From fb06f39c3431dcdeb51d68fc9948e11d00cce0bc Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 17 Aug 2025 16:00:11 -0700 Subject: [PATCH] Offload type checking to called function. --- src/lib/crypto/nano-nacl.ts | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/lib/crypto/nano-nacl.ts b/src/lib/crypto/nano-nacl.ts index cd6ecc7..35e57ab 100644 --- a/src/lib/crypto/nano-nacl.ts +++ b/src/lib/crypto/nano-nacl.ts @@ -574,31 +574,18 @@ export class NanoNaCl { static verify (signedMessage: unknown, signature: unknown, publicKey: unknown): boolean { try { if (!(signedMessage instanceof Uint8Array)) { - throw new TypeError('Message must be Uint8Array') + throw new TypeError('Signed message must be Uint8Array') } if (!(signature instanceof Uint8Array)) { throw new TypeError('Signature must be Uint8Array') } - if (!(publicKey instanceof Uint8Array)) { - throw new TypeError('Public key must be Uint8Array') - } if (signature.byteLength !== this.crypto_sign_BYTES) { throw new Error(`Signature must be ${this.crypto_sign_BYTES} bytes`) } - if (publicKey.byteLength !== this.crypto_sign_PUBLICKEYBYTES) { - throw new Error(`Public key must be ${this.crypto_sign_PUBLICKEYBYTES} bytes`) - } - const msg = new Uint8Array(signedMessage) - const sig = new Uint8Array(signature) - const pub = new Uint8Array(publicKey) - signedMessage = undefined - signature = undefined - publicKey = undefined - const sm = new Uint8Array(this.crypto_sign_BYTES + msg.length) - const m = new Uint8Array(this.crypto_sign_BYTES + msg.length) - sm.set(sig, 0) - sm.set(msg, this.crypto_sign_BYTES) - return (this.crypto_sign_open(m, sm, sm.length, pub) >= 0) + const sm = new Uint8Array(this.crypto_sign_BYTES + signedMessage.length) + sm.set(signature, 0) + sm.set(signedMessage, this.crypto_sign_BYTES) + return (this.open(sm, publicKey as Uint8Array).byteLength >= 0) } catch (err) { throw new Error('Failed to verify signature on message with the given public key', { cause: err }) } -- 2.47.3