@coinbase/cdp-hooks 0.0.76 → 0.0.77

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 (306) hide show
  1. package/dist/esm/index.js +38 -32
  2. package/dist/esm/index10.js +1 -1
  3. package/dist/esm/index100.js +276 -9
  4. package/dist/esm/index101.js +3 -2
  5. package/dist/esm/index102.js +4 -2
  6. package/dist/esm/index103.js +9 -3
  7. package/dist/esm/index104.js +2 -327
  8. package/dist/esm/index105.js +2 -14
  9. package/dist/esm/index106.js +3 -5
  10. package/dist/esm/index107.js +299 -28
  11. package/dist/esm/index108.js +14 -2
  12. package/dist/esm/index109.js +4 -7
  13. package/dist/esm/index11.js +1 -1
  14. package/dist/esm/index110.js +29 -188
  15. package/dist/esm/index111.js +2 -32
  16. package/dist/esm/index112.js +7 -21
  17. package/dist/esm/index113.js +214 -5
  18. package/dist/esm/index114.js +30 -72
  19. package/dist/esm/index115.js +21 -5
  20. package/dist/esm/index116.js +5 -5
  21. package/dist/esm/index117.js +69 -31
  22. package/dist/esm/index118.js +5 -75
  23. package/dist/esm/index119.js +6 -3
  24. package/dist/esm/index12.js +1 -1
  25. package/dist/esm/index120.js +28 -16
  26. package/dist/esm/index121.js +57 -433
  27. package/dist/esm/index122.js +3 -31
  28. package/dist/esm/index123.js +17 -20
  29. package/dist/esm/index124.js +439 -21
  30. package/dist/esm/index125.js +28 -32
  31. package/dist/esm/index126.js +18 -185
  32. package/dist/esm/index127.js +31 -6
  33. package/dist/esm/index128.js +35 -2
  34. package/dist/esm/index129.js +189 -8
  35. package/dist/esm/index13.js +1 -1
  36. package/dist/esm/index130.js +7 -17
  37. package/dist/esm/index131.js +2 -28
  38. package/dist/esm/index132.js +12 -8
  39. package/dist/esm/index133.js +15 -52
  40. package/dist/esm/index134.js +23 -41
  41. package/dist/esm/index135.js +8 -8
  42. package/dist/esm/index136.js +55 -7
  43. package/dist/esm/index137.js +44 -15
  44. package/dist/esm/index138.js +8 -18
  45. package/dist/esm/index139.js +7 -24
  46. package/dist/esm/index14.js +1 -1
  47. package/dist/esm/index140.js +16 -16
  48. package/dist/esm/index141.js +17 -53
  49. package/dist/esm/index142.js +22 -9
  50. package/dist/esm/index143.js +15 -159
  51. package/dist/esm/index144.js +53 -20
  52. package/dist/esm/index145.js +11 -127
  53. package/dist/esm/index146.js +153 -31
  54. package/dist/esm/index147.js +21 -6
  55. package/dist/esm/index148.js +127 -27
  56. package/dist/esm/index149.js +31 -184
  57. package/dist/esm/index15.js +1 -1
  58. package/dist/esm/index150.js +7 -4
  59. package/dist/esm/index151.js +26 -63
  60. package/dist/esm/index152.js +192 -3
  61. package/dist/esm/index153.js +4 -21
  62. package/dist/esm/index154.js +61 -13
  63. package/dist/esm/index155.js +3 -24
  64. package/dist/esm/index156.js +20 -11
  65. package/dist/esm/index157.js +15 -33
  66. package/dist/esm/index158.js +24 -3
  67. package/dist/esm/index159.js +11 -18
  68. package/dist/esm/index16.js +1 -1
  69. package/dist/esm/index160.js +33 -26
  70. package/dist/esm/index161.js +3 -36
  71. package/dist/esm/index162.js +18 -7
  72. package/dist/esm/index163.js +26 -24
  73. package/dist/esm/index164.js +34 -27
  74. package/dist/esm/index165.js +7 -64
  75. package/dist/esm/index166.js +25 -9
  76. package/dist/esm/index167.js +28 -33
  77. package/dist/esm/index168.js +64 -27
  78. package/dist/esm/index169.js +9 -24
  79. package/dist/esm/index17.js +36 -5
  80. package/dist/esm/index170.js +33 -3
  81. package/dist/esm/index171.js +27 -14
  82. package/dist/esm/index172.js +24 -103
  83. package/dist/esm/index173.js +3 -64
  84. package/dist/esm/index174.js +14 -5
  85. package/dist/esm/index175.js +103 -6
  86. package/dist/esm/index176.js +62 -25
  87. package/dist/esm/index177.js +5 -38
  88. package/dist/esm/index178.js +6 -13
  89. package/dist/esm/index179.js +24 -39
  90. package/dist/esm/index18.js +28 -7
  91. package/dist/esm/index180.js +38 -5
  92. package/dist/esm/index181.js +13 -11
  93. package/dist/esm/index182.js +42 -19
  94. package/dist/esm/index183.js +5 -78
  95. package/dist/esm/index184.js +12 -2
  96. package/dist/esm/index185.js +19 -37
  97. package/dist/esm/index186.js +73 -105
  98. package/dist/esm/index187.js +2 -49
  99. package/dist/esm/index188.js +36 -31
  100. package/dist/esm/index189.js +110 -8
  101. package/dist/esm/index19.js +7 -6
  102. package/dist/esm/index190.js +48 -6
  103. package/dist/esm/index191.js +32 -6
  104. package/dist/esm/index192.js +8 -11
  105. package/dist/esm/index193.js +6 -10
  106. package/dist/esm/index194.js +6 -13
  107. package/dist/esm/index195.js +11 -32
  108. package/dist/esm/index196.js +11 -5
  109. package/dist/esm/index197.js +13 -8
  110. package/dist/esm/index198.js +30 -17
  111. package/dist/esm/index199.js +5 -32
  112. package/dist/esm/index2.js +2 -2
  113. package/dist/esm/index20.js +4 -7
  114. package/dist/esm/index200.js +8 -20
  115. package/dist/esm/index201.js +19 -3
  116. package/dist/esm/index202.js +31 -17
  117. package/dist/esm/index203.js +20 -10
  118. package/dist/esm/index204.js +3 -21
  119. package/dist/esm/index205.js +16 -21
  120. package/dist/esm/index206.js +10 -5
  121. package/dist/esm/index207.js +21 -5
  122. package/dist/esm/index208.js +22 -8
  123. package/dist/esm/index209.js +5 -104
  124. package/dist/esm/index21.js +5 -5
  125. package/dist/esm/index210.js +6 -3
  126. package/dist/esm/index211.js +8 -18
  127. package/dist/esm/index212.js +99 -166
  128. package/dist/esm/index213.js +3 -18
  129. package/dist/esm/index214.js +19 -10
  130. package/dist/esm/index215.js +170 -39
  131. package/dist/esm/index216.js +18 -2
  132. package/dist/esm/index217.js +10 -5
  133. package/dist/esm/index218.js +38 -10
  134. package/dist/esm/index219.js +2 -20
  135. package/dist/esm/index22.js +5 -5
  136. package/dist/esm/index220.js +69 -7
  137. package/dist/esm/index221.js +34 -11
  138. package/dist/esm/index222.js +14 -66
  139. package/dist/esm/index223.js +39 -64
  140. package/dist/esm/index224.js +2 -186
  141. package/dist/esm/index225.js +4 -22
  142. package/dist/esm/index226.js +9 -41
  143. package/dist/esm/index227.js +17 -74
  144. package/dist/esm/index228.js +7 -40
  145. package/dist/esm/index229.js +10 -15
  146. package/dist/esm/index23.js +5 -5
  147. package/dist/esm/index230.js +66 -13
  148. package/dist/esm/index231.js +65 -7
  149. package/dist/esm/index232.js +185 -6
  150. package/dist/esm/index233.js +21 -35
  151. package/dist/esm/index234.js +42 -15
  152. package/dist/esm/index235.js +76 -8
  153. package/dist/esm/index236.js +40 -12
  154. package/dist/esm/index237.js +16 -9
  155. package/dist/esm/index238.js +12 -15
  156. package/dist/esm/index239.js +7 -22
  157. package/dist/esm/index24.js +6 -55
  158. package/dist/esm/index240.js +6 -30
  159. package/dist/esm/index241.js +37 -2
  160. package/dist/esm/index242.js +15 -13
  161. package/dist/esm/index243.js +8 -12
  162. package/dist/esm/index244.js +12 -47
  163. package/dist/esm/index245.js +9 -9
  164. package/dist/esm/index246.js +16 -13
  165. package/dist/esm/index247.js +21 -13
  166. package/dist/esm/index248.js +28 -6
  167. package/dist/esm/index249.js +2 -16
  168. package/dist/esm/index25.js +7 -8
  169. package/dist/esm/index250.js +12 -23
  170. package/dist/esm/index251.js +12 -11
  171. package/dist/esm/index252.js +45 -22
  172. package/dist/esm/index253.js +9 -51
  173. package/dist/esm/index254.js +13 -17
  174. package/dist/esm/index255.js +13 -13
  175. package/dist/esm/index256.js +8 -11
  176. package/dist/esm/index257.js +15 -103
  177. package/dist/esm/index258.js +24 -5
  178. package/dist/esm/index259.js +10 -222
  179. package/dist/esm/index26.js +8 -34
  180. package/dist/esm/index260.js +24 -6
  181. package/dist/esm/index261.js +52 -7
  182. package/dist/esm/index262.js +17 -26
  183. package/dist/esm/index263.js +13 -18
  184. package/dist/esm/index264.js +11 -145
  185. package/dist/esm/index265.js +103 -12
  186. package/dist/esm/index266.js +6 -36
  187. package/dist/esm/index267.js +223 -41
  188. package/dist/esm/index268.js +6 -38
  189. package/dist/esm/index269.js +7 -2
  190. package/dist/esm/index27.js +57 -18
  191. package/dist/esm/index270.js +25 -68
  192. package/dist/esm/index271.js +19 -34
  193. package/dist/esm/index272.js +143 -12
  194. package/dist/esm/index273.js +13 -2
  195. package/dist/esm/index274.js +35 -68
  196. package/dist/esm/index275.js +41 -3
  197. package/dist/esm/index276.js +2 -137
  198. package/dist/esm/index277.js +69 -156
  199. package/dist/esm/index278.js +134 -7
  200. package/dist/esm/index279.js +3 -16
  201. package/dist/esm/index28.js +8 -11
  202. package/dist/esm/index280.js +140 -98
  203. package/dist/esm/index281.js +9 -134
  204. package/dist/esm/index282.js +16 -78
  205. package/dist/esm/index283.js +114 -2
  206. package/dist/esm/index284.js +124 -687
  207. package/dist/esm/index285.js +73 -133
  208. package/dist/esm/index286.js +2 -43
  209. package/dist/esm/index287.js +675 -178
  210. package/dist/esm/index288.js +136 -63
  211. package/dist/esm/index289.js +42 -4
  212. package/dist/esm/index29.js +34 -12
  213. package/dist/esm/index290.js +200 -40
  214. package/dist/esm/index291.js +3 -7
  215. package/dist/esm/index292.js +61 -58
  216. package/dist/esm/index293.js +4 -77
  217. package/dist/esm/index294.js +41 -4
  218. package/dist/esm/index295.js +7 -194
  219. package/dist/esm/index296.js +62 -3
  220. package/dist/esm/index297.js +61 -47
  221. package/dist/esm/index298.js +4 -45
  222. package/dist/esm/index299.js +194 -4
  223. package/dist/esm/index3.js +1 -1
  224. package/dist/esm/index30.js +18 -54
  225. package/dist/esm/index300.js +64 -5
  226. package/dist/esm/index301.js +45 -2
  227. package/dist/esm/index302.js +4 -21
  228. package/dist/esm/index303.js +7 -0
  229. package/dist/esm/index304.js +4 -0
  230. package/dist/esm/index305.js +24 -0
  231. package/dist/esm/index31.js +11 -57
  232. package/dist/esm/index32.js +12 -56
  233. package/dist/esm/index33.js +54 -5
  234. package/dist/esm/index34.js +57 -47
  235. package/dist/esm/index35.js +56 -33
  236. package/dist/esm/index36.js +5 -4
  237. package/dist/esm/index37.js +46 -8
  238. package/dist/esm/index38.js +31 -67
  239. package/dist/esm/index39.js +3 -9
  240. package/dist/esm/index40.js +9 -28
  241. package/dist/esm/index41.js +68 -70
  242. package/dist/esm/index42.js +9 -19
  243. package/dist/esm/index43.js +26 -108
  244. package/dist/esm/index44.js +70 -60
  245. package/dist/esm/index45.js +19 -24
  246. package/dist/esm/index46.js +110 -40
  247. package/dist/esm/index47.js +57 -34
  248. package/dist/esm/index48.js +20 -54
  249. package/dist/esm/index49.js +37 -160
  250. package/dist/esm/index5.js +3 -3
  251. package/dist/esm/index50.js +36 -38
  252. package/dist/esm/index51.js +58 -9
  253. package/dist/esm/index52.js +161 -29
  254. package/dist/esm/index53.js +39 -36
  255. package/dist/esm/index54.js +7 -7
  256. package/dist/esm/index55.js +30 -28
  257. package/dist/esm/index56.js +34 -44
  258. package/dist/esm/index57.js +9 -88
  259. package/dist/esm/index58.js +26 -37
  260. package/dist/esm/index59.js +46 -8
  261. package/dist/esm/index6.js +2 -2
  262. package/dist/esm/index60.js +88 -6
  263. package/dist/esm/index61.js +40 -16
  264. package/dist/esm/index62.js +8 -8
  265. package/dist/esm/index63.js +6 -13
  266. package/dist/esm/index64.js +16 -7
  267. package/dist/esm/index65.js +8 -9
  268. package/dist/esm/index66.js +13 -16
  269. package/dist/esm/index67.js +7 -46
  270. package/dist/esm/index68.js +9 -13
  271. package/dist/esm/index69.js +15 -15
  272. package/dist/esm/index7.js +1 -1
  273. package/dist/esm/index70.js +46 -13
  274. package/dist/esm/index71.js +13 -6
  275. package/dist/esm/index72.js +15 -34
  276. package/dist/esm/index73.js +13 -9
  277. package/dist/esm/index74.js +5 -7
  278. package/dist/esm/index75.js +35 -25
  279. package/dist/esm/index76.js +9 -10
  280. package/dist/esm/index77.js +7 -13
  281. package/dist/esm/index78.js +25 -11
  282. package/dist/esm/index79.js +10 -116
  283. package/dist/esm/index8.js +2 -2
  284. package/dist/esm/index80.js +13 -32
  285. package/dist/esm/index81.js +11 -79
  286. package/dist/esm/index82.js +108 -169
  287. package/dist/esm/index83.js +26 -37
  288. package/dist/esm/index84.js +79 -6
  289. package/dist/esm/index85.js +177 -13
  290. package/dist/esm/index86.js +44 -13
  291. package/dist/esm/index87.js +6 -99
  292. package/dist/esm/index88.js +13 -72
  293. package/dist/esm/index89.js +13 -87
  294. package/dist/esm/index9.js +1 -1
  295. package/dist/esm/index90.js +93 -142
  296. package/dist/esm/index91.js +65 -129
  297. package/dist/esm/index92.js +73 -54
  298. package/dist/esm/index93.js +148 -23
  299. package/dist/esm/index94.js +133 -102
  300. package/dist/esm/index95.js +68 -6
  301. package/dist/esm/index96.js +23 -131
  302. package/dist/esm/index97.js +101 -271
  303. package/dist/esm/index98.js +7 -3
  304. package/dist/esm/index99.js +132 -4
  305. package/dist/types/index.d.ts +21 -0
  306. package/package.json +3 -3
@@ -1,203 +1,700 @@
1
- import { bitLen as B, bitMask as z } from "./index285.js";
2
- import { validateField as Z, Field as O, FpInvertBatch as R } from "./index259.js";
3
- const g = BigInt(0), h = BigInt(1);
4
- function b(t, r) {
5
- const e = r.negate();
6
- return t ? e : r;
1
+ import { hmac as dt } from "./index289.js";
2
+ import { _validateObject as at, bitMask as ft, abool as Q, ensureBytes as z, memoized as nt, createHmacDrbg as ht, bytesToNumberBE as ct, numberToHexUnpadded as M, aInRange as mt } from "./index288.js";
3
+ import { _createCurveFields as wt, wNAF as yt, normalizeZ as pt, pippenger as gt, mulEndoUnsafe as Et, negateCt as ot } from "./index290.js";
4
+ import { Field as bt, mapHashToField as vt, getMinHashLength as Bt } from "./index267.js";
5
+ import { concatBytes as I, abytes as it, bytesToHex as rt, hexToBytes as xt, randomBytes as St, isBytes as Rt } from "./index272.js";
6
+ function st(e) {
7
+ e.lowS !== void 0 && Q("lowS", e.lowS), e.prehash !== void 0 && Q("prehash", e.prehash);
7
8
  }
8
- function L(t, r, e) {
9
- const n = (s) => s.pz, i = R(t.Fp, e.map(n));
10
- return e.map((s, f) => s.toAffine(i[f])).map(t.fromAffine);
11
- }
12
- function I(t, r) {
13
- if (!Number.isSafeInteger(t) || t <= 0 || t > r)
14
- throw new Error("invalid window size, expected [1.." + r + "], got W=" + t);
9
+ class Ot extends Error {
10
+ constructor(i = "") {
11
+ super(i);
12
+ }
15
13
  }
16
- function E(t, r) {
17
- I(t, r);
18
- const e = Math.ceil(r / t) + 1, n = 2 ** (t - 1), i = 2 ** t, o = z(t), s = BigInt(t);
19
- return { windows: e, windowSize: n, mask: o, maxNumber: i, shiftBy: s };
14
+ const F = {
15
+ // asn.1 DER encoding utils
16
+ Err: Ot,
17
+ // Basic building block is TLV (Tag-Length-Value)
18
+ _tlv: {
19
+ encode: (e, i) => {
20
+ const { Err: t } = F;
21
+ if (e < 0 || e > 256)
22
+ throw new t("tlv.encode: wrong tag");
23
+ if (i.length & 1)
24
+ throw new t("tlv.encode: unpadded data");
25
+ const w = i.length / 2, p = M(w);
26
+ if (p.length / 2 & 128)
27
+ throw new t("tlv.encode: long form length too big");
28
+ const b = w > 127 ? M(p.length / 2 | 128) : "";
29
+ return M(e) + b + p + i;
30
+ },
31
+ // v - value, l - left bytes (unparsed)
32
+ decode(e, i) {
33
+ const { Err: t } = F;
34
+ let w = 0;
35
+ if (e < 0 || e > 256)
36
+ throw new t("tlv.encode: wrong tag");
37
+ if (i.length < 2 || i[w++] !== e)
38
+ throw new t("tlv.decode: wrong tlv");
39
+ const p = i[w++], b = !!(p & 128);
40
+ let u = 0;
41
+ if (!b)
42
+ u = p;
43
+ else {
44
+ const S = p & 127;
45
+ if (!S)
46
+ throw new t("tlv.decode(long): indefinite length not supported");
47
+ if (S > 4)
48
+ throw new t("tlv.decode(long): byte length is too big");
49
+ const N = i.subarray(w, w + S);
50
+ if (N.length !== S)
51
+ throw new t("tlv.decode: length bytes not complete");
52
+ if (N[0] === 0)
53
+ throw new t("tlv.decode(long): zero leftmost byte");
54
+ for (const q of N)
55
+ u = u << 8 | q;
56
+ if (w += S, u < 128)
57
+ throw new t("tlv.decode(long): not minimal encoding");
58
+ }
59
+ const x = i.subarray(w, w + u);
60
+ if (x.length !== u)
61
+ throw new t("tlv.decode: wrong value length");
62
+ return { v: x, l: i.subarray(w + u) };
63
+ }
64
+ },
65
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
66
+ // since we always use positive integers here. It must always be empty:
67
+ // - add zero byte if exists
68
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
69
+ _int: {
70
+ encode(e) {
71
+ const { Err: i } = F;
72
+ if (e < U)
73
+ throw new i("integer: negative integers are not allowed");
74
+ let t = M(e);
75
+ if (Number.parseInt(t[0], 16) & 8 && (t = "00" + t), t.length & 1)
76
+ throw new i("unexpected DER parsing assertion: unpadded hex");
77
+ return t;
78
+ },
79
+ decode(e) {
80
+ const { Err: i } = F;
81
+ if (e[0] & 128)
82
+ throw new i("invalid signature integer: negative");
83
+ if (e[0] === 0 && !(e[1] & 128))
84
+ throw new i("invalid signature integer: unnecessary leading zero");
85
+ return ct(e);
86
+ }
87
+ },
88
+ toSig(e) {
89
+ const { Err: i, _int: t, _tlv: w } = F, p = z("signature", e), { v: b, l: u } = w.decode(48, p);
90
+ if (u.length)
91
+ throw new i("invalid signature: left bytes after parsing");
92
+ const { v: x, l: S } = w.decode(2, b), { v: N, l: q } = w.decode(2, S);
93
+ if (q.length)
94
+ throw new i("invalid signature: left bytes after parsing");
95
+ return { r: t.decode(x), s: t.decode(N) };
96
+ },
97
+ hexFromSig(e) {
98
+ const { _tlv: i, _int: t } = F, w = i.encode(2, t.encode(e.r)), p = i.encode(2, t.encode(e.s)), b = w + p;
99
+ return i.encode(48, b);
100
+ }
101
+ }, U = BigInt(0), k = BigInt(1), At = BigInt(2), W = BigInt(3), Zt = BigInt(4);
102
+ function Tt(e, i, t) {
103
+ function w(p) {
104
+ const b = e.sqr(p), u = e.mul(b, p);
105
+ return e.add(e.add(u, e.mul(p, i)), t);
106
+ }
107
+ return w;
20
108
  }
21
- function v(t, r, e) {
22
- const { windowSize: n, mask: i, maxNumber: o, shiftBy: s } = e;
23
- let f = Number(t & i), a = t >> s;
24
- f > n && (f -= o, a += h);
25
- const d = r * n, c = d + Math.abs(f) - 1, p = f === 0, l = f < 0, u = r % 2 !== 0;
26
- return { nextN: a, offset: c, isZero: p, isNeg: l, isNegF: u, offsetF: d };
109
+ function lt(e, i, t) {
110
+ const { BYTES: w } = e;
111
+ function p(b) {
112
+ let u;
113
+ if (typeof b == "bigint")
114
+ u = b;
115
+ else {
116
+ let x = z("private key", b);
117
+ if (i) {
118
+ if (!i.includes(x.length * 2))
119
+ throw new Error("invalid private key");
120
+ const S = new Uint8Array(w);
121
+ S.set(x, S.length - x.length), x = S;
122
+ }
123
+ try {
124
+ u = e.fromBytes(x);
125
+ } catch {
126
+ throw new Error(`invalid private key: expected ui8a of size ${w}, got ${typeof b}`);
127
+ }
128
+ }
129
+ if (t && (u = e.create(u)), !e.isValidNot0(u))
130
+ throw new Error("invalid private key: out of range [1..N-1]");
131
+ return u;
132
+ }
133
+ return p;
27
134
  }
28
- function j(t, r) {
29
- if (!Array.isArray(t))
30
- throw new Error("array expected");
31
- t.forEach((e, n) => {
32
- if (!(e instanceof r))
33
- throw new Error("invalid point at index " + n);
135
+ function zt(e, i = {}) {
136
+ const { Fp: t, Fn: w } = wt("weierstrass", e, i), { h: p, n: b } = e;
137
+ at(i, {}, {
138
+ allowInfinityPoint: "boolean",
139
+ clearCofactor: "function",
140
+ isTorsionFree: "function",
141
+ fromBytes: "function",
142
+ toBytes: "function",
143
+ endo: "object",
144
+ wrapPrivateKey: "boolean"
34
145
  });
35
- }
36
- function _(t, r) {
37
- if (!Array.isArray(t))
38
- throw new Error("array of scalars expected");
39
- t.forEach((e, n) => {
40
- if (!r.isValid(e))
41
- throw new Error("invalid scalar at index " + n);
146
+ const { endo: u } = i;
147
+ if (u && (!t.is0(e.a) || typeof u.beta != "bigint" || typeof u.splitScalar != "function"))
148
+ throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
149
+ function x() {
150
+ if (!t.isOdd)
151
+ throw new Error("compression is not supported: Field does not have .isOdd()");
152
+ }
153
+ function S(v, r, s) {
154
+ const { x: n, y: o } = r.toAffine(), a = t.toBytes(n);
155
+ if (Q("isCompressed", s), s) {
156
+ x();
157
+ const d = !t.isOdd(o);
158
+ return I(ut(d), a);
159
+ } else
160
+ return I(Uint8Array.of(4), a, t.toBytes(o));
161
+ }
162
+ function N(v) {
163
+ it(v);
164
+ const r = t.BYTES, s = r + 1, n = 2 * r + 1, o = v.length, a = v[0], d = v.subarray(1);
165
+ if (o === s && (a === 2 || a === 3)) {
166
+ const c = t.fromBytes(d);
167
+ if (!t.isValid(c))
168
+ throw new Error("bad point: is not on curve, wrong x");
169
+ const l = T(c);
170
+ let h;
171
+ try {
172
+ h = t.sqrt(l);
173
+ } catch (g) {
174
+ const m = g instanceof Error ? ": " + g.message : "";
175
+ throw new Error("bad point: is not on curve, sqrt error" + m);
176
+ }
177
+ x();
178
+ const f = t.isOdd(h);
179
+ return (a & 1) === 1 !== f && (h = t.neg(h)), { x: c, y: h };
180
+ } else if (o === n && a === 4) {
181
+ const c = t.fromBytes(d.subarray(r * 0, r * 1)), l = t.fromBytes(d.subarray(r * 1, r * 2));
182
+ if (!L(c, l))
183
+ throw new Error("bad point: is not on curve");
184
+ return { x: c, y: l };
185
+ } else
186
+ throw new Error(`bad point: got length ${o}, expected compressed=${s} or uncompressed=${n}`);
187
+ }
188
+ const q = i.toBytes || S, C = i.fromBytes || N, T = Tt(t, e.a, e.b);
189
+ function L(v, r) {
190
+ const s = t.sqr(r), n = T(v);
191
+ return t.eql(s, n);
192
+ }
193
+ if (!L(e.Gx, e.Gy))
194
+ throw new Error("bad curve params: generator point");
195
+ const J = t.mul(t.pow(e.a, W), Zt), tt = t.mul(t.sqr(e.b), BigInt(27));
196
+ if (t.is0(t.add(J, tt)))
197
+ throw new Error("bad curve params: a or b");
198
+ function K(v, r, s = !1) {
199
+ if (!t.isValid(r) || s && t.is0(r))
200
+ throw new Error(`bad point coordinate ${v}`);
201
+ return r;
202
+ }
203
+ function G(v) {
204
+ if (!(v instanceof y))
205
+ throw new Error("ProjectivePoint expected");
206
+ }
207
+ const X = nt((v, r) => {
208
+ const { px: s, py: n, pz: o } = v;
209
+ if (t.eql(o, t.ONE))
210
+ return { x: s, y: n };
211
+ const a = v.is0();
212
+ r == null && (r = a ? t.ONE : t.inv(o));
213
+ const d = t.mul(s, r), c = t.mul(n, r), l = t.mul(o, r);
214
+ if (a)
215
+ return { x: t.ZERO, y: t.ZERO };
216
+ if (!t.eql(l, t.ONE))
217
+ throw new Error("invZ was invalid");
218
+ return { x: d, y: c };
219
+ }), V = nt((v) => {
220
+ if (v.is0()) {
221
+ if (i.allowInfinityPoint && !t.is0(v.py))
222
+ return;
223
+ throw new Error("bad point: ZERO");
224
+ }
225
+ const { x: r, y: s } = v.toAffine();
226
+ if (!t.isValid(r) || !t.isValid(s))
227
+ throw new Error("bad point: x or y not field elements");
228
+ if (!L(r, s))
229
+ throw new Error("bad point: equation left != right");
230
+ if (!v.isTorsionFree())
231
+ throw new Error("bad point: not in prime-order subgroup");
232
+ return !0;
42
233
  });
43
- }
44
- const N = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap();
45
- function A(t) {
46
- return M.get(t) || 1;
47
- }
48
- function S(t) {
49
- if (t !== g)
50
- throw new Error("invalid wNAF");
51
- }
52
- function U(t, r) {
53
- return {
54
- constTimeNegate: b,
55
- hasPrecomputes(e) {
56
- return A(e) !== 1;
57
- },
58
- // non-const time multiplication ladder
59
- unsafeLadder(e, n, i = t.ZERO) {
60
- let o = e;
61
- for (; n > g; )
62
- n & h && (i = i.add(o)), o = o.double(), n >>= h;
63
- return i;
64
- },
234
+ function $(v, r, s, n, o) {
235
+ return s = new y(t.mul(s.px, v), s.py, s.pz), r = ot(n, r), s = ot(o, s), r.add(s);
236
+ }
237
+ class y {
238
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
239
+ constructor(r, s, n) {
240
+ this.px = K("x", r), this.py = K("y", s, !0), this.pz = K("z", n), Object.freeze(this);
241
+ }
242
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
243
+ static fromAffine(r) {
244
+ const { x: s, y: n } = r || {};
245
+ if (!r || !t.isValid(s) || !t.isValid(n))
246
+ throw new Error("invalid affine point");
247
+ if (r instanceof y)
248
+ throw new Error("projective point not allowed");
249
+ return t.is0(s) && t.is0(n) ? y.ZERO : new y(s, n, t.ONE);
250
+ }
251
+ get x() {
252
+ return this.toAffine().x;
253
+ }
254
+ get y() {
255
+ return this.toAffine().y;
256
+ }
257
+ static normalizeZ(r) {
258
+ return pt(y, "pz", r);
259
+ }
260
+ static fromBytes(r) {
261
+ return it(r), y.fromHex(r);
262
+ }
263
+ /** Converts hash string or Uint8Array to Point. */
264
+ static fromHex(r) {
265
+ const s = y.fromAffine(C(z("pointHex", r)));
266
+ return s.assertValidity(), s;
267
+ }
268
+ /** Multiplies generator point by privateKey. */
269
+ static fromPrivateKey(r) {
270
+ const s = lt(w, i.allowedPrivateKeyLengths, i.wrapPrivateKey);
271
+ return y.BASE.multiply(s(r));
272
+ }
273
+ /** Multiscalar Multiplication */
274
+ static msm(r, s) {
275
+ return gt(y, w, r, s);
276
+ }
65
277
  /**
66
- * Creates a wNAF precomputation window. Used for caching.
67
- * Default window size is set by `utils.precompute()` and is equal to 8.
68
- * Number of precomputed points depends on the curve size:
69
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
70
- * - 𝑊 is the window size
71
- * - 𝑛 is the bitlength of the curve order.
72
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
73
- * @param elm Point instance
74
- * @param W window size
75
- * @returns precomputed point tables flattened to a single array
278
+ *
279
+ * @param windowSize
280
+ * @param isLazy true will defer table computation until the first multiplication
281
+ * @returns
76
282
  */
77
- precomputeWindow(e, n) {
78
- const { windows: i, windowSize: o } = E(n, r), s = [];
79
- let f = e, a = f;
80
- for (let d = 0; d < i; d++) {
81
- a = f, s.push(a);
82
- for (let c = 1; c < o; c++)
83
- a = a.add(f), s.push(a);
84
- f = a.double();
85
- }
86
- return s;
87
- },
283
+ precompute(r = 8, s = !0) {
284
+ return _.setWindowSize(this, r), s || this.multiply(W), this;
285
+ }
286
+ /** "Private method", don't use it directly */
287
+ _setWindowSize(r) {
288
+ this.precompute(r);
289
+ }
290
+ // TODO: return `this`
291
+ /** A point on curve is valid if it conforms to equation. */
292
+ assertValidity() {
293
+ V(this);
294
+ }
295
+ hasEvenY() {
296
+ const { y: r } = this.toAffine();
297
+ if (!t.isOdd)
298
+ throw new Error("Field doesn't support isOdd");
299
+ return !t.isOdd(r);
300
+ }
301
+ /** Compare one point to another. */
302
+ equals(r) {
303
+ G(r);
304
+ const { px: s, py: n, pz: o } = this, { px: a, py: d, pz: c } = r, l = t.eql(t.mul(s, c), t.mul(a, o)), h = t.eql(t.mul(n, c), t.mul(d, o));
305
+ return l && h;
306
+ }
307
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
308
+ negate() {
309
+ return new y(this.px, t.neg(this.py), this.pz);
310
+ }
311
+ // Renes-Costello-Batina exception-free doubling formula.
312
+ // There is 30% faster Jacobian formula, but it is not complete.
313
+ // https://eprint.iacr.org/2015/1060, algorithm 3
314
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
315
+ double() {
316
+ const { a: r, b: s } = e, n = t.mul(s, W), { px: o, py: a, pz: d } = this;
317
+ let c = t.ZERO, l = t.ZERO, h = t.ZERO, f = t.mul(o, o), B = t.mul(a, a), g = t.mul(d, d), m = t.mul(o, a);
318
+ return m = t.add(m, m), h = t.mul(o, d), h = t.add(h, h), c = t.mul(r, h), l = t.mul(n, g), l = t.add(c, l), c = t.sub(B, l), l = t.add(B, l), l = t.mul(c, l), c = t.mul(m, c), h = t.mul(n, h), g = t.mul(r, g), m = t.sub(f, g), m = t.mul(r, m), m = t.add(m, h), h = t.add(f, f), f = t.add(h, f), f = t.add(f, g), f = t.mul(f, m), l = t.add(l, f), g = t.mul(a, d), g = t.add(g, g), f = t.mul(g, m), c = t.sub(c, f), h = t.mul(g, B), h = t.add(h, h), h = t.add(h, h), new y(c, l, h);
319
+ }
320
+ // Renes-Costello-Batina exception-free addition formula.
321
+ // There is 30% faster Jacobian formula, but it is not complete.
322
+ // https://eprint.iacr.org/2015/1060, algorithm 1
323
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
324
+ add(r) {
325
+ G(r);
326
+ const { px: s, py: n, pz: o } = this, { px: a, py: d, pz: c } = r;
327
+ let l = t.ZERO, h = t.ZERO, f = t.ZERO;
328
+ const B = e.a, g = t.mul(e.b, W);
329
+ let m = t.mul(s, a), R = t.mul(n, d), O = t.mul(o, c), A = t.add(s, n), E = t.add(a, d);
330
+ A = t.mul(A, E), E = t.add(m, R), A = t.sub(A, E), E = t.add(s, o);
331
+ let Z = t.add(a, c);
332
+ return E = t.mul(E, Z), Z = t.add(m, O), E = t.sub(E, Z), Z = t.add(n, o), l = t.add(d, c), Z = t.mul(Z, l), l = t.add(R, O), Z = t.sub(Z, l), f = t.mul(B, E), l = t.mul(g, O), f = t.add(l, f), l = t.sub(R, f), f = t.add(R, f), h = t.mul(l, f), R = t.add(m, m), R = t.add(R, m), O = t.mul(B, O), E = t.mul(g, E), R = t.add(R, O), O = t.sub(m, O), O = t.mul(B, O), E = t.add(E, O), m = t.mul(R, E), h = t.add(h, m), m = t.mul(Z, E), l = t.mul(A, l), l = t.sub(l, m), m = t.mul(A, R), f = t.mul(Z, f), f = t.add(f, m), new y(l, h, f);
333
+ }
334
+ subtract(r) {
335
+ return this.add(r.negate());
336
+ }
337
+ is0() {
338
+ return this.equals(y.ZERO);
339
+ }
88
340
  /**
89
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
90
- * @param W window size
91
- * @param precomputes precomputed tables
92
- * @param n scalar (we don't check here, but should be less than curve order)
93
- * @returns real and fake (for const-time) points
341
+ * Constant time multiplication.
342
+ * Uses wNAF method. Windowed method may be 10% faster,
343
+ * but takes 2x longer to generate and consumes 2x memory.
344
+ * Uses precomputes when available.
345
+ * Uses endomorphism for Koblitz curves.
346
+ * @param scalar by which the point would be multiplied
347
+ * @returns New point
94
348
  */
95
- wNAF(e, n, i) {
96
- let o = t.ZERO, s = t.BASE;
97
- const f = E(e, r);
98
- for (let a = 0; a < f.windows; a++) {
99
- const { nextN: d, offset: c, isZero: p, isNeg: l, isNegF: u, offsetF: m } = v(i, a, f);
100
- i = d, p ? s = s.add(b(u, n[m])) : o = o.add(b(l, n[c]));
349
+ multiply(r) {
350
+ const { endo: s } = i;
351
+ if (!w.isValidNot0(r))
352
+ throw new Error("invalid scalar: out of range");
353
+ let n, o;
354
+ const a = (d) => _.wNAFCached(this, d, y.normalizeZ);
355
+ if (s) {
356
+ const { k1neg: d, k1: c, k2neg: l, k2: h } = s.splitScalar(r), { p: f, f: B } = a(c), { p: g, f: m } = a(h);
357
+ o = B.add(m), n = $(s.beta, f, g, d, l);
358
+ } else {
359
+ const { p: d, f: c } = a(r);
360
+ n = d, o = c;
101
361
  }
102
- return S(i), { p: o, f: s };
103
- },
362
+ return y.normalizeZ([n, o])[0];
363
+ }
104
364
  /**
105
- * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
106
- * @param W window size
107
- * @param precomputes precomputed tables
108
- * @param n scalar (we don't check here, but should be less than curve order)
109
- * @param acc accumulator point to add result of multiplication
110
- * @returns point
365
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
366
+ * It's faster, but should only be used when you don't care about
367
+ * an exposed private key e.g. sig verification, which works over *public* keys.
111
368
  */
112
- wNAFUnsafe(e, n, i, o = t.ZERO) {
113
- const s = E(e, r);
114
- for (let f = 0; f < s.windows && i !== g; f++) {
115
- const { nextN: a, offset: d, isZero: c, isNeg: p } = v(i, f, s);
116
- if (i = a, !c) {
117
- const l = n[d];
118
- o = o.add(p ? l.negate() : l);
119
- }
369
+ multiplyUnsafe(r) {
370
+ const { endo: s } = i, n = this;
371
+ if (!w.isValid(r))
372
+ throw new Error("invalid scalar: out of range");
373
+ if (r === U || n.is0())
374
+ return y.ZERO;
375
+ if (r === k)
376
+ return n;
377
+ if (_.hasPrecomputes(this))
378
+ return this.multiply(r);
379
+ if (s) {
380
+ const { k1neg: o, k1: a, k2neg: d, k2: c } = s.splitScalar(r), { p1: l, p2: h } = Et(y, n, a, c);
381
+ return $(s.beta, l, h, o, d);
382
+ } else
383
+ return _.wNAFCachedUnsafe(n, r);
384
+ }
385
+ multiplyAndAddUnsafe(r, s, n) {
386
+ const o = this.multiplyUnsafe(s).add(r.multiplyUnsafe(n));
387
+ return o.is0() ? void 0 : o;
388
+ }
389
+ /**
390
+ * Converts Projective point to affine (x, y) coordinates.
391
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
392
+ */
393
+ toAffine(r) {
394
+ return X(this, r);
395
+ }
396
+ /**
397
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
398
+ * Always torsion-free for cofactor=1 curves.
399
+ */
400
+ isTorsionFree() {
401
+ const { isTorsionFree: r } = i;
402
+ return p === k ? !0 : r ? r(y, this) : _.wNAFCachedUnsafe(this, b).is0();
403
+ }
404
+ clearCofactor() {
405
+ const { clearCofactor: r } = i;
406
+ return p === k ? this : r ? r(y, this) : this.multiplyUnsafe(p);
407
+ }
408
+ toBytes(r = !0) {
409
+ return Q("isCompressed", r), this.assertValidity(), q(y, this, r);
410
+ }
411
+ /** @deprecated use `toBytes` */
412
+ toRawBytes(r = !0) {
413
+ return this.toBytes(r);
414
+ }
415
+ toHex(r = !0) {
416
+ return rt(this.toBytes(r));
417
+ }
418
+ toString() {
419
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
420
+ }
421
+ }
422
+ y.BASE = new y(e.Gx, e.Gy, t.ONE), y.ZERO = new y(t.ZERO, t.ONE, t.ZERO), y.Fp = t, y.Fn = w;
423
+ const P = w.BITS, _ = yt(y, i.endo ? Math.ceil(P / 2) : P);
424
+ return y;
425
+ }
426
+ function ut(e) {
427
+ return Uint8Array.of(e ? 2 : 3);
428
+ }
429
+ function Nt(e, i, t = {}) {
430
+ at(i, { hash: "function" }, {
431
+ hmac: "function",
432
+ lowS: "boolean",
433
+ randomBytes: "function",
434
+ bits2int: "function",
435
+ bits2int_modN: "function"
436
+ });
437
+ const w = i.randomBytes || St, p = i.hmac || ((n, ...o) => dt(i.hash, n, I(...o))), { Fp: b, Fn: u } = e, { ORDER: x, BITS: S } = u;
438
+ function N(n) {
439
+ const o = x >> k;
440
+ return n > o;
441
+ }
442
+ function q(n) {
443
+ return N(n) ? u.neg(n) : n;
444
+ }
445
+ function C(n, o) {
446
+ if (!u.isValidNot0(o))
447
+ throw new Error(`invalid signature ${n}: out of range 1..CURVE.n`);
448
+ }
449
+ class T {
450
+ constructor(o, a, d) {
451
+ C("r", o), C("s", a), this.r = o, this.s = a, d != null && (this.recovery = d), Object.freeze(this);
452
+ }
453
+ // pair (bytes of r, bytes of s)
454
+ static fromCompact(o) {
455
+ const a = u.BYTES, d = z("compactSignature", o, a * 2);
456
+ return new T(u.fromBytes(d.subarray(0, a)), u.fromBytes(d.subarray(a, a * 2)));
457
+ }
458
+ // DER encoded ECDSA signature
459
+ // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
460
+ static fromDER(o) {
461
+ const { r: a, s: d } = F.toSig(z("DER", o));
462
+ return new T(a, d);
463
+ }
464
+ /**
465
+ * @todo remove
466
+ * @deprecated
467
+ */
468
+ assertValidity() {
469
+ }
470
+ addRecoveryBit(o) {
471
+ return new T(this.r, this.s, o);
472
+ }
473
+ // ProjPointType<bigint>
474
+ recoverPublicKey(o) {
475
+ const a = b.ORDER, { r: d, s: c, recovery: l } = this;
476
+ if (l == null || ![0, 1, 2, 3].includes(l))
477
+ throw new Error("recovery id invalid");
478
+ if (x * At < a && l > 1)
479
+ throw new Error("recovery id is ambiguous for h>1 curve");
480
+ const f = l === 2 || l === 3 ? d + x : d;
481
+ if (!b.isValid(f))
482
+ throw new Error("recovery id 2 or 3 invalid");
483
+ const B = b.toBytes(f), g = e.fromHex(I(ut((l & 1) === 0), B)), m = u.inv(f), R = V(z("msgHash", o)), O = u.create(-R * m), A = u.create(c * m), E = e.BASE.multiplyUnsafe(O).add(g.multiplyUnsafe(A));
484
+ if (E.is0())
485
+ throw new Error("point at infinify");
486
+ return E.assertValidity(), E;
487
+ }
488
+ // Signatures should be low-s, to prevent malleability.
489
+ hasHighS() {
490
+ return N(this.s);
491
+ }
492
+ normalizeS() {
493
+ return this.hasHighS() ? new T(this.r, u.neg(this.s), this.recovery) : this;
494
+ }
495
+ toBytes(o) {
496
+ if (o === "compact")
497
+ return I(u.toBytes(this.r), u.toBytes(this.s));
498
+ if (o === "der")
499
+ return xt(F.hexFromSig(this));
500
+ throw new Error("invalid format");
501
+ }
502
+ // DER-encoded
503
+ toDERRawBytes() {
504
+ return this.toBytes("der");
505
+ }
506
+ toDERHex() {
507
+ return rt(this.toBytes("der"));
508
+ }
509
+ // padded bytes of r, then padded bytes of s
510
+ toCompactRawBytes() {
511
+ return this.toBytes("compact");
512
+ }
513
+ toCompactHex() {
514
+ return rt(this.toBytes("compact"));
515
+ }
516
+ }
517
+ const L = lt(u, t.allowedPrivateKeyLengths, t.wrapPrivateKey), J = {
518
+ isValidPrivateKey(n) {
519
+ try {
520
+ return L(n), !0;
521
+ } catch {
522
+ return !1;
120
523
  }
121
- return S(i), o;
122
524
  },
123
- getPrecomputes(e, n, i) {
124
- let o = N.get(n);
125
- return o || (o = this.precomputeWindow(n, e), e !== 1 && (typeof i == "function" && (o = i(o)), N.set(n, o))), o;
126
- },
127
- wNAFCached(e, n, i) {
128
- const o = A(e);
129
- return this.wNAF(o, this.getPrecomputes(o, e, i), n);
130
- },
131
- wNAFCachedUnsafe(e, n, i, o) {
132
- const s = A(e);
133
- return s === 1 ? this.unsafeLadder(e, n, o) : this.wNAFUnsafe(s, this.getPrecomputes(s, e, i), n, o);
525
+ normPrivateKeyToScalar: L,
526
+ /**
527
+ * Produces cryptographically secure private key from random of size
528
+ * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
529
+ */
530
+ randomPrivateKey: () => {
531
+ const n = x;
532
+ return vt(w(Bt(n)), n);
134
533
  },
135
- // We calculate precomputes for elliptic curve point multiplication
136
- // using windowed method. This specifies window size and
137
- // stores precomputed values. Usually only base point would be precomputed.
138
- setWindowSize(e, n) {
139
- I(n, r), M.set(e, n), N.delete(e);
534
+ precompute(n = 8, o = e.BASE) {
535
+ return o.precompute(n, !1);
140
536
  }
141
537
  };
538
+ function tt(n, o = !0) {
539
+ return e.fromPrivateKey(n).toBytes(o);
540
+ }
541
+ function K(n) {
542
+ if (typeof n == "bigint")
543
+ return !1;
544
+ if (n instanceof e)
545
+ return !0;
546
+ const a = z("key", n).length, d = b.BYTES, c = d + 1, l = 2 * d + 1;
547
+ if (!(t.allowedPrivateKeyLengths || u.BYTES === c))
548
+ return a === c || a === l;
549
+ }
550
+ function G(n, o, a = !0) {
551
+ if (K(n) === !0)
552
+ throw new Error("first arg must be private key");
553
+ if (K(o) === !1)
554
+ throw new Error("second arg must be public key");
555
+ return e.fromHex(o).multiply(L(n)).toBytes(a);
556
+ }
557
+ const X = i.bits2int || function(n) {
558
+ if (n.length > 8192)
559
+ throw new Error("input is too large");
560
+ const o = ct(n), a = n.length * 8 - S;
561
+ return a > 0 ? o >> BigInt(a) : o;
562
+ }, V = i.bits2int_modN || function(n) {
563
+ return u.create(X(n));
564
+ }, $ = ft(S);
565
+ function y(n) {
566
+ return mt("num < 2^" + S, n, U, $), u.toBytes(n);
567
+ }
568
+ function P(n, o, a = _) {
569
+ if (["recovered", "canonical"].some((A) => A in a))
570
+ throw new Error("sign() legacy options not supported");
571
+ const { hash: d } = i;
572
+ let { lowS: c, prehash: l, extraEntropy: h } = a;
573
+ c == null && (c = !0), n = z("msgHash", n), st(a), l && (n = z("prehashed msgHash", d(n)));
574
+ const f = V(n), B = L(o), g = [y(B), y(f)];
575
+ if (h != null && h !== !1) {
576
+ const A = h === !0 ? w(b.BYTES) : h;
577
+ g.push(z("extraEntropy", A));
578
+ }
579
+ const m = I(...g), R = f;
580
+ function O(A) {
581
+ const E = X(A);
582
+ if (!u.isValidNot0(E))
583
+ return;
584
+ const Z = u.inv(E), j = e.BASE.multiply(E).toAffine(), Y = u.create(j.x);
585
+ if (Y === U)
586
+ return;
587
+ const H = u.create(Z * u.create(R + Y * B));
588
+ if (H === U)
589
+ return;
590
+ let et = (j.x === Y ? 0 : 2) | Number(j.y & k), D = H;
591
+ return c && N(H) && (D = q(H), et ^= 1), new T(Y, D, et);
592
+ }
593
+ return { seed: m, k2sig: O };
594
+ }
595
+ const _ = { lowS: i.lowS, prehash: !1 }, v = { lowS: i.lowS, prehash: !1 };
596
+ function r(n, o, a = _) {
597
+ const { seed: d, k2sig: c } = P(n, o, a);
598
+ return ht(i.hash.outputLen, u.BYTES, p)(d, c);
599
+ }
600
+ e.BASE.precompute(8);
601
+ function s(n, o, a, d = v) {
602
+ const c = n;
603
+ o = z("msgHash", o), a = z("publicKey", a), st(d);
604
+ const { lowS: l, prehash: h, format: f } = d;
605
+ if ("strict" in d)
606
+ throw new Error("options.strict was renamed to lowS");
607
+ if (f !== void 0 && !["compact", "der", "js"].includes(f))
608
+ throw new Error('format must be "compact", "der" or "js"');
609
+ const B = typeof c == "string" || Rt(c), g = !B && !f && typeof c == "object" && c !== null && typeof c.r == "bigint" && typeof c.s == "bigint";
610
+ if (!B && !g)
611
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
612
+ let m, R;
613
+ try {
614
+ if (g)
615
+ if (f === void 0 || f === "js")
616
+ m = new T(c.r, c.s);
617
+ else
618
+ throw new Error("invalid format");
619
+ if (B) {
620
+ try {
621
+ f !== "compact" && (m = T.fromDER(c));
622
+ } catch (D) {
623
+ if (!(D instanceof F.Err))
624
+ throw D;
625
+ }
626
+ !m && f !== "der" && (m = T.fromCompact(c));
627
+ }
628
+ R = e.fromHex(a);
629
+ } catch {
630
+ return !1;
631
+ }
632
+ if (!m || l && m.hasHighS())
633
+ return !1;
634
+ h && (o = i.hash(o));
635
+ const { r: O, s: A } = m, E = V(o), Z = u.inv(A), j = u.create(E * Z), Y = u.create(O * Z), H = e.BASE.multiplyUnsafe(j).add(R.multiplyUnsafe(Y));
636
+ return H.is0() ? !1 : u.create(H.x) === O;
637
+ }
638
+ return Object.freeze({
639
+ getPublicKey: tt,
640
+ getSharedSecret: G,
641
+ sign: r,
642
+ verify: s,
643
+ utils: J,
644
+ Point: e,
645
+ Signature: T
646
+ });
142
647
  }
143
- function $(t, r, e, n) {
144
- let i = r, o = t.ZERO, s = t.ZERO;
145
- for (; e > g || n > g; )
146
- e & h && (o = o.add(i)), n & h && (s = s.add(i)), i = i.double(), e >>= h, n >>= h;
147
- return { p1: o, p2: s };
648
+ function Ft(e) {
649
+ const i = {
650
+ a: e.a,
651
+ b: e.b,
652
+ p: e.Fp.ORDER,
653
+ n: e.n,
654
+ h: e.h,
655
+ Gx: e.Gx,
656
+ Gy: e.Gy
657
+ }, t = e.Fp, w = bt(i.n, e.nBitLength), p = {
658
+ Fp: t,
659
+ Fn: w,
660
+ allowedPrivateKeyLengths: e.allowedPrivateKeyLengths,
661
+ allowInfinityPoint: e.allowInfinityPoint,
662
+ endo: e.endo,
663
+ wrapPrivateKey: e.wrapPrivateKey,
664
+ isTorsionFree: e.isTorsionFree,
665
+ clearCofactor: e.clearCofactor,
666
+ fromBytes: e.fromBytes,
667
+ toBytes: e.toBytes
668
+ };
669
+ return { CURVE: i, curveOpts: p };
148
670
  }
149
- function D(t, r, e, n) {
150
- j(e, t), _(n, r);
151
- const i = e.length, o = n.length;
152
- if (i !== o)
153
- throw new Error("arrays of points and scalars must have equal length");
154
- const s = t.ZERO, f = B(BigInt(i));
155
- let a = 1;
156
- f > 12 ? a = f - 3 : f > 4 ? a = f - 2 : f > 0 && (a = 2);
157
- const d = z(a), c = new Array(Number(d) + 1).fill(s), p = Math.floor((r.BITS - 1) / a) * a;
158
- let l = s;
159
- for (let u = p; u >= 0; u -= a) {
160
- c.fill(s);
161
- for (let w = 0; w < o; w++) {
162
- const F = n[w], y = Number(F >> BigInt(u) & d);
163
- c[y] = c[y].add(e[w]);
164
- }
165
- let m = s;
166
- for (let w = c.length - 1, F = s; w > 0; w--)
167
- F = F.add(c[w]), m = m.add(F);
168
- if (l = l.add(m), u !== 0)
169
- for (let w = 0; w < a; w++)
170
- l = l.double();
171
- }
172
- return l;
671
+ function Lt(e) {
672
+ const { CURVE: i, curveOpts: t } = Ft(e), w = {
673
+ hash: e.hash,
674
+ hmac: e.hmac,
675
+ randomBytes: e.randomBytes,
676
+ lowS: e.lowS,
677
+ bits2int: e.bits2int,
678
+ bits2int_modN: e.bits2int_modN
679
+ };
680
+ return { CURVE: i, curveOpts: t, ecdsaOpts: w };
173
681
  }
174
- function x(t, r) {
175
- if (r) {
176
- if (r.ORDER !== t)
177
- throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
178
- return Z(r), r;
179
- } else
180
- return O(t);
682
+ function _t(e, i) {
683
+ return Object.assign({}, i, {
684
+ ProjectivePoint: i.Point,
685
+ CURVE: e
686
+ });
181
687
  }
182
- function G(t, r, e = {}) {
183
- if (!r || typeof r != "object")
184
- throw new Error(`expected valid ${t} CURVE object`);
185
- for (const f of ["p", "n", "h"]) {
186
- const a = r[f];
187
- if (!(typeof a == "bigint" && a > g))
188
- throw new Error(`CURVE.${f} must be positive bigint`);
189
- }
190
- const n = x(r.p, e.Fp), i = x(r.n, e.Fn), s = ["Gx", "Gy", "a", "b"];
191
- for (const f of s)
192
- if (!n.isValid(r[f]))
193
- throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);
194
- return { Fp: n, Fn: i };
688
+ function It(e) {
689
+ const { CURVE: i, curveOpts: t, ecdsaOpts: w } = Lt(e), p = zt(i, t), b = Nt(p, w, t);
690
+ return _t(e, b);
195
691
  }
196
692
  export {
197
- G as _createCurveFields,
198
- $ as mulEndoUnsafe,
199
- b as negateCt,
200
- L as normalizeZ,
201
- D as pippenger,
202
- U as wNAF
693
+ F as DER,
694
+ Ot as DERErr,
695
+ Tt as _legacyHelperEquat,
696
+ lt as _legacyHelperNormPriv,
697
+ Nt as ecdsa,
698
+ It as weierstrass,
699
+ zt as weierstrassN
203
700
  };