]> git.codecow.com Git - libnemo.git/commitdiff
Offload type checking to called function.
authorChris Duncan <chris@zoso.dev>
Sun, 17 Aug 2025 23:00:11 +0000 (16:00 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 17 Aug 2025 23:00:11 +0000 (16:00 -0700)
src/lib/crypto/nano-nacl.ts

index cd6ecc71e920a65bab8de221a9be2168da20752b..35e57abab437edb24f6a5afb8e10debf61c766f9 100644 (file)
@@ -574,31 +574,18 @@ export class NanoNaCl {
        static verify (signedMessage: unknown, signature: unknown, publicKey: unknown): boolean {\r
                try {\r
                        if (!(signedMessage instanceof Uint8Array)) {\r
-                               throw new TypeError('Message must be Uint8Array')\r
+                               throw new TypeError('Signed message must be Uint8Array')\r
                        }\r
                        if (!(signature instanceof Uint8Array)) {\r
                                throw new TypeError('Signature must be Uint8Array')\r
                        }\r
-                       if (!(publicKey instanceof Uint8Array)) {\r
-                               throw new TypeError('Public key must be Uint8Array')\r
-                       }\r
                        if (signature.byteLength !== this.crypto_sign_BYTES) {\r
                                throw new Error(`Signature must be ${this.crypto_sign_BYTES} bytes`)\r
                        }\r
-                       if (publicKey.byteLength !== this.crypto_sign_PUBLICKEYBYTES) {\r
-                               throw new Error(`Public key must be ${this.crypto_sign_PUBLICKEYBYTES} bytes`)\r
-                       }\r
-                       const msg = new Uint8Array(signedMessage)\r
-                       const sig = new Uint8Array(signature)\r
-                       const pub = new Uint8Array(publicKey)\r
-                       signedMessage = undefined\r
-                       signature = undefined\r
-                       publicKey = undefined\r
-                       const sm = new Uint8Array(this.crypto_sign_BYTES + msg.length)\r
-                       const m = new Uint8Array(this.crypto_sign_BYTES + msg.length)\r
-                       sm.set(sig, 0)\r
-                       sm.set(msg, this.crypto_sign_BYTES)\r
-                       return (this.crypto_sign_open(m, sm, sm.length, pub) >= 0)\r
+                       const sm = new Uint8Array(this.crypto_sign_BYTES + signedMessage.length)\r
+                       sm.set(signature, 0)\r
+                       sm.set(signedMessage, this.crypto_sign_BYTES)\r
+                       return (this.open(sm, publicKey as Uint8Array<ArrayBuffer>).byteLength >= 0)\r
                } catch (err) {\r
                        throw new Error('Failed to verify signature on message with the given public key', { cause: err })\r
                }\r