result = await this.unlock(key, iv, encrypted)
break
}
+ case 'update': {
+ result = await this.update(key, keySalt)
+ break
+ }
case 'verify': {
result = await this.verify(seed, mnemonicPhrase)
break
}
}
+ /**
+ * Decrypts the input and sets the seed and, if it is included, the mnemonic.
+ */
+ static async update (key?: CryptoKey, keySalt?: ArrayBuffer): Promise<NamedData<ArrayBuffer>> {
+ try {
+ if (this.#locked) {
+ throw new Error('Wallet is locked')
+ }
+ if (this.#seed == null) {
+ throw new Error('Wallet seed not found')
+ }
+ if (key == null || keySalt == null) {
+ throw new TypeError('Wallet password is required')
+ }
+ const { iv, encrypted } = await this.#encryptWallet(key)
+ return { iv, salt: keySalt, encrypted }
+ } catch (err) {
+ console.error(err)
+ throw new Error('Failed to update wallet password', { cause: err })
+ }
+ }
+
/**
* Checks the seed and, if it exists, the mnemonic against input. The wallet
* must be unlocked prior to verification.
}
// Seed to import
- if (action === 'import' && !(messageData.seed instanceof ArrayBuffer)) {
+ if (action === 'import' && 'seed' in message && !(messageData.seed instanceof ArrayBuffer)) {
throw new TypeError('Seed required to import wallet')
}
const seed = messageData.seed instanceof ArrayBuffer