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': {
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')
}
* 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()
}
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'
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()
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'
: 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'
* 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')
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 })
}
}
}
* @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
* @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