/**\r
* Listens for messages from a calling function.\r
*/\r
- addEventListener('message', (message) => {\r
+ addEventListener('message', message => {\r
const data = JSON.parse(new TextDecoder().decode(message.data ?? message))\r
for (const d of data) {\r
d.publicKey = hexify(convert(d.privateKey).publicKey)\r
postMessage(buf, [buf])\r
})\r
\r
- var gf = function (init?: number[]) {\r
+ const gf = function (init?: number[]): Float64Array {\r
const r = new Float64Array(16)\r
if (init) for (let i = 0; i < init.length; i++) r[i] = init[i]\r
return r\r
}\r
\r
- var gf0 = gf(),\r
- gf1 = gf([1]),\r
- D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),\r
- D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),\r
- X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),\r
- Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),\r
- I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83])\r
+ const gf0 = gf()\r
+ const gf1 = gf([1])\r
+ const D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203])\r
+ const D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406])\r
+ const X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169])\r
+ const Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666])\r
+ const I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83])\r
\r
- function vn (x, xi, y, yi, n) {\r
+ function vn (x, xi, y, yi, n): number {\r
var i, d = 0\r
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i]\r
return (1 & ((d - 1) >>> 8)) - 1\r
}\r
\r
- function crypto_verify_32 (x, xi, y, yi) {\r
+ function crypto_verify_32 (x, xi, y, yi): number {\r
return vn(x, xi, y, yi, 32)\r
}\r
\r
- function set25519 (r, a) {\r
+ function set25519 (r, a): void {\r
var i\r
for (i = 0; i < 16; i++) r[i] = a[i] | 0\r
}\r
o[0] += c - 1 + 37 * (c - 1)\r
}\r
\r
- function sel25519 (p, q, b) {\r
+ function sel25519 (p, q, b): void {\r
var t, c = ~(b - 1)\r
for (var i = 0; i < 16; i++) {\r
t = c & (p[i] ^ q[i])\r
}\r
}\r
\r
- function pack25519 (o, n) {\r
+ function pack25519 (o, n): void {\r
var i, j, b\r
var m = gf(), t = gf()\r
for (i = 0; i < 16; i++) t[i] = n[i]\r
}\r
}\r
\r
- function neq25519 (a, b) {\r
+ function neq25519 (a, b): number {\r
var c = new Uint8Array(32), d = new Uint8Array(32)\r
pack25519(c, a)\r
pack25519(d, b)\r
return crypto_verify_32(c, 0, d, 0)\r
}\r
\r
- function par25519 (a) {\r
+ function par25519 (a): number {\r
var d = new Uint8Array(32)\r
pack25519(d, a)\r
return d[0] & 1\r
}\r
\r
- function unpack25519 (o, n) {\r
+ function unpack25519 (o, n): void {\r
var i\r
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8)\r
o[15] &= 0x7fff\r
}\r
\r
- function A (o, a, b) {\r
+ function A (o, a, b): void {\r
for (let i = 0; i < 16; i++) o[i] = a[i] + b[i]\r
}\r
\r
- function Z (o, a, b) {\r
+ function Z (o, a, b): void {\r
for (let i = 0; i < 16; i++) o[i] = a[i] - b[i]\r
}\r
\r
- function M (o, a, b) {\r
+ function M (o, a, b): void {\r
let v, c,\r
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,\r
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,\r
o[15] = t15\r
}\r
\r
- function S (o, a) {\r
+ function S (o, a): void {\r
M(o, a, a)\r
}\r
\r
- function inv25519 (o, i) {\r
+ function inv25519 (o, i): void {\r
var c = gf()\r
var a\r
for (a = 0; a < 16; a++) c[a] = i[a]\r
for (a = 0; a < 16; a++) o[a] = c[a]\r
}\r
\r
- function pow2523 (o, i) {\r
+ function pow2523 (o, i): void {\r
var c = gf()\r
var a\r
for (a = 0; a < 16; a++) c[a] = i[a]\r
}\r
\r
// Note: difference from TweetNaCl - BLAKE2b used to hash instead of SHA-512.\r
- function crypto_hash (out: Uint8Array, m: Uint8Array, n: number) {\r
+ function crypto_hash (out: Uint8Array, m: Uint8Array, n: number): number {\r
const input = new Uint8Array(n)\r
for (let i = 0; i < n; ++i) input[i] = m[i]\r
const hash = new Blake2b(64).update(m).digest()\r
return 0\r
}\r
\r
- function add (p, q) {\r
+ function add (p, q): void {\r
const a = gf(), b = gf(), c = gf(),\r
d = gf(), e = gf(), f = gf(),\r
g = gf(), h = gf(), t = gf()\r
M(p[3], e, h)\r
}\r
\r
- function cswap (p, q, b) {\r
+ function cswap (p, q, b): void {\r
for (let i = 0; i < 4; i++) {\r
sel25519(p[i], q[i], b)\r
}\r
}\r
\r
- function pack (r, p) {\r
+ function pack (r, p): void {\r
const tx = gf(), ty = gf(), zi = gf()\r
inv25519(zi, p[2])\r
M(tx, p[0], zi)\r
r[31] ^= par25519(tx) << 7\r
}\r
\r
- function scalarmult (p, q, s) {\r
+ function scalarmult (p, q, s): void {\r
set25519(p[0], gf0)\r
set25519(p[1], gf1)\r
set25519(p[2], gf1)\r
}\r
}\r
\r
- function scalarbase (p, s) {\r
+ function scalarbase (p, s): void {\r
const q = [gf(), gf(), gf(), gf()]\r
set25519(q[0], X)\r
set25519(q[1], Y)\r
\r
const L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10])\r
\r
- function modL (r, x) {\r
+ function modL (r, x): void {\r
let carry, i, j, k\r
for (i = 63; i >= 32; --i) {\r
carry = 0\r
}\r
}\r
\r
- function reduce (r) {\r
+ function reduce (r): void {\r
let x = new Float64Array(64), i\r
for (i = 0; i < 64; i++) x[i] = r[i]\r
for (i = 0; i < 64; i++) r[i] = 0\r
}\r
\r
// Note: difference from C - smlen returned, not passed as argument.\r
- function crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array) {\r
+ function crypto_sign (sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array): number {\r
const d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64)\r
const x = new Float64Array(64)\r
const p = [gf(), gf(), gf(), gf()]\r
return smlen\r
}\r
\r
- function unpackneg (r, p) {\r
+ function unpackneg (r, p): -1 | 0 {\r
const t = gf(), chk = gf(), num = gf(),\r
den = gf(), den2 = gf(), den4 = gf(),\r
den6 = gf()\r
\r
S(chk, r[0])\r
M(chk, chk, den)\r
+\r
if (neq25519(chk, num)) return -1\r
\r
if (par25519(r[0]) === (p[31] >> 7)) Z(r[0], gf0, r[0])\r
-\r
M(r[3], r[0], r[1])\r
return 0\r
}\r