await test('locking and unlocking a Bip44Wallet with random bytes', 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 key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
- const lockResult = await wallet.lock(key)\r
+ const key = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
\r
+ const lockResult = await wallet.lock(new Uint8Array(key))\r
assert.ok(lockResult)\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(key)\r
+ const unlockResult = await wallet.unlock(new Uint8Array(key))\r
\r
assert.equals(unlockResult, true)\r
assert.ok('mnemonic' in wallet)\r
await test('fail to unlock a Bip44Wallet with different random bytes', 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 rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
- const wrongKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
- const lockResult = await wallet.lock(rightKey)\r
+ const rightKey = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
+ const wrongKey = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
+ const lockResult = await wallet.lock(new Uint8Array(rightKey))\r
\r
- await assert.rejects(wallet.unlock(wrongKey), { message: 'Failed to unlock wallet' })\r
+ await assert.rejects(wallet.unlock(new Uint8Array(wrongKey)), { message: 'Failed to unlock wallet' })\r
assert.equals(lockResult, true)\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
\r
await test('fail to unlock a Bip44Wallet with different valid inputs', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
- const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
+ const key = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
\r
- await assert.rejects(wallet.unlock(key), { message: 'Failed to unlock wallet' })\r
+ await assert.rejects(wallet.unlock(new Uint8Array(key)), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
assert.notEqual(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC)\r
await wallet.destroy()\r
})\r
\r
- await test('locking and unlocking a Blake2bWallet with a random CryptoKey', async () => {\r
+ await test('locking and unlocking a Blake2bWallet with random bytes', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
- const lockResult = await wallet.lock(key)\r
+ const key = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
+ const lockResult = await wallet.lock(new Uint8Array(key))\r
\r
assert.equals(lockResult, true)\r
assert.ok('mnemonic' in wallet)\r
assert.equals(wallet.mnemonic, '')\r
assert.equals(wallet.seed, '')\r
\r
- const unlockResult = await wallet.unlock(key)\r
+ const unlockResult = await wallet.unlock(new Uint8Array(key))\r
\r
assert.equals(lockResult, true)\r
assert.equals(unlockResult, true)\r
await test('fail to unlock a Blake2bWallet with different keys', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
- const wrongKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
- const lockResult = await wallet.lock(rightKey)\r
+ const rightKey = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
+ const wrongKey = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
+ const lockResult = await wallet.lock(new Uint8Array(rightKey))\r
\r
- await assert.rejects(wallet.unlock(wrongKey), { message: 'Failed to unlock wallet' })\r
+ await assert.rejects(wallet.unlock(new Uint8Array(wrongKey)), { message: 'Failed to unlock wallet' })\r
assert.equals(lockResult, true)\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
\r
await test('fail to unlock a Blake2bWallet with different valid inputs', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
- const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])\r
+ const key = globalThis.crypto.getRandomValues(new Uint8Array(64))\r
\r
- await assert.rejects(wallet.unlock(key), { message: 'Failed to unlock wallet' })\r
+ await assert.rejects(wallet.unlock(new Uint8Array(key)), { message: 'Failed to unlock wallet' })\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
assert.notEqual(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_1)\r