* @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 })
}
}
}