From: Chris Duncan Date: Fri, 29 Nov 2024 10:45:27 +0000 (-0800) Subject: Add typings. Remove unnecessary allocation when hashing. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=cf3f6099886a8d612dbfa3f14ac5239661ffe9a6;p=libnemo.git Add typings. Remove unnecessary allocation when hashing. --- diff --git a/src/lib/workers/nano-nacl.ts b/src/lib/workers/nano-nacl.ts index 4ef0df1..0cab73d 100644 --- a/src/lib/workers/nano-nacl.ts +++ b/src/lib/workers/nano-nacl.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later - +//@ts-nocheck 'use strict' // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. @@ -525,12 +525,8 @@ async function NanoNaCl (Blake2b: Blake2b) { } // Note: difference from TweetNaCl - BLAKE2b used to hash instead of SHA-512. - function crypto_hash (out, m, n) { - const input = new Uint8Array(n) - for (let i = 0; i < n; ++i) { - input[i] = m[i] - } - const hash = new Blake2b(64).update(input).digest() + function crypto_hash (out: Uint8Array, m: Uint8Array, n: number) { + const hash = new Blake2b(64).update(m).digest() for (let i = 0; i < 64; ++i) { out[i] = hash[i] } @@ -665,7 +661,7 @@ async function NanoNaCl (Blake2b: Blake2b) { } // Note: difference from C - smlen returned, not passed as argument. - function crypto_sign (sm, m, n, sk) { + function crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array) { var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64) var i, j, x = new Float64Array(64) var p = [gf(), gf(), gf(), gf()] @@ -738,7 +734,7 @@ async function NanoNaCl (Blake2b: Blake2b) { return 0 } - function crypto_sign_open (m, sm, n, pk) { + function crypto_sign_open (m: Uint8Array, sm: Uint8Array, n: number, pk: Uint8Array) { var i var t = new Uint8Array(32), h = new Uint8Array(64) var p = [gf(), gf(), gf(), gf()],