Skip to content
Open
3 changes: 3 additions & 0 deletions __tests__/integration/hd-segwit-bech32-wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ describe('Bech32 Segwit HD (BIP84)', () => {
assert.strictEqual(hd.getNextFreeAddressIndex(), 2);
assert.strictEqual(hd.next_free_change_address_index, 2);

// fetch multiple addresses starting with first free address index
assert.strictEqual(await hd.getNextAddressesAsync(5)[2].address, hd._getExternalAddressByIndex(3));

// now fetch txs
await hd.fetchTransactions();
assert.ok(hd._lastTxFetch > 0);
Expand Down
25 changes: 25 additions & 0 deletions __tests__/unit/hd-segwit-bech32-wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ describe('Bech32 Segwit HD (BIP84)', () => {
assert.strictEqual(hd._getDerivationPathByAddress(hd._getExternalAddressByIndex(1)), "m/84'/0'/0'/0/1");
assert.strictEqual(hd._getDerivationPathByAddress(hd._getInternalAddressByIndex(0)), "m/84'/0'/0'/1/0");
assert.strictEqual(hd._getDerivationPathByAddress(hd._getInternalAddressByIndex(1)), "m/84'/0'/0'/1/1");

// fetch multiple addresses starting with first free address index
assert.strictEqual((await hd.getNextAddressesAsync(5))[0].address, hd._getExternalAddressByIndex(0));
assert.strictEqual((await hd.getNextAddressesAsync(5))[1].address, hd._getExternalAddressByIndex(1));
assert.strictEqual((await hd.getNextAddressesAsync(5))[2].address, hd._getExternalAddressByIndex(2));
assert.strictEqual((await hd.getNextAddressesAsync(5))[3].address, hd._getExternalAddressByIndex(3));
assert.strictEqual((await hd.getNextAddressesAsync(5))[4].address, hd._getExternalAddressByIndex(4));
});

it('can generate addresses only via zpub', function () {
Expand Down Expand Up @@ -74,4 +81,22 @@ describe('Bech32 Segwit HD (BIP84)', () => {
hd2.setSecret(hd.getSecret());
assert.ok(hd2.validateMnemonic());
});

it('signs and verifies messages', async () => {
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const hd = new HDSegwitBech32Wallet();
hd.setSecret(mnemonic);
assert.strictEqual(hd._getExternalAddressByIndex(0), 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu');
assert.strictEqual(
hd.signMessage('running bitcoin', hd._getExternalAddressByIndex(0), true),
'IJXWxJ3J7lxfIAWK6NDSfMrK2C9Zjyse5zfG+AGp3CzpZ0uUnaLwouZtcQfZjCicZ02NsqkGUTnj9D7ky91tLQk=',
);
assert.ok(
hd.verifyMessage(
'running bitcoin',
hd._getExternalAddressByIndex(0),
'IJXWxJ3J7lxfIAWK6NDSfMrK2C9Zjyse5zfG+AGp3CzpZ0uUnaLwouZtcQfZjCicZ02NsqkGUTnj9D7ky91tLQk=',
),
);
});
});
18 changes: 18 additions & 0 deletions __tests__/unit/hd-segwit-p2sh-wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,21 @@ it('can fullfill user generated entropy if less than 32 bytes provided', async (

assert.ok(secret.split(' ').length === 12 || secret.split(' ').length === 24);
});

it('signs and verifies messages', async () => {
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
const hd = new HDSegwitP2SHWallet();
hd.setSecret(mnemonic);
assert.strictEqual(hd._getExternalAddressByIndex(0), '37VucYSaXLCAsxYyAPfbSi9eh4iEcbShgf');
assert.strictEqual(
hd.signMessage('running bitcoin', hd._getExternalAddressByIndex(0), true),
'H/+rN386XGg2gcekDIzMk1XtvN5iZnAhxfk+Usnlsl55CxGAF/Ci78VRl1ZkG+y6yjbm73JEHUIWq64FsHPbBG4=',
);
assert.ok(
hd.verifyMessage(
'running bitcoin',
hd._getExternalAddressByIndex(0),
'H/+rN386XGg2gcekDIzMk1XtvN5iZnAhxfk+Usnlsl55CxGAF/Ci78VRl1ZkG+y6yjbm73JEHUIWq64FsHPbBG4=',
),
);
});
Loading