From 6f0f5d9f5b4f2cf064e07e0e869fd522fb724d56 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 6 Aug 2025 10:35:30 -0700 Subject: [PATCH] Adjust error handling for block signature verification. --- src/lib/block.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 1e38fbf..7258ef1 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -477,15 +477,16 @@ class Block { * @param {string} [key] - Hexadecimal-formatted public key to use for verification * @returns {boolean} True if block was signed by the matching private key */ - async verify (key?: string): Promise { - key ??= this.account.publicKey - if (!key) { - throw new Error('Provide a key for block signature verification.') - } + async verify (key?: string): Promise + async verify (key: unknown): Promise { try { + key ??= this.account.publicKey + if (typeof key !== 'string') { + throw new Error('Invalid key') + } return await NanoNaCl.verify(this.hash, hex.toBytes(this.signature ?? ''), hex.toBytes(key)) } catch (err) { - throw new Error(`Failed to derive public key from private key`, { cause: err }) + throw new Error('Failed to verify block signature', { cause: err }) } } } -- 2.47.3