From f913730e4576d123950eff754403f4993c169615 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 4 Dec 2024 06:27:17 -0800 Subject: [PATCH] Return empty byte array instead of null if there are issues opening a signed message. Return detached signature as uppercase hex so calling function can ingest it more easily. --- src/lib/nano-nacl.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/nano-nacl.ts b/src/lib/nano-nacl.ts index d6f9fad..5f5b651 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -809,25 +809,25 @@ const n = () => { return signedMsg } - const open = function (signedMsg: Uint8Array, publicKey: Uint8Array): Uint8Array | null { + const open = function (signedMsg: Uint8Array, publicKey: Uint8Array): Uint8Array { checkArrayTypes(signedMsg, publicKey) if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) throw new Error('bad public key size') const tmp = new Uint8Array(signedMsg.length) var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey) - if (mlen < 0) return null + if (mlen < 0) return new Uint8Array(0) var m = new Uint8Array(mlen) for (var i = 0; i < m.length; i++) m[i] = tmp[i] return m } - const detached = function (msg: Uint8Array, secretKey: Uint8Array): Uint8Array { + const detached = function (msg: Uint8Array, secretKey: Uint8Array): string { var signedMsg = sign(msg, secretKey) var sig = new Uint8Array(crypto_sign_BYTES) for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i] - return sig + return hexify(sig).toUpperCase() } const verify = function (msg: Uint8Array, sig: Uint8Array, publicKey: Uint8Array): boolean { -- 2.34.1