2021-09-23 15:05:10 +02:00
|
|
|
import wif from 'wif';
|
|
|
|
import bip38 from 'bip38';
|
|
|
|
|
2019-12-27 03:21:07 +01:00
|
|
|
import {
|
2021-09-23 15:05:10 +02:00
|
|
|
HDAezeedWallet,
|
2019-12-27 03:21:07 +01:00
|
|
|
HDLegacyBreadwalletWallet,
|
2021-09-23 15:05:10 +02:00
|
|
|
HDLegacyElectrumSeedP2PKHWallet,
|
2019-12-27 03:21:07 +01:00
|
|
|
HDLegacyP2PKHWallet,
|
|
|
|
HDSegwitBech32Wallet,
|
2020-05-04 11:52:01 +02:00
|
|
|
HDSegwitElectrumSeedP2WPKHWallet,
|
2021-09-23 15:05:10 +02:00
|
|
|
HDSegwitP2SHWallet,
|
|
|
|
LegacyWallet,
|
|
|
|
LightningCustodianWallet,
|
|
|
|
LightningLdkWallet,
|
2020-10-05 23:25:14 +02:00
|
|
|
MultisigHDWallet,
|
2021-04-15 19:52:48 +02:00
|
|
|
SLIP39LegacyP2PKHWallet,
|
|
|
|
SLIP39SegwitBech32Wallet,
|
2021-09-23 15:05:10 +02:00
|
|
|
SLIP39SegwitP2SHWallet,
|
|
|
|
SegwitBech32Wallet,
|
|
|
|
SegwitP2SHWallet,
|
|
|
|
WatchOnlyWallet,
|
2020-05-24 12:27:08 +02:00
|
|
|
} from '.';
|
2020-07-29 22:00:00 +02:00
|
|
|
import loc from '../loc';
|
2021-09-23 15:05:10 +02:00
|
|
|
import bip39WalletFormats from './bip39_wallet_formats.json'; // https://github.com/spesmilo/electrum/blob/master/electrum/bip39_wallet_formats.json
|
|
|
|
import bip39WalletFormatsBlueWallet from './bip39_wallet_formats_bluewallet.json';
|
|
|
|
|
|
|
|
// https://github.com/bitcoinjs/bip32/blob/master/ts-src/bip32.ts#L43
|
|
|
|
export const validateBip32 = path => path.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that starts wallet search and import process. It has async generator inside, so
|
|
|
|
* that the process can be stoped at any time. It reporst all the progress through callbacks.
|
|
|
|
*
|
|
|
|
* @param askPassphrase {bool} If true import process will call onPassword callback for wallet with optional password.
|
|
|
|
* @param searchAccounts {bool} If true import process will scan for all known derivation path from bip39_wallet_formats.json. If false it will use limited version.
|
|
|
|
* @param onProgress {function} Callback to report scanning progress
|
|
|
|
* @param onWallet {function} Callback to report wallet found
|
|
|
|
* @param onPassword {function} Callback to ask for password if needed
|
|
|
|
* @returns {{promise: Promise, stop: function}}
|
|
|
|
*/
|
|
|
|
const startImport = (importTextOrig, askPassphrase = false, searchAccounts = false, onProgress, onWallet, onPassword) => {
|
|
|
|
// state
|
|
|
|
let promiseResolve;
|
|
|
|
let promiseReject;
|
|
|
|
let running = true; // if you put it to false, internal generator stops
|
|
|
|
const wallets = [];
|
|
|
|
const promise = new Promise((resolve, reject) => {
|
|
|
|
promiseResolve = resolve;
|
|
|
|
promiseReject = reject;
|
|
|
|
});
|
|
|
|
|
|
|
|
// actions
|
|
|
|
const reportProgress = name => {
|
|
|
|
onProgress(name);
|
2020-10-24 19:20:59 +02:00
|
|
|
};
|
2021-09-23 15:05:10 +02:00
|
|
|
const reportFinish = (cancelled, stopped) => {
|
|
|
|
promiseResolve({ cancelled, stopped, wallets });
|
2020-10-24 19:20:59 +02:00
|
|
|
};
|
2021-09-23 15:05:10 +02:00
|
|
|
const reportWallet = wallet => {
|
|
|
|
if (wallets.some(w => w.getID() === wallet.getID())) return; // do not add duplicates
|
|
|
|
wallets.push(wallet);
|
|
|
|
onWallet(wallet);
|
2020-10-24 19:20:59 +02:00
|
|
|
};
|
2021-09-23 15:05:10 +02:00
|
|
|
const stop = () => (running = false);
|
2019-12-27 03:21:07 +01:00
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
async function* importGenerator() {
|
|
|
|
// The plan:
|
|
|
|
// -3. ask for password, if needed and validate it
|
|
|
|
// -2. check if BIP38 encrypted
|
|
|
|
// -1a. check if multisig
|
|
|
|
// -1. check lightning custodian
|
|
|
|
// 0. check if its HDSegwitBech32Wallet (BIP84)
|
|
|
|
// 1. check if its HDSegwitP2SHWallet (BIP49)
|
|
|
|
// 2. check if its HDLegacyP2PKHWallet (BIP44)
|
|
|
|
// 3. check if its HDLegacyBreadwalletWallet (no BIP, just "m/0")
|
|
|
|
// 3.1 check HD Electrum legacy
|
|
|
|
// 3.2 check if its AEZEED
|
|
|
|
// 3.3 check if its SLIP39
|
|
|
|
// 4. check if its Segwit WIF (P2SH)
|
|
|
|
// 5. check if its Legacy WIF
|
|
|
|
// 6. check if its address (watch-only wallet)
|
|
|
|
// 7. check if its private key (segwit address P2SH) TODO
|
|
|
|
// 7. check if its private key (legacy address) TODO
|
|
|
|
let text = importTextOrig.trim();
|
2021-07-20 16:36:44 +02:00
|
|
|
let password;
|
|
|
|
|
|
|
|
// BIP38 password required
|
|
|
|
if (text.startsWith('6P')) {
|
|
|
|
do {
|
2021-09-23 15:05:10 +02:00
|
|
|
password = await onPassword(loc.wallets.looks_like_bip38, loc.wallets.enter_bip38_password);
|
2021-07-20 16:36:44 +02:00
|
|
|
} while (!password);
|
|
|
|
}
|
|
|
|
|
|
|
|
// HD BIP39 wallet password is optinal
|
|
|
|
const hd = new HDSegwitBech32Wallet();
|
|
|
|
hd.setSecret(text);
|
2021-09-23 15:05:10 +02:00
|
|
|
if (askPassphrase && hd.validateMnemonic()) {
|
|
|
|
password = await onPassword(loc.wallets.import_passphrase_title, loc.wallets.import_passphrase_message);
|
2021-07-20 16:36:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AEZEED password needs to be correct
|
|
|
|
const aezeed = new HDAezeedWallet();
|
|
|
|
aezeed.setSecret(text);
|
|
|
|
if (await aezeed.mnemonicInvalidPassword()) {
|
|
|
|
do {
|
2021-09-23 15:05:10 +02:00
|
|
|
password = await onPassword('', loc.wallets.enter_bip38_password);
|
2021-07-20 16:36:44 +02:00
|
|
|
aezeed.setPassphrase(password);
|
|
|
|
} while (await aezeed.mnemonicInvalidPassword());
|
|
|
|
}
|
|
|
|
|
|
|
|
// SLIP39 wallet password is optinal
|
2021-09-23 15:05:10 +02:00
|
|
|
if (askPassphrase && text.includes('\n')) {
|
2021-07-20 16:36:44 +02:00
|
|
|
const s1 = new SLIP39SegwitP2SHWallet();
|
|
|
|
s1.setSecret(text);
|
|
|
|
|
|
|
|
if (s1.validateMnemonic()) {
|
2021-09-23 15:05:10 +02:00
|
|
|
password = await onPassword(loc.wallets.import_passphrase_title, loc.wallets.import_passphrase_message);
|
2021-07-20 16:36:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 10:22:34 +02:00
|
|
|
// ELECTRUM segwit wallet password is optinal
|
|
|
|
const electrum1 = new HDSegwitElectrumSeedP2WPKHWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
electrum1.setSecret(text);
|
|
|
|
if (askPassphrase && electrum1.validateMnemonic()) {
|
|
|
|
password = await onPassword(loc.wallets.import_passphrase_title, loc.wallets.import_passphrase_message);
|
2021-07-26 10:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ELECTRUM legacy wallet password is optinal
|
|
|
|
const electrum2 = new HDLegacyElectrumSeedP2PKHWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
electrum2.setSecret(text);
|
|
|
|
if (askPassphrase && electrum2.validateMnemonic()) {
|
|
|
|
password = await onPassword(loc.wallets.import_passphrase_title, loc.wallets.import_passphrase_message);
|
2021-09-09 13:00:11 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
// is it bip38 encrypted
|
|
|
|
if (text.startsWith('6P')) {
|
|
|
|
const decryptedKey = await bip38.decryptAsync(text, password);
|
2020-10-05 23:25:14 +02:00
|
|
|
|
2020-10-15 13:14:55 +02:00
|
|
|
if (decryptedKey) {
|
2021-09-23 15:05:10 +02:00
|
|
|
text = wif.encode(0x80, decryptedKey.privateKey, decryptedKey.compressed);
|
2019-12-27 03:21:07 +01:00
|
|
|
}
|
2020-10-15 13:14:55 +02:00
|
|
|
}
|
2019-12-27 03:21:07 +01:00
|
|
|
|
2020-10-15 13:14:55 +02:00
|
|
|
// is it multisig?
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'multisignature' };
|
|
|
|
const ms = new MultisigHDWallet();
|
|
|
|
ms.setSecret(text);
|
|
|
|
if (ms.getN() > 0 && ms.getM() > 0) {
|
|
|
|
await ms.fetchBalance();
|
|
|
|
yield { wallet: ms };
|
2020-10-15 13:14:55 +02:00
|
|
|
}
|
2019-12-27 03:21:07 +01:00
|
|
|
|
2020-10-15 13:14:55 +02:00
|
|
|
// is it lightning custodian?
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'lightning custodian' };
|
|
|
|
if (text.startsWith('blitzhub://') || text.startsWith('lndhub://')) {
|
2020-10-15 13:14:55 +02:00
|
|
|
const lnd = new LightningCustodianWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
if (text.includes('@')) {
|
|
|
|
const split = text.split('@');
|
2020-10-15 13:14:55 +02:00
|
|
|
lnd.setBaseURI(split[1]);
|
|
|
|
lnd.setSecret(split[0]);
|
2019-12-27 03:21:07 +01:00
|
|
|
}
|
2021-10-23 21:17:00 +02:00
|
|
|
await lnd.init();
|
2020-10-15 13:14:55 +02:00
|
|
|
await lnd.authorize();
|
|
|
|
await lnd.fetchTransactions();
|
|
|
|
await lnd.fetchUserInvoices();
|
|
|
|
await lnd.fetchPendingTransactions();
|
|
|
|
await lnd.fetchBalance();
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: lnd };
|
2020-10-15 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
// is it LDK?
|
|
|
|
yield { progress: 'lightning' };
|
|
|
|
if (text.startsWith('ldk://')) {
|
|
|
|
const ldk = new LightningLdkWallet();
|
|
|
|
ldk.setSecret(text);
|
|
|
|
if (ldk.valid()) {
|
|
|
|
await ldk.init();
|
|
|
|
yield { wallet: ldk };
|
2019-12-27 03:21:07 +01:00
|
|
|
}
|
2021-09-23 15:05:10 +02:00
|
|
|
}
|
2021-03-25 16:28:25 +01:00
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
// check bip39 wallets
|
|
|
|
yield { progress: 'bip39' };
|
|
|
|
const hd2 = new HDSegwitBech32Wallet();
|
|
|
|
hd2.setSecret(text);
|
|
|
|
hd2.setPassphrase(password);
|
|
|
|
if (hd2.validateMnemonic()) {
|
|
|
|
let walletFound = false;
|
|
|
|
// by default we don't try all the paths and options
|
|
|
|
const paths = searchAccounts ? bip39WalletFormats : bip39WalletFormatsBlueWallet;
|
|
|
|
for (const i of paths) {
|
|
|
|
// we need to skip m/0' p2pkh from default scan list. It could be a BRD wallet and will be handled later
|
|
|
|
if (i.derivation_path === "m/0'" && i.script_type === 'p2pkh') continue;
|
|
|
|
let paths;
|
|
|
|
if (i.iterate_accounts && searchAccounts) {
|
|
|
|
const basicPath = i.derivation_path.slice(0, -2); // remove 0' from the end
|
|
|
|
paths = [...Array(10).keys()].map(j => basicPath + j + "'"); // add account number
|
|
|
|
} else {
|
|
|
|
paths = [i.derivation_path];
|
|
|
|
}
|
|
|
|
let WalletClass;
|
|
|
|
switch (i.script_type) {
|
|
|
|
case 'p2pkh':
|
|
|
|
WalletClass = HDLegacyP2PKHWallet;
|
|
|
|
break;
|
|
|
|
case 'p2wpkh-p2sh':
|
|
|
|
WalletClass = HDSegwitP2SHWallet;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// p2wpkh
|
|
|
|
WalletClass = HDSegwitBech32Wallet;
|
|
|
|
}
|
|
|
|
for (const path of paths) {
|
|
|
|
const wallet = new WalletClass();
|
|
|
|
wallet.setSecret(text);
|
|
|
|
wallet.setPassphrase(password);
|
|
|
|
wallet.setDerivationPath(path);
|
|
|
|
yield { progress: `bip39 ${i.script_type} ${path}` };
|
|
|
|
if (await wallet.wasEverUsed()) {
|
2022-10-31 13:25:26 +01:00
|
|
|
yield { wallet };
|
2021-09-23 15:05:10 +02:00
|
|
|
walletFound = true;
|
|
|
|
} else {
|
|
|
|
break; // don't check second account if first one is empty
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 16:28:25 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
// m/0' p2pkh is a special case. It could be regular a HD wallet or a BRD wallet.
|
|
|
|
// to decide which one is it let's compare number of transactions
|
|
|
|
const m0Legacy = new HDLegacyP2PKHWallet();
|
|
|
|
m0Legacy.setSecret(text);
|
|
|
|
m0Legacy.setPassphrase(password);
|
|
|
|
m0Legacy.setDerivationPath("m/0'");
|
|
|
|
yield { progress: "bip39 p2pkh m/0'" };
|
|
|
|
// BRD doesn't support passphrase and only works with 12 words seeds
|
|
|
|
if (!password && text.split(' ').length === 12) {
|
|
|
|
const brd = new HDLegacyBreadwalletWallet();
|
|
|
|
brd.setSecret(text);
|
|
|
|
|
|
|
|
if (await m0Legacy.wasEverUsed()) {
|
|
|
|
await m0Legacy.fetchBalance();
|
|
|
|
await m0Legacy.fetchTransactions();
|
|
|
|
yield { progress: 'BRD' };
|
|
|
|
await brd.fetchBalance();
|
|
|
|
await brd.fetchTransactions();
|
|
|
|
if (brd.getTransactions().length > m0Legacy.getTransactions().length) {
|
|
|
|
yield { wallet: brd };
|
|
|
|
} else {
|
|
|
|
yield { wallet: m0Legacy };
|
|
|
|
}
|
|
|
|
walletFound = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (await m0Legacy.wasEverUsed()) {
|
|
|
|
yield { wallet: m0Legacy };
|
|
|
|
walletFound = true;
|
|
|
|
}
|
2021-03-25 16:28:25 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
// if we havent found any wallet for this seed suggest new bech32 wallet
|
|
|
|
if (!walletFound) {
|
|
|
|
yield { wallet: hd2 };
|
2021-03-25 16:28:25 +01:00
|
|
|
}
|
2021-09-23 15:05:10 +02:00
|
|
|
// return;
|
2020-10-15 13:14:55 +02:00
|
|
|
}
|
2019-12-27 03:21:07 +01:00
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'wif' };
|
2020-10-15 13:14:55 +02:00
|
|
|
const segwitWallet = new SegwitP2SHWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
segwitWallet.setSecret(text);
|
2020-10-15 13:14:55 +02:00
|
|
|
if (segwitWallet.getAddress()) {
|
|
|
|
// ok its a valid WIF
|
2022-03-12 10:13:03 +01:00
|
|
|
let walletFound = false;
|
2019-12-27 03:21:07 +01:00
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'wif p2wpkh' };
|
2020-10-15 13:14:55 +02:00
|
|
|
const segwitBech32Wallet = new SegwitBech32Wallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
segwitBech32Wallet.setSecret(text);
|
2021-03-25 16:28:25 +01:00
|
|
|
if (await segwitBech32Wallet.wasEverUsed()) {
|
2020-10-15 13:14:55 +02:00
|
|
|
// yep, its single-address bech32 wallet
|
2021-03-25 16:28:25 +01:00
|
|
|
await segwitBech32Wallet.fetchBalance();
|
2022-03-12 10:13:03 +01:00
|
|
|
walletFound = true;
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: segwitBech32Wallet };
|
2021-03-25 16:28:25 +01:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'wif p2wpkh-p2sh' };
|
2021-03-25 16:28:25 +01:00
|
|
|
if (await segwitWallet.wasEverUsed()) {
|
2022-03-12 10:13:03 +01:00
|
|
|
// yep, its single-address p2wpkh wallet
|
2020-10-15 13:14:55 +02:00
|
|
|
await segwitWallet.fetchBalance();
|
2022-03-12 10:13:03 +01:00
|
|
|
walletFound = true;
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: segwitWallet };
|
2019-12-27 03:21:07 +01:00
|
|
|
}
|
2021-03-25 16:28:25 +01:00
|
|
|
|
|
|
|
// default wallet is Legacy
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'wif p2pkh' };
|
2021-03-25 16:28:25 +01:00
|
|
|
const legacyWallet = new LegacyWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
legacyWallet.setSecret(text);
|
2022-03-12 10:13:03 +01:00
|
|
|
if (await legacyWallet.wasEverUsed()) {
|
|
|
|
// yep, its single-address legacy wallet
|
|
|
|
await legacyWallet.fetchBalance();
|
|
|
|
walletFound = true;
|
|
|
|
yield { wallet: legacyWallet };
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no wallets was ever used, import all of them
|
|
|
|
if (!walletFound) {
|
|
|
|
yield { wallet: segwitBech32Wallet };
|
|
|
|
yield { wallet: segwitWallet };
|
|
|
|
yield { wallet: legacyWallet };
|
|
|
|
}
|
2020-10-15 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// case - WIF is valid, just has uncompressed pubkey
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'wif p2pkh' };
|
2020-10-15 13:14:55 +02:00
|
|
|
const legacyWallet = new LegacyWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
legacyWallet.setSecret(text);
|
2020-10-15 13:14:55 +02:00
|
|
|
if (legacyWallet.getAddress()) {
|
|
|
|
await legacyWallet.fetchBalance();
|
|
|
|
await legacyWallet.fetchTransactions();
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: legacyWallet };
|
2020-10-15 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 21:53:29 +02:00
|
|
|
// maybe its a watch-only address?
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'watch only' };
|
2021-05-13 21:53:29 +02:00
|
|
|
const watchOnly = new WatchOnlyWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
watchOnly.setSecret(text);
|
2021-05-13 21:53:29 +02:00
|
|
|
if (watchOnly.valid()) {
|
|
|
|
await watchOnly.fetchBalance();
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: watchOnly };
|
|
|
|
}
|
|
|
|
|
|
|
|
// electrum p2wpkh-p2sh
|
|
|
|
yield { progress: 'electrum p2wpkh-p2sh' };
|
|
|
|
const el1 = new HDSegwitElectrumSeedP2WPKHWallet();
|
|
|
|
el1.setSecret(text);
|
|
|
|
el1.setPassphrase(password);
|
|
|
|
if (el1.validateMnemonic()) {
|
|
|
|
yield { wallet: el1 }; // not fetching txs or balances, fuck it, yolo, life is too short
|
|
|
|
}
|
|
|
|
|
|
|
|
// electrum p2wpkh-p2sh
|
|
|
|
yield { progress: 'electrum p2pkh' };
|
|
|
|
const el2 = new HDLegacyElectrumSeedP2PKHWallet();
|
|
|
|
el2.setSecret(text);
|
|
|
|
el2.setPassphrase(password);
|
|
|
|
if (el2.validateMnemonic()) {
|
|
|
|
yield { wallet: el2 }; // not fetching txs or balances, fuck it, yolo, life is too short
|
2021-05-13 21:53:29 +02:00
|
|
|
}
|
2019-12-27 03:21:07 +01:00
|
|
|
|
2021-01-28 13:54:23 +01:00
|
|
|
// is it AEZEED?
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'aezeed' };
|
|
|
|
const aezeed2 = new HDAezeedWallet();
|
|
|
|
aezeed2.setSecret(text);
|
|
|
|
aezeed2.setPassphrase(password);
|
|
|
|
if (await aezeed2.validateMnemonicAsync()) {
|
|
|
|
yield { wallet: aezeed2 }; // not fetching txs or balances, fuck it, yolo, life is too short
|
|
|
|
}
|
2021-01-28 13:54:23 +01:00
|
|
|
|
2021-04-15 19:52:48 +02:00
|
|
|
// if it is multi-line string, then it is probably SLIP39 wallet
|
|
|
|
// each line - one share
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'SLIP39' };
|
|
|
|
if (text.includes('\n')) {
|
2021-04-15 19:52:48 +02:00
|
|
|
const s1 = new SLIP39SegwitP2SHWallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
s1.setSecret(text);
|
2021-04-15 19:52:48 +02:00
|
|
|
|
|
|
|
if (s1.validateMnemonic()) {
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'SLIP39 p2wpkh-p2sh' };
|
2021-07-20 16:36:44 +02:00
|
|
|
s1.setPassphrase(password);
|
2021-04-15 19:52:48 +02:00
|
|
|
if (await s1.wasEverUsed()) {
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: s1 };
|
2021-04-15 19:52:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'SLIP39 p2pkh' };
|
2021-04-15 19:52:48 +02:00
|
|
|
const s2 = new SLIP39LegacyP2PKHWallet();
|
2021-07-20 16:36:44 +02:00
|
|
|
s2.setPassphrase(password);
|
2021-09-23 15:05:10 +02:00
|
|
|
s2.setSecret(text);
|
2021-04-15 19:52:48 +02:00
|
|
|
if (await s2.wasEverUsed()) {
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: s2 };
|
2021-04-15 19:52:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { progress: 'SLIP39 p2wpkh' };
|
2021-04-15 19:52:48 +02:00
|
|
|
const s3 = new SLIP39SegwitBech32Wallet();
|
2021-09-23 15:05:10 +02:00
|
|
|
s3.setSecret(text);
|
2021-07-20 16:36:44 +02:00
|
|
|
s3.setPassphrase(password);
|
2021-09-23 15:05:10 +02:00
|
|
|
yield { wallet: s3 };
|
2021-04-15 19:52:48 +02:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 15:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// POEHALI
|
|
|
|
(async () => {
|
|
|
|
const generator = importGenerator();
|
|
|
|
while (true) {
|
|
|
|
const next = await generator.next();
|
|
|
|
if (!running) throw new Error('Discovery stopped'); // break if stop() has been called
|
|
|
|
if (next.value?.progress) reportProgress(next.value.progress);
|
|
|
|
if (next.value?.wallet) reportWallet(next.value.wallet);
|
|
|
|
if (next.done) break; // break if generator has been finished
|
|
|
|
}
|
|
|
|
reportFinish();
|
|
|
|
})().catch(e => {
|
|
|
|
if (e.message === 'Cancel Pressed') {
|
|
|
|
reportFinish(true);
|
|
|
|
return;
|
|
|
|
} else if (e.message === 'Discovery stopped') {
|
|
|
|
reportFinish(undefined, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
promiseReject(e);
|
|
|
|
});
|
2021-04-15 19:52:48 +02:00
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
return { promise, stop };
|
|
|
|
};
|
2020-10-24 19:20:59 +02:00
|
|
|
|
2021-09-23 15:05:10 +02:00
|
|
|
export default startImport;
|