@prosopo/procaptcha-bundle 3.0.12 → 3.1.6
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.
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js +17 -7
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.js +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaComponentProvider.js.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaProps.d.ts +1 -0
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaProps.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js +2 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.js +2 -2
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/components/frictionlessCaptcha.js.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js +6 -2
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js.map +1 -1
- package/CHANGELOG.md +374 -0
- package/dist/bundle/{ProcaptchaWidget-48FxVPQd.js → ProcaptchaWidget-CJ-4hVS1.js} +25 -25
- package/dist/bundle/{ProcaptchaWidget-B2BzhXLv.js → ProcaptchaWidget-Cw3s7cGX.js} +290 -268
- package/dist/bundle/{builder-DNHtDoNG.js → builder-ByZ5z580.js} +3 -1
- package/dist/bundle/captchaComponentProvider-Cn75EmSH.js +1002 -0
- package/dist/bundle/{captchaRenderer-DdOlOCKw.js → captchaRenderer-s4QuLEen.js} +23 -22
- package/dist/bundle/{commonChunk-HCVkoCqn.js → commonChunk-BjvuHlB1.js} +62 -68
- package/dist/bundle/{emotion-element-5486c51c.browser.esm-D7qvHZDV.js → emotion-element-c39617d8.browser.esm-BNNnmykm.js} +343 -345
- package/dist/bundle/index-BuQg3Zno.js +1884 -0
- package/dist/bundle/{index-DyYmvHVN.js → index-DIdd2cUz.js} +1 -1
- package/dist/bundle/{index-C00_J7av.js → index-IgqrmVIs.js} +61 -59
- package/dist/bundle/nobleChunk-Bbltwf44.js +2728 -0
- package/dist/bundle/procaptcha.bundle.js +2 -2
- package/dist/bundle/util/captcha/captchaComponentProvider.d.ts.map +1 -1
- package/dist/bundle/util/captcha/captchaProps.d.ts +1 -0
- package/dist/bundle/util/captcha/captchaProps.d.ts.map +1 -1
- package/dist/bundle/util/captcha/captchaRenderer.d.ts +1 -1
- package/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
- package/dist/bundle/util/captcha/components/frictionlessCaptcha.d.ts.map +1 -1
- package/dist/bundle/util/widgetFactory.d.ts.map +1 -1
- package/dist/bundle/{utilChunk-sqstc6C5.js → utilChunk-DPr6oTOj.js} +22 -22
- package/dist/bundle/{utilCryptoChunk-qm-BM2eT.js → utilCryptoChunk-D6ZLkbFV.js} +176 -167
- package/dist/bundle/{web2Chunk-DCsWA5PR.js → web2Chunk-CNoojUDK.js} +1083 -983
- package/dist/bundle/web3Chunk-BlYvY4Ea.js +525 -0
- package/dist/bundle/{zodChunk-wTu9ZHzV.js → zodChunk-aEfPZzrp.js} +3 -3
- package/dist/cjs/util/captcha/captchaComponentProvider.cjs +3 -2
- package/dist/cjs/util/captcha/captchaRenderer.cjs +4 -3
- package/dist/cjs/util/captcha/components/frictionlessCaptcha.cjs +4 -3
- package/dist/cjs/util/captcha/components/imageCaptcha.cjs +1 -1
- package/dist/cjs/util/captcha/components/powCaptcha.cjs +1 -1
- package/dist/cjs/util/widgetFactory.cjs +7 -2
- package/dist/util/captcha/captchaComponentProvider.js +3 -2
- package/dist/util/captcha/captchaRenderer.js +4 -3
- package/dist/util/captcha/components/frictionlessCaptcha.js +4 -3
- package/dist/util/captcha/components/imageCaptcha.js +1 -1
- package/dist/util/captcha/components/powCaptcha.js +1 -1
- package/dist/util/widgetFactory.js +7 -2
- package/package.json +25 -26
- package/stats.html +1 -1
- package/vite.test.config.ts +3 -2
- package/dist/bundle/captchaComponentProvider-B7Vxx339.js +0 -968
- package/dist/bundle/index-7Xh-Mf8v.js +0 -1318
- package/dist/bundle/nobleChunk-Qozzkbsq.js +0 -3648
- package/dist/bundle/web3Chunk-B8txCqUJ.js +0 -517
|
@@ -1,3648 +0,0 @@
|
|
|
1
|
-
function Ss(e) {
|
|
2
|
-
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
3
|
-
}
|
|
4
|
-
function et(e) {
|
|
5
|
-
if (!Number.isSafeInteger(e) || e < 0)
|
|
6
|
-
throw new Error("positive integer expected, got " + e);
|
|
7
|
-
}
|
|
8
|
-
function ie(e, ...t) {
|
|
9
|
-
if (!Ss(e))
|
|
10
|
-
throw new Error("Uint8Array expected");
|
|
11
|
-
if (t.length > 0 && !t.includes(e.length))
|
|
12
|
-
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
13
|
-
}
|
|
14
|
-
function Tn(e) {
|
|
15
|
-
if (typeof e != "function" || typeof e.create != "function")
|
|
16
|
-
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
17
|
-
et(e.outputLen), et(e.blockLen);
|
|
18
|
-
}
|
|
19
|
-
function te(e, t = !0) {
|
|
20
|
-
if (e.destroyed)
|
|
21
|
-
throw new Error("Hash instance has been destroyed");
|
|
22
|
-
if (t && e.finished)
|
|
23
|
-
throw new Error("Hash#digest() has already been called");
|
|
24
|
-
}
|
|
25
|
-
function Nn(e, t) {
|
|
26
|
-
ie(e);
|
|
27
|
-
const n = t.outputLen;
|
|
28
|
-
if (e.length < n)
|
|
29
|
-
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
30
|
-
}
|
|
31
|
-
function qt(e) {
|
|
32
|
-
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
33
|
-
}
|
|
34
|
-
function it(...e) {
|
|
35
|
-
for (let t = 0; t < e.length; t++)
|
|
36
|
-
e[t].fill(0);
|
|
37
|
-
}
|
|
38
|
-
function Ee(e) {
|
|
39
|
-
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
40
|
-
}
|
|
41
|
-
function ct(e, t) {
|
|
42
|
-
return e << 32 - t | e >>> t;
|
|
43
|
-
}
|
|
44
|
-
function R(e, t) {
|
|
45
|
-
return e << t | e >>> 32 - t >>> 0;
|
|
46
|
-
}
|
|
47
|
-
const Rn = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
48
|
-
function Gn(e) {
|
|
49
|
-
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
50
|
-
}
|
|
51
|
-
const xt = Rn ? (e) => e : (e) => Gn(e);
|
|
52
|
-
function Is(e) {
|
|
53
|
-
for (let t = 0; t < e.length; t++)
|
|
54
|
-
e[t] = Gn(e[t]);
|
|
55
|
-
return e;
|
|
56
|
-
}
|
|
57
|
-
const Dt = Rn ? (e) => e : Is;
|
|
58
|
-
function qn(e) {
|
|
59
|
-
if (typeof e != "string")
|
|
60
|
-
throw new Error("string expected");
|
|
61
|
-
return new Uint8Array(new TextEncoder().encode(e));
|
|
62
|
-
}
|
|
63
|
-
function Tt(e) {
|
|
64
|
-
return typeof e == "string" && (e = qn(e)), ie(e), e;
|
|
65
|
-
}
|
|
66
|
-
function hn(e) {
|
|
67
|
-
return typeof e == "string" && (e = qn(e)), ie(e), e;
|
|
68
|
-
}
|
|
69
|
-
function Mn(e, t) {
|
|
70
|
-
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
71
|
-
throw new Error("options should be object or undefined");
|
|
72
|
-
return Object.assign(e, t);
|
|
73
|
-
}
|
|
74
|
-
let Pe = class {
|
|
75
|
-
};
|
|
76
|
-
function Vn(e) {
|
|
77
|
-
const t = (s) => e().update(Tt(s)).digest(), n = e();
|
|
78
|
-
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
79
|
-
}
|
|
80
|
-
function Us(e) {
|
|
81
|
-
const t = (s, r) => e(r).update(Tt(s)).digest(), n = e({});
|
|
82
|
-
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = (s) => e(s), t;
|
|
83
|
-
}
|
|
84
|
-
const vs = /* @__PURE__ */ Uint8Array.from([
|
|
85
|
-
0,
|
|
86
|
-
1,
|
|
87
|
-
2,
|
|
88
|
-
3,
|
|
89
|
-
4,
|
|
90
|
-
5,
|
|
91
|
-
6,
|
|
92
|
-
7,
|
|
93
|
-
8,
|
|
94
|
-
9,
|
|
95
|
-
10,
|
|
96
|
-
11,
|
|
97
|
-
12,
|
|
98
|
-
13,
|
|
99
|
-
14,
|
|
100
|
-
15,
|
|
101
|
-
14,
|
|
102
|
-
10,
|
|
103
|
-
4,
|
|
104
|
-
8,
|
|
105
|
-
9,
|
|
106
|
-
15,
|
|
107
|
-
13,
|
|
108
|
-
6,
|
|
109
|
-
1,
|
|
110
|
-
12,
|
|
111
|
-
0,
|
|
112
|
-
2,
|
|
113
|
-
11,
|
|
114
|
-
7,
|
|
115
|
-
5,
|
|
116
|
-
3,
|
|
117
|
-
11,
|
|
118
|
-
8,
|
|
119
|
-
12,
|
|
120
|
-
0,
|
|
121
|
-
5,
|
|
122
|
-
2,
|
|
123
|
-
15,
|
|
124
|
-
13,
|
|
125
|
-
10,
|
|
126
|
-
14,
|
|
127
|
-
3,
|
|
128
|
-
6,
|
|
129
|
-
7,
|
|
130
|
-
1,
|
|
131
|
-
9,
|
|
132
|
-
4,
|
|
133
|
-
7,
|
|
134
|
-
9,
|
|
135
|
-
3,
|
|
136
|
-
1,
|
|
137
|
-
13,
|
|
138
|
-
12,
|
|
139
|
-
11,
|
|
140
|
-
14,
|
|
141
|
-
2,
|
|
142
|
-
6,
|
|
143
|
-
5,
|
|
144
|
-
10,
|
|
145
|
-
4,
|
|
146
|
-
0,
|
|
147
|
-
15,
|
|
148
|
-
8,
|
|
149
|
-
9,
|
|
150
|
-
0,
|
|
151
|
-
5,
|
|
152
|
-
7,
|
|
153
|
-
2,
|
|
154
|
-
4,
|
|
155
|
-
10,
|
|
156
|
-
15,
|
|
157
|
-
14,
|
|
158
|
-
1,
|
|
159
|
-
11,
|
|
160
|
-
12,
|
|
161
|
-
6,
|
|
162
|
-
8,
|
|
163
|
-
3,
|
|
164
|
-
13,
|
|
165
|
-
2,
|
|
166
|
-
12,
|
|
167
|
-
6,
|
|
168
|
-
10,
|
|
169
|
-
0,
|
|
170
|
-
11,
|
|
171
|
-
8,
|
|
172
|
-
3,
|
|
173
|
-
4,
|
|
174
|
-
13,
|
|
175
|
-
7,
|
|
176
|
-
5,
|
|
177
|
-
15,
|
|
178
|
-
14,
|
|
179
|
-
1,
|
|
180
|
-
9,
|
|
181
|
-
12,
|
|
182
|
-
5,
|
|
183
|
-
1,
|
|
184
|
-
15,
|
|
185
|
-
14,
|
|
186
|
-
13,
|
|
187
|
-
4,
|
|
188
|
-
10,
|
|
189
|
-
0,
|
|
190
|
-
7,
|
|
191
|
-
6,
|
|
192
|
-
3,
|
|
193
|
-
9,
|
|
194
|
-
2,
|
|
195
|
-
8,
|
|
196
|
-
11,
|
|
197
|
-
13,
|
|
198
|
-
11,
|
|
199
|
-
7,
|
|
200
|
-
14,
|
|
201
|
-
12,
|
|
202
|
-
1,
|
|
203
|
-
3,
|
|
204
|
-
9,
|
|
205
|
-
5,
|
|
206
|
-
0,
|
|
207
|
-
15,
|
|
208
|
-
4,
|
|
209
|
-
8,
|
|
210
|
-
6,
|
|
211
|
-
2,
|
|
212
|
-
10,
|
|
213
|
-
6,
|
|
214
|
-
15,
|
|
215
|
-
14,
|
|
216
|
-
9,
|
|
217
|
-
11,
|
|
218
|
-
3,
|
|
219
|
-
0,
|
|
220
|
-
8,
|
|
221
|
-
12,
|
|
222
|
-
2,
|
|
223
|
-
13,
|
|
224
|
-
7,
|
|
225
|
-
1,
|
|
226
|
-
4,
|
|
227
|
-
10,
|
|
228
|
-
5,
|
|
229
|
-
10,
|
|
230
|
-
2,
|
|
231
|
-
8,
|
|
232
|
-
4,
|
|
233
|
-
7,
|
|
234
|
-
6,
|
|
235
|
-
1,
|
|
236
|
-
5,
|
|
237
|
-
15,
|
|
238
|
-
11,
|
|
239
|
-
9,
|
|
240
|
-
14,
|
|
241
|
-
3,
|
|
242
|
-
12,
|
|
243
|
-
13,
|
|
244
|
-
0,
|
|
245
|
-
0,
|
|
246
|
-
1,
|
|
247
|
-
2,
|
|
248
|
-
3,
|
|
249
|
-
4,
|
|
250
|
-
5,
|
|
251
|
-
6,
|
|
252
|
-
7,
|
|
253
|
-
8,
|
|
254
|
-
9,
|
|
255
|
-
10,
|
|
256
|
-
11,
|
|
257
|
-
12,
|
|
258
|
-
13,
|
|
259
|
-
14,
|
|
260
|
-
15,
|
|
261
|
-
14,
|
|
262
|
-
10,
|
|
263
|
-
4,
|
|
264
|
-
8,
|
|
265
|
-
9,
|
|
266
|
-
15,
|
|
267
|
-
13,
|
|
268
|
-
6,
|
|
269
|
-
1,
|
|
270
|
-
12,
|
|
271
|
-
0,
|
|
272
|
-
2,
|
|
273
|
-
11,
|
|
274
|
-
7,
|
|
275
|
-
5,
|
|
276
|
-
3,
|
|
277
|
-
// Blake1, unused in others
|
|
278
|
-
11,
|
|
279
|
-
8,
|
|
280
|
-
12,
|
|
281
|
-
0,
|
|
282
|
-
5,
|
|
283
|
-
2,
|
|
284
|
-
15,
|
|
285
|
-
13,
|
|
286
|
-
10,
|
|
287
|
-
14,
|
|
288
|
-
3,
|
|
289
|
-
6,
|
|
290
|
-
7,
|
|
291
|
-
1,
|
|
292
|
-
9,
|
|
293
|
-
4,
|
|
294
|
-
7,
|
|
295
|
-
9,
|
|
296
|
-
3,
|
|
297
|
-
1,
|
|
298
|
-
13,
|
|
299
|
-
12,
|
|
300
|
-
11,
|
|
301
|
-
14,
|
|
302
|
-
2,
|
|
303
|
-
6,
|
|
304
|
-
5,
|
|
305
|
-
10,
|
|
306
|
-
4,
|
|
307
|
-
0,
|
|
308
|
-
15,
|
|
309
|
-
8,
|
|
310
|
-
9,
|
|
311
|
-
0,
|
|
312
|
-
5,
|
|
313
|
-
7,
|
|
314
|
-
2,
|
|
315
|
-
4,
|
|
316
|
-
10,
|
|
317
|
-
15,
|
|
318
|
-
14,
|
|
319
|
-
1,
|
|
320
|
-
11,
|
|
321
|
-
12,
|
|
322
|
-
6,
|
|
323
|
-
8,
|
|
324
|
-
3,
|
|
325
|
-
13,
|
|
326
|
-
2,
|
|
327
|
-
12,
|
|
328
|
-
6,
|
|
329
|
-
10,
|
|
330
|
-
0,
|
|
331
|
-
11,
|
|
332
|
-
8,
|
|
333
|
-
3,
|
|
334
|
-
4,
|
|
335
|
-
13,
|
|
336
|
-
7,
|
|
337
|
-
5,
|
|
338
|
-
15,
|
|
339
|
-
14,
|
|
340
|
-
1,
|
|
341
|
-
9
|
|
342
|
-
]);
|
|
343
|
-
function $s(e, t, n, s) {
|
|
344
|
-
if (typeof e.setBigUint64 == "function")
|
|
345
|
-
return e.setBigUint64(t, n, s);
|
|
346
|
-
const r = BigInt(32), o = BigInt(4294967295), i = Number(n >> r & o), c = Number(n & o), f = s ? 4 : 0, l = s ? 0 : 4;
|
|
347
|
-
e.setUint32(t + f, i, s), e.setUint32(t + l, c, s);
|
|
348
|
-
}
|
|
349
|
-
function Ls(e, t, n) {
|
|
350
|
-
return e & t ^ ~e & n;
|
|
351
|
-
}
|
|
352
|
-
function Ds(e, t, n) {
|
|
353
|
-
return e & t ^ e & n ^ t & n;
|
|
354
|
-
}
|
|
355
|
-
let Zn = class extends Pe {
|
|
356
|
-
constructor(t, n, s, r) {
|
|
357
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = Ee(this.buffer);
|
|
358
|
-
}
|
|
359
|
-
update(t) {
|
|
360
|
-
te(this), t = Tt(t), ie(t);
|
|
361
|
-
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
362
|
-
for (let i = 0; i < o; ) {
|
|
363
|
-
const c = Math.min(r - this.pos, o - i);
|
|
364
|
-
if (c === r) {
|
|
365
|
-
const f = Ee(t);
|
|
366
|
-
for (; r <= o - i; i += r)
|
|
367
|
-
this.process(f, i);
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
s.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
371
|
-
}
|
|
372
|
-
return this.length += t.length, this.roundClean(), this;
|
|
373
|
-
}
|
|
374
|
-
digestInto(t) {
|
|
375
|
-
te(this), Nn(t, this), this.finished = !0;
|
|
376
|
-
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
377
|
-
let { pos: i } = this;
|
|
378
|
-
n[i++] = 128, it(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
379
|
-
for (let a = i; a < r; a++)
|
|
380
|
-
n[a] = 0;
|
|
381
|
-
$s(s, r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
382
|
-
const c = Ee(t), f = this.outputLen;
|
|
383
|
-
if (f % 4)
|
|
384
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
385
|
-
const l = f / 4, h = this.get();
|
|
386
|
-
if (l > h.length)
|
|
387
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
388
|
-
for (let a = 0; a < l; a++)
|
|
389
|
-
c.setUint32(4 * a, h[a], o);
|
|
390
|
-
}
|
|
391
|
-
digest() {
|
|
392
|
-
const { buffer: t, outputLen: n } = this;
|
|
393
|
-
this.digestInto(t);
|
|
394
|
-
const s = t.slice(0, n);
|
|
395
|
-
return this.destroy(), s;
|
|
396
|
-
}
|
|
397
|
-
_cloneInto(t) {
|
|
398
|
-
t || (t = new this.constructor()), t.set(...this.get());
|
|
399
|
-
const { blockLen: n, buffer: s, length: r, finished: o, destroyed: i, pos: c } = this;
|
|
400
|
-
return t.destroyed = i, t.finished = o, t.length = r, t.pos = c, r % n && t.buffer.set(s), t;
|
|
401
|
-
}
|
|
402
|
-
clone() {
|
|
403
|
-
return this._cloneInto();
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
const yt = /* @__PURE__ */ Uint32Array.from([
|
|
407
|
-
1779033703,
|
|
408
|
-
3144134277,
|
|
409
|
-
1013904242,
|
|
410
|
-
2773480762,
|
|
411
|
-
1359893119,
|
|
412
|
-
2600822924,
|
|
413
|
-
528734635,
|
|
414
|
-
1541459225
|
|
415
|
-
]);
|
|
416
|
-
const X = /* @__PURE__ */ Uint32Array.from([
|
|
417
|
-
1779033703,
|
|
418
|
-
4089235720,
|
|
419
|
-
3144134277,
|
|
420
|
-
2227873595,
|
|
421
|
-
1013904242,
|
|
422
|
-
4271175723,
|
|
423
|
-
2773480762,
|
|
424
|
-
1595750129,
|
|
425
|
-
1359893119,
|
|
426
|
-
2917565137,
|
|
427
|
-
2600822924,
|
|
428
|
-
725511199,
|
|
429
|
-
528734635,
|
|
430
|
-
4215389547,
|
|
431
|
-
1541459225,
|
|
432
|
-
327033209
|
|
433
|
-
]), xe = /* @__PURE__ */ BigInt(2 ** 32 - 1), ln = /* @__PURE__ */ BigInt(32);
|
|
434
|
-
function zn(e, t = !1) {
|
|
435
|
-
return t ? { h: Number(e & xe), l: Number(e >> ln & xe) } : { h: Number(e >> ln & xe) | 0, l: Number(e & xe) | 0 };
|
|
436
|
-
}
|
|
437
|
-
function Cs(e, t = !1) {
|
|
438
|
-
const n = e.length;
|
|
439
|
-
let s = new Uint32Array(n), r = new Uint32Array(n);
|
|
440
|
-
for (let o = 0; o < n; o++) {
|
|
441
|
-
const { h: i, l: c } = zn(e[o], t);
|
|
442
|
-
[s[o], r[o]] = [i, c];
|
|
443
|
-
}
|
|
444
|
-
return [s, r];
|
|
445
|
-
}
|
|
446
|
-
const dn = (e, t, n) => e >>> n, un = (e, t, n) => e << 32 - n | t >>> n, Ct = (e, t, n) => e >>> n | t << 32 - n, kt = (e, t, n) => e << 32 - n | t >>> n, fe = (e, t, n) => e << 64 - n | t >>> n - 32, ae = (e, t, n) => e >>> n - 32 | t << 64 - n, ks = (e, t) => t, Os = (e, t) => e;
|
|
447
|
-
function rt(e, t, n, s) {
|
|
448
|
-
const r = (t >>> 0) + (s >>> 0);
|
|
449
|
-
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
450
|
-
}
|
|
451
|
-
const Qe = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), Je = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, Ts = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), Ns = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, Rs = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), Gs = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, j = /* @__PURE__ */ Uint32Array.from([
|
|
452
|
-
4089235720,
|
|
453
|
-
1779033703,
|
|
454
|
-
2227873595,
|
|
455
|
-
3144134277,
|
|
456
|
-
4271175723,
|
|
457
|
-
1013904242,
|
|
458
|
-
1595750129,
|
|
459
|
-
2773480762,
|
|
460
|
-
2917565137,
|
|
461
|
-
1359893119,
|
|
462
|
-
725511199,
|
|
463
|
-
2600822924,
|
|
464
|
-
4215389547,
|
|
465
|
-
528734635,
|
|
466
|
-
327033209,
|
|
467
|
-
1541459225
|
|
468
|
-
]), U = /* @__PURE__ */ new Uint32Array(32);
|
|
469
|
-
function pt(e, t, n, s, r, o) {
|
|
470
|
-
const i = r[o], c = r[o + 1];
|
|
471
|
-
let f = U[2 * e], l = U[2 * e + 1], h = U[2 * t], a = U[2 * t + 1], d = U[2 * n], u = U[2 * n + 1], y = U[2 * s], b = U[2 * s + 1], w = Qe(f, h, i);
|
|
472
|
-
l = Je(w, l, a, c), f = w | 0, { Dh: b, Dl: y } = { Dh: b ^ l, Dl: y ^ f }, { Dh: b, Dl: y } = { Dh: ks(b, y), Dl: Os(b) }, { h: u, l: d } = rt(u, d, b, y), { Bh: a, Bl: h } = { Bh: a ^ u, Bl: h ^ d }, { Bh: a, Bl: h } = { Bh: Ct(a, h, 24), Bl: kt(a, h, 24) }, U[2 * e] = f, U[2 * e + 1] = l, U[2 * t] = h, U[2 * t + 1] = a, U[2 * n] = d, U[2 * n + 1] = u, U[2 * s] = y, U[2 * s + 1] = b;
|
|
473
|
-
}
|
|
474
|
-
function mt(e, t, n, s, r, o) {
|
|
475
|
-
const i = r[o], c = r[o + 1];
|
|
476
|
-
let f = U[2 * e], l = U[2 * e + 1], h = U[2 * t], a = U[2 * t + 1], d = U[2 * n], u = U[2 * n + 1], y = U[2 * s], b = U[2 * s + 1], w = Qe(f, h, i);
|
|
477
|
-
l = Je(w, l, a, c), f = w | 0, { Dh: b, Dl: y } = { Dh: b ^ l, Dl: y ^ f }, { Dh: b, Dl: y } = { Dh: Ct(b, y, 16), Dl: kt(b, y, 16) }, { h: u, l: d } = rt(u, d, b, y), { Bh: a, Bl: h } = { Bh: a ^ u, Bl: h ^ d }, { Bh: a, Bl: h } = { Bh: fe(a, h, 63), Bl: ae(a, h, 63) }, U[2 * e] = f, U[2 * e + 1] = l, U[2 * t] = h, U[2 * t + 1] = a, U[2 * n] = d, U[2 * n + 1] = u, U[2 * s] = y, U[2 * s + 1] = b;
|
|
478
|
-
}
|
|
479
|
-
function qs(e, t = {}, n, s, r) {
|
|
480
|
-
if (et(n), e < 0 || e > n)
|
|
481
|
-
throw new Error("outputLen bigger than keyLen");
|
|
482
|
-
const { key: o, salt: i, personalization: c } = t;
|
|
483
|
-
if (o !== void 0 && (o.length < 1 || o.length > n))
|
|
484
|
-
throw new Error("key length must be undefined or 1.." + n);
|
|
485
|
-
if (i !== void 0 && i.length !== s)
|
|
486
|
-
throw new Error("salt must be undefined or " + s);
|
|
487
|
-
if (c !== void 0 && c.length !== r)
|
|
488
|
-
throw new Error("personalization must be undefined or " + r);
|
|
489
|
-
}
|
|
490
|
-
class Ms extends Pe {
|
|
491
|
-
constructor(t, n) {
|
|
492
|
-
super(), this.finished = !1, this.destroyed = !1, this.length = 0, this.pos = 0, et(t), et(n), this.blockLen = t, this.outputLen = n, this.buffer = new Uint8Array(t), this.buffer32 = qt(this.buffer);
|
|
493
|
-
}
|
|
494
|
-
update(t) {
|
|
495
|
-
te(this), t = Tt(t), ie(t);
|
|
496
|
-
const { blockLen: n, buffer: s, buffer32: r } = this, o = t.length, i = t.byteOffset, c = t.buffer;
|
|
497
|
-
for (let f = 0; f < o; ) {
|
|
498
|
-
this.pos === n && (Dt(r), this.compress(r, 0, !1), Dt(r), this.pos = 0);
|
|
499
|
-
const l = Math.min(n - this.pos, o - f), h = i + f;
|
|
500
|
-
if (l === n && !(h % 4) && f + l < o) {
|
|
501
|
-
const a = new Uint32Array(c, h, Math.floor((o - f) / 4));
|
|
502
|
-
Dt(a);
|
|
503
|
-
for (let d = 0; f + n < o; d += r.length, f += n)
|
|
504
|
-
this.length += n, this.compress(a, d, !1);
|
|
505
|
-
Dt(a);
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
s.set(t.subarray(f, f + l), this.pos), this.pos += l, this.length += l, f += l;
|
|
509
|
-
}
|
|
510
|
-
return this;
|
|
511
|
-
}
|
|
512
|
-
digestInto(t) {
|
|
513
|
-
te(this), Nn(t, this);
|
|
514
|
-
const { pos: n, buffer32: s } = this;
|
|
515
|
-
this.finished = !0, it(this.buffer.subarray(n)), Dt(s), this.compress(s, 0, !0), Dt(s);
|
|
516
|
-
const r = qt(t);
|
|
517
|
-
this.get().forEach((o, i) => r[i] = xt(o));
|
|
518
|
-
}
|
|
519
|
-
digest() {
|
|
520
|
-
const { buffer: t, outputLen: n } = this;
|
|
521
|
-
this.digestInto(t);
|
|
522
|
-
const s = t.slice(0, n);
|
|
523
|
-
return this.destroy(), s;
|
|
524
|
-
}
|
|
525
|
-
_cloneInto(t) {
|
|
526
|
-
const { buffer: n, length: s, finished: r, destroyed: o, outputLen: i, pos: c } = this;
|
|
527
|
-
return t || (t = new this.constructor({ dkLen: i })), t.set(...this.get()), t.buffer.set(n), t.destroyed = o, t.finished = r, t.length = s, t.pos = c, t.outputLen = i, t;
|
|
528
|
-
}
|
|
529
|
-
clone() {
|
|
530
|
-
return this._cloneInto();
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
class Vs extends Ms {
|
|
534
|
-
constructor(t = {}) {
|
|
535
|
-
const n = t.dkLen === void 0 ? 64 : t.dkLen;
|
|
536
|
-
super(128, n), this.v0l = j[0] | 0, this.v0h = j[1] | 0, this.v1l = j[2] | 0, this.v1h = j[3] | 0, this.v2l = j[4] | 0, this.v2h = j[5] | 0, this.v3l = j[6] | 0, this.v3h = j[7] | 0, this.v4l = j[8] | 0, this.v4h = j[9] | 0, this.v5l = j[10] | 0, this.v5h = j[11] | 0, this.v6l = j[12] | 0, this.v6h = j[13] | 0, this.v7l = j[14] | 0, this.v7h = j[15] | 0, qs(n, t, 64, 16, 16);
|
|
537
|
-
let { key: s, personalization: r, salt: o } = t, i = 0;
|
|
538
|
-
if (s !== void 0 && (s = Tt(s), i = s.length), this.v0l ^= this.outputLen | i << 8 | 65536 | 1 << 24, o !== void 0) {
|
|
539
|
-
o = Tt(o);
|
|
540
|
-
const c = qt(o);
|
|
541
|
-
this.v4l ^= xt(c[0]), this.v4h ^= xt(c[1]), this.v5l ^= xt(c[2]), this.v5h ^= xt(c[3]);
|
|
542
|
-
}
|
|
543
|
-
if (r !== void 0) {
|
|
544
|
-
r = Tt(r);
|
|
545
|
-
const c = qt(r);
|
|
546
|
-
this.v6l ^= xt(c[0]), this.v6h ^= xt(c[1]), this.v7l ^= xt(c[2]), this.v7h ^= xt(c[3]);
|
|
547
|
-
}
|
|
548
|
-
if (s !== void 0) {
|
|
549
|
-
const c = new Uint8Array(this.blockLen);
|
|
550
|
-
c.set(s), this.update(c);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
// prettier-ignore
|
|
554
|
-
get() {
|
|
555
|
-
let { v0l: t, v0h: n, v1l: s, v1h: r, v2l: o, v2h: i, v3l: c, v3h: f, v4l: l, v4h: h, v5l: a, v5h: d, v6l: u, v6h: y, v7l: b, v7h: w } = this;
|
|
556
|
-
return [t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w];
|
|
557
|
-
}
|
|
558
|
-
// prettier-ignore
|
|
559
|
-
set(t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w) {
|
|
560
|
-
this.v0l = t | 0, this.v0h = n | 0, this.v1l = s | 0, this.v1h = r | 0, this.v2l = o | 0, this.v2h = i | 0, this.v3l = c | 0, this.v3h = f | 0, this.v4l = l | 0, this.v4h = h | 0, this.v5l = a | 0, this.v5h = d | 0, this.v6l = u | 0, this.v6h = y | 0, this.v7l = b | 0, this.v7h = w | 0;
|
|
561
|
-
}
|
|
562
|
-
compress(t, n, s) {
|
|
563
|
-
this.get().forEach((f, l) => U[l] = f), U.set(j, 16);
|
|
564
|
-
let { h: r, l: o } = zn(BigInt(this.length));
|
|
565
|
-
U[24] = j[8] ^ o, U[25] = j[9] ^ r, s && (U[28] = ~U[28], U[29] = ~U[29]);
|
|
566
|
-
let i = 0;
|
|
567
|
-
const c = vs;
|
|
568
|
-
for (let f = 0; f < 12; f++)
|
|
569
|
-
pt(0, 4, 8, 12, t, n + 2 * c[i++]), mt(0, 4, 8, 12, t, n + 2 * c[i++]), pt(1, 5, 9, 13, t, n + 2 * c[i++]), mt(1, 5, 9, 13, t, n + 2 * c[i++]), pt(2, 6, 10, 14, t, n + 2 * c[i++]), mt(2, 6, 10, 14, t, n + 2 * c[i++]), pt(3, 7, 11, 15, t, n + 2 * c[i++]), mt(3, 7, 11, 15, t, n + 2 * c[i++]), pt(0, 5, 10, 15, t, n + 2 * c[i++]), mt(0, 5, 10, 15, t, n + 2 * c[i++]), pt(1, 6, 11, 12, t, n + 2 * c[i++]), mt(1, 6, 11, 12, t, n + 2 * c[i++]), pt(2, 7, 8, 13, t, n + 2 * c[i++]), mt(2, 7, 8, 13, t, n + 2 * c[i++]), pt(3, 4, 9, 14, t, n + 2 * c[i++]), mt(3, 4, 9, 14, t, n + 2 * c[i++]);
|
|
570
|
-
this.v0l ^= U[0] ^ U[16], this.v0h ^= U[1] ^ U[17], this.v1l ^= U[2] ^ U[18], this.v1h ^= U[3] ^ U[19], this.v2l ^= U[4] ^ U[20], this.v2h ^= U[5] ^ U[21], this.v3l ^= U[6] ^ U[22], this.v3h ^= U[7] ^ U[23], this.v4l ^= U[8] ^ U[24], this.v4h ^= U[9] ^ U[25], this.v5l ^= U[10] ^ U[26], this.v5h ^= U[11] ^ U[27], this.v6l ^= U[12] ^ U[28], this.v6h ^= U[13] ^ U[29], this.v7l ^= U[14] ^ U[30], this.v7h ^= U[15] ^ U[31], it(U);
|
|
571
|
-
}
|
|
572
|
-
destroy() {
|
|
573
|
-
this.destroyed = !0, it(this.buffer32), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
const Zs = /* @__PURE__ */ Us((e) => new Vs(e));
|
|
577
|
-
const ii = Zs;
|
|
578
|
-
let jn = class extends Pe {
|
|
579
|
-
constructor(t, n) {
|
|
580
|
-
super(), this.finished = !1, this.destroyed = !1, Tn(t);
|
|
581
|
-
const s = Tt(n);
|
|
582
|
-
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
583
|
-
throw new Error("Expected instance of class which extends utils.Hash");
|
|
584
|
-
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
585
|
-
const r = this.blockLen, o = new Uint8Array(r);
|
|
586
|
-
o.set(s.length > r ? t.create().update(s).digest() : s);
|
|
587
|
-
for (let i = 0; i < o.length; i++)
|
|
588
|
-
o[i] ^= 54;
|
|
589
|
-
this.iHash.update(o), this.oHash = t.create();
|
|
590
|
-
for (let i = 0; i < o.length; i++)
|
|
591
|
-
o[i] ^= 106;
|
|
592
|
-
this.oHash.update(o), it(o);
|
|
593
|
-
}
|
|
594
|
-
update(t) {
|
|
595
|
-
return te(this), this.iHash.update(t), this;
|
|
596
|
-
}
|
|
597
|
-
digestInto(t) {
|
|
598
|
-
te(this), ie(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
599
|
-
}
|
|
600
|
-
digest() {
|
|
601
|
-
const t = new Uint8Array(this.oHash.outputLen);
|
|
602
|
-
return this.digestInto(t), t;
|
|
603
|
-
}
|
|
604
|
-
_cloneInto(t) {
|
|
605
|
-
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
606
|
-
const { oHash: n, iHash: s, finished: r, destroyed: o, blockLen: i, outputLen: c } = this;
|
|
607
|
-
return t = t, t.finished = r, t.destroyed = o, t.blockLen = i, t.outputLen = c, t.oHash = n._cloneInto(t.oHash), t.iHash = s._cloneInto(t.iHash), t;
|
|
608
|
-
}
|
|
609
|
-
clone() {
|
|
610
|
-
return this._cloneInto();
|
|
611
|
-
}
|
|
612
|
-
destroy() {
|
|
613
|
-
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
const Wn = (e, t, n) => new jn(e, t).update(n).digest();
|
|
617
|
-
Wn.create = (e, t) => new jn(e, t);
|
|
618
|
-
function zs(e, t, n, s) {
|
|
619
|
-
Tn(e);
|
|
620
|
-
const r = Mn({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: c } = r;
|
|
621
|
-
if (et(o), et(i), et(c), o < 1)
|
|
622
|
-
throw new Error("iterations (c) should be >= 1");
|
|
623
|
-
const f = hn(t), l = hn(n), h = new Uint8Array(i), a = Wn.create(e, f), d = a._cloneInto().update(l);
|
|
624
|
-
return { c: o, dkLen: i, asyncTick: c, DK: h, PRF: a, PRFSalt: d };
|
|
625
|
-
}
|
|
626
|
-
function js(e, t, n, s, r) {
|
|
627
|
-
return e.destroy(), t.destroy(), s && s.destroy(), it(r), n;
|
|
628
|
-
}
|
|
629
|
-
function Fn(e, t, n, s) {
|
|
630
|
-
const { c: r, dkLen: o, DK: i, PRF: c, PRFSalt: f } = zs(e, t, n, s);
|
|
631
|
-
let l;
|
|
632
|
-
const h = new Uint8Array(4), a = Ee(h), d = new Uint8Array(c.outputLen);
|
|
633
|
-
for (let u = 1, y = 0; y < o; u++, y += c.outputLen) {
|
|
634
|
-
const b = i.subarray(y, y + c.outputLen);
|
|
635
|
-
a.setInt32(0, u, !1), (l = f._cloneInto(l)).update(h).digestInto(d), b.set(d.subarray(0, b.length));
|
|
636
|
-
for (let w = 1; w < r; w++) {
|
|
637
|
-
c._cloneInto(l).update(d).digestInto(d);
|
|
638
|
-
for (let H = 0; H < b.length; H++)
|
|
639
|
-
b[H] ^= d[H];
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return js(c, f, i, l, d);
|
|
643
|
-
}
|
|
644
|
-
const Ws = /* @__PURE__ */ Uint32Array.from([
|
|
645
|
-
1116352408,
|
|
646
|
-
1899447441,
|
|
647
|
-
3049323471,
|
|
648
|
-
3921009573,
|
|
649
|
-
961987163,
|
|
650
|
-
1508970993,
|
|
651
|
-
2453635748,
|
|
652
|
-
2870763221,
|
|
653
|
-
3624381080,
|
|
654
|
-
310598401,
|
|
655
|
-
607225278,
|
|
656
|
-
1426881987,
|
|
657
|
-
1925078388,
|
|
658
|
-
2162078206,
|
|
659
|
-
2614888103,
|
|
660
|
-
3248222580,
|
|
661
|
-
3835390401,
|
|
662
|
-
4022224774,
|
|
663
|
-
264347078,
|
|
664
|
-
604807628,
|
|
665
|
-
770255983,
|
|
666
|
-
1249150122,
|
|
667
|
-
1555081692,
|
|
668
|
-
1996064986,
|
|
669
|
-
2554220882,
|
|
670
|
-
2821834349,
|
|
671
|
-
2952996808,
|
|
672
|
-
3210313671,
|
|
673
|
-
3336571891,
|
|
674
|
-
3584528711,
|
|
675
|
-
113926993,
|
|
676
|
-
338241895,
|
|
677
|
-
666307205,
|
|
678
|
-
773529912,
|
|
679
|
-
1294757372,
|
|
680
|
-
1396182291,
|
|
681
|
-
1695183700,
|
|
682
|
-
1986661051,
|
|
683
|
-
2177026350,
|
|
684
|
-
2456956037,
|
|
685
|
-
2730485921,
|
|
686
|
-
2820302411,
|
|
687
|
-
3259730800,
|
|
688
|
-
3345764771,
|
|
689
|
-
3516065817,
|
|
690
|
-
3600352804,
|
|
691
|
-
4094571909,
|
|
692
|
-
275423344,
|
|
693
|
-
430227734,
|
|
694
|
-
506948616,
|
|
695
|
-
659060556,
|
|
696
|
-
883997877,
|
|
697
|
-
958139571,
|
|
698
|
-
1322822218,
|
|
699
|
-
1537002063,
|
|
700
|
-
1747873779,
|
|
701
|
-
1955562222,
|
|
702
|
-
2024104815,
|
|
703
|
-
2227730452,
|
|
704
|
-
2361852424,
|
|
705
|
-
2428436474,
|
|
706
|
-
2756734187,
|
|
707
|
-
3204031479,
|
|
708
|
-
3329325298
|
|
709
|
-
]), Bt = /* @__PURE__ */ new Uint32Array(64);
|
|
710
|
-
let Fs = class extends Zn {
|
|
711
|
-
constructor(t = 32) {
|
|
712
|
-
super(64, t, 8, !1), this.A = yt[0] | 0, this.B = yt[1] | 0, this.C = yt[2] | 0, this.D = yt[3] | 0, this.E = yt[4] | 0, this.F = yt[5] | 0, this.G = yt[6] | 0, this.H = yt[7] | 0;
|
|
713
|
-
}
|
|
714
|
-
get() {
|
|
715
|
-
const { A: t, B: n, C: s, D: r, E: o, F: i, G: c, H: f } = this;
|
|
716
|
-
return [t, n, s, r, o, i, c, f];
|
|
717
|
-
}
|
|
718
|
-
// prettier-ignore
|
|
719
|
-
set(t, n, s, r, o, i, c, f) {
|
|
720
|
-
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D = r | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
|
|
721
|
-
}
|
|
722
|
-
process(t, n) {
|
|
723
|
-
for (let a = 0; a < 16; a++, n += 4)
|
|
724
|
-
Bt[a] = t.getUint32(n, !1);
|
|
725
|
-
for (let a = 16; a < 64; a++) {
|
|
726
|
-
const d = Bt[a - 15], u = Bt[a - 2], y = ct(d, 7) ^ ct(d, 18) ^ d >>> 3, b = ct(u, 17) ^ ct(u, 19) ^ u >>> 10;
|
|
727
|
-
Bt[a] = b + Bt[a - 7] + y + Bt[a - 16] | 0;
|
|
728
|
-
}
|
|
729
|
-
let { A: s, B: r, C: o, D: i, E: c, F: f, G: l, H: h } = this;
|
|
730
|
-
for (let a = 0; a < 64; a++) {
|
|
731
|
-
const d = ct(c, 6) ^ ct(c, 11) ^ ct(c, 25), u = h + d + Ls(c, f, l) + Ws[a] + Bt[a] | 0, b = (ct(s, 2) ^ ct(s, 13) ^ ct(s, 22)) + Ds(s, r, o) | 0;
|
|
732
|
-
h = l, l = f, f = c, c = i + u | 0, i = o, o = r, r = s, s = u + b | 0;
|
|
733
|
-
}
|
|
734
|
-
s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, c, f, l, h);
|
|
735
|
-
}
|
|
736
|
-
roundClean() {
|
|
737
|
-
it(Bt);
|
|
738
|
-
}
|
|
739
|
-
destroy() {
|
|
740
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0), it(this.buffer);
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
const Kn = Cs([
|
|
744
|
-
"0x428a2f98d728ae22",
|
|
745
|
-
"0x7137449123ef65cd",
|
|
746
|
-
"0xb5c0fbcfec4d3b2f",
|
|
747
|
-
"0xe9b5dba58189dbbc",
|
|
748
|
-
"0x3956c25bf348b538",
|
|
749
|
-
"0x59f111f1b605d019",
|
|
750
|
-
"0x923f82a4af194f9b",
|
|
751
|
-
"0xab1c5ed5da6d8118",
|
|
752
|
-
"0xd807aa98a3030242",
|
|
753
|
-
"0x12835b0145706fbe",
|
|
754
|
-
"0x243185be4ee4b28c",
|
|
755
|
-
"0x550c7dc3d5ffb4e2",
|
|
756
|
-
"0x72be5d74f27b896f",
|
|
757
|
-
"0x80deb1fe3b1696b1",
|
|
758
|
-
"0x9bdc06a725c71235",
|
|
759
|
-
"0xc19bf174cf692694",
|
|
760
|
-
"0xe49b69c19ef14ad2",
|
|
761
|
-
"0xefbe4786384f25e3",
|
|
762
|
-
"0x0fc19dc68b8cd5b5",
|
|
763
|
-
"0x240ca1cc77ac9c65",
|
|
764
|
-
"0x2de92c6f592b0275",
|
|
765
|
-
"0x4a7484aa6ea6e483",
|
|
766
|
-
"0x5cb0a9dcbd41fbd4",
|
|
767
|
-
"0x76f988da831153b5",
|
|
768
|
-
"0x983e5152ee66dfab",
|
|
769
|
-
"0xa831c66d2db43210",
|
|
770
|
-
"0xb00327c898fb213f",
|
|
771
|
-
"0xbf597fc7beef0ee4",
|
|
772
|
-
"0xc6e00bf33da88fc2",
|
|
773
|
-
"0xd5a79147930aa725",
|
|
774
|
-
"0x06ca6351e003826f",
|
|
775
|
-
"0x142929670a0e6e70",
|
|
776
|
-
"0x27b70a8546d22ffc",
|
|
777
|
-
"0x2e1b21385c26c926",
|
|
778
|
-
"0x4d2c6dfc5ac42aed",
|
|
779
|
-
"0x53380d139d95b3df",
|
|
780
|
-
"0x650a73548baf63de",
|
|
781
|
-
"0x766a0abb3c77b2a8",
|
|
782
|
-
"0x81c2c92e47edaee6",
|
|
783
|
-
"0x92722c851482353b",
|
|
784
|
-
"0xa2bfe8a14cf10364",
|
|
785
|
-
"0xa81a664bbc423001",
|
|
786
|
-
"0xc24b8b70d0f89791",
|
|
787
|
-
"0xc76c51a30654be30",
|
|
788
|
-
"0xd192e819d6ef5218",
|
|
789
|
-
"0xd69906245565a910",
|
|
790
|
-
"0xf40e35855771202a",
|
|
791
|
-
"0x106aa07032bbd1b8",
|
|
792
|
-
"0x19a4c116b8d2d0c8",
|
|
793
|
-
"0x1e376c085141ab53",
|
|
794
|
-
"0x2748774cdf8eeb99",
|
|
795
|
-
"0x34b0bcb5e19b48a8",
|
|
796
|
-
"0x391c0cb3c5c95a63",
|
|
797
|
-
"0x4ed8aa4ae3418acb",
|
|
798
|
-
"0x5b9cca4f7763e373",
|
|
799
|
-
"0x682e6ff3d6b2b8a3",
|
|
800
|
-
"0x748f82ee5defb2fc",
|
|
801
|
-
"0x78a5636f43172f60",
|
|
802
|
-
"0x84c87814a1f0ab72",
|
|
803
|
-
"0x8cc702081a6439ec",
|
|
804
|
-
"0x90befffa23631e28",
|
|
805
|
-
"0xa4506cebde82bde9",
|
|
806
|
-
"0xbef9a3f7b2c67915",
|
|
807
|
-
"0xc67178f2e372532b",
|
|
808
|
-
"0xca273eceea26619c",
|
|
809
|
-
"0xd186b8c721c0c207",
|
|
810
|
-
"0xeada7dd6cde0eb1e",
|
|
811
|
-
"0xf57d4f7fee6ed178",
|
|
812
|
-
"0x06f067aa72176fba",
|
|
813
|
-
"0x0a637dc5a2c898a6",
|
|
814
|
-
"0x113f9804bef90dae",
|
|
815
|
-
"0x1b710b35131c471b",
|
|
816
|
-
"0x28db77f523047d84",
|
|
817
|
-
"0x32caab7b40c72493",
|
|
818
|
-
"0x3c9ebe0a15c9bebc",
|
|
819
|
-
"0x431d67c49c100d4c",
|
|
820
|
-
"0x4cc5d4becb3e42b6",
|
|
821
|
-
"0x597f299cfc657e2a",
|
|
822
|
-
"0x5fcb6fab3ad6faec",
|
|
823
|
-
"0x6c44198c4a475817"
|
|
824
|
-
].map((e) => BigInt(e))), Ks = Kn[0], Ys = Kn[1], At = /* @__PURE__ */ new Uint32Array(80), Et = /* @__PURE__ */ new Uint32Array(80);
|
|
825
|
-
let Xs = class extends Zn {
|
|
826
|
-
constructor(t = 64) {
|
|
827
|
-
super(128, t, 16, !1), this.Ah = X[0] | 0, this.Al = X[1] | 0, this.Bh = X[2] | 0, this.Bl = X[3] | 0, this.Ch = X[4] | 0, this.Cl = X[5] | 0, this.Dh = X[6] | 0, this.Dl = X[7] | 0, this.Eh = X[8] | 0, this.El = X[9] | 0, this.Fh = X[10] | 0, this.Fl = X[11] | 0, this.Gh = X[12] | 0, this.Gl = X[13] | 0, this.Hh = X[14] | 0, this.Hl = X[15] | 0;
|
|
828
|
-
}
|
|
829
|
-
// prettier-ignore
|
|
830
|
-
get() {
|
|
831
|
-
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: c, Dl: f, Eh: l, El: h, Fh: a, Fl: d, Gh: u, Gl: y, Hh: b, Hl: w } = this;
|
|
832
|
-
return [t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w];
|
|
833
|
-
}
|
|
834
|
-
// prettier-ignore
|
|
835
|
-
set(t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w) {
|
|
836
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = f | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = a | 0, this.Fl = d | 0, this.Gh = u | 0, this.Gl = y | 0, this.Hh = b | 0, this.Hl = w | 0;
|
|
837
|
-
}
|
|
838
|
-
process(t, n) {
|
|
839
|
-
for (let p = 0; p < 16; p++, n += 4)
|
|
840
|
-
At[p] = t.getUint32(n), Et[p] = t.getUint32(n += 4);
|
|
841
|
-
for (let p = 16; p < 80; p++) {
|
|
842
|
-
const D = At[p - 15] | 0, m = Et[p - 15] | 0, $ = Ct(D, m, 1) ^ Ct(D, m, 8) ^ dn(D, m, 7), C = kt(D, m, 1) ^ kt(D, m, 8) ^ un(D, m, 7), _ = At[p - 2] | 0, x = Et[p - 2] | 0, A = Ct(_, x, 19) ^ fe(_, x, 61) ^ dn(_, x, 6), g = kt(_, x, 19) ^ ae(_, x, 61) ^ un(_, x, 6), B = Ts(C, g, Et[p - 7], Et[p - 16]), E = Ns(B, $, A, At[p - 7], At[p - 16]);
|
|
843
|
-
At[p] = E | 0, Et[p] = B | 0;
|
|
844
|
-
}
|
|
845
|
-
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: c, Cl: f, Dh: l, Dl: h, Eh: a, El: d, Fh: u, Fl: y, Gh: b, Gl: w, Hh: H, Hl: v } = this;
|
|
846
|
-
for (let p = 0; p < 80; p++) {
|
|
847
|
-
const D = Ct(a, d, 14) ^ Ct(a, d, 18) ^ fe(a, d, 41), m = kt(a, d, 14) ^ kt(a, d, 18) ^ ae(a, d, 41), $ = a & u ^ ~a & b, C = d & y ^ ~d & w, _ = Rs(v, m, C, Ys[p], Et[p]), x = Gs(_, H, D, $, Ks[p], At[p]), A = _ | 0, g = Ct(s, r, 28) ^ fe(s, r, 34) ^ fe(s, r, 39), B = kt(s, r, 28) ^ ae(s, r, 34) ^ ae(s, r, 39), E = s & o ^ s & c ^ o & c, I = r & i ^ r & f ^ i & f;
|
|
848
|
-
H = b | 0, v = w | 0, b = u | 0, w = y | 0, u = a | 0, y = d | 0, { h: a, l: d } = rt(l | 0, h | 0, x | 0, A | 0), l = c | 0, h = f | 0, c = o | 0, f = i | 0, o = s | 0, i = r | 0;
|
|
849
|
-
const S = Qe(A, B, I);
|
|
850
|
-
s = Je(S, x, g, E), r = S | 0;
|
|
851
|
-
}
|
|
852
|
-
({ h: s, l: r } = rt(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = rt(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: c, l: f } = rt(this.Ch | 0, this.Cl | 0, c | 0, f | 0), { h: l, l: h } = rt(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: a, l: d } = rt(this.Eh | 0, this.El | 0, a | 0, d | 0), { h: u, l: y } = rt(this.Fh | 0, this.Fl | 0, u | 0, y | 0), { h: b, l: w } = rt(this.Gh | 0, this.Gl | 0, b | 0, w | 0), { h: H, l: v } = rt(this.Hh | 0, this.Hl | 0, H | 0, v | 0), this.set(s, r, o, i, c, f, l, h, a, d, u, y, b, w, H, v);
|
|
853
|
-
}
|
|
854
|
-
roundClean() {
|
|
855
|
-
it(At, Et);
|
|
856
|
-
}
|
|
857
|
-
destroy() {
|
|
858
|
-
it(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
const tn = /* @__PURE__ */ Vn(() => new Fs()), Ps = /* @__PURE__ */ Vn(() => new Xs());
|
|
862
|
-
function xn(e, t, n, s, r, o) {
|
|
863
|
-
let i = e[t++] ^ n[s++], c = e[t++] ^ n[s++], f = e[t++] ^ n[s++], l = e[t++] ^ n[s++], h = e[t++] ^ n[s++], a = e[t++] ^ n[s++], d = e[t++] ^ n[s++], u = e[t++] ^ n[s++], y = e[t++] ^ n[s++], b = e[t++] ^ n[s++], w = e[t++] ^ n[s++], H = e[t++] ^ n[s++], v = e[t++] ^ n[s++], p = e[t++] ^ n[s++], D = e[t++] ^ n[s++], m = e[t++] ^ n[s++], $ = i, C = c, _ = f, x = l, A = h, g = a, B = d, E = u, I = y, S = b, L = w, O = H, k = v, G = p, N = D, T = m;
|
|
864
|
-
for (let M = 0; M < 8; M += 2)
|
|
865
|
-
A ^= R($ + k | 0, 7), I ^= R(A + $ | 0, 9), k ^= R(I + A | 0, 13), $ ^= R(k + I | 0, 18), S ^= R(g + C | 0, 7), G ^= R(S + g | 0, 9), C ^= R(G + S | 0, 13), g ^= R(C + G | 0, 18), N ^= R(L + B | 0, 7), _ ^= R(N + L | 0, 9), B ^= R(_ + N | 0, 13), L ^= R(B + _ | 0, 18), x ^= R(T + O | 0, 7), E ^= R(x + T | 0, 9), O ^= R(E + x | 0, 13), T ^= R(O + E | 0, 18), C ^= R($ + x | 0, 7), _ ^= R(C + $ | 0, 9), x ^= R(_ + C | 0, 13), $ ^= R(x + _ | 0, 18), B ^= R(g + A | 0, 7), E ^= R(B + g | 0, 9), A ^= R(E + B | 0, 13), g ^= R(A + E | 0, 18), O ^= R(L + S | 0, 7), I ^= R(O + L | 0, 9), S ^= R(I + O | 0, 13), L ^= R(S + I | 0, 18), k ^= R(T + N | 0, 7), G ^= R(k + T | 0, 9), N ^= R(G + k | 0, 13), T ^= R(N + G | 0, 18);
|
|
866
|
-
r[o++] = i + $ | 0, r[o++] = c + C | 0, r[o++] = f + _ | 0, r[o++] = l + x | 0, r[o++] = h + A | 0, r[o++] = a + g | 0, r[o++] = d + B | 0, r[o++] = u + E | 0, r[o++] = y + I | 0, r[o++] = b + S | 0, r[o++] = w + L | 0, r[o++] = H + O | 0, r[o++] = v + k | 0, r[o++] = p + G | 0, r[o++] = D + N | 0, r[o++] = m + T | 0;
|
|
867
|
-
}
|
|
868
|
-
function Ce(e, t, n, s, r) {
|
|
869
|
-
let o = s + 0, i = s + 16 * r;
|
|
870
|
-
for (let c = 0; c < 16; c++)
|
|
871
|
-
n[i + c] = e[t + (2 * r - 1) * 16 + c];
|
|
872
|
-
for (let c = 0; c < r; c++, o += 16, t += 16)
|
|
873
|
-
xn(n, i, e, t, n, o), c > 0 && (i += 16), xn(n, o, e, t += 16, n, i);
|
|
874
|
-
}
|
|
875
|
-
function Qs(e, t, n) {
|
|
876
|
-
const s = Mn({
|
|
877
|
-
dkLen: 32,
|
|
878
|
-
asyncTick: 10,
|
|
879
|
-
maxmem: 1073742848
|
|
880
|
-
}, n), { N: r, r: o, p: i, dkLen: c, asyncTick: f, maxmem: l, onProgress: h } = s;
|
|
881
|
-
if (et(r), et(o), et(i), et(c), et(f), et(l), h !== void 0 && typeof h != "function")
|
|
882
|
-
throw new Error("progressCb should be function");
|
|
883
|
-
const a = 128 * o, d = a / 4, u = Math.pow(2, 32);
|
|
884
|
-
if (r <= 1 || (r & r - 1) !== 0 || r > u)
|
|
885
|
-
throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");
|
|
886
|
-
if (i < 0 || i > (u - 1) * 32 / a)
|
|
887
|
-
throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
|
|
888
|
-
if (c < 0 || c > (u - 1) * 32)
|
|
889
|
-
throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
|
|
890
|
-
if (a * (r + i) > l)
|
|
891
|
-
throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of " + l);
|
|
892
|
-
const b = Fn(tn, e, t, { c: 1, dkLen: a * i }), w = qt(b), H = qt(new Uint8Array(a * r)), v = qt(new Uint8Array(a));
|
|
893
|
-
let p = () => {
|
|
894
|
-
};
|
|
895
|
-
if (h) {
|
|
896
|
-
const D = 2 * r * i, m = Math.max(Math.floor(D / 1e4), 1);
|
|
897
|
-
let $ = 0;
|
|
898
|
-
p = () => {
|
|
899
|
-
$++, h && (!($ % m) || $ === D) && h($ / D);
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
return { N: r, r: o, p: i, dkLen: c, blockSize32: d, V: H, B32: w, B: b, tmp: v, blockMixCb: p, asyncTick: f };
|
|
903
|
-
}
|
|
904
|
-
function Js(e, t, n, s, r) {
|
|
905
|
-
const o = Fn(tn, e, n, { c: 1, dkLen: t });
|
|
906
|
-
return it(n, s, r), o;
|
|
907
|
-
}
|
|
908
|
-
function ai(e, t, n) {
|
|
909
|
-
const { N: s, r, p: o, dkLen: i, blockSize32: c, V: f, B32: l, B: h, tmp: a, blockMixCb: d } = Qs(e, t, n);
|
|
910
|
-
Dt(l);
|
|
911
|
-
for (let u = 0; u < o; u++) {
|
|
912
|
-
const y = c * u;
|
|
913
|
-
for (let b = 0; b < c; b++)
|
|
914
|
-
f[b] = l[y + b];
|
|
915
|
-
for (let b = 0, w = 0; b < s - 1; b++)
|
|
916
|
-
Ce(f, w, f, w += c, r), d();
|
|
917
|
-
Ce(f, (s - 1) * c, l, y, r), d();
|
|
918
|
-
for (let b = 0; b < s; b++) {
|
|
919
|
-
const w = l[y + c - 16] % s;
|
|
920
|
-
for (let H = 0; H < c; H++)
|
|
921
|
-
a[H] = l[y + H] ^ f[w * c + H];
|
|
922
|
-
Ce(a, 0, l, y, r), d();
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
return Dt(l), Js(e, i, h, f, a);
|
|
926
|
-
}
|
|
927
|
-
const Wt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
928
|
-
function en(e) {
|
|
929
|
-
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
930
|
-
}
|
|
931
|
-
function ze(e) {
|
|
932
|
-
if (!Number.isSafeInteger(e) || e < 0)
|
|
933
|
-
throw new Error("positive integer expected, got " + e);
|
|
934
|
-
}
|
|
935
|
-
function ot(e, ...t) {
|
|
936
|
-
if (!en(e))
|
|
937
|
-
throw new Error("Uint8Array expected");
|
|
938
|
-
if (t.length > 0 && !t.includes(e.length))
|
|
939
|
-
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
940
|
-
}
|
|
941
|
-
function t0(e) {
|
|
942
|
-
if (typeof e != "function" || typeof e.create != "function")
|
|
943
|
-
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
944
|
-
ze(e.outputLen), ze(e.blockLen);
|
|
945
|
-
}
|
|
946
|
-
function He(e, t = !0) {
|
|
947
|
-
if (e.destroyed)
|
|
948
|
-
throw new Error("Hash instance has been destroyed");
|
|
949
|
-
if (t && e.finished)
|
|
950
|
-
throw new Error("Hash#digest() has already been called");
|
|
951
|
-
}
|
|
952
|
-
function e0(e, t) {
|
|
953
|
-
ot(e);
|
|
954
|
-
const n = t.outputLen;
|
|
955
|
-
if (e.length < n)
|
|
956
|
-
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
957
|
-
}
|
|
958
|
-
function ee(...e) {
|
|
959
|
-
for (let t = 0; t < e.length; t++)
|
|
960
|
-
e[t].fill(0);
|
|
961
|
-
}
|
|
962
|
-
function ke(e) {
|
|
963
|
-
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
964
|
-
}
|
|
965
|
-
function ft(e, t) {
|
|
966
|
-
return e << 32 - t | e >>> t;
|
|
967
|
-
}
|
|
968
|
-
const Yn = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", n0 = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
969
|
-
function Mt(e) {
|
|
970
|
-
if (ot(e), Yn)
|
|
971
|
-
return e.toHex();
|
|
972
|
-
let t = "";
|
|
973
|
-
for (let n = 0; n < e.length; n++)
|
|
974
|
-
t += n0[e[n]];
|
|
975
|
-
return t;
|
|
976
|
-
}
|
|
977
|
-
const lt = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
978
|
-
function bn(e) {
|
|
979
|
-
if (e >= lt._0 && e <= lt._9)
|
|
980
|
-
return e - lt._0;
|
|
981
|
-
if (e >= lt.A && e <= lt.F)
|
|
982
|
-
return e - (lt.A - 10);
|
|
983
|
-
if (e >= lt.a && e <= lt.f)
|
|
984
|
-
return e - (lt.a - 10);
|
|
985
|
-
}
|
|
986
|
-
function nn(e) {
|
|
987
|
-
if (typeof e != "string")
|
|
988
|
-
throw new Error("hex string expected, got " + typeof e);
|
|
989
|
-
if (Yn)
|
|
990
|
-
return Uint8Array.fromHex(e);
|
|
991
|
-
const t = e.length, n = t / 2;
|
|
992
|
-
if (t % 2)
|
|
993
|
-
throw new Error("hex string expected, got unpadded hex of length " + t);
|
|
994
|
-
const s = new Uint8Array(n);
|
|
995
|
-
for (let r = 0, o = 0; r < n; r++, o += 2) {
|
|
996
|
-
const i = bn(e.charCodeAt(o)), c = bn(e.charCodeAt(o + 1));
|
|
997
|
-
if (i === void 0 || c === void 0) {
|
|
998
|
-
const f = e[o] + e[o + 1];
|
|
999
|
-
throw new Error('hex string expected, got non-hex character "' + f + '" at index ' + o);
|
|
1000
|
-
}
|
|
1001
|
-
s[r] = i * 16 + c;
|
|
1002
|
-
}
|
|
1003
|
-
return s;
|
|
1004
|
-
}
|
|
1005
|
-
function s0(e) {
|
|
1006
|
-
if (typeof e != "string")
|
|
1007
|
-
throw new Error("string expected");
|
|
1008
|
-
return new Uint8Array(new TextEncoder().encode(e));
|
|
1009
|
-
}
|
|
1010
|
-
function sn(e) {
|
|
1011
|
-
return typeof e == "string" && (e = s0(e)), ot(e), e;
|
|
1012
|
-
}
|
|
1013
|
-
function wt(...e) {
|
|
1014
|
-
let t = 0;
|
|
1015
|
-
for (let s = 0; s < e.length; s++) {
|
|
1016
|
-
const r = e[s];
|
|
1017
|
-
ot(r), t += r.length;
|
|
1018
|
-
}
|
|
1019
|
-
const n = new Uint8Array(t);
|
|
1020
|
-
for (let s = 0, r = 0; s < e.length; s++) {
|
|
1021
|
-
const o = e[s];
|
|
1022
|
-
n.set(o, r), r += o.length;
|
|
1023
|
-
}
|
|
1024
|
-
return n;
|
|
1025
|
-
}
|
|
1026
|
-
let Xn = class {
|
|
1027
|
-
};
|
|
1028
|
-
function Pn(e) {
|
|
1029
|
-
const t = (s) => e().update(sn(s)).digest(), n = e();
|
|
1030
|
-
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
1031
|
-
}
|
|
1032
|
-
function Qn(e = 32) {
|
|
1033
|
-
if (Wt && typeof Wt.getRandomValues == "function")
|
|
1034
|
-
return Wt.getRandomValues(new Uint8Array(e));
|
|
1035
|
-
if (Wt && typeof Wt.randomBytes == "function")
|
|
1036
|
-
return Uint8Array.from(Wt.randomBytes(e));
|
|
1037
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
1038
|
-
}
|
|
1039
|
-
const rn = /* @__PURE__ */ BigInt(0), je = /* @__PURE__ */ BigInt(1);
|
|
1040
|
-
function Vt(e, t) {
|
|
1041
|
-
if (typeof t != "boolean")
|
|
1042
|
-
throw new Error(e + " boolean expected, got " + t);
|
|
1043
|
-
}
|
|
1044
|
-
function be(e) {
|
|
1045
|
-
const t = e.toString(16);
|
|
1046
|
-
return t.length & 1 ? "0" + t : t;
|
|
1047
|
-
}
|
|
1048
|
-
function Jn(e) {
|
|
1049
|
-
if (typeof e != "string")
|
|
1050
|
-
throw new Error("hex string expected, got " + typeof e);
|
|
1051
|
-
return e === "" ? rn : BigInt("0x" + e);
|
|
1052
|
-
}
|
|
1053
|
-
function Ue(e) {
|
|
1054
|
-
return Jn(Mt(e));
|
|
1055
|
-
}
|
|
1056
|
-
function ne(e) {
|
|
1057
|
-
return ot(e), Jn(Mt(Uint8Array.from(e).reverse()));
|
|
1058
|
-
}
|
|
1059
|
-
function on(e, t) {
|
|
1060
|
-
return nn(e.toString(16).padStart(t * 2, "0"));
|
|
1061
|
-
}
|
|
1062
|
-
function se(e, t) {
|
|
1063
|
-
return on(e, t).reverse();
|
|
1064
|
-
}
|
|
1065
|
-
function V(e, t, n) {
|
|
1066
|
-
let s;
|
|
1067
|
-
if (typeof t == "string")
|
|
1068
|
-
try {
|
|
1069
|
-
s = nn(t);
|
|
1070
|
-
} catch (o) {
|
|
1071
|
-
throw new Error(e + " must be hex string or Uint8Array, cause: " + o);
|
|
1072
|
-
}
|
|
1073
|
-
else if (en(t))
|
|
1074
|
-
s = Uint8Array.from(t);
|
|
1075
|
-
else
|
|
1076
|
-
throw new Error(e + " must be hex string or Uint8Array");
|
|
1077
|
-
const r = s.length;
|
|
1078
|
-
if (typeof n == "number" && r !== n)
|
|
1079
|
-
throw new Error(e + " of length " + n + " expected, got " + r);
|
|
1080
|
-
return s;
|
|
1081
|
-
}
|
|
1082
|
-
function r0(e, t) {
|
|
1083
|
-
if (e.length !== t.length)
|
|
1084
|
-
return !1;
|
|
1085
|
-
let n = 0;
|
|
1086
|
-
for (let s = 0; s < e.length; s++)
|
|
1087
|
-
n |= e[s] ^ t[s];
|
|
1088
|
-
return n === 0;
|
|
1089
|
-
}
|
|
1090
|
-
const Oe = (e) => typeof e == "bigint" && rn <= e;
|
|
1091
|
-
function i0(e, t, n) {
|
|
1092
|
-
return Oe(e) && Oe(t) && Oe(n) && t <= e && e < n;
|
|
1093
|
-
}
|
|
1094
|
-
function Jt(e, t, n, s) {
|
|
1095
|
-
if (!i0(t, n, s))
|
|
1096
|
-
throw new Error("expected valid " + e + ": " + n + " <= n < " + s + ", got " + t);
|
|
1097
|
-
}
|
|
1098
|
-
function o0(e) {
|
|
1099
|
-
let t;
|
|
1100
|
-
for (t = 0; e > rn; e >>= je, t += 1)
|
|
1101
|
-
;
|
|
1102
|
-
return t;
|
|
1103
|
-
}
|
|
1104
|
-
const ve = (e) => (je << BigInt(e)) - je;
|
|
1105
|
-
function c0(e, t, n) {
|
|
1106
|
-
if (typeof e != "number" || e < 2)
|
|
1107
|
-
throw new Error("hashLen must be a number");
|
|
1108
|
-
if (typeof t != "number" || t < 2)
|
|
1109
|
-
throw new Error("qByteLen must be a number");
|
|
1110
|
-
if (typeof n != "function")
|
|
1111
|
-
throw new Error("hmacFn must be a function");
|
|
1112
|
-
const s = (u) => new Uint8Array(u), r = (u) => Uint8Array.of(u);
|
|
1113
|
-
let o = s(e), i = s(e), c = 0;
|
|
1114
|
-
const f = () => {
|
|
1115
|
-
o.fill(1), i.fill(0), c = 0;
|
|
1116
|
-
}, l = (...u) => n(i, o, ...u), h = (u = s(0)) => {
|
|
1117
|
-
i = l(r(0), u), o = l(), u.length !== 0 && (i = l(r(1), u), o = l());
|
|
1118
|
-
}, a = () => {
|
|
1119
|
-
if (c++ >= 1e3)
|
|
1120
|
-
throw new Error("drbg: tried 1000 values");
|
|
1121
|
-
let u = 0;
|
|
1122
|
-
const y = [];
|
|
1123
|
-
for (; u < t; ) {
|
|
1124
|
-
o = l();
|
|
1125
|
-
const b = o.slice();
|
|
1126
|
-
y.push(b), u += o.length;
|
|
1127
|
-
}
|
|
1128
|
-
return wt(...y);
|
|
1129
|
-
};
|
|
1130
|
-
return (u, y) => {
|
|
1131
|
-
f(), h(u);
|
|
1132
|
-
let b;
|
|
1133
|
-
for (; !(b = y(a())); )
|
|
1134
|
-
h();
|
|
1135
|
-
return f(), b;
|
|
1136
|
-
};
|
|
1137
|
-
}
|
|
1138
|
-
function ue(e, t, n = {}) {
|
|
1139
|
-
if (!e || typeof e != "object")
|
|
1140
|
-
throw new Error("expected valid options object");
|
|
1141
|
-
function s(r, o, i) {
|
|
1142
|
-
const c = e[r];
|
|
1143
|
-
if (i && c === void 0)
|
|
1144
|
-
return;
|
|
1145
|
-
const f = typeof c;
|
|
1146
|
-
if (f !== o || c === null)
|
|
1147
|
-
throw new Error(`param "${r}" is invalid: expected ${o}, got ${f}`);
|
|
1148
|
-
}
|
|
1149
|
-
Object.entries(t).forEach(([r, o]) => s(r, o, !1)), Object.entries(n).forEach(([r, o]) => s(r, o, !0));
|
|
1150
|
-
}
|
|
1151
|
-
function _e(e) {
|
|
1152
|
-
const t = /* @__PURE__ */ new WeakMap();
|
|
1153
|
-
return (n, ...s) => {
|
|
1154
|
-
const r = t.get(n);
|
|
1155
|
-
if (r !== void 0)
|
|
1156
|
-
return r;
|
|
1157
|
-
const o = e(n, ...s);
|
|
1158
|
-
return t.set(n, o), o;
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
const nt = BigInt(0), K = BigInt(1), Rt = /* @__PURE__ */ BigInt(2), f0 = /* @__PURE__ */ BigInt(3), ts = /* @__PURE__ */ BigInt(4), es = /* @__PURE__ */ BigInt(5), ns = /* @__PURE__ */ BigInt(8);
|
|
1162
|
-
function z(e, t) {
|
|
1163
|
-
const n = e % t;
|
|
1164
|
-
return n >= nt ? n : t + n;
|
|
1165
|
-
}
|
|
1166
|
-
function Z(e, t, n) {
|
|
1167
|
-
let s = e;
|
|
1168
|
-
for (; t-- > nt; )
|
|
1169
|
-
s *= s, s %= n;
|
|
1170
|
-
return s;
|
|
1171
|
-
}
|
|
1172
|
-
function wn(e, t) {
|
|
1173
|
-
if (e === nt)
|
|
1174
|
-
throw new Error("invert: expected non-zero number");
|
|
1175
|
-
if (t <= nt)
|
|
1176
|
-
throw new Error("invert: expected positive modulus, got " + t);
|
|
1177
|
-
let n = z(e, t), s = t, r = nt, o = K;
|
|
1178
|
-
for (; n !== nt; ) {
|
|
1179
|
-
const c = s / n, f = s % n, l = r - o * c;
|
|
1180
|
-
s = n, n = f, r = o, o = l;
|
|
1181
|
-
}
|
|
1182
|
-
if (s !== K)
|
|
1183
|
-
throw new Error("invert: does not exist");
|
|
1184
|
-
return z(r, t);
|
|
1185
|
-
}
|
|
1186
|
-
function ss(e, t) {
|
|
1187
|
-
const n = (e.ORDER + K) / ts, s = e.pow(t, n);
|
|
1188
|
-
if (!e.eql(e.sqr(s), t))
|
|
1189
|
-
throw new Error("Cannot find square root");
|
|
1190
|
-
return s;
|
|
1191
|
-
}
|
|
1192
|
-
function a0(e, t) {
|
|
1193
|
-
const n = (e.ORDER - es) / ns, s = e.mul(t, Rt), r = e.pow(s, n), o = e.mul(t, r), i = e.mul(e.mul(o, Rt), r), c = e.mul(o, e.sub(i, e.ONE));
|
|
1194
|
-
if (!e.eql(e.sqr(c), t))
|
|
1195
|
-
throw new Error("Cannot find square root");
|
|
1196
|
-
return c;
|
|
1197
|
-
}
|
|
1198
|
-
function h0(e) {
|
|
1199
|
-
if (e < BigInt(3))
|
|
1200
|
-
throw new Error("sqrt is not defined for small field");
|
|
1201
|
-
let t = e - K, n = 0;
|
|
1202
|
-
for (; t % Rt === nt; )
|
|
1203
|
-
t /= Rt, n++;
|
|
1204
|
-
let s = Rt;
|
|
1205
|
-
const r = Zt(e);
|
|
1206
|
-
for (; gn(r, s) === 1; )
|
|
1207
|
-
if (s++ > 1e3)
|
|
1208
|
-
throw new Error("Cannot find square root: probably non-prime P");
|
|
1209
|
-
if (n === 1)
|
|
1210
|
-
return ss;
|
|
1211
|
-
let o = r.pow(s, t);
|
|
1212
|
-
const i = (t + K) / Rt;
|
|
1213
|
-
return function(f, l) {
|
|
1214
|
-
if (f.is0(l))
|
|
1215
|
-
return l;
|
|
1216
|
-
if (gn(f, l) !== 1)
|
|
1217
|
-
throw new Error("Cannot find square root");
|
|
1218
|
-
let h = n, a = f.mul(f.ONE, o), d = f.pow(l, t), u = f.pow(l, i);
|
|
1219
|
-
for (; !f.eql(d, f.ONE); ) {
|
|
1220
|
-
if (f.is0(d))
|
|
1221
|
-
return f.ZERO;
|
|
1222
|
-
let y = 1, b = f.sqr(d);
|
|
1223
|
-
for (; !f.eql(b, f.ONE); )
|
|
1224
|
-
if (y++, b = f.sqr(b), y === h)
|
|
1225
|
-
throw new Error("Cannot find square root");
|
|
1226
|
-
const w = K << BigInt(h - y - 1), H = f.pow(a, w);
|
|
1227
|
-
h = y, a = f.sqr(H), d = f.mul(d, a), u = f.mul(u, H);
|
|
1228
|
-
}
|
|
1229
|
-
return u;
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
function l0(e) {
|
|
1233
|
-
return e % ts === f0 ? ss : e % ns === es ? a0 : h0(e);
|
|
1234
|
-
}
|
|
1235
|
-
const Ot = (e, t) => (z(e, t) & K) === K, d0 = [
|
|
1236
|
-
"create",
|
|
1237
|
-
"isValid",
|
|
1238
|
-
"is0",
|
|
1239
|
-
"neg",
|
|
1240
|
-
"inv",
|
|
1241
|
-
"sqrt",
|
|
1242
|
-
"sqr",
|
|
1243
|
-
"eql",
|
|
1244
|
-
"add",
|
|
1245
|
-
"sub",
|
|
1246
|
-
"mul",
|
|
1247
|
-
"pow",
|
|
1248
|
-
"div",
|
|
1249
|
-
"addN",
|
|
1250
|
-
"subN",
|
|
1251
|
-
"mulN",
|
|
1252
|
-
"sqrN"
|
|
1253
|
-
];
|
|
1254
|
-
function u0(e) {
|
|
1255
|
-
const t = {
|
|
1256
|
-
ORDER: "bigint",
|
|
1257
|
-
MASK: "bigint",
|
|
1258
|
-
BYTES: "number",
|
|
1259
|
-
BITS: "number"
|
|
1260
|
-
}, n = d0.reduce((s, r) => (s[r] = "function", s), t);
|
|
1261
|
-
return ue(e, n), e;
|
|
1262
|
-
}
|
|
1263
|
-
function x0(e, t, n) {
|
|
1264
|
-
if (n < nt)
|
|
1265
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
1266
|
-
if (n === nt)
|
|
1267
|
-
return e.ONE;
|
|
1268
|
-
if (n === K)
|
|
1269
|
-
return t;
|
|
1270
|
-
let s = e.ONE, r = t;
|
|
1271
|
-
for (; n > nt; )
|
|
1272
|
-
n & K && (s = e.mul(s, r)), r = e.sqr(r), n >>= K;
|
|
1273
|
-
return s;
|
|
1274
|
-
}
|
|
1275
|
-
function rs(e, t, n = !1) {
|
|
1276
|
-
const s = new Array(t.length).fill(n ? e.ZERO : void 0), r = t.reduce((i, c, f) => e.is0(c) ? i : (s[f] = i, e.mul(i, c)), e.ONE), o = e.inv(r);
|
|
1277
|
-
return t.reduceRight((i, c, f) => e.is0(c) ? i : (s[f] = e.mul(i, s[f]), e.mul(i, c)), o), s;
|
|
1278
|
-
}
|
|
1279
|
-
function gn(e, t) {
|
|
1280
|
-
const n = (e.ORDER - K) / Rt, s = e.pow(t, n), r = e.eql(s, e.ONE), o = e.eql(s, e.ZERO), i = e.eql(s, e.neg(e.ONE));
|
|
1281
|
-
if (!r && !o && !i)
|
|
1282
|
-
throw new Error("invalid Legendre symbol result");
|
|
1283
|
-
return r ? 1 : o ? 0 : -1;
|
|
1284
|
-
}
|
|
1285
|
-
function b0(e, t) {
|
|
1286
|
-
t !== void 0 && ze(t);
|
|
1287
|
-
const n = t !== void 0 ? t : e.toString(2).length, s = Math.ceil(n / 8);
|
|
1288
|
-
return { nBitLength: n, nByteLength: s };
|
|
1289
|
-
}
|
|
1290
|
-
function Zt(e, t, n = !1, s = {}) {
|
|
1291
|
-
if (e <= nt)
|
|
1292
|
-
throw new Error("invalid field: expected ORDER > 0, got " + e);
|
|
1293
|
-
let r, o;
|
|
1294
|
-
if (typeof t == "object" && t != null) {
|
|
1295
|
-
if (s.sqrt || n)
|
|
1296
|
-
throw new Error("cannot specify opts in two arguments");
|
|
1297
|
-
const h = t;
|
|
1298
|
-
h.BITS && (r = h.BITS), h.sqrt && (o = h.sqrt), typeof h.isLE == "boolean" && (n = h.isLE);
|
|
1299
|
-
} else
|
|
1300
|
-
typeof t == "number" && (r = t), s.sqrt && (o = s.sqrt);
|
|
1301
|
-
const { nBitLength: i, nByteLength: c } = b0(e, r);
|
|
1302
|
-
if (c > 2048)
|
|
1303
|
-
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1304
|
-
let f;
|
|
1305
|
-
const l = Object.freeze({
|
|
1306
|
-
ORDER: e,
|
|
1307
|
-
isLE: n,
|
|
1308
|
-
BITS: i,
|
|
1309
|
-
BYTES: c,
|
|
1310
|
-
MASK: ve(i),
|
|
1311
|
-
ZERO: nt,
|
|
1312
|
-
ONE: K,
|
|
1313
|
-
create: (h) => z(h, e),
|
|
1314
|
-
isValid: (h) => {
|
|
1315
|
-
if (typeof h != "bigint")
|
|
1316
|
-
throw new Error("invalid field element: expected bigint, got " + typeof h);
|
|
1317
|
-
return nt <= h && h < e;
|
|
1318
|
-
},
|
|
1319
|
-
is0: (h) => h === nt,
|
|
1320
|
-
// is valid and invertible
|
|
1321
|
-
isValidNot0: (h) => !l.is0(h) && l.isValid(h),
|
|
1322
|
-
isOdd: (h) => (h & K) === K,
|
|
1323
|
-
neg: (h) => z(-h, e),
|
|
1324
|
-
eql: (h, a) => h === a,
|
|
1325
|
-
sqr: (h) => z(h * h, e),
|
|
1326
|
-
add: (h, a) => z(h + a, e),
|
|
1327
|
-
sub: (h, a) => z(h - a, e),
|
|
1328
|
-
mul: (h, a) => z(h * a, e),
|
|
1329
|
-
pow: (h, a) => x0(l, h, a),
|
|
1330
|
-
div: (h, a) => z(h * wn(a, e), e),
|
|
1331
|
-
// Same as above, but doesn't normalize
|
|
1332
|
-
sqrN: (h) => h * h,
|
|
1333
|
-
addN: (h, a) => h + a,
|
|
1334
|
-
subN: (h, a) => h - a,
|
|
1335
|
-
mulN: (h, a) => h * a,
|
|
1336
|
-
inv: (h) => wn(h, e),
|
|
1337
|
-
sqrt: o || ((h) => (f || (f = l0(e)), f(l, h))),
|
|
1338
|
-
toBytes: (h) => n ? se(h, c) : on(h, c),
|
|
1339
|
-
fromBytes: (h) => {
|
|
1340
|
-
if (h.length !== c)
|
|
1341
|
-
throw new Error("Field.fromBytes: expected " + c + " bytes, got " + h.length);
|
|
1342
|
-
return n ? ne(h) : Ue(h);
|
|
1343
|
-
},
|
|
1344
|
-
// TODO: we don't need it here, move out to separate fn
|
|
1345
|
-
invertBatch: (h) => rs(l, h),
|
|
1346
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
1347
|
-
// and it's unclear what to return in there.
|
|
1348
|
-
cmov: (h, a, d) => d ? a : h
|
|
1349
|
-
});
|
|
1350
|
-
return Object.freeze(l);
|
|
1351
|
-
}
|
|
1352
|
-
function is(e) {
|
|
1353
|
-
if (typeof e != "bigint")
|
|
1354
|
-
throw new Error("field order must be bigint");
|
|
1355
|
-
const t = e.toString(2).length;
|
|
1356
|
-
return Math.ceil(t / 8);
|
|
1357
|
-
}
|
|
1358
|
-
function os(e) {
|
|
1359
|
-
const t = is(e);
|
|
1360
|
-
return t + Math.ceil(t / 2);
|
|
1361
|
-
}
|
|
1362
|
-
function w0(e, t, n = !1) {
|
|
1363
|
-
const s = e.length, r = is(t), o = os(t);
|
|
1364
|
-
if (s < 16 || s < o || s > 1024)
|
|
1365
|
-
throw new Error("expected " + o + "-1024 bytes of input, got " + s);
|
|
1366
|
-
const i = n ? ne(e) : Ue(e), c = z(i, t - K) + K;
|
|
1367
|
-
return n ? se(c, r) : on(c, r);
|
|
1368
|
-
}
|
|
1369
|
-
function g0(e, t, n, s) {
|
|
1370
|
-
if (typeof e.setBigUint64 == "function")
|
|
1371
|
-
return e.setBigUint64(t, n, s);
|
|
1372
|
-
const r = BigInt(32), o = BigInt(4294967295), i = Number(n >> r & o), c = Number(n & o), f = s ? 4 : 0, l = s ? 0 : 4;
|
|
1373
|
-
e.setUint32(t + f, i, s), e.setUint32(t + l, c, s);
|
|
1374
|
-
}
|
|
1375
|
-
function y0(e, t, n) {
|
|
1376
|
-
return e & t ^ ~e & n;
|
|
1377
|
-
}
|
|
1378
|
-
function p0(e, t, n) {
|
|
1379
|
-
return e & t ^ e & n ^ t & n;
|
|
1380
|
-
}
|
|
1381
|
-
let cs = class extends Xn {
|
|
1382
|
-
constructor(t, n, s, r) {
|
|
1383
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = ke(this.buffer);
|
|
1384
|
-
}
|
|
1385
|
-
update(t) {
|
|
1386
|
-
He(this), t = sn(t), ot(t);
|
|
1387
|
-
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
1388
|
-
for (let i = 0; i < o; ) {
|
|
1389
|
-
const c = Math.min(r - this.pos, o - i);
|
|
1390
|
-
if (c === r) {
|
|
1391
|
-
const f = ke(t);
|
|
1392
|
-
for (; r <= o - i; i += r)
|
|
1393
|
-
this.process(f, i);
|
|
1394
|
-
continue;
|
|
1395
|
-
}
|
|
1396
|
-
s.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
1397
|
-
}
|
|
1398
|
-
return this.length += t.length, this.roundClean(), this;
|
|
1399
|
-
}
|
|
1400
|
-
digestInto(t) {
|
|
1401
|
-
He(this), e0(t, this), this.finished = !0;
|
|
1402
|
-
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
1403
|
-
let { pos: i } = this;
|
|
1404
|
-
n[i++] = 128, ee(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
1405
|
-
for (let a = i; a < r; a++)
|
|
1406
|
-
n[a] = 0;
|
|
1407
|
-
g0(s, r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
1408
|
-
const c = ke(t), f = this.outputLen;
|
|
1409
|
-
if (f % 4)
|
|
1410
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
1411
|
-
const l = f / 4, h = this.get();
|
|
1412
|
-
if (l > h.length)
|
|
1413
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
1414
|
-
for (let a = 0; a < l; a++)
|
|
1415
|
-
c.setUint32(4 * a, h[a], o);
|
|
1416
|
-
}
|
|
1417
|
-
digest() {
|
|
1418
|
-
const { buffer: t, outputLen: n } = this;
|
|
1419
|
-
this.digestInto(t);
|
|
1420
|
-
const s = t.slice(0, n);
|
|
1421
|
-
return this.destroy(), s;
|
|
1422
|
-
}
|
|
1423
|
-
_cloneInto(t) {
|
|
1424
|
-
t || (t = new this.constructor()), t.set(...this.get());
|
|
1425
|
-
const { blockLen: n, buffer: s, length: r, finished: o, destroyed: i, pos: c } = this;
|
|
1426
|
-
return t.destroyed = i, t.finished = o, t.length = r, t.pos = c, r % n && t.buffer.set(s), t;
|
|
1427
|
-
}
|
|
1428
|
-
clone() {
|
|
1429
|
-
return this._cloneInto();
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
const Ht = /* @__PURE__ */ Uint32Array.from([
|
|
1433
|
-
1779033703,
|
|
1434
|
-
3144134277,
|
|
1435
|
-
1013904242,
|
|
1436
|
-
2773480762,
|
|
1437
|
-
1359893119,
|
|
1438
|
-
2600822924,
|
|
1439
|
-
528734635,
|
|
1440
|
-
1541459225
|
|
1441
|
-
]);
|
|
1442
|
-
const P = /* @__PURE__ */ Uint32Array.from([
|
|
1443
|
-
1779033703,
|
|
1444
|
-
4089235720,
|
|
1445
|
-
3144134277,
|
|
1446
|
-
2227873595,
|
|
1447
|
-
1013904242,
|
|
1448
|
-
4271175723,
|
|
1449
|
-
2773480762,
|
|
1450
|
-
1595750129,
|
|
1451
|
-
1359893119,
|
|
1452
|
-
2917565137,
|
|
1453
|
-
2600822924,
|
|
1454
|
-
725511199,
|
|
1455
|
-
528734635,
|
|
1456
|
-
4215389547,
|
|
1457
|
-
1541459225,
|
|
1458
|
-
327033209
|
|
1459
|
-
]), we = /* @__PURE__ */ BigInt(2 ** 32 - 1), yn = /* @__PURE__ */ BigInt(32);
|
|
1460
|
-
function m0(e, t = !1) {
|
|
1461
|
-
return t ? { h: Number(e & we), l: Number(e >> yn & we) } : { h: Number(e >> yn & we) | 0, l: Number(e & we) | 0 };
|
|
1462
|
-
}
|
|
1463
|
-
function B0(e, t = !1) {
|
|
1464
|
-
const n = e.length;
|
|
1465
|
-
let s = new Uint32Array(n), r = new Uint32Array(n);
|
|
1466
|
-
for (let o = 0; o < n; o++) {
|
|
1467
|
-
const { h: i, l: c } = m0(e[o], t);
|
|
1468
|
-
[s[o], r[o]] = [i, c];
|
|
1469
|
-
}
|
|
1470
|
-
return [s, r];
|
|
1471
|
-
}
|
|
1472
|
-
const pn = (e, t, n) => e >>> n, mn = (e, t, n) => e << 32 - n | t >>> n, Ft = (e, t, n) => e >>> n | t << 32 - n, Kt = (e, t, n) => e << 32 - n | t >>> n, ge = (e, t, n) => e << 64 - n | t >>> n - 32, ye = (e, t, n) => e >>> n - 32 | t << 64 - n;
|
|
1473
|
-
function dt(e, t, n, s) {
|
|
1474
|
-
const r = (t >>> 0) + (s >>> 0);
|
|
1475
|
-
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
1476
|
-
}
|
|
1477
|
-
const A0 = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), E0 = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, H0 = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), _0 = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, S0 = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), I0 = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, U0 = /* @__PURE__ */ Uint32Array.from([
|
|
1478
|
-
1116352408,
|
|
1479
|
-
1899447441,
|
|
1480
|
-
3049323471,
|
|
1481
|
-
3921009573,
|
|
1482
|
-
961987163,
|
|
1483
|
-
1508970993,
|
|
1484
|
-
2453635748,
|
|
1485
|
-
2870763221,
|
|
1486
|
-
3624381080,
|
|
1487
|
-
310598401,
|
|
1488
|
-
607225278,
|
|
1489
|
-
1426881987,
|
|
1490
|
-
1925078388,
|
|
1491
|
-
2162078206,
|
|
1492
|
-
2614888103,
|
|
1493
|
-
3248222580,
|
|
1494
|
-
3835390401,
|
|
1495
|
-
4022224774,
|
|
1496
|
-
264347078,
|
|
1497
|
-
604807628,
|
|
1498
|
-
770255983,
|
|
1499
|
-
1249150122,
|
|
1500
|
-
1555081692,
|
|
1501
|
-
1996064986,
|
|
1502
|
-
2554220882,
|
|
1503
|
-
2821834349,
|
|
1504
|
-
2952996808,
|
|
1505
|
-
3210313671,
|
|
1506
|
-
3336571891,
|
|
1507
|
-
3584528711,
|
|
1508
|
-
113926993,
|
|
1509
|
-
338241895,
|
|
1510
|
-
666307205,
|
|
1511
|
-
773529912,
|
|
1512
|
-
1294757372,
|
|
1513
|
-
1396182291,
|
|
1514
|
-
1695183700,
|
|
1515
|
-
1986661051,
|
|
1516
|
-
2177026350,
|
|
1517
|
-
2456956037,
|
|
1518
|
-
2730485921,
|
|
1519
|
-
2820302411,
|
|
1520
|
-
3259730800,
|
|
1521
|
-
3345764771,
|
|
1522
|
-
3516065817,
|
|
1523
|
-
3600352804,
|
|
1524
|
-
4094571909,
|
|
1525
|
-
275423344,
|
|
1526
|
-
430227734,
|
|
1527
|
-
506948616,
|
|
1528
|
-
659060556,
|
|
1529
|
-
883997877,
|
|
1530
|
-
958139571,
|
|
1531
|
-
1322822218,
|
|
1532
|
-
1537002063,
|
|
1533
|
-
1747873779,
|
|
1534
|
-
1955562222,
|
|
1535
|
-
2024104815,
|
|
1536
|
-
2227730452,
|
|
1537
|
-
2361852424,
|
|
1538
|
-
2428436474,
|
|
1539
|
-
2756734187,
|
|
1540
|
-
3204031479,
|
|
1541
|
-
3329325298
|
|
1542
|
-
]), _t = /* @__PURE__ */ new Uint32Array(64);
|
|
1543
|
-
let v0 = class extends cs {
|
|
1544
|
-
constructor(t = 32) {
|
|
1545
|
-
super(64, t, 8, !1), this.A = Ht[0] | 0, this.B = Ht[1] | 0, this.C = Ht[2] | 0, this.D = Ht[3] | 0, this.E = Ht[4] | 0, this.F = Ht[5] | 0, this.G = Ht[6] | 0, this.H = Ht[7] | 0;
|
|
1546
|
-
}
|
|
1547
|
-
get() {
|
|
1548
|
-
const { A: t, B: n, C: s, D: r, E: o, F: i, G: c, H: f } = this;
|
|
1549
|
-
return [t, n, s, r, o, i, c, f];
|
|
1550
|
-
}
|
|
1551
|
-
// prettier-ignore
|
|
1552
|
-
set(t, n, s, r, o, i, c, f) {
|
|
1553
|
-
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D = r | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
|
|
1554
|
-
}
|
|
1555
|
-
process(t, n) {
|
|
1556
|
-
for (let a = 0; a < 16; a++, n += 4)
|
|
1557
|
-
_t[a] = t.getUint32(n, !1);
|
|
1558
|
-
for (let a = 16; a < 64; a++) {
|
|
1559
|
-
const d = _t[a - 15], u = _t[a - 2], y = ft(d, 7) ^ ft(d, 18) ^ d >>> 3, b = ft(u, 17) ^ ft(u, 19) ^ u >>> 10;
|
|
1560
|
-
_t[a] = b + _t[a - 7] + y + _t[a - 16] | 0;
|
|
1561
|
-
}
|
|
1562
|
-
let { A: s, B: r, C: o, D: i, E: c, F: f, G: l, H: h } = this;
|
|
1563
|
-
for (let a = 0; a < 64; a++) {
|
|
1564
|
-
const d = ft(c, 6) ^ ft(c, 11) ^ ft(c, 25), u = h + d + y0(c, f, l) + U0[a] + _t[a] | 0, b = (ft(s, 2) ^ ft(s, 13) ^ ft(s, 22)) + p0(s, r, o) | 0;
|
|
1565
|
-
h = l, l = f, f = c, c = i + u | 0, i = o, o = r, r = s, s = u + b | 0;
|
|
1566
|
-
}
|
|
1567
|
-
s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, c, f, l, h);
|
|
1568
|
-
}
|
|
1569
|
-
roundClean() {
|
|
1570
|
-
ee(_t);
|
|
1571
|
-
}
|
|
1572
|
-
destroy() {
|
|
1573
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0), ee(this.buffer);
|
|
1574
|
-
}
|
|
1575
|
-
};
|
|
1576
|
-
const fs = B0([
|
|
1577
|
-
"0x428a2f98d728ae22",
|
|
1578
|
-
"0x7137449123ef65cd",
|
|
1579
|
-
"0xb5c0fbcfec4d3b2f",
|
|
1580
|
-
"0xe9b5dba58189dbbc",
|
|
1581
|
-
"0x3956c25bf348b538",
|
|
1582
|
-
"0x59f111f1b605d019",
|
|
1583
|
-
"0x923f82a4af194f9b",
|
|
1584
|
-
"0xab1c5ed5da6d8118",
|
|
1585
|
-
"0xd807aa98a3030242",
|
|
1586
|
-
"0x12835b0145706fbe",
|
|
1587
|
-
"0x243185be4ee4b28c",
|
|
1588
|
-
"0x550c7dc3d5ffb4e2",
|
|
1589
|
-
"0x72be5d74f27b896f",
|
|
1590
|
-
"0x80deb1fe3b1696b1",
|
|
1591
|
-
"0x9bdc06a725c71235",
|
|
1592
|
-
"0xc19bf174cf692694",
|
|
1593
|
-
"0xe49b69c19ef14ad2",
|
|
1594
|
-
"0xefbe4786384f25e3",
|
|
1595
|
-
"0x0fc19dc68b8cd5b5",
|
|
1596
|
-
"0x240ca1cc77ac9c65",
|
|
1597
|
-
"0x2de92c6f592b0275",
|
|
1598
|
-
"0x4a7484aa6ea6e483",
|
|
1599
|
-
"0x5cb0a9dcbd41fbd4",
|
|
1600
|
-
"0x76f988da831153b5",
|
|
1601
|
-
"0x983e5152ee66dfab",
|
|
1602
|
-
"0xa831c66d2db43210",
|
|
1603
|
-
"0xb00327c898fb213f",
|
|
1604
|
-
"0xbf597fc7beef0ee4",
|
|
1605
|
-
"0xc6e00bf33da88fc2",
|
|
1606
|
-
"0xd5a79147930aa725",
|
|
1607
|
-
"0x06ca6351e003826f",
|
|
1608
|
-
"0x142929670a0e6e70",
|
|
1609
|
-
"0x27b70a8546d22ffc",
|
|
1610
|
-
"0x2e1b21385c26c926",
|
|
1611
|
-
"0x4d2c6dfc5ac42aed",
|
|
1612
|
-
"0x53380d139d95b3df",
|
|
1613
|
-
"0x650a73548baf63de",
|
|
1614
|
-
"0x766a0abb3c77b2a8",
|
|
1615
|
-
"0x81c2c92e47edaee6",
|
|
1616
|
-
"0x92722c851482353b",
|
|
1617
|
-
"0xa2bfe8a14cf10364",
|
|
1618
|
-
"0xa81a664bbc423001",
|
|
1619
|
-
"0xc24b8b70d0f89791",
|
|
1620
|
-
"0xc76c51a30654be30",
|
|
1621
|
-
"0xd192e819d6ef5218",
|
|
1622
|
-
"0xd69906245565a910",
|
|
1623
|
-
"0xf40e35855771202a",
|
|
1624
|
-
"0x106aa07032bbd1b8",
|
|
1625
|
-
"0x19a4c116b8d2d0c8",
|
|
1626
|
-
"0x1e376c085141ab53",
|
|
1627
|
-
"0x2748774cdf8eeb99",
|
|
1628
|
-
"0x34b0bcb5e19b48a8",
|
|
1629
|
-
"0x391c0cb3c5c95a63",
|
|
1630
|
-
"0x4ed8aa4ae3418acb",
|
|
1631
|
-
"0x5b9cca4f7763e373",
|
|
1632
|
-
"0x682e6ff3d6b2b8a3",
|
|
1633
|
-
"0x748f82ee5defb2fc",
|
|
1634
|
-
"0x78a5636f43172f60",
|
|
1635
|
-
"0x84c87814a1f0ab72",
|
|
1636
|
-
"0x8cc702081a6439ec",
|
|
1637
|
-
"0x90befffa23631e28",
|
|
1638
|
-
"0xa4506cebde82bde9",
|
|
1639
|
-
"0xbef9a3f7b2c67915",
|
|
1640
|
-
"0xc67178f2e372532b",
|
|
1641
|
-
"0xca273eceea26619c",
|
|
1642
|
-
"0xd186b8c721c0c207",
|
|
1643
|
-
"0xeada7dd6cde0eb1e",
|
|
1644
|
-
"0xf57d4f7fee6ed178",
|
|
1645
|
-
"0x06f067aa72176fba",
|
|
1646
|
-
"0x0a637dc5a2c898a6",
|
|
1647
|
-
"0x113f9804bef90dae",
|
|
1648
|
-
"0x1b710b35131c471b",
|
|
1649
|
-
"0x28db77f523047d84",
|
|
1650
|
-
"0x32caab7b40c72493",
|
|
1651
|
-
"0x3c9ebe0a15c9bebc",
|
|
1652
|
-
"0x431d67c49c100d4c",
|
|
1653
|
-
"0x4cc5d4becb3e42b6",
|
|
1654
|
-
"0x597f299cfc657e2a",
|
|
1655
|
-
"0x5fcb6fab3ad6faec",
|
|
1656
|
-
"0x6c44198c4a475817"
|
|
1657
|
-
].map((e) => BigInt(e))), $0 = fs[0], L0 = fs[1], St = /* @__PURE__ */ new Uint32Array(80), It = /* @__PURE__ */ new Uint32Array(80);
|
|
1658
|
-
let D0 = class extends cs {
|
|
1659
|
-
constructor(t = 64) {
|
|
1660
|
-
super(128, t, 16, !1), this.Ah = P[0] | 0, this.Al = P[1] | 0, this.Bh = P[2] | 0, this.Bl = P[3] | 0, this.Ch = P[4] | 0, this.Cl = P[5] | 0, this.Dh = P[6] | 0, this.Dl = P[7] | 0, this.Eh = P[8] | 0, this.El = P[9] | 0, this.Fh = P[10] | 0, this.Fl = P[11] | 0, this.Gh = P[12] | 0, this.Gl = P[13] | 0, this.Hh = P[14] | 0, this.Hl = P[15] | 0;
|
|
1661
|
-
}
|
|
1662
|
-
// prettier-ignore
|
|
1663
|
-
get() {
|
|
1664
|
-
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: c, Dl: f, Eh: l, El: h, Fh: a, Fl: d, Gh: u, Gl: y, Hh: b, Hl: w } = this;
|
|
1665
|
-
return [t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w];
|
|
1666
|
-
}
|
|
1667
|
-
// prettier-ignore
|
|
1668
|
-
set(t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w) {
|
|
1669
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = f | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = a | 0, this.Fl = d | 0, this.Gh = u | 0, this.Gl = y | 0, this.Hh = b | 0, this.Hl = w | 0;
|
|
1670
|
-
}
|
|
1671
|
-
process(t, n) {
|
|
1672
|
-
for (let p = 0; p < 16; p++, n += 4)
|
|
1673
|
-
St[p] = t.getUint32(n), It[p] = t.getUint32(n += 4);
|
|
1674
|
-
for (let p = 16; p < 80; p++) {
|
|
1675
|
-
const D = St[p - 15] | 0, m = It[p - 15] | 0, $ = Ft(D, m, 1) ^ Ft(D, m, 8) ^ pn(D, m, 7), C = Kt(D, m, 1) ^ Kt(D, m, 8) ^ mn(D, m, 7), _ = St[p - 2] | 0, x = It[p - 2] | 0, A = Ft(_, x, 19) ^ ge(_, x, 61) ^ pn(_, x, 6), g = Kt(_, x, 19) ^ ye(_, x, 61) ^ mn(_, x, 6), B = H0(C, g, It[p - 7], It[p - 16]), E = _0(B, $, A, St[p - 7], St[p - 16]);
|
|
1676
|
-
St[p] = E | 0, It[p] = B | 0;
|
|
1677
|
-
}
|
|
1678
|
-
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: c, Cl: f, Dh: l, Dl: h, Eh: a, El: d, Fh: u, Fl: y, Gh: b, Gl: w, Hh: H, Hl: v } = this;
|
|
1679
|
-
for (let p = 0; p < 80; p++) {
|
|
1680
|
-
const D = Ft(a, d, 14) ^ Ft(a, d, 18) ^ ge(a, d, 41), m = Kt(a, d, 14) ^ Kt(a, d, 18) ^ ye(a, d, 41), $ = a & u ^ ~a & b, C = d & y ^ ~d & w, _ = S0(v, m, C, L0[p], It[p]), x = I0(_, H, D, $, $0[p], St[p]), A = _ | 0, g = Ft(s, r, 28) ^ ge(s, r, 34) ^ ge(s, r, 39), B = Kt(s, r, 28) ^ ye(s, r, 34) ^ ye(s, r, 39), E = s & o ^ s & c ^ o & c, I = r & i ^ r & f ^ i & f;
|
|
1681
|
-
H = b | 0, v = w | 0, b = u | 0, w = y | 0, u = a | 0, y = d | 0, { h: a, l: d } = dt(l | 0, h | 0, x | 0, A | 0), l = c | 0, h = f | 0, c = o | 0, f = i | 0, o = s | 0, i = r | 0;
|
|
1682
|
-
const S = A0(A, B, I);
|
|
1683
|
-
s = E0(S, x, g, E), r = S | 0;
|
|
1684
|
-
}
|
|
1685
|
-
({ h: s, l: r } = dt(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = dt(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: c, l: f } = dt(this.Ch | 0, this.Cl | 0, c | 0, f | 0), { h: l, l: h } = dt(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: a, l: d } = dt(this.Eh | 0, this.El | 0, a | 0, d | 0), { h: u, l: y } = dt(this.Fh | 0, this.Fl | 0, u | 0, y | 0), { h: b, l: w } = dt(this.Gh | 0, this.Gl | 0, b | 0, w | 0), { h: H, l: v } = dt(this.Hh | 0, this.Hl | 0, H | 0, v | 0), this.set(s, r, o, i, c, f, l, h, a, d, u, y, b, w, H, v);
|
|
1686
|
-
}
|
|
1687
|
-
roundClean() {
|
|
1688
|
-
ee(St, It);
|
|
1689
|
-
}
|
|
1690
|
-
destroy() {
|
|
1691
|
-
ee(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
const C0 = /* @__PURE__ */ Pn(() => new v0()), k0 = /* @__PURE__ */ Pn(() => new D0());
|
|
1695
|
-
const re = BigInt(0), Gt = BigInt(1);
|
|
1696
|
-
function he(e, t) {
|
|
1697
|
-
const n = t.negate();
|
|
1698
|
-
return e ? n : t;
|
|
1699
|
-
}
|
|
1700
|
-
function as(e, t, n) {
|
|
1701
|
-
const s = t === "pz" ? (i) => i.pz : (i) => i.ez, r = rs(e.Fp, n.map(s));
|
|
1702
|
-
return n.map((i, c) => i.toAffine(r[c])).map(e.fromAffine);
|
|
1703
|
-
}
|
|
1704
|
-
function hs(e, t) {
|
|
1705
|
-
if (!Number.isSafeInteger(e) || e <= 0 || e > t)
|
|
1706
|
-
throw new Error("invalid window size, expected [1.." + t + "], got W=" + e);
|
|
1707
|
-
}
|
|
1708
|
-
function Te(e, t) {
|
|
1709
|
-
hs(e, t);
|
|
1710
|
-
const n = Math.ceil(t / e) + 1, s = 2 ** (e - 1), r = 2 ** e, o = ve(e), i = BigInt(e);
|
|
1711
|
-
return { windows: n, windowSize: s, mask: o, maxNumber: r, shiftBy: i };
|
|
1712
|
-
}
|
|
1713
|
-
function Bn(e, t, n) {
|
|
1714
|
-
const { windowSize: s, mask: r, maxNumber: o, shiftBy: i } = n;
|
|
1715
|
-
let c = Number(e & r), f = e >> i;
|
|
1716
|
-
c > s && (c -= o, f += Gt);
|
|
1717
|
-
const l = t * s, h = l + Math.abs(c) - 1, a = c === 0, d = c < 0, u = t % 2 !== 0;
|
|
1718
|
-
return { nextN: f, offset: h, isZero: a, isNeg: d, isNegF: u, offsetF: l };
|
|
1719
|
-
}
|
|
1720
|
-
function O0(e, t) {
|
|
1721
|
-
if (!Array.isArray(e))
|
|
1722
|
-
throw new Error("array expected");
|
|
1723
|
-
e.forEach((n, s) => {
|
|
1724
|
-
if (!(n instanceof t))
|
|
1725
|
-
throw new Error("invalid point at index " + s);
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
function T0(e, t) {
|
|
1729
|
-
if (!Array.isArray(e))
|
|
1730
|
-
throw new Error("array of scalars expected");
|
|
1731
|
-
e.forEach((n, s) => {
|
|
1732
|
-
if (!t.isValid(n))
|
|
1733
|
-
throw new Error("invalid scalar at index " + s);
|
|
1734
|
-
});
|
|
1735
|
-
}
|
|
1736
|
-
const Ne = /* @__PURE__ */ new WeakMap(), ls = /* @__PURE__ */ new WeakMap();
|
|
1737
|
-
function Re(e) {
|
|
1738
|
-
return ls.get(e) || 1;
|
|
1739
|
-
}
|
|
1740
|
-
function An(e) {
|
|
1741
|
-
if (e !== re)
|
|
1742
|
-
throw new Error("invalid wNAF");
|
|
1743
|
-
}
|
|
1744
|
-
function ds(e, t) {
|
|
1745
|
-
return {
|
|
1746
|
-
constTimeNegate: he,
|
|
1747
|
-
hasPrecomputes(n) {
|
|
1748
|
-
return Re(n) !== 1;
|
|
1749
|
-
},
|
|
1750
|
-
// non-const time multiplication ladder
|
|
1751
|
-
unsafeLadder(n, s, r = e.ZERO) {
|
|
1752
|
-
let o = n;
|
|
1753
|
-
for (; s > re; )
|
|
1754
|
-
s & Gt && (r = r.add(o)), o = o.double(), s >>= Gt;
|
|
1755
|
-
return r;
|
|
1756
|
-
},
|
|
1757
|
-
/**
|
|
1758
|
-
* Creates a wNAF precomputation window. Used for caching.
|
|
1759
|
-
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1760
|
-
* Number of precomputed points depends on the curve size:
|
|
1761
|
-
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1762
|
-
* - 𝑊 is the window size
|
|
1763
|
-
* - 𝑛 is the bitlength of the curve order.
|
|
1764
|
-
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1765
|
-
* @param elm Point instance
|
|
1766
|
-
* @param W window size
|
|
1767
|
-
* @returns precomputed point tables flattened to a single array
|
|
1768
|
-
*/
|
|
1769
|
-
precomputeWindow(n, s) {
|
|
1770
|
-
const { windows: r, windowSize: o } = Te(s, t), i = [];
|
|
1771
|
-
let c = n, f = c;
|
|
1772
|
-
for (let l = 0; l < r; l++) {
|
|
1773
|
-
f = c, i.push(f);
|
|
1774
|
-
for (let h = 1; h < o; h++)
|
|
1775
|
-
f = f.add(c), i.push(f);
|
|
1776
|
-
c = f.double();
|
|
1777
|
-
}
|
|
1778
|
-
return i;
|
|
1779
|
-
},
|
|
1780
|
-
/**
|
|
1781
|
-
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1782
|
-
* @param W window size
|
|
1783
|
-
* @param precomputes precomputed tables
|
|
1784
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
1785
|
-
* @returns real and fake (for const-time) points
|
|
1786
|
-
*/
|
|
1787
|
-
wNAF(n, s, r) {
|
|
1788
|
-
let o = e.ZERO, i = e.BASE;
|
|
1789
|
-
const c = Te(n, t);
|
|
1790
|
-
for (let f = 0; f < c.windows; f++) {
|
|
1791
|
-
const { nextN: l, offset: h, isZero: a, isNeg: d, isNegF: u, offsetF: y } = Bn(r, f, c);
|
|
1792
|
-
r = l, a ? i = i.add(he(u, s[y])) : o = o.add(he(d, s[h]));
|
|
1793
|
-
}
|
|
1794
|
-
return An(r), { p: o, f: i };
|
|
1795
|
-
},
|
|
1796
|
-
/**
|
|
1797
|
-
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1798
|
-
* @param W window size
|
|
1799
|
-
* @param precomputes precomputed tables
|
|
1800
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
1801
|
-
* @param acc accumulator point to add result of multiplication
|
|
1802
|
-
* @returns point
|
|
1803
|
-
*/
|
|
1804
|
-
wNAFUnsafe(n, s, r, o = e.ZERO) {
|
|
1805
|
-
const i = Te(n, t);
|
|
1806
|
-
for (let c = 0; c < i.windows && r !== re; c++) {
|
|
1807
|
-
const { nextN: f, offset: l, isZero: h, isNeg: a } = Bn(r, c, i);
|
|
1808
|
-
if (r = f, !h) {
|
|
1809
|
-
const d = s[l];
|
|
1810
|
-
o = o.add(a ? d.negate() : d);
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
return An(r), o;
|
|
1814
|
-
},
|
|
1815
|
-
getPrecomputes(n, s, r) {
|
|
1816
|
-
let o = Ne.get(s);
|
|
1817
|
-
return o || (o = this.precomputeWindow(s, n), n !== 1 && (typeof r == "function" && (o = r(o)), Ne.set(s, o))), o;
|
|
1818
|
-
},
|
|
1819
|
-
wNAFCached(n, s, r) {
|
|
1820
|
-
const o = Re(n);
|
|
1821
|
-
return this.wNAF(o, this.getPrecomputes(o, n, r), s);
|
|
1822
|
-
},
|
|
1823
|
-
wNAFCachedUnsafe(n, s, r, o) {
|
|
1824
|
-
const i = Re(n);
|
|
1825
|
-
return i === 1 ? this.unsafeLadder(n, s, o) : this.wNAFUnsafe(i, this.getPrecomputes(i, n, r), s, o);
|
|
1826
|
-
},
|
|
1827
|
-
// We calculate precomputes for elliptic curve point multiplication
|
|
1828
|
-
// using windowed method. This specifies window size and
|
|
1829
|
-
// stores precomputed values. Usually only base point would be precomputed.
|
|
1830
|
-
setWindowSize(n, s) {
|
|
1831
|
-
hs(s, t), ls.set(n, s), Ne.delete(n);
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
|
-
}
|
|
1835
|
-
function N0(e, t, n, s) {
|
|
1836
|
-
let r = t, o = e.ZERO, i = e.ZERO;
|
|
1837
|
-
for (; n > re || s > re; )
|
|
1838
|
-
n & Gt && (o = o.add(r)), s & Gt && (i = i.add(r)), r = r.double(), n >>= Gt, s >>= Gt;
|
|
1839
|
-
return { p1: o, p2: i };
|
|
1840
|
-
}
|
|
1841
|
-
function cn(e, t, n, s) {
|
|
1842
|
-
O0(n, e), T0(s, t);
|
|
1843
|
-
const r = n.length, o = s.length;
|
|
1844
|
-
if (r !== o)
|
|
1845
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
1846
|
-
const i = e.ZERO, c = o0(BigInt(r));
|
|
1847
|
-
let f = 1;
|
|
1848
|
-
c > 12 ? f = c - 3 : c > 4 ? f = c - 2 : c > 0 && (f = 2);
|
|
1849
|
-
const l = ve(f), h = new Array(Number(l) + 1).fill(i), a = Math.floor((t.BITS - 1) / f) * f;
|
|
1850
|
-
let d = i;
|
|
1851
|
-
for (let u = a; u >= 0; u -= f) {
|
|
1852
|
-
h.fill(i);
|
|
1853
|
-
for (let b = 0; b < o; b++) {
|
|
1854
|
-
const w = s[b], H = Number(w >> BigInt(u) & l);
|
|
1855
|
-
h[H] = h[H].add(n[b]);
|
|
1856
|
-
}
|
|
1857
|
-
let y = i;
|
|
1858
|
-
for (let b = h.length - 1, w = i; b > 0; b--)
|
|
1859
|
-
w = w.add(h[b]), y = y.add(w);
|
|
1860
|
-
if (d = d.add(y), u !== 0)
|
|
1861
|
-
for (let b = 0; b < f; b++)
|
|
1862
|
-
d = d.double();
|
|
1863
|
-
}
|
|
1864
|
-
return d;
|
|
1865
|
-
}
|
|
1866
|
-
function En(e, t) {
|
|
1867
|
-
if (t) {
|
|
1868
|
-
if (t.ORDER !== e)
|
|
1869
|
-
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1870
|
-
return u0(t), t;
|
|
1871
|
-
} else
|
|
1872
|
-
return Zt(e);
|
|
1873
|
-
}
|
|
1874
|
-
function us(e, t, n = {}) {
|
|
1875
|
-
if (!t || typeof t != "object")
|
|
1876
|
-
throw new Error(`expected valid ${e} CURVE object`);
|
|
1877
|
-
for (const c of ["p", "n", "h"]) {
|
|
1878
|
-
const f = t[c];
|
|
1879
|
-
if (!(typeof f == "bigint" && f > re))
|
|
1880
|
-
throw new Error(`CURVE.${c} must be positive bigint`);
|
|
1881
|
-
}
|
|
1882
|
-
const s = En(t.p, n.Fp), r = En(t.n, n.Fn), i = ["Gx", "Gy", "a", e === "weierstrass" ? "b" : "d"];
|
|
1883
|
-
for (const c of i)
|
|
1884
|
-
if (!s.isValid(t[c]))
|
|
1885
|
-
throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
|
|
1886
|
-
return { Fp: s, Fn: r };
|
|
1887
|
-
}
|
|
1888
|
-
const ht = BigInt(0), tt = BigInt(1), Ge = BigInt(2), R0 = BigInt(8), G0 = { zip215: !0 };
|
|
1889
|
-
function q0(e, t, n, s) {
|
|
1890
|
-
const r = e.sqr(n), o = e.sqr(s), i = e.add(e.mul(t.a, r), o), c = e.add(e.ONE, e.mul(t.d, e.mul(r, o)));
|
|
1891
|
-
return e.eql(i, c);
|
|
1892
|
-
}
|
|
1893
|
-
function M0(e, t = {}) {
|
|
1894
|
-
const { Fp: n, Fn: s } = us("edwards", e, t), { h: r, n: o } = e;
|
|
1895
|
-
ue(t, {}, { uvRatio: "function" });
|
|
1896
|
-
const i = Ge << BigInt(s.BYTES * 8) - tt, c = (b) => n.create(b), f = t.uvRatio || ((b, w) => {
|
|
1897
|
-
try {
|
|
1898
|
-
return { isValid: !0, value: n.sqrt(n.div(b, w)) };
|
|
1899
|
-
} catch {
|
|
1900
|
-
return { isValid: !1, value: ht };
|
|
1901
|
-
}
|
|
1902
|
-
});
|
|
1903
|
-
if (!q0(n, e, e.Gx, e.Gy))
|
|
1904
|
-
throw new Error("bad curve params: generator point");
|
|
1905
|
-
function l(b, w, H = !1) {
|
|
1906
|
-
const v = H ? tt : ht;
|
|
1907
|
-
return Jt("coordinate " + b, w, v, i), w;
|
|
1908
|
-
}
|
|
1909
|
-
function h(b) {
|
|
1910
|
-
if (!(b instanceof u))
|
|
1911
|
-
throw new Error("ExtendedPoint expected");
|
|
1912
|
-
}
|
|
1913
|
-
const a = _e((b, w) => {
|
|
1914
|
-
const { ex: H, ey: v, ez: p } = b, D = b.is0();
|
|
1915
|
-
w == null && (w = D ? R0 : n.inv(p));
|
|
1916
|
-
const m = c(H * w), $ = c(v * w), C = c(p * w);
|
|
1917
|
-
if (D)
|
|
1918
|
-
return { x: ht, y: tt };
|
|
1919
|
-
if (C !== tt)
|
|
1920
|
-
throw new Error("invZ was invalid");
|
|
1921
|
-
return { x: m, y: $ };
|
|
1922
|
-
}), d = _e((b) => {
|
|
1923
|
-
const { a: w, d: H } = e;
|
|
1924
|
-
if (b.is0())
|
|
1925
|
-
throw new Error("bad point: ZERO");
|
|
1926
|
-
const { ex: v, ey: p, ez: D, et: m } = b, $ = c(v * v), C = c(p * p), _ = c(D * D), x = c(_ * _), A = c($ * w), g = c(_ * c(A + C)), B = c(x + c(H * c($ * C)));
|
|
1927
|
-
if (g !== B)
|
|
1928
|
-
throw new Error("bad point: equation left != right (1)");
|
|
1929
|
-
const E = c(v * p), I = c(D * m);
|
|
1930
|
-
if (E !== I)
|
|
1931
|
-
throw new Error("bad point: equation left != right (2)");
|
|
1932
|
-
return !0;
|
|
1933
|
-
});
|
|
1934
|
-
class u {
|
|
1935
|
-
constructor(w, H, v, p) {
|
|
1936
|
-
this.ex = l("x", w), this.ey = l("y", H), this.ez = l("z", v, !0), this.et = l("t", p), Object.freeze(this);
|
|
1937
|
-
}
|
|
1938
|
-
get x() {
|
|
1939
|
-
return this.toAffine().x;
|
|
1940
|
-
}
|
|
1941
|
-
get y() {
|
|
1942
|
-
return this.toAffine().y;
|
|
1943
|
-
}
|
|
1944
|
-
static fromAffine(w) {
|
|
1945
|
-
if (w instanceof u)
|
|
1946
|
-
throw new Error("extended point not allowed");
|
|
1947
|
-
const { x: H, y: v } = w || {};
|
|
1948
|
-
return l("x", H), l("y", v), new u(H, v, tt, c(H * v));
|
|
1949
|
-
}
|
|
1950
|
-
static normalizeZ(w) {
|
|
1951
|
-
return as(u, "ez", w);
|
|
1952
|
-
}
|
|
1953
|
-
// Multiscalar Multiplication
|
|
1954
|
-
static msm(w, H) {
|
|
1955
|
-
return cn(u, s, w, H);
|
|
1956
|
-
}
|
|
1957
|
-
// "Private method", don't use it directly
|
|
1958
|
-
_setWindowSize(w) {
|
|
1959
|
-
this.precompute(w);
|
|
1960
|
-
}
|
|
1961
|
-
precompute(w = 8, H = !0) {
|
|
1962
|
-
return y.setWindowSize(this, w), H || this.multiply(Ge), this;
|
|
1963
|
-
}
|
|
1964
|
-
// Not required for fromHex(), which always creates valid points.
|
|
1965
|
-
// Could be useful for fromAffine().
|
|
1966
|
-
assertValidity() {
|
|
1967
|
-
d(this);
|
|
1968
|
-
}
|
|
1969
|
-
// Compare one point to another.
|
|
1970
|
-
equals(w) {
|
|
1971
|
-
h(w);
|
|
1972
|
-
const { ex: H, ey: v, ez: p } = this, { ex: D, ey: m, ez: $ } = w, C = c(H * $), _ = c(D * p), x = c(v * $), A = c(m * p);
|
|
1973
|
-
return C === _ && x === A;
|
|
1974
|
-
}
|
|
1975
|
-
is0() {
|
|
1976
|
-
return this.equals(u.ZERO);
|
|
1977
|
-
}
|
|
1978
|
-
negate() {
|
|
1979
|
-
return new u(c(-this.ex), this.ey, this.ez, c(-this.et));
|
|
1980
|
-
}
|
|
1981
|
-
// Fast algo for doubling Extended Point.
|
|
1982
|
-
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
1983
|
-
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
1984
|
-
double() {
|
|
1985
|
-
const { a: w } = e, { ex: H, ey: v, ez: p } = this, D = c(H * H), m = c(v * v), $ = c(Ge * c(p * p)), C = c(w * D), _ = H + v, x = c(c(_ * _) - D - m), A = C + m, g = A - $, B = C - m, E = c(x * g), I = c(A * B), S = c(x * B), L = c(g * A);
|
|
1986
|
-
return new u(E, I, L, S);
|
|
1987
|
-
}
|
|
1988
|
-
// Fast algo for adding 2 Extended Points.
|
|
1989
|
-
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
1990
|
-
// Cost: 9M + 1*a + 1*d + 7add.
|
|
1991
|
-
add(w) {
|
|
1992
|
-
h(w);
|
|
1993
|
-
const { a: H, d: v } = e, { ex: p, ey: D, ez: m, et: $ } = this, { ex: C, ey: _, ez: x, et: A } = w, g = c(p * C), B = c(D * _), E = c($ * v * A), I = c(m * x), S = c((p + D) * (C + _) - g - B), L = I - E, O = I + E, k = c(B - H * g), G = c(S * L), N = c(O * k), T = c(S * k), M = c(L * O);
|
|
1994
|
-
return new u(G, N, M, T);
|
|
1995
|
-
}
|
|
1996
|
-
subtract(w) {
|
|
1997
|
-
return this.add(w.negate());
|
|
1998
|
-
}
|
|
1999
|
-
// Constant-time multiplication.
|
|
2000
|
-
multiply(w) {
|
|
2001
|
-
const H = w;
|
|
2002
|
-
Jt("scalar", H, tt, o);
|
|
2003
|
-
const { p: v, f: p } = y.wNAFCached(this, H, u.normalizeZ);
|
|
2004
|
-
return u.normalizeZ([v, p])[0];
|
|
2005
|
-
}
|
|
2006
|
-
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
2007
|
-
// It's faster, but should only be used when you don't care about
|
|
2008
|
-
// an exposed private key e.g. sig verification.
|
|
2009
|
-
// Does NOT allow scalars higher than CURVE.n.
|
|
2010
|
-
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
2011
|
-
multiplyUnsafe(w, H = u.ZERO) {
|
|
2012
|
-
const v = w;
|
|
2013
|
-
return Jt("scalar", v, ht, o), v === ht ? u.ZERO : this.is0() || v === tt ? this : y.wNAFCachedUnsafe(this, v, u.normalizeZ, H);
|
|
2014
|
-
}
|
|
2015
|
-
// Checks if point is of small order.
|
|
2016
|
-
// If you add something to small order point, you will have "dirty"
|
|
2017
|
-
// point with torsion component.
|
|
2018
|
-
// Multiplies point by cofactor and checks if the result is 0.
|
|
2019
|
-
isSmallOrder() {
|
|
2020
|
-
return this.multiplyUnsafe(r).is0();
|
|
2021
|
-
}
|
|
2022
|
-
// Multiplies point by curve order and checks if the result is 0.
|
|
2023
|
-
// Returns `false` is the point is dirty.
|
|
2024
|
-
isTorsionFree() {
|
|
2025
|
-
return y.wNAFCachedUnsafe(this, o).is0();
|
|
2026
|
-
}
|
|
2027
|
-
// Converts Extended point to default (x, y) coordinates.
|
|
2028
|
-
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
2029
|
-
toAffine(w) {
|
|
2030
|
-
return a(this, w);
|
|
2031
|
-
}
|
|
2032
|
-
clearCofactor() {
|
|
2033
|
-
return r === tt ? this : this.multiplyUnsafe(r);
|
|
2034
|
-
}
|
|
2035
|
-
static fromBytes(w, H = !1) {
|
|
2036
|
-
return ot(w), this.fromHex(w, H);
|
|
2037
|
-
}
|
|
2038
|
-
// Converts hash string or Uint8Array to Point.
|
|
2039
|
-
// Uses algo from RFC8032 5.1.3.
|
|
2040
|
-
static fromHex(w, H = !1) {
|
|
2041
|
-
const { d: v, a: p } = e, D = n.BYTES;
|
|
2042
|
-
w = V("pointHex", w, D), Vt("zip215", H);
|
|
2043
|
-
const m = w.slice(), $ = w[D - 1];
|
|
2044
|
-
m[D - 1] = $ & -129;
|
|
2045
|
-
const C = ne(m), _ = H ? i : n.ORDER;
|
|
2046
|
-
Jt("pointHex.y", C, ht, _);
|
|
2047
|
-
const x = c(C * C), A = c(x - tt), g = c(v * x - p);
|
|
2048
|
-
let { isValid: B, value: E } = f(A, g);
|
|
2049
|
-
if (!B)
|
|
2050
|
-
throw new Error("Point.fromHex: invalid y coordinate");
|
|
2051
|
-
const I = (E & tt) === tt, S = ($ & 128) !== 0;
|
|
2052
|
-
if (!H && E === ht && S)
|
|
2053
|
-
throw new Error("Point.fromHex: x=0 and x_0=1");
|
|
2054
|
-
return S !== I && (E = c(-E)), u.fromAffine({ x: E, y: C });
|
|
2055
|
-
}
|
|
2056
|
-
static fromPrivateScalar(w) {
|
|
2057
|
-
return u.BASE.multiply(w);
|
|
2058
|
-
}
|
|
2059
|
-
toBytes() {
|
|
2060
|
-
const { x: w, y: H } = this.toAffine(), v = se(H, n.BYTES);
|
|
2061
|
-
return v[v.length - 1] |= w & tt ? 128 : 0, v;
|
|
2062
|
-
}
|
|
2063
|
-
/** @deprecated use `toBytes` */
|
|
2064
|
-
toRawBytes() {
|
|
2065
|
-
return this.toBytes();
|
|
2066
|
-
}
|
|
2067
|
-
toHex() {
|
|
2068
|
-
return Mt(this.toBytes());
|
|
2069
|
-
}
|
|
2070
|
-
toString() {
|
|
2071
|
-
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
2072
|
-
}
|
|
2073
|
-
}
|
|
2074
|
-
u.BASE = new u(e.Gx, e.Gy, tt, c(e.Gx * e.Gy)), u.ZERO = new u(ht, tt, tt, ht), u.Fp = n, u.Fn = s;
|
|
2075
|
-
const y = ds(u, s.BYTES * 8);
|
|
2076
|
-
return u;
|
|
2077
|
-
}
|
|
2078
|
-
function V0(e, t) {
|
|
2079
|
-
ue(t, {
|
|
2080
|
-
hash: "function"
|
|
2081
|
-
}, {
|
|
2082
|
-
adjustScalarBytes: "function",
|
|
2083
|
-
randomBytes: "function",
|
|
2084
|
-
domain: "function",
|
|
2085
|
-
prehash: "function",
|
|
2086
|
-
mapToCurve: "function"
|
|
2087
|
-
});
|
|
2088
|
-
const { prehash: n, hash: s } = t, { BASE: r, Fp: o, Fn: i } = e, c = i.ORDER, f = t.randomBytes || Qn, l = t.adjustScalarBytes || ((m) => m), h = t.domain || ((m, $, C) => {
|
|
2089
|
-
if (Vt("phflag", C), $.length || C)
|
|
2090
|
-
throw new Error("Contexts/pre-hash are not supported");
|
|
2091
|
-
return m;
|
|
2092
|
-
});
|
|
2093
|
-
function a(m) {
|
|
2094
|
-
return i.create(m);
|
|
2095
|
-
}
|
|
2096
|
-
function d(m) {
|
|
2097
|
-
return a(ne(m));
|
|
2098
|
-
}
|
|
2099
|
-
function u(m) {
|
|
2100
|
-
const $ = o.BYTES;
|
|
2101
|
-
m = V("private key", m, $);
|
|
2102
|
-
const C = V("hashed private key", s(m), 2 * $), _ = l(C.slice(0, $)), x = C.slice($, 2 * $), A = d(_);
|
|
2103
|
-
return { head: _, prefix: x, scalar: A };
|
|
2104
|
-
}
|
|
2105
|
-
function y(m) {
|
|
2106
|
-
const { head: $, prefix: C, scalar: _ } = u(m), x = r.multiply(_), A = x.toBytes();
|
|
2107
|
-
return { head: $, prefix: C, scalar: _, point: x, pointBytes: A };
|
|
2108
|
-
}
|
|
2109
|
-
function b(m) {
|
|
2110
|
-
return y(m).pointBytes;
|
|
2111
|
-
}
|
|
2112
|
-
function w(m = Uint8Array.of(), ...$) {
|
|
2113
|
-
const C = wt(...$);
|
|
2114
|
-
return d(s(h(C, V("context", m), !!n)));
|
|
2115
|
-
}
|
|
2116
|
-
function H(m, $, C = {}) {
|
|
2117
|
-
m = V("message", m), n && (m = n(m));
|
|
2118
|
-
const { prefix: _, scalar: x, pointBytes: A } = y($), g = w(C.context, _, m), B = r.multiply(g).toBytes(), E = w(C.context, B, A, m), I = a(g + E * x);
|
|
2119
|
-
Jt("signature.s", I, ht, c);
|
|
2120
|
-
const S = o.BYTES, L = wt(B, se(I, S));
|
|
2121
|
-
return V("result", L, S * 2);
|
|
2122
|
-
}
|
|
2123
|
-
const v = G0;
|
|
2124
|
-
function p(m, $, C, _ = v) {
|
|
2125
|
-
const { context: x, zip215: A } = _, g = o.BYTES;
|
|
2126
|
-
m = V("signature", m, 2 * g), $ = V("message", $), C = V("publicKey", C, g), A !== void 0 && Vt("zip215", A), n && ($ = n($));
|
|
2127
|
-
const B = ne(m.slice(g, 2 * g));
|
|
2128
|
-
let E, I, S;
|
|
2129
|
-
try {
|
|
2130
|
-
E = e.fromHex(C, A), I = e.fromHex(m.slice(0, g), A), S = r.multiplyUnsafe(B);
|
|
2131
|
-
} catch {
|
|
2132
|
-
return !1;
|
|
2133
|
-
}
|
|
2134
|
-
if (!A && E.isSmallOrder())
|
|
2135
|
-
return !1;
|
|
2136
|
-
const L = w(x, I.toBytes(), E.toBytes(), $);
|
|
2137
|
-
return I.add(E.multiplyUnsafe(L)).subtract(S).clearCofactor().is0();
|
|
2138
|
-
}
|
|
2139
|
-
return r.precompute(8), { getPublicKey: b, sign: H, verify: p, utils: {
|
|
2140
|
-
getExtendedPublicKey: y,
|
|
2141
|
-
/** ed25519 priv keys are uniform 32b. No need to check for modulo bias, like in secp256k1. */
|
|
2142
|
-
randomPrivateKey: () => f(o.BYTES),
|
|
2143
|
-
/**
|
|
2144
|
-
* We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
|
|
2145
|
-
* values. This slows down first getPublicKey() by milliseconds (see Speed section),
|
|
2146
|
-
* but allows to speed-up subsequent getPublicKey() calls up to 20x.
|
|
2147
|
-
* @param windowSize 2, 4, 8, 16
|
|
2148
|
-
*/
|
|
2149
|
-
precompute(m = 8, $ = e.BASE) {
|
|
2150
|
-
return $.precompute(m, !1);
|
|
2151
|
-
}
|
|
2152
|
-
}, Point: e };
|
|
2153
|
-
}
|
|
2154
|
-
function Z0(e) {
|
|
2155
|
-
const t = {
|
|
2156
|
-
a: e.a,
|
|
2157
|
-
d: e.d,
|
|
2158
|
-
p: e.Fp.ORDER,
|
|
2159
|
-
n: e.n,
|
|
2160
|
-
h: e.h,
|
|
2161
|
-
Gx: e.Gx,
|
|
2162
|
-
Gy: e.Gy
|
|
2163
|
-
}, n = e.Fp, s = Zt(t.n, e.nBitLength, !0), r = { Fp: n, Fn: s, uvRatio: e.uvRatio }, o = {
|
|
2164
|
-
hash: e.hash,
|
|
2165
|
-
randomBytes: e.randomBytes,
|
|
2166
|
-
adjustScalarBytes: e.adjustScalarBytes,
|
|
2167
|
-
domain: e.domain,
|
|
2168
|
-
prehash: e.prehash,
|
|
2169
|
-
mapToCurve: e.mapToCurve
|
|
2170
|
-
};
|
|
2171
|
-
return { CURVE: t, curveOpts: r, eddsaOpts: o };
|
|
2172
|
-
}
|
|
2173
|
-
function z0(e, t) {
|
|
2174
|
-
return Object.assign({}, t, { ExtendedPoint: t.Point, CURVE: e });
|
|
2175
|
-
}
|
|
2176
|
-
function j0(e) {
|
|
2177
|
-
const { CURVE: t, curveOpts: n, eddsaOpts: s } = Z0(e), r = M0(t, n), o = V0(r, s);
|
|
2178
|
-
return z0(e, o);
|
|
2179
|
-
}
|
|
2180
|
-
const xi = BigInt(0), bi = BigInt(1), wi = BigInt(2);
|
|
2181
|
-
const W0 = BigInt(0), gt = BigInt(1), Hn = BigInt(2), gi = BigInt(3), F0 = BigInt(5), K0 = BigInt(8), $e = {
|
|
2182
|
-
p: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),
|
|
2183
|
-
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
2184
|
-
h: K0,
|
|
2185
|
-
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
2186
|
-
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
2187
|
-
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
2188
|
-
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
2189
|
-
};
|
|
2190
|
-
function Y0(e) {
|
|
2191
|
-
const t = BigInt(10), n = BigInt(20), s = BigInt(40), r = BigInt(80), o = $e.p, c = e * e % o * e % o, f = Z(c, Hn, o) * c % o, l = Z(f, gt, o) * e % o, h = Z(l, F0, o) * l % o, a = Z(h, t, o) * h % o, d = Z(a, n, o) * a % o, u = Z(d, s, o) * d % o, y = Z(u, r, o) * u % o, b = Z(y, r, o) * u % o, w = Z(b, t, o) * h % o;
|
|
2192
|
-
return { pow_p_5_8: Z(w, Hn, o) * e % o, b2: c };
|
|
2193
|
-
}
|
|
2194
|
-
function X0(e) {
|
|
2195
|
-
return e[0] &= 248, e[31] &= 127, e[31] |= 64, e;
|
|
2196
|
-
}
|
|
2197
|
-
const We = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
2198
|
-
function fn(e, t) {
|
|
2199
|
-
const n = $e.p, s = z(t * t * t, n), r = z(s * s * t, n), o = Y0(e * r).pow_p_5_8;
|
|
2200
|
-
let i = z(e * s * o, n);
|
|
2201
|
-
const c = z(t * i * i, n), f = i, l = z(i * We, n), h = c === e, a = c === z(-e, n), d = c === z(-e * We, n);
|
|
2202
|
-
return h && (i = f), (a || d) && (i = l), Ot(i, n) && (i = z(-i, n)), { isValid: h || a, value: i };
|
|
2203
|
-
}
|
|
2204
|
-
const Qt = Zt($e.p, void 0, !0), P0 = {
|
|
2205
|
-
...$e,
|
|
2206
|
-
Fp: Qt,
|
|
2207
|
-
hash: k0,
|
|
2208
|
-
adjustScalarBytes: X0,
|
|
2209
|
-
// dom2
|
|
2210
|
-
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
2211
|
-
// Constant-time, u/√v
|
|
2212
|
-
uvRatio: fn
|
|
2213
|
-
}, st = j0(P0);
|
|
2214
|
-
function qe(e) {
|
|
2215
|
-
if (!(e instanceof W))
|
|
2216
|
-
throw new Error("RistrettoPoint expected");
|
|
2217
|
-
}
|
|
2218
|
-
const Fe = We, Q0 = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"), J0 = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"), tr = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"), er = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"), _n = (e) => fn(gt, e), nr = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), Me = (e) => st.CURVE.Fp.create(ne(e) & nr);
|
|
2219
|
-
function Sn(e) {
|
|
2220
|
-
const { d: t } = st.CURVE, n = st.CURVE.Fp.ORDER, s = st.CURVE.Fp.create, r = s(Fe * e * e), o = s((r + gt) * tr);
|
|
2221
|
-
let i = BigInt(-1);
|
|
2222
|
-
const c = s((i - t * r) * s(r + t));
|
|
2223
|
-
let { isValid: f, value: l } = fn(o, c), h = s(l * e);
|
|
2224
|
-
Ot(h, n) || (h = s(-h)), f || (l = h), f || (i = r);
|
|
2225
|
-
const a = s(i * (r - gt) * er - c), d = l * l, u = s((l + l) * c), y = s(a * Q0), b = s(gt - d), w = s(gt + d);
|
|
2226
|
-
return new st.Point(s(u * w), s(b * y), s(y * w), s(u * b));
|
|
2227
|
-
}
|
|
2228
|
-
class W {
|
|
2229
|
-
// Private property to discourage combining ExtendedPoint + RistrettoPoint
|
|
2230
|
-
// Always use Ristretto encoding/decoding instead.
|
|
2231
|
-
constructor(t) {
|
|
2232
|
-
this.ep = t;
|
|
2233
|
-
}
|
|
2234
|
-
static fromAffine(t) {
|
|
2235
|
-
return new W(st.Point.fromAffine(t));
|
|
2236
|
-
}
|
|
2237
|
-
/**
|
|
2238
|
-
* Takes uniform output of 64-byte hash function like sha512 and converts it to `RistrettoPoint`.
|
|
2239
|
-
* The hash-to-group operation applies Elligator twice and adds the results.
|
|
2240
|
-
* **Note:** this is one-way map, there is no conversion from point to hash.
|
|
2241
|
-
* Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-B) and on
|
|
2242
|
-
* the [website](https://ristretto.group/formulas/elligator.html).
|
|
2243
|
-
* @param hex 64-byte output of a hash function
|
|
2244
|
-
*/
|
|
2245
|
-
static hashToCurve(t) {
|
|
2246
|
-
t = V("ristrettoHash", t, 64);
|
|
2247
|
-
const n = Me(t.slice(0, 32)), s = Sn(n), r = Me(t.slice(32, 64)), o = Sn(r);
|
|
2248
|
-
return new W(s.add(o));
|
|
2249
|
-
}
|
|
2250
|
-
static fromBytes(t) {
|
|
2251
|
-
return ot(t), this.fromHex(t);
|
|
2252
|
-
}
|
|
2253
|
-
/**
|
|
2254
|
-
* Converts ristretto-encoded string to ristretto point.
|
|
2255
|
-
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
|
|
2256
|
-
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
2257
|
-
*/
|
|
2258
|
-
static fromHex(t) {
|
|
2259
|
-
t = V("ristrettoHex", t, 32);
|
|
2260
|
-
const { a: n, d: s } = st.CURVE, r = Qt.ORDER, o = Qt.create, i = "RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint", c = Me(t);
|
|
2261
|
-
if (!r0(se(c, 32), t) || Ot(c, r))
|
|
2262
|
-
throw new Error(i);
|
|
2263
|
-
const f = o(c * c), l = o(gt + n * f), h = o(gt - n * f), a = o(l * l), d = o(h * h), u = o(n * s * a - d), { isValid: y, value: b } = _n(o(u * d)), w = o(b * h), H = o(b * w * u);
|
|
2264
|
-
let v = o((c + c) * w);
|
|
2265
|
-
Ot(v, r) && (v = o(-v));
|
|
2266
|
-
const p = o(l * H), D = o(v * p);
|
|
2267
|
-
if (!y || Ot(D, r) || p === W0)
|
|
2268
|
-
throw new Error(i);
|
|
2269
|
-
return new W(new st.Point(v, p, gt, D));
|
|
2270
|
-
}
|
|
2271
|
-
static msm(t, n) {
|
|
2272
|
-
const s = Zt(st.CURVE.n, st.CURVE.nBitLength);
|
|
2273
|
-
return cn(W, s, t, n);
|
|
2274
|
-
}
|
|
2275
|
-
/**
|
|
2276
|
-
* Encodes ristretto point to Uint8Array.
|
|
2277
|
-
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
|
|
2278
|
-
*/
|
|
2279
|
-
toBytes() {
|
|
2280
|
-
let { ex: t, ey: n, ez: s, et: r } = this.ep;
|
|
2281
|
-
const o = Qt.ORDER, i = Qt.create, c = i(i(s + n) * i(s - n)), f = i(t * n), l = i(f * f), { value: h } = _n(i(c * l)), a = i(h * c), d = i(h * f), u = i(a * d * r);
|
|
2282
|
-
let y;
|
|
2283
|
-
if (Ot(r * u, o)) {
|
|
2284
|
-
let w = i(n * Fe), H = i(t * Fe);
|
|
2285
|
-
t = w, n = H, y = i(a * J0);
|
|
2286
|
-
} else
|
|
2287
|
-
y = d;
|
|
2288
|
-
Ot(t * u, o) && (n = i(-n));
|
|
2289
|
-
let b = i((s - n) * y);
|
|
2290
|
-
return Ot(b, o) && (b = i(-b)), se(b, 32);
|
|
2291
|
-
}
|
|
2292
|
-
/** @deprecated use `toBytes` */
|
|
2293
|
-
toRawBytes() {
|
|
2294
|
-
return this.toBytes();
|
|
2295
|
-
}
|
|
2296
|
-
toHex() {
|
|
2297
|
-
return Mt(this.toBytes());
|
|
2298
|
-
}
|
|
2299
|
-
toString() {
|
|
2300
|
-
return this.toHex();
|
|
2301
|
-
}
|
|
2302
|
-
/**
|
|
2303
|
-
* Compares two Ristretto points.
|
|
2304
|
-
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
|
|
2305
|
-
*/
|
|
2306
|
-
equals(t) {
|
|
2307
|
-
qe(t);
|
|
2308
|
-
const { ex: n, ey: s } = this.ep, { ex: r, ey: o } = t.ep, i = Qt.create, c = i(n * o) === i(s * r), f = i(s * o) === i(n * r);
|
|
2309
|
-
return c || f;
|
|
2310
|
-
}
|
|
2311
|
-
add(t) {
|
|
2312
|
-
return qe(t), new W(this.ep.add(t.ep));
|
|
2313
|
-
}
|
|
2314
|
-
subtract(t) {
|
|
2315
|
-
return qe(t), new W(this.ep.subtract(t.ep));
|
|
2316
|
-
}
|
|
2317
|
-
multiply(t) {
|
|
2318
|
-
return new W(this.ep.multiply(t));
|
|
2319
|
-
}
|
|
2320
|
-
multiplyUnsafe(t) {
|
|
2321
|
-
return new W(this.ep.multiplyUnsafe(t));
|
|
2322
|
-
}
|
|
2323
|
-
double() {
|
|
2324
|
-
return new W(this.ep.double());
|
|
2325
|
-
}
|
|
2326
|
-
negate() {
|
|
2327
|
-
return new W(this.ep.negate());
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
const yi = (W.BASE || (W.BASE = new W(st.Point.BASE)), W.ZERO || (W.ZERO = new W(st.Point.ZERO)), W), pe = /* @__PURE__ */ BigInt(2 ** 32 - 1), In = /* @__PURE__ */ BigInt(32);
|
|
2331
|
-
function sr(e, t = !1) {
|
|
2332
|
-
return t ? { h: Number(e & pe), l: Number(e >> In & pe) } : { h: Number(e >> In & pe) | 0, l: Number(e & pe) | 0 };
|
|
2333
|
-
}
|
|
2334
|
-
function xs(e, t = !1) {
|
|
2335
|
-
const n = e.length;
|
|
2336
|
-
let s = new Uint32Array(n), r = new Uint32Array(n);
|
|
2337
|
-
for (let o = 0; o < n; o++) {
|
|
2338
|
-
const { h: i, l: c } = sr(e[o], t);
|
|
2339
|
-
[s[o], r[o]] = [i, c];
|
|
2340
|
-
}
|
|
2341
|
-
return [s, r];
|
|
2342
|
-
}
|
|
2343
|
-
const Un = (e, t, n) => e >>> n, vn = (e, t, n) => e << 32 - n | t >>> n, Yt = (e, t, n) => e >>> n | t << 32 - n, Xt = (e, t, n) => e << 32 - n | t >>> n, me = (e, t, n) => e << 64 - n | t >>> n - 32, Be = (e, t, n) => e >>> n - 32 | t << 64 - n, rr = (e, t, n) => e << n | t >>> 32 - n, ir = (e, t, n) => t << n | e >>> 32 - n, or = (e, t, n) => t << n - 32 | e >>> 64 - n, cr = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
2344
|
-
function ut(e, t, n, s) {
|
|
2345
|
-
const r = (t >>> 0) + (s >>> 0);
|
|
2346
|
-
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
2347
|
-
}
|
|
2348
|
-
const fr = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), ar = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, hr = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), lr = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, dr = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), ur = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, Pt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
2349
|
-
function xr(e) {
|
|
2350
|
-
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
2351
|
-
}
|
|
2352
|
-
function Le(e, ...t) {
|
|
2353
|
-
if (!xr(e))
|
|
2354
|
-
throw new Error("Uint8Array expected");
|
|
2355
|
-
if (t.length > 0 && !t.includes(e.length))
|
|
2356
|
-
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
2357
|
-
}
|
|
2358
|
-
function $n(e, t = !0) {
|
|
2359
|
-
if (e.destroyed)
|
|
2360
|
-
throw new Error("Hash instance has been destroyed");
|
|
2361
|
-
if (t && e.finished)
|
|
2362
|
-
throw new Error("Hash#digest() has already been called");
|
|
2363
|
-
}
|
|
2364
|
-
function br(e, t) {
|
|
2365
|
-
Le(e);
|
|
2366
|
-
const n = t.outputLen;
|
|
2367
|
-
if (e.length < n)
|
|
2368
|
-
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
2369
|
-
}
|
|
2370
|
-
function pi(e) {
|
|
2371
|
-
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
2372
|
-
}
|
|
2373
|
-
function Se(...e) {
|
|
2374
|
-
for (let t = 0; t < e.length; t++)
|
|
2375
|
-
e[t].fill(0);
|
|
2376
|
-
}
|
|
2377
|
-
function Ve(e) {
|
|
2378
|
-
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
2379
|
-
}
|
|
2380
|
-
function wr(e) {
|
|
2381
|
-
if (typeof e != "string")
|
|
2382
|
-
throw new Error("string expected");
|
|
2383
|
-
return new Uint8Array(new TextEncoder().encode(e));
|
|
2384
|
-
}
|
|
2385
|
-
function bs(e) {
|
|
2386
|
-
return typeof e == "string" && (e = wr(e)), Le(e), e;
|
|
2387
|
-
}
|
|
2388
|
-
function mi(...e) {
|
|
2389
|
-
let t = 0;
|
|
2390
|
-
for (let s = 0; s < e.length; s++) {
|
|
2391
|
-
const r = e[s];
|
|
2392
|
-
Le(r), t += r.length;
|
|
2393
|
-
}
|
|
2394
|
-
const n = new Uint8Array(t);
|
|
2395
|
-
for (let s = 0, r = 0; s < e.length; s++) {
|
|
2396
|
-
const o = e[s];
|
|
2397
|
-
n.set(o, r), r += o.length;
|
|
2398
|
-
}
|
|
2399
|
-
return n;
|
|
2400
|
-
}
|
|
2401
|
-
let gr = class {
|
|
2402
|
-
};
|
|
2403
|
-
function yr(e) {
|
|
2404
|
-
const t = (s) => e().update(bs(s)).digest(), n = e();
|
|
2405
|
-
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
2406
|
-
}
|
|
2407
|
-
function Ai(e = 32) {
|
|
2408
|
-
if (Pt && typeof Pt.getRandomValues == "function")
|
|
2409
|
-
return Pt.getRandomValues(new Uint8Array(e));
|
|
2410
|
-
if (Pt && typeof Pt.randomBytes == "function")
|
|
2411
|
-
return Uint8Array.from(Pt.randomBytes(e));
|
|
2412
|
-
throw new Error("crypto.getRandomValues must be defined");
|
|
2413
|
-
}
|
|
2414
|
-
const pr = BigInt(0), ce = BigInt(1), mr = BigInt(2), Br = BigInt(7), Ar = BigInt(256), Er = BigInt(113), ws = [], gs = [], ys = [];
|
|
2415
|
-
for (let e = 0, t = ce, n = 1, s = 0; e < 24; e++) {
|
|
2416
|
-
[n, s] = [s, (2 * n + 3 * s) % 5], ws.push(2 * (5 * s + n)), gs.push((e + 1) * (e + 2) / 2 % 64);
|
|
2417
|
-
let r = pr;
|
|
2418
|
-
for (let o = 0; o < 7; o++)
|
|
2419
|
-
t = (t << ce ^ (t >> Br) * Er) % Ar, t & mr && (r ^= ce << (ce << /* @__PURE__ */ BigInt(o)) - ce);
|
|
2420
|
-
ys.push(r);
|
|
2421
|
-
}
|
|
2422
|
-
const ps = xs(ys, !0), Hr = ps[0], _r = ps[1], Ln = (e, t, n) => n > 32 ? or(e, t, n) : rr(e, t, n), Dn = (e, t, n) => n > 32 ? cr(e, t, n) : ir(e, t, n);
|
|
2423
|
-
function Ei(e, t = 24) {
|
|
2424
|
-
const n = new Uint32Array(10);
|
|
2425
|
-
for (let s = 24 - t; s < 24; s++) {
|
|
2426
|
-
for (let i = 0; i < 10; i++)
|
|
2427
|
-
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
2428
|
-
for (let i = 0; i < 10; i += 2) {
|
|
2429
|
-
const c = (i + 8) % 10, f = (i + 2) % 10, l = n[f], h = n[f + 1], a = Ln(l, h, 1) ^ n[c], d = Dn(l, h, 1) ^ n[c + 1];
|
|
2430
|
-
for (let u = 0; u < 50; u += 10)
|
|
2431
|
-
e[i + u] ^= a, e[i + u + 1] ^= d;
|
|
2432
|
-
}
|
|
2433
|
-
let r = e[2], o = e[3];
|
|
2434
|
-
for (let i = 0; i < 24; i++) {
|
|
2435
|
-
const c = gs[i], f = Ln(r, o, c), l = Dn(r, o, c), h = ws[i];
|
|
2436
|
-
r = e[h], o = e[h + 1], e[h] = f, e[h + 1] = l;
|
|
2437
|
-
}
|
|
2438
|
-
for (let i = 0; i < 50; i += 10) {
|
|
2439
|
-
for (let c = 0; c < 10; c++)
|
|
2440
|
-
n[c] = e[i + c];
|
|
2441
|
-
for (let c = 0; c < 10; c++)
|
|
2442
|
-
e[i + c] ^= ~n[(c + 2) % 10] & n[(c + 4) % 10];
|
|
2443
|
-
}
|
|
2444
|
-
e[0] ^= Hr[s], e[1] ^= _r[s];
|
|
2445
|
-
}
|
|
2446
|
-
Se(n);
|
|
2447
|
-
}
|
|
2448
|
-
function Sr(e, t, n, s) {
|
|
2449
|
-
if (typeof e.setBigUint64 == "function")
|
|
2450
|
-
return e.setBigUint64(t, n, s);
|
|
2451
|
-
const r = BigInt(32), o = BigInt(4294967295), i = Number(n >> r & o), c = Number(n & o), f = s ? 4 : 0, l = s ? 0 : 4;
|
|
2452
|
-
e.setUint32(t + f, i, s), e.setUint32(t + l, c, s);
|
|
2453
|
-
}
|
|
2454
|
-
let Ir = class extends gr {
|
|
2455
|
-
constructor(t, n, s, r) {
|
|
2456
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = Ve(this.buffer);
|
|
2457
|
-
}
|
|
2458
|
-
update(t) {
|
|
2459
|
-
$n(this), t = bs(t), Le(t);
|
|
2460
|
-
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
2461
|
-
for (let i = 0; i < o; ) {
|
|
2462
|
-
const c = Math.min(r - this.pos, o - i);
|
|
2463
|
-
if (c === r) {
|
|
2464
|
-
const f = Ve(t);
|
|
2465
|
-
for (; r <= o - i; i += r)
|
|
2466
|
-
this.process(f, i);
|
|
2467
|
-
continue;
|
|
2468
|
-
}
|
|
2469
|
-
s.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
2470
|
-
}
|
|
2471
|
-
return this.length += t.length, this.roundClean(), this;
|
|
2472
|
-
}
|
|
2473
|
-
digestInto(t) {
|
|
2474
|
-
$n(this), br(t, this), this.finished = !0;
|
|
2475
|
-
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
2476
|
-
let { pos: i } = this;
|
|
2477
|
-
n[i++] = 128, Se(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
2478
|
-
for (let a = i; a < r; a++)
|
|
2479
|
-
n[a] = 0;
|
|
2480
|
-
Sr(s, r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
2481
|
-
const c = Ve(t), f = this.outputLen;
|
|
2482
|
-
if (f % 4)
|
|
2483
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
2484
|
-
const l = f / 4, h = this.get();
|
|
2485
|
-
if (l > h.length)
|
|
2486
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
2487
|
-
for (let a = 0; a < l; a++)
|
|
2488
|
-
c.setUint32(4 * a, h[a], o);
|
|
2489
|
-
}
|
|
2490
|
-
digest() {
|
|
2491
|
-
const { buffer: t, outputLen: n } = this;
|
|
2492
|
-
this.digestInto(t);
|
|
2493
|
-
const s = t.slice(0, n);
|
|
2494
|
-
return this.destroy(), s;
|
|
2495
|
-
}
|
|
2496
|
-
_cloneInto(t) {
|
|
2497
|
-
t || (t = new this.constructor()), t.set(...this.get());
|
|
2498
|
-
const { blockLen: n, buffer: s, length: r, finished: o, destroyed: i, pos: c } = this;
|
|
2499
|
-
return t.destroyed = i, t.finished = o, t.length = r, t.pos = c, r % n && t.buffer.set(s), t;
|
|
2500
|
-
}
|
|
2501
|
-
clone() {
|
|
2502
|
-
return this._cloneInto();
|
|
2503
|
-
}
|
|
2504
|
-
};
|
|
2505
|
-
const Q = /* @__PURE__ */ Uint32Array.from([
|
|
2506
|
-
1779033703,
|
|
2507
|
-
4089235720,
|
|
2508
|
-
3144134277,
|
|
2509
|
-
2227873595,
|
|
2510
|
-
1013904242,
|
|
2511
|
-
4271175723,
|
|
2512
|
-
2773480762,
|
|
2513
|
-
1595750129,
|
|
2514
|
-
1359893119,
|
|
2515
|
-
2917565137,
|
|
2516
|
-
2600822924,
|
|
2517
|
-
725511199,
|
|
2518
|
-
528734635,
|
|
2519
|
-
4215389547,
|
|
2520
|
-
1541459225,
|
|
2521
|
-
327033209
|
|
2522
|
-
]);
|
|
2523
|
-
const ms = xs([
|
|
2524
|
-
"0x428a2f98d728ae22",
|
|
2525
|
-
"0x7137449123ef65cd",
|
|
2526
|
-
"0xb5c0fbcfec4d3b2f",
|
|
2527
|
-
"0xe9b5dba58189dbbc",
|
|
2528
|
-
"0x3956c25bf348b538",
|
|
2529
|
-
"0x59f111f1b605d019",
|
|
2530
|
-
"0x923f82a4af194f9b",
|
|
2531
|
-
"0xab1c5ed5da6d8118",
|
|
2532
|
-
"0xd807aa98a3030242",
|
|
2533
|
-
"0x12835b0145706fbe",
|
|
2534
|
-
"0x243185be4ee4b28c",
|
|
2535
|
-
"0x550c7dc3d5ffb4e2",
|
|
2536
|
-
"0x72be5d74f27b896f",
|
|
2537
|
-
"0x80deb1fe3b1696b1",
|
|
2538
|
-
"0x9bdc06a725c71235",
|
|
2539
|
-
"0xc19bf174cf692694",
|
|
2540
|
-
"0xe49b69c19ef14ad2",
|
|
2541
|
-
"0xefbe4786384f25e3",
|
|
2542
|
-
"0x0fc19dc68b8cd5b5",
|
|
2543
|
-
"0x240ca1cc77ac9c65",
|
|
2544
|
-
"0x2de92c6f592b0275",
|
|
2545
|
-
"0x4a7484aa6ea6e483",
|
|
2546
|
-
"0x5cb0a9dcbd41fbd4",
|
|
2547
|
-
"0x76f988da831153b5",
|
|
2548
|
-
"0x983e5152ee66dfab",
|
|
2549
|
-
"0xa831c66d2db43210",
|
|
2550
|
-
"0xb00327c898fb213f",
|
|
2551
|
-
"0xbf597fc7beef0ee4",
|
|
2552
|
-
"0xc6e00bf33da88fc2",
|
|
2553
|
-
"0xd5a79147930aa725",
|
|
2554
|
-
"0x06ca6351e003826f",
|
|
2555
|
-
"0x142929670a0e6e70",
|
|
2556
|
-
"0x27b70a8546d22ffc",
|
|
2557
|
-
"0x2e1b21385c26c926",
|
|
2558
|
-
"0x4d2c6dfc5ac42aed",
|
|
2559
|
-
"0x53380d139d95b3df",
|
|
2560
|
-
"0x650a73548baf63de",
|
|
2561
|
-
"0x766a0abb3c77b2a8",
|
|
2562
|
-
"0x81c2c92e47edaee6",
|
|
2563
|
-
"0x92722c851482353b",
|
|
2564
|
-
"0xa2bfe8a14cf10364",
|
|
2565
|
-
"0xa81a664bbc423001",
|
|
2566
|
-
"0xc24b8b70d0f89791",
|
|
2567
|
-
"0xc76c51a30654be30",
|
|
2568
|
-
"0xd192e819d6ef5218",
|
|
2569
|
-
"0xd69906245565a910",
|
|
2570
|
-
"0xf40e35855771202a",
|
|
2571
|
-
"0x106aa07032bbd1b8",
|
|
2572
|
-
"0x19a4c116b8d2d0c8",
|
|
2573
|
-
"0x1e376c085141ab53",
|
|
2574
|
-
"0x2748774cdf8eeb99",
|
|
2575
|
-
"0x34b0bcb5e19b48a8",
|
|
2576
|
-
"0x391c0cb3c5c95a63",
|
|
2577
|
-
"0x4ed8aa4ae3418acb",
|
|
2578
|
-
"0x5b9cca4f7763e373",
|
|
2579
|
-
"0x682e6ff3d6b2b8a3",
|
|
2580
|
-
"0x748f82ee5defb2fc",
|
|
2581
|
-
"0x78a5636f43172f60",
|
|
2582
|
-
"0x84c87814a1f0ab72",
|
|
2583
|
-
"0x8cc702081a6439ec",
|
|
2584
|
-
"0x90befffa23631e28",
|
|
2585
|
-
"0xa4506cebde82bde9",
|
|
2586
|
-
"0xbef9a3f7b2c67915",
|
|
2587
|
-
"0xc67178f2e372532b",
|
|
2588
|
-
"0xca273eceea26619c",
|
|
2589
|
-
"0xd186b8c721c0c207",
|
|
2590
|
-
"0xeada7dd6cde0eb1e",
|
|
2591
|
-
"0xf57d4f7fee6ed178",
|
|
2592
|
-
"0x06f067aa72176fba",
|
|
2593
|
-
"0x0a637dc5a2c898a6",
|
|
2594
|
-
"0x113f9804bef90dae",
|
|
2595
|
-
"0x1b710b35131c471b",
|
|
2596
|
-
"0x28db77f523047d84",
|
|
2597
|
-
"0x32caab7b40c72493",
|
|
2598
|
-
"0x3c9ebe0a15c9bebc",
|
|
2599
|
-
"0x431d67c49c100d4c",
|
|
2600
|
-
"0x4cc5d4becb3e42b6",
|
|
2601
|
-
"0x597f299cfc657e2a",
|
|
2602
|
-
"0x5fcb6fab3ad6faec",
|
|
2603
|
-
"0x6c44198c4a475817"
|
|
2604
|
-
].map((e) => BigInt(e))), Ur = ms[0], vr = ms[1], Ut = /* @__PURE__ */ new Uint32Array(80), vt = /* @__PURE__ */ new Uint32Array(80);
|
|
2605
|
-
let $r = class extends Ir {
|
|
2606
|
-
constructor(t = 64) {
|
|
2607
|
-
super(128, t, 16, !1), this.Ah = Q[0] | 0, this.Al = Q[1] | 0, this.Bh = Q[2] | 0, this.Bl = Q[3] | 0, this.Ch = Q[4] | 0, this.Cl = Q[5] | 0, this.Dh = Q[6] | 0, this.Dl = Q[7] | 0, this.Eh = Q[8] | 0, this.El = Q[9] | 0, this.Fh = Q[10] | 0, this.Fl = Q[11] | 0, this.Gh = Q[12] | 0, this.Gl = Q[13] | 0, this.Hh = Q[14] | 0, this.Hl = Q[15] | 0;
|
|
2608
|
-
}
|
|
2609
|
-
// prettier-ignore
|
|
2610
|
-
get() {
|
|
2611
|
-
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: c, Dl: f, Eh: l, El: h, Fh: a, Fl: d, Gh: u, Gl: y, Hh: b, Hl: w } = this;
|
|
2612
|
-
return [t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w];
|
|
2613
|
-
}
|
|
2614
|
-
// prettier-ignore
|
|
2615
|
-
set(t, n, s, r, o, i, c, f, l, h, a, d, u, y, b, w) {
|
|
2616
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = f | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = a | 0, this.Fl = d | 0, this.Gh = u | 0, this.Gl = y | 0, this.Hh = b | 0, this.Hl = w | 0;
|
|
2617
|
-
}
|
|
2618
|
-
process(t, n) {
|
|
2619
|
-
for (let p = 0; p < 16; p++, n += 4)
|
|
2620
|
-
Ut[p] = t.getUint32(n), vt[p] = t.getUint32(n += 4);
|
|
2621
|
-
for (let p = 16; p < 80; p++) {
|
|
2622
|
-
const D = Ut[p - 15] | 0, m = vt[p - 15] | 0, $ = Yt(D, m, 1) ^ Yt(D, m, 8) ^ Un(D, m, 7), C = Xt(D, m, 1) ^ Xt(D, m, 8) ^ vn(D, m, 7), _ = Ut[p - 2] | 0, x = vt[p - 2] | 0, A = Yt(_, x, 19) ^ me(_, x, 61) ^ Un(_, x, 6), g = Xt(_, x, 19) ^ Be(_, x, 61) ^ vn(_, x, 6), B = hr(C, g, vt[p - 7], vt[p - 16]), E = lr(B, $, A, Ut[p - 7], Ut[p - 16]);
|
|
2623
|
-
Ut[p] = E | 0, vt[p] = B | 0;
|
|
2624
|
-
}
|
|
2625
|
-
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: c, Cl: f, Dh: l, Dl: h, Eh: a, El: d, Fh: u, Fl: y, Gh: b, Gl: w, Hh: H, Hl: v } = this;
|
|
2626
|
-
for (let p = 0; p < 80; p++) {
|
|
2627
|
-
const D = Yt(a, d, 14) ^ Yt(a, d, 18) ^ me(a, d, 41), m = Xt(a, d, 14) ^ Xt(a, d, 18) ^ Be(a, d, 41), $ = a & u ^ ~a & b, C = d & y ^ ~d & w, _ = dr(v, m, C, vr[p], vt[p]), x = ur(_, H, D, $, Ur[p], Ut[p]), A = _ | 0, g = Yt(s, r, 28) ^ me(s, r, 34) ^ me(s, r, 39), B = Xt(s, r, 28) ^ Be(s, r, 34) ^ Be(s, r, 39), E = s & o ^ s & c ^ o & c, I = r & i ^ r & f ^ i & f;
|
|
2628
|
-
H = b | 0, v = w | 0, b = u | 0, w = y | 0, u = a | 0, y = d | 0, { h: a, l: d } = ut(l | 0, h | 0, x | 0, A | 0), l = c | 0, h = f | 0, c = o | 0, f = i | 0, o = s | 0, i = r | 0;
|
|
2629
|
-
const S = fr(A, B, I);
|
|
2630
|
-
s = ar(S, x, g, E), r = S | 0;
|
|
2631
|
-
}
|
|
2632
|
-
({ h: s, l: r } = ut(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = ut(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: c, l: f } = ut(this.Ch | 0, this.Cl | 0, c | 0, f | 0), { h: l, l: h } = ut(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: a, l: d } = ut(this.Eh | 0, this.El | 0, a | 0, d | 0), { h: u, l: y } = ut(this.Fh | 0, this.Fl | 0, u | 0, y | 0), { h: b, l: w } = ut(this.Gh | 0, this.Gl | 0, b | 0, w | 0), { h: H, l: v } = ut(this.Hh | 0, this.Hl | 0, H | 0, v | 0), this.set(s, r, o, i, c, f, l, h, a, d, u, y, b, w, H, v);
|
|
2633
|
-
}
|
|
2634
|
-
roundClean() {
|
|
2635
|
-
Se(Ut, vt);
|
|
2636
|
-
}
|
|
2637
|
-
destroy() {
|
|
2638
|
-
Se(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
2639
|
-
}
|
|
2640
|
-
};
|
|
2641
|
-
const Lr = /* @__PURE__ */ yr(() => new $r()), Si = Lr, Ii = Ps, Ui = tn;
|
|
2642
|
-
class Bs extends Xn {
|
|
2643
|
-
constructor(t, n) {
|
|
2644
|
-
super(), this.finished = !1, this.destroyed = !1, t0(t);
|
|
2645
|
-
const s = sn(n);
|
|
2646
|
-
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
2647
|
-
throw new Error("Expected instance of class which extends utils.Hash");
|
|
2648
|
-
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
2649
|
-
const r = this.blockLen, o = new Uint8Array(r);
|
|
2650
|
-
o.set(s.length > r ? t.create().update(s).digest() : s);
|
|
2651
|
-
for (let i = 0; i < o.length; i++)
|
|
2652
|
-
o[i] ^= 54;
|
|
2653
|
-
this.iHash.update(o), this.oHash = t.create();
|
|
2654
|
-
for (let i = 0; i < o.length; i++)
|
|
2655
|
-
o[i] ^= 106;
|
|
2656
|
-
this.oHash.update(o), ee(o);
|
|
2657
|
-
}
|
|
2658
|
-
update(t) {
|
|
2659
|
-
return He(this), this.iHash.update(t), this;
|
|
2660
|
-
}
|
|
2661
|
-
digestInto(t) {
|
|
2662
|
-
He(this), ot(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
2663
|
-
}
|
|
2664
|
-
digest() {
|
|
2665
|
-
const t = new Uint8Array(this.oHash.outputLen);
|
|
2666
|
-
return this.digestInto(t), t;
|
|
2667
|
-
}
|
|
2668
|
-
_cloneInto(t) {
|
|
2669
|
-
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
2670
|
-
const { oHash: n, iHash: s, finished: r, destroyed: o, blockLen: i, outputLen: c } = this;
|
|
2671
|
-
return t = t, t.finished = r, t.destroyed = o, t.blockLen = i, t.outputLen = c, t.oHash = n._cloneInto(t.oHash), t.iHash = s._cloneInto(t.iHash), t;
|
|
2672
|
-
}
|
|
2673
|
-
clone() {
|
|
2674
|
-
return this._cloneInto();
|
|
2675
|
-
}
|
|
2676
|
-
destroy() {
|
|
2677
|
-
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
const As = (e, t, n) => new Bs(e, t).update(n).digest();
|
|
2681
|
-
As.create = (e, t) => new Bs(e, t);
|
|
2682
|
-
function Cn(e) {
|
|
2683
|
-
e.lowS !== void 0 && Vt("lowS", e.lowS), e.prehash !== void 0 && Vt("prehash", e.prehash);
|
|
2684
|
-
}
|
|
2685
|
-
class Dr extends Error {
|
|
2686
|
-
constructor(t = "") {
|
|
2687
|
-
super(t);
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
const bt = {
|
|
2691
|
-
// asn.1 DER encoding utils
|
|
2692
|
-
Err: Dr,
|
|
2693
|
-
// Basic building block is TLV (Tag-Length-Value)
|
|
2694
|
-
_tlv: {
|
|
2695
|
-
encode: (e, t) => {
|
|
2696
|
-
const { Err: n } = bt;
|
|
2697
|
-
if (e < 0 || e > 256)
|
|
2698
|
-
throw new n("tlv.encode: wrong tag");
|
|
2699
|
-
if (t.length & 1)
|
|
2700
|
-
throw new n("tlv.encode: unpadded data");
|
|
2701
|
-
const s = t.length / 2, r = be(s);
|
|
2702
|
-
if (r.length / 2 & 128)
|
|
2703
|
-
throw new n("tlv.encode: long form length too big");
|
|
2704
|
-
const o = s > 127 ? be(r.length / 2 | 128) : "";
|
|
2705
|
-
return be(e) + o + r + t;
|
|
2706
|
-
},
|
|
2707
|
-
// v - value, l - left bytes (unparsed)
|
|
2708
|
-
decode(e, t) {
|
|
2709
|
-
const { Err: n } = bt;
|
|
2710
|
-
let s = 0;
|
|
2711
|
-
if (e < 0 || e > 256)
|
|
2712
|
-
throw new n("tlv.encode: wrong tag");
|
|
2713
|
-
if (t.length < 2 || t[s++] !== e)
|
|
2714
|
-
throw new n("tlv.decode: wrong tlv");
|
|
2715
|
-
const r = t[s++], o = !!(r & 128);
|
|
2716
|
-
let i = 0;
|
|
2717
|
-
if (!o)
|
|
2718
|
-
i = r;
|
|
2719
|
-
else {
|
|
2720
|
-
const f = r & 127;
|
|
2721
|
-
if (!f)
|
|
2722
|
-
throw new n("tlv.decode(long): indefinite length not supported");
|
|
2723
|
-
if (f > 4)
|
|
2724
|
-
throw new n("tlv.decode(long): byte length is too big");
|
|
2725
|
-
const l = t.subarray(s, s + f);
|
|
2726
|
-
if (l.length !== f)
|
|
2727
|
-
throw new n("tlv.decode: length bytes not complete");
|
|
2728
|
-
if (l[0] === 0)
|
|
2729
|
-
throw new n("tlv.decode(long): zero leftmost byte");
|
|
2730
|
-
for (const h of l)
|
|
2731
|
-
i = i << 8 | h;
|
|
2732
|
-
if (s += f, i < 128)
|
|
2733
|
-
throw new n("tlv.decode(long): not minimal encoding");
|
|
2734
|
-
}
|
|
2735
|
-
const c = t.subarray(s, s + i);
|
|
2736
|
-
if (c.length !== i)
|
|
2737
|
-
throw new n("tlv.decode: wrong value length");
|
|
2738
|
-
return { v: c, l: t.subarray(s + i) };
|
|
2739
|
-
}
|
|
2740
|
-
},
|
|
2741
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
2742
|
-
// since we always use positive integers here. It must always be empty:
|
|
2743
|
-
// - add zero byte if exists
|
|
2744
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
2745
|
-
_int: {
|
|
2746
|
-
encode(e) {
|
|
2747
|
-
const { Err: t } = bt;
|
|
2748
|
-
if (e < le)
|
|
2749
|
-
throw new t("integer: negative integers are not allowed");
|
|
2750
|
-
let n = be(e);
|
|
2751
|
-
if (Number.parseInt(n[0], 16) & 8 && (n = "00" + n), n.length & 1)
|
|
2752
|
-
throw new t("unexpected DER parsing assertion: unpadded hex");
|
|
2753
|
-
return n;
|
|
2754
|
-
},
|
|
2755
|
-
decode(e) {
|
|
2756
|
-
const { Err: t } = bt;
|
|
2757
|
-
if (e[0] & 128)
|
|
2758
|
-
throw new t("invalid signature integer: negative");
|
|
2759
|
-
if (e[0] === 0 && !(e[1] & 128))
|
|
2760
|
-
throw new t("invalid signature integer: unnecessary leading zero");
|
|
2761
|
-
return Ue(e);
|
|
2762
|
-
}
|
|
2763
|
-
},
|
|
2764
|
-
toSig(e) {
|
|
2765
|
-
const { Err: t, _int: n, _tlv: s } = bt, r = V("signature", e), { v: o, l: i } = s.decode(48, r);
|
|
2766
|
-
if (i.length)
|
|
2767
|
-
throw new t("invalid signature: left bytes after parsing");
|
|
2768
|
-
const { v: c, l: f } = s.decode(2, o), { v: l, l: h } = s.decode(2, f);
|
|
2769
|
-
if (h.length)
|
|
2770
|
-
throw new t("invalid signature: left bytes after parsing");
|
|
2771
|
-
return { r: n.decode(c), s: n.decode(l) };
|
|
2772
|
-
},
|
|
2773
|
-
hexFromSig(e) {
|
|
2774
|
-
const { _tlv: t, _int: n } = bt, s = t.encode(2, n.encode(e.r)), r = t.encode(2, n.encode(e.s)), o = s + r;
|
|
2775
|
-
return t.encode(48, o);
|
|
2776
|
-
}
|
|
2777
|
-
}, le = BigInt(0), de = BigInt(1), Cr = BigInt(2), Ae = BigInt(3), kr = BigInt(4);
|
|
2778
|
-
function Or(e, t, n) {
|
|
2779
|
-
function s(r) {
|
|
2780
|
-
const o = e.sqr(r), i = e.mul(o, r);
|
|
2781
|
-
return e.add(e.add(i, e.mul(r, t)), n);
|
|
2782
|
-
}
|
|
2783
|
-
return s;
|
|
2784
|
-
}
|
|
2785
|
-
function Es(e, t, n) {
|
|
2786
|
-
const { BYTES: s } = e;
|
|
2787
|
-
function r(o) {
|
|
2788
|
-
let i;
|
|
2789
|
-
if (typeof o == "bigint")
|
|
2790
|
-
i = o;
|
|
2791
|
-
else {
|
|
2792
|
-
let c = V("private key", o);
|
|
2793
|
-
if (t) {
|
|
2794
|
-
if (!t.includes(c.length * 2))
|
|
2795
|
-
throw new Error("invalid private key");
|
|
2796
|
-
const f = new Uint8Array(s);
|
|
2797
|
-
f.set(c, f.length - c.length), c = f;
|
|
2798
|
-
}
|
|
2799
|
-
try {
|
|
2800
|
-
i = e.fromBytes(c);
|
|
2801
|
-
} catch {
|
|
2802
|
-
throw new Error(`invalid private key: expected ui8a of size ${s}, got ${typeof o}`);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
if (n && (i = e.create(i)), !e.isValidNot0(i))
|
|
2806
|
-
throw new Error("invalid private key: out of range [1..N-1]");
|
|
2807
|
-
return i;
|
|
2808
|
-
}
|
|
2809
|
-
return r;
|
|
2810
|
-
}
|
|
2811
|
-
function Tr(e, t = {}) {
|
|
2812
|
-
const { Fp: n, Fn: s } = us("weierstrass", e, t), { h: r, n: o } = e;
|
|
2813
|
-
ue(t, {}, {
|
|
2814
|
-
allowInfinityPoint: "boolean",
|
|
2815
|
-
clearCofactor: "function",
|
|
2816
|
-
isTorsionFree: "function",
|
|
2817
|
-
fromBytes: "function",
|
|
2818
|
-
toBytes: "function",
|
|
2819
|
-
endo: "object",
|
|
2820
|
-
wrapPrivateKey: "boolean"
|
|
2821
|
-
});
|
|
2822
|
-
const { endo: i } = t;
|
|
2823
|
-
if (i && (!n.is0(e.a) || typeof i.beta != "bigint" || typeof i.splitScalar != "function"))
|
|
2824
|
-
throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
|
|
2825
|
-
function c() {
|
|
2826
|
-
if (!n.isOdd)
|
|
2827
|
-
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
2828
|
-
}
|
|
2829
|
-
function f(_, x, A) {
|
|
2830
|
-
const { x: g, y: B } = x.toAffine(), E = n.toBytes(g);
|
|
2831
|
-
if (Vt("isCompressed", A), A) {
|
|
2832
|
-
c();
|
|
2833
|
-
const I = !n.isOdd(B);
|
|
2834
|
-
return wt(Hs(I), E);
|
|
2835
|
-
} else
|
|
2836
|
-
return wt(Uint8Array.of(4), E, n.toBytes(B));
|
|
2837
|
-
}
|
|
2838
|
-
function l(_) {
|
|
2839
|
-
ot(_);
|
|
2840
|
-
const x = n.BYTES, A = x + 1, g = 2 * x + 1, B = _.length, E = _[0], I = _.subarray(1);
|
|
2841
|
-
if (B === A && (E === 2 || E === 3)) {
|
|
2842
|
-
const S = n.fromBytes(I);
|
|
2843
|
-
if (!n.isValid(S))
|
|
2844
|
-
throw new Error("bad point: is not on curve, wrong x");
|
|
2845
|
-
const L = d(S);
|
|
2846
|
-
let O;
|
|
2847
|
-
try {
|
|
2848
|
-
O = n.sqrt(L);
|
|
2849
|
-
} catch (N) {
|
|
2850
|
-
const T = N instanceof Error ? ": " + N.message : "";
|
|
2851
|
-
throw new Error("bad point: is not on curve, sqrt error" + T);
|
|
2852
|
-
}
|
|
2853
|
-
c();
|
|
2854
|
-
const k = n.isOdd(O);
|
|
2855
|
-
return (E & 1) === 1 !== k && (O = n.neg(O)), { x: S, y: O };
|
|
2856
|
-
} else if (B === g && E === 4) {
|
|
2857
|
-
const S = n.fromBytes(I.subarray(x * 0, x * 1)), L = n.fromBytes(I.subarray(x * 1, x * 2));
|
|
2858
|
-
if (!u(S, L))
|
|
2859
|
-
throw new Error("bad point: is not on curve");
|
|
2860
|
-
return { x: S, y: L };
|
|
2861
|
-
} else
|
|
2862
|
-
throw new Error(`bad point: got length ${B}, expected compressed=${A} or uncompressed=${g}`);
|
|
2863
|
-
}
|
|
2864
|
-
const h = t.toBytes || f, a = t.fromBytes || l, d = Or(n, e.a, e.b);
|
|
2865
|
-
function u(_, x) {
|
|
2866
|
-
const A = n.sqr(x), g = d(_);
|
|
2867
|
-
return n.eql(A, g);
|
|
2868
|
-
}
|
|
2869
|
-
if (!u(e.Gx, e.Gy))
|
|
2870
|
-
throw new Error("bad curve params: generator point");
|
|
2871
|
-
const y = n.mul(n.pow(e.a, Ae), kr), b = n.mul(n.sqr(e.b), BigInt(27));
|
|
2872
|
-
if (n.is0(n.add(y, b)))
|
|
2873
|
-
throw new Error("bad curve params: a or b");
|
|
2874
|
-
function w(_, x, A = !1) {
|
|
2875
|
-
if (!n.isValid(x) || A && n.is0(x))
|
|
2876
|
-
throw new Error(`bad point coordinate ${_}`);
|
|
2877
|
-
return x;
|
|
2878
|
-
}
|
|
2879
|
-
function H(_) {
|
|
2880
|
-
if (!(_ instanceof m))
|
|
2881
|
-
throw new Error("ProjectivePoint expected");
|
|
2882
|
-
}
|
|
2883
|
-
const v = _e((_, x) => {
|
|
2884
|
-
const { px: A, py: g, pz: B } = _;
|
|
2885
|
-
if (n.eql(B, n.ONE))
|
|
2886
|
-
return { x: A, y: g };
|
|
2887
|
-
const E = _.is0();
|
|
2888
|
-
x == null && (x = E ? n.ONE : n.inv(B));
|
|
2889
|
-
const I = n.mul(A, x), S = n.mul(g, x), L = n.mul(B, x);
|
|
2890
|
-
if (E)
|
|
2891
|
-
return { x: n.ZERO, y: n.ZERO };
|
|
2892
|
-
if (!n.eql(L, n.ONE))
|
|
2893
|
-
throw new Error("invZ was invalid");
|
|
2894
|
-
return { x: I, y: S };
|
|
2895
|
-
}), p = _e((_) => {
|
|
2896
|
-
if (_.is0()) {
|
|
2897
|
-
if (t.allowInfinityPoint && !n.is0(_.py))
|
|
2898
|
-
return;
|
|
2899
|
-
throw new Error("bad point: ZERO");
|
|
2900
|
-
}
|
|
2901
|
-
const { x, y: A } = _.toAffine();
|
|
2902
|
-
if (!n.isValid(x) || !n.isValid(A))
|
|
2903
|
-
throw new Error("bad point: x or y not field elements");
|
|
2904
|
-
if (!u(x, A))
|
|
2905
|
-
throw new Error("bad point: equation left != right");
|
|
2906
|
-
if (!_.isTorsionFree())
|
|
2907
|
-
throw new Error("bad point: not in prime-order subgroup");
|
|
2908
|
-
return !0;
|
|
2909
|
-
});
|
|
2910
|
-
function D(_, x, A, g, B) {
|
|
2911
|
-
return A = new m(n.mul(A.px, _), A.py, A.pz), x = he(g, x), A = he(B, A), x.add(A);
|
|
2912
|
-
}
|
|
2913
|
-
class m {
|
|
2914
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2915
|
-
constructor(x, A, g) {
|
|
2916
|
-
this.px = w("x", x), this.py = w("y", A, !0), this.pz = w("z", g), Object.freeze(this);
|
|
2917
|
-
}
|
|
2918
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2919
|
-
static fromAffine(x) {
|
|
2920
|
-
const { x: A, y: g } = x || {};
|
|
2921
|
-
if (!x || !n.isValid(A) || !n.isValid(g))
|
|
2922
|
-
throw new Error("invalid affine point");
|
|
2923
|
-
if (x instanceof m)
|
|
2924
|
-
throw new Error("projective point not allowed");
|
|
2925
|
-
return n.is0(A) && n.is0(g) ? m.ZERO : new m(A, g, n.ONE);
|
|
2926
|
-
}
|
|
2927
|
-
get x() {
|
|
2928
|
-
return this.toAffine().x;
|
|
2929
|
-
}
|
|
2930
|
-
get y() {
|
|
2931
|
-
return this.toAffine().y;
|
|
2932
|
-
}
|
|
2933
|
-
static normalizeZ(x) {
|
|
2934
|
-
return as(m, "pz", x);
|
|
2935
|
-
}
|
|
2936
|
-
static fromBytes(x) {
|
|
2937
|
-
return ot(x), m.fromHex(x);
|
|
2938
|
-
}
|
|
2939
|
-
/** Converts hash string or Uint8Array to Point. */
|
|
2940
|
-
static fromHex(x) {
|
|
2941
|
-
const A = m.fromAffine(a(V("pointHex", x)));
|
|
2942
|
-
return A.assertValidity(), A;
|
|
2943
|
-
}
|
|
2944
|
-
/** Multiplies generator point by privateKey. */
|
|
2945
|
-
static fromPrivateKey(x) {
|
|
2946
|
-
const A = Es(s, t.allowedPrivateKeyLengths, t.wrapPrivateKey);
|
|
2947
|
-
return m.BASE.multiply(A(x));
|
|
2948
|
-
}
|
|
2949
|
-
/** Multiscalar Multiplication */
|
|
2950
|
-
static msm(x, A) {
|
|
2951
|
-
return cn(m, s, x, A);
|
|
2952
|
-
}
|
|
2953
|
-
/**
|
|
2954
|
-
*
|
|
2955
|
-
* @param windowSize
|
|
2956
|
-
* @param isLazy true will defer table computation until the first multiplication
|
|
2957
|
-
* @returns
|
|
2958
|
-
*/
|
|
2959
|
-
precompute(x = 8, A = !0) {
|
|
2960
|
-
return C.setWindowSize(this, x), A || this.multiply(Ae), this;
|
|
2961
|
-
}
|
|
2962
|
-
/** "Private method", don't use it directly */
|
|
2963
|
-
_setWindowSize(x) {
|
|
2964
|
-
this.precompute(x);
|
|
2965
|
-
}
|
|
2966
|
-
// TODO: return `this`
|
|
2967
|
-
/** A point on curve is valid if it conforms to equation. */
|
|
2968
|
-
assertValidity() {
|
|
2969
|
-
p(this);
|
|
2970
|
-
}
|
|
2971
|
-
hasEvenY() {
|
|
2972
|
-
const { y: x } = this.toAffine();
|
|
2973
|
-
if (!n.isOdd)
|
|
2974
|
-
throw new Error("Field doesn't support isOdd");
|
|
2975
|
-
return !n.isOdd(x);
|
|
2976
|
-
}
|
|
2977
|
-
/** Compare one point to another. */
|
|
2978
|
-
equals(x) {
|
|
2979
|
-
H(x);
|
|
2980
|
-
const { px: A, py: g, pz: B } = this, { px: E, py: I, pz: S } = x, L = n.eql(n.mul(A, S), n.mul(E, B)), O = n.eql(n.mul(g, S), n.mul(I, B));
|
|
2981
|
-
return L && O;
|
|
2982
|
-
}
|
|
2983
|
-
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
2984
|
-
negate() {
|
|
2985
|
-
return new m(this.px, n.neg(this.py), this.pz);
|
|
2986
|
-
}
|
|
2987
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
2988
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2989
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2990
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2991
|
-
double() {
|
|
2992
|
-
const { a: x, b: A } = e, g = n.mul(A, Ae), { px: B, py: E, pz: I } = this;
|
|
2993
|
-
let S = n.ZERO, L = n.ZERO, O = n.ZERO, k = n.mul(B, B), G = n.mul(E, E), N = n.mul(I, I), T = n.mul(B, E);
|
|
2994
|
-
return T = n.add(T, T), O = n.mul(B, I), O = n.add(O, O), S = n.mul(x, O), L = n.mul(g, N), L = n.add(S, L), S = n.sub(G, L), L = n.add(G, L), L = n.mul(S, L), S = n.mul(T, S), O = n.mul(g, O), N = n.mul(x, N), T = n.sub(k, N), T = n.mul(x, T), T = n.add(T, O), O = n.add(k, k), k = n.add(O, k), k = n.add(k, N), k = n.mul(k, T), L = n.add(L, k), N = n.mul(E, I), N = n.add(N, N), k = n.mul(N, T), S = n.sub(S, k), O = n.mul(N, G), O = n.add(O, O), O = n.add(O, O), new m(S, L, O);
|
|
2995
|
-
}
|
|
2996
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
2997
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2998
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2999
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
3000
|
-
add(x) {
|
|
3001
|
-
H(x);
|
|
3002
|
-
const { px: A, py: g, pz: B } = this, { px: E, py: I, pz: S } = x;
|
|
3003
|
-
let L = n.ZERO, O = n.ZERO, k = n.ZERO;
|
|
3004
|
-
const G = e.a, N = n.mul(e.b, Ae);
|
|
3005
|
-
let T = n.mul(A, E), M = n.mul(g, I), F = n.mul(B, S), Y = n.add(A, g), q = n.add(E, I);
|
|
3006
|
-
Y = n.mul(Y, q), q = n.add(T, M), Y = n.sub(Y, q), q = n.add(A, B);
|
|
3007
|
-
let J = n.add(E, S);
|
|
3008
|
-
return q = n.mul(q, J), J = n.add(T, F), q = n.sub(q, J), J = n.add(g, B), L = n.add(I, S), J = n.mul(J, L), L = n.add(M, F), J = n.sub(J, L), k = n.mul(G, q), L = n.mul(N, F), k = n.add(L, k), L = n.sub(M, k), k = n.add(M, k), O = n.mul(L, k), M = n.add(T, T), M = n.add(M, T), F = n.mul(G, F), q = n.mul(N, q), M = n.add(M, F), F = n.sub(T, F), F = n.mul(G, F), q = n.add(q, F), T = n.mul(M, q), O = n.add(O, T), T = n.mul(J, q), L = n.mul(Y, L), L = n.sub(L, T), T = n.mul(Y, M), k = n.mul(J, k), k = n.add(k, T), new m(L, O, k);
|
|
3009
|
-
}
|
|
3010
|
-
subtract(x) {
|
|
3011
|
-
return this.add(x.negate());
|
|
3012
|
-
}
|
|
3013
|
-
is0() {
|
|
3014
|
-
return this.equals(m.ZERO);
|
|
3015
|
-
}
|
|
3016
|
-
/**
|
|
3017
|
-
* Constant time multiplication.
|
|
3018
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
3019
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
3020
|
-
* Uses precomputes when available.
|
|
3021
|
-
* Uses endomorphism for Koblitz curves.
|
|
3022
|
-
* @param scalar by which the point would be multiplied
|
|
3023
|
-
* @returns New point
|
|
3024
|
-
*/
|
|
3025
|
-
multiply(x) {
|
|
3026
|
-
const { endo: A } = t;
|
|
3027
|
-
if (!s.isValidNot0(x))
|
|
3028
|
-
throw new Error("invalid scalar: out of range");
|
|
3029
|
-
let g, B;
|
|
3030
|
-
const E = (I) => C.wNAFCached(this, I, m.normalizeZ);
|
|
3031
|
-
if (A) {
|
|
3032
|
-
const { k1neg: I, k1: S, k2neg: L, k2: O } = A.splitScalar(x), { p: k, f: G } = E(S), { p: N, f: T } = E(O);
|
|
3033
|
-
B = G.add(T), g = D(A.beta, k, N, I, L);
|
|
3034
|
-
} else {
|
|
3035
|
-
const { p: I, f: S } = E(x);
|
|
3036
|
-
g = I, B = S;
|
|
3037
|
-
}
|
|
3038
|
-
return m.normalizeZ([g, B])[0];
|
|
3039
|
-
}
|
|
3040
|
-
/**
|
|
3041
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
3042
|
-
* It's faster, but should only be used when you don't care about
|
|
3043
|
-
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
3044
|
-
*/
|
|
3045
|
-
multiplyUnsafe(x) {
|
|
3046
|
-
const { endo: A } = t, g = this;
|
|
3047
|
-
if (!s.isValid(x))
|
|
3048
|
-
throw new Error("invalid scalar: out of range");
|
|
3049
|
-
if (x === le || g.is0())
|
|
3050
|
-
return m.ZERO;
|
|
3051
|
-
if (x === de)
|
|
3052
|
-
return g;
|
|
3053
|
-
if (C.hasPrecomputes(this))
|
|
3054
|
-
return this.multiply(x);
|
|
3055
|
-
if (A) {
|
|
3056
|
-
const { k1neg: B, k1: E, k2neg: I, k2: S } = A.splitScalar(x), { p1: L, p2: O } = N0(m, g, E, S);
|
|
3057
|
-
return D(A.beta, L, O, B, I);
|
|
3058
|
-
} else
|
|
3059
|
-
return C.wNAFCachedUnsafe(g, x);
|
|
3060
|
-
}
|
|
3061
|
-
multiplyAndAddUnsafe(x, A, g) {
|
|
3062
|
-
const B = this.multiplyUnsafe(A).add(x.multiplyUnsafe(g));
|
|
3063
|
-
return B.is0() ? void 0 : B;
|
|
3064
|
-
}
|
|
3065
|
-
/**
|
|
3066
|
-
* Converts Projective point to affine (x, y) coordinates.
|
|
3067
|
-
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
3068
|
-
*/
|
|
3069
|
-
toAffine(x) {
|
|
3070
|
-
return v(this, x);
|
|
3071
|
-
}
|
|
3072
|
-
/**
|
|
3073
|
-
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
3074
|
-
* Always torsion-free for cofactor=1 curves.
|
|
3075
|
-
*/
|
|
3076
|
-
isTorsionFree() {
|
|
3077
|
-
const { isTorsionFree: x } = t;
|
|
3078
|
-
return r === de ? !0 : x ? x(m, this) : C.wNAFCachedUnsafe(this, o).is0();
|
|
3079
|
-
}
|
|
3080
|
-
clearCofactor() {
|
|
3081
|
-
const { clearCofactor: x } = t;
|
|
3082
|
-
return r === de ? this : x ? x(m, this) : this.multiplyUnsafe(r);
|
|
3083
|
-
}
|
|
3084
|
-
toBytes(x = !0) {
|
|
3085
|
-
return Vt("isCompressed", x), this.assertValidity(), h(m, this, x);
|
|
3086
|
-
}
|
|
3087
|
-
/** @deprecated use `toBytes` */
|
|
3088
|
-
toRawBytes(x = !0) {
|
|
3089
|
-
return this.toBytes(x);
|
|
3090
|
-
}
|
|
3091
|
-
toHex(x = !0) {
|
|
3092
|
-
return Mt(this.toBytes(x));
|
|
3093
|
-
}
|
|
3094
|
-
toString() {
|
|
3095
|
-
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
m.BASE = new m(e.Gx, e.Gy, n.ONE), m.ZERO = new m(n.ZERO, n.ONE, n.ZERO), m.Fp = n, m.Fn = s;
|
|
3099
|
-
const $ = s.BITS, C = ds(m, t.endo ? Math.ceil($ / 2) : $);
|
|
3100
|
-
return m;
|
|
3101
|
-
}
|
|
3102
|
-
function Hs(e) {
|
|
3103
|
-
return Uint8Array.of(e ? 2 : 3);
|
|
3104
|
-
}
|
|
3105
|
-
function Nr(e, t, n = {}) {
|
|
3106
|
-
ue(t, { hash: "function" }, {
|
|
3107
|
-
hmac: "function",
|
|
3108
|
-
lowS: "boolean",
|
|
3109
|
-
randomBytes: "function",
|
|
3110
|
-
bits2int: "function",
|
|
3111
|
-
bits2int_modN: "function"
|
|
3112
|
-
});
|
|
3113
|
-
const s = t.randomBytes || Qn, r = t.hmac || ((g, ...B) => As(t.hash, g, wt(...B))), { Fp: o, Fn: i } = e, { ORDER: c, BITS: f } = i;
|
|
3114
|
-
function l(g) {
|
|
3115
|
-
const B = c >> de;
|
|
3116
|
-
return g > B;
|
|
3117
|
-
}
|
|
3118
|
-
function h(g) {
|
|
3119
|
-
return l(g) ? i.neg(g) : g;
|
|
3120
|
-
}
|
|
3121
|
-
function a(g, B) {
|
|
3122
|
-
if (!i.isValidNot0(B))
|
|
3123
|
-
throw new Error(`invalid signature ${g}: out of range 1..CURVE.n`);
|
|
3124
|
-
}
|
|
3125
|
-
class d {
|
|
3126
|
-
constructor(B, E, I) {
|
|
3127
|
-
a("r", B), a("s", E), this.r = B, this.s = E, I != null && (this.recovery = I), Object.freeze(this);
|
|
3128
|
-
}
|
|
3129
|
-
// pair (bytes of r, bytes of s)
|
|
3130
|
-
static fromCompact(B) {
|
|
3131
|
-
const E = i.BYTES, I = V("compactSignature", B, E * 2);
|
|
3132
|
-
return new d(i.fromBytes(I.subarray(0, E)), i.fromBytes(I.subarray(E, E * 2)));
|
|
3133
|
-
}
|
|
3134
|
-
// DER encoded ECDSA signature
|
|
3135
|
-
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
3136
|
-
static fromDER(B) {
|
|
3137
|
-
const { r: E, s: I } = bt.toSig(V("DER", B));
|
|
3138
|
-
return new d(E, I);
|
|
3139
|
-
}
|
|
3140
|
-
/**
|
|
3141
|
-
* @todo remove
|
|
3142
|
-
* @deprecated
|
|
3143
|
-
*/
|
|
3144
|
-
assertValidity() {
|
|
3145
|
-
}
|
|
3146
|
-
addRecoveryBit(B) {
|
|
3147
|
-
return new d(this.r, this.s, B);
|
|
3148
|
-
}
|
|
3149
|
-
// ProjPointType<bigint>
|
|
3150
|
-
recoverPublicKey(B) {
|
|
3151
|
-
const E = o.ORDER, { r: I, s: S, recovery: L } = this;
|
|
3152
|
-
if (L == null || ![0, 1, 2, 3].includes(L))
|
|
3153
|
-
throw new Error("recovery id invalid");
|
|
3154
|
-
if (c * Cr < E && L > 1)
|
|
3155
|
-
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
3156
|
-
const k = L === 2 || L === 3 ? I + c : I;
|
|
3157
|
-
if (!o.isValid(k))
|
|
3158
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
3159
|
-
const G = o.toBytes(k), N = e.fromHex(wt(Hs((L & 1) === 0), G)), T = i.inv(k), M = p(V("msgHash", B)), F = i.create(-M * T), Y = i.create(S * T), q = e.BASE.multiplyUnsafe(F).add(N.multiplyUnsafe(Y));
|
|
3160
|
-
if (q.is0())
|
|
3161
|
-
throw new Error("point at infinify");
|
|
3162
|
-
return q.assertValidity(), q;
|
|
3163
|
-
}
|
|
3164
|
-
// Signatures should be low-s, to prevent malleability.
|
|
3165
|
-
hasHighS() {
|
|
3166
|
-
return l(this.s);
|
|
3167
|
-
}
|
|
3168
|
-
normalizeS() {
|
|
3169
|
-
return this.hasHighS() ? new d(this.r, i.neg(this.s), this.recovery) : this;
|
|
3170
|
-
}
|
|
3171
|
-
toBytes(B) {
|
|
3172
|
-
if (B === "compact")
|
|
3173
|
-
return wt(i.toBytes(this.r), i.toBytes(this.s));
|
|
3174
|
-
if (B === "der")
|
|
3175
|
-
return nn(bt.hexFromSig(this));
|
|
3176
|
-
throw new Error("invalid format");
|
|
3177
|
-
}
|
|
3178
|
-
// DER-encoded
|
|
3179
|
-
toDERRawBytes() {
|
|
3180
|
-
return this.toBytes("der");
|
|
3181
|
-
}
|
|
3182
|
-
toDERHex() {
|
|
3183
|
-
return Mt(this.toBytes("der"));
|
|
3184
|
-
}
|
|
3185
|
-
// padded bytes of r, then padded bytes of s
|
|
3186
|
-
toCompactRawBytes() {
|
|
3187
|
-
return this.toBytes("compact");
|
|
3188
|
-
}
|
|
3189
|
-
toCompactHex() {
|
|
3190
|
-
return Mt(this.toBytes("compact"));
|
|
3191
|
-
}
|
|
3192
|
-
}
|
|
3193
|
-
const u = Es(i, n.allowedPrivateKeyLengths, n.wrapPrivateKey), y = {
|
|
3194
|
-
isValidPrivateKey(g) {
|
|
3195
|
-
try {
|
|
3196
|
-
return u(g), !0;
|
|
3197
|
-
} catch {
|
|
3198
|
-
return !1;
|
|
3199
|
-
}
|
|
3200
|
-
},
|
|
3201
|
-
normPrivateKeyToScalar: u,
|
|
3202
|
-
/**
|
|
3203
|
-
* Produces cryptographically secure private key from random of size
|
|
3204
|
-
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
3205
|
-
*/
|
|
3206
|
-
randomPrivateKey: () => {
|
|
3207
|
-
const g = c;
|
|
3208
|
-
return w0(s(os(g)), g);
|
|
3209
|
-
},
|
|
3210
|
-
precompute(g = 8, B = e.BASE) {
|
|
3211
|
-
return B.precompute(g, !1);
|
|
3212
|
-
}
|
|
3213
|
-
};
|
|
3214
|
-
function b(g, B = !0) {
|
|
3215
|
-
return e.fromPrivateKey(g).toBytes(B);
|
|
3216
|
-
}
|
|
3217
|
-
function w(g) {
|
|
3218
|
-
if (typeof g == "bigint")
|
|
3219
|
-
return !1;
|
|
3220
|
-
if (g instanceof e)
|
|
3221
|
-
return !0;
|
|
3222
|
-
const E = V("key", g).length, I = o.BYTES, S = I + 1, L = 2 * I + 1;
|
|
3223
|
-
if (!(n.allowedPrivateKeyLengths || i.BYTES === S))
|
|
3224
|
-
return E === S || E === L;
|
|
3225
|
-
}
|
|
3226
|
-
function H(g, B, E = !0) {
|
|
3227
|
-
if (w(g) === !0)
|
|
3228
|
-
throw new Error("first arg must be private key");
|
|
3229
|
-
if (w(B) === !1)
|
|
3230
|
-
throw new Error("second arg must be public key");
|
|
3231
|
-
return e.fromHex(B).multiply(u(g)).toBytes(E);
|
|
3232
|
-
}
|
|
3233
|
-
const v = t.bits2int || function(g) {
|
|
3234
|
-
if (g.length > 8192)
|
|
3235
|
-
throw new Error("input is too large");
|
|
3236
|
-
const B = Ue(g), E = g.length * 8 - f;
|
|
3237
|
-
return E > 0 ? B >> BigInt(E) : B;
|
|
3238
|
-
}, p = t.bits2int_modN || function(g) {
|
|
3239
|
-
return i.create(v(g));
|
|
3240
|
-
}, D = ve(f);
|
|
3241
|
-
function m(g) {
|
|
3242
|
-
return Jt("num < 2^" + f, g, le, D), i.toBytes(g);
|
|
3243
|
-
}
|
|
3244
|
-
function $(g, B, E = C) {
|
|
3245
|
-
if (["recovered", "canonical"].some((Y) => Y in E))
|
|
3246
|
-
throw new Error("sign() legacy options not supported");
|
|
3247
|
-
const { hash: I } = t;
|
|
3248
|
-
let { lowS: S, prehash: L, extraEntropy: O } = E;
|
|
3249
|
-
S == null && (S = !0), g = V("msgHash", g), Cn(E), L && (g = V("prehashed msgHash", I(g)));
|
|
3250
|
-
const k = p(g), G = u(B), N = [m(G), m(k)];
|
|
3251
|
-
if (O != null && O !== !1) {
|
|
3252
|
-
const Y = O === !0 ? s(o.BYTES) : O;
|
|
3253
|
-
N.push(V("extraEntropy", Y));
|
|
3254
|
-
}
|
|
3255
|
-
const T = wt(...N), M = k;
|
|
3256
|
-
function F(Y) {
|
|
3257
|
-
const q = v(Y);
|
|
3258
|
-
if (!i.isValidNot0(q))
|
|
3259
|
-
return;
|
|
3260
|
-
const J = i.inv(q), oe = e.BASE.multiply(q).toAffine(), zt = i.create(oe.x);
|
|
3261
|
-
if (zt === le)
|
|
3262
|
-
return;
|
|
3263
|
-
const Nt = i.create(J * i.create(M + zt * G));
|
|
3264
|
-
if (Nt === le)
|
|
3265
|
-
return;
|
|
3266
|
-
let De = (oe.x === zt ? 0 : 2) | Number(oe.y & de), jt = Nt;
|
|
3267
|
-
return S && l(Nt) && (jt = h(Nt), De ^= 1), new d(zt, jt, De);
|
|
3268
|
-
}
|
|
3269
|
-
return { seed: T, k2sig: F };
|
|
3270
|
-
}
|
|
3271
|
-
const C = { lowS: t.lowS, prehash: !1 }, _ = { lowS: t.lowS, prehash: !1 };
|
|
3272
|
-
function x(g, B, E = C) {
|
|
3273
|
-
const { seed: I, k2sig: S } = $(g, B, E);
|
|
3274
|
-
return c0(t.hash.outputLen, i.BYTES, r)(I, S);
|
|
3275
|
-
}
|
|
3276
|
-
e.BASE.precompute(8);
|
|
3277
|
-
function A(g, B, E, I = _) {
|
|
3278
|
-
const S = g;
|
|
3279
|
-
B = V("msgHash", B), E = V("publicKey", E), Cn(I);
|
|
3280
|
-
const { lowS: L, prehash: O, format: k } = I;
|
|
3281
|
-
if ("strict" in I)
|
|
3282
|
-
throw new Error("options.strict was renamed to lowS");
|
|
3283
|
-
if (k !== void 0 && !["compact", "der", "js"].includes(k))
|
|
3284
|
-
throw new Error('format must be "compact", "der" or "js"');
|
|
3285
|
-
const G = typeof S == "string" || en(S), N = !G && !k && typeof S == "object" && S !== null && typeof S.r == "bigint" && typeof S.s == "bigint";
|
|
3286
|
-
if (!G && !N)
|
|
3287
|
-
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
3288
|
-
let T, M;
|
|
3289
|
-
try {
|
|
3290
|
-
if (N)
|
|
3291
|
-
if (k === void 0 || k === "js")
|
|
3292
|
-
T = new d(S.r, S.s);
|
|
3293
|
-
else
|
|
3294
|
-
throw new Error("invalid format");
|
|
3295
|
-
if (G) {
|
|
3296
|
-
try {
|
|
3297
|
-
k !== "compact" && (T = d.fromDER(S));
|
|
3298
|
-
} catch (jt) {
|
|
3299
|
-
if (!(jt instanceof bt.Err))
|
|
3300
|
-
throw jt;
|
|
3301
|
-
}
|
|
3302
|
-
!T && k !== "der" && (T = d.fromCompact(S));
|
|
3303
|
-
}
|
|
3304
|
-
M = e.fromHex(E);
|
|
3305
|
-
} catch {
|
|
3306
|
-
return !1;
|
|
3307
|
-
}
|
|
3308
|
-
if (!T || L && T.hasHighS())
|
|
3309
|
-
return !1;
|
|
3310
|
-
O && (B = t.hash(B));
|
|
3311
|
-
const { r: F, s: Y } = T, q = p(B), J = i.inv(Y), oe = i.create(q * J), zt = i.create(F * J), Nt = e.BASE.multiplyUnsafe(oe).add(M.multiplyUnsafe(zt));
|
|
3312
|
-
return Nt.is0() ? !1 : i.create(Nt.x) === F;
|
|
3313
|
-
}
|
|
3314
|
-
return Object.freeze({
|
|
3315
|
-
getPublicKey: b,
|
|
3316
|
-
getSharedSecret: H,
|
|
3317
|
-
sign: x,
|
|
3318
|
-
verify: A,
|
|
3319
|
-
utils: y,
|
|
3320
|
-
Point: e,
|
|
3321
|
-
Signature: d
|
|
3322
|
-
});
|
|
3323
|
-
}
|
|
3324
|
-
function Rr(e) {
|
|
3325
|
-
const t = {
|
|
3326
|
-
a: e.a,
|
|
3327
|
-
b: e.b,
|
|
3328
|
-
p: e.Fp.ORDER,
|
|
3329
|
-
n: e.n,
|
|
3330
|
-
h: e.h,
|
|
3331
|
-
Gx: e.Gx,
|
|
3332
|
-
Gy: e.Gy
|
|
3333
|
-
}, n = e.Fp, s = Zt(t.n, e.nBitLength), r = {
|
|
3334
|
-
Fp: n,
|
|
3335
|
-
Fn: s,
|
|
3336
|
-
allowedPrivateKeyLengths: e.allowedPrivateKeyLengths,
|
|
3337
|
-
allowInfinityPoint: e.allowInfinityPoint,
|
|
3338
|
-
endo: e.endo,
|
|
3339
|
-
wrapPrivateKey: e.wrapPrivateKey,
|
|
3340
|
-
isTorsionFree: e.isTorsionFree,
|
|
3341
|
-
clearCofactor: e.clearCofactor,
|
|
3342
|
-
fromBytes: e.fromBytes,
|
|
3343
|
-
toBytes: e.toBytes
|
|
3344
|
-
};
|
|
3345
|
-
return { CURVE: t, curveOpts: r };
|
|
3346
|
-
}
|
|
3347
|
-
function Gr(e) {
|
|
3348
|
-
const { CURVE: t, curveOpts: n } = Rr(e), s = {
|
|
3349
|
-
hash: e.hash,
|
|
3350
|
-
hmac: e.hmac,
|
|
3351
|
-
randomBytes: e.randomBytes,
|
|
3352
|
-
lowS: e.lowS,
|
|
3353
|
-
bits2int: e.bits2int,
|
|
3354
|
-
bits2int_modN: e.bits2int_modN
|
|
3355
|
-
};
|
|
3356
|
-
return { CURVE: t, curveOpts: n, ecdsaOpts: s };
|
|
3357
|
-
}
|
|
3358
|
-
function qr(e, t) {
|
|
3359
|
-
return Object.assign({}, t, {
|
|
3360
|
-
ProjectivePoint: t.Point,
|
|
3361
|
-
CURVE: e
|
|
3362
|
-
});
|
|
3363
|
-
}
|
|
3364
|
-
function Mr(e) {
|
|
3365
|
-
const { CURVE: t, curveOpts: n, ecdsaOpts: s } = Gr(e), r = Tr(t, n), o = Nr(r, s, n);
|
|
3366
|
-
return qr(e, o);
|
|
3367
|
-
}
|
|
3368
|
-
function Vr(e, t) {
|
|
3369
|
-
const n = (s) => Mr({ ...e, hash: s });
|
|
3370
|
-
return { ...n(t), create: n };
|
|
3371
|
-
}
|
|
3372
|
-
const Ie = {
|
|
3373
|
-
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
3374
|
-
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
3375
|
-
h: BigInt(1),
|
|
3376
|
-
a: BigInt(0),
|
|
3377
|
-
b: BigInt(7),
|
|
3378
|
-
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
3379
|
-
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
3380
|
-
};
|
|
3381
|
-
BigInt(0);
|
|
3382
|
-
const Zr = BigInt(1), Ke = BigInt(2), kn = (e, t) => (e + t / Ke) / t;
|
|
3383
|
-
function zr(e) {
|
|
3384
|
-
const t = Ie.p, n = BigInt(3), s = BigInt(6), r = BigInt(11), o = BigInt(22), i = BigInt(23), c = BigInt(44), f = BigInt(88), l = e * e * e % t, h = l * l * e % t, a = Z(h, n, t) * h % t, d = Z(a, n, t) * h % t, u = Z(d, Ke, t) * l % t, y = Z(u, r, t) * u % t, b = Z(y, o, t) * y % t, w = Z(b, c, t) * b % t, H = Z(w, f, t) * w % t, v = Z(H, c, t) * b % t, p = Z(v, n, t) * h % t, D = Z(p, i, t) * y % t, m = Z(D, s, t) * l % t, $ = Z(m, Ke, t);
|
|
3385
|
-
if (!Ye.eql(Ye.sqr($), e))
|
|
3386
|
-
throw new Error("Cannot find square root");
|
|
3387
|
-
return $;
|
|
3388
|
-
}
|
|
3389
|
-
const Ye = Zt(Ie.p, void 0, void 0, { sqrt: zr }), vi = Vr({
|
|
3390
|
-
...Ie,
|
|
3391
|
-
Fp: Ye,
|
|
3392
|
-
lowS: !0,
|
|
3393
|
-
// Allow only low-S signatures by default in sign() and verify()
|
|
3394
|
-
endo: {
|
|
3395
|
-
// Endomorphism, see above
|
|
3396
|
-
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
3397
|
-
splitScalar: (e) => {
|
|
3398
|
-
const t = Ie.n, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), s = -Zr * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), r = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), o = n, i = BigInt("0x100000000000000000000000000000000"), c = kn(o * e, t), f = kn(-s * e, t);
|
|
3399
|
-
let l = z(e - c * n - f * r, t), h = z(-c * s - f * o, t);
|
|
3400
|
-
const a = l > i, d = h > i;
|
|
3401
|
-
if (a && (l = t - l), d && (h = t - h), l > i || h > i)
|
|
3402
|
-
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
3403
|
-
return { k1neg: a, k1: l, k2neg: d, k2: h };
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
}, C0);
|
|
3407
|
-
function jr(e) {
|
|
3408
|
-
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
3409
|
-
}
|
|
3410
|
-
function an(e, ...t) {
|
|
3411
|
-
if (!jr(e))
|
|
3412
|
-
throw new Error("Uint8Array expected");
|
|
3413
|
-
if (t.length > 0 && !t.includes(e.length))
|
|
3414
|
-
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
3415
|
-
}
|
|
3416
|
-
function On(e, t = !0) {
|
|
3417
|
-
if (e.destroyed)
|
|
3418
|
-
throw new Error("Hash instance has been destroyed");
|
|
3419
|
-
if (t && e.finished)
|
|
3420
|
-
throw new Error("Hash#digest() has already been called");
|
|
3421
|
-
}
|
|
3422
|
-
function Wr(e, t) {
|
|
3423
|
-
an(e);
|
|
3424
|
-
const n = t.outputLen;
|
|
3425
|
-
if (e.length < n)
|
|
3426
|
-
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
3427
|
-
}
|
|
3428
|
-
function Xe(...e) {
|
|
3429
|
-
for (let t = 0; t < e.length; t++)
|
|
3430
|
-
e[t].fill(0);
|
|
3431
|
-
}
|
|
3432
|
-
function Ze(e) {
|
|
3433
|
-
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
3434
|
-
}
|
|
3435
|
-
function at(e, t) {
|
|
3436
|
-
return e << 32 - t | e >>> t;
|
|
3437
|
-
}
|
|
3438
|
-
function Fr(e) {
|
|
3439
|
-
if (typeof e != "string")
|
|
3440
|
-
throw new Error("string expected");
|
|
3441
|
-
return new Uint8Array(new TextEncoder().encode(e));
|
|
3442
|
-
}
|
|
3443
|
-
function _s(e) {
|
|
3444
|
-
return typeof e == "string" && (e = Fr(e)), an(e), e;
|
|
3445
|
-
}
|
|
3446
|
-
class Kr {
|
|
3447
|
-
}
|
|
3448
|
-
function Yr(e) {
|
|
3449
|
-
const t = (s) => e().update(_s(s)).digest(), n = e();
|
|
3450
|
-
return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
|
|
3451
|
-
}
|
|
3452
|
-
function Xr(e, t, n, s) {
|
|
3453
|
-
if (typeof e.setBigUint64 == "function")
|
|
3454
|
-
return e.setBigUint64(t, n, s);
|
|
3455
|
-
const r = BigInt(32), o = BigInt(4294967295), i = Number(n >> r & o), c = Number(n & o), f = s ? 4 : 0, l = s ? 0 : 4;
|
|
3456
|
-
e.setUint32(t + f, i, s), e.setUint32(t + l, c, s);
|
|
3457
|
-
}
|
|
3458
|
-
function Pr(e, t, n) {
|
|
3459
|
-
return e & t ^ ~e & n;
|
|
3460
|
-
}
|
|
3461
|
-
function Qr(e, t, n) {
|
|
3462
|
-
return e & t ^ e & n ^ t & n;
|
|
3463
|
-
}
|
|
3464
|
-
class Jr extends Kr {
|
|
3465
|
-
constructor(t, n, s, r) {
|
|
3466
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = Ze(this.buffer);
|
|
3467
|
-
}
|
|
3468
|
-
update(t) {
|
|
3469
|
-
On(this), t = _s(t), an(t);
|
|
3470
|
-
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
3471
|
-
for (let i = 0; i < o; ) {
|
|
3472
|
-
const c = Math.min(r - this.pos, o - i);
|
|
3473
|
-
if (c === r) {
|
|
3474
|
-
const f = Ze(t);
|
|
3475
|
-
for (; r <= o - i; i += r)
|
|
3476
|
-
this.process(f, i);
|
|
3477
|
-
continue;
|
|
3478
|
-
}
|
|
3479
|
-
s.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
3480
|
-
}
|
|
3481
|
-
return this.length += t.length, this.roundClean(), this;
|
|
3482
|
-
}
|
|
3483
|
-
digestInto(t) {
|
|
3484
|
-
On(this), Wr(t, this), this.finished = !0;
|
|
3485
|
-
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
3486
|
-
let { pos: i } = this;
|
|
3487
|
-
n[i++] = 128, Xe(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
3488
|
-
for (let a = i; a < r; a++)
|
|
3489
|
-
n[a] = 0;
|
|
3490
|
-
Xr(s, r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
3491
|
-
const c = Ze(t), f = this.outputLen;
|
|
3492
|
-
if (f % 4)
|
|
3493
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
3494
|
-
const l = f / 4, h = this.get();
|
|
3495
|
-
if (l > h.length)
|
|
3496
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
3497
|
-
for (let a = 0; a < l; a++)
|
|
3498
|
-
c.setUint32(4 * a, h[a], o);
|
|
3499
|
-
}
|
|
3500
|
-
digest() {
|
|
3501
|
-
const { buffer: t, outputLen: n } = this;
|
|
3502
|
-
this.digestInto(t);
|
|
3503
|
-
const s = t.slice(0, n);
|
|
3504
|
-
return this.destroy(), s;
|
|
3505
|
-
}
|
|
3506
|
-
_cloneInto(t) {
|
|
3507
|
-
t || (t = new this.constructor()), t.set(...this.get());
|
|
3508
|
-
const { blockLen: n, buffer: s, length: r, finished: o, destroyed: i, pos: c } = this;
|
|
3509
|
-
return t.destroyed = i, t.finished = o, t.length = r, t.pos = c, r % n && t.buffer.set(s), t;
|
|
3510
|
-
}
|
|
3511
|
-
clone() {
|
|
3512
|
-
return this._cloneInto();
|
|
3513
|
-
}
|
|
3514
|
-
}
|
|
3515
|
-
const $t = /* @__PURE__ */ Uint32Array.from([
|
|
3516
|
-
1779033703,
|
|
3517
|
-
3144134277,
|
|
3518
|
-
1013904242,
|
|
3519
|
-
2773480762,
|
|
3520
|
-
1359893119,
|
|
3521
|
-
2600822924,
|
|
3522
|
-
528734635,
|
|
3523
|
-
1541459225
|
|
3524
|
-
]);
|
|
3525
|
-
const $i = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
3526
|
-
const ti = /* @__PURE__ */ Uint32Array.from([
|
|
3527
|
-
1116352408,
|
|
3528
|
-
1899447441,
|
|
3529
|
-
3049323471,
|
|
3530
|
-
3921009573,
|
|
3531
|
-
961987163,
|
|
3532
|
-
1508970993,
|
|
3533
|
-
2453635748,
|
|
3534
|
-
2870763221,
|
|
3535
|
-
3624381080,
|
|
3536
|
-
310598401,
|
|
3537
|
-
607225278,
|
|
3538
|
-
1426881987,
|
|
3539
|
-
1925078388,
|
|
3540
|
-
2162078206,
|
|
3541
|
-
2614888103,
|
|
3542
|
-
3248222580,
|
|
3543
|
-
3835390401,
|
|
3544
|
-
4022224774,
|
|
3545
|
-
264347078,
|
|
3546
|
-
604807628,
|
|
3547
|
-
770255983,
|
|
3548
|
-
1249150122,
|
|
3549
|
-
1555081692,
|
|
3550
|
-
1996064986,
|
|
3551
|
-
2554220882,
|
|
3552
|
-
2821834349,
|
|
3553
|
-
2952996808,
|
|
3554
|
-
3210313671,
|
|
3555
|
-
3336571891,
|
|
3556
|
-
3584528711,
|
|
3557
|
-
113926993,
|
|
3558
|
-
338241895,
|
|
3559
|
-
666307205,
|
|
3560
|
-
773529912,
|
|
3561
|
-
1294757372,
|
|
3562
|
-
1396182291,
|
|
3563
|
-
1695183700,
|
|
3564
|
-
1986661051,
|
|
3565
|
-
2177026350,
|
|
3566
|
-
2456956037,
|
|
3567
|
-
2730485921,
|
|
3568
|
-
2820302411,
|
|
3569
|
-
3259730800,
|
|
3570
|
-
3345764771,
|
|
3571
|
-
3516065817,
|
|
3572
|
-
3600352804,
|
|
3573
|
-
4094571909,
|
|
3574
|
-
275423344,
|
|
3575
|
-
430227734,
|
|
3576
|
-
506948616,
|
|
3577
|
-
659060556,
|
|
3578
|
-
883997877,
|
|
3579
|
-
958139571,
|
|
3580
|
-
1322822218,
|
|
3581
|
-
1537002063,
|
|
3582
|
-
1747873779,
|
|
3583
|
-
1955562222,
|
|
3584
|
-
2024104815,
|
|
3585
|
-
2227730452,
|
|
3586
|
-
2361852424,
|
|
3587
|
-
2428436474,
|
|
3588
|
-
2756734187,
|
|
3589
|
-
3204031479,
|
|
3590
|
-
3329325298
|
|
3591
|
-
]), Lt = /* @__PURE__ */ new Uint32Array(64);
|
|
3592
|
-
class ei extends Jr {
|
|
3593
|
-
constructor(t = 32) {
|
|
3594
|
-
super(64, t, 8, !1), this.A = $t[0] | 0, this.B = $t[1] | 0, this.C = $t[2] | 0, this.D = $t[3] | 0, this.E = $t[4] | 0, this.F = $t[5] | 0, this.G = $t[6] | 0, this.H = $t[7] | 0;
|
|
3595
|
-
}
|
|
3596
|
-
get() {
|
|
3597
|
-
const { A: t, B: n, C: s, D: r, E: o, F: i, G: c, H: f } = this;
|
|
3598
|
-
return [t, n, s, r, o, i, c, f];
|
|
3599
|
-
}
|
|
3600
|
-
// prettier-ignore
|
|
3601
|
-
set(t, n, s, r, o, i, c, f) {
|
|
3602
|
-
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D = r | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = f | 0;
|
|
3603
|
-
}
|
|
3604
|
-
process(t, n) {
|
|
3605
|
-
for (let a = 0; a < 16; a++, n += 4)
|
|
3606
|
-
Lt[a] = t.getUint32(n, !1);
|
|
3607
|
-
for (let a = 16; a < 64; a++) {
|
|
3608
|
-
const d = Lt[a - 15], u = Lt[a - 2], y = at(d, 7) ^ at(d, 18) ^ d >>> 3, b = at(u, 17) ^ at(u, 19) ^ u >>> 10;
|
|
3609
|
-
Lt[a] = b + Lt[a - 7] + y + Lt[a - 16] | 0;
|
|
3610
|
-
}
|
|
3611
|
-
let { A: s, B: r, C: o, D: i, E: c, F: f, G: l, H: h } = this;
|
|
3612
|
-
for (let a = 0; a < 64; a++) {
|
|
3613
|
-
const d = at(c, 6) ^ at(c, 11) ^ at(c, 25), u = h + d + Pr(c, f, l) + ti[a] + Lt[a] | 0, b = (at(s, 2) ^ at(s, 13) ^ at(s, 22)) + Qr(s, r, o) | 0;
|
|
3614
|
-
h = l, l = f, f = c, c = i + u | 0, i = o, o = r, r = s, s = u + b | 0;
|
|
3615
|
-
}
|
|
3616
|
-
s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, f = f + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, c, f, l, h);
|
|
3617
|
-
}
|
|
3618
|
-
roundClean() {
|
|
3619
|
-
Xe(Lt);
|
|
3620
|
-
}
|
|
3621
|
-
destroy() {
|
|
3622
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0), Xe(this.buffer);
|
|
3623
|
-
}
|
|
3624
|
-
}
|
|
3625
|
-
const ni = /* @__PURE__ */ Yr(() => new ei()), Li = ni;
|
|
3626
|
-
export {
|
|
3627
|
-
yi as R,
|
|
3628
|
-
Si as a,
|
|
3629
|
-
ii as b,
|
|
3630
|
-
mi as c,
|
|
3631
|
-
ne as d,
|
|
3632
|
-
Jt as e,
|
|
3633
|
-
st as f,
|
|
3634
|
-
pi as g,
|
|
3635
|
-
ve as h,
|
|
3636
|
-
en as i,
|
|
3637
|
-
Ii as j,
|
|
3638
|
-
Ei as k,
|
|
3639
|
-
Ui as l,
|
|
3640
|
-
z as m,
|
|
3641
|
-
se as n,
|
|
3642
|
-
vi as o,
|
|
3643
|
-
Fn as p,
|
|
3644
|
-
Li as q,
|
|
3645
|
-
Ai as r,
|
|
3646
|
-
ai as s,
|
|
3647
|
-
wr as u
|
|
3648
|
-
};
|