/**
* Decrypts the input and sets the seed and, if it is included, the mnemonic.
*/
- static async unlock (key: CryptoKey, iv: ArrayBuffer, encrypted?: ArrayBuffer): Promise<NamedData<boolean>> {
+ static async unlock (key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise<NamedData<boolean>> {
try {
+ if (key == null) {
+ throw new TypeError('Wallet password is required')
+ }
+ if (iv == null) {
+ throw new TypeError('Wallet IV is required')
+ }
if (encrypted == null) {
- throw new TypeError('Wallet encrypted secrets required to unlock')
+ throw new TypeError('Wallet encrypted data is required')
}
const { seed, mnemonic } = await this.#decryptWallet(key, iv, encrypted)
if (!(seed instanceof ArrayBuffer)) {
const action = messageData.action
debugger
// Password for lock/unlock key
- if ('password' in messageData || !(messageData.password instanceof ArrayBuffer)) {
+ if (messageData.password != null && !(messageData.password instanceof ArrayBuffer)) {
throw new TypeError('Password must be ArrayBuffer')
}
- const password: ArrayBuffer = messageData.password
+ const password = messageData.password
// IV for crypto key, included if unlocking or generated if creating
if (action === 'unlock' && !(messageData.iv instanceof ArrayBuffer)) {
: crypto.getRandomValues(new Uint8Array(32)).buffer
// CryptoKey from password, decryption key if unlocking else encryption key
- const key = await this.#createAesKey(action === 'unlock' ? 'decrypt' : 'encrypt', password, keySalt)
+ const key = password instanceof ArrayBuffer
+ ? await this.#createAesKey(action === 'unlock' ? 'decrypt' : 'encrypt', password, keySalt)
+ : undefined
// Type of wallet
if (messageData.type !== undefined && messageData.type !== 'BIP-44' && messageData.type !== 'BLAKE2b') {