@pufferfinance/puffer-sdk 1.23.1 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/puffer-client-helpers.cjs +1 -1
- package/dist/api/puffer-client-helpers.cjs.map +1 -1
- package/dist/api/puffer-client-helpers.js +3 -3
- package/dist/api/puffer-client-helpers.js.map +1 -1
- package/dist/api/puffer-client.cjs +1 -1
- package/dist/api/puffer-client.js +2 -2
- package/dist/ccip-FdkpGaX4.cjs +2 -0
- package/dist/ccip-FdkpGaX4.cjs.map +1 -0
- package/dist/{ccip-CiQCCFUl.js → ccip-w5ez1DCx.js} +43 -39
- package/dist/ccip-w5ez1DCx.js.map +1 -0
- package/dist/chains/constants.cjs +1 -1
- package/dist/chains/constants.d.ts +2 -1
- package/dist/chains/constants.js +1 -1
- package/dist/{constants-BaHwPdbi.js → constants-BweLzNUt.js} +690 -616
- package/dist/constants-BweLzNUt.js.map +1 -0
- package/dist/constants-JN89aXws.cjs +9 -0
- package/dist/constants-JN89aXws.cjs.map +1 -0
- package/dist/contracts/addresses.cjs +1 -1
- package/dist/contracts/addresses.js +1 -1
- package/dist/contracts/handlers/carrot-staking-handler.cjs +1 -1
- package/dist/contracts/handlers/carrot-staking-handler.d.ts +368 -352
- package/dist/contracts/handlers/carrot-staking-handler.js +2 -2
- package/dist/contracts/handlers/concrete-vault-handler.cjs +1 -1
- package/dist/contracts/handlers/concrete-vault-handler.d.ts +368 -352
- package/dist/contracts/handlers/concrete-vault-handler.js +2 -2
- package/dist/contracts/handlers/distributor-handler.cjs +1 -1
- package/dist/contracts/handlers/distributor-handler.d.ts +368 -352
- package/dist/contracts/handlers/distributor-handler.js +2 -2
- package/dist/contracts/handlers/erc20-permit-handler.cjs +1 -1
- package/dist/contracts/handlers/erc20-permit-handler.cjs.map +1 -1
- package/dist/contracts/handlers/erc20-permit-handler.d.ts +368 -352
- package/dist/contracts/handlers/erc20-permit-handler.js +3 -3
- package/dist/contracts/handlers/erc20-permit-handler.js.map +1 -1
- package/dist/contracts/handlers/guardian-module-handler.cjs +1 -1
- package/dist/contracts/handlers/guardian-module-handler.d.ts +368 -352
- package/dist/contracts/handlers/guardian-module-handler.js +2 -2
- package/dist/contracts/handlers/institutional-access-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/institutional-access-manager-handler.d.ts +368 -352
- package/dist/contracts/handlers/institutional-access-manager-handler.js +3 -3
- package/dist/contracts/handlers/institutional-vault-handler.cjs +1 -1
- package/dist/contracts/handlers/institutional-vault-handler.d.ts +368 -352
- package/dist/contracts/handlers/institutional-vault-handler.js +2 -2
- package/dist/contracts/handlers/l1-reward-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/l1-reward-manager-handler.d.ts +368 -352
- package/dist/contracts/handlers/l1-reward-manager-handler.js +2 -2
- package/dist/contracts/handlers/l2-reward-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/l2-reward-manager-handler.d.ts +368 -352
- package/dist/contracts/handlers/l2-reward-manager-handler.js +2 -2
- package/dist/contracts/handlers/mtw-carrot-handler.cjs +1 -1
- package/dist/contracts/handlers/mtw-carrot-handler.d.ts +368 -352
- package/dist/contracts/handlers/mtw-carrot-handler.js +2 -2
- package/dist/contracts/handlers/nucleus-accountant-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-accountant-handler.d.ts +368 -352
- package/dist/contracts/handlers/nucleus-accountant-handler.js +1 -1
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.d.ts +368 -352
- package/dist/contracts/handlers/nucleus-atomic-queue-handler.js +2 -2
- package/dist/contracts/handlers/nucleus-boring-vault-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-boring-vault-handler.d.ts +368 -352
- package/dist/contracts/handlers/nucleus-boring-vault-handler.js +2 -2
- package/dist/contracts/handlers/nucleus-teller-handler.cjs +1 -1
- package/dist/contracts/handlers/nucleus-teller-handler.d.ts +368 -352
- package/dist/contracts/handlers/nucleus-teller-handler.js +2 -2
- package/dist/contracts/handlers/puf-locker-handler.cjs +1 -1
- package/dist/contracts/handlers/puf-locker-handler.d.ts +368 -352
- package/dist/contracts/handlers/puf-locker-handler.js +2 -2
- package/dist/contracts/handlers/puffer-depositor-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-depositor-handler.d.ts +368 -352
- package/dist/contracts/handlers/puffer-depositor-handler.js +2 -2
- package/dist/contracts/handlers/puffer-l2-depositor-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-l2-depositor-handler.d.ts +368 -352
- package/dist/contracts/handlers/puffer-l2-depositor-handler.js +2 -2
- package/dist/contracts/handlers/puffer-oracle-v2-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-oracle-v2-handler.d.ts +368 -352
- package/dist/contracts/handlers/puffer-oracle-v2-handler.js +2 -2
- package/dist/contracts/handlers/puffer-protocol-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-protocol-handler.d.ts +368 -352
- package/dist/contracts/handlers/puffer-protocol-handler.js +2 -2
- package/dist/contracts/handlers/puffer-vault-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-vault-handler.d.ts +368 -352
- package/dist/contracts/handlers/puffer-vault-handler.js +2 -2
- package/dist/contracts/handlers/puffer-withdrawal-manager-handler.cjs +1 -1
- package/dist/contracts/handlers/puffer-withdrawal-manager-handler.d.ts +368 -352
- package/dist/contracts/handlers/puffer-withdrawal-manager-handler.js +2 -2
- package/dist/contracts/handlers/validator-ticket-handler.cjs +1 -1
- package/dist/contracts/handlers/validator-ticket-handler.d.ts +368 -352
- package/dist/contracts/handlers/validator-ticket-handler.js +2 -2
- package/dist/contracts/tokens.cjs +1 -1
- package/dist/contracts/tokens.cjs.map +1 -1
- package/dist/contracts/tokens.js +7 -6
- package/dist/contracts/tokens.js.map +1 -1
- package/dist/contracts/vaults-addresses.cjs +1 -1
- package/dist/contracts/vaults-addresses.js +1 -1
- package/dist/createWalletClient-CYva1_XM.js +3262 -0
- package/dist/createWalletClient-CYva1_XM.js.map +1 -0
- package/dist/createWalletClient-LeyDLKOH.cjs +5 -0
- package/dist/createWalletClient-LeyDLKOH.cjs.map +1 -0
- package/dist/{getContract-DGV8J5xI.js → getContract-BES7gSby.js} +2 -2
- package/dist/getContract-BES7gSby.js.map +1 -0
- package/dist/{getContract-RNLlK54b.cjs → getContract-F-fd_vf7.cjs} +2 -2
- package/dist/{getContract-DGV8J5xI.js.map → getContract-F-fd_vf7.cjs.map} +1 -1
- package/dist/localBatchGatewayRequest-CCdxn5t3.js +90 -0
- package/dist/localBatchGatewayRequest-CCdxn5t3.js.map +1 -0
- package/dist/localBatchGatewayRequest-DCWU6kQW.cjs +2 -0
- package/dist/localBatchGatewayRequest-DCWU6kQW.cjs.map +1 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +1 -1
- package/dist/secp256k1-DGP4Y7VW.js +1291 -0
- package/dist/secp256k1-DGP4Y7VW.js.map +1 -0
- package/dist/secp256k1-QOxLqUEc.cjs +2 -0
- package/dist/secp256k1-QOxLqUEc.cjs.map +1 -0
- package/dist/utils/version.cjs +1 -1
- package/dist/utils/version.js +1 -1
- package/dist/writeContract-Cqc9vxbU.cjs +36 -0
- package/dist/writeContract-Cqc9vxbU.cjs.map +1 -0
- package/dist/{writeContract-BU3yK-Xj.js → writeContract-QAArm5iD.js} +1894 -1361
- package/dist/writeContract-QAArm5iD.js.map +1 -0
- package/package.json +2 -2
- package/dist/ccip-CiQCCFUl.js.map +0 -1
- package/dist/ccip-DIWF4nDh.cjs +0 -2
- package/dist/ccip-DIWF4nDh.cjs.map +0 -1
- package/dist/constants-BaHwPdbi.js.map +0 -1
- package/dist/constants-c-vATmlG.cjs +0 -9
- package/dist/constants-c-vATmlG.cjs.map +0 -1
- package/dist/createWalletClient-D74YRepQ.js +0 -3290
- package/dist/createWalletClient-D74YRepQ.js.map +0 -1
- package/dist/createWalletClient-DKSH6l9_.cjs +0 -6
- package/dist/createWalletClient-DKSH6l9_.cjs.map +0 -1
- package/dist/getContract-RNLlK54b.cjs.map +0 -1
- package/dist/secp256k1-B-LxKJrQ.js +0 -1340
- package/dist/secp256k1-B-LxKJrQ.js.map +0 -1
- package/dist/secp256k1-CC-cv1vD.cjs +0 -2
- package/dist/secp256k1-CC-cv1vD.cjs.map +0 -1
- package/dist/writeContract-BU3yK-Xj.js.map +0 -1
- package/dist/writeContract-CKqv1dsa.cjs +0 -32
- package/dist/writeContract-CKqv1dsa.cjs.map +0 -1
|
@@ -0,0 +1,1291 @@
|
|
|
1
|
+
import { f as xt, g as Tt, j as at, k as st, l as F, H as Jt, m as te, o as ee, q as ne, r as qt, u as re, v as oe, w as ie } from "./constants-BweLzNUt.js";
|
|
2
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
const St = /* @__PURE__ */ BigInt(0), Et = /* @__PURE__ */ BigInt(1);
|
|
4
|
+
function lt(e, n) {
|
|
5
|
+
if (typeof n != "boolean")
|
|
6
|
+
throw new Error(e + " boolean expected, got " + n);
|
|
7
|
+
}
|
|
8
|
+
function ft(e) {
|
|
9
|
+
const n = e.toString(16);
|
|
10
|
+
return n.length & 1 ? "0" + n : n;
|
|
11
|
+
}
|
|
12
|
+
function kt(e) {
|
|
13
|
+
if (typeof e != "string")
|
|
14
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
15
|
+
return e === "" ? St : BigInt("0x" + e);
|
|
16
|
+
}
|
|
17
|
+
function dt(e) {
|
|
18
|
+
return kt(st(e));
|
|
19
|
+
}
|
|
20
|
+
function jt(e) {
|
|
21
|
+
return at(e), kt(st(Uint8Array.from(e).reverse()));
|
|
22
|
+
}
|
|
23
|
+
function It(e, n) {
|
|
24
|
+
return xt(e.toString(16).padStart(n * 2, "0"));
|
|
25
|
+
}
|
|
26
|
+
function Ut(e, n) {
|
|
27
|
+
return It(e, n).reverse();
|
|
28
|
+
}
|
|
29
|
+
function $(e, n, t) {
|
|
30
|
+
let r;
|
|
31
|
+
if (typeof n == "string")
|
|
32
|
+
try {
|
|
33
|
+
r = xt(n);
|
|
34
|
+
} catch (i) {
|
|
35
|
+
throw new Error(e + " must be hex string or Uint8Array, cause: " + i);
|
|
36
|
+
}
|
|
37
|
+
else if (Tt(n))
|
|
38
|
+
r = Uint8Array.from(n);
|
|
39
|
+
else
|
|
40
|
+
throw new Error(e + " must be hex string or Uint8Array");
|
|
41
|
+
const s = r.length;
|
|
42
|
+
if (typeof t == "number" && s !== t)
|
|
43
|
+
throw new Error(e + " of length " + t + " expected, got " + s);
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
const mt = (e) => typeof e == "bigint" && St <= e;
|
|
47
|
+
function se(e, n, t) {
|
|
48
|
+
return mt(e) && mt(n) && mt(t) && n <= e && e < t;
|
|
49
|
+
}
|
|
50
|
+
function fe(e, n, t, r) {
|
|
51
|
+
if (!se(n, t, r))
|
|
52
|
+
throw new Error("expected valid " + e + ": " + t + " <= n < " + r + ", got " + n);
|
|
53
|
+
}
|
|
54
|
+
function ce(e) {
|
|
55
|
+
let n;
|
|
56
|
+
for (n = 0; e > St; e >>= Et, n += 1)
|
|
57
|
+
;
|
|
58
|
+
return n;
|
|
59
|
+
}
|
|
60
|
+
const ht = (e) => (Et << BigInt(e)) - Et;
|
|
61
|
+
function ae(e, n, t) {
|
|
62
|
+
if (typeof e != "number" || e < 2)
|
|
63
|
+
throw new Error("hashLen must be a number");
|
|
64
|
+
if (typeof n != "number" || n < 2)
|
|
65
|
+
throw new Error("qByteLen must be a number");
|
|
66
|
+
if (typeof t != "function")
|
|
67
|
+
throw new Error("hmacFn must be a function");
|
|
68
|
+
const r = (S) => new Uint8Array(S), s = (S) => Uint8Array.of(S);
|
|
69
|
+
let i = r(e), o = r(e), a = 0;
|
|
70
|
+
const l = () => {
|
|
71
|
+
i.fill(1), o.fill(0), a = 0;
|
|
72
|
+
}, g = (...S) => t(o, i, ...S), f = (S = r(0)) => {
|
|
73
|
+
o = g(s(0), S), i = g(), S.length !== 0 && (o = g(s(1), S), i = g());
|
|
74
|
+
}, E = () => {
|
|
75
|
+
if (a++ >= 1e3)
|
|
76
|
+
throw new Error("drbg: tried 1000 values");
|
|
77
|
+
let S = 0;
|
|
78
|
+
const _ = [];
|
|
79
|
+
for (; S < n; ) {
|
|
80
|
+
i = g();
|
|
81
|
+
const N = i.slice();
|
|
82
|
+
_.push(N), S += i.length;
|
|
83
|
+
}
|
|
84
|
+
return F(..._);
|
|
85
|
+
};
|
|
86
|
+
return (S, _) => {
|
|
87
|
+
l(), f(S);
|
|
88
|
+
let N;
|
|
89
|
+
for (; !(N = _(E())); )
|
|
90
|
+
f();
|
|
91
|
+
return l(), N;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function Nt(e, n, t = {}) {
|
|
95
|
+
if (!e || typeof e != "object")
|
|
96
|
+
throw new Error("expected valid options object");
|
|
97
|
+
function r(s, i, o) {
|
|
98
|
+
const a = e[s];
|
|
99
|
+
if (o && a === void 0)
|
|
100
|
+
return;
|
|
101
|
+
const l = typeof a;
|
|
102
|
+
if (l !== i || a === null)
|
|
103
|
+
throw new Error(`param "${s}" is invalid: expected ${i}, got ${l}`);
|
|
104
|
+
}
|
|
105
|
+
Object.entries(n).forEach(([s, i]) => r(s, i, !1)), Object.entries(t).forEach(([s, i]) => r(s, i, !0));
|
|
106
|
+
}
|
|
107
|
+
function At(e) {
|
|
108
|
+
const n = /* @__PURE__ */ new WeakMap();
|
|
109
|
+
return (t, ...r) => {
|
|
110
|
+
const s = n.get(t);
|
|
111
|
+
if (s !== void 0)
|
|
112
|
+
return s;
|
|
113
|
+
const i = e(t, ...r);
|
|
114
|
+
return n.set(t, i), i;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
class Mt extends Jt {
|
|
118
|
+
constructor(n, t) {
|
|
119
|
+
super(), this.finished = !1, this.destroyed = !1, te(n);
|
|
120
|
+
const r = ee(t);
|
|
121
|
+
if (this.iHash = n.create(), typeof this.iHash.update != "function")
|
|
122
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
123
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
124
|
+
const s = this.blockLen, i = new Uint8Array(s);
|
|
125
|
+
i.set(r.length > s ? n.create().update(r).digest() : r);
|
|
126
|
+
for (let o = 0; o < i.length; o++)
|
|
127
|
+
i[o] ^= 54;
|
|
128
|
+
this.iHash.update(i), this.oHash = n.create();
|
|
129
|
+
for (let o = 0; o < i.length; o++)
|
|
130
|
+
i[o] ^= 106;
|
|
131
|
+
this.oHash.update(i), ne(i);
|
|
132
|
+
}
|
|
133
|
+
update(n) {
|
|
134
|
+
return qt(this), this.iHash.update(n), this;
|
|
135
|
+
}
|
|
136
|
+
digestInto(n) {
|
|
137
|
+
qt(this), at(n, this.outputLen), this.finished = !0, this.iHash.digestInto(n), this.oHash.update(n), this.oHash.digestInto(n), this.destroy();
|
|
138
|
+
}
|
|
139
|
+
digest() {
|
|
140
|
+
const n = new Uint8Array(this.oHash.outputLen);
|
|
141
|
+
return this.digestInto(n), n;
|
|
142
|
+
}
|
|
143
|
+
_cloneInto(n) {
|
|
144
|
+
n || (n = Object.create(Object.getPrototypeOf(this), {}));
|
|
145
|
+
const { oHash: t, iHash: r, finished: s, destroyed: i, blockLen: o, outputLen: a } = this;
|
|
146
|
+
return n = n, n.finished = s, n.destroyed = i, n.blockLen = o, n.outputLen = a, n.oHash = t._cloneInto(n.oHash), n.iHash = r._cloneInto(n.iHash), n;
|
|
147
|
+
}
|
|
148
|
+
clone() {
|
|
149
|
+
return this._cloneInto();
|
|
150
|
+
}
|
|
151
|
+
destroy() {
|
|
152
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const $t = (e, n, t) => new Mt(e, n).update(t).digest();
|
|
156
|
+
$t.create = (e, n) => new Mt(e, n);
|
|
157
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
158
|
+
const j = BigInt(0), k = BigInt(1), P = /* @__PURE__ */ BigInt(2), le = /* @__PURE__ */ BigInt(3), Ct = /* @__PURE__ */ BigInt(4), Vt = /* @__PURE__ */ BigInt(5), Kt = /* @__PURE__ */ BigInt(8);
|
|
159
|
+
function C(e, n) {
|
|
160
|
+
const t = e % n;
|
|
161
|
+
return t >= j ? t : n + t;
|
|
162
|
+
}
|
|
163
|
+
function M(e, n, t) {
|
|
164
|
+
let r = e;
|
|
165
|
+
for (; n-- > j; )
|
|
166
|
+
r *= r, r %= t;
|
|
167
|
+
return r;
|
|
168
|
+
}
|
|
169
|
+
function _t(e, n) {
|
|
170
|
+
if (e === j)
|
|
171
|
+
throw new Error("invert: expected non-zero number");
|
|
172
|
+
if (n <= j)
|
|
173
|
+
throw new Error("invert: expected positive modulus, got " + n);
|
|
174
|
+
let t = C(e, n), r = n, s = j, i = k;
|
|
175
|
+
for (; t !== j; ) {
|
|
176
|
+
const a = r / t, l = r % t, g = s - i * a;
|
|
177
|
+
r = t, t = l, s = i, i = g;
|
|
178
|
+
}
|
|
179
|
+
if (r !== k)
|
|
180
|
+
throw new Error("invert: does not exist");
|
|
181
|
+
return C(s, n);
|
|
182
|
+
}
|
|
183
|
+
function Yt(e, n) {
|
|
184
|
+
const t = (e.ORDER + k) / Ct, r = e.pow(n, t);
|
|
185
|
+
if (!e.eql(e.sqr(r), n))
|
|
186
|
+
throw new Error("Cannot find square root");
|
|
187
|
+
return r;
|
|
188
|
+
}
|
|
189
|
+
function ue(e, n) {
|
|
190
|
+
const t = (e.ORDER - Vt) / Kt, r = e.mul(n, P), s = e.pow(r, t), i = e.mul(n, s), o = e.mul(e.mul(i, P), s), a = e.mul(i, e.sub(o, e.ONE));
|
|
191
|
+
if (!e.eql(e.sqr(a), n))
|
|
192
|
+
throw new Error("Cannot find square root");
|
|
193
|
+
return a;
|
|
194
|
+
}
|
|
195
|
+
function de(e) {
|
|
196
|
+
if (e < BigInt(3))
|
|
197
|
+
throw new Error("sqrt is not defined for small field");
|
|
198
|
+
let n = e - k, t = 0;
|
|
199
|
+
for (; n % P === j; )
|
|
200
|
+
n /= P, t++;
|
|
201
|
+
let r = P;
|
|
202
|
+
const s = wt(e);
|
|
203
|
+
for (; Ht(s, r) === 1; )
|
|
204
|
+
if (r++ > 1e3)
|
|
205
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
206
|
+
if (t === 1)
|
|
207
|
+
return Yt;
|
|
208
|
+
let i = s.pow(r, n);
|
|
209
|
+
const o = (n + k) / P;
|
|
210
|
+
return function(l, g) {
|
|
211
|
+
if (l.is0(g))
|
|
212
|
+
return g;
|
|
213
|
+
if (Ht(l, g) !== 1)
|
|
214
|
+
throw new Error("Cannot find square root");
|
|
215
|
+
let f = t, E = l.mul(l.ONE, i), x = l.pow(g, n), S = l.pow(g, o);
|
|
216
|
+
for (; !l.eql(x, l.ONE); ) {
|
|
217
|
+
if (l.is0(x))
|
|
218
|
+
return l.ZERO;
|
|
219
|
+
let _ = 1, N = l.sqr(x);
|
|
220
|
+
for (; !l.eql(N, l.ONE); )
|
|
221
|
+
if (_++, N = l.sqr(N), _ === f)
|
|
222
|
+
throw new Error("Cannot find square root");
|
|
223
|
+
const L = k << BigInt(f - _ - 1), U = l.pow(E, L);
|
|
224
|
+
f = _, E = l.sqr(U), x = l.mul(x, E), S = l.mul(S, U);
|
|
225
|
+
}
|
|
226
|
+
return S;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function he(e) {
|
|
230
|
+
return e % Ct === le ? Yt : e % Kt === Vt ? ue : de(e);
|
|
231
|
+
}
|
|
232
|
+
const we = [
|
|
233
|
+
"create",
|
|
234
|
+
"isValid",
|
|
235
|
+
"is0",
|
|
236
|
+
"neg",
|
|
237
|
+
"inv",
|
|
238
|
+
"sqrt",
|
|
239
|
+
"sqr",
|
|
240
|
+
"eql",
|
|
241
|
+
"add",
|
|
242
|
+
"sub",
|
|
243
|
+
"mul",
|
|
244
|
+
"pow",
|
|
245
|
+
"div",
|
|
246
|
+
"addN",
|
|
247
|
+
"subN",
|
|
248
|
+
"mulN",
|
|
249
|
+
"sqrN"
|
|
250
|
+
];
|
|
251
|
+
function ge(e) {
|
|
252
|
+
const n = {
|
|
253
|
+
ORDER: "bigint",
|
|
254
|
+
MASK: "bigint",
|
|
255
|
+
BYTES: "number",
|
|
256
|
+
BITS: "number"
|
|
257
|
+
}, t = we.reduce((r, s) => (r[s] = "function", r), n);
|
|
258
|
+
return Nt(e, t), e;
|
|
259
|
+
}
|
|
260
|
+
function me(e, n, t) {
|
|
261
|
+
if (t < j)
|
|
262
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
263
|
+
if (t === j)
|
|
264
|
+
return e.ONE;
|
|
265
|
+
if (t === k)
|
|
266
|
+
return n;
|
|
267
|
+
let r = e.ONE, s = n;
|
|
268
|
+
for (; t > j; )
|
|
269
|
+
t & k && (r = e.mul(r, s)), s = e.sqr(s), t >>= k;
|
|
270
|
+
return r;
|
|
271
|
+
}
|
|
272
|
+
function Dt(e, n, t = !1) {
|
|
273
|
+
const r = new Array(n.length).fill(t ? e.ZERO : void 0), s = n.reduce((o, a, l) => e.is0(a) ? o : (r[l] = o, e.mul(o, a)), e.ONE), i = e.inv(s);
|
|
274
|
+
return n.reduceRight((o, a, l) => e.is0(a) ? o : (r[l] = e.mul(o, r[l]), e.mul(o, a)), i), r;
|
|
275
|
+
}
|
|
276
|
+
function Ht(e, n) {
|
|
277
|
+
const t = (e.ORDER - k) / P, r = e.pow(n, t), s = e.eql(r, e.ONE), i = e.eql(r, e.ZERO), o = e.eql(r, e.neg(e.ONE));
|
|
278
|
+
if (!s && !i && !o)
|
|
279
|
+
throw new Error("invalid Legendre symbol result");
|
|
280
|
+
return s ? 1 : i ? 0 : -1;
|
|
281
|
+
}
|
|
282
|
+
function ye(e, n) {
|
|
283
|
+
n !== void 0 && re(n);
|
|
284
|
+
const t = n !== void 0 ? n : e.toString(2).length, r = Math.ceil(t / 8);
|
|
285
|
+
return { nBitLength: t, nByteLength: r };
|
|
286
|
+
}
|
|
287
|
+
function wt(e, n, t = !1, r = {}) {
|
|
288
|
+
if (e <= j)
|
|
289
|
+
throw new Error("invalid field: expected ORDER > 0, got " + e);
|
|
290
|
+
let s, i;
|
|
291
|
+
if (typeof n == "object" && n != null) {
|
|
292
|
+
if (r.sqrt || t)
|
|
293
|
+
throw new Error("cannot specify opts in two arguments");
|
|
294
|
+
const f = n;
|
|
295
|
+
f.BITS && (s = f.BITS), f.sqrt && (i = f.sqrt), typeof f.isLE == "boolean" && (t = f.isLE);
|
|
296
|
+
} else
|
|
297
|
+
typeof n == "number" && (s = n), r.sqrt && (i = r.sqrt);
|
|
298
|
+
const { nBitLength: o, nByteLength: a } = ye(e, s);
|
|
299
|
+
if (a > 2048)
|
|
300
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
301
|
+
let l;
|
|
302
|
+
const g = Object.freeze({
|
|
303
|
+
ORDER: e,
|
|
304
|
+
isLE: t,
|
|
305
|
+
BITS: o,
|
|
306
|
+
BYTES: a,
|
|
307
|
+
MASK: ht(o),
|
|
308
|
+
ZERO: j,
|
|
309
|
+
ONE: k,
|
|
310
|
+
create: (f) => C(f, e),
|
|
311
|
+
isValid: (f) => {
|
|
312
|
+
if (typeof f != "bigint")
|
|
313
|
+
throw new Error("invalid field element: expected bigint, got " + typeof f);
|
|
314
|
+
return j <= f && f < e;
|
|
315
|
+
},
|
|
316
|
+
is0: (f) => f === j,
|
|
317
|
+
// is valid and invertible
|
|
318
|
+
isValidNot0: (f) => !g.is0(f) && g.isValid(f),
|
|
319
|
+
isOdd: (f) => (f & k) === k,
|
|
320
|
+
neg: (f) => C(-f, e),
|
|
321
|
+
eql: (f, E) => f === E,
|
|
322
|
+
sqr: (f) => C(f * f, e),
|
|
323
|
+
add: (f, E) => C(f + E, e),
|
|
324
|
+
sub: (f, E) => C(f - E, e),
|
|
325
|
+
mul: (f, E) => C(f * E, e),
|
|
326
|
+
pow: (f, E) => me(g, f, E),
|
|
327
|
+
div: (f, E) => C(f * _t(E, e), e),
|
|
328
|
+
// Same as above, but doesn't normalize
|
|
329
|
+
sqrN: (f) => f * f,
|
|
330
|
+
addN: (f, E) => f + E,
|
|
331
|
+
subN: (f, E) => f - E,
|
|
332
|
+
mulN: (f, E) => f * E,
|
|
333
|
+
inv: (f) => _t(f, e),
|
|
334
|
+
sqrt: i || ((f) => (l || (l = he(e)), l(g, f))),
|
|
335
|
+
toBytes: (f) => t ? Ut(f, a) : It(f, a),
|
|
336
|
+
fromBytes: (f) => {
|
|
337
|
+
if (f.length !== a)
|
|
338
|
+
throw new Error("Field.fromBytes: expected " + a + " bytes, got " + f.length);
|
|
339
|
+
return t ? jt(f) : dt(f);
|
|
340
|
+
},
|
|
341
|
+
// TODO: we don't need it here, move out to separate fn
|
|
342
|
+
invertBatch: (f) => Dt(g, f),
|
|
343
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
344
|
+
// and it's unclear what to return in there.
|
|
345
|
+
cmov: (f, E, x) => x ? E : f
|
|
346
|
+
});
|
|
347
|
+
return Object.freeze(g);
|
|
348
|
+
}
|
|
349
|
+
function Gt(e) {
|
|
350
|
+
if (typeof e != "bigint")
|
|
351
|
+
throw new Error("field order must be bigint");
|
|
352
|
+
const n = e.toString(2).length;
|
|
353
|
+
return Math.ceil(n / 8);
|
|
354
|
+
}
|
|
355
|
+
function Ft(e) {
|
|
356
|
+
const n = Gt(e);
|
|
357
|
+
return n + Math.ceil(n / 2);
|
|
358
|
+
}
|
|
359
|
+
function pe(e, n, t = !1) {
|
|
360
|
+
const r = e.length, s = Gt(n), i = Ft(n);
|
|
361
|
+
if (r < 16 || r < i || r > 1024)
|
|
362
|
+
throw new Error("expected " + i + "-1024 bytes of input, got " + r);
|
|
363
|
+
const o = t ? jt(e) : dt(e), a = C(o, n - k) + k;
|
|
364
|
+
return t ? Ut(a, s) : It(a, s);
|
|
365
|
+
}
|
|
366
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
367
|
+
const et = BigInt(0), X = BigInt(1);
|
|
368
|
+
function rt(e, n) {
|
|
369
|
+
const t = n.negate();
|
|
370
|
+
return e ? t : n;
|
|
371
|
+
}
|
|
372
|
+
function be(e, n, t) {
|
|
373
|
+
const r = (o) => o.pz, s = Dt(e.Fp, t.map(r));
|
|
374
|
+
return t.map((o, a) => o.toAffine(s[a])).map(e.fromAffine);
|
|
375
|
+
}
|
|
376
|
+
function Pt(e, n) {
|
|
377
|
+
if (!Number.isSafeInteger(e) || e <= 0 || e > n)
|
|
378
|
+
throw new Error("invalid window size, expected [1.." + n + "], got W=" + e);
|
|
379
|
+
}
|
|
380
|
+
function yt(e, n) {
|
|
381
|
+
Pt(e, n);
|
|
382
|
+
const t = Math.ceil(n / e) + 1, r = 2 ** (e - 1), s = 2 ** e, i = ht(e), o = BigInt(e);
|
|
383
|
+
return { windows: t, windowSize: r, mask: i, maxNumber: s, shiftBy: o };
|
|
384
|
+
}
|
|
385
|
+
function Ot(e, n, t) {
|
|
386
|
+
const { windowSize: r, mask: s, maxNumber: i, shiftBy: o } = t;
|
|
387
|
+
let a = Number(e & s), l = e >> o;
|
|
388
|
+
a > r && (a -= i, l += X);
|
|
389
|
+
const g = n * r, f = g + Math.abs(a) - 1, E = a === 0, x = a < 0, S = n % 2 !== 0;
|
|
390
|
+
return { nextN: l, offset: f, isZero: E, isNeg: x, isNegF: S, offsetF: g };
|
|
391
|
+
}
|
|
392
|
+
function Ee(e, n) {
|
|
393
|
+
if (!Array.isArray(e))
|
|
394
|
+
throw new Error("array expected");
|
|
395
|
+
e.forEach((t, r) => {
|
|
396
|
+
if (!(t instanceof n))
|
|
397
|
+
throw new Error("invalid point at index " + r);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
function Be(e, n) {
|
|
401
|
+
if (!Array.isArray(e))
|
|
402
|
+
throw new Error("array of scalars expected");
|
|
403
|
+
e.forEach((t, r) => {
|
|
404
|
+
if (!n.isValid(t))
|
|
405
|
+
throw new Error("invalid scalar at index " + r);
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
const pt = /* @__PURE__ */ new WeakMap(), Xt = /* @__PURE__ */ new WeakMap();
|
|
409
|
+
function bt(e) {
|
|
410
|
+
return Xt.get(e) || 1;
|
|
411
|
+
}
|
|
412
|
+
function Zt(e) {
|
|
413
|
+
if (e !== et)
|
|
414
|
+
throw new Error("invalid wNAF");
|
|
415
|
+
}
|
|
416
|
+
function ve(e, n) {
|
|
417
|
+
return {
|
|
418
|
+
constTimeNegate: rt,
|
|
419
|
+
hasPrecomputes(t) {
|
|
420
|
+
return bt(t) !== 1;
|
|
421
|
+
},
|
|
422
|
+
// non-const time multiplication ladder
|
|
423
|
+
unsafeLadder(t, r, s = e.ZERO) {
|
|
424
|
+
let i = t;
|
|
425
|
+
for (; r > et; )
|
|
426
|
+
r & X && (s = s.add(i)), i = i.double(), r >>= X;
|
|
427
|
+
return s;
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
431
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
432
|
+
* Number of precomputed points depends on the curve size:
|
|
433
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
434
|
+
* - 𝑊 is the window size
|
|
435
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
436
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
437
|
+
* @param elm Point instance
|
|
438
|
+
* @param W window size
|
|
439
|
+
* @returns precomputed point tables flattened to a single array
|
|
440
|
+
*/
|
|
441
|
+
precomputeWindow(t, r) {
|
|
442
|
+
const { windows: s, windowSize: i } = yt(r, n), o = [];
|
|
443
|
+
let a = t, l = a;
|
|
444
|
+
for (let g = 0; g < s; g++) {
|
|
445
|
+
l = a, o.push(l);
|
|
446
|
+
for (let f = 1; f < i; f++)
|
|
447
|
+
l = l.add(a), o.push(l);
|
|
448
|
+
a = l.double();
|
|
449
|
+
}
|
|
450
|
+
return o;
|
|
451
|
+
},
|
|
452
|
+
/**
|
|
453
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
454
|
+
* @param W window size
|
|
455
|
+
* @param precomputes precomputed tables
|
|
456
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
457
|
+
* @returns real and fake (for const-time) points
|
|
458
|
+
*/
|
|
459
|
+
wNAF(t, r, s) {
|
|
460
|
+
let i = e.ZERO, o = e.BASE;
|
|
461
|
+
const a = yt(t, n);
|
|
462
|
+
for (let l = 0; l < a.windows; l++) {
|
|
463
|
+
const { nextN: g, offset: f, isZero: E, isNeg: x, isNegF: S, offsetF: _ } = Ot(s, l, a);
|
|
464
|
+
s = g, E ? o = o.add(rt(S, r[_])) : i = i.add(rt(x, r[f]));
|
|
465
|
+
}
|
|
466
|
+
return Zt(s), { p: i, f: o };
|
|
467
|
+
},
|
|
468
|
+
/**
|
|
469
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
470
|
+
* @param W window size
|
|
471
|
+
* @param precomputes precomputed tables
|
|
472
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
473
|
+
* @param acc accumulator point to add result of multiplication
|
|
474
|
+
* @returns point
|
|
475
|
+
*/
|
|
476
|
+
wNAFUnsafe(t, r, s, i = e.ZERO) {
|
|
477
|
+
const o = yt(t, n);
|
|
478
|
+
for (let a = 0; a < o.windows && s !== et; a++) {
|
|
479
|
+
const { nextN: l, offset: g, isZero: f, isNeg: E } = Ot(s, a, o);
|
|
480
|
+
if (s = l, !f) {
|
|
481
|
+
const x = r[g];
|
|
482
|
+
i = i.add(E ? x.negate() : x);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return Zt(s), i;
|
|
486
|
+
},
|
|
487
|
+
getPrecomputes(t, r, s) {
|
|
488
|
+
let i = pt.get(r);
|
|
489
|
+
return i || (i = this.precomputeWindow(r, t), t !== 1 && (typeof s == "function" && (i = s(i)), pt.set(r, i))), i;
|
|
490
|
+
},
|
|
491
|
+
wNAFCached(t, r, s) {
|
|
492
|
+
const i = bt(t);
|
|
493
|
+
return this.wNAF(i, this.getPrecomputes(i, t, s), r);
|
|
494
|
+
},
|
|
495
|
+
wNAFCachedUnsafe(t, r, s, i) {
|
|
496
|
+
const o = bt(t);
|
|
497
|
+
return o === 1 ? this.unsafeLadder(t, r, i) : this.wNAFUnsafe(o, this.getPrecomputes(o, t, s), r, i);
|
|
498
|
+
},
|
|
499
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
500
|
+
// using windowed method. This specifies window size and
|
|
501
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
502
|
+
setWindowSize(t, r) {
|
|
503
|
+
Pt(r, n), Xt.set(t, r), pt.delete(t);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
function xe(e, n, t, r) {
|
|
508
|
+
let s = n, i = e.ZERO, o = e.ZERO;
|
|
509
|
+
for (; t > et || r > et; )
|
|
510
|
+
t & X && (i = i.add(s)), r & X && (o = o.add(s)), s = s.double(), t >>= X, r >>= X;
|
|
511
|
+
return { p1: i, p2: o };
|
|
512
|
+
}
|
|
513
|
+
function Se(e, n, t, r) {
|
|
514
|
+
Ee(t, e), Be(r, n);
|
|
515
|
+
const s = t.length, i = r.length;
|
|
516
|
+
if (s !== i)
|
|
517
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
518
|
+
const o = e.ZERO, a = ce(BigInt(s));
|
|
519
|
+
let l = 1;
|
|
520
|
+
a > 12 ? l = a - 3 : a > 4 ? l = a - 2 : a > 0 && (l = 2);
|
|
521
|
+
const g = ht(l), f = new Array(Number(g) + 1).fill(o), E = Math.floor((n.BITS - 1) / l) * l;
|
|
522
|
+
let x = o;
|
|
523
|
+
for (let S = E; S >= 0; S -= l) {
|
|
524
|
+
f.fill(o);
|
|
525
|
+
for (let N = 0; N < i; N++) {
|
|
526
|
+
const L = r[N], U = Number(L >> BigInt(S) & g);
|
|
527
|
+
f[U] = f[U].add(t[N]);
|
|
528
|
+
}
|
|
529
|
+
let _ = o;
|
|
530
|
+
for (let N = f.length - 1, L = o; N > 0; N--)
|
|
531
|
+
L = L.add(f[N]), _ = _.add(L);
|
|
532
|
+
if (x = x.add(_), S !== 0)
|
|
533
|
+
for (let N = 0; N < l; N++)
|
|
534
|
+
x = x.double();
|
|
535
|
+
}
|
|
536
|
+
return x;
|
|
537
|
+
}
|
|
538
|
+
function Rt(e, n) {
|
|
539
|
+
if (n) {
|
|
540
|
+
if (n.ORDER !== e)
|
|
541
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
542
|
+
return ge(n), n;
|
|
543
|
+
} else
|
|
544
|
+
return wt(e);
|
|
545
|
+
}
|
|
546
|
+
function Ie(e, n, t = {}) {
|
|
547
|
+
if (!n || typeof n != "object")
|
|
548
|
+
throw new Error(`expected valid ${e} CURVE object`);
|
|
549
|
+
for (const a of ["p", "n", "h"]) {
|
|
550
|
+
const l = n[a];
|
|
551
|
+
if (!(typeof l == "bigint" && l > et))
|
|
552
|
+
throw new Error(`CURVE.${a} must be positive bigint`);
|
|
553
|
+
}
|
|
554
|
+
const r = Rt(n.p, t.Fp), s = Rt(n.n, t.Fn), o = ["Gx", "Gy", "a", "b"];
|
|
555
|
+
for (const a of o)
|
|
556
|
+
if (!r.isValid(n[a]))
|
|
557
|
+
throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);
|
|
558
|
+
return { Fp: r, Fn: s };
|
|
559
|
+
}
|
|
560
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
561
|
+
function Lt(e) {
|
|
562
|
+
e.lowS !== void 0 && lt("lowS", e.lowS), e.prehash !== void 0 && lt("prehash", e.prehash);
|
|
563
|
+
}
|
|
564
|
+
class Ne extends Error {
|
|
565
|
+
constructor(n = "") {
|
|
566
|
+
super(n);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const V = {
|
|
570
|
+
// asn.1 DER encoding utils
|
|
571
|
+
Err: Ne,
|
|
572
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
573
|
+
_tlv: {
|
|
574
|
+
encode: (e, n) => {
|
|
575
|
+
const { Err: t } = V;
|
|
576
|
+
if (e < 0 || e > 256)
|
|
577
|
+
throw new t("tlv.encode: wrong tag");
|
|
578
|
+
if (n.length & 1)
|
|
579
|
+
throw new t("tlv.encode: unpadded data");
|
|
580
|
+
const r = n.length / 2, s = ft(r);
|
|
581
|
+
if (s.length / 2 & 128)
|
|
582
|
+
throw new t("tlv.encode: long form length too big");
|
|
583
|
+
const i = r > 127 ? ft(s.length / 2 | 128) : "";
|
|
584
|
+
return ft(e) + i + s + n;
|
|
585
|
+
},
|
|
586
|
+
// v - value, l - left bytes (unparsed)
|
|
587
|
+
decode(e, n) {
|
|
588
|
+
const { Err: t } = V;
|
|
589
|
+
let r = 0;
|
|
590
|
+
if (e < 0 || e > 256)
|
|
591
|
+
throw new t("tlv.encode: wrong tag");
|
|
592
|
+
if (n.length < 2 || n[r++] !== e)
|
|
593
|
+
throw new t("tlv.decode: wrong tlv");
|
|
594
|
+
const s = n[r++], i = !!(s & 128);
|
|
595
|
+
let o = 0;
|
|
596
|
+
if (!i)
|
|
597
|
+
o = s;
|
|
598
|
+
else {
|
|
599
|
+
const l = s & 127;
|
|
600
|
+
if (!l)
|
|
601
|
+
throw new t("tlv.decode(long): indefinite length not supported");
|
|
602
|
+
if (l > 4)
|
|
603
|
+
throw new t("tlv.decode(long): byte length is too big");
|
|
604
|
+
const g = n.subarray(r, r + l);
|
|
605
|
+
if (g.length !== l)
|
|
606
|
+
throw new t("tlv.decode: length bytes not complete");
|
|
607
|
+
if (g[0] === 0)
|
|
608
|
+
throw new t("tlv.decode(long): zero leftmost byte");
|
|
609
|
+
for (const f of g)
|
|
610
|
+
o = o << 8 | f;
|
|
611
|
+
if (r += l, o < 128)
|
|
612
|
+
throw new t("tlv.decode(long): not minimal encoding");
|
|
613
|
+
}
|
|
614
|
+
const a = n.subarray(r, r + o);
|
|
615
|
+
if (a.length !== o)
|
|
616
|
+
throw new t("tlv.decode: wrong value length");
|
|
617
|
+
return { v: a, l: n.subarray(r + o) };
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
621
|
+
// since we always use positive integers here. It must always be empty:
|
|
622
|
+
// - add zero byte if exists
|
|
623
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
624
|
+
_int: {
|
|
625
|
+
encode(e) {
|
|
626
|
+
const { Err: n } = V;
|
|
627
|
+
if (e < ot)
|
|
628
|
+
throw new n("integer: negative integers are not allowed");
|
|
629
|
+
let t = ft(e);
|
|
630
|
+
if (Number.parseInt(t[0], 16) & 8 && (t = "00" + t), t.length & 1)
|
|
631
|
+
throw new n("unexpected DER parsing assertion: unpadded hex");
|
|
632
|
+
return t;
|
|
633
|
+
},
|
|
634
|
+
decode(e) {
|
|
635
|
+
const { Err: n } = V;
|
|
636
|
+
if (e[0] & 128)
|
|
637
|
+
throw new n("invalid signature integer: negative");
|
|
638
|
+
if (e[0] === 0 && !(e[1] & 128))
|
|
639
|
+
throw new n("invalid signature integer: unnecessary leading zero");
|
|
640
|
+
return dt(e);
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
toSig(e) {
|
|
644
|
+
const { Err: n, _int: t, _tlv: r } = V, s = $("signature", e), { v: i, l: o } = r.decode(48, s);
|
|
645
|
+
if (o.length)
|
|
646
|
+
throw new n("invalid signature: left bytes after parsing");
|
|
647
|
+
const { v: a, l } = r.decode(2, i), { v: g, l: f } = r.decode(2, l);
|
|
648
|
+
if (f.length)
|
|
649
|
+
throw new n("invalid signature: left bytes after parsing");
|
|
650
|
+
return { r: t.decode(a), s: t.decode(g) };
|
|
651
|
+
},
|
|
652
|
+
hexFromSig(e) {
|
|
653
|
+
const { _tlv: n, _int: t } = V, r = n.encode(2, t.encode(e.r)), s = n.encode(2, t.encode(e.s)), i = r + s;
|
|
654
|
+
return n.encode(48, i);
|
|
655
|
+
}
|
|
656
|
+
}, ot = BigInt(0), it = BigInt(1), qe = BigInt(2), ct = BigInt(3), Ae = BigInt(4);
|
|
657
|
+
function _e(e, n, t) {
|
|
658
|
+
function r(s) {
|
|
659
|
+
const i = e.sqr(s), o = e.mul(i, s);
|
|
660
|
+
return e.add(e.add(o, e.mul(s, n)), t);
|
|
661
|
+
}
|
|
662
|
+
return r;
|
|
663
|
+
}
|
|
664
|
+
function Wt(e, n, t) {
|
|
665
|
+
const { BYTES: r } = e;
|
|
666
|
+
function s(i) {
|
|
667
|
+
let o;
|
|
668
|
+
if (typeof i == "bigint")
|
|
669
|
+
o = i;
|
|
670
|
+
else {
|
|
671
|
+
let a = $("private key", i);
|
|
672
|
+
if (n) {
|
|
673
|
+
if (!n.includes(a.length * 2))
|
|
674
|
+
throw new Error("invalid private key");
|
|
675
|
+
const l = new Uint8Array(r);
|
|
676
|
+
l.set(a, l.length - a.length), a = l;
|
|
677
|
+
}
|
|
678
|
+
try {
|
|
679
|
+
o = e.fromBytes(a);
|
|
680
|
+
} catch {
|
|
681
|
+
throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof i}`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (t && (o = e.create(o)), !e.isValidNot0(o))
|
|
685
|
+
throw new Error("invalid private key: out of range [1..N-1]");
|
|
686
|
+
return o;
|
|
687
|
+
}
|
|
688
|
+
return s;
|
|
689
|
+
}
|
|
690
|
+
function He(e, n = {}) {
|
|
691
|
+
const { Fp: t, Fn: r } = Ie("weierstrass", e, n), { h: s, n: i } = e;
|
|
692
|
+
Nt(n, {}, {
|
|
693
|
+
allowInfinityPoint: "boolean",
|
|
694
|
+
clearCofactor: "function",
|
|
695
|
+
isTorsionFree: "function",
|
|
696
|
+
fromBytes: "function",
|
|
697
|
+
toBytes: "function",
|
|
698
|
+
endo: "object",
|
|
699
|
+
wrapPrivateKey: "boolean"
|
|
700
|
+
});
|
|
701
|
+
const { endo: o } = n;
|
|
702
|
+
if (o && (!t.is0(e.a) || typeof o.beta != "bigint" || typeof o.splitScalar != "function"))
|
|
703
|
+
throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');
|
|
704
|
+
function a() {
|
|
705
|
+
if (!t.isOdd)
|
|
706
|
+
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
707
|
+
}
|
|
708
|
+
function l(H, c, h) {
|
|
709
|
+
const { x: u, y: d } = c.toAffine(), w = t.toBytes(u);
|
|
710
|
+
if (lt("isCompressed", h), h) {
|
|
711
|
+
a();
|
|
712
|
+
const p = !t.isOdd(d);
|
|
713
|
+
return F(Qt(p), w);
|
|
714
|
+
} else
|
|
715
|
+
return F(Uint8Array.of(4), w, t.toBytes(d));
|
|
716
|
+
}
|
|
717
|
+
function g(H) {
|
|
718
|
+
at(H);
|
|
719
|
+
const c = t.BYTES, h = c + 1, u = 2 * c + 1, d = H.length, w = H[0], p = H.subarray(1);
|
|
720
|
+
if (d === h && (w === 2 || w === 3)) {
|
|
721
|
+
const m = t.fromBytes(p);
|
|
722
|
+
if (!t.isValid(m))
|
|
723
|
+
throw new Error("bad point: is not on curve, wrong x");
|
|
724
|
+
const y = x(m);
|
|
725
|
+
let B;
|
|
726
|
+
try {
|
|
727
|
+
B = t.sqrt(y);
|
|
728
|
+
} catch (q) {
|
|
729
|
+
const v = q instanceof Error ? ": " + q.message : "";
|
|
730
|
+
throw new Error("bad point: is not on curve, sqrt error" + v);
|
|
731
|
+
}
|
|
732
|
+
a();
|
|
733
|
+
const b = t.isOdd(B);
|
|
734
|
+
return (w & 1) === 1 !== b && (B = t.neg(B)), { x: m, y: B };
|
|
735
|
+
} else if (d === u && w === 4) {
|
|
736
|
+
const m = t.fromBytes(p.subarray(c * 0, c * 1)), y = t.fromBytes(p.subarray(c * 1, c * 2));
|
|
737
|
+
if (!S(m, y))
|
|
738
|
+
throw new Error("bad point: is not on curve");
|
|
739
|
+
return { x: m, y };
|
|
740
|
+
} else
|
|
741
|
+
throw new Error(`bad point: got length ${d}, expected compressed=${h} or uncompressed=${u}`);
|
|
742
|
+
}
|
|
743
|
+
const f = n.toBytes || l, E = n.fromBytes || g, x = _e(t, e.a, e.b);
|
|
744
|
+
function S(H, c) {
|
|
745
|
+
const h = t.sqr(c), u = x(H);
|
|
746
|
+
return t.eql(h, u);
|
|
747
|
+
}
|
|
748
|
+
if (!S(e.Gx, e.Gy))
|
|
749
|
+
throw new Error("bad curve params: generator point");
|
|
750
|
+
const _ = t.mul(t.pow(e.a, ct), Ae), N = t.mul(t.sqr(e.b), BigInt(27));
|
|
751
|
+
if (t.is0(t.add(_, N)))
|
|
752
|
+
throw new Error("bad curve params: a or b");
|
|
753
|
+
function L(H, c, h = !1) {
|
|
754
|
+
if (!t.isValid(c) || h && t.is0(c))
|
|
755
|
+
throw new Error(`bad point coordinate ${H}`);
|
|
756
|
+
return c;
|
|
757
|
+
}
|
|
758
|
+
function U(H) {
|
|
759
|
+
if (!(H instanceof I))
|
|
760
|
+
throw new Error("ProjectivePoint expected");
|
|
761
|
+
}
|
|
762
|
+
const W = At((H, c) => {
|
|
763
|
+
const { px: h, py: u, pz: d } = H;
|
|
764
|
+
if (t.eql(d, t.ONE))
|
|
765
|
+
return { x: h, y: u };
|
|
766
|
+
const w = H.is0();
|
|
767
|
+
c == null && (c = w ? t.ONE : t.inv(d));
|
|
768
|
+
const p = t.mul(h, c), m = t.mul(u, c), y = t.mul(d, c);
|
|
769
|
+
if (w)
|
|
770
|
+
return { x: t.ZERO, y: t.ZERO };
|
|
771
|
+
if (!t.eql(y, t.ONE))
|
|
772
|
+
throw new Error("invZ was invalid");
|
|
773
|
+
return { x: p, y: m };
|
|
774
|
+
}), Y = At((H) => {
|
|
775
|
+
if (H.is0()) {
|
|
776
|
+
if (n.allowInfinityPoint && !t.is0(H.py))
|
|
777
|
+
return;
|
|
778
|
+
throw new Error("bad point: ZERO");
|
|
779
|
+
}
|
|
780
|
+
const { x: c, y: h } = H.toAffine();
|
|
781
|
+
if (!t.isValid(c) || !t.isValid(h))
|
|
782
|
+
throw new Error("bad point: x or y not field elements");
|
|
783
|
+
if (!S(c, h))
|
|
784
|
+
throw new Error("bad point: equation left != right");
|
|
785
|
+
if (!H.isTorsionFree())
|
|
786
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
787
|
+
return !0;
|
|
788
|
+
});
|
|
789
|
+
function Q(H, c, h, u, d) {
|
|
790
|
+
return h = new I(t.mul(h.px, H), h.py, h.pz), c = rt(u, c), h = rt(d, h), c.add(h);
|
|
791
|
+
}
|
|
792
|
+
class I {
|
|
793
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
794
|
+
constructor(c, h, u) {
|
|
795
|
+
this.px = L("x", c), this.py = L("y", h, !0), this.pz = L("z", u), Object.freeze(this);
|
|
796
|
+
}
|
|
797
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
798
|
+
static fromAffine(c) {
|
|
799
|
+
const { x: h, y: u } = c || {};
|
|
800
|
+
if (!c || !t.isValid(h) || !t.isValid(u))
|
|
801
|
+
throw new Error("invalid affine point");
|
|
802
|
+
if (c instanceof I)
|
|
803
|
+
throw new Error("projective point not allowed");
|
|
804
|
+
return t.is0(h) && t.is0(u) ? I.ZERO : new I(h, u, t.ONE);
|
|
805
|
+
}
|
|
806
|
+
get x() {
|
|
807
|
+
return this.toAffine().x;
|
|
808
|
+
}
|
|
809
|
+
get y() {
|
|
810
|
+
return this.toAffine().y;
|
|
811
|
+
}
|
|
812
|
+
static normalizeZ(c) {
|
|
813
|
+
return be(I, "pz", c);
|
|
814
|
+
}
|
|
815
|
+
static fromBytes(c) {
|
|
816
|
+
return at(c), I.fromHex(c);
|
|
817
|
+
}
|
|
818
|
+
/** Converts hash string or Uint8Array to Point. */
|
|
819
|
+
static fromHex(c) {
|
|
820
|
+
const h = I.fromAffine(E($("pointHex", c)));
|
|
821
|
+
return h.assertValidity(), h;
|
|
822
|
+
}
|
|
823
|
+
/** Multiplies generator point by privateKey. */
|
|
824
|
+
static fromPrivateKey(c) {
|
|
825
|
+
const h = Wt(r, n.allowedPrivateKeyLengths, n.wrapPrivateKey);
|
|
826
|
+
return I.BASE.multiply(h(c));
|
|
827
|
+
}
|
|
828
|
+
/** Multiscalar Multiplication */
|
|
829
|
+
static msm(c, h) {
|
|
830
|
+
return Se(I, r, c, h);
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
*
|
|
834
|
+
* @param windowSize
|
|
835
|
+
* @param isLazy true will defer table computation until the first multiplication
|
|
836
|
+
* @returns
|
|
837
|
+
*/
|
|
838
|
+
precompute(c = 8, h = !0) {
|
|
839
|
+
return K.setWindowSize(this, c), h || this.multiply(ct), this;
|
|
840
|
+
}
|
|
841
|
+
/** "Private method", don't use it directly */
|
|
842
|
+
_setWindowSize(c) {
|
|
843
|
+
this.precompute(c);
|
|
844
|
+
}
|
|
845
|
+
// TODO: return `this`
|
|
846
|
+
/** A point on curve is valid if it conforms to equation. */
|
|
847
|
+
assertValidity() {
|
|
848
|
+
Y(this);
|
|
849
|
+
}
|
|
850
|
+
hasEvenY() {
|
|
851
|
+
const { y: c } = this.toAffine();
|
|
852
|
+
if (!t.isOdd)
|
|
853
|
+
throw new Error("Field doesn't support isOdd");
|
|
854
|
+
return !t.isOdd(c);
|
|
855
|
+
}
|
|
856
|
+
/** Compare one point to another. */
|
|
857
|
+
equals(c) {
|
|
858
|
+
U(c);
|
|
859
|
+
const { px: h, py: u, pz: d } = this, { px: w, py: p, pz: m } = c, y = t.eql(t.mul(h, m), t.mul(w, d)), B = t.eql(t.mul(u, m), t.mul(p, d));
|
|
860
|
+
return y && B;
|
|
861
|
+
}
|
|
862
|
+
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
863
|
+
negate() {
|
|
864
|
+
return new I(this.px, t.neg(this.py), this.pz);
|
|
865
|
+
}
|
|
866
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
867
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
868
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
869
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
870
|
+
double() {
|
|
871
|
+
const { a: c, b: h } = e, u = t.mul(h, ct), { px: d, py: w, pz: p } = this;
|
|
872
|
+
let m = t.ZERO, y = t.ZERO, B = t.ZERO, b = t.mul(d, d), O = t.mul(w, w), q = t.mul(p, p), v = t.mul(d, w);
|
|
873
|
+
return v = t.add(v, v), B = t.mul(d, p), B = t.add(B, B), m = t.mul(c, B), y = t.mul(u, q), y = t.add(m, y), m = t.sub(O, y), y = t.add(O, y), y = t.mul(m, y), m = t.mul(v, m), B = t.mul(u, B), q = t.mul(c, q), v = t.sub(b, q), v = t.mul(c, v), v = t.add(v, B), B = t.add(b, b), b = t.add(B, b), b = t.add(b, q), b = t.mul(b, v), y = t.add(y, b), q = t.mul(w, p), q = t.add(q, q), b = t.mul(q, v), m = t.sub(m, b), B = t.mul(q, O), B = t.add(B, B), B = t.add(B, B), new I(m, y, B);
|
|
874
|
+
}
|
|
875
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
876
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
877
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
878
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
879
|
+
add(c) {
|
|
880
|
+
U(c);
|
|
881
|
+
const { px: h, py: u, pz: d } = this, { px: w, py: p, pz: m } = c;
|
|
882
|
+
let y = t.ZERO, B = t.ZERO, b = t.ZERO;
|
|
883
|
+
const O = e.a, q = t.mul(e.b, ct);
|
|
884
|
+
let v = t.mul(h, w), Z = t.mul(u, p), R = t.mul(d, m), z = t.add(h, u), A = t.add(w, p);
|
|
885
|
+
z = t.mul(z, A), A = t.add(v, Z), z = t.sub(z, A), A = t.add(h, d);
|
|
886
|
+
let T = t.add(w, m);
|
|
887
|
+
return A = t.mul(A, T), T = t.add(v, R), A = t.sub(A, T), T = t.add(u, d), y = t.add(p, m), T = t.mul(T, y), y = t.add(Z, R), T = t.sub(T, y), b = t.mul(O, A), y = t.mul(q, R), b = t.add(y, b), y = t.sub(Z, b), b = t.add(Z, b), B = t.mul(y, b), Z = t.add(v, v), Z = t.add(Z, v), R = t.mul(O, R), A = t.mul(q, A), Z = t.add(Z, R), R = t.sub(v, R), R = t.mul(O, R), A = t.add(A, R), v = t.mul(Z, A), B = t.add(B, v), v = t.mul(T, A), y = t.mul(z, y), y = t.sub(y, v), v = t.mul(z, Z), b = t.mul(T, b), b = t.add(b, v), new I(y, B, b);
|
|
888
|
+
}
|
|
889
|
+
subtract(c) {
|
|
890
|
+
return this.add(c.negate());
|
|
891
|
+
}
|
|
892
|
+
is0() {
|
|
893
|
+
return this.equals(I.ZERO);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Constant time multiplication.
|
|
897
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
898
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
899
|
+
* Uses precomputes when available.
|
|
900
|
+
* Uses endomorphism for Koblitz curves.
|
|
901
|
+
* @param scalar by which the point would be multiplied
|
|
902
|
+
* @returns New point
|
|
903
|
+
*/
|
|
904
|
+
multiply(c) {
|
|
905
|
+
const { endo: h } = n;
|
|
906
|
+
if (!r.isValidNot0(c))
|
|
907
|
+
throw new Error("invalid scalar: out of range");
|
|
908
|
+
let u, d;
|
|
909
|
+
const w = (p) => K.wNAFCached(this, p, I.normalizeZ);
|
|
910
|
+
if (h) {
|
|
911
|
+
const { k1neg: p, k1: m, k2neg: y, k2: B } = h.splitScalar(c), { p: b, f: O } = w(m), { p: q, f: v } = w(B);
|
|
912
|
+
d = O.add(v), u = Q(h.beta, b, q, p, y);
|
|
913
|
+
} else {
|
|
914
|
+
const { p, f: m } = w(c);
|
|
915
|
+
u = p, d = m;
|
|
916
|
+
}
|
|
917
|
+
return I.normalizeZ([u, d])[0];
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
921
|
+
* It's faster, but should only be used when you don't care about
|
|
922
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
923
|
+
*/
|
|
924
|
+
multiplyUnsafe(c) {
|
|
925
|
+
const { endo: h } = n, u = this;
|
|
926
|
+
if (!r.isValid(c))
|
|
927
|
+
throw new Error("invalid scalar: out of range");
|
|
928
|
+
if (c === ot || u.is0())
|
|
929
|
+
return I.ZERO;
|
|
930
|
+
if (c === it)
|
|
931
|
+
return u;
|
|
932
|
+
if (K.hasPrecomputes(this))
|
|
933
|
+
return this.multiply(c);
|
|
934
|
+
if (h) {
|
|
935
|
+
const { k1neg: d, k1: w, k2neg: p, k2: m } = h.splitScalar(c), { p1: y, p2: B } = xe(I, u, w, m);
|
|
936
|
+
return Q(h.beta, y, B, d, p);
|
|
937
|
+
} else
|
|
938
|
+
return K.wNAFCachedUnsafe(u, c);
|
|
939
|
+
}
|
|
940
|
+
multiplyAndAddUnsafe(c, h, u) {
|
|
941
|
+
const d = this.multiplyUnsafe(h).add(c.multiplyUnsafe(u));
|
|
942
|
+
return d.is0() ? void 0 : d;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Converts Projective point to affine (x, y) coordinates.
|
|
946
|
+
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
947
|
+
*/
|
|
948
|
+
toAffine(c) {
|
|
949
|
+
return W(this, c);
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
953
|
+
* Always torsion-free for cofactor=1 curves.
|
|
954
|
+
*/
|
|
955
|
+
isTorsionFree() {
|
|
956
|
+
const { isTorsionFree: c } = n;
|
|
957
|
+
return s === it ? !0 : c ? c(I, this) : K.wNAFCachedUnsafe(this, i).is0();
|
|
958
|
+
}
|
|
959
|
+
clearCofactor() {
|
|
960
|
+
const { clearCofactor: c } = n;
|
|
961
|
+
return s === it ? this : c ? c(I, this) : this.multiplyUnsafe(s);
|
|
962
|
+
}
|
|
963
|
+
toBytes(c = !0) {
|
|
964
|
+
return lt("isCompressed", c), this.assertValidity(), f(I, this, c);
|
|
965
|
+
}
|
|
966
|
+
/** @deprecated use `toBytes` */
|
|
967
|
+
toRawBytes(c = !0) {
|
|
968
|
+
return this.toBytes(c);
|
|
969
|
+
}
|
|
970
|
+
toHex(c = !0) {
|
|
971
|
+
return st(this.toBytes(c));
|
|
972
|
+
}
|
|
973
|
+
toString() {
|
|
974
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
I.BASE = new I(e.Gx, e.Gy, t.ONE), I.ZERO = new I(t.ZERO, t.ONE, t.ZERO), I.Fp = t, I.Fn = r;
|
|
978
|
+
const D = r.BITS, K = ve(I, n.endo ? Math.ceil(D / 2) : D);
|
|
979
|
+
return I;
|
|
980
|
+
}
|
|
981
|
+
function Qt(e) {
|
|
982
|
+
return Uint8Array.of(e ? 2 : 3);
|
|
983
|
+
}
|
|
984
|
+
function Oe(e, n, t = {}) {
|
|
985
|
+
Nt(n, { hash: "function" }, {
|
|
986
|
+
hmac: "function",
|
|
987
|
+
lowS: "boolean",
|
|
988
|
+
randomBytes: "function",
|
|
989
|
+
bits2int: "function",
|
|
990
|
+
bits2int_modN: "function"
|
|
991
|
+
});
|
|
992
|
+
const r = n.randomBytes || oe, s = n.hmac || ((u, ...d) => $t(n.hash, u, F(...d))), { Fp: i, Fn: o } = e, { ORDER: a, BITS: l } = o;
|
|
993
|
+
function g(u) {
|
|
994
|
+
const d = a >> it;
|
|
995
|
+
return u > d;
|
|
996
|
+
}
|
|
997
|
+
function f(u) {
|
|
998
|
+
return g(u) ? o.neg(u) : u;
|
|
999
|
+
}
|
|
1000
|
+
function E(u, d) {
|
|
1001
|
+
if (!o.isValidNot0(d))
|
|
1002
|
+
throw new Error(`invalid signature ${u}: out of range 1..CURVE.n`);
|
|
1003
|
+
}
|
|
1004
|
+
class x {
|
|
1005
|
+
constructor(d, w, p) {
|
|
1006
|
+
E("r", d), E("s", w), this.r = d, this.s = w, p != null && (this.recovery = p), Object.freeze(this);
|
|
1007
|
+
}
|
|
1008
|
+
// pair (bytes of r, bytes of s)
|
|
1009
|
+
static fromCompact(d) {
|
|
1010
|
+
const w = o.BYTES, p = $("compactSignature", d, w * 2);
|
|
1011
|
+
return new x(o.fromBytes(p.subarray(0, w)), o.fromBytes(p.subarray(w, w * 2)));
|
|
1012
|
+
}
|
|
1013
|
+
// DER encoded ECDSA signature
|
|
1014
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
1015
|
+
static fromDER(d) {
|
|
1016
|
+
const { r: w, s: p } = V.toSig($("DER", d));
|
|
1017
|
+
return new x(w, p);
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* @todo remove
|
|
1021
|
+
* @deprecated
|
|
1022
|
+
*/
|
|
1023
|
+
assertValidity() {
|
|
1024
|
+
}
|
|
1025
|
+
addRecoveryBit(d) {
|
|
1026
|
+
return new x(this.r, this.s, d);
|
|
1027
|
+
}
|
|
1028
|
+
// ProjPointType<bigint>
|
|
1029
|
+
recoverPublicKey(d) {
|
|
1030
|
+
const w = i.ORDER, { r: p, s: m, recovery: y } = this;
|
|
1031
|
+
if (y == null || ![0, 1, 2, 3].includes(y))
|
|
1032
|
+
throw new Error("recovery id invalid");
|
|
1033
|
+
if (a * qe < w && y > 1)
|
|
1034
|
+
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
1035
|
+
const b = y === 2 || y === 3 ? p + a : p;
|
|
1036
|
+
if (!i.isValid(b))
|
|
1037
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
1038
|
+
const O = i.toBytes(b), q = e.fromHex(F(Qt((y & 1) === 0), O)), v = o.inv(b), Z = Y($("msgHash", d)), R = o.create(-Z * v), z = o.create(m * v), A = e.BASE.multiplyUnsafe(R).add(q.multiplyUnsafe(z));
|
|
1039
|
+
if (A.is0())
|
|
1040
|
+
throw new Error("point at infinify");
|
|
1041
|
+
return A.assertValidity(), A;
|
|
1042
|
+
}
|
|
1043
|
+
// Signatures should be low-s, to prevent malleability.
|
|
1044
|
+
hasHighS() {
|
|
1045
|
+
return g(this.s);
|
|
1046
|
+
}
|
|
1047
|
+
normalizeS() {
|
|
1048
|
+
return this.hasHighS() ? new x(this.r, o.neg(this.s), this.recovery) : this;
|
|
1049
|
+
}
|
|
1050
|
+
toBytes(d) {
|
|
1051
|
+
if (d === "compact")
|
|
1052
|
+
return F(o.toBytes(this.r), o.toBytes(this.s));
|
|
1053
|
+
if (d === "der")
|
|
1054
|
+
return xt(V.hexFromSig(this));
|
|
1055
|
+
throw new Error("invalid format");
|
|
1056
|
+
}
|
|
1057
|
+
// DER-encoded
|
|
1058
|
+
toDERRawBytes() {
|
|
1059
|
+
return this.toBytes("der");
|
|
1060
|
+
}
|
|
1061
|
+
toDERHex() {
|
|
1062
|
+
return st(this.toBytes("der"));
|
|
1063
|
+
}
|
|
1064
|
+
// padded bytes of r, then padded bytes of s
|
|
1065
|
+
toCompactRawBytes() {
|
|
1066
|
+
return this.toBytes("compact");
|
|
1067
|
+
}
|
|
1068
|
+
toCompactHex() {
|
|
1069
|
+
return st(this.toBytes("compact"));
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
const S = Wt(o, t.allowedPrivateKeyLengths, t.wrapPrivateKey), _ = {
|
|
1073
|
+
isValidPrivateKey(u) {
|
|
1074
|
+
try {
|
|
1075
|
+
return S(u), !0;
|
|
1076
|
+
} catch {
|
|
1077
|
+
return !1;
|
|
1078
|
+
}
|
|
1079
|
+
},
|
|
1080
|
+
normPrivateKeyToScalar: S,
|
|
1081
|
+
/**
|
|
1082
|
+
* Produces cryptographically secure private key from random of size
|
|
1083
|
+
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
1084
|
+
*/
|
|
1085
|
+
randomPrivateKey: () => {
|
|
1086
|
+
const u = a;
|
|
1087
|
+
return pe(r(Ft(u)), u);
|
|
1088
|
+
},
|
|
1089
|
+
precompute(u = 8, d = e.BASE) {
|
|
1090
|
+
return d.precompute(u, !1);
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
function N(u, d = !0) {
|
|
1094
|
+
return e.fromPrivateKey(u).toBytes(d);
|
|
1095
|
+
}
|
|
1096
|
+
function L(u) {
|
|
1097
|
+
if (typeof u == "bigint")
|
|
1098
|
+
return !1;
|
|
1099
|
+
if (u instanceof e)
|
|
1100
|
+
return !0;
|
|
1101
|
+
const w = $("key", u).length, p = i.BYTES, m = p + 1, y = 2 * p + 1;
|
|
1102
|
+
if (!(t.allowedPrivateKeyLengths || o.BYTES === m))
|
|
1103
|
+
return w === m || w === y;
|
|
1104
|
+
}
|
|
1105
|
+
function U(u, d, w = !0) {
|
|
1106
|
+
if (L(u) === !0)
|
|
1107
|
+
throw new Error("first arg must be private key");
|
|
1108
|
+
if (L(d) === !1)
|
|
1109
|
+
throw new Error("second arg must be public key");
|
|
1110
|
+
return e.fromHex(d).multiply(S(u)).toBytes(w);
|
|
1111
|
+
}
|
|
1112
|
+
const W = n.bits2int || function(u) {
|
|
1113
|
+
if (u.length > 8192)
|
|
1114
|
+
throw new Error("input is too large");
|
|
1115
|
+
const d = dt(u), w = u.length * 8 - l;
|
|
1116
|
+
return w > 0 ? d >> BigInt(w) : d;
|
|
1117
|
+
}, Y = n.bits2int_modN || function(u) {
|
|
1118
|
+
return o.create(W(u));
|
|
1119
|
+
}, Q = ht(l);
|
|
1120
|
+
function I(u) {
|
|
1121
|
+
return fe("num < 2^" + l, u, ot, Q), o.toBytes(u);
|
|
1122
|
+
}
|
|
1123
|
+
function D(u, d, w = K) {
|
|
1124
|
+
if (["recovered", "canonical"].some((z) => z in w))
|
|
1125
|
+
throw new Error("sign() legacy options not supported");
|
|
1126
|
+
const { hash: p } = n;
|
|
1127
|
+
let { lowS: m, prehash: y, extraEntropy: B } = w;
|
|
1128
|
+
m == null && (m = !0), u = $("msgHash", u), Lt(w), y && (u = $("prehashed msgHash", p(u)));
|
|
1129
|
+
const b = Y(u), O = S(d), q = [I(O), I(b)];
|
|
1130
|
+
if (B != null && B !== !1) {
|
|
1131
|
+
const z = B === !0 ? r(i.BYTES) : B;
|
|
1132
|
+
q.push($("extraEntropy", z));
|
|
1133
|
+
}
|
|
1134
|
+
const v = F(...q), Z = b;
|
|
1135
|
+
function R(z) {
|
|
1136
|
+
const A = W(z);
|
|
1137
|
+
if (!o.isValidNot0(A))
|
|
1138
|
+
return;
|
|
1139
|
+
const T = o.inv(A), nt = e.BASE.multiply(A).toAffine(), J = o.create(nt.x);
|
|
1140
|
+
if (J === ot)
|
|
1141
|
+
return;
|
|
1142
|
+
const G = o.create(T * o.create(Z + J * O));
|
|
1143
|
+
if (G === ot)
|
|
1144
|
+
return;
|
|
1145
|
+
let gt = (nt.x === J ? 0 : 2) | Number(nt.y & it), tt = G;
|
|
1146
|
+
return m && g(G) && (tt = f(G), gt ^= 1), new x(J, tt, gt);
|
|
1147
|
+
}
|
|
1148
|
+
return { seed: v, k2sig: R };
|
|
1149
|
+
}
|
|
1150
|
+
const K = { lowS: n.lowS, prehash: !1 }, H = { lowS: n.lowS, prehash: !1 };
|
|
1151
|
+
function c(u, d, w = K) {
|
|
1152
|
+
const { seed: p, k2sig: m } = D(u, d, w);
|
|
1153
|
+
return ae(n.hash.outputLen, o.BYTES, s)(p, m);
|
|
1154
|
+
}
|
|
1155
|
+
e.BASE.precompute(8);
|
|
1156
|
+
function h(u, d, w, p = H) {
|
|
1157
|
+
const m = u;
|
|
1158
|
+
d = $("msgHash", d), w = $("publicKey", w), Lt(p);
|
|
1159
|
+
const { lowS: y, prehash: B, format: b } = p;
|
|
1160
|
+
if ("strict" in p)
|
|
1161
|
+
throw new Error("options.strict was renamed to lowS");
|
|
1162
|
+
if (b !== void 0 && !["compact", "der", "js"].includes(b))
|
|
1163
|
+
throw new Error('format must be "compact", "der" or "js"');
|
|
1164
|
+
const O = typeof m == "string" || Tt(m), q = !O && !b && typeof m == "object" && m !== null && typeof m.r == "bigint" && typeof m.s == "bigint";
|
|
1165
|
+
if (!O && !q)
|
|
1166
|
+
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
1167
|
+
let v, Z;
|
|
1168
|
+
try {
|
|
1169
|
+
if (q)
|
|
1170
|
+
if (b === void 0 || b === "js")
|
|
1171
|
+
v = new x(m.r, m.s);
|
|
1172
|
+
else
|
|
1173
|
+
throw new Error("invalid format");
|
|
1174
|
+
if (O) {
|
|
1175
|
+
try {
|
|
1176
|
+
b !== "compact" && (v = x.fromDER(m));
|
|
1177
|
+
} catch (tt) {
|
|
1178
|
+
if (!(tt instanceof V.Err))
|
|
1179
|
+
throw tt;
|
|
1180
|
+
}
|
|
1181
|
+
!v && b !== "der" && (v = x.fromCompact(m));
|
|
1182
|
+
}
|
|
1183
|
+
Z = e.fromHex(w);
|
|
1184
|
+
} catch {
|
|
1185
|
+
return !1;
|
|
1186
|
+
}
|
|
1187
|
+
if (!v || y && v.hasHighS())
|
|
1188
|
+
return !1;
|
|
1189
|
+
B && (d = n.hash(d));
|
|
1190
|
+
const { r: R, s: z } = v, A = Y(d), T = o.inv(z), nt = o.create(A * T), J = o.create(R * T), G = e.BASE.multiplyUnsafe(nt).add(Z.multiplyUnsafe(J));
|
|
1191
|
+
return G.is0() ? !1 : o.create(G.x) === R;
|
|
1192
|
+
}
|
|
1193
|
+
return Object.freeze({
|
|
1194
|
+
getPublicKey: N,
|
|
1195
|
+
getSharedSecret: U,
|
|
1196
|
+
sign: c,
|
|
1197
|
+
verify: h,
|
|
1198
|
+
utils: _,
|
|
1199
|
+
Point: e,
|
|
1200
|
+
Signature: x
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
function Ze(e) {
|
|
1204
|
+
const n = {
|
|
1205
|
+
a: e.a,
|
|
1206
|
+
b: e.b,
|
|
1207
|
+
p: e.Fp.ORDER,
|
|
1208
|
+
n: e.n,
|
|
1209
|
+
h: e.h,
|
|
1210
|
+
Gx: e.Gx,
|
|
1211
|
+
Gy: e.Gy
|
|
1212
|
+
}, t = e.Fp, r = wt(n.n, e.nBitLength), s = {
|
|
1213
|
+
Fp: t,
|
|
1214
|
+
Fn: r,
|
|
1215
|
+
allowedPrivateKeyLengths: e.allowedPrivateKeyLengths,
|
|
1216
|
+
allowInfinityPoint: e.allowInfinityPoint,
|
|
1217
|
+
endo: e.endo,
|
|
1218
|
+
wrapPrivateKey: e.wrapPrivateKey,
|
|
1219
|
+
isTorsionFree: e.isTorsionFree,
|
|
1220
|
+
clearCofactor: e.clearCofactor,
|
|
1221
|
+
fromBytes: e.fromBytes,
|
|
1222
|
+
toBytes: e.toBytes
|
|
1223
|
+
};
|
|
1224
|
+
return { CURVE: n, curveOpts: s };
|
|
1225
|
+
}
|
|
1226
|
+
function Re(e) {
|
|
1227
|
+
const { CURVE: n, curveOpts: t } = Ze(e), r = {
|
|
1228
|
+
hash: e.hash,
|
|
1229
|
+
hmac: e.hmac,
|
|
1230
|
+
randomBytes: e.randomBytes,
|
|
1231
|
+
lowS: e.lowS,
|
|
1232
|
+
bits2int: e.bits2int,
|
|
1233
|
+
bits2int_modN: e.bits2int_modN
|
|
1234
|
+
};
|
|
1235
|
+
return { CURVE: n, curveOpts: t, ecdsaOpts: r };
|
|
1236
|
+
}
|
|
1237
|
+
function Le(e, n) {
|
|
1238
|
+
return Object.assign({}, n, {
|
|
1239
|
+
ProjectivePoint: n.Point,
|
|
1240
|
+
CURVE: e
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
function ze(e) {
|
|
1244
|
+
const { CURVE: n, curveOpts: t, ecdsaOpts: r } = Re(e), s = He(n, t), i = Oe(s, r, t);
|
|
1245
|
+
return Le(e, i);
|
|
1246
|
+
}
|
|
1247
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1248
|
+
function Te(e, n) {
|
|
1249
|
+
const t = (r) => ze({ ...e, hash: r });
|
|
1250
|
+
return { ...t(n), create: t };
|
|
1251
|
+
}
|
|
1252
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1253
|
+
const ut = {
|
|
1254
|
+
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
1255
|
+
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
1256
|
+
h: BigInt(1),
|
|
1257
|
+
a: BigInt(0),
|
|
1258
|
+
b: BigInt(7),
|
|
1259
|
+
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
1260
|
+
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
1261
|
+
};
|
|
1262
|
+
BigInt(0);
|
|
1263
|
+
const ke = BigInt(1), Bt = BigInt(2), zt = (e, n) => (e + n / Bt) / n;
|
|
1264
|
+
function je(e) {
|
|
1265
|
+
const n = ut.p, t = BigInt(3), r = BigInt(6), s = BigInt(11), i = BigInt(22), o = BigInt(23), a = BigInt(44), l = BigInt(88), g = e * e * e % n, f = g * g * e % n, E = M(f, t, n) * f % n, x = M(E, t, n) * f % n, S = M(x, Bt, n) * g % n, _ = M(S, s, n) * S % n, N = M(_, i, n) * _ % n, L = M(N, a, n) * N % n, U = M(L, l, n) * L % n, W = M(U, a, n) * N % n, Y = M(W, t, n) * f % n, Q = M(Y, o, n) * _ % n, I = M(Q, r, n) * g % n, D = M(I, Bt, n);
|
|
1266
|
+
if (!vt.eql(vt.sqr(D), e))
|
|
1267
|
+
throw new Error("Cannot find square root");
|
|
1268
|
+
return D;
|
|
1269
|
+
}
|
|
1270
|
+
const vt = wt(ut.p, void 0, void 0, { sqrt: je }), Me = Te({
|
|
1271
|
+
...ut,
|
|
1272
|
+
Fp: vt,
|
|
1273
|
+
lowS: !0,
|
|
1274
|
+
// Allow only low-S signatures by default in sign() and verify()
|
|
1275
|
+
endo: {
|
|
1276
|
+
// Endomorphism, see above
|
|
1277
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1278
|
+
splitScalar: (e) => {
|
|
1279
|
+
const n = ut.n, t = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), r = -ke * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), s = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), i = t, o = BigInt("0x100000000000000000000000000000000"), a = zt(i * e, n), l = zt(-r * e, n);
|
|
1280
|
+
let g = C(e - a * t - l * s, n), f = C(-a * r - l * i, n);
|
|
1281
|
+
const E = g > o, x = f > o;
|
|
1282
|
+
if (E && (g = n - g), x && (f = n - f), g > o || f > o)
|
|
1283
|
+
throw new Error("splitScalar: Endomorphism failed, k=" + e);
|
|
1284
|
+
return { k1neg: E, k1: g, k2neg: x, k2: f };
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}, ie);
|
|
1288
|
+
export {
|
|
1289
|
+
Me as secp256k1
|
|
1290
|
+
};
|
|
1291
|
+
//# sourceMappingURL=secp256k1-DGP4Y7VW.js.map
|