@lombard.finance/sdk-starknet 0.3.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.cjs +229 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +30378 -0
- package/dist/index2.js.map +1 -0
- package/dist/index3.cjs +2 -0
- package/dist/index3.cjs.map +1 -0
- package/dist/index3.js +2316 -0
- package/dist/index3.js.map +1 -0
- package/package.json +66 -0
- package/src/contract-functions/approve.stories.tsx +74 -0
- package/src/contract-functions/approve.ts +56 -0
- package/src/contract-functions/balance-of.stories.tsx +54 -0
- package/src/contract-functions/balance-of.ts +41 -0
- package/src/contract-functions/mint.ts +109 -0
- package/src/contract-functions/redeem.ts +107 -0
- package/src/index.ts +25 -0
- package/src/module/createStarknetModule.ts +38 -0
- package/src/services/StarknetServiceImpl.ts +83 -0
- package/src/services/index.ts +7 -0
- package/src/stories/components/Button/Button.css +10 -0
- package/src/stories/components/Button/Button.tsx +52 -0
- package/src/stories/components/Button/index.ts +1 -0
- package/src/stories/components/CodeBlock/CodeBlock.tsx +38 -0
- package/src/stories/components/CodeBlock/CodeBlockStyles.css +3 -0
- package/src/stories/components/CodeBlock/index.ts +1 -0
- package/src/stories/components/ConnectButton/connect-button.tsx +112 -0
- package/src/stories/components/ConnectButton/index.ts +1 -0
- package/src/stories/components/Spinner/Spinner.tsx +24 -0
- package/src/stories/components/Spinner/index.ts +1 -0
- package/src/stories/components/decorators/function-type.tsx +66 -0
- package/src/stories/components/decorators/index.ts +1 -0
- package/src/stories/components/decorators/starknet-context.tsx +21 -0
- package/src/stories/components/error-block.tsx +21 -0
- package/src/stories/hooks/use-connection.ts +70 -0
- package/src/stories/hooks/use-query.ts +56 -0
- package/src/tokens/abi/ERC20_ABI.ts +1122 -0
- package/src/tokens/abi/LBTC_ABI.ts +1615 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.ts +709 -0
- package/src/tokens/abi/LBTC_BRIDGE_ABI.ts +1568 -0
- package/src/tokens/lib/tokens.ts +267 -0
- package/src/utils/account.ts +81 -0
- package/src/utils/chains.ts +33 -0
- package/src/utils/common.ts +11 -0
- package/src/utils/env.ts +6 -0
- package/src/utils/err.ts +121 -0
- package/src/utils/rpc-providers.ts +25 -0
- package/src/utils/signature.ts +60 -0
- package/src/utils/span.ts +56 -0
- package/src/utils/typed-data.ts +36 -0
- package/src/utils/wallet-account.ts +9 -0
- package/src/wallet-functions/sign-message.stories.tsx +72 -0
- package/src/wallet-functions/sign-message.ts +127 -0
- package/src/wallet-functions/sign-terms-of-service.ts +45 -0
package/dist/index3.js
ADDED
|
@@ -0,0 +1,2316 @@
|
|
|
1
|
+
import { r as xe, a as Fe, g as $e } from "./index2.js";
|
|
2
|
+
function et(s, x) {
|
|
3
|
+
for (var M = 0; M < x.length; M++) {
|
|
4
|
+
const m = x[M];
|
|
5
|
+
if (typeof m != "string" && !Array.isArray(m)) {
|
|
6
|
+
for (const K in m)
|
|
7
|
+
if (K !== "default" && !(K in s)) {
|
|
8
|
+
const T = Object.getOwnPropertyDescriptor(m, K);
|
|
9
|
+
T && Object.defineProperty(s, K, T.get ? T : {
|
|
10
|
+
enumerable: !0,
|
|
11
|
+
get: () => m[K]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return Object.freeze(Object.defineProperty(s, Symbol.toStringTag, { value: "Module" }));
|
|
17
|
+
}
|
|
18
|
+
var be = {}, He = {}, Ie = {}, Ue = {}, Pe = {}, Me;
|
|
19
|
+
function tt() {
|
|
20
|
+
return Me || (Me = 1, (function(s) {
|
|
21
|
+
Object.defineProperty(s, "__esModule", { value: !0 }), s.hmac = s.HMAC = void 0;
|
|
22
|
+
const x = /* @__PURE__ */ xe();
|
|
23
|
+
class M extends x.Hash {
|
|
24
|
+
constructor(T, ie) {
|
|
25
|
+
super(), this.finished = !1, this.destroyed = !1, (0, x.ahash)(T);
|
|
26
|
+
const Q = (0, x.toBytes)(ie);
|
|
27
|
+
if (this.iHash = T.create(), typeof this.iHash.update != "function")
|
|
28
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
29
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
30
|
+
const ne = this.blockLen, oe = new Uint8Array(ne);
|
|
31
|
+
oe.set(Q.length > ne ? T.create().update(Q).digest() : Q);
|
|
32
|
+
for (let fe = 0; fe < oe.length; fe++)
|
|
33
|
+
oe[fe] ^= 54;
|
|
34
|
+
this.iHash.update(oe), this.oHash = T.create();
|
|
35
|
+
for (let fe = 0; fe < oe.length; fe++)
|
|
36
|
+
oe[fe] ^= 106;
|
|
37
|
+
this.oHash.update(oe), (0, x.clean)(oe);
|
|
38
|
+
}
|
|
39
|
+
update(T) {
|
|
40
|
+
return (0, x.aexists)(this), this.iHash.update(T), this;
|
|
41
|
+
}
|
|
42
|
+
digestInto(T) {
|
|
43
|
+
(0, x.aexists)(this), (0, x.abytes)(T, this.outputLen), this.finished = !0, this.iHash.digestInto(T), this.oHash.update(T), this.oHash.digestInto(T), this.destroy();
|
|
44
|
+
}
|
|
45
|
+
digest() {
|
|
46
|
+
const T = new Uint8Array(this.oHash.outputLen);
|
|
47
|
+
return this.digestInto(T), T;
|
|
48
|
+
}
|
|
49
|
+
_cloneInto(T) {
|
|
50
|
+
T || (T = Object.create(Object.getPrototypeOf(this), {}));
|
|
51
|
+
const { oHash: ie, iHash: Q, finished: ne, destroyed: oe, blockLen: fe, outputLen: G } = this;
|
|
52
|
+
return T = T, T.finished = ne, T.destroyed = oe, T.blockLen = fe, T.outputLen = G, T.oHash = ie._cloneInto(T.oHash), T.iHash = Q._cloneInto(T.iHash), T;
|
|
53
|
+
}
|
|
54
|
+
clone() {
|
|
55
|
+
return this._cloneInto();
|
|
56
|
+
}
|
|
57
|
+
destroy() {
|
|
58
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
s.HMAC = M;
|
|
62
|
+
const m = (K, T, ie) => new M(K, T).update(ie).digest();
|
|
63
|
+
s.hmac = m, s.hmac.create = (K, T) => new M(K, T);
|
|
64
|
+
})(Pe)), Pe;
|
|
65
|
+
}
|
|
66
|
+
var Le = {}, Ze;
|
|
67
|
+
function Ae() {
|
|
68
|
+
return Ze || (Ze = 1, (function(s) {
|
|
69
|
+
Object.defineProperty(s, "__esModule", { value: !0 }), s.notImplemented = s.bitMask = s.utf8ToBytes = s.randomBytes = s.isBytes = s.hexToBytes = s.concatBytes = s.bytesToUtf8 = s.bytesToHex = s.anumber = s.abytes = void 0, s.abool = T, s._abool2 = ie, s._abytes2 = Q, s.numberToHexUnpadded = ne, s.hexToNumber = oe, s.bytesToNumberBE = fe, s.bytesToNumberLE = G, s.numberToBytesBE = re, s.numberToBytesLE = H, s.numberToVarBytesBE = j, s.ensureBytes = X, s.equalBytes = D, s.copyBytes = se, s.asciiToBytes = J, s.inRange = ce, s.aInRange = le, s.bitLen = R, s.bitGet = y, s.bitSet = A, s.createHmacDrbg = q, s.validateObject = F, s.isHash = S, s._validateObject = v, s.memoized = a;
|
|
70
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
71
|
+
const x = /* @__PURE__ */ xe();
|
|
72
|
+
var M = /* @__PURE__ */ xe();
|
|
73
|
+
Object.defineProperty(s, "abytes", { enumerable: !0, get: function() {
|
|
74
|
+
return M.abytes;
|
|
75
|
+
} }), Object.defineProperty(s, "anumber", { enumerable: !0, get: function() {
|
|
76
|
+
return M.anumber;
|
|
77
|
+
} }), Object.defineProperty(s, "bytesToHex", { enumerable: !0, get: function() {
|
|
78
|
+
return M.bytesToHex;
|
|
79
|
+
} }), Object.defineProperty(s, "bytesToUtf8", { enumerable: !0, get: function() {
|
|
80
|
+
return M.bytesToUtf8;
|
|
81
|
+
} }), Object.defineProperty(s, "concatBytes", { enumerable: !0, get: function() {
|
|
82
|
+
return M.concatBytes;
|
|
83
|
+
} }), Object.defineProperty(s, "hexToBytes", { enumerable: !0, get: function() {
|
|
84
|
+
return M.hexToBytes;
|
|
85
|
+
} }), Object.defineProperty(s, "isBytes", { enumerable: !0, get: function() {
|
|
86
|
+
return M.isBytes;
|
|
87
|
+
} }), Object.defineProperty(s, "randomBytes", { enumerable: !0, get: function() {
|
|
88
|
+
return M.randomBytes;
|
|
89
|
+
} }), Object.defineProperty(s, "utf8ToBytes", { enumerable: !0, get: function() {
|
|
90
|
+
return M.utf8ToBytes;
|
|
91
|
+
} });
|
|
92
|
+
const m = /* @__PURE__ */ BigInt(0), K = /* @__PURE__ */ BigInt(1);
|
|
93
|
+
function T(r, e) {
|
|
94
|
+
if (typeof e != "boolean")
|
|
95
|
+
throw new Error(r + " boolean expected, got " + e);
|
|
96
|
+
}
|
|
97
|
+
function ie(r, e = "") {
|
|
98
|
+
if (typeof r != "boolean") {
|
|
99
|
+
const f = e && `"${e}"`;
|
|
100
|
+
throw new Error(f + "expected boolean, got type=" + typeof r);
|
|
101
|
+
}
|
|
102
|
+
return r;
|
|
103
|
+
}
|
|
104
|
+
function Q(r, e, f = "") {
|
|
105
|
+
const g = (0, x.isBytes)(r), n = r == null ? void 0 : r.length, i = e !== void 0;
|
|
106
|
+
if (!g || i && n !== e) {
|
|
107
|
+
const c = f && `"${f}" `, h = i ? ` of length ${e}` : "", p = g ? `length=${n}` : `type=${typeof r}`;
|
|
108
|
+
throw new Error(c + "expected Uint8Array" + h + ", got " + p);
|
|
109
|
+
}
|
|
110
|
+
return r;
|
|
111
|
+
}
|
|
112
|
+
function ne(r) {
|
|
113
|
+
const e = r.toString(16);
|
|
114
|
+
return e.length & 1 ? "0" + e : e;
|
|
115
|
+
}
|
|
116
|
+
function oe(r) {
|
|
117
|
+
if (typeof r != "string")
|
|
118
|
+
throw new Error("hex string expected, got " + typeof r);
|
|
119
|
+
return r === "" ? m : BigInt("0x" + r);
|
|
120
|
+
}
|
|
121
|
+
function fe(r) {
|
|
122
|
+
return oe((0, x.bytesToHex)(r));
|
|
123
|
+
}
|
|
124
|
+
function G(r) {
|
|
125
|
+
return (0, x.abytes)(r), oe((0, x.bytesToHex)(Uint8Array.from(r).reverse()));
|
|
126
|
+
}
|
|
127
|
+
function re(r, e) {
|
|
128
|
+
return (0, x.hexToBytes)(r.toString(16).padStart(e * 2, "0"));
|
|
129
|
+
}
|
|
130
|
+
function H(r, e) {
|
|
131
|
+
return re(r, e).reverse();
|
|
132
|
+
}
|
|
133
|
+
function j(r) {
|
|
134
|
+
return (0, x.hexToBytes)(ne(r));
|
|
135
|
+
}
|
|
136
|
+
function X(r, e, f) {
|
|
137
|
+
let g;
|
|
138
|
+
if (typeof e == "string")
|
|
139
|
+
try {
|
|
140
|
+
g = (0, x.hexToBytes)(e);
|
|
141
|
+
} catch (i) {
|
|
142
|
+
throw new Error(r + " must be hex string or Uint8Array, cause: " + i);
|
|
143
|
+
}
|
|
144
|
+
else if ((0, x.isBytes)(e))
|
|
145
|
+
g = Uint8Array.from(e);
|
|
146
|
+
else
|
|
147
|
+
throw new Error(r + " must be hex string or Uint8Array");
|
|
148
|
+
const n = g.length;
|
|
149
|
+
if (typeof f == "number" && n !== f)
|
|
150
|
+
throw new Error(r + " of length " + f + " expected, got " + n);
|
|
151
|
+
return g;
|
|
152
|
+
}
|
|
153
|
+
function D(r, e) {
|
|
154
|
+
if (r.length !== e.length)
|
|
155
|
+
return !1;
|
|
156
|
+
let f = 0;
|
|
157
|
+
for (let g = 0; g < r.length; g++)
|
|
158
|
+
f |= r[g] ^ e[g];
|
|
159
|
+
return f === 0;
|
|
160
|
+
}
|
|
161
|
+
function se(r) {
|
|
162
|
+
return Uint8Array.from(r);
|
|
163
|
+
}
|
|
164
|
+
function J(r) {
|
|
165
|
+
return Uint8Array.from(r, (e, f) => {
|
|
166
|
+
const g = e.charCodeAt(0);
|
|
167
|
+
if (e.length !== 1 || g > 127)
|
|
168
|
+
throw new Error(`string contains non-ASCII character "${r[f]}" with code ${g} at position ${f}`);
|
|
169
|
+
return g;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const $ = (r) => typeof r == "bigint" && m <= r;
|
|
173
|
+
function ce(r, e, f) {
|
|
174
|
+
return $(r) && $(e) && $(f) && e <= r && r < f;
|
|
175
|
+
}
|
|
176
|
+
function le(r, e, f, g) {
|
|
177
|
+
if (!ce(e, f, g))
|
|
178
|
+
throw new Error("expected valid " + r + ": " + f + " <= n < " + g + ", got " + e);
|
|
179
|
+
}
|
|
180
|
+
function R(r) {
|
|
181
|
+
let e;
|
|
182
|
+
for (e = 0; r > m; r >>= K, e += 1)
|
|
183
|
+
;
|
|
184
|
+
return e;
|
|
185
|
+
}
|
|
186
|
+
function y(r, e) {
|
|
187
|
+
return r >> BigInt(e) & K;
|
|
188
|
+
}
|
|
189
|
+
function A(r, e, f) {
|
|
190
|
+
return r | (f ? K : m) << BigInt(e);
|
|
191
|
+
}
|
|
192
|
+
const O = (r) => (K << BigInt(r)) - K;
|
|
193
|
+
s.bitMask = O;
|
|
194
|
+
function q(r, e, f) {
|
|
195
|
+
if (typeof r != "number" || r < 2)
|
|
196
|
+
throw new Error("hashLen must be a number");
|
|
197
|
+
if (typeof e != "number" || e < 2)
|
|
198
|
+
throw new Error("qByteLen must be a number");
|
|
199
|
+
if (typeof f != "function")
|
|
200
|
+
throw new Error("hmacFn must be a function");
|
|
201
|
+
const g = (U) => new Uint8Array(U), n = (U) => Uint8Array.of(U);
|
|
202
|
+
let i = g(r), c = g(r), h = 0;
|
|
203
|
+
const p = () => {
|
|
204
|
+
i.fill(1), c.fill(0), h = 0;
|
|
205
|
+
}, C = (...U) => f(c, i, ...U), Z = (U = g(0)) => {
|
|
206
|
+
c = C(n(0), U), i = C(), U.length !== 0 && (c = C(n(1), U), i = C());
|
|
207
|
+
}, _ = () => {
|
|
208
|
+
if (h++ >= 1e3)
|
|
209
|
+
throw new Error("drbg: tried 1000 values");
|
|
210
|
+
let U = 0;
|
|
211
|
+
const Y = [];
|
|
212
|
+
for (; U < e; ) {
|
|
213
|
+
i = C();
|
|
214
|
+
const V = i.slice();
|
|
215
|
+
Y.push(V), U += i.length;
|
|
216
|
+
}
|
|
217
|
+
return (0, x.concatBytes)(...Y);
|
|
218
|
+
};
|
|
219
|
+
return (U, Y) => {
|
|
220
|
+
p(), Z(U);
|
|
221
|
+
let V;
|
|
222
|
+
for (; !(V = Y(_())); )
|
|
223
|
+
Z();
|
|
224
|
+
return p(), V;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const z = {
|
|
228
|
+
bigint: (r) => typeof r == "bigint",
|
|
229
|
+
function: (r) => typeof r == "function",
|
|
230
|
+
boolean: (r) => typeof r == "boolean",
|
|
231
|
+
string: (r) => typeof r == "string",
|
|
232
|
+
stringOrUint8Array: (r) => typeof r == "string" || (0, x.isBytes)(r),
|
|
233
|
+
isSafeInteger: (r) => Number.isSafeInteger(r),
|
|
234
|
+
array: (r) => Array.isArray(r),
|
|
235
|
+
field: (r, e) => e.Fp.isValid(r),
|
|
236
|
+
hash: (r) => typeof r == "function" && Number.isSafeInteger(r.outputLen)
|
|
237
|
+
};
|
|
238
|
+
function F(r, e, f = {}) {
|
|
239
|
+
const g = (n, i, c) => {
|
|
240
|
+
const h = z[i];
|
|
241
|
+
if (typeof h != "function")
|
|
242
|
+
throw new Error("invalid validator function");
|
|
243
|
+
const p = r[n];
|
|
244
|
+
if (!(c && p === void 0) && !h(p, r))
|
|
245
|
+
throw new Error("param " + String(n) + " is invalid. Expected " + i + ", got " + p);
|
|
246
|
+
};
|
|
247
|
+
for (const [n, i] of Object.entries(e))
|
|
248
|
+
g(n, i, !1);
|
|
249
|
+
for (const [n, i] of Object.entries(f))
|
|
250
|
+
g(n, i, !0);
|
|
251
|
+
return r;
|
|
252
|
+
}
|
|
253
|
+
function S(r) {
|
|
254
|
+
return typeof r == "function" && Number.isSafeInteger(r.outputLen);
|
|
255
|
+
}
|
|
256
|
+
function v(r, e, f = {}) {
|
|
257
|
+
if (!r || typeof r != "object")
|
|
258
|
+
throw new Error("expected valid options object");
|
|
259
|
+
function g(n, i, c) {
|
|
260
|
+
const h = r[n];
|
|
261
|
+
if (c && h === void 0)
|
|
262
|
+
return;
|
|
263
|
+
const p = typeof h;
|
|
264
|
+
if (p !== i || h === null)
|
|
265
|
+
throw new Error(`param "${n}" is invalid: expected ${i}, got ${p}`);
|
|
266
|
+
}
|
|
267
|
+
Object.entries(e).forEach(([n, i]) => g(n, i, !1)), Object.entries(f).forEach(([n, i]) => g(n, i, !0));
|
|
268
|
+
}
|
|
269
|
+
const t = () => {
|
|
270
|
+
throw new Error("not implemented");
|
|
271
|
+
};
|
|
272
|
+
s.notImplemented = t;
|
|
273
|
+
function a(r) {
|
|
274
|
+
const e = /* @__PURE__ */ new WeakMap();
|
|
275
|
+
return (f, ...g) => {
|
|
276
|
+
const n = e.get(f);
|
|
277
|
+
if (n !== void 0)
|
|
278
|
+
return n;
|
|
279
|
+
const i = r(f, ...g);
|
|
280
|
+
return e.set(f, i), i;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
})(Le)), Le;
|
|
284
|
+
}
|
|
285
|
+
var Te = {}, he = {}, De;
|
|
286
|
+
function Ne() {
|
|
287
|
+
if (De) return he;
|
|
288
|
+
De = 1, Object.defineProperty(he, "__esModule", { value: !0 }), he.isNegativeLE = void 0, he.mod = G, he.pow = re, he.pow2 = H, he.invert = j, he.tonelliShanks = $, he.FpSqrt = ce, he.validateField = y, he.FpPow = A, he.FpInvertBatch = O, he.FpDiv = q, he.FpLegendre = z, he.FpIsSquare = F, he.nLength = S, he.Field = v, he.FpSqrtOdd = t, he.FpSqrtEven = a, he.hashToPrivateScalar = r, he.getFieldBytesLength = e, he.getMinHashLength = f, he.mapHashToField = g;
|
|
289
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
290
|
+
const s = /* @__PURE__ */ Ae(), x = BigInt(0), M = BigInt(1), m = /* @__PURE__ */ BigInt(2), K = /* @__PURE__ */ BigInt(3), T = /* @__PURE__ */ BigInt(4), ie = /* @__PURE__ */ BigInt(5), Q = /* @__PURE__ */ BigInt(7), ne = /* @__PURE__ */ BigInt(8), oe = /* @__PURE__ */ BigInt(9), fe = /* @__PURE__ */ BigInt(16);
|
|
291
|
+
function G(n, i) {
|
|
292
|
+
const c = n % i;
|
|
293
|
+
return c >= x ? c : i + c;
|
|
294
|
+
}
|
|
295
|
+
function re(n, i, c) {
|
|
296
|
+
return A(v(c), n, i);
|
|
297
|
+
}
|
|
298
|
+
function H(n, i, c) {
|
|
299
|
+
let h = n;
|
|
300
|
+
for (; i-- > x; )
|
|
301
|
+
h *= h, h %= c;
|
|
302
|
+
return h;
|
|
303
|
+
}
|
|
304
|
+
function j(n, i) {
|
|
305
|
+
if (n === x)
|
|
306
|
+
throw new Error("invert: expected non-zero number");
|
|
307
|
+
if (i <= x)
|
|
308
|
+
throw new Error("invert: expected positive modulus, got " + i);
|
|
309
|
+
let c = G(n, i), h = i, p = x, C = M;
|
|
310
|
+
for (; c !== x; ) {
|
|
311
|
+
const _ = h / c, B = h % c, U = p - C * _;
|
|
312
|
+
h = c, c = B, p = C, C = U;
|
|
313
|
+
}
|
|
314
|
+
if (h !== M)
|
|
315
|
+
throw new Error("invert: does not exist");
|
|
316
|
+
return G(p, i);
|
|
317
|
+
}
|
|
318
|
+
function X(n, i, c) {
|
|
319
|
+
if (!n.eql(n.sqr(i), c))
|
|
320
|
+
throw new Error("Cannot find square root");
|
|
321
|
+
}
|
|
322
|
+
function D(n, i) {
|
|
323
|
+
const c = (n.ORDER + M) / T, h = n.pow(i, c);
|
|
324
|
+
return X(n, h, i), h;
|
|
325
|
+
}
|
|
326
|
+
function se(n, i) {
|
|
327
|
+
const c = (n.ORDER - ie) / ne, h = n.mul(i, m), p = n.pow(h, c), C = n.mul(i, p), Z = n.mul(n.mul(C, m), p), _ = n.mul(C, n.sub(Z, n.ONE));
|
|
328
|
+
return X(n, _, i), _;
|
|
329
|
+
}
|
|
330
|
+
function J(n) {
|
|
331
|
+
const i = v(n), c = $(n), h = c(i, i.neg(i.ONE)), p = c(i, h), C = c(i, i.neg(h)), Z = (n + Q) / fe;
|
|
332
|
+
return (_, B) => {
|
|
333
|
+
let U = _.pow(B, Z), Y = _.mul(U, h);
|
|
334
|
+
const V = _.mul(U, p), l = _.mul(U, C), L = _.eql(_.sqr(Y), B), ee = _.eql(_.sqr(V), B);
|
|
335
|
+
U = _.cmov(U, Y, L), Y = _.cmov(l, V, ee);
|
|
336
|
+
const ye = _.eql(_.sqr(Y), B), Be = _.cmov(U, Y, ye);
|
|
337
|
+
return X(_, Be, B), Be;
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function $(n) {
|
|
341
|
+
if (n < K)
|
|
342
|
+
throw new Error("sqrt is not defined for small field");
|
|
343
|
+
let i = n - M, c = 0;
|
|
344
|
+
for (; i % m === x; )
|
|
345
|
+
i /= m, c++;
|
|
346
|
+
let h = m;
|
|
347
|
+
const p = v(n);
|
|
348
|
+
for (; z(p, h) === 1; )
|
|
349
|
+
if (h++ > 1e3)
|
|
350
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
351
|
+
if (c === 1)
|
|
352
|
+
return D;
|
|
353
|
+
let C = p.pow(h, i);
|
|
354
|
+
const Z = (i + M) / m;
|
|
355
|
+
return function(B, U) {
|
|
356
|
+
if (B.is0(U))
|
|
357
|
+
return U;
|
|
358
|
+
if (z(B, U) !== 1)
|
|
359
|
+
throw new Error("Cannot find square root");
|
|
360
|
+
let Y = c, V = B.mul(B.ONE, C), l = B.pow(U, i), L = B.pow(U, Z);
|
|
361
|
+
for (; !B.eql(l, B.ONE); ) {
|
|
362
|
+
if (B.is0(l))
|
|
363
|
+
return B.ZERO;
|
|
364
|
+
let ee = 1, ye = B.sqr(l);
|
|
365
|
+
for (; !B.eql(ye, B.ONE); )
|
|
366
|
+
if (ee++, ye = B.sqr(ye), ee === Y)
|
|
367
|
+
throw new Error("Cannot find square root");
|
|
368
|
+
const Be = M << BigInt(Y - ee - 1), ve = B.pow(V, Be);
|
|
369
|
+
Y = ee, V = B.sqr(ve), l = B.mul(l, V), L = B.mul(L, ve);
|
|
370
|
+
}
|
|
371
|
+
return L;
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function ce(n) {
|
|
375
|
+
return n % T === K ? D : n % ne === ie ? se : n % fe === oe ? J(n) : $(n);
|
|
376
|
+
}
|
|
377
|
+
const le = (n, i) => (G(n, i) & M) === M;
|
|
378
|
+
he.isNegativeLE = le;
|
|
379
|
+
const R = [
|
|
380
|
+
"create",
|
|
381
|
+
"isValid",
|
|
382
|
+
"is0",
|
|
383
|
+
"neg",
|
|
384
|
+
"inv",
|
|
385
|
+
"sqrt",
|
|
386
|
+
"sqr",
|
|
387
|
+
"eql",
|
|
388
|
+
"add",
|
|
389
|
+
"sub",
|
|
390
|
+
"mul",
|
|
391
|
+
"pow",
|
|
392
|
+
"div",
|
|
393
|
+
"addN",
|
|
394
|
+
"subN",
|
|
395
|
+
"mulN",
|
|
396
|
+
"sqrN"
|
|
397
|
+
];
|
|
398
|
+
function y(n) {
|
|
399
|
+
const i = {
|
|
400
|
+
ORDER: "bigint",
|
|
401
|
+
MASK: "bigint",
|
|
402
|
+
BYTES: "number",
|
|
403
|
+
BITS: "number"
|
|
404
|
+
}, c = R.reduce((h, p) => (h[p] = "function", h), i);
|
|
405
|
+
return (0, s._validateObject)(n, c), n;
|
|
406
|
+
}
|
|
407
|
+
function A(n, i, c) {
|
|
408
|
+
if (c < x)
|
|
409
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
410
|
+
if (c === x)
|
|
411
|
+
return n.ONE;
|
|
412
|
+
if (c === M)
|
|
413
|
+
return i;
|
|
414
|
+
let h = n.ONE, p = i;
|
|
415
|
+
for (; c > x; )
|
|
416
|
+
c & M && (h = n.mul(h, p)), p = n.sqr(p), c >>= M;
|
|
417
|
+
return h;
|
|
418
|
+
}
|
|
419
|
+
function O(n, i, c = !1) {
|
|
420
|
+
const h = new Array(i.length).fill(c ? n.ZERO : void 0), p = i.reduce((Z, _, B) => n.is0(_) ? Z : (h[B] = Z, n.mul(Z, _)), n.ONE), C = n.inv(p);
|
|
421
|
+
return i.reduceRight((Z, _, B) => n.is0(_) ? Z : (h[B] = n.mul(Z, h[B]), n.mul(Z, _)), C), h;
|
|
422
|
+
}
|
|
423
|
+
function q(n, i, c) {
|
|
424
|
+
return n.mul(i, typeof c == "bigint" ? j(c, n.ORDER) : n.inv(c));
|
|
425
|
+
}
|
|
426
|
+
function z(n, i) {
|
|
427
|
+
const c = (n.ORDER - M) / m, h = n.pow(i, c), p = n.eql(h, n.ONE), C = n.eql(h, n.ZERO), Z = n.eql(h, n.neg(n.ONE));
|
|
428
|
+
if (!p && !C && !Z)
|
|
429
|
+
throw new Error("invalid Legendre symbol result");
|
|
430
|
+
return p ? 1 : C ? 0 : -1;
|
|
431
|
+
}
|
|
432
|
+
function F(n, i) {
|
|
433
|
+
return z(n, i) === 1;
|
|
434
|
+
}
|
|
435
|
+
function S(n, i) {
|
|
436
|
+
i !== void 0 && (0, s.anumber)(i);
|
|
437
|
+
const c = i !== void 0 ? i : n.toString(2).length, h = Math.ceil(c / 8);
|
|
438
|
+
return { nBitLength: c, nByteLength: h };
|
|
439
|
+
}
|
|
440
|
+
function v(n, i, c = !1, h = {}) {
|
|
441
|
+
if (n <= x)
|
|
442
|
+
throw new Error("invalid field: expected ORDER > 0, got " + n);
|
|
443
|
+
let p, C, Z = !1, _;
|
|
444
|
+
if (typeof i == "object" && i != null) {
|
|
445
|
+
if (h.sqrt || c)
|
|
446
|
+
throw new Error("cannot specify opts in two arguments");
|
|
447
|
+
const l = i;
|
|
448
|
+
l.BITS && (p = l.BITS), l.sqrt && (C = l.sqrt), typeof l.isLE == "boolean" && (c = l.isLE), typeof l.modFromBytes == "boolean" && (Z = l.modFromBytes), _ = l.allowedLengths;
|
|
449
|
+
} else
|
|
450
|
+
typeof i == "number" && (p = i), h.sqrt && (C = h.sqrt);
|
|
451
|
+
const { nBitLength: B, nByteLength: U } = S(n, p);
|
|
452
|
+
if (U > 2048)
|
|
453
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
454
|
+
let Y;
|
|
455
|
+
const V = Object.freeze({
|
|
456
|
+
ORDER: n,
|
|
457
|
+
isLE: c,
|
|
458
|
+
BITS: B,
|
|
459
|
+
BYTES: U,
|
|
460
|
+
MASK: (0, s.bitMask)(B),
|
|
461
|
+
ZERO: x,
|
|
462
|
+
ONE: M,
|
|
463
|
+
allowedLengths: _,
|
|
464
|
+
create: (l) => G(l, n),
|
|
465
|
+
isValid: (l) => {
|
|
466
|
+
if (typeof l != "bigint")
|
|
467
|
+
throw new Error("invalid field element: expected bigint, got " + typeof l);
|
|
468
|
+
return x <= l && l < n;
|
|
469
|
+
},
|
|
470
|
+
is0: (l) => l === x,
|
|
471
|
+
// is valid and invertible
|
|
472
|
+
isValidNot0: (l) => !V.is0(l) && V.isValid(l),
|
|
473
|
+
isOdd: (l) => (l & M) === M,
|
|
474
|
+
neg: (l) => G(-l, n),
|
|
475
|
+
eql: (l, L) => l === L,
|
|
476
|
+
sqr: (l) => G(l * l, n),
|
|
477
|
+
add: (l, L) => G(l + L, n),
|
|
478
|
+
sub: (l, L) => G(l - L, n),
|
|
479
|
+
mul: (l, L) => G(l * L, n),
|
|
480
|
+
pow: (l, L) => A(V, l, L),
|
|
481
|
+
div: (l, L) => G(l * j(L, n), n),
|
|
482
|
+
// Same as above, but doesn't normalize
|
|
483
|
+
sqrN: (l) => l * l,
|
|
484
|
+
addN: (l, L) => l + L,
|
|
485
|
+
subN: (l, L) => l - L,
|
|
486
|
+
mulN: (l, L) => l * L,
|
|
487
|
+
inv: (l) => j(l, n),
|
|
488
|
+
sqrt: C || ((l) => (Y || (Y = ce(n)), Y(V, l))),
|
|
489
|
+
toBytes: (l) => c ? (0, s.numberToBytesLE)(l, U) : (0, s.numberToBytesBE)(l, U),
|
|
490
|
+
fromBytes: (l, L = !0) => {
|
|
491
|
+
if (_) {
|
|
492
|
+
if (!_.includes(l.length) || l.length > U)
|
|
493
|
+
throw new Error("Field.fromBytes: expected " + _ + " bytes, got " + l.length);
|
|
494
|
+
const ye = new Uint8Array(U);
|
|
495
|
+
ye.set(l, c ? 0 : ye.length - l.length), l = ye;
|
|
496
|
+
}
|
|
497
|
+
if (l.length !== U)
|
|
498
|
+
throw new Error("Field.fromBytes: expected " + U + " bytes, got " + l.length);
|
|
499
|
+
let ee = c ? (0, s.bytesToNumberLE)(l) : (0, s.bytesToNumberBE)(l);
|
|
500
|
+
if (Z && (ee = G(ee, n)), !L && !V.isValid(ee))
|
|
501
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
502
|
+
return ee;
|
|
503
|
+
},
|
|
504
|
+
// TODO: we don't need it here, move out to separate fn
|
|
505
|
+
invertBatch: (l) => O(V, l),
|
|
506
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
507
|
+
// and it's unclear what to return in there.
|
|
508
|
+
cmov: (l, L, ee) => ee ? L : l
|
|
509
|
+
});
|
|
510
|
+
return Object.freeze(V);
|
|
511
|
+
}
|
|
512
|
+
function t(n, i) {
|
|
513
|
+
if (!n.isOdd)
|
|
514
|
+
throw new Error("Field doesn't have isOdd");
|
|
515
|
+
const c = n.sqrt(i);
|
|
516
|
+
return n.isOdd(c) ? c : n.neg(c);
|
|
517
|
+
}
|
|
518
|
+
function a(n, i) {
|
|
519
|
+
if (!n.isOdd)
|
|
520
|
+
throw new Error("Field doesn't have isOdd");
|
|
521
|
+
const c = n.sqrt(i);
|
|
522
|
+
return n.isOdd(c) ? n.neg(c) : c;
|
|
523
|
+
}
|
|
524
|
+
function r(n, i, c = !1) {
|
|
525
|
+
n = (0, s.ensureBytes)("privateHash", n);
|
|
526
|
+
const h = n.length, p = S(i).nByteLength + 8;
|
|
527
|
+
if (p < 24 || h < p || h > 1024)
|
|
528
|
+
throw new Error("hashToPrivateScalar: expected " + p + "-1024 bytes of input, got " + h);
|
|
529
|
+
const C = c ? (0, s.bytesToNumberLE)(n) : (0, s.bytesToNumberBE)(n);
|
|
530
|
+
return G(C, i - M) + M;
|
|
531
|
+
}
|
|
532
|
+
function e(n) {
|
|
533
|
+
if (typeof n != "bigint")
|
|
534
|
+
throw new Error("field order must be bigint");
|
|
535
|
+
const i = n.toString(2).length;
|
|
536
|
+
return Math.ceil(i / 8);
|
|
537
|
+
}
|
|
538
|
+
function f(n) {
|
|
539
|
+
const i = e(n);
|
|
540
|
+
return i + Math.ceil(i / 2);
|
|
541
|
+
}
|
|
542
|
+
function g(n, i, c = !1) {
|
|
543
|
+
const h = n.length, p = e(i), C = f(i);
|
|
544
|
+
if (h < 16 || h < C || h > 1024)
|
|
545
|
+
throw new Error("expected " + C + "-1024 bytes of input, got " + h);
|
|
546
|
+
const Z = c ? (0, s.bytesToNumberLE)(n) : (0, s.bytesToNumberBE)(n), _ = G(Z, i - M) + M;
|
|
547
|
+
return c ? (0, s.numberToBytesLE)(_, p) : (0, s.numberToBytesBE)(_, p);
|
|
548
|
+
}
|
|
549
|
+
return he;
|
|
550
|
+
}
|
|
551
|
+
var Ve;
|
|
552
|
+
function nt() {
|
|
553
|
+
if (Ve) return Te;
|
|
554
|
+
Ve = 1, Object.defineProperty(Te, "__esModule", { value: !0 }), Te.wNAF = void 0, Te.negateCt = K, Te.normalizeZ = T, Te.mulEndoUnsafe = D, Te.pippenger = se, Te.precomputeMSMUnsafe = J, Te.validateBasic = $, Te._createCurveFields = le;
|
|
555
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
556
|
+
const s = /* @__PURE__ */ Ae(), x = /* @__PURE__ */ Ne(), M = BigInt(0), m = BigInt(1);
|
|
557
|
+
function K(R, y) {
|
|
558
|
+
const A = y.negate();
|
|
559
|
+
return R ? A : y;
|
|
560
|
+
}
|
|
561
|
+
function T(R, y) {
|
|
562
|
+
const A = (0, x.FpInvertBatch)(R.Fp, y.map((O) => O.Z));
|
|
563
|
+
return y.map((O, q) => R.fromAffine(O.toAffine(A[q])));
|
|
564
|
+
}
|
|
565
|
+
function ie(R, y) {
|
|
566
|
+
if (!Number.isSafeInteger(R) || R <= 0 || R > y)
|
|
567
|
+
throw new Error("invalid window size, expected [1.." + y + "], got W=" + R);
|
|
568
|
+
}
|
|
569
|
+
function Q(R, y) {
|
|
570
|
+
ie(R, y);
|
|
571
|
+
const A = Math.ceil(y / R) + 1, O = 2 ** (R - 1), q = 2 ** R, z = (0, s.bitMask)(R), F = BigInt(R);
|
|
572
|
+
return { windows: A, windowSize: O, mask: z, maxNumber: q, shiftBy: F };
|
|
573
|
+
}
|
|
574
|
+
function ne(R, y, A) {
|
|
575
|
+
const { windowSize: O, mask: q, maxNumber: z, shiftBy: F } = A;
|
|
576
|
+
let S = Number(R & q), v = R >> F;
|
|
577
|
+
S > O && (S -= z, v += m);
|
|
578
|
+
const t = y * O, a = t + Math.abs(S) - 1, r = S === 0, e = S < 0, f = y % 2 !== 0;
|
|
579
|
+
return { nextN: v, offset: a, isZero: r, isNeg: e, isNegF: f, offsetF: t };
|
|
580
|
+
}
|
|
581
|
+
function oe(R, y) {
|
|
582
|
+
if (!Array.isArray(R))
|
|
583
|
+
throw new Error("array expected");
|
|
584
|
+
R.forEach((A, O) => {
|
|
585
|
+
if (!(A instanceof y))
|
|
586
|
+
throw new Error("invalid point at index " + O);
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
function fe(R, y) {
|
|
590
|
+
if (!Array.isArray(R))
|
|
591
|
+
throw new Error("array of scalars expected");
|
|
592
|
+
R.forEach((A, O) => {
|
|
593
|
+
if (!y.isValid(A))
|
|
594
|
+
throw new Error("invalid scalar at index " + O);
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
const G = /* @__PURE__ */ new WeakMap(), re = /* @__PURE__ */ new WeakMap();
|
|
598
|
+
function H(R) {
|
|
599
|
+
return re.get(R) || 1;
|
|
600
|
+
}
|
|
601
|
+
function j(R) {
|
|
602
|
+
if (R !== M)
|
|
603
|
+
throw new Error("invalid wNAF");
|
|
604
|
+
}
|
|
605
|
+
class X {
|
|
606
|
+
// Parametrized with a given Point class (not individual point)
|
|
607
|
+
constructor(y, A) {
|
|
608
|
+
this.BASE = y.BASE, this.ZERO = y.ZERO, this.Fn = y.Fn, this.bits = A;
|
|
609
|
+
}
|
|
610
|
+
// non-const time multiplication ladder
|
|
611
|
+
_unsafeLadder(y, A, O = this.ZERO) {
|
|
612
|
+
let q = y;
|
|
613
|
+
for (; A > M; )
|
|
614
|
+
A & m && (O = O.add(q)), q = q.double(), A >>= m;
|
|
615
|
+
return O;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
619
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
620
|
+
* Number of precomputed points depends on the curve size:
|
|
621
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
622
|
+
* - 𝑊 is the window size
|
|
623
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
624
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
625
|
+
* @param point Point instance
|
|
626
|
+
* @param W window size
|
|
627
|
+
* @returns precomputed point tables flattened to a single array
|
|
628
|
+
*/
|
|
629
|
+
precomputeWindow(y, A) {
|
|
630
|
+
const { windows: O, windowSize: q } = Q(A, this.bits), z = [];
|
|
631
|
+
let F = y, S = F;
|
|
632
|
+
for (let v = 0; v < O; v++) {
|
|
633
|
+
S = F, z.push(S);
|
|
634
|
+
for (let t = 1; t < q; t++)
|
|
635
|
+
S = S.add(F), z.push(S);
|
|
636
|
+
F = S.double();
|
|
637
|
+
}
|
|
638
|
+
return z;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
642
|
+
* More compact implementation:
|
|
643
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
644
|
+
* @returns real and fake (for const-time) points
|
|
645
|
+
*/
|
|
646
|
+
wNAF(y, A, O) {
|
|
647
|
+
if (!this.Fn.isValid(O))
|
|
648
|
+
throw new Error("invalid scalar");
|
|
649
|
+
let q = this.ZERO, z = this.BASE;
|
|
650
|
+
const F = Q(y, this.bits);
|
|
651
|
+
for (let S = 0; S < F.windows; S++) {
|
|
652
|
+
const { nextN: v, offset: t, isZero: a, isNeg: r, isNegF: e, offsetF: f } = ne(O, S, F);
|
|
653
|
+
O = v, a ? z = z.add(K(e, A[f])) : q = q.add(K(r, A[t]));
|
|
654
|
+
}
|
|
655
|
+
return j(O), { p: q, f: z };
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
659
|
+
* @param acc accumulator point to add result of multiplication
|
|
660
|
+
* @returns point
|
|
661
|
+
*/
|
|
662
|
+
wNAFUnsafe(y, A, O, q = this.ZERO) {
|
|
663
|
+
const z = Q(y, this.bits);
|
|
664
|
+
for (let F = 0; F < z.windows && O !== M; F++) {
|
|
665
|
+
const { nextN: S, offset: v, isZero: t, isNeg: a } = ne(O, F, z);
|
|
666
|
+
if (O = S, !t) {
|
|
667
|
+
const r = A[v];
|
|
668
|
+
q = q.add(a ? r.negate() : r);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return j(O), q;
|
|
672
|
+
}
|
|
673
|
+
getPrecomputes(y, A, O) {
|
|
674
|
+
let q = G.get(A);
|
|
675
|
+
return q || (q = this.precomputeWindow(A, y), y !== 1 && (typeof O == "function" && (q = O(q)), G.set(A, q))), q;
|
|
676
|
+
}
|
|
677
|
+
cached(y, A, O) {
|
|
678
|
+
const q = H(y);
|
|
679
|
+
return this.wNAF(q, this.getPrecomputes(q, y, O), A);
|
|
680
|
+
}
|
|
681
|
+
unsafe(y, A, O, q) {
|
|
682
|
+
const z = H(y);
|
|
683
|
+
return z === 1 ? this._unsafeLadder(y, A, q) : this.wNAFUnsafe(z, this.getPrecomputes(z, y, O), A, q);
|
|
684
|
+
}
|
|
685
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
686
|
+
// using windowed method. This specifies window size and
|
|
687
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
688
|
+
createCache(y, A) {
|
|
689
|
+
ie(A, this.bits), re.set(y, A), G.delete(y);
|
|
690
|
+
}
|
|
691
|
+
hasCache(y) {
|
|
692
|
+
return H(y) !== 1;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
Te.wNAF = X;
|
|
696
|
+
function D(R, y, A, O) {
|
|
697
|
+
let q = y, z = R.ZERO, F = R.ZERO;
|
|
698
|
+
for (; A > M || O > M; )
|
|
699
|
+
A & m && (z = z.add(q)), O & m && (F = F.add(q)), q = q.double(), A >>= m, O >>= m;
|
|
700
|
+
return { p1: z, p2: F };
|
|
701
|
+
}
|
|
702
|
+
function se(R, y, A, O) {
|
|
703
|
+
oe(A, R), fe(O, y);
|
|
704
|
+
const q = A.length, z = O.length;
|
|
705
|
+
if (q !== z)
|
|
706
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
707
|
+
const F = R.ZERO, S = (0, s.bitLen)(BigInt(q));
|
|
708
|
+
let v = 1;
|
|
709
|
+
S > 12 ? v = S - 3 : S > 4 ? v = S - 2 : S > 0 && (v = 2);
|
|
710
|
+
const t = (0, s.bitMask)(v), a = new Array(Number(t) + 1).fill(F), r = Math.floor((y.BITS - 1) / v) * v;
|
|
711
|
+
let e = F;
|
|
712
|
+
for (let f = r; f >= 0; f -= v) {
|
|
713
|
+
a.fill(F);
|
|
714
|
+
for (let n = 0; n < z; n++) {
|
|
715
|
+
const i = O[n], c = Number(i >> BigInt(f) & t);
|
|
716
|
+
a[c] = a[c].add(A[n]);
|
|
717
|
+
}
|
|
718
|
+
let g = F;
|
|
719
|
+
for (let n = a.length - 1, i = F; n > 0; n--)
|
|
720
|
+
i = i.add(a[n]), g = g.add(i);
|
|
721
|
+
if (e = e.add(g), f !== 0)
|
|
722
|
+
for (let n = 0; n < v; n++)
|
|
723
|
+
e = e.double();
|
|
724
|
+
}
|
|
725
|
+
return e;
|
|
726
|
+
}
|
|
727
|
+
function J(R, y, A, O) {
|
|
728
|
+
ie(O, y.BITS), oe(A, R);
|
|
729
|
+
const q = R.ZERO, z = 2 ** O - 1, F = Math.ceil(y.BITS / O), S = (0, s.bitMask)(O), v = A.map((t) => {
|
|
730
|
+
const a = [];
|
|
731
|
+
for (let r = 0, e = t; r < z; r++)
|
|
732
|
+
a.push(e), e = e.add(t);
|
|
733
|
+
return a;
|
|
734
|
+
});
|
|
735
|
+
return (t) => {
|
|
736
|
+
if (fe(t, y), t.length > A.length)
|
|
737
|
+
throw new Error("array of scalars must be smaller than array of points");
|
|
738
|
+
let a = q;
|
|
739
|
+
for (let r = 0; r < F; r++) {
|
|
740
|
+
if (a !== q)
|
|
741
|
+
for (let f = 0; f < O; f++)
|
|
742
|
+
a = a.double();
|
|
743
|
+
const e = BigInt(F * O - (r + 1) * O);
|
|
744
|
+
for (let f = 0; f < t.length; f++) {
|
|
745
|
+
const g = t[f], n = Number(g >> e & S);
|
|
746
|
+
n && (a = a.add(v[f][n - 1]));
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return a;
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
function $(R) {
|
|
753
|
+
return (0, x.validateField)(R.Fp), (0, s.validateObject)(R, {
|
|
754
|
+
n: "bigint",
|
|
755
|
+
h: "bigint",
|
|
756
|
+
Gx: "field",
|
|
757
|
+
Gy: "field"
|
|
758
|
+
}, {
|
|
759
|
+
nBitLength: "isSafeInteger",
|
|
760
|
+
nByteLength: "isSafeInteger"
|
|
761
|
+
}), Object.freeze({
|
|
762
|
+
...(0, x.nLength)(R.n, R.nBitLength),
|
|
763
|
+
...R,
|
|
764
|
+
p: R.Fp.ORDER
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
function ce(R, y, A) {
|
|
768
|
+
if (y) {
|
|
769
|
+
if (y.ORDER !== R)
|
|
770
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
771
|
+
return (0, x.validateField)(y), y;
|
|
772
|
+
} else
|
|
773
|
+
return (0, x.Field)(R, { isLE: A });
|
|
774
|
+
}
|
|
775
|
+
function le(R, y, A = {}, O) {
|
|
776
|
+
if (O === void 0 && (O = R === "edwards"), !y || typeof y != "object")
|
|
777
|
+
throw new Error(`expected valid ${R} CURVE object`);
|
|
778
|
+
for (const v of ["p", "n", "h"]) {
|
|
779
|
+
const t = y[v];
|
|
780
|
+
if (!(typeof t == "bigint" && t > M))
|
|
781
|
+
throw new Error(`CURVE.${v} must be positive bigint`);
|
|
782
|
+
}
|
|
783
|
+
const q = ce(y.p, A.Fp, O), z = ce(y.n, A.Fn, O), S = ["Gx", "Gy", "a", R === "weierstrass" ? "b" : "d"];
|
|
784
|
+
for (const v of S)
|
|
785
|
+
if (!q.isValid(y[v]))
|
|
786
|
+
throw new Error(`CURVE.${v} must be valid field element of CURVE.Fp`);
|
|
787
|
+
return y = Object.freeze(Object.assign({}, y)), { CURVE: y, Fp: q, Fn: z };
|
|
788
|
+
}
|
|
789
|
+
return Te;
|
|
790
|
+
}
|
|
791
|
+
var Ke;
|
|
792
|
+
function Qe() {
|
|
793
|
+
return Ke || (Ke = 1, (function(s) {
|
|
794
|
+
Object.defineProperty(s, "__esModule", { value: !0 }), s.DER = s.DERErr = void 0, s._splitEndoScalar = Q, s._normFnElement = D, s.weierstrassN = se, s.SWUFpSqrtRatio = $, s.mapToCurveSimpleSWU = ce, s.ecdh = R, s.ecdsa = y, s.weierstrassPoints = A, s._legacyHelperEquat = z, s.weierstrass = v;
|
|
795
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
796
|
+
const x = /* @__PURE__ */ tt(), M = /* @__PURE__ */ xe(), m = /* @__PURE__ */ Ae(), K = /* @__PURE__ */ nt(), T = /* @__PURE__ */ Ne(), ie = (t, a) => (t + (t >= 0 ? a : -a) / H) / a;
|
|
797
|
+
function Q(t, a, r) {
|
|
798
|
+
const [[e, f], [g, n]] = a, i = ie(n * t, r), c = ie(-f * t, r);
|
|
799
|
+
let h = t - i * e - c * g, p = -i * f - c * n;
|
|
800
|
+
const C = h < G, Z = p < G;
|
|
801
|
+
C && (h = -h), Z && (p = -p);
|
|
802
|
+
const _ = (0, m.bitMask)(Math.ceil((0, m.bitLen)(r) / 2)) + re;
|
|
803
|
+
if (h < G || h >= _ || p < G || p >= _)
|
|
804
|
+
throw new Error("splitScalar (endomorphism): failed, k=" + t);
|
|
805
|
+
return { k1neg: C, k1: h, k2neg: Z, k2: p };
|
|
806
|
+
}
|
|
807
|
+
function ne(t) {
|
|
808
|
+
if (!["compact", "recovered", "der"].includes(t))
|
|
809
|
+
throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
810
|
+
return t;
|
|
811
|
+
}
|
|
812
|
+
function oe(t, a) {
|
|
813
|
+
const r = {};
|
|
814
|
+
for (let e of Object.keys(a))
|
|
815
|
+
r[e] = t[e] === void 0 ? a[e] : t[e];
|
|
816
|
+
return (0, m._abool2)(r.lowS, "lowS"), (0, m._abool2)(r.prehash, "prehash"), r.format !== void 0 && ne(r.format), r;
|
|
817
|
+
}
|
|
818
|
+
class fe extends Error {
|
|
819
|
+
constructor(a = "") {
|
|
820
|
+
super(a);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
s.DERErr = fe, s.DER = {
|
|
824
|
+
// asn.1 DER encoding utils
|
|
825
|
+
Err: fe,
|
|
826
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
827
|
+
_tlv: {
|
|
828
|
+
encode: (t, a) => {
|
|
829
|
+
const { Err: r } = s.DER;
|
|
830
|
+
if (t < 0 || t > 256)
|
|
831
|
+
throw new r("tlv.encode: wrong tag");
|
|
832
|
+
if (a.length & 1)
|
|
833
|
+
throw new r("tlv.encode: unpadded data");
|
|
834
|
+
const e = a.length / 2, f = (0, m.numberToHexUnpadded)(e);
|
|
835
|
+
if (f.length / 2 & 128)
|
|
836
|
+
throw new r("tlv.encode: long form length too big");
|
|
837
|
+
const g = e > 127 ? (0, m.numberToHexUnpadded)(f.length / 2 | 128) : "";
|
|
838
|
+
return (0, m.numberToHexUnpadded)(t) + g + f + a;
|
|
839
|
+
},
|
|
840
|
+
// v - value, l - left bytes (unparsed)
|
|
841
|
+
decode(t, a) {
|
|
842
|
+
const { Err: r } = s.DER;
|
|
843
|
+
let e = 0;
|
|
844
|
+
if (t < 0 || t > 256)
|
|
845
|
+
throw new r("tlv.encode: wrong tag");
|
|
846
|
+
if (a.length < 2 || a[e++] !== t)
|
|
847
|
+
throw new r("tlv.decode: wrong tlv");
|
|
848
|
+
const f = a[e++], g = !!(f & 128);
|
|
849
|
+
let n = 0;
|
|
850
|
+
if (!g)
|
|
851
|
+
n = f;
|
|
852
|
+
else {
|
|
853
|
+
const c = f & 127;
|
|
854
|
+
if (!c)
|
|
855
|
+
throw new r("tlv.decode(long): indefinite length not supported");
|
|
856
|
+
if (c > 4)
|
|
857
|
+
throw new r("tlv.decode(long): byte length is too big");
|
|
858
|
+
const h = a.subarray(e, e + c);
|
|
859
|
+
if (h.length !== c)
|
|
860
|
+
throw new r("tlv.decode: length bytes not complete");
|
|
861
|
+
if (h[0] === 0)
|
|
862
|
+
throw new r("tlv.decode(long): zero leftmost byte");
|
|
863
|
+
for (const p of h)
|
|
864
|
+
n = n << 8 | p;
|
|
865
|
+
if (e += c, n < 128)
|
|
866
|
+
throw new r("tlv.decode(long): not minimal encoding");
|
|
867
|
+
}
|
|
868
|
+
const i = a.subarray(e, e + n);
|
|
869
|
+
if (i.length !== n)
|
|
870
|
+
throw new r("tlv.decode: wrong value length");
|
|
871
|
+
return { v: i, l: a.subarray(e + n) };
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
875
|
+
// since we always use positive integers here. It must always be empty:
|
|
876
|
+
// - add zero byte if exists
|
|
877
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
878
|
+
_int: {
|
|
879
|
+
encode(t) {
|
|
880
|
+
const { Err: a } = s.DER;
|
|
881
|
+
if (t < G)
|
|
882
|
+
throw new a("integer: negative integers are not allowed");
|
|
883
|
+
let r = (0, m.numberToHexUnpadded)(t);
|
|
884
|
+
if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
|
|
885
|
+
throw new a("unexpected DER parsing assertion: unpadded hex");
|
|
886
|
+
return r;
|
|
887
|
+
},
|
|
888
|
+
decode(t) {
|
|
889
|
+
const { Err: a } = s.DER;
|
|
890
|
+
if (t[0] & 128)
|
|
891
|
+
throw new a("invalid signature integer: negative");
|
|
892
|
+
if (t[0] === 0 && !(t[1] & 128))
|
|
893
|
+
throw new a("invalid signature integer: unnecessary leading zero");
|
|
894
|
+
return (0, m.bytesToNumberBE)(t);
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
toSig(t) {
|
|
898
|
+
const { Err: a, _int: r, _tlv: e } = s.DER, f = (0, m.ensureBytes)("signature", t), { v: g, l: n } = e.decode(48, f);
|
|
899
|
+
if (n.length)
|
|
900
|
+
throw new a("invalid signature: left bytes after parsing");
|
|
901
|
+
const { v: i, l: c } = e.decode(2, g), { v: h, l: p } = e.decode(2, c);
|
|
902
|
+
if (p.length)
|
|
903
|
+
throw new a("invalid signature: left bytes after parsing");
|
|
904
|
+
return { r: r.decode(i), s: r.decode(h) };
|
|
905
|
+
},
|
|
906
|
+
hexFromSig(t) {
|
|
907
|
+
const { _tlv: a, _int: r } = s.DER, e = a.encode(2, r.encode(t.r)), f = a.encode(2, r.encode(t.s)), g = e + f;
|
|
908
|
+
return a.encode(48, g);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const G = BigInt(0), re = BigInt(1), H = BigInt(2), j = BigInt(3), X = BigInt(4);
|
|
912
|
+
function D(t, a) {
|
|
913
|
+
const { BYTES: r } = t;
|
|
914
|
+
let e;
|
|
915
|
+
if (typeof a == "bigint")
|
|
916
|
+
e = a;
|
|
917
|
+
else {
|
|
918
|
+
let f = (0, m.ensureBytes)("private key", a);
|
|
919
|
+
try {
|
|
920
|
+
e = t.fromBytes(f);
|
|
921
|
+
} catch {
|
|
922
|
+
throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof a}`);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
if (!t.isValidNot0(e))
|
|
926
|
+
throw new Error("invalid private key: out of range [1..N-1]");
|
|
927
|
+
return e;
|
|
928
|
+
}
|
|
929
|
+
function se(t, a = {}) {
|
|
930
|
+
const r = (0, K._createCurveFields)("weierstrass", t, a), { Fp: e, Fn: f } = r;
|
|
931
|
+
let g = r.CURVE;
|
|
932
|
+
const { h: n, n: i } = g;
|
|
933
|
+
(0, m._validateObject)(a, {}, {
|
|
934
|
+
allowInfinityPoint: "boolean",
|
|
935
|
+
clearCofactor: "function",
|
|
936
|
+
isTorsionFree: "function",
|
|
937
|
+
fromBytes: "function",
|
|
938
|
+
toBytes: "function",
|
|
939
|
+
endo: "object",
|
|
940
|
+
wrapPrivateKey: "boolean"
|
|
941
|
+
});
|
|
942
|
+
const { endo: c } = a;
|
|
943
|
+
if (c && (!e.is0(g.a) || typeof c.beta != "bigint" || !Array.isArray(c.basises)))
|
|
944
|
+
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
945
|
+
const h = le(e, f);
|
|
946
|
+
function p() {
|
|
947
|
+
if (!e.isOdd)
|
|
948
|
+
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
949
|
+
}
|
|
950
|
+
function C(ue, E, w) {
|
|
951
|
+
const { x: d, y: N } = E.toAffine(), o = e.toBytes(d);
|
|
952
|
+
if ((0, m._abool2)(w, "isCompressed"), w) {
|
|
953
|
+
p();
|
|
954
|
+
const u = !e.isOdd(N);
|
|
955
|
+
return (0, m.concatBytes)(J(u), o);
|
|
956
|
+
} else
|
|
957
|
+
return (0, m.concatBytes)(Uint8Array.of(4), o, e.toBytes(N));
|
|
958
|
+
}
|
|
959
|
+
function Z(ue) {
|
|
960
|
+
(0, m._abytes2)(ue, void 0, "Point");
|
|
961
|
+
const { publicKey: E, publicKeyUncompressed: w } = h, d = ue.length, N = ue[0], o = ue.subarray(1);
|
|
962
|
+
if (d === E && (N === 2 || N === 3)) {
|
|
963
|
+
const u = e.fromBytes(o);
|
|
964
|
+
if (!e.isValid(u))
|
|
965
|
+
throw new Error("bad point: is not on curve, wrong x");
|
|
966
|
+
const b = U(u);
|
|
967
|
+
let I;
|
|
968
|
+
try {
|
|
969
|
+
I = e.sqrt(b);
|
|
970
|
+
} catch (ge) {
|
|
971
|
+
const de = ge instanceof Error ? ": " + ge.message : "";
|
|
972
|
+
throw new Error("bad point: is not on curve, sqrt error" + de);
|
|
973
|
+
}
|
|
974
|
+
p();
|
|
975
|
+
const k = e.isOdd(I);
|
|
976
|
+
return (N & 1) === 1 !== k && (I = e.neg(I)), { x: u, y: I };
|
|
977
|
+
} else if (d === w && N === 4) {
|
|
978
|
+
const u = e.BYTES, b = e.fromBytes(o.subarray(0, u)), I = e.fromBytes(o.subarray(u, u * 2));
|
|
979
|
+
if (!Y(b, I))
|
|
980
|
+
throw new Error("bad point: is not on curve");
|
|
981
|
+
return { x: b, y: I };
|
|
982
|
+
} else
|
|
983
|
+
throw new Error(`bad point: got length ${d}, expected compressed=${E} or uncompressed=${w}`);
|
|
984
|
+
}
|
|
985
|
+
const _ = a.toBytes || C, B = a.fromBytes || Z;
|
|
986
|
+
function U(ue) {
|
|
987
|
+
const E = e.sqr(ue), w = e.mul(E, ue);
|
|
988
|
+
return e.add(e.add(w, e.mul(ue, g.a)), g.b);
|
|
989
|
+
}
|
|
990
|
+
function Y(ue, E) {
|
|
991
|
+
const w = e.sqr(E), d = U(ue);
|
|
992
|
+
return e.eql(w, d);
|
|
993
|
+
}
|
|
994
|
+
if (!Y(g.Gx, g.Gy))
|
|
995
|
+
throw new Error("bad curve params: generator point");
|
|
996
|
+
const V = e.mul(e.pow(g.a, j), X), l = e.mul(e.sqr(g.b), BigInt(27));
|
|
997
|
+
if (e.is0(e.add(V, l)))
|
|
998
|
+
throw new Error("bad curve params: a or b");
|
|
999
|
+
function L(ue, E, w = !1) {
|
|
1000
|
+
if (!e.isValid(E) || w && e.is0(E))
|
|
1001
|
+
throw new Error(`bad point coordinate ${ue}`);
|
|
1002
|
+
return E;
|
|
1003
|
+
}
|
|
1004
|
+
function ee(ue) {
|
|
1005
|
+
if (!(ue instanceof te))
|
|
1006
|
+
throw new Error("ProjectivePoint expected");
|
|
1007
|
+
}
|
|
1008
|
+
function ye(ue) {
|
|
1009
|
+
if (!c || !c.basises)
|
|
1010
|
+
throw new Error("no endo");
|
|
1011
|
+
return Q(ue, c.basises, f.ORDER);
|
|
1012
|
+
}
|
|
1013
|
+
const Be = (0, m.memoized)((ue, E) => {
|
|
1014
|
+
const { X: w, Y: d, Z: N } = ue;
|
|
1015
|
+
if (e.eql(N, e.ONE))
|
|
1016
|
+
return { x: w, y: d };
|
|
1017
|
+
const o = ue.is0();
|
|
1018
|
+
E == null && (E = o ? e.ONE : e.inv(N));
|
|
1019
|
+
const u = e.mul(w, E), b = e.mul(d, E), I = e.mul(N, E);
|
|
1020
|
+
if (o)
|
|
1021
|
+
return { x: e.ZERO, y: e.ZERO };
|
|
1022
|
+
if (!e.eql(I, e.ONE))
|
|
1023
|
+
throw new Error("invZ was invalid");
|
|
1024
|
+
return { x: u, y: b };
|
|
1025
|
+
}), ve = (0, m.memoized)((ue) => {
|
|
1026
|
+
if (ue.is0()) {
|
|
1027
|
+
if (a.allowInfinityPoint && !e.is0(ue.Y))
|
|
1028
|
+
return;
|
|
1029
|
+
throw new Error("bad point: ZERO");
|
|
1030
|
+
}
|
|
1031
|
+
const { x: E, y: w } = ue.toAffine();
|
|
1032
|
+
if (!e.isValid(E) || !e.isValid(w))
|
|
1033
|
+
throw new Error("bad point: x or y not field elements");
|
|
1034
|
+
if (!Y(E, w))
|
|
1035
|
+
throw new Error("bad point: equation left != right");
|
|
1036
|
+
if (!ue.isTorsionFree())
|
|
1037
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
1038
|
+
return !0;
|
|
1039
|
+
});
|
|
1040
|
+
function _e(ue, E, w, d, N) {
|
|
1041
|
+
return w = new te(e.mul(w.X, ue), w.Y, w.Z), E = (0, K.negateCt)(d, E), w = (0, K.negateCt)(N, w), E.add(w);
|
|
1042
|
+
}
|
|
1043
|
+
class te {
|
|
1044
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1045
|
+
constructor(E, w, d) {
|
|
1046
|
+
this.X = L("x", E), this.Y = L("y", w, !0), this.Z = L("z", d), Object.freeze(this);
|
|
1047
|
+
}
|
|
1048
|
+
static CURVE() {
|
|
1049
|
+
return g;
|
|
1050
|
+
}
|
|
1051
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1052
|
+
static fromAffine(E) {
|
|
1053
|
+
const { x: w, y: d } = E || {};
|
|
1054
|
+
if (!E || !e.isValid(w) || !e.isValid(d))
|
|
1055
|
+
throw new Error("invalid affine point");
|
|
1056
|
+
if (E instanceof te)
|
|
1057
|
+
throw new Error("projective point not allowed");
|
|
1058
|
+
return e.is0(w) && e.is0(d) ? te.ZERO : new te(w, d, e.ONE);
|
|
1059
|
+
}
|
|
1060
|
+
static fromBytes(E) {
|
|
1061
|
+
const w = te.fromAffine(B((0, m._abytes2)(E, void 0, "point")));
|
|
1062
|
+
return w.assertValidity(), w;
|
|
1063
|
+
}
|
|
1064
|
+
static fromHex(E) {
|
|
1065
|
+
return te.fromBytes((0, m.ensureBytes)("pointHex", E));
|
|
1066
|
+
}
|
|
1067
|
+
get x() {
|
|
1068
|
+
return this.toAffine().x;
|
|
1069
|
+
}
|
|
1070
|
+
get y() {
|
|
1071
|
+
return this.toAffine().y;
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
*
|
|
1075
|
+
* @param windowSize
|
|
1076
|
+
* @param isLazy true will defer table computation until the first multiplication
|
|
1077
|
+
* @returns
|
|
1078
|
+
*/
|
|
1079
|
+
precompute(E = 8, w = !0) {
|
|
1080
|
+
return Oe.createCache(this, E), w || this.multiply(j), this;
|
|
1081
|
+
}
|
|
1082
|
+
// TODO: return `this`
|
|
1083
|
+
/** A point on curve is valid if it conforms to equation. */
|
|
1084
|
+
assertValidity() {
|
|
1085
|
+
ve(this);
|
|
1086
|
+
}
|
|
1087
|
+
hasEvenY() {
|
|
1088
|
+
const { y: E } = this.toAffine();
|
|
1089
|
+
if (!e.isOdd)
|
|
1090
|
+
throw new Error("Field doesn't support isOdd");
|
|
1091
|
+
return !e.isOdd(E);
|
|
1092
|
+
}
|
|
1093
|
+
/** Compare one point to another. */
|
|
1094
|
+
equals(E) {
|
|
1095
|
+
ee(E);
|
|
1096
|
+
const { X: w, Y: d, Z: N } = this, { X: o, Y: u, Z: b } = E, I = e.eql(e.mul(w, b), e.mul(o, N)), k = e.eql(e.mul(d, b), e.mul(u, N));
|
|
1097
|
+
return I && k;
|
|
1098
|
+
}
|
|
1099
|
+
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
1100
|
+
negate() {
|
|
1101
|
+
return new te(this.X, e.neg(this.Y), this.Z);
|
|
1102
|
+
}
|
|
1103
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
1104
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1105
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1106
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1107
|
+
double() {
|
|
1108
|
+
const { a: E, b: w } = g, d = e.mul(w, j), { X: N, Y: o, Z: u } = this;
|
|
1109
|
+
let b = e.ZERO, I = e.ZERO, k = e.ZERO, W = e.mul(N, N), ge = e.mul(o, o), de = e.mul(u, u), ae = e.mul(N, o);
|
|
1110
|
+
return ae = e.add(ae, ae), k = e.mul(N, u), k = e.add(k, k), b = e.mul(E, k), I = e.mul(d, de), I = e.add(b, I), b = e.sub(ge, I), I = e.add(ge, I), I = e.mul(b, I), b = e.mul(ae, b), k = e.mul(d, k), de = e.mul(E, de), ae = e.sub(W, de), ae = e.mul(E, ae), ae = e.add(ae, k), k = e.add(W, W), W = e.add(k, W), W = e.add(W, de), W = e.mul(W, ae), I = e.add(I, W), de = e.mul(o, u), de = e.add(de, de), W = e.mul(de, ae), b = e.sub(b, W), k = e.mul(de, ge), k = e.add(k, k), k = e.add(k, k), new te(b, I, k);
|
|
1111
|
+
}
|
|
1112
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
1113
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1114
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1115
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1116
|
+
add(E) {
|
|
1117
|
+
ee(E);
|
|
1118
|
+
const { X: w, Y: d, Z: N } = this, { X: o, Y: u, Z: b } = E;
|
|
1119
|
+
let I = e.ZERO, k = e.ZERO, W = e.ZERO;
|
|
1120
|
+
const ge = g.a, de = e.mul(g.b, j);
|
|
1121
|
+
let ae = e.mul(w, o), me = e.mul(d, u), Ee = e.mul(N, b), Se = e.add(w, d), we = e.add(o, u);
|
|
1122
|
+
Se = e.mul(Se, we), we = e.add(ae, me), Se = e.sub(Se, we), we = e.add(w, N);
|
|
1123
|
+
let pe = e.add(o, b);
|
|
1124
|
+
return we = e.mul(we, pe), pe = e.add(ae, Ee), we = e.sub(we, pe), pe = e.add(d, N), I = e.add(u, b), pe = e.mul(pe, I), I = e.add(me, Ee), pe = e.sub(pe, I), W = e.mul(ge, we), I = e.mul(de, Ee), W = e.add(I, W), I = e.sub(me, W), W = e.add(me, W), k = e.mul(I, W), me = e.add(ae, ae), me = e.add(me, ae), Ee = e.mul(ge, Ee), we = e.mul(de, we), me = e.add(me, Ee), Ee = e.sub(ae, Ee), Ee = e.mul(ge, Ee), we = e.add(we, Ee), ae = e.mul(me, we), k = e.add(k, ae), ae = e.mul(pe, we), I = e.mul(Se, I), I = e.sub(I, ae), ae = e.mul(Se, me), W = e.mul(pe, W), W = e.add(W, ae), new te(I, k, W);
|
|
1125
|
+
}
|
|
1126
|
+
subtract(E) {
|
|
1127
|
+
return this.add(E.negate());
|
|
1128
|
+
}
|
|
1129
|
+
is0() {
|
|
1130
|
+
return this.equals(te.ZERO);
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Constant time multiplication.
|
|
1134
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
1135
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
1136
|
+
* Uses precomputes when available.
|
|
1137
|
+
* Uses endomorphism for Koblitz curves.
|
|
1138
|
+
* @param scalar by which the point would be multiplied
|
|
1139
|
+
* @returns New point
|
|
1140
|
+
*/
|
|
1141
|
+
multiply(E) {
|
|
1142
|
+
const { endo: w } = a;
|
|
1143
|
+
if (!f.isValidNot0(E))
|
|
1144
|
+
throw new Error("invalid scalar: out of range");
|
|
1145
|
+
let d, N;
|
|
1146
|
+
const o = (u) => Oe.cached(this, u, (b) => (0, K.normalizeZ)(te, b));
|
|
1147
|
+
if (w) {
|
|
1148
|
+
const { k1neg: u, k1: b, k2neg: I, k2: k } = ye(E), { p: W, f: ge } = o(b), { p: de, f: ae } = o(k);
|
|
1149
|
+
N = ge.add(ae), d = _e(w.beta, W, de, u, I);
|
|
1150
|
+
} else {
|
|
1151
|
+
const { p: u, f: b } = o(E);
|
|
1152
|
+
d = u, N = b;
|
|
1153
|
+
}
|
|
1154
|
+
return (0, K.normalizeZ)(te, [d, N])[0];
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1158
|
+
* It's faster, but should only be used when you don't care about
|
|
1159
|
+
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
1160
|
+
*/
|
|
1161
|
+
multiplyUnsafe(E) {
|
|
1162
|
+
const { endo: w } = a, d = this;
|
|
1163
|
+
if (!f.isValid(E))
|
|
1164
|
+
throw new Error("invalid scalar: out of range");
|
|
1165
|
+
if (E === G || d.is0())
|
|
1166
|
+
return te.ZERO;
|
|
1167
|
+
if (E === re)
|
|
1168
|
+
return d;
|
|
1169
|
+
if (Oe.hasCache(this))
|
|
1170
|
+
return this.multiply(E);
|
|
1171
|
+
if (w) {
|
|
1172
|
+
const { k1neg: N, k1: o, k2neg: u, k2: b } = ye(E), { p1: I, p2: k } = (0, K.mulEndoUnsafe)(te, d, o, b);
|
|
1173
|
+
return _e(w.beta, I, k, N, u);
|
|
1174
|
+
} else
|
|
1175
|
+
return Oe.unsafe(d, E);
|
|
1176
|
+
}
|
|
1177
|
+
multiplyAndAddUnsafe(E, w, d) {
|
|
1178
|
+
const N = this.multiplyUnsafe(w).add(E.multiplyUnsafe(d));
|
|
1179
|
+
return N.is0() ? void 0 : N;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Converts Projective point to affine (x, y) coordinates.
|
|
1183
|
+
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
1184
|
+
*/
|
|
1185
|
+
toAffine(E) {
|
|
1186
|
+
return Be(this, E);
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
1190
|
+
* Always torsion-free for cofactor=1 curves.
|
|
1191
|
+
*/
|
|
1192
|
+
isTorsionFree() {
|
|
1193
|
+
const { isTorsionFree: E } = a;
|
|
1194
|
+
return n === re ? !0 : E ? E(te, this) : Oe.unsafe(this, i).is0();
|
|
1195
|
+
}
|
|
1196
|
+
clearCofactor() {
|
|
1197
|
+
const { clearCofactor: E } = a;
|
|
1198
|
+
return n === re ? this : E ? E(te, this) : this.multiplyUnsafe(n);
|
|
1199
|
+
}
|
|
1200
|
+
isSmallOrder() {
|
|
1201
|
+
return this.multiplyUnsafe(n).is0();
|
|
1202
|
+
}
|
|
1203
|
+
toBytes(E = !0) {
|
|
1204
|
+
return (0, m._abool2)(E, "isCompressed"), this.assertValidity(), _(te, this, E);
|
|
1205
|
+
}
|
|
1206
|
+
toHex(E = !0) {
|
|
1207
|
+
return (0, m.bytesToHex)(this.toBytes(E));
|
|
1208
|
+
}
|
|
1209
|
+
toString() {
|
|
1210
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1211
|
+
}
|
|
1212
|
+
// TODO: remove
|
|
1213
|
+
get px() {
|
|
1214
|
+
return this.X;
|
|
1215
|
+
}
|
|
1216
|
+
get py() {
|
|
1217
|
+
return this.X;
|
|
1218
|
+
}
|
|
1219
|
+
get pz() {
|
|
1220
|
+
return this.Z;
|
|
1221
|
+
}
|
|
1222
|
+
toRawBytes(E = !0) {
|
|
1223
|
+
return this.toBytes(E);
|
|
1224
|
+
}
|
|
1225
|
+
_setWindowSize(E) {
|
|
1226
|
+
this.precompute(E);
|
|
1227
|
+
}
|
|
1228
|
+
static normalizeZ(E) {
|
|
1229
|
+
return (0, K.normalizeZ)(te, E);
|
|
1230
|
+
}
|
|
1231
|
+
static msm(E, w) {
|
|
1232
|
+
return (0, K.pippenger)(te, f, E, w);
|
|
1233
|
+
}
|
|
1234
|
+
static fromPrivateKey(E) {
|
|
1235
|
+
return te.BASE.multiply(D(f, E));
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
te.BASE = new te(g.Gx, g.Gy, e.ONE), te.ZERO = new te(e.ZERO, e.ONE, e.ZERO), te.Fp = e, te.Fn = f;
|
|
1239
|
+
const Re = f.BITS, Oe = new K.wNAF(te, a.endo ? Math.ceil(Re / 2) : Re);
|
|
1240
|
+
return te.BASE.precompute(8), te;
|
|
1241
|
+
}
|
|
1242
|
+
function J(t) {
|
|
1243
|
+
return Uint8Array.of(t ? 2 : 3);
|
|
1244
|
+
}
|
|
1245
|
+
function $(t, a) {
|
|
1246
|
+
const r = t.ORDER;
|
|
1247
|
+
let e = G;
|
|
1248
|
+
for (let B = r - re; B % H === G; B /= H)
|
|
1249
|
+
e += re;
|
|
1250
|
+
const f = e, g = H << f - re - re, n = g * H, i = (r - re) / n, c = (i - re) / H, h = n - re, p = g, C = t.pow(a, i), Z = t.pow(a, (i + re) / H);
|
|
1251
|
+
let _ = (B, U) => {
|
|
1252
|
+
let Y = C, V = t.pow(U, h), l = t.sqr(V);
|
|
1253
|
+
l = t.mul(l, U);
|
|
1254
|
+
let L = t.mul(B, l);
|
|
1255
|
+
L = t.pow(L, c), L = t.mul(L, V), V = t.mul(L, U), l = t.mul(L, B);
|
|
1256
|
+
let ee = t.mul(l, V);
|
|
1257
|
+
L = t.pow(ee, p);
|
|
1258
|
+
let ye = t.eql(L, t.ONE);
|
|
1259
|
+
V = t.mul(l, Z), L = t.mul(ee, Y), l = t.cmov(V, l, ye), ee = t.cmov(L, ee, ye);
|
|
1260
|
+
for (let Be = f; Be > re; Be--) {
|
|
1261
|
+
let ve = Be - H;
|
|
1262
|
+
ve = H << ve - re;
|
|
1263
|
+
let _e = t.pow(ee, ve);
|
|
1264
|
+
const te = t.eql(_e, t.ONE);
|
|
1265
|
+
V = t.mul(l, Y), Y = t.mul(Y, Y), _e = t.mul(ee, Y), l = t.cmov(V, l, te), ee = t.cmov(_e, ee, te);
|
|
1266
|
+
}
|
|
1267
|
+
return { isValid: ye, value: l };
|
|
1268
|
+
};
|
|
1269
|
+
if (t.ORDER % X === j) {
|
|
1270
|
+
const B = (t.ORDER - j) / X, U = t.sqrt(t.neg(a));
|
|
1271
|
+
_ = (Y, V) => {
|
|
1272
|
+
let l = t.sqr(V);
|
|
1273
|
+
const L = t.mul(Y, V);
|
|
1274
|
+
l = t.mul(l, L);
|
|
1275
|
+
let ee = t.pow(l, B);
|
|
1276
|
+
ee = t.mul(ee, L);
|
|
1277
|
+
const ye = t.mul(ee, U), Be = t.mul(t.sqr(ee), V), ve = t.eql(Be, Y);
|
|
1278
|
+
let _e = t.cmov(ye, ee, ve);
|
|
1279
|
+
return { isValid: ve, value: _e };
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
return _;
|
|
1283
|
+
}
|
|
1284
|
+
function ce(t, a) {
|
|
1285
|
+
(0, T.validateField)(t);
|
|
1286
|
+
const { A: r, B: e, Z: f } = a;
|
|
1287
|
+
if (!t.isValid(r) || !t.isValid(e) || !t.isValid(f))
|
|
1288
|
+
throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
1289
|
+
const g = $(t, f);
|
|
1290
|
+
if (!t.isOdd)
|
|
1291
|
+
throw new Error("Field does not have .isOdd()");
|
|
1292
|
+
return (n) => {
|
|
1293
|
+
let i, c, h, p, C, Z, _, B;
|
|
1294
|
+
i = t.sqr(n), i = t.mul(i, f), c = t.sqr(i), c = t.add(c, i), h = t.add(c, t.ONE), h = t.mul(h, e), p = t.cmov(f, t.neg(c), !t.eql(c, t.ZERO)), p = t.mul(p, r), c = t.sqr(h), Z = t.sqr(p), C = t.mul(Z, r), c = t.add(c, C), c = t.mul(c, h), Z = t.mul(Z, p), C = t.mul(Z, e), c = t.add(c, C), _ = t.mul(i, h);
|
|
1295
|
+
const { isValid: U, value: Y } = g(c, Z);
|
|
1296
|
+
B = t.mul(i, n), B = t.mul(B, Y), _ = t.cmov(_, h, U), B = t.cmov(B, Y, U);
|
|
1297
|
+
const V = t.isOdd(n) === t.isOdd(B);
|
|
1298
|
+
B = t.cmov(t.neg(B), B, V);
|
|
1299
|
+
const l = (0, T.FpInvertBatch)(t, [p], !0)[0];
|
|
1300
|
+
return _ = t.mul(_, l), { x: _, y: B };
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
function le(t, a) {
|
|
1304
|
+
return {
|
|
1305
|
+
secretKey: a.BYTES,
|
|
1306
|
+
publicKey: 1 + t.BYTES,
|
|
1307
|
+
publicKeyUncompressed: 1 + 2 * t.BYTES,
|
|
1308
|
+
publicKeyHasPrefix: !0,
|
|
1309
|
+
signature: 2 * a.BYTES
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
function R(t, a = {}) {
|
|
1313
|
+
const { Fn: r } = t, e = a.randomBytes || m.randomBytes, f = Object.assign(le(t.Fp, r), { seed: (0, T.getMinHashLength)(r.ORDER) });
|
|
1314
|
+
function g(_) {
|
|
1315
|
+
try {
|
|
1316
|
+
return !!D(r, _);
|
|
1317
|
+
} catch {
|
|
1318
|
+
return !1;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
function n(_, B) {
|
|
1322
|
+
const { publicKey: U, publicKeyUncompressed: Y } = f;
|
|
1323
|
+
try {
|
|
1324
|
+
const V = _.length;
|
|
1325
|
+
return B === !0 && V !== U || B === !1 && V !== Y ? !1 : !!t.fromBytes(_);
|
|
1326
|
+
} catch {
|
|
1327
|
+
return !1;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
function i(_ = e(f.seed)) {
|
|
1331
|
+
return (0, T.mapHashToField)((0, m._abytes2)(_, f.seed, "seed"), r.ORDER);
|
|
1332
|
+
}
|
|
1333
|
+
function c(_, B = !0) {
|
|
1334
|
+
return t.BASE.multiply(D(r, _)).toBytes(B);
|
|
1335
|
+
}
|
|
1336
|
+
function h(_) {
|
|
1337
|
+
const B = i(_);
|
|
1338
|
+
return { secretKey: B, publicKey: c(B) };
|
|
1339
|
+
}
|
|
1340
|
+
function p(_) {
|
|
1341
|
+
if (typeof _ == "bigint")
|
|
1342
|
+
return !1;
|
|
1343
|
+
if (_ instanceof t)
|
|
1344
|
+
return !0;
|
|
1345
|
+
const { secretKey: B, publicKey: U, publicKeyUncompressed: Y } = f;
|
|
1346
|
+
if (r.allowedLengths || B === U)
|
|
1347
|
+
return;
|
|
1348
|
+
const V = (0, m.ensureBytes)("key", _).length;
|
|
1349
|
+
return V === U || V === Y;
|
|
1350
|
+
}
|
|
1351
|
+
function C(_, B, U = !0) {
|
|
1352
|
+
if (p(_) === !0)
|
|
1353
|
+
throw new Error("first arg must be private key");
|
|
1354
|
+
if (p(B) === !1)
|
|
1355
|
+
throw new Error("second arg must be public key");
|
|
1356
|
+
const Y = D(r, _);
|
|
1357
|
+
return t.fromHex(B).multiply(Y).toBytes(U);
|
|
1358
|
+
}
|
|
1359
|
+
return Object.freeze({ getPublicKey: c, getSharedSecret: C, keygen: h, Point: t, utils: {
|
|
1360
|
+
isValidSecretKey: g,
|
|
1361
|
+
isValidPublicKey: n,
|
|
1362
|
+
randomSecretKey: i,
|
|
1363
|
+
// TODO: remove
|
|
1364
|
+
isValidPrivateKey: g,
|
|
1365
|
+
randomPrivateKey: i,
|
|
1366
|
+
normPrivateKeyToScalar: (_) => D(r, _),
|
|
1367
|
+
precompute(_ = 8, B = t.BASE) {
|
|
1368
|
+
return B.precompute(_, !1);
|
|
1369
|
+
}
|
|
1370
|
+
}, lengths: f });
|
|
1371
|
+
}
|
|
1372
|
+
function y(t, a, r = {}) {
|
|
1373
|
+
(0, M.ahash)(a), (0, m._validateObject)(r, {}, {
|
|
1374
|
+
hmac: "function",
|
|
1375
|
+
lowS: "boolean",
|
|
1376
|
+
randomBytes: "function",
|
|
1377
|
+
bits2int: "function",
|
|
1378
|
+
bits2int_modN: "function"
|
|
1379
|
+
});
|
|
1380
|
+
const e = r.randomBytes || m.randomBytes, f = r.hmac || ((w, ...d) => (0, x.hmac)(a, w, (0, m.concatBytes)(...d))), { Fp: g, Fn: n } = t, { ORDER: i, BITS: c } = n, { keygen: h, getPublicKey: p, getSharedSecret: C, utils: Z, lengths: _ } = R(t, r), B = {
|
|
1381
|
+
prehash: !1,
|
|
1382
|
+
lowS: typeof r.lowS == "boolean" ? r.lowS : !1,
|
|
1383
|
+
format: void 0,
|
|
1384
|
+
//'compact' as ECDSASigFormat,
|
|
1385
|
+
extraEntropy: !1
|
|
1386
|
+
}, U = "compact";
|
|
1387
|
+
function Y(w) {
|
|
1388
|
+
const d = i >> re;
|
|
1389
|
+
return w > d;
|
|
1390
|
+
}
|
|
1391
|
+
function V(w, d) {
|
|
1392
|
+
if (!n.isValidNot0(d))
|
|
1393
|
+
throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);
|
|
1394
|
+
return d;
|
|
1395
|
+
}
|
|
1396
|
+
function l(w, d) {
|
|
1397
|
+
ne(d);
|
|
1398
|
+
const N = _.signature, o = d === "compact" ? N : d === "recovered" ? N + 1 : void 0;
|
|
1399
|
+
return (0, m._abytes2)(w, o, `${d} signature`);
|
|
1400
|
+
}
|
|
1401
|
+
class L {
|
|
1402
|
+
constructor(d, N, o) {
|
|
1403
|
+
this.r = V("r", d), this.s = V("s", N), o != null && (this.recovery = o), Object.freeze(this);
|
|
1404
|
+
}
|
|
1405
|
+
static fromBytes(d, N = U) {
|
|
1406
|
+
l(d, N);
|
|
1407
|
+
let o;
|
|
1408
|
+
if (N === "der") {
|
|
1409
|
+
const { r: k, s: W } = s.DER.toSig((0, m._abytes2)(d));
|
|
1410
|
+
return new L(k, W);
|
|
1411
|
+
}
|
|
1412
|
+
N === "recovered" && (o = d[0], N = "compact", d = d.subarray(1));
|
|
1413
|
+
const u = n.BYTES, b = d.subarray(0, u), I = d.subarray(u, u * 2);
|
|
1414
|
+
return new L(n.fromBytes(b), n.fromBytes(I), o);
|
|
1415
|
+
}
|
|
1416
|
+
static fromHex(d, N) {
|
|
1417
|
+
return this.fromBytes((0, m.hexToBytes)(d), N);
|
|
1418
|
+
}
|
|
1419
|
+
addRecoveryBit(d) {
|
|
1420
|
+
return new L(this.r, this.s, d);
|
|
1421
|
+
}
|
|
1422
|
+
recoverPublicKey(d) {
|
|
1423
|
+
const N = g.ORDER, { r: o, s: u, recovery: b } = this;
|
|
1424
|
+
if (b == null || ![0, 1, 2, 3].includes(b))
|
|
1425
|
+
throw new Error("recovery id invalid");
|
|
1426
|
+
if (i * H < N && b > 1)
|
|
1427
|
+
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
1428
|
+
const k = b === 2 || b === 3 ? o + i : o;
|
|
1429
|
+
if (!g.isValid(k))
|
|
1430
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
1431
|
+
const W = g.toBytes(k), ge = t.fromBytes((0, m.concatBytes)(J((b & 1) === 0), W)), de = n.inv(k), ae = ye((0, m.ensureBytes)("msgHash", d)), me = n.create(-ae * de), Ee = n.create(u * de), Se = t.BASE.multiplyUnsafe(me).add(ge.multiplyUnsafe(Ee));
|
|
1432
|
+
if (Se.is0())
|
|
1433
|
+
throw new Error("point at infinify");
|
|
1434
|
+
return Se.assertValidity(), Se;
|
|
1435
|
+
}
|
|
1436
|
+
// Signatures should be low-s, to prevent malleability.
|
|
1437
|
+
hasHighS() {
|
|
1438
|
+
return Y(this.s);
|
|
1439
|
+
}
|
|
1440
|
+
toBytes(d = U) {
|
|
1441
|
+
if (ne(d), d === "der")
|
|
1442
|
+
return (0, m.hexToBytes)(s.DER.hexFromSig(this));
|
|
1443
|
+
const N = n.toBytes(this.r), o = n.toBytes(this.s);
|
|
1444
|
+
if (d === "recovered") {
|
|
1445
|
+
if (this.recovery == null)
|
|
1446
|
+
throw new Error("recovery bit must be present");
|
|
1447
|
+
return (0, m.concatBytes)(Uint8Array.of(this.recovery), N, o);
|
|
1448
|
+
}
|
|
1449
|
+
return (0, m.concatBytes)(N, o);
|
|
1450
|
+
}
|
|
1451
|
+
toHex(d) {
|
|
1452
|
+
return (0, m.bytesToHex)(this.toBytes(d));
|
|
1453
|
+
}
|
|
1454
|
+
// TODO: remove
|
|
1455
|
+
assertValidity() {
|
|
1456
|
+
}
|
|
1457
|
+
static fromCompact(d) {
|
|
1458
|
+
return L.fromBytes((0, m.ensureBytes)("sig", d), "compact");
|
|
1459
|
+
}
|
|
1460
|
+
static fromDER(d) {
|
|
1461
|
+
return L.fromBytes((0, m.ensureBytes)("sig", d), "der");
|
|
1462
|
+
}
|
|
1463
|
+
normalizeS() {
|
|
1464
|
+
return this.hasHighS() ? new L(this.r, n.neg(this.s), this.recovery) : this;
|
|
1465
|
+
}
|
|
1466
|
+
toDERRawBytes() {
|
|
1467
|
+
return this.toBytes("der");
|
|
1468
|
+
}
|
|
1469
|
+
toDERHex() {
|
|
1470
|
+
return (0, m.bytesToHex)(this.toBytes("der"));
|
|
1471
|
+
}
|
|
1472
|
+
toCompactRawBytes() {
|
|
1473
|
+
return this.toBytes("compact");
|
|
1474
|
+
}
|
|
1475
|
+
toCompactHex() {
|
|
1476
|
+
return (0, m.bytesToHex)(this.toBytes("compact"));
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
const ee = r.bits2int || function(d) {
|
|
1480
|
+
if (d.length > 8192)
|
|
1481
|
+
throw new Error("input is too large");
|
|
1482
|
+
const N = (0, m.bytesToNumberBE)(d), o = d.length * 8 - c;
|
|
1483
|
+
return o > 0 ? N >> BigInt(o) : N;
|
|
1484
|
+
}, ye = r.bits2int_modN || function(d) {
|
|
1485
|
+
return n.create(ee(d));
|
|
1486
|
+
}, Be = (0, m.bitMask)(c);
|
|
1487
|
+
function ve(w) {
|
|
1488
|
+
return (0, m.aInRange)("num < 2^" + c, w, G, Be), n.toBytes(w);
|
|
1489
|
+
}
|
|
1490
|
+
function _e(w, d) {
|
|
1491
|
+
return (0, m._abytes2)(w, void 0, "message"), d ? (0, m._abytes2)(a(w), void 0, "prehashed message") : w;
|
|
1492
|
+
}
|
|
1493
|
+
function te(w, d, N) {
|
|
1494
|
+
if (["recovered", "canonical"].some((me) => me in N))
|
|
1495
|
+
throw new Error("sign() legacy options not supported");
|
|
1496
|
+
const { lowS: o, prehash: u, extraEntropy: b } = oe(N, B);
|
|
1497
|
+
w = _e(w, u);
|
|
1498
|
+
const I = ye(w), k = D(n, d), W = [ve(k), ve(I)];
|
|
1499
|
+
if (b != null && b !== !1) {
|
|
1500
|
+
const me = b === !0 ? e(_.secretKey) : b;
|
|
1501
|
+
W.push((0, m.ensureBytes)("extraEntropy", me));
|
|
1502
|
+
}
|
|
1503
|
+
const ge = (0, m.concatBytes)(...W), de = I;
|
|
1504
|
+
function ae(me) {
|
|
1505
|
+
const Ee = ee(me);
|
|
1506
|
+
if (!n.isValidNot0(Ee))
|
|
1507
|
+
return;
|
|
1508
|
+
const Se = n.inv(Ee), we = t.BASE.multiply(Ee).toAffine(), pe = n.create(we.x);
|
|
1509
|
+
if (pe === G)
|
|
1510
|
+
return;
|
|
1511
|
+
const qe = n.create(Se * n.create(de + pe * k));
|
|
1512
|
+
if (qe === G)
|
|
1513
|
+
return;
|
|
1514
|
+
let Ce = (we.x === pe ? 0 : 2) | Number(we.y & re), ke = qe;
|
|
1515
|
+
return o && Y(qe) && (ke = n.neg(qe), Ce ^= 1), new L(pe, ke, Ce);
|
|
1516
|
+
}
|
|
1517
|
+
return { seed: ge, k2sig: ae };
|
|
1518
|
+
}
|
|
1519
|
+
function Re(w, d, N = {}) {
|
|
1520
|
+
w = (0, m.ensureBytes)("message", w);
|
|
1521
|
+
const { seed: o, k2sig: u } = te(w, d, N);
|
|
1522
|
+
return (0, m.createHmacDrbg)(a.outputLen, n.BYTES, f)(o, u);
|
|
1523
|
+
}
|
|
1524
|
+
function Oe(w) {
|
|
1525
|
+
let d;
|
|
1526
|
+
const N = typeof w == "string" || (0, m.isBytes)(w), o = !N && w !== null && typeof w == "object" && typeof w.r == "bigint" && typeof w.s == "bigint";
|
|
1527
|
+
if (!N && !o)
|
|
1528
|
+
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
1529
|
+
if (o)
|
|
1530
|
+
d = new L(w.r, w.s);
|
|
1531
|
+
else if (N) {
|
|
1532
|
+
try {
|
|
1533
|
+
d = L.fromBytes((0, m.ensureBytes)("sig", w), "der");
|
|
1534
|
+
} catch (u) {
|
|
1535
|
+
if (!(u instanceof s.DER.Err))
|
|
1536
|
+
throw u;
|
|
1537
|
+
}
|
|
1538
|
+
if (!d)
|
|
1539
|
+
try {
|
|
1540
|
+
d = L.fromBytes((0, m.ensureBytes)("sig", w), "compact");
|
|
1541
|
+
} catch {
|
|
1542
|
+
return !1;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
return d || !1;
|
|
1546
|
+
}
|
|
1547
|
+
function ue(w, d, N, o = {}) {
|
|
1548
|
+
const { lowS: u, prehash: b, format: I } = oe(o, B);
|
|
1549
|
+
if (N = (0, m.ensureBytes)("publicKey", N), d = _e((0, m.ensureBytes)("message", d), b), "strict" in o)
|
|
1550
|
+
throw new Error("options.strict was renamed to lowS");
|
|
1551
|
+
const k = I === void 0 ? Oe(w) : L.fromBytes((0, m.ensureBytes)("sig", w), I);
|
|
1552
|
+
if (k === !1)
|
|
1553
|
+
return !1;
|
|
1554
|
+
try {
|
|
1555
|
+
const W = t.fromBytes(N);
|
|
1556
|
+
if (u && k.hasHighS())
|
|
1557
|
+
return !1;
|
|
1558
|
+
const { r: ge, s: de } = k, ae = ye(d), me = n.inv(de), Ee = n.create(ae * me), Se = n.create(ge * me), we = t.BASE.multiplyUnsafe(Ee).add(W.multiplyUnsafe(Se));
|
|
1559
|
+
return we.is0() ? !1 : n.create(we.x) === ge;
|
|
1560
|
+
} catch {
|
|
1561
|
+
return !1;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
function E(w, d, N = {}) {
|
|
1565
|
+
const { prehash: o } = oe(N, B);
|
|
1566
|
+
return d = _e(d, o), L.fromBytes(w, "recovered").recoverPublicKey(d).toBytes();
|
|
1567
|
+
}
|
|
1568
|
+
return Object.freeze({
|
|
1569
|
+
keygen: h,
|
|
1570
|
+
getPublicKey: p,
|
|
1571
|
+
getSharedSecret: C,
|
|
1572
|
+
utils: Z,
|
|
1573
|
+
lengths: _,
|
|
1574
|
+
Point: t,
|
|
1575
|
+
sign: Re,
|
|
1576
|
+
verify: ue,
|
|
1577
|
+
recoverPublicKey: E,
|
|
1578
|
+
Signature: L,
|
|
1579
|
+
hash: a
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
function A(t) {
|
|
1583
|
+
const { CURVE: a, curveOpts: r } = O(t), e = se(a, r);
|
|
1584
|
+
return F(t, e);
|
|
1585
|
+
}
|
|
1586
|
+
function O(t) {
|
|
1587
|
+
const a = {
|
|
1588
|
+
a: t.a,
|
|
1589
|
+
b: t.b,
|
|
1590
|
+
p: t.Fp.ORDER,
|
|
1591
|
+
n: t.n,
|
|
1592
|
+
h: t.h,
|
|
1593
|
+
Gx: t.Gx,
|
|
1594
|
+
Gy: t.Gy
|
|
1595
|
+
}, r = t.Fp;
|
|
1596
|
+
let e = t.allowedPrivateKeyLengths ? Array.from(new Set(t.allowedPrivateKeyLengths.map((n) => Math.ceil(n / 2)))) : void 0;
|
|
1597
|
+
const f = (0, T.Field)(a.n, {
|
|
1598
|
+
BITS: t.nBitLength,
|
|
1599
|
+
allowedLengths: e,
|
|
1600
|
+
modFromBytes: t.wrapPrivateKey
|
|
1601
|
+
}), g = {
|
|
1602
|
+
Fp: r,
|
|
1603
|
+
Fn: f,
|
|
1604
|
+
allowInfinityPoint: t.allowInfinityPoint,
|
|
1605
|
+
endo: t.endo,
|
|
1606
|
+
isTorsionFree: t.isTorsionFree,
|
|
1607
|
+
clearCofactor: t.clearCofactor,
|
|
1608
|
+
fromBytes: t.fromBytes,
|
|
1609
|
+
toBytes: t.toBytes
|
|
1610
|
+
};
|
|
1611
|
+
return { CURVE: a, curveOpts: g };
|
|
1612
|
+
}
|
|
1613
|
+
function q(t) {
|
|
1614
|
+
const { CURVE: a, curveOpts: r } = O(t), e = {
|
|
1615
|
+
hmac: t.hmac,
|
|
1616
|
+
randomBytes: t.randomBytes,
|
|
1617
|
+
lowS: t.lowS,
|
|
1618
|
+
bits2int: t.bits2int,
|
|
1619
|
+
bits2int_modN: t.bits2int_modN
|
|
1620
|
+
};
|
|
1621
|
+
return { CURVE: a, curveOpts: r, hash: t.hash, ecdsaOpts: e };
|
|
1622
|
+
}
|
|
1623
|
+
function z(t, a, r) {
|
|
1624
|
+
function e(f) {
|
|
1625
|
+
const g = t.sqr(f), n = t.mul(g, f);
|
|
1626
|
+
return t.add(t.add(n, t.mul(f, a)), r);
|
|
1627
|
+
}
|
|
1628
|
+
return e;
|
|
1629
|
+
}
|
|
1630
|
+
function F(t, a) {
|
|
1631
|
+
const { Fp: r, Fn: e } = a;
|
|
1632
|
+
function f(n) {
|
|
1633
|
+
return (0, m.inRange)(n, re, e.ORDER);
|
|
1634
|
+
}
|
|
1635
|
+
const g = z(r, t.a, t.b);
|
|
1636
|
+
return Object.assign({}, {
|
|
1637
|
+
CURVE: t,
|
|
1638
|
+
Point: a,
|
|
1639
|
+
ProjectivePoint: a,
|
|
1640
|
+
normPrivateKeyToScalar: (n) => D(e, n),
|
|
1641
|
+
weierstrassEquation: g,
|
|
1642
|
+
isWithinCurveOrder: f
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
function S(t, a) {
|
|
1646
|
+
const r = a.Point;
|
|
1647
|
+
return Object.assign({}, a, {
|
|
1648
|
+
ProjectivePoint: r,
|
|
1649
|
+
CURVE: Object.assign({}, t, (0, T.nLength)(r.Fn.ORDER, r.Fn.BITS))
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
function v(t) {
|
|
1653
|
+
const { CURVE: a, curveOpts: r, hash: e, ecdsaOpts: f } = q(t), g = se(a, r), n = y(g, e, f);
|
|
1654
|
+
return S(t, n);
|
|
1655
|
+
}
|
|
1656
|
+
})(Ue)), Ue;
|
|
1657
|
+
}
|
|
1658
|
+
var ze;
|
|
1659
|
+
function rt() {
|
|
1660
|
+
if (ze) return Ie;
|
|
1661
|
+
ze = 1, Object.defineProperty(Ie, "__esModule", { value: !0 }), Ie.getHash = x, Ie.createCurve = M;
|
|
1662
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1663
|
+
const s = /* @__PURE__ */ Qe();
|
|
1664
|
+
function x(m) {
|
|
1665
|
+
return { hash: m };
|
|
1666
|
+
}
|
|
1667
|
+
function M(m, K) {
|
|
1668
|
+
const T = (ie) => (0, s.weierstrass)({ ...m, hash: ie });
|
|
1669
|
+
return { ...T(K), create: T };
|
|
1670
|
+
}
|
|
1671
|
+
return Ie;
|
|
1672
|
+
}
|
|
1673
|
+
var je = {}, Ye;
|
|
1674
|
+
function ot() {
|
|
1675
|
+
return Ye || (Ye = 1, (function(s) {
|
|
1676
|
+
Object.defineProperty(s, "__esModule", { value: !0 }), s._DST_scalar = void 0, s.expand_message_xmd = ne, s.expand_message_xof = oe, s.hash_to_field = fe, s.isogenyMap = G, s.createHasher = re;
|
|
1677
|
+
const x = /* @__PURE__ */ Ae(), M = /* @__PURE__ */ Ne(), m = x.bytesToNumberBE;
|
|
1678
|
+
function K(H, j) {
|
|
1679
|
+
if (ie(H), ie(j), H < 0 || H >= 1 << 8 * j)
|
|
1680
|
+
throw new Error("invalid I2OSP input: " + H);
|
|
1681
|
+
const X = Array.from({ length: j }).fill(0);
|
|
1682
|
+
for (let D = j - 1; D >= 0; D--)
|
|
1683
|
+
X[D] = H & 255, H >>>= 8;
|
|
1684
|
+
return new Uint8Array(X);
|
|
1685
|
+
}
|
|
1686
|
+
function T(H, j) {
|
|
1687
|
+
const X = new Uint8Array(H.length);
|
|
1688
|
+
for (let D = 0; D < H.length; D++)
|
|
1689
|
+
X[D] = H[D] ^ j[D];
|
|
1690
|
+
return X;
|
|
1691
|
+
}
|
|
1692
|
+
function ie(H) {
|
|
1693
|
+
if (!Number.isSafeInteger(H))
|
|
1694
|
+
throw new Error("number expected");
|
|
1695
|
+
}
|
|
1696
|
+
function Q(H) {
|
|
1697
|
+
if (!(0, x.isBytes)(H) && typeof H != "string")
|
|
1698
|
+
throw new Error("DST must be Uint8Array or string");
|
|
1699
|
+
return typeof H == "string" ? (0, x.utf8ToBytes)(H) : H;
|
|
1700
|
+
}
|
|
1701
|
+
function ne(H, j, X, D) {
|
|
1702
|
+
(0, x.abytes)(H), ie(X), j = Q(j), j.length > 255 && (j = D((0, x.concatBytes)((0, x.utf8ToBytes)("H2C-OVERSIZE-DST-"), j)));
|
|
1703
|
+
const { outputLen: se, blockLen: J } = D, $ = Math.ceil(X / se);
|
|
1704
|
+
if (X > 65535 || $ > 255)
|
|
1705
|
+
throw new Error("expand_message_xmd: invalid lenInBytes");
|
|
1706
|
+
const ce = (0, x.concatBytes)(j, K(j.length, 1)), le = K(0, J), R = K(X, 2), y = new Array($), A = D((0, x.concatBytes)(le, H, R, K(0, 1), ce));
|
|
1707
|
+
y[0] = D((0, x.concatBytes)(A, K(1, 1), ce));
|
|
1708
|
+
for (let q = 1; q <= $; q++) {
|
|
1709
|
+
const z = [T(A, y[q - 1]), K(q + 1, 1), ce];
|
|
1710
|
+
y[q] = D((0, x.concatBytes)(...z));
|
|
1711
|
+
}
|
|
1712
|
+
return (0, x.concatBytes)(...y).slice(0, X);
|
|
1713
|
+
}
|
|
1714
|
+
function oe(H, j, X, D, se) {
|
|
1715
|
+
if ((0, x.abytes)(H), ie(X), j = Q(j), j.length > 255) {
|
|
1716
|
+
const J = Math.ceil(2 * D / 8);
|
|
1717
|
+
j = se.create({ dkLen: J }).update((0, x.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(j).digest();
|
|
1718
|
+
}
|
|
1719
|
+
if (X > 65535 || j.length > 255)
|
|
1720
|
+
throw new Error("expand_message_xof: invalid lenInBytes");
|
|
1721
|
+
return se.create({ dkLen: X }).update(H).update(K(X, 2)).update(j).update(K(j.length, 1)).digest();
|
|
1722
|
+
}
|
|
1723
|
+
function fe(H, j, X) {
|
|
1724
|
+
(0, x._validateObject)(X, {
|
|
1725
|
+
p: "bigint",
|
|
1726
|
+
m: "number",
|
|
1727
|
+
k: "number",
|
|
1728
|
+
hash: "function"
|
|
1729
|
+
});
|
|
1730
|
+
const { p: D, k: se, m: J, hash: $, expand: ce, DST: le } = X;
|
|
1731
|
+
if (!(0, x.isHash)(X.hash))
|
|
1732
|
+
throw new Error("expected valid hash");
|
|
1733
|
+
(0, x.abytes)(H), ie(j);
|
|
1734
|
+
const R = D.toString(2).length, y = Math.ceil((R + se) / 8), A = j * J * y;
|
|
1735
|
+
let O;
|
|
1736
|
+
if (ce === "xmd")
|
|
1737
|
+
O = ne(H, le, A, $);
|
|
1738
|
+
else if (ce === "xof")
|
|
1739
|
+
O = oe(H, le, A, se, $);
|
|
1740
|
+
else if (ce === "_internal_pass")
|
|
1741
|
+
O = H;
|
|
1742
|
+
else
|
|
1743
|
+
throw new Error('expand must be "xmd" or "xof"');
|
|
1744
|
+
const q = new Array(j);
|
|
1745
|
+
for (let z = 0; z < j; z++) {
|
|
1746
|
+
const F = new Array(J);
|
|
1747
|
+
for (let S = 0; S < J; S++) {
|
|
1748
|
+
const v = y * (S + z * J), t = O.subarray(v, v + y);
|
|
1749
|
+
F[S] = (0, M.mod)(m(t), D);
|
|
1750
|
+
}
|
|
1751
|
+
q[z] = F;
|
|
1752
|
+
}
|
|
1753
|
+
return q;
|
|
1754
|
+
}
|
|
1755
|
+
function G(H, j) {
|
|
1756
|
+
const X = j.map((D) => Array.from(D).reverse());
|
|
1757
|
+
return (D, se) => {
|
|
1758
|
+
const [J, $, ce, le] = X.map((A) => A.reduce((O, q) => H.add(H.mul(O, D), q))), [R, y] = (0, M.FpInvertBatch)(H, [$, le], !0);
|
|
1759
|
+
return D = H.mul(J, R), se = H.mul(se, H.mul(ce, y)), { x: D, y: se };
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
s._DST_scalar = (0, x.utf8ToBytes)("HashToScalar-");
|
|
1763
|
+
function re(H, j, X) {
|
|
1764
|
+
if (typeof j != "function")
|
|
1765
|
+
throw new Error("mapToCurve() must be defined");
|
|
1766
|
+
function D(J) {
|
|
1767
|
+
return H.fromAffine(j(J));
|
|
1768
|
+
}
|
|
1769
|
+
function se(J) {
|
|
1770
|
+
const $ = J.clearCofactor();
|
|
1771
|
+
return $.equals(H.ZERO) ? H.ZERO : ($.assertValidity(), $);
|
|
1772
|
+
}
|
|
1773
|
+
return {
|
|
1774
|
+
defaults: X,
|
|
1775
|
+
hashToCurve(J, $) {
|
|
1776
|
+
const ce = Object.assign({}, X, $), le = fe(J, 2, ce), R = D(le[0]), y = D(le[1]);
|
|
1777
|
+
return se(R.add(y));
|
|
1778
|
+
},
|
|
1779
|
+
encodeToCurve(J, $) {
|
|
1780
|
+
const ce = X.encodeDST ? { DST: X.encodeDST } : {}, le = Object.assign({}, X, ce, $), R = fe(J, 1, le), y = D(R[0]);
|
|
1781
|
+
return se(y);
|
|
1782
|
+
},
|
|
1783
|
+
/** See {@link H2CHasher} */
|
|
1784
|
+
mapToCurve(J) {
|
|
1785
|
+
if (!Array.isArray(J))
|
|
1786
|
+
throw new Error("expected array of bigints");
|
|
1787
|
+
for (const $ of J)
|
|
1788
|
+
if (typeof $ != "bigint")
|
|
1789
|
+
throw new Error("expected array of bigints");
|
|
1790
|
+
return se(D(J));
|
|
1791
|
+
},
|
|
1792
|
+
// hash_to_scalar can produce 0: https://www.rfc-editor.org/errata/eid8393
|
|
1793
|
+
// RFC 9380, draft-irtf-cfrg-bbs-signatures-08
|
|
1794
|
+
hashToScalar(J, $) {
|
|
1795
|
+
const ce = H.Fn.ORDER, le = Object.assign({}, X, { p: ce, m: 1, DST: s._DST_scalar }, $);
|
|
1796
|
+
return fe(J, 1, le)[0][0];
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
})(je)), je;
|
|
1801
|
+
}
|
|
1802
|
+
var Xe;
|
|
1803
|
+
function st() {
|
|
1804
|
+
return Xe || (Xe = 1, (function(s) {
|
|
1805
|
+
Object.defineProperty(s, "__esModule", { value: !0 }), s.encodeToCurve = s.hashToCurve = s.secp256k1_hasher = s.schnorr = s.secp256k1 = void 0;
|
|
1806
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1807
|
+
const x = /* @__PURE__ */ Fe(), M = /* @__PURE__ */ xe(), m = /* @__PURE__ */ rt(), K = /* @__PURE__ */ ot(), T = /* @__PURE__ */ Ne(), ie = /* @__PURE__ */ Qe(), Q = /* @__PURE__ */ Ae(), ne = {
|
|
1808
|
+
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
1809
|
+
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
1810
|
+
h: BigInt(1),
|
|
1811
|
+
a: BigInt(0),
|
|
1812
|
+
b: BigInt(7),
|
|
1813
|
+
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
1814
|
+
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
1815
|
+
}, oe = {
|
|
1816
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1817
|
+
basises: [
|
|
1818
|
+
[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
|
|
1819
|
+
[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
|
|
1820
|
+
]
|
|
1821
|
+
}, fe = /* @__PURE__ */ BigInt(0), G = /* @__PURE__ */ BigInt(1), re = /* @__PURE__ */ BigInt(2);
|
|
1822
|
+
function H(S) {
|
|
1823
|
+
const v = ne.p, t = BigInt(3), a = BigInt(6), r = BigInt(11), e = BigInt(22), f = BigInt(23), g = BigInt(44), n = BigInt(88), i = S * S * S % v, c = i * i * S % v, h = (0, T.pow2)(c, t, v) * c % v, p = (0, T.pow2)(h, t, v) * c % v, C = (0, T.pow2)(p, re, v) * i % v, Z = (0, T.pow2)(C, r, v) * C % v, _ = (0, T.pow2)(Z, e, v) * Z % v, B = (0, T.pow2)(_, g, v) * _ % v, U = (0, T.pow2)(B, n, v) * B % v, Y = (0, T.pow2)(U, g, v) * _ % v, V = (0, T.pow2)(Y, t, v) * c % v, l = (0, T.pow2)(V, f, v) * Z % v, L = (0, T.pow2)(l, a, v) * i % v, ee = (0, T.pow2)(L, re, v);
|
|
1824
|
+
if (!j.eql(j.sqr(ee), S))
|
|
1825
|
+
throw new Error("Cannot find square root");
|
|
1826
|
+
return ee;
|
|
1827
|
+
}
|
|
1828
|
+
const j = (0, T.Field)(ne.p, { sqrt: H });
|
|
1829
|
+
s.secp256k1 = (0, m.createCurve)({ ...ne, Fp: j, lowS: !0, endo: oe }, x.sha256);
|
|
1830
|
+
const X = {};
|
|
1831
|
+
function D(S, ...v) {
|
|
1832
|
+
let t = X[S];
|
|
1833
|
+
if (t === void 0) {
|
|
1834
|
+
const a = (0, x.sha256)((0, Q.utf8ToBytes)(S));
|
|
1835
|
+
t = (0, Q.concatBytes)(a, a), X[S] = t;
|
|
1836
|
+
}
|
|
1837
|
+
return (0, x.sha256)((0, Q.concatBytes)(t, ...v));
|
|
1838
|
+
}
|
|
1839
|
+
const se = (S) => S.toBytes(!0).slice(1), J = s.secp256k1.Point, $ = (S) => S % re === fe;
|
|
1840
|
+
function ce(S) {
|
|
1841
|
+
const { Fn: v, BASE: t } = J, a = (0, ie._normFnElement)(v, S), r = t.multiply(a);
|
|
1842
|
+
return { scalar: $(r.y) ? a : v.neg(a), bytes: se(r) };
|
|
1843
|
+
}
|
|
1844
|
+
function le(S) {
|
|
1845
|
+
const v = j;
|
|
1846
|
+
if (!v.isValidNot0(S))
|
|
1847
|
+
throw new Error("invalid x: Fail if x ≥ p");
|
|
1848
|
+
const t = v.create(S * S), a = v.create(t * S + BigInt(7));
|
|
1849
|
+
let r = v.sqrt(a);
|
|
1850
|
+
$(r) || (r = v.neg(r));
|
|
1851
|
+
const e = J.fromAffine({ x: S, y: r });
|
|
1852
|
+
return e.assertValidity(), e;
|
|
1853
|
+
}
|
|
1854
|
+
const R = Q.bytesToNumberBE;
|
|
1855
|
+
function y(...S) {
|
|
1856
|
+
return J.Fn.create(R(D("BIP0340/challenge", ...S)));
|
|
1857
|
+
}
|
|
1858
|
+
function A(S) {
|
|
1859
|
+
return ce(S).bytes;
|
|
1860
|
+
}
|
|
1861
|
+
function O(S, v, t = (0, M.randomBytes)(32)) {
|
|
1862
|
+
const { Fn: a } = J, r = (0, Q.ensureBytes)("message", S), { bytes: e, scalar: f } = ce(v), g = (0, Q.ensureBytes)("auxRand", t, 32), n = a.toBytes(f ^ R(D("BIP0340/aux", g))), i = D("BIP0340/nonce", n, e, r), { bytes: c, scalar: h } = ce(i), p = y(c, e, r), C = new Uint8Array(64);
|
|
1863
|
+
if (C.set(c, 0), C.set(a.toBytes(a.create(h + p * f)), 32), !q(C, r, e))
|
|
1864
|
+
throw new Error("sign: Invalid signature produced");
|
|
1865
|
+
return C;
|
|
1866
|
+
}
|
|
1867
|
+
function q(S, v, t) {
|
|
1868
|
+
const { Fn: a, BASE: r } = J, e = (0, Q.ensureBytes)("signature", S, 64), f = (0, Q.ensureBytes)("message", v), g = (0, Q.ensureBytes)("publicKey", t, 32);
|
|
1869
|
+
try {
|
|
1870
|
+
const n = le(R(g)), i = R(e.subarray(0, 32));
|
|
1871
|
+
if (!(0, Q.inRange)(i, G, ne.p))
|
|
1872
|
+
return !1;
|
|
1873
|
+
const c = R(e.subarray(32, 64));
|
|
1874
|
+
if (!(0, Q.inRange)(c, G, ne.n))
|
|
1875
|
+
return !1;
|
|
1876
|
+
const h = y(a.toBytes(i), se(n), f), p = r.multiplyUnsafe(c).add(n.multiplyUnsafe(a.neg(h))), { x: C, y: Z } = p.toAffine();
|
|
1877
|
+
return !(p.is0() || !$(Z) || C !== i);
|
|
1878
|
+
} catch {
|
|
1879
|
+
return !1;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
s.schnorr = (() => {
|
|
1883
|
+
const t = (r = (0, M.randomBytes)(48)) => (0, T.mapHashToField)(r, ne.n);
|
|
1884
|
+
s.secp256k1.utils.randomSecretKey;
|
|
1885
|
+
function a(r) {
|
|
1886
|
+
const e = t(r);
|
|
1887
|
+
return { secretKey: e, publicKey: A(e) };
|
|
1888
|
+
}
|
|
1889
|
+
return {
|
|
1890
|
+
keygen: a,
|
|
1891
|
+
getPublicKey: A,
|
|
1892
|
+
sign: O,
|
|
1893
|
+
verify: q,
|
|
1894
|
+
Point: J,
|
|
1895
|
+
utils: {
|
|
1896
|
+
randomSecretKey: t,
|
|
1897
|
+
randomPrivateKey: t,
|
|
1898
|
+
taggedHash: D,
|
|
1899
|
+
// TODO: remove
|
|
1900
|
+
lift_x: le,
|
|
1901
|
+
pointToBytes: se,
|
|
1902
|
+
numberToBytesBE: Q.numberToBytesBE,
|
|
1903
|
+
bytesToNumberBE: Q.bytesToNumberBE,
|
|
1904
|
+
mod: T.mod
|
|
1905
|
+
},
|
|
1906
|
+
lengths: {
|
|
1907
|
+
secretKey: 32,
|
|
1908
|
+
publicKey: 32,
|
|
1909
|
+
publicKeyHasPrefix: !1,
|
|
1910
|
+
signature: 64,
|
|
1911
|
+
seed: 48
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
})();
|
|
1915
|
+
const z = (0, K.isogenyMap)(j, [
|
|
1916
|
+
// xNum
|
|
1917
|
+
[
|
|
1918
|
+
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
1919
|
+
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
1920
|
+
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
1921
|
+
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
1922
|
+
],
|
|
1923
|
+
// xDen
|
|
1924
|
+
[
|
|
1925
|
+
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
1926
|
+
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
1927
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
1928
|
+
// LAST 1
|
|
1929
|
+
],
|
|
1930
|
+
// yNum
|
|
1931
|
+
[
|
|
1932
|
+
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
1933
|
+
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
1934
|
+
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
1935
|
+
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
1936
|
+
],
|
|
1937
|
+
// yDen
|
|
1938
|
+
[
|
|
1939
|
+
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
1940
|
+
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
1941
|
+
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
1942
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
1943
|
+
// LAST 1
|
|
1944
|
+
]
|
|
1945
|
+
].map((S) => S.map((v) => BigInt(v)))), F = (0, ie.mapToCurveSimpleSWU)(j, {
|
|
1946
|
+
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
1947
|
+
B: BigInt("1771"),
|
|
1948
|
+
Z: j.create(BigInt("-11"))
|
|
1949
|
+
});
|
|
1950
|
+
s.secp256k1_hasher = (0, K.createHasher)(s.secp256k1.Point, (S) => {
|
|
1951
|
+
const { x: v, y: t } = F(j.create(S[0]));
|
|
1952
|
+
return z(v, t);
|
|
1953
|
+
}, {
|
|
1954
|
+
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
1955
|
+
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
1956
|
+
p: j.ORDER,
|
|
1957
|
+
m: 1,
|
|
1958
|
+
k: 128,
|
|
1959
|
+
expand: "xmd",
|
|
1960
|
+
hash: x.sha256
|
|
1961
|
+
}), s.hashToCurve = s.secp256k1_hasher.hashToCurve, s.encodeToCurve = s.secp256k1_hasher.encodeToCurve;
|
|
1962
|
+
})(He)), He;
|
|
1963
|
+
}
|
|
1964
|
+
var P = {}, We;
|
|
1965
|
+
function it() {
|
|
1966
|
+
if (We) return P;
|
|
1967
|
+
We = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.isHash = P.validateObject = P.memoized = P.notImplemented = P.createHmacDrbg = P.bitMask = P.bitSet = P.bitGet = P.bitLen = P.aInRange = P.inRange = P.asciiToBytes = P.copyBytes = P.equalBytes = P.ensureBytes = P.numberToVarBytesBE = P.numberToBytesLE = P.numberToBytesBE = P.bytesToNumberLE = P.bytesToNumberBE = P.hexToNumber = P.numberToHexUnpadded = P.abool = P.utf8ToBytes = P.randomBytes = P.isBytes = P.hexToBytes = P.concatBytes = P.bytesToUtf8 = P.bytesToHex = P.anumber = P.abytes = void 0;
|
|
1968
|
+
const s = /* @__PURE__ */ Ae();
|
|
1969
|
+
return P.abytes = s.abytes, P.anumber = s.anumber, P.bytesToHex = s.bytesToHex, P.bytesToUtf8 = s.bytesToUtf8, P.concatBytes = s.concatBytes, P.hexToBytes = s.hexToBytes, P.isBytes = s.isBytes, P.randomBytes = s.randomBytes, P.utf8ToBytes = s.utf8ToBytes, P.abool = s.abool, P.numberToHexUnpadded = s.numberToHexUnpadded, P.hexToNumber = s.hexToNumber, P.bytesToNumberBE = s.bytesToNumberBE, P.bytesToNumberLE = s.bytesToNumberLE, P.numberToBytesBE = s.numberToBytesBE, P.numberToBytesLE = s.numberToBytesLE, P.numberToVarBytesBE = s.numberToVarBytesBE, P.ensureBytes = s.ensureBytes, P.equalBytes = s.equalBytes, P.copyBytes = s.copyBytes, P.asciiToBytes = s.asciiToBytes, P.inRange = s.inRange, P.aInRange = s.aInRange, P.bitLen = s.bitLen, P.bitGet = s.bitGet, P.bitSet = s.bitSet, P.bitMask = s.bitMask, P.createHmacDrbg = s.createHmacDrbg, P.notImplemented = s.notImplemented, P.memoized = s.memoized, P.validateObject = s.validateObject, P.isHash = s.isHash, P;
|
|
1970
|
+
}
|
|
1971
|
+
var Ge;
|
|
1972
|
+
function ct() {
|
|
1973
|
+
if (Ge) return be;
|
|
1974
|
+
Ge = 1;
|
|
1975
|
+
var s = /* @__PURE__ */ st(), x = /* @__PURE__ */ Ne(), M = /* @__PURE__ */ it();
|
|
1976
|
+
function m(o) {
|
|
1977
|
+
var u = /* @__PURE__ */ Object.create(null);
|
|
1978
|
+
return o && Object.keys(o).forEach(function(b) {
|
|
1979
|
+
if (b !== "default") {
|
|
1980
|
+
var I = Object.getOwnPropertyDescriptor(o, b);
|
|
1981
|
+
Object.defineProperty(u, b, I.get ? I : {
|
|
1982
|
+
enumerable: !0,
|
|
1983
|
+
get: function() {
|
|
1984
|
+
return o[b];
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
}), u.default = o, Object.freeze(u);
|
|
1989
|
+
}
|
|
1990
|
+
var K = /* @__PURE__ */ m(x), T = /* @__PURE__ */ m(M);
|
|
1991
|
+
const ie = s.secp256k1.ProjectivePoint, Q = "Expected Private", ne = "Expected Point", oe = "Expected Tweak", fe = "Expected Hash", G = "Expected Signature", re = "Expected Extra Data (32 bytes)", H = "Expected Scalar", j = "Bad Recovery Id", X = 32, D = 32, se = new Uint8Array([
|
|
1992
|
+
255,
|
|
1993
|
+
255,
|
|
1994
|
+
255,
|
|
1995
|
+
255,
|
|
1996
|
+
255,
|
|
1997
|
+
255,
|
|
1998
|
+
255,
|
|
1999
|
+
255,
|
|
2000
|
+
255,
|
|
2001
|
+
255,
|
|
2002
|
+
255,
|
|
2003
|
+
255,
|
|
2004
|
+
255,
|
|
2005
|
+
255,
|
|
2006
|
+
255,
|
|
2007
|
+
254,
|
|
2008
|
+
186,
|
|
2009
|
+
174,
|
|
2010
|
+
220,
|
|
2011
|
+
230,
|
|
2012
|
+
175,
|
|
2013
|
+
72,
|
|
2014
|
+
160,
|
|
2015
|
+
59,
|
|
2016
|
+
191,
|
|
2017
|
+
210,
|
|
2018
|
+
94,
|
|
2019
|
+
140,
|
|
2020
|
+
208,
|
|
2021
|
+
54,
|
|
2022
|
+
65,
|
|
2023
|
+
65
|
|
2024
|
+
]), J = 32, $ = new Uint8Array(32), ce = new Uint8Array([
|
|
2025
|
+
0,
|
|
2026
|
+
0,
|
|
2027
|
+
0,
|
|
2028
|
+
0,
|
|
2029
|
+
0,
|
|
2030
|
+
0,
|
|
2031
|
+
0,
|
|
2032
|
+
0,
|
|
2033
|
+
0,
|
|
2034
|
+
0,
|
|
2035
|
+
0,
|
|
2036
|
+
0,
|
|
2037
|
+
0,
|
|
2038
|
+
0,
|
|
2039
|
+
0,
|
|
2040
|
+
1,
|
|
2041
|
+
69,
|
|
2042
|
+
81,
|
|
2043
|
+
35,
|
|
2044
|
+
25,
|
|
2045
|
+
80,
|
|
2046
|
+
183,
|
|
2047
|
+
95,
|
|
2048
|
+
196,
|
|
2049
|
+
64,
|
|
2050
|
+
45,
|
|
2051
|
+
161,
|
|
2052
|
+
114,
|
|
2053
|
+
47,
|
|
2054
|
+
201,
|
|
2055
|
+
186,
|
|
2056
|
+
238
|
|
2057
|
+
]), le = BigInt(1);
|
|
2058
|
+
function R(o) {
|
|
2059
|
+
return o instanceof Uint8Array;
|
|
2060
|
+
}
|
|
2061
|
+
function y(o, u) {
|
|
2062
|
+
for (let b = 0; b < 32; ++b)
|
|
2063
|
+
if (o[b] !== u[b])
|
|
2064
|
+
return o[b] < u[b] ? -1 : 1;
|
|
2065
|
+
return 0;
|
|
2066
|
+
}
|
|
2067
|
+
function A(o) {
|
|
2068
|
+
return y(o, $) === 0;
|
|
2069
|
+
}
|
|
2070
|
+
function O(o) {
|
|
2071
|
+
return !(!(o instanceof Uint8Array) || o.length !== D || y(o, se) >= 0);
|
|
2072
|
+
}
|
|
2073
|
+
function q(o) {
|
|
2074
|
+
return o instanceof Uint8Array && o.length === 64 && y(o.subarray(0, 32), se) < 0 && y(o.subarray(32, 64), se) < 0;
|
|
2075
|
+
}
|
|
2076
|
+
function z(o) {
|
|
2077
|
+
return R(o) && o.length === 64 && y(o.subarray(0, 32), ce) < 0;
|
|
2078
|
+
}
|
|
2079
|
+
function F(o) {
|
|
2080
|
+
return !(A(o.subarray(0, 32)) || A(o.subarray(32, 64)));
|
|
2081
|
+
}
|
|
2082
|
+
function S(o) {
|
|
2083
|
+
return o instanceof Uint8Array && o.length === X;
|
|
2084
|
+
}
|
|
2085
|
+
function v(o) {
|
|
2086
|
+
return o === void 0 || o instanceof Uint8Array && o.length === J;
|
|
2087
|
+
}
|
|
2088
|
+
function t(o) {
|
|
2089
|
+
let u;
|
|
2090
|
+
if (typeof o == "bigint")
|
|
2091
|
+
u = o;
|
|
2092
|
+
else if (typeof o == "number" && Number.isSafeInteger(o) && o >= 0)
|
|
2093
|
+
u = BigInt(o);
|
|
2094
|
+
else if (typeof o == "string") {
|
|
2095
|
+
if (o.length !== 64)
|
|
2096
|
+
throw new Error("Expected 32 bytes of private scalar");
|
|
2097
|
+
u = T.hexToNumber(o);
|
|
2098
|
+
} else if (o instanceof Uint8Array) {
|
|
2099
|
+
if (o.length !== 32)
|
|
2100
|
+
throw new Error("Expected 32 bytes of private scalar");
|
|
2101
|
+
u = T.bytesToNumberBE(o);
|
|
2102
|
+
} else
|
|
2103
|
+
throw new TypeError("Expected valid private scalar");
|
|
2104
|
+
if (u < 0) throw new Error("Expected private scalar >= 0");
|
|
2105
|
+
return u;
|
|
2106
|
+
}
|
|
2107
|
+
function a(o) {
|
|
2108
|
+
return s.secp256k1.utils.normPrivateKeyToScalar(o);
|
|
2109
|
+
}
|
|
2110
|
+
function r(o, u) {
|
|
2111
|
+
const b = a(o), I = t(u), k = T.numberToBytesBE(K.mod(b + I, s.secp256k1.CURVE.n), 32);
|
|
2112
|
+
return s.secp256k1.utils.isValidPrivateKey(k) ? k : null;
|
|
2113
|
+
}
|
|
2114
|
+
function e(o, u) {
|
|
2115
|
+
const b = a(o), I = t(u), k = T.numberToBytesBE(K.mod(b - I, s.secp256k1.CURVE.n), 32);
|
|
2116
|
+
return s.secp256k1.utils.isValidPrivateKey(k) ? k : null;
|
|
2117
|
+
}
|
|
2118
|
+
function f(o) {
|
|
2119
|
+
const u = a(o), b = T.numberToBytesBE(s.secp256k1.CURVE.n - u, 32);
|
|
2120
|
+
return s.secp256k1.utils.isValidPrivateKey(b) ? b : null;
|
|
2121
|
+
}
|
|
2122
|
+
function g(o, u, b) {
|
|
2123
|
+
const I = p(o), k = t(u), W = ie.BASE.multiplyAndAddUnsafe(I, k, le);
|
|
2124
|
+
if (!W) throw new Error("Tweaked point at infinity");
|
|
2125
|
+
return W.toRawBytes(b);
|
|
2126
|
+
}
|
|
2127
|
+
function n(o, u, b) {
|
|
2128
|
+
const I = p(o), k = typeof u == "string" ? u : T.bytesToHex(u), W = T.hexToNumber(k);
|
|
2129
|
+
return I.multiply(W).toRawBytes(b);
|
|
2130
|
+
}
|
|
2131
|
+
function i(o, u) {
|
|
2132
|
+
return o === void 0 ? u !== void 0 ? _(u) : !0 : !!o;
|
|
2133
|
+
}
|
|
2134
|
+
function c(o) {
|
|
2135
|
+
try {
|
|
2136
|
+
return o();
|
|
2137
|
+
} catch {
|
|
2138
|
+
return null;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
function h(o) {
|
|
2142
|
+
return s.schnorr.utils.lift_x(T.bytesToNumberBE(o));
|
|
2143
|
+
}
|
|
2144
|
+
function p(o) {
|
|
2145
|
+
return o.length === 32 ? h(o) : ie.fromHex(o);
|
|
2146
|
+
}
|
|
2147
|
+
function C(o, u) {
|
|
2148
|
+
if (o.length === 32 !== u) return !1;
|
|
2149
|
+
try {
|
|
2150
|
+
return u ? !!h(o) : !!ie.fromHex(o);
|
|
2151
|
+
} catch {
|
|
2152
|
+
return !1;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
function Z(o) {
|
|
2156
|
+
return C(o, !1);
|
|
2157
|
+
}
|
|
2158
|
+
function _(o) {
|
|
2159
|
+
return C(o, !1) && o.length === 33;
|
|
2160
|
+
}
|
|
2161
|
+
function B(o) {
|
|
2162
|
+
return s.secp256k1.utils.isValidPrivateKey(o);
|
|
2163
|
+
}
|
|
2164
|
+
function U(o) {
|
|
2165
|
+
return C(o, !0);
|
|
2166
|
+
}
|
|
2167
|
+
function Y(o, u) {
|
|
2168
|
+
if (!U(o))
|
|
2169
|
+
throw new Error(ne);
|
|
2170
|
+
if (!O(u))
|
|
2171
|
+
throw new Error(oe);
|
|
2172
|
+
return c(() => {
|
|
2173
|
+
const b = g(o, u, !0);
|
|
2174
|
+
return { parity: b[0] % 2 === 1 ? 1 : 0, xOnlyPubkey: b.slice(1) };
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
function V(o) {
|
|
2178
|
+
if (!Z(o))
|
|
2179
|
+
throw new Error(ne);
|
|
2180
|
+
return o.slice(1, 33);
|
|
2181
|
+
}
|
|
2182
|
+
function l(o, u) {
|
|
2183
|
+
if (!B(o))
|
|
2184
|
+
throw new Error(Q);
|
|
2185
|
+
return c(
|
|
2186
|
+
() => s.secp256k1.getPublicKey(o, i(u))
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
function L(o) {
|
|
2190
|
+
if (!B(o))
|
|
2191
|
+
throw new Error(Q);
|
|
2192
|
+
return V(l(o));
|
|
2193
|
+
}
|
|
2194
|
+
function ee(o, u) {
|
|
2195
|
+
if (!Z(o))
|
|
2196
|
+
throw new Error(ne);
|
|
2197
|
+
return p(o).toRawBytes(i(u, o));
|
|
2198
|
+
}
|
|
2199
|
+
function ye(o, u, b) {
|
|
2200
|
+
if (!Z(o))
|
|
2201
|
+
throw new Error(ne);
|
|
2202
|
+
if (!O(u))
|
|
2203
|
+
throw new Error(oe);
|
|
2204
|
+
return c(
|
|
2205
|
+
() => n(o, u, i(b, o))
|
|
2206
|
+
);
|
|
2207
|
+
}
|
|
2208
|
+
function Be(o, u, b) {
|
|
2209
|
+
if (!Z(o) || !Z(u))
|
|
2210
|
+
throw new Error(ne);
|
|
2211
|
+
return c(() => {
|
|
2212
|
+
const I = p(o), k = p(u);
|
|
2213
|
+
return I.equals(k.negate()) ? null : I.add(k).toRawBytes(i(b, o));
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
function ve(o, u, b) {
|
|
2217
|
+
if (!Z(o))
|
|
2218
|
+
throw new Error(ne);
|
|
2219
|
+
if (!O(u))
|
|
2220
|
+
throw new Error(oe);
|
|
2221
|
+
return c(
|
|
2222
|
+
() => g(o, u, i(b, o))
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
function _e(o, u) {
|
|
2226
|
+
if (!B(o))
|
|
2227
|
+
throw new Error(Q);
|
|
2228
|
+
if (!O(u))
|
|
2229
|
+
throw new Error(oe);
|
|
2230
|
+
return c(() => r(o, u));
|
|
2231
|
+
}
|
|
2232
|
+
function te(o, u) {
|
|
2233
|
+
if (!B(o))
|
|
2234
|
+
throw new Error(Q);
|
|
2235
|
+
if (!O(u))
|
|
2236
|
+
throw new Error(oe);
|
|
2237
|
+
return c(() => e(o, u));
|
|
2238
|
+
}
|
|
2239
|
+
function Re(o) {
|
|
2240
|
+
if (!B(o))
|
|
2241
|
+
throw new Error(Q);
|
|
2242
|
+
return f(o);
|
|
2243
|
+
}
|
|
2244
|
+
function Oe(o, u, b) {
|
|
2245
|
+
if (!B(u))
|
|
2246
|
+
throw new Error(Q);
|
|
2247
|
+
if (!S(o))
|
|
2248
|
+
throw new Error(H);
|
|
2249
|
+
if (!v(b))
|
|
2250
|
+
throw new Error(re);
|
|
2251
|
+
return s.secp256k1.sign(o, u, { extraEntropy: b }).toCompactRawBytes();
|
|
2252
|
+
}
|
|
2253
|
+
function ue(o, u, b) {
|
|
2254
|
+
if (!B(u))
|
|
2255
|
+
throw new Error(Q);
|
|
2256
|
+
if (!S(o))
|
|
2257
|
+
throw new Error(H);
|
|
2258
|
+
if (!v(b))
|
|
2259
|
+
throw new Error(re);
|
|
2260
|
+
const I = s.secp256k1.sign(o, u, { extraEntropy: b });
|
|
2261
|
+
return {
|
|
2262
|
+
signature: I.toCompactRawBytes(),
|
|
2263
|
+
recoveryId: I.recovery
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
2266
|
+
function E(o, u, b) {
|
|
2267
|
+
if (!B(u))
|
|
2268
|
+
throw new Error(Q);
|
|
2269
|
+
if (!S(o))
|
|
2270
|
+
throw new Error(H);
|
|
2271
|
+
if (!v(b))
|
|
2272
|
+
throw new Error(re);
|
|
2273
|
+
return s.schnorr.sign(o, u, b);
|
|
2274
|
+
}
|
|
2275
|
+
function w(o, u, b, I) {
|
|
2276
|
+
if (!S(o))
|
|
2277
|
+
throw new Error(fe);
|
|
2278
|
+
if (!q(u) || !F(u))
|
|
2279
|
+
throw new Error(G);
|
|
2280
|
+
if (b & 2 && !z(u))
|
|
2281
|
+
throw new Error(j);
|
|
2282
|
+
if (!U(u.subarray(0, 32)))
|
|
2283
|
+
throw new Error(G);
|
|
2284
|
+
const W = s.secp256k1.Signature.fromCompact(u).addRecoveryBit(b).recoverPublicKey(o);
|
|
2285
|
+
if (!W) throw new Error(G);
|
|
2286
|
+
return W.toRawBytes(i(I));
|
|
2287
|
+
}
|
|
2288
|
+
function d(o, u, b, I) {
|
|
2289
|
+
if (!Z(u))
|
|
2290
|
+
throw new Error(ne);
|
|
2291
|
+
if (!q(b))
|
|
2292
|
+
throw new Error(G);
|
|
2293
|
+
if (!S(o))
|
|
2294
|
+
throw new Error(H);
|
|
2295
|
+
return s.secp256k1.verify(b, o, u, { lowS: I });
|
|
2296
|
+
}
|
|
2297
|
+
function N(o, u, b) {
|
|
2298
|
+
if (!U(u))
|
|
2299
|
+
throw new Error(ne);
|
|
2300
|
+
if (!q(b))
|
|
2301
|
+
throw new Error(G);
|
|
2302
|
+
if (!S(o))
|
|
2303
|
+
throw new Error(H);
|
|
2304
|
+
return s.schnorr.verify(b, o, u);
|
|
2305
|
+
}
|
|
2306
|
+
return be.isPoint = Z, be.isPointCompressed = _, be.isPrivate = B, be.isXOnlyPoint = U, be.pointAdd = Be, be.pointAddScalar = ve, be.pointCompress = ee, be.pointFromScalar = l, be.pointMultiply = ye, be.privateAdd = _e, be.privateNegate = Re, be.privateSub = te, be.recover = w, be.sign = Oe, be.signRecoverable = ue, be.signSchnorr = E, be.verify = d, be.verifySchnorr = N, be.xOnlyPointAddTweak = Y, be.xOnlyPointFromPoint = V, be.xOnlyPointFromScalar = L, be;
|
|
2307
|
+
}
|
|
2308
|
+
var Je = ct();
|
|
2309
|
+
const at = /* @__PURE__ */ $e(Je), ft = /* @__PURE__ */ et({
|
|
2310
|
+
__proto__: null,
|
|
2311
|
+
default: at
|
|
2312
|
+
}, [Je]);
|
|
2313
|
+
export {
|
|
2314
|
+
ft as i
|
|
2315
|
+
};
|
|
2316
|
+
//# sourceMappingURL=index3.js.map
|