@sentio/sdk 2.57.12-rc.f → 2.57.12-rc.g
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/lib/{chunk-FDFFHCFA.js → chunk-2F2KNF4Z.js} +16113 -3887
- package/lib/chunk-2F2KNF4Z.js.map +1 -0
- package/lib/{chunk-QT2RHOVE.js → chunk-4HPFNKDX.js} +76 -146
- package/lib/chunk-4HPFNKDX.js.map +1 -0
- package/lib/{chunk-3NTVNR24.js → chunk-4OCWUYSJ.js} +2 -2
- package/lib/{chunk-M2LXR3BO.js → chunk-73SHERGU.js} +968 -1459
- package/lib/chunk-73SHERGU.js.map +1 -0
- package/lib/{chunk-MNZ4WYMA.js → chunk-7ECRTQD7.js} +2900 -3012
- package/lib/chunk-7ECRTQD7.js.map +1 -0
- package/lib/{chunk-2S4VBXER.js → chunk-7S6WQ4RL.js} +3 -3
- package/lib/{chunk-FTNDYH4A.js → chunk-AZFMPZRN.js} +200 -418
- package/lib/chunk-AZFMPZRN.js.map +1 -0
- package/lib/{chunk-QSUUYUJL.js → chunk-BZCXYTDE.js} +3 -3
- package/lib/{chunk-Q52U5JD3.js → chunk-E2DS6WZF.js} +14 -14
- package/lib/{chunk-Q52U5JD3.js.map → chunk-E2DS6WZF.js.map} +1 -1
- package/lib/{chunk-QUMTLHC5.js → chunk-GE6BRIGS.js} +5 -5
- package/lib/{chunk-MERD27M6.js → chunk-J3I3VNTV.js} +3 -3
- package/lib/{chunk-NMHIV5TJ.js → chunk-J3QOJ2RV.js} +4 -4
- package/lib/{chunk-BRHYXWEW.js → chunk-LPSNAS2G.js} +3 -3
- package/lib/chunk-LR232ZJV.js +2593 -0
- package/lib/chunk-LR232ZJV.js.map +1 -0
- package/lib/{chunk-TOXC2A6K.js → chunk-N36N7RXJ.js} +3 -3
- package/lib/{chunk-FLCIAA4G.js → chunk-OJG2VJ5T.js} +5 -5
- package/lib/{chunk-FLCIAA4G.js.map → chunk-OJG2VJ5T.js.map} +1 -1
- package/lib/{chunk-U5FYYK4Y.js → chunk-ONBEMKI5.js} +2 -2
- package/lib/{chunk-IGFULPWN.js → chunk-PVX2LIM5.js} +4 -4
- package/lib/{chunk-ZAY2PRBU.js → chunk-RMT2JEWA.js} +37 -37
- package/lib/{chunk-ZAY2PRBU.js.map → chunk-RMT2JEWA.js.map} +1 -1
- package/lib/{chunk-VWXVCB2D.js → chunk-S6MJ3KIL.js} +269 -384
- package/lib/chunk-S6MJ3KIL.js.map +1 -0
- package/lib/{chunk-FV4WLDIZ.js → chunk-UIBPOKNT.js} +16 -16
- package/lib/chunk-UIBPOKNT.js.map +1 -0
- package/package.json +3 -3
- package/lib/chunk-FDFFHCFA.js.map +0 -1
- package/lib/chunk-FTNDYH4A.js.map +0 -1
- package/lib/chunk-FV4WLDIZ.js.map +0 -1
- package/lib/chunk-M2LXR3BO.js.map +0 -1
- package/lib/chunk-MNZ4WYMA.js.map +0 -1
- package/lib/chunk-QT2RHOVE.js.map +0 -1
- package/lib/chunk-VWXVCB2D.js.map +0 -1
- /package/lib/{chunk-3NTVNR24.js.map → chunk-4OCWUYSJ.js.map} +0 -0
- /package/lib/{chunk-2S4VBXER.js.map → chunk-7S6WQ4RL.js.map} +0 -0
- /package/lib/{chunk-QSUUYUJL.js.map → chunk-BZCXYTDE.js.map} +0 -0
- /package/lib/{chunk-QUMTLHC5.js.map → chunk-GE6BRIGS.js.map} +0 -0
- /package/lib/{chunk-MERD27M6.js.map → chunk-J3I3VNTV.js.map} +0 -0
- /package/lib/{chunk-NMHIV5TJ.js.map → chunk-J3QOJ2RV.js.map} +0 -0
- /package/lib/{chunk-BRHYXWEW.js.map → chunk-LPSNAS2G.js.map} +0 -0
- /package/lib/{chunk-TOXC2A6K.js.map → chunk-N36N7RXJ.js.map} +0 -0
- /package/lib/{chunk-U5FYYK4Y.js.map → chunk-ONBEMKI5.js.map} +0 -0
- /package/lib/{chunk-IGFULPWN.js.map → chunk-PVX2LIM5.js.map} +0 -0
@@ -0,0 +1,2593 @@
|
|
1
|
+
import { createRequire as createRequireSdkShim } from 'module'; const require = createRequireSdkShim(import.meta.url);
|
2
|
+
import {
|
3
|
+
__export,
|
4
|
+
__name
|
5
|
+
} from "./chunk-R7PMHHKJ.js";
|
6
|
+
|
7
|
+
// ../../node_modules/.pnpm/@scure+base@1.1.7/node_modules/@scure/base/lib/esm/index.js
|
8
|
+
// @__NO_SIDE_EFFECTS__
|
9
|
+
function assertNumber(n) {
|
10
|
+
if (!Number.isSafeInteger(n))
|
11
|
+
throw new Error(`Wrong integer: ${n}`);
|
12
|
+
}
|
13
|
+
__name(assertNumber, "assertNumber");
|
14
|
+
function isBytes(a) {
|
15
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
16
|
+
}
|
17
|
+
__name(isBytes, "isBytes");
|
18
|
+
// @__NO_SIDE_EFFECTS__
|
19
|
+
function chain(...args) {
|
20
|
+
const id = /* @__PURE__ */ __name((a) => a, "id");
|
21
|
+
const wrap = /* @__PURE__ */ __name((a, b) => (c) => a(b(c)), "wrap");
|
22
|
+
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
23
|
+
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
24
|
+
return { encode, decode };
|
25
|
+
}
|
26
|
+
__name(chain, "chain");
|
27
|
+
// @__NO_SIDE_EFFECTS__
|
28
|
+
function alphabet(alphabet2) {
|
29
|
+
return {
|
30
|
+
encode: /* @__PURE__ */ __name((digits) => {
|
31
|
+
if (!Array.isArray(digits) || digits.length && typeof digits[0] !== "number")
|
32
|
+
throw new Error("alphabet.encode input should be an array of numbers");
|
33
|
+
return digits.map((i) => {
|
34
|
+
/* @__PURE__ */ assertNumber(i);
|
35
|
+
if (i < 0 || i >= alphabet2.length)
|
36
|
+
throw new Error(`Digit index outside alphabet: ${i} (alphabet: ${alphabet2.length})`);
|
37
|
+
return alphabet2[i];
|
38
|
+
});
|
39
|
+
}, "encode"),
|
40
|
+
decode: /* @__PURE__ */ __name((input) => {
|
41
|
+
if (!Array.isArray(input) || input.length && typeof input[0] !== "string")
|
42
|
+
throw new Error("alphabet.decode input should be array of strings");
|
43
|
+
return input.map((letter) => {
|
44
|
+
if (typeof letter !== "string")
|
45
|
+
throw new Error(`alphabet.decode: not string element=${letter}`);
|
46
|
+
const index = alphabet2.indexOf(letter);
|
47
|
+
if (index === -1)
|
48
|
+
throw new Error(`Unknown letter: "${letter}". Allowed: ${alphabet2}`);
|
49
|
+
return index;
|
50
|
+
});
|
51
|
+
}, "decode")
|
52
|
+
};
|
53
|
+
}
|
54
|
+
__name(alphabet, "alphabet");
|
55
|
+
// @__NO_SIDE_EFFECTS__
|
56
|
+
function join(separator = "") {
|
57
|
+
if (typeof separator !== "string")
|
58
|
+
throw new Error("join separator should be string");
|
59
|
+
return {
|
60
|
+
encode: /* @__PURE__ */ __name((from) => {
|
61
|
+
if (!Array.isArray(from) || from.length && typeof from[0] !== "string")
|
62
|
+
throw new Error("join.encode input should be array of strings");
|
63
|
+
for (let i of from)
|
64
|
+
if (typeof i !== "string")
|
65
|
+
throw new Error(`join.encode: non-string input=${i}`);
|
66
|
+
return from.join(separator);
|
67
|
+
}, "encode"),
|
68
|
+
decode: /* @__PURE__ */ __name((to) => {
|
69
|
+
if (typeof to !== "string")
|
70
|
+
throw new Error("join.decode input should be string");
|
71
|
+
return to.split(separator);
|
72
|
+
}, "decode")
|
73
|
+
};
|
74
|
+
}
|
75
|
+
__name(join, "join");
|
76
|
+
// @__NO_SIDE_EFFECTS__
|
77
|
+
function padding(bits, chr = "=") {
|
78
|
+
/* @__PURE__ */ assertNumber(bits);
|
79
|
+
if (typeof chr !== "string")
|
80
|
+
throw new Error("padding chr should be string");
|
81
|
+
return {
|
82
|
+
encode(data) {
|
83
|
+
if (!Array.isArray(data) || data.length && typeof data[0] !== "string")
|
84
|
+
throw new Error("padding.encode input should be array of strings");
|
85
|
+
for (let i of data)
|
86
|
+
if (typeof i !== "string")
|
87
|
+
throw new Error(`padding.encode: non-string input=${i}`);
|
88
|
+
while (data.length * bits % 8)
|
89
|
+
data.push(chr);
|
90
|
+
return data;
|
91
|
+
},
|
92
|
+
decode(input) {
|
93
|
+
if (!Array.isArray(input) || input.length && typeof input[0] !== "string")
|
94
|
+
throw new Error("padding.encode input should be array of strings");
|
95
|
+
for (let i of input)
|
96
|
+
if (typeof i !== "string")
|
97
|
+
throw new Error(`padding.decode: non-string input=${i}`);
|
98
|
+
let end = input.length;
|
99
|
+
if (end * bits % 8)
|
100
|
+
throw new Error("Invalid padding: string should have whole number of bytes");
|
101
|
+
for (; end > 0 && input[end - 1] === chr; end--) {
|
102
|
+
if (!((end - 1) * bits % 8))
|
103
|
+
throw new Error("Invalid padding: string has too much padding");
|
104
|
+
}
|
105
|
+
return input.slice(0, end);
|
106
|
+
}
|
107
|
+
};
|
108
|
+
}
|
109
|
+
__name(padding, "padding");
|
110
|
+
// @__NO_SIDE_EFFECTS__
|
111
|
+
function convertRadix(data, from, to) {
|
112
|
+
if (from < 2)
|
113
|
+
throw new Error(`convertRadix: wrong from=${from}, base cannot be less than 2`);
|
114
|
+
if (to < 2)
|
115
|
+
throw new Error(`convertRadix: wrong to=${to}, base cannot be less than 2`);
|
116
|
+
if (!Array.isArray(data))
|
117
|
+
throw new Error("convertRadix: data should be array");
|
118
|
+
if (!data.length)
|
119
|
+
return [];
|
120
|
+
let pos = 0;
|
121
|
+
const res = [];
|
122
|
+
const digits = Array.from(data);
|
123
|
+
digits.forEach((d) => {
|
124
|
+
/* @__PURE__ */ assertNumber(d);
|
125
|
+
if (d < 0 || d >= from)
|
126
|
+
throw new Error(`Wrong integer: ${d}`);
|
127
|
+
});
|
128
|
+
while (true) {
|
129
|
+
let carry = 0;
|
130
|
+
let done = true;
|
131
|
+
for (let i = pos; i < digits.length; i++) {
|
132
|
+
const digit = digits[i];
|
133
|
+
const digitBase = from * carry + digit;
|
134
|
+
if (!Number.isSafeInteger(digitBase) || from * carry / from !== carry || digitBase - digit !== from * carry) {
|
135
|
+
throw new Error("convertRadix: carry overflow");
|
136
|
+
}
|
137
|
+
carry = digitBase % to;
|
138
|
+
const rounded = Math.floor(digitBase / to);
|
139
|
+
digits[i] = rounded;
|
140
|
+
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
141
|
+
throw new Error("convertRadix: carry overflow");
|
142
|
+
if (!done)
|
143
|
+
continue;
|
144
|
+
else if (!rounded)
|
145
|
+
pos = i;
|
146
|
+
else
|
147
|
+
done = false;
|
148
|
+
}
|
149
|
+
res.push(carry);
|
150
|
+
if (done)
|
151
|
+
break;
|
152
|
+
}
|
153
|
+
for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
|
154
|
+
res.push(0);
|
155
|
+
return res.reverse();
|
156
|
+
}
|
157
|
+
__name(convertRadix, "convertRadix");
|
158
|
+
var gcd = /* @__PURE__ */ __name(/* @__NO_SIDE_EFFECTS__ */ (a, b) => !b ? a : /* @__PURE__ */ gcd(b, a % b), "gcd");
|
159
|
+
var radix2carry = /* @__PURE__ */ __name(/* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - /* @__PURE__ */ gcd(from, to)), "radix2carry");
|
160
|
+
// @__NO_SIDE_EFFECTS__
|
161
|
+
function convertRadix2(data, from, to, padding2) {
|
162
|
+
if (!Array.isArray(data))
|
163
|
+
throw new Error("convertRadix2: data should be array");
|
164
|
+
if (from <= 0 || from > 32)
|
165
|
+
throw new Error(`convertRadix2: wrong from=${from}`);
|
166
|
+
if (to <= 0 || to > 32)
|
167
|
+
throw new Error(`convertRadix2: wrong to=${to}`);
|
168
|
+
if (/* @__PURE__ */ radix2carry(from, to) > 32) {
|
169
|
+
throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
170
|
+
}
|
171
|
+
let carry = 0;
|
172
|
+
let pos = 0;
|
173
|
+
const mask = 2 ** to - 1;
|
174
|
+
const res = [];
|
175
|
+
for (const n of data) {
|
176
|
+
/* @__PURE__ */ assertNumber(n);
|
177
|
+
if (n >= 2 ** from)
|
178
|
+
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
179
|
+
carry = carry << from | n;
|
180
|
+
if (pos + from > 32)
|
181
|
+
throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
182
|
+
pos += from;
|
183
|
+
for (; pos >= to; pos -= to)
|
184
|
+
res.push((carry >> pos - to & mask) >>> 0);
|
185
|
+
carry &= 2 ** pos - 1;
|
186
|
+
}
|
187
|
+
carry = carry << to - pos & mask;
|
188
|
+
if (!padding2 && pos >= from)
|
189
|
+
throw new Error("Excess padding");
|
190
|
+
if (!padding2 && carry)
|
191
|
+
throw new Error(`Non-zero padding: ${carry}`);
|
192
|
+
if (padding2 && pos > 0)
|
193
|
+
res.push(carry >>> 0);
|
194
|
+
return res;
|
195
|
+
}
|
196
|
+
__name(convertRadix2, "convertRadix2");
|
197
|
+
// @__NO_SIDE_EFFECTS__
|
198
|
+
function radix(num) {
|
199
|
+
/* @__PURE__ */ assertNumber(num);
|
200
|
+
return {
|
201
|
+
encode: /* @__PURE__ */ __name((bytes2) => {
|
202
|
+
if (!isBytes(bytes2))
|
203
|
+
throw new Error("radix.encode input should be Uint8Array");
|
204
|
+
return /* @__PURE__ */ convertRadix(Array.from(bytes2), 2 ** 8, num);
|
205
|
+
}, "encode"),
|
206
|
+
decode: /* @__PURE__ */ __name((digits) => {
|
207
|
+
if (!Array.isArray(digits) || digits.length && typeof digits[0] !== "number")
|
208
|
+
throw new Error("radix.decode input should be array of numbers");
|
209
|
+
return Uint8Array.from(/* @__PURE__ */ convertRadix(digits, num, 2 ** 8));
|
210
|
+
}, "decode")
|
211
|
+
};
|
212
|
+
}
|
213
|
+
__name(radix, "radix");
|
214
|
+
// @__NO_SIDE_EFFECTS__
|
215
|
+
function radix2(bits, revPadding = false) {
|
216
|
+
/* @__PURE__ */ assertNumber(bits);
|
217
|
+
if (bits <= 0 || bits > 32)
|
218
|
+
throw new Error("radix2: bits should be in (0..32]");
|
219
|
+
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
220
|
+
throw new Error("radix2: carry overflow");
|
221
|
+
return {
|
222
|
+
encode: /* @__PURE__ */ __name((bytes2) => {
|
223
|
+
if (!isBytes(bytes2))
|
224
|
+
throw new Error("radix2.encode input should be Uint8Array");
|
225
|
+
return /* @__PURE__ */ convertRadix2(Array.from(bytes2), 8, bits, !revPadding);
|
226
|
+
}, "encode"),
|
227
|
+
decode: /* @__PURE__ */ __name((digits) => {
|
228
|
+
if (!Array.isArray(digits) || digits.length && typeof digits[0] !== "number")
|
229
|
+
throw new Error("radix2.decode input should be array of numbers");
|
230
|
+
return Uint8Array.from(/* @__PURE__ */ convertRadix2(digits, bits, 8, revPadding));
|
231
|
+
}, "decode")
|
232
|
+
};
|
233
|
+
}
|
234
|
+
__name(radix2, "radix2");
|
235
|
+
// @__NO_SIDE_EFFECTS__
|
236
|
+
function checksum(len, fn) {
|
237
|
+
/* @__PURE__ */ assertNumber(len);
|
238
|
+
if (typeof fn !== "function")
|
239
|
+
throw new Error("checksum fn should be function");
|
240
|
+
return {
|
241
|
+
encode(data) {
|
242
|
+
if (!isBytes(data))
|
243
|
+
throw new Error("checksum.encode: input should be Uint8Array");
|
244
|
+
const checksum2 = fn(data).slice(0, len);
|
245
|
+
const res = new Uint8Array(data.length + len);
|
246
|
+
res.set(data);
|
247
|
+
res.set(checksum2, data.length);
|
248
|
+
return res;
|
249
|
+
},
|
250
|
+
decode(data) {
|
251
|
+
if (!isBytes(data))
|
252
|
+
throw new Error("checksum.decode: input should be Uint8Array");
|
253
|
+
const payload = data.slice(0, -len);
|
254
|
+
const newChecksum = fn(payload).slice(0, len);
|
255
|
+
const oldChecksum = data.slice(-len);
|
256
|
+
for (let i = 0; i < len; i++)
|
257
|
+
if (newChecksum[i] !== oldChecksum[i])
|
258
|
+
throw new Error("Invalid checksum");
|
259
|
+
return payload;
|
260
|
+
}
|
261
|
+
};
|
262
|
+
}
|
263
|
+
__name(checksum, "checksum");
|
264
|
+
var base64 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join(""));
|
265
|
+
var genBase58 = /* @__PURE__ */ __name((abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join("")), "genBase58");
|
266
|
+
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
267
|
+
var createBase58check = /* @__PURE__ */ __name((sha2562) => /* @__PURE__ */ chain(/* @__PURE__ */ checksum(4, (data) => sha2562(sha2562(data))), base58), "createBase58check");
|
268
|
+
|
269
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/utils.js
|
270
|
+
var utils_exports = {};
|
271
|
+
__export(utils_exports, {
|
272
|
+
abytes: () => abytes,
|
273
|
+
bitGet: () => bitGet,
|
274
|
+
bitLen: () => bitLen,
|
275
|
+
bitMask: () => bitMask,
|
276
|
+
bitSet: () => bitSet,
|
277
|
+
bytesToHex: () => bytesToHex,
|
278
|
+
bytesToNumberBE: () => bytesToNumberBE,
|
279
|
+
bytesToNumberLE: () => bytesToNumberLE,
|
280
|
+
concatBytes: () => concatBytes,
|
281
|
+
createHmacDrbg: () => createHmacDrbg,
|
282
|
+
ensureBytes: () => ensureBytes,
|
283
|
+
equalBytes: () => equalBytes,
|
284
|
+
hexToBytes: () => hexToBytes,
|
285
|
+
hexToNumber: () => hexToNumber,
|
286
|
+
isBytes: () => isBytes2,
|
287
|
+
numberToBytesBE: () => numberToBytesBE,
|
288
|
+
numberToBytesLE: () => numberToBytesLE,
|
289
|
+
numberToHexUnpadded: () => numberToHexUnpadded,
|
290
|
+
numberToVarBytesBE: () => numberToVarBytesBE,
|
291
|
+
utf8ToBytes: () => utf8ToBytes,
|
292
|
+
validateObject: () => validateObject
|
293
|
+
});
|
294
|
+
var _0n = BigInt(0);
|
295
|
+
var _1n = BigInt(1);
|
296
|
+
var _2n = BigInt(2);
|
297
|
+
function isBytes2(a) {
|
298
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
299
|
+
}
|
300
|
+
__name(isBytes2, "isBytes");
|
301
|
+
function abytes(item) {
|
302
|
+
if (!isBytes2(item))
|
303
|
+
throw new Error("Uint8Array expected");
|
304
|
+
}
|
305
|
+
__name(abytes, "abytes");
|
306
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
307
|
+
function bytesToHex(bytes2) {
|
308
|
+
abytes(bytes2);
|
309
|
+
let hex = "";
|
310
|
+
for (let i = 0; i < bytes2.length; i++) {
|
311
|
+
hex += hexes[bytes2[i]];
|
312
|
+
}
|
313
|
+
return hex;
|
314
|
+
}
|
315
|
+
__name(bytesToHex, "bytesToHex");
|
316
|
+
function numberToHexUnpadded(num) {
|
317
|
+
const hex = num.toString(16);
|
318
|
+
return hex.length & 1 ? `0${hex}` : hex;
|
319
|
+
}
|
320
|
+
__name(numberToHexUnpadded, "numberToHexUnpadded");
|
321
|
+
function hexToNumber(hex) {
|
322
|
+
if (typeof hex !== "string")
|
323
|
+
throw new Error("hex string expected, got " + typeof hex);
|
324
|
+
return BigInt(hex === "" ? "0" : `0x${hex}`);
|
325
|
+
}
|
326
|
+
__name(hexToNumber, "hexToNumber");
|
327
|
+
var asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
|
328
|
+
function asciiToBase16(char) {
|
329
|
+
if (char >= asciis._0 && char <= asciis._9)
|
330
|
+
return char - asciis._0;
|
331
|
+
if (char >= asciis._A && char <= asciis._F)
|
332
|
+
return char - (asciis._A - 10);
|
333
|
+
if (char >= asciis._a && char <= asciis._f)
|
334
|
+
return char - (asciis._a - 10);
|
335
|
+
return;
|
336
|
+
}
|
337
|
+
__name(asciiToBase16, "asciiToBase16");
|
338
|
+
function hexToBytes(hex) {
|
339
|
+
if (typeof hex !== "string")
|
340
|
+
throw new Error("hex string expected, got " + typeof hex);
|
341
|
+
const hl = hex.length;
|
342
|
+
const al = hl / 2;
|
343
|
+
if (hl % 2)
|
344
|
+
throw new Error("padded hex string expected, got unpadded hex of length " + hl);
|
345
|
+
const array = new Uint8Array(al);
|
346
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
347
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
348
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
349
|
+
if (n1 === void 0 || n2 === void 0) {
|
350
|
+
const char = hex[hi] + hex[hi + 1];
|
351
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
352
|
+
}
|
353
|
+
array[ai] = n1 * 16 + n2;
|
354
|
+
}
|
355
|
+
return array;
|
356
|
+
}
|
357
|
+
__name(hexToBytes, "hexToBytes");
|
358
|
+
function bytesToNumberBE(bytes2) {
|
359
|
+
return hexToNumber(bytesToHex(bytes2));
|
360
|
+
}
|
361
|
+
__name(bytesToNumberBE, "bytesToNumberBE");
|
362
|
+
function bytesToNumberLE(bytes2) {
|
363
|
+
abytes(bytes2);
|
364
|
+
return hexToNumber(bytesToHex(Uint8Array.from(bytes2).reverse()));
|
365
|
+
}
|
366
|
+
__name(bytesToNumberLE, "bytesToNumberLE");
|
367
|
+
function numberToBytesBE(n, len) {
|
368
|
+
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
369
|
+
}
|
370
|
+
__name(numberToBytesBE, "numberToBytesBE");
|
371
|
+
function numberToBytesLE(n, len) {
|
372
|
+
return numberToBytesBE(n, len).reverse();
|
373
|
+
}
|
374
|
+
__name(numberToBytesLE, "numberToBytesLE");
|
375
|
+
function numberToVarBytesBE(n) {
|
376
|
+
return hexToBytes(numberToHexUnpadded(n));
|
377
|
+
}
|
378
|
+
__name(numberToVarBytesBE, "numberToVarBytesBE");
|
379
|
+
function ensureBytes(title, hex, expectedLength) {
|
380
|
+
let res;
|
381
|
+
if (typeof hex === "string") {
|
382
|
+
try {
|
383
|
+
res = hexToBytes(hex);
|
384
|
+
} catch (e) {
|
385
|
+
throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
|
386
|
+
}
|
387
|
+
} else if (isBytes2(hex)) {
|
388
|
+
res = Uint8Array.from(hex);
|
389
|
+
} else {
|
390
|
+
throw new Error(`${title} must be hex string or Uint8Array`);
|
391
|
+
}
|
392
|
+
const len = res.length;
|
393
|
+
if (typeof expectedLength === "number" && len !== expectedLength)
|
394
|
+
throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
|
395
|
+
return res;
|
396
|
+
}
|
397
|
+
__name(ensureBytes, "ensureBytes");
|
398
|
+
function concatBytes(...arrays) {
|
399
|
+
let sum = 0;
|
400
|
+
for (let i = 0; i < arrays.length; i++) {
|
401
|
+
const a = arrays[i];
|
402
|
+
abytes(a);
|
403
|
+
sum += a.length;
|
404
|
+
}
|
405
|
+
const res = new Uint8Array(sum);
|
406
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
407
|
+
const a = arrays[i];
|
408
|
+
res.set(a, pad);
|
409
|
+
pad += a.length;
|
410
|
+
}
|
411
|
+
return res;
|
412
|
+
}
|
413
|
+
__name(concatBytes, "concatBytes");
|
414
|
+
function equalBytes(a, b) {
|
415
|
+
if (a.length !== b.length)
|
416
|
+
return false;
|
417
|
+
let diff = 0;
|
418
|
+
for (let i = 0; i < a.length; i++)
|
419
|
+
diff |= a[i] ^ b[i];
|
420
|
+
return diff === 0;
|
421
|
+
}
|
422
|
+
__name(equalBytes, "equalBytes");
|
423
|
+
function utf8ToBytes(str) {
|
424
|
+
if (typeof str !== "string")
|
425
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
426
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
427
|
+
}
|
428
|
+
__name(utf8ToBytes, "utf8ToBytes");
|
429
|
+
function bitLen(n) {
|
430
|
+
let len;
|
431
|
+
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
432
|
+
;
|
433
|
+
return len;
|
434
|
+
}
|
435
|
+
__name(bitLen, "bitLen");
|
436
|
+
function bitGet(n, pos) {
|
437
|
+
return n >> BigInt(pos) & _1n;
|
438
|
+
}
|
439
|
+
__name(bitGet, "bitGet");
|
440
|
+
function bitSet(n, pos, value) {
|
441
|
+
return n | (value ? _1n : _0n) << BigInt(pos);
|
442
|
+
}
|
443
|
+
__name(bitSet, "bitSet");
|
444
|
+
var bitMask = /* @__PURE__ */ __name((n) => (_2n << BigInt(n - 1)) - _1n, "bitMask");
|
445
|
+
var u8n = /* @__PURE__ */ __name((data) => new Uint8Array(data), "u8n");
|
446
|
+
var u8fr = /* @__PURE__ */ __name((arr) => Uint8Array.from(arr), "u8fr");
|
447
|
+
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
448
|
+
if (typeof hashLen !== "number" || hashLen < 2)
|
449
|
+
throw new Error("hashLen must be a number");
|
450
|
+
if (typeof qByteLen !== "number" || qByteLen < 2)
|
451
|
+
throw new Error("qByteLen must be a number");
|
452
|
+
if (typeof hmacFn !== "function")
|
453
|
+
throw new Error("hmacFn must be a function");
|
454
|
+
let v = u8n(hashLen);
|
455
|
+
let k = u8n(hashLen);
|
456
|
+
let i = 0;
|
457
|
+
const reset = /* @__PURE__ */ __name(() => {
|
458
|
+
v.fill(1);
|
459
|
+
k.fill(0);
|
460
|
+
i = 0;
|
461
|
+
}, "reset");
|
462
|
+
const h = /* @__PURE__ */ __name((...b) => hmacFn(k, v, ...b), "h");
|
463
|
+
const reseed = /* @__PURE__ */ __name((seed = u8n()) => {
|
464
|
+
k = h(u8fr([0]), seed);
|
465
|
+
v = h();
|
466
|
+
if (seed.length === 0)
|
467
|
+
return;
|
468
|
+
k = h(u8fr([1]), seed);
|
469
|
+
v = h();
|
470
|
+
}, "reseed");
|
471
|
+
const gen = /* @__PURE__ */ __name(() => {
|
472
|
+
if (i++ >= 1e3)
|
473
|
+
throw new Error("drbg: tried 1000 values");
|
474
|
+
let len = 0;
|
475
|
+
const out = [];
|
476
|
+
while (len < qByteLen) {
|
477
|
+
v = h();
|
478
|
+
const sl = v.slice();
|
479
|
+
out.push(sl);
|
480
|
+
len += v.length;
|
481
|
+
}
|
482
|
+
return concatBytes(...out);
|
483
|
+
}, "gen");
|
484
|
+
const genUntil = /* @__PURE__ */ __name((seed, pred) => {
|
485
|
+
reset();
|
486
|
+
reseed(seed);
|
487
|
+
let res = void 0;
|
488
|
+
while (!(res = pred(gen())))
|
489
|
+
reseed();
|
490
|
+
reset();
|
491
|
+
return res;
|
492
|
+
}, "genUntil");
|
493
|
+
return genUntil;
|
494
|
+
}
|
495
|
+
__name(createHmacDrbg, "createHmacDrbg");
|
496
|
+
var validatorFns = {
|
497
|
+
bigint: /* @__PURE__ */ __name((val) => typeof val === "bigint", "bigint"),
|
498
|
+
function: /* @__PURE__ */ __name((val) => typeof val === "function", "function"),
|
499
|
+
boolean: /* @__PURE__ */ __name((val) => typeof val === "boolean", "boolean"),
|
500
|
+
string: /* @__PURE__ */ __name((val) => typeof val === "string", "string"),
|
501
|
+
stringOrUint8Array: /* @__PURE__ */ __name((val) => typeof val === "string" || isBytes2(val), "stringOrUint8Array"),
|
502
|
+
isSafeInteger: /* @__PURE__ */ __name((val) => Number.isSafeInteger(val), "isSafeInteger"),
|
503
|
+
array: /* @__PURE__ */ __name((val) => Array.isArray(val), "array"),
|
504
|
+
field: /* @__PURE__ */ __name((val, object) => object.Fp.isValid(val), "field"),
|
505
|
+
hash: /* @__PURE__ */ __name((val) => typeof val === "function" && Number.isSafeInteger(val.outputLen), "hash")
|
506
|
+
};
|
507
|
+
function validateObject(object, validators, optValidators = {}) {
|
508
|
+
const checkField = /* @__PURE__ */ __name((fieldName, type, isOptional) => {
|
509
|
+
const checkVal = validatorFns[type];
|
510
|
+
if (typeof checkVal !== "function")
|
511
|
+
throw new Error(`Invalid validator "${type}", expected function`);
|
512
|
+
const val = object[fieldName];
|
513
|
+
if (isOptional && val === void 0)
|
514
|
+
return;
|
515
|
+
if (!checkVal(val, object)) {
|
516
|
+
throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
|
517
|
+
}
|
518
|
+
}, "checkField");
|
519
|
+
for (const [fieldName, type] of Object.entries(validators))
|
520
|
+
checkField(fieldName, type, false);
|
521
|
+
for (const [fieldName, type] of Object.entries(optValidators))
|
522
|
+
checkField(fieldName, type, true);
|
523
|
+
return object;
|
524
|
+
}
|
525
|
+
__name(validateObject, "validateObject");
|
526
|
+
|
527
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
528
|
+
var weierstrass_exports = {};
|
529
|
+
__export(weierstrass_exports, {
|
530
|
+
DER: () => DER,
|
531
|
+
SWUFpSqrtRatio: () => SWUFpSqrtRatio,
|
532
|
+
mapToCurveSimpleSWU: () => mapToCurveSimpleSWU,
|
533
|
+
weierstrass: () => weierstrass,
|
534
|
+
weierstrassPoints: () => weierstrassPoints
|
535
|
+
});
|
536
|
+
|
537
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/modular.js
|
538
|
+
var _0n2 = BigInt(0);
|
539
|
+
var _1n2 = BigInt(1);
|
540
|
+
var _2n2 = BigInt(2);
|
541
|
+
var _3n = BigInt(3);
|
542
|
+
var _4n = BigInt(4);
|
543
|
+
var _5n = BigInt(5);
|
544
|
+
var _8n = BigInt(8);
|
545
|
+
var _9n = BigInt(9);
|
546
|
+
var _16n = BigInt(16);
|
547
|
+
function mod(a, b) {
|
548
|
+
const result = a % b;
|
549
|
+
return result >= _0n2 ? result : b + result;
|
550
|
+
}
|
551
|
+
__name(mod, "mod");
|
552
|
+
function pow(num, power, modulo) {
|
553
|
+
if (modulo <= _0n2 || power < _0n2)
|
554
|
+
throw new Error("Expected power/modulo > 0");
|
555
|
+
if (modulo === _1n2)
|
556
|
+
return _0n2;
|
557
|
+
let res = _1n2;
|
558
|
+
while (power > _0n2) {
|
559
|
+
if (power & _1n2)
|
560
|
+
res = res * num % modulo;
|
561
|
+
num = num * num % modulo;
|
562
|
+
power >>= _1n2;
|
563
|
+
}
|
564
|
+
return res;
|
565
|
+
}
|
566
|
+
__name(pow, "pow");
|
567
|
+
function pow2(x, power, modulo) {
|
568
|
+
let res = x;
|
569
|
+
while (power-- > _0n2) {
|
570
|
+
res *= res;
|
571
|
+
res %= modulo;
|
572
|
+
}
|
573
|
+
return res;
|
574
|
+
}
|
575
|
+
__name(pow2, "pow2");
|
576
|
+
function invert(number2, modulo) {
|
577
|
+
if (number2 === _0n2 || modulo <= _0n2) {
|
578
|
+
throw new Error(`invert: expected positive integers, got n=${number2} mod=${modulo}`);
|
579
|
+
}
|
580
|
+
let a = mod(number2, modulo);
|
581
|
+
let b = modulo;
|
582
|
+
let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
|
583
|
+
while (a !== _0n2) {
|
584
|
+
const q = b / a;
|
585
|
+
const r = b % a;
|
586
|
+
const m = x - u * q;
|
587
|
+
const n = y - v * q;
|
588
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
589
|
+
}
|
590
|
+
const gcd2 = b;
|
591
|
+
if (gcd2 !== _1n2)
|
592
|
+
throw new Error("invert: does not exist");
|
593
|
+
return mod(x, modulo);
|
594
|
+
}
|
595
|
+
__name(invert, "invert");
|
596
|
+
function tonelliShanks(P) {
|
597
|
+
const legendreC = (P - _1n2) / _2n2;
|
598
|
+
let Q, S, Z;
|
599
|
+
for (Q = P - _1n2, S = 0; Q % _2n2 === _0n2; Q /= _2n2, S++)
|
600
|
+
;
|
601
|
+
for (Z = _2n2; Z < P && pow(Z, legendreC, P) !== P - _1n2; Z++)
|
602
|
+
;
|
603
|
+
if (S === 1) {
|
604
|
+
const p1div4 = (P + _1n2) / _4n;
|
605
|
+
return /* @__PURE__ */ __name(function tonelliFast(Fp2, n) {
|
606
|
+
const root = Fp2.pow(n, p1div4);
|
607
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
608
|
+
throw new Error("Cannot find square root");
|
609
|
+
return root;
|
610
|
+
}, "tonelliFast");
|
611
|
+
}
|
612
|
+
const Q1div2 = (Q + _1n2) / _2n2;
|
613
|
+
return /* @__PURE__ */ __name(function tonelliSlow(Fp2, n) {
|
614
|
+
if (Fp2.pow(n, legendreC) === Fp2.neg(Fp2.ONE))
|
615
|
+
throw new Error("Cannot find square root");
|
616
|
+
let r = S;
|
617
|
+
let g = Fp2.pow(Fp2.mul(Fp2.ONE, Z), Q);
|
618
|
+
let x = Fp2.pow(n, Q1div2);
|
619
|
+
let b = Fp2.pow(n, Q);
|
620
|
+
while (!Fp2.eql(b, Fp2.ONE)) {
|
621
|
+
if (Fp2.eql(b, Fp2.ZERO))
|
622
|
+
return Fp2.ZERO;
|
623
|
+
let m = 1;
|
624
|
+
for (let t2 = Fp2.sqr(b); m < r; m++) {
|
625
|
+
if (Fp2.eql(t2, Fp2.ONE))
|
626
|
+
break;
|
627
|
+
t2 = Fp2.sqr(t2);
|
628
|
+
}
|
629
|
+
const ge = Fp2.pow(g, _1n2 << BigInt(r - m - 1));
|
630
|
+
g = Fp2.sqr(ge);
|
631
|
+
x = Fp2.mul(x, ge);
|
632
|
+
b = Fp2.mul(b, g);
|
633
|
+
r = m;
|
634
|
+
}
|
635
|
+
return x;
|
636
|
+
}, "tonelliSlow");
|
637
|
+
}
|
638
|
+
__name(tonelliShanks, "tonelliShanks");
|
639
|
+
function FpSqrt(P) {
|
640
|
+
if (P % _4n === _3n) {
|
641
|
+
const p1div4 = (P + _1n2) / _4n;
|
642
|
+
return /* @__PURE__ */ __name(function sqrt3mod4(Fp2, n) {
|
643
|
+
const root = Fp2.pow(n, p1div4);
|
644
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
645
|
+
throw new Error("Cannot find square root");
|
646
|
+
return root;
|
647
|
+
}, "sqrt3mod4");
|
648
|
+
}
|
649
|
+
if (P % _8n === _5n) {
|
650
|
+
const c1 = (P - _5n) / _8n;
|
651
|
+
return /* @__PURE__ */ __name(function sqrt5mod8(Fp2, n) {
|
652
|
+
const n2 = Fp2.mul(n, _2n2);
|
653
|
+
const v = Fp2.pow(n2, c1);
|
654
|
+
const nv = Fp2.mul(n, v);
|
655
|
+
const i = Fp2.mul(Fp2.mul(nv, _2n2), v);
|
656
|
+
const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
|
657
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
658
|
+
throw new Error("Cannot find square root");
|
659
|
+
return root;
|
660
|
+
}, "sqrt5mod8");
|
661
|
+
}
|
662
|
+
if (P % _16n === _9n) {
|
663
|
+
}
|
664
|
+
return tonelliShanks(P);
|
665
|
+
}
|
666
|
+
__name(FpSqrt, "FpSqrt");
|
667
|
+
var FIELD_FIELDS = [
|
668
|
+
"create",
|
669
|
+
"isValid",
|
670
|
+
"is0",
|
671
|
+
"neg",
|
672
|
+
"inv",
|
673
|
+
"sqrt",
|
674
|
+
"sqr",
|
675
|
+
"eql",
|
676
|
+
"add",
|
677
|
+
"sub",
|
678
|
+
"mul",
|
679
|
+
"pow",
|
680
|
+
"div",
|
681
|
+
"addN",
|
682
|
+
"subN",
|
683
|
+
"mulN",
|
684
|
+
"sqrN"
|
685
|
+
];
|
686
|
+
function validateField(field) {
|
687
|
+
const initial = {
|
688
|
+
ORDER: "bigint",
|
689
|
+
MASK: "bigint",
|
690
|
+
BYTES: "isSafeInteger",
|
691
|
+
BITS: "isSafeInteger"
|
692
|
+
};
|
693
|
+
const opts = FIELD_FIELDS.reduce((map, val) => {
|
694
|
+
map[val] = "function";
|
695
|
+
return map;
|
696
|
+
}, initial);
|
697
|
+
return validateObject(field, opts);
|
698
|
+
}
|
699
|
+
__name(validateField, "validateField");
|
700
|
+
function FpPow(f, num, power) {
|
701
|
+
if (power < _0n2)
|
702
|
+
throw new Error("Expected power > 0");
|
703
|
+
if (power === _0n2)
|
704
|
+
return f.ONE;
|
705
|
+
if (power === _1n2)
|
706
|
+
return num;
|
707
|
+
let p = f.ONE;
|
708
|
+
let d = num;
|
709
|
+
while (power > _0n2) {
|
710
|
+
if (power & _1n2)
|
711
|
+
p = f.mul(p, d);
|
712
|
+
d = f.sqr(d);
|
713
|
+
power >>= _1n2;
|
714
|
+
}
|
715
|
+
return p;
|
716
|
+
}
|
717
|
+
__name(FpPow, "FpPow");
|
718
|
+
function FpInvertBatch(f, nums) {
|
719
|
+
const tmp = new Array(nums.length);
|
720
|
+
const lastMultiplied = nums.reduce((acc, num, i) => {
|
721
|
+
if (f.is0(num))
|
722
|
+
return acc;
|
723
|
+
tmp[i] = acc;
|
724
|
+
return f.mul(acc, num);
|
725
|
+
}, f.ONE);
|
726
|
+
const inverted = f.inv(lastMultiplied);
|
727
|
+
nums.reduceRight((acc, num, i) => {
|
728
|
+
if (f.is0(num))
|
729
|
+
return acc;
|
730
|
+
tmp[i] = f.mul(acc, tmp[i]);
|
731
|
+
return f.mul(acc, num);
|
732
|
+
}, inverted);
|
733
|
+
return tmp;
|
734
|
+
}
|
735
|
+
__name(FpInvertBatch, "FpInvertBatch");
|
736
|
+
function nLength(n, nBitLength) {
|
737
|
+
const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
|
738
|
+
const nByteLength = Math.ceil(_nBitLength / 8);
|
739
|
+
return { nBitLength: _nBitLength, nByteLength };
|
740
|
+
}
|
741
|
+
__name(nLength, "nLength");
|
742
|
+
function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
|
743
|
+
if (ORDER <= _0n2)
|
744
|
+
throw new Error(`Expected Field ORDER > 0, got ${ORDER}`);
|
745
|
+
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
746
|
+
if (BYTES > 2048)
|
747
|
+
throw new Error("Field lengths over 2048 bytes are not supported");
|
748
|
+
const sqrtP = FpSqrt(ORDER);
|
749
|
+
const f = Object.freeze({
|
750
|
+
ORDER,
|
751
|
+
BITS,
|
752
|
+
BYTES,
|
753
|
+
MASK: bitMask(BITS),
|
754
|
+
ZERO: _0n2,
|
755
|
+
ONE: _1n2,
|
756
|
+
create: /* @__PURE__ */ __name((num) => mod(num, ORDER), "create"),
|
757
|
+
isValid: /* @__PURE__ */ __name((num) => {
|
758
|
+
if (typeof num !== "bigint")
|
759
|
+
throw new Error(`Invalid field element: expected bigint, got ${typeof num}`);
|
760
|
+
return _0n2 <= num && num < ORDER;
|
761
|
+
}, "isValid"),
|
762
|
+
is0: /* @__PURE__ */ __name((num) => num === _0n2, "is0"),
|
763
|
+
isOdd: /* @__PURE__ */ __name((num) => (num & _1n2) === _1n2, "isOdd"),
|
764
|
+
neg: /* @__PURE__ */ __name((num) => mod(-num, ORDER), "neg"),
|
765
|
+
eql: /* @__PURE__ */ __name((lhs, rhs) => lhs === rhs, "eql"),
|
766
|
+
sqr: /* @__PURE__ */ __name((num) => mod(num * num, ORDER), "sqr"),
|
767
|
+
add: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs + rhs, ORDER), "add"),
|
768
|
+
sub: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs - rhs, ORDER), "sub"),
|
769
|
+
mul: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs * rhs, ORDER), "mul"),
|
770
|
+
pow: /* @__PURE__ */ __name((num, power) => FpPow(f, num, power), "pow"),
|
771
|
+
div: /* @__PURE__ */ __name((lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER), "div"),
|
772
|
+
// Same as above, but doesn't normalize
|
773
|
+
sqrN: /* @__PURE__ */ __name((num) => num * num, "sqrN"),
|
774
|
+
addN: /* @__PURE__ */ __name((lhs, rhs) => lhs + rhs, "addN"),
|
775
|
+
subN: /* @__PURE__ */ __name((lhs, rhs) => lhs - rhs, "subN"),
|
776
|
+
mulN: /* @__PURE__ */ __name((lhs, rhs) => lhs * rhs, "mulN"),
|
777
|
+
inv: /* @__PURE__ */ __name((num) => invert(num, ORDER), "inv"),
|
778
|
+
sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
|
779
|
+
invertBatch: /* @__PURE__ */ __name((lst) => FpInvertBatch(f, lst), "invertBatch"),
|
780
|
+
// TODO: do we really need constant cmov?
|
781
|
+
// We don't have const-time bigints anyway, so probably will be not very useful
|
782
|
+
cmov: /* @__PURE__ */ __name((a, b, c) => c ? b : a, "cmov"),
|
783
|
+
toBytes: /* @__PURE__ */ __name((num) => isLE2 ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES), "toBytes"),
|
784
|
+
fromBytes: /* @__PURE__ */ __name((bytes2) => {
|
785
|
+
if (bytes2.length !== BYTES)
|
786
|
+
throw new Error(`Fp.fromBytes: expected ${BYTES}, got ${bytes2.length}`);
|
787
|
+
return isLE2 ? bytesToNumberLE(bytes2) : bytesToNumberBE(bytes2);
|
788
|
+
}, "fromBytes")
|
789
|
+
});
|
790
|
+
return Object.freeze(f);
|
791
|
+
}
|
792
|
+
__name(Field, "Field");
|
793
|
+
function getFieldBytesLength(fieldOrder) {
|
794
|
+
if (typeof fieldOrder !== "bigint")
|
795
|
+
throw new Error("field order must be bigint");
|
796
|
+
const bitLength = fieldOrder.toString(2).length;
|
797
|
+
return Math.ceil(bitLength / 8);
|
798
|
+
}
|
799
|
+
__name(getFieldBytesLength, "getFieldBytesLength");
|
800
|
+
function getMinHashLength(fieldOrder) {
|
801
|
+
const length = getFieldBytesLength(fieldOrder);
|
802
|
+
return length + Math.ceil(length / 2);
|
803
|
+
}
|
804
|
+
__name(getMinHashLength, "getMinHashLength");
|
805
|
+
function mapHashToField(key, fieldOrder, isLE2 = false) {
|
806
|
+
const len = key.length;
|
807
|
+
const fieldLen = getFieldBytesLength(fieldOrder);
|
808
|
+
const minLen = getMinHashLength(fieldOrder);
|
809
|
+
if (len < 16 || len < minLen || len > 1024)
|
810
|
+
throw new Error(`expected ${minLen}-1024 bytes of input, got ${len}`);
|
811
|
+
const num = isLE2 ? bytesToNumberBE(key) : bytesToNumberLE(key);
|
812
|
+
const reduced = mod(num, fieldOrder - _1n2) + _1n2;
|
813
|
+
return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
814
|
+
}
|
815
|
+
__name(mapHashToField, "mapHashToField");
|
816
|
+
|
817
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/curve.js
|
818
|
+
var _0n3 = BigInt(0);
|
819
|
+
var _1n3 = BigInt(1);
|
820
|
+
function wNAF(c, bits) {
|
821
|
+
const constTimeNegate = /* @__PURE__ */ __name((condition, item) => {
|
822
|
+
const neg = item.negate();
|
823
|
+
return condition ? neg : item;
|
824
|
+
}, "constTimeNegate");
|
825
|
+
const opts = /* @__PURE__ */ __name((W) => {
|
826
|
+
const windows = Math.ceil(bits / W) + 1;
|
827
|
+
const windowSize = 2 ** (W - 1);
|
828
|
+
return { windows, windowSize };
|
829
|
+
}, "opts");
|
830
|
+
return {
|
831
|
+
constTimeNegate,
|
832
|
+
// non-const time multiplication ladder
|
833
|
+
unsafeLadder(elm, n) {
|
834
|
+
let p = c.ZERO;
|
835
|
+
let d = elm;
|
836
|
+
while (n > _0n3) {
|
837
|
+
if (n & _1n3)
|
838
|
+
p = p.add(d);
|
839
|
+
d = d.double();
|
840
|
+
n >>= _1n3;
|
841
|
+
}
|
842
|
+
return p;
|
843
|
+
},
|
844
|
+
/**
|
845
|
+
* Creates a wNAF precomputation window. Used for caching.
|
846
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
847
|
+
* Number of precomputed points depends on the curve size:
|
848
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
849
|
+
* - 𝑊 is the window size
|
850
|
+
* - 𝑛 is the bitlength of the curve order.
|
851
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
852
|
+
* @returns precomputed point tables flattened to a single array
|
853
|
+
*/
|
854
|
+
precomputeWindow(elm, W) {
|
855
|
+
const { windows, windowSize } = opts(W);
|
856
|
+
const points = [];
|
857
|
+
let p = elm;
|
858
|
+
let base = p;
|
859
|
+
for (let window = 0; window < windows; window++) {
|
860
|
+
base = p;
|
861
|
+
points.push(base);
|
862
|
+
for (let i = 1; i < windowSize; i++) {
|
863
|
+
base = base.add(p);
|
864
|
+
points.push(base);
|
865
|
+
}
|
866
|
+
p = base.double();
|
867
|
+
}
|
868
|
+
return points;
|
869
|
+
},
|
870
|
+
/**
|
871
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
872
|
+
* @param W window size
|
873
|
+
* @param precomputes precomputed tables
|
874
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
875
|
+
* @returns real and fake (for const-time) points
|
876
|
+
*/
|
877
|
+
wNAF(W, precomputes, n) {
|
878
|
+
const { windows, windowSize } = opts(W);
|
879
|
+
let p = c.ZERO;
|
880
|
+
let f = c.BASE;
|
881
|
+
const mask = BigInt(2 ** W - 1);
|
882
|
+
const maxNumber = 2 ** W;
|
883
|
+
const shiftBy = BigInt(W);
|
884
|
+
for (let window = 0; window < windows; window++) {
|
885
|
+
const offset = window * windowSize;
|
886
|
+
let wbits = Number(n & mask);
|
887
|
+
n >>= shiftBy;
|
888
|
+
if (wbits > windowSize) {
|
889
|
+
wbits -= maxNumber;
|
890
|
+
n += _1n3;
|
891
|
+
}
|
892
|
+
const offset1 = offset;
|
893
|
+
const offset2 = offset + Math.abs(wbits) - 1;
|
894
|
+
const cond1 = window % 2 !== 0;
|
895
|
+
const cond2 = wbits < 0;
|
896
|
+
if (wbits === 0) {
|
897
|
+
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
898
|
+
} else {
|
899
|
+
p = p.add(constTimeNegate(cond2, precomputes[offset2]));
|
900
|
+
}
|
901
|
+
}
|
902
|
+
return { p, f };
|
903
|
+
},
|
904
|
+
wNAFCached(P, precomputesMap, n, transform) {
|
905
|
+
const W = P._WINDOW_SIZE || 1;
|
906
|
+
let comp = precomputesMap.get(P);
|
907
|
+
if (!comp) {
|
908
|
+
comp = this.precomputeWindow(P, W);
|
909
|
+
if (W !== 1) {
|
910
|
+
precomputesMap.set(P, transform(comp));
|
911
|
+
}
|
912
|
+
}
|
913
|
+
return this.wNAF(W, comp, n);
|
914
|
+
}
|
915
|
+
};
|
916
|
+
}
|
917
|
+
__name(wNAF, "wNAF");
|
918
|
+
function validateBasic(curve) {
|
919
|
+
validateField(curve.Fp);
|
920
|
+
validateObject(curve, {
|
921
|
+
n: "bigint",
|
922
|
+
h: "bigint",
|
923
|
+
Gx: "field",
|
924
|
+
Gy: "field"
|
925
|
+
}, {
|
926
|
+
nBitLength: "isSafeInteger",
|
927
|
+
nByteLength: "isSafeInteger"
|
928
|
+
});
|
929
|
+
return Object.freeze({
|
930
|
+
...nLength(curve.n, curve.nBitLength),
|
931
|
+
...curve,
|
932
|
+
...{ p: curve.Fp.ORDER }
|
933
|
+
});
|
934
|
+
}
|
935
|
+
__name(validateBasic, "validateBasic");
|
936
|
+
|
937
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
938
|
+
function validatePointOpts(curve) {
|
939
|
+
const opts = validateBasic(curve);
|
940
|
+
validateObject(opts, {
|
941
|
+
a: "field",
|
942
|
+
b: "field"
|
943
|
+
}, {
|
944
|
+
allowedPrivateKeyLengths: "array",
|
945
|
+
wrapPrivateKey: "boolean",
|
946
|
+
isTorsionFree: "function",
|
947
|
+
clearCofactor: "function",
|
948
|
+
allowInfinityPoint: "boolean",
|
949
|
+
fromBytes: "function",
|
950
|
+
toBytes: "function"
|
951
|
+
});
|
952
|
+
const { endo, Fp: Fp2, a } = opts;
|
953
|
+
if (endo) {
|
954
|
+
if (!Fp2.eql(a, Fp2.ZERO)) {
|
955
|
+
throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
|
956
|
+
}
|
957
|
+
if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
|
958
|
+
throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
|
959
|
+
}
|
960
|
+
}
|
961
|
+
return Object.freeze({ ...opts });
|
962
|
+
}
|
963
|
+
__name(validatePointOpts, "validatePointOpts");
|
964
|
+
var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports;
|
965
|
+
var DER = {
|
966
|
+
// asn.1 DER encoding utils
|
967
|
+
Err: class DERErr extends Error {
|
968
|
+
static {
|
969
|
+
__name(this, "DERErr");
|
970
|
+
}
|
971
|
+
constructor(m = "") {
|
972
|
+
super(m);
|
973
|
+
}
|
974
|
+
},
|
975
|
+
_parseInt(data) {
|
976
|
+
const { Err: E } = DER;
|
977
|
+
if (data.length < 2 || data[0] !== 2)
|
978
|
+
throw new E("Invalid signature integer tag");
|
979
|
+
const len = data[1];
|
980
|
+
const res = data.subarray(2, len + 2);
|
981
|
+
if (!len || res.length !== len)
|
982
|
+
throw new E("Invalid signature integer: wrong length");
|
983
|
+
if (res[0] & 128)
|
984
|
+
throw new E("Invalid signature integer: negative");
|
985
|
+
if (res[0] === 0 && !(res[1] & 128))
|
986
|
+
throw new E("Invalid signature integer: unnecessary leading zero");
|
987
|
+
return { d: b2n(res), l: data.subarray(len + 2) };
|
988
|
+
},
|
989
|
+
toSig(hex) {
|
990
|
+
const { Err: E } = DER;
|
991
|
+
const data = typeof hex === "string" ? h2b(hex) : hex;
|
992
|
+
abytes(data);
|
993
|
+
let l = data.length;
|
994
|
+
if (l < 2 || data[0] != 48)
|
995
|
+
throw new E("Invalid signature tag");
|
996
|
+
if (data[1] !== l - 2)
|
997
|
+
throw new E("Invalid signature: incorrect length");
|
998
|
+
const { d: r, l: sBytes } = DER._parseInt(data.subarray(2));
|
999
|
+
const { d: s, l: rBytesLeft } = DER._parseInt(sBytes);
|
1000
|
+
if (rBytesLeft.length)
|
1001
|
+
throw new E("Invalid signature: left bytes after parsing");
|
1002
|
+
return { r, s };
|
1003
|
+
},
|
1004
|
+
hexFromSig(sig) {
|
1005
|
+
const slice = /* @__PURE__ */ __name((s2) => Number.parseInt(s2[0], 16) & 8 ? "00" + s2 : s2, "slice");
|
1006
|
+
const h = /* @__PURE__ */ __name((num) => {
|
1007
|
+
const hex = num.toString(16);
|
1008
|
+
return hex.length & 1 ? `0${hex}` : hex;
|
1009
|
+
}, "h");
|
1010
|
+
const s = slice(h(sig.s));
|
1011
|
+
const r = slice(h(sig.r));
|
1012
|
+
const shl = s.length / 2;
|
1013
|
+
const rhl = r.length / 2;
|
1014
|
+
const sl = h(shl);
|
1015
|
+
const rl = h(rhl);
|
1016
|
+
return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
|
1017
|
+
}
|
1018
|
+
};
|
1019
|
+
var _0n4 = BigInt(0);
|
1020
|
+
var _1n4 = BigInt(1);
|
1021
|
+
var _2n3 = BigInt(2);
|
1022
|
+
var _3n2 = BigInt(3);
|
1023
|
+
var _4n2 = BigInt(4);
|
1024
|
+
function weierstrassPoints(opts) {
|
1025
|
+
const CURVE = validatePointOpts(opts);
|
1026
|
+
const { Fp: Fp2 } = CURVE;
|
1027
|
+
const toBytes2 = CURVE.toBytes || ((_c, point, _isCompressed) => {
|
1028
|
+
const a = point.toAffine();
|
1029
|
+
return concatBytes(Uint8Array.from([4]), Fp2.toBytes(a.x), Fp2.toBytes(a.y));
|
1030
|
+
});
|
1031
|
+
const fromBytes = CURVE.fromBytes || ((bytes2) => {
|
1032
|
+
const tail = bytes2.subarray(1);
|
1033
|
+
const x = Fp2.fromBytes(tail.subarray(0, Fp2.BYTES));
|
1034
|
+
const y = Fp2.fromBytes(tail.subarray(Fp2.BYTES, 2 * Fp2.BYTES));
|
1035
|
+
return { x, y };
|
1036
|
+
});
|
1037
|
+
function weierstrassEquation(x) {
|
1038
|
+
const { a, b } = CURVE;
|
1039
|
+
const x2 = Fp2.sqr(x);
|
1040
|
+
const x3 = Fp2.mul(x2, x);
|
1041
|
+
return Fp2.add(Fp2.add(x3, Fp2.mul(x, a)), b);
|
1042
|
+
}
|
1043
|
+
__name(weierstrassEquation, "weierstrassEquation");
|
1044
|
+
if (!Fp2.eql(Fp2.sqr(CURVE.Gy), weierstrassEquation(CURVE.Gx)))
|
1045
|
+
throw new Error("bad generator point: equation left != right");
|
1046
|
+
function isWithinCurveOrder(num) {
|
1047
|
+
return typeof num === "bigint" && _0n4 < num && num < CURVE.n;
|
1048
|
+
}
|
1049
|
+
__name(isWithinCurveOrder, "isWithinCurveOrder");
|
1050
|
+
function assertGE(num) {
|
1051
|
+
if (!isWithinCurveOrder(num))
|
1052
|
+
throw new Error("Expected valid bigint: 0 < bigint < curve.n");
|
1053
|
+
}
|
1054
|
+
__name(assertGE, "assertGE");
|
1055
|
+
function normPrivateKeyToScalar(key) {
|
1056
|
+
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE;
|
1057
|
+
if (lengths && typeof key !== "bigint") {
|
1058
|
+
if (isBytes2(key))
|
1059
|
+
key = bytesToHex(key);
|
1060
|
+
if (typeof key !== "string" || !lengths.includes(key.length))
|
1061
|
+
throw new Error("Invalid key");
|
1062
|
+
key = key.padStart(nByteLength * 2, "0");
|
1063
|
+
}
|
1064
|
+
let num;
|
1065
|
+
try {
|
1066
|
+
num = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
|
1067
|
+
} catch (error) {
|
1068
|
+
throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
|
1069
|
+
}
|
1070
|
+
if (wrapPrivateKey)
|
1071
|
+
num = mod(num, n);
|
1072
|
+
assertGE(num);
|
1073
|
+
return num;
|
1074
|
+
}
|
1075
|
+
__name(normPrivateKeyToScalar, "normPrivateKeyToScalar");
|
1076
|
+
const pointPrecomputes = /* @__PURE__ */ new Map();
|
1077
|
+
function assertPrjPoint(other) {
|
1078
|
+
if (!(other instanceof Point2))
|
1079
|
+
throw new Error("ProjectivePoint expected");
|
1080
|
+
}
|
1081
|
+
__name(assertPrjPoint, "assertPrjPoint");
|
1082
|
+
class Point2 {
|
1083
|
+
static {
|
1084
|
+
__name(this, "Point");
|
1085
|
+
}
|
1086
|
+
constructor(px, py, pz) {
|
1087
|
+
this.px = px;
|
1088
|
+
this.py = py;
|
1089
|
+
this.pz = pz;
|
1090
|
+
if (px == null || !Fp2.isValid(px))
|
1091
|
+
throw new Error("x required");
|
1092
|
+
if (py == null || !Fp2.isValid(py))
|
1093
|
+
throw new Error("y required");
|
1094
|
+
if (pz == null || !Fp2.isValid(pz))
|
1095
|
+
throw new Error("z required");
|
1096
|
+
}
|
1097
|
+
// Does not validate if the point is on-curve.
|
1098
|
+
// Use fromHex instead, or call assertValidity() later.
|
1099
|
+
static fromAffine(p) {
|
1100
|
+
const { x, y } = p || {};
|
1101
|
+
if (!p || !Fp2.isValid(x) || !Fp2.isValid(y))
|
1102
|
+
throw new Error("invalid affine point");
|
1103
|
+
if (p instanceof Point2)
|
1104
|
+
throw new Error("projective point not allowed");
|
1105
|
+
const is0 = /* @__PURE__ */ __name((i) => Fp2.eql(i, Fp2.ZERO), "is0");
|
1106
|
+
if (is0(x) && is0(y))
|
1107
|
+
return Point2.ZERO;
|
1108
|
+
return new Point2(x, y, Fp2.ONE);
|
1109
|
+
}
|
1110
|
+
get x() {
|
1111
|
+
return this.toAffine().x;
|
1112
|
+
}
|
1113
|
+
get y() {
|
1114
|
+
return this.toAffine().y;
|
1115
|
+
}
|
1116
|
+
/**
|
1117
|
+
* Takes a bunch of Projective Points but executes only one
|
1118
|
+
* inversion on all of them. Inversion is very slow operation,
|
1119
|
+
* so this improves performance massively.
|
1120
|
+
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
1121
|
+
*/
|
1122
|
+
static normalizeZ(points) {
|
1123
|
+
const toInv = Fp2.invertBatch(points.map((p) => p.pz));
|
1124
|
+
return points.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
|
1125
|
+
}
|
1126
|
+
/**
|
1127
|
+
* Converts hash string or Uint8Array to Point.
|
1128
|
+
* @param hex short/long ECDSA hex
|
1129
|
+
*/
|
1130
|
+
static fromHex(hex) {
|
1131
|
+
const P = Point2.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
|
1132
|
+
P.assertValidity();
|
1133
|
+
return P;
|
1134
|
+
}
|
1135
|
+
// Multiplies generator point by privateKey.
|
1136
|
+
static fromPrivateKey(privateKey) {
|
1137
|
+
return Point2.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
1138
|
+
}
|
1139
|
+
// "Private method", don't use it directly
|
1140
|
+
_setWindowSize(windowSize) {
|
1141
|
+
this._WINDOW_SIZE = windowSize;
|
1142
|
+
pointPrecomputes.delete(this);
|
1143
|
+
}
|
1144
|
+
// A point on curve is valid if it conforms to equation.
|
1145
|
+
assertValidity() {
|
1146
|
+
if (this.is0()) {
|
1147
|
+
if (CURVE.allowInfinityPoint && !Fp2.is0(this.py))
|
1148
|
+
return;
|
1149
|
+
throw new Error("bad point: ZERO");
|
1150
|
+
}
|
1151
|
+
const { x, y } = this.toAffine();
|
1152
|
+
if (!Fp2.isValid(x) || !Fp2.isValid(y))
|
1153
|
+
throw new Error("bad point: x or y not FE");
|
1154
|
+
const left = Fp2.sqr(y);
|
1155
|
+
const right = weierstrassEquation(x);
|
1156
|
+
if (!Fp2.eql(left, right))
|
1157
|
+
throw new Error("bad point: equation left != right");
|
1158
|
+
if (!this.isTorsionFree())
|
1159
|
+
throw new Error("bad point: not in prime-order subgroup");
|
1160
|
+
}
|
1161
|
+
hasEvenY() {
|
1162
|
+
const { y } = this.toAffine();
|
1163
|
+
if (Fp2.isOdd)
|
1164
|
+
return !Fp2.isOdd(y);
|
1165
|
+
throw new Error("Field doesn't support isOdd");
|
1166
|
+
}
|
1167
|
+
/**
|
1168
|
+
* Compare one point to another.
|
1169
|
+
*/
|
1170
|
+
equals(other) {
|
1171
|
+
assertPrjPoint(other);
|
1172
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
1173
|
+
const { px: X2, py: Y2, pz: Z2 } = other;
|
1174
|
+
const U1 = Fp2.eql(Fp2.mul(X1, Z2), Fp2.mul(X2, Z1));
|
1175
|
+
const U2 = Fp2.eql(Fp2.mul(Y1, Z2), Fp2.mul(Y2, Z1));
|
1176
|
+
return U1 && U2;
|
1177
|
+
}
|
1178
|
+
/**
|
1179
|
+
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
1180
|
+
*/
|
1181
|
+
negate() {
|
1182
|
+
return new Point2(this.px, Fp2.neg(this.py), this.pz);
|
1183
|
+
}
|
1184
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
1185
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
1186
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
1187
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
1188
|
+
double() {
|
1189
|
+
const { a, b } = CURVE;
|
1190
|
+
const b3 = Fp2.mul(b, _3n2);
|
1191
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
1192
|
+
let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
|
1193
|
+
let t0 = Fp2.mul(X1, X1);
|
1194
|
+
let t1 = Fp2.mul(Y1, Y1);
|
1195
|
+
let t2 = Fp2.mul(Z1, Z1);
|
1196
|
+
let t3 = Fp2.mul(X1, Y1);
|
1197
|
+
t3 = Fp2.add(t3, t3);
|
1198
|
+
Z3 = Fp2.mul(X1, Z1);
|
1199
|
+
Z3 = Fp2.add(Z3, Z3);
|
1200
|
+
X3 = Fp2.mul(a, Z3);
|
1201
|
+
Y3 = Fp2.mul(b3, t2);
|
1202
|
+
Y3 = Fp2.add(X3, Y3);
|
1203
|
+
X3 = Fp2.sub(t1, Y3);
|
1204
|
+
Y3 = Fp2.add(t1, Y3);
|
1205
|
+
Y3 = Fp2.mul(X3, Y3);
|
1206
|
+
X3 = Fp2.mul(t3, X3);
|
1207
|
+
Z3 = Fp2.mul(b3, Z3);
|
1208
|
+
t2 = Fp2.mul(a, t2);
|
1209
|
+
t3 = Fp2.sub(t0, t2);
|
1210
|
+
t3 = Fp2.mul(a, t3);
|
1211
|
+
t3 = Fp2.add(t3, Z3);
|
1212
|
+
Z3 = Fp2.add(t0, t0);
|
1213
|
+
t0 = Fp2.add(Z3, t0);
|
1214
|
+
t0 = Fp2.add(t0, t2);
|
1215
|
+
t0 = Fp2.mul(t0, t3);
|
1216
|
+
Y3 = Fp2.add(Y3, t0);
|
1217
|
+
t2 = Fp2.mul(Y1, Z1);
|
1218
|
+
t2 = Fp2.add(t2, t2);
|
1219
|
+
t0 = Fp2.mul(t2, t3);
|
1220
|
+
X3 = Fp2.sub(X3, t0);
|
1221
|
+
Z3 = Fp2.mul(t2, t1);
|
1222
|
+
Z3 = Fp2.add(Z3, Z3);
|
1223
|
+
Z3 = Fp2.add(Z3, Z3);
|
1224
|
+
return new Point2(X3, Y3, Z3);
|
1225
|
+
}
|
1226
|
+
// Renes-Costello-Batina exception-free addition formula.
|
1227
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
1228
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
1229
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
1230
|
+
add(other) {
|
1231
|
+
assertPrjPoint(other);
|
1232
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
1233
|
+
const { px: X2, py: Y2, pz: Z2 } = other;
|
1234
|
+
let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
|
1235
|
+
const a = CURVE.a;
|
1236
|
+
const b3 = Fp2.mul(CURVE.b, _3n2);
|
1237
|
+
let t0 = Fp2.mul(X1, X2);
|
1238
|
+
let t1 = Fp2.mul(Y1, Y2);
|
1239
|
+
let t2 = Fp2.mul(Z1, Z2);
|
1240
|
+
let t3 = Fp2.add(X1, Y1);
|
1241
|
+
let t4 = Fp2.add(X2, Y2);
|
1242
|
+
t3 = Fp2.mul(t3, t4);
|
1243
|
+
t4 = Fp2.add(t0, t1);
|
1244
|
+
t3 = Fp2.sub(t3, t4);
|
1245
|
+
t4 = Fp2.add(X1, Z1);
|
1246
|
+
let t5 = Fp2.add(X2, Z2);
|
1247
|
+
t4 = Fp2.mul(t4, t5);
|
1248
|
+
t5 = Fp2.add(t0, t2);
|
1249
|
+
t4 = Fp2.sub(t4, t5);
|
1250
|
+
t5 = Fp2.add(Y1, Z1);
|
1251
|
+
X3 = Fp2.add(Y2, Z2);
|
1252
|
+
t5 = Fp2.mul(t5, X3);
|
1253
|
+
X3 = Fp2.add(t1, t2);
|
1254
|
+
t5 = Fp2.sub(t5, X3);
|
1255
|
+
Z3 = Fp2.mul(a, t4);
|
1256
|
+
X3 = Fp2.mul(b3, t2);
|
1257
|
+
Z3 = Fp2.add(X3, Z3);
|
1258
|
+
X3 = Fp2.sub(t1, Z3);
|
1259
|
+
Z3 = Fp2.add(t1, Z3);
|
1260
|
+
Y3 = Fp2.mul(X3, Z3);
|
1261
|
+
t1 = Fp2.add(t0, t0);
|
1262
|
+
t1 = Fp2.add(t1, t0);
|
1263
|
+
t2 = Fp2.mul(a, t2);
|
1264
|
+
t4 = Fp2.mul(b3, t4);
|
1265
|
+
t1 = Fp2.add(t1, t2);
|
1266
|
+
t2 = Fp2.sub(t0, t2);
|
1267
|
+
t2 = Fp2.mul(a, t2);
|
1268
|
+
t4 = Fp2.add(t4, t2);
|
1269
|
+
t0 = Fp2.mul(t1, t4);
|
1270
|
+
Y3 = Fp2.add(Y3, t0);
|
1271
|
+
t0 = Fp2.mul(t5, t4);
|
1272
|
+
X3 = Fp2.mul(t3, X3);
|
1273
|
+
X3 = Fp2.sub(X3, t0);
|
1274
|
+
t0 = Fp2.mul(t3, t1);
|
1275
|
+
Z3 = Fp2.mul(t5, Z3);
|
1276
|
+
Z3 = Fp2.add(Z3, t0);
|
1277
|
+
return new Point2(X3, Y3, Z3);
|
1278
|
+
}
|
1279
|
+
subtract(other) {
|
1280
|
+
return this.add(other.negate());
|
1281
|
+
}
|
1282
|
+
is0() {
|
1283
|
+
return this.equals(Point2.ZERO);
|
1284
|
+
}
|
1285
|
+
wNAF(n) {
|
1286
|
+
return wnaf.wNAFCached(this, pointPrecomputes, n, (comp) => {
|
1287
|
+
const toInv = Fp2.invertBatch(comp.map((p) => p.pz));
|
1288
|
+
return comp.map((p, i) => p.toAffine(toInv[i])).map(Point2.fromAffine);
|
1289
|
+
});
|
1290
|
+
}
|
1291
|
+
/**
|
1292
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
1293
|
+
* It's faster, but should only be used when you don't care about
|
1294
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
1295
|
+
*/
|
1296
|
+
multiplyUnsafe(n) {
|
1297
|
+
const I = Point2.ZERO;
|
1298
|
+
if (n === _0n4)
|
1299
|
+
return I;
|
1300
|
+
assertGE(n);
|
1301
|
+
if (n === _1n4)
|
1302
|
+
return this;
|
1303
|
+
const { endo } = CURVE;
|
1304
|
+
if (!endo)
|
1305
|
+
return wnaf.unsafeLadder(this, n);
|
1306
|
+
let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
|
1307
|
+
let k1p = I;
|
1308
|
+
let k2p = I;
|
1309
|
+
let d = this;
|
1310
|
+
while (k1 > _0n4 || k2 > _0n4) {
|
1311
|
+
if (k1 & _1n4)
|
1312
|
+
k1p = k1p.add(d);
|
1313
|
+
if (k2 & _1n4)
|
1314
|
+
k2p = k2p.add(d);
|
1315
|
+
d = d.double();
|
1316
|
+
k1 >>= _1n4;
|
1317
|
+
k2 >>= _1n4;
|
1318
|
+
}
|
1319
|
+
if (k1neg)
|
1320
|
+
k1p = k1p.negate();
|
1321
|
+
if (k2neg)
|
1322
|
+
k2p = k2p.negate();
|
1323
|
+
k2p = new Point2(Fp2.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
1324
|
+
return k1p.add(k2p);
|
1325
|
+
}
|
1326
|
+
/**
|
1327
|
+
* Constant time multiplication.
|
1328
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
1329
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
1330
|
+
* Uses precomputes when available.
|
1331
|
+
* Uses endomorphism for Koblitz curves.
|
1332
|
+
* @param scalar by which the point would be multiplied
|
1333
|
+
* @returns New point
|
1334
|
+
*/
|
1335
|
+
multiply(scalar) {
|
1336
|
+
assertGE(scalar);
|
1337
|
+
let n = scalar;
|
1338
|
+
let point, fake;
|
1339
|
+
const { endo } = CURVE;
|
1340
|
+
if (endo) {
|
1341
|
+
const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
|
1342
|
+
let { p: k1p, f: f1p } = this.wNAF(k1);
|
1343
|
+
let { p: k2p, f: f2p } = this.wNAF(k2);
|
1344
|
+
k1p = wnaf.constTimeNegate(k1neg, k1p);
|
1345
|
+
k2p = wnaf.constTimeNegate(k2neg, k2p);
|
1346
|
+
k2p = new Point2(Fp2.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
1347
|
+
point = k1p.add(k2p);
|
1348
|
+
fake = f1p.add(f2p);
|
1349
|
+
} else {
|
1350
|
+
const { p, f } = this.wNAF(n);
|
1351
|
+
point = p;
|
1352
|
+
fake = f;
|
1353
|
+
}
|
1354
|
+
return Point2.normalizeZ([point, fake])[0];
|
1355
|
+
}
|
1356
|
+
/**
|
1357
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
1358
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
1359
|
+
* The trick could be useful if both P and Q are not G (not in our case).
|
1360
|
+
* @returns non-zero affine point
|
1361
|
+
*/
|
1362
|
+
multiplyAndAddUnsafe(Q, a, b) {
|
1363
|
+
const G = Point2.BASE;
|
1364
|
+
const mul = /* @__PURE__ */ __name((P, a2) => a2 === _0n4 || a2 === _1n4 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2), "mul");
|
1365
|
+
const sum = mul(this, a).add(mul(Q, b));
|
1366
|
+
return sum.is0() ? void 0 : sum;
|
1367
|
+
}
|
1368
|
+
// Converts Projective point to affine (x, y) coordinates.
|
1369
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
1370
|
+
// (x, y, z) ∋ (x=x/z, y=y/z)
|
1371
|
+
toAffine(iz) {
|
1372
|
+
const { px: x, py: y, pz: z } = this;
|
1373
|
+
const is0 = this.is0();
|
1374
|
+
if (iz == null)
|
1375
|
+
iz = is0 ? Fp2.ONE : Fp2.inv(z);
|
1376
|
+
const ax = Fp2.mul(x, iz);
|
1377
|
+
const ay = Fp2.mul(y, iz);
|
1378
|
+
const zz = Fp2.mul(z, iz);
|
1379
|
+
if (is0)
|
1380
|
+
return { x: Fp2.ZERO, y: Fp2.ZERO };
|
1381
|
+
if (!Fp2.eql(zz, Fp2.ONE))
|
1382
|
+
throw new Error("invZ was invalid");
|
1383
|
+
return { x: ax, y: ay };
|
1384
|
+
}
|
1385
|
+
isTorsionFree() {
|
1386
|
+
const { h: cofactor, isTorsionFree } = CURVE;
|
1387
|
+
if (cofactor === _1n4)
|
1388
|
+
return true;
|
1389
|
+
if (isTorsionFree)
|
1390
|
+
return isTorsionFree(Point2, this);
|
1391
|
+
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
1392
|
+
}
|
1393
|
+
clearCofactor() {
|
1394
|
+
const { h: cofactor, clearCofactor } = CURVE;
|
1395
|
+
if (cofactor === _1n4)
|
1396
|
+
return this;
|
1397
|
+
if (clearCofactor)
|
1398
|
+
return clearCofactor(Point2, this);
|
1399
|
+
return this.multiplyUnsafe(CURVE.h);
|
1400
|
+
}
|
1401
|
+
toRawBytes(isCompressed = true) {
|
1402
|
+
this.assertValidity();
|
1403
|
+
return toBytes2(Point2, this, isCompressed);
|
1404
|
+
}
|
1405
|
+
toHex(isCompressed = true) {
|
1406
|
+
return bytesToHex(this.toRawBytes(isCompressed));
|
1407
|
+
}
|
1408
|
+
}
|
1409
|
+
Point2.BASE = new Point2(CURVE.Gx, CURVE.Gy, Fp2.ONE);
|
1410
|
+
Point2.ZERO = new Point2(Fp2.ZERO, Fp2.ONE, Fp2.ZERO);
|
1411
|
+
const _bits = CURVE.nBitLength;
|
1412
|
+
const wnaf = wNAF(Point2, CURVE.endo ? Math.ceil(_bits / 2) : _bits);
|
1413
|
+
return {
|
1414
|
+
CURVE,
|
1415
|
+
ProjectivePoint: Point2,
|
1416
|
+
normPrivateKeyToScalar,
|
1417
|
+
weierstrassEquation,
|
1418
|
+
isWithinCurveOrder
|
1419
|
+
};
|
1420
|
+
}
|
1421
|
+
__name(weierstrassPoints, "weierstrassPoints");
|
1422
|
+
function validateOpts(curve) {
|
1423
|
+
const opts = validateBasic(curve);
|
1424
|
+
validateObject(opts, {
|
1425
|
+
hash: "hash",
|
1426
|
+
hmac: "function",
|
1427
|
+
randomBytes: "function"
|
1428
|
+
}, {
|
1429
|
+
bits2int: "function",
|
1430
|
+
bits2int_modN: "function",
|
1431
|
+
lowS: "boolean"
|
1432
|
+
});
|
1433
|
+
return Object.freeze({ lowS: true, ...opts });
|
1434
|
+
}
|
1435
|
+
__name(validateOpts, "validateOpts");
|
1436
|
+
function weierstrass(curveDef) {
|
1437
|
+
const CURVE = validateOpts(curveDef);
|
1438
|
+
const { Fp: Fp2, n: CURVE_ORDER } = CURVE;
|
1439
|
+
const compressedLen = Fp2.BYTES + 1;
|
1440
|
+
const uncompressedLen = 2 * Fp2.BYTES + 1;
|
1441
|
+
function isValidFieldElement(num) {
|
1442
|
+
return _0n4 < num && num < Fp2.ORDER;
|
1443
|
+
}
|
1444
|
+
__name(isValidFieldElement, "isValidFieldElement");
|
1445
|
+
function modN(a) {
|
1446
|
+
return mod(a, CURVE_ORDER);
|
1447
|
+
}
|
1448
|
+
__name(modN, "modN");
|
1449
|
+
function invN(a) {
|
1450
|
+
return invert(a, CURVE_ORDER);
|
1451
|
+
}
|
1452
|
+
__name(invN, "invN");
|
1453
|
+
const { ProjectivePoint: Point2, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
|
1454
|
+
...CURVE,
|
1455
|
+
toBytes(_c, point, isCompressed) {
|
1456
|
+
const a = point.toAffine();
|
1457
|
+
const x = Fp2.toBytes(a.x);
|
1458
|
+
const cat = concatBytes;
|
1459
|
+
if (isCompressed) {
|
1460
|
+
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
|
1461
|
+
} else {
|
1462
|
+
return cat(Uint8Array.from([4]), x, Fp2.toBytes(a.y));
|
1463
|
+
}
|
1464
|
+
},
|
1465
|
+
fromBytes(bytes2) {
|
1466
|
+
const len = bytes2.length;
|
1467
|
+
const head = bytes2[0];
|
1468
|
+
const tail = bytes2.subarray(1);
|
1469
|
+
if (len === compressedLen && (head === 2 || head === 3)) {
|
1470
|
+
const x = bytesToNumberBE(tail);
|
1471
|
+
if (!isValidFieldElement(x))
|
1472
|
+
throw new Error("Point is not on curve");
|
1473
|
+
const y2 = weierstrassEquation(x);
|
1474
|
+
let y;
|
1475
|
+
try {
|
1476
|
+
y = Fp2.sqrt(y2);
|
1477
|
+
} catch (sqrtError) {
|
1478
|
+
const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
1479
|
+
throw new Error("Point is not on curve" + suffix);
|
1480
|
+
}
|
1481
|
+
const isYOdd = (y & _1n4) === _1n4;
|
1482
|
+
const isHeadOdd = (head & 1) === 1;
|
1483
|
+
if (isHeadOdd !== isYOdd)
|
1484
|
+
y = Fp2.neg(y);
|
1485
|
+
return { x, y };
|
1486
|
+
} else if (len === uncompressedLen && head === 4) {
|
1487
|
+
const x = Fp2.fromBytes(tail.subarray(0, Fp2.BYTES));
|
1488
|
+
const y = Fp2.fromBytes(tail.subarray(Fp2.BYTES, 2 * Fp2.BYTES));
|
1489
|
+
return { x, y };
|
1490
|
+
} else {
|
1491
|
+
throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
|
1492
|
+
}
|
1493
|
+
}
|
1494
|
+
});
|
1495
|
+
const numToNByteStr = /* @__PURE__ */ __name((num) => bytesToHex(numberToBytesBE(num, CURVE.nByteLength)), "numToNByteStr");
|
1496
|
+
function isBiggerThanHalfOrder(number2) {
|
1497
|
+
const HALF = CURVE_ORDER >> _1n4;
|
1498
|
+
return number2 > HALF;
|
1499
|
+
}
|
1500
|
+
__name(isBiggerThanHalfOrder, "isBiggerThanHalfOrder");
|
1501
|
+
function normalizeS(s) {
|
1502
|
+
return isBiggerThanHalfOrder(s) ? modN(-s) : s;
|
1503
|
+
}
|
1504
|
+
__name(normalizeS, "normalizeS");
|
1505
|
+
const slcNum = /* @__PURE__ */ __name((b, from, to) => bytesToNumberBE(b.slice(from, to)), "slcNum");
|
1506
|
+
class Signature {
|
1507
|
+
static {
|
1508
|
+
__name(this, "Signature");
|
1509
|
+
}
|
1510
|
+
constructor(r, s, recovery) {
|
1511
|
+
this.r = r;
|
1512
|
+
this.s = s;
|
1513
|
+
this.recovery = recovery;
|
1514
|
+
this.assertValidity();
|
1515
|
+
}
|
1516
|
+
// pair (bytes of r, bytes of s)
|
1517
|
+
static fromCompact(hex) {
|
1518
|
+
const l = CURVE.nByteLength;
|
1519
|
+
hex = ensureBytes("compactSignature", hex, l * 2);
|
1520
|
+
return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
1521
|
+
}
|
1522
|
+
// DER encoded ECDSA signature
|
1523
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
1524
|
+
static fromDER(hex) {
|
1525
|
+
const { r, s } = DER.toSig(ensureBytes("DER", hex));
|
1526
|
+
return new Signature(r, s);
|
1527
|
+
}
|
1528
|
+
assertValidity() {
|
1529
|
+
if (!isWithinCurveOrder(this.r))
|
1530
|
+
throw new Error("r must be 0 < r < CURVE.n");
|
1531
|
+
if (!isWithinCurveOrder(this.s))
|
1532
|
+
throw new Error("s must be 0 < s < CURVE.n");
|
1533
|
+
}
|
1534
|
+
addRecoveryBit(recovery) {
|
1535
|
+
return new Signature(this.r, this.s, recovery);
|
1536
|
+
}
|
1537
|
+
recoverPublicKey(msgHash) {
|
1538
|
+
const { r, s, recovery: rec } = this;
|
1539
|
+
const h = bits2int_modN(ensureBytes("msgHash", msgHash));
|
1540
|
+
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
1541
|
+
throw new Error("recovery id invalid");
|
1542
|
+
const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
|
1543
|
+
if (radj >= Fp2.ORDER)
|
1544
|
+
throw new Error("recovery id 2 or 3 invalid");
|
1545
|
+
const prefix = (rec & 1) === 0 ? "02" : "03";
|
1546
|
+
const R = Point2.fromHex(prefix + numToNByteStr(radj));
|
1547
|
+
const ir = invN(radj);
|
1548
|
+
const u1 = modN(-h * ir);
|
1549
|
+
const u2 = modN(s * ir);
|
1550
|
+
const Q = Point2.BASE.multiplyAndAddUnsafe(R, u1, u2);
|
1551
|
+
if (!Q)
|
1552
|
+
throw new Error("point at infinify");
|
1553
|
+
Q.assertValidity();
|
1554
|
+
return Q;
|
1555
|
+
}
|
1556
|
+
// Signatures should be low-s, to prevent malleability.
|
1557
|
+
hasHighS() {
|
1558
|
+
return isBiggerThanHalfOrder(this.s);
|
1559
|
+
}
|
1560
|
+
normalizeS() {
|
1561
|
+
return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
|
1562
|
+
}
|
1563
|
+
// DER-encoded
|
1564
|
+
toDERRawBytes() {
|
1565
|
+
return hexToBytes(this.toDERHex());
|
1566
|
+
}
|
1567
|
+
toDERHex() {
|
1568
|
+
return DER.hexFromSig({ r: this.r, s: this.s });
|
1569
|
+
}
|
1570
|
+
// padded bytes of r, then padded bytes of s
|
1571
|
+
toCompactRawBytes() {
|
1572
|
+
return hexToBytes(this.toCompactHex());
|
1573
|
+
}
|
1574
|
+
toCompactHex() {
|
1575
|
+
return numToNByteStr(this.r) + numToNByteStr(this.s);
|
1576
|
+
}
|
1577
|
+
}
|
1578
|
+
const utils = {
|
1579
|
+
isValidPrivateKey(privateKey) {
|
1580
|
+
try {
|
1581
|
+
normPrivateKeyToScalar(privateKey);
|
1582
|
+
return true;
|
1583
|
+
} catch (error) {
|
1584
|
+
return false;
|
1585
|
+
}
|
1586
|
+
},
|
1587
|
+
normPrivateKeyToScalar,
|
1588
|
+
/**
|
1589
|
+
* Produces cryptographically secure private key from random of size
|
1590
|
+
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
1591
|
+
*/
|
1592
|
+
randomPrivateKey: /* @__PURE__ */ __name(() => {
|
1593
|
+
const length = getMinHashLength(CURVE.n);
|
1594
|
+
return mapHashToField(CURVE.randomBytes(length), CURVE.n);
|
1595
|
+
}, "randomPrivateKey"),
|
1596
|
+
/**
|
1597
|
+
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
1598
|
+
* Allows to massively speed-up `point.multiply(scalar)`.
|
1599
|
+
* @returns cached point
|
1600
|
+
* @example
|
1601
|
+
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
1602
|
+
* fast.multiply(privKey); // much faster ECDH now
|
1603
|
+
*/
|
1604
|
+
precompute(windowSize = 8, point = Point2.BASE) {
|
1605
|
+
point._setWindowSize(windowSize);
|
1606
|
+
point.multiply(BigInt(3));
|
1607
|
+
return point;
|
1608
|
+
}
|
1609
|
+
};
|
1610
|
+
function getPublicKey(privateKey, isCompressed = true) {
|
1611
|
+
return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
1612
|
+
}
|
1613
|
+
__name(getPublicKey, "getPublicKey");
|
1614
|
+
function isProbPub(item) {
|
1615
|
+
const arr = isBytes2(item);
|
1616
|
+
const str = typeof item === "string";
|
1617
|
+
const len = (arr || str) && item.length;
|
1618
|
+
if (arr)
|
1619
|
+
return len === compressedLen || len === uncompressedLen;
|
1620
|
+
if (str)
|
1621
|
+
return len === 2 * compressedLen || len === 2 * uncompressedLen;
|
1622
|
+
if (item instanceof Point2)
|
1623
|
+
return true;
|
1624
|
+
return false;
|
1625
|
+
}
|
1626
|
+
__name(isProbPub, "isProbPub");
|
1627
|
+
function getSharedSecret(privateA, publicB, isCompressed = true) {
|
1628
|
+
if (isProbPub(privateA))
|
1629
|
+
throw new Error("first arg must be private key");
|
1630
|
+
if (!isProbPub(publicB))
|
1631
|
+
throw new Error("second arg must be public key");
|
1632
|
+
const b = Point2.fromHex(publicB);
|
1633
|
+
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
1634
|
+
}
|
1635
|
+
__name(getSharedSecret, "getSharedSecret");
|
1636
|
+
const bits2int = CURVE.bits2int || function(bytes2) {
|
1637
|
+
const num = bytesToNumberBE(bytes2);
|
1638
|
+
const delta = bytes2.length * 8 - CURVE.nBitLength;
|
1639
|
+
return delta > 0 ? num >> BigInt(delta) : num;
|
1640
|
+
};
|
1641
|
+
const bits2int_modN = CURVE.bits2int_modN || function(bytes2) {
|
1642
|
+
return modN(bits2int(bytes2));
|
1643
|
+
};
|
1644
|
+
const ORDER_MASK = bitMask(CURVE.nBitLength);
|
1645
|
+
function int2octets(num) {
|
1646
|
+
if (typeof num !== "bigint")
|
1647
|
+
throw new Error("bigint expected");
|
1648
|
+
if (!(_0n4 <= num && num < ORDER_MASK))
|
1649
|
+
throw new Error(`bigint expected < 2^${CURVE.nBitLength}`);
|
1650
|
+
return numberToBytesBE(num, CURVE.nByteLength);
|
1651
|
+
}
|
1652
|
+
__name(int2octets, "int2octets");
|
1653
|
+
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
1654
|
+
if (["recovered", "canonical"].some((k) => k in opts))
|
1655
|
+
throw new Error("sign() legacy options not supported");
|
1656
|
+
const { hash: hash2, randomBytes: randomBytes2 } = CURVE;
|
1657
|
+
let { lowS, prehash, extraEntropy: ent } = opts;
|
1658
|
+
if (lowS == null)
|
1659
|
+
lowS = true;
|
1660
|
+
msgHash = ensureBytes("msgHash", msgHash);
|
1661
|
+
if (prehash)
|
1662
|
+
msgHash = ensureBytes("prehashed msgHash", hash2(msgHash));
|
1663
|
+
const h1int = bits2int_modN(msgHash);
|
1664
|
+
const d = normPrivateKeyToScalar(privateKey);
|
1665
|
+
const seedArgs = [int2octets(d), int2octets(h1int)];
|
1666
|
+
if (ent != null && ent !== false) {
|
1667
|
+
const e = ent === true ? randomBytes2(Fp2.BYTES) : ent;
|
1668
|
+
seedArgs.push(ensureBytes("extraEntropy", e));
|
1669
|
+
}
|
1670
|
+
const seed = concatBytes(...seedArgs);
|
1671
|
+
const m = h1int;
|
1672
|
+
function k2sig(kBytes) {
|
1673
|
+
const k = bits2int(kBytes);
|
1674
|
+
if (!isWithinCurveOrder(k))
|
1675
|
+
return;
|
1676
|
+
const ik = invN(k);
|
1677
|
+
const q = Point2.BASE.multiply(k).toAffine();
|
1678
|
+
const r = modN(q.x);
|
1679
|
+
if (r === _0n4)
|
1680
|
+
return;
|
1681
|
+
const s = modN(ik * modN(m + r * d));
|
1682
|
+
if (s === _0n4)
|
1683
|
+
return;
|
1684
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n4);
|
1685
|
+
let normS = s;
|
1686
|
+
if (lowS && isBiggerThanHalfOrder(s)) {
|
1687
|
+
normS = normalizeS(s);
|
1688
|
+
recovery ^= 1;
|
1689
|
+
}
|
1690
|
+
return new Signature(r, normS, recovery);
|
1691
|
+
}
|
1692
|
+
__name(k2sig, "k2sig");
|
1693
|
+
return { seed, k2sig };
|
1694
|
+
}
|
1695
|
+
__name(prepSig, "prepSig");
|
1696
|
+
const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
|
1697
|
+
const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
|
1698
|
+
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
1699
|
+
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
1700
|
+
const C = CURVE;
|
1701
|
+
const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
|
1702
|
+
return drbg(seed, k2sig);
|
1703
|
+
}
|
1704
|
+
__name(sign, "sign");
|
1705
|
+
Point2.BASE._setWindowSize(8);
|
1706
|
+
function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
1707
|
+
const sg = signature;
|
1708
|
+
msgHash = ensureBytes("msgHash", msgHash);
|
1709
|
+
publicKey = ensureBytes("publicKey", publicKey);
|
1710
|
+
if ("strict" in opts)
|
1711
|
+
throw new Error("options.strict was renamed to lowS");
|
1712
|
+
const { lowS, prehash } = opts;
|
1713
|
+
let _sig = void 0;
|
1714
|
+
let P;
|
1715
|
+
try {
|
1716
|
+
if (typeof sg === "string" || isBytes2(sg)) {
|
1717
|
+
try {
|
1718
|
+
_sig = Signature.fromDER(sg);
|
1719
|
+
} catch (derError) {
|
1720
|
+
if (!(derError instanceof DER.Err))
|
1721
|
+
throw derError;
|
1722
|
+
_sig = Signature.fromCompact(sg);
|
1723
|
+
}
|
1724
|
+
} else if (typeof sg === "object" && typeof sg.r === "bigint" && typeof sg.s === "bigint") {
|
1725
|
+
const { r: r2, s: s2 } = sg;
|
1726
|
+
_sig = new Signature(r2, s2);
|
1727
|
+
} else {
|
1728
|
+
throw new Error("PARSE");
|
1729
|
+
}
|
1730
|
+
P = Point2.fromHex(publicKey);
|
1731
|
+
} catch (error) {
|
1732
|
+
if (error.message === "PARSE")
|
1733
|
+
throw new Error(`signature must be Signature instance, Uint8Array or hex string`);
|
1734
|
+
return false;
|
1735
|
+
}
|
1736
|
+
if (lowS && _sig.hasHighS())
|
1737
|
+
return false;
|
1738
|
+
if (prehash)
|
1739
|
+
msgHash = CURVE.hash(msgHash);
|
1740
|
+
const { r, s } = _sig;
|
1741
|
+
const h = bits2int_modN(msgHash);
|
1742
|
+
const is = invN(s);
|
1743
|
+
const u1 = modN(h * is);
|
1744
|
+
const u2 = modN(r * is);
|
1745
|
+
const R = Point2.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
|
1746
|
+
if (!R)
|
1747
|
+
return false;
|
1748
|
+
const v = modN(R.x);
|
1749
|
+
return v === r;
|
1750
|
+
}
|
1751
|
+
__name(verify, "verify");
|
1752
|
+
return {
|
1753
|
+
CURVE,
|
1754
|
+
getPublicKey,
|
1755
|
+
getSharedSecret,
|
1756
|
+
sign,
|
1757
|
+
verify,
|
1758
|
+
ProjectivePoint: Point2,
|
1759
|
+
Signature,
|
1760
|
+
utils
|
1761
|
+
};
|
1762
|
+
}
|
1763
|
+
__name(weierstrass, "weierstrass");
|
1764
|
+
function SWUFpSqrtRatio(Fp2, Z) {
|
1765
|
+
const q = Fp2.ORDER;
|
1766
|
+
let l = _0n4;
|
1767
|
+
for (let o = q - _1n4; o % _2n3 === _0n4; o /= _2n3)
|
1768
|
+
l += _1n4;
|
1769
|
+
const c1 = l;
|
1770
|
+
const _2n_pow_c1_1 = _2n3 << c1 - _1n4 - _1n4;
|
1771
|
+
const _2n_pow_c1 = _2n_pow_c1_1 * _2n3;
|
1772
|
+
const c2 = (q - _1n4) / _2n_pow_c1;
|
1773
|
+
const c3 = (c2 - _1n4) / _2n3;
|
1774
|
+
const c4 = _2n_pow_c1 - _1n4;
|
1775
|
+
const c5 = _2n_pow_c1_1;
|
1776
|
+
const c6 = Fp2.pow(Z, c2);
|
1777
|
+
const c7 = Fp2.pow(Z, (c2 + _1n4) / _2n3);
|
1778
|
+
let sqrtRatio = /* @__PURE__ */ __name((u, v) => {
|
1779
|
+
let tv1 = c6;
|
1780
|
+
let tv2 = Fp2.pow(v, c4);
|
1781
|
+
let tv3 = Fp2.sqr(tv2);
|
1782
|
+
tv3 = Fp2.mul(tv3, v);
|
1783
|
+
let tv5 = Fp2.mul(u, tv3);
|
1784
|
+
tv5 = Fp2.pow(tv5, c3);
|
1785
|
+
tv5 = Fp2.mul(tv5, tv2);
|
1786
|
+
tv2 = Fp2.mul(tv5, v);
|
1787
|
+
tv3 = Fp2.mul(tv5, u);
|
1788
|
+
let tv4 = Fp2.mul(tv3, tv2);
|
1789
|
+
tv5 = Fp2.pow(tv4, c5);
|
1790
|
+
let isQR = Fp2.eql(tv5, Fp2.ONE);
|
1791
|
+
tv2 = Fp2.mul(tv3, c7);
|
1792
|
+
tv5 = Fp2.mul(tv4, tv1);
|
1793
|
+
tv3 = Fp2.cmov(tv2, tv3, isQR);
|
1794
|
+
tv4 = Fp2.cmov(tv5, tv4, isQR);
|
1795
|
+
for (let i = c1; i > _1n4; i--) {
|
1796
|
+
let tv52 = i - _2n3;
|
1797
|
+
tv52 = _2n3 << tv52 - _1n4;
|
1798
|
+
let tvv5 = Fp2.pow(tv4, tv52);
|
1799
|
+
const e1 = Fp2.eql(tvv5, Fp2.ONE);
|
1800
|
+
tv2 = Fp2.mul(tv3, tv1);
|
1801
|
+
tv1 = Fp2.mul(tv1, tv1);
|
1802
|
+
tvv5 = Fp2.mul(tv4, tv1);
|
1803
|
+
tv3 = Fp2.cmov(tv2, tv3, e1);
|
1804
|
+
tv4 = Fp2.cmov(tvv5, tv4, e1);
|
1805
|
+
}
|
1806
|
+
return { isValid: isQR, value: tv3 };
|
1807
|
+
}, "sqrtRatio");
|
1808
|
+
if (Fp2.ORDER % _4n2 === _3n2) {
|
1809
|
+
const c12 = (Fp2.ORDER - _3n2) / _4n2;
|
1810
|
+
const c22 = Fp2.sqrt(Fp2.neg(Z));
|
1811
|
+
sqrtRatio = /* @__PURE__ */ __name((u, v) => {
|
1812
|
+
let tv1 = Fp2.sqr(v);
|
1813
|
+
const tv2 = Fp2.mul(u, v);
|
1814
|
+
tv1 = Fp2.mul(tv1, tv2);
|
1815
|
+
let y1 = Fp2.pow(tv1, c12);
|
1816
|
+
y1 = Fp2.mul(y1, tv2);
|
1817
|
+
const y2 = Fp2.mul(y1, c22);
|
1818
|
+
const tv3 = Fp2.mul(Fp2.sqr(y1), v);
|
1819
|
+
const isQR = Fp2.eql(tv3, u);
|
1820
|
+
let y = Fp2.cmov(y2, y1, isQR);
|
1821
|
+
return { isValid: isQR, value: y };
|
1822
|
+
}, "sqrtRatio");
|
1823
|
+
}
|
1824
|
+
return sqrtRatio;
|
1825
|
+
}
|
1826
|
+
__name(SWUFpSqrtRatio, "SWUFpSqrtRatio");
|
1827
|
+
function mapToCurveSimpleSWU(Fp2, opts) {
|
1828
|
+
validateField(Fp2);
|
1829
|
+
if (!Fp2.isValid(opts.A) || !Fp2.isValid(opts.B) || !Fp2.isValid(opts.Z))
|
1830
|
+
throw new Error("mapToCurveSimpleSWU: invalid opts");
|
1831
|
+
const sqrtRatio = SWUFpSqrtRatio(Fp2, opts.Z);
|
1832
|
+
if (!Fp2.isOdd)
|
1833
|
+
throw new Error("Fp.isOdd is not implemented!");
|
1834
|
+
return (u) => {
|
1835
|
+
let tv1, tv2, tv3, tv4, tv5, tv6, x, y;
|
1836
|
+
tv1 = Fp2.sqr(u);
|
1837
|
+
tv1 = Fp2.mul(tv1, opts.Z);
|
1838
|
+
tv2 = Fp2.sqr(tv1);
|
1839
|
+
tv2 = Fp2.add(tv2, tv1);
|
1840
|
+
tv3 = Fp2.add(tv2, Fp2.ONE);
|
1841
|
+
tv3 = Fp2.mul(tv3, opts.B);
|
1842
|
+
tv4 = Fp2.cmov(opts.Z, Fp2.neg(tv2), !Fp2.eql(tv2, Fp2.ZERO));
|
1843
|
+
tv4 = Fp2.mul(tv4, opts.A);
|
1844
|
+
tv2 = Fp2.sqr(tv3);
|
1845
|
+
tv6 = Fp2.sqr(tv4);
|
1846
|
+
tv5 = Fp2.mul(tv6, opts.A);
|
1847
|
+
tv2 = Fp2.add(tv2, tv5);
|
1848
|
+
tv2 = Fp2.mul(tv2, tv3);
|
1849
|
+
tv6 = Fp2.mul(tv6, tv4);
|
1850
|
+
tv5 = Fp2.mul(tv6, opts.B);
|
1851
|
+
tv2 = Fp2.add(tv2, tv5);
|
1852
|
+
x = Fp2.mul(tv1, tv3);
|
1853
|
+
const { isValid, value } = sqrtRatio(tv2, tv6);
|
1854
|
+
y = Fp2.mul(tv1, u);
|
1855
|
+
y = Fp2.mul(y, value);
|
1856
|
+
x = Fp2.cmov(x, tv3, isValid);
|
1857
|
+
y = Fp2.cmov(y, value, isValid);
|
1858
|
+
const e1 = Fp2.isOdd(u) === Fp2.isOdd(y);
|
1859
|
+
y = Fp2.cmov(Fp2.neg(y), y, e1);
|
1860
|
+
x = Fp2.div(x, tv4);
|
1861
|
+
return { x, y };
|
1862
|
+
};
|
1863
|
+
}
|
1864
|
+
__name(mapToCurveSimpleSWU, "mapToCurveSimpleSWU");
|
1865
|
+
|
1866
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
|
1867
|
+
function number(n) {
|
1868
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
1869
|
+
throw new Error(`positive integer expected, not ${n}`);
|
1870
|
+
}
|
1871
|
+
__name(number, "number");
|
1872
|
+
function isBytes3(a) {
|
1873
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
1874
|
+
}
|
1875
|
+
__name(isBytes3, "isBytes");
|
1876
|
+
function bytes(b, ...lengths) {
|
1877
|
+
if (!isBytes3(b))
|
1878
|
+
throw new Error("Uint8Array expected");
|
1879
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
1880
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
1881
|
+
}
|
1882
|
+
__name(bytes, "bytes");
|
1883
|
+
function hash(h) {
|
1884
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
1885
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
1886
|
+
number(h.outputLen);
|
1887
|
+
number(h.blockLen);
|
1888
|
+
}
|
1889
|
+
__name(hash, "hash");
|
1890
|
+
function exists(instance, checkFinished = true) {
|
1891
|
+
if (instance.destroyed)
|
1892
|
+
throw new Error("Hash instance has been destroyed");
|
1893
|
+
if (checkFinished && instance.finished)
|
1894
|
+
throw new Error("Hash#digest() has already been called");
|
1895
|
+
}
|
1896
|
+
__name(exists, "exists");
|
1897
|
+
function output(out, instance) {
|
1898
|
+
bytes(out);
|
1899
|
+
const min = instance.outputLen;
|
1900
|
+
if (out.length < min) {
|
1901
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
1902
|
+
}
|
1903
|
+
}
|
1904
|
+
__name(output, "output");
|
1905
|
+
|
1906
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/cryptoNode.js
|
1907
|
+
import * as nc from "node:crypto";
|
1908
|
+
var crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : void 0;
|
1909
|
+
|
1910
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/utils.js
|
1911
|
+
var u32 = /* @__PURE__ */ __name((arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4)), "u32");
|
1912
|
+
var createView = /* @__PURE__ */ __name((arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength), "createView");
|
1913
|
+
var rotr = /* @__PURE__ */ __name((word, shift) => word << 32 - shift | word >>> shift, "rotr");
|
1914
|
+
var rotl = /* @__PURE__ */ __name((word, shift) => word << shift | word >>> 32 - shift >>> 0, "rotl");
|
1915
|
+
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
1916
|
+
var byteSwap = /* @__PURE__ */ __name((word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255, "byteSwap");
|
1917
|
+
function byteSwap32(arr) {
|
1918
|
+
for (let i = 0; i < arr.length; i++) {
|
1919
|
+
arr[i] = byteSwap(arr[i]);
|
1920
|
+
}
|
1921
|
+
}
|
1922
|
+
__name(byteSwap32, "byteSwap32");
|
1923
|
+
var hexes2 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
1924
|
+
function bytesToHex2(bytes2) {
|
1925
|
+
bytes(bytes2);
|
1926
|
+
let hex = "";
|
1927
|
+
for (let i = 0; i < bytes2.length; i++) {
|
1928
|
+
hex += hexes2[bytes2[i]];
|
1929
|
+
}
|
1930
|
+
return hex;
|
1931
|
+
}
|
1932
|
+
__name(bytesToHex2, "bytesToHex");
|
1933
|
+
var asciis2 = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
|
1934
|
+
function asciiToBase162(char) {
|
1935
|
+
if (char >= asciis2._0 && char <= asciis2._9)
|
1936
|
+
return char - asciis2._0;
|
1937
|
+
if (char >= asciis2._A && char <= asciis2._F)
|
1938
|
+
return char - (asciis2._A - 10);
|
1939
|
+
if (char >= asciis2._a && char <= asciis2._f)
|
1940
|
+
return char - (asciis2._a - 10);
|
1941
|
+
return;
|
1942
|
+
}
|
1943
|
+
__name(asciiToBase162, "asciiToBase16");
|
1944
|
+
function hexToBytes2(hex) {
|
1945
|
+
if (typeof hex !== "string")
|
1946
|
+
throw new Error("hex string expected, got " + typeof hex);
|
1947
|
+
const hl = hex.length;
|
1948
|
+
const al = hl / 2;
|
1949
|
+
if (hl % 2)
|
1950
|
+
throw new Error("padded hex string expected, got unpadded hex of length " + hl);
|
1951
|
+
const array = new Uint8Array(al);
|
1952
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
1953
|
+
const n1 = asciiToBase162(hex.charCodeAt(hi));
|
1954
|
+
const n2 = asciiToBase162(hex.charCodeAt(hi + 1));
|
1955
|
+
if (n1 === void 0 || n2 === void 0) {
|
1956
|
+
const char = hex[hi] + hex[hi + 1];
|
1957
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
1958
|
+
}
|
1959
|
+
array[ai] = n1 * 16 + n2;
|
1960
|
+
}
|
1961
|
+
return array;
|
1962
|
+
}
|
1963
|
+
__name(hexToBytes2, "hexToBytes");
|
1964
|
+
function utf8ToBytes2(str) {
|
1965
|
+
if (typeof str !== "string")
|
1966
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
1967
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
1968
|
+
}
|
1969
|
+
__name(utf8ToBytes2, "utf8ToBytes");
|
1970
|
+
function toBytes(data) {
|
1971
|
+
if (typeof data === "string")
|
1972
|
+
data = utf8ToBytes2(data);
|
1973
|
+
bytes(data);
|
1974
|
+
return data;
|
1975
|
+
}
|
1976
|
+
__name(toBytes, "toBytes");
|
1977
|
+
function concatBytes2(...arrays) {
|
1978
|
+
let sum = 0;
|
1979
|
+
for (let i = 0; i < arrays.length; i++) {
|
1980
|
+
const a = arrays[i];
|
1981
|
+
bytes(a);
|
1982
|
+
sum += a.length;
|
1983
|
+
}
|
1984
|
+
const res = new Uint8Array(sum);
|
1985
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
1986
|
+
const a = arrays[i];
|
1987
|
+
res.set(a, pad);
|
1988
|
+
pad += a.length;
|
1989
|
+
}
|
1990
|
+
return res;
|
1991
|
+
}
|
1992
|
+
__name(concatBytes2, "concatBytes");
|
1993
|
+
var Hash = class {
|
1994
|
+
static {
|
1995
|
+
__name(this, "Hash");
|
1996
|
+
}
|
1997
|
+
// Safe version that clones internal state
|
1998
|
+
clone() {
|
1999
|
+
return this._cloneInto();
|
2000
|
+
}
|
2001
|
+
};
|
2002
|
+
var toStr = {}.toString;
|
2003
|
+
function checkOpts(defaults, opts) {
|
2004
|
+
if (opts !== void 0 && toStr.call(opts) !== "[object Object]")
|
2005
|
+
throw new Error("Options should be object or undefined");
|
2006
|
+
const merged = Object.assign(defaults, opts);
|
2007
|
+
return merged;
|
2008
|
+
}
|
2009
|
+
__name(checkOpts, "checkOpts");
|
2010
|
+
function wrapConstructor(hashCons) {
|
2011
|
+
const hashC = /* @__PURE__ */ __name((msg) => hashCons().update(toBytes(msg)).digest(), "hashC");
|
2012
|
+
const tmp = hashCons();
|
2013
|
+
hashC.outputLen = tmp.outputLen;
|
2014
|
+
hashC.blockLen = tmp.blockLen;
|
2015
|
+
hashC.create = () => hashCons();
|
2016
|
+
return hashC;
|
2017
|
+
}
|
2018
|
+
__name(wrapConstructor, "wrapConstructor");
|
2019
|
+
function wrapXOFConstructorWithOpts(hashCons) {
|
2020
|
+
const hashC = /* @__PURE__ */ __name((msg, opts) => hashCons(opts).update(toBytes(msg)).digest(), "hashC");
|
2021
|
+
const tmp = hashCons({});
|
2022
|
+
hashC.outputLen = tmp.outputLen;
|
2023
|
+
hashC.blockLen = tmp.blockLen;
|
2024
|
+
hashC.create = (opts) => hashCons(opts);
|
2025
|
+
return hashC;
|
2026
|
+
}
|
2027
|
+
__name(wrapXOFConstructorWithOpts, "wrapXOFConstructorWithOpts");
|
2028
|
+
function randomBytes(bytesLength = 32) {
|
2029
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
2030
|
+
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
2031
|
+
}
|
2032
|
+
throw new Error("crypto.getRandomValues must be defined");
|
2033
|
+
}
|
2034
|
+
__name(randomBytes, "randomBytes");
|
2035
|
+
|
2036
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_md.js
|
2037
|
+
function setBigUint64(view, byteOffset, value, isLE2) {
|
2038
|
+
if (typeof view.setBigUint64 === "function")
|
2039
|
+
return view.setBigUint64(byteOffset, value, isLE2);
|
2040
|
+
const _32n2 = BigInt(32);
|
2041
|
+
const _u32_max = BigInt(4294967295);
|
2042
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
2043
|
+
const wl = Number(value & _u32_max);
|
2044
|
+
const h = isLE2 ? 4 : 0;
|
2045
|
+
const l = isLE2 ? 0 : 4;
|
2046
|
+
view.setUint32(byteOffset + h, wh, isLE2);
|
2047
|
+
view.setUint32(byteOffset + l, wl, isLE2);
|
2048
|
+
}
|
2049
|
+
__name(setBigUint64, "setBigUint64");
|
2050
|
+
var Chi = /* @__PURE__ */ __name((a, b, c) => a & b ^ ~a & c, "Chi");
|
2051
|
+
var Maj = /* @__PURE__ */ __name((a, b, c) => a & b ^ a & c ^ b & c, "Maj");
|
2052
|
+
var HashMD = class extends Hash {
|
2053
|
+
static {
|
2054
|
+
__name(this, "HashMD");
|
2055
|
+
}
|
2056
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
2057
|
+
super();
|
2058
|
+
this.blockLen = blockLen;
|
2059
|
+
this.outputLen = outputLen;
|
2060
|
+
this.padOffset = padOffset;
|
2061
|
+
this.isLE = isLE2;
|
2062
|
+
this.finished = false;
|
2063
|
+
this.length = 0;
|
2064
|
+
this.pos = 0;
|
2065
|
+
this.destroyed = false;
|
2066
|
+
this.buffer = new Uint8Array(blockLen);
|
2067
|
+
this.view = createView(this.buffer);
|
2068
|
+
}
|
2069
|
+
update(data) {
|
2070
|
+
exists(this);
|
2071
|
+
const { view, buffer, blockLen } = this;
|
2072
|
+
data = toBytes(data);
|
2073
|
+
const len = data.length;
|
2074
|
+
for (let pos = 0; pos < len; ) {
|
2075
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
2076
|
+
if (take === blockLen) {
|
2077
|
+
const dataView = createView(data);
|
2078
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
2079
|
+
this.process(dataView, pos);
|
2080
|
+
continue;
|
2081
|
+
}
|
2082
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
2083
|
+
this.pos += take;
|
2084
|
+
pos += take;
|
2085
|
+
if (this.pos === blockLen) {
|
2086
|
+
this.process(view, 0);
|
2087
|
+
this.pos = 0;
|
2088
|
+
}
|
2089
|
+
}
|
2090
|
+
this.length += data.length;
|
2091
|
+
this.roundClean();
|
2092
|
+
return this;
|
2093
|
+
}
|
2094
|
+
digestInto(out) {
|
2095
|
+
exists(this);
|
2096
|
+
output(out, this);
|
2097
|
+
this.finished = true;
|
2098
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
2099
|
+
let { pos } = this;
|
2100
|
+
buffer[pos++] = 128;
|
2101
|
+
this.buffer.subarray(pos).fill(0);
|
2102
|
+
if (this.padOffset > blockLen - pos) {
|
2103
|
+
this.process(view, 0);
|
2104
|
+
pos = 0;
|
2105
|
+
}
|
2106
|
+
for (let i = pos; i < blockLen; i++)
|
2107
|
+
buffer[i] = 0;
|
2108
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
2109
|
+
this.process(view, 0);
|
2110
|
+
const oview = createView(out);
|
2111
|
+
const len = this.outputLen;
|
2112
|
+
if (len % 4)
|
2113
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
2114
|
+
const outLen = len / 4;
|
2115
|
+
const state = this.get();
|
2116
|
+
if (outLen > state.length)
|
2117
|
+
throw new Error("_sha2: outputLen bigger than state");
|
2118
|
+
for (let i = 0; i < outLen; i++)
|
2119
|
+
oview.setUint32(4 * i, state[i], isLE2);
|
2120
|
+
}
|
2121
|
+
digest() {
|
2122
|
+
const { buffer, outputLen } = this;
|
2123
|
+
this.digestInto(buffer);
|
2124
|
+
const res = buffer.slice(0, outputLen);
|
2125
|
+
this.destroy();
|
2126
|
+
return res;
|
2127
|
+
}
|
2128
|
+
_cloneInto(to) {
|
2129
|
+
to || (to = new this.constructor());
|
2130
|
+
to.set(...this.get());
|
2131
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
2132
|
+
to.length = length;
|
2133
|
+
to.pos = pos;
|
2134
|
+
to.finished = finished;
|
2135
|
+
to.destroyed = destroyed;
|
2136
|
+
if (length % blockLen)
|
2137
|
+
to.buffer.set(buffer);
|
2138
|
+
return to;
|
2139
|
+
}
|
2140
|
+
};
|
2141
|
+
|
2142
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/sha256.js
|
2143
|
+
var SHA256_K = /* @__PURE__ */ new Uint32Array([
|
2144
|
+
1116352408,
|
2145
|
+
1899447441,
|
2146
|
+
3049323471,
|
2147
|
+
3921009573,
|
2148
|
+
961987163,
|
2149
|
+
1508970993,
|
2150
|
+
2453635748,
|
2151
|
+
2870763221,
|
2152
|
+
3624381080,
|
2153
|
+
310598401,
|
2154
|
+
607225278,
|
2155
|
+
1426881987,
|
2156
|
+
1925078388,
|
2157
|
+
2162078206,
|
2158
|
+
2614888103,
|
2159
|
+
3248222580,
|
2160
|
+
3835390401,
|
2161
|
+
4022224774,
|
2162
|
+
264347078,
|
2163
|
+
604807628,
|
2164
|
+
770255983,
|
2165
|
+
1249150122,
|
2166
|
+
1555081692,
|
2167
|
+
1996064986,
|
2168
|
+
2554220882,
|
2169
|
+
2821834349,
|
2170
|
+
2952996808,
|
2171
|
+
3210313671,
|
2172
|
+
3336571891,
|
2173
|
+
3584528711,
|
2174
|
+
113926993,
|
2175
|
+
338241895,
|
2176
|
+
666307205,
|
2177
|
+
773529912,
|
2178
|
+
1294757372,
|
2179
|
+
1396182291,
|
2180
|
+
1695183700,
|
2181
|
+
1986661051,
|
2182
|
+
2177026350,
|
2183
|
+
2456956037,
|
2184
|
+
2730485921,
|
2185
|
+
2820302411,
|
2186
|
+
3259730800,
|
2187
|
+
3345764771,
|
2188
|
+
3516065817,
|
2189
|
+
3600352804,
|
2190
|
+
4094571909,
|
2191
|
+
275423344,
|
2192
|
+
430227734,
|
2193
|
+
506948616,
|
2194
|
+
659060556,
|
2195
|
+
883997877,
|
2196
|
+
958139571,
|
2197
|
+
1322822218,
|
2198
|
+
1537002063,
|
2199
|
+
1747873779,
|
2200
|
+
1955562222,
|
2201
|
+
2024104815,
|
2202
|
+
2227730452,
|
2203
|
+
2361852424,
|
2204
|
+
2428436474,
|
2205
|
+
2756734187,
|
2206
|
+
3204031479,
|
2207
|
+
3329325298
|
2208
|
+
]);
|
2209
|
+
var SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
2210
|
+
1779033703,
|
2211
|
+
3144134277,
|
2212
|
+
1013904242,
|
2213
|
+
2773480762,
|
2214
|
+
1359893119,
|
2215
|
+
2600822924,
|
2216
|
+
528734635,
|
2217
|
+
1541459225
|
2218
|
+
]);
|
2219
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
2220
|
+
var SHA256 = class extends HashMD {
|
2221
|
+
static {
|
2222
|
+
__name(this, "SHA256");
|
2223
|
+
}
|
2224
|
+
constructor() {
|
2225
|
+
super(64, 32, 8, false);
|
2226
|
+
this.A = SHA256_IV[0] | 0;
|
2227
|
+
this.B = SHA256_IV[1] | 0;
|
2228
|
+
this.C = SHA256_IV[2] | 0;
|
2229
|
+
this.D = SHA256_IV[3] | 0;
|
2230
|
+
this.E = SHA256_IV[4] | 0;
|
2231
|
+
this.F = SHA256_IV[5] | 0;
|
2232
|
+
this.G = SHA256_IV[6] | 0;
|
2233
|
+
this.H = SHA256_IV[7] | 0;
|
2234
|
+
}
|
2235
|
+
get() {
|
2236
|
+
const { A, B, C, D, E, F, G, H } = this;
|
2237
|
+
return [A, B, C, D, E, F, G, H];
|
2238
|
+
}
|
2239
|
+
// prettier-ignore
|
2240
|
+
set(A, B, C, D, E, F, G, H) {
|
2241
|
+
this.A = A | 0;
|
2242
|
+
this.B = B | 0;
|
2243
|
+
this.C = C | 0;
|
2244
|
+
this.D = D | 0;
|
2245
|
+
this.E = E | 0;
|
2246
|
+
this.F = F | 0;
|
2247
|
+
this.G = G | 0;
|
2248
|
+
this.H = H | 0;
|
2249
|
+
}
|
2250
|
+
process(view, offset) {
|
2251
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
2252
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
2253
|
+
for (let i = 16; i < 64; i++) {
|
2254
|
+
const W15 = SHA256_W[i - 15];
|
2255
|
+
const W2 = SHA256_W[i - 2];
|
2256
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
2257
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
2258
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
2259
|
+
}
|
2260
|
+
let { A, B, C, D, E, F, G, H } = this;
|
2261
|
+
for (let i = 0; i < 64; i++) {
|
2262
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
2263
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
2264
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
2265
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
2266
|
+
H = G;
|
2267
|
+
G = F;
|
2268
|
+
F = E;
|
2269
|
+
E = D + T1 | 0;
|
2270
|
+
D = C;
|
2271
|
+
C = B;
|
2272
|
+
B = A;
|
2273
|
+
A = T1 + T2 | 0;
|
2274
|
+
}
|
2275
|
+
A = A + this.A | 0;
|
2276
|
+
B = B + this.B | 0;
|
2277
|
+
C = C + this.C | 0;
|
2278
|
+
D = D + this.D | 0;
|
2279
|
+
E = E + this.E | 0;
|
2280
|
+
F = F + this.F | 0;
|
2281
|
+
G = G + this.G | 0;
|
2282
|
+
H = H + this.H | 0;
|
2283
|
+
this.set(A, B, C, D, E, F, G, H);
|
2284
|
+
}
|
2285
|
+
roundClean() {
|
2286
|
+
SHA256_W.fill(0);
|
2287
|
+
}
|
2288
|
+
destroy() {
|
2289
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
2290
|
+
this.buffer.fill(0);
|
2291
|
+
}
|
2292
|
+
};
|
2293
|
+
var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
2294
|
+
|
2295
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/hmac.js
|
2296
|
+
var HMAC = class extends Hash {
|
2297
|
+
static {
|
2298
|
+
__name(this, "HMAC");
|
2299
|
+
}
|
2300
|
+
constructor(hash2, _key) {
|
2301
|
+
super();
|
2302
|
+
this.finished = false;
|
2303
|
+
this.destroyed = false;
|
2304
|
+
hash(hash2);
|
2305
|
+
const key = toBytes(_key);
|
2306
|
+
this.iHash = hash2.create();
|
2307
|
+
if (typeof this.iHash.update !== "function")
|
2308
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
2309
|
+
this.blockLen = this.iHash.blockLen;
|
2310
|
+
this.outputLen = this.iHash.outputLen;
|
2311
|
+
const blockLen = this.blockLen;
|
2312
|
+
const pad = new Uint8Array(blockLen);
|
2313
|
+
pad.set(key.length > blockLen ? hash2.create().update(key).digest() : key);
|
2314
|
+
for (let i = 0; i < pad.length; i++)
|
2315
|
+
pad[i] ^= 54;
|
2316
|
+
this.iHash.update(pad);
|
2317
|
+
this.oHash = hash2.create();
|
2318
|
+
for (let i = 0; i < pad.length; i++)
|
2319
|
+
pad[i] ^= 54 ^ 92;
|
2320
|
+
this.oHash.update(pad);
|
2321
|
+
pad.fill(0);
|
2322
|
+
}
|
2323
|
+
update(buf) {
|
2324
|
+
exists(this);
|
2325
|
+
this.iHash.update(buf);
|
2326
|
+
return this;
|
2327
|
+
}
|
2328
|
+
digestInto(out) {
|
2329
|
+
exists(this);
|
2330
|
+
bytes(out, this.outputLen);
|
2331
|
+
this.finished = true;
|
2332
|
+
this.iHash.digestInto(out);
|
2333
|
+
this.oHash.update(out);
|
2334
|
+
this.oHash.digestInto(out);
|
2335
|
+
this.destroy();
|
2336
|
+
}
|
2337
|
+
digest() {
|
2338
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
2339
|
+
this.digestInto(out);
|
2340
|
+
return out;
|
2341
|
+
}
|
2342
|
+
_cloneInto(to) {
|
2343
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
2344
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
2345
|
+
to = to;
|
2346
|
+
to.finished = finished;
|
2347
|
+
to.destroyed = destroyed;
|
2348
|
+
to.blockLen = blockLen;
|
2349
|
+
to.outputLen = outputLen;
|
2350
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
2351
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
2352
|
+
return to;
|
2353
|
+
}
|
2354
|
+
destroy() {
|
2355
|
+
this.destroyed = true;
|
2356
|
+
this.oHash.destroy();
|
2357
|
+
this.iHash.destroy();
|
2358
|
+
}
|
2359
|
+
};
|
2360
|
+
var hmac = /* @__PURE__ */ __name((hash2, key, message) => new HMAC(hash2, key).update(message).digest(), "hmac");
|
2361
|
+
hmac.create = (hash2, key) => new HMAC(hash2, key);
|
2362
|
+
|
2363
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/_shortw_utils.js
|
2364
|
+
function getHash(hash2) {
|
2365
|
+
return {
|
2366
|
+
hash: hash2,
|
2367
|
+
hmac: /* @__PURE__ */ __name((key, ...msgs) => hmac(hash2, key, concatBytes2(...msgs)), "hmac"),
|
2368
|
+
randomBytes
|
2369
|
+
};
|
2370
|
+
}
|
2371
|
+
__name(getHash, "getHash");
|
2372
|
+
function createCurve(curveDef, defHash) {
|
2373
|
+
const create = /* @__PURE__ */ __name((hash2) => weierstrass({ ...curveDef, ...getHash(hash2) }), "create");
|
2374
|
+
return Object.freeze({ ...create(defHash), create });
|
2375
|
+
}
|
2376
|
+
__name(createCurve, "createCurve");
|
2377
|
+
|
2378
|
+
// ../../node_modules/.pnpm/@noble+curves@1.4.0/node_modules/@noble/curves/esm/secp256k1.js
|
2379
|
+
var secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
|
2380
|
+
var secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
2381
|
+
var _1n5 = BigInt(1);
|
2382
|
+
var _2n4 = BigInt(2);
|
2383
|
+
var divNearest = /* @__PURE__ */ __name((a, b) => (a + b / _2n4) / b, "divNearest");
|
2384
|
+
function sqrtMod(y) {
|
2385
|
+
const P = secp256k1P;
|
2386
|
+
const _3n3 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
2387
|
+
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
2388
|
+
const b2 = y * y * y % P;
|
2389
|
+
const b3 = b2 * b2 * y % P;
|
2390
|
+
const b6 = pow2(b3, _3n3, P) * b3 % P;
|
2391
|
+
const b9 = pow2(b6, _3n3, P) * b3 % P;
|
2392
|
+
const b11 = pow2(b9, _2n4, P) * b2 % P;
|
2393
|
+
const b22 = pow2(b11, _11n, P) * b11 % P;
|
2394
|
+
const b44 = pow2(b22, _22n, P) * b22 % P;
|
2395
|
+
const b88 = pow2(b44, _44n, P) * b44 % P;
|
2396
|
+
const b176 = pow2(b88, _88n, P) * b88 % P;
|
2397
|
+
const b220 = pow2(b176, _44n, P) * b44 % P;
|
2398
|
+
const b223 = pow2(b220, _3n3, P) * b3 % P;
|
2399
|
+
const t1 = pow2(b223, _23n, P) * b22 % P;
|
2400
|
+
const t2 = pow2(t1, _6n, P) * b2 % P;
|
2401
|
+
const root = pow2(t2, _2n4, P);
|
2402
|
+
if (!Fp.eql(Fp.sqr(root), y))
|
2403
|
+
throw new Error("Cannot find square root");
|
2404
|
+
return root;
|
2405
|
+
}
|
2406
|
+
__name(sqrtMod, "sqrtMod");
|
2407
|
+
var Fp = Field(secp256k1P, void 0, void 0, { sqrt: sqrtMod });
|
2408
|
+
var secp256k1 = createCurve({
|
2409
|
+
a: BigInt(0),
|
2410
|
+
// equation params: a, b
|
2411
|
+
b: BigInt(7),
|
2412
|
+
// Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
|
2413
|
+
Fp,
|
2414
|
+
// Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
2415
|
+
n: secp256k1N,
|
2416
|
+
// Curve order, total count of valid points in the field
|
2417
|
+
// Base point (x, y) aka generator point
|
2418
|
+
Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
|
2419
|
+
Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),
|
2420
|
+
h: BigInt(1),
|
2421
|
+
// Cofactor
|
2422
|
+
lowS: true,
|
2423
|
+
// Allow only low-S signatures by default in sign() and verify()
|
2424
|
+
/**
|
2425
|
+
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
2426
|
+
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
2427
|
+
* For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
2428
|
+
* Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
2429
|
+
*/
|
2430
|
+
endo: {
|
2431
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
2432
|
+
splitScalar: /* @__PURE__ */ __name((k) => {
|
2433
|
+
const n = secp256k1N;
|
2434
|
+
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
2435
|
+
const b1 = -_1n5 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
2436
|
+
const a2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
2437
|
+
const b2 = a1;
|
2438
|
+
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
2439
|
+
const c1 = divNearest(b2 * k, n);
|
2440
|
+
const c2 = divNearest(-b1 * k, n);
|
2441
|
+
let k1 = mod(k - c1 * a1 - c2 * a2, n);
|
2442
|
+
let k2 = mod(-c1 * b1 - c2 * b2, n);
|
2443
|
+
const k1neg = k1 > POW_2_128;
|
2444
|
+
const k2neg = k2 > POW_2_128;
|
2445
|
+
if (k1neg)
|
2446
|
+
k1 = n - k1;
|
2447
|
+
if (k2neg)
|
2448
|
+
k2 = n - k2;
|
2449
|
+
if (k1 > POW_2_128 || k2 > POW_2_128) {
|
2450
|
+
throw new Error("splitScalar: Endomorphism failed, k=" + k);
|
2451
|
+
}
|
2452
|
+
return { k1neg, k1, k2neg, k2 };
|
2453
|
+
}, "splitScalar")
|
2454
|
+
}
|
2455
|
+
}, sha256);
|
2456
|
+
var _0n5 = BigInt(0);
|
2457
|
+
var Point = secp256k1.ProjectivePoint;
|
2458
|
+
|
2459
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_u64.js
|
2460
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
2461
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
2462
|
+
function fromBig(n, le = false) {
|
2463
|
+
if (le)
|
2464
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
2465
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
2466
|
+
}
|
2467
|
+
__name(fromBig, "fromBig");
|
2468
|
+
function split(lst, le = false) {
|
2469
|
+
let Ah = new Uint32Array(lst.length);
|
2470
|
+
let Al = new Uint32Array(lst.length);
|
2471
|
+
for (let i = 0; i < lst.length; i++) {
|
2472
|
+
const { h, l } = fromBig(lst[i], le);
|
2473
|
+
[Ah[i], Al[i]] = [h, l];
|
2474
|
+
}
|
2475
|
+
return [Ah, Al];
|
2476
|
+
}
|
2477
|
+
__name(split, "split");
|
2478
|
+
var toBig = /* @__PURE__ */ __name((h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0), "toBig");
|
2479
|
+
var shrSH = /* @__PURE__ */ __name((h, _l, s) => h >>> s, "shrSH");
|
2480
|
+
var shrSL = /* @__PURE__ */ __name((h, l, s) => h << 32 - s | l >>> s, "shrSL");
|
2481
|
+
var rotrSH = /* @__PURE__ */ __name((h, l, s) => h >>> s | l << 32 - s, "rotrSH");
|
2482
|
+
var rotrSL = /* @__PURE__ */ __name((h, l, s) => h << 32 - s | l >>> s, "rotrSL");
|
2483
|
+
var rotrBH = /* @__PURE__ */ __name((h, l, s) => h << 64 - s | l >>> s - 32, "rotrBH");
|
2484
|
+
var rotrBL = /* @__PURE__ */ __name((h, l, s) => h >>> s - 32 | l << 64 - s, "rotrBL");
|
2485
|
+
var rotr32H = /* @__PURE__ */ __name((_h, l) => l, "rotr32H");
|
2486
|
+
var rotr32L = /* @__PURE__ */ __name((h, _l) => h, "rotr32L");
|
2487
|
+
var rotlSH = /* @__PURE__ */ __name((h, l, s) => h << s | l >>> 32 - s, "rotlSH");
|
2488
|
+
var rotlSL = /* @__PURE__ */ __name((h, l, s) => l << s | h >>> 32 - s, "rotlSL");
|
2489
|
+
var rotlBH = /* @__PURE__ */ __name((h, l, s) => l << s - 32 | h >>> 64 - s, "rotlBH");
|
2490
|
+
var rotlBL = /* @__PURE__ */ __name((h, l, s) => h << s - 32 | l >>> 64 - s, "rotlBL");
|
2491
|
+
function add(Ah, Al, Bh, Bl) {
|
2492
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
2493
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
2494
|
+
}
|
2495
|
+
__name(add, "add");
|
2496
|
+
var add3L = /* @__PURE__ */ __name((Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0), "add3L");
|
2497
|
+
var add3H = /* @__PURE__ */ __name((low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0, "add3H");
|
2498
|
+
var add4L = /* @__PURE__ */ __name((Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0), "add4L");
|
2499
|
+
var add4H = /* @__PURE__ */ __name((low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0, "add4H");
|
2500
|
+
var add5L = /* @__PURE__ */ __name((Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0), "add5L");
|
2501
|
+
var add5H = /* @__PURE__ */ __name((low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0, "add5H");
|
2502
|
+
var u64 = {
|
2503
|
+
fromBig,
|
2504
|
+
split,
|
2505
|
+
toBig,
|
2506
|
+
shrSH,
|
2507
|
+
shrSL,
|
2508
|
+
rotrSH,
|
2509
|
+
rotrSL,
|
2510
|
+
rotrBH,
|
2511
|
+
rotrBL,
|
2512
|
+
rotr32H,
|
2513
|
+
rotr32L,
|
2514
|
+
rotlSH,
|
2515
|
+
rotlSL,
|
2516
|
+
rotlBH,
|
2517
|
+
rotlBL,
|
2518
|
+
add,
|
2519
|
+
add3L,
|
2520
|
+
add3H,
|
2521
|
+
add4L,
|
2522
|
+
add4H,
|
2523
|
+
add5H,
|
2524
|
+
add5L
|
2525
|
+
};
|
2526
|
+
var u64_default = u64;
|
2527
|
+
|
2528
|
+
export {
|
2529
|
+
number,
|
2530
|
+
bytes,
|
2531
|
+
hash,
|
2532
|
+
exists,
|
2533
|
+
output,
|
2534
|
+
u32,
|
2535
|
+
createView,
|
2536
|
+
rotl,
|
2537
|
+
isLE,
|
2538
|
+
byteSwap32,
|
2539
|
+
bytesToHex2 as bytesToHex,
|
2540
|
+
hexToBytes2 as hexToBytes,
|
2541
|
+
utf8ToBytes2 as utf8ToBytes,
|
2542
|
+
toBytes,
|
2543
|
+
concatBytes2 as concatBytes,
|
2544
|
+
Hash,
|
2545
|
+
checkOpts,
|
2546
|
+
wrapConstructor,
|
2547
|
+
wrapXOFConstructorWithOpts,
|
2548
|
+
hmac,
|
2549
|
+
HashMD,
|
2550
|
+
sha256,
|
2551
|
+
split,
|
2552
|
+
rotlSH,
|
2553
|
+
rotlSL,
|
2554
|
+
rotlBH,
|
2555
|
+
rotlBL,
|
2556
|
+
u64_default,
|
2557
|
+
base64,
|
2558
|
+
createBase58check,
|
2559
|
+
bytesToHex as bytesToHex2,
|
2560
|
+
hexToBytes as hexToBytes2,
|
2561
|
+
mod,
|
2562
|
+
validateField,
|
2563
|
+
FpPow,
|
2564
|
+
weierstrass_exports,
|
2565
|
+
secp256k1
|
2566
|
+
};
|
2567
|
+
/*! Bundled license information:
|
2568
|
+
|
2569
|
+
@scure/base/lib/esm/index.js:
|
2570
|
+
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2571
|
+
|
2572
|
+
@noble/curves/esm/abstract/utils.js:
|
2573
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2574
|
+
|
2575
|
+
@noble/curves/esm/abstract/modular.js:
|
2576
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2577
|
+
|
2578
|
+
@noble/curves/esm/abstract/curve.js:
|
2579
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2580
|
+
|
2581
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
2582
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2583
|
+
|
2584
|
+
@noble/hashes/esm/utils.js:
|
2585
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2586
|
+
|
2587
|
+
@noble/curves/esm/_shortw_utils.js:
|
2588
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2589
|
+
|
2590
|
+
@noble/curves/esm/secp256k1.js:
|
2591
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
2592
|
+
*/
|
2593
|
+
//# sourceMappingURL=chunk-LR232ZJV.js.map
|