@babylonlabs-io/ts-sdk 0.74.0 → 0.74.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/{PeginManager-E-UHA1un.cjs → PeginManager-DEByBX5R.cjs} +2 -2
  2. package/dist/{PeginManager-E-UHA1un.cjs.map → PeginManager-DEByBX5R.cjs.map} +1 -1
  3. package/dist/{PeginManager-C9RPOd0L.js → PeginManager-DNimKlmw.js} +11 -11
  4. package/dist/{PeginManager-C9RPOd0L.js.map → PeginManager-DNimKlmw.js.map} +1 -1
  5. package/dist/{bip322Verify-D6sBBUHE.js → bip322Verify-DSco3Yhl.js} +2 -2
  6. package/dist/{bip322Verify-D6sBBUHE.js.map → bip322Verify-DSco3Yhl.js.map} +1 -1
  7. package/dist/buildAndBroadcastReclaim-Cqc6Jiqk.cjs +2 -0
  8. package/dist/{buildAndBroadcastReclaim-U-PyFfDg.cjs.map → buildAndBroadcastReclaim-Cqc6Jiqk.cjs.map} +1 -1
  9. package/dist/{buildAndBroadcastReclaim-BXclIcu_.js → buildAndBroadcastReclaim-DCGcupg7.js} +6 -6
  10. package/dist/{buildAndBroadcastReclaim-BXclIcu_.js.map → buildAndBroadcastReclaim-DCGcupg7.js.map} +1 -1
  11. package/dist/constants-BTZdyOuk.cjs +2 -0
  12. package/dist/constants-BTZdyOuk.cjs.map +1 -0
  13. package/dist/constants-D5vORbQE.js +29 -0
  14. package/dist/constants-D5vORbQE.js.map +1 -0
  15. package/dist/fundPeginTransaction-54-Rwb2k.cjs +2 -0
  16. package/dist/fundPeginTransaction-54-Rwb2k.cjs.map +1 -0
  17. package/dist/fundPeginTransaction-CwhRbCQC.js +88 -0
  18. package/dist/fundPeginTransaction-CwhRbCQC.js.map +1 -0
  19. package/dist/{index-Cs7_Evtk.cjs → index-CK1Xvq4K.cjs} +2 -2
  20. package/dist/{index-Cs7_Evtk.cjs.map → index-CK1Xvq4K.cjs.map} +1 -1
  21. package/dist/{index-LgmJhdEN.js → index-DQ5bfoT3.js} +2 -2
  22. package/dist/{index-LgmJhdEN.js.map → index-DQ5bfoT3.js.map} +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +15 -15
  25. package/dist/noPayout-4RZB2g1e.cjs +2 -0
  26. package/dist/noPayout-4RZB2g1e.cjs.map +1 -0
  27. package/dist/noPayout-DiGr4eas.js +361 -0
  28. package/dist/noPayout-DiGr4eas.js.map +1 -0
  29. package/dist/{parseFundingOutpoints-B67CoXpF.js → parseFundingOutpoints-BQWvINfm.js} +2 -2
  30. package/dist/{parseFundingOutpoints-B67CoXpF.js.map → parseFundingOutpoints-BQWvINfm.js.map} +1 -1
  31. package/dist/pegin-registration-client-CXK3B_D1.js +882 -0
  32. package/dist/pegin-registration-client-CXK3B_D1.js.map +1 -0
  33. package/dist/pegin-registration-client-DLsMNm8Z.cjs +2 -0
  34. package/dist/pegin-registration-client-DLsMNm8Z.cjs.map +1 -0
  35. package/dist/{primeVpAuth-DBHohVKM.cjs → primeVpAuth-BOGKniTl.cjs} +2 -2
  36. package/dist/{primeVpAuth-DBHohVKM.cjs.map → primeVpAuth-BOGKniTl.cjs.map} +1 -1
  37. package/dist/{primeVpAuth-DvaD45q_.js → primeVpAuth-DdfHSC53.js} +4 -4
  38. package/dist/{primeVpAuth-DvaD45q_.js.map → primeVpAuth-DdfHSC53.js.map} +1 -1
  39. package/dist/{psbtInputFields-BIxBpPj2.cjs → psbtInputFields-BrV_ZfL_.cjs} +2 -2
  40. package/dist/{psbtInputFields-BIxBpPj2.cjs.map → psbtInputFields-BrV_ZfL_.cjs.map} +1 -1
  41. package/dist/{psbtInputFields-B3e05Xe6.js → psbtInputFields-CCVyaQMi.js} +2 -2
  42. package/dist/{psbtInputFields-B3e05Xe6.js.map → psbtInputFields-CCVyaQMi.js.map} +1 -1
  43. package/dist/secp256k1-D-H9jmd7.js +1766 -0
  44. package/dist/secp256k1-D-H9jmd7.js.map +1 -0
  45. package/dist/secp256k1-DDHQ1_za.cjs +2 -0
  46. package/dist/secp256k1-DDHQ1_za.cjs.map +1 -0
  47. package/dist/{sha2-CrlWM5S8.js → sha2-CLpQd0Rd.js} +8 -8
  48. package/dist/{sha2-CrlWM5S8.js.map → sha2-CLpQd0Rd.js.map} +1 -1
  49. package/dist/{signPsbtsWithFallback-DMSpIQWH.cjs → signPsbtsWithFallback-DtwzL5AA.cjs} +2 -2
  50. package/dist/{signPsbtsWithFallback-DMSpIQWH.cjs.map → signPsbtsWithFallback-DtwzL5AA.cjs.map} +1 -1
  51. package/dist/{signPsbtsWithFallback-0VBALhjS.js → signPsbtsWithFallback-f7QLp0q8.js} +4 -4
  52. package/dist/{signPsbtsWithFallback-0VBALhjS.js.map → signPsbtsWithFallback-f7QLp0q8.js.map} +1 -1
  53. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  54. package/dist/tbv/core/clients/eth/index.js +3 -3
  55. package/dist/tbv/core/clients/index.cjs +1 -1
  56. package/dist/tbv/core/clients/index.js +5 -5
  57. package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
  58. package/dist/tbv/core/clients/vault-provider/status/index.js +1 -1
  59. package/dist/tbv/core/index.cjs +1 -1
  60. package/dist/tbv/core/index.js +15 -15
  61. package/dist/tbv/core/managers/index.cjs +1 -1
  62. package/dist/tbv/core/managers/index.js +2 -2
  63. package/dist/tbv/core/primitives/index.cjs +1 -1
  64. package/dist/tbv/core/primitives/index.js +4 -4
  65. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +5 -6
  66. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -1
  67. package/dist/tbv/core/primitives/psbt/__tests__/assertWasmPeginSizing.test.d.ts +2 -2
  68. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +36 -14
  69. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  70. package/dist/tbv/core/primitives/psbt/constants.d.ts +39 -0
  71. package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
  72. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  73. package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
  74. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
  75. package/dist/tbv/core/services/index.cjs +1 -1
  76. package/dist/tbv/core/services/index.js +2 -2
  77. package/dist/tbv/core/utils/fee/constants.d.ts +4 -4
  78. package/dist/tbv/core/utils/index.cjs +1 -1
  79. package/dist/tbv/core/utils/index.js +2 -2
  80. package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
  81. package/dist/tbv/core/vault-secrets/index.js +1 -1
  82. package/dist/tbv/index.cjs +1 -1
  83. package/dist/tbv/index.js +15 -15
  84. package/dist/test/setup.browser.d.ts +2 -0
  85. package/dist/test/setup.browser.d.ts.map +1 -0
  86. package/dist/testing/index.js +1 -1
  87. package/dist/{toRefundInputs-C3oIN0aW.js → toRefundInputs-BNSXIymn.js} +7 -7
  88. package/dist/{toRefundInputs-C3oIN0aW.js.map → toRefundInputs-BNSXIymn.js.map} +1 -1
  89. package/dist/{toRefundInputs-BwG6T0PP.cjs → toRefundInputs-meTyor7r.cjs} +2 -2
  90. package/dist/{toRefundInputs-BwG6T0PP.cjs.map → toRefundInputs-meTyor7r.cjs.map} +1 -1
  91. package/dist/{types-DSlcXtog.cjs → types-BzSOthHH.cjs} +2 -2
  92. package/dist/{types-DSlcXtog.cjs.map → types-BzSOthHH.cjs.map} +1 -1
  93. package/dist/{types-CPDLZm3l.js → types-C5DyrC8F.js} +2 -2
  94. package/dist/{types-CPDLZm3l.js.map → types-C5DyrC8F.js.map} +1 -1
  95. package/dist/verifyKeyPathSchnorrSignature-BVtNwgK6.js +360 -0
  96. package/dist/verifyKeyPathSchnorrSignature-BVtNwgK6.js.map +1 -0
  97. package/dist/verifyKeyPathSchnorrSignature-BjB8Znly.cjs +2 -0
  98. package/dist/verifyKeyPathSchnorrSignature-BjB8Znly.cjs.map +1 -0
  99. package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js +1140 -0
  100. package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js.map +1 -0
  101. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs +2 -0
  102. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs.map +1 -0
  103. package/package.json +4 -1
  104. package/dist/buildAndBroadcastReclaim-U-PyFfDg.cjs +0 -2
  105. package/dist/constants-Bh38W9mq.cjs +0 -2
  106. package/dist/constants-Bh38W9mq.cjs.map +0 -1
  107. package/dist/constants-CPzppOdq.js +0 -17
  108. package/dist/constants-CPzppOdq.js.map +0 -1
  109. package/dist/fundPeginTransaction-B2wyjqp0.js +0 -83
  110. package/dist/fundPeginTransaction-B2wyjqp0.js.map +0 -1
  111. package/dist/fundPeginTransaction-BLD8FRL9.cjs +0 -2
  112. package/dist/fundPeginTransaction-BLD8FRL9.cjs.map +0 -1
  113. package/dist/noPayout-DpGRzidi.js +0 -353
  114. package/dist/noPayout-DpGRzidi.js.map +0 -1
  115. package/dist/noPayout-zEifyecV.cjs +0 -2
  116. package/dist/noPayout-zEifyecV.cjs.map +0 -1
  117. package/dist/pegin-registration-client-6vLk2itL.cjs +0 -2
  118. package/dist/pegin-registration-client-6vLk2itL.cjs.map +0 -1
  119. package/dist/pegin-registration-client-BdRiR8br.js +0 -2635
  120. package/dist/pegin-registration-client-BdRiR8br.js.map +0 -1
  121. package/dist/vaultCoreVersion-DYfw3qed.cjs +0 -2
  122. package/dist/vaultCoreVersion-DYfw3qed.cjs.map +0 -1
  123. package/dist/vaultCoreVersion-D_fP9P3C.js +0 -10
  124. package/dist/vaultCoreVersion-D_fP9P3C.js.map +0 -1
  125. package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs +0 -2
  126. package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs.map +0 -1
  127. package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js +0 -372
  128. package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js.map +0 -1
  129. package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs +0 -2
  130. package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs.map +0 -1
  131. package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js +0 -951
  132. package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js.map +0 -1
@@ -0,0 +1,1766 @@
1
+ function Un(t, e) {
2
+ if (!Number.isInteger(t) || t < 1 || t > 65535)
3
+ throw new Error(
4
+ `Invalid vaultCoreVersion ${t} from ${e}: expected an integer in [1, 65535].`
5
+ );
6
+ }
7
+ const ct = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
8
+ function Ut(t) {
9
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
10
+ }
11
+ function Ct(t) {
12
+ if (!Number.isSafeInteger(t) || t < 0)
13
+ throw new Error("positive integer expected, got " + t);
14
+ }
15
+ function ot(t, ...e) {
16
+ if (!Ut(t))
17
+ throw new Error("Uint8Array expected");
18
+ if (e.length > 0 && !e.includes(t.length))
19
+ throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
20
+ }
21
+ function de(t) {
22
+ if (typeof t != "function" || typeof t.create != "function")
23
+ throw new Error("Hash should be wrapped by utils.createHasher");
24
+ Ct(t.outputLen), Ct(t.blockLen);
25
+ }
26
+ function vt(t, e = !0) {
27
+ if (t.destroyed)
28
+ throw new Error("Hash instance has been destroyed");
29
+ if (e && t.finished)
30
+ throw new Error("Hash#digest() has already been called");
31
+ }
32
+ function je(t, e) {
33
+ ot(t);
34
+ const r = e.outputLen;
35
+ if (t.length < r)
36
+ throw new Error("digestInto() expects output buffer of length at least " + r);
37
+ }
38
+ function St(...t) {
39
+ for (let e = 0; e < t.length; e++)
40
+ t[e].fill(0);
41
+ }
42
+ function qt(t) {
43
+ return new DataView(t.buffer, t.byteOffset, t.byteLength);
44
+ }
45
+ function Y(t, e) {
46
+ return t << 32 - e | t >>> e;
47
+ }
48
+ const he = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ye = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
49
+ function ft(t) {
50
+ if (ot(t), he)
51
+ return t.toHex();
52
+ let e = "";
53
+ for (let r = 0; r < t.length; r++)
54
+ e += Ye[t[r]];
55
+ return e;
56
+ }
57
+ const D = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
58
+ function ee(t) {
59
+ if (t >= D._0 && t <= D._9)
60
+ return t - D._0;
61
+ if (t >= D.A && t <= D.F)
62
+ return t - (D.A - 10);
63
+ if (t >= D.a && t <= D.f)
64
+ return t - (D.a - 10);
65
+ }
66
+ function At(t) {
67
+ if (typeof t != "string")
68
+ throw new Error("hex string expected, got " + typeof t);
69
+ if (he)
70
+ return Uint8Array.fromHex(t);
71
+ const e = t.length, r = e / 2;
72
+ if (e % 2)
73
+ throw new Error("hex string expected, got unpadded hex of length " + e);
74
+ const n = new Uint8Array(r);
75
+ for (let o = 0, s = 0; o < r; o++, s += 2) {
76
+ const i = ee(t.charCodeAt(s)), c = ee(t.charCodeAt(s + 1));
77
+ if (i === void 0 || c === void 0) {
78
+ const f = t[s] + t[s + 1];
79
+ throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + s);
80
+ }
81
+ n[o] = i * 16 + c;
82
+ }
83
+ return n;
84
+ }
85
+ function ge(t) {
86
+ if (typeof t != "string")
87
+ throw new Error("string expected");
88
+ return new Uint8Array(new TextEncoder().encode(t));
89
+ }
90
+ function Xt(t) {
91
+ return typeof t == "string" && (t = ge(t)), ot(t), t;
92
+ }
93
+ function z(...t) {
94
+ let e = 0;
95
+ for (let n = 0; n < t.length; n++) {
96
+ const o = t[n];
97
+ ot(o), e += o.length;
98
+ }
99
+ const r = new Uint8Array(e);
100
+ for (let n = 0, o = 0; n < t.length; n++) {
101
+ const s = t[n];
102
+ r.set(s, o), o += s.length;
103
+ }
104
+ return r;
105
+ }
106
+ class we {
107
+ }
108
+ function ze(t) {
109
+ const e = (n) => t().update(Xt(n)).digest(), r = t();
110
+ return e.outputLen = r.outputLen, e.blockLen = r.blockLen, e.create = () => t(), e;
111
+ }
112
+ function Ht(t = 32) {
113
+ if (ct && typeof ct.getRandomValues == "function")
114
+ return ct.getRandomValues(new Uint8Array(t));
115
+ if (ct && typeof ct.randomBytes == "function")
116
+ return Uint8Array.from(ct.randomBytes(t));
117
+ throw new Error("crypto.getRandomValues must be defined");
118
+ }
119
+ function De(t, e, r, n) {
120
+ if (typeof t.setBigUint64 == "function")
121
+ return t.setBigUint64(e, r, n);
122
+ const o = BigInt(32), s = BigInt(4294967295), i = Number(r >> o & s), c = Number(r & s), f = n ? 4 : 0, g = n ? 0 : 4;
123
+ t.setUint32(e + f, i, n), t.setUint32(e + g, c, n);
124
+ }
125
+ function Xe(t, e, r) {
126
+ return t & e ^ ~t & r;
127
+ }
128
+ function Ge(t, e, r) {
129
+ return t & e ^ t & r ^ e & r;
130
+ }
131
+ class Fe extends we {
132
+ constructor(e, r, n, o) {
133
+ super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = r, this.padOffset = n, this.isLE = o, this.buffer = new Uint8Array(e), this.view = qt(this.buffer);
134
+ }
135
+ update(e) {
136
+ vt(this), e = Xt(e), ot(e);
137
+ const { view: r, buffer: n, blockLen: o } = this, s = e.length;
138
+ for (let i = 0; i < s; ) {
139
+ const c = Math.min(o - this.pos, s - i);
140
+ if (c === o) {
141
+ const f = qt(e);
142
+ for (; o <= s - i; i += o)
143
+ this.process(f, i);
144
+ continue;
145
+ }
146
+ n.set(e.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === o && (this.process(r, 0), this.pos = 0);
147
+ }
148
+ return this.length += e.length, this.roundClean(), this;
149
+ }
150
+ digestInto(e) {
151
+ vt(this), je(e, this), this.finished = !0;
152
+ const { buffer: r, view: n, blockLen: o, isLE: s } = this;
153
+ let { pos: i } = this;
154
+ r[i++] = 128, St(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(n, 0), i = 0);
155
+ for (let b = i; b < o; b++)
156
+ r[b] = 0;
157
+ De(n, o - 8, BigInt(this.length * 8), s), this.process(n, 0);
158
+ const c = qt(e), f = this.outputLen;
159
+ if (f % 4)
160
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
161
+ const g = f / 4, y = this.get();
162
+ if (g > y.length)
163
+ throw new Error("_sha2: outputLen bigger than state");
164
+ for (let b = 0; b < g; b++)
165
+ c.setUint32(4 * b, y[b], s);
166
+ }
167
+ digest() {
168
+ const { buffer: e, outputLen: r } = this;
169
+ this.digestInto(e);
170
+ const n = e.slice(0, r);
171
+ return this.destroy(), n;
172
+ }
173
+ _cloneInto(e) {
174
+ e || (e = new this.constructor()), e.set(...this.get());
175
+ const { blockLen: r, buffer: n, length: o, finished: s, destroyed: i, pos: c } = this;
176
+ return e.destroyed = i, e.finished = s, e.length = o, e.pos = c, o % r && e.buffer.set(n), e;
177
+ }
178
+ clone() {
179
+ return this._cloneInto();
180
+ }
181
+ }
182
+ const P = /* @__PURE__ */ Uint32Array.from([
183
+ 1779033703,
184
+ 3144134277,
185
+ 1013904242,
186
+ 2773480762,
187
+ 1359893119,
188
+ 2600822924,
189
+ 528734635,
190
+ 1541459225
191
+ ]), Pe = /* @__PURE__ */ Uint32Array.from([
192
+ 1116352408,
193
+ 1899447441,
194
+ 3049323471,
195
+ 3921009573,
196
+ 961987163,
197
+ 1508970993,
198
+ 2453635748,
199
+ 2870763221,
200
+ 3624381080,
201
+ 310598401,
202
+ 607225278,
203
+ 1426881987,
204
+ 1925078388,
205
+ 2162078206,
206
+ 2614888103,
207
+ 3248222580,
208
+ 3835390401,
209
+ 4022224774,
210
+ 264347078,
211
+ 604807628,
212
+ 770255983,
213
+ 1249150122,
214
+ 1555081692,
215
+ 1996064986,
216
+ 2554220882,
217
+ 2821834349,
218
+ 2952996808,
219
+ 3210313671,
220
+ 3336571891,
221
+ 3584528711,
222
+ 113926993,
223
+ 338241895,
224
+ 666307205,
225
+ 773529912,
226
+ 1294757372,
227
+ 1396182291,
228
+ 1695183700,
229
+ 1986661051,
230
+ 2177026350,
231
+ 2456956037,
232
+ 2730485921,
233
+ 2820302411,
234
+ 3259730800,
235
+ 3345764771,
236
+ 3516065817,
237
+ 3600352804,
238
+ 4094571909,
239
+ 275423344,
240
+ 430227734,
241
+ 506948616,
242
+ 659060556,
243
+ 883997877,
244
+ 958139571,
245
+ 1322822218,
246
+ 1537002063,
247
+ 1747873779,
248
+ 1955562222,
249
+ 2024104815,
250
+ 2227730452,
251
+ 2361852424,
252
+ 2428436474,
253
+ 2756734187,
254
+ 3204031479,
255
+ 3329325298
256
+ ]), W = /* @__PURE__ */ new Uint32Array(64);
257
+ class We extends Fe {
258
+ constructor(e = 32) {
259
+ super(64, e, 8, !1), this.A = P[0] | 0, this.B = P[1] | 0, this.C = P[2] | 0, this.D = P[3] | 0, this.E = P[4] | 0, this.F = P[5] | 0, this.G = P[6] | 0, this.H = P[7] | 0;
260
+ }
261
+ get() {
262
+ const { A: e, B: r, C: n, D: o, E: s, F: i, G: c, H: f } = this;
263
+ return [e, r, n, o, s, i, c, f];
264
+ }
265
+ // prettier-ignore
266
+ set(e, r, n, o, s, i, c, f) {
267
+ this.A = e | 0, this.B = r | 0, this.C = n | 0, this.D = o | 0, this.E = s | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
268
+ }
269
+ process(e, r) {
270
+ for (let b = 0; b < 16; b++, r += 4)
271
+ W[b] = e.getUint32(r, !1);
272
+ for (let b = 16; b < 64; b++) {
273
+ const a = W[b - 15], l = W[b - 2], p = Y(a, 7) ^ Y(a, 18) ^ a >>> 3, B = Y(l, 17) ^ Y(l, 19) ^ l >>> 10;
274
+ W[b] = B + W[b - 7] + p + W[b - 16] | 0;
275
+ }
276
+ let { A: n, B: o, C: s, D: i, E: c, F: f, G: g, H: y } = this;
277
+ for (let b = 0; b < 64; b++) {
278
+ const a = Y(c, 6) ^ Y(c, 11) ^ Y(c, 25), l = y + a + Xe(c, f, g) + Pe[b] + W[b] | 0, B = (Y(n, 2) ^ Y(n, 13) ^ Y(n, 22)) + Ge(n, o, s) | 0;
279
+ y = g, g = f, f = c, c = i + l | 0, i = s, s = o, o = n, n = l + B | 0;
280
+ }
281
+ n = n + this.A | 0, o = o + this.B | 0, s = s + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, g = g + this.G | 0, y = y + this.H | 0, this.set(n, o, s, i, c, f, g, y);
282
+ }
283
+ roundClean() {
284
+ St(W);
285
+ }
286
+ destroy() {
287
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), St(this.buffer);
288
+ }
289
+ }
290
+ const $t = /* @__PURE__ */ ze(() => new We());
291
+ class ye extends we {
292
+ constructor(e, r) {
293
+ super(), this.finished = !1, this.destroyed = !1, de(e);
294
+ const n = Xt(r);
295
+ if (this.iHash = e.create(), typeof this.iHash.update != "function")
296
+ throw new Error("Expected instance of class which extends utils.Hash");
297
+ this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
298
+ const o = this.blockLen, s = new Uint8Array(o);
299
+ s.set(n.length > o ? e.create().update(n).digest() : n);
300
+ for (let i = 0; i < s.length; i++)
301
+ s[i] ^= 54;
302
+ this.iHash.update(s), this.oHash = e.create();
303
+ for (let i = 0; i < s.length; i++)
304
+ s[i] ^= 106;
305
+ this.oHash.update(s), St(s);
306
+ }
307
+ update(e) {
308
+ return vt(this), this.iHash.update(e), this;
309
+ }
310
+ digestInto(e) {
311
+ vt(this), ot(e, this.outputLen), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
312
+ }
313
+ digest() {
314
+ const e = new Uint8Array(this.oHash.outputLen);
315
+ return this.digestInto(e), e;
316
+ }
317
+ _cloneInto(e) {
318
+ e || (e = Object.create(Object.getPrototypeOf(this), {}));
319
+ const { oHash: r, iHash: n, finished: o, destroyed: s, blockLen: i, outputLen: c } = this;
320
+ return e = e, e.finished = o, e.destroyed = s, e.blockLen = i, e.outputLen = c, e.oHash = r._cloneInto(e.oHash), e.iHash = n._cloneInto(e.iHash), e;
321
+ }
322
+ clone() {
323
+ return this._cloneInto();
324
+ }
325
+ destroy() {
326
+ this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
327
+ }
328
+ }
329
+ const be = (t, e, r) => new ye(t, e).update(r).digest();
330
+ be.create = (t, e) => new ye(t, e);
331
+ const Gt = /* @__PURE__ */ BigInt(0), Mt = /* @__PURE__ */ BigInt(1);
332
+ function It(t, e = "") {
333
+ if (typeof t != "boolean") {
334
+ const r = e && `"${e}"`;
335
+ throw new Error(r + "expected boolean, got type=" + typeof t);
336
+ }
337
+ return t;
338
+ }
339
+ function tt(t, e, r = "") {
340
+ const n = Ut(t), o = t == null ? void 0 : t.length, s = e !== void 0;
341
+ if (!n || s && o !== e) {
342
+ const i = r && `"${r}" `, c = s ? ` of length ${e}` : "", f = n ? `length=${o}` : `type=${typeof t}`;
343
+ throw new Error(i + "expected Uint8Array" + c + ", got " + f);
344
+ }
345
+ return t;
346
+ }
347
+ function xt(t) {
348
+ const e = t.toString(16);
349
+ return e.length & 1 ? "0" + e : e;
350
+ }
351
+ function me(t) {
352
+ if (typeof t != "string")
353
+ throw new Error("hex string expected, got " + typeof t);
354
+ return t === "" ? Gt : BigInt("0x" + t);
355
+ }
356
+ function dt(t) {
357
+ return me(ft(t));
358
+ }
359
+ function pe(t) {
360
+ return ot(t), me(ft(Uint8Array.from(t).reverse()));
361
+ }
362
+ function Ot(t, e) {
363
+ return At(t.toString(16).padStart(e * 2, "0"));
364
+ }
365
+ function Ee(t, e) {
366
+ return Ot(t, e).reverse();
367
+ }
368
+ function T(t, e, r) {
369
+ let n;
370
+ if (typeof e == "string")
371
+ try {
372
+ n = At(e);
373
+ } catch (s) {
374
+ throw new Error(t + " must be hex string or Uint8Array, cause: " + s);
375
+ }
376
+ else if (Ut(e))
377
+ n = Uint8Array.from(e);
378
+ else
379
+ throw new Error(t + " must be hex string or Uint8Array");
380
+ const o = n.length;
381
+ if (typeof r == "number" && o !== r)
382
+ throw new Error(t + " of length " + r + " expected, got " + o);
383
+ return n;
384
+ }
385
+ const Lt = (t) => typeof t == "bigint" && Gt <= t;
386
+ function jt(t, e, r) {
387
+ return Lt(t) && Lt(e) && Lt(r) && e <= t && t < r;
388
+ }
389
+ function Qe(t, e, r, n) {
390
+ if (!jt(e, r, n))
391
+ throw new Error("expected valid " + t + ": " + r + " <= n < " + n + ", got " + e);
392
+ }
393
+ function xe(t) {
394
+ let e;
395
+ for (e = 0; t > Gt; t >>= Mt, e += 1)
396
+ ;
397
+ return e;
398
+ }
399
+ const yt = (t) => (Mt << BigInt(t)) - Mt;
400
+ function Je(t, e, r) {
401
+ if (typeof t != "number" || t < 2)
402
+ throw new Error("hashLen must be a number");
403
+ if (typeof e != "number" || e < 2)
404
+ throw new Error("qByteLen must be a number");
405
+ if (typeof r != "function")
406
+ throw new Error("hmacFn must be a function");
407
+ const n = (l) => new Uint8Array(l), o = (l) => Uint8Array.of(l);
408
+ let s = n(t), i = n(t), c = 0;
409
+ const f = () => {
410
+ s.fill(1), i.fill(0), c = 0;
411
+ }, g = (...l) => r(i, s, ...l), y = (l = n(0)) => {
412
+ i = g(o(0), l), s = g(), l.length !== 0 && (i = g(o(1), l), s = g());
413
+ }, b = () => {
414
+ if (c++ >= 1e3)
415
+ throw new Error("drbg: tried 1000 values");
416
+ let l = 0;
417
+ const p = [];
418
+ for (; l < e; ) {
419
+ s = g();
420
+ const B = s.slice();
421
+ p.push(B), l += s.length;
422
+ }
423
+ return z(...p);
424
+ };
425
+ return (l, p) => {
426
+ f(), y(l);
427
+ let B;
428
+ for (; !(B = p(b())); )
429
+ y();
430
+ return f(), B;
431
+ };
432
+ }
433
+ function Ft(t, e, r = {}) {
434
+ if (!t || typeof t != "object")
435
+ throw new Error("expected valid options object");
436
+ function n(o, s, i) {
437
+ const c = t[o];
438
+ if (i && c === void 0)
439
+ return;
440
+ const f = typeof c;
441
+ if (f !== s || c === null)
442
+ throw new Error(`param "${o}" is invalid: expected ${s}, got ${f}`);
443
+ }
444
+ Object.entries(e).forEach(([o, s]) => n(o, s, !1)), Object.entries(r).forEach(([o, s]) => n(o, s, !0));
445
+ }
446
+ function ne(t) {
447
+ const e = /* @__PURE__ */ new WeakMap();
448
+ return (r, ...n) => {
449
+ const o = e.get(r);
450
+ if (o !== void 0)
451
+ return o;
452
+ const s = t(r, ...n);
453
+ return e.set(r, s), s;
454
+ };
455
+ }
456
+ const $ = BigInt(0), k = BigInt(1), et = /* @__PURE__ */ BigInt(2), Be = /* @__PURE__ */ BigInt(3), ve = /* @__PURE__ */ BigInt(4), Se = /* @__PURE__ */ BigInt(5), tn = /* @__PURE__ */ BigInt(7), Ae = /* @__PURE__ */ BigInt(8), en = /* @__PURE__ */ BigInt(9), Ie = /* @__PURE__ */ BigInt(16);
457
+ function j(t, e) {
458
+ const r = t % e;
459
+ return r >= $ ? r : e + r;
460
+ }
461
+ function M(t, e, r) {
462
+ let n = t;
463
+ for (; e-- > $; )
464
+ n *= n, n %= r;
465
+ return n;
466
+ }
467
+ function re(t, e) {
468
+ if (t === $)
469
+ throw new Error("invert: expected non-zero number");
470
+ if (e <= $)
471
+ throw new Error("invert: expected positive modulus, got " + e);
472
+ let r = j(t, e), n = e, o = $, s = k;
473
+ for (; r !== $; ) {
474
+ const c = n / r, f = n % r, g = o - s * c;
475
+ n = r, r = f, o = s, s = g;
476
+ }
477
+ if (n !== k)
478
+ throw new Error("invert: does not exist");
479
+ return j(o, e);
480
+ }
481
+ function Pt(t, e, r) {
482
+ if (!t.eql(t.sqr(e), r))
483
+ throw new Error("Cannot find square root");
484
+ }
485
+ function _e(t, e) {
486
+ const r = (t.ORDER + k) / ve, n = t.pow(e, r);
487
+ return Pt(t, n, e), n;
488
+ }
489
+ function nn(t, e) {
490
+ const r = (t.ORDER - Se) / Ae, n = t.mul(e, et), o = t.pow(n, r), s = t.mul(e, o), i = t.mul(t.mul(s, et), o), c = t.mul(s, t.sub(i, t.ONE));
491
+ return Pt(t, c, e), c;
492
+ }
493
+ function rn(t) {
494
+ const e = bt(t), r = Ne(t), n = r(e, e.neg(e.ONE)), o = r(e, n), s = r(e, e.neg(n)), i = (t + tn) / Ie;
495
+ return (c, f) => {
496
+ let g = c.pow(f, i), y = c.mul(g, n);
497
+ const b = c.mul(g, o), a = c.mul(g, s), l = c.eql(c.sqr(y), f), p = c.eql(c.sqr(b), f);
498
+ g = c.cmov(g, y, l), y = c.cmov(a, b, p);
499
+ const B = c.eql(c.sqr(y), f), R = c.cmov(g, y, B);
500
+ return Pt(c, R, f), R;
501
+ };
502
+ }
503
+ function Ne(t) {
504
+ if (t < Be)
505
+ throw new Error("sqrt is not defined for small field");
506
+ let e = t - k, r = 0;
507
+ for (; e % et === $; )
508
+ e /= et, r++;
509
+ let n = et;
510
+ const o = bt(t);
511
+ for (; oe(o, n) === 1; )
512
+ if (n++ > 1e3)
513
+ throw new Error("Cannot find square root: probably non-prime P");
514
+ if (r === 1)
515
+ return _e;
516
+ let s = o.pow(n, e);
517
+ const i = (e + k) / et;
518
+ return function(f, g) {
519
+ if (f.is0(g))
520
+ return g;
521
+ if (oe(f, g) !== 1)
522
+ throw new Error("Cannot find square root");
523
+ let y = r, b = f.mul(f.ONE, s), a = f.pow(g, e), l = f.pow(g, i);
524
+ for (; !f.eql(a, f.ONE); ) {
525
+ if (f.is0(a))
526
+ return f.ZERO;
527
+ let p = 1, B = f.sqr(a);
528
+ for (; !f.eql(B, f.ONE); )
529
+ if (p++, B = f.sqr(B), p === y)
530
+ throw new Error("Cannot find square root");
531
+ const R = k << BigInt(y - p - 1), q = f.pow(b, R);
532
+ y = p, b = f.sqr(q), a = f.mul(a, b), l = f.mul(l, q);
533
+ }
534
+ return l;
535
+ };
536
+ }
537
+ function on(t) {
538
+ return t % ve === Be ? _e : t % Ae === Se ? nn : t % Ie === en ? rn(t) : Ne(t);
539
+ }
540
+ const sn = [
541
+ "create",
542
+ "isValid",
543
+ "is0",
544
+ "neg",
545
+ "inv",
546
+ "sqrt",
547
+ "sqr",
548
+ "eql",
549
+ "add",
550
+ "sub",
551
+ "mul",
552
+ "pow",
553
+ "div",
554
+ "addN",
555
+ "subN",
556
+ "mulN",
557
+ "sqrN"
558
+ ];
559
+ function cn(t) {
560
+ const e = {
561
+ ORDER: "bigint",
562
+ MASK: "bigint",
563
+ BYTES: "number",
564
+ BITS: "number"
565
+ }, r = sn.reduce((n, o) => (n[o] = "function", n), e);
566
+ return Ft(t, r), t;
567
+ }
568
+ function fn(t, e, r) {
569
+ if (r < $)
570
+ throw new Error("invalid exponent, negatives unsupported");
571
+ if (r === $)
572
+ return t.ONE;
573
+ if (r === k)
574
+ return e;
575
+ let n = t.ONE, o = e;
576
+ for (; r > $; )
577
+ r & k && (n = t.mul(n, o)), o = t.sqr(o), r >>= k;
578
+ return n;
579
+ }
580
+ function Re(t, e, r = !1) {
581
+ const n = new Array(e.length).fill(r ? t.ZERO : void 0), o = e.reduce((i, c, f) => t.is0(c) ? i : (n[f] = i, t.mul(i, c)), t.ONE), s = t.inv(o);
582
+ return e.reduceRight((i, c, f) => t.is0(c) ? i : (n[f] = t.mul(i, n[f]), t.mul(i, c)), s), n;
583
+ }
584
+ function oe(t, e) {
585
+ const r = (t.ORDER - k) / et, n = t.pow(e, r), o = t.eql(n, t.ONE), s = t.eql(n, t.ZERO), i = t.eql(n, t.neg(t.ONE));
586
+ if (!o && !s && !i)
587
+ throw new Error("invalid Legendre symbol result");
588
+ return o ? 1 : s ? 0 : -1;
589
+ }
590
+ function Ue(t, e) {
591
+ e !== void 0 && Ct(e);
592
+ const r = e !== void 0 ? e : t.toString(2).length, n = Math.ceil(r / 8);
593
+ return { nBitLength: r, nByteLength: n };
594
+ }
595
+ function bt(t, e, r = !1, n = {}) {
596
+ if (t <= $)
597
+ throw new Error("invalid field: expected ORDER > 0, got " + t);
598
+ let o, s, i = !1, c;
599
+ if (typeof e == "object" && e != null) {
600
+ if (n.sqrt || r)
601
+ throw new Error("cannot specify opts in two arguments");
602
+ const a = e;
603
+ a.BITS && (o = a.BITS), a.sqrt && (s = a.sqrt), typeof a.isLE == "boolean" && (r = a.isLE), typeof a.modFromBytes == "boolean" && (i = a.modFromBytes), c = a.allowedLengths;
604
+ } else
605
+ typeof e == "number" && (o = e), n.sqrt && (s = n.sqrt);
606
+ const { nBitLength: f, nByteLength: g } = Ue(t, o);
607
+ if (g > 2048)
608
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
609
+ let y;
610
+ const b = Object.freeze({
611
+ ORDER: t,
612
+ isLE: r,
613
+ BITS: f,
614
+ BYTES: g,
615
+ MASK: yt(f),
616
+ ZERO: $,
617
+ ONE: k,
618
+ allowedLengths: c,
619
+ create: (a) => j(a, t),
620
+ isValid: (a) => {
621
+ if (typeof a != "bigint")
622
+ throw new Error("invalid field element: expected bigint, got " + typeof a);
623
+ return $ <= a && a < t;
624
+ },
625
+ is0: (a) => a === $,
626
+ // is valid and invertible
627
+ isValidNot0: (a) => !b.is0(a) && b.isValid(a),
628
+ isOdd: (a) => (a & k) === k,
629
+ neg: (a) => j(-a, t),
630
+ eql: (a, l) => a === l,
631
+ sqr: (a) => j(a * a, t),
632
+ add: (a, l) => j(a + l, t),
633
+ sub: (a, l) => j(a - l, t),
634
+ mul: (a, l) => j(a * l, t),
635
+ pow: (a, l) => fn(b, a, l),
636
+ div: (a, l) => j(a * re(l, t), t),
637
+ // Same as above, but doesn't normalize
638
+ sqrN: (a) => a * a,
639
+ addN: (a, l) => a + l,
640
+ subN: (a, l) => a - l,
641
+ mulN: (a, l) => a * l,
642
+ inv: (a) => re(a, t),
643
+ sqrt: s || ((a) => (y || (y = on(t)), y(b, a))),
644
+ toBytes: (a) => r ? Ee(a, g) : Ot(a, g),
645
+ fromBytes: (a, l = !0) => {
646
+ if (c) {
647
+ if (!c.includes(a.length) || a.length > g)
648
+ throw new Error("Field.fromBytes: expected " + c + " bytes, got " + a.length);
649
+ const B = new Uint8Array(g);
650
+ B.set(a, r ? 0 : B.length - a.length), a = B;
651
+ }
652
+ if (a.length !== g)
653
+ throw new Error("Field.fromBytes: expected " + g + " bytes, got " + a.length);
654
+ let p = r ? pe(a) : dt(a);
655
+ if (i && (p = j(p, t)), !l && !b.isValid(p))
656
+ throw new Error("invalid field element: outside of range 0..ORDER");
657
+ return p;
658
+ },
659
+ // TODO: we don't need it here, move out to separate fn
660
+ invertBatch: (a) => Re(b, a),
661
+ // We can't move this out because Fp6, Fp12 implement it
662
+ // and it's unclear what to return in there.
663
+ cmov: (a, l, p) => p ? l : a
664
+ });
665
+ return Object.freeze(b);
666
+ }
667
+ function He(t) {
668
+ if (typeof t != "bigint")
669
+ throw new Error("field order must be bigint");
670
+ const e = t.toString(2).length;
671
+ return Math.ceil(e / 8);
672
+ }
673
+ function Oe(t) {
674
+ const e = He(t);
675
+ return e + Math.ceil(e / 2);
676
+ }
677
+ function qe(t, e, r = !1) {
678
+ const n = t.length, o = He(e), s = Oe(e);
679
+ if (n < 16 || n < s || n > 1024)
680
+ throw new Error("expected " + s + "-1024 bytes of input, got " + n);
681
+ const i = r ? pe(t) : dt(t), c = j(i, e - k) + k;
682
+ return r ? Ee(c, o) : Ot(c, o);
683
+ }
684
+ const ut = BigInt(0), nt = BigInt(1);
685
+ function _t(t, e) {
686
+ const r = e.negate();
687
+ return t ? r : e;
688
+ }
689
+ function Vt(t, e) {
690
+ const r = Re(t.Fp, e.map((n) => n.Z));
691
+ return e.map((n, o) => t.fromAffine(n.toAffine(r[o])));
692
+ }
693
+ function Le(t, e) {
694
+ if (!Number.isSafeInteger(t) || t <= 0 || t > e)
695
+ throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
696
+ }
697
+ function Zt(t, e) {
698
+ Le(t, e);
699
+ const r = Math.ceil(e / t) + 1, n = 2 ** (t - 1), o = 2 ** t, s = yt(t), i = BigInt(t);
700
+ return { windows: r, windowSize: n, mask: s, maxNumber: o, shiftBy: i };
701
+ }
702
+ function se(t, e, r) {
703
+ const { windowSize: n, mask: o, maxNumber: s, shiftBy: i } = r;
704
+ let c = Number(t & o), f = t >> i;
705
+ c > n && (c -= s, f += nt);
706
+ const g = e * n, y = g + Math.abs(c) - 1, b = c === 0, a = c < 0, l = e % 2 !== 0;
707
+ return { nextN: f, offset: y, isZero: b, isNeg: a, isNegF: l, offsetF: g };
708
+ }
709
+ function an(t, e) {
710
+ if (!Array.isArray(t))
711
+ throw new Error("array expected");
712
+ t.forEach((r, n) => {
713
+ if (!(r instanceof e))
714
+ throw new Error("invalid point at index " + n);
715
+ });
716
+ }
717
+ function un(t, e) {
718
+ if (!Array.isArray(t))
719
+ throw new Error("array of scalars expected");
720
+ t.forEach((r, n) => {
721
+ if (!e.isValid(r))
722
+ throw new Error("invalid scalar at index " + n);
723
+ });
724
+ }
725
+ const Tt = /* @__PURE__ */ new WeakMap(), Ve = /* @__PURE__ */ new WeakMap();
726
+ function Kt(t) {
727
+ return Ve.get(t) || 1;
728
+ }
729
+ function ie(t) {
730
+ if (t !== ut)
731
+ throw new Error("invalid wNAF");
732
+ }
733
+ class ln {
734
+ // Parametrized with a given Point class (not individual point)
735
+ constructor(e, r) {
736
+ this.BASE = e.BASE, this.ZERO = e.ZERO, this.Fn = e.Fn, this.bits = r;
737
+ }
738
+ // non-const time multiplication ladder
739
+ _unsafeLadder(e, r, n = this.ZERO) {
740
+ let o = e;
741
+ for (; r > ut; )
742
+ r & nt && (n = n.add(o)), o = o.double(), r >>= nt;
743
+ return n;
744
+ }
745
+ /**
746
+ * Creates a wNAF precomputation window. Used for caching.
747
+ * Default window size is set by `utils.precompute()` and is equal to 8.
748
+ * Number of precomputed points depends on the curve size:
749
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
750
+ * - 𝑊 is the window size
751
+ * - 𝑛 is the bitlength of the curve order.
752
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
753
+ * @param point Point instance
754
+ * @param W window size
755
+ * @returns precomputed point tables flattened to a single array
756
+ */
757
+ precomputeWindow(e, r) {
758
+ const { windows: n, windowSize: o } = Zt(r, this.bits), s = [];
759
+ let i = e, c = i;
760
+ for (let f = 0; f < n; f++) {
761
+ c = i, s.push(c);
762
+ for (let g = 1; g < o; g++)
763
+ c = c.add(i), s.push(c);
764
+ i = c.double();
765
+ }
766
+ return s;
767
+ }
768
+ /**
769
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
770
+ * More compact implementation:
771
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
772
+ * @returns real and fake (for const-time) points
773
+ */
774
+ wNAF(e, r, n) {
775
+ if (!this.Fn.isValid(n))
776
+ throw new Error("invalid scalar");
777
+ let o = this.ZERO, s = this.BASE;
778
+ const i = Zt(e, this.bits);
779
+ for (let c = 0; c < i.windows; c++) {
780
+ const { nextN: f, offset: g, isZero: y, isNeg: b, isNegF: a, offsetF: l } = se(n, c, i);
781
+ n = f, y ? s = s.add(_t(a, r[l])) : o = o.add(_t(b, r[g]));
782
+ }
783
+ return ie(n), { p: o, f: s };
784
+ }
785
+ /**
786
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
787
+ * @param acc accumulator point to add result of multiplication
788
+ * @returns point
789
+ */
790
+ wNAFUnsafe(e, r, n, o = this.ZERO) {
791
+ const s = Zt(e, this.bits);
792
+ for (let i = 0; i < s.windows && n !== ut; i++) {
793
+ const { nextN: c, offset: f, isZero: g, isNeg: y } = se(n, i, s);
794
+ if (n = c, !g) {
795
+ const b = r[f];
796
+ o = o.add(y ? b.negate() : b);
797
+ }
798
+ }
799
+ return ie(n), o;
800
+ }
801
+ getPrecomputes(e, r, n) {
802
+ let o = Tt.get(r);
803
+ return o || (o = this.precomputeWindow(r, e), e !== 1 && (typeof n == "function" && (o = n(o)), Tt.set(r, o))), o;
804
+ }
805
+ cached(e, r, n) {
806
+ const o = Kt(e);
807
+ return this.wNAF(o, this.getPrecomputes(o, e, n), r);
808
+ }
809
+ unsafe(e, r, n, o) {
810
+ const s = Kt(e);
811
+ return s === 1 ? this._unsafeLadder(e, r, o) : this.wNAFUnsafe(s, this.getPrecomputes(s, e, n), r, o);
812
+ }
813
+ // We calculate precomputes for elliptic curve point multiplication
814
+ // using windowed method. This specifies window size and
815
+ // stores precomputed values. Usually only base point would be precomputed.
816
+ createCache(e, r) {
817
+ Le(r, this.bits), Ve.set(e, r), Tt.delete(e);
818
+ }
819
+ hasCache(e) {
820
+ return Kt(e) !== 1;
821
+ }
822
+ }
823
+ function dn(t, e, r, n) {
824
+ let o = e, s = t.ZERO, i = t.ZERO;
825
+ for (; r > ut || n > ut; )
826
+ r & nt && (s = s.add(o)), n & nt && (i = i.add(o)), o = o.double(), r >>= nt, n >>= nt;
827
+ return { p1: s, p2: i };
828
+ }
829
+ function hn(t, e, r, n) {
830
+ an(r, t), un(n, e);
831
+ const o = r.length, s = n.length;
832
+ if (o !== s)
833
+ throw new Error("arrays of points and scalars must have equal length");
834
+ const i = t.ZERO, c = xe(BigInt(o));
835
+ let f = 1;
836
+ c > 12 ? f = c - 3 : c > 4 ? f = c - 2 : c > 0 && (f = 2);
837
+ const g = yt(f), y = new Array(Number(g) + 1).fill(i), b = Math.floor((e.BITS - 1) / f) * f;
838
+ let a = i;
839
+ for (let l = b; l >= 0; l -= f) {
840
+ y.fill(i);
841
+ for (let B = 0; B < s; B++) {
842
+ const R = n[B], q = Number(R >> BigInt(l) & g);
843
+ y[q] = y[q].add(r[B]);
844
+ }
845
+ let p = i;
846
+ for (let B = y.length - 1, R = i; B > 0; B--)
847
+ R = R.add(y[B]), p = p.add(R);
848
+ if (a = a.add(p), l !== 0)
849
+ for (let B = 0; B < f; B++)
850
+ a = a.double();
851
+ }
852
+ return a;
853
+ }
854
+ function ce(t, e, r) {
855
+ if (e) {
856
+ if (e.ORDER !== t)
857
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
858
+ return cn(e), e;
859
+ } else
860
+ return bt(t, { isLE: r });
861
+ }
862
+ function gn(t, e, r = {}, n) {
863
+ if (n === void 0 && (n = t === "edwards"), !e || typeof e != "object")
864
+ throw new Error(`expected valid ${t} CURVE object`);
865
+ for (const f of ["p", "n", "h"]) {
866
+ const g = e[f];
867
+ if (!(typeof g == "bigint" && g > ut))
868
+ throw new Error(`CURVE.${f} must be positive bigint`);
869
+ }
870
+ const o = ce(e.p, r.Fp, n), s = ce(e.n, r.Fn, n), c = ["Gx", "Gy", "a", "b"];
871
+ for (const f of c)
872
+ if (!o.isValid(e[f]))
873
+ throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);
874
+ return e = Object.freeze(Object.assign({}, e)), { CURVE: e, Fp: o, Fn: s };
875
+ }
876
+ const fe = (t, e) => (t + (t >= 0 ? e : -e) / Ze) / e;
877
+ function wn(t, e, r) {
878
+ const [[n, o], [s, i]] = e, c = fe(i * t, r), f = fe(-o * t, r);
879
+ let g = t - c * n - f * s, y = -c * o - f * i;
880
+ const b = g < G, a = y < G;
881
+ b && (g = -g), a && (y = -y);
882
+ const l = yt(Math.ceil(xe(r) / 2)) + at;
883
+ if (g < G || g >= l || y < G || y >= l)
884
+ throw new Error("splitScalar (endomorphism): failed, k=" + t);
885
+ return { k1neg: b, k1: g, k2neg: a, k2: y };
886
+ }
887
+ function Yt(t) {
888
+ if (!["compact", "recovered", "der"].includes(t))
889
+ throw new Error('Signature format must be "compact", "recovered", or "der"');
890
+ return t;
891
+ }
892
+ function kt(t, e) {
893
+ const r = {};
894
+ for (let n of Object.keys(e))
895
+ r[n] = t[n] === void 0 ? e[n] : t[n];
896
+ return It(r.lowS, "lowS"), It(r.prehash, "prehash"), r.format !== void 0 && Yt(r.format), r;
897
+ }
898
+ class yn extends Error {
899
+ constructor(e = "") {
900
+ super(e);
901
+ }
902
+ }
903
+ const X = {
904
+ // asn.1 DER encoding utils
905
+ Err: yn,
906
+ // Basic building block is TLV (Tag-Length-Value)
907
+ _tlv: {
908
+ encode: (t, e) => {
909
+ const { Err: r } = X;
910
+ if (t < 0 || t > 256)
911
+ throw new r("tlv.encode: wrong tag");
912
+ if (e.length & 1)
913
+ throw new r("tlv.encode: unpadded data");
914
+ const n = e.length / 2, o = xt(n);
915
+ if (o.length / 2 & 128)
916
+ throw new r("tlv.encode: long form length too big");
917
+ const s = n > 127 ? xt(o.length / 2 | 128) : "";
918
+ return xt(t) + s + o + e;
919
+ },
920
+ // v - value, l - left bytes (unparsed)
921
+ decode(t, e) {
922
+ const { Err: r } = X;
923
+ let n = 0;
924
+ if (t < 0 || t > 256)
925
+ throw new r("tlv.encode: wrong tag");
926
+ if (e.length < 2 || e[n++] !== t)
927
+ throw new r("tlv.decode: wrong tlv");
928
+ const o = e[n++], s = !!(o & 128);
929
+ let i = 0;
930
+ if (!s)
931
+ i = o;
932
+ else {
933
+ const f = o & 127;
934
+ if (!f)
935
+ throw new r("tlv.decode(long): indefinite length not supported");
936
+ if (f > 4)
937
+ throw new r("tlv.decode(long): byte length is too big");
938
+ const g = e.subarray(n, n + f);
939
+ if (g.length !== f)
940
+ throw new r("tlv.decode: length bytes not complete");
941
+ if (g[0] === 0)
942
+ throw new r("tlv.decode(long): zero leftmost byte");
943
+ for (const y of g)
944
+ i = i << 8 | y;
945
+ if (n += f, i < 128)
946
+ throw new r("tlv.decode(long): not minimal encoding");
947
+ }
948
+ const c = e.subarray(n, n + i);
949
+ if (c.length !== i)
950
+ throw new r("tlv.decode: wrong value length");
951
+ return { v: c, l: e.subarray(n + i) };
952
+ }
953
+ },
954
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
955
+ // since we always use positive integers here. It must always be empty:
956
+ // - add zero byte if exists
957
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
958
+ _int: {
959
+ encode(t) {
960
+ const { Err: e } = X;
961
+ if (t < G)
962
+ throw new e("integer: negative integers are not allowed");
963
+ let r = xt(t);
964
+ if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
965
+ throw new e("unexpected DER parsing assertion: unpadded hex");
966
+ return r;
967
+ },
968
+ decode(t) {
969
+ const { Err: e } = X;
970
+ if (t[0] & 128)
971
+ throw new e("invalid signature integer: negative");
972
+ if (t[0] === 0 && !(t[1] & 128))
973
+ throw new e("invalid signature integer: unnecessary leading zero");
974
+ return dt(t);
975
+ }
976
+ },
977
+ toSig(t) {
978
+ const { Err: e, _int: r, _tlv: n } = X, o = T("signature", t), { v: s, l: i } = n.decode(48, o);
979
+ if (i.length)
980
+ throw new e("invalid signature: left bytes after parsing");
981
+ const { v: c, l: f } = n.decode(2, s), { v: g, l: y } = n.decode(2, f);
982
+ if (y.length)
983
+ throw new e("invalid signature: left bytes after parsing");
984
+ return { r: r.decode(c), s: r.decode(g) };
985
+ },
986
+ hexFromSig(t) {
987
+ const { _tlv: e, _int: r } = X, n = e.encode(2, r.encode(t.r)), o = e.encode(2, r.encode(t.s)), s = n + o;
988
+ return e.encode(48, s);
989
+ }
990
+ }, G = BigInt(0), at = BigInt(1), Ze = BigInt(2), Bt = BigInt(3), bn = BigInt(4);
991
+ function rt(t, e) {
992
+ const { BYTES: r } = t;
993
+ let n;
994
+ if (typeof e == "bigint")
995
+ n = e;
996
+ else {
997
+ let o = T("private key", e);
998
+ try {
999
+ n = t.fromBytes(o);
1000
+ } catch {
1001
+ throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`);
1002
+ }
1003
+ }
1004
+ if (!t.isValidNot0(n))
1005
+ throw new Error("invalid private key: out of range [1..N-1]");
1006
+ return n;
1007
+ }
1008
+ function mn(t, e = {}) {
1009
+ const r = gn("weierstrass", t, e), { Fp: n, Fn: o } = r;
1010
+ let s = r.CURVE;
1011
+ const { h: i, n: c } = s;
1012
+ Ft(e, {}, {
1013
+ allowInfinityPoint: "boolean",
1014
+ clearCofactor: "function",
1015
+ isTorsionFree: "function",
1016
+ fromBytes: "function",
1017
+ toBytes: "function",
1018
+ endo: "object",
1019
+ wrapPrivateKey: "boolean"
1020
+ });
1021
+ const { endo: f } = e;
1022
+ if (f && (!n.is0(s.a) || typeof f.beta != "bigint" || !Array.isArray(f.basises)))
1023
+ throw new Error('invalid endo: expected "beta": bigint and "basises": array');
1024
+ const g = Ke(n, o);
1025
+ function y() {
1026
+ if (!n.isOdd)
1027
+ throw new Error("compression is not supported: Field does not have .isOdd()");
1028
+ }
1029
+ function b(N, h, d) {
1030
+ const { x: u, y: w } = h.toAffine(), m = n.toBytes(u);
1031
+ if (It(d, "isCompressed"), d) {
1032
+ y();
1033
+ const v = !n.isOdd(w);
1034
+ return z(Te(v), m);
1035
+ } else
1036
+ return z(Uint8Array.of(4), m, n.toBytes(w));
1037
+ }
1038
+ function a(N) {
1039
+ tt(N, void 0, "Point");
1040
+ const { publicKey: h, publicKeyUncompressed: d } = g, u = N.length, w = N[0], m = N.subarray(1);
1041
+ if (u === h && (w === 2 || w === 3)) {
1042
+ const v = n.fromBytes(m);
1043
+ if (!n.isValid(v))
1044
+ throw new Error("bad point: is not on curve, wrong x");
1045
+ const x = B(v);
1046
+ let E;
1047
+ try {
1048
+ E = n.sqrt(x);
1049
+ } catch (V) {
1050
+ const U = V instanceof Error ? ": " + V.message : "";
1051
+ throw new Error("bad point: is not on curve, sqrt error" + U);
1052
+ }
1053
+ y();
1054
+ const S = n.isOdd(E);
1055
+ return (w & 1) === 1 !== S && (E = n.neg(E)), { x: v, y: E };
1056
+ } else if (u === d && w === 4) {
1057
+ const v = n.BYTES, x = n.fromBytes(m.subarray(0, v)), E = n.fromBytes(m.subarray(v, v * 2));
1058
+ if (!R(x, E))
1059
+ throw new Error("bad point: is not on curve");
1060
+ return { x, y: E };
1061
+ } else
1062
+ throw new Error(`bad point: got length ${u}, expected compressed=${h} or uncompressed=${d}`);
1063
+ }
1064
+ const l = e.toBytes || b, p = e.fromBytes || a;
1065
+ function B(N) {
1066
+ const h = n.sqr(N), d = n.mul(h, N);
1067
+ return n.add(n.add(d, n.mul(N, s.a)), s.b);
1068
+ }
1069
+ function R(N, h) {
1070
+ const d = n.sqr(h), u = B(N);
1071
+ return n.eql(d, u);
1072
+ }
1073
+ if (!R(s.Gx, s.Gy))
1074
+ throw new Error("bad curve params: generator point");
1075
+ const q = n.mul(n.pow(s.a, Bt), bn), gt = n.mul(n.sqr(s.b), BigInt(27));
1076
+ if (n.is0(n.add(q, gt)))
1077
+ throw new Error("bad curve params: a or b");
1078
+ function L(N, h, d = !1) {
1079
+ if (!n.isValid(h) || d && n.is0(h))
1080
+ throw new Error(`bad point coordinate ${N}`);
1081
+ return h;
1082
+ }
1083
+ function Q(N) {
1084
+ if (!(N instanceof I))
1085
+ throw new Error("ProjectivePoint expected");
1086
+ }
1087
+ function F(N) {
1088
+ if (!f || !f.basises)
1089
+ throw new Error("no endo");
1090
+ return wn(N, f.basises, o.ORDER);
1091
+ }
1092
+ const st = ne((N, h) => {
1093
+ const { X: d, Y: u, Z: w } = N;
1094
+ if (n.eql(w, n.ONE))
1095
+ return { x: d, y: u };
1096
+ const m = N.is0();
1097
+ h == null && (h = m ? n.ONE : n.inv(w));
1098
+ const v = n.mul(d, h), x = n.mul(u, h), E = n.mul(w, h);
1099
+ if (m)
1100
+ return { x: n.ZERO, y: n.ZERO };
1101
+ if (!n.eql(E, n.ONE))
1102
+ throw new Error("invZ was invalid");
1103
+ return { x: v, y: x };
1104
+ }), mt = ne((N) => {
1105
+ if (N.is0()) {
1106
+ if (e.allowInfinityPoint && !n.is0(N.Y))
1107
+ return;
1108
+ throw new Error("bad point: ZERO");
1109
+ }
1110
+ const { x: h, y: d } = N.toAffine();
1111
+ if (!n.isValid(h) || !n.isValid(d))
1112
+ throw new Error("bad point: x or y not field elements");
1113
+ if (!R(h, d))
1114
+ throw new Error("bad point: equation left != right");
1115
+ if (!N.isTorsionFree())
1116
+ throw new Error("bad point: not in prime-order subgroup");
1117
+ return !0;
1118
+ });
1119
+ function it(N, h, d, u, w) {
1120
+ return d = new I(n.mul(d.X, N), d.Y, d.Z), h = _t(u, h), d = _t(w, d), h.add(d);
1121
+ }
1122
+ class I {
1123
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
1124
+ constructor(h, d, u) {
1125
+ this.X = L("x", h), this.Y = L("y", d, !0), this.Z = L("z", u), Object.freeze(this);
1126
+ }
1127
+ static CURVE() {
1128
+ return s;
1129
+ }
1130
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
1131
+ static fromAffine(h) {
1132
+ const { x: d, y: u } = h || {};
1133
+ if (!h || !n.isValid(d) || !n.isValid(u))
1134
+ throw new Error("invalid affine point");
1135
+ if (h instanceof I)
1136
+ throw new Error("projective point not allowed");
1137
+ return n.is0(d) && n.is0(u) ? I.ZERO : new I(d, u, n.ONE);
1138
+ }
1139
+ static fromBytes(h) {
1140
+ const d = I.fromAffine(p(tt(h, void 0, "point")));
1141
+ return d.assertValidity(), d;
1142
+ }
1143
+ static fromHex(h) {
1144
+ return I.fromBytes(T("pointHex", h));
1145
+ }
1146
+ get x() {
1147
+ return this.toAffine().x;
1148
+ }
1149
+ get y() {
1150
+ return this.toAffine().y;
1151
+ }
1152
+ /**
1153
+ *
1154
+ * @param windowSize
1155
+ * @param isLazy true will defer table computation until the first multiplication
1156
+ * @returns
1157
+ */
1158
+ precompute(h = 8, d = !0) {
1159
+ return J.createCache(this, h), d || this.multiply(Bt), this;
1160
+ }
1161
+ // TODO: return `this`
1162
+ /** A point on curve is valid if it conforms to equation. */
1163
+ assertValidity() {
1164
+ mt(this);
1165
+ }
1166
+ hasEvenY() {
1167
+ const { y: h } = this.toAffine();
1168
+ if (!n.isOdd)
1169
+ throw new Error("Field doesn't support isOdd");
1170
+ return !n.isOdd(h);
1171
+ }
1172
+ /** Compare one point to another. */
1173
+ equals(h) {
1174
+ Q(h);
1175
+ const { X: d, Y: u, Z: w } = this, { X: m, Y: v, Z: x } = h, E = n.eql(n.mul(d, x), n.mul(m, w)), S = n.eql(n.mul(u, x), n.mul(v, w));
1176
+ return E && S;
1177
+ }
1178
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
1179
+ negate() {
1180
+ return new I(this.X, n.neg(this.Y), this.Z);
1181
+ }
1182
+ // Renes-Costello-Batina exception-free doubling formula.
1183
+ // There is 30% faster Jacobian formula, but it is not complete.
1184
+ // https://eprint.iacr.org/2015/1060, algorithm 3
1185
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
1186
+ double() {
1187
+ const { a: h, b: d } = s, u = n.mul(d, Bt), { X: w, Y: m, Z: v } = this;
1188
+ let x = n.ZERO, E = n.ZERO, S = n.ZERO, A = n.mul(w, w), V = n.mul(m, m), U = n.mul(v, v), _ = n.mul(w, m);
1189
+ return _ = n.add(_, _), S = n.mul(w, v), S = n.add(S, S), x = n.mul(h, S), E = n.mul(u, U), E = n.add(x, E), x = n.sub(V, E), E = n.add(V, E), E = n.mul(x, E), x = n.mul(_, x), S = n.mul(u, S), U = n.mul(h, U), _ = n.sub(A, U), _ = n.mul(h, _), _ = n.add(_, S), S = n.add(A, A), A = n.add(S, A), A = n.add(A, U), A = n.mul(A, _), E = n.add(E, A), U = n.mul(m, v), U = n.add(U, U), A = n.mul(U, _), x = n.sub(x, A), S = n.mul(U, V), S = n.add(S, S), S = n.add(S, S), new I(x, E, S);
1190
+ }
1191
+ // Renes-Costello-Batina exception-free addition formula.
1192
+ // There is 30% faster Jacobian formula, but it is not complete.
1193
+ // https://eprint.iacr.org/2015/1060, algorithm 1
1194
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
1195
+ add(h) {
1196
+ Q(h);
1197
+ const { X: d, Y: u, Z: w } = this, { X: m, Y: v, Z: x } = h;
1198
+ let E = n.ZERO, S = n.ZERO, A = n.ZERO;
1199
+ const V = s.a, U = n.mul(s.b, Bt);
1200
+ let _ = n.mul(d, m), H = n.mul(u, v), Z = n.mul(w, x), C = n.add(d, u), O = n.add(m, v);
1201
+ C = n.mul(C, O), O = n.add(_, H), C = n.sub(C, O), O = n.add(d, w);
1202
+ let K = n.add(m, x);
1203
+ return O = n.mul(O, K), K = n.add(_, Z), O = n.sub(O, K), K = n.add(u, w), E = n.add(v, x), K = n.mul(K, E), E = n.add(H, Z), K = n.sub(K, E), A = n.mul(V, O), E = n.mul(U, Z), A = n.add(E, A), E = n.sub(H, A), A = n.add(H, A), S = n.mul(E, A), H = n.add(_, _), H = n.add(H, _), Z = n.mul(V, Z), O = n.mul(U, O), H = n.add(H, Z), Z = n.sub(_, Z), Z = n.mul(V, Z), O = n.add(O, Z), _ = n.mul(H, O), S = n.add(S, _), _ = n.mul(K, O), E = n.mul(C, E), E = n.sub(E, _), _ = n.mul(C, H), A = n.mul(K, A), A = n.add(A, _), new I(E, S, A);
1204
+ }
1205
+ subtract(h) {
1206
+ return this.add(h.negate());
1207
+ }
1208
+ is0() {
1209
+ return this.equals(I.ZERO);
1210
+ }
1211
+ /**
1212
+ * Constant time multiplication.
1213
+ * Uses wNAF method. Windowed method may be 10% faster,
1214
+ * but takes 2x longer to generate and consumes 2x memory.
1215
+ * Uses precomputes when available.
1216
+ * Uses endomorphism for Koblitz curves.
1217
+ * @param scalar by which the point would be multiplied
1218
+ * @returns New point
1219
+ */
1220
+ multiply(h) {
1221
+ const { endo: d } = e;
1222
+ if (!o.isValidNot0(h))
1223
+ throw new Error("invalid scalar: out of range");
1224
+ let u, w;
1225
+ const m = (v) => J.cached(this, v, (x) => Vt(I, x));
1226
+ if (d) {
1227
+ const { k1neg: v, k1: x, k2neg: E, k2: S } = F(h), { p: A, f: V } = m(x), { p: U, f: _ } = m(S);
1228
+ w = V.add(_), u = it(d.beta, A, U, v, E);
1229
+ } else {
1230
+ const { p: v, f: x } = m(h);
1231
+ u = v, w = x;
1232
+ }
1233
+ return Vt(I, [u, w])[0];
1234
+ }
1235
+ /**
1236
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
1237
+ * It's faster, but should only be used when you don't care about
1238
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
1239
+ */
1240
+ multiplyUnsafe(h) {
1241
+ const { endo: d } = e, u = this;
1242
+ if (!o.isValid(h))
1243
+ throw new Error("invalid scalar: out of range");
1244
+ if (h === G || u.is0())
1245
+ return I.ZERO;
1246
+ if (h === at)
1247
+ return u;
1248
+ if (J.hasCache(this))
1249
+ return this.multiply(h);
1250
+ if (d) {
1251
+ const { k1neg: w, k1: m, k2neg: v, k2: x } = F(h), { p1: E, p2: S } = dn(I, u, m, x);
1252
+ return it(d.beta, E, S, w, v);
1253
+ } else
1254
+ return J.unsafe(u, h);
1255
+ }
1256
+ multiplyAndAddUnsafe(h, d, u) {
1257
+ const w = this.multiplyUnsafe(d).add(h.multiplyUnsafe(u));
1258
+ return w.is0() ? void 0 : w;
1259
+ }
1260
+ /**
1261
+ * Converts Projective point to affine (x, y) coordinates.
1262
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
1263
+ */
1264
+ toAffine(h) {
1265
+ return st(this, h);
1266
+ }
1267
+ /**
1268
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
1269
+ * Always torsion-free for cofactor=1 curves.
1270
+ */
1271
+ isTorsionFree() {
1272
+ const { isTorsionFree: h } = e;
1273
+ return i === at ? !0 : h ? h(I, this) : J.unsafe(this, c).is0();
1274
+ }
1275
+ clearCofactor() {
1276
+ const { clearCofactor: h } = e;
1277
+ return i === at ? this : h ? h(I, this) : this.multiplyUnsafe(i);
1278
+ }
1279
+ isSmallOrder() {
1280
+ return this.multiplyUnsafe(i).is0();
1281
+ }
1282
+ toBytes(h = !0) {
1283
+ return It(h, "isCompressed"), this.assertValidity(), l(I, this, h);
1284
+ }
1285
+ toHex(h = !0) {
1286
+ return ft(this.toBytes(h));
1287
+ }
1288
+ toString() {
1289
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
1290
+ }
1291
+ // TODO: remove
1292
+ get px() {
1293
+ return this.X;
1294
+ }
1295
+ get py() {
1296
+ return this.X;
1297
+ }
1298
+ get pz() {
1299
+ return this.Z;
1300
+ }
1301
+ toRawBytes(h = !0) {
1302
+ return this.toBytes(h);
1303
+ }
1304
+ _setWindowSize(h) {
1305
+ this.precompute(h);
1306
+ }
1307
+ static normalizeZ(h) {
1308
+ return Vt(I, h);
1309
+ }
1310
+ static msm(h, d) {
1311
+ return hn(I, o, h, d);
1312
+ }
1313
+ static fromPrivateKey(h) {
1314
+ return I.BASE.multiply(rt(o, h));
1315
+ }
1316
+ }
1317
+ I.BASE = new I(s.Gx, s.Gy, n.ONE), I.ZERO = new I(n.ZERO, n.ONE, n.ZERO), I.Fp = n, I.Fn = o;
1318
+ const pt = o.BITS, J = new ln(I, e.endo ? Math.ceil(pt / 2) : pt);
1319
+ return I.BASE.precompute(8), I;
1320
+ }
1321
+ function Te(t) {
1322
+ return Uint8Array.of(t ? 2 : 3);
1323
+ }
1324
+ function Ke(t, e) {
1325
+ return {
1326
+ secretKey: e.BYTES,
1327
+ publicKey: 1 + t.BYTES,
1328
+ publicKeyUncompressed: 1 + 2 * t.BYTES,
1329
+ publicKeyHasPrefix: !0,
1330
+ signature: 2 * e.BYTES
1331
+ };
1332
+ }
1333
+ function pn(t, e = {}) {
1334
+ const { Fn: r } = t, n = e.randomBytes || Ht, o = Object.assign(Ke(t.Fp, r), { seed: Oe(r.ORDER) });
1335
+ function s(l) {
1336
+ try {
1337
+ return !!rt(r, l);
1338
+ } catch {
1339
+ return !1;
1340
+ }
1341
+ }
1342
+ function i(l, p) {
1343
+ const { publicKey: B, publicKeyUncompressed: R } = o;
1344
+ try {
1345
+ const q = l.length;
1346
+ return p === !0 && q !== B || p === !1 && q !== R ? !1 : !!t.fromBytes(l);
1347
+ } catch {
1348
+ return !1;
1349
+ }
1350
+ }
1351
+ function c(l = n(o.seed)) {
1352
+ return qe(tt(l, o.seed, "seed"), r.ORDER);
1353
+ }
1354
+ function f(l, p = !0) {
1355
+ return t.BASE.multiply(rt(r, l)).toBytes(p);
1356
+ }
1357
+ function g(l) {
1358
+ const p = c(l);
1359
+ return { secretKey: p, publicKey: f(p) };
1360
+ }
1361
+ function y(l) {
1362
+ if (typeof l == "bigint")
1363
+ return !1;
1364
+ if (l instanceof t)
1365
+ return !0;
1366
+ const { secretKey: p, publicKey: B, publicKeyUncompressed: R } = o;
1367
+ if (r.allowedLengths || p === B)
1368
+ return;
1369
+ const q = T("key", l).length;
1370
+ return q === B || q === R;
1371
+ }
1372
+ function b(l, p, B = !0) {
1373
+ if (y(l) === !0)
1374
+ throw new Error("first arg must be private key");
1375
+ if (y(p) === !1)
1376
+ throw new Error("second arg must be public key");
1377
+ const R = rt(r, l);
1378
+ return t.fromHex(p).multiply(R).toBytes(B);
1379
+ }
1380
+ return Object.freeze({ getPublicKey: f, getSharedSecret: b, keygen: g, Point: t, utils: {
1381
+ isValidSecretKey: s,
1382
+ isValidPublicKey: i,
1383
+ randomSecretKey: c,
1384
+ // TODO: remove
1385
+ isValidPrivateKey: s,
1386
+ randomPrivateKey: c,
1387
+ normPrivateKeyToScalar: (l) => rt(r, l),
1388
+ precompute(l = 8, p = t.BASE) {
1389
+ return p.precompute(l, !1);
1390
+ }
1391
+ }, lengths: o });
1392
+ }
1393
+ function En(t, e, r = {}) {
1394
+ de(e), Ft(r, {}, {
1395
+ hmac: "function",
1396
+ lowS: "boolean",
1397
+ randomBytes: "function",
1398
+ bits2int: "function",
1399
+ bits2int_modN: "function"
1400
+ });
1401
+ const n = r.randomBytes || Ht, o = r.hmac || ((d, ...u) => be(e, d, z(...u))), { Fp: s, Fn: i } = t, { ORDER: c, BITS: f } = i, { keygen: g, getPublicKey: y, getSharedSecret: b, utils: a, lengths: l } = pn(t, r), p = {
1402
+ prehash: !1,
1403
+ lowS: typeof r.lowS == "boolean" ? r.lowS : !1,
1404
+ format: void 0,
1405
+ //'compact' as ECDSASigFormat,
1406
+ extraEntropy: !1
1407
+ }, B = "compact";
1408
+ function R(d) {
1409
+ const u = c >> at;
1410
+ return d > u;
1411
+ }
1412
+ function q(d, u) {
1413
+ if (!i.isValidNot0(u))
1414
+ throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);
1415
+ return u;
1416
+ }
1417
+ function gt(d, u) {
1418
+ Yt(u);
1419
+ const w = l.signature, m = u === "compact" ? w : u === "recovered" ? w + 1 : void 0;
1420
+ return tt(d, m, `${u} signature`);
1421
+ }
1422
+ class L {
1423
+ constructor(u, w, m) {
1424
+ this.r = q("r", u), this.s = q("s", w), m != null && (this.recovery = m), Object.freeze(this);
1425
+ }
1426
+ static fromBytes(u, w = B) {
1427
+ gt(u, w);
1428
+ let m;
1429
+ if (w === "der") {
1430
+ const { r: S, s: A } = X.toSig(tt(u));
1431
+ return new L(S, A);
1432
+ }
1433
+ w === "recovered" && (m = u[0], w = "compact", u = u.subarray(1));
1434
+ const v = i.BYTES, x = u.subarray(0, v), E = u.subarray(v, v * 2);
1435
+ return new L(i.fromBytes(x), i.fromBytes(E), m);
1436
+ }
1437
+ static fromHex(u, w) {
1438
+ return this.fromBytes(At(u), w);
1439
+ }
1440
+ addRecoveryBit(u) {
1441
+ return new L(this.r, this.s, u);
1442
+ }
1443
+ recoverPublicKey(u) {
1444
+ const w = s.ORDER, { r: m, s: v, recovery: x } = this;
1445
+ if (x == null || ![0, 1, 2, 3].includes(x))
1446
+ throw new Error("recovery id invalid");
1447
+ if (c * Ze < w && x > 1)
1448
+ throw new Error("recovery id is ambiguous for h>1 curve");
1449
+ const S = x === 2 || x === 3 ? m + c : m;
1450
+ if (!s.isValid(S))
1451
+ throw new Error("recovery id 2 or 3 invalid");
1452
+ const A = s.toBytes(S), V = t.fromBytes(z(Te((x & 1) === 0), A)), U = i.inv(S), _ = F(T("msgHash", u)), H = i.create(-_ * U), Z = i.create(v * U), C = t.BASE.multiplyUnsafe(H).add(V.multiplyUnsafe(Z));
1453
+ if (C.is0())
1454
+ throw new Error("point at infinify");
1455
+ return C.assertValidity(), C;
1456
+ }
1457
+ // Signatures should be low-s, to prevent malleability.
1458
+ hasHighS() {
1459
+ return R(this.s);
1460
+ }
1461
+ toBytes(u = B) {
1462
+ if (Yt(u), u === "der")
1463
+ return At(X.hexFromSig(this));
1464
+ const w = i.toBytes(this.r), m = i.toBytes(this.s);
1465
+ if (u === "recovered") {
1466
+ if (this.recovery == null)
1467
+ throw new Error("recovery bit must be present");
1468
+ return z(Uint8Array.of(this.recovery), w, m);
1469
+ }
1470
+ return z(w, m);
1471
+ }
1472
+ toHex(u) {
1473
+ return ft(this.toBytes(u));
1474
+ }
1475
+ // TODO: remove
1476
+ assertValidity() {
1477
+ }
1478
+ static fromCompact(u) {
1479
+ return L.fromBytes(T("sig", u), "compact");
1480
+ }
1481
+ static fromDER(u) {
1482
+ return L.fromBytes(T("sig", u), "der");
1483
+ }
1484
+ normalizeS() {
1485
+ return this.hasHighS() ? new L(this.r, i.neg(this.s), this.recovery) : this;
1486
+ }
1487
+ toDERRawBytes() {
1488
+ return this.toBytes("der");
1489
+ }
1490
+ toDERHex() {
1491
+ return ft(this.toBytes("der"));
1492
+ }
1493
+ toCompactRawBytes() {
1494
+ return this.toBytes("compact");
1495
+ }
1496
+ toCompactHex() {
1497
+ return ft(this.toBytes("compact"));
1498
+ }
1499
+ }
1500
+ const Q = r.bits2int || function(u) {
1501
+ if (u.length > 8192)
1502
+ throw new Error("input is too large");
1503
+ const w = dt(u), m = u.length * 8 - f;
1504
+ return m > 0 ? w >> BigInt(m) : w;
1505
+ }, F = r.bits2int_modN || function(u) {
1506
+ return i.create(Q(u));
1507
+ }, st = yt(f);
1508
+ function mt(d) {
1509
+ return Qe("num < 2^" + f, d, G, st), i.toBytes(d);
1510
+ }
1511
+ function it(d, u) {
1512
+ return tt(d, void 0, "message"), u ? tt(e(d), void 0, "prehashed message") : d;
1513
+ }
1514
+ function I(d, u, w) {
1515
+ if (["recovered", "canonical"].some((H) => H in w))
1516
+ throw new Error("sign() legacy options not supported");
1517
+ const { lowS: m, prehash: v, extraEntropy: x } = kt(w, p);
1518
+ d = it(d, v);
1519
+ const E = F(d), S = rt(i, u), A = [mt(S), mt(E)];
1520
+ if (x != null && x !== !1) {
1521
+ const H = x === !0 ? n(l.secretKey) : x;
1522
+ A.push(T("extraEntropy", H));
1523
+ }
1524
+ const V = z(...A), U = E;
1525
+ function _(H) {
1526
+ const Z = Q(H);
1527
+ if (!i.isValidNot0(Z))
1528
+ return;
1529
+ const C = i.inv(Z), O = t.BASE.multiply(Z).toAffine(), K = i.create(O.x);
1530
+ if (K === G)
1531
+ return;
1532
+ const Et = i.create(C * i.create(U + K * S));
1533
+ if (Et === G)
1534
+ return;
1535
+ let Jt = (O.x === K ? 0 : 2) | Number(O.y & at), te = Et;
1536
+ return m && R(Et) && (te = i.neg(Et), Jt ^= 1), new L(K, te, Jt);
1537
+ }
1538
+ return { seed: V, k2sig: _ };
1539
+ }
1540
+ function pt(d, u, w = {}) {
1541
+ d = T("message", d);
1542
+ const { seed: m, k2sig: v } = I(d, u, w);
1543
+ return Je(e.outputLen, i.BYTES, o)(m, v);
1544
+ }
1545
+ function J(d) {
1546
+ let u;
1547
+ const w = typeof d == "string" || Ut(d), m = !w && d !== null && typeof d == "object" && typeof d.r == "bigint" && typeof d.s == "bigint";
1548
+ if (!w && !m)
1549
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
1550
+ if (m)
1551
+ u = new L(d.r, d.s);
1552
+ else if (w) {
1553
+ try {
1554
+ u = L.fromBytes(T("sig", d), "der");
1555
+ } catch (v) {
1556
+ if (!(v instanceof X.Err))
1557
+ throw v;
1558
+ }
1559
+ if (!u)
1560
+ try {
1561
+ u = L.fromBytes(T("sig", d), "compact");
1562
+ } catch {
1563
+ return !1;
1564
+ }
1565
+ }
1566
+ return u || !1;
1567
+ }
1568
+ function N(d, u, w, m = {}) {
1569
+ const { lowS: v, prehash: x, format: E } = kt(m, p);
1570
+ if (w = T("publicKey", w), u = it(T("message", u), x), "strict" in m)
1571
+ throw new Error("options.strict was renamed to lowS");
1572
+ const S = E === void 0 ? J(d) : L.fromBytes(T("sig", d), E);
1573
+ if (S === !1)
1574
+ return !1;
1575
+ try {
1576
+ const A = t.fromBytes(w);
1577
+ if (v && S.hasHighS())
1578
+ return !1;
1579
+ const { r: V, s: U } = S, _ = F(u), H = i.inv(U), Z = i.create(_ * H), C = i.create(V * H), O = t.BASE.multiplyUnsafe(Z).add(A.multiplyUnsafe(C));
1580
+ return O.is0() ? !1 : i.create(O.x) === V;
1581
+ } catch {
1582
+ return !1;
1583
+ }
1584
+ }
1585
+ function h(d, u, w = {}) {
1586
+ const { prehash: m } = kt(w, p);
1587
+ return u = it(u, m), L.fromBytes(d, "recovered").recoverPublicKey(u).toBytes();
1588
+ }
1589
+ return Object.freeze({
1590
+ keygen: g,
1591
+ getPublicKey: y,
1592
+ getSharedSecret: b,
1593
+ utils: a,
1594
+ lengths: l,
1595
+ Point: t,
1596
+ sign: pt,
1597
+ verify: N,
1598
+ recoverPublicKey: h,
1599
+ Signature: L,
1600
+ hash: e
1601
+ });
1602
+ }
1603
+ function xn(t) {
1604
+ const e = {
1605
+ a: t.a,
1606
+ b: t.b,
1607
+ p: t.Fp.ORDER,
1608
+ n: t.n,
1609
+ h: t.h,
1610
+ Gx: t.Gx,
1611
+ Gy: t.Gy
1612
+ }, r = t.Fp;
1613
+ let n = t.allowedPrivateKeyLengths ? Array.from(new Set(t.allowedPrivateKeyLengths.map((i) => Math.ceil(i / 2)))) : void 0;
1614
+ const o = bt(e.n, {
1615
+ BITS: t.nBitLength,
1616
+ allowedLengths: n,
1617
+ modFromBytes: t.wrapPrivateKey
1618
+ }), s = {
1619
+ Fp: r,
1620
+ Fn: o,
1621
+ allowInfinityPoint: t.allowInfinityPoint,
1622
+ endo: t.endo,
1623
+ isTorsionFree: t.isTorsionFree,
1624
+ clearCofactor: t.clearCofactor,
1625
+ fromBytes: t.fromBytes,
1626
+ toBytes: t.toBytes
1627
+ };
1628
+ return { CURVE: e, curveOpts: s };
1629
+ }
1630
+ function Bn(t) {
1631
+ const { CURVE: e, curveOpts: r } = xn(t), n = {
1632
+ hmac: t.hmac,
1633
+ randomBytes: t.randomBytes,
1634
+ lowS: t.lowS,
1635
+ bits2int: t.bits2int,
1636
+ bits2int_modN: t.bits2int_modN
1637
+ };
1638
+ return { CURVE: e, curveOpts: r, hash: t.hash, ecdsaOpts: n };
1639
+ }
1640
+ function vn(t, e) {
1641
+ const r = e.Point;
1642
+ return Object.assign({}, e, {
1643
+ ProjectivePoint: r,
1644
+ CURVE: Object.assign({}, t, Ue(r.Fn.ORDER, r.Fn.BITS))
1645
+ });
1646
+ }
1647
+ function Sn(t) {
1648
+ const { CURVE: e, curveOpts: r, hash: n, ecdsaOpts: o } = Bn(t), s = mn(e, r), i = En(s, n, o);
1649
+ return vn(t, i);
1650
+ }
1651
+ function An(t, e) {
1652
+ const r = (n) => Sn({ ...t, hash: n });
1653
+ return { ...r(e), create: r };
1654
+ }
1655
+ const lt = {
1656
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
1657
+ n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
1658
+ h: BigInt(1),
1659
+ a: BigInt(0),
1660
+ b: BigInt(7),
1661
+ Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
1662
+ Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
1663
+ }, In = {
1664
+ beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1665
+ basises: [
1666
+ [BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
1667
+ [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
1668
+ ]
1669
+ }, _n = /* @__PURE__ */ BigInt(0), ae = /* @__PURE__ */ BigInt(1), zt = /* @__PURE__ */ BigInt(2);
1670
+ function Nn(t) {
1671
+ const e = lt.p, r = BigInt(3), n = BigInt(6), o = BigInt(11), s = BigInt(22), i = BigInt(23), c = BigInt(44), f = BigInt(88), g = t * t * t % e, y = g * g * t % e, b = M(y, r, e) * y % e, a = M(b, r, e) * y % e, l = M(a, zt, e) * g % e, p = M(l, o, e) * l % e, B = M(p, s, e) * p % e, R = M(B, c, e) * B % e, q = M(R, f, e) * R % e, gt = M(q, c, e) * B % e, L = M(gt, r, e) * y % e, Q = M(L, i, e) * p % e, F = M(Q, n, e) * g % e, st = M(F, zt, e);
1672
+ if (!Nt.eql(Nt.sqr(st), t))
1673
+ throw new Error("Cannot find square root");
1674
+ return st;
1675
+ }
1676
+ const Nt = bt(lt.p, { sqrt: Nn }), ke = An({ ...lt, Fp: Nt, lowS: !0, endo: In }, $t), ue = {};
1677
+ function Rt(t, ...e) {
1678
+ let r = ue[t];
1679
+ if (r === void 0) {
1680
+ const n = $t(ge(t));
1681
+ r = z(n, n), ue[t] = r;
1682
+ }
1683
+ return $t(z(r, ...e));
1684
+ }
1685
+ const Wt = (t) => t.toBytes(!0).slice(1), ht = ke.Point, Qt = (t) => t % zt === _n;
1686
+ function Dt(t) {
1687
+ const { Fn: e, BASE: r } = ht, n = rt(e, t), o = r.multiply(n);
1688
+ return { scalar: Qt(o.y) ? n : e.neg(n), bytes: Wt(o) };
1689
+ }
1690
+ function Ce(t) {
1691
+ const e = Nt;
1692
+ if (!e.isValidNot0(t))
1693
+ throw new Error("invalid x: Fail if x ≥ p");
1694
+ const r = e.create(t * t), n = e.create(r * t + BigInt(7));
1695
+ let o = e.sqrt(n);
1696
+ Qt(o) || (o = e.neg(o));
1697
+ const s = ht.fromAffine({ x: t, y: o });
1698
+ return s.assertValidity(), s;
1699
+ }
1700
+ const wt = dt;
1701
+ function $e(...t) {
1702
+ return ht.Fn.create(wt(Rt("BIP0340/challenge", ...t)));
1703
+ }
1704
+ function le(t) {
1705
+ return Dt(t).bytes;
1706
+ }
1707
+ function Rn(t, e, r = Ht(32)) {
1708
+ const { Fn: n } = ht, o = T("message", t), { bytes: s, scalar: i } = Dt(e), c = T("auxRand", r, 32), f = n.toBytes(i ^ wt(Rt("BIP0340/aux", c))), g = Rt("BIP0340/nonce", f, s, o), { bytes: y, scalar: b } = Dt(g), a = $e(y, s, o), l = new Uint8Array(64);
1709
+ if (l.set(y, 0), l.set(n.toBytes(n.create(b + a * i)), 32), !Me(l, o, s))
1710
+ throw new Error("sign: Invalid signature produced");
1711
+ return l;
1712
+ }
1713
+ function Me(t, e, r) {
1714
+ const { Fn: n, BASE: o } = ht, s = T("signature", t, 64), i = T("message", e), c = T("publicKey", r, 32);
1715
+ try {
1716
+ const f = Ce(wt(c)), g = wt(s.subarray(0, 32));
1717
+ if (!jt(g, ae, lt.p))
1718
+ return !1;
1719
+ const y = wt(s.subarray(32, 64));
1720
+ if (!jt(y, ae, lt.n))
1721
+ return !1;
1722
+ const b = $e(n.toBytes(g), Wt(f), i), a = o.multiplyUnsafe(y).add(f.multiplyUnsafe(n.neg(b))), { x: l, y: p } = a.toAffine();
1723
+ return !(a.is0() || !Qt(p) || l !== g);
1724
+ } catch {
1725
+ return !1;
1726
+ }
1727
+ }
1728
+ const Hn = /* @__PURE__ */ (() => {
1729
+ const r = (o = Ht(48)) => qe(o, lt.n);
1730
+ ke.utils.randomSecretKey;
1731
+ function n(o) {
1732
+ const s = r(o);
1733
+ return { secretKey: s, publicKey: le(s) };
1734
+ }
1735
+ return {
1736
+ keygen: n,
1737
+ getPublicKey: le,
1738
+ sign: Rn,
1739
+ verify: Me,
1740
+ Point: ht,
1741
+ utils: {
1742
+ randomSecretKey: r,
1743
+ randomPrivateKey: r,
1744
+ taggedHash: Rt,
1745
+ // TODO: remove
1746
+ lift_x: Ce,
1747
+ pointToBytes: Wt,
1748
+ numberToBytesBE: Ot,
1749
+ bytesToNumberBE: dt,
1750
+ mod: j
1751
+ },
1752
+ lengths: {
1753
+ secretKey: 32,
1754
+ publicKey: 32,
1755
+ publicKeyHasPrefix: !1,
1756
+ signature: 64,
1757
+ seed: 48
1758
+ }
1759
+ };
1760
+ })();
1761
+ export {
1762
+ Un as a,
1763
+ Hn as b,
1764
+ ke as s
1765
+ };
1766
+ //# sourceMappingURL=secp256k1-D-H9jmd7.js.map