]> git.codecow.com Git - libnemo.git/commitdiff
Adjust error handling for block signature verification.
authorChris Duncan <chris@zoso.dev>
Wed, 6 Aug 2025 17:35:30 +0000 (10:35 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 6 Aug 2025 17:35:30 +0000 (10:35 -0700)
src/lib/block.ts

index 1e38fbf721f9b5fcfa5ecba254af66c7d1156f1e..7258ef1ca3f788cf9aad52a5356768f72717cbc9 100644 (file)
@@ -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<boolean> {
-               key ??= this.account.publicKey
-               if (!key) {
-                       throw new Error('Provide a key for block signature verification.')
-               }
+       async verify (key?: string): Promise<boolean>
+       async verify (key: unknown): Promise<boolean> {
                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 })
                }
        }
 }