]> git.codecow.com Git - libnemo.git/commitdiff
Explicitly type function variables to ensure type safety. Use const where possible.
authorChris Duncan <chris@zoso.dev>
Thu, 14 Aug 2025 13:56:24 +0000 (06:56 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 14 Aug 2025 13:56:24 +0000 (06:56 -0700)
src/lib/crypto/nano-nacl.ts

index c2c4d1d42557d45765a2b18627f5b7b362cac463..b00a0177af718a256309aa57e23398d9aae380c0 100644 (file)
@@ -27,7 +27,7 @@ export class NanoNaCl {
        static XY: BigInt64Array = new BigInt64Array([0xdd90n, 0xa5b7n, 0x8ab3n, 0x6dden, 0x52f5n, 0x7751n, 0x9f80n, 0x20f0n, 0xe37dn, 0x64abn, 0x4e8en, 0x66ean, 0x7665n, 0xd78bn, 0x5f0fn, 0xe787n])\r
 \r
        static #vn (x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number): number {\r
-               let d = 0\r
+               let d: number = 0\r
                for (let i = 0; i < n; i++) {\r
                        d |= x[xi + i] ^ y[yi + i]\r
                }\r
@@ -48,7 +48,8 @@ export class NanoNaCl {
        }\r
 \r
        static car25519 (out: BigInt64Array): void {\r
-               let v, c, s = 1n << 16n\r
+               let v: bigint, c: bigint\r
+               const s: bigint = 1n << 16n\r
                c = 0n\r
                for (let i = 0; i < 16; i++) {\r
                        v = out[i] + c + s\r
@@ -71,8 +72,8 @@ export class NanoNaCl {
        }\r
 \r
        static neq25519 (a: BigInt64Array, b: BigInt64Array): number {\r
-               const c = new Uint8Array(32)\r
-               const d = new Uint8Array(32)\r
+               const c: Uint8Array = new Uint8Array(32)\r
+               const d: Uint8Array = new Uint8Array(32)\r
                this.pack25519(c, a)\r
                this.pack25519(d, b)\r
                return this.#vn(c, 0, d, 0, 32)\r
@@ -104,7 +105,7 @@ export class NanoNaCl {
        }\r
 \r
        static par25519 (a: BigInt64Array): number {\r
-               const d = new Uint8Array(32)\r
+               const d: Uint8Array = new Uint8Array(32)\r
                this.pack25519(d, a)\r
                return d[0] & 1\r
        }\r
@@ -139,7 +140,8 @@ export class NanoNaCl {
        }\r
 \r
        static Multiply (out: BigInt64Array, a: BigInt64Array, b: BigInt64Array): void {\r
-               let v, c, s: bigint = 1n << 16n\r
+               let v: bigint, c: bigint\r
+               const s: bigint = 1n << 16n\r
                const t: BigInt64Array = new BigInt64Array(31)\r
                t.fill(0n)\r
 \r
@@ -178,7 +180,8 @@ export class NanoNaCl {
        }\r
 \r
        static Square (out: BigInt64Array, a: BigInt64Array): void {\r
-               let v, c, s: bigint = 1n << 16n\r
+               let v: bigint, c: bigint\r
+               const s: bigint = 1n << 16n\r
                const t: BigInt64Array = new BigInt64Array(31)\r
                t.fill(0n)\r
 \r
@@ -324,7 +327,7 @@ export class NanoNaCl {
        }\r
 \r
        static reduce (r: Uint8Array): void {\r
-               const x = new BigInt64Array(64)\r
+               const x: BigInt64Array = new BigInt64Array(64)\r
                for (let i = 0; i < 64; i++) {\r
                        x[i] = BigInt(r[i])\r
                }\r