BlueWallet/tests/unit/hd-legacy-breadwallet.test.js

51 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-11-27 14:42:12 +01:00
import assert from 'assert';
import { HDLegacyBreadwalletWallet } from '../../class';
2022-04-17 22:22:25 +02:00
describe('HDLegacyBreadwalletWallet', () => {
it('Legacy HD Breadwallet works', async () => {
if (!process.env.HD_MNEMONIC_BREAD) {
console.error('process.env.HD_MNEMONIC_BREAD not set, skipped');
return;
}
const hdBread = new HDLegacyBreadwalletWallet();
hdBread.setSecret(process.env.HD_MNEMONIC_BREAD);
2022-04-17 22:22:25 +02:00
assert.strictEqual(hdBread.validateMnemonic(), true);
assert.strictEqual(hdBread._getExternalAddressByIndex(0), '1M1UphJDb1mpXV3FVEg6b2qqaBieNuaNrt');
assert.strictEqual(hdBread._getInternalAddressByIndex(0), '1A9Sc4opR6c7Ui6NazECiGmsmnUPh2WeHJ');
hdBread._internal_segwit_index = 2;
hdBread._external_segwit_index = 2;
assert.ok(hdBread._getExternalAddressByIndex(0).startsWith('1'));
assert.ok(hdBread._getInternalAddressByIndex(0).startsWith('1'));
assert.strictEqual(hdBread._getExternalAddressByIndex(2), 'bc1qh0vtrnjn7zs99j4n6xaadde95ctnnvegh9l2jn');
assert.strictEqual(hdBread._getInternalAddressByIndex(2), 'bc1qk9hvkxqsqmps6ex3qawr79rvtg8es4ecjfu5v0');
2020-11-27 14:42:12 +01:00
2022-04-17 22:22:25 +02:00
assert.strictEqual(hdBread._getDerivationPathByAddress('1M1UphJDb1mpXV3FVEg6b2qqaBieNuaNrt'), "m/0'/0/0");
assert.strictEqual(hdBread._getDerivationPathByAddress('bc1qk9hvkxqsqmps6ex3qawr79rvtg8es4ecjfu5v0'), "m/0'/1/2");
2020-11-27 14:42:12 +01:00
2022-04-17 22:22:25 +02:00
assert.strictEqual(
hdBread._getPubkeyByAddress(hdBread._getExternalAddressByIndex(0)).toString('hex'),
'029ba027f3f0a9fa69ce680a246198d56a3b047108f26791d1e4aa2d10e7e7a29a',
);
assert.strictEqual(
hdBread._getPubkeyByAddress(hdBread._getInternalAddressByIndex(0)).toString('hex'),
'03074225b31a95af63de31267104e07863d892d291a33ef5b2b32d59c772d5c784',
);
2022-04-17 22:22:25 +02:00
assert.strictEqual(
hdBread.getXpub(),
'xpub68hPk9CrHimZMBQEja43qWRC2TuXmCDdgZcR5YMebr38XatUEPu2Q2oaBViSMshDcyuMDGkGbTS2aqNHFKdcN1sFWaZgK6SLg84dtN7Ym64',
);
2020-11-27 14:42:12 +01:00
2022-04-17 22:22:25 +02:00
assert.ok(hdBread.getAllExternalAddresses().includes('1M1UphJDb1mpXV3FVEg6b2qqaBieNuaNrt'));
assert.ok(hdBread.getAllExternalAddresses().includes('bc1qh0vtrnjn7zs99j4n6xaadde95ctnnvegh9l2jn'));
});
it('Can use french seed', async () => {
const hdBread = new HDLegacyBreadwalletWallet();
hdBread.setSecret('abaisser abaisser abaisser abaisser abaisser abaisser abaisser abaisser abaisser abaisser abaisser abeille');
assert.strictEqual(hdBread.validateMnemonic(), true);
assert.strictEqual(hdBread._getExternalAddressByIndex(0), '1JFdzwd8SqFn5LeeiDKcbYUfXxvButqXgX');
});
});