From 273472ae5f4b7f1d1b64f077acca7a2468ddf6f9 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 3 Jul 2025 14:02:45 -0700 Subject: [PATCH] Ensure password bytes exist when locking or unlocking. --- src/lib/account.ts | 6 ++++++ src/lib/wallets/wallet.ts | 6 ++++++ 2 files changed, 12 insertions(+) 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', -- 2.47.3