From 51e5c6aef7630f91f0ac66c0ae28e54e20f6847f Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 16:24:33 -0800 Subject: [PATCH] Add typings to resolve remaining typescript issues. --- src/lib/nano-nacl.ts | 73 +++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/lib/nano-nacl.ts b/src/lib/nano-nacl.ts index 2a07669..7e04d58 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -//@ts-nocheck + 'use strict' import { Blake2b } from './blake2b.js' @@ -69,7 +69,7 @@ const n = () => { o[0] += c - 1 + 37 * (c - 1) } - function sel25519 (p, q, b): void { + function sel25519 (p: Float64Array, q: Float64Array, b: number): void { let t const c = ~(b - 1) for (let i = 0; i < 16; i++) { @@ -79,7 +79,7 @@ const n = () => { } } - function pack25519 (o, n): void { + function pack25519 (o: Uint8Array, n: Float64Array): void { let b: number const m: Float64Array = gf() const t: Float64Array = gf() @@ -104,34 +104,34 @@ const n = () => { } } - function neq25519 (a, b): number { - var c = new Uint8Array(32), d = new Uint8Array(32) + function neq25519 (a: Float64Array, b: Float64Array): number { + const c = new Uint8Array(32) + const d = new Uint8Array(32) pack25519(c, a) pack25519(d, b) return crypto_verify_32(c, 0, d, 0) } - function par25519 (a): number { + function par25519 (a: Float64Array): number { var d = new Uint8Array(32) pack25519(d, a) return d[0] & 1 } - function unpack25519 (o, n): void { - var i - for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8) + function unpack25519 (o: Float64Array, n: Uint8Array): void { + for (let i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8) o[15] &= 0x7fff } - function A (o, a, b): void { + function A (o: Float64Array, a: Float64Array, b: Float64Array): void { for (let i = 0; i < 16; i++) o[i] = a[i] + b[i] } - function Z (o, a: Float64Array, b): void { + function Z (o: Float64Array, a: Float64Array, b: Float64Array): void { for (let i = 0; i < 16; i++) o[i] = a[i] - b[i] } - function M (o, a: Float64Array, b: Float64Array): void { + function M (o: Float64Array, a: Float64Array, b: Float64Array): void { let v, c, t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, @@ -502,23 +502,22 @@ const n = () => { o[15] = t15 } - function S (o, a): void { + function S (o: Float64Array, a: Float64Array): void { M(o, a, a) } - function inv25519 (o, i): void { - var c = gf() - var a - for (a = 0; a < 16; a++) c[a] = i[a] - for (a = 253; a >= 0; a--) { + function inv25519 (o: Float64Array, i: Float64Array): void { + const c: Float64Array = gf() + for (let a = 0; a < 16; a++) c[a] = i[a] + for (let a = 253; a >= 0; a--) { S(c, c) if (a !== 2 && a !== 4) M(c, c, i) } - for (a = 0; a < 16; a++) o[a] = c[a] + for (let a = 0; a < 16; a++) o[a] = c[a] } - function pow2523 (o, i): void { - var c = gf() + function pow2523 (o: Float64Array, i: Float64Array): void { + const c: Float64Array = gf() for (let a = 0; a < 16; a++) c[a] = i[a] for (let a = 250; a >= 0; a--) { S(c, c) @@ -536,10 +535,16 @@ const n = () => { return 0 } - function add (p, q): void { - const a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf() + function add (p: Float64Array[], q: Float64Array[]): void { + const a: Float64Array = gf() + const b: Float64Array = gf() + const c: Float64Array = gf() + const d: Float64Array = gf() + const e: Float64Array = gf() + const f: Float64Array = gf() + const g: Float64Array = gf() + const h: Float64Array = gf() + const t: Float64Array = gf() Z(a, p[1], p[0]) Z(t, q[1], q[0]) @@ -562,14 +567,16 @@ const n = () => { M(p[3], e, h) } - function cswap (p, q, b): void { + function cswap (p: Float64Array[], q: Float64Array[], b: number): void { for (let i = 0; i < 4; i++) { sel25519(p[i], q[i], b) } } - function pack (r, p): void { - const tx = gf(), ty = gf(), zi = gf() + function pack (r: Uint8Array, p: Float64Array[]): void { + const tx: Float64Array = gf() + const ty: Float64Array = gf() + const zi: Float64Array = gf() inv25519(zi, p[2]) M(tx, p[0], zi) M(ty, p[1], zi) @@ -673,9 +680,13 @@ const n = () => { } function unpackneg (r: Float64Array[], p: Uint8Array): -1 | 0 { - const t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf() + const t: Float64Array = gf() + const chk: Float64Array = gf() + const num: Float64Array = gf() + const den: Float64Array = gf() + const den2: Float64Array = gf() + const den4: Float64Array = gf() + const den6: Float64Array = gf() set25519(r[2], gf1) unpack25519(r[1], p) -- 2.34.1