digiid-ts 2.0.0 → 2.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/digiid-ts.es.js +324 -323
- package/dist/digiid-ts.es.js.map +1 -1
- package/dist/digiid-ts.umd.js +2 -2
- package/dist/digiid-ts.umd.js.map +1 -1
- package/dist/digiid.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/digiid-ts.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Me = (e, t, r) => t in e ?
|
|
1
|
+
var Ve = Object.defineProperty;
|
|
2
|
+
var Me = (e, t, r) => t in e ? Ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var m = (e, t, r) => Me(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { randomBytes as Ye } from "crypto";
|
|
5
5
|
class C extends Error {
|
|
@@ -8,7 +8,7 @@ class C extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
function
|
|
11
|
+
function Tt(e) {
|
|
12
12
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
13
13
|
}
|
|
14
14
|
function ut(e, t = "") {
|
|
@@ -18,10 +18,10 @@ function ut(e, t = "") {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
function N(e, t, r = "") {
|
|
21
|
-
const n =
|
|
22
|
-
if (!n ||
|
|
23
|
-
const
|
|
24
|
-
throw new Error(
|
|
21
|
+
const n = Tt(e), s = e == null ? void 0 : e.length, o = t !== void 0;
|
|
22
|
+
if (!n || o && s !== t) {
|
|
23
|
+
const i = r && `"${r}" `, c = o ? ` of length ${t}` : "", f = n ? `length=${s}` : `type=${typeof e}`;
|
|
24
|
+
throw new Error(i + "expected Uint8Array" + c + ", got " + f);
|
|
25
25
|
}
|
|
26
26
|
return e;
|
|
27
27
|
}
|
|
@@ -79,13 +79,13 @@ function Rt(e) {
|
|
|
79
79
|
if (t % 2)
|
|
80
80
|
throw new Error("hex string expected, got unpadded hex of length " + t);
|
|
81
81
|
const n = new Uint8Array(r);
|
|
82
|
-
for (let s = 0,
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
const f = e[
|
|
86
|
-
throw new Error('hex string expected, got non-hex character "' + f + '" at index ' +
|
|
82
|
+
for (let s = 0, o = 0; s < r; s++, o += 2) {
|
|
83
|
+
const i = Wt(e.charCodeAt(o)), c = Wt(e.charCodeAt(o + 1));
|
|
84
|
+
if (i === void 0 || c === void 0) {
|
|
85
|
+
const f = e[o] + e[o + 1];
|
|
86
|
+
throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + o);
|
|
87
87
|
}
|
|
88
|
-
n[s] =
|
|
88
|
+
n[s] = i * 16 + c;
|
|
89
89
|
}
|
|
90
90
|
return n;
|
|
91
91
|
}
|
|
@@ -97,13 +97,13 @@ function it(...e) {
|
|
|
97
97
|
}
|
|
98
98
|
const r = new Uint8Array(t);
|
|
99
99
|
for (let n = 0, s = 0; n < e.length; n++) {
|
|
100
|
-
const
|
|
101
|
-
r.set(
|
|
100
|
+
const o = e[n];
|
|
101
|
+
r.set(o, s), s += o.length;
|
|
102
102
|
}
|
|
103
103
|
return r;
|
|
104
104
|
}
|
|
105
105
|
function Ge(e, t = {}) {
|
|
106
|
-
const r = (s,
|
|
106
|
+
const r = (s, o) => e(o).update(s).digest(), n = e(void 0);
|
|
107
107
|
return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.create = (s) => e(s), Object.assign(r, t), Object.freeze(r);
|
|
108
108
|
}
|
|
109
109
|
function le(e = 32) {
|
|
@@ -138,27 +138,27 @@ let We = class {
|
|
|
138
138
|
}
|
|
139
139
|
update(t) {
|
|
140
140
|
Bt(this), N(t);
|
|
141
|
-
const { view: r, buffer: n, blockLen: s } = this,
|
|
142
|
-
for (let
|
|
143
|
-
const c = Math.min(s - this.pos,
|
|
141
|
+
const { view: r, buffer: n, blockLen: s } = this, o = t.length;
|
|
142
|
+
for (let i = 0; i < o; ) {
|
|
143
|
+
const c = Math.min(s - this.pos, o - i);
|
|
144
144
|
if (c === s) {
|
|
145
145
|
const f = Ot(t);
|
|
146
|
-
for (; s <=
|
|
147
|
-
this.process(f,
|
|
146
|
+
for (; s <= o - i; i += s)
|
|
147
|
+
this.process(f, i);
|
|
148
148
|
continue;
|
|
149
149
|
}
|
|
150
|
-
n.set(t.subarray(
|
|
150
|
+
n.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === s && (this.process(r, 0), this.pos = 0);
|
|
151
151
|
}
|
|
152
152
|
return this.length += t.length, this.roundClean(), this;
|
|
153
153
|
}
|
|
154
154
|
digestInto(t) {
|
|
155
155
|
Bt(this), je(t, this), this.finished = !0;
|
|
156
|
-
const { buffer: r, view: n, blockLen: s, isLE:
|
|
157
|
-
let { pos:
|
|
158
|
-
r[
|
|
159
|
-
for (let d =
|
|
156
|
+
const { buffer: r, view: n, blockLen: s, isLE: o } = this;
|
|
157
|
+
let { pos: i } = this;
|
|
158
|
+
r[i++] = 128, vt(this.buffer.subarray(i)), this.padOffset > s - i && (this.process(n, 0), i = 0);
|
|
159
|
+
for (let d = i; d < s; d++)
|
|
160
160
|
r[d] = 0;
|
|
161
|
-
n.setBigUint64(s - 8, BigInt(this.length * 8),
|
|
161
|
+
n.setBigUint64(s - 8, BigInt(this.length * 8), o), this.process(n, 0);
|
|
162
162
|
const c = Ot(t), f = this.outputLen;
|
|
163
163
|
if (f % 4)
|
|
164
164
|
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
@@ -166,7 +166,7 @@ let We = class {
|
|
|
166
166
|
if (a > h.length)
|
|
167
167
|
throw new Error("_sha2: outputLen bigger than state");
|
|
168
168
|
for (let d = 0; d < a; d++)
|
|
169
|
-
c.setUint32(4 * d, h[d],
|
|
169
|
+
c.setUint32(4 * d, h[d], o);
|
|
170
170
|
}
|
|
171
171
|
digest() {
|
|
172
172
|
const { buffer: t, outputLen: r } = this;
|
|
@@ -176,8 +176,8 @@ let We = class {
|
|
|
176
176
|
}
|
|
177
177
|
_cloneInto(t) {
|
|
178
178
|
t || (t = new this.constructor()), t.set(...this.get());
|
|
179
|
-
const { blockLen: r, buffer: n, length: s, finished:
|
|
180
|
-
return t.destroyed =
|
|
179
|
+
const { blockLen: r, buffer: n, length: s, finished: o, destroyed: i, pos: c } = this;
|
|
180
|
+
return t.destroyed = i, t.finished = o, t.length = s, t.pos = c, s % r && t.buffer.set(n), t;
|
|
181
181
|
}
|
|
182
182
|
clone() {
|
|
183
183
|
return this._cloneInto();
|
|
@@ -263,26 +263,26 @@ class Qe extends We {
|
|
|
263
263
|
super(64, t, 8, !1);
|
|
264
264
|
}
|
|
265
265
|
get() {
|
|
266
|
-
const { A: t, B: r, C: n, D: s, E:
|
|
267
|
-
return [t, r, n, s,
|
|
266
|
+
const { A: t, B: r, C: n, D: s, E: o, F: i, G: c, H: f } = this;
|
|
267
|
+
return [t, r, n, s, o, i, c, f];
|
|
268
268
|
}
|
|
269
269
|
// prettier-ignore
|
|
270
|
-
set(t, r, n, s,
|
|
271
|
-
this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = s | 0, this.E =
|
|
270
|
+
set(t, r, n, s, o, i, c, f) {
|
|
271
|
+
this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = s | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
|
|
272
272
|
}
|
|
273
273
|
process(t, r) {
|
|
274
274
|
for (let d = 0; d < 16; d++, r += 4)
|
|
275
275
|
nt[d] = t.getUint32(r, !1);
|
|
276
276
|
for (let d = 16; d < 64; d++) {
|
|
277
|
-
const
|
|
278
|
-
nt[d] = U + nt[d - 7] +
|
|
277
|
+
const x = nt[d - 15], g = nt[d - 2], y = P(x, 7) ^ P(x, 18) ^ x >>> 3, U = P(g, 17) ^ P(g, 19) ^ g >>> 10;
|
|
278
|
+
nt[d] = U + nt[d - 7] + y + nt[d - 16] | 0;
|
|
279
279
|
}
|
|
280
|
-
let { A: n, B: s, C:
|
|
280
|
+
let { A: n, B: s, C: o, D: i, E: c, F: f, G: a, H: h } = this;
|
|
281
281
|
for (let d = 0; d < 64; d++) {
|
|
282
|
-
const
|
|
283
|
-
h = a, a = f, f = c, c =
|
|
282
|
+
const x = P(c, 6) ^ P(c, 11) ^ P(c, 25), g = h + x + ze(c, f, a) + Pe[d] + nt[d] | 0, U = (P(n, 2) ^ P(n, 13) ^ P(n, 22)) + Fe(n, s, o) | 0;
|
|
283
|
+
h = a, a = f, f = c, c = i + g | 0, i = o, o = s, s = n, n = g + U | 0;
|
|
284
284
|
}
|
|
285
|
-
n = n + this.A | 0, s = s + this.B | 0,
|
|
285
|
+
n = n + this.A | 0, s = s + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, a = a + this.G | 0, h = h + this.H | 0, this.set(n, s, o, i, c, f, a, h);
|
|
286
286
|
}
|
|
287
287
|
roundClean() {
|
|
288
288
|
vt(nt);
|
|
@@ -311,7 +311,7 @@ const tn = /* @__PURE__ */ Ge(
|
|
|
311
311
|
/* @__PURE__ */ Xe(1)
|
|
312
312
|
);
|
|
313
313
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
314
|
-
const
|
|
314
|
+
const Vt = /* @__PURE__ */ BigInt(0), $t = /* @__PURE__ */ BigInt(1);
|
|
315
315
|
function At(e, t = "") {
|
|
316
316
|
if (typeof e != "boolean") {
|
|
317
317
|
const r = t && `"${t}" `;
|
|
@@ -334,7 +334,7 @@ function pt(e) {
|
|
|
334
334
|
function he(e) {
|
|
335
335
|
if (typeof e != "string")
|
|
336
336
|
throw new Error("hex string expected, got " + typeof e);
|
|
337
|
-
return e === "" ?
|
|
337
|
+
return e === "" ? Vt : BigInt("0x" + e);
|
|
338
338
|
}
|
|
339
339
|
function Ut(e) {
|
|
340
340
|
return he(Lt(e));
|
|
@@ -355,7 +355,7 @@ function we(e, t) {
|
|
|
355
355
|
function en(e) {
|
|
356
356
|
return Uint8Array.from(e);
|
|
357
357
|
}
|
|
358
|
-
const Et = (e) => typeof e == "bigint" &&
|
|
358
|
+
const Et = (e) => typeof e == "bigint" && Vt <= e;
|
|
359
359
|
function nn(e, t, r) {
|
|
360
360
|
return Et(e) && Et(t) && Et(r) && t <= e && e < r;
|
|
361
361
|
}
|
|
@@ -365,7 +365,7 @@ function rn(e, t, r, n) {
|
|
|
365
365
|
}
|
|
366
366
|
function sn(e) {
|
|
367
367
|
let t;
|
|
368
|
-
for (t = 0; e >
|
|
368
|
+
for (t = 0; e > Vt; e >>= $t, t += 1)
|
|
369
369
|
;
|
|
370
370
|
return t;
|
|
371
371
|
}
|
|
@@ -373,19 +373,19 @@ const Yt = (e) => ($t << BigInt(e)) - $t;
|
|
|
373
373
|
function on(e, t, r) {
|
|
374
374
|
if (ut(e, "hashLen"), ut(t, "qByteLen"), typeof r != "function")
|
|
375
375
|
throw new Error("hmacFn must be a function");
|
|
376
|
-
const n = (I) => new Uint8Array(I), s = Uint8Array.of(),
|
|
376
|
+
const n = (I) => new Uint8Array(I), s = Uint8Array.of(), o = Uint8Array.of(0), i = Uint8Array.of(1), c = 1e3;
|
|
377
377
|
let f = n(e), a = n(e), h = 0;
|
|
378
378
|
const d = () => {
|
|
379
379
|
f.fill(1), a.fill(0), h = 0;
|
|
380
|
-
},
|
|
381
|
-
a =
|
|
382
|
-
},
|
|
380
|
+
}, x = (...I) => r(a, it(f, ...I)), g = (I = s) => {
|
|
381
|
+
a = x(o, I), f = x(), I.length !== 0 && (a = x(i, I), f = x());
|
|
382
|
+
}, y = () => {
|
|
383
383
|
if (h++ >= c)
|
|
384
384
|
throw new Error("drbg: tried max amount of iterations");
|
|
385
385
|
let I = 0;
|
|
386
386
|
const O = [];
|
|
387
387
|
for (; I < t; ) {
|
|
388
|
-
f =
|
|
388
|
+
f = x();
|
|
389
389
|
const j = f.slice();
|
|
390
390
|
O.push(j), I += f.length;
|
|
391
391
|
}
|
|
@@ -394,7 +394,7 @@ function on(e, t, r) {
|
|
|
394
394
|
return (I, O) => {
|
|
395
395
|
d(), g(I);
|
|
396
396
|
let j;
|
|
397
|
-
for (; !(j = O(
|
|
397
|
+
for (; !(j = O(y())); )
|
|
398
398
|
g();
|
|
399
399
|
return d(), j;
|
|
400
400
|
};
|
|
@@ -402,15 +402,15 @@ function on(e, t, r) {
|
|
|
402
402
|
function jt(e, t = {}, r = {}) {
|
|
403
403
|
if (!e || typeof e != "object")
|
|
404
404
|
throw new Error("expected valid options object");
|
|
405
|
-
function n(
|
|
406
|
-
const f = e[
|
|
405
|
+
function n(o, i, c) {
|
|
406
|
+
const f = e[o];
|
|
407
407
|
if (c && f === void 0)
|
|
408
408
|
return;
|
|
409
409
|
const a = typeof f;
|
|
410
|
-
if (a !==
|
|
411
|
-
throw new Error(`param "${
|
|
410
|
+
if (a !== i || f === null)
|
|
411
|
+
throw new Error(`param "${o}" is invalid: expected ${i}, got ${a}`);
|
|
412
412
|
}
|
|
413
|
-
const s = (
|
|
413
|
+
const s = (o, i) => Object.entries(o).forEach(([c, f]) => n(c, f, i));
|
|
414
414
|
s(t, !1), s(r, !0);
|
|
415
415
|
}
|
|
416
416
|
function Pt(e) {
|
|
@@ -419,8 +419,8 @@ function Pt(e) {
|
|
|
419
419
|
const s = t.get(r);
|
|
420
420
|
if (s !== void 0)
|
|
421
421
|
return s;
|
|
422
|
-
const
|
|
423
|
-
return t.set(r,
|
|
422
|
+
const o = e(r, ...n);
|
|
423
|
+
return t.set(r, o), o;
|
|
424
424
|
};
|
|
425
425
|
}
|
|
426
426
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -440,10 +440,10 @@ function Qt(e, t) {
|
|
|
440
440
|
throw new Error("invert: expected non-zero number");
|
|
441
441
|
if (t <= Y)
|
|
442
442
|
throw new Error("invert: expected positive modulus, got " + t);
|
|
443
|
-
let r = F(e, t), n = t, s = Y,
|
|
443
|
+
let r = F(e, t), n = t, s = Y, o = M;
|
|
444
444
|
for (; r !== Y; ) {
|
|
445
|
-
const c = n / r, f = n % r, a = s -
|
|
446
|
-
n = r, r = f, s =
|
|
445
|
+
const c = n / r, f = n % r, a = s - o * c;
|
|
446
|
+
n = r, r = f, s = o, o = a;
|
|
447
447
|
}
|
|
448
448
|
if (n !== M)
|
|
449
449
|
throw new Error("invert: does not exist");
|
|
@@ -458,15 +458,15 @@ function Ee(e, t) {
|
|
|
458
458
|
return Kt(e, n, t), n;
|
|
459
459
|
}
|
|
460
460
|
function an(e, t) {
|
|
461
|
-
const r = (e.ORDER - ye) / xe, n = e.mul(t, ft), s = e.pow(n, r),
|
|
461
|
+
const r = (e.ORDER - ye) / xe, n = e.mul(t, ft), s = e.pow(n, r), o = e.mul(t, s), i = e.mul(e.mul(o, ft), s), c = e.mul(o, e.sub(i, e.ONE));
|
|
462
462
|
return Kt(e, c, t), c;
|
|
463
463
|
}
|
|
464
464
|
function un(e) {
|
|
465
|
-
const t = St(e), r = Be(e), n = r(t, t.neg(t.ONE)), s = r(t, n),
|
|
465
|
+
const t = St(e), r = Be(e), n = r(t, t.neg(t.ONE)), s = r(t, n), o = r(t, t.neg(n)), i = (e + cn) / me;
|
|
466
466
|
return (c, f) => {
|
|
467
|
-
let a = c.pow(f,
|
|
468
|
-
const d = c.mul(a, s),
|
|
469
|
-
a = c.cmov(a, h, g), h = c.cmov(
|
|
467
|
+
let a = c.pow(f, i), h = c.mul(a, n);
|
|
468
|
+
const d = c.mul(a, s), x = c.mul(a, o), g = c.eql(c.sqr(h), f), y = c.eql(c.sqr(d), f);
|
|
469
|
+
a = c.cmov(a, h, g), h = c.cmov(x, d, y);
|
|
470
470
|
const U = c.eql(c.sqr(h), f), I = c.cmov(a, h, U);
|
|
471
471
|
return Kt(c, I, f), I;
|
|
472
472
|
};
|
|
@@ -484,23 +484,23 @@ function Be(e) {
|
|
|
484
484
|
throw new Error("Cannot find square root: probably non-prime P");
|
|
485
485
|
if (r === 1)
|
|
486
486
|
return Ee;
|
|
487
|
-
let
|
|
488
|
-
const
|
|
487
|
+
let o = s.pow(n, t);
|
|
488
|
+
const i = (t + M) / ft;
|
|
489
489
|
return function(f, a) {
|
|
490
490
|
if (f.is0(a))
|
|
491
491
|
return a;
|
|
492
492
|
if (Jt(f, a) !== 1)
|
|
493
493
|
throw new Error("Cannot find square root");
|
|
494
|
-
let h = r, d = f.mul(f.ONE,
|
|
495
|
-
for (; !f.eql(
|
|
496
|
-
if (f.is0(
|
|
494
|
+
let h = r, d = f.mul(f.ONE, o), x = f.pow(a, t), g = f.pow(a, i);
|
|
495
|
+
for (; !f.eql(x, f.ONE); ) {
|
|
496
|
+
if (f.is0(x))
|
|
497
497
|
return f.ZERO;
|
|
498
|
-
let
|
|
498
|
+
let y = 1, U = f.sqr(x);
|
|
499
499
|
for (; !f.eql(U, f.ONE); )
|
|
500
|
-
if (
|
|
500
|
+
if (y++, U = f.sqr(U), y === h)
|
|
501
501
|
throw new Error("Cannot find square root");
|
|
502
|
-
const I = M << BigInt(h -
|
|
503
|
-
h =
|
|
502
|
+
const I = M << BigInt(h - y - 1), O = f.pow(d, I);
|
|
503
|
+
h = y, d = f.sqr(O), x = f.mul(x, d), g = f.mul(g, O);
|
|
504
504
|
}
|
|
505
505
|
return g;
|
|
506
506
|
};
|
|
@@ -548,14 +548,14 @@ function gn(e, t, r) {
|
|
|
548
548
|
return n;
|
|
549
549
|
}
|
|
550
550
|
function ve(e, t, r = !1) {
|
|
551
|
-
const n = new Array(t.length).fill(r ? e.ZERO : void 0), s = t.reduce((
|
|
552
|
-
return t.reduceRight((
|
|
551
|
+
const n = new Array(t.length).fill(r ? e.ZERO : void 0), s = t.reduce((i, c, f) => e.is0(c) ? i : (n[f] = i, e.mul(i, c)), e.ONE), o = e.inv(s);
|
|
552
|
+
return t.reduceRight((i, c, f) => e.is0(c) ? i : (n[f] = e.mul(i, n[f]), e.mul(i, c)), o), n;
|
|
553
553
|
}
|
|
554
554
|
function Jt(e, t) {
|
|
555
|
-
const r = (e.ORDER - M) / ft, n = e.pow(t, r), s = e.eql(n, e.ONE),
|
|
556
|
-
if (!s && !
|
|
555
|
+
const r = (e.ORDER - M) / ft, n = e.pow(t, r), s = e.eql(n, e.ONE), o = e.eql(n, e.ZERO), i = e.eql(n, e.neg(e.ONE));
|
|
556
|
+
if (!s && !o && !i)
|
|
557
557
|
throw new Error("invalid Legendre symbol result");
|
|
558
|
-
return s ? 1 :
|
|
558
|
+
return s ? 1 : o ? 0 : -1;
|
|
559
559
|
}
|
|
560
560
|
function wn(e, t) {
|
|
561
561
|
t !== void 0 && ut(t);
|
|
@@ -574,15 +574,15 @@ class bn {
|
|
|
574
574
|
m(this, "_sqrt");
|
|
575
575
|
// cached sqrt
|
|
576
576
|
m(this, "_mod");
|
|
577
|
-
var
|
|
577
|
+
var i;
|
|
578
578
|
if (t <= Y)
|
|
579
579
|
throw new Error("invalid field: expected ORDER > 0, got " + t);
|
|
580
580
|
let n;
|
|
581
|
-
this.isLE = !1, r != null && typeof r == "object" && (typeof r.BITS == "number" && (n = r.BITS), typeof r.sqrt == "function" && (this.sqrt = r.sqrt), typeof r.isLE == "boolean" && (this.isLE = r.isLE), r.allowedLengths && (this._lengths = (
|
|
582
|
-
const { nBitLength: s, nByteLength:
|
|
583
|
-
if (
|
|
581
|
+
this.isLE = !1, r != null && typeof r == "object" && (typeof r.BITS == "number" && (n = r.BITS), typeof r.sqrt == "function" && (this.sqrt = r.sqrt), typeof r.isLE == "boolean" && (this.isLE = r.isLE), r.allowedLengths && (this._lengths = (i = r.allowedLengths) == null ? void 0 : i.slice()), typeof r.modFromBytes == "boolean" && (this._mod = r.modFromBytes));
|
|
582
|
+
const { nBitLength: s, nByteLength: o } = wn(t, n);
|
|
583
|
+
if (o > 2048)
|
|
584
584
|
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
585
|
-
this.ORDER = t, this.BITS = s, this.BYTES =
|
|
585
|
+
this.ORDER = t, this.BITS = s, this.BYTES = o, this._sqrt = void 0, Object.preventExtensions(this);
|
|
586
586
|
}
|
|
587
587
|
create(t) {
|
|
588
588
|
return F(t, this.ORDER);
|
|
@@ -650,17 +650,17 @@ class bn {
|
|
|
650
650
|
}
|
|
651
651
|
fromBytes(t, r = !1) {
|
|
652
652
|
N(t);
|
|
653
|
-
const { _lengths: n, BYTES: s, isLE:
|
|
653
|
+
const { _lengths: n, BYTES: s, isLE: o, ORDER: i, _mod: c } = this;
|
|
654
654
|
if (n) {
|
|
655
655
|
if (!n.includes(t.length) || t.length > s)
|
|
656
656
|
throw new Error("Field.fromBytes: expected " + n + " bytes, got " + t.length);
|
|
657
657
|
const a = new Uint8Array(s);
|
|
658
|
-
a.set(t,
|
|
658
|
+
a.set(t, o ? 0 : a.length - t.length), t = a;
|
|
659
659
|
}
|
|
660
660
|
if (t.length !== s)
|
|
661
661
|
throw new Error("Field.fromBytes: expected " + s + " bytes, got " + t.length);
|
|
662
|
-
let f =
|
|
663
|
-
if (c && (f = F(f,
|
|
662
|
+
let f = o ? ge(t) : Ut(t);
|
|
663
|
+
if (c && (f = F(f, i)), !r && !this.isValid(f))
|
|
664
664
|
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
665
665
|
return f;
|
|
666
666
|
}
|
|
@@ -689,10 +689,10 @@ function Ae(e) {
|
|
|
689
689
|
}
|
|
690
690
|
function pn(e, t, r = !1) {
|
|
691
691
|
N(e);
|
|
692
|
-
const n = e.length, s = Re(t),
|
|
693
|
-
if (n < 16 || n <
|
|
694
|
-
throw new Error("expected " +
|
|
695
|
-
const
|
|
692
|
+
const n = e.length, s = Re(t), o = Ae(t);
|
|
693
|
+
if (n < 16 || n < o || n > 1024)
|
|
694
|
+
throw new Error("expected " + o + "-1024 bytes of input, got " + n);
|
|
695
|
+
const i = r ? ge(e) : Ut(e), c = F(i, t - M) + M;
|
|
696
696
|
return r ? we(c, s) : Mt(c, s);
|
|
697
697
|
}
|
|
698
698
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -711,15 +711,15 @@ function Ie(e, t) {
|
|
|
711
711
|
}
|
|
712
712
|
function Ht(e, t) {
|
|
713
713
|
Ie(e, t);
|
|
714
|
-
const r = Math.ceil(t / e) + 1, n = 2 ** (e - 1), s = 2 ** e,
|
|
715
|
-
return { windows: r, windowSize: n, mask:
|
|
714
|
+
const r = Math.ceil(t / e) + 1, n = 2 ** (e - 1), s = 2 ** e, o = Yt(e), i = BigInt(e);
|
|
715
|
+
return { windows: r, windowSize: n, mask: o, maxNumber: s, shiftBy: i };
|
|
716
716
|
}
|
|
717
717
|
function ee(e, t, r) {
|
|
718
|
-
const { windowSize: n, mask: s, maxNumber:
|
|
719
|
-
let c = Number(e & s), f = e >>
|
|
720
|
-
c > n && (c -=
|
|
721
|
-
const a = t * n, h = a + Math.abs(c) - 1, d = c === 0,
|
|
722
|
-
return { nextN: f, offset: h, isZero: d, isNeg:
|
|
718
|
+
const { windowSize: n, mask: s, maxNumber: o, shiftBy: i } = r;
|
|
719
|
+
let c = Number(e & s), f = e >> i;
|
|
720
|
+
c > n && (c -= o, f += at);
|
|
721
|
+
const a = t * n, h = a + Math.abs(c) - 1, d = c === 0, x = c < 0, g = t % 2 !== 0;
|
|
722
|
+
return { nextN: f, offset: h, isZero: d, isNeg: x, isNegF: g, offsetF: a };
|
|
723
723
|
}
|
|
724
724
|
const qt = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap();
|
|
725
725
|
function Nt(e) {
|
|
@@ -758,15 +758,15 @@ class yn {
|
|
|
758
758
|
* @returns precomputed point tables flattened to a single array
|
|
759
759
|
*/
|
|
760
760
|
precomputeWindow(t, r) {
|
|
761
|
-
const { windows: n, windowSize: s } = Ht(r, this.bits),
|
|
762
|
-
let
|
|
761
|
+
const { windows: n, windowSize: s } = Ht(r, this.bits), o = [];
|
|
762
|
+
let i = t, c = i;
|
|
763
763
|
for (let f = 0; f < n; f++) {
|
|
764
|
-
c =
|
|
764
|
+
c = i, o.push(c);
|
|
765
765
|
for (let a = 1; a < s; a++)
|
|
766
|
-
c = c.add(
|
|
767
|
-
|
|
766
|
+
c = c.add(i), o.push(c);
|
|
767
|
+
i = c.double();
|
|
768
768
|
}
|
|
769
|
-
return
|
|
769
|
+
return o;
|
|
770
770
|
}
|
|
771
771
|
/**
|
|
772
772
|
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
@@ -777,13 +777,13 @@ class yn {
|
|
|
777
777
|
wNAF(t, r, n) {
|
|
778
778
|
if (!this.Fn.isValid(n))
|
|
779
779
|
throw new Error("invalid scalar");
|
|
780
|
-
let s = this.ZERO,
|
|
781
|
-
const
|
|
782
|
-
for (let c = 0; c <
|
|
783
|
-
const { nextN: f, offset: a, isZero: h, isNeg: d, isNegF:
|
|
784
|
-
n = f, h ?
|
|
780
|
+
let s = this.ZERO, o = this.BASE;
|
|
781
|
+
const i = Ht(t, this.bits);
|
|
782
|
+
for (let c = 0; c < i.windows; c++) {
|
|
783
|
+
const { nextN: f, offset: a, isZero: h, isNeg: d, isNegF: x, offsetF: g } = ee(n, c, i);
|
|
784
|
+
n = f, h ? o = o.add(It(x, r[g])) : s = s.add(It(d, r[a]));
|
|
785
785
|
}
|
|
786
|
-
return ne(n), { p: s, f:
|
|
786
|
+
return ne(n), { p: s, f: o };
|
|
787
787
|
}
|
|
788
788
|
/**
|
|
789
789
|
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
@@ -791,9 +791,9 @@ class yn {
|
|
|
791
791
|
* @returns point
|
|
792
792
|
*/
|
|
793
793
|
wNAFUnsafe(t, r, n, s = this.ZERO) {
|
|
794
|
-
const
|
|
795
|
-
for (let
|
|
796
|
-
const { nextN: c, offset: f, isZero: a, isNeg: h } = ee(n,
|
|
794
|
+
const o = Ht(t, this.bits);
|
|
795
|
+
for (let i = 0; i < o.windows && n !== dt; i++) {
|
|
796
|
+
const { nextN: c, offset: f, isZero: a, isNeg: h } = ee(n, i, o);
|
|
797
797
|
if (n = c, !a) {
|
|
798
798
|
const d = r[f];
|
|
799
799
|
s = s.add(h ? d.negate() : d);
|
|
@@ -810,8 +810,8 @@ class yn {
|
|
|
810
810
|
return this.wNAF(s, this.getPrecomputes(s, t, n), r);
|
|
811
811
|
}
|
|
812
812
|
unsafe(t, r, n, s) {
|
|
813
|
-
const
|
|
814
|
-
return
|
|
813
|
+
const o = Nt(t);
|
|
814
|
+
return o === 1 ? this._unsafeLadder(t, r, s) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, n), r, s);
|
|
815
815
|
}
|
|
816
816
|
// We calculate precomputes for elliptic curve point multiplication
|
|
817
817
|
// using windowed method. This specifies window size and
|
|
@@ -824,10 +824,10 @@ class yn {
|
|
|
824
824
|
}
|
|
825
825
|
}
|
|
826
826
|
function xn(e, t, r, n) {
|
|
827
|
-
let s = t,
|
|
827
|
+
let s = t, o = e.ZERO, i = e.ZERO;
|
|
828
828
|
for (; r > dt || n > dt; )
|
|
829
|
-
r & at && (
|
|
830
|
-
return { p1:
|
|
829
|
+
r & at && (o = o.add(s)), n & at && (i = i.add(s)), s = s.double(), r >>= at, n >>= at;
|
|
830
|
+
return { p1: o, p2: i };
|
|
831
831
|
}
|
|
832
832
|
function re(e, t, r) {
|
|
833
833
|
if (t) {
|
|
@@ -845,11 +845,11 @@ function mn(e, t, r = {}, n) {
|
|
|
845
845
|
if (!(typeof a == "bigint" && a > dt))
|
|
846
846
|
throw new Error(`CURVE.${f} must be positive bigint`);
|
|
847
847
|
}
|
|
848
|
-
const s = re(t.p, r.Fp, n),
|
|
848
|
+
const s = re(t.p, r.Fp, n), o = re(t.n, r.Fn, n), c = ["Gx", "Gy", "a", "b"];
|
|
849
849
|
for (const f of c)
|
|
850
850
|
if (!s.isValid(t[f]))
|
|
851
851
|
throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);
|
|
852
|
-
return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: s, Fn:
|
|
852
|
+
return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: s, Fn: o };
|
|
853
853
|
}
|
|
854
854
|
function En(e, t) {
|
|
855
855
|
return function(n) {
|
|
@@ -870,11 +870,11 @@ class Ue {
|
|
|
870
870
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
871
871
|
const n = this.blockLen, s = new Uint8Array(n);
|
|
872
872
|
s.set(r.length > n ? t.create().update(r).digest() : r);
|
|
873
|
-
for (let
|
|
874
|
-
s[
|
|
873
|
+
for (let o = 0; o < s.length; o++)
|
|
874
|
+
s[o] ^= 54;
|
|
875
875
|
this.iHash.update(s), this.oHash = t.create();
|
|
876
|
-
for (let
|
|
877
|
-
s[
|
|
876
|
+
for (let o = 0; o < s.length; o++)
|
|
877
|
+
s[o] ^= 106;
|
|
878
878
|
this.oHash.update(s), vt(s);
|
|
879
879
|
}
|
|
880
880
|
update(t) {
|
|
@@ -889,8 +889,8 @@ class Ue {
|
|
|
889
889
|
}
|
|
890
890
|
_cloneInto(t) {
|
|
891
891
|
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
892
|
-
const { oHash: r, iHash: n, finished: s, destroyed:
|
|
893
|
-
return t = t, t.finished = s, t.destroyed =
|
|
892
|
+
const { oHash: r, iHash: n, finished: s, destroyed: o, blockLen: i, outputLen: c } = this;
|
|
893
|
+
return t = t, t.finished = s, t.destroyed = o, t.blockLen = i, t.outputLen = c, t.oHash = r._cloneInto(t.oHash), t.iHash = n._cloneInto(t.iHash), t;
|
|
894
894
|
}
|
|
895
895
|
clone() {
|
|
896
896
|
return this._cloneInto();
|
|
@@ -904,14 +904,14 @@ Se.create = (e, t) => new Ue(e, t);
|
|
|
904
904
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
905
905
|
const se = (e, t) => (e + (e >= 0 ? t : -t) / _e) / t;
|
|
906
906
|
function Bn(e, t, r) {
|
|
907
|
-
const [[n, s], [
|
|
908
|
-
let a = e - c * n - f *
|
|
909
|
-
const d = a < tt,
|
|
910
|
-
d && (a = -a),
|
|
907
|
+
const [[n, s], [o, i]] = t, c = se(i * e, r), f = se(-s * e, r);
|
|
908
|
+
let a = e - c * n - f * o, h = -c * s - f * i;
|
|
909
|
+
const d = a < tt, x = h < tt;
|
|
910
|
+
d && (a = -a), x && (h = -h);
|
|
911
911
|
const g = Yt(Math.ceil(sn(r) / 2)) + lt;
|
|
912
912
|
if (a < tt || a >= g || h < tt || h >= g)
|
|
913
913
|
throw new Error("splitScalar (endomorphism): failed, k=" + e);
|
|
914
|
-
return { k1neg: d, k1: a, k2neg:
|
|
914
|
+
return { k1neg: d, k1: a, k2neg: x, k2: h };
|
|
915
915
|
}
|
|
916
916
|
function Zt(e) {
|
|
917
917
|
if (!["compact", "recovered", "der"].includes(e))
|
|
@@ -943,8 +943,8 @@ const ot = {
|
|
|
943
943
|
const n = t.length / 2, s = pt(n);
|
|
944
944
|
if (s.length / 2 & 128)
|
|
945
945
|
throw new r("tlv.encode: long form length too big");
|
|
946
|
-
const
|
|
947
|
-
return pt(e) +
|
|
946
|
+
const o = n > 127 ? pt(s.length / 2 | 128) : "";
|
|
947
|
+
return pt(e) + o + s + t;
|
|
948
948
|
},
|
|
949
949
|
// v - value, l - left bytes (unparsed)
|
|
950
950
|
decode(e, t) {
|
|
@@ -954,10 +954,10 @@ const ot = {
|
|
|
954
954
|
throw new r("tlv.encode: wrong tag");
|
|
955
955
|
if (t.length < 2 || t[n++] !== e)
|
|
956
956
|
throw new r("tlv.decode: wrong tlv");
|
|
957
|
-
const s = t[n++],
|
|
958
|
-
let
|
|
959
|
-
if (!
|
|
960
|
-
|
|
957
|
+
const s = t[n++], o = !!(s & 128);
|
|
958
|
+
let i = 0;
|
|
959
|
+
if (!o)
|
|
960
|
+
i = s;
|
|
961
961
|
else {
|
|
962
962
|
const f = s & 127;
|
|
963
963
|
if (!f)
|
|
@@ -970,14 +970,14 @@ const ot = {
|
|
|
970
970
|
if (a[0] === 0)
|
|
971
971
|
throw new r("tlv.decode(long): zero leftmost byte");
|
|
972
972
|
for (const h of a)
|
|
973
|
-
|
|
974
|
-
if (n += f,
|
|
973
|
+
i = i << 8 | h;
|
|
974
|
+
if (n += f, i < 128)
|
|
975
975
|
throw new r("tlv.decode(long): not minimal encoding");
|
|
976
976
|
}
|
|
977
|
-
const c = t.subarray(n, n +
|
|
978
|
-
if (c.length !==
|
|
977
|
+
const c = t.subarray(n, n + i);
|
|
978
|
+
if (c.length !== i)
|
|
979
979
|
throw new r("tlv.decode: wrong value length");
|
|
980
|
-
return { v: c, l: t.subarray(n +
|
|
980
|
+
return { v: c, l: t.subarray(n + i) };
|
|
981
981
|
}
|
|
982
982
|
},
|
|
983
983
|
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
@@ -1004,23 +1004,23 @@ const ot = {
|
|
|
1004
1004
|
}
|
|
1005
1005
|
},
|
|
1006
1006
|
toSig(e) {
|
|
1007
|
-
const { Err: t, _int: r, _tlv: n } = ot, s = N(e, void 0, "signature"), { v:
|
|
1008
|
-
if (
|
|
1007
|
+
const { Err: t, _int: r, _tlv: n } = ot, s = N(e, void 0, "signature"), { v: o, l: i } = n.decode(48, s);
|
|
1008
|
+
if (i.length)
|
|
1009
1009
|
throw new t("invalid signature: left bytes after parsing");
|
|
1010
|
-
const { v: c, l: f } = n.decode(2,
|
|
1010
|
+
const { v: c, l: f } = n.decode(2, o), { v: a, l: h } = n.decode(2, f);
|
|
1011
1011
|
if (h.length)
|
|
1012
1012
|
throw new t("invalid signature: left bytes after parsing");
|
|
1013
1013
|
return { r: r.decode(c), s: r.decode(a) };
|
|
1014
1014
|
},
|
|
1015
1015
|
hexFromSig(e) {
|
|
1016
|
-
const { _tlv: t, _int: r } = ot, n = t.encode(2, r.encode(e.r)), s = t.encode(2, r.encode(e.s)),
|
|
1017
|
-
return t.encode(48,
|
|
1016
|
+
const { _tlv: t, _int: r } = ot, n = t.encode(2, r.encode(e.r)), s = t.encode(2, r.encode(e.s)), o = n + s;
|
|
1017
|
+
return t.encode(48, o);
|
|
1018
1018
|
}
|
|
1019
1019
|
}, tt = BigInt(0), lt = BigInt(1), _e = BigInt(2), yt = BigInt(3), Rn = BigInt(4);
|
|
1020
1020
|
function An(e, t = {}) {
|
|
1021
1021
|
const r = mn("weierstrass", e, t), { Fp: n, Fn: s } = r;
|
|
1022
|
-
let
|
|
1023
|
-
const { h:
|
|
1022
|
+
let o = r.CURVE;
|
|
1023
|
+
const { h: i, n: c } = o;
|
|
1024
1024
|
jt(t, {}, {
|
|
1025
1025
|
allowInfinityPoint: "boolean",
|
|
1026
1026
|
clearCofactor: "function",
|
|
@@ -1030,7 +1030,7 @@ function An(e, t = {}) {
|
|
|
1030
1030
|
endo: "object"
|
|
1031
1031
|
});
|
|
1032
1032
|
const { endo: f } = t;
|
|
1033
|
-
if (f && (!n.is0(
|
|
1033
|
+
if (f && (!n.is0(o.a) || typeof f.beta != "bigint" || !Array.isArray(f.basises)))
|
|
1034
1034
|
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
1035
1035
|
const a = He(n, s);
|
|
1036
1036
|
function h() {
|
|
@@ -1046,7 +1046,7 @@ function An(e, t = {}) {
|
|
|
1046
1046
|
} else
|
|
1047
1047
|
return it(Uint8Array.of(4), B, n.toBytes(p));
|
|
1048
1048
|
}
|
|
1049
|
-
function
|
|
1049
|
+
function x(S) {
|
|
1050
1050
|
N(S, void 0, "Point");
|
|
1051
1051
|
const { publicKey: l, publicKeyUncompressed: u } = a, w = S.length, p = S[0], B = S.subarray(1);
|
|
1052
1052
|
if (w === l && (p === 2 || p === 3)) {
|
|
@@ -1072,18 +1072,18 @@ function An(e, t = {}) {
|
|
|
1072
1072
|
} else
|
|
1073
1073
|
throw new Error(`bad point: got length ${w}, expected compressed=${l} or uncompressed=${u}`);
|
|
1074
1074
|
}
|
|
1075
|
-
const g = t.toBytes || d,
|
|
1075
|
+
const g = t.toBytes || d, y = t.fromBytes || x;
|
|
1076
1076
|
function U(S) {
|
|
1077
1077
|
const l = n.sqr(S), u = n.mul(l, S);
|
|
1078
|
-
return n.add(n.add(u, n.mul(S,
|
|
1078
|
+
return n.add(n.add(u, n.mul(S, o.a)), o.b);
|
|
1079
1079
|
}
|
|
1080
1080
|
function I(S, l) {
|
|
1081
1081
|
const u = n.sqr(l), w = U(S);
|
|
1082
1082
|
return n.eql(u, w);
|
|
1083
1083
|
}
|
|
1084
|
-
if (!I(
|
|
1084
|
+
if (!I(o.Gx, o.Gy))
|
|
1085
1085
|
throw new Error("bad curve params: generator point");
|
|
1086
|
-
const O = n.mul(n.pow(
|
|
1086
|
+
const O = n.mul(n.pow(o.a, yt), Rn), j = n.mul(n.sqr(o.b), BigInt(27));
|
|
1087
1087
|
if (n.is0(n.add(O, j)))
|
|
1088
1088
|
throw new Error("bad curve params: a or b");
|
|
1089
1089
|
function W(S, l, u = !1) {
|
|
@@ -1139,7 +1139,7 @@ function An(e, t = {}) {
|
|
|
1139
1139
|
this.X = W("x", l), this.Y = W("y", u, !0), this.Z = W("z", w), Object.freeze(this);
|
|
1140
1140
|
}
|
|
1141
1141
|
static CURVE() {
|
|
1142
|
-
return
|
|
1142
|
+
return o;
|
|
1143
1143
|
}
|
|
1144
1144
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1145
1145
|
static fromAffine(l) {
|
|
@@ -1151,7 +1151,7 @@ function An(e, t = {}) {
|
|
|
1151
1151
|
return n.is0(u) && n.is0(w) ? _.ZERO : new _(u, w, n.ONE);
|
|
1152
1152
|
}
|
|
1153
1153
|
static fromBytes(l) {
|
|
1154
|
-
const u = _.fromAffine(
|
|
1154
|
+
const u = _.fromAffine(y(N(l, void 0, "point")));
|
|
1155
1155
|
return u.assertValidity(), u;
|
|
1156
1156
|
}
|
|
1157
1157
|
static fromHex(l) {
|
|
@@ -1198,7 +1198,7 @@ function An(e, t = {}) {
|
|
|
1198
1198
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1199
1199
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1200
1200
|
double() {
|
|
1201
|
-
const { a: l, b: u } =
|
|
1201
|
+
const { a: l, b: u } = o, w = n.mul(u, yt), { X: p, Y: B, Z: E } = this;
|
|
1202
1202
|
let v = n.ZERO, b = n.ZERO, R = n.ZERO, L = n.mul(p, p), D = n.mul(B, B), H = n.mul(E, E), A = n.mul(p, B);
|
|
1203
1203
|
return A = n.add(A, A), R = n.mul(p, E), R = n.add(R, R), v = n.mul(l, R), b = n.mul(w, H), b = n.add(v, b), v = n.sub(D, b), b = n.add(D, b), b = n.mul(v, b), v = n.mul(A, v), R = n.mul(w, R), H = n.mul(l, H), A = n.sub(L, H), A = n.mul(l, A), A = n.add(A, R), R = n.add(L, L), L = n.add(R, L), L = n.add(L, H), L = n.mul(L, A), b = n.add(b, L), H = n.mul(B, E), H = n.add(H, H), L = n.mul(H, A), v = n.sub(v, L), R = n.mul(H, D), R = n.add(R, R), R = n.add(R, R), new _(v, b, R);
|
|
1204
1204
|
}
|
|
@@ -1210,11 +1210,11 @@ function An(e, t = {}) {
|
|
|
1210
1210
|
Z(l);
|
|
1211
1211
|
const { X: u, Y: w, Z: p } = this, { X: B, Y: E, Z: v } = l;
|
|
1212
1212
|
let b = n.ZERO, R = n.ZERO, L = n.ZERO;
|
|
1213
|
-
const D =
|
|
1214
|
-
let A = n.mul(u, B), $ = n.mul(w, E),
|
|
1213
|
+
const D = o.a, H = n.mul(o.b, yt);
|
|
1214
|
+
let A = n.mul(u, B), $ = n.mul(w, E), T = n.mul(p, v), K = n.add(u, w), q = n.add(B, E);
|
|
1215
1215
|
K = n.mul(K, q), q = n.add(A, $), K = n.sub(K, q), q = n.add(u, p);
|
|
1216
|
-
let
|
|
1217
|
-
return q = n.mul(q,
|
|
1216
|
+
let V = n.add(B, v);
|
|
1217
|
+
return q = n.mul(q, V), V = n.add(A, T), q = n.sub(q, V), V = n.add(w, p), b = n.add(E, v), V = n.mul(V, b), b = n.add($, T), V = n.sub(V, b), L = n.mul(D, q), b = n.mul(H, T), L = n.add(b, L), b = n.sub($, L), L = n.add($, L), R = n.mul(b, L), $ = n.add(A, A), $ = n.add($, A), T = n.mul(D, T), q = n.mul(H, q), $ = n.add($, T), T = n.sub(A, T), T = n.mul(D, T), q = n.add(q, T), A = n.mul($, q), R = n.add(R, A), A = n.mul(V, q), b = n.mul(K, b), b = n.sub(b, A), A = n.mul(K, $), L = n.mul(V, L), L = n.add(L, A), new _(b, R, L);
|
|
1218
1218
|
}
|
|
1219
1219
|
subtract(l) {
|
|
1220
1220
|
return this.add(l.negate());
|
|
@@ -1280,14 +1280,14 @@ function An(e, t = {}) {
|
|
|
1280
1280
|
*/
|
|
1281
1281
|
isTorsionFree() {
|
|
1282
1282
|
const { isTorsionFree: l } = t;
|
|
1283
|
-
return
|
|
1283
|
+
return i === lt ? !0 : l ? l(_, this) : ct.unsafe(this, c).is0();
|
|
1284
1284
|
}
|
|
1285
1285
|
clearCofactor() {
|
|
1286
1286
|
const { clearCofactor: l } = t;
|
|
1287
|
-
return
|
|
1287
|
+
return i === lt ? this : l ? l(_, this) : this.multiplyUnsafe(i);
|
|
1288
1288
|
}
|
|
1289
1289
|
isSmallOrder() {
|
|
1290
|
-
return this.multiplyUnsafe(
|
|
1290
|
+
return this.multiplyUnsafe(i).is0();
|
|
1291
1291
|
}
|
|
1292
1292
|
toBytes(l = !0) {
|
|
1293
1293
|
return At(l, "isCompressed"), this.assertValidity(), g(_, this, l);
|
|
@@ -1300,7 +1300,7 @@ function An(e, t = {}) {
|
|
|
1300
1300
|
}
|
|
1301
1301
|
};
|
|
1302
1302
|
// base / generator point
|
|
1303
|
-
m(_, "BASE", new _(
|
|
1303
|
+
m(_, "BASE", new _(o.Gx, o.Gy, n.ONE)), // zero / infinity / identity point
|
|
1304
1304
|
m(_, "ZERO", new _(n.ZERO, n.ONE, n.ZERO)), // 0, 1, 0
|
|
1305
1305
|
// math field
|
|
1306
1306
|
m(_, "Fp", n), // scalar field
|
|
@@ -1323,19 +1323,19 @@ function He(e, t) {
|
|
|
1323
1323
|
}
|
|
1324
1324
|
function In(e, t = {}) {
|
|
1325
1325
|
const { Fn: r } = e, n = t.randomBytes || le, s = Object.assign(He(e.Fp, r), { seed: Ae(r.ORDER) });
|
|
1326
|
-
function
|
|
1326
|
+
function o(g) {
|
|
1327
1327
|
try {
|
|
1328
|
-
const
|
|
1329
|
-
return r.isValidNot0(
|
|
1328
|
+
const y = r.fromBytes(g);
|
|
1329
|
+
return r.isValidNot0(y);
|
|
1330
1330
|
} catch {
|
|
1331
1331
|
return !1;
|
|
1332
1332
|
}
|
|
1333
1333
|
}
|
|
1334
|
-
function
|
|
1334
|
+
function i(g, y) {
|
|
1335
1335
|
const { publicKey: U, publicKeyUncompressed: I } = s;
|
|
1336
1336
|
try {
|
|
1337
1337
|
const O = g.length;
|
|
1338
|
-
return
|
|
1338
|
+
return y === !0 && O !== U || y === !1 && O !== I ? !1 : !!e.fromBytes(g);
|
|
1339
1339
|
} catch {
|
|
1340
1340
|
return !1;
|
|
1341
1341
|
}
|
|
@@ -1343,30 +1343,30 @@ function In(e, t = {}) {
|
|
|
1343
1343
|
function c(g = n(s.seed)) {
|
|
1344
1344
|
return pn(N(g, s.seed, "seed"), r.ORDER);
|
|
1345
1345
|
}
|
|
1346
|
-
function f(g,
|
|
1347
|
-
return e.BASE.multiply(r.fromBytes(g)).toBytes(
|
|
1346
|
+
function f(g, y = !0) {
|
|
1347
|
+
return e.BASE.multiply(r.fromBytes(g)).toBytes(y);
|
|
1348
1348
|
}
|
|
1349
1349
|
function a(g) {
|
|
1350
|
-
const { secretKey:
|
|
1351
|
-
if (!
|
|
1350
|
+
const { secretKey: y, publicKey: U, publicKeyUncompressed: I } = s;
|
|
1351
|
+
if (!Tt(g) || "_lengths" in r && r._lengths || y === U)
|
|
1352
1352
|
return;
|
|
1353
1353
|
const O = N(g, void 0, "key").length;
|
|
1354
1354
|
return O === U || O === I;
|
|
1355
1355
|
}
|
|
1356
|
-
function h(g,
|
|
1356
|
+
function h(g, y, U = !0) {
|
|
1357
1357
|
if (a(g) === !0)
|
|
1358
1358
|
throw new Error("first arg must be private key");
|
|
1359
|
-
if (a(
|
|
1359
|
+
if (a(y) === !1)
|
|
1360
1360
|
throw new Error("second arg must be public key");
|
|
1361
1361
|
const I = r.fromBytes(g);
|
|
1362
|
-
return e.fromBytes(
|
|
1362
|
+
return e.fromBytes(y).multiply(I).toBytes(U);
|
|
1363
1363
|
}
|
|
1364
1364
|
const d = {
|
|
1365
|
-
isValidSecretKey:
|
|
1366
|
-
isValidPublicKey:
|
|
1365
|
+
isValidSecretKey: o,
|
|
1366
|
+
isValidPublicKey: i,
|
|
1367
1367
|
randomSecretKey: c
|
|
1368
|
-
},
|
|
1369
|
-
return Object.freeze({ getPublicKey: f, getSharedSecret: h, keygen:
|
|
1368
|
+
}, x = En(c, f);
|
|
1369
|
+
return Object.freeze({ getPublicKey: f, getSharedSecret: h, keygen: x, Point: e, utils: d, lengths: s });
|
|
1370
1370
|
}
|
|
1371
1371
|
function Ln(e, t, r = {}) {
|
|
1372
1372
|
ae(t), jt(r, {}, {
|
|
@@ -1376,18 +1376,18 @@ function Ln(e, t, r = {}) {
|
|
|
1376
1376
|
bits2int: "function",
|
|
1377
1377
|
bits2int_modN: "function"
|
|
1378
1378
|
}), r = Object.assign({}, r);
|
|
1379
|
-
const n = r.randomBytes || le, s = r.hmac || ((l, u) => Se(t, l, u)), { Fp:
|
|
1379
|
+
const n = r.randomBytes || le, s = r.hmac || ((l, u) => Se(t, l, u)), { Fp: o, Fn: i } = e, { ORDER: c, BITS: f } = i, { keygen: a, getPublicKey: h, getSharedSecret: d, utils: x, lengths: g } = In(e, r), y = {
|
|
1380
1380
|
prehash: !0,
|
|
1381
1381
|
lowS: typeof r.lowS == "boolean" ? r.lowS : !0,
|
|
1382
1382
|
format: "compact",
|
|
1383
1383
|
extraEntropy: !1
|
|
1384
|
-
}, U = c * _e <
|
|
1384
|
+
}, U = c * _e < o.ORDER;
|
|
1385
1385
|
function I(l) {
|
|
1386
1386
|
const u = c >> lt;
|
|
1387
1387
|
return l > u;
|
|
1388
1388
|
}
|
|
1389
1389
|
function O(l, u) {
|
|
1390
|
-
if (!
|
|
1390
|
+
if (!i.isValidNot0(u))
|
|
1391
1391
|
throw new Error(`invalid signature ${l}: out of range 1..Point.Fn.ORDER`);
|
|
1392
1392
|
return u;
|
|
1393
1393
|
}
|
|
@@ -1412,7 +1412,7 @@ function Ln(e, t, r = {}) {
|
|
|
1412
1412
|
}
|
|
1413
1413
|
Object.freeze(this);
|
|
1414
1414
|
}
|
|
1415
|
-
static fromBytes(u, w =
|
|
1415
|
+
static fromBytes(u, w = y.format) {
|
|
1416
1416
|
W(u, w);
|
|
1417
1417
|
let p;
|
|
1418
1418
|
if (w === "der") {
|
|
@@ -1421,7 +1421,7 @@ function Ln(e, t, r = {}) {
|
|
|
1421
1421
|
}
|
|
1422
1422
|
w === "recovered" && (p = u[0], w = "compact", u = u.subarray(1));
|
|
1423
1423
|
const B = g.signature / 2, E = u.subarray(0, B), v = u.subarray(B, B * 2);
|
|
1424
|
-
return new Z(
|
|
1424
|
+
return new Z(i.fromBytes(E), i.fromBytes(v), p);
|
|
1425
1425
|
}
|
|
1426
1426
|
static fromHex(u, w) {
|
|
1427
1427
|
return this.fromBytes(Rt(u), w);
|
|
@@ -1437,9 +1437,9 @@ function Ln(e, t, r = {}) {
|
|
|
1437
1437
|
}
|
|
1438
1438
|
recoverPublicKey(u) {
|
|
1439
1439
|
const { r: w, s: p } = this, B = this.assertRecovery(), E = B === 2 || B === 3 ? w + c : w;
|
|
1440
|
-
if (!
|
|
1440
|
+
if (!o.isValid(E))
|
|
1441
1441
|
throw new Error("invalid recovery id: sig.r+curve.n != R.x");
|
|
1442
|
-
const v =
|
|
1442
|
+
const v = o.toBytes(E), b = e.fromBytes(it(Oe((B & 1) === 0), v)), R = i.inv(E), L = G(N(u, void 0, "msgHash")), D = i.create(-L * R), H = i.create(p * R), A = e.BASE.multiplyUnsafe(D).add(b.multiplyUnsafe(H));
|
|
1443
1443
|
if (A.is0())
|
|
1444
1444
|
throw new Error("invalid recovery: point at infinify");
|
|
1445
1445
|
return A.assertValidity(), A;
|
|
@@ -1448,10 +1448,10 @@ function Ln(e, t, r = {}) {
|
|
|
1448
1448
|
hasHighS() {
|
|
1449
1449
|
return I(this.s);
|
|
1450
1450
|
}
|
|
1451
|
-
toBytes(u =
|
|
1451
|
+
toBytes(u = y.format) {
|
|
1452
1452
|
if (Zt(u), u === "der")
|
|
1453
1453
|
return Rt(ot.hexFromSig(this));
|
|
1454
|
-
const { r: w, s: p } = this, B =
|
|
1454
|
+
const { r: w, s: p } = this, B = i.toBytes(w), E = i.toBytes(p);
|
|
1455
1455
|
return u === "recovered" ? (j(), it(Uint8Array.of(this.assertRecovery()), B, E)) : it(B, E);
|
|
1456
1456
|
}
|
|
1457
1457
|
toHex(u) {
|
|
@@ -1464,19 +1464,19 @@ function Ln(e, t, r = {}) {
|
|
|
1464
1464
|
const w = Ut(u), p = u.length * 8 - f;
|
|
1465
1465
|
return p > 0 ? w >> BigInt(p) : w;
|
|
1466
1466
|
}, G = r.bits2int_modN || function(u) {
|
|
1467
|
-
return
|
|
1467
|
+
return i.create(k(u));
|
|
1468
1468
|
}, _t = Yt(f);
|
|
1469
1469
|
function ht(l) {
|
|
1470
|
-
return rn("num < 2^" + f, l, tt, _t),
|
|
1470
|
+
return rn("num < 2^" + f, l, tt, _t), i.toBytes(l);
|
|
1471
1471
|
}
|
|
1472
1472
|
function z(l, u) {
|
|
1473
1473
|
return N(l, void 0, "message"), u ? N(t(l), void 0, "prehashed message") : l;
|
|
1474
1474
|
}
|
|
1475
1475
|
function bt(l, u, w) {
|
|
1476
|
-
const { lowS: p, prehash: B, extraEntropy: E } = Dt(w,
|
|
1476
|
+
const { lowS: p, prehash: B, extraEntropy: E } = Dt(w, y);
|
|
1477
1477
|
l = z(l, B);
|
|
1478
|
-
const v = G(l), b =
|
|
1479
|
-
if (!
|
|
1478
|
+
const v = G(l), b = i.fromBytes(u);
|
|
1479
|
+
if (!i.isValidNot0(b))
|
|
1480
1480
|
throw new Error("invalid private key");
|
|
1481
1481
|
const R = [ht(b), ht(v)];
|
|
1482
1482
|
if (E != null && E !== !1) {
|
|
@@ -1486,26 +1486,26 @@ function Ln(e, t, r = {}) {
|
|
|
1486
1486
|
const L = it(...R), D = v;
|
|
1487
1487
|
function H(A) {
|
|
1488
1488
|
const $ = k(A);
|
|
1489
|
-
if (!
|
|
1489
|
+
if (!i.isValidNot0($))
|
|
1490
1490
|
return;
|
|
1491
|
-
const
|
|
1491
|
+
const T = i.inv($), K = e.BASE.multiply($).toAffine(), q = i.create(K.x);
|
|
1492
1492
|
if (q === tt)
|
|
1493
1493
|
return;
|
|
1494
|
-
const
|
|
1495
|
-
if (
|
|
1494
|
+
const V = i.create(T * i.create(D + q * b));
|
|
1495
|
+
if (V === tt)
|
|
1496
1496
|
return;
|
|
1497
|
-
let zt = (K.x === q ? 0 : 2) | Number(K.y & lt), Ft =
|
|
1498
|
-
return p && I(
|
|
1497
|
+
let zt = (K.x === q ? 0 : 2) | Number(K.y & lt), Ft = V;
|
|
1498
|
+
return p && I(V) && (Ft = i.neg(V), zt ^= 1), new Z(q, Ft, U ? void 0 : zt);
|
|
1499
1499
|
}
|
|
1500
1500
|
return { seed: L, k2sig: H };
|
|
1501
1501
|
}
|
|
1502
1502
|
function ct(l, u, w = {}) {
|
|
1503
1503
|
const { seed: p, k2sig: B } = bt(l, u, w);
|
|
1504
|
-
return on(t.outputLen,
|
|
1504
|
+
return on(t.outputLen, i.BYTES, s)(p, B).toBytes(w.format);
|
|
1505
1505
|
}
|
|
1506
1506
|
function _(l, u, w, p = {}) {
|
|
1507
|
-
const { lowS: B, prehash: E, format: v } = Dt(p,
|
|
1508
|
-
if (w = N(w, void 0, "publicKey"), u = z(u, E), !
|
|
1507
|
+
const { lowS: B, prehash: E, format: v } = Dt(p, y);
|
|
1508
|
+
if (w = N(w, void 0, "publicKey"), u = z(u, E), !Tt(l)) {
|
|
1509
1509
|
const b = l instanceof Z ? ", use sig.toBytes()" : "";
|
|
1510
1510
|
throw new Error("verify expects Uint8Array signature" + b);
|
|
1511
1511
|
}
|
|
@@ -1514,21 +1514,21 @@ function Ln(e, t, r = {}) {
|
|
|
1514
1514
|
const b = Z.fromBytes(l, v), R = e.fromBytes(w);
|
|
1515
1515
|
if (B && b.hasHighS())
|
|
1516
1516
|
return !1;
|
|
1517
|
-
const { r: L, s: D } = b, H = G(u), A =
|
|
1518
|
-
return K.is0() ? !1 :
|
|
1517
|
+
const { r: L, s: D } = b, H = G(u), A = i.inv(D), $ = i.create(H * A), T = i.create(L * A), K = e.BASE.multiplyUnsafe($).add(R.multiplyUnsafe(T));
|
|
1518
|
+
return K.is0() ? !1 : i.create(K.x) === L;
|
|
1519
1519
|
} catch {
|
|
1520
1520
|
return !1;
|
|
1521
1521
|
}
|
|
1522
1522
|
}
|
|
1523
1523
|
function S(l, u, w = {}) {
|
|
1524
|
-
const { prehash: p } = Dt(w,
|
|
1524
|
+
const { prehash: p } = Dt(w, y);
|
|
1525
1525
|
return u = z(u, p), Z.fromBytes(l, "recovered").recoverPublicKey(u).toBytes();
|
|
1526
1526
|
}
|
|
1527
1527
|
return Object.freeze({
|
|
1528
1528
|
keygen: a,
|
|
1529
1529
|
getPublicKey: h,
|
|
1530
1530
|
getSharedSecret: d,
|
|
1531
|
-
utils:
|
|
1531
|
+
utils: x,
|
|
1532
1532
|
lengths: g,
|
|
1533
1533
|
Point: e,
|
|
1534
1534
|
sign: ct,
|
|
@@ -1555,7 +1555,7 @@ const Gt = {
|
|
|
1555
1555
|
]
|
|
1556
1556
|
}, oe = /* @__PURE__ */ BigInt(2);
|
|
1557
1557
|
function Sn(e) {
|
|
1558
|
-
const t = Gt.p, r = BigInt(3), n = BigInt(6), s = BigInt(11),
|
|
1558
|
+
const t = Gt.p, r = BigInt(3), n = BigInt(6), s = BigInt(11), o = BigInt(22), i = BigInt(23), c = BigInt(44), f = BigInt(88), a = e * e * e % t, h = a * a * e % t, d = X(h, r, t) * h % t, x = X(d, r, t) * h % t, g = X(x, oe, t) * a % t, y = X(g, s, t) * g % t, U = X(y, o, t) * y % t, I = X(U, c, t) * U % t, O = X(I, f, t) * I % t, j = X(O, c, t) * U % t, W = X(j, r, t) * h % t, Z = X(W, i, t) * y % t, k = X(Z, n, t) * a % t, G = X(k, oe, t);
|
|
1559
1559
|
if (!Ct.eql(Ct.sqr(G), e))
|
|
1560
1560
|
throw new Error("Cannot find square root");
|
|
1561
1561
|
return G;
|
|
@@ -1616,8 +1616,8 @@ function Ne(e) {
|
|
|
1616
1616
|
function kn(e, t, r, n) {
|
|
1617
1617
|
if (typeof e.setBigUint64 == "function")
|
|
1618
1618
|
return e.setBigUint64(t, r, n);
|
|
1619
|
-
const s = BigInt(32),
|
|
1620
|
-
e.setUint32(t + f,
|
|
1619
|
+
const s = BigInt(32), o = BigInt(4294967295), i = Number(r >> s & o), c = Number(r & o), f = n ? 4 : 0, a = n ? 0 : 4;
|
|
1620
|
+
e.setUint32(t + f, i, n), e.setUint32(t + a, c, n);
|
|
1621
1621
|
}
|
|
1622
1622
|
function $n(e, t, r) {
|
|
1623
1623
|
return e & t ^ ~e & r;
|
|
@@ -1631,27 +1631,27 @@ class De extends Dn {
|
|
|
1631
1631
|
}
|
|
1632
1632
|
update(t) {
|
|
1633
1633
|
ie(this), t = qe(t), Xt(t);
|
|
1634
|
-
const { view: r, buffer: n, blockLen: s } = this,
|
|
1635
|
-
for (let
|
|
1636
|
-
const c = Math.min(s - this.pos,
|
|
1634
|
+
const { view: r, buffer: n, blockLen: s } = this, o = t.length;
|
|
1635
|
+
for (let i = 0; i < o; ) {
|
|
1636
|
+
const c = Math.min(s - this.pos, o - i);
|
|
1637
1637
|
if (c === s) {
|
|
1638
1638
|
const f = kt(t);
|
|
1639
|
-
for (; s <=
|
|
1640
|
-
this.process(f,
|
|
1639
|
+
for (; s <= o - i; i += s)
|
|
1640
|
+
this.process(f, i);
|
|
1641
1641
|
continue;
|
|
1642
1642
|
}
|
|
1643
|
-
n.set(t.subarray(
|
|
1643
|
+
n.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === s && (this.process(r, 0), this.pos = 0);
|
|
1644
1644
|
}
|
|
1645
1645
|
return this.length += t.length, this.roundClean(), this;
|
|
1646
1646
|
}
|
|
1647
1647
|
digestInto(t) {
|
|
1648
1648
|
ie(this), qn(t, this), this.finished = !0;
|
|
1649
|
-
const { buffer: r, view: n, blockLen: s, isLE:
|
|
1650
|
-
let { pos:
|
|
1651
|
-
r[
|
|
1652
|
-
for (let d =
|
|
1649
|
+
const { buffer: r, view: n, blockLen: s, isLE: o } = this;
|
|
1650
|
+
let { pos: i } = this;
|
|
1651
|
+
r[i++] = 128, gt(this.buffer.subarray(i)), this.padOffset > s - i && (this.process(n, 0), i = 0);
|
|
1652
|
+
for (let d = i; d < s; d++)
|
|
1653
1653
|
r[d] = 0;
|
|
1654
|
-
kn(n, s - 8, BigInt(this.length * 8),
|
|
1654
|
+
kn(n, s - 8, BigInt(this.length * 8), o), this.process(n, 0);
|
|
1655
1655
|
const c = kt(t), f = this.outputLen;
|
|
1656
1656
|
if (f % 4)
|
|
1657
1657
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -1659,7 +1659,7 @@ class De extends Dn {
|
|
|
1659
1659
|
if (a > h.length)
|
|
1660
1660
|
throw new Error("_sha2: outputLen bigger than state");
|
|
1661
1661
|
for (let d = 0; d < a; d++)
|
|
1662
|
-
c.setUint32(4 * d, h[d],
|
|
1662
|
+
c.setUint32(4 * d, h[d], o);
|
|
1663
1663
|
}
|
|
1664
1664
|
digest() {
|
|
1665
1665
|
const { buffer: t, outputLen: r } = this;
|
|
@@ -1669,8 +1669,8 @@ class De extends Dn {
|
|
|
1669
1669
|
}
|
|
1670
1670
|
_cloneInto(t) {
|
|
1671
1671
|
t || (t = new this.constructor()), t.set(...this.get());
|
|
1672
|
-
const { blockLen: r, buffer: n, length: s, finished:
|
|
1673
|
-
return t.destroyed =
|
|
1672
|
+
const { blockLen: r, buffer: n, length: s, finished: o, destroyed: i, pos: c } = this;
|
|
1673
|
+
return t.destroyed = i, t.finished = o, t.length = s, t.pos = c, s % r && t.buffer.set(n), t;
|
|
1674
1674
|
}
|
|
1675
1675
|
clone() {
|
|
1676
1676
|
return this._cloneInto();
|
|
@@ -1702,19 +1702,19 @@ const rt = /* @__PURE__ */ Uint32Array.from([
|
|
|
1702
1702
|
14,
|
|
1703
1703
|
11,
|
|
1704
1704
|
8
|
|
1705
|
-
]), ke = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)),
|
|
1706
|
-
const r = [[ke], [
|
|
1705
|
+
]), ke = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Tn = ke.map((e) => (9 * e + 5) % 16), $e = /* @__PURE__ */ (() => {
|
|
1706
|
+
const r = [[ke], [Tn]];
|
|
1707
1707
|
for (let n = 0; n < 4; n++)
|
|
1708
1708
|
for (let s of r)
|
|
1709
|
-
s.push(s[n].map((
|
|
1709
|
+
s.push(s[n].map((o) => Cn[o]));
|
|
1710
1710
|
return r;
|
|
1711
|
-
})(), Ze = $e[0], Ce = $e[1],
|
|
1711
|
+
})(), Ze = $e[0], Ce = $e[1], Te = /* @__PURE__ */ [
|
|
1712
1712
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
1713
1713
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
1714
1714
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1715
1715
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1716
1716
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1717
|
-
].map((e) => Uint8Array.from(e)),
|
|
1717
|
+
].map((e) => Uint8Array.from(e)), Vn = /* @__PURE__ */ Ze.map((e, t) => e.map((r) => Te[t][r])), Mn = /* @__PURE__ */ Ce.map((e, t) => e.map((r) => Te[t][r])), Yn = /* @__PURE__ */ Uint32Array.from([
|
|
1718
1718
|
0,
|
|
1719
1719
|
1518500249,
|
|
1720
1720
|
1859775393,
|
|
@@ -1736,28 +1736,28 @@ class Kn extends De {
|
|
|
1736
1736
|
super(64, 20, 8, !0), this.h0 = 1732584193, this.h1 = -271733879, this.h2 = -1732584194, this.h3 = 271733878, this.h4 = -1009589776;
|
|
1737
1737
|
}
|
|
1738
1738
|
get() {
|
|
1739
|
-
const { h0: t, h1: r, h2: n, h3: s, h4:
|
|
1740
|
-
return [t, r, n, s,
|
|
1739
|
+
const { h0: t, h1: r, h2: n, h3: s, h4: o } = this;
|
|
1740
|
+
return [t, r, n, s, o];
|
|
1741
1741
|
}
|
|
1742
|
-
set(t, r, n, s,
|
|
1743
|
-
this.h0 = t | 0, this.h1 = r | 0, this.h2 = n | 0, this.h3 = s | 0, this.h4 =
|
|
1742
|
+
set(t, r, n, s, o) {
|
|
1743
|
+
this.h0 = t | 0, this.h1 = r | 0, this.h2 = n | 0, this.h3 = s | 0, this.h4 = o | 0;
|
|
1744
1744
|
}
|
|
1745
1745
|
process(t, r) {
|
|
1746
1746
|
for (let g = 0; g < 16; g++, r += 4)
|
|
1747
1747
|
mt[g] = t.getUint32(r, !0);
|
|
1748
|
-
let n = this.h0 | 0, s = n,
|
|
1748
|
+
let n = this.h0 | 0, s = n, o = this.h1 | 0, i = o, c = this.h2 | 0, f = c, a = this.h3 | 0, h = a, d = this.h4 | 0, x = d;
|
|
1749
1749
|
for (let g = 0; g < 5; g++) {
|
|
1750
|
-
const
|
|
1750
|
+
const y = 4 - g, U = Yn[g], I = jn[g], O = Ze[g], j = Ce[g], W = Vn[g], Z = Mn[g];
|
|
1751
1751
|
for (let k = 0; k < 16; k++) {
|
|
1752
|
-
const G = xt(n + ce(g,
|
|
1753
|
-
n = d, d = a, a = xt(c, 10) | 0, c =
|
|
1752
|
+
const G = xt(n + ce(g, o, c, a) + mt[O[k]] + U, W[k]) + d | 0;
|
|
1753
|
+
n = d, d = a, a = xt(c, 10) | 0, c = o, o = G;
|
|
1754
1754
|
}
|
|
1755
1755
|
for (let k = 0; k < 16; k++) {
|
|
1756
|
-
const G = xt(s + ce(
|
|
1757
|
-
s =
|
|
1756
|
+
const G = xt(s + ce(y, i, f, h) + mt[j[k]] + I, Z[k]) + x | 0;
|
|
1757
|
+
s = x, x = h, h = xt(f, 10) | 0, f = i, i = G;
|
|
1758
1758
|
}
|
|
1759
1759
|
}
|
|
1760
|
-
this.set(this.h1 + c + h | 0, this.h2 + a +
|
|
1760
|
+
this.set(this.h1 + c + h | 0, this.h2 + a + x | 0, this.h3 + d + s | 0, this.h4 + n + i | 0, this.h0 + o + f | 0);
|
|
1761
1761
|
}
|
|
1762
1762
|
roundClean() {
|
|
1763
1763
|
gt(mt);
|
|
@@ -1837,26 +1837,26 @@ class Fn extends De {
|
|
|
1837
1837
|
super(64, t, 8, !1), this.A = rt[0] | 0, this.B = rt[1] | 0, this.C = rt[2] | 0, this.D = rt[3] | 0, this.E = rt[4] | 0, this.F = rt[5] | 0, this.G = rt[6] | 0, this.H = rt[7] | 0;
|
|
1838
1838
|
}
|
|
1839
1839
|
get() {
|
|
1840
|
-
const { A: t, B: r, C: n, D: s, E:
|
|
1841
|
-
return [t, r, n, s,
|
|
1840
|
+
const { A: t, B: r, C: n, D: s, E: o, F: i, G: c, H: f } = this;
|
|
1841
|
+
return [t, r, n, s, o, i, c, f];
|
|
1842
1842
|
}
|
|
1843
1843
|
// prettier-ignore
|
|
1844
|
-
set(t, r, n, s,
|
|
1845
|
-
this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = s | 0, this.E =
|
|
1844
|
+
set(t, r, n, s, o, i, c, f) {
|
|
1845
|
+
this.A = t | 0, this.B = r | 0, this.C = n | 0, this.D = s | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
|
|
1846
1846
|
}
|
|
1847
1847
|
process(t, r) {
|
|
1848
1848
|
for (let d = 0; d < 16; d++, r += 4)
|
|
1849
1849
|
st[d] = t.getUint32(r, !1);
|
|
1850
1850
|
for (let d = 16; d < 64; d++) {
|
|
1851
|
-
const
|
|
1852
|
-
st[d] = U + st[d - 7] +
|
|
1851
|
+
const x = st[d - 15], g = st[d - 2], y = Q(x, 7) ^ Q(x, 18) ^ x >>> 3, U = Q(g, 17) ^ Q(g, 19) ^ g >>> 10;
|
|
1852
|
+
st[d] = U + st[d - 7] + y + st[d - 16] | 0;
|
|
1853
1853
|
}
|
|
1854
|
-
let { A: n, B: s, C:
|
|
1854
|
+
let { A: n, B: s, C: o, D: i, E: c, F: f, G: a, H: h } = this;
|
|
1855
1855
|
for (let d = 0; d < 64; d++) {
|
|
1856
|
-
const
|
|
1857
|
-
h = a, a = f, f = c, c =
|
|
1856
|
+
const x = Q(c, 6) ^ Q(c, 11) ^ Q(c, 25), g = h + x + $n(c, f, a) + zn[d] + st[d] | 0, U = (Q(n, 2) ^ Q(n, 13) ^ Q(n, 22)) + Zn(n, s, o) | 0;
|
|
1857
|
+
h = a, a = f, f = c, c = i + g | 0, i = o, o = s, s = n, n = g + U | 0;
|
|
1858
1858
|
}
|
|
1859
|
-
n = n + this.A | 0, s = s + this.B | 0,
|
|
1859
|
+
n = n + this.A | 0, s = s + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, a = a + this.G | 0, h = h + this.H | 0, this.set(n, s, o, i, c, f, a, h);
|
|
1860
1860
|
}
|
|
1861
1861
|
roundClean() {
|
|
1862
1862
|
gt(st);
|
|
@@ -1873,16 +1873,16 @@ function Qn(e) {
|
|
|
1873
1873
|
if (!n) continue;
|
|
1874
1874
|
const s = Pn.indexOf(n);
|
|
1875
1875
|
if (s === -1) throw new Error("Invalid base58 character");
|
|
1876
|
-
for (let
|
|
1877
|
-
t[
|
|
1876
|
+
for (let i = 0; i < t.length; i++)
|
|
1877
|
+
t[i] *= 58;
|
|
1878
1878
|
t[0] += s;
|
|
1879
|
-
let
|
|
1880
|
-
for (let
|
|
1881
|
-
const c = t[
|
|
1882
|
-
t[
|
|
1879
|
+
let o = 0;
|
|
1880
|
+
for (let i = 0; i < t.length; i++) {
|
|
1881
|
+
const c = t[i];
|
|
1882
|
+
t[i] = c + o, o = t[i] >> 8, t[i] &= 255;
|
|
1883
1883
|
}
|
|
1884
|
-
for (;
|
|
1885
|
-
t.push(
|
|
1884
|
+
for (; o > 0; )
|
|
1885
|
+
t.push(o & 255), o >>= 8;
|
|
1886
1886
|
}
|
|
1887
1887
|
for (let r = 0; r < e.length && e[r] === "1"; r++)
|
|
1888
1888
|
t.push(0);
|
|
@@ -1891,15 +1891,15 @@ function Qn(e) {
|
|
|
1891
1891
|
function Jn(e) {
|
|
1892
1892
|
const t = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", n = e.toLowerCase().split("1");
|
|
1893
1893
|
if (n.length !== 2) return null;
|
|
1894
|
-
const s = n[0],
|
|
1895
|
-
if (!s || !
|
|
1896
|
-
const
|
|
1897
|
-
for (const h of
|
|
1894
|
+
const s = n[0], o = n[1];
|
|
1895
|
+
if (!s || !o || s !== "dgb") return null;
|
|
1896
|
+
const i = [];
|
|
1897
|
+
for (const h of o) {
|
|
1898
1898
|
const d = t.indexOf(h);
|
|
1899
1899
|
if (d === -1) return null;
|
|
1900
|
-
|
|
1900
|
+
i.push(d);
|
|
1901
1901
|
}
|
|
1902
|
-
const c =
|
|
1902
|
+
const c = i.slice(0, -6);
|
|
1903
1903
|
if (c.length < 1) return null;
|
|
1904
1904
|
const f = c[0];
|
|
1905
1905
|
if (f === void 0) return null;
|
|
@@ -1907,33 +1907,33 @@ function Jn(e) {
|
|
|
1907
1907
|
return a ? { version: f, program: new Uint8Array(a) } : null;
|
|
1908
1908
|
}
|
|
1909
1909
|
function tr(e, t, r, n) {
|
|
1910
|
-
let s = 0,
|
|
1911
|
-
const
|
|
1910
|
+
let s = 0, o = 0;
|
|
1911
|
+
const i = [], c = (1 << r) - 1;
|
|
1912
1912
|
for (const f of e) {
|
|
1913
1913
|
if (f < 0 || f >> t !== 0) return null;
|
|
1914
|
-
for (s = s << t | f,
|
|
1915
|
-
|
|
1914
|
+
for (s = s << t | f, o += t; o >= r; )
|
|
1915
|
+
o -= r, i.push(s >> o & c);
|
|
1916
1916
|
}
|
|
1917
|
-
return
|
|
1917
|
+
return o >= t || s << r - o & c ? null : i;
|
|
1918
1918
|
}
|
|
1919
1919
|
function er(e, t) {
|
|
1920
|
-
const r = new TextEncoder().encode(t), n = new Uint8Array([r.length]), s = new TextEncoder().encode(e),
|
|
1921
|
-
let
|
|
1922
|
-
if (
|
|
1923
|
-
|
|
1924
|
-
else if (
|
|
1925
|
-
|
|
1926
|
-
else if (
|
|
1927
|
-
|
|
1920
|
+
const r = new TextEncoder().encode(t), n = new Uint8Array([r.length]), s = new TextEncoder().encode(e), o = [];
|
|
1921
|
+
let i = s.length;
|
|
1922
|
+
if (i < 253)
|
|
1923
|
+
o.push(i);
|
|
1924
|
+
else if (i <= 65535)
|
|
1925
|
+
o.push(253, i & 255, i >> 8 & 255);
|
|
1926
|
+
else if (i <= 4294967295)
|
|
1927
|
+
o.push(
|
|
1928
1928
|
254,
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1929
|
+
i & 255,
|
|
1930
|
+
i >> 8 & 255,
|
|
1931
|
+
i >> 16 & 255,
|
|
1932
|
+
i >> 24 & 255
|
|
1933
1933
|
);
|
|
1934
1934
|
else
|
|
1935
1935
|
throw new Error("Message too long");
|
|
1936
|
-
const c = new Uint8Array(
|
|
1936
|
+
const c = new Uint8Array(o), f = n.length + r.length + c.length + s.length, a = new Uint8Array(f);
|
|
1937
1937
|
let h = 0;
|
|
1938
1938
|
return a.set(n, h), h += n.length, a.set(r, h), h += r.length, a.set(c, h), h += c.length, a.set(s, h), wt(wt(a));
|
|
1939
1939
|
}
|
|
@@ -1942,22 +1942,18 @@ function nr(e, t) {
|
|
|
1942
1942
|
throw new Error("Invalid signature length");
|
|
1943
1943
|
const r = t[0];
|
|
1944
1944
|
if (r === void 0) throw new Error("Invalid signature");
|
|
1945
|
-
const n = r - 27, s = n >= 4;
|
|
1946
|
-
if (
|
|
1945
|
+
const n = r - 27, s = n >= 4, o = n % 4;
|
|
1946
|
+
if (o < 0 || o > 3)
|
|
1947
1947
|
throw new Error("Invalid recovery ID");
|
|
1948
|
-
const
|
|
1949
|
-
BigInt("0x" + Array.from(
|
|
1948
|
+
const i = t.slice(1, 33), c = t.slice(33, 65), f = new On.Signature(
|
|
1949
|
+
BigInt("0x" + Array.from(i).map((a) => a.toString(16).padStart(2, "0")).join("")),
|
|
1950
1950
|
BigInt("0x" + Array.from(c).map((a) => a.toString(16).padStart(2, "0")).join(""))
|
|
1951
|
-
);
|
|
1951
|
+
).addRecoveryBit(o);
|
|
1952
1952
|
try {
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
return d;
|
|
1958
|
-
});
|
|
1959
|
-
} catch {
|
|
1960
|
-
throw new Error("Failed to recover public key");
|
|
1953
|
+
const a = f.recoverPublicKey(e), h = a.toBytes(!0), d = a.toBytes(!1);
|
|
1954
|
+
return s ? [h] : [d, h];
|
|
1955
|
+
} catch (a) {
|
|
1956
|
+
throw new Error("Failed to recover public key: " + (a instanceof Error ? a.message : String(a)));
|
|
1961
1957
|
}
|
|
1962
1958
|
}
|
|
1963
1959
|
function fe(e) {
|
|
@@ -1968,8 +1964,8 @@ function rr(e, t) {
|
|
|
1968
1964
|
try {
|
|
1969
1965
|
const r = Qn(e);
|
|
1970
1966
|
if (r.length < 25) return !1;
|
|
1971
|
-
const n = r.slice(0, -4), s = r.slice(-4),
|
|
1972
|
-
if (!s.every((a, h) => a ===
|
|
1967
|
+
const n = r.slice(0, -4), s = r.slice(-4), i = wt(wt(n)).slice(0, 4);
|
|
1968
|
+
if (!s.every((a, h) => a === i[h]))
|
|
1973
1969
|
return !1;
|
|
1974
1970
|
const c = n.slice(1), f = fe(t);
|
|
1975
1971
|
return c.every((a, h) => a === f[h]);
|
|
@@ -1982,8 +1978,13 @@ function rr(e, t) {
|
|
|
1982
1978
|
if (!r) return !1;
|
|
1983
1979
|
const { version: n, program: s } = r;
|
|
1984
1980
|
if (n === 0) {
|
|
1985
|
-
|
|
1986
|
-
|
|
1981
|
+
let o = t;
|
|
1982
|
+
if (t.length === 65) {
|
|
1983
|
+
const c = t[64] % 2 === 0;
|
|
1984
|
+
o = new Uint8Array(33), o[0] = c ? 2 : 3, o.set(t.slice(1, 33), 1);
|
|
1985
|
+
}
|
|
1986
|
+
const i = fe(o);
|
|
1987
|
+
return s.every((c, f) => c === i[f]);
|
|
1987
1988
|
}
|
|
1988
1989
|
return !1;
|
|
1989
1990
|
} catch {
|
|
@@ -1998,14 +1999,14 @@ async function sr(e, t, r) {
|
|
|
1998
1999
|
const s = Uint8Array.from(atob(r), (c) => c.charCodeAt(0));
|
|
1999
2000
|
if (s.length !== 65)
|
|
2000
2001
|
throw new Error("Invalid signature length");
|
|
2001
|
-
const
|
|
2002
|
-
for (const c of
|
|
2002
|
+
const o = er(e, n), i = nr(o, s);
|
|
2003
|
+
for (const c of i)
|
|
2003
2004
|
if (rr(t, c))
|
|
2004
2005
|
return !0;
|
|
2005
2006
|
return !1;
|
|
2006
2007
|
} catch (s) {
|
|
2007
|
-
const
|
|
2008
|
-
throw new C(`Signature verification failed: ${
|
|
2008
|
+
const o = s instanceof Error ? s.message : String(s);
|
|
2009
|
+
throw new C(`Signature verification failed: ${o}`);
|
|
2009
2010
|
}
|
|
2010
2011
|
}
|
|
2011
2012
|
function or(e = 16) {
|
|
@@ -2017,8 +2018,8 @@ function ar(e) {
|
|
|
2017
2018
|
let t;
|
|
2018
2019
|
try {
|
|
2019
2020
|
t = new URL(e.callbackUrl);
|
|
2020
|
-
} catch (
|
|
2021
|
-
throw new C(`Invalid callback URL: ${
|
|
2021
|
+
} catch (i) {
|
|
2022
|
+
throw new C(`Invalid callback URL: ${i.message}`);
|
|
2022
2023
|
}
|
|
2023
2024
|
const r = t.host + t.pathname, n = e.nonce || or(), s = e.unsecure ? "1" : "0";
|
|
2024
2025
|
if (e.unsecure && t.protocol !== "http:")
|
|
@@ -2028,40 +2029,40 @@ function ar(e) {
|
|
|
2028
2029
|
return `digiid://${r}?x=${n}&u=${s}`;
|
|
2029
2030
|
}
|
|
2030
2031
|
async function ur(e, t) {
|
|
2031
|
-
const { address: r, uri: n, signature: s } = e, { expectedCallbackUrl:
|
|
2032
|
+
const { address: r, uri: n, signature: s } = e, { expectedCallbackUrl: o, expectedNonce: i } = t;
|
|
2032
2033
|
if (!r || !n || !s)
|
|
2033
2034
|
throw new C("Missing required callback data: address, uri, or signature.");
|
|
2034
2035
|
let c;
|
|
2035
2036
|
try {
|
|
2036
|
-
const
|
|
2037
|
-
c = new URL(
|
|
2038
|
-
} catch (
|
|
2039
|
-
throw new C(`Invalid URI received in callback: ${
|
|
2037
|
+
const y = n.replace(/^digiid:/, "http:");
|
|
2038
|
+
c = new URL(y);
|
|
2039
|
+
} catch (y) {
|
|
2040
|
+
throw new C(`Invalid URI received in callback: ${y.message}`);
|
|
2040
2041
|
}
|
|
2041
2042
|
const f = c.searchParams.get("x"), a = c.searchParams.get("u"), h = c.host + c.pathname;
|
|
2042
2043
|
if (f === null || a === null)
|
|
2043
2044
|
throw new C("URI missing nonce (x) or unsecure (u) parameter.");
|
|
2044
2045
|
let d;
|
|
2045
2046
|
try {
|
|
2046
|
-
d = typeof
|
|
2047
|
-
} catch (
|
|
2048
|
-
throw new C(`Invalid expectedCallbackUrl provided: ${
|
|
2047
|
+
d = typeof o == "string" ? new URL(o) : o;
|
|
2048
|
+
} catch (y) {
|
|
2049
|
+
throw new C(`Invalid expectedCallbackUrl provided: ${y.message}`);
|
|
2049
2050
|
}
|
|
2050
|
-
const
|
|
2051
|
-
if (h !==
|
|
2052
|
-
throw new C(`Callback URL mismatch: URI contained "${h}", expected "${
|
|
2051
|
+
const x = d.host + d.pathname;
|
|
2052
|
+
if (h !== x)
|
|
2053
|
+
throw new C(`Callback URL mismatch: URI contained "${h}", expected "${x}"`);
|
|
2053
2054
|
const g = d.protocol;
|
|
2054
2055
|
if (a === "1" && g !== "http:")
|
|
2055
2056
|
throw new C("URI indicates unsecure (u=1), but expectedCallbackUrl is not http.");
|
|
2056
2057
|
if (a === "0" && g !== "https:")
|
|
2057
2058
|
throw new C("URI indicates secure (u=0), but expectedCallbackUrl is not https.");
|
|
2058
|
-
if (
|
|
2059
|
-
throw new C(`Nonce mismatch: URI contained "${f}", expected "${
|
|
2059
|
+
if (i && f !== i)
|
|
2060
|
+
throw new C(`Nonce mismatch: URI contained "${f}", expected "${i}". Possible replay attack.`);
|
|
2060
2061
|
try {
|
|
2061
2062
|
if (!await sr(n, r, s))
|
|
2062
2063
|
throw new C("Invalid signature.");
|
|
2063
|
-
} catch (
|
|
2064
|
-
throw
|
|
2064
|
+
} catch (y) {
|
|
2065
|
+
throw y instanceof C ? y : new C(`Unexpected error during signature verification: ${y.message}`);
|
|
2065
2066
|
}
|
|
2066
2067
|
return {
|
|
2067
2068
|
isValid: !0,
|