From: Chris Duncan Date: Fri, 18 Jul 2025 14:17:59 +0000 (-0700) Subject: Shorten account private key export method and make primary implementation private... X-Git-Tag: v0.10.5~56^2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=8f55c46fc9bf39eb11819a59cb4e79f738be4597;p=libnemo.git Shorten account private key export method and make primary implementation private. Pass buffer data directly to worker queue assignments instead of using intermediate variables. Update tests. --- diff --git a/src/lib/account.ts b/src/lib/account.ts index 08ac884..8674c5e 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -171,6 +171,45 @@ export class Account { } } + /** + * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without + * exposing the private keys of accounts. + * + * Retrieves and decrypts the private key of the Account. The same password + * used to lock it must be used to unlock it. If derived from a wallet, the + * password for the account is the wallet seed. + * + * @param {Key} password Used previously to lock the Account + * @returns Private key bytes as a Uint8Array + */ + async export (password: Key): Promise> + /** + * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without + * exposing the private keys of accounts. + * + * Retrieves and decrypts the private key of the Account. The same password + * used to lock it must be used to unlock it. If derived from a wallet, the + * password for the account is the wallet seed. + * + * @param {Key} password Used previously to lock the Account + * @returns Private key bytes as a hexadecimal string + */ + async export (password: Key, format: 'hex'): Promise + async export (password: Key, format?: 'hex'): Promise { + if (typeof password === 'string') password = utf8.toBytes(password) + try { + const privateKey = await this.#export(password) + return format === 'hex' + ? bytes.toHex(privateKey) + : privateKey + } catch (err) { + console.log(err) + throw new Error('Failed to export Account private key') + } finally { + bytes.erase(password) + } + } + /** * Refreshes the account from its current state on the network. * @@ -207,67 +246,24 @@ export class Account { * Signs a block using the private key of the account. The signature is * appended to the signature field of the block before being returned. * - * @param {Key} password - Required to decrypt the private key for signing * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - The block data to be hashed and signed + * @param {Key} password - Required to decrypt the private key for signing * @returns {Promise} Hexadecimal-formatted 64-byte signature */ async sign (block: ChangeBlock | ReceiveBlock | SendBlock, password: Key): Promise { - const privateKey = await this.exportPrivateKey(password) + if (typeof password === 'string') password = utf8.toBytes(password) try { const headers = { method: 'detached' } - const data = { - privateKey: privateKey.buffer, + const result = await NanoNaClWorker.assign(headers, { + privateKey: (await this.#export(password)).buffer, msg: hex.toBytes(block.hash).buffer - } - const result = await NanoNaClWorker.assign(headers, data) + }) block.signature = result return result } catch (err) { throw new Error(`Failed to sign block`, { cause: err }) - } finally { - bytes.erase(privateKey) - } - } - - /** - * Retrieves and decryptes the private key of the Account. The same password - * used to lock it must be used to unlock it. - * - * @param {Key} password Used previously to lock the Account - * @returns Private key bytes as a Uint8Array - */ - async exportPrivateKey (password: Key): Promise> - /** - * Retrieves and decryptes the private key of the Account. The same password - * used to lock it must be used to unlock it. - * - * @param {Key} password Used previously to lock the Account - * @returns Private key bytes as a hexadecimal string - */ - async exportPrivateKey (password: Key, format: 'hex'): Promise - async exportPrivateKey (password: Key, format?: 'hex'): Promise { - if (typeof password === 'string') password = utf8.toBytes(password) - if (password == null || !(password instanceof Uint8Array)) { - throw new Error('Password must be string or bytes') - } - try { - const headers = { - method: 'get', - name: this.publicKey, - store: 'Account' - } - const data = { - password: password.buffer - } - const response = await SafeWorker.assign(headers, data) - const privateKey = new Uint8Array(response[this.publicKey] as ArrayBuffer) - return format === 'hex' - ? bytes.toHex(privateKey) - : privateKey - } catch (err) { - throw new Error(`Failed to export private key for Account ${this.address}`, { cause: err }) } finally { bytes.erase(password) } @@ -320,6 +316,35 @@ export class Account { return publicKey } + /** + * Retrieves and decrypts the private key of the Account. The same password + * used to lock it must be used to unlock it. + * + * @param {Key} password Used previously to lock the Account + * @returns Private key bytes as a Uint8Array + */ + async #export (password: Key): Promise> { + if (typeof password === 'string') password = utf8.toBytes(password) + if (password == null || !(password instanceof Uint8Array)) { + throw new Error('Password must be string or bytes') + } + try { + const headers = { + method: 'get', + name: this.publicKey, + store: 'Account' + } + const response = await SafeWorker.assign(headers, { + password: password.buffer + }) + return new Uint8Array(response[this.publicKey] as ArrayBuffer) + } catch (err) { + throw new Error(`Failed to export private key for Account ${this.address}`, { cause: err }) + } finally { + bytes.erase(password) + } + } + /** * Instantiates an Account object from its private key which is then encrypted * and stored in IndexedDB. The corresponding public key will automatically be @@ -348,10 +373,9 @@ export class Account { const headers = { method: 'convert' } - const data = { + const publicKey = await NanoNaClWorker.assign(headers, { privateKey: new Uint8Array(privateKey).buffer - } - const publicKey = await NanoNaClWorker.assign(headers, data) + }) privateAccounts[publicKey] = privateKey.buffer const address = this.#keyToAddress(hex.toBytes(publicKey)) this.#isInternal = true diff --git a/src/lib/block.ts b/src/lib/block.ts index 092b32b..1eec2c9 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -98,6 +98,34 @@ abstract class Block { this.work = result.work } + /** + * Sends the block to a node for processing on the network. + * + * The block must already be signed (see `sign()` for more information). + * The block must also have a `work` value. + * + * @param {Rpc|string|URL} rpc - RPC node information required to call `process` + * @returns {Promise} Hash of the processed block + */ + async process (rpc: Rpc): Promise { + if (!this.signature) { + throw new Error('Block is missing signature. Use sign() and try again.') + } + if (!this.work == null) { + throw new Error('Block is missing proof-of-work. Generate PoW and try again.') + } + const data = { + "subtype": this.subtype, + "json_block": "true", + "block": this.toJSON() + } + const res = await rpc.call('process', data) + if (res.hash == null) { + throw new Error('Block could not be processed', res) + } + return res.hash + } + /** * Signs the block using a private key. If a key is not provided, the private * key of the block's account will be used if it exists. If that fails, an @@ -150,34 +178,6 @@ abstract class Block { } } - /** - * Sends the block to a node for processing on the network. - * - * The block must already be signed (see `sign()` for more information). - * The block must also have a `work` value. - * - * @param {Rpc|string|URL} rpc - RPC node information required to call `process` - * @returns {Promise} Hash of the processed block - */ - async process (rpc: Rpc): Promise { - if (!this.signature) { - throw new Error('Block is missing signature. Use sign() and try again.') - } - if (!this.work == null) { - throw new Error('Block is missing proof-of-work. Generate PoW and try again.') - } - const data = { - "subtype": this.subtype, - "json_block": "true", - "block": this.toJSON() - } - const res = await rpc.call('process', data) - if (res.hash == null) { - throw new Error('Block could not be processed', res) - } - return res.hash - } - /** * Verifies the signature of the block. If a key is not provided, the public * key of the block's account will be used if it exists. @@ -194,12 +194,11 @@ abstract class Block { const headers = { method: 'verify' } - const data = { + return await NanoNaClWorker.assign(headers, { msg: hex.toBytes(this.hash).buffer, signature: hex.toBytes(this.signature ?? '').buffer, publicKey: hex.toBytes(key).buffer - } - return await NanoNaClWorker.assign(headers, data) + }) } catch (err) { throw new Error(`Failed to derive public key from private key`, { cause: err }) } diff --git a/src/lib/tools.ts b/src/lib/tools.ts index a9a4459..eeeaac2 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -95,11 +95,10 @@ export async function sign (key: Key, ...input: string[]): Promise { const headers = { method: 'detached' } - const data = { + return await NanoNaClWorker.assign(headers, { privateKey: key.buffer, msg: (hash(input) as Uint8Array).buffer - } - return await NanoNaClWorker.assign(headers, data) + }) } catch (err) { throw new Error(`Failed to sign message with private key`, { cause: err }) } finally { @@ -182,12 +181,11 @@ export async function verify (key: Key, signature: string, ...input: string[]): const headers = { method: 'verify' } - const data = { + return await NanoNaClWorker.assign(headers, { msg: (hash(input) as Uint8Array).buffer, signature: hex.toBytes(signature).buffer, publicKey: new Uint8Array(key).buffer - } - return await NanoNaClWorker.assign(headers, data) + }) } catch (err) { throw new Error('Failed to verify signature', { cause: err }) } finally { diff --git a/src/lib/wallets/bip44-wallet.ts b/src/lib/wallets/bip44-wallet.ts index 6cbe424..8ea9276 100644 --- a/src/lib/wallets/bip44-wallet.ts +++ b/src/lib/wallets/bip44-wallet.ts @@ -215,10 +215,9 @@ export class Bip44Wallet extends Wallet { const headers = { indexes } - const data = { + const results = await Bip44CkdWorker.assign(headers, { seed: hex.toBytes(this.seed).buffer - } - const results = await Bip44CkdWorker.assign(headers, data) + }) const privateKeys: KeyPair[] = [] for (const i of Object.keys(results)) { if (results[i] == null || !(results[i] instanceof ArrayBuffer)) { diff --git a/src/lib/wallets/wallet.ts b/src/lib/wallets/wallet.ts index 28c2823..cbb8e4c 100644 --- a/src/lib/wallets/wallet.ts +++ b/src/lib/wallets/wallet.ts @@ -173,11 +173,10 @@ export abstract class Wallet { method: 'set', store: 'Wallet' } - const data: Data = { + const success = await SafeWorker.assign(headers, { [this.id]: encoded.buffer, password: password.buffer - } - const success = await SafeWorker.assign(headers, data) + }) if (!success) { throw null } @@ -238,10 +237,9 @@ export abstract class Wallet { name: this.id, store: 'Wallet', } - const data = { + const response = await SafeWorker.assign(headers, { password: password.buffer - } - const response = await SafeWorker.assign(headers, data) + }) const decoded = bytes.toUtf8(response[this.id]) const deserialized = JSON.parse(decoded) let { id, mnemonic, seed } = deserialized diff --git a/src/types.d.ts b/src/types.d.ts index bc24af2..50a9415 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -9,6 +9,7 @@ */ export declare class Account { get address (): string + get index (): number | undefined get publicKey (): string get balance (): bigint | undefined get frontier (): string | undefined @@ -30,88 +31,92 @@ export declare class Account { * Instantiates an Account object from its Nano address. * * @param {string} addresses - Address of the account - * @returns {Account} The instantiated Account object + * @returns {Account} A new Account object */ static import (address: string): Account /** * Instantiates Account objects from their Nano addresses. * * @param {string[]} addresses - Addresses of the accounts - * @returns {Account[]} The instantiated Account objects + * @returns {Account[]} Array of new Account objects */ static import (addresses: string[]): Account[] /** * Instantiates an Account object from its public key. It is unable to sign * blocks or messages since it has no private key. * - * @param {string} publicKey - Public key of the account - * @returns {Account} The instantiated Account object - */ - static import (publicKey: string): Account - /** - * Instantiates an Account object from its public key. It is unable to sign - * blocks or messages since it has no private key. - * - * @param {Uint8Array} publicKey - Public key of the account - * @returns {Account} The instantiated Account object + * @param {Key} publicKey - Public key of the account + * @returns {Account} A new Account object */ - static import (publicKey: Uint8Array): Account + static import (publicKey: Key): Account /** * Instantiates Account objects from their public keys. They are unable to sign * blocks or messages since they have no private key. * - * @param {string[]} publicKeys - Public keys of the accounts - * @returns {Account[]} The instantiated Account objects + * @param {Key[]} publicKeys - Public keys of the accounts + * @returns {Account[]} Array of new Account objects */ - static import (publicKeys: string[]): Account[] + static import (publicKeys: Key[]): Account[] /** - * Instantiates Account objects from their public keys. They are unable to sign - * blocks or messages since they have no private key. + * Instantiates an Account object from its public key. It is unable to sign + * blocks or messages since it has no private key. * - * @param {Uint8Array[]} publicKeys - Public keys of the accounts - * @returns {Account[]} The instantiated Account objects + * @param {KeyPair} keypair - Index and keys of the account + * @returns {Account} A new Account object */ - static import (publicKeys: Uint8Array[]): Account[] + static import (keypair: KeyPair): Account /** - * Instantiates an Account object from its private key which is then encrypted - * and stored in IndexedDB. The corresponding public key will automatically be - * derived and saved. + * Instantiates Account objects from their public keys. They are unable to sign + * blocks or messages since they have no private key. * - * @param {string} privateKey - Private key of the account - * @param {Key} password - Used to encrypt the private key - * @returns {Account} A new Account object + * @param {KeyPair[]} keypairs - Indexes and keys of the accounts + * @returns {Account[]} Array of new Account objects */ - static import (privateKey: string, password: Key): Promise + static import (keypairs: KeyPair[]): Account[] /** * Instantiates an Account object from its private key which is then encrypted * and stored in IndexedDB. The corresponding public key will automatically be * derived and saved. * - * @param {Uint8Array} privateKey - Private key of the account + * @param {KeyPair} keypair - Index and keys of the account * @param {Key} password - Used to encrypt the private key - * @returns {Account} A new Account object + * @returns {Promise} Promise for a new Account object */ - static import (privateKey: Uint8Array, password: Key): Promise + static import (keypair: KeyPair, password: Key): Promise /** * Instantiates Account objects from their private keys which are then * encrypted and stored in IndexedDB. The corresponding public keys will * automatically be derived and saved. * - * @param {string[]} privateKeys - Private keys of the account + * @param {KeyPair[]} keypairs - Indexes and keys of the accounts * @param {Key} password - Used to encrypt the private keys - * @returns {Account[]} The instantiated Account objects + * @returns {Promise} Promise for array of new Account objects */ - static import (privateKeys: string[], password: Key): Promise + static import (keypairs: KeyPair[], password: Key): Promise /** - * Instantiates Account objects from their private keys which are then - * encrypted and stored in IndexedDB. The corresponding public keys will - * automatically be derived and saved. + * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without + * exposing the private keys of accounts. * - * @param {Uint8Array[]} privateKeys - Private keys of the account - * @param {Key} password - Used to encrypt the private keys - * @returns {Account[]} The instantiated Account objects + * Retrieves and decrypts the private key of the Account. The same password + * used to lock it must be used to unlock it. If derived from a wallet, the + * password for the account is the wallet seed. + * + * @param {Key} password Used previously to lock the Account + * @returns Private key bytes as a Uint8Array + */ + export (password: Key): Promise> + /** + * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without + * exposing the private keys of accounts. + * + * Retrieves and decrypts the private key of the Account. The same password + * used to lock it must be used to unlock it. If derived from a wallet, the + * password for the account is the wallet seed. + * + * @param {Key} password Used previously to lock the Account + * @returns Private key bytes as a hexadecimal string */ - static import (privateKeys: Uint8Array[], password: Key): Promise + export (password: Key, format: 'hex'): Promise /** * Refreshes the account from its current state on the network. * @@ -125,28 +130,12 @@ export declare class Account { * Signs a block using the private key of the account. The signature is * appended to the signature field of the block before being returned. * - * @param {Key} password - Required to decrypt the private key for signing * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - The block data to be hashed and signed + * @param {Key} password - Required to decrypt the private key for signing * @returns {Promise} Hexadecimal-formatted 64-byte signature */ sign (block: ChangeBlock | ReceiveBlock | SendBlock, password: Key): Promise /** - * Retrieves and decryptes the private key of the Account. The same password - * used to lock it must be used to unlock it. - * - * @param {Key} password Used previously to lock the Account - * @returns Private key bytes as a Uint8Array - */ - exportPrivateKey (password: Key): Promise> - /** - * Retrieves and decryptes the private key of the Account. The same password - * used to lock it must be used to unlock it. - * - * @param {Key} password Used previously to lock the Account - * @returns Private key bytes as a hexadecimal string - */ - exportPrivateKey (password: Key, format: 'hex'): Promise - /** * Validates a Nano address with 'nano' and 'xrb' prefixes * Derived from https://github.com/alecrios/nano-address-validator * @@ -155,6 +144,11 @@ export declare class Account { */ static validate (address: unknown): asserts address is string } +export declare class AccountList extends Object { + [index: number]: Account + get length (): number; + [Symbol.iterator] (): Iterator +} /** * Represents a block as defined by the Nano cryptocurrency protocol. The Block @@ -193,6 +187,16 @@ declare abstract class Block { */ pow (): Promise /** + * Sends the block to a node for processing on the network. + * + * The block must already be signed (see `sign()` for more information). + * The block must also have a `work` value. + * + * @param {Rpc|string|URL} rpc - RPC node information required to call `process` + * @returns {Promise} Hash of the processed block + */ + process (rpc: Rpc): Promise + /** * Signs the block using a private key. If a key is not provided, the private * key of the block's account will be used if it exists. If that fails, an * error is thrown. @@ -217,16 +221,6 @@ declare abstract class Block { [key: string]: string }): Promise /** - * Sends the block to a node for processing on the network. - * - * The block must already be signed (see `sign()` for more information). - * The block must also have a `work` value. - * - * @param {Rpc|string|URL} rpc - RPC node information required to call `process` - * @returns {Promise} Hash of the processed block - */ - process (rpc: Rpc): Promise - /** * Verifies the signature of the block. If a key is not provided, the public * key of the block's account will be used if it exists. * @@ -235,7 +229,6 @@ declare abstract class Block { */ verify (key?: string): Promise } - /** * Represents a block that sends funds from one address to another as defined by * the Nano cryptocurrency protocol. @@ -251,7 +244,6 @@ export declare class SendBlock extends Block { work?: string constructor (sender: Account | string, balance: string, recipient: string, amount: string, representative: Account | string, frontier: string, work?: string) } - /** * Represents a block that receives funds sent to one address from another as * defined by the Nano cryptocurrency protocol. @@ -267,7 +259,6 @@ export declare class ReceiveBlock extends Block { work?: string constructor (recipient: Account | string, balance: string, origin: string, amount: string, representative: Account | string, frontier?: string, work?: string) } - /** * Represents a block that changes the representative account to which the user * account delegates their vote weight using the the Open Representative Voting @@ -285,12 +276,6 @@ export declare class ChangeBlock extends Block { constructor (account: Account | string, balance: string, representative: Account | string, frontier: string, work?: string) } -export declare class AccountList extends Object { - [index: number]: Account - get length (): number; - [Symbol.iterator] (): Iterator -} - export type Data = { [key: string]: ArrayBuffer } diff --git a/test/test.derive-accounts.mjs b/test/test.derive-accounts.mjs index 00cf66e..bcee3b3 100644 --- a/test/test.derive-accounts.mjs +++ b/test/test.derive-accounts.mjs @@ -13,7 +13,7 @@ await suite('Derive accounts from BIP-44 wallet', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.account() - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0) assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0) @@ -31,8 +31,8 @@ await suite('Derive accounts from BIP-44 wallet', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(1, 2) - const privateKey1 = await accounts[1].exportPrivateKey(wallet.seed, 'hex') - const privateKey2 = await accounts[2].exportPrivateKey(wallet.seed, 'hex') + const privateKey1 = await accounts[1].export(wallet.seed, 'hex') + const privateKey2 = await accounts[2].export(wallet.seed, 'hex') assert.equals(accounts.length, 2) assert.equals(privateKey1, NANO_TEST_VECTORS.PRIVATE_1) @@ -59,7 +59,7 @@ await suite('Derive accounts from BIP-44 wallet', async () => { assert.equals(a.index, i) assert.exists(a.address) assert.exists(a.publicKey) - const privateKey = await a.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await a.export(wallet.seed, 'hex') assert.exists(privateKey) } @@ -73,7 +73,7 @@ await suite('Derive accounts from BLAKE2b wallet', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.account(1) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_1) // assert.equals(account.publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_0) @@ -91,8 +91,8 @@ await suite('Derive accounts from BLAKE2b wallet', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BLAKE2B_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(1, 2) - // const privateKey1 = await accounts[1].exportPrivateKey(wallet.seed, 'hex') - // const privateKey2 = await accounts[2].exportPrivateKey(wallet.seed, 'hex') + // const privateKey1 = await accounts[1].export(wallet.seed, 'hex') + // const privateKey2 = await accounts[2].export(wallet.seed, 'hex') assert.equals(accounts.length, 2) // assert.equals(privateKey1, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_1) @@ -119,7 +119,7 @@ await suite('Derive accounts from BLAKE2b wallet', async () => { assert.equals(a.index, i) assert.exists(a.address) assert.exists(a.publicKey) - const privateKey = await a.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await a.export(wallet.seed, 'hex') assert.exists(privateKey) } diff --git a/test/test.import-wallet.mjs b/test/test.import-wallet.mjs index f43b86c..230488f 100644 --- a/test/test.import-wallet.mjs +++ b/test/test.import-wallet.mjs @@ -22,7 +22,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0) assert.equals(account.address, NANO_TEST_VECTORS.ADDRESS_0) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0) await wallet.destroy() @@ -41,7 +41,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0) assert.equals(account.address, NANO_TEST_VECTORS.ADDRESS_0) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0) await wallet.destroy() @@ -57,7 +57,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_0) assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_0) await wallet.destroy() @@ -73,7 +73,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_1) assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_1) await wallet.destroy() @@ -89,7 +89,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_2) assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_2) await wallet.destroy() @@ -105,7 +105,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_3) assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_3) await wallet.destroy() @@ -126,7 +126,7 @@ await suite('Import wallets', async () => { assert.exists(accounts[i]) assert.exists(accounts[i].address) assert.exists(accounts[i].publicKey) - const privateKey = await accounts[i].exportPrivateKey(wallet.seed, 'hex') + const privateKey = await accounts[i].export(wallet.seed, 'hex') assert.exists(privateKey) } @@ -148,7 +148,7 @@ await suite('Import wallets', async () => { assert.exists(accounts[i]) assert.exists(accounts[i].address) assert.exists(accounts[i].publicKey) - const privateKey = await accounts[i].exportPrivateKey(wallet.seed, 'hex') + const privateKey = await accounts[i].export(wallet.seed, 'hex') assert.exists(privateKey) } @@ -168,13 +168,13 @@ await suite('Import wallets', async () => { assert.ok(accounts[0] instanceof Account) assert.equals(accounts[0].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_0) assert.equals(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_0) - const privateKey0 = await accounts[0].exportPrivateKey(wallet.seed, 'hex') + const privateKey0 = await accounts[0].export(wallet.seed, 'hex') assert.equals(privateKey0, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_0) assert.ok(accounts[1] instanceof Account) assert.equals(accounts[1].publicKey, TREZOR_TEST_VECTORS.BLAKE2B_1_PUBLIC_1) assert.equals(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1) - const privateKey1 = await accounts[1].exportPrivateKey(wallet.seed, 'hex') + const privateKey1 = await accounts[1].export(wallet.seed, 'hex') assert.equals(privateKey1, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_1) await wallet.destroy() @@ -184,7 +184,7 @@ await suite('Import wallets', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const walletAccount = await wallet.account() - const walletAccountPrivateKey = await walletAccount.exportPrivateKey(wallet.seed, 'hex') + const walletAccountPrivateKey = await walletAccount.export(wallet.seed, 'hex') assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) @@ -194,7 +194,7 @@ await suite('Import wallets', async () => { const imported = await Blake2bWallet.fromMnemonic(TREZOR_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_2) await imported.unlock(TREZOR_TEST_VECTORS.PASSWORD) const importedAccount = await imported.account() - const importedAccountPrivateKey = await importedAccount.exportPrivateKey(imported.seed, 'hex') + const importedAccountPrivateKey = await importedAccount.export(imported.seed, 'hex') assert.equals(imported.mnemonic, wallet.mnemonic) assert.equals(imported.seed, wallet.seed) @@ -217,7 +217,7 @@ await suite('Import wallets', async () => { assert.equals(account.publicKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PUBLIC_0) assert.equals(account.address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(privateKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PRIVATE_0) await wallet.destroy() diff --git a/test/test.lock-unlock.mjs b/test/test.lock-unlock.mjs index 06804a3..67d8e01 100644 --- a/test/test.lock-unlock.mjs +++ b/test/test.lock-unlock.mjs @@ -60,7 +60,7 @@ await suite('Lock and unlock wallets', async () => { assert.equals(lockResult, true) const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(unlockResult, true) assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0) @@ -207,7 +207,7 @@ await suite('Lock and unlock wallets', async () => { assert.equals(lockResult, true) const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') assert.equals(unlockResult, true) assert.equals(privateKey, TREZOR_TEST_VECTORS.BLAKE2B_PRIVATE_0) diff --git a/test/test.tools.mjs b/test/test.tools.mjs index c31f962..1a6adea 100644 --- a/test/test.tools.mjs +++ b/test/test.tools.mjs @@ -105,7 +105,7 @@ await suite('signature tests', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.account() - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') const sendBlock = new SendBlock( account.address, '5618869000000000000000000000000', @@ -125,7 +125,7 @@ await suite('signature tests', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.account() - const privateKey = await account.exportPrivateKey(wallet.seed, 'hex') + const privateKey = await account.export(wallet.seed, 'hex') const sendBlock = new SendBlock( account.address, '5618869000000000000000000000000',