* @returns {Promise<string>} Hexadecimal-formatted 64-byte signature\r
*/\r
async sign (index: number, block: ChangeBlock | ReceiveBlock | SendBlock): Promise<string> {\r
- if (this.#locked) throw new Error('wallet must be unlocked to sign')\r
- if (this.#s == null) throw new Error('wallet seed not found')\r
+ if (this.#locked) throw new Error('Wallet must be unlocked to sign')\r
+ if (this.#s == null) throw new Error('Wallet seed not found')\r
try {\r
- const account = this.account(index)\r
- return (await account).sign(block, new Uint8Array(this.#s))\r
+ const account = await this.account(index)\r
+ return await account.sign(block, this.seed)\r
} catch (err) {\r
- throw new Error(`failed to sign block`, { cause: err })\r
+ throw new Error(`Failed to sign block`, { cause: err })\r
}\r
}\r
\r
// from nano.org python sample code
BLAKE2B_SEED: '0000000000000000000000000000000000000000000000000000000000000001',
BLAKE2B_PRIVATE_1: '1495F2D49159CC2EAAAA97EBB42346418E1268AFF16D7FCA90E6BAD6D0965520',
+ // derived from, but not provided by, python sample code
+ BLAKE2B_PUBLIC_1: '8F26EF538DE2D678FF8524CCF07C089E90844B204C821D74AEAE416F5C301604',
+ BLAKE2B_ADDRESS_1: 'nano_35s8xxbrurpph5zrcb8ey3y1j9niij7k1m645otcxdk3fxg517i6j5empshy',
// from nano.org test vectors
MNEMONIC: 'edge defense waste choose enrich upon flee junk siren film clown finish luggage leader kid quick brick print evidence swap drill paddle truly occur',
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account()\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
\r
- assert.equal(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\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
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(1, 2)\r
- const privateKey1 = await accounts[1].export(wallet.seed, 'hex')\r
- const privateKey2 = await accounts[2].export(wallet.seed, 'hex')\r
\r
assert.equal(accounts.length, 2)\r
- assert.equal(privateKey1, NANO_TEST_VECTORS.PRIVATE_1)\r
assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_1)\r
assert.equal(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_1)\r
assert.equal(accounts[1].index, 1)\r
- assert.equal(privateKey2, NANO_TEST_VECTORS.PRIVATE_2)\r
assert.equal(accounts[2].publicKey, NANO_TEST_VECTORS.PUBLIC_2)\r
assert.equal(accounts[2].address, NANO_TEST_VECTORS.ADDRESS_2)\r
assert.equal(accounts[2].index, 2)\r
assert.equal(a.index, i)\r
assert.exists(a.address)\r
assert.exists(a.publicKey)\r
- const privateKey = await a.export(wallet.seed, 'hex')\r
- assert.exists(privateKey)\r
}\r
\r
await assert.resolves(wallet.destroy())\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const account = await wallet.account(1)\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
\r
- assert.equal(privateKey, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_1)\r
- // assert.equal(account.publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_0)\r
- // assert.equal(account.address, NANO_TEST_VECTORS.BLAKE2B_ADDRESS_0)\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 wallet.accounts(1)\r
assert.exists(accounts[1])\r
+ assert.exists(accounts[1].publicKey)\r
+ assert.exists(accounts[1].address)\r
assert.equal(account, accounts[1])\r
\r
await assert.resolves(wallet.destroy())\r
await test('derive low indexed accounts from the given BLAKE2B seed', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const accounts = await wallet.accounts(1, 2)\r
- // const privateKey1 = await accounts[1].export(wallet.seed, 'hex')\r
- // const privateKey2 = await accounts[2].export(wallet.seed, 'hex')\r
+ const accounts = await wallet.accounts(2, 3)\r
\r
assert.equal(accounts.length, 2)\r
- // assert.equal(privateKey1, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_1)\r
- // assert.equal(accounts[1].publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_1)\r
- // assert.equal(accounts[1].address, NANO_TEST_VECTORS.BLAKE2B_ADDRESS_1)\r
- assert.equal(accounts[1].index, 1)\r
- // assert.equal(privateKey2, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_2)\r
- // assert.equal(accounts[2].publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_2)\r
- // assert.equal(accounts[2].address, NANO_TEST_VECTORS.BLAKE2B_ADDRESS_2)\r
+ assert.exists(accounts[2].publicKey)\r
+ assert.exists(accounts[2].address)\r
assert.equal(accounts[2].index, 2)\r
+ assert.exists(accounts[3].publicKey)\r
+ assert.exists(accounts[3].address)\r
+ assert.equal(accounts[3].index, 3)\r
\r
await assert.resolves(wallet.destroy())\r
})\r
assert.equal(a.index, i)\r
assert.exists(a.address)\r
assert.exists(a.publicKey)\r
- const privateKey = await a.export(wallet.seed, 'hex')\r
- assert.exists(privateKey)\r
}\r
\r
await assert.resolves(wallet.destroy())\r
assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.equal(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
assert.equal(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.equal(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_0)\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_0)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.equal(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_1)\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_1)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.equal(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_2)\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_2)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.equal(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_3)\r
assert.equal(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_3)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.exists(accounts[i])\r
assert.exists(accounts[i].address)\r
assert.exists(accounts[i].publicKey)\r
- const privateKey = await accounts[i].export(wallet.seed, 'hex')\r
- assert.exists(privateKey)\r
}\r
\r
await assert.resolves(wallet.destroy())\r
assert.exists(accounts[i])\r
assert.exists(accounts[i].address)\r
assert.exists(accounts[i].publicKey)\r
- const privateKey = await accounts[i].export(wallet.seed, 'hex')\r
- assert.exists(privateKey)\r
}\r
\r
await assert.resolves(wallet.destroy())\r
assert.ok(accounts[0] instanceof Account)\r
assert.equal(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0)\r
assert.equal(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0)\r
- const privateKey0 = await accounts[0].export(wallet.seed, 'hex')\r
- assert.equal(privateKey0, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_0)\r
\r
assert.ok(accounts[1] instanceof Account)\r
assert.equal(accounts[1].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1)\r
assert.equal(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1)\r
- const privateKey1 = await accounts[1].export(wallet.seed, 'hex')\r
- assert.equal(privateKey1, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_1)\r
\r
await assert.resolves(wallet.destroy())\r
})\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 walletAccount = await wallet.account()\r
- const walletAccountPrivateKey = await walletAccount.export(wallet.seed, 'hex')\r
\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\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 importedAccount = await imported.account()\r
- const importedAccountPrivateKey = await importedAccount.export(imported.seed, 'hex')\r
\r
assert.equal(imported.mnemonic, wallet.mnemonic)\r
assert.equal(imported.seed, wallet.seed)\r
assert.equal(importedAccount.publicKey, walletAccount.publicKey)\r
- assert.equal(importedAccountPrivateKey, walletAccountPrivateKey)\r
\r
await assert.resolves(wallet.destroy())\r
await assert.resolves(imported.destroy())\r
assert.equal(account.publicKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PUBLIC_0)\r
assert.equal(account.address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0)\r
\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
- assert.equal(privateKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PRIVATE_0)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.ok(account instanceof Account)
assert.exists(account.address)
assert.exists(account.publicKey)
- await assert.rejects(account.export(''))
})
await test('get second and third accounts', async () => {
assert.equal(lockResult, true)\r
\r
const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
\r
assert.equal(unlockResult, true)\r
- assert.equal(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\r
assert.equal(lockResult, true)\r
\r
const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
\r
assert.equal(unlockResult, true)\r
- assert.equal(privateKey, TREZOR_TEST_VECTORS.BLAKE2B_PRIVATE_0)\r
-\r
await assert.resolves(wallet.destroy())\r
})\r
\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 account = await wallet.account()\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
+ if (account.index == null) {\r
+ throw new Error('Account index missing')\r
+ }\r
const sendBlock = new SendBlock(\r
account.address,\r
'5618869000000000000000000000000',\r
'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',\r
'92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',\r
)\r
- await sendBlock.sign(privateKey)\r
+\r
+ const signature = await wallet.sign(account.index, sendBlock)\r
const valid = await sendBlock.verify(account.publicKey)\r
+\r
+ assert.equal(signature, sendBlock.signature)\r
assert.equal(valid, true)\r
\r
await assert.resolves(wallet.destroy())\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 account = await wallet.account()\r
- const privateKey = await account.export(wallet.seed, 'hex')\r
+ if (account.index == null) {\r
+ throw new Error('Account index missing')\r
+ }\r
const sendBlock = new SendBlock(\r
account.address,\r
'5618869000000000000000000000000',\r
'nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou',\r
'92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D',\r
)\r
- await sendBlock.sign(privateKey)\r
+ assert.equal(account.index, 0)\r
+ const signature = await wallet.sign(account.index, sendBlock)\r
+\r
+ assert.equal(signature, sendBlock.signature)\r
\r
sendBlock.account = Account.import('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
const valid = await sendBlock.verify(account.publicKey)\r