mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-23 15:20:55 +01:00
Merge pull request #3355 from BlueWallet/fix-incorrect-path-in-bip49
FIX: hardware wallet with BIP44/BIP49 wallet reports incorrect change…
This commit is contained in:
commit
851ffd59ce
5 changed files with 53 additions and 4 deletions
|
@ -162,4 +162,9 @@ export class HDLegacyP2PKHWallet extends AbstractHDElectrumWallet {
|
|||
|
||||
return psbt;
|
||||
}
|
||||
|
||||
_getDerivationPathByAddress(address, BIP = 44) {
|
||||
// only changing defaults for function arguments
|
||||
return super._getDerivationPathByAddress(address, BIP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,4 +148,9 @@ export class HDSegwitP2SHWallet extends AbstractHDElectrumWallet {
|
|||
});
|
||||
return address;
|
||||
}
|
||||
|
||||
_getDerivationPathByAddress(address, BIP = 49) {
|
||||
// only changing defaults for function arguments
|
||||
return super._getDerivationPathByAddress(address, BIP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ describe('Legacy HD (BIP44)', () => {
|
|||
'02ad7b2216f3a2b38d56db8a7ee5c540fd12c4bbb7013106eff78cc2ace65aa002',
|
||||
);
|
||||
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getExternalAddressByIndex(0)), "m/84'/0'/0'/0/0"); // wrong, FIXME
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getInternalAddressByIndex(0)), "m/84'/0'/0'/1/0"); // wrong, FIXME
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getExternalAddressByIndex(0)), "m/44'/0'/0'/0/0");
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getInternalAddressByIndex(0)), "m/44'/0'/0'/1/0");
|
||||
});
|
||||
|
||||
it('can create TX', async () => {
|
||||
|
|
|
@ -24,8 +24,8 @@ describe('P2SH Segwit HD (BIP49)', () => {
|
|||
'03c107e6976d59e17490513fbed3fb321736b7231d24f3d09306c72714acf1859d',
|
||||
);
|
||||
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getExternalAddressByIndex(0)), "m/84'/0'/0'/0/0"); // wrong, FIXME
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getInternalAddressByIndex(0)), "m/84'/0'/0'/1/0"); // wrong, FIXME
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getExternalAddressByIndex(0)), "m/49'/0'/0'/0/0");
|
||||
assert.strictEqual(hd._getDerivationPathByAddress(hd._getInternalAddressByIndex(0)), "m/49'/0'/0'/1/0");
|
||||
|
||||
assert.strictEqual('L4MqtwJm6hkbACLG4ho5DF8GhcXdLEbbvpJnbzA9abfD6RDpbr2m', hd._getExternalWIFByIndex(0));
|
||||
assert.strictEqual(
|
||||
|
|
|
@ -297,6 +297,45 @@ describe('Watch only wallet', () => {
|
|||
assert.ok(!w.addressIsChange(await w._getExternalAddressByIndex(0)));
|
||||
assert.ok(w.addressIsChange(await w._getInternalAddressByIndex(0)));
|
||||
});
|
||||
|
||||
it('can craft correct psbt for HW wallet to sign', async () => {
|
||||
const w = new WatchOnlyWallet();
|
||||
w.setSecret('ypub6Y9u3QCRC1HkZv3stNxcQVwmw7vC7KX5Ldz38En5P88RQbesP2oy16hNyQocVCfYRQPxdHcd3pmu9AFhLv7NdChWmw5iNLryZ2U6EEHdnfo');
|
||||
w.init();
|
||||
|
||||
// a hack to make it find pubkey for address correctly:
|
||||
w._hdWalletInstance.next_free_address_index = 110;
|
||||
w._hdWalletInstance.next_free_change_address_index = 110;
|
||||
|
||||
const utxos = [
|
||||
{
|
||||
height: 557538,
|
||||
value: 51432,
|
||||
address: '3GCvDBAktgQQtsbN6x5DYiQCMmgZ9Yk8BK',
|
||||
txId: 'b2ac59bc282083498d1e87805d89bef9d3f3bc216c1d2c4dfaa2e2911b547100',
|
||||
vout: 0,
|
||||
txid: 'b2ac59bc282083498d1e87805d89bef9d3f3bc216c1d2c4dfaa2e2911b547100',
|
||||
amount: 51432,
|
||||
wif: false,
|
||||
confirmations: 132402,
|
||||
},
|
||||
];
|
||||
|
||||
const changeAddress = '3DrZBgntD8kBBbuKLJtPVAeGT75BMC7NxU';
|
||||
|
||||
const { psbt } = await w.createTransaction(
|
||||
utxos,
|
||||
[{ address: 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu', value: 5000 }],
|
||||
1,
|
||||
changeAddress,
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
psbt.data.outputs[1].bip32Derivation[0].pubkey.toString('hex'),
|
||||
'03e060c9b5bb85476caa53e3b8cd3d40c9dc2c36a8a5e8ed87e48bfc9bbe1760ad',
|
||||
);
|
||||
assert.strictEqual(psbt.data.outputs[1].bip32Derivation[0].path, "m/49'/0'/0'/1/46");
|
||||
});
|
||||
});
|
||||
|
||||
describe('BC-UR', () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue