]> git.codecow.com Git - libnemo.git/commitdiff
Shorten account private key export method and make primary implementation private...
authorChris Duncan <chris@zoso.dev>
Fri, 18 Jul 2025 14:17:59 +0000 (07:17 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 18 Jul 2025 14:17:59 +0000 (07:17 -0700)
src/lib/account.ts
src/lib/block.ts
src/lib/tools.ts
src/lib/wallets/bip44-wallet.ts
src/lib/wallets/wallet.ts
src/types.d.ts
test/test.derive-accounts.mjs
test/test.import-wallet.mjs
test/test.lock-unlock.mjs
test/test.tools.mjs

index 08ac88462c9a38e7e7b2853eeb1408d50699088d..8674c5e565497b09973759835e9dc6fb0eb536c8 100644 (file)
@@ -171,6 +171,45 @@ export class Account {
                }\r
        }\r
 \r
+       /**\r
+       * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without\r
+       * exposing the private keys of accounts.\r
+       *\r
+       * Retrieves and decrypts the private key of the Account. The same password\r
+       * used to lock it must be used to unlock it. If derived from a wallet, the\r
+       * password for the account is the wallet seed.\r
+       *\r
+       * @param {Key} password Used previously to lock the Account\r
+       * @returns Private key bytes as a Uint8Array\r
+       */\r
+       async export (password: Key): Promise<Uint8Array<ArrayBuffer>>\r
+       /**\r
+       * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without\r
+       * exposing the private keys of accounts.\r
+       *\r
+       * Retrieves and decrypts the private key of the Account. The same password\r
+       * used to lock it must be used to unlock it. If derived from a wallet, the\r
+       * password for the account is the wallet seed.\r
+       *\r
+       * @param {Key} password Used previously to lock the Account\r
+       * @returns Private key bytes as a hexadecimal string\r
+       */\r
+       async export (password: Key, format: 'hex'): Promise<string>\r
+       async export (password: Key, format?: 'hex'): Promise<Key> {\r
+               if (typeof password === 'string') password = utf8.toBytes(password)\r
+               try {\r
+                       const privateKey = await this.#export(password)\r
+                       return format === 'hex'\r
+                               ? bytes.toHex(privateKey)\r
+                               : privateKey\r
+               } catch (err) {\r
+                       console.log(err)\r
+                       throw new Error('Failed to export Account private key')\r
+               } finally {\r
+                       bytes.erase(password)\r
+               }\r
+       }\r
+\r
        /**\r
        * Refreshes the account from its current state on the network.\r
        *\r
@@ -207,67 +246,24 @@ export class Account {
        * Signs a block using the private key of the account. The signature is\r
        * appended to the signature field of the block before being returned.\r
        *\r
-       * @param {Key} password - Required to decrypt the private key for signing\r
        * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - The block data to be hashed and signed\r
+       * @param {Key} password - Required to decrypt the private key for signing\r
        * @returns {Promise<string>} Hexadecimal-formatted 64-byte signature\r
        */\r
        async sign (block: ChangeBlock | ReceiveBlock | SendBlock, password: Key): Promise<string> {\r
-               const privateKey = await this.exportPrivateKey(password)\r
+               if (typeof password === 'string') password = utf8.toBytes(password)\r
                try {\r
                        const headers = {\r
                                method: 'detached'\r
                        }\r
-                       const data = {\r
-                               privateKey: privateKey.buffer,\r
+                       const result = await NanoNaClWorker.assign(headers, {\r
+                               privateKey: (await this.#export(password)).buffer,\r
                                msg: hex.toBytes(block.hash).buffer\r
-                       }\r
-                       const result = await NanoNaClWorker.assign(headers, data)\r
+                       })\r
                        block.signature = result\r
                        return result\r
                } catch (err) {\r
                        throw new Error(`Failed to sign block`, { cause: err })\r
-               } finally {\r
-                       bytes.erase(privateKey)\r
-               }\r
-       }\r
-\r
-       /**\r
-       * Retrieves and decryptes the private key of the Account. The same password\r
-       * used to lock it must be used to unlock it.\r
-       *\r
-       * @param {Key} password Used previously to lock the Account\r
-       * @returns Private key bytes as a Uint8Array\r
-       */\r
-       async exportPrivateKey (password: Key): Promise<Uint8Array<ArrayBuffer>>\r
-       /**\r
-       * Retrieves and decryptes the private key of the Account. The same password\r
-       * used to lock it must be used to unlock it.\r
-       *\r
-       * @param {Key} password Used previously to lock the Account\r
-       * @returns Private key bytes as a hexadecimal string\r
-       */\r
-       async exportPrivateKey (password: Key, format: 'hex'): Promise<string>\r
-       async exportPrivateKey (password: Key, format?: 'hex'): Promise<Key> {\r
-               if (typeof password === 'string') password = utf8.toBytes(password)\r
-               if (password == null || !(password instanceof Uint8Array)) {\r
-                       throw new Error('Password must be string or bytes')\r
-               }\r
-               try {\r
-                       const headers = {\r
-                               method: 'get',\r
-                               name: this.publicKey,\r
-                               store: 'Account'\r
-                       }\r
-                       const data = {\r
-                               password: password.buffer\r
-                       }\r
-                       const response = await SafeWorker.assign(headers, data)\r
-                       const privateKey = new Uint8Array(response[this.publicKey] as ArrayBuffer)\r
-                       return format === 'hex'\r
-                               ? bytes.toHex(privateKey)\r
-                               : privateKey\r
-               } catch (err) {\r
-                       throw new Error(`Failed to export private key for Account ${this.address}`, { cause: err })\r
                } finally {\r
                        bytes.erase(password)\r
                }\r
@@ -320,6 +316,35 @@ export class Account {
                return publicKey\r
        }\r
 \r
+       /**\r
+       * Retrieves and decrypts the private key of the Account. The same password\r
+       * used to lock it must be used to unlock it.\r
+       *\r
+       * @param {Key} password Used previously to lock the Account\r
+       * @returns Private key bytes as a Uint8Array\r
+       */\r
+       async #export (password: Key): Promise<Uint8Array<ArrayBuffer>> {\r
+               if (typeof password === 'string') password = utf8.toBytes(password)\r
+               if (password == null || !(password instanceof Uint8Array)) {\r
+                       throw new Error('Password must be string or bytes')\r
+               }\r
+               try {\r
+                       const headers = {\r
+                               method: 'get',\r
+                               name: this.publicKey,\r
+                               store: 'Account'\r
+                       }\r
+                       const response = await SafeWorker.assign(headers, {\r
+                               password: password.buffer\r
+                       })\r
+                       return new Uint8Array(response[this.publicKey] as ArrayBuffer)\r
+               } catch (err) {\r
+                       throw new Error(`Failed to export private key for Account ${this.address}`, { cause: err })\r
+               } finally {\r
+                       bytes.erase(password)\r
+               }\r
+       }\r
+\r
        /**\r
        * Instantiates an Account object from its private key which is then encrypted\r
        * and stored in IndexedDB. The corresponding public key will automatically be\r
@@ -348,10 +373,9 @@ export class Account {
                                const headers = {\r
                                        method: 'convert'\r
                                }\r
-                               const data = {\r
+                               const publicKey = await NanoNaClWorker.assign(headers, {\r
                                        privateKey: new Uint8Array(privateKey).buffer\r
-                               }\r
-                               const publicKey = await NanoNaClWorker.assign(headers, data)\r
+                               })\r
                                privateAccounts[publicKey] = privateKey.buffer\r
                                const address = this.#keyToAddress(hex.toBytes(publicKey))\r
                                this.#isInternal = true\r
index 092b32b3abc095f2194dd0219aecfbcb7286bbe6..1eec2c98ef20ab8620cebc7c9ae4cfe0efc651e3 100644 (file)
@@ -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<string>} Hash of the processed block
+       */
+       async process (rpc: Rpc): Promise<string> {
+               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<string>} Hash of the processed block
-       */
-       async process (rpc: Rpc): Promise<string> {
-               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 })
                }
index a9a445910988789ff4a5f456947f0553224983a7..eeeaac24a4d7d79a04fd27069bad81b104b65c7b 100644 (file)
@@ -95,11 +95,10 @@ export async function sign (key: Key, ...input: string[]): Promise<string> {
                const headers = {
                        method: 'detached'
                }
-               const data = {
+               return await NanoNaClWorker.assign(headers, {
                        privateKey: key.buffer,
                        msg: (hash(input) as Uint8Array<ArrayBuffer>).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<ArrayBuffer>).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 {
index 6cbe42470f92219d0ce39ca0a27ce49a939e1487..8ea927690a23d9919afdbf2b690957492a35ef4d 100644 (file)
@@ -215,10 +215,9 @@ export class Bip44Wallet extends Wallet {
                const headers = {\r
                        indexes\r
                }\r
-               const data = {\r
+               const results = await Bip44CkdWorker.assign(headers, {\r
                        seed: hex.toBytes(this.seed).buffer\r
-               }\r
-               const results = await Bip44CkdWorker.assign(headers, data)\r
+               })\r
                const privateKeys: KeyPair[] = []\r
                for (const i of Object.keys(results)) {\r
                        if (results[i] == null || !(results[i] instanceof ArrayBuffer)) {\r
index 28c28239ab40f33f6a24f342a2f62fcbb7907f89..cbb8e4c95edad53632982ff6f9cb3c58e9e0fada 100644 (file)
@@ -173,11 +173,10 @@ export abstract class Wallet {
                                method: 'set',\r
                                store: 'Wallet'\r
                        }\r
-                       const data: Data = {\r
+                       const success = await SafeWorker.assign(headers, {\r
                                [this.id]: encoded.buffer,\r
                                password: password.buffer\r
-                       }\r
-                       const success = await SafeWorker.assign(headers, data)\r
+                       })\r
                        if (!success) {\r
                                throw null\r
                        }\r
@@ -238,10 +237,9 @@ export abstract class Wallet {
                                name: this.id,\r
                                store: 'Wallet',\r
                        }\r
-                       const data = {\r
+                       const response = await SafeWorker.assign(headers, {\r
                                password: password.buffer\r
-                       }\r
-                       const response = await SafeWorker.assign(headers, data)\r
+                       })\r
                        const decoded = bytes.toUtf8(response[this.id])\r
                        const deserialized = JSON.parse(decoded)\r
                        let { id, mnemonic, seed } = deserialized\r
index bc24af2f320990d20aa2bd8f18d63546aff2fbb1..50a94152cd10e4ca30c285ea2f5e9a160f6b62a1 100644 (file)
@@ -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<ArrayBuffer>): 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<ArrayBuffer>[]): 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<Account>
+       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<Account>} Promise for a new Account object
        */
-       static import (privateKey: Uint8Array<ArrayBuffer>, password: Key): Promise<Account>
+       static import (keypair: KeyPair, password: Key): Promise<Account>
        /**
        * 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<Account[]>} Promise for array of new Account objects
        */
-       static import (privateKeys: string[], password: Key): Promise<Account[]>
+       static import (keypairs: KeyPair[], password: Key): Promise<Account[]>
        /**
-       * 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<Uint8Array<ArrayBuffer>>
+       /**
+       * 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<ArrayBuffer>[], password: Key): Promise<Account[]>
+       export (password: Key, format: 'hex'): Promise<string>
        /**
        * 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<string>} Hexadecimal-formatted 64-byte signature
        */
        sign (block: ChangeBlock | ReceiveBlock | SendBlock, password: Key): Promise<string>
        /**
-       * 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<Uint8Array<ArrayBuffer>>
-       /**
-       * 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<string>
-       /**
        * 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<Account>
+}
 
 /**
 * Represents a block as defined by the Nano cryptocurrency protocol. The Block
@@ -193,6 +187,16 @@ declare abstract class Block {
        */
        pow (): Promise<void>
        /**
+       * 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<string>} Hash of the processed block
+       */
+       process (rpc: Rpc): Promise<string>
+       /**
        * 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<void>
        /**
-       * 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<string>} Hash of the processed block
-       */
-       process (rpc: Rpc): Promise<string>
-       /**
        * 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<boolean>
 }
-
 /**
 * 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<Account>
-}
-
 export type Data = {
        [key: string]: ArrayBuffer
 }
index 00cf66e1232e9f1a5927459ca616459e40f43793..bcee3b39dcbdbb46d66cdc4196e823af202020c9 100644 (file)
@@ -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)\r
                await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
                const account = await wallet.account()\r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
 \r
                assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
                assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
@@ -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)\r
                await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
                const accounts = await wallet.accounts(1, 2)\r
-               const privateKey1 = await accounts[1].exportPrivateKey(wallet.seed, 'hex')\r
-               const privateKey2 = await accounts[2].exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey1 = await accounts[1].export(wallet.seed, 'hex')\r
+               const privateKey2 = await accounts[2].export(wallet.seed, 'hex')\r
 \r
                assert.equals(accounts.length, 2)\r
                assert.equals(privateKey1, NANO_TEST_VECTORS.PRIVATE_1)\r
@@ -59,7 +59,7 @@ await suite('Derive accounts from BIP-44 wallet', async () => {
                        assert.equals(a.index, i)\r
                        assert.exists(a.address)\r
                        assert.exists(a.publicKey)\r
-                       const privateKey = await a.exportPrivateKey(wallet.seed, 'hex')\r
+                       const privateKey = await a.export(wallet.seed, 'hex')\r
                        assert.exists(privateKey)\r
                }\r
 \r
@@ -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)\r
                await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
                const account = await wallet.account(1)\r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
 \r
                assert.equals(privateKey, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_1)\r
                // assert.equals(account.publicKey, NANO_TEST_VECTORS.BLAKE2B_PUBLIC_0)\r
@@ -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)\r
                await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
                const accounts = await wallet.accounts(1, 2)\r
-               // const privateKey1 = await accounts[1].exportPrivateKey(wallet.seed, 'hex')\r
-               // const privateKey2 = await accounts[2].exportPrivateKey(wallet.seed, 'hex')\r
+               // const privateKey1 = await accounts[1].export(wallet.seed, 'hex')\r
+               // const privateKey2 = await accounts[2].export(wallet.seed, 'hex')\r
 \r
                assert.equals(accounts.length, 2)\r
                // assert.equals(privateKey1, NANO_TEST_VECTORS.BLAKE2B_PRIVATE_1)\r
@@ -119,7 +119,7 @@ await suite('Derive accounts from BLAKE2b wallet', async () => {
                        assert.equals(a.index, i)\r
                        assert.exists(a.address)\r
                        assert.exists(a.publicKey)\r
-                       const privateKey = await a.exportPrivateKey(wallet.seed, 'hex')\r
+                       const privateKey = await a.export(wallet.seed, 'hex')\r
                        assert.exists(privateKey)\r
                }\r
 \r
index f43b86c666bbce1d4cbaa512d7b66367ed36c3f1..230488f6474557d9ce18d70920b8c3f23f5392da 100644 (file)
@@ -22,7 +22,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
                assert.equals(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
 \r
                await wallet.destroy()\r
@@ -41,7 +41,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_0)\r
                assert.equals(account.address, NANO_TEST_VECTORS.ADDRESS_0)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
 \r
                await wallet.destroy()\r
@@ -57,7 +57,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_0)\r
                assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_0)\r
 \r
                await wallet.destroy()\r
@@ -73,7 +73,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_1)\r
                assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_1)\r
 \r
                await wallet.destroy()\r
@@ -89,7 +89,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_2)\r
                assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_2)\r
 \r
                await wallet.destroy()\r
@@ -105,7 +105,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, CUSTOM_TEST_VECTORS.PUBLIC_3)\r
                assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, CUSTOM_TEST_VECTORS.PRIVATE_3)\r
 \r
                await wallet.destroy()\r
@@ -126,7 +126,7 @@ await suite('Import wallets', async () => {
                        assert.exists(accounts[i])\r
                        assert.exists(accounts[i].address)\r
                        assert.exists(accounts[i].publicKey)\r
-                       const privateKey = await accounts[i].exportPrivateKey(wallet.seed, 'hex')\r
+                       const privateKey = await accounts[i].export(wallet.seed, 'hex')\r
                        assert.exists(privateKey)\r
                }\r
 \r
@@ -148,7 +148,7 @@ await suite('Import wallets', async () => {
                        assert.exists(accounts[i])\r
                        assert.exists(accounts[i].address)\r
                        assert.exists(accounts[i].publicKey)\r
-                       const privateKey = await accounts[i].exportPrivateKey(wallet.seed, 'hex')\r
+                       const privateKey = await accounts[i].export(wallet.seed, 'hex')\r
                        assert.exists(privateKey)\r
                }\r
 \r
@@ -168,13 +168,13 @@ await suite('Import wallets', async () => {
                assert.ok(accounts[0] instanceof Account)\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
-               const privateKey0 = await accounts[0].exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey0 = await accounts[0].export(wallet.seed, 'hex')\r
                assert.equals(privateKey0, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_0)\r
 \r
                assert.ok(accounts[1] instanceof Account)\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
-               const privateKey1 = await accounts[1].exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey1 = await accounts[1].export(wallet.seed, 'hex')\r
                assert.equals(privateKey1, TREZOR_TEST_VECTORS.BLAKE2B_1_PRIVATE_1)\r
 \r
                await wallet.destroy()\r
@@ -184,7 +184,7 @@ await suite('Import wallets', async () => {
                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.exportPrivateKey(wallet.seed, 'hex')\r
+               const walletAccountPrivateKey = await walletAccount.export(wallet.seed, 'hex')\r
 \r
                assert.ok('mnemonic' in wallet)\r
                assert.ok('seed' in wallet)\r
@@ -194,7 +194,7 @@ await suite('Import wallets', async () => {
                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.exportPrivateKey(imported.seed, 'hex')\r
+               const importedAccountPrivateKey = await importedAccount.export(imported.seed, 'hex')\r
 \r
                assert.equals(imported.mnemonic, wallet.mnemonic)\r
                assert.equals(imported.seed, wallet.seed)\r
@@ -217,7 +217,7 @@ await suite('Import wallets', async () => {
                assert.equals(account.publicKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PUBLIC_0)\r
                assert.equals(account.address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0)\r
 \r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                assert.equals(privateKey, TREZOR_TEST_VECTORS.BLAKE2B_3_PRIVATE_0)\r
 \r
                await wallet.destroy()\r
index 06804a3c8a94f32f00962f31e55632e885bd203c..67d8e01b319da7347c0d567da23598455f9d3dbe 100644 (file)
@@ -60,7 +60,7 @@ await suite('Lock and unlock wallets', async () => {
                assert.equals(lockResult, true)\r
 \r
                const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
 \r
                assert.equals(unlockResult, true)\r
                assert.equals(privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
@@ -207,7 +207,7 @@ await suite('Lock and unlock wallets', async () => {
                assert.equals(lockResult, true)\r
 \r
                const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
-               const privateKey = await account.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
 \r
                assert.equals(unlockResult, true)\r
                assert.equals(privateKey, TREZOR_TEST_VECTORS.BLAKE2B_PRIVATE_0)\r
index c31f962e3201e63dea08dbbe97d42e90014ec1b2..1a6adea4b390b8c1dda4db616b62a9449621090e 100644 (file)
@@ -105,7 +105,7 @@ await suite('signature tests', async () => {
                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.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                const sendBlock = new SendBlock(\r
                        account.address,\r
                        '5618869000000000000000000000000',\r
@@ -125,7 +125,7 @@ await suite('signature tests', async () => {
                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.exportPrivateKey(wallet.seed, 'hex')\r
+               const privateKey = await account.export(wallet.seed, 'hex')\r
                const sendBlock = new SendBlock(\r
                        account.address,\r
                        '5618869000000000000000000000000',\r