\r
'use strict'\r
\r
-import { assert, test } from '#test/GLOBALS.mjs'\r
+import { assert, test } from '#GLOBALS.mjs'\r
import { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/TEST_VECTORS.js'\r
import { Account, Bip44Wallet, Blake2bWallet } from '#dist/main.js'\r
\r
-test('import wallet with test vectors test', () => {\r
- test('should successfully import a wallet with the official Nano test vectors mnemonic', async () => {\r
- const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
- assert.equals(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC)\r
- assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
- assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
- assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
- assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
- })\r
-\r
- test('should successfully import a wallet with the checksum starting with a zero', async () => {\r
- const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, 'food define cancel major spoon trash cigar basic aim bless wolf win ability seek paddle bench seed century group they mercy address monkey cake')\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- assert.equals(wallet.seed, 'F665F804E5907985455D1E5A7AD344843A2ED4179A7E06EEF263DE925FF6F4C0991B0A9344FCEE939FE0F1B1841B8C9B20FEACF6B954B74B2D26A01906B758E2')\r
- })\r
-\r
- test('should successfully import a wallet with a 12-word phrase', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_0)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
- const account = accounts[0]\r
-\r
- assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_0)\r
- assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_0)\r
- assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_0)\r
- assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_0)\r
- assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0)\r
- })\r
-\r
- test('should successfully import a wallet with a 15-word phrase', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_1)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
- const account = accounts[0]\r
-\r
- assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_1)\r
- assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_1)\r
- assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_1)\r
- assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_1)\r
- assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1)\r
- })\r
-\r
- test('should successfully import a wallet with a 18-word phrase', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_2)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
- const account = accounts[0]\r
-\r
- assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_2)\r
- assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_2)\r
- assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_2)\r
- assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_2)\r
- assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2)\r
- })\r
-\r
- test('should successfully import a wallet with a 21-word phrase', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_3)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
- const account = accounts[0]\r
-\r
- assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_3)\r
- assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_3)\r
- assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_3)\r
- assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_3)\r
- assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3)\r
- })\r
-\r
- test('should successfully import a wallet with the official Nano test vectors seed', async () => {\r
- const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
- assert.equals(wallet.mnemonic, '')\r
- assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
- assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
- assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
- assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
- })\r
-\r
- test('should successfully import a BIP-44 wallet with the zero seed', async () => {\r
- const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0, TREZOR_TEST_VECTORS.PASSWORD)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts(0, 3)\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
- assert.equals(wallet.seed, TREZOR_TEST_VECTORS.SEED_0.toUpperCase())\r
- assert.equals(accounts.length, 4)\r
- for (let i = 0; i < accounts.length; i++) {\r
- assert.ok(accounts[i])\r
- assert.ok(accounts[i].address)\r
- assert.ok(accounts[i].publicKey)\r
- assert.ok(accounts[i].privateKey)\r
- assert.equals(accounts[i].index, i)\r
- }\r
- })\r
-\r
- test('should successfully import a BLAKE2b wallet with the zero seed', async () => {\r
- const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts(0, 3)\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
- assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0)\r
- assert.equals(accounts.length, 4)\r
- for (let i = 0; i < accounts.length; i++) {\r
- assert.ok(accounts[i])\r
- assert.ok(accounts[i].address)\r
- assert.ok(accounts[i].publicKey)\r
- assert.ok(accounts[i].privateKey)\r
- assert.equals(accounts[i].index, i)\r
- }\r
- })\r
-\r
- test('should successfully import a BLAKE2b wallet with Trezor test vectors', async () => {\r
- const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts(0, 1)\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
- assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
- assert.ok(accounts[0] instanceof Account)\r
- assert.equals(accounts[0].index, 0)\r
- assert.equals(accounts[0].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_0)\r
- assert.equals(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0)\r
- assert.equals(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0)\r
- assert.ok(accounts[1] instanceof Account)\r
- assert.equals(accounts[1].index, 1)\r
- assert.equals(accounts[1].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_1)\r
- assert.equals(accounts[1].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1)\r
- assert.equals(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1)\r
- })\r
-\r
- test('should get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => {\r
- const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const walletAccounts = await wallet.accounts()\r
- const walletAccount = walletAccounts[0]\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.ok(walletAccount)\r
- assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_2)\r
-\r
- const imported = await Blake2bWallet.fromMnemonic(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_2)\r
- await imported.unlock(TREZOR_TEST_VECTORS.PASSWORD)\r
- const importedAccounts = await imported.accounts()\r
- const importedAccount = importedAccounts[0]\r
-\r
- assert.equals(imported.mnemonic, wallet.mnemonic)\r
- assert.equals(imported.seed, wallet.seed)\r
- assert.equals(importedAccount.privateKey, walletAccount.privateKey)\r
- assert.equals(importedAccount.publicKey, walletAccount.publicKey)\r
- })\r
-\r
- test('should get identical BLAKE2b wallets when created with max entropy value', async () => {\r
- const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
- await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts()\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.ok(accounts[0] instanceof Account)\r
- assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
- assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_3)\r
- assert.equals(accounts[0].index, 0)\r
- assert.equals(accounts[0].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PRIVATE_0)\r
- assert.equals(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PUBLIC_0)\r
- assert.equals(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0)\r
- })\r
-})\r
-\r
-test('invalid wallet', async () => {\r
- test('throw when given invalid entropy', async () => {\r
- await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797'))\r
- await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701'))\r
- await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x')))\r
- })\r
-\r
- test('should throw when given a seed with an invalid length', async () => {\r
- await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'),\r
- `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length + 1}-character string.`)\r
- await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)),\r
- `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length - 1}-character string.`)\r
- })\r
-\r
- test('should throw when given a seed containing non-hex characters', async () => {\r
- await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')),\r
- 'Seed contains invalid hexadecimal characters.')\r
- await assert.rejects(Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')),\r
- 'Seed contains invalid hexadecimal characters.')\r
- })\r
-})\r
-\r
-test('import from storage', async () => {\r
- test('should retrieve a Bip44Wallet from storage using an ID', async () => {\r
- const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id\r
- const wallet = await Bip44Wallet.restore(id)\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, '')\r
- assert.equals(wallet.seed, '')\r
-\r
- const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
-\r
- assert.equals(unlockResult, true)\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC)\r
- assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
- })\r
-\r
- test('should retrieve a Blake2bWallet from storage using an ID', async () => {\r
- const id = (await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)).id\r
- const wallet = await Blake2bWallet.restore(id)\r
-\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, '')\r
- assert.equals(wallet.seed, '')\r
-\r
- const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
-\r
- assert.equals(unlockResult, true)\r
- assert.ok('mnemonic' in wallet)\r
- assert.ok('seed' in wallet)\r
- assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
- assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0)\r
- })\r
+test('import a wallet with the official Nano test vectors mnemonic', async () => {\r
+ const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.ok(accounts[0] instanceof Account)\r
+ assert.equals(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC)\r
+ assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
+ assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
+ assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
+ assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
+})\r
+\r
+test('import a wallet with the checksum starting with a zero', async () => {\r
+ const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, 'food define cancel major spoon trash cigar basic aim bless wolf win ability seek paddle bench seed century group they mercy address monkey cake')\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ assert.equals(wallet.seed, 'F665F804E5907985455D1E5A7AD344843A2ED4179A7E06EEF263DE925FF6F4C0991B0A9344FCEE939FE0F1B1841B8C9B20FEACF6B954B74B2D26A01906B758E2')\r
+})\r
+\r
+test('import a wallet with a 12-word phrase', async () => {\r
+ const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_0)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+ const account = accounts[0]\r
+\r
+ assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_0)\r
+ assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_0)\r
+ assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_0)\r
+ assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_0)\r
+ assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0)\r
+})\r
+\r
+test('import a wallet with a 15-word phrase', async () => {\r
+ const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_1)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+ const account = accounts[0]\r
+\r
+ assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_1)\r
+ assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_1)\r
+ assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_1)\r
+ assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_1)\r
+ assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1)\r
+})\r
+\r
+test('import a wallet with a 18-word phrase', async () => {\r
+ const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_2)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+ const account = accounts[0]\r
+\r
+ assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_2)\r
+ assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_2)\r
+ assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_2)\r
+ assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_2)\r
+ assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2)\r
+})\r
+\r
+test('import a wallet with a 21-word phrase', async () => {\r
+ const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_3)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+ const account = accounts[0]\r
+\r
+ assert.equals(wallet.mnemonic, CUSTOM_TEST_VECTORS.MNEMONIC_3)\r
+ assert.equals(wallet.seed, CUSTOM_TEST_VECTORS.SEED_3)\r
+ assert.equals(account.privateKey, CUSTOM_TEST_VECTORS.PRIVATE_3)\r
+ assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_3)\r
+ assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3)\r
+})\r
+\r
+test('import a wallet with the official Nano test vectors seed', async () => {\r
+ const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.ok(accounts[0] instanceof Account)\r
+ assert.equals(wallet.mnemonic, '')\r
+ assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
+ assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
+ assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
+ assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
+})\r
+\r
+test('import a BIP-44 wallet with the zero seed', async () => {\r
+ const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0, TREZOR_TEST_VECTORS.PASSWORD)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts(0, 3)\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
+ assert.equals(wallet.seed, TREZOR_TEST_VECTORS.SEED_0.toUpperCase())\r
+ assert.equals(accounts.length, 4)\r
+ for (let i = 0; i < accounts.length; i++) {\r
+ assert.ok(accounts[i])\r
+ assert.ok(accounts[i].address)\r
+ assert.ok(accounts[i].publicKey)\r
+ assert.ok(accounts[i].privateKey)\r
+ assert.equals(accounts[i].index, i)\r
+ }\r
+})\r
+\r
+test('import a BLAKE2b wallet with the zero seed', async () => {\r
+ const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts(0, 3)\r
+\r
+ console.log(`\nHERE 1\n`)\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
+ assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0)\r
+ assert.equals(accounts.length, 4)\r
+ console.log(`\nHERE 2\n`)\r
+ for (let i = 0; i < accounts.length; i++) {\r
+ assert.ok(accounts[i])\r
+ assert.ok(accounts[i].address)\r
+ assert.ok(accounts[i].publicKey)\r
+ assert.ok(accounts[i].privateKey)\r
+ assert.equals(accounts[i].index, i)\r
+ }\r
+})\r
+\r
+test('import a BLAKE2b wallet with Trezor test vectors', async () => {\r
+ const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts(0, 1)\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_1)\r
+ assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1)\r
+ assert.ok(accounts[0] instanceof Account)\r
+ assert.equals(accounts[0].index, 0)\r
+ assert.equals(accounts[0].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_0)\r
+ assert.equals(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0)\r
+ assert.equals(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0)\r
+ assert.ok(accounts[1] instanceof Account)\r
+ assert.equals(accounts[1].index, 1)\r
+ assert.equals(accounts[1].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_1)\r
+ assert.equals(accounts[1].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1)\r
+ assert.equals(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1)\r
+})\r
+\r
+test('get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => {\r
+ const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const walletAccounts = await wallet.accounts()\r
+ const walletAccount = walletAccounts[0]\r
+\r
+ console.log(`\nHERE 3\n`)\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.ok(walletAccount)\r
+ assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_2)\r
+\r
+ console.log(`\nHERE 4\n`)\r
+ const imported = await Blake2bWallet.fromMnemonic(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_2)\r
+ await imported.unlock(TREZOR_TEST_VECTORS.PASSWORD)\r
+ const importedAccounts = await imported.accounts()\r
+ const importedAccount = importedAccounts[0]\r
+\r
+ console.log(`\nHERE 5\n`)\r
+ assert.equals(imported.mnemonic, wallet.mnemonic)\r
+ assert.equals(imported.seed, wallet.seed)\r
+ assert.equals(importedAccount.privateKey, walletAccount.privateKey)\r
+ assert.equals(importedAccount.publicKey, walletAccount.publicKey)\r
+})\r
+\r
+test('get identical BLAKE2b wallets when created with max entropy value', async () => {\r
+ const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const accounts = await wallet.accounts()\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.ok(accounts[0] instanceof Account)\r
+ assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_3)\r
+ assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_3)\r
+ assert.equals(accounts[0].index, 0)\r
+ assert.equals(accounts[0].privateKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PRIVATE_0)\r
+ assert.equals(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PUBLIC_0)\r
+ assert.equals(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0)\r
+})\r
+\r
+test('reject when given invalid entropy', async () => {\r
+ await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797'))\r
+ await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701'))\r
+ await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x')))\r
+})\r
+\r
+test('reject when given a seed with an invalid length', async () => {\r
+ await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'),\r
+ `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length + 1}-character string.`)\r
+ await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)),\r
+ `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length - 1}-character string.`)\r
+})\r
+\r
+test('reject when given a seed containing non-hex characters', async () => {\r
+ await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')),\r
+ 'Seed contains invalid hexadecimal characters.')\r
+ await assert.rejects(Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')),\r
+ 'Seed contains invalid hexadecimal characters.')\r
+})\r
+\r
+\r
+test('retrieve a Bip44Wallet from storage using an ID', async () => {\r
+ const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id\r
+ const wallet = await Bip44Wallet.restore(id)\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, '')\r
+ assert.equals(wallet.seed, '')\r
+\r
+ const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equals(unlockResult, true)\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC)\r
+ assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED)\r
+})\r
+\r
+test('retrieve a Blake2bWallet from storage using an ID', async () => {\r
+ const id = (await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)).id\r
+ const wallet = await Blake2bWallet.restore(id)\r
+\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, '')\r
+ assert.equals(wallet.seed, '')\r
+\r
+ const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equals(unlockResult, true)\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.equals(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0)\r
+ assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0)\r
})\r