BlueWallet/tests/unit/watch-only-wallet.test.js

364 lines
18 KiB
JavaScript
Raw Normal View History

2019-06-08 14:57:44 +02:00
import { WatchOnlyWallet } from '../../class';
import { decodeUR } from 'bc-ur/dist';
import { Psbt } from 'bitcoinjs-lib';
const assert = require('assert');
describe('Watch only wallet', () => {
it('can validate address', async () => {
const w = new WatchOnlyWallet();
for (const secret of [
'bc1quhnve8q4tk3unhmjts7ymxv8cd6w9xv8wy29uv',
'12eQ9m4sgAwTSQoNXkRABKhCXCsjm2jdVG',
'3BDsBDxDimYgNZzsqszNZobqQq3yeUoJf2',
'BC1QUHNVE8Q4TK3UNHMJTS7YMXV8CD6W9XV8WY29UV',
]) {
w.setSecret(secret);
assert.ok(w.valid());
assert.deepStrictEqual(
w.getAllExternalAddresses().map(elem => elem.toUpperCase()),
[secret.toUpperCase()],
);
assert.strictEqual(w.isHd(), false);
2021-04-19 13:09:35 +02:00
assert.ok(!w.useWithHardwareWalletEnabled());
}
w.setSecret('not valid');
assert.ok(!w.valid());
for (const secret of [
'xpub6CQdfC3v9gU86eaSn7AhUFcBVxiGhdtYxdC5Cw2vLmFkfth2KXCMmYcPpvZviA89X6DXDs4PJDk5QVL2G2xaVjv7SM4roWHr1gR4xB3Z7Ps',
'ypub6XRzrn3HB1tjhhvrHbk1vnXCecZEdXohGzCk3GXwwbDoJ3VBzZ34jNGWbC6WrS7idXrYjjXEzcPDX5VqnHEnuNf5VAXgLfSaytMkJ2rwVqy',
'zpub6r7jhKKm7BAVx3b3nSnuadY1WnshZYkhK8gKFoRLwK9rF3Mzv28BrGcCGA3ugGtawi1WLb2vyjQAX9ZTDGU5gNk2bLdTc3iEXr6tzR1ipNP',
]) {
w.setSecret(secret);
assert.ok(w.valid());
assert.strictEqual(w.isHd(), true);
assert.strictEqual(w.getMasterFingerprint(), false);
assert.strictEqual(w.getMasterFingerprintHex(), '00000000');
assert.ok(w.isXpubValid(), w.secret);
2021-04-19 13:09:35 +02:00
assert.ok(!w.useWithHardwareWalletEnabled());
}
});
it('can validate xpub', () => {
const w = new WatchOnlyWallet();
w.setSecret('xpub6CQdfC3v9gU86eaSn7AhUFcBVxiGhdtYxdC5Cw2vLmFkfth2KXCMmYcPpvZviA89X6DXDs4PJDk5QVL2G2xaVjv7SM4roWHr1gR4xB3Z7Ps');
assert.ok(w.isXpubValid());
assert.ok(w.valid());
w.setSecret('ypub6XRzrn3HB1tjhhvrHbk1vnXCecZEdXohGzCk3GXwwbDoJ3VBzZ34jNGWbC6WrS7idXrYjjXEzcPDX5VqnHEnuNf5VAXgLfSaytMkJ2rwVqy');
assert.ok(w.isXpubValid());
assert.ok(w.valid());
w.setSecret('zpub6r7jhKKm7BAVx3b3nSnuadY1WnshZYkhK8gKFoRLwK9rF3Mzv28BrGcCGA3ugGtawi1WLb2vyjQAX9ZTDGU5gNk2bLdTc3iEXr6tzR1ipNP');
assert.ok(w.isXpubValid());
assert.ok(w.valid());
w.setSecret('xpub6CQdfC3v9gU86eaSn7AhUFcBVxiGhdtYxdC5Cw2vLmFkfth2KXCMmYcPpvZviA89X6D');
assert.ok(!w.isXpubValid());
assert.ok(!w.valid());
w.setSecret('ypub6XRzrn3HB1tjhhvrHbk1vnXCecZEdXohGzCk3GXwwbDoJ3VBzZ34jNGWbC6WrS7idXr');
assert.ok(!w.isXpubValid());
assert.ok(!w.valid());
w.setSecret('ypub6XRzrn3HB1tjhhvrHbk1vnXCecZEdXohGzCk3GXwwbDoJ3VBzZ34jNGWbC6WrS7idXr');
assert.ok(!w.isXpubValid());
assert.ok(!w.valid());
});
it('can create PSBT base64 without signature for HW wallet xpub', async () => {
const w = new WatchOnlyWallet();
w.setSecret('xpub6CQdfC3v9gU86eaSn7AhUFcBVxiGhdtYxdC5Cw2vLmFkfth2KXCMmYcPpvZviA89X6DXDs4PJDk5QVL2G2xaVjv7SM4roWHr1gR4xB3Z7Ps');
w.init();
const changeAddress = '1KZjqYHm7a1DjhjcdcjfQvYfF2h6PqatjX';
// hardcoding so we wont have to call w.getChangeAddressAsync()
const utxos = [
{
height: 530926,
value: 1000,
address: '12eQ9m4sgAwTSQoNXkRABKhCXCsjm2jdVG',
txid: 'd0432027a86119c63a0be8fa453275c2333b59067f1e559389cd3e0e377c8b96',
vout: 1,
txhex:
'0100000001b630ac364a04b83548994ded4705b98316b2d1fe18b9fffa2627be9eef11bf60000000006b48304502210096e68d94d374e3a688ed2e6605289f81172540abaab5f6cc431c231919860746022075ee4e64c867ed9d369d01a9b35d8b1689a821be8d729fff7fb3dfcc75d16f6401210281d2e40ba6422fc97b61fd5643bee83dd749d8369339edc795d7b3f00e96c681fdffffff02ef020000000000001976a914e4271ef9e9a03a89b981c73d3d6936d2f6fccc0688ace8030000000000001976a914120ad7854152901ebeb269acb6cef20e71b3cf5988acea190800',
},
];
// hardcoding utxo so we wont have to call w.fetchUtxo() and w.getUtxo()
const { psbt } = await w.createTransaction(utxos, [{ address: '1QDCFcpnrZ4yrAQxmbvSgeUC9iZZ8ehcR5' }], 1, changeAddress);
assert.strictEqual(
psbt.toBase64(),
'cHNidP8BAFUCAAAAAZaLfDcOPs2Jk1UefwZZOzPCdTJF+ugLOsYZYagnIEPQAQAAAAAAAACAASgDAAAAAAAAGXapFP6ZRvxlaU5S/9HQFr1i2lsgp58AiKwAAAAAAAEA4gEAAAABtjCsNkoEuDVImU3tRwW5gxay0f4Yuf/6Jie+nu8Rv2AAAAAAa0gwRQIhAJbmjZTTdOOmiO0uZgUon4EXJUCrqrX2zEMcIxkZhgdGAiB17k5kyGftnTadAamzXYsWiaghvo1yn/9/s9/MddFvZAEhAoHS5AumQi/Je2H9VkO+6D3XSdg2kzntx5XXs/AOlsaB/f///wLvAgAAAAAAABl2qRTkJx756aA6ibmBxz09aTbS9vzMBois6AMAAAAAAAAZdqkUEgrXhUFSkB6+smmsts7yDnGzz1mIrOoZCAAiBgPGm5BfckKzaIEi8GlRM5oe4A2mUvbsxlJ+pmMhRsrOYhgAAAAALAAAgAAAAIAAAACAAAAAAAAAAAAAAA==',
);
});
it('can create PSBT base64 without signature for HW wallet ypub', async () => {
const w = new WatchOnlyWallet();
w.setSecret('ypub6XRzrn3HB1tjhhvrHbk1vnXCecZEdXohGzCk3GXwwbDoJ3VBzZ34jNGWbC6WrS7idXrYjjXEzcPDX5VqnHEnuNf5VAXgLfSaytMkJ2rwVqy');
w.init();
const changeAddress = '333R1N8zst8bK7xMtqBndmwcd288qxEBmr';
// hardcoding so we wont have to call w.getChangeAddressAsync()
const utxos = [
{
height: 566299,
value: 250000,
address: '37EX3KrmopubWPLB8Y8NR36wXs7icu2kjQ',
txid: '786f05d0c531c4bb399ab8cf406b2f118504280bd015e26e4ff9539f8201d4f4',
vout: 0,
},
];
// hardcoding utxo so we wont have to call w.fetchUtxo() and w.getUtxo()
const { psbt } = await w.createTransaction(utxos, [{ address: '398qz3BtNG8DABpEGa2VkHBcficxkgeKvX' }], 1, changeAddress);
assert.strictEqual(
psbt.toBase64(),
'cHNidP8BAFMCAAAAAfTUAYKfU/lPbuIV0AsoBIURL2tAz7iaObvEMcXQBW94AAAAAAAAAACAAdDPAwAAAAAAF6kUUatl8TFvnlvB8H/KsqbnR6kpUluHAAAAAAABASCQ0AMAAAAAABepFDzN1E7LDjAMNARzCHsU4rXqBf55hwEEFgAUG3vPJhyWYtt/ikPpOCW6jCqkmxsiBgLHMhb0QhE8eyJBnE9syGAtMehGmHe1sxpm+TlxjgFXERgAAAAAMQAAgAAAAIAAAACAAAAAAAAAAAAAAA==',
);
});
it('can create PSBT base64 without signature for HW wallet zpub', async () => {
const w = new WatchOnlyWallet();
2019-09-27 16:49:56 +02:00
w.setSecret('zpub6rjLjQVqVnj7crz9E4QWj4WgczmEseJq22u2B6k2HZr6NE2PQx3ZYg8BnbjN9kCfHymSeMd2EpwpM5iiz5Nrb3TzvddxW2RMcE3VXdVaXHk');
// zpub provided by Stepan @ CryptoAdvance
w.init();
const changeAddress = 'bc1quuafy8htjjj263cvpj7md84magzmc8svmh8lrm';
// hardcoding so we wont have to call w.getChangeAddressAsync()
const utxos = [
{
height: 596736,
value: 20000,
address: 'bc1qhu8jqyzfazgatpctqn44xr7pdd3mdx6qy2r6xa',
txId: '7f3b9e032a84413d7a5027b0d020f8acf80ad28f68b5bce8fa8ac357248c5b80',
vout: 0,
},
];
// hardcoding utxo so we wont have to call w.fetchUtxo() and w.getUtxo()
const { psbt } = await w.createTransaction(
2019-09-27 16:49:56 +02:00
utxos,
[{ address: 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu', value: 5000 }],
1,
changeAddress,
);
assert.strictEqual(
psbt.toBase64(),
'cHNidP8BAHECAAAAAYBbjCRXw4r66Ly1aI/SCvis+CDQsCdQej1BhCoDnjt/AAAAAAAAAACAAogTAAAAAAAAFgAUwM681sPTyox13F7GLr5VMw75EOK2OQAAAAAAABYAFOc6kh7rlKStRwwMvbaeu+oFvB4MAAAAAAABAR8gTgAAAAAAABYAFL8PIBBJ6JHVhwsE61MPwWtjtptAIgYDWOHbOE3D4KiuoR7kHtmTtFZ7KXQB+8zb51QALLJxTx8YAAAAAFQAAIAAAACAAAAAgAAAAAAAAAAAAAAiAgM005BVD8MgH5kiSGnwXSfzaxLeDSl3y17Vhrx3F/9XxBgAAAAAVAAAgAAAAIAAAACAAQAAAAAAAAAA',
2019-09-27 16:49:56 +02:00
);
});
2020-02-24 22:45:14 +01:00
it('can import coldcard/electrum compatible JSON skeleton wallet, and create a tx with master fingerprint', async () => {
const w = new WatchOnlyWallet();
w.setSecret(require('fs').readFileSync('./tests/unit/fixtures/skeleton-coldcard.txt', 'ascii'));
2020-02-24 22:45:14 +01:00
w.init();
assert.ok(w.valid());
assert.strictEqual(
w.getSecret(),
'zpub6rFDtF1nuXZ9PUL4XzKURh3vJBW6Kj6TUrYL4qPtFNtDXtcTVfiqjQDyrZNwjwzt5HS14qdqo3Co2282Lv3Re6Y5wFZxAVuMEpeygnnDwfx',
);
assert.strictEqual(w.getMasterFingerprint(), 64392470);
assert.strictEqual(w.getMasterFingerprintHex(), '168dd603');
2021-04-19 13:09:35 +02:00
assert.ok(w.useWithHardwareWalletEnabled());
2020-02-24 22:45:14 +01:00
const utxos = [
{
height: 618811,
value: 66600,
address: 'bc1qzqjwye4musmz56cg44ttnchj49zueh9yr0qsxt',
txId: '5df595dc09ee7a5c245b34ea519288137ffee731629c4ff322a6de4f72c06222',
vout: 0,
txid: '5df595dc09ee7a5c245b34ea519288137ffee731629c4ff322a6de4f72c06222',
amount: 66600,
wif: false,
confirmations: 1,
},
];
const { psbt } = await w.createTransaction(
2021-02-08 05:59:31 +01:00
utxos,
[{ address: 'bc1qdamevhw3zwm0ajsmyh39x8ygf0jr0syadmzepn', value: 5000 }],
22,
'bc1qtutssamysdkgd87df0afjct0mztx56qpze7wqe',
);
assert.strictEqual(
psbt.toBase64(),
'cHNidP8BAHECAAAAASJiwHJP3qYi80+cYjHn/n8TiJJR6jRbJFx67gnclfVdAAAAAAAAAACAAogTAAAAAAAAFgAUb3eWXdETtv7KGyXiUxyIS+Q3wJ003QAAAAAAABYAFF8XCHdkg2yGn81L+plhb9iWamgBAAAAAAABAR8oBAEAAAAAABYAFBAk4ma75DYqawitVrni8qlFzNykIgYDNK9TxoCjQ8P0+qI2Hu4hrnXnJuYAC3h2puZbgRORp+sYFo3WA1QAAIAAAACAAAAAgAAAAAAAAAAAAAAiAgL1DWeV+AfIP5RRB5zHv5vuXsIt8+rF9rrsji3FhQlhzBgWjdYDVAAAgAAAAIAAAACAAQAAAAAAAAAA',
);
});
it('can import Electrum compatible backup wallet, and create a tx with master fingerprint', async () => {
const w = new WatchOnlyWallet();
w.setSecret(require('fs').readFileSync('./tests/unit/fixtures/skeleton-electrum.txt', 'ascii'));
2021-02-08 05:59:31 +01:00
w.init();
assert.ok(w.valid());
assert.strictEqual(
w.getSecret(),
'zpub6rFDtF1nuXZ9PUL4XzKURh3vJBW6Kj6TUrYL4qPtFNtDXtcTVfiqjQDyrZNwjwzt5HS14qdqo3Co2282Lv3Re6Y5wFZxAVuMEpeygnnDwfx',
);
assert.strictEqual(w.getMasterFingerprint(), 64392470);
assert.strictEqual(w.getMasterFingerprintHex(), '168dd603');
2021-04-19 13:09:35 +02:00
assert.ok(w.useWithHardwareWalletEnabled());
2021-02-08 05:59:31 +01:00
const utxos = [
{
height: 618811,
value: 66600,
address: 'bc1qzqjwye4musmz56cg44ttnchj49zueh9yr0qsxt',
txId: '5df595dc09ee7a5c245b34ea519288137ffee731629c4ff322a6de4f72c06222',
vout: 0,
txid: '5df595dc09ee7a5c245b34ea519288137ffee731629c4ff322a6de4f72c06222',
amount: 66600,
wif: false,
confirmations: 1,
},
];
const { psbt } = await w.createTransaction(
2020-02-24 22:45:14 +01:00
utxos,
[{ address: 'bc1qdamevhw3zwm0ajsmyh39x8ygf0jr0syadmzepn', value: 5000 }],
22,
'bc1qtutssamysdkgd87df0afjct0mztx56qpze7wqe',
);
assert.strictEqual(
psbt.toBase64(),
'cHNidP8BAHECAAAAASJiwHJP3qYi80+cYjHn/n8TiJJR6jRbJFx67gnclfVdAAAAAAAAAACAAogTAAAAAAAAFgAUb3eWXdETtv7KGyXiUxyIS+Q3wJ003QAAAAAAABYAFF8XCHdkg2yGn81L+plhb9iWamgBAAAAAAABAR8oBAEAAAAAABYAFBAk4ma75DYqawitVrni8qlFzNykIgYDNK9TxoCjQ8P0+qI2Hu4hrnXnJuYAC3h2puZbgRORp+sYFo3WA1QAAIAAAACAAAAAgAAAAAAAAAAAAAAiAgL1DWeV+AfIP5RRB5zHv5vuXsIt8+rF9rrsji3FhQlhzBgWjdYDVAAAgAAAAIAAAACAAQAAAAAAAAAA',
2020-02-24 22:45:14 +01:00
);
});
it('can import cobo vault JSON skeleton wallet', async () => {
const w = new WatchOnlyWallet();
w.setSecret(require('fs').readFileSync('./tests/unit/fixtures/skeleton-cobo.txt', 'ascii'));
w.init();
assert.ok(w.valid());
assert.strictEqual(
w.getSecret(),
'zpub6rcabYFcdr41zyUNRWRyHYs2Sm86E5XV8RjjRzTFYsiCngteeZnkwaF2xuhjmM6kpHjuNpFW42BMhzPmFwXt48e1FhddMB7xidZzN4SF24K',
);
assert.strictEqual(w.getMasterFingerprint(), 1908437330);
assert.strictEqual(w.getMasterFingerprintHex(), '5271c071');
assert.strictEqual(w.getLabel(), 'Cobo Vault 5271c071');
2021-04-19 13:09:35 +02:00
assert.ok(w.useWithHardwareWalletEnabled());
});
it('can import zpub with master fingerprint', async () => {
const w = new WatchOnlyWallet();
w.setSecret(require('fs').readFileSync('./tests/unit/fixtures/skeleton-walletdescriptor.txt', 'ascii'));
w.init();
assert.ok(w.valid());
assert.strictEqual(
w.getSecret(),
'zpub6s2RJ9qAEBW8Abhojs6LyDzF7gttcDr6EsR3Umu2aptZBb45e734rGtt4KqsCMmNyR1EEzUU2ugdVYez2VywQvAbBjUSKn8ho4Zk2c5otkk',
);
assert.strictEqual(w.getMasterFingerprint(), 4167290508);
assert.strictEqual(w.getMasterFingerprintHex(), '8cce63f8');
2021-04-19 13:09:35 +02:00
assert.ok(!w.useWithHardwareWalletEnabled());
});
2019-09-27 16:49:56 +02:00
it('can combine signed PSBT and prepare it for broadcast', async () => {
const w = new WatchOnlyWallet();
2019-09-27 16:49:56 +02:00
w.setSecret('zpub6rjLjQVqVnj7crz9E4QWj4WgczmEseJq22u2B6k2HZr6NE2PQx3ZYg8BnbjN9kCfHymSeMd2EpwpM5iiz5Nrb3TzvddxW2RMcE3VXdVaXHk');
w.init();
const signedPsbt =
'cHNidP8BAHECAAAAAYBbjCRXw4r66Ly1aI/SCvis+CDQsCdQej1BhCoDnjt/AAAAAAAAAACAAogTAAAAAAAAFgAUwM681sPTyox13F7GLr5VMw75EOK3OQAAAAAAABYAFOc6kh7rlKStRwwMvbaeu+oFvB4MAAAAAAAiAgNY4ds4TcPgqK6hHuQe2ZO0VnspdAH7zNvnVAAssnFPH0cwRAIgPR9zZzNTnfPqZJifyUwdM2cWW8PZqCnSCsfCePlZ2aoCIFbhr/5P/bS6eGQZtX3+6q+nUO6KaSKYgaaZrUZENF6BAQAAAA==';
const unsignedPsbt =
'cHNidP8BAHECAAAAAYBbjCRXw4r66Ly1aI/SCvis+CDQsCdQej1BhCoDnjt/AAAAAAAAAACAAogTAAAAAAAAFgAUwM681sPTyox13F7GLr5VMw75EOK3OQAAAAAAABYAFOc6kh7rlKStRwwMvbaeu+oFvB4MAAAAAAABAR8gTgAAAAAAABYAFL8PIBBJ6JHVhwsE61MPwWtjtptAIgYDWOHbOE3D4KiuoR7kHtmTtFZ7KXQB+8zb51QALLJxTx8YAAAAAFQAAIAAAACAAAAAgAAAAAAAAAAAAAAiAgM005BVD8MgH5kiSGnwXSfzaxLeDSl3y17Vhrx3F/9XxBgAAAAAVAAAgAAAAIAAAACAAQAAAAAAAAAA';
const Tx = w.combinePsbt(unsignedPsbt, signedPsbt);
assert.strictEqual(
Tx.toHex(),
'02000000000101805b8c2457c38afae8bcb5688fd20af8acf820d0b027507a3d41842a039e3b7f000000000000000080028813000000000000160014c0cebcd6c3d3ca8c75dc5ec62ebe55330ef910e2b739000000000000160014e73a921eeb94a4ad470c0cbdb69ebbea05bc1e0c0247304402203d1f736733539df3ea64989fc94c1d3367165bc3d9a829d20ac7c278f959d9aa022056e1affe4ffdb4ba786419b57dfeeaafa750ee8a69229881a699ad4644345e8101210358e1db384dc3e0a8aea11ee41ed993b4567b297401fbccdbe754002cb2714f1f00000000',
);
// checking that combine can work with both base64 and pure Psbt objects
const Tx2 = w.combinePsbt(Psbt.fromBase64(unsignedPsbt), Psbt.fromBase64(signedPsbt));
assert.strictEqual(Tx2.toHex(), Tx.toHex());
2019-09-27 16:49:56 +02:00
});
2020-03-31 13:05:27 +02:00
it('ypub watch-only can generate addresses', async () => {
const w = new WatchOnlyWallet();
2019-06-14 21:18:49 +02:00
w.setSecret('ypub6Y9u3QCRC1HkZv3stNxcQVwmw7vC7KX5Ldz38En5P88RQbesP2oy16hNyQocVCfYRQPxdHcd3pmu9AFhLv7NdChWmw5iNLryZ2U6EEHdnfo');
2020-03-31 13:05:27 +02:00
w.init();
assert.ok((await w._getExternalAddressByIndex(0)).startsWith('3'));
assert.ok(w.getAllExternalAddresses().includes(await w._getExternalAddressByIndex(0)));
});
2020-03-31 13:05:27 +02:00
it('xpub watch-only can generate addresses', async () => {
const w = new WatchOnlyWallet();
w.setSecret('xpub6CQdfC3v9gU86eaSn7AhUFcBVxiGhdtYxdC5Cw2vLmFkfth2KXCMmYcPpvZviA89X6DXDs4PJDk5QVL2G2xaVjv7SM4roWHr1gR4xB3Z7Ps');
2020-03-31 13:05:27 +02:00
w.init();
assert.ok((await w._getExternalAddressByIndex(0)).startsWith('1'));
assert.ok(w.getAllExternalAddresses().includes(await w._getExternalAddressByIndex(0)));
2019-05-12 22:49:43 +02:00
});
2020-10-29 20:03:13 +01:00
it('can determine change address for HD wallet', async () => {
const w = new WatchOnlyWallet();
w.setSecret('ypub6Y9u3QCRC1HkZv3stNxcQVwmw7vC7KX5Ldz38En5P88RQbesP2oy16hNyQocVCfYRQPxdHcd3pmu9AFhLv7NdChWmw5iNLryZ2U6EEHdnfo');
w.init();
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', () => {
it('can decodeUR() and then combine unfinalized signed PSBT', () => {
const unsignedPayload = decodeUR([
'UR:BYTES/TYQ4XURNVF607QGQWYPQQQQQQ9U63JU4AD5C93Y057WNRNTV24AE8QK4DDHVT04GHTKNQZCXYHNW5QGQQQQQPLHLLLLS9LRRQQQQQQQQQQTQQ9P9YMAAVV5GVUNKD49W4GDNJ4C9GJP7383QFCQQQQQQQQQPVQQ5CXKNG9PNTGMDRV0GNWNJZS23KGG3V0KXQQQQQQQQQYQ375XRQQQQQQQQQQTQQ98UXJHTKAHE83Q8W5VGHH2G93698VZLP6PZQCPXW47RAFD36W04SNHNTZK8CLCWHXDJJRRZ2EP998STFNRYWFQPC0CC3N8X87Z5QQQGQQQQQZQQQQQQSQQQQQQQQQQQQQQQYGPQY5M4J23F3Z9TK6HZTRDD6M89QX955DEH3HXGXAC6NJQMT3CHYTJHRZXVUCLC2SQQPQQQQQQGQQQQQZQQZQQQQQQQQQQQQQ3QYQK6E2MCA75ZCRMMWZYWXNQKGKNNJC7JUXPNWR5QPYQC3EYRM4NDQ5VGENNRLP2QQQYQQQQQPQQQQQQGQQQQQQQQZQQQQQQQ6GYX3G',
]);
const uPsbtB64 = Buffer.from(unsignedPayload, 'hex').toString('base64');
const payloadSignedButNotFinalized = decodeUR([
'UR:BYTES/TR58QUMZWNLSZQR3QGQQQQQP0X5VH90TDXPVFRA8N5CU6MZ40WFC94TTDMZMA296A5CQKP39UM4QZQQQQQQ0ALLLLUP0CCCQQQQQQQQQZCQPGFFXL0TR9ZR8YANDFT42RVU4WP2YS05FUGZWQQQQQQQQQQTQQ9XP456PGV66XMGMR6YM5US5Z5DJZYTRA3SQQQQQQQPZQGPXW47RAFD36W04SNHNTZK8CLCWHXDJJRRZ2EP998STFNRYWFQPC068XPZQYGRH45ESDZ623KSNPTY2VJ37LWA2HTCCLGSDWPDDEPK48JAKNSVZTQPZQD0W5ND2M7D62YYQ74A85DRKM8ESQS2WSTZ5F4V2YNNGY9S7F0NSQYQQQQQ7VRJ5Z',
]);
const sPsbtB64 = Buffer.from(payloadSignedButNotFinalized, 'hex').toString('base64');
const w = new WatchOnlyWallet();
w.setSecret('zpub6s2RJ9qAEBW8Abhojs6LyDzF7gttcDr6EsR3Umu2aptZBb45e734rGtt4KqsCMmNyR1EEzUU2ugdVYez2VywQvAbBjUSKn8ho4Zk2c5otkk');
w.init();
const tx = w.combinePsbt(uPsbtB64, sPsbtB64);
assert.strictEqual(
tx.toHex(),
'0200000000010179a8cb95eb6982c48fa79d31cd6c557b9382d56b6ec5bea8baed300b0625e6ea0100000000feffffff02fc630000000000001600142526fbd63288672766d4aeaa1b3957054483e89e204e000000000000160014c1ad3414335a36d1b1e89ba7214151b211163ec602473044022077ad33068b4a8da130ac8a64a3efbbaabaf18fa20d705adc86d53cbb69c18258022035eea4daadf9ba51080f57a7a3476d9f300414e82c544d58a24e682161e4be700121026757c3ea5b1d39f584ef358ac7c7f0eb99b290c625642529e0b4cc6472401c3f00000000',
);
});
});