@coinbase/cdp-hooks 0.0.96 → 0.0.97

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.
Files changed (282) hide show
  1. package/dist/esm/index100.js +35 -25
  2. package/dist/esm/index101.js +9 -46
  3. package/dist/esm/index102.js +31 -69
  4. package/dist/esm/index103.js +36 -40
  5. package/dist/esm/index104.js +9 -75
  6. package/dist/esm/index105.js +25 -27
  7. package/dist/esm/index106.js +46 -6
  8. package/dist/esm/index107.js +69 -16
  9. package/dist/esm/index108.js +40 -8
  10. package/dist/esm/index109.js +75 -13
  11. package/dist/esm/index110.js +31 -7
  12. package/dist/esm/index111.js +6 -9
  13. package/dist/esm/index112.js +16 -16
  14. package/dist/esm/index113.js +8 -12
  15. package/dist/esm/index114.js +13 -46
  16. package/dist/esm/index115.js +7 -13
  17. package/dist/esm/index116.js +9 -16
  18. package/dist/esm/index117.js +16 -13
  19. package/dist/esm/index118.js +11 -5
  20. package/dist/esm/index119.js +46 -35
  21. package/dist/esm/index120.js +13 -9
  22. package/dist/esm/index121.js +15 -7
  23. package/dist/esm/index122.js +13 -28
  24. package/dist/esm/index123.js +6 -10
  25. package/dist/esm/index124.js +32 -11
  26. package/dist/esm/index125.js +9 -11
  27. package/dist/esm/index126.js +8 -120
  28. package/dist/esm/index127.js +27 -32
  29. package/dist/esm/index128.js +10 -80
  30. package/dist/esm/index129.js +13 -176
  31. package/dist/esm/index130.js +11 -44
  32. package/dist/esm/index131.js +120 -6
  33. package/dist/esm/index132.js +30 -151
  34. package/dist/esm/index133.js +80 -14
  35. package/dist/esm/index134.js +177 -14
  36. package/dist/esm/index135.js +42 -97
  37. package/dist/esm/index136.js +6 -72
  38. package/dist/esm/index137.js +153 -86
  39. package/dist/esm/index138.js +14 -148
  40. package/dist/esm/index139.js +14 -136
  41. package/dist/esm/index140.js +94 -63
  42. package/dist/esm/index141.js +72 -23
  43. package/dist/esm/index142.js +83 -154
  44. package/dist/esm/index143.js +148 -6
  45. package/dist/esm/index144.js +136 -11
  46. package/dist/esm/index145.js +68 -19
  47. package/dist/esm/index146.js +23 -135
  48. package/dist/esm/index147.js +155 -75
  49. package/dist/esm/index148.js +6 -9
  50. package/dist/esm/index149.js +11 -28
  51. package/dist/esm/index150.js +17 -87
  52. package/dist/esm/index151.js +135 -350
  53. package/dist/esm/index152.js +79 -3
  54. package/dist/esm/index153.js +10 -5
  55. package/dist/esm/index154.js +29 -2
  56. package/dist/esm/index155.js +90 -3
  57. package/dist/esm/index156.js +351 -9
  58. package/dist/esm/index157.js +3 -327
  59. package/dist/esm/index158.js +5 -14
  60. package/dist/esm/index159.js +2 -5
  61. package/dist/esm/index160.js +3 -56
  62. package/dist/esm/index161.js +9 -13
  63. package/dist/esm/index162.js +327 -2
  64. package/dist/esm/index163.js +13 -7
  65. package/dist/esm/index164.js +4 -30
  66. package/dist/esm/index165.js +29 -188
  67. package/dist/esm/index166.js +13 -32
  68. package/dist/esm/index167.js +2 -22
  69. package/dist/esm/index168.js +7 -5
  70. package/dist/esm/index169.js +25 -68
  71. package/dist/esm/index170.js +214 -5
  72. package/dist/esm/index171.js +32 -6
  73. package/dist/esm/index172.js +20 -34
  74. package/dist/esm/index173.js +5 -119
  75. package/dist/esm/index174.js +74 -3
  76. package/dist/esm/index175.js +5 -18
  77. package/dist/esm/index176.js +5 -26
  78. package/dist/esm/index177.js +28 -26
  79. package/dist/esm/index178.js +105 -20
  80. package/dist/esm/index179.js +3 -24
  81. package/dist/esm/index180.js +17 -7
  82. package/dist/esm/index181.js +18 -185
  83. package/dist/esm/index182.js +34 -2
  84. package/dist/esm/index183.js +28 -461
  85. package/dist/esm/index184.js +16 -20
  86. package/dist/esm/index185.js +6 -158
  87. package/dist/esm/index186.js +193 -21
  88. package/dist/esm/index187.js +2 -128
  89. package/dist/esm/index188.js +467 -38
  90. package/dist/esm/index189.js +27 -6
  91. package/dist/esm/index190.js +160 -27
  92. package/dist/esm/index191.js +20 -54
  93. package/dist/esm/index192.js +126 -44
  94. package/dist/esm/index193.js +31 -184
  95. package/dist/esm/index194.js +7 -4
  96. package/dist/esm/index195.js +26 -72
  97. package/dist/esm/index196.js +52 -17
  98. package/dist/esm/index197.js +46 -3
  99. package/dist/esm/index198.js +188 -13
  100. package/dist/esm/index199.js +4 -24
  101. package/dist/esm/index200.js +73 -11
  102. package/dist/esm/index201.js +18 -16
  103. package/dist/esm/index202.js +3 -35
  104. package/dist/esm/index203.js +17 -3
  105. package/dist/esm/index204.js +23 -18
  106. package/dist/esm/index205.js +11 -27
  107. package/dist/esm/index206.js +17 -34
  108. package/dist/esm/index207.js +34 -8
  109. package/dist/esm/index208.js +3 -8
  110. package/dist/esm/index209.js +18 -25
  111. package/dist/esm/index210.js +26 -27
  112. package/dist/esm/index211.js +35 -3
  113. package/dist/esm/index212.js +8 -79
  114. package/dist/esm/index213.js +7 -9
  115. package/dist/esm/index214.js +23 -10
  116. package/dist/esm/index215.js +27 -20
  117. package/dist/esm/index216.js +3 -8
  118. package/dist/esm/index217.js +78 -9
  119. package/dist/esm/index218.js +9 -11
  120. package/dist/esm/index219.js +12 -6
  121. package/dist/esm/index220.js +21 -6
  122. package/dist/esm/index221.js +8 -13
  123. package/dist/esm/index222.js +9 -31
  124. package/dist/esm/index223.js +12 -5
  125. package/dist/esm/index224.js +6 -37
  126. package/dist/esm/index225.js +6 -110
  127. package/dist/esm/index226.js +12 -47
  128. package/dist/esm/index227.js +31 -31
  129. package/dist/esm/index228.js +5 -18
  130. package/dist/esm/index229.js +35 -17
  131. package/dist/esm/index230.js +108 -40
  132. package/dist/esm/index231.js +46 -40
  133. package/dist/esm/index232.js +32 -8
  134. package/dist/esm/index233.js +17 -7
  135. package/dist/esm/index234.js +19 -16
  136. package/dist/esm/index235.js +42 -22
  137. package/dist/esm/index236.js +40 -22
  138. package/dist/esm/index237.js +8 -16
  139. package/dist/esm/index238.js +7 -54
  140. package/dist/esm/index239.js +16 -27
  141. package/dist/esm/index240.js +22 -24
  142. package/dist/esm/index241.js +24 -104
  143. package/dist/esm/index242.js +17 -3
  144. package/dist/esm/index243.js +54 -5
  145. package/dist/esm/index244.js +26 -30
  146. package/dist/esm/index245.js +24 -20
  147. package/dist/esm/index246.js +104 -3
  148. package/dist/esm/index247.js +3 -18
  149. package/dist/esm/index248.js +5 -5
  150. package/dist/esm/index249.js +31 -8
  151. package/dist/esm/index250.js +19 -102
  152. package/dist/esm/index251.js +3 -64
  153. package/dist/esm/index252.js +17 -5
  154. package/dist/esm/index253.js +5 -6
  155. package/dist/esm/index254.js +8 -27
  156. package/dist/esm/index255.js +103 -33
  157. package/dist/esm/index256.js +64 -13
  158. package/dist/esm/index257.js +5 -16
  159. package/dist/esm/index258.js +6 -78
  160. package/dist/esm/index259.js +28 -2
  161. package/dist/esm/index260.js +33 -14
  162. package/dist/esm/index261.js +13 -18
  163. package/dist/esm/index262.js +16 -171
  164. package/dist/esm/index263.js +77 -16
  165. package/dist/esm/index264.js +2 -11
  166. package/dist/esm/index265.js +15 -10
  167. package/dist/esm/index266.js +18 -38
  168. package/dist/esm/index267.js +172 -2
  169. package/dist/esm/index268.js +17 -69
  170. package/dist/esm/index269.js +10 -34
  171. package/dist/esm/index270.js +10 -15
  172. package/dist/esm/index271.js +2 -41
  173. package/dist/esm/index272.js +41 -2
  174. package/dist/esm/index273.js +2 -5
  175. package/dist/esm/index274.js +4 -10
  176. package/dist/esm/index275.js +9 -18
  177. package/dist/esm/index276.js +19 -7
  178. package/dist/esm/index277.js +7 -11
  179. package/dist/esm/index278.js +11 -72
  180. package/dist/esm/index279.js +71 -64
  181. package/dist/esm/index280.js +60 -182
  182. package/dist/esm/index281.js +185 -20
  183. package/dist/esm/index282.js +21 -41
  184. package/dist/esm/index283.js +41 -24
  185. package/dist/esm/index284.js +24 -89
  186. package/dist/esm/index285.js +68 -18
  187. package/dist/esm/index286.js +34 -10
  188. package/dist/esm/index287.js +10 -7
  189. package/dist/esm/index288.js +13 -7
  190. package/dist/esm/index289.js +7 -6
  191. package/dist/esm/index290.js +6 -36
  192. package/dist/esm/index291.js +35 -14
  193. package/dist/esm/index292.js +15 -8
  194. package/dist/esm/index293.js +8 -8
  195. package/dist/esm/index294.js +8 -16
  196. package/dist/esm/index295.js +15 -21
  197. package/dist/esm/index296.js +22 -30
  198. package/dist/esm/index297.js +31 -2
  199. package/dist/esm/index298.js +2 -14
  200. package/dist/esm/index299.js +13 -12
  201. package/dist/esm/index3.js +1 -1
  202. package/dist/esm/index300.js +10 -45
  203. package/dist/esm/index301.js +47 -9
  204. package/dist/esm/index302.js +8 -12
  205. package/dist/esm/index303.js +10 -10
  206. package/dist/esm/index304.js +13 -14
  207. package/dist/esm/index305.js +14 -8
  208. package/dist/esm/index306.js +6 -13
  209. package/dist/esm/index307.js +15 -24
  210. package/dist/esm/index308.js +24 -24
  211. package/dist/esm/index309.js +20 -27
  212. package/dist/esm/index310.js +31 -9
  213. package/dist/esm/index311.js +9 -51
  214. package/dist/esm/index312.js +38 -24
  215. package/dist/esm/index313.js +37 -17
  216. package/dist/esm/index314.js +17 -14
  217. package/dist/esm/index315.js +14 -11
  218. package/dist/esm/index316.js +11 -12
  219. package/dist/esm/index317.js +12 -19
  220. package/dist/esm/index318.js +18 -106
  221. package/dist/esm/index319.js +105 -101
  222. package/dist/esm/index320.js +103 -6
  223. package/dist/esm/index321.js +7 -7
  224. package/dist/esm/index322.js +7 -27
  225. package/dist/esm/index323.js +26 -15
  226. package/dist/esm/index324.js +13 -211
  227. package/dist/esm/index325.js +213 -12
  228. package/dist/esm/index326.js +12 -35
  229. package/dist/esm/index327.js +35 -41
  230. package/dist/esm/index328.js +42 -2
  231. package/dist/esm/index329.js +3 -68
  232. package/dist/esm/index330.js +68 -3
  233. package/dist/esm/index331.js +3 -136
  234. package/dist/esm/index332.js +125 -163
  235. package/dist/esm/index333.js +174 -9
  236. package/dist/esm/index334.js +9 -16
  237. package/dist/esm/index335.js +16 -133
  238. package/dist/esm/index336.js +112 -172
  239. package/dist/esm/index337.js +194 -2
  240. package/dist/esm/index338.js +2 -79
  241. package/dist/esm/index339.js +77 -13
  242. package/dist/esm/index340.js +13 -89
  243. package/dist/esm/index341.js +70 -143
  244. package/dist/esm/index342.js +157 -36
  245. package/dist/esm/index343.js +41 -654
  246. package/dist/esm/index344.js +646 -196
  247. package/dist/esm/index345.js +201 -172
  248. package/dist/esm/index346.js +176 -3
  249. package/dist/esm/index347.js +1 -1
  250. package/dist/esm/index349.js +2 -2
  251. package/dist/esm/index350.js +1 -1
  252. package/dist/esm/index351.js +1 -1
  253. package/dist/esm/index352.js +2 -2
  254. package/dist/esm/index353.js +3 -3
  255. package/dist/esm/index354.js +1 -1
  256. package/dist/esm/index73.js +2 -2
  257. package/dist/esm/index74.js +1 -1
  258. package/dist/esm/index75.js +2 -2
  259. package/dist/esm/index76.js +1 -1
  260. package/dist/esm/index77.js +1 -1
  261. package/dist/esm/index78.js +1 -1
  262. package/dist/esm/index79.js +1 -1
  263. package/dist/esm/index80.js +2 -2
  264. package/dist/esm/index81.js +2 -2
  265. package/dist/esm/index82.js +5 -5
  266. package/dist/esm/index83.js +2 -2
  267. package/dist/esm/index85.js +37 -33
  268. package/dist/esm/index86.js +2 -4
  269. package/dist/esm/index87.js +69 -9
  270. package/dist/esm/index88.js +33 -117
  271. package/dist/esm/index89.js +13 -60
  272. package/dist/esm/index90.js +33 -23
  273. package/dist/esm/index91.js +3 -36
  274. package/dist/esm/index92.js +9 -41
  275. package/dist/esm/index93.js +118 -58
  276. package/dist/esm/index94.js +58 -165
  277. package/dist/esm/index95.js +21 -36
  278. package/dist/esm/index96.js +36 -9
  279. package/dist/esm/index97.js +38 -28
  280. package/dist/esm/index98.js +58 -36
  281. package/dist/esm/index99.js +167 -8
  282. package/package.json +3 -3
@@ -1,208 +1,658 @@
1
- const w = /* @__PURE__ */ BigInt(0), p = /* @__PURE__ */ BigInt(1);
2
- function b(t) {
3
- return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
1
+ import { validateBasic as mt, pippenger as bt, wNAF as vt } from "./index346.js";
2
+ import { Field as Bt, mod as wt, getMinHashLength as xt, mapHashToField as St, FpInvertBatch as Rt, invert as Ot } from "./index325.js";
3
+ import { bytesToNumberBE as $, bitMask as At, validateObject as pt, concatBytes as at, aInRange as W, ensureBytes as F, hexToBytes as dt, isBytes as yt, createHmacDrbg as Tt, abool as _, bytesToHex as lt, inRange as gt, numberToHexUnpadded as nt, numberToBytesBE as Et, memoized as ft } from "./index345.js";
4
+ function ht(m) {
5
+ m.lowS !== void 0 && _("lowS", m.lowS), m.prehash !== void 0 && _("prehash", m.prehash);
4
6
  }
5
- function h(t) {
6
- if (!b(t))
7
- throw new Error("Uint8Array expected");
8
- }
9
- function k(t, n) {
10
- if (typeof n != "boolean")
11
- throw new Error(t + " boolean expected, got " + n);
12
- }
13
- function F(t) {
14
- const n = t.toString(16);
15
- return n.length & 1 ? "0" + n : n;
16
- }
17
- function E(t) {
18
- if (typeof t != "string")
19
- throw new Error("hex string expected, got " + typeof t);
20
- return t === "" ? w : BigInt("0x" + t);
21
- }
22
- const U = (
23
- // @ts-ignore
24
- typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function"
25
- ), S = /* @__PURE__ */ Array.from({ length: 256 }, (t, n) => n.toString(16).padStart(2, "0"));
26
- function x(t) {
27
- if (h(t), U)
28
- return t.toHex();
29
- let n = "";
30
- for (let e = 0; e < t.length; e++)
31
- n += S[t[e]];
32
- return n;
33
- }
34
- const u = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
35
- function m(t) {
36
- if (t >= u._0 && t <= u._9)
37
- return t - u._0;
38
- if (t >= u.A && t <= u.F)
39
- return t - (u.A - 10);
40
- if (t >= u.a && t <= u.f)
41
- return t - (u.a - 10);
42
- }
43
- function B(t) {
44
- if (typeof t != "string")
45
- throw new Error("hex string expected, got " + typeof t);
46
- if (U)
47
- return Uint8Array.fromHex(t);
48
- const n = t.length, e = n / 2;
49
- if (n % 2)
50
- throw new Error("hex string expected, got unpadded hex of length " + n);
51
- const r = new Uint8Array(e);
52
- for (let o = 0, i = 0; o < e; o++, i += 2) {
53
- const a = m(t.charCodeAt(i)), f = m(t.charCodeAt(i + 1));
54
- if (a === void 0 || f === void 0) {
55
- const c = t[i] + t[i + 1];
56
- throw new Error('hex string expected, got non-hex character "' + c + '" at index ' + i);
57
- }
58
- r[o] = a * 16 + f;
59
- }
60
- return r;
61
- }
62
- function O(t) {
63
- return E(x(t));
64
- }
65
- function V(t) {
66
- return h(t), E(x(Uint8Array.from(t).reverse()));
7
+ function Zt(m) {
8
+ const r = mt(m);
9
+ pt(r, {
10
+ a: "field",
11
+ b: "field"
12
+ }, {
13
+ allowInfinityPoint: "boolean",
14
+ allowedPrivateKeyLengths: "array",
15
+ clearCofactor: "function",
16
+ fromBytes: "function",
17
+ isTorsionFree: "function",
18
+ toBytes: "function",
19
+ wrapPrivateKey: "boolean"
20
+ });
21
+ const { endo: t, Fp: b, a: S } = r;
22
+ if (t) {
23
+ if (!b.eql(S, b.ZERO))
24
+ throw new Error("invalid endo: CURVE.a must be 0");
25
+ if (typeof t != "object" || typeof t.beta != "bigint" || typeof t.splitScalar != "function")
26
+ throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
27
+ }
28
+ return Object.freeze({ ...r });
67
29
  }
68
- function T(t, n) {
69
- return B(t.toString(16).padStart(n * 2, "0"));
30
+ class zt extends Error {
31
+ constructor(r = "") {
32
+ super(r);
33
+ }
70
34
  }
71
- function C(t, n) {
72
- return T(t, n).reverse();
35
+ const C = {
36
+ // asn.1 DER encoding utils
37
+ Err: zt,
38
+ // Basic building block is TLV (Tag-Length-Value)
39
+ _tlv: {
40
+ encode: (m, r) => {
41
+ const { Err: t } = C;
42
+ if (m < 0 || m > 256)
43
+ throw new t("tlv.encode: wrong tag");
44
+ if (r.length & 1)
45
+ throw new t("tlv.encode: unpadded data");
46
+ const b = r.length / 2, S = nt(b);
47
+ if (S.length / 2 & 128)
48
+ throw new t("tlv.encode: long form length too big");
49
+ const N = b > 127 ? nt(S.length / 2 | 128) : "";
50
+ return nt(m) + N + S + r;
51
+ },
52
+ // v - value, l - left bytes (unparsed)
53
+ decode(m, r) {
54
+ const { Err: t } = C;
55
+ let b = 0;
56
+ if (m < 0 || m > 256)
57
+ throw new t("tlv.encode: wrong tag");
58
+ if (r.length < 2 || r[b++] !== m)
59
+ throw new t("tlv.decode: wrong tlv");
60
+ const S = r[b++], N = !!(S & 128);
61
+ let A = 0;
62
+ if (!N)
63
+ A = S;
64
+ else {
65
+ const x = S & 127;
66
+ if (!x)
67
+ throw new t("tlv.decode(long): indefinite length not supported");
68
+ if (x > 4)
69
+ throw new t("tlv.decode(long): byte length is too big");
70
+ const L = r.subarray(b, b + x);
71
+ if (L.length !== x)
72
+ throw new t("tlv.decode: length bytes not complete");
73
+ if (L[0] === 0)
74
+ throw new t("tlv.decode(long): zero leftmost byte");
75
+ for (const O of L)
76
+ A = A << 8 | O;
77
+ if (b += x, A < 128)
78
+ throw new t("tlv.decode(long): not minimal encoding");
79
+ }
80
+ const V = r.subarray(b, b + A);
81
+ if (V.length !== A)
82
+ throw new t("tlv.decode: wrong value length");
83
+ return { v: V, l: r.subarray(b + A) };
84
+ }
85
+ },
86
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
87
+ // since we always use positive integers here. It must always be empty:
88
+ // - add zero byte if exists
89
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
90
+ _int: {
91
+ encode(m) {
92
+ const { Err: r } = C;
93
+ if (m < U)
94
+ throw new r("integer: negative integers are not allowed");
95
+ let t = nt(m);
96
+ if (Number.parseInt(t[0], 16) & 8 && (t = "00" + t), t.length & 1)
97
+ throw new r("unexpected DER parsing assertion: unpadded hex");
98
+ return t;
99
+ },
100
+ decode(m) {
101
+ const { Err: r } = C;
102
+ if (m[0] & 128)
103
+ throw new r("invalid signature integer: negative");
104
+ if (m[0] === 0 && !(m[1] & 128))
105
+ throw new r("invalid signature integer: unnecessary leading zero");
106
+ return $(m);
107
+ }
108
+ },
109
+ toSig(m) {
110
+ const { Err: r, _int: t, _tlv: b } = C, S = F("signature", m), { v: N, l: A } = b.decode(48, S);
111
+ if (A.length)
112
+ throw new r("invalid signature: left bytes after parsing");
113
+ const { v: V, l: x } = b.decode(2, N), { v: L, l: O } = b.decode(2, x);
114
+ if (O.length)
115
+ throw new r("invalid signature: left bytes after parsing");
116
+ return { r: t.decode(V), s: t.decode(L) };
117
+ },
118
+ hexFromSig(m) {
119
+ const { _tlv: r, _int: t } = C, b = r.encode(2, t.encode(m.r)), S = r.encode(2, t.encode(m.s)), N = b + S;
120
+ return r.encode(48, N);
121
+ }
122
+ };
123
+ function st(m, r) {
124
+ return lt(Et(m, r));
73
125
  }
74
- function M(t, n, e) {
75
- let r;
76
- if (typeof n == "string")
126
+ const U = BigInt(0), R = BigInt(1);
127
+ BigInt(2);
128
+ const ct = BigInt(3), Nt = BigInt(4);
129
+ function qt(m) {
130
+ const r = Zt(m), { Fp: t } = r, b = Bt(r.n, r.nBitLength), S = r.toBytes || ((w, e, i) => {
131
+ const c = e.toAffine();
132
+ return at(Uint8Array.from([4]), t.toBytes(c.x), t.toBytes(c.y));
133
+ }), N = r.fromBytes || ((w) => {
134
+ const e = w.subarray(1), i = t.fromBytes(e.subarray(0, t.BYTES)), c = t.fromBytes(e.subarray(t.BYTES, 2 * t.BYTES));
135
+ return { x: i, y: c };
136
+ });
137
+ function A(w) {
138
+ const { a: e, b: i } = r, c = t.sqr(w), d = t.mul(c, w);
139
+ return t.add(t.add(d, t.mul(w, e)), i);
140
+ }
141
+ function V(w, e) {
142
+ const i = t.sqr(e), c = A(w);
143
+ return t.eql(i, c);
144
+ }
145
+ if (!V(r.Gx, r.Gy))
146
+ throw new Error("bad curve params: generator point");
147
+ const x = t.mul(t.pow(r.a, ct), Nt), L = t.mul(t.sqr(r.b), BigInt(27));
148
+ if (t.is0(t.add(x, L)))
149
+ throw new Error("bad curve params: a or b");
150
+ function O(w) {
151
+ return gt(w, R, r.n);
152
+ }
153
+ function k(w) {
154
+ const { allowedPrivateKeyLengths: e, nByteLength: i, wrapPrivateKey: c, n: d } = r;
155
+ if (e && typeof w != "bigint") {
156
+ if (yt(w) && (w = lt(w)), typeof w != "string" || !e.includes(w.length))
157
+ throw new Error("invalid private key");
158
+ w = w.padStart(i * 2, "0");
159
+ }
160
+ let y;
77
161
  try {
78
- r = B(n);
79
- } catch (i) {
80
- throw new Error(t + " must be hex string or Uint8Array, cause: " + i);
81
- }
82
- else if (b(n))
83
- r = Uint8Array.from(n);
84
- else
85
- throw new Error(t + " must be hex string or Uint8Array");
86
- const o = r.length;
87
- if (typeof e == "number" && o !== e)
88
- throw new Error(t + " of length " + e + " expected, got " + o);
89
- return r;
90
- }
91
- function H(...t) {
92
- let n = 0;
93
- for (let r = 0; r < t.length; r++) {
94
- const o = t[r];
95
- h(o), n += o.length;
96
- }
97
- const e = new Uint8Array(n);
98
- for (let r = 0, o = 0; r < t.length; r++) {
99
- const i = t[r];
100
- e.set(i, o), o += i.length;
101
- }
102
- return e;
103
- }
104
- const y = (t) => typeof t == "bigint" && w <= t;
105
- function I(t, n, e) {
106
- return y(t) && y(n) && y(e) && n <= t && t < e;
107
- }
108
- function R(t, n, e, r) {
109
- if (!I(n, e, r))
110
- throw new Error("expected valid " + t + ": " + e + " <= n < " + r + ", got " + n);
111
- }
112
- function j(t) {
113
- let n;
114
- for (n = 0; t > w; t >>= p, n += 1)
115
- ;
116
- return n;
117
- }
118
- const z = (t) => (p << BigInt(t)) - p, d = (t) => new Uint8Array(t), A = (t) => Uint8Array.from(t);
119
- function D(t, n, e) {
120
- if (typeof t != "number" || t < 2)
121
- throw new Error("hashLen must be a number");
122
- if (typeof n != "number" || n < 2)
123
- throw new Error("qByteLen must be a number");
124
- if (typeof e != "function")
125
- throw new Error("hmacFn must be a function");
126
- let r = d(t), o = d(t), i = 0;
127
- const a = () => {
128
- r.fill(1), o.fill(0), i = 0;
129
- }, f = (...s) => e(o, r, ...s), c = (s = d(0)) => {
130
- o = f(A([0]), s), r = f(), s.length !== 0 && (o = f(A([1]), s), r = f());
131
- }, v = () => {
132
- if (i++ >= 1e3)
133
- throw new Error("drbg: tried 1000 values");
134
- let s = 0;
135
- const l = [];
136
- for (; s < n; ) {
137
- r = f();
138
- const g = r.slice();
139
- l.push(g), s += r.length;
140
- }
141
- return H(...l);
142
- };
143
- return (s, l) => {
144
- a(), c(s);
145
- let g;
146
- for (; !(g = l(v())); )
147
- c();
148
- return a(), g;
162
+ y = typeof w == "bigint" ? w : $(F("private key", w, i));
163
+ } catch {
164
+ throw new Error("invalid private key, expected hex or " + i + " bytes, got " + typeof w);
165
+ }
166
+ return c && (y = wt(y, d)), W("private key", y, R, d), y;
167
+ }
168
+ function tt(w) {
169
+ if (!(w instanceof g))
170
+ throw new Error("ProjectivePoint expected");
171
+ }
172
+ const rt = ft((w, e) => {
173
+ const { px: i, py: c, pz: d } = w;
174
+ if (t.eql(d, t.ONE))
175
+ return { x: i, y: c };
176
+ const y = w.is0();
177
+ e == null && (e = y ? t.ONE : t.inv(d));
178
+ const v = t.mul(i, e), E = t.mul(c, e), a = t.mul(d, e);
179
+ if (y)
180
+ return { x: t.ZERO, y: t.ZERO };
181
+ if (!t.eql(a, t.ONE))
182
+ throw new Error("invZ was invalid");
183
+ return { x: v, y: E };
184
+ }), G = ft((w) => {
185
+ if (w.is0()) {
186
+ if (r.allowInfinityPoint && !t.is0(w.py))
187
+ return;
188
+ throw new Error("bad point: ZERO");
189
+ }
190
+ const { x: e, y: i } = w.toAffine();
191
+ if (!t.isValid(e) || !t.isValid(i))
192
+ throw new Error("bad point: x or y not FE");
193
+ if (!V(e, i))
194
+ throw new Error("bad point: equation left != right");
195
+ if (!w.isTorsionFree())
196
+ throw new Error("bad point: not in prime-order subgroup");
197
+ return !0;
198
+ });
199
+ class g {
200
+ constructor(e, i, c) {
201
+ if (e == null || !t.isValid(e))
202
+ throw new Error("x required");
203
+ if (i == null || !t.isValid(i) || t.is0(i))
204
+ throw new Error("y required");
205
+ if (c == null || !t.isValid(c))
206
+ throw new Error("z required");
207
+ this.px = e, this.py = i, this.pz = c, Object.freeze(this);
208
+ }
209
+ // Does not validate if the point is on-curve.
210
+ // Use fromHex instead, or call assertValidity() later.
211
+ static fromAffine(e) {
212
+ const { x: i, y: c } = e || {};
213
+ if (!e || !t.isValid(i) || !t.isValid(c))
214
+ throw new Error("invalid affine point");
215
+ if (e instanceof g)
216
+ throw new Error("projective point not allowed");
217
+ const d = (y) => t.eql(y, t.ZERO);
218
+ return d(i) && d(c) ? g.ZERO : new g(i, c, t.ONE);
219
+ }
220
+ get x() {
221
+ return this.toAffine().x;
222
+ }
223
+ get y() {
224
+ return this.toAffine().y;
225
+ }
226
+ /**
227
+ * Takes a bunch of Projective Points but executes only one
228
+ * inversion on all of them. Inversion is very slow operation,
229
+ * so this improves performance massively.
230
+ * Optimization: converts a list of projective points to a list of identical points with Z=1.
231
+ */
232
+ static normalizeZ(e) {
233
+ const i = Rt(t, e.map((c) => c.pz));
234
+ return e.map((c, d) => c.toAffine(i[d])).map(g.fromAffine);
235
+ }
236
+ /**
237
+ * Converts hash string or Uint8Array to Point.
238
+ * @param hex short/long ECDSA hex
239
+ */
240
+ static fromHex(e) {
241
+ const i = g.fromAffine(N(F("pointHex", e)));
242
+ return i.assertValidity(), i;
243
+ }
244
+ // Multiplies generator point by privateKey.
245
+ static fromPrivateKey(e) {
246
+ return g.BASE.multiply(k(e));
247
+ }
248
+ // Multiscalar Multiplication
249
+ static msm(e, i) {
250
+ return bt(g, b, e, i);
251
+ }
252
+ // "Private method", don't use it directly
253
+ _setWindowSize(e) {
254
+ j.setWindowSize(this, e);
255
+ }
256
+ // A point on curve is valid if it conforms to equation.
257
+ assertValidity() {
258
+ G(this);
259
+ }
260
+ hasEvenY() {
261
+ const { y: e } = this.toAffine();
262
+ if (t.isOdd)
263
+ return !t.isOdd(e);
264
+ throw new Error("Field doesn't support isOdd");
265
+ }
266
+ /**
267
+ * Compare one point to another.
268
+ */
269
+ equals(e) {
270
+ tt(e);
271
+ const { px: i, py: c, pz: d } = this, { px: y, py: v, pz: E } = e, a = t.eql(t.mul(i, E), t.mul(y, d)), p = t.eql(t.mul(c, E), t.mul(v, d));
272
+ return a && p;
273
+ }
274
+ /**
275
+ * Flips point to one corresponding to (x, -y) in Affine coordinates.
276
+ */
277
+ negate() {
278
+ return new g(this.px, t.neg(this.py), this.pz);
279
+ }
280
+ // Renes-Costello-Batina exception-free doubling formula.
281
+ // There is 30% faster Jacobian formula, but it is not complete.
282
+ // https://eprint.iacr.org/2015/1060, algorithm 3
283
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
284
+ double() {
285
+ const { a: e, b: i } = r, c = t.mul(i, ct), { px: d, py: y, pz: v } = this;
286
+ let E = t.ZERO, a = t.ZERO, p = t.ZERO, l = t.mul(d, d), T = t.mul(y, y), o = t.mul(v, v), n = t.mul(d, y);
287
+ return n = t.add(n, n), p = t.mul(d, v), p = t.add(p, p), E = t.mul(e, p), a = t.mul(c, o), a = t.add(E, a), E = t.sub(T, a), a = t.add(T, a), a = t.mul(E, a), E = t.mul(n, E), p = t.mul(c, p), o = t.mul(e, o), n = t.sub(l, o), n = t.mul(e, n), n = t.add(n, p), p = t.add(l, l), l = t.add(p, l), l = t.add(l, o), l = t.mul(l, n), a = t.add(a, l), o = t.mul(y, v), o = t.add(o, o), l = t.mul(o, n), E = t.sub(E, l), p = t.mul(o, T), p = t.add(p, p), p = t.add(p, p), new g(E, a, p);
288
+ }
289
+ // Renes-Costello-Batina exception-free addition formula.
290
+ // There is 30% faster Jacobian formula, but it is not complete.
291
+ // https://eprint.iacr.org/2015/1060, algorithm 1
292
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
293
+ add(e) {
294
+ tt(e);
295
+ const { px: i, py: c, pz: d } = this, { px: y, py: v, pz: E } = e;
296
+ let a = t.ZERO, p = t.ZERO, l = t.ZERO;
297
+ const T = r.a, o = t.mul(r.b, ct);
298
+ let n = t.mul(i, y), s = t.mul(c, v), h = t.mul(d, E), u = t.add(i, c), f = t.add(y, v);
299
+ u = t.mul(u, f), f = t.add(n, s), u = t.sub(u, f), f = t.add(i, d);
300
+ let B = t.add(y, E);
301
+ return f = t.mul(f, B), B = t.add(n, h), f = t.sub(f, B), B = t.add(c, d), a = t.add(v, E), B = t.mul(B, a), a = t.add(s, h), B = t.sub(B, a), l = t.mul(T, f), a = t.mul(o, h), l = t.add(a, l), a = t.sub(s, l), l = t.add(s, l), p = t.mul(a, l), s = t.add(n, n), s = t.add(s, n), h = t.mul(T, h), f = t.mul(o, f), s = t.add(s, h), h = t.sub(n, h), h = t.mul(T, h), f = t.add(f, h), n = t.mul(s, f), p = t.add(p, n), n = t.mul(B, f), a = t.mul(u, a), a = t.sub(a, n), n = t.mul(u, s), l = t.mul(B, l), l = t.add(l, n), new g(a, p, l);
302
+ }
303
+ subtract(e) {
304
+ return this.add(e.negate());
305
+ }
306
+ is0() {
307
+ return this.equals(g.ZERO);
308
+ }
309
+ wNAF(e) {
310
+ return j.wNAFCached(this, e, g.normalizeZ);
311
+ }
312
+ /**
313
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
314
+ * It's faster, but should only be used when you don't care about
315
+ * an exposed private key e.g. sig verification, which works over *public* keys.
316
+ */
317
+ multiplyUnsafe(e) {
318
+ const { endo: i, n: c } = r;
319
+ W("scalar", e, U, c);
320
+ const d = g.ZERO;
321
+ if (e === U)
322
+ return d;
323
+ if (this.is0() || e === R)
324
+ return this;
325
+ if (!i || j.hasPrecomputes(this))
326
+ return j.wNAFCachedUnsafe(this, e, g.normalizeZ);
327
+ let { k1neg: y, k1: v, k2neg: E, k2: a } = i.splitScalar(e), p = d, l = d, T = this;
328
+ for (; v > U || a > U; )
329
+ v & R && (p = p.add(T)), a & R && (l = l.add(T)), T = T.double(), v >>= R, a >>= R;
330
+ return y && (p = p.negate()), E && (l = l.negate()), l = new g(t.mul(l.px, i.beta), l.py, l.pz), p.add(l);
331
+ }
332
+ /**
333
+ * Constant time multiplication.
334
+ * Uses wNAF method. Windowed method may be 10% faster,
335
+ * but takes 2x longer to generate and consumes 2x memory.
336
+ * Uses precomputes when available.
337
+ * Uses endomorphism for Koblitz curves.
338
+ * @param scalar by which the point would be multiplied
339
+ * @returns New point
340
+ */
341
+ multiply(e) {
342
+ const { endo: i, n: c } = r;
343
+ W("scalar", e, R, c);
344
+ let d, y;
345
+ if (i) {
346
+ const { k1neg: v, k1: E, k2neg: a, k2: p } = i.splitScalar(e);
347
+ let { p: l, f: T } = this.wNAF(E), { p: o, f: n } = this.wNAF(p);
348
+ l = j.constTimeNegate(v, l), o = j.constTimeNegate(a, o), o = new g(t.mul(o.px, i.beta), o.py, o.pz), d = l.add(o), y = T.add(n);
349
+ } else {
350
+ const { p: v, f: E } = this.wNAF(e);
351
+ d = v, y = E;
352
+ }
353
+ return g.normalizeZ([d, y])[0];
354
+ }
355
+ /**
356
+ * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
357
+ * Not using Strauss-Shamir trick: precomputation tables are faster.
358
+ * The trick could be useful if both P and Q are not G (not in our case).
359
+ * @returns non-zero affine point
360
+ */
361
+ multiplyAndAddUnsafe(e, i, c) {
362
+ const d = g.BASE, y = (E, a) => a === U || a === R || !E.equals(d) ? E.multiplyUnsafe(a) : E.multiply(a), v = y(this, i).add(y(e, c));
363
+ return v.is0() ? void 0 : v;
364
+ }
365
+ // Converts Projective point to affine (x, y) coordinates.
366
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
367
+ // (x, y, z) ∋ (x=x/z, y=y/z)
368
+ toAffine(e) {
369
+ return rt(this, e);
370
+ }
371
+ isTorsionFree() {
372
+ const { h: e, isTorsionFree: i } = r;
373
+ if (e === R)
374
+ return !0;
375
+ if (i)
376
+ return i(g, this);
377
+ throw new Error("isTorsionFree() has not been declared for the elliptic curve");
378
+ }
379
+ clearCofactor() {
380
+ const { h: e, clearCofactor: i } = r;
381
+ return e === R ? this : i ? i(g, this) : this.multiplyUnsafe(r.h);
382
+ }
383
+ toRawBytes(e = !0) {
384
+ return _("isCompressed", e), this.assertValidity(), S(g, this, e);
385
+ }
386
+ toHex(e = !0) {
387
+ return _("isCompressed", e), lt(this.toRawBytes(e));
388
+ }
389
+ }
390
+ g.BASE = new g(r.Gx, r.Gy, t.ONE), g.ZERO = new g(t.ZERO, t.ONE, t.ZERO);
391
+ const { endo: et, nBitLength: q } = r, j = vt(g, et ? Math.ceil(q / 2) : q);
392
+ return {
393
+ CURVE: r,
394
+ ProjectivePoint: g,
395
+ normPrivateKeyToScalar: k,
396
+ weierstrassEquation: A,
397
+ isWithinCurveOrder: O
149
398
  };
150
399
  }
151
- const _ = {
152
- bigint: (t) => typeof t == "bigint",
153
- function: (t) => typeof t == "function",
154
- boolean: (t) => typeof t == "boolean",
155
- string: (t) => typeof t == "string",
156
- stringOrUint8Array: (t) => typeof t == "string" || b(t),
157
- isSafeInteger: (t) => Number.isSafeInteger(t),
158
- array: (t) => Array.isArray(t),
159
- field: (t, n) => n.Fp.isValid(t),
160
- hash: (t) => typeof t == "function" && Number.isSafeInteger(t.outputLen)
161
- };
162
- function P(t, n, e = {}) {
163
- const r = (o, i, a) => {
164
- const f = _[i];
165
- if (typeof f != "function")
166
- throw new Error("invalid validator function");
167
- const c = t[o];
168
- if (!(a && c === void 0) && !f(c, t))
169
- throw new Error("param " + String(o) + " is invalid. Expected " + i + ", got " + c);
170
- };
171
- for (const [o, i] of Object.entries(n))
172
- r(o, i, !1);
173
- for (const [o, i] of Object.entries(e))
174
- r(o, i, !0);
175
- return t;
400
+ function Ft(m) {
401
+ const r = mt(m);
402
+ return pt(r, {
403
+ hash: "hash",
404
+ hmac: "function",
405
+ randomBytes: "function"
406
+ }, {
407
+ bits2int: "function",
408
+ bits2int_modN: "function",
409
+ lowS: "boolean"
410
+ }), Object.freeze({ lowS: !0, ...r });
176
411
  }
177
- function W(t) {
178
- const n = /* @__PURE__ */ new WeakMap();
179
- return (e, ...r) => {
180
- const o = n.get(e);
181
- if (o !== void 0)
182
- return o;
183
- const i = t(e, ...r);
184
- return n.set(e, i), i;
412
+ function Ht(m) {
413
+ const r = Ft(m), { Fp: t, n: b, nByteLength: S, nBitLength: N } = r, A = t.BYTES + 1, V = 2 * t.BYTES + 1;
414
+ function x(o) {
415
+ return wt(o, b);
416
+ }
417
+ function L(o) {
418
+ return Ot(o, b);
419
+ }
420
+ const { ProjectivePoint: O, normPrivateKeyToScalar: k, weierstrassEquation: tt, isWithinCurveOrder: rt } = qt({
421
+ ...r,
422
+ toBytes(o, n, s) {
423
+ const h = n.toAffine(), u = t.toBytes(h.x), f = at;
424
+ return _("isCompressed", s), s ? f(Uint8Array.from([n.hasEvenY() ? 2 : 3]), u) : f(Uint8Array.from([4]), u, t.toBytes(h.y));
425
+ },
426
+ fromBytes(o) {
427
+ const n = o.length, s = o[0], h = o.subarray(1);
428
+ if (n === A && (s === 2 || s === 3)) {
429
+ const u = $(h);
430
+ if (!gt(u, R, t.ORDER))
431
+ throw new Error("Point is not on curve");
432
+ const f = tt(u);
433
+ let B;
434
+ try {
435
+ B = t.sqrt(f);
436
+ } catch (Y) {
437
+ const z = Y instanceof Error ? ": " + Y.message : "";
438
+ throw new Error("Point is not on curve" + z);
439
+ }
440
+ const Z = (B & R) === R;
441
+ return (s & 1) === 1 !== Z && (B = t.neg(B)), { x: u, y: B };
442
+ } else if (n === V && s === 4) {
443
+ const u = t.fromBytes(h.subarray(0, t.BYTES)), f = t.fromBytes(h.subarray(t.BYTES, 2 * t.BYTES));
444
+ return { x: u, y: f };
445
+ } else {
446
+ const u = A, f = V;
447
+ throw new Error("invalid Point, expected length of " + u + ", or uncompressed " + f + ", got " + n);
448
+ }
449
+ }
450
+ });
451
+ function G(o) {
452
+ const n = b >> R;
453
+ return o > n;
454
+ }
455
+ function g(o) {
456
+ return G(o) ? x(-o) : o;
457
+ }
458
+ const et = (o, n, s) => $(o.slice(n, s));
459
+ class q {
460
+ constructor(n, s, h) {
461
+ W("r", n, R, b), W("s", s, R, b), this.r = n, this.s = s, h != null && (this.recovery = h), Object.freeze(this);
462
+ }
463
+ // pair (bytes of r, bytes of s)
464
+ static fromCompact(n) {
465
+ const s = S;
466
+ return n = F("compactSignature", n, s * 2), new q(et(n, 0, s), et(n, s, 2 * s));
467
+ }
468
+ // DER encoded ECDSA signature
469
+ // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
470
+ static fromDER(n) {
471
+ const { r: s, s: h } = C.toSig(F("DER", n));
472
+ return new q(s, h);
473
+ }
474
+ /**
475
+ * @todo remove
476
+ * @deprecated
477
+ */
478
+ assertValidity() {
479
+ }
480
+ addRecoveryBit(n) {
481
+ return new q(this.r, this.s, n);
482
+ }
483
+ recoverPublicKey(n) {
484
+ const { r: s, s: h, recovery: u } = this, f = d(F("msgHash", n));
485
+ if (u == null || ![0, 1, 2, 3].includes(u))
486
+ throw new Error("recovery id invalid");
487
+ const B = u === 2 || u === 3 ? s + r.n : s;
488
+ if (B >= t.ORDER)
489
+ throw new Error("recovery id 2 or 3 invalid");
490
+ const Z = (u & 1) === 0 ? "02" : "03", H = O.fromHex(Z + st(B, t.BYTES)), Y = L(B), z = x(-f * Y), P = x(h * Y), I = O.BASE.multiplyAndAddUnsafe(H, z, P);
491
+ if (!I)
492
+ throw new Error("point at infinify");
493
+ return I.assertValidity(), I;
494
+ }
495
+ // Signatures should be low-s, to prevent malleability.
496
+ hasHighS() {
497
+ return G(this.s);
498
+ }
499
+ normalizeS() {
500
+ return this.hasHighS() ? new q(this.r, x(-this.s), this.recovery) : this;
501
+ }
502
+ // DER-encoded
503
+ toDERRawBytes() {
504
+ return dt(this.toDERHex());
505
+ }
506
+ toDERHex() {
507
+ return C.hexFromSig(this);
508
+ }
509
+ // padded bytes of r, then padded bytes of s
510
+ toCompactRawBytes() {
511
+ return dt(this.toCompactHex());
512
+ }
513
+ toCompactHex() {
514
+ const n = S;
515
+ return st(this.r, n) + st(this.s, n);
516
+ }
517
+ }
518
+ const j = {
519
+ isValidPrivateKey(o) {
520
+ try {
521
+ return k(o), !0;
522
+ } catch {
523
+ return !1;
524
+ }
525
+ },
526
+ normPrivateKeyToScalar: k,
527
+ /**
528
+ * Produces cryptographically secure private key from random of size
529
+ * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
530
+ */
531
+ randomPrivateKey: () => {
532
+ const o = xt(r.n);
533
+ return St(r.randomBytes(o), r.n);
534
+ },
535
+ /**
536
+ * Creates precompute table for an arbitrary EC point. Makes point "cached".
537
+ * Allows to massively speed-up `point.multiply(scalar)`.
538
+ * @returns cached point
539
+ * @example
540
+ * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
541
+ * fast.multiply(privKey); // much faster ECDH now
542
+ */
543
+ precompute(o = 8, n = O.BASE) {
544
+ return n._setWindowSize(o), n.multiply(BigInt(3)), n;
545
+ }
546
+ };
547
+ function w(o, n = !0) {
548
+ return O.fromPrivateKey(o).toRawBytes(n);
549
+ }
550
+ function e(o) {
551
+ if (typeof o == "bigint")
552
+ return !1;
553
+ if (o instanceof O)
554
+ return !0;
555
+ const s = F("key", o).length, h = t.BYTES, u = h + 1, f = 2 * h + 1;
556
+ if (!(r.allowedPrivateKeyLengths || S === u))
557
+ return s === u || s === f;
558
+ }
559
+ function i(o, n, s = !0) {
560
+ if (e(o) === !0)
561
+ throw new Error("first arg must be private key");
562
+ if (e(n) === !1)
563
+ throw new Error("second arg must be public key");
564
+ return O.fromHex(n).multiply(k(o)).toRawBytes(s);
565
+ }
566
+ const c = r.bits2int || function(o) {
567
+ if (o.length > 8192)
568
+ throw new Error("input is too large");
569
+ const n = $(o), s = o.length * 8 - N;
570
+ return s > 0 ? n >> BigInt(s) : n;
571
+ }, d = r.bits2int_modN || function(o) {
572
+ return x(c(o));
573
+ }, y = At(N);
574
+ function v(o) {
575
+ return W("num < 2^" + N, o, U, y), Et(o, S);
576
+ }
577
+ function E(o, n, s = a) {
578
+ if (["recovered", "canonical"].some((D) => D in s))
579
+ throw new Error("sign() legacy options not supported");
580
+ const { hash: h, randomBytes: u } = r;
581
+ let { lowS: f, prehash: B, extraEntropy: Z } = s;
582
+ f == null && (f = !0), o = F("msgHash", o), ht(s), B && (o = F("prehashed msgHash", h(o)));
583
+ const H = d(o), Y = k(n), z = [v(Y), v(H)];
584
+ if (Z != null && Z !== !1) {
585
+ const D = Z === !0 ? u(t.BYTES) : Z;
586
+ z.push(F("extraEntropy", D));
587
+ }
588
+ const P = at(...z), I = H;
589
+ function ot(D) {
590
+ const X = c(D);
591
+ if (!rt(X))
592
+ return;
593
+ const it = L(X), Q = O.BASE.multiply(X).toAffine(), K = x(Q.x);
594
+ if (K === U)
595
+ return;
596
+ const J = x(it * x(I + K * Y));
597
+ if (J === U)
598
+ return;
599
+ let M = (Q.x === K ? 0 : 2) | Number(Q.y & R), ut = J;
600
+ return f && G(J) && (ut = g(J), M ^= 1), new q(K, ut, M);
601
+ }
602
+ return { seed: P, k2sig: ot };
603
+ }
604
+ const a = { lowS: r.lowS, prehash: !1 }, p = { lowS: r.lowS, prehash: !1 };
605
+ function l(o, n, s = a) {
606
+ const { seed: h, k2sig: u } = E(o, n, s), f = r;
607
+ return Tt(f.hash.outputLen, f.nByteLength, f.hmac)(h, u);
608
+ }
609
+ O.BASE._setWindowSize(8);
610
+ function T(o, n, s, h = p) {
611
+ const u = o;
612
+ n = F("msgHash", n), s = F("publicKey", s);
613
+ const { lowS: f, prehash: B, format: Z } = h;
614
+ if (ht(h), "strict" in h)
615
+ throw new Error("options.strict was renamed to lowS");
616
+ if (Z !== void 0 && Z !== "compact" && Z !== "der")
617
+ throw new Error("format must be compact or der");
618
+ const H = typeof u == "string" || yt(u), Y = !H && !Z && typeof u == "object" && u !== null && typeof u.r == "bigint" && typeof u.s == "bigint";
619
+ if (!H && !Y)
620
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
621
+ let z, P;
622
+ try {
623
+ if (Y && (z = new q(u.r, u.s)), H) {
624
+ try {
625
+ Z !== "compact" && (z = q.fromDER(u));
626
+ } catch (M) {
627
+ if (!(M instanceof C.Err))
628
+ throw M;
629
+ }
630
+ !z && Z !== "der" && (z = q.fromCompact(u));
631
+ }
632
+ P = O.fromHex(s);
633
+ } catch {
634
+ return !1;
635
+ }
636
+ if (!z || f && z.hasHighS())
637
+ return !1;
638
+ B && (n = r.hash(n));
639
+ const { r: I, s: ot } = z, D = d(n), X = L(ot), it = x(D * X), Q = x(I * X), K = O.BASE.multiplyAndAddUnsafe(P, it, Q)?.toAffine();
640
+ return K ? x(K.x) === I : !1;
641
+ }
642
+ return {
643
+ CURVE: r,
644
+ getPublicKey: w,
645
+ getSharedSecret: i,
646
+ sign: l,
647
+ verify: T,
648
+ ProjectivePoint: O,
649
+ Signature: q,
650
+ utils: j
185
651
  };
186
652
  }
187
653
  export {
188
- R as aInRange,
189
- k as abool,
190
- h as abytes,
191
- j as bitLen,
192
- z as bitMask,
193
- x as bytesToHex,
194
- O as bytesToNumberBE,
195
- V as bytesToNumberLE,
196
- H as concatBytes,
197
- D as createHmacDrbg,
198
- M as ensureBytes,
199
- B as hexToBytes,
200
- E as hexToNumber,
201
- I as inRange,
202
- b as isBytes,
203
- W as memoized,
204
- T as numberToBytesBE,
205
- C as numberToBytesLE,
206
- F as numberToHexUnpadded,
207
- P as validateObject
654
+ C as DER,
655
+ zt as DERErr,
656
+ Ht as weierstrass,
657
+ qt as weierstrassPoints
208
658
  };