@blockend/widget 1.0.32 → 1.0.34

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 (114) hide show
  1. package/dist/{AllRoutes-CPwuTwqd.js → AllRoutes-DW-2t6-d.js} +25 -25
  2. package/dist/{Box-CIChapvH.js → Box-C4X6PUtu.js} +21 -22
  3. package/dist/{EstGas-CEFILtyf.js → EstGas-Lj2vKAmO.js} +26 -30
  4. package/dist/{Grow-DJZj9zjv.js → Grow-CCS_DglL.js} +78 -78
  5. package/dist/{InputComp-DqF1JGIu.js → InputComp-FIX0Q9qG.js} +13 -14
  6. package/dist/{LoadRoute-r3sHTYXM.js → LoadRoute-Di4rBHfs.js} +6 -7
  7. package/dist/{QuotesProgress-BXVLxZ8U.js → QuotesProgress-CDe2mdH1.js} +1 -1
  8. package/dist/{SwapAsset-07WvVwl-.js → SwapAsset-B0GIHqge.js} +1 -1
  9. package/dist/{Tooltip-CNAsCF8n.js → Tooltip-CsLgOKrX.js} +62 -62
  10. package/dist/{TxnButton-D2TTkFYA.js → TxnButton-CFquc6ws.js} +19 -19
  11. package/dist/{add-t2GqC9VA.js → add-Cb5Hpxtd.js} +1 -1
  12. package/dist/{all-wallets-DFyf0q31.js → all-wallets-IvJFyonp.js} +1 -1
  13. package/dist/{app-store-aAahwmBP.js → app-store-DGHaTAGg.js} +1 -1
  14. package/dist/{apple-DeRgpwlc.js → apple-BzfrhDcG.js} +1 -1
  15. package/dist/{arrow-bottom-DdEOkaAj.js → arrow-bottom-BTM5yMbs.js} +1 -1
  16. package/dist/{arrow-bottom-circle-BWwREWcv.js → arrow-bottom-circle-wJZrQ1UB.js} +1 -1
  17. package/dist/{arrow-left-CulyLmoH.js → arrow-left-yb9jvZLF.js} +1 -1
  18. package/dist/{arrow-right-Dwr7TISn.js → arrow-right-CNq-seAV.js} +1 -1
  19. package/dist/{arrow-top-pL4rM_y8.js → arrow-top-viS3mMCD.js} +1 -1
  20. package/dist/{bank-CPuyK_08.js → bank-BCcggibH.js} +1 -1
  21. package/dist/{basic-CVc9xEvb.js → basic-DaTq2wkc.js} +3 -3
  22. package/dist/{browser-Cbq2Zbp4.js → browser-CmA0GPLB.js} +1 -1
  23. package/dist/{card-B_hUtPWK.js → card-BO4I6Psi.js} +1 -1
  24. package/dist/{ccip-BLVGcR4A.js → ccip-CkXLKCYn.js} +20 -20
  25. package/dist/{checkmark-WEqTsFAc.js → checkmark-DF8VoFaX.js} +1 -1
  26. package/dist/{checkmark-bold-Du_ZvhqM.js → checkmark-bold-C6OPR-mV.js} +1 -1
  27. package/dist/{chevron-bottom-C-s-lv4L.js → chevron-bottom-BTjaTIFm.js} +1 -1
  28. package/dist/{chevron-left-C7NcRElx.js → chevron-left-D6wphcsV.js} +1 -1
  29. package/dist/{chevron-right-CSzmAmdn.js → chevron-right-Ba05aF4G.js} +1 -1
  30. package/dist/{chevron-top-Dd99Wfel.js → chevron-top-I_q0NhsC.js} +1 -1
  31. package/dist/{chrome-store-C4p77Of0.js → chrome-store-DvzERGX1.js} +1 -1
  32. package/dist/{clock-Cib24qjH.js → clock-GIv_XdGS.js} +1 -1
  33. package/dist/{close-BXjEkTvS.js → close-ChDp2HIX.js} +1 -1
  34. package/dist/{coinPlaceholder-BFNC7cQN.js → coinPlaceholder-D6rBGR5B.js} +1 -1
  35. package/dist/{compass-CXPX5Ycp.js → compass-DFCkTDdC.js} +1 -1
  36. package/dist/{copy-BEawMbmF.js → copy-DyQCksHx.js} +1 -1
  37. package/dist/{core-Bez9Ow7F.js → core-BnRPnZUj.js} +3 -3
  38. package/dist/{cursor-Cxq4Q9jk.js → cursor-BhR8wfWc.js} +1 -1
  39. package/dist/{cursor-transparent-ZjJ0P2vr.js → cursor-transparent-CYfTh9TG.js} +1 -1
  40. package/dist/{desktop-BhZVovAp.js → desktop-CdNR2WGz.js} +1 -1
  41. package/dist/{disconnect-AC-bffZO.js → disconnect-Bbfhuf4x.js} +1 -1
  42. package/dist/{discord-dT97h-CC.js → discord-04uw628s.js} +1 -1
  43. package/dist/{down-DP56YSKp.js → down-DmSxEW66.js} +2 -2
  44. package/dist/{etherscan-rYFRhRTM.js → etherscan-D7Ga60vG.js} +1 -1
  45. package/dist/{exclamation-triangle-C-pCuC08.js → exclamation-triangle-CMEJoc37.js} +1 -1
  46. package/dist/{extension-BnqauLSn.js → extension-C0IOh4C8.js} +1 -1
  47. package/dist/{external-link-M9D6e_F3.js → external-link-CEy2KY-H.js} +1 -1
  48. package/dist/{facebook-DHezcoD-.js → facebook-XHE6-OiD.js} +1 -1
  49. package/dist/{farcaster-D0Ky-Imv.js → farcaster-BVsAZpup.js} +1 -1
  50. package/dist/{filters-B02NYLWq.js → filters-BjuqhDXY.js} +1 -1
  51. package/dist/{getChainIds-CJd2TZYT.js → getChainIds-cRV7v4Vu.js} +75 -75
  52. package/dist/{getCosmosAddress-DTZfw04G.js → getCosmosAddress-Cm0YEa9v.js} +2 -2
  53. package/dist/{github-BzQkIMuE.js → github-C5YGtlqc.js} +1 -1
  54. package/dist/{google-BpwCJ4Fs.js → google-DFDexaN0.js} +1 -1
  55. package/dist/{hamburger-BzqwkUjE.js → hamburger-CZPNB-Jp.js} +20 -20
  56. package/dist/{help-circle-C0nOySHC.js → help-circle-C2OFxIs0.js} +1 -1
  57. package/dist/{id-DFP_kFd4.js → id-CforGy9u.js} +1 -1
  58. package/dist/{image-QiYOAGjM.js → image-BLq9nQ13.js} +1 -1
  59. package/dist/{index-D5hLIe-N.js → index-BRrWKwgI.js} +1 -1
  60. package/dist/{index-DDk00SOL.js → index-Bw4t164c.js} +45 -45
  61. package/dist/{index-DaJ1272l.js → index-ByWf22Y4.js} +43 -43
  62. package/dist/index-C6pDnqRd.js +30456 -0
  63. package/dist/{index-DXdD3L9f.js → index-Cx-XaRo6.js} +243 -243
  64. package/dist/{index-CrC4B7xn.js → index-D7-VO30b.js} +22 -23
  65. package/dist/{index-DxPp2gBS.js → index-DKPTk58K.js} +78 -78
  66. package/dist/{index-CjtwASJt.js → index-DrWi5MDR.js} +4 -4
  67. package/dist/{index-DW3W7zaF.js → index-EuXqE26M.js} +53 -54
  68. package/dist/{index-Dy_n2MPD.js → index-HOk_h4cO.js} +14 -14
  69. package/dist/{index-oc8HPfOF.js → index-sSdagBAC.js} +93 -93
  70. package/dist/{index.es-C-j-Ghef.js → index.es-B1r2oZcy.js} +2 -2
  71. package/dist/{index.es-Bsr7zP98.js → index.es-DP4lrxUS.js} +5 -5
  72. package/dist/index.es.js +1 -1
  73. package/dist/{info-BTLQJ-wd.js → info-CJ1NTOxH.js} +1 -1
  74. package/dist/{info-circle-Dla9169_.js → info-circle-Daj7vZoR.js} +1 -1
  75. package/dist/{lightbulb-PN8DA_Wh.js → lightbulb-BLkY2HTh.js} +1 -1
  76. package/dist/{mail-BGYZut_4.js → mail-CAKz4cbl.js} +1 -1
  77. package/dist/{mobile-BM760ZzX.js → mobile-BopKRCBe.js} +1 -1
  78. package/dist/{more-rHGnl2ck.js → more-X_2v_wZ3.js} +1 -1
  79. package/dist/{network-placeholder-CyQl-3_2.js → network-placeholder-C1OcyWkc.js} +1 -1
  80. package/dist/{nftPlaceholder-nuUJ8nKY.js → nftPlaceholder-B3ZKQ1U2.js} +1 -1
  81. package/dist/{off-GYlwYDrT.js → off-OZ4tqosO.js} +1 -1
  82. package/dist/{play-store-Ck01Ez1F.js → play-store-HsWGEr_g.js} +1 -1
  83. package/dist/{plus-CQfXWgLw.js → plus-C7yRM6wl.js} +1 -1
  84. package/dist/{qr-code-CyLVwLY7.js → qr-code-DfWVQYKi.js} +1 -1
  85. package/dist/{recycle-horizontal-DvnWPcEQ.js → recycle-horizontal-C5u6LBUM.js} +1 -1
  86. package/dist/{refresh-BOxj8b2n.js → refresh-BYw1HzOO.js} +1 -1
  87. package/dist/{reown-logo-D1iprOTg.js → reown-logo-CXMihtcp.js} +1 -1
  88. package/dist/{search-DrPaZPnc.js → search-ByiAQZVh.js} +1 -1
  89. package/dist/{send-ybBREe4b.js → send-Bs5FwLBZ.js} +1 -1
  90. package/dist/shareicon-CG3v7iKI.js +10 -0
  91. package/dist/{swapHorizontal-BddjZdXK.js → swapHorizontal-B7d_h2Se.js} +1 -1
  92. package/dist/{swapHorizontalBold-B6AWjPZ9.js → swapHorizontalBold-xBnEd6a1.js} +1 -1
  93. package/dist/{swapHorizontalMedium-CNacWoBn.js → swapHorizontalMedium-aLC75TbM.js} +1 -1
  94. package/dist/{swapHorizontalRoundedBold-B8VcPnqt.js → swapHorizontalRoundedBold-D1ph5kGS.js} +1 -1
  95. package/dist/{swapVertical-zY2BbSyQ.js → swapVertical-DtfbArUn.js} +1 -1
  96. package/dist/{telegram-DS4l-8Oc.js → telegram-0Il36fMk.js} +1 -1
  97. package/dist/{three-dots-RctNqamK.js → three-dots-wNW622nV.js} +1 -1
  98. package/dist/{twitch-CJ0llIIH.js → twitch-Dt1-Wtif.js} +1 -1
  99. package/dist/{twitterIcon-pgvN9-bP.js → twitterIcon-CpSpHPYu.js} +1 -1
  100. package/dist/{unsupportedProp-BJVuEW_b.js → unsupportedProp-DBVCAgxp.js} +1 -1
  101. package/dist/{useRegisterError-C_YLA1dw.js → useRegisterError-Cs0PKbRQ.js} +3257 -4302
  102. package/dist/{verify-BeZLo1Fq.js → verify-BFIm6NMn.js} +1 -1
  103. package/dist/{verify-filled-meyb7E16.js → verify-filled-bGZT7egL.js} +1 -1
  104. package/dist/{w3m-modal-C-Jp9NVv.js → w3m-modal-C6VaThR4.js} +2 -2
  105. package/dist/{wallet-CFcOgSsz.js → wallet-BeQcPBdd.js} +1 -1
  106. package/dist/{wallet-placeholder-CeUMILZq.js → wallet-placeholder-CCGVvv4Q.js} +1 -1
  107. package/dist/{walletconnect-D6LB1PyC.js → walletconnect-BnSO61ut.js} +1 -1
  108. package/dist/{warning-circle-BRtzofvT.js → warning-circle-D80fIuKG.js} +1 -1
  109. package/dist/widget.css +1 -1
  110. package/dist/{x-DKQAOOh3.js → x-4jy71myv.js} +1 -1
  111. package/package.json +7 -19
  112. package/dist/index-CLzkn733.js +0 -28223
  113. package/dist/secp256k1-DgmH1qVg.js +0 -1251
  114. package/dist/shareicon-D3Qj5j1T.js +0 -262
@@ -1,1251 +0,0 @@
1
- import { aG as ce, x as ae, aH as le, J as ue, aI as de } from "./index-CLzkn733.js";
2
- const Tt = /* @__PURE__ */ BigInt(0), Ot = /* @__PURE__ */ BigInt(1);
3
- function ut(e) {
4
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
5
- }
6
- function Ut(e) {
7
- if (!ut(e))
8
- throw new Error("Uint8Array expected");
9
- }
10
- function at(e, n) {
11
- if (typeof n != "boolean")
12
- throw new Error(e + " boolean expected, got " + n);
13
- }
14
- function ht(e) {
15
- const n = e.toString(16);
16
- return n.length & 1 ? "0" + n : n;
17
- }
18
- function $t(e) {
19
- if (typeof e != "string")
20
- throw new Error("hex string expected, got " + typeof e);
21
- return e === "" ? Tt : BigInt("0x" + e);
22
- }
23
- const Gt = (
24
- // @ts-ignore
25
- typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function"
26
- ), he = /* @__PURE__ */ Array.from({ length: 256 }, (e, n) => n.toString(16).padStart(2, "0"));
27
- function lt(e) {
28
- if (Ut(e), Gt)
29
- return e.toHex();
30
- let n = "";
31
- for (let t = 0; t < e.length; t++)
32
- n += he[e[t]];
33
- return n;
34
- }
35
- const W = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
36
- function kt(e) {
37
- if (e >= W._0 && e <= W._9)
38
- return e - W._0;
39
- if (e >= W.A && e <= W.F)
40
- return e - (W.A - 10);
41
- if (e >= W.a && e <= W.f)
42
- return e - (W.a - 10);
43
- }
44
- function wt(e) {
45
- if (typeof e != "string")
46
- throw new Error("hex string expected, got " + typeof e);
47
- if (Gt)
48
- return Uint8Array.fromHex(e);
49
- const n = e.length, t = n / 2;
50
- if (n % 2)
51
- throw new Error("hex string expected, got unpadded hex of length " + n);
52
- const r = new Uint8Array(t);
53
- for (let i = 0, s = 0; i < t; i++, s += 2) {
54
- const a = kt(e.charCodeAt(s)), u = kt(e.charCodeAt(s + 1));
55
- if (a === void 0 || u === void 0) {
56
- const o = e[s] + e[s + 1];
57
- throw new Error('hex string expected, got non-hex character "' + o + '" at index ' + s);
58
- }
59
- r[i] = a * 16 + u;
60
- }
61
- return r;
62
- }
63
- function et(e) {
64
- return $t(lt(e));
65
- }
66
- function Wt(e) {
67
- return Ut(e), $t(lt(Uint8Array.from(e).reverse()));
68
- }
69
- function dt(e, n) {
70
- return wt(e.toString(16).padStart(n * 2, "0"));
71
- }
72
- function Dt(e, n) {
73
- return dt(e, n).reverse();
74
- }
75
- function K(e, n, t) {
76
- let r;
77
- if (typeof n == "string")
78
- try {
79
- r = wt(n);
80
- } catch (s) {
81
- throw new Error(e + " must be hex string or Uint8Array, cause: " + s);
82
- }
83
- else if (ut(n))
84
- r = Uint8Array.from(n);
85
- else
86
- throw new Error(e + " must be hex string or Uint8Array");
87
- const i = r.length;
88
- if (typeof t == "number" && i !== t)
89
- throw new Error(e + " of length " + t + " expected, got " + i);
90
- return r;
91
- }
92
- function gt(...e) {
93
- let n = 0;
94
- for (let r = 0; r < e.length; r++) {
95
- const i = e[r];
96
- Ut(i), n += i.length;
97
- }
98
- const t = new Uint8Array(n);
99
- for (let r = 0, i = 0; r < e.length; r++) {
100
- const s = e[r];
101
- t.set(s, i), i += s.length;
102
- }
103
- return t;
104
- }
105
- const bt = (e) => typeof e == "bigint" && Tt <= e;
106
- function Lt(e, n, t) {
107
- return bt(e) && bt(n) && bt(t) && n <= e && e < t;
108
- }
109
- function it(e, n, t, r) {
110
- if (!Lt(n, t, r))
111
- throw new Error("expected valid " + e + ": " + t + " <= n < " + r + ", got " + n);
112
- }
113
- function we(e) {
114
- let n;
115
- for (n = 0; e > Tt; e >>= Ot, n += 1)
116
- ;
117
- return n;
118
- }
119
- const mt = (e) => (Ot << BigInt(e)) - Ot, Bt = (e) => new Uint8Array(e), Ct = (e) => Uint8Array.from(e);
120
- function ge(e, n, t) {
121
- if (typeof e != "number" || e < 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 t != "function")
126
- throw new Error("hmacFn must be a function");
127
- let r = Bt(e), i = Bt(e), s = 0;
128
- const a = () => {
129
- r.fill(1), i.fill(0), s = 0;
130
- }, u = (...A) => t(i, r, ...A), o = (A = Bt(0)) => {
131
- i = u(Ct([0]), A), r = u(), A.length !== 0 && (i = u(Ct([1]), A), r = u());
132
- }, d = () => {
133
- if (s++ >= 1e3)
134
- throw new Error("drbg: tried 1000 values");
135
- let A = 0;
136
- const I = [];
137
- for (; A < n; ) {
138
- r = u();
139
- const z = r.slice();
140
- I.push(z), A += r.length;
141
- }
142
- return gt(...I);
143
- };
144
- return (A, I) => {
145
- a(), o(A);
146
- let z;
147
- for (; !(z = I(d())); )
148
- o();
149
- return a(), z;
150
- };
151
- }
152
- const me = {
153
- bigint: (e) => typeof e == "bigint",
154
- function: (e) => typeof e == "function",
155
- boolean: (e) => typeof e == "boolean",
156
- string: (e) => typeof e == "string",
157
- stringOrUint8Array: (e) => typeof e == "string" || ut(e),
158
- isSafeInteger: (e) => Number.isSafeInteger(e),
159
- array: (e) => Array.isArray(e),
160
- field: (e, n) => n.Fp.isValid(e),
161
- hash: (e) => typeof e == "function" && Number.isSafeInteger(e.outputLen)
162
- };
163
- function pt(e, n, t = {}) {
164
- const r = (i, s, a) => {
165
- const u = me[s];
166
- if (typeof u != "function")
167
- throw new Error("invalid validator function");
168
- const o = e[i];
169
- if (!(a && o === void 0) && !u(o, e))
170
- throw new Error("param " + String(i) + " is invalid. Expected " + s + ", got " + o);
171
- };
172
- for (const [i, s] of Object.entries(n))
173
- r(i, s, !1);
174
- for (const [i, s] of Object.entries(t))
175
- r(i, s, !0);
176
- return e;
177
- }
178
- function Ht(e) {
179
- const n = /* @__PURE__ */ new WeakMap();
180
- return (t, ...r) => {
181
- const i = n.get(t);
182
- if (i !== void 0)
183
- return i;
184
- const s = e(t, ...r);
185
- return n.set(t, s), s;
186
- };
187
- }
188
- const Y = BigInt(0), H = BigInt(1), tt = /* @__PURE__ */ BigInt(2), pe = /* @__PURE__ */ BigInt(3), Xt = /* @__PURE__ */ BigInt(4), Ft = /* @__PURE__ */ BigInt(5), Qt = /* @__PURE__ */ BigInt(8);
189
- function M(e, n) {
190
- const t = e % n;
191
- return t >= Y ? t : n + t;
192
- }
193
- function j(e, n, t) {
194
- let r = e;
195
- for (; n-- > Y; )
196
- r *= r, r %= t;
197
- return r;
198
- }
199
- function qt(e, n) {
200
- if (e === Y)
201
- throw new Error("invert: expected non-zero number");
202
- if (n <= Y)
203
- throw new Error("invert: expected positive modulus, got " + n);
204
- let t = M(e, n), r = n, i = Y, s = H;
205
- for (; t !== Y; ) {
206
- const u = r / t, o = r % t, d = i - s * u;
207
- r = t, t = o, i = s, s = d;
208
- }
209
- if (r !== H)
210
- throw new Error("invert: does not exist");
211
- return M(i, n);
212
- }
213
- function Jt(e, n) {
214
- const t = (e.ORDER + H) / Xt, r = e.pow(n, t);
215
- if (!e.eql(e.sqr(r), n))
216
- throw new Error("Cannot find square root");
217
- return r;
218
- }
219
- function ye(e, n) {
220
- const t = (e.ORDER - Ft) / Qt, r = e.mul(n, tt), i = e.pow(r, t), s = e.mul(n, i), a = e.mul(e.mul(s, tt), i), u = e.mul(s, e.sub(a, e.ONE));
221
- if (!e.eql(e.sqr(u), n))
222
- throw new Error("Cannot find square root");
223
- return u;
224
- }
225
- function Ee(e) {
226
- if (e < BigInt(3))
227
- throw new Error("sqrt is not defined for small field");
228
- let n = e - H, t = 0;
229
- for (; n % tt === Y; )
230
- n /= tt, t++;
231
- let r = tt;
232
- const i = _t(e);
233
- for (; Vt(i, r) === 1; )
234
- if (r++ > 1e3)
235
- throw new Error("Cannot find square root: probably non-prime P");
236
- if (t === 1)
237
- return Jt;
238
- let s = i.pow(r, n);
239
- const a = (n + H) / tt;
240
- return function(o, d) {
241
- if (o.is0(d))
242
- return d;
243
- if (Vt(o, d) !== 1)
244
- throw new Error("Cannot find square root");
245
- let m = t, A = o.mul(o.ONE, s), I = o.pow(d, n), z = o.pow(d, a);
246
- for (; !o.eql(I, o.ONE); ) {
247
- if (o.is0(I))
248
- return o.ZERO;
249
- let T = 1, g = o.sqr(I);
250
- for (; !o.eql(g, o.ONE); )
251
- if (T++, g = o.sqr(g), T === m)
252
- throw new Error("Cannot find square root");
253
- const k = H << BigInt(m - T - 1), U = o.pow(A, k);
254
- m = T, A = o.sqr(U), I = o.mul(I, A), z = o.mul(z, U);
255
- }
256
- return z;
257
- };
258
- }
259
- function be(e) {
260
- return e % Xt === pe ? Jt : e % Qt === Ft ? ye : Ee(e);
261
- }
262
- const Be = [
263
- "create",
264
- "isValid",
265
- "is0",
266
- "neg",
267
- "inv",
268
- "sqrt",
269
- "sqr",
270
- "eql",
271
- "add",
272
- "sub",
273
- "mul",
274
- "pow",
275
- "div",
276
- "addN",
277
- "subN",
278
- "mulN",
279
- "sqrN"
280
- ];
281
- function ve(e) {
282
- const n = {
283
- ORDER: "bigint",
284
- MASK: "bigint",
285
- BYTES: "isSafeInteger",
286
- BITS: "isSafeInteger"
287
- }, t = Be.reduce((r, i) => (r[i] = "function", r), n);
288
- return pt(e, t);
289
- }
290
- function xe(e, n, t) {
291
- if (t < Y)
292
- throw new Error("invalid exponent, negatives unsupported");
293
- if (t === Y)
294
- return e.ONE;
295
- if (t === H)
296
- return n;
297
- let r = e.ONE, i = n;
298
- for (; t > Y; )
299
- t & H && (r = e.mul(r, i)), i = e.sqr(i), t >>= H;
300
- return r;
301
- }
302
- function te(e, n, t = !1) {
303
- const r = new Array(n.length).fill(t ? e.ZERO : void 0), i = n.reduce((a, u, o) => e.is0(u) ? a : (r[o] = a, e.mul(a, u)), e.ONE), s = e.inv(i);
304
- return n.reduceRight((a, u, o) => e.is0(u) ? a : (r[o] = e.mul(a, r[o]), e.mul(a, u)), s), r;
305
- }
306
- function Vt(e, n) {
307
- const t = (e.ORDER - H) / tt, r = e.pow(n, t), i = e.eql(r, e.ONE), s = e.eql(r, e.ZERO), a = e.eql(r, e.neg(e.ONE));
308
- if (!i && !s && !a)
309
- throw new Error("invalid Legendre symbol result");
310
- return i ? 1 : s ? 0 : -1;
311
- }
312
- function ee(e, n) {
313
- n !== void 0 && ce(n);
314
- const t = n !== void 0 ? n : e.toString(2).length, r = Math.ceil(t / 8);
315
- return { nBitLength: t, nByteLength: r };
316
- }
317
- function _t(e, n, t = !1, r = {}) {
318
- if (e <= Y)
319
- throw new Error("invalid field: expected ORDER > 0, got " + e);
320
- const { nBitLength: i, nByteLength: s } = ee(e, n);
321
- if (s > 2048)
322
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
323
- let a;
324
- const u = Object.freeze({
325
- ORDER: e,
326
- isLE: t,
327
- BITS: i,
328
- BYTES: s,
329
- MASK: mt(i),
330
- ZERO: Y,
331
- ONE: H,
332
- create: (o) => M(o, e),
333
- isValid: (o) => {
334
- if (typeof o != "bigint")
335
- throw new Error("invalid field element: expected bigint, got " + typeof o);
336
- return Y <= o && o < e;
337
- },
338
- is0: (o) => o === Y,
339
- isOdd: (o) => (o & H) === H,
340
- neg: (o) => M(-o, e),
341
- eql: (o, d) => o === d,
342
- sqr: (o) => M(o * o, e),
343
- add: (o, d) => M(o + d, e),
344
- sub: (o, d) => M(o - d, e),
345
- mul: (o, d) => M(o * d, e),
346
- pow: (o, d) => xe(u, o, d),
347
- div: (o, d) => M(o * qt(d, e), e),
348
- // Same as above, but doesn't normalize
349
- sqrN: (o) => o * o,
350
- addN: (o, d) => o + d,
351
- subN: (o, d) => o - d,
352
- mulN: (o, d) => o * d,
353
- inv: (o) => qt(o, e),
354
- sqrt: r.sqrt || ((o) => (a || (a = be(e)), a(u, o))),
355
- toBytes: (o) => t ? Dt(o, s) : dt(o, s),
356
- fromBytes: (o) => {
357
- if (o.length !== s)
358
- throw new Error("Field.fromBytes: expected " + s + " bytes, got " + o.length);
359
- return t ? Wt(o) : et(o);
360
- },
361
- // TODO: we don't need it here, move out to separate fn
362
- invertBatch: (o) => te(u, o),
363
- // We can't move this out because Fp6, Fp12 implement it
364
- // and it's unclear what to return in there.
365
- cmov: (o, d, m) => m ? d : o
366
- });
367
- return Object.freeze(u);
368
- }
369
- function ne(e) {
370
- if (typeof e != "bigint")
371
- throw new Error("field order must be bigint");
372
- const n = e.toString(2).length;
373
- return Math.ceil(n / 8);
374
- }
375
- function re(e) {
376
- const n = ne(e);
377
- return n + Math.ceil(n / 2);
378
- }
379
- function Se(e, n, t = !1) {
380
- const r = e.length, i = ne(n), s = re(n);
381
- if (r < 16 || r < s || r > 1024)
382
- throw new Error("expected " + s + "-1024 bytes of input, got " + r);
383
- const a = t ? Wt(e) : et(e), u = M(a, n - H) + H;
384
- return t ? Dt(u, i) : dt(u, i);
385
- }
386
- const Mt = BigInt(0), Rt = BigInt(1);
387
- function vt(e, n) {
388
- const t = n.negate();
389
- return e ? t : n;
390
- }
391
- function oe(e, n) {
392
- if (!Number.isSafeInteger(e) || e <= 0 || e > n)
393
- throw new Error("invalid window size, expected [1.." + n + "], got W=" + e);
394
- }
395
- function xt(e, n) {
396
- oe(e, n);
397
- const t = Math.ceil(n / e) + 1, r = 2 ** (e - 1), i = 2 ** e, s = mt(e), a = BigInt(e);
398
- return { windows: t, windowSize: r, mask: s, maxNumber: i, shiftBy: a };
399
- }
400
- function Yt(e, n, t) {
401
- const { windowSize: r, mask: i, maxNumber: s, shiftBy: a } = t;
402
- let u = Number(e & i), o = e >> a;
403
- u > r && (u -= s, o += Rt);
404
- const d = n * r, m = d + Math.abs(u) - 1, A = u === 0, I = u < 0, z = n % 2 !== 0;
405
- return { nextN: o, offset: m, isZero: A, isNeg: I, isNegF: z, offsetF: d };
406
- }
407
- function Ae(e, n) {
408
- if (!Array.isArray(e))
409
- throw new Error("array expected");
410
- e.forEach((t, r) => {
411
- if (!(t instanceof n))
412
- throw new Error("invalid point at index " + r);
413
- });
414
- }
415
- function Ne(e, n) {
416
- if (!Array.isArray(e))
417
- throw new Error("array of scalars expected");
418
- e.forEach((t, r) => {
419
- if (!n.isValid(t))
420
- throw new Error("invalid scalar at index " + r);
421
- });
422
- }
423
- const St = /* @__PURE__ */ new WeakMap(), ie = /* @__PURE__ */ new WeakMap();
424
- function At(e) {
425
- return ie.get(e) || 1;
426
- }
427
- function Ie(e, n) {
428
- return {
429
- constTimeNegate: vt,
430
- hasPrecomputes(t) {
431
- return At(t) !== 1;
432
- },
433
- // non-const time multiplication ladder
434
- unsafeLadder(t, r, i = e.ZERO) {
435
- let s = t;
436
- for (; r > Mt; )
437
- r & Rt && (i = i.add(s)), s = s.double(), r >>= Rt;
438
- return i;
439
- },
440
- /**
441
- * Creates a wNAF precomputation window. Used for caching.
442
- * Default window size is set by `utils.precompute()` and is equal to 8.
443
- * Number of precomputed points depends on the curve size:
444
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
445
- * - 𝑊 is the window size
446
- * - 𝑛 is the bitlength of the curve order.
447
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
448
- * @param elm Point instance
449
- * @param W window size
450
- * @returns precomputed point tables flattened to a single array
451
- */
452
- precomputeWindow(t, r) {
453
- const { windows: i, windowSize: s } = xt(r, n), a = [];
454
- let u = t, o = u;
455
- for (let d = 0; d < i; d++) {
456
- o = u, a.push(o);
457
- for (let m = 1; m < s; m++)
458
- o = o.add(u), a.push(o);
459
- u = o.double();
460
- }
461
- return a;
462
- },
463
- /**
464
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
465
- * @param W window size
466
- * @param precomputes precomputed tables
467
- * @param n scalar (we don't check here, but should be less than curve order)
468
- * @returns real and fake (for const-time) points
469
- */
470
- wNAF(t, r, i) {
471
- let s = e.ZERO, a = e.BASE;
472
- const u = xt(t, n);
473
- for (let o = 0; o < u.windows; o++) {
474
- const { nextN: d, offset: m, isZero: A, isNeg: I, isNegF: z, offsetF: T } = Yt(i, o, u);
475
- i = d, A ? a = a.add(vt(z, r[T])) : s = s.add(vt(I, r[m]));
476
- }
477
- return { p: s, f: a };
478
- },
479
- /**
480
- * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
481
- * @param W window size
482
- * @param precomputes precomputed tables
483
- * @param n scalar (we don't check here, but should be less than curve order)
484
- * @param acc accumulator point to add result of multiplication
485
- * @returns point
486
- */
487
- wNAFUnsafe(t, r, i, s = e.ZERO) {
488
- const a = xt(t, n);
489
- for (let u = 0; u < a.windows && i !== Mt; u++) {
490
- const { nextN: o, offset: d, isZero: m, isNeg: A } = Yt(i, u, a);
491
- if (i = o, !m) {
492
- const I = r[d];
493
- s = s.add(A ? I.negate() : I);
494
- }
495
- }
496
- return s;
497
- },
498
- getPrecomputes(t, r, i) {
499
- let s = St.get(r);
500
- return s || (s = this.precomputeWindow(r, t), t !== 1 && St.set(r, i(s))), s;
501
- },
502
- wNAFCached(t, r, i) {
503
- const s = At(t);
504
- return this.wNAF(s, this.getPrecomputes(s, t, i), r);
505
- },
506
- wNAFCachedUnsafe(t, r, i, s) {
507
- const a = At(t);
508
- return a === 1 ? this.unsafeLadder(t, r, s) : this.wNAFUnsafe(a, this.getPrecomputes(a, t, i), r, s);
509
- },
510
- // We calculate precomputes for elliptic curve point multiplication
511
- // using windowed method. This specifies window size and
512
- // stores precomputed values. Usually only base point would be precomputed.
513
- setWindowSize(t, r) {
514
- oe(r, n), ie.set(t, r), St.delete(t);
515
- }
516
- };
517
- }
518
- function Oe(e, n, t, r) {
519
- Ae(t, e), Ne(r, n);
520
- const i = t.length, s = r.length;
521
- if (i !== s)
522
- throw new Error("arrays of points and scalars must have equal length");
523
- const a = e.ZERO, u = we(BigInt(i));
524
- let o = 1;
525
- u > 12 ? o = u - 3 : u > 4 ? o = u - 2 : u > 0 && (o = 2);
526
- const d = mt(o), m = new Array(Number(d) + 1).fill(a), A = Math.floor((n.BITS - 1) / o) * o;
527
- let I = a;
528
- for (let z = A; z >= 0; z -= o) {
529
- m.fill(a);
530
- for (let g = 0; g < s; g++) {
531
- const k = r[g], U = Number(k >> BigInt(z) & d);
532
- m[U] = m[U].add(t[g]);
533
- }
534
- let T = a;
535
- for (let g = m.length - 1, k = a; g > 0; g--)
536
- k = k.add(m[g]), T = T.add(k);
537
- if (I = I.add(T), z !== 0)
538
- for (let g = 0; g < o; g++)
539
- I = I.double();
540
- }
541
- return I;
542
- }
543
- function se(e) {
544
- return ve(e.Fp), pt(e, {
545
- n: "bigint",
546
- h: "bigint",
547
- Gx: "field",
548
- Gy: "field"
549
- }, {
550
- nBitLength: "isSafeInteger",
551
- nByteLength: "isSafeInteger"
552
- }), Object.freeze({
553
- ...ee(e.n, e.nBitLength),
554
- ...e,
555
- p: e.Fp.ORDER
556
- });
557
- }
558
- function jt(e) {
559
- e.lowS !== void 0 && at("lowS", e.lowS), e.prehash !== void 0 && at("prehash", e.prehash);
560
- }
561
- function qe(e) {
562
- const n = se(e);
563
- pt(n, {
564
- a: "field",
565
- b: "field"
566
- }, {
567
- allowInfinityPoint: "boolean",
568
- allowedPrivateKeyLengths: "array",
569
- clearCofactor: "function",
570
- fromBytes: "function",
571
- isTorsionFree: "function",
572
- toBytes: "function",
573
- wrapPrivateKey: "boolean"
574
- });
575
- const { endo: t, Fp: r, a: i } = n;
576
- if (t) {
577
- if (!r.eql(i, r.ZERO))
578
- throw new Error("invalid endo: CURVE.a must be 0");
579
- if (typeof t != "object" || typeof t.beta != "bigint" || typeof t.splitScalar != "function")
580
- throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
581
- }
582
- return Object.freeze({ ...n });
583
- }
584
- class Re extends Error {
585
- constructor(n = "") {
586
- super(n);
587
- }
588
- }
589
- const D = {
590
- // asn.1 DER encoding utils
591
- Err: Re,
592
- // Basic building block is TLV (Tag-Length-Value)
593
- _tlv: {
594
- encode: (e, n) => {
595
- const { Err: t } = D;
596
- if (e < 0 || e > 256)
597
- throw new t("tlv.encode: wrong tag");
598
- if (n.length & 1)
599
- throw new t("tlv.encode: unpadded data");
600
- const r = n.length / 2, i = ht(r);
601
- if (i.length / 2 & 128)
602
- throw new t("tlv.encode: long form length too big");
603
- const s = r > 127 ? ht(i.length / 2 | 128) : "";
604
- return ht(e) + s + i + n;
605
- },
606
- // v - value, l - left bytes (unparsed)
607
- decode(e, n) {
608
- const { Err: t } = D;
609
- let r = 0;
610
- if (e < 0 || e > 256)
611
- throw new t("tlv.encode: wrong tag");
612
- if (n.length < 2 || n[r++] !== e)
613
- throw new t("tlv.decode: wrong tlv");
614
- const i = n[r++], s = !!(i & 128);
615
- let a = 0;
616
- if (!s)
617
- a = i;
618
- else {
619
- const o = i & 127;
620
- if (!o)
621
- throw new t("tlv.decode(long): indefinite length not supported");
622
- if (o > 4)
623
- throw new t("tlv.decode(long): byte length is too big");
624
- const d = n.subarray(r, r + o);
625
- if (d.length !== o)
626
- throw new t("tlv.decode: length bytes not complete");
627
- if (d[0] === 0)
628
- throw new t("tlv.decode(long): zero leftmost byte");
629
- for (const m of d)
630
- a = a << 8 | m;
631
- if (r += o, a < 128)
632
- throw new t("tlv.decode(long): not minimal encoding");
633
- }
634
- const u = n.subarray(r, r + a);
635
- if (u.length !== a)
636
- throw new t("tlv.decode: wrong value length");
637
- return { v: u, l: n.subarray(r + a) };
638
- }
639
- },
640
- // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
641
- // since we always use positive integers here. It must always be empty:
642
- // - add zero byte if exists
643
- // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
644
- _int: {
645
- encode(e) {
646
- const { Err: n } = D;
647
- if (e < X)
648
- throw new n("integer: negative integers are not allowed");
649
- let t = ht(e);
650
- if (Number.parseInt(t[0], 16) & 8 && (t = "00" + t), t.length & 1)
651
- throw new n("unexpected DER parsing assertion: unpadded hex");
652
- return t;
653
- },
654
- decode(e) {
655
- const { Err: n } = D;
656
- if (e[0] & 128)
657
- throw new n("invalid signature integer: negative");
658
- if (e[0] === 0 && !(e[1] & 128))
659
- throw new n("invalid signature integer: unnecessary leading zero");
660
- return et(e);
661
- }
662
- },
663
- toSig(e) {
664
- const { Err: n, _int: t, _tlv: r } = D, i = K("signature", e), { v: s, l: a } = r.decode(48, i);
665
- if (a.length)
666
- throw new n("invalid signature: left bytes after parsing");
667
- const { v: u, l: o } = r.decode(2, s), { v: d, l: m } = r.decode(2, o);
668
- if (m.length)
669
- throw new n("invalid signature: left bytes after parsing");
670
- return { r: t.decode(u), s: t.decode(d) };
671
- },
672
- hexFromSig(e) {
673
- const { _tlv: n, _int: t } = D, r = n.encode(2, t.encode(e.r)), i = n.encode(2, t.encode(e.s)), s = r + i;
674
- return n.encode(48, s);
675
- }
676
- };
677
- function Nt(e, n) {
678
- return lt(dt(e, n));
679
- }
680
- const X = BigInt(0), L = BigInt(1);
681
- BigInt(2);
682
- const It = BigInt(3), Ze = BigInt(4);
683
- function ze(e) {
684
- const n = qe(e), { Fp: t } = n, r = _t(n.n, n.nBitLength), i = n.toBytes || ((x, f, h) => {
685
- const p = f.toAffine();
686
- return gt(Uint8Array.from([4]), t.toBytes(p.x), t.toBytes(p.y));
687
- }), s = n.fromBytes || ((x) => {
688
- const f = x.subarray(1), h = t.fromBytes(f.subarray(0, t.BYTES)), p = t.fromBytes(f.subarray(t.BYTES, 2 * t.BYTES));
689
- return { x: h, y: p };
690
- });
691
- function a(x) {
692
- const { a: f, b: h } = n, p = t.sqr(x), B = t.mul(p, x);
693
- return t.add(t.add(B, t.mul(x, f)), h);
694
- }
695
- function u(x, f) {
696
- const h = t.sqr(f), p = a(x);
697
- return t.eql(h, p);
698
- }
699
- if (!u(n.Gx, n.Gy))
700
- throw new Error("bad curve params: generator point");
701
- const o = t.mul(t.pow(n.a, It), Ze), d = t.mul(t.sqr(n.b), BigInt(27));
702
- if (t.is0(t.add(o, d)))
703
- throw new Error("bad curve params: a or b");
704
- function m(x) {
705
- return Lt(x, L, n.n);
706
- }
707
- function A(x) {
708
- const { allowedPrivateKeyLengths: f, nByteLength: h, wrapPrivateKey: p, n: B } = n;
709
- if (f && typeof x != "bigint") {
710
- if (ut(x) && (x = lt(x)), typeof x != "string" || !f.includes(x.length))
711
- throw new Error("invalid private key");
712
- x = x.padStart(h * 2, "0");
713
- }
714
- let O;
715
- try {
716
- O = typeof x == "bigint" ? x : et(K("private key", x, h));
717
- } catch {
718
- throw new Error("invalid private key, expected hex or " + h + " bytes, got " + typeof x);
719
- }
720
- return p && (O = M(O, B)), it("private key", O, L, B), O;
721
- }
722
- function I(x) {
723
- if (!(x instanceof g))
724
- throw new Error("ProjectivePoint expected");
725
- }
726
- const z = Ht((x, f) => {
727
- const { px: h, py: p, pz: B } = x;
728
- if (t.eql(B, t.ONE))
729
- return { x: h, y: p };
730
- const O = x.is0();
731
- f == null && (f = O ? t.ONE : t.inv(B));
732
- const R = t.mul(h, f), q = t.mul(p, f), y = t.mul(B, f);
733
- if (O)
734
- return { x: t.ZERO, y: t.ZERO };
735
- if (!t.eql(y, t.ONE))
736
- throw new Error("invZ was invalid");
737
- return { x: R, y: q };
738
- }), T = Ht((x) => {
739
- if (x.is0()) {
740
- if (n.allowInfinityPoint && !t.is0(x.py))
741
- return;
742
- throw new Error("bad point: ZERO");
743
- }
744
- const { x: f, y: h } = x.toAffine();
745
- if (!t.isValid(f) || !t.isValid(h))
746
- throw new Error("bad point: x or y not FE");
747
- if (!u(f, h))
748
- throw new Error("bad point: equation left != right");
749
- if (!x.isTorsionFree())
750
- throw new Error("bad point: not in prime-order subgroup");
751
- return !0;
752
- });
753
- class g {
754
- constructor(f, h, p) {
755
- if (f == null || !t.isValid(f))
756
- throw new Error("x required");
757
- if (h == null || !t.isValid(h) || t.is0(h))
758
- throw new Error("y required");
759
- if (p == null || !t.isValid(p))
760
- throw new Error("z required");
761
- this.px = f, this.py = h, this.pz = p, Object.freeze(this);
762
- }
763
- // Does not validate if the point is on-curve.
764
- // Use fromHex instead, or call assertValidity() later.
765
- static fromAffine(f) {
766
- const { x: h, y: p } = f || {};
767
- if (!f || !t.isValid(h) || !t.isValid(p))
768
- throw new Error("invalid affine point");
769
- if (f instanceof g)
770
- throw new Error("projective point not allowed");
771
- const B = (O) => t.eql(O, t.ZERO);
772
- return B(h) && B(p) ? g.ZERO : new g(h, p, t.ONE);
773
- }
774
- get x() {
775
- return this.toAffine().x;
776
- }
777
- get y() {
778
- return this.toAffine().y;
779
- }
780
- /**
781
- * Takes a bunch of Projective Points but executes only one
782
- * inversion on all of them. Inversion is very slow operation,
783
- * so this improves performance massively.
784
- * Optimization: converts a list of projective points to a list of identical points with Z=1.
785
- */
786
- static normalizeZ(f) {
787
- const h = te(t, f.map((p) => p.pz));
788
- return f.map((p, B) => p.toAffine(h[B])).map(g.fromAffine);
789
- }
790
- /**
791
- * Converts hash string or Uint8Array to Point.
792
- * @param hex short/long ECDSA hex
793
- */
794
- static fromHex(f) {
795
- const h = g.fromAffine(s(K("pointHex", f)));
796
- return h.assertValidity(), h;
797
- }
798
- // Multiplies generator point by privateKey.
799
- static fromPrivateKey(f) {
800
- return g.BASE.multiply(A(f));
801
- }
802
- // Multiscalar Multiplication
803
- static msm(f, h) {
804
- return Oe(g, r, f, h);
805
- }
806
- // "Private method", don't use it directly
807
- _setWindowSize(f) {
808
- $.setWindowSize(this, f);
809
- }
810
- // A point on curve is valid if it conforms to equation.
811
- assertValidity() {
812
- T(this);
813
- }
814
- hasEvenY() {
815
- const { y: f } = this.toAffine();
816
- if (t.isOdd)
817
- return !t.isOdd(f);
818
- throw new Error("Field doesn't support isOdd");
819
- }
820
- /**
821
- * Compare one point to another.
822
- */
823
- equals(f) {
824
- I(f);
825
- const { px: h, py: p, pz: B } = this, { px: O, py: R, pz: q } = f, y = t.eql(t.mul(h, q), t.mul(O, B)), N = t.eql(t.mul(p, q), t.mul(R, B));
826
- return y && N;
827
- }
828
- /**
829
- * Flips point to one corresponding to (x, -y) in Affine coordinates.
830
- */
831
- negate() {
832
- return new g(this.px, t.neg(this.py), this.pz);
833
- }
834
- // Renes-Costello-Batina exception-free doubling formula.
835
- // There is 30% faster Jacobian formula, but it is not complete.
836
- // https://eprint.iacr.org/2015/1060, algorithm 3
837
- // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
838
- double() {
839
- const { a: f, b: h } = n, p = t.mul(h, It), { px: B, py: O, pz: R } = this;
840
- let q = t.ZERO, y = t.ZERO, N = t.ZERO, E = t.mul(B, B), _ = t.mul(O, O), l = t.mul(R, R), c = t.mul(B, O);
841
- return c = t.add(c, c), N = t.mul(B, R), N = t.add(N, N), q = t.mul(f, N), y = t.mul(p, l), y = t.add(q, y), q = t.sub(_, y), y = t.add(_, y), y = t.mul(q, y), q = t.mul(c, q), N = t.mul(p, N), l = t.mul(f, l), c = t.sub(E, l), c = t.mul(f, c), c = t.add(c, N), N = t.add(E, E), E = t.add(N, E), E = t.add(E, l), E = t.mul(E, c), y = t.add(y, E), l = t.mul(O, R), l = t.add(l, l), E = t.mul(l, c), q = t.sub(q, E), N = t.mul(l, _), N = t.add(N, N), N = t.add(N, N), new g(q, y, N);
842
- }
843
- // Renes-Costello-Batina exception-free addition formula.
844
- // There is 30% faster Jacobian formula, but it is not complete.
845
- // https://eprint.iacr.org/2015/1060, algorithm 1
846
- // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
847
- add(f) {
848
- I(f);
849
- const { px: h, py: p, pz: B } = this, { px: O, py: R, pz: q } = f;
850
- let y = t.ZERO, N = t.ZERO, E = t.ZERO;
851
- const _ = n.a, l = t.mul(n.b, It);
852
- let c = t.mul(h, O), w = t.mul(p, R), S = t.mul(B, q), b = t.add(h, p), v = t.add(O, R);
853
- b = t.mul(b, v), v = t.add(c, w), b = t.sub(b, v), v = t.add(h, B);
854
- let Z = t.add(O, q);
855
- return v = t.mul(v, Z), Z = t.add(c, S), v = t.sub(v, Z), Z = t.add(p, B), y = t.add(R, q), Z = t.mul(Z, y), y = t.add(w, S), Z = t.sub(Z, y), E = t.mul(_, v), y = t.mul(l, S), E = t.add(y, E), y = t.sub(w, E), E = t.add(w, E), N = t.mul(y, E), w = t.add(c, c), w = t.add(w, c), S = t.mul(_, S), v = t.mul(l, v), w = t.add(w, S), S = t.sub(c, S), S = t.mul(_, S), v = t.add(v, S), c = t.mul(w, v), N = t.add(N, c), c = t.mul(Z, v), y = t.mul(b, y), y = t.sub(y, c), c = t.mul(b, w), E = t.mul(Z, E), E = t.add(E, c), new g(y, N, E);
856
- }
857
- subtract(f) {
858
- return this.add(f.negate());
859
- }
860
- is0() {
861
- return this.equals(g.ZERO);
862
- }
863
- wNAF(f) {
864
- return $.wNAFCached(this, f, g.normalizeZ);
865
- }
866
- /**
867
- * Non-constant-time multiplication. Uses double-and-add algorithm.
868
- * It's faster, but should only be used when you don't care about
869
- * an exposed private key e.g. sig verification, which works over *public* keys.
870
- */
871
- multiplyUnsafe(f) {
872
- const { endo: h, n: p } = n;
873
- it("scalar", f, X, p);
874
- const B = g.ZERO;
875
- if (f === X)
876
- return B;
877
- if (this.is0() || f === L)
878
- return this;
879
- if (!h || $.hasPrecomputes(this))
880
- return $.wNAFCachedUnsafe(this, f, g.normalizeZ);
881
- let { k1neg: O, k1: R, k2neg: q, k2: y } = h.splitScalar(f), N = B, E = B, _ = this;
882
- for (; R > X || y > X; )
883
- R & L && (N = N.add(_)), y & L && (E = E.add(_)), _ = _.double(), R >>= L, y >>= L;
884
- return O && (N = N.negate()), q && (E = E.negate()), E = new g(t.mul(E.px, h.beta), E.py, E.pz), N.add(E);
885
- }
886
- /**
887
- * Constant time multiplication.
888
- * Uses wNAF method. Windowed method may be 10% faster,
889
- * but takes 2x longer to generate and consumes 2x memory.
890
- * Uses precomputes when available.
891
- * Uses endomorphism for Koblitz curves.
892
- * @param scalar by which the point would be multiplied
893
- * @returns New point
894
- */
895
- multiply(f) {
896
- const { endo: h, n: p } = n;
897
- it("scalar", f, L, p);
898
- let B, O;
899
- if (h) {
900
- const { k1neg: R, k1: q, k2neg: y, k2: N } = h.splitScalar(f);
901
- let { p: E, f: _ } = this.wNAF(q), { p: l, f: c } = this.wNAF(N);
902
- E = $.constTimeNegate(R, E), l = $.constTimeNegate(y, l), l = new g(t.mul(l.px, h.beta), l.py, l.pz), B = E.add(l), O = _.add(c);
903
- } else {
904
- const { p: R, f: q } = this.wNAF(f);
905
- B = R, O = q;
906
- }
907
- return g.normalizeZ([B, O])[0];
908
- }
909
- /**
910
- * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
911
- * Not using Strauss-Shamir trick: precomputation tables are faster.
912
- * The trick could be useful if both P and Q are not G (not in our case).
913
- * @returns non-zero affine point
914
- */
915
- multiplyAndAddUnsafe(f, h, p) {
916
- const B = g.BASE, O = (q, y) => y === X || y === L || !q.equals(B) ? q.multiplyUnsafe(y) : q.multiply(y), R = O(this, h).add(O(f, p));
917
- return R.is0() ? void 0 : R;
918
- }
919
- // Converts Projective point to affine (x, y) coordinates.
920
- // Can accept precomputed Z^-1 - for example, from invertBatch.
921
- // (x, y, z) ∋ (x=x/z, y=y/z)
922
- toAffine(f) {
923
- return z(this, f);
924
- }
925
- isTorsionFree() {
926
- const { h: f, isTorsionFree: h } = n;
927
- if (f === L)
928
- return !0;
929
- if (h)
930
- return h(g, this);
931
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
932
- }
933
- clearCofactor() {
934
- const { h: f, clearCofactor: h } = n;
935
- return f === L ? this : h ? h(g, this) : this.multiplyUnsafe(n.h);
936
- }
937
- toRawBytes(f = !0) {
938
- return at("isCompressed", f), this.assertValidity(), i(g, this, f);
939
- }
940
- toHex(f = !0) {
941
- return at("isCompressed", f), lt(this.toRawBytes(f));
942
- }
943
- }
944
- g.BASE = new g(n.Gx, n.Gy, t.ONE), g.ZERO = new g(t.ZERO, t.ONE, t.ZERO);
945
- const { endo: k, nBitLength: U } = n, $ = Ie(g, k ? Math.ceil(U / 2) : U);
946
- return {
947
- CURVE: n,
948
- ProjectivePoint: g,
949
- normPrivateKeyToScalar: A,
950
- weierstrassEquation: a,
951
- isWithinCurveOrder: m
952
- };
953
- }
954
- function Te(e) {
955
- const n = se(e);
956
- return pt(n, {
957
- hash: "hash",
958
- hmac: "function",
959
- randomBytes: "function"
960
- }, {
961
- bits2int: "function",
962
- bits2int_modN: "function",
963
- lowS: "boolean"
964
- }), Object.freeze({ lowS: !0, ...n });
965
- }
966
- function Ue(e) {
967
- const n = Te(e), { Fp: t, n: r, nByteLength: i, nBitLength: s } = n, a = t.BYTES + 1, u = 2 * t.BYTES + 1;
968
- function o(l) {
969
- return M(l, r);
970
- }
971
- function d(l) {
972
- return qt(l, r);
973
- }
974
- const { ProjectivePoint: m, normPrivateKeyToScalar: A, weierstrassEquation: I, isWithinCurveOrder: z } = ze({
975
- ...n,
976
- toBytes(l, c, w) {
977
- const S = c.toAffine(), b = t.toBytes(S.x), v = gt;
978
- return at("isCompressed", w), w ? v(Uint8Array.from([c.hasEvenY() ? 2 : 3]), b) : v(Uint8Array.from([4]), b, t.toBytes(S.y));
979
- },
980
- fromBytes(l) {
981
- const c = l.length, w = l[0], S = l.subarray(1);
982
- if (c === a && (w === 2 || w === 3)) {
983
- const b = et(S);
984
- if (!Lt(b, L, t.ORDER))
985
- throw new Error("Point is not on curve");
986
- const v = I(b);
987
- let Z;
988
- try {
989
- Z = t.sqrt(v);
990
- } catch (P) {
991
- const V = P instanceof Error ? ": " + P.message : "";
992
- throw new Error("Point is not on curve" + V);
993
- }
994
- const C = (Z & L) === L;
995
- return (w & 1) === 1 !== C && (Z = t.neg(Z)), { x: b, y: Z };
996
- } else if (c === u && w === 4) {
997
- const b = t.fromBytes(S.subarray(0, t.BYTES)), v = t.fromBytes(S.subarray(t.BYTES, 2 * t.BYTES));
998
- return { x: b, y: v };
999
- } else {
1000
- const b = a, v = u;
1001
- throw new Error("invalid Point, expected length of " + b + ", or uncompressed " + v + ", got " + c);
1002
- }
1003
- }
1004
- });
1005
- function T(l) {
1006
- const c = r >> L;
1007
- return l > c;
1008
- }
1009
- function g(l) {
1010
- return T(l) ? o(-l) : l;
1011
- }
1012
- const k = (l, c, w) => et(l.slice(c, w));
1013
- class U {
1014
- constructor(c, w, S) {
1015
- it("r", c, L, r), it("s", w, L, r), this.r = c, this.s = w, S != null && (this.recovery = S), Object.freeze(this);
1016
- }
1017
- // pair (bytes of r, bytes of s)
1018
- static fromCompact(c) {
1019
- const w = i;
1020
- return c = K("compactSignature", c, w * 2), new U(k(c, 0, w), k(c, w, 2 * w));
1021
- }
1022
- // DER encoded ECDSA signature
1023
- // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
1024
- static fromDER(c) {
1025
- const { r: w, s: S } = D.toSig(K("DER", c));
1026
- return new U(w, S);
1027
- }
1028
- /**
1029
- * @todo remove
1030
- * @deprecated
1031
- */
1032
- assertValidity() {
1033
- }
1034
- addRecoveryBit(c) {
1035
- return new U(this.r, this.s, c);
1036
- }
1037
- recoverPublicKey(c) {
1038
- const { r: w, s: S, recovery: b } = this, v = B(K("msgHash", c));
1039
- if (b == null || ![0, 1, 2, 3].includes(b))
1040
- throw new Error("recovery id invalid");
1041
- const Z = b === 2 || b === 3 ? w + n.n : w;
1042
- if (Z >= t.ORDER)
1043
- throw new Error("recovery id 2 or 3 invalid");
1044
- const C = (b & 1) === 0 ? "02" : "03", G = m.fromHex(C + Nt(Z, t.BYTES)), P = d(Z), V = o(-v * P), nt = o(S * P), F = m.BASE.multiplyAndAddUnsafe(G, V, nt);
1045
- if (!F)
1046
- throw new Error("point at infinify");
1047
- return F.assertValidity(), F;
1048
- }
1049
- // Signatures should be low-s, to prevent malleability.
1050
- hasHighS() {
1051
- return T(this.s);
1052
- }
1053
- normalizeS() {
1054
- return this.hasHighS() ? new U(this.r, o(-this.s), this.recovery) : this;
1055
- }
1056
- // DER-encoded
1057
- toDERRawBytes() {
1058
- return wt(this.toDERHex());
1059
- }
1060
- toDERHex() {
1061
- return D.hexFromSig(this);
1062
- }
1063
- // padded bytes of r, then padded bytes of s
1064
- toCompactRawBytes() {
1065
- return wt(this.toCompactHex());
1066
- }
1067
- toCompactHex() {
1068
- const c = i;
1069
- return Nt(this.r, c) + Nt(this.s, c);
1070
- }
1071
- }
1072
- const $ = {
1073
- isValidPrivateKey(l) {
1074
- try {
1075
- return A(l), !0;
1076
- } catch {
1077
- return !1;
1078
- }
1079
- },
1080
- normPrivateKeyToScalar: A,
1081
- /**
1082
- * Produces cryptographically secure private key from random of size
1083
- * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
1084
- */
1085
- randomPrivateKey: () => {
1086
- const l = re(n.n);
1087
- return Se(n.randomBytes(l), n.n);
1088
- },
1089
- /**
1090
- * Creates precompute table for an arbitrary EC point. Makes point "cached".
1091
- * Allows to massively speed-up `point.multiply(scalar)`.
1092
- * @returns cached point
1093
- * @example
1094
- * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
1095
- * fast.multiply(privKey); // much faster ECDH now
1096
- */
1097
- precompute(l = 8, c = m.BASE) {
1098
- return c._setWindowSize(l), c.multiply(BigInt(3)), c;
1099
- }
1100
- };
1101
- function x(l, c = !0) {
1102
- return m.fromPrivateKey(l).toRawBytes(c);
1103
- }
1104
- function f(l) {
1105
- if (typeof l == "bigint")
1106
- return !1;
1107
- if (l instanceof m)
1108
- return !0;
1109
- const w = K("key", l).length, S = t.BYTES, b = S + 1, v = 2 * S + 1;
1110
- if (!(n.allowedPrivateKeyLengths || i === b))
1111
- return w === b || w === v;
1112
- }
1113
- function h(l, c, w = !0) {
1114
- if (f(l) === !0)
1115
- throw new Error("first arg must be private key");
1116
- if (f(c) === !1)
1117
- throw new Error("second arg must be public key");
1118
- return m.fromHex(c).multiply(A(l)).toRawBytes(w);
1119
- }
1120
- const p = n.bits2int || function(l) {
1121
- if (l.length > 8192)
1122
- throw new Error("input is too large");
1123
- const c = et(l), w = l.length * 8 - s;
1124
- return w > 0 ? c >> BigInt(w) : c;
1125
- }, B = n.bits2int_modN || function(l) {
1126
- return o(p(l));
1127
- }, O = mt(s);
1128
- function R(l) {
1129
- return it("num < 2^" + s, l, X, O), dt(l, i);
1130
- }
1131
- function q(l, c, w = y) {
1132
- if (["recovered", "canonical"].some((Q) => Q in w))
1133
- throw new Error("sign() legacy options not supported");
1134
- const { hash: S, randomBytes: b } = n;
1135
- let { lowS: v, prehash: Z, extraEntropy: C } = w;
1136
- v == null && (v = !0), l = K("msgHash", l), jt(w), Z && (l = K("prehashed msgHash", S(l)));
1137
- const G = B(l), P = A(c), V = [R(P), R(G)];
1138
- if (C != null && C !== !1) {
1139
- const Q = C === !0 ? b(t.BYTES) : C;
1140
- V.push(K("extraEntropy", Q));
1141
- }
1142
- const nt = gt(...V), F = G;
1143
- function yt(Q) {
1144
- const rt = p(Q);
1145
- if (!z(rt))
1146
- return;
1147
- const Et = d(rt), st = m.BASE.multiply(rt).toAffine(), J = o(st.x);
1148
- if (J === X)
1149
- return;
1150
- const ft = o(Et * o(F + J * P));
1151
- if (ft === X)
1152
- return;
1153
- let ct = (st.x === J ? 0 : 2) | Number(st.y & L), ot = ft;
1154
- return v && T(ft) && (ot = g(ft), ct ^= 1), new U(J, ot, ct);
1155
- }
1156
- return { seed: nt, k2sig: yt };
1157
- }
1158
- const y = { lowS: n.lowS, prehash: !1 }, N = { lowS: n.lowS, prehash: !1 };
1159
- function E(l, c, w = y) {
1160
- const { seed: S, k2sig: b } = q(l, c, w), v = n;
1161
- return ge(v.hash.outputLen, v.nByteLength, v.hmac)(S, b);
1162
- }
1163
- m.BASE._setWindowSize(8);
1164
- function _(l, c, w, S = N) {
1165
- var ct;
1166
- const b = l;
1167
- c = K("msgHash", c), w = K("publicKey", w);
1168
- const { lowS: v, prehash: Z, format: C } = S;
1169
- if (jt(S), "strict" in S)
1170
- throw new Error("options.strict was renamed to lowS");
1171
- if (C !== void 0 && C !== "compact" && C !== "der")
1172
- throw new Error("format must be compact or der");
1173
- const G = typeof b == "string" || ut(b), P = !G && !C && typeof b == "object" && b !== null && typeof b.r == "bigint" && typeof b.s == "bigint";
1174
- if (!G && !P)
1175
- throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
1176
- let V, nt;
1177
- try {
1178
- if (P && (V = new U(b.r, b.s)), G) {
1179
- try {
1180
- C !== "compact" && (V = U.fromDER(b));
1181
- } catch (ot) {
1182
- if (!(ot instanceof D.Err))
1183
- throw ot;
1184
- }
1185
- !V && C !== "der" && (V = U.fromCompact(b));
1186
- }
1187
- nt = m.fromHex(w);
1188
- } catch {
1189
- return !1;
1190
- }
1191
- if (!V || v && V.hasHighS())
1192
- return !1;
1193
- Z && (c = n.hash(c));
1194
- const { r: F, s: yt } = V, Q = B(c), rt = d(yt), Et = o(Q * rt), st = o(F * rt), J = (ct = m.BASE.multiplyAndAddUnsafe(nt, Et, st)) == null ? void 0 : ct.toAffine();
1195
- return J ? o(J.x) === F : !1;
1196
- }
1197
- return {
1198
- CURVE: n,
1199
- getPublicKey: x,
1200
- getSharedSecret: h,
1201
- sign: E,
1202
- verify: _,
1203
- ProjectivePoint: m,
1204
- Signature: U,
1205
- utils: $
1206
- };
1207
- }
1208
- function Le(e) {
1209
- return {
1210
- hash: e,
1211
- hmac: (n, ...t) => le(e, n, ue(...t)),
1212
- randomBytes: ae
1213
- };
1214
- }
1215
- function _e(e, n) {
1216
- const t = (r) => Ue({ ...e, ...Le(r) });
1217
- return { ...t(n), create: t };
1218
- }
1219
- const fe = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), Kt = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), ke = BigInt(0), Ce = BigInt(1), Zt = BigInt(2), Pt = (e, n) => (e + n / Zt) / n;
1220
- function He(e) {
1221
- const n = fe, t = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), a = BigInt(23), u = BigInt(44), o = BigInt(88), d = e * e * e % n, m = d * d * e % n, A = j(m, t, n) * m % n, I = j(A, t, n) * m % n, z = j(I, Zt, n) * d % n, T = j(z, i, n) * z % n, g = j(T, s, n) * T % n, k = j(g, u, n) * g % n, U = j(k, o, n) * k % n, $ = j(U, u, n) * g % n, x = j($, t, n) * m % n, f = j(x, a, n) * T % n, h = j(f, r, n) * d % n, p = j(h, Zt, n);
1222
- if (!zt.eql(zt.sqr(p), e))
1223
- throw new Error("Cannot find square root");
1224
- return p;
1225
- }
1226
- const zt = _t(fe, void 0, void 0, { sqrt: He }), Me = _e({
1227
- a: ke,
1228
- b: BigInt(7),
1229
- Fp: zt,
1230
- n: Kt,
1231
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
1232
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
1233
- h: BigInt(1),
1234
- lowS: !0,
1235
- // Allow only low-S signatures by default in sign() and verify()
1236
- endo: {
1237
- // Endomorphism, see above
1238
- beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1239
- splitScalar: (e) => {
1240
- const n = Kt, t = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -Ce * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = t, a = BigInt("0x100000000000000000000000000000000"), u = Pt(s * e, n), o = Pt(-r * e, n);
1241
- let d = M(e - u * t - o * i, n), m = M(-u * r - o * s, n);
1242
- const A = d > a, I = m > a;
1243
- if (A && (d = n - d), I && (m = n - m), d > a || m > a)
1244
- throw new Error("splitScalar: Endomorphism failed, k=" + e);
1245
- return { k1neg: A, k1: d, k2neg: I, k2: m };
1246
- }
1247
- }
1248
- }, de);
1249
- export {
1250
- Me as secp256k1
1251
- };