Merge pull request #3921 from BlueWallet/fix-path-from-hw-watchonly-wallets

FIX: correct path when importing watch-only from hardware wallet
This commit is contained in:
GLaDOS 2021-09-27 19:25:34 +01:00 committed by GitHub
commit 3c13e659ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -261,7 +261,7 @@ export class AbstractWallet {
this.secret = parsedSecret.ExtPubKey;
const mfp = Buffer.from(parsedSecret.MasterFingerprint, 'hex').reverse().toString('hex');
this.masterFingerprint = parseInt(mfp, 16);
this._derivationPath = `m/${parsedSecret.AccountKeyPath}`;
this._derivationPath = parsedSecret.AccountKeyPath.startsWith('m/') ? parsedSecret.AccountKeyPath : `m/${parsedSecret.AccountKeyPath}`;
if (parsedSecret.CoboVaultFirmwareVersion) this.use_with_hardware_wallet = true;
}
} catch (_) {}

View File

@ -362,6 +362,20 @@ describe('import procedure', () => {
);
await promise;
assert.strictEqual(store.state.wallets[0].type, WatchOnlyWallet.type);
assert.strictEqual(store.state.wallets[0].getDerivationPath(), "m/84'/0'/0'");
});
it('can import watch-only Keystone vault export', async () => {
const store = createStore();
const { promise } = startImport(
'{"ExtPubKey":"zpub6qT7amLcp2exr4mU4AhXZMjD9CFkopECVhUxc9LHW8pNsJG2B9ogs5sFbGZpxEeT5TBjLmc7EFYgZA9EeWEM1xkJMFLefzZc8eigRFhKB8Q","MasterFingerprint":"01EBDA7D","AccountKeyPath":"m/84\'/0\'/0\'"}',
false,
false,
...store.callbacks,
);
await promise;
assert.strictEqual(store.state.wallets[0].type, WatchOnlyWallet.type);
assert.strictEqual(store.state.wallets[0].getDerivationPath(), "m/84'/0'/0'");
});
it('can import BIP39 wallets with truncated words', async () => {

View File

@ -438,6 +438,11 @@ describe('BC-UR', () => {
Buffer.from(decoded, 'hex').toString('ascii'),
'{"ExtPubKey":"zpub6qT7amLcp2exr4mU4AhXZMjD9CFkopECVhUxc9LHW8pNsJG2B9ogs5sFbGZpxEeT5TBjLmc7EFYgZA9EeWEM1xkJMFLefzZc8eigRFhKB8Q","MasterFingerprint":"01EBDA7D","AccountKeyPath":"m/84\'/0\'/0\'"}',
);
const w = new WatchOnlyWallet();
w.setSecret(Buffer.from(decoded, 'hex').toString('ascii'));
w.init();
assert.strictEqual(w.getDerivationPath(), "m/84'/0'/0'");
});
it('v2: can decodeUR() PSBT', () => {