From: Chris Duncan Date: Thu, 31 Jul 2025 23:02:56 +0000 (-0700) Subject: Fix password parsing. X-Git-Tag: v0.10.5~47^2~33 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=841cdda578dbbb73680a787f304e7986da08e925;p=libnemo.git Fix password parsing. --- diff --git a/src/lib/safe.ts b/src/lib/safe.ts index b42baa4..1defc8e 100644 --- a/src/lib/safe.ts +++ b/src/lib/safe.ts @@ -229,10 +229,16 @@ export class Safe { /** * Decrypts the input and sets the seed and, if it is included, the mnemonic. */ - static async unlock (key: CryptoKey, iv: ArrayBuffer, encrypted?: ArrayBuffer): Promise> { + static async unlock (key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise> { 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)) { @@ -362,10 +368,10 @@ export class Safe { 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)) { @@ -384,7 +390,9 @@ export class Safe { : 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') {