From: Chris Duncan Date: Thu, 3 Jul 2025 21:02:45 +0000 (-0700) Subject: Ensure password bytes exist when locking or unlocking. X-Git-Tag: v0.10.5~136^2~4 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=273472ae5f4b7f1d1b64f077acca7a2468ddf6f9;p=libnemo.git Ensure password bytes exist when locking or unlocking. --- diff --git a/src/lib/account.ts b/src/lib/account.ts index 2bc5c1d..01bd615 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -137,6 +137,9 @@ export class Account { if (typeof password === 'string') { password = utf8.toBytes(password) } + if (password == null || password.constructor.name !== 'Uint8Array') { + throw new Error('Failed to unlock wallet') + } try { if (this.#prv != null) { await Account.#poolSafe.assign({ @@ -157,6 +160,9 @@ export class Account { if (typeof password === 'string') { password = utf8.toBytes(password) } + if (password == null || password.constructor.name !== 'Uint8Array') { + throw new Error('Failed to unlock wallet') + } try { this.#prv = await Account.#poolSafe.assign({ method: 'get', diff --git a/src/lib/wallets/wallet.ts b/src/lib/wallets/wallet.ts index a883563..474a8ba 100644 --- a/src/lib/wallets/wallet.ts +++ b/src/lib/wallets/wallet.ts @@ -229,6 +229,9 @@ export abstract class Wallet { if (typeof password === 'string') { password = utf8.toBytes(password) } + if (password == null || password.constructor.name !== 'Uint8Array') { + throw new Error('Failed to unlock wallet') + } let success = true try { const data: { id: string, mnemonic: string | null, seed: string | null } = { @@ -276,6 +279,9 @@ export abstract class Wallet { if (typeof password === 'string') { password = utf8.toBytes(password) } + if (password == null || password.constructor.name !== 'Uint8Array') { + throw new Error('Failed to unlock wallet') + } try { const data = await this.#poolSafe.assign({ method: 'get',