@gardenfi/utils 2.5.3-beta.1 → 2.5.3-beta.3
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/index10.cjs +1 -1
- package/dist/index10.js +4 -4
- package/dist/index101.cjs +4 -1
- package/dist/index101.js +190 -8
- package/dist/index102.cjs +3 -1
- package/dist/index102.js +446 -13
- package/dist/index104.cjs +1 -1
- package/dist/index104.js +161 -21
- package/dist/index105.cjs +1 -1
- package/dist/index105.js +20 -50
- package/dist/index106.cjs +1 -1
- package/dist/index106.js +127 -11
- package/dist/index107.cjs +1 -1
- package/dist/index107.js +31 -154
- package/dist/index108.cjs +1 -1
- package/dist/index108.js +6 -21
- package/dist/index109.cjs +1 -1
- package/dist/index109.js +27 -127
- package/dist/index110.cjs +1 -1
- package/dist/index110.js +51 -34
- package/dist/index111.cjs +1 -1
- package/dist/index111.js +45 -6
- package/dist/index112.cjs +1 -1
- package/dist/index112.js +191 -27
- package/dist/index113.cjs +1 -1
- package/dist/index113.js +4 -56
- package/dist/index114.cjs +1 -1
- package/dist/index114.js +61 -42
- package/dist/index115.cjs +1 -1
- package/dist/index115.js +14 -185
- package/dist/index116.cjs +1 -1
- package/dist/index116.js +3 -4
- package/dist/index117.cjs +1 -1
- package/dist/index117.js +13 -61
- package/dist/index118.cjs +1 -1
- package/dist/index118.js +24 -3
- package/dist/index119.cjs +1 -1
- package/dist/index119.js +11 -20
- package/dist/index120.cjs +1 -1
- package/dist/index120.js +18 -16
- package/dist/index121.cjs +1 -1
- package/dist/index121.js +33 -22
- package/dist/index122.cjs +1 -1
- package/dist/index122.js +3 -12
- package/dist/index123.cjs +1 -1
- package/dist/index123.js +18 -18
- package/dist/index124.cjs +1 -1
- package/dist/index124.js +26 -33
- package/dist/index125.cjs +1 -1
- package/dist/index125.js +37 -3
- package/dist/index126.cjs +1 -1
- package/dist/index126.js +8 -18
- package/dist/index127.cjs +1 -1
- package/dist/index127.js +10 -27
- package/dist/index128.cjs +1 -1
- package/dist/index128.js +24 -35
- package/dist/index129.cjs +1 -1
- package/dist/index129.js +28 -8
- package/dist/index130.cjs +1 -1
- package/dist/index130.js +3 -10
- package/dist/index131.cjs +1 -1
- package/dist/index131.js +64 -24
- package/dist/index132.cjs +1 -1
- package/dist/index132.js +9 -28
- package/dist/index133.cjs +1 -1
- package/dist/index133.js +19 -63
- package/dist/index134.cjs +1 -1
- package/dist/index134.js +8 -9
- package/dist/index135.cjs +1 -1
- package/dist/index135.js +10 -23
- package/dist/index136.cjs +1 -1
- package/dist/index136.js +11 -24
- package/dist/index137.cjs +1 -1
- package/dist/index137.js +6 -24
- package/dist/index138.cjs +1 -1
- package/dist/index138.js +6 -3
- package/dist/index139.cjs +1 -1
- package/dist/index139.js +13 -14
- package/dist/index140.cjs +1 -1
- package/dist/index140.js +30 -101
- package/dist/index141.cjs +1 -1
- package/dist/index141.js +5 -81
- package/dist/index142.cjs +1 -1
- package/dist/index142.js +37 -5
- package/dist/index143.cjs +1 -1
- package/dist/index143.js +111 -6
- package/dist/index144.cjs +1 -1
- package/dist/index144.js +169 -25
- package/dist/index145.cjs +1 -1
- package/dist/index145.js +49 -26
- package/dist/index146.cjs +1 -1
- package/dist/index146.js +32 -13
- package/dist/index147.cjs +1 -1
- package/dist/index147.js +7 -42
- package/dist/index148.cjs +1 -1
- package/dist/index148.js +8 -19
- package/dist/index149.cjs +1 -1
- package/dist/index149.js +20 -78
- package/dist/index150.cjs +1 -1
- package/dist/index150.js +24 -2
- package/dist/index151.cjs +1 -1
- package/dist/index151.js +39 -34
- package/dist/index152.cjs +1 -1
- package/dist/index152.js +22 -111
- package/dist/index153.cjs +1 -1
- package/dist/index153.js +21 -166
- package/dist/index154.cjs +1 -1
- package/dist/index154.js +50 -48
- package/dist/index155.cjs +1 -1
- package/dist/index155.js +11 -32
- package/dist/index156.cjs +1 -1
- package/dist/index156.js +24 -8
- package/dist/index157.cjs +1 -1
- package/dist/index157.js +24 -6
- package/dist/index158.cjs +1 -1
- package/dist/index158.js +104 -6
- package/dist/index159.cjs +1 -1
- package/dist/index159.js +3 -12
- package/dist/index160.cjs +1 -1
- package/dist/index160.js +5 -10
- package/dist/index161.cjs +1 -1
- package/dist/index161.js +31 -13
- package/dist/index162.cjs +1 -1
- package/dist/index162.js +3 -32
- package/dist/index163.cjs +1 -1
- package/dist/index163.js +18 -5
- package/dist/index164.cjs +1 -1
- package/dist/index164.js +5 -7
- package/dist/index165.cjs +1 -1
- package/dist/index165.js +8 -8
- package/dist/index166.cjs +1 -1
- package/dist/index166.js +102 -19
- package/dist/index167.cjs +1 -1
- package/dist/index167.js +78 -29
- package/dist/index168.cjs +1 -1
- package/dist/index168.js +5 -3
- package/dist/index169.cjs +1 -1
- package/dist/index169.js +6 -17
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +2 -2
- package/dist/index170.cjs +1 -1
- package/dist/index170.js +27 -10
- package/dist/index171.cjs +1 -1
- package/dist/index171.js +33 -20
- package/dist/index172.cjs +1 -1
- package/dist/index172.js +13 -22
- package/dist/index173.cjs +1 -1
- package/dist/index173.js +19 -5
- package/dist/index174.cjs +1 -1
- package/dist/index174.js +78 -5
- package/dist/index175.cjs +1 -1
- package/dist/index175.js +2 -9
- package/dist/index176.cjs +1 -1
- package/dist/index176.js +14 -104
- package/dist/index177.cjs +1 -1
- package/dist/index177.js +19 -3
- package/dist/index178.cjs +1 -1
- package/dist/index178.js +170 -17
- package/dist/index179.cjs +1 -1
- package/dist/index179.js +16 -170
- package/dist/index180.cjs +1 -1
- package/dist/index180.js +10 -17
- package/dist/index181.cjs +1 -1
- package/dist/index181.js +2 -2
- package/dist/index183.cjs +1 -1
- package/dist/index183.js +3 -3
- package/dist/index185.cjs +1 -1
- package/dist/index185.js +5 -5
- package/dist/index186.cjs +1 -1
- package/dist/index186.js +3 -3
- package/dist/index188.cjs +1 -1
- package/dist/index188.js +51 -74
- package/dist/index189.cjs +1 -1
- package/dist/index189.js +1 -1
- package/dist/index190.cjs +1 -1
- package/dist/index190.js +2 -2
- package/dist/index191.cjs +1 -1
- package/dist/index191.js +3 -3
- package/dist/index193.cjs +1 -1
- package/dist/index193.js +2 -2
- package/dist/index194.cjs +1 -1
- package/dist/index194.js +2 -2
- package/dist/index195.cjs +1 -1
- package/dist/index195.js +8 -8
- package/dist/index196.cjs +1 -1
- package/dist/index196.js +35 -8
- package/dist/index197.cjs +1 -1
- package/dist/index197.js +15 -34
- package/dist/index198.cjs +1 -1
- package/dist/index198.js +13 -15
- package/dist/index199.cjs +1 -1
- package/dist/index199.js +5 -13
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +2 -2
- package/dist/index200.cjs +2 -1
- package/dist/index200.js +24 -13
- package/dist/index201.cjs +1 -2
- package/dist/index201.js +13 -24
- package/dist/index202.cjs +1 -1
- package/dist/index202.js +25 -6
- package/dist/index203.cjs +1 -1
- package/dist/index203.js +17 -24
- package/dist/index204.cjs +1 -1
- package/dist/index204.js +15 -18
- package/dist/index205.cjs +1 -1
- package/dist/index205.js +5 -15
- package/dist/index206.cjs +1 -1
- package/dist/index206.js +13 -5
- package/dist/index207.cjs +1 -1
- package/dist/index207.js +9 -12
- package/dist/index208.cjs +1 -1
- package/dist/index208.js +16 -10
- package/dist/index209.cjs +2 -1
- package/dist/index209.js +41 -16
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +17 -4
- package/dist/index210.cjs +1 -2
- package/dist/index210.js +2 -42
- package/dist/index211.cjs +1 -1
- package/dist/index211.js +6 -2
- package/dist/index212.cjs +1 -1
- package/dist/index212.js +10 -5
- package/dist/index213.cjs +1 -1
- package/dist/index213.js +18 -9
- package/dist/index214.cjs +1 -1
- package/dist/index214.js +8 -19
- package/dist/index215.cjs +1 -1
- package/dist/index215.js +66 -8
- package/dist/index216.cjs +1 -1
- package/dist/index216.js +64 -65
- package/dist/index217.cjs +1 -1
- package/dist/index217.js +183 -60
- package/dist/index218.cjs +1 -1
- package/dist/index218.js +25 -183
- package/dist/index219.cjs +1 -1
- package/dist/index219.js +61 -13
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +9 -9
- package/dist/index220.cjs +1 -1
- package/dist/index220.js +18 -54
- package/dist/index221.cjs +1 -1
- package/dist/index221.js +10 -34
- package/dist/index222.cjs +1 -1
- package/dist/index222.js +7 -10
- package/dist/index223.cjs +1 -1
- package/dist/index223.js +12 -13
- package/dist/index224.cjs +1 -1
- package/dist/index224.js +11 -12
- package/dist/index225.cjs +1 -1
- package/dist/index225.js +19 -11
- package/dist/index226.cjs +1 -1
- package/dist/index226.js +106 -101
- package/dist/index227.cjs +1 -1
- package/dist/index227.js +6 -6
- package/dist/index228.cjs +1 -1
- package/dist/index228.js +7 -245
- package/dist/index229.cjs +1 -1
- package/dist/index229.js +103 -6
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +12 -26
- package/dist/index230.cjs +1 -1
- package/dist/index230.js +27 -7
- package/dist/index231.cjs +1 -1
- package/dist/index231.js +16 -26
- package/dist/index232.cjs +1 -1
- package/dist/index232.js +213 -18
- package/dist/index233.cjs +1 -1
- package/dist/index233.js +43 -143
- package/dist/index234.cjs +1 -1
- package/dist/index234.js +9 -24
- package/dist/index235.cjs +1 -1
- package/dist/index235.js +24 -46
- package/dist/index236.cjs +1 -1
- package/dist/index236.js +42 -9
- package/dist/index237.cjs +1 -1
- package/dist/index237.js +66 -30
- package/dist/index238.cjs +1 -1
- package/dist/index238.js +2 -79
- package/dist/index239.cjs +1 -1
- package/dist/index239.js +12 -2
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +59 -8
- package/dist/index240.cjs +1 -1
- package/dist/index240.js +19 -11
- package/dist/index241.cjs +1 -1
- package/dist/index241.js +68 -19
- package/dist/index242.cjs +1 -1
- package/dist/index242.js +657 -68
- package/dist/index243.cjs +1 -1
- package/dist/index243.js +189 -771
- package/dist/index244.cjs +1 -1
- package/dist/index244.js +164 -135
- package/dist/index245.cjs +2 -1
- package/dist/index245.js +62 -196
- package/dist/index246.cjs +1 -2
- package/dist/index246.js +14 -66
- package/dist/index247.cjs +1 -1
- package/dist/index247.js +4 -14
- package/dist/index248.cjs +1 -1
- package/dist/index248.js +2 -5
- package/dist/index25.cjs +16 -1
- package/dist/index25.js +113 -12
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +30 -58
- package/dist/index27.cjs +1 -16
- package/dist/index27.js +24 -111
- package/dist/index28.cjs +1 -1
- package/dist/index28.js +7 -29
- package/dist/index30.cjs +1 -1
- package/dist/index30.js +2 -2
- package/dist/index31.cjs +1 -1
- package/dist/index31.js +2 -2
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +2 -2
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +4 -4
- package/dist/index34.cjs +1 -1
- package/dist/index34.js +4 -4
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +7 -7
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +4 -4
- package/dist/index37.cjs +1 -1
- package/dist/index37.js +34 -33
- package/dist/index38.cjs +1 -1
- package/dist/index38.js +1 -1
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +10 -10
- package/dist/index43.cjs +1 -1
- package/dist/index43.js +1 -1
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +5 -5
- package/dist/index49.cjs +1 -1
- package/dist/index49.js +50 -68
- package/dist/index50.cjs +1 -1
- package/dist/index50.js +7 -9
- package/dist/index51.cjs +1 -1
- package/dist/index51.js +15 -27
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +10 -71
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +5 -19
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +14 -50
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +3 -7
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +26 -16
- package/dist/index57.cjs +1 -1
- package/dist/index57.js +109 -10
- package/dist/index58.cjs +1 -1
- package/dist/index58.js +4 -5
- package/dist/index59.cjs +1 -1
- package/dist/index59.js +6 -14
- package/dist/index60.cjs +1 -1
- package/dist/index60.js +88 -3
- package/dist/index61.cjs +1 -1
- package/dist/index61.js +6 -26
- package/dist/index62.cjs +1 -1
- package/dist/index62.js +121 -105
- package/dist/index63.cjs +1 -1
- package/dist/index63.js +7 -4
- package/dist/index64.cjs +1 -1
- package/dist/index64.js +21 -6
- package/dist/index65.cjs +1 -1
- package/dist/index65.js +16 -87
- package/dist/index66.cjs +1 -1
- package/dist/index66.js +39 -5
- package/dist/index67.cjs +1 -1
- package/dist/index67.js +20 -124
- package/dist/index68.cjs +1 -1
- package/dist/index68.js +10 -6
- package/dist/index69.cjs +1 -1
- package/dist/index69.js +6 -21
- package/dist/index70.cjs +1 -1
- package/dist/index70.js +19 -17
- package/dist/index71.cjs +1 -1
- package/dist/index71.js +105 -39
- package/dist/index72.cjs +1 -1
- package/dist/index72.js +67 -20
- package/dist/index73.cjs +1 -1
- package/dist/index73.js +9 -11
- package/dist/index74.cjs +1 -1
- package/dist/index74.js +28 -6
- package/dist/index75.cjs +1 -1
- package/dist/index75.js +67 -102
- package/dist/index76.cjs +1 -1
- package/dist/index76.js +4 -3
- package/dist/index77.cjs +2 -1
- package/dist/index77.js +3 -9
- package/dist/index78.cjs +1 -2
- package/dist/index78.js +9 -3
- package/dist/index81.cjs +1 -1
- package/dist/index81.js +1 -1
- package/dist/index82.cjs +1 -1
- package/dist/index82.js +13 -2
- package/dist/index83.cjs +1 -1
- package/dist/index83.js +2 -8
- package/dist/index84.cjs +1 -3
- package/dist/index84.js +6 -214
- package/dist/index85.cjs +2 -1
- package/dist/index85.js +55 -32
- package/dist/index86.cjs +3 -1
- package/dist/index86.js +214 -20
- package/dist/index87.cjs +1 -1
- package/dist/index87.js +32 -6
- package/dist/index88.cjs +1 -1
- package/dist/index88.js +21 -73
- package/dist/index89.cjs +1 -1
- package/dist/index89.js +5 -5
- package/dist/index90.cjs +1 -1
- package/dist/index90.js +73 -5
- package/dist/index91.cjs +1 -9
- package/dist/index91.js +5 -35
- package/dist/index92.cjs +1 -3
- package/dist/index92.js +5 -95
- package/dist/index93.cjs +9 -1
- package/dist/index93.js +36 -3
- package/dist/index94.cjs +3 -1
- package/dist/index94.js +87 -15
- package/dist/index95.cjs +1 -3
- package/dist/index95.js +3 -452
- package/dist/index96.cjs +1 -2
- package/dist/index96.js +10 -46
- package/dist/index98.cjs +1 -1
- package/dist/index98.js +3 -3
- package/dist/index99.cjs +1 -4
- package/dist/index99.js +16 -187
- package/package.json +2 -2
- package/dist/index249.cjs +0 -1
- package/dist/index249.js +0 -4
package/dist/index243.js
CHANGED
|
@@ -1,791 +1,209 @@
|
|
|
1
|
-
import { hmac as vt } from "./index237.js";
|
|
2
|
-
import { ahash as Bt, randomBytes as yt, concatBytes as I, bytesToHex as et, hexToBytes as lt, isBytes as Rt } from "./index233.js";
|
|
3
|
-
import { _validateObject as mt, bytesToNumberBE as wt, bitMask as pt, _abool2 as rt, _abytes2 as k, ensureBytes as N, memoized as dt, createHmacDrbg as St, numberToHexUnpadded as J, bitLen as xt, aInRange as Ot } from "./index244.js";
|
|
4
|
-
import { _createCurveFields as Zt, wNAF as At, normalizeZ as st, mulEndoUnsafe as Ut, pippenger as Ft, negateCt as ft } from "./index245.js";
|
|
5
|
-
import { nLength as Vt, Field as Yt, getMinHashLength as Kt, mapHashToField as Nt } from "./index228.js";
|
|
6
1
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
let A = r - V * t - B * w, U = -V * m - B * l;
|
|
11
|
-
const D = A < L, X = U < L;
|
|
12
|
-
D && (A = -A), X && (U = -U);
|
|
13
|
-
const E = pt(Math.ceil(xt(c) / 2)) + $;
|
|
14
|
-
if (A < L || A >= E || U < L || U >= E)
|
|
15
|
-
throw new Error("splitScalar (endomorphism): failed, k=" + r);
|
|
16
|
-
return { k1neg: D, k1: A, k2neg: X, k2: U };
|
|
2
|
+
const w = /* @__PURE__ */ BigInt(0), p = /* @__PURE__ */ BigInt(1);
|
|
3
|
+
function b(t) {
|
|
4
|
+
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
17
5
|
}
|
|
18
|
-
function
|
|
19
|
-
if (!
|
|
20
|
-
throw new Error(
|
|
21
|
-
return r;
|
|
6
|
+
function h(t) {
|
|
7
|
+
if (!b(t))
|
|
8
|
+
throw new Error("Uint8Array expected");
|
|
22
9
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
c[t] = r[t] === void 0 ? s[t] : r[t];
|
|
27
|
-
return rt(c.lowS, "lowS"), rt(c.prehash, "prehash"), c.format !== void 0 && ct(c.format), c;
|
|
10
|
+
function k(t, n) {
|
|
11
|
+
if (typeof n != "boolean")
|
|
12
|
+
throw new Error(t + " boolean expected, got " + n);
|
|
28
13
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
14
|
+
function F(t) {
|
|
15
|
+
const n = t.toString(16);
|
|
16
|
+
return n.length & 1 ? "0" + n : n;
|
|
33
17
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
_tlv: {
|
|
39
|
-
encode: (r, s) => {
|
|
40
|
-
const { Err: c } = C;
|
|
41
|
-
if (r < 0 || r > 256)
|
|
42
|
-
throw new c("tlv.encode: wrong tag");
|
|
43
|
-
if (s.length & 1)
|
|
44
|
-
throw new c("tlv.encode: unpadded data");
|
|
45
|
-
const t = s.length / 2, m = J(t);
|
|
46
|
-
if (m.length / 2 & 128)
|
|
47
|
-
throw new c("tlv.encode: long form length too big");
|
|
48
|
-
const w = t > 127 ? J(m.length / 2 | 128) : "";
|
|
49
|
-
return J(r) + w + m + s;
|
|
50
|
-
},
|
|
51
|
-
// v - value, l - left bytes (unparsed)
|
|
52
|
-
decode(r, s) {
|
|
53
|
-
const { Err: c } = C;
|
|
54
|
-
let t = 0;
|
|
55
|
-
if (r < 0 || r > 256)
|
|
56
|
-
throw new c("tlv.encode: wrong tag");
|
|
57
|
-
if (s.length < 2 || s[t++] !== r)
|
|
58
|
-
throw new c("tlv.decode: wrong tlv");
|
|
59
|
-
const m = s[t++], w = !!(m & 128);
|
|
60
|
-
let l = 0;
|
|
61
|
-
if (!w)
|
|
62
|
-
l = m;
|
|
63
|
-
else {
|
|
64
|
-
const B = m & 127;
|
|
65
|
-
if (!B)
|
|
66
|
-
throw new c("tlv.decode(long): indefinite length not supported");
|
|
67
|
-
if (B > 4)
|
|
68
|
-
throw new c("tlv.decode(long): byte length is too big");
|
|
69
|
-
const A = s.subarray(t, t + B);
|
|
70
|
-
if (A.length !== B)
|
|
71
|
-
throw new c("tlv.decode: length bytes not complete");
|
|
72
|
-
if (A[0] === 0)
|
|
73
|
-
throw new c("tlv.decode(long): zero leftmost byte");
|
|
74
|
-
for (const U of A)
|
|
75
|
-
l = l << 8 | U;
|
|
76
|
-
if (t += B, l < 128)
|
|
77
|
-
throw new c("tlv.decode(long): not minimal encoding");
|
|
78
|
-
}
|
|
79
|
-
const V = s.subarray(t, t + l);
|
|
80
|
-
if (V.length !== l)
|
|
81
|
-
throw new c("tlv.decode: wrong value length");
|
|
82
|
-
return { v: V, l: s.subarray(t + l) };
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
86
|
-
// since we always use positive integers here. It must always be empty:
|
|
87
|
-
// - add zero byte if exists
|
|
88
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
89
|
-
_int: {
|
|
90
|
-
encode(r) {
|
|
91
|
-
const { Err: s } = C;
|
|
92
|
-
if (r < L)
|
|
93
|
-
throw new s("integer: negative integers are not allowed");
|
|
94
|
-
let c = J(r);
|
|
95
|
-
if (Number.parseInt(c[0], 16) & 8 && (c = "00" + c), c.length & 1)
|
|
96
|
-
throw new s("unexpected DER parsing assertion: unpadded hex");
|
|
97
|
-
return c;
|
|
98
|
-
},
|
|
99
|
-
decode(r) {
|
|
100
|
-
const { Err: s } = C;
|
|
101
|
-
if (r[0] & 128)
|
|
102
|
-
throw new s("invalid signature integer: negative");
|
|
103
|
-
if (r[0] === 0 && !(r[1] & 128))
|
|
104
|
-
throw new s("invalid signature integer: unnecessary leading zero");
|
|
105
|
-
return wt(r);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
toSig(r) {
|
|
109
|
-
const { Err: s, _int: c, _tlv: t } = C, m = N("signature", r), { v: w, l } = t.decode(48, m);
|
|
110
|
-
if (l.length)
|
|
111
|
-
throw new s("invalid signature: left bytes after parsing");
|
|
112
|
-
const { v: V, l: B } = t.decode(2, w), { v: A, l: U } = t.decode(2, B);
|
|
113
|
-
if (U.length)
|
|
114
|
-
throw new s("invalid signature: left bytes after parsing");
|
|
115
|
-
return { r: c.decode(V), s: c.decode(A) };
|
|
116
|
-
},
|
|
117
|
-
hexFromSig(r) {
|
|
118
|
-
const { _tlv: s, _int: c } = C, t = s.encode(2, c.encode(r.r)), m = s.encode(2, c.encode(r.s)), w = t + m;
|
|
119
|
-
return s.encode(48, w);
|
|
120
|
-
}
|
|
121
|
-
}, L = BigInt(0), $ = BigInt(1), gt = BigInt(2), tt = BigInt(3), _t = BigInt(4);
|
|
122
|
-
function M(r, s) {
|
|
123
|
-
const { BYTES: c } = r;
|
|
124
|
-
let t;
|
|
125
|
-
if (typeof s == "bigint")
|
|
126
|
-
t = s;
|
|
127
|
-
else {
|
|
128
|
-
let m = N("private key", s);
|
|
129
|
-
try {
|
|
130
|
-
t = r.fromBytes(m);
|
|
131
|
-
} catch {
|
|
132
|
-
throw new Error(`invalid private key: expected ui8a of size ${c}, got ${typeof s}`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (!r.isValidNot0(t))
|
|
136
|
-
throw new Error("invalid private key: out of range [1..N-1]");
|
|
137
|
-
return t;
|
|
18
|
+
function E(t) {
|
|
19
|
+
if (typeof t != "string")
|
|
20
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
21
|
+
return t === "" ? w : BigInt("0x" + t);
|
|
138
22
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const d = T(f);
|
|
177
|
-
let u;
|
|
178
|
-
try {
|
|
179
|
-
u = t.sqrt(d);
|
|
180
|
-
} catch (O) {
|
|
181
|
-
const v = O instanceof Error ? ": " + O.message : "";
|
|
182
|
-
throw new Error("bad point: is not on curve, sqrt error" + v);
|
|
183
|
-
}
|
|
184
|
-
U();
|
|
185
|
-
const h = t.isOdd(u);
|
|
186
|
-
return (i & 1) === 1 !== h && (u = t.neg(u)), { x: f, y: u };
|
|
187
|
-
} else if (e === n && i === 4) {
|
|
188
|
-
const f = t.BYTES, d = t.fromBytes(a.subarray(0, f)), u = t.fromBytes(a.subarray(f, f * 2));
|
|
189
|
-
if (!H(d, u))
|
|
190
|
-
throw new Error("bad point: is not on curve");
|
|
191
|
-
return { x: d, y: u };
|
|
192
|
-
} else
|
|
193
|
-
throw new Error(`bad point: got length ${e}, expected compressed=${o} or uncompressed=${n}`);
|
|
194
|
-
}
|
|
195
|
-
const E = s.toBytes || D, x = s.fromBytes || X;
|
|
196
|
-
function T(b) {
|
|
197
|
-
const o = t.sqr(b), n = t.mul(o, b);
|
|
198
|
-
return t.add(t.add(n, t.mul(b, w.a)), w.b);
|
|
199
|
-
}
|
|
200
|
-
function H(b, o) {
|
|
201
|
-
const n = t.sqr(o), e = T(b);
|
|
202
|
-
return t.eql(n, e);
|
|
203
|
-
}
|
|
204
|
-
if (!H(w.Gx, w.Gy))
|
|
205
|
-
throw new Error("bad curve params: generator point");
|
|
206
|
-
const _ = t.mul(t.pow(w.a, tt), _t), nt = t.mul(t.sqr(w.b), BigInt(27));
|
|
207
|
-
if (t.is0(t.add(_, nt)))
|
|
208
|
-
throw new Error("bad curve params: a or b");
|
|
209
|
-
function F(b, o, n = !1) {
|
|
210
|
-
if (!t.isValid(o) || n && t.is0(o))
|
|
211
|
-
throw new Error(`bad point coordinate ${b}`);
|
|
212
|
-
return o;
|
|
213
|
-
}
|
|
214
|
-
function G(b) {
|
|
215
|
-
if (!(b instanceof p))
|
|
216
|
-
throw new Error("ProjectivePoint expected");
|
|
217
|
-
}
|
|
218
|
-
function j(b) {
|
|
219
|
-
if (!B || !B.basises)
|
|
220
|
-
throw new Error("no endo");
|
|
221
|
-
return Tt(b, B.basises, m.ORDER);
|
|
222
|
-
}
|
|
223
|
-
const ot = dt((b, o) => {
|
|
224
|
-
const { X: n, Y: e, Z: i } = b;
|
|
225
|
-
if (t.eql(i, t.ONE))
|
|
226
|
-
return { x: n, y: e };
|
|
227
|
-
const a = b.is0();
|
|
228
|
-
o == null && (o = a ? t.ONE : t.inv(i));
|
|
229
|
-
const f = t.mul(n, o), d = t.mul(e, o), u = t.mul(i, o);
|
|
230
|
-
if (a)
|
|
231
|
-
return { x: t.ZERO, y: t.ZERO };
|
|
232
|
-
if (!t.eql(u, t.ONE))
|
|
233
|
-
throw new Error("invZ was invalid");
|
|
234
|
-
return { x: f, y: d };
|
|
235
|
-
}), P = dt((b) => {
|
|
236
|
-
if (b.is0()) {
|
|
237
|
-
if (s.allowInfinityPoint && !t.is0(b.Y))
|
|
238
|
-
return;
|
|
239
|
-
throw new Error("bad point: ZERO");
|
|
240
|
-
}
|
|
241
|
-
const { x: o, y: n } = b.toAffine();
|
|
242
|
-
if (!t.isValid(o) || !t.isValid(n))
|
|
243
|
-
throw new Error("bad point: x or y not field elements");
|
|
244
|
-
if (!H(o, n))
|
|
245
|
-
throw new Error("bad point: equation left != right");
|
|
246
|
-
if (!b.isTorsionFree())
|
|
247
|
-
throw new Error("bad point: not in prime-order subgroup");
|
|
248
|
-
return !0;
|
|
249
|
-
});
|
|
250
|
-
function z(b, o, n, e, i) {
|
|
251
|
-
return n = new p(t.mul(n.X, b), n.Y, n.Z), o = ft(e, o), n = ft(i, n), o.add(n);
|
|
252
|
-
}
|
|
253
|
-
class p {
|
|
254
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
255
|
-
constructor(o, n, e) {
|
|
256
|
-
this.X = F("x", o), this.Y = F("y", n, !0), this.Z = F("z", e), Object.freeze(this);
|
|
257
|
-
}
|
|
258
|
-
static CURVE() {
|
|
259
|
-
return w;
|
|
260
|
-
}
|
|
261
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
262
|
-
static fromAffine(o) {
|
|
263
|
-
const { x: n, y: e } = o || {};
|
|
264
|
-
if (!o || !t.isValid(n) || !t.isValid(e))
|
|
265
|
-
throw new Error("invalid affine point");
|
|
266
|
-
if (o instanceof p)
|
|
267
|
-
throw new Error("projective point not allowed");
|
|
268
|
-
return t.is0(n) && t.is0(e) ? p.ZERO : new p(n, e, t.ONE);
|
|
269
|
-
}
|
|
270
|
-
static fromBytes(o) {
|
|
271
|
-
const n = p.fromAffine(x(k(o, void 0, "point")));
|
|
272
|
-
return n.assertValidity(), n;
|
|
273
|
-
}
|
|
274
|
-
static fromHex(o) {
|
|
275
|
-
return p.fromBytes(N("pointHex", o));
|
|
276
|
-
}
|
|
277
|
-
get x() {
|
|
278
|
-
return this.toAffine().x;
|
|
279
|
-
}
|
|
280
|
-
get y() {
|
|
281
|
-
return this.toAffine().y;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
*
|
|
285
|
-
* @param windowSize
|
|
286
|
-
* @param isLazy true will defer table computation until the first multiplication
|
|
287
|
-
* @returns
|
|
288
|
-
*/
|
|
289
|
-
precompute(o = 8, n = !0) {
|
|
290
|
-
return q.createCache(this, o), n || this.multiply(tt), this;
|
|
291
|
-
}
|
|
292
|
-
// TODO: return `this`
|
|
293
|
-
/** A point on curve is valid if it conforms to equation. */
|
|
294
|
-
assertValidity() {
|
|
295
|
-
P(this);
|
|
296
|
-
}
|
|
297
|
-
hasEvenY() {
|
|
298
|
-
const { y: o } = this.toAffine();
|
|
299
|
-
if (!t.isOdd)
|
|
300
|
-
throw new Error("Field doesn't support isOdd");
|
|
301
|
-
return !t.isOdd(o);
|
|
302
|
-
}
|
|
303
|
-
/** Compare one point to another. */
|
|
304
|
-
equals(o) {
|
|
305
|
-
G(o);
|
|
306
|
-
const { X: n, Y: e, Z: i } = this, { X: a, Y: f, Z: d } = o, u = t.eql(t.mul(n, d), t.mul(a, i)), h = t.eql(t.mul(e, d), t.mul(f, i));
|
|
307
|
-
return u && h;
|
|
308
|
-
}
|
|
309
|
-
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
310
|
-
negate() {
|
|
311
|
-
return new p(this.X, t.neg(this.Y), this.Z);
|
|
312
|
-
}
|
|
313
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
314
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
315
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
316
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
317
|
-
double() {
|
|
318
|
-
const { a: o, b: n } = w, e = t.mul(n, tt), { X: i, Y: a, Z: f } = this;
|
|
319
|
-
let d = t.ZERO, u = t.ZERO, h = t.ZERO, y = t.mul(i, i), O = t.mul(a, a), v = t.mul(f, f), g = t.mul(i, a);
|
|
320
|
-
return g = t.add(g, g), h = t.mul(i, f), h = t.add(h, h), d = t.mul(o, h), u = t.mul(e, v), u = t.add(d, u), d = t.sub(O, u), u = t.add(O, u), u = t.mul(d, u), d = t.mul(g, d), h = t.mul(e, h), v = t.mul(o, v), g = t.sub(y, v), g = t.mul(o, g), g = t.add(g, h), h = t.add(y, y), y = t.add(h, y), y = t.add(y, v), y = t.mul(y, g), u = t.add(u, y), v = t.mul(a, f), v = t.add(v, v), y = t.mul(v, g), d = t.sub(d, y), h = t.mul(v, O), h = t.add(h, h), h = t.add(h, h), new p(d, u, h);
|
|
321
|
-
}
|
|
322
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
323
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
324
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
325
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
326
|
-
add(o) {
|
|
327
|
-
G(o);
|
|
328
|
-
const { X: n, Y: e, Z: i } = this, { X: a, Y: f, Z: d } = o;
|
|
329
|
-
let u = t.ZERO, h = t.ZERO, y = t.ZERO;
|
|
330
|
-
const O = w.a, v = t.mul(w.b, tt);
|
|
331
|
-
let g = t.mul(n, a), R = t.mul(e, f), Z = t.mul(i, d), K = t.add(n, e), S = t.add(a, f);
|
|
332
|
-
K = t.mul(K, S), S = t.add(g, R), K = t.sub(K, S), S = t.add(n, i);
|
|
333
|
-
let Y = t.add(a, d);
|
|
334
|
-
return S = t.mul(S, Y), Y = t.add(g, Z), S = t.sub(S, Y), Y = t.add(e, i), u = t.add(f, d), Y = t.mul(Y, u), u = t.add(R, Z), Y = t.sub(Y, u), y = t.mul(O, S), u = t.mul(v, Z), y = t.add(u, y), u = t.sub(R, y), y = t.add(R, y), h = t.mul(u, y), R = t.add(g, g), R = t.add(R, g), Z = t.mul(O, Z), S = t.mul(v, S), R = t.add(R, Z), Z = t.sub(g, Z), Z = t.mul(O, Z), S = t.add(S, Z), g = t.mul(R, S), h = t.add(h, g), g = t.mul(Y, S), u = t.mul(K, u), u = t.sub(u, g), g = t.mul(K, R), y = t.mul(Y, y), y = t.add(y, g), new p(u, h, y);
|
|
335
|
-
}
|
|
336
|
-
subtract(o) {
|
|
337
|
-
return this.add(o.negate());
|
|
338
|
-
}
|
|
339
|
-
is0() {
|
|
340
|
-
return this.equals(p.ZERO);
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Constant time multiplication.
|
|
344
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
345
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
346
|
-
* Uses precomputes when available.
|
|
347
|
-
* Uses endomorphism for Koblitz curves.
|
|
348
|
-
* @param scalar by which the point would be multiplied
|
|
349
|
-
* @returns New point
|
|
350
|
-
*/
|
|
351
|
-
multiply(o) {
|
|
352
|
-
const { endo: n } = s;
|
|
353
|
-
if (!m.isValidNot0(o))
|
|
354
|
-
throw new Error("invalid scalar: out of range");
|
|
355
|
-
let e, i;
|
|
356
|
-
const a = (f) => q.cached(this, f, (d) => st(p, d));
|
|
357
|
-
if (n) {
|
|
358
|
-
const { k1neg: f, k1: d, k2neg: u, k2: h } = j(o), { p: y, f: O } = a(d), { p: v, f: g } = a(h);
|
|
359
|
-
i = O.add(g), e = z(n.beta, y, v, f, u);
|
|
360
|
-
} else {
|
|
361
|
-
const { p: f, f: d } = a(o);
|
|
362
|
-
e = f, i = d;
|
|
363
|
-
}
|
|
364
|
-
return st(p, [e, i])[0];
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
368
|
-
* It's faster, but should only be used when you don't care about
|
|
369
|
-
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
370
|
-
*/
|
|
371
|
-
multiplyUnsafe(o) {
|
|
372
|
-
const { endo: n } = s, e = this;
|
|
373
|
-
if (!m.isValid(o))
|
|
374
|
-
throw new Error("invalid scalar: out of range");
|
|
375
|
-
if (o === L || e.is0())
|
|
376
|
-
return p.ZERO;
|
|
377
|
-
if (o === $)
|
|
378
|
-
return e;
|
|
379
|
-
if (q.hasCache(this))
|
|
380
|
-
return this.multiply(o);
|
|
381
|
-
if (n) {
|
|
382
|
-
const { k1neg: i, k1: a, k2neg: f, k2: d } = j(o), { p1: u, p2: h } = Ut(p, e, a, d);
|
|
383
|
-
return z(n.beta, u, h, i, f);
|
|
384
|
-
} else
|
|
385
|
-
return q.unsafe(e, o);
|
|
386
|
-
}
|
|
387
|
-
multiplyAndAddUnsafe(o, n, e) {
|
|
388
|
-
const i = this.multiplyUnsafe(n).add(o.multiplyUnsafe(e));
|
|
389
|
-
return i.is0() ? void 0 : i;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Converts Projective point to affine (x, y) coordinates.
|
|
393
|
-
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
394
|
-
*/
|
|
395
|
-
toAffine(o) {
|
|
396
|
-
return ot(this, o);
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
400
|
-
* Always torsion-free for cofactor=1 curves.
|
|
401
|
-
*/
|
|
402
|
-
isTorsionFree() {
|
|
403
|
-
const { isTorsionFree: o } = s;
|
|
404
|
-
return l === $ ? !0 : o ? o(p, this) : q.unsafe(this, V).is0();
|
|
405
|
-
}
|
|
406
|
-
clearCofactor() {
|
|
407
|
-
const { clearCofactor: o } = s;
|
|
408
|
-
return l === $ ? this : o ? o(p, this) : this.multiplyUnsafe(l);
|
|
409
|
-
}
|
|
410
|
-
isSmallOrder() {
|
|
411
|
-
return this.multiplyUnsafe(l).is0();
|
|
412
|
-
}
|
|
413
|
-
toBytes(o = !0) {
|
|
414
|
-
return rt(o, "isCompressed"), this.assertValidity(), E(p, this, o);
|
|
415
|
-
}
|
|
416
|
-
toHex(o = !0) {
|
|
417
|
-
return et(this.toBytes(o));
|
|
418
|
-
}
|
|
419
|
-
toString() {
|
|
420
|
-
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
421
|
-
}
|
|
422
|
-
// TODO: remove
|
|
423
|
-
get px() {
|
|
424
|
-
return this.X;
|
|
425
|
-
}
|
|
426
|
-
get py() {
|
|
427
|
-
return this.X;
|
|
428
|
-
}
|
|
429
|
-
get pz() {
|
|
430
|
-
return this.Z;
|
|
431
|
-
}
|
|
432
|
-
toRawBytes(o = !0) {
|
|
433
|
-
return this.toBytes(o);
|
|
434
|
-
}
|
|
435
|
-
_setWindowSize(o) {
|
|
436
|
-
this.precompute(o);
|
|
437
|
-
}
|
|
438
|
-
static normalizeZ(o) {
|
|
439
|
-
return st(p, o);
|
|
440
|
-
}
|
|
441
|
-
static msm(o, n) {
|
|
442
|
-
return Ft(p, m, o, n);
|
|
443
|
-
}
|
|
444
|
-
static fromPrivateKey(o) {
|
|
445
|
-
return p.BASE.multiply(M(m, o));
|
|
446
|
-
}
|
|
23
|
+
const U = (
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function"
|
|
26
|
+
), S = /* @__PURE__ */ Array.from({ length: 256 }, (t, n) => n.toString(16).padStart(2, "0"));
|
|
27
|
+
function x(t) {
|
|
28
|
+
if (h(t), U)
|
|
29
|
+
return t.toHex();
|
|
30
|
+
let n = "";
|
|
31
|
+
for (let e = 0; e < t.length; e++)
|
|
32
|
+
n += S[t[e]];
|
|
33
|
+
return n;
|
|
34
|
+
}
|
|
35
|
+
const u = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
36
|
+
function m(t) {
|
|
37
|
+
if (t >= u._0 && t <= u._9)
|
|
38
|
+
return t - u._0;
|
|
39
|
+
if (t >= u.A && t <= u.F)
|
|
40
|
+
return t - (u.A - 10);
|
|
41
|
+
if (t >= u.a && t <= u.f)
|
|
42
|
+
return t - (u.a - 10);
|
|
43
|
+
}
|
|
44
|
+
function B(t) {
|
|
45
|
+
if (typeof t != "string")
|
|
46
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
47
|
+
if (U)
|
|
48
|
+
return Uint8Array.fromHex(t);
|
|
49
|
+
const n = t.length, e = n / 2;
|
|
50
|
+
if (n % 2)
|
|
51
|
+
throw new Error("hex string expected, got unpadded hex of length " + n);
|
|
52
|
+
const r = new Uint8Array(e);
|
|
53
|
+
for (let o = 0, i = 0; o < e; o++, i += 2) {
|
|
54
|
+
const a = m(t.charCodeAt(i)), f = m(t.charCodeAt(i + 1));
|
|
55
|
+
if (a === void 0 || f === void 0) {
|
|
56
|
+
const c = t[i] + t[i + 1];
|
|
57
|
+
throw new Error('hex string expected, got non-hex character "' + c + '" at index ' + i);
|
|
58
|
+
}
|
|
59
|
+
r[o] = a * 16 + f;
|
|
447
60
|
}
|
|
448
|
-
|
|
449
|
-
const W = m.BITS, q = new At(p, s.endo ? Math.ceil(W / 2) : W);
|
|
450
|
-
return p.BASE.precompute(8), p;
|
|
61
|
+
return r;
|
|
451
62
|
}
|
|
452
|
-
function
|
|
453
|
-
return
|
|
63
|
+
function O(t) {
|
|
64
|
+
return E(x(t));
|
|
454
65
|
}
|
|
455
|
-
function
|
|
456
|
-
return
|
|
457
|
-
secretKey: s.BYTES,
|
|
458
|
-
publicKey: 1 + r.BYTES,
|
|
459
|
-
publicKeyUncompressed: 1 + 2 * r.BYTES,
|
|
460
|
-
publicKeyHasPrefix: !0,
|
|
461
|
-
signature: 2 * s.BYTES
|
|
462
|
-
};
|
|
66
|
+
function V(t) {
|
|
67
|
+
return h(t), E(x(Uint8Array.from(t).reverse()));
|
|
463
68
|
}
|
|
464
|
-
function
|
|
465
|
-
|
|
466
|
-
function w(E) {
|
|
467
|
-
try {
|
|
468
|
-
return !!M(c, E);
|
|
469
|
-
} catch {
|
|
470
|
-
return !1;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
function l(E, x) {
|
|
474
|
-
const { publicKey: T, publicKeyUncompressed: H } = m;
|
|
475
|
-
try {
|
|
476
|
-
const _ = E.length;
|
|
477
|
-
return x === !0 && _ !== T || x === !1 && _ !== H ? !1 : !!r.fromBytes(E);
|
|
478
|
-
} catch {
|
|
479
|
-
return !1;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function V(E = t(m.seed)) {
|
|
483
|
-
return Nt(k(E, m.seed, "seed"), c.ORDER);
|
|
484
|
-
}
|
|
485
|
-
function B(E, x = !0) {
|
|
486
|
-
return r.BASE.multiply(M(c, E)).toBytes(x);
|
|
487
|
-
}
|
|
488
|
-
function A(E) {
|
|
489
|
-
const x = V(E);
|
|
490
|
-
return { secretKey: x, publicKey: B(x) };
|
|
491
|
-
}
|
|
492
|
-
function U(E) {
|
|
493
|
-
if (typeof E == "bigint")
|
|
494
|
-
return !1;
|
|
495
|
-
if (E instanceof r)
|
|
496
|
-
return !0;
|
|
497
|
-
const { secretKey: x, publicKey: T, publicKeyUncompressed: H } = m;
|
|
498
|
-
if (c.allowedLengths || x === T)
|
|
499
|
-
return;
|
|
500
|
-
const _ = N("key", E).length;
|
|
501
|
-
return _ === T || _ === H;
|
|
502
|
-
}
|
|
503
|
-
function D(E, x, T = !0) {
|
|
504
|
-
if (U(E) === !0)
|
|
505
|
-
throw new Error("first arg must be private key");
|
|
506
|
-
if (U(x) === !1)
|
|
507
|
-
throw new Error("second arg must be public key");
|
|
508
|
-
const H = M(c, E);
|
|
509
|
-
return r.fromHex(x).multiply(H).toBytes(T);
|
|
510
|
-
}
|
|
511
|
-
return Object.freeze({ getPublicKey: B, getSharedSecret: D, keygen: A, Point: r, utils: {
|
|
512
|
-
isValidSecretKey: w,
|
|
513
|
-
isValidPublicKey: l,
|
|
514
|
-
randomSecretKey: V,
|
|
515
|
-
// TODO: remove
|
|
516
|
-
isValidPrivateKey: w,
|
|
517
|
-
randomPrivateKey: V,
|
|
518
|
-
normPrivateKeyToScalar: (E) => M(c, E),
|
|
519
|
-
precompute(E = 8, x = r.BASE) {
|
|
520
|
-
return x.precompute(E, !1);
|
|
521
|
-
}
|
|
522
|
-
}, lengths: m });
|
|
69
|
+
function T(t, n) {
|
|
70
|
+
return B(t.toString(16).padStart(n * 2, "0"));
|
|
523
71
|
}
|
|
524
|
-
function
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
bits2int_modN: "function"
|
|
531
|
-
});
|
|
532
|
-
const t = c.randomBytes || yt, m = c.hmac || ((n, ...e) => vt(s, n, I(...e))), { Fp: w, Fn: l } = r, { ORDER: V, BITS: B } = l, { keygen: A, getPublicKey: U, getSharedSecret: D, utils: X, lengths: E } = Lt(r, c), x = {
|
|
533
|
-
prehash: !1,
|
|
534
|
-
lowS: typeof c.lowS == "boolean" ? c.lowS : !1,
|
|
535
|
-
format: void 0,
|
|
536
|
-
//'compact' as ECDSASigFormat,
|
|
537
|
-
extraEntropy: !1
|
|
538
|
-
}, T = "compact";
|
|
539
|
-
function H(n) {
|
|
540
|
-
const e = V >> $;
|
|
541
|
-
return n > e;
|
|
542
|
-
}
|
|
543
|
-
function _(n, e) {
|
|
544
|
-
if (!l.isValidNot0(e))
|
|
545
|
-
throw new Error(`invalid signature ${n}: out of range 1..Point.Fn.ORDER`);
|
|
546
|
-
return e;
|
|
547
|
-
}
|
|
548
|
-
function nt(n, e) {
|
|
549
|
-
ct(e);
|
|
550
|
-
const i = E.signature, a = e === "compact" ? i : e === "recovered" ? i + 1 : void 0;
|
|
551
|
-
return k(n, a, `${e} signature`);
|
|
552
|
-
}
|
|
553
|
-
class F {
|
|
554
|
-
constructor(e, i, a) {
|
|
555
|
-
this.r = _("r", e), this.s = _("s", i), a != null && (this.recovery = a), Object.freeze(this);
|
|
556
|
-
}
|
|
557
|
-
static fromBytes(e, i = T) {
|
|
558
|
-
nt(e, i);
|
|
559
|
-
let a;
|
|
560
|
-
if (i === "der") {
|
|
561
|
-
const { r: h, s: y } = C.toSig(k(e));
|
|
562
|
-
return new F(h, y);
|
|
563
|
-
}
|
|
564
|
-
i === "recovered" && (a = e[0], i = "compact", e = e.subarray(1));
|
|
565
|
-
const f = l.BYTES, d = e.subarray(0, f), u = e.subarray(f, f * 2);
|
|
566
|
-
return new F(l.fromBytes(d), l.fromBytes(u), a);
|
|
567
|
-
}
|
|
568
|
-
static fromHex(e, i) {
|
|
569
|
-
return this.fromBytes(lt(e), i);
|
|
570
|
-
}
|
|
571
|
-
addRecoveryBit(e) {
|
|
572
|
-
return new F(this.r, this.s, e);
|
|
573
|
-
}
|
|
574
|
-
recoverPublicKey(e) {
|
|
575
|
-
const i = w.ORDER, { r: a, s: f, recovery: d } = this;
|
|
576
|
-
if (d == null || ![0, 1, 2, 3].includes(d))
|
|
577
|
-
throw new Error("recovery id invalid");
|
|
578
|
-
if (V * gt < i && d > 1)
|
|
579
|
-
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
580
|
-
const h = d === 2 || d === 3 ? a + V : a;
|
|
581
|
-
if (!w.isValid(h))
|
|
582
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
583
|
-
const y = w.toBytes(h), O = r.fromBytes(I(Et((d & 1) === 0), y)), v = l.inv(h), g = j(N("msgHash", e)), R = l.create(-g * v), Z = l.create(f * v), K = r.BASE.multiplyUnsafe(R).add(O.multiplyUnsafe(Z));
|
|
584
|
-
if (K.is0())
|
|
585
|
-
throw new Error("point at infinify");
|
|
586
|
-
return K.assertValidity(), K;
|
|
587
|
-
}
|
|
588
|
-
// Signatures should be low-s, to prevent malleability.
|
|
589
|
-
hasHighS() {
|
|
590
|
-
return H(this.s);
|
|
591
|
-
}
|
|
592
|
-
toBytes(e = T) {
|
|
593
|
-
if (ct(e), e === "der")
|
|
594
|
-
return lt(C.hexFromSig(this));
|
|
595
|
-
const i = l.toBytes(this.r), a = l.toBytes(this.s);
|
|
596
|
-
if (e === "recovered") {
|
|
597
|
-
if (this.recovery == null)
|
|
598
|
-
throw new Error("recovery bit must be present");
|
|
599
|
-
return I(Uint8Array.of(this.recovery), i, a);
|
|
600
|
-
}
|
|
601
|
-
return I(i, a);
|
|
602
|
-
}
|
|
603
|
-
toHex(e) {
|
|
604
|
-
return et(this.toBytes(e));
|
|
605
|
-
}
|
|
606
|
-
// TODO: remove
|
|
607
|
-
assertValidity() {
|
|
608
|
-
}
|
|
609
|
-
static fromCompact(e) {
|
|
610
|
-
return F.fromBytes(N("sig", e), "compact");
|
|
611
|
-
}
|
|
612
|
-
static fromDER(e) {
|
|
613
|
-
return F.fromBytes(N("sig", e), "der");
|
|
614
|
-
}
|
|
615
|
-
normalizeS() {
|
|
616
|
-
return this.hasHighS() ? new F(this.r, l.neg(this.s), this.recovery) : this;
|
|
617
|
-
}
|
|
618
|
-
toDERRawBytes() {
|
|
619
|
-
return this.toBytes("der");
|
|
620
|
-
}
|
|
621
|
-
toDERHex() {
|
|
622
|
-
return et(this.toBytes("der"));
|
|
623
|
-
}
|
|
624
|
-
toCompactRawBytes() {
|
|
625
|
-
return this.toBytes("compact");
|
|
626
|
-
}
|
|
627
|
-
toCompactHex() {
|
|
628
|
-
return et(this.toBytes("compact"));
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
const G = c.bits2int || function(e) {
|
|
632
|
-
if (e.length > 8192)
|
|
633
|
-
throw new Error("input is too large");
|
|
634
|
-
const i = wt(e), a = e.length * 8 - B;
|
|
635
|
-
return a > 0 ? i >> BigInt(a) : i;
|
|
636
|
-
}, j = c.bits2int_modN || function(e) {
|
|
637
|
-
return l.create(G(e));
|
|
638
|
-
}, ot = pt(B);
|
|
639
|
-
function P(n) {
|
|
640
|
-
return Ot("num < 2^" + B, n, L, ot), l.toBytes(n);
|
|
641
|
-
}
|
|
642
|
-
function z(n, e) {
|
|
643
|
-
return k(n, void 0, "message"), e ? k(s(n), void 0, "prehashed message") : n;
|
|
644
|
-
}
|
|
645
|
-
function p(n, e, i) {
|
|
646
|
-
if (["recovered", "canonical"].some((R) => R in i))
|
|
647
|
-
throw new Error("sign() legacy options not supported");
|
|
648
|
-
const { lowS: a, prehash: f, extraEntropy: d } = it(i, x);
|
|
649
|
-
n = z(n, f);
|
|
650
|
-
const u = j(n), h = M(l, e), y = [P(h), P(u)];
|
|
651
|
-
if (d != null && d !== !1) {
|
|
652
|
-
const R = d === !0 ? t(E.secretKey) : d;
|
|
653
|
-
y.push(N("extraEntropy", R));
|
|
654
|
-
}
|
|
655
|
-
const O = I(...y), v = u;
|
|
656
|
-
function g(R) {
|
|
657
|
-
const Z = G(R);
|
|
658
|
-
if (!l.isValidNot0(Z))
|
|
659
|
-
return;
|
|
660
|
-
const K = l.inv(Z), S = r.BASE.multiply(Z).toAffine(), Y = l.create(S.x);
|
|
661
|
-
if (Y === L)
|
|
662
|
-
return;
|
|
663
|
-
const Q = l.create(K * l.create(v + Y * h));
|
|
664
|
-
if (Q === L)
|
|
665
|
-
return;
|
|
666
|
-
let at = (S.x === Y ? 0 : 2) | Number(S.y & $), ut = Q;
|
|
667
|
-
return a && H(Q) && (ut = l.neg(Q), at ^= 1), new F(Y, ut, at);
|
|
668
|
-
}
|
|
669
|
-
return { seed: O, k2sig: g };
|
|
670
|
-
}
|
|
671
|
-
function W(n, e, i = {}) {
|
|
672
|
-
n = N("message", n);
|
|
673
|
-
const { seed: a, k2sig: f } = p(n, e, i);
|
|
674
|
-
return St(s.outputLen, l.BYTES, m)(a, f);
|
|
675
|
-
}
|
|
676
|
-
function q(n) {
|
|
677
|
-
let e;
|
|
678
|
-
const i = typeof n == "string" || Rt(n), a = !i && n !== null && typeof n == "object" && typeof n.r == "bigint" && typeof n.s == "bigint";
|
|
679
|
-
if (!i && !a)
|
|
680
|
-
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
681
|
-
if (a)
|
|
682
|
-
e = new F(n.r, n.s);
|
|
683
|
-
else if (i) {
|
|
684
|
-
try {
|
|
685
|
-
e = F.fromBytes(N("sig", n), "der");
|
|
686
|
-
} catch (f) {
|
|
687
|
-
if (!(f instanceof C.Err))
|
|
688
|
-
throw f;
|
|
689
|
-
}
|
|
690
|
-
if (!e)
|
|
691
|
-
try {
|
|
692
|
-
e = F.fromBytes(N("sig", n), "compact");
|
|
693
|
-
} catch {
|
|
694
|
-
return !1;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return e || !1;
|
|
698
|
-
}
|
|
699
|
-
function b(n, e, i, a = {}) {
|
|
700
|
-
const { lowS: f, prehash: d, format: u } = it(a, x);
|
|
701
|
-
if (i = N("publicKey", i), e = z(N("message", e), d), "strict" in a)
|
|
702
|
-
throw new Error("options.strict was renamed to lowS");
|
|
703
|
-
const h = u === void 0 ? q(n) : F.fromBytes(N("sig", n), u);
|
|
704
|
-
if (h === !1)
|
|
705
|
-
return !1;
|
|
72
|
+
function C(t, n) {
|
|
73
|
+
return T(t, n).reverse();
|
|
74
|
+
}
|
|
75
|
+
function M(t, n, e) {
|
|
76
|
+
let r;
|
|
77
|
+
if (typeof n == "string")
|
|
706
78
|
try {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
720
|
-
return Object.freeze({
|
|
721
|
-
keygen: A,
|
|
722
|
-
getPublicKey: U,
|
|
723
|
-
getSharedSecret: D,
|
|
724
|
-
utils: X,
|
|
725
|
-
lengths: E,
|
|
726
|
-
Point: r,
|
|
727
|
-
sign: W,
|
|
728
|
-
verify: b,
|
|
729
|
-
recoverPublicKey: o,
|
|
730
|
-
Signature: F,
|
|
731
|
-
hash: s
|
|
732
|
-
});
|
|
79
|
+
r = B(n);
|
|
80
|
+
} catch (i) {
|
|
81
|
+
throw new Error(t + " must be hex string or Uint8Array, cause: " + i);
|
|
82
|
+
}
|
|
83
|
+
else if (b(n))
|
|
84
|
+
r = Uint8Array.from(n);
|
|
85
|
+
else
|
|
86
|
+
throw new Error(t + " must be hex string or Uint8Array");
|
|
87
|
+
const o = r.length;
|
|
88
|
+
if (typeof e == "number" && o !== e)
|
|
89
|
+
throw new Error(t + " of length " + e + " expected, got " + o);
|
|
90
|
+
return r;
|
|
733
91
|
}
|
|
734
|
-
function
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
isTorsionFree: r.isTorsionFree,
|
|
755
|
-
clearCofactor: r.clearCofactor,
|
|
756
|
-
fromBytes: r.fromBytes,
|
|
757
|
-
toBytes: r.toBytes
|
|
758
|
-
};
|
|
759
|
-
return { CURVE: s, curveOpts: w };
|
|
92
|
+
function H(...t) {
|
|
93
|
+
let n = 0;
|
|
94
|
+
for (let r = 0; r < t.length; r++) {
|
|
95
|
+
const o = t[r];
|
|
96
|
+
h(o), n += o.length;
|
|
97
|
+
}
|
|
98
|
+
const e = new Uint8Array(n);
|
|
99
|
+
for (let r = 0, o = 0; r < t.length; r++) {
|
|
100
|
+
const i = t[r];
|
|
101
|
+
e.set(i, o), o += i.length;
|
|
102
|
+
}
|
|
103
|
+
return e;
|
|
104
|
+
}
|
|
105
|
+
const y = (t) => typeof t == "bigint" && w <= t;
|
|
106
|
+
function I(t, n, e) {
|
|
107
|
+
return y(t) && y(n) && y(e) && n <= t && t < e;
|
|
108
|
+
}
|
|
109
|
+
function R(t, n, e, r) {
|
|
110
|
+
if (!I(n, e, r))
|
|
111
|
+
throw new Error("expected valid " + t + ": " + e + " <= n < " + r + ", got " + n);
|
|
760
112
|
}
|
|
761
|
-
function
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
113
|
+
function j(t) {
|
|
114
|
+
let n;
|
|
115
|
+
for (n = 0; t > w; t >>= p, n += 1)
|
|
116
|
+
;
|
|
117
|
+
return n;
|
|
118
|
+
}
|
|
119
|
+
const z = (t) => (p << BigInt(t)) - p, d = (t) => new Uint8Array(t), A = (t) => Uint8Array.from(t);
|
|
120
|
+
function D(t, n, e) {
|
|
121
|
+
if (typeof t != "number" || t < 2)
|
|
122
|
+
throw new Error("hashLen must be a number");
|
|
123
|
+
if (typeof n != "number" || n < 2)
|
|
124
|
+
throw new Error("qByteLen must be a number");
|
|
125
|
+
if (typeof e != "function")
|
|
126
|
+
throw new Error("hmacFn must be a function");
|
|
127
|
+
let r = d(t), o = d(t), i = 0;
|
|
128
|
+
const a = () => {
|
|
129
|
+
r.fill(1), o.fill(0), i = 0;
|
|
130
|
+
}, f = (...s) => e(o, r, ...s), c = (s = d(0)) => {
|
|
131
|
+
o = f(A([0]), s), r = f(), s.length !== 0 && (o = f(A([1]), s), r = f());
|
|
132
|
+
}, v = () => {
|
|
133
|
+
if (i++ >= 1e3)
|
|
134
|
+
throw new Error("drbg: tried 1000 values");
|
|
135
|
+
let s = 0;
|
|
136
|
+
const l = [];
|
|
137
|
+
for (; s < n; ) {
|
|
138
|
+
r = f();
|
|
139
|
+
const g = r.slice();
|
|
140
|
+
l.push(g), s += r.length;
|
|
141
|
+
}
|
|
142
|
+
return H(...l);
|
|
143
|
+
};
|
|
144
|
+
return (s, l) => {
|
|
145
|
+
a(), c(s);
|
|
146
|
+
let g;
|
|
147
|
+
for (; !(g = l(v())); )
|
|
148
|
+
c();
|
|
149
|
+
return a(), g;
|
|
768
150
|
};
|
|
769
|
-
return { CURVE: s, curveOpts: c, hash: r.hash, ecdsaOpts: t };
|
|
770
151
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
152
|
+
const _ = {
|
|
153
|
+
bigint: (t) => typeof t == "bigint",
|
|
154
|
+
function: (t) => typeof t == "function",
|
|
155
|
+
boolean: (t) => typeof t == "boolean",
|
|
156
|
+
string: (t) => typeof t == "string",
|
|
157
|
+
stringOrUint8Array: (t) => typeof t == "string" || b(t),
|
|
158
|
+
isSafeInteger: (t) => Number.isSafeInteger(t),
|
|
159
|
+
array: (t) => Array.isArray(t),
|
|
160
|
+
field: (t, n) => n.Fp.isValid(t),
|
|
161
|
+
hash: (t) => typeof t == "function" && Number.isSafeInteger(t.outputLen)
|
|
162
|
+
};
|
|
163
|
+
function P(t, n, e = {}) {
|
|
164
|
+
const r = (o, i, a) => {
|
|
165
|
+
const f = _[i];
|
|
166
|
+
if (typeof f != "function")
|
|
167
|
+
throw new Error("invalid validator function");
|
|
168
|
+
const c = t[o];
|
|
169
|
+
if (!(a && c === void 0) && !f(c, t))
|
|
170
|
+
throw new Error("param " + String(o) + " is invalid. Expected " + i + ", got " + c);
|
|
171
|
+
};
|
|
172
|
+
for (const [o, i] of Object.entries(n))
|
|
173
|
+
r(o, i, !1);
|
|
174
|
+
for (const [o, i] of Object.entries(e))
|
|
175
|
+
r(o, i, !0);
|
|
176
|
+
return t;
|
|
777
177
|
}
|
|
778
|
-
function
|
|
779
|
-
const
|
|
780
|
-
return
|
|
178
|
+
function W(t) {
|
|
179
|
+
const n = /* @__PURE__ */ new WeakMap();
|
|
180
|
+
return (e, ...r) => {
|
|
181
|
+
const o = n.get(e);
|
|
182
|
+
if (o !== void 0)
|
|
183
|
+
return o;
|
|
184
|
+
const i = t(e, ...r);
|
|
185
|
+
return n.set(e, i), i;
|
|
186
|
+
};
|
|
781
187
|
}
|
|
782
188
|
export {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
189
|
+
R as aInRange,
|
|
190
|
+
k as abool,
|
|
191
|
+
h as abytes,
|
|
192
|
+
j as bitLen,
|
|
193
|
+
z as bitMask,
|
|
194
|
+
x as bytesToHex,
|
|
195
|
+
O as bytesToNumberBE,
|
|
196
|
+
V as bytesToNumberLE,
|
|
197
|
+
H as concatBytes,
|
|
198
|
+
D as createHmacDrbg,
|
|
199
|
+
M as ensureBytes,
|
|
200
|
+
B as hexToBytes,
|
|
201
|
+
E as hexToNumber,
|
|
202
|
+
I as inRange,
|
|
203
|
+
b as isBytes,
|
|
204
|
+
W as memoized,
|
|
205
|
+
T as numberToBytesBE,
|
|
206
|
+
C as numberToBytesLE,
|
|
207
|
+
F as numberToHexUnpadded,
|
|
208
|
+
P as validateObject
|
|
791
209
|
};
|