mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
Merge pull request #4576 from BlueWallet/limpbrains-import-empty-wif
FIX: allow user to choose wallet type when importing empty WIF
This commit is contained in:
commit
2e815f35e8
@ -269,6 +269,7 @@ const startImport = (importTextOrig, askPassphrase = false, searchAccounts = fal
|
||||
segwitWallet.setSecret(text);
|
||||
if (segwitWallet.getAddress()) {
|
||||
// ok its a valid WIF
|
||||
let walletFound = false;
|
||||
|
||||
yield { progress: 'wif p2wpkh' };
|
||||
const segwitBech32Wallet = new SegwitBech32Wallet();
|
||||
@ -276,13 +277,15 @@ const startImport = (importTextOrig, askPassphrase = false, searchAccounts = fal
|
||||
if (await segwitBech32Wallet.wasEverUsed()) {
|
||||
// yep, its single-address bech32 wallet
|
||||
await segwitBech32Wallet.fetchBalance();
|
||||
walletFound = true;
|
||||
yield { wallet: segwitBech32Wallet };
|
||||
}
|
||||
|
||||
yield { progress: 'wif p2wpkh-p2sh' };
|
||||
if (await segwitWallet.wasEverUsed()) {
|
||||
// yep, its single-address bech32 wallet
|
||||
// yep, its single-address p2wpkh wallet
|
||||
await segwitWallet.fetchBalance();
|
||||
walletFound = true;
|
||||
yield { wallet: segwitWallet };
|
||||
}
|
||||
|
||||
@ -290,7 +293,19 @@ const startImport = (importTextOrig, askPassphrase = false, searchAccounts = fal
|
||||
yield { progress: 'wif p2pkh' };
|
||||
const legacyWallet = new LegacyWallet();
|
||||
legacyWallet.setSecret(text);
|
||||
yield { wallet: legacyWallet };
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
||||
// case - WIF is valid, just has uncompressed pubkey
|
||||
|
@ -129,20 +129,36 @@ describe('import procedure', () => {
|
||||
assert.strictEqual(store.state.wallets[0].getAddress(), '1AhcdMCzby4VXgqrexuMfh7eiSprRFtN78');
|
||||
});
|
||||
|
||||
it('can import Legacy P2SH Segwit', async () => {
|
||||
it('can import P2SH Segwit', async () => {
|
||||
const store = createStore();
|
||||
const { promise } = startImport('L3NxFnYoBGjJ5PhxrxV6jorvjnc8cerYJx71vXU6ta8BXQxHVZya', false, false, ...store.callbacks);
|
||||
await promise;
|
||||
assert.strictEqual(store.state.wallets[0].type, SegwitP2SHWallet.type);
|
||||
assert.strictEqual(store.state.wallets[0].getAddress(), '3KM9VfdsDf9uT7uwZagoKgVn8z35m9CtSM');
|
||||
assert.strictEqual(store.state.wallets[1].type, LegacyWallet.type);
|
||||
assert.strictEqual(store.state.wallets[1].getAddress(), '1L7AmTTKbAAefBe93gJcFRTH9fdfhkMdHt');
|
||||
});
|
||||
|
||||
it('can import Legacy Bech32 Segwit', async () => {
|
||||
it('can import Bech32 Segwit', async () => {
|
||||
const store = createStore();
|
||||
const { promise } = startImport('L1T6FfKpKHi8JE6eBKrsXkenw34d5FfFzJUZ6dLs2utxkSvsDfxZ', false, false, ...store.callbacks);
|
||||
await promise;
|
||||
assert.strictEqual(store.state.wallets[0].type, SegwitBech32Wallet.type);
|
||||
assert.strictEqual(store.state.wallets[0].getAddress(), 'bc1q763rf54hzuncmf8dtlz558uqe4f247mq39rjvr');
|
||||
assert.strictEqual(store.state.wallets[1].type, LegacyWallet.type);
|
||||
assert.strictEqual(store.state.wallets[1].getAddress(), '1PV5YV6UWWL6rJuKsNH5uY75E9377hFFWn');
|
||||
});
|
||||
|
||||
it('can import Legacy/P2SH/Bech32 from an empty wallet', async () => {
|
||||
const store = createStore();
|
||||
const { promise } = startImport('L36mabzoQyMZoHHsBFVNB7PUBXgXTynwY6yR7kYZ82EkS7oejVp2', false, false, ...store.callbacks);
|
||||
await promise;
|
||||
assert.strictEqual(store.state.wallets[0].type, SegwitBech32Wallet.type);
|
||||
assert.strictEqual(store.state.wallets[0].getAddress(), 'bc1q8dkdgpaq9sd2xwptsjhe7krwp0k595w0hdtkfr');
|
||||
assert.strictEqual(store.state.wallets[1].type, SegwitP2SHWallet.type);
|
||||
assert.strictEqual(store.state.wallets[1].getAddress(), '3QNykAevvcnyw8S85wn4U8tsH2nksRMEKr');
|
||||
assert.strictEqual(store.state.wallets[2].type, LegacyWallet.type);
|
||||
assert.strictEqual(store.state.wallets[2].getAddress(), '16RDEqXtDmZjm8f4s6Uf3EHgjCpsSqB2zM');
|
||||
});
|
||||
|
||||
it('can import BIP44', async () => {
|
||||
@ -285,8 +301,14 @@ describe('import procedure', () => {
|
||||
const { promise } = startImport('6PnU5voARjBBykwSddwCdcn6Eu9EcsK24Gs5zWxbJbPZYW7eiYQP8XgKbN', false, false, ...store.callbacks);
|
||||
await promise;
|
||||
assert.strictEqual(store.state.wallets[0].getSecret(), 'KxqRtpd9vFju297ACPKHrGkgXuberTveZPXbRDiQ3MXZycSQYtjc');
|
||||
assert.strictEqual(store.state.wallets[0].type, LegacyWallet.type);
|
||||
assert.strictEqual(store.state.wallets[0].getAddress(), '1639W2kM6UY9PdavMQeLqG4SuUEae9NZfq');
|
||||
assert.strictEqual(store.state.wallets[0].type, SegwitBech32Wallet.type);
|
||||
assert.strictEqual(store.state.wallets[0].getAddress(), 'bc1qxaqgapg7sugyvq3zh0re8plqkgrvrxzr6snmqr');
|
||||
assert.strictEqual(store.state.wallets[1].getSecret(), 'KxqRtpd9vFju297ACPKHrGkgXuberTveZPXbRDiQ3MXZycSQYtjc');
|
||||
assert.strictEqual(store.state.wallets[1].type, SegwitP2SHWallet.type);
|
||||
assert.strictEqual(store.state.wallets[1].getAddress(), '3ANCYnBvFPJyc4sxNFWnLkVBfDrKBZCVSp');
|
||||
assert.strictEqual(store.state.wallets[2].getSecret(), 'KxqRtpd9vFju297ACPKHrGkgXuberTveZPXbRDiQ3MXZycSQYtjc');
|
||||
assert.strictEqual(store.state.wallets[2].type, LegacyWallet.type);
|
||||
assert.strictEqual(store.state.wallets[2].getAddress(), '1639W2kM6UY9PdavMQeLqG4SuUEae9NZfq');
|
||||
});
|
||||
|
||||
it('can import watch-only address', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user