/**
* Decrypts the input and sets the seed and, if it is included, the mnemonic.
*/
- unlock (type?: string, key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise<NamedData<boolean>> {
+ unlock (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise<NamedData<boolean>> {
if (type == null) {
throw new TypeError('Wallet type is required')
}
if (mnemonic != null && !(mnemonic instanceof ArrayBuffer)) {
throw new TypeError('Invalid mnemonic')
}
+ this.#type = type
this.#seed = seed
this.#mnemonic = mnemonic
this.#locked = false
\r
await assert.resolves(wallet.destroy())\r
})\r
+\r
+ await test('derive from restored BIP-44 wallet', async () => {\r
+ const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
+ const restored = await Wallet.restore(wallet.id)\r
+ await restored.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const account = await restored.account()\r
+\r
+ assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
+ assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
+ assert.equal(account.index, 0)\r
+\r
+ const accounts = await restored.accounts()\r
+ assert.exists(accounts[0])\r
+ assert.equal(account, accounts[0])\r
+\r
+ await assert.resolves(wallet.destroy())\r
+ await assert.resolves(restored.destroy())\r
+ })\r
}),\r
\r
suite('Derive accounts from BLAKE2b wallet', async () => {\r
\r
await assert.resolves(wallet.destroy())\r
})\r
+\r
+ await test('derive from restored BLAKE2b wallet', async () => {\r
+ const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
+ const restored = await Wallet.restore(wallet.id)\r
+ await restored.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const account = await restored.account(1)\r
+\r
+ assert.equal(account.publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_1)\r
+ assert.equal(account.address, NANO_TEST_VECTORS.BLAKE2B_ADDRESS_1)\r
+ assert.equal(account.index, 1)\r
+\r
+ const accounts = await restored.accounts(1)\r
+ assert.exists(accounts[1])\r
+ assert.equal(account, accounts[1])\r
+\r
+ await assert.resolves(wallet.destroy())\r
+ await assert.resolves(restored.destroy())\r
+ })\r
})\r
])\r
await assert.resolves(wallet.destroy())\r
})\r
\r
- await test('fail to unlock a Bip44Wallet with different passwords', async () => {\r
+ await test('fail to unlock a BIP-44 wallet with different passwords', async () => {\r
const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
wallet.lock()\r
await assert.resolves(wallet.destroy())\r
})\r
\r
- await test('fail to unlock a Bip44Wallet with invalid input', async () => {\r
+ await test('fail to unlock a BIP-44 wallet with invalid input', async () => {\r
const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
\r
await assert.resolves(wallet.destroy())\r
})\r
\r
- await test('locking and unlocking a Blake2bWallet with a password', async () => {\r
+ await test('locking and unlocking a BLAKE2b wallet with a password', async () => {\r
const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
\r
assert.ok('mnemonic' in wallet)\r
await assert.resolves(wallet.destroy())\r
})\r
\r
- await test('fail to unlock a Blake2bWallet with different passwords', async () => {\r
+ await test('fail to unlock a BLAKE2b wallet with different passwords', async () => {\r
const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
\r
await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' })\r
await assert.resolves(wallet.destroy())\r
})\r
\r
- await test('fail to unlock a Blake2bWallet with no input', async () => {\r
+ await test('fail to unlock a BLAKE2b wallet with no input', async () => {\r
const wallet = await Wallet.load('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
\r
await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' })\r