@pufferfinance/puffer-sdk 1.13.0 → 1.13.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 (143) hide show
  1. package/dist/api/puffer-client-helpers.cjs +1 -1
  2. package/dist/api/puffer-client-helpers.cjs.map +1 -1
  3. package/dist/api/puffer-client-helpers.js +70 -65
  4. package/dist/api/puffer-client-helpers.js.map +1 -1
  5. package/dist/api/puffer-client.cjs +1 -1
  6. package/dist/api/puffer-client.js +2 -2
  7. package/dist/{ccip-BO_b9tFc.cjs → ccip-C0xwQhXU.cjs} +2 -2
  8. package/dist/ccip-C0xwQhXU.cjs.map +1 -0
  9. package/dist/{ccip-DLDO0_x2.js → ccip-K-z2PL4P.js} +3 -3
  10. package/dist/ccip-K-z2PL4P.js.map +1 -0
  11. package/dist/chains/constants.cjs +1 -1
  12. package/dist/chains/constants.js +1 -1
  13. package/dist/constants-BcPRVxdH.cjs +9 -0
  14. package/dist/constants-BcPRVxdH.cjs.map +1 -0
  15. package/dist/{constants-BjRNQpT2.js → constants-CH7Tz5jz.js} +745 -694
  16. package/dist/constants-CH7Tz5jz.js.map +1 -0
  17. package/dist/contracts/abis/l1-reward-manager-abis.cjs +1 -1
  18. package/dist/contracts/abis/l1-reward-manager-abis.d.ts +527 -1
  19. package/dist/contracts/abis/l1-reward-manager-abis.js +1 -1
  20. package/dist/contracts/abis/l2-reward-manager-abis.cjs +1 -1
  21. package/dist/contracts/abis/l2-reward-manager-abis.d.ts +1416 -1
  22. package/dist/contracts/abis/l2-reward-manager-abis.js +1 -1
  23. package/dist/contracts/abis/nucleus-accountant-abis.cjs +1 -1
  24. package/dist/contracts/abis/nucleus-accountant-abis.d.ts +2 -1
  25. package/dist/contracts/abis/nucleus-accountant-abis.js +1 -1
  26. package/dist/contracts/abis/nucleus-atomic-queue-abis.cjs +1 -1
  27. package/dist/contracts/abis/nucleus-atomic-queue-abis.d.ts +2 -1
  28. package/dist/contracts/abis/nucleus-atomic-queue-abis.js +1 -1
  29. package/dist/contracts/abis/nucleus-boring-vault-abis.cjs +1 -1
  30. package/dist/contracts/abis/nucleus-boring-vault-abis.d.ts +2 -1
  31. package/dist/contracts/abis/nucleus-boring-vault-abis.js +1 -1
  32. package/dist/contracts/abis/nucleus-teller-abis.cjs +1 -1
  33. package/dist/contracts/abis/nucleus-teller-abis.d.ts +2 -1
  34. package/dist/contracts/abis/nucleus-teller-abis.js +1 -1
  35. package/dist/contracts/abis/puf-locker-abis.cjs +1 -1
  36. package/dist/contracts/abis/puf-locker-abis.d.ts +484 -1
  37. package/dist/contracts/abis/puf-locker-abis.js +1 -1
  38. package/dist/contracts/abis/puffer-depositor-abis.cjs +1 -1
  39. package/dist/contracts/abis/puffer-depositor-abis.d.ts +663 -2
  40. package/dist/contracts/abis/puffer-depositor-abis.js +1 -1
  41. package/dist/contracts/abis/puffer-vault-abis.cjs +1 -1
  42. package/dist/contracts/abis/puffer-vault-abis.d.ts +4 -2
  43. package/dist/contracts/abis/puffer-vault-abis.js +1 -1
  44. package/dist/contracts/abis/puffer-withdrawal-manager-abis.cjs +1 -1
  45. package/dist/contracts/abis/puffer-withdrawal-manager-abis.d.ts +514 -1
  46. package/dist/contracts/abis/puffer-withdrawal-manager-abis.js +1 -1
  47. package/dist/contracts/addresses.cjs +1 -1
  48. package/dist/contracts/addresses.d.ts +6 -15
  49. package/dist/contracts/addresses.js +1 -1
  50. package/dist/contracts/handlers/carrot-staking-handler.cjs +1 -1
  51. package/dist/contracts/handlers/carrot-staking-handler.js +2 -2
  52. package/dist/contracts/handlers/distributor-handler.cjs +1 -1
  53. package/dist/contracts/handlers/distributor-handler.js +2 -2
  54. package/dist/contracts/handlers/erc20-permit-handler.cjs +1 -1
  55. package/dist/contracts/handlers/erc20-permit-handler.cjs.map +1 -1
  56. package/dist/contracts/handlers/erc20-permit-handler.d.ts +17101 -14898
  57. package/dist/contracts/handlers/erc20-permit-handler.js +3 -3
  58. package/dist/contracts/handlers/erc20-permit-handler.js.map +1 -1
  59. package/dist/contracts/handlers/l1-reward-manager-handler.cjs +1 -1
  60. package/dist/contracts/handlers/l1-reward-manager-handler.js +2 -2
  61. package/dist/contracts/handlers/l2-reward-manager-handler.cjs +1 -1
  62. package/dist/contracts/handlers/l2-reward-manager-handler.js +2 -2
  63. package/dist/contracts/handlers/mtw-carrot-handler.cjs +1 -1
  64. package/dist/contracts/handlers/mtw-carrot-handler.js +2 -2
  65. package/dist/contracts/handlers/nucleus-accountant-handler.cjs +1 -1
  66. package/dist/contracts/handlers/nucleus-accountant-handler.js +1 -1
  67. package/dist/contracts/handlers/nucleus-atomic-queue-handler.cjs +1 -1
  68. package/dist/contracts/handlers/nucleus-atomic-queue-handler.cjs.map +1 -1
  69. package/dist/contracts/handlers/nucleus-atomic-queue-handler.d.ts +7619 -14812
  70. package/dist/contracts/handlers/nucleus-atomic-queue-handler.js +2 -2
  71. package/dist/contracts/handlers/nucleus-atomic-queue-handler.js.map +1 -1
  72. package/dist/contracts/handlers/nucleus-boring-vault-handler.cjs +1 -1
  73. package/dist/contracts/handlers/nucleus-boring-vault-handler.js +2 -2
  74. package/dist/contracts/handlers/nucleus-teller-handler.cjs +1 -1
  75. package/dist/contracts/handlers/nucleus-teller-handler.js +2 -2
  76. package/dist/contracts/handlers/puf-locker-handler.cjs +1 -1
  77. package/dist/contracts/handlers/puf-locker-handler.cjs.map +1 -1
  78. package/dist/contracts/handlers/puf-locker-handler.js +2 -2
  79. package/dist/contracts/handlers/puf-locker-handler.js.map +1 -1
  80. package/dist/contracts/handlers/puffer-depositor-handler.cjs +1 -1
  81. package/dist/contracts/handlers/puffer-depositor-handler.d.ts +11215 -14794
  82. package/dist/contracts/handlers/puffer-depositor-handler.js +2 -2
  83. package/dist/contracts/handlers/puffer-l2-depositor-handler.cjs +1 -1
  84. package/dist/contracts/handlers/puffer-l2-depositor-handler.js +2 -2
  85. package/dist/contracts/handlers/puffer-vault-handler.cjs +1 -1
  86. package/dist/contracts/handlers/puffer-vault-handler.js +2 -2
  87. package/dist/contracts/handlers/puffer-withdrawal-manager-handler.cjs +1 -1
  88. package/dist/contracts/handlers/puffer-withdrawal-manager-handler.js +2 -2
  89. package/dist/contracts/tokens.cjs +1 -1
  90. package/dist/contracts/tokens.js +1 -1
  91. package/dist/contracts/vaults-addresses.cjs +1 -1
  92. package/dist/contracts/vaults-addresses.d.ts +5 -4
  93. package/dist/contracts/vaults-addresses.js +1 -1
  94. package/dist/createWalletClient-DNLhBkOd.js +3289 -0
  95. package/dist/createWalletClient-DNLhBkOd.js.map +1 -0
  96. package/dist/createWalletClient-Di5of07E.cjs +6 -0
  97. package/dist/createWalletClient-Di5of07E.cjs.map +1 -0
  98. package/dist/{getContract-CezEyDf-.js → getContract-6ajhFbP2.js} +2 -2
  99. package/dist/getContract-6ajhFbP2.js.map +1 -0
  100. package/dist/{getContract-3QbyfZBF.cjs → getContract-ChPFzc5y.cjs} +2 -2
  101. package/dist/{getContract-CezEyDf-.js.map → getContract-ChPFzc5y.cjs.map} +1 -1
  102. package/dist/main.cjs +1 -1
  103. package/dist/main.js +1 -1
  104. package/dist/secp256k1-B8plqpXf.cjs +2 -0
  105. package/dist/secp256k1-B8plqpXf.cjs.map +1 -0
  106. package/dist/secp256k1-Ev0s9Yr6.js +1340 -0
  107. package/dist/secp256k1-Ev0s9Yr6.js.map +1 -0
  108. package/dist/utils/version.cjs +1 -1
  109. package/dist/utils/version.js +1 -1
  110. package/dist/writeContract-BatuNuTe.cjs +32 -0
  111. package/dist/writeContract-BatuNuTe.cjs.map +1 -0
  112. package/dist/{writeContract-ChuHpJLC.js → writeContract-CjcOEtWX.js} +822 -763
  113. package/dist/writeContract-CjcOEtWX.js.map +1 -0
  114. package/package.json +15 -15
  115. package/dist/ccip-BO_b9tFc.cjs.map +0 -1
  116. package/dist/ccip-DLDO0_x2.js.map +0 -1
  117. package/dist/constants-BjRNQpT2.js.map +0 -1
  118. package/dist/constants-DA2xUb9r.cjs +0 -9
  119. package/dist/constants-DA2xUb9r.cjs.map +0 -1
  120. package/dist/contracts/handlers/carrot-staking-handler.d.ts +0 -15063
  121. package/dist/contracts/handlers/distributor-handler.d.ts +0 -15369
  122. package/dist/contracts/handlers/l1-reward-manager-handler.d.ts +0 -15107
  123. package/dist/contracts/handlers/l2-reward-manager-handler.d.ts +0 -15353
  124. package/dist/contracts/handlers/mtw-carrot-handler.d.ts +0 -15293
  125. package/dist/contracts/handlers/nucleus-accountant-handler.d.ts +0 -15126
  126. package/dist/contracts/handlers/nucleus-boring-vault-handler.d.ts +0 -15284
  127. package/dist/contracts/handlers/nucleus-teller-handler.d.ts +0 -15201
  128. package/dist/contracts/handlers/puf-locker-handler.d.ts +0 -15116
  129. package/dist/contracts/handlers/puffer-l2-depositor-handler.d.ts +0 -14969
  130. package/dist/contracts/handlers/puffer-vault-handler.d.ts +0 -17452
  131. package/dist/contracts/handlers/puffer-withdrawal-manager-handler.d.ts +0 -15111
  132. package/dist/createWalletClient-BuLYysrp.cjs +0 -4
  133. package/dist/createWalletClient-BuLYysrp.cjs.map +0 -1
  134. package/dist/createWalletClient-DNcW-ENe.js +0 -2028
  135. package/dist/createWalletClient-DNcW-ENe.js.map +0 -1
  136. package/dist/getContract-3QbyfZBF.cjs.map +0 -1
  137. package/dist/secp256k1-3OC5y4qp.js +0 -1579
  138. package/dist/secp256k1-3OC5y4qp.js.map +0 -1
  139. package/dist/secp256k1-bcahnPX9.cjs +0 -2
  140. package/dist/secp256k1-bcahnPX9.cjs.map +0 -1
  141. package/dist/writeContract-ChuHpJLC.js.map +0 -1
  142. package/dist/writeContract-D97dSJQe.cjs +0 -32
  143. package/dist/writeContract-D97dSJQe.cjs.map +0 -1
@@ -1,1579 +0,0 @@
1
- function Pt(e) {
2
- if (!Number.isSafeInteger(e) || e < 0)
3
- throw new Error("positive integer expected, got " + e);
4
- }
5
- function we(e) {
6
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
7
- }
8
- function vt(e, ...n) {
9
- if (!we(e))
10
- throw new Error("Uint8Array expected");
11
- if (n.length > 0 && !n.includes(e.length))
12
- throw new Error("Uint8Array expected of length " + n + ", got length=" + e.length);
13
- }
14
- function pe(e) {
15
- if (typeof e != "function" || typeof e.create != "function")
16
- throw new Error("Hash should be wrapped by utils.wrapConstructor");
17
- Pt(e.outputLen), Pt(e.blockLen);
18
- }
19
- function Bt(e, n = !0) {
20
- if (e.destroyed)
21
- throw new Error("Hash instance has been destroyed");
22
- if (n && e.finished)
23
- throw new Error("Hash#digest() has already been called");
24
- }
25
- function ye(e, n) {
26
- vt(e);
27
- const t = n.outputLen;
28
- if (e.length < t)
29
- throw new Error("digestInto() expects output buffer of length at least " + t);
30
- }
31
- const at = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
32
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
33
- const Ot = (e) => new DataView(e.buffer, e.byteOffset, e.byteLength), P = (e, n) => e << 32 - n | e >>> n;
34
- function be(e) {
35
- if (typeof e != "string")
36
- throw new Error("utf8ToBytes expected string, got " + typeof e);
37
- return new Uint8Array(new TextEncoder().encode(e));
38
- }
39
- function Mt(e) {
40
- return typeof e == "string" && (e = be(e)), vt(e), e;
41
- }
42
- function me(...e) {
43
- let n = 0;
44
- for (let r = 0; r < e.length; r++) {
45
- const o = e[r];
46
- vt(o), n += o.length;
47
- }
48
- const t = new Uint8Array(n);
49
- for (let r = 0, o = 0; r < e.length; r++) {
50
- const i = e[r];
51
- t.set(i, o), o += i.length;
52
- }
53
- return t;
54
- }
55
- class ne {
56
- // Safe version that clones internal state
57
- clone() {
58
- return this._cloneInto();
59
- }
60
- }
61
- function xe(e) {
62
- const n = (r) => e().update(Mt(r)).digest(), t = e();
63
- return n.outputLen = t.outputLen, n.blockLen = t.blockLen, n.create = () => e(), n;
64
- }
65
- function Ee(e = 32) {
66
- if (at && typeof at.getRandomValues == "function")
67
- return at.getRandomValues(new Uint8Array(e));
68
- if (at && typeof at.randomBytes == "function")
69
- return at.randomBytes(e);
70
- throw new Error("crypto.getRandomValues must be defined");
71
- }
72
- function Be(e, n, t, r) {
73
- if (typeof e.setBigUint64 == "function")
74
- return e.setBigUint64(n, t, r);
75
- const o = BigInt(32), i = BigInt(4294967295), c = Number(t >> o & i), f = Number(t & i), s = r ? 4 : 0, u = r ? 0 : 4;
76
- e.setUint32(n + s, c, r), e.setUint32(n + u, f, r);
77
- }
78
- const ve = (e, n, t) => e & n ^ ~e & t, Se = (e, n, t) => e & n ^ e & t ^ n & t;
79
- class Ae extends ne {
80
- constructor(n, t, r, o) {
81
- super(), this.blockLen = n, this.outputLen = t, this.padOffset = r, this.isLE = o, this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.buffer = new Uint8Array(n), this.view = Ot(this.buffer);
82
- }
83
- update(n) {
84
- Bt(this);
85
- const { view: t, buffer: r, blockLen: o } = this;
86
- n = Mt(n);
87
- const i = n.length;
88
- for (let c = 0; c < i; ) {
89
- const f = Math.min(o - this.pos, i - c);
90
- if (f === o) {
91
- const s = Ot(n);
92
- for (; o <= i - c; c += o)
93
- this.process(s, c);
94
- continue;
95
- }
96
- r.set(n.subarray(c, c + f), this.pos), this.pos += f, c += f, this.pos === o && (this.process(t, 0), this.pos = 0);
97
- }
98
- return this.length += n.length, this.roundClean(), this;
99
- }
100
- digestInto(n) {
101
- Bt(this), ye(n, this), this.finished = !0;
102
- const { buffer: t, view: r, blockLen: o, isLE: i } = this;
103
- let { pos: c } = this;
104
- t[c++] = 128, this.buffer.subarray(c).fill(0), this.padOffset > o - c && (this.process(r, 0), c = 0);
105
- for (let h = c; h < o; h++)
106
- t[h] = 0;
107
- Be(r, o - 8, BigInt(this.length * 8), i), this.process(r, 0);
108
- const f = Ot(n), s = this.outputLen;
109
- if (s % 4)
110
- throw new Error("_sha2: outputLen should be aligned to 32bit");
111
- const u = s / 4, b = this.get();
112
- if (u > b.length)
113
- throw new Error("_sha2: outputLen bigger than state");
114
- for (let h = 0; h < u; h++)
115
- f.setUint32(4 * h, b[h], i);
116
- }
117
- digest() {
118
- const { buffer: n, outputLen: t } = this;
119
- this.digestInto(n);
120
- const r = n.slice(0, t);
121
- return this.destroy(), r;
122
- }
123
- _cloneInto(n) {
124
- n || (n = new this.constructor()), n.set(...this.get());
125
- const { blockLen: t, buffer: r, length: o, finished: i, destroyed: c, pos: f } = this;
126
- return n.length = o, n.pos = f, n.finished = i, n.destroyed = c, o % t && n.buffer.set(r), n;
127
- }
128
- }
129
- const Ie = /* @__PURE__ */ new Uint32Array([
130
- 1116352408,
131
- 1899447441,
132
- 3049323471,
133
- 3921009573,
134
- 961987163,
135
- 1508970993,
136
- 2453635748,
137
- 2870763221,
138
- 3624381080,
139
- 310598401,
140
- 607225278,
141
- 1426881987,
142
- 1925078388,
143
- 2162078206,
144
- 2614888103,
145
- 3248222580,
146
- 3835390401,
147
- 4022224774,
148
- 264347078,
149
- 604807628,
150
- 770255983,
151
- 1249150122,
152
- 1555081692,
153
- 1996064986,
154
- 2554220882,
155
- 2821834349,
156
- 2952996808,
157
- 3210313671,
158
- 3336571891,
159
- 3584528711,
160
- 113926993,
161
- 338241895,
162
- 666307205,
163
- 773529912,
164
- 1294757372,
165
- 1396182291,
166
- 1695183700,
167
- 1986661051,
168
- 2177026350,
169
- 2456956037,
170
- 2730485921,
171
- 2820302411,
172
- 3259730800,
173
- 3345764771,
174
- 3516065817,
175
- 3600352804,
176
- 4094571909,
177
- 275423344,
178
- 430227734,
179
- 506948616,
180
- 659060556,
181
- 883997877,
182
- 958139571,
183
- 1322822218,
184
- 1537002063,
185
- 1747873779,
186
- 1955562222,
187
- 2024104815,
188
- 2227730452,
189
- 2361852424,
190
- 2428436474,
191
- 2756734187,
192
- 3204031479,
193
- 3329325298
194
- ]), Q = /* @__PURE__ */ new Uint32Array([
195
- 1779033703,
196
- 3144134277,
197
- 1013904242,
198
- 2773480762,
199
- 1359893119,
200
- 2600822924,
201
- 528734635,
202
- 1541459225
203
- ]), J = /* @__PURE__ */ new Uint32Array(64);
204
- class Ne extends Ae {
205
- constructor() {
206
- super(64, 32, 8, !1), this.A = Q[0] | 0, this.B = Q[1] | 0, this.C = Q[2] | 0, this.D = Q[3] | 0, this.E = Q[4] | 0, this.F = Q[5] | 0, this.G = Q[6] | 0, this.H = Q[7] | 0;
207
- }
208
- get() {
209
- const { A: n, B: t, C: r, D: o, E: i, F: c, G: f, H: s } = this;
210
- return [n, t, r, o, i, c, f, s];
211
- }
212
- // prettier-ignore
213
- set(n, t, r, o, i, c, f, s) {
214
- this.A = n | 0, this.B = t | 0, this.C = r | 0, this.D = o | 0, this.E = i | 0, this.F = c | 0, this.G = f | 0, this.H = s | 0;
215
- }
216
- process(n, t) {
217
- for (let h = 0; h < 16; h++, t += 4)
218
- J[h] = n.getUint32(t, !1);
219
- for (let h = 16; h < 64; h++) {
220
- const l = J[h - 15], m = J[h - 2], N = P(l, 7) ^ P(l, 18) ^ l >>> 3, y = P(m, 17) ^ P(m, 19) ^ m >>> 10;
221
- J[h] = y + J[h - 7] + N + J[h - 16] | 0;
222
- }
223
- let { A: r, B: o, C: i, D: c, E: f, F: s, G: u, H: b } = this;
224
- for (let h = 0; h < 64; h++) {
225
- const l = P(f, 6) ^ P(f, 11) ^ P(f, 25), m = b + l + ve(f, s, u) + Ie[h] + J[h] | 0, y = (P(r, 2) ^ P(r, 13) ^ P(r, 22)) + Se(r, o, i) | 0;
226
- b = u, u = s, s = f, f = c + m | 0, c = i, i = o, o = r, r = m + y | 0;
227
- }
228
- r = r + this.A | 0, o = o + this.B | 0, i = i + this.C | 0, c = c + this.D | 0, f = f + this.E | 0, s = s + this.F | 0, u = u + this.G | 0, b = b + this.H | 0, this.set(r, o, i, c, f, s, u, b);
229
- }
230
- roundClean() {
231
- J.fill(0);
232
- }
233
- destroy() {
234
- this.set(0, 0, 0, 0, 0, 0, 0, 0), this.buffer.fill(0);
235
- }
236
- }
237
- const qe = /* @__PURE__ */ xe(() => new Ne());
238
- class re extends ne {
239
- constructor(n, t) {
240
- super(), this.finished = !1, this.destroyed = !1, pe(n);
241
- const r = Mt(t);
242
- if (this.iHash = n.create(), typeof this.iHash.update != "function")
243
- throw new Error("Expected instance of class which extends utils.Hash");
244
- this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
245
- const o = this.blockLen, i = new Uint8Array(o);
246
- i.set(r.length > o ? n.create().update(r).digest() : r);
247
- for (let c = 0; c < i.length; c++)
248
- i[c] ^= 54;
249
- this.iHash.update(i), this.oHash = n.create();
250
- for (let c = 0; c < i.length; c++)
251
- i[c] ^= 106;
252
- this.oHash.update(i), i.fill(0);
253
- }
254
- update(n) {
255
- return Bt(this), this.iHash.update(n), this;
256
- }
257
- digestInto(n) {
258
- Bt(this), vt(n, this.outputLen), this.finished = !0, this.iHash.digestInto(n), this.oHash.update(n), this.oHash.digestInto(n), this.destroy();
259
- }
260
- digest() {
261
- const n = new Uint8Array(this.oHash.outputLen);
262
- return this.digestInto(n), n;
263
- }
264
- _cloneInto(n) {
265
- n || (n = Object.create(Object.getPrototypeOf(this), {}));
266
- const { oHash: t, iHash: r, finished: o, destroyed: i, blockLen: c, outputLen: f } = this;
267
- return n = n, n.finished = o, n.destroyed = i, n.blockLen = c, n.outputLen = f, n.oHash = t._cloneInto(n.oHash), n.iHash = r._cloneInto(n.iHash), n;
268
- }
269
- destroy() {
270
- this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
271
- }
272
- }
273
- const oe = (e, n, t) => new re(e, n).update(t).digest();
274
- oe.create = (e, n) => new re(e, n);
275
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
276
- const St = /* @__PURE__ */ BigInt(0), At = /* @__PURE__ */ BigInt(1), Oe = /* @__PURE__ */ BigInt(2);
277
- function it(e) {
278
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
279
- }
280
- function mt(e) {
281
- if (!it(e))
282
- throw new Error("Uint8Array expected");
283
- }
284
- function lt(e, n) {
285
- if (typeof n != "boolean")
286
- throw new Error(e + " boolean expected, got " + n);
287
- }
288
- const Le = /* @__PURE__ */ Array.from({ length: 256 }, (e, n) => n.toString(16).padStart(2, "0"));
289
- function dt(e) {
290
- mt(e);
291
- let n = "";
292
- for (let t = 0; t < e.length; t++)
293
- n += Le[e[t]];
294
- return n;
295
- }
296
- function ut(e) {
297
- const n = e.toString(16);
298
- return n.length & 1 ? "0" + n : n;
299
- }
300
- function jt(e) {
301
- if (typeof e != "string")
302
- throw new Error("hex string expected, got " + typeof e);
303
- return e === "" ? St : BigInt("0x" + e);
304
- }
305
- const $ = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
306
- function Gt(e) {
307
- if (e >= $._0 && e <= $._9)
308
- return e - $._0;
309
- if (e >= $.A && e <= $.F)
310
- return e - ($.A - 10);
311
- if (e >= $.a && e <= $.f)
312
- return e - ($.a - 10);
313
- }
314
- function ht(e) {
315
- if (typeof e != "string")
316
- throw new Error("hex string expected, got " + typeof e);
317
- const n = e.length, t = n / 2;
318
- if (n % 2)
319
- throw new Error("hex string expected, got unpadded hex of length " + n);
320
- const r = new Uint8Array(t);
321
- for (let o = 0, i = 0; o < t; o++, i += 2) {
322
- const c = Gt(e.charCodeAt(i)), f = Gt(e.charCodeAt(i + 1));
323
- if (c === void 0 || f === void 0) {
324
- const s = e[i] + e[i + 1];
325
- throw new Error('hex string expected, got non-hex character "' + s + '" at index ' + i);
326
- }
327
- r[o] = c * 16 + f;
328
- }
329
- return r;
330
- }
331
- function rt(e) {
332
- return jt(dt(e));
333
- }
334
- function Yt(e) {
335
- return mt(e), jt(dt(Uint8Array.from(e).reverse()));
336
- }
337
- function gt(e, n) {
338
- return ht(e.toString(16).padStart(n * 2, "0"));
339
- }
340
- function Ft(e, n) {
341
- return gt(e, n).reverse();
342
- }
343
- function He(e) {
344
- return ht(ut(e));
345
- }
346
- function K(e, n, t) {
347
- let r;
348
- if (typeof n == "string")
349
- try {
350
- r = ht(n);
351
- } catch (i) {
352
- throw new Error(e + " must be hex string or Uint8Array, cause: " + i);
353
- }
354
- else if (it(n))
355
- r = Uint8Array.from(n);
356
- else
357
- throw new Error(e + " must be hex string or Uint8Array");
358
- const o = r.length;
359
- if (typeof t == "number" && o !== t)
360
- throw new Error(e + " of length " + t + " expected, got " + o);
361
- return r;
362
- }
363
- function bt(...e) {
364
- let n = 0;
365
- for (let r = 0; r < e.length; r++) {
366
- const o = e[r];
367
- mt(o), n += o.length;
368
- }
369
- const t = new Uint8Array(n);
370
- for (let r = 0, o = 0; r < e.length; r++) {
371
- const i = e[r];
372
- t.set(i, o), o += i.length;
373
- }
374
- return t;
375
- }
376
- function Ue(e, n) {
377
- if (e.length !== n.length)
378
- return !1;
379
- let t = 0;
380
- for (let r = 0; r < e.length; r++)
381
- t |= e[r] ^ n[r];
382
- return t === 0;
383
- }
384
- function Te(e) {
385
- if (typeof e != "string")
386
- throw new Error("string expected");
387
- return new Uint8Array(new TextEncoder().encode(e));
388
- }
389
- const Lt = (e) => typeof e == "bigint" && St <= e;
390
- function It(e, n, t) {
391
- return Lt(e) && Lt(n) && Lt(t) && n <= e && e < t;
392
- }
393
- function ot(e, n, t, r) {
394
- if (!It(n, t, r))
395
- throw new Error("expected valid " + e + ": " + t + " <= n < " + r + ", got " + n);
396
- }
397
- function ie(e) {
398
- let n;
399
- for (n = 0; e > St; e >>= At, n += 1)
400
- ;
401
- return n;
402
- }
403
- function _e(e, n) {
404
- return e >> BigInt(n) & At;
405
- }
406
- function ke(e, n, t) {
407
- return e | (t ? At : St) << BigInt(n);
408
- }
409
- const Kt = (e) => (Oe << BigInt(e - 1)) - At, Ht = (e) => new Uint8Array(e), $t = (e) => Uint8Array.from(e);
410
- function se(e, n, t) {
411
- if (typeof e != "number" || e < 2)
412
- throw new Error("hashLen must be a number");
413
- if (typeof n != "number" || n < 2)
414
- throw new Error("qByteLen must be a number");
415
- if (typeof t != "function")
416
- throw new Error("hmacFn must be a function");
417
- let r = Ht(e), o = Ht(e), i = 0;
418
- const c = () => {
419
- r.fill(1), o.fill(0), i = 0;
420
- }, f = (...h) => t(o, r, ...h), s = (h = Ht()) => {
421
- o = f($t([0]), h), r = f(), h.length !== 0 && (o = f($t([1]), h), r = f());
422
- }, u = () => {
423
- if (i++ >= 1e3)
424
- throw new Error("drbg: tried 1000 values");
425
- let h = 0;
426
- const l = [];
427
- for (; h < n; ) {
428
- r = f();
429
- const m = r.slice();
430
- l.push(m), h += r.length;
431
- }
432
- return bt(...l);
433
- };
434
- return (h, l) => {
435
- c(), s(h);
436
- let m;
437
- for (; !(m = l(u())); )
438
- s();
439
- return c(), m;
440
- };
441
- }
442
- const ze = {
443
- bigint: (e) => typeof e == "bigint",
444
- function: (e) => typeof e == "function",
445
- boolean: (e) => typeof e == "boolean",
446
- string: (e) => typeof e == "string",
447
- stringOrUint8Array: (e) => typeof e == "string" || it(e),
448
- isSafeInteger: (e) => Number.isSafeInteger(e),
449
- array: (e) => Array.isArray(e),
450
- field: (e, n) => n.Fp.isValid(e),
451
- hash: (e) => typeof e == "function" && Number.isSafeInteger(e.outputLen)
452
- };
453
- function xt(e, n, t = {}) {
454
- const r = (o, i, c) => {
455
- const f = ze[i];
456
- if (typeof f != "function")
457
- throw new Error("invalid validator function");
458
- const s = e[o];
459
- if (!(c && s === void 0) && !f(s, e))
460
- throw new Error("param " + String(o) + " is invalid. Expected " + i + ", got " + s);
461
- };
462
- for (const [o, i] of Object.entries(n))
463
- r(o, i, !1);
464
- for (const [o, i] of Object.entries(t))
465
- r(o, i, !0);
466
- return e;
467
- }
468
- const Ce = () => {
469
- throw new Error("not implemented");
470
- };
471
- function zt(e) {
472
- const n = /* @__PURE__ */ new WeakMap();
473
- return (t, ...r) => {
474
- const o = n.get(t);
475
- if (o !== void 0)
476
- return o;
477
- const i = e(t, ...r);
478
- return n.set(t, i), i;
479
- };
480
- }
481
- const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
482
- __proto__: null,
483
- aInRange: ot,
484
- abool: lt,
485
- abytes: mt,
486
- bitGet: _e,
487
- bitLen: ie,
488
- bitMask: Kt,
489
- bitSet: ke,
490
- bytesToHex: dt,
491
- bytesToNumberBE: rt,
492
- bytesToNumberLE: Yt,
493
- concatBytes: bt,
494
- createHmacDrbg: se,
495
- ensureBytes: K,
496
- equalBytes: Ue,
497
- hexToBytes: ht,
498
- hexToNumber: jt,
499
- inRange: It,
500
- isBytes: it,
501
- memoized: zt,
502
- notImplemented: Ce,
503
- numberToBytesBE: gt,
504
- numberToBytesLE: Ft,
505
- numberToHexUnpadded: ut,
506
- numberToVarBytesBE: He,
507
- utf8ToBytes: Te,
508
- validateObject: xt
509
- }, Symbol.toStringTag, { value: "Module" }));
510
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
511
- const z = BigInt(0), T = BigInt(1), nt = /* @__PURE__ */ BigInt(2), Ze = /* @__PURE__ */ BigInt(3), Ct = /* @__PURE__ */ BigInt(4), Dt = /* @__PURE__ */ BigInt(5), Wt = /* @__PURE__ */ BigInt(8);
512
- function M(e, n) {
513
- const t = e % n;
514
- return t >= z ? t : n + t;
515
- }
516
- function Ve(e, n, t) {
517
- if (n < z)
518
- throw new Error("invalid exponent, negatives unsupported");
519
- if (t <= z)
520
- throw new Error("invalid modulus");
521
- if (t === T)
522
- return z;
523
- let r = T;
524
- for (; n > z; )
525
- n & T && (r = r * e % t), e = e * e % t, n >>= T;
526
- return r;
527
- }
528
- function Y(e, n, t) {
529
- let r = e;
530
- for (; n-- > z; )
531
- r *= r, r %= t;
532
- return r;
533
- }
534
- function Rt(e, n) {
535
- if (e === z)
536
- throw new Error("invert: expected non-zero number");
537
- if (n <= z)
538
- throw new Error("invert: expected positive modulus, got " + n);
539
- let t = M(e, n), r = n, o = z, i = T;
540
- for (; t !== z; ) {
541
- const f = r / t, s = r % t, u = o - i * f;
542
- r = t, t = s, o = i, i = u;
543
- }
544
- if (r !== T)
545
- throw new Error("invert: does not exist");
546
- return M(o, n);
547
- }
548
- function Me(e) {
549
- const n = (e - T) / nt;
550
- let t, r, o;
551
- for (t = e - T, r = 0; t % nt === z; t /= nt, r++)
552
- ;
553
- for (o = nt; o < e && Ve(o, n, e) !== e - T; o++)
554
- if (o > 1e3)
555
- throw new Error("Cannot find square root: likely non-prime P");
556
- if (r === 1) {
557
- const c = (e + T) / Ct;
558
- return function(s, u) {
559
- const b = s.pow(u, c);
560
- if (!s.eql(s.sqr(b), u))
561
- throw new Error("Cannot find square root");
562
- return b;
563
- };
564
- }
565
- const i = (t + T) / nt;
566
- return function(f, s) {
567
- if (f.pow(s, n) === f.neg(f.ONE))
568
- throw new Error("Cannot find square root");
569
- let u = r, b = f.pow(f.mul(f.ONE, o), t), h = f.pow(s, i), l = f.pow(s, t);
570
- for (; !f.eql(l, f.ONE); ) {
571
- if (f.eql(l, f.ZERO))
572
- return f.ZERO;
573
- let m = 1;
574
- for (let y = f.sqr(l); m < u && !f.eql(y, f.ONE); m++)
575
- y = f.sqr(y);
576
- const N = f.pow(b, T << BigInt(u - m - 1));
577
- b = f.sqr(N), h = f.mul(h, N), l = f.mul(l, b), u = m;
578
- }
579
- return h;
580
- };
581
- }
582
- function je(e) {
583
- if (e % Ct === Ze) {
584
- const n = (e + T) / Ct;
585
- return function(r, o) {
586
- const i = r.pow(o, n);
587
- if (!r.eql(r.sqr(i), o))
588
- throw new Error("Cannot find square root");
589
- return i;
590
- };
591
- }
592
- if (e % Wt === Dt) {
593
- const n = (e - Dt) / Wt;
594
- return function(r, o) {
595
- const i = r.mul(o, nt), c = r.pow(i, n), f = r.mul(o, c), s = r.mul(r.mul(f, nt), c), u = r.mul(f, r.sub(s, r.ONE));
596
- if (!r.eql(r.sqr(u), o))
597
- throw new Error("Cannot find square root");
598
- return u;
599
- };
600
- }
601
- return Me(e);
602
- }
603
- const Ye = [
604
- "create",
605
- "isValid",
606
- "is0",
607
- "neg",
608
- "inv",
609
- "sqrt",
610
- "sqr",
611
- "eql",
612
- "add",
613
- "sub",
614
- "mul",
615
- "pow",
616
- "div",
617
- "addN",
618
- "subN",
619
- "mulN",
620
- "sqrN"
621
- ];
622
- function Fe(e) {
623
- const n = {
624
- ORDER: "bigint",
625
- MASK: "bigint",
626
- BYTES: "isSafeInteger",
627
- BITS: "isSafeInteger"
628
- }, t = Ye.reduce((r, o) => (r[o] = "function", r), n);
629
- return xt(e, t);
630
- }
631
- function Ke(e, n, t) {
632
- if (t < z)
633
- throw new Error("invalid exponent, negatives unsupported");
634
- if (t === z)
635
- return e.ONE;
636
- if (t === T)
637
- return n;
638
- let r = e.ONE, o = n;
639
- for (; t > z; )
640
- t & T && (r = e.mul(r, o)), o = e.sqr(o), t >>= T;
641
- return r;
642
- }
643
- function Pe(e, n) {
644
- const t = new Array(n.length), r = n.reduce((i, c, f) => e.is0(c) ? i : (t[f] = i, e.mul(i, c)), e.ONE), o = e.inv(r);
645
- return n.reduceRight((i, c, f) => e.is0(c) ? i : (t[f] = e.mul(i, t[f]), e.mul(i, c)), o), t;
646
- }
647
- function ce(e, n) {
648
- const t = n !== void 0 ? n : e.toString(2).length, r = Math.ceil(t / 8);
649
- return { nBitLength: t, nByteLength: r };
650
- }
651
- function fe(e, n, t = !1, r = {}) {
652
- if (e <= z)
653
- throw new Error("invalid field: expected ORDER > 0, got " + e);
654
- const { nBitLength: o, nByteLength: i } = ce(e, n);
655
- if (i > 2048)
656
- throw new Error("invalid field: expected ORDER of <= 2048 bytes");
657
- let c;
658
- const f = Object.freeze({
659
- ORDER: e,
660
- BITS: o,
661
- BYTES: i,
662
- MASK: Kt(o),
663
- ZERO: z,
664
- ONE: T,
665
- create: (s) => M(s, e),
666
- isValid: (s) => {
667
- if (typeof s != "bigint")
668
- throw new Error("invalid field element: expected bigint, got " + typeof s);
669
- return z <= s && s < e;
670
- },
671
- is0: (s) => s === z,
672
- isOdd: (s) => (s & T) === T,
673
- neg: (s) => M(-s, e),
674
- eql: (s, u) => s === u,
675
- sqr: (s) => M(s * s, e),
676
- add: (s, u) => M(s + u, e),
677
- sub: (s, u) => M(s - u, e),
678
- mul: (s, u) => M(s * u, e),
679
- pow: (s, u) => Ke(f, s, u),
680
- div: (s, u) => M(s * Rt(u, e), e),
681
- // Same as above, but doesn't normalize
682
- sqrN: (s) => s * s,
683
- addN: (s, u) => s + u,
684
- subN: (s, u) => s - u,
685
- mulN: (s, u) => s * u,
686
- inv: (s) => Rt(s, e),
687
- sqrt: r.sqrt || ((s) => (c || (c = je(e)), c(f, s))),
688
- invertBatch: (s) => Pe(f, s),
689
- // TODO: do we really need constant cmov?
690
- // We don't have const-time bigints anyway, so probably will be not very useful
691
- cmov: (s, u, b) => b ? u : s,
692
- toBytes: (s) => t ? Ft(s, i) : gt(s, i),
693
- fromBytes: (s) => {
694
- if (s.length !== i)
695
- throw new Error("Field.fromBytes: expected " + i + " bytes, got " + s.length);
696
- return t ? Yt(s) : rt(s);
697
- }
698
- });
699
- return Object.freeze(f);
700
- }
701
- function ae(e) {
702
- if (typeof e != "bigint")
703
- throw new Error("field order must be bigint");
704
- const n = e.toString(2).length;
705
- return Math.ceil(n / 8);
706
- }
707
- function ue(e) {
708
- const n = ae(e);
709
- return n + Math.ceil(n / 2);
710
- }
711
- function Ge(e, n, t = !1) {
712
- const r = e.length, o = ae(n), i = ue(n);
713
- if (r < 16 || r < i || r > 1024)
714
- throw new Error("expected " + i + "-1024 bytes of input, got " + r);
715
- const c = t ? rt(e) : Yt(e), f = M(c, n - T) + T;
716
- return t ? Ft(f, o) : gt(f, o);
717
- }
718
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
719
- const Xt = BigInt(0), Et = BigInt(1);
720
- function Ut(e, n) {
721
- const t = n.negate();
722
- return e ? t : n;
723
- }
724
- function le(e, n) {
725
- if (!Number.isSafeInteger(e) || e <= 0 || e > n)
726
- throw new Error("invalid window size, expected [1.." + n + "], got W=" + e);
727
- }
728
- function Tt(e, n) {
729
- le(e, n);
730
- const t = Math.ceil(n / e) + 1, r = 2 ** (e - 1);
731
- return { windows: t, windowSize: r };
732
- }
733
- function $e(e, n) {
734
- if (!Array.isArray(e))
735
- throw new Error("array expected");
736
- e.forEach((t, r) => {
737
- if (!(t instanceof n))
738
- throw new Error("invalid point at index " + r);
739
- });
740
- }
741
- function De(e, n) {
742
- if (!Array.isArray(e))
743
- throw new Error("array of scalars expected");
744
- e.forEach((t, r) => {
745
- if (!n.isValid(t))
746
- throw new Error("invalid scalar at index " + r);
747
- });
748
- }
749
- const _t = /* @__PURE__ */ new WeakMap(), de = /* @__PURE__ */ new WeakMap();
750
- function kt(e) {
751
- return de.get(e) || 1;
752
- }
753
- function We(e, n) {
754
- return {
755
- constTimeNegate: Ut,
756
- hasPrecomputes(t) {
757
- return kt(t) !== 1;
758
- },
759
- // non-const time multiplication ladder
760
- unsafeLadder(t, r, o = e.ZERO) {
761
- let i = t;
762
- for (; r > Xt; )
763
- r & Et && (o = o.add(i)), i = i.double(), r >>= Et;
764
- return o;
765
- },
766
- /**
767
- * Creates a wNAF precomputation window. Used for caching.
768
- * Default window size is set by `utils.precompute()` and is equal to 8.
769
- * Number of precomputed points depends on the curve size:
770
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
771
- * - 𝑊 is the window size
772
- * - 𝑛 is the bitlength of the curve order.
773
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
774
- * @param elm Point instance
775
- * @param W window size
776
- * @returns precomputed point tables flattened to a single array
777
- */
778
- precomputeWindow(t, r) {
779
- const { windows: o, windowSize: i } = Tt(r, n), c = [];
780
- let f = t, s = f;
781
- for (let u = 0; u < o; u++) {
782
- s = f, c.push(s);
783
- for (let b = 1; b < i; b++)
784
- s = s.add(f), c.push(s);
785
- f = s.double();
786
- }
787
- return c;
788
- },
789
- /**
790
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
791
- * @param W window size
792
- * @param precomputes precomputed tables
793
- * @param n scalar (we don't check here, but should be less than curve order)
794
- * @returns real and fake (for const-time) points
795
- */
796
- wNAF(t, r, o) {
797
- const { windows: i, windowSize: c } = Tt(t, n);
798
- let f = e.ZERO, s = e.BASE;
799
- const u = BigInt(2 ** t - 1), b = 2 ** t, h = BigInt(t);
800
- for (let l = 0; l < i; l++) {
801
- const m = l * c;
802
- let N = Number(o & u);
803
- o >>= h, N > c && (N -= b, o += Et);
804
- const y = m, a = m + Math.abs(N) - 1, g = l % 2 !== 0, x = N < 0;
805
- N === 0 ? s = s.add(Ut(g, r[y])) : f = f.add(Ut(x, r[a]));
806
- }
807
- return { p: f, f: s };
808
- },
809
- /**
810
- * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
811
- * @param W window size
812
- * @param precomputes precomputed tables
813
- * @param n scalar (we don't check here, but should be less than curve order)
814
- * @param acc accumulator point to add result of multiplication
815
- * @returns point
816
- */
817
- wNAFUnsafe(t, r, o, i = e.ZERO) {
818
- const { windows: c, windowSize: f } = Tt(t, n), s = BigInt(2 ** t - 1), u = 2 ** t, b = BigInt(t);
819
- for (let h = 0; h < c; h++) {
820
- const l = h * f;
821
- if (o === Xt)
822
- break;
823
- let m = Number(o & s);
824
- if (o >>= b, m > f && (m -= u, o += Et), m === 0)
825
- continue;
826
- let N = r[l + Math.abs(m) - 1];
827
- m < 0 && (N = N.negate()), i = i.add(N);
828
- }
829
- return i;
830
- },
831
- getPrecomputes(t, r, o) {
832
- let i = _t.get(r);
833
- return i || (i = this.precomputeWindow(r, t), t !== 1 && _t.set(r, o(i))), i;
834
- },
835
- wNAFCached(t, r, o) {
836
- const i = kt(t);
837
- return this.wNAF(i, this.getPrecomputes(i, t, o), r);
838
- },
839
- wNAFCachedUnsafe(t, r, o, i) {
840
- const c = kt(t);
841
- return c === 1 ? this.unsafeLadder(t, r, i) : this.wNAFUnsafe(c, this.getPrecomputes(c, t, o), r, i);
842
- },
843
- // We calculate precomputes for elliptic curve point multiplication
844
- // using windowed method. This specifies window size and
845
- // stores precomputed values. Usually only base point would be precomputed.
846
- setWindowSize(t, r) {
847
- le(r, n), de.set(t, r), _t.delete(t);
848
- }
849
- };
850
- }
851
- function Xe(e, n, t, r) {
852
- if ($e(t, e), De(r, n), t.length !== r.length)
853
- throw new Error("arrays of points and scalars must have equal length");
854
- const o = e.ZERO, i = ie(BigInt(t.length)), c = i > 12 ? i - 3 : i > 4 ? i - 2 : i ? 2 : 1, f = (1 << c) - 1, s = new Array(f + 1).fill(o), u = Math.floor((n.BITS - 1) / c) * c;
855
- let b = o;
856
- for (let h = u; h >= 0; h -= c) {
857
- s.fill(o);
858
- for (let m = 0; m < r.length; m++) {
859
- const N = r[m], y = Number(N >> BigInt(h) & BigInt(f));
860
- s[y] = s[y].add(t[m]);
861
- }
862
- let l = o;
863
- for (let m = s.length - 1, N = o; m > 0; m--)
864
- N = N.add(s[m]), l = l.add(N);
865
- if (b = b.add(l), h !== 0)
866
- for (let m = 0; m < c; m++)
867
- b = b.double();
868
- }
869
- return b;
870
- }
871
- function he(e) {
872
- return Fe(e.Fp), xt(e, {
873
- n: "bigint",
874
- h: "bigint",
875
- Gx: "field",
876
- Gy: "field"
877
- }, {
878
- nBitLength: "isSafeInteger",
879
- nByteLength: "isSafeInteger"
880
- }), Object.freeze({
881
- ...ce(e.n, e.nBitLength),
882
- ...e,
883
- p: e.Fp.ORDER
884
- });
885
- }
886
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
887
- function Qt(e) {
888
- e.lowS !== void 0 && lt("lowS", e.lowS), e.prehash !== void 0 && lt("prehash", e.prehash);
889
- }
890
- function Qe(e) {
891
- const n = he(e);
892
- xt(n, {
893
- a: "field",
894
- b: "field"
895
- }, {
896
- allowedPrivateKeyLengths: "array",
897
- wrapPrivateKey: "boolean",
898
- isTorsionFree: "function",
899
- clearCofactor: "function",
900
- allowInfinityPoint: "boolean",
901
- fromBytes: "function",
902
- toBytes: "function"
903
- });
904
- const { endo: t, Fp: r, a: o } = n;
905
- if (t) {
906
- if (!r.eql(o, r.ZERO))
907
- throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");
908
- if (typeof t != "object" || typeof t.beta != "bigint" || typeof t.splitScalar != "function")
909
- throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function");
910
- }
911
- return Object.freeze({ ...n });
912
- }
913
- const { bytesToNumberBE: Je, hexToBytes: tn } = Re, D = {
914
- // asn.1 DER encoding utils
915
- Err: class extends Error {
916
- constructor(n = "") {
917
- super(n);
918
- }
919
- },
920
- // Basic building block is TLV (Tag-Length-Value)
921
- _tlv: {
922
- encode: (e, n) => {
923
- const { Err: t } = D;
924
- if (e < 0 || e > 256)
925
- throw new t("tlv.encode: wrong tag");
926
- if (n.length & 1)
927
- throw new t("tlv.encode: unpadded data");
928
- const r = n.length / 2, o = ut(r);
929
- if (o.length / 2 & 128)
930
- throw new t("tlv.encode: long form length too big");
931
- const i = r > 127 ? ut(o.length / 2 | 128) : "";
932
- return ut(e) + i + o + n;
933
- },
934
- // v - value, l - left bytes (unparsed)
935
- decode(e, n) {
936
- const { Err: t } = D;
937
- let r = 0;
938
- if (e < 0 || e > 256)
939
- throw new t("tlv.encode: wrong tag");
940
- if (n.length < 2 || n[r++] !== e)
941
- throw new t("tlv.decode: wrong tlv");
942
- const o = n[r++], i = !!(o & 128);
943
- let c = 0;
944
- if (!i)
945
- c = o;
946
- else {
947
- const s = o & 127;
948
- if (!s)
949
- throw new t("tlv.decode(long): indefinite length not supported");
950
- if (s > 4)
951
- throw new t("tlv.decode(long): byte length is too big");
952
- const u = n.subarray(r, r + s);
953
- if (u.length !== s)
954
- throw new t("tlv.decode: length bytes not complete");
955
- if (u[0] === 0)
956
- throw new t("tlv.decode(long): zero leftmost byte");
957
- for (const b of u)
958
- c = c << 8 | b;
959
- if (r += s, c < 128)
960
- throw new t("tlv.decode(long): not minimal encoding");
961
- }
962
- const f = n.subarray(r, r + c);
963
- if (f.length !== c)
964
- throw new t("tlv.decode: wrong value length");
965
- return { v: f, l: n.subarray(r + c) };
966
- }
967
- },
968
- // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
969
- // since we always use positive integers here. It must always be empty:
970
- // - add zero byte if exists
971
- // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
972
- _int: {
973
- encode(e) {
974
- const { Err: n } = D;
975
- if (e < W)
976
- throw new n("integer: negative integers are not allowed");
977
- let t = ut(e);
978
- if (Number.parseInt(t[0], 16) & 8 && (t = "00" + t), t.length & 1)
979
- throw new n("unexpected DER parsing assertion: unpadded hex");
980
- return t;
981
- },
982
- decode(e) {
983
- const { Err: n } = D;
984
- if (e[0] & 128)
985
- throw new n("invalid signature integer: negative");
986
- if (e[0] === 0 && !(e[1] & 128))
987
- throw new n("invalid signature integer: unnecessary leading zero");
988
- return Je(e);
989
- }
990
- },
991
- toSig(e) {
992
- const { Err: n, _int: t, _tlv: r } = D, o = typeof e == "string" ? tn(e) : e;
993
- mt(o);
994
- const { v: i, l: c } = r.decode(48, o);
995
- if (c.length)
996
- throw new n("invalid signature: left bytes after parsing");
997
- const { v: f, l: s } = r.decode(2, i), { v: u, l: b } = r.decode(2, s);
998
- if (b.length)
999
- throw new n("invalid signature: left bytes after parsing");
1000
- return { r: t.decode(f), s: t.decode(u) };
1001
- },
1002
- hexFromSig(e) {
1003
- const { _tlv: n, _int: t } = D, r = n.encode(2, t.encode(e.r)), o = n.encode(2, t.encode(e.s)), i = r + o;
1004
- return n.encode(48, i);
1005
- }
1006
- }, W = BigInt(0), k = BigInt(1);
1007
- BigInt(2);
1008
- const Jt = BigInt(3);
1009
- BigInt(4);
1010
- function en(e) {
1011
- const n = Qe(e), { Fp: t } = n, r = fe(n.n, n.nBitLength), o = n.toBytes || ((y, a, g) => {
1012
- const x = a.toAffine();
1013
- return bt(Uint8Array.from([4]), t.toBytes(x.x), t.toBytes(x.y));
1014
- }), i = n.fromBytes || ((y) => {
1015
- const a = y.subarray(1), g = t.fromBytes(a.subarray(0, t.BYTES)), x = t.fromBytes(a.subarray(t.BYTES, 2 * t.BYTES));
1016
- return { x: g, y: x };
1017
- });
1018
- function c(y) {
1019
- const { a, b: g } = n, x = t.sqr(y), E = t.mul(x, y);
1020
- return t.add(t.add(E, t.mul(y, a)), g);
1021
- }
1022
- if (!t.eql(t.sqr(n.Gy), c(n.Gx)))
1023
- throw new Error("bad generator point: equation left != right");
1024
- function f(y) {
1025
- return It(y, k, n.n);
1026
- }
1027
- function s(y) {
1028
- const { allowedPrivateKeyLengths: a, nByteLength: g, wrapPrivateKey: x, n: E } = n;
1029
- if (a && typeof y != "bigint") {
1030
- if (it(y) && (y = dt(y)), typeof y != "string" || !a.includes(y.length))
1031
- throw new Error("invalid private key");
1032
- y = y.padStart(g * 2, "0");
1033
- }
1034
- let q;
1035
- try {
1036
- q = typeof y == "bigint" ? y : rt(K("private key", y, g));
1037
- } catch {
1038
- throw new Error("invalid private key, expected hex or " + g + " bytes, got " + typeof y);
1039
- }
1040
- return x && (q = M(q, E)), ot("private key", q, k, E), q;
1041
- }
1042
- function u(y) {
1043
- if (!(y instanceof l))
1044
- throw new Error("ProjectivePoint expected");
1045
- }
1046
- const b = zt((y, a) => {
1047
- const { px: g, py: x, pz: E } = y;
1048
- if (t.eql(E, t.ONE))
1049
- return { x: g, y: x };
1050
- const q = y.is0();
1051
- a == null && (a = q ? t.ONE : t.inv(E));
1052
- const L = t.mul(g, a), I = t.mul(x, a), B = t.mul(E, a);
1053
- if (q)
1054
- return { x: t.ZERO, y: t.ZERO };
1055
- if (!t.eql(B, t.ONE))
1056
- throw new Error("invZ was invalid");
1057
- return { x: L, y: I };
1058
- }), h = zt((y) => {
1059
- if (y.is0()) {
1060
- if (n.allowInfinityPoint && !t.is0(y.py))
1061
- return;
1062
- throw new Error("bad point: ZERO");
1063
- }
1064
- const { x: a, y: g } = y.toAffine();
1065
- if (!t.isValid(a) || !t.isValid(g))
1066
- throw new Error("bad point: x or y not FE");
1067
- const x = t.sqr(g), E = c(a);
1068
- if (!t.eql(x, E))
1069
- throw new Error("bad point: equation left != right");
1070
- if (!y.isTorsionFree())
1071
- throw new Error("bad point: not in prime-order subgroup");
1072
- return !0;
1073
- });
1074
- class l {
1075
- constructor(a, g, x) {
1076
- if (this.px = a, this.py = g, this.pz = x, a == null || !t.isValid(a))
1077
- throw new Error("x required");
1078
- if (g == null || !t.isValid(g))
1079
- throw new Error("y required");
1080
- if (x == null || !t.isValid(x))
1081
- throw new Error("z required");
1082
- Object.freeze(this);
1083
- }
1084
- // Does not validate if the point is on-curve.
1085
- // Use fromHex instead, or call assertValidity() later.
1086
- static fromAffine(a) {
1087
- const { x: g, y: x } = a || {};
1088
- if (!a || !t.isValid(g) || !t.isValid(x))
1089
- throw new Error("invalid affine point");
1090
- if (a instanceof l)
1091
- throw new Error("projective point not allowed");
1092
- const E = (q) => t.eql(q, t.ZERO);
1093
- return E(g) && E(x) ? l.ZERO : new l(g, x, t.ONE);
1094
- }
1095
- get x() {
1096
- return this.toAffine().x;
1097
- }
1098
- get y() {
1099
- return this.toAffine().y;
1100
- }
1101
- /**
1102
- * Takes a bunch of Projective Points but executes only one
1103
- * inversion on all of them. Inversion is very slow operation,
1104
- * so this improves performance massively.
1105
- * Optimization: converts a list of projective points to a list of identical points with Z=1.
1106
- */
1107
- static normalizeZ(a) {
1108
- const g = t.invertBatch(a.map((x) => x.pz));
1109
- return a.map((x, E) => x.toAffine(g[E])).map(l.fromAffine);
1110
- }
1111
- /**
1112
- * Converts hash string or Uint8Array to Point.
1113
- * @param hex short/long ECDSA hex
1114
- */
1115
- static fromHex(a) {
1116
- const g = l.fromAffine(i(K("pointHex", a)));
1117
- return g.assertValidity(), g;
1118
- }
1119
- // Multiplies generator point by privateKey.
1120
- static fromPrivateKey(a) {
1121
- return l.BASE.multiply(s(a));
1122
- }
1123
- // Multiscalar Multiplication
1124
- static msm(a, g) {
1125
- return Xe(l, r, a, g);
1126
- }
1127
- // "Private method", don't use it directly
1128
- _setWindowSize(a) {
1129
- N.setWindowSize(this, a);
1130
- }
1131
- // A point on curve is valid if it conforms to equation.
1132
- assertValidity() {
1133
- h(this);
1134
- }
1135
- hasEvenY() {
1136
- const { y: a } = this.toAffine();
1137
- if (t.isOdd)
1138
- return !t.isOdd(a);
1139
- throw new Error("Field doesn't support isOdd");
1140
- }
1141
- /**
1142
- * Compare one point to another.
1143
- */
1144
- equals(a) {
1145
- u(a);
1146
- const { px: g, py: x, pz: E } = this, { px: q, py: L, pz: I } = a, B = t.eql(t.mul(g, I), t.mul(q, E)), A = t.eql(t.mul(x, I), t.mul(L, E));
1147
- return B && A;
1148
- }
1149
- /**
1150
- * Flips point to one corresponding to (x, -y) in Affine coordinates.
1151
- */
1152
- negate() {
1153
- return new l(this.px, t.neg(this.py), this.pz);
1154
- }
1155
- // Renes-Costello-Batina exception-free doubling formula.
1156
- // There is 30% faster Jacobian formula, but it is not complete.
1157
- // https://eprint.iacr.org/2015/1060, algorithm 3
1158
- // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
1159
- double() {
1160
- const { a, b: g } = n, x = t.mul(g, Jt), { px: E, py: q, pz: L } = this;
1161
- let I = t.ZERO, B = t.ZERO, A = t.ZERO, v = t.mul(E, E), C = t.mul(q, q), U = t.mul(L, L), H = t.mul(E, q);
1162
- return H = t.add(H, H), A = t.mul(E, L), A = t.add(A, A), I = t.mul(a, A), B = t.mul(x, U), B = t.add(I, B), I = t.sub(C, B), B = t.add(C, B), B = t.mul(I, B), I = t.mul(H, I), A = t.mul(x, A), U = t.mul(a, U), H = t.sub(v, U), H = t.mul(a, H), H = t.add(H, A), A = t.add(v, v), v = t.add(A, v), v = t.add(v, U), v = t.mul(v, H), B = t.add(B, v), U = t.mul(q, L), U = t.add(U, U), v = t.mul(U, H), I = t.sub(I, v), A = t.mul(U, C), A = t.add(A, A), A = t.add(A, A), new l(I, B, A);
1163
- }
1164
- // Renes-Costello-Batina exception-free addition formula.
1165
- // There is 30% faster Jacobian formula, but it is not complete.
1166
- // https://eprint.iacr.org/2015/1060, algorithm 1
1167
- // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
1168
- add(a) {
1169
- u(a);
1170
- const { px: g, py: x, pz: E } = this, { px: q, py: L, pz: I } = a;
1171
- let B = t.ZERO, A = t.ZERO, v = t.ZERO;
1172
- const C = n.a, U = t.mul(n.b, Jt);
1173
- let H = t.mul(g, q), j = t.mul(x, L), d = t.mul(E, I), w = t.add(g, x), p = t.add(q, L);
1174
- w = t.mul(w, p), p = t.add(H, j), w = t.sub(w, p), p = t.add(g, E);
1175
- let S = t.add(q, I);
1176
- return p = t.mul(p, S), S = t.add(H, d), p = t.sub(p, S), S = t.add(x, E), B = t.add(L, I), S = t.mul(S, B), B = t.add(j, d), S = t.sub(S, B), v = t.mul(C, p), B = t.mul(U, d), v = t.add(B, v), B = t.sub(j, v), v = t.add(j, v), A = t.mul(B, v), j = t.add(H, H), j = t.add(j, H), d = t.mul(C, d), p = t.mul(U, p), j = t.add(j, d), d = t.sub(H, d), d = t.mul(C, d), p = t.add(p, d), H = t.mul(j, p), A = t.add(A, H), H = t.mul(S, p), B = t.mul(w, B), B = t.sub(B, H), H = t.mul(w, j), v = t.mul(S, v), v = t.add(v, H), new l(B, A, v);
1177
- }
1178
- subtract(a) {
1179
- return this.add(a.negate());
1180
- }
1181
- is0() {
1182
- return this.equals(l.ZERO);
1183
- }
1184
- wNAF(a) {
1185
- return N.wNAFCached(this, a, l.normalizeZ);
1186
- }
1187
- /**
1188
- * Non-constant-time multiplication. Uses double-and-add algorithm.
1189
- * It's faster, but should only be used when you don't care about
1190
- * an exposed private key e.g. sig verification, which works over *public* keys.
1191
- */
1192
- multiplyUnsafe(a) {
1193
- const { endo: g, n: x } = n;
1194
- ot("scalar", a, W, x);
1195
- const E = l.ZERO;
1196
- if (a === W)
1197
- return E;
1198
- if (this.is0() || a === k)
1199
- return this;
1200
- if (!g || N.hasPrecomputes(this))
1201
- return N.wNAFCachedUnsafe(this, a, l.normalizeZ);
1202
- let { k1neg: q, k1: L, k2neg: I, k2: B } = g.splitScalar(a), A = E, v = E, C = this;
1203
- for (; L > W || B > W; )
1204
- L & k && (A = A.add(C)), B & k && (v = v.add(C)), C = C.double(), L >>= k, B >>= k;
1205
- return q && (A = A.negate()), I && (v = v.negate()), v = new l(t.mul(v.px, g.beta), v.py, v.pz), A.add(v);
1206
- }
1207
- /**
1208
- * Constant time multiplication.
1209
- * Uses wNAF method. Windowed method may be 10% faster,
1210
- * but takes 2x longer to generate and consumes 2x memory.
1211
- * Uses precomputes when available.
1212
- * Uses endomorphism for Koblitz curves.
1213
- * @param scalar by which the point would be multiplied
1214
- * @returns New point
1215
- */
1216
- multiply(a) {
1217
- const { endo: g, n: x } = n;
1218
- ot("scalar", a, k, x);
1219
- let E, q;
1220
- if (g) {
1221
- const { k1neg: L, k1: I, k2neg: B, k2: A } = g.splitScalar(a);
1222
- let { p: v, f: C } = this.wNAF(I), { p: U, f: H } = this.wNAF(A);
1223
- v = N.constTimeNegate(L, v), U = N.constTimeNegate(B, U), U = new l(t.mul(U.px, g.beta), U.py, U.pz), E = v.add(U), q = C.add(H);
1224
- } else {
1225
- const { p: L, f: I } = this.wNAF(a);
1226
- E = L, q = I;
1227
- }
1228
- return l.normalizeZ([E, q])[0];
1229
- }
1230
- /**
1231
- * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
1232
- * Not using Strauss-Shamir trick: precomputation tables are faster.
1233
- * The trick could be useful if both P and Q are not G (not in our case).
1234
- * @returns non-zero affine point
1235
- */
1236
- multiplyAndAddUnsafe(a, g, x) {
1237
- const E = l.BASE, q = (I, B) => B === W || B === k || !I.equals(E) ? I.multiplyUnsafe(B) : I.multiply(B), L = q(this, g).add(q(a, x));
1238
- return L.is0() ? void 0 : L;
1239
- }
1240
- // Converts Projective point to affine (x, y) coordinates.
1241
- // Can accept precomputed Z^-1 - for example, from invertBatch.
1242
- // (x, y, z) ∋ (x=x/z, y=y/z)
1243
- toAffine(a) {
1244
- return b(this, a);
1245
- }
1246
- isTorsionFree() {
1247
- const { h: a, isTorsionFree: g } = n;
1248
- if (a === k)
1249
- return !0;
1250
- if (g)
1251
- return g(l, this);
1252
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
1253
- }
1254
- clearCofactor() {
1255
- const { h: a, clearCofactor: g } = n;
1256
- return a === k ? this : g ? g(l, this) : this.multiplyUnsafe(n.h);
1257
- }
1258
- toRawBytes(a = !0) {
1259
- return lt("isCompressed", a), this.assertValidity(), o(l, this, a);
1260
- }
1261
- toHex(a = !0) {
1262
- return lt("isCompressed", a), dt(this.toRawBytes(a));
1263
- }
1264
- }
1265
- l.BASE = new l(n.Gx, n.Gy, t.ONE), l.ZERO = new l(t.ZERO, t.ONE, t.ZERO);
1266
- const m = n.nBitLength, N = We(l, n.endo ? Math.ceil(m / 2) : m);
1267
- return {
1268
- CURVE: n,
1269
- ProjectivePoint: l,
1270
- normPrivateKeyToScalar: s,
1271
- weierstrassEquation: c,
1272
- isWithinCurveOrder: f
1273
- };
1274
- }
1275
- function nn(e) {
1276
- const n = he(e);
1277
- return xt(n, {
1278
- hash: "hash",
1279
- hmac: "function",
1280
- randomBytes: "function"
1281
- }, {
1282
- bits2int: "function",
1283
- bits2int_modN: "function",
1284
- lowS: "boolean"
1285
- }), Object.freeze({ lowS: !0, ...n });
1286
- }
1287
- function rn(e) {
1288
- const n = nn(e), { Fp: t, n: r } = n, o = t.BYTES + 1, i = 2 * t.BYTES + 1;
1289
- function c(d) {
1290
- return M(d, r);
1291
- }
1292
- function f(d) {
1293
- return Rt(d, r);
1294
- }
1295
- const { ProjectivePoint: s, normPrivateKeyToScalar: u, weierstrassEquation: b, isWithinCurveOrder: h } = en({
1296
- ...n,
1297
- toBytes(d, w, p) {
1298
- const S = w.toAffine(), O = t.toBytes(S.x), _ = bt;
1299
- return lt("isCompressed", p), p ? _(Uint8Array.from([w.hasEvenY() ? 2 : 3]), O) : _(Uint8Array.from([4]), O, t.toBytes(S.y));
1300
- },
1301
- fromBytes(d) {
1302
- const w = d.length, p = d[0], S = d.subarray(1);
1303
- if (w === o && (p === 2 || p === 3)) {
1304
- const O = rt(S);
1305
- if (!It(O, k, t.ORDER))
1306
- throw new Error("Point is not on curve");
1307
- const _ = b(O);
1308
- let Z;
1309
- try {
1310
- Z = t.sqrt(_);
1311
- } catch (F) {
1312
- const V = F instanceof Error ? ": " + F.message : "";
1313
- throw new Error("Point is not on curve" + V);
1314
- }
1315
- const R = (Z & k) === k;
1316
- return (p & 1) === 1 !== R && (Z = t.neg(Z)), { x: O, y: Z };
1317
- } else if (w === i && p === 4) {
1318
- const O = t.fromBytes(S.subarray(0, t.BYTES)), _ = t.fromBytes(S.subarray(t.BYTES, 2 * t.BYTES));
1319
- return { x: O, y: _ };
1320
- } else {
1321
- const O = o, _ = i;
1322
- throw new Error("invalid Point, expected length of " + O + ", or uncompressed " + _ + ", got " + w);
1323
- }
1324
- }
1325
- }), l = (d) => dt(gt(d, n.nByteLength));
1326
- function m(d) {
1327
- const w = r >> k;
1328
- return d > w;
1329
- }
1330
- function N(d) {
1331
- return m(d) ? c(-d) : d;
1332
- }
1333
- const y = (d, w, p) => rt(d.slice(w, p));
1334
- class a {
1335
- constructor(w, p, S) {
1336
- this.r = w, this.s = p, this.recovery = S, this.assertValidity();
1337
- }
1338
- // pair (bytes of r, bytes of s)
1339
- static fromCompact(w) {
1340
- const p = n.nByteLength;
1341
- return w = K("compactSignature", w, p * 2), new a(y(w, 0, p), y(w, p, 2 * p));
1342
- }
1343
- // DER encoded ECDSA signature
1344
- // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
1345
- static fromDER(w) {
1346
- const { r: p, s: S } = D.toSig(K("DER", w));
1347
- return new a(p, S);
1348
- }
1349
- assertValidity() {
1350
- ot("r", this.r, k, r), ot("s", this.s, k, r);
1351
- }
1352
- addRecoveryBit(w) {
1353
- return new a(this.r, this.s, w);
1354
- }
1355
- recoverPublicKey(w) {
1356
- const { r: p, s: S, recovery: O } = this, _ = I(K("msgHash", w));
1357
- if (O == null || ![0, 1, 2, 3].includes(O))
1358
- throw new Error("recovery id invalid");
1359
- const Z = O === 2 || O === 3 ? p + n.n : p;
1360
- if (Z >= t.ORDER)
1361
- throw new Error("recovery id 2 or 3 invalid");
1362
- const R = O & 1 ? "03" : "02", G = s.fromHex(R + l(Z)), F = f(Z), V = c(-_ * F), st = c(S * F), X = s.BASE.multiplyAndAddUnsafe(G, V, st);
1363
- if (!X)
1364
- throw new Error("point at infinify");
1365
- return X.assertValidity(), X;
1366
- }
1367
- // Signatures should be low-s, to prevent malleability.
1368
- hasHighS() {
1369
- return m(this.s);
1370
- }
1371
- normalizeS() {
1372
- return this.hasHighS() ? new a(this.r, c(-this.s), this.recovery) : this;
1373
- }
1374
- // DER-encoded
1375
- toDERRawBytes() {
1376
- return ht(this.toDERHex());
1377
- }
1378
- toDERHex() {
1379
- return D.hexFromSig({ r: this.r, s: this.s });
1380
- }
1381
- // padded bytes of r, then padded bytes of s
1382
- toCompactRawBytes() {
1383
- return ht(this.toCompactHex());
1384
- }
1385
- toCompactHex() {
1386
- return l(this.r) + l(this.s);
1387
- }
1388
- }
1389
- const g = {
1390
- isValidPrivateKey(d) {
1391
- try {
1392
- return u(d), !0;
1393
- } catch {
1394
- return !1;
1395
- }
1396
- },
1397
- normPrivateKeyToScalar: u,
1398
- /**
1399
- * Produces cryptographically secure private key from random of size
1400
- * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
1401
- */
1402
- randomPrivateKey: () => {
1403
- const d = ue(n.n);
1404
- return Ge(n.randomBytes(d), n.n);
1405
- },
1406
- /**
1407
- * Creates precompute table for an arbitrary EC point. Makes point "cached".
1408
- * Allows to massively speed-up `point.multiply(scalar)`.
1409
- * @returns cached point
1410
- * @example
1411
- * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
1412
- * fast.multiply(privKey); // much faster ECDH now
1413
- */
1414
- precompute(d = 8, w = s.BASE) {
1415
- return w._setWindowSize(d), w.multiply(BigInt(3)), w;
1416
- }
1417
- };
1418
- function x(d, w = !0) {
1419
- return s.fromPrivateKey(d).toRawBytes(w);
1420
- }
1421
- function E(d) {
1422
- const w = it(d), p = typeof d == "string", S = (w || p) && d.length;
1423
- return w ? S === o || S === i : p ? S === 2 * o || S === 2 * i : d instanceof s;
1424
- }
1425
- function q(d, w, p = !0) {
1426
- if (E(d))
1427
- throw new Error("first arg must be private key");
1428
- if (!E(w))
1429
- throw new Error("second arg must be public key");
1430
- return s.fromHex(w).multiply(u(d)).toRawBytes(p);
1431
- }
1432
- const L = n.bits2int || function(d) {
1433
- if (d.length > 8192)
1434
- throw new Error("input is too large");
1435
- const w = rt(d), p = d.length * 8 - n.nBitLength;
1436
- return p > 0 ? w >> BigInt(p) : w;
1437
- }, I = n.bits2int_modN || function(d) {
1438
- return c(L(d));
1439
- }, B = Kt(n.nBitLength);
1440
- function A(d) {
1441
- return ot("num < 2^" + n.nBitLength, d, W, B), gt(d, n.nByteLength);
1442
- }
1443
- function v(d, w, p = C) {
1444
- if (["recovered", "canonical"].some((tt) => tt in p))
1445
- throw new Error("sign() legacy options not supported");
1446
- const { hash: S, randomBytes: O } = n;
1447
- let { lowS: _, prehash: Z, extraEntropy: R } = p;
1448
- _ == null && (_ = !0), d = K("msgHash", d), Qt(p), Z && (d = K("prehashed msgHash", S(d)));
1449
- const G = I(d), F = u(w), V = [A(F), A(G)];
1450
- if (R != null && R !== !1) {
1451
- const tt = R === !0 ? O(t.BYTES) : R;
1452
- V.push(K("extraEntropy", tt));
1453
- }
1454
- const st = bt(...V), X = G;
1455
- function Nt(tt) {
1456
- const ct = L(tt);
1457
- if (!h(ct))
1458
- return;
1459
- const qt = f(ct), wt = s.BASE.multiply(ct).toAffine(), et = c(wt.x);
1460
- if (et === W)
1461
- return;
1462
- const pt = c(qt * c(X + et * F));
1463
- if (pt === W)
1464
- return;
1465
- let yt = (wt.x === et ? 0 : 2) | Number(wt.y & k), ft = pt;
1466
- return _ && m(pt) && (ft = N(pt), yt ^= 1), new a(et, ft, yt);
1467
- }
1468
- return { seed: st, k2sig: Nt };
1469
- }
1470
- const C = { lowS: n.lowS, prehash: !1 }, U = { lowS: n.lowS, prehash: !1 };
1471
- function H(d, w, p = C) {
1472
- const { seed: S, k2sig: O } = v(d, w, p), _ = n;
1473
- return se(_.hash.outputLen, _.nByteLength, _.hmac)(S, O);
1474
- }
1475
- s.BASE._setWindowSize(8);
1476
- function j(d, w, p, S = U) {
1477
- var yt;
1478
- const O = d;
1479
- w = K("msgHash", w), p = K("publicKey", p);
1480
- const { lowS: _, prehash: Z, format: R } = S;
1481
- if (Qt(S), "strict" in S)
1482
- throw new Error("options.strict was renamed to lowS");
1483
- if (R !== void 0 && R !== "compact" && R !== "der")
1484
- throw new Error("format must be compact or der");
1485
- const G = typeof O == "string" || it(O), F = !G && !R && typeof O == "object" && O !== null && typeof O.r == "bigint" && typeof O.s == "bigint";
1486
- if (!G && !F)
1487
- throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
1488
- let V, st;
1489
- try {
1490
- if (F && (V = new a(O.r, O.s)), G) {
1491
- try {
1492
- R !== "compact" && (V = a.fromDER(O));
1493
- } catch (ft) {
1494
- if (!(ft instanceof D.Err))
1495
- throw ft;
1496
- }
1497
- !V && R !== "der" && (V = a.fromCompact(O));
1498
- }
1499
- st = s.fromHex(p);
1500
- } catch {
1501
- return !1;
1502
- }
1503
- if (!V || _ && V.hasHighS())
1504
- return !1;
1505
- Z && (w = n.hash(w));
1506
- const { r: X, s: Nt } = V, tt = I(w), ct = f(Nt), qt = c(tt * ct), wt = c(X * ct), et = (yt = s.BASE.multiplyAndAddUnsafe(st, qt, wt)) == null ? void 0 : yt.toAffine();
1507
- return et ? c(et.x) === X : !1;
1508
- }
1509
- return {
1510
- CURVE: n,
1511
- getPublicKey: x,
1512
- getSharedSecret: q,
1513
- sign: H,
1514
- verify: j,
1515
- ProjectivePoint: s,
1516
- Signature: a,
1517
- utils: g
1518
- };
1519
- }
1520
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1521
- function on(e) {
1522
- return {
1523
- hash: e,
1524
- hmac: (n, ...t) => oe(e, n, me(...t)),
1525
- randomBytes: Ee
1526
- };
1527
- }
1528
- function sn(e, n) {
1529
- const t = (r) => rn({ ...e, ...on(r) });
1530
- return Object.freeze({ ...t(n), create: t });
1531
- }
1532
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
1533
- const ge = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"), te = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"), cn = BigInt(1), Zt = BigInt(2), ee = (e, n) => (e + n / Zt) / n;
1534
- function fn(e) {
1535
- const n = ge, t = BigInt(3), r = BigInt(6), o = BigInt(11), i = BigInt(22), c = BigInt(23), f = BigInt(44), s = BigInt(88), u = e * e * e % n, b = u * u * e % n, h = Y(b, t, n) * b % n, l = Y(h, t, n) * b % n, m = Y(l, Zt, n) * u % n, N = Y(m, o, n) * m % n, y = Y(N, i, n) * N % n, a = Y(y, f, n) * y % n, g = Y(a, s, n) * a % n, x = Y(g, f, n) * y % n, E = Y(x, t, n) * b % n, q = Y(E, c, n) * N % n, L = Y(q, r, n) * u % n, I = Y(L, Zt, n);
1536
- if (!Vt.eql(Vt.sqr(I), e))
1537
- throw new Error("Cannot find square root");
1538
- return I;
1539
- }
1540
- const Vt = fe(ge, void 0, void 0, { sqrt: fn }), an = sn({
1541
- a: BigInt(0),
1542
- // equation params: a, b
1543
- b: BigInt(7),
1544
- // Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
1545
- Fp: Vt,
1546
- // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
1547
- n: te,
1548
- // Curve order, total count of valid points in the field
1549
- // Base point (x, y) aka generator point
1550
- Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
1551
- Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
1552
- h: BigInt(1),
1553
- // Cofactor
1554
- lowS: !0,
1555
- // Allow only low-S signatures by default in sign() and verify()
1556
- /**
1557
- * secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
1558
- * Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
1559
- * For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
1560
- * Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
1561
- */
1562
- endo: {
1563
- beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
1564
- splitScalar: (e) => {
1565
- const n = te, t = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -cn * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), o = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), i = t, c = BigInt("0x100000000000000000000000000000000"), f = ee(i * e, n), s = ee(-r * e, n);
1566
- let u = M(e - f * t - s * o, n), b = M(-f * r - s * i, n);
1567
- const h = u > c, l = b > c;
1568
- if (h && (u = n - u), l && (b = n - b), u > c || b > c)
1569
- throw new Error("splitScalar: Endomorphism failed, k=" + e);
1570
- return { k1neg: h, k1: u, k2neg: l, k2: b };
1571
- }
1572
- }
1573
- }, qe);
1574
- BigInt(0);
1575
- an.ProjectivePoint;
1576
- export {
1577
- an as secp256k1
1578
- };
1579
- //# sourceMappingURL=secp256k1-3OC5y4qp.js.map