@etherplay/dev-wallet-host 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/site/assets/{App-DDcApMye.js → App-jiH5KsZN.js} +2624 -845
- package/site/assets/App-jiH5KsZN.js.map +1 -0
- package/site/assets/{bignumbers-DEXSwWwa.js → bignumbers-CDwemtjh.js} +2 -2
- package/site/assets/{bignumbers-DEXSwWwa.js.map → bignumbers-CDwemtjh.js.map} +1 -1
- package/site/assets/{index-BpgHGts3.js → index--WaQfBnk.js} +3 -3
- package/site/assets/{index-BpgHGts3.js.map → index--WaQfBnk.js.map} +1 -1
- package/site/assets/{index-BrlXb28n.js → index-B0bHIDP-.js} +2 -2
- package/site/assets/{index-BrlXb28n.js.map → index-B0bHIDP-.js.map} +1 -1
- package/site/assets/{index-BXoUMG4U.js → index-BQfjfSli.js} +6 -6
- package/site/assets/{index-BXoUMG4U.js.map → index-BQfjfSli.js.map} +1 -1
- package/site/assets/{index-Boiz7eM2.js → index-CNWQNI4F.js} +8 -8
- package/site/assets/{index-Boiz7eM2.js.map → index-CNWQNI4F.js.map} +1 -1
- package/site/assets/{index-BAWUHBts.js → index-CY5VRUKw.js} +4 -4
- package/site/assets/{index-BAWUHBts.js.map → index-CY5VRUKw.js.map} +1 -1
- package/site/assets/{index-NKFZZPPE.js → index-LuGvuWDj.js} +6 -6
- package/site/assets/{index-NKFZZPPE.js.map → index-LuGvuWDj.js.map} +1 -1
- package/site/assets/{login-Bm1QORQJ.js → login-Djc2e6Ld.js} +3 -3
- package/site/assets/{login-Bm1QORQJ.js.map → login-Djc2e6Ld.js.map} +1 -1
- package/site/assets/{typed-data-CUGl6Sw8.js → typed-data-B1d1daZe.js} +4 -4
- package/site/assets/{typed-data-CUGl6Sw8.js.map → typed-data-B1d1daZe.js.map} +1 -1
- package/site/assets/{utf8-xywbIwOw.js → utf8-CL2y2HZA.js} +2 -2
- package/site/assets/{utf8-xywbIwOw.js.map → utf8-CL2y2HZA.js.map} +1 -1
- package/site/login/index.html +1 -1
- package/site/assets/App-DDcApMye.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index--WaQfBnk.js","assets/index-client-8kPxwRn_.js","assets/login-Djc2e6Ld.js","assets/login-Dm0rG43D.css","assets/index-BQfjfSli.js","assets/typed-data-B1d1daZe.js","assets/utf8-CL2y2HZA.js","assets/index-B0bHIDP-.js","assets/index-LuGvuWDj.js","assets/bignumbers-CDwemtjh.js","assets/index-CNWQNI4F.js","assets/index-CY5VRUKw.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __typeError = (msg) => {
|
|
4
4
|
throw TypeError(msg);
|
|
@@ -20,7 +20,7 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
20
20
|
});
|
|
21
21
|
var _a, _b, _c, _d, _e, _t, _e2, _s, _a2, _i, _r, _o, _n, _h, _d2, _c2, _p, _E_instances, m_fn, _f, _e3, _s2, _t2, _i2, _o2, _r2, _n2, _a3, _c3, _g2, _h2, _d3, _l, _g, _h3;
|
|
22
22
|
import { i as is_array, g as get_prototype_of, o as object_prototype, c as create_text, a as active_effect, b as get_first_child, d as is_firefox, T as TEMPLATE_FRAGMENT, e as TEMPLATE_USE_IMPORT_NODE, f as block, E as EFFECT_TRANSPARENT, r as resume_effect, h as branch, p as pause_effect, U as UNINITIALIZED, j as get$2, k as derived_safe_equal, I as INERT, l as array_from, m as mutable_source, s as source$1, n as internal_set, q as pause_children, t as clear_text_content, u as run_out_transitions, v as destroy_effect, w as EACH_INDEX_REACTIVE, x as EACH_ITEM_REACTIVE, y as EACH_ITEM_IMMUTABLE, z as get_next_sibling, A as EACH_IS_CONTROLLED, B as queue_micro_task, C as EACH_IS_ANIMATED, D as effect, F as untrack, G as render_effect, H as deep_read_state, J as safe_not_equal$1, L as LOADING_ATTR_SYMBOL, N as NAMESPACE_HTML, K as get_descriptors, S as STATE_SYMBOL, M as component_context, O as user_pre_effect, P as user_effect, Q as run_all, R as run, V as derived, W as noop$3, X as teardown, Y as define_property, Z as set, _ as proxy, $ as get_descriptor, a0 as props_invalid_value, a1 as LEGACY_DERIVED_PROP, a2 as PROPS_IS_UPDATED, a3 as safe_equals, a4 as PROPS_IS_BINDABLE, a5 as LEGACY_PROPS, a6 as PROPS_IS_LAZY_INITIAL, a7 as legacy_mode_flag, a8 as PROPS_IS_RUNES, a9 as PROPS_IS_IMMUTABLE, aa as enable_legacy_mode_flag, ab as delegate, ac as push, ad as user_derived, ae as sibling, af as pop, ag as child, ah as template_effect, ai as set_text, aj as first_child, ak as onMount, al as event, am as state } from "./index-client-8kPxwRn_.js";
|
|
23
|
-
import { _ as __vitePreload, h as hostConfig } from "./login-
|
|
23
|
+
import { _ as __vitePreload, h as hostConfig } from "./login-Djc2e6Ld.js";
|
|
24
24
|
const empty = [];
|
|
25
25
|
function snapshot(value, skip_warning = false) {
|
|
26
26
|
return clone(value, /* @__PURE__ */ new Map(), "", empty);
|
|
@@ -1535,11 +1535,9 @@ function OTP($$anchor, $$props) {
|
|
|
1535
1535
|
let otpInputs = [];
|
|
1536
1536
|
function onPaste(event2) {
|
|
1537
1537
|
var _a4;
|
|
1538
|
-
console.log(event2);
|
|
1539
1538
|
event2.preventDefault();
|
|
1540
1539
|
const text2 = (_a4 = event2.clipboardData) == null ? void 0 : _a4.getData("text");
|
|
1541
1540
|
const numerals = text2.replace(/\D/g, "");
|
|
1542
|
-
console.log({ numerals });
|
|
1543
1541
|
const currentIndex = Number(event2.target.dataset.index);
|
|
1544
1542
|
$$props.onAcknowledge();
|
|
1545
1543
|
let startIndex = otpInputs.findIndex((input, index2) => index2 < currentIndex && !input.value);
|
|
@@ -1581,7 +1579,6 @@ function OTP($$anchor, $$props) {
|
|
|
1581
1579
|
}
|
|
1582
1580
|
function onChange(event2) {
|
|
1583
1581
|
const val = event2.target.value;
|
|
1584
|
-
console.log({ val });
|
|
1585
1582
|
if (!val) {
|
|
1586
1583
|
event2.preventDefault();
|
|
1587
1584
|
return;
|
|
@@ -1600,7 +1597,6 @@ function OTP($$anchor, $$props) {
|
|
|
1600
1597
|
if (value) {
|
|
1601
1598
|
$$props.onAcknowledge();
|
|
1602
1599
|
}
|
|
1603
|
-
console.log({ target, value });
|
|
1604
1600
|
toggleFilledClass(target);
|
|
1605
1601
|
if (target.nextElementSibling) {
|
|
1606
1602
|
if ("focus" in target.nextElementSibling && target.nextElementSibling.focus) {
|
|
@@ -1651,7 +1647,6 @@ function Email($$anchor, $$props) {
|
|
|
1651
1647
|
let otp = state(void 0);
|
|
1652
1648
|
async function _submitOTP(text2) {
|
|
1653
1649
|
var _a4;
|
|
1654
|
-
console.log({ otpCode: text2 });
|
|
1655
1650
|
try {
|
|
1656
1651
|
await $$props.authProvider.provideOTP(text2);
|
|
1657
1652
|
} catch (error) {
|
|
@@ -1839,6 +1834,7 @@ function Loading($$anchor) {
|
|
|
1839
1834
|
var main2 = root$2();
|
|
1840
1835
|
append($$anchor, main2);
|
|
1841
1836
|
}
|
|
1837
|
+
const crypto$2 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
1842
1838
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1843
1839
|
function isBytes$5(a5) {
|
|
1844
1840
|
return a5 instanceof Uint8Array || ArrayBuffer.isView(a5) && a5.constructor.name === "Uint8Array";
|
|
@@ -1853,6 +1849,12 @@ function abytes$2(b2, ...lengths) {
|
|
|
1853
1849
|
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
1854
1850
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
|
|
1855
1851
|
}
|
|
1852
|
+
function ahash$1(h2) {
|
|
1853
|
+
if (typeof h2 !== "function" || typeof h2.create !== "function")
|
|
1854
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
1855
|
+
anumber$3(h2.outputLen);
|
|
1856
|
+
anumber$3(h2.blockLen);
|
|
1857
|
+
}
|
|
1856
1858
|
function aexists$1(instance, checkFinished = true) {
|
|
1857
1859
|
if (instance.destroyed)
|
|
1858
1860
|
throw new Error("Hash instance has been destroyed");
|
|
@@ -1948,6 +1950,21 @@ function toBytes$1(data) {
|
|
|
1948
1950
|
abytes$2(data);
|
|
1949
1951
|
return data;
|
|
1950
1952
|
}
|
|
1953
|
+
function concatBytes$2(...arrays) {
|
|
1954
|
+
let sum = 0;
|
|
1955
|
+
for (let i3 = 0; i3 < arrays.length; i3++) {
|
|
1956
|
+
const a5 = arrays[i3];
|
|
1957
|
+
abytes$2(a5);
|
|
1958
|
+
sum += a5.length;
|
|
1959
|
+
}
|
|
1960
|
+
const res = new Uint8Array(sum);
|
|
1961
|
+
for (let i3 = 0, pad = 0; i3 < arrays.length; i3++) {
|
|
1962
|
+
const a5 = arrays[i3];
|
|
1963
|
+
res.set(a5, pad);
|
|
1964
|
+
pad += a5.length;
|
|
1965
|
+
}
|
|
1966
|
+
return res;
|
|
1967
|
+
}
|
|
1951
1968
|
let Hash$1 = class Hash {
|
|
1952
1969
|
};
|
|
1953
1970
|
function createHasher(hashCons) {
|
|
@@ -1958,6 +1975,81 @@ function createHasher(hashCons) {
|
|
|
1958
1975
|
hashC.create = () => hashCons();
|
|
1959
1976
|
return hashC;
|
|
1960
1977
|
}
|
|
1978
|
+
function randomBytes$1(bytesLength = 32) {
|
|
1979
|
+
if (crypto$2 && typeof crypto$2.getRandomValues === "function") {
|
|
1980
|
+
return crypto$2.getRandomValues(new Uint8Array(bytesLength));
|
|
1981
|
+
}
|
|
1982
|
+
if (crypto$2 && typeof crypto$2.randomBytes === "function") {
|
|
1983
|
+
return Uint8Array.from(crypto$2.randomBytes(bytesLength));
|
|
1984
|
+
}
|
|
1985
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
1986
|
+
}
|
|
1987
|
+
let HMAC$1 = class HMAC extends Hash$1 {
|
|
1988
|
+
constructor(hash, _key) {
|
|
1989
|
+
super();
|
|
1990
|
+
this.finished = false;
|
|
1991
|
+
this.destroyed = false;
|
|
1992
|
+
ahash$1(hash);
|
|
1993
|
+
const key = toBytes$1(_key);
|
|
1994
|
+
this.iHash = hash.create();
|
|
1995
|
+
if (typeof this.iHash.update !== "function")
|
|
1996
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1997
|
+
this.blockLen = this.iHash.blockLen;
|
|
1998
|
+
this.outputLen = this.iHash.outputLen;
|
|
1999
|
+
const blockLen = this.blockLen;
|
|
2000
|
+
const pad = new Uint8Array(blockLen);
|
|
2001
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
2002
|
+
for (let i3 = 0; i3 < pad.length; i3++)
|
|
2003
|
+
pad[i3] ^= 54;
|
|
2004
|
+
this.iHash.update(pad);
|
|
2005
|
+
this.oHash = hash.create();
|
|
2006
|
+
for (let i3 = 0; i3 < pad.length; i3++)
|
|
2007
|
+
pad[i3] ^= 54 ^ 92;
|
|
2008
|
+
this.oHash.update(pad);
|
|
2009
|
+
clean(pad);
|
|
2010
|
+
}
|
|
2011
|
+
update(buf) {
|
|
2012
|
+
aexists$1(this);
|
|
2013
|
+
this.iHash.update(buf);
|
|
2014
|
+
return this;
|
|
2015
|
+
}
|
|
2016
|
+
digestInto(out) {
|
|
2017
|
+
aexists$1(this);
|
|
2018
|
+
abytes$2(out, this.outputLen);
|
|
2019
|
+
this.finished = true;
|
|
2020
|
+
this.iHash.digestInto(out);
|
|
2021
|
+
this.oHash.update(out);
|
|
2022
|
+
this.oHash.digestInto(out);
|
|
2023
|
+
this.destroy();
|
|
2024
|
+
}
|
|
2025
|
+
digest() {
|
|
2026
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
2027
|
+
this.digestInto(out);
|
|
2028
|
+
return out;
|
|
2029
|
+
}
|
|
2030
|
+
_cloneInto(to) {
|
|
2031
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
2032
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
2033
|
+
to = to;
|
|
2034
|
+
to.finished = finished;
|
|
2035
|
+
to.destroyed = destroyed;
|
|
2036
|
+
to.blockLen = blockLen;
|
|
2037
|
+
to.outputLen = outputLen;
|
|
2038
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
2039
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
2040
|
+
return to;
|
|
2041
|
+
}
|
|
2042
|
+
clone() {
|
|
2043
|
+
return this._cloneInto();
|
|
2044
|
+
}
|
|
2045
|
+
destroy() {
|
|
2046
|
+
this.destroyed = true;
|
|
2047
|
+
this.oHash.destroy();
|
|
2048
|
+
this.iHash.destroy();
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
const hmac$1 = (hash, key, message) => new HMAC$1(hash, key).update(message).digest();
|
|
2052
|
+
hmac$1.create = (hash, key) => new HMAC$1(hash, key);
|
|
1961
2053
|
function setBigUint64$1(view, byteOffset, value, isLE2) {
|
|
1962
2054
|
if (typeof view.setBigUint64 === "function")
|
|
1963
2055
|
return view.setBigUint64(byteOffset, value, isLE2);
|
|
@@ -2076,6 +2168,24 @@ const SHA256_IV$1 = /* @__PURE__ */ Uint32Array.from([
|
|
|
2076
2168
|
528734635,
|
|
2077
2169
|
1541459225
|
|
2078
2170
|
]);
|
|
2171
|
+
const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
2172
|
+
1779033703,
|
|
2173
|
+
4089235720,
|
|
2174
|
+
3144134277,
|
|
2175
|
+
2227873595,
|
|
2176
|
+
1013904242,
|
|
2177
|
+
4271175723,
|
|
2178
|
+
2773480762,
|
|
2179
|
+
1595750129,
|
|
2180
|
+
1359893119,
|
|
2181
|
+
2917565137,
|
|
2182
|
+
2600822924,
|
|
2183
|
+
725511199,
|
|
2184
|
+
528734635,
|
|
2185
|
+
4215389547,
|
|
2186
|
+
1541459225,
|
|
2187
|
+
327033209
|
|
2188
|
+
]);
|
|
2079
2189
|
const U32_MASK64$1 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2080
2190
|
const _32n$1 = /* @__PURE__ */ BigInt(32);
|
|
2081
2191
|
function fromBig$1(n4, le = false) {
|
|
@@ -2093,10 +2203,26 @@ function split$1(lst, le = false) {
|
|
|
2093
2203
|
}
|
|
2094
2204
|
return [Ah, Al];
|
|
2095
2205
|
}
|
|
2206
|
+
const shrSH$1 = (h2, _l2, s5) => h2 >>> s5;
|
|
2207
|
+
const shrSL$1 = (h2, l3, s5) => h2 << 32 - s5 | l3 >>> s5;
|
|
2208
|
+
const rotrSH$1 = (h2, l3, s5) => h2 >>> s5 | l3 << 32 - s5;
|
|
2209
|
+
const rotrSL$1 = (h2, l3, s5) => h2 << 32 - s5 | l3 >>> s5;
|
|
2210
|
+
const rotrBH$1 = (h2, l3, s5) => h2 << 64 - s5 | l3 >>> s5 - 32;
|
|
2211
|
+
const rotrBL$1 = (h2, l3, s5) => h2 >>> s5 - 32 | l3 << 64 - s5;
|
|
2096
2212
|
const rotlSH$1 = (h2, l3, s5) => h2 << s5 | l3 >>> 32 - s5;
|
|
2097
2213
|
const rotlSL$1 = (h2, l3, s5) => l3 << s5 | h2 >>> 32 - s5;
|
|
2098
2214
|
const rotlBH$1 = (h2, l3, s5) => l3 << s5 - 32 | h2 >>> 64 - s5;
|
|
2099
2215
|
const rotlBL$1 = (h2, l3, s5) => h2 << s5 - 32 | l3 >>> 64 - s5;
|
|
2216
|
+
function add$1(Ah, Al, Bh, Bl) {
|
|
2217
|
+
const l3 = (Al >>> 0) + (Bl >>> 0);
|
|
2218
|
+
return { h: Ah + Bh + (l3 / 2 ** 32 | 0) | 0, l: l3 | 0 };
|
|
2219
|
+
}
|
|
2220
|
+
const add3L$1 = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
2221
|
+
const add3H$1 = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
2222
|
+
const add4L$1 = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
2223
|
+
const add4H$1 = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
2224
|
+
const add5L$1 = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
2225
|
+
const add5H$1 = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
2100
2226
|
const SHA256_K$1 = /* @__PURE__ */ Uint32Array.from([
|
|
2101
2227
|
1116352408,
|
|
2102
2228
|
1899447441,
|
|
@@ -2177,14 +2303,14 @@ let SHA256$1 = class SHA256 extends HashMD$1 {
|
|
|
2177
2303
|
this.H = SHA256_IV$1[7] | 0;
|
|
2178
2304
|
}
|
|
2179
2305
|
get() {
|
|
2180
|
-
const { A: A3, B, C:
|
|
2181
|
-
return [A3, B,
|
|
2306
|
+
const { A: A3, B, C: C2, D: D2, E: E2, F, G: G2, H } = this;
|
|
2307
|
+
return [A3, B, C2, D2, E2, F, G2, H];
|
|
2182
2308
|
}
|
|
2183
2309
|
// prettier-ignore
|
|
2184
|
-
set(A3, B,
|
|
2310
|
+
set(A3, B, C2, D2, E2, F, G2, H) {
|
|
2185
2311
|
this.A = A3 | 0;
|
|
2186
2312
|
this.B = B | 0;
|
|
2187
|
-
this.C =
|
|
2313
|
+
this.C = C2 | 0;
|
|
2188
2314
|
this.D = D2 | 0;
|
|
2189
2315
|
this.E = E2 | 0;
|
|
2190
2316
|
this.F = F | 0;
|
|
@@ -2201,30 +2327,30 @@ let SHA256$1 = class SHA256 extends HashMD$1 {
|
|
|
2201
2327
|
const s1 = rotr$1(W2, 17) ^ rotr$1(W2, 19) ^ W2 >>> 10;
|
|
2202
2328
|
SHA256_W$1[i3] = s1 + SHA256_W$1[i3 - 7] + s0 + SHA256_W$1[i3 - 16] | 0;
|
|
2203
2329
|
}
|
|
2204
|
-
let { A: A3, B, C:
|
|
2330
|
+
let { A: A3, B, C: C2, D: D2, E: E2, F, G: G2, H } = this;
|
|
2205
2331
|
for (let i3 = 0; i3 < 64; i3++) {
|
|
2206
2332
|
const sigma1 = rotr$1(E2, 6) ^ rotr$1(E2, 11) ^ rotr$1(E2, 25);
|
|
2207
2333
|
const T1 = H + sigma1 + Chi$1(E2, F, G2) + SHA256_K$1[i3] + SHA256_W$1[i3] | 0;
|
|
2208
2334
|
const sigma0 = rotr$1(A3, 2) ^ rotr$1(A3, 13) ^ rotr$1(A3, 22);
|
|
2209
|
-
const T22 = sigma0 + Maj$1(A3, B,
|
|
2335
|
+
const T22 = sigma0 + Maj$1(A3, B, C2) | 0;
|
|
2210
2336
|
H = G2;
|
|
2211
2337
|
G2 = F;
|
|
2212
2338
|
F = E2;
|
|
2213
2339
|
E2 = D2 + T1 | 0;
|
|
2214
|
-
D2 =
|
|
2215
|
-
|
|
2340
|
+
D2 = C2;
|
|
2341
|
+
C2 = B;
|
|
2216
2342
|
B = A3;
|
|
2217
2343
|
A3 = T1 + T22 | 0;
|
|
2218
2344
|
}
|
|
2219
2345
|
A3 = A3 + this.A | 0;
|
|
2220
2346
|
B = B + this.B | 0;
|
|
2221
|
-
|
|
2347
|
+
C2 = C2 + this.C | 0;
|
|
2222
2348
|
D2 = D2 + this.D | 0;
|
|
2223
2349
|
E2 = E2 + this.E | 0;
|
|
2224
2350
|
F = F + this.F | 0;
|
|
2225
2351
|
G2 = G2 + this.G | 0;
|
|
2226
2352
|
H = H + this.H | 0;
|
|
2227
|
-
this.set(A3, B,
|
|
2353
|
+
this.set(A3, B, C2, D2, E2, F, G2, H);
|
|
2228
2354
|
}
|
|
2229
2355
|
roundClean() {
|
|
2230
2356
|
clean(SHA256_W$1);
|
|
@@ -2234,7 +2360,205 @@ let SHA256$1 = class SHA256 extends HashMD$1 {
|
|
|
2234
2360
|
clean(this.buffer);
|
|
2235
2361
|
}
|
|
2236
2362
|
};
|
|
2363
|
+
const K512 = /* @__PURE__ */ (() => split$1([
|
|
2364
|
+
"0x428a2f98d728ae22",
|
|
2365
|
+
"0x7137449123ef65cd",
|
|
2366
|
+
"0xb5c0fbcfec4d3b2f",
|
|
2367
|
+
"0xe9b5dba58189dbbc",
|
|
2368
|
+
"0x3956c25bf348b538",
|
|
2369
|
+
"0x59f111f1b605d019",
|
|
2370
|
+
"0x923f82a4af194f9b",
|
|
2371
|
+
"0xab1c5ed5da6d8118",
|
|
2372
|
+
"0xd807aa98a3030242",
|
|
2373
|
+
"0x12835b0145706fbe",
|
|
2374
|
+
"0x243185be4ee4b28c",
|
|
2375
|
+
"0x550c7dc3d5ffb4e2",
|
|
2376
|
+
"0x72be5d74f27b896f",
|
|
2377
|
+
"0x80deb1fe3b1696b1",
|
|
2378
|
+
"0x9bdc06a725c71235",
|
|
2379
|
+
"0xc19bf174cf692694",
|
|
2380
|
+
"0xe49b69c19ef14ad2",
|
|
2381
|
+
"0xefbe4786384f25e3",
|
|
2382
|
+
"0x0fc19dc68b8cd5b5",
|
|
2383
|
+
"0x240ca1cc77ac9c65",
|
|
2384
|
+
"0x2de92c6f592b0275",
|
|
2385
|
+
"0x4a7484aa6ea6e483",
|
|
2386
|
+
"0x5cb0a9dcbd41fbd4",
|
|
2387
|
+
"0x76f988da831153b5",
|
|
2388
|
+
"0x983e5152ee66dfab",
|
|
2389
|
+
"0xa831c66d2db43210",
|
|
2390
|
+
"0xb00327c898fb213f",
|
|
2391
|
+
"0xbf597fc7beef0ee4",
|
|
2392
|
+
"0xc6e00bf33da88fc2",
|
|
2393
|
+
"0xd5a79147930aa725",
|
|
2394
|
+
"0x06ca6351e003826f",
|
|
2395
|
+
"0x142929670a0e6e70",
|
|
2396
|
+
"0x27b70a8546d22ffc",
|
|
2397
|
+
"0x2e1b21385c26c926",
|
|
2398
|
+
"0x4d2c6dfc5ac42aed",
|
|
2399
|
+
"0x53380d139d95b3df",
|
|
2400
|
+
"0x650a73548baf63de",
|
|
2401
|
+
"0x766a0abb3c77b2a8",
|
|
2402
|
+
"0x81c2c92e47edaee6",
|
|
2403
|
+
"0x92722c851482353b",
|
|
2404
|
+
"0xa2bfe8a14cf10364",
|
|
2405
|
+
"0xa81a664bbc423001",
|
|
2406
|
+
"0xc24b8b70d0f89791",
|
|
2407
|
+
"0xc76c51a30654be30",
|
|
2408
|
+
"0xd192e819d6ef5218",
|
|
2409
|
+
"0xd69906245565a910",
|
|
2410
|
+
"0xf40e35855771202a",
|
|
2411
|
+
"0x106aa07032bbd1b8",
|
|
2412
|
+
"0x19a4c116b8d2d0c8",
|
|
2413
|
+
"0x1e376c085141ab53",
|
|
2414
|
+
"0x2748774cdf8eeb99",
|
|
2415
|
+
"0x34b0bcb5e19b48a8",
|
|
2416
|
+
"0x391c0cb3c5c95a63",
|
|
2417
|
+
"0x4ed8aa4ae3418acb",
|
|
2418
|
+
"0x5b9cca4f7763e373",
|
|
2419
|
+
"0x682e6ff3d6b2b8a3",
|
|
2420
|
+
"0x748f82ee5defb2fc",
|
|
2421
|
+
"0x78a5636f43172f60",
|
|
2422
|
+
"0x84c87814a1f0ab72",
|
|
2423
|
+
"0x8cc702081a6439ec",
|
|
2424
|
+
"0x90befffa23631e28",
|
|
2425
|
+
"0xa4506cebde82bde9",
|
|
2426
|
+
"0xbef9a3f7b2c67915",
|
|
2427
|
+
"0xc67178f2e372532b",
|
|
2428
|
+
"0xca273eceea26619c",
|
|
2429
|
+
"0xd186b8c721c0c207",
|
|
2430
|
+
"0xeada7dd6cde0eb1e",
|
|
2431
|
+
"0xf57d4f7fee6ed178",
|
|
2432
|
+
"0x06f067aa72176fba",
|
|
2433
|
+
"0x0a637dc5a2c898a6",
|
|
2434
|
+
"0x113f9804bef90dae",
|
|
2435
|
+
"0x1b710b35131c471b",
|
|
2436
|
+
"0x28db77f523047d84",
|
|
2437
|
+
"0x32caab7b40c72493",
|
|
2438
|
+
"0x3c9ebe0a15c9bebc",
|
|
2439
|
+
"0x431d67c49c100d4c",
|
|
2440
|
+
"0x4cc5d4becb3e42b6",
|
|
2441
|
+
"0x597f299cfc657e2a",
|
|
2442
|
+
"0x5fcb6fab3ad6faec",
|
|
2443
|
+
"0x6c44198c4a475817"
|
|
2444
|
+
].map((n4) => BigInt(n4))))();
|
|
2445
|
+
const SHA512_Kh$1 = /* @__PURE__ */ (() => K512[0])();
|
|
2446
|
+
const SHA512_Kl$1 = /* @__PURE__ */ (() => K512[1])();
|
|
2447
|
+
const SHA512_W_H$1 = /* @__PURE__ */ new Uint32Array(80);
|
|
2448
|
+
const SHA512_W_L$1 = /* @__PURE__ */ new Uint32Array(80);
|
|
2449
|
+
let SHA512$1 = class SHA512 extends HashMD$1 {
|
|
2450
|
+
constructor(outputLen = 64) {
|
|
2451
|
+
super(128, outputLen, 16, false);
|
|
2452
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
2453
|
+
this.Al = SHA512_IV[1] | 0;
|
|
2454
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
2455
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
2456
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
2457
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
2458
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
2459
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
2460
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
2461
|
+
this.El = SHA512_IV[9] | 0;
|
|
2462
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
2463
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
2464
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
2465
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
2466
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
2467
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
2468
|
+
}
|
|
2469
|
+
// prettier-ignore
|
|
2470
|
+
get() {
|
|
2471
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
2472
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
2473
|
+
}
|
|
2474
|
+
// prettier-ignore
|
|
2475
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
2476
|
+
this.Ah = Ah | 0;
|
|
2477
|
+
this.Al = Al | 0;
|
|
2478
|
+
this.Bh = Bh | 0;
|
|
2479
|
+
this.Bl = Bl | 0;
|
|
2480
|
+
this.Ch = Ch | 0;
|
|
2481
|
+
this.Cl = Cl | 0;
|
|
2482
|
+
this.Dh = Dh | 0;
|
|
2483
|
+
this.Dl = Dl | 0;
|
|
2484
|
+
this.Eh = Eh | 0;
|
|
2485
|
+
this.El = El | 0;
|
|
2486
|
+
this.Fh = Fh | 0;
|
|
2487
|
+
this.Fl = Fl | 0;
|
|
2488
|
+
this.Gh = Gh | 0;
|
|
2489
|
+
this.Gl = Gl | 0;
|
|
2490
|
+
this.Hh = Hh | 0;
|
|
2491
|
+
this.Hl = Hl | 0;
|
|
2492
|
+
}
|
|
2493
|
+
process(view, offset) {
|
|
2494
|
+
for (let i3 = 0; i3 < 16; i3++, offset += 4) {
|
|
2495
|
+
SHA512_W_H$1[i3] = view.getUint32(offset);
|
|
2496
|
+
SHA512_W_L$1[i3] = view.getUint32(offset += 4);
|
|
2497
|
+
}
|
|
2498
|
+
for (let i3 = 16; i3 < 80; i3++) {
|
|
2499
|
+
const W15h = SHA512_W_H$1[i3 - 15] | 0;
|
|
2500
|
+
const W15l = SHA512_W_L$1[i3 - 15] | 0;
|
|
2501
|
+
const s0h = rotrSH$1(W15h, W15l, 1) ^ rotrSH$1(W15h, W15l, 8) ^ shrSH$1(W15h, W15l, 7);
|
|
2502
|
+
const s0l = rotrSL$1(W15h, W15l, 1) ^ rotrSL$1(W15h, W15l, 8) ^ shrSL$1(W15h, W15l, 7);
|
|
2503
|
+
const W2h = SHA512_W_H$1[i3 - 2] | 0;
|
|
2504
|
+
const W2l = SHA512_W_L$1[i3 - 2] | 0;
|
|
2505
|
+
const s1h = rotrSH$1(W2h, W2l, 19) ^ rotrBH$1(W2h, W2l, 61) ^ shrSH$1(W2h, W2l, 6);
|
|
2506
|
+
const s1l = rotrSL$1(W2h, W2l, 19) ^ rotrBL$1(W2h, W2l, 61) ^ shrSL$1(W2h, W2l, 6);
|
|
2507
|
+
const SUMl = add4L$1(s0l, s1l, SHA512_W_L$1[i3 - 7], SHA512_W_L$1[i3 - 16]);
|
|
2508
|
+
const SUMh = add4H$1(SUMl, s0h, s1h, SHA512_W_H$1[i3 - 7], SHA512_W_H$1[i3 - 16]);
|
|
2509
|
+
SHA512_W_H$1[i3] = SUMh | 0;
|
|
2510
|
+
SHA512_W_L$1[i3] = SUMl | 0;
|
|
2511
|
+
}
|
|
2512
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
2513
|
+
for (let i3 = 0; i3 < 80; i3++) {
|
|
2514
|
+
const sigma1h = rotrSH$1(Eh, El, 14) ^ rotrSH$1(Eh, El, 18) ^ rotrBH$1(Eh, El, 41);
|
|
2515
|
+
const sigma1l = rotrSL$1(Eh, El, 14) ^ rotrSL$1(Eh, El, 18) ^ rotrBL$1(Eh, El, 41);
|
|
2516
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
2517
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
2518
|
+
const T1ll = add5L$1(Hl, sigma1l, CHIl, SHA512_Kl$1[i3], SHA512_W_L$1[i3]);
|
|
2519
|
+
const T1h = add5H$1(T1ll, Hh, sigma1h, CHIh, SHA512_Kh$1[i3], SHA512_W_H$1[i3]);
|
|
2520
|
+
const T1l = T1ll | 0;
|
|
2521
|
+
const sigma0h = rotrSH$1(Ah, Al, 28) ^ rotrBH$1(Ah, Al, 34) ^ rotrBH$1(Ah, Al, 39);
|
|
2522
|
+
const sigma0l = rotrSL$1(Ah, Al, 28) ^ rotrBL$1(Ah, Al, 34) ^ rotrBL$1(Ah, Al, 39);
|
|
2523
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
2524
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
2525
|
+
Hh = Gh | 0;
|
|
2526
|
+
Hl = Gl | 0;
|
|
2527
|
+
Gh = Fh | 0;
|
|
2528
|
+
Gl = Fl | 0;
|
|
2529
|
+
Fh = Eh | 0;
|
|
2530
|
+
Fl = El | 0;
|
|
2531
|
+
({ h: Eh, l: El } = add$1(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
2532
|
+
Dh = Ch | 0;
|
|
2533
|
+
Dl = Cl | 0;
|
|
2534
|
+
Ch = Bh | 0;
|
|
2535
|
+
Cl = Bl | 0;
|
|
2536
|
+
Bh = Ah | 0;
|
|
2537
|
+
Bl = Al | 0;
|
|
2538
|
+
const All = add3L$1(T1l, sigma0l, MAJl);
|
|
2539
|
+
Ah = add3H$1(All, T1h, sigma0h, MAJh);
|
|
2540
|
+
Al = All | 0;
|
|
2541
|
+
}
|
|
2542
|
+
({ h: Ah, l: Al } = add$1(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
2543
|
+
({ h: Bh, l: Bl } = add$1(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
2544
|
+
({ h: Ch, l: Cl } = add$1(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
2545
|
+
({ h: Dh, l: Dl } = add$1(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
2546
|
+
({ h: Eh, l: El } = add$1(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
2547
|
+
({ h: Fh, l: Fl } = add$1(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
2548
|
+
({ h: Gh, l: Gl } = add$1(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
2549
|
+
({ h: Hh, l: Hl } = add$1(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
2550
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
2551
|
+
}
|
|
2552
|
+
roundClean() {
|
|
2553
|
+
clean(SHA512_W_H$1, SHA512_W_L$1);
|
|
2554
|
+
}
|
|
2555
|
+
destroy() {
|
|
2556
|
+
clean(this.buffer);
|
|
2557
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
2558
|
+
}
|
|
2559
|
+
};
|
|
2237
2560
|
const sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256$1());
|
|
2561
|
+
const sha512$1 = /* @__PURE__ */ createHasher(() => new SHA512$1());
|
|
2238
2562
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2239
2563
|
function isBytes$4(a5) {
|
|
2240
2564
|
return a5 instanceof Uint8Array || ArrayBuffer.isView(a5) && a5.constructor.name === "Uint8Array";
|
|
@@ -4606,38 +4930,718 @@ zebra
|
|
|
4606
4930
|
zero
|
|
4607
4931
|
zone
|
|
4608
4932
|
zoo`.split("\n");
|
|
4609
|
-
|
|
4610
|
-
const
|
|
4611
|
-
const
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
const
|
|
4615
|
-
|
|
4616
|
-
const SHA3_ROTL$1 = [];
|
|
4617
|
-
const _SHA3_IOTA$1 = [];
|
|
4618
|
-
for (let round = 0, R2 = _1n$6, x2 = 1, y3 = 0; round < 24; round++) {
|
|
4619
|
-
[x2, y3] = [y3, (2 * x2 + 3 * y3) % 5];
|
|
4620
|
-
SHA3_PI$1.push(2 * (5 * y3 + x2));
|
|
4621
|
-
SHA3_ROTL$1.push((round + 1) * (round + 2) / 2 % 64);
|
|
4622
|
-
let t6 = _0n$5;
|
|
4623
|
-
for (let j = 0; j < 7; j++) {
|
|
4624
|
-
R2 = (R2 << _1n$6 ^ (R2 >> _7n$1) * _0x71n$1) % _256n$1;
|
|
4625
|
-
if (R2 & _2n$4)
|
|
4626
|
-
t6 ^= _1n$6 << (_1n$6 << /* @__PURE__ */ BigInt(j)) - _1n$6;
|
|
4933
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
4934
|
+
const _0n$a = /* @__PURE__ */ BigInt(0);
|
|
4935
|
+
const _1n$c = /* @__PURE__ */ BigInt(1);
|
|
4936
|
+
function _abool2(value, title = "") {
|
|
4937
|
+
if (typeof value !== "boolean") {
|
|
4938
|
+
const prefix = title && `"${title}"`;
|
|
4939
|
+
throw new Error(prefix + "expected boolean, got type=" + typeof value);
|
|
4627
4940
|
}
|
|
4628
|
-
|
|
4941
|
+
return value;
|
|
4629
4942
|
}
|
|
4630
|
-
|
|
4631
|
-
const
|
|
4632
|
-
const
|
|
4633
|
-
const
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4943
|
+
function _abytes2(value, length, title = "") {
|
|
4944
|
+
const bytes = isBytes$5(value);
|
|
4945
|
+
const len = value == null ? void 0 : value.length;
|
|
4946
|
+
const needsLen = length !== void 0;
|
|
4947
|
+
if (!bytes || needsLen && len !== length) {
|
|
4948
|
+
const prefix = title && `"${title}" `;
|
|
4949
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
4950
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
4951
|
+
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
4952
|
+
}
|
|
4953
|
+
return value;
|
|
4954
|
+
}
|
|
4955
|
+
function hexToNumber$1(hex) {
|
|
4956
|
+
if (typeof hex !== "string")
|
|
4957
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
4958
|
+
return hex === "" ? _0n$a : BigInt("0x" + hex);
|
|
4959
|
+
}
|
|
4960
|
+
function bytesToNumberBE$1(bytes) {
|
|
4961
|
+
return hexToNumber$1(bytesToHex$2(bytes));
|
|
4962
|
+
}
|
|
4963
|
+
function bytesToNumberLE$1(bytes) {
|
|
4964
|
+
abytes$2(bytes);
|
|
4965
|
+
return hexToNumber$1(bytesToHex$2(Uint8Array.from(bytes).reverse()));
|
|
4966
|
+
}
|
|
4967
|
+
function numberToBytesBE$1(n4, len) {
|
|
4968
|
+
return hexToBytes$2(n4.toString(16).padStart(len * 2, "0"));
|
|
4969
|
+
}
|
|
4970
|
+
function numberToBytesLE$1(n4, len) {
|
|
4971
|
+
return numberToBytesBE$1(n4, len).reverse();
|
|
4972
|
+
}
|
|
4973
|
+
function ensureBytes$1(title, hex, expectedLength) {
|
|
4974
|
+
let res;
|
|
4975
|
+
if (typeof hex === "string") {
|
|
4976
|
+
try {
|
|
4977
|
+
res = hexToBytes$2(hex);
|
|
4978
|
+
} catch (e4) {
|
|
4979
|
+
throw new Error(title + " must be hex string or Uint8Array, cause: " + e4);
|
|
4980
|
+
}
|
|
4981
|
+
} else if (isBytes$5(hex)) {
|
|
4982
|
+
res = Uint8Array.from(hex);
|
|
4983
|
+
} else {
|
|
4984
|
+
throw new Error(title + " must be hex string or Uint8Array");
|
|
4985
|
+
}
|
|
4986
|
+
const len = res.length;
|
|
4987
|
+
if (typeof expectedLength === "number" && len !== expectedLength)
|
|
4988
|
+
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
4989
|
+
return res;
|
|
4990
|
+
}
|
|
4991
|
+
function copyBytes(bytes) {
|
|
4992
|
+
return Uint8Array.from(bytes);
|
|
4993
|
+
}
|
|
4994
|
+
const isPosBig$1 = (n4) => typeof n4 === "bigint" && _0n$a <= n4;
|
|
4995
|
+
function inRange$1(n4, min, max) {
|
|
4996
|
+
return isPosBig$1(n4) && isPosBig$1(min) && isPosBig$1(max) && min <= n4 && n4 < max;
|
|
4997
|
+
}
|
|
4998
|
+
function aInRange$1(title, n4, min, max) {
|
|
4999
|
+
if (!inRange$1(n4, min, max))
|
|
5000
|
+
throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n4);
|
|
5001
|
+
}
|
|
5002
|
+
function bitLen$1(n4) {
|
|
5003
|
+
let len;
|
|
5004
|
+
for (len = 0; n4 > _0n$a; n4 >>= _1n$c, len += 1)
|
|
5005
|
+
;
|
|
5006
|
+
return len;
|
|
5007
|
+
}
|
|
5008
|
+
const bitMask$1 = (n4) => (_1n$c << BigInt(n4)) - _1n$c;
|
|
5009
|
+
function _validateObject(object, fields, optFields = {}) {
|
|
5010
|
+
if (!object || typeof object !== "object")
|
|
5011
|
+
throw new Error("expected valid options object");
|
|
5012
|
+
function checkField(fieldName, expectedType, isOpt) {
|
|
5013
|
+
const val = object[fieldName];
|
|
5014
|
+
if (isOpt && val === void 0)
|
|
5015
|
+
return;
|
|
5016
|
+
const current = typeof val;
|
|
5017
|
+
if (current !== expectedType || val === null)
|
|
5018
|
+
throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
5019
|
+
}
|
|
5020
|
+
Object.entries(fields).forEach(([k2, v2]) => checkField(k2, v2, false));
|
|
5021
|
+
Object.entries(optFields).forEach(([k2, v2]) => checkField(k2, v2, true));
|
|
5022
|
+
}
|
|
5023
|
+
function memoized$1(fn) {
|
|
5024
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
5025
|
+
return (arg, ...args) => {
|
|
5026
|
+
const val = map.get(arg);
|
|
5027
|
+
if (val !== void 0)
|
|
5028
|
+
return val;
|
|
5029
|
+
const computed = fn(arg, ...args);
|
|
5030
|
+
map.set(arg, computed);
|
|
5031
|
+
return computed;
|
|
5032
|
+
};
|
|
5033
|
+
}
|
|
5034
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5035
|
+
const _0n$9 = BigInt(0), _1n$b = BigInt(1), _2n$8 = /* @__PURE__ */ BigInt(2), _3n$3 = /* @__PURE__ */ BigInt(3);
|
|
5036
|
+
const _4n$1 = /* @__PURE__ */ BigInt(4), _5n$2 = /* @__PURE__ */ BigInt(5), _7n$2 = /* @__PURE__ */ BigInt(7);
|
|
5037
|
+
const _8n$3 = /* @__PURE__ */ BigInt(8), _9n = /* @__PURE__ */ BigInt(9), _16n = /* @__PURE__ */ BigInt(16);
|
|
5038
|
+
function mod$1(a5, b2) {
|
|
5039
|
+
const result = a5 % b2;
|
|
5040
|
+
return result >= _0n$9 ? result : b2 + result;
|
|
5041
|
+
}
|
|
5042
|
+
function pow2$1(x2, power, modulo) {
|
|
5043
|
+
let res = x2;
|
|
5044
|
+
while (power-- > _0n$9) {
|
|
5045
|
+
res *= res;
|
|
5046
|
+
res %= modulo;
|
|
5047
|
+
}
|
|
5048
|
+
return res;
|
|
5049
|
+
}
|
|
5050
|
+
function invert$1(number, modulo) {
|
|
5051
|
+
if (number === _0n$9)
|
|
5052
|
+
throw new Error("invert: expected non-zero number");
|
|
5053
|
+
if (modulo <= _0n$9)
|
|
5054
|
+
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
5055
|
+
let a5 = mod$1(number, modulo);
|
|
5056
|
+
let b2 = modulo;
|
|
5057
|
+
let x2 = _0n$9, u4 = _1n$b;
|
|
5058
|
+
while (a5 !== _0n$9) {
|
|
5059
|
+
const q2 = b2 / a5;
|
|
5060
|
+
const r7 = b2 % a5;
|
|
5061
|
+
const m2 = x2 - u4 * q2;
|
|
5062
|
+
b2 = a5, a5 = r7, x2 = u4, u4 = m2;
|
|
5063
|
+
}
|
|
5064
|
+
const gcd2 = b2;
|
|
5065
|
+
if (gcd2 !== _1n$b)
|
|
5066
|
+
throw new Error("invert: does not exist");
|
|
5067
|
+
return mod$1(x2, modulo);
|
|
5068
|
+
}
|
|
5069
|
+
function assertIsSquare(Fp2, root2, n4) {
|
|
5070
|
+
if (!Fp2.eql(Fp2.sqr(root2), n4))
|
|
5071
|
+
throw new Error("Cannot find square root");
|
|
5072
|
+
}
|
|
5073
|
+
function sqrt3mod4(Fp2, n4) {
|
|
5074
|
+
const p1div4 = (Fp2.ORDER + _1n$b) / _4n$1;
|
|
5075
|
+
const root2 = Fp2.pow(n4, p1div4);
|
|
5076
|
+
assertIsSquare(Fp2, root2, n4);
|
|
5077
|
+
return root2;
|
|
5078
|
+
}
|
|
5079
|
+
function sqrt5mod8(Fp2, n4) {
|
|
5080
|
+
const p5div8 = (Fp2.ORDER - _5n$2) / _8n$3;
|
|
5081
|
+
const n22 = Fp2.mul(n4, _2n$8);
|
|
5082
|
+
const v2 = Fp2.pow(n22, p5div8);
|
|
5083
|
+
const nv = Fp2.mul(n4, v2);
|
|
5084
|
+
const i3 = Fp2.mul(Fp2.mul(nv, _2n$8), v2);
|
|
5085
|
+
const root2 = Fp2.mul(nv, Fp2.sub(i3, Fp2.ONE));
|
|
5086
|
+
assertIsSquare(Fp2, root2, n4);
|
|
5087
|
+
return root2;
|
|
5088
|
+
}
|
|
5089
|
+
function sqrt9mod16(P2) {
|
|
5090
|
+
const Fp_ = Field$1(P2);
|
|
5091
|
+
const tn = tonelliShanks$1(P2);
|
|
5092
|
+
const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));
|
|
5093
|
+
const c22 = tn(Fp_, c1);
|
|
5094
|
+
const c3 = tn(Fp_, Fp_.neg(c1));
|
|
5095
|
+
const c4 = (P2 + _7n$2) / _16n;
|
|
5096
|
+
return (Fp2, n4) => {
|
|
5097
|
+
let tv1 = Fp2.pow(n4, c4);
|
|
5098
|
+
let tv2 = Fp2.mul(tv1, c1);
|
|
5099
|
+
const tv3 = Fp2.mul(tv1, c22);
|
|
5100
|
+
const tv4 = Fp2.mul(tv1, c3);
|
|
5101
|
+
const e1 = Fp2.eql(Fp2.sqr(tv2), n4);
|
|
5102
|
+
const e22 = Fp2.eql(Fp2.sqr(tv3), n4);
|
|
5103
|
+
tv1 = Fp2.cmov(tv1, tv2, e1);
|
|
5104
|
+
tv2 = Fp2.cmov(tv4, tv3, e22);
|
|
5105
|
+
const e32 = Fp2.eql(Fp2.sqr(tv2), n4);
|
|
5106
|
+
const root2 = Fp2.cmov(tv1, tv2, e32);
|
|
5107
|
+
assertIsSquare(Fp2, root2, n4);
|
|
5108
|
+
return root2;
|
|
5109
|
+
};
|
|
5110
|
+
}
|
|
5111
|
+
function tonelliShanks$1(P2) {
|
|
5112
|
+
if (P2 < _3n$3)
|
|
5113
|
+
throw new Error("sqrt is not defined for small field");
|
|
5114
|
+
let Q = P2 - _1n$b;
|
|
5115
|
+
let S2 = 0;
|
|
5116
|
+
while (Q % _2n$8 === _0n$9) {
|
|
5117
|
+
Q /= _2n$8;
|
|
5118
|
+
S2++;
|
|
5119
|
+
}
|
|
5120
|
+
let Z = _2n$8;
|
|
5121
|
+
const _Fp = Field$1(P2);
|
|
5122
|
+
while (FpLegendre(_Fp, Z) === 1) {
|
|
5123
|
+
if (Z++ > 1e3)
|
|
5124
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
5125
|
+
}
|
|
5126
|
+
if (S2 === 1)
|
|
5127
|
+
return sqrt3mod4;
|
|
5128
|
+
let cc = _Fp.pow(Z, Q);
|
|
5129
|
+
const Q1div2 = (Q + _1n$b) / _2n$8;
|
|
5130
|
+
return function tonelliSlow(Fp2, n4) {
|
|
5131
|
+
if (Fp2.is0(n4))
|
|
5132
|
+
return n4;
|
|
5133
|
+
if (FpLegendre(Fp2, n4) !== 1)
|
|
5134
|
+
throw new Error("Cannot find square root");
|
|
5135
|
+
let M2 = S2;
|
|
5136
|
+
let c3 = Fp2.mul(Fp2.ONE, cc);
|
|
5137
|
+
let t6 = Fp2.pow(n4, Q);
|
|
5138
|
+
let R2 = Fp2.pow(n4, Q1div2);
|
|
5139
|
+
while (!Fp2.eql(t6, Fp2.ONE)) {
|
|
5140
|
+
if (Fp2.is0(t6))
|
|
5141
|
+
return Fp2.ZERO;
|
|
5142
|
+
let i3 = 1;
|
|
5143
|
+
let t_tmp = Fp2.sqr(t6);
|
|
5144
|
+
while (!Fp2.eql(t_tmp, Fp2.ONE)) {
|
|
5145
|
+
i3++;
|
|
5146
|
+
t_tmp = Fp2.sqr(t_tmp);
|
|
5147
|
+
if (i3 === M2)
|
|
5148
|
+
throw new Error("Cannot find square root");
|
|
5149
|
+
}
|
|
5150
|
+
const exponent = _1n$b << BigInt(M2 - i3 - 1);
|
|
5151
|
+
const b2 = Fp2.pow(c3, exponent);
|
|
5152
|
+
M2 = i3;
|
|
5153
|
+
c3 = Fp2.sqr(b2);
|
|
5154
|
+
t6 = Fp2.mul(t6, c3);
|
|
5155
|
+
R2 = Fp2.mul(R2, b2);
|
|
5156
|
+
}
|
|
5157
|
+
return R2;
|
|
5158
|
+
};
|
|
5159
|
+
}
|
|
5160
|
+
function FpSqrt$1(P2) {
|
|
5161
|
+
if (P2 % _4n$1 === _3n$3)
|
|
5162
|
+
return sqrt3mod4;
|
|
5163
|
+
if (P2 % _8n$3 === _5n$2)
|
|
5164
|
+
return sqrt5mod8;
|
|
5165
|
+
if (P2 % _16n === _9n)
|
|
5166
|
+
return sqrt9mod16(P2);
|
|
5167
|
+
return tonelliShanks$1(P2);
|
|
5168
|
+
}
|
|
5169
|
+
const isNegativeLE = (num, modulo) => (mod$1(num, modulo) & _1n$b) === _1n$b;
|
|
5170
|
+
const FIELD_FIELDS$1 = [
|
|
5171
|
+
"create",
|
|
5172
|
+
"isValid",
|
|
5173
|
+
"is0",
|
|
5174
|
+
"neg",
|
|
5175
|
+
"inv",
|
|
5176
|
+
"sqrt",
|
|
5177
|
+
"sqr",
|
|
5178
|
+
"eql",
|
|
5179
|
+
"add",
|
|
5180
|
+
"sub",
|
|
5181
|
+
"mul",
|
|
5182
|
+
"pow",
|
|
5183
|
+
"div",
|
|
5184
|
+
"addN",
|
|
5185
|
+
"subN",
|
|
5186
|
+
"mulN",
|
|
5187
|
+
"sqrN"
|
|
5188
|
+
];
|
|
5189
|
+
function validateField$1(field) {
|
|
5190
|
+
const initial = {
|
|
5191
|
+
ORDER: "bigint",
|
|
5192
|
+
MASK: "bigint",
|
|
5193
|
+
BYTES: "number",
|
|
5194
|
+
BITS: "number"
|
|
5195
|
+
};
|
|
5196
|
+
const opts = FIELD_FIELDS$1.reduce((map, val) => {
|
|
5197
|
+
map[val] = "function";
|
|
5198
|
+
return map;
|
|
5199
|
+
}, initial);
|
|
5200
|
+
_validateObject(field, opts);
|
|
5201
|
+
return field;
|
|
5202
|
+
}
|
|
5203
|
+
function FpPow$1(Fp2, num, power) {
|
|
5204
|
+
if (power < _0n$9)
|
|
5205
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
5206
|
+
if (power === _0n$9)
|
|
5207
|
+
return Fp2.ONE;
|
|
5208
|
+
if (power === _1n$b)
|
|
5209
|
+
return num;
|
|
5210
|
+
let p5 = Fp2.ONE;
|
|
5211
|
+
let d2 = num;
|
|
5212
|
+
while (power > _0n$9) {
|
|
5213
|
+
if (power & _1n$b)
|
|
5214
|
+
p5 = Fp2.mul(p5, d2);
|
|
5215
|
+
d2 = Fp2.sqr(d2);
|
|
5216
|
+
power >>= _1n$b;
|
|
5217
|
+
}
|
|
5218
|
+
return p5;
|
|
5219
|
+
}
|
|
5220
|
+
function FpInvertBatch$1(Fp2, nums, passZero = false) {
|
|
5221
|
+
const inverted = new Array(nums.length).fill(passZero ? Fp2.ZERO : void 0);
|
|
5222
|
+
const multipliedAcc = nums.reduce((acc, num, i3) => {
|
|
5223
|
+
if (Fp2.is0(num))
|
|
5224
|
+
return acc;
|
|
5225
|
+
inverted[i3] = acc;
|
|
5226
|
+
return Fp2.mul(acc, num);
|
|
5227
|
+
}, Fp2.ONE);
|
|
5228
|
+
const invertedAcc = Fp2.inv(multipliedAcc);
|
|
5229
|
+
nums.reduceRight((acc, num, i3) => {
|
|
5230
|
+
if (Fp2.is0(num))
|
|
5231
|
+
return acc;
|
|
5232
|
+
inverted[i3] = Fp2.mul(acc, inverted[i3]);
|
|
5233
|
+
return Fp2.mul(acc, num);
|
|
5234
|
+
}, invertedAcc);
|
|
5235
|
+
return inverted;
|
|
5236
|
+
}
|
|
5237
|
+
function FpLegendre(Fp2, n4) {
|
|
5238
|
+
const p1mod2 = (Fp2.ORDER - _1n$b) / _2n$8;
|
|
5239
|
+
const powered = Fp2.pow(n4, p1mod2);
|
|
5240
|
+
const yes = Fp2.eql(powered, Fp2.ONE);
|
|
5241
|
+
const zero = Fp2.eql(powered, Fp2.ZERO);
|
|
5242
|
+
const no = Fp2.eql(powered, Fp2.neg(Fp2.ONE));
|
|
5243
|
+
if (!yes && !zero && !no)
|
|
5244
|
+
throw new Error("invalid Legendre symbol result");
|
|
5245
|
+
return yes ? 1 : zero ? 0 : -1;
|
|
5246
|
+
}
|
|
5247
|
+
function nLength$1(n4, nBitLength) {
|
|
5248
|
+
if (nBitLength !== void 0)
|
|
5249
|
+
anumber$3(nBitLength);
|
|
5250
|
+
const _nBitLength = nBitLength !== void 0 ? nBitLength : n4.toString(2).length;
|
|
5251
|
+
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
5252
|
+
return { nBitLength: _nBitLength, nByteLength };
|
|
5253
|
+
}
|
|
5254
|
+
function Field$1(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
|
|
5255
|
+
if (ORDER <= _0n$9)
|
|
5256
|
+
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
5257
|
+
let _nbitLength = void 0;
|
|
5258
|
+
let _sqrt = void 0;
|
|
5259
|
+
let modFromBytes = false;
|
|
5260
|
+
let allowedLengths = void 0;
|
|
5261
|
+
if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
|
|
5262
|
+
if (opts.sqrt || isLE2)
|
|
5263
|
+
throw new Error("cannot specify opts in two arguments");
|
|
5264
|
+
const _opts = bitLenOrOpts;
|
|
5265
|
+
if (_opts.BITS)
|
|
5266
|
+
_nbitLength = _opts.BITS;
|
|
5267
|
+
if (_opts.sqrt)
|
|
5268
|
+
_sqrt = _opts.sqrt;
|
|
5269
|
+
if (typeof _opts.isLE === "boolean")
|
|
5270
|
+
isLE2 = _opts.isLE;
|
|
5271
|
+
if (typeof _opts.modFromBytes === "boolean")
|
|
5272
|
+
modFromBytes = _opts.modFromBytes;
|
|
5273
|
+
allowedLengths = _opts.allowedLengths;
|
|
5274
|
+
} else {
|
|
5275
|
+
if (typeof bitLenOrOpts === "number")
|
|
5276
|
+
_nbitLength = bitLenOrOpts;
|
|
5277
|
+
if (opts.sqrt)
|
|
5278
|
+
_sqrt = opts.sqrt;
|
|
5279
|
+
}
|
|
5280
|
+
const { nBitLength: BITS, nByteLength: BYTES } = nLength$1(ORDER, _nbitLength);
|
|
5281
|
+
if (BYTES > 2048)
|
|
5282
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
5283
|
+
let sqrtP;
|
|
5284
|
+
const f3 = Object.freeze({
|
|
5285
|
+
ORDER,
|
|
5286
|
+
isLE: isLE2,
|
|
5287
|
+
BITS,
|
|
5288
|
+
BYTES,
|
|
5289
|
+
MASK: bitMask$1(BITS),
|
|
5290
|
+
ZERO: _0n$9,
|
|
5291
|
+
ONE: _1n$b,
|
|
5292
|
+
allowedLengths,
|
|
5293
|
+
create: (num) => mod$1(num, ORDER),
|
|
5294
|
+
isValid: (num) => {
|
|
5295
|
+
if (typeof num !== "bigint")
|
|
5296
|
+
throw new Error("invalid field element: expected bigint, got " + typeof num);
|
|
5297
|
+
return _0n$9 <= num && num < ORDER;
|
|
5298
|
+
},
|
|
5299
|
+
is0: (num) => num === _0n$9,
|
|
5300
|
+
// is valid and invertible
|
|
5301
|
+
isValidNot0: (num) => !f3.is0(num) && f3.isValid(num),
|
|
5302
|
+
isOdd: (num) => (num & _1n$b) === _1n$b,
|
|
5303
|
+
neg: (num) => mod$1(-num, ORDER),
|
|
5304
|
+
eql: (lhs, rhs) => lhs === rhs,
|
|
5305
|
+
sqr: (num) => mod$1(num * num, ORDER),
|
|
5306
|
+
add: (lhs, rhs) => mod$1(lhs + rhs, ORDER),
|
|
5307
|
+
sub: (lhs, rhs) => mod$1(lhs - rhs, ORDER),
|
|
5308
|
+
mul: (lhs, rhs) => mod$1(lhs * rhs, ORDER),
|
|
5309
|
+
pow: (num, power) => FpPow$1(f3, num, power),
|
|
5310
|
+
div: (lhs, rhs) => mod$1(lhs * invert$1(rhs, ORDER), ORDER),
|
|
5311
|
+
// Same as above, but doesn't normalize
|
|
5312
|
+
sqrN: (num) => num * num,
|
|
5313
|
+
addN: (lhs, rhs) => lhs + rhs,
|
|
5314
|
+
subN: (lhs, rhs) => lhs - rhs,
|
|
5315
|
+
mulN: (lhs, rhs) => lhs * rhs,
|
|
5316
|
+
inv: (num) => invert$1(num, ORDER),
|
|
5317
|
+
sqrt: _sqrt || ((n4) => {
|
|
5318
|
+
if (!sqrtP)
|
|
5319
|
+
sqrtP = FpSqrt$1(ORDER);
|
|
5320
|
+
return sqrtP(f3, n4);
|
|
5321
|
+
}),
|
|
5322
|
+
toBytes: (num) => isLE2 ? numberToBytesLE$1(num, BYTES) : numberToBytesBE$1(num, BYTES),
|
|
5323
|
+
fromBytes: (bytes, skipValidation = true) => {
|
|
5324
|
+
if (allowedLengths) {
|
|
5325
|
+
if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
|
|
5326
|
+
throw new Error("Field.fromBytes: expected " + allowedLengths + " bytes, got " + bytes.length);
|
|
5327
|
+
}
|
|
5328
|
+
const padded = new Uint8Array(BYTES);
|
|
5329
|
+
padded.set(bytes, isLE2 ? 0 : padded.length - bytes.length);
|
|
5330
|
+
bytes = padded;
|
|
5331
|
+
}
|
|
5332
|
+
if (bytes.length !== BYTES)
|
|
5333
|
+
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
5334
|
+
let scalar = isLE2 ? bytesToNumberLE$1(bytes) : bytesToNumberBE$1(bytes);
|
|
5335
|
+
if (modFromBytes)
|
|
5336
|
+
scalar = mod$1(scalar, ORDER);
|
|
5337
|
+
if (!skipValidation) {
|
|
5338
|
+
if (!f3.isValid(scalar))
|
|
5339
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
5340
|
+
}
|
|
5341
|
+
return scalar;
|
|
5342
|
+
},
|
|
5343
|
+
// TODO: we don't need it here, move out to separate fn
|
|
5344
|
+
invertBatch: (lst) => FpInvertBatch$1(f3, lst),
|
|
5345
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
5346
|
+
// and it's unclear what to return in there.
|
|
5347
|
+
cmov: (a5, b2, c3) => c3 ? b2 : a5
|
|
5348
|
+
});
|
|
5349
|
+
return Object.freeze(f3);
|
|
5350
|
+
}
|
|
5351
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5352
|
+
const _0n$8 = BigInt(0);
|
|
5353
|
+
const _1n$a = BigInt(1);
|
|
5354
|
+
function negateCt(condition, item) {
|
|
5355
|
+
const neg = item.negate();
|
|
5356
|
+
return condition ? neg : item;
|
|
5357
|
+
}
|
|
5358
|
+
function normalizeZ(c3, points) {
|
|
5359
|
+
const invertedZs = FpInvertBatch$1(c3.Fp, points.map((p5) => p5.Z));
|
|
5360
|
+
return points.map((p5, i3) => c3.fromAffine(p5.toAffine(invertedZs[i3])));
|
|
5361
|
+
}
|
|
5362
|
+
function validateW$1(W2, bits) {
|
|
5363
|
+
if (!Number.isSafeInteger(W2) || W2 <= 0 || W2 > bits)
|
|
5364
|
+
throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W2);
|
|
5365
|
+
}
|
|
5366
|
+
function calcWOpts$1(W2, scalarBits) {
|
|
5367
|
+
validateW$1(W2, scalarBits);
|
|
5368
|
+
const windows = Math.ceil(scalarBits / W2) + 1;
|
|
5369
|
+
const windowSize = 2 ** (W2 - 1);
|
|
5370
|
+
const maxNumber = 2 ** W2;
|
|
5371
|
+
const mask = bitMask$1(W2);
|
|
5372
|
+
const shiftBy = BigInt(W2);
|
|
5373
|
+
return { windows, windowSize, mask, maxNumber, shiftBy };
|
|
5374
|
+
}
|
|
5375
|
+
function calcOffsets(n4, window2, wOpts) {
|
|
5376
|
+
const { windowSize, mask, maxNumber, shiftBy } = wOpts;
|
|
5377
|
+
let wbits = Number(n4 & mask);
|
|
5378
|
+
let nextN = n4 >> shiftBy;
|
|
5379
|
+
if (wbits > windowSize) {
|
|
5380
|
+
wbits -= maxNumber;
|
|
5381
|
+
nextN += _1n$a;
|
|
5382
|
+
}
|
|
5383
|
+
const offsetStart = window2 * windowSize;
|
|
5384
|
+
const offset = offsetStart + Math.abs(wbits) - 1;
|
|
5385
|
+
const isZero = wbits === 0;
|
|
5386
|
+
const isNeg = wbits < 0;
|
|
5387
|
+
const isNegF = window2 % 2 !== 0;
|
|
5388
|
+
const offsetF = offsetStart;
|
|
5389
|
+
return { nextN, offset, isZero, isNeg, isNegF, offsetF };
|
|
5390
|
+
}
|
|
5391
|
+
function validateMSMPoints$1(points, c3) {
|
|
5392
|
+
if (!Array.isArray(points))
|
|
5393
|
+
throw new Error("array expected");
|
|
5394
|
+
points.forEach((p5, i3) => {
|
|
5395
|
+
if (!(p5 instanceof c3))
|
|
5396
|
+
throw new Error("invalid point at index " + i3);
|
|
5397
|
+
});
|
|
5398
|
+
}
|
|
5399
|
+
function validateMSMScalars$1(scalars, field) {
|
|
5400
|
+
if (!Array.isArray(scalars))
|
|
5401
|
+
throw new Error("array of scalars expected");
|
|
5402
|
+
scalars.forEach((s5, i3) => {
|
|
5403
|
+
if (!field.isValid(s5))
|
|
5404
|
+
throw new Error("invalid scalar at index " + i3);
|
|
5405
|
+
});
|
|
5406
|
+
}
|
|
5407
|
+
const pointPrecomputes$1 = /* @__PURE__ */ new WeakMap();
|
|
5408
|
+
const pointWindowSizes$1 = /* @__PURE__ */ new WeakMap();
|
|
5409
|
+
function getW$1(P2) {
|
|
5410
|
+
return pointWindowSizes$1.get(P2) || 1;
|
|
5411
|
+
}
|
|
5412
|
+
function assert0(n4) {
|
|
5413
|
+
if (n4 !== _0n$8)
|
|
5414
|
+
throw new Error("invalid wNAF");
|
|
5415
|
+
}
|
|
5416
|
+
let wNAF$2 = class wNAF {
|
|
5417
|
+
// Parametrized with a given Point class (not individual point)
|
|
5418
|
+
constructor(Point3, bits) {
|
|
5419
|
+
this.BASE = Point3.BASE;
|
|
5420
|
+
this.ZERO = Point3.ZERO;
|
|
5421
|
+
this.Fn = Point3.Fn;
|
|
5422
|
+
this.bits = bits;
|
|
5423
|
+
}
|
|
5424
|
+
// non-const time multiplication ladder
|
|
5425
|
+
_unsafeLadder(elm, n4, p5 = this.ZERO) {
|
|
5426
|
+
let d2 = elm;
|
|
5427
|
+
while (n4 > _0n$8) {
|
|
5428
|
+
if (n4 & _1n$a)
|
|
5429
|
+
p5 = p5.add(d2);
|
|
5430
|
+
d2 = d2.double();
|
|
5431
|
+
n4 >>= _1n$a;
|
|
5432
|
+
}
|
|
5433
|
+
return p5;
|
|
5434
|
+
}
|
|
5435
|
+
/**
|
|
5436
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
5437
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
5438
|
+
* Number of precomputed points depends on the curve size:
|
|
5439
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
5440
|
+
* - 𝑊 is the window size
|
|
5441
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
5442
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
5443
|
+
* @param point Point instance
|
|
5444
|
+
* @param W window size
|
|
5445
|
+
* @returns precomputed point tables flattened to a single array
|
|
5446
|
+
*/
|
|
5447
|
+
precomputeWindow(point, W2) {
|
|
5448
|
+
const { windows, windowSize } = calcWOpts$1(W2, this.bits);
|
|
5449
|
+
const points = [];
|
|
5450
|
+
let p5 = point;
|
|
5451
|
+
let base = p5;
|
|
5452
|
+
for (let window2 = 0; window2 < windows; window2++) {
|
|
5453
|
+
base = p5;
|
|
5454
|
+
points.push(base);
|
|
5455
|
+
for (let i3 = 1; i3 < windowSize; i3++) {
|
|
5456
|
+
base = base.add(p5);
|
|
5457
|
+
points.push(base);
|
|
5458
|
+
}
|
|
5459
|
+
p5 = base.double();
|
|
5460
|
+
}
|
|
5461
|
+
return points;
|
|
5462
|
+
}
|
|
5463
|
+
/**
|
|
5464
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
5465
|
+
* More compact implementation:
|
|
5466
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
5467
|
+
* @returns real and fake (for const-time) points
|
|
5468
|
+
*/
|
|
5469
|
+
wNAF(W2, precomputes, n4) {
|
|
5470
|
+
if (!this.Fn.isValid(n4))
|
|
5471
|
+
throw new Error("invalid scalar");
|
|
5472
|
+
let p5 = this.ZERO;
|
|
5473
|
+
let f3 = this.BASE;
|
|
5474
|
+
const wo = calcWOpts$1(W2, this.bits);
|
|
5475
|
+
for (let window2 = 0; window2 < wo.windows; window2++) {
|
|
5476
|
+
const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n4, window2, wo);
|
|
5477
|
+
n4 = nextN;
|
|
5478
|
+
if (isZero) {
|
|
5479
|
+
f3 = f3.add(negateCt(isNegF, precomputes[offsetF]));
|
|
5480
|
+
} else {
|
|
5481
|
+
p5 = p5.add(negateCt(isNeg, precomputes[offset]));
|
|
5482
|
+
}
|
|
5483
|
+
}
|
|
5484
|
+
assert0(n4);
|
|
5485
|
+
return { p: p5, f: f3 };
|
|
5486
|
+
}
|
|
5487
|
+
/**
|
|
5488
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
5489
|
+
* @param acc accumulator point to add result of multiplication
|
|
5490
|
+
* @returns point
|
|
5491
|
+
*/
|
|
5492
|
+
wNAFUnsafe(W2, precomputes, n4, acc = this.ZERO) {
|
|
5493
|
+
const wo = calcWOpts$1(W2, this.bits);
|
|
5494
|
+
for (let window2 = 0; window2 < wo.windows; window2++) {
|
|
5495
|
+
if (n4 === _0n$8)
|
|
5496
|
+
break;
|
|
5497
|
+
const { nextN, offset, isZero, isNeg } = calcOffsets(n4, window2, wo);
|
|
5498
|
+
n4 = nextN;
|
|
5499
|
+
if (isZero) {
|
|
5500
|
+
continue;
|
|
5501
|
+
} else {
|
|
5502
|
+
const item = precomputes[offset];
|
|
5503
|
+
acc = acc.add(isNeg ? item.negate() : item);
|
|
5504
|
+
}
|
|
5505
|
+
}
|
|
5506
|
+
assert0(n4);
|
|
5507
|
+
return acc;
|
|
5508
|
+
}
|
|
5509
|
+
getPrecomputes(W2, point, transform) {
|
|
5510
|
+
let comp = pointPrecomputes$1.get(point);
|
|
5511
|
+
if (!comp) {
|
|
5512
|
+
comp = this.precomputeWindow(point, W2);
|
|
5513
|
+
if (W2 !== 1) {
|
|
5514
|
+
if (typeof transform === "function")
|
|
5515
|
+
comp = transform(comp);
|
|
5516
|
+
pointPrecomputes$1.set(point, comp);
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5519
|
+
return comp;
|
|
5520
|
+
}
|
|
5521
|
+
cached(point, scalar, transform) {
|
|
5522
|
+
const W2 = getW$1(point);
|
|
5523
|
+
return this.wNAF(W2, this.getPrecomputes(W2, point, transform), scalar);
|
|
5524
|
+
}
|
|
5525
|
+
unsafe(point, scalar, transform, prev) {
|
|
5526
|
+
const W2 = getW$1(point);
|
|
5527
|
+
if (W2 === 1)
|
|
5528
|
+
return this._unsafeLadder(point, scalar, prev);
|
|
5529
|
+
return this.wNAFUnsafe(W2, this.getPrecomputes(W2, point, transform), scalar, prev);
|
|
5530
|
+
}
|
|
5531
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
5532
|
+
// using windowed method. This specifies window size and
|
|
5533
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
5534
|
+
createCache(P2, W2) {
|
|
5535
|
+
validateW$1(W2, this.bits);
|
|
5536
|
+
pointWindowSizes$1.set(P2, W2);
|
|
5537
|
+
pointPrecomputes$1.delete(P2);
|
|
5538
|
+
}
|
|
5539
|
+
hasCache(elm) {
|
|
5540
|
+
return getW$1(elm) !== 1;
|
|
5541
|
+
}
|
|
5542
|
+
};
|
|
5543
|
+
function pippenger$1(c3, fieldN, points, scalars) {
|
|
5544
|
+
validateMSMPoints$1(points, c3);
|
|
5545
|
+
validateMSMScalars$1(scalars, fieldN);
|
|
5546
|
+
const plength = points.length;
|
|
5547
|
+
const slength = scalars.length;
|
|
5548
|
+
if (plength !== slength)
|
|
5549
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
5550
|
+
const zero = c3.ZERO;
|
|
5551
|
+
const wbits = bitLen$1(BigInt(plength));
|
|
5552
|
+
let windowSize = 1;
|
|
5553
|
+
if (wbits > 12)
|
|
5554
|
+
windowSize = wbits - 3;
|
|
5555
|
+
else if (wbits > 4)
|
|
5556
|
+
windowSize = wbits - 2;
|
|
5557
|
+
else if (wbits > 0)
|
|
5558
|
+
windowSize = 2;
|
|
5559
|
+
const MASK = bitMask$1(windowSize);
|
|
5560
|
+
const buckets = new Array(Number(MASK) + 1).fill(zero);
|
|
5561
|
+
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
5562
|
+
let sum = zero;
|
|
5563
|
+
for (let i3 = lastBits; i3 >= 0; i3 -= windowSize) {
|
|
5564
|
+
buckets.fill(zero);
|
|
5565
|
+
for (let j = 0; j < slength; j++) {
|
|
5566
|
+
const scalar = scalars[j];
|
|
5567
|
+
const wbits2 = Number(scalar >> BigInt(i3) & MASK);
|
|
5568
|
+
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
5569
|
+
}
|
|
5570
|
+
let resI = zero;
|
|
5571
|
+
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
5572
|
+
sumI = sumI.add(buckets[j]);
|
|
5573
|
+
resI = resI.add(sumI);
|
|
5574
|
+
}
|
|
5575
|
+
sum = sum.add(resI);
|
|
5576
|
+
if (i3 !== 0)
|
|
5577
|
+
for (let j = 0; j < windowSize; j++)
|
|
5578
|
+
sum = sum.double();
|
|
5579
|
+
}
|
|
5580
|
+
return sum;
|
|
5581
|
+
}
|
|
5582
|
+
function createField(order, field, isLE2) {
|
|
5583
|
+
if (field) {
|
|
5584
|
+
if (field.ORDER !== order)
|
|
5585
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
5586
|
+
validateField$1(field);
|
|
5587
|
+
return field;
|
|
5588
|
+
} else {
|
|
5589
|
+
return Field$1(order, { isLE: isLE2 });
|
|
5590
|
+
}
|
|
5591
|
+
}
|
|
5592
|
+
function _createCurveFields(type2, CURVE2, curveOpts = {}, FpFnLE) {
|
|
5593
|
+
if (FpFnLE === void 0)
|
|
5594
|
+
FpFnLE = type2 === "edwards";
|
|
5595
|
+
if (!CURVE2 || typeof CURVE2 !== "object")
|
|
5596
|
+
throw new Error(`expected valid ${type2} CURVE object`);
|
|
5597
|
+
for (const p5 of ["p", "n", "h"]) {
|
|
5598
|
+
const val = CURVE2[p5];
|
|
5599
|
+
if (!(typeof val === "bigint" && val > _0n$8))
|
|
5600
|
+
throw new Error(`CURVE.${p5} must be positive bigint`);
|
|
5601
|
+
}
|
|
5602
|
+
const Fp2 = createField(CURVE2.p, curveOpts.Fp, FpFnLE);
|
|
5603
|
+
const Fn = createField(CURVE2.n, curveOpts.Fn, FpFnLE);
|
|
5604
|
+
const _b2 = "d";
|
|
5605
|
+
const params = ["Gx", "Gy", "a", _b2];
|
|
5606
|
+
for (const p5 of params) {
|
|
5607
|
+
if (!Fp2.isValid(CURVE2[p5]))
|
|
5608
|
+
throw new Error(`CURVE.${p5} must be valid field element of CURVE.Fp`);
|
|
5609
|
+
}
|
|
5610
|
+
CURVE2 = Object.freeze(Object.assign({}, CURVE2));
|
|
5611
|
+
return { CURVE: CURVE2, Fp: Fp2, Fn };
|
|
5612
|
+
}
|
|
5613
|
+
const _0n$7 = BigInt(0);
|
|
5614
|
+
const _1n$9 = BigInt(1);
|
|
5615
|
+
const _2n$7 = BigInt(2);
|
|
5616
|
+
const _7n$1 = BigInt(7);
|
|
5617
|
+
const _256n$1 = BigInt(256);
|
|
5618
|
+
const _0x71n$1 = BigInt(113);
|
|
5619
|
+
const SHA3_PI$1 = [];
|
|
5620
|
+
const SHA3_ROTL$1 = [];
|
|
5621
|
+
const _SHA3_IOTA$1 = [];
|
|
5622
|
+
for (let round = 0, R2 = _1n$9, x2 = 1, y3 = 0; round < 24; round++) {
|
|
5623
|
+
[x2, y3] = [y3, (2 * x2 + 3 * y3) % 5];
|
|
5624
|
+
SHA3_PI$1.push(2 * (5 * y3 + x2));
|
|
5625
|
+
SHA3_ROTL$1.push((round + 1) * (round + 2) / 2 % 64);
|
|
5626
|
+
let t6 = _0n$7;
|
|
5627
|
+
for (let j = 0; j < 7; j++) {
|
|
5628
|
+
R2 = (R2 << _1n$9 ^ (R2 >> _7n$1) * _0x71n$1) % _256n$1;
|
|
5629
|
+
if (R2 & _2n$7)
|
|
5630
|
+
t6 ^= _1n$9 << (_1n$9 << /* @__PURE__ */ BigInt(j)) - _1n$9;
|
|
5631
|
+
}
|
|
5632
|
+
_SHA3_IOTA$1.push(t6);
|
|
5633
|
+
}
|
|
5634
|
+
const IOTAS = split$1(_SHA3_IOTA$1, true);
|
|
5635
|
+
const SHA3_IOTA_H$1 = IOTAS[0];
|
|
5636
|
+
const SHA3_IOTA_L$1 = IOTAS[1];
|
|
5637
|
+
const rotlH$1 = (h2, l3, s5) => s5 > 32 ? rotlBH$1(h2, l3, s5) : rotlSH$1(h2, l3, s5);
|
|
5638
|
+
const rotlL$1 = (h2, l3, s5) => s5 > 32 ? rotlBL$1(h2, l3, s5) : rotlSL$1(h2, l3, s5);
|
|
5639
|
+
function keccakP$1(s5, rounds = 24) {
|
|
5640
|
+
const B = new Uint32Array(5 * 2);
|
|
5641
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
5642
|
+
for (let x2 = 0; x2 < 10; x2++)
|
|
5643
|
+
B[x2] = s5[x2] ^ s5[x2 + 10] ^ s5[x2 + 20] ^ s5[x2 + 30] ^ s5[x2 + 40];
|
|
5644
|
+
for (let x2 = 0; x2 < 10; x2 += 2) {
|
|
4641
5645
|
const idx1 = (x2 + 8) % 10;
|
|
4642
5646
|
const idx0 = (x2 + 2) % 10;
|
|
4643
5647
|
const B0 = B[idx0];
|
|
@@ -5127,14 +6131,14 @@ class SHA2562 extends HashMD2 {
|
|
|
5127
6131
|
this.H = SHA256_IV[7] | 0;
|
|
5128
6132
|
}
|
|
5129
6133
|
get() {
|
|
5130
|
-
const { A: A3, B, C:
|
|
5131
|
-
return [A3, B,
|
|
6134
|
+
const { A: A3, B, C: C2, D: D2, E: E2, F, G: G2, H } = this;
|
|
6135
|
+
return [A3, B, C2, D2, E2, F, G2, H];
|
|
5132
6136
|
}
|
|
5133
6137
|
// prettier-ignore
|
|
5134
|
-
set(A3, B,
|
|
6138
|
+
set(A3, B, C2, D2, E2, F, G2, H) {
|
|
5135
6139
|
this.A = A3 | 0;
|
|
5136
6140
|
this.B = B | 0;
|
|
5137
|
-
this.C =
|
|
6141
|
+
this.C = C2 | 0;
|
|
5138
6142
|
this.D = D2 | 0;
|
|
5139
6143
|
this.E = E2 | 0;
|
|
5140
6144
|
this.F = F | 0;
|
|
@@ -5151,30 +6155,30 @@ class SHA2562 extends HashMD2 {
|
|
|
5151
6155
|
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
5152
6156
|
SHA256_W[i3] = s1 + SHA256_W[i3 - 7] + s0 + SHA256_W[i3 - 16] | 0;
|
|
5153
6157
|
}
|
|
5154
|
-
let { A: A3, B, C:
|
|
6158
|
+
let { A: A3, B, C: C2, D: D2, E: E2, F, G: G2, H } = this;
|
|
5155
6159
|
for (let i3 = 0; i3 < 64; i3++) {
|
|
5156
6160
|
const sigma1 = rotr(E2, 6) ^ rotr(E2, 11) ^ rotr(E2, 25);
|
|
5157
6161
|
const T1 = H + sigma1 + Chi(E2, F, G2) + SHA256_K[i3] + SHA256_W[i3] | 0;
|
|
5158
6162
|
const sigma0 = rotr(A3, 2) ^ rotr(A3, 13) ^ rotr(A3, 22);
|
|
5159
|
-
const T22 = sigma0 + Maj(A3, B,
|
|
6163
|
+
const T22 = sigma0 + Maj(A3, B, C2) | 0;
|
|
5160
6164
|
H = G2;
|
|
5161
6165
|
G2 = F;
|
|
5162
6166
|
F = E2;
|
|
5163
6167
|
E2 = D2 + T1 | 0;
|
|
5164
|
-
D2 =
|
|
5165
|
-
|
|
6168
|
+
D2 = C2;
|
|
6169
|
+
C2 = B;
|
|
5166
6170
|
B = A3;
|
|
5167
6171
|
A3 = T1 + T22 | 0;
|
|
5168
6172
|
}
|
|
5169
6173
|
A3 = A3 + this.A | 0;
|
|
5170
6174
|
B = B + this.B | 0;
|
|
5171
|
-
|
|
6175
|
+
C2 = C2 + this.C | 0;
|
|
5172
6176
|
D2 = D2 + this.D | 0;
|
|
5173
6177
|
E2 = E2 + this.E | 0;
|
|
5174
6178
|
F = F + this.F | 0;
|
|
5175
6179
|
G2 = G2 + this.G | 0;
|
|
5176
6180
|
H = H + this.H | 0;
|
|
5177
|
-
this.set(A3, B,
|
|
6181
|
+
this.set(A3, B, C2, D2, E2, F, G2, H);
|
|
5178
6182
|
}
|
|
5179
6183
|
roundClean() {
|
|
5180
6184
|
SHA256_W.fill(0);
|
|
@@ -5185,7 +6189,7 @@ class SHA2562 extends HashMD2 {
|
|
|
5185
6189
|
}
|
|
5186
6190
|
}
|
|
5187
6191
|
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA2562());
|
|
5188
|
-
class
|
|
6192
|
+
class HMAC2 extends Hash2 {
|
|
5189
6193
|
constructor(hash, _key) {
|
|
5190
6194
|
super();
|
|
5191
6195
|
this.finished = false;
|
|
@@ -5246,12 +6250,12 @@ class HMAC extends Hash2 {
|
|
|
5246
6250
|
this.iHash.destroy();
|
|
5247
6251
|
}
|
|
5248
6252
|
}
|
|
5249
|
-
const hmac = (hash, key, message) => new
|
|
5250
|
-
hmac.create = (hash, key) => new
|
|
6253
|
+
const hmac = (hash, key, message) => new HMAC2(hash, key).update(message).digest();
|
|
6254
|
+
hmac.create = (hash, key) => new HMAC2(hash, key);
|
|
5251
6255
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5252
|
-
const _0n$
|
|
5253
|
-
const _1n$
|
|
5254
|
-
const _2n$
|
|
6256
|
+
const _0n$6 = /* @__PURE__ */ BigInt(0);
|
|
6257
|
+
const _1n$8 = /* @__PURE__ */ BigInt(1);
|
|
6258
|
+
const _2n$6 = /* @__PURE__ */ BigInt(2);
|
|
5255
6259
|
function isBytes$2(a5) {
|
|
5256
6260
|
return a5 instanceof Uint8Array || ArrayBuffer.isView(a5) && a5.constructor.name === "Uint8Array";
|
|
5257
6261
|
}
|
|
@@ -5279,7 +6283,7 @@ function numberToHexUnpadded(num) {
|
|
|
5279
6283
|
function hexToNumber(hex) {
|
|
5280
6284
|
if (typeof hex !== "string")
|
|
5281
6285
|
throw new Error("hex string expected, got " + typeof hex);
|
|
5282
|
-
return hex === "" ? _0n$
|
|
6286
|
+
return hex === "" ? _0n$6 : BigInt("0x" + hex);
|
|
5283
6287
|
}
|
|
5284
6288
|
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
5285
6289
|
function asciiToBase16(ch) {
|
|
@@ -5372,7 +6376,7 @@ function utf8ToBytes(str) {
|
|
|
5372
6376
|
throw new Error("string expected");
|
|
5373
6377
|
return new Uint8Array(new TextEncoder().encode(str));
|
|
5374
6378
|
}
|
|
5375
|
-
const isPosBig = (n4) => typeof n4 === "bigint" && _0n$
|
|
6379
|
+
const isPosBig = (n4) => typeof n4 === "bigint" && _0n$6 <= n4;
|
|
5376
6380
|
function inRange(n4, min, max) {
|
|
5377
6381
|
return isPosBig(n4) && isPosBig(min) && isPosBig(max) && min <= n4 && n4 < max;
|
|
5378
6382
|
}
|
|
@@ -5382,17 +6386,17 @@ function aInRange(title, n4, min, max) {
|
|
|
5382
6386
|
}
|
|
5383
6387
|
function bitLen(n4) {
|
|
5384
6388
|
let len;
|
|
5385
|
-
for (len = 0; n4 > _0n$
|
|
6389
|
+
for (len = 0; n4 > _0n$6; n4 >>= _1n$8, len += 1)
|
|
5386
6390
|
;
|
|
5387
6391
|
return len;
|
|
5388
6392
|
}
|
|
5389
6393
|
function bitGet(n4, pos) {
|
|
5390
|
-
return n4 >> BigInt(pos) & _1n$
|
|
6394
|
+
return n4 >> BigInt(pos) & _1n$8;
|
|
5391
6395
|
}
|
|
5392
6396
|
function bitSet(n4, pos, value) {
|
|
5393
|
-
return n4 | (value ? _1n$
|
|
6397
|
+
return n4 | (value ? _1n$8 : _0n$6) << BigInt(pos);
|
|
5394
6398
|
}
|
|
5395
|
-
const bitMask = (n4) => (_2n$
|
|
6399
|
+
const bitMask = (n4) => (_2n$6 << BigInt(n4 - 1)) - _1n$8;
|
|
5396
6400
|
const u8n$1 = (data) => new Uint8Array(data);
|
|
5397
6401
|
const u8fr = (arr) => Uint8Array.from(arr);
|
|
5398
6402
|
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
@@ -5516,123 +6520,123 @@ const ut = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
5516
6520
|
validateObject
|
|
5517
6521
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
5518
6522
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5519
|
-
const _0n$
|
|
5520
|
-
const _4n = /* @__PURE__ */ BigInt(4), _5n = /* @__PURE__ */ BigInt(5), _8n = /* @__PURE__ */ BigInt(8);
|
|
6523
|
+
const _0n$5 = BigInt(0), _1n$7 = BigInt(1), _2n$5 = /* @__PURE__ */ BigInt(2), _3n$2 = /* @__PURE__ */ BigInt(3);
|
|
6524
|
+
const _4n = /* @__PURE__ */ BigInt(4), _5n$1 = /* @__PURE__ */ BigInt(5), _8n$2 = /* @__PURE__ */ BigInt(8);
|
|
5521
6525
|
function mod(a5, b2) {
|
|
5522
6526
|
const result = a5 % b2;
|
|
5523
|
-
return result >= _0n$
|
|
6527
|
+
return result >= _0n$5 ? result : b2 + result;
|
|
5524
6528
|
}
|
|
5525
6529
|
function pow(num, power, modulo) {
|
|
5526
|
-
if (power < _0n$
|
|
6530
|
+
if (power < _0n$5)
|
|
5527
6531
|
throw new Error("invalid exponent, negatives unsupported");
|
|
5528
|
-
if (modulo <= _0n$
|
|
6532
|
+
if (modulo <= _0n$5)
|
|
5529
6533
|
throw new Error("invalid modulus");
|
|
5530
|
-
if (modulo === _1n$
|
|
5531
|
-
return _0n$
|
|
5532
|
-
let res = _1n$
|
|
5533
|
-
while (power > _0n$
|
|
5534
|
-
if (power & _1n$
|
|
6534
|
+
if (modulo === _1n$7)
|
|
6535
|
+
return _0n$5;
|
|
6536
|
+
let res = _1n$7;
|
|
6537
|
+
while (power > _0n$5) {
|
|
6538
|
+
if (power & _1n$7)
|
|
5535
6539
|
res = res * num % modulo;
|
|
5536
6540
|
num = num * num % modulo;
|
|
5537
|
-
power >>= _1n$
|
|
6541
|
+
power >>= _1n$7;
|
|
5538
6542
|
}
|
|
5539
6543
|
return res;
|
|
5540
6544
|
}
|
|
5541
6545
|
function pow2(x2, power, modulo) {
|
|
5542
6546
|
let res = x2;
|
|
5543
|
-
while (power-- > _0n$
|
|
6547
|
+
while (power-- > _0n$5) {
|
|
5544
6548
|
res *= res;
|
|
5545
6549
|
res %= modulo;
|
|
5546
6550
|
}
|
|
5547
6551
|
return res;
|
|
5548
6552
|
}
|
|
5549
6553
|
function invert(number, modulo) {
|
|
5550
|
-
if (number === _0n$
|
|
6554
|
+
if (number === _0n$5)
|
|
5551
6555
|
throw new Error("invert: expected non-zero number");
|
|
5552
|
-
if (modulo <= _0n$
|
|
6556
|
+
if (modulo <= _0n$5)
|
|
5553
6557
|
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
5554
6558
|
let a5 = mod(number, modulo);
|
|
5555
6559
|
let b2 = modulo;
|
|
5556
|
-
let x2 = _0n$
|
|
5557
|
-
while (a5 !== _0n$
|
|
6560
|
+
let x2 = _0n$5, u4 = _1n$7;
|
|
6561
|
+
while (a5 !== _0n$5) {
|
|
5558
6562
|
const q2 = b2 / a5;
|
|
5559
6563
|
const r7 = b2 % a5;
|
|
5560
6564
|
const m2 = x2 - u4 * q2;
|
|
5561
6565
|
b2 = a5, a5 = r7, x2 = u4, u4 = m2;
|
|
5562
6566
|
}
|
|
5563
6567
|
const gcd2 = b2;
|
|
5564
|
-
if (gcd2 !== _1n$
|
|
6568
|
+
if (gcd2 !== _1n$7)
|
|
5565
6569
|
throw new Error("invert: does not exist");
|
|
5566
6570
|
return mod(x2, modulo);
|
|
5567
6571
|
}
|
|
5568
|
-
function tonelliShanks(
|
|
5569
|
-
const legendreC = (
|
|
6572
|
+
function tonelliShanks(P2) {
|
|
6573
|
+
const legendreC = (P2 - _1n$7) / _2n$5;
|
|
5570
6574
|
let Q, S2, Z;
|
|
5571
|
-
for (Q =
|
|
6575
|
+
for (Q = P2 - _1n$7, S2 = 0; Q % _2n$5 === _0n$5; Q /= _2n$5, S2++)
|
|
5572
6576
|
;
|
|
5573
|
-
for (Z = _2n$
|
|
6577
|
+
for (Z = _2n$5; Z < P2 && pow(Z, legendreC, P2) !== P2 - _1n$7; Z++) {
|
|
5574
6578
|
if (Z > 1e3)
|
|
5575
6579
|
throw new Error("Cannot find square root: likely non-prime P");
|
|
5576
6580
|
}
|
|
5577
6581
|
if (S2 === 1) {
|
|
5578
|
-
const p1div4 = (
|
|
5579
|
-
return function tonelliFast(
|
|
5580
|
-
const root2 =
|
|
5581
|
-
if (!
|
|
6582
|
+
const p1div4 = (P2 + _1n$7) / _4n;
|
|
6583
|
+
return function tonelliFast(Fp2, n4) {
|
|
6584
|
+
const root2 = Fp2.pow(n4, p1div4);
|
|
6585
|
+
if (!Fp2.eql(Fp2.sqr(root2), n4))
|
|
5582
6586
|
throw new Error("Cannot find square root");
|
|
5583
6587
|
return root2;
|
|
5584
6588
|
};
|
|
5585
6589
|
}
|
|
5586
|
-
const Q1div2 = (Q + _1n$
|
|
5587
|
-
return function tonelliSlow(
|
|
5588
|
-
if (
|
|
6590
|
+
const Q1div2 = (Q + _1n$7) / _2n$5;
|
|
6591
|
+
return function tonelliSlow(Fp2, n4) {
|
|
6592
|
+
if (Fp2.pow(n4, legendreC) === Fp2.neg(Fp2.ONE))
|
|
5589
6593
|
throw new Error("Cannot find square root");
|
|
5590
6594
|
let r7 = S2;
|
|
5591
|
-
let g2 =
|
|
5592
|
-
let x2 =
|
|
5593
|
-
let b2 =
|
|
5594
|
-
while (!
|
|
5595
|
-
if (
|
|
5596
|
-
return
|
|
6595
|
+
let g2 = Fp2.pow(Fp2.mul(Fp2.ONE, Z), Q);
|
|
6596
|
+
let x2 = Fp2.pow(n4, Q1div2);
|
|
6597
|
+
let b2 = Fp2.pow(n4, Q);
|
|
6598
|
+
while (!Fp2.eql(b2, Fp2.ONE)) {
|
|
6599
|
+
if (Fp2.eql(b2, Fp2.ZERO))
|
|
6600
|
+
return Fp2.ZERO;
|
|
5597
6601
|
let m2 = 1;
|
|
5598
|
-
for (let t22 =
|
|
5599
|
-
if (
|
|
6602
|
+
for (let t22 = Fp2.sqr(b2); m2 < r7; m2++) {
|
|
6603
|
+
if (Fp2.eql(t22, Fp2.ONE))
|
|
5600
6604
|
break;
|
|
5601
|
-
t22 =
|
|
6605
|
+
t22 = Fp2.sqr(t22);
|
|
5602
6606
|
}
|
|
5603
|
-
const ge2 =
|
|
5604
|
-
g2 =
|
|
5605
|
-
x2 =
|
|
5606
|
-
b2 =
|
|
6607
|
+
const ge2 = Fp2.pow(g2, _1n$7 << BigInt(r7 - m2 - 1));
|
|
6608
|
+
g2 = Fp2.sqr(ge2);
|
|
6609
|
+
x2 = Fp2.mul(x2, ge2);
|
|
6610
|
+
b2 = Fp2.mul(b2, g2);
|
|
5607
6611
|
r7 = m2;
|
|
5608
6612
|
}
|
|
5609
6613
|
return x2;
|
|
5610
6614
|
};
|
|
5611
6615
|
}
|
|
5612
|
-
function FpSqrt(
|
|
5613
|
-
if (
|
|
5614
|
-
const p1div4 = (
|
|
5615
|
-
return function
|
|
5616
|
-
const root2 =
|
|
5617
|
-
if (!
|
|
6616
|
+
function FpSqrt(P2) {
|
|
6617
|
+
if (P2 % _4n === _3n$2) {
|
|
6618
|
+
const p1div4 = (P2 + _1n$7) / _4n;
|
|
6619
|
+
return function sqrt3mod42(Fp2, n4) {
|
|
6620
|
+
const root2 = Fp2.pow(n4, p1div4);
|
|
6621
|
+
if (!Fp2.eql(Fp2.sqr(root2), n4))
|
|
5618
6622
|
throw new Error("Cannot find square root");
|
|
5619
6623
|
return root2;
|
|
5620
6624
|
};
|
|
5621
6625
|
}
|
|
5622
|
-
if (
|
|
5623
|
-
const c1 = (
|
|
5624
|
-
return function
|
|
5625
|
-
const n22 =
|
|
5626
|
-
const v2 =
|
|
5627
|
-
const nv =
|
|
5628
|
-
const i3 =
|
|
5629
|
-
const root2 =
|
|
5630
|
-
if (!
|
|
6626
|
+
if (P2 % _8n$2 === _5n$1) {
|
|
6627
|
+
const c1 = (P2 - _5n$1) / _8n$2;
|
|
6628
|
+
return function sqrt5mod82(Fp2, n4) {
|
|
6629
|
+
const n22 = Fp2.mul(n4, _2n$5);
|
|
6630
|
+
const v2 = Fp2.pow(n22, c1);
|
|
6631
|
+
const nv = Fp2.mul(n4, v2);
|
|
6632
|
+
const i3 = Fp2.mul(Fp2.mul(nv, _2n$5), v2);
|
|
6633
|
+
const root2 = Fp2.mul(nv, Fp2.sub(i3, Fp2.ONE));
|
|
6634
|
+
if (!Fp2.eql(Fp2.sqr(root2), n4))
|
|
5631
6635
|
throw new Error("Cannot find square root");
|
|
5632
6636
|
return root2;
|
|
5633
6637
|
};
|
|
5634
6638
|
}
|
|
5635
|
-
return tonelliShanks(
|
|
6639
|
+
return tonelliShanks(P2);
|
|
5636
6640
|
}
|
|
5637
6641
|
const FIELD_FIELDS = [
|
|
5638
6642
|
"create",
|
|
@@ -5667,19 +6671,19 @@ function validateField(field) {
|
|
|
5667
6671
|
return validateObject(field, opts);
|
|
5668
6672
|
}
|
|
5669
6673
|
function FpPow(f3, num, power) {
|
|
5670
|
-
if (power < _0n$
|
|
6674
|
+
if (power < _0n$5)
|
|
5671
6675
|
throw new Error("invalid exponent, negatives unsupported");
|
|
5672
|
-
if (power === _0n$
|
|
6676
|
+
if (power === _0n$5)
|
|
5673
6677
|
return f3.ONE;
|
|
5674
|
-
if (power === _1n$
|
|
6678
|
+
if (power === _1n$7)
|
|
5675
6679
|
return num;
|
|
5676
6680
|
let p5 = f3.ONE;
|
|
5677
6681
|
let d2 = num;
|
|
5678
|
-
while (power > _0n$
|
|
5679
|
-
if (power & _1n$
|
|
6682
|
+
while (power > _0n$5) {
|
|
6683
|
+
if (power & _1n$7)
|
|
5680
6684
|
p5 = f3.mul(p5, d2);
|
|
5681
6685
|
d2 = f3.sqr(d2);
|
|
5682
|
-
power >>= _1n$
|
|
6686
|
+
power >>= _1n$7;
|
|
5683
6687
|
}
|
|
5684
6688
|
return p5;
|
|
5685
6689
|
}
|
|
@@ -5706,7 +6710,7 @@ function nLength(n4, nBitLength) {
|
|
|
5706
6710
|
return { nBitLength: _nBitLength, nByteLength };
|
|
5707
6711
|
}
|
|
5708
6712
|
function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
|
|
5709
|
-
if (ORDER <= _0n$
|
|
6713
|
+
if (ORDER <= _0n$5)
|
|
5710
6714
|
throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
|
|
5711
6715
|
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
5712
6716
|
if (BYTES > 2048)
|
|
@@ -5718,16 +6722,16 @@ function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
|
|
|
5718
6722
|
BITS,
|
|
5719
6723
|
BYTES,
|
|
5720
6724
|
MASK: bitMask(BITS),
|
|
5721
|
-
ZERO: _0n$
|
|
5722
|
-
ONE: _1n$
|
|
6725
|
+
ZERO: _0n$5,
|
|
6726
|
+
ONE: _1n$7,
|
|
5723
6727
|
create: (num) => mod(num, ORDER),
|
|
5724
6728
|
isValid: (num) => {
|
|
5725
6729
|
if (typeof num !== "bigint")
|
|
5726
6730
|
throw new Error("invalid field element: expected bigint, got " + typeof num);
|
|
5727
|
-
return _0n$
|
|
6731
|
+
return _0n$5 <= num && num < ORDER;
|
|
5728
6732
|
},
|
|
5729
|
-
is0: (num) => num === _0n$
|
|
5730
|
-
isOdd: (num) => (num & _1n$
|
|
6733
|
+
is0: (num) => num === _0n$5,
|
|
6734
|
+
isOdd: (num) => (num & _1n$7) === _1n$7,
|
|
5731
6735
|
neg: (num) => mod(-num, ORDER),
|
|
5732
6736
|
eql: (lhs, rhs) => lhs === rhs,
|
|
5733
6737
|
sqr: (num) => mod(num * num, ORDER),
|
|
@@ -5777,12 +6781,12 @@ function mapHashToField(key, fieldOrder, isLE2 = false) {
|
|
|
5777
6781
|
if (len < 16 || len < minLen || len > 1024)
|
|
5778
6782
|
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
5779
6783
|
const num = isLE2 ? bytesToNumberLE(key) : bytesToNumberBE(key);
|
|
5780
|
-
const reduced = mod(num, fieldOrder - _1n$
|
|
6784
|
+
const reduced = mod(num, fieldOrder - _1n$7) + _1n$7;
|
|
5781
6785
|
return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
5782
6786
|
}
|
|
5783
6787
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5784
|
-
const _0n$
|
|
5785
|
-
const _1n$
|
|
6788
|
+
const _0n$4 = BigInt(0);
|
|
6789
|
+
const _1n$6 = BigInt(1);
|
|
5786
6790
|
function constTimeNegate(condition, item) {
|
|
5787
6791
|
const neg = item.negate();
|
|
5788
6792
|
return condition ? neg : item;
|
|
@@ -5815,8 +6819,8 @@ function validateMSMScalars(scalars, field) {
|
|
|
5815
6819
|
}
|
|
5816
6820
|
const pointPrecomputes = /* @__PURE__ */ new WeakMap();
|
|
5817
6821
|
const pointWindowSizes = /* @__PURE__ */ new WeakMap();
|
|
5818
|
-
function getW(
|
|
5819
|
-
return pointWindowSizes.get(
|
|
6822
|
+
function getW(P2) {
|
|
6823
|
+
return pointWindowSizes.get(P2) || 1;
|
|
5820
6824
|
}
|
|
5821
6825
|
function wNAF$1(c3, bits) {
|
|
5822
6826
|
return {
|
|
@@ -5827,11 +6831,11 @@ function wNAF$1(c3, bits) {
|
|
|
5827
6831
|
// non-const time multiplication ladder
|
|
5828
6832
|
unsafeLadder(elm, n4, p5 = c3.ZERO) {
|
|
5829
6833
|
let d2 = elm;
|
|
5830
|
-
while (n4 > _0n$
|
|
5831
|
-
if (n4 & _1n$
|
|
6834
|
+
while (n4 > _0n$4) {
|
|
6835
|
+
if (n4 & _1n$6)
|
|
5832
6836
|
p5 = p5.add(d2);
|
|
5833
6837
|
d2 = d2.double();
|
|
5834
|
-
n4 >>= _1n$
|
|
6838
|
+
n4 >>= _1n$6;
|
|
5835
6839
|
}
|
|
5836
6840
|
return p5;
|
|
5837
6841
|
},
|
|
@@ -5883,7 +6887,7 @@ function wNAF$1(c3, bits) {
|
|
|
5883
6887
|
n4 >>= shiftBy;
|
|
5884
6888
|
if (wbits > windowSize) {
|
|
5885
6889
|
wbits -= maxNumber;
|
|
5886
|
-
n4 += _1n$
|
|
6890
|
+
n4 += _1n$6;
|
|
5887
6891
|
}
|
|
5888
6892
|
const offset1 = offset;
|
|
5889
6893
|
const offset2 = offset + Math.abs(wbits) - 1;
|
|
@@ -5912,13 +6916,13 @@ function wNAF$1(c3, bits) {
|
|
|
5912
6916
|
const shiftBy = BigInt(W2);
|
|
5913
6917
|
for (let window2 = 0; window2 < windows; window2++) {
|
|
5914
6918
|
const offset = window2 * windowSize;
|
|
5915
|
-
if (n4 === _0n$
|
|
6919
|
+
if (n4 === _0n$4)
|
|
5916
6920
|
break;
|
|
5917
6921
|
let wbits = Number(n4 & mask);
|
|
5918
6922
|
n4 >>= shiftBy;
|
|
5919
6923
|
if (wbits > windowSize) {
|
|
5920
6924
|
wbits -= maxNumber;
|
|
5921
|
-
n4 += _1n$
|
|
6925
|
+
n4 += _1n$6;
|
|
5922
6926
|
}
|
|
5923
6927
|
if (wbits === 0)
|
|
5924
6928
|
continue;
|
|
@@ -5929,32 +6933,32 @@ function wNAF$1(c3, bits) {
|
|
|
5929
6933
|
}
|
|
5930
6934
|
return acc;
|
|
5931
6935
|
},
|
|
5932
|
-
getPrecomputes(W2,
|
|
5933
|
-
let comp = pointPrecomputes.get(
|
|
6936
|
+
getPrecomputes(W2, P2, transform) {
|
|
6937
|
+
let comp = pointPrecomputes.get(P2);
|
|
5934
6938
|
if (!comp) {
|
|
5935
|
-
comp = this.precomputeWindow(
|
|
6939
|
+
comp = this.precomputeWindow(P2, W2);
|
|
5936
6940
|
if (W2 !== 1)
|
|
5937
|
-
pointPrecomputes.set(
|
|
6941
|
+
pointPrecomputes.set(P2, transform(comp));
|
|
5938
6942
|
}
|
|
5939
6943
|
return comp;
|
|
5940
6944
|
},
|
|
5941
|
-
wNAFCached(
|
|
5942
|
-
const W2 = getW(
|
|
5943
|
-
return this.wNAF(W2, this.getPrecomputes(W2,
|
|
6945
|
+
wNAFCached(P2, n4, transform) {
|
|
6946
|
+
const W2 = getW(P2);
|
|
6947
|
+
return this.wNAF(W2, this.getPrecomputes(W2, P2, transform), n4);
|
|
5944
6948
|
},
|
|
5945
|
-
wNAFCachedUnsafe(
|
|
5946
|
-
const W2 = getW(
|
|
6949
|
+
wNAFCachedUnsafe(P2, n4, transform, prev) {
|
|
6950
|
+
const W2 = getW(P2);
|
|
5947
6951
|
if (W2 === 1)
|
|
5948
|
-
return this.unsafeLadder(
|
|
5949
|
-
return this.wNAFUnsafe(W2, this.getPrecomputes(W2,
|
|
6952
|
+
return this.unsafeLadder(P2, n4, prev);
|
|
6953
|
+
return this.wNAFUnsafe(W2, this.getPrecomputes(W2, P2, transform), n4, prev);
|
|
5950
6954
|
},
|
|
5951
6955
|
// We calculate precomputes for elliptic curve point multiplication
|
|
5952
6956
|
// using windowed method. This specifies window size and
|
|
5953
6957
|
// stores precomputed values. Usually only base point would be precomputed.
|
|
5954
|
-
setWindowSize(
|
|
6958
|
+
setWindowSize(P2, W2) {
|
|
5955
6959
|
validateW(W2, bits);
|
|
5956
|
-
pointWindowSizes.set(
|
|
5957
|
-
pointPrecomputes.delete(
|
|
6960
|
+
pointWindowSizes.set(P2, W2);
|
|
6961
|
+
pointPrecomputes.delete(P2);
|
|
5958
6962
|
}
|
|
5959
6963
|
};
|
|
5960
6964
|
}
|
|
@@ -6027,9 +7031,9 @@ function validatePointOpts(curve2) {
|
|
|
6027
7031
|
fromBytes: "function",
|
|
6028
7032
|
toBytes: "function"
|
|
6029
7033
|
});
|
|
6030
|
-
const { endo, Fp, a: a5 } = opts;
|
|
7034
|
+
const { endo, Fp: Fp2, a: a5 } = opts;
|
|
6031
7035
|
if (endo) {
|
|
6032
|
-
if (!
|
|
7036
|
+
if (!Fp2.eql(a5, Fp2.ZERO)) {
|
|
6033
7037
|
throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");
|
|
6034
7038
|
}
|
|
6035
7039
|
if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
|
|
@@ -6106,7 +7110,7 @@ const DER = {
|
|
|
6106
7110
|
_int: {
|
|
6107
7111
|
encode(num) {
|
|
6108
7112
|
const { Err: E2 } = DER;
|
|
6109
|
-
if (num < _0n$
|
|
7113
|
+
if (num < _0n$3)
|
|
6110
7114
|
throw new E2("integer: negative integers are not allowed");
|
|
6111
7115
|
let hex = numberToHexUnpadded(num);
|
|
6112
7116
|
if (Number.parseInt(hex[0], 16) & 8)
|
|
@@ -6145,34 +7149,34 @@ const DER = {
|
|
|
6145
7149
|
return tlv.encode(48, seq);
|
|
6146
7150
|
}
|
|
6147
7151
|
};
|
|
6148
|
-
const _0n$
|
|
7152
|
+
const _0n$3 = BigInt(0), _1n$5 = BigInt(1);
|
|
6149
7153
|
BigInt(2);
|
|
6150
|
-
const _3n = BigInt(3);
|
|
7154
|
+
const _3n$1 = BigInt(3);
|
|
6151
7155
|
BigInt(4);
|
|
6152
7156
|
function weierstrassPoints(opts) {
|
|
6153
7157
|
const CURVE2 = validatePointOpts(opts);
|
|
6154
|
-
const { Fp } = CURVE2;
|
|
7158
|
+
const { Fp: Fp2 } = CURVE2;
|
|
6155
7159
|
const Fn = Field(CURVE2.n, CURVE2.nBitLength);
|
|
6156
7160
|
const toBytes2 = CURVE2.toBytes || ((_c4, point, _isCompressed) => {
|
|
6157
7161
|
const a5 = point.toAffine();
|
|
6158
|
-
return concatBytes(Uint8Array.from([4]),
|
|
7162
|
+
return concatBytes(Uint8Array.from([4]), Fp2.toBytes(a5.x), Fp2.toBytes(a5.y));
|
|
6159
7163
|
});
|
|
6160
7164
|
const fromBytes = CURVE2.fromBytes || ((bytes) => {
|
|
6161
7165
|
const tail = bytes.subarray(1);
|
|
6162
|
-
const x2 =
|
|
6163
|
-
const y3 =
|
|
7166
|
+
const x2 = Fp2.fromBytes(tail.subarray(0, Fp2.BYTES));
|
|
7167
|
+
const y3 = Fp2.fromBytes(tail.subarray(Fp2.BYTES, 2 * Fp2.BYTES));
|
|
6164
7168
|
return { x: x2, y: y3 };
|
|
6165
7169
|
});
|
|
6166
7170
|
function weierstrassEquation(x2) {
|
|
6167
7171
|
const { a: a5, b: b2 } = CURVE2;
|
|
6168
|
-
const x22 =
|
|
6169
|
-
const x3 =
|
|
6170
|
-
return
|
|
7172
|
+
const x22 = Fp2.sqr(x2);
|
|
7173
|
+
const x3 = Fp2.mul(x22, x2);
|
|
7174
|
+
return Fp2.add(Fp2.add(x3, Fp2.mul(x2, a5)), b2);
|
|
6171
7175
|
}
|
|
6172
|
-
if (!
|
|
7176
|
+
if (!Fp2.eql(Fp2.sqr(CURVE2.Gy), weierstrassEquation(CURVE2.Gx)))
|
|
6173
7177
|
throw new Error("bad generator point: equation left != right");
|
|
6174
7178
|
function isWithinCurveOrder(num) {
|
|
6175
|
-
return inRange(num, _1n$
|
|
7179
|
+
return inRange(num, _1n$5, CURVE2.n);
|
|
6176
7180
|
}
|
|
6177
7181
|
function normPrivateKeyToScalar(key) {
|
|
6178
7182
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: N2 } = CURVE2;
|
|
@@ -6191,56 +7195,56 @@ function weierstrassPoints(opts) {
|
|
|
6191
7195
|
}
|
|
6192
7196
|
if (wrapPrivateKey)
|
|
6193
7197
|
num = mod(num, N2);
|
|
6194
|
-
aInRange("private key", num, _1n$
|
|
7198
|
+
aInRange("private key", num, _1n$5, N2);
|
|
6195
7199
|
return num;
|
|
6196
7200
|
}
|
|
6197
7201
|
function assertPrjPoint(other) {
|
|
6198
|
-
if (!(other instanceof
|
|
7202
|
+
if (!(other instanceof Point3))
|
|
6199
7203
|
throw new Error("ProjectivePoint expected");
|
|
6200
7204
|
}
|
|
6201
7205
|
const toAffineMemo = memoized((p5, iz) => {
|
|
6202
7206
|
const { px: x2, py: y3, pz: z2 } = p5;
|
|
6203
|
-
if (
|
|
7207
|
+
if (Fp2.eql(z2, Fp2.ONE))
|
|
6204
7208
|
return { x: x2, y: y3 };
|
|
6205
7209
|
const is0 = p5.is0();
|
|
6206
7210
|
if (iz == null)
|
|
6207
|
-
iz = is0 ?
|
|
6208
|
-
const ax =
|
|
6209
|
-
const ay =
|
|
6210
|
-
const zz =
|
|
7211
|
+
iz = is0 ? Fp2.ONE : Fp2.inv(z2);
|
|
7212
|
+
const ax = Fp2.mul(x2, iz);
|
|
7213
|
+
const ay = Fp2.mul(y3, iz);
|
|
7214
|
+
const zz = Fp2.mul(z2, iz);
|
|
6211
7215
|
if (is0)
|
|
6212
|
-
return { x:
|
|
6213
|
-
if (!
|
|
7216
|
+
return { x: Fp2.ZERO, y: Fp2.ZERO };
|
|
7217
|
+
if (!Fp2.eql(zz, Fp2.ONE))
|
|
6214
7218
|
throw new Error("invZ was invalid");
|
|
6215
7219
|
return { x: ax, y: ay };
|
|
6216
7220
|
});
|
|
6217
7221
|
const assertValidMemo = memoized((p5) => {
|
|
6218
7222
|
if (p5.is0()) {
|
|
6219
|
-
if (CURVE2.allowInfinityPoint && !
|
|
7223
|
+
if (CURVE2.allowInfinityPoint && !Fp2.is0(p5.py))
|
|
6220
7224
|
return;
|
|
6221
7225
|
throw new Error("bad point: ZERO");
|
|
6222
7226
|
}
|
|
6223
7227
|
const { x: x2, y: y3 } = p5.toAffine();
|
|
6224
|
-
if (!
|
|
7228
|
+
if (!Fp2.isValid(x2) || !Fp2.isValid(y3))
|
|
6225
7229
|
throw new Error("bad point: x or y not FE");
|
|
6226
|
-
const left =
|
|
7230
|
+
const left = Fp2.sqr(y3);
|
|
6227
7231
|
const right = weierstrassEquation(x2);
|
|
6228
|
-
if (!
|
|
7232
|
+
if (!Fp2.eql(left, right))
|
|
6229
7233
|
throw new Error("bad point: equation left != right");
|
|
6230
7234
|
if (!p5.isTorsionFree())
|
|
6231
7235
|
throw new Error("bad point: not in prime-order subgroup");
|
|
6232
7236
|
return true;
|
|
6233
7237
|
});
|
|
6234
|
-
class
|
|
7238
|
+
class Point3 {
|
|
6235
7239
|
constructor(px, py, pz) {
|
|
6236
7240
|
this.px = px;
|
|
6237
7241
|
this.py = py;
|
|
6238
7242
|
this.pz = pz;
|
|
6239
|
-
if (px == null || !
|
|
7243
|
+
if (px == null || !Fp2.isValid(px))
|
|
6240
7244
|
throw new Error("x required");
|
|
6241
|
-
if (py == null || !
|
|
7245
|
+
if (py == null || !Fp2.isValid(py))
|
|
6242
7246
|
throw new Error("y required");
|
|
6243
|
-
if (pz == null || !
|
|
7247
|
+
if (pz == null || !Fp2.isValid(pz))
|
|
6244
7248
|
throw new Error("z required");
|
|
6245
7249
|
Object.freeze(this);
|
|
6246
7250
|
}
|
|
@@ -6248,14 +7252,14 @@ function weierstrassPoints(opts) {
|
|
|
6248
7252
|
// Use fromHex instead, or call assertValidity() later.
|
|
6249
7253
|
static fromAffine(p5) {
|
|
6250
7254
|
const { x: x2, y: y3 } = p5 || {};
|
|
6251
|
-
if (!p5 || !
|
|
7255
|
+
if (!p5 || !Fp2.isValid(x2) || !Fp2.isValid(y3))
|
|
6252
7256
|
throw new Error("invalid affine point");
|
|
6253
|
-
if (p5 instanceof
|
|
7257
|
+
if (p5 instanceof Point3)
|
|
6254
7258
|
throw new Error("projective point not allowed");
|
|
6255
|
-
const is0 = (i3) =>
|
|
7259
|
+
const is0 = (i3) => Fp2.eql(i3, Fp2.ZERO);
|
|
6256
7260
|
if (is0(x2) && is0(y3))
|
|
6257
|
-
return
|
|
6258
|
-
return new
|
|
7261
|
+
return Point3.ZERO;
|
|
7262
|
+
return new Point3(x2, y3, Fp2.ONE);
|
|
6259
7263
|
}
|
|
6260
7264
|
get x() {
|
|
6261
7265
|
return this.toAffine().x;
|
|
@@ -6270,25 +7274,25 @@ function weierstrassPoints(opts) {
|
|
|
6270
7274
|
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
6271
7275
|
*/
|
|
6272
7276
|
static normalizeZ(points) {
|
|
6273
|
-
const toInv =
|
|
6274
|
-
return points.map((p5, i3) => p5.toAffine(toInv[i3])).map(
|
|
7277
|
+
const toInv = Fp2.invertBatch(points.map((p5) => p5.pz));
|
|
7278
|
+
return points.map((p5, i3) => p5.toAffine(toInv[i3])).map(Point3.fromAffine);
|
|
6275
7279
|
}
|
|
6276
7280
|
/**
|
|
6277
7281
|
* Converts hash string or Uint8Array to Point.
|
|
6278
7282
|
* @param hex short/long ECDSA hex
|
|
6279
7283
|
*/
|
|
6280
7284
|
static fromHex(hex) {
|
|
6281
|
-
const
|
|
6282
|
-
|
|
6283
|
-
return
|
|
7285
|
+
const P2 = Point3.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
|
|
7286
|
+
P2.assertValidity();
|
|
7287
|
+
return P2;
|
|
6284
7288
|
}
|
|
6285
7289
|
// Multiplies generator point by privateKey.
|
|
6286
7290
|
static fromPrivateKey(privateKey) {
|
|
6287
|
-
return
|
|
7291
|
+
return Point3.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
6288
7292
|
}
|
|
6289
7293
|
// Multiscalar Multiplication
|
|
6290
7294
|
static msm(points, scalars) {
|
|
6291
|
-
return pippenger(
|
|
7295
|
+
return pippenger(Point3, Fn, points, scalars);
|
|
6292
7296
|
}
|
|
6293
7297
|
// "Private method", don't use it directly
|
|
6294
7298
|
_setWindowSize(windowSize) {
|
|
@@ -6300,8 +7304,8 @@ function weierstrassPoints(opts) {
|
|
|
6300
7304
|
}
|
|
6301
7305
|
hasEvenY() {
|
|
6302
7306
|
const { y: y3 } = this.toAffine();
|
|
6303
|
-
if (
|
|
6304
|
-
return !
|
|
7307
|
+
if (Fp2.isOdd)
|
|
7308
|
+
return !Fp2.isOdd(y3);
|
|
6305
7309
|
throw new Error("Field doesn't support isOdd");
|
|
6306
7310
|
}
|
|
6307
7311
|
/**
|
|
@@ -6311,15 +7315,15 @@ function weierstrassPoints(opts) {
|
|
|
6311
7315
|
assertPrjPoint(other);
|
|
6312
7316
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
6313
7317
|
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
6314
|
-
const U1 =
|
|
6315
|
-
const U22 =
|
|
7318
|
+
const U1 = Fp2.eql(Fp2.mul(X1, Z2), Fp2.mul(X2, Z1));
|
|
7319
|
+
const U22 = Fp2.eql(Fp2.mul(Y1, Z2), Fp2.mul(Y2, Z1));
|
|
6316
7320
|
return U1 && U22;
|
|
6317
7321
|
}
|
|
6318
7322
|
/**
|
|
6319
7323
|
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
6320
7324
|
*/
|
|
6321
7325
|
negate() {
|
|
6322
|
-
return new
|
|
7326
|
+
return new Point3(this.px, Fp2.neg(this.py), this.pz);
|
|
6323
7327
|
}
|
|
6324
7328
|
// Renes-Costello-Batina exception-free doubling formula.
|
|
6325
7329
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -6327,41 +7331,41 @@ function weierstrassPoints(opts) {
|
|
|
6327
7331
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
6328
7332
|
double() {
|
|
6329
7333
|
const { a: a5, b: b2 } = CURVE2;
|
|
6330
|
-
const b3 =
|
|
7334
|
+
const b3 = Fp2.mul(b2, _3n$1);
|
|
6331
7335
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
6332
|
-
let X3 =
|
|
6333
|
-
let t0 =
|
|
6334
|
-
let t1 =
|
|
6335
|
-
let t22 =
|
|
6336
|
-
let t32 =
|
|
6337
|
-
t32 =
|
|
6338
|
-
Z3 =
|
|
6339
|
-
Z3 =
|
|
6340
|
-
X3 =
|
|
6341
|
-
Y3 =
|
|
6342
|
-
Y3 =
|
|
6343
|
-
X3 =
|
|
6344
|
-
Y3 =
|
|
6345
|
-
Y3 =
|
|
6346
|
-
X3 =
|
|
6347
|
-
Z3 =
|
|
6348
|
-
t22 =
|
|
6349
|
-
t32 =
|
|
6350
|
-
t32 =
|
|
6351
|
-
t32 =
|
|
6352
|
-
Z3 =
|
|
6353
|
-
t0 =
|
|
6354
|
-
t0 =
|
|
6355
|
-
t0 =
|
|
6356
|
-
Y3 =
|
|
6357
|
-
t22 =
|
|
6358
|
-
t22 =
|
|
6359
|
-
t0 =
|
|
6360
|
-
X3 =
|
|
6361
|
-
Z3 =
|
|
6362
|
-
Z3 =
|
|
6363
|
-
Z3 =
|
|
6364
|
-
return new
|
|
7336
|
+
let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
|
|
7337
|
+
let t0 = Fp2.mul(X1, X1);
|
|
7338
|
+
let t1 = Fp2.mul(Y1, Y1);
|
|
7339
|
+
let t22 = Fp2.mul(Z1, Z1);
|
|
7340
|
+
let t32 = Fp2.mul(X1, Y1);
|
|
7341
|
+
t32 = Fp2.add(t32, t32);
|
|
7342
|
+
Z3 = Fp2.mul(X1, Z1);
|
|
7343
|
+
Z3 = Fp2.add(Z3, Z3);
|
|
7344
|
+
X3 = Fp2.mul(a5, Z3);
|
|
7345
|
+
Y3 = Fp2.mul(b3, t22);
|
|
7346
|
+
Y3 = Fp2.add(X3, Y3);
|
|
7347
|
+
X3 = Fp2.sub(t1, Y3);
|
|
7348
|
+
Y3 = Fp2.add(t1, Y3);
|
|
7349
|
+
Y3 = Fp2.mul(X3, Y3);
|
|
7350
|
+
X3 = Fp2.mul(t32, X3);
|
|
7351
|
+
Z3 = Fp2.mul(b3, Z3);
|
|
7352
|
+
t22 = Fp2.mul(a5, t22);
|
|
7353
|
+
t32 = Fp2.sub(t0, t22);
|
|
7354
|
+
t32 = Fp2.mul(a5, t32);
|
|
7355
|
+
t32 = Fp2.add(t32, Z3);
|
|
7356
|
+
Z3 = Fp2.add(t0, t0);
|
|
7357
|
+
t0 = Fp2.add(Z3, t0);
|
|
7358
|
+
t0 = Fp2.add(t0, t22);
|
|
7359
|
+
t0 = Fp2.mul(t0, t32);
|
|
7360
|
+
Y3 = Fp2.add(Y3, t0);
|
|
7361
|
+
t22 = Fp2.mul(Y1, Z1);
|
|
7362
|
+
t22 = Fp2.add(t22, t22);
|
|
7363
|
+
t0 = Fp2.mul(t22, t32);
|
|
7364
|
+
X3 = Fp2.sub(X3, t0);
|
|
7365
|
+
Z3 = Fp2.mul(t22, t1);
|
|
7366
|
+
Z3 = Fp2.add(Z3, Z3);
|
|
7367
|
+
Z3 = Fp2.add(Z3, Z3);
|
|
7368
|
+
return new Point3(X3, Y3, Z3);
|
|
6365
7369
|
}
|
|
6366
7370
|
// Renes-Costello-Batina exception-free addition formula.
|
|
6367
7371
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -6371,59 +7375,59 @@ function weierstrassPoints(opts) {
|
|
|
6371
7375
|
assertPrjPoint(other);
|
|
6372
7376
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
6373
7377
|
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
6374
|
-
let X3 =
|
|
7378
|
+
let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
|
|
6375
7379
|
const a5 = CURVE2.a;
|
|
6376
|
-
const b3 =
|
|
6377
|
-
let t0 =
|
|
6378
|
-
let t1 =
|
|
6379
|
-
let t22 =
|
|
6380
|
-
let t32 =
|
|
6381
|
-
let t42 =
|
|
6382
|
-
t32 =
|
|
6383
|
-
t42 =
|
|
6384
|
-
t32 =
|
|
6385
|
-
t42 =
|
|
6386
|
-
let t52 =
|
|
6387
|
-
t42 =
|
|
6388
|
-
t52 =
|
|
6389
|
-
t42 =
|
|
6390
|
-
t52 =
|
|
6391
|
-
X3 =
|
|
6392
|
-
t52 =
|
|
6393
|
-
X3 =
|
|
6394
|
-
t52 =
|
|
6395
|
-
Z3 =
|
|
6396
|
-
X3 =
|
|
6397
|
-
Z3 =
|
|
6398
|
-
X3 =
|
|
6399
|
-
Z3 =
|
|
6400
|
-
Y3 =
|
|
6401
|
-
t1 =
|
|
6402
|
-
t1 =
|
|
6403
|
-
t22 =
|
|
6404
|
-
t42 =
|
|
6405
|
-
t1 =
|
|
6406
|
-
t22 =
|
|
6407
|
-
t22 =
|
|
6408
|
-
t42 =
|
|
6409
|
-
t0 =
|
|
6410
|
-
Y3 =
|
|
6411
|
-
t0 =
|
|
6412
|
-
X3 =
|
|
6413
|
-
X3 =
|
|
6414
|
-
t0 =
|
|
6415
|
-
Z3 =
|
|
6416
|
-
Z3 =
|
|
6417
|
-
return new
|
|
7380
|
+
const b3 = Fp2.mul(CURVE2.b, _3n$1);
|
|
7381
|
+
let t0 = Fp2.mul(X1, X2);
|
|
7382
|
+
let t1 = Fp2.mul(Y1, Y2);
|
|
7383
|
+
let t22 = Fp2.mul(Z1, Z2);
|
|
7384
|
+
let t32 = Fp2.add(X1, Y1);
|
|
7385
|
+
let t42 = Fp2.add(X2, Y2);
|
|
7386
|
+
t32 = Fp2.mul(t32, t42);
|
|
7387
|
+
t42 = Fp2.add(t0, t1);
|
|
7388
|
+
t32 = Fp2.sub(t32, t42);
|
|
7389
|
+
t42 = Fp2.add(X1, Z1);
|
|
7390
|
+
let t52 = Fp2.add(X2, Z2);
|
|
7391
|
+
t42 = Fp2.mul(t42, t52);
|
|
7392
|
+
t52 = Fp2.add(t0, t22);
|
|
7393
|
+
t42 = Fp2.sub(t42, t52);
|
|
7394
|
+
t52 = Fp2.add(Y1, Z1);
|
|
7395
|
+
X3 = Fp2.add(Y2, Z2);
|
|
7396
|
+
t52 = Fp2.mul(t52, X3);
|
|
7397
|
+
X3 = Fp2.add(t1, t22);
|
|
7398
|
+
t52 = Fp2.sub(t52, X3);
|
|
7399
|
+
Z3 = Fp2.mul(a5, t42);
|
|
7400
|
+
X3 = Fp2.mul(b3, t22);
|
|
7401
|
+
Z3 = Fp2.add(X3, Z3);
|
|
7402
|
+
X3 = Fp2.sub(t1, Z3);
|
|
7403
|
+
Z3 = Fp2.add(t1, Z3);
|
|
7404
|
+
Y3 = Fp2.mul(X3, Z3);
|
|
7405
|
+
t1 = Fp2.add(t0, t0);
|
|
7406
|
+
t1 = Fp2.add(t1, t0);
|
|
7407
|
+
t22 = Fp2.mul(a5, t22);
|
|
7408
|
+
t42 = Fp2.mul(b3, t42);
|
|
7409
|
+
t1 = Fp2.add(t1, t22);
|
|
7410
|
+
t22 = Fp2.sub(t0, t22);
|
|
7411
|
+
t22 = Fp2.mul(a5, t22);
|
|
7412
|
+
t42 = Fp2.add(t42, t22);
|
|
7413
|
+
t0 = Fp2.mul(t1, t42);
|
|
7414
|
+
Y3 = Fp2.add(Y3, t0);
|
|
7415
|
+
t0 = Fp2.mul(t52, t42);
|
|
7416
|
+
X3 = Fp2.mul(t32, X3);
|
|
7417
|
+
X3 = Fp2.sub(X3, t0);
|
|
7418
|
+
t0 = Fp2.mul(t32, t1);
|
|
7419
|
+
Z3 = Fp2.mul(t52, Z3);
|
|
7420
|
+
Z3 = Fp2.add(Z3, t0);
|
|
7421
|
+
return new Point3(X3, Y3, Z3);
|
|
6418
7422
|
}
|
|
6419
7423
|
subtract(other) {
|
|
6420
7424
|
return this.add(other.negate());
|
|
6421
7425
|
}
|
|
6422
7426
|
is0() {
|
|
6423
|
-
return this.equals(
|
|
7427
|
+
return this.equals(Point3.ZERO);
|
|
6424
7428
|
}
|
|
6425
7429
|
wNAF(n4) {
|
|
6426
|
-
return wnaf.wNAFCached(this, n4,
|
|
7430
|
+
return wnaf.wNAFCached(this, n4, Point3.normalizeZ);
|
|
6427
7431
|
}
|
|
6428
7432
|
/**
|
|
6429
7433
|
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
@@ -6432,32 +7436,32 @@ function weierstrassPoints(opts) {
|
|
|
6432
7436
|
*/
|
|
6433
7437
|
multiplyUnsafe(sc) {
|
|
6434
7438
|
const { endo, n: N2 } = CURVE2;
|
|
6435
|
-
aInRange("scalar", sc, _0n$
|
|
6436
|
-
const
|
|
6437
|
-
if (sc === _0n$
|
|
6438
|
-
return
|
|
6439
|
-
if (this.is0() || sc === _1n$
|
|
7439
|
+
aInRange("scalar", sc, _0n$3, N2);
|
|
7440
|
+
const I2 = Point3.ZERO;
|
|
7441
|
+
if (sc === _0n$3)
|
|
7442
|
+
return I2;
|
|
7443
|
+
if (this.is0() || sc === _1n$5)
|
|
6440
7444
|
return this;
|
|
6441
7445
|
if (!endo || wnaf.hasPrecomputes(this))
|
|
6442
|
-
return wnaf.wNAFCachedUnsafe(this, sc,
|
|
7446
|
+
return wnaf.wNAFCachedUnsafe(this, sc, Point3.normalizeZ);
|
|
6443
7447
|
let { k1neg, k1, k2neg, k2 } = endo.splitScalar(sc);
|
|
6444
|
-
let k1p =
|
|
6445
|
-
let k2p =
|
|
7448
|
+
let k1p = I2;
|
|
7449
|
+
let k2p = I2;
|
|
6446
7450
|
let d2 = this;
|
|
6447
|
-
while (k1 > _0n$
|
|
6448
|
-
if (k1 & _1n$
|
|
7451
|
+
while (k1 > _0n$3 || k2 > _0n$3) {
|
|
7452
|
+
if (k1 & _1n$5)
|
|
6449
7453
|
k1p = k1p.add(d2);
|
|
6450
|
-
if (k2 & _1n$
|
|
7454
|
+
if (k2 & _1n$5)
|
|
6451
7455
|
k2p = k2p.add(d2);
|
|
6452
7456
|
d2 = d2.double();
|
|
6453
|
-
k1 >>= _1n$
|
|
6454
|
-
k2 >>= _1n$
|
|
7457
|
+
k1 >>= _1n$5;
|
|
7458
|
+
k2 >>= _1n$5;
|
|
6455
7459
|
}
|
|
6456
7460
|
if (k1neg)
|
|
6457
7461
|
k1p = k1p.negate();
|
|
6458
7462
|
if (k2neg)
|
|
6459
7463
|
k2p = k2p.negate();
|
|
6460
|
-
k2p = new
|
|
7464
|
+
k2p = new Point3(Fp2.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
6461
7465
|
return k1p.add(k2p);
|
|
6462
7466
|
}
|
|
6463
7467
|
/**
|
|
@@ -6471,7 +7475,7 @@ function weierstrassPoints(opts) {
|
|
|
6471
7475
|
*/
|
|
6472
7476
|
multiply(scalar) {
|
|
6473
7477
|
const { endo, n: N2 } = CURVE2;
|
|
6474
|
-
aInRange("scalar", scalar, _1n$
|
|
7478
|
+
aInRange("scalar", scalar, _1n$5, N2);
|
|
6475
7479
|
let point, fake;
|
|
6476
7480
|
if (endo) {
|
|
6477
7481
|
const { k1neg, k1, k2neg, k2 } = endo.splitScalar(scalar);
|
|
@@ -6479,7 +7483,7 @@ function weierstrassPoints(opts) {
|
|
|
6479
7483
|
let { p: k2p, f: f2p } = this.wNAF(k2);
|
|
6480
7484
|
k1p = wnaf.constTimeNegate(k1neg, k1p);
|
|
6481
7485
|
k2p = wnaf.constTimeNegate(k2neg, k2p);
|
|
6482
|
-
k2p = new
|
|
7486
|
+
k2p = new Point3(Fp2.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
6483
7487
|
point = k1p.add(k2p);
|
|
6484
7488
|
fake = f1p.add(f2p);
|
|
6485
7489
|
} else {
|
|
@@ -6487,7 +7491,7 @@ function weierstrassPoints(opts) {
|
|
|
6487
7491
|
point = p5;
|
|
6488
7492
|
fake = f3;
|
|
6489
7493
|
}
|
|
6490
|
-
return
|
|
7494
|
+
return Point3.normalizeZ([point, fake])[0];
|
|
6491
7495
|
}
|
|
6492
7496
|
/**
|
|
6493
7497
|
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
@@ -6496,8 +7500,8 @@ function weierstrassPoints(opts) {
|
|
|
6496
7500
|
* @returns non-zero affine point
|
|
6497
7501
|
*/
|
|
6498
7502
|
multiplyAndAddUnsafe(Q, a5, b2) {
|
|
6499
|
-
const G2 =
|
|
6500
|
-
const mul = (
|
|
7503
|
+
const G2 = Point3.BASE;
|
|
7504
|
+
const mul = (P2, a6) => a6 === _0n$3 || a6 === _1n$5 || !P2.equals(G2) ? P2.multiplyUnsafe(a6) : P2.multiply(a6);
|
|
6501
7505
|
const sum = mul(this, a5).add(mul(Q, b2));
|
|
6502
7506
|
return sum.is0() ? void 0 : sum;
|
|
6503
7507
|
}
|
|
@@ -6509,43 +7513,43 @@ function weierstrassPoints(opts) {
|
|
|
6509
7513
|
}
|
|
6510
7514
|
isTorsionFree() {
|
|
6511
7515
|
const { h: cofactor, isTorsionFree } = CURVE2;
|
|
6512
|
-
if (cofactor === _1n$
|
|
7516
|
+
if (cofactor === _1n$5)
|
|
6513
7517
|
return true;
|
|
6514
7518
|
if (isTorsionFree)
|
|
6515
|
-
return isTorsionFree(
|
|
7519
|
+
return isTorsionFree(Point3, this);
|
|
6516
7520
|
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
6517
7521
|
}
|
|
6518
7522
|
clearCofactor() {
|
|
6519
7523
|
const { h: cofactor, clearCofactor } = CURVE2;
|
|
6520
|
-
if (cofactor === _1n$
|
|
7524
|
+
if (cofactor === _1n$5)
|
|
6521
7525
|
return this;
|
|
6522
7526
|
if (clearCofactor)
|
|
6523
|
-
return clearCofactor(
|
|
7527
|
+
return clearCofactor(Point3, this);
|
|
6524
7528
|
return this.multiplyUnsafe(CURVE2.h);
|
|
6525
7529
|
}
|
|
6526
7530
|
toRawBytes(isCompressed = true) {
|
|
6527
7531
|
abool("isCompressed", isCompressed);
|
|
6528
7532
|
this.assertValidity();
|
|
6529
|
-
return toBytes2(
|
|
7533
|
+
return toBytes2(Point3, this, isCompressed);
|
|
6530
7534
|
}
|
|
6531
7535
|
toHex(isCompressed = true) {
|
|
6532
7536
|
abool("isCompressed", isCompressed);
|
|
6533
7537
|
return bytesToHex(this.toRawBytes(isCompressed));
|
|
6534
7538
|
}
|
|
6535
7539
|
}
|
|
6536
|
-
|
|
6537
|
-
|
|
7540
|
+
Point3.BASE = new Point3(CURVE2.Gx, CURVE2.Gy, Fp2.ONE);
|
|
7541
|
+
Point3.ZERO = new Point3(Fp2.ZERO, Fp2.ONE, Fp2.ZERO);
|
|
6538
7542
|
const _bits = CURVE2.nBitLength;
|
|
6539
|
-
const wnaf = wNAF$1(
|
|
7543
|
+
const wnaf = wNAF$1(Point3, CURVE2.endo ? Math.ceil(_bits / 2) : _bits);
|
|
6540
7544
|
return {
|
|
6541
7545
|
CURVE: CURVE2,
|
|
6542
|
-
ProjectivePoint:
|
|
7546
|
+
ProjectivePoint: Point3,
|
|
6543
7547
|
normPrivateKeyToScalar,
|
|
6544
7548
|
weierstrassEquation,
|
|
6545
7549
|
isWithinCurveOrder
|
|
6546
7550
|
};
|
|
6547
7551
|
}
|
|
6548
|
-
function validateOpts(curve2) {
|
|
7552
|
+
function validateOpts$1(curve2) {
|
|
6549
7553
|
const opts = validateBasic(curve2);
|
|
6550
7554
|
validateObject(opts, {
|
|
6551
7555
|
hash: "hash",
|
|
@@ -6559,27 +7563,27 @@ function validateOpts(curve2) {
|
|
|
6559
7563
|
return Object.freeze({ lowS: true, ...opts });
|
|
6560
7564
|
}
|
|
6561
7565
|
function weierstrass(curveDef) {
|
|
6562
|
-
const CURVE2 = validateOpts(curveDef);
|
|
6563
|
-
const { Fp, n: CURVE_ORDER } = CURVE2;
|
|
6564
|
-
const compressedLen =
|
|
6565
|
-
const uncompressedLen = 2 *
|
|
7566
|
+
const CURVE2 = validateOpts$1(curveDef);
|
|
7567
|
+
const { Fp: Fp2, n: CURVE_ORDER } = CURVE2;
|
|
7568
|
+
const compressedLen = Fp2.BYTES + 1;
|
|
7569
|
+
const uncompressedLen = 2 * Fp2.BYTES + 1;
|
|
6566
7570
|
function modN(a5) {
|
|
6567
7571
|
return mod(a5, CURVE_ORDER);
|
|
6568
7572
|
}
|
|
6569
7573
|
function invN(a5) {
|
|
6570
7574
|
return invert(a5, CURVE_ORDER);
|
|
6571
7575
|
}
|
|
6572
|
-
const { ProjectivePoint:
|
|
7576
|
+
const { ProjectivePoint: Point3, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
|
|
6573
7577
|
...CURVE2,
|
|
6574
7578
|
toBytes(_c4, point, isCompressed) {
|
|
6575
7579
|
const a5 = point.toAffine();
|
|
6576
|
-
const x2 =
|
|
7580
|
+
const x2 = Fp2.toBytes(a5.x);
|
|
6577
7581
|
const cat = concatBytes;
|
|
6578
7582
|
abool("isCompressed", isCompressed);
|
|
6579
7583
|
if (isCompressed) {
|
|
6580
7584
|
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x2);
|
|
6581
7585
|
} else {
|
|
6582
|
-
return cat(Uint8Array.from([4]), x2,
|
|
7586
|
+
return cat(Uint8Array.from([4]), x2, Fp2.toBytes(a5.y));
|
|
6583
7587
|
}
|
|
6584
7588
|
},
|
|
6585
7589
|
fromBytes(bytes) {
|
|
@@ -6588,24 +7592,24 @@ function weierstrass(curveDef) {
|
|
|
6588
7592
|
const tail = bytes.subarray(1);
|
|
6589
7593
|
if (len === compressedLen && (head === 2 || head === 3)) {
|
|
6590
7594
|
const x2 = bytesToNumberBE(tail);
|
|
6591
|
-
if (!inRange(x2, _1n$
|
|
7595
|
+
if (!inRange(x2, _1n$5, Fp2.ORDER))
|
|
6592
7596
|
throw new Error("Point is not on curve");
|
|
6593
7597
|
const y22 = weierstrassEquation(x2);
|
|
6594
7598
|
let y3;
|
|
6595
7599
|
try {
|
|
6596
|
-
y3 =
|
|
7600
|
+
y3 = Fp2.sqrt(y22);
|
|
6597
7601
|
} catch (sqrtError) {
|
|
6598
7602
|
const suffix = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
6599
7603
|
throw new Error("Point is not on curve" + suffix);
|
|
6600
7604
|
}
|
|
6601
|
-
const isYOdd = (y3 & _1n$
|
|
7605
|
+
const isYOdd = (y3 & _1n$5) === _1n$5;
|
|
6602
7606
|
const isHeadOdd = (head & 1) === 1;
|
|
6603
7607
|
if (isHeadOdd !== isYOdd)
|
|
6604
|
-
y3 =
|
|
7608
|
+
y3 = Fp2.neg(y3);
|
|
6605
7609
|
return { x: x2, y: y3 };
|
|
6606
7610
|
} else if (len === uncompressedLen && head === 4) {
|
|
6607
|
-
const x2 =
|
|
6608
|
-
const y3 =
|
|
7611
|
+
const x2 = Fp2.fromBytes(tail.subarray(0, Fp2.BYTES));
|
|
7612
|
+
const y3 = Fp2.fromBytes(tail.subarray(Fp2.BYTES, 2 * Fp2.BYTES));
|
|
6609
7613
|
return { x: x2, y: y3 };
|
|
6610
7614
|
} else {
|
|
6611
7615
|
const cl = compressedLen;
|
|
@@ -6616,7 +7620,7 @@ function weierstrass(curveDef) {
|
|
|
6616
7620
|
});
|
|
6617
7621
|
const numToNByteStr = (num) => bytesToHex(numberToBytesBE(num, CURVE2.nByteLength));
|
|
6618
7622
|
function isBiggerThanHalfOrder(number) {
|
|
6619
|
-
const HALF = CURVE_ORDER >> _1n$
|
|
7623
|
+
const HALF = CURVE_ORDER >> _1n$5;
|
|
6620
7624
|
return number > HALF;
|
|
6621
7625
|
}
|
|
6622
7626
|
function normalizeS(s5) {
|
|
@@ -6643,8 +7647,8 @@ function weierstrass(curveDef) {
|
|
|
6643
7647
|
return new Signature(r7, s5);
|
|
6644
7648
|
}
|
|
6645
7649
|
assertValidity() {
|
|
6646
|
-
aInRange("r", this.r, _1n$
|
|
6647
|
-
aInRange("s", this.s, _1n$
|
|
7650
|
+
aInRange("r", this.r, _1n$5, CURVE_ORDER);
|
|
7651
|
+
aInRange("s", this.s, _1n$5, CURVE_ORDER);
|
|
6648
7652
|
}
|
|
6649
7653
|
addRecoveryBit(recovery) {
|
|
6650
7654
|
return new Signature(this.r, this.s, recovery);
|
|
@@ -6655,14 +7659,14 @@ function weierstrass(curveDef) {
|
|
|
6655
7659
|
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
6656
7660
|
throw new Error("recovery id invalid");
|
|
6657
7661
|
const radj = rec === 2 || rec === 3 ? r7 + CURVE2.n : r7;
|
|
6658
|
-
if (radj >=
|
|
7662
|
+
if (radj >= Fp2.ORDER)
|
|
6659
7663
|
throw new Error("recovery id 2 or 3 invalid");
|
|
6660
7664
|
const prefix = (rec & 1) === 0 ? "02" : "03";
|
|
6661
|
-
const R2 =
|
|
7665
|
+
const R2 = Point3.fromHex(prefix + numToNByteStr(radj));
|
|
6662
7666
|
const ir = invN(radj);
|
|
6663
7667
|
const u1 = modN(-h2 * ir);
|
|
6664
7668
|
const u22 = modN(s5 * ir);
|
|
6665
|
-
const Q =
|
|
7669
|
+
const Q = Point3.BASE.multiplyAndAddUnsafe(R2, u1, u22);
|
|
6666
7670
|
if (!Q)
|
|
6667
7671
|
throw new Error("point at infinify");
|
|
6668
7672
|
Q.assertValidity();
|
|
@@ -6716,14 +7720,14 @@ function weierstrass(curveDef) {
|
|
|
6716
7720
|
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
6717
7721
|
* fast.multiply(privKey); // much faster ECDH now
|
|
6718
7722
|
*/
|
|
6719
|
-
precompute(windowSize = 8, point =
|
|
7723
|
+
precompute(windowSize = 8, point = Point3.BASE) {
|
|
6720
7724
|
point._setWindowSize(windowSize);
|
|
6721
7725
|
point.multiply(BigInt(3));
|
|
6722
7726
|
return point;
|
|
6723
7727
|
}
|
|
6724
7728
|
};
|
|
6725
7729
|
function getPublicKey2(privateKey, isCompressed = true) {
|
|
6726
|
-
return
|
|
7730
|
+
return Point3.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
6727
7731
|
}
|
|
6728
7732
|
function isProbPub(item) {
|
|
6729
7733
|
const arr = isBytes$2(item);
|
|
@@ -6733,7 +7737,7 @@ function weierstrass(curveDef) {
|
|
|
6733
7737
|
return len === compressedLen || len === uncompressedLen;
|
|
6734
7738
|
if (str)
|
|
6735
7739
|
return len === 2 * compressedLen || len === 2 * uncompressedLen;
|
|
6736
|
-
if (item instanceof
|
|
7740
|
+
if (item instanceof Point3)
|
|
6737
7741
|
return true;
|
|
6738
7742
|
return false;
|
|
6739
7743
|
}
|
|
@@ -6742,7 +7746,7 @@ function weierstrass(curveDef) {
|
|
|
6742
7746
|
throw new Error("first arg must be private key");
|
|
6743
7747
|
if (!isProbPub(publicB))
|
|
6744
7748
|
throw new Error("second arg must be public key");
|
|
6745
|
-
const b2 =
|
|
7749
|
+
const b2 = Point3.fromHex(publicB);
|
|
6746
7750
|
return b2.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
6747
7751
|
}
|
|
6748
7752
|
const bits2int = CURVE2.bits2int || function(bytes) {
|
|
@@ -6757,7 +7761,7 @@ function weierstrass(curveDef) {
|
|
|
6757
7761
|
};
|
|
6758
7762
|
const ORDER_MASK = bitMask(CURVE2.nBitLength);
|
|
6759
7763
|
function int2octets(num) {
|
|
6760
|
-
aInRange("num < 2^" + CURVE2.nBitLength, num, _0n$
|
|
7764
|
+
aInRange("num < 2^" + CURVE2.nBitLength, num, _0n$3, ORDER_MASK);
|
|
6761
7765
|
return numberToBytesBE(num, CURVE2.nByteLength);
|
|
6762
7766
|
}
|
|
6763
7767
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
@@ -6775,7 +7779,7 @@ function weierstrass(curveDef) {
|
|
|
6775
7779
|
const d2 = normPrivateKeyToScalar(privateKey);
|
|
6776
7780
|
const seedArgs = [int2octets(d2), int2octets(h1int)];
|
|
6777
7781
|
if (ent != null && ent !== false) {
|
|
6778
|
-
const e4 = ent === true ? randomBytes2(
|
|
7782
|
+
const e4 = ent === true ? randomBytes2(Fp2.BYTES) : ent;
|
|
6779
7783
|
seedArgs.push(ensureBytes("extraEntropy", e4));
|
|
6780
7784
|
}
|
|
6781
7785
|
const seed = concatBytes(...seedArgs);
|
|
@@ -6785,14 +7789,14 @@ function weierstrass(curveDef) {
|
|
|
6785
7789
|
if (!isWithinCurveOrder(k2))
|
|
6786
7790
|
return;
|
|
6787
7791
|
const ik = invN(k2);
|
|
6788
|
-
const q2 =
|
|
7792
|
+
const q2 = Point3.BASE.multiply(k2).toAffine();
|
|
6789
7793
|
const r7 = modN(q2.x);
|
|
6790
|
-
if (r7 === _0n$
|
|
7794
|
+
if (r7 === _0n$3)
|
|
6791
7795
|
return;
|
|
6792
7796
|
const s5 = modN(ik * modN(m2 + r7 * d2));
|
|
6793
|
-
if (s5 === _0n$
|
|
7797
|
+
if (s5 === _0n$3)
|
|
6794
7798
|
return;
|
|
6795
|
-
let recovery = (q2.x === r7 ? 0 : 2) | Number(q2.y & _1n$
|
|
7799
|
+
let recovery = (q2.x === r7 ? 0 : 2) | Number(q2.y & _1n$5);
|
|
6796
7800
|
let normS = s5;
|
|
6797
7801
|
if (lowS && isBiggerThanHalfOrder(s5)) {
|
|
6798
7802
|
normS = normalizeS(s5);
|
|
@@ -6806,11 +7810,11 @@ function weierstrass(curveDef) {
|
|
|
6806
7810
|
const defaultVerOpts = { lowS: CURVE2.lowS, prehash: false };
|
|
6807
7811
|
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
|
6808
7812
|
const { seed, k2sig } = prepSig(msgHash, privKey, opts);
|
|
6809
|
-
const
|
|
6810
|
-
const drbg = createHmacDrbg(
|
|
7813
|
+
const C2 = CURVE2;
|
|
7814
|
+
const drbg = createHmacDrbg(C2.hash.outputLen, C2.nByteLength, C2.hmac);
|
|
6811
7815
|
return drbg(seed, k2sig);
|
|
6812
7816
|
}
|
|
6813
|
-
|
|
7817
|
+
Point3.BASE._setWindowSize(8);
|
|
6814
7818
|
function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
6815
7819
|
var _a4;
|
|
6816
7820
|
const sg = signature;
|
|
@@ -6827,7 +7831,7 @@ function weierstrass(curveDef) {
|
|
|
6827
7831
|
if (!isHex && !isObj)
|
|
6828
7832
|
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
6829
7833
|
let _sig = void 0;
|
|
6830
|
-
let
|
|
7834
|
+
let P2;
|
|
6831
7835
|
try {
|
|
6832
7836
|
if (isObj)
|
|
6833
7837
|
_sig = new Signature(sg.r, sg.s);
|
|
@@ -6842,7 +7846,7 @@ function weierstrass(curveDef) {
|
|
|
6842
7846
|
if (!_sig && format !== "der")
|
|
6843
7847
|
_sig = Signature.fromCompact(sg);
|
|
6844
7848
|
}
|
|
6845
|
-
|
|
7849
|
+
P2 = Point3.fromHex(publicKey);
|
|
6846
7850
|
} catch (error) {
|
|
6847
7851
|
return false;
|
|
6848
7852
|
}
|
|
@@ -6857,7 +7861,7 @@ function weierstrass(curveDef) {
|
|
|
6857
7861
|
const is = invN(s5);
|
|
6858
7862
|
const u1 = modN(h2 * is);
|
|
6859
7863
|
const u22 = modN(r7 * is);
|
|
6860
|
-
const R2 = (_a4 =
|
|
7864
|
+
const R2 = (_a4 = Point3.BASE.multiplyAndAddUnsafe(P2, u1, u22)) == null ? void 0 : _a4.toAffine();
|
|
6861
7865
|
if (!R2)
|
|
6862
7866
|
return false;
|
|
6863
7867
|
const v2 = modN(R2.x);
|
|
@@ -6869,7 +7873,7 @@ function weierstrass(curveDef) {
|
|
|
6869
7873
|
getSharedSecret,
|
|
6870
7874
|
sign,
|
|
6871
7875
|
verify,
|
|
6872
|
-
ProjectivePoint:
|
|
7876
|
+
ProjectivePoint: Point3,
|
|
6873
7877
|
Signature,
|
|
6874
7878
|
utils: utils2
|
|
6875
7879
|
};
|
|
@@ -6889,27 +7893,27 @@ function createCurve(curveDef, defHash) {
|
|
|
6889
7893
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6890
7894
|
const secp256k1P = BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f");
|
|
6891
7895
|
const secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
6892
|
-
const _1n$
|
|
6893
|
-
const _2n$
|
|
6894
|
-
const divNearest = (a5, b2) => (a5 + b2 / _2n$
|
|
7896
|
+
const _1n$4 = BigInt(1);
|
|
7897
|
+
const _2n$4 = BigInt(2);
|
|
7898
|
+
const divNearest = (a5, b2) => (a5 + b2 / _2n$4) / b2;
|
|
6895
7899
|
function sqrtMod(y3) {
|
|
6896
|
-
const
|
|
7900
|
+
const P2 = secp256k1P;
|
|
6897
7901
|
const _3n2 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
6898
7902
|
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
6899
|
-
const b2 = y3 * y3 * y3 %
|
|
6900
|
-
const b3 = b2 * b2 * y3 %
|
|
6901
|
-
const b6 = pow2(b3, _3n2,
|
|
6902
|
-
const b9 = pow2(b6, _3n2,
|
|
6903
|
-
const b11 = pow2(b9, _2n$
|
|
6904
|
-
const b22 = pow2(b11, _11n,
|
|
6905
|
-
const b44 = pow2(b22, _22n,
|
|
6906
|
-
const b88 = pow2(b44, _44n,
|
|
6907
|
-
const b176 = pow2(b88, _88n,
|
|
6908
|
-
const b220 = pow2(b176, _44n,
|
|
6909
|
-
const b223 = pow2(b220, _3n2,
|
|
6910
|
-
const t1 = pow2(b223, _23n,
|
|
6911
|
-
const t22 = pow2(t1, _6n,
|
|
6912
|
-
const root2 = pow2(t22, _2n$
|
|
7903
|
+
const b2 = y3 * y3 * y3 % P2;
|
|
7904
|
+
const b3 = b2 * b2 * y3 % P2;
|
|
7905
|
+
const b6 = pow2(b3, _3n2, P2) * b3 % P2;
|
|
7906
|
+
const b9 = pow2(b6, _3n2, P2) * b3 % P2;
|
|
7907
|
+
const b11 = pow2(b9, _2n$4, P2) * b2 % P2;
|
|
7908
|
+
const b22 = pow2(b11, _11n, P2) * b11 % P2;
|
|
7909
|
+
const b44 = pow2(b22, _22n, P2) * b22 % P2;
|
|
7910
|
+
const b88 = pow2(b44, _44n, P2) * b44 % P2;
|
|
7911
|
+
const b176 = pow2(b88, _88n, P2) * b88 % P2;
|
|
7912
|
+
const b220 = pow2(b176, _44n, P2) * b44 % P2;
|
|
7913
|
+
const b223 = pow2(b220, _3n2, P2) * b3 % P2;
|
|
7914
|
+
const t1 = pow2(b223, _23n, P2) * b22 % P2;
|
|
7915
|
+
const t22 = pow2(t1, _6n, P2) * b2 % P2;
|
|
7916
|
+
const root2 = pow2(t22, _2n$4, P2);
|
|
6913
7917
|
if (!Fpk1.eql(Fpk1.sqr(root2), y3))
|
|
6914
7918
|
throw new Error("Cannot find square root");
|
|
6915
7919
|
return root2;
|
|
@@ -6936,7 +7940,7 @@ const secp256k1 = createCurve({
|
|
|
6936
7940
|
splitScalar: (k2) => {
|
|
6937
7941
|
const n4 = secp256k1N;
|
|
6938
7942
|
const a1 = BigInt("0x3086d221a7d46bcde86c90e49284eb15");
|
|
6939
|
-
const b1 = -_1n$
|
|
7943
|
+
const b1 = -_1n$4 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3");
|
|
6940
7944
|
const a22 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8");
|
|
6941
7945
|
const b2 = a1;
|
|
6942
7946
|
const POW_2_128 = BigInt("0x100000000000000000000000000000000");
|
|
@@ -6964,6 +7968,1108 @@ function delegationMessage(terms) {
|
|
|
6964
7968
|
const expires = BigInt(terms.deadline) === 0n ? "never" : BigInt(terms.deadline).toString(10);
|
|
6965
7969
|
return HEAD + terms.delegate.toLowerCase() + "\nContract: " + terms.contract.toLowerCase() + "\nChain ID: " + BigInt(terms.chainId).toString(10) + "\nExpires: " + expires;
|
|
6966
7970
|
}
|
|
7971
|
+
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
7972
|
+
const B256 = 2n ** 256n;
|
|
7973
|
+
const P$2 = B256 - 0x1000003d1n;
|
|
7974
|
+
const N$1 = B256 - 0x14551231950b75fc4402da1732fc9bebfn;
|
|
7975
|
+
const Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n;
|
|
7976
|
+
const Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;
|
|
7977
|
+
const CURVE = {
|
|
7978
|
+
a: 0n,
|
|
7979
|
+
b: 7n
|
|
7980
|
+
};
|
|
7981
|
+
const fLen = 32;
|
|
7982
|
+
const curve = (x2) => M$1(M$1(x2 * x2) * x2 + CURVE.b);
|
|
7983
|
+
const err = (m2 = "") => {
|
|
7984
|
+
throw new Error(m2);
|
|
7985
|
+
};
|
|
7986
|
+
const isB = (n4) => typeof n4 === "bigint";
|
|
7987
|
+
const isS = (s5) => typeof s5 === "string";
|
|
7988
|
+
const fe = (n4) => isB(n4) && 0n < n4 && n4 < P$2;
|
|
7989
|
+
const ge = (n4) => isB(n4) && 0n < n4 && n4 < N$1;
|
|
7990
|
+
const isu8 = (a5) => a5 instanceof Uint8Array || ArrayBuffer.isView(a5) && a5.constructor.name === "Uint8Array";
|
|
7991
|
+
const au8 = (a5, l3) => (
|
|
7992
|
+
// assert is Uint8Array (of specific length)
|
|
7993
|
+
!isu8(a5) || typeof l3 === "number" && l3 > 0 && a5.length !== l3 ? err("Uint8Array expected") : a5
|
|
7994
|
+
);
|
|
7995
|
+
const u8n = (data) => new Uint8Array(data);
|
|
7996
|
+
const toU8 = (a5, len) => au8(isS(a5) ? h2b(a5) : u8n(au8(a5)), len);
|
|
7997
|
+
const M$1 = (a5, b2 = P$2) => {
|
|
7998
|
+
const r7 = a5 % b2;
|
|
7999
|
+
return r7 >= 0n ? r7 : b2 + r7;
|
|
8000
|
+
};
|
|
8001
|
+
const aPoint = (p5) => p5 instanceof Point$1 ? p5 : err("Point expected");
|
|
8002
|
+
let Point$1 = class Point {
|
|
8003
|
+
constructor(px, py, pz) {
|
|
8004
|
+
this.px = px;
|
|
8005
|
+
this.py = py;
|
|
8006
|
+
this.pz = pz;
|
|
8007
|
+
Object.freeze(this);
|
|
8008
|
+
}
|
|
8009
|
+
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
8010
|
+
static fromAffine(p5) {
|
|
8011
|
+
return p5.x === 0n && p5.y === 0n ? I$1 : new Point(p5.x, p5.y, 1n);
|
|
8012
|
+
}
|
|
8013
|
+
/** Convert Uint8Array or hex string to Point. */
|
|
8014
|
+
static fromHex(hex) {
|
|
8015
|
+
hex = toU8(hex);
|
|
8016
|
+
let p5 = void 0;
|
|
8017
|
+
const head = hex[0], tail = hex.subarray(1);
|
|
8018
|
+
const x2 = slc(tail, 0, fLen), len = hex.length;
|
|
8019
|
+
if (len === 33 && [2, 3].includes(head)) {
|
|
8020
|
+
if (!fe(x2))
|
|
8021
|
+
err("Point hex invalid: x not FE");
|
|
8022
|
+
let y3 = sqrt(curve(x2));
|
|
8023
|
+
const isYOdd = (y3 & 1n) === 1n;
|
|
8024
|
+
const headOdd = (head & 1) === 1;
|
|
8025
|
+
if (headOdd !== isYOdd)
|
|
8026
|
+
y3 = M$1(-y3);
|
|
8027
|
+
p5 = new Point(x2, y3, 1n);
|
|
8028
|
+
}
|
|
8029
|
+
if (len === 65 && head === 4)
|
|
8030
|
+
p5 = new Point(x2, slc(tail, fLen, 2 * fLen), 1n);
|
|
8031
|
+
return p5 ? p5.ok() : err("Point invalid: not on curve");
|
|
8032
|
+
}
|
|
8033
|
+
/** Create point from a private key. */
|
|
8034
|
+
static fromPrivateKey(k2) {
|
|
8035
|
+
return G$1.mul(toPriv(k2));
|
|
8036
|
+
}
|
|
8037
|
+
get x() {
|
|
8038
|
+
return this.aff().x;
|
|
8039
|
+
}
|
|
8040
|
+
// .x, .y will call expensive toAffine:
|
|
8041
|
+
get y() {
|
|
8042
|
+
return this.aff().y;
|
|
8043
|
+
}
|
|
8044
|
+
// should be used with care.
|
|
8045
|
+
/** Equality check: compare points P&Q. */
|
|
8046
|
+
equals(other) {
|
|
8047
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
8048
|
+
const { px: X2, py: Y2, pz: Z2 } = aPoint(other);
|
|
8049
|
+
const X1Z2 = M$1(X1 * Z2), X2Z1 = M$1(X2 * Z1);
|
|
8050
|
+
const Y1Z2 = M$1(Y1 * Z2), Y2Z1 = M$1(Y2 * Z1);
|
|
8051
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
8052
|
+
}
|
|
8053
|
+
/** Flip point over y coordinate. */
|
|
8054
|
+
negate() {
|
|
8055
|
+
return new Point(this.px, M$1(-this.py), this.pz);
|
|
8056
|
+
}
|
|
8057
|
+
/** Point doubling: P+P, complete formula. */
|
|
8058
|
+
double() {
|
|
8059
|
+
return this.add(this);
|
|
8060
|
+
}
|
|
8061
|
+
/**
|
|
8062
|
+
* Point addition: P+Q, complete, exception-free formula
|
|
8063
|
+
* (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
|
|
8064
|
+
* Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
8065
|
+
*/
|
|
8066
|
+
add(other) {
|
|
8067
|
+
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
8068
|
+
const { px: X2, py: Y2, pz: Z2 } = aPoint(other);
|
|
8069
|
+
const { a: a5, b: b2 } = CURVE;
|
|
8070
|
+
let X3 = 0n, Y3 = 0n, Z3 = 0n;
|
|
8071
|
+
const b3 = M$1(b2 * 3n);
|
|
8072
|
+
let t0 = M$1(X1 * X2), t1 = M$1(Y1 * Y2), t22 = M$1(Z1 * Z2), t32 = M$1(X1 + Y1);
|
|
8073
|
+
let t42 = M$1(X2 + Y2);
|
|
8074
|
+
t32 = M$1(t32 * t42);
|
|
8075
|
+
t42 = M$1(t0 + t1);
|
|
8076
|
+
t32 = M$1(t32 - t42);
|
|
8077
|
+
t42 = M$1(X1 + Z1);
|
|
8078
|
+
let t52 = M$1(X2 + Z2);
|
|
8079
|
+
t42 = M$1(t42 * t52);
|
|
8080
|
+
t52 = M$1(t0 + t22);
|
|
8081
|
+
t42 = M$1(t42 - t52);
|
|
8082
|
+
t52 = M$1(Y1 + Z1);
|
|
8083
|
+
X3 = M$1(Y2 + Z2);
|
|
8084
|
+
t52 = M$1(t52 * X3);
|
|
8085
|
+
X3 = M$1(t1 + t22);
|
|
8086
|
+
t52 = M$1(t52 - X3);
|
|
8087
|
+
Z3 = M$1(a5 * t42);
|
|
8088
|
+
X3 = M$1(b3 * t22);
|
|
8089
|
+
Z3 = M$1(X3 + Z3);
|
|
8090
|
+
X3 = M$1(t1 - Z3);
|
|
8091
|
+
Z3 = M$1(t1 + Z3);
|
|
8092
|
+
Y3 = M$1(X3 * Z3);
|
|
8093
|
+
t1 = M$1(t0 + t0);
|
|
8094
|
+
t1 = M$1(t1 + t0);
|
|
8095
|
+
t22 = M$1(a5 * t22);
|
|
8096
|
+
t42 = M$1(b3 * t42);
|
|
8097
|
+
t1 = M$1(t1 + t22);
|
|
8098
|
+
t22 = M$1(t0 - t22);
|
|
8099
|
+
t22 = M$1(a5 * t22);
|
|
8100
|
+
t42 = M$1(t42 + t22);
|
|
8101
|
+
t0 = M$1(t1 * t42);
|
|
8102
|
+
Y3 = M$1(Y3 + t0);
|
|
8103
|
+
t0 = M$1(t52 * t42);
|
|
8104
|
+
X3 = M$1(t32 * X3);
|
|
8105
|
+
X3 = M$1(X3 - t0);
|
|
8106
|
+
t0 = M$1(t32 * t1);
|
|
8107
|
+
Z3 = M$1(t52 * Z3);
|
|
8108
|
+
Z3 = M$1(Z3 + t0);
|
|
8109
|
+
return new Point(X3, Y3, Z3);
|
|
8110
|
+
}
|
|
8111
|
+
mul(n4, safe = true) {
|
|
8112
|
+
if (!safe && n4 === 0n)
|
|
8113
|
+
return I$1;
|
|
8114
|
+
if (!ge(n4))
|
|
8115
|
+
err("scalar invalid");
|
|
8116
|
+
if (this.equals(G$1))
|
|
8117
|
+
return wNAF2(n4).p;
|
|
8118
|
+
let p5 = I$1, f3 = G$1;
|
|
8119
|
+
for (let d2 = this; n4 > 0n; d2 = d2.double(), n4 >>= 1n) {
|
|
8120
|
+
if (n4 & 1n)
|
|
8121
|
+
p5 = p5.add(d2);
|
|
8122
|
+
else if (safe)
|
|
8123
|
+
f3 = f3.add(d2);
|
|
8124
|
+
}
|
|
8125
|
+
return p5;
|
|
8126
|
+
}
|
|
8127
|
+
mulAddQUns(R2, u1, u22) {
|
|
8128
|
+
return this.mul(u1, false).add(R2.mul(u22, false)).ok();
|
|
8129
|
+
}
|
|
8130
|
+
// to private keys. Doesn't use Shamir trick
|
|
8131
|
+
/** Convert point to 2d xy affine point. (x, y, z) ∋ (x=x/z, y=y/z) */
|
|
8132
|
+
toAffine() {
|
|
8133
|
+
const { px: x2, py: y3, pz: z2 } = this;
|
|
8134
|
+
if (this.equals(I$1))
|
|
8135
|
+
return { x: 0n, y: 0n };
|
|
8136
|
+
if (z2 === 1n)
|
|
8137
|
+
return { x: x2, y: y3 };
|
|
8138
|
+
const iz = inv(z2, P$2);
|
|
8139
|
+
if (M$1(z2 * iz) !== 1n)
|
|
8140
|
+
err("inverse invalid");
|
|
8141
|
+
return { x: M$1(x2 * iz), y: M$1(y3 * iz) };
|
|
8142
|
+
}
|
|
8143
|
+
/** Checks if the point is valid and on-curve. */
|
|
8144
|
+
assertValidity() {
|
|
8145
|
+
const { x: x2, y: y3 } = this.aff();
|
|
8146
|
+
if (!fe(x2) || !fe(y3))
|
|
8147
|
+
err("Point invalid: x or y");
|
|
8148
|
+
return M$1(y3 * y3) === curve(x2) ? (
|
|
8149
|
+
// y² = x³ + ax + b, must be equal
|
|
8150
|
+
this
|
|
8151
|
+
) : err("Point invalid: not on curve");
|
|
8152
|
+
}
|
|
8153
|
+
multiply(n4) {
|
|
8154
|
+
return this.mul(n4);
|
|
8155
|
+
}
|
|
8156
|
+
// Aliases to compress code
|
|
8157
|
+
aff() {
|
|
8158
|
+
return this.toAffine();
|
|
8159
|
+
}
|
|
8160
|
+
ok() {
|
|
8161
|
+
return this.assertValidity();
|
|
8162
|
+
}
|
|
8163
|
+
toHex(isCompressed = true) {
|
|
8164
|
+
const { x: x2, y: y3 } = this.aff();
|
|
8165
|
+
const head = isCompressed ? (y3 & 1n) === 0n ? "02" : "03" : "04";
|
|
8166
|
+
return head + n2h(x2) + (isCompressed ? "" : n2h(y3));
|
|
8167
|
+
}
|
|
8168
|
+
toRawBytes(isCompressed = true) {
|
|
8169
|
+
return h2b(this.toHex(isCompressed));
|
|
8170
|
+
}
|
|
8171
|
+
};
|
|
8172
|
+
Point$1.BASE = new Point$1(Gx, Gy, 1n);
|
|
8173
|
+
Point$1.ZERO = new Point$1(0n, 1n, 0n);
|
|
8174
|
+
const { BASE: G$1, ZERO: I$1 } = Point$1;
|
|
8175
|
+
const padh = (n4, pad) => n4.toString(16).padStart(pad, "0");
|
|
8176
|
+
const b2h = (b2) => Array.from(au8(b2)).map((e4) => padh(e4, 2)).join("");
|
|
8177
|
+
const C$3 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
8178
|
+
const _ch = (ch) => {
|
|
8179
|
+
if (ch >= C$3._0 && ch <= C$3._9)
|
|
8180
|
+
return ch - C$3._0;
|
|
8181
|
+
if (ch >= C$3.A && ch <= C$3.F)
|
|
8182
|
+
return ch - (C$3.A - 10);
|
|
8183
|
+
if (ch >= C$3.a && ch <= C$3.f)
|
|
8184
|
+
return ch - (C$3.a - 10);
|
|
8185
|
+
return;
|
|
8186
|
+
};
|
|
8187
|
+
const h2b = (hex) => {
|
|
8188
|
+
const e4 = "hex invalid";
|
|
8189
|
+
if (!isS(hex))
|
|
8190
|
+
return err(e4);
|
|
8191
|
+
const hl = hex.length, al = hl / 2;
|
|
8192
|
+
if (hl % 2)
|
|
8193
|
+
return err(e4);
|
|
8194
|
+
const array = u8n(al);
|
|
8195
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
8196
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
8197
|
+
const n22 = _ch(hex.charCodeAt(hi + 1));
|
|
8198
|
+
if (n1 === void 0 || n22 === void 0)
|
|
8199
|
+
return err(e4);
|
|
8200
|
+
array[ai] = n1 * 16 + n22;
|
|
8201
|
+
}
|
|
8202
|
+
return array;
|
|
8203
|
+
};
|
|
8204
|
+
const b2n = (b2) => BigInt("0x" + (b2h(b2) || "0"));
|
|
8205
|
+
const slc = (b2, from, to) => b2n(b2.slice(from, to));
|
|
8206
|
+
const n2b = (num) => {
|
|
8207
|
+
return isB(num) && num >= 0n && num < B256 ? h2b(padh(num, 2 * fLen)) : err("bigint expected");
|
|
8208
|
+
};
|
|
8209
|
+
const n2h = (num) => b2h(n2b(num));
|
|
8210
|
+
const inv = (num, md) => {
|
|
8211
|
+
if (num === 0n || md <= 0n)
|
|
8212
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
8213
|
+
let a5 = M$1(num, md), b2 = md, x2 = 0n, u4 = 1n;
|
|
8214
|
+
while (a5 !== 0n) {
|
|
8215
|
+
const q2 = b2 / a5, r7 = b2 % a5;
|
|
8216
|
+
const m2 = x2 - u4 * q2;
|
|
8217
|
+
b2 = a5, a5 = r7, x2 = u4, u4 = m2;
|
|
8218
|
+
}
|
|
8219
|
+
return b2 === 1n ? M$1(x2, md) : err("no inverse");
|
|
8220
|
+
};
|
|
8221
|
+
const sqrt = (n4) => {
|
|
8222
|
+
let r7 = 1n;
|
|
8223
|
+
for (let num = n4, e4 = (P$2 + 1n) / 4n; e4 > 0n; e4 >>= 1n) {
|
|
8224
|
+
if (e4 & 1n)
|
|
8225
|
+
r7 = r7 * num % P$2;
|
|
8226
|
+
num = num * num % P$2;
|
|
8227
|
+
}
|
|
8228
|
+
return M$1(r7 * r7) === n4 ? r7 : err("sqrt invalid");
|
|
8229
|
+
};
|
|
8230
|
+
const toPriv = (p5) => {
|
|
8231
|
+
if (!isB(p5))
|
|
8232
|
+
p5 = b2n(toU8(p5, fLen));
|
|
8233
|
+
return ge(p5) ? p5 : err("private key invalid 3");
|
|
8234
|
+
};
|
|
8235
|
+
const getPublicKey = (privKey, isCompressed = true) => {
|
|
8236
|
+
return Point$1.fromPrivateKey(privKey).toRawBytes(isCompressed);
|
|
8237
|
+
};
|
|
8238
|
+
const W = 8;
|
|
8239
|
+
const precompute = () => {
|
|
8240
|
+
const points = [];
|
|
8241
|
+
const windows = 256 / W + 1;
|
|
8242
|
+
let p5 = G$1, b2 = p5;
|
|
8243
|
+
for (let w2 = 0; w2 < windows; w2++) {
|
|
8244
|
+
b2 = p5;
|
|
8245
|
+
points.push(b2);
|
|
8246
|
+
for (let i3 = 1; i3 < 2 ** (W - 1); i3++) {
|
|
8247
|
+
b2 = b2.add(p5);
|
|
8248
|
+
points.push(b2);
|
|
8249
|
+
}
|
|
8250
|
+
p5 = b2.double();
|
|
8251
|
+
}
|
|
8252
|
+
return points;
|
|
8253
|
+
};
|
|
8254
|
+
let Gpows = void 0;
|
|
8255
|
+
const wNAF2 = (n4) => {
|
|
8256
|
+
const comp = Gpows || (Gpows = precompute());
|
|
8257
|
+
const neg = (cnd, p6) => {
|
|
8258
|
+
let n5 = p6.negate();
|
|
8259
|
+
return cnd ? n5 : p6;
|
|
8260
|
+
};
|
|
8261
|
+
let p5 = I$1, f3 = G$1;
|
|
8262
|
+
const windows = 1 + 256 / W;
|
|
8263
|
+
const wsize = 2 ** (W - 1);
|
|
8264
|
+
const mask = BigInt(2 ** W - 1);
|
|
8265
|
+
const maxNum = 2 ** W;
|
|
8266
|
+
const shiftBy = BigInt(W);
|
|
8267
|
+
for (let w2 = 0; w2 < windows; w2++) {
|
|
8268
|
+
const off = w2 * wsize;
|
|
8269
|
+
let wbits = Number(n4 & mask);
|
|
8270
|
+
n4 >>= shiftBy;
|
|
8271
|
+
if (wbits > wsize) {
|
|
8272
|
+
wbits -= maxNum;
|
|
8273
|
+
n4 += 1n;
|
|
8274
|
+
}
|
|
8275
|
+
const off1 = off, off2 = off + Math.abs(wbits) - 1;
|
|
8276
|
+
const cnd1 = w2 % 2 !== 0, cnd2 = wbits < 0;
|
|
8277
|
+
if (wbits === 0) {
|
|
8278
|
+
f3 = f3.add(neg(cnd1, comp[off1]));
|
|
8279
|
+
} else {
|
|
8280
|
+
p5 = p5.add(neg(cnd2, comp[off2]));
|
|
8281
|
+
}
|
|
8282
|
+
}
|
|
8283
|
+
return { p: p5, f: f3 };
|
|
8284
|
+
};
|
|
8285
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8286
|
+
const _0n$2 = BigInt(0), _1n$3 = BigInt(1), _2n$3 = BigInt(2), _8n$1 = BigInt(8);
|
|
8287
|
+
function isEdValidXY(Fp2, CURVE2, x2, y3) {
|
|
8288
|
+
const x22 = Fp2.sqr(x2);
|
|
8289
|
+
const y22 = Fp2.sqr(y3);
|
|
8290
|
+
const left = Fp2.add(Fp2.mul(CURVE2.a, x22), y22);
|
|
8291
|
+
const right = Fp2.add(Fp2.ONE, Fp2.mul(CURVE2.d, Fp2.mul(x22, y22)));
|
|
8292
|
+
return Fp2.eql(left, right);
|
|
8293
|
+
}
|
|
8294
|
+
function edwards(params, extraOpts = {}) {
|
|
8295
|
+
const validated = _createCurveFields("edwards", params, extraOpts, extraOpts.FpFnLE);
|
|
8296
|
+
const { Fp: Fp2, Fn } = validated;
|
|
8297
|
+
let CURVE2 = validated.CURVE;
|
|
8298
|
+
const { h: cofactor } = CURVE2;
|
|
8299
|
+
_validateObject(extraOpts, {}, { uvRatio: "function" });
|
|
8300
|
+
const MASK = _2n$3 << BigInt(Fn.BYTES * 8) - _1n$3;
|
|
8301
|
+
const modP = (n4) => Fp2.create(n4);
|
|
8302
|
+
const uvRatio2 = extraOpts.uvRatio || ((u4, v2) => {
|
|
8303
|
+
try {
|
|
8304
|
+
return { isValid: true, value: Fp2.sqrt(Fp2.div(u4, v2)) };
|
|
8305
|
+
} catch (e4) {
|
|
8306
|
+
return { isValid: false, value: _0n$2 };
|
|
8307
|
+
}
|
|
8308
|
+
});
|
|
8309
|
+
if (!isEdValidXY(Fp2, CURVE2, CURVE2.Gx, CURVE2.Gy))
|
|
8310
|
+
throw new Error("bad curve params: generator point");
|
|
8311
|
+
function acoord(title, n4, banZero = false) {
|
|
8312
|
+
const min = banZero ? _1n$3 : _0n$2;
|
|
8313
|
+
aInRange$1("coordinate " + title, n4, min, MASK);
|
|
8314
|
+
return n4;
|
|
8315
|
+
}
|
|
8316
|
+
function aextpoint(other) {
|
|
8317
|
+
if (!(other instanceof Point3))
|
|
8318
|
+
throw new Error("ExtendedPoint expected");
|
|
8319
|
+
}
|
|
8320
|
+
const toAffineMemo = memoized$1((p5, iz) => {
|
|
8321
|
+
const { X, Y, Z } = p5;
|
|
8322
|
+
const is0 = p5.is0();
|
|
8323
|
+
if (iz == null)
|
|
8324
|
+
iz = is0 ? _8n$1 : Fp2.inv(Z);
|
|
8325
|
+
const x2 = modP(X * iz);
|
|
8326
|
+
const y3 = modP(Y * iz);
|
|
8327
|
+
const zz = Fp2.mul(Z, iz);
|
|
8328
|
+
if (is0)
|
|
8329
|
+
return { x: _0n$2, y: _1n$3 };
|
|
8330
|
+
if (zz !== _1n$3)
|
|
8331
|
+
throw new Error("invZ was invalid");
|
|
8332
|
+
return { x: x2, y: y3 };
|
|
8333
|
+
});
|
|
8334
|
+
const assertValidMemo = memoized$1((p5) => {
|
|
8335
|
+
const { a: a5, d: d2 } = CURVE2;
|
|
8336
|
+
if (p5.is0())
|
|
8337
|
+
throw new Error("bad point: ZERO");
|
|
8338
|
+
const { X, Y, Z, T: T3 } = p5;
|
|
8339
|
+
const X2 = modP(X * X);
|
|
8340
|
+
const Y2 = modP(Y * Y);
|
|
8341
|
+
const Z2 = modP(Z * Z);
|
|
8342
|
+
const Z4 = modP(Z2 * Z2);
|
|
8343
|
+
const aX2 = modP(X2 * a5);
|
|
8344
|
+
const left = modP(Z2 * modP(aX2 + Y2));
|
|
8345
|
+
const right = modP(Z4 + modP(d2 * modP(X2 * Y2)));
|
|
8346
|
+
if (left !== right)
|
|
8347
|
+
throw new Error("bad point: equation left != right (1)");
|
|
8348
|
+
const XY = modP(X * Y);
|
|
8349
|
+
const ZT = modP(Z * T3);
|
|
8350
|
+
if (XY !== ZT)
|
|
8351
|
+
throw new Error("bad point: equation left != right (2)");
|
|
8352
|
+
return true;
|
|
8353
|
+
});
|
|
8354
|
+
class Point3 {
|
|
8355
|
+
constructor(X, Y, Z, T3) {
|
|
8356
|
+
this.X = acoord("x", X);
|
|
8357
|
+
this.Y = acoord("y", Y);
|
|
8358
|
+
this.Z = acoord("z", Z, true);
|
|
8359
|
+
this.T = acoord("t", T3);
|
|
8360
|
+
Object.freeze(this);
|
|
8361
|
+
}
|
|
8362
|
+
static CURVE() {
|
|
8363
|
+
return CURVE2;
|
|
8364
|
+
}
|
|
8365
|
+
static fromAffine(p5) {
|
|
8366
|
+
if (p5 instanceof Point3)
|
|
8367
|
+
throw new Error("extended point not allowed");
|
|
8368
|
+
const { x: x2, y: y3 } = p5 || {};
|
|
8369
|
+
acoord("x", x2);
|
|
8370
|
+
acoord("y", y3);
|
|
8371
|
+
return new Point3(x2, y3, _1n$3, modP(x2 * y3));
|
|
8372
|
+
}
|
|
8373
|
+
// Uses algo from RFC8032 5.1.3.
|
|
8374
|
+
static fromBytes(bytes, zip215 = false) {
|
|
8375
|
+
const len = Fp2.BYTES;
|
|
8376
|
+
const { a: a5, d: d2 } = CURVE2;
|
|
8377
|
+
bytes = copyBytes(_abytes2(bytes, len, "point"));
|
|
8378
|
+
_abool2(zip215, "zip215");
|
|
8379
|
+
const normed = copyBytes(bytes);
|
|
8380
|
+
const lastByte = bytes[len - 1];
|
|
8381
|
+
normed[len - 1] = lastByte & -129;
|
|
8382
|
+
const y3 = bytesToNumberLE$1(normed);
|
|
8383
|
+
const max = zip215 ? MASK : Fp2.ORDER;
|
|
8384
|
+
aInRange$1("point.y", y3, _0n$2, max);
|
|
8385
|
+
const y22 = modP(y3 * y3);
|
|
8386
|
+
const u4 = modP(y22 - _1n$3);
|
|
8387
|
+
const v2 = modP(d2 * y22 - a5);
|
|
8388
|
+
let { isValid, value: x2 } = uvRatio2(u4, v2);
|
|
8389
|
+
if (!isValid)
|
|
8390
|
+
throw new Error("bad point: invalid y coordinate");
|
|
8391
|
+
const isXOdd = (x2 & _1n$3) === _1n$3;
|
|
8392
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
8393
|
+
if (!zip215 && x2 === _0n$2 && isLastByteOdd)
|
|
8394
|
+
throw new Error("bad point: x=0 and x_0=1");
|
|
8395
|
+
if (isLastByteOdd !== isXOdd)
|
|
8396
|
+
x2 = modP(-x2);
|
|
8397
|
+
return Point3.fromAffine({ x: x2, y: y3 });
|
|
8398
|
+
}
|
|
8399
|
+
static fromHex(bytes, zip215 = false) {
|
|
8400
|
+
return Point3.fromBytes(ensureBytes$1("point", bytes), zip215);
|
|
8401
|
+
}
|
|
8402
|
+
get x() {
|
|
8403
|
+
return this.toAffine().x;
|
|
8404
|
+
}
|
|
8405
|
+
get y() {
|
|
8406
|
+
return this.toAffine().y;
|
|
8407
|
+
}
|
|
8408
|
+
precompute(windowSize = 8, isLazy = true) {
|
|
8409
|
+
wnaf.createCache(this, windowSize);
|
|
8410
|
+
if (!isLazy)
|
|
8411
|
+
this.multiply(_2n$3);
|
|
8412
|
+
return this;
|
|
8413
|
+
}
|
|
8414
|
+
// Useful in fromAffine() - not for fromBytes(), which always created valid points.
|
|
8415
|
+
assertValidity() {
|
|
8416
|
+
assertValidMemo(this);
|
|
8417
|
+
}
|
|
8418
|
+
// Compare one point to another.
|
|
8419
|
+
equals(other) {
|
|
8420
|
+
aextpoint(other);
|
|
8421
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
8422
|
+
const { X: X2, Y: Y2, Z: Z2 } = other;
|
|
8423
|
+
const X1Z2 = modP(X1 * Z2);
|
|
8424
|
+
const X2Z1 = modP(X2 * Z1);
|
|
8425
|
+
const Y1Z2 = modP(Y1 * Z2);
|
|
8426
|
+
const Y2Z1 = modP(Y2 * Z1);
|
|
8427
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
8428
|
+
}
|
|
8429
|
+
is0() {
|
|
8430
|
+
return this.equals(Point3.ZERO);
|
|
8431
|
+
}
|
|
8432
|
+
negate() {
|
|
8433
|
+
return new Point3(modP(-this.X), this.Y, this.Z, modP(-this.T));
|
|
8434
|
+
}
|
|
8435
|
+
// Fast algo for doubling Extended Point.
|
|
8436
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
8437
|
+
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
8438
|
+
double() {
|
|
8439
|
+
const { a: a5 } = CURVE2;
|
|
8440
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
8441
|
+
const A3 = modP(X1 * X1);
|
|
8442
|
+
const B = modP(Y1 * Y1);
|
|
8443
|
+
const C2 = modP(_2n$3 * modP(Z1 * Z1));
|
|
8444
|
+
const D2 = modP(a5 * A3);
|
|
8445
|
+
const x1y1 = X1 + Y1;
|
|
8446
|
+
const E2 = modP(modP(x1y1 * x1y1) - A3 - B);
|
|
8447
|
+
const G2 = D2 + B;
|
|
8448
|
+
const F = G2 - C2;
|
|
8449
|
+
const H = D2 - B;
|
|
8450
|
+
const X3 = modP(E2 * F);
|
|
8451
|
+
const Y3 = modP(G2 * H);
|
|
8452
|
+
const T3 = modP(E2 * H);
|
|
8453
|
+
const Z3 = modP(F * G2);
|
|
8454
|
+
return new Point3(X3, Y3, Z3, T3);
|
|
8455
|
+
}
|
|
8456
|
+
// Fast algo for adding 2 Extended Points.
|
|
8457
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
8458
|
+
// Cost: 9M + 1*a + 1*d + 7add.
|
|
8459
|
+
add(other) {
|
|
8460
|
+
aextpoint(other);
|
|
8461
|
+
const { a: a5, d: d2 } = CURVE2;
|
|
8462
|
+
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
8463
|
+
const { X: X2, Y: Y2, Z: Z2, T: T22 } = other;
|
|
8464
|
+
const A3 = modP(X1 * X2);
|
|
8465
|
+
const B = modP(Y1 * Y2);
|
|
8466
|
+
const C2 = modP(T1 * d2 * T22);
|
|
8467
|
+
const D2 = modP(Z1 * Z2);
|
|
8468
|
+
const E2 = modP((X1 + Y1) * (X2 + Y2) - A3 - B);
|
|
8469
|
+
const F = D2 - C2;
|
|
8470
|
+
const G2 = D2 + C2;
|
|
8471
|
+
const H = modP(B - a5 * A3);
|
|
8472
|
+
const X3 = modP(E2 * F);
|
|
8473
|
+
const Y3 = modP(G2 * H);
|
|
8474
|
+
const T3 = modP(E2 * H);
|
|
8475
|
+
const Z3 = modP(F * G2);
|
|
8476
|
+
return new Point3(X3, Y3, Z3, T3);
|
|
8477
|
+
}
|
|
8478
|
+
subtract(other) {
|
|
8479
|
+
return this.add(other.negate());
|
|
8480
|
+
}
|
|
8481
|
+
// Constant-time multiplication.
|
|
8482
|
+
multiply(scalar) {
|
|
8483
|
+
if (!Fn.isValidNot0(scalar))
|
|
8484
|
+
throw new Error("invalid scalar: expected 1 <= sc < curve.n");
|
|
8485
|
+
const { p: p5, f: f3 } = wnaf.cached(this, scalar, (p6) => normalizeZ(Point3, p6));
|
|
8486
|
+
return normalizeZ(Point3, [p5, f3])[0];
|
|
8487
|
+
}
|
|
8488
|
+
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
8489
|
+
// It's faster, but should only be used when you don't care about
|
|
8490
|
+
// an exposed private key e.g. sig verification.
|
|
8491
|
+
// Does NOT allow scalars higher than CURVE.n.
|
|
8492
|
+
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
8493
|
+
multiplyUnsafe(scalar, acc = Point3.ZERO) {
|
|
8494
|
+
if (!Fn.isValid(scalar))
|
|
8495
|
+
throw new Error("invalid scalar: expected 0 <= sc < curve.n");
|
|
8496
|
+
if (scalar === _0n$2)
|
|
8497
|
+
return Point3.ZERO;
|
|
8498
|
+
if (this.is0() || scalar === _1n$3)
|
|
8499
|
+
return this;
|
|
8500
|
+
return wnaf.unsafe(this, scalar, (p5) => normalizeZ(Point3, p5), acc);
|
|
8501
|
+
}
|
|
8502
|
+
// Checks if point is of small order.
|
|
8503
|
+
// If you add something to small order point, you will have "dirty"
|
|
8504
|
+
// point with torsion component.
|
|
8505
|
+
// Multiplies point by cofactor and checks if the result is 0.
|
|
8506
|
+
isSmallOrder() {
|
|
8507
|
+
return this.multiplyUnsafe(cofactor).is0();
|
|
8508
|
+
}
|
|
8509
|
+
// Multiplies point by curve order and checks if the result is 0.
|
|
8510
|
+
// Returns `false` is the point is dirty.
|
|
8511
|
+
isTorsionFree() {
|
|
8512
|
+
return wnaf.unsafe(this, CURVE2.n).is0();
|
|
8513
|
+
}
|
|
8514
|
+
// Converts Extended point to default (x, y) coordinates.
|
|
8515
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
8516
|
+
toAffine(invertedZ) {
|
|
8517
|
+
return toAffineMemo(this, invertedZ);
|
|
8518
|
+
}
|
|
8519
|
+
clearCofactor() {
|
|
8520
|
+
if (cofactor === _1n$3)
|
|
8521
|
+
return this;
|
|
8522
|
+
return this.multiplyUnsafe(cofactor);
|
|
8523
|
+
}
|
|
8524
|
+
toBytes() {
|
|
8525
|
+
const { x: x2, y: y3 } = this.toAffine();
|
|
8526
|
+
const bytes = Fp2.toBytes(y3);
|
|
8527
|
+
bytes[bytes.length - 1] |= x2 & _1n$3 ? 128 : 0;
|
|
8528
|
+
return bytes;
|
|
8529
|
+
}
|
|
8530
|
+
toHex() {
|
|
8531
|
+
return bytesToHex$2(this.toBytes());
|
|
8532
|
+
}
|
|
8533
|
+
toString() {
|
|
8534
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
8535
|
+
}
|
|
8536
|
+
// TODO: remove
|
|
8537
|
+
get ex() {
|
|
8538
|
+
return this.X;
|
|
8539
|
+
}
|
|
8540
|
+
get ey() {
|
|
8541
|
+
return this.Y;
|
|
8542
|
+
}
|
|
8543
|
+
get ez() {
|
|
8544
|
+
return this.Z;
|
|
8545
|
+
}
|
|
8546
|
+
get et() {
|
|
8547
|
+
return this.T;
|
|
8548
|
+
}
|
|
8549
|
+
static normalizeZ(points) {
|
|
8550
|
+
return normalizeZ(Point3, points);
|
|
8551
|
+
}
|
|
8552
|
+
static msm(points, scalars) {
|
|
8553
|
+
return pippenger$1(Point3, Fn, points, scalars);
|
|
8554
|
+
}
|
|
8555
|
+
_setWindowSize(windowSize) {
|
|
8556
|
+
this.precompute(windowSize);
|
|
8557
|
+
}
|
|
8558
|
+
toRawBytes() {
|
|
8559
|
+
return this.toBytes();
|
|
8560
|
+
}
|
|
8561
|
+
}
|
|
8562
|
+
Point3.BASE = new Point3(CURVE2.Gx, CURVE2.Gy, _1n$3, modP(CURVE2.Gx * CURVE2.Gy));
|
|
8563
|
+
Point3.ZERO = new Point3(_0n$2, _1n$3, _1n$3, _0n$2);
|
|
8564
|
+
Point3.Fp = Fp2;
|
|
8565
|
+
Point3.Fn = Fn;
|
|
8566
|
+
const wnaf = new wNAF$2(Point3, Fn.BITS);
|
|
8567
|
+
Point3.BASE.precompute(8);
|
|
8568
|
+
return Point3;
|
|
8569
|
+
}
|
|
8570
|
+
function eddsa(Point3, cHash, eddsaOpts = {}) {
|
|
8571
|
+
if (typeof cHash !== "function")
|
|
8572
|
+
throw new Error('"hash" function param is required');
|
|
8573
|
+
_validateObject(eddsaOpts, {}, {
|
|
8574
|
+
adjustScalarBytes: "function",
|
|
8575
|
+
randomBytes: "function",
|
|
8576
|
+
domain: "function",
|
|
8577
|
+
prehash: "function",
|
|
8578
|
+
mapToCurve: "function"
|
|
8579
|
+
});
|
|
8580
|
+
const { prehash } = eddsaOpts;
|
|
8581
|
+
const { BASE, Fp: Fp2, Fn } = Point3;
|
|
8582
|
+
const randomBytes2 = eddsaOpts.randomBytes || randomBytes$1;
|
|
8583
|
+
const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
|
|
8584
|
+
const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
|
|
8585
|
+
_abool2(phflag, "phflag");
|
|
8586
|
+
if (ctx.length || phflag)
|
|
8587
|
+
throw new Error("Contexts/pre-hash are not supported");
|
|
8588
|
+
return data;
|
|
8589
|
+
});
|
|
8590
|
+
function modN_LE(hash) {
|
|
8591
|
+
return Fn.create(bytesToNumberLE$1(hash));
|
|
8592
|
+
}
|
|
8593
|
+
function getPrivateScalar(key) {
|
|
8594
|
+
const len = lengths.secretKey;
|
|
8595
|
+
key = ensureBytes$1("private key", key, len);
|
|
8596
|
+
const hashed = ensureBytes$1("hashed private key", cHash(key), 2 * len);
|
|
8597
|
+
const head = adjustScalarBytes2(hashed.slice(0, len));
|
|
8598
|
+
const prefix = hashed.slice(len, 2 * len);
|
|
8599
|
+
const scalar = modN_LE(head);
|
|
8600
|
+
return { head, prefix, scalar };
|
|
8601
|
+
}
|
|
8602
|
+
function getExtendedPublicKey(secretKey) {
|
|
8603
|
+
const { head, prefix, scalar } = getPrivateScalar(secretKey);
|
|
8604
|
+
const point = BASE.multiply(scalar);
|
|
8605
|
+
const pointBytes = point.toBytes();
|
|
8606
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
8607
|
+
}
|
|
8608
|
+
function getPublicKey2(secretKey) {
|
|
8609
|
+
return getExtendedPublicKey(secretKey).pointBytes;
|
|
8610
|
+
}
|
|
8611
|
+
function hashDomainToScalar(context = Uint8Array.of(), ...msgs) {
|
|
8612
|
+
const msg = concatBytes$2(...msgs);
|
|
8613
|
+
return modN_LE(cHash(domain(msg, ensureBytes$1("context", context), !!prehash)));
|
|
8614
|
+
}
|
|
8615
|
+
function sign(msg, secretKey, options = {}) {
|
|
8616
|
+
msg = ensureBytes$1("message", msg);
|
|
8617
|
+
if (prehash)
|
|
8618
|
+
msg = prehash(msg);
|
|
8619
|
+
const { prefix, scalar, pointBytes } = getExtendedPublicKey(secretKey);
|
|
8620
|
+
const r7 = hashDomainToScalar(options.context, prefix, msg);
|
|
8621
|
+
const R2 = BASE.multiply(r7).toBytes();
|
|
8622
|
+
const k2 = hashDomainToScalar(options.context, R2, pointBytes, msg);
|
|
8623
|
+
const s5 = Fn.create(r7 + k2 * scalar);
|
|
8624
|
+
if (!Fn.isValid(s5))
|
|
8625
|
+
throw new Error("sign failed: invalid s");
|
|
8626
|
+
const rs = concatBytes$2(R2, Fn.toBytes(s5));
|
|
8627
|
+
return _abytes2(rs, lengths.signature, "result");
|
|
8628
|
+
}
|
|
8629
|
+
const verifyOpts = { zip215: true };
|
|
8630
|
+
function verify(sig, msg, publicKey, options = verifyOpts) {
|
|
8631
|
+
const { context, zip215 } = options;
|
|
8632
|
+
const len = lengths.signature;
|
|
8633
|
+
sig = ensureBytes$1("signature", sig, len);
|
|
8634
|
+
msg = ensureBytes$1("message", msg);
|
|
8635
|
+
publicKey = ensureBytes$1("publicKey", publicKey, lengths.publicKey);
|
|
8636
|
+
if (zip215 !== void 0)
|
|
8637
|
+
_abool2(zip215, "zip215");
|
|
8638
|
+
if (prehash)
|
|
8639
|
+
msg = prehash(msg);
|
|
8640
|
+
const mid = len / 2;
|
|
8641
|
+
const r7 = sig.subarray(0, mid);
|
|
8642
|
+
const s5 = bytesToNumberLE$1(sig.subarray(mid, len));
|
|
8643
|
+
let A3, R2, SB;
|
|
8644
|
+
try {
|
|
8645
|
+
A3 = Point3.fromBytes(publicKey, zip215);
|
|
8646
|
+
R2 = Point3.fromBytes(r7, zip215);
|
|
8647
|
+
SB = BASE.multiplyUnsafe(s5);
|
|
8648
|
+
} catch (error) {
|
|
8649
|
+
return false;
|
|
8650
|
+
}
|
|
8651
|
+
if (!zip215 && A3.isSmallOrder())
|
|
8652
|
+
return false;
|
|
8653
|
+
const k2 = hashDomainToScalar(context, R2.toBytes(), A3.toBytes(), msg);
|
|
8654
|
+
const RkA = R2.add(A3.multiplyUnsafe(k2));
|
|
8655
|
+
return RkA.subtract(SB).clearCofactor().is0();
|
|
8656
|
+
}
|
|
8657
|
+
const _size = Fp2.BYTES;
|
|
8658
|
+
const lengths = {
|
|
8659
|
+
secretKey: _size,
|
|
8660
|
+
publicKey: _size,
|
|
8661
|
+
signature: 2 * _size,
|
|
8662
|
+
seed: _size
|
|
8663
|
+
};
|
|
8664
|
+
function randomSecretKey(seed = randomBytes2(lengths.seed)) {
|
|
8665
|
+
return _abytes2(seed, lengths.seed, "seed");
|
|
8666
|
+
}
|
|
8667
|
+
function keygen(seed) {
|
|
8668
|
+
const secretKey = utils2.randomSecretKey(seed);
|
|
8669
|
+
return { secretKey, publicKey: getPublicKey2(secretKey) };
|
|
8670
|
+
}
|
|
8671
|
+
function isValidSecretKey(key) {
|
|
8672
|
+
return isBytes$5(key) && key.length === Fn.BYTES;
|
|
8673
|
+
}
|
|
8674
|
+
function isValidPublicKey(key, zip215) {
|
|
8675
|
+
try {
|
|
8676
|
+
return !!Point3.fromBytes(key, zip215);
|
|
8677
|
+
} catch (error) {
|
|
8678
|
+
return false;
|
|
8679
|
+
}
|
|
8680
|
+
}
|
|
8681
|
+
const utils2 = {
|
|
8682
|
+
getExtendedPublicKey,
|
|
8683
|
+
randomSecretKey,
|
|
8684
|
+
isValidSecretKey,
|
|
8685
|
+
isValidPublicKey,
|
|
8686
|
+
/**
|
|
8687
|
+
* Converts ed public key to x public key. Uses formula:
|
|
8688
|
+
* - ed25519:
|
|
8689
|
+
* - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
|
|
8690
|
+
* - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
|
|
8691
|
+
* - ed448:
|
|
8692
|
+
* - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
|
|
8693
|
+
* - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
|
|
8694
|
+
*/
|
|
8695
|
+
toMontgomery(publicKey) {
|
|
8696
|
+
const { y: y3 } = Point3.fromBytes(publicKey);
|
|
8697
|
+
const size = lengths.publicKey;
|
|
8698
|
+
const is25519 = size === 32;
|
|
8699
|
+
if (!is25519 && size !== 57)
|
|
8700
|
+
throw new Error("only defined for 25519 and 448");
|
|
8701
|
+
const u4 = is25519 ? Fp2.div(_1n$3 + y3, _1n$3 - y3) : Fp2.div(y3 - _1n$3, y3 + _1n$3);
|
|
8702
|
+
return Fp2.toBytes(u4);
|
|
8703
|
+
},
|
|
8704
|
+
toMontgomerySecret(secretKey) {
|
|
8705
|
+
const size = lengths.secretKey;
|
|
8706
|
+
_abytes2(secretKey, size);
|
|
8707
|
+
const hashed = cHash(secretKey.subarray(0, size));
|
|
8708
|
+
return adjustScalarBytes2(hashed).subarray(0, size);
|
|
8709
|
+
},
|
|
8710
|
+
/** @deprecated */
|
|
8711
|
+
randomPrivateKey: randomSecretKey,
|
|
8712
|
+
/** @deprecated */
|
|
8713
|
+
precompute(windowSize = 8, point = Point3.BASE) {
|
|
8714
|
+
return point.precompute(windowSize, false);
|
|
8715
|
+
}
|
|
8716
|
+
};
|
|
8717
|
+
return Object.freeze({
|
|
8718
|
+
keygen,
|
|
8719
|
+
getPublicKey: getPublicKey2,
|
|
8720
|
+
sign,
|
|
8721
|
+
verify,
|
|
8722
|
+
utils: utils2,
|
|
8723
|
+
Point: Point3,
|
|
8724
|
+
lengths
|
|
8725
|
+
});
|
|
8726
|
+
}
|
|
8727
|
+
function _eddsa_legacy_opts_to_new(c3) {
|
|
8728
|
+
const CURVE2 = {
|
|
8729
|
+
a: c3.a,
|
|
8730
|
+
d: c3.d,
|
|
8731
|
+
p: c3.Fp.ORDER,
|
|
8732
|
+
n: c3.n,
|
|
8733
|
+
h: c3.h,
|
|
8734
|
+
Gx: c3.Gx,
|
|
8735
|
+
Gy: c3.Gy
|
|
8736
|
+
};
|
|
8737
|
+
const Fp2 = c3.Fp;
|
|
8738
|
+
const Fn = Field$1(CURVE2.n, c3.nBitLength, true);
|
|
8739
|
+
const curveOpts = { Fp: Fp2, Fn, uvRatio: c3.uvRatio };
|
|
8740
|
+
const eddsaOpts = {
|
|
8741
|
+
randomBytes: c3.randomBytes,
|
|
8742
|
+
adjustScalarBytes: c3.adjustScalarBytes,
|
|
8743
|
+
domain: c3.domain,
|
|
8744
|
+
prehash: c3.prehash,
|
|
8745
|
+
mapToCurve: c3.mapToCurve
|
|
8746
|
+
};
|
|
8747
|
+
return { CURVE: CURVE2, curveOpts, hash: c3.hash, eddsaOpts };
|
|
8748
|
+
}
|
|
8749
|
+
function _eddsa_new_output_to_legacy(c3, eddsa2) {
|
|
8750
|
+
const Point3 = eddsa2.Point;
|
|
8751
|
+
const legacy = Object.assign({}, eddsa2, {
|
|
8752
|
+
ExtendedPoint: Point3,
|
|
8753
|
+
CURVE: c3,
|
|
8754
|
+
nBitLength: Point3.Fn.BITS,
|
|
8755
|
+
nByteLength: Point3.Fn.BYTES
|
|
8756
|
+
});
|
|
8757
|
+
return legacy;
|
|
8758
|
+
}
|
|
8759
|
+
function twistedEdwards(c3) {
|
|
8760
|
+
const { CURVE: CURVE2, curveOpts, hash, eddsaOpts } = _eddsa_legacy_opts_to_new(c3);
|
|
8761
|
+
const Point3 = edwards(CURVE2, curveOpts);
|
|
8762
|
+
const EDDSA = eddsa(Point3, hash, eddsaOpts);
|
|
8763
|
+
return _eddsa_new_output_to_legacy(c3, EDDSA);
|
|
8764
|
+
}
|
|
8765
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8766
|
+
const _0n$1 = BigInt(0);
|
|
8767
|
+
const _1n$2 = BigInt(1);
|
|
8768
|
+
const _2n$2 = BigInt(2);
|
|
8769
|
+
function validateOpts(curve2) {
|
|
8770
|
+
_validateObject(curve2, {
|
|
8771
|
+
adjustScalarBytes: "function",
|
|
8772
|
+
powPminus2: "function"
|
|
8773
|
+
});
|
|
8774
|
+
return Object.freeze({ ...curve2 });
|
|
8775
|
+
}
|
|
8776
|
+
function montgomery(curveDef) {
|
|
8777
|
+
const CURVE2 = validateOpts(curveDef);
|
|
8778
|
+
const { P: P2, type: type2, adjustScalarBytes: adjustScalarBytes2, powPminus2, randomBytes: rand } = CURVE2;
|
|
8779
|
+
const is25519 = type2 === "x25519";
|
|
8780
|
+
if (!is25519 && type2 !== "x448")
|
|
8781
|
+
throw new Error("invalid type");
|
|
8782
|
+
const randomBytes_ = rand || randomBytes$1;
|
|
8783
|
+
const montgomeryBits = is25519 ? 255 : 448;
|
|
8784
|
+
const fieldLen = is25519 ? 32 : 56;
|
|
8785
|
+
const Gu = is25519 ? BigInt(9) : BigInt(5);
|
|
8786
|
+
const a24 = is25519 ? BigInt(121665) : BigInt(39081);
|
|
8787
|
+
const minScalar = is25519 ? _2n$2 ** BigInt(254) : _2n$2 ** BigInt(447);
|
|
8788
|
+
const maxAdded = is25519 ? BigInt(8) * _2n$2 ** BigInt(251) - _1n$2 : BigInt(4) * _2n$2 ** BigInt(445) - _1n$2;
|
|
8789
|
+
const maxScalar = minScalar + maxAdded + _1n$2;
|
|
8790
|
+
const modP = (n4) => mod$1(n4, P2);
|
|
8791
|
+
const GuBytes = encodeU(Gu);
|
|
8792
|
+
function encodeU(u4) {
|
|
8793
|
+
return numberToBytesLE$1(modP(u4), fieldLen);
|
|
8794
|
+
}
|
|
8795
|
+
function decodeU(u4) {
|
|
8796
|
+
const _u = ensureBytes$1("u coordinate", u4, fieldLen);
|
|
8797
|
+
if (is25519)
|
|
8798
|
+
_u[31] &= 127;
|
|
8799
|
+
return modP(bytesToNumberLE$1(_u));
|
|
8800
|
+
}
|
|
8801
|
+
function decodeScalar(scalar) {
|
|
8802
|
+
return bytesToNumberLE$1(adjustScalarBytes2(ensureBytes$1("scalar", scalar, fieldLen)));
|
|
8803
|
+
}
|
|
8804
|
+
function scalarMult(scalar, u4) {
|
|
8805
|
+
const pu = montgomeryLadder(decodeU(u4), decodeScalar(scalar));
|
|
8806
|
+
if (pu === _0n$1)
|
|
8807
|
+
throw new Error("invalid private or public key received");
|
|
8808
|
+
return encodeU(pu);
|
|
8809
|
+
}
|
|
8810
|
+
function scalarMultBase(scalar) {
|
|
8811
|
+
return scalarMult(scalar, GuBytes);
|
|
8812
|
+
}
|
|
8813
|
+
function cswap(swap, x_2, x_3) {
|
|
8814
|
+
const dummy = modP(swap * (x_2 - x_3));
|
|
8815
|
+
x_2 = modP(x_2 - dummy);
|
|
8816
|
+
x_3 = modP(x_3 + dummy);
|
|
8817
|
+
return { x_2, x_3 };
|
|
8818
|
+
}
|
|
8819
|
+
function montgomeryLadder(u4, scalar) {
|
|
8820
|
+
aInRange$1("u", u4, _0n$1, P2);
|
|
8821
|
+
aInRange$1("scalar", scalar, minScalar, maxScalar);
|
|
8822
|
+
const k2 = scalar;
|
|
8823
|
+
const x_1 = u4;
|
|
8824
|
+
let x_2 = _1n$2;
|
|
8825
|
+
let z_2 = _0n$1;
|
|
8826
|
+
let x_3 = u4;
|
|
8827
|
+
let z_3 = _1n$2;
|
|
8828
|
+
let swap = _0n$1;
|
|
8829
|
+
for (let t6 = BigInt(montgomeryBits - 1); t6 >= _0n$1; t6--) {
|
|
8830
|
+
const k_t = k2 >> t6 & _1n$2;
|
|
8831
|
+
swap ^= k_t;
|
|
8832
|
+
({ x_2, x_3 } = cswap(swap, x_2, x_3));
|
|
8833
|
+
({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
|
|
8834
|
+
swap = k_t;
|
|
8835
|
+
const A3 = x_2 + z_2;
|
|
8836
|
+
const AA = modP(A3 * A3);
|
|
8837
|
+
const B = x_2 - z_2;
|
|
8838
|
+
const BB = modP(B * B);
|
|
8839
|
+
const E2 = AA - BB;
|
|
8840
|
+
const C2 = x_3 + z_3;
|
|
8841
|
+
const D2 = x_3 - z_3;
|
|
8842
|
+
const DA = modP(D2 * A3);
|
|
8843
|
+
const CB = modP(C2 * B);
|
|
8844
|
+
const dacb = DA + CB;
|
|
8845
|
+
const da_cb = DA - CB;
|
|
8846
|
+
x_3 = modP(dacb * dacb);
|
|
8847
|
+
z_3 = modP(x_1 * modP(da_cb * da_cb));
|
|
8848
|
+
x_2 = modP(AA * BB);
|
|
8849
|
+
z_2 = modP(E2 * (AA + modP(a24 * E2)));
|
|
8850
|
+
}
|
|
8851
|
+
({ x_2, x_3 } = cswap(swap, x_2, x_3));
|
|
8852
|
+
({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
|
|
8853
|
+
const z2 = powPminus2(z_2);
|
|
8854
|
+
return modP(x_2 * z2);
|
|
8855
|
+
}
|
|
8856
|
+
const lengths = {
|
|
8857
|
+
secretKey: fieldLen,
|
|
8858
|
+
publicKey: fieldLen,
|
|
8859
|
+
seed: fieldLen
|
|
8860
|
+
};
|
|
8861
|
+
const randomSecretKey = (seed = randomBytes_(fieldLen)) => {
|
|
8862
|
+
abytes$2(seed, lengths.seed);
|
|
8863
|
+
return seed;
|
|
8864
|
+
};
|
|
8865
|
+
function keygen(seed) {
|
|
8866
|
+
const secretKey = randomSecretKey(seed);
|
|
8867
|
+
return { secretKey, publicKey: scalarMultBase(secretKey) };
|
|
8868
|
+
}
|
|
8869
|
+
const utils2 = {
|
|
8870
|
+
randomSecretKey,
|
|
8871
|
+
randomPrivateKey: randomSecretKey
|
|
8872
|
+
};
|
|
8873
|
+
return {
|
|
8874
|
+
keygen,
|
|
8875
|
+
getSharedSecret: (secretKey, publicKey) => scalarMult(secretKey, publicKey),
|
|
8876
|
+
getPublicKey: (secretKey) => scalarMultBase(secretKey),
|
|
8877
|
+
scalarMult,
|
|
8878
|
+
scalarMultBase,
|
|
8879
|
+
utils: utils2,
|
|
8880
|
+
GuBytes: GuBytes.slice(),
|
|
8881
|
+
lengths
|
|
8882
|
+
};
|
|
8883
|
+
}
|
|
8884
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8885
|
+
const _1n$1 = BigInt(1), _2n$1 = BigInt(2), _3n = BigInt(3);
|
|
8886
|
+
const _5n = BigInt(5), _8n = BigInt(8);
|
|
8887
|
+
const ed25519_CURVE_p = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
|
|
8888
|
+
const ed25519_CURVE = /* @__PURE__ */ (() => ({
|
|
8889
|
+
p: ed25519_CURVE_p,
|
|
8890
|
+
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
8891
|
+
h: _8n,
|
|
8892
|
+
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
8893
|
+
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
8894
|
+
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
8895
|
+
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
8896
|
+
}))();
|
|
8897
|
+
function ed25519_pow_2_252_3(x2) {
|
|
8898
|
+
const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
|
|
8899
|
+
const P2 = ed25519_CURVE_p;
|
|
8900
|
+
const x22 = x2 * x2 % P2;
|
|
8901
|
+
const b2 = x22 * x2 % P2;
|
|
8902
|
+
const b4 = pow2$1(b2, _2n$1, P2) * b2 % P2;
|
|
8903
|
+
const b5 = pow2$1(b4, _1n$1, P2) * x2 % P2;
|
|
8904
|
+
const b10 = pow2$1(b5, _5n, P2) * b5 % P2;
|
|
8905
|
+
const b20 = pow2$1(b10, _10n, P2) * b10 % P2;
|
|
8906
|
+
const b40 = pow2$1(b20, _20n, P2) * b20 % P2;
|
|
8907
|
+
const b80 = pow2$1(b40, _40n, P2) * b40 % P2;
|
|
8908
|
+
const b160 = pow2$1(b80, _80n, P2) * b80 % P2;
|
|
8909
|
+
const b240 = pow2$1(b160, _80n, P2) * b80 % P2;
|
|
8910
|
+
const b250 = pow2$1(b240, _10n, P2) * b10 % P2;
|
|
8911
|
+
const pow_p_5_8 = pow2$1(b250, _2n$1, P2) * x2 % P2;
|
|
8912
|
+
return { pow_p_5_8, b2 };
|
|
8913
|
+
}
|
|
8914
|
+
function adjustScalarBytes(bytes) {
|
|
8915
|
+
bytes[0] &= 248;
|
|
8916
|
+
bytes[31] &= 127;
|
|
8917
|
+
bytes[31] |= 64;
|
|
8918
|
+
return bytes;
|
|
8919
|
+
}
|
|
8920
|
+
const ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
8921
|
+
function uvRatio(u4, v2) {
|
|
8922
|
+
const P2 = ed25519_CURVE_p;
|
|
8923
|
+
const v3 = mod$1(v2 * v2 * v2, P2);
|
|
8924
|
+
const v7 = mod$1(v3 * v3 * v2, P2);
|
|
8925
|
+
const pow3 = ed25519_pow_2_252_3(u4 * v7).pow_p_5_8;
|
|
8926
|
+
let x2 = mod$1(u4 * v3 * pow3, P2);
|
|
8927
|
+
const vx2 = mod$1(v2 * x2 * x2, P2);
|
|
8928
|
+
const root1 = x2;
|
|
8929
|
+
const root2 = mod$1(x2 * ED25519_SQRT_M1, P2);
|
|
8930
|
+
const useRoot1 = vx2 === u4;
|
|
8931
|
+
const useRoot2 = vx2 === mod$1(-u4, P2);
|
|
8932
|
+
const noRoot = vx2 === mod$1(-u4 * ED25519_SQRT_M1, P2);
|
|
8933
|
+
if (useRoot1)
|
|
8934
|
+
x2 = root1;
|
|
8935
|
+
if (useRoot2 || noRoot)
|
|
8936
|
+
x2 = root2;
|
|
8937
|
+
if (isNegativeLE(x2, P2))
|
|
8938
|
+
x2 = mod$1(-x2, P2);
|
|
8939
|
+
return { isValid: useRoot1 || useRoot2, value: x2 };
|
|
8940
|
+
}
|
|
8941
|
+
const Fp = /* @__PURE__ */ (() => Field$1(ed25519_CURVE.p, { isLE: true }))();
|
|
8942
|
+
const ed25519Defaults = /* @__PURE__ */ (() => ({
|
|
8943
|
+
...ed25519_CURVE,
|
|
8944
|
+
Fp,
|
|
8945
|
+
hash: sha512$1,
|
|
8946
|
+
adjustScalarBytes,
|
|
8947
|
+
// dom2
|
|
8948
|
+
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
8949
|
+
// Constant-time, u/√v
|
|
8950
|
+
uvRatio
|
|
8951
|
+
}))();
|
|
8952
|
+
const ed25519 = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
|
|
8953
|
+
const x25519 = /* @__PURE__ */ (() => {
|
|
8954
|
+
const P2 = Fp.ORDER;
|
|
8955
|
+
return montgomery({
|
|
8956
|
+
P: P2,
|
|
8957
|
+
type: "x25519",
|
|
8958
|
+
powPminus2: (x2) => {
|
|
8959
|
+
const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x2);
|
|
8960
|
+
return mod$1(pow2$1(pow_p_5_8, _3n, P2) * b2, P2);
|
|
8961
|
+
},
|
|
8962
|
+
adjustScalarBytes
|
|
8963
|
+
});
|
|
8964
|
+
})();
|
|
8965
|
+
function extract(hash, ikm, salt) {
|
|
8966
|
+
ahash$1(hash);
|
|
8967
|
+
if (salt === void 0)
|
|
8968
|
+
salt = new Uint8Array(hash.outputLen);
|
|
8969
|
+
return hmac$1(hash, toBytes$1(salt), toBytes$1(ikm));
|
|
8970
|
+
}
|
|
8971
|
+
const HKDF_COUNTER = /* @__PURE__ */ Uint8Array.from([0]);
|
|
8972
|
+
const EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
8973
|
+
function expand(hash, prk, info, length = 32) {
|
|
8974
|
+
ahash$1(hash);
|
|
8975
|
+
anumber$3(length);
|
|
8976
|
+
const olen = hash.outputLen;
|
|
8977
|
+
if (length > 255 * olen)
|
|
8978
|
+
throw new Error("Length should be <= 255*HashLen");
|
|
8979
|
+
const blocks = Math.ceil(length / olen);
|
|
8980
|
+
if (info === void 0)
|
|
8981
|
+
info = EMPTY_BUFFER;
|
|
8982
|
+
const okm = new Uint8Array(blocks * olen);
|
|
8983
|
+
const HMAC3 = hmac$1.create(hash, prk);
|
|
8984
|
+
const HMACTmp = HMAC3._cloneInto();
|
|
8985
|
+
const T3 = new Uint8Array(HMAC3.outputLen);
|
|
8986
|
+
for (let counter = 0; counter < blocks; counter++) {
|
|
8987
|
+
HKDF_COUNTER[0] = counter + 1;
|
|
8988
|
+
HMACTmp.update(counter === 0 ? EMPTY_BUFFER : T3).update(info).update(HKDF_COUNTER).digestInto(T3);
|
|
8989
|
+
okm.set(T3, olen * counter);
|
|
8990
|
+
HMAC3._cloneInto(HMACTmp);
|
|
8991
|
+
}
|
|
8992
|
+
HMAC3.destroy();
|
|
8993
|
+
HMACTmp.destroy();
|
|
8994
|
+
clean(T3, HKDF_COUNTER);
|
|
8995
|
+
return okm.slice(0, length);
|
|
8996
|
+
}
|
|
8997
|
+
const hkdf = (hash, ikm, salt, info, length) => expand(hash, extract(hash, ikm, salt), info, length);
|
|
8998
|
+
function hkdfSha256(ikm, info, length) {
|
|
8999
|
+
return hkdf(sha256$1, ikm, new Uint8Array(0), info, length);
|
|
9000
|
+
}
|
|
9001
|
+
function ed25519PublicKey(seed) {
|
|
9002
|
+
return ed25519.getPublicKey(seed);
|
|
9003
|
+
}
|
|
9004
|
+
function x25519PublicKey(privateKey) {
|
|
9005
|
+
return x25519.getPublicKey(privateKey);
|
|
9006
|
+
}
|
|
9007
|
+
hexToBytes$2("302e020100300506032b657004220420");
|
|
9008
|
+
const P$1 = 2n ** 255n - 19n;
|
|
9009
|
+
function littleEndian(bytes) {
|
|
9010
|
+
let n4 = 0n;
|
|
9011
|
+
for (let i3 = bytes.length - 1; i3 >= 0; i3--) {
|
|
9012
|
+
n4 = n4 << 8n | BigInt(bytes[i3]);
|
|
9013
|
+
}
|
|
9014
|
+
return n4;
|
|
9015
|
+
}
|
|
9016
|
+
/* @__PURE__ */ new Set([
|
|
9017
|
+
0n,
|
|
9018
|
+
1n,
|
|
9019
|
+
P$1 - 1n,
|
|
9020
|
+
littleEndian(hexToBytes$2("26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05")),
|
|
9021
|
+
littleEndian(hexToBytes$2("c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a"))
|
|
9022
|
+
]);
|
|
9023
|
+
const SIGNING_KEY_LABEL = "delegated-identity ed25519 signing key";
|
|
9024
|
+
const ENCRYPTION_KEY_LABEL = "delegated-identity x25519 encryption key";
|
|
9025
|
+
function toHex$1(bytes) {
|
|
9026
|
+
return `0x${bytesToHex$2(bytes)}`;
|
|
9027
|
+
}
|
|
9028
|
+
function deriveKeySet(originPrivateKey) {
|
|
9029
|
+
const ikm = toPrivateKeyBytes(originPrivateKey);
|
|
9030
|
+
if (ikm.length !== 32) {
|
|
9031
|
+
throw new Error(`an origin private key is 32 bytes, got ${ikm.length}`);
|
|
9032
|
+
}
|
|
9033
|
+
const signing = hkdfSha256(ikm, SIGNING_KEY_LABEL, 32);
|
|
9034
|
+
const encryption = hkdfSha256(ikm, ENCRYPTION_KEY_LABEL, 32);
|
|
9035
|
+
return {
|
|
9036
|
+
signing: { publicKey: toHex$1(ed25519PublicKey(signing)), privateKey: toHex$1(signing) },
|
|
9037
|
+
encryption: { publicKey: toHex$1(x25519PublicKey(encryption)), privateKey: toHex$1(encryption) }
|
|
9038
|
+
};
|
|
9039
|
+
}
|
|
9040
|
+
const KEY_PATTERN = /^0x[0-9a-fA-F]{64}$/;
|
|
9041
|
+
function taggedKeys(keySet) {
|
|
9042
|
+
var _a4, _b2;
|
|
9043
|
+
const signing = (_a4 = keySet == null ? void 0 : keySet.signing) == null ? void 0 : _a4.publicKey;
|
|
9044
|
+
const encryption = (_b2 = keySet == null ? void 0 : keySet.encryption) == null ? void 0 : _b2.publicKey;
|
|
9045
|
+
if (typeof signing !== "string" || !KEY_PATTERN.test(signing)) {
|
|
9046
|
+
throw new Error("the signing key is not 32 bytes of 0x-prefixed hex");
|
|
9047
|
+
}
|
|
9048
|
+
if (typeof encryption !== "string" || !KEY_PATTERN.test(encryption)) {
|
|
9049
|
+
throw new Error("the encryption key is not 32 bytes of 0x-prefixed hex");
|
|
9050
|
+
}
|
|
9051
|
+
return { signing: `ed25519:${signing.toLowerCase()}`, encryption: `x25519:${encryption.toLowerCase()}` };
|
|
9052
|
+
}
|
|
9053
|
+
function originPublicKeyPublicationMessage(orig, keySet) {
|
|
9054
|
+
const keys = taggedKeys(keySet);
|
|
9055
|
+
return [
|
|
9056
|
+
`Origin: ${orig}`,
|
|
9057
|
+
"",
|
|
9058
|
+
"IMPORTANT: Only sign on trusted websites.",
|
|
9059
|
+
"",
|
|
9060
|
+
"This authorizes the following keys for your account:",
|
|
9061
|
+
"",
|
|
9062
|
+
"Signing key, to act for your account in this app:",
|
|
9063
|
+
keys.signing,
|
|
9064
|
+
"",
|
|
9065
|
+
"Encryption key, for others to send you encrypted messages:",
|
|
9066
|
+
keys.encryption
|
|
9067
|
+
].join("\n");
|
|
9068
|
+
}
|
|
9069
|
+
new TextEncoder();
|
|
9070
|
+
function toPrivateKeyBytes(privateKey) {
|
|
9071
|
+
return typeof privateKey === "string" ? hexToBytes$2(privateKey.slice(2)) : privateKey;
|
|
9072
|
+
}
|
|
6967
9073
|
const bufToB64 = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf)));
|
|
6968
9074
|
async function generateEcdhKeyPair() {
|
|
6969
9075
|
return window.crypto.subtle.generateKey(
|
|
@@ -7320,17 +9426,6 @@ Verify before proceeding.`;
|
|
|
7320
9426
|
function localKeyMessage() {
|
|
7321
9427
|
return "DO NOT ACCEPT THIS SIGNATURE REQUEST! This used by Etherplay Wallet to generate your seed phrase.";
|
|
7322
9428
|
}
|
|
7323
|
-
function originPublicKeyPublicationMessage(orig, publicKey) {
|
|
7324
|
-
return `Origin: ${orig}
|
|
7325
|
-
|
|
7326
|
-
IMPORTANT: Only sign on trusted websites.
|
|
7327
|
-
|
|
7328
|
-
This authorizes the following Public Key to represent your account:
|
|
7329
|
-
|
|
7330
|
-
${publicKey}
|
|
7331
|
-
|
|
7332
|
-
Others can use this key to write encrypted messages to you securely.`;
|
|
7333
|
-
}
|
|
7334
9429
|
function fromEntropyKeyToMnemonic(entropyKey) {
|
|
7335
9430
|
return entropyToMnemonic(hexToBytes$2(entropyKey.slice(2)), wordlist);
|
|
7336
9431
|
}
|
|
@@ -7338,6 +9433,12 @@ function fromSignatureToKey(signature) {
|
|
|
7338
9433
|
const hash = keccak_256$1(hexToBytes$2(signature.slice(2)));
|
|
7339
9434
|
return `0x${bytesToHex$2(hash)}`;
|
|
7340
9435
|
}
|
|
9436
|
+
function deriveOriginKeys(originKeySignature, accountGenerator2) {
|
|
9437
|
+
const originKey = fromSignatureToKey(originKeySignature);
|
|
9438
|
+
const originAccount = accountGenerator2.fromMnemonicToAccount(fromEntropyKeyToMnemonic(originKey), 0);
|
|
9439
|
+
const keySet = deriveKeySet(originKey);
|
|
9440
|
+
return { originAccount, keySet };
|
|
9441
|
+
}
|
|
7341
9442
|
function deriveEtherplayAccount(key, mechanism2, accountGenerator2) {
|
|
7342
9443
|
const mnemonic = fromEntropyKeyToMnemonic(key);
|
|
7343
9444
|
return {
|
|
@@ -7356,10 +9457,8 @@ async function deriveOriginAccount(origin2, account, accountGenerator2, granted)
|
|
|
7356
9457
|
const accountMnemonic = fromEntropyKeyToMnemonic(account.localAccount.key);
|
|
7357
9458
|
const accountObject = accountGenerator2.fromMnemonicToAccount(accountMnemonic, account.localAccount.index);
|
|
7358
9459
|
const originKeySignature = await accountGenerator2.signTextMessage(originKeyMessage(origin2), accountObject.privateKey);
|
|
7359
|
-
const
|
|
7360
|
-
const
|
|
7361
|
-
const originAccount = accountGenerator2.fromMnemonicToAccount(originMnemonic, 0);
|
|
7362
|
-
const savedPublicKeyPublicationSignature = await accountGenerator2.signTextMessage(originPublicKeyPublicationMessage(origin2, originAccount.publicKey), accountObject.privateKey);
|
|
9460
|
+
const { originAccount, keySet } = deriveOriginKeys(originKeySignature, accountGenerator2);
|
|
9461
|
+
const savedPublicKeyPublicationSignature = await accountGenerator2.signTextMessage(originPublicKeyPublicationMessage(origin2, keySet), accountObject.privateKey);
|
|
7363
9462
|
const savedDelegations = [];
|
|
7364
9463
|
for (const delegation of (granted == null ? void 0 : granted.delegations) || []) {
|
|
7365
9464
|
const signature = await accountGenerator2.signTextMessage(delegationMessage({
|
|
@@ -7384,6 +9483,7 @@ async function deriveOriginAccount(origin2, account, accountGenerator2, granted)
|
|
|
7384
9483
|
address: originAccount.address,
|
|
7385
9484
|
privateKey: originAccount.privateKey
|
|
7386
9485
|
},
|
|
9486
|
+
keySet,
|
|
7387
9487
|
metadata: {},
|
|
7388
9488
|
mechanismUsed: account.signer.mechanismUsed,
|
|
7389
9489
|
savedPublicKeyPublicationSignature,
|
|
@@ -7690,8 +9790,8 @@ function getGlobal() {
|
|
|
7690
9790
|
if (typeof global$1 !== "undefined") return global$1;
|
|
7691
9791
|
return {};
|
|
7692
9792
|
}
|
|
7693
|
-
const G
|
|
7694
|
-
const FormDataCtor = typeof G
|
|
9793
|
+
const G = getGlobal();
|
|
9794
|
+
const FormDataCtor = typeof G.FormData !== "undefined" ? G.FormData : void 0;
|
|
7695
9795
|
const isFormData = (thing) => {
|
|
7696
9796
|
if (!thing) return false;
|
|
7697
9797
|
if (FormDataCtor && thing instanceof FormDataCtor) return true;
|
|
@@ -9474,13 +11574,13 @@ ieee754.write = function(buffer2, value, offset, isLE2, mLen, nBytes) {
|
|
|
9474
11574
|
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
|
9475
11575
|
if (offset < 0) throw new RangeError("Index out of range");
|
|
9476
11576
|
}
|
|
9477
|
-
function writeFloat(buf, value, offset,
|
|
11577
|
+
function writeFloat(buf, value, offset, littleEndian2, noAssert) {
|
|
9478
11578
|
value = +value;
|
|
9479
11579
|
offset = offset >>> 0;
|
|
9480
11580
|
if (!noAssert) {
|
|
9481
11581
|
checkIEEE754(buf, value, offset, 4);
|
|
9482
11582
|
}
|
|
9483
|
-
ieee754$1.write(buf, value, offset,
|
|
11583
|
+
ieee754$1.write(buf, value, offset, littleEndian2, 23, 4);
|
|
9484
11584
|
return offset + 4;
|
|
9485
11585
|
}
|
|
9486
11586
|
Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
@@ -9489,13 +11589,13 @@ ieee754.write = function(buffer2, value, offset, isLE2, mLen, nBytes) {
|
|
|
9489
11589
|
Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
9490
11590
|
return writeFloat(this, value, offset, false, noAssert);
|
|
9491
11591
|
};
|
|
9492
|
-
function writeDouble(buf, value, offset,
|
|
11592
|
+
function writeDouble(buf, value, offset, littleEndian2, noAssert) {
|
|
9493
11593
|
value = +value;
|
|
9494
11594
|
offset = offset >>> 0;
|
|
9495
11595
|
if (!noAssert) {
|
|
9496
11596
|
checkIEEE754(buf, value, offset, 8);
|
|
9497
11597
|
}
|
|
9498
|
-
ieee754$1.write(buf, value, offset,
|
|
11598
|
+
ieee754$1.write(buf, value, offset, littleEndian2, 52, 8);
|
|
9499
11599
|
return offset + 8;
|
|
9500
11600
|
}
|
|
9501
11601
|
Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
@@ -12630,17 +14730,17 @@ const c$8 = function(e4, ...t6) {
|
|
|
12630
14730
|
const a5 = "/v1/accounts/{id}".replace("{id}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
12631
14731
|
let u4;
|
|
12632
14732
|
e4 && (u4 = e4.baseOptions);
|
|
12633
|
-
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {},
|
|
12634
|
-
await r$h(p5, e4), await r$h(p5, e4), s5 && (
|
|
14733
|
+
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {}, P2 = {};
|
|
14734
|
+
await r$h(p5, e4), await r$h(p5, e4), s5 && (P2.expand = s5), c$8(h2, P2);
|
|
12635
14735
|
let w2 = u4 && u4.headers ? u4.headers : {};
|
|
12636
14736
|
return l3.headers = { ...p5, ...w2, ...n5.headers }, { url: d$6(h2), options: l3 };
|
|
12637
14737
|
}, getAccounts: async (t7, s5, n5, a5, o5, h2, u4, l3 = {}) => {
|
|
12638
14738
|
const p5 = new URL("/v1/accounts", i$9);
|
|
12639
|
-
let
|
|
12640
|
-
e4 && (
|
|
12641
|
-
const w2 = { method: "GET", ...
|
|
14739
|
+
let P2;
|
|
14740
|
+
e4 && (P2 = e4.baseOptions);
|
|
14741
|
+
const w2 = { method: "GET", ...P2, ...l3 }, g2 = {}, m2 = {};
|
|
12642
14742
|
await r$h(g2, e4), await r$h(g2, e4), await r$h(g2, e4), await r$h(g2, e4), await r$h(g2, e4), void 0 !== t7 && (m2.limit = t7), void 0 !== s5 && (m2.skip = s5), void 0 !== n5 && (m2.order = n5), void 0 !== a5 && (m2.chainId = a5), void 0 !== o5 && (m2.player = o5), void 0 !== h2 && (m2.address = h2), u4 && (m2.expand = u4), c$8(p5, m2);
|
|
12643
|
-
let y3 =
|
|
14743
|
+
let y3 = P2 && P2.headers ? P2.headers : {};
|
|
12644
14744
|
return w2.headers = { ...g2, ...y3, ...l3.headers }, { url: d$6(p5), options: w2 };
|
|
12645
14745
|
} };
|
|
12646
14746
|
}(t6);
|
|
@@ -12658,7 +14758,7 @@ const c$8 = function(e4, ...t6) {
|
|
|
12658
14758
|
return l$4(p5, axios, s$c, t6);
|
|
12659
14759
|
} };
|
|
12660
14760
|
};
|
|
12661
|
-
|
|
14761
|
+
class P extends n$d {
|
|
12662
14762
|
createAccount(e4, t6) {
|
|
12663
14763
|
return p$6(this.configuration).createAccount(e4.createAccountRequest, t6).then((e5) => e5(this.axios, this.basePath));
|
|
12664
14764
|
}
|
|
@@ -12671,7 +14771,7 @@ let P$1 = class P extends n$d {
|
|
|
12671
14771
|
getAccounts(e4 = {}, t6) {
|
|
12672
14772
|
return p$6(this.configuration).getAccounts(e4.limit, e4.skip, e4.order, e4.chainId, e4.player, e4.address, e4.expand, t6).then((e5) => e5(this.axios, this.basePath));
|
|
12673
14773
|
}
|
|
12674
|
-
}
|
|
14774
|
+
}
|
|
12675
14775
|
const w = function(t6) {
|
|
12676
14776
|
const n4 = /* @__PURE__ */ function(e4) {
|
|
12677
14777
|
return { createAccountV2: async (t7, s5 = {}) => {
|
|
@@ -12701,14 +14801,14 @@ const w = function(t6) {
|
|
|
12701
14801
|
await r$h(l3, e4), await r$h(l3, e4), await r$h(l3, e4), await r$h(l3, e4), await r$h(l3, e4), c$8(a5, {});
|
|
12702
14802
|
let p5 = h2 && h2.headers ? h2.headers : {};
|
|
12703
14803
|
return u4.headers = { ...l3, ...p5, ...s5.headers }, { url: d$6(a5), options: u4 };
|
|
12704
|
-
}, getAccountsV2: async (t7, s5, n5, a5, o5, h2, u4, l3, p5,
|
|
14804
|
+
}, getAccountsV2: async (t7, s5, n5, a5, o5, h2, u4, l3, p5, P2 = {}) => {
|
|
12705
14805
|
const w2 = new URL("/v2/accounts", i$9);
|
|
12706
14806
|
let g2;
|
|
12707
14807
|
e4 && (g2 = e4.baseOptions);
|
|
12708
|
-
const m2 = { method: "GET", ...g2, ...
|
|
14808
|
+
const m2 = { method: "GET", ...g2, ...P2 }, y3 = {}, R2 = {};
|
|
12709
14809
|
await r$h(y3, e4), await r$h(y3, e4), await r$h(y3, e4), await r$h(y3, e4), await r$h(y3, e4), void 0 !== t7 && (R2.limit = t7), void 0 !== s5 && (R2.skip = s5), void 0 !== n5 && (R2.order = n5), void 0 !== a5 && (R2.chainId = a5), void 0 !== o5 && (R2.user = o5), void 0 !== h2 && (R2.chainType = h2), void 0 !== u4 && (R2.accountType = u4), void 0 !== l3 && (R2.custody = l3), void 0 !== p5 && (R2.address = p5), c$8(w2, R2);
|
|
12710
14810
|
let f3 = g2 && g2.headers ? g2.headers : {};
|
|
12711
|
-
return m2.headers = { ...y3, ...f3, ...
|
|
14811
|
+
return m2.headers = { ...y3, ...f3, ...P2.headers }, { url: d$6(w2), options: m2 };
|
|
12712
14812
|
}, getSignerIdByAddress: async (t7, s5 = {}) => {
|
|
12713
14813
|
o$f("getSignerIdByAddress", "address", t7);
|
|
12714
14814
|
const n5 = new URL("/v2/accounts/signer", i$9);
|
|
@@ -12747,8 +14847,8 @@ const w = function(t6) {
|
|
|
12747
14847
|
}, async getAccountV2(a5, i3) {
|
|
12748
14848
|
const o5 = await n4.getAccountV2(a5, i3);
|
|
12749
14849
|
return l$4(o5, axios, s$c, t6);
|
|
12750
|
-
}, async getAccountsV2(a5, i3, o5, r7, h2, c3, u4, d2, p5,
|
|
12751
|
-
const w2 = await n4.getAccountsV2(a5, i3, o5, r7, h2, c3, u4, d2, p5,
|
|
14850
|
+
}, async getAccountsV2(a5, i3, o5, r7, h2, c3, u4, d2, p5, P2) {
|
|
14851
|
+
const w2 = await n4.getAccountsV2(a5, i3, o5, r7, h2, c3, u4, d2, p5, P2);
|
|
12752
14852
|
return l$4(w2, axios, s$c, t6);
|
|
12753
14853
|
}, async getSignerIdByAddress(a5, i3) {
|
|
12754
14854
|
const o5 = await n4.getSignerIdByAddress(a5, i3);
|
|
@@ -12811,8 +14911,8 @@ const m$3 = function(t6) {
|
|
|
12811
14911
|
e4 && (h2 = e4.baseOptions);
|
|
12812
14912
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12813
14913
|
await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12814
|
-
let
|
|
12815
|
-
return l3.headers = { ...p5, ...
|
|
14914
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
14915
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12816
14916
|
}, initSIWE: async (t7, s5, n5 = {}) => {
|
|
12817
14917
|
o$f("initSIWE", "sIWERequest", t7);
|
|
12818
14918
|
const a5 = new URL("/iam/v1/siwe/init", i$9);
|
|
@@ -12820,8 +14920,8 @@ const m$3 = function(t6) {
|
|
|
12820
14920
|
e4 && (h2 = e4.baseOptions);
|
|
12821
14921
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12822
14922
|
await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12823
|
-
let
|
|
12824
|
-
return l3.headers = { ...p5, ...
|
|
14923
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
14924
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12825
14925
|
}, linkEmail: async (t7, s5, n5 = {}) => {
|
|
12826
14926
|
o$f("linkEmail", "loginRequest", t7);
|
|
12827
14927
|
const a5 = new URL("/iam/v1/password/link", i$9);
|
|
@@ -12829,8 +14929,8 @@ const m$3 = function(t6) {
|
|
|
12829
14929
|
e4 && (h2 = e4.baseOptions);
|
|
12830
14930
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12831
14931
|
await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12832
|
-
let
|
|
12833
|
-
return l3.headers = { ...p5, ...
|
|
14932
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
14933
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12834
14934
|
}, linkOAuth: async (t7, s5, n5 = {}) => {
|
|
12835
14935
|
o$f("linkOAuth", "oAuthInitRequest", t7);
|
|
12836
14936
|
const a5 = new URL("/iam/v1/oauth/init_link", i$9);
|
|
@@ -12838,8 +14938,8 @@ const m$3 = function(t6) {
|
|
|
12838
14938
|
e4 && (h2 = e4.baseOptions);
|
|
12839
14939
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12840
14940
|
await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12841
|
-
let
|
|
12842
|
-
return l3.headers = { ...p5, ...
|
|
14941
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
14942
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12843
14943
|
}, linkSIWE: async (t7, s5 = {}) => {
|
|
12844
14944
|
o$f("linkSIWE", "sIWEAuthenticateRequest", t7);
|
|
12845
14945
|
const n5 = new URL("/iam/v1/siwe/link", i$9);
|
|
@@ -12856,8 +14956,8 @@ const m$3 = function(t6) {
|
|
|
12856
14956
|
e4 && (h2 = e4.baseOptions);
|
|
12857
14957
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12858
14958
|
await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12859
|
-
let
|
|
12860
|
-
return l3.headers = { ...p5, ...
|
|
14959
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
14960
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12861
14961
|
}, loginEmailPassword: async (t7, s5, n5 = {}) => {
|
|
12862
14962
|
o$f("loginEmailPassword", "loginRequest", t7);
|
|
12863
14963
|
const a5 = new URL("/iam/v1/password/login", i$9);
|
|
@@ -12865,8 +14965,8 @@ const m$3 = function(t6) {
|
|
|
12865
14965
|
e4 && (h2 = e4.baseOptions);
|
|
12866
14966
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12867
14967
|
await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12868
|
-
let
|
|
12869
|
-
return l3.headers = { ...p5, ...
|
|
14968
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
14969
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12870
14970
|
}, loginWithIdToken: async (t7, s5 = {}) => {
|
|
12871
14971
|
o$f("loginWithIdToken", "loginWithIdTokenRequest", t7);
|
|
12872
14972
|
const n5 = new URL("/iam/v1/oauth/login_id_token", i$9);
|
|
@@ -12953,8 +15053,8 @@ const m$3 = function(t6) {
|
|
|
12953
15053
|
e4 && (h2 = e4.baseOptions);
|
|
12954
15054
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12955
15055
|
await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12956
|
-
let
|
|
12957
|
-
return l3.headers = { ...p5, ...
|
|
15056
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
15057
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12958
15058
|
}, thirdParty: async (t7, s5, n5 = {}) => {
|
|
12959
15059
|
o$f("thirdParty", "thirdPartyOAuthRequest", t7);
|
|
12960
15060
|
const a5 = new URL("/iam/v1/oauth/third_party", i$9);
|
|
@@ -12962,8 +15062,8 @@ const m$3 = function(t6) {
|
|
|
12962
15062
|
e4 && (h2 = e4.baseOptions);
|
|
12963
15063
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
12964
15064
|
await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["x-game"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
12965
|
-
let
|
|
12966
|
-
return l3.headers = { ...p5, ...
|
|
15065
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
15066
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
12967
15067
|
}, unlinkEmail: async (t7, s5 = {}) => {
|
|
12968
15068
|
o$f("unlinkEmail", "unlinkEmailRequest", t7);
|
|
12969
15069
|
const n5 = new URL("/iam/v1/password/unlink", i$9);
|
|
@@ -13402,8 +15502,8 @@ const R$1 = function(t6) {
|
|
|
13402
15502
|
const a5 = "/reset-password/{token}".replace("{token}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
13403
15503
|
let u4;
|
|
13404
15504
|
e4 && (u4 = e4.baseOptions);
|
|
13405
|
-
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {},
|
|
13406
|
-
await r$h(p5, e4), void 0 !== s5 && (
|
|
15505
|
+
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {}, P2 = {};
|
|
15506
|
+
await r$h(p5, e4), void 0 !== s5 && (P2.callbackURL = s5), c$8(h2, P2);
|
|
13407
15507
|
let w2 = u4 && u4.headers ? u4.headers : {};
|
|
13408
15508
|
return l3.headers = { ...p5, ...w2, ...n5.headers }, { url: d$6(h2), options: l3 };
|
|
13409
15509
|
}, revokeOtherSessionsPost: async (t7, s5 = {}) => {
|
|
@@ -13532,8 +15632,8 @@ const R$1 = function(t6) {
|
|
|
13532
15632
|
e4 && (h2 = e4.baseOptions);
|
|
13533
15633
|
const u4 = { method: "GET", ...h2, ...n5 }, l3 = {}, p5 = {};
|
|
13534
15634
|
await r$h(l3, e4), void 0 !== t7 && (p5.token = t7), void 0 !== s5 && (p5.callbackURL = s5), c$8(a5, p5);
|
|
13535
|
-
let
|
|
13536
|
-
return u4.headers = { ...l3, ...
|
|
15635
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
15636
|
+
return u4.headers = { ...l3, ...P2, ...n5.headers }, { url: d$6(a5), options: u4 };
|
|
13537
15637
|
} };
|
|
13538
15638
|
}(t6);
|
|
13539
15639
|
return { async accountInfoPost(a5, i3) {
|
|
@@ -13799,10 +15899,10 @@ const b = function(t6) {
|
|
|
13799
15899
|
const a5 = "/rpc/{chainId}".replace("{chainId}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
13800
15900
|
let l3;
|
|
13801
15901
|
e4 && (l3 = e4.baseOptions);
|
|
13802
|
-
const p5 = { method: "POST", ...l3, ...n5 },
|
|
13803
|
-
await r$h(
|
|
15902
|
+
const p5 = { method: "POST", ...l3, ...n5 }, P2 = {};
|
|
15903
|
+
await r$h(P2, e4), P2["Content-Type"] = "application/json", c$8(h2, {});
|
|
13804
15904
|
let w2 = l3 && l3.headers ? l3.headers : {};
|
|
13805
|
-
return p5.headers = { ...
|
|
15905
|
+
return p5.headers = { ...P2, ...w2, ...n5.headers }, p5.data = u$4(s5, p5, e4), { url: d$6(h2), options: p5 };
|
|
13806
15906
|
}, handleRpcRequest: async (t7, s5 = {}) => {
|
|
13807
15907
|
o$f("handleRpcRequest", "jsonRpcRequest", t7);
|
|
13808
15908
|
const n5 = new URL("/rpc", i$9);
|
|
@@ -13839,24 +15939,24 @@ const S = function(t6) {
|
|
|
13839
15939
|
e4 && (h2 = e4.baseOptions);
|
|
13840
15940
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
13841
15941
|
await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["X-Behalf-Of-Project"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
13842
|
-
let
|
|
13843
|
-
return l3.headers = { ...p5, ...
|
|
15942
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
15943
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
13844
15944
|
}, getPlayerSessions: async (t7, s5, n5, a5, h2, u4 = {}) => {
|
|
13845
15945
|
o$f("getPlayerSessions", "player", t7);
|
|
13846
15946
|
const l3 = new URL("/v1/sessions", i$9);
|
|
13847
15947
|
let p5;
|
|
13848
15948
|
e4 && (p5 = e4.baseOptions);
|
|
13849
|
-
const
|
|
15949
|
+
const P2 = { method: "GET", ...p5, ...u4 }, w2 = {}, g2 = {};
|
|
13850
15950
|
await r$h(w2, e4), await r$h(w2, e4), void 0 !== s5 && (g2.limit = s5), void 0 !== n5 && (g2.skip = n5), void 0 !== a5 && (g2.order = a5), void 0 !== t7 && (g2.player = t7), h2 && (g2.expand = h2), c$8(l3, g2);
|
|
13851
15951
|
let m2 = p5 && p5.headers ? p5.headers : {};
|
|
13852
|
-
return
|
|
15952
|
+
return P2.headers = { ...w2, ...m2, ...u4.headers }, { url: d$6(l3), options: P2 };
|
|
13853
15953
|
}, getSession: async (t7, s5, n5 = {}) => {
|
|
13854
15954
|
o$f("getSession", "id", t7);
|
|
13855
15955
|
const a5 = "/v1/sessions/{id}".replace("{id}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
13856
15956
|
let u4;
|
|
13857
15957
|
e4 && (u4 = e4.baseOptions);
|
|
13858
|
-
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {},
|
|
13859
|
-
await r$h(p5, e4), await r$h(p5, e4), s5 && (
|
|
15958
|
+
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {}, P2 = {};
|
|
15959
|
+
await r$h(p5, e4), await r$h(p5, e4), s5 && (P2.expand = s5), c$8(h2, P2);
|
|
13860
15960
|
let w2 = u4 && u4.headers ? u4.headers : {};
|
|
13861
15961
|
return l3.headers = { ...p5, ...w2, ...n5.headers }, { url: d$6(h2), options: l3 };
|
|
13862
15962
|
}, revokeSession: async (t7, s5, n5 = {}) => {
|
|
@@ -13866,17 +15966,17 @@ const S = function(t6) {
|
|
|
13866
15966
|
e4 && (h2 = e4.baseOptions);
|
|
13867
15967
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
13868
15968
|
await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["X-Behalf-Of-Project"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
13869
|
-
let
|
|
13870
|
-
return l3.headers = { ...p5, ...
|
|
15969
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
15970
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
13871
15971
|
}, signatureSession: async (t7, s5, n5 = {}) => {
|
|
13872
15972
|
o$f("signatureSession", "id", t7), o$f("signatureSession", "signatureRequest", s5);
|
|
13873
15973
|
const a5 = "/v1/sessions/{id}/signature".replace("{id}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
13874
15974
|
let l3;
|
|
13875
15975
|
e4 && (l3 = e4.baseOptions);
|
|
13876
|
-
const p5 = { method: "POST", ...l3, ...n5 },
|
|
13877
|
-
await r$h(
|
|
15976
|
+
const p5 = { method: "POST", ...l3, ...n5 }, P2 = {};
|
|
15977
|
+
await r$h(P2, e4), await r$h(P2, e4), await r$h(P2, e4), P2["Content-Type"] = "application/json", c$8(h2, {});
|
|
13878
15978
|
let w2 = l3 && l3.headers ? l3.headers : {};
|
|
13879
|
-
return p5.headers = { ...
|
|
15979
|
+
return p5.headers = { ...P2, ...w2, ...n5.headers }, p5.data = u$4(s5, p5, e4), { url: d$6(h2), options: p5 };
|
|
13880
15980
|
} };
|
|
13881
15981
|
}(t6);
|
|
13882
15982
|
return { async createSession(a5, i3, o5) {
|
|
@@ -13922,8 +16022,8 @@ const k$1 = function(t6) {
|
|
|
13922
16022
|
e4 && (h2 = e4.baseOptions);
|
|
13923
16023
|
const l3 = { method: "POST", ...h2, ...n5 }, p5 = {};
|
|
13924
16024
|
await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), null != s5 && (p5["X-Behalf-Of-Project"] = String(s5)), p5["Content-Type"] = "application/json", c$8(a5, {});
|
|
13925
|
-
let
|
|
13926
|
-
return l3.headers = { ...p5, ...
|
|
16025
|
+
let P2 = h2 && h2.headers ? h2.headers : {};
|
|
16026
|
+
return l3.headers = { ...p5, ...P2, ...n5.headers }, l3.data = u$4(t7, l3, e4), { url: d$6(a5), options: l3 };
|
|
13927
16027
|
}, estimateTransactionIntentCost: async (t7, s5 = {}) => {
|
|
13928
16028
|
o$f("estimateTransactionIntentCost", "createTransactionIntentRequest", t7);
|
|
13929
16029
|
const n5 = new URL("/v1/transaction_intents/estimate_gas_cost", i$9);
|
|
@@ -13938,27 +16038,27 @@ const k$1 = function(t6) {
|
|
|
13938
16038
|
const a5 = "/v1/transaction_intents/{id}".replace("{id}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
13939
16039
|
let u4;
|
|
13940
16040
|
e4 && (u4 = e4.baseOptions);
|
|
13941
|
-
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {},
|
|
13942
|
-
await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), s5 && (
|
|
16041
|
+
const l3 = { method: "GET", ...u4, ...n5 }, p5 = {}, P2 = {};
|
|
16042
|
+
await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), await r$h(p5, e4), s5 && (P2.expand = s5), c$8(h2, P2);
|
|
13943
16043
|
let w2 = u4 && u4.headers ? u4.headers : {};
|
|
13944
16044
|
return l3.headers = { ...p5, ...w2, ...n5.headers }, { url: d$6(h2), options: l3 };
|
|
13945
|
-
}, getTransactionIntents: async (t7, s5, n5, a5, o5, h2, u4, l3, p5,
|
|
16045
|
+
}, getTransactionIntents: async (t7, s5, n5, a5, o5, h2, u4, l3, p5, P2 = {}) => {
|
|
13946
16046
|
const w2 = new URL("/v1/transaction_intents", i$9);
|
|
13947
16047
|
let g2;
|
|
13948
16048
|
e4 && (g2 = e4.baseOptions);
|
|
13949
|
-
const m2 = { method: "GET", ...g2, ...
|
|
16049
|
+
const m2 = { method: "GET", ...g2, ...P2 }, y3 = {}, R2 = {};
|
|
13950
16050
|
await r$h(y3, e4), await r$h(y3, e4), void 0 !== t7 && (R2.limit = t7), void 0 !== s5 && (R2.skip = s5), void 0 !== n5 && (R2.order = n5), a5 && (R2.expand = a5), void 0 !== o5 && (R2.chainId = o5), h2 && (R2.account = h2), u4 && (R2.player = u4), void 0 !== l3 && (R2.status = l3), p5 && (R2.policy = p5), c$8(w2, R2);
|
|
13951
16051
|
let f3 = g2 && g2.headers ? g2.headers : {};
|
|
13952
|
-
return m2.headers = { ...y3, ...f3, ...
|
|
16052
|
+
return m2.headers = { ...y3, ...f3, ...P2.headers }, { url: d$6(w2), options: m2 };
|
|
13953
16053
|
}, signature: async (t7, s5, n5 = {}) => {
|
|
13954
16054
|
o$f("signature", "id", t7), o$f("signature", "signatureRequest", s5);
|
|
13955
16055
|
const a5 = "/v1/transaction_intents/{id}/signature".replace("{id}", encodeURIComponent(String(t7))), h2 = new URL(a5, i$9);
|
|
13956
16056
|
let l3;
|
|
13957
16057
|
e4 && (l3 = e4.baseOptions);
|
|
13958
|
-
const p5 = { method: "POST", ...l3, ...n5 },
|
|
13959
|
-
await r$h(
|
|
16058
|
+
const p5 = { method: "POST", ...l3, ...n5 }, P2 = {};
|
|
16059
|
+
await r$h(P2, e4), await r$h(P2, e4), P2["Content-Type"] = "application/json", c$8(h2, {});
|
|
13960
16060
|
let w2 = l3 && l3.headers ? l3.headers : {};
|
|
13961
|
-
return p5.headers = { ...
|
|
16061
|
+
return p5.headers = { ...P2, ...w2, ...n5.headers }, p5.data = u$4(s5, p5, e4), { url: d$6(h2), options: p5 };
|
|
13962
16062
|
} };
|
|
13963
16063
|
}(t6);
|
|
13964
16064
|
return { async createTransactionIntent(a5, i3, o5) {
|
|
@@ -13970,8 +16070,8 @@ const k$1 = function(t6) {
|
|
|
13970
16070
|
}, async getTransactionIntent(a5, i3, o5) {
|
|
13971
16071
|
const r7 = await n4.getTransactionIntent(a5, i3, o5);
|
|
13972
16072
|
return l$4(r7, axios, s$c, t6);
|
|
13973
|
-
}, async getTransactionIntents(a5, i3, o5, r7, h2, c3, u4, d2, p5,
|
|
13974
|
-
const w2 = await n4.getTransactionIntents(a5, i3, o5, r7, h2, c3, u4, d2, p5,
|
|
16073
|
+
}, async getTransactionIntents(a5, i3, o5, r7, h2, c3, u4, d2, p5, P2) {
|
|
16074
|
+
const w2 = await n4.getTransactionIntents(a5, i3, o5, r7, h2, c3, u4, d2, p5, P2);
|
|
13975
16075
|
return l$4(w2, axios, s$c, t6);
|
|
13976
16076
|
}, async signature(a5, i3, o5) {
|
|
13977
16077
|
const r7 = await n4.signature(a5, i3, o5);
|
|
@@ -14015,14 +16115,14 @@ const q = function(t6) {
|
|
|
14015
16115
|
await r$h(l3, e4), await r$h(l3, e4), c$8(a5, {});
|
|
14016
16116
|
let p5 = h2 && h2.headers ? h2.headers : {};
|
|
14017
16117
|
return u4.headers = { ...l3, ...p5, ...s5.headers }, { url: d$6(a5), options: u4 };
|
|
14018
|
-
}, getAuthUsers: async (t7, s5, n5, a5, o5, h2, u4, l3, p5,
|
|
16118
|
+
}, getAuthUsers: async (t7, s5, n5, a5, o5, h2, u4, l3, p5, P2 = {}) => {
|
|
14019
16119
|
const w2 = new URL("/v2/users", i$9);
|
|
14020
16120
|
let g2;
|
|
14021
16121
|
e4 && (g2 = e4.baseOptions);
|
|
14022
|
-
const m2 = { method: "GET", ...g2, ...
|
|
16122
|
+
const m2 = { method: "GET", ...g2, ...P2 }, y3 = {}, R2 = {};
|
|
14023
16123
|
await r$h(y3, e4), await r$h(y3, e4), void 0 !== t7 && (R2.limit = t7), void 0 !== s5 && (R2.skip = s5), void 0 !== n5 && (R2.order = n5), void 0 !== a5 && (R2.name = a5), void 0 !== o5 && (R2.externalUserId = o5), void 0 !== h2 && (R2.email = h2), void 0 !== u4 && (R2.phoneNumber = u4), void 0 !== l3 && (R2.authProviderId = l3), void 0 !== p5 && (R2.walletClientType = p5), c$8(w2, R2);
|
|
14024
16124
|
let f3 = g2 && g2.headers ? g2.headers : {};
|
|
14025
|
-
return m2.headers = { ...y3, ...f3, ...
|
|
16125
|
+
return m2.headers = { ...y3, ...f3, ...P2.headers }, { url: d$6(w2), options: m2 };
|
|
14026
16126
|
}, getUserWallet: async (t7, s5 = {}) => {
|
|
14027
16127
|
o$f("getUserWallet", "id", t7);
|
|
14028
16128
|
const n5 = "/v2/users/{id}/wallet".replace("{id}", encodeURIComponent(String(t7))), a5 = new URL(n5, i$9);
|
|
@@ -14066,8 +16166,8 @@ const q = function(t6) {
|
|
|
14066
16166
|
}, async getAuthUser(a5, i3) {
|
|
14067
16167
|
const o5 = await n4.getAuthUser(a5, i3);
|
|
14068
16168
|
return l$4(o5, axios, s$c, t6);
|
|
14069
|
-
}, async getAuthUsers(a5, i3, o5, r7, h2, c3, u4, d2, p5,
|
|
14070
|
-
const w2 = await n4.getAuthUsers(a5, i3, o5, r7, h2, c3, u4, d2, p5,
|
|
16169
|
+
}, async getAuthUsers(a5, i3, o5, r7, h2, c3, u4, d2, p5, P2) {
|
|
16170
|
+
const w2 = await n4.getAuthUsers(a5, i3, o5, r7, h2, c3, u4, d2, p5, P2);
|
|
14071
16171
|
return l$4(w2, axios, s$c, t6);
|
|
14072
16172
|
}, async getUserWallet(a5, i3) {
|
|
14073
16173
|
const o5 = await n4.getUserWallet(a5, i3);
|
|
@@ -14083,7 +16183,7 @@ const q = function(t6) {
|
|
|
14083
16183
|
return l$4(o5, axios, s$c, t6);
|
|
14084
16184
|
} };
|
|
14085
16185
|
};
|
|
14086
|
-
|
|
16186
|
+
class I extends n$d {
|
|
14087
16187
|
deleteUser(e4, t6) {
|
|
14088
16188
|
return q(this.configuration).deleteUser(e4.id, t6).then((e5) => e5(this.axios, this.basePath));
|
|
14089
16189
|
}
|
|
@@ -14105,7 +16205,7 @@ let I$1 = class I extends n$d {
|
|
|
14105
16205
|
thirdPartyV2(e4, t6) {
|
|
14106
16206
|
return q(this.configuration).thirdPartyV2(e4.thirdPartyOAuthRequest, t6).then((e5) => e5(this.axios, this.basePath));
|
|
14107
16207
|
}
|
|
14108
|
-
}
|
|
16208
|
+
}
|
|
14109
16209
|
class x {
|
|
14110
16210
|
constructor(e4 = {}) {
|
|
14111
16211
|
__publicField(this, "apiKey");
|
|
@@ -14145,7 +16245,7 @@ let U$1 = class U {
|
|
|
14145
16245
|
const n4 = { basePath: s5.basePath, accessToken: s5.accessToken, nativeAppIdentifier: s5.nativeAppIdentifier };
|
|
14146
16246
|
this.config = { backend: A$3(n4) };
|
|
14147
16247
|
const a5 = { basePath: `${s5.basePath}/iam/v2/auth`, accessToken: "", nativeAppIdentifier: s5.nativeAppIdentifier }, i3 = A$3(a5);
|
|
14148
|
-
this.authenticationApi = new y$3(this.config.backend, void 0, this.axiosInstance), this.authApi = new f$2(i3, void 0, this.axiosInstance), this.userApi = new I
|
|
16248
|
+
this.authenticationApi = new y$3(this.config.backend, void 0, this.axiosInstance), this.authApi = new f$2(i3, void 0, this.axiosInstance), this.userApi = new I(this.config.backend, void 0, this.axiosInstance), this.transactionIntentsApi = new v(this.config.backend, void 0, this.axiosInstance), this.accountsApi = new P(this.config.backend, void 0, this.axiosInstance), this.accountsV2Api = new g(this.config.backend, void 0, this.axiosInstance), this.sessionsApi = new T$2(this.config.backend, void 0, this.axiosInstance), this.rpcApi = new O$3(this.config.backend, void 0, this.axiosInstance);
|
|
14149
16249
|
}
|
|
14150
16250
|
setupInterceptors() {
|
|
14151
16251
|
this.axiosInstance.interceptors.response.use((e4) => e4, async (e4) => {
|
|
@@ -14281,7 +16381,7 @@ let a$c = class a2 extends t$i {
|
|
|
14281
16381
|
this.statusCode = r7, this.name = "RequestError", Object.setPrototypeOf(this, a2.prototype);
|
|
14282
16382
|
}
|
|
14283
16383
|
};
|
|
14284
|
-
var E$3, A$2, e$9, T$1, t$h, n$b, o$c, O$1, _, C$
|
|
16384
|
+
var E$3, A$2, e$9, T$1, t$h, n$b, o$c, O$1, _, C$2, N, c$6, a$b;
|
|
14285
16385
|
!function(E2) {
|
|
14286
16386
|
E2[E2.NONE = 0] = "NONE", E2[E2.UNAUTHENTICATED = 1] = "UNAUTHENTICATED", E2[E2.EMBEDDED_SIGNER_NOT_CONFIGURED = 2] = "EMBEDDED_SIGNER_NOT_CONFIGURED", E2[E2.CREATING_ACCOUNT = 3] = "CREATING_ACCOUNT", E2[E2.READY = 4] = "READY";
|
|
14287
16387
|
}(E$3 || (E$3 = {})), function(E2) {
|
|
@@ -14302,9 +16402,9 @@ var E$3, A$2, e$9, T$1, t$h, n$b, o$c, O$1, _, C$3, N$1, c$6, a$b;
|
|
|
14302
16402
|
E2.GOOGLE = "google", E2.TWITTER = "twitter", E2.APPLE = "apple", E2.FACEBOOK = "facebook", E2.DISCORD = "discord", E2.EPIC_GAMES = "epic_games", E2.LINE = "line";
|
|
14303
16403
|
}(_ || (_ = {})), function(E2) {
|
|
14304
16404
|
E2.ACTION_VERIFY_EMAIL = "verify_email";
|
|
14305
|
-
}(C$
|
|
16405
|
+
}(C$2 || (C$2 = {})), function(E2) {
|
|
14306
16406
|
E2.EOA = "Externally Owned Account", E2.SMART_ACCOUNT = "Smart Account", E2.DELEGATED_ACCOUNT = "Delegated Account";
|
|
14307
|
-
}(N
|
|
16407
|
+
}(N || (N = {})), function(E2) {
|
|
14308
16408
|
E2.EVM = "EVM", E2.SVM = "SVM";
|
|
14309
16409
|
}(c$6 || (c$6 = {})), function(E2) {
|
|
14310
16410
|
E2.ASC = "asc", E2.DESC = "desc";
|
|
@@ -15117,7 +17217,7 @@ let n$9 = (_e = class {
|
|
|
15117
17217
|
}
|
|
15118
17218
|
static async init({ sentry: e4, configuration: o5 }) {
|
|
15119
17219
|
if (e4) return void (_e.sentry = e4);
|
|
15120
|
-
const a5 = await __vitePreload(() => import("./index
|
|
17220
|
+
const a5 = await __vitePreload(() => import("./index--WaQfBnk.js"), true ? __vite__mapDeps([0,1,2,3]) : void 0);
|
|
15121
17221
|
_e.sentry = new a5.BrowserClient({ dsn: r$a, integrations: [], stackParser: a5.defaultStackParser, transport: a5.makeFetchTransport }), _e.baseTags = { projectId: (o5 == null ? void 0 : o5.baseConfiguration.publishableKey) ?? "", sdk: t$d, sdkVersion: o$9 }, _e.processQueuedCalls();
|
|
15122
17222
|
}
|
|
15123
17223
|
static processQueuedCalls() {
|
|
@@ -15224,7 +17324,7 @@ let p$3 = class p3 {
|
|
|
15224
17324
|
}
|
|
15225
17325
|
async switchChain({ chainId: e4 }) {
|
|
15226
17326
|
const t6 = await s$9.fromStorage(this.storage);
|
|
15227
|
-
if ((t6 == null ? void 0 : t6.accountType) === N
|
|
17327
|
+
if ((t6 == null ? void 0 : t6.accountType) === N.EOA) new s$9({ ...t6, chainId: e4 }).save(this.storage);
|
|
15228
17328
|
else {
|
|
15229
17329
|
const a5 = await this.iframeManager.switchChain(e4);
|
|
15230
17330
|
new s$9({ ...t6, id: a5.account, chainId: e4 }).save(this.storage);
|
|
@@ -15510,23 +17610,23 @@ const t$8 = async (t6) => {
|
|
|
15510
17610
|
let g2 = a5;
|
|
15511
17611
|
if ([T$1.UPGRADEABLE_V5, T$1.UPGRADEABLE_V6].includes(d2)) {
|
|
15512
17612
|
const e4 = { name: "Openfort", version: "0.5", chainId: Number(o5), verifyingContract: c3 }, t7 = { OpenfortMessage: [{ name: "hashedMessage", type: "bytes32" }] }, a6 = { hashedMessage: g2 }, { _TypedDataEncoder: s6 } = await __vitePreload(async () => {
|
|
15513
|
-
const { _TypedDataEncoder: s7 } = await import("./index-
|
|
17613
|
+
const { _TypedDataEncoder: s7 } = await import("./index-BQfjfSli.js");
|
|
15514
17614
|
return { _TypedDataEncoder: s7 };
|
|
15515
17615
|
}, true ? __vite__mapDeps([4,5,6,7,1,2,3]) : void 0);
|
|
15516
17616
|
g2 = s6.hash(e4, t7, a6);
|
|
15517
17617
|
}
|
|
15518
|
-
const
|
|
17618
|
+
const P2 = await s5.sign(g2, false, false);
|
|
15519
17619
|
if (i3 && n4 && [T$1.UPGRADEABLE_V5, T$1.UPGRADEABLE_V6].includes(d2)) {
|
|
15520
|
-
const { id: e4 } = await __vitePreload(() => import("./index-
|
|
15521
|
-
const { defaultAbiCoder: t8 } = await import("./index-
|
|
17620
|
+
const { id: e4 } = await __vitePreload(() => import("./index-BQfjfSli.js"), true ? __vite__mapDeps([4,5,6,7,1,2,3]) : void 0), { defaultAbiCoder: t7 } = await __vitePreload(async () => {
|
|
17621
|
+
const { defaultAbiCoder: t8 } = await import("./index-LuGvuWDj.js");
|
|
15522
17622
|
return { defaultAbiCoder: t8 };
|
|
15523
17623
|
}, true ? __vite__mapDeps([8,7,9,6,1,2,3]) : void 0), { hexConcat: a6 } = await __vitePreload(async () => {
|
|
15524
17624
|
const { hexConcat: a7 } = await Promise.resolve().then(() => index$1);
|
|
15525
17625
|
return { hexConcat: a7 };
|
|
15526
17626
|
}, true ? void 0 : void 0), s6 = a6([e4("createAccountWithNonce(address,bytes32,bool)").slice(0, 10), t7.encode(["address", "bytes32", "bool"], [r7, n4, false])]);
|
|
15527
|
-
return a6([t7.encode(["address", "bytes", "bytes"], [i3, s6,
|
|
17627
|
+
return a6([t7.encode(["address", "bytes", "bytes"], [i3, s6, P2]), "0x6492649264926492649264926492649264926492649264926492649264926492"]);
|
|
15528
17628
|
}
|
|
15529
|
-
return
|
|
17629
|
+
return P2;
|
|
15530
17630
|
};
|
|
15531
17631
|
async function a$7(e4, t6, a5) {
|
|
15532
17632
|
const s5 = { ...e4 };
|
|
@@ -15564,7 +17664,7 @@ const t$7 = async ({ params: t6, signer: o5, account: n4 }) => {
|
|
|
15564
17664
|
const i3 = t6[0], d2 = t6[1];
|
|
15565
17665
|
if (!d2 || !i3) throw new A$1(E$2.INVALID_PARAMS, "personal_sign requires an address and a message");
|
|
15566
17666
|
if (d2.toLowerCase() !== n4.address.toLowerCase()) throw new A$1(E$2.INVALID_PARAMS, "personal_sign requires the signer to be the from address");
|
|
15567
|
-
const { hashMessage: p5 } = await __vitePreload(() => import("./index-
|
|
17667
|
+
const { hashMessage: p5 } = await __vitePreload(() => import("./index-BQfjfSli.js"), true ? __vite__mapDeps([4,5,6,7,1,2,3]) : void 0);
|
|
15568
17668
|
return await t$8({ hash: p5(n$a(i3)), implementationType: n4.implementationType || n4.type, chainId: Number(n4.chainId), signer: o5, address: d2, salt: n4.salt, factoryAddress: n4.factoryAddress, ownerAddress: n4.ownerAddress });
|
|
15569
17669
|
};
|
|
15570
17670
|
function a$6(t6) {
|
|
@@ -17001,7 +19101,7 @@ const d$5 = async ({ params: d2, signer: p5, account: l3, authentication: u4, ba
|
|
|
17001
19101
|
var _a4, _b2, _c4, _d4, _e4, _f2, _g3, _h4, _i3, _j;
|
|
17002
19102
|
const A3 = ((_c4 = (_b2 = (_a4 = d2[0]) == null ? void 0 : _a4.capabilities) == null ? void 0 : _b2.paymasterService) == null ? void 0 : _c4.policy) ?? T3;
|
|
17003
19103
|
let m2;
|
|
17004
|
-
if (l3.accountType === N
|
|
19104
|
+
if (l3.accountType === N.DELEGATED_ACCOUNT) {
|
|
17005
19105
|
const [e4, t6] = await Promise.all([c$4(g2, l3.address), g2.getTransactionCount(l3.address)]);
|
|
17006
19106
|
if (!e4) {
|
|
17007
19107
|
const e5 = await i$5({ signer: p5, accountAddress: l3.address, contractAddress: l3.implementationAddress, chainId: l3.chainId, nonce: t6 });
|
|
@@ -17052,15 +19152,15 @@ const r$5 = ["types", "domain", "primaryType", "message"], n$5 = (a5, n4) => {
|
|
|
17052
19152
|
}, s$6 = async ({ params: r7, method: s5, signer: d2, implementationType: i3, rpcProvider: o5, account: p5 }) => {
|
|
17053
19153
|
const c3 = r7[0], h2 = r7[1];
|
|
17054
19154
|
if (!c3 || !h2) throw new A$1(E$2.INVALID_PARAMS, `${s5} requires an address and a typed data JSON`);
|
|
17055
|
-
const { chainId: m2 } = await o5.detectNetwork(),
|
|
19155
|
+
const { chainId: m2 } = await o5.detectNetwork(), I2 = n$5(h2, m2), y3 = { ...I2.types };
|
|
17056
19156
|
delete y3.EIP712Domain;
|
|
17057
|
-
const { _TypedDataEncoder: A3 } = await __vitePreload(() => import("./index-
|
|
19157
|
+
const { _TypedDataEncoder: A3 } = await __vitePreload(() => import("./index-BQfjfSli.js"), true ? __vite__mapDeps([4,5,6,7,1,2,3]) : void 0), w2 = A3.hash(I2.domain, y3, I2.message);
|
|
17058
19158
|
return await t$8({ hash: w2, implementationType: i3, chainId: m2, signer: d2, address: c3, ownerAddress: p5.ownerAddress, factoryAddress: p5.factoryAddress, salt: p5.salt });
|
|
17059
19159
|
};
|
|
17060
|
-
var C$
|
|
17061
|
-
!function(
|
|
17062
|
-
|
|
17063
|
-
}(C$
|
|
19160
|
+
var C$1;
|
|
19161
|
+
!function(C2) {
|
|
19162
|
+
C2.ACCOUNTS_CHANGED = "accountsChanged", C2.CHAIN_CHANGED = "chainChanged", C2.ACCOUNTS_CONNECT = "connect", C2.DISCONNECT = "disconnect";
|
|
19163
|
+
}(C$1 || (C$1 = {}));
|
|
17064
19164
|
let E$1 = (_f = class {
|
|
17065
19165
|
constructor({ storage: t6, backendApiClients: e4, openfortEventEmitter: a5, feeSponsorshipId: i3, ensureSigner: r7, chains: n4, validateAndRefreshSession: h2 }) {
|
|
17066
19166
|
__privateAdd(this, _E_instances);
|
|
@@ -17076,10 +19176,10 @@ let E$1 = (_f = class {
|
|
|
17076
19176
|
__privateAdd(this, _h);
|
|
17077
19177
|
__privateAdd(this, _d2, async () => (__privateGet(this, _a2) || __privateSet(this, _a2, await __privateGet(this, _h).call(this)), __privateGet(this, _a2)));
|
|
17078
19178
|
__privateAdd(this, _c2, async () => {
|
|
17079
|
-
__privateSet(this, _a2, void 0), __privateGet(this, _r).emit(C$
|
|
19179
|
+
__privateSet(this, _a2, void 0), __privateGet(this, _r).emit(C$1.DISCONNECT, { code: 4900, message: "Disconnected" }), __privateGet(this, _r).emit(C$1.ACCOUNTS_CHANGED, []);
|
|
17080
19180
|
});
|
|
17081
19181
|
__privateAdd(this, _p, async (t6) => {
|
|
17082
|
-
__privateGet(this, _r).emit(C$
|
|
19182
|
+
__privateGet(this, _r).emit(C$1.ACCOUNTS_CHANGED, [t6]);
|
|
17083
19183
|
});
|
|
17084
19184
|
__privateSet(this, _h, r7), __privateSet(this, _t, t6), __privateSet(this, _s, n4), __privateSet(this, _e2, i3), __privateSet(this, _i, h2), __privateSet(this, _n, e4), __privateSet(this, _r, new t$9()), a5.on(A$2.ON_LOGOUT, __privateGet(this, _c2)), a5.on(A$2.ON_SWITCH_ACCOUNT, __privateGet(this, _p));
|
|
17085
19185
|
}
|
|
@@ -17089,7 +19189,7 @@ let E$1 = (_f = class {
|
|
|
17089
19189
|
async getRpcProvider() {
|
|
17090
19190
|
if (!__privateGet(this, _o)) {
|
|
17091
19191
|
const e4 = await s$9.fromStorage(__privateGet(this, _t)), s5 = (e4 == null ? void 0 : e4.chainId) || (__privateGet(this, _s) ? Number(Object.keys(__privateGet(this, _s))[0]) : void 0) || 8453;
|
|
17092
|
-
await __vitePreload(() => import("./index-
|
|
19192
|
+
await __vitePreload(() => import("./index-CNWQNI4F.js"), true ? __vite__mapDeps([10,7,5,6,11,9,1,2,3]) : void 0).then((t6) => {
|
|
17093
19193
|
const e5 = __privateGet(this, _s) ? __privateGet(this, _s)[s5] : void 0;
|
|
17094
19194
|
__privateSet(this, _o, new t6.StaticJsonRpcProvider(e5 ?? t$a[s5]));
|
|
17095
19195
|
});
|
|
@@ -17123,7 +19223,7 @@ let E$1 = (_f = class {
|
|
|
17123
19223
|
const e4 = await s$9.fromStorage(__privateGet(this, _t));
|
|
17124
19224
|
if (e4) {
|
|
17125
19225
|
const t6 = await this.getRpcProvider(), { chainId: s6 } = await t6.detectNetwork();
|
|
17126
|
-
return __privateGet(this, _r).emit(C$
|
|
19226
|
+
return __privateGet(this, _r).emit(C$1.ACCOUNTS_CONNECT, { chainId: r$b(s6) }), [e4.address];
|
|
17127
19227
|
}
|
|
17128
19228
|
throw new A$1(R.UNAUTHORIZED, "Unauthorized - must be authenticated and configured with a signer.");
|
|
17129
19229
|
}
|
|
@@ -17133,7 +19233,7 @@ let E$1 = (_f = class {
|
|
|
17133
19233
|
const o5 = await this.getRpcProvider(), { chainId: n4 } = await o5.detectNetwork(), [h2] = s5.params || [];
|
|
17134
19234
|
h2.chainId || (h2.chainId = n4.toString());
|
|
17135
19235
|
const c3 = s$8(h2), { serialize: p5 } = await __vitePreload(async () => {
|
|
17136
|
-
const { serialize: p6 } = await import("./index-
|
|
19236
|
+
const { serialize: p6 } = await import("./index-CY5VRUKw.js").then((n5) => n5.i);
|
|
17137
19237
|
return { serialize: p6 };
|
|
17138
19238
|
}, true ? __vite__mapDeps([11,7,9]) : void 0), w2 = (t6) => ({ legacy: 0, eip2930: 1, eip1559: 2 })[t6], { gas: u4, ...l3 } = c3, g2 = { ...l3, gasLimit: u4, to: c3.to ?? void 0, type: w2(c3.type) }, f3 = p5(g2), { keccak256: S2 } = await __vitePreload(async () => {
|
|
17139
19239
|
const { keccak256: S3 } = await Promise.resolve().then(() => index);
|
|
@@ -17149,7 +19249,7 @@ let E$1 = (_f = class {
|
|
|
17149
19249
|
case "eth_sendTransaction": {
|
|
17150
19250
|
const [i3, r7, o5] = await Promise.all([s$9.fromStorage(__privateGet(this, _t)), __privateGet(this, _d2).call(this), r$g.fromStorage(__privateGet(this, _t))]);
|
|
17151
19251
|
if (!i3 || !o5) throw new A$1(R.UNAUTHORIZED, "Unauthorized - call eth_requestAccounts first");
|
|
17152
|
-
if (await __privateGet(this, _i).call(this), (i3 == null ? void 0 : i3.accountType) === N
|
|
19252
|
+
if (await __privateGet(this, _i).call(this), (i3 == null ? void 0 : i3.accountType) === N.EOA) {
|
|
17153
19253
|
const [t6] = s5.params || [], e4 = await this.getRpcProvider(), a5 = await a$7(t6, e4, i3.address), r8 = await __privateMethod(this, _E_instances, m_fn).call(this, { method: "eth_signTransaction", params: [a5] });
|
|
17154
19254
|
return __privateMethod(this, _E_instances, m_fn).call(this, { method: "eth_sendRawTransaction", params: [r8] });
|
|
17155
19255
|
}
|
|
@@ -17158,7 +19258,7 @@ let E$1 = (_f = class {
|
|
|
17158
19258
|
case "eth_sendRawTransactionSync": {
|
|
17159
19259
|
const [i3, r7, o5] = await Promise.all([s$9.fromStorage(__privateGet(this, _t)), __privateGet(this, _d2).call(this), r$g.fromStorage(__privateGet(this, _t))]);
|
|
17160
19260
|
if (!i3 || !o5) throw new A$1(R.UNAUTHORIZED, "Unauthorized - call eth_requestAccounts first");
|
|
17161
|
-
if ((i3 == null ? void 0 : i3.accountType) === N
|
|
19261
|
+
if ((i3 == null ? void 0 : i3.accountType) === N.EOA) throw new A$1(R.UNSUPPORTED_METHOD, `${s5.method}: Method not supported`);
|
|
17162
19262
|
return await __privateGet(this, _i).call(this), await d$5({ params: s5.params || [], signer: r7, account: i3, authentication: o5, backendClient: __privateGet(this, _n), rpcProvider: await this.getRpcProvider(), feeSponsorshipId: __privateGet(this, _e2) });
|
|
17163
19263
|
}
|
|
17164
19264
|
case "eth_estimateGas": {
|
|
@@ -17190,10 +19290,10 @@ let E$1 = (_f = class {
|
|
|
17190
19290
|
await __privateGet(this, _i).call(this);
|
|
17191
19291
|
try {
|
|
17192
19292
|
const e4 = parseInt(s5.params[0].chainId, 16);
|
|
17193
|
-
await t6.switchChain({ chainId: e4 }), await __vitePreload(() => import("./index-
|
|
19293
|
+
await t6.switchChain({ chainId: e4 }), await __vitePreload(() => import("./index-CNWQNI4F.js"), true ? __vite__mapDeps([10,7,5,6,11,9,1,2,3]) : void 0).then((t7) => {
|
|
17194
19294
|
const s6 = __privateGet(this, _s) ? __privateGet(this, _s)[e4] : void 0;
|
|
17195
19295
|
__privateSet(this, _o, new t7.StaticJsonRpcProvider(s6 ?? t$a[e4]));
|
|
17196
|
-
}), __privateGet(this, _r).emit(C$
|
|
19296
|
+
}), __privateGet(this, _r).emit(C$1.CHAIN_CHANGED, r$b(e4));
|
|
17197
19297
|
} catch (t7) {
|
|
17198
19298
|
const e4 = t7;
|
|
17199
19299
|
throw new A$1(E$2.INTERNAL_ERROR, `Failed to switch chain: ${e4.message}`);
|
|
@@ -17209,21 +19309,21 @@ let E$1 = (_f = class {
|
|
|
17209
19309
|
return null;
|
|
17210
19310
|
case "wallet_getCallsStatus": {
|
|
17211
19311
|
const i3 = await s$9.fromStorage(__privateGet(this, _t));
|
|
17212
|
-
if ((i3 == null ? void 0 : i3.accountType) === N
|
|
19312
|
+
if ((i3 == null ? void 0 : i3.accountType) === N.EOA) throw new A$1(R.UNSUPPORTED_METHOD, `${s5.method}: Method not supported`);
|
|
17213
19313
|
const r7 = await r$g.fromStorage(__privateGet(this, _t));
|
|
17214
19314
|
if (!i3 || !r7) throw new A$1(R.UNAUTHORIZED, "Unauthorized - call eth_requestAccounts first");
|
|
17215
19315
|
return await __privateGet(this, _i).call(this), await r$8({ params: s5.params || {}, authentication: r7, backendClient: __privateGet(this, _n) });
|
|
17216
19316
|
}
|
|
17217
19317
|
case "wallet_sendCalls": {
|
|
17218
19318
|
const [i3, r7, o5] = await Promise.all([s$9.fromStorage(__privateGet(this, _t)), __privateGet(this, _d2).call(this), r$g.fromStorage(__privateGet(this, _t))]);
|
|
17219
|
-
if ((i3 == null ? void 0 : i3.accountType) === N
|
|
19319
|
+
if ((i3 == null ? void 0 : i3.accountType) === N.EOA) throw new A$1(R.UNSUPPORTED_METHOD, `${s5.method}: Method not supported`);
|
|
17220
19320
|
if (!i3 || !o5) throw new A$1(R.UNAUTHORIZED, "Unauthorized - call eth_requestAccounts first");
|
|
17221
19321
|
await __privateGet(this, _i).call(this);
|
|
17222
19322
|
return await a$5({ params: s5.params ? s5.params[0].calls : [], signer: r7, account: i3, authentication: o5, backendClient: __privateGet(this, _n), rpcProvider: await this.getRpcProvider(), feeSponsorshipId: __privateGet(this, _e2) });
|
|
17223
19323
|
}
|
|
17224
19324
|
case "wallet_grantPermissions": {
|
|
17225
19325
|
const i3 = await s$9.fromStorage(__privateGet(this, _t));
|
|
17226
|
-
if ((i3 == null ? void 0 : i3.accountType) === N
|
|
19326
|
+
if ((i3 == null ? void 0 : i3.accountType) === N.EOA) throw new A$1(R.UNSUPPORTED_METHOD, `${s5.method}: Method not supported`);
|
|
17227
19327
|
const r7 = await __privateGet(this, _d2).call(this), o5 = await r$g.fromStorage(__privateGet(this, _t));
|
|
17228
19328
|
if (!i3 || !o5) throw new A$1(R.UNAUTHORIZED, "Unauthorized - call eth_requestAccounts first");
|
|
17229
19329
|
return await __privateGet(this, _i).call(this), await r$7({ params: s5.params || [], signer: r7, account: i3, authentication: o5, backendClient: __privateGet(this, _n), feeSponsorshipId: __privateGet(this, _e2) });
|
|
@@ -17235,7 +19335,7 @@ let E$1 = (_f = class {
|
|
|
17235
19335
|
}
|
|
17236
19336
|
case "wallet_getCapabilities": {
|
|
17237
19337
|
const e4 = await s$9.fromStorage(__privateGet(this, _t));
|
|
17238
|
-
if ((e4 == null ? void 0 : e4.accountType) === N
|
|
19338
|
+
if ((e4 == null ? void 0 : e4.accountType) === N.EOA) throw new A$1(R.UNSUPPORTED_METHOD, `${s5.method}: Method not supported`);
|
|
17239
19339
|
const i3 = await this.getRpcProvider(), { chainId: o5 } = await i3.detectNetwork();
|
|
17240
19340
|
return { [r$b(o5)]: { permissions: { supported: true, signerTypes: ["account", "key"], keyTypes: ["secp256k1"], permissionTypes: ["contract-calls"] }, paymasterService: { supported: true }, atomicBatch: { supported: true } } };
|
|
17241
19341
|
}
|
|
@@ -17540,17 +19640,17 @@ const e$2 = () => {
|
|
|
17540
19640
|
const p4 = ({ messenger: p5, methods: h2, timeout: l3, channel: f3, log: S2 }) => {
|
|
17541
19641
|
const g2 = t$f();
|
|
17542
19642
|
let u4;
|
|
17543
|
-
const
|
|
19643
|
+
const I2 = [];
|
|
17544
19644
|
let y3 = false;
|
|
17545
|
-
const A3 = s$3(h2), { promise: N2, resolve:
|
|
19645
|
+
const A3 = s$3(h2), { promise: N2, resolve: C2, reject: j } = e$2(), M2 = setTimeout(() => {
|
|
17546
19646
|
j(new r$4("CONNECTION_TIMEOUT", `Connection timed out after ${l3}ms`));
|
|
17547
19647
|
}, l3), R2 = () => {
|
|
17548
|
-
for (const e4 of
|
|
19648
|
+
for (const e4 of I2) e4();
|
|
17549
19649
|
}, T3 = () => {
|
|
17550
19650
|
if (y3) return;
|
|
17551
|
-
|
|
19651
|
+
I2.push(l$2(p5, h2, f3, S2));
|
|
17552
19652
|
const { remoteProxy: e4, destroy: t6 } = d$3(p5, f3, S2);
|
|
17553
|
-
|
|
19653
|
+
I2.push(t6), clearTimeout(M2), y3 = true, C2({ remoteProxy: e4, destroy: R2 });
|
|
17554
19654
|
}, k2 = () => {
|
|
17555
19655
|
const e4 = { namespace: a$4, type: "SYN", channel: f3, participantId: g2 };
|
|
17556
19656
|
S2 == null ? void 0 : S2("Sending handshake SYN", e4);
|
|
@@ -17584,7 +19684,7 @@ const p4 = ({ messenger: p5, methods: h2, timeout: l3, channel: f3, log: S2 }) =
|
|
|
17584
19684
|
S2 == null ? void 0 : S2("Received handshake ACK2", e5), T3();
|
|
17585
19685
|
})(e4);
|
|
17586
19686
|
};
|
|
17587
|
-
return p5.addMessageHandler(v2),
|
|
19687
|
+
return p5.addMessageHandler(v2), I2.push(() => p5.removeMessageHandler(v2)), k2(), N2;
|
|
17588
19688
|
};
|
|
17589
19689
|
const a$1 = /* @__PURE__ */ new WeakSet(), m = ({ messenger: m2, methods: c3 = {}, timeout: i3, channel: d2, log: h2 }) => {
|
|
17590
19690
|
if (!m2) throw new r$4("INVALID_ARGUMENT", "messenger must be defined");
|
|
@@ -17673,7 +19773,7 @@ class T2 {
|
|
|
17673
19773
|
function d$2(r7) {
|
|
17674
19774
|
return "error" in r7;
|
|
17675
19775
|
}
|
|
17676
|
-
|
|
19776
|
+
class C {
|
|
17677
19777
|
constructor(r7, e4, i3) {
|
|
17678
19778
|
__publicField(this, "uuid");
|
|
17679
19779
|
__publicField(this, "action", r$3.UPDATE_AUTHENTICATION);
|
|
@@ -17681,7 +19781,7 @@ let C$1 = class C {
|
|
|
17681
19781
|
__publicField(this, "recovery");
|
|
17682
19782
|
this.uuid = r7, this.accessToken = e4, this.recovery = i3;
|
|
17683
19783
|
}
|
|
17684
|
-
}
|
|
19784
|
+
}
|
|
17685
19785
|
var y$1;
|
|
17686
19786
|
!function(r7) {
|
|
17687
19787
|
r7.OPENFORT = "openfort";
|
|
@@ -17711,11 +19811,11 @@ class D extends s$b {
|
|
|
17711
19811
|
super(E$4.NOT_CONFIGURED, "Signer is not configured");
|
|
17712
19812
|
}
|
|
17713
19813
|
}
|
|
17714
|
-
|
|
19814
|
+
class M extends t$i {
|
|
17715
19815
|
constructor() {
|
|
17716
19816
|
super(E$4.OTP_REQUIRED, "OTP verification required");
|
|
17717
19817
|
}
|
|
17718
|
-
}
|
|
19818
|
+
}
|
|
17719
19819
|
class K {
|
|
17720
19820
|
constructor(e4, i3, t6) {
|
|
17721
19821
|
__publicField(this, "messenger");
|
|
@@ -17776,7 +19876,7 @@ class K {
|
|
|
17776
19876
|
if (e4.error === s$1) throw new z();
|
|
17777
19877
|
if (e4.error === n3) throw this.storage.remove(o$e.ACCOUNT), new A2();
|
|
17778
19878
|
if (e4.error === o$2) throw new O2();
|
|
17779
|
-
if (e4.error === c2) throw new M
|
|
19879
|
+
if (e4.error === c2) throw new M();
|
|
17780
19880
|
throw this.storage.remove(o$e.ACCOUNT), new t$i(E$4.INTERNAL_ERROR, `Unknown error: ${e4.error}`);
|
|
17781
19881
|
}
|
|
17782
19882
|
throw e4;
|
|
@@ -17843,7 +19943,7 @@ class K {
|
|
|
17843
19943
|
if (!this.isLoaded() || !this.remote) return void t$c("IframeManager not loaded, skipping authentication update");
|
|
17844
19944
|
const e4 = await r$g.fromStorage(this.storage);
|
|
17845
19945
|
if (!e4) return void t$c("No authentication found, skipping update");
|
|
17846
|
-
const t6 = new C
|
|
19946
|
+
const t6 = new C(t$f(), e4.token);
|
|
17847
19947
|
t$c("Updating authentication in iframe with token");
|
|
17848
19948
|
const n4 = await this.remote.updateAuthentication(t6);
|
|
17849
19949
|
d$2(n4) && this.handleError(n4);
|
|
@@ -18023,7 +20123,7 @@ class k {
|
|
|
18023
20123
|
}
|
|
18024
20124
|
async configure(e4) {
|
|
18025
20125
|
await this.validateAndRefreshToken();
|
|
18026
|
-
const r7 = e4.recoveryParams ?? { recoveryMethod: e$9.AUTOMATIC }, [t6, s5] = await Promise.all([this.ensureSigner(), this.getEntropy(r7)]), a5 = { chainId: e4.chainId, entropy: s5, accountType: e4.accountType ?? N
|
|
20126
|
+
const r7 = e4.recoveryParams ?? { recoveryMethod: e$9.AUTOMATIC }, [t6, s5] = await Promise.all([this.ensureSigner(), this.getEntropy(r7)]), a5 = { chainId: e4.chainId, entropy: s5, accountType: e4.accountType ?? N.SMART_ACCOUNT, chainType: e4.chainType ?? c$6.EVM, getPasskeyKeyFn: async (e5) => this.getPasskeyKey(e5) }, i3 = await t6.configure(a5);
|
|
18027
20127
|
return { id: i3.id, chainId: i3.chainId, address: i3.address, ownerAddress: i3.ownerAddress, chainType: i3.chainType, accountType: i3.accountType, implementationType: i3.implementationType, factoryAddress: i3.factoryAddress, salt: i3.salt, createdAt: i3.createdAt, implementationAddress: i3.implementationAddress, recoveryMethod: s$9.parseRecoveryMethod(i3.recoveryMethod), recoveryMethodDetails: i3.recoveryMethodDetails };
|
|
18028
20128
|
}
|
|
18029
20129
|
async create(e4) {
|
|
@@ -18061,7 +20161,7 @@ class k {
|
|
|
18061
20161
|
if (!i3) throw new s$b(E$4.MISSING_SIGNER, "No account found");
|
|
18062
20162
|
const n4 = { ...r7 };
|
|
18063
20163
|
delete n4.EIP712Domain;
|
|
18064
|
-
const { _TypedDataEncoder: d2 } = await __vitePreload(() => import("./index-
|
|
20164
|
+
const { _TypedDataEncoder: d2 } = await __vitePreload(() => import("./index-BQfjfSli.js"), true ? __vite__mapDeps([4,5,6,7,1,2,3]) : void 0), h2 = d2.hash(e4, n4, t6);
|
|
18065
20165
|
return await t$8({ hash: h2, implementationType: i3.implementationType || i3.type, chainId: Number(i3.chainId), signer: s5, address: i3.address, ownerAddress: i3.ownerAddress, factoryAddress: i3.factoryAddress, salt: i3.salt });
|
|
18066
20166
|
}
|
|
18067
20167
|
async exportPrivateKey() {
|
|
@@ -18332,7 +20432,7 @@ class d {
|
|
|
18332
20432
|
async signupEmailPassword(e4, t6, i3, a5, o5) {
|
|
18333
20433
|
return c$5(async () => {
|
|
18334
20434
|
const s5 = (await this.backendApiClients.authApi.signUpEmailPost({ signUpEmailPostRequest: { email: e4, password: t6, name: i3, callbackURL: a5 } }, { headers: this.buildAuthHeaders(o5) })).data;
|
|
18335
|
-
return null === s5.token ? { action: C$
|
|
20435
|
+
return null === s5.token ? { action: C$2.ACTION_VERIFY_EMAIL } : { token: s5.token, user: r$1(s5.user) };
|
|
18336
20436
|
}, { context: "signupEmailPassword" });
|
|
18337
20437
|
}
|
|
18338
20438
|
async validateCredentials(t6, i3) {
|
|
@@ -18772,8 +20872,7 @@ function createOpenfortProvider(settings) {
|
|
|
18772
20872
|
const email2 = currentMechanism.email;
|
|
18773
20873
|
store.set({ step: "VerifyingOTP", mechanism: currentMechanism });
|
|
18774
20874
|
try {
|
|
18775
|
-
|
|
18776
|
-
console.log({ resultFromLoginWithOTP });
|
|
20875
|
+
await openfortInstance.auth.logInWithEmailOtp({ email: email2, otp });
|
|
18777
20876
|
await completeLogin(currentMechanism);
|
|
18778
20877
|
} catch (err2) {
|
|
18779
20878
|
const message = "failed to generate account after OTP";
|
|
@@ -18838,7 +20937,7 @@ function createOpenfortProvider(settings) {
|
|
|
18838
20937
|
} else {
|
|
18839
20938
|
const account = await openfortInstance.embeddedWallet.create({
|
|
18840
20939
|
chainType,
|
|
18841
|
-
accountType: N
|
|
20940
|
+
accountType: N.EOA,
|
|
18842
20941
|
recoveryParams: {
|
|
18843
20942
|
recoveryMethod: e$9.AUTOMATIC,
|
|
18844
20943
|
encryptionSession
|
|
@@ -18857,12 +20956,6 @@ function createOpenfortProvider(settings) {
|
|
|
18857
20956
|
throw new Error("Openfort not initialized");
|
|
18858
20957
|
}
|
|
18859
20958
|
const signature = await openfortInstance.embeddedWallet.signMessage(message);
|
|
18860
|
-
const signatureUsingMessageHash = await openfortInstance.embeddedWallet.signMessage(message, { hashMessage: true });
|
|
18861
|
-
console.log({
|
|
18862
|
-
signature,
|
|
18863
|
-
signatureUsingMessageHash,
|
|
18864
|
-
privateKey: await openfortInstance.embeddedWallet.exportPrivateKey()
|
|
18865
|
-
});
|
|
18866
20959
|
return fromSignatureToKey(signature);
|
|
18867
20960
|
}
|
|
18868
20961
|
async function generateAccount({ key, mechanism: mechanism2 }) {
|
|
@@ -19204,7 +21297,7 @@ const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
|
|
|
19204
21297
|
].map((n4) => BigInt(n4))))();
|
|
19205
21298
|
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
19206
21299
|
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
19207
|
-
class
|
|
21300
|
+
class SHA5122 extends HashMD2 {
|
|
19208
21301
|
constructor() {
|
|
19209
21302
|
super(128, 64, 16, false);
|
|
19210
21303
|
this.Ah = 1779033703 | 0;
|
|
@@ -19316,7 +21409,7 @@ class SHA512 extends HashMD2 {
|
|
|
19316
21409
|
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
19317
21410
|
}
|
|
19318
21411
|
}
|
|
19319
|
-
const sha512 = /* @__PURE__ */ wrapConstructor(() => new
|
|
21412
|
+
const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA5122());
|
|
19320
21413
|
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
19321
21414
|
function isBytes(a5) {
|
|
19322
21415
|
return a5 instanceof Uint8Array || ArrayBuffer.isView(a5) && a5.constructor.name === "Uint8Array";
|
|
@@ -19501,7 +21594,7 @@ const genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @
|
|
|
19501
21594
|
const base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
19502
21595
|
const createBase58check = (sha2562) => /* @__PURE__ */ chain(checksum(4, (data) => sha2562(sha2562(data))), base58);
|
|
19503
21596
|
/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
|
|
19504
|
-
const
|
|
21597
|
+
const Point2 = secp256k1.ProjectivePoint;
|
|
19505
21598
|
const base58check = createBase58check(sha256);
|
|
19506
21599
|
function bytesToNumber(bytes) {
|
|
19507
21600
|
abytes$1(bytes);
|
|
@@ -19563,11 +21656,11 @@ class HDKey {
|
|
|
19563
21656
|
if (8 * seed.length < 128 || 8 * seed.length > 512) {
|
|
19564
21657
|
throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got " + seed.length);
|
|
19565
21658
|
}
|
|
19566
|
-
const
|
|
21659
|
+
const I2 = hmac(sha512, MASTER_SECRET, seed);
|
|
19567
21660
|
return new HDKey({
|
|
19568
21661
|
versions,
|
|
19569
|
-
chainCode:
|
|
19570
|
-
privateKey:
|
|
21662
|
+
chainCode: I2.slice(32),
|
|
21663
|
+
privateKey: I2.slice(0, 32)
|
|
19571
21664
|
});
|
|
19572
21665
|
}
|
|
19573
21666
|
static fromExtendedKey(base58key, versions = BITCOIN_VERSIONS) {
|
|
@@ -19624,7 +21717,7 @@ class HDKey {
|
|
|
19624
21717
|
this.privKeyBytes = numberToBytes(this.privKey);
|
|
19625
21718
|
this.pubKey = secp256k1.getPublicKey(opt.privateKey, true);
|
|
19626
21719
|
} else if (opt.publicKey) {
|
|
19627
|
-
this.pubKey =
|
|
21720
|
+
this.pubKey = Point2.fromHex(opt.publicKey).toRawBytes(true);
|
|
19628
21721
|
} else {
|
|
19629
21722
|
throw new Error("HDKey: no public or private key provided");
|
|
19630
21723
|
}
|
|
@@ -19669,9 +21762,9 @@ class HDKey {
|
|
|
19669
21762
|
} else {
|
|
19670
21763
|
data = concatBytes$1(this.pubKey, data);
|
|
19671
21764
|
}
|
|
19672
|
-
const
|
|
19673
|
-
const childTweak = bytesToNumber(
|
|
19674
|
-
const chainCode =
|
|
21765
|
+
const I2 = hmac(sha512, this.chainCode, data);
|
|
21766
|
+
const childTweak = bytesToNumber(I2.slice(0, 32));
|
|
21767
|
+
const chainCode = I2.slice(32);
|
|
19675
21768
|
if (!secp256k1.utils.isValidPrivateKey(childTweak)) {
|
|
19676
21769
|
throw new Error("Tweak bigger than curve order");
|
|
19677
21770
|
}
|
|
@@ -19690,8 +21783,8 @@ class HDKey {
|
|
|
19690
21783
|
}
|
|
19691
21784
|
opt.privateKey = added;
|
|
19692
21785
|
} else {
|
|
19693
|
-
const added =
|
|
19694
|
-
if (added.equals(
|
|
21786
|
+
const added = Point2.fromHex(this.pubKey).add(Point2.fromPrivateKey(childTweak));
|
|
21787
|
+
if (added.equals(Point2.ZERO)) {
|
|
19695
21788
|
throw new Error("The tweak was equal to negative P, which made the result key invalid");
|
|
19696
21789
|
}
|
|
19697
21790
|
opt.publicKey = added.toRawBytes(true);
|
|
@@ -19978,320 +22071,6 @@ class Keccak2 extends Hash2 {
|
|
|
19978
22071
|
}
|
|
19979
22072
|
const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak2(blockLen, suffix, outputLen));
|
|
19980
22073
|
const keccak_256 = /* @__PURE__ */ gen(1, 136, 256 / 8);
|
|
19981
|
-
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
19982
|
-
const B256 = 2n ** 256n;
|
|
19983
|
-
const P2 = B256 - 0x1000003d1n;
|
|
19984
|
-
const N = B256 - 0x14551231950b75fc4402da1732fc9bebfn;
|
|
19985
|
-
const Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n;
|
|
19986
|
-
const Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;
|
|
19987
|
-
const CURVE = {
|
|
19988
|
-
a: 0n,
|
|
19989
|
-
b: 7n
|
|
19990
|
-
};
|
|
19991
|
-
const fLen = 32;
|
|
19992
|
-
const curve = (x2) => M2(M2(x2 * x2) * x2 + CURVE.b);
|
|
19993
|
-
const err = (m2 = "") => {
|
|
19994
|
-
throw new Error(m2);
|
|
19995
|
-
};
|
|
19996
|
-
const isB = (n4) => typeof n4 === "bigint";
|
|
19997
|
-
const isS = (s5) => typeof s5 === "string";
|
|
19998
|
-
const fe = (n4) => isB(n4) && 0n < n4 && n4 < P2;
|
|
19999
|
-
const ge = (n4) => isB(n4) && 0n < n4 && n4 < N;
|
|
20000
|
-
const isu8 = (a5) => a5 instanceof Uint8Array || ArrayBuffer.isView(a5) && a5.constructor.name === "Uint8Array";
|
|
20001
|
-
const au8 = (a5, l3) => (
|
|
20002
|
-
// assert is Uint8Array (of specific length)
|
|
20003
|
-
!isu8(a5) || typeof l3 === "number" && l3 > 0 && a5.length !== l3 ? err("Uint8Array expected") : a5
|
|
20004
|
-
);
|
|
20005
|
-
const u8n = (data) => new Uint8Array(data);
|
|
20006
|
-
const toU8 = (a5, len) => au8(isS(a5) ? h2b(a5) : u8n(au8(a5)), len);
|
|
20007
|
-
const M2 = (a5, b2 = P2) => {
|
|
20008
|
-
const r7 = a5 % b2;
|
|
20009
|
-
return r7 >= 0n ? r7 : b2 + r7;
|
|
20010
|
-
};
|
|
20011
|
-
const aPoint = (p5) => p5 instanceof Point ? p5 : err("Point expected");
|
|
20012
|
-
class Point {
|
|
20013
|
-
constructor(px, py, pz) {
|
|
20014
|
-
this.px = px;
|
|
20015
|
-
this.py = py;
|
|
20016
|
-
this.pz = pz;
|
|
20017
|
-
Object.freeze(this);
|
|
20018
|
-
}
|
|
20019
|
-
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
20020
|
-
static fromAffine(p5) {
|
|
20021
|
-
return p5.x === 0n && p5.y === 0n ? I2 : new Point(p5.x, p5.y, 1n);
|
|
20022
|
-
}
|
|
20023
|
-
/** Convert Uint8Array or hex string to Point. */
|
|
20024
|
-
static fromHex(hex) {
|
|
20025
|
-
hex = toU8(hex);
|
|
20026
|
-
let p5 = void 0;
|
|
20027
|
-
const head = hex[0], tail = hex.subarray(1);
|
|
20028
|
-
const x2 = slc(tail, 0, fLen), len = hex.length;
|
|
20029
|
-
if (len === 33 && [2, 3].includes(head)) {
|
|
20030
|
-
if (!fe(x2))
|
|
20031
|
-
err("Point hex invalid: x not FE");
|
|
20032
|
-
let y3 = sqrt(curve(x2));
|
|
20033
|
-
const isYOdd = (y3 & 1n) === 1n;
|
|
20034
|
-
const headOdd = (head & 1) === 1;
|
|
20035
|
-
if (headOdd !== isYOdd)
|
|
20036
|
-
y3 = M2(-y3);
|
|
20037
|
-
p5 = new Point(x2, y3, 1n);
|
|
20038
|
-
}
|
|
20039
|
-
if (len === 65 && head === 4)
|
|
20040
|
-
p5 = new Point(x2, slc(tail, fLen, 2 * fLen), 1n);
|
|
20041
|
-
return p5 ? p5.ok() : err("Point invalid: not on curve");
|
|
20042
|
-
}
|
|
20043
|
-
/** Create point from a private key. */
|
|
20044
|
-
static fromPrivateKey(k2) {
|
|
20045
|
-
return G.mul(toPriv(k2));
|
|
20046
|
-
}
|
|
20047
|
-
get x() {
|
|
20048
|
-
return this.aff().x;
|
|
20049
|
-
}
|
|
20050
|
-
// .x, .y will call expensive toAffine:
|
|
20051
|
-
get y() {
|
|
20052
|
-
return this.aff().y;
|
|
20053
|
-
}
|
|
20054
|
-
// should be used with care.
|
|
20055
|
-
/** Equality check: compare points P&Q. */
|
|
20056
|
-
equals(other) {
|
|
20057
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
20058
|
-
const { px: X2, py: Y2, pz: Z2 } = aPoint(other);
|
|
20059
|
-
const X1Z2 = M2(X1 * Z2), X2Z1 = M2(X2 * Z1);
|
|
20060
|
-
const Y1Z2 = M2(Y1 * Z2), Y2Z1 = M2(Y2 * Z1);
|
|
20061
|
-
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
20062
|
-
}
|
|
20063
|
-
/** Flip point over y coordinate. */
|
|
20064
|
-
negate() {
|
|
20065
|
-
return new Point(this.px, M2(-this.py), this.pz);
|
|
20066
|
-
}
|
|
20067
|
-
/** Point doubling: P+P, complete formula. */
|
|
20068
|
-
double() {
|
|
20069
|
-
return this.add(this);
|
|
20070
|
-
}
|
|
20071
|
-
/**
|
|
20072
|
-
* Point addition: P+Q, complete, exception-free formula
|
|
20073
|
-
* (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
|
|
20074
|
-
* Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
20075
|
-
*/
|
|
20076
|
-
add(other) {
|
|
20077
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
20078
|
-
const { px: X2, py: Y2, pz: Z2 } = aPoint(other);
|
|
20079
|
-
const { a: a5, b: b2 } = CURVE;
|
|
20080
|
-
let X3 = 0n, Y3 = 0n, Z3 = 0n;
|
|
20081
|
-
const b3 = M2(b2 * 3n);
|
|
20082
|
-
let t0 = M2(X1 * X2), t1 = M2(Y1 * Y2), t22 = M2(Z1 * Z2), t32 = M2(X1 + Y1);
|
|
20083
|
-
let t42 = M2(X2 + Y2);
|
|
20084
|
-
t32 = M2(t32 * t42);
|
|
20085
|
-
t42 = M2(t0 + t1);
|
|
20086
|
-
t32 = M2(t32 - t42);
|
|
20087
|
-
t42 = M2(X1 + Z1);
|
|
20088
|
-
let t52 = M2(X2 + Z2);
|
|
20089
|
-
t42 = M2(t42 * t52);
|
|
20090
|
-
t52 = M2(t0 + t22);
|
|
20091
|
-
t42 = M2(t42 - t52);
|
|
20092
|
-
t52 = M2(Y1 + Z1);
|
|
20093
|
-
X3 = M2(Y2 + Z2);
|
|
20094
|
-
t52 = M2(t52 * X3);
|
|
20095
|
-
X3 = M2(t1 + t22);
|
|
20096
|
-
t52 = M2(t52 - X3);
|
|
20097
|
-
Z3 = M2(a5 * t42);
|
|
20098
|
-
X3 = M2(b3 * t22);
|
|
20099
|
-
Z3 = M2(X3 + Z3);
|
|
20100
|
-
X3 = M2(t1 - Z3);
|
|
20101
|
-
Z3 = M2(t1 + Z3);
|
|
20102
|
-
Y3 = M2(X3 * Z3);
|
|
20103
|
-
t1 = M2(t0 + t0);
|
|
20104
|
-
t1 = M2(t1 + t0);
|
|
20105
|
-
t22 = M2(a5 * t22);
|
|
20106
|
-
t42 = M2(b3 * t42);
|
|
20107
|
-
t1 = M2(t1 + t22);
|
|
20108
|
-
t22 = M2(t0 - t22);
|
|
20109
|
-
t22 = M2(a5 * t22);
|
|
20110
|
-
t42 = M2(t42 + t22);
|
|
20111
|
-
t0 = M2(t1 * t42);
|
|
20112
|
-
Y3 = M2(Y3 + t0);
|
|
20113
|
-
t0 = M2(t52 * t42);
|
|
20114
|
-
X3 = M2(t32 * X3);
|
|
20115
|
-
X3 = M2(X3 - t0);
|
|
20116
|
-
t0 = M2(t32 * t1);
|
|
20117
|
-
Z3 = M2(t52 * Z3);
|
|
20118
|
-
Z3 = M2(Z3 + t0);
|
|
20119
|
-
return new Point(X3, Y3, Z3);
|
|
20120
|
-
}
|
|
20121
|
-
mul(n4, safe = true) {
|
|
20122
|
-
if (!safe && n4 === 0n)
|
|
20123
|
-
return I2;
|
|
20124
|
-
if (!ge(n4))
|
|
20125
|
-
err("scalar invalid");
|
|
20126
|
-
if (this.equals(G))
|
|
20127
|
-
return wNAF(n4).p;
|
|
20128
|
-
let p5 = I2, f3 = G;
|
|
20129
|
-
for (let d2 = this; n4 > 0n; d2 = d2.double(), n4 >>= 1n) {
|
|
20130
|
-
if (n4 & 1n)
|
|
20131
|
-
p5 = p5.add(d2);
|
|
20132
|
-
else if (safe)
|
|
20133
|
-
f3 = f3.add(d2);
|
|
20134
|
-
}
|
|
20135
|
-
return p5;
|
|
20136
|
-
}
|
|
20137
|
-
mulAddQUns(R2, u1, u22) {
|
|
20138
|
-
return this.mul(u1, false).add(R2.mul(u22, false)).ok();
|
|
20139
|
-
}
|
|
20140
|
-
// to private keys. Doesn't use Shamir trick
|
|
20141
|
-
/** Convert point to 2d xy affine point. (x, y, z) ∋ (x=x/z, y=y/z) */
|
|
20142
|
-
toAffine() {
|
|
20143
|
-
const { px: x2, py: y3, pz: z2 } = this;
|
|
20144
|
-
if (this.equals(I2))
|
|
20145
|
-
return { x: 0n, y: 0n };
|
|
20146
|
-
if (z2 === 1n)
|
|
20147
|
-
return { x: x2, y: y3 };
|
|
20148
|
-
const iz = inv(z2, P2);
|
|
20149
|
-
if (M2(z2 * iz) !== 1n)
|
|
20150
|
-
err("inverse invalid");
|
|
20151
|
-
return { x: M2(x2 * iz), y: M2(y3 * iz) };
|
|
20152
|
-
}
|
|
20153
|
-
/** Checks if the point is valid and on-curve. */
|
|
20154
|
-
assertValidity() {
|
|
20155
|
-
const { x: x2, y: y3 } = this.aff();
|
|
20156
|
-
if (!fe(x2) || !fe(y3))
|
|
20157
|
-
err("Point invalid: x or y");
|
|
20158
|
-
return M2(y3 * y3) === curve(x2) ? (
|
|
20159
|
-
// y² = x³ + ax + b, must be equal
|
|
20160
|
-
this
|
|
20161
|
-
) : err("Point invalid: not on curve");
|
|
20162
|
-
}
|
|
20163
|
-
multiply(n4) {
|
|
20164
|
-
return this.mul(n4);
|
|
20165
|
-
}
|
|
20166
|
-
// Aliases to compress code
|
|
20167
|
-
aff() {
|
|
20168
|
-
return this.toAffine();
|
|
20169
|
-
}
|
|
20170
|
-
ok() {
|
|
20171
|
-
return this.assertValidity();
|
|
20172
|
-
}
|
|
20173
|
-
toHex(isCompressed = true) {
|
|
20174
|
-
const { x: x2, y: y3 } = this.aff();
|
|
20175
|
-
const head = isCompressed ? (y3 & 1n) === 0n ? "02" : "03" : "04";
|
|
20176
|
-
return head + n2h(x2) + (isCompressed ? "" : n2h(y3));
|
|
20177
|
-
}
|
|
20178
|
-
toRawBytes(isCompressed = true) {
|
|
20179
|
-
return h2b(this.toHex(isCompressed));
|
|
20180
|
-
}
|
|
20181
|
-
}
|
|
20182
|
-
Point.BASE = new Point(Gx, Gy, 1n);
|
|
20183
|
-
Point.ZERO = new Point(0n, 1n, 0n);
|
|
20184
|
-
const { BASE: G, ZERO: I2 } = Point;
|
|
20185
|
-
const padh = (n4, pad) => n4.toString(16).padStart(pad, "0");
|
|
20186
|
-
const b2h = (b2) => Array.from(au8(b2)).map((e4) => padh(e4, 2)).join("");
|
|
20187
|
-
const C2 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
20188
|
-
const _ch = (ch) => {
|
|
20189
|
-
if (ch >= C2._0 && ch <= C2._9)
|
|
20190
|
-
return ch - C2._0;
|
|
20191
|
-
if (ch >= C2.A && ch <= C2.F)
|
|
20192
|
-
return ch - (C2.A - 10);
|
|
20193
|
-
if (ch >= C2.a && ch <= C2.f)
|
|
20194
|
-
return ch - (C2.a - 10);
|
|
20195
|
-
return;
|
|
20196
|
-
};
|
|
20197
|
-
const h2b = (hex) => {
|
|
20198
|
-
const e4 = "hex invalid";
|
|
20199
|
-
if (!isS(hex))
|
|
20200
|
-
return err(e4);
|
|
20201
|
-
const hl = hex.length, al = hl / 2;
|
|
20202
|
-
if (hl % 2)
|
|
20203
|
-
return err(e4);
|
|
20204
|
-
const array = u8n(al);
|
|
20205
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
20206
|
-
const n1 = _ch(hex.charCodeAt(hi));
|
|
20207
|
-
const n22 = _ch(hex.charCodeAt(hi + 1));
|
|
20208
|
-
if (n1 === void 0 || n22 === void 0)
|
|
20209
|
-
return err(e4);
|
|
20210
|
-
array[ai] = n1 * 16 + n22;
|
|
20211
|
-
}
|
|
20212
|
-
return array;
|
|
20213
|
-
};
|
|
20214
|
-
const b2n = (b2) => BigInt("0x" + (b2h(b2) || "0"));
|
|
20215
|
-
const slc = (b2, from, to) => b2n(b2.slice(from, to));
|
|
20216
|
-
const n2b = (num) => {
|
|
20217
|
-
return isB(num) && num >= 0n && num < B256 ? h2b(padh(num, 2 * fLen)) : err("bigint expected");
|
|
20218
|
-
};
|
|
20219
|
-
const n2h = (num) => b2h(n2b(num));
|
|
20220
|
-
const inv = (num, md) => {
|
|
20221
|
-
if (num === 0n || md <= 0n)
|
|
20222
|
-
err("no inverse n=" + num + " mod=" + md);
|
|
20223
|
-
let a5 = M2(num, md), b2 = md, x2 = 0n, u4 = 1n;
|
|
20224
|
-
while (a5 !== 0n) {
|
|
20225
|
-
const q2 = b2 / a5, r7 = b2 % a5;
|
|
20226
|
-
const m2 = x2 - u4 * q2;
|
|
20227
|
-
b2 = a5, a5 = r7, x2 = u4, u4 = m2;
|
|
20228
|
-
}
|
|
20229
|
-
return b2 === 1n ? M2(x2, md) : err("no inverse");
|
|
20230
|
-
};
|
|
20231
|
-
const sqrt = (n4) => {
|
|
20232
|
-
let r7 = 1n;
|
|
20233
|
-
for (let num = n4, e4 = (P2 + 1n) / 4n; e4 > 0n; e4 >>= 1n) {
|
|
20234
|
-
if (e4 & 1n)
|
|
20235
|
-
r7 = r7 * num % P2;
|
|
20236
|
-
num = num * num % P2;
|
|
20237
|
-
}
|
|
20238
|
-
return M2(r7 * r7) === n4 ? r7 : err("sqrt invalid");
|
|
20239
|
-
};
|
|
20240
|
-
const toPriv = (p5) => {
|
|
20241
|
-
if (!isB(p5))
|
|
20242
|
-
p5 = b2n(toU8(p5, fLen));
|
|
20243
|
-
return ge(p5) ? p5 : err("private key invalid 3");
|
|
20244
|
-
};
|
|
20245
|
-
const getPublicKey = (privKey, isCompressed = true) => {
|
|
20246
|
-
return Point.fromPrivateKey(privKey).toRawBytes(isCompressed);
|
|
20247
|
-
};
|
|
20248
|
-
const W = 8;
|
|
20249
|
-
const precompute = () => {
|
|
20250
|
-
const points = [];
|
|
20251
|
-
const windows = 256 / W + 1;
|
|
20252
|
-
let p5 = G, b2 = p5;
|
|
20253
|
-
for (let w2 = 0; w2 < windows; w2++) {
|
|
20254
|
-
b2 = p5;
|
|
20255
|
-
points.push(b2);
|
|
20256
|
-
for (let i3 = 1; i3 < 2 ** (W - 1); i3++) {
|
|
20257
|
-
b2 = b2.add(p5);
|
|
20258
|
-
points.push(b2);
|
|
20259
|
-
}
|
|
20260
|
-
p5 = b2.double();
|
|
20261
|
-
}
|
|
20262
|
-
return points;
|
|
20263
|
-
};
|
|
20264
|
-
let Gpows = void 0;
|
|
20265
|
-
const wNAF = (n4) => {
|
|
20266
|
-
const comp = Gpows || (Gpows = precompute());
|
|
20267
|
-
const neg = (cnd, p6) => {
|
|
20268
|
-
let n5 = p6.negate();
|
|
20269
|
-
return cnd ? n5 : p6;
|
|
20270
|
-
};
|
|
20271
|
-
let p5 = I2, f3 = G;
|
|
20272
|
-
const windows = 1 + 256 / W;
|
|
20273
|
-
const wsize = 2 ** (W - 1);
|
|
20274
|
-
const mask = BigInt(2 ** W - 1);
|
|
20275
|
-
const maxNum = 2 ** W;
|
|
20276
|
-
const shiftBy = BigInt(W);
|
|
20277
|
-
for (let w2 = 0; w2 < windows; w2++) {
|
|
20278
|
-
const off = w2 * wsize;
|
|
20279
|
-
let wbits = Number(n4 & mask);
|
|
20280
|
-
n4 >>= shiftBy;
|
|
20281
|
-
if (wbits > wsize) {
|
|
20282
|
-
wbits -= maxNum;
|
|
20283
|
-
n4 += 1n;
|
|
20284
|
-
}
|
|
20285
|
-
const off1 = off, off2 = off + Math.abs(wbits) - 1;
|
|
20286
|
-
const cnd1 = w2 % 2 !== 0, cnd2 = wbits < 0;
|
|
20287
|
-
if (wbits === 0) {
|
|
20288
|
-
f3 = f3.add(neg(cnd1, comp[off1]));
|
|
20289
|
-
} else {
|
|
20290
|
-
p5 = p5.add(neg(cnd2, comp[off2]));
|
|
20291
|
-
}
|
|
20292
|
-
}
|
|
20293
|
-
return { p: p5, f: f3 };
|
|
20294
|
-
};
|
|
20295
22074
|
const ethHexStartRe = /^0[xX]/;
|
|
20296
22075
|
function strip0x(hex) {
|
|
20297
22076
|
return hex.replace(ethHexStartRe, "");
|
|
@@ -21252,4 +23031,4 @@ export {
|
|
|
21252
23031
|
process$1 as p,
|
|
21253
23032
|
splitSignature as s
|
|
21254
23033
|
};
|
|
21255
|
-
//# sourceMappingURL=App-
|
|
23034
|
+
//# sourceMappingURL=App-jiH5KsZN.js.map
|