@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
|
@@ -0,0 +1,2728 @@
|
|
|
1
|
+
const kt = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
2
|
+
function ye(t) {
|
|
3
|
+
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
4
|
+
}
|
|
5
|
+
function F(t) {
|
|
6
|
+
if (!Number.isSafeInteger(t) || t < 0)
|
|
7
|
+
throw new Error("positive integer expected, got " + t);
|
|
8
|
+
}
|
|
9
|
+
function et(t, ...e) {
|
|
10
|
+
if (!ye(t))
|
|
11
|
+
throw new Error("Uint8Array expected");
|
|
12
|
+
if (e.length > 0 && !e.includes(t.length))
|
|
13
|
+
throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
|
|
14
|
+
}
|
|
15
|
+
function $e(t) {
|
|
16
|
+
if (typeof t != "function" || typeof t.create != "function")
|
|
17
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
18
|
+
F(t.outputLen), F(t.blockLen);
|
|
19
|
+
}
|
|
20
|
+
function Nt(t, e = !0) {
|
|
21
|
+
if (t.destroyed)
|
|
22
|
+
throw new Error("Hash instance has been destroyed");
|
|
23
|
+
if (e && t.finished)
|
|
24
|
+
throw new Error("Hash#digest() has already been called");
|
|
25
|
+
}
|
|
26
|
+
function Ye(t, e) {
|
|
27
|
+
et(t);
|
|
28
|
+
const n = e.outputLen;
|
|
29
|
+
if (t.length < n)
|
|
30
|
+
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
31
|
+
}
|
|
32
|
+
function St(t) {
|
|
33
|
+
return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
|
|
34
|
+
}
|
|
35
|
+
function rt(...t) {
|
|
36
|
+
for (let e = 0; e < t.length; e++)
|
|
37
|
+
t[e].fill(0);
|
|
38
|
+
}
|
|
39
|
+
function Wt(t) {
|
|
40
|
+
return new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
41
|
+
}
|
|
42
|
+
function ot(t, e) {
|
|
43
|
+
return t << 32 - e | t >>> e;
|
|
44
|
+
}
|
|
45
|
+
function C(t, e) {
|
|
46
|
+
return t << e | t >>> 32 - e >>> 0;
|
|
47
|
+
}
|
|
48
|
+
const Xe = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
49
|
+
function Ke(t) {
|
|
50
|
+
return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
|
|
51
|
+
}
|
|
52
|
+
const ft = Xe ? (t) => t : (t) => Ke(t);
|
|
53
|
+
function In(t) {
|
|
54
|
+
for (let e = 0; e < t.length; e++)
|
|
55
|
+
t[e] = Ke(t[e]);
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
const gt = Xe ? (t) => t : In, Pe = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ln = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
|
|
59
|
+
function It(t) {
|
|
60
|
+
if (et(t), Pe)
|
|
61
|
+
return t.toHex();
|
|
62
|
+
let e = "";
|
|
63
|
+
for (let n = 0; n < t.length; n++)
|
|
64
|
+
e += Ln[t[n]];
|
|
65
|
+
return e;
|
|
66
|
+
}
|
|
67
|
+
const ct = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
68
|
+
function Ie(t) {
|
|
69
|
+
if (t >= ct._0 && t <= ct._9)
|
|
70
|
+
return t - ct._0;
|
|
71
|
+
if (t >= ct.A && t <= ct.F)
|
|
72
|
+
return t - (ct.A - 10);
|
|
73
|
+
if (t >= ct.a && t <= ct.f)
|
|
74
|
+
return t - (ct.a - 10);
|
|
75
|
+
}
|
|
76
|
+
function ge(t) {
|
|
77
|
+
if (typeof t != "string")
|
|
78
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
79
|
+
if (Pe)
|
|
80
|
+
return Uint8Array.fromHex(t);
|
|
81
|
+
const e = t.length, n = e / 2;
|
|
82
|
+
if (e % 2)
|
|
83
|
+
throw new Error("hex string expected, got unpadded hex of length " + e);
|
|
84
|
+
const r = new Uint8Array(n);
|
|
85
|
+
for (let i = 0, s = 0; i < n; i++, s += 2) {
|
|
86
|
+
const o = Ie(t.charCodeAt(s)), c = Ie(t.charCodeAt(s + 1));
|
|
87
|
+
if (o === void 0 || c === void 0) {
|
|
88
|
+
const a = t[s] + t[s + 1];
|
|
89
|
+
throw new Error('hex string expected, got non-hex character "' + a + '" at index ' + s);
|
|
90
|
+
}
|
|
91
|
+
r[i] = o * 16 + c;
|
|
92
|
+
}
|
|
93
|
+
return r;
|
|
94
|
+
}
|
|
95
|
+
function We(t) {
|
|
96
|
+
if (typeof t != "string")
|
|
97
|
+
throw new Error("string expected");
|
|
98
|
+
return new Uint8Array(new TextEncoder().encode(t));
|
|
99
|
+
}
|
|
100
|
+
function Bt(t) {
|
|
101
|
+
return typeof t == "string" && (t = We(t)), et(t), t;
|
|
102
|
+
}
|
|
103
|
+
function Le(t) {
|
|
104
|
+
return typeof t == "string" && (t = We(t)), et(t), t;
|
|
105
|
+
}
|
|
106
|
+
function lt(...t) {
|
|
107
|
+
let e = 0;
|
|
108
|
+
for (let r = 0; r < t.length; r++) {
|
|
109
|
+
const i = t[r];
|
|
110
|
+
et(i), e += i.length;
|
|
111
|
+
}
|
|
112
|
+
const n = new Uint8Array(e);
|
|
113
|
+
for (let r = 0, i = 0; r < t.length; r++) {
|
|
114
|
+
const s = t[r];
|
|
115
|
+
n.set(s, i), i += s.length;
|
|
116
|
+
}
|
|
117
|
+
return n;
|
|
118
|
+
}
|
|
119
|
+
function Qe(t, e) {
|
|
120
|
+
if (e !== void 0 && {}.toString.call(e) !== "[object Object]")
|
|
121
|
+
throw new Error("options should be object or undefined");
|
|
122
|
+
return Object.assign(t, e);
|
|
123
|
+
}
|
|
124
|
+
class me {
|
|
125
|
+
}
|
|
126
|
+
function Je(t) {
|
|
127
|
+
const e = (r) => t().update(Bt(r)).digest(), n = t();
|
|
128
|
+
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
|
|
129
|
+
}
|
|
130
|
+
function On(t) {
|
|
131
|
+
const e = (r, i) => t(i).update(Bt(r)).digest(), n = t({});
|
|
132
|
+
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = (r) => t(r), e;
|
|
133
|
+
}
|
|
134
|
+
function Fe(t = 32) {
|
|
135
|
+
if (kt && typeof kt.getRandomValues == "function")
|
|
136
|
+
return kt.getRandomValues(new Uint8Array(t));
|
|
137
|
+
if (kt && typeof kt.randomBytes == "function")
|
|
138
|
+
return Uint8Array.from(kt.randomBytes(t));
|
|
139
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
140
|
+
}
|
|
141
|
+
function Hn(t, e, n, r) {
|
|
142
|
+
if (typeof t.setBigUint64 == "function")
|
|
143
|
+
return t.setBigUint64(e, n, r);
|
|
144
|
+
const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), c = Number(n & s), a = r ? 4 : 0, l = r ? 0 : 4;
|
|
145
|
+
t.setUint32(e + a, o, r), t.setUint32(e + l, c, r);
|
|
146
|
+
}
|
|
147
|
+
function Rn(t, e, n) {
|
|
148
|
+
return t & e ^ ~t & n;
|
|
149
|
+
}
|
|
150
|
+
function kn(t, e, n) {
|
|
151
|
+
return t & e ^ t & n ^ e & n;
|
|
152
|
+
}
|
|
153
|
+
class tn extends me {
|
|
154
|
+
constructor(e, n, r, i) {
|
|
155
|
+
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = i, this.buffer = new Uint8Array(e), this.view = Wt(this.buffer);
|
|
156
|
+
}
|
|
157
|
+
update(e) {
|
|
158
|
+
Nt(this), e = Bt(e), et(e);
|
|
159
|
+
const { view: n, buffer: r, blockLen: i } = this, s = e.length;
|
|
160
|
+
for (let o = 0; o < s; ) {
|
|
161
|
+
const c = Math.min(i - this.pos, s - o);
|
|
162
|
+
if (c === i) {
|
|
163
|
+
const a = Wt(e);
|
|
164
|
+
for (; i <= s - o; o += i)
|
|
165
|
+
this.process(a, o);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
r.set(e.subarray(o, o + c), this.pos), this.pos += c, o += c, this.pos === i && (this.process(n, 0), this.pos = 0);
|
|
169
|
+
}
|
|
170
|
+
return this.length += e.length, this.roundClean(), this;
|
|
171
|
+
}
|
|
172
|
+
digestInto(e) {
|
|
173
|
+
Nt(this), Ye(e, this), this.finished = !0;
|
|
174
|
+
const { buffer: n, view: r, blockLen: i, isLE: s } = this;
|
|
175
|
+
let { pos: o } = this;
|
|
176
|
+
n[o++] = 128, rt(this.buffer.subarray(o)), this.padOffset > i - o && (this.process(r, 0), o = 0);
|
|
177
|
+
for (let u = o; u < i; u++)
|
|
178
|
+
n[u] = 0;
|
|
179
|
+
Hn(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
180
|
+
const c = Wt(e), a = this.outputLen;
|
|
181
|
+
if (a % 4)
|
|
182
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
183
|
+
const l = a / 4, f = this.get();
|
|
184
|
+
if (l > f.length)
|
|
185
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
186
|
+
for (let u = 0; u < l; u++)
|
|
187
|
+
c.setUint32(4 * u, f[u], s);
|
|
188
|
+
}
|
|
189
|
+
digest() {
|
|
190
|
+
const { buffer: e, outputLen: n } = this;
|
|
191
|
+
this.digestInto(e);
|
|
192
|
+
const r = e.slice(0, n);
|
|
193
|
+
return this.destroy(), r;
|
|
194
|
+
}
|
|
195
|
+
_cloneInto(e) {
|
|
196
|
+
e || (e = new this.constructor()), e.set(...this.get());
|
|
197
|
+
const { blockLen: n, buffer: r, length: i, finished: s, destroyed: o, pos: c } = this;
|
|
198
|
+
return e.destroyed = o, e.finished = s, e.length = i, e.pos = c, i % n && e.buffer.set(r), e;
|
|
199
|
+
}
|
|
200
|
+
clone() {
|
|
201
|
+
return this._cloneInto();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const ht = /* @__PURE__ */ Uint32Array.from([
|
|
205
|
+
1779033703,
|
|
206
|
+
3144134277,
|
|
207
|
+
1013904242,
|
|
208
|
+
2773480762,
|
|
209
|
+
1359893119,
|
|
210
|
+
2600822924,
|
|
211
|
+
528734635,
|
|
212
|
+
1541459225
|
|
213
|
+
]);
|
|
214
|
+
const W = /* @__PURE__ */ Uint32Array.from([
|
|
215
|
+
1779033703,
|
|
216
|
+
4089235720,
|
|
217
|
+
3144134277,
|
|
218
|
+
2227873595,
|
|
219
|
+
1013904242,
|
|
220
|
+
4271175723,
|
|
221
|
+
2773480762,
|
|
222
|
+
1595750129,
|
|
223
|
+
1359893119,
|
|
224
|
+
2917565137,
|
|
225
|
+
2600822924,
|
|
226
|
+
725511199,
|
|
227
|
+
528734635,
|
|
228
|
+
4215389547,
|
|
229
|
+
1541459225,
|
|
230
|
+
327033209
|
|
231
|
+
]), Xt = /* @__PURE__ */ BigInt(2 ** 32 - 1), Oe = /* @__PURE__ */ BigInt(32);
|
|
232
|
+
function en(t, e = !1) {
|
|
233
|
+
return e ? { h: Number(t & Xt), l: Number(t >> Oe & Xt) } : { h: Number(t >> Oe & Xt) | 0, l: Number(t & Xt) | 0 };
|
|
234
|
+
}
|
|
235
|
+
function nn(t, e = !1) {
|
|
236
|
+
const n = t.length;
|
|
237
|
+
let r = new Uint32Array(n), i = new Uint32Array(n);
|
|
238
|
+
for (let s = 0; s < n; s++) {
|
|
239
|
+
const { h: o, l: c } = en(t[s], e);
|
|
240
|
+
[r[s], i[s]] = [o, c];
|
|
241
|
+
}
|
|
242
|
+
return [r, i];
|
|
243
|
+
}
|
|
244
|
+
const He = (t, e, n) => t >>> n, Re = (t, e, n) => t << 32 - n | e >>> n, mt = (t, e, n) => t >>> n | e << 32 - n, pt = (t, e, n) => t << 32 - n | e >>> n, zt = (t, e, n) => t << 64 - n | e >>> n - 32, Vt = (t, e, n) => t >>> n - 32 | e << 64 - n, Un = (t, e) => e, qn = (t, e) => t, Nn = (t, e, n) => t << n | e >>> 32 - n, Tn = (t, e, n) => e << n | t >>> 32 - n, Dn = (t, e, n) => e << n - 32 | t >>> 64 - n, Cn = (t, e, n) => t << n - 32 | e >>> 64 - n;
|
|
245
|
+
function st(t, e, n, r) {
|
|
246
|
+
const i = (e >>> 0) + (r >>> 0);
|
|
247
|
+
return { h: t + n + (i / 2 ** 32 | 0) | 0, l: i | 0 };
|
|
248
|
+
}
|
|
249
|
+
const pe = (t, e, n) => (t >>> 0) + (e >>> 0) + (n >>> 0), Ee = (t, e, n, r) => e + n + r + (t / 2 ** 32 | 0) | 0, Zn = (t, e, n, r) => (t >>> 0) + (e >>> 0) + (n >>> 0) + (r >>> 0), Mn = (t, e, n, r, i) => e + n + r + i + (t / 2 ** 32 | 0) | 0, zn = (t, e, n, r, i) => (t >>> 0) + (e >>> 0) + (n >>> 0) + (r >>> 0) + (i >>> 0), Vn = (t, e, n, r, i, s) => e + n + r + i + s + (t / 2 ** 32 | 0) | 0, Gn = /* @__PURE__ */ Uint32Array.from([
|
|
250
|
+
1116352408,
|
|
251
|
+
1899447441,
|
|
252
|
+
3049323471,
|
|
253
|
+
3921009573,
|
|
254
|
+
961987163,
|
|
255
|
+
1508970993,
|
|
256
|
+
2453635748,
|
|
257
|
+
2870763221,
|
|
258
|
+
3624381080,
|
|
259
|
+
310598401,
|
|
260
|
+
607225278,
|
|
261
|
+
1426881987,
|
|
262
|
+
1925078388,
|
|
263
|
+
2162078206,
|
|
264
|
+
2614888103,
|
|
265
|
+
3248222580,
|
|
266
|
+
3835390401,
|
|
267
|
+
4022224774,
|
|
268
|
+
264347078,
|
|
269
|
+
604807628,
|
|
270
|
+
770255983,
|
|
271
|
+
1249150122,
|
|
272
|
+
1555081692,
|
|
273
|
+
1996064986,
|
|
274
|
+
2554220882,
|
|
275
|
+
2821834349,
|
|
276
|
+
2952996808,
|
|
277
|
+
3210313671,
|
|
278
|
+
3336571891,
|
|
279
|
+
3584528711,
|
|
280
|
+
113926993,
|
|
281
|
+
338241895,
|
|
282
|
+
666307205,
|
|
283
|
+
773529912,
|
|
284
|
+
1294757372,
|
|
285
|
+
1396182291,
|
|
286
|
+
1695183700,
|
|
287
|
+
1986661051,
|
|
288
|
+
2177026350,
|
|
289
|
+
2456956037,
|
|
290
|
+
2730485921,
|
|
291
|
+
2820302411,
|
|
292
|
+
3259730800,
|
|
293
|
+
3345764771,
|
|
294
|
+
3516065817,
|
|
295
|
+
3600352804,
|
|
296
|
+
4094571909,
|
|
297
|
+
275423344,
|
|
298
|
+
430227734,
|
|
299
|
+
506948616,
|
|
300
|
+
659060556,
|
|
301
|
+
883997877,
|
|
302
|
+
958139571,
|
|
303
|
+
1322822218,
|
|
304
|
+
1537002063,
|
|
305
|
+
1747873779,
|
|
306
|
+
1955562222,
|
|
307
|
+
2024104815,
|
|
308
|
+
2227730452,
|
|
309
|
+
2361852424,
|
|
310
|
+
2428436474,
|
|
311
|
+
2756734187,
|
|
312
|
+
3204031479,
|
|
313
|
+
3329325298
|
|
314
|
+
]), dt = /* @__PURE__ */ new Uint32Array(64);
|
|
315
|
+
class jn extends tn {
|
|
316
|
+
constructor(e = 32) {
|
|
317
|
+
super(64, e, 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;
|
|
318
|
+
}
|
|
319
|
+
get() {
|
|
320
|
+
const { A: e, B: n, C: r, D: i, E: s, F: o, G: c, H: a } = this;
|
|
321
|
+
return [e, n, r, i, s, o, c, a];
|
|
322
|
+
}
|
|
323
|
+
// prettier-ignore
|
|
324
|
+
set(e, n, r, i, s, o, c, a) {
|
|
325
|
+
this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = s | 0, this.F = o | 0, this.G = c | 0, this.H = a | 0;
|
|
326
|
+
}
|
|
327
|
+
process(e, n) {
|
|
328
|
+
for (let u = 0; u < 16; u++, n += 4)
|
|
329
|
+
dt[u] = e.getUint32(n, !1);
|
|
330
|
+
for (let u = 16; u < 64; u++) {
|
|
331
|
+
const b = dt[u - 15], h = dt[u - 2], E = ot(b, 7) ^ ot(b, 18) ^ b >>> 3, w = ot(h, 17) ^ ot(h, 19) ^ h >>> 10;
|
|
332
|
+
dt[u] = w + dt[u - 7] + E + dt[u - 16] | 0;
|
|
333
|
+
}
|
|
334
|
+
let { A: r, B: i, C: s, D: o, E: c, F: a, G: l, H: f } = this;
|
|
335
|
+
for (let u = 0; u < 64; u++) {
|
|
336
|
+
const b = ot(c, 6) ^ ot(c, 11) ^ ot(c, 25), h = f + b + Rn(c, a, l) + Gn[u] + dt[u] | 0, w = (ot(r, 2) ^ ot(r, 13) ^ ot(r, 22)) + kn(r, i, s) | 0;
|
|
337
|
+
f = l, l = a, a = c, c = o + h | 0, o = s, s = i, i = r, r = h + w | 0;
|
|
338
|
+
}
|
|
339
|
+
r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, l = l + this.G | 0, f = f + this.H | 0, this.set(r, i, s, o, c, a, l, f);
|
|
340
|
+
}
|
|
341
|
+
roundClean() {
|
|
342
|
+
rt(dt);
|
|
343
|
+
}
|
|
344
|
+
destroy() {
|
|
345
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), rt(this.buffer);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const rn = nn([
|
|
349
|
+
"0x428a2f98d728ae22",
|
|
350
|
+
"0x7137449123ef65cd",
|
|
351
|
+
"0xb5c0fbcfec4d3b2f",
|
|
352
|
+
"0xe9b5dba58189dbbc",
|
|
353
|
+
"0x3956c25bf348b538",
|
|
354
|
+
"0x59f111f1b605d019",
|
|
355
|
+
"0x923f82a4af194f9b",
|
|
356
|
+
"0xab1c5ed5da6d8118",
|
|
357
|
+
"0xd807aa98a3030242",
|
|
358
|
+
"0x12835b0145706fbe",
|
|
359
|
+
"0x243185be4ee4b28c",
|
|
360
|
+
"0x550c7dc3d5ffb4e2",
|
|
361
|
+
"0x72be5d74f27b896f",
|
|
362
|
+
"0x80deb1fe3b1696b1",
|
|
363
|
+
"0x9bdc06a725c71235",
|
|
364
|
+
"0xc19bf174cf692694",
|
|
365
|
+
"0xe49b69c19ef14ad2",
|
|
366
|
+
"0xefbe4786384f25e3",
|
|
367
|
+
"0x0fc19dc68b8cd5b5",
|
|
368
|
+
"0x240ca1cc77ac9c65",
|
|
369
|
+
"0x2de92c6f592b0275",
|
|
370
|
+
"0x4a7484aa6ea6e483",
|
|
371
|
+
"0x5cb0a9dcbd41fbd4",
|
|
372
|
+
"0x76f988da831153b5",
|
|
373
|
+
"0x983e5152ee66dfab",
|
|
374
|
+
"0xa831c66d2db43210",
|
|
375
|
+
"0xb00327c898fb213f",
|
|
376
|
+
"0xbf597fc7beef0ee4",
|
|
377
|
+
"0xc6e00bf33da88fc2",
|
|
378
|
+
"0xd5a79147930aa725",
|
|
379
|
+
"0x06ca6351e003826f",
|
|
380
|
+
"0x142929670a0e6e70",
|
|
381
|
+
"0x27b70a8546d22ffc",
|
|
382
|
+
"0x2e1b21385c26c926",
|
|
383
|
+
"0x4d2c6dfc5ac42aed",
|
|
384
|
+
"0x53380d139d95b3df",
|
|
385
|
+
"0x650a73548baf63de",
|
|
386
|
+
"0x766a0abb3c77b2a8",
|
|
387
|
+
"0x81c2c92e47edaee6",
|
|
388
|
+
"0x92722c851482353b",
|
|
389
|
+
"0xa2bfe8a14cf10364",
|
|
390
|
+
"0xa81a664bbc423001",
|
|
391
|
+
"0xc24b8b70d0f89791",
|
|
392
|
+
"0xc76c51a30654be30",
|
|
393
|
+
"0xd192e819d6ef5218",
|
|
394
|
+
"0xd69906245565a910",
|
|
395
|
+
"0xf40e35855771202a",
|
|
396
|
+
"0x106aa07032bbd1b8",
|
|
397
|
+
"0x19a4c116b8d2d0c8",
|
|
398
|
+
"0x1e376c085141ab53",
|
|
399
|
+
"0x2748774cdf8eeb99",
|
|
400
|
+
"0x34b0bcb5e19b48a8",
|
|
401
|
+
"0x391c0cb3c5c95a63",
|
|
402
|
+
"0x4ed8aa4ae3418acb",
|
|
403
|
+
"0x5b9cca4f7763e373",
|
|
404
|
+
"0x682e6ff3d6b2b8a3",
|
|
405
|
+
"0x748f82ee5defb2fc",
|
|
406
|
+
"0x78a5636f43172f60",
|
|
407
|
+
"0x84c87814a1f0ab72",
|
|
408
|
+
"0x8cc702081a6439ec",
|
|
409
|
+
"0x90befffa23631e28",
|
|
410
|
+
"0xa4506cebde82bde9",
|
|
411
|
+
"0xbef9a3f7b2c67915",
|
|
412
|
+
"0xc67178f2e372532b",
|
|
413
|
+
"0xca273eceea26619c",
|
|
414
|
+
"0xd186b8c721c0c207",
|
|
415
|
+
"0xeada7dd6cde0eb1e",
|
|
416
|
+
"0xf57d4f7fee6ed178",
|
|
417
|
+
"0x06f067aa72176fba",
|
|
418
|
+
"0x0a637dc5a2c898a6",
|
|
419
|
+
"0x113f9804bef90dae",
|
|
420
|
+
"0x1b710b35131c471b",
|
|
421
|
+
"0x28db77f523047d84",
|
|
422
|
+
"0x32caab7b40c72493",
|
|
423
|
+
"0x3c9ebe0a15c9bebc",
|
|
424
|
+
"0x431d67c49c100d4c",
|
|
425
|
+
"0x4cc5d4becb3e42b6",
|
|
426
|
+
"0x597f299cfc657e2a",
|
|
427
|
+
"0x5fcb6fab3ad6faec",
|
|
428
|
+
"0x6c44198c4a475817"
|
|
429
|
+
].map((t) => BigInt(t))), $n = rn[0], Yn = rn[1], bt = /* @__PURE__ */ new Uint32Array(80), xt = /* @__PURE__ */ new Uint32Array(80);
|
|
430
|
+
class Xn extends tn {
|
|
431
|
+
constructor(e = 64) {
|
|
432
|
+
super(128, e, 16, !1), this.Ah = W[0] | 0, this.Al = W[1] | 0, this.Bh = W[2] | 0, this.Bl = W[3] | 0, this.Ch = W[4] | 0, this.Cl = W[5] | 0, this.Dh = W[6] | 0, this.Dl = W[7] | 0, this.Eh = W[8] | 0, this.El = W[9] | 0, this.Fh = W[10] | 0, this.Fl = W[11] | 0, this.Gh = W[12] | 0, this.Gl = W[13] | 0, this.Hh = W[14] | 0, this.Hl = W[15] | 0;
|
|
433
|
+
}
|
|
434
|
+
// prettier-ignore
|
|
435
|
+
get() {
|
|
436
|
+
const { Ah: e, Al: n, Bh: r, Bl: i, Ch: s, Cl: o, Dh: c, Dl: a, Eh: l, El: f, Fh: u, Fl: b, Gh: h, Gl: E, Hh: w, Hl: x } = this;
|
|
437
|
+
return [e, n, r, i, s, o, c, a, l, f, u, b, h, E, w, x];
|
|
438
|
+
}
|
|
439
|
+
// prettier-ignore
|
|
440
|
+
set(e, n, r, i, s, o, c, a, l, f, u, b, h, E, w, x) {
|
|
441
|
+
this.Ah = e | 0, this.Al = n | 0, this.Bh = r | 0, this.Bl = i | 0, this.Ch = s | 0, this.Cl = o | 0, this.Dh = c | 0, this.Dl = a | 0, this.Eh = l | 0, this.El = f | 0, this.Fh = u | 0, this.Fl = b | 0, this.Gh = h | 0, this.Gl = E | 0, this.Hh = w | 0, this.Hl = x | 0;
|
|
442
|
+
}
|
|
443
|
+
process(e, n) {
|
|
444
|
+
for (let L = 0; L < 16; L++, n += 4)
|
|
445
|
+
bt[L] = e.getUint32(n), xt[L] = e.getUint32(n += 4);
|
|
446
|
+
for (let L = 16; L < 80; L++) {
|
|
447
|
+
const T = bt[L - 15] | 0, m = xt[L - 15] | 0, H = mt(T, m, 1) ^ mt(T, m, 8) ^ He(T, m, 7), U = pt(T, m, 1) ^ pt(T, m, 8) ^ Re(T, m, 7), O = bt[L - 2] | 0, d = xt[L - 2] | 0, p = mt(O, d, 19) ^ zt(O, d, 61) ^ He(O, d, 6), y = pt(O, d, 19) ^ Vt(O, d, 61) ^ Re(O, d, 6), g = Zn(U, y, xt[L - 7], xt[L - 16]), B = Mn(g, H, p, bt[L - 7], bt[L - 16]);
|
|
448
|
+
bt[L] = B | 0, xt[L] = g | 0;
|
|
449
|
+
}
|
|
450
|
+
let { Ah: r, Al: i, Bh: s, Bl: o, Ch: c, Cl: a, Dh: l, Dl: f, Eh: u, El: b, Fh: h, Fl: E, Gh: w, Gl: x, Hh: _, Hl: R } = this;
|
|
451
|
+
for (let L = 0; L < 80; L++) {
|
|
452
|
+
const T = mt(u, b, 14) ^ mt(u, b, 18) ^ zt(u, b, 41), m = pt(u, b, 14) ^ pt(u, b, 18) ^ Vt(u, b, 41), H = u & h ^ ~u & w, U = b & E ^ ~b & x, O = zn(R, m, U, Yn[L], xt[L]), d = Vn(O, _, T, H, $n[L], bt[L]), p = O | 0, y = mt(r, i, 28) ^ zt(r, i, 34) ^ zt(r, i, 39), g = pt(r, i, 28) ^ Vt(r, i, 34) ^ Vt(r, i, 39), B = r & s ^ r & c ^ s & c, v = i & o ^ i & a ^ o & a;
|
|
453
|
+
_ = w | 0, R = x | 0, w = h | 0, x = E | 0, h = u | 0, E = b | 0, { h: u, l: b } = st(l | 0, f | 0, d | 0, p | 0), l = c | 0, f = a | 0, c = s | 0, a = o | 0, s = r | 0, o = i | 0;
|
|
454
|
+
const A = pe(p, g, v);
|
|
455
|
+
r = Ee(A, d, y, B), i = A | 0;
|
|
456
|
+
}
|
|
457
|
+
({ h: r, l: i } = st(this.Ah | 0, this.Al | 0, r | 0, i | 0)), { h: s, l: o } = st(this.Bh | 0, this.Bl | 0, s | 0, o | 0), { h: c, l: a } = st(this.Ch | 0, this.Cl | 0, c | 0, a | 0), { h: l, l: f } = st(this.Dh | 0, this.Dl | 0, l | 0, f | 0), { h: u, l: b } = st(this.Eh | 0, this.El | 0, u | 0, b | 0), { h, l: E } = st(this.Fh | 0, this.Fl | 0, h | 0, E | 0), { h: w, l: x } = st(this.Gh | 0, this.Gl | 0, w | 0, x | 0), { h: _, l: R } = st(this.Hh | 0, this.Hl | 0, _ | 0, R | 0), this.set(r, i, s, o, c, a, l, f, u, b, h, E, w, x, _, R);
|
|
458
|
+
}
|
|
459
|
+
roundClean() {
|
|
460
|
+
rt(bt, xt);
|
|
461
|
+
}
|
|
462
|
+
destroy() {
|
|
463
|
+
rt(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
const Ft = /* @__PURE__ */ Je(() => new jn()), sn = /* @__PURE__ */ Je(() => new Xn()), ss = Ft, Kn = /* @__PURE__ */ Uint8Array.from([
|
|
467
|
+
0,
|
|
468
|
+
1,
|
|
469
|
+
2,
|
|
470
|
+
3,
|
|
471
|
+
4,
|
|
472
|
+
5,
|
|
473
|
+
6,
|
|
474
|
+
7,
|
|
475
|
+
8,
|
|
476
|
+
9,
|
|
477
|
+
10,
|
|
478
|
+
11,
|
|
479
|
+
12,
|
|
480
|
+
13,
|
|
481
|
+
14,
|
|
482
|
+
15,
|
|
483
|
+
14,
|
|
484
|
+
10,
|
|
485
|
+
4,
|
|
486
|
+
8,
|
|
487
|
+
9,
|
|
488
|
+
15,
|
|
489
|
+
13,
|
|
490
|
+
6,
|
|
491
|
+
1,
|
|
492
|
+
12,
|
|
493
|
+
0,
|
|
494
|
+
2,
|
|
495
|
+
11,
|
|
496
|
+
7,
|
|
497
|
+
5,
|
|
498
|
+
3,
|
|
499
|
+
11,
|
|
500
|
+
8,
|
|
501
|
+
12,
|
|
502
|
+
0,
|
|
503
|
+
5,
|
|
504
|
+
2,
|
|
505
|
+
15,
|
|
506
|
+
13,
|
|
507
|
+
10,
|
|
508
|
+
14,
|
|
509
|
+
3,
|
|
510
|
+
6,
|
|
511
|
+
7,
|
|
512
|
+
1,
|
|
513
|
+
9,
|
|
514
|
+
4,
|
|
515
|
+
7,
|
|
516
|
+
9,
|
|
517
|
+
3,
|
|
518
|
+
1,
|
|
519
|
+
13,
|
|
520
|
+
12,
|
|
521
|
+
11,
|
|
522
|
+
14,
|
|
523
|
+
2,
|
|
524
|
+
6,
|
|
525
|
+
5,
|
|
526
|
+
10,
|
|
527
|
+
4,
|
|
528
|
+
0,
|
|
529
|
+
15,
|
|
530
|
+
8,
|
|
531
|
+
9,
|
|
532
|
+
0,
|
|
533
|
+
5,
|
|
534
|
+
7,
|
|
535
|
+
2,
|
|
536
|
+
4,
|
|
537
|
+
10,
|
|
538
|
+
15,
|
|
539
|
+
14,
|
|
540
|
+
1,
|
|
541
|
+
11,
|
|
542
|
+
12,
|
|
543
|
+
6,
|
|
544
|
+
8,
|
|
545
|
+
3,
|
|
546
|
+
13,
|
|
547
|
+
2,
|
|
548
|
+
12,
|
|
549
|
+
6,
|
|
550
|
+
10,
|
|
551
|
+
0,
|
|
552
|
+
11,
|
|
553
|
+
8,
|
|
554
|
+
3,
|
|
555
|
+
4,
|
|
556
|
+
13,
|
|
557
|
+
7,
|
|
558
|
+
5,
|
|
559
|
+
15,
|
|
560
|
+
14,
|
|
561
|
+
1,
|
|
562
|
+
9,
|
|
563
|
+
12,
|
|
564
|
+
5,
|
|
565
|
+
1,
|
|
566
|
+
15,
|
|
567
|
+
14,
|
|
568
|
+
13,
|
|
569
|
+
4,
|
|
570
|
+
10,
|
|
571
|
+
0,
|
|
572
|
+
7,
|
|
573
|
+
6,
|
|
574
|
+
3,
|
|
575
|
+
9,
|
|
576
|
+
2,
|
|
577
|
+
8,
|
|
578
|
+
11,
|
|
579
|
+
13,
|
|
580
|
+
11,
|
|
581
|
+
7,
|
|
582
|
+
14,
|
|
583
|
+
12,
|
|
584
|
+
1,
|
|
585
|
+
3,
|
|
586
|
+
9,
|
|
587
|
+
5,
|
|
588
|
+
0,
|
|
589
|
+
15,
|
|
590
|
+
4,
|
|
591
|
+
8,
|
|
592
|
+
6,
|
|
593
|
+
2,
|
|
594
|
+
10,
|
|
595
|
+
6,
|
|
596
|
+
15,
|
|
597
|
+
14,
|
|
598
|
+
9,
|
|
599
|
+
11,
|
|
600
|
+
3,
|
|
601
|
+
0,
|
|
602
|
+
8,
|
|
603
|
+
12,
|
|
604
|
+
2,
|
|
605
|
+
13,
|
|
606
|
+
7,
|
|
607
|
+
1,
|
|
608
|
+
4,
|
|
609
|
+
10,
|
|
610
|
+
5,
|
|
611
|
+
10,
|
|
612
|
+
2,
|
|
613
|
+
8,
|
|
614
|
+
4,
|
|
615
|
+
7,
|
|
616
|
+
6,
|
|
617
|
+
1,
|
|
618
|
+
5,
|
|
619
|
+
15,
|
|
620
|
+
11,
|
|
621
|
+
9,
|
|
622
|
+
14,
|
|
623
|
+
3,
|
|
624
|
+
12,
|
|
625
|
+
13,
|
|
626
|
+
0,
|
|
627
|
+
0,
|
|
628
|
+
1,
|
|
629
|
+
2,
|
|
630
|
+
3,
|
|
631
|
+
4,
|
|
632
|
+
5,
|
|
633
|
+
6,
|
|
634
|
+
7,
|
|
635
|
+
8,
|
|
636
|
+
9,
|
|
637
|
+
10,
|
|
638
|
+
11,
|
|
639
|
+
12,
|
|
640
|
+
13,
|
|
641
|
+
14,
|
|
642
|
+
15,
|
|
643
|
+
14,
|
|
644
|
+
10,
|
|
645
|
+
4,
|
|
646
|
+
8,
|
|
647
|
+
9,
|
|
648
|
+
15,
|
|
649
|
+
13,
|
|
650
|
+
6,
|
|
651
|
+
1,
|
|
652
|
+
12,
|
|
653
|
+
0,
|
|
654
|
+
2,
|
|
655
|
+
11,
|
|
656
|
+
7,
|
|
657
|
+
5,
|
|
658
|
+
3,
|
|
659
|
+
// Blake1, unused in others
|
|
660
|
+
11,
|
|
661
|
+
8,
|
|
662
|
+
12,
|
|
663
|
+
0,
|
|
664
|
+
5,
|
|
665
|
+
2,
|
|
666
|
+
15,
|
|
667
|
+
13,
|
|
668
|
+
10,
|
|
669
|
+
14,
|
|
670
|
+
3,
|
|
671
|
+
6,
|
|
672
|
+
7,
|
|
673
|
+
1,
|
|
674
|
+
9,
|
|
675
|
+
4,
|
|
676
|
+
7,
|
|
677
|
+
9,
|
|
678
|
+
3,
|
|
679
|
+
1,
|
|
680
|
+
13,
|
|
681
|
+
12,
|
|
682
|
+
11,
|
|
683
|
+
14,
|
|
684
|
+
2,
|
|
685
|
+
6,
|
|
686
|
+
5,
|
|
687
|
+
10,
|
|
688
|
+
4,
|
|
689
|
+
0,
|
|
690
|
+
15,
|
|
691
|
+
8,
|
|
692
|
+
9,
|
|
693
|
+
0,
|
|
694
|
+
5,
|
|
695
|
+
7,
|
|
696
|
+
2,
|
|
697
|
+
4,
|
|
698
|
+
10,
|
|
699
|
+
15,
|
|
700
|
+
14,
|
|
701
|
+
1,
|
|
702
|
+
11,
|
|
703
|
+
12,
|
|
704
|
+
6,
|
|
705
|
+
8,
|
|
706
|
+
3,
|
|
707
|
+
13,
|
|
708
|
+
2,
|
|
709
|
+
12,
|
|
710
|
+
6,
|
|
711
|
+
10,
|
|
712
|
+
0,
|
|
713
|
+
11,
|
|
714
|
+
8,
|
|
715
|
+
3,
|
|
716
|
+
4,
|
|
717
|
+
13,
|
|
718
|
+
7,
|
|
719
|
+
5,
|
|
720
|
+
15,
|
|
721
|
+
14,
|
|
722
|
+
1,
|
|
723
|
+
9
|
|
724
|
+
]);
|
|
725
|
+
const $ = /* @__PURE__ */ Uint32Array.from([
|
|
726
|
+
4089235720,
|
|
727
|
+
1779033703,
|
|
728
|
+
2227873595,
|
|
729
|
+
3144134277,
|
|
730
|
+
4271175723,
|
|
731
|
+
1013904242,
|
|
732
|
+
1595750129,
|
|
733
|
+
2773480762,
|
|
734
|
+
2917565137,
|
|
735
|
+
1359893119,
|
|
736
|
+
725511199,
|
|
737
|
+
2600822924,
|
|
738
|
+
4215389547,
|
|
739
|
+
528734635,
|
|
740
|
+
327033209,
|
|
741
|
+
1541459225
|
|
742
|
+
]), S = /* @__PURE__ */ new Uint32Array(32);
|
|
743
|
+
function wt(t, e, n, r, i, s) {
|
|
744
|
+
const o = i[s], c = i[s + 1];
|
|
745
|
+
let a = S[2 * t], l = S[2 * t + 1], f = S[2 * e], u = S[2 * e + 1], b = S[2 * n], h = S[2 * n + 1], E = S[2 * r], w = S[2 * r + 1], x = pe(a, f, o);
|
|
746
|
+
l = Ee(x, l, u, c), a = x | 0, { Dh: w, Dl: E } = { Dh: w ^ l, Dl: E ^ a }, { Dh: w, Dl: E } = { Dh: Un(w, E), Dl: qn(w) }, { h, l: b } = st(h, b, w, E), { Bh: u, Bl: f } = { Bh: u ^ h, Bl: f ^ b }, { Bh: u, Bl: f } = { Bh: mt(u, f, 24), Bl: pt(u, f, 24) }, S[2 * t] = a, S[2 * t + 1] = l, S[2 * e] = f, S[2 * e + 1] = u, S[2 * n] = b, S[2 * n + 1] = h, S[2 * r] = E, S[2 * r + 1] = w;
|
|
747
|
+
}
|
|
748
|
+
function yt(t, e, n, r, i, s) {
|
|
749
|
+
const o = i[s], c = i[s + 1];
|
|
750
|
+
let a = S[2 * t], l = S[2 * t + 1], f = S[2 * e], u = S[2 * e + 1], b = S[2 * n], h = S[2 * n + 1], E = S[2 * r], w = S[2 * r + 1], x = pe(a, f, o);
|
|
751
|
+
l = Ee(x, l, u, c), a = x | 0, { Dh: w, Dl: E } = { Dh: w ^ l, Dl: E ^ a }, { Dh: w, Dl: E } = { Dh: mt(w, E, 16), Dl: pt(w, E, 16) }, { h, l: b } = st(h, b, w, E), { Bh: u, Bl: f } = { Bh: u ^ h, Bl: f ^ b }, { Bh: u, Bl: f } = { Bh: zt(u, f, 63), Bl: Vt(u, f, 63) }, S[2 * t] = a, S[2 * t + 1] = l, S[2 * e] = f, S[2 * e + 1] = u, S[2 * n] = b, S[2 * n + 1] = h, S[2 * r] = E, S[2 * r + 1] = w;
|
|
752
|
+
}
|
|
753
|
+
function Pn(t, e = {}, n, r, i) {
|
|
754
|
+
if (F(n), t < 0 || t > n)
|
|
755
|
+
throw new Error("outputLen bigger than keyLen");
|
|
756
|
+
const { key: s, salt: o, personalization: c } = e;
|
|
757
|
+
if (s !== void 0 && (s.length < 1 || s.length > n))
|
|
758
|
+
throw new Error("key length must be undefined or 1.." + n);
|
|
759
|
+
if (o !== void 0 && o.length !== r)
|
|
760
|
+
throw new Error("salt must be undefined or " + r);
|
|
761
|
+
if (c !== void 0 && c.length !== i)
|
|
762
|
+
throw new Error("personalization must be undefined or " + i);
|
|
763
|
+
}
|
|
764
|
+
class Wn extends me {
|
|
765
|
+
constructor(e, n) {
|
|
766
|
+
super(), this.finished = !1, this.destroyed = !1, this.length = 0, this.pos = 0, F(e), F(n), this.blockLen = e, this.outputLen = n, this.buffer = new Uint8Array(e), this.buffer32 = St(this.buffer);
|
|
767
|
+
}
|
|
768
|
+
update(e) {
|
|
769
|
+
Nt(this), e = Bt(e), et(e);
|
|
770
|
+
const { blockLen: n, buffer: r, buffer32: i } = this, s = e.length, o = e.byteOffset, c = e.buffer;
|
|
771
|
+
for (let a = 0; a < s; ) {
|
|
772
|
+
this.pos === n && (gt(i), this.compress(i, 0, !1), gt(i), this.pos = 0);
|
|
773
|
+
const l = Math.min(n - this.pos, s - a), f = o + a;
|
|
774
|
+
if (l === n && !(f % 4) && a + l < s) {
|
|
775
|
+
const u = new Uint32Array(c, f, Math.floor((s - a) / 4));
|
|
776
|
+
gt(u);
|
|
777
|
+
for (let b = 0; a + n < s; b += i.length, a += n)
|
|
778
|
+
this.length += n, this.compress(u, b, !1);
|
|
779
|
+
gt(u);
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
r.set(e.subarray(a, a + l), this.pos), this.pos += l, this.length += l, a += l;
|
|
783
|
+
}
|
|
784
|
+
return this;
|
|
785
|
+
}
|
|
786
|
+
digestInto(e) {
|
|
787
|
+
Nt(this), Ye(e, this);
|
|
788
|
+
const { pos: n, buffer32: r } = this;
|
|
789
|
+
this.finished = !0, rt(this.buffer.subarray(n)), gt(r), this.compress(r, 0, !0), gt(r);
|
|
790
|
+
const i = St(e);
|
|
791
|
+
this.get().forEach((s, o) => i[o] = ft(s));
|
|
792
|
+
}
|
|
793
|
+
digest() {
|
|
794
|
+
const { buffer: e, outputLen: n } = this;
|
|
795
|
+
this.digestInto(e);
|
|
796
|
+
const r = e.slice(0, n);
|
|
797
|
+
return this.destroy(), r;
|
|
798
|
+
}
|
|
799
|
+
_cloneInto(e) {
|
|
800
|
+
const { buffer: n, length: r, finished: i, destroyed: s, outputLen: o, pos: c } = this;
|
|
801
|
+
return e || (e = new this.constructor({ dkLen: o })), e.set(...this.get()), e.buffer.set(n), e.destroyed = s, e.finished = i, e.length = r, e.pos = c, e.outputLen = o, e;
|
|
802
|
+
}
|
|
803
|
+
clone() {
|
|
804
|
+
return this._cloneInto();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
class Qn extends Wn {
|
|
808
|
+
constructor(e = {}) {
|
|
809
|
+
const n = e.dkLen === void 0 ? 64 : e.dkLen;
|
|
810
|
+
super(128, n), this.v0l = $[0] | 0, this.v0h = $[1] | 0, this.v1l = $[2] | 0, this.v1h = $[3] | 0, this.v2l = $[4] | 0, this.v2h = $[5] | 0, this.v3l = $[6] | 0, this.v3h = $[7] | 0, this.v4l = $[8] | 0, this.v4h = $[9] | 0, this.v5l = $[10] | 0, this.v5h = $[11] | 0, this.v6l = $[12] | 0, this.v6h = $[13] | 0, this.v7l = $[14] | 0, this.v7h = $[15] | 0, Pn(n, e, 64, 16, 16);
|
|
811
|
+
let { key: r, personalization: i, salt: s } = e, o = 0;
|
|
812
|
+
if (r !== void 0 && (r = Bt(r), o = r.length), this.v0l ^= this.outputLen | o << 8 | 65536 | 1 << 24, s !== void 0) {
|
|
813
|
+
s = Bt(s);
|
|
814
|
+
const c = St(s);
|
|
815
|
+
this.v4l ^= ft(c[0]), this.v4h ^= ft(c[1]), this.v5l ^= ft(c[2]), this.v5h ^= ft(c[3]);
|
|
816
|
+
}
|
|
817
|
+
if (i !== void 0) {
|
|
818
|
+
i = Bt(i);
|
|
819
|
+
const c = St(i);
|
|
820
|
+
this.v6l ^= ft(c[0]), this.v6h ^= ft(c[1]), this.v7l ^= ft(c[2]), this.v7h ^= ft(c[3]);
|
|
821
|
+
}
|
|
822
|
+
if (r !== void 0) {
|
|
823
|
+
const c = new Uint8Array(this.blockLen);
|
|
824
|
+
c.set(r), this.update(c);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
// prettier-ignore
|
|
828
|
+
get() {
|
|
829
|
+
let { v0l: e, v0h: n, v1l: r, v1h: i, v2l: s, v2h: o, v3l: c, v3h: a, v4l: l, v4h: f, v5l: u, v5h: b, v6l: h, v6h: E, v7l: w, v7h: x } = this;
|
|
830
|
+
return [e, n, r, i, s, o, c, a, l, f, u, b, h, E, w, x];
|
|
831
|
+
}
|
|
832
|
+
// prettier-ignore
|
|
833
|
+
set(e, n, r, i, s, o, c, a, l, f, u, b, h, E, w, x) {
|
|
834
|
+
this.v0l = e | 0, this.v0h = n | 0, this.v1l = r | 0, this.v1h = i | 0, this.v2l = s | 0, this.v2h = o | 0, this.v3l = c | 0, this.v3h = a | 0, this.v4l = l | 0, this.v4h = f | 0, this.v5l = u | 0, this.v5h = b | 0, this.v6l = h | 0, this.v6h = E | 0, this.v7l = w | 0, this.v7h = x | 0;
|
|
835
|
+
}
|
|
836
|
+
compress(e, n, r) {
|
|
837
|
+
this.get().forEach((a, l) => S[l] = a), S.set($, 16);
|
|
838
|
+
let { h: i, l: s } = en(BigInt(this.length));
|
|
839
|
+
S[24] = $[8] ^ s, S[25] = $[9] ^ i, r && (S[28] = ~S[28], S[29] = ~S[29]);
|
|
840
|
+
let o = 0;
|
|
841
|
+
const c = Kn;
|
|
842
|
+
for (let a = 0; a < 12; a++)
|
|
843
|
+
wt(0, 4, 8, 12, e, n + 2 * c[o++]), yt(0, 4, 8, 12, e, n + 2 * c[o++]), wt(1, 5, 9, 13, e, n + 2 * c[o++]), yt(1, 5, 9, 13, e, n + 2 * c[o++]), wt(2, 6, 10, 14, e, n + 2 * c[o++]), yt(2, 6, 10, 14, e, n + 2 * c[o++]), wt(3, 7, 11, 15, e, n + 2 * c[o++]), yt(3, 7, 11, 15, e, n + 2 * c[o++]), wt(0, 5, 10, 15, e, n + 2 * c[o++]), yt(0, 5, 10, 15, e, n + 2 * c[o++]), wt(1, 6, 11, 12, e, n + 2 * c[o++]), yt(1, 6, 11, 12, e, n + 2 * c[o++]), wt(2, 7, 8, 13, e, n + 2 * c[o++]), yt(2, 7, 8, 13, e, n + 2 * c[o++]), wt(3, 4, 9, 14, e, n + 2 * c[o++]), yt(3, 4, 9, 14, e, n + 2 * c[o++]);
|
|
844
|
+
this.v0l ^= S[0] ^ S[16], this.v0h ^= S[1] ^ S[17], this.v1l ^= S[2] ^ S[18], this.v1h ^= S[3] ^ S[19], this.v2l ^= S[4] ^ S[20], this.v2h ^= S[5] ^ S[21], this.v3l ^= S[6] ^ S[22], this.v3h ^= S[7] ^ S[23], this.v4l ^= S[8] ^ S[24], this.v4h ^= S[9] ^ S[25], this.v5l ^= S[10] ^ S[26], this.v5h ^= S[11] ^ S[27], this.v6l ^= S[12] ^ S[28], this.v6h ^= S[13] ^ S[29], this.v7l ^= S[14] ^ S[30], this.v7h ^= S[15] ^ S[31], rt(S);
|
|
845
|
+
}
|
|
846
|
+
destroy() {
|
|
847
|
+
this.destroyed = !0, rt(this.buffer32), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
const Jn = /* @__PURE__ */ On((t) => new Qn(t));
|
|
851
|
+
const os = Jn;
|
|
852
|
+
class on extends me {
|
|
853
|
+
constructor(e, n) {
|
|
854
|
+
super(), this.finished = !1, this.destroyed = !1, $e(e);
|
|
855
|
+
const r = Bt(n);
|
|
856
|
+
if (this.iHash = e.create(), typeof this.iHash.update != "function")
|
|
857
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
858
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
859
|
+
const i = this.blockLen, s = new Uint8Array(i);
|
|
860
|
+
s.set(r.length > i ? e.create().update(r).digest() : r);
|
|
861
|
+
for (let o = 0; o < s.length; o++)
|
|
862
|
+
s[o] ^= 54;
|
|
863
|
+
this.iHash.update(s), this.oHash = e.create();
|
|
864
|
+
for (let o = 0; o < s.length; o++)
|
|
865
|
+
s[o] ^= 106;
|
|
866
|
+
this.oHash.update(s), rt(s);
|
|
867
|
+
}
|
|
868
|
+
update(e) {
|
|
869
|
+
return Nt(this), this.iHash.update(e), this;
|
|
870
|
+
}
|
|
871
|
+
digestInto(e) {
|
|
872
|
+
Nt(this), et(e, this.outputLen), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
|
|
873
|
+
}
|
|
874
|
+
digest() {
|
|
875
|
+
const e = new Uint8Array(this.oHash.outputLen);
|
|
876
|
+
return this.digestInto(e), e;
|
|
877
|
+
}
|
|
878
|
+
_cloneInto(e) {
|
|
879
|
+
e || (e = Object.create(Object.getPrototypeOf(this), {}));
|
|
880
|
+
const { oHash: n, iHash: r, finished: i, destroyed: s, blockLen: o, outputLen: c } = this;
|
|
881
|
+
return e = e, e.finished = i, e.destroyed = s, e.blockLen = o, e.outputLen = c, e.oHash = n._cloneInto(e.oHash), e.iHash = r._cloneInto(e.iHash), e;
|
|
882
|
+
}
|
|
883
|
+
clone() {
|
|
884
|
+
return this._cloneInto();
|
|
885
|
+
}
|
|
886
|
+
destroy() {
|
|
887
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const Be = (t, e, n) => new on(t, e).update(n).digest();
|
|
891
|
+
Be.create = (t, e) => new on(t, e);
|
|
892
|
+
function Fn(t, e, n, r) {
|
|
893
|
+
$e(t);
|
|
894
|
+
const i = Qe({ dkLen: 32, asyncTick: 10 }, r), { c: s, dkLen: o, asyncTick: c } = i;
|
|
895
|
+
if (F(s), F(o), F(c), s < 1)
|
|
896
|
+
throw new Error("iterations (c) should be >= 1");
|
|
897
|
+
const a = Le(e), l = Le(n), f = new Uint8Array(o), u = Be.create(t, a), b = u._cloneInto().update(l);
|
|
898
|
+
return { c: s, dkLen: o, asyncTick: c, DK: f, PRF: u, PRFSalt: b };
|
|
899
|
+
}
|
|
900
|
+
function tr(t, e, n, r, i) {
|
|
901
|
+
return t.destroy(), e.destroy(), r && r.destroy(), rt(i), n;
|
|
902
|
+
}
|
|
903
|
+
function cn(t, e, n, r) {
|
|
904
|
+
const { c: i, dkLen: s, DK: o, PRF: c, PRFSalt: a } = Fn(t, e, n, r);
|
|
905
|
+
let l;
|
|
906
|
+
const f = new Uint8Array(4), u = Wt(f), b = new Uint8Array(c.outputLen);
|
|
907
|
+
for (let h = 1, E = 0; E < s; h++, E += c.outputLen) {
|
|
908
|
+
const w = o.subarray(E, E + c.outputLen);
|
|
909
|
+
u.setInt32(0, h, !1), (l = a._cloneInto(l)).update(f).digestInto(b), w.set(b.subarray(0, w.length));
|
|
910
|
+
for (let x = 1; x < i; x++) {
|
|
911
|
+
c._cloneInto(l).update(b).digestInto(b);
|
|
912
|
+
for (let _ = 0; _ < w.length; _++)
|
|
913
|
+
w[_] ^= b[_];
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return tr(c, a, o, l, b);
|
|
917
|
+
}
|
|
918
|
+
function ke(t, e, n, r, i, s) {
|
|
919
|
+
let o = t[e++] ^ n[r++], c = t[e++] ^ n[r++], a = t[e++] ^ n[r++], l = t[e++] ^ n[r++], f = t[e++] ^ n[r++], u = t[e++] ^ n[r++], b = t[e++] ^ n[r++], h = t[e++] ^ n[r++], E = t[e++] ^ n[r++], w = t[e++] ^ n[r++], x = t[e++] ^ n[r++], _ = t[e++] ^ n[r++], R = t[e++] ^ n[r++], L = t[e++] ^ n[r++], T = t[e++] ^ n[r++], m = t[e++] ^ n[r++], H = o, U = c, O = a, d = l, p = f, y = u, g = b, B = h, v = E, A = w, I = x, q = _, k = R, Z = L, D = T, N = m;
|
|
920
|
+
for (let z = 0; z < 8; z += 2)
|
|
921
|
+
p ^= C(H + k | 0, 7), v ^= C(p + H | 0, 9), k ^= C(v + p | 0, 13), H ^= C(k + v | 0, 18), A ^= C(y + U | 0, 7), Z ^= C(A + y | 0, 9), U ^= C(Z + A | 0, 13), y ^= C(U + Z | 0, 18), D ^= C(I + g | 0, 7), O ^= C(D + I | 0, 9), g ^= C(O + D | 0, 13), I ^= C(g + O | 0, 18), d ^= C(N + q | 0, 7), B ^= C(d + N | 0, 9), q ^= C(B + d | 0, 13), N ^= C(q + B | 0, 18), U ^= C(H + d | 0, 7), O ^= C(U + H | 0, 9), d ^= C(O + U | 0, 13), H ^= C(d + O | 0, 18), g ^= C(y + p | 0, 7), B ^= C(g + y | 0, 9), p ^= C(B + g | 0, 13), y ^= C(p + B | 0, 18), q ^= C(I + A | 0, 7), v ^= C(q + I | 0, 9), A ^= C(v + q | 0, 13), I ^= C(A + v | 0, 18), k ^= C(N + D | 0, 7), Z ^= C(k + N | 0, 9), D ^= C(Z + k | 0, 13), N ^= C(D + Z | 0, 18);
|
|
922
|
+
i[s++] = o + H | 0, i[s++] = c + U | 0, i[s++] = a + O | 0, i[s++] = l + d | 0, i[s++] = f + p | 0, i[s++] = u + y | 0, i[s++] = b + g | 0, i[s++] = h + B | 0, i[s++] = E + v | 0, i[s++] = w + A | 0, i[s++] = x + I | 0, i[s++] = _ + q | 0, i[s++] = R + k | 0, i[s++] = L + Z | 0, i[s++] = T + D | 0, i[s++] = m + N | 0;
|
|
923
|
+
}
|
|
924
|
+
function se(t, e, n, r, i) {
|
|
925
|
+
let s = r + 0, o = r + 16 * i;
|
|
926
|
+
for (let c = 0; c < 16; c++)
|
|
927
|
+
n[o + c] = t[e + (2 * i - 1) * 16 + c];
|
|
928
|
+
for (let c = 0; c < i; c++, s += 16, e += 16)
|
|
929
|
+
ke(n, o, t, e, n, s), c > 0 && (o += 16), ke(n, s, t, e += 16, n, o);
|
|
930
|
+
}
|
|
931
|
+
function er(t, e, n) {
|
|
932
|
+
const r = Qe({
|
|
933
|
+
dkLen: 32,
|
|
934
|
+
asyncTick: 10,
|
|
935
|
+
maxmem: 1073742848
|
|
936
|
+
}, n), { N: i, r: s, p: o, dkLen: c, asyncTick: a, maxmem: l, onProgress: f } = r;
|
|
937
|
+
if (F(i), F(s), F(o), F(c), F(a), F(l), f !== void 0 && typeof f != "function")
|
|
938
|
+
throw new Error("progressCb should be function");
|
|
939
|
+
const u = 128 * s, b = u / 4, h = Math.pow(2, 32);
|
|
940
|
+
if (i <= 1 || (i & i - 1) !== 0 || i > h)
|
|
941
|
+
throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");
|
|
942
|
+
if (o < 0 || o > (h - 1) * 32 / u)
|
|
943
|
+
throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");
|
|
944
|
+
if (c < 0 || c > (h - 1) * 32)
|
|
945
|
+
throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");
|
|
946
|
+
if (u * (i + o) > l)
|
|
947
|
+
throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of " + l);
|
|
948
|
+
const w = cn(Ft, t, e, { c: 1, dkLen: u * o }), x = St(w), _ = St(new Uint8Array(u * i)), R = St(new Uint8Array(u));
|
|
949
|
+
let L = () => {
|
|
950
|
+
};
|
|
951
|
+
if (f) {
|
|
952
|
+
const T = 2 * i * o, m = Math.max(Math.floor(T / 1e4), 1);
|
|
953
|
+
let H = 0;
|
|
954
|
+
L = () => {
|
|
955
|
+
H++, f && (!(H % m) || H === T) && f(H / T);
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
return { N: i, r: s, p: o, dkLen: c, blockSize32: b, V: _, B32: x, B: w, tmp: R, blockMixCb: L, asyncTick: a };
|
|
959
|
+
}
|
|
960
|
+
function nr(t, e, n, r, i) {
|
|
961
|
+
const s = cn(Ft, t, n, { c: 1, dkLen: e });
|
|
962
|
+
return rt(n, r, i), s;
|
|
963
|
+
}
|
|
964
|
+
function is(t, e, n) {
|
|
965
|
+
const { N: r, r: i, p: s, dkLen: o, blockSize32: c, V: a, B32: l, B: f, tmp: u, blockMixCb: b } = er(t, e, n);
|
|
966
|
+
gt(l);
|
|
967
|
+
for (let h = 0; h < s; h++) {
|
|
968
|
+
const E = c * h;
|
|
969
|
+
for (let w = 0; w < c; w++)
|
|
970
|
+
a[w] = l[E + w];
|
|
971
|
+
for (let w = 0, x = 0; w < r - 1; w++)
|
|
972
|
+
se(a, x, a, x += c, i), b();
|
|
973
|
+
se(a, (r - 1) * c, l, E, i), b();
|
|
974
|
+
for (let w = 0; w < r; w++) {
|
|
975
|
+
const x = l[E + c - 16] % r;
|
|
976
|
+
for (let _ = 0; _ < c; _++)
|
|
977
|
+
u[_] = l[E + _] ^ a[x * c + _];
|
|
978
|
+
se(u, 0, l, E, i), b();
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return gt(l), nr(t, o, f, a, u);
|
|
982
|
+
}
|
|
983
|
+
const _e = /* @__PURE__ */ BigInt(0), he = /* @__PURE__ */ BigInt(1);
|
|
984
|
+
function Lt(t, e) {
|
|
985
|
+
if (typeof e != "boolean")
|
|
986
|
+
throw new Error(t + " boolean expected, got " + e);
|
|
987
|
+
}
|
|
988
|
+
function Kt(t) {
|
|
989
|
+
const e = t.toString(16);
|
|
990
|
+
return e.length & 1 ? "0" + e : e;
|
|
991
|
+
}
|
|
992
|
+
function fn(t) {
|
|
993
|
+
if (typeof t != "string")
|
|
994
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
995
|
+
return t === "" ? _e : BigInt("0x" + t);
|
|
996
|
+
}
|
|
997
|
+
function te(t) {
|
|
998
|
+
return fn(It(t));
|
|
999
|
+
}
|
|
1000
|
+
function Tt(t) {
|
|
1001
|
+
return et(t), fn(It(Uint8Array.from(t).reverse()));
|
|
1002
|
+
}
|
|
1003
|
+
function Ae(t, e) {
|
|
1004
|
+
return ge(t.toString(16).padStart(e * 2, "0"));
|
|
1005
|
+
}
|
|
1006
|
+
function Dt(t, e) {
|
|
1007
|
+
return Ae(t, e).reverse();
|
|
1008
|
+
}
|
|
1009
|
+
function V(t, e, n) {
|
|
1010
|
+
let r;
|
|
1011
|
+
if (typeof e == "string")
|
|
1012
|
+
try {
|
|
1013
|
+
r = ge(e);
|
|
1014
|
+
} catch (s) {
|
|
1015
|
+
throw new Error(t + " must be hex string or Uint8Array, cause: " + s);
|
|
1016
|
+
}
|
|
1017
|
+
else if (ye(e))
|
|
1018
|
+
r = Uint8Array.from(e);
|
|
1019
|
+
else
|
|
1020
|
+
throw new Error(t + " must be hex string or Uint8Array");
|
|
1021
|
+
const i = r.length;
|
|
1022
|
+
if (typeof n == "number" && i !== n)
|
|
1023
|
+
throw new Error(t + " of length " + n + " expected, got " + i);
|
|
1024
|
+
return r;
|
|
1025
|
+
}
|
|
1026
|
+
function rr(t, e) {
|
|
1027
|
+
if (t.length !== e.length)
|
|
1028
|
+
return !1;
|
|
1029
|
+
let n = 0;
|
|
1030
|
+
for (let r = 0; r < t.length; r++)
|
|
1031
|
+
n |= t[r] ^ e[r];
|
|
1032
|
+
return n === 0;
|
|
1033
|
+
}
|
|
1034
|
+
const oe = (t) => typeof t == "bigint" && _e <= t;
|
|
1035
|
+
function sr(t, e, n) {
|
|
1036
|
+
return oe(t) && oe(e) && oe(n) && e <= t && t < n;
|
|
1037
|
+
}
|
|
1038
|
+
function qt(t, e, n, r) {
|
|
1039
|
+
if (!sr(e, n, r))
|
|
1040
|
+
throw new Error("expected valid " + t + ": " + n + " <= n < " + r + ", got " + e);
|
|
1041
|
+
}
|
|
1042
|
+
function or(t) {
|
|
1043
|
+
let e;
|
|
1044
|
+
for (e = 0; t > _e; t >>= he, e += 1)
|
|
1045
|
+
;
|
|
1046
|
+
return e;
|
|
1047
|
+
}
|
|
1048
|
+
const ee = (t) => (he << BigInt(t)) - he;
|
|
1049
|
+
function ir(t, e, n) {
|
|
1050
|
+
if (typeof t != "number" || t < 2)
|
|
1051
|
+
throw new Error("hashLen must be a number");
|
|
1052
|
+
if (typeof e != "number" || e < 2)
|
|
1053
|
+
throw new Error("qByteLen must be a number");
|
|
1054
|
+
if (typeof n != "function")
|
|
1055
|
+
throw new Error("hmacFn must be a function");
|
|
1056
|
+
const r = (h) => new Uint8Array(h), i = (h) => Uint8Array.of(h);
|
|
1057
|
+
let s = r(t), o = r(t), c = 0;
|
|
1058
|
+
const a = () => {
|
|
1059
|
+
s.fill(1), o.fill(0), c = 0;
|
|
1060
|
+
}, l = (...h) => n(o, s, ...h), f = (h = r(0)) => {
|
|
1061
|
+
o = l(i(0), h), s = l(), h.length !== 0 && (o = l(i(1), h), s = l());
|
|
1062
|
+
}, u = () => {
|
|
1063
|
+
if (c++ >= 1e3)
|
|
1064
|
+
throw new Error("drbg: tried 1000 values");
|
|
1065
|
+
let h = 0;
|
|
1066
|
+
const E = [];
|
|
1067
|
+
for (; h < e; ) {
|
|
1068
|
+
s = l();
|
|
1069
|
+
const w = s.slice();
|
|
1070
|
+
E.push(w), h += s.length;
|
|
1071
|
+
}
|
|
1072
|
+
return lt(...E);
|
|
1073
|
+
};
|
|
1074
|
+
return (h, E) => {
|
|
1075
|
+
a(), f(h);
|
|
1076
|
+
let w;
|
|
1077
|
+
for (; !(w = E(u())); )
|
|
1078
|
+
f();
|
|
1079
|
+
return a(), w;
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
function Yt(t, e, n = {}) {
|
|
1083
|
+
if (!t || typeof t != "object")
|
|
1084
|
+
throw new Error("expected valid options object");
|
|
1085
|
+
function r(i, s, o) {
|
|
1086
|
+
const c = t[i];
|
|
1087
|
+
if (o && c === void 0)
|
|
1088
|
+
return;
|
|
1089
|
+
const a = typeof c;
|
|
1090
|
+
if (a !== s || c === null)
|
|
1091
|
+
throw new Error(`param "${i}" is invalid: expected ${s}, got ${a}`);
|
|
1092
|
+
}
|
|
1093
|
+
Object.entries(e).forEach(([i, s]) => r(i, s, !1)), Object.entries(n).forEach(([i, s]) => r(i, s, !0));
|
|
1094
|
+
}
|
|
1095
|
+
function Qt(t) {
|
|
1096
|
+
const e = /* @__PURE__ */ new WeakMap();
|
|
1097
|
+
return (n, ...r) => {
|
|
1098
|
+
const i = e.get(n);
|
|
1099
|
+
if (i !== void 0)
|
|
1100
|
+
return i;
|
|
1101
|
+
const s = t(n, ...r);
|
|
1102
|
+
return e.set(n, s), s;
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
const tt = BigInt(0), K = BigInt(1), At = /* @__PURE__ */ BigInt(2), cr = /* @__PURE__ */ BigInt(3), an = /* @__PURE__ */ BigInt(4), ln = /* @__PURE__ */ BigInt(5), un = /* @__PURE__ */ BigInt(8);
|
|
1106
|
+
function j(t, e) {
|
|
1107
|
+
const n = t % e;
|
|
1108
|
+
return n >= tt ? n : e + n;
|
|
1109
|
+
}
|
|
1110
|
+
function G(t, e, n) {
|
|
1111
|
+
let r = t;
|
|
1112
|
+
for (; e-- > tt; )
|
|
1113
|
+
r *= r, r %= n;
|
|
1114
|
+
return r;
|
|
1115
|
+
}
|
|
1116
|
+
function Ue(t, e) {
|
|
1117
|
+
if (t === tt)
|
|
1118
|
+
throw new Error("invert: expected non-zero number");
|
|
1119
|
+
if (e <= tt)
|
|
1120
|
+
throw new Error("invert: expected positive modulus, got " + e);
|
|
1121
|
+
let n = j(t, e), r = e, i = tt, s = K;
|
|
1122
|
+
for (; n !== tt; ) {
|
|
1123
|
+
const c = r / n, a = r % n, l = i - s * c;
|
|
1124
|
+
r = n, n = a, i = s, s = l;
|
|
1125
|
+
}
|
|
1126
|
+
if (r !== K)
|
|
1127
|
+
throw new Error("invert: does not exist");
|
|
1128
|
+
return j(i, e);
|
|
1129
|
+
}
|
|
1130
|
+
function hn(t, e) {
|
|
1131
|
+
const n = (t.ORDER + K) / an, r = t.pow(e, n);
|
|
1132
|
+
if (!t.eql(t.sqr(r), e))
|
|
1133
|
+
throw new Error("Cannot find square root");
|
|
1134
|
+
return r;
|
|
1135
|
+
}
|
|
1136
|
+
function fr(t, e) {
|
|
1137
|
+
const n = (t.ORDER - ln) / un, r = t.mul(e, At), i = t.pow(r, n), s = t.mul(e, i), o = t.mul(t.mul(s, At), i), c = t.mul(s, t.sub(o, t.ONE));
|
|
1138
|
+
if (!t.eql(t.sqr(c), e))
|
|
1139
|
+
throw new Error("Cannot find square root");
|
|
1140
|
+
return c;
|
|
1141
|
+
}
|
|
1142
|
+
function ar(t) {
|
|
1143
|
+
if (t < BigInt(3))
|
|
1144
|
+
throw new Error("sqrt is not defined for small field");
|
|
1145
|
+
let e = t - K, n = 0;
|
|
1146
|
+
for (; e % At === tt; )
|
|
1147
|
+
e /= At, n++;
|
|
1148
|
+
let r = At;
|
|
1149
|
+
const i = Ot(t);
|
|
1150
|
+
for (; qe(i, r) === 1; )
|
|
1151
|
+
if (r++ > 1e3)
|
|
1152
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
1153
|
+
if (n === 1)
|
|
1154
|
+
return hn;
|
|
1155
|
+
let s = i.pow(r, e);
|
|
1156
|
+
const o = (e + K) / At;
|
|
1157
|
+
return function(a, l) {
|
|
1158
|
+
if (a.is0(l))
|
|
1159
|
+
return l;
|
|
1160
|
+
if (qe(a, l) !== 1)
|
|
1161
|
+
throw new Error("Cannot find square root");
|
|
1162
|
+
let f = n, u = a.mul(a.ONE, s), b = a.pow(l, e), h = a.pow(l, o);
|
|
1163
|
+
for (; !a.eql(b, a.ONE); ) {
|
|
1164
|
+
if (a.is0(b))
|
|
1165
|
+
return a.ZERO;
|
|
1166
|
+
let E = 1, w = a.sqr(b);
|
|
1167
|
+
for (; !a.eql(w, a.ONE); )
|
|
1168
|
+
if (E++, w = a.sqr(w), E === f)
|
|
1169
|
+
throw new Error("Cannot find square root");
|
|
1170
|
+
const x = K << BigInt(f - E - 1), _ = a.pow(u, x);
|
|
1171
|
+
f = E, u = a.sqr(_), b = a.mul(b, u), h = a.mul(h, _);
|
|
1172
|
+
}
|
|
1173
|
+
return h;
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
function lr(t) {
|
|
1177
|
+
return t % an === cr ? hn : t % un === ln ? fr : ar(t);
|
|
1178
|
+
}
|
|
1179
|
+
const Et = (t, e) => (j(t, e) & K) === K, ur = [
|
|
1180
|
+
"create",
|
|
1181
|
+
"isValid",
|
|
1182
|
+
"is0",
|
|
1183
|
+
"neg",
|
|
1184
|
+
"inv",
|
|
1185
|
+
"sqrt",
|
|
1186
|
+
"sqr",
|
|
1187
|
+
"eql",
|
|
1188
|
+
"add",
|
|
1189
|
+
"sub",
|
|
1190
|
+
"mul",
|
|
1191
|
+
"pow",
|
|
1192
|
+
"div",
|
|
1193
|
+
"addN",
|
|
1194
|
+
"subN",
|
|
1195
|
+
"mulN",
|
|
1196
|
+
"sqrN"
|
|
1197
|
+
];
|
|
1198
|
+
function hr(t) {
|
|
1199
|
+
const e = {
|
|
1200
|
+
ORDER: "bigint",
|
|
1201
|
+
MASK: "bigint",
|
|
1202
|
+
BYTES: "number",
|
|
1203
|
+
BITS: "number"
|
|
1204
|
+
}, n = ur.reduce((r, i) => (r[i] = "function", r), e);
|
|
1205
|
+
return Yt(t, n), t;
|
|
1206
|
+
}
|
|
1207
|
+
function dr(t, e, n) {
|
|
1208
|
+
if (n < tt)
|
|
1209
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
1210
|
+
if (n === tt)
|
|
1211
|
+
return t.ONE;
|
|
1212
|
+
if (n === K)
|
|
1213
|
+
return e;
|
|
1214
|
+
let r = t.ONE, i = e;
|
|
1215
|
+
for (; n > tt; )
|
|
1216
|
+
n & K && (r = t.mul(r, i)), i = t.sqr(i), n >>= K;
|
|
1217
|
+
return r;
|
|
1218
|
+
}
|
|
1219
|
+
function dn(t, e, n = !1) {
|
|
1220
|
+
const r = new Array(e.length).fill(n ? t.ZERO : void 0), i = e.reduce((o, c, a) => t.is0(c) ? o : (r[a] = o, t.mul(o, c)), t.ONE), s = t.inv(i);
|
|
1221
|
+
return e.reduceRight((o, c, a) => t.is0(c) ? o : (r[a] = t.mul(o, r[a]), t.mul(o, c)), s), r;
|
|
1222
|
+
}
|
|
1223
|
+
function qe(t, e) {
|
|
1224
|
+
const n = (t.ORDER - K) / At, r = t.pow(e, n), i = t.eql(r, t.ONE), s = t.eql(r, t.ZERO), o = t.eql(r, t.neg(t.ONE));
|
|
1225
|
+
if (!i && !s && !o)
|
|
1226
|
+
throw new Error("invalid Legendre symbol result");
|
|
1227
|
+
return i ? 1 : s ? 0 : -1;
|
|
1228
|
+
}
|
|
1229
|
+
function br(t, e) {
|
|
1230
|
+
e !== void 0 && F(e);
|
|
1231
|
+
const n = e !== void 0 ? e : t.toString(2).length, r = Math.ceil(n / 8);
|
|
1232
|
+
return { nBitLength: n, nByteLength: r };
|
|
1233
|
+
}
|
|
1234
|
+
function Ot(t, e, n = !1, r = {}) {
|
|
1235
|
+
if (t <= tt)
|
|
1236
|
+
throw new Error("invalid field: expected ORDER > 0, got " + t);
|
|
1237
|
+
let i, s;
|
|
1238
|
+
if (typeof e == "object" && e != null) {
|
|
1239
|
+
if (r.sqrt || n)
|
|
1240
|
+
throw new Error("cannot specify opts in two arguments");
|
|
1241
|
+
const f = e;
|
|
1242
|
+
f.BITS && (i = f.BITS), f.sqrt && (s = f.sqrt), typeof f.isLE == "boolean" && (n = f.isLE);
|
|
1243
|
+
} else
|
|
1244
|
+
typeof e == "number" && (i = e), r.sqrt && (s = r.sqrt);
|
|
1245
|
+
const { nBitLength: o, nByteLength: c } = br(t, i);
|
|
1246
|
+
if (c > 2048)
|
|
1247
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1248
|
+
let a;
|
|
1249
|
+
const l = Object.freeze({
|
|
1250
|
+
ORDER: t,
|
|
1251
|
+
isLE: n,
|
|
1252
|
+
BITS: o,
|
|
1253
|
+
BYTES: c,
|
|
1254
|
+
MASK: ee(o),
|
|
1255
|
+
ZERO: tt,
|
|
1256
|
+
ONE: K,
|
|
1257
|
+
create: (f) => j(f, t),
|
|
1258
|
+
isValid: (f) => {
|
|
1259
|
+
if (typeof f != "bigint")
|
|
1260
|
+
throw new Error("invalid field element: expected bigint, got " + typeof f);
|
|
1261
|
+
return tt <= f && f < t;
|
|
1262
|
+
},
|
|
1263
|
+
is0: (f) => f === tt,
|
|
1264
|
+
// is valid and invertible
|
|
1265
|
+
isValidNot0: (f) => !l.is0(f) && l.isValid(f),
|
|
1266
|
+
isOdd: (f) => (f & K) === K,
|
|
1267
|
+
neg: (f) => j(-f, t),
|
|
1268
|
+
eql: (f, u) => f === u,
|
|
1269
|
+
sqr: (f) => j(f * f, t),
|
|
1270
|
+
add: (f, u) => j(f + u, t),
|
|
1271
|
+
sub: (f, u) => j(f - u, t),
|
|
1272
|
+
mul: (f, u) => j(f * u, t),
|
|
1273
|
+
pow: (f, u) => dr(l, f, u),
|
|
1274
|
+
div: (f, u) => j(f * Ue(u, t), t),
|
|
1275
|
+
// Same as above, but doesn't normalize
|
|
1276
|
+
sqrN: (f) => f * f,
|
|
1277
|
+
addN: (f, u) => f + u,
|
|
1278
|
+
subN: (f, u) => f - u,
|
|
1279
|
+
mulN: (f, u) => f * u,
|
|
1280
|
+
inv: (f) => Ue(f, t),
|
|
1281
|
+
sqrt: s || ((f) => (a || (a = lr(t)), a(l, f))),
|
|
1282
|
+
toBytes: (f) => n ? Dt(f, c) : Ae(f, c),
|
|
1283
|
+
fromBytes: (f) => {
|
|
1284
|
+
if (f.length !== c)
|
|
1285
|
+
throw new Error("Field.fromBytes: expected " + c + " bytes, got " + f.length);
|
|
1286
|
+
return n ? Tt(f) : te(f);
|
|
1287
|
+
},
|
|
1288
|
+
// TODO: we don't need it here, move out to separate fn
|
|
1289
|
+
invertBatch: (f) => dn(l, f),
|
|
1290
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
1291
|
+
// and it's unclear what to return in there.
|
|
1292
|
+
cmov: (f, u, b) => b ? u : f
|
|
1293
|
+
});
|
|
1294
|
+
return Object.freeze(l);
|
|
1295
|
+
}
|
|
1296
|
+
function bn(t) {
|
|
1297
|
+
if (typeof t != "bigint")
|
|
1298
|
+
throw new Error("field order must be bigint");
|
|
1299
|
+
const e = t.toString(2).length;
|
|
1300
|
+
return Math.ceil(e / 8);
|
|
1301
|
+
}
|
|
1302
|
+
function xn(t) {
|
|
1303
|
+
const e = bn(t);
|
|
1304
|
+
return e + Math.ceil(e / 2);
|
|
1305
|
+
}
|
|
1306
|
+
function xr(t, e, n = !1) {
|
|
1307
|
+
const r = t.length, i = bn(e), s = xn(e);
|
|
1308
|
+
if (r < 16 || r < s || r > 1024)
|
|
1309
|
+
throw new Error("expected " + s + "-1024 bytes of input, got " + r);
|
|
1310
|
+
const o = n ? Tt(t) : te(t), c = j(o, e - K) + K;
|
|
1311
|
+
return n ? Dt(c, i) : Ae(c, i);
|
|
1312
|
+
}
|
|
1313
|
+
const Ct = BigInt(0), vt = BigInt(1);
|
|
1314
|
+
function Gt(t, e) {
|
|
1315
|
+
const n = e.negate();
|
|
1316
|
+
return t ? n : e;
|
|
1317
|
+
}
|
|
1318
|
+
function wn(t, e, n) {
|
|
1319
|
+
const r = e === "pz" ? (o) => o.pz : (o) => o.ez, i = dn(t.Fp, n.map(r));
|
|
1320
|
+
return n.map((o, c) => o.toAffine(i[c])).map(t.fromAffine);
|
|
1321
|
+
}
|
|
1322
|
+
function yn(t, e) {
|
|
1323
|
+
if (!Number.isSafeInteger(t) || t <= 0 || t > e)
|
|
1324
|
+
throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
|
|
1325
|
+
}
|
|
1326
|
+
function ie(t, e) {
|
|
1327
|
+
yn(t, e);
|
|
1328
|
+
const n = Math.ceil(e / t) + 1, r = 2 ** (t - 1), i = 2 ** t, s = ee(t), o = BigInt(t);
|
|
1329
|
+
return { windows: n, windowSize: r, mask: s, maxNumber: i, shiftBy: o };
|
|
1330
|
+
}
|
|
1331
|
+
function Ne(t, e, n) {
|
|
1332
|
+
const { windowSize: r, mask: i, maxNumber: s, shiftBy: o } = n;
|
|
1333
|
+
let c = Number(t & i), a = t >> o;
|
|
1334
|
+
c > r && (c -= s, a += vt);
|
|
1335
|
+
const l = e * r, f = l + Math.abs(c) - 1, u = c === 0, b = c < 0, h = e % 2 !== 0;
|
|
1336
|
+
return { nextN: a, offset: f, isZero: u, isNeg: b, isNegF: h, offsetF: l };
|
|
1337
|
+
}
|
|
1338
|
+
function wr(t, e) {
|
|
1339
|
+
if (!Array.isArray(t))
|
|
1340
|
+
throw new Error("array expected");
|
|
1341
|
+
t.forEach((n, r) => {
|
|
1342
|
+
if (!(n instanceof e))
|
|
1343
|
+
throw new Error("invalid point at index " + r);
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
function yr(t, e) {
|
|
1347
|
+
if (!Array.isArray(t))
|
|
1348
|
+
throw new Error("array of scalars expected");
|
|
1349
|
+
t.forEach((n, r) => {
|
|
1350
|
+
if (!e.isValid(n))
|
|
1351
|
+
throw new Error("invalid scalar at index " + r);
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
const ce = /* @__PURE__ */ new WeakMap(), gn = /* @__PURE__ */ new WeakMap();
|
|
1355
|
+
function fe(t) {
|
|
1356
|
+
return gn.get(t) || 1;
|
|
1357
|
+
}
|
|
1358
|
+
function Te(t) {
|
|
1359
|
+
if (t !== Ct)
|
|
1360
|
+
throw new Error("invalid wNAF");
|
|
1361
|
+
}
|
|
1362
|
+
function mn(t, e) {
|
|
1363
|
+
return {
|
|
1364
|
+
constTimeNegate: Gt,
|
|
1365
|
+
hasPrecomputes(n) {
|
|
1366
|
+
return fe(n) !== 1;
|
|
1367
|
+
},
|
|
1368
|
+
// non-const time multiplication ladder
|
|
1369
|
+
unsafeLadder(n, r, i = t.ZERO) {
|
|
1370
|
+
let s = n;
|
|
1371
|
+
for (; r > Ct; )
|
|
1372
|
+
r & vt && (i = i.add(s)), s = s.double(), r >>= vt;
|
|
1373
|
+
return i;
|
|
1374
|
+
},
|
|
1375
|
+
/**
|
|
1376
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
1377
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1378
|
+
* Number of precomputed points depends on the curve size:
|
|
1379
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1380
|
+
* - 𝑊 is the window size
|
|
1381
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
1382
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1383
|
+
* @param elm Point instance
|
|
1384
|
+
* @param W window size
|
|
1385
|
+
* @returns precomputed point tables flattened to a single array
|
|
1386
|
+
*/
|
|
1387
|
+
precomputeWindow(n, r) {
|
|
1388
|
+
const { windows: i, windowSize: s } = ie(r, e), o = [];
|
|
1389
|
+
let c = n, a = c;
|
|
1390
|
+
for (let l = 0; l < i; l++) {
|
|
1391
|
+
a = c, o.push(a);
|
|
1392
|
+
for (let f = 1; f < s; f++)
|
|
1393
|
+
a = a.add(c), o.push(a);
|
|
1394
|
+
c = a.double();
|
|
1395
|
+
}
|
|
1396
|
+
return o;
|
|
1397
|
+
},
|
|
1398
|
+
/**
|
|
1399
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1400
|
+
* @param W window size
|
|
1401
|
+
* @param precomputes precomputed tables
|
|
1402
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
1403
|
+
* @returns real and fake (for const-time) points
|
|
1404
|
+
*/
|
|
1405
|
+
wNAF(n, r, i) {
|
|
1406
|
+
let s = t.ZERO, o = t.BASE;
|
|
1407
|
+
const c = ie(n, e);
|
|
1408
|
+
for (let a = 0; a < c.windows; a++) {
|
|
1409
|
+
const { nextN: l, offset: f, isZero: u, isNeg: b, isNegF: h, offsetF: E } = Ne(i, a, c);
|
|
1410
|
+
i = l, u ? o = o.add(Gt(h, r[E])) : s = s.add(Gt(b, r[f]));
|
|
1411
|
+
}
|
|
1412
|
+
return Te(i), { p: s, f: o };
|
|
1413
|
+
},
|
|
1414
|
+
/**
|
|
1415
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1416
|
+
* @param W window size
|
|
1417
|
+
* @param precomputes precomputed tables
|
|
1418
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
1419
|
+
* @param acc accumulator point to add result of multiplication
|
|
1420
|
+
* @returns point
|
|
1421
|
+
*/
|
|
1422
|
+
wNAFUnsafe(n, r, i, s = t.ZERO) {
|
|
1423
|
+
const o = ie(n, e);
|
|
1424
|
+
for (let c = 0; c < o.windows && i !== Ct; c++) {
|
|
1425
|
+
const { nextN: a, offset: l, isZero: f, isNeg: u } = Ne(i, c, o);
|
|
1426
|
+
if (i = a, !f) {
|
|
1427
|
+
const b = r[l];
|
|
1428
|
+
s = s.add(u ? b.negate() : b);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
return Te(i), s;
|
|
1432
|
+
},
|
|
1433
|
+
getPrecomputes(n, r, i) {
|
|
1434
|
+
let s = ce.get(r);
|
|
1435
|
+
return s || (s = this.precomputeWindow(r, n), n !== 1 && (typeof i == "function" && (s = i(s)), ce.set(r, s))), s;
|
|
1436
|
+
},
|
|
1437
|
+
wNAFCached(n, r, i) {
|
|
1438
|
+
const s = fe(n);
|
|
1439
|
+
return this.wNAF(s, this.getPrecomputes(s, n, i), r);
|
|
1440
|
+
},
|
|
1441
|
+
wNAFCachedUnsafe(n, r, i, s) {
|
|
1442
|
+
const o = fe(n);
|
|
1443
|
+
return o === 1 ? this.unsafeLadder(n, r, s) : this.wNAFUnsafe(o, this.getPrecomputes(o, n, i), r, s);
|
|
1444
|
+
},
|
|
1445
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1446
|
+
// using windowed method. This specifies window size and
|
|
1447
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1448
|
+
setWindowSize(n, r) {
|
|
1449
|
+
yn(r, e), gn.set(n, r), ce.delete(n);
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
function gr(t, e, n, r) {
|
|
1454
|
+
let i = e, s = t.ZERO, o = t.ZERO;
|
|
1455
|
+
for (; n > Ct || r > Ct; )
|
|
1456
|
+
n & vt && (s = s.add(i)), r & vt && (o = o.add(i)), i = i.double(), n >>= vt, r >>= vt;
|
|
1457
|
+
return { p1: s, p2: o };
|
|
1458
|
+
}
|
|
1459
|
+
function ve(t, e, n, r) {
|
|
1460
|
+
wr(n, t), yr(r, e);
|
|
1461
|
+
const i = n.length, s = r.length;
|
|
1462
|
+
if (i !== s)
|
|
1463
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
1464
|
+
const o = t.ZERO, c = or(BigInt(i));
|
|
1465
|
+
let a = 1;
|
|
1466
|
+
c > 12 ? a = c - 3 : c > 4 ? a = c - 2 : c > 0 && (a = 2);
|
|
1467
|
+
const l = ee(a), f = new Array(Number(l) + 1).fill(o), u = Math.floor((e.BITS - 1) / a) * a;
|
|
1468
|
+
let b = o;
|
|
1469
|
+
for (let h = u; h >= 0; h -= a) {
|
|
1470
|
+
f.fill(o);
|
|
1471
|
+
for (let w = 0; w < s; w++) {
|
|
1472
|
+
const x = r[w], _ = Number(x >> BigInt(h) & l);
|
|
1473
|
+
f[_] = f[_].add(n[w]);
|
|
1474
|
+
}
|
|
1475
|
+
let E = o;
|
|
1476
|
+
for (let w = f.length - 1, x = o; w > 0; w--)
|
|
1477
|
+
x = x.add(f[w]), E = E.add(x);
|
|
1478
|
+
if (b = b.add(E), h !== 0)
|
|
1479
|
+
for (let w = 0; w < a; w++)
|
|
1480
|
+
b = b.double();
|
|
1481
|
+
}
|
|
1482
|
+
return b;
|
|
1483
|
+
}
|
|
1484
|
+
function De(t, e) {
|
|
1485
|
+
if (e) {
|
|
1486
|
+
if (e.ORDER !== t)
|
|
1487
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1488
|
+
return hr(e), e;
|
|
1489
|
+
} else
|
|
1490
|
+
return Ot(t);
|
|
1491
|
+
}
|
|
1492
|
+
function pn(t, e, n = {}) {
|
|
1493
|
+
if (!e || typeof e != "object")
|
|
1494
|
+
throw new Error(`expected valid ${t} CURVE object`);
|
|
1495
|
+
for (const c of ["p", "n", "h"]) {
|
|
1496
|
+
const a = e[c];
|
|
1497
|
+
if (!(typeof a == "bigint" && a > Ct))
|
|
1498
|
+
throw new Error(`CURVE.${c} must be positive bigint`);
|
|
1499
|
+
}
|
|
1500
|
+
const r = De(e.p, n.Fp), i = De(e.n, n.Fn), o = ["Gx", "Gy", "a", t === "weierstrass" ? "b" : "d"];
|
|
1501
|
+
for (const c of o)
|
|
1502
|
+
if (!r.isValid(e[c]))
|
|
1503
|
+
throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
|
|
1504
|
+
return { Fp: r, Fn: i };
|
|
1505
|
+
}
|
|
1506
|
+
const it = BigInt(0), J = BigInt(1), ae = BigInt(2), mr = BigInt(8), pr = { zip215: !0 };
|
|
1507
|
+
function Er(t, e, n, r) {
|
|
1508
|
+
const i = t.sqr(n), s = t.sqr(r), o = t.add(t.mul(e.a, i), s), c = t.add(t.ONE, t.mul(e.d, t.mul(i, s)));
|
|
1509
|
+
return t.eql(o, c);
|
|
1510
|
+
}
|
|
1511
|
+
function Br(t, e = {}) {
|
|
1512
|
+
const { Fp: n, Fn: r } = pn("edwards", t, e), { h: i, n: s } = t;
|
|
1513
|
+
Yt(e, {}, { uvRatio: "function" });
|
|
1514
|
+
const o = ae << BigInt(r.BYTES * 8) - J, c = (w) => n.create(w), a = e.uvRatio || ((w, x) => {
|
|
1515
|
+
try {
|
|
1516
|
+
return { isValid: !0, value: n.sqrt(n.div(w, x)) };
|
|
1517
|
+
} catch {
|
|
1518
|
+
return { isValid: !1, value: it };
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
if (!Er(n, t, t.Gx, t.Gy))
|
|
1522
|
+
throw new Error("bad curve params: generator point");
|
|
1523
|
+
function l(w, x, _ = !1) {
|
|
1524
|
+
const R = _ ? J : it;
|
|
1525
|
+
return qt("coordinate " + w, x, R, o), x;
|
|
1526
|
+
}
|
|
1527
|
+
function f(w) {
|
|
1528
|
+
if (!(w instanceof h))
|
|
1529
|
+
throw new Error("ExtendedPoint expected");
|
|
1530
|
+
}
|
|
1531
|
+
const u = Qt((w, x) => {
|
|
1532
|
+
const { ex: _, ey: R, ez: L } = w, T = w.is0();
|
|
1533
|
+
x == null && (x = T ? mr : n.inv(L));
|
|
1534
|
+
const m = c(_ * x), H = c(R * x), U = c(L * x);
|
|
1535
|
+
if (T)
|
|
1536
|
+
return { x: it, y: J };
|
|
1537
|
+
if (U !== J)
|
|
1538
|
+
throw new Error("invZ was invalid");
|
|
1539
|
+
return { x: m, y: H };
|
|
1540
|
+
}), b = Qt((w) => {
|
|
1541
|
+
const { a: x, d: _ } = t;
|
|
1542
|
+
if (w.is0())
|
|
1543
|
+
throw new Error("bad point: ZERO");
|
|
1544
|
+
const { ex: R, ey: L, ez: T, et: m } = w, H = c(R * R), U = c(L * L), O = c(T * T), d = c(O * O), p = c(H * x), y = c(O * c(p + U)), g = c(d + c(_ * c(H * U)));
|
|
1545
|
+
if (y !== g)
|
|
1546
|
+
throw new Error("bad point: equation left != right (1)");
|
|
1547
|
+
const B = c(R * L), v = c(T * m);
|
|
1548
|
+
if (B !== v)
|
|
1549
|
+
throw new Error("bad point: equation left != right (2)");
|
|
1550
|
+
return !0;
|
|
1551
|
+
});
|
|
1552
|
+
class h {
|
|
1553
|
+
constructor(x, _, R, L) {
|
|
1554
|
+
this.ex = l("x", x), this.ey = l("y", _), this.ez = l("z", R, !0), this.et = l("t", L), Object.freeze(this);
|
|
1555
|
+
}
|
|
1556
|
+
get x() {
|
|
1557
|
+
return this.toAffine().x;
|
|
1558
|
+
}
|
|
1559
|
+
get y() {
|
|
1560
|
+
return this.toAffine().y;
|
|
1561
|
+
}
|
|
1562
|
+
static fromAffine(x) {
|
|
1563
|
+
if (x instanceof h)
|
|
1564
|
+
throw new Error("extended point not allowed");
|
|
1565
|
+
const { x: _, y: R } = x || {};
|
|
1566
|
+
return l("x", _), l("y", R), new h(_, R, J, c(_ * R));
|
|
1567
|
+
}
|
|
1568
|
+
static normalizeZ(x) {
|
|
1569
|
+
return wn(h, "ez", x);
|
|
1570
|
+
}
|
|
1571
|
+
// Multiscalar Multiplication
|
|
1572
|
+
static msm(x, _) {
|
|
1573
|
+
return ve(h, r, x, _);
|
|
1574
|
+
}
|
|
1575
|
+
// "Private method", don't use it directly
|
|
1576
|
+
_setWindowSize(x) {
|
|
1577
|
+
this.precompute(x);
|
|
1578
|
+
}
|
|
1579
|
+
precompute(x = 8, _ = !0) {
|
|
1580
|
+
return E.setWindowSize(this, x), _ || this.multiply(ae), this;
|
|
1581
|
+
}
|
|
1582
|
+
// Not required for fromHex(), which always creates valid points.
|
|
1583
|
+
// Could be useful for fromAffine().
|
|
1584
|
+
assertValidity() {
|
|
1585
|
+
b(this);
|
|
1586
|
+
}
|
|
1587
|
+
// Compare one point to another.
|
|
1588
|
+
equals(x) {
|
|
1589
|
+
f(x);
|
|
1590
|
+
const { ex: _, ey: R, ez: L } = this, { ex: T, ey: m, ez: H } = x, U = c(_ * H), O = c(T * L), d = c(R * H), p = c(m * L);
|
|
1591
|
+
return U === O && d === p;
|
|
1592
|
+
}
|
|
1593
|
+
is0() {
|
|
1594
|
+
return this.equals(h.ZERO);
|
|
1595
|
+
}
|
|
1596
|
+
negate() {
|
|
1597
|
+
return new h(c(-this.ex), this.ey, this.ez, c(-this.et));
|
|
1598
|
+
}
|
|
1599
|
+
// Fast algo for doubling Extended Point.
|
|
1600
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
1601
|
+
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
1602
|
+
double() {
|
|
1603
|
+
const { a: x } = t, { ex: _, ey: R, ez: L } = this, T = c(_ * _), m = c(R * R), H = c(ae * c(L * L)), U = c(x * T), O = _ + R, d = c(c(O * O) - T - m), p = U + m, y = p - H, g = U - m, B = c(d * y), v = c(p * g), A = c(d * g), I = c(y * p);
|
|
1604
|
+
return new h(B, v, I, A);
|
|
1605
|
+
}
|
|
1606
|
+
// Fast algo for adding 2 Extended Points.
|
|
1607
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
1608
|
+
// Cost: 9M + 1*a + 1*d + 7add.
|
|
1609
|
+
add(x) {
|
|
1610
|
+
f(x);
|
|
1611
|
+
const { a: _, d: R } = t, { ex: L, ey: T, ez: m, et: H } = this, { ex: U, ey: O, ez: d, et: p } = x, y = c(L * U), g = c(T * O), B = c(H * R * p), v = c(m * d), A = c((L + T) * (U + O) - y - g), I = v - B, q = v + B, k = c(g - _ * y), Z = c(A * I), D = c(q * k), N = c(A * k), z = c(I * q);
|
|
1612
|
+
return new h(Z, D, z, N);
|
|
1613
|
+
}
|
|
1614
|
+
subtract(x) {
|
|
1615
|
+
return this.add(x.negate());
|
|
1616
|
+
}
|
|
1617
|
+
// Constant-time multiplication.
|
|
1618
|
+
multiply(x) {
|
|
1619
|
+
const _ = x;
|
|
1620
|
+
qt("scalar", _, J, s);
|
|
1621
|
+
const { p: R, f: L } = E.wNAFCached(this, _, h.normalizeZ);
|
|
1622
|
+
return h.normalizeZ([R, L])[0];
|
|
1623
|
+
}
|
|
1624
|
+
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1625
|
+
// It's faster, but should only be used when you don't care about
|
|
1626
|
+
// an exposed private key e.g. sig verification.
|
|
1627
|
+
// Does NOT allow scalars higher than CURVE.n.
|
|
1628
|
+
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
1629
|
+
multiplyUnsafe(x, _ = h.ZERO) {
|
|
1630
|
+
const R = x;
|
|
1631
|
+
return qt("scalar", R, it, s), R === it ? h.ZERO : this.is0() || R === J ? this : E.wNAFCachedUnsafe(this, R, h.normalizeZ, _);
|
|
1632
|
+
}
|
|
1633
|
+
// Checks if point is of small order.
|
|
1634
|
+
// If you add something to small order point, you will have "dirty"
|
|
1635
|
+
// point with torsion component.
|
|
1636
|
+
// Multiplies point by cofactor and checks if the result is 0.
|
|
1637
|
+
isSmallOrder() {
|
|
1638
|
+
return this.multiplyUnsafe(i).is0();
|
|
1639
|
+
}
|
|
1640
|
+
// Multiplies point by curve order and checks if the result is 0.
|
|
1641
|
+
// Returns `false` is the point is dirty.
|
|
1642
|
+
isTorsionFree() {
|
|
1643
|
+
return E.wNAFCachedUnsafe(this, s).is0();
|
|
1644
|
+
}
|
|
1645
|
+
// Converts Extended point to default (x, y) coordinates.
|
|
1646
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
1647
|
+
toAffine(x) {
|
|
1648
|
+
return u(this, x);
|
|
1649
|
+
}
|
|
1650
|
+
clearCofactor() {
|
|
1651
|
+
return i === J ? this : this.multiplyUnsafe(i);
|
|
1652
|
+
}
|
|
1653
|
+
static fromBytes(x, _ = !1) {
|
|
1654
|
+
return et(x), this.fromHex(x, _);
|
|
1655
|
+
}
|
|
1656
|
+
// Converts hash string or Uint8Array to Point.
|
|
1657
|
+
// Uses algo from RFC8032 5.1.3.
|
|
1658
|
+
static fromHex(x, _ = !1) {
|
|
1659
|
+
const { d: R, a: L } = t, T = n.BYTES;
|
|
1660
|
+
x = V("pointHex", x, T), Lt("zip215", _);
|
|
1661
|
+
const m = x.slice(), H = x[T - 1];
|
|
1662
|
+
m[T - 1] = H & -129;
|
|
1663
|
+
const U = Tt(m), O = _ ? o : n.ORDER;
|
|
1664
|
+
qt("pointHex.y", U, it, O);
|
|
1665
|
+
const d = c(U * U), p = c(d - J), y = c(R * d - L);
|
|
1666
|
+
let { isValid: g, value: B } = a(p, y);
|
|
1667
|
+
if (!g)
|
|
1668
|
+
throw new Error("Point.fromHex: invalid y coordinate");
|
|
1669
|
+
const v = (B & J) === J, A = (H & 128) !== 0;
|
|
1670
|
+
if (!_ && B === it && A)
|
|
1671
|
+
throw new Error("Point.fromHex: x=0 and x_0=1");
|
|
1672
|
+
return A !== v && (B = c(-B)), h.fromAffine({ x: B, y: U });
|
|
1673
|
+
}
|
|
1674
|
+
static fromPrivateScalar(x) {
|
|
1675
|
+
return h.BASE.multiply(x);
|
|
1676
|
+
}
|
|
1677
|
+
toBytes() {
|
|
1678
|
+
const { x, y: _ } = this.toAffine(), R = Dt(_, n.BYTES);
|
|
1679
|
+
return R[R.length - 1] |= x & J ? 128 : 0, R;
|
|
1680
|
+
}
|
|
1681
|
+
/** @deprecated use `toBytes` */
|
|
1682
|
+
toRawBytes() {
|
|
1683
|
+
return this.toBytes();
|
|
1684
|
+
}
|
|
1685
|
+
toHex() {
|
|
1686
|
+
return It(this.toBytes());
|
|
1687
|
+
}
|
|
1688
|
+
toString() {
|
|
1689
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
h.BASE = new h(t.Gx, t.Gy, J, c(t.Gx * t.Gy)), h.ZERO = new h(it, J, J, it), h.Fp = n, h.Fn = r;
|
|
1693
|
+
const E = mn(h, r.BYTES * 8);
|
|
1694
|
+
return h;
|
|
1695
|
+
}
|
|
1696
|
+
function _r(t, e) {
|
|
1697
|
+
Yt(e, {
|
|
1698
|
+
hash: "function"
|
|
1699
|
+
}, {
|
|
1700
|
+
adjustScalarBytes: "function",
|
|
1701
|
+
randomBytes: "function",
|
|
1702
|
+
domain: "function",
|
|
1703
|
+
prehash: "function",
|
|
1704
|
+
mapToCurve: "function"
|
|
1705
|
+
});
|
|
1706
|
+
const { prehash: n, hash: r } = e, { BASE: i, Fp: s, Fn: o } = t, c = o.ORDER, a = e.randomBytes || Fe, l = e.adjustScalarBytes || ((m) => m), f = e.domain || ((m, H, U) => {
|
|
1707
|
+
if (Lt("phflag", U), H.length || U)
|
|
1708
|
+
throw new Error("Contexts/pre-hash are not supported");
|
|
1709
|
+
return m;
|
|
1710
|
+
});
|
|
1711
|
+
function u(m) {
|
|
1712
|
+
return o.create(m);
|
|
1713
|
+
}
|
|
1714
|
+
function b(m) {
|
|
1715
|
+
return u(Tt(m));
|
|
1716
|
+
}
|
|
1717
|
+
function h(m) {
|
|
1718
|
+
const H = s.BYTES;
|
|
1719
|
+
m = V("private key", m, H);
|
|
1720
|
+
const U = V("hashed private key", r(m), 2 * H), O = l(U.slice(0, H)), d = U.slice(H, 2 * H), p = b(O);
|
|
1721
|
+
return { head: O, prefix: d, scalar: p };
|
|
1722
|
+
}
|
|
1723
|
+
function E(m) {
|
|
1724
|
+
const { head: H, prefix: U, scalar: O } = h(m), d = i.multiply(O), p = d.toBytes();
|
|
1725
|
+
return { head: H, prefix: U, scalar: O, point: d, pointBytes: p };
|
|
1726
|
+
}
|
|
1727
|
+
function w(m) {
|
|
1728
|
+
return E(m).pointBytes;
|
|
1729
|
+
}
|
|
1730
|
+
function x(m = Uint8Array.of(), ...H) {
|
|
1731
|
+
const U = lt(...H);
|
|
1732
|
+
return b(r(f(U, V("context", m), !!n)));
|
|
1733
|
+
}
|
|
1734
|
+
function _(m, H, U = {}) {
|
|
1735
|
+
m = V("message", m), n && (m = n(m));
|
|
1736
|
+
const { prefix: O, scalar: d, pointBytes: p } = E(H), y = x(U.context, O, m), g = i.multiply(y).toBytes(), B = x(U.context, g, p, m), v = u(y + B * d);
|
|
1737
|
+
qt("signature.s", v, it, c);
|
|
1738
|
+
const A = s.BYTES, I = lt(g, Dt(v, A));
|
|
1739
|
+
return V("result", I, A * 2);
|
|
1740
|
+
}
|
|
1741
|
+
const R = pr;
|
|
1742
|
+
function L(m, H, U, O = R) {
|
|
1743
|
+
const { context: d, zip215: p } = O, y = s.BYTES;
|
|
1744
|
+
m = V("signature", m, 2 * y), H = V("message", H), U = V("publicKey", U, y), p !== void 0 && Lt("zip215", p), n && (H = n(H));
|
|
1745
|
+
const g = Tt(m.slice(y, 2 * y));
|
|
1746
|
+
let B, v, A;
|
|
1747
|
+
try {
|
|
1748
|
+
B = t.fromHex(U, p), v = t.fromHex(m.slice(0, y), p), A = i.multiplyUnsafe(g);
|
|
1749
|
+
} catch {
|
|
1750
|
+
return !1;
|
|
1751
|
+
}
|
|
1752
|
+
if (!p && B.isSmallOrder())
|
|
1753
|
+
return !1;
|
|
1754
|
+
const I = x(d, v.toBytes(), B.toBytes(), H);
|
|
1755
|
+
return v.add(B.multiplyUnsafe(I)).subtract(A).clearCofactor().is0();
|
|
1756
|
+
}
|
|
1757
|
+
return i.precompute(8), { getPublicKey: w, sign: _, verify: L, utils: {
|
|
1758
|
+
getExtendedPublicKey: E,
|
|
1759
|
+
/** ed25519 priv keys are uniform 32b. No need to check for modulo bias, like in secp256k1. */
|
|
1760
|
+
randomPrivateKey: () => a(s.BYTES),
|
|
1761
|
+
/**
|
|
1762
|
+
* We're doing scalar multiplication (used in getPublicKey etc) with precomputed BASE_POINT
|
|
1763
|
+
* values. This slows down first getPublicKey() by milliseconds (see Speed section),
|
|
1764
|
+
* but allows to speed-up subsequent getPublicKey() calls up to 20x.
|
|
1765
|
+
* @param windowSize 2, 4, 8, 16
|
|
1766
|
+
*/
|
|
1767
|
+
precompute(m = 8, H = t.BASE) {
|
|
1768
|
+
return H.precompute(m, !1);
|
|
1769
|
+
}
|
|
1770
|
+
}, Point: t };
|
|
1771
|
+
}
|
|
1772
|
+
function Ar(t) {
|
|
1773
|
+
const e = {
|
|
1774
|
+
a: t.a,
|
|
1775
|
+
d: t.d,
|
|
1776
|
+
p: t.Fp.ORDER,
|
|
1777
|
+
n: t.n,
|
|
1778
|
+
h: t.h,
|
|
1779
|
+
Gx: t.Gx,
|
|
1780
|
+
Gy: t.Gy
|
|
1781
|
+
}, n = t.Fp, r = Ot(e.n, t.nBitLength, !0), i = { Fp: n, Fn: r, uvRatio: t.uvRatio }, s = {
|
|
1782
|
+
hash: t.hash,
|
|
1783
|
+
randomBytes: t.randomBytes,
|
|
1784
|
+
adjustScalarBytes: t.adjustScalarBytes,
|
|
1785
|
+
domain: t.domain,
|
|
1786
|
+
prehash: t.prehash,
|
|
1787
|
+
mapToCurve: t.mapToCurve
|
|
1788
|
+
};
|
|
1789
|
+
return { CURVE: e, curveOpts: i, eddsaOpts: s };
|
|
1790
|
+
}
|
|
1791
|
+
function vr(t, e) {
|
|
1792
|
+
return Object.assign({}, e, { ExtendedPoint: e.Point, CURVE: t });
|
|
1793
|
+
}
|
|
1794
|
+
function Sr(t) {
|
|
1795
|
+
const { CURVE: e, curveOpts: n, eddsaOpts: r } = Ar(t), i = Br(e, n), s = _r(i, r);
|
|
1796
|
+
return vr(t, s);
|
|
1797
|
+
}
|
|
1798
|
+
const cs = BigInt(0), fs = BigInt(1), as = BigInt(2);
|
|
1799
|
+
const Ir = BigInt(0), ut = BigInt(1), Ce = BigInt(2), ls = BigInt(3), Lr = BigInt(5), Or = BigInt(8), ne = {
|
|
1800
|
+
p: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),
|
|
1801
|
+
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
1802
|
+
h: Or,
|
|
1803
|
+
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
1804
|
+
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
1805
|
+
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
1806
|
+
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
1807
|
+
};
|
|
1808
|
+
function Hr(t) {
|
|
1809
|
+
const e = BigInt(10), n = BigInt(20), r = BigInt(40), i = BigInt(80), s = ne.p, c = t * t % s * t % s, a = G(c, Ce, s) * c % s, l = G(a, ut, s) * t % s, f = G(l, Lr, s) * l % s, u = G(f, e, s) * f % s, b = G(u, n, s) * u % s, h = G(b, r, s) * b % s, E = G(h, i, s) * h % s, w = G(E, i, s) * h % s, x = G(w, e, s) * f % s;
|
|
1810
|
+
return { pow_p_5_8: G(x, Ce, s) * t % s, b2: c };
|
|
1811
|
+
}
|
|
1812
|
+
function Rr(t) {
|
|
1813
|
+
return t[0] &= 248, t[31] &= 127, t[31] |= 64, t;
|
|
1814
|
+
}
|
|
1815
|
+
const de = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
1816
|
+
function Se(t, e) {
|
|
1817
|
+
const n = ne.p, r = j(e * e * e, n), i = j(r * r * e, n), s = Hr(t * i).pow_p_5_8;
|
|
1818
|
+
let o = j(t * r * s, n);
|
|
1819
|
+
const c = j(e * o * o, n), a = o, l = j(o * de, n), f = c === t, u = c === j(-t, n), b = c === j(-t * de, n);
|
|
1820
|
+
return f && (o = a), (u || b) && (o = l), Et(o, n) && (o = j(-o, n)), { isValid: f || u, value: o };
|
|
1821
|
+
}
|
|
1822
|
+
const Ut = Ot(ne.p, void 0, !0), kr = {
|
|
1823
|
+
...ne,
|
|
1824
|
+
Fp: Ut,
|
|
1825
|
+
hash: sn,
|
|
1826
|
+
adjustScalarBytes: Rr,
|
|
1827
|
+
// dom2
|
|
1828
|
+
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
1829
|
+
// Constant-time, u/√v
|
|
1830
|
+
uvRatio: Se
|
|
1831
|
+
}, nt = Sr(kr);
|
|
1832
|
+
function le(t) {
|
|
1833
|
+
if (!(t instanceof Y))
|
|
1834
|
+
throw new Error("RistrettoPoint expected");
|
|
1835
|
+
}
|
|
1836
|
+
const be = de, Ur = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"), qr = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"), Nr = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"), Tr = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"), Ze = (t) => Se(ut, t), Dr = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ue = (t) => nt.CURVE.Fp.create(Tt(t) & Dr);
|
|
1837
|
+
function Me(t) {
|
|
1838
|
+
const { d: e } = nt.CURVE, n = nt.CURVE.Fp.ORDER, r = nt.CURVE.Fp.create, i = r(be * t * t), s = r((i + ut) * Nr);
|
|
1839
|
+
let o = BigInt(-1);
|
|
1840
|
+
const c = r((o - e * i) * r(i + e));
|
|
1841
|
+
let { isValid: a, value: l } = Se(s, c), f = r(l * t);
|
|
1842
|
+
Et(f, n) || (f = r(-f)), a || (l = f), a || (o = i);
|
|
1843
|
+
const u = r(o * (i - ut) * Tr - c), b = l * l, h = r((l + l) * c), E = r(u * Ur), w = r(ut - b), x = r(ut + b);
|
|
1844
|
+
return new nt.Point(r(h * x), r(w * E), r(E * x), r(h * w));
|
|
1845
|
+
}
|
|
1846
|
+
class Y {
|
|
1847
|
+
// Private property to discourage combining ExtendedPoint + RistrettoPoint
|
|
1848
|
+
// Always use Ristretto encoding/decoding instead.
|
|
1849
|
+
constructor(e) {
|
|
1850
|
+
this.ep = e;
|
|
1851
|
+
}
|
|
1852
|
+
static fromAffine(e) {
|
|
1853
|
+
return new Y(nt.Point.fromAffine(e));
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Takes uniform output of 64-byte hash function like sha512 and converts it to `RistrettoPoint`.
|
|
1857
|
+
* The hash-to-group operation applies Elligator twice and adds the results.
|
|
1858
|
+
* **Note:** this is one-way map, there is no conversion from point to hash.
|
|
1859
|
+
* Described in [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#appendix-B) and on
|
|
1860
|
+
* the [website](https://ristretto.group/formulas/elligator.html).
|
|
1861
|
+
* @param hex 64-byte output of a hash function
|
|
1862
|
+
*/
|
|
1863
|
+
static hashToCurve(e) {
|
|
1864
|
+
e = V("ristrettoHash", e, 64);
|
|
1865
|
+
const n = ue(e.slice(0, 32)), r = Me(n), i = ue(e.slice(32, 64)), s = Me(i);
|
|
1866
|
+
return new Y(r.add(s));
|
|
1867
|
+
}
|
|
1868
|
+
static fromBytes(e) {
|
|
1869
|
+
return et(e), this.fromHex(e);
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Converts ristretto-encoded string to ristretto point.
|
|
1873
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
|
|
1874
|
+
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
1875
|
+
*/
|
|
1876
|
+
static fromHex(e) {
|
|
1877
|
+
e = V("ristrettoHex", e, 32);
|
|
1878
|
+
const { a: n, d: r } = nt.CURVE, i = Ut.ORDER, s = Ut.create, o = "RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint", c = ue(e);
|
|
1879
|
+
if (!rr(Dt(c, 32), e) || Et(c, i))
|
|
1880
|
+
throw new Error(o);
|
|
1881
|
+
const a = s(c * c), l = s(ut + n * a), f = s(ut - n * a), u = s(l * l), b = s(f * f), h = s(n * r * u - b), { isValid: E, value: w } = Ze(s(h * b)), x = s(w * f), _ = s(w * x * h);
|
|
1882
|
+
let R = s((c + c) * x);
|
|
1883
|
+
Et(R, i) && (R = s(-R));
|
|
1884
|
+
const L = s(l * _), T = s(R * L);
|
|
1885
|
+
if (!E || Et(T, i) || L === Ir)
|
|
1886
|
+
throw new Error(o);
|
|
1887
|
+
return new Y(new nt.Point(R, L, ut, T));
|
|
1888
|
+
}
|
|
1889
|
+
static msm(e, n) {
|
|
1890
|
+
const r = Ot(nt.CURVE.n, nt.CURVE.nBitLength);
|
|
1891
|
+
return ve(Y, r, e, n);
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Encodes ristretto point to Uint8Array.
|
|
1895
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
|
|
1896
|
+
*/
|
|
1897
|
+
toBytes() {
|
|
1898
|
+
let { ex: e, ey: n, ez: r, et: i } = this.ep;
|
|
1899
|
+
const s = Ut.ORDER, o = Ut.create, c = o(o(r + n) * o(r - n)), a = o(e * n), l = o(a * a), { value: f } = Ze(o(c * l)), u = o(f * c), b = o(f * a), h = o(u * b * i);
|
|
1900
|
+
let E;
|
|
1901
|
+
if (Et(i * h, s)) {
|
|
1902
|
+
let x = o(n * be), _ = o(e * be);
|
|
1903
|
+
e = x, n = _, E = o(u * qr);
|
|
1904
|
+
} else
|
|
1905
|
+
E = b;
|
|
1906
|
+
Et(e * h, s) && (n = o(-n));
|
|
1907
|
+
let w = o((r - n) * E);
|
|
1908
|
+
return Et(w, s) && (w = o(-w)), Dt(w, 32);
|
|
1909
|
+
}
|
|
1910
|
+
/** @deprecated use `toBytes` */
|
|
1911
|
+
toRawBytes() {
|
|
1912
|
+
return this.toBytes();
|
|
1913
|
+
}
|
|
1914
|
+
toHex() {
|
|
1915
|
+
return It(this.toBytes());
|
|
1916
|
+
}
|
|
1917
|
+
toString() {
|
|
1918
|
+
return this.toHex();
|
|
1919
|
+
}
|
|
1920
|
+
/**
|
|
1921
|
+
* Compares two Ristretto points.
|
|
1922
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
|
|
1923
|
+
*/
|
|
1924
|
+
equals(e) {
|
|
1925
|
+
le(e);
|
|
1926
|
+
const { ex: n, ey: r } = this.ep, { ex: i, ey: s } = e.ep, o = Ut.create, c = o(n * s) === o(r * i), a = o(r * s) === o(n * i);
|
|
1927
|
+
return c || a;
|
|
1928
|
+
}
|
|
1929
|
+
add(e) {
|
|
1930
|
+
return le(e), new Y(this.ep.add(e.ep));
|
|
1931
|
+
}
|
|
1932
|
+
subtract(e) {
|
|
1933
|
+
return le(e), new Y(this.ep.subtract(e.ep));
|
|
1934
|
+
}
|
|
1935
|
+
multiply(e) {
|
|
1936
|
+
return new Y(this.ep.multiply(e));
|
|
1937
|
+
}
|
|
1938
|
+
multiplyUnsafe(e) {
|
|
1939
|
+
return new Y(this.ep.multiplyUnsafe(e));
|
|
1940
|
+
}
|
|
1941
|
+
double() {
|
|
1942
|
+
return new Y(this.ep.double());
|
|
1943
|
+
}
|
|
1944
|
+
negate() {
|
|
1945
|
+
return new Y(this.ep.negate());
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
const us = (Y.BASE || (Y.BASE = new Y(nt.Point.BASE)), Y.ZERO || (Y.ZERO = new Y(nt.Point.ZERO)), Y), Cr = BigInt(0), Mt = BigInt(1), Zr = BigInt(2), Mr = BigInt(7), zr = BigInt(256), Vr = BigInt(113), En = [], Bn = [], _n = [];
|
|
1949
|
+
for (let t = 0, e = Mt, n = 1, r = 0; t < 24; t++) {
|
|
1950
|
+
[n, r] = [r, (2 * n + 3 * r) % 5], En.push(2 * (5 * r + n)), Bn.push((t + 1) * (t + 2) / 2 % 64);
|
|
1951
|
+
let i = Cr;
|
|
1952
|
+
for (let s = 0; s < 7; s++)
|
|
1953
|
+
e = (e << Mt ^ (e >> Mr) * Vr) % zr, e & Zr && (i ^= Mt << (Mt << /* @__PURE__ */ BigInt(s)) - Mt);
|
|
1954
|
+
_n.push(i);
|
|
1955
|
+
}
|
|
1956
|
+
const An = nn(_n, !0), Gr = An[0], jr = An[1], ze = (t, e, n) => n > 32 ? Dn(t, e, n) : Nn(t, e, n), Ve = (t, e, n) => n > 32 ? Cn(t, e, n) : Tn(t, e, n);
|
|
1957
|
+
function hs(t, e = 24) {
|
|
1958
|
+
const n = new Uint32Array(10);
|
|
1959
|
+
for (let r = 24 - e; r < 24; r++) {
|
|
1960
|
+
for (let o = 0; o < 10; o++)
|
|
1961
|
+
n[o] = t[o] ^ t[o + 10] ^ t[o + 20] ^ t[o + 30] ^ t[o + 40];
|
|
1962
|
+
for (let o = 0; o < 10; o += 2) {
|
|
1963
|
+
const c = (o + 8) % 10, a = (o + 2) % 10, l = n[a], f = n[a + 1], u = ze(l, f, 1) ^ n[c], b = Ve(l, f, 1) ^ n[c + 1];
|
|
1964
|
+
for (let h = 0; h < 50; h += 10)
|
|
1965
|
+
t[o + h] ^= u, t[o + h + 1] ^= b;
|
|
1966
|
+
}
|
|
1967
|
+
let i = t[2], s = t[3];
|
|
1968
|
+
for (let o = 0; o < 24; o++) {
|
|
1969
|
+
const c = Bn[o], a = ze(i, s, c), l = Ve(i, s, c), f = En[o];
|
|
1970
|
+
i = t[f], s = t[f + 1], t[f] = a, t[f + 1] = l;
|
|
1971
|
+
}
|
|
1972
|
+
for (let o = 0; o < 50; o += 10) {
|
|
1973
|
+
for (let c = 0; c < 10; c++)
|
|
1974
|
+
n[c] = t[o + c];
|
|
1975
|
+
for (let c = 0; c < 10; c++)
|
|
1976
|
+
t[o + c] ^= ~n[(c + 2) % 10] & n[(c + 4) % 10];
|
|
1977
|
+
}
|
|
1978
|
+
t[0] ^= Gr[r], t[1] ^= jr[r];
|
|
1979
|
+
}
|
|
1980
|
+
rt(n);
|
|
1981
|
+
}
|
|
1982
|
+
const ds = sn;
|
|
1983
|
+
function Ge(t) {
|
|
1984
|
+
t.lowS !== void 0 && Lt("lowS", t.lowS), t.prehash !== void 0 && Lt("prehash", t.prehash);
|
|
1985
|
+
}
|
|
1986
|
+
class $r extends Error {
|
|
1987
|
+
constructor(e = "") {
|
|
1988
|
+
super(e);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
const at = {
|
|
1992
|
+
// asn.1 DER encoding utils
|
|
1993
|
+
Err: $r,
|
|
1994
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
1995
|
+
_tlv: {
|
|
1996
|
+
encode: (t, e) => {
|
|
1997
|
+
const { Err: n } = at;
|
|
1998
|
+
if (t < 0 || t > 256)
|
|
1999
|
+
throw new n("tlv.encode: wrong tag");
|
|
2000
|
+
if (e.length & 1)
|
|
2001
|
+
throw new n("tlv.encode: unpadded data");
|
|
2002
|
+
const r = e.length / 2, i = Kt(r);
|
|
2003
|
+
if (i.length / 2 & 128)
|
|
2004
|
+
throw new n("tlv.encode: long form length too big");
|
|
2005
|
+
const s = r > 127 ? Kt(i.length / 2 | 128) : "";
|
|
2006
|
+
return Kt(t) + s + i + e;
|
|
2007
|
+
},
|
|
2008
|
+
// v - value, l - left bytes (unparsed)
|
|
2009
|
+
decode(t, e) {
|
|
2010
|
+
const { Err: n } = at;
|
|
2011
|
+
let r = 0;
|
|
2012
|
+
if (t < 0 || t > 256)
|
|
2013
|
+
throw new n("tlv.encode: wrong tag");
|
|
2014
|
+
if (e.length < 2 || e[r++] !== t)
|
|
2015
|
+
throw new n("tlv.decode: wrong tlv");
|
|
2016
|
+
const i = e[r++], s = !!(i & 128);
|
|
2017
|
+
let o = 0;
|
|
2018
|
+
if (!s)
|
|
2019
|
+
o = i;
|
|
2020
|
+
else {
|
|
2021
|
+
const a = i & 127;
|
|
2022
|
+
if (!a)
|
|
2023
|
+
throw new n("tlv.decode(long): indefinite length not supported");
|
|
2024
|
+
if (a > 4)
|
|
2025
|
+
throw new n("tlv.decode(long): byte length is too big");
|
|
2026
|
+
const l = e.subarray(r, r + a);
|
|
2027
|
+
if (l.length !== a)
|
|
2028
|
+
throw new n("tlv.decode: length bytes not complete");
|
|
2029
|
+
if (l[0] === 0)
|
|
2030
|
+
throw new n("tlv.decode(long): zero leftmost byte");
|
|
2031
|
+
for (const f of l)
|
|
2032
|
+
o = o << 8 | f;
|
|
2033
|
+
if (r += a, o < 128)
|
|
2034
|
+
throw new n("tlv.decode(long): not minimal encoding");
|
|
2035
|
+
}
|
|
2036
|
+
const c = e.subarray(r, r + o);
|
|
2037
|
+
if (c.length !== o)
|
|
2038
|
+
throw new n("tlv.decode: wrong value length");
|
|
2039
|
+
return { v: c, l: e.subarray(r + o) };
|
|
2040
|
+
}
|
|
2041
|
+
},
|
|
2042
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
2043
|
+
// since we always use positive integers here. It must always be empty:
|
|
2044
|
+
// - add zero byte if exists
|
|
2045
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
2046
|
+
_int: {
|
|
2047
|
+
encode(t) {
|
|
2048
|
+
const { Err: e } = at;
|
|
2049
|
+
if (t < jt)
|
|
2050
|
+
throw new e("integer: negative integers are not allowed");
|
|
2051
|
+
let n = Kt(t);
|
|
2052
|
+
if (Number.parseInt(n[0], 16) & 8 && (n = "00" + n), n.length & 1)
|
|
2053
|
+
throw new e("unexpected DER parsing assertion: unpadded hex");
|
|
2054
|
+
return n;
|
|
2055
|
+
},
|
|
2056
|
+
decode(t) {
|
|
2057
|
+
const { Err: e } = at;
|
|
2058
|
+
if (t[0] & 128)
|
|
2059
|
+
throw new e("invalid signature integer: negative");
|
|
2060
|
+
if (t[0] === 0 && !(t[1] & 128))
|
|
2061
|
+
throw new e("invalid signature integer: unnecessary leading zero");
|
|
2062
|
+
return te(t);
|
|
2063
|
+
}
|
|
2064
|
+
},
|
|
2065
|
+
toSig(t) {
|
|
2066
|
+
const { Err: e, _int: n, _tlv: r } = at, i = V("signature", t), { v: s, l: o } = r.decode(48, i);
|
|
2067
|
+
if (o.length)
|
|
2068
|
+
throw new e("invalid signature: left bytes after parsing");
|
|
2069
|
+
const { v: c, l: a } = r.decode(2, s), { v: l, l: f } = r.decode(2, a);
|
|
2070
|
+
if (f.length)
|
|
2071
|
+
throw new e("invalid signature: left bytes after parsing");
|
|
2072
|
+
return { r: n.decode(c), s: n.decode(l) };
|
|
2073
|
+
},
|
|
2074
|
+
hexFromSig(t) {
|
|
2075
|
+
const { _tlv: e, _int: n } = at, r = e.encode(2, n.encode(t.r)), i = e.encode(2, n.encode(t.s)), s = r + i;
|
|
2076
|
+
return e.encode(48, s);
|
|
2077
|
+
}
|
|
2078
|
+
}, jt = BigInt(0), $t = BigInt(1), Yr = BigInt(2), Pt = BigInt(3), Xr = BigInt(4);
|
|
2079
|
+
function Kr(t, e, n) {
|
|
2080
|
+
function r(i) {
|
|
2081
|
+
const s = t.sqr(i), o = t.mul(s, i);
|
|
2082
|
+
return t.add(t.add(o, t.mul(i, e)), n);
|
|
2083
|
+
}
|
|
2084
|
+
return r;
|
|
2085
|
+
}
|
|
2086
|
+
function vn(t, e, n) {
|
|
2087
|
+
const { BYTES: r } = t;
|
|
2088
|
+
function i(s) {
|
|
2089
|
+
let o;
|
|
2090
|
+
if (typeof s == "bigint")
|
|
2091
|
+
o = s;
|
|
2092
|
+
else {
|
|
2093
|
+
let c = V("private key", s);
|
|
2094
|
+
if (e) {
|
|
2095
|
+
if (!e.includes(c.length * 2))
|
|
2096
|
+
throw new Error("invalid private key");
|
|
2097
|
+
const a = new Uint8Array(r);
|
|
2098
|
+
a.set(c, a.length - c.length), c = a;
|
|
2099
|
+
}
|
|
2100
|
+
try {
|
|
2101
|
+
o = t.fromBytes(c);
|
|
2102
|
+
} catch {
|
|
2103
|
+
throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof s}`);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
if (n && (o = t.create(o)), !t.isValidNot0(o))
|
|
2107
|
+
throw new Error("invalid private key: out of range [1..N-1]");
|
|
2108
|
+
return o;
|
|
2109
|
+
}
|
|
2110
|
+
return i;
|
|
2111
|
+
}
|
|
2112
|
+
function Pr(t, e = {}) {
|
|
2113
|
+
const { Fp: n, Fn: r } = pn("weierstrass", t, e), { h: i, n: s } = t;
|
|
2114
|
+
Yt(e, {}, {
|
|
2115
|
+
allowInfinityPoint: "boolean",
|
|
2116
|
+
clearCofactor: "function",
|
|
2117
|
+
isTorsionFree: "function",
|
|
2118
|
+
fromBytes: "function",
|
|
2119
|
+
toBytes: "function",
|
|
2120
|
+
endo: "object",
|
|
2121
|
+
wrapPrivateKey: "boolean"
|
|
2122
|
+
});
|
|
2123
|
+
const { endo: o } = e;
|
|
2124
|
+
if (o && (!n.is0(t.a) || typeof o.beta != "bigint" || typeof o.splitScalar != "function"))
|
|
2125
|
+
throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
|
|
2126
|
+
function c() {
|
|
2127
|
+
if (!n.isOdd)
|
|
2128
|
+
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
2129
|
+
}
|
|
2130
|
+
function a(O, d, p) {
|
|
2131
|
+
const { x: y, y: g } = d.toAffine(), B = n.toBytes(y);
|
|
2132
|
+
if (Lt("isCompressed", p), p) {
|
|
2133
|
+
c();
|
|
2134
|
+
const v = !n.isOdd(g);
|
|
2135
|
+
return lt(Sn(v), B);
|
|
2136
|
+
} else
|
|
2137
|
+
return lt(Uint8Array.of(4), B, n.toBytes(g));
|
|
2138
|
+
}
|
|
2139
|
+
function l(O) {
|
|
2140
|
+
et(O);
|
|
2141
|
+
const d = n.BYTES, p = d + 1, y = 2 * d + 1, g = O.length, B = O[0], v = O.subarray(1);
|
|
2142
|
+
if (g === p && (B === 2 || B === 3)) {
|
|
2143
|
+
const A = n.fromBytes(v);
|
|
2144
|
+
if (!n.isValid(A))
|
|
2145
|
+
throw new Error("bad point: is not on curve, wrong x");
|
|
2146
|
+
const I = b(A);
|
|
2147
|
+
let q;
|
|
2148
|
+
try {
|
|
2149
|
+
q = n.sqrt(I);
|
|
2150
|
+
} catch (D) {
|
|
2151
|
+
const N = D instanceof Error ? ": " + D.message : "";
|
|
2152
|
+
throw new Error("bad point: is not on curve, sqrt error" + N);
|
|
2153
|
+
}
|
|
2154
|
+
c();
|
|
2155
|
+
const k = n.isOdd(q);
|
|
2156
|
+
return (B & 1) === 1 !== k && (q = n.neg(q)), { x: A, y: q };
|
|
2157
|
+
} else if (g === y && B === 4) {
|
|
2158
|
+
const A = n.fromBytes(v.subarray(d * 0, d * 1)), I = n.fromBytes(v.subarray(d * 1, d * 2));
|
|
2159
|
+
if (!h(A, I))
|
|
2160
|
+
throw new Error("bad point: is not on curve");
|
|
2161
|
+
return { x: A, y: I };
|
|
2162
|
+
} else
|
|
2163
|
+
throw new Error(`bad point: got length ${g}, expected compressed=${p} or uncompressed=${y}`);
|
|
2164
|
+
}
|
|
2165
|
+
const f = e.toBytes || a, u = e.fromBytes || l, b = Kr(n, t.a, t.b);
|
|
2166
|
+
function h(O, d) {
|
|
2167
|
+
const p = n.sqr(d), y = b(O);
|
|
2168
|
+
return n.eql(p, y);
|
|
2169
|
+
}
|
|
2170
|
+
if (!h(t.Gx, t.Gy))
|
|
2171
|
+
throw new Error("bad curve params: generator point");
|
|
2172
|
+
const E = n.mul(n.pow(t.a, Pt), Xr), w = n.mul(n.sqr(t.b), BigInt(27));
|
|
2173
|
+
if (n.is0(n.add(E, w)))
|
|
2174
|
+
throw new Error("bad curve params: a or b");
|
|
2175
|
+
function x(O, d, p = !1) {
|
|
2176
|
+
if (!n.isValid(d) || p && n.is0(d))
|
|
2177
|
+
throw new Error(`bad point coordinate ${O}`);
|
|
2178
|
+
return d;
|
|
2179
|
+
}
|
|
2180
|
+
function _(O) {
|
|
2181
|
+
if (!(O instanceof m))
|
|
2182
|
+
throw new Error("ProjectivePoint expected");
|
|
2183
|
+
}
|
|
2184
|
+
const R = Qt((O, d) => {
|
|
2185
|
+
const { px: p, py: y, pz: g } = O;
|
|
2186
|
+
if (n.eql(g, n.ONE))
|
|
2187
|
+
return { x: p, y };
|
|
2188
|
+
const B = O.is0();
|
|
2189
|
+
d == null && (d = B ? n.ONE : n.inv(g));
|
|
2190
|
+
const v = n.mul(p, d), A = n.mul(y, d), I = n.mul(g, d);
|
|
2191
|
+
if (B)
|
|
2192
|
+
return { x: n.ZERO, y: n.ZERO };
|
|
2193
|
+
if (!n.eql(I, n.ONE))
|
|
2194
|
+
throw new Error("invZ was invalid");
|
|
2195
|
+
return { x: v, y: A };
|
|
2196
|
+
}), L = Qt((O) => {
|
|
2197
|
+
if (O.is0()) {
|
|
2198
|
+
if (e.allowInfinityPoint && !n.is0(O.py))
|
|
2199
|
+
return;
|
|
2200
|
+
throw new Error("bad point: ZERO");
|
|
2201
|
+
}
|
|
2202
|
+
const { x: d, y: p } = O.toAffine();
|
|
2203
|
+
if (!n.isValid(d) || !n.isValid(p))
|
|
2204
|
+
throw new Error("bad point: x or y not field elements");
|
|
2205
|
+
if (!h(d, p))
|
|
2206
|
+
throw new Error("bad point: equation left != right");
|
|
2207
|
+
if (!O.isTorsionFree())
|
|
2208
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
2209
|
+
return !0;
|
|
2210
|
+
});
|
|
2211
|
+
function T(O, d, p, y, g) {
|
|
2212
|
+
return p = new m(n.mul(p.px, O), p.py, p.pz), d = Gt(y, d), p = Gt(g, p), d.add(p);
|
|
2213
|
+
}
|
|
2214
|
+
class m {
|
|
2215
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2216
|
+
constructor(d, p, y) {
|
|
2217
|
+
this.px = x("x", d), this.py = x("y", p, !0), this.pz = x("z", y), Object.freeze(this);
|
|
2218
|
+
}
|
|
2219
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2220
|
+
static fromAffine(d) {
|
|
2221
|
+
const { x: p, y } = d || {};
|
|
2222
|
+
if (!d || !n.isValid(p) || !n.isValid(y))
|
|
2223
|
+
throw new Error("invalid affine point");
|
|
2224
|
+
if (d instanceof m)
|
|
2225
|
+
throw new Error("projective point not allowed");
|
|
2226
|
+
return n.is0(p) && n.is0(y) ? m.ZERO : new m(p, y, n.ONE);
|
|
2227
|
+
}
|
|
2228
|
+
get x() {
|
|
2229
|
+
return this.toAffine().x;
|
|
2230
|
+
}
|
|
2231
|
+
get y() {
|
|
2232
|
+
return this.toAffine().y;
|
|
2233
|
+
}
|
|
2234
|
+
static normalizeZ(d) {
|
|
2235
|
+
return wn(m, "pz", d);
|
|
2236
|
+
}
|
|
2237
|
+
static fromBytes(d) {
|
|
2238
|
+
return et(d), m.fromHex(d);
|
|
2239
|
+
}
|
|
2240
|
+
/** Converts hash string or Uint8Array to Point. */
|
|
2241
|
+
static fromHex(d) {
|
|
2242
|
+
const p = m.fromAffine(u(V("pointHex", d)));
|
|
2243
|
+
return p.assertValidity(), p;
|
|
2244
|
+
}
|
|
2245
|
+
/** Multiplies generator point by privateKey. */
|
|
2246
|
+
static fromPrivateKey(d) {
|
|
2247
|
+
const p = vn(r, e.allowedPrivateKeyLengths, e.wrapPrivateKey);
|
|
2248
|
+
return m.BASE.multiply(p(d));
|
|
2249
|
+
}
|
|
2250
|
+
/** Multiscalar Multiplication */
|
|
2251
|
+
static msm(d, p) {
|
|
2252
|
+
return ve(m, r, d, p);
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
*
|
|
2256
|
+
* @param windowSize
|
|
2257
|
+
* @param isLazy true will defer table computation until the first multiplication
|
|
2258
|
+
* @returns
|
|
2259
|
+
*/
|
|
2260
|
+
precompute(d = 8, p = !0) {
|
|
2261
|
+
return U.setWindowSize(this, d), p || this.multiply(Pt), this;
|
|
2262
|
+
}
|
|
2263
|
+
/** "Private method", don't use it directly */
|
|
2264
|
+
_setWindowSize(d) {
|
|
2265
|
+
this.precompute(d);
|
|
2266
|
+
}
|
|
2267
|
+
// TODO: return `this`
|
|
2268
|
+
/** A point on curve is valid if it conforms to equation. */
|
|
2269
|
+
assertValidity() {
|
|
2270
|
+
L(this);
|
|
2271
|
+
}
|
|
2272
|
+
hasEvenY() {
|
|
2273
|
+
const { y: d } = this.toAffine();
|
|
2274
|
+
if (!n.isOdd)
|
|
2275
|
+
throw new Error("Field doesn't support isOdd");
|
|
2276
|
+
return !n.isOdd(d);
|
|
2277
|
+
}
|
|
2278
|
+
/** Compare one point to another. */
|
|
2279
|
+
equals(d) {
|
|
2280
|
+
_(d);
|
|
2281
|
+
const { px: p, py: y, pz: g } = this, { px: B, py: v, pz: A } = d, I = n.eql(n.mul(p, A), n.mul(B, g)), q = n.eql(n.mul(y, A), n.mul(v, g));
|
|
2282
|
+
return I && q;
|
|
2283
|
+
}
|
|
2284
|
+
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
2285
|
+
negate() {
|
|
2286
|
+
return new m(this.px, n.neg(this.py), this.pz);
|
|
2287
|
+
}
|
|
2288
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
2289
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2290
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2291
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2292
|
+
double() {
|
|
2293
|
+
const { a: d, b: p } = t, y = n.mul(p, Pt), { px: g, py: B, pz: v } = this;
|
|
2294
|
+
let A = n.ZERO, I = n.ZERO, q = n.ZERO, k = n.mul(g, g), Z = n.mul(B, B), D = n.mul(v, v), N = n.mul(g, B);
|
|
2295
|
+
return N = n.add(N, N), q = n.mul(g, v), q = n.add(q, q), A = n.mul(d, q), I = n.mul(y, D), I = n.add(A, I), A = n.sub(Z, I), I = n.add(Z, I), I = n.mul(A, I), A = n.mul(N, A), q = n.mul(y, q), D = n.mul(d, D), N = n.sub(k, D), N = n.mul(d, N), N = n.add(N, q), q = n.add(k, k), k = n.add(q, k), k = n.add(k, D), k = n.mul(k, N), I = n.add(I, k), D = n.mul(B, v), D = n.add(D, D), k = n.mul(D, N), A = n.sub(A, k), q = n.mul(D, Z), q = n.add(q, q), q = n.add(q, q), new m(A, I, q);
|
|
2296
|
+
}
|
|
2297
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
2298
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2299
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2300
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2301
|
+
add(d) {
|
|
2302
|
+
_(d);
|
|
2303
|
+
const { px: p, py: y, pz: g } = this, { px: B, py: v, pz: A } = d;
|
|
2304
|
+
let I = n.ZERO, q = n.ZERO, k = n.ZERO;
|
|
2305
|
+
const Z = t.a, D = n.mul(t.b, Pt);
|
|
2306
|
+
let N = n.mul(p, B), z = n.mul(y, v), X = n.mul(g, A), P = n.add(p, y), M = n.add(B, v);
|
|
2307
|
+
P = n.mul(P, M), M = n.add(N, z), P = n.sub(P, M), M = n.add(p, g);
|
|
2308
|
+
let Q = n.add(B, A);
|
|
2309
|
+
return M = n.mul(M, Q), Q = n.add(N, X), M = n.sub(M, Q), Q = n.add(y, g), I = n.add(v, A), Q = n.mul(Q, I), I = n.add(z, X), Q = n.sub(Q, I), k = n.mul(Z, M), I = n.mul(D, X), k = n.add(I, k), I = n.sub(z, k), k = n.add(z, k), q = n.mul(I, k), z = n.add(N, N), z = n.add(z, N), X = n.mul(Z, X), M = n.mul(D, M), z = n.add(z, X), X = n.sub(N, X), X = n.mul(Z, X), M = n.add(M, X), N = n.mul(z, M), q = n.add(q, N), N = n.mul(Q, M), I = n.mul(P, I), I = n.sub(I, N), N = n.mul(P, z), k = n.mul(Q, k), k = n.add(k, N), new m(I, q, k);
|
|
2310
|
+
}
|
|
2311
|
+
subtract(d) {
|
|
2312
|
+
return this.add(d.negate());
|
|
2313
|
+
}
|
|
2314
|
+
is0() {
|
|
2315
|
+
return this.equals(m.ZERO);
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Constant time multiplication.
|
|
2319
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
2320
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
2321
|
+
* Uses precomputes when available.
|
|
2322
|
+
* Uses endomorphism for Koblitz curves.
|
|
2323
|
+
* @param scalar by which the point would be multiplied
|
|
2324
|
+
* @returns New point
|
|
2325
|
+
*/
|
|
2326
|
+
multiply(d) {
|
|
2327
|
+
const { endo: p } = e;
|
|
2328
|
+
if (!r.isValidNot0(d))
|
|
2329
|
+
throw new Error("invalid scalar: out of range");
|
|
2330
|
+
let y, g;
|
|
2331
|
+
const B = (v) => U.wNAFCached(this, v, m.normalizeZ);
|
|
2332
|
+
if (p) {
|
|
2333
|
+
const { k1neg: v, k1: A, k2neg: I, k2: q } = p.splitScalar(d), { p: k, f: Z } = B(A), { p: D, f: N } = B(q);
|
|
2334
|
+
g = Z.add(N), y = T(p.beta, k, D, v, I);
|
|
2335
|
+
} else {
|
|
2336
|
+
const { p: v, f: A } = B(d);
|
|
2337
|
+
y = v, g = A;
|
|
2338
|
+
}
|
|
2339
|
+
return m.normalizeZ([y, g])[0];
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
2343
|
+
* It's faster, but should only be used when you don't care about
|
|
2344
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
2345
|
+
*/
|
|
2346
|
+
multiplyUnsafe(d) {
|
|
2347
|
+
const { endo: p } = e, y = this;
|
|
2348
|
+
if (!r.isValid(d))
|
|
2349
|
+
throw new Error("invalid scalar: out of range");
|
|
2350
|
+
if (d === jt || y.is0())
|
|
2351
|
+
return m.ZERO;
|
|
2352
|
+
if (d === $t)
|
|
2353
|
+
return y;
|
|
2354
|
+
if (U.hasPrecomputes(this))
|
|
2355
|
+
return this.multiply(d);
|
|
2356
|
+
if (p) {
|
|
2357
|
+
const { k1neg: g, k1: B, k2neg: v, k2: A } = p.splitScalar(d), { p1: I, p2: q } = gr(m, y, B, A);
|
|
2358
|
+
return T(p.beta, I, q, g, v);
|
|
2359
|
+
} else
|
|
2360
|
+
return U.wNAFCachedUnsafe(y, d);
|
|
2361
|
+
}
|
|
2362
|
+
multiplyAndAddUnsafe(d, p, y) {
|
|
2363
|
+
const g = this.multiplyUnsafe(p).add(d.multiplyUnsafe(y));
|
|
2364
|
+
return g.is0() ? void 0 : g;
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* Converts Projective point to affine (x, y) coordinates.
|
|
2368
|
+
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
2369
|
+
*/
|
|
2370
|
+
toAffine(d) {
|
|
2371
|
+
return R(this, d);
|
|
2372
|
+
}
|
|
2373
|
+
/**
|
|
2374
|
+
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
2375
|
+
* Always torsion-free for cofactor=1 curves.
|
|
2376
|
+
*/
|
|
2377
|
+
isTorsionFree() {
|
|
2378
|
+
const { isTorsionFree: d } = e;
|
|
2379
|
+
return i === $t ? !0 : d ? d(m, this) : U.wNAFCachedUnsafe(this, s).is0();
|
|
2380
|
+
}
|
|
2381
|
+
clearCofactor() {
|
|
2382
|
+
const { clearCofactor: d } = e;
|
|
2383
|
+
return i === $t ? this : d ? d(m, this) : this.multiplyUnsafe(i);
|
|
2384
|
+
}
|
|
2385
|
+
toBytes(d = !0) {
|
|
2386
|
+
return Lt("isCompressed", d), this.assertValidity(), f(m, this, d);
|
|
2387
|
+
}
|
|
2388
|
+
/** @deprecated use `toBytes` */
|
|
2389
|
+
toRawBytes(d = !0) {
|
|
2390
|
+
return this.toBytes(d);
|
|
2391
|
+
}
|
|
2392
|
+
toHex(d = !0) {
|
|
2393
|
+
return It(this.toBytes(d));
|
|
2394
|
+
}
|
|
2395
|
+
toString() {
|
|
2396
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
m.BASE = new m(t.Gx, t.Gy, n.ONE), m.ZERO = new m(n.ZERO, n.ONE, n.ZERO), m.Fp = n, m.Fn = r;
|
|
2400
|
+
const H = r.BITS, U = mn(m, e.endo ? Math.ceil(H / 2) : H);
|
|
2401
|
+
return m;
|
|
2402
|
+
}
|
|
2403
|
+
function Sn(t) {
|
|
2404
|
+
return Uint8Array.of(t ? 2 : 3);
|
|
2405
|
+
}
|
|
2406
|
+
function Wr(t, e, n = {}) {
|
|
2407
|
+
Yt(e, { hash: "function" }, {
|
|
2408
|
+
hmac: "function",
|
|
2409
|
+
lowS: "boolean",
|
|
2410
|
+
randomBytes: "function",
|
|
2411
|
+
bits2int: "function",
|
|
2412
|
+
bits2int_modN: "function"
|
|
2413
|
+
});
|
|
2414
|
+
const r = e.randomBytes || Fe, i = e.hmac || ((y, ...g) => Be(e.hash, y, lt(...g))), { Fp: s, Fn: o } = t, { ORDER: c, BITS: a } = o;
|
|
2415
|
+
function l(y) {
|
|
2416
|
+
const g = c >> $t;
|
|
2417
|
+
return y > g;
|
|
2418
|
+
}
|
|
2419
|
+
function f(y) {
|
|
2420
|
+
return l(y) ? o.neg(y) : y;
|
|
2421
|
+
}
|
|
2422
|
+
function u(y, g) {
|
|
2423
|
+
if (!o.isValidNot0(g))
|
|
2424
|
+
throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`);
|
|
2425
|
+
}
|
|
2426
|
+
class b {
|
|
2427
|
+
constructor(g, B, v) {
|
|
2428
|
+
u("r", g), u("s", B), this.r = g, this.s = B, v != null && (this.recovery = v), Object.freeze(this);
|
|
2429
|
+
}
|
|
2430
|
+
// pair (bytes of r, bytes of s)
|
|
2431
|
+
static fromCompact(g) {
|
|
2432
|
+
const B = o.BYTES, v = V("compactSignature", g, B * 2);
|
|
2433
|
+
return new b(o.fromBytes(v.subarray(0, B)), o.fromBytes(v.subarray(B, B * 2)));
|
|
2434
|
+
}
|
|
2435
|
+
// DER encoded ECDSA signature
|
|
2436
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
2437
|
+
static fromDER(g) {
|
|
2438
|
+
const { r: B, s: v } = at.toSig(V("DER", g));
|
|
2439
|
+
return new b(B, v);
|
|
2440
|
+
}
|
|
2441
|
+
/**
|
|
2442
|
+
* @todo remove
|
|
2443
|
+
* @deprecated
|
|
2444
|
+
*/
|
|
2445
|
+
assertValidity() {
|
|
2446
|
+
}
|
|
2447
|
+
addRecoveryBit(g) {
|
|
2448
|
+
return new b(this.r, this.s, g);
|
|
2449
|
+
}
|
|
2450
|
+
// ProjPointType<bigint>
|
|
2451
|
+
recoverPublicKey(g) {
|
|
2452
|
+
const B = s.ORDER, { r: v, s: A, recovery: I } = this;
|
|
2453
|
+
if (I == null || ![0, 1, 2, 3].includes(I))
|
|
2454
|
+
throw new Error("recovery id invalid");
|
|
2455
|
+
if (c * Yr < B && I > 1)
|
|
2456
|
+
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
2457
|
+
const k = I === 2 || I === 3 ? v + c : v;
|
|
2458
|
+
if (!s.isValid(k))
|
|
2459
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
2460
|
+
const Z = s.toBytes(k), D = t.fromHex(lt(Sn((I & 1) === 0), Z)), N = o.inv(k), z = L(V("msgHash", g)), X = o.create(-z * N), P = o.create(A * N), M = t.BASE.multiplyUnsafe(X).add(D.multiplyUnsafe(P));
|
|
2461
|
+
if (M.is0())
|
|
2462
|
+
throw new Error("point at infinify");
|
|
2463
|
+
return M.assertValidity(), M;
|
|
2464
|
+
}
|
|
2465
|
+
// Signatures should be low-s, to prevent malleability.
|
|
2466
|
+
hasHighS() {
|
|
2467
|
+
return l(this.s);
|
|
2468
|
+
}
|
|
2469
|
+
normalizeS() {
|
|
2470
|
+
return this.hasHighS() ? new b(this.r, o.neg(this.s), this.recovery) : this;
|
|
2471
|
+
}
|
|
2472
|
+
toBytes(g) {
|
|
2473
|
+
if (g === "compact")
|
|
2474
|
+
return lt(o.toBytes(this.r), o.toBytes(this.s));
|
|
2475
|
+
if (g === "der")
|
|
2476
|
+
return ge(at.hexFromSig(this));
|
|
2477
|
+
throw new Error("invalid format");
|
|
2478
|
+
}
|
|
2479
|
+
// DER-encoded
|
|
2480
|
+
toDERRawBytes() {
|
|
2481
|
+
return this.toBytes("der");
|
|
2482
|
+
}
|
|
2483
|
+
toDERHex() {
|
|
2484
|
+
return It(this.toBytes("der"));
|
|
2485
|
+
}
|
|
2486
|
+
// padded bytes of r, then padded bytes of s
|
|
2487
|
+
toCompactRawBytes() {
|
|
2488
|
+
return this.toBytes("compact");
|
|
2489
|
+
}
|
|
2490
|
+
toCompactHex() {
|
|
2491
|
+
return It(this.toBytes("compact"));
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
const h = vn(o, n.allowedPrivateKeyLengths, n.wrapPrivateKey), E = {
|
|
2495
|
+
isValidPrivateKey(y) {
|
|
2496
|
+
try {
|
|
2497
|
+
return h(y), !0;
|
|
2498
|
+
} catch {
|
|
2499
|
+
return !1;
|
|
2500
|
+
}
|
|
2501
|
+
},
|
|
2502
|
+
normPrivateKeyToScalar: h,
|
|
2503
|
+
/**
|
|
2504
|
+
* Produces cryptographically secure private key from random of size
|
|
2505
|
+
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
2506
|
+
*/
|
|
2507
|
+
randomPrivateKey: () => {
|
|
2508
|
+
const y = c;
|
|
2509
|
+
return xr(r(xn(y)), y);
|
|
2510
|
+
},
|
|
2511
|
+
precompute(y = 8, g = t.BASE) {
|
|
2512
|
+
return g.precompute(y, !1);
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2515
|
+
function w(y, g = !0) {
|
|
2516
|
+
return t.fromPrivateKey(y).toBytes(g);
|
|
2517
|
+
}
|
|
2518
|
+
function x(y) {
|
|
2519
|
+
if (typeof y == "bigint")
|
|
2520
|
+
return !1;
|
|
2521
|
+
if (y instanceof t)
|
|
2522
|
+
return !0;
|
|
2523
|
+
const B = V("key", y).length, v = s.BYTES, A = v + 1, I = 2 * v + 1;
|
|
2524
|
+
if (!(n.allowedPrivateKeyLengths || o.BYTES === A))
|
|
2525
|
+
return B === A || B === I;
|
|
2526
|
+
}
|
|
2527
|
+
function _(y, g, B = !0) {
|
|
2528
|
+
if (x(y) === !0)
|
|
2529
|
+
throw new Error("first arg must be private key");
|
|
2530
|
+
if (x(g) === !1)
|
|
2531
|
+
throw new Error("second arg must be public key");
|
|
2532
|
+
return t.fromHex(g).multiply(h(y)).toBytes(B);
|
|
2533
|
+
}
|
|
2534
|
+
const R = e.bits2int || function(y) {
|
|
2535
|
+
if (y.length > 8192)
|
|
2536
|
+
throw new Error("input is too large");
|
|
2537
|
+
const g = te(y), B = y.length * 8 - a;
|
|
2538
|
+
return B > 0 ? g >> BigInt(B) : g;
|
|
2539
|
+
}, L = e.bits2int_modN || function(y) {
|
|
2540
|
+
return o.create(R(y));
|
|
2541
|
+
}, T = ee(a);
|
|
2542
|
+
function m(y) {
|
|
2543
|
+
return qt("num < 2^" + a, y, jt, T), o.toBytes(y);
|
|
2544
|
+
}
|
|
2545
|
+
function H(y, g, B = U) {
|
|
2546
|
+
if (["recovered", "canonical"].some((P) => P in B))
|
|
2547
|
+
throw new Error("sign() legacy options not supported");
|
|
2548
|
+
const { hash: v } = e;
|
|
2549
|
+
let { lowS: A, prehash: I, extraEntropy: q } = B;
|
|
2550
|
+
A == null && (A = !0), y = V("msgHash", y), Ge(B), I && (y = V("prehashed msgHash", v(y)));
|
|
2551
|
+
const k = L(y), Z = h(g), D = [m(Z), m(k)];
|
|
2552
|
+
if (q != null && q !== !1) {
|
|
2553
|
+
const P = q === !0 ? r(s.BYTES) : q;
|
|
2554
|
+
D.push(V("extraEntropy", P));
|
|
2555
|
+
}
|
|
2556
|
+
const N = lt(...D), z = k;
|
|
2557
|
+
function X(P) {
|
|
2558
|
+
const M = R(P);
|
|
2559
|
+
if (!o.isValidNot0(M))
|
|
2560
|
+
return;
|
|
2561
|
+
const Q = o.inv(M), Zt = t.BASE.multiply(M).toAffine(), Ht = o.create(Zt.x);
|
|
2562
|
+
if (Ht === jt)
|
|
2563
|
+
return;
|
|
2564
|
+
const _t = o.create(Q * o.create(z + Ht * Z));
|
|
2565
|
+
if (_t === jt)
|
|
2566
|
+
return;
|
|
2567
|
+
let re = (Zt.x === Ht ? 0 : 2) | Number(Zt.y & $t), Rt = _t;
|
|
2568
|
+
return A && l(_t) && (Rt = f(_t), re ^= 1), new b(Ht, Rt, re);
|
|
2569
|
+
}
|
|
2570
|
+
return { seed: N, k2sig: X };
|
|
2571
|
+
}
|
|
2572
|
+
const U = { lowS: e.lowS, prehash: !1 }, O = { lowS: e.lowS, prehash: !1 };
|
|
2573
|
+
function d(y, g, B = U) {
|
|
2574
|
+
const { seed: v, k2sig: A } = H(y, g, B);
|
|
2575
|
+
return ir(e.hash.outputLen, o.BYTES, i)(v, A);
|
|
2576
|
+
}
|
|
2577
|
+
t.BASE.precompute(8);
|
|
2578
|
+
function p(y, g, B, v = O) {
|
|
2579
|
+
const A = y;
|
|
2580
|
+
g = V("msgHash", g), B = V("publicKey", B), Ge(v);
|
|
2581
|
+
const { lowS: I, prehash: q, format: k } = v;
|
|
2582
|
+
if ("strict" in v)
|
|
2583
|
+
throw new Error("options.strict was renamed to lowS");
|
|
2584
|
+
if (k !== void 0 && !["compact", "der", "js"].includes(k))
|
|
2585
|
+
throw new Error('format must be "compact", "der" or "js"');
|
|
2586
|
+
const Z = typeof A == "string" || ye(A), D = !Z && !k && typeof A == "object" && A !== null && typeof A.r == "bigint" && typeof A.s == "bigint";
|
|
2587
|
+
if (!Z && !D)
|
|
2588
|
+
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
2589
|
+
let N, z;
|
|
2590
|
+
try {
|
|
2591
|
+
if (D)
|
|
2592
|
+
if (k === void 0 || k === "js")
|
|
2593
|
+
N = new b(A.r, A.s);
|
|
2594
|
+
else
|
|
2595
|
+
throw new Error("invalid format");
|
|
2596
|
+
if (Z) {
|
|
2597
|
+
try {
|
|
2598
|
+
k !== "compact" && (N = b.fromDER(A));
|
|
2599
|
+
} catch (Rt) {
|
|
2600
|
+
if (!(Rt instanceof at.Err))
|
|
2601
|
+
throw Rt;
|
|
2602
|
+
}
|
|
2603
|
+
!N && k !== "der" && (N = b.fromCompact(A));
|
|
2604
|
+
}
|
|
2605
|
+
z = t.fromHex(B);
|
|
2606
|
+
} catch {
|
|
2607
|
+
return !1;
|
|
2608
|
+
}
|
|
2609
|
+
if (!N || I && N.hasHighS())
|
|
2610
|
+
return !1;
|
|
2611
|
+
q && (g = e.hash(g));
|
|
2612
|
+
const { r: X, s: P } = N, M = L(g), Q = o.inv(P), Zt = o.create(M * Q), Ht = o.create(X * Q), _t = t.BASE.multiplyUnsafe(Zt).add(z.multiplyUnsafe(Ht));
|
|
2613
|
+
return _t.is0() ? !1 : o.create(_t.x) === X;
|
|
2614
|
+
}
|
|
2615
|
+
return Object.freeze({
|
|
2616
|
+
getPublicKey: w,
|
|
2617
|
+
getSharedSecret: _,
|
|
2618
|
+
sign: d,
|
|
2619
|
+
verify: p,
|
|
2620
|
+
utils: E,
|
|
2621
|
+
Point: t,
|
|
2622
|
+
Signature: b
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
function Qr(t) {
|
|
2626
|
+
const e = {
|
|
2627
|
+
a: t.a,
|
|
2628
|
+
b: t.b,
|
|
2629
|
+
p: t.Fp.ORDER,
|
|
2630
|
+
n: t.n,
|
|
2631
|
+
h: t.h,
|
|
2632
|
+
Gx: t.Gx,
|
|
2633
|
+
Gy: t.Gy
|
|
2634
|
+
}, n = t.Fp, r = Ot(e.n, t.nBitLength), i = {
|
|
2635
|
+
Fp: n,
|
|
2636
|
+
Fn: r,
|
|
2637
|
+
allowedPrivateKeyLengths: t.allowedPrivateKeyLengths,
|
|
2638
|
+
allowInfinityPoint: t.allowInfinityPoint,
|
|
2639
|
+
endo: t.endo,
|
|
2640
|
+
wrapPrivateKey: t.wrapPrivateKey,
|
|
2641
|
+
isTorsionFree: t.isTorsionFree,
|
|
2642
|
+
clearCofactor: t.clearCofactor,
|
|
2643
|
+
fromBytes: t.fromBytes,
|
|
2644
|
+
toBytes: t.toBytes
|
|
2645
|
+
};
|
|
2646
|
+
return { CURVE: e, curveOpts: i };
|
|
2647
|
+
}
|
|
2648
|
+
function Jr(t) {
|
|
2649
|
+
const { CURVE: e, curveOpts: n } = Qr(t), r = {
|
|
2650
|
+
hash: t.hash,
|
|
2651
|
+
hmac: t.hmac,
|
|
2652
|
+
randomBytes: t.randomBytes,
|
|
2653
|
+
lowS: t.lowS,
|
|
2654
|
+
bits2int: t.bits2int,
|
|
2655
|
+
bits2int_modN: t.bits2int_modN
|
|
2656
|
+
};
|
|
2657
|
+
return { CURVE: e, curveOpts: n, ecdsaOpts: r };
|
|
2658
|
+
}
|
|
2659
|
+
function Fr(t, e) {
|
|
2660
|
+
return Object.assign({}, e, {
|
|
2661
|
+
ProjectivePoint: e.Point,
|
|
2662
|
+
CURVE: t
|
|
2663
|
+
});
|
|
2664
|
+
}
|
|
2665
|
+
function ts(t) {
|
|
2666
|
+
const { CURVE: e, curveOpts: n, ecdsaOpts: r } = Jr(t), i = Pr(e, n), s = Wr(i, r, n);
|
|
2667
|
+
return Fr(t, s);
|
|
2668
|
+
}
|
|
2669
|
+
function es(t, e) {
|
|
2670
|
+
const n = (r) => ts({ ...t, hash: r });
|
|
2671
|
+
return { ...n(e), create: n };
|
|
2672
|
+
}
|
|
2673
|
+
const Jt = {
|
|
2674
|
+
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
2675
|
+
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
2676
|
+
h: BigInt(1),
|
|
2677
|
+
a: BigInt(0),
|
|
2678
|
+
b: BigInt(7),
|
|
2679
|
+
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
2680
|
+
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
2681
|
+
};
|
|
2682
|
+
BigInt(0);
|
|
2683
|
+
const ns = BigInt(1), xe = BigInt(2), je = (t, e) => (t + e / xe) / e;
|
|
2684
|
+
function rs(t) {
|
|
2685
|
+
const e = Jt.p, n = BigInt(3), r = BigInt(6), i = BigInt(11), s = BigInt(22), o = BigInt(23), c = BigInt(44), a = BigInt(88), l = t * t * t % e, f = l * l * t % e, u = G(f, n, e) * f % e, b = G(u, n, e) * f % e, h = G(b, xe, e) * l % e, E = G(h, i, e) * h % e, w = G(E, s, e) * E % e, x = G(w, c, e) * w % e, _ = G(x, a, e) * x % e, R = G(_, c, e) * w % e, L = G(R, n, e) * f % e, T = G(L, o, e) * E % e, m = G(T, r, e) * l % e, H = G(m, xe, e);
|
|
2686
|
+
if (!we.eql(we.sqr(H), t))
|
|
2687
|
+
throw new Error("Cannot find square root");
|
|
2688
|
+
return H;
|
|
2689
|
+
}
|
|
2690
|
+
const we = Ot(Jt.p, void 0, void 0, { sqrt: rs }), bs = es({
|
|
2691
|
+
...Jt,
|
|
2692
|
+
Fp: we,
|
|
2693
|
+
lowS: !0,
|
|
2694
|
+
// Allow only low-S signatures by default in sign() and verify()
|
|
2695
|
+
endo: {
|
|
2696
|
+
// Endomorphism, see above
|
|
2697
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
2698
|
+
splitScalar: (t) => {
|
|
2699
|
+
const e = Jt.n, n = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -ns * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), i = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), s = n, o = BigInt("0x100000000000000000000000000000000"), c = je(s * t, e), a = je(-r * t, e);
|
|
2700
|
+
let l = j(t - c * n - a * i, e), f = j(-c * r - a * s, e);
|
|
2701
|
+
const u = l > o, b = f > o;
|
|
2702
|
+
if (u && (l = e - l), b && (f = e - f), l > o || f > o)
|
|
2703
|
+
throw new Error("splitScalar: Endomorphism failed, k=" + t);
|
|
2704
|
+
return { k1neg: u, k1: l, k2neg: b, k2: f };
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
}, Ft);
|
|
2708
|
+
export {
|
|
2709
|
+
us as R,
|
|
2710
|
+
ds as a,
|
|
2711
|
+
os as b,
|
|
2712
|
+
lt as c,
|
|
2713
|
+
Tt as d,
|
|
2714
|
+
qt as e,
|
|
2715
|
+
nt as f,
|
|
2716
|
+
St as g,
|
|
2717
|
+
ee as h,
|
|
2718
|
+
ye as i,
|
|
2719
|
+
ss as j,
|
|
2720
|
+
hs as k,
|
|
2721
|
+
bs as l,
|
|
2722
|
+
j as m,
|
|
2723
|
+
Dt as n,
|
|
2724
|
+
cn as p,
|
|
2725
|
+
Fe as r,
|
|
2726
|
+
is as s,
|
|
2727
|
+
We as u
|
|
2728
|
+
};
|