@btc-vision/transaction 1.8.7-beta.0 → 1.8.8
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/browser/btc-vision-bitcoin.js +832 -828
- package/browser/index.js +1074 -947
- package/browser/noble-curves.js +1183 -2156
- package/browser/noble-hashes.js +88 -88
- package/browser/rolldown-runtime.js +26 -19
- package/browser/src/epoch/validator/EpochValidator.d.ts +28 -6
- package/browser/src/transaction/builders/TransactionBuilder.d.ts +1 -0
- package/browser/src/transaction/offline/OfflineTransactionManager.d.ts +50 -0
- package/browser/src/transaction/offline/interfaces/ISerializableState.d.ts +10 -2
- package/browser/vendors.js +3267 -3229
- package/build/epoch/validator/EpochValidator.d.ts +28 -6
- package/build/epoch/validator/EpochValidator.js +44 -10
- package/build/transaction/TransactionFactory.js +1 -1
- package/build/transaction/builders/FundingTransaction.js +17 -13
- package/build/transaction/builders/TransactionBuilder.d.ts +1 -0
- package/build/transaction/builders/TransactionBuilder.js +32 -7
- package/build/transaction/offline/OfflineTransactionManager.d.ts +50 -0
- package/build/transaction/offline/OfflineTransactionManager.js +142 -1
- package/build/transaction/offline/TransactionSerializer.js +9 -0
- package/build/transaction/offline/interfaces/ISerializableState.d.ts +10 -2
- package/build/transaction/offline/interfaces/ISerializableState.js +3 -2
- package/build/transaction/shared/TweakedTransaction.js +27 -5
- package/package.json +1 -1
- package/src/epoch/validator/EpochValidator.ts +67 -6
- package/src/transaction/TransactionFactory.ts +1 -1
- package/src/transaction/builders/FundingTransaction.ts +21 -16
- package/src/transaction/builders/TransactionBuilder.ts +46 -10
- package/src/transaction/offline/OfflineTransactionManager.ts +191 -1
- package/src/transaction/offline/TransactionSerializer.ts +11 -0
- package/src/transaction/offline/interfaces/ISerializableState.ts +10 -2
- package/src/transaction/shared/TweakedTransaction.ts +33 -5
- package/test/add-refund-output.test.ts +96 -11
- package/test/csv-multisig-offline-edges.test.ts +293 -0
- package/test/csv-multisig-offline.test.ts +202 -0
- package/test/transaction-builders.test.ts +69 -3
- package/tsconfig.build.tsbuildinfo +1 -1
package/browser/noble-curves.js
CHANGED
|
@@ -1,119 +1,115 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
function
|
|
1
|
+
import { n as dt, r as Ze } from "./rolldown-runtime.js";
|
|
2
|
+
function Ce(t) {
|
|
3
3
|
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in t && t.BYTES_PER_ELEMENT === 1;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function Et(t, e = "") {
|
|
6
6
|
if (typeof t != "number") {
|
|
7
|
-
const
|
|
8
|
-
throw new TypeError(`${
|
|
7
|
+
const r = e && `"${e}" `;
|
|
8
|
+
throw new TypeError(`${r}expected number, got ${typeof t}`);
|
|
9
9
|
}
|
|
10
10
|
if (!Number.isSafeInteger(t) || t < 0) {
|
|
11
|
-
const
|
|
12
|
-
throw new RangeError(`${
|
|
11
|
+
const r = e && `"${e}" `;
|
|
12
|
+
throw new RangeError(`${r}expected integer >= 0, got ${t}`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
19
|
-
throw
|
|
15
|
+
function mt(t, e, r = "") {
|
|
16
|
+
const n = Ce(t), o = t?.length, i = e !== void 0;
|
|
17
|
+
if (!n || i && o !== e) {
|
|
18
|
+
const c = r && `"${r}" `, s = i ? ` of length ${e}` : "", a = n ? `length=${o}` : `type=${typeof t}`, u = c + "expected Uint8Array" + s + ", got " + a;
|
|
19
|
+
throw n ? new RangeError(u) : new TypeError(u);
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function ke(t) {
|
|
24
24
|
if (typeof t != "function" || typeof t.create != "function") throw new TypeError("Hash must wrapped by utils.createHasher");
|
|
25
|
-
if (
|
|
25
|
+
if (Et(t.outputLen), Et(t.blockLen), t.outputLen < 1) throw new Error('"outputLen" must be >= 1');
|
|
26
26
|
if (t.blockLen < 1) throw new Error('"blockLen" must be >= 1');
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function Dt(t, e = !0) {
|
|
29
29
|
if (t.destroyed) throw new Error("Hash instance has been destroyed");
|
|
30
|
-
if (
|
|
30
|
+
if (e && t.finished) throw new Error("Hash#digest() has already been called");
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
if (t.length <
|
|
32
|
+
function je(t, e) {
|
|
33
|
+
mt(t, void 0, "digestInto() output");
|
|
34
|
+
const r = e.outputLen;
|
|
35
|
+
if (t.length < r) throw new RangeError('"digestInto() output" expected to be of length >=' + r);
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
for (let
|
|
37
|
+
function Bt(...t) {
|
|
38
|
+
for (let e = 0; e < t.length; e++) t[e].fill(0);
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function Vt(t) {
|
|
41
41
|
return new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
return t << 32 -
|
|
43
|
+
function nt(t, e) {
|
|
44
|
+
return t << 32 - e | t >>> e;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
return t <<
|
|
46
|
+
function vr(t, e) {
|
|
47
|
+
return t << e | t >>> 32 - e >>> 0;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
if (
|
|
51
|
-
let
|
|
52
|
-
for (let
|
|
53
|
-
return
|
|
49
|
+
function le(t) {
|
|
50
|
+
if (mt(t), he) return t.toHex();
|
|
51
|
+
let e = "";
|
|
52
|
+
for (let r = 0; r < t.length; r++) e += Ye[t[r]];
|
|
53
|
+
return e;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (t >=
|
|
57
|
-
if (t >=
|
|
58
|
-
if (t >=
|
|
55
|
+
function Ae(t) {
|
|
56
|
+
if (t >= rt._0 && t <= rt._9) return t - rt._0;
|
|
57
|
+
if (t >= rt.A && t <= rt.F) return t - (rt.A - 10);
|
|
58
|
+
if (t >= rt.a && t <= rt.f) return t - (rt.a - 10);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function Ve(t) {
|
|
61
61
|
if (typeof t != "string") throw new TypeError("hex string expected, got " + typeof t);
|
|
62
|
-
if (
|
|
62
|
+
if (he) try {
|
|
63
63
|
return Uint8Array.fromHex(t);
|
|
64
64
|
} catch (o) {
|
|
65
65
|
throw o instanceof SyntaxError ? new RangeError(o.message) : o;
|
|
66
66
|
}
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
70
|
-
for (let o = 0, i = 0; o <
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
74
|
-
throw new RangeError('hex string expected, got non-hex character "' +
|
|
67
|
+
const e = t.length, r = e / 2;
|
|
68
|
+
if (e % 2) throw new RangeError("hex string expected, got unpadded hex of length " + e);
|
|
69
|
+
const n = new Uint8Array(r);
|
|
70
|
+
for (let o = 0, i = 0; o < r; o++, i += 2) {
|
|
71
|
+
const c = Ae(t.charCodeAt(i)), s = Ae(t.charCodeAt(i + 1));
|
|
72
|
+
if (c === void 0 || s === void 0) {
|
|
73
|
+
const a = t[i] + t[i + 1];
|
|
74
|
+
throw new RangeError('hex string expected, got non-hex character "' + a + '" at index ' + i);
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
n[o] = c * 16 + s;
|
|
77
77
|
}
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
function Nt(t) {
|
|
81
|
-
if (typeof t != "string") throw new TypeError("string expected");
|
|
82
|
-
return new Uint8Array(new TextEncoder().encode(t));
|
|
78
|
+
return n;
|
|
83
79
|
}
|
|
84
|
-
function
|
|
85
|
-
let
|
|
86
|
-
for (let
|
|
87
|
-
const o = t[
|
|
88
|
-
|
|
80
|
+
function In(...t) {
|
|
81
|
+
let e = 0;
|
|
82
|
+
for (let n = 0; n < t.length; n++) {
|
|
83
|
+
const o = t[n];
|
|
84
|
+
mt(o), e += o.length;
|
|
89
85
|
}
|
|
90
|
-
const
|
|
91
|
-
for (let
|
|
92
|
-
const i = t[
|
|
93
|
-
|
|
86
|
+
const r = new Uint8Array(e);
|
|
87
|
+
for (let n = 0, o = 0; n < t.length; n++) {
|
|
88
|
+
const i = t[n];
|
|
89
|
+
r.set(i, o), o += i.length;
|
|
94
90
|
}
|
|
95
|
-
return
|
|
91
|
+
return r;
|
|
96
92
|
}
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
return
|
|
93
|
+
function xt(t, e = {}) {
|
|
94
|
+
const r = (o, i) => t(i).update(o).digest(), n = t(void 0);
|
|
95
|
+
return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.canXOF = n.canXOF, r.create = (o) => t(o), Object.assign(r, e), Object.freeze(r);
|
|
100
96
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
if (typeof
|
|
97
|
+
function Fn(t = 32) {
|
|
98
|
+
Et(t, "bytesLength");
|
|
99
|
+
const e = typeof globalThis == "object" ? globalThis.crypto : null;
|
|
100
|
+
if (typeof e?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
|
|
105
101
|
if (t > 65536) throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);
|
|
106
|
-
return
|
|
102
|
+
return e.getRandomValues(new Uint8Array(t));
|
|
107
103
|
}
|
|
108
|
-
var
|
|
109
|
-
|
|
104
|
+
var he, Ye, rt, gt, It = dt((() => {
|
|
105
|
+
he = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ye = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0")), rt = {
|
|
110
106
|
_0: 48,
|
|
111
107
|
_9: 57,
|
|
112
108
|
A: 65,
|
|
113
109
|
F: 70,
|
|
114
110
|
a: 97,
|
|
115
111
|
f: 102
|
|
116
|
-
},
|
|
112
|
+
}, gt = (t) => ({ oid: Uint8Array.from([
|
|
117
113
|
6,
|
|
118
114
|
9,
|
|
119
115
|
96,
|
|
@@ -126,11 +122,11 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
|
|
|
126
122
|
2,
|
|
127
123
|
t
|
|
128
124
|
]) });
|
|
129
|
-
})),
|
|
130
|
-
_HMAC: () =>
|
|
131
|
-
hmac: () =>
|
|
132
|
-
}),
|
|
133
|
-
|
|
125
|
+
})), xr = /* @__PURE__ */ Ze({
|
|
126
|
+
_HMAC: () => Ut,
|
|
127
|
+
hmac: () => de
|
|
128
|
+
}), Ut, de, Ln = dt((() => {
|
|
129
|
+
It(), Ut = class {
|
|
134
130
|
oHash;
|
|
135
131
|
iHash;
|
|
136
132
|
blockLen;
|
|
@@ -138,23 +134,23 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
|
|
|
138
134
|
canXOF = !1;
|
|
139
135
|
finished = !1;
|
|
140
136
|
destroyed = !1;
|
|
141
|
-
constructor(t,
|
|
142
|
-
if (
|
|
137
|
+
constructor(t, e) {
|
|
138
|
+
if (ke(t), mt(e, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function") throw new Error("Expected instance of class which extends utils.Hash");
|
|
143
139
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
for (let o = 0; o <
|
|
147
|
-
this.iHash.update(
|
|
148
|
-
for (let o = 0; o <
|
|
149
|
-
this.oHash.update(
|
|
140
|
+
const r = this.blockLen, n = new Uint8Array(r);
|
|
141
|
+
n.set(e.length > r ? t.create().update(e).digest() : e);
|
|
142
|
+
for (let o = 0; o < n.length; o++) n[o] ^= 54;
|
|
143
|
+
this.iHash.update(n), this.oHash = t.create();
|
|
144
|
+
for (let o = 0; o < n.length; o++) n[o] ^= 106;
|
|
145
|
+
this.oHash.update(n), Bt(n);
|
|
150
146
|
}
|
|
151
147
|
update(t) {
|
|
152
|
-
return
|
|
148
|
+
return Dt(this), this.iHash.update(t), this;
|
|
153
149
|
}
|
|
154
150
|
digestInto(t) {
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
this.iHash.digestInto(
|
|
151
|
+
Dt(this), je(t, this), this.finished = !0;
|
|
152
|
+
const e = t.subarray(0, this.outputLen);
|
|
153
|
+
this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
|
|
158
154
|
}
|
|
159
155
|
digest() {
|
|
160
156
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -162,8 +158,8 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
|
|
|
162
158
|
}
|
|
163
159
|
_cloneInto(t) {
|
|
164
160
|
t ||= Object.create(Object.getPrototypeOf(this), {});
|
|
165
|
-
const { oHash:
|
|
166
|
-
return t = t, t.finished =
|
|
161
|
+
const { oHash: e, iHash: r, finished: n, destroyed: o, blockLen: i, outputLen: c } = this;
|
|
162
|
+
return t = t, t.finished = n, t.destroyed = o, t.blockLen = i, t.outputLen = c, t.oHash = e._cloneInto(t.oHash), t.iHash = r._cloneInto(t.iHash), t;
|
|
167
163
|
}
|
|
168
164
|
clone() {
|
|
169
165
|
return this._cloneInto();
|
|
@@ -171,19 +167,19 @@ var pr, Xe, On, xt, Lt, Qt = Dt((() => {
|
|
|
171
167
|
destroy() {
|
|
172
168
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
173
169
|
}
|
|
174
|
-
},
|
|
175
|
-
const t = ((
|
|
176
|
-
return t.create = (
|
|
170
|
+
}, de = /* @__PURE__ */ (() => {
|
|
171
|
+
const t = ((e, r, n) => new Ut(e, r).update(n).digest());
|
|
172
|
+
return t.create = (e, r) => new Ut(e, r), t;
|
|
177
173
|
})();
|
|
178
174
|
}));
|
|
179
|
-
function
|
|
180
|
-
return t &
|
|
175
|
+
function Nn(t, e, r) {
|
|
176
|
+
return t & e ^ ~t & r;
|
|
181
177
|
}
|
|
182
|
-
function
|
|
183
|
-
return t &
|
|
178
|
+
function Tn(t, e, r) {
|
|
179
|
+
return t & e ^ t & r ^ e & r;
|
|
184
180
|
}
|
|
185
|
-
var
|
|
186
|
-
|
|
181
|
+
var Wt, at, ut, M, G, Un = dt((() => {
|
|
182
|
+
It(), Wt = class {
|
|
187
183
|
blockLen;
|
|
188
184
|
outputLen;
|
|
189
185
|
canXOF = !1;
|
|
@@ -195,51 +191,51 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
|
|
|
195
191
|
length = 0;
|
|
196
192
|
pos = 0;
|
|
197
193
|
destroyed = !1;
|
|
198
|
-
constructor(t,
|
|
199
|
-
this.blockLen = t, this.outputLen =
|
|
194
|
+
constructor(t, e, r, n) {
|
|
195
|
+
this.blockLen = t, this.outputLen = e, this.padOffset = r, this.isLE = n, this.buffer = new Uint8Array(t), this.view = Vt(this.buffer);
|
|
200
196
|
}
|
|
201
197
|
update(t) {
|
|
202
|
-
|
|
203
|
-
const { view:
|
|
198
|
+
Dt(this), mt(t);
|
|
199
|
+
const { view: e, buffer: r, blockLen: n } = this, o = t.length;
|
|
204
200
|
for (let i = 0; i < o; ) {
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
207
|
-
const
|
|
208
|
-
for (;
|
|
201
|
+
const c = Math.min(n - this.pos, o - i);
|
|
202
|
+
if (c === n) {
|
|
203
|
+
const s = Vt(t);
|
|
204
|
+
for (; n <= o - i; i += n) this.process(s, i);
|
|
209
205
|
continue;
|
|
210
206
|
}
|
|
211
|
-
|
|
207
|
+
r.set(t.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === n && (this.process(e, 0), this.pos = 0);
|
|
212
208
|
}
|
|
213
209
|
return this.length += t.length, this.roundClean(), this;
|
|
214
210
|
}
|
|
215
211
|
digestInto(t) {
|
|
216
|
-
|
|
217
|
-
const { buffer:
|
|
212
|
+
Dt(this), je(t, this), this.finished = !0;
|
|
213
|
+
const { buffer: e, view: r, blockLen: n, isLE: o } = this;
|
|
218
214
|
let { pos: i } = this;
|
|
219
|
-
|
|
220
|
-
for (let
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
for (let
|
|
215
|
+
e[i++] = 128, Bt(this.buffer.subarray(i)), this.padOffset > n - i && (this.process(r, 0), i = 0);
|
|
216
|
+
for (let f = i; f < n; f++) e[f] = 0;
|
|
217
|
+
r.setBigUint64(n - 8, BigInt(this.length * 8), o), this.process(r, 0);
|
|
218
|
+
const c = Vt(t), s = this.outputLen;
|
|
219
|
+
if (s % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
220
|
+
const a = s / 4, u = this.get();
|
|
221
|
+
if (a > u.length) throw new Error("_sha2: outputLen bigger than state");
|
|
222
|
+
for (let f = 0; f < a; f++) c.setUint32(4 * f, u[f], o);
|
|
227
223
|
}
|
|
228
224
|
digest() {
|
|
229
|
-
const { buffer: t, outputLen:
|
|
225
|
+
const { buffer: t, outputLen: e } = this;
|
|
230
226
|
this.digestInto(t);
|
|
231
|
-
const
|
|
232
|
-
return this.destroy(),
|
|
227
|
+
const r = t.slice(0, e);
|
|
228
|
+
return this.destroy(), r;
|
|
233
229
|
}
|
|
234
230
|
_cloneInto(t) {
|
|
235
231
|
t ||= new this.constructor(), t.set(...this.get());
|
|
236
|
-
const { blockLen:
|
|
237
|
-
return t.destroyed = i, t.finished = o, t.length =
|
|
232
|
+
const { blockLen: e, buffer: r, length: n, finished: o, destroyed: i, pos: c } = this;
|
|
233
|
+
return t.destroyed = i, t.finished = o, t.length = n, t.pos = c, n % e && t.buffer.set(r), t;
|
|
238
234
|
}
|
|
239
235
|
clone() {
|
|
240
236
|
return this._cloneInto();
|
|
241
237
|
}
|
|
242
|
-
},
|
|
238
|
+
}, at = /* @__PURE__ */ Uint32Array.from([
|
|
243
239
|
1779033703,
|
|
244
240
|
3144134277,
|
|
245
241
|
1013904242,
|
|
@@ -248,7 +244,7 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
|
|
|
248
244
|
2600822924,
|
|
249
245
|
528734635,
|
|
250
246
|
1541459225
|
|
251
|
-
]),
|
|
247
|
+
]), ut = /* @__PURE__ */ Uint32Array.from([
|
|
252
248
|
3238371032,
|
|
253
249
|
914150663,
|
|
254
250
|
812702999,
|
|
@@ -257,7 +253,7 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
|
|
|
257
253
|
1750603025,
|
|
258
254
|
1694076839,
|
|
259
255
|
3204075428
|
|
260
|
-
]),
|
|
256
|
+
]), M = /* @__PURE__ */ Uint32Array.from([
|
|
261
257
|
3418070365,
|
|
262
258
|
3238371032,
|
|
263
259
|
1654270250,
|
|
@@ -274,7 +270,7 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
|
|
|
274
270
|
1694076839,
|
|
275
271
|
1203062813,
|
|
276
272
|
3204075428
|
|
277
|
-
]),
|
|
273
|
+
]), G = /* @__PURE__ */ Uint32Array.from([
|
|
278
274
|
1779033703,
|
|
279
275
|
4089235720,
|
|
280
276
|
3144134277,
|
|
@@ -293,48 +289,48 @@ var Fe, Ht, Tt, lt, ut, Br = Dt((() => {
|
|
|
293
289
|
327033209
|
|
294
290
|
]);
|
|
295
291
|
}));
|
|
296
|
-
function
|
|
297
|
-
return
|
|
298
|
-
h: Number(t &
|
|
299
|
-
l: Number(t >>
|
|
292
|
+
function $n(t, e = !1) {
|
|
293
|
+
return e ? {
|
|
294
|
+
h: Number(t & St),
|
|
295
|
+
l: Number(t >> Qt & St)
|
|
300
296
|
} : {
|
|
301
|
-
h: Number(t >>
|
|
302
|
-
l: Number(t &
|
|
297
|
+
h: Number(t >> Qt & St) | 0,
|
|
298
|
+
l: Number(t & St) | 0
|
|
303
299
|
};
|
|
304
300
|
}
|
|
305
|
-
function
|
|
306
|
-
const
|
|
307
|
-
let
|
|
308
|
-
for (let i = 0; i <
|
|
309
|
-
const { h:
|
|
310
|
-
[
|
|
301
|
+
function Dn(t, e = !1) {
|
|
302
|
+
const r = t.length;
|
|
303
|
+
let n = new Uint32Array(r), o = new Uint32Array(r);
|
|
304
|
+
for (let i = 0; i < r; i++) {
|
|
305
|
+
const { h: c, l: s } = $n(t[i], e);
|
|
306
|
+
[n[i], o[i]] = [c, s];
|
|
311
307
|
}
|
|
312
|
-
return [
|
|
308
|
+
return [n, o];
|
|
313
309
|
}
|
|
314
|
-
function
|
|
315
|
-
const o = (
|
|
310
|
+
function it(t, e, r, n) {
|
|
311
|
+
const o = (e >>> 0) + (n >>> 0);
|
|
316
312
|
return {
|
|
317
|
-
h: t +
|
|
313
|
+
h: t + r + (o / 2 ** 32 | 0) | 0,
|
|
318
314
|
l: o | 0
|
|
319
315
|
};
|
|
320
316
|
}
|
|
321
|
-
var
|
|
322
|
-
|
|
323
|
-
})),
|
|
324
|
-
_SHA224: () =>
|
|
325
|
-
_SHA256: () =>
|
|
326
|
-
_SHA384: () =>
|
|
327
|
-
_SHA512: () =>
|
|
328
|
-
_SHA512_224: () =>
|
|
329
|
-
_SHA512_256: () =>
|
|
330
|
-
sha224: () =>
|
|
331
|
-
sha256: () =>
|
|
332
|
-
sha384: () =>
|
|
333
|
-
sha512: () =>
|
|
334
|
-
sha512_224: () =>
|
|
335
|
-
sha512_256: () =>
|
|
336
|
-
}),
|
|
337
|
-
|
|
317
|
+
var St, Qt, Jt, Pt, bt, wt, _t, Ht, ze, Me, Ge, Ke, Xe, We, qn = dt((() => {
|
|
318
|
+
St = /* @__PURE__ */ BigInt(2 ** 32 - 1), Qt = /* @__PURE__ */ BigInt(32), Jt = (t, e, r) => t >>> r, Pt = (t, e, r) => t << 32 - r | e >>> r, bt = (t, e, r) => t >>> r | e << 32 - r, wt = (t, e, r) => t << 32 - r | e >>> r, _t = (t, e, r) => t << 64 - r | e >>> r - 32, Ht = (t, e, r) => t >>> r - 32 | e << 64 - r, ze = (t, e, r) => (t >>> 0) + (e >>> 0) + (r >>> 0), Me = (t, e, r, n) => e + r + n + (t / 2 ** 32 | 0) | 0, Ge = (t, e, r, n) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (n >>> 0), Ke = (t, e, r, n, o) => e + r + n + o + (t / 2 ** 32 | 0) | 0, Xe = (t, e, r, n, o) => (t >>> 0) + (e >>> 0) + (r >>> 0) + (n >>> 0) + (o >>> 0), We = (t, e, r, n, o, i) => e + r + n + o + i + (t / 2 ** 32 | 0) | 0;
|
|
319
|
+
})), Br = /* @__PURE__ */ Ze({
|
|
320
|
+
_SHA224: () => ee,
|
|
321
|
+
_SHA256: () => te,
|
|
322
|
+
_SHA384: () => re,
|
|
323
|
+
_SHA512: () => ne,
|
|
324
|
+
_SHA512_224: () => oe,
|
|
325
|
+
_SHA512_256: () => ie,
|
|
326
|
+
sha224: () => Qe,
|
|
327
|
+
sha256: () => ge,
|
|
328
|
+
sha384: () => Pe,
|
|
329
|
+
sha512: () => Je,
|
|
330
|
+
sha512_224: () => en,
|
|
331
|
+
sha512_256: () => tn
|
|
332
|
+
}), Re, st, Yt, te, ee, zt, Se, _e, ct, ft, Rt, ne, re, Y, z, oe, ie, ge, Qe, Je, Pe, tn, en, Zn = dt((() => {
|
|
333
|
+
Un(), qn(), It(), Re = /* @__PURE__ */ Uint32Array.from([
|
|
338
334
|
1116352408,
|
|
339
335
|
1899447441,
|
|
340
336
|
3049323471,
|
|
@@ -399,70 +395,70 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
|
|
|
399
395
|
2756734187,
|
|
400
396
|
3204031479,
|
|
401
397
|
3329325298
|
|
402
|
-
]),
|
|
398
|
+
]), st = /* @__PURE__ */ new Uint32Array(64), Yt = class extends Wt {
|
|
403
399
|
constructor(t) {
|
|
404
400
|
super(64, t, 8, !1);
|
|
405
401
|
}
|
|
406
402
|
get() {
|
|
407
|
-
const { A: t, B:
|
|
403
|
+
const { A: t, B: e, C: r, D: n, E: o, F: i, G: c, H: s } = this;
|
|
408
404
|
return [
|
|
409
405
|
t,
|
|
410
|
-
n,
|
|
411
406
|
e,
|
|
412
407
|
r,
|
|
408
|
+
n,
|
|
413
409
|
o,
|
|
414
410
|
i,
|
|
415
|
-
|
|
416
|
-
|
|
411
|
+
c,
|
|
412
|
+
s
|
|
417
413
|
];
|
|
418
414
|
}
|
|
419
|
-
set(t,
|
|
420
|
-
this.A = t | 0, this.B =
|
|
415
|
+
set(t, e, r, n, o, i, c, s) {
|
|
416
|
+
this.A = t | 0, this.B = e | 0, this.C = r | 0, this.D = n | 0, this.E = o | 0, this.F = i | 0, this.G = c | 0, this.H = s | 0;
|
|
421
417
|
}
|
|
422
|
-
process(t,
|
|
423
|
-
for (let
|
|
424
|
-
for (let
|
|
425
|
-
const
|
|
426
|
-
|
|
418
|
+
process(t, e) {
|
|
419
|
+
for (let f = 0; f < 16; f++, e += 4) st[f] = t.getUint32(e, !1);
|
|
420
|
+
for (let f = 16; f < 64; f++) {
|
|
421
|
+
const g = st[f - 15], m = st[f - 2], w = nt(g, 7) ^ nt(g, 18) ^ g >>> 3, A = nt(m, 17) ^ nt(m, 19) ^ m >>> 10;
|
|
422
|
+
st[f] = A + st[f - 7] + w + st[f - 16] | 0;
|
|
427
423
|
}
|
|
428
|
-
let { A:
|
|
429
|
-
for (let
|
|
430
|
-
const
|
|
431
|
-
|
|
424
|
+
let { A: r, B: n, C: o, D: i, E: c, F: s, G: a, H: u } = this;
|
|
425
|
+
for (let f = 0; f < 64; f++) {
|
|
426
|
+
const g = nt(c, 6) ^ nt(c, 11) ^ nt(c, 25), m = u + g + Nn(c, s, a) + Re[f] + st[f] | 0, w = (nt(r, 2) ^ nt(r, 13) ^ nt(r, 22)) + Tn(r, n, o) | 0;
|
|
427
|
+
u = a, a = s, s = c, c = i + m | 0, i = o, o = n, n = r, r = m + w | 0;
|
|
432
428
|
}
|
|
433
|
-
|
|
429
|
+
r = r + this.A | 0, n = n + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, s = s + this.F | 0, a = a + this.G | 0, u = u + this.H | 0, this.set(r, n, o, i, c, s, a, u);
|
|
434
430
|
}
|
|
435
431
|
roundClean() {
|
|
436
|
-
|
|
432
|
+
Bt(st);
|
|
437
433
|
}
|
|
438
434
|
destroy() {
|
|
439
|
-
this.destroyed = !0, this.set(0, 0, 0, 0, 0, 0, 0, 0),
|
|
440
|
-
}
|
|
441
|
-
},
|
|
442
|
-
A =
|
|
443
|
-
B =
|
|
444
|
-
C =
|
|
445
|
-
D =
|
|
446
|
-
E =
|
|
447
|
-
F =
|
|
448
|
-
G =
|
|
449
|
-
H =
|
|
435
|
+
this.destroyed = !0, this.set(0, 0, 0, 0, 0, 0, 0, 0), Bt(this.buffer);
|
|
436
|
+
}
|
|
437
|
+
}, te = class extends Yt {
|
|
438
|
+
A = at[0] | 0;
|
|
439
|
+
B = at[1] | 0;
|
|
440
|
+
C = at[2] | 0;
|
|
441
|
+
D = at[3] | 0;
|
|
442
|
+
E = at[4] | 0;
|
|
443
|
+
F = at[5] | 0;
|
|
444
|
+
G = at[6] | 0;
|
|
445
|
+
H = at[7] | 0;
|
|
450
446
|
constructor() {
|
|
451
447
|
super(32);
|
|
452
448
|
}
|
|
453
|
-
},
|
|
454
|
-
A =
|
|
455
|
-
B =
|
|
456
|
-
C =
|
|
457
|
-
D =
|
|
458
|
-
E =
|
|
459
|
-
F =
|
|
460
|
-
G =
|
|
461
|
-
H =
|
|
449
|
+
}, ee = class extends Yt {
|
|
450
|
+
A = ut[0] | 0;
|
|
451
|
+
B = ut[1] | 0;
|
|
452
|
+
C = ut[2] | 0;
|
|
453
|
+
D = ut[3] | 0;
|
|
454
|
+
E = ut[4] | 0;
|
|
455
|
+
F = ut[5] | 0;
|
|
456
|
+
G = ut[6] | 0;
|
|
457
|
+
H = ut[7] | 0;
|
|
462
458
|
constructor() {
|
|
463
459
|
super(28);
|
|
464
460
|
}
|
|
465
|
-
},
|
|
461
|
+
}, zt = Dn([
|
|
466
462
|
"0x428a2f98d728ae22",
|
|
467
463
|
"0x7137449123ef65cd",
|
|
468
464
|
"0xb5c0fbcfec4d3b2f",
|
|
@@ -543,97 +539,97 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
|
|
|
543
539
|
"0x597f299cfc657e2a",
|
|
544
540
|
"0x5fcb6fab3ad6faec",
|
|
545
541
|
"0x6c44198c4a475817"
|
|
546
|
-
].map((t) => BigInt(t))),
|
|
542
|
+
].map((t) => BigInt(t))), Se = zt[0], _e = zt[1], ct = /* @__PURE__ */ new Uint32Array(80), ft = /* @__PURE__ */ new Uint32Array(80), Rt = class extends Wt {
|
|
547
543
|
constructor(t) {
|
|
548
544
|
super(128, t, 16, !1);
|
|
549
545
|
}
|
|
550
546
|
get() {
|
|
551
|
-
const { Ah: t, Al:
|
|
547
|
+
const { Ah: t, Al: e, Bh: r, Bl: n, Ch: o, Cl: i, Dh: c, Dl: s, Eh: a, El: u, Fh: f, Fl: g, Gh: m, Gl: w, Hh: A, Hl: _ } = this;
|
|
552
548
|
return [
|
|
553
549
|
t,
|
|
554
|
-
n,
|
|
555
550
|
e,
|
|
556
551
|
r,
|
|
552
|
+
n,
|
|
557
553
|
o,
|
|
558
554
|
i,
|
|
555
|
+
c,
|
|
556
|
+
s,
|
|
559
557
|
a,
|
|
558
|
+
u,
|
|
560
559
|
f,
|
|
561
|
-
l,
|
|
562
560
|
g,
|
|
563
|
-
|
|
564
|
-
u,
|
|
565
|
-
d,
|
|
566
|
-
h,
|
|
561
|
+
m,
|
|
567
562
|
w,
|
|
568
|
-
|
|
563
|
+
A,
|
|
564
|
+
_
|
|
569
565
|
];
|
|
570
566
|
}
|
|
571
|
-
set(t,
|
|
572
|
-
this.Ah = t | 0, this.Al =
|
|
567
|
+
set(t, e, r, n, o, i, c, s, a, u, f, g, m, w, A, _) {
|
|
568
|
+
this.Ah = t | 0, this.Al = e | 0, this.Bh = r | 0, this.Bl = n | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = c | 0, this.Dl = s | 0, this.Eh = a | 0, this.El = u | 0, this.Fh = f | 0, this.Fl = g | 0, this.Gh = m | 0, this.Gl = w | 0, this.Hh = A | 0, this.Hl = _ | 0;
|
|
573
569
|
}
|
|
574
|
-
process(t,
|
|
575
|
-
for (let
|
|
576
|
-
|
|
577
|
-
for (let
|
|
578
|
-
const
|
|
579
|
-
|
|
570
|
+
process(t, e) {
|
|
571
|
+
for (let x = 0; x < 16; x++, e += 4)
|
|
572
|
+
ct[x] = t.getUint32(e), ft[x] = t.getUint32(e += 4);
|
|
573
|
+
for (let x = 16; x < 80; x++) {
|
|
574
|
+
const q = ct[x - 15] | 0, Z = ft[x - 15] | 0, T = bt(q, Z, 1) ^ bt(q, Z, 8) ^ Jt(q, Z, 7), Q = wt(q, Z, 1) ^ wt(q, Z, 8) ^ Pt(q, Z, 7), $ = ct[x - 2] | 0, R = ft[x - 2] | 0, C = bt($, R, 19) ^ _t($, R, 61) ^ Jt($, R, 6), X = wt($, R, 19) ^ Ht($, R, 61) ^ Pt($, R, 6), F = Ge(Q, X, ft[x - 7], ft[x - 16]), h = Ke(F, T, C, ct[x - 7], ct[x - 16]);
|
|
575
|
+
ct[x] = h | 0, ft[x] = F | 0;
|
|
580
576
|
}
|
|
581
|
-
let { Ah:
|
|
582
|
-
for (let
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
|
|
577
|
+
let { Ah: r, Al: n, Bh: o, Bl: i, Ch: c, Cl: s, Dh: a, Dl: u, Eh: f, El: g, Fh: m, Fl: w, Gh: A, Gl: _, Hh: H, Hl: O } = this;
|
|
578
|
+
for (let x = 0; x < 80; x++) {
|
|
579
|
+
const q = bt(f, g, 14) ^ bt(f, g, 18) ^ _t(f, g, 41), Z = wt(f, g, 14) ^ wt(f, g, 18) ^ Ht(f, g, 41), T = f & m ^ ~f & A, Q = g & w ^ ~g & _, $ = Xe(O, Z, Q, _e[x], ft[x]), R = We($, H, q, T, Se[x], ct[x]), C = $ | 0, X = bt(r, n, 28) ^ _t(r, n, 34) ^ _t(r, n, 39), F = wt(r, n, 28) ^ Ht(r, n, 34) ^ Ht(r, n, 39), h = r & o ^ r & c ^ o & c, y = n & i ^ n & s ^ i & s;
|
|
580
|
+
H = A | 0, O = _ | 0, A = m | 0, _ = w | 0, m = f | 0, w = g | 0, { h: f, l: g } = it(a | 0, u | 0, R | 0, C | 0), a = c | 0, u = s | 0, c = o | 0, s = i | 0, o = r | 0, i = n | 0;
|
|
581
|
+
const B = ze(C, F, y);
|
|
582
|
+
r = Me(B, R, X, h), n = B | 0;
|
|
587
583
|
}
|
|
588
|
-
({ h:
|
|
584
|
+
({ h: r, l: n } = it(this.Ah | 0, this.Al | 0, r | 0, n | 0)), { h: o, l: i } = it(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: c, l: s } = it(this.Ch | 0, this.Cl | 0, c | 0, s | 0), { h: a, l: u } = it(this.Dh | 0, this.Dl | 0, a | 0, u | 0), { h: f, l: g } = it(this.Eh | 0, this.El | 0, f | 0, g | 0), { h: m, l: w } = it(this.Fh | 0, this.Fl | 0, m | 0, w | 0), { h: A, l: _ } = it(this.Gh | 0, this.Gl | 0, A | 0, _ | 0), { h: H, l: O } = it(this.Hh | 0, this.Hl | 0, H | 0, O | 0), this.set(r, n, o, i, c, s, a, u, f, g, m, w, A, _, H, O);
|
|
589
585
|
}
|
|
590
586
|
roundClean() {
|
|
591
|
-
|
|
587
|
+
Bt(ct, ft);
|
|
592
588
|
}
|
|
593
589
|
destroy() {
|
|
594
|
-
this.destroyed = !0,
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
|
-
Ah =
|
|
598
|
-
Al =
|
|
599
|
-
Bh =
|
|
600
|
-
Bl =
|
|
601
|
-
Ch =
|
|
602
|
-
Cl =
|
|
603
|
-
Dh =
|
|
604
|
-
Dl =
|
|
605
|
-
Eh =
|
|
606
|
-
El =
|
|
607
|
-
Fh =
|
|
608
|
-
Fl =
|
|
609
|
-
Gh =
|
|
610
|
-
Gl =
|
|
611
|
-
Hh =
|
|
612
|
-
Hl =
|
|
590
|
+
this.destroyed = !0, Bt(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
591
|
+
}
|
|
592
|
+
}, ne = class extends Rt {
|
|
593
|
+
Ah = G[0] | 0;
|
|
594
|
+
Al = G[1] | 0;
|
|
595
|
+
Bh = G[2] | 0;
|
|
596
|
+
Bl = G[3] | 0;
|
|
597
|
+
Ch = G[4] | 0;
|
|
598
|
+
Cl = G[5] | 0;
|
|
599
|
+
Dh = G[6] | 0;
|
|
600
|
+
Dl = G[7] | 0;
|
|
601
|
+
Eh = G[8] | 0;
|
|
602
|
+
El = G[9] | 0;
|
|
603
|
+
Fh = G[10] | 0;
|
|
604
|
+
Fl = G[11] | 0;
|
|
605
|
+
Gh = G[12] | 0;
|
|
606
|
+
Gl = G[13] | 0;
|
|
607
|
+
Hh = G[14] | 0;
|
|
608
|
+
Hl = G[15] | 0;
|
|
613
609
|
constructor() {
|
|
614
610
|
super(64);
|
|
615
611
|
}
|
|
616
|
-
},
|
|
617
|
-
Ah =
|
|
618
|
-
Al =
|
|
619
|
-
Bh =
|
|
620
|
-
Bl =
|
|
621
|
-
Ch =
|
|
622
|
-
Cl =
|
|
623
|
-
Dh =
|
|
624
|
-
Dl =
|
|
625
|
-
Eh =
|
|
626
|
-
El =
|
|
627
|
-
Fh =
|
|
628
|
-
Fl =
|
|
629
|
-
Gh =
|
|
630
|
-
Gl =
|
|
631
|
-
Hh =
|
|
632
|
-
Hl =
|
|
612
|
+
}, re = class extends Rt {
|
|
613
|
+
Ah = M[0] | 0;
|
|
614
|
+
Al = M[1] | 0;
|
|
615
|
+
Bh = M[2] | 0;
|
|
616
|
+
Bl = M[3] | 0;
|
|
617
|
+
Ch = M[4] | 0;
|
|
618
|
+
Cl = M[5] | 0;
|
|
619
|
+
Dh = M[6] | 0;
|
|
620
|
+
Dl = M[7] | 0;
|
|
621
|
+
Eh = M[8] | 0;
|
|
622
|
+
El = M[9] | 0;
|
|
623
|
+
Fh = M[10] | 0;
|
|
624
|
+
Fl = M[11] | 0;
|
|
625
|
+
Gh = M[12] | 0;
|
|
626
|
+
Gl = M[13] | 0;
|
|
627
|
+
Hh = M[14] | 0;
|
|
628
|
+
Hl = M[15] | 0;
|
|
633
629
|
constructor() {
|
|
634
630
|
super(48);
|
|
635
631
|
}
|
|
636
|
-
},
|
|
632
|
+
}, Y = /* @__PURE__ */ Uint32Array.from([
|
|
637
633
|
2352822216,
|
|
638
634
|
424955298,
|
|
639
635
|
1944164710,
|
|
@@ -650,7 +646,7 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
|
|
|
650
646
|
1780299464,
|
|
651
647
|
286451373,
|
|
652
648
|
2446758561
|
|
653
|
-
]),
|
|
649
|
+
]), z = /* @__PURE__ */ Uint32Array.from([
|
|
654
650
|
573645204,
|
|
655
651
|
4230739756,
|
|
656
652
|
2673172387,
|
|
@@ -667,111 +663,111 @@ var ee, Ie, Ne, je, Ut, qt, ne, re, Hn, Tn, Fn, In, Nn, jn, Rr = Dt((() => {
|
|
|
667
663
|
746961066,
|
|
668
664
|
246885852,
|
|
669
665
|
2177182882
|
|
670
|
-
]),
|
|
671
|
-
Ah =
|
|
672
|
-
Al =
|
|
673
|
-
Bh =
|
|
674
|
-
Bl =
|
|
675
|
-
Ch =
|
|
676
|
-
Cl =
|
|
677
|
-
Dh =
|
|
678
|
-
Dl =
|
|
679
|
-
Eh =
|
|
680
|
-
El =
|
|
681
|
-
Fh =
|
|
682
|
-
Fl =
|
|
683
|
-
Gh =
|
|
684
|
-
Gl =
|
|
685
|
-
Hh =
|
|
686
|
-
Hl =
|
|
666
|
+
]), oe = class extends Rt {
|
|
667
|
+
Ah = Y[0] | 0;
|
|
668
|
+
Al = Y[1] | 0;
|
|
669
|
+
Bh = Y[2] | 0;
|
|
670
|
+
Bl = Y[3] | 0;
|
|
671
|
+
Ch = Y[4] | 0;
|
|
672
|
+
Cl = Y[5] | 0;
|
|
673
|
+
Dh = Y[6] | 0;
|
|
674
|
+
Dl = Y[7] | 0;
|
|
675
|
+
Eh = Y[8] | 0;
|
|
676
|
+
El = Y[9] | 0;
|
|
677
|
+
Fh = Y[10] | 0;
|
|
678
|
+
Fl = Y[11] | 0;
|
|
679
|
+
Gh = Y[12] | 0;
|
|
680
|
+
Gl = Y[13] | 0;
|
|
681
|
+
Hh = Y[14] | 0;
|
|
682
|
+
Hl = Y[15] | 0;
|
|
687
683
|
constructor() {
|
|
688
684
|
super(28);
|
|
689
685
|
}
|
|
690
|
-
},
|
|
691
|
-
Ah =
|
|
692
|
-
Al =
|
|
693
|
-
Bh =
|
|
694
|
-
Bl =
|
|
695
|
-
Ch =
|
|
696
|
-
Cl =
|
|
697
|
-
Dh =
|
|
698
|
-
Dl =
|
|
699
|
-
Eh =
|
|
700
|
-
El =
|
|
701
|
-
Fh =
|
|
702
|
-
Fl =
|
|
703
|
-
Gh =
|
|
704
|
-
Gl =
|
|
705
|
-
Hh =
|
|
706
|
-
Hl =
|
|
686
|
+
}, ie = class extends Rt {
|
|
687
|
+
Ah = z[0] | 0;
|
|
688
|
+
Al = z[1] | 0;
|
|
689
|
+
Bh = z[2] | 0;
|
|
690
|
+
Bl = z[3] | 0;
|
|
691
|
+
Ch = z[4] | 0;
|
|
692
|
+
Cl = z[5] | 0;
|
|
693
|
+
Dh = z[6] | 0;
|
|
694
|
+
Dl = z[7] | 0;
|
|
695
|
+
Eh = z[8] | 0;
|
|
696
|
+
El = z[9] | 0;
|
|
697
|
+
Fh = z[10] | 0;
|
|
698
|
+
Fl = z[11] | 0;
|
|
699
|
+
Gh = z[12] | 0;
|
|
700
|
+
Gl = z[13] | 0;
|
|
701
|
+
Hh = z[14] | 0;
|
|
702
|
+
Hl = z[15] | 0;
|
|
707
703
|
constructor() {
|
|
708
704
|
super(32);
|
|
709
705
|
}
|
|
710
|
-
},
|
|
706
|
+
}, ge = /* @__PURE__ */ xt(() => new te(), /* @__PURE__ */ gt(1)), Qe = /* @__PURE__ */ xt(() => new ee(), /* @__PURE__ */ gt(4)), Je = /* @__PURE__ */ xt(() => new ne(), /* @__PURE__ */ gt(3)), Pe = /* @__PURE__ */ xt(() => new re(), /* @__PURE__ */ gt(2)), tn = /* @__PURE__ */ xt(() => new ie(), /* @__PURE__ */ gt(6)), en = /* @__PURE__ */ xt(() => new oe(), /* @__PURE__ */ gt(5));
|
|
711
707
|
}));
|
|
712
|
-
function
|
|
708
|
+
function Cn(t) {
|
|
713
709
|
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
714
710
|
}
|
|
715
|
-
function
|
|
711
|
+
function Ar(t, e = "") {
|
|
716
712
|
if (!Number.isSafeInteger(t) || t < 0) {
|
|
717
|
-
const
|
|
718
|
-
throw new Error(`${
|
|
713
|
+
const r = e && `"${e}" `;
|
|
714
|
+
throw new Error(`${r}expected integer >= 0, got ${t}`);
|
|
719
715
|
}
|
|
720
716
|
}
|
|
721
|
-
function
|
|
722
|
-
const
|
|
723
|
-
if (!
|
|
724
|
-
const
|
|
725
|
-
throw new Error(
|
|
717
|
+
function nn(t, e, r = "") {
|
|
718
|
+
const n = Cn(t), o = t?.length, i = e !== void 0;
|
|
719
|
+
if (!n || i && o !== e) {
|
|
720
|
+
const c = r && `"${r}" `, s = i ? ` of length ${e}` : "", a = n ? `length=${o}` : `type=${typeof t}`;
|
|
721
|
+
throw new Error(c + "expected Uint8Array" + s + ", got " + a);
|
|
726
722
|
}
|
|
727
723
|
return t;
|
|
728
724
|
}
|
|
729
|
-
function
|
|
725
|
+
function Rr(t, e = !0) {
|
|
730
726
|
if (t.destroyed) throw new Error("Hash instance has been destroyed");
|
|
731
|
-
if (
|
|
727
|
+
if (e && t.finished) throw new Error("Hash#digest() has already been called");
|
|
732
728
|
}
|
|
733
|
-
function
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
if (t.length <
|
|
729
|
+
function Sr(t, e) {
|
|
730
|
+
nn(t, void 0, "digestInto() output");
|
|
731
|
+
const r = e.outputLen;
|
|
732
|
+
if (t.length < r) throw new Error('"digestInto() output" expected to be of length >=' + r);
|
|
737
733
|
}
|
|
738
|
-
function
|
|
734
|
+
function _r(t) {
|
|
739
735
|
return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
|
|
740
736
|
}
|
|
741
|
-
function
|
|
742
|
-
for (let
|
|
737
|
+
function Hr(...t) {
|
|
738
|
+
for (let e = 0; e < t.length; e++) t[e].fill(0);
|
|
743
739
|
}
|
|
744
|
-
function
|
|
740
|
+
function kn(t) {
|
|
745
741
|
return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
|
|
746
742
|
}
|
|
747
|
-
function
|
|
748
|
-
for (let
|
|
743
|
+
function jn(t) {
|
|
744
|
+
for (let e = 0; e < t.length; e++) t[e] = kn(t[e]);
|
|
749
745
|
return t;
|
|
750
746
|
}
|
|
751
|
-
function
|
|
752
|
-
let
|
|
753
|
-
for (let
|
|
754
|
-
const o = t[
|
|
755
|
-
|
|
747
|
+
function Or(...t) {
|
|
748
|
+
let e = 0;
|
|
749
|
+
for (let n = 0; n < t.length; n++) {
|
|
750
|
+
const o = t[n];
|
|
751
|
+
nn(o), e += o.length;
|
|
756
752
|
}
|
|
757
|
-
const
|
|
758
|
-
for (let
|
|
759
|
-
const i = t[
|
|
760
|
-
|
|
753
|
+
const r = new Uint8Array(e);
|
|
754
|
+
for (let n = 0, o = 0; n < t.length; n++) {
|
|
755
|
+
const i = t[n];
|
|
756
|
+
r.set(i, o), o += i.length;
|
|
761
757
|
}
|
|
762
|
-
return
|
|
758
|
+
return r;
|
|
763
759
|
}
|
|
764
|
-
function
|
|
765
|
-
const
|
|
766
|
-
return
|
|
760
|
+
function Ir(t, e = {}) {
|
|
761
|
+
const r = (o, i) => t(i).update(o).digest(), n = t(void 0);
|
|
762
|
+
return r.outputLen = n.outputLen, r.blockLen = n.blockLen, r.create = (o) => t(o), Object.assign(r, e), Object.freeze(r);
|
|
767
763
|
}
|
|
768
|
-
function
|
|
769
|
-
const
|
|
770
|
-
if (typeof
|
|
771
|
-
return
|
|
764
|
+
function Fr(t = 32) {
|
|
765
|
+
const e = typeof globalThis == "object" ? globalThis.crypto : null;
|
|
766
|
+
if (typeof e?.getRandomValues != "function") throw new Error("crypto.getRandomValues must be defined");
|
|
767
|
+
return e.getRandomValues(new Uint8Array(t));
|
|
772
768
|
}
|
|
773
|
-
var
|
|
774
|
-
|
|
769
|
+
var He, Vn, Yn, zn = dt((() => {
|
|
770
|
+
He = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68, Vn = He ? (t) => t : jn, Yn = (t) => ({ oid: Uint8Array.from([
|
|
775
771
|
6,
|
|
776
772
|
9,
|
|
777
773
|
96,
|
|
@@ -785,258 +781,250 @@ var ln, Fr, Ir, Nr, jr = Dt((() => {
|
|
|
785
781
|
t
|
|
786
782
|
]) });
|
|
787
783
|
}));
|
|
788
|
-
function
|
|
784
|
+
function Lr(t, e = "") {
|
|
789
785
|
if (typeof t != "boolean") {
|
|
790
|
-
const
|
|
791
|
-
throw new Error(
|
|
786
|
+
const r = e && `"${e}" `;
|
|
787
|
+
throw new Error(r + "expected boolean, got type=" + typeof t);
|
|
792
788
|
}
|
|
793
789
|
return t;
|
|
794
790
|
}
|
|
795
|
-
var
|
|
796
|
-
|
|
791
|
+
var Nr = dt((() => {
|
|
792
|
+
zn();
|
|
797
793
|
}));
|
|
798
|
-
function
|
|
794
|
+
function be(t) {
|
|
799
795
|
if (!Number.isSafeInteger(t) || t < 0 || t > 4294967295) throw new Error("wrong u32 integer:" + t);
|
|
800
796
|
return t;
|
|
801
797
|
}
|
|
802
|
-
function
|
|
803
|
-
return
|
|
798
|
+
function rn(t) {
|
|
799
|
+
return be(t), (t & t - 1) === 0 && t !== 0;
|
|
804
800
|
}
|
|
805
|
-
function
|
|
806
|
-
|
|
807
|
-
let
|
|
808
|
-
for (let
|
|
809
|
-
return
|
|
801
|
+
function Mn(t, e) {
|
|
802
|
+
be(t);
|
|
803
|
+
let r = 0;
|
|
804
|
+
for (let n = 0; n < e; n++, t >>>= 1) r = r << 1 | t & 1;
|
|
805
|
+
return r;
|
|
810
806
|
}
|
|
811
|
-
function
|
|
812
|
-
return
|
|
807
|
+
function on(t) {
|
|
808
|
+
return be(t), 31 - Math.clz32(t);
|
|
813
809
|
}
|
|
814
|
-
function
|
|
815
|
-
const
|
|
816
|
-
if (
|
|
817
|
-
const
|
|
818
|
-
for (let
|
|
819
|
-
const o =
|
|
820
|
-
if (
|
|
821
|
-
const i = t[
|
|
822
|
-
t[
|
|
810
|
+
function Oe(t) {
|
|
811
|
+
const e = t.length;
|
|
812
|
+
if (e < 2 || !rn(e)) throw new Error("n must be a power of 2 and greater than 1. Got " + e);
|
|
813
|
+
const r = on(e);
|
|
814
|
+
for (let n = 0; n < e; n++) {
|
|
815
|
+
const o = Mn(n, r);
|
|
816
|
+
if (n < o) {
|
|
817
|
+
const i = t[n];
|
|
818
|
+
t[n] = t[o], t[o] = i;
|
|
823
819
|
}
|
|
824
820
|
}
|
|
825
821
|
return t;
|
|
826
822
|
}
|
|
827
|
-
var
|
|
828
|
-
|
|
829
|
-
const { N:
|
|
830
|
-
if (
|
|
831
|
-
const
|
|
832
|
-
return (
|
|
833
|
-
if (
|
|
834
|
-
o &&
|
|
835
|
-
for (let
|
|
836
|
-
const
|
|
837
|
-
for (let
|
|
838
|
-
const
|
|
839
|
-
if (
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
} else i ? (
|
|
823
|
+
var Gn, Tr = dt((() => {
|
|
824
|
+
Gn = (t, e) => {
|
|
825
|
+
const { N: r, roots: n, dit: o, invertButterflies: i = !1, skipStages: c = 0, brp: s = !0 } = e, a = on(r);
|
|
826
|
+
if (!rn(r)) throw new Error("FFT: Polynomial size should be power of two");
|
|
827
|
+
const u = o !== i;
|
|
828
|
+
return (f) => {
|
|
829
|
+
if (f.length !== r) throw new Error("FFT: wrong Polynomial length");
|
|
830
|
+
o && s && Oe(f);
|
|
831
|
+
for (let g = 0, m = 1; g < a - c; g++) {
|
|
832
|
+
const w = o ? g + 1 + c : a - g, A = 1 << w, _ = A >> 1, H = r >> w;
|
|
833
|
+
for (let O = 0; O < r; O += A) for (let x = 0, q = m++; x < _; x++) {
|
|
834
|
+
const Z = i ? o ? r - q : q : x * H, T = O + x, Q = O + x + _, $ = n[Z], R = f[Q], C = f[T];
|
|
835
|
+
if (u) {
|
|
836
|
+
const X = t.mul(R, $);
|
|
837
|
+
f[T] = t.add(C, X), f[Q] = t.sub(C, X);
|
|
838
|
+
} else i ? (f[T] = t.add(R, C), f[Q] = t.mul(t.sub(R, C), $)) : (f[T] = t.add(C, R), f[Q] = t.mul(t.sub(C, R), $));
|
|
843
839
|
}
|
|
844
840
|
}
|
|
845
|
-
return !o &&
|
|
841
|
+
return !o && s && Oe(f), f;
|
|
846
842
|
};
|
|
847
843
|
};
|
|
848
844
|
}));
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
var
|
|
852
|
-
function
|
|
845
|
+
Zn();
|
|
846
|
+
It();
|
|
847
|
+
var W = (t, e, r) => mt(t, e, r), sn = Et, cn = le, lt = (...t) => In(...t), se = (t) => Ve(t), fn = Ce, an = (t) => Fn(t), qt = /* @__PURE__ */ BigInt(0), ce = /* @__PURE__ */ BigInt(1);
|
|
848
|
+
function Ot(t, e = "") {
|
|
853
849
|
if (typeof t != "boolean") {
|
|
854
|
-
const
|
|
855
|
-
throw new TypeError(
|
|
850
|
+
const r = e && `"${e}" `;
|
|
851
|
+
throw new TypeError(r + "expected boolean, got type=" + typeof t);
|
|
856
852
|
}
|
|
857
853
|
return t;
|
|
858
854
|
}
|
|
859
|
-
function
|
|
855
|
+
function we(t) {
|
|
860
856
|
if (typeof t == "bigint") {
|
|
861
|
-
if (
|
|
862
|
-
} else
|
|
857
|
+
if (!$t(t)) throw new RangeError("positive bigint expected, got " + t);
|
|
858
|
+
} else sn(t);
|
|
863
859
|
return t;
|
|
864
860
|
}
|
|
865
|
-
function
|
|
861
|
+
function fe(t, e = "") {
|
|
866
862
|
if (typeof t != "number") {
|
|
867
|
-
const
|
|
868
|
-
throw new TypeError(
|
|
863
|
+
const r = e && `"${e}" `;
|
|
864
|
+
throw new TypeError(r + "expected number, got type=" + typeof t);
|
|
869
865
|
}
|
|
870
866
|
if (!Number.isSafeInteger(t)) {
|
|
871
|
-
const
|
|
872
|
-
throw new RangeError(
|
|
867
|
+
const r = e && `"${e}" `;
|
|
868
|
+
throw new RangeError(r + "expected safe integer, got " + t);
|
|
873
869
|
}
|
|
874
870
|
}
|
|
875
|
-
function
|
|
876
|
-
const
|
|
877
|
-
return
|
|
871
|
+
function Nt(t) {
|
|
872
|
+
const e = we(t).toString(16);
|
|
873
|
+
return e.length & 1 ? "0" + e : e;
|
|
878
874
|
}
|
|
879
|
-
function
|
|
875
|
+
function un(t) {
|
|
880
876
|
if (typeof t != "string") throw new TypeError("hex string expected, got " + typeof t);
|
|
881
|
-
return t === "" ?
|
|
882
|
-
}
|
|
883
|
-
function St(t) {
|
|
884
|
-
return Pn(Ke(t));
|
|
877
|
+
return t === "" ? qt : BigInt("0x" + t);
|
|
885
878
|
}
|
|
886
|
-
function
|
|
887
|
-
return
|
|
879
|
+
function Ct(t) {
|
|
880
|
+
return un(le(t));
|
|
888
881
|
}
|
|
889
|
-
function
|
|
890
|
-
|
|
891
|
-
t = Je(t);
|
|
892
|
-
const e = t.toString(16);
|
|
893
|
-
if (e.length > n * 2) throw new RangeError("number too large");
|
|
894
|
-
return _n(e.padStart(n * 2, "0"));
|
|
882
|
+
function ln(t) {
|
|
883
|
+
return un(le(Kn(mt(t)).reverse()));
|
|
895
884
|
}
|
|
896
|
-
function
|
|
897
|
-
|
|
885
|
+
function pe(t, e) {
|
|
886
|
+
if (Et(e), e === 0) throw new RangeError("zero length");
|
|
887
|
+
t = we(t);
|
|
888
|
+
const r = t.toString(16);
|
|
889
|
+
if (r.length > e * 2) throw new RangeError("number too large");
|
|
890
|
+
return Ve(r.padStart(e * 2, "0"));
|
|
898
891
|
}
|
|
899
|
-
function
|
|
900
|
-
return
|
|
892
|
+
function hn(t, e) {
|
|
893
|
+
return pe(t, e).reverse();
|
|
901
894
|
}
|
|
902
|
-
function
|
|
903
|
-
|
|
904
|
-
return Uint8Array.from(t, (n, e) => {
|
|
905
|
-
const r = n.charCodeAt(0);
|
|
906
|
-
if (n.length !== 1 || r > 127) throw new RangeError(`string contains non-ASCII character "${t[e]}" with code ${r} at position ${e}`);
|
|
907
|
-
return r;
|
|
908
|
-
});
|
|
895
|
+
function Kn(t) {
|
|
896
|
+
return Uint8Array.from(W(t));
|
|
909
897
|
}
|
|
910
|
-
var
|
|
911
|
-
function
|
|
912
|
-
return
|
|
898
|
+
var $t = (t) => typeof t == "bigint" && qt <= t;
|
|
899
|
+
function Xn(t, e, r) {
|
|
900
|
+
return $t(t) && $t(e) && $t(r) && e <= t && t < r;
|
|
913
901
|
}
|
|
914
|
-
function
|
|
915
|
-
if (!
|
|
902
|
+
function dn(t, e, r, n) {
|
|
903
|
+
if (!Xn(e, r, n)) throw new RangeError("expected valid " + t + ": " + r + " <= n < " + n + ", got " + e);
|
|
916
904
|
}
|
|
917
905
|
function ye(t) {
|
|
918
|
-
if (t <
|
|
919
|
-
let
|
|
920
|
-
for (
|
|
921
|
-
return
|
|
906
|
+
if (t < qt) throw new Error("expected non-negative bigint, got " + t);
|
|
907
|
+
let e;
|
|
908
|
+
for (e = 0; t > qt; t >>= ce, e += 1) ;
|
|
909
|
+
return e;
|
|
922
910
|
}
|
|
923
|
-
var
|
|
924
|
-
function
|
|
925
|
-
if (
|
|
926
|
-
const
|
|
927
|
-
let
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
},
|
|
931
|
-
|
|
932
|
-
},
|
|
933
|
-
if (
|
|
934
|
-
let
|
|
935
|
-
const
|
|
936
|
-
for (;
|
|
937
|
-
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
}
|
|
941
|
-
return
|
|
911
|
+
var Ee = (t) => (ce << BigInt(t)) - ce;
|
|
912
|
+
function Wn(t, e, r) {
|
|
913
|
+
if (Et(t, "hashLen"), Et(e, "qByteLen"), typeof r != "function") throw new TypeError("hmacFn must be a function");
|
|
914
|
+
const n = (H) => new Uint8Array(H), o = Uint8Array.of(), i = Uint8Array.of(0), c = Uint8Array.of(1), s = 1e3;
|
|
915
|
+
let a = n(t), u = n(t), f = 0;
|
|
916
|
+
const g = () => {
|
|
917
|
+
a.fill(1), u.fill(0), f = 0;
|
|
918
|
+
}, m = (...H) => r(u, lt(a, ...H)), w = (H = o) => {
|
|
919
|
+
u = m(i, H), a = m(), H.length !== 0 && (u = m(c, H), a = m());
|
|
920
|
+
}, A = () => {
|
|
921
|
+
if (f++ >= s) throw new Error("drbg: tried max amount of iterations");
|
|
922
|
+
let H = 0;
|
|
923
|
+
const O = [];
|
|
924
|
+
for (; H < e; ) {
|
|
925
|
+
a = m();
|
|
926
|
+
const x = a.slice();
|
|
927
|
+
O.push(x), H += a.length;
|
|
928
|
+
}
|
|
929
|
+
return lt(...O);
|
|
942
930
|
};
|
|
943
|
-
return (
|
|
944
|
-
|
|
945
|
-
let
|
|
946
|
-
for (; (
|
|
947
|
-
return
|
|
931
|
+
return (H, O) => {
|
|
932
|
+
g(), w(H);
|
|
933
|
+
let x;
|
|
934
|
+
for (; (x = O(A())) === void 0; ) w();
|
|
935
|
+
return g(), x;
|
|
948
936
|
};
|
|
949
937
|
}
|
|
950
|
-
function
|
|
938
|
+
function kt(t, e = {}, r = {}) {
|
|
951
939
|
if (Object.prototype.toString.call(t) !== "[object Object]") throw new TypeError("expected valid options object");
|
|
952
|
-
function
|
|
953
|
-
if (!
|
|
954
|
-
const
|
|
955
|
-
if (
|
|
956
|
-
const
|
|
957
|
-
if (
|
|
958
|
-
}
|
|
959
|
-
const o = (i,
|
|
960
|
-
o(
|
|
961
|
-
}
|
|
962
|
-
var
|
|
963
|
-
function
|
|
964
|
-
if (
|
|
965
|
-
const
|
|
966
|
-
return
|
|
967
|
-
}
|
|
968
|
-
function
|
|
969
|
-
if (
|
|
970
|
-
let
|
|
971
|
-
for (;
|
|
972
|
-
|
|
973
|
-
return
|
|
940
|
+
function n(i, c, s) {
|
|
941
|
+
if (!s && c !== "function" && !Object.hasOwn(t, i)) throw new TypeError(`param "${i}" is invalid: expected own property`);
|
|
942
|
+
const a = t[i];
|
|
943
|
+
if (s && a === void 0) return;
|
|
944
|
+
const u = typeof a;
|
|
945
|
+
if (u !== c || a === null) throw new TypeError(`param "${i}" is invalid: expected ${c}, got ${u}`);
|
|
946
|
+
}
|
|
947
|
+
const o = (i, c) => Object.entries(i).forEach(([s, a]) => n(s, a, c));
|
|
948
|
+
o(e, !1), o(r, !0);
|
|
949
|
+
}
|
|
950
|
+
var K = /* @__PURE__ */ BigInt(0), D = /* @__PURE__ */ BigInt(1), pt = /* @__PURE__ */ BigInt(2), gn = /* @__PURE__ */ BigInt(3), bn = /* @__PURE__ */ BigInt(4), wn = /* @__PURE__ */ BigInt(5), Qn = /* @__PURE__ */ BigInt(7), pn = /* @__PURE__ */ BigInt(8), Jn = /* @__PURE__ */ BigInt(9), yn = /* @__PURE__ */ BigInt(16);
|
|
951
|
+
function tt(t, e) {
|
|
952
|
+
if (e <= K) throw new Error("mod: expected positive modulus, got " + e);
|
|
953
|
+
const r = t % e;
|
|
954
|
+
return r >= K ? r : e + r;
|
|
955
|
+
}
|
|
956
|
+
function P(t, e, r) {
|
|
957
|
+
if (e < K) throw new Error("pow2: expected non-negative exponent, got " + e);
|
|
958
|
+
let n = t;
|
|
959
|
+
for (; e-- > K; )
|
|
960
|
+
n *= n, n %= r;
|
|
961
|
+
return n;
|
|
974
962
|
}
|
|
975
|
-
function
|
|
976
|
-
if (t ===
|
|
977
|
-
if (
|
|
978
|
-
let
|
|
979
|
-
for (;
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
}
|
|
983
|
-
if (
|
|
984
|
-
return
|
|
985
|
-
}
|
|
986
|
-
function
|
|
987
|
-
const
|
|
988
|
-
if (!
|
|
989
|
-
}
|
|
990
|
-
function
|
|
991
|
-
const
|
|
992
|
-
return
|
|
993
|
-
}
|
|
994
|
-
function
|
|
995
|
-
const
|
|
996
|
-
return
|
|
997
|
-
}
|
|
998
|
-
function
|
|
999
|
-
const
|
|
1000
|
-
return ((
|
|
1001
|
-
const
|
|
1002
|
-
let
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
const
|
|
1006
|
-
return
|
|
963
|
+
function Ie(t, e) {
|
|
964
|
+
if (t === K) throw new Error("invert: expected non-zero number");
|
|
965
|
+
if (e <= K) throw new Error("invert: expected positive modulus, got " + e);
|
|
966
|
+
let r = tt(t, e), n = e, o = K, i = D, c = D, s = K;
|
|
967
|
+
for (; r !== K; ) {
|
|
968
|
+
const a = n / r, u = n - r * a, f = o - c * a, g = i - s * a;
|
|
969
|
+
n = r, r = u, o = c, i = s, c = f, s = g;
|
|
970
|
+
}
|
|
971
|
+
if (n !== D) throw new Error("invert: does not exist");
|
|
972
|
+
return tt(o, e);
|
|
973
|
+
}
|
|
974
|
+
function me(t, e, r) {
|
|
975
|
+
const n = t;
|
|
976
|
+
if (!n.eql(n.sqr(e), r)) throw new Error("Cannot find square root");
|
|
977
|
+
}
|
|
978
|
+
function En(t, e) {
|
|
979
|
+
const r = t, n = (r.ORDER + D) / bn, o = r.pow(e, n);
|
|
980
|
+
return me(r, o, e), o;
|
|
981
|
+
}
|
|
982
|
+
function Pn(t, e) {
|
|
983
|
+
const r = t, n = (r.ORDER - wn) / pn, o = r.mul(e, pt), i = r.pow(o, n), c = r.mul(e, i), s = r.mul(r.mul(c, pt), i), a = r.mul(c, r.sub(s, r.ONE));
|
|
984
|
+
return me(r, a, e), a;
|
|
985
|
+
}
|
|
986
|
+
function tr(t) {
|
|
987
|
+
const e = jt(t), r = mn(t), n = r(e, e.neg(e.ONE)), o = r(e, n), i = r(e, e.neg(n)), c = (t + Qn) / yn;
|
|
988
|
+
return ((s, a) => {
|
|
989
|
+
const u = s;
|
|
990
|
+
let f = u.pow(a, c), g = u.mul(f, n);
|
|
991
|
+
const m = u.mul(f, o), w = u.mul(f, i), A = u.eql(u.sqr(g), a), _ = u.eql(u.sqr(m), a);
|
|
992
|
+
f = u.cmov(f, g, A), g = u.cmov(w, m, _);
|
|
993
|
+
const H = u.eql(u.sqr(g), a), O = u.cmov(f, g, H);
|
|
994
|
+
return me(u, O, a), O;
|
|
1007
995
|
});
|
|
1008
996
|
}
|
|
1009
|
-
function
|
|
1010
|
-
if (t <
|
|
1011
|
-
let
|
|
1012
|
-
for (;
|
|
1013
|
-
|
|
1014
|
-
let
|
|
1015
|
-
const o =
|
|
1016
|
-
for (;
|
|
1017
|
-
if (
|
|
1018
|
-
let i = o.pow(
|
|
1019
|
-
const
|
|
1020
|
-
return function(
|
|
1021
|
-
const
|
|
1022
|
-
if (
|
|
1023
|
-
if (
|
|
1024
|
-
let
|
|
1025
|
-
for (; !
|
|
1026
|
-
if (
|
|
1027
|
-
let
|
|
1028
|
-
for (; !
|
|
1029
|
-
if (
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
}
|
|
1033
|
-
return
|
|
997
|
+
function mn(t) {
|
|
998
|
+
if (t < gn) throw new Error("sqrt is not defined for small field");
|
|
999
|
+
let e = t - D, r = 0;
|
|
1000
|
+
for (; e % pt === K; )
|
|
1001
|
+
e /= pt, r++;
|
|
1002
|
+
let n = pt;
|
|
1003
|
+
const o = jt(t);
|
|
1004
|
+
for (; Fe(o, n) === 1; ) if (n++ > 1e3) throw new Error("Cannot find square root: probably non-prime P");
|
|
1005
|
+
if (r === 1) return En;
|
|
1006
|
+
let i = o.pow(n, e);
|
|
1007
|
+
const c = (e + D) / pt;
|
|
1008
|
+
return function(a, u) {
|
|
1009
|
+
const f = a;
|
|
1010
|
+
if (f.is0(u)) return u;
|
|
1011
|
+
if (Fe(f, u) !== 1) throw new Error("Cannot find square root");
|
|
1012
|
+
let g = r, m = f.mul(f.ONE, i), w = f.pow(u, e), A = f.pow(u, c);
|
|
1013
|
+
for (; !f.eql(w, f.ONE); ) {
|
|
1014
|
+
if (f.is0(w)) return f.ZERO;
|
|
1015
|
+
let _ = 1, H = f.sqr(w);
|
|
1016
|
+
for (; !f.eql(H, f.ONE); )
|
|
1017
|
+
if (_++, H = f.sqr(H), _ === g) throw new Error("Cannot find square root");
|
|
1018
|
+
const O = D << BigInt(g - _ - 1), x = f.pow(m, O);
|
|
1019
|
+
g = _, m = f.sqr(x), w = f.mul(w, m), A = f.mul(A, x);
|
|
1020
|
+
}
|
|
1021
|
+
return A;
|
|
1034
1022
|
};
|
|
1035
1023
|
}
|
|
1036
|
-
function
|
|
1037
|
-
return t %
|
|
1024
|
+
function er(t) {
|
|
1025
|
+
return t % bn === gn ? En : t % pn === wn ? Pn : t % yn === Jn ? tr(t) : mn(t);
|
|
1038
1026
|
}
|
|
1039
|
-
var
|
|
1027
|
+
var nr = [
|
|
1040
1028
|
"create",
|
|
1041
1029
|
"isValid",
|
|
1042
1030
|
"is0",
|
|
@@ -1055,1088 +1043,347 @@ var Pr = [
|
|
|
1055
1043
|
"mulN",
|
|
1056
1044
|
"sqrN"
|
|
1057
1045
|
];
|
|
1058
|
-
function
|
|
1059
|
-
if (
|
|
1046
|
+
function rr(t) {
|
|
1047
|
+
if (kt(t, nr.reduce((e, r) => (e[r] = "function", e), {
|
|
1060
1048
|
ORDER: "bigint",
|
|
1061
1049
|
BYTES: "number",
|
|
1062
1050
|
BITS: "number"
|
|
1063
|
-
})),
|
|
1064
|
-
if (t.ORDER <=
|
|
1051
|
+
})), fe(t.BYTES, "BYTES"), fe(t.BITS, "BITS"), t.BYTES < 1 || t.BITS < 1) throw new Error("invalid field: expected BYTES/BITS > 0");
|
|
1052
|
+
if (t.ORDER <= D) throw new Error("invalid field: expected ORDER > 1, got " + t.ORDER);
|
|
1065
1053
|
return t;
|
|
1066
1054
|
}
|
|
1067
|
-
function
|
|
1068
|
-
const
|
|
1069
|
-
if (
|
|
1070
|
-
if (
|
|
1071
|
-
if (
|
|
1072
|
-
let o =
|
|
1073
|
-
for (;
|
|
1074
|
-
|
|
1055
|
+
function or(t, e, r) {
|
|
1056
|
+
const n = t;
|
|
1057
|
+
if (r < K) throw new Error("invalid exponent, negatives unsupported");
|
|
1058
|
+
if (r === K) return n.ONE;
|
|
1059
|
+
if (r === D) return e;
|
|
1060
|
+
let o = n.ONE, i = e;
|
|
1061
|
+
for (; r > K; )
|
|
1062
|
+
r & D && (o = n.mul(o, i)), i = n.sqr(i), r >>= D;
|
|
1075
1063
|
return o;
|
|
1076
1064
|
}
|
|
1077
|
-
function
|
|
1078
|
-
const
|
|
1079
|
-
return
|
|
1080
|
-
}
|
|
1081
|
-
function
|
|
1082
|
-
const
|
|
1083
|
-
if (!i && !
|
|
1084
|
-
return i ? 1 :
|
|
1085
|
-
}
|
|
1086
|
-
function
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
if (
|
|
1091
|
-
|
|
1092
|
-
const e = ye(t);
|
|
1093
|
-
if (n !== void 0 && n < e) throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${n})`);
|
|
1094
|
-
const r = n !== void 0 ? n : e;
|
|
1065
|
+
function vn(t, e, r = !1) {
|
|
1066
|
+
const n = t, o = new Array(e.length).fill(r ? n.ZERO : void 0), i = e.reduce((s, a, u) => n.is0(a) ? s : (o[u] = s, n.mul(s, a)), n.ONE), c = n.inv(i);
|
|
1067
|
+
return e.reduceRight((s, a, u) => n.is0(a) ? s : (o[u] = n.mul(s, o[u]), n.mul(s, a)), c), o;
|
|
1068
|
+
}
|
|
1069
|
+
function Fe(t, e) {
|
|
1070
|
+
const r = t, n = (r.ORDER - D) / pt, o = r.pow(e, n), i = r.eql(o, r.ONE), c = r.eql(o, r.ZERO), s = r.eql(o, r.neg(r.ONE));
|
|
1071
|
+
if (!i && !c && !s) throw new Error("invalid Legendre symbol result");
|
|
1072
|
+
return i ? 1 : c ? 0 : -1;
|
|
1073
|
+
}
|
|
1074
|
+
function ir(t, e) {
|
|
1075
|
+
if (e !== void 0 && sn(e), t <= K) throw new Error("invalid n length: expected positive n, got " + t);
|
|
1076
|
+
if (e !== void 0 && e < 1) throw new Error("invalid n length: expected positive bit length, got " + e);
|
|
1077
|
+
const r = ye(t);
|
|
1078
|
+
if (e !== void 0 && e < r) throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);
|
|
1079
|
+
const n = e !== void 0 ? e : r;
|
|
1095
1080
|
return {
|
|
1096
|
-
nBitLength:
|
|
1097
|
-
nByteLength: Math.ceil(
|
|
1081
|
+
nBitLength: n,
|
|
1082
|
+
nByteLength: Math.ceil(n / 8)
|
|
1098
1083
|
};
|
|
1099
1084
|
}
|
|
1100
|
-
var
|
|
1085
|
+
var Le = /* @__PURE__ */ new WeakMap(), xn = class {
|
|
1101
1086
|
ORDER;
|
|
1102
1087
|
BITS;
|
|
1103
1088
|
BYTES;
|
|
1104
1089
|
isLE;
|
|
1105
|
-
ZERO =
|
|
1106
|
-
ONE =
|
|
1090
|
+
ZERO = K;
|
|
1091
|
+
ONE = D;
|
|
1107
1092
|
_lengths;
|
|
1108
1093
|
_mod;
|
|
1109
|
-
constructor(t,
|
|
1110
|
-
if (t <=
|
|
1111
|
-
let
|
|
1112
|
-
this.isLE = !1,
|
|
1113
|
-
value:
|
|
1094
|
+
constructor(t, e = {}) {
|
|
1095
|
+
if (t <= D) throw new Error("invalid field: expected ORDER > 1, got " + t);
|
|
1096
|
+
let r;
|
|
1097
|
+
this.isLE = !1, e != null && typeof e == "object" && (typeof e.BITS == "number" && (r = e.BITS), typeof e.sqrt == "function" && Object.defineProperty(this, "sqrt", {
|
|
1098
|
+
value: e.sqrt,
|
|
1114
1099
|
enumerable: !0
|
|
1115
|
-
}), typeof
|
|
1116
|
-
const { nBitLength:
|
|
1100
|
+
}), typeof e.isLE == "boolean" && (this.isLE = e.isLE), e.allowedLengths && (this._lengths = Object.freeze(e.allowedLengths.slice())), typeof e.modFromBytes == "boolean" && (this._mod = e.modFromBytes));
|
|
1101
|
+
const { nBitLength: n, nByteLength: o } = ir(t, r);
|
|
1117
1102
|
if (o > 2048) throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1118
|
-
this.ORDER = t, this.BITS =
|
|
1103
|
+
this.ORDER = t, this.BITS = n, this.BYTES = o, Object.freeze(this);
|
|
1119
1104
|
}
|
|
1120
1105
|
create(t) {
|
|
1121
|
-
return
|
|
1106
|
+
return tt(t, this.ORDER);
|
|
1122
1107
|
}
|
|
1123
1108
|
isValid(t) {
|
|
1124
1109
|
if (typeof t != "bigint") throw new TypeError("invalid field element: expected bigint, got " + typeof t);
|
|
1125
|
-
return
|
|
1110
|
+
return K <= t && t < this.ORDER;
|
|
1126
1111
|
}
|
|
1127
1112
|
is0(t) {
|
|
1128
|
-
return t ===
|
|
1113
|
+
return t === K;
|
|
1129
1114
|
}
|
|
1130
1115
|
isValidNot0(t) {
|
|
1131
1116
|
return !this.is0(t) && this.isValid(t);
|
|
1132
1117
|
}
|
|
1133
1118
|
isOdd(t) {
|
|
1134
|
-
return (t &
|
|
1119
|
+
return (t & D) === D;
|
|
1135
1120
|
}
|
|
1136
1121
|
neg(t) {
|
|
1137
|
-
return
|
|
1122
|
+
return tt(-t, this.ORDER);
|
|
1138
1123
|
}
|
|
1139
|
-
eql(t,
|
|
1140
|
-
return t ===
|
|
1124
|
+
eql(t, e) {
|
|
1125
|
+
return t === e;
|
|
1141
1126
|
}
|
|
1142
1127
|
sqr(t) {
|
|
1143
|
-
return
|
|
1128
|
+
return tt(t * t, this.ORDER);
|
|
1144
1129
|
}
|
|
1145
|
-
add(t,
|
|
1146
|
-
return
|
|
1130
|
+
add(t, e) {
|
|
1131
|
+
return tt(t + e, this.ORDER);
|
|
1147
1132
|
}
|
|
1148
|
-
sub(t,
|
|
1149
|
-
return
|
|
1133
|
+
sub(t, e) {
|
|
1134
|
+
return tt(t - e, this.ORDER);
|
|
1150
1135
|
}
|
|
1151
|
-
mul(t,
|
|
1152
|
-
return
|
|
1136
|
+
mul(t, e) {
|
|
1137
|
+
return tt(t * e, this.ORDER);
|
|
1153
1138
|
}
|
|
1154
|
-
pow(t,
|
|
1155
|
-
return
|
|
1139
|
+
pow(t, e) {
|
|
1140
|
+
return or(this, t, e);
|
|
1156
1141
|
}
|
|
1157
|
-
div(t,
|
|
1158
|
-
return
|
|
1142
|
+
div(t, e) {
|
|
1143
|
+
return tt(t * Ie(e, this.ORDER), this.ORDER);
|
|
1159
1144
|
}
|
|
1160
1145
|
sqrN(t) {
|
|
1161
1146
|
return t * t;
|
|
1162
1147
|
}
|
|
1163
|
-
addN(t,
|
|
1164
|
-
return t +
|
|
1148
|
+
addN(t, e) {
|
|
1149
|
+
return t + e;
|
|
1165
1150
|
}
|
|
1166
|
-
subN(t,
|
|
1167
|
-
return t -
|
|
1151
|
+
subN(t, e) {
|
|
1152
|
+
return t - e;
|
|
1168
1153
|
}
|
|
1169
|
-
mulN(t,
|
|
1170
|
-
return t *
|
|
1154
|
+
mulN(t, e) {
|
|
1155
|
+
return t * e;
|
|
1171
1156
|
}
|
|
1172
1157
|
inv(t) {
|
|
1173
|
-
return
|
|
1158
|
+
return Ie(t, this.ORDER);
|
|
1174
1159
|
}
|
|
1175
1160
|
sqrt(t) {
|
|
1176
|
-
let
|
|
1177
|
-
return
|
|
1161
|
+
let e = Le.get(this);
|
|
1162
|
+
return e || Le.set(this, e = er(this.ORDER)), e(this, t);
|
|
1178
1163
|
}
|
|
1179
1164
|
toBytes(t) {
|
|
1180
|
-
return this.isLE ?
|
|
1181
|
-
}
|
|
1182
|
-
fromBytes(t,
|
|
1183
|
-
|
|
1184
|
-
const { _lengths:
|
|
1185
|
-
if (
|
|
1186
|
-
if (t.length < 1 || !
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
if (t.length !==
|
|
1191
|
-
let
|
|
1192
|
-
if (
|
|
1165
|
+
return this.isLE ? hn(t, this.BYTES) : pe(t, this.BYTES);
|
|
1166
|
+
}
|
|
1167
|
+
fromBytes(t, e = !1) {
|
|
1168
|
+
W(t);
|
|
1169
|
+
const { _lengths: r, BYTES: n, isLE: o, ORDER: i, _mod: c } = this;
|
|
1170
|
+
if (r) {
|
|
1171
|
+
if (t.length < 1 || !r.includes(t.length) || t.length > n) throw new Error("Field.fromBytes: expected " + r + " bytes, got " + t.length);
|
|
1172
|
+
const a = new Uint8Array(n);
|
|
1173
|
+
a.set(t, o ? 0 : a.length - t.length), t = a;
|
|
1174
|
+
}
|
|
1175
|
+
if (t.length !== n) throw new Error("Field.fromBytes: expected " + n + " bytes, got " + t.length);
|
|
1176
|
+
let s = o ? ln(t) : Ct(t);
|
|
1177
|
+
if (c && (s = tt(s, i)), !e && !this.isValid(s))
|
|
1193
1178
|
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
1194
|
-
return
|
|
1179
|
+
return s;
|
|
1195
1180
|
}
|
|
1196
1181
|
invertBatch(t) {
|
|
1197
|
-
return
|
|
1182
|
+
return vn(this, t);
|
|
1198
1183
|
}
|
|
1199
|
-
cmov(t,
|
|
1200
|
-
return
|
|
1184
|
+
cmov(t, e, r) {
|
|
1185
|
+
return Ot(r, "condition"), r ? e : t;
|
|
1201
1186
|
}
|
|
1202
1187
|
};
|
|
1203
|
-
Object.freeze(
|
|
1204
|
-
function
|
|
1205
|
-
return new
|
|
1188
|
+
Object.freeze(xn.prototype);
|
|
1189
|
+
function jt(t, e = {}) {
|
|
1190
|
+
return new xn(t, e);
|
|
1206
1191
|
}
|
|
1207
|
-
function
|
|
1192
|
+
function Bn(t) {
|
|
1208
1193
|
if (typeof t != "bigint") throw new Error("field order must be bigint");
|
|
1209
|
-
if (t <=
|
|
1210
|
-
const
|
|
1211
|
-
return Math.ceil(
|
|
1212
|
-
}
|
|
1213
|
-
function nn(t) {
|
|
1214
|
-
const n = er(t);
|
|
1215
|
-
return n + Math.ceil(n / 2);
|
|
1216
|
-
}
|
|
1217
|
-
function nr(t, n, e = !1) {
|
|
1218
|
-
st(t);
|
|
1219
|
-
const r = t.length, o = er(n), i = Math.max(nn(n), 16);
|
|
1220
|
-
if (r < i || r > 1024) throw new Error("expected " + i + "-1024 bytes of input, got " + r);
|
|
1221
|
-
const a = bt(e ? ge(t) : St(t), n - ot) + ot;
|
|
1222
|
-
return e ? zn(a, o) : tn(a, o);
|
|
1223
|
-
}
|
|
1224
|
-
var Wt = /* @__PURE__ */ BigInt(0), Zt = /* @__PURE__ */ BigInt(1);
|
|
1225
|
-
function Gr(t) {
|
|
1226
|
-
const n = t;
|
|
1227
|
-
if (typeof n != "function") throw new TypeError("Point must be a constructor");
|
|
1228
|
-
Mt({
|
|
1229
|
-
Fp: n.Fp,
|
|
1230
|
-
Fn: n.Fn,
|
|
1231
|
-
fromAffine: n.fromAffine,
|
|
1232
|
-
fromBytes: n.fromBytes,
|
|
1233
|
-
fromHex: n.fromHex
|
|
1234
|
-
}, {
|
|
1235
|
-
Fp: "object",
|
|
1236
|
-
Fn: "object",
|
|
1237
|
-
fromAffine: "function",
|
|
1238
|
-
fromBytes: "function",
|
|
1239
|
-
fromHex: "function"
|
|
1240
|
-
}), se(n.Fp), se(n.Fn);
|
|
1241
|
-
}
|
|
1242
|
-
function we(t, n) {
|
|
1243
|
-
const e = n.negate();
|
|
1244
|
-
return t ? e : n;
|
|
1245
|
-
}
|
|
1246
|
-
function gn(t, n) {
|
|
1247
|
-
const e = Ee(t.Fp, n.map((r) => r.Z));
|
|
1248
|
-
return n.map((r, o) => t.fromAffine(r.toAffine(e[o])));
|
|
1249
|
-
}
|
|
1250
|
-
function rr(t, n) {
|
|
1251
|
-
if (!Number.isSafeInteger(t) || t <= 0 || t > n) throw new Error("invalid window size, expected [1.." + n + "], got W=" + t);
|
|
1194
|
+
if (t <= D) throw new Error("field order must be greater than 1");
|
|
1195
|
+
const e = ye(t - D);
|
|
1196
|
+
return Math.ceil(e / 8);
|
|
1252
1197
|
}
|
|
1253
|
-
function
|
|
1254
|
-
|
|
1255
|
-
|
|
1198
|
+
function An(t) {
|
|
1199
|
+
const e = Bn(t);
|
|
1200
|
+
return e + Math.ceil(e / 2);
|
|
1201
|
+
}
|
|
1202
|
+
function sr(t, e, r = !1) {
|
|
1203
|
+
W(t);
|
|
1204
|
+
const n = t.length, o = Bn(e), i = Math.max(An(e), 16);
|
|
1205
|
+
if (n < i || n > 1024) throw new Error("expected " + i + "-1024 bytes of input, got " + n);
|
|
1206
|
+
const c = tt(r ? ln(t) : Ct(t), e - D) + D;
|
|
1207
|
+
return r ? hn(c, o) : pe(c, o);
|
|
1208
|
+
}
|
|
1209
|
+
var At = /* @__PURE__ */ BigInt(0), yt = /* @__PURE__ */ BigInt(1);
|
|
1210
|
+
function Zt(t, e) {
|
|
1211
|
+
const r = e.negate();
|
|
1212
|
+
return t ? r : e;
|
|
1213
|
+
}
|
|
1214
|
+
function Ne(t, e) {
|
|
1215
|
+
const r = vn(t.Fp, e.map((n) => n.Z));
|
|
1216
|
+
return e.map((n, o) => t.fromAffine(n.toAffine(r[o])));
|
|
1217
|
+
}
|
|
1218
|
+
function Rn(t, e) {
|
|
1219
|
+
if (!Number.isSafeInteger(t) || t <= 0 || t > e) throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
|
|
1220
|
+
}
|
|
1221
|
+
function Mt(t, e) {
|
|
1222
|
+
Rn(t, e);
|
|
1223
|
+
const r = Math.ceil(e / t) + 1, n = 2 ** (t - 1), o = 2 ** t;
|
|
1256
1224
|
return {
|
|
1257
|
-
windows:
|
|
1258
|
-
windowSize:
|
|
1259
|
-
mask:
|
|
1225
|
+
windows: r,
|
|
1226
|
+
windowSize: n,
|
|
1227
|
+
mask: Ee(t),
|
|
1260
1228
|
maxNumber: o,
|
|
1261
1229
|
shiftBy: BigInt(t)
|
|
1262
1230
|
};
|
|
1263
1231
|
}
|
|
1264
|
-
function
|
|
1265
|
-
const { windowSize:
|
|
1266
|
-
let
|
|
1267
|
-
|
|
1268
|
-
const
|
|
1232
|
+
function Te(t, e, r) {
|
|
1233
|
+
const { windowSize: n, mask: o, maxNumber: i, shiftBy: c } = r;
|
|
1234
|
+
let s = Number(t & o), a = t >> c;
|
|
1235
|
+
s > n && (s -= i, a += yt);
|
|
1236
|
+
const u = e * n, f = u + Math.abs(s) - 1, g = s === 0, m = s < 0, w = e % 2 !== 0;
|
|
1269
1237
|
return {
|
|
1270
|
-
nextN:
|
|
1271
|
-
offset:
|
|
1272
|
-
isZero:
|
|
1273
|
-
isNeg:
|
|
1274
|
-
isNegF:
|
|
1275
|
-
offsetF:
|
|
1238
|
+
nextN: a,
|
|
1239
|
+
offset: f,
|
|
1240
|
+
isZero: g,
|
|
1241
|
+
isNeg: m,
|
|
1242
|
+
isNegF: w,
|
|
1243
|
+
offsetF: u
|
|
1276
1244
|
};
|
|
1277
1245
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
if (!(e instanceof n)) throw new Error("invalid point at index " + r);
|
|
1282
|
-
});
|
|
1246
|
+
var Gt = /* @__PURE__ */ new WeakMap(), Sn = /* @__PURE__ */ new WeakMap();
|
|
1247
|
+
function Kt(t) {
|
|
1248
|
+
return Sn.get(t) || 1;
|
|
1283
1249
|
}
|
|
1284
|
-
function
|
|
1285
|
-
if (
|
|
1286
|
-
t.forEach((e, r) => {
|
|
1287
|
-
if (!n.isValid(e)) throw new Error("invalid scalar at index " + r);
|
|
1288
|
-
});
|
|
1250
|
+
function Ue(t) {
|
|
1251
|
+
if (t !== At) throw new Error("invalid wNAF");
|
|
1289
1252
|
}
|
|
1290
|
-
var
|
|
1291
|
-
function Oe(t) {
|
|
1292
|
-
return or.get(t) || 1;
|
|
1293
|
-
}
|
|
1294
|
-
function bn(t) {
|
|
1295
|
-
if (t !== Wt) throw new Error("invalid wNAF");
|
|
1296
|
-
}
|
|
1297
|
-
var Xr = class {
|
|
1253
|
+
var cr = class {
|
|
1298
1254
|
BASE;
|
|
1299
1255
|
ZERO;
|
|
1300
1256
|
Fn;
|
|
1301
1257
|
bits;
|
|
1302
|
-
constructor(t,
|
|
1303
|
-
this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits =
|
|
1304
|
-
}
|
|
1305
|
-
_unsafeLadder(t,
|
|
1306
|
-
let
|
|
1307
|
-
for (;
|
|
1308
|
-
|
|
1309
|
-
return
|
|
1310
|
-
}
|
|
1311
|
-
precomputeWindow(t,
|
|
1312
|
-
const { windows:
|
|
1313
|
-
let i = t,
|
|
1314
|
-
for (let
|
|
1315
|
-
|
|
1316
|
-
for (let
|
|
1317
|
-
|
|
1318
|
-
i =
|
|
1258
|
+
constructor(t, e) {
|
|
1259
|
+
this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = e;
|
|
1260
|
+
}
|
|
1261
|
+
_unsafeLadder(t, e, r = this.ZERO) {
|
|
1262
|
+
let n = t;
|
|
1263
|
+
for (; e > At; )
|
|
1264
|
+
e & yt && (r = r.add(n)), n = n.double(), e >>= yt;
|
|
1265
|
+
return r;
|
|
1266
|
+
}
|
|
1267
|
+
precomputeWindow(t, e) {
|
|
1268
|
+
const { windows: r, windowSize: n } = Mt(e, this.bits), o = [];
|
|
1269
|
+
let i = t, c = i;
|
|
1270
|
+
for (let s = 0; s < r; s++) {
|
|
1271
|
+
c = i, o.push(c);
|
|
1272
|
+
for (let a = 1; a < n; a++)
|
|
1273
|
+
c = c.add(i), o.push(c);
|
|
1274
|
+
i = c.double();
|
|
1319
1275
|
}
|
|
1320
1276
|
return o;
|
|
1321
1277
|
}
|
|
1322
|
-
wNAF(t,
|
|
1323
|
-
if (!this.Fn.isValid(
|
|
1324
|
-
let
|
|
1325
|
-
const i =
|
|
1326
|
-
for (let
|
|
1327
|
-
const { nextN:
|
|
1328
|
-
|
|
1278
|
+
wNAF(t, e, r) {
|
|
1279
|
+
if (!this.Fn.isValid(r)) throw new Error("invalid scalar");
|
|
1280
|
+
let n = this.ZERO, o = this.BASE;
|
|
1281
|
+
const i = Mt(t, this.bits);
|
|
1282
|
+
for (let c = 0; c < i.windows; c++) {
|
|
1283
|
+
const { nextN: s, offset: a, isZero: u, isNeg: f, isNegF: g, offsetF: m } = Te(r, c, i);
|
|
1284
|
+
r = s, u ? o = o.add(Zt(g, e[m])) : n = n.add(Zt(f, e[a]));
|
|
1329
1285
|
}
|
|
1330
|
-
return
|
|
1331
|
-
p:
|
|
1286
|
+
return Ue(r), {
|
|
1287
|
+
p: n,
|
|
1332
1288
|
f: o
|
|
1333
1289
|
};
|
|
1334
1290
|
}
|
|
1335
|
-
wNAFUnsafe(t,
|
|
1336
|
-
const o =
|
|
1337
|
-
for (let i = 0; i < o.windows &&
|
|
1338
|
-
const { nextN:
|
|
1339
|
-
if (
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1291
|
+
wNAFUnsafe(t, e, r, n = this.ZERO) {
|
|
1292
|
+
const o = Mt(t, this.bits);
|
|
1293
|
+
for (let i = 0; i < o.windows && r !== At; i++) {
|
|
1294
|
+
const { nextN: c, offset: s, isZero: a, isNeg: u } = Te(r, i, o);
|
|
1295
|
+
if (r = c, !a) {
|
|
1296
|
+
const f = e[s];
|
|
1297
|
+
n = n.add(u ? f.negate() : f);
|
|
1342
1298
|
}
|
|
1343
1299
|
}
|
|
1344
|
-
return
|
|
1300
|
+
return Ue(r), n;
|
|
1345
1301
|
}
|
|
1346
|
-
getPrecomputes(t,
|
|
1347
|
-
let
|
|
1348
|
-
return
|
|
1302
|
+
getPrecomputes(t, e, r) {
|
|
1303
|
+
let n = Gt.get(e);
|
|
1304
|
+
return n || (n = this.precomputeWindow(e, t), t !== 1 && (typeof r == "function" && (n = r(n)), Gt.set(e, n))), n;
|
|
1349
1305
|
}
|
|
1350
|
-
cached(t,
|
|
1351
|
-
const
|
|
1352
|
-
return this.wNAF(
|
|
1306
|
+
cached(t, e, r) {
|
|
1307
|
+
const n = Kt(t);
|
|
1308
|
+
return this.wNAF(n, this.getPrecomputes(n, t, r), e);
|
|
1353
1309
|
}
|
|
1354
|
-
unsafe(t,
|
|
1355
|
-
const o =
|
|
1356
|
-
return o === 1 ? this._unsafeLadder(t,
|
|
1310
|
+
unsafe(t, e, r, n) {
|
|
1311
|
+
const o = Kt(t);
|
|
1312
|
+
return o === 1 ? this._unsafeLadder(t, e, n) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, r), e, n);
|
|
1357
1313
|
}
|
|
1358
|
-
createCache(t,
|
|
1359
|
-
|
|
1314
|
+
createCache(t, e) {
|
|
1315
|
+
Rn(e, this.bits), Sn.set(t, e), Gt.delete(t);
|
|
1360
1316
|
}
|
|
1361
1317
|
hasCache(t) {
|
|
1362
|
-
return
|
|
1318
|
+
return Kt(t) !== 1;
|
|
1363
1319
|
}
|
|
1364
1320
|
};
|
|
1365
|
-
function
|
|
1366
|
-
let o =
|
|
1367
|
-
for (;
|
|
1368
|
-
|
|
1321
|
+
function fr(t, e, r, n) {
|
|
1322
|
+
let o = e, i = t.ZERO, c = t.ZERO;
|
|
1323
|
+
for (; r > At || n > At; )
|
|
1324
|
+
r & yt && (i = i.add(o)), n & yt && (c = c.add(o)), o = o.double(), r >>= yt, n >>= yt;
|
|
1369
1325
|
return {
|
|
1370
1326
|
p1: i,
|
|
1371
|
-
p2:
|
|
1327
|
+
p2: c
|
|
1372
1328
|
};
|
|
1373
1329
|
}
|
|
1374
|
-
function
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
let d = a;
|
|
1384
|
-
for (let h = u; h >= 0; h -= l) {
|
|
1385
|
-
s.fill(a);
|
|
1386
|
-
for (let b = 0; b < i; b++) {
|
|
1387
|
-
const E = e[b], T = Number(E >> BigInt(h) & g);
|
|
1388
|
-
s[T] = s[T].add(n[b]);
|
|
1389
|
-
}
|
|
1390
|
-
let w = a;
|
|
1391
|
-
for (let b = s.length - 1, E = a; b > 0; b--)
|
|
1392
|
-
E = E.add(s[b]), w = w.add(E);
|
|
1393
|
-
if (d = d.add(w), h !== 0) for (let b = 0; b < l; b++) d = d.double();
|
|
1394
|
-
}
|
|
1395
|
-
return d;
|
|
1396
|
-
}
|
|
1397
|
-
function yn(t, n, e) {
|
|
1398
|
-
if (n) {
|
|
1399
|
-
if (n.ORDER !== t) throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1400
|
-
return se(n), n;
|
|
1401
|
-
} else return ve(t, { isLE: e });
|
|
1402
|
-
}
|
|
1403
|
-
function Jr(t, n, e = {}, r) {
|
|
1404
|
-
if (r === void 0 && (r = t === "edwards"), !n || typeof n != "object") throw new Error(`expected valid ${t} CURVE object`);
|
|
1405
|
-
for (const f of [
|
|
1330
|
+
function $e(t, e, r) {
|
|
1331
|
+
if (e) {
|
|
1332
|
+
if (e.ORDER !== t) throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1333
|
+
return rr(e), e;
|
|
1334
|
+
} else return jt(t, { isLE: r });
|
|
1335
|
+
}
|
|
1336
|
+
function ar(t, e, r = {}, n) {
|
|
1337
|
+
if (n === void 0 && (n = t === "edwards"), !e || typeof e != "object") throw new Error(`expected valid ${t} CURVE object`);
|
|
1338
|
+
for (const s of [
|
|
1406
1339
|
"p",
|
|
1407
1340
|
"n",
|
|
1408
1341
|
"h"
|
|
1409
1342
|
]) {
|
|
1410
|
-
const
|
|
1411
|
-
if (!(typeof
|
|
1343
|
+
const a = e[s];
|
|
1344
|
+
if (!(typeof a == "bigint" && a > At)) throw new Error(`CURVE.${s} must be positive bigint`);
|
|
1412
1345
|
}
|
|
1413
|
-
const o =
|
|
1346
|
+
const o = $e(e.p, r.Fp, n), i = $e(e.n, r.Fn, n), c = [
|
|
1414
1347
|
"Gx",
|
|
1415
1348
|
"Gy",
|
|
1416
1349
|
"a",
|
|
1417
1350
|
t === "weierstrass" ? "b" : "d"
|
|
1418
1351
|
];
|
|
1419
|
-
for (const
|
|
1420
|
-
return
|
|
1421
|
-
CURVE:
|
|
1352
|
+
for (const s of c) if (!o.isValid(e[s])) throw new Error(`CURVE.${s} must be valid field element of CURVE.Fp`);
|
|
1353
|
+
return e = Object.freeze(Object.assign({}, e)), {
|
|
1354
|
+
CURVE: e,
|
|
1422
1355
|
Fp: o,
|
|
1423
1356
|
Fn: i
|
|
1424
1357
|
};
|
|
1425
1358
|
}
|
|
1426
|
-
function
|
|
1427
|
-
return function(
|
|
1428
|
-
const o = t(
|
|
1359
|
+
function ur(t, e) {
|
|
1360
|
+
return function(n) {
|
|
1361
|
+
const o = t(n);
|
|
1429
1362
|
return {
|
|
1430
1363
|
secretKey: o,
|
|
1431
|
-
publicKey:
|
|
1432
|
-
};
|
|
1433
|
-
};
|
|
1434
|
-
}
|
|
1435
|
-
function ir(t) {
|
|
1436
|
-
if (!Number.isSafeInteger(t) || t < 0 || t > 4294967295) throw new Error("wrong u32 integer:" + t);
|
|
1437
|
-
return t;
|
|
1438
|
-
}
|
|
1439
|
-
function eo(t) {
|
|
1440
|
-
if (ir(t), t <= 1) return 1;
|
|
1441
|
-
if (t > 2147483648) throw new Error("nextPowerOfTwo overflow: result does not fit u32");
|
|
1442
|
-
return 1 << Pe(t - 1) + 1 >>> 0;
|
|
1443
|
-
}
|
|
1444
|
-
function Pe(t) {
|
|
1445
|
-
return ir(t), 31 - Math.clz32(t);
|
|
1446
|
-
}
|
|
1447
|
-
function no(t, n, e, r, o) {
|
|
1448
|
-
const i = t, a = e || ((s, u) => new Array(s).fill(u ?? i.ZERO)), f = (s) => {
|
|
1449
|
-
if (Array.isArray(s)) return !0;
|
|
1450
|
-
if (!ArrayBuffer.isView(s)) return !1;
|
|
1451
|
-
const u = s;
|
|
1452
|
-
return typeof u.length == "number" && typeof u.slice == "function" && typeof u[Symbol.iterator] == "function";
|
|
1453
|
-
}, l = (...s) => {
|
|
1454
|
-
if (!s.length) return 0;
|
|
1455
|
-
for (const d of s) if (!f(d)) throw new Error("poly: not polynomial: " + d);
|
|
1456
|
-
const u = s[0].length;
|
|
1457
|
-
for (let d = 1; d < s.length; d++) if (s[d].length !== u) throw new Error(`poly: mismatched lengths ${u} vs ${s[d].length}`);
|
|
1458
|
-
if (o !== void 0 && u !== o) throw new Error(`poly: expected fixed length ${o}, got ${u}`);
|
|
1459
|
-
return u;
|
|
1460
|
-
};
|
|
1461
|
-
function g(s, u, d = !1) {
|
|
1462
|
-
const h = Pe(u), w = d ? n.brp(h) : n.roots(h);
|
|
1463
|
-
for (let b = 0; b < u; b++) if (i.eql(s, w[b])) return b;
|
|
1464
|
-
return -1;
|
|
1465
|
-
}
|
|
1466
|
-
return {
|
|
1467
|
-
roots: n,
|
|
1468
|
-
create: a,
|
|
1469
|
-
length: o,
|
|
1470
|
-
extend: (s, u) => {
|
|
1471
|
-
l(s);
|
|
1472
|
-
const d = a(u, i.ZERO);
|
|
1473
|
-
for (let h = 0; h < Math.min(s.length, u); h++) d[h] = s[h];
|
|
1474
|
-
return d;
|
|
1475
|
-
},
|
|
1476
|
-
degree: (s) => {
|
|
1477
|
-
l(s);
|
|
1478
|
-
for (let u = s.length - 1; u >= 0; u--) if (!i.is0(s[u])) return u;
|
|
1479
|
-
return -1;
|
|
1480
|
-
},
|
|
1481
|
-
add: (s, u) => {
|
|
1482
|
-
const d = l(s, u), h = a(d);
|
|
1483
|
-
for (let w = 0; w < d; w++) h[w] = i.add(s[w], u[w]);
|
|
1484
|
-
return h;
|
|
1485
|
-
},
|
|
1486
|
-
sub: (s, u) => {
|
|
1487
|
-
const d = l(s, u), h = a(d);
|
|
1488
|
-
for (let w = 0; w < d; w++) h[w] = i.sub(s[w], u[w]);
|
|
1489
|
-
return h;
|
|
1490
|
-
},
|
|
1491
|
-
dot: (s, u) => {
|
|
1492
|
-
const d = l(s, u), h = a(d);
|
|
1493
|
-
for (let w = 0; w < d; w++) h[w] = i.mul(s[w], u[w]);
|
|
1494
|
-
return h;
|
|
1495
|
-
},
|
|
1496
|
-
mul: (s, u) => {
|
|
1497
|
-
if (f(u)) {
|
|
1498
|
-
const d = l(s, u);
|
|
1499
|
-
if (r) {
|
|
1500
|
-
const h = r.direct(s, !1, !0), w = r.direct(u, !1, !0);
|
|
1501
|
-
for (let b = 0; b < h.length; b++) h[b] = i.mul(h[b], w[b]);
|
|
1502
|
-
return r.inverse(h, !0, !1);
|
|
1503
|
-
} else {
|
|
1504
|
-
const h = a(d);
|
|
1505
|
-
for (let w = 0; w < d; w++) for (let b = 0; b < d; b++) {
|
|
1506
|
-
const E = (w + b) % d;
|
|
1507
|
-
h[E] = i.add(h[E], i.mul(s[w], u[b]));
|
|
1508
|
-
}
|
|
1509
|
-
return h;
|
|
1510
|
-
}
|
|
1511
|
-
} else {
|
|
1512
|
-
const d = a(l(s));
|
|
1513
|
-
for (let h = 0; h < d.length; h++) d[h] = i.mul(s[h], u);
|
|
1514
|
-
return d;
|
|
1515
|
-
}
|
|
1516
|
-
},
|
|
1517
|
-
convolve(s, u) {
|
|
1518
|
-
const d = eo(s.length + u.length - 1);
|
|
1519
|
-
return this.mul(this.extend(s, d), this.extend(u, d));
|
|
1520
|
-
},
|
|
1521
|
-
shift(s, u) {
|
|
1522
|
-
const d = a(l(s));
|
|
1523
|
-
d[0] = s[0];
|
|
1524
|
-
for (let h = 1, w = i.ONE; h < s.length; h++)
|
|
1525
|
-
w = i.mul(w, u), d[h] = i.mul(s[h], w);
|
|
1526
|
-
return d;
|
|
1527
|
-
},
|
|
1528
|
-
clone: (s) => {
|
|
1529
|
-
l(s);
|
|
1530
|
-
const u = a(s.length);
|
|
1531
|
-
for (let d = 0; d < s.length; d++) u[d] = s[d];
|
|
1532
|
-
return u;
|
|
1533
|
-
},
|
|
1534
|
-
eval: (s, u) => {
|
|
1535
|
-
l(s, u);
|
|
1536
|
-
let d = i.ZERO;
|
|
1537
|
-
for (let h = 0; h < s.length; h++) d = i.add(d, i.mul(s[h], u[h]));
|
|
1538
|
-
return d;
|
|
1539
|
-
},
|
|
1540
|
-
monomial: {
|
|
1541
|
-
basis: (s, u) => {
|
|
1542
|
-
const d = a(u);
|
|
1543
|
-
let h = i.ONE;
|
|
1544
|
-
for (let w = 0; w < u; w++)
|
|
1545
|
-
d[w] = h, h = i.mul(h, s);
|
|
1546
|
-
return d;
|
|
1547
|
-
},
|
|
1548
|
-
eval: (s, u) => {
|
|
1549
|
-
l(s);
|
|
1550
|
-
let d = i.ZERO;
|
|
1551
|
-
for (let h = s.length - 1; h >= 0; h--) d = i.add(i.mul(d, u), s[h]);
|
|
1552
|
-
return d;
|
|
1553
|
-
}
|
|
1554
|
-
},
|
|
1555
|
-
lagrange: {
|
|
1556
|
-
basis: (s, u, d = !1, h) => {
|
|
1557
|
-
const w = Pe(u), b = h || (d ? n.brp(w) : n.roots(w)), E = a(u), T = g(s, u, d);
|
|
1558
|
-
if (T !== -1)
|
|
1559
|
-
return E[T] = i.ONE, E;
|
|
1560
|
-
const B = i.pow(s, BigInt(u)), C = i.mul(i.sub(B, i.ONE), i.inv(BigInt(u))), O = a(u);
|
|
1561
|
-
for (let z = 0; z < u; z++) O[z] = i.sub(s, b[z]);
|
|
1562
|
-
const F = i.invertBatch(O);
|
|
1563
|
-
for (let z = 0; z < u; z++) E[z] = i.mul(C, i.mul(b[z], F[z]));
|
|
1564
|
-
return E;
|
|
1565
|
-
},
|
|
1566
|
-
eval(s, u, d = !1) {
|
|
1567
|
-
l(s);
|
|
1568
|
-
const h = g(u, s.length, d);
|
|
1569
|
-
if (h !== -1) return s[h];
|
|
1570
|
-
const w = this.basis(u, s.length, d);
|
|
1571
|
-
let b = i.ZERO;
|
|
1572
|
-
for (let E = 0; E < s.length; E++) i.is0(s[E]) || (b = i.add(b, i.mul(s[E], w[E])));
|
|
1573
|
-
return b;
|
|
1574
|
-
}
|
|
1575
|
-
},
|
|
1576
|
-
vanishing(s) {
|
|
1577
|
-
l(s);
|
|
1578
|
-
const u = a(s.length + 1, i.ZERO);
|
|
1579
|
-
u[0] = i.ONE;
|
|
1580
|
-
for (const d of s) {
|
|
1581
|
-
const h = i.neg(d);
|
|
1582
|
-
for (let w = u.length - 1; w > 0; w--) u[w] = i.add(i.mul(u[w], h), u[w - 1]);
|
|
1583
|
-
u[0] = i.mul(u[0], h);
|
|
1584
|
-
}
|
|
1585
|
-
return u;
|
|
1586
|
-
}
|
|
1587
|
-
};
|
|
1588
|
-
}
|
|
1589
|
-
var ro = St;
|
|
1590
|
-
function kt(t, n) {
|
|
1591
|
-
if (Ft(t), Ft(n), n < 0 || n > 4) throw new Error("invalid I2OSP length: " + n);
|
|
1592
|
-
if (t < 0 || t > 2 ** (8 * n) - 1) throw new Error("invalid I2OSP input: " + t);
|
|
1593
|
-
const e = Array.from({ length: n }).fill(0);
|
|
1594
|
-
for (let r = n - 1; r >= 0; r--)
|
|
1595
|
-
e[r] = t & 255, t >>>= 8;
|
|
1596
|
-
return new Uint8Array(e);
|
|
1597
|
-
}
|
|
1598
|
-
function oo(t, n) {
|
|
1599
|
-
const e = new Uint8Array(t.length);
|
|
1600
|
-
for (let r = 0; r < t.length; r++) e[r] = t[r] ^ n[r];
|
|
1601
|
-
return e;
|
|
1602
|
-
}
|
|
1603
|
-
function sr(t) {
|
|
1604
|
-
if (!oe(t) && typeof t != "string") throw new Error("DST must be Uint8Array or ascii string");
|
|
1605
|
-
const n = typeof t == "string" ? be(t) : t;
|
|
1606
|
-
if (n.length === 0) throw new Error("DST must be non-empty");
|
|
1607
|
-
return n;
|
|
1608
|
-
}
|
|
1609
|
-
function io(t, n, e, r) {
|
|
1610
|
-
st(t), Ft(e), n = sr(n), n.length > 255 && (n = r(Q(be("H2C-OVERSIZE-DST-"), n)));
|
|
1611
|
-
const { outputLen: o, blockLen: i } = r, a = Math.ceil(e / o);
|
|
1612
|
-
if (e > 65535 || a > 255) throw new Error("expand_message_xmd: invalid lenInBytes");
|
|
1613
|
-
const f = Q(n, kt(n.length, 1)), l = new Uint8Array(i), g = kt(e, 2), s = new Array(a), u = r(Q(l, t, g, kt(0, 1), f));
|
|
1614
|
-
s[0] = r(Q(u, kt(1, 1), f));
|
|
1615
|
-
for (let d = 1; d < a; d++) s[d] = r(Q(oo(u, s[d - 1]), kt(d + 1, 1), f));
|
|
1616
|
-
return Q(...s).slice(0, e);
|
|
1617
|
-
}
|
|
1618
|
-
function so(t, n, e, r, o) {
|
|
1619
|
-
if (st(t), Ft(e), n = sr(n), n.length > 255) {
|
|
1620
|
-
const i = Math.ceil(2 * r / 8);
|
|
1621
|
-
n = o.create({ dkLen: i }).update(be("H2C-OVERSIZE-DST-")).update(n).digest();
|
|
1622
|
-
}
|
|
1623
|
-
if (e > 65535 || n.length > 255) throw new Error("expand_message_xof: invalid lenInBytes");
|
|
1624
|
-
return o.create({ dkLen: e }).update(t).update(kt(e, 2)).update(n).update(kt(n.length, 1)).digest();
|
|
1625
|
-
}
|
|
1626
|
-
function He(t, n, e) {
|
|
1627
|
-
Mt(e, {
|
|
1628
|
-
p: "bigint",
|
|
1629
|
-
m: "number",
|
|
1630
|
-
k: "number",
|
|
1631
|
-
hash: "function"
|
|
1632
|
-
});
|
|
1633
|
-
const { p: r, k: o, m: i, hash: a, expand: f, DST: l } = e;
|
|
1634
|
-
if (Ft(a.outputLen, "valid hash"), st(t), Ft(n), n < 1) throw new Error("hash_to_field: expected count >= 1");
|
|
1635
|
-
if (i < 1) throw new Error("hash_to_field: expected m >= 1");
|
|
1636
|
-
const g = r.toString(2).length, s = Math.ceil((g + o) / 8), u = n * i * s;
|
|
1637
|
-
let d;
|
|
1638
|
-
if (f === "xmd") d = io(t, l, u, a);
|
|
1639
|
-
else if (f === "xof") d = so(t, l, u, o, a);
|
|
1640
|
-
else if (f === "_internal_pass") d = t;
|
|
1641
|
-
else throw new Error('expand must be "xmd" or "xof"');
|
|
1642
|
-
const h = new Array(n);
|
|
1643
|
-
for (let w = 0; w < n; w++) {
|
|
1644
|
-
const b = new Array(i);
|
|
1645
|
-
for (let E = 0; E < i; E++) {
|
|
1646
|
-
const T = s * (E + w * i);
|
|
1647
|
-
b[E] = bt(ro(d.subarray(T, T + s)), r);
|
|
1648
|
-
}
|
|
1649
|
-
h[w] = b;
|
|
1650
|
-
}
|
|
1651
|
-
return h;
|
|
1652
|
-
}
|
|
1653
|
-
function co(t, n) {
|
|
1654
|
-
const e = n.map((r) => Array.from(r).reverse());
|
|
1655
|
-
return (r, o) => {
|
|
1656
|
-
const [i, a, f, l] = e.map((u) => u.reduce((d, h) => t.add(t.mul(d, r), h))), [g, s] = Ee(t, [a, l], !0);
|
|
1657
|
-
return r = t.mul(i, g), o = t.mul(o, t.mul(f, s)), {
|
|
1658
|
-
x: r,
|
|
1659
|
-
y: o
|
|
1364
|
+
publicKey: e(o)
|
|
1660
1365
|
};
|
|
1661
1366
|
};
|
|
1662
1367
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
function a(f) {
|
|
1675
|
-
const l = f.clearCofactor();
|
|
1676
|
-
return l.equals(t.ZERO) ? t.ZERO : (l.assertValidity(), l);
|
|
1677
|
-
}
|
|
1678
|
-
return Object.freeze({
|
|
1679
|
-
get defaults() {
|
|
1680
|
-
return r(o);
|
|
1681
|
-
},
|
|
1682
|
-
Point: t,
|
|
1683
|
-
hashToCurve(f, l) {
|
|
1684
|
-
const g = He(f, 2, Object.assign({}, o, l)), s = i(g[0]), u = i(g[1]);
|
|
1685
|
-
return a(s.add(u));
|
|
1686
|
-
},
|
|
1687
|
-
encodeToCurve(f, l) {
|
|
1688
|
-
const g = o.encodeDST ? { DST: o.encodeDST } : {};
|
|
1689
|
-
return a(i(He(f, 1, Object.assign({}, o, g, l))[0]));
|
|
1690
|
-
},
|
|
1691
|
-
mapToCurve(f) {
|
|
1692
|
-
if (o.m === 1) {
|
|
1693
|
-
if (typeof f != "bigint") throw new Error("expected bigint (m=1)");
|
|
1694
|
-
return a(i([f]));
|
|
1695
|
-
}
|
|
1696
|
-
if (!Array.isArray(f)) throw new Error("expected array of bigints");
|
|
1697
|
-
for (const l of f) if (typeof l != "bigint") throw new Error("expected array of bigints");
|
|
1698
|
-
return a(i(f));
|
|
1699
|
-
},
|
|
1700
|
-
hashToScalar(f, l) {
|
|
1701
|
-
const g = t.Fn.ORDER;
|
|
1702
|
-
return He(f, 1, Object.assign({}, o, {
|
|
1703
|
-
p: g,
|
|
1704
|
-
m: 1,
|
|
1705
|
-
DST: fo
|
|
1706
|
-
}, l))[0][0];
|
|
1707
|
-
}
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
Qt();
|
|
1711
|
-
var fe = (t) => {
|
|
1712
|
-
if (!Number.isSafeInteger(t.min) || !Number.isSafeInteger(t.max)) throw new Error("Wrong signers info: min=" + t.min + " max=" + t.max);
|
|
1713
|
-
if (t.min < 2 || t.max < 2 || t.min > t.max) throw new Error("Wrong signers info: min=" + t.min + " max=" + t.max);
|
|
1714
|
-
}, pn = (t, n) => {
|
|
1715
|
-
if (n < t.min || n > t.max) throw new Error("Wrong number of commitments=" + n);
|
|
1716
|
-
}, ae = class extends Error {
|
|
1717
|
-
cheaters;
|
|
1718
|
-
constructor(t, n) {
|
|
1719
|
-
super(t), this.cheaters = n;
|
|
1720
|
-
}
|
|
1721
|
-
};
|
|
1722
|
-
function cr(t) {
|
|
1723
|
-
Mt(t, {
|
|
1724
|
-
name: "string",
|
|
1725
|
-
hash: "function"
|
|
1726
|
-
}, {
|
|
1727
|
-
hashToScalar: "function",
|
|
1728
|
-
validatePoint: "function",
|
|
1729
|
-
parsePublicKey: "function",
|
|
1730
|
-
adjustScalar: "function",
|
|
1731
|
-
adjustPoint: "function",
|
|
1732
|
-
challenge: "function",
|
|
1733
|
-
adjustNonces: "function",
|
|
1734
|
-
adjustSecret: "function",
|
|
1735
|
-
adjustPublic: "function",
|
|
1736
|
-
adjustGroupCommitmentShare: "function",
|
|
1737
|
-
adjustDKG: "function"
|
|
1738
|
-
}), Gr(t.Point);
|
|
1739
|
-
const { Point: n } = t, e = t.Fn === void 0 ? n.Fn : t.Fn, r = t.hash, o = t.hashToScalar === void 0 ? (c, m = { DST: new Uint8Array() }) => {
|
|
1740
|
-
const y = r(Q(m.DST, c));
|
|
1741
|
-
return e.create(e.isLE ? ge(y) : St(y));
|
|
1742
|
-
} : t.hashToScalar, i = Nt(t.H1 !== void 0 ? t.H1 : t.name + "rho"), a = Nt(t.H2 !== void 0 ? t.H2 : t.name + "chal"), f = Nt(t.H3 !== void 0 ? t.H3 : t.name + "nonce"), l = Nt(t.H4 !== void 0 ? t.H4 : t.name + "msg"), g = Nt(t.H5 !== void 0 ? t.H5 : t.name + "com"), s = Nt(t.HDKG !== void 0 ? t.HDKG : t.name + "dkg"), u = Nt(t.HID !== void 0 ? t.HID : t.name + "id"), d = (c) => o(c, { DST: i }), h = (c) => o(c, { DST: a }), w = (c) => o(c, { DST: f }), b = (c) => r(Q(l, c)), E = (c) => r(Q(g, c)), T = (c) => o(c, { DST: s }), B = (c) => o(c, { DST: u }), C = (c = wt) => {
|
|
1743
|
-
const m = nr(c(nn(e.ORDER)), e.ORDER, e.isLE);
|
|
1744
|
-
return e.isLE ? ge(m) : St(m);
|
|
1745
|
-
}, O = (c) => c.toBytes(), F = (c) => {
|
|
1746
|
-
const m = n.fromBytes(c);
|
|
1747
|
-
return t.validatePoint && t.validatePoint(m), m;
|
|
1748
|
-
}, z = (c, m) => ({
|
|
1749
|
-
identifier: c,
|
|
1750
|
-
hiding: O(n.BASE.multiply(e.fromBytes(m.hiding))),
|
|
1751
|
-
binding: O(n.BASE.multiply(e.fromBytes(m.binding)))
|
|
1752
|
-
}), W = t.adjustPoint === void 0 ? (c) => c : t.adjustPoint, N = (c) => {
|
|
1753
|
-
if (!e.isValid(c) || e.is0(c)) throw new Error("Invalid identifier " + c);
|
|
1754
|
-
return c;
|
|
1755
|
-
}, V = (c) => Ct(e.toBytes(N(c))), K = (c) => {
|
|
1756
|
-
const m = N(e.fromBytes(he(c)));
|
|
1757
|
-
if (V(m) !== c) throw new Error("expected canonical identifier hex");
|
|
1758
|
-
return m;
|
|
1759
|
-
}, M = {
|
|
1760
|
-
encode: (c, m) => {
|
|
1761
|
-
let y = Q(O(c), e.toBytes(m));
|
|
1762
|
-
return t.adjustTx && (y = t.adjustTx.encode(y)), y;
|
|
1763
|
-
},
|
|
1764
|
-
decode: (c) => (t.adjustTx && (c = t.adjustTx.decode(c)), {
|
|
1765
|
-
R: F(c.subarray(0, -e.BYTES)),
|
|
1766
|
-
z: e.fromBytes(c.subarray(-e.BYTES))
|
|
1767
|
-
})
|
|
1768
|
-
}, v = (c = wt) => {
|
|
1769
|
-
let m = C(c);
|
|
1770
|
-
t.adjustScalar && (m = t.adjustScalar(m));
|
|
1771
|
-
let y = n.BASE.multiply(m);
|
|
1772
|
-
return {
|
|
1773
|
-
scalar: m,
|
|
1774
|
-
point: y
|
|
1775
|
-
};
|
|
1776
|
-
}, H = "roots are unavailable in FROST polynomial mode", U = no(e, {
|
|
1777
|
-
info: {
|
|
1778
|
-
G: e.ZERO,
|
|
1779
|
-
oddFactor: e.ZERO,
|
|
1780
|
-
powerOfTwo: 0
|
|
1781
|
-
},
|
|
1782
|
-
roots() {
|
|
1783
|
-
throw new Error(H);
|
|
1784
|
-
},
|
|
1785
|
-
brp() {
|
|
1786
|
-
throw new Error(H);
|
|
1787
|
-
},
|
|
1788
|
-
inverse() {
|
|
1789
|
-
throw new Error(H);
|
|
1790
|
-
},
|
|
1791
|
-
omega() {
|
|
1792
|
-
throw new Error(H);
|
|
1793
|
-
},
|
|
1794
|
-
clear() {
|
|
1795
|
-
}
|
|
1796
|
-
}), S = (c, m) => Qr(n, c, m), p = (c, m) => {
|
|
1797
|
-
if (!m.length) throw new Error("empty coefficients");
|
|
1798
|
-
return U.monomial.eval(m, c);
|
|
1799
|
-
}, R = (c, m) => {
|
|
1800
|
-
const y = "invalid parameters";
|
|
1801
|
-
if (!c.some((L) => e.eql(L, m))) throw new Error(y);
|
|
1802
|
-
const x = new Set(c);
|
|
1803
|
-
if (x.size !== c.length) throw new Error(y);
|
|
1804
|
-
if (!x.has(m)) throw new Error(y);
|
|
1805
|
-
let A = e.ONE, j = e.ONE;
|
|
1806
|
-
for (const L of c)
|
|
1807
|
-
e.eql(L, m) || (A = e.mul(A, L), j = e.mul(j, e.sub(L, m)));
|
|
1808
|
-
return e.div(A, j);
|
|
1809
|
-
}, I = (c, m) => S(m, U.monomial.basis(c, m.length)), _ = (c, m, y, x = wt) => {
|
|
1810
|
-
fe(c);
|
|
1811
|
-
const A = m === void 0 ? C(x) : e.fromBytes(m);
|
|
1812
|
-
if (!y) {
|
|
1813
|
-
y = [];
|
|
1814
|
-
for (let L = 0; L < c.min - 1; L++) y.push(C(x));
|
|
1815
|
-
}
|
|
1816
|
-
if (y.length !== c.min - 1) throw new Error("wrong coefficients length");
|
|
1817
|
-
const j = [A, ...y];
|
|
1818
|
-
return {
|
|
1819
|
-
coefficients: j,
|
|
1820
|
-
commitment: j.map((L) => n.BASE.multiply(L)),
|
|
1821
|
-
secret: A
|
|
1822
|
-
};
|
|
1823
|
-
}, D = {
|
|
1824
|
-
challenge: (c, m, y) => T(Q(e.toBytes(c), O(m), O(y))),
|
|
1825
|
-
compute(c, m, y, x = wt) {
|
|
1826
|
-
if (m.length < 1) throw new Error("coefficients should have at least one element");
|
|
1827
|
-
const { point: A, scalar: j } = v(x), L = y[0], P = this.challenge(c, L, A), k = e.add(j, e.mul(m[0], P));
|
|
1828
|
-
return M.encode(A, k);
|
|
1829
|
-
},
|
|
1830
|
-
validate(c, m, y) {
|
|
1831
|
-
if (m.length < 1) throw new Error("commitment should have at least one element");
|
|
1832
|
-
const { R: x, z: A } = M.decode(y), j = F(m[0]), L = this.challenge(c, j, x);
|
|
1833
|
-
if (!x.equals(n.BASE.multiply(A).subtract(j.multiply(L)))) throw new Error("invalid proof of knowledge");
|
|
1834
|
-
}
|
|
1835
|
-
}, q = {
|
|
1836
|
-
challenge: (c, m, y) => t.challenge ? t.challenge(c, m, y) : h(Q(O(c), O(m), y)),
|
|
1837
|
-
sign(c, m, y = wt) {
|
|
1838
|
-
const { point: x, scalar: A } = v(y), j = n.BASE.multiply(m), L = this.challenge(x, j, c);
|
|
1839
|
-
return [x, e.add(A, e.mul(L, m))];
|
|
1840
|
-
},
|
|
1841
|
-
verify(c, m, y, x) {
|
|
1842
|
-
t.adjustPoint && (x = t.adjustPoint(x)), t.adjustPoint && (m = t.adjustPoint(m));
|
|
1843
|
-
const A = this.challenge(m, x, c), j = n.BASE.multiply(y), L = x.multiply(A);
|
|
1844
|
-
let P = j.subtract(L).subtract(m);
|
|
1845
|
-
return P.clearCofactor && (P = P.clearCofactor()), n.ZERO.equals(P);
|
|
1846
|
-
}
|
|
1847
|
-
}, X = (c, m, y) => {
|
|
1848
|
-
if (!n.BASE.multiply(y).equals(I(c, m))) throw new Error("invalid secret share");
|
|
1849
|
-
}, Y = {
|
|
1850
|
-
fromNumber(c) {
|
|
1851
|
-
if (!Number.isSafeInteger(c)) throw new Error("expected safe interger");
|
|
1852
|
-
return V(BigInt(c));
|
|
1853
|
-
},
|
|
1854
|
-
derive(c) {
|
|
1855
|
-
if (typeof c != "string") throw new Error("wrong identifier string: " + c);
|
|
1856
|
-
return V(B(Nt(c)));
|
|
1857
|
-
}
|
|
1858
|
-
}, Z = (c, m = wt) => w(Q(m(32), e.toBytes(c))), nt = (c, m, y) => {
|
|
1859
|
-
const x = m.map((tt) => [
|
|
1860
|
-
tt.identifier,
|
|
1861
|
-
K(tt.identifier),
|
|
1862
|
-
F(tt.hiding),
|
|
1863
|
-
F(tt.binding)
|
|
1864
|
-
]);
|
|
1865
|
-
x.sort((tt, ht) => tt[1] < ht[1] ? -1 : tt[1] > ht[1] ? 1 : 0);
|
|
1866
|
-
const A = [];
|
|
1867
|
-
for (const [tt, ht, $, et] of x) A.push(e.toBytes(ht), O($), O(et));
|
|
1868
|
-
const j = E(Q(...A)), L = Q(O(c), b(y), j), P = {};
|
|
1869
|
-
for (const [tt, ht] of x) P[tt] = d(Q(L, e.toBytes(ht)));
|
|
1870
|
-
const k = [], G = [];
|
|
1871
|
-
for (const [tt, ht, $, et] of x) {
|
|
1872
|
-
if (n.ZERO.equals($) || n.ZERO.equals(et)) throw new Error("infinity commitment");
|
|
1873
|
-
k.push($, et), G.push(e.ONE, P[tt]);
|
|
1874
|
-
}
|
|
1875
|
-
const mt = S(k, G);
|
|
1876
|
-
return {
|
|
1877
|
-
identifiers: x.map((tt) => tt[1]),
|
|
1878
|
-
groupCommitment: mt,
|
|
1879
|
-
bindingFactors: P
|
|
1880
|
-
};
|
|
1881
|
-
}, rt = (c, m, y, x) => {
|
|
1882
|
-
const A = W(F(c)), j = K(x), { identifiers: L, groupCommitment: P, bindingFactors: k } = nt(A, m, y), G = k[x];
|
|
1883
|
-
return {
|
|
1884
|
-
lambda: R(L, j),
|
|
1885
|
-
challenge: q.challenge(P, A, y),
|
|
1886
|
-
bindingFactor: G,
|
|
1887
|
-
groupCommitment: P
|
|
1888
|
-
};
|
|
1889
|
-
};
|
|
1890
|
-
Object.freeze(Y);
|
|
1891
|
-
const it = {
|
|
1892
|
-
Identifier: Y,
|
|
1893
|
-
DKG: Object.freeze({
|
|
1894
|
-
round1: (c, m, y, x = wt) => {
|
|
1895
|
-
fe(m);
|
|
1896
|
-
const A = K(c), { coefficients: j, commitment: L } = _(m, y, void 0, x), P = D.compute(A, j, L, x), k = L.map(O);
|
|
1897
|
-
return {
|
|
1898
|
-
public: {
|
|
1899
|
-
identifier: V(A),
|
|
1900
|
-
commitment: k,
|
|
1901
|
-
proofOfKnowledge: P
|
|
1902
|
-
},
|
|
1903
|
-
secret: {
|
|
1904
|
-
identifier: A,
|
|
1905
|
-
coefficients: j,
|
|
1906
|
-
commitment: L.map(O),
|
|
1907
|
-
signers: {
|
|
1908
|
-
min: m.min,
|
|
1909
|
-
max: m.max
|
|
1910
|
-
},
|
|
1911
|
-
step: 1
|
|
1912
|
-
}
|
|
1913
|
-
};
|
|
1914
|
-
},
|
|
1915
|
-
round2: (c, m) => {
|
|
1916
|
-
if (m.length !== c.signers.max - 1) throw new Error("wrong number of round1 packages");
|
|
1917
|
-
if (!c.coefficients || c.step === 3) throw new Error("round3 package used in round2");
|
|
1918
|
-
const y = {};
|
|
1919
|
-
for (const x of m) {
|
|
1920
|
-
if (x.commitment.length !== c.signers.min) throw new Error("wrong number of commitments");
|
|
1921
|
-
const A = K(x.identifier);
|
|
1922
|
-
if (A === c.identifier) throw new Error("duplicate id=" + V(A));
|
|
1923
|
-
D.validate(A, x.commitment, x.proofOfKnowledge);
|
|
1924
|
-
for (const L of x.commitment) F(L);
|
|
1925
|
-
if (y[x.identifier]) throw new Error("Duplicate id=" + A);
|
|
1926
|
-
const j = e.toBytes(p(A, c.coefficients));
|
|
1927
|
-
y[x.identifier] = {
|
|
1928
|
-
identifier: V(c.identifier),
|
|
1929
|
-
signingShare: j
|
|
1930
|
-
};
|
|
1931
|
-
}
|
|
1932
|
-
return c.step = 2, y;
|
|
1933
|
-
},
|
|
1934
|
-
round3: (c, m, y) => {
|
|
1935
|
-
if (m.length !== c.signers.max - 1) throw new Error("wrong length of round1 packages");
|
|
1936
|
-
if (!c.coefficients || c.step !== 2) throw new Error("round2 package used in round3");
|
|
1937
|
-
if (y.length !== m.length) throw new Error("wrong length of round2 packages");
|
|
1938
|
-
const x = {};
|
|
1939
|
-
for (const $ of m) {
|
|
1940
|
-
if (!$.identifier || !$.commitment) throw new Error("wrong round1 share");
|
|
1941
|
-
x[$.identifier] = { ...$ };
|
|
1942
|
-
}
|
|
1943
|
-
for (const $ of y) {
|
|
1944
|
-
if (!$.identifier || !$.signingShare) throw new Error("wrong round2 share");
|
|
1945
|
-
if (!x[$.identifier]) throw new Error("round1 share for " + $.identifier + " is missing");
|
|
1946
|
-
x[$.identifier].signingShare = $.signingShare;
|
|
1947
|
-
}
|
|
1948
|
-
if (Object.keys(x).length !== m.length) throw new Error("mismatch identifiers between rounds");
|
|
1949
|
-
let A = e.ZERO;
|
|
1950
|
-
if (c.commitment.length !== c.signers.min) throw new Error("wrong commitments length");
|
|
1951
|
-
const j = c.commitment.map(F), L = p(c.identifier, c.coefficients);
|
|
1952
|
-
X(c.identifier, j, L);
|
|
1953
|
-
const P = j.map(O), k = { [V(c.identifier)]: P };
|
|
1954
|
-
for (const $ in x) {
|
|
1955
|
-
const et = x[$];
|
|
1956
|
-
if (!et.signingShare || !et.commitment) throw new Error("mismatch identifiers");
|
|
1957
|
-
const pt = K($), Gt = e.fromBytes(et.signingShare), xe = et.commitment.map(F);
|
|
1958
|
-
X(c.identifier, xe, Gt), A = e.add(A, Gt);
|
|
1959
|
-
const Jt = V(pt);
|
|
1960
|
-
if (k[Jt]) throw new Error("duplicated id=" + Jt);
|
|
1961
|
-
k[Jt] = et.commitment;
|
|
1962
|
-
}
|
|
1963
|
-
A = e.add(A, L);
|
|
1964
|
-
const G = new Array(c.signers.min).fill(n.ZERO);
|
|
1965
|
-
for (const $ in k) {
|
|
1966
|
-
const et = k[$];
|
|
1967
|
-
if (et.length !== c.signers.min) throw new Error("wrong commitments length");
|
|
1968
|
-
for (let pt = 0; pt < et.length; pt++) G[pt] = G[pt].add(F(et[pt]));
|
|
1969
|
-
}
|
|
1970
|
-
const mt = G.map(O), tt = {};
|
|
1971
|
-
for (const $ in k) tt[$] = O(I(K($), G));
|
|
1972
|
-
let ht = {
|
|
1973
|
-
public: {
|
|
1974
|
-
signers: {
|
|
1975
|
-
min: c.signers.min,
|
|
1976
|
-
max: c.signers.max
|
|
1977
|
-
},
|
|
1978
|
-
commitments: mt,
|
|
1979
|
-
verifyingShares: Object.fromEntries(Object.entries(tt).map(([$, et]) => [$, et.slice()]))
|
|
1980
|
-
},
|
|
1981
|
-
secret: {
|
|
1982
|
-
identifier: V(c.identifier),
|
|
1983
|
-
signingShare: e.toBytes(A)
|
|
1984
|
-
}
|
|
1985
|
-
};
|
|
1986
|
-
t.adjustDKG && (ht = t.adjustDKG(ht));
|
|
1987
|
-
for (let $ = 0; $ < c.coefficients.length; $++) c.coefficients[$] -= c.coefficients[$];
|
|
1988
|
-
return delete c.coefficients, c.step = 3, ht;
|
|
1989
|
-
},
|
|
1990
|
-
clean(c) {
|
|
1991
|
-
if (c.identifier -= c.identifier, c.coefficients) for (let m = 0; m < c.coefficients.length; m++) c.coefficients[m] -= c.coefficients[m];
|
|
1992
|
-
c.step = 3;
|
|
1993
|
-
}
|
|
1994
|
-
}),
|
|
1995
|
-
trustedDealer(c, m, y, x = wt) {
|
|
1996
|
-
if (fe(c), m === void 0) {
|
|
1997
|
-
m = [];
|
|
1998
|
-
for (let G = 1; G <= c.max; G++) m.push(Y.fromNumber(G));
|
|
1999
|
-
} else if (!Array.isArray(m) || m.length !== c.max) throw new Error("identifiers should be array of " + c.max);
|
|
2000
|
-
const A = {};
|
|
2001
|
-
for (const G of m) {
|
|
2002
|
-
const mt = K(G);
|
|
2003
|
-
if (G in A) throw new Error("duplicated id=" + G);
|
|
2004
|
-
A[G] = mt;
|
|
2005
|
-
}
|
|
2006
|
-
const j = _(c, y, void 0, x), L = j.commitment.map(O), P = {}, k = {};
|
|
2007
|
-
for (const G of m) {
|
|
2008
|
-
const mt = p(A[G], j.coefficients);
|
|
2009
|
-
k[G] = O(n.BASE.multiply(mt)), P[G] = {
|
|
2010
|
-
identifier: G,
|
|
2011
|
-
signingShare: e.toBytes(mt)
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
return {
|
|
2015
|
-
public: {
|
|
2016
|
-
signers: {
|
|
2017
|
-
min: c.min,
|
|
2018
|
-
max: c.max
|
|
2019
|
-
},
|
|
2020
|
-
commitments: L,
|
|
2021
|
-
verifyingShares: k
|
|
2022
|
-
},
|
|
2023
|
-
secretShares: P
|
|
2024
|
-
};
|
|
2025
|
-
},
|
|
2026
|
-
validateSecret(c, m) {
|
|
2027
|
-
X(K(c.identifier), m.commitments.map(F), e.fromBytes(c.signingShare));
|
|
2028
|
-
},
|
|
2029
|
-
commit(c, m = wt) {
|
|
2030
|
-
const y = e.fromBytes(c.signingShare), x = Z(y, m), A = Z(y, m), j = {
|
|
2031
|
-
hiding: e.toBytes(x),
|
|
2032
|
-
binding: e.toBytes(A)
|
|
2033
|
-
};
|
|
2034
|
-
return {
|
|
2035
|
-
nonces: j,
|
|
2036
|
-
commitments: z(c.identifier, j)
|
|
2037
|
-
};
|
|
2038
|
-
},
|
|
2039
|
-
signShare(c, m, y, x, A) {
|
|
2040
|
-
pn(m.signers, x.length);
|
|
2041
|
-
const j = e.fromBytes(y.hiding), L = e.fromBytes(y.binding);
|
|
2042
|
-
if (e.is0(j) || e.is0(L)) throw new Error("signing nonces already used");
|
|
2043
|
-
const P = {
|
|
2044
|
-
identifier: c.identifier,
|
|
2045
|
-
hiding: O(n.BASE.multiply(j)),
|
|
2046
|
-
binding: O(n.BASE.multiply(L))
|
|
2047
|
-
}, k = x.find((wr) => wr.identifier === c.identifier);
|
|
2048
|
-
if (!k) throw new Error("missing signer commitment");
|
|
2049
|
-
if (Ct(k.hiding) !== Ct(P.hiding) || Ct(k.binding) !== Ct(P.binding)) throw new Error("incorrect signer commitment");
|
|
2050
|
-
t.adjustSecret && (c = t.adjustSecret(c, m)), t.adjustPublic && (m = t.adjustPublic(m));
|
|
2051
|
-
const G = e.fromBytes(c.signingShare), { lambda: mt, challenge: tt, bindingFactor: ht, groupCommitment: $ } = rt(m.commitments[0], x, A, c.identifier), et = t.adjustNonces ? t.adjustNonces($, y) : y, pt = t.adjustNonces ? e.fromBytes(et.hiding) : j, Gt = t.adjustNonces ? e.fromBytes(et.binding) : L, xe = e.mul(e.mul(mt, G), tt), Jt = e.mul(Gt, ht), gr = e.toBytes(e.add(e.add(pt, Jt), xe));
|
|
2052
|
-
return y.hiding.fill(0), y.binding.fill(0), gr;
|
|
2053
|
-
},
|
|
2054
|
-
verifyShare(c, m, y, x, A) {
|
|
2055
|
-
t.adjustPublic && (c = t.adjustPublic(c));
|
|
2056
|
-
const j = m.find((Gt) => Gt.identifier === x);
|
|
2057
|
-
if (!j) throw new Error("cannot find identifier commitment");
|
|
2058
|
-
const L = F(c.verifyingShares[x]), P = F(j.hiding), k = F(j.binding), { lambda: G, challenge: mt, bindingFactor: tt, groupCommitment: ht } = rt(c.commitments[0], m, y, x);
|
|
2059
|
-
let $ = P.add(k.multiply(tt));
|
|
2060
|
-
t.adjustGroupCommitmentShare && ($ = t.adjustGroupCommitmentShare(ht, $));
|
|
2061
|
-
const et = n.BASE.multiply(e.fromBytes(A)), pt = $.add(L.multiply(e.mul(mt, G)));
|
|
2062
|
-
return et.equals(pt);
|
|
2063
|
-
},
|
|
2064
|
-
aggregate(c, m, y, x) {
|
|
2065
|
-
t.adjustPublic && (c = t.adjustPublic(c));
|
|
2066
|
-
try {
|
|
2067
|
-
pn(c.signers, m.length);
|
|
2068
|
-
} catch {
|
|
2069
|
-
throw new ae("aggregation failed", []);
|
|
2070
|
-
}
|
|
2071
|
-
const A = m.map((k) => k.identifier);
|
|
2072
|
-
if (A.length !== Object.keys(x).length) throw new ae("aggregation failed", []);
|
|
2073
|
-
for (const k of A) if (!(k in x) || !(k in c.verifyingShares)) throw new ae("aggregation failed", []);
|
|
2074
|
-
const j = F(c.commitments[0]), { groupCommitment: L } = nt(j, m, y);
|
|
2075
|
-
let P = e.ZERO;
|
|
2076
|
-
for (const k of A) P = e.add(P, e.fromBytes(x[k]));
|
|
2077
|
-
if (!q.verify(y, L, P, j)) {
|
|
2078
|
-
const k = [];
|
|
2079
|
-
for (const G of A) this.verifyShare(c, m, y, G, x[G]) || k.push(G);
|
|
2080
|
-
throw new ae("aggregation failed", k);
|
|
2081
|
-
}
|
|
2082
|
-
return M.encode(L, P);
|
|
2083
|
-
},
|
|
2084
|
-
sign(c, m) {
|
|
2085
|
-
let y = e.fromBytes(m);
|
|
2086
|
-
t.adjustScalar && (y = t.adjustScalar(y));
|
|
2087
|
-
const [x, A] = q.sign(c, y);
|
|
2088
|
-
return M.encode(x, A);
|
|
2089
|
-
},
|
|
2090
|
-
verify(c, m, y) {
|
|
2091
|
-
const x = t.parsePublicKey ? t.parsePublicKey(y) : F(y), { R: A, z: j } = M.decode(c);
|
|
2092
|
-
return q.verify(m, A, j, x);
|
|
2093
|
-
},
|
|
2094
|
-
combineSecret(c, m) {
|
|
2095
|
-
if (fe(m), !Array.isArray(c) || c.length < m.min) throw new Error("wrong secret shares array");
|
|
2096
|
-
const y = [], x = {};
|
|
2097
|
-
for (const L of c) {
|
|
2098
|
-
const P = K(L.identifier), k = V(P);
|
|
2099
|
-
if (x[k]) throw new Error("duplicated id=" + k);
|
|
2100
|
-
x[k] = !0, y.push([P, e.fromBytes(L.signingShare)]);
|
|
2101
|
-
}
|
|
2102
|
-
const A = y.map(([L]) => L);
|
|
2103
|
-
let j = e.ZERO;
|
|
2104
|
-
for (const [L, P] of y) j = e.add(j, e.mul(P, R(A, L)));
|
|
2105
|
-
return e.toBytes(j);
|
|
2106
|
-
},
|
|
2107
|
-
utils: Object.freeze({
|
|
2108
|
-
Fn: e,
|
|
2109
|
-
randomScalar: (c = wt) => e.toBytes(v(c).scalar),
|
|
2110
|
-
generateSecretPolynomial: (c, m, y, x) => {
|
|
2111
|
-
const A = _(c, m, y, x);
|
|
2112
|
-
return {
|
|
2113
|
-
...A,
|
|
2114
|
-
commitment: A.commitment.map(O)
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
})
|
|
2118
|
-
};
|
|
2119
|
-
return Object.freeze(it);
|
|
2120
|
-
}
|
|
2121
|
-
Er();
|
|
2122
|
-
Qt();
|
|
2123
|
-
var En = (t, n) => (t + (t >= 0 ? n : -n) / Bt) / n;
|
|
2124
|
-
function lo(t, n, e) {
|
|
2125
|
-
Mn("scalar", t, yt, e);
|
|
2126
|
-
const [[r, o], [i, a]] = n, f = En(a * t, e), l = En(-o * t, e);
|
|
2127
|
-
let g = t - f * r - l * i, s = -f * o - l * a;
|
|
2128
|
-
const u = g < yt, d = s < yt;
|
|
2129
|
-
u && (g = -g), d && (s = -s);
|
|
2130
|
-
const h = pe(Math.ceil(ye(e) / 2)) + ct;
|
|
2131
|
-
if (g < yt || g >= h || s < yt || s >= h) throw new Error("splitScalar (endomorphism): failed for k");
|
|
1368
|
+
Ln();
|
|
1369
|
+
It();
|
|
1370
|
+
var De = (t, e) => (t + (t >= 0 ? e : -e) / _n) / e;
|
|
1371
|
+
function lr(t, e, r) {
|
|
1372
|
+
dn("scalar", t, ot, r);
|
|
1373
|
+
const [[n, o], [i, c]] = e, s = De(c * t, r), a = De(-o * t, r);
|
|
1374
|
+
let u = t - s * n - a * i, f = -s * o - a * c;
|
|
1375
|
+
const g = u < ot, m = f < ot;
|
|
1376
|
+
g && (u = -u), m && (f = -f);
|
|
1377
|
+
const w = Ee(Math.ceil(ye(r) / 2)) + ht;
|
|
1378
|
+
if (u < ot || u >= w || f < ot || f >= w) throw new Error("splitScalar (endomorphism): failed for k");
|
|
2132
1379
|
return {
|
|
2133
|
-
k1neg:
|
|
2134
|
-
k1:
|
|
2135
|
-
k2neg:
|
|
2136
|
-
k2:
|
|
1380
|
+
k1neg: g,
|
|
1381
|
+
k1: u,
|
|
1382
|
+
k2neg: m,
|
|
1383
|
+
k2: f
|
|
2137
1384
|
};
|
|
2138
1385
|
}
|
|
2139
|
-
function
|
|
1386
|
+
function ae(t) {
|
|
2140
1387
|
if (![
|
|
2141
1388
|
"compact",
|
|
2142
1389
|
"recovered",
|
|
@@ -2144,96 +1391,96 @@ function ze(t) {
|
|
|
2144
1391
|
].includes(t)) throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
2145
1392
|
return t;
|
|
2146
1393
|
}
|
|
2147
|
-
function
|
|
2148
|
-
|
|
2149
|
-
const
|
|
2150
|
-
for (let
|
|
2151
|
-
return
|
|
1394
|
+
function Xt(t, e) {
|
|
1395
|
+
kt(t);
|
|
1396
|
+
const r = {};
|
|
1397
|
+
for (let n of Object.keys(e)) r[n] = t[n] === void 0 ? e[n] : t[n];
|
|
1398
|
+
return Ot(r.lowS, "lowS"), Ot(r.prehash, "prehash"), r.format !== void 0 && ae(r.format), r;
|
|
2152
1399
|
}
|
|
2153
|
-
var
|
|
1400
|
+
var hr = class extends Error {
|
|
2154
1401
|
constructor(t = "") {
|
|
2155
1402
|
super(t);
|
|
2156
1403
|
}
|
|
2157
|
-
},
|
|
2158
|
-
Err:
|
|
1404
|
+
}, et = {
|
|
1405
|
+
Err: hr,
|
|
2159
1406
|
_tlv: {
|
|
2160
|
-
encode: (t,
|
|
2161
|
-
const { Err:
|
|
2162
|
-
if (
|
|
2163
|
-
if (typeof
|
|
2164
|
-
if (
|
|
2165
|
-
const
|
|
2166
|
-
if (o.length / 2 & 128) throw new
|
|
2167
|
-
const i =
|
|
2168
|
-
return
|
|
1407
|
+
encode: (t, e) => {
|
|
1408
|
+
const { Err: r } = et;
|
|
1409
|
+
if (fe(t, "tag"), t < 0 || t > 255) throw new r("tlv.encode: wrong tag");
|
|
1410
|
+
if (typeof e != "string") throw new TypeError('"data" expected string, got type=' + typeof e);
|
|
1411
|
+
if (e.length & 1) throw new r("tlv.encode: unpadded data");
|
|
1412
|
+
const n = e.length / 2, o = Nt(n);
|
|
1413
|
+
if (o.length / 2 & 128) throw new r("tlv.encode: long form length too big");
|
|
1414
|
+
const i = n > 127 ? Nt(o.length / 2 | 128) : "";
|
|
1415
|
+
return Nt(t) + i + o + e;
|
|
2169
1416
|
},
|
|
2170
|
-
decode(t,
|
|
2171
|
-
const { Err:
|
|
2172
|
-
|
|
2173
|
-
let
|
|
2174
|
-
if (t < 0 || t > 255) throw new
|
|
2175
|
-
if (
|
|
2176
|
-
const o = n
|
|
2177
|
-
let
|
|
2178
|
-
if (!i)
|
|
1417
|
+
decode(t, e) {
|
|
1418
|
+
const { Err: r } = et;
|
|
1419
|
+
e = W(e, void 0, "DER data");
|
|
1420
|
+
let n = 0;
|
|
1421
|
+
if (t < 0 || t > 255) throw new r("tlv.encode: wrong tag");
|
|
1422
|
+
if (e.length < 2 || e[n++] !== t) throw new r("tlv.decode: wrong tlv");
|
|
1423
|
+
const o = e[n++], i = !!(o & 128);
|
|
1424
|
+
let c = 0;
|
|
1425
|
+
if (!i) c = o;
|
|
2179
1426
|
else {
|
|
2180
|
-
const
|
|
2181
|
-
if (!
|
|
2182
|
-
if (
|
|
2183
|
-
const
|
|
2184
|
-
if (
|
|
2185
|
-
if (
|
|
2186
|
-
for (const
|
|
2187
|
-
if (
|
|
1427
|
+
const a = o & 127;
|
|
1428
|
+
if (!a) throw new r("tlv.decode(long): indefinite length not supported");
|
|
1429
|
+
if (a > 4) throw new r("tlv.decode(long): byte length is too big");
|
|
1430
|
+
const u = e.subarray(n, n + a);
|
|
1431
|
+
if (u.length !== a) throw new r("tlv.decode: length bytes not complete");
|
|
1432
|
+
if (u[0] === 0) throw new r("tlv.decode(long): zero leftmost byte");
|
|
1433
|
+
for (const f of u) c = c << 8 | f;
|
|
1434
|
+
if (n += a, c < 128) throw new r("tlv.decode(long): not minimal encoding");
|
|
2188
1435
|
}
|
|
2189
|
-
const
|
|
2190
|
-
if (
|
|
1436
|
+
const s = e.subarray(n, n + c);
|
|
1437
|
+
if (s.length !== c) throw new r("tlv.decode: wrong value length");
|
|
2191
1438
|
return {
|
|
2192
|
-
v:
|
|
2193
|
-
l:
|
|
1439
|
+
v: s,
|
|
1440
|
+
l: e.subarray(n + c)
|
|
2194
1441
|
};
|
|
2195
1442
|
}
|
|
2196
1443
|
},
|
|
2197
1444
|
_int: {
|
|
2198
1445
|
encode(t) {
|
|
2199
|
-
const { Err:
|
|
2200
|
-
if (
|
|
2201
|
-
let
|
|
2202
|
-
if (Number.parseInt(
|
|
2203
|
-
return
|
|
1446
|
+
const { Err: e } = et;
|
|
1447
|
+
if (we(t), t < ot) throw new e("integer: negative integers are not allowed");
|
|
1448
|
+
let r = Nt(t);
|
|
1449
|
+
if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1) throw new e("unexpected DER parsing assertion: unpadded hex");
|
|
1450
|
+
return r;
|
|
2204
1451
|
},
|
|
2205
1452
|
decode(t) {
|
|
2206
|
-
const { Err:
|
|
2207
|
-
if (t.length < 1) throw new
|
|
2208
|
-
if (t[0] & 128) throw new
|
|
2209
|
-
if (t.length > 1 && t[0] === 0 && !(t[1] & 128)) throw new
|
|
2210
|
-
return
|
|
1453
|
+
const { Err: e } = et;
|
|
1454
|
+
if (t.length < 1) throw new e("invalid signature integer: empty");
|
|
1455
|
+
if (t[0] & 128) throw new e("invalid signature integer: negative");
|
|
1456
|
+
if (t.length > 1 && t[0] === 0 && !(t[1] & 128)) throw new e("invalid signature integer: unnecessary leading zero");
|
|
1457
|
+
return Ct(t);
|
|
2211
1458
|
}
|
|
2212
1459
|
},
|
|
2213
1460
|
toSig(t) {
|
|
2214
|
-
const { Err:
|
|
2215
|
-
if (
|
|
2216
|
-
const { v:
|
|
2217
|
-
if (
|
|
1461
|
+
const { Err: e, _int: r, _tlv: n } = et, o = W(t, void 0, "signature"), { v: i, l: c } = n.decode(48, o);
|
|
1462
|
+
if (c.length) throw new e("invalid signature: left bytes after parsing");
|
|
1463
|
+
const { v: s, l: a } = n.decode(2, i), { v: u, l: f } = n.decode(2, a);
|
|
1464
|
+
if (f.length) throw new e("invalid signature: left bytes after parsing");
|
|
2218
1465
|
return {
|
|
2219
|
-
r:
|
|
2220
|
-
s:
|
|
1466
|
+
r: r.decode(s),
|
|
1467
|
+
s: r.decode(u)
|
|
2221
1468
|
};
|
|
2222
1469
|
},
|
|
2223
1470
|
hexFromSig(t) {
|
|
2224
|
-
const { _tlv:
|
|
2225
|
-
return
|
|
1471
|
+
const { _tlv: e, _int: r } = et, n = e.encode(2, r.encode(t.r)) + e.encode(2, r.encode(t.s));
|
|
1472
|
+
return e.encode(48, n);
|
|
2226
1473
|
}
|
|
2227
1474
|
};
|
|
2228
|
-
Object.freeze(
|
|
2229
|
-
Object.freeze(
|
|
2230
|
-
Object.freeze(
|
|
2231
|
-
var
|
|
2232
|
-
function
|
|
2233
|
-
const
|
|
2234
|
-
let i =
|
|
2235
|
-
const { h:
|
|
2236
|
-
|
|
1475
|
+
Object.freeze(et._tlv);
|
|
1476
|
+
Object.freeze(et._int);
|
|
1477
|
+
Object.freeze(et);
|
|
1478
|
+
var ot = /* @__PURE__ */ BigInt(0), ht = /* @__PURE__ */ BigInt(1), _n = /* @__PURE__ */ BigInt(2), Tt = /* @__PURE__ */ BigInt(3), dr = /* @__PURE__ */ BigInt(4);
|
|
1479
|
+
function gr(t, e = {}) {
|
|
1480
|
+
const r = ar("weierstrass", t, e), n = r.Fp, o = r.Fn;
|
|
1481
|
+
let i = r.CURVE;
|
|
1482
|
+
const { h: c, n: s } = i;
|
|
1483
|
+
kt(e, {}, {
|
|
2237
1484
|
allowInfinityPoint: "boolean",
|
|
2238
1485
|
clearCofactor: "function",
|
|
2239
1486
|
isTorsionFree: "function",
|
|
@@ -2241,103 +1488,103 @@ function ho(t, n = {}) {
|
|
|
2241
1488
|
toBytes: "function",
|
|
2242
1489
|
endo: "object"
|
|
2243
1490
|
});
|
|
2244
|
-
const { endo:
|
|
2245
|
-
if (
|
|
1491
|
+
const { endo: a, allowInfinityPoint: u } = e;
|
|
1492
|
+
if (a && (!n.is0(i.a) || typeof a.beta != "bigint" || !Array.isArray(a.basises)))
|
|
2246
1493
|
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
2247
|
-
const
|
|
2248
|
-
function
|
|
2249
|
-
if (!
|
|
2250
|
-
}
|
|
2251
|
-
function
|
|
2252
|
-
if (
|
|
2253
|
-
const { x:
|
|
2254
|
-
return
|
|
2255
|
-
}
|
|
2256
|
-
function
|
|
2257
|
-
|
|
2258
|
-
const { publicKey:
|
|
2259
|
-
if (
|
|
2260
|
-
x:
|
|
2261
|
-
y:
|
|
1494
|
+
const f = On(n, o);
|
|
1495
|
+
function g() {
|
|
1496
|
+
if (!n.isOdd) throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
1497
|
+
}
|
|
1498
|
+
function m(F, h, y) {
|
|
1499
|
+
if (u && h.is0()) return Uint8Array.of(0);
|
|
1500
|
+
const { x: B, y: d } = h.toAffine(), l = n.toBytes(B);
|
|
1501
|
+
return Ot(y, "isCompressed"), y ? (g(), lt(Hn(!n.isOdd(d)), l)) : lt(Uint8Array.of(4), l, n.toBytes(d));
|
|
1502
|
+
}
|
|
1503
|
+
function w(F) {
|
|
1504
|
+
W(F, void 0, "Point");
|
|
1505
|
+
const { publicKey: h, publicKeyUncompressed: y } = f, B = F.length, d = F[0], l = F.subarray(1);
|
|
1506
|
+
if (u && B === 1 && d === 0) return {
|
|
1507
|
+
x: n.ZERO,
|
|
1508
|
+
y: n.ZERO
|
|
2262
1509
|
};
|
|
2263
|
-
if (
|
|
2264
|
-
const
|
|
2265
|
-
if (!
|
|
2266
|
-
const
|
|
2267
|
-
let
|
|
1510
|
+
if (B === h && (d === 2 || d === 3)) {
|
|
1511
|
+
const b = n.fromBytes(l);
|
|
1512
|
+
if (!n.isValid(b)) throw new Error("bad point: is not on curve, wrong x");
|
|
1513
|
+
const E = H(b);
|
|
1514
|
+
let p;
|
|
2268
1515
|
try {
|
|
2269
|
-
|
|
2270
|
-
} catch (
|
|
2271
|
-
const
|
|
2272
|
-
throw new Error("bad point: is not on curve, sqrt error" +
|
|
1516
|
+
p = n.sqrt(E);
|
|
1517
|
+
} catch (S) {
|
|
1518
|
+
const N = S instanceof Error ? ": " + S.message : "";
|
|
1519
|
+
throw new Error("bad point: is not on curve, sqrt error" + N);
|
|
2273
1520
|
}
|
|
2274
|
-
|
|
2275
|
-
const
|
|
2276
|
-
return (
|
|
2277
|
-
x:
|
|
2278
|
-
y:
|
|
1521
|
+
g();
|
|
1522
|
+
const v = n.isOdd(p);
|
|
1523
|
+
return (d & 1) === 1 !== v && (p = n.neg(p)), {
|
|
1524
|
+
x: b,
|
|
1525
|
+
y: p
|
|
2279
1526
|
};
|
|
2280
|
-
} else if (
|
|
2281
|
-
const
|
|
2282
|
-
if (!
|
|
1527
|
+
} else if (B === y && d === 4) {
|
|
1528
|
+
const b = n.BYTES, E = n.fromBytes(l.subarray(0, b)), p = n.fromBytes(l.subarray(b, b * 2));
|
|
1529
|
+
if (!O(E, p)) throw new Error("bad point: is not on curve");
|
|
2283
1530
|
return {
|
|
2284
|
-
x:
|
|
2285
|
-
y:
|
|
1531
|
+
x: E,
|
|
1532
|
+
y: p
|
|
2286
1533
|
};
|
|
2287
|
-
} else throw new Error(`bad point: got length ${
|
|
2288
|
-
}
|
|
2289
|
-
const
|
|
2290
|
-
function
|
|
2291
|
-
const
|
|
2292
|
-
return
|
|
2293
|
-
}
|
|
2294
|
-
function
|
|
2295
|
-
const
|
|
2296
|
-
return
|
|
2297
|
-
}
|
|
2298
|
-
if (!
|
|
2299
|
-
const
|
|
2300
|
-
if (
|
|
2301
|
-
function
|
|
2302
|
-
if (!
|
|
2303
|
-
return
|
|
2304
|
-
}
|
|
2305
|
-
function F
|
|
2306
|
-
if (!(
|
|
2307
|
-
}
|
|
2308
|
-
function
|
|
2309
|
-
if (!
|
|
2310
|
-
return
|
|
2311
|
-
}
|
|
2312
|
-
function
|
|
2313
|
-
return
|
|
2314
|
-
}
|
|
2315
|
-
class
|
|
2316
|
-
static BASE = new
|
|
2317
|
-
static ZERO = new
|
|
2318
|
-
static Fp =
|
|
1534
|
+
} else throw new Error(`bad point: got length ${B}, expected compressed=${h} or uncompressed=${y}`);
|
|
1535
|
+
}
|
|
1536
|
+
const A = e.toBytes === void 0 ? m : e.toBytes, _ = e.fromBytes === void 0 ? w : e.fromBytes;
|
|
1537
|
+
function H(F) {
|
|
1538
|
+
const h = n.sqr(F), y = n.mul(h, F);
|
|
1539
|
+
return n.add(n.add(y, n.mul(F, i.a)), i.b);
|
|
1540
|
+
}
|
|
1541
|
+
function O(F, h) {
|
|
1542
|
+
const y = n.sqr(h), B = H(F);
|
|
1543
|
+
return n.eql(y, B);
|
|
1544
|
+
}
|
|
1545
|
+
if (!O(i.Gx, i.Gy)) throw new Error("bad curve params: generator point");
|
|
1546
|
+
const x = n.mul(n.pow(i.a, Tt), dr), q = n.mul(n.sqr(i.b), BigInt(27));
|
|
1547
|
+
if (n.is0(n.add(x, q))) throw new Error("bad curve params: a or b");
|
|
1548
|
+
function Z(F, h, y = !1) {
|
|
1549
|
+
if (!n.isValid(h) || y && n.is0(h)) throw new Error(`bad point coordinate ${F}`);
|
|
1550
|
+
return h;
|
|
1551
|
+
}
|
|
1552
|
+
function T(F) {
|
|
1553
|
+
if (!(F instanceof R)) throw new Error("Weierstrass Point expected");
|
|
1554
|
+
}
|
|
1555
|
+
function Q(F) {
|
|
1556
|
+
if (!a || !a.basises) throw new Error("no endo");
|
|
1557
|
+
return lr(F, a.basises, o.ORDER);
|
|
1558
|
+
}
|
|
1559
|
+
function $(F, h, y, B, d) {
|
|
1560
|
+
return y = new R(n.mul(y.X, F), y.Y, y.Z), h = Zt(B, h), y = Zt(d, y), h.add(y);
|
|
1561
|
+
}
|
|
1562
|
+
class R {
|
|
1563
|
+
static BASE = new R(i.Gx, i.Gy, n.ONE);
|
|
1564
|
+
static ZERO = new R(n.ZERO, n.ONE, n.ZERO);
|
|
1565
|
+
static Fp = n;
|
|
2319
1566
|
static Fn = o;
|
|
2320
1567
|
X;
|
|
2321
1568
|
Y;
|
|
2322
1569
|
Z;
|
|
2323
|
-
constructor(
|
|
2324
|
-
this.X =
|
|
1570
|
+
constructor(h, y, B) {
|
|
1571
|
+
this.X = Z("x", h), this.Y = Z("y", y, !0), this.Z = Z("z", B), Object.freeze(this);
|
|
2325
1572
|
}
|
|
2326
1573
|
static CURVE() {
|
|
2327
1574
|
return i;
|
|
2328
1575
|
}
|
|
2329
|
-
static fromAffine(
|
|
2330
|
-
const { x:
|
|
2331
|
-
if (!
|
|
2332
|
-
if (
|
|
2333
|
-
return
|
|
1576
|
+
static fromAffine(h) {
|
|
1577
|
+
const { x: y, y: B } = h || {};
|
|
1578
|
+
if (!h || !n.isValid(y) || !n.isValid(B)) throw new Error("invalid affine point");
|
|
1579
|
+
if (h instanceof R) throw new Error("projective point not allowed");
|
|
1580
|
+
return n.is0(y) && n.is0(B) ? R.ZERO : new R(y, B, n.ONE);
|
|
2334
1581
|
}
|
|
2335
|
-
static fromBytes(
|
|
2336
|
-
const
|
|
2337
|
-
return
|
|
1582
|
+
static fromBytes(h) {
|
|
1583
|
+
const y = R.fromAffine(_(W(h, void 0, "point")));
|
|
1584
|
+
return y.assertValidity(), y;
|
|
2338
1585
|
}
|
|
2339
|
-
static fromHex(
|
|
2340
|
-
return
|
|
1586
|
+
static fromHex(h) {
|
|
1587
|
+
return R.fromBytes(se(h));
|
|
2341
1588
|
}
|
|
2342
1589
|
get x() {
|
|
2343
1590
|
return this.toAffine().x;
|
|
@@ -2345,420 +1592,354 @@ function ho(t, n = {}) {
|
|
|
2345
1592
|
get y() {
|
|
2346
1593
|
return this.toAffine().y;
|
|
2347
1594
|
}
|
|
2348
|
-
precompute(
|
|
2349
|
-
return
|
|
1595
|
+
precompute(h = 8, y = !0) {
|
|
1596
|
+
return X.createCache(this, h), y || this.multiply(Tt), this;
|
|
2350
1597
|
}
|
|
2351
1598
|
assertValidity() {
|
|
2352
|
-
const
|
|
2353
|
-
if (
|
|
2354
|
-
if (
|
|
1599
|
+
const h = this;
|
|
1600
|
+
if (h.is0()) {
|
|
1601
|
+
if (e.allowInfinityPoint && n.is0(h.X) && n.eql(h.Y, n.ONE) && n.is0(h.Z)) return;
|
|
2355
1602
|
throw new Error("bad point: ZERO");
|
|
2356
1603
|
}
|
|
2357
|
-
const { x:
|
|
2358
|
-
if (!
|
|
2359
|
-
if (!
|
|
2360
|
-
if (!
|
|
1604
|
+
const { x: y, y: B } = h.toAffine();
|
|
1605
|
+
if (!n.isValid(y) || !n.isValid(B)) throw new Error("bad point: x or y not field elements");
|
|
1606
|
+
if (!O(y, B)) throw new Error("bad point: equation left != right");
|
|
1607
|
+
if (!h.isTorsionFree()) throw new Error("bad point: not in prime-order subgroup");
|
|
2361
1608
|
}
|
|
2362
1609
|
hasEvenY() {
|
|
2363
|
-
const { y:
|
|
2364
|
-
if (!
|
|
2365
|
-
return !
|
|
1610
|
+
const { y: h } = this.toAffine();
|
|
1611
|
+
if (!n.isOdd) throw new Error("Field doesn't support isOdd");
|
|
1612
|
+
return !n.isOdd(h);
|
|
2366
1613
|
}
|
|
2367
|
-
equals(
|
|
2368
|
-
|
|
2369
|
-
const { X:
|
|
2370
|
-
return
|
|
1614
|
+
equals(h) {
|
|
1615
|
+
T(h);
|
|
1616
|
+
const { X: y, Y: B, Z: d } = this, { X: l, Y: b, Z: E } = h, p = n.eql(n.mul(y, E), n.mul(l, d)), v = n.eql(n.mul(B, E), n.mul(b, d));
|
|
1617
|
+
return p && v;
|
|
2371
1618
|
}
|
|
2372
1619
|
negate() {
|
|
2373
|
-
return new
|
|
1620
|
+
return new R(this.X, n.neg(this.Y), this.Z);
|
|
2374
1621
|
}
|
|
2375
1622
|
double() {
|
|
2376
|
-
const { a:
|
|
2377
|
-
let
|
|
2378
|
-
return
|
|
2379
|
-
}
|
|
2380
|
-
add(
|
|
2381
|
-
|
|
2382
|
-
const { X:
|
|
2383
|
-
let
|
|
2384
|
-
const
|
|
2385
|
-
let
|
|
2386
|
-
|
|
2387
|
-
let
|
|
2388
|
-
return
|
|
2389
|
-
}
|
|
2390
|
-
subtract(
|
|
2391
|
-
return
|
|
1623
|
+
const { a: h, b: y } = i, B = n.mul(y, Tt), { X: d, Y: l, Z: b } = this;
|
|
1624
|
+
let E = n.ZERO, p = n.ZERO, v = n.ZERO, S = n.mul(d, d), N = n.mul(l, l), L = n.mul(b, b), I = n.mul(d, l);
|
|
1625
|
+
return I = n.add(I, I), v = n.mul(d, b), v = n.add(v, v), E = n.mul(h, v), p = n.mul(B, L), p = n.add(E, p), E = n.sub(N, p), p = n.add(N, p), p = n.mul(E, p), E = n.mul(I, E), v = n.mul(B, v), L = n.mul(h, L), I = n.sub(S, L), I = n.mul(h, I), I = n.add(I, v), v = n.add(S, S), S = n.add(v, S), S = n.add(S, L), S = n.mul(S, I), p = n.add(p, S), L = n.mul(l, b), L = n.add(L, L), S = n.mul(L, I), E = n.sub(E, S), v = n.mul(L, N), v = n.add(v, v), v = n.add(v, v), new R(E, p, v);
|
|
1626
|
+
}
|
|
1627
|
+
add(h) {
|
|
1628
|
+
T(h);
|
|
1629
|
+
const { X: y, Y: B, Z: d } = this, { X: l, Y: b, Z: E } = h;
|
|
1630
|
+
let p = n.ZERO, v = n.ZERO, S = n.ZERO;
|
|
1631
|
+
const N = i.a, L = n.mul(i.b, Tt);
|
|
1632
|
+
let I = n.mul(y, l), k = n.mul(B, b), j = n.mul(d, E), V = n.add(y, B), U = n.add(l, b);
|
|
1633
|
+
V = n.mul(V, U), U = n.add(I, k), V = n.sub(V, U), U = n.add(y, d);
|
|
1634
|
+
let J = n.add(l, E);
|
|
1635
|
+
return U = n.mul(U, J), J = n.add(I, j), U = n.sub(U, J), J = n.add(B, d), p = n.add(b, E), J = n.mul(J, p), p = n.add(k, j), J = n.sub(J, p), S = n.mul(N, U), p = n.mul(L, j), S = n.add(p, S), p = n.sub(k, S), S = n.add(k, S), v = n.mul(p, S), k = n.add(I, I), k = n.add(k, I), j = n.mul(N, j), U = n.mul(L, U), k = n.add(k, j), j = n.sub(I, j), j = n.mul(N, j), U = n.add(U, j), I = n.mul(k, U), v = n.add(v, I), I = n.mul(J, U), p = n.mul(V, p), p = n.sub(p, I), I = n.mul(V, k), S = n.mul(J, S), S = n.add(S, I), new R(p, v, S);
|
|
1636
|
+
}
|
|
1637
|
+
subtract(h) {
|
|
1638
|
+
return T(h), this.add(h.negate());
|
|
2392
1639
|
}
|
|
2393
1640
|
is0() {
|
|
2394
|
-
return this.equals(
|
|
2395
|
-
}
|
|
2396
|
-
multiply(
|
|
2397
|
-
const { endo:
|
|
2398
|
-
if (!o.isValidNot0(
|
|
2399
|
-
let
|
|
2400
|
-
const
|
|
2401
|
-
if (
|
|
2402
|
-
const { k1neg:
|
|
2403
|
-
|
|
1641
|
+
return this.equals(R.ZERO);
|
|
1642
|
+
}
|
|
1643
|
+
multiply(h) {
|
|
1644
|
+
const { endo: y } = e;
|
|
1645
|
+
if (!o.isValidNot0(h)) throw new RangeError("invalid scalar: out of range");
|
|
1646
|
+
let B, d;
|
|
1647
|
+
const l = (b) => X.cached(this, b, (E) => Ne(R, E));
|
|
1648
|
+
if (y) {
|
|
1649
|
+
const { k1neg: b, k1: E, k2neg: p, k2: v } = Q(h), { p: S, f: N } = l(E), { p: L, f: I } = l(v);
|
|
1650
|
+
d = N.add(I), B = $(y.beta, S, L, b, p);
|
|
2404
1651
|
} else {
|
|
2405
|
-
const { p:
|
|
2406
|
-
|
|
1652
|
+
const { p: b, f: E } = l(h);
|
|
1653
|
+
B = b, d = E;
|
|
2407
1654
|
}
|
|
2408
|
-
return
|
|
2409
|
-
}
|
|
2410
|
-
multiplyUnsafe(
|
|
2411
|
-
const { endo:
|
|
2412
|
-
if (!o.isValid(
|
|
2413
|
-
if (
|
|
2414
|
-
if (
|
|
2415
|
-
if (
|
|
2416
|
-
if (
|
|
2417
|
-
const { k1neg:
|
|
2418
|
-
return
|
|
2419
|
-
} else return
|
|
2420
|
-
}
|
|
2421
|
-
toAffine(
|
|
2422
|
-
const
|
|
2423
|
-
let
|
|
2424
|
-
const { X:
|
|
2425
|
-
if (
|
|
2426
|
-
x:
|
|
2427
|
-
y:
|
|
1655
|
+
return Ne(R, [B, d])[0];
|
|
1656
|
+
}
|
|
1657
|
+
multiplyUnsafe(h) {
|
|
1658
|
+
const { endo: y } = e, B = this, d = h;
|
|
1659
|
+
if (!o.isValid(d)) throw new RangeError("invalid scalar: out of range");
|
|
1660
|
+
if (d === ot || B.is0()) return R.ZERO;
|
|
1661
|
+
if (d === ht) return B;
|
|
1662
|
+
if (X.hasCache(this)) return this.multiply(d);
|
|
1663
|
+
if (y) {
|
|
1664
|
+
const { k1neg: l, k1: b, k2neg: E, k2: p } = Q(d), { p1: v, p2: S } = fr(R, B, b, p);
|
|
1665
|
+
return $(y.beta, v, S, l, E);
|
|
1666
|
+
} else return X.unsafe(B, d);
|
|
1667
|
+
}
|
|
1668
|
+
toAffine(h) {
|
|
1669
|
+
const y = this;
|
|
1670
|
+
let B = h;
|
|
1671
|
+
const { X: d, Y: l, Z: b } = y;
|
|
1672
|
+
if (n.eql(b, n.ONE)) return {
|
|
1673
|
+
x: d,
|
|
1674
|
+
y: l
|
|
2428
1675
|
};
|
|
2429
|
-
const
|
|
2430
|
-
|
|
2431
|
-
const
|
|
2432
|
-
if (
|
|
2433
|
-
x:
|
|
2434
|
-
y:
|
|
1676
|
+
const E = y.is0();
|
|
1677
|
+
B == null && (B = E ? n.ONE : n.inv(b));
|
|
1678
|
+
const p = n.mul(d, B), v = n.mul(l, B), S = n.mul(b, B);
|
|
1679
|
+
if (E) return {
|
|
1680
|
+
x: n.ZERO,
|
|
1681
|
+
y: n.ZERO
|
|
2435
1682
|
};
|
|
2436
|
-
if (!
|
|
1683
|
+
if (!n.eql(S, n.ONE)) throw new Error("invZ was invalid");
|
|
2437
1684
|
return {
|
|
2438
|
-
x:
|
|
2439
|
-
y:
|
|
1685
|
+
x: p,
|
|
1686
|
+
y: v
|
|
2440
1687
|
};
|
|
2441
1688
|
}
|
|
2442
1689
|
isTorsionFree() {
|
|
2443
|
-
const { isTorsionFree:
|
|
2444
|
-
return
|
|
1690
|
+
const { isTorsionFree: h } = e;
|
|
1691
|
+
return c === ht ? !0 : h ? h(R, this) : X.unsafe(this, s).is0();
|
|
2445
1692
|
}
|
|
2446
1693
|
clearCofactor() {
|
|
2447
|
-
const { clearCofactor:
|
|
2448
|
-
return
|
|
1694
|
+
const { clearCofactor: h } = e;
|
|
1695
|
+
return c === ht ? this : h ? h(R, this) : this.multiplyUnsafe(c);
|
|
2449
1696
|
}
|
|
2450
1697
|
isSmallOrder() {
|
|
2451
|
-
return
|
|
1698
|
+
return c === ht ? this.is0() : this.clearCofactor().is0();
|
|
2452
1699
|
}
|
|
2453
|
-
toBytes(
|
|
2454
|
-
return
|
|
1700
|
+
toBytes(h = !0) {
|
|
1701
|
+
return Ot(h, "isCompressed"), this.assertValidity(), A(R, this, h);
|
|
2455
1702
|
}
|
|
2456
|
-
toHex(
|
|
2457
|
-
return
|
|
1703
|
+
toHex(h = !0) {
|
|
1704
|
+
return cn(this.toBytes(h));
|
|
2458
1705
|
}
|
|
2459
1706
|
toString() {
|
|
2460
1707
|
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
2461
1708
|
}
|
|
2462
1709
|
}
|
|
2463
|
-
const
|
|
2464
|
-
return
|
|
1710
|
+
const C = o.BITS, X = new cr(R, e.endo ? Math.ceil(C / 2) : C);
|
|
1711
|
+
return C >= 8 && R.BASE.precompute(8), Object.freeze(R.prototype), Object.freeze(R), R;
|
|
2465
1712
|
}
|
|
2466
|
-
function
|
|
1713
|
+
function Hn(t) {
|
|
2467
1714
|
return Uint8Array.of(t ? 2 : 3);
|
|
2468
1715
|
}
|
|
2469
|
-
function
|
|
2470
|
-
const e = se(t), r = e.ORDER;
|
|
2471
|
-
let o = yt;
|
|
2472
|
-
for (let b = r - ct; b % Bt === yt; b /= Bt) o += ct;
|
|
2473
|
-
const i = o, a = Bt << i - ct - ct, f = a * Bt, l = (r - ct) / f, g = (l - ct) / Bt, s = f - ct, u = a, d = e.pow(n, l), h = e.pow(n, (l + ct) / Bt);
|
|
2474
|
-
let w = (b, E) => {
|
|
2475
|
-
let T = d, B = e.pow(E, s), C = e.sqr(B);
|
|
2476
|
-
C = e.mul(C, E);
|
|
2477
|
-
let O = e.mul(b, C);
|
|
2478
|
-
O = e.pow(O, g), O = e.mul(O, B), B = e.mul(O, E), C = e.mul(O, b);
|
|
2479
|
-
let F = e.mul(C, B);
|
|
2480
|
-
O = e.pow(F, u);
|
|
2481
|
-
let z = e.eql(O, e.ONE);
|
|
2482
|
-
B = e.mul(C, h), O = e.mul(F, T), C = e.cmov(B, C, z), F = e.cmov(O, F, z);
|
|
2483
|
-
for (let W = i; W > ct; W--) {
|
|
2484
|
-
let N = W - Bt;
|
|
2485
|
-
N = Bt << N - ct;
|
|
2486
|
-
let V = e.pow(F, N);
|
|
2487
|
-
const K = e.eql(V, e.ONE);
|
|
2488
|
-
B = e.mul(C, T), T = e.mul(T, T), V = e.mul(F, T), C = e.cmov(B, C, K), F = e.cmov(V, F, K);
|
|
2489
|
-
}
|
|
2490
|
-
return {
|
|
2491
|
-
isValid: !e.is0(E) && (z || e.is0(b)),
|
|
2492
|
-
value: C
|
|
2493
|
-
};
|
|
2494
|
-
};
|
|
2495
|
-
if (e.ORDER % Me === Xt) {
|
|
2496
|
-
const b = (e.ORDER - Xt) / Me, E = e.sqrt(e.neg(n));
|
|
2497
|
-
w = (T, B) => {
|
|
2498
|
-
let C = e.sqr(B);
|
|
2499
|
-
const O = e.mul(T, B);
|
|
2500
|
-
C = e.mul(C, O);
|
|
2501
|
-
let F = e.pow(C, b);
|
|
2502
|
-
F = e.mul(F, O);
|
|
2503
|
-
const z = e.mul(F, E), W = e.mul(e.sqr(F), B), N = e.eql(W, T);
|
|
2504
|
-
let V = e.cmov(z, F, N);
|
|
2505
|
-
return {
|
|
2506
|
-
isValid: !e.is0(B) && N,
|
|
2507
|
-
value: V
|
|
2508
|
-
};
|
|
2509
|
-
};
|
|
2510
|
-
}
|
|
2511
|
-
return w;
|
|
2512
|
-
}
|
|
2513
|
-
function go(t, n) {
|
|
2514
|
-
const e = se(t), { A: r, B: o, Z: i } = n;
|
|
2515
|
-
if (!e.isValidNot0(r) || !e.isValidNot0(o) || !e.isValid(i)) throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
2516
|
-
if (e.eql(i, e.neg(e.ONE)) || hn(e, i)) throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
2517
|
-
const a = e.mul(o, e.inv(e.mul(i, r)));
|
|
2518
|
-
if (!hn(e, e.add(e.add(e.mul(e.sqr(a), a), e.mul(r, a)), o))) throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
2519
|
-
const f = mo(e, i);
|
|
2520
|
-
if (!e.isOdd) throw new Error("Field does not have .isOdd()");
|
|
2521
|
-
return (l) => {
|
|
2522
|
-
let g, s, u, d, h, w, b, E;
|
|
2523
|
-
g = e.sqr(l), g = e.mul(g, i), s = e.sqr(g), s = e.add(s, g), u = e.add(s, e.ONE), u = e.mul(u, o), d = e.cmov(i, e.neg(s), !e.eql(s, e.ZERO)), d = e.mul(d, r), s = e.sqr(u), w = e.sqr(d), h = e.mul(w, r), s = e.add(s, h), s = e.mul(s, u), w = e.mul(w, d), h = e.mul(w, o), s = e.add(s, h), b = e.mul(g, u);
|
|
2524
|
-
const { isValid: T, value: B } = f(s, w);
|
|
2525
|
-
E = e.mul(g, l), E = e.mul(E, B), b = e.cmov(b, u, T), E = e.cmov(E, B, T);
|
|
2526
|
-
const C = e.isOdd(l) === e.isOdd(E);
|
|
2527
|
-
E = e.cmov(e.neg(E), E, C);
|
|
2528
|
-
const O = Ee(e, [d], !0)[0];
|
|
2529
|
-
return b = e.mul(b, O), {
|
|
2530
|
-
x: b,
|
|
2531
|
-
y: E
|
|
2532
|
-
};
|
|
2533
|
-
};
|
|
2534
|
-
}
|
|
2535
|
-
function ar(t, n) {
|
|
1716
|
+
function On(t, e) {
|
|
2536
1717
|
return {
|
|
2537
|
-
secretKey:
|
|
1718
|
+
secretKey: e.BYTES,
|
|
2538
1719
|
publicKey: 1 + t.BYTES,
|
|
2539
1720
|
publicKeyUncompressed: 1 + 2 * t.BYTES,
|
|
2540
1721
|
publicKeyHasPrefix: !0,
|
|
2541
|
-
signature: 2 *
|
|
1722
|
+
signature: 2 * e.BYTES
|
|
2542
1723
|
};
|
|
2543
1724
|
}
|
|
2544
|
-
function
|
|
2545
|
-
const { Fn:
|
|
2546
|
-
function i(
|
|
1725
|
+
function br(t, e = {}) {
|
|
1726
|
+
const { Fn: r } = t, n = e.randomBytes === void 0 ? an : e.randomBytes, o = Object.assign(On(t.Fp, r), { seed: Math.max(An(r.ORDER), 16) });
|
|
1727
|
+
function i(w) {
|
|
2547
1728
|
try {
|
|
2548
|
-
const
|
|
2549
|
-
return
|
|
1729
|
+
const A = r.fromBytes(w);
|
|
1730
|
+
return r.isValidNot0(A);
|
|
2550
1731
|
} catch {
|
|
2551
1732
|
return !1;
|
|
2552
1733
|
}
|
|
2553
1734
|
}
|
|
2554
|
-
function
|
|
2555
|
-
const { publicKey:
|
|
1735
|
+
function c(w, A) {
|
|
1736
|
+
const { publicKey: _, publicKeyUncompressed: H } = o;
|
|
2556
1737
|
try {
|
|
2557
|
-
const
|
|
2558
|
-
return
|
|
1738
|
+
const O = w.length;
|
|
1739
|
+
return A === !0 && O !== _ || A === !1 && O !== H ? !1 : !!t.fromBytes(w);
|
|
2559
1740
|
} catch {
|
|
2560
1741
|
return !1;
|
|
2561
1742
|
}
|
|
2562
1743
|
}
|
|
2563
|
-
function
|
|
2564
|
-
return
|
|
1744
|
+
function s(w) {
|
|
1745
|
+
return w = w === void 0 ? n(o.seed) : w, sr(W(w, o.seed, "seed"), r.ORDER);
|
|
2565
1746
|
}
|
|
2566
|
-
function
|
|
2567
|
-
return t.BASE.multiply(
|
|
1747
|
+
function a(w, A = !0) {
|
|
1748
|
+
return t.BASE.multiply(r.fromBytes(w)).toBytes(A);
|
|
2568
1749
|
}
|
|
2569
|
-
function
|
|
2570
|
-
const { secretKey:
|
|
2571
|
-
if (!
|
|
2572
|
-
const
|
|
2573
|
-
if (!(
|
|
2574
|
-
return
|
|
1750
|
+
function u(w) {
|
|
1751
|
+
const { secretKey: A, publicKey: _, publicKeyUncompressed: H } = o, O = r._lengths;
|
|
1752
|
+
if (!fn(w)) return;
|
|
1753
|
+
const x = W(w, void 0, "key").length, q = x === _ || x === H, Z = x === A || !!O?.includes(x);
|
|
1754
|
+
if (!(q && Z))
|
|
1755
|
+
return q;
|
|
2575
1756
|
}
|
|
2576
|
-
function
|
|
2577
|
-
if (
|
|
2578
|
-
if (
|
|
2579
|
-
const
|
|
2580
|
-
return t.fromBytes(
|
|
1757
|
+
function f(w, A, _ = !0) {
|
|
1758
|
+
if (u(w) === !0) throw new Error("first arg must be private key");
|
|
1759
|
+
if (u(A) === !1) throw new Error("second arg must be public key");
|
|
1760
|
+
const H = r.fromBytes(w);
|
|
1761
|
+
return t.fromBytes(A).multiply(H).toBytes(_);
|
|
2581
1762
|
}
|
|
2582
|
-
const
|
|
1763
|
+
const g = {
|
|
2583
1764
|
isValidSecretKey: i,
|
|
2584
|
-
isValidPublicKey:
|
|
2585
|
-
randomSecretKey:
|
|
2586
|
-
},
|
|
2587
|
-
return Object.freeze(
|
|
2588
|
-
getPublicKey:
|
|
2589
|
-
getSharedSecret:
|
|
2590
|
-
keygen:
|
|
1765
|
+
isValidPublicKey: c,
|
|
1766
|
+
randomSecretKey: s
|
|
1767
|
+
}, m = ur(s, a);
|
|
1768
|
+
return Object.freeze(g), Object.freeze(o), Object.freeze({
|
|
1769
|
+
getPublicKey: a,
|
|
1770
|
+
getSharedSecret: f,
|
|
1771
|
+
keygen: m,
|
|
2591
1772
|
Point: t,
|
|
2592
|
-
utils:
|
|
1773
|
+
utils: g,
|
|
2593
1774
|
lengths: o
|
|
2594
1775
|
});
|
|
2595
1776
|
}
|
|
2596
|
-
function
|
|
2597
|
-
const
|
|
2598
|
-
|
|
1777
|
+
function wr(t, e, r = {}) {
|
|
1778
|
+
const n = e;
|
|
1779
|
+
ke(n), kt(r, {}, {
|
|
2599
1780
|
hmac: "function",
|
|
2600
1781
|
lowS: "boolean",
|
|
2601
1782
|
randomBytes: "function",
|
|
2602
1783
|
bits2int: "function",
|
|
2603
1784
|
bits2int_modN: "function"
|
|
2604
|
-
}),
|
|
2605
|
-
const o =
|
|
1785
|
+
}), r = Object.assign({}, r);
|
|
1786
|
+
const o = r.randomBytes === void 0 ? an : r.randomBytes, i = r.hmac === void 0 ? (d, l) => de(n, d, l) : r.hmac, { Fp: c, Fn: s } = t, { ORDER: a, BITS: u } = s, { keygen: f, getPublicKey: g, getSharedSecret: m, utils: w, lengths: A } = br(t, r), _ = {
|
|
2606
1787
|
prehash: !0,
|
|
2607
|
-
lowS: typeof
|
|
1788
|
+
lowS: typeof r.lowS == "boolean" ? r.lowS : !0,
|
|
2608
1789
|
format: "compact",
|
|
2609
1790
|
extraEntropy: !1
|
|
2610
|
-
},
|
|
2611
|
-
function
|
|
2612
|
-
return
|
|
1791
|
+
}, H = a * _n + ht < c.ORDER;
|
|
1792
|
+
function O(d) {
|
|
1793
|
+
return d > a >> ht;
|
|
2613
1794
|
}
|
|
2614
|
-
function
|
|
2615
|
-
if (!
|
|
2616
|
-
return
|
|
1795
|
+
function x(d, l) {
|
|
1796
|
+
if (!s.isValidNot0(l)) throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);
|
|
1797
|
+
return l;
|
|
2617
1798
|
}
|
|
2618
|
-
function
|
|
2619
|
-
if (
|
|
1799
|
+
function q() {
|
|
1800
|
+
if (H) throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
|
|
2620
1801
|
}
|
|
2621
|
-
function
|
|
2622
|
-
|
|
2623
|
-
const
|
|
2624
|
-
return
|
|
1802
|
+
function Z(d, l) {
|
|
1803
|
+
ae(l);
|
|
1804
|
+
const b = A.signature;
|
|
1805
|
+
return W(d, l === "compact" ? b : l === "recovered" ? b + 1 : void 0);
|
|
2625
1806
|
}
|
|
2626
|
-
class
|
|
1807
|
+
class T {
|
|
2627
1808
|
r;
|
|
2628
1809
|
s;
|
|
2629
1810
|
recovery;
|
|
2630
|
-
constructor(
|
|
2631
|
-
if (this.r =
|
|
2632
|
-
if (
|
|
1811
|
+
constructor(l, b, E) {
|
|
1812
|
+
if (this.r = x("r", l), this.s = x("s", b), E != null) {
|
|
1813
|
+
if (q(), ![
|
|
2633
1814
|
0,
|
|
2634
1815
|
1,
|
|
2635
1816
|
2,
|
|
2636
1817
|
3
|
|
2637
|
-
].includes(
|
|
2638
|
-
this.recovery =
|
|
1818
|
+
].includes(E)) throw new Error("invalid recovery id");
|
|
1819
|
+
this.recovery = E;
|
|
2639
1820
|
}
|
|
2640
1821
|
Object.freeze(this);
|
|
2641
1822
|
}
|
|
2642
|
-
static fromBytes(
|
|
2643
|
-
|
|
2644
|
-
let
|
|
2645
|
-
if (
|
|
2646
|
-
const { r:
|
|
2647
|
-
return new
|
|
1823
|
+
static fromBytes(l, b = _.format) {
|
|
1824
|
+
Z(l, b);
|
|
1825
|
+
let E;
|
|
1826
|
+
if (b === "der") {
|
|
1827
|
+
const { r: N, s: L } = et.toSig(W(l));
|
|
1828
|
+
return new T(N, L);
|
|
2648
1829
|
}
|
|
2649
|
-
|
|
2650
|
-
const
|
|
2651
|
-
return new
|
|
1830
|
+
b === "recovered" && (E = l[0], b = "compact", l = l.subarray(1));
|
|
1831
|
+
const p = A.signature / 2, v = l.subarray(0, p), S = l.subarray(p, p * 2);
|
|
1832
|
+
return new T(s.fromBytes(v), s.fromBytes(S), E);
|
|
2652
1833
|
}
|
|
2653
|
-
static fromHex(
|
|
2654
|
-
return this.fromBytes(
|
|
1834
|
+
static fromHex(l, b) {
|
|
1835
|
+
return this.fromBytes(se(l), b);
|
|
2655
1836
|
}
|
|
2656
1837
|
assertRecovery() {
|
|
2657
|
-
const { recovery:
|
|
2658
|
-
if (
|
|
2659
|
-
return
|
|
1838
|
+
const { recovery: l } = this;
|
|
1839
|
+
if (l == null) throw new Error("invalid recovery id: must be present");
|
|
1840
|
+
return l;
|
|
2660
1841
|
}
|
|
2661
|
-
addRecoveryBit(
|
|
2662
|
-
return new
|
|
1842
|
+
addRecoveryBit(l) {
|
|
1843
|
+
return new T(this.r, this.s, l);
|
|
2663
1844
|
}
|
|
2664
|
-
recoverPublicKey(
|
|
2665
|
-
const { r:
|
|
2666
|
-
if (!
|
|
2667
|
-
const
|
|
2668
|
-
if (
|
|
2669
|
-
return
|
|
1845
|
+
recoverPublicKey(l) {
|
|
1846
|
+
const { r: b, s: E } = this, p = this.assertRecovery(), v = p === 2 || p === 3 ? b + a : b;
|
|
1847
|
+
if (!c.isValid(v)) throw new Error("invalid recovery id: sig.r+curve.n != R.x");
|
|
1848
|
+
const S = c.toBytes(v), N = t.fromBytes(lt(Hn((p & 1) === 0), S)), L = s.inv(v), I = $(W(l, void 0, "msgHash")), k = s.create(-I * L), j = s.create(E * L), V = t.BASE.multiplyUnsafe(k).add(N.multiplyUnsafe(j));
|
|
1849
|
+
if (V.is0()) throw new Error("invalid recovery: point at infinify");
|
|
1850
|
+
return V.assertValidity(), V;
|
|
2670
1851
|
}
|
|
2671
1852
|
hasHighS() {
|
|
2672
|
-
return
|
|
2673
|
-
}
|
|
2674
|
-
toBytes(
|
|
2675
|
-
if (
|
|
2676
|
-
const { r:
|
|
2677
|
-
return
|
|
2678
|
-
}
|
|
2679
|
-
toHex(
|
|
2680
|
-
return
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
Object.freeze(
|
|
2684
|
-
const
|
|
2685
|
-
if (
|
|
2686
|
-
const
|
|
2687
|
-
return
|
|
2688
|
-
} :
|
|
2689
|
-
return
|
|
2690
|
-
} :
|
|
2691
|
-
function
|
|
2692
|
-
return
|
|
2693
|
-
}
|
|
2694
|
-
function
|
|
2695
|
-
return
|
|
2696
|
-
}
|
|
2697
|
-
function
|
|
2698
|
-
const { lowS:
|
|
2699
|
-
|
|
2700
|
-
const
|
|
2701
|
-
if (!
|
|
2702
|
-
const
|
|
2703
|
-
if (
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
}
|
|
2707
|
-
const
|
|
2708
|
-
function
|
|
2709
|
-
const
|
|
2710
|
-
if (!
|
|
2711
|
-
const
|
|
2712
|
-
if (
|
|
2713
|
-
const
|
|
2714
|
-
if (
|
|
2715
|
-
let
|
|
2716
|
-
return
|
|
1853
|
+
return O(this.s);
|
|
1854
|
+
}
|
|
1855
|
+
toBytes(l = _.format) {
|
|
1856
|
+
if (ae(l), l === "der") return se(et.hexFromSig(this));
|
|
1857
|
+
const { r: b, s: E } = this, p = s.toBytes(b), v = s.toBytes(E);
|
|
1858
|
+
return l === "recovered" ? (q(), lt(Uint8Array.of(this.assertRecovery()), p, v)) : lt(p, v);
|
|
1859
|
+
}
|
|
1860
|
+
toHex(l) {
|
|
1861
|
+
return cn(this.toBytes(l));
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
Object.freeze(T.prototype), Object.freeze(T);
|
|
1865
|
+
const Q = r.bits2int === void 0 ? function(l) {
|
|
1866
|
+
if (l.length > 8192) throw new Error("input is too large");
|
|
1867
|
+
const b = Ct(l), E = l.length * 8 - u;
|
|
1868
|
+
return E > 0 ? b >> BigInt(E) : b;
|
|
1869
|
+
} : r.bits2int, $ = r.bits2int_modN === void 0 ? function(l) {
|
|
1870
|
+
return s.create(Q(l));
|
|
1871
|
+
} : r.bits2int_modN, R = Ee(u);
|
|
1872
|
+
function C(d) {
|
|
1873
|
+
return dn("num < 2^" + u, d, ot, R), s.toBytes(d);
|
|
1874
|
+
}
|
|
1875
|
+
function X(d, l) {
|
|
1876
|
+
return W(d, void 0, "message"), l ? W(n(d), void 0, "prehashed message") : d;
|
|
1877
|
+
}
|
|
1878
|
+
function F(d, l, b) {
|
|
1879
|
+
const { lowS: E, prehash: p, extraEntropy: v } = Xt(b, _);
|
|
1880
|
+
d = X(d, p);
|
|
1881
|
+
const S = $(d), N = s.fromBytes(l);
|
|
1882
|
+
if (!s.isValidNot0(N)) throw new Error("invalid private key");
|
|
1883
|
+
const L = [C(N), C(S)];
|
|
1884
|
+
if (v != null && v !== !1) {
|
|
1885
|
+
const V = v === !0 ? o(A.secretKey) : v;
|
|
1886
|
+
L.push(W(V, void 0, "extraEntropy"));
|
|
1887
|
+
}
|
|
1888
|
+
const I = lt(...L), k = S;
|
|
1889
|
+
function j(V) {
|
|
1890
|
+
const U = Q(V);
|
|
1891
|
+
if (!s.isValidNot0(U)) return;
|
|
1892
|
+
const J = s.inv(U), vt = t.BASE.multiply(U).toAffine(), Ft = s.create(vt.x);
|
|
1893
|
+
if (Ft === ot) return;
|
|
1894
|
+
const Lt = s.create(J * s.create(k + Ft * N));
|
|
1895
|
+
if (Lt === ot) return;
|
|
1896
|
+
let xe = (vt.x === Ft ? 0 : 2) | Number(vt.y & ht), Be = Lt;
|
|
1897
|
+
return E && O(Lt) && (Be = s.neg(Lt), xe ^= 1), new T(Ft, Be, H ? void 0 : xe);
|
|
2717
1898
|
}
|
|
2718
1899
|
return {
|
|
2719
|
-
seed:
|
|
2720
|
-
k2sig:
|
|
1900
|
+
seed: I,
|
|
1901
|
+
k2sig: j
|
|
2721
1902
|
};
|
|
2722
1903
|
}
|
|
2723
|
-
function
|
|
2724
|
-
const { seed:
|
|
2725
|
-
return
|
|
1904
|
+
function h(d, l, b = {}) {
|
|
1905
|
+
const { seed: E, k2sig: p } = F(d, l, b);
|
|
1906
|
+
return Wn(n.outputLen, s.BYTES, i)(E, p).toBytes(b.format);
|
|
2726
1907
|
}
|
|
2727
|
-
function
|
|
2728
|
-
const { lowS:
|
|
2729
|
-
if (
|
|
2730
|
-
const
|
|
2731
|
-
throw new Error("verify expects Uint8Array signature" +
|
|
1908
|
+
function y(d, l, b, E = {}) {
|
|
1909
|
+
const { lowS: p, prehash: v, format: S } = Xt(E, _);
|
|
1910
|
+
if (b = W(b, void 0, "publicKey"), l = X(l, v), !fn(d)) {
|
|
1911
|
+
const N = d instanceof T ? ", use sig.toBytes()" : "";
|
|
1912
|
+
throw new Error("verify expects Uint8Array signature" + N);
|
|
2732
1913
|
}
|
|
2733
|
-
|
|
1914
|
+
Z(d, S);
|
|
2734
1915
|
try {
|
|
2735
|
-
const
|
|
2736
|
-
if (
|
|
2737
|
-
const { r:
|
|
2738
|
-
return
|
|
1916
|
+
const N = T.fromBytes(d, S), L = t.fromBytes(b);
|
|
1917
|
+
if (p && N.hasHighS()) return !1;
|
|
1918
|
+
const { r: I, s: k } = N, j = $(l), V = s.inv(k), U = s.create(j * V), J = s.create(I * V), vt = t.BASE.multiplyUnsafe(U).add(L.multiplyUnsafe(J));
|
|
1919
|
+
return vt.is0() ? !1 : s.create(vt.x) === I;
|
|
2739
1920
|
} catch {
|
|
2740
1921
|
return !1;
|
|
2741
1922
|
}
|
|
2742
1923
|
}
|
|
2743
|
-
function
|
|
2744
|
-
const { prehash:
|
|
2745
|
-
return
|
|
1924
|
+
function B(d, l, b = {}) {
|
|
1925
|
+
const { prehash: E } = Xt(b, _);
|
|
1926
|
+
return l = X(l, E), T.fromBytes(d, "recovered").recoverPublicKey(l).toBytes();
|
|
2746
1927
|
}
|
|
2747
1928
|
return Object.freeze({
|
|
2748
|
-
keygen:
|
|
2749
|
-
getPublicKey:
|
|
2750
|
-
getSharedSecret:
|
|
2751
|
-
utils:
|
|
2752
|
-
lengths:
|
|
1929
|
+
keygen: f,
|
|
1930
|
+
getPublicKey: g,
|
|
1931
|
+
getSharedSecret: m,
|
|
1932
|
+
utils: w,
|
|
1933
|
+
lengths: A,
|
|
2753
1934
|
Point: t,
|
|
2754
|
-
sign:
|
|
2755
|
-
verify:
|
|
2756
|
-
recoverPublicKey:
|
|
2757
|
-
Signature:
|
|
2758
|
-
hash:
|
|
1935
|
+
sign: h,
|
|
1936
|
+
verify: y,
|
|
1937
|
+
recoverPublicKey: B,
|
|
1938
|
+
Signature: T,
|
|
1939
|
+
hash: n
|
|
2759
1940
|
});
|
|
2760
1941
|
}
|
|
2761
|
-
var
|
|
1942
|
+
var ve = {
|
|
2762
1943
|
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
2763
1944
|
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
2764
1945
|
h: BigInt(1),
|
|
@@ -2766,209 +1947,55 @@ var rn = {
|
|
|
2766
1947
|
b: BigInt(7),
|
|
2767
1948
|
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
2768
1949
|
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
2769
|
-
},
|
|
1950
|
+
}, pr = {
|
|
2770
1951
|
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
2771
1952
|
basises: [[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")], [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]
|
|
2772
|
-
},
|
|
2773
|
-
function
|
|
2774
|
-
const
|
|
2775
|
-
if (!
|
|
2776
|
-
return
|
|
2777
|
-
}
|
|
2778
|
-
var
|
|
2779
|
-
Fp:
|
|
2780
|
-
endo:
|
|
2781
|
-
}),
|
|
2782
|
-
function ur(t, ...n) {
|
|
2783
|
-
let e = vn[t];
|
|
2784
|
-
if (e === void 0) {
|
|
2785
|
-
const r = jt(be(t));
|
|
2786
|
-
e = Q(r, r), vn[t] = e;
|
|
2787
|
-
}
|
|
2788
|
-
return jt(Q(e, ...n));
|
|
2789
|
-
}
|
|
2790
|
-
var Ye = (t) => t.toBytes(!0).slice(1), Vt = (t) => t % Ge === lr;
|
|
2791
|
-
function Eo(t) {
|
|
2792
|
-
const n = It;
|
|
2793
|
-
if (!n.isValidNot0(t)) throw new Error("invalid x: Fail if x ≥ p");
|
|
2794
|
-
const e = n.create(t * t), r = n.create(e * t + BigInt(7));
|
|
2795
|
-
let o = n.sqrt(r);
|
|
2796
|
-
Vt(o) || (o = n.neg(o));
|
|
2797
|
-
const i = J.fromAffine({
|
|
2798
|
-
x: t,
|
|
2799
|
-
y: o
|
|
2800
|
-
});
|
|
2801
|
-
return i.assertValidity(), i;
|
|
2802
|
-
}
|
|
2803
|
-
var vo = St;
|
|
2804
|
-
function xo(...t) {
|
|
2805
|
-
return J.Fn.create(vo(ur("BIP0340/challenge", ...t)));
|
|
2806
|
-
}
|
|
2807
|
-
var Bo = co(It, [
|
|
2808
|
-
[
|
|
2809
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
2810
|
-
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
2811
|
-
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
2812
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
2813
|
-
],
|
|
2814
|
-
[
|
|
2815
|
-
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
2816
|
-
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
2817
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
2818
|
-
],
|
|
2819
|
-
[
|
|
2820
|
-
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
2821
|
-
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
2822
|
-
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
2823
|
-
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
2824
|
-
],
|
|
2825
|
-
[
|
|
2826
|
-
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
2827
|
-
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
2828
|
-
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
2829
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
2830
|
-
]
|
|
2831
|
-
].map((t) => t.map((n) => BigInt(n)))), xn, So = () => xn || (xn = go(It, {
|
|
2832
|
-
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
2833
|
-
B: BigInt("1771"),
|
|
2834
|
-
Z: It.create(BigInt("-11"))
|
|
2835
|
-
})), dr = ao(J, (t) => {
|
|
2836
|
-
const { x: n, y: e } = So()(It.create(t[0]));
|
|
2837
|
-
return Bo(n, e);
|
|
2838
|
-
}, {
|
|
2839
|
-
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
2840
|
-
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
2841
|
-
p: It.ORDER,
|
|
2842
|
-
m: 1,
|
|
2843
|
-
k: 128,
|
|
2844
|
-
expand: "xmd",
|
|
2845
|
-
hash: jt
|
|
2846
|
-
}), Po = cr({
|
|
2847
|
-
name: "FROST-secp256k1-SHA256-v1",
|
|
2848
|
-
Point: J,
|
|
2849
|
-
hashToScalar: dr.hashToScalar,
|
|
2850
|
-
hash: jt
|
|
2851
|
-
});
|
|
2852
|
-
function hr(t, n) {
|
|
2853
|
-
if (n === void 0) return lr;
|
|
2854
|
-
const e = St(ur("TapTweak", Ye(t), n));
|
|
2855
|
-
if (!J.Fn.isValid(e)) throw new Error("invalid TapTweak hash");
|
|
2856
|
-
return e;
|
|
2857
|
-
}
|
|
2858
|
-
function on(t) {
|
|
2859
|
-
return Vt(J.fromBytes(t.commitments[0]).y) ? t : {
|
|
2860
|
-
signers: {
|
|
2861
|
-
min: t.signers.min,
|
|
2862
|
-
max: t.signers.max
|
|
2863
|
-
},
|
|
2864
|
-
commitments: t.commitments.map((n) => J.fromBytes(n).negate().toBytes()),
|
|
2865
|
-
verifyingShares: Object.fromEntries(Object.entries(t.verifyingShares).map(([n, e]) => [n, J.fromBytes(e).negate().toBytes()]))
|
|
2866
|
-
};
|
|
2867
|
-
}
|
|
2868
|
-
function mr(t, n) {
|
|
2869
|
-
if (Vt(J.fromBytes(n.commitments[0]).y)) return t;
|
|
2870
|
-
const e = J.Fn;
|
|
2871
|
-
return {
|
|
2872
|
-
...t,
|
|
2873
|
-
signingShare: e.toBytes(e.neg(e.fromBytes(t.signingShare)))
|
|
2874
|
-
};
|
|
2875
|
-
}
|
|
2876
|
-
function Ao(t, n) {
|
|
2877
|
-
if (Vt(t.y)) return n;
|
|
2878
|
-
const e = J.Fn;
|
|
2879
|
-
return {
|
|
2880
|
-
binding: e.toBytes(e.neg(e.fromBytes(n.binding))),
|
|
2881
|
-
hiding: e.toBytes(e.neg(e.fromBytes(n.hiding)))
|
|
2882
|
-
};
|
|
2883
|
-
}
|
|
2884
|
-
function Ro(t, n, e) {
|
|
2885
|
-
const r = J.Fn, o = mr(t, n), i = on(n), a = hr(J.fromBytes(i.commitments[0]), e), f = r.toBytes(r.add(r.fromBytes(o.signingShare), a));
|
|
2886
|
-
return {
|
|
2887
|
-
identifier: o.identifier,
|
|
2888
|
-
signingShare: f
|
|
2889
|
-
};
|
|
2890
|
-
}
|
|
2891
|
-
function _o(t, n) {
|
|
2892
|
-
const e = on(t), r = hr(J.fromBytes(e.commitments[0]), n), o = J.BASE.multiply(r), i = e.commitments.map((f, l) => (l === 0 ? J.fromBytes(f).add(o) : J.fromBytes(f)).toBytes()), a = {};
|
|
2893
|
-
for (const f in e.verifyingShares) a[f] = J.fromBytes(e.verifyingShares[f]).add(o).toBytes();
|
|
2894
|
-
return {
|
|
2895
|
-
signers: {
|
|
2896
|
-
min: e.signers.min,
|
|
2897
|
-
max: e.signers.max
|
|
2898
|
-
},
|
|
2899
|
-
commitments: i,
|
|
2900
|
-
verifyingShares: a
|
|
2901
|
-
};
|
|
2902
|
-
}
|
|
2903
|
-
var zo = cr({
|
|
2904
|
-
name: "FROST-secp256k1-SHA256-TR-v1",
|
|
2905
|
-
Point: J,
|
|
2906
|
-
hashToScalar: dr.hashToScalar,
|
|
2907
|
-
hash: jt,
|
|
2908
|
-
parsePublicKey(t) {
|
|
2909
|
-
if (t.length === 32) return Eo(St(t));
|
|
2910
|
-
if (t.length === 33) return J.fromBytes(t);
|
|
2911
|
-
throw new Error(`expected x-only or compressed public key, got length=${t.length}`);
|
|
2912
|
-
},
|
|
2913
|
-
adjustScalar(t) {
|
|
2914
|
-
return Vt(J.BASE.multiply(t).y) ? t : J.Fn.neg(t);
|
|
2915
|
-
},
|
|
2916
|
-
adjustPoint: (t) => Vt(t.y) ? t : t.negate(),
|
|
2917
|
-
challenge(t, n, e) {
|
|
2918
|
-
return xo(Ye(t), Ye(n), e);
|
|
2919
|
-
},
|
|
2920
|
-
adjustNonces: Ao,
|
|
2921
|
-
adjustGroupCommitmentShare: (t, n) => Vt(t.y) ? n : n.negate(),
|
|
2922
|
-
adjustPublic: on,
|
|
2923
|
-
adjustSecret: mr,
|
|
2924
|
-
adjustTx: {
|
|
2925
|
-
encode: (t) => t.subarray(1),
|
|
2926
|
-
decode: (t) => Q(Uint8Array.of(2), t)
|
|
2927
|
-
},
|
|
2928
|
-
adjustDKG: (t) => {
|
|
2929
|
-
const n = new Uint8Array(0);
|
|
2930
|
-
return {
|
|
2931
|
-
public: _o(t.public, n),
|
|
2932
|
-
secret: Ro(t.secret, t.public, n)
|
|
2933
|
-
};
|
|
2934
|
-
}
|
|
2935
|
-
});
|
|
1953
|
+
}, qe = /* @__PURE__ */ BigInt(2);
|
|
1954
|
+
function yr(t) {
|
|
1955
|
+
const e = ve.p, r = BigInt(3), n = BigInt(6), o = BigInt(11), i = BigInt(22), c = BigInt(23), s = BigInt(44), a = BigInt(88), u = t * t * t % e, f = u * u * t % e, g = P(P(P(f, r, e) * f % e, r, e) * f % e, qe, e) * u % e, m = P(g, o, e) * g % e, w = P(m, i, e) * m % e, A = P(w, s, e) * w % e, _ = P(P(P(P(P(P(A, a, e) * A % e, s, e) * w % e, r, e) * f % e, c, e) * m % e, n, e) * u % e, qe, e);
|
|
1956
|
+
if (!ue.eql(ue.sqr(_), t)) throw new Error("Cannot find square root");
|
|
1957
|
+
return _;
|
|
1958
|
+
}
|
|
1959
|
+
var ue = jt(ve.p, { sqrt: yr }), Er = /* @__PURE__ */ gr(ve, {
|
|
1960
|
+
Fp: ue,
|
|
1961
|
+
endo: pr
|
|
1962
|
+
}), Ur = /* @__PURE__ */ wr(Er, ge);
|
|
2936
1963
|
export {
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
1964
|
+
Tn as A,
|
|
1965
|
+
_r as C,
|
|
1966
|
+
Je as D,
|
|
1967
|
+
Br as E,
|
|
1968
|
+
xt as F,
|
|
1969
|
+
It as I,
|
|
1970
|
+
vr as L,
|
|
1971
|
+
xr as M,
|
|
1972
|
+
Ln as N,
|
|
1973
|
+
Nn as O,
|
|
1974
|
+
Bt as P,
|
|
1975
|
+
Vn as S,
|
|
1976
|
+
ge as T,
|
|
1977
|
+
Ir as _,
|
|
1978
|
+
an as a,
|
|
1979
|
+
Yn as b,
|
|
1980
|
+
Mn as c,
|
|
1981
|
+
nn as d,
|
|
1982
|
+
Rr as f,
|
|
1983
|
+
Or as g,
|
|
1984
|
+
Hr as h,
|
|
1985
|
+
lt as i,
|
|
1986
|
+
Un as j,
|
|
1987
|
+
Wt as k,
|
|
1988
|
+
Lr as l,
|
|
1989
|
+
Sr as m,
|
|
1990
|
+
tt as n,
|
|
1991
|
+
Gn as o,
|
|
1992
|
+
Ar as p,
|
|
1993
|
+
Ct as r,
|
|
1994
|
+
Tr as s,
|
|
1995
|
+
Ur as t,
|
|
1996
|
+
Nr as u,
|
|
1997
|
+
zn as v,
|
|
1998
|
+
Zn as w,
|
|
1999
|
+
Fr as x,
|
|
2000
|
+
Cn as y
|
|
2974
2001
|
};
|