@avalabs/avacloud-waas-react 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -1
- package/dist/index.mjs +18 -1
- package/package.json +1 -1
- package/dist/_esm-QWLX263D.mjs +0 -3919
- package/dist/ccip-ZGPV4OUI.mjs +0 -14
- package/dist/chunk-CASSC3OP.mjs +0 -67
- package/dist/chunk-G3BBITEG.mjs +0 -367
- package/dist/chunk-H4SP2TEB.mjs +0 -2343
- package/dist/chunk-TMRHATUE.mjs +0 -5868
- package/dist/dejavu-mono-latin-400-normal-IE7EMRRJ.woff2 +0 -0
- package/dist/dejavu-mono-latin-400-normal-MXASKUMG.woff +0 -0
- package/dist/dejavu-mono-latin-700-normal-4E6K55SY.woff +0 -0
- package/dist/dejavu-mono-latin-700-normal-4R4GZIXF.woff2 +0 -0
- package/dist/index.css +0 -473
- package/dist/inter-cyrillic-400-normal-KFLOZ6L3.woff2 +0 -0
- package/dist/inter-cyrillic-400-normal-UGV3X2ZX.woff +0 -0
- package/dist/inter-cyrillic-500-normal-5QURBI26.woff +0 -0
- package/dist/inter-cyrillic-500-normal-MRQZIV3H.woff2 +0 -0
- package/dist/inter-cyrillic-600-normal-EDUIRGIU.woff +0 -0
- package/dist/inter-cyrillic-600-normal-VQSXM56D.woff2 +0 -0
- package/dist/inter-cyrillic-700-normal-6AC775OW.woff2 +0 -0
- package/dist/inter-cyrillic-700-normal-D4IEZ3GW.woff +0 -0
- package/dist/inter-cyrillic-ext-400-normal-JB453SGZ.woff2 +0 -0
- package/dist/inter-cyrillic-ext-400-normal-UT7C7CGZ.woff +0 -0
- package/dist/inter-cyrillic-ext-500-normal-JTQKN4HY.woff2 +0 -0
- package/dist/inter-cyrillic-ext-500-normal-WLOKRQXN.woff +0 -0
- package/dist/inter-cyrillic-ext-600-normal-EFECVKGZ.woff2 +0 -0
- package/dist/inter-cyrillic-ext-600-normal-NBG3W4IU.woff +0 -0
- package/dist/inter-cyrillic-ext-700-normal-4PBXEWDR.woff +0 -0
- package/dist/inter-cyrillic-ext-700-normal-SJP7DRTO.woff2 +0 -0
- package/dist/inter-greek-400-normal-7Y67TOYM.woff +0 -0
- package/dist/inter-greek-400-normal-BRMJUT6T.woff2 +0 -0
- package/dist/inter-greek-500-normal-LCPH243Y.woff +0 -0
- package/dist/inter-greek-500-normal-PQX5SJVP.woff2 +0 -0
- package/dist/inter-greek-600-normal-PKJBTQPQ.woff2 +0 -0
- package/dist/inter-greek-600-normal-UPKYUUFH.woff +0 -0
- package/dist/inter-greek-700-normal-5N2Y4K7P.woff2 +0 -0
- package/dist/inter-greek-700-normal-OE26ANW4.woff +0 -0
- package/dist/inter-greek-ext-400-normal-4HYCVGMS.woff +0 -0
- package/dist/inter-greek-ext-400-normal-QIS4ONLW.woff2 +0 -0
- package/dist/inter-greek-ext-500-normal-AOIZUIP4.woff +0 -0
- package/dist/inter-greek-ext-500-normal-Z2CEJP2K.woff2 +0 -0
- package/dist/inter-greek-ext-600-normal-FQPCNDF3.woff +0 -0
- package/dist/inter-greek-ext-600-normal-KM6XRHAQ.woff2 +0 -0
- package/dist/inter-greek-ext-700-normal-FDEUQJ34.woff +0 -0
- package/dist/inter-greek-ext-700-normal-LWL55ZDD.woff2 +0 -0
- package/dist/inter-latin-400-normal-O6KIPRV2.woff +0 -0
- package/dist/inter-latin-400-normal-VQ3UBCDI.woff2 +0 -0
- package/dist/inter-latin-500-normal-OD7WVACW.woff +0 -0
- package/dist/inter-latin-500-normal-PUEXTTCT.woff2 +0 -0
- package/dist/inter-latin-600-normal-5WVF6G4B.woff +0 -0
- package/dist/inter-latin-600-normal-GQRH5MIF.woff2 +0 -0
- package/dist/inter-latin-700-normal-5OESYTDS.woff2 +0 -0
- package/dist/inter-latin-700-normal-ZQVBARDV.woff +0 -0
- package/dist/inter-latin-ext-400-normal-BTAMM2KL.woff2 +0 -0
- package/dist/inter-latin-ext-400-normal-YUALTDTA.woff +0 -0
- package/dist/inter-latin-ext-500-normal-DV5RJSXI.woff2 +0 -0
- package/dist/inter-latin-ext-500-normal-KJKTVLML.woff +0 -0
- package/dist/inter-latin-ext-600-normal-AOYWYIP3.woff2 +0 -0
- package/dist/inter-latin-ext-600-normal-L5SWE5DY.woff +0 -0
- package/dist/inter-latin-ext-700-normal-2RDPBVFQ.woff2 +0 -0
- package/dist/inter-latin-ext-700-normal-XQIRBHUR.woff +0 -0
- package/dist/inter-vietnamese-400-normal-724F3VTF.woff +0 -0
- package/dist/inter-vietnamese-400-normal-KH5NGGJJ.woff2 +0 -0
- package/dist/inter-vietnamese-500-normal-F77QXW2X.woff2 +0 -0
- package/dist/inter-vietnamese-500-normal-ZTDWBSHR.woff +0 -0
- package/dist/inter-vietnamese-600-normal-47DK6MCQ.woff2 +0 -0
- package/dist/inter-vietnamese-600-normal-M4XR4C4S.woff +0 -0
- package/dist/inter-vietnamese-700-normal-ONTG3SOY.woff +0 -0
- package/dist/inter-vietnamese-700-normal-T2WXKRNY.woff2 +0 -0
- package/dist/mod-LKCIPMBZ.mjs +0 -2628
- package/dist/secp256k1-AYCAE7S6.mjs +0 -16
package/dist/chunk-H4SP2TEB.mjs
DELETED
|
@@ -1,2343 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Hash,
|
|
3
|
-
_validateObject,
|
|
4
|
-
aInRange,
|
|
5
|
-
abool,
|
|
6
|
-
abytes,
|
|
7
|
-
aexists,
|
|
8
|
-
ahash,
|
|
9
|
-
anumber,
|
|
10
|
-
aoutput,
|
|
11
|
-
bitLen,
|
|
12
|
-
bitMask,
|
|
13
|
-
bytesToHex,
|
|
14
|
-
bytesToNumberBE,
|
|
15
|
-
bytesToNumberLE,
|
|
16
|
-
clean,
|
|
17
|
-
concatBytes,
|
|
18
|
-
createHasher,
|
|
19
|
-
createHmacDrbg,
|
|
20
|
-
createView,
|
|
21
|
-
ensureBytes,
|
|
22
|
-
hexToBytes,
|
|
23
|
-
inRange,
|
|
24
|
-
isBytes,
|
|
25
|
-
isHash,
|
|
26
|
-
memoized,
|
|
27
|
-
numberToBytesBE,
|
|
28
|
-
numberToBytesLE,
|
|
29
|
-
numberToHexUnpadded,
|
|
30
|
-
randomBytes,
|
|
31
|
-
rotr,
|
|
32
|
-
toBytes,
|
|
33
|
-
utf8ToBytes
|
|
34
|
-
} from "./chunk-G3BBITEG.mjs";
|
|
35
|
-
|
|
36
|
-
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js
|
|
37
|
-
function setBigUint64(view, byteOffset, value, isLE) {
|
|
38
|
-
if (typeof view.setBigUint64 === "function")
|
|
39
|
-
return view.setBigUint64(byteOffset, value, isLE);
|
|
40
|
-
const _32n = BigInt(32);
|
|
41
|
-
const _u32_max = BigInt(4294967295);
|
|
42
|
-
const wh = Number(value >> _32n & _u32_max);
|
|
43
|
-
const wl = Number(value & _u32_max);
|
|
44
|
-
const h = isLE ? 4 : 0;
|
|
45
|
-
const l = isLE ? 0 : 4;
|
|
46
|
-
view.setUint32(byteOffset + h, wh, isLE);
|
|
47
|
-
view.setUint32(byteOffset + l, wl, isLE);
|
|
48
|
-
}
|
|
49
|
-
function Chi(a, b, c) {
|
|
50
|
-
return a & b ^ ~a & c;
|
|
51
|
-
}
|
|
52
|
-
function Maj(a, b, c) {
|
|
53
|
-
return a & b ^ a & c ^ b & c;
|
|
54
|
-
}
|
|
55
|
-
var HashMD = class extends Hash {
|
|
56
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
57
|
-
super();
|
|
58
|
-
this.finished = false;
|
|
59
|
-
this.length = 0;
|
|
60
|
-
this.pos = 0;
|
|
61
|
-
this.destroyed = false;
|
|
62
|
-
this.blockLen = blockLen;
|
|
63
|
-
this.outputLen = outputLen;
|
|
64
|
-
this.padOffset = padOffset;
|
|
65
|
-
this.isLE = isLE;
|
|
66
|
-
this.buffer = new Uint8Array(blockLen);
|
|
67
|
-
this.view = createView(this.buffer);
|
|
68
|
-
}
|
|
69
|
-
update(data) {
|
|
70
|
-
aexists(this);
|
|
71
|
-
data = toBytes(data);
|
|
72
|
-
abytes(data);
|
|
73
|
-
const { view, buffer, blockLen } = this;
|
|
74
|
-
const len = data.length;
|
|
75
|
-
for (let pos = 0; pos < len; ) {
|
|
76
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
77
|
-
if (take === blockLen) {
|
|
78
|
-
const dataView = createView(data);
|
|
79
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
80
|
-
this.process(dataView, pos);
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
84
|
-
this.pos += take;
|
|
85
|
-
pos += take;
|
|
86
|
-
if (this.pos === blockLen) {
|
|
87
|
-
this.process(view, 0);
|
|
88
|
-
this.pos = 0;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
this.length += data.length;
|
|
92
|
-
this.roundClean();
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
digestInto(out) {
|
|
96
|
-
aexists(this);
|
|
97
|
-
aoutput(out, this);
|
|
98
|
-
this.finished = true;
|
|
99
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
100
|
-
let { pos } = this;
|
|
101
|
-
buffer[pos++] = 128;
|
|
102
|
-
clean(this.buffer.subarray(pos));
|
|
103
|
-
if (this.padOffset > blockLen - pos) {
|
|
104
|
-
this.process(view, 0);
|
|
105
|
-
pos = 0;
|
|
106
|
-
}
|
|
107
|
-
for (let i = pos; i < blockLen; i++)
|
|
108
|
-
buffer[i] = 0;
|
|
109
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
110
|
-
this.process(view, 0);
|
|
111
|
-
const oview = createView(out);
|
|
112
|
-
const len = this.outputLen;
|
|
113
|
-
if (len % 4)
|
|
114
|
-
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
115
|
-
const outLen = len / 4;
|
|
116
|
-
const state = this.get();
|
|
117
|
-
if (outLen > state.length)
|
|
118
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
119
|
-
for (let i = 0; i < outLen; i++)
|
|
120
|
-
oview.setUint32(4 * i, state[i], isLE);
|
|
121
|
-
}
|
|
122
|
-
digest() {
|
|
123
|
-
const { buffer, outputLen } = this;
|
|
124
|
-
this.digestInto(buffer);
|
|
125
|
-
const res = buffer.slice(0, outputLen);
|
|
126
|
-
this.destroy();
|
|
127
|
-
return res;
|
|
128
|
-
}
|
|
129
|
-
_cloneInto(to) {
|
|
130
|
-
to || (to = new this.constructor());
|
|
131
|
-
to.set(...this.get());
|
|
132
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
133
|
-
to.destroyed = destroyed;
|
|
134
|
-
to.finished = finished;
|
|
135
|
-
to.length = length;
|
|
136
|
-
to.pos = pos;
|
|
137
|
-
if (length % blockLen)
|
|
138
|
-
to.buffer.set(buffer);
|
|
139
|
-
return to;
|
|
140
|
-
}
|
|
141
|
-
clone() {
|
|
142
|
-
return this._cloneInto();
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
146
|
-
1779033703,
|
|
147
|
-
3144134277,
|
|
148
|
-
1013904242,
|
|
149
|
-
2773480762,
|
|
150
|
-
1359893119,
|
|
151
|
-
2600822924,
|
|
152
|
-
528734635,
|
|
153
|
-
1541459225
|
|
154
|
-
]);
|
|
155
|
-
|
|
156
|
-
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
|
|
157
|
-
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
158
|
-
1116352408,
|
|
159
|
-
1899447441,
|
|
160
|
-
3049323471,
|
|
161
|
-
3921009573,
|
|
162
|
-
961987163,
|
|
163
|
-
1508970993,
|
|
164
|
-
2453635748,
|
|
165
|
-
2870763221,
|
|
166
|
-
3624381080,
|
|
167
|
-
310598401,
|
|
168
|
-
607225278,
|
|
169
|
-
1426881987,
|
|
170
|
-
1925078388,
|
|
171
|
-
2162078206,
|
|
172
|
-
2614888103,
|
|
173
|
-
3248222580,
|
|
174
|
-
3835390401,
|
|
175
|
-
4022224774,
|
|
176
|
-
264347078,
|
|
177
|
-
604807628,
|
|
178
|
-
770255983,
|
|
179
|
-
1249150122,
|
|
180
|
-
1555081692,
|
|
181
|
-
1996064986,
|
|
182
|
-
2554220882,
|
|
183
|
-
2821834349,
|
|
184
|
-
2952996808,
|
|
185
|
-
3210313671,
|
|
186
|
-
3336571891,
|
|
187
|
-
3584528711,
|
|
188
|
-
113926993,
|
|
189
|
-
338241895,
|
|
190
|
-
666307205,
|
|
191
|
-
773529912,
|
|
192
|
-
1294757372,
|
|
193
|
-
1396182291,
|
|
194
|
-
1695183700,
|
|
195
|
-
1986661051,
|
|
196
|
-
2177026350,
|
|
197
|
-
2456956037,
|
|
198
|
-
2730485921,
|
|
199
|
-
2820302411,
|
|
200
|
-
3259730800,
|
|
201
|
-
3345764771,
|
|
202
|
-
3516065817,
|
|
203
|
-
3600352804,
|
|
204
|
-
4094571909,
|
|
205
|
-
275423344,
|
|
206
|
-
430227734,
|
|
207
|
-
506948616,
|
|
208
|
-
659060556,
|
|
209
|
-
883997877,
|
|
210
|
-
958139571,
|
|
211
|
-
1322822218,
|
|
212
|
-
1537002063,
|
|
213
|
-
1747873779,
|
|
214
|
-
1955562222,
|
|
215
|
-
2024104815,
|
|
216
|
-
2227730452,
|
|
217
|
-
2361852424,
|
|
218
|
-
2428436474,
|
|
219
|
-
2756734187,
|
|
220
|
-
3204031479,
|
|
221
|
-
3329325298
|
|
222
|
-
]);
|
|
223
|
-
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
224
|
-
var SHA256 = class extends HashMD {
|
|
225
|
-
constructor(outputLen = 32) {
|
|
226
|
-
super(64, outputLen, 8, false);
|
|
227
|
-
this.A = SHA256_IV[0] | 0;
|
|
228
|
-
this.B = SHA256_IV[1] | 0;
|
|
229
|
-
this.C = SHA256_IV[2] | 0;
|
|
230
|
-
this.D = SHA256_IV[3] | 0;
|
|
231
|
-
this.E = SHA256_IV[4] | 0;
|
|
232
|
-
this.F = SHA256_IV[5] | 0;
|
|
233
|
-
this.G = SHA256_IV[6] | 0;
|
|
234
|
-
this.H = SHA256_IV[7] | 0;
|
|
235
|
-
}
|
|
236
|
-
get() {
|
|
237
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
238
|
-
return [A, B, C, D, E, F, G, H];
|
|
239
|
-
}
|
|
240
|
-
// prettier-ignore
|
|
241
|
-
set(A, B, C, D, E, F, G, H) {
|
|
242
|
-
this.A = A | 0;
|
|
243
|
-
this.B = B | 0;
|
|
244
|
-
this.C = C | 0;
|
|
245
|
-
this.D = D | 0;
|
|
246
|
-
this.E = E | 0;
|
|
247
|
-
this.F = F | 0;
|
|
248
|
-
this.G = G | 0;
|
|
249
|
-
this.H = H | 0;
|
|
250
|
-
}
|
|
251
|
-
process(view, offset) {
|
|
252
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
253
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
254
|
-
for (let i = 16; i < 64; i++) {
|
|
255
|
-
const W15 = SHA256_W[i - 15];
|
|
256
|
-
const W2 = SHA256_W[i - 2];
|
|
257
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
258
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
259
|
-
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
260
|
-
}
|
|
261
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
262
|
-
for (let i = 0; i < 64; i++) {
|
|
263
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
264
|
-
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
265
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
266
|
-
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
267
|
-
H = G;
|
|
268
|
-
G = F;
|
|
269
|
-
F = E;
|
|
270
|
-
E = D + T1 | 0;
|
|
271
|
-
D = C;
|
|
272
|
-
C = B;
|
|
273
|
-
B = A;
|
|
274
|
-
A = T1 + T2 | 0;
|
|
275
|
-
}
|
|
276
|
-
A = A + this.A | 0;
|
|
277
|
-
B = B + this.B | 0;
|
|
278
|
-
C = C + this.C | 0;
|
|
279
|
-
D = D + this.D | 0;
|
|
280
|
-
E = E + this.E | 0;
|
|
281
|
-
F = F + this.F | 0;
|
|
282
|
-
G = G + this.G | 0;
|
|
283
|
-
H = H + this.H | 0;
|
|
284
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
285
|
-
}
|
|
286
|
-
roundClean() {
|
|
287
|
-
clean(SHA256_W);
|
|
288
|
-
}
|
|
289
|
-
destroy() {
|
|
290
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
291
|
-
clean(this.buffer);
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
295
|
-
|
|
296
|
-
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/hmac.js
|
|
297
|
-
var HMAC = class extends Hash {
|
|
298
|
-
constructor(hash, _key) {
|
|
299
|
-
super();
|
|
300
|
-
this.finished = false;
|
|
301
|
-
this.destroyed = false;
|
|
302
|
-
ahash(hash);
|
|
303
|
-
const key = toBytes(_key);
|
|
304
|
-
this.iHash = hash.create();
|
|
305
|
-
if (typeof this.iHash.update !== "function")
|
|
306
|
-
throw new Error("Expected instance of class which extends utils.Hash");
|
|
307
|
-
this.blockLen = this.iHash.blockLen;
|
|
308
|
-
this.outputLen = this.iHash.outputLen;
|
|
309
|
-
const blockLen = this.blockLen;
|
|
310
|
-
const pad = new Uint8Array(blockLen);
|
|
311
|
-
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
312
|
-
for (let i = 0; i < pad.length; i++)
|
|
313
|
-
pad[i] ^= 54;
|
|
314
|
-
this.iHash.update(pad);
|
|
315
|
-
this.oHash = hash.create();
|
|
316
|
-
for (let i = 0; i < pad.length; i++)
|
|
317
|
-
pad[i] ^= 54 ^ 92;
|
|
318
|
-
this.oHash.update(pad);
|
|
319
|
-
clean(pad);
|
|
320
|
-
}
|
|
321
|
-
update(buf) {
|
|
322
|
-
aexists(this);
|
|
323
|
-
this.iHash.update(buf);
|
|
324
|
-
return this;
|
|
325
|
-
}
|
|
326
|
-
digestInto(out) {
|
|
327
|
-
aexists(this);
|
|
328
|
-
abytes(out, this.outputLen);
|
|
329
|
-
this.finished = true;
|
|
330
|
-
this.iHash.digestInto(out);
|
|
331
|
-
this.oHash.update(out);
|
|
332
|
-
this.oHash.digestInto(out);
|
|
333
|
-
this.destroy();
|
|
334
|
-
}
|
|
335
|
-
digest() {
|
|
336
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
337
|
-
this.digestInto(out);
|
|
338
|
-
return out;
|
|
339
|
-
}
|
|
340
|
-
_cloneInto(to) {
|
|
341
|
-
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
342
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
343
|
-
to = to;
|
|
344
|
-
to.finished = finished;
|
|
345
|
-
to.destroyed = destroyed;
|
|
346
|
-
to.blockLen = blockLen;
|
|
347
|
-
to.outputLen = outputLen;
|
|
348
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
349
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
350
|
-
return to;
|
|
351
|
-
}
|
|
352
|
-
clone() {
|
|
353
|
-
return this._cloneInto();
|
|
354
|
-
}
|
|
355
|
-
destroy() {
|
|
356
|
-
this.destroyed = true;
|
|
357
|
-
this.oHash.destroy();
|
|
358
|
-
this.iHash.destroy();
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
var hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
362
|
-
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
363
|
-
|
|
364
|
-
// ../../node_modules/.pnpm/@noble+curves@1.9.2/node_modules/@noble/curves/esm/abstract/modular.js
|
|
365
|
-
var _0n = BigInt(0);
|
|
366
|
-
var _1n = BigInt(1);
|
|
367
|
-
var _2n = /* @__PURE__ */ BigInt(2);
|
|
368
|
-
var _3n = /* @__PURE__ */ BigInt(3);
|
|
369
|
-
var _4n = /* @__PURE__ */ BigInt(4);
|
|
370
|
-
var _5n = /* @__PURE__ */ BigInt(5);
|
|
371
|
-
var _8n = /* @__PURE__ */ BigInt(8);
|
|
372
|
-
function mod(a, b) {
|
|
373
|
-
const result = a % b;
|
|
374
|
-
return result >= _0n ? result : b + result;
|
|
375
|
-
}
|
|
376
|
-
function pow2(x, power, modulo) {
|
|
377
|
-
let res = x;
|
|
378
|
-
while (power-- > _0n) {
|
|
379
|
-
res *= res;
|
|
380
|
-
res %= modulo;
|
|
381
|
-
}
|
|
382
|
-
return res;
|
|
383
|
-
}
|
|
384
|
-
function invert(number, modulo) {
|
|
385
|
-
if (number === _0n)
|
|
386
|
-
throw new Error("invert: expected non-zero number");
|
|
387
|
-
if (modulo <= _0n)
|
|
388
|
-
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
389
|
-
let a = mod(number, modulo);
|
|
390
|
-
let b = modulo;
|
|
391
|
-
let x = _0n, y = _1n, u = _1n, v = _0n;
|
|
392
|
-
while (a !== _0n) {
|
|
393
|
-
const q = b / a;
|
|
394
|
-
const r = b % a;
|
|
395
|
-
const m = x - u * q;
|
|
396
|
-
const n = y - v * q;
|
|
397
|
-
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
398
|
-
}
|
|
399
|
-
const gcd = b;
|
|
400
|
-
if (gcd !== _1n)
|
|
401
|
-
throw new Error("invert: does not exist");
|
|
402
|
-
return mod(x, modulo);
|
|
403
|
-
}
|
|
404
|
-
function sqrt3mod4(Fp, n) {
|
|
405
|
-
const p1div4 = (Fp.ORDER + _1n) / _4n;
|
|
406
|
-
const root = Fp.pow(n, p1div4);
|
|
407
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
408
|
-
throw new Error("Cannot find square root");
|
|
409
|
-
return root;
|
|
410
|
-
}
|
|
411
|
-
function sqrt5mod8(Fp, n) {
|
|
412
|
-
const p5div8 = (Fp.ORDER - _5n) / _8n;
|
|
413
|
-
const n2 = Fp.mul(n, _2n);
|
|
414
|
-
const v = Fp.pow(n2, p5div8);
|
|
415
|
-
const nv = Fp.mul(n, v);
|
|
416
|
-
const i = Fp.mul(Fp.mul(nv, _2n), v);
|
|
417
|
-
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
418
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
419
|
-
throw new Error("Cannot find square root");
|
|
420
|
-
return root;
|
|
421
|
-
}
|
|
422
|
-
function tonelliShanks(P) {
|
|
423
|
-
if (P < BigInt(3))
|
|
424
|
-
throw new Error("sqrt is not defined for small field");
|
|
425
|
-
let Q = P - _1n;
|
|
426
|
-
let S = 0;
|
|
427
|
-
while (Q % _2n === _0n) {
|
|
428
|
-
Q /= _2n;
|
|
429
|
-
S++;
|
|
430
|
-
}
|
|
431
|
-
let Z = _2n;
|
|
432
|
-
const _Fp = Field(P);
|
|
433
|
-
while (FpLegendre(_Fp, Z) === 1) {
|
|
434
|
-
if (Z++ > 1e3)
|
|
435
|
-
throw new Error("Cannot find square root: probably non-prime P");
|
|
436
|
-
}
|
|
437
|
-
if (S === 1)
|
|
438
|
-
return sqrt3mod4;
|
|
439
|
-
let cc = _Fp.pow(Z, Q);
|
|
440
|
-
const Q1div2 = (Q + _1n) / _2n;
|
|
441
|
-
return function tonelliSlow(Fp, n) {
|
|
442
|
-
if (Fp.is0(n))
|
|
443
|
-
return n;
|
|
444
|
-
if (FpLegendre(Fp, n) !== 1)
|
|
445
|
-
throw new Error("Cannot find square root");
|
|
446
|
-
let M = S;
|
|
447
|
-
let c = Fp.mul(Fp.ONE, cc);
|
|
448
|
-
let t = Fp.pow(n, Q);
|
|
449
|
-
let R = Fp.pow(n, Q1div2);
|
|
450
|
-
while (!Fp.eql(t, Fp.ONE)) {
|
|
451
|
-
if (Fp.is0(t))
|
|
452
|
-
return Fp.ZERO;
|
|
453
|
-
let i = 1;
|
|
454
|
-
let t_tmp = Fp.sqr(t);
|
|
455
|
-
while (!Fp.eql(t_tmp, Fp.ONE)) {
|
|
456
|
-
i++;
|
|
457
|
-
t_tmp = Fp.sqr(t_tmp);
|
|
458
|
-
if (i === M)
|
|
459
|
-
throw new Error("Cannot find square root");
|
|
460
|
-
}
|
|
461
|
-
const exponent = _1n << BigInt(M - i - 1);
|
|
462
|
-
const b = Fp.pow(c, exponent);
|
|
463
|
-
M = i;
|
|
464
|
-
c = Fp.sqr(b);
|
|
465
|
-
t = Fp.mul(t, c);
|
|
466
|
-
R = Fp.mul(R, b);
|
|
467
|
-
}
|
|
468
|
-
return R;
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
function FpSqrt(P) {
|
|
472
|
-
if (P % _4n === _3n)
|
|
473
|
-
return sqrt3mod4;
|
|
474
|
-
if (P % _8n === _5n)
|
|
475
|
-
return sqrt5mod8;
|
|
476
|
-
return tonelliShanks(P);
|
|
477
|
-
}
|
|
478
|
-
var FIELD_FIELDS = [
|
|
479
|
-
"create",
|
|
480
|
-
"isValid",
|
|
481
|
-
"is0",
|
|
482
|
-
"neg",
|
|
483
|
-
"inv",
|
|
484
|
-
"sqrt",
|
|
485
|
-
"sqr",
|
|
486
|
-
"eql",
|
|
487
|
-
"add",
|
|
488
|
-
"sub",
|
|
489
|
-
"mul",
|
|
490
|
-
"pow",
|
|
491
|
-
"div",
|
|
492
|
-
"addN",
|
|
493
|
-
"subN",
|
|
494
|
-
"mulN",
|
|
495
|
-
"sqrN"
|
|
496
|
-
];
|
|
497
|
-
function validateField(field) {
|
|
498
|
-
const initial = {
|
|
499
|
-
ORDER: "bigint",
|
|
500
|
-
MASK: "bigint",
|
|
501
|
-
BYTES: "number",
|
|
502
|
-
BITS: "number"
|
|
503
|
-
};
|
|
504
|
-
const opts = FIELD_FIELDS.reduce((map, val) => {
|
|
505
|
-
map[val] = "function";
|
|
506
|
-
return map;
|
|
507
|
-
}, initial);
|
|
508
|
-
_validateObject(field, opts);
|
|
509
|
-
return field;
|
|
510
|
-
}
|
|
511
|
-
function FpPow(Fp, num2, power) {
|
|
512
|
-
if (power < _0n)
|
|
513
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
514
|
-
if (power === _0n)
|
|
515
|
-
return Fp.ONE;
|
|
516
|
-
if (power === _1n)
|
|
517
|
-
return num2;
|
|
518
|
-
let p = Fp.ONE;
|
|
519
|
-
let d = num2;
|
|
520
|
-
while (power > _0n) {
|
|
521
|
-
if (power & _1n)
|
|
522
|
-
p = Fp.mul(p, d);
|
|
523
|
-
d = Fp.sqr(d);
|
|
524
|
-
power >>= _1n;
|
|
525
|
-
}
|
|
526
|
-
return p;
|
|
527
|
-
}
|
|
528
|
-
function FpInvertBatch(Fp, nums, passZero = false) {
|
|
529
|
-
const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : void 0);
|
|
530
|
-
const multipliedAcc = nums.reduce((acc, num2, i) => {
|
|
531
|
-
if (Fp.is0(num2))
|
|
532
|
-
return acc;
|
|
533
|
-
inverted[i] = acc;
|
|
534
|
-
return Fp.mul(acc, num2);
|
|
535
|
-
}, Fp.ONE);
|
|
536
|
-
const invertedAcc = Fp.inv(multipliedAcc);
|
|
537
|
-
nums.reduceRight((acc, num2, i) => {
|
|
538
|
-
if (Fp.is0(num2))
|
|
539
|
-
return acc;
|
|
540
|
-
inverted[i] = Fp.mul(acc, inverted[i]);
|
|
541
|
-
return Fp.mul(acc, num2);
|
|
542
|
-
}, invertedAcc);
|
|
543
|
-
return inverted;
|
|
544
|
-
}
|
|
545
|
-
function FpLegendre(Fp, n) {
|
|
546
|
-
const p1mod2 = (Fp.ORDER - _1n) / _2n;
|
|
547
|
-
const powered = Fp.pow(n, p1mod2);
|
|
548
|
-
const yes = Fp.eql(powered, Fp.ONE);
|
|
549
|
-
const zero = Fp.eql(powered, Fp.ZERO);
|
|
550
|
-
const no = Fp.eql(powered, Fp.neg(Fp.ONE));
|
|
551
|
-
if (!yes && !zero && !no)
|
|
552
|
-
throw new Error("invalid Legendre symbol result");
|
|
553
|
-
return yes ? 1 : zero ? 0 : -1;
|
|
554
|
-
}
|
|
555
|
-
function nLength(n, nBitLength) {
|
|
556
|
-
if (nBitLength !== void 0)
|
|
557
|
-
anumber(nBitLength);
|
|
558
|
-
const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
|
|
559
|
-
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
560
|
-
return { nBitLength: _nBitLength, nByteLength };
|
|
561
|
-
}
|
|
562
|
-
function Field(ORDER, bitLenOrOpts, isLE = false, opts = {}) {
|
|
563
|
-
if (ORDER <= _0n)
|
|
564
|
-
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
565
|
-
let _nbitLength = void 0;
|
|
566
|
-
let _sqrt = void 0;
|
|
567
|
-
if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
|
|
568
|
-
if (opts.sqrt || isLE)
|
|
569
|
-
throw new Error("cannot specify opts in two arguments");
|
|
570
|
-
const _opts = bitLenOrOpts;
|
|
571
|
-
if (_opts.BITS)
|
|
572
|
-
_nbitLength = _opts.BITS;
|
|
573
|
-
if (_opts.sqrt)
|
|
574
|
-
_sqrt = _opts.sqrt;
|
|
575
|
-
if (typeof _opts.isLE === "boolean")
|
|
576
|
-
isLE = _opts.isLE;
|
|
577
|
-
} else {
|
|
578
|
-
if (typeof bitLenOrOpts === "number")
|
|
579
|
-
_nbitLength = bitLenOrOpts;
|
|
580
|
-
if (opts.sqrt)
|
|
581
|
-
_sqrt = opts.sqrt;
|
|
582
|
-
}
|
|
583
|
-
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, _nbitLength);
|
|
584
|
-
if (BYTES > 2048)
|
|
585
|
-
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
586
|
-
let sqrtP;
|
|
587
|
-
const f = Object.freeze({
|
|
588
|
-
ORDER,
|
|
589
|
-
isLE,
|
|
590
|
-
BITS,
|
|
591
|
-
BYTES,
|
|
592
|
-
MASK: bitMask(BITS),
|
|
593
|
-
ZERO: _0n,
|
|
594
|
-
ONE: _1n,
|
|
595
|
-
create: (num2) => mod(num2, ORDER),
|
|
596
|
-
isValid: (num2) => {
|
|
597
|
-
if (typeof num2 !== "bigint")
|
|
598
|
-
throw new Error("invalid field element: expected bigint, got " + typeof num2);
|
|
599
|
-
return _0n <= num2 && num2 < ORDER;
|
|
600
|
-
},
|
|
601
|
-
is0: (num2) => num2 === _0n,
|
|
602
|
-
// is valid and invertible
|
|
603
|
-
isValidNot0: (num2) => !f.is0(num2) && f.isValid(num2),
|
|
604
|
-
isOdd: (num2) => (num2 & _1n) === _1n,
|
|
605
|
-
neg: (num2) => mod(-num2, ORDER),
|
|
606
|
-
eql: (lhs, rhs) => lhs === rhs,
|
|
607
|
-
sqr: (num2) => mod(num2 * num2, ORDER),
|
|
608
|
-
add: (lhs, rhs) => mod(lhs + rhs, ORDER),
|
|
609
|
-
sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
|
|
610
|
-
mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
|
|
611
|
-
pow: (num2, power) => FpPow(f, num2, power),
|
|
612
|
-
div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
|
|
613
|
-
// Same as above, but doesn't normalize
|
|
614
|
-
sqrN: (num2) => num2 * num2,
|
|
615
|
-
addN: (lhs, rhs) => lhs + rhs,
|
|
616
|
-
subN: (lhs, rhs) => lhs - rhs,
|
|
617
|
-
mulN: (lhs, rhs) => lhs * rhs,
|
|
618
|
-
inv: (num2) => invert(num2, ORDER),
|
|
619
|
-
sqrt: _sqrt || ((n) => {
|
|
620
|
-
if (!sqrtP)
|
|
621
|
-
sqrtP = FpSqrt(ORDER);
|
|
622
|
-
return sqrtP(f, n);
|
|
623
|
-
}),
|
|
624
|
-
toBytes: (num2) => isLE ? numberToBytesLE(num2, BYTES) : numberToBytesBE(num2, BYTES),
|
|
625
|
-
fromBytes: (bytes) => {
|
|
626
|
-
if (bytes.length !== BYTES)
|
|
627
|
-
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
628
|
-
return isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
|
|
629
|
-
},
|
|
630
|
-
// TODO: we don't need it here, move out to separate fn
|
|
631
|
-
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
632
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
633
|
-
// and it's unclear what to return in there.
|
|
634
|
-
cmov: (a, b, c) => c ? b : a
|
|
635
|
-
});
|
|
636
|
-
return Object.freeze(f);
|
|
637
|
-
}
|
|
638
|
-
function getFieldBytesLength(fieldOrder) {
|
|
639
|
-
if (typeof fieldOrder !== "bigint")
|
|
640
|
-
throw new Error("field order must be bigint");
|
|
641
|
-
const bitLength = fieldOrder.toString(2).length;
|
|
642
|
-
return Math.ceil(bitLength / 8);
|
|
643
|
-
}
|
|
644
|
-
function getMinHashLength(fieldOrder) {
|
|
645
|
-
const length = getFieldBytesLength(fieldOrder);
|
|
646
|
-
return length + Math.ceil(length / 2);
|
|
647
|
-
}
|
|
648
|
-
function mapHashToField(key, fieldOrder, isLE = false) {
|
|
649
|
-
const len = key.length;
|
|
650
|
-
const fieldLen = getFieldBytesLength(fieldOrder);
|
|
651
|
-
const minLen = getMinHashLength(fieldOrder);
|
|
652
|
-
if (len < 16 || len < minLen || len > 1024)
|
|
653
|
-
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
654
|
-
const num2 = isLE ? bytesToNumberLE(key) : bytesToNumberBE(key);
|
|
655
|
-
const reduced = mod(num2, fieldOrder - _1n) + _1n;
|
|
656
|
-
return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// ../../node_modules/.pnpm/@noble+curves@1.9.2/node_modules/@noble/curves/esm/abstract/curve.js
|
|
660
|
-
var _0n2 = BigInt(0);
|
|
661
|
-
var _1n2 = BigInt(1);
|
|
662
|
-
function negateCt(condition, item) {
|
|
663
|
-
const neg = item.negate();
|
|
664
|
-
return condition ? neg : item;
|
|
665
|
-
}
|
|
666
|
-
function normalizeZ(c, property, points) {
|
|
667
|
-
const getz = property === "pz" ? (p) => p.pz : (p) => p.ez;
|
|
668
|
-
const toInv = FpInvertBatch(c.Fp, points.map(getz));
|
|
669
|
-
const affined = points.map((p, i) => p.toAffine(toInv[i]));
|
|
670
|
-
return affined.map(c.fromAffine);
|
|
671
|
-
}
|
|
672
|
-
function validateW(W, bits) {
|
|
673
|
-
if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
|
|
674
|
-
throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
|
|
675
|
-
}
|
|
676
|
-
function calcWOpts(W, scalarBits) {
|
|
677
|
-
validateW(W, scalarBits);
|
|
678
|
-
const windows = Math.ceil(scalarBits / W) + 1;
|
|
679
|
-
const windowSize = 2 ** (W - 1);
|
|
680
|
-
const maxNumber = 2 ** W;
|
|
681
|
-
const mask = bitMask(W);
|
|
682
|
-
const shiftBy = BigInt(W);
|
|
683
|
-
return { windows, windowSize, mask, maxNumber, shiftBy };
|
|
684
|
-
}
|
|
685
|
-
function calcOffsets(n, window, wOpts) {
|
|
686
|
-
const { windowSize, mask, maxNumber, shiftBy } = wOpts;
|
|
687
|
-
let wbits = Number(n & mask);
|
|
688
|
-
let nextN = n >> shiftBy;
|
|
689
|
-
if (wbits > windowSize) {
|
|
690
|
-
wbits -= maxNumber;
|
|
691
|
-
nextN += _1n2;
|
|
692
|
-
}
|
|
693
|
-
const offsetStart = window * windowSize;
|
|
694
|
-
const offset = offsetStart + Math.abs(wbits) - 1;
|
|
695
|
-
const isZero = wbits === 0;
|
|
696
|
-
const isNeg = wbits < 0;
|
|
697
|
-
const isNegF = window % 2 !== 0;
|
|
698
|
-
const offsetF = offsetStart;
|
|
699
|
-
return { nextN, offset, isZero, isNeg, isNegF, offsetF };
|
|
700
|
-
}
|
|
701
|
-
function validateMSMPoints(points, c) {
|
|
702
|
-
if (!Array.isArray(points))
|
|
703
|
-
throw new Error("array expected");
|
|
704
|
-
points.forEach((p, i) => {
|
|
705
|
-
if (!(p instanceof c))
|
|
706
|
-
throw new Error("invalid point at index " + i);
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
function validateMSMScalars(scalars, field) {
|
|
710
|
-
if (!Array.isArray(scalars))
|
|
711
|
-
throw new Error("array of scalars expected");
|
|
712
|
-
scalars.forEach((s, i) => {
|
|
713
|
-
if (!field.isValid(s))
|
|
714
|
-
throw new Error("invalid scalar at index " + i);
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
var pointPrecomputes = /* @__PURE__ */ new WeakMap();
|
|
718
|
-
var pointWindowSizes = /* @__PURE__ */ new WeakMap();
|
|
719
|
-
function getW(P) {
|
|
720
|
-
return pointWindowSizes.get(P) || 1;
|
|
721
|
-
}
|
|
722
|
-
function assert0(n) {
|
|
723
|
-
if (n !== _0n2)
|
|
724
|
-
throw new Error("invalid wNAF");
|
|
725
|
-
}
|
|
726
|
-
function wNAF(c, bits) {
|
|
727
|
-
return {
|
|
728
|
-
constTimeNegate: negateCt,
|
|
729
|
-
hasPrecomputes(elm) {
|
|
730
|
-
return getW(elm) !== 1;
|
|
731
|
-
},
|
|
732
|
-
// non-const time multiplication ladder
|
|
733
|
-
unsafeLadder(elm, n, p = c.ZERO) {
|
|
734
|
-
let d = elm;
|
|
735
|
-
while (n > _0n2) {
|
|
736
|
-
if (n & _1n2)
|
|
737
|
-
p = p.add(d);
|
|
738
|
-
d = d.double();
|
|
739
|
-
n >>= _1n2;
|
|
740
|
-
}
|
|
741
|
-
return p;
|
|
742
|
-
},
|
|
743
|
-
/**
|
|
744
|
-
* Creates a wNAF precomputation window. Used for caching.
|
|
745
|
-
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
746
|
-
* Number of precomputed points depends on the curve size:
|
|
747
|
-
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
748
|
-
* - 𝑊 is the window size
|
|
749
|
-
* - 𝑛 is the bitlength of the curve order.
|
|
750
|
-
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
751
|
-
* @param elm Point instance
|
|
752
|
-
* @param W window size
|
|
753
|
-
* @returns precomputed point tables flattened to a single array
|
|
754
|
-
*/
|
|
755
|
-
precomputeWindow(elm, W) {
|
|
756
|
-
const { windows, windowSize } = calcWOpts(W, bits);
|
|
757
|
-
const points = [];
|
|
758
|
-
let p = elm;
|
|
759
|
-
let base = p;
|
|
760
|
-
for (let window = 0; window < windows; window++) {
|
|
761
|
-
base = p;
|
|
762
|
-
points.push(base);
|
|
763
|
-
for (let i = 1; i < windowSize; i++) {
|
|
764
|
-
base = base.add(p);
|
|
765
|
-
points.push(base);
|
|
766
|
-
}
|
|
767
|
-
p = base.double();
|
|
768
|
-
}
|
|
769
|
-
return points;
|
|
770
|
-
},
|
|
771
|
-
/**
|
|
772
|
-
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
773
|
-
* @param W window size
|
|
774
|
-
* @param precomputes precomputed tables
|
|
775
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
776
|
-
* @returns real and fake (for const-time) points
|
|
777
|
-
*/
|
|
778
|
-
wNAF(W, precomputes, n) {
|
|
779
|
-
let p = c.ZERO;
|
|
780
|
-
let f = c.BASE;
|
|
781
|
-
const wo = calcWOpts(W, bits);
|
|
782
|
-
for (let window = 0; window < wo.windows; window++) {
|
|
783
|
-
const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
|
|
784
|
-
n = nextN;
|
|
785
|
-
if (isZero) {
|
|
786
|
-
f = f.add(negateCt(isNegF, precomputes[offsetF]));
|
|
787
|
-
} else {
|
|
788
|
-
p = p.add(negateCt(isNeg, precomputes[offset]));
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
assert0(n);
|
|
792
|
-
return { p, f };
|
|
793
|
-
},
|
|
794
|
-
/**
|
|
795
|
-
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
796
|
-
* @param W window size
|
|
797
|
-
* @param precomputes precomputed tables
|
|
798
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
799
|
-
* @param acc accumulator point to add result of multiplication
|
|
800
|
-
* @returns point
|
|
801
|
-
*/
|
|
802
|
-
wNAFUnsafe(W, precomputes, n, acc = c.ZERO) {
|
|
803
|
-
const wo = calcWOpts(W, bits);
|
|
804
|
-
for (let window = 0; window < wo.windows; window++) {
|
|
805
|
-
if (n === _0n2)
|
|
806
|
-
break;
|
|
807
|
-
const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
|
|
808
|
-
n = nextN;
|
|
809
|
-
if (isZero) {
|
|
810
|
-
continue;
|
|
811
|
-
} else {
|
|
812
|
-
const item = precomputes[offset];
|
|
813
|
-
acc = acc.add(isNeg ? item.negate() : item);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
assert0(n);
|
|
817
|
-
return acc;
|
|
818
|
-
},
|
|
819
|
-
getPrecomputes(W, P, transform) {
|
|
820
|
-
let comp = pointPrecomputes.get(P);
|
|
821
|
-
if (!comp) {
|
|
822
|
-
comp = this.precomputeWindow(P, W);
|
|
823
|
-
if (W !== 1) {
|
|
824
|
-
if (typeof transform === "function")
|
|
825
|
-
comp = transform(comp);
|
|
826
|
-
pointPrecomputes.set(P, comp);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return comp;
|
|
830
|
-
},
|
|
831
|
-
wNAFCached(P, n, transform) {
|
|
832
|
-
const W = getW(P);
|
|
833
|
-
return this.wNAF(W, this.getPrecomputes(W, P, transform), n);
|
|
834
|
-
},
|
|
835
|
-
wNAFCachedUnsafe(P, n, transform, prev) {
|
|
836
|
-
const W = getW(P);
|
|
837
|
-
if (W === 1)
|
|
838
|
-
return this.unsafeLadder(P, n, prev);
|
|
839
|
-
return this.wNAFUnsafe(W, this.getPrecomputes(W, P, transform), n, prev);
|
|
840
|
-
},
|
|
841
|
-
// We calculate precomputes for elliptic curve point multiplication
|
|
842
|
-
// using windowed method. This specifies window size and
|
|
843
|
-
// stores precomputed values. Usually only base point would be precomputed.
|
|
844
|
-
setWindowSize(P, W) {
|
|
845
|
-
validateW(W, bits);
|
|
846
|
-
pointWindowSizes.set(P, W);
|
|
847
|
-
pointPrecomputes.delete(P);
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
function mulEndoUnsafe(c, point, k1, k2) {
|
|
852
|
-
let acc = point;
|
|
853
|
-
let p1 = c.ZERO;
|
|
854
|
-
let p2 = c.ZERO;
|
|
855
|
-
while (k1 > _0n2 || k2 > _0n2) {
|
|
856
|
-
if (k1 & _1n2)
|
|
857
|
-
p1 = p1.add(acc);
|
|
858
|
-
if (k2 & _1n2)
|
|
859
|
-
p2 = p2.add(acc);
|
|
860
|
-
acc = acc.double();
|
|
861
|
-
k1 >>= _1n2;
|
|
862
|
-
k2 >>= _1n2;
|
|
863
|
-
}
|
|
864
|
-
return { p1, p2 };
|
|
865
|
-
}
|
|
866
|
-
function pippenger(c, fieldN, points, scalars) {
|
|
867
|
-
validateMSMPoints(points, c);
|
|
868
|
-
validateMSMScalars(scalars, fieldN);
|
|
869
|
-
const plength = points.length;
|
|
870
|
-
const slength = scalars.length;
|
|
871
|
-
if (plength !== slength)
|
|
872
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
873
|
-
const zero = c.ZERO;
|
|
874
|
-
const wbits = bitLen(BigInt(plength));
|
|
875
|
-
let windowSize = 1;
|
|
876
|
-
if (wbits > 12)
|
|
877
|
-
windowSize = wbits - 3;
|
|
878
|
-
else if (wbits > 4)
|
|
879
|
-
windowSize = wbits - 2;
|
|
880
|
-
else if (wbits > 0)
|
|
881
|
-
windowSize = 2;
|
|
882
|
-
const MASK = bitMask(windowSize);
|
|
883
|
-
const buckets = new Array(Number(MASK) + 1).fill(zero);
|
|
884
|
-
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
885
|
-
let sum = zero;
|
|
886
|
-
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
887
|
-
buckets.fill(zero);
|
|
888
|
-
for (let j = 0; j < slength; j++) {
|
|
889
|
-
const scalar = scalars[j];
|
|
890
|
-
const wbits2 = Number(scalar >> BigInt(i) & MASK);
|
|
891
|
-
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
892
|
-
}
|
|
893
|
-
let resI = zero;
|
|
894
|
-
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
895
|
-
sumI = sumI.add(buckets[j]);
|
|
896
|
-
resI = resI.add(sumI);
|
|
897
|
-
}
|
|
898
|
-
sum = sum.add(resI);
|
|
899
|
-
if (i !== 0)
|
|
900
|
-
for (let j = 0; j < windowSize; j++)
|
|
901
|
-
sum = sum.double();
|
|
902
|
-
}
|
|
903
|
-
return sum;
|
|
904
|
-
}
|
|
905
|
-
function createField(order, field) {
|
|
906
|
-
if (field) {
|
|
907
|
-
if (field.ORDER !== order)
|
|
908
|
-
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
909
|
-
validateField(field);
|
|
910
|
-
return field;
|
|
911
|
-
} else {
|
|
912
|
-
return Field(order);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
function _createCurveFields(type, CURVE, curveOpts = {}) {
|
|
916
|
-
if (!CURVE || typeof CURVE !== "object")
|
|
917
|
-
throw new Error(`expected valid ${type} CURVE object`);
|
|
918
|
-
for (const p of ["p", "n", "h"]) {
|
|
919
|
-
const val = CURVE[p];
|
|
920
|
-
if (!(typeof val === "bigint" && val > _0n2))
|
|
921
|
-
throw new Error(`CURVE.${p} must be positive bigint`);
|
|
922
|
-
}
|
|
923
|
-
const Fp = createField(CURVE.p, curveOpts.Fp);
|
|
924
|
-
const Fn = createField(CURVE.n, curveOpts.Fn);
|
|
925
|
-
const _b = type === "weierstrass" ? "b" : "d";
|
|
926
|
-
const params = ["Gx", "Gy", "a", _b];
|
|
927
|
-
for (const p of params) {
|
|
928
|
-
if (!Fp.isValid(CURVE[p]))
|
|
929
|
-
throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
|
|
930
|
-
}
|
|
931
|
-
return { Fp, Fn };
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// ../../node_modules/.pnpm/@noble+curves@1.9.2/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
935
|
-
function validateSigVerOpts(opts) {
|
|
936
|
-
if (opts.lowS !== void 0)
|
|
937
|
-
abool("lowS", opts.lowS);
|
|
938
|
-
if (opts.prehash !== void 0)
|
|
939
|
-
abool("prehash", opts.prehash);
|
|
940
|
-
}
|
|
941
|
-
var DERErr = class extends Error {
|
|
942
|
-
constructor(m = "") {
|
|
943
|
-
super(m);
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
var DER = {
|
|
947
|
-
// asn.1 DER encoding utils
|
|
948
|
-
Err: DERErr,
|
|
949
|
-
// Basic building block is TLV (Tag-Length-Value)
|
|
950
|
-
_tlv: {
|
|
951
|
-
encode: (tag, data) => {
|
|
952
|
-
const { Err: E } = DER;
|
|
953
|
-
if (tag < 0 || tag > 256)
|
|
954
|
-
throw new E("tlv.encode: wrong tag");
|
|
955
|
-
if (data.length & 1)
|
|
956
|
-
throw new E("tlv.encode: unpadded data");
|
|
957
|
-
const dataLen = data.length / 2;
|
|
958
|
-
const len = numberToHexUnpadded(dataLen);
|
|
959
|
-
if (len.length / 2 & 128)
|
|
960
|
-
throw new E("tlv.encode: long form length too big");
|
|
961
|
-
const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
|
|
962
|
-
const t = numberToHexUnpadded(tag);
|
|
963
|
-
return t + lenLen + len + data;
|
|
964
|
-
},
|
|
965
|
-
// v - value, l - left bytes (unparsed)
|
|
966
|
-
decode(tag, data) {
|
|
967
|
-
const { Err: E } = DER;
|
|
968
|
-
let pos = 0;
|
|
969
|
-
if (tag < 0 || tag > 256)
|
|
970
|
-
throw new E("tlv.encode: wrong tag");
|
|
971
|
-
if (data.length < 2 || data[pos++] !== tag)
|
|
972
|
-
throw new E("tlv.decode: wrong tlv");
|
|
973
|
-
const first = data[pos++];
|
|
974
|
-
const isLong = !!(first & 128);
|
|
975
|
-
let length = 0;
|
|
976
|
-
if (!isLong)
|
|
977
|
-
length = first;
|
|
978
|
-
else {
|
|
979
|
-
const lenLen = first & 127;
|
|
980
|
-
if (!lenLen)
|
|
981
|
-
throw new E("tlv.decode(long): indefinite length not supported");
|
|
982
|
-
if (lenLen > 4)
|
|
983
|
-
throw new E("tlv.decode(long): byte length is too big");
|
|
984
|
-
const lengthBytes = data.subarray(pos, pos + lenLen);
|
|
985
|
-
if (lengthBytes.length !== lenLen)
|
|
986
|
-
throw new E("tlv.decode: length bytes not complete");
|
|
987
|
-
if (lengthBytes[0] === 0)
|
|
988
|
-
throw new E("tlv.decode(long): zero leftmost byte");
|
|
989
|
-
for (const b of lengthBytes)
|
|
990
|
-
length = length << 8 | b;
|
|
991
|
-
pos += lenLen;
|
|
992
|
-
if (length < 128)
|
|
993
|
-
throw new E("tlv.decode(long): not minimal encoding");
|
|
994
|
-
}
|
|
995
|
-
const v = data.subarray(pos, pos + length);
|
|
996
|
-
if (v.length !== length)
|
|
997
|
-
throw new E("tlv.decode: wrong value length");
|
|
998
|
-
return { v, l: data.subarray(pos + length) };
|
|
999
|
-
}
|
|
1000
|
-
},
|
|
1001
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
1002
|
-
// since we always use positive integers here. It must always be empty:
|
|
1003
|
-
// - add zero byte if exists
|
|
1004
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
1005
|
-
_int: {
|
|
1006
|
-
encode(num2) {
|
|
1007
|
-
const { Err: E } = DER;
|
|
1008
|
-
if (num2 < _0n3)
|
|
1009
|
-
throw new E("integer: negative integers are not allowed");
|
|
1010
|
-
let hex = numberToHexUnpadded(num2);
|
|
1011
|
-
if (Number.parseInt(hex[0], 16) & 8)
|
|
1012
|
-
hex = "00" + hex;
|
|
1013
|
-
if (hex.length & 1)
|
|
1014
|
-
throw new E("unexpected DER parsing assertion: unpadded hex");
|
|
1015
|
-
return hex;
|
|
1016
|
-
},
|
|
1017
|
-
decode(data) {
|
|
1018
|
-
const { Err: E } = DER;
|
|
1019
|
-
if (data[0] & 128)
|
|
1020
|
-
throw new E("invalid signature integer: negative");
|
|
1021
|
-
if (data[0] === 0 && !(data[1] & 128))
|
|
1022
|
-
throw new E("invalid signature integer: unnecessary leading zero");
|
|
1023
|
-
return bytesToNumberBE(data);
|
|
1024
|
-
}
|
|
1025
|
-
},
|
|
1026
|
-
toSig(hex) {
|
|
1027
|
-
const { Err: E, _int: int, _tlv: tlv } = DER;
|
|
1028
|
-
const data = ensureBytes("signature", hex);
|
|
1029
|
-
const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
|
|
1030
|
-
if (seqLeftBytes.length)
|
|
1031
|
-
throw new E("invalid signature: left bytes after parsing");
|
|
1032
|
-
const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
|
|
1033
|
-
const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
|
|
1034
|
-
if (sLeftBytes.length)
|
|
1035
|
-
throw new E("invalid signature: left bytes after parsing");
|
|
1036
|
-
return { r: int.decode(rBytes), s: int.decode(sBytes) };
|
|
1037
|
-
},
|
|
1038
|
-
hexFromSig(sig) {
|
|
1039
|
-
const { _tlv: tlv, _int: int } = DER;
|
|
1040
|
-
const rs = tlv.encode(2, int.encode(sig.r));
|
|
1041
|
-
const ss = tlv.encode(2, int.encode(sig.s));
|
|
1042
|
-
const seq = rs + ss;
|
|
1043
|
-
return tlv.encode(48, seq);
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
var _0n3 = BigInt(0);
|
|
1047
|
-
var _1n3 = BigInt(1);
|
|
1048
|
-
var _2n2 = BigInt(2);
|
|
1049
|
-
var _3n2 = BigInt(3);
|
|
1050
|
-
var _4n2 = BigInt(4);
|
|
1051
|
-
function _legacyHelperEquat(Fp, a, b) {
|
|
1052
|
-
function weierstrassEquation(x) {
|
|
1053
|
-
const x2 = Fp.sqr(x);
|
|
1054
|
-
const x3 = Fp.mul(x2, x);
|
|
1055
|
-
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
|
|
1056
|
-
}
|
|
1057
|
-
return weierstrassEquation;
|
|
1058
|
-
}
|
|
1059
|
-
function _legacyHelperNormPriv(Fn, allowedPrivateKeyLengths, wrapPrivateKey) {
|
|
1060
|
-
const { BYTES: expected } = Fn;
|
|
1061
|
-
function normPrivateKeyToScalar(key) {
|
|
1062
|
-
let num2;
|
|
1063
|
-
if (typeof key === "bigint") {
|
|
1064
|
-
num2 = key;
|
|
1065
|
-
} else {
|
|
1066
|
-
let bytes = ensureBytes("private key", key);
|
|
1067
|
-
if (allowedPrivateKeyLengths) {
|
|
1068
|
-
if (!allowedPrivateKeyLengths.includes(bytes.length * 2))
|
|
1069
|
-
throw new Error("invalid private key");
|
|
1070
|
-
const padded = new Uint8Array(expected);
|
|
1071
|
-
padded.set(bytes, padded.length - bytes.length);
|
|
1072
|
-
bytes = padded;
|
|
1073
|
-
}
|
|
1074
|
-
try {
|
|
1075
|
-
num2 = Fn.fromBytes(bytes);
|
|
1076
|
-
} catch (error) {
|
|
1077
|
-
throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key}`);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
if (wrapPrivateKey)
|
|
1081
|
-
num2 = Fn.create(num2);
|
|
1082
|
-
if (!Fn.isValidNot0(num2))
|
|
1083
|
-
throw new Error("invalid private key: out of range [1..N-1]");
|
|
1084
|
-
return num2;
|
|
1085
|
-
}
|
|
1086
|
-
return normPrivateKeyToScalar;
|
|
1087
|
-
}
|
|
1088
|
-
function weierstrassN(CURVE, curveOpts = {}) {
|
|
1089
|
-
const { Fp, Fn } = _createCurveFields("weierstrass", CURVE, curveOpts);
|
|
1090
|
-
const { h: cofactor, n: CURVE_ORDER } = CURVE;
|
|
1091
|
-
_validateObject(curveOpts, {}, {
|
|
1092
|
-
allowInfinityPoint: "boolean",
|
|
1093
|
-
clearCofactor: "function",
|
|
1094
|
-
isTorsionFree: "function",
|
|
1095
|
-
fromBytes: "function",
|
|
1096
|
-
toBytes: "function",
|
|
1097
|
-
endo: "object",
|
|
1098
|
-
wrapPrivateKey: "boolean"
|
|
1099
|
-
});
|
|
1100
|
-
const { endo } = curveOpts;
|
|
1101
|
-
if (endo) {
|
|
1102
|
-
if (!Fp.is0(CURVE.a) || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
|
|
1103
|
-
throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
function assertCompressionIsSupported() {
|
|
1107
|
-
if (!Fp.isOdd)
|
|
1108
|
-
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
1109
|
-
}
|
|
1110
|
-
function pointToBytes2(_c, point, isCompressed) {
|
|
1111
|
-
const { x, y } = point.toAffine();
|
|
1112
|
-
const bx = Fp.toBytes(x);
|
|
1113
|
-
abool("isCompressed", isCompressed);
|
|
1114
|
-
if (isCompressed) {
|
|
1115
|
-
assertCompressionIsSupported();
|
|
1116
|
-
const hasEvenY = !Fp.isOdd(y);
|
|
1117
|
-
return concatBytes(pprefix(hasEvenY), bx);
|
|
1118
|
-
} else {
|
|
1119
|
-
return concatBytes(Uint8Array.of(4), bx, Fp.toBytes(y));
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
function pointFromBytes(bytes) {
|
|
1123
|
-
abytes(bytes);
|
|
1124
|
-
const L = Fp.BYTES;
|
|
1125
|
-
const LC = L + 1;
|
|
1126
|
-
const LU = 2 * L + 1;
|
|
1127
|
-
const length = bytes.length;
|
|
1128
|
-
const head = bytes[0];
|
|
1129
|
-
const tail = bytes.subarray(1);
|
|
1130
|
-
if (length === LC && (head === 2 || head === 3)) {
|
|
1131
|
-
const x = Fp.fromBytes(tail);
|
|
1132
|
-
if (!Fp.isValid(x))
|
|
1133
|
-
throw new Error("bad point: is not on curve, wrong x");
|
|
1134
|
-
const y2 = weierstrassEquation(x);
|
|
1135
|
-
let y;
|
|
1136
|
-
try {
|
|
1137
|
-
y = Fp.sqrt(y2);
|
|
1138
|
-
} catch (sqrtError) {
|
|
1139
|
-
const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
1140
|
-
throw new Error("bad point: is not on curve, sqrt error" + err);
|
|
1141
|
-
}
|
|
1142
|
-
assertCompressionIsSupported();
|
|
1143
|
-
const isYOdd = Fp.isOdd(y);
|
|
1144
|
-
const isHeadOdd = (head & 1) === 1;
|
|
1145
|
-
if (isHeadOdd !== isYOdd)
|
|
1146
|
-
y = Fp.neg(y);
|
|
1147
|
-
return { x, y };
|
|
1148
|
-
} else if (length === LU && head === 4) {
|
|
1149
|
-
const x = Fp.fromBytes(tail.subarray(L * 0, L * 1));
|
|
1150
|
-
const y = Fp.fromBytes(tail.subarray(L * 1, L * 2));
|
|
1151
|
-
if (!isValidXY(x, y))
|
|
1152
|
-
throw new Error("bad point: is not on curve");
|
|
1153
|
-
return { x, y };
|
|
1154
|
-
} else {
|
|
1155
|
-
throw new Error(`bad point: got length ${length}, expected compressed=${LC} or uncompressed=${LU}`);
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
const toBytes2 = curveOpts.toBytes || pointToBytes2;
|
|
1159
|
-
const fromBytes = curveOpts.fromBytes || pointFromBytes;
|
|
1160
|
-
const weierstrassEquation = _legacyHelperEquat(Fp, CURVE.a, CURVE.b);
|
|
1161
|
-
function isValidXY(x, y) {
|
|
1162
|
-
const left = Fp.sqr(y);
|
|
1163
|
-
const right = weierstrassEquation(x);
|
|
1164
|
-
return Fp.eql(left, right);
|
|
1165
|
-
}
|
|
1166
|
-
if (!isValidXY(CURVE.Gx, CURVE.Gy))
|
|
1167
|
-
throw new Error("bad curve params: generator point");
|
|
1168
|
-
const _4a3 = Fp.mul(Fp.pow(CURVE.a, _3n2), _4n2);
|
|
1169
|
-
const _27b2 = Fp.mul(Fp.sqr(CURVE.b), BigInt(27));
|
|
1170
|
-
if (Fp.is0(Fp.add(_4a3, _27b2)))
|
|
1171
|
-
throw new Error("bad curve params: a or b");
|
|
1172
|
-
function acoord(title, n, banZero = false) {
|
|
1173
|
-
if (!Fp.isValid(n) || banZero && Fp.is0(n))
|
|
1174
|
-
throw new Error(`bad point coordinate ${title}`);
|
|
1175
|
-
return n;
|
|
1176
|
-
}
|
|
1177
|
-
function aprjpoint(other) {
|
|
1178
|
-
if (!(other instanceof Point2))
|
|
1179
|
-
throw new Error("ProjectivePoint expected");
|
|
1180
|
-
}
|
|
1181
|
-
const toAffineMemo = memoized((p, iz) => {
|
|
1182
|
-
const { px: x, py: y, pz: z } = p;
|
|
1183
|
-
if (Fp.eql(z, Fp.ONE))
|
|
1184
|
-
return { x, y };
|
|
1185
|
-
const is0 = p.is0();
|
|
1186
|
-
if (iz == null)
|
|
1187
|
-
iz = is0 ? Fp.ONE : Fp.inv(z);
|
|
1188
|
-
const ax = Fp.mul(x, iz);
|
|
1189
|
-
const ay = Fp.mul(y, iz);
|
|
1190
|
-
const zz = Fp.mul(z, iz);
|
|
1191
|
-
if (is0)
|
|
1192
|
-
return { x: Fp.ZERO, y: Fp.ZERO };
|
|
1193
|
-
if (!Fp.eql(zz, Fp.ONE))
|
|
1194
|
-
throw new Error("invZ was invalid");
|
|
1195
|
-
return { x: ax, y: ay };
|
|
1196
|
-
});
|
|
1197
|
-
const assertValidMemo = memoized((p) => {
|
|
1198
|
-
if (p.is0()) {
|
|
1199
|
-
if (curveOpts.allowInfinityPoint && !Fp.is0(p.py))
|
|
1200
|
-
return;
|
|
1201
|
-
throw new Error("bad point: ZERO");
|
|
1202
|
-
}
|
|
1203
|
-
const { x, y } = p.toAffine();
|
|
1204
|
-
if (!Fp.isValid(x) || !Fp.isValid(y))
|
|
1205
|
-
throw new Error("bad point: x or y not field elements");
|
|
1206
|
-
if (!isValidXY(x, y))
|
|
1207
|
-
throw new Error("bad point: equation left != right");
|
|
1208
|
-
if (!p.isTorsionFree())
|
|
1209
|
-
throw new Error("bad point: not in prime-order subgroup");
|
|
1210
|
-
return true;
|
|
1211
|
-
});
|
|
1212
|
-
function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
|
|
1213
|
-
k2p = new Point2(Fp.mul(k2p.px, endoBeta), k2p.py, k2p.pz);
|
|
1214
|
-
k1p = negateCt(k1neg, k1p);
|
|
1215
|
-
k2p = negateCt(k2neg, k2p);
|
|
1216
|
-
return k1p.add(k2p);
|
|
1217
|
-
}
|
|
1218
|
-
class Point2 {
|
|
1219
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1220
|
-
constructor(px, py, pz) {
|
|
1221
|
-
this.px = acoord("x", px);
|
|
1222
|
-
this.py = acoord("y", py, true);
|
|
1223
|
-
this.pz = acoord("z", pz);
|
|
1224
|
-
Object.freeze(this);
|
|
1225
|
-
}
|
|
1226
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1227
|
-
static fromAffine(p) {
|
|
1228
|
-
const { x, y } = p || {};
|
|
1229
|
-
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
1230
|
-
throw new Error("invalid affine point");
|
|
1231
|
-
if (p instanceof Point2)
|
|
1232
|
-
throw new Error("projective point not allowed");
|
|
1233
|
-
if (Fp.is0(x) && Fp.is0(y))
|
|
1234
|
-
return Point2.ZERO;
|
|
1235
|
-
return new Point2(x, y, Fp.ONE);
|
|
1236
|
-
}
|
|
1237
|
-
get x() {
|
|
1238
|
-
return this.toAffine().x;
|
|
1239
|
-
}
|
|
1240
|
-
get y() {
|
|
1241
|
-
return this.toAffine().y;
|
|
1242
|
-
}
|
|
1243
|
-
static normalizeZ(points) {
|
|
1244
|
-
return normalizeZ(Point2, "pz", points);
|
|
1245
|
-
}
|
|
1246
|
-
static fromBytes(bytes) {
|
|
1247
|
-
abytes(bytes);
|
|
1248
|
-
return Point2.fromHex(bytes);
|
|
1249
|
-
}
|
|
1250
|
-
/** Converts hash string or Uint8Array to Point. */
|
|
1251
|
-
static fromHex(hex) {
|
|
1252
|
-
const P = Point2.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
|
|
1253
|
-
P.assertValidity();
|
|
1254
|
-
return P;
|
|
1255
|
-
}
|
|
1256
|
-
/** Multiplies generator point by privateKey. */
|
|
1257
|
-
static fromPrivateKey(privateKey) {
|
|
1258
|
-
const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
|
|
1259
|
-
return Point2.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
1260
|
-
}
|
|
1261
|
-
/** Multiscalar Multiplication */
|
|
1262
|
-
static msm(points, scalars) {
|
|
1263
|
-
return pippenger(Point2, Fn, points, scalars);
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
*
|
|
1267
|
-
* @param windowSize
|
|
1268
|
-
* @param isLazy true will defer table computation until the first multiplication
|
|
1269
|
-
* @returns
|
|
1270
|
-
*/
|
|
1271
|
-
precompute(windowSize = 8, isLazy = true) {
|
|
1272
|
-
wnaf.setWindowSize(this, windowSize);
|
|
1273
|
-
if (!isLazy)
|
|
1274
|
-
this.multiply(_3n2);
|
|
1275
|
-
return this;
|
|
1276
|
-
}
|
|
1277
|
-
/** "Private method", don't use it directly */
|
|
1278
|
-
_setWindowSize(windowSize) {
|
|
1279
|
-
this.precompute(windowSize);
|
|
1280
|
-
}
|
|
1281
|
-
// TODO: return `this`
|
|
1282
|
-
/** A point on curve is valid if it conforms to equation. */
|
|
1283
|
-
assertValidity() {
|
|
1284
|
-
assertValidMemo(this);
|
|
1285
|
-
}
|
|
1286
|
-
hasEvenY() {
|
|
1287
|
-
const { y } = this.toAffine();
|
|
1288
|
-
if (!Fp.isOdd)
|
|
1289
|
-
throw new Error("Field doesn't support isOdd");
|
|
1290
|
-
return !Fp.isOdd(y);
|
|
1291
|
-
}
|
|
1292
|
-
/** Compare one point to another. */
|
|
1293
|
-
equals(other) {
|
|
1294
|
-
aprjpoint(other);
|
|
1295
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1296
|
-
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
1297
|
-
const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
|
|
1298
|
-
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
1299
|
-
return U1 && U2;
|
|
1300
|
-
}
|
|
1301
|
-
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
1302
|
-
negate() {
|
|
1303
|
-
return new Point2(this.px, Fp.neg(this.py), this.pz);
|
|
1304
|
-
}
|
|
1305
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
1306
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1307
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1308
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1309
|
-
double() {
|
|
1310
|
-
const { a, b } = CURVE;
|
|
1311
|
-
const b3 = Fp.mul(b, _3n2);
|
|
1312
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1313
|
-
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
1314
|
-
let t0 = Fp.mul(X1, X1);
|
|
1315
|
-
let t1 = Fp.mul(Y1, Y1);
|
|
1316
|
-
let t2 = Fp.mul(Z1, Z1);
|
|
1317
|
-
let t3 = Fp.mul(X1, Y1);
|
|
1318
|
-
t3 = Fp.add(t3, t3);
|
|
1319
|
-
Z3 = Fp.mul(X1, Z1);
|
|
1320
|
-
Z3 = Fp.add(Z3, Z3);
|
|
1321
|
-
X3 = Fp.mul(a, Z3);
|
|
1322
|
-
Y3 = Fp.mul(b3, t2);
|
|
1323
|
-
Y3 = Fp.add(X3, Y3);
|
|
1324
|
-
X3 = Fp.sub(t1, Y3);
|
|
1325
|
-
Y3 = Fp.add(t1, Y3);
|
|
1326
|
-
Y3 = Fp.mul(X3, Y3);
|
|
1327
|
-
X3 = Fp.mul(t3, X3);
|
|
1328
|
-
Z3 = Fp.mul(b3, Z3);
|
|
1329
|
-
t2 = Fp.mul(a, t2);
|
|
1330
|
-
t3 = Fp.sub(t0, t2);
|
|
1331
|
-
t3 = Fp.mul(a, t3);
|
|
1332
|
-
t3 = Fp.add(t3, Z3);
|
|
1333
|
-
Z3 = Fp.add(t0, t0);
|
|
1334
|
-
t0 = Fp.add(Z3, t0);
|
|
1335
|
-
t0 = Fp.add(t0, t2);
|
|
1336
|
-
t0 = Fp.mul(t0, t3);
|
|
1337
|
-
Y3 = Fp.add(Y3, t0);
|
|
1338
|
-
t2 = Fp.mul(Y1, Z1);
|
|
1339
|
-
t2 = Fp.add(t2, t2);
|
|
1340
|
-
t0 = Fp.mul(t2, t3);
|
|
1341
|
-
X3 = Fp.sub(X3, t0);
|
|
1342
|
-
Z3 = Fp.mul(t2, t1);
|
|
1343
|
-
Z3 = Fp.add(Z3, Z3);
|
|
1344
|
-
Z3 = Fp.add(Z3, Z3);
|
|
1345
|
-
return new Point2(X3, Y3, Z3);
|
|
1346
|
-
}
|
|
1347
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
1348
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1349
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1350
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1351
|
-
add(other) {
|
|
1352
|
-
aprjpoint(other);
|
|
1353
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
1354
|
-
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
1355
|
-
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
|
|
1356
|
-
const a = CURVE.a;
|
|
1357
|
-
const b3 = Fp.mul(CURVE.b, _3n2);
|
|
1358
|
-
let t0 = Fp.mul(X1, X2);
|
|
1359
|
-
let t1 = Fp.mul(Y1, Y2);
|
|
1360
|
-
let t2 = Fp.mul(Z1, Z2);
|
|
1361
|
-
let t3 = Fp.add(X1, Y1);
|
|
1362
|
-
let t4 = Fp.add(X2, Y2);
|
|
1363
|
-
t3 = Fp.mul(t3, t4);
|
|
1364
|
-
t4 = Fp.add(t0, t1);
|
|
1365
|
-
t3 = Fp.sub(t3, t4);
|
|
1366
|
-
t4 = Fp.add(X1, Z1);
|
|
1367
|
-
let t5 = Fp.add(X2, Z2);
|
|
1368
|
-
t4 = Fp.mul(t4, t5);
|
|
1369
|
-
t5 = Fp.add(t0, t2);
|
|
1370
|
-
t4 = Fp.sub(t4, t5);
|
|
1371
|
-
t5 = Fp.add(Y1, Z1);
|
|
1372
|
-
X3 = Fp.add(Y2, Z2);
|
|
1373
|
-
t5 = Fp.mul(t5, X3);
|
|
1374
|
-
X3 = Fp.add(t1, t2);
|
|
1375
|
-
t5 = Fp.sub(t5, X3);
|
|
1376
|
-
Z3 = Fp.mul(a, t4);
|
|
1377
|
-
X3 = Fp.mul(b3, t2);
|
|
1378
|
-
Z3 = Fp.add(X3, Z3);
|
|
1379
|
-
X3 = Fp.sub(t1, Z3);
|
|
1380
|
-
Z3 = Fp.add(t1, Z3);
|
|
1381
|
-
Y3 = Fp.mul(X3, Z3);
|
|
1382
|
-
t1 = Fp.add(t0, t0);
|
|
1383
|
-
t1 = Fp.add(t1, t0);
|
|
1384
|
-
t2 = Fp.mul(a, t2);
|
|
1385
|
-
t4 = Fp.mul(b3, t4);
|
|
1386
|
-
t1 = Fp.add(t1, t2);
|
|
1387
|
-
t2 = Fp.sub(t0, t2);
|
|
1388
|
-
t2 = Fp.mul(a, t2);
|
|
1389
|
-
t4 = Fp.add(t4, t2);
|
|
1390
|
-
t0 = Fp.mul(t1, t4);
|
|
1391
|
-
Y3 = Fp.add(Y3, t0);
|
|
1392
|
-
t0 = Fp.mul(t5, t4);
|
|
1393
|
-
X3 = Fp.mul(t3, X3);
|
|
1394
|
-
X3 = Fp.sub(X3, t0);
|
|
1395
|
-
t0 = Fp.mul(t3, t1);
|
|
1396
|
-
Z3 = Fp.mul(t5, Z3);
|
|
1397
|
-
Z3 = Fp.add(Z3, t0);
|
|
1398
|
-
return new Point2(X3, Y3, Z3);
|
|
1399
|
-
}
|
|
1400
|
-
subtract(other) {
|
|
1401
|
-
return this.add(other.negate());
|
|
1402
|
-
}
|
|
1403
|
-
is0() {
|
|
1404
|
-
return this.equals(Point2.ZERO);
|
|
1405
|
-
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Constant time multiplication.
|
|
1408
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
1409
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
1410
|
-
* Uses precomputes when available.
|
|
1411
|
-
* Uses endomorphism for Koblitz curves.
|
|
1412
|
-
* @param scalar by which the point would be multiplied
|
|
1413
|
-
* @returns New point
|
|
1414
|
-
*/
|
|
1415
|
-
multiply(scalar) {
|
|
1416
|
-
const { endo: endo2 } = curveOpts;
|
|
1417
|
-
if (!Fn.isValidNot0(scalar))
|
|
1418
|
-
throw new Error("invalid scalar: out of range");
|
|
1419
|
-
let point, fake;
|
|
1420
|
-
const mul = (n) => wnaf.wNAFCached(this, n, Point2.normalizeZ);
|
|
1421
|
-
if (endo2) {
|
|
1422
|
-
const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(scalar);
|
|
1423
|
-
const { p: k1p, f: k1f } = mul(k1);
|
|
1424
|
-
const { p: k2p, f: k2f } = mul(k2);
|
|
1425
|
-
fake = k1f.add(k2f);
|
|
1426
|
-
point = finishEndo(endo2.beta, k1p, k2p, k1neg, k2neg);
|
|
1427
|
-
} else {
|
|
1428
|
-
const { p, f } = mul(scalar);
|
|
1429
|
-
point = p;
|
|
1430
|
-
fake = f;
|
|
1431
|
-
}
|
|
1432
|
-
return Point2.normalizeZ([point, fake])[0];
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1436
|
-
* It's faster, but should only be used when you don't care about
|
|
1437
|
-
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
1438
|
-
*/
|
|
1439
|
-
multiplyUnsafe(sc) {
|
|
1440
|
-
const { endo: endo2 } = curveOpts;
|
|
1441
|
-
const p = this;
|
|
1442
|
-
if (!Fn.isValid(sc))
|
|
1443
|
-
throw new Error("invalid scalar: out of range");
|
|
1444
|
-
if (sc === _0n3 || p.is0())
|
|
1445
|
-
return Point2.ZERO;
|
|
1446
|
-
if (sc === _1n3)
|
|
1447
|
-
return p;
|
|
1448
|
-
if (wnaf.hasPrecomputes(this))
|
|
1449
|
-
return this.multiply(sc);
|
|
1450
|
-
if (endo2) {
|
|
1451
|
-
const { k1neg, k1, k2neg, k2 } = endo2.splitScalar(sc);
|
|
1452
|
-
const { p1, p2 } = mulEndoUnsafe(Point2, p, k1, k2);
|
|
1453
|
-
return finishEndo(endo2.beta, p1, p2, k1neg, k2neg);
|
|
1454
|
-
} else {
|
|
1455
|
-
return wnaf.wNAFCachedUnsafe(p, sc);
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
multiplyAndAddUnsafe(Q, a, b) {
|
|
1459
|
-
const sum = this.multiplyUnsafe(a).add(Q.multiplyUnsafe(b));
|
|
1460
|
-
return sum.is0() ? void 0 : sum;
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Converts Projective point to affine (x, y) coordinates.
|
|
1464
|
-
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
1465
|
-
*/
|
|
1466
|
-
toAffine(invertedZ) {
|
|
1467
|
-
return toAffineMemo(this, invertedZ);
|
|
1468
|
-
}
|
|
1469
|
-
/**
|
|
1470
|
-
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
1471
|
-
* Always torsion-free for cofactor=1 curves.
|
|
1472
|
-
*/
|
|
1473
|
-
isTorsionFree() {
|
|
1474
|
-
const { isTorsionFree } = curveOpts;
|
|
1475
|
-
if (cofactor === _1n3)
|
|
1476
|
-
return true;
|
|
1477
|
-
if (isTorsionFree)
|
|
1478
|
-
return isTorsionFree(Point2, this);
|
|
1479
|
-
return wnaf.wNAFCachedUnsafe(this, CURVE_ORDER).is0();
|
|
1480
|
-
}
|
|
1481
|
-
clearCofactor() {
|
|
1482
|
-
const { clearCofactor } = curveOpts;
|
|
1483
|
-
if (cofactor === _1n3)
|
|
1484
|
-
return this;
|
|
1485
|
-
if (clearCofactor)
|
|
1486
|
-
return clearCofactor(Point2, this);
|
|
1487
|
-
return this.multiplyUnsafe(cofactor);
|
|
1488
|
-
}
|
|
1489
|
-
toBytes(isCompressed = true) {
|
|
1490
|
-
abool("isCompressed", isCompressed);
|
|
1491
|
-
this.assertValidity();
|
|
1492
|
-
return toBytes2(Point2, this, isCompressed);
|
|
1493
|
-
}
|
|
1494
|
-
/** @deprecated use `toBytes` */
|
|
1495
|
-
toRawBytes(isCompressed = true) {
|
|
1496
|
-
return this.toBytes(isCompressed);
|
|
1497
|
-
}
|
|
1498
|
-
toHex(isCompressed = true) {
|
|
1499
|
-
return bytesToHex(this.toBytes(isCompressed));
|
|
1500
|
-
}
|
|
1501
|
-
toString() {
|
|
1502
|
-
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
Point2.BASE = new Point2(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
1506
|
-
Point2.ZERO = new Point2(Fp.ZERO, Fp.ONE, Fp.ZERO);
|
|
1507
|
-
Point2.Fp = Fp;
|
|
1508
|
-
Point2.Fn = Fn;
|
|
1509
|
-
const bits = Fn.BITS;
|
|
1510
|
-
const wnaf = wNAF(Point2, curveOpts.endo ? Math.ceil(bits / 2) : bits);
|
|
1511
|
-
return Point2;
|
|
1512
|
-
}
|
|
1513
|
-
function pprefix(hasEvenY) {
|
|
1514
|
-
return Uint8Array.of(hasEvenY ? 2 : 3);
|
|
1515
|
-
}
|
|
1516
|
-
function ecdsa(Point2, ecdsaOpts, curveOpts = {}) {
|
|
1517
|
-
_validateObject(ecdsaOpts, { hash: "function" }, {
|
|
1518
|
-
hmac: "function",
|
|
1519
|
-
lowS: "boolean",
|
|
1520
|
-
randomBytes: "function",
|
|
1521
|
-
bits2int: "function",
|
|
1522
|
-
bits2int_modN: "function"
|
|
1523
|
-
});
|
|
1524
|
-
const randomBytes_ = ecdsaOpts.randomBytes || randomBytes;
|
|
1525
|
-
const hmac_ = ecdsaOpts.hmac || ((key, ...msgs) => hmac(ecdsaOpts.hash, key, concatBytes(...msgs)));
|
|
1526
|
-
const { Fp, Fn } = Point2;
|
|
1527
|
-
const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
|
|
1528
|
-
function isBiggerThanHalfOrder(number) {
|
|
1529
|
-
const HALF = CURVE_ORDER >> _1n3;
|
|
1530
|
-
return number > HALF;
|
|
1531
|
-
}
|
|
1532
|
-
function normalizeS(s) {
|
|
1533
|
-
return isBiggerThanHalfOrder(s) ? Fn.neg(s) : s;
|
|
1534
|
-
}
|
|
1535
|
-
function aValidRS(title, num2) {
|
|
1536
|
-
if (!Fn.isValidNot0(num2))
|
|
1537
|
-
throw new Error(`invalid signature ${title}: out of range 1..CURVE.n`);
|
|
1538
|
-
}
|
|
1539
|
-
class Signature {
|
|
1540
|
-
constructor(r, s, recovery) {
|
|
1541
|
-
aValidRS("r", r);
|
|
1542
|
-
aValidRS("s", s);
|
|
1543
|
-
this.r = r;
|
|
1544
|
-
this.s = s;
|
|
1545
|
-
if (recovery != null)
|
|
1546
|
-
this.recovery = recovery;
|
|
1547
|
-
Object.freeze(this);
|
|
1548
|
-
}
|
|
1549
|
-
// pair (bytes of r, bytes of s)
|
|
1550
|
-
static fromCompact(hex) {
|
|
1551
|
-
const L = Fn.BYTES;
|
|
1552
|
-
const b = ensureBytes("compactSignature", hex, L * 2);
|
|
1553
|
-
return new Signature(Fn.fromBytes(b.subarray(0, L)), Fn.fromBytes(b.subarray(L, L * 2)));
|
|
1554
|
-
}
|
|
1555
|
-
// DER encoded ECDSA signature
|
|
1556
|
-
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1557
|
-
static fromDER(hex) {
|
|
1558
|
-
const { r, s } = DER.toSig(ensureBytes("DER", hex));
|
|
1559
|
-
return new Signature(r, s);
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* @todo remove
|
|
1563
|
-
* @deprecated
|
|
1564
|
-
*/
|
|
1565
|
-
assertValidity() {
|
|
1566
|
-
}
|
|
1567
|
-
addRecoveryBit(recovery) {
|
|
1568
|
-
return new Signature(this.r, this.s, recovery);
|
|
1569
|
-
}
|
|
1570
|
-
// ProjPointType<bigint>
|
|
1571
|
-
recoverPublicKey(msgHash) {
|
|
1572
|
-
const FIELD_ORDER = Fp.ORDER;
|
|
1573
|
-
const { r, s, recovery: rec } = this;
|
|
1574
|
-
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
1575
|
-
throw new Error("recovery id invalid");
|
|
1576
|
-
const hasCofactor = CURVE_ORDER * _2n2 < FIELD_ORDER;
|
|
1577
|
-
if (hasCofactor && rec > 1)
|
|
1578
|
-
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
1579
|
-
const radj = rec === 2 || rec === 3 ? r + CURVE_ORDER : r;
|
|
1580
|
-
if (!Fp.isValid(radj))
|
|
1581
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
1582
|
-
const x = Fp.toBytes(radj);
|
|
1583
|
-
const R = Point2.fromHex(concatBytes(pprefix((rec & 1) === 0), x));
|
|
1584
|
-
const ir = Fn.inv(radj);
|
|
1585
|
-
const h = bits2int_modN(ensureBytes("msgHash", msgHash));
|
|
1586
|
-
const u1 = Fn.create(-h * ir);
|
|
1587
|
-
const u2 = Fn.create(s * ir);
|
|
1588
|
-
const Q = Point2.BASE.multiplyUnsafe(u1).add(R.multiplyUnsafe(u2));
|
|
1589
|
-
if (Q.is0())
|
|
1590
|
-
throw new Error("point at infinify");
|
|
1591
|
-
Q.assertValidity();
|
|
1592
|
-
return Q;
|
|
1593
|
-
}
|
|
1594
|
-
// Signatures should be low-s, to prevent malleability.
|
|
1595
|
-
hasHighS() {
|
|
1596
|
-
return isBiggerThanHalfOrder(this.s);
|
|
1597
|
-
}
|
|
1598
|
-
normalizeS() {
|
|
1599
|
-
return this.hasHighS() ? new Signature(this.r, Fn.neg(this.s), this.recovery) : this;
|
|
1600
|
-
}
|
|
1601
|
-
toBytes(format) {
|
|
1602
|
-
if (format === "compact")
|
|
1603
|
-
return concatBytes(Fn.toBytes(this.r), Fn.toBytes(this.s));
|
|
1604
|
-
if (format === "der")
|
|
1605
|
-
return hexToBytes(DER.hexFromSig(this));
|
|
1606
|
-
throw new Error("invalid format");
|
|
1607
|
-
}
|
|
1608
|
-
// DER-encoded
|
|
1609
|
-
toDERRawBytes() {
|
|
1610
|
-
return this.toBytes("der");
|
|
1611
|
-
}
|
|
1612
|
-
toDERHex() {
|
|
1613
|
-
return bytesToHex(this.toBytes("der"));
|
|
1614
|
-
}
|
|
1615
|
-
// padded bytes of r, then padded bytes of s
|
|
1616
|
-
toCompactRawBytes() {
|
|
1617
|
-
return this.toBytes("compact");
|
|
1618
|
-
}
|
|
1619
|
-
toCompactHex() {
|
|
1620
|
-
return bytesToHex(this.toBytes("compact"));
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
|
|
1624
|
-
const utils = {
|
|
1625
|
-
isValidPrivateKey(privateKey) {
|
|
1626
|
-
try {
|
|
1627
|
-
normPrivateKeyToScalar(privateKey);
|
|
1628
|
-
return true;
|
|
1629
|
-
} catch (error) {
|
|
1630
|
-
return false;
|
|
1631
|
-
}
|
|
1632
|
-
},
|
|
1633
|
-
normPrivateKeyToScalar,
|
|
1634
|
-
/**
|
|
1635
|
-
* Produces cryptographically secure private key from random of size
|
|
1636
|
-
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1637
|
-
*/
|
|
1638
|
-
randomPrivateKey: () => {
|
|
1639
|
-
const n = CURVE_ORDER;
|
|
1640
|
-
return mapHashToField(randomBytes_(getMinHashLength(n)), n);
|
|
1641
|
-
},
|
|
1642
|
-
precompute(windowSize = 8, point = Point2.BASE) {
|
|
1643
|
-
return point.precompute(windowSize, false);
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
function getPublicKey(privateKey, isCompressed = true) {
|
|
1647
|
-
return Point2.fromPrivateKey(privateKey).toBytes(isCompressed);
|
|
1648
|
-
}
|
|
1649
|
-
function isProbPub(item) {
|
|
1650
|
-
if (typeof item === "bigint")
|
|
1651
|
-
return false;
|
|
1652
|
-
if (item instanceof Point2)
|
|
1653
|
-
return true;
|
|
1654
|
-
const arr = ensureBytes("key", item);
|
|
1655
|
-
const length = arr.length;
|
|
1656
|
-
const L = Fp.BYTES;
|
|
1657
|
-
const LC = L + 1;
|
|
1658
|
-
const LU = 2 * L + 1;
|
|
1659
|
-
if (curveOpts.allowedPrivateKeyLengths || Fn.BYTES === LC) {
|
|
1660
|
-
return void 0;
|
|
1661
|
-
} else {
|
|
1662
|
-
return length === LC || length === LU;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
function getSharedSecret(privateA, publicB, isCompressed = true) {
|
|
1666
|
-
if (isProbPub(privateA) === true)
|
|
1667
|
-
throw new Error("first arg must be private key");
|
|
1668
|
-
if (isProbPub(publicB) === false)
|
|
1669
|
-
throw new Error("second arg must be public key");
|
|
1670
|
-
const b = Point2.fromHex(publicB);
|
|
1671
|
-
return b.multiply(normPrivateKeyToScalar(privateA)).toBytes(isCompressed);
|
|
1672
|
-
}
|
|
1673
|
-
const bits2int = ecdsaOpts.bits2int || function(bytes) {
|
|
1674
|
-
if (bytes.length > 8192)
|
|
1675
|
-
throw new Error("input is too large");
|
|
1676
|
-
const num2 = bytesToNumberBE(bytes);
|
|
1677
|
-
const delta = bytes.length * 8 - fnBits;
|
|
1678
|
-
return delta > 0 ? num2 >> BigInt(delta) : num2;
|
|
1679
|
-
};
|
|
1680
|
-
const bits2int_modN = ecdsaOpts.bits2int_modN || function(bytes) {
|
|
1681
|
-
return Fn.create(bits2int(bytes));
|
|
1682
|
-
};
|
|
1683
|
-
const ORDER_MASK = bitMask(fnBits);
|
|
1684
|
-
function int2octets(num2) {
|
|
1685
|
-
aInRange("num < 2^" + fnBits, num2, _0n3, ORDER_MASK);
|
|
1686
|
-
return Fn.toBytes(num2);
|
|
1687
|
-
}
|
|
1688
|
-
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
1689
|
-
if (["recovered", "canonical"].some((k) => k in opts))
|
|
1690
|
-
throw new Error("sign() legacy options not supported");
|
|
1691
|
-
const { hash } = ecdsaOpts;
|
|
1692
|
-
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
1693
|
-
if (lowS == null)
|
|
1694
|
-
lowS = true;
|
|
1695
|
-
msgHash = ensureBytes("msgHash", msgHash);
|
|
1696
|
-
validateSigVerOpts(opts);
|
|
1697
|
-
if (prehash)
|
|
1698
|
-
msgHash = ensureBytes("prehashed msgHash", hash(msgHash));
|
|
1699
|
-
const h1int = bits2int_modN(msgHash);
|
|
1700
|
-
const d = normPrivateKeyToScalar(privateKey);
|
|
1701
|
-
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
1702
|
-
if (ent != null && ent !== false) {
|
|
1703
|
-
const e = ent === true ? randomBytes_(Fp.BYTES) : ent;
|
|
1704
|
-
seedArgs.push(ensureBytes("extraEntropy", e));
|
|
1705
|
-
}
|
|
1706
|
-
const seed = concatBytes(...seedArgs);
|
|
1707
|
-
const m = h1int;
|
|
1708
|
-
function k2sig(kBytes) {
|
|
1709
|
-
const k = bits2int(kBytes);
|
|
1710
|
-
if (!Fn.isValidNot0(k))
|
|
1711
|
-
return;
|
|
1712
|
-
const ik = Fn.inv(k);
|
|
1713
|
-
const q = Point2.BASE.multiply(k).toAffine();
|
|
1714
|
-
const r = Fn.create(q.x);
|
|
1715
|
-
if (r === _0n3)
|
|
1716
|
-
return;
|
|
1717
|
-
const s = Fn.create(ik * Fn.create(m + r * d));
|
|
1718
|
-
if (s === _0n3)
|
|
1719
|
-
return;
|
|
1720
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n3);
|
|
1721
|
-
let normS = s;
|
|
1722
|
-
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
1723
|
-
normS = normalizeS(s);
|
|
1724
|
-
recovery ^= 1;
|
|
1725
|
-
}
|
|
1726
|
-
return new Signature(r, normS, recovery);
|
|
1727
|
-
}
|
|
1728
|
-
return { seed, k2sig };
|
|
1729
|
-
}
|
|
1730
|
-
const defaultSigOpts = { lowS: ecdsaOpts.lowS, prehash: false };
|
|
1731
|
-
const defaultVerOpts = { lowS: ecdsaOpts.lowS, prehash: false };
|
|
1732
|
-
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
|
1733
|
-
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
|
1734
|
-
const drbg = createHmacDrbg(ecdsaOpts.hash.outputLen, Fn.BYTES, hmac_);
|
|
1735
|
-
return drbg(seed, k2sig);
|
|
1736
|
-
}
|
|
1737
|
-
Point2.BASE.precompute(8);
|
|
1738
|
-
function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
1739
|
-
const sg = signature;
|
|
1740
|
-
msgHash = ensureBytes("msgHash", msgHash);
|
|
1741
|
-
publicKey = ensureBytes("publicKey", publicKey);
|
|
1742
|
-
validateSigVerOpts(opts);
|
|
1743
|
-
const { lowS, prehash, format } = opts;
|
|
1744
|
-
if ("strict" in opts)
|
|
1745
|
-
throw new Error("options.strict was renamed to lowS");
|
|
1746
|
-
if (format !== void 0 && !["compact", "der", "js"].includes(format))
|
|
1747
|
-
throw new Error('format must be "compact", "der" or "js"');
|
|
1748
|
-
const isHex = typeof sg === "string" || isBytes(sg);
|
|
1749
|
-
const isObj = !isHex && !format && typeof sg === "object" && sg !== null && typeof sg.r === "bigint" && typeof sg.s === "bigint";
|
|
1750
|
-
if (!isHex && !isObj)
|
|
1751
|
-
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
1752
|
-
let _sig = void 0;
|
|
1753
|
-
let P;
|
|
1754
|
-
try {
|
|
1755
|
-
if (isObj) {
|
|
1756
|
-
if (format === void 0 || format === "js") {
|
|
1757
|
-
_sig = new Signature(sg.r, sg.s);
|
|
1758
|
-
} else {
|
|
1759
|
-
throw new Error("invalid format");
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
if (isHex) {
|
|
1763
|
-
try {
|
|
1764
|
-
if (format !== "compact")
|
|
1765
|
-
_sig = Signature.fromDER(sg);
|
|
1766
|
-
} catch (derError) {
|
|
1767
|
-
if (!(derError instanceof DER.Err))
|
|
1768
|
-
throw derError;
|
|
1769
|
-
}
|
|
1770
|
-
if (!_sig && format !== "der")
|
|
1771
|
-
_sig = Signature.fromCompact(sg);
|
|
1772
|
-
}
|
|
1773
|
-
P = Point2.fromHex(publicKey);
|
|
1774
|
-
} catch (error) {
|
|
1775
|
-
return false;
|
|
1776
|
-
}
|
|
1777
|
-
if (!_sig)
|
|
1778
|
-
return false;
|
|
1779
|
-
if (lowS && _sig.hasHighS())
|
|
1780
|
-
return false;
|
|
1781
|
-
if (prehash)
|
|
1782
|
-
msgHash = ecdsaOpts.hash(msgHash);
|
|
1783
|
-
const { r, s } = _sig;
|
|
1784
|
-
const h = bits2int_modN(msgHash);
|
|
1785
|
-
const is = Fn.inv(s);
|
|
1786
|
-
const u1 = Fn.create(h * is);
|
|
1787
|
-
const u2 = Fn.create(r * is);
|
|
1788
|
-
const R = Point2.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
|
|
1789
|
-
if (R.is0())
|
|
1790
|
-
return false;
|
|
1791
|
-
const v = Fn.create(R.x);
|
|
1792
|
-
return v === r;
|
|
1793
|
-
}
|
|
1794
|
-
return Object.freeze({
|
|
1795
|
-
getPublicKey,
|
|
1796
|
-
getSharedSecret,
|
|
1797
|
-
sign,
|
|
1798
|
-
verify,
|
|
1799
|
-
utils,
|
|
1800
|
-
Point: Point2,
|
|
1801
|
-
Signature
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
function _weierstrass_legacy_opts_to_new(c) {
|
|
1805
|
-
const CURVE = {
|
|
1806
|
-
a: c.a,
|
|
1807
|
-
b: c.b,
|
|
1808
|
-
p: c.Fp.ORDER,
|
|
1809
|
-
n: c.n,
|
|
1810
|
-
h: c.h,
|
|
1811
|
-
Gx: c.Gx,
|
|
1812
|
-
Gy: c.Gy
|
|
1813
|
-
};
|
|
1814
|
-
const Fp = c.Fp;
|
|
1815
|
-
const Fn = Field(CURVE.n, c.nBitLength);
|
|
1816
|
-
const curveOpts = {
|
|
1817
|
-
Fp,
|
|
1818
|
-
Fn,
|
|
1819
|
-
allowedPrivateKeyLengths: c.allowedPrivateKeyLengths,
|
|
1820
|
-
allowInfinityPoint: c.allowInfinityPoint,
|
|
1821
|
-
endo: c.endo,
|
|
1822
|
-
wrapPrivateKey: c.wrapPrivateKey,
|
|
1823
|
-
isTorsionFree: c.isTorsionFree,
|
|
1824
|
-
clearCofactor: c.clearCofactor,
|
|
1825
|
-
fromBytes: c.fromBytes,
|
|
1826
|
-
toBytes: c.toBytes
|
|
1827
|
-
};
|
|
1828
|
-
return { CURVE, curveOpts };
|
|
1829
|
-
}
|
|
1830
|
-
function _ecdsa_legacy_opts_to_new(c) {
|
|
1831
|
-
const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c);
|
|
1832
|
-
const ecdsaOpts = {
|
|
1833
|
-
hash: c.hash,
|
|
1834
|
-
hmac: c.hmac,
|
|
1835
|
-
randomBytes: c.randomBytes,
|
|
1836
|
-
lowS: c.lowS,
|
|
1837
|
-
bits2int: c.bits2int,
|
|
1838
|
-
bits2int_modN: c.bits2int_modN
|
|
1839
|
-
};
|
|
1840
|
-
return { CURVE, curveOpts, ecdsaOpts };
|
|
1841
|
-
}
|
|
1842
|
-
function _ecdsa_new_output_to_legacy(c, ecdsa2) {
|
|
1843
|
-
return Object.assign({}, ecdsa2, {
|
|
1844
|
-
ProjectivePoint: ecdsa2.Point,
|
|
1845
|
-
CURVE: c
|
|
1846
|
-
});
|
|
1847
|
-
}
|
|
1848
|
-
function weierstrass(c) {
|
|
1849
|
-
const { CURVE, curveOpts, ecdsaOpts } = _ecdsa_legacy_opts_to_new(c);
|
|
1850
|
-
const Point2 = weierstrassN(CURVE, curveOpts);
|
|
1851
|
-
const signs = ecdsa(Point2, ecdsaOpts, curveOpts);
|
|
1852
|
-
return _ecdsa_new_output_to_legacy(c, signs);
|
|
1853
|
-
}
|
|
1854
|
-
function SWUFpSqrtRatio(Fp, Z) {
|
|
1855
|
-
const q = Fp.ORDER;
|
|
1856
|
-
let l = _0n3;
|
|
1857
|
-
for (let o = q - _1n3; o % _2n2 === _0n3; o /= _2n2)
|
|
1858
|
-
l += _1n3;
|
|
1859
|
-
const c1 = l;
|
|
1860
|
-
const _2n_pow_c1_1 = _2n2 << c1 - _1n3 - _1n3;
|
|
1861
|
-
const _2n_pow_c1 = _2n_pow_c1_1 * _2n2;
|
|
1862
|
-
const c2 = (q - _1n3) / _2n_pow_c1;
|
|
1863
|
-
const c3 = (c2 - _1n3) / _2n2;
|
|
1864
|
-
const c4 = _2n_pow_c1 - _1n3;
|
|
1865
|
-
const c5 = _2n_pow_c1_1;
|
|
1866
|
-
const c6 = Fp.pow(Z, c2);
|
|
1867
|
-
const c7 = Fp.pow(Z, (c2 + _1n3) / _2n2);
|
|
1868
|
-
let sqrtRatio = (u, v) => {
|
|
1869
|
-
let tv1 = c6;
|
|
1870
|
-
let tv2 = Fp.pow(v, c4);
|
|
1871
|
-
let tv3 = Fp.sqr(tv2);
|
|
1872
|
-
tv3 = Fp.mul(tv3, v);
|
|
1873
|
-
let tv5 = Fp.mul(u, tv3);
|
|
1874
|
-
tv5 = Fp.pow(tv5, c3);
|
|
1875
|
-
tv5 = Fp.mul(tv5, tv2);
|
|
1876
|
-
tv2 = Fp.mul(tv5, v);
|
|
1877
|
-
tv3 = Fp.mul(tv5, u);
|
|
1878
|
-
let tv4 = Fp.mul(tv3, tv2);
|
|
1879
|
-
tv5 = Fp.pow(tv4, c5);
|
|
1880
|
-
let isQR = Fp.eql(tv5, Fp.ONE);
|
|
1881
|
-
tv2 = Fp.mul(tv3, c7);
|
|
1882
|
-
tv5 = Fp.mul(tv4, tv1);
|
|
1883
|
-
tv3 = Fp.cmov(tv2, tv3, isQR);
|
|
1884
|
-
tv4 = Fp.cmov(tv5, tv4, isQR);
|
|
1885
|
-
for (let i = c1; i > _1n3; i--) {
|
|
1886
|
-
let tv52 = i - _2n2;
|
|
1887
|
-
tv52 = _2n2 << tv52 - _1n3;
|
|
1888
|
-
let tvv5 = Fp.pow(tv4, tv52);
|
|
1889
|
-
const e1 = Fp.eql(tvv5, Fp.ONE);
|
|
1890
|
-
tv2 = Fp.mul(tv3, tv1);
|
|
1891
|
-
tv1 = Fp.mul(tv1, tv1);
|
|
1892
|
-
tvv5 = Fp.mul(tv4, tv1);
|
|
1893
|
-
tv3 = Fp.cmov(tv2, tv3, e1);
|
|
1894
|
-
tv4 = Fp.cmov(tvv5, tv4, e1);
|
|
1895
|
-
}
|
|
1896
|
-
return { isValid: isQR, value: tv3 };
|
|
1897
|
-
};
|
|
1898
|
-
if (Fp.ORDER % _4n2 === _3n2) {
|
|
1899
|
-
const c12 = (Fp.ORDER - _3n2) / _4n2;
|
|
1900
|
-
const c22 = Fp.sqrt(Fp.neg(Z));
|
|
1901
|
-
sqrtRatio = (u, v) => {
|
|
1902
|
-
let tv1 = Fp.sqr(v);
|
|
1903
|
-
const tv2 = Fp.mul(u, v);
|
|
1904
|
-
tv1 = Fp.mul(tv1, tv2);
|
|
1905
|
-
let y1 = Fp.pow(tv1, c12);
|
|
1906
|
-
y1 = Fp.mul(y1, tv2);
|
|
1907
|
-
const y2 = Fp.mul(y1, c22);
|
|
1908
|
-
const tv3 = Fp.mul(Fp.sqr(y1), v);
|
|
1909
|
-
const isQR = Fp.eql(tv3, u);
|
|
1910
|
-
let y = Fp.cmov(y2, y1, isQR);
|
|
1911
|
-
return { isValid: isQR, value: y };
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
return sqrtRatio;
|
|
1915
|
-
}
|
|
1916
|
-
function mapToCurveSimpleSWU(Fp, opts) {
|
|
1917
|
-
validateField(Fp);
|
|
1918
|
-
const { A, B, Z } = opts;
|
|
1919
|
-
if (!Fp.isValid(A) || !Fp.isValid(B) || !Fp.isValid(Z))
|
|
1920
|
-
throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
1921
|
-
const sqrtRatio = SWUFpSqrtRatio(Fp, Z);
|
|
1922
|
-
if (!Fp.isOdd)
|
|
1923
|
-
throw new Error("Field does not have .isOdd()");
|
|
1924
|
-
return (u) => {
|
|
1925
|
-
let tv1, tv2, tv3, tv4, tv5, tv6, x, y;
|
|
1926
|
-
tv1 = Fp.sqr(u);
|
|
1927
|
-
tv1 = Fp.mul(tv1, Z);
|
|
1928
|
-
tv2 = Fp.sqr(tv1);
|
|
1929
|
-
tv2 = Fp.add(tv2, tv1);
|
|
1930
|
-
tv3 = Fp.add(tv2, Fp.ONE);
|
|
1931
|
-
tv3 = Fp.mul(tv3, B);
|
|
1932
|
-
tv4 = Fp.cmov(Z, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO));
|
|
1933
|
-
tv4 = Fp.mul(tv4, A);
|
|
1934
|
-
tv2 = Fp.sqr(tv3);
|
|
1935
|
-
tv6 = Fp.sqr(tv4);
|
|
1936
|
-
tv5 = Fp.mul(tv6, A);
|
|
1937
|
-
tv2 = Fp.add(tv2, tv5);
|
|
1938
|
-
tv2 = Fp.mul(tv2, tv3);
|
|
1939
|
-
tv6 = Fp.mul(tv6, tv4);
|
|
1940
|
-
tv5 = Fp.mul(tv6, B);
|
|
1941
|
-
tv2 = Fp.add(tv2, tv5);
|
|
1942
|
-
x = Fp.mul(tv1, tv3);
|
|
1943
|
-
const { isValid, value } = sqrtRatio(tv2, tv6);
|
|
1944
|
-
y = Fp.mul(tv1, u);
|
|
1945
|
-
y = Fp.mul(y, value);
|
|
1946
|
-
x = Fp.cmov(x, tv3, isValid);
|
|
1947
|
-
y = Fp.cmov(y, value, isValid);
|
|
1948
|
-
const e1 = Fp.isOdd(u) === Fp.isOdd(y);
|
|
1949
|
-
y = Fp.cmov(Fp.neg(y), y, e1);
|
|
1950
|
-
const tv4_inv = FpInvertBatch(Fp, [tv4], true)[0];
|
|
1951
|
-
x = Fp.mul(x, tv4_inv);
|
|
1952
|
-
return { x, y };
|
|
1953
|
-
};
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
// ../../node_modules/.pnpm/@noble+curves@1.9.2/node_modules/@noble/curves/esm/_shortw_utils.js
|
|
1957
|
-
function createCurve(curveDef, defHash) {
|
|
1958
|
-
const create = (hash) => weierstrass({ ...curveDef, hash });
|
|
1959
|
-
return { ...create(defHash), create };
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
// ../../node_modules/.pnpm/@noble+curves@1.9.2/node_modules/@noble/curves/esm/abstract/hash-to-curve.js
|
|
1963
|
-
var os2ip = bytesToNumberBE;
|
|
1964
|
-
function i2osp(value, length) {
|
|
1965
|
-
anum(value);
|
|
1966
|
-
anum(length);
|
|
1967
|
-
if (value < 0 || value >= 1 << 8 * length)
|
|
1968
|
-
throw new Error("invalid I2OSP input: " + value);
|
|
1969
|
-
const res = Array.from({ length }).fill(0);
|
|
1970
|
-
for (let i = length - 1; i >= 0; i--) {
|
|
1971
|
-
res[i] = value & 255;
|
|
1972
|
-
value >>>= 8;
|
|
1973
|
-
}
|
|
1974
|
-
return new Uint8Array(res);
|
|
1975
|
-
}
|
|
1976
|
-
function strxor(a, b) {
|
|
1977
|
-
const arr = new Uint8Array(a.length);
|
|
1978
|
-
for (let i = 0; i < a.length; i++) {
|
|
1979
|
-
arr[i] = a[i] ^ b[i];
|
|
1980
|
-
}
|
|
1981
|
-
return arr;
|
|
1982
|
-
}
|
|
1983
|
-
function anum(item) {
|
|
1984
|
-
if (!Number.isSafeInteger(item))
|
|
1985
|
-
throw new Error("number expected");
|
|
1986
|
-
}
|
|
1987
|
-
function expand_message_xmd(msg, DST, lenInBytes, H) {
|
|
1988
|
-
abytes(msg);
|
|
1989
|
-
abytes(DST);
|
|
1990
|
-
anum(lenInBytes);
|
|
1991
|
-
if (DST.length > 255)
|
|
1992
|
-
DST = H(concatBytes(utf8ToBytes("H2C-OVERSIZE-DST-"), DST));
|
|
1993
|
-
const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
|
|
1994
|
-
const ell = Math.ceil(lenInBytes / b_in_bytes);
|
|
1995
|
-
if (lenInBytes > 65535 || ell > 255)
|
|
1996
|
-
throw new Error("expand_message_xmd: invalid lenInBytes");
|
|
1997
|
-
const DST_prime = concatBytes(DST, i2osp(DST.length, 1));
|
|
1998
|
-
const Z_pad = i2osp(0, r_in_bytes);
|
|
1999
|
-
const l_i_b_str = i2osp(lenInBytes, 2);
|
|
2000
|
-
const b = new Array(ell);
|
|
2001
|
-
const b_0 = H(concatBytes(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
|
|
2002
|
-
b[0] = H(concatBytes(b_0, i2osp(1, 1), DST_prime));
|
|
2003
|
-
for (let i = 1; i <= ell; i++) {
|
|
2004
|
-
const args = [strxor(b_0, b[i - 1]), i2osp(i + 1, 1), DST_prime];
|
|
2005
|
-
b[i] = H(concatBytes(...args));
|
|
2006
|
-
}
|
|
2007
|
-
const pseudo_random_bytes = concatBytes(...b);
|
|
2008
|
-
return pseudo_random_bytes.slice(0, lenInBytes);
|
|
2009
|
-
}
|
|
2010
|
-
function expand_message_xof(msg, DST, lenInBytes, k, H) {
|
|
2011
|
-
abytes(msg);
|
|
2012
|
-
abytes(DST);
|
|
2013
|
-
anum(lenInBytes);
|
|
2014
|
-
if (DST.length > 255) {
|
|
2015
|
-
const dkLen = Math.ceil(2 * k / 8);
|
|
2016
|
-
DST = H.create({ dkLen }).update(utf8ToBytes("H2C-OVERSIZE-DST-")).update(DST).digest();
|
|
2017
|
-
}
|
|
2018
|
-
if (lenInBytes > 65535 || DST.length > 255)
|
|
2019
|
-
throw new Error("expand_message_xof: invalid lenInBytes");
|
|
2020
|
-
return H.create({ dkLen: lenInBytes }).update(msg).update(i2osp(lenInBytes, 2)).update(DST).update(i2osp(DST.length, 1)).digest();
|
|
2021
|
-
}
|
|
2022
|
-
function hash_to_field(msg, count, options) {
|
|
2023
|
-
_validateObject(options, {
|
|
2024
|
-
p: "bigint",
|
|
2025
|
-
m: "number",
|
|
2026
|
-
k: "number",
|
|
2027
|
-
hash: "function"
|
|
2028
|
-
});
|
|
2029
|
-
const { p, k, m, hash, expand, DST: _DST } = options;
|
|
2030
|
-
if (!isBytes(_DST) && typeof _DST !== "string")
|
|
2031
|
-
throw new Error("DST must be string or uint8array");
|
|
2032
|
-
if (!isHash(options.hash))
|
|
2033
|
-
throw new Error("expected valid hash");
|
|
2034
|
-
abytes(msg);
|
|
2035
|
-
anum(count);
|
|
2036
|
-
const DST = typeof _DST === "string" ? utf8ToBytes(_DST) : _DST;
|
|
2037
|
-
const log2p = p.toString(2).length;
|
|
2038
|
-
const L = Math.ceil((log2p + k) / 8);
|
|
2039
|
-
const len_in_bytes = count * m * L;
|
|
2040
|
-
let prb;
|
|
2041
|
-
if (expand === "xmd") {
|
|
2042
|
-
prb = expand_message_xmd(msg, DST, len_in_bytes, hash);
|
|
2043
|
-
} else if (expand === "xof") {
|
|
2044
|
-
prb = expand_message_xof(msg, DST, len_in_bytes, k, hash);
|
|
2045
|
-
} else if (expand === "_internal_pass") {
|
|
2046
|
-
prb = msg;
|
|
2047
|
-
} else {
|
|
2048
|
-
throw new Error('expand must be "xmd" or "xof"');
|
|
2049
|
-
}
|
|
2050
|
-
const u = new Array(count);
|
|
2051
|
-
for (let i = 0; i < count; i++) {
|
|
2052
|
-
const e = new Array(m);
|
|
2053
|
-
for (let j = 0; j < m; j++) {
|
|
2054
|
-
const elm_offset = L * (j + i * m);
|
|
2055
|
-
const tv = prb.subarray(elm_offset, elm_offset + L);
|
|
2056
|
-
e[j] = mod(os2ip(tv), p);
|
|
2057
|
-
}
|
|
2058
|
-
u[i] = e;
|
|
2059
|
-
}
|
|
2060
|
-
return u;
|
|
2061
|
-
}
|
|
2062
|
-
function isogenyMap(field, map) {
|
|
2063
|
-
const coeff = map.map((i) => Array.from(i).reverse());
|
|
2064
|
-
return (x, y) => {
|
|
2065
|
-
const [xn, xd, yn, yd] = coeff.map((val) => val.reduce((acc, i) => field.add(field.mul(acc, x), i)));
|
|
2066
|
-
const [xd_inv, yd_inv] = FpInvertBatch(field, [xd, yd], true);
|
|
2067
|
-
x = field.mul(xn, xd_inv);
|
|
2068
|
-
y = field.mul(y, field.mul(yn, yd_inv));
|
|
2069
|
-
return { x, y };
|
|
2070
|
-
};
|
|
2071
|
-
}
|
|
2072
|
-
function createHasher2(Point2, mapToCurve, defaults) {
|
|
2073
|
-
if (typeof mapToCurve !== "function")
|
|
2074
|
-
throw new Error("mapToCurve() must be defined");
|
|
2075
|
-
function map(num2) {
|
|
2076
|
-
return Point2.fromAffine(mapToCurve(num2));
|
|
2077
|
-
}
|
|
2078
|
-
function clear(initial) {
|
|
2079
|
-
const P = initial.clearCofactor();
|
|
2080
|
-
if (P.equals(Point2.ZERO))
|
|
2081
|
-
return Point2.ZERO;
|
|
2082
|
-
P.assertValidity();
|
|
2083
|
-
return P;
|
|
2084
|
-
}
|
|
2085
|
-
return {
|
|
2086
|
-
defaults,
|
|
2087
|
-
hashToCurve(msg, options) {
|
|
2088
|
-
const dst = defaults.DST ? defaults.DST : {};
|
|
2089
|
-
const opts = Object.assign({}, defaults, dst, options);
|
|
2090
|
-
const u = hash_to_field(msg, 2, opts);
|
|
2091
|
-
const u0 = map(u[0]);
|
|
2092
|
-
const u1 = map(u[1]);
|
|
2093
|
-
return clear(u0.add(u1));
|
|
2094
|
-
},
|
|
2095
|
-
encodeToCurve(msg, options) {
|
|
2096
|
-
const dst = defaults.encodeDST ? defaults.encodeDST : {};
|
|
2097
|
-
const opts = Object.assign({}, defaults, dst, options);
|
|
2098
|
-
const u = hash_to_field(msg, 1, opts);
|
|
2099
|
-
return clear(map(u[0]));
|
|
2100
|
-
},
|
|
2101
|
-
/** See {@link H2CHasher} */
|
|
2102
|
-
mapToCurve(scalars) {
|
|
2103
|
-
if (!Array.isArray(scalars))
|
|
2104
|
-
throw new Error("expected array of bigints");
|
|
2105
|
-
for (const i of scalars)
|
|
2106
|
-
if (typeof i !== "bigint")
|
|
2107
|
-
throw new Error("expected array of bigints");
|
|
2108
|
-
return clear(map(scalars));
|
|
2109
|
-
}
|
|
2110
|
-
};
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
// ../../node_modules/.pnpm/@noble+curves@1.9.2/node_modules/@noble/curves/esm/secp256k1.js
|
|
2114
|
-
var secp256k1_CURVE = {
|
|
2115
|
-
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
2116
|
-
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
2117
|
-
h: BigInt(1),
|
|
2118
|
-
a: BigInt(0),
|
|
2119
|
-
b: BigInt(7),
|
|
2120
|
-
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
2121
|
-
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
2122
|
-
};
|
|
2123
|
-
var _0n4 = BigInt(0);
|
|
2124
|
-
var _1n4 = BigInt(1);
|
|
2125
|
-
var _2n3 = BigInt(2);
|
|
2126
|
-
var divNearest = (a, b) => (a + b / _2n3) / b;
|
|
2127
|
-
function sqrtMod(y) {
|
|
2128
|
-
const P = secp256k1_CURVE.p;
|
|
2129
|
-
const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
2130
|
-
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
2131
|
-
const b2 = y * y * y % P;
|
|
2132
|
-
const b3 = b2 * b2 * y % P;
|
|
2133
|
-
const b6 = pow2(b3, _3n3, P) * b3 % P;
|
|
2134
|
-
const b9 = pow2(b6, _3n3, P) * b3 % P;
|
|
2135
|
-
const b11 = pow2(b9, _2n3, P) * b2 % P;
|
|
2136
|
-
const b22 = pow2(b11, _11n, P) * b11 % P;
|
|
2137
|
-
const b44 = pow2(b22, _22n, P) * b22 % P;
|
|
2138
|
-
const b88 = pow2(b44, _44n, P) * b44 % P;
|
|
2139
|
-
const b176 = pow2(b88, _88n, P) * b88 % P;
|
|
2140
|
-
const b220 = pow2(b176, _44n, P) * b44 % P;
|
|
2141
|
-
const b223 = pow2(b220, _3n3, P) * b3 % P;
|
|
2142
|
-
const t1 = pow2(b223, _23n, P) * b22 % P;
|
|
2143
|
-
const t2 = pow2(t1, _6n, P) * b2 % P;
|
|
2144
|
-
const root = pow2(t2, _2n3, P);
|
|
2145
|
-
if (!Fpk1.eql(Fpk1.sqr(root), y))
|
|
2146
|
-
throw new Error("Cannot find square root");
|
|
2147
|
-
return root;
|
|
2148
|
-
}
|
|
2149
|
-
var Fpk1 = Field(secp256k1_CURVE.p, void 0, void 0, { sqrt: sqrtMod });
|
|
2150
|
-
var secp256k1 = createCurve({
|
|
2151
|
-
...secp256k1_CURVE,
|
|
2152
|
-
Fp: Fpk1,
|
|
2153
|
-
lowS: true,
|
|
2154
|
-
// Allow only low-S signatures by default in sign() and verify()
|
|
2155
|
-
endo: {
|
|
2156
|
-
// Endomorphism, see above
|
|
2157
|
-
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
2158
|
-
splitScalar: (k) => {
|
|
2159
|
-
const n = secp256k1_CURVE.n;
|
|
2160
|
-
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
|
2161
|
-
const b1 = -_1n4 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
|
2162
|
-
const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
|
2163
|
-
const b2 = a1;
|
|
2164
|
-
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
|
2165
|
-
const c1 = divNearest(b2 * k, n);
|
|
2166
|
-
const c2 = divNearest(-b1 * k, n);
|
|
2167
|
-
let k1 = mod(k - c1 * a1 - c2 * a2, n);
|
|
2168
|
-
let k2 = mod(-c1 * b1 - c2 * b2, n);
|
|
2169
|
-
const k1neg = k1 > POW_2_128;
|
|
2170
|
-
const k2neg = k2 > POW_2_128;
|
|
2171
|
-
if (k1neg)
|
|
2172
|
-
k1 = n - k1;
|
|
2173
|
-
if (k2neg)
|
|
2174
|
-
k2 = n - k2;
|
|
2175
|
-
if (k1 > POW_2_128 || k2 > POW_2_128) {
|
|
2176
|
-
throw new Error("splitScalar: Endomorphism failed, k=" + k);
|
|
2177
|
-
}
|
|
2178
|
-
return { k1neg, k1, k2neg, k2 };
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
}, sha256);
|
|
2182
|
-
var TAGGED_HASH_PREFIXES = {};
|
|
2183
|
-
function taggedHash(tag, ...messages) {
|
|
2184
|
-
let tagP = TAGGED_HASH_PREFIXES[tag];
|
|
2185
|
-
if (tagP === void 0) {
|
|
2186
|
-
const tagH = sha256(Uint8Array.from(tag, (c) => c.charCodeAt(0)));
|
|
2187
|
-
tagP = concatBytes(tagH, tagH);
|
|
2188
|
-
TAGGED_HASH_PREFIXES[tag] = tagP;
|
|
2189
|
-
}
|
|
2190
|
-
return sha256(concatBytes(tagP, ...messages));
|
|
2191
|
-
}
|
|
2192
|
-
var pointToBytes = (point) => point.toBytes(true).slice(1);
|
|
2193
|
-
var numTo32b = (n) => numberToBytesBE(n, 32);
|
|
2194
|
-
var modP = (x) => mod(x, secp256k1_CURVE.p);
|
|
2195
|
-
var modN = (x) => mod(x, secp256k1_CURVE.n);
|
|
2196
|
-
var Point = /* @__PURE__ */ (() => secp256k1.Point)();
|
|
2197
|
-
var hasEven = (y) => y % _2n3 === _0n4;
|
|
2198
|
-
function schnorrGetExtPubKey(priv) {
|
|
2199
|
-
let d_ = secp256k1.utils.normPrivateKeyToScalar(priv);
|
|
2200
|
-
let p = Point.fromPrivateKey(d_);
|
|
2201
|
-
const scalar = hasEven(p.y) ? d_ : modN(-d_);
|
|
2202
|
-
return { scalar, bytes: pointToBytes(p) };
|
|
2203
|
-
}
|
|
2204
|
-
function lift_x(x) {
|
|
2205
|
-
aInRange("x", x, _1n4, secp256k1_CURVE.p);
|
|
2206
|
-
const xx = modP(x * x);
|
|
2207
|
-
const c = modP(xx * x + BigInt(7));
|
|
2208
|
-
let y = sqrtMod(c);
|
|
2209
|
-
if (!hasEven(y))
|
|
2210
|
-
y = modP(-y);
|
|
2211
|
-
const p = Point.fromAffine({ x, y });
|
|
2212
|
-
p.assertValidity();
|
|
2213
|
-
return p;
|
|
2214
|
-
}
|
|
2215
|
-
var num = bytesToNumberBE;
|
|
2216
|
-
function challenge(...args) {
|
|
2217
|
-
return modN(num(taggedHash("BIP0340/challenge", ...args)));
|
|
2218
|
-
}
|
|
2219
|
-
function schnorrGetPublicKey(privateKey) {
|
|
2220
|
-
return schnorrGetExtPubKey(privateKey).bytes;
|
|
2221
|
-
}
|
|
2222
|
-
function schnorrSign(message, privateKey, auxRand = randomBytes(32)) {
|
|
2223
|
-
const m = ensureBytes("message", message);
|
|
2224
|
-
const { bytes: px, scalar: d } = schnorrGetExtPubKey(privateKey);
|
|
2225
|
-
const a = ensureBytes("auxRand", auxRand, 32);
|
|
2226
|
-
const t = numTo32b(d ^ num(taggedHash("BIP0340/aux", a)));
|
|
2227
|
-
const rand = taggedHash("BIP0340/nonce", t, px, m);
|
|
2228
|
-
const k_ = modN(num(rand));
|
|
2229
|
-
if (k_ === _0n4)
|
|
2230
|
-
throw new Error("sign failed: k is zero");
|
|
2231
|
-
const { bytes: rx, scalar: k } = schnorrGetExtPubKey(k_);
|
|
2232
|
-
const e = challenge(rx, px, m);
|
|
2233
|
-
const sig = new Uint8Array(64);
|
|
2234
|
-
sig.set(rx, 0);
|
|
2235
|
-
sig.set(numTo32b(modN(k + e * d)), 32);
|
|
2236
|
-
if (!schnorrVerify(sig, m, px))
|
|
2237
|
-
throw new Error("sign: Invalid signature produced");
|
|
2238
|
-
return sig;
|
|
2239
|
-
}
|
|
2240
|
-
function schnorrVerify(signature, message, publicKey) {
|
|
2241
|
-
const sig = ensureBytes("signature", signature, 64);
|
|
2242
|
-
const m = ensureBytes("message", message);
|
|
2243
|
-
const pub = ensureBytes("publicKey", publicKey, 32);
|
|
2244
|
-
try {
|
|
2245
|
-
const P = lift_x(num(pub));
|
|
2246
|
-
const r = num(sig.subarray(0, 32));
|
|
2247
|
-
if (!inRange(r, _1n4, secp256k1_CURVE.p))
|
|
2248
|
-
return false;
|
|
2249
|
-
const s = num(sig.subarray(32, 64));
|
|
2250
|
-
if (!inRange(s, _1n4, secp256k1_CURVE.n))
|
|
2251
|
-
return false;
|
|
2252
|
-
const e = challenge(numTo32b(r), pointToBytes(P), m);
|
|
2253
|
-
const R = Point.BASE.multiplyUnsafe(s).add(P.multiplyUnsafe(modN(-e)));
|
|
2254
|
-
const { x, y } = R.toAffine();
|
|
2255
|
-
if (R.is0() || !hasEven(y) || x !== r)
|
|
2256
|
-
return false;
|
|
2257
|
-
return true;
|
|
2258
|
-
} catch (error) {
|
|
2259
|
-
return false;
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
var schnorr = /* @__PURE__ */ (() => ({
|
|
2263
|
-
getPublicKey: schnorrGetPublicKey,
|
|
2264
|
-
sign: schnorrSign,
|
|
2265
|
-
verify: schnorrVerify,
|
|
2266
|
-
utils: {
|
|
2267
|
-
randomPrivateKey: secp256k1.utils.randomPrivateKey,
|
|
2268
|
-
lift_x,
|
|
2269
|
-
pointToBytes,
|
|
2270
|
-
numberToBytesBE,
|
|
2271
|
-
bytesToNumberBE,
|
|
2272
|
-
taggedHash,
|
|
2273
|
-
mod
|
|
2274
|
-
}
|
|
2275
|
-
}))();
|
|
2276
|
-
var isoMap = /* @__PURE__ */ (() => isogenyMap(Fpk1, [
|
|
2277
|
-
// xNum
|
|
2278
|
-
[
|
|
2279
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
2280
|
-
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
2281
|
-
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
2282
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
2283
|
-
],
|
|
2284
|
-
// xDen
|
|
2285
|
-
[
|
|
2286
|
-
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
2287
|
-
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
2288
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
2289
|
-
// LAST 1
|
|
2290
|
-
],
|
|
2291
|
-
// yNum
|
|
2292
|
-
[
|
|
2293
|
-
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
2294
|
-
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
2295
|
-
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
2296
|
-
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
2297
|
-
],
|
|
2298
|
-
// yDen
|
|
2299
|
-
[
|
|
2300
|
-
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
2301
|
-
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
2302
|
-
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
2303
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
2304
|
-
// LAST 1
|
|
2305
|
-
]
|
|
2306
|
-
].map((i) => i.map((j) => BigInt(j)))))();
|
|
2307
|
-
var mapSWU = /* @__PURE__ */ (() => mapToCurveSimpleSWU(Fpk1, {
|
|
2308
|
-
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
2309
|
-
B: BigInt("1771"),
|
|
2310
|
-
Z: Fpk1.create(BigInt("-11"))
|
|
2311
|
-
}))();
|
|
2312
|
-
var secp256k1_hasher = /* @__PURE__ */ (() => createHasher2(secp256k1.Point, (scalars) => {
|
|
2313
|
-
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
2314
|
-
return isoMap(x, y);
|
|
2315
|
-
}, {
|
|
2316
|
-
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
2317
|
-
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
2318
|
-
p: Fpk1.ORDER,
|
|
2319
|
-
m: 1,
|
|
2320
|
-
k: 128,
|
|
2321
|
-
expand: "xmd",
|
|
2322
|
-
hash: sha256
|
|
2323
|
-
}))();
|
|
2324
|
-
var hashToCurve = /* @__PURE__ */ (() => secp256k1_hasher.hashToCurve)();
|
|
2325
|
-
var encodeToCurve = /* @__PURE__ */ (() => secp256k1_hasher.encodeToCurve)();
|
|
2326
|
-
|
|
2327
|
-
export {
|
|
2328
|
-
sha256,
|
|
2329
|
-
secp256k1,
|
|
2330
|
-
schnorr,
|
|
2331
|
-
secp256k1_hasher,
|
|
2332
|
-
hashToCurve,
|
|
2333
|
-
encodeToCurve
|
|
2334
|
-
};
|
|
2335
|
-
/*! Bundled license information:
|
|
2336
|
-
|
|
2337
|
-
@noble/curves/esm/abstract/modular.js:
|
|
2338
|
-
@noble/curves/esm/abstract/curve.js:
|
|
2339
|
-
@noble/curves/esm/abstract/weierstrass.js:
|
|
2340
|
-
@noble/curves/esm/_shortw_utils.js:
|
|
2341
|
-
@noble/curves/esm/secp256k1.js:
|
|
2342
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2343
|
-
*/
|