]> git.codecow.com Git - libnemo.git/commitdiff
Rename wallet import to avoid confusion with JS keyword.
authorChris Duncan <chris@zoso.dev>
Sun, 10 Aug 2025 00:33:14 +0000 (17:33 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 10 Aug 2025 00:33:14 +0000 (17:33 -0700)
src/lib/wallet/ledger.ts
src/lib/wallet/safe.ts
src/lib/wallet/wallet.ts

index 89d2dabba57ee5dc8007a6610c46e59a534e8b50..eab4086561b20fed6828fc644575bbf2da5a259b 100644 (file)
@@ -354,7 +354,7 @@ export class Ledger extends Wallet {
        */\r
        async verify (mnemonic: string): Promise<boolean>\r
        async verify (secret: string): Promise<boolean> {\r
-               const testWallet = await Wallet.import('BIP-44', '', secret)\r
+               const testWallet = await Wallet.load('BIP-44', '', secret)\r
                await testWallet.unlock('')\r
                const testAccount = await testWallet.account(0)\r
                const testOpenBlock = await new Block(testAccount.address, '0', testAccount.publicKey, testAccount.address)\r
index 83677cff92abc7c38404471dc42a29a843ea4f27..6b18a1fbbaa8e2306eafd8b08bacd6ae4ab78e6b 100644 (file)
@@ -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<NamedData<ArrayBuffer>> {
+       static async load (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise<NamedData<ArrayBuffer>> {
                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<NamedData<ArrayBuffer>> {
+       static async #load (type?: 'BIP-44' | 'BLAKE2b', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise<NamedData<ArrayBuffer>> {
                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 })
                }
        }
 }
index 61aa240128605d6c70c834dd6dace134119c86e9..cd78d37451eee02079c963fcf4b95856d921cc6e 100644 (file)
@@ -92,7 +92,7 @@ export class Wallet {
        * @param {string} [salt=''] - Used when generating the final seed\r
        * @returns {Wallet} A newly instantiated Wallet\r
        */\r
-       static async import (type: 'BIP-44' | 'BLAKE2b', password: string, seed: string): Promise<Wallet>\r
+       static async load (type: 'BIP-44' | 'BLAKE2b', password: string, seed: string): Promise<Wallet>\r
        /**\r
        * Imports an existing HD wallet by using an entropy value generated using a\r
        * cryptographically strong pseudorandom number generator.\r
@@ -101,13 +101,13 @@ export class Wallet {
        * @param {string} [salt=''] - Used when generating the final seed\r
        * @returns {Wallet} A newly instantiated Wallet\r
        */\r
-       static async import (type: 'BIP-44' | 'BLAKE2b', password: string, mnemonicPhrase: string, mnemonicSalt?: string): Promise<Wallet>\r
-       static async import (type: 'BIP-44' | 'BLAKE2b', password: string, secret: string, mnemonicSalt?: string): Promise<Wallet> {\r
+       static async load (type: 'BIP-44' | 'BLAKE2b', password: string, mnemonicPhrase: string, mnemonicSalt?: string): Promise<Wallet>\r
+       static async load (type: 'BIP-44' | 'BLAKE2b', password: string, secret: string, mnemonicSalt?: string): Promise<Wallet> {\r
                Wallet.#isInternal = true\r
                const self = new this(type)\r
                try {\r
                        const data: NamedData = {\r
-                               action: 'import',\r
+                               action: 'load',\r
                                type,\r
                                password: utf8.toBuffer(password)\r
                        }\r