From: Chris Duncan Date: Sun, 10 Aug 2025 00:33:14 +0000 (-0700) Subject: Rename wallet import to avoid confusion with JS keyword. X-Git-Tag: v0.10.5~41^2~141 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=52991ec8037ef210d6efadc0523f91e6a3ebc8c1;p=libnemo.git Rename wallet import to avoid confusion with JS keyword. --- diff --git a/src/lib/wallet/ledger.ts b/src/lib/wallet/ledger.ts index 89d2dab..eab4086 100644 --- a/src/lib/wallet/ledger.ts +++ b/src/lib/wallet/ledger.ts @@ -354,7 +354,7 @@ export class Ledger extends Wallet { */ async verify (mnemonic: string): Promise async verify (secret: string): Promise { - const testWallet = await Wallet.import('BIP-44', '', secret) + const testWallet = await Wallet.load('BIP-44', '', secret) await testWallet.unlock('') const testAccount = await testWallet.account(0) const testOpenBlock = await new Block(testAccount.address, '0', testAccount.publicKey, testAccount.address) diff --git a/src/lib/wallet/safe.ts b/src/lib/wallet/safe.ts index 83677cf..6b18a1f 100644 --- a/src/lib/wallet/safe.ts +++ b/src/lib/wallet/safe.ts @@ -53,8 +53,8 @@ export class Safe { result = await this.derive(index) break } - case 'import': { - result = await this.import(type, key, keySalt, mnemonicPhrase ?? seed, mnemonicSalt) + case 'load': { + result = await this.load(type, key, keySalt, mnemonicPhrase ?? seed, mnemonicSalt) break } case 'lock': { @@ -115,7 +115,7 @@ export class Safe { try { const entropy = crypto.getRandomValues(new Uint8Array(32)) const { phrase: mnemonicPhrase } = await Bip39.fromEntropy(entropy) - const record = await this.#import(type, key, keySalt, mnemonicPhrase, mnemonicSalt) + const record = await this.#load(type, key, keySalt, mnemonicPhrase, mnemonicSalt) if (this.#seed == null || this.#mnemonic == null) { throw new Error('Failed to generate seed and mnemonic') } @@ -160,15 +160,15 @@ export class Safe { * Encrypts an existing seed or mnemonic+salt and returns the initialization * vector, salt, and encrypted data representing the wallet in a locked state. */ - static async import (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise> { + static async load (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise> { try { - const record = await this.#import(type, key, keySalt, secret, mnemonicSalt) + const record = await this.#load(type, key, keySalt, secret, mnemonicSalt) if (this.#seed == null) { throw new Error('Wallet seed not found') } return record } catch (err) { - throw new Error('Failed to import wallet', { cause: err }) + throw new Error('Failed to load wallet', { cause: err }) } finally { this.lock() } @@ -390,7 +390,7 @@ export class Safe { if (messageData.action !== 'STOP' && messageData.action !== 'create' && messageData.action !== 'derive' - && messageData.action !== 'import' + && messageData.action !== 'load' && messageData.action !== 'lock' && messageData.action !== 'sign' && messageData.action !== 'unlock' @@ -442,13 +442,13 @@ export class Safe { const type: 'BIP-44' | 'BLAKE2b' | undefined = messageData.type // Import requires seed or mnemonic phrase - if (action === 'import' && messageData.seed == null && messageData.mnemonicPhrase == null) { - throw new TypeError('Seed or mnemonic phrase required to import wallet') + if (action === 'load' && messageData.seed == null && messageData.mnemonicPhrase == null) { + throw new TypeError('Seed or mnemonic phrase required to load wallet') } - // Seed to import - if (action === 'import' && 'seed' in messageData && !(messageData.seed instanceof ArrayBuffer)) { - throw new TypeError('Seed required to import wallet') + // Seed to load + if (action === 'load' && 'seed' in messageData && !(messageData.seed instanceof ArrayBuffer)) { + throw new TypeError('Seed required to load wallet') } const seed = messageData.seed instanceof ArrayBuffer ? messageData.seed.slice() @@ -458,8 +458,8 @@ export class Safe { delete messageData.seed } - // Mnemonic phrase to import - if (action === 'import' && 'mnemonicPhrase' in message && typeof messageData.mnemonicPhrase !== 'string') { + // Mnemonic phrase to load + if (action === 'load' && 'mnemonicPhrase' in message && typeof messageData.mnemonicPhrase !== 'string') { throw new TypeError('Invalid mnemonic phrase') } const mnemonicPhrase = typeof messageData.mnemonicPhrase === 'string' @@ -467,8 +467,8 @@ export class Safe { : undefined delete messageData.mnemonicPhrase - // Mnemonic salt for mnemonic phrase to import - if (action === 'import' && messageData.mnemonicSalt != undefined && typeof messageData.mnemonicSalt !== 'string') { + // Mnemonic salt for mnemonic phrase to load + if (action === 'load' && messageData.mnemonicSalt != undefined && typeof messageData.mnemonicSalt !== 'string') { throw new TypeError('Invalid mnemonic salt for mnemonic phrase') } const mnemonicSalt = typeof messageData.mnemonicSalt === 'string' @@ -522,7 +522,7 @@ export class Safe { * Encrypts an existing seed or mnemonic+salt and returns the initialization * vector, salt, and encrypted data representing the wallet in a locked state. */ - static async #import (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise> { + static async #load (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise> { try { if (!this.#locked) { throw new Error('Wallet is in use') @@ -568,7 +568,7 @@ export class Safe { const { iv, encrypted } = await this.#encryptWallet(key) return { iv, salt: keySalt, encrypted } } catch (err) { - throw new Error('Failed to import wallet', { cause: err }) + throw new Error('Failed to load wallet', { cause: err }) } } } diff --git a/src/lib/wallet/wallet.ts b/src/lib/wallet/wallet.ts index 61aa240..cd78d37 100644 --- a/src/lib/wallet/wallet.ts +++ b/src/lib/wallet/wallet.ts @@ -92,7 +92,7 @@ export class Wallet { * @param {string} [salt=''] - Used when generating the final seed * @returns {Wallet} A newly instantiated Wallet */ - static async import (type: 'BIP-44' | 'BLAKE2b', password: string, seed: string): Promise + static async load (type: 'BIP-44' | 'BLAKE2b', password: string, seed: string): Promise /** * Imports an existing HD wallet by using an entropy value generated using a * cryptographically strong pseudorandom number generator. @@ -101,13 +101,13 @@ export class Wallet { * @param {string} [salt=''] - Used when generating the final seed * @returns {Wallet} A newly instantiated Wallet */ - static async import (type: 'BIP-44' | 'BLAKE2b', password: string, mnemonicPhrase: string, mnemonicSalt?: string): Promise - static async import (type: 'BIP-44' | 'BLAKE2b', password: string, secret: string, mnemonicSalt?: string): Promise { + static async load (type: 'BIP-44' | 'BLAKE2b', password: string, mnemonicPhrase: string, mnemonicSalt?: string): Promise + static async load (type: 'BIP-44' | 'BLAKE2b', password: string, secret: string, mnemonicSalt?: string): Promise { Wallet.#isInternal = true const self = new this(type) try { const data: NamedData = { - action: 'import', + action: 'load', type, password: utf8.toBuffer(password) }