From b6a479e64be1874517063ef686e4c5fec5cb236b Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 10 Nov 2024 13:25:03 -0800 Subject: [PATCH] Test additional accounts when deriving from BLAKE2b wallet. Test more BLAKE2b wallet seeds. Use Trezor wallet password instead of Nano password for consistency with Trezor test vectors. --- test/import-wallet.test.mjs | 50 +++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/test/import-wallet.test.mjs b/test/import-wallet.test.mjs index 960c70f..7fd35f0 100644 --- a/test/import-wallet.test.mjs +++ b/test/import-wallet.test.mjs @@ -140,36 +140,60 @@ describe('import wallet with test vectors test', () => { it('should successfully import a BLAKE2b wallet with Trezor test vectors', async () => { const wallet = await Blake2bWallet.fromMnemonic(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1) await wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD) - const accounts = await wallet.accounts() + const accounts = await wallet.accounts(0, 1) assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) - assert.ok(accounts[0] instanceof Account) assert.equal(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_1) assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) - assert.equal(accounts[0].privateKey, TREZOR_TEST_VECTORS.NANOS_CC_PRIVATE_1) - assert.equal(accounts[0].publicKey, TREZOR_TEST_VECTORS.NANOS_CC_PUBLIC_1) - assert.equal(accounts[0].address, TREZOR_TEST_VECTORS.NANOS_CC_ADDRESS_1) + assert.ok(accounts[0] instanceof Account) + assert.equal(accounts[0].index, 0) + assert.equal(accounts[0].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_0) + assert.equal(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0) + assert.equal(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0) + assert.ok(accounts[1] instanceof Account) + assert.equal(accounts[1].index, 1) + assert.equal(accounts[1].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_1) + assert.equal(accounts[1].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1) + assert.equal(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1) }) it('should get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => { - const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0) - await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + const wallet = await Blake2bWallet.fromSeed(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2) + await wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD) const walletAccounts = await wallet.accounts() + const walletAccount = walletAccounts[0] assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) - assert.ok(walletAccounts[0]) - assert.equal(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0) + assert.ok(walletAccount) + assert.equal(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_2) - const imported = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_0) - await imported.unlock(NANO_TEST_VECTORS.PASSWORD) + const imported = await Blake2bWallet.fromMnemonic(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_2) + await imported.unlock(TREZOR_TEST_VECTORS.PASSWORD) const importedAccounts = await imported.accounts() + const importedAccount = importedAccounts[0] assert.equal(imported.mnemonic, wallet.mnemonic) assert.equal(imported.seed, wallet.seed) - assert.equal(importedAccounts[0].privateKey, walletAccounts[0].privateKey) - assert.equal(importedAccounts[0].publicKey, walletAccounts[0].publicKey) + assert.equal(importedAccount.privateKey, walletAccount.privateKey) + assert.equal(importedAccount.publicKey, walletAccount.publicKey) + }) + + it('should get identical BLAKE2b wallets when created with max entropy value', async () => { + const wallet = await Blake2bWallet.fromMnemonic(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3) + await wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD) + const accounts = await wallet.accounts() + + assert.ok('mnemonic' in wallet) + assert.ok('seed' in wallet) + assert.ok(accounts[0] instanceof Account) + assert.equal(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_3) + assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_3) + assert.equal(accounts[0].index, 0) + assert.equal(accounts[0].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PRIVATE_0) + assert.equal(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PUBLIC_0) + assert.equal(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0) }) }) -- 2.34.1