@lydianpay/sdk-web 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -12
- package/dist/chunks/browser-BFd9Zasn.js +33 -0
- package/dist/chunks/connect-multichain-W5NFpeTb.js +9971 -0
- package/dist/chunks/index-B2KlqxZz.js +5944 -0
- package/dist/chunks/index-B8vFbue_.js +114 -0
- package/dist/chunks/{index-DJbuCqvB.js → index-ChcFlkGu.js} +927 -1293
- package/dist/chunks/{index-DrpAyUns.js → index-DDKaYwMc.js} +101 -83
- package/dist/chunks/index-DhuuCvX-.js +4716 -0
- package/dist/chunks/index-FAg0du7P.js +595 -0
- package/dist/chunks/index-SMHjRBlL.js +314 -0
- package/dist/chunks/mm-install-modal_2.entry-Dhx9nDM_.js +1365 -0
- package/dist/chunks/{mountEngine-DoxKiMjy.js → mountEngine-0u7my-Xz.js} +5715 -5589
- package/dist/chunks/utils-Ca8X9WUu.js +264 -0
- package/dist/lydian.js +1 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/ui/initConfig.d.ts +3 -0
- package/package.json +8 -4
- package/dist/chunks/metamask-sdk-C2ev3Ki6.js +0 -15037
|
@@ -0,0 +1,4716 @@
|
|
|
1
|
+
import { g as cn } from "./mountEngine-0u7my-Xz.js";
|
|
2
|
+
import { a as Ot, r as an } from "./utils-Ca8X9WUu.js";
|
|
3
|
+
function fn(t, f) {
|
|
4
|
+
for (var y = 0; y < f.length; y++) {
|
|
5
|
+
const S = f[y];
|
|
6
|
+
if (typeof S != "string" && !Array.isArray(S)) {
|
|
7
|
+
for (const H in S)
|
|
8
|
+
if (H !== "default" && !(H in t)) {
|
|
9
|
+
const m = Object.getOwnPropertyDescriptor(S, H);
|
|
10
|
+
m && Object.defineProperty(t, H, m.get ? m : {
|
|
11
|
+
enumerable: !0,
|
|
12
|
+
get: () => S[H]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return Object.freeze(Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }));
|
|
18
|
+
}
|
|
19
|
+
var Xt = {}, Wt = {}, me;
|
|
20
|
+
function Ht() {
|
|
21
|
+
return me || (me = 1, (function(t) {
|
|
22
|
+
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
23
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.wrapCipher = t.Hash = t.nextTick = t.isLE = void 0, t.isBytes = f, t.abool = y, t.anumber = S, t.abytes = H, t.ahash = m, t.aexists = I, t.aoutput = D, t.u8 = F, t.u32 = G, t.clean = Y, t.createView = L, t.bytesToHex = d, t.hexToBytes = T, t.hexToNumber = P, t.bytesToNumberBE = V, t.numberToBytesBE = k, t.utf8ToBytes = E, t.bytesToUtf8 = U, t.toBytes = Z, t.overlapBytes = j, t.complexOverlapBytes = z, t.concatBytes = Q, t.checkOpts = X, t.equalBytes = N, t.getOutput = p, t.setBigUint64 = c, t.u64Lengths = s, t.isAligned32 = q, t.copyBytes = K;
|
|
24
|
+
function f(e) {
|
|
25
|
+
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
26
|
+
}
|
|
27
|
+
function y(e) {
|
|
28
|
+
if (typeof e != "boolean")
|
|
29
|
+
throw new Error(`boolean expected, not ${e}`);
|
|
30
|
+
}
|
|
31
|
+
function S(e) {
|
|
32
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
33
|
+
throw new Error("positive integer expected, got " + e);
|
|
34
|
+
}
|
|
35
|
+
function H(e, ...n) {
|
|
36
|
+
if (!f(e))
|
|
37
|
+
throw new Error("Uint8Array expected");
|
|
38
|
+
if (n.length > 0 && !n.includes(e.length))
|
|
39
|
+
throw new Error("Uint8Array expected of length " + n + ", got length=" + e.length);
|
|
40
|
+
}
|
|
41
|
+
function m(e) {
|
|
42
|
+
if (typeof e != "function" || typeof e.create != "function")
|
|
43
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
44
|
+
S(e.outputLen), S(e.blockLen);
|
|
45
|
+
}
|
|
46
|
+
function I(e, n = !0) {
|
|
47
|
+
if (e.destroyed)
|
|
48
|
+
throw new Error("Hash instance has been destroyed");
|
|
49
|
+
if (n && e.finished)
|
|
50
|
+
throw new Error("Hash#digest() has already been called");
|
|
51
|
+
}
|
|
52
|
+
function D(e, n) {
|
|
53
|
+
H(e);
|
|
54
|
+
const r = n.outputLen;
|
|
55
|
+
if (e.length < r)
|
|
56
|
+
throw new Error("digestInto() expects output buffer of length at least " + r);
|
|
57
|
+
}
|
|
58
|
+
function F(e) {
|
|
59
|
+
return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
60
|
+
}
|
|
61
|
+
function G(e) {
|
|
62
|
+
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
63
|
+
}
|
|
64
|
+
function Y(...e) {
|
|
65
|
+
for (let n = 0; n < e.length; n++)
|
|
66
|
+
e[n].fill(0);
|
|
67
|
+
}
|
|
68
|
+
function L(e) {
|
|
69
|
+
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
70
|
+
}
|
|
71
|
+
t.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
72
|
+
const M = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", B = /* @__PURE__ */ Array.from({ length: 256 }, (e, n) => n.toString(16).padStart(2, "0"));
|
|
73
|
+
function d(e) {
|
|
74
|
+
if (H(e), M)
|
|
75
|
+
return e.toHex();
|
|
76
|
+
let n = "";
|
|
77
|
+
for (let r = 0; r < e.length; r++)
|
|
78
|
+
n += B[e[r]];
|
|
79
|
+
return n;
|
|
80
|
+
}
|
|
81
|
+
const w = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
82
|
+
function v(e) {
|
|
83
|
+
if (e >= w._0 && e <= w._9)
|
|
84
|
+
return e - w._0;
|
|
85
|
+
if (e >= w.A && e <= w.F)
|
|
86
|
+
return e - (w.A - 10);
|
|
87
|
+
if (e >= w.a && e <= w.f)
|
|
88
|
+
return e - (w.a - 10);
|
|
89
|
+
}
|
|
90
|
+
function T(e) {
|
|
91
|
+
if (typeof e != "string")
|
|
92
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
93
|
+
if (M)
|
|
94
|
+
return Uint8Array.fromHex(e);
|
|
95
|
+
const n = e.length, r = n / 2;
|
|
96
|
+
if (n % 2)
|
|
97
|
+
throw new Error("hex string expected, got unpadded hex of length " + n);
|
|
98
|
+
const i = new Uint8Array(r);
|
|
99
|
+
for (let a = 0, b = 0; a < r; a++, b += 2) {
|
|
100
|
+
const A = v(e.charCodeAt(b)), u = v(e.charCodeAt(b + 1));
|
|
101
|
+
if (A === void 0 || u === void 0) {
|
|
102
|
+
const l = e[b] + e[b + 1];
|
|
103
|
+
throw new Error('hex string expected, got non-hex character "' + l + '" at index ' + b);
|
|
104
|
+
}
|
|
105
|
+
i[a] = A * 16 + u;
|
|
106
|
+
}
|
|
107
|
+
return i;
|
|
108
|
+
}
|
|
109
|
+
function P(e) {
|
|
110
|
+
if (typeof e != "string")
|
|
111
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
112
|
+
return BigInt(e === "" ? "0" : "0x" + e);
|
|
113
|
+
}
|
|
114
|
+
function V(e) {
|
|
115
|
+
return P(d(e));
|
|
116
|
+
}
|
|
117
|
+
function k(e, n) {
|
|
118
|
+
return T(e.toString(16).padStart(n * 2, "0"));
|
|
119
|
+
}
|
|
120
|
+
const O = async () => {
|
|
121
|
+
};
|
|
122
|
+
t.nextTick = O;
|
|
123
|
+
function E(e) {
|
|
124
|
+
if (typeof e != "string")
|
|
125
|
+
throw new Error("string expected");
|
|
126
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
127
|
+
}
|
|
128
|
+
function U(e) {
|
|
129
|
+
return new TextDecoder().decode(e);
|
|
130
|
+
}
|
|
131
|
+
function Z(e) {
|
|
132
|
+
if (typeof e == "string")
|
|
133
|
+
e = E(e);
|
|
134
|
+
else if (f(e))
|
|
135
|
+
e = K(e);
|
|
136
|
+
else
|
|
137
|
+
throw new Error("Uint8Array expected, got " + typeof e);
|
|
138
|
+
return e;
|
|
139
|
+
}
|
|
140
|
+
function j(e, n) {
|
|
141
|
+
return e.buffer === n.buffer && // best we can do, may fail with an obscure Proxy
|
|
142
|
+
e.byteOffset < n.byteOffset + n.byteLength && // a starts before b end
|
|
143
|
+
n.byteOffset < e.byteOffset + e.byteLength;
|
|
144
|
+
}
|
|
145
|
+
function z(e, n) {
|
|
146
|
+
if (j(e, n) && e.byteOffset < n.byteOffset)
|
|
147
|
+
throw new Error("complex overlap of input and output is not supported");
|
|
148
|
+
}
|
|
149
|
+
function Q(...e) {
|
|
150
|
+
let n = 0;
|
|
151
|
+
for (let i = 0; i < e.length; i++) {
|
|
152
|
+
const a = e[i];
|
|
153
|
+
H(a), n += a.length;
|
|
154
|
+
}
|
|
155
|
+
const r = new Uint8Array(n);
|
|
156
|
+
for (let i = 0, a = 0; i < e.length; i++) {
|
|
157
|
+
const b = e[i];
|
|
158
|
+
r.set(b, a), a += b.length;
|
|
159
|
+
}
|
|
160
|
+
return r;
|
|
161
|
+
}
|
|
162
|
+
function X(e, n) {
|
|
163
|
+
if (n == null || typeof n != "object")
|
|
164
|
+
throw new Error("options must be defined");
|
|
165
|
+
return Object.assign(e, n);
|
|
166
|
+
}
|
|
167
|
+
function N(e, n) {
|
|
168
|
+
if (e.length !== n.length)
|
|
169
|
+
return !1;
|
|
170
|
+
let r = 0;
|
|
171
|
+
for (let i = 0; i < e.length; i++)
|
|
172
|
+
r |= e[i] ^ n[i];
|
|
173
|
+
return r === 0;
|
|
174
|
+
}
|
|
175
|
+
class R {
|
|
176
|
+
}
|
|
177
|
+
t.Hash = R;
|
|
178
|
+
const o = /* @__NO_SIDE_EFFECTS__ */ (e, n) => {
|
|
179
|
+
function r(i, ...a) {
|
|
180
|
+
if (H(i), !t.isLE)
|
|
181
|
+
throw new Error("Non little-endian hardware is not yet supported");
|
|
182
|
+
if (e.nonceLength !== void 0) {
|
|
183
|
+
const _ = a[0];
|
|
184
|
+
if (!_)
|
|
185
|
+
throw new Error("nonce / iv required");
|
|
186
|
+
e.varSizeNonce ? H(_) : H(_, e.nonceLength);
|
|
187
|
+
}
|
|
188
|
+
const b = e.tagLength;
|
|
189
|
+
b && a[1] !== void 0 && H(a[1]);
|
|
190
|
+
const A = n(i, ...a), u = (_, C) => {
|
|
191
|
+
if (C !== void 0) {
|
|
192
|
+
if (_ !== 2)
|
|
193
|
+
throw new Error("cipher output not supported");
|
|
194
|
+
H(C);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
let l = !1;
|
|
198
|
+
return {
|
|
199
|
+
encrypt(_, C) {
|
|
200
|
+
if (l)
|
|
201
|
+
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
202
|
+
return l = !0, H(_), u(A.encrypt.length, C), A.encrypt(_, C);
|
|
203
|
+
},
|
|
204
|
+
decrypt(_, C) {
|
|
205
|
+
if (H(_), b && _.length < b)
|
|
206
|
+
throw new Error("invalid ciphertext length: smaller than tagLength=" + b);
|
|
207
|
+
return u(A.decrypt.length, C), A.decrypt(_, C);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return Object.assign(r, e), r;
|
|
212
|
+
};
|
|
213
|
+
t.wrapCipher = o;
|
|
214
|
+
function p(e, n, r = !0) {
|
|
215
|
+
if (n === void 0)
|
|
216
|
+
return new Uint8Array(e);
|
|
217
|
+
if (n.length !== e)
|
|
218
|
+
throw new Error("invalid output length, expected " + e + ", got: " + n.length);
|
|
219
|
+
if (r && !q(n))
|
|
220
|
+
throw new Error("invalid output, must be aligned");
|
|
221
|
+
return n;
|
|
222
|
+
}
|
|
223
|
+
function c(e, n, r, i) {
|
|
224
|
+
if (typeof e.setBigUint64 == "function")
|
|
225
|
+
return e.setBigUint64(n, r, i);
|
|
226
|
+
const a = BigInt(32), b = BigInt(4294967295), A = Number(r >> a & b), u = Number(r & b), l = i ? 4 : 0, g = i ? 0 : 4;
|
|
227
|
+
e.setUint32(n + l, A, i), e.setUint32(n + g, u, i);
|
|
228
|
+
}
|
|
229
|
+
function s(e, n, r) {
|
|
230
|
+
y(r);
|
|
231
|
+
const i = new Uint8Array(16), a = L(i);
|
|
232
|
+
return c(a, 0, BigInt(n), r), c(a, 8, BigInt(e), r), i;
|
|
233
|
+
}
|
|
234
|
+
function q(e) {
|
|
235
|
+
return e.byteOffset % 4 === 0;
|
|
236
|
+
}
|
|
237
|
+
function K(e) {
|
|
238
|
+
return Uint8Array.from(e);
|
|
239
|
+
}
|
|
240
|
+
})(Wt)), Wt;
|
|
241
|
+
}
|
|
242
|
+
var Ft = {}, St = {}, we;
|
|
243
|
+
function le() {
|
|
244
|
+
return we || (we = 1, Object.defineProperty(St, "__esModule", { value: !0 }), St.AEAD_TAG_LENGTH = St.XCHACHA20_NONCE_LENGTH = St.CURVE25519_PUBLIC_KEY_SIZE = St.ETH_PUBLIC_KEY_SIZE = St.UNCOMPRESSED_PUBLIC_KEY_SIZE = St.COMPRESSED_PUBLIC_KEY_SIZE = St.SECRET_KEY_LENGTH = void 0, St.SECRET_KEY_LENGTH = 32, St.COMPRESSED_PUBLIC_KEY_SIZE = 33, St.UNCOMPRESSED_PUBLIC_KEY_SIZE = 65, St.ETH_PUBLIC_KEY_SIZE = 64, St.CURVE25519_PUBLIC_KEY_SIZE = 32, St.XCHACHA20_NONCE_LENGTH = 24, St.AEAD_TAG_LENGTH = 16), St;
|
|
245
|
+
}
|
|
246
|
+
var _e;
|
|
247
|
+
function zt() {
|
|
248
|
+
return _e || (_e = 1, (function(t) {
|
|
249
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.ephemeralKeySize = t.symmetricNonceLength = t.symmetricAlgorithm = t.isHkdfKeyCompressed = t.isEphemeralKeyCompressed = t.ellipticCurve = t.ECIES_CONFIG = t.Config = void 0;
|
|
250
|
+
var f = le(), y = (
|
|
251
|
+
/** @class */
|
|
252
|
+
(function() {
|
|
253
|
+
function G() {
|
|
254
|
+
this.ellipticCurve = "secp256k1", this.isEphemeralKeyCompressed = !1, this.isHkdfKeyCompressed = !1, this.symmetricAlgorithm = "aes-256-gcm", this.symmetricNonceLength = 16;
|
|
255
|
+
}
|
|
256
|
+
return Object.defineProperty(G.prototype, "ephemeralKeySize", {
|
|
257
|
+
get: function() {
|
|
258
|
+
var Y = {
|
|
259
|
+
secp256k1: this.isEphemeralKeyCompressed ? f.COMPRESSED_PUBLIC_KEY_SIZE : f.UNCOMPRESSED_PUBLIC_KEY_SIZE,
|
|
260
|
+
x25519: f.CURVE25519_PUBLIC_KEY_SIZE,
|
|
261
|
+
ed25519: f.CURVE25519_PUBLIC_KEY_SIZE
|
|
262
|
+
};
|
|
263
|
+
/* v8 ignore else -- @preserve */
|
|
264
|
+
if (this.ellipticCurve in Y)
|
|
265
|
+
return Y[this.ellipticCurve];
|
|
266
|
+
throw new Error("Not implemented");
|
|
267
|
+
},
|
|
268
|
+
enumerable: !1,
|
|
269
|
+
configurable: !0
|
|
270
|
+
}), G;
|
|
271
|
+
})()
|
|
272
|
+
);
|
|
273
|
+
t.Config = y, t.ECIES_CONFIG = new y();
|
|
274
|
+
var S = function() {
|
|
275
|
+
return t.ECIES_CONFIG.ellipticCurve;
|
|
276
|
+
};
|
|
277
|
+
t.ellipticCurve = S;
|
|
278
|
+
var H = function() {
|
|
279
|
+
return t.ECIES_CONFIG.isEphemeralKeyCompressed;
|
|
280
|
+
};
|
|
281
|
+
t.isEphemeralKeyCompressed = H;
|
|
282
|
+
var m = function() {
|
|
283
|
+
return t.ECIES_CONFIG.isHkdfKeyCompressed;
|
|
284
|
+
};
|
|
285
|
+
t.isHkdfKeyCompressed = m;
|
|
286
|
+
var I = function() {
|
|
287
|
+
return t.ECIES_CONFIG.symmetricAlgorithm;
|
|
288
|
+
};
|
|
289
|
+
t.symmetricAlgorithm = I;
|
|
290
|
+
var D = function() {
|
|
291
|
+
return t.ECIES_CONFIG.symmetricNonceLength;
|
|
292
|
+
};
|
|
293
|
+
t.symmetricNonceLength = D;
|
|
294
|
+
var F = function() {
|
|
295
|
+
return t.ECIES_CONFIG.ephemeralKeySize;
|
|
296
|
+
};
|
|
297
|
+
t.ephemeralKeySize = F;
|
|
298
|
+
})(Ft)), Ft;
|
|
299
|
+
}
|
|
300
|
+
var $t = {}, Vt = {}, Rt = {}, Qt = {}, Jt = {}, jt = {}, pe;
|
|
301
|
+
function un() {
|
|
302
|
+
return pe || (pe = 1, Object.defineProperty(jt, "__esModule", { value: !0 }), jt.crypto = void 0, jt.crypto = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0), jt;
|
|
303
|
+
}
|
|
304
|
+
var ve;
|
|
305
|
+
function Je() {
|
|
306
|
+
return ve || (ve = 1, (function(t) {
|
|
307
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.gcm = t.ctr = t.cbc = t.utils = void 0, t.randomBytes = S, t.getWebcryptoSubtle = H, t.managedNonce = m;
|
|
308
|
+
const f = /* @__PURE__ */ un(), y = /* @__PURE__ */ Ht();
|
|
309
|
+
function S(G = 32) {
|
|
310
|
+
if (f.crypto && typeof f.crypto.getRandomValues == "function")
|
|
311
|
+
return f.crypto.getRandomValues(new Uint8Array(G));
|
|
312
|
+
if (f.crypto && typeof f.crypto.randomBytes == "function")
|
|
313
|
+
return Uint8Array.from(f.crypto.randomBytes(G));
|
|
314
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
315
|
+
}
|
|
316
|
+
function H() {
|
|
317
|
+
if (f.crypto && typeof f.crypto.subtle == "object" && f.crypto.subtle != null)
|
|
318
|
+
return f.crypto.subtle;
|
|
319
|
+
throw new Error("crypto.subtle must be defined");
|
|
320
|
+
}
|
|
321
|
+
function m(G) {
|
|
322
|
+
const { nonceLength: Y } = G;
|
|
323
|
+
return (0, y.anumber)(Y), ((L, ...M) => ({
|
|
324
|
+
encrypt(B, ...d) {
|
|
325
|
+
const w = S(Y), v = G(L, w, ...M).encrypt(B, ...d), T = (0, y.concatBytes)(w, v);
|
|
326
|
+
return v.fill(0), T;
|
|
327
|
+
},
|
|
328
|
+
decrypt(B, ...d) {
|
|
329
|
+
const w = B.subarray(0, Y), v = B.subarray(Y);
|
|
330
|
+
return G(L, w, ...M).decrypt(v, ...d);
|
|
331
|
+
}
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
t.utils = {
|
|
335
|
+
async encrypt(G, Y, L, M) {
|
|
336
|
+
const B = H(), d = await B.importKey("raw", G, Y, !0, ["encrypt"]), w = await B.encrypt(L, d, M);
|
|
337
|
+
return new Uint8Array(w);
|
|
338
|
+
},
|
|
339
|
+
async decrypt(G, Y, L, M) {
|
|
340
|
+
const B = H(), d = await B.importKey("raw", G, Y, !0, ["decrypt"]), w = await B.decrypt(L, d, M);
|
|
341
|
+
return new Uint8Array(w);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const I = {
|
|
345
|
+
CBC: "AES-CBC",
|
|
346
|
+
CTR: "AES-CTR",
|
|
347
|
+
GCM: "AES-GCM"
|
|
348
|
+
};
|
|
349
|
+
function D(G, Y, L) {
|
|
350
|
+
if (G === I.CBC)
|
|
351
|
+
return { name: I.CBC, iv: Y };
|
|
352
|
+
if (G === I.CTR)
|
|
353
|
+
return { name: I.CTR, counter: Y, length: 64 };
|
|
354
|
+
if (G === I.GCM)
|
|
355
|
+
return L ? { name: I.GCM, iv: Y, additionalData: L } : { name: I.GCM, iv: Y };
|
|
356
|
+
throw new Error("unknown aes block mode");
|
|
357
|
+
}
|
|
358
|
+
function F(G) {
|
|
359
|
+
return (Y, L, M) => {
|
|
360
|
+
(0, y.abytes)(Y), (0, y.abytes)(L);
|
|
361
|
+
const B = { name: G, length: Y.length * 8 }, d = D(G, L, M);
|
|
362
|
+
let w = !1;
|
|
363
|
+
return {
|
|
364
|
+
// keyLength,
|
|
365
|
+
encrypt(v) {
|
|
366
|
+
if ((0, y.abytes)(v), w)
|
|
367
|
+
throw new Error("Cannot encrypt() twice with same key / nonce");
|
|
368
|
+
return w = !0, t.utils.encrypt(Y, B, d, v);
|
|
369
|
+
},
|
|
370
|
+
decrypt(v) {
|
|
371
|
+
return (0, y.abytes)(v), t.utils.decrypt(Y, B, d, v);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
t.cbc = F(I.CBC), t.ctr = F(I.CTR), t.gcm = F(I.GCM);
|
|
377
|
+
})(Jt)), Jt;
|
|
378
|
+
}
|
|
379
|
+
var te = {}, mt = {}, At = {}, Ee;
|
|
380
|
+
function ln() {
|
|
381
|
+
if (Ee) return At;
|
|
382
|
+
Ee = 1, Object.defineProperty(At, "__esModule", { value: !0 }), At.SHA512_IV = At.SHA384_IV = At.SHA224_IV = At.SHA256_IV = At.HashMD = void 0, At.setBigUint64 = f, At.Chi = y, At.Maj = S;
|
|
383
|
+
const t = /* @__PURE__ */ Ot();
|
|
384
|
+
function f(m, I, D, F) {
|
|
385
|
+
if (typeof m.setBigUint64 == "function")
|
|
386
|
+
return m.setBigUint64(I, D, F);
|
|
387
|
+
const G = BigInt(32), Y = BigInt(4294967295), L = Number(D >> G & Y), M = Number(D & Y), B = F ? 4 : 0, d = F ? 0 : 4;
|
|
388
|
+
m.setUint32(I + B, L, F), m.setUint32(I + d, M, F);
|
|
389
|
+
}
|
|
390
|
+
function y(m, I, D) {
|
|
391
|
+
return m & I ^ ~m & D;
|
|
392
|
+
}
|
|
393
|
+
function S(m, I, D) {
|
|
394
|
+
return m & I ^ m & D ^ I & D;
|
|
395
|
+
}
|
|
396
|
+
class H extends t.Hash {
|
|
397
|
+
constructor(I, D, F, G) {
|
|
398
|
+
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = I, this.outputLen = D, this.padOffset = F, this.isLE = G, this.buffer = new Uint8Array(I), this.view = (0, t.createView)(this.buffer);
|
|
399
|
+
}
|
|
400
|
+
update(I) {
|
|
401
|
+
(0, t.aexists)(this), I = (0, t.toBytes)(I), (0, t.abytes)(I);
|
|
402
|
+
const { view: D, buffer: F, blockLen: G } = this, Y = I.length;
|
|
403
|
+
for (let L = 0; L < Y; ) {
|
|
404
|
+
const M = Math.min(G - this.pos, Y - L);
|
|
405
|
+
if (M === G) {
|
|
406
|
+
const B = (0, t.createView)(I);
|
|
407
|
+
for (; G <= Y - L; L += G)
|
|
408
|
+
this.process(B, L);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
F.set(I.subarray(L, L + M), this.pos), this.pos += M, L += M, this.pos === G && (this.process(D, 0), this.pos = 0);
|
|
412
|
+
}
|
|
413
|
+
return this.length += I.length, this.roundClean(), this;
|
|
414
|
+
}
|
|
415
|
+
digestInto(I) {
|
|
416
|
+
(0, t.aexists)(this), (0, t.aoutput)(I, this), this.finished = !0;
|
|
417
|
+
const { buffer: D, view: F, blockLen: G, isLE: Y } = this;
|
|
418
|
+
let { pos: L } = this;
|
|
419
|
+
D[L++] = 128, (0, t.clean)(this.buffer.subarray(L)), this.padOffset > G - L && (this.process(F, 0), L = 0);
|
|
420
|
+
for (let v = L; v < G; v++)
|
|
421
|
+
D[v] = 0;
|
|
422
|
+
f(F, G - 8, BigInt(this.length * 8), Y), this.process(F, 0);
|
|
423
|
+
const M = (0, t.createView)(I), B = this.outputLen;
|
|
424
|
+
if (B % 4)
|
|
425
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
426
|
+
const d = B / 4, w = this.get();
|
|
427
|
+
if (d > w.length)
|
|
428
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
429
|
+
for (let v = 0; v < d; v++)
|
|
430
|
+
M.setUint32(4 * v, w[v], Y);
|
|
431
|
+
}
|
|
432
|
+
digest() {
|
|
433
|
+
const { buffer: I, outputLen: D } = this;
|
|
434
|
+
this.digestInto(I);
|
|
435
|
+
const F = I.slice(0, D);
|
|
436
|
+
return this.destroy(), F;
|
|
437
|
+
}
|
|
438
|
+
_cloneInto(I) {
|
|
439
|
+
I || (I = new this.constructor()), I.set(...this.get());
|
|
440
|
+
const { blockLen: D, buffer: F, length: G, finished: Y, destroyed: L, pos: M } = this;
|
|
441
|
+
return I.destroyed = L, I.finished = Y, I.length = G, I.pos = M, G % D && I.buffer.set(F), I;
|
|
442
|
+
}
|
|
443
|
+
clone() {
|
|
444
|
+
return this._cloneInto();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return At.HashMD = H, At.SHA256_IV = Uint32Array.from([
|
|
448
|
+
1779033703,
|
|
449
|
+
3144134277,
|
|
450
|
+
1013904242,
|
|
451
|
+
2773480762,
|
|
452
|
+
1359893119,
|
|
453
|
+
2600822924,
|
|
454
|
+
528734635,
|
|
455
|
+
1541459225
|
|
456
|
+
]), At.SHA224_IV = Uint32Array.from([
|
|
457
|
+
3238371032,
|
|
458
|
+
914150663,
|
|
459
|
+
812702999,
|
|
460
|
+
4144912697,
|
|
461
|
+
4290775857,
|
|
462
|
+
1750603025,
|
|
463
|
+
1694076839,
|
|
464
|
+
3204075428
|
|
465
|
+
]), At.SHA384_IV = Uint32Array.from([
|
|
466
|
+
3418070365,
|
|
467
|
+
3238371032,
|
|
468
|
+
1654270250,
|
|
469
|
+
914150663,
|
|
470
|
+
2438529370,
|
|
471
|
+
812702999,
|
|
472
|
+
355462360,
|
|
473
|
+
4144912697,
|
|
474
|
+
1731405415,
|
|
475
|
+
4290775857,
|
|
476
|
+
2394180231,
|
|
477
|
+
1750603025,
|
|
478
|
+
3675008525,
|
|
479
|
+
1694076839,
|
|
480
|
+
1203062813,
|
|
481
|
+
3204075428
|
|
482
|
+
]), At.SHA512_IV = Uint32Array.from([
|
|
483
|
+
1779033703,
|
|
484
|
+
4089235720,
|
|
485
|
+
3144134277,
|
|
486
|
+
2227873595,
|
|
487
|
+
1013904242,
|
|
488
|
+
4271175723,
|
|
489
|
+
2773480762,
|
|
490
|
+
1595750129,
|
|
491
|
+
1359893119,
|
|
492
|
+
2917565137,
|
|
493
|
+
2600822924,
|
|
494
|
+
725511199,
|
|
495
|
+
528734635,
|
|
496
|
+
4215389547,
|
|
497
|
+
1541459225,
|
|
498
|
+
327033209
|
|
499
|
+
]), At;
|
|
500
|
+
}
|
|
501
|
+
var Be;
|
|
502
|
+
function de() {
|
|
503
|
+
if (Be) return mt;
|
|
504
|
+
Be = 1, Object.defineProperty(mt, "__esModule", { value: !0 }), mt.sha512_224 = mt.sha512_256 = mt.sha384 = mt.sha512 = mt.sha224 = mt.sha256 = mt.SHA512_256 = mt.SHA512_224 = mt.SHA384 = mt.SHA512 = mt.SHA224 = mt.SHA256 = void 0;
|
|
505
|
+
const t = /* @__PURE__ */ ln(), f = /* @__PURE__ */ an(), y = /* @__PURE__ */ Ot(), S = /* @__PURE__ */ Uint32Array.from([
|
|
506
|
+
1116352408,
|
|
507
|
+
1899447441,
|
|
508
|
+
3049323471,
|
|
509
|
+
3921009573,
|
|
510
|
+
961987163,
|
|
511
|
+
1508970993,
|
|
512
|
+
2453635748,
|
|
513
|
+
2870763221,
|
|
514
|
+
3624381080,
|
|
515
|
+
310598401,
|
|
516
|
+
607225278,
|
|
517
|
+
1426881987,
|
|
518
|
+
1925078388,
|
|
519
|
+
2162078206,
|
|
520
|
+
2614888103,
|
|
521
|
+
3248222580,
|
|
522
|
+
3835390401,
|
|
523
|
+
4022224774,
|
|
524
|
+
264347078,
|
|
525
|
+
604807628,
|
|
526
|
+
770255983,
|
|
527
|
+
1249150122,
|
|
528
|
+
1555081692,
|
|
529
|
+
1996064986,
|
|
530
|
+
2554220882,
|
|
531
|
+
2821834349,
|
|
532
|
+
2952996808,
|
|
533
|
+
3210313671,
|
|
534
|
+
3336571891,
|
|
535
|
+
3584528711,
|
|
536
|
+
113926993,
|
|
537
|
+
338241895,
|
|
538
|
+
666307205,
|
|
539
|
+
773529912,
|
|
540
|
+
1294757372,
|
|
541
|
+
1396182291,
|
|
542
|
+
1695183700,
|
|
543
|
+
1986661051,
|
|
544
|
+
2177026350,
|
|
545
|
+
2456956037,
|
|
546
|
+
2730485921,
|
|
547
|
+
2820302411,
|
|
548
|
+
3259730800,
|
|
549
|
+
3345764771,
|
|
550
|
+
3516065817,
|
|
551
|
+
3600352804,
|
|
552
|
+
4094571909,
|
|
553
|
+
275423344,
|
|
554
|
+
430227734,
|
|
555
|
+
506948616,
|
|
556
|
+
659060556,
|
|
557
|
+
883997877,
|
|
558
|
+
958139571,
|
|
559
|
+
1322822218,
|
|
560
|
+
1537002063,
|
|
561
|
+
1747873779,
|
|
562
|
+
1955562222,
|
|
563
|
+
2024104815,
|
|
564
|
+
2227730452,
|
|
565
|
+
2361852424,
|
|
566
|
+
2428436474,
|
|
567
|
+
2756734187,
|
|
568
|
+
3204031479,
|
|
569
|
+
3329325298
|
|
570
|
+
]), H = /* @__PURE__ */ new Uint32Array(64);
|
|
571
|
+
class m extends t.HashMD {
|
|
572
|
+
constructor(V = 32) {
|
|
573
|
+
super(64, V, 8, !1), this.A = t.SHA256_IV[0] | 0, this.B = t.SHA256_IV[1] | 0, this.C = t.SHA256_IV[2] | 0, this.D = t.SHA256_IV[3] | 0, this.E = t.SHA256_IV[4] | 0, this.F = t.SHA256_IV[5] | 0, this.G = t.SHA256_IV[6] | 0, this.H = t.SHA256_IV[7] | 0;
|
|
574
|
+
}
|
|
575
|
+
get() {
|
|
576
|
+
const { A: V, B: k, C: O, D: E, E: U, F: Z, G: j, H: z } = this;
|
|
577
|
+
return [V, k, O, E, U, Z, j, z];
|
|
578
|
+
}
|
|
579
|
+
// prettier-ignore
|
|
580
|
+
set(V, k, O, E, U, Z, j, z) {
|
|
581
|
+
this.A = V | 0, this.B = k | 0, this.C = O | 0, this.D = E | 0, this.E = U | 0, this.F = Z | 0, this.G = j | 0, this.H = z | 0;
|
|
582
|
+
}
|
|
583
|
+
process(V, k) {
|
|
584
|
+
for (let N = 0; N < 16; N++, k += 4)
|
|
585
|
+
H[N] = V.getUint32(k, !1);
|
|
586
|
+
for (let N = 16; N < 64; N++) {
|
|
587
|
+
const R = H[N - 15], o = H[N - 2], p = (0, y.rotr)(R, 7) ^ (0, y.rotr)(R, 18) ^ R >>> 3, c = (0, y.rotr)(o, 17) ^ (0, y.rotr)(o, 19) ^ o >>> 10;
|
|
588
|
+
H[N] = c + H[N - 7] + p + H[N - 16] | 0;
|
|
589
|
+
}
|
|
590
|
+
let { A: O, B: E, C: U, D: Z, E: j, F: z, G: Q, H: X } = this;
|
|
591
|
+
for (let N = 0; N < 64; N++) {
|
|
592
|
+
const R = (0, y.rotr)(j, 6) ^ (0, y.rotr)(j, 11) ^ (0, y.rotr)(j, 25), o = X + R + (0, t.Chi)(j, z, Q) + S[N] + H[N] | 0, c = ((0, y.rotr)(O, 2) ^ (0, y.rotr)(O, 13) ^ (0, y.rotr)(O, 22)) + (0, t.Maj)(O, E, U) | 0;
|
|
593
|
+
X = Q, Q = z, z = j, j = Z + o | 0, Z = U, U = E, E = O, O = o + c | 0;
|
|
594
|
+
}
|
|
595
|
+
O = O + this.A | 0, E = E + this.B | 0, U = U + this.C | 0, Z = Z + this.D | 0, j = j + this.E | 0, z = z + this.F | 0, Q = Q + this.G | 0, X = X + this.H | 0, this.set(O, E, U, Z, j, z, Q, X);
|
|
596
|
+
}
|
|
597
|
+
roundClean() {
|
|
598
|
+
(0, y.clean)(H);
|
|
599
|
+
}
|
|
600
|
+
destroy() {
|
|
601
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), (0, y.clean)(this.buffer);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
mt.SHA256 = m;
|
|
605
|
+
class I extends m {
|
|
606
|
+
constructor() {
|
|
607
|
+
super(28), this.A = t.SHA224_IV[0] | 0, this.B = t.SHA224_IV[1] | 0, this.C = t.SHA224_IV[2] | 0, this.D = t.SHA224_IV[3] | 0, this.E = t.SHA224_IV[4] | 0, this.F = t.SHA224_IV[5] | 0, this.G = t.SHA224_IV[6] | 0, this.H = t.SHA224_IV[7] | 0;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
mt.SHA224 = I;
|
|
611
|
+
const D = f.split([
|
|
612
|
+
"0x428a2f98d728ae22",
|
|
613
|
+
"0x7137449123ef65cd",
|
|
614
|
+
"0xb5c0fbcfec4d3b2f",
|
|
615
|
+
"0xe9b5dba58189dbbc",
|
|
616
|
+
"0x3956c25bf348b538",
|
|
617
|
+
"0x59f111f1b605d019",
|
|
618
|
+
"0x923f82a4af194f9b",
|
|
619
|
+
"0xab1c5ed5da6d8118",
|
|
620
|
+
"0xd807aa98a3030242",
|
|
621
|
+
"0x12835b0145706fbe",
|
|
622
|
+
"0x243185be4ee4b28c",
|
|
623
|
+
"0x550c7dc3d5ffb4e2",
|
|
624
|
+
"0x72be5d74f27b896f",
|
|
625
|
+
"0x80deb1fe3b1696b1",
|
|
626
|
+
"0x9bdc06a725c71235",
|
|
627
|
+
"0xc19bf174cf692694",
|
|
628
|
+
"0xe49b69c19ef14ad2",
|
|
629
|
+
"0xefbe4786384f25e3",
|
|
630
|
+
"0x0fc19dc68b8cd5b5",
|
|
631
|
+
"0x240ca1cc77ac9c65",
|
|
632
|
+
"0x2de92c6f592b0275",
|
|
633
|
+
"0x4a7484aa6ea6e483",
|
|
634
|
+
"0x5cb0a9dcbd41fbd4",
|
|
635
|
+
"0x76f988da831153b5",
|
|
636
|
+
"0x983e5152ee66dfab",
|
|
637
|
+
"0xa831c66d2db43210",
|
|
638
|
+
"0xb00327c898fb213f",
|
|
639
|
+
"0xbf597fc7beef0ee4",
|
|
640
|
+
"0xc6e00bf33da88fc2",
|
|
641
|
+
"0xd5a79147930aa725",
|
|
642
|
+
"0x06ca6351e003826f",
|
|
643
|
+
"0x142929670a0e6e70",
|
|
644
|
+
"0x27b70a8546d22ffc",
|
|
645
|
+
"0x2e1b21385c26c926",
|
|
646
|
+
"0x4d2c6dfc5ac42aed",
|
|
647
|
+
"0x53380d139d95b3df",
|
|
648
|
+
"0x650a73548baf63de",
|
|
649
|
+
"0x766a0abb3c77b2a8",
|
|
650
|
+
"0x81c2c92e47edaee6",
|
|
651
|
+
"0x92722c851482353b",
|
|
652
|
+
"0xa2bfe8a14cf10364",
|
|
653
|
+
"0xa81a664bbc423001",
|
|
654
|
+
"0xc24b8b70d0f89791",
|
|
655
|
+
"0xc76c51a30654be30",
|
|
656
|
+
"0xd192e819d6ef5218",
|
|
657
|
+
"0xd69906245565a910",
|
|
658
|
+
"0xf40e35855771202a",
|
|
659
|
+
"0x106aa07032bbd1b8",
|
|
660
|
+
"0x19a4c116b8d2d0c8",
|
|
661
|
+
"0x1e376c085141ab53",
|
|
662
|
+
"0x2748774cdf8eeb99",
|
|
663
|
+
"0x34b0bcb5e19b48a8",
|
|
664
|
+
"0x391c0cb3c5c95a63",
|
|
665
|
+
"0x4ed8aa4ae3418acb",
|
|
666
|
+
"0x5b9cca4f7763e373",
|
|
667
|
+
"0x682e6ff3d6b2b8a3",
|
|
668
|
+
"0x748f82ee5defb2fc",
|
|
669
|
+
"0x78a5636f43172f60",
|
|
670
|
+
"0x84c87814a1f0ab72",
|
|
671
|
+
"0x8cc702081a6439ec",
|
|
672
|
+
"0x90befffa23631e28",
|
|
673
|
+
"0xa4506cebde82bde9",
|
|
674
|
+
"0xbef9a3f7b2c67915",
|
|
675
|
+
"0xc67178f2e372532b",
|
|
676
|
+
"0xca273eceea26619c",
|
|
677
|
+
"0xd186b8c721c0c207",
|
|
678
|
+
"0xeada7dd6cde0eb1e",
|
|
679
|
+
"0xf57d4f7fee6ed178",
|
|
680
|
+
"0x06f067aa72176fba",
|
|
681
|
+
"0x0a637dc5a2c898a6",
|
|
682
|
+
"0x113f9804bef90dae",
|
|
683
|
+
"0x1b710b35131c471b",
|
|
684
|
+
"0x28db77f523047d84",
|
|
685
|
+
"0x32caab7b40c72493",
|
|
686
|
+
"0x3c9ebe0a15c9bebc",
|
|
687
|
+
"0x431d67c49c100d4c",
|
|
688
|
+
"0x4cc5d4becb3e42b6",
|
|
689
|
+
"0x597f299cfc657e2a",
|
|
690
|
+
"0x5fcb6fab3ad6faec",
|
|
691
|
+
"0x6c44198c4a475817"
|
|
692
|
+
].map((P) => BigInt(P))), F = D[0], G = D[1], Y = /* @__PURE__ */ new Uint32Array(80), L = /* @__PURE__ */ new Uint32Array(80);
|
|
693
|
+
class M extends t.HashMD {
|
|
694
|
+
constructor(V = 64) {
|
|
695
|
+
super(128, V, 16, !1), this.Ah = t.SHA512_IV[0] | 0, this.Al = t.SHA512_IV[1] | 0, this.Bh = t.SHA512_IV[2] | 0, this.Bl = t.SHA512_IV[3] | 0, this.Ch = t.SHA512_IV[4] | 0, this.Cl = t.SHA512_IV[5] | 0, this.Dh = t.SHA512_IV[6] | 0, this.Dl = t.SHA512_IV[7] | 0, this.Eh = t.SHA512_IV[8] | 0, this.El = t.SHA512_IV[9] | 0, this.Fh = t.SHA512_IV[10] | 0, this.Fl = t.SHA512_IV[11] | 0, this.Gh = t.SHA512_IV[12] | 0, this.Gl = t.SHA512_IV[13] | 0, this.Hh = t.SHA512_IV[14] | 0, this.Hl = t.SHA512_IV[15] | 0;
|
|
696
|
+
}
|
|
697
|
+
// prettier-ignore
|
|
698
|
+
get() {
|
|
699
|
+
const { Ah: V, Al: k, Bh: O, Bl: E, Ch: U, Cl: Z, Dh: j, Dl: z, Eh: Q, El: X, Fh: N, Fl: R, Gh: o, Gl: p, Hh: c, Hl: s } = this;
|
|
700
|
+
return [V, k, O, E, U, Z, j, z, Q, X, N, R, o, p, c, s];
|
|
701
|
+
}
|
|
702
|
+
// prettier-ignore
|
|
703
|
+
set(V, k, O, E, U, Z, j, z, Q, X, N, R, o, p, c, s) {
|
|
704
|
+
this.Ah = V | 0, this.Al = k | 0, this.Bh = O | 0, this.Bl = E | 0, this.Ch = U | 0, this.Cl = Z | 0, this.Dh = j | 0, this.Dl = z | 0, this.Eh = Q | 0, this.El = X | 0, this.Fh = N | 0, this.Fl = R | 0, this.Gh = o | 0, this.Gl = p | 0, this.Hh = c | 0, this.Hl = s | 0;
|
|
705
|
+
}
|
|
706
|
+
process(V, k) {
|
|
707
|
+
for (let e = 0; e < 16; e++, k += 4)
|
|
708
|
+
Y[e] = V.getUint32(k), L[e] = V.getUint32(k += 4);
|
|
709
|
+
for (let e = 16; e < 80; e++) {
|
|
710
|
+
const n = Y[e - 15] | 0, r = L[e - 15] | 0, i = f.rotrSH(n, r, 1) ^ f.rotrSH(n, r, 8) ^ f.shrSH(n, r, 7), a = f.rotrSL(n, r, 1) ^ f.rotrSL(n, r, 8) ^ f.shrSL(n, r, 7), b = Y[e - 2] | 0, A = L[e - 2] | 0, u = f.rotrSH(b, A, 19) ^ f.rotrBH(b, A, 61) ^ f.shrSH(b, A, 6), l = f.rotrSL(b, A, 19) ^ f.rotrBL(b, A, 61) ^ f.shrSL(b, A, 6), g = f.add4L(a, l, L[e - 7], L[e - 16]), _ = f.add4H(g, i, u, Y[e - 7], Y[e - 16]);
|
|
711
|
+
Y[e] = _ | 0, L[e] = g | 0;
|
|
712
|
+
}
|
|
713
|
+
let { Ah: O, Al: E, Bh: U, Bl: Z, Ch: j, Cl: z, Dh: Q, Dl: X, Eh: N, El: R, Fh: o, Fl: p, Gh: c, Gl: s, Hh: q, Hl: K } = this;
|
|
714
|
+
for (let e = 0; e < 80; e++) {
|
|
715
|
+
const n = f.rotrSH(N, R, 14) ^ f.rotrSH(N, R, 18) ^ f.rotrBH(N, R, 41), r = f.rotrSL(N, R, 14) ^ f.rotrSL(N, R, 18) ^ f.rotrBL(N, R, 41), i = N & o ^ ~N & c, a = R & p ^ ~R & s, b = f.add5L(K, r, a, G[e], L[e]), A = f.add5H(b, q, n, i, F[e], Y[e]), u = b | 0, l = f.rotrSH(O, E, 28) ^ f.rotrBH(O, E, 34) ^ f.rotrBH(O, E, 39), g = f.rotrSL(O, E, 28) ^ f.rotrBL(O, E, 34) ^ f.rotrBL(O, E, 39), _ = O & U ^ O & j ^ U & j, C = E & Z ^ E & z ^ Z & z;
|
|
716
|
+
q = c | 0, K = s | 0, c = o | 0, s = p | 0, o = N | 0, p = R | 0, { h: N, l: R } = f.add(Q | 0, X | 0, A | 0, u | 0), Q = j | 0, X = z | 0, j = U | 0, z = Z | 0, U = O | 0, Z = E | 0;
|
|
717
|
+
const h = f.add3L(u, g, C);
|
|
718
|
+
O = f.add3H(h, A, l, _), E = h | 0;
|
|
719
|
+
}
|
|
720
|
+
({ h: O, l: E } = f.add(this.Ah | 0, this.Al | 0, O | 0, E | 0)), { h: U, l: Z } = f.add(this.Bh | 0, this.Bl | 0, U | 0, Z | 0), { h: j, l: z } = f.add(this.Ch | 0, this.Cl | 0, j | 0, z | 0), { h: Q, l: X } = f.add(this.Dh | 0, this.Dl | 0, Q | 0, X | 0), { h: N, l: R } = f.add(this.Eh | 0, this.El | 0, N | 0, R | 0), { h: o, l: p } = f.add(this.Fh | 0, this.Fl | 0, o | 0, p | 0), { h: c, l: s } = f.add(this.Gh | 0, this.Gl | 0, c | 0, s | 0), { h: q, l: K } = f.add(this.Hh | 0, this.Hl | 0, q | 0, K | 0), this.set(O, E, U, Z, j, z, Q, X, N, R, o, p, c, s, q, K);
|
|
721
|
+
}
|
|
722
|
+
roundClean() {
|
|
723
|
+
(0, y.clean)(Y, L);
|
|
724
|
+
}
|
|
725
|
+
destroy() {
|
|
726
|
+
(0, y.clean)(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
mt.SHA512 = M;
|
|
730
|
+
class B extends M {
|
|
731
|
+
constructor() {
|
|
732
|
+
super(48), this.Ah = t.SHA384_IV[0] | 0, this.Al = t.SHA384_IV[1] | 0, this.Bh = t.SHA384_IV[2] | 0, this.Bl = t.SHA384_IV[3] | 0, this.Ch = t.SHA384_IV[4] | 0, this.Cl = t.SHA384_IV[5] | 0, this.Dh = t.SHA384_IV[6] | 0, this.Dl = t.SHA384_IV[7] | 0, this.Eh = t.SHA384_IV[8] | 0, this.El = t.SHA384_IV[9] | 0, this.Fh = t.SHA384_IV[10] | 0, this.Fl = t.SHA384_IV[11] | 0, this.Gh = t.SHA384_IV[12] | 0, this.Gl = t.SHA384_IV[13] | 0, this.Hh = t.SHA384_IV[14] | 0, this.Hl = t.SHA384_IV[15] | 0;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
mt.SHA384 = B;
|
|
736
|
+
const d = /* @__PURE__ */ Uint32Array.from([
|
|
737
|
+
2352822216,
|
|
738
|
+
424955298,
|
|
739
|
+
1944164710,
|
|
740
|
+
2312950998,
|
|
741
|
+
502970286,
|
|
742
|
+
855612546,
|
|
743
|
+
1738396948,
|
|
744
|
+
1479516111,
|
|
745
|
+
258812777,
|
|
746
|
+
2077511080,
|
|
747
|
+
2011393907,
|
|
748
|
+
79989058,
|
|
749
|
+
1067287976,
|
|
750
|
+
1780299464,
|
|
751
|
+
286451373,
|
|
752
|
+
2446758561
|
|
753
|
+
]), w = /* @__PURE__ */ Uint32Array.from([
|
|
754
|
+
573645204,
|
|
755
|
+
4230739756,
|
|
756
|
+
2673172387,
|
|
757
|
+
3360449730,
|
|
758
|
+
596883563,
|
|
759
|
+
1867755857,
|
|
760
|
+
2520282905,
|
|
761
|
+
1497426621,
|
|
762
|
+
2519219938,
|
|
763
|
+
2827943907,
|
|
764
|
+
3193839141,
|
|
765
|
+
1401305490,
|
|
766
|
+
721525244,
|
|
767
|
+
746961066,
|
|
768
|
+
246885852,
|
|
769
|
+
2177182882
|
|
770
|
+
]);
|
|
771
|
+
class v extends M {
|
|
772
|
+
constructor() {
|
|
773
|
+
super(28), this.Ah = d[0] | 0, this.Al = d[1] | 0, this.Bh = d[2] | 0, this.Bl = d[3] | 0, this.Ch = d[4] | 0, this.Cl = d[5] | 0, this.Dh = d[6] | 0, this.Dl = d[7] | 0, this.Eh = d[8] | 0, this.El = d[9] | 0, this.Fh = d[10] | 0, this.Fl = d[11] | 0, this.Gh = d[12] | 0, this.Gl = d[13] | 0, this.Hh = d[14] | 0, this.Hl = d[15] | 0;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
mt.SHA512_224 = v;
|
|
777
|
+
class T extends M {
|
|
778
|
+
constructor() {
|
|
779
|
+
super(32), this.Ah = w[0] | 0, this.Al = w[1] | 0, this.Bh = w[2] | 0, this.Bl = w[3] | 0, this.Ch = w[4] | 0, this.Cl = w[5] | 0, this.Dh = w[6] | 0, this.Dl = w[7] | 0, this.Eh = w[8] | 0, this.El = w[9] | 0, this.Fh = w[10] | 0, this.Fl = w[11] | 0, this.Gh = w[12] | 0, this.Gl = w[13] | 0, this.Hh = w[14] | 0, this.Hl = w[15] | 0;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return mt.SHA512_256 = T, mt.sha256 = (0, y.createHasher)(() => new m()), mt.sha224 = (0, y.createHasher)(() => new I()), mt.sha512 = (0, y.createHasher)(() => new M()), mt.sha384 = (0, y.createHasher)(() => new B()), mt.sha512_256 = (0, y.createHasher)(() => new T()), mt.sha512_224 = (0, y.createHasher)(() => new v()), mt;
|
|
783
|
+
}
|
|
784
|
+
var Ct = {}, ee = {}, Se;
|
|
785
|
+
function Ut() {
|
|
786
|
+
return Se || (Se = 1, (function(t) {
|
|
787
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.notImplemented = t.bitMask = t.utf8ToBytes = t.randomBytes = t.isBytes = t.hexToBytes = t.concatBytes = t.bytesToUtf8 = t.bytesToHex = t.anumber = t.abytes = void 0, t.abool = m, t._abool2 = I, t._abytes2 = D, t.numberToHexUnpadded = F, t.hexToNumber = G, t.bytesToNumberBE = Y, t.bytesToNumberLE = L, t.numberToBytesBE = M, t.numberToBytesLE = B, t.numberToVarBytesBE = d, t.ensureBytes = w, t.equalBytes = v, t.copyBytes = T, t.asciiToBytes = P, t.inRange = k, t.aInRange = O, t.bitLen = E, t.bitGet = U, t.bitSet = Z, t.createHmacDrbg = z, t.validateObject = X, t.isHash = N, t._validateObject = R, t.memoized = p;
|
|
788
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
789
|
+
const f = /* @__PURE__ */ Ot();
|
|
790
|
+
var y = /* @__PURE__ */ Ot();
|
|
791
|
+
Object.defineProperty(t, "abytes", { enumerable: !0, get: function() {
|
|
792
|
+
return y.abytes;
|
|
793
|
+
} }), Object.defineProperty(t, "anumber", { enumerable: !0, get: function() {
|
|
794
|
+
return y.anumber;
|
|
795
|
+
} }), Object.defineProperty(t, "bytesToHex", { enumerable: !0, get: function() {
|
|
796
|
+
return y.bytesToHex;
|
|
797
|
+
} }), Object.defineProperty(t, "bytesToUtf8", { enumerable: !0, get: function() {
|
|
798
|
+
return y.bytesToUtf8;
|
|
799
|
+
} }), Object.defineProperty(t, "concatBytes", { enumerable: !0, get: function() {
|
|
800
|
+
return y.concatBytes;
|
|
801
|
+
} }), Object.defineProperty(t, "hexToBytes", { enumerable: !0, get: function() {
|
|
802
|
+
return y.hexToBytes;
|
|
803
|
+
} }), Object.defineProperty(t, "isBytes", { enumerable: !0, get: function() {
|
|
804
|
+
return y.isBytes;
|
|
805
|
+
} }), Object.defineProperty(t, "randomBytes", { enumerable: !0, get: function() {
|
|
806
|
+
return y.randomBytes;
|
|
807
|
+
} }), Object.defineProperty(t, "utf8ToBytes", { enumerable: !0, get: function() {
|
|
808
|
+
return y.utf8ToBytes;
|
|
809
|
+
} });
|
|
810
|
+
const S = /* @__PURE__ */ BigInt(0), H = /* @__PURE__ */ BigInt(1);
|
|
811
|
+
function m(c, s) {
|
|
812
|
+
if (typeof s != "boolean")
|
|
813
|
+
throw new Error(c + " boolean expected, got " + s);
|
|
814
|
+
}
|
|
815
|
+
function I(c, s = "") {
|
|
816
|
+
if (typeof c != "boolean") {
|
|
817
|
+
const q = s && `"${s}"`;
|
|
818
|
+
throw new Error(q + "expected boolean, got type=" + typeof c);
|
|
819
|
+
}
|
|
820
|
+
return c;
|
|
821
|
+
}
|
|
822
|
+
function D(c, s, q = "") {
|
|
823
|
+
const K = (0, f.isBytes)(c), e = c == null ? void 0 : c.length, n = s !== void 0;
|
|
824
|
+
if (!K || n && e !== s) {
|
|
825
|
+
const r = q && `"${q}" `, i = n ? ` of length ${s}` : "", a = K ? `length=${e}` : `type=${typeof c}`;
|
|
826
|
+
throw new Error(r + "expected Uint8Array" + i + ", got " + a);
|
|
827
|
+
}
|
|
828
|
+
return c;
|
|
829
|
+
}
|
|
830
|
+
function F(c) {
|
|
831
|
+
const s = c.toString(16);
|
|
832
|
+
return s.length & 1 ? "0" + s : s;
|
|
833
|
+
}
|
|
834
|
+
function G(c) {
|
|
835
|
+
if (typeof c != "string")
|
|
836
|
+
throw new Error("hex string expected, got " + typeof c);
|
|
837
|
+
return c === "" ? S : BigInt("0x" + c);
|
|
838
|
+
}
|
|
839
|
+
function Y(c) {
|
|
840
|
+
return G((0, f.bytesToHex)(c));
|
|
841
|
+
}
|
|
842
|
+
function L(c) {
|
|
843
|
+
return (0, f.abytes)(c), G((0, f.bytesToHex)(Uint8Array.from(c).reverse()));
|
|
844
|
+
}
|
|
845
|
+
function M(c, s) {
|
|
846
|
+
return (0, f.hexToBytes)(c.toString(16).padStart(s * 2, "0"));
|
|
847
|
+
}
|
|
848
|
+
function B(c, s) {
|
|
849
|
+
return M(c, s).reverse();
|
|
850
|
+
}
|
|
851
|
+
function d(c) {
|
|
852
|
+
return (0, f.hexToBytes)(F(c));
|
|
853
|
+
}
|
|
854
|
+
function w(c, s, q) {
|
|
855
|
+
let K;
|
|
856
|
+
if (typeof s == "string")
|
|
857
|
+
try {
|
|
858
|
+
K = (0, f.hexToBytes)(s);
|
|
859
|
+
} catch (n) {
|
|
860
|
+
throw new Error(c + " must be hex string or Uint8Array, cause: " + n);
|
|
861
|
+
}
|
|
862
|
+
else if ((0, f.isBytes)(s))
|
|
863
|
+
K = Uint8Array.from(s);
|
|
864
|
+
else
|
|
865
|
+
throw new Error(c + " must be hex string or Uint8Array");
|
|
866
|
+
const e = K.length;
|
|
867
|
+
if (typeof q == "number" && e !== q)
|
|
868
|
+
throw new Error(c + " of length " + q + " expected, got " + e);
|
|
869
|
+
return K;
|
|
870
|
+
}
|
|
871
|
+
function v(c, s) {
|
|
872
|
+
if (c.length !== s.length)
|
|
873
|
+
return !1;
|
|
874
|
+
let q = 0;
|
|
875
|
+
for (let K = 0; K < c.length; K++)
|
|
876
|
+
q |= c[K] ^ s[K];
|
|
877
|
+
return q === 0;
|
|
878
|
+
}
|
|
879
|
+
function T(c) {
|
|
880
|
+
return Uint8Array.from(c);
|
|
881
|
+
}
|
|
882
|
+
function P(c) {
|
|
883
|
+
return Uint8Array.from(c, (s, q) => {
|
|
884
|
+
const K = s.charCodeAt(0);
|
|
885
|
+
if (s.length !== 1 || K > 127)
|
|
886
|
+
throw new Error(`string contains non-ASCII character "${c[q]}" with code ${K} at position ${q}`);
|
|
887
|
+
return K;
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
const V = (c) => typeof c == "bigint" && S <= c;
|
|
891
|
+
function k(c, s, q) {
|
|
892
|
+
return V(c) && V(s) && V(q) && s <= c && c < q;
|
|
893
|
+
}
|
|
894
|
+
function O(c, s, q, K) {
|
|
895
|
+
if (!k(s, q, K))
|
|
896
|
+
throw new Error("expected valid " + c + ": " + q + " <= n < " + K + ", got " + s);
|
|
897
|
+
}
|
|
898
|
+
function E(c) {
|
|
899
|
+
let s;
|
|
900
|
+
for (s = 0; c > S; c >>= H, s += 1)
|
|
901
|
+
;
|
|
902
|
+
return s;
|
|
903
|
+
}
|
|
904
|
+
function U(c, s) {
|
|
905
|
+
return c >> BigInt(s) & H;
|
|
906
|
+
}
|
|
907
|
+
function Z(c, s, q) {
|
|
908
|
+
return c | (q ? H : S) << BigInt(s);
|
|
909
|
+
}
|
|
910
|
+
const j = (c) => (H << BigInt(c)) - H;
|
|
911
|
+
t.bitMask = j;
|
|
912
|
+
function z(c, s, q) {
|
|
913
|
+
if (typeof c != "number" || c < 2)
|
|
914
|
+
throw new Error("hashLen must be a number");
|
|
915
|
+
if (typeof s != "number" || s < 2)
|
|
916
|
+
throw new Error("qByteLen must be a number");
|
|
917
|
+
if (typeof q != "function")
|
|
918
|
+
throw new Error("hmacFn must be a function");
|
|
919
|
+
const K = (g) => new Uint8Array(g), e = (g) => Uint8Array.of(g);
|
|
920
|
+
let n = K(c), r = K(c), i = 0;
|
|
921
|
+
const a = () => {
|
|
922
|
+
n.fill(1), r.fill(0), i = 0;
|
|
923
|
+
}, b = (...g) => q(r, n, ...g), A = (g = K(0)) => {
|
|
924
|
+
r = b(e(0), g), n = b(), g.length !== 0 && (r = b(e(1), g), n = b());
|
|
925
|
+
}, u = () => {
|
|
926
|
+
if (i++ >= 1e3)
|
|
927
|
+
throw new Error("drbg: tried 1000 values");
|
|
928
|
+
let g = 0;
|
|
929
|
+
const _ = [];
|
|
930
|
+
for (; g < s; ) {
|
|
931
|
+
n = b();
|
|
932
|
+
const C = n.slice();
|
|
933
|
+
_.push(C), g += n.length;
|
|
934
|
+
}
|
|
935
|
+
return (0, f.concatBytes)(..._);
|
|
936
|
+
};
|
|
937
|
+
return (g, _) => {
|
|
938
|
+
a(), A(g);
|
|
939
|
+
let C;
|
|
940
|
+
for (; !(C = _(u())); )
|
|
941
|
+
A();
|
|
942
|
+
return a(), C;
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
const Q = {
|
|
946
|
+
bigint: (c) => typeof c == "bigint",
|
|
947
|
+
function: (c) => typeof c == "function",
|
|
948
|
+
boolean: (c) => typeof c == "boolean",
|
|
949
|
+
string: (c) => typeof c == "string",
|
|
950
|
+
stringOrUint8Array: (c) => typeof c == "string" || (0, f.isBytes)(c),
|
|
951
|
+
isSafeInteger: (c) => Number.isSafeInteger(c),
|
|
952
|
+
array: (c) => Array.isArray(c),
|
|
953
|
+
field: (c, s) => s.Fp.isValid(c),
|
|
954
|
+
hash: (c) => typeof c == "function" && Number.isSafeInteger(c.outputLen)
|
|
955
|
+
};
|
|
956
|
+
function X(c, s, q = {}) {
|
|
957
|
+
const K = (e, n, r) => {
|
|
958
|
+
const i = Q[n];
|
|
959
|
+
if (typeof i != "function")
|
|
960
|
+
throw new Error("invalid validator function");
|
|
961
|
+
const a = c[e];
|
|
962
|
+
if (!(r && a === void 0) && !i(a, c))
|
|
963
|
+
throw new Error("param " + String(e) + " is invalid. Expected " + n + ", got " + a);
|
|
964
|
+
};
|
|
965
|
+
for (const [e, n] of Object.entries(s))
|
|
966
|
+
K(e, n, !1);
|
|
967
|
+
for (const [e, n] of Object.entries(q))
|
|
968
|
+
K(e, n, !0);
|
|
969
|
+
return c;
|
|
970
|
+
}
|
|
971
|
+
function N(c) {
|
|
972
|
+
return typeof c == "function" && Number.isSafeInteger(c.outputLen);
|
|
973
|
+
}
|
|
974
|
+
function R(c, s, q = {}) {
|
|
975
|
+
if (!c || typeof c != "object")
|
|
976
|
+
throw new Error("expected valid options object");
|
|
977
|
+
function K(e, n, r) {
|
|
978
|
+
const i = c[e];
|
|
979
|
+
if (r && i === void 0)
|
|
980
|
+
return;
|
|
981
|
+
const a = typeof i;
|
|
982
|
+
if (a !== n || i === null)
|
|
983
|
+
throw new Error(`param "${e}" is invalid: expected ${n}, got ${a}`);
|
|
984
|
+
}
|
|
985
|
+
Object.entries(s).forEach(([e, n]) => K(e, n, !1)), Object.entries(q).forEach(([e, n]) => K(e, n, !0));
|
|
986
|
+
}
|
|
987
|
+
const o = () => {
|
|
988
|
+
throw new Error("not implemented");
|
|
989
|
+
};
|
|
990
|
+
t.notImplemented = o;
|
|
991
|
+
function p(c) {
|
|
992
|
+
const s = /* @__PURE__ */ new WeakMap();
|
|
993
|
+
return (q, ...K) => {
|
|
994
|
+
const e = s.get(q);
|
|
995
|
+
if (e !== void 0)
|
|
996
|
+
return e;
|
|
997
|
+
const n = c(q, ...K);
|
|
998
|
+
return s.set(q, n), n;
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
})(ee)), ee;
|
|
1002
|
+
}
|
|
1003
|
+
var _t = {}, xe;
|
|
1004
|
+
function qt() {
|
|
1005
|
+
if (xe) return _t;
|
|
1006
|
+
xe = 1, Object.defineProperty(_t, "__esModule", { value: !0 }), _t.isNegativeLE = void 0, _t.mod = L, _t.pow = M, _t.pow2 = B, _t.invert = d, _t.tonelliShanks = V, _t.FpSqrt = k, _t.validateField = U, _t.FpPow = Z, _t.FpInvertBatch = j, _t.FpDiv = z, _t.FpLegendre = Q, _t.FpIsSquare = X, _t.nLength = N, _t.Field = R, _t.FpSqrtOdd = o, _t.FpSqrtEven = p, _t.hashToPrivateScalar = c, _t.getFieldBytesLength = s, _t.getMinHashLength = q, _t.mapHashToField = K;
|
|
1007
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1008
|
+
const t = /* @__PURE__ */ Ut(), f = BigInt(0), y = BigInt(1), S = /* @__PURE__ */ BigInt(2), H = /* @__PURE__ */ BigInt(3), m = /* @__PURE__ */ BigInt(4), I = /* @__PURE__ */ BigInt(5), D = /* @__PURE__ */ BigInt(7), F = /* @__PURE__ */ BigInt(8), G = /* @__PURE__ */ BigInt(9), Y = /* @__PURE__ */ BigInt(16);
|
|
1009
|
+
function L(e, n) {
|
|
1010
|
+
const r = e % n;
|
|
1011
|
+
return r >= f ? r : n + r;
|
|
1012
|
+
}
|
|
1013
|
+
function M(e, n, r) {
|
|
1014
|
+
return Z(R(r), e, n);
|
|
1015
|
+
}
|
|
1016
|
+
function B(e, n, r) {
|
|
1017
|
+
let i = e;
|
|
1018
|
+
for (; n-- > f; )
|
|
1019
|
+
i *= i, i %= r;
|
|
1020
|
+
return i;
|
|
1021
|
+
}
|
|
1022
|
+
function d(e, n) {
|
|
1023
|
+
if (e === f)
|
|
1024
|
+
throw new Error("invert: expected non-zero number");
|
|
1025
|
+
if (n <= f)
|
|
1026
|
+
throw new Error("invert: expected positive modulus, got " + n);
|
|
1027
|
+
let r = L(e, n), i = n, a = f, b = y;
|
|
1028
|
+
for (; r !== f; ) {
|
|
1029
|
+
const u = i / r, l = i % r, g = a - b * u;
|
|
1030
|
+
i = r, r = l, a = b, b = g;
|
|
1031
|
+
}
|
|
1032
|
+
if (i !== y)
|
|
1033
|
+
throw new Error("invert: does not exist");
|
|
1034
|
+
return L(a, n);
|
|
1035
|
+
}
|
|
1036
|
+
function w(e, n, r) {
|
|
1037
|
+
if (!e.eql(e.sqr(n), r))
|
|
1038
|
+
throw new Error("Cannot find square root");
|
|
1039
|
+
}
|
|
1040
|
+
function v(e, n) {
|
|
1041
|
+
const r = (e.ORDER + y) / m, i = e.pow(n, r);
|
|
1042
|
+
return w(e, i, n), i;
|
|
1043
|
+
}
|
|
1044
|
+
function T(e, n) {
|
|
1045
|
+
const r = (e.ORDER - I) / F, i = e.mul(n, S), a = e.pow(i, r), b = e.mul(n, a), A = e.mul(e.mul(b, S), a), u = e.mul(b, e.sub(A, e.ONE));
|
|
1046
|
+
return w(e, u, n), u;
|
|
1047
|
+
}
|
|
1048
|
+
function P(e) {
|
|
1049
|
+
const n = R(e), r = V(e), i = r(n, n.neg(n.ONE)), a = r(n, i), b = r(n, n.neg(i)), A = (e + D) / Y;
|
|
1050
|
+
return (u, l) => {
|
|
1051
|
+
let g = u.pow(l, A), _ = u.mul(g, i);
|
|
1052
|
+
const C = u.mul(g, a), h = u.mul(g, b), x = u.eql(u.sqr(_), l), W = u.eql(u.sqr(C), l);
|
|
1053
|
+
g = u.cmov(g, _, x), _ = u.cmov(h, C, W);
|
|
1054
|
+
const $ = u.eql(u.sqr(_), l), ot = u.cmov(g, _, $);
|
|
1055
|
+
return w(u, ot, l), ot;
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function V(e) {
|
|
1059
|
+
if (e < H)
|
|
1060
|
+
throw new Error("sqrt is not defined for small field");
|
|
1061
|
+
let n = e - y, r = 0;
|
|
1062
|
+
for (; n % S === f; )
|
|
1063
|
+
n /= S, r++;
|
|
1064
|
+
let i = S;
|
|
1065
|
+
const a = R(e);
|
|
1066
|
+
for (; Q(a, i) === 1; )
|
|
1067
|
+
if (i++ > 1e3)
|
|
1068
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
1069
|
+
if (r === 1)
|
|
1070
|
+
return v;
|
|
1071
|
+
let b = a.pow(i, n);
|
|
1072
|
+
const A = (n + y) / S;
|
|
1073
|
+
return function(l, g) {
|
|
1074
|
+
if (l.is0(g))
|
|
1075
|
+
return g;
|
|
1076
|
+
if (Q(l, g) !== 1)
|
|
1077
|
+
throw new Error("Cannot find square root");
|
|
1078
|
+
let _ = r, C = l.mul(l.ONE, b), h = l.pow(g, n), x = l.pow(g, A);
|
|
1079
|
+
for (; !l.eql(h, l.ONE); ) {
|
|
1080
|
+
if (l.is0(h))
|
|
1081
|
+
return l.ZERO;
|
|
1082
|
+
let W = 1, $ = l.sqr(h);
|
|
1083
|
+
for (; !l.eql($, l.ONE); )
|
|
1084
|
+
if (W++, $ = l.sqr($), W === _)
|
|
1085
|
+
throw new Error("Cannot find square root");
|
|
1086
|
+
const ot = y << BigInt(_ - W - 1), nt = l.pow(C, ot);
|
|
1087
|
+
_ = W, C = l.sqr(nt), h = l.mul(h, C), x = l.mul(x, nt);
|
|
1088
|
+
}
|
|
1089
|
+
return x;
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
function k(e) {
|
|
1093
|
+
return e % m === H ? v : e % F === I ? T : e % Y === G ? P(e) : V(e);
|
|
1094
|
+
}
|
|
1095
|
+
const O = (e, n) => (L(e, n) & y) === y;
|
|
1096
|
+
_t.isNegativeLE = O;
|
|
1097
|
+
const E = [
|
|
1098
|
+
"create",
|
|
1099
|
+
"isValid",
|
|
1100
|
+
"is0",
|
|
1101
|
+
"neg",
|
|
1102
|
+
"inv",
|
|
1103
|
+
"sqrt",
|
|
1104
|
+
"sqr",
|
|
1105
|
+
"eql",
|
|
1106
|
+
"add",
|
|
1107
|
+
"sub",
|
|
1108
|
+
"mul",
|
|
1109
|
+
"pow",
|
|
1110
|
+
"div",
|
|
1111
|
+
"addN",
|
|
1112
|
+
"subN",
|
|
1113
|
+
"mulN",
|
|
1114
|
+
"sqrN"
|
|
1115
|
+
];
|
|
1116
|
+
function U(e) {
|
|
1117
|
+
const n = {
|
|
1118
|
+
ORDER: "bigint",
|
|
1119
|
+
MASK: "bigint",
|
|
1120
|
+
BYTES: "number",
|
|
1121
|
+
BITS: "number"
|
|
1122
|
+
}, r = E.reduce((i, a) => (i[a] = "function", i), n);
|
|
1123
|
+
return (0, t._validateObject)(e, r), e;
|
|
1124
|
+
}
|
|
1125
|
+
function Z(e, n, r) {
|
|
1126
|
+
if (r < f)
|
|
1127
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
1128
|
+
if (r === f)
|
|
1129
|
+
return e.ONE;
|
|
1130
|
+
if (r === y)
|
|
1131
|
+
return n;
|
|
1132
|
+
let i = e.ONE, a = n;
|
|
1133
|
+
for (; r > f; )
|
|
1134
|
+
r & y && (i = e.mul(i, a)), a = e.sqr(a), r >>= y;
|
|
1135
|
+
return i;
|
|
1136
|
+
}
|
|
1137
|
+
function j(e, n, r = !1) {
|
|
1138
|
+
const i = new Array(n.length).fill(r ? e.ZERO : void 0), a = n.reduce((A, u, l) => e.is0(u) ? A : (i[l] = A, e.mul(A, u)), e.ONE), b = e.inv(a);
|
|
1139
|
+
return n.reduceRight((A, u, l) => e.is0(u) ? A : (i[l] = e.mul(A, i[l]), e.mul(A, u)), b), i;
|
|
1140
|
+
}
|
|
1141
|
+
function z(e, n, r) {
|
|
1142
|
+
return e.mul(n, typeof r == "bigint" ? d(r, e.ORDER) : e.inv(r));
|
|
1143
|
+
}
|
|
1144
|
+
function Q(e, n) {
|
|
1145
|
+
const r = (e.ORDER - y) / S, i = e.pow(n, r), a = e.eql(i, e.ONE), b = e.eql(i, e.ZERO), A = e.eql(i, e.neg(e.ONE));
|
|
1146
|
+
if (!a && !b && !A)
|
|
1147
|
+
throw new Error("invalid Legendre symbol result");
|
|
1148
|
+
return a ? 1 : b ? 0 : -1;
|
|
1149
|
+
}
|
|
1150
|
+
function X(e, n) {
|
|
1151
|
+
return Q(e, n) === 1;
|
|
1152
|
+
}
|
|
1153
|
+
function N(e, n) {
|
|
1154
|
+
n !== void 0 && (0, t.anumber)(n);
|
|
1155
|
+
const r = n !== void 0 ? n : e.toString(2).length, i = Math.ceil(r / 8);
|
|
1156
|
+
return { nBitLength: r, nByteLength: i };
|
|
1157
|
+
}
|
|
1158
|
+
function R(e, n, r = !1, i = {}) {
|
|
1159
|
+
if (e <= f)
|
|
1160
|
+
throw new Error("invalid field: expected ORDER > 0, got " + e);
|
|
1161
|
+
let a, b, A = !1, u;
|
|
1162
|
+
if (typeof n == "object" && n != null) {
|
|
1163
|
+
if (i.sqrt || r)
|
|
1164
|
+
throw new Error("cannot specify opts in two arguments");
|
|
1165
|
+
const h = n;
|
|
1166
|
+
h.BITS && (a = h.BITS), h.sqrt && (b = h.sqrt), typeof h.isLE == "boolean" && (r = h.isLE), typeof h.modFromBytes == "boolean" && (A = h.modFromBytes), u = h.allowedLengths;
|
|
1167
|
+
} else
|
|
1168
|
+
typeof n == "number" && (a = n), i.sqrt && (b = i.sqrt);
|
|
1169
|
+
const { nBitLength: l, nByteLength: g } = N(e, a);
|
|
1170
|
+
if (g > 2048)
|
|
1171
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1172
|
+
let _;
|
|
1173
|
+
const C = Object.freeze({
|
|
1174
|
+
ORDER: e,
|
|
1175
|
+
isLE: r,
|
|
1176
|
+
BITS: l,
|
|
1177
|
+
BYTES: g,
|
|
1178
|
+
MASK: (0, t.bitMask)(l),
|
|
1179
|
+
ZERO: f,
|
|
1180
|
+
ONE: y,
|
|
1181
|
+
allowedLengths: u,
|
|
1182
|
+
create: (h) => L(h, e),
|
|
1183
|
+
isValid: (h) => {
|
|
1184
|
+
if (typeof h != "bigint")
|
|
1185
|
+
throw new Error("invalid field element: expected bigint, got " + typeof h);
|
|
1186
|
+
return f <= h && h < e;
|
|
1187
|
+
},
|
|
1188
|
+
is0: (h) => h === f,
|
|
1189
|
+
// is valid and invertible
|
|
1190
|
+
isValidNot0: (h) => !C.is0(h) && C.isValid(h),
|
|
1191
|
+
isOdd: (h) => (h & y) === y,
|
|
1192
|
+
neg: (h) => L(-h, e),
|
|
1193
|
+
eql: (h, x) => h === x,
|
|
1194
|
+
sqr: (h) => L(h * h, e),
|
|
1195
|
+
add: (h, x) => L(h + x, e),
|
|
1196
|
+
sub: (h, x) => L(h - x, e),
|
|
1197
|
+
mul: (h, x) => L(h * x, e),
|
|
1198
|
+
pow: (h, x) => Z(C, h, x),
|
|
1199
|
+
div: (h, x) => L(h * d(x, e), e),
|
|
1200
|
+
// Same as above, but doesn't normalize
|
|
1201
|
+
sqrN: (h) => h * h,
|
|
1202
|
+
addN: (h, x) => h + x,
|
|
1203
|
+
subN: (h, x) => h - x,
|
|
1204
|
+
mulN: (h, x) => h * x,
|
|
1205
|
+
inv: (h) => d(h, e),
|
|
1206
|
+
sqrt: b || ((h) => (_ || (_ = k(e)), _(C, h))),
|
|
1207
|
+
toBytes: (h) => r ? (0, t.numberToBytesLE)(h, g) : (0, t.numberToBytesBE)(h, g),
|
|
1208
|
+
fromBytes: (h, x = !0) => {
|
|
1209
|
+
if (u) {
|
|
1210
|
+
if (!u.includes(h.length) || h.length > g)
|
|
1211
|
+
throw new Error("Field.fromBytes: expected " + u + " bytes, got " + h.length);
|
|
1212
|
+
const $ = new Uint8Array(g);
|
|
1213
|
+
$.set(h, r ? 0 : $.length - h.length), h = $;
|
|
1214
|
+
}
|
|
1215
|
+
if (h.length !== g)
|
|
1216
|
+
throw new Error("Field.fromBytes: expected " + g + " bytes, got " + h.length);
|
|
1217
|
+
let W = r ? (0, t.bytesToNumberLE)(h) : (0, t.bytesToNumberBE)(h);
|
|
1218
|
+
if (A && (W = L(W, e)), !x && !C.isValid(W))
|
|
1219
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
1220
|
+
return W;
|
|
1221
|
+
},
|
|
1222
|
+
// TODO: we don't need it here, move out to separate fn
|
|
1223
|
+
invertBatch: (h) => j(C, h),
|
|
1224
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
1225
|
+
// and it's unclear what to return in there.
|
|
1226
|
+
cmov: (h, x, W) => W ? x : h
|
|
1227
|
+
});
|
|
1228
|
+
return Object.freeze(C);
|
|
1229
|
+
}
|
|
1230
|
+
function o(e, n) {
|
|
1231
|
+
if (!e.isOdd)
|
|
1232
|
+
throw new Error("Field doesn't have isOdd");
|
|
1233
|
+
const r = e.sqrt(n);
|
|
1234
|
+
return e.isOdd(r) ? r : e.neg(r);
|
|
1235
|
+
}
|
|
1236
|
+
function p(e, n) {
|
|
1237
|
+
if (!e.isOdd)
|
|
1238
|
+
throw new Error("Field doesn't have isOdd");
|
|
1239
|
+
const r = e.sqrt(n);
|
|
1240
|
+
return e.isOdd(r) ? e.neg(r) : r;
|
|
1241
|
+
}
|
|
1242
|
+
function c(e, n, r = !1) {
|
|
1243
|
+
e = (0, t.ensureBytes)("privateHash", e);
|
|
1244
|
+
const i = e.length, a = N(n).nByteLength + 8;
|
|
1245
|
+
if (a < 24 || i < a || i > 1024)
|
|
1246
|
+
throw new Error("hashToPrivateScalar: expected " + a + "-1024 bytes of input, got " + i);
|
|
1247
|
+
const b = r ? (0, t.bytesToNumberLE)(e) : (0, t.bytesToNumberBE)(e);
|
|
1248
|
+
return L(b, n - y) + y;
|
|
1249
|
+
}
|
|
1250
|
+
function s(e) {
|
|
1251
|
+
if (typeof e != "bigint")
|
|
1252
|
+
throw new Error("field order must be bigint");
|
|
1253
|
+
const n = e.toString(2).length;
|
|
1254
|
+
return Math.ceil(n / 8);
|
|
1255
|
+
}
|
|
1256
|
+
function q(e) {
|
|
1257
|
+
const n = s(e);
|
|
1258
|
+
return n + Math.ceil(n / 2);
|
|
1259
|
+
}
|
|
1260
|
+
function K(e, n, r = !1) {
|
|
1261
|
+
const i = e.length, a = s(n), b = q(n);
|
|
1262
|
+
if (i < 16 || i < b || i > 1024)
|
|
1263
|
+
throw new Error("expected " + b + "-1024 bytes of input, got " + i);
|
|
1264
|
+
const A = r ? (0, t.bytesToNumberLE)(e) : (0, t.bytesToNumberBE)(e), u = L(A, n - y) + y;
|
|
1265
|
+
return r ? (0, t.numberToBytesLE)(u, a) : (0, t.numberToBytesBE)(u, a);
|
|
1266
|
+
}
|
|
1267
|
+
return _t;
|
|
1268
|
+
}
|
|
1269
|
+
var Ae;
|
|
1270
|
+
function he() {
|
|
1271
|
+
if (Ae) return Ct;
|
|
1272
|
+
Ae = 1, Object.defineProperty(Ct, "__esModule", { value: !0 }), Ct.wNAF = void 0, Ct.negateCt = H, Ct.normalizeZ = m, Ct.mulEndoUnsafe = v, Ct.pippenger = T, Ct.precomputeMSMUnsafe = P, Ct.validateBasic = V, Ct._createCurveFields = O;
|
|
1273
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1274
|
+
const t = /* @__PURE__ */ Ut(), f = /* @__PURE__ */ qt(), y = BigInt(0), S = BigInt(1);
|
|
1275
|
+
function H(E, U) {
|
|
1276
|
+
const Z = U.negate();
|
|
1277
|
+
return E ? Z : U;
|
|
1278
|
+
}
|
|
1279
|
+
function m(E, U) {
|
|
1280
|
+
const Z = (0, f.FpInvertBatch)(E.Fp, U.map((j) => j.Z));
|
|
1281
|
+
return U.map((j, z) => E.fromAffine(j.toAffine(Z[z])));
|
|
1282
|
+
}
|
|
1283
|
+
function I(E, U) {
|
|
1284
|
+
if (!Number.isSafeInteger(E) || E <= 0 || E > U)
|
|
1285
|
+
throw new Error("invalid window size, expected [1.." + U + "], got W=" + E);
|
|
1286
|
+
}
|
|
1287
|
+
function D(E, U) {
|
|
1288
|
+
I(E, U);
|
|
1289
|
+
const Z = Math.ceil(U / E) + 1, j = 2 ** (E - 1), z = 2 ** E, Q = (0, t.bitMask)(E), X = BigInt(E);
|
|
1290
|
+
return { windows: Z, windowSize: j, mask: Q, maxNumber: z, shiftBy: X };
|
|
1291
|
+
}
|
|
1292
|
+
function F(E, U, Z) {
|
|
1293
|
+
const { windowSize: j, mask: z, maxNumber: Q, shiftBy: X } = Z;
|
|
1294
|
+
let N = Number(E & z), R = E >> X;
|
|
1295
|
+
N > j && (N -= Q, R += S);
|
|
1296
|
+
const o = U * j, p = o + Math.abs(N) - 1, c = N === 0, s = N < 0, q = U % 2 !== 0;
|
|
1297
|
+
return { nextN: R, offset: p, isZero: c, isNeg: s, isNegF: q, offsetF: o };
|
|
1298
|
+
}
|
|
1299
|
+
function G(E, U) {
|
|
1300
|
+
if (!Array.isArray(E))
|
|
1301
|
+
throw new Error("array expected");
|
|
1302
|
+
E.forEach((Z, j) => {
|
|
1303
|
+
if (!(Z instanceof U))
|
|
1304
|
+
throw new Error("invalid point at index " + j);
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
function Y(E, U) {
|
|
1308
|
+
if (!Array.isArray(E))
|
|
1309
|
+
throw new Error("array of scalars expected");
|
|
1310
|
+
E.forEach((Z, j) => {
|
|
1311
|
+
if (!U.isValid(Z))
|
|
1312
|
+
throw new Error("invalid scalar at index " + j);
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
const L = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap();
|
|
1316
|
+
function B(E) {
|
|
1317
|
+
return M.get(E) || 1;
|
|
1318
|
+
}
|
|
1319
|
+
function d(E) {
|
|
1320
|
+
if (E !== y)
|
|
1321
|
+
throw new Error("invalid wNAF");
|
|
1322
|
+
}
|
|
1323
|
+
class w {
|
|
1324
|
+
// Parametrized with a given Point class (not individual point)
|
|
1325
|
+
constructor(U, Z) {
|
|
1326
|
+
this.BASE = U.BASE, this.ZERO = U.ZERO, this.Fn = U.Fn, this.bits = Z;
|
|
1327
|
+
}
|
|
1328
|
+
// non-const time multiplication ladder
|
|
1329
|
+
_unsafeLadder(U, Z, j = this.ZERO) {
|
|
1330
|
+
let z = U;
|
|
1331
|
+
for (; Z > y; )
|
|
1332
|
+
Z & S && (j = j.add(z)), z = z.double(), Z >>= S;
|
|
1333
|
+
return j;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
1337
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1338
|
+
* Number of precomputed points depends on the curve size:
|
|
1339
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1340
|
+
* - 𝑊 is the window size
|
|
1341
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
1342
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1343
|
+
* @param point Point instance
|
|
1344
|
+
* @param W window size
|
|
1345
|
+
* @returns precomputed point tables flattened to a single array
|
|
1346
|
+
*/
|
|
1347
|
+
precomputeWindow(U, Z) {
|
|
1348
|
+
const { windows: j, windowSize: z } = D(Z, this.bits), Q = [];
|
|
1349
|
+
let X = U, N = X;
|
|
1350
|
+
for (let R = 0; R < j; R++) {
|
|
1351
|
+
N = X, Q.push(N);
|
|
1352
|
+
for (let o = 1; o < z; o++)
|
|
1353
|
+
N = N.add(X), Q.push(N);
|
|
1354
|
+
X = N.double();
|
|
1355
|
+
}
|
|
1356
|
+
return Q;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1360
|
+
* More compact implementation:
|
|
1361
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
1362
|
+
* @returns real and fake (for const-time) points
|
|
1363
|
+
*/
|
|
1364
|
+
wNAF(U, Z, j) {
|
|
1365
|
+
if (!this.Fn.isValid(j))
|
|
1366
|
+
throw new Error("invalid scalar");
|
|
1367
|
+
let z = this.ZERO, Q = this.BASE;
|
|
1368
|
+
const X = D(U, this.bits);
|
|
1369
|
+
for (let N = 0; N < X.windows; N++) {
|
|
1370
|
+
const { nextN: R, offset: o, isZero: p, isNeg: c, isNegF: s, offsetF: q } = F(j, N, X);
|
|
1371
|
+
j = R, p ? Q = Q.add(H(s, Z[q])) : z = z.add(H(c, Z[o]));
|
|
1372
|
+
}
|
|
1373
|
+
return d(j), { p: z, f: Q };
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1377
|
+
* @param acc accumulator point to add result of multiplication
|
|
1378
|
+
* @returns point
|
|
1379
|
+
*/
|
|
1380
|
+
wNAFUnsafe(U, Z, j, z = this.ZERO) {
|
|
1381
|
+
const Q = D(U, this.bits);
|
|
1382
|
+
for (let X = 0; X < Q.windows && j !== y; X++) {
|
|
1383
|
+
const { nextN: N, offset: R, isZero: o, isNeg: p } = F(j, X, Q);
|
|
1384
|
+
if (j = N, !o) {
|
|
1385
|
+
const c = Z[R];
|
|
1386
|
+
z = z.add(p ? c.negate() : c);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
return d(j), z;
|
|
1390
|
+
}
|
|
1391
|
+
getPrecomputes(U, Z, j) {
|
|
1392
|
+
let z = L.get(Z);
|
|
1393
|
+
return z || (z = this.precomputeWindow(Z, U), U !== 1 && (typeof j == "function" && (z = j(z)), L.set(Z, z))), z;
|
|
1394
|
+
}
|
|
1395
|
+
cached(U, Z, j) {
|
|
1396
|
+
const z = B(U);
|
|
1397
|
+
return this.wNAF(z, this.getPrecomputes(z, U, j), Z);
|
|
1398
|
+
}
|
|
1399
|
+
unsafe(U, Z, j, z) {
|
|
1400
|
+
const Q = B(U);
|
|
1401
|
+
return Q === 1 ? this._unsafeLadder(U, Z, z) : this.wNAFUnsafe(Q, this.getPrecomputes(Q, U, j), Z, z);
|
|
1402
|
+
}
|
|
1403
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1404
|
+
// using windowed method. This specifies window size and
|
|
1405
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1406
|
+
createCache(U, Z) {
|
|
1407
|
+
I(Z, this.bits), M.set(U, Z), L.delete(U);
|
|
1408
|
+
}
|
|
1409
|
+
hasCache(U) {
|
|
1410
|
+
return B(U) !== 1;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
Ct.wNAF = w;
|
|
1414
|
+
function v(E, U, Z, j) {
|
|
1415
|
+
let z = U, Q = E.ZERO, X = E.ZERO;
|
|
1416
|
+
for (; Z > y || j > y; )
|
|
1417
|
+
Z & S && (Q = Q.add(z)), j & S && (X = X.add(z)), z = z.double(), Z >>= S, j >>= S;
|
|
1418
|
+
return { p1: Q, p2: X };
|
|
1419
|
+
}
|
|
1420
|
+
function T(E, U, Z, j) {
|
|
1421
|
+
G(Z, E), Y(j, U);
|
|
1422
|
+
const z = Z.length, Q = j.length;
|
|
1423
|
+
if (z !== Q)
|
|
1424
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
1425
|
+
const X = E.ZERO, N = (0, t.bitLen)(BigInt(z));
|
|
1426
|
+
let R = 1;
|
|
1427
|
+
N > 12 ? R = N - 3 : N > 4 ? R = N - 2 : N > 0 && (R = 2);
|
|
1428
|
+
const o = (0, t.bitMask)(R), p = new Array(Number(o) + 1).fill(X), c = Math.floor((U.BITS - 1) / R) * R;
|
|
1429
|
+
let s = X;
|
|
1430
|
+
for (let q = c; q >= 0; q -= R) {
|
|
1431
|
+
p.fill(X);
|
|
1432
|
+
for (let e = 0; e < Q; e++) {
|
|
1433
|
+
const n = j[e], r = Number(n >> BigInt(q) & o);
|
|
1434
|
+
p[r] = p[r].add(Z[e]);
|
|
1435
|
+
}
|
|
1436
|
+
let K = X;
|
|
1437
|
+
for (let e = p.length - 1, n = X; e > 0; e--)
|
|
1438
|
+
n = n.add(p[e]), K = K.add(n);
|
|
1439
|
+
if (s = s.add(K), q !== 0)
|
|
1440
|
+
for (let e = 0; e < R; e++)
|
|
1441
|
+
s = s.double();
|
|
1442
|
+
}
|
|
1443
|
+
return s;
|
|
1444
|
+
}
|
|
1445
|
+
function P(E, U, Z, j) {
|
|
1446
|
+
I(j, U.BITS), G(Z, E);
|
|
1447
|
+
const z = E.ZERO, Q = 2 ** j - 1, X = Math.ceil(U.BITS / j), N = (0, t.bitMask)(j), R = Z.map((o) => {
|
|
1448
|
+
const p = [];
|
|
1449
|
+
for (let c = 0, s = o; c < Q; c++)
|
|
1450
|
+
p.push(s), s = s.add(o);
|
|
1451
|
+
return p;
|
|
1452
|
+
});
|
|
1453
|
+
return (o) => {
|
|
1454
|
+
if (Y(o, U), o.length > Z.length)
|
|
1455
|
+
throw new Error("array of scalars must be smaller than array of points");
|
|
1456
|
+
let p = z;
|
|
1457
|
+
for (let c = 0; c < X; c++) {
|
|
1458
|
+
if (p !== z)
|
|
1459
|
+
for (let q = 0; q < j; q++)
|
|
1460
|
+
p = p.double();
|
|
1461
|
+
const s = BigInt(X * j - (c + 1) * j);
|
|
1462
|
+
for (let q = 0; q < o.length; q++) {
|
|
1463
|
+
const K = o[q], e = Number(K >> s & N);
|
|
1464
|
+
e && (p = p.add(R[q][e - 1]));
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return p;
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function V(E) {
|
|
1471
|
+
return (0, f.validateField)(E.Fp), (0, t.validateObject)(E, {
|
|
1472
|
+
n: "bigint",
|
|
1473
|
+
h: "bigint",
|
|
1474
|
+
Gx: "field",
|
|
1475
|
+
Gy: "field"
|
|
1476
|
+
}, {
|
|
1477
|
+
nBitLength: "isSafeInteger",
|
|
1478
|
+
nByteLength: "isSafeInteger"
|
|
1479
|
+
}), Object.freeze({
|
|
1480
|
+
...(0, f.nLength)(E.n, E.nBitLength),
|
|
1481
|
+
...E,
|
|
1482
|
+
p: E.Fp.ORDER
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
function k(E, U, Z) {
|
|
1486
|
+
if (U) {
|
|
1487
|
+
if (U.ORDER !== E)
|
|
1488
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1489
|
+
return (0, f.validateField)(U), U;
|
|
1490
|
+
} else
|
|
1491
|
+
return (0, f.Field)(E, { isLE: Z });
|
|
1492
|
+
}
|
|
1493
|
+
function O(E, U, Z = {}, j) {
|
|
1494
|
+
if (j === void 0 && (j = E === "edwards"), !U || typeof U != "object")
|
|
1495
|
+
throw new Error(`expected valid ${E} CURVE object`);
|
|
1496
|
+
for (const R of ["p", "n", "h"]) {
|
|
1497
|
+
const o = U[R];
|
|
1498
|
+
if (!(typeof o == "bigint" && o > y))
|
|
1499
|
+
throw new Error(`CURVE.${R} must be positive bigint`);
|
|
1500
|
+
}
|
|
1501
|
+
const z = k(U.p, Z.Fp, j), Q = k(U.n, Z.Fn, j), N = ["Gx", "Gy", "a", E === "weierstrass" ? "b" : "d"];
|
|
1502
|
+
for (const R of N)
|
|
1503
|
+
if (!z.isValid(U[R]))
|
|
1504
|
+
throw new Error(`CURVE.${R} must be valid field element of CURVE.Fp`);
|
|
1505
|
+
return U = Object.freeze(Object.assign({}, U)), { CURVE: U, Fp: z, Fn: Q };
|
|
1506
|
+
}
|
|
1507
|
+
return Ct;
|
|
1508
|
+
}
|
|
1509
|
+
var Tt = {}, Ie;
|
|
1510
|
+
function dn() {
|
|
1511
|
+
if (Ie) return Tt;
|
|
1512
|
+
Ie = 1, Object.defineProperty(Tt, "__esModule", { value: !0 }), Tt.PrimeEdwardsPoint = void 0, Tt.edwards = F, Tt.eddsa = Y, Tt.twistedEdwards = B;
|
|
1513
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1514
|
+
const t = /* @__PURE__ */ Ut(), f = /* @__PURE__ */ he(), y = /* @__PURE__ */ qt(), S = BigInt(0), H = BigInt(1), m = BigInt(2), I = BigInt(8);
|
|
1515
|
+
function D(d, w, v, T) {
|
|
1516
|
+
const P = d.sqr(v), V = d.sqr(T), k = d.add(d.mul(w.a, P), V), O = d.add(d.ONE, d.mul(w.d, d.mul(P, V)));
|
|
1517
|
+
return d.eql(k, O);
|
|
1518
|
+
}
|
|
1519
|
+
function F(d, w = {}) {
|
|
1520
|
+
const v = (0, f._createCurveFields)("edwards", d, w, w.FpFnLE), { Fp: T, Fn: P } = v;
|
|
1521
|
+
let V = v.CURVE;
|
|
1522
|
+
const { h: k } = V;
|
|
1523
|
+
(0, t._validateObject)(w, {}, { uvRatio: "function" });
|
|
1524
|
+
const O = m << BigInt(P.BYTES * 8) - H, E = (R) => T.create(R), U = w.uvRatio || ((R, o) => {
|
|
1525
|
+
try {
|
|
1526
|
+
return { isValid: !0, value: T.sqrt(T.div(R, o)) };
|
|
1527
|
+
} catch {
|
|
1528
|
+
return { isValid: !1, value: S };
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
if (!D(T, V, V.Gx, V.Gy))
|
|
1532
|
+
throw new Error("bad curve params: generator point");
|
|
1533
|
+
function Z(R, o, p = !1) {
|
|
1534
|
+
const c = p ? H : S;
|
|
1535
|
+
return (0, t.aInRange)("coordinate " + R, o, c, O), o;
|
|
1536
|
+
}
|
|
1537
|
+
function j(R) {
|
|
1538
|
+
if (!(R instanceof X))
|
|
1539
|
+
throw new Error("ExtendedPoint expected");
|
|
1540
|
+
}
|
|
1541
|
+
const z = (0, t.memoized)((R, o) => {
|
|
1542
|
+
const { X: p, Y: c, Z: s } = R, q = R.is0();
|
|
1543
|
+
o == null && (o = q ? I : T.inv(s));
|
|
1544
|
+
const K = E(p * o), e = E(c * o), n = T.mul(s, o);
|
|
1545
|
+
if (q)
|
|
1546
|
+
return { x: S, y: H };
|
|
1547
|
+
if (n !== H)
|
|
1548
|
+
throw new Error("invZ was invalid");
|
|
1549
|
+
return { x: K, y: e };
|
|
1550
|
+
}), Q = (0, t.memoized)((R) => {
|
|
1551
|
+
const { a: o, d: p } = V;
|
|
1552
|
+
if (R.is0())
|
|
1553
|
+
throw new Error("bad point: ZERO");
|
|
1554
|
+
const { X: c, Y: s, Z: q, T: K } = R, e = E(c * c), n = E(s * s), r = E(q * q), i = E(r * r), a = E(e * o), b = E(r * E(a + n)), A = E(i + E(p * E(e * n)));
|
|
1555
|
+
if (b !== A)
|
|
1556
|
+
throw new Error("bad point: equation left != right (1)");
|
|
1557
|
+
const u = E(c * s), l = E(q * K);
|
|
1558
|
+
if (u !== l)
|
|
1559
|
+
throw new Error("bad point: equation left != right (2)");
|
|
1560
|
+
return !0;
|
|
1561
|
+
});
|
|
1562
|
+
class X {
|
|
1563
|
+
constructor(o, p, c, s) {
|
|
1564
|
+
this.X = Z("x", o), this.Y = Z("y", p), this.Z = Z("z", c, !0), this.T = Z("t", s), Object.freeze(this);
|
|
1565
|
+
}
|
|
1566
|
+
static CURVE() {
|
|
1567
|
+
return V;
|
|
1568
|
+
}
|
|
1569
|
+
static fromAffine(o) {
|
|
1570
|
+
if (o instanceof X)
|
|
1571
|
+
throw new Error("extended point not allowed");
|
|
1572
|
+
const { x: p, y: c } = o || {};
|
|
1573
|
+
return Z("x", p), Z("y", c), new X(p, c, H, E(p * c));
|
|
1574
|
+
}
|
|
1575
|
+
// Uses algo from RFC8032 5.1.3.
|
|
1576
|
+
static fromBytes(o, p = !1) {
|
|
1577
|
+
const c = T.BYTES, { a: s, d: q } = V;
|
|
1578
|
+
o = (0, t.copyBytes)((0, t._abytes2)(o, c, "point")), (0, t._abool2)(p, "zip215");
|
|
1579
|
+
const K = (0, t.copyBytes)(o), e = o[c - 1];
|
|
1580
|
+
K[c - 1] = e & -129;
|
|
1581
|
+
const n = (0, t.bytesToNumberLE)(K), r = p ? O : T.ORDER;
|
|
1582
|
+
(0, t.aInRange)("point.y", n, S, r);
|
|
1583
|
+
const i = E(n * n), a = E(i - H), b = E(q * i - s);
|
|
1584
|
+
let { isValid: A, value: u } = U(a, b);
|
|
1585
|
+
if (!A)
|
|
1586
|
+
throw new Error("bad point: invalid y coordinate");
|
|
1587
|
+
const l = (u & H) === H, g = (e & 128) !== 0;
|
|
1588
|
+
if (!p && u === S && g)
|
|
1589
|
+
throw new Error("bad point: x=0 and x_0=1");
|
|
1590
|
+
return g !== l && (u = E(-u)), X.fromAffine({ x: u, y: n });
|
|
1591
|
+
}
|
|
1592
|
+
static fromHex(o, p = !1) {
|
|
1593
|
+
return X.fromBytes((0, t.ensureBytes)("point", o), p);
|
|
1594
|
+
}
|
|
1595
|
+
get x() {
|
|
1596
|
+
return this.toAffine().x;
|
|
1597
|
+
}
|
|
1598
|
+
get y() {
|
|
1599
|
+
return this.toAffine().y;
|
|
1600
|
+
}
|
|
1601
|
+
precompute(o = 8, p = !0) {
|
|
1602
|
+
return N.createCache(this, o), p || this.multiply(m), this;
|
|
1603
|
+
}
|
|
1604
|
+
// Useful in fromAffine() - not for fromBytes(), which always created valid points.
|
|
1605
|
+
assertValidity() {
|
|
1606
|
+
Q(this);
|
|
1607
|
+
}
|
|
1608
|
+
// Compare one point to another.
|
|
1609
|
+
equals(o) {
|
|
1610
|
+
j(o);
|
|
1611
|
+
const { X: p, Y: c, Z: s } = this, { X: q, Y: K, Z: e } = o, n = E(p * e), r = E(q * s), i = E(c * e), a = E(K * s);
|
|
1612
|
+
return n === r && i === a;
|
|
1613
|
+
}
|
|
1614
|
+
is0() {
|
|
1615
|
+
return this.equals(X.ZERO);
|
|
1616
|
+
}
|
|
1617
|
+
negate() {
|
|
1618
|
+
return new X(E(-this.X), this.Y, this.Z, E(-this.T));
|
|
1619
|
+
}
|
|
1620
|
+
// Fast algo for doubling Extended Point.
|
|
1621
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
1622
|
+
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
1623
|
+
double() {
|
|
1624
|
+
const { a: o } = V, { X: p, Y: c, Z: s } = this, q = E(p * p), K = E(c * c), e = E(m * E(s * s)), n = E(o * q), r = p + c, i = E(E(r * r) - q - K), a = n + K, b = a - e, A = n - K, u = E(i * b), l = E(a * A), g = E(i * A), _ = E(b * a);
|
|
1625
|
+
return new X(u, l, _, g);
|
|
1626
|
+
}
|
|
1627
|
+
// Fast algo for adding 2 Extended Points.
|
|
1628
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
1629
|
+
// Cost: 9M + 1*a + 1*d + 7add.
|
|
1630
|
+
add(o) {
|
|
1631
|
+
j(o);
|
|
1632
|
+
const { a: p, d: c } = V, { X: s, Y: q, Z: K, T: e } = this, { X: n, Y: r, Z: i, T: a } = o, b = E(s * n), A = E(q * r), u = E(e * c * a), l = E(K * i), g = E((s + q) * (n + r) - b - A), _ = l - u, C = l + u, h = E(A - p * b), x = E(g * _), W = E(C * h), $ = E(g * h), ot = E(_ * C);
|
|
1633
|
+
return new X(x, W, ot, $);
|
|
1634
|
+
}
|
|
1635
|
+
subtract(o) {
|
|
1636
|
+
return this.add(o.negate());
|
|
1637
|
+
}
|
|
1638
|
+
// Constant-time multiplication.
|
|
1639
|
+
multiply(o) {
|
|
1640
|
+
if (!P.isValidNot0(o))
|
|
1641
|
+
throw new Error("invalid scalar: expected 1 <= sc < curve.n");
|
|
1642
|
+
const { p, f: c } = N.cached(this, o, (s) => (0, f.normalizeZ)(X, s));
|
|
1643
|
+
return (0, f.normalizeZ)(X, [p, c])[0];
|
|
1644
|
+
}
|
|
1645
|
+
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1646
|
+
// It's faster, but should only be used when you don't care about
|
|
1647
|
+
// an exposed private key e.g. sig verification.
|
|
1648
|
+
// Does NOT allow scalars higher than CURVE.n.
|
|
1649
|
+
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
1650
|
+
multiplyUnsafe(o, p = X.ZERO) {
|
|
1651
|
+
if (!P.isValid(o))
|
|
1652
|
+
throw new Error("invalid scalar: expected 0 <= sc < curve.n");
|
|
1653
|
+
return o === S ? X.ZERO : this.is0() || o === H ? this : N.unsafe(this, o, (c) => (0, f.normalizeZ)(X, c), p);
|
|
1654
|
+
}
|
|
1655
|
+
// Checks if point is of small order.
|
|
1656
|
+
// If you add something to small order point, you will have "dirty"
|
|
1657
|
+
// point with torsion component.
|
|
1658
|
+
// Multiplies point by cofactor and checks if the result is 0.
|
|
1659
|
+
isSmallOrder() {
|
|
1660
|
+
return this.multiplyUnsafe(k).is0();
|
|
1661
|
+
}
|
|
1662
|
+
// Multiplies point by curve order and checks if the result is 0.
|
|
1663
|
+
// Returns `false` is the point is dirty.
|
|
1664
|
+
isTorsionFree() {
|
|
1665
|
+
return N.unsafe(this, V.n).is0();
|
|
1666
|
+
}
|
|
1667
|
+
// Converts Extended point to default (x, y) coordinates.
|
|
1668
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
1669
|
+
toAffine(o) {
|
|
1670
|
+
return z(this, o);
|
|
1671
|
+
}
|
|
1672
|
+
clearCofactor() {
|
|
1673
|
+
return k === H ? this : this.multiplyUnsafe(k);
|
|
1674
|
+
}
|
|
1675
|
+
toBytes() {
|
|
1676
|
+
const { x: o, y: p } = this.toAffine(), c = T.toBytes(p);
|
|
1677
|
+
return c[c.length - 1] |= o & H ? 128 : 0, c;
|
|
1678
|
+
}
|
|
1679
|
+
toHex() {
|
|
1680
|
+
return (0, t.bytesToHex)(this.toBytes());
|
|
1681
|
+
}
|
|
1682
|
+
toString() {
|
|
1683
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1684
|
+
}
|
|
1685
|
+
// TODO: remove
|
|
1686
|
+
get ex() {
|
|
1687
|
+
return this.X;
|
|
1688
|
+
}
|
|
1689
|
+
get ey() {
|
|
1690
|
+
return this.Y;
|
|
1691
|
+
}
|
|
1692
|
+
get ez() {
|
|
1693
|
+
return this.Z;
|
|
1694
|
+
}
|
|
1695
|
+
get et() {
|
|
1696
|
+
return this.T;
|
|
1697
|
+
}
|
|
1698
|
+
static normalizeZ(o) {
|
|
1699
|
+
return (0, f.normalizeZ)(X, o);
|
|
1700
|
+
}
|
|
1701
|
+
static msm(o, p) {
|
|
1702
|
+
return (0, f.pippenger)(X, P, o, p);
|
|
1703
|
+
}
|
|
1704
|
+
_setWindowSize(o) {
|
|
1705
|
+
this.precompute(o);
|
|
1706
|
+
}
|
|
1707
|
+
toRawBytes() {
|
|
1708
|
+
return this.toBytes();
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
X.BASE = new X(V.Gx, V.Gy, H, E(V.Gx * V.Gy)), X.ZERO = new X(S, H, H, S), X.Fp = T, X.Fn = P;
|
|
1712
|
+
const N = new f.wNAF(X, P.BITS);
|
|
1713
|
+
return X.BASE.precompute(8), X;
|
|
1714
|
+
}
|
|
1715
|
+
class G {
|
|
1716
|
+
constructor(w) {
|
|
1717
|
+
this.ep = w;
|
|
1718
|
+
}
|
|
1719
|
+
// Static methods that must be implemented by subclasses
|
|
1720
|
+
static fromBytes(w) {
|
|
1721
|
+
(0, t.notImplemented)();
|
|
1722
|
+
}
|
|
1723
|
+
static fromHex(w) {
|
|
1724
|
+
(0, t.notImplemented)();
|
|
1725
|
+
}
|
|
1726
|
+
get x() {
|
|
1727
|
+
return this.toAffine().x;
|
|
1728
|
+
}
|
|
1729
|
+
get y() {
|
|
1730
|
+
return this.toAffine().y;
|
|
1731
|
+
}
|
|
1732
|
+
// Common implementations
|
|
1733
|
+
clearCofactor() {
|
|
1734
|
+
return this;
|
|
1735
|
+
}
|
|
1736
|
+
assertValidity() {
|
|
1737
|
+
this.ep.assertValidity();
|
|
1738
|
+
}
|
|
1739
|
+
toAffine(w) {
|
|
1740
|
+
return this.ep.toAffine(w);
|
|
1741
|
+
}
|
|
1742
|
+
toHex() {
|
|
1743
|
+
return (0, t.bytesToHex)(this.toBytes());
|
|
1744
|
+
}
|
|
1745
|
+
toString() {
|
|
1746
|
+
return this.toHex();
|
|
1747
|
+
}
|
|
1748
|
+
isTorsionFree() {
|
|
1749
|
+
return !0;
|
|
1750
|
+
}
|
|
1751
|
+
isSmallOrder() {
|
|
1752
|
+
return !1;
|
|
1753
|
+
}
|
|
1754
|
+
add(w) {
|
|
1755
|
+
return this.assertSame(w), this.init(this.ep.add(w.ep));
|
|
1756
|
+
}
|
|
1757
|
+
subtract(w) {
|
|
1758
|
+
return this.assertSame(w), this.init(this.ep.subtract(w.ep));
|
|
1759
|
+
}
|
|
1760
|
+
multiply(w) {
|
|
1761
|
+
return this.init(this.ep.multiply(w));
|
|
1762
|
+
}
|
|
1763
|
+
multiplyUnsafe(w) {
|
|
1764
|
+
return this.init(this.ep.multiplyUnsafe(w));
|
|
1765
|
+
}
|
|
1766
|
+
double() {
|
|
1767
|
+
return this.init(this.ep.double());
|
|
1768
|
+
}
|
|
1769
|
+
negate() {
|
|
1770
|
+
return this.init(this.ep.negate());
|
|
1771
|
+
}
|
|
1772
|
+
precompute(w, v) {
|
|
1773
|
+
return this.init(this.ep.precompute(w, v));
|
|
1774
|
+
}
|
|
1775
|
+
/** @deprecated use `toBytes` */
|
|
1776
|
+
toRawBytes() {
|
|
1777
|
+
return this.toBytes();
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
Tt.PrimeEdwardsPoint = G;
|
|
1781
|
+
function Y(d, w, v = {}) {
|
|
1782
|
+
if (typeof w != "function")
|
|
1783
|
+
throw new Error('"hash" function param is required');
|
|
1784
|
+
(0, t._validateObject)(v, {}, {
|
|
1785
|
+
adjustScalarBytes: "function",
|
|
1786
|
+
randomBytes: "function",
|
|
1787
|
+
domain: "function",
|
|
1788
|
+
prehash: "function",
|
|
1789
|
+
mapToCurve: "function"
|
|
1790
|
+
});
|
|
1791
|
+
const { prehash: T } = v, { BASE: P, Fp: V, Fn: k } = d, O = v.randomBytes || t.randomBytes, E = v.adjustScalarBytes || ((r) => r), U = v.domain || ((r, i, a) => {
|
|
1792
|
+
if ((0, t._abool2)(a, "phflag"), i.length || a)
|
|
1793
|
+
throw new Error("Contexts/pre-hash are not supported");
|
|
1794
|
+
return r;
|
|
1795
|
+
});
|
|
1796
|
+
function Z(r) {
|
|
1797
|
+
return k.create((0, t.bytesToNumberLE)(r));
|
|
1798
|
+
}
|
|
1799
|
+
function j(r) {
|
|
1800
|
+
const i = c.secretKey;
|
|
1801
|
+
r = (0, t.ensureBytes)("private key", r, i);
|
|
1802
|
+
const a = (0, t.ensureBytes)("hashed private key", w(r), 2 * i), b = E(a.slice(0, i)), A = a.slice(i, 2 * i), u = Z(b);
|
|
1803
|
+
return { head: b, prefix: A, scalar: u };
|
|
1804
|
+
}
|
|
1805
|
+
function z(r) {
|
|
1806
|
+
const { head: i, prefix: a, scalar: b } = j(r), A = P.multiply(b), u = A.toBytes();
|
|
1807
|
+
return { head: i, prefix: a, scalar: b, point: A, pointBytes: u };
|
|
1808
|
+
}
|
|
1809
|
+
function Q(r) {
|
|
1810
|
+
return z(r).pointBytes;
|
|
1811
|
+
}
|
|
1812
|
+
function X(r = Uint8Array.of(), ...i) {
|
|
1813
|
+
const a = (0, t.concatBytes)(...i);
|
|
1814
|
+
return Z(w(U(a, (0, t.ensureBytes)("context", r), !!T)));
|
|
1815
|
+
}
|
|
1816
|
+
function N(r, i, a = {}) {
|
|
1817
|
+
r = (0, t.ensureBytes)("message", r), T && (r = T(r));
|
|
1818
|
+
const { prefix: b, scalar: A, pointBytes: u } = z(i), l = X(a.context, b, r), g = P.multiply(l).toBytes(), _ = X(a.context, g, u, r), C = k.create(l + _ * A);
|
|
1819
|
+
if (!k.isValid(C))
|
|
1820
|
+
throw new Error("sign failed: invalid s");
|
|
1821
|
+
const h = (0, t.concatBytes)(g, k.toBytes(C));
|
|
1822
|
+
return (0, t._abytes2)(h, c.signature, "result");
|
|
1823
|
+
}
|
|
1824
|
+
const R = { zip215: !0 };
|
|
1825
|
+
function o(r, i, a, b = R) {
|
|
1826
|
+
const { context: A, zip215: u } = b, l = c.signature;
|
|
1827
|
+
r = (0, t.ensureBytes)("signature", r, l), i = (0, t.ensureBytes)("message", i), a = (0, t.ensureBytes)("publicKey", a, c.publicKey), u !== void 0 && (0, t._abool2)(u, "zip215"), T && (i = T(i));
|
|
1828
|
+
const g = l / 2, _ = r.subarray(0, g), C = (0, t.bytesToNumberLE)(r.subarray(g, l));
|
|
1829
|
+
let h, x, W;
|
|
1830
|
+
try {
|
|
1831
|
+
h = d.fromBytes(a, u), x = d.fromBytes(_, u), W = P.multiplyUnsafe(C);
|
|
1832
|
+
} catch {
|
|
1833
|
+
return !1;
|
|
1834
|
+
}
|
|
1835
|
+
if (!u && h.isSmallOrder())
|
|
1836
|
+
return !1;
|
|
1837
|
+
const $ = X(A, x.toBytes(), h.toBytes(), i);
|
|
1838
|
+
return x.add(h.multiplyUnsafe($)).subtract(W).clearCofactor().is0();
|
|
1839
|
+
}
|
|
1840
|
+
const p = V.BYTES, c = {
|
|
1841
|
+
secretKey: p,
|
|
1842
|
+
publicKey: p,
|
|
1843
|
+
signature: 2 * p,
|
|
1844
|
+
seed: p
|
|
1845
|
+
};
|
|
1846
|
+
function s(r = O(c.seed)) {
|
|
1847
|
+
return (0, t._abytes2)(r, c.seed, "seed");
|
|
1848
|
+
}
|
|
1849
|
+
function q(r) {
|
|
1850
|
+
const i = n.randomSecretKey(r);
|
|
1851
|
+
return { secretKey: i, publicKey: Q(i) };
|
|
1852
|
+
}
|
|
1853
|
+
function K(r) {
|
|
1854
|
+
return (0, t.isBytes)(r) && r.length === k.BYTES;
|
|
1855
|
+
}
|
|
1856
|
+
function e(r, i) {
|
|
1857
|
+
try {
|
|
1858
|
+
return !!d.fromBytes(r, i);
|
|
1859
|
+
} catch {
|
|
1860
|
+
return !1;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
const n = {
|
|
1864
|
+
getExtendedPublicKey: z,
|
|
1865
|
+
randomSecretKey: s,
|
|
1866
|
+
isValidSecretKey: K,
|
|
1867
|
+
isValidPublicKey: e,
|
|
1868
|
+
/**
|
|
1869
|
+
* Converts ed public key to x public key. Uses formula:
|
|
1870
|
+
* - ed25519:
|
|
1871
|
+
* - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
|
|
1872
|
+
* - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
|
|
1873
|
+
* - ed448:
|
|
1874
|
+
* - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
|
|
1875
|
+
* - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
|
|
1876
|
+
*/
|
|
1877
|
+
toMontgomery(r) {
|
|
1878
|
+
const { y: i } = d.fromBytes(r), a = c.publicKey, b = a === 32;
|
|
1879
|
+
if (!b && a !== 57)
|
|
1880
|
+
throw new Error("only defined for 25519 and 448");
|
|
1881
|
+
const A = b ? V.div(H + i, H - i) : V.div(i - H, i + H);
|
|
1882
|
+
return V.toBytes(A);
|
|
1883
|
+
},
|
|
1884
|
+
toMontgomerySecret(r) {
|
|
1885
|
+
const i = c.secretKey;
|
|
1886
|
+
(0, t._abytes2)(r, i);
|
|
1887
|
+
const a = w(r.subarray(0, i));
|
|
1888
|
+
return E(a).subarray(0, i);
|
|
1889
|
+
},
|
|
1890
|
+
/** @deprecated */
|
|
1891
|
+
randomPrivateKey: s,
|
|
1892
|
+
/** @deprecated */
|
|
1893
|
+
precompute(r = 8, i = d.BASE) {
|
|
1894
|
+
return i.precompute(r, !1);
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
return Object.freeze({
|
|
1898
|
+
keygen: q,
|
|
1899
|
+
getPublicKey: Q,
|
|
1900
|
+
sign: N,
|
|
1901
|
+
verify: o,
|
|
1902
|
+
utils: n,
|
|
1903
|
+
Point: d,
|
|
1904
|
+
lengths: c
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
function L(d) {
|
|
1908
|
+
const w = {
|
|
1909
|
+
a: d.a,
|
|
1910
|
+
d: d.d,
|
|
1911
|
+
p: d.Fp.ORDER,
|
|
1912
|
+
n: d.n,
|
|
1913
|
+
h: d.h,
|
|
1914
|
+
Gx: d.Gx,
|
|
1915
|
+
Gy: d.Gy
|
|
1916
|
+
}, v = d.Fp, T = (0, y.Field)(w.n, d.nBitLength, !0), P = { Fp: v, Fn: T, uvRatio: d.uvRatio }, V = {
|
|
1917
|
+
randomBytes: d.randomBytes,
|
|
1918
|
+
adjustScalarBytes: d.adjustScalarBytes,
|
|
1919
|
+
domain: d.domain,
|
|
1920
|
+
prehash: d.prehash,
|
|
1921
|
+
mapToCurve: d.mapToCurve
|
|
1922
|
+
};
|
|
1923
|
+
return { CURVE: w, curveOpts: P, hash: d.hash, eddsaOpts: V };
|
|
1924
|
+
}
|
|
1925
|
+
function M(d, w) {
|
|
1926
|
+
const v = w.Point;
|
|
1927
|
+
return Object.assign({}, w, {
|
|
1928
|
+
ExtendedPoint: v,
|
|
1929
|
+
CURVE: d,
|
|
1930
|
+
nBitLength: v.Fn.BITS,
|
|
1931
|
+
nByteLength: v.Fn.BYTES
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
function B(d) {
|
|
1935
|
+
const { CURVE: w, curveOpts: v, hash: T, eddsaOpts: P } = L(d), V = F(w, v), k = Y(V, T, P);
|
|
1936
|
+
return M(d, k);
|
|
1937
|
+
}
|
|
1938
|
+
return Tt;
|
|
1939
|
+
}
|
|
1940
|
+
var ne = {}, Ce;
|
|
1941
|
+
function tn() {
|
|
1942
|
+
return Ce || (Ce = 1, (function(t) {
|
|
1943
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t._DST_scalar = void 0, t.expand_message_xmd = F, t.expand_message_xof = G, t.hash_to_field = Y, t.isogenyMap = L, t.createHasher = M;
|
|
1944
|
+
const f = /* @__PURE__ */ Ut(), y = /* @__PURE__ */ qt(), S = f.bytesToNumberBE;
|
|
1945
|
+
function H(B, d) {
|
|
1946
|
+
if (I(B), I(d), B < 0 || B >= 1 << 8 * d)
|
|
1947
|
+
throw new Error("invalid I2OSP input: " + B);
|
|
1948
|
+
const w = Array.from({ length: d }).fill(0);
|
|
1949
|
+
for (let v = d - 1; v >= 0; v--)
|
|
1950
|
+
w[v] = B & 255, B >>>= 8;
|
|
1951
|
+
return new Uint8Array(w);
|
|
1952
|
+
}
|
|
1953
|
+
function m(B, d) {
|
|
1954
|
+
const w = new Uint8Array(B.length);
|
|
1955
|
+
for (let v = 0; v < B.length; v++)
|
|
1956
|
+
w[v] = B[v] ^ d[v];
|
|
1957
|
+
return w;
|
|
1958
|
+
}
|
|
1959
|
+
function I(B) {
|
|
1960
|
+
if (!Number.isSafeInteger(B))
|
|
1961
|
+
throw new Error("number expected");
|
|
1962
|
+
}
|
|
1963
|
+
function D(B) {
|
|
1964
|
+
if (!(0, f.isBytes)(B) && typeof B != "string")
|
|
1965
|
+
throw new Error("DST must be Uint8Array or string");
|
|
1966
|
+
return typeof B == "string" ? (0, f.utf8ToBytes)(B) : B;
|
|
1967
|
+
}
|
|
1968
|
+
function F(B, d, w, v) {
|
|
1969
|
+
(0, f.abytes)(B), I(w), d = D(d), d.length > 255 && (d = v((0, f.concatBytes)((0, f.utf8ToBytes)("H2C-OVERSIZE-DST-"), d)));
|
|
1970
|
+
const { outputLen: T, blockLen: P } = v, V = Math.ceil(w / T);
|
|
1971
|
+
if (w > 65535 || V > 255)
|
|
1972
|
+
throw new Error("expand_message_xmd: invalid lenInBytes");
|
|
1973
|
+
const k = (0, f.concatBytes)(d, H(d.length, 1)), O = H(0, P), E = H(w, 2), U = new Array(V), Z = v((0, f.concatBytes)(O, B, E, H(0, 1), k));
|
|
1974
|
+
U[0] = v((0, f.concatBytes)(Z, H(1, 1), k));
|
|
1975
|
+
for (let z = 1; z <= V; z++) {
|
|
1976
|
+
const Q = [m(Z, U[z - 1]), H(z + 1, 1), k];
|
|
1977
|
+
U[z] = v((0, f.concatBytes)(...Q));
|
|
1978
|
+
}
|
|
1979
|
+
return (0, f.concatBytes)(...U).slice(0, w);
|
|
1980
|
+
}
|
|
1981
|
+
function G(B, d, w, v, T) {
|
|
1982
|
+
if ((0, f.abytes)(B), I(w), d = D(d), d.length > 255) {
|
|
1983
|
+
const P = Math.ceil(2 * v / 8);
|
|
1984
|
+
d = T.create({ dkLen: P }).update((0, f.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(d).digest();
|
|
1985
|
+
}
|
|
1986
|
+
if (w > 65535 || d.length > 255)
|
|
1987
|
+
throw new Error("expand_message_xof: invalid lenInBytes");
|
|
1988
|
+
return T.create({ dkLen: w }).update(B).update(H(w, 2)).update(d).update(H(d.length, 1)).digest();
|
|
1989
|
+
}
|
|
1990
|
+
function Y(B, d, w) {
|
|
1991
|
+
(0, f._validateObject)(w, {
|
|
1992
|
+
p: "bigint",
|
|
1993
|
+
m: "number",
|
|
1994
|
+
k: "number",
|
|
1995
|
+
hash: "function"
|
|
1996
|
+
});
|
|
1997
|
+
const { p: v, k: T, m: P, hash: V, expand: k, DST: O } = w;
|
|
1998
|
+
if (!(0, f.isHash)(w.hash))
|
|
1999
|
+
throw new Error("expected valid hash");
|
|
2000
|
+
(0, f.abytes)(B), I(d);
|
|
2001
|
+
const E = v.toString(2).length, U = Math.ceil((E + T) / 8), Z = d * P * U;
|
|
2002
|
+
let j;
|
|
2003
|
+
if (k === "xmd")
|
|
2004
|
+
j = F(B, O, Z, V);
|
|
2005
|
+
else if (k === "xof")
|
|
2006
|
+
j = G(B, O, Z, T, V);
|
|
2007
|
+
else if (k === "_internal_pass")
|
|
2008
|
+
j = B;
|
|
2009
|
+
else
|
|
2010
|
+
throw new Error('expand must be "xmd" or "xof"');
|
|
2011
|
+
const z = new Array(d);
|
|
2012
|
+
for (let Q = 0; Q < d; Q++) {
|
|
2013
|
+
const X = new Array(P);
|
|
2014
|
+
for (let N = 0; N < P; N++) {
|
|
2015
|
+
const R = U * (N + Q * P), o = j.subarray(R, R + U);
|
|
2016
|
+
X[N] = (0, y.mod)(S(o), v);
|
|
2017
|
+
}
|
|
2018
|
+
z[Q] = X;
|
|
2019
|
+
}
|
|
2020
|
+
return z;
|
|
2021
|
+
}
|
|
2022
|
+
function L(B, d) {
|
|
2023
|
+
const w = d.map((v) => Array.from(v).reverse());
|
|
2024
|
+
return (v, T) => {
|
|
2025
|
+
const [P, V, k, O] = w.map((Z) => Z.reduce((j, z) => B.add(B.mul(j, v), z))), [E, U] = (0, y.FpInvertBatch)(B, [V, O], !0);
|
|
2026
|
+
return v = B.mul(P, E), T = B.mul(T, B.mul(k, U)), { x: v, y: T };
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
t._DST_scalar = (0, f.utf8ToBytes)("HashToScalar-");
|
|
2030
|
+
function M(B, d, w) {
|
|
2031
|
+
if (typeof d != "function")
|
|
2032
|
+
throw new Error("mapToCurve() must be defined");
|
|
2033
|
+
function v(P) {
|
|
2034
|
+
return B.fromAffine(d(P));
|
|
2035
|
+
}
|
|
2036
|
+
function T(P) {
|
|
2037
|
+
const V = P.clearCofactor();
|
|
2038
|
+
return V.equals(B.ZERO) ? B.ZERO : (V.assertValidity(), V);
|
|
2039
|
+
}
|
|
2040
|
+
return {
|
|
2041
|
+
defaults: w,
|
|
2042
|
+
hashToCurve(P, V) {
|
|
2043
|
+
const k = Object.assign({}, w, V), O = Y(P, 2, k), E = v(O[0]), U = v(O[1]);
|
|
2044
|
+
return T(E.add(U));
|
|
2045
|
+
},
|
|
2046
|
+
encodeToCurve(P, V) {
|
|
2047
|
+
const k = w.encodeDST ? { DST: w.encodeDST } : {}, O = Object.assign({}, w, k, V), E = Y(P, 1, O), U = v(E[0]);
|
|
2048
|
+
return T(U);
|
|
2049
|
+
},
|
|
2050
|
+
/** See {@link H2CHasher} */
|
|
2051
|
+
mapToCurve(P) {
|
|
2052
|
+
if (!Array.isArray(P))
|
|
2053
|
+
throw new Error("expected array of bigints");
|
|
2054
|
+
for (const V of P)
|
|
2055
|
+
if (typeof V != "bigint")
|
|
2056
|
+
throw new Error("expected array of bigints");
|
|
2057
|
+
return T(v(P));
|
|
2058
|
+
},
|
|
2059
|
+
// hash_to_scalar can produce 0: https://www.rfc-editor.org/errata/eid8393
|
|
2060
|
+
// RFC 9380, draft-irtf-cfrg-bbs-signatures-08
|
|
2061
|
+
hashToScalar(P, V) {
|
|
2062
|
+
const k = B.Fn.ORDER, O = Object.assign({}, w, { p: k, m: 1, DST: t._DST_scalar }, V);
|
|
2063
|
+
return Y(P, 1, O)[0][0];
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
})(ne)), ne;
|
|
2068
|
+
}
|
|
2069
|
+
var Yt = {}, He;
|
|
2070
|
+
function hn() {
|
|
2071
|
+
if (He) return Yt;
|
|
2072
|
+
He = 1, Object.defineProperty(Yt, "__esModule", { value: !0 }), Yt.montgomery = I;
|
|
2073
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2074
|
+
const t = /* @__PURE__ */ Ut(), f = /* @__PURE__ */ qt(), y = BigInt(0), S = BigInt(1), H = BigInt(2);
|
|
2075
|
+
function m(D) {
|
|
2076
|
+
return (0, t._validateObject)(D, {
|
|
2077
|
+
adjustScalarBytes: "function",
|
|
2078
|
+
powPminus2: "function"
|
|
2079
|
+
}), Object.freeze({ ...D });
|
|
2080
|
+
}
|
|
2081
|
+
function I(D) {
|
|
2082
|
+
const F = m(D), { P: G, type: Y, adjustScalarBytes: L, powPminus2: M, randomBytes: B } = F, d = Y === "x25519";
|
|
2083
|
+
if (!d && Y !== "x448")
|
|
2084
|
+
throw new Error("invalid type");
|
|
2085
|
+
const w = B || t.randomBytes, v = d ? 255 : 448, T = d ? 32 : 56, P = BigInt(d ? 9 : 5), V = BigInt(d ? 121665 : 39081), k = d ? H ** BigInt(254) : H ** BigInt(447), O = d ? BigInt(8) * H ** BigInt(251) - S : BigInt(4) * H ** BigInt(445) - S, E = k + O + S, U = (K) => (0, f.mod)(K, G), Z = j(P);
|
|
2086
|
+
function j(K) {
|
|
2087
|
+
return (0, t.numberToBytesLE)(U(K), T);
|
|
2088
|
+
}
|
|
2089
|
+
function z(K) {
|
|
2090
|
+
const e = (0, t.ensureBytes)("u coordinate", K, T);
|
|
2091
|
+
return d && (e[31] &= 127), U((0, t.bytesToNumberLE)(e));
|
|
2092
|
+
}
|
|
2093
|
+
function Q(K) {
|
|
2094
|
+
return (0, t.bytesToNumberLE)(L((0, t.ensureBytes)("scalar", K, T)));
|
|
2095
|
+
}
|
|
2096
|
+
function X(K, e) {
|
|
2097
|
+
const n = o(z(e), Q(K));
|
|
2098
|
+
if (n === y)
|
|
2099
|
+
throw new Error("invalid private or public key received");
|
|
2100
|
+
return j(n);
|
|
2101
|
+
}
|
|
2102
|
+
function N(K) {
|
|
2103
|
+
return X(K, Z);
|
|
2104
|
+
}
|
|
2105
|
+
function R(K, e, n) {
|
|
2106
|
+
const r = U(K * (e - n));
|
|
2107
|
+
return e = U(e - r), n = U(n + r), { x_2: e, x_3: n };
|
|
2108
|
+
}
|
|
2109
|
+
function o(K, e) {
|
|
2110
|
+
(0, t.aInRange)("u", K, y, G), (0, t.aInRange)("scalar", e, k, E);
|
|
2111
|
+
const n = e, r = K;
|
|
2112
|
+
let i = S, a = y, b = K, A = S, u = y;
|
|
2113
|
+
for (let g = BigInt(v - 1); g >= y; g--) {
|
|
2114
|
+
const _ = n >> g & S;
|
|
2115
|
+
u ^= _, { x_2: i, x_3: b } = R(u, i, b), { x_2: a, x_3: A } = R(u, a, A), u = _;
|
|
2116
|
+
const C = i + a, h = U(C * C), x = i - a, W = U(x * x), $ = h - W, ot = b + A, nt = b - A, st = U(nt * C), rt = U(ot * x), yt = st + rt, ut = st - rt;
|
|
2117
|
+
b = U(yt * yt), A = U(r * U(ut * ut)), i = U(h * W), a = U($ * (h + U(V * $)));
|
|
2118
|
+
}
|
|
2119
|
+
({ x_2: i, x_3: b } = R(u, i, b)), { x_2: a, x_3: A } = R(u, a, A);
|
|
2120
|
+
const l = M(a);
|
|
2121
|
+
return U(i * l);
|
|
2122
|
+
}
|
|
2123
|
+
const p = {
|
|
2124
|
+
secretKey: T,
|
|
2125
|
+
publicKey: T,
|
|
2126
|
+
seed: T
|
|
2127
|
+
}, c = (K = w(T)) => ((0, t.abytes)(K, p.seed), K);
|
|
2128
|
+
function s(K) {
|
|
2129
|
+
const e = c(K);
|
|
2130
|
+
return { secretKey: e, publicKey: N(e) };
|
|
2131
|
+
}
|
|
2132
|
+
return {
|
|
2133
|
+
keygen: s,
|
|
2134
|
+
getSharedSecret: (K, e) => X(K, e),
|
|
2135
|
+
getPublicKey: (K) => N(K),
|
|
2136
|
+
scalarMult: X,
|
|
2137
|
+
scalarMultBase: N,
|
|
2138
|
+
utils: {
|
|
2139
|
+
randomSecretKey: c,
|
|
2140
|
+
randomPrivateKey: c
|
|
2141
|
+
},
|
|
2142
|
+
GuBytes: Z.slice(),
|
|
2143
|
+
lengths: p
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
return Yt;
|
|
2147
|
+
}
|
|
2148
|
+
var Oe;
|
|
2149
|
+
function yn() {
|
|
2150
|
+
return Oe || (Oe = 1, (function(t) {
|
|
2151
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.hash_to_ristretto255 = t.hashToRistretto255 = t.encodeToCurve = t.hashToCurve = t.RistrettoPoint = t.edwardsToMontgomery = t.ED25519_TORSION_SUBGROUP = t.ristretto255_hasher = t.ristretto255 = t.ed25519_hasher = t.x25519 = t.ed25519ph = t.ed25519ctx = t.ed25519 = void 0, t.edwardsToMontgomeryPub = b, t.edwardsToMontgomeryPriv = A;
|
|
2152
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2153
|
+
const f = /* @__PURE__ */ de(), y = /* @__PURE__ */ Ot(), S = /* @__PURE__ */ he(), H = /* @__PURE__ */ dn(), m = /* @__PURE__ */ tn(), I = /* @__PURE__ */ qt(), D = /* @__PURE__ */ hn(), F = /* @__PURE__ */ Ut(), G = /* @__PURE__ */ BigInt(0), Y = BigInt(1), L = BigInt(2), M = BigInt(3), B = BigInt(5), d = BigInt(8), w = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"), v = {
|
|
2154
|
+
p: w,
|
|
2155
|
+
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
2156
|
+
h: d,
|
|
2157
|
+
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
2158
|
+
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
2159
|
+
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
2160
|
+
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
2161
|
+
};
|
|
2162
|
+
function T(u) {
|
|
2163
|
+
const l = BigInt(10), g = BigInt(20), _ = BigInt(40), C = BigInt(80), h = w, W = u * u % h * u % h, $ = (0, I.pow2)(W, L, h) * W % h, ot = (0, I.pow2)($, Y, h) * u % h, nt = (0, I.pow2)(ot, B, h) * ot % h, st = (0, I.pow2)(nt, l, h) * nt % h, rt = (0, I.pow2)(st, g, h) * st % h, yt = (0, I.pow2)(rt, _, h) * rt % h, ut = (0, I.pow2)(yt, C, h) * yt % h, ct = (0, I.pow2)(ut, C, h) * yt % h, et = (0, I.pow2)(ct, l, h) * nt % h;
|
|
2164
|
+
return { pow_p_5_8: (0, I.pow2)(et, L, h) * u % h, b2: W };
|
|
2165
|
+
}
|
|
2166
|
+
function P(u) {
|
|
2167
|
+
return u[0] &= 248, u[31] &= 127, u[31] |= 64, u;
|
|
2168
|
+
}
|
|
2169
|
+
const V = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
2170
|
+
function k(u, l) {
|
|
2171
|
+
const g = w, _ = (0, I.mod)(l * l * l, g), C = (0, I.mod)(_ * _ * l, g), h = T(u * C).pow_p_5_8;
|
|
2172
|
+
let x = (0, I.mod)(u * _ * h, g);
|
|
2173
|
+
const W = (0, I.mod)(l * x * x, g), $ = x, ot = (0, I.mod)(x * V, g), nt = W === u, st = W === (0, I.mod)(-u, g), rt = W === (0, I.mod)(-u * V, g);
|
|
2174
|
+
return nt && (x = $), (st || rt) && (x = ot), (0, I.isNegativeLE)(x, g) && (x = (0, I.mod)(-x, g)), { isValid: nt || st, value: x };
|
|
2175
|
+
}
|
|
2176
|
+
const O = (0, I.Field)(v.p, { isLE: !0 }), E = (0, I.Field)(v.n, { isLE: !0 }), U = {
|
|
2177
|
+
...v,
|
|
2178
|
+
Fp: O,
|
|
2179
|
+
hash: f.sha512,
|
|
2180
|
+
adjustScalarBytes: P,
|
|
2181
|
+
// dom2
|
|
2182
|
+
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
2183
|
+
// Constant-time, u/√v
|
|
2184
|
+
uvRatio: k
|
|
2185
|
+
};
|
|
2186
|
+
t.ed25519 = (0, H.twistedEdwards)(U);
|
|
2187
|
+
function Z(u, l, g) {
|
|
2188
|
+
if (l.length > 255)
|
|
2189
|
+
throw new Error("Context is too big");
|
|
2190
|
+
return (0, y.concatBytes)((0, y.utf8ToBytes)("SigEd25519 no Ed25519 collisions"), new Uint8Array([g ? 1 : 0, l.length]), l, u);
|
|
2191
|
+
}
|
|
2192
|
+
t.ed25519ctx = (0, H.twistedEdwards)({
|
|
2193
|
+
...U,
|
|
2194
|
+
domain: Z
|
|
2195
|
+
}), t.ed25519ph = (0, H.twistedEdwards)(Object.assign({}, U, {
|
|
2196
|
+
domain: Z,
|
|
2197
|
+
prehash: f.sha512
|
|
2198
|
+
})), t.x25519 = (() => {
|
|
2199
|
+
const u = O.ORDER;
|
|
2200
|
+
return (0, D.montgomery)({
|
|
2201
|
+
P: u,
|
|
2202
|
+
type: "x25519",
|
|
2203
|
+
powPminus2: (l) => {
|
|
2204
|
+
const { pow_p_5_8: g, b2: _ } = T(l);
|
|
2205
|
+
return (0, I.mod)((0, I.pow2)(g, M, u) * _, u);
|
|
2206
|
+
},
|
|
2207
|
+
adjustScalarBytes: P
|
|
2208
|
+
});
|
|
2209
|
+
})();
|
|
2210
|
+
const j = (w + M) / d, z = O.pow(L, j), Q = O.sqrt(O.neg(O.ONE));
|
|
2211
|
+
function X(u) {
|
|
2212
|
+
const l = (w - B) / d, g = BigInt(486662);
|
|
2213
|
+
let _ = O.sqr(u);
|
|
2214
|
+
_ = O.mul(_, L);
|
|
2215
|
+
let C = O.add(_, O.ONE), h = O.neg(g), x = O.sqr(C), W = O.mul(x, C), $ = O.mul(_, g);
|
|
2216
|
+
$ = O.mul($, h), $ = O.add($, x), $ = O.mul($, h);
|
|
2217
|
+
let ot = O.sqr(W);
|
|
2218
|
+
x = O.sqr(ot), ot = O.mul(ot, W), ot = O.mul(ot, $), x = O.mul(x, ot);
|
|
2219
|
+
let nt = O.pow(x, l);
|
|
2220
|
+
nt = O.mul(nt, ot);
|
|
2221
|
+
let st = O.mul(nt, Q);
|
|
2222
|
+
x = O.sqr(nt), x = O.mul(x, W);
|
|
2223
|
+
let rt = O.eql(x, $), yt = O.cmov(st, nt, rt), ut = O.mul(h, _), ct = O.mul(nt, u);
|
|
2224
|
+
ct = O.mul(ct, z);
|
|
2225
|
+
let et = O.mul(ct, Q), tt = O.mul($, _);
|
|
2226
|
+
x = O.sqr(ct), x = O.mul(x, W);
|
|
2227
|
+
let J = O.eql(x, tt), it = O.cmov(et, ct, J);
|
|
2228
|
+
x = O.sqr(yt), x = O.mul(x, W);
|
|
2229
|
+
let at = O.eql(x, $), dt = O.cmov(ut, h, at), ft = O.cmov(it, yt, at), lt = O.isOdd(ft);
|
|
2230
|
+
return ft = O.cmov(ft, O.neg(ft), at !== lt), { xMn: dt, xMd: C, yMn: ft, yMd: Y };
|
|
2231
|
+
}
|
|
2232
|
+
const N = (0, I.FpSqrtEven)(O, O.neg(BigInt(486664)));
|
|
2233
|
+
function R(u) {
|
|
2234
|
+
const { xMn: l, xMd: g, yMn: _, yMd: C } = X(u);
|
|
2235
|
+
let h = O.mul(l, C);
|
|
2236
|
+
h = O.mul(h, N);
|
|
2237
|
+
let x = O.mul(g, _), W = O.sub(l, g), $ = O.add(l, g), ot = O.mul(x, $), nt = O.eql(ot, O.ZERO);
|
|
2238
|
+
h = O.cmov(h, O.ZERO, nt), x = O.cmov(x, O.ONE, nt), W = O.cmov(W, O.ONE, nt), $ = O.cmov($, O.ONE, nt);
|
|
2239
|
+
const [st, rt] = (0, I.FpInvertBatch)(O, [x, $], !0);
|
|
2240
|
+
return { x: O.mul(h, st), y: O.mul(W, rt) };
|
|
2241
|
+
}
|
|
2242
|
+
t.ed25519_hasher = (0, m.createHasher)(t.ed25519.Point, (u) => R(u[0]), {
|
|
2243
|
+
DST: "edwards25519_XMD:SHA-512_ELL2_RO_",
|
|
2244
|
+
encodeDST: "edwards25519_XMD:SHA-512_ELL2_NU_",
|
|
2245
|
+
p: w,
|
|
2246
|
+
m: 1,
|
|
2247
|
+
k: 128,
|
|
2248
|
+
expand: "xmd",
|
|
2249
|
+
hash: f.sha512
|
|
2250
|
+
});
|
|
2251
|
+
const o = V, p = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"), c = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"), s = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"), q = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"), K = (u) => k(Y, u), e = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), n = (u) => t.ed25519.Point.Fp.create((0, F.bytesToNumberLE)(u) & e);
|
|
2252
|
+
function r(u) {
|
|
2253
|
+
const { d: l } = v, g = w, _ = (tt) => O.create(tt), C = _(o * u * u), h = _((C + Y) * s);
|
|
2254
|
+
let x = BigInt(-1);
|
|
2255
|
+
const W = _((x - l * C) * _(C + l));
|
|
2256
|
+
let { isValid: $, value: ot } = k(h, W), nt = _(ot * u);
|
|
2257
|
+
(0, I.isNegativeLE)(nt, g) || (nt = _(-nt)), $ || (ot = nt), $ || (x = C);
|
|
2258
|
+
const st = _(x * (C - Y) * q - W), rt = ot * ot, yt = _((ot + ot) * W), ut = _(st * p), ct = _(Y - rt), et = _(Y + rt);
|
|
2259
|
+
return new t.ed25519.Point(_(yt * et), _(ct * ut), _(ut * et), _(yt * ct));
|
|
2260
|
+
}
|
|
2261
|
+
function i(u) {
|
|
2262
|
+
(0, y.abytes)(u, 64);
|
|
2263
|
+
const l = n(u.subarray(0, 32)), g = r(l), _ = n(u.subarray(32, 64)), C = r(_);
|
|
2264
|
+
return new a(g.add(C));
|
|
2265
|
+
}
|
|
2266
|
+
class a extends H.PrimeEdwardsPoint {
|
|
2267
|
+
constructor(l) {
|
|
2268
|
+
super(l);
|
|
2269
|
+
}
|
|
2270
|
+
static fromAffine(l) {
|
|
2271
|
+
return new a(t.ed25519.Point.fromAffine(l));
|
|
2272
|
+
}
|
|
2273
|
+
assertSame(l) {
|
|
2274
|
+
if (!(l instanceof a))
|
|
2275
|
+
throw new Error("RistrettoPoint expected");
|
|
2276
|
+
}
|
|
2277
|
+
init(l) {
|
|
2278
|
+
return new a(l);
|
|
2279
|
+
}
|
|
2280
|
+
/** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
|
|
2281
|
+
static hashToCurve(l) {
|
|
2282
|
+
return i((0, F.ensureBytes)("ristrettoHash", l, 64));
|
|
2283
|
+
}
|
|
2284
|
+
static fromBytes(l) {
|
|
2285
|
+
(0, y.abytes)(l, 32);
|
|
2286
|
+
const { a: g, d: _ } = v, C = w, h = (at) => O.create(at), x = n(l);
|
|
2287
|
+
if (!(0, F.equalBytes)(O.toBytes(x), l) || (0, I.isNegativeLE)(x, C))
|
|
2288
|
+
throw new Error("invalid ristretto255 encoding 1");
|
|
2289
|
+
const W = h(x * x), $ = h(Y + g * W), ot = h(Y - g * W), nt = h($ * $), st = h(ot * ot), rt = h(g * _ * nt - st), { isValid: yt, value: ut } = K(h(rt * st)), ct = h(ut * ot), et = h(ut * ct * rt);
|
|
2290
|
+
let tt = h((x + x) * ct);
|
|
2291
|
+
(0, I.isNegativeLE)(tt, C) && (tt = h(-tt));
|
|
2292
|
+
const J = h($ * et), it = h(tt * J);
|
|
2293
|
+
if (!yt || (0, I.isNegativeLE)(it, C) || J === G)
|
|
2294
|
+
throw new Error("invalid ristretto255 encoding 2");
|
|
2295
|
+
return new a(new t.ed25519.Point(tt, J, Y, it));
|
|
2296
|
+
}
|
|
2297
|
+
/**
|
|
2298
|
+
* Converts ristretto-encoded string to ristretto point.
|
|
2299
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
|
|
2300
|
+
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
2301
|
+
*/
|
|
2302
|
+
static fromHex(l) {
|
|
2303
|
+
return a.fromBytes((0, F.ensureBytes)("ristrettoHex", l, 32));
|
|
2304
|
+
}
|
|
2305
|
+
static msm(l, g) {
|
|
2306
|
+
return (0, S.pippenger)(a, t.ed25519.Point.Fn, l, g);
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Encodes ristretto point to Uint8Array.
|
|
2310
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
|
|
2311
|
+
*/
|
|
2312
|
+
toBytes() {
|
|
2313
|
+
let { X: l, Y: g, Z: _, T: C } = this.ep;
|
|
2314
|
+
const h = w, x = (et) => O.create(et), W = x(x(_ + g) * x(_ - g)), $ = x(l * g), ot = x($ * $), { value: nt } = K(x(W * ot)), st = x(nt * W), rt = x(nt * $), yt = x(st * rt * C);
|
|
2315
|
+
let ut;
|
|
2316
|
+
if ((0, I.isNegativeLE)(C * yt, h)) {
|
|
2317
|
+
let et = x(g * o), tt = x(l * o);
|
|
2318
|
+
l = et, g = tt, ut = x(st * c);
|
|
2319
|
+
} else
|
|
2320
|
+
ut = rt;
|
|
2321
|
+
(0, I.isNegativeLE)(l * yt, h) && (g = x(-g));
|
|
2322
|
+
let ct = x((_ - g) * ut);
|
|
2323
|
+
return (0, I.isNegativeLE)(ct, h) && (ct = x(-ct)), O.toBytes(ct);
|
|
2324
|
+
}
|
|
2325
|
+
/**
|
|
2326
|
+
* Compares two Ristretto points.
|
|
2327
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
|
|
2328
|
+
*/
|
|
2329
|
+
equals(l) {
|
|
2330
|
+
this.assertSame(l);
|
|
2331
|
+
const { X: g, Y: _ } = this.ep, { X: C, Y: h } = l.ep, x = (ot) => O.create(ot), W = x(g * h) === x(_ * C), $ = x(_ * h) === x(g * C);
|
|
2332
|
+
return W || $;
|
|
2333
|
+
}
|
|
2334
|
+
is0() {
|
|
2335
|
+
return this.equals(a.ZERO);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
a.BASE = new a(t.ed25519.Point.BASE), a.ZERO = new a(t.ed25519.Point.ZERO), a.Fp = O, a.Fn = E, t.ristretto255 = { Point: a }, t.ristretto255_hasher = {
|
|
2339
|
+
hashToCurve(u, l) {
|
|
2340
|
+
const g = (l == null ? void 0 : l.DST) || "ristretto255_XMD:SHA-512_R255MAP_RO_", _ = (0, m.expand_message_xmd)(u, g, 64, f.sha512);
|
|
2341
|
+
return i(_);
|
|
2342
|
+
},
|
|
2343
|
+
hashToScalar(u, l = { DST: m._DST_scalar }) {
|
|
2344
|
+
const g = (0, m.expand_message_xmd)(u, l.DST, 64, f.sha512);
|
|
2345
|
+
return E.create((0, F.bytesToNumberLE)(g));
|
|
2346
|
+
}
|
|
2347
|
+
}, t.ED25519_TORSION_SUBGROUP = [
|
|
2348
|
+
"0100000000000000000000000000000000000000000000000000000000000000",
|
|
2349
|
+
"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a",
|
|
2350
|
+
"0000000000000000000000000000000000000000000000000000000000000080",
|
|
2351
|
+
"26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05",
|
|
2352
|
+
"ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f",
|
|
2353
|
+
"26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85",
|
|
2354
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
2355
|
+
"c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"
|
|
2356
|
+
];
|
|
2357
|
+
function b(u) {
|
|
2358
|
+
return t.ed25519.utils.toMontgomery((0, F.ensureBytes)("pub", u));
|
|
2359
|
+
}
|
|
2360
|
+
t.edwardsToMontgomery = b;
|
|
2361
|
+
function A(u) {
|
|
2362
|
+
return t.ed25519.utils.toMontgomerySecret((0, F.ensureBytes)("pub", u));
|
|
2363
|
+
}
|
|
2364
|
+
t.RistrettoPoint = a, t.hashToCurve = t.ed25519_hasher.hashToCurve, t.encodeToCurve = t.ed25519_hasher.encodeToCurve, t.hashToRistretto255 = t.ristretto255_hasher.hashToCurve, t.hash_to_ristretto255 = t.ristretto255_hasher.hashToCurve;
|
|
2365
|
+
})(te)), te;
|
|
2366
|
+
}
|
|
2367
|
+
var re = {}, Dt = {}, oe = {}, se = {}, Te;
|
|
2368
|
+
function en() {
|
|
2369
|
+
return Te || (Te = 1, (function(t) {
|
|
2370
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.hmac = t.HMAC = void 0;
|
|
2371
|
+
const f = /* @__PURE__ */ Ot();
|
|
2372
|
+
class y extends f.Hash {
|
|
2373
|
+
constructor(m, I) {
|
|
2374
|
+
super(), this.finished = !1, this.destroyed = !1, (0, f.ahash)(m);
|
|
2375
|
+
const D = (0, f.toBytes)(I);
|
|
2376
|
+
if (this.iHash = m.create(), typeof this.iHash.update != "function")
|
|
2377
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
2378
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
2379
|
+
const F = this.blockLen, G = new Uint8Array(F);
|
|
2380
|
+
G.set(D.length > F ? m.create().update(D).digest() : D);
|
|
2381
|
+
for (let Y = 0; Y < G.length; Y++)
|
|
2382
|
+
G[Y] ^= 54;
|
|
2383
|
+
this.iHash.update(G), this.oHash = m.create();
|
|
2384
|
+
for (let Y = 0; Y < G.length; Y++)
|
|
2385
|
+
G[Y] ^= 106;
|
|
2386
|
+
this.oHash.update(G), (0, f.clean)(G);
|
|
2387
|
+
}
|
|
2388
|
+
update(m) {
|
|
2389
|
+
return (0, f.aexists)(this), this.iHash.update(m), this;
|
|
2390
|
+
}
|
|
2391
|
+
digestInto(m) {
|
|
2392
|
+
(0, f.aexists)(this), (0, f.abytes)(m, this.outputLen), this.finished = !0, this.iHash.digestInto(m), this.oHash.update(m), this.oHash.digestInto(m), this.destroy();
|
|
2393
|
+
}
|
|
2394
|
+
digest() {
|
|
2395
|
+
const m = new Uint8Array(this.oHash.outputLen);
|
|
2396
|
+
return this.digestInto(m), m;
|
|
2397
|
+
}
|
|
2398
|
+
_cloneInto(m) {
|
|
2399
|
+
m || (m = Object.create(Object.getPrototypeOf(this), {}));
|
|
2400
|
+
const { oHash: I, iHash: D, finished: F, destroyed: G, blockLen: Y, outputLen: L } = this;
|
|
2401
|
+
return m = m, m.finished = F, m.destroyed = G, m.blockLen = Y, m.outputLen = L, m.oHash = I._cloneInto(m.oHash), m.iHash = D._cloneInto(m.iHash), m;
|
|
2402
|
+
}
|
|
2403
|
+
clone() {
|
|
2404
|
+
return this._cloneInto();
|
|
2405
|
+
}
|
|
2406
|
+
destroy() {
|
|
2407
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
t.HMAC = y;
|
|
2411
|
+
const S = (H, m, I) => new y(H, m).update(I).digest();
|
|
2412
|
+
t.hmac = S, t.hmac.create = (H, m) => new y(H, m);
|
|
2413
|
+
})(se)), se;
|
|
2414
|
+
}
|
|
2415
|
+
var Le;
|
|
2416
|
+
function nn() {
|
|
2417
|
+
return Le || (Le = 1, (function(t) {
|
|
2418
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.DER = t.DERErr = void 0, t._splitEndoScalar = D, t._normFnElement = v, t.weierstrassN = T, t.SWUFpSqrtRatio = V, t.mapToCurveSimpleSWU = k, t.ecdh = E, t.ecdsa = U, t.weierstrassPoints = Z, t._legacyHelperEquat = Q, t.weierstrass = R;
|
|
2419
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2420
|
+
const f = /* @__PURE__ */ en(), y = /* @__PURE__ */ Ot(), S = /* @__PURE__ */ Ut(), H = /* @__PURE__ */ he(), m = /* @__PURE__ */ qt(), I = (o, p) => (o + (o >= 0 ? p : -p) / B) / p;
|
|
2421
|
+
function D(o, p, c) {
|
|
2422
|
+
const [[s, q], [K, e]] = p, n = I(e * o, c), r = I(-q * o, c);
|
|
2423
|
+
let i = o - n * s - r * K, a = -n * q - r * e;
|
|
2424
|
+
const b = i < L, A = a < L;
|
|
2425
|
+
b && (i = -i), A && (a = -a);
|
|
2426
|
+
const u = (0, S.bitMask)(Math.ceil((0, S.bitLen)(c) / 2)) + M;
|
|
2427
|
+
if (i < L || i >= u || a < L || a >= u)
|
|
2428
|
+
throw new Error("splitScalar (endomorphism): failed, k=" + o);
|
|
2429
|
+
return { k1neg: b, k1: i, k2neg: A, k2: a };
|
|
2430
|
+
}
|
|
2431
|
+
function F(o) {
|
|
2432
|
+
if (!["compact", "recovered", "der"].includes(o))
|
|
2433
|
+
throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
2434
|
+
return o;
|
|
2435
|
+
}
|
|
2436
|
+
function G(o, p) {
|
|
2437
|
+
const c = {};
|
|
2438
|
+
for (let s of Object.keys(p))
|
|
2439
|
+
c[s] = o[s] === void 0 ? p[s] : o[s];
|
|
2440
|
+
return (0, S._abool2)(c.lowS, "lowS"), (0, S._abool2)(c.prehash, "prehash"), c.format !== void 0 && F(c.format), c;
|
|
2441
|
+
}
|
|
2442
|
+
class Y extends Error {
|
|
2443
|
+
constructor(p = "") {
|
|
2444
|
+
super(p);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
t.DERErr = Y, t.DER = {
|
|
2448
|
+
// asn.1 DER encoding utils
|
|
2449
|
+
Err: Y,
|
|
2450
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
2451
|
+
_tlv: {
|
|
2452
|
+
encode: (o, p) => {
|
|
2453
|
+
const { Err: c } = t.DER;
|
|
2454
|
+
if (o < 0 || o > 256)
|
|
2455
|
+
throw new c("tlv.encode: wrong tag");
|
|
2456
|
+
if (p.length & 1)
|
|
2457
|
+
throw new c("tlv.encode: unpadded data");
|
|
2458
|
+
const s = p.length / 2, q = (0, S.numberToHexUnpadded)(s);
|
|
2459
|
+
if (q.length / 2 & 128)
|
|
2460
|
+
throw new c("tlv.encode: long form length too big");
|
|
2461
|
+
const K = s > 127 ? (0, S.numberToHexUnpadded)(q.length / 2 | 128) : "";
|
|
2462
|
+
return (0, S.numberToHexUnpadded)(o) + K + q + p;
|
|
2463
|
+
},
|
|
2464
|
+
// v - value, l - left bytes (unparsed)
|
|
2465
|
+
decode(o, p) {
|
|
2466
|
+
const { Err: c } = t.DER;
|
|
2467
|
+
let s = 0;
|
|
2468
|
+
if (o < 0 || o > 256)
|
|
2469
|
+
throw new c("tlv.encode: wrong tag");
|
|
2470
|
+
if (p.length < 2 || p[s++] !== o)
|
|
2471
|
+
throw new c("tlv.decode: wrong tlv");
|
|
2472
|
+
const q = p[s++], K = !!(q & 128);
|
|
2473
|
+
let e = 0;
|
|
2474
|
+
if (!K)
|
|
2475
|
+
e = q;
|
|
2476
|
+
else {
|
|
2477
|
+
const r = q & 127;
|
|
2478
|
+
if (!r)
|
|
2479
|
+
throw new c("tlv.decode(long): indefinite length not supported");
|
|
2480
|
+
if (r > 4)
|
|
2481
|
+
throw new c("tlv.decode(long): byte length is too big");
|
|
2482
|
+
const i = p.subarray(s, s + r);
|
|
2483
|
+
if (i.length !== r)
|
|
2484
|
+
throw new c("tlv.decode: length bytes not complete");
|
|
2485
|
+
if (i[0] === 0)
|
|
2486
|
+
throw new c("tlv.decode(long): zero leftmost byte");
|
|
2487
|
+
for (const a of i)
|
|
2488
|
+
e = e << 8 | a;
|
|
2489
|
+
if (s += r, e < 128)
|
|
2490
|
+
throw new c("tlv.decode(long): not minimal encoding");
|
|
2491
|
+
}
|
|
2492
|
+
const n = p.subarray(s, s + e);
|
|
2493
|
+
if (n.length !== e)
|
|
2494
|
+
throw new c("tlv.decode: wrong value length");
|
|
2495
|
+
return { v: n, l: p.subarray(s + e) };
|
|
2496
|
+
}
|
|
2497
|
+
},
|
|
2498
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
2499
|
+
// since we always use positive integers here. It must always be empty:
|
|
2500
|
+
// - add zero byte if exists
|
|
2501
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
2502
|
+
_int: {
|
|
2503
|
+
encode(o) {
|
|
2504
|
+
const { Err: p } = t.DER;
|
|
2505
|
+
if (o < L)
|
|
2506
|
+
throw new p("integer: negative integers are not allowed");
|
|
2507
|
+
let c = (0, S.numberToHexUnpadded)(o);
|
|
2508
|
+
if (Number.parseInt(c[0], 16) & 8 && (c = "00" + c), c.length & 1)
|
|
2509
|
+
throw new p("unexpected DER parsing assertion: unpadded hex");
|
|
2510
|
+
return c;
|
|
2511
|
+
},
|
|
2512
|
+
decode(o) {
|
|
2513
|
+
const { Err: p } = t.DER;
|
|
2514
|
+
if (o[0] & 128)
|
|
2515
|
+
throw new p("invalid signature integer: negative");
|
|
2516
|
+
if (o[0] === 0 && !(o[1] & 128))
|
|
2517
|
+
throw new p("invalid signature integer: unnecessary leading zero");
|
|
2518
|
+
return (0, S.bytesToNumberBE)(o);
|
|
2519
|
+
}
|
|
2520
|
+
},
|
|
2521
|
+
toSig(o) {
|
|
2522
|
+
const { Err: p, _int: c, _tlv: s } = t.DER, q = (0, S.ensureBytes)("signature", o), { v: K, l: e } = s.decode(48, q);
|
|
2523
|
+
if (e.length)
|
|
2524
|
+
throw new p("invalid signature: left bytes after parsing");
|
|
2525
|
+
const { v: n, l: r } = s.decode(2, K), { v: i, l: a } = s.decode(2, r);
|
|
2526
|
+
if (a.length)
|
|
2527
|
+
throw new p("invalid signature: left bytes after parsing");
|
|
2528
|
+
return { r: c.decode(n), s: c.decode(i) };
|
|
2529
|
+
},
|
|
2530
|
+
hexFromSig(o) {
|
|
2531
|
+
const { _tlv: p, _int: c } = t.DER, s = p.encode(2, c.encode(o.r)), q = p.encode(2, c.encode(o.s)), K = s + q;
|
|
2532
|
+
return p.encode(48, K);
|
|
2533
|
+
}
|
|
2534
|
+
};
|
|
2535
|
+
const L = BigInt(0), M = BigInt(1), B = BigInt(2), d = BigInt(3), w = BigInt(4);
|
|
2536
|
+
function v(o, p) {
|
|
2537
|
+
const { BYTES: c } = o;
|
|
2538
|
+
let s;
|
|
2539
|
+
if (typeof p == "bigint")
|
|
2540
|
+
s = p;
|
|
2541
|
+
else {
|
|
2542
|
+
let q = (0, S.ensureBytes)("private key", p);
|
|
2543
|
+
try {
|
|
2544
|
+
s = o.fromBytes(q);
|
|
2545
|
+
} catch {
|
|
2546
|
+
throw new Error(`invalid private key: expected ui8a of size ${c}, got ${typeof p}`);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
if (!o.isValidNot0(s))
|
|
2550
|
+
throw new Error("invalid private key: out of range [1..N-1]");
|
|
2551
|
+
return s;
|
|
2552
|
+
}
|
|
2553
|
+
function T(o, p = {}) {
|
|
2554
|
+
const c = (0, H._createCurveFields)("weierstrass", o, p), { Fp: s, Fn: q } = c;
|
|
2555
|
+
let K = c.CURVE;
|
|
2556
|
+
const { h: e, n } = K;
|
|
2557
|
+
(0, S._validateObject)(p, {}, {
|
|
2558
|
+
allowInfinityPoint: "boolean",
|
|
2559
|
+
clearCofactor: "function",
|
|
2560
|
+
isTorsionFree: "function",
|
|
2561
|
+
fromBytes: "function",
|
|
2562
|
+
toBytes: "function",
|
|
2563
|
+
endo: "object",
|
|
2564
|
+
wrapPrivateKey: "boolean"
|
|
2565
|
+
});
|
|
2566
|
+
const { endo: r } = p;
|
|
2567
|
+
if (r && (!s.is0(K.a) || typeof r.beta != "bigint" || !Array.isArray(r.basises)))
|
|
2568
|
+
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
2569
|
+
const i = O(s, q);
|
|
2570
|
+
function a() {
|
|
2571
|
+
if (!s.isOdd)
|
|
2572
|
+
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
2573
|
+
}
|
|
2574
|
+
function b(ct, et, tt) {
|
|
2575
|
+
const { x: J, y: it } = et.toAffine(), at = s.toBytes(J);
|
|
2576
|
+
if ((0, S._abool2)(tt, "isCompressed"), tt) {
|
|
2577
|
+
a();
|
|
2578
|
+
const dt = !s.isOdd(it);
|
|
2579
|
+
return (0, S.concatBytes)(P(dt), at);
|
|
2580
|
+
} else
|
|
2581
|
+
return (0, S.concatBytes)(Uint8Array.of(4), at, s.toBytes(it));
|
|
2582
|
+
}
|
|
2583
|
+
function A(ct) {
|
|
2584
|
+
(0, S._abytes2)(ct, void 0, "Point");
|
|
2585
|
+
const { publicKey: et, publicKeyUncompressed: tt } = i, J = ct.length, it = ct[0], at = ct.subarray(1);
|
|
2586
|
+
if (J === et && (it === 2 || it === 3)) {
|
|
2587
|
+
const dt = s.fromBytes(at);
|
|
2588
|
+
if (!s.isValid(dt))
|
|
2589
|
+
throw new Error("bad point: is not on curve, wrong x");
|
|
2590
|
+
const ft = g(dt);
|
|
2591
|
+
let lt;
|
|
2592
|
+
try {
|
|
2593
|
+
lt = s.sqrt(ft);
|
|
2594
|
+
} catch (Et) {
|
|
2595
|
+
const wt = Et instanceof Error ? ": " + Et.message : "";
|
|
2596
|
+
throw new Error("bad point: is not on curve, sqrt error" + wt);
|
|
2597
|
+
}
|
|
2598
|
+
a();
|
|
2599
|
+
const ht = s.isOdd(lt);
|
|
2600
|
+
return (it & 1) === 1 !== ht && (lt = s.neg(lt)), { x: dt, y: lt };
|
|
2601
|
+
} else if (J === tt && it === 4) {
|
|
2602
|
+
const dt = s.BYTES, ft = s.fromBytes(at.subarray(0, dt)), lt = s.fromBytes(at.subarray(dt, dt * 2));
|
|
2603
|
+
if (!_(ft, lt))
|
|
2604
|
+
throw new Error("bad point: is not on curve");
|
|
2605
|
+
return { x: ft, y: lt };
|
|
2606
|
+
} else
|
|
2607
|
+
throw new Error(`bad point: got length ${J}, expected compressed=${et} or uncompressed=${tt}`);
|
|
2608
|
+
}
|
|
2609
|
+
const u = p.toBytes || b, l = p.fromBytes || A;
|
|
2610
|
+
function g(ct) {
|
|
2611
|
+
const et = s.sqr(ct), tt = s.mul(et, ct);
|
|
2612
|
+
return s.add(s.add(tt, s.mul(ct, K.a)), K.b);
|
|
2613
|
+
}
|
|
2614
|
+
function _(ct, et) {
|
|
2615
|
+
const tt = s.sqr(et), J = g(ct);
|
|
2616
|
+
return s.eql(tt, J);
|
|
2617
|
+
}
|
|
2618
|
+
if (!_(K.Gx, K.Gy))
|
|
2619
|
+
throw new Error("bad curve params: generator point");
|
|
2620
|
+
const C = s.mul(s.pow(K.a, d), w), h = s.mul(s.sqr(K.b), BigInt(27));
|
|
2621
|
+
if (s.is0(s.add(C, h)))
|
|
2622
|
+
throw new Error("bad curve params: a or b");
|
|
2623
|
+
function x(ct, et, tt = !1) {
|
|
2624
|
+
if (!s.isValid(et) || tt && s.is0(et))
|
|
2625
|
+
throw new Error(`bad point coordinate ${ct}`);
|
|
2626
|
+
return et;
|
|
2627
|
+
}
|
|
2628
|
+
function W(ct) {
|
|
2629
|
+
if (!(ct instanceof rt))
|
|
2630
|
+
throw new Error("ProjectivePoint expected");
|
|
2631
|
+
}
|
|
2632
|
+
function $(ct) {
|
|
2633
|
+
if (!r || !r.basises)
|
|
2634
|
+
throw new Error("no endo");
|
|
2635
|
+
return D(ct, r.basises, q.ORDER);
|
|
2636
|
+
}
|
|
2637
|
+
const ot = (0, S.memoized)((ct, et) => {
|
|
2638
|
+
const { X: tt, Y: J, Z: it } = ct;
|
|
2639
|
+
if (s.eql(it, s.ONE))
|
|
2640
|
+
return { x: tt, y: J };
|
|
2641
|
+
const at = ct.is0();
|
|
2642
|
+
et == null && (et = at ? s.ONE : s.inv(it));
|
|
2643
|
+
const dt = s.mul(tt, et), ft = s.mul(J, et), lt = s.mul(it, et);
|
|
2644
|
+
if (at)
|
|
2645
|
+
return { x: s.ZERO, y: s.ZERO };
|
|
2646
|
+
if (!s.eql(lt, s.ONE))
|
|
2647
|
+
throw new Error("invZ was invalid");
|
|
2648
|
+
return { x: dt, y: ft };
|
|
2649
|
+
}), nt = (0, S.memoized)((ct) => {
|
|
2650
|
+
if (ct.is0()) {
|
|
2651
|
+
if (p.allowInfinityPoint && !s.is0(ct.Y))
|
|
2652
|
+
return;
|
|
2653
|
+
throw new Error("bad point: ZERO");
|
|
2654
|
+
}
|
|
2655
|
+
const { x: et, y: tt } = ct.toAffine();
|
|
2656
|
+
if (!s.isValid(et) || !s.isValid(tt))
|
|
2657
|
+
throw new Error("bad point: x or y not field elements");
|
|
2658
|
+
if (!_(et, tt))
|
|
2659
|
+
throw new Error("bad point: equation left != right");
|
|
2660
|
+
if (!ct.isTorsionFree())
|
|
2661
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
2662
|
+
return !0;
|
|
2663
|
+
});
|
|
2664
|
+
function st(ct, et, tt, J, it) {
|
|
2665
|
+
return tt = new rt(s.mul(tt.X, ct), tt.Y, tt.Z), et = (0, H.negateCt)(J, et), tt = (0, H.negateCt)(it, tt), et.add(tt);
|
|
2666
|
+
}
|
|
2667
|
+
class rt {
|
|
2668
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2669
|
+
constructor(et, tt, J) {
|
|
2670
|
+
this.X = x("x", et), this.Y = x("y", tt, !0), this.Z = x("z", J), Object.freeze(this);
|
|
2671
|
+
}
|
|
2672
|
+
static CURVE() {
|
|
2673
|
+
return K;
|
|
2674
|
+
}
|
|
2675
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2676
|
+
static fromAffine(et) {
|
|
2677
|
+
const { x: tt, y: J } = et || {};
|
|
2678
|
+
if (!et || !s.isValid(tt) || !s.isValid(J))
|
|
2679
|
+
throw new Error("invalid affine point");
|
|
2680
|
+
if (et instanceof rt)
|
|
2681
|
+
throw new Error("projective point not allowed");
|
|
2682
|
+
return s.is0(tt) && s.is0(J) ? rt.ZERO : new rt(tt, J, s.ONE);
|
|
2683
|
+
}
|
|
2684
|
+
static fromBytes(et) {
|
|
2685
|
+
const tt = rt.fromAffine(l((0, S._abytes2)(et, void 0, "point")));
|
|
2686
|
+
return tt.assertValidity(), tt;
|
|
2687
|
+
}
|
|
2688
|
+
static fromHex(et) {
|
|
2689
|
+
return rt.fromBytes((0, S.ensureBytes)("pointHex", et));
|
|
2690
|
+
}
|
|
2691
|
+
get x() {
|
|
2692
|
+
return this.toAffine().x;
|
|
2693
|
+
}
|
|
2694
|
+
get y() {
|
|
2695
|
+
return this.toAffine().y;
|
|
2696
|
+
}
|
|
2697
|
+
/**
|
|
2698
|
+
*
|
|
2699
|
+
* @param windowSize
|
|
2700
|
+
* @param isLazy true will defer table computation until the first multiplication
|
|
2701
|
+
* @returns
|
|
2702
|
+
*/
|
|
2703
|
+
precompute(et = 8, tt = !0) {
|
|
2704
|
+
return ut.createCache(this, et), tt || this.multiply(d), this;
|
|
2705
|
+
}
|
|
2706
|
+
// TODO: return `this`
|
|
2707
|
+
/** A point on curve is valid if it conforms to equation. */
|
|
2708
|
+
assertValidity() {
|
|
2709
|
+
nt(this);
|
|
2710
|
+
}
|
|
2711
|
+
hasEvenY() {
|
|
2712
|
+
const { y: et } = this.toAffine();
|
|
2713
|
+
if (!s.isOdd)
|
|
2714
|
+
throw new Error("Field doesn't support isOdd");
|
|
2715
|
+
return !s.isOdd(et);
|
|
2716
|
+
}
|
|
2717
|
+
/** Compare one point to another. */
|
|
2718
|
+
equals(et) {
|
|
2719
|
+
W(et);
|
|
2720
|
+
const { X: tt, Y: J, Z: it } = this, { X: at, Y: dt, Z: ft } = et, lt = s.eql(s.mul(tt, ft), s.mul(at, it)), ht = s.eql(s.mul(J, ft), s.mul(dt, it));
|
|
2721
|
+
return lt && ht;
|
|
2722
|
+
}
|
|
2723
|
+
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
2724
|
+
negate() {
|
|
2725
|
+
return new rt(this.X, s.neg(this.Y), this.Z);
|
|
2726
|
+
}
|
|
2727
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
2728
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2729
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2730
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2731
|
+
double() {
|
|
2732
|
+
const { a: et, b: tt } = K, J = s.mul(tt, d), { X: it, Y: at, Z: dt } = this;
|
|
2733
|
+
let ft = s.ZERO, lt = s.ZERO, ht = s.ZERO, bt = s.mul(it, it), Et = s.mul(at, at), wt = s.mul(dt, dt), gt = s.mul(it, at);
|
|
2734
|
+
return gt = s.add(gt, gt), ht = s.mul(it, dt), ht = s.add(ht, ht), ft = s.mul(et, ht), lt = s.mul(J, wt), lt = s.add(ft, lt), ft = s.sub(Et, lt), lt = s.add(Et, lt), lt = s.mul(ft, lt), ft = s.mul(gt, ft), ht = s.mul(J, ht), wt = s.mul(et, wt), gt = s.sub(bt, wt), gt = s.mul(et, gt), gt = s.add(gt, ht), ht = s.add(bt, bt), bt = s.add(ht, bt), bt = s.add(bt, wt), bt = s.mul(bt, gt), lt = s.add(lt, bt), wt = s.mul(at, dt), wt = s.add(wt, wt), bt = s.mul(wt, gt), ft = s.sub(ft, bt), ht = s.mul(wt, Et), ht = s.add(ht, ht), ht = s.add(ht, ht), new rt(ft, lt, ht);
|
|
2735
|
+
}
|
|
2736
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
2737
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2738
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2739
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2740
|
+
add(et) {
|
|
2741
|
+
W(et);
|
|
2742
|
+
const { X: tt, Y: J, Z: it } = this, { X: at, Y: dt, Z: ft } = et;
|
|
2743
|
+
let lt = s.ZERO, ht = s.ZERO, bt = s.ZERO;
|
|
2744
|
+
const Et = K.a, wt = s.mul(K.b, d);
|
|
2745
|
+
let gt = s.mul(tt, at), pt = s.mul(J, dt), Bt = s.mul(it, ft), It = s.add(tt, J), vt = s.add(at, dt);
|
|
2746
|
+
It = s.mul(It, vt), vt = s.add(gt, pt), It = s.sub(It, vt), vt = s.add(tt, it);
|
|
2747
|
+
let xt = s.add(at, ft);
|
|
2748
|
+
return vt = s.mul(vt, xt), xt = s.add(gt, Bt), vt = s.sub(vt, xt), xt = s.add(J, it), lt = s.add(dt, ft), xt = s.mul(xt, lt), lt = s.add(pt, Bt), xt = s.sub(xt, lt), bt = s.mul(Et, vt), lt = s.mul(wt, Bt), bt = s.add(lt, bt), lt = s.sub(pt, bt), bt = s.add(pt, bt), ht = s.mul(lt, bt), pt = s.add(gt, gt), pt = s.add(pt, gt), Bt = s.mul(Et, Bt), vt = s.mul(wt, vt), pt = s.add(pt, Bt), Bt = s.sub(gt, Bt), Bt = s.mul(Et, Bt), vt = s.add(vt, Bt), gt = s.mul(pt, vt), ht = s.add(ht, gt), gt = s.mul(xt, vt), lt = s.mul(It, lt), lt = s.sub(lt, gt), gt = s.mul(It, pt), bt = s.mul(xt, bt), bt = s.add(bt, gt), new rt(lt, ht, bt);
|
|
2749
|
+
}
|
|
2750
|
+
subtract(et) {
|
|
2751
|
+
return this.add(et.negate());
|
|
2752
|
+
}
|
|
2753
|
+
is0() {
|
|
2754
|
+
return this.equals(rt.ZERO);
|
|
2755
|
+
}
|
|
2756
|
+
/**
|
|
2757
|
+
* Constant time multiplication.
|
|
2758
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
2759
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
2760
|
+
* Uses precomputes when available.
|
|
2761
|
+
* Uses endomorphism for Koblitz curves.
|
|
2762
|
+
* @param scalar by which the point would be multiplied
|
|
2763
|
+
* @returns New point
|
|
2764
|
+
*/
|
|
2765
|
+
multiply(et) {
|
|
2766
|
+
const { endo: tt } = p;
|
|
2767
|
+
if (!q.isValidNot0(et))
|
|
2768
|
+
throw new Error("invalid scalar: out of range");
|
|
2769
|
+
let J, it;
|
|
2770
|
+
const at = (dt) => ut.cached(this, dt, (ft) => (0, H.normalizeZ)(rt, ft));
|
|
2771
|
+
if (tt) {
|
|
2772
|
+
const { k1neg: dt, k1: ft, k2neg: lt, k2: ht } = $(et), { p: bt, f: Et } = at(ft), { p: wt, f: gt } = at(ht);
|
|
2773
|
+
it = Et.add(gt), J = st(tt.beta, bt, wt, dt, lt);
|
|
2774
|
+
} else {
|
|
2775
|
+
const { p: dt, f: ft } = at(et);
|
|
2776
|
+
J = dt, it = ft;
|
|
2777
|
+
}
|
|
2778
|
+
return (0, H.normalizeZ)(rt, [J, it])[0];
|
|
2779
|
+
}
|
|
2780
|
+
/**
|
|
2781
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
2782
|
+
* It's faster, but should only be used when you don't care about
|
|
2783
|
+
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
2784
|
+
*/
|
|
2785
|
+
multiplyUnsafe(et) {
|
|
2786
|
+
const { endo: tt } = p, J = this;
|
|
2787
|
+
if (!q.isValid(et))
|
|
2788
|
+
throw new Error("invalid scalar: out of range");
|
|
2789
|
+
if (et === L || J.is0())
|
|
2790
|
+
return rt.ZERO;
|
|
2791
|
+
if (et === M)
|
|
2792
|
+
return J;
|
|
2793
|
+
if (ut.hasCache(this))
|
|
2794
|
+
return this.multiply(et);
|
|
2795
|
+
if (tt) {
|
|
2796
|
+
const { k1neg: it, k1: at, k2neg: dt, k2: ft } = $(et), { p1: lt, p2: ht } = (0, H.mulEndoUnsafe)(rt, J, at, ft);
|
|
2797
|
+
return st(tt.beta, lt, ht, it, dt);
|
|
2798
|
+
} else
|
|
2799
|
+
return ut.unsafe(J, et);
|
|
2800
|
+
}
|
|
2801
|
+
multiplyAndAddUnsafe(et, tt, J) {
|
|
2802
|
+
const it = this.multiplyUnsafe(tt).add(et.multiplyUnsafe(J));
|
|
2803
|
+
return it.is0() ? void 0 : it;
|
|
2804
|
+
}
|
|
2805
|
+
/**
|
|
2806
|
+
* Converts Projective point to affine (x, y) coordinates.
|
|
2807
|
+
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
2808
|
+
*/
|
|
2809
|
+
toAffine(et) {
|
|
2810
|
+
return ot(this, et);
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
2814
|
+
* Always torsion-free for cofactor=1 curves.
|
|
2815
|
+
*/
|
|
2816
|
+
isTorsionFree() {
|
|
2817
|
+
const { isTorsionFree: et } = p;
|
|
2818
|
+
return e === M ? !0 : et ? et(rt, this) : ut.unsafe(this, n).is0();
|
|
2819
|
+
}
|
|
2820
|
+
clearCofactor() {
|
|
2821
|
+
const { clearCofactor: et } = p;
|
|
2822
|
+
return e === M ? this : et ? et(rt, this) : this.multiplyUnsafe(e);
|
|
2823
|
+
}
|
|
2824
|
+
isSmallOrder() {
|
|
2825
|
+
return this.multiplyUnsafe(e).is0();
|
|
2826
|
+
}
|
|
2827
|
+
toBytes(et = !0) {
|
|
2828
|
+
return (0, S._abool2)(et, "isCompressed"), this.assertValidity(), u(rt, this, et);
|
|
2829
|
+
}
|
|
2830
|
+
toHex(et = !0) {
|
|
2831
|
+
return (0, S.bytesToHex)(this.toBytes(et));
|
|
2832
|
+
}
|
|
2833
|
+
toString() {
|
|
2834
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
2835
|
+
}
|
|
2836
|
+
// TODO: remove
|
|
2837
|
+
get px() {
|
|
2838
|
+
return this.X;
|
|
2839
|
+
}
|
|
2840
|
+
get py() {
|
|
2841
|
+
return this.X;
|
|
2842
|
+
}
|
|
2843
|
+
get pz() {
|
|
2844
|
+
return this.Z;
|
|
2845
|
+
}
|
|
2846
|
+
toRawBytes(et = !0) {
|
|
2847
|
+
return this.toBytes(et);
|
|
2848
|
+
}
|
|
2849
|
+
_setWindowSize(et) {
|
|
2850
|
+
this.precompute(et);
|
|
2851
|
+
}
|
|
2852
|
+
static normalizeZ(et) {
|
|
2853
|
+
return (0, H.normalizeZ)(rt, et);
|
|
2854
|
+
}
|
|
2855
|
+
static msm(et, tt) {
|
|
2856
|
+
return (0, H.pippenger)(rt, q, et, tt);
|
|
2857
|
+
}
|
|
2858
|
+
static fromPrivateKey(et) {
|
|
2859
|
+
return rt.BASE.multiply(v(q, et));
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
rt.BASE = new rt(K.Gx, K.Gy, s.ONE), rt.ZERO = new rt(s.ZERO, s.ONE, s.ZERO), rt.Fp = s, rt.Fn = q;
|
|
2863
|
+
const yt = q.BITS, ut = new H.wNAF(rt, p.endo ? Math.ceil(yt / 2) : yt);
|
|
2864
|
+
return rt.BASE.precompute(8), rt;
|
|
2865
|
+
}
|
|
2866
|
+
function P(o) {
|
|
2867
|
+
return Uint8Array.of(o ? 2 : 3);
|
|
2868
|
+
}
|
|
2869
|
+
function V(o, p) {
|
|
2870
|
+
const c = o.ORDER;
|
|
2871
|
+
let s = L;
|
|
2872
|
+
for (let l = c - M; l % B === L; l /= B)
|
|
2873
|
+
s += M;
|
|
2874
|
+
const q = s, K = B << q - M - M, e = K * B, n = (c - M) / e, r = (n - M) / B, i = e - M, a = K, b = o.pow(p, n), A = o.pow(p, (n + M) / B);
|
|
2875
|
+
let u = (l, g) => {
|
|
2876
|
+
let _ = b, C = o.pow(g, i), h = o.sqr(C);
|
|
2877
|
+
h = o.mul(h, g);
|
|
2878
|
+
let x = o.mul(l, h);
|
|
2879
|
+
x = o.pow(x, r), x = o.mul(x, C), C = o.mul(x, g), h = o.mul(x, l);
|
|
2880
|
+
let W = o.mul(h, C);
|
|
2881
|
+
x = o.pow(W, a);
|
|
2882
|
+
let $ = o.eql(x, o.ONE);
|
|
2883
|
+
C = o.mul(h, A), x = o.mul(W, _), h = o.cmov(C, h, $), W = o.cmov(x, W, $);
|
|
2884
|
+
for (let ot = q; ot > M; ot--) {
|
|
2885
|
+
let nt = ot - B;
|
|
2886
|
+
nt = B << nt - M;
|
|
2887
|
+
let st = o.pow(W, nt);
|
|
2888
|
+
const rt = o.eql(st, o.ONE);
|
|
2889
|
+
C = o.mul(h, _), _ = o.mul(_, _), st = o.mul(W, _), h = o.cmov(C, h, rt), W = o.cmov(st, W, rt);
|
|
2890
|
+
}
|
|
2891
|
+
return { isValid: $, value: h };
|
|
2892
|
+
};
|
|
2893
|
+
if (o.ORDER % w === d) {
|
|
2894
|
+
const l = (o.ORDER - d) / w, g = o.sqrt(o.neg(p));
|
|
2895
|
+
u = (_, C) => {
|
|
2896
|
+
let h = o.sqr(C);
|
|
2897
|
+
const x = o.mul(_, C);
|
|
2898
|
+
h = o.mul(h, x);
|
|
2899
|
+
let W = o.pow(h, l);
|
|
2900
|
+
W = o.mul(W, x);
|
|
2901
|
+
const $ = o.mul(W, g), ot = o.mul(o.sqr(W), C), nt = o.eql(ot, _);
|
|
2902
|
+
let st = o.cmov($, W, nt);
|
|
2903
|
+
return { isValid: nt, value: st };
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2906
|
+
return u;
|
|
2907
|
+
}
|
|
2908
|
+
function k(o, p) {
|
|
2909
|
+
(0, m.validateField)(o);
|
|
2910
|
+
const { A: c, B: s, Z: q } = p;
|
|
2911
|
+
if (!o.isValid(c) || !o.isValid(s) || !o.isValid(q))
|
|
2912
|
+
throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
2913
|
+
const K = V(o, q);
|
|
2914
|
+
if (!o.isOdd)
|
|
2915
|
+
throw new Error("Field does not have .isOdd()");
|
|
2916
|
+
return (e) => {
|
|
2917
|
+
let n, r, i, a, b, A, u, l;
|
|
2918
|
+
n = o.sqr(e), n = o.mul(n, q), r = o.sqr(n), r = o.add(r, n), i = o.add(r, o.ONE), i = o.mul(i, s), a = o.cmov(q, o.neg(r), !o.eql(r, o.ZERO)), a = o.mul(a, c), r = o.sqr(i), A = o.sqr(a), b = o.mul(A, c), r = o.add(r, b), r = o.mul(r, i), A = o.mul(A, a), b = o.mul(A, s), r = o.add(r, b), u = o.mul(n, i);
|
|
2919
|
+
const { isValid: g, value: _ } = K(r, A);
|
|
2920
|
+
l = o.mul(n, e), l = o.mul(l, _), u = o.cmov(u, i, g), l = o.cmov(l, _, g);
|
|
2921
|
+
const C = o.isOdd(e) === o.isOdd(l);
|
|
2922
|
+
l = o.cmov(o.neg(l), l, C);
|
|
2923
|
+
const h = (0, m.FpInvertBatch)(o, [a], !0)[0];
|
|
2924
|
+
return u = o.mul(u, h), { x: u, y: l };
|
|
2925
|
+
};
|
|
2926
|
+
}
|
|
2927
|
+
function O(o, p) {
|
|
2928
|
+
return {
|
|
2929
|
+
secretKey: p.BYTES,
|
|
2930
|
+
publicKey: 1 + o.BYTES,
|
|
2931
|
+
publicKeyUncompressed: 1 + 2 * o.BYTES,
|
|
2932
|
+
publicKeyHasPrefix: !0,
|
|
2933
|
+
signature: 2 * p.BYTES
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2936
|
+
function E(o, p = {}) {
|
|
2937
|
+
const { Fn: c } = o, s = p.randomBytes || S.randomBytes, q = Object.assign(O(o.Fp, c), { seed: (0, m.getMinHashLength)(c.ORDER) });
|
|
2938
|
+
function K(u) {
|
|
2939
|
+
try {
|
|
2940
|
+
return !!v(c, u);
|
|
2941
|
+
} catch {
|
|
2942
|
+
return !1;
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
function e(u, l) {
|
|
2946
|
+
const { publicKey: g, publicKeyUncompressed: _ } = q;
|
|
2947
|
+
try {
|
|
2948
|
+
const C = u.length;
|
|
2949
|
+
return l === !0 && C !== g || l === !1 && C !== _ ? !1 : !!o.fromBytes(u);
|
|
2950
|
+
} catch {
|
|
2951
|
+
return !1;
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
function n(u = s(q.seed)) {
|
|
2955
|
+
return (0, m.mapHashToField)((0, S._abytes2)(u, q.seed, "seed"), c.ORDER);
|
|
2956
|
+
}
|
|
2957
|
+
function r(u, l = !0) {
|
|
2958
|
+
return o.BASE.multiply(v(c, u)).toBytes(l);
|
|
2959
|
+
}
|
|
2960
|
+
function i(u) {
|
|
2961
|
+
const l = n(u);
|
|
2962
|
+
return { secretKey: l, publicKey: r(l) };
|
|
2963
|
+
}
|
|
2964
|
+
function a(u) {
|
|
2965
|
+
if (typeof u == "bigint")
|
|
2966
|
+
return !1;
|
|
2967
|
+
if (u instanceof o)
|
|
2968
|
+
return !0;
|
|
2969
|
+
const { secretKey: l, publicKey: g, publicKeyUncompressed: _ } = q;
|
|
2970
|
+
if (c.allowedLengths || l === g)
|
|
2971
|
+
return;
|
|
2972
|
+
const C = (0, S.ensureBytes)("key", u).length;
|
|
2973
|
+
return C === g || C === _;
|
|
2974
|
+
}
|
|
2975
|
+
function b(u, l, g = !0) {
|
|
2976
|
+
if (a(u) === !0)
|
|
2977
|
+
throw new Error("first arg must be private key");
|
|
2978
|
+
if (a(l) === !1)
|
|
2979
|
+
throw new Error("second arg must be public key");
|
|
2980
|
+
const _ = v(c, u);
|
|
2981
|
+
return o.fromHex(l).multiply(_).toBytes(g);
|
|
2982
|
+
}
|
|
2983
|
+
return Object.freeze({ getPublicKey: r, getSharedSecret: b, keygen: i, Point: o, utils: {
|
|
2984
|
+
isValidSecretKey: K,
|
|
2985
|
+
isValidPublicKey: e,
|
|
2986
|
+
randomSecretKey: n,
|
|
2987
|
+
// TODO: remove
|
|
2988
|
+
isValidPrivateKey: K,
|
|
2989
|
+
randomPrivateKey: n,
|
|
2990
|
+
normPrivateKeyToScalar: (u) => v(c, u),
|
|
2991
|
+
precompute(u = 8, l = o.BASE) {
|
|
2992
|
+
return l.precompute(u, !1);
|
|
2993
|
+
}
|
|
2994
|
+
}, lengths: q });
|
|
2995
|
+
}
|
|
2996
|
+
function U(o, p, c = {}) {
|
|
2997
|
+
(0, y.ahash)(p), (0, S._validateObject)(c, {}, {
|
|
2998
|
+
hmac: "function",
|
|
2999
|
+
lowS: "boolean",
|
|
3000
|
+
randomBytes: "function",
|
|
3001
|
+
bits2int: "function",
|
|
3002
|
+
bits2int_modN: "function"
|
|
3003
|
+
});
|
|
3004
|
+
const s = c.randomBytes || S.randomBytes, q = c.hmac || ((tt, ...J) => (0, f.hmac)(p, tt, (0, S.concatBytes)(...J))), { Fp: K, Fn: e } = o, { ORDER: n, BITS: r } = e, { keygen: i, getPublicKey: a, getSharedSecret: b, utils: A, lengths: u } = E(o, c), l = {
|
|
3005
|
+
prehash: !1,
|
|
3006
|
+
lowS: typeof c.lowS == "boolean" ? c.lowS : !1,
|
|
3007
|
+
format: void 0,
|
|
3008
|
+
//'compact' as ECDSASigFormat,
|
|
3009
|
+
extraEntropy: !1
|
|
3010
|
+
}, g = "compact";
|
|
3011
|
+
function _(tt) {
|
|
3012
|
+
const J = n >> M;
|
|
3013
|
+
return tt > J;
|
|
3014
|
+
}
|
|
3015
|
+
function C(tt, J) {
|
|
3016
|
+
if (!e.isValidNot0(J))
|
|
3017
|
+
throw new Error(`invalid signature ${tt}: out of range 1..Point.Fn.ORDER`);
|
|
3018
|
+
return J;
|
|
3019
|
+
}
|
|
3020
|
+
function h(tt, J) {
|
|
3021
|
+
F(J);
|
|
3022
|
+
const it = u.signature, at = J === "compact" ? it : J === "recovered" ? it + 1 : void 0;
|
|
3023
|
+
return (0, S._abytes2)(tt, at, `${J} signature`);
|
|
3024
|
+
}
|
|
3025
|
+
class x {
|
|
3026
|
+
constructor(J, it, at) {
|
|
3027
|
+
this.r = C("r", J), this.s = C("s", it), at != null && (this.recovery = at), Object.freeze(this);
|
|
3028
|
+
}
|
|
3029
|
+
static fromBytes(J, it = g) {
|
|
3030
|
+
h(J, it);
|
|
3031
|
+
let at;
|
|
3032
|
+
if (it === "der") {
|
|
3033
|
+
const { r: ht, s: bt } = t.DER.toSig((0, S._abytes2)(J));
|
|
3034
|
+
return new x(ht, bt);
|
|
3035
|
+
}
|
|
3036
|
+
it === "recovered" && (at = J[0], it = "compact", J = J.subarray(1));
|
|
3037
|
+
const dt = e.BYTES, ft = J.subarray(0, dt), lt = J.subarray(dt, dt * 2);
|
|
3038
|
+
return new x(e.fromBytes(ft), e.fromBytes(lt), at);
|
|
3039
|
+
}
|
|
3040
|
+
static fromHex(J, it) {
|
|
3041
|
+
return this.fromBytes((0, S.hexToBytes)(J), it);
|
|
3042
|
+
}
|
|
3043
|
+
addRecoveryBit(J) {
|
|
3044
|
+
return new x(this.r, this.s, J);
|
|
3045
|
+
}
|
|
3046
|
+
recoverPublicKey(J) {
|
|
3047
|
+
const it = K.ORDER, { r: at, s: dt, recovery: ft } = this;
|
|
3048
|
+
if (ft == null || ![0, 1, 2, 3].includes(ft))
|
|
3049
|
+
throw new Error("recovery id invalid");
|
|
3050
|
+
if (n * B < it && ft > 1)
|
|
3051
|
+
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
3052
|
+
const ht = ft === 2 || ft === 3 ? at + n : at;
|
|
3053
|
+
if (!K.isValid(ht))
|
|
3054
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
3055
|
+
const bt = K.toBytes(ht), Et = o.fromBytes((0, S.concatBytes)(P((ft & 1) === 0), bt)), wt = e.inv(ht), gt = $((0, S.ensureBytes)("msgHash", J)), pt = e.create(-gt * wt), Bt = e.create(dt * wt), It = o.BASE.multiplyUnsafe(pt).add(Et.multiplyUnsafe(Bt));
|
|
3056
|
+
if (It.is0())
|
|
3057
|
+
throw new Error("point at infinify");
|
|
3058
|
+
return It.assertValidity(), It;
|
|
3059
|
+
}
|
|
3060
|
+
// Signatures should be low-s, to prevent malleability.
|
|
3061
|
+
hasHighS() {
|
|
3062
|
+
return _(this.s);
|
|
3063
|
+
}
|
|
3064
|
+
toBytes(J = g) {
|
|
3065
|
+
if (F(J), J === "der")
|
|
3066
|
+
return (0, S.hexToBytes)(t.DER.hexFromSig(this));
|
|
3067
|
+
const it = e.toBytes(this.r), at = e.toBytes(this.s);
|
|
3068
|
+
if (J === "recovered") {
|
|
3069
|
+
if (this.recovery == null)
|
|
3070
|
+
throw new Error("recovery bit must be present");
|
|
3071
|
+
return (0, S.concatBytes)(Uint8Array.of(this.recovery), it, at);
|
|
3072
|
+
}
|
|
3073
|
+
return (0, S.concatBytes)(it, at);
|
|
3074
|
+
}
|
|
3075
|
+
toHex(J) {
|
|
3076
|
+
return (0, S.bytesToHex)(this.toBytes(J));
|
|
3077
|
+
}
|
|
3078
|
+
// TODO: remove
|
|
3079
|
+
assertValidity() {
|
|
3080
|
+
}
|
|
3081
|
+
static fromCompact(J) {
|
|
3082
|
+
return x.fromBytes((0, S.ensureBytes)("sig", J), "compact");
|
|
3083
|
+
}
|
|
3084
|
+
static fromDER(J) {
|
|
3085
|
+
return x.fromBytes((0, S.ensureBytes)("sig", J), "der");
|
|
3086
|
+
}
|
|
3087
|
+
normalizeS() {
|
|
3088
|
+
return this.hasHighS() ? new x(this.r, e.neg(this.s), this.recovery) : this;
|
|
3089
|
+
}
|
|
3090
|
+
toDERRawBytes() {
|
|
3091
|
+
return this.toBytes("der");
|
|
3092
|
+
}
|
|
3093
|
+
toDERHex() {
|
|
3094
|
+
return (0, S.bytesToHex)(this.toBytes("der"));
|
|
3095
|
+
}
|
|
3096
|
+
toCompactRawBytes() {
|
|
3097
|
+
return this.toBytes("compact");
|
|
3098
|
+
}
|
|
3099
|
+
toCompactHex() {
|
|
3100
|
+
return (0, S.bytesToHex)(this.toBytes("compact"));
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
const W = c.bits2int || function(J) {
|
|
3104
|
+
if (J.length > 8192)
|
|
3105
|
+
throw new Error("input is too large");
|
|
3106
|
+
const it = (0, S.bytesToNumberBE)(J), at = J.length * 8 - r;
|
|
3107
|
+
return at > 0 ? it >> BigInt(at) : it;
|
|
3108
|
+
}, $ = c.bits2int_modN || function(J) {
|
|
3109
|
+
return e.create(W(J));
|
|
3110
|
+
}, ot = (0, S.bitMask)(r);
|
|
3111
|
+
function nt(tt) {
|
|
3112
|
+
return (0, S.aInRange)("num < 2^" + r, tt, L, ot), e.toBytes(tt);
|
|
3113
|
+
}
|
|
3114
|
+
function st(tt, J) {
|
|
3115
|
+
return (0, S._abytes2)(tt, void 0, "message"), J ? (0, S._abytes2)(p(tt), void 0, "prehashed message") : tt;
|
|
3116
|
+
}
|
|
3117
|
+
function rt(tt, J, it) {
|
|
3118
|
+
if (["recovered", "canonical"].some((pt) => pt in it))
|
|
3119
|
+
throw new Error("sign() legacy options not supported");
|
|
3120
|
+
const { lowS: at, prehash: dt, extraEntropy: ft } = G(it, l);
|
|
3121
|
+
tt = st(tt, dt);
|
|
3122
|
+
const lt = $(tt), ht = v(e, J), bt = [nt(ht), nt(lt)];
|
|
3123
|
+
if (ft != null && ft !== !1) {
|
|
3124
|
+
const pt = ft === !0 ? s(u.secretKey) : ft;
|
|
3125
|
+
bt.push((0, S.ensureBytes)("extraEntropy", pt));
|
|
3126
|
+
}
|
|
3127
|
+
const Et = (0, S.concatBytes)(...bt), wt = lt;
|
|
3128
|
+
function gt(pt) {
|
|
3129
|
+
const Bt = W(pt);
|
|
3130
|
+
if (!e.isValidNot0(Bt))
|
|
3131
|
+
return;
|
|
3132
|
+
const It = e.inv(Bt), vt = o.BASE.multiply(Bt).toAffine(), xt = e.create(vt.x);
|
|
3133
|
+
if (xt === L)
|
|
3134
|
+
return;
|
|
3135
|
+
const kt = e.create(It * e.create(wt + xt * ht));
|
|
3136
|
+
if (kt === L)
|
|
3137
|
+
return;
|
|
3138
|
+
let be = (vt.x === xt ? 0 : 2) | Number(vt.y & M), ge = kt;
|
|
3139
|
+
return at && _(kt) && (ge = e.neg(kt), be ^= 1), new x(xt, ge, be);
|
|
3140
|
+
}
|
|
3141
|
+
return { seed: Et, k2sig: gt };
|
|
3142
|
+
}
|
|
3143
|
+
function yt(tt, J, it = {}) {
|
|
3144
|
+
tt = (0, S.ensureBytes)("message", tt);
|
|
3145
|
+
const { seed: at, k2sig: dt } = rt(tt, J, it);
|
|
3146
|
+
return (0, S.createHmacDrbg)(p.outputLen, e.BYTES, q)(at, dt);
|
|
3147
|
+
}
|
|
3148
|
+
function ut(tt) {
|
|
3149
|
+
let J;
|
|
3150
|
+
const it = typeof tt == "string" || (0, S.isBytes)(tt), at = !it && tt !== null && typeof tt == "object" && typeof tt.r == "bigint" && typeof tt.s == "bigint";
|
|
3151
|
+
if (!it && !at)
|
|
3152
|
+
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
3153
|
+
if (at)
|
|
3154
|
+
J = new x(tt.r, tt.s);
|
|
3155
|
+
else if (it) {
|
|
3156
|
+
try {
|
|
3157
|
+
J = x.fromBytes((0, S.ensureBytes)("sig", tt), "der");
|
|
3158
|
+
} catch (dt) {
|
|
3159
|
+
if (!(dt instanceof t.DER.Err))
|
|
3160
|
+
throw dt;
|
|
3161
|
+
}
|
|
3162
|
+
if (!J)
|
|
3163
|
+
try {
|
|
3164
|
+
J = x.fromBytes((0, S.ensureBytes)("sig", tt), "compact");
|
|
3165
|
+
} catch {
|
|
3166
|
+
return !1;
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
return J || !1;
|
|
3170
|
+
}
|
|
3171
|
+
function ct(tt, J, it, at = {}) {
|
|
3172
|
+
const { lowS: dt, prehash: ft, format: lt } = G(at, l);
|
|
3173
|
+
if (it = (0, S.ensureBytes)("publicKey", it), J = st((0, S.ensureBytes)("message", J), ft), "strict" in at)
|
|
3174
|
+
throw new Error("options.strict was renamed to lowS");
|
|
3175
|
+
const ht = lt === void 0 ? ut(tt) : x.fromBytes((0, S.ensureBytes)("sig", tt), lt);
|
|
3176
|
+
if (ht === !1)
|
|
3177
|
+
return !1;
|
|
3178
|
+
try {
|
|
3179
|
+
const bt = o.fromBytes(it);
|
|
3180
|
+
if (dt && ht.hasHighS())
|
|
3181
|
+
return !1;
|
|
3182
|
+
const { r: Et, s: wt } = ht, gt = $(J), pt = e.inv(wt), Bt = e.create(gt * pt), It = e.create(Et * pt), vt = o.BASE.multiplyUnsafe(Bt).add(bt.multiplyUnsafe(It));
|
|
3183
|
+
return vt.is0() ? !1 : e.create(vt.x) === Et;
|
|
3184
|
+
} catch {
|
|
3185
|
+
return !1;
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
function et(tt, J, it = {}) {
|
|
3189
|
+
const { prehash: at } = G(it, l);
|
|
3190
|
+
return J = st(J, at), x.fromBytes(tt, "recovered").recoverPublicKey(J).toBytes();
|
|
3191
|
+
}
|
|
3192
|
+
return Object.freeze({
|
|
3193
|
+
keygen: i,
|
|
3194
|
+
getPublicKey: a,
|
|
3195
|
+
getSharedSecret: b,
|
|
3196
|
+
utils: A,
|
|
3197
|
+
lengths: u,
|
|
3198
|
+
Point: o,
|
|
3199
|
+
sign: yt,
|
|
3200
|
+
verify: ct,
|
|
3201
|
+
recoverPublicKey: et,
|
|
3202
|
+
Signature: x,
|
|
3203
|
+
hash: p
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3206
|
+
function Z(o) {
|
|
3207
|
+
const { CURVE: p, curveOpts: c } = j(o), s = T(p, c);
|
|
3208
|
+
return X(o, s);
|
|
3209
|
+
}
|
|
3210
|
+
function j(o) {
|
|
3211
|
+
const p = {
|
|
3212
|
+
a: o.a,
|
|
3213
|
+
b: o.b,
|
|
3214
|
+
p: o.Fp.ORDER,
|
|
3215
|
+
n: o.n,
|
|
3216
|
+
h: o.h,
|
|
3217
|
+
Gx: o.Gx,
|
|
3218
|
+
Gy: o.Gy
|
|
3219
|
+
}, c = o.Fp;
|
|
3220
|
+
let s = o.allowedPrivateKeyLengths ? Array.from(new Set(o.allowedPrivateKeyLengths.map((e) => Math.ceil(e / 2)))) : void 0;
|
|
3221
|
+
const q = (0, m.Field)(p.n, {
|
|
3222
|
+
BITS: o.nBitLength,
|
|
3223
|
+
allowedLengths: s,
|
|
3224
|
+
modFromBytes: o.wrapPrivateKey
|
|
3225
|
+
}), K = {
|
|
3226
|
+
Fp: c,
|
|
3227
|
+
Fn: q,
|
|
3228
|
+
allowInfinityPoint: o.allowInfinityPoint,
|
|
3229
|
+
endo: o.endo,
|
|
3230
|
+
isTorsionFree: o.isTorsionFree,
|
|
3231
|
+
clearCofactor: o.clearCofactor,
|
|
3232
|
+
fromBytes: o.fromBytes,
|
|
3233
|
+
toBytes: o.toBytes
|
|
3234
|
+
};
|
|
3235
|
+
return { CURVE: p, curveOpts: K };
|
|
3236
|
+
}
|
|
3237
|
+
function z(o) {
|
|
3238
|
+
const { CURVE: p, curveOpts: c } = j(o), s = {
|
|
3239
|
+
hmac: o.hmac,
|
|
3240
|
+
randomBytes: o.randomBytes,
|
|
3241
|
+
lowS: o.lowS,
|
|
3242
|
+
bits2int: o.bits2int,
|
|
3243
|
+
bits2int_modN: o.bits2int_modN
|
|
3244
|
+
};
|
|
3245
|
+
return { CURVE: p, curveOpts: c, hash: o.hash, ecdsaOpts: s };
|
|
3246
|
+
}
|
|
3247
|
+
function Q(o, p, c) {
|
|
3248
|
+
function s(q) {
|
|
3249
|
+
const K = o.sqr(q), e = o.mul(K, q);
|
|
3250
|
+
return o.add(o.add(e, o.mul(q, p)), c);
|
|
3251
|
+
}
|
|
3252
|
+
return s;
|
|
3253
|
+
}
|
|
3254
|
+
function X(o, p) {
|
|
3255
|
+
const { Fp: c, Fn: s } = p;
|
|
3256
|
+
function q(e) {
|
|
3257
|
+
return (0, S.inRange)(e, M, s.ORDER);
|
|
3258
|
+
}
|
|
3259
|
+
const K = Q(c, o.a, o.b);
|
|
3260
|
+
return Object.assign({}, {
|
|
3261
|
+
CURVE: o,
|
|
3262
|
+
Point: p,
|
|
3263
|
+
ProjectivePoint: p,
|
|
3264
|
+
normPrivateKeyToScalar: (e) => v(s, e),
|
|
3265
|
+
weierstrassEquation: K,
|
|
3266
|
+
isWithinCurveOrder: q
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
3269
|
+
function N(o, p) {
|
|
3270
|
+
const c = p.Point;
|
|
3271
|
+
return Object.assign({}, p, {
|
|
3272
|
+
ProjectivePoint: c,
|
|
3273
|
+
CURVE: Object.assign({}, o, (0, m.nLength)(c.Fn.ORDER, c.Fn.BITS))
|
|
3274
|
+
});
|
|
3275
|
+
}
|
|
3276
|
+
function R(o) {
|
|
3277
|
+
const { CURVE: p, curveOpts: c, hash: s, ecdsaOpts: q } = z(o), K = T(p, c), e = U(K, s, q);
|
|
3278
|
+
return N(o, e);
|
|
3279
|
+
}
|
|
3280
|
+
})(oe)), oe;
|
|
3281
|
+
}
|
|
3282
|
+
var Ue;
|
|
3283
|
+
function bn() {
|
|
3284
|
+
if (Ue) return Dt;
|
|
3285
|
+
Ue = 1, Object.defineProperty(Dt, "__esModule", { value: !0 }), Dt.getHash = f, Dt.createCurve = y;
|
|
3286
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3287
|
+
const t = /* @__PURE__ */ nn();
|
|
3288
|
+
function f(S) {
|
|
3289
|
+
return { hash: S };
|
|
3290
|
+
}
|
|
3291
|
+
function y(S, H) {
|
|
3292
|
+
const m = (I) => (0, t.weierstrass)({ ...S, hash: I });
|
|
3293
|
+
return { ...m(H), create: m };
|
|
3294
|
+
}
|
|
3295
|
+
return Dt;
|
|
3296
|
+
}
|
|
3297
|
+
var Re;
|
|
3298
|
+
function gn() {
|
|
3299
|
+
return Re || (Re = 1, (function(t) {
|
|
3300
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.encodeToCurve = t.hashToCurve = t.secp256k1_hasher = t.schnorr = t.secp256k1 = void 0;
|
|
3301
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3302
|
+
const f = /* @__PURE__ */ de(), y = /* @__PURE__ */ Ot(), S = /* @__PURE__ */ bn(), H = /* @__PURE__ */ tn(), m = /* @__PURE__ */ qt(), I = /* @__PURE__ */ nn(), D = /* @__PURE__ */ Ut(), F = {
|
|
3303
|
+
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
3304
|
+
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
3305
|
+
h: BigInt(1),
|
|
3306
|
+
a: BigInt(0),
|
|
3307
|
+
b: BigInt(7),
|
|
3308
|
+
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
3309
|
+
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
3310
|
+
}, G = {
|
|
3311
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
3312
|
+
basises: [
|
|
3313
|
+
[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
|
|
3314
|
+
[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
|
|
3315
|
+
]
|
|
3316
|
+
}, Y = /* @__PURE__ */ BigInt(0), L = /* @__PURE__ */ BigInt(1), M = /* @__PURE__ */ BigInt(2);
|
|
3317
|
+
function B(N) {
|
|
3318
|
+
const R = F.p, o = BigInt(3), p = BigInt(6), c = BigInt(11), s = BigInt(22), q = BigInt(23), K = BigInt(44), e = BigInt(88), n = N * N * N % R, r = n * n * N % R, i = (0, m.pow2)(r, o, R) * r % R, a = (0, m.pow2)(i, o, R) * r % R, b = (0, m.pow2)(a, M, R) * n % R, A = (0, m.pow2)(b, c, R) * b % R, u = (0, m.pow2)(A, s, R) * A % R, l = (0, m.pow2)(u, K, R) * u % R, g = (0, m.pow2)(l, e, R) * l % R, _ = (0, m.pow2)(g, K, R) * u % R, C = (0, m.pow2)(_, o, R) * r % R, h = (0, m.pow2)(C, q, R) * A % R, x = (0, m.pow2)(h, p, R) * n % R, W = (0, m.pow2)(x, M, R);
|
|
3319
|
+
if (!d.eql(d.sqr(W), N))
|
|
3320
|
+
throw new Error("Cannot find square root");
|
|
3321
|
+
return W;
|
|
3322
|
+
}
|
|
3323
|
+
const d = (0, m.Field)(F.p, { sqrt: B });
|
|
3324
|
+
t.secp256k1 = (0, S.createCurve)({ ...F, Fp: d, lowS: !0, endo: G }, f.sha256);
|
|
3325
|
+
const w = {};
|
|
3326
|
+
function v(N, ...R) {
|
|
3327
|
+
let o = w[N];
|
|
3328
|
+
if (o === void 0) {
|
|
3329
|
+
const p = (0, f.sha256)((0, D.utf8ToBytes)(N));
|
|
3330
|
+
o = (0, D.concatBytes)(p, p), w[N] = o;
|
|
3331
|
+
}
|
|
3332
|
+
return (0, f.sha256)((0, D.concatBytes)(o, ...R));
|
|
3333
|
+
}
|
|
3334
|
+
const T = (N) => N.toBytes(!0).slice(1), P = t.secp256k1.Point, V = (N) => N % M === Y;
|
|
3335
|
+
function k(N) {
|
|
3336
|
+
const { Fn: R, BASE: o } = P, p = (0, I._normFnElement)(R, N), c = o.multiply(p);
|
|
3337
|
+
return { scalar: V(c.y) ? p : R.neg(p), bytes: T(c) };
|
|
3338
|
+
}
|
|
3339
|
+
function O(N) {
|
|
3340
|
+
const R = d;
|
|
3341
|
+
if (!R.isValidNot0(N))
|
|
3342
|
+
throw new Error("invalid x: Fail if x ≥ p");
|
|
3343
|
+
const o = R.create(N * N), p = R.create(o * N + BigInt(7));
|
|
3344
|
+
let c = R.sqrt(p);
|
|
3345
|
+
V(c) || (c = R.neg(c));
|
|
3346
|
+
const s = P.fromAffine({ x: N, y: c });
|
|
3347
|
+
return s.assertValidity(), s;
|
|
3348
|
+
}
|
|
3349
|
+
const E = D.bytesToNumberBE;
|
|
3350
|
+
function U(...N) {
|
|
3351
|
+
return P.Fn.create(E(v("BIP0340/challenge", ...N)));
|
|
3352
|
+
}
|
|
3353
|
+
function Z(N) {
|
|
3354
|
+
return k(N).bytes;
|
|
3355
|
+
}
|
|
3356
|
+
function j(N, R, o = (0, y.randomBytes)(32)) {
|
|
3357
|
+
const { Fn: p } = P, c = (0, D.ensureBytes)("message", N), { bytes: s, scalar: q } = k(R), K = (0, D.ensureBytes)("auxRand", o, 32), e = p.toBytes(q ^ E(v("BIP0340/aux", K))), n = v("BIP0340/nonce", e, s, c), { bytes: r, scalar: i } = k(n), a = U(r, s, c), b = new Uint8Array(64);
|
|
3358
|
+
if (b.set(r, 0), b.set(p.toBytes(p.create(i + a * q)), 32), !z(b, c, s))
|
|
3359
|
+
throw new Error("sign: Invalid signature produced");
|
|
3360
|
+
return b;
|
|
3361
|
+
}
|
|
3362
|
+
function z(N, R, o) {
|
|
3363
|
+
const { Fn: p, BASE: c } = P, s = (0, D.ensureBytes)("signature", N, 64), q = (0, D.ensureBytes)("message", R), K = (0, D.ensureBytes)("publicKey", o, 32);
|
|
3364
|
+
try {
|
|
3365
|
+
const e = O(E(K)), n = E(s.subarray(0, 32));
|
|
3366
|
+
if (!(0, D.inRange)(n, L, F.p))
|
|
3367
|
+
return !1;
|
|
3368
|
+
const r = E(s.subarray(32, 64));
|
|
3369
|
+
if (!(0, D.inRange)(r, L, F.n))
|
|
3370
|
+
return !1;
|
|
3371
|
+
const i = U(p.toBytes(n), T(e), q), a = c.multiplyUnsafe(r).add(e.multiplyUnsafe(p.neg(i))), { x: b, y: A } = a.toAffine();
|
|
3372
|
+
return !(a.is0() || !V(A) || b !== n);
|
|
3373
|
+
} catch {
|
|
3374
|
+
return !1;
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
t.schnorr = (() => {
|
|
3378
|
+
const o = (c = (0, y.randomBytes)(48)) => (0, m.mapHashToField)(c, F.n);
|
|
3379
|
+
t.secp256k1.utils.randomSecretKey;
|
|
3380
|
+
function p(c) {
|
|
3381
|
+
const s = o(c);
|
|
3382
|
+
return { secretKey: s, publicKey: Z(s) };
|
|
3383
|
+
}
|
|
3384
|
+
return {
|
|
3385
|
+
keygen: p,
|
|
3386
|
+
getPublicKey: Z,
|
|
3387
|
+
sign: j,
|
|
3388
|
+
verify: z,
|
|
3389
|
+
Point: P,
|
|
3390
|
+
utils: {
|
|
3391
|
+
randomSecretKey: o,
|
|
3392
|
+
randomPrivateKey: o,
|
|
3393
|
+
taggedHash: v,
|
|
3394
|
+
// TODO: remove
|
|
3395
|
+
lift_x: O,
|
|
3396
|
+
pointToBytes: T,
|
|
3397
|
+
numberToBytesBE: D.numberToBytesBE,
|
|
3398
|
+
bytesToNumberBE: D.bytesToNumberBE,
|
|
3399
|
+
mod: m.mod
|
|
3400
|
+
},
|
|
3401
|
+
lengths: {
|
|
3402
|
+
secretKey: 32,
|
|
3403
|
+
publicKey: 32,
|
|
3404
|
+
publicKeyHasPrefix: !1,
|
|
3405
|
+
signature: 64,
|
|
3406
|
+
seed: 48
|
|
3407
|
+
}
|
|
3408
|
+
};
|
|
3409
|
+
})();
|
|
3410
|
+
const Q = (0, H.isogenyMap)(d, [
|
|
3411
|
+
// xNum
|
|
3412
|
+
[
|
|
3413
|
+
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
3414
|
+
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
3415
|
+
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
3416
|
+
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
3417
|
+
],
|
|
3418
|
+
// xDen
|
|
3419
|
+
[
|
|
3420
|
+
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
3421
|
+
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
3422
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
3423
|
+
// LAST 1
|
|
3424
|
+
],
|
|
3425
|
+
// yNum
|
|
3426
|
+
[
|
|
3427
|
+
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
3428
|
+
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
3429
|
+
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
3430
|
+
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
3431
|
+
],
|
|
3432
|
+
// yDen
|
|
3433
|
+
[
|
|
3434
|
+
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
3435
|
+
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
3436
|
+
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
3437
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
3438
|
+
// LAST 1
|
|
3439
|
+
]
|
|
3440
|
+
].map((N) => N.map((R) => BigInt(R)))), X = (0, I.mapToCurveSimpleSWU)(d, {
|
|
3441
|
+
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
3442
|
+
B: BigInt("1771"),
|
|
3443
|
+
Z: d.create(BigInt("-11"))
|
|
3444
|
+
});
|
|
3445
|
+
t.secp256k1_hasher = (0, H.createHasher)(t.secp256k1.Point, (N) => {
|
|
3446
|
+
const { x: R, y: o } = X(d.create(N[0]));
|
|
3447
|
+
return Q(R, o);
|
|
3448
|
+
}, {
|
|
3449
|
+
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
3450
|
+
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
3451
|
+
p: d.ORDER,
|
|
3452
|
+
m: 1,
|
|
3453
|
+
k: 128,
|
|
3454
|
+
expand: "xmd",
|
|
3455
|
+
hash: f.sha256
|
|
3456
|
+
}), t.hashToCurve = t.secp256k1_hasher.hashToCurve, t.encodeToCurve = t.secp256k1_hasher.encodeToCurve;
|
|
3457
|
+
})(re)), re;
|
|
3458
|
+
}
|
|
3459
|
+
var ie = {}, Ke;
|
|
3460
|
+
function rn() {
|
|
3461
|
+
return Ke || (Ke = 1, (function(t) {
|
|
3462
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.decodeHex = t.remove0x = void 0;
|
|
3463
|
+
var f = /* @__PURE__ */ Ht(), y = function(H) {
|
|
3464
|
+
return H.startsWith("0x") || H.startsWith("0X") ? H.slice(2) : H;
|
|
3465
|
+
};
|
|
3466
|
+
t.remove0x = y;
|
|
3467
|
+
var S = function(H) {
|
|
3468
|
+
return (0, f.hexToBytes)((0, t.remove0x)(H));
|
|
3469
|
+
};
|
|
3470
|
+
t.decodeHex = S;
|
|
3471
|
+
})(ie)), ie;
|
|
3472
|
+
}
|
|
3473
|
+
var Pe;
|
|
3474
|
+
function mn() {
|
|
3475
|
+
return Pe || (Pe = 1, (function(t) {
|
|
3476
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.hexToPublicKey = t.convertPublicKeyFormat = t.getSharedPoint = t.getPublicKey = t.isValidPrivateKey = t.getValidSecret = void 0;
|
|
3477
|
+
var f = /* @__PURE__ */ Je(), y = /* @__PURE__ */ yn(), S = /* @__PURE__ */ gn(), H = zt(), m = le(), I = rn(), D = function(v) {
|
|
3478
|
+
var T;
|
|
3479
|
+
do
|
|
3480
|
+
T = (0, f.randomBytes)(m.SECRET_KEY_LENGTH);
|
|
3481
|
+
while (!(0, t.isValidPrivateKey)(T, v));
|
|
3482
|
+
return T;
|
|
3483
|
+
};
|
|
3484
|
+
t.getValidSecret = D;
|
|
3485
|
+
var F = function(v, T) {
|
|
3486
|
+
return B(T, function(P) {
|
|
3487
|
+
return P.utils.isValidSecretKey(v);
|
|
3488
|
+
}, function() {
|
|
3489
|
+
return !0;
|
|
3490
|
+
}, function() {
|
|
3491
|
+
return !0;
|
|
3492
|
+
});
|
|
3493
|
+
};
|
|
3494
|
+
t.isValidPrivateKey = F;
|
|
3495
|
+
var G = function(v, T) {
|
|
3496
|
+
return B(T, function(P) {
|
|
3497
|
+
return P.getPublicKey(v);
|
|
3498
|
+
}, function(P) {
|
|
3499
|
+
return P.getPublicKey(v);
|
|
3500
|
+
}, function(P) {
|
|
3501
|
+
return P.getPublicKey(v);
|
|
3502
|
+
});
|
|
3503
|
+
};
|
|
3504
|
+
t.getPublicKey = G;
|
|
3505
|
+
var Y = function(v, T, P, V) {
|
|
3506
|
+
return B(V, function(k) {
|
|
3507
|
+
return k.getSharedSecret(v, T, P);
|
|
3508
|
+
}, function(k) {
|
|
3509
|
+
return k.getSharedSecret(v, T);
|
|
3510
|
+
}, function(k) {
|
|
3511
|
+
return w(k, v, T);
|
|
3512
|
+
});
|
|
3513
|
+
};
|
|
3514
|
+
t.getSharedPoint = Y;
|
|
3515
|
+
var L = function(v, T, P) {
|
|
3516
|
+
return B(P, function(V) {
|
|
3517
|
+
return V.getSharedSecret(
|
|
3518
|
+
Uint8Array.from(Array(31).fill(0).concat([1])),
|
|
3519
|
+
// 1 as private key
|
|
3520
|
+
v,
|
|
3521
|
+
T
|
|
3522
|
+
);
|
|
3523
|
+
}, function() {
|
|
3524
|
+
return v;
|
|
3525
|
+
}, function() {
|
|
3526
|
+
return v;
|
|
3527
|
+
});
|
|
3528
|
+
};
|
|
3529
|
+
t.convertPublicKeyFormat = L;
|
|
3530
|
+
var M = function(v, T) {
|
|
3531
|
+
var P = (0, I.decodeHex)(v);
|
|
3532
|
+
return B(T, function() {
|
|
3533
|
+
return d(P);
|
|
3534
|
+
}, function() {
|
|
3535
|
+
return P;
|
|
3536
|
+
}, function() {
|
|
3537
|
+
return P;
|
|
3538
|
+
});
|
|
3539
|
+
};
|
|
3540
|
+
t.hexToPublicKey = M;
|
|
3541
|
+
function B(v, T, P, V) {
|
|
3542
|
+
var k = v || H.ECIES_CONFIG.ellipticCurve;
|
|
3543
|
+
/* v8 ignore else -- @preserve */
|
|
3544
|
+
if (k === "secp256k1")
|
|
3545
|
+
return T(S.secp256k1);
|
|
3546
|
+
if (k === "x25519")
|
|
3547
|
+
return P(y.x25519);
|
|
3548
|
+
if (k === "ed25519")
|
|
3549
|
+
return V(y.ed25519);
|
|
3550
|
+
throw new Error("Not implemented");
|
|
3551
|
+
}
|
|
3552
|
+
var d = function(v) {
|
|
3553
|
+
if (v.length === m.ETH_PUBLIC_KEY_SIZE) {
|
|
3554
|
+
var T = new Uint8Array(1 + v.length);
|
|
3555
|
+
return T.set([4]), T.set(v, 1), T;
|
|
3556
|
+
}
|
|
3557
|
+
return v;
|
|
3558
|
+
}, w = function(v, T, P) {
|
|
3559
|
+
var V = v.utils.getExtendedPublicKey(T).scalar, k = v.Point.fromBytes(P).multiply(V);
|
|
3560
|
+
return k.toBytes();
|
|
3561
|
+
};
|
|
3562
|
+
})(Qt)), Qt;
|
|
3563
|
+
}
|
|
3564
|
+
var ce = {}, Kt = {}, Ne;
|
|
3565
|
+
function wn() {
|
|
3566
|
+
if (Ne) return Kt;
|
|
3567
|
+
Ne = 1, Object.defineProperty(Kt, "__esModule", { value: !0 }), Kt.hkdf = void 0, Kt.extract = y, Kt.expand = m;
|
|
3568
|
+
const t = /* @__PURE__ */ en(), f = /* @__PURE__ */ Ot();
|
|
3569
|
+
function y(D, F, G) {
|
|
3570
|
+
return (0, f.ahash)(D), G === void 0 && (G = new Uint8Array(D.outputLen)), (0, t.hmac)(D, (0, f.toBytes)(G), (0, f.toBytes)(F));
|
|
3571
|
+
}
|
|
3572
|
+
const S = /* @__PURE__ */ Uint8Array.from([0]), H = /* @__PURE__ */ Uint8Array.of();
|
|
3573
|
+
function m(D, F, G, Y = 32) {
|
|
3574
|
+
(0, f.ahash)(D), (0, f.anumber)(Y);
|
|
3575
|
+
const L = D.outputLen;
|
|
3576
|
+
if (Y > 255 * L)
|
|
3577
|
+
throw new Error("Length should be <= 255*HashLen");
|
|
3578
|
+
const M = Math.ceil(Y / L);
|
|
3579
|
+
G === void 0 && (G = H);
|
|
3580
|
+
const B = new Uint8Array(M * L), d = t.hmac.create(D, F), w = d._cloneInto(), v = new Uint8Array(d.outputLen);
|
|
3581
|
+
for (let T = 0; T < M; T++)
|
|
3582
|
+
S[0] = T + 1, w.update(T === 0 ? H : v).update(G).update(S).digestInto(v), B.set(v, L * T), d._cloneInto(w);
|
|
3583
|
+
return d.destroy(), w.destroy(), (0, f.clean)(v, S), B.slice(0, Y);
|
|
3584
|
+
}
|
|
3585
|
+
const I = (D, F, G, Y, L) => m(D, y(D, F, G), Y, L);
|
|
3586
|
+
return Kt.hkdf = I, Kt;
|
|
3587
|
+
}
|
|
3588
|
+
var qe;
|
|
3589
|
+
function _n() {
|
|
3590
|
+
return qe || (qe = 1, (function(t) {
|
|
3591
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.getSharedKey = t.deriveKey = void 0;
|
|
3592
|
+
var f = /* @__PURE__ */ Ht(), y = /* @__PURE__ */ wn(), S = /* @__PURE__ */ de(), H = function(I, D, F) {
|
|
3593
|
+
return (0, y.hkdf)(S.sha256, I, D, F, 32);
|
|
3594
|
+
};
|
|
3595
|
+
t.deriveKey = H;
|
|
3596
|
+
var m = function() {
|
|
3597
|
+
for (var I = [], D = 0; D < arguments.length; D++)
|
|
3598
|
+
I[D] = arguments[D];
|
|
3599
|
+
return (0, t.deriveKey)(f.concatBytes.apply(void 0, I));
|
|
3600
|
+
};
|
|
3601
|
+
t.getSharedKey = m;
|
|
3602
|
+
})(ce)), ce;
|
|
3603
|
+
}
|
|
3604
|
+
var ae = {}, Pt = {}, fe = {}, Lt = {}, Me;
|
|
3605
|
+
function pn() {
|
|
3606
|
+
if (Me) return Lt;
|
|
3607
|
+
Me = 1, Object.defineProperty(Lt, "__esModule", { value: !0 }), Lt.polyval = Lt.ghash = void 0, Lt._toGHASHKey = D;
|
|
3608
|
+
const t = /* @__PURE__ */ Ht(), f = 16, y = /* @__PURE__ */ new Uint8Array(16), S = (0, t.u32)(y), H = 225, m = (M, B, d, w) => {
|
|
3609
|
+
const v = w & 1;
|
|
3610
|
+
return {
|
|
3611
|
+
s3: d << 31 | w >>> 1,
|
|
3612
|
+
s2: B << 31 | d >>> 1,
|
|
3613
|
+
s1: M << 31 | B >>> 1,
|
|
3614
|
+
s0: M >>> 1 ^ H << 24 & -(v & 1)
|
|
3615
|
+
// reduce % poly
|
|
3616
|
+
};
|
|
3617
|
+
}, I = (M) => (M >>> 0 & 255) << 24 | (M >>> 8 & 255) << 16 | (M >>> 16 & 255) << 8 | M >>> 24 & 255 | 0;
|
|
3618
|
+
function D(M) {
|
|
3619
|
+
M.reverse();
|
|
3620
|
+
const B = M[15] & 1;
|
|
3621
|
+
let d = 0;
|
|
3622
|
+
for (let w = 0; w < M.length; w++) {
|
|
3623
|
+
const v = M[w];
|
|
3624
|
+
M[w] = v >>> 1 | d, d = (v & 1) << 7;
|
|
3625
|
+
}
|
|
3626
|
+
return M[0] ^= -B & 225, M;
|
|
3627
|
+
}
|
|
3628
|
+
const F = (M) => M > 64 * 1024 ? 8 : M > 1024 ? 4 : 2;
|
|
3629
|
+
class G {
|
|
3630
|
+
// We select bits per window adaptively based on expectedLength
|
|
3631
|
+
constructor(B, d) {
|
|
3632
|
+
this.blockLen = f, this.outputLen = f, this.s0 = 0, this.s1 = 0, this.s2 = 0, this.s3 = 0, this.finished = !1, B = (0, t.toBytes)(B), (0, t.abytes)(B, 16);
|
|
3633
|
+
const w = (0, t.createView)(B);
|
|
3634
|
+
let v = w.getUint32(0, !1), T = w.getUint32(4, !1), P = w.getUint32(8, !1), V = w.getUint32(12, !1);
|
|
3635
|
+
const k = [];
|
|
3636
|
+
for (let z = 0; z < 128; z++)
|
|
3637
|
+
k.push({ s0: I(v), s1: I(T), s2: I(P), s3: I(V) }), { s0: v, s1: T, s2: P, s3: V } = m(v, T, P, V);
|
|
3638
|
+
const O = F(d || 1024);
|
|
3639
|
+
if (![1, 2, 4, 8].includes(O))
|
|
3640
|
+
throw new Error("ghash: invalid window size, expected 2, 4 or 8");
|
|
3641
|
+
this.W = O;
|
|
3642
|
+
const U = 128 / O, Z = this.windowSize = 2 ** O, j = [];
|
|
3643
|
+
for (let z = 0; z < U; z++)
|
|
3644
|
+
for (let Q = 0; Q < Z; Q++) {
|
|
3645
|
+
let X = 0, N = 0, R = 0, o = 0;
|
|
3646
|
+
for (let p = 0; p < O; p++) {
|
|
3647
|
+
if (!(Q >>> O - p - 1 & 1))
|
|
3648
|
+
continue;
|
|
3649
|
+
const { s0: s, s1: q, s2: K, s3: e } = k[O * z + p];
|
|
3650
|
+
X ^= s, N ^= q, R ^= K, o ^= e;
|
|
3651
|
+
}
|
|
3652
|
+
j.push({ s0: X, s1: N, s2: R, s3: o });
|
|
3653
|
+
}
|
|
3654
|
+
this.t = j;
|
|
3655
|
+
}
|
|
3656
|
+
_updateBlock(B, d, w, v) {
|
|
3657
|
+
B ^= this.s0, d ^= this.s1, w ^= this.s2, v ^= this.s3;
|
|
3658
|
+
const { W: T, t: P, windowSize: V } = this;
|
|
3659
|
+
let k = 0, O = 0, E = 0, U = 0;
|
|
3660
|
+
const Z = (1 << T) - 1;
|
|
3661
|
+
let j = 0;
|
|
3662
|
+
for (const z of [B, d, w, v])
|
|
3663
|
+
for (let Q = 0; Q < 4; Q++) {
|
|
3664
|
+
const X = z >>> 8 * Q & 255;
|
|
3665
|
+
for (let N = 8 / T - 1; N >= 0; N--) {
|
|
3666
|
+
const R = X >>> T * N & Z, { s0: o, s1: p, s2: c, s3: s } = P[j * V + R];
|
|
3667
|
+
k ^= o, O ^= p, E ^= c, U ^= s, j += 1;
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
this.s0 = k, this.s1 = O, this.s2 = E, this.s3 = U;
|
|
3671
|
+
}
|
|
3672
|
+
update(B) {
|
|
3673
|
+
(0, t.aexists)(this), B = (0, t.toBytes)(B), (0, t.abytes)(B);
|
|
3674
|
+
const d = (0, t.u32)(B), w = Math.floor(B.length / f), v = B.length % f;
|
|
3675
|
+
for (let T = 0; T < w; T++)
|
|
3676
|
+
this._updateBlock(d[T * 4 + 0], d[T * 4 + 1], d[T * 4 + 2], d[T * 4 + 3]);
|
|
3677
|
+
return v && (y.set(B.subarray(w * f)), this._updateBlock(S[0], S[1], S[2], S[3]), (0, t.clean)(S)), this;
|
|
3678
|
+
}
|
|
3679
|
+
destroy() {
|
|
3680
|
+
const { t: B } = this;
|
|
3681
|
+
for (const d of B)
|
|
3682
|
+
d.s0 = 0, d.s1 = 0, d.s2 = 0, d.s3 = 0;
|
|
3683
|
+
}
|
|
3684
|
+
digestInto(B) {
|
|
3685
|
+
(0, t.aexists)(this), (0, t.aoutput)(B, this), this.finished = !0;
|
|
3686
|
+
const { s0: d, s1: w, s2: v, s3: T } = this, P = (0, t.u32)(B);
|
|
3687
|
+
return P[0] = d, P[1] = w, P[2] = v, P[3] = T, B;
|
|
3688
|
+
}
|
|
3689
|
+
digest() {
|
|
3690
|
+
const B = new Uint8Array(f);
|
|
3691
|
+
return this.digestInto(B), this.destroy(), B;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
class Y extends G {
|
|
3695
|
+
constructor(B, d) {
|
|
3696
|
+
B = (0, t.toBytes)(B), (0, t.abytes)(B);
|
|
3697
|
+
const w = D((0, t.copyBytes)(B));
|
|
3698
|
+
super(w, d), (0, t.clean)(w);
|
|
3699
|
+
}
|
|
3700
|
+
update(B) {
|
|
3701
|
+
B = (0, t.toBytes)(B), (0, t.aexists)(this);
|
|
3702
|
+
const d = (0, t.u32)(B), w = B.length % f, v = Math.floor(B.length / f);
|
|
3703
|
+
for (let T = 0; T < v; T++)
|
|
3704
|
+
this._updateBlock(I(d[T * 4 + 3]), I(d[T * 4 + 2]), I(d[T * 4 + 1]), I(d[T * 4 + 0]));
|
|
3705
|
+
return w && (y.set(B.subarray(v * f)), this._updateBlock(I(S[3]), I(S[2]), I(S[1]), I(S[0])), (0, t.clean)(S)), this;
|
|
3706
|
+
}
|
|
3707
|
+
digestInto(B) {
|
|
3708
|
+
(0, t.aexists)(this), (0, t.aoutput)(B, this), this.finished = !0;
|
|
3709
|
+
const { s0: d, s1: w, s2: v, s3: T } = this, P = (0, t.u32)(B);
|
|
3710
|
+
return P[0] = d, P[1] = w, P[2] = v, P[3] = T, B.reverse();
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
function L(M) {
|
|
3714
|
+
const B = (w, v) => M(v, w.length).update((0, t.toBytes)(w)).digest(), d = M(new Uint8Array(16), 0);
|
|
3715
|
+
return B.outputLen = d.outputLen, B.blockLen = d.blockLen, B.create = (w, v) => M(w, v), B;
|
|
3716
|
+
}
|
|
3717
|
+
return Lt.ghash = L((M, B) => new G(M, B)), Lt.polyval = L((M, B) => new Y(M, B)), Lt;
|
|
3718
|
+
}
|
|
3719
|
+
var Ve;
|
|
3720
|
+
function vn() {
|
|
3721
|
+
return Ve || (Ve = 1, (function(t) {
|
|
3722
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.unsafe = t.aeskwp = t.aeskw = t.siv = t.gcmsiv = t.gcm = t.cfb = t.cbc = t.ecb = t.ctr = void 0;
|
|
3723
|
+
const f = /* @__PURE__ */ pn(), y = /* @__PURE__ */ Ht(), S = 16, H = 4, m = /* @__PURE__ */ new Uint8Array(S), I = 283;
|
|
3724
|
+
function D(n) {
|
|
3725
|
+
return n << 1 ^ I & -(n >> 7);
|
|
3726
|
+
}
|
|
3727
|
+
function F(n, r) {
|
|
3728
|
+
let i = 0;
|
|
3729
|
+
for (; r > 0; r >>= 1)
|
|
3730
|
+
i ^= n & -(r & 1), n = D(n);
|
|
3731
|
+
return i;
|
|
3732
|
+
}
|
|
3733
|
+
const G = /* @__PURE__ */ (() => {
|
|
3734
|
+
const n = new Uint8Array(256);
|
|
3735
|
+
for (let i = 0, a = 1; i < 256; i++, a ^= D(a))
|
|
3736
|
+
n[i] = a;
|
|
3737
|
+
const r = new Uint8Array(256);
|
|
3738
|
+
r[0] = 99;
|
|
3739
|
+
for (let i = 0; i < 255; i++) {
|
|
3740
|
+
let a = n[255 - i];
|
|
3741
|
+
a |= a << 8, r[n[i]] = (a ^ a >> 4 ^ a >> 5 ^ a >> 6 ^ a >> 7 ^ 99) & 255;
|
|
3742
|
+
}
|
|
3743
|
+
return (0, y.clean)(n), r;
|
|
3744
|
+
})(), Y = /* @__PURE__ */ G.map((n, r) => G.indexOf(r)), L = (n) => n << 24 | n >>> 8, M = (n) => n << 8 | n >>> 24, B = (n) => n << 24 & 4278190080 | n << 8 & 16711680 | n >>> 8 & 65280 | n >>> 24 & 255;
|
|
3745
|
+
function d(n, r) {
|
|
3746
|
+
if (n.length !== 256)
|
|
3747
|
+
throw new Error("Wrong sbox length");
|
|
3748
|
+
const i = new Uint32Array(256).map((_, C) => r(n[C])), a = i.map(M), b = a.map(M), A = b.map(M), u = new Uint32Array(256 * 256), l = new Uint32Array(256 * 256), g = new Uint16Array(256 * 256);
|
|
3749
|
+
for (let _ = 0; _ < 256; _++)
|
|
3750
|
+
for (let C = 0; C < 256; C++) {
|
|
3751
|
+
const h = _ * 256 + C;
|
|
3752
|
+
u[h] = i[_] ^ a[C], l[h] = b[_] ^ A[C], g[h] = n[_] << 8 | n[C];
|
|
3753
|
+
}
|
|
3754
|
+
return { sbox: n, sbox2: g, T0: i, T1: a, T2: b, T3: A, T01: u, T23: l };
|
|
3755
|
+
}
|
|
3756
|
+
const w = /* @__PURE__ */ d(G, (n) => F(n, 3) << 24 | n << 16 | n << 8 | F(n, 2)), v = /* @__PURE__ */ d(Y, (n) => F(n, 11) << 24 | F(n, 13) << 16 | F(n, 9) << 8 | F(n, 14)), T = /* @__PURE__ */ (() => {
|
|
3757
|
+
const n = new Uint8Array(16);
|
|
3758
|
+
for (let r = 0, i = 1; r < 16; r++, i = D(i))
|
|
3759
|
+
n[r] = i;
|
|
3760
|
+
return n;
|
|
3761
|
+
})();
|
|
3762
|
+
function P(n) {
|
|
3763
|
+
(0, y.abytes)(n);
|
|
3764
|
+
const r = n.length;
|
|
3765
|
+
if (![16, 24, 32].includes(r))
|
|
3766
|
+
throw new Error("aes: invalid key size, should be 16, 24 or 32, got " + r);
|
|
3767
|
+
const { sbox2: i } = w, a = [];
|
|
3768
|
+
(0, y.isAligned32)(n) || a.push(n = (0, y.copyBytes)(n));
|
|
3769
|
+
const b = (0, y.u32)(n), A = b.length, u = (g) => O(i, g, g, g, g), l = new Uint32Array(r + 28);
|
|
3770
|
+
l.set(b);
|
|
3771
|
+
for (let g = A; g < l.length; g++) {
|
|
3772
|
+
let _ = l[g - 1];
|
|
3773
|
+
g % A === 0 ? _ = u(L(_)) ^ T[g / A - 1] : A > 6 && g % A === 4 && (_ = u(_)), l[g] = l[g - A] ^ _;
|
|
3774
|
+
}
|
|
3775
|
+
return (0, y.clean)(...a), l;
|
|
3776
|
+
}
|
|
3777
|
+
function V(n) {
|
|
3778
|
+
const r = P(n), i = r.slice(), a = r.length, { sbox2: b } = w, { T0: A, T1: u, T2: l, T3: g } = v;
|
|
3779
|
+
for (let _ = 0; _ < a; _ += 4)
|
|
3780
|
+
for (let C = 0; C < 4; C++)
|
|
3781
|
+
i[_ + C] = r[a - _ - 4 + C];
|
|
3782
|
+
(0, y.clean)(r);
|
|
3783
|
+
for (let _ = 4; _ < a - 4; _++) {
|
|
3784
|
+
const C = i[_], h = O(b, C, C, C, C);
|
|
3785
|
+
i[_] = A[h & 255] ^ u[h >>> 8 & 255] ^ l[h >>> 16 & 255] ^ g[h >>> 24];
|
|
3786
|
+
}
|
|
3787
|
+
return i;
|
|
3788
|
+
}
|
|
3789
|
+
function k(n, r, i, a, b, A) {
|
|
3790
|
+
return n[i << 8 & 65280 | a >>> 8 & 255] ^ r[b >>> 8 & 65280 | A >>> 24 & 255];
|
|
3791
|
+
}
|
|
3792
|
+
function O(n, r, i, a, b) {
|
|
3793
|
+
return n[r & 255 | i & 65280] | n[a >>> 16 & 255 | b >>> 16 & 65280] << 16;
|
|
3794
|
+
}
|
|
3795
|
+
function E(n, r, i, a, b) {
|
|
3796
|
+
const { sbox2: A, T01: u, T23: l } = w;
|
|
3797
|
+
let g = 0;
|
|
3798
|
+
r ^= n[g++], i ^= n[g++], a ^= n[g++], b ^= n[g++];
|
|
3799
|
+
const _ = n.length / 4 - 2;
|
|
3800
|
+
for (let $ = 0; $ < _; $++) {
|
|
3801
|
+
const ot = n[g++] ^ k(u, l, r, i, a, b), nt = n[g++] ^ k(u, l, i, a, b, r), st = n[g++] ^ k(u, l, a, b, r, i), rt = n[g++] ^ k(u, l, b, r, i, a);
|
|
3802
|
+
r = ot, i = nt, a = st, b = rt;
|
|
3803
|
+
}
|
|
3804
|
+
const C = n[g++] ^ O(A, r, i, a, b), h = n[g++] ^ O(A, i, a, b, r), x = n[g++] ^ O(A, a, b, r, i), W = n[g++] ^ O(A, b, r, i, a);
|
|
3805
|
+
return { s0: C, s1: h, s2: x, s3: W };
|
|
3806
|
+
}
|
|
3807
|
+
function U(n, r, i, a, b) {
|
|
3808
|
+
const { sbox2: A, T01: u, T23: l } = v;
|
|
3809
|
+
let g = 0;
|
|
3810
|
+
r ^= n[g++], i ^= n[g++], a ^= n[g++], b ^= n[g++];
|
|
3811
|
+
const _ = n.length / 4 - 2;
|
|
3812
|
+
for (let $ = 0; $ < _; $++) {
|
|
3813
|
+
const ot = n[g++] ^ k(u, l, r, b, a, i), nt = n[g++] ^ k(u, l, i, r, b, a), st = n[g++] ^ k(u, l, a, i, r, b), rt = n[g++] ^ k(u, l, b, a, i, r);
|
|
3814
|
+
r = ot, i = nt, a = st, b = rt;
|
|
3815
|
+
}
|
|
3816
|
+
const C = n[g++] ^ O(A, r, b, a, i), h = n[g++] ^ O(A, i, r, b, a), x = n[g++] ^ O(A, a, i, r, b), W = n[g++] ^ O(A, b, a, i, r);
|
|
3817
|
+
return { s0: C, s1: h, s2: x, s3: W };
|
|
3818
|
+
}
|
|
3819
|
+
function Z(n, r, i, a) {
|
|
3820
|
+
(0, y.abytes)(r, S), (0, y.abytes)(i);
|
|
3821
|
+
const b = i.length;
|
|
3822
|
+
a = (0, y.getOutput)(b, a), (0, y.complexOverlapBytes)(i, a);
|
|
3823
|
+
const A = r, u = (0, y.u32)(A);
|
|
3824
|
+
let { s0: l, s1: g, s2: _, s3: C } = E(n, u[0], u[1], u[2], u[3]);
|
|
3825
|
+
const h = (0, y.u32)(i), x = (0, y.u32)(a);
|
|
3826
|
+
for (let $ = 0; $ + 4 <= h.length; $ += 4) {
|
|
3827
|
+
x[$ + 0] = h[$ + 0] ^ l, x[$ + 1] = h[$ + 1] ^ g, x[$ + 2] = h[$ + 2] ^ _, x[$ + 3] = h[$ + 3] ^ C;
|
|
3828
|
+
let ot = 1;
|
|
3829
|
+
for (let nt = A.length - 1; nt >= 0; nt--)
|
|
3830
|
+
ot = ot + (A[nt] & 255) | 0, A[nt] = ot & 255, ot >>>= 8;
|
|
3831
|
+
({ s0: l, s1: g, s2: _, s3: C } = E(n, u[0], u[1], u[2], u[3]));
|
|
3832
|
+
}
|
|
3833
|
+
const W = S * Math.floor(h.length / H);
|
|
3834
|
+
if (W < b) {
|
|
3835
|
+
const $ = new Uint32Array([l, g, _, C]), ot = (0, y.u8)($);
|
|
3836
|
+
for (let nt = W, st = 0; nt < b; nt++, st++)
|
|
3837
|
+
a[nt] = i[nt] ^ ot[st];
|
|
3838
|
+
(0, y.clean)($);
|
|
3839
|
+
}
|
|
3840
|
+
return a;
|
|
3841
|
+
}
|
|
3842
|
+
function j(n, r, i, a, b) {
|
|
3843
|
+
(0, y.abytes)(i, S), (0, y.abytes)(a), b = (0, y.getOutput)(a.length, b);
|
|
3844
|
+
const A = i, u = (0, y.u32)(A), l = (0, y.createView)(A), g = (0, y.u32)(a), _ = (0, y.u32)(b), C = r ? 0 : 12, h = a.length;
|
|
3845
|
+
let x = l.getUint32(C, r), { s0: W, s1: $, s2: ot, s3: nt } = E(n, u[0], u[1], u[2], u[3]);
|
|
3846
|
+
for (let rt = 0; rt + 4 <= g.length; rt += 4)
|
|
3847
|
+
_[rt + 0] = g[rt + 0] ^ W, _[rt + 1] = g[rt + 1] ^ $, _[rt + 2] = g[rt + 2] ^ ot, _[rt + 3] = g[rt + 3] ^ nt, x = x + 1 >>> 0, l.setUint32(C, x, r), { s0: W, s1: $, s2: ot, s3: nt } = E(n, u[0], u[1], u[2], u[3]);
|
|
3848
|
+
const st = S * Math.floor(g.length / H);
|
|
3849
|
+
if (st < h) {
|
|
3850
|
+
const rt = new Uint32Array([W, $, ot, nt]), yt = (0, y.u8)(rt);
|
|
3851
|
+
for (let ut = st, ct = 0; ut < h; ut++, ct++)
|
|
3852
|
+
b[ut] = a[ut] ^ yt[ct];
|
|
3853
|
+
(0, y.clean)(rt);
|
|
3854
|
+
}
|
|
3855
|
+
return b;
|
|
3856
|
+
}
|
|
3857
|
+
t.ctr = (0, y.wrapCipher)({ blockSize: 16, nonceLength: 16 }, function(r, i) {
|
|
3858
|
+
function a(b, A) {
|
|
3859
|
+
if ((0, y.abytes)(b), A !== void 0 && ((0, y.abytes)(A), !(0, y.isAligned32)(A)))
|
|
3860
|
+
throw new Error("unaligned destination");
|
|
3861
|
+
const u = P(r), l = (0, y.copyBytes)(i), g = [u, l];
|
|
3862
|
+
(0, y.isAligned32)(b) || g.push(b = (0, y.copyBytes)(b));
|
|
3863
|
+
const _ = Z(u, l, b, A);
|
|
3864
|
+
return (0, y.clean)(...g), _;
|
|
3865
|
+
}
|
|
3866
|
+
return {
|
|
3867
|
+
encrypt: (b, A) => a(b, A),
|
|
3868
|
+
decrypt: (b, A) => a(b, A)
|
|
3869
|
+
};
|
|
3870
|
+
});
|
|
3871
|
+
function z(n) {
|
|
3872
|
+
if ((0, y.abytes)(n), n.length % S !== 0)
|
|
3873
|
+
throw new Error("aes-(cbc/ecb).decrypt ciphertext should consist of blocks with size " + S);
|
|
3874
|
+
}
|
|
3875
|
+
function Q(n, r, i) {
|
|
3876
|
+
(0, y.abytes)(n);
|
|
3877
|
+
let a = n.length;
|
|
3878
|
+
const b = a % S;
|
|
3879
|
+
if (!r && b !== 0)
|
|
3880
|
+
throw new Error("aec/(cbc-ecb): unpadded plaintext with disabled padding");
|
|
3881
|
+
(0, y.isAligned32)(n) || (n = (0, y.copyBytes)(n));
|
|
3882
|
+
const A = (0, y.u32)(n);
|
|
3883
|
+
if (r) {
|
|
3884
|
+
let l = S - b;
|
|
3885
|
+
l || (l = S), a = a + l;
|
|
3886
|
+
}
|
|
3887
|
+
i = (0, y.getOutput)(a, i), (0, y.complexOverlapBytes)(n, i);
|
|
3888
|
+
const u = (0, y.u32)(i);
|
|
3889
|
+
return { b: A, o: u, out: i };
|
|
3890
|
+
}
|
|
3891
|
+
function X(n, r) {
|
|
3892
|
+
if (!r)
|
|
3893
|
+
return n;
|
|
3894
|
+
const i = n.length;
|
|
3895
|
+
if (!i)
|
|
3896
|
+
throw new Error("aes/pcks5: empty ciphertext not allowed");
|
|
3897
|
+
const a = n[i - 1];
|
|
3898
|
+
if (a <= 0 || a > 16)
|
|
3899
|
+
throw new Error("aes/pcks5: wrong padding");
|
|
3900
|
+
const b = n.subarray(0, -a);
|
|
3901
|
+
for (let A = 0; A < a; A++)
|
|
3902
|
+
if (n[i - A - 1] !== a)
|
|
3903
|
+
throw new Error("aes/pcks5: wrong padding");
|
|
3904
|
+
return b;
|
|
3905
|
+
}
|
|
3906
|
+
function N(n) {
|
|
3907
|
+
const r = new Uint8Array(16), i = (0, y.u32)(r);
|
|
3908
|
+
r.set(n);
|
|
3909
|
+
const a = S - n.length;
|
|
3910
|
+
for (let b = S - a; b < S; b++)
|
|
3911
|
+
r[b] = a;
|
|
3912
|
+
return i;
|
|
3913
|
+
}
|
|
3914
|
+
t.ecb = (0, y.wrapCipher)({ blockSize: 16 }, function(r, i = {}) {
|
|
3915
|
+
const a = !i.disablePadding;
|
|
3916
|
+
return {
|
|
3917
|
+
encrypt(b, A) {
|
|
3918
|
+
const { b: u, o: l, out: g } = Q(b, a, A), _ = P(r);
|
|
3919
|
+
let C = 0;
|
|
3920
|
+
for (; C + 4 <= u.length; ) {
|
|
3921
|
+
const { s0: h, s1: x, s2: W, s3: $ } = E(_, u[C + 0], u[C + 1], u[C + 2], u[C + 3]);
|
|
3922
|
+
l[C++] = h, l[C++] = x, l[C++] = W, l[C++] = $;
|
|
3923
|
+
}
|
|
3924
|
+
if (a) {
|
|
3925
|
+
const h = N(b.subarray(C * 4)), { s0: x, s1: W, s2: $, s3: ot } = E(_, h[0], h[1], h[2], h[3]);
|
|
3926
|
+
l[C++] = x, l[C++] = W, l[C++] = $, l[C++] = ot;
|
|
3927
|
+
}
|
|
3928
|
+
return (0, y.clean)(_), g;
|
|
3929
|
+
},
|
|
3930
|
+
decrypt(b, A) {
|
|
3931
|
+
z(b);
|
|
3932
|
+
const u = V(r);
|
|
3933
|
+
A = (0, y.getOutput)(b.length, A);
|
|
3934
|
+
const l = [u];
|
|
3935
|
+
(0, y.isAligned32)(b) || l.push(b = (0, y.copyBytes)(b)), (0, y.complexOverlapBytes)(b, A);
|
|
3936
|
+
const g = (0, y.u32)(b), _ = (0, y.u32)(A);
|
|
3937
|
+
for (let C = 0; C + 4 <= g.length; ) {
|
|
3938
|
+
const { s0: h, s1: x, s2: W, s3: $ } = U(u, g[C + 0], g[C + 1], g[C + 2], g[C + 3]);
|
|
3939
|
+
_[C++] = h, _[C++] = x, _[C++] = W, _[C++] = $;
|
|
3940
|
+
}
|
|
3941
|
+
return (0, y.clean)(...l), X(A, a);
|
|
3942
|
+
}
|
|
3943
|
+
};
|
|
3944
|
+
}), t.cbc = (0, y.wrapCipher)({ blockSize: 16, nonceLength: 16 }, function(r, i, a = {}) {
|
|
3945
|
+
const b = !a.disablePadding;
|
|
3946
|
+
return {
|
|
3947
|
+
encrypt(A, u) {
|
|
3948
|
+
const l = P(r), { b: g, o: _, out: C } = Q(A, b, u);
|
|
3949
|
+
let h = i;
|
|
3950
|
+
const x = [l];
|
|
3951
|
+
(0, y.isAligned32)(h) || x.push(h = (0, y.copyBytes)(h));
|
|
3952
|
+
const W = (0, y.u32)(h);
|
|
3953
|
+
let $ = W[0], ot = W[1], nt = W[2], st = W[3], rt = 0;
|
|
3954
|
+
for (; rt + 4 <= g.length; )
|
|
3955
|
+
$ ^= g[rt + 0], ot ^= g[rt + 1], nt ^= g[rt + 2], st ^= g[rt + 3], { s0: $, s1: ot, s2: nt, s3: st } = E(l, $, ot, nt, st), _[rt++] = $, _[rt++] = ot, _[rt++] = nt, _[rt++] = st;
|
|
3956
|
+
if (b) {
|
|
3957
|
+
const yt = N(A.subarray(rt * 4));
|
|
3958
|
+
$ ^= yt[0], ot ^= yt[1], nt ^= yt[2], st ^= yt[3], { s0: $, s1: ot, s2: nt, s3: st } = E(l, $, ot, nt, st), _[rt++] = $, _[rt++] = ot, _[rt++] = nt, _[rt++] = st;
|
|
3959
|
+
}
|
|
3960
|
+
return (0, y.clean)(...x), C;
|
|
3961
|
+
},
|
|
3962
|
+
decrypt(A, u) {
|
|
3963
|
+
z(A);
|
|
3964
|
+
const l = V(r);
|
|
3965
|
+
let g = i;
|
|
3966
|
+
const _ = [l];
|
|
3967
|
+
(0, y.isAligned32)(g) || _.push(g = (0, y.copyBytes)(g));
|
|
3968
|
+
const C = (0, y.u32)(g);
|
|
3969
|
+
u = (0, y.getOutput)(A.length, u), (0, y.isAligned32)(A) || _.push(A = (0, y.copyBytes)(A)), (0, y.complexOverlapBytes)(A, u);
|
|
3970
|
+
const h = (0, y.u32)(A), x = (0, y.u32)(u);
|
|
3971
|
+
let W = C[0], $ = C[1], ot = C[2], nt = C[3];
|
|
3972
|
+
for (let st = 0; st + 4 <= h.length; ) {
|
|
3973
|
+
const rt = W, yt = $, ut = ot, ct = nt;
|
|
3974
|
+
W = h[st + 0], $ = h[st + 1], ot = h[st + 2], nt = h[st + 3];
|
|
3975
|
+
const { s0: et, s1: tt, s2: J, s3: it } = U(l, W, $, ot, nt);
|
|
3976
|
+
x[st++] = et ^ rt, x[st++] = tt ^ yt, x[st++] = J ^ ut, x[st++] = it ^ ct;
|
|
3977
|
+
}
|
|
3978
|
+
return (0, y.clean)(..._), X(u, b);
|
|
3979
|
+
}
|
|
3980
|
+
};
|
|
3981
|
+
}), t.cfb = (0, y.wrapCipher)({ blockSize: 16, nonceLength: 16 }, function(r, i) {
|
|
3982
|
+
function a(b, A, u) {
|
|
3983
|
+
(0, y.abytes)(b);
|
|
3984
|
+
const l = b.length;
|
|
3985
|
+
if (u = (0, y.getOutput)(l, u), (0, y.overlapBytes)(b, u))
|
|
3986
|
+
throw new Error("overlapping src and dst not supported.");
|
|
3987
|
+
const g = P(r);
|
|
3988
|
+
let _ = i;
|
|
3989
|
+
const C = [g];
|
|
3990
|
+
(0, y.isAligned32)(_) || C.push(_ = (0, y.copyBytes)(_)), (0, y.isAligned32)(b) || C.push(b = (0, y.copyBytes)(b));
|
|
3991
|
+
const h = (0, y.u32)(b), x = (0, y.u32)(u), W = A ? x : h, $ = (0, y.u32)(_);
|
|
3992
|
+
let ot = $[0], nt = $[1], st = $[2], rt = $[3];
|
|
3993
|
+
for (let ut = 0; ut + 4 <= h.length; ) {
|
|
3994
|
+
const { s0: ct, s1: et, s2: tt, s3: J } = E(g, ot, nt, st, rt);
|
|
3995
|
+
x[ut + 0] = h[ut + 0] ^ ct, x[ut + 1] = h[ut + 1] ^ et, x[ut + 2] = h[ut + 2] ^ tt, x[ut + 3] = h[ut + 3] ^ J, ot = W[ut++], nt = W[ut++], st = W[ut++], rt = W[ut++];
|
|
3996
|
+
}
|
|
3997
|
+
const yt = S * Math.floor(h.length / H);
|
|
3998
|
+
if (yt < l) {
|
|
3999
|
+
({ s0: ot, s1: nt, s2: st, s3: rt } = E(g, ot, nt, st, rt));
|
|
4000
|
+
const ut = (0, y.u8)(new Uint32Array([ot, nt, st, rt]));
|
|
4001
|
+
for (let ct = yt, et = 0; ct < l; ct++, et++)
|
|
4002
|
+
u[ct] = b[ct] ^ ut[et];
|
|
4003
|
+
(0, y.clean)(ut);
|
|
4004
|
+
}
|
|
4005
|
+
return (0, y.clean)(...C), u;
|
|
4006
|
+
}
|
|
4007
|
+
return {
|
|
4008
|
+
encrypt: (b, A) => a(b, !0, A),
|
|
4009
|
+
decrypt: (b, A) => a(b, !1, A)
|
|
4010
|
+
};
|
|
4011
|
+
});
|
|
4012
|
+
function R(n, r, i, a, b) {
|
|
4013
|
+
const A = b ? b.length : 0, u = n.create(i, a.length + A);
|
|
4014
|
+
b && u.update(b);
|
|
4015
|
+
const l = (0, y.u64Lengths)(8 * a.length, 8 * A, r);
|
|
4016
|
+
u.update(a), u.update(l);
|
|
4017
|
+
const g = u.digest();
|
|
4018
|
+
return (0, y.clean)(l), g;
|
|
4019
|
+
}
|
|
4020
|
+
t.gcm = (0, y.wrapCipher)({ blockSize: 16, nonceLength: 12, tagLength: 16, varSizeNonce: !0 }, function(r, i, a) {
|
|
4021
|
+
if (i.length < 8)
|
|
4022
|
+
throw new Error("aes/gcm: invalid nonce length");
|
|
4023
|
+
const b = 16;
|
|
4024
|
+
function A(l, g, _) {
|
|
4025
|
+
const C = R(f.ghash, !1, l, _, a);
|
|
4026
|
+
for (let h = 0; h < g.length; h++)
|
|
4027
|
+
C[h] ^= g[h];
|
|
4028
|
+
return C;
|
|
4029
|
+
}
|
|
4030
|
+
function u() {
|
|
4031
|
+
const l = P(r), g = m.slice(), _ = m.slice();
|
|
4032
|
+
if (j(l, !1, _, _, g), i.length === 12)
|
|
4033
|
+
_.set(i);
|
|
4034
|
+
else {
|
|
4035
|
+
const h = m.slice(), x = (0, y.createView)(h);
|
|
4036
|
+
(0, y.setBigUint64)(x, 8, BigInt(i.length * 8), !1);
|
|
4037
|
+
const W = f.ghash.create(g).update(i).update(h);
|
|
4038
|
+
W.digestInto(_), W.destroy();
|
|
4039
|
+
}
|
|
4040
|
+
const C = j(l, !1, _, m);
|
|
4041
|
+
return { xk: l, authKey: g, counter: _, tagMask: C };
|
|
4042
|
+
}
|
|
4043
|
+
return {
|
|
4044
|
+
encrypt(l) {
|
|
4045
|
+
const { xk: g, authKey: _, counter: C, tagMask: h } = u(), x = new Uint8Array(l.length + b), W = [g, _, C, h];
|
|
4046
|
+
(0, y.isAligned32)(l) || W.push(l = (0, y.copyBytes)(l)), j(g, !1, C, l, x.subarray(0, l.length));
|
|
4047
|
+
const $ = A(_, h, x.subarray(0, x.length - b));
|
|
4048
|
+
return W.push($), x.set($, l.length), (0, y.clean)(...W), x;
|
|
4049
|
+
},
|
|
4050
|
+
decrypt(l) {
|
|
4051
|
+
const { xk: g, authKey: _, counter: C, tagMask: h } = u(), x = [g, _, h, C];
|
|
4052
|
+
(0, y.isAligned32)(l) || x.push(l = (0, y.copyBytes)(l));
|
|
4053
|
+
const W = l.subarray(0, -b), $ = l.subarray(-b), ot = A(_, h, W);
|
|
4054
|
+
if (x.push(ot), !(0, y.equalBytes)(ot, $))
|
|
4055
|
+
throw new Error("aes/gcm: invalid ghash tag");
|
|
4056
|
+
const nt = j(g, !1, C, W);
|
|
4057
|
+
return (0, y.clean)(...x), nt;
|
|
4058
|
+
}
|
|
4059
|
+
};
|
|
4060
|
+
});
|
|
4061
|
+
const o = (n, r, i) => (a) => {
|
|
4062
|
+
if (!Number.isSafeInteger(a) || r > a || a > i) {
|
|
4063
|
+
const b = "[" + r + ".." + i + "]";
|
|
4064
|
+
throw new Error("" + n + ": expected value in range " + b + ", got " + a);
|
|
4065
|
+
}
|
|
4066
|
+
};
|
|
4067
|
+
t.gcmsiv = (0, y.wrapCipher)({ blockSize: 16, nonceLength: 12, tagLength: 16, varSizeNonce: !0 }, function(r, i, a) {
|
|
4068
|
+
const A = o("AAD", 0, 68719476736), u = o("plaintext", 0, 2 ** 36), l = o("nonce", 12, 12), g = o("ciphertext", 16, 2 ** 36 + 16);
|
|
4069
|
+
(0, y.abytes)(r, 16, 24, 32), l(i.length), a !== void 0 && A(a.length);
|
|
4070
|
+
function _() {
|
|
4071
|
+
const x = P(r), W = new Uint8Array(r.length), $ = new Uint8Array(16), ot = [x, W];
|
|
4072
|
+
let nt = i;
|
|
4073
|
+
(0, y.isAligned32)(nt) || ot.push(nt = (0, y.copyBytes)(nt));
|
|
4074
|
+
const st = (0, y.u32)(nt);
|
|
4075
|
+
let rt = 0, yt = st[0], ut = st[1], ct = st[2], et = 0;
|
|
4076
|
+
for (const J of [$, W].map(y.u32)) {
|
|
4077
|
+
const it = (0, y.u32)(J);
|
|
4078
|
+
for (let at = 0; at < it.length; at += 2) {
|
|
4079
|
+
const { s0: dt, s1: ft } = E(x, rt, yt, ut, ct);
|
|
4080
|
+
it[at + 0] = dt, it[at + 1] = ft, rt = ++et;
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
const tt = { authKey: $, encKey: P(W) };
|
|
4084
|
+
return (0, y.clean)(...ot), tt;
|
|
4085
|
+
}
|
|
4086
|
+
function C(x, W, $) {
|
|
4087
|
+
const ot = R(f.polyval, !0, W, $, a);
|
|
4088
|
+
for (let ct = 0; ct < 12; ct++)
|
|
4089
|
+
ot[ct] ^= i[ct];
|
|
4090
|
+
ot[15] &= 127;
|
|
4091
|
+
const nt = (0, y.u32)(ot);
|
|
4092
|
+
let st = nt[0], rt = nt[1], yt = nt[2], ut = nt[3];
|
|
4093
|
+
return { s0: st, s1: rt, s2: yt, s3: ut } = E(x, st, rt, yt, ut), nt[0] = st, nt[1] = rt, nt[2] = yt, nt[3] = ut, ot;
|
|
4094
|
+
}
|
|
4095
|
+
function h(x, W, $) {
|
|
4096
|
+
let ot = (0, y.copyBytes)(W);
|
|
4097
|
+
ot[15] |= 128;
|
|
4098
|
+
const nt = j(x, !0, ot, $);
|
|
4099
|
+
return (0, y.clean)(ot), nt;
|
|
4100
|
+
}
|
|
4101
|
+
return {
|
|
4102
|
+
encrypt(x) {
|
|
4103
|
+
u(x.length);
|
|
4104
|
+
const { encKey: W, authKey: $ } = _(), ot = C(W, $, x), nt = [W, $, ot];
|
|
4105
|
+
(0, y.isAligned32)(x) || nt.push(x = (0, y.copyBytes)(x));
|
|
4106
|
+
const st = new Uint8Array(x.length + 16);
|
|
4107
|
+
return st.set(ot, x.length), st.set(h(W, ot, x)), (0, y.clean)(...nt), st;
|
|
4108
|
+
},
|
|
4109
|
+
decrypt(x) {
|
|
4110
|
+
g(x.length);
|
|
4111
|
+
const W = x.subarray(-16), { encKey: $, authKey: ot } = _(), nt = [$, ot];
|
|
4112
|
+
(0, y.isAligned32)(x) || nt.push(x = (0, y.copyBytes)(x));
|
|
4113
|
+
const st = h($, W, x.subarray(0, -16)), rt = C($, ot, st);
|
|
4114
|
+
if (nt.push(rt), !(0, y.equalBytes)(W, rt))
|
|
4115
|
+
throw (0, y.clean)(...nt), new Error("invalid polyval tag");
|
|
4116
|
+
return (0, y.clean)(...nt), st;
|
|
4117
|
+
}
|
|
4118
|
+
};
|
|
4119
|
+
}), t.siv = t.gcmsiv;
|
|
4120
|
+
function p(n) {
|
|
4121
|
+
return n instanceof Uint32Array || ArrayBuffer.isView(n) && n.constructor.name === "Uint32Array";
|
|
4122
|
+
}
|
|
4123
|
+
function c(n, r) {
|
|
4124
|
+
if ((0, y.abytes)(r, 16), !p(n))
|
|
4125
|
+
throw new Error("_encryptBlock accepts result of expandKeyLE");
|
|
4126
|
+
const i = (0, y.u32)(r);
|
|
4127
|
+
let { s0: a, s1: b, s2: A, s3: u } = E(n, i[0], i[1], i[2], i[3]);
|
|
4128
|
+
return i[0] = a, i[1] = b, i[2] = A, i[3] = u, r;
|
|
4129
|
+
}
|
|
4130
|
+
function s(n, r) {
|
|
4131
|
+
if ((0, y.abytes)(r, 16), !p(n))
|
|
4132
|
+
throw new Error("_decryptBlock accepts result of expandKeyLE");
|
|
4133
|
+
const i = (0, y.u32)(r);
|
|
4134
|
+
let { s0: a, s1: b, s2: A, s3: u } = U(n, i[0], i[1], i[2], i[3]);
|
|
4135
|
+
return i[0] = a, i[1] = b, i[2] = A, i[3] = u, r;
|
|
4136
|
+
}
|
|
4137
|
+
const q = {
|
|
4138
|
+
/*
|
|
4139
|
+
High-level pseudocode:
|
|
4140
|
+
```
|
|
4141
|
+
A: u64 = IV
|
|
4142
|
+
out = []
|
|
4143
|
+
for (let i=0, ctr = 0; i<6; i++) {
|
|
4144
|
+
for (const chunk of chunks(plaintext, 8)) {
|
|
4145
|
+
A ^= swapEndianess(ctr++)
|
|
4146
|
+
[A, res] = chunks(encrypt(A || chunk), 8);
|
|
4147
|
+
out ||= res
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
out = A || out
|
|
4151
|
+
```
|
|
4152
|
+
Decrypt is the same, but reversed.
|
|
4153
|
+
*/
|
|
4154
|
+
encrypt(n, r) {
|
|
4155
|
+
if (r.length >= 2 ** 32)
|
|
4156
|
+
throw new Error("plaintext should be less than 4gb");
|
|
4157
|
+
const i = P(n);
|
|
4158
|
+
if (r.length === 16)
|
|
4159
|
+
c(i, r);
|
|
4160
|
+
else {
|
|
4161
|
+
const a = (0, y.u32)(r);
|
|
4162
|
+
let b = a[0], A = a[1];
|
|
4163
|
+
for (let u = 0, l = 1; u < 6; u++)
|
|
4164
|
+
for (let g = 2; g < a.length; g += 2, l++) {
|
|
4165
|
+
const { s0: _, s1: C, s2: h, s3: x } = E(i, b, A, a[g], a[g + 1]);
|
|
4166
|
+
b = _, A = C ^ B(l), a[g] = h, a[g + 1] = x;
|
|
4167
|
+
}
|
|
4168
|
+
a[0] = b, a[1] = A;
|
|
4169
|
+
}
|
|
4170
|
+
i.fill(0);
|
|
4171
|
+
},
|
|
4172
|
+
decrypt(n, r) {
|
|
4173
|
+
if (r.length - 8 >= 2 ** 32)
|
|
4174
|
+
throw new Error("ciphertext should be less than 4gb");
|
|
4175
|
+
const i = V(n), a = r.length / 8 - 1;
|
|
4176
|
+
if (a === 1)
|
|
4177
|
+
s(i, r);
|
|
4178
|
+
else {
|
|
4179
|
+
const b = (0, y.u32)(r);
|
|
4180
|
+
let A = b[0], u = b[1];
|
|
4181
|
+
for (let l = 0, g = a * 6; l < 6; l++)
|
|
4182
|
+
for (let _ = a * 2; _ >= 1; _ -= 2, g--) {
|
|
4183
|
+
u ^= B(g);
|
|
4184
|
+
const { s0: C, s1: h, s2: x, s3: W } = U(i, A, u, b[_], b[_ + 1]);
|
|
4185
|
+
A = C, u = h, b[_] = x, b[_ + 1] = W;
|
|
4186
|
+
}
|
|
4187
|
+
b[0] = A, b[1] = u;
|
|
4188
|
+
}
|
|
4189
|
+
i.fill(0);
|
|
4190
|
+
}
|
|
4191
|
+
}, K = /* @__PURE__ */ new Uint8Array(8).fill(166);
|
|
4192
|
+
t.aeskw = (0, y.wrapCipher)({ blockSize: 8 }, (n) => ({
|
|
4193
|
+
encrypt(r) {
|
|
4194
|
+
if (!r.length || r.length % 8 !== 0)
|
|
4195
|
+
throw new Error("invalid plaintext length");
|
|
4196
|
+
if (r.length === 8)
|
|
4197
|
+
throw new Error("8-byte keys not allowed in AESKW, use AESKWP instead");
|
|
4198
|
+
const i = (0, y.concatBytes)(K, r);
|
|
4199
|
+
return q.encrypt(n, i), i;
|
|
4200
|
+
},
|
|
4201
|
+
decrypt(r) {
|
|
4202
|
+
if (r.length % 8 !== 0 || r.length < 24)
|
|
4203
|
+
throw new Error("invalid ciphertext length");
|
|
4204
|
+
const i = (0, y.copyBytes)(r);
|
|
4205
|
+
if (q.decrypt(n, i), !(0, y.equalBytes)(i.subarray(0, 8), K))
|
|
4206
|
+
throw new Error("integrity check failed");
|
|
4207
|
+
return i.subarray(0, 8).fill(0), i.subarray(8);
|
|
4208
|
+
}
|
|
4209
|
+
}));
|
|
4210
|
+
const e = 2790873510;
|
|
4211
|
+
t.aeskwp = (0, y.wrapCipher)({ blockSize: 8 }, (n) => ({
|
|
4212
|
+
encrypt(r) {
|
|
4213
|
+
if (!r.length)
|
|
4214
|
+
throw new Error("invalid plaintext length");
|
|
4215
|
+
const i = Math.ceil(r.length / 8) * 8, a = new Uint8Array(8 + i);
|
|
4216
|
+
a.set(r, 8);
|
|
4217
|
+
const b = (0, y.u32)(a);
|
|
4218
|
+
return b[0] = e, b[1] = B(r.length), q.encrypt(n, a), a;
|
|
4219
|
+
},
|
|
4220
|
+
decrypt(r) {
|
|
4221
|
+
if (r.length < 16)
|
|
4222
|
+
throw new Error("invalid ciphertext length");
|
|
4223
|
+
const i = (0, y.copyBytes)(r), a = (0, y.u32)(i);
|
|
4224
|
+
q.decrypt(n, i);
|
|
4225
|
+
const b = B(a[1]) >>> 0, A = Math.ceil(b / 8) * 8;
|
|
4226
|
+
if (a[0] !== e || i.length - 8 !== A)
|
|
4227
|
+
throw new Error("integrity check failed");
|
|
4228
|
+
for (let u = b; u < A; u++)
|
|
4229
|
+
if (i[8 + u] !== 0)
|
|
4230
|
+
throw new Error("integrity check failed");
|
|
4231
|
+
return i.subarray(0, 8).fill(0), i.subarray(8, 8 + b);
|
|
4232
|
+
}
|
|
4233
|
+
})), t.unsafe = {
|
|
4234
|
+
expandKeyLE: P,
|
|
4235
|
+
expandKeyDecLE: V,
|
|
4236
|
+
encrypt: E,
|
|
4237
|
+
decrypt: U,
|
|
4238
|
+
encryptBlock: c,
|
|
4239
|
+
decryptBlock: s,
|
|
4240
|
+
ctrCounter: Z,
|
|
4241
|
+
ctr32: j
|
|
4242
|
+
};
|
|
4243
|
+
})(fe)), fe;
|
|
4244
|
+
}
|
|
4245
|
+
var je;
|
|
4246
|
+
function En() {
|
|
4247
|
+
if (je) return Pt;
|
|
4248
|
+
je = 1, Object.defineProperty(Pt, "__esModule", { value: !0 }), Pt.aes256cbc = Pt.aes256gcm = void 0;
|
|
4249
|
+
const t = /* @__PURE__ */ vn(), f = (S, H, m) => (0, t.gcm)(S, H, m);
|
|
4250
|
+
Pt.aes256gcm = f;
|
|
4251
|
+
const y = (S, H, m) => (0, t.cbc)(S, H);
|
|
4252
|
+
return Pt.aes256cbc = y, Pt;
|
|
4253
|
+
}
|
|
4254
|
+
var Nt = {}, ue = {}, Zt = {}, De;
|
|
4255
|
+
function Bn() {
|
|
4256
|
+
if (De) return Zt;
|
|
4257
|
+
De = 1, Object.defineProperty(Zt, "__esModule", { value: !0 }), Zt.rotl = I, Zt.createCipher = B;
|
|
4258
|
+
const t = /* @__PURE__ */ Ht(), f = (d) => Uint8Array.from(d.split("").map((w) => w.charCodeAt(0))), y = f("expand 16-byte k"), S = f("expand 32-byte k"), H = (0, t.u32)(y), m = (0, t.u32)(S);
|
|
4259
|
+
function I(d, w) {
|
|
4260
|
+
return d << w | d >>> 32 - w;
|
|
4261
|
+
}
|
|
4262
|
+
function D(d) {
|
|
4263
|
+
return d.byteOffset % 4 === 0;
|
|
4264
|
+
}
|
|
4265
|
+
const F = 64, G = 16, Y = 2 ** 32 - 1, L = new Uint32Array();
|
|
4266
|
+
function M(d, w, v, T, P, V, k, O) {
|
|
4267
|
+
const E = P.length, U = new Uint8Array(F), Z = (0, t.u32)(U), j = D(P) && D(V), z = j ? (0, t.u32)(P) : L, Q = j ? (0, t.u32)(V) : L;
|
|
4268
|
+
for (let X = 0; X < E; k++) {
|
|
4269
|
+
if (d(w, v, T, Z, k, O), k >= Y)
|
|
4270
|
+
throw new Error("arx: counter overflow");
|
|
4271
|
+
const N = Math.min(F, E - X);
|
|
4272
|
+
if (j && N === F) {
|
|
4273
|
+
const R = X / 4;
|
|
4274
|
+
if (X % 4 !== 0)
|
|
4275
|
+
throw new Error("arx: invalid block position");
|
|
4276
|
+
for (let o = 0, p; o < G; o++)
|
|
4277
|
+
p = R + o, Q[p] = z[p] ^ Z[o];
|
|
4278
|
+
X += F;
|
|
4279
|
+
continue;
|
|
4280
|
+
}
|
|
4281
|
+
for (let R = 0, o; R < N; R++)
|
|
4282
|
+
o = X + R, V[o] = P[o] ^ U[R];
|
|
4283
|
+
X += N;
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
function B(d, w) {
|
|
4287
|
+
const { allowShortKeys: v, extendNonceFn: T, counterLength: P, counterRight: V, rounds: k } = (0, t.checkOpts)({ allowShortKeys: !1, counterLength: 8, counterRight: !1, rounds: 20 }, w);
|
|
4288
|
+
if (typeof d != "function")
|
|
4289
|
+
throw new Error("core must be a function");
|
|
4290
|
+
return (0, t.anumber)(P), (0, t.anumber)(k), (0, t.abool)(V), (0, t.abool)(v), (O, E, U, Z, j = 0) => {
|
|
4291
|
+
(0, t.abytes)(O), (0, t.abytes)(E), (0, t.abytes)(U);
|
|
4292
|
+
const z = U.length;
|
|
4293
|
+
if (Z === void 0 && (Z = new Uint8Array(z)), (0, t.abytes)(Z), (0, t.anumber)(j), j < 0 || j >= Y)
|
|
4294
|
+
throw new Error("arx: counter overflow");
|
|
4295
|
+
if (Z.length < z)
|
|
4296
|
+
throw new Error(`arx: output (${Z.length}) is shorter than data (${z})`);
|
|
4297
|
+
const Q = [];
|
|
4298
|
+
let X = O.length, N, R;
|
|
4299
|
+
if (X === 32)
|
|
4300
|
+
Q.push(N = (0, t.copyBytes)(O)), R = m;
|
|
4301
|
+
else if (X === 16 && v)
|
|
4302
|
+
N = new Uint8Array(32), N.set(O), N.set(O, 16), R = H, Q.push(N);
|
|
4303
|
+
else
|
|
4304
|
+
throw new Error(`arx: invalid 32-byte key, got length=${X}`);
|
|
4305
|
+
D(E) || Q.push(E = (0, t.copyBytes)(E));
|
|
4306
|
+
const o = (0, t.u32)(N);
|
|
4307
|
+
if (T) {
|
|
4308
|
+
if (E.length !== 24)
|
|
4309
|
+
throw new Error("arx: extended nonce must be 24 bytes");
|
|
4310
|
+
T(R, o, (0, t.u32)(E.subarray(0, 16)), o), E = E.subarray(16);
|
|
4311
|
+
}
|
|
4312
|
+
const p = 16 - P;
|
|
4313
|
+
if (p !== E.length)
|
|
4314
|
+
throw new Error(`arx: nonce must be ${p} or 16 bytes`);
|
|
4315
|
+
if (p !== 12) {
|
|
4316
|
+
const s = new Uint8Array(12);
|
|
4317
|
+
s.set(E, V ? 0 : 12 - E.length), E = s, Q.push(E);
|
|
4318
|
+
}
|
|
4319
|
+
const c = (0, t.u32)(E);
|
|
4320
|
+
return M(d, R, o, c, U, Z, j, k), (0, t.clean)(...Q), Z;
|
|
4321
|
+
};
|
|
4322
|
+
}
|
|
4323
|
+
return Zt;
|
|
4324
|
+
}
|
|
4325
|
+
var Mt = {}, Ze;
|
|
4326
|
+
function Sn() {
|
|
4327
|
+
if (Ze) return Mt;
|
|
4328
|
+
Ze = 1, Object.defineProperty(Mt, "__esModule", { value: !0 }), Mt.poly1305 = void 0, Mt.wrapConstructorWithKey = S;
|
|
4329
|
+
const t = /* @__PURE__ */ Ht(), f = (H, m) => H[m++] & 255 | (H[m++] & 255) << 8;
|
|
4330
|
+
class y {
|
|
4331
|
+
constructor(m) {
|
|
4332
|
+
this.blockLen = 16, this.outputLen = 16, this.buffer = new Uint8Array(16), this.r = new Uint16Array(10), this.h = new Uint16Array(10), this.pad = new Uint16Array(8), this.pos = 0, this.finished = !1, m = (0, t.toBytes)(m), (0, t.abytes)(m, 32);
|
|
4333
|
+
const I = f(m, 0), D = f(m, 2), F = f(m, 4), G = f(m, 6), Y = f(m, 8), L = f(m, 10), M = f(m, 12), B = f(m, 14);
|
|
4334
|
+
this.r[0] = I & 8191, this.r[1] = (I >>> 13 | D << 3) & 8191, this.r[2] = (D >>> 10 | F << 6) & 7939, this.r[3] = (F >>> 7 | G << 9) & 8191, this.r[4] = (G >>> 4 | Y << 12) & 255, this.r[5] = Y >>> 1 & 8190, this.r[6] = (Y >>> 14 | L << 2) & 8191, this.r[7] = (L >>> 11 | M << 5) & 8065, this.r[8] = (M >>> 8 | B << 8) & 8191, this.r[9] = B >>> 5 & 127;
|
|
4335
|
+
for (let d = 0; d < 8; d++)
|
|
4336
|
+
this.pad[d] = f(m, 16 + 2 * d);
|
|
4337
|
+
}
|
|
4338
|
+
process(m, I, D = !1) {
|
|
4339
|
+
const F = D ? 0 : 2048, { h: G, r: Y } = this, L = Y[0], M = Y[1], B = Y[2], d = Y[3], w = Y[4], v = Y[5], T = Y[6], P = Y[7], V = Y[8], k = Y[9], O = f(m, I + 0), E = f(m, I + 2), U = f(m, I + 4), Z = f(m, I + 6), j = f(m, I + 8), z = f(m, I + 10), Q = f(m, I + 12), X = f(m, I + 14);
|
|
4340
|
+
let N = G[0] + (O & 8191), R = G[1] + ((O >>> 13 | E << 3) & 8191), o = G[2] + ((E >>> 10 | U << 6) & 8191), p = G[3] + ((U >>> 7 | Z << 9) & 8191), c = G[4] + ((Z >>> 4 | j << 12) & 8191), s = G[5] + (j >>> 1 & 8191), q = G[6] + ((j >>> 14 | z << 2) & 8191), K = G[7] + ((z >>> 11 | Q << 5) & 8191), e = G[8] + ((Q >>> 8 | X << 8) & 8191), n = G[9] + (X >>> 5 | F), r = 0, i = r + N * L + R * (5 * k) + o * (5 * V) + p * (5 * P) + c * (5 * T);
|
|
4341
|
+
r = i >>> 13, i &= 8191, i += s * (5 * v) + q * (5 * w) + K * (5 * d) + e * (5 * B) + n * (5 * M), r += i >>> 13, i &= 8191;
|
|
4342
|
+
let a = r + N * M + R * L + o * (5 * k) + p * (5 * V) + c * (5 * P);
|
|
4343
|
+
r = a >>> 13, a &= 8191, a += s * (5 * T) + q * (5 * v) + K * (5 * w) + e * (5 * d) + n * (5 * B), r += a >>> 13, a &= 8191;
|
|
4344
|
+
let b = r + N * B + R * M + o * L + p * (5 * k) + c * (5 * V);
|
|
4345
|
+
r = b >>> 13, b &= 8191, b += s * (5 * P) + q * (5 * T) + K * (5 * v) + e * (5 * w) + n * (5 * d), r += b >>> 13, b &= 8191;
|
|
4346
|
+
let A = r + N * d + R * B + o * M + p * L + c * (5 * k);
|
|
4347
|
+
r = A >>> 13, A &= 8191, A += s * (5 * V) + q * (5 * P) + K * (5 * T) + e * (5 * v) + n * (5 * w), r += A >>> 13, A &= 8191;
|
|
4348
|
+
let u = r + N * w + R * d + o * B + p * M + c * L;
|
|
4349
|
+
r = u >>> 13, u &= 8191, u += s * (5 * k) + q * (5 * V) + K * (5 * P) + e * (5 * T) + n * (5 * v), r += u >>> 13, u &= 8191;
|
|
4350
|
+
let l = r + N * v + R * w + o * d + p * B + c * M;
|
|
4351
|
+
r = l >>> 13, l &= 8191, l += s * L + q * (5 * k) + K * (5 * V) + e * (5 * P) + n * (5 * T), r += l >>> 13, l &= 8191;
|
|
4352
|
+
let g = r + N * T + R * v + o * w + p * d + c * B;
|
|
4353
|
+
r = g >>> 13, g &= 8191, g += s * M + q * L + K * (5 * k) + e * (5 * V) + n * (5 * P), r += g >>> 13, g &= 8191;
|
|
4354
|
+
let _ = r + N * P + R * T + o * v + p * w + c * d;
|
|
4355
|
+
r = _ >>> 13, _ &= 8191, _ += s * B + q * M + K * L + e * (5 * k) + n * (5 * V), r += _ >>> 13, _ &= 8191;
|
|
4356
|
+
let C = r + N * V + R * P + o * T + p * v + c * w;
|
|
4357
|
+
r = C >>> 13, C &= 8191, C += s * d + q * B + K * M + e * L + n * (5 * k), r += C >>> 13, C &= 8191;
|
|
4358
|
+
let h = r + N * k + R * V + o * P + p * T + c * v;
|
|
4359
|
+
r = h >>> 13, h &= 8191, h += s * w + q * d + K * B + e * M + n * L, r += h >>> 13, h &= 8191, r = (r << 2) + r | 0, r = r + i | 0, i = r & 8191, r = r >>> 13, a += r, G[0] = i, G[1] = a, G[2] = b, G[3] = A, G[4] = u, G[5] = l, G[6] = g, G[7] = _, G[8] = C, G[9] = h;
|
|
4360
|
+
}
|
|
4361
|
+
finalize() {
|
|
4362
|
+
const { h: m, pad: I } = this, D = new Uint16Array(10);
|
|
4363
|
+
let F = m[1] >>> 13;
|
|
4364
|
+
m[1] &= 8191;
|
|
4365
|
+
for (let L = 2; L < 10; L++)
|
|
4366
|
+
m[L] += F, F = m[L] >>> 13, m[L] &= 8191;
|
|
4367
|
+
m[0] += F * 5, F = m[0] >>> 13, m[0] &= 8191, m[1] += F, F = m[1] >>> 13, m[1] &= 8191, m[2] += F, D[0] = m[0] + 5, F = D[0] >>> 13, D[0] &= 8191;
|
|
4368
|
+
for (let L = 1; L < 10; L++)
|
|
4369
|
+
D[L] = m[L] + F, F = D[L] >>> 13, D[L] &= 8191;
|
|
4370
|
+
D[9] -= 8192;
|
|
4371
|
+
let G = (F ^ 1) - 1;
|
|
4372
|
+
for (let L = 0; L < 10; L++)
|
|
4373
|
+
D[L] &= G;
|
|
4374
|
+
G = ~G;
|
|
4375
|
+
for (let L = 0; L < 10; L++)
|
|
4376
|
+
m[L] = m[L] & G | D[L];
|
|
4377
|
+
m[0] = (m[0] | m[1] << 13) & 65535, m[1] = (m[1] >>> 3 | m[2] << 10) & 65535, m[2] = (m[2] >>> 6 | m[3] << 7) & 65535, m[3] = (m[3] >>> 9 | m[4] << 4) & 65535, m[4] = (m[4] >>> 12 | m[5] << 1 | m[6] << 14) & 65535, m[5] = (m[6] >>> 2 | m[7] << 11) & 65535, m[6] = (m[7] >>> 5 | m[8] << 8) & 65535, m[7] = (m[8] >>> 8 | m[9] << 5) & 65535;
|
|
4378
|
+
let Y = m[0] + I[0];
|
|
4379
|
+
m[0] = Y & 65535;
|
|
4380
|
+
for (let L = 1; L < 8; L++)
|
|
4381
|
+
Y = (m[L] + I[L] | 0) + (Y >>> 16) | 0, m[L] = Y & 65535;
|
|
4382
|
+
(0, t.clean)(D);
|
|
4383
|
+
}
|
|
4384
|
+
update(m) {
|
|
4385
|
+
(0, t.aexists)(this), m = (0, t.toBytes)(m), (0, t.abytes)(m);
|
|
4386
|
+
const { buffer: I, blockLen: D } = this, F = m.length;
|
|
4387
|
+
for (let G = 0; G < F; ) {
|
|
4388
|
+
const Y = Math.min(D - this.pos, F - G);
|
|
4389
|
+
if (Y === D) {
|
|
4390
|
+
for (; D <= F - G; G += D)
|
|
4391
|
+
this.process(m, G);
|
|
4392
|
+
continue;
|
|
4393
|
+
}
|
|
4394
|
+
I.set(m.subarray(G, G + Y), this.pos), this.pos += Y, G += Y, this.pos === D && (this.process(I, 0, !1), this.pos = 0);
|
|
4395
|
+
}
|
|
4396
|
+
return this;
|
|
4397
|
+
}
|
|
4398
|
+
destroy() {
|
|
4399
|
+
(0, t.clean)(this.h, this.r, this.buffer, this.pad);
|
|
4400
|
+
}
|
|
4401
|
+
digestInto(m) {
|
|
4402
|
+
(0, t.aexists)(this), (0, t.aoutput)(m, this), this.finished = !0;
|
|
4403
|
+
const { buffer: I, h: D } = this;
|
|
4404
|
+
let { pos: F } = this;
|
|
4405
|
+
if (F) {
|
|
4406
|
+
for (I[F++] = 1; F < 16; F++)
|
|
4407
|
+
I[F] = 0;
|
|
4408
|
+
this.process(I, 0, !0);
|
|
4409
|
+
}
|
|
4410
|
+
this.finalize();
|
|
4411
|
+
let G = 0;
|
|
4412
|
+
for (let Y = 0; Y < 8; Y++)
|
|
4413
|
+
m[G++] = D[Y] >>> 0, m[G++] = D[Y] >>> 8;
|
|
4414
|
+
return m;
|
|
4415
|
+
}
|
|
4416
|
+
digest() {
|
|
4417
|
+
const { buffer: m, outputLen: I } = this;
|
|
4418
|
+
this.digestInto(m);
|
|
4419
|
+
const D = m.slice(0, I);
|
|
4420
|
+
return this.destroy(), D;
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
function S(H) {
|
|
4424
|
+
const m = (D, F) => H(F).update((0, t.toBytes)(D)).digest(), I = H(new Uint8Array(32));
|
|
4425
|
+
return m.outputLen = I.outputLen, m.blockLen = I.blockLen, m.create = (D) => H(D), m;
|
|
4426
|
+
}
|
|
4427
|
+
return Mt.poly1305 = S((H) => new y(H)), Mt;
|
|
4428
|
+
}
|
|
4429
|
+
var Ge;
|
|
4430
|
+
function xn() {
|
|
4431
|
+
return Ge || (Ge = 1, (function(t) {
|
|
4432
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.xchacha20poly1305 = t.chacha20poly1305 = t._poly1305_aead = t.chacha12 = t.chacha8 = t.xchacha20 = t.chacha20 = t.chacha20orig = void 0, t.hchacha = m;
|
|
4433
|
+
const f = /* @__PURE__ */ Bn(), y = /* @__PURE__ */ Sn(), S = /* @__PURE__ */ Ht();
|
|
4434
|
+
function H(L, M, B, d, w, v = 20) {
|
|
4435
|
+
let T = L[0], P = L[1], V = L[2], k = L[3], O = M[0], E = M[1], U = M[2], Z = M[3], j = M[4], z = M[5], Q = M[6], X = M[7], N = w, R = B[0], o = B[1], p = B[2], c = T, s = P, q = V, K = k, e = O, n = E, r = U, i = Z, a = j, b = z, A = Q, u = X, l = N, g = R, _ = o, C = p;
|
|
4436
|
+
for (let x = 0; x < v; x += 2)
|
|
4437
|
+
c = c + e | 0, l = (0, f.rotl)(l ^ c, 16), a = a + l | 0, e = (0, f.rotl)(e ^ a, 12), c = c + e | 0, l = (0, f.rotl)(l ^ c, 8), a = a + l | 0, e = (0, f.rotl)(e ^ a, 7), s = s + n | 0, g = (0, f.rotl)(g ^ s, 16), b = b + g | 0, n = (0, f.rotl)(n ^ b, 12), s = s + n | 0, g = (0, f.rotl)(g ^ s, 8), b = b + g | 0, n = (0, f.rotl)(n ^ b, 7), q = q + r | 0, _ = (0, f.rotl)(_ ^ q, 16), A = A + _ | 0, r = (0, f.rotl)(r ^ A, 12), q = q + r | 0, _ = (0, f.rotl)(_ ^ q, 8), A = A + _ | 0, r = (0, f.rotl)(r ^ A, 7), K = K + i | 0, C = (0, f.rotl)(C ^ K, 16), u = u + C | 0, i = (0, f.rotl)(i ^ u, 12), K = K + i | 0, C = (0, f.rotl)(C ^ K, 8), u = u + C | 0, i = (0, f.rotl)(i ^ u, 7), c = c + n | 0, C = (0, f.rotl)(C ^ c, 16), A = A + C | 0, n = (0, f.rotl)(n ^ A, 12), c = c + n | 0, C = (0, f.rotl)(C ^ c, 8), A = A + C | 0, n = (0, f.rotl)(n ^ A, 7), s = s + r | 0, l = (0, f.rotl)(l ^ s, 16), u = u + l | 0, r = (0, f.rotl)(r ^ u, 12), s = s + r | 0, l = (0, f.rotl)(l ^ s, 8), u = u + l | 0, r = (0, f.rotl)(r ^ u, 7), q = q + i | 0, g = (0, f.rotl)(g ^ q, 16), a = a + g | 0, i = (0, f.rotl)(i ^ a, 12), q = q + i | 0, g = (0, f.rotl)(g ^ q, 8), a = a + g | 0, i = (0, f.rotl)(i ^ a, 7), K = K + e | 0, _ = (0, f.rotl)(_ ^ K, 16), b = b + _ | 0, e = (0, f.rotl)(e ^ b, 12), K = K + e | 0, _ = (0, f.rotl)(_ ^ K, 8), b = b + _ | 0, e = (0, f.rotl)(e ^ b, 7);
|
|
4438
|
+
let h = 0;
|
|
4439
|
+
d[h++] = T + c | 0, d[h++] = P + s | 0, d[h++] = V + q | 0, d[h++] = k + K | 0, d[h++] = O + e | 0, d[h++] = E + n | 0, d[h++] = U + r | 0, d[h++] = Z + i | 0, d[h++] = j + a | 0, d[h++] = z + b | 0, d[h++] = Q + A | 0, d[h++] = X + u | 0, d[h++] = N + l | 0, d[h++] = R + g | 0, d[h++] = o + _ | 0, d[h++] = p + C | 0;
|
|
4440
|
+
}
|
|
4441
|
+
function m(L, M, B, d) {
|
|
4442
|
+
let w = L[0], v = L[1], T = L[2], P = L[3], V = M[0], k = M[1], O = M[2], E = M[3], U = M[4], Z = M[5], j = M[6], z = M[7], Q = B[0], X = B[1], N = B[2], R = B[3];
|
|
4443
|
+
for (let p = 0; p < 20; p += 2)
|
|
4444
|
+
w = w + V | 0, Q = (0, f.rotl)(Q ^ w, 16), U = U + Q | 0, V = (0, f.rotl)(V ^ U, 12), w = w + V | 0, Q = (0, f.rotl)(Q ^ w, 8), U = U + Q | 0, V = (0, f.rotl)(V ^ U, 7), v = v + k | 0, X = (0, f.rotl)(X ^ v, 16), Z = Z + X | 0, k = (0, f.rotl)(k ^ Z, 12), v = v + k | 0, X = (0, f.rotl)(X ^ v, 8), Z = Z + X | 0, k = (0, f.rotl)(k ^ Z, 7), T = T + O | 0, N = (0, f.rotl)(N ^ T, 16), j = j + N | 0, O = (0, f.rotl)(O ^ j, 12), T = T + O | 0, N = (0, f.rotl)(N ^ T, 8), j = j + N | 0, O = (0, f.rotl)(O ^ j, 7), P = P + E | 0, R = (0, f.rotl)(R ^ P, 16), z = z + R | 0, E = (0, f.rotl)(E ^ z, 12), P = P + E | 0, R = (0, f.rotl)(R ^ P, 8), z = z + R | 0, E = (0, f.rotl)(E ^ z, 7), w = w + k | 0, R = (0, f.rotl)(R ^ w, 16), j = j + R | 0, k = (0, f.rotl)(k ^ j, 12), w = w + k | 0, R = (0, f.rotl)(R ^ w, 8), j = j + R | 0, k = (0, f.rotl)(k ^ j, 7), v = v + O | 0, Q = (0, f.rotl)(Q ^ v, 16), z = z + Q | 0, O = (0, f.rotl)(O ^ z, 12), v = v + O | 0, Q = (0, f.rotl)(Q ^ v, 8), z = z + Q | 0, O = (0, f.rotl)(O ^ z, 7), T = T + E | 0, X = (0, f.rotl)(X ^ T, 16), U = U + X | 0, E = (0, f.rotl)(E ^ U, 12), T = T + E | 0, X = (0, f.rotl)(X ^ T, 8), U = U + X | 0, E = (0, f.rotl)(E ^ U, 7), P = P + V | 0, N = (0, f.rotl)(N ^ P, 16), Z = Z + N | 0, V = (0, f.rotl)(V ^ Z, 12), P = P + V | 0, N = (0, f.rotl)(N ^ P, 8), Z = Z + N | 0, V = (0, f.rotl)(V ^ Z, 7);
|
|
4445
|
+
let o = 0;
|
|
4446
|
+
d[o++] = w, d[o++] = v, d[o++] = T, d[o++] = P, d[o++] = Q, d[o++] = X, d[o++] = N, d[o++] = R;
|
|
4447
|
+
}
|
|
4448
|
+
t.chacha20orig = (0, f.createCipher)(H, {
|
|
4449
|
+
counterRight: !1,
|
|
4450
|
+
counterLength: 8,
|
|
4451
|
+
allowShortKeys: !0
|
|
4452
|
+
}), t.chacha20 = (0, f.createCipher)(H, {
|
|
4453
|
+
counterRight: !1,
|
|
4454
|
+
counterLength: 4,
|
|
4455
|
+
allowShortKeys: !1
|
|
4456
|
+
}), t.xchacha20 = (0, f.createCipher)(H, {
|
|
4457
|
+
counterRight: !1,
|
|
4458
|
+
counterLength: 8,
|
|
4459
|
+
extendNonceFn: m,
|
|
4460
|
+
allowShortKeys: !1
|
|
4461
|
+
}), t.chacha8 = (0, f.createCipher)(H, {
|
|
4462
|
+
counterRight: !1,
|
|
4463
|
+
counterLength: 4,
|
|
4464
|
+
rounds: 8
|
|
4465
|
+
}), t.chacha12 = (0, f.createCipher)(H, {
|
|
4466
|
+
counterRight: !1,
|
|
4467
|
+
counterLength: 4,
|
|
4468
|
+
rounds: 12
|
|
4469
|
+
});
|
|
4470
|
+
const I = /* @__PURE__ */ new Uint8Array(16), D = (L, M) => {
|
|
4471
|
+
L.update(M);
|
|
4472
|
+
const B = M.length % 16;
|
|
4473
|
+
B && L.update(I.subarray(B));
|
|
4474
|
+
}, F = /* @__PURE__ */ new Uint8Array(32);
|
|
4475
|
+
function G(L, M, B, d, w) {
|
|
4476
|
+
const v = L(M, B, F), T = y.poly1305.create(v);
|
|
4477
|
+
w && D(T, w), D(T, d);
|
|
4478
|
+
const P = (0, S.u64Lengths)(d.length, w ? w.length : 0, !0);
|
|
4479
|
+
T.update(P);
|
|
4480
|
+
const V = T.digest();
|
|
4481
|
+
return (0, S.clean)(v, P), V;
|
|
4482
|
+
}
|
|
4483
|
+
const Y = (L) => (M, B, d) => ({
|
|
4484
|
+
encrypt(v, T) {
|
|
4485
|
+
const P = v.length;
|
|
4486
|
+
T = (0, S.getOutput)(P + 16, T, !1), T.set(v);
|
|
4487
|
+
const V = T.subarray(0, -16);
|
|
4488
|
+
L(M, B, V, V, 1);
|
|
4489
|
+
const k = G(L, M, B, V, d);
|
|
4490
|
+
return T.set(k, P), (0, S.clean)(k), T;
|
|
4491
|
+
},
|
|
4492
|
+
decrypt(v, T) {
|
|
4493
|
+
T = (0, S.getOutput)(v.length - 16, T, !1);
|
|
4494
|
+
const P = v.subarray(0, -16), V = v.subarray(-16), k = G(L, M, B, P, d);
|
|
4495
|
+
if (!(0, S.equalBytes)(V, k))
|
|
4496
|
+
throw new Error("invalid tag");
|
|
4497
|
+
return T.set(v.subarray(0, -16)), L(M, B, T, T, 1), (0, S.clean)(k), T;
|
|
4498
|
+
}
|
|
4499
|
+
});
|
|
4500
|
+
t._poly1305_aead = Y, t.chacha20poly1305 = (0, S.wrapCipher)({ blockSize: 64, nonceLength: 12, tagLength: 16 }, (0, t._poly1305_aead)(t.chacha20)), t.xchacha20poly1305 = (0, S.wrapCipher)({ blockSize: 64, nonceLength: 24, tagLength: 16 }, (0, t._poly1305_aead)(t.xchacha20));
|
|
4501
|
+
})(ue)), ue;
|
|
4502
|
+
}
|
|
4503
|
+
var ke;
|
|
4504
|
+
function An() {
|
|
4505
|
+
if (ke) return Nt;
|
|
4506
|
+
ke = 1, Object.defineProperty(Nt, "__esModule", { value: !0 }), Nt.chacha20 = Nt.xchacha20 = void 0;
|
|
4507
|
+
const t = /* @__PURE__ */ xn(), f = (S, H, m) => (0, t.xchacha20poly1305)(S, H, m);
|
|
4508
|
+
Nt.xchacha20 = f;
|
|
4509
|
+
const y = (S, H, m) => (0, t.chacha20poly1305)(S, H, m);
|
|
4510
|
+
return Nt.chacha20 = y, Nt;
|
|
4511
|
+
}
|
|
4512
|
+
var Ye;
|
|
4513
|
+
function In() {
|
|
4514
|
+
return Ye || (Ye = 1, (function(t) {
|
|
4515
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.aesDecrypt = t.aesEncrypt = t.symDecrypt = t.symEncrypt = void 0;
|
|
4516
|
+
var f = En(), y = An(), S = /* @__PURE__ */ Ht(), H = /* @__PURE__ */ Je(), m = zt(), I = le(), D = function(M, B, d) {
|
|
4517
|
+
return G(Y, m.ECIES_CONFIG.symmetricAlgorithm, m.ECIES_CONFIG.symmetricNonceLength, M, B, d);
|
|
4518
|
+
};
|
|
4519
|
+
t.symEncrypt = D;
|
|
4520
|
+
var F = function(M, B, d) {
|
|
4521
|
+
return G(L, m.ECIES_CONFIG.symmetricAlgorithm, m.ECIES_CONFIG.symmetricNonceLength, M, B, d);
|
|
4522
|
+
};
|
|
4523
|
+
t.symDecrypt = F, t.aesEncrypt = t.symEncrypt, t.aesDecrypt = t.symDecrypt;
|
|
4524
|
+
function G(M, B, d, w, v, T) {
|
|
4525
|
+
if (B === "aes-256-gcm")
|
|
4526
|
+
return M(f.aes256gcm, w, v, d, I.AEAD_TAG_LENGTH, T);
|
|
4527
|
+
if (B === "xchacha20")
|
|
4528
|
+
return M(y.xchacha20, w, v, I.XCHACHA20_NONCE_LENGTH, I.AEAD_TAG_LENGTH, T);
|
|
4529
|
+
if (B === "aes-256-cbc")
|
|
4530
|
+
return M(f.aes256cbc, w, v, 16, 0);
|
|
4531
|
+
throw new Error("Not implemented");
|
|
4532
|
+
}
|
|
4533
|
+
function Y(M, B, d, w, v, T) {
|
|
4534
|
+
var P = (0, H.randomBytes)(w), V = M(B, P, T), k = V.encrypt(d);
|
|
4535
|
+
if (v === 0)
|
|
4536
|
+
return (0, S.concatBytes)(P, k);
|
|
4537
|
+
var O = k.length - v, E = k.subarray(0, O), U = k.subarray(O);
|
|
4538
|
+
return (0, S.concatBytes)(P, U, E);
|
|
4539
|
+
}
|
|
4540
|
+
function L(M, B, d, w, v, T) {
|
|
4541
|
+
var P = d.subarray(0, w), V = M(B, Uint8Array.from(P), T), k = d.subarray(w);
|
|
4542
|
+
if (v === 0)
|
|
4543
|
+
return V.decrypt(k);
|
|
4544
|
+
var O = k.subarray(0, v), E = k.subarray(v);
|
|
4545
|
+
return V.decrypt((0, S.concatBytes)(E, O));
|
|
4546
|
+
}
|
|
4547
|
+
})(ae)), ae;
|
|
4548
|
+
}
|
|
4549
|
+
var ze;
|
|
4550
|
+
function ye() {
|
|
4551
|
+
return ze || (ze = 1, (function(t) {
|
|
4552
|
+
var f = Rt && Rt.__createBinding || (Object.create ? (function(S, H, m, I) {
|
|
4553
|
+
I === void 0 && (I = m);
|
|
4554
|
+
var D = Object.getOwnPropertyDescriptor(H, m);
|
|
4555
|
+
(!D || ("get" in D ? !H.__esModule : D.writable || D.configurable)) && (D = { enumerable: !0, get: function() {
|
|
4556
|
+
return H[m];
|
|
4557
|
+
} }), Object.defineProperty(S, I, D);
|
|
4558
|
+
}) : (function(S, H, m, I) {
|
|
4559
|
+
I === void 0 && (I = m), S[I] = H[m];
|
|
4560
|
+
})), y = Rt && Rt.__exportStar || function(S, H) {
|
|
4561
|
+
for (var m in S) m !== "default" && !Object.prototype.hasOwnProperty.call(H, m) && f(H, S, m);
|
|
4562
|
+
};
|
|
4563
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), y(mn(), t), y(_n(), t), y(rn(), t), y(In(), t);
|
|
4564
|
+
})(Rt)), Rt;
|
|
4565
|
+
}
|
|
4566
|
+
var Gt = {}, Xe;
|
|
4567
|
+
function on() {
|
|
4568
|
+
if (Xe) return Gt;
|
|
4569
|
+
Xe = 1, Object.defineProperty(Gt, "__esModule", { value: !0 }), Gt.PublicKey = void 0;
|
|
4570
|
+
var t = /* @__PURE__ */ Ht(), f = ye(), y = (
|
|
4571
|
+
/** @class */
|
|
4572
|
+
(function() {
|
|
4573
|
+
function S(H, m) {
|
|
4574
|
+
var I = (0, f.convertPublicKeyFormat)(H, !0, m), D = (0, f.convertPublicKeyFormat)(H, !1, m);
|
|
4575
|
+
this.data = I, this.dataUncompressed = I.length !== D.length ? D : null;
|
|
4576
|
+
}
|
|
4577
|
+
return S.fromHex = function(H, m) {
|
|
4578
|
+
return new S((0, f.hexToPublicKey)(H, m), m);
|
|
4579
|
+
}, Object.defineProperty(S.prototype, "_uncompressed", {
|
|
4580
|
+
get: function() {
|
|
4581
|
+
return this.dataUncompressed !== null ? this.dataUncompressed : this.data;
|
|
4582
|
+
},
|
|
4583
|
+
enumerable: !1,
|
|
4584
|
+
configurable: !0
|
|
4585
|
+
}), Object.defineProperty(S.prototype, "uncompressed", {
|
|
4586
|
+
/** @deprecated - use `PublicKey.toBytes(false)` instead. You may also need `Buffer.from`. */
|
|
4587
|
+
get: function() {
|
|
4588
|
+
return Buffer.from(this._uncompressed);
|
|
4589
|
+
},
|
|
4590
|
+
enumerable: !1,
|
|
4591
|
+
configurable: !0
|
|
4592
|
+
}), Object.defineProperty(S.prototype, "compressed", {
|
|
4593
|
+
/** @deprecated - use `PublicKey.toBytes()` instead. You may also need `Buffer.from`. */
|
|
4594
|
+
get: function() {
|
|
4595
|
+
return Buffer.from(this.data);
|
|
4596
|
+
},
|
|
4597
|
+
enumerable: !1,
|
|
4598
|
+
configurable: !0
|
|
4599
|
+
}), S.prototype.toBytes = function(H) {
|
|
4600
|
+
return H === void 0 && (H = !0), H ? this.data : this._uncompressed;
|
|
4601
|
+
}, S.prototype.toHex = function(H) {
|
|
4602
|
+
return H === void 0 && (H = !0), (0, t.bytesToHex)(this.toBytes(H));
|
|
4603
|
+
}, S.prototype.decapsulate = function(H, m) {
|
|
4604
|
+
m === void 0 && (m = !1);
|
|
4605
|
+
var I = this.toBytes(m), D = H.multiply(this, m);
|
|
4606
|
+
return (0, f.getSharedKey)(I, D);
|
|
4607
|
+
}, S.prototype.equals = function(H) {
|
|
4608
|
+
return (0, t.equalBytes)(this.data, H.data);
|
|
4609
|
+
}, S;
|
|
4610
|
+
})()
|
|
4611
|
+
);
|
|
4612
|
+
return Gt.PublicKey = y, Gt;
|
|
4613
|
+
}
|
|
4614
|
+
var We;
|
|
4615
|
+
function Cn() {
|
|
4616
|
+
if (We) return Vt;
|
|
4617
|
+
We = 1, Object.defineProperty(Vt, "__esModule", { value: !0 }), Vt.PrivateKey = void 0;
|
|
4618
|
+
var t = /* @__PURE__ */ Ht(), f = ye(), y = on(), S = (
|
|
4619
|
+
/** @class */
|
|
4620
|
+
(function() {
|
|
4621
|
+
function H(m, I) {
|
|
4622
|
+
if (this.curve = I, m === void 0)
|
|
4623
|
+
this.data = (0, f.getValidSecret)(I);
|
|
4624
|
+
else if ((0, f.isValidPrivateKey)(m, I))
|
|
4625
|
+
this.data = m;
|
|
4626
|
+
else
|
|
4627
|
+
throw new Error("Invalid private key");
|
|
4628
|
+
this.publicKey = new y.PublicKey((0, f.getPublicKey)(this.data, I), I);
|
|
4629
|
+
}
|
|
4630
|
+
return H.fromHex = function(m, I) {
|
|
4631
|
+
return new H((0, f.decodeHex)(m), I);
|
|
4632
|
+
}, Object.defineProperty(H.prototype, "secret", {
|
|
4633
|
+
/** @description From version 0.5.0, `Uint8Array` will be returned instead of `Buffer`. */
|
|
4634
|
+
get: function() {
|
|
4635
|
+
return Buffer.from(this.data);
|
|
4636
|
+
},
|
|
4637
|
+
enumerable: !1,
|
|
4638
|
+
configurable: !0
|
|
4639
|
+
}), H.prototype.toHex = function() {
|
|
4640
|
+
return (0, t.bytesToHex)(this.data);
|
|
4641
|
+
}, H.prototype.encapsulate = function(m, I) {
|
|
4642
|
+
I === void 0 && (I = !1);
|
|
4643
|
+
var D = this.publicKey.toBytes(I), F = this.multiply(m, I);
|
|
4644
|
+
return (0, f.getSharedKey)(D, F);
|
|
4645
|
+
}, H.prototype.multiply = function(m, I) {
|
|
4646
|
+
return I === void 0 && (I = !1), (0, f.getSharedPoint)(this.data, m.toBytes(!0), I, this.curve);
|
|
4647
|
+
}, H.prototype.equals = function(m) {
|
|
4648
|
+
return (0, t.equalBytes)(this.data, m.data);
|
|
4649
|
+
}, H;
|
|
4650
|
+
})()
|
|
4651
|
+
);
|
|
4652
|
+
return Vt.PrivateKey = S, Vt;
|
|
4653
|
+
}
|
|
4654
|
+
var Fe;
|
|
4655
|
+
function $e() {
|
|
4656
|
+
return Fe || (Fe = 1, (function(t) {
|
|
4657
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.PublicKey = t.PrivateKey = void 0;
|
|
4658
|
+
var f = Cn();
|
|
4659
|
+
Object.defineProperty(t, "PrivateKey", { enumerable: !0, get: function() {
|
|
4660
|
+
return f.PrivateKey;
|
|
4661
|
+
} });
|
|
4662
|
+
var y = on();
|
|
4663
|
+
Object.defineProperty(t, "PublicKey", { enumerable: !0, get: function() {
|
|
4664
|
+
return y.PublicKey;
|
|
4665
|
+
} });
|
|
4666
|
+
})($t)), $t;
|
|
4667
|
+
}
|
|
4668
|
+
var Qe;
|
|
4669
|
+
function Hn() {
|
|
4670
|
+
return Qe || (Qe = 1, (function(t) {
|
|
4671
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), t.utils = t.PublicKey = t.PrivateKey = t.ECIES_CONFIG = void 0, t.encrypt = m, t.decrypt = D;
|
|
4672
|
+
var f = /* @__PURE__ */ Ht(), y = zt(), S = $e(), H = ye();
|
|
4673
|
+
function m(L, M) {
|
|
4674
|
+
return Buffer.from(I(L, M, y.ECIES_CONFIG));
|
|
4675
|
+
}
|
|
4676
|
+
function I(L, M, B) {
|
|
4677
|
+
var d = B.ellipticCurve, w = new S.PrivateKey(void 0, d), v = L instanceof Uint8Array ? new S.PublicKey(L, d) : S.PublicKey.fromHex(L, d), T = w.encapsulate(v, B.isHkdfKeyCompressed), P = w.publicKey.toBytes(B.isEphemeralKeyCompressed), V = (0, H.symEncrypt)(T, M);
|
|
4678
|
+
return (0, f.concatBytes)(P, V);
|
|
4679
|
+
}
|
|
4680
|
+
function D(L, M) {
|
|
4681
|
+
return Buffer.from(F(L, M));
|
|
4682
|
+
}
|
|
4683
|
+
function F(L, M, B) {
|
|
4684
|
+
B === void 0 && (B = y.ECIES_CONFIG);
|
|
4685
|
+
var d = B.ellipticCurve, w = L instanceof Uint8Array ? new S.PrivateKey(L, d) : S.PrivateKey.fromHex(L, d), v = B.ephemeralKeySize, T = new S.PublicKey(M.subarray(0, v), d), P = M.subarray(v), V = T.decapsulate(w, B.isHkdfKeyCompressed);
|
|
4686
|
+
return (0, H.symDecrypt)(V, P);
|
|
4687
|
+
}
|
|
4688
|
+
var G = zt();
|
|
4689
|
+
Object.defineProperty(t, "ECIES_CONFIG", { enumerable: !0, get: function() {
|
|
4690
|
+
return G.ECIES_CONFIG;
|
|
4691
|
+
} });
|
|
4692
|
+
var Y = $e();
|
|
4693
|
+
Object.defineProperty(t, "PrivateKey", { enumerable: !0, get: function() {
|
|
4694
|
+
return Y.PrivateKey;
|
|
4695
|
+
} }), Object.defineProperty(t, "PublicKey", { enumerable: !0, get: function() {
|
|
4696
|
+
return Y.PublicKey;
|
|
4697
|
+
} }), t.utils = {
|
|
4698
|
+
// TODO: remove these after 0.5.0
|
|
4699
|
+
aesEncrypt: H.aesEncrypt,
|
|
4700
|
+
aesDecrypt: H.aesDecrypt,
|
|
4701
|
+
symEncrypt: H.symEncrypt,
|
|
4702
|
+
symDecrypt: H.symDecrypt,
|
|
4703
|
+
decodeHex: H.decodeHex,
|
|
4704
|
+
getValidSecret: H.getValidSecret,
|
|
4705
|
+
remove0x: H.remove0x
|
|
4706
|
+
};
|
|
4707
|
+
})(Xt)), Xt;
|
|
4708
|
+
}
|
|
4709
|
+
var sn = Hn();
|
|
4710
|
+
const On = /* @__PURE__ */ cn(sn), Un = /* @__PURE__ */ fn({
|
|
4711
|
+
__proto__: null,
|
|
4712
|
+
default: On
|
|
4713
|
+
}, [sn]);
|
|
4714
|
+
export {
|
|
4715
|
+
Un as i
|
|
4716
|
+
};
|