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