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

index a942801e6db714a0b86aed8e89814cfa27a1899a..5b8c2b0f9d3cd97dcd1cb9c06426ba3219262e72 100644 (file)
@@ -487,20 +487,7 @@ export class NanoNaCl {
        static detached (message: Uint8Array<ArrayBuffer>, privateKey: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>\r
        static detached (message: unknown, privateKey: unknown): Uint8Array<ArrayBuffer> {\r
                try {\r
-                       if (!(message instanceof Uint8Array)) {\r
-                               throw new TypeError('Message must be Uint8Array')\r
-                       }\r
-                       if (!(privateKey instanceof Uint8Array)) {\r
-                               throw new TypeError('Private key must be Uint8Array')\r
-                       }\r
-                       const m = new Uint8Array(message)\r
-                       const mLen = m.length\r
-                       const prv = new Uint8Array(privateKey)\r
-                       message = undefined\r
-                       privateKey = undefined\r
-                       const sm = new Uint8Array(this.crypto_sign_BYTES + mLen)\r
-                       const pub = this.convert(prv)\r
-                       this.crypto_sign(sm, m, mLen, prv, pub)\r
+                       const sm = this.sign(message as Uint8Array<ArrayBuffer>, privateKey as Uint8Array<ArrayBuffer>)\r
                        return new Uint8Array(sm.buffer.slice(0, this.crypto_sign_BYTES))\r
                } catch (err) {\r
                        throw new Error('Failed to sign and return signature', { cause: err })\r