From: Chris Duncan Date: Wed, 6 Aug 2025 17:35:30 +0000 (-0700) Subject: Adjust error handling for block signature verification. X-Git-Tag: v0.10.5~43^2~71 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6f0f5d9f5b4f2cf064e07e0e869fd522fb724d56;p=libnemo.git Adjust error handling for block signature verification. --- 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 }) } } }