bitcoin-wallet-connector 0.1.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/README.md +208 -0
- package/lib/BitcoinConnectionProvider.d.ts +23 -0
- package/lib/BitcoinWalletAdapterConnector-Bq835yj0.mjs +123 -0
- package/lib/BitcoinWalletAdapterConnector-Bq835yj0.mjs.map +1 -0
- package/lib/BitcoinWalletAdapterConnector-DMef0iHV.js +2 -0
- package/lib/BitcoinWalletAdapterConnector-DMef0iHV.js.map +1 -0
- package/lib/BitcoinWalletAdapterConnector.d.ts +30 -0
- package/lib/BitgetWalletAdapter.impl-C_HLO7Oi.mjs +10 -0
- package/lib/BitgetWalletAdapter.impl-C_HLO7Oi.mjs.map +1 -0
- package/lib/BitgetWalletAdapter.impl-CxnKMf7U.js +2 -0
- package/lib/BitgetWalletAdapter.impl-CxnKMf7U.js.map +1 -0
- package/lib/LeatherWalletAdapter.impl-B2QgX_tO.js +2 -0
- package/lib/LeatherWalletAdapter.impl-B2QgX_tO.js.map +1 -0
- package/lib/LeatherWalletAdapter.impl-RUYx555r.mjs +184 -0
- package/lib/LeatherWalletAdapter.impl-RUYx555r.mjs.map +1 -0
- package/lib/MagicEdenWalletAdapter.impl-CrA6SGvG.mjs +235 -0
- package/lib/MagicEdenWalletAdapter.impl-CrA6SGvG.mjs.map +1 -0
- package/lib/MagicEdenWalletAdapter.impl-Di3Nu2S5.js +2 -0
- package/lib/MagicEdenWalletAdapter.impl-Di3Nu2S5.js.map +1 -0
- package/lib/OkxWalletAdapter.impl-BepoUL1B.mjs +67 -0
- package/lib/OkxWalletAdapter.impl-BepoUL1B.mjs.map +1 -0
- package/lib/OkxWalletAdapter.impl-C8kesjGu.js +2 -0
- package/lib/OkxWalletAdapter.impl-C8kesjGu.js.map +1 -0
- package/lib/UnisatCompatibleWalletAdapterImpl-Cq2Oqk1b.js +2 -0
- package/lib/UnisatCompatibleWalletAdapterImpl-Cq2Oqk1b.js.map +1 -0
- package/lib/UnisatCompatibleWalletAdapterImpl-M38FqkZI.mjs +137 -0
- package/lib/UnisatCompatibleWalletAdapterImpl-M38FqkZI.mjs.map +1 -0
- package/lib/UnisatWalletAdapter.impl-CJB22se8.mjs +14 -0
- package/lib/UnisatWalletAdapter.impl-CJB22se8.mjs.map +1 -0
- package/lib/UnisatWalletAdapter.impl-EISvxdpc.js +2 -0
- package/lib/UnisatWalletAdapter.impl-EISvxdpc.js.map +1 -0
- package/lib/WalletAdapters.types-CnvOqHFH.mjs +32 -0
- package/lib/WalletAdapters.types-CnvOqHFH.mjs.map +1 -0
- package/lib/WalletAdapters.types-De_x1lzr.js +2 -0
- package/lib/WalletAdapters.types-De_x1lzr.js.map +1 -0
- package/lib/WalletAdapters.types.d.ts +110 -0
- package/lib/XverseCompatibleWalletAdapterImpl-Bf-BK5VK.js +2 -0
- package/lib/XverseCompatibleWalletAdapterImpl-Bf-BK5VK.js.map +1 -0
- package/lib/XverseCompatibleWalletAdapterImpl-DXKnO_-V.mjs +151 -0
- package/lib/XverseCompatibleWalletAdapterImpl-DXKnO_-V.mjs.map +1 -0
- package/lib/XverseWalletAdapter.impl-CZO0RQva.mjs +105 -0
- package/lib/XverseWalletAdapter.impl-CZO0RQva.mjs.map +1 -0
- package/lib/XverseWalletAdapter.impl-lJwMi-Iv.js +2 -0
- package/lib/XverseWalletAdapter.impl-lJwMi-Iv.js.map +1 -0
- package/lib/adapters/BitgetWalletAdapter.d.ts +2 -0
- package/lib/adapters/BitgetWalletAdapter.impl.d.ts +8 -0
- package/lib/adapters/LeatherWalletAdapter.d.ts +2 -0
- package/lib/adapters/LeatherWalletAdapter.impl.d.ts +41 -0
- package/lib/adapters/MagicEdenWalletAdapter.d.ts +11 -0
- package/lib/adapters/MagicEdenWalletAdapter.impl.d.ts +22 -0
- package/lib/adapters/MockAddressWalletAdapter.d.ts +33 -0
- package/lib/adapters/OkxWalletAdapter.d.ts +2 -0
- package/lib/adapters/OkxWalletAdapter.impl.d.ts +51 -0
- package/lib/adapters/UnisatWalletAdapter.d.ts +2 -0
- package/lib/adapters/UnisatWalletAdapter.impl.d.ts +14 -0
- package/lib/adapters/XverseWalletAdapter.d.ts +3 -0
- package/lib/adapters/XverseWalletAdapter.impl.d.ts +14 -0
- package/lib/adapters/index.d.ts +7 -0
- package/lib/adapters.js +2 -0
- package/lib/adapters.js.map +1 -0
- package/lib/adapters.mjs +11 -0
- package/lib/adapters.mjs.map +1 -0
- package/lib/bitget-C7oB4Ffq.mjs +5 -0
- package/lib/bitget-C7oB4Ffq.mjs.map +1 -0
- package/lib/bitget-DXnsxx_y.js +2 -0
- package/lib/bitget-DXnsxx_y.js.map +1 -0
- package/lib/index-CaV3F1Nm.js +424 -0
- package/lib/index-CaV3F1Nm.js.map +1 -0
- package/lib/index-CcQUdePc.mjs +12224 -0
- package/lib/index-CcQUdePc.mjs.map +1 -0
- package/lib/index-D7YwhNAG.mjs +3946 -0
- package/lib/index-D7YwhNAG.mjs.map +1 -0
- package/lib/index-Zx0KcpYx.js +2 -0
- package/lib/index-Zx0KcpYx.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +20 -0
- package/lib/index.mjs.map +1 -0
- package/lib/leather-BoQG_CPn.mjs +5 -0
- package/lib/leather-BoQG_CPn.mjs.map +1 -0
- package/lib/leather-DJ8nWmM8.js +2 -0
- package/lib/leather-DJ8nWmM8.js.map +1 -0
- package/lib/magiceden-B36CEQa6.js +2 -0
- package/lib/magiceden-B36CEQa6.js.map +1 -0
- package/lib/magiceden-Cg7d3agI.mjs +5 -0
- package/lib/magiceden-Cg7d3agI.mjs.map +1 -0
- package/lib/misc-B5EWO_dn.mjs +10 -0
- package/lib/misc-B5EWO_dn.mjs.map +1 -0
- package/lib/misc-CigR0RqC.js +2 -0
- package/lib/misc-CigR0RqC.js.map +1 -0
- package/lib/okx-ChwzM0dK.js +2 -0
- package/lib/okx-ChwzM0dK.js.map +1 -0
- package/lib/okx-DWbHwazu.mjs +5 -0
- package/lib/okx-DWbHwazu.mjs.map +1 -0
- package/lib/react.d.ts +2 -0
- package/lib/react.js +2 -0
- package/lib/react.js.map +1 -0
- package/lib/react.mjs +128 -0
- package/lib/react.mjs.map +1 -0
- package/lib/transaction-CiLOYSE_.mjs +1063 -0
- package/lib/transaction-CiLOYSE_.mjs.map +1 -0
- package/lib/transaction-CzdnbXSo.js +2 -0
- package/lib/transaction-CzdnbXSo.js.map +1 -0
- package/lib/unisat-BvZW5h0U.js +2 -0
- package/lib/unisat-BvZW5h0U.js.map +1 -0
- package/lib/unisat-pLgab4nG.mjs +5 -0
- package/lib/unisat-pLgab4nG.mjs.map +1 -0
- package/lib/utils/StateChannel.d.ts +14 -0
- package/lib/utils/UnisatCompatibleWalletAdapterImpl.d.ts +99 -0
- package/lib/utils/XverseCompatibleWalletAdapterImpl.d.ts +80 -0
- package/lib/utils/XverseCompatibleWalletAdapterImpl_legacy.d.ts +44 -0
- package/lib/utils/bitcoinAddressHelpers.d.ts +14 -0
- package/lib/utils/bitcoinNetworkHelpers.d.ts +4 -0
- package/lib/utils/createAdapterAvailability.d.ts +15 -0
- package/lib/utils/error.d.ts +6 -0
- package/lib/utils/misc.d.ts +3 -0
- package/lib/xverse-IKOHyGi-.js +2 -0
- package/lib/xverse-IKOHyGi-.js.map +1 -0
- package/lib/xverse-iHLNanCB.mjs +5 -0
- package/lib/xverse-iHLNanCB.mjs.map +1 -0
- package/package.json +86 -0
- package/src/BitcoinConnectionProvider.stories.tsx +329 -0
- package/src/BitcoinConnectionProvider.tsx +234 -0
- package/src/BitcoinWalletAdapterConnector.ts +166 -0
- package/src/WalletAdapters.types.ts +154 -0
- package/src/_/bitget.png +0 -0
- package/src/_/leather.svg +4 -0
- package/src/_/magiceden.png +0 -0
- package/src/_/okx.png +0 -0
- package/src/_/unisat.svg +31 -0
- package/src/_/xverse.png +0 -0
- package/src/adapters/BitgetWalletAdapter.impl.ts +22 -0
- package/src/adapters/BitgetWalletAdapter.ts +44 -0
- package/src/adapters/LeatherWalletAdapter.impl.ts +324 -0
- package/src/adapters/LeatherWalletAdapter.ts +35 -0
- package/src/adapters/MagicEdenWalletAdapter.impl.ts +139 -0
- package/src/adapters/MagicEdenWalletAdapter.ts +51 -0
- package/src/adapters/MockAddressWalletAdapter.ts +199 -0
- package/src/adapters/OkxWalletAdapter.impl.ts +168 -0
- package/src/adapters/OkxWalletAdapter.ts +37 -0
- package/src/adapters/UnisatWalletAdapter.impl.ts +32 -0
- package/src/adapters/UnisatWalletAdapter.ts +50 -0
- package/src/adapters/XverseWalletAdapter.impl.ts +150 -0
- package/src/adapters/XverseWalletAdapter.ts +37 -0
- package/src/adapters/index.ts +7 -0
- package/src/env.d.ts +9 -0
- package/src/index.ts +3 -0
- package/src/react.ts +9 -0
- package/src/utils/StateChannel.ts +39 -0
- package/src/utils/UnisatCompatibleWalletAdapterImpl.ts +342 -0
- package/src/utils/XverseCompatibleWalletAdapterImpl.ts +288 -0
- package/src/utils/XverseCompatibleWalletAdapterImpl_legacy.ts +278 -0
- package/src/utils/bitcoinAddressHelpers.ts +132 -0
- package/src/utils/bitcoinNetworkHelpers.ts +17 -0
- package/src/utils/createAdapterAvailability.ts +92 -0
- package/src/utils/error.ts +13 -0
- package/src/utils/misc.ts +10 -0
|
@@ -0,0 +1,3946 @@
|
|
|
1
|
+
import { a as dt, B as Nt, b as zt, W as er } from "./WalletAdapters.types-CnvOqHFH.mjs";
|
|
2
|
+
function Pt({
|
|
3
|
+
getPrecondition: t,
|
|
4
|
+
initializer: e,
|
|
5
|
+
pollIntervalMs: n = 300
|
|
6
|
+
}) {
|
|
7
|
+
let r = null, o = null, s = !1;
|
|
8
|
+
const i = /* @__PURE__ */ new Set(), c = () => {
|
|
9
|
+
o != null && (clearInterval(o), o = null);
|
|
10
|
+
}, a = (u) => {
|
|
11
|
+
r = u;
|
|
12
|
+
for (const g of i)
|
|
13
|
+
g(u);
|
|
14
|
+
}, f = async () => {
|
|
15
|
+
if (r != null || s) return;
|
|
16
|
+
const u = t();
|
|
17
|
+
if (u != null) {
|
|
18
|
+
s = !0;
|
|
19
|
+
try {
|
|
20
|
+
const g = await e(u.value);
|
|
21
|
+
a(g), c();
|
|
22
|
+
} catch (g) {
|
|
23
|
+
console.warn("[WalletAdapter] Failed to initialize adapter", g);
|
|
24
|
+
} finally {
|
|
25
|
+
s = !1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, d = () => {
|
|
29
|
+
r == null && (f(), !(r != null || o != null) && (o = setInterval(() => {
|
|
30
|
+
f();
|
|
31
|
+
}, n)));
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
subscribe: (u) => r != null ? (u(r), { unsubscribe: () => {
|
|
35
|
+
} }) : (i.add(u), d(), {
|
|
36
|
+
unsubscribe: () => {
|
|
37
|
+
i.delete(u), i.size === 0 && c();
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const Pn = "bitget.bitcoin", _n = {
|
|
43
|
+
name: "Bitget",
|
|
44
|
+
iconUrl: import("./bitget-C7oB4Ffq.mjs").then((t) => t.default),
|
|
45
|
+
websiteUrl: "https://web3.bitget.com/",
|
|
46
|
+
downloadUrl: "https://web3.bitget.com/en/wallet-download"
|
|
47
|
+
}, Hn = Pt({
|
|
48
|
+
getPrecondition: () => window.bitkeep?.unisat == null ? null : { value: window.bitkeep.unisat },
|
|
49
|
+
initializer: async (t) => {
|
|
50
|
+
const { BitgetWalletAdapterImpl: e } = await import("./BitgetWalletAdapter.impl-C_HLO7Oi.mjs");
|
|
51
|
+
return new e(t);
|
|
52
|
+
}
|
|
53
|
+
}), Qs = {
|
|
54
|
+
adapterId: Pn,
|
|
55
|
+
metadata: _n,
|
|
56
|
+
getAdapter: () => Hn
|
|
57
|
+
}, Ln = "LeatherProvider.BitcoinProvider", Tn = {
|
|
58
|
+
name: "Leather",
|
|
59
|
+
iconUrl: import("./leather-BoQG_CPn.mjs").then((t) => t.default),
|
|
60
|
+
websiteUrl: "https://leather.io/",
|
|
61
|
+
downloadUrl: "https://leather.io/wallet"
|
|
62
|
+
}, Nn = Pt({
|
|
63
|
+
getPrecondition: () => {
|
|
64
|
+
const t = window.LeatherProvider?.request;
|
|
65
|
+
return t == null ? null : { value: t };
|
|
66
|
+
},
|
|
67
|
+
initializer: async (t) => {
|
|
68
|
+
const { LeatherWalletAdapterImpl: e } = await import("./LeatherWalletAdapter.impl-RUYx555r.mjs");
|
|
69
|
+
return new e(t);
|
|
70
|
+
}
|
|
71
|
+
}), Js = {
|
|
72
|
+
adapterId: Ln,
|
|
73
|
+
metadata: Tn,
|
|
74
|
+
getAdapter: () => Nn
|
|
75
|
+
}, Cn = "magiceden.bitcoin", Dn = (t) => Pt({
|
|
76
|
+
getPrecondition: () => {
|
|
77
|
+
const e = window.magicEden?.bitcoin;
|
|
78
|
+
return e?.isMagicEden ? { value: e } : null;
|
|
79
|
+
},
|
|
80
|
+
initializer: async (e) => {
|
|
81
|
+
const { MagicEdenWalletAdapterImpl: n } = await import("./MagicEdenWalletAdapter.impl-CrA6SGvG.mjs");
|
|
82
|
+
return new n(t, e);
|
|
83
|
+
}
|
|
84
|
+
}), ti = (t) => {
|
|
85
|
+
const e = Dn(t);
|
|
86
|
+
return {
|
|
87
|
+
adapterId: Cn,
|
|
88
|
+
/**
|
|
89
|
+
* https://docs-wallet.magiceden.io/resources/logos-and-brand-assets
|
|
90
|
+
*/
|
|
91
|
+
metadata: {
|
|
92
|
+
name: "Magic Eden",
|
|
93
|
+
iconUrl: import("./magiceden-Cg7d3agI.mjs").then((n) => n.default),
|
|
94
|
+
websiteUrl: "https://wallet.magiceden.io/",
|
|
95
|
+
downloadUrl: "https://wallet.magiceden.io/download"
|
|
96
|
+
},
|
|
97
|
+
getAdapter: () => e
|
|
98
|
+
};
|
|
99
|
+
}, Kn = "okxwallet.bitcoin", Vn = {
|
|
100
|
+
name: "OKX Wallet",
|
|
101
|
+
iconUrl: import("./okx-DWbHwazu.mjs").then((t) => t.default),
|
|
102
|
+
websiteUrl: "https://web3.okx.com/",
|
|
103
|
+
downloadUrl: "https://web3.okx.com/download"
|
|
104
|
+
}, Mn = Pt({
|
|
105
|
+
getPrecondition: () => {
|
|
106
|
+
const t = window.okxwallet?.bitcoin;
|
|
107
|
+
return t == null ? null : { value: t };
|
|
108
|
+
},
|
|
109
|
+
initializer: async (t) => {
|
|
110
|
+
const { OkxWalletAdapterImpl: e } = await import("./OkxWalletAdapter.impl-BepoUL1B.mjs");
|
|
111
|
+
return new e(t);
|
|
112
|
+
}
|
|
113
|
+
}), ei = {
|
|
114
|
+
adapterId: Kn,
|
|
115
|
+
metadata: Vn,
|
|
116
|
+
getAdapter: () => Mn
|
|
117
|
+
}, Wn = "unisat", qn = {
|
|
118
|
+
name: "UniSat",
|
|
119
|
+
/**
|
|
120
|
+
* https://next-cdn.unisat.io/_/2025-v965/UniSat%20Logo.zip
|
|
121
|
+
*/
|
|
122
|
+
iconUrl: import("./unisat-pLgab4nG.mjs").then((t) => t.default),
|
|
123
|
+
websiteUrl: "https://unisat.io/",
|
|
124
|
+
downloadUrl: "https://unisat.io/download"
|
|
125
|
+
}, jn = Pt({
|
|
126
|
+
getPrecondition: () => {
|
|
127
|
+
const t = window.unisat;
|
|
128
|
+
return t == null ? null : { value: t };
|
|
129
|
+
},
|
|
130
|
+
initializer: async (t) => {
|
|
131
|
+
const { UnisatWalletAdapterImpl: e } = await import("./UnisatWalletAdapter.impl-CJB22se8.mjs");
|
|
132
|
+
return new e(t);
|
|
133
|
+
}
|
|
134
|
+
}), ri = {
|
|
135
|
+
adapterId: Wn,
|
|
136
|
+
metadata: qn,
|
|
137
|
+
getAdapter: () => jn
|
|
138
|
+
}, Sr = "XverseProviders.BitcoinProvider", Fn = {
|
|
139
|
+
name: "Xverse",
|
|
140
|
+
iconUrl: import("./xverse-iHLNanCB.mjs").then((t) => t.default),
|
|
141
|
+
websiteUrl: "https://xverse.app/",
|
|
142
|
+
downloadUrl: "https://www.xverse.app/download"
|
|
143
|
+
}, Zn = Pt({
|
|
144
|
+
getPrecondition: () => {
|
|
145
|
+
const t = (window.btc_providers ?? []).find(
|
|
146
|
+
(e) => e.id === Sr
|
|
147
|
+
);
|
|
148
|
+
return t == null ? null : { value: t };
|
|
149
|
+
},
|
|
150
|
+
initializer: async () => {
|
|
151
|
+
const { XverseWalletAdapterImpl: t } = await import("./XverseWalletAdapter.impl-CZO0RQva.mjs");
|
|
152
|
+
return new t();
|
|
153
|
+
}
|
|
154
|
+
}), ni = {
|
|
155
|
+
adapterId: Sr,
|
|
156
|
+
metadata: Fn,
|
|
157
|
+
getAdapter: () => Zn
|
|
158
|
+
};
|
|
159
|
+
function $t(t) {
|
|
160
|
+
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
161
|
+
}
|
|
162
|
+
function vr(t) {
|
|
163
|
+
if (!$t(t))
|
|
164
|
+
throw new Error("Uint8Array expected");
|
|
165
|
+
}
|
|
166
|
+
function Ir(t, e) {
|
|
167
|
+
return Array.isArray(e) ? e.length === 0 ? !0 : t ? e.every((n) => typeof n == "string") : e.every((n) => Number.isSafeInteger(n)) : !1;
|
|
168
|
+
}
|
|
169
|
+
function Ne(t) {
|
|
170
|
+
if (typeof t != "function")
|
|
171
|
+
throw new Error("function expected");
|
|
172
|
+
return !0;
|
|
173
|
+
}
|
|
174
|
+
function wt(t, e) {
|
|
175
|
+
if (typeof e != "string")
|
|
176
|
+
throw new Error(`${t}: string expected`);
|
|
177
|
+
return !0;
|
|
178
|
+
}
|
|
179
|
+
function _t(t) {
|
|
180
|
+
if (!Number.isSafeInteger(t))
|
|
181
|
+
throw new Error(`invalid integer: ${t}`);
|
|
182
|
+
}
|
|
183
|
+
function ee(t) {
|
|
184
|
+
if (!Array.isArray(t))
|
|
185
|
+
throw new Error("array expected");
|
|
186
|
+
}
|
|
187
|
+
function re(t, e) {
|
|
188
|
+
if (!Ir(!0, e))
|
|
189
|
+
throw new Error(`${t}: array of strings expected`);
|
|
190
|
+
}
|
|
191
|
+
function Ce(t, e) {
|
|
192
|
+
if (!Ir(!1, e))
|
|
193
|
+
throw new Error(`${t}: array of numbers expected`);
|
|
194
|
+
}
|
|
195
|
+
// @__NO_SIDE_EFFECTS__
|
|
196
|
+
function Mt(...t) {
|
|
197
|
+
const e = (s) => s, n = (s, i) => (c) => s(i(c)), r = t.map((s) => s.encode).reduceRight(n, e), o = t.map((s) => s.decode).reduce(n, e);
|
|
198
|
+
return { encode: r, decode: o };
|
|
199
|
+
}
|
|
200
|
+
// @__NO_SIDE_EFFECTS__
|
|
201
|
+
function de(t) {
|
|
202
|
+
const e = typeof t == "string" ? t.split("") : t, n = e.length;
|
|
203
|
+
re("alphabet", e);
|
|
204
|
+
const r = new Map(e.map((o, s) => [o, s]));
|
|
205
|
+
return {
|
|
206
|
+
encode: (o) => (ee(o), o.map((s) => {
|
|
207
|
+
if (!Number.isSafeInteger(s) || s < 0 || s >= n)
|
|
208
|
+
throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);
|
|
209
|
+
return e[s];
|
|
210
|
+
})),
|
|
211
|
+
decode: (o) => (ee(o), o.map((s) => {
|
|
212
|
+
wt("alphabet.decode", s);
|
|
213
|
+
const i = r.get(s);
|
|
214
|
+
if (i === void 0)
|
|
215
|
+
throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);
|
|
216
|
+
return i;
|
|
217
|
+
}))
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// @__NO_SIDE_EFFECTS__
|
|
221
|
+
function he(t = "") {
|
|
222
|
+
return wt("join", t), {
|
|
223
|
+
encode: (e) => (re("join.decode", e), e.join(t)),
|
|
224
|
+
decode: (e) => (wt("join.decode", e), e.split(t))
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// @__NO_SIDE_EFFECTS__
|
|
228
|
+
function zn(t, e = "=") {
|
|
229
|
+
return _t(t), wt("padding", e), {
|
|
230
|
+
encode(n) {
|
|
231
|
+
for (re("padding.encode", n); n.length * t % 8; )
|
|
232
|
+
n.push(e);
|
|
233
|
+
return n;
|
|
234
|
+
},
|
|
235
|
+
decode(n) {
|
|
236
|
+
re("padding.decode", n);
|
|
237
|
+
let r = n.length;
|
|
238
|
+
if (r * t % 8)
|
|
239
|
+
throw new Error("padding: invalid, string should have whole number of bytes");
|
|
240
|
+
for (; r > 0 && n[r - 1] === e; r--)
|
|
241
|
+
if ((r - 1) * t % 8 === 0)
|
|
242
|
+
throw new Error("padding: invalid, string has too much padding");
|
|
243
|
+
return n.slice(0, r);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// @__NO_SIDE_EFFECTS__
|
|
248
|
+
function Gn(t) {
|
|
249
|
+
return Ne(t), { encode: (e) => e, decode: (e) => t(e) };
|
|
250
|
+
}
|
|
251
|
+
function rr(t, e, n) {
|
|
252
|
+
if (e < 2)
|
|
253
|
+
throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);
|
|
254
|
+
if (n < 2)
|
|
255
|
+
throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);
|
|
256
|
+
if (ee(t), !t.length)
|
|
257
|
+
return [];
|
|
258
|
+
let r = 0;
|
|
259
|
+
const o = [], s = Array.from(t, (c) => {
|
|
260
|
+
if (_t(c), c < 0 || c >= e)
|
|
261
|
+
throw new Error(`invalid integer: ${c}`);
|
|
262
|
+
return c;
|
|
263
|
+
}), i = s.length;
|
|
264
|
+
for (; ; ) {
|
|
265
|
+
let c = 0, a = !0;
|
|
266
|
+
for (let f = r; f < i; f++) {
|
|
267
|
+
const d = s[f], u = e * c, g = u + d;
|
|
268
|
+
if (!Number.isSafeInteger(g) || u / e !== c || g - d !== u)
|
|
269
|
+
throw new Error("convertRadix: carry overflow");
|
|
270
|
+
const l = g / n;
|
|
271
|
+
c = g % n;
|
|
272
|
+
const b = Math.floor(l);
|
|
273
|
+
if (s[f] = b, !Number.isSafeInteger(b) || b * n + c !== g)
|
|
274
|
+
throw new Error("convertRadix: carry overflow");
|
|
275
|
+
if (a)
|
|
276
|
+
b ? a = !1 : r = f;
|
|
277
|
+
else continue;
|
|
278
|
+
}
|
|
279
|
+
if (o.push(c), a)
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
for (let c = 0; c < t.length - 1 && t[c] === 0; c++)
|
|
283
|
+
o.push(0);
|
|
284
|
+
return o.reverse();
|
|
285
|
+
}
|
|
286
|
+
const $r = (t, e) => e === 0 ? t : $r(e, t % e), ne = /* @__NO_SIDE_EFFECTS__ */ (t, e) => t + (e - $r(t, e)), Jt = /* @__PURE__ */ (() => {
|
|
287
|
+
let t = [];
|
|
288
|
+
for (let e = 0; e < 40; e++)
|
|
289
|
+
t.push(2 ** e);
|
|
290
|
+
return t;
|
|
291
|
+
})();
|
|
292
|
+
function Re(t, e, n, r) {
|
|
293
|
+
if (ee(t), e <= 0 || e > 32)
|
|
294
|
+
throw new Error(`convertRadix2: wrong from=${e}`);
|
|
295
|
+
if (n <= 0 || n > 32)
|
|
296
|
+
throw new Error(`convertRadix2: wrong to=${n}`);
|
|
297
|
+
if (/* @__PURE__ */ ne(e, n) > 32)
|
|
298
|
+
throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${/* @__PURE__ */ ne(e, n)}`);
|
|
299
|
+
let o = 0, s = 0;
|
|
300
|
+
const i = Jt[e], c = Jt[n] - 1, a = [];
|
|
301
|
+
for (const f of t) {
|
|
302
|
+
if (_t(f), f >= i)
|
|
303
|
+
throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);
|
|
304
|
+
if (o = o << e | f, s + e > 32)
|
|
305
|
+
throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);
|
|
306
|
+
for (s += e; s >= n; s -= n)
|
|
307
|
+
a.push((o >> s - n & c) >>> 0);
|
|
308
|
+
const d = Jt[s];
|
|
309
|
+
if (d === void 0)
|
|
310
|
+
throw new Error("invalid carry");
|
|
311
|
+
o &= d - 1;
|
|
312
|
+
}
|
|
313
|
+
if (o = o << n - s & c, !r && s >= e)
|
|
314
|
+
throw new Error("Excess padding");
|
|
315
|
+
if (!r && o > 0)
|
|
316
|
+
throw new Error(`Non-zero padding: ${o}`);
|
|
317
|
+
return r && s > 0 && a.push(o >>> 0), a;
|
|
318
|
+
}
|
|
319
|
+
// @__NO_SIDE_EFFECTS__
|
|
320
|
+
function Yn(t) {
|
|
321
|
+
_t(t);
|
|
322
|
+
const e = 2 ** 8;
|
|
323
|
+
return {
|
|
324
|
+
encode: (n) => {
|
|
325
|
+
if (!$t(n))
|
|
326
|
+
throw new Error("radix.encode input should be Uint8Array");
|
|
327
|
+
return rr(Array.from(n), e, t);
|
|
328
|
+
},
|
|
329
|
+
decode: (n) => (Ce("radix.decode", n), Uint8Array.from(rr(n, t, e)))
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
// @__NO_SIDE_EFFECTS__
|
|
333
|
+
function De(t, e = !1) {
|
|
334
|
+
if (_t(t), t <= 0 || t > 32)
|
|
335
|
+
throw new Error("radix2: bits should be in (0..32]");
|
|
336
|
+
if (/* @__PURE__ */ ne(8, t) > 32 || /* @__PURE__ */ ne(t, 8) > 32)
|
|
337
|
+
throw new Error("radix2: carry overflow");
|
|
338
|
+
return {
|
|
339
|
+
encode: (n) => {
|
|
340
|
+
if (!$t(n))
|
|
341
|
+
throw new Error("radix2.encode input should be Uint8Array");
|
|
342
|
+
return Re(Array.from(n), 8, t, !e);
|
|
343
|
+
},
|
|
344
|
+
decode: (n) => (Ce("radix2.decode", n), Uint8Array.from(Re(n, t, 8, e)))
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function nr(t) {
|
|
348
|
+
return Ne(t), function(...e) {
|
|
349
|
+
try {
|
|
350
|
+
return t.apply(null, e);
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function Xn(t, e) {
|
|
356
|
+
return _t(t), Ne(e), {
|
|
357
|
+
encode(n) {
|
|
358
|
+
if (!$t(n))
|
|
359
|
+
throw new Error("checksum.encode: input should be Uint8Array");
|
|
360
|
+
const r = e(n).slice(0, t), o = new Uint8Array(n.length + t);
|
|
361
|
+
return o.set(n), o.set(r, n.length), o;
|
|
362
|
+
},
|
|
363
|
+
decode(n) {
|
|
364
|
+
if (!$t(n))
|
|
365
|
+
throw new Error("checksum.decode: input should be Uint8Array");
|
|
366
|
+
const r = n.slice(0, -t), o = n.slice(-t), s = e(r).slice(0, t);
|
|
367
|
+
for (let i = 0; i < t; i++)
|
|
368
|
+
if (s[i] !== o[i])
|
|
369
|
+
throw new Error("Invalid checksum");
|
|
370
|
+
return r;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const Qn = typeof Uint8Array.from([]).toBase64 == "function" && typeof Uint8Array.fromBase64 == "function", Jn = (t, e) => {
|
|
375
|
+
wt("base64", t);
|
|
376
|
+
const n = /^[A-Za-z0-9=+/]+$/, r = "base64";
|
|
377
|
+
if (t.length > 0 && !n.test(t))
|
|
378
|
+
throw new Error("invalid base64");
|
|
379
|
+
return Uint8Array.fromBase64(t, { alphabet: r, lastChunkHandling: "strict" });
|
|
380
|
+
}, oi = Qn ? {
|
|
381
|
+
encode(t) {
|
|
382
|
+
return vr(t), t.toBase64();
|
|
383
|
+
},
|
|
384
|
+
decode(t) {
|
|
385
|
+
return Jn(t);
|
|
386
|
+
}
|
|
387
|
+
} : /* @__PURE__ */ Mt(/* @__PURE__ */ De(6), /* @__PURE__ */ de("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ zn(6), /* @__PURE__ */ he("")), to = /* @__NO_SIDE_EFFECTS__ */ (t) => /* @__PURE__ */ Mt(/* @__PURE__ */ Yn(58), /* @__PURE__ */ de(t), /* @__PURE__ */ he("")), eo = /* @__PURE__ */ to("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"), ro = (t) => /* @__PURE__ */ Mt(Xn(4, (e) => t(t(e))), eo), Ue = /* @__PURE__ */ Mt(/* @__PURE__ */ de("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ he("")), or = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
388
|
+
function Ct(t) {
|
|
389
|
+
const e = t >> 25;
|
|
390
|
+
let n = (t & 33554431) << 5;
|
|
391
|
+
for (let r = 0; r < or.length; r++)
|
|
392
|
+
(e >> r & 1) === 1 && (n ^= or[r]);
|
|
393
|
+
return n;
|
|
394
|
+
}
|
|
395
|
+
function sr(t, e, n = 1) {
|
|
396
|
+
const r = t.length;
|
|
397
|
+
let o = 1;
|
|
398
|
+
for (let s = 0; s < r; s++) {
|
|
399
|
+
const i = t.charCodeAt(s);
|
|
400
|
+
if (i < 33 || i > 126)
|
|
401
|
+
throw new Error(`Invalid prefix (${t})`);
|
|
402
|
+
o = Ct(o) ^ i >> 5;
|
|
403
|
+
}
|
|
404
|
+
o = Ct(o);
|
|
405
|
+
for (let s = 0; s < r; s++)
|
|
406
|
+
o = Ct(o) ^ t.charCodeAt(s) & 31;
|
|
407
|
+
for (let s of e)
|
|
408
|
+
o = Ct(o) ^ s;
|
|
409
|
+
for (let s = 0; s < 6; s++)
|
|
410
|
+
o = Ct(o);
|
|
411
|
+
return o ^= n, Ue.encode(Re([o % Jt[30]], 30, 5, !1));
|
|
412
|
+
}
|
|
413
|
+
// @__NO_SIDE_EFFECTS__
|
|
414
|
+
function Or(t) {
|
|
415
|
+
const e = t === "bech32" ? 1 : 734539939, n = /* @__PURE__ */ De(5), r = n.decode, o = n.encode, s = nr(r);
|
|
416
|
+
function i(u, g, l = 90) {
|
|
417
|
+
wt("bech32.encode prefix", u), $t(g) && (g = Array.from(g)), Ce("bech32.encode", g);
|
|
418
|
+
const b = u.length;
|
|
419
|
+
if (b === 0)
|
|
420
|
+
throw new TypeError(`Invalid prefix length ${b}`);
|
|
421
|
+
const v = b + 7 + g.length;
|
|
422
|
+
if (l !== !1 && v > l)
|
|
423
|
+
throw new TypeError(`Length ${v} exceeds limit ${l}`);
|
|
424
|
+
const S = u.toLowerCase(), O = sr(S, g, e);
|
|
425
|
+
return `${S}1${Ue.encode(g)}${O}`;
|
|
426
|
+
}
|
|
427
|
+
function c(u, g = 90) {
|
|
428
|
+
wt("bech32.decode input", u);
|
|
429
|
+
const l = u.length;
|
|
430
|
+
if (l < 8 || g !== !1 && l > g)
|
|
431
|
+
throw new TypeError(`invalid string length: ${l} (${u}). Expected (8..${g})`);
|
|
432
|
+
const b = u.toLowerCase();
|
|
433
|
+
if (u !== b && u !== u.toUpperCase())
|
|
434
|
+
throw new Error("String must be lowercase or uppercase");
|
|
435
|
+
const v = b.lastIndexOf("1");
|
|
436
|
+
if (v === 0 || v === -1)
|
|
437
|
+
throw new Error('Letter "1" must be present between prefix and data only');
|
|
438
|
+
const S = b.slice(0, v), O = b.slice(v + 1);
|
|
439
|
+
if (O.length < 6)
|
|
440
|
+
throw new Error("Data must be at least 6 characters long");
|
|
441
|
+
const V = Ue.decode(O).slice(0, -6), F = sr(S, V, e);
|
|
442
|
+
if (!O.endsWith(F))
|
|
443
|
+
throw new Error(`Invalid checksum in ${u}: expected "${F}"`);
|
|
444
|
+
return { prefix: S, words: V };
|
|
445
|
+
}
|
|
446
|
+
const a = nr(c);
|
|
447
|
+
function f(u) {
|
|
448
|
+
const { prefix: g, words: l } = c(u, !1);
|
|
449
|
+
return { prefix: g, words: l, bytes: r(l) };
|
|
450
|
+
}
|
|
451
|
+
function d(u, g) {
|
|
452
|
+
return i(u, o(g));
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
encode: i,
|
|
456
|
+
decode: c,
|
|
457
|
+
encodeFromBytes: d,
|
|
458
|
+
decodeToBytes: f,
|
|
459
|
+
decodeUnsafe: a,
|
|
460
|
+
fromWords: r,
|
|
461
|
+
fromWordsUnsafe: s,
|
|
462
|
+
toWords: o
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
const ke = /* @__PURE__ */ Or("bech32"), Rr = /* @__PURE__ */ Or("bech32m"), no = {
|
|
466
|
+
encode: (t) => new TextDecoder().decode(t),
|
|
467
|
+
decode: (t) => new TextEncoder().encode(t)
|
|
468
|
+
}, oo = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", so = {
|
|
469
|
+
encode(t) {
|
|
470
|
+
return vr(t), t.toHex();
|
|
471
|
+
},
|
|
472
|
+
decode(t) {
|
|
473
|
+
return wt("hex", t), Uint8Array.fromHex(t);
|
|
474
|
+
}
|
|
475
|
+
}, rt = oo ? so : /* @__PURE__ */ Mt(/* @__PURE__ */ De(4), /* @__PURE__ */ de("0123456789abcdef"), /* @__PURE__ */ he(""), /* @__PURE__ */ Gn((t) => {
|
|
476
|
+
if (typeof t != "string" || t.length % 2 !== 0)
|
|
477
|
+
throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);
|
|
478
|
+
return t.toLowerCase();
|
|
479
|
+
}));
|
|
480
|
+
function Ke(t) {
|
|
481
|
+
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
482
|
+
}
|
|
483
|
+
function mt(t, e = "") {
|
|
484
|
+
if (!Number.isSafeInteger(t) || t < 0) {
|
|
485
|
+
const n = e && `"${e}" `;
|
|
486
|
+
throw new Error(`${n}expected integer >= 0, got ${t}`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function k(t, e, n = "") {
|
|
490
|
+
const r = Ke(t), o = t?.length, s = e !== void 0;
|
|
491
|
+
if (!r || s && o !== e) {
|
|
492
|
+
const i = n && `"${n}" `, c = s ? ` of length ${e}` : "", a = r ? `length=${o}` : `type=${typeof t}`;
|
|
493
|
+
throw new Error(i + "expected Uint8Array" + c + ", got " + a);
|
|
494
|
+
}
|
|
495
|
+
return t;
|
|
496
|
+
}
|
|
497
|
+
function Ur(t) {
|
|
498
|
+
if (typeof t != "function" || typeof t.create != "function")
|
|
499
|
+
throw new Error("Hash must wrapped by utils.createHasher");
|
|
500
|
+
mt(t.outputLen), mt(t.blockLen);
|
|
501
|
+
}
|
|
502
|
+
function oe(t, e = !0) {
|
|
503
|
+
if (t.destroyed)
|
|
504
|
+
throw new Error("Hash instance has been destroyed");
|
|
505
|
+
if (e && t.finished)
|
|
506
|
+
throw new Error("Hash#digest() has already been called");
|
|
507
|
+
}
|
|
508
|
+
function io(t, e) {
|
|
509
|
+
k(t, void 0, "digestInto() output");
|
|
510
|
+
const n = e.outputLen;
|
|
511
|
+
if (t.length < n)
|
|
512
|
+
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
513
|
+
}
|
|
514
|
+
function Ot(...t) {
|
|
515
|
+
for (let e = 0; e < t.length; e++)
|
|
516
|
+
t[e].fill(0);
|
|
517
|
+
}
|
|
518
|
+
function Be(t) {
|
|
519
|
+
return new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
520
|
+
}
|
|
521
|
+
function tt(t, e) {
|
|
522
|
+
return t << 32 - e | t >>> e;
|
|
523
|
+
}
|
|
524
|
+
function Gt(t, e) {
|
|
525
|
+
return t << e | t >>> 32 - e >>> 0;
|
|
526
|
+
}
|
|
527
|
+
const kr = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", co = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
|
|
528
|
+
function le(t) {
|
|
529
|
+
if (k(t), kr)
|
|
530
|
+
return t.toHex();
|
|
531
|
+
let e = "";
|
|
532
|
+
for (let n = 0; n < t.length; n++)
|
|
533
|
+
e += co[t[n]];
|
|
534
|
+
return e;
|
|
535
|
+
}
|
|
536
|
+
const st = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
537
|
+
function ir(t) {
|
|
538
|
+
if (t >= st._0 && t <= st._9)
|
|
539
|
+
return t - st._0;
|
|
540
|
+
if (t >= st.A && t <= st.F)
|
|
541
|
+
return t - (st.A - 10);
|
|
542
|
+
if (t >= st.a && t <= st.f)
|
|
543
|
+
return t - (st.a - 10);
|
|
544
|
+
}
|
|
545
|
+
function se(t) {
|
|
546
|
+
if (typeof t != "string")
|
|
547
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
548
|
+
if (kr)
|
|
549
|
+
return Uint8Array.fromHex(t);
|
|
550
|
+
const e = t.length, n = e / 2;
|
|
551
|
+
if (e % 2)
|
|
552
|
+
throw new Error("hex string expected, got unpadded hex of length " + e);
|
|
553
|
+
const r = new Uint8Array(n);
|
|
554
|
+
for (let o = 0, s = 0; o < n; o++, s += 2) {
|
|
555
|
+
const i = ir(t.charCodeAt(s)), c = ir(t.charCodeAt(s + 1));
|
|
556
|
+
if (i === void 0 || c === void 0) {
|
|
557
|
+
const a = t[s] + t[s + 1];
|
|
558
|
+
throw new Error('hex string expected, got non-hex character "' + a + '" at index ' + s);
|
|
559
|
+
}
|
|
560
|
+
r[o] = i * 16 + c;
|
|
561
|
+
}
|
|
562
|
+
return r;
|
|
563
|
+
}
|
|
564
|
+
function et(...t) {
|
|
565
|
+
let e = 0;
|
|
566
|
+
for (let r = 0; r < t.length; r++) {
|
|
567
|
+
const o = t[r];
|
|
568
|
+
k(o), e += o.length;
|
|
569
|
+
}
|
|
570
|
+
const n = new Uint8Array(e);
|
|
571
|
+
for (let r = 0, o = 0; r < t.length; r++) {
|
|
572
|
+
const s = t[r];
|
|
573
|
+
n.set(s, o), o += s.length;
|
|
574
|
+
}
|
|
575
|
+
return n;
|
|
576
|
+
}
|
|
577
|
+
function Pr(t, e = {}) {
|
|
578
|
+
const n = (o, s) => t(s).update(o).digest(), r = t(void 0);
|
|
579
|
+
return n.outputLen = r.outputLen, n.blockLen = r.blockLen, n.create = (o) => t(o), Object.assign(n, e), Object.freeze(n);
|
|
580
|
+
}
|
|
581
|
+
function pe(t = 32) {
|
|
582
|
+
const e = typeof globalThis == "object" ? globalThis.crypto : null;
|
|
583
|
+
if (typeof e?.getRandomValues != "function")
|
|
584
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
585
|
+
return e.getRandomValues(new Uint8Array(t));
|
|
586
|
+
}
|
|
587
|
+
const ao = (t) => ({
|
|
588
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, t])
|
|
589
|
+
});
|
|
590
|
+
function fo(t, e, n) {
|
|
591
|
+
return t & e ^ ~t & n;
|
|
592
|
+
}
|
|
593
|
+
function uo(t, e, n) {
|
|
594
|
+
return t & e ^ t & n ^ e & n;
|
|
595
|
+
}
|
|
596
|
+
class _r {
|
|
597
|
+
blockLen;
|
|
598
|
+
outputLen;
|
|
599
|
+
padOffset;
|
|
600
|
+
isLE;
|
|
601
|
+
// For partial updates less than block size
|
|
602
|
+
buffer;
|
|
603
|
+
view;
|
|
604
|
+
finished = !1;
|
|
605
|
+
length = 0;
|
|
606
|
+
pos = 0;
|
|
607
|
+
destroyed = !1;
|
|
608
|
+
constructor(e, n, r, o) {
|
|
609
|
+
this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = o, this.buffer = new Uint8Array(e), this.view = Be(this.buffer);
|
|
610
|
+
}
|
|
611
|
+
update(e) {
|
|
612
|
+
oe(this), k(e);
|
|
613
|
+
const { view: n, buffer: r, blockLen: o } = this, s = e.length;
|
|
614
|
+
for (let i = 0; i < s; ) {
|
|
615
|
+
const c = Math.min(o - this.pos, s - i);
|
|
616
|
+
if (c === o) {
|
|
617
|
+
const a = Be(e);
|
|
618
|
+
for (; o <= s - i; i += o)
|
|
619
|
+
this.process(a, i);
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
r.set(e.subarray(i, i + c), this.pos), this.pos += c, i += c, this.pos === o && (this.process(n, 0), this.pos = 0);
|
|
623
|
+
}
|
|
624
|
+
return this.length += e.length, this.roundClean(), this;
|
|
625
|
+
}
|
|
626
|
+
digestInto(e) {
|
|
627
|
+
oe(this), io(e, this), this.finished = !0;
|
|
628
|
+
const { buffer: n, view: r, blockLen: o, isLE: s } = this;
|
|
629
|
+
let { pos: i } = this;
|
|
630
|
+
n[i++] = 128, Ot(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(r, 0), i = 0);
|
|
631
|
+
for (let u = i; u < o; u++)
|
|
632
|
+
n[u] = 0;
|
|
633
|
+
r.setBigUint64(o - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
634
|
+
const c = Be(e), a = this.outputLen;
|
|
635
|
+
if (a % 4)
|
|
636
|
+
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
637
|
+
const f = a / 4, d = this.get();
|
|
638
|
+
if (f > d.length)
|
|
639
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
640
|
+
for (let u = 0; u < f; u++)
|
|
641
|
+
c.setUint32(4 * u, d[u], s);
|
|
642
|
+
}
|
|
643
|
+
digest() {
|
|
644
|
+
const { buffer: e, outputLen: n } = this;
|
|
645
|
+
this.digestInto(e);
|
|
646
|
+
const r = e.slice(0, n);
|
|
647
|
+
return this.destroy(), r;
|
|
648
|
+
}
|
|
649
|
+
_cloneInto(e) {
|
|
650
|
+
e ||= new this.constructor(), e.set(...this.get());
|
|
651
|
+
const { blockLen: n, buffer: r, length: o, finished: s, destroyed: i, pos: c } = this;
|
|
652
|
+
return e.destroyed = i, e.finished = s, e.length = o, e.pos = c, o % n && e.buffer.set(r), e;
|
|
653
|
+
}
|
|
654
|
+
clone() {
|
|
655
|
+
return this._cloneInto();
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const ht = /* @__PURE__ */ Uint32Array.from([
|
|
659
|
+
1779033703,
|
|
660
|
+
3144134277,
|
|
661
|
+
1013904242,
|
|
662
|
+
2773480762,
|
|
663
|
+
1359893119,
|
|
664
|
+
2600822924,
|
|
665
|
+
528734635,
|
|
666
|
+
1541459225
|
|
667
|
+
]), ho = /* @__PURE__ */ Uint32Array.from([
|
|
668
|
+
1116352408,
|
|
669
|
+
1899447441,
|
|
670
|
+
3049323471,
|
|
671
|
+
3921009573,
|
|
672
|
+
961987163,
|
|
673
|
+
1508970993,
|
|
674
|
+
2453635748,
|
|
675
|
+
2870763221,
|
|
676
|
+
3624381080,
|
|
677
|
+
310598401,
|
|
678
|
+
607225278,
|
|
679
|
+
1426881987,
|
|
680
|
+
1925078388,
|
|
681
|
+
2162078206,
|
|
682
|
+
2614888103,
|
|
683
|
+
3248222580,
|
|
684
|
+
3835390401,
|
|
685
|
+
4022224774,
|
|
686
|
+
264347078,
|
|
687
|
+
604807628,
|
|
688
|
+
770255983,
|
|
689
|
+
1249150122,
|
|
690
|
+
1555081692,
|
|
691
|
+
1996064986,
|
|
692
|
+
2554220882,
|
|
693
|
+
2821834349,
|
|
694
|
+
2952996808,
|
|
695
|
+
3210313671,
|
|
696
|
+
3336571891,
|
|
697
|
+
3584528711,
|
|
698
|
+
113926993,
|
|
699
|
+
338241895,
|
|
700
|
+
666307205,
|
|
701
|
+
773529912,
|
|
702
|
+
1294757372,
|
|
703
|
+
1396182291,
|
|
704
|
+
1695183700,
|
|
705
|
+
1986661051,
|
|
706
|
+
2177026350,
|
|
707
|
+
2456956037,
|
|
708
|
+
2730485921,
|
|
709
|
+
2820302411,
|
|
710
|
+
3259730800,
|
|
711
|
+
3345764771,
|
|
712
|
+
3516065817,
|
|
713
|
+
3600352804,
|
|
714
|
+
4094571909,
|
|
715
|
+
275423344,
|
|
716
|
+
430227734,
|
|
717
|
+
506948616,
|
|
718
|
+
659060556,
|
|
719
|
+
883997877,
|
|
720
|
+
958139571,
|
|
721
|
+
1322822218,
|
|
722
|
+
1537002063,
|
|
723
|
+
1747873779,
|
|
724
|
+
1955562222,
|
|
725
|
+
2024104815,
|
|
726
|
+
2227730452,
|
|
727
|
+
2361852424,
|
|
728
|
+
2428436474,
|
|
729
|
+
2756734187,
|
|
730
|
+
3204031479,
|
|
731
|
+
3329325298
|
|
732
|
+
]), lt = /* @__PURE__ */ new Uint32Array(64);
|
|
733
|
+
class lo extends _r {
|
|
734
|
+
constructor(e) {
|
|
735
|
+
super(64, e, 8, !1);
|
|
736
|
+
}
|
|
737
|
+
get() {
|
|
738
|
+
const { A: e, B: n, C: r, D: o, E: s, F: i, G: c, H: a } = this;
|
|
739
|
+
return [e, n, r, o, s, i, c, a];
|
|
740
|
+
}
|
|
741
|
+
// prettier-ignore
|
|
742
|
+
set(e, n, r, o, s, i, c, a) {
|
|
743
|
+
this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = o | 0, this.E = s | 0, this.F = i | 0, this.G = c | 0, this.H = a | 0;
|
|
744
|
+
}
|
|
745
|
+
process(e, n) {
|
|
746
|
+
for (let u = 0; u < 16; u++, n += 4)
|
|
747
|
+
lt[u] = e.getUint32(n, !1);
|
|
748
|
+
for (let u = 16; u < 64; u++) {
|
|
749
|
+
const g = lt[u - 15], l = lt[u - 2], b = tt(g, 7) ^ tt(g, 18) ^ g >>> 3, v = tt(l, 17) ^ tt(l, 19) ^ l >>> 10;
|
|
750
|
+
lt[u] = v + lt[u - 7] + b + lt[u - 16] | 0;
|
|
751
|
+
}
|
|
752
|
+
let { A: r, B: o, C: s, D: i, E: c, F: a, G: f, H: d } = this;
|
|
753
|
+
for (let u = 0; u < 64; u++) {
|
|
754
|
+
const g = tt(c, 6) ^ tt(c, 11) ^ tt(c, 25), l = d + g + fo(c, a, f) + ho[u] + lt[u] | 0, v = (tt(r, 2) ^ tt(r, 13) ^ tt(r, 22)) + uo(r, o, s) | 0;
|
|
755
|
+
d = f, f = a, a = c, c = i + l | 0, i = s, s = o, o = r, r = l + v | 0;
|
|
756
|
+
}
|
|
757
|
+
r = r + this.A | 0, o = o + this.B | 0, s = s + this.C | 0, i = i + this.D | 0, c = c + this.E | 0, a = a + this.F | 0, f = f + this.G | 0, d = d + this.H | 0, this.set(r, o, s, i, c, a, f, d);
|
|
758
|
+
}
|
|
759
|
+
roundClean() {
|
|
760
|
+
Ot(lt);
|
|
761
|
+
}
|
|
762
|
+
destroy() {
|
|
763
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), Ot(this.buffer);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
class po extends lo {
|
|
767
|
+
// We cannot use array here since array allows indexing by variable
|
|
768
|
+
// which means optimizer/compiler cannot use registers.
|
|
769
|
+
A = ht[0] | 0;
|
|
770
|
+
B = ht[1] | 0;
|
|
771
|
+
C = ht[2] | 0;
|
|
772
|
+
D = ht[3] | 0;
|
|
773
|
+
E = ht[4] | 0;
|
|
774
|
+
F = ht[5] | 0;
|
|
775
|
+
G = ht[6] | 0;
|
|
776
|
+
H = ht[7] | 0;
|
|
777
|
+
constructor() {
|
|
778
|
+
super(32);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const at = /* @__PURE__ */ Pr(
|
|
782
|
+
() => new po(),
|
|
783
|
+
/* @__PURE__ */ ao(1)
|
|
784
|
+
);
|
|
785
|
+
const Ve = /* @__PURE__ */ BigInt(0), Pe = /* @__PURE__ */ BigInt(1);
|
|
786
|
+
function ie(t, e = "") {
|
|
787
|
+
if (typeof t != "boolean") {
|
|
788
|
+
const n = e && `"${e}" `;
|
|
789
|
+
throw new Error(n + "expected boolean, got type=" + typeof t);
|
|
790
|
+
}
|
|
791
|
+
return t;
|
|
792
|
+
}
|
|
793
|
+
function Hr(t) {
|
|
794
|
+
if (typeof t == "bigint") {
|
|
795
|
+
if (!te(t))
|
|
796
|
+
throw new Error("positive bigint expected, got " + t);
|
|
797
|
+
} else
|
|
798
|
+
mt(t);
|
|
799
|
+
return t;
|
|
800
|
+
}
|
|
801
|
+
function Yt(t) {
|
|
802
|
+
const e = Hr(t).toString(16);
|
|
803
|
+
return e.length & 1 ? "0" + e : e;
|
|
804
|
+
}
|
|
805
|
+
function Lr(t) {
|
|
806
|
+
if (typeof t != "string")
|
|
807
|
+
throw new Error("hex string expected, got " + typeof t);
|
|
808
|
+
return t === "" ? Ve : BigInt("0x" + t);
|
|
809
|
+
}
|
|
810
|
+
function ut(t) {
|
|
811
|
+
return Lr(le(t));
|
|
812
|
+
}
|
|
813
|
+
function Tr(t) {
|
|
814
|
+
return Lr(le(wo(k(t)).reverse()));
|
|
815
|
+
}
|
|
816
|
+
function we(t, e) {
|
|
817
|
+
mt(e), t = Hr(t);
|
|
818
|
+
const n = se(t.toString(16).padStart(e * 2, "0"));
|
|
819
|
+
if (n.length !== e)
|
|
820
|
+
throw new Error("number too large");
|
|
821
|
+
return n;
|
|
822
|
+
}
|
|
823
|
+
function Nr(t, e) {
|
|
824
|
+
return we(t, e).reverse();
|
|
825
|
+
}
|
|
826
|
+
function wo(t) {
|
|
827
|
+
return Uint8Array.from(t);
|
|
828
|
+
}
|
|
829
|
+
function go(t) {
|
|
830
|
+
return Uint8Array.from(t, (e, n) => {
|
|
831
|
+
const r = e.charCodeAt(0);
|
|
832
|
+
if (e.length !== 1 || r > 127)
|
|
833
|
+
throw new Error(`string contains non-ASCII character "${t[n]}" with code ${r} at position ${n}`);
|
|
834
|
+
return r;
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
const te = (t) => typeof t == "bigint" && Ve <= t;
|
|
838
|
+
function yo(t, e, n) {
|
|
839
|
+
return te(t) && te(e) && te(n) && e <= t && t < n;
|
|
840
|
+
}
|
|
841
|
+
function bo(t, e, n, r) {
|
|
842
|
+
if (!yo(e, n, r))
|
|
843
|
+
throw new Error("expected valid " + t + ": " + n + " <= n < " + r + ", got " + e);
|
|
844
|
+
}
|
|
845
|
+
function Eo(t) {
|
|
846
|
+
let e;
|
|
847
|
+
for (e = 0; t > Ve; t >>= Pe, e += 1)
|
|
848
|
+
;
|
|
849
|
+
return e;
|
|
850
|
+
}
|
|
851
|
+
const Me = (t) => (Pe << BigInt(t)) - Pe;
|
|
852
|
+
function mo(t, e, n) {
|
|
853
|
+
if (mt(t, "hashLen"), mt(e, "qByteLen"), typeof n != "function")
|
|
854
|
+
throw new Error("hmacFn must be a function");
|
|
855
|
+
const r = (S) => new Uint8Array(S), o = Uint8Array.of(), s = Uint8Array.of(0), i = Uint8Array.of(1), c = 1e3;
|
|
856
|
+
let a = r(t), f = r(t), d = 0;
|
|
857
|
+
const u = () => {
|
|
858
|
+
a.fill(1), f.fill(0), d = 0;
|
|
859
|
+
}, g = (...S) => n(f, et(a, ...S)), l = (S = o) => {
|
|
860
|
+
f = g(s, S), a = g(), S.length !== 0 && (f = g(i, S), a = g());
|
|
861
|
+
}, b = () => {
|
|
862
|
+
if (d++ >= c)
|
|
863
|
+
throw new Error("drbg: tried max amount of iterations");
|
|
864
|
+
let S = 0;
|
|
865
|
+
const O = [];
|
|
866
|
+
for (; S < e; ) {
|
|
867
|
+
a = g();
|
|
868
|
+
const V = a.slice();
|
|
869
|
+
O.push(V), S += a.length;
|
|
870
|
+
}
|
|
871
|
+
return et(...O);
|
|
872
|
+
};
|
|
873
|
+
return (S, O) => {
|
|
874
|
+
u(), l(S);
|
|
875
|
+
let V;
|
|
876
|
+
for (; !(V = O(b())); )
|
|
877
|
+
l();
|
|
878
|
+
return u(), V;
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
function We(t, e = {}, n = {}) {
|
|
882
|
+
if (!t || typeof t != "object")
|
|
883
|
+
throw new Error("expected valid options object");
|
|
884
|
+
function r(s, i, c) {
|
|
885
|
+
const a = t[s];
|
|
886
|
+
if (c && a === void 0)
|
|
887
|
+
return;
|
|
888
|
+
const f = typeof a;
|
|
889
|
+
if (f !== i || a === null)
|
|
890
|
+
throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`);
|
|
891
|
+
}
|
|
892
|
+
const o = (s, i) => Object.entries(s).forEach(([c, a]) => r(c, a, i));
|
|
893
|
+
o(e, !1), o(n, !0);
|
|
894
|
+
}
|
|
895
|
+
function cr(t) {
|
|
896
|
+
const e = /* @__PURE__ */ new WeakMap();
|
|
897
|
+
return (n, ...r) => {
|
|
898
|
+
const o = e.get(n);
|
|
899
|
+
if (o !== void 0)
|
|
900
|
+
return o;
|
|
901
|
+
const s = t(n, ...r);
|
|
902
|
+
return e.set(n, s), s;
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
const j = /* @__PURE__ */ BigInt(0), q = /* @__PURE__ */ BigInt(1), yt = /* @__PURE__ */ BigInt(2), Cr = /* @__PURE__ */ BigInt(3), Dr = /* @__PURE__ */ BigInt(4), Kr = /* @__PURE__ */ BigInt(5), xo = /* @__PURE__ */ BigInt(7), Vr = /* @__PURE__ */ BigInt(8), Ao = /* @__PURE__ */ BigInt(9), Mr = /* @__PURE__ */ BigInt(16);
|
|
906
|
+
function X(t, e) {
|
|
907
|
+
const n = t % e;
|
|
908
|
+
return n >= j ? n : e + n;
|
|
909
|
+
}
|
|
910
|
+
function G(t, e, n) {
|
|
911
|
+
let r = t;
|
|
912
|
+
for (; e-- > j; )
|
|
913
|
+
r *= r, r %= n;
|
|
914
|
+
return r;
|
|
915
|
+
}
|
|
916
|
+
function ar(t, e) {
|
|
917
|
+
if (t === j)
|
|
918
|
+
throw new Error("invert: expected non-zero number");
|
|
919
|
+
if (e <= j)
|
|
920
|
+
throw new Error("invert: expected positive modulus, got " + e);
|
|
921
|
+
let n = X(t, e), r = e, o = j, s = q;
|
|
922
|
+
for (; n !== j; ) {
|
|
923
|
+
const c = r / n, a = r % n, f = o - s * c;
|
|
924
|
+
r = n, n = a, o = s, s = f;
|
|
925
|
+
}
|
|
926
|
+
if (r !== q)
|
|
927
|
+
throw new Error("invert: does not exist");
|
|
928
|
+
return X(o, e);
|
|
929
|
+
}
|
|
930
|
+
function qe(t, e, n) {
|
|
931
|
+
if (!t.eql(t.sqr(e), n))
|
|
932
|
+
throw new Error("Cannot find square root");
|
|
933
|
+
}
|
|
934
|
+
function Wr(t, e) {
|
|
935
|
+
const n = (t.ORDER + q) / Dr, r = t.pow(e, n);
|
|
936
|
+
return qe(t, r, e), r;
|
|
937
|
+
}
|
|
938
|
+
function Bo(t, e) {
|
|
939
|
+
const n = (t.ORDER - Kr) / Vr, r = t.mul(e, yt), o = t.pow(r, n), s = t.mul(e, o), i = t.mul(t.mul(s, yt), o), c = t.mul(s, t.sub(i, t.ONE));
|
|
940
|
+
return qe(t, c, e), c;
|
|
941
|
+
}
|
|
942
|
+
function So(t) {
|
|
943
|
+
const e = ge(t), n = qr(t), r = n(e, e.neg(e.ONE)), o = n(e, r), s = n(e, e.neg(r)), i = (t + xo) / Mr;
|
|
944
|
+
return (c, a) => {
|
|
945
|
+
let f = c.pow(a, i), d = c.mul(f, r);
|
|
946
|
+
const u = c.mul(f, o), g = c.mul(f, s), l = c.eql(c.sqr(d), a), b = c.eql(c.sqr(u), a);
|
|
947
|
+
f = c.cmov(f, d, l), d = c.cmov(g, u, b);
|
|
948
|
+
const v = c.eql(c.sqr(d), a), S = c.cmov(f, d, v);
|
|
949
|
+
return qe(c, S, a), S;
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function qr(t) {
|
|
953
|
+
if (t < Cr)
|
|
954
|
+
throw new Error("sqrt is not defined for small field");
|
|
955
|
+
let e = t - q, n = 0;
|
|
956
|
+
for (; e % yt === j; )
|
|
957
|
+
e /= yt, n++;
|
|
958
|
+
let r = yt;
|
|
959
|
+
const o = ge(t);
|
|
960
|
+
for (; fr(o, r) === 1; )
|
|
961
|
+
if (r++ > 1e3)
|
|
962
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
963
|
+
if (n === 1)
|
|
964
|
+
return Wr;
|
|
965
|
+
let s = o.pow(r, e);
|
|
966
|
+
const i = (e + q) / yt;
|
|
967
|
+
return function(a, f) {
|
|
968
|
+
if (a.is0(f))
|
|
969
|
+
return f;
|
|
970
|
+
if (fr(a, f) !== 1)
|
|
971
|
+
throw new Error("Cannot find square root");
|
|
972
|
+
let d = n, u = a.mul(a.ONE, s), g = a.pow(f, e), l = a.pow(f, i);
|
|
973
|
+
for (; !a.eql(g, a.ONE); ) {
|
|
974
|
+
if (a.is0(g))
|
|
975
|
+
return a.ZERO;
|
|
976
|
+
let b = 1, v = a.sqr(g);
|
|
977
|
+
for (; !a.eql(v, a.ONE); )
|
|
978
|
+
if (b++, v = a.sqr(v), b === d)
|
|
979
|
+
throw new Error("Cannot find square root");
|
|
980
|
+
const S = q << BigInt(d - b - 1), O = a.pow(u, S);
|
|
981
|
+
d = b, u = a.sqr(O), g = a.mul(g, u), l = a.mul(l, O);
|
|
982
|
+
}
|
|
983
|
+
return l;
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
function vo(t) {
|
|
987
|
+
return t % Dr === Cr ? Wr : t % Vr === Kr ? Bo : t % Mr === Ao ? So(t) : qr(t);
|
|
988
|
+
}
|
|
989
|
+
const Io = [
|
|
990
|
+
"create",
|
|
991
|
+
"isValid",
|
|
992
|
+
"is0",
|
|
993
|
+
"neg",
|
|
994
|
+
"inv",
|
|
995
|
+
"sqrt",
|
|
996
|
+
"sqr",
|
|
997
|
+
"eql",
|
|
998
|
+
"add",
|
|
999
|
+
"sub",
|
|
1000
|
+
"mul",
|
|
1001
|
+
"pow",
|
|
1002
|
+
"div",
|
|
1003
|
+
"addN",
|
|
1004
|
+
"subN",
|
|
1005
|
+
"mulN",
|
|
1006
|
+
"sqrN"
|
|
1007
|
+
];
|
|
1008
|
+
function $o(t) {
|
|
1009
|
+
const e = {
|
|
1010
|
+
ORDER: "bigint",
|
|
1011
|
+
BYTES: "number",
|
|
1012
|
+
BITS: "number"
|
|
1013
|
+
}, n = Io.reduce((r, o) => (r[o] = "function", r), e);
|
|
1014
|
+
return We(t, n), t;
|
|
1015
|
+
}
|
|
1016
|
+
function Oo(t, e, n) {
|
|
1017
|
+
if (n < j)
|
|
1018
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
1019
|
+
if (n === j)
|
|
1020
|
+
return t.ONE;
|
|
1021
|
+
if (n === q)
|
|
1022
|
+
return e;
|
|
1023
|
+
let r = t.ONE, o = e;
|
|
1024
|
+
for (; n > j; )
|
|
1025
|
+
n & q && (r = t.mul(r, o)), o = t.sqr(o), n >>= q;
|
|
1026
|
+
return r;
|
|
1027
|
+
}
|
|
1028
|
+
function jr(t, e, n = !1) {
|
|
1029
|
+
const r = new Array(e.length).fill(n ? t.ZERO : void 0), o = e.reduce((i, c, a) => t.is0(c) ? i : (r[a] = i, t.mul(i, c)), t.ONE), s = t.inv(o);
|
|
1030
|
+
return e.reduceRight((i, c, a) => t.is0(c) ? i : (r[a] = t.mul(i, r[a]), t.mul(i, c)), s), r;
|
|
1031
|
+
}
|
|
1032
|
+
function fr(t, e) {
|
|
1033
|
+
const n = (t.ORDER - q) / yt, r = t.pow(e, n), o = t.eql(r, t.ONE), s = t.eql(r, t.ZERO), i = t.eql(r, t.neg(t.ONE));
|
|
1034
|
+
if (!o && !s && !i)
|
|
1035
|
+
throw new Error("invalid Legendre symbol result");
|
|
1036
|
+
return o ? 1 : s ? 0 : -1;
|
|
1037
|
+
}
|
|
1038
|
+
function Ro(t, e) {
|
|
1039
|
+
e !== void 0 && mt(e);
|
|
1040
|
+
const n = e !== void 0 ? e : t.toString(2).length, r = Math.ceil(n / 8);
|
|
1041
|
+
return { nBitLength: n, nByteLength: r };
|
|
1042
|
+
}
|
|
1043
|
+
class Uo {
|
|
1044
|
+
ORDER;
|
|
1045
|
+
BITS;
|
|
1046
|
+
BYTES;
|
|
1047
|
+
isLE;
|
|
1048
|
+
ZERO = j;
|
|
1049
|
+
ONE = q;
|
|
1050
|
+
_lengths;
|
|
1051
|
+
_sqrt;
|
|
1052
|
+
// cached sqrt
|
|
1053
|
+
_mod;
|
|
1054
|
+
constructor(e, n = {}) {
|
|
1055
|
+
if (e <= j)
|
|
1056
|
+
throw new Error("invalid field: expected ORDER > 0, got " + e);
|
|
1057
|
+
let r;
|
|
1058
|
+
this.isLE = !1, n != null && typeof n == "object" && (typeof n.BITS == "number" && (r = n.BITS), typeof n.sqrt == "function" && (this.sqrt = n.sqrt), typeof n.isLE == "boolean" && (this.isLE = n.isLE), n.allowedLengths && (this._lengths = n.allowedLengths?.slice()), typeof n.modFromBytes == "boolean" && (this._mod = n.modFromBytes));
|
|
1059
|
+
const { nBitLength: o, nByteLength: s } = Ro(e, r);
|
|
1060
|
+
if (s > 2048)
|
|
1061
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1062
|
+
this.ORDER = e, this.BITS = o, this.BYTES = s, this._sqrt = void 0, Object.preventExtensions(this);
|
|
1063
|
+
}
|
|
1064
|
+
create(e) {
|
|
1065
|
+
return X(e, this.ORDER);
|
|
1066
|
+
}
|
|
1067
|
+
isValid(e) {
|
|
1068
|
+
if (typeof e != "bigint")
|
|
1069
|
+
throw new Error("invalid field element: expected bigint, got " + typeof e);
|
|
1070
|
+
return j <= e && e < this.ORDER;
|
|
1071
|
+
}
|
|
1072
|
+
is0(e) {
|
|
1073
|
+
return e === j;
|
|
1074
|
+
}
|
|
1075
|
+
// is valid and invertible
|
|
1076
|
+
isValidNot0(e) {
|
|
1077
|
+
return !this.is0(e) && this.isValid(e);
|
|
1078
|
+
}
|
|
1079
|
+
isOdd(e) {
|
|
1080
|
+
return (e & q) === q;
|
|
1081
|
+
}
|
|
1082
|
+
neg(e) {
|
|
1083
|
+
return X(-e, this.ORDER);
|
|
1084
|
+
}
|
|
1085
|
+
eql(e, n) {
|
|
1086
|
+
return e === n;
|
|
1087
|
+
}
|
|
1088
|
+
sqr(e) {
|
|
1089
|
+
return X(e * e, this.ORDER);
|
|
1090
|
+
}
|
|
1091
|
+
add(e, n) {
|
|
1092
|
+
return X(e + n, this.ORDER);
|
|
1093
|
+
}
|
|
1094
|
+
sub(e, n) {
|
|
1095
|
+
return X(e - n, this.ORDER);
|
|
1096
|
+
}
|
|
1097
|
+
mul(e, n) {
|
|
1098
|
+
return X(e * n, this.ORDER);
|
|
1099
|
+
}
|
|
1100
|
+
pow(e, n) {
|
|
1101
|
+
return Oo(this, e, n);
|
|
1102
|
+
}
|
|
1103
|
+
div(e, n) {
|
|
1104
|
+
return X(e * ar(n, this.ORDER), this.ORDER);
|
|
1105
|
+
}
|
|
1106
|
+
// Same as above, but doesn't normalize
|
|
1107
|
+
sqrN(e) {
|
|
1108
|
+
return e * e;
|
|
1109
|
+
}
|
|
1110
|
+
addN(e, n) {
|
|
1111
|
+
return e + n;
|
|
1112
|
+
}
|
|
1113
|
+
subN(e, n) {
|
|
1114
|
+
return e - n;
|
|
1115
|
+
}
|
|
1116
|
+
mulN(e, n) {
|
|
1117
|
+
return e * n;
|
|
1118
|
+
}
|
|
1119
|
+
inv(e) {
|
|
1120
|
+
return ar(e, this.ORDER);
|
|
1121
|
+
}
|
|
1122
|
+
sqrt(e) {
|
|
1123
|
+
return this._sqrt || (this._sqrt = vo(this.ORDER)), this._sqrt(this, e);
|
|
1124
|
+
}
|
|
1125
|
+
toBytes(e) {
|
|
1126
|
+
return this.isLE ? Nr(e, this.BYTES) : we(e, this.BYTES);
|
|
1127
|
+
}
|
|
1128
|
+
fromBytes(e, n = !1) {
|
|
1129
|
+
k(e);
|
|
1130
|
+
const { _lengths: r, BYTES: o, isLE: s, ORDER: i, _mod: c } = this;
|
|
1131
|
+
if (r) {
|
|
1132
|
+
if (!r.includes(e.length) || e.length > o)
|
|
1133
|
+
throw new Error("Field.fromBytes: expected " + r + " bytes, got " + e.length);
|
|
1134
|
+
const f = new Uint8Array(o);
|
|
1135
|
+
f.set(e, s ? 0 : f.length - e.length), e = f;
|
|
1136
|
+
}
|
|
1137
|
+
if (e.length !== o)
|
|
1138
|
+
throw new Error("Field.fromBytes: expected " + o + " bytes, got " + e.length);
|
|
1139
|
+
let a = s ? Tr(e) : ut(e);
|
|
1140
|
+
if (c && (a = X(a, i)), !n && !this.isValid(a))
|
|
1141
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
1142
|
+
return a;
|
|
1143
|
+
}
|
|
1144
|
+
// TODO: we don't need it here, move out to separate fn
|
|
1145
|
+
invertBatch(e) {
|
|
1146
|
+
return jr(this, e);
|
|
1147
|
+
}
|
|
1148
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
1149
|
+
// and it's unclear what to return in there.
|
|
1150
|
+
cmov(e, n, r) {
|
|
1151
|
+
return r ? n : e;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
function ge(t, e = {}) {
|
|
1155
|
+
return new Uo(t, e);
|
|
1156
|
+
}
|
|
1157
|
+
function Fr(t) {
|
|
1158
|
+
if (typeof t != "bigint")
|
|
1159
|
+
throw new Error("field order must be bigint");
|
|
1160
|
+
const e = t.toString(2).length;
|
|
1161
|
+
return Math.ceil(e / 8);
|
|
1162
|
+
}
|
|
1163
|
+
function Zr(t) {
|
|
1164
|
+
const e = Fr(t);
|
|
1165
|
+
return e + Math.ceil(e / 2);
|
|
1166
|
+
}
|
|
1167
|
+
function zr(t, e, n = !1) {
|
|
1168
|
+
k(t);
|
|
1169
|
+
const r = t.length, o = Fr(e), s = Zr(e);
|
|
1170
|
+
if (r < 16 || r < s || r > 1024)
|
|
1171
|
+
throw new Error("expected " + s + "-1024 bytes of input, got " + r);
|
|
1172
|
+
const i = n ? Tr(t) : ut(t), c = X(i, e - q) + q;
|
|
1173
|
+
return n ? Nr(c, o) : we(c, o);
|
|
1174
|
+
}
|
|
1175
|
+
const Rt = /* @__PURE__ */ BigInt(0), bt = /* @__PURE__ */ BigInt(1);
|
|
1176
|
+
function ce(t, e) {
|
|
1177
|
+
const n = e.negate();
|
|
1178
|
+
return t ? n : e;
|
|
1179
|
+
}
|
|
1180
|
+
function ur(t, e) {
|
|
1181
|
+
const n = jr(t.Fp, e.map((r) => r.Z));
|
|
1182
|
+
return e.map((r, o) => t.fromAffine(r.toAffine(n[o])));
|
|
1183
|
+
}
|
|
1184
|
+
function Gr(t, e) {
|
|
1185
|
+
if (!Number.isSafeInteger(t) || t <= 0 || t > e)
|
|
1186
|
+
throw new Error("invalid window size, expected [1.." + e + "], got W=" + t);
|
|
1187
|
+
}
|
|
1188
|
+
function Se(t, e) {
|
|
1189
|
+
Gr(t, e);
|
|
1190
|
+
const n = Math.ceil(e / t) + 1, r = 2 ** (t - 1), o = 2 ** t, s = Me(t), i = BigInt(t);
|
|
1191
|
+
return { windows: n, windowSize: r, mask: s, maxNumber: o, shiftBy: i };
|
|
1192
|
+
}
|
|
1193
|
+
function dr(t, e, n) {
|
|
1194
|
+
const { windowSize: r, mask: o, maxNumber: s, shiftBy: i } = n;
|
|
1195
|
+
let c = Number(t & o), a = t >> i;
|
|
1196
|
+
c > r && (c -= s, a += bt);
|
|
1197
|
+
const f = e * r, d = f + Math.abs(c) - 1, u = c === 0, g = c < 0, l = e % 2 !== 0;
|
|
1198
|
+
return { nextN: a, offset: d, isZero: u, isNeg: g, isNegF: l, offsetF: f };
|
|
1199
|
+
}
|
|
1200
|
+
const ve = /* @__PURE__ */ new WeakMap(), Yr = /* @__PURE__ */ new WeakMap();
|
|
1201
|
+
function Ie(t) {
|
|
1202
|
+
return Yr.get(t) || 1;
|
|
1203
|
+
}
|
|
1204
|
+
function hr(t) {
|
|
1205
|
+
if (t !== Rt)
|
|
1206
|
+
throw new Error("invalid wNAF");
|
|
1207
|
+
}
|
|
1208
|
+
class ko {
|
|
1209
|
+
BASE;
|
|
1210
|
+
ZERO;
|
|
1211
|
+
Fn;
|
|
1212
|
+
bits;
|
|
1213
|
+
// Parametrized with a given Point class (not individual point)
|
|
1214
|
+
constructor(e, n) {
|
|
1215
|
+
this.BASE = e.BASE, this.ZERO = e.ZERO, this.Fn = e.Fn, this.bits = n;
|
|
1216
|
+
}
|
|
1217
|
+
// non-const time multiplication ladder
|
|
1218
|
+
_unsafeLadder(e, n, r = this.ZERO) {
|
|
1219
|
+
let o = e;
|
|
1220
|
+
for (; n > Rt; )
|
|
1221
|
+
n & bt && (r = r.add(o)), o = o.double(), n >>= bt;
|
|
1222
|
+
return r;
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
1226
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1227
|
+
* Number of precomputed points depends on the curve size:
|
|
1228
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1229
|
+
* - 𝑊 is the window size
|
|
1230
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
1231
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1232
|
+
* @param point Point instance
|
|
1233
|
+
* @param W window size
|
|
1234
|
+
* @returns precomputed point tables flattened to a single array
|
|
1235
|
+
*/
|
|
1236
|
+
precomputeWindow(e, n) {
|
|
1237
|
+
const { windows: r, windowSize: o } = Se(n, this.bits), s = [];
|
|
1238
|
+
let i = e, c = i;
|
|
1239
|
+
for (let a = 0; a < r; a++) {
|
|
1240
|
+
c = i, s.push(c);
|
|
1241
|
+
for (let f = 1; f < o; f++)
|
|
1242
|
+
c = c.add(i), s.push(c);
|
|
1243
|
+
i = c.double();
|
|
1244
|
+
}
|
|
1245
|
+
return s;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1249
|
+
* More compact implementation:
|
|
1250
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
1251
|
+
* @returns real and fake (for const-time) points
|
|
1252
|
+
*/
|
|
1253
|
+
wNAF(e, n, r) {
|
|
1254
|
+
if (!this.Fn.isValid(r))
|
|
1255
|
+
throw new Error("invalid scalar");
|
|
1256
|
+
let o = this.ZERO, s = this.BASE;
|
|
1257
|
+
const i = Se(e, this.bits);
|
|
1258
|
+
for (let c = 0; c < i.windows; c++) {
|
|
1259
|
+
const { nextN: a, offset: f, isZero: d, isNeg: u, isNegF: g, offsetF: l } = dr(r, c, i);
|
|
1260
|
+
r = a, d ? s = s.add(ce(g, n[l])) : o = o.add(ce(u, n[f]));
|
|
1261
|
+
}
|
|
1262
|
+
return hr(r), { p: o, f: s };
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1266
|
+
* @param acc accumulator point to add result of multiplication
|
|
1267
|
+
* @returns point
|
|
1268
|
+
*/
|
|
1269
|
+
wNAFUnsafe(e, n, r, o = this.ZERO) {
|
|
1270
|
+
const s = Se(e, this.bits);
|
|
1271
|
+
for (let i = 0; i < s.windows && r !== Rt; i++) {
|
|
1272
|
+
const { nextN: c, offset: a, isZero: f, isNeg: d } = dr(r, i, s);
|
|
1273
|
+
if (r = c, !f) {
|
|
1274
|
+
const u = n[a];
|
|
1275
|
+
o = o.add(d ? u.negate() : u);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return hr(r), o;
|
|
1279
|
+
}
|
|
1280
|
+
getPrecomputes(e, n, r) {
|
|
1281
|
+
let o = ve.get(n);
|
|
1282
|
+
return o || (o = this.precomputeWindow(n, e), e !== 1 && (typeof r == "function" && (o = r(o)), ve.set(n, o))), o;
|
|
1283
|
+
}
|
|
1284
|
+
cached(e, n, r) {
|
|
1285
|
+
const o = Ie(e);
|
|
1286
|
+
return this.wNAF(o, this.getPrecomputes(o, e, r), n);
|
|
1287
|
+
}
|
|
1288
|
+
unsafe(e, n, r, o) {
|
|
1289
|
+
const s = Ie(e);
|
|
1290
|
+
return s === 1 ? this._unsafeLadder(e, n, o) : this.wNAFUnsafe(s, this.getPrecomputes(s, e, r), n, o);
|
|
1291
|
+
}
|
|
1292
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1293
|
+
// using windowed method. This specifies window size and
|
|
1294
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1295
|
+
createCache(e, n) {
|
|
1296
|
+
Gr(n, this.bits), Yr.set(e, n), ve.delete(e);
|
|
1297
|
+
}
|
|
1298
|
+
hasCache(e) {
|
|
1299
|
+
return Ie(e) !== 1;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function Po(t, e, n, r) {
|
|
1303
|
+
let o = e, s = t.ZERO, i = t.ZERO;
|
|
1304
|
+
for (; n > Rt || r > Rt; )
|
|
1305
|
+
n & bt && (s = s.add(o)), r & bt && (i = i.add(o)), o = o.double(), n >>= bt, r >>= bt;
|
|
1306
|
+
return { p1: s, p2: i };
|
|
1307
|
+
}
|
|
1308
|
+
function lr(t, e, n) {
|
|
1309
|
+
if (e) {
|
|
1310
|
+
if (e.ORDER !== t)
|
|
1311
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1312
|
+
return $o(e), e;
|
|
1313
|
+
} else
|
|
1314
|
+
return ge(t, { isLE: n });
|
|
1315
|
+
}
|
|
1316
|
+
function _o(t, e, n = {}, r) {
|
|
1317
|
+
if (r === void 0 && (r = t === "edwards"), !e || typeof e != "object")
|
|
1318
|
+
throw new Error(`expected valid ${t} CURVE object`);
|
|
1319
|
+
for (const a of ["p", "n", "h"]) {
|
|
1320
|
+
const f = e[a];
|
|
1321
|
+
if (!(typeof f == "bigint" && f > Rt))
|
|
1322
|
+
throw new Error(`CURVE.${a} must be positive bigint`);
|
|
1323
|
+
}
|
|
1324
|
+
const o = lr(e.p, n.Fp, r), s = lr(e.n, n.Fn, r), c = ["Gx", "Gy", "a", "b"];
|
|
1325
|
+
for (const a of c)
|
|
1326
|
+
if (!o.isValid(e[a]))
|
|
1327
|
+
throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);
|
|
1328
|
+
return e = Object.freeze(Object.assign({}, e)), { CURVE: e, Fp: o, Fn: s };
|
|
1329
|
+
}
|
|
1330
|
+
function Xr(t, e) {
|
|
1331
|
+
return function(r) {
|
|
1332
|
+
const o = t(r);
|
|
1333
|
+
return { secretKey: o, publicKey: e(o) };
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
class Qr {
|
|
1337
|
+
oHash;
|
|
1338
|
+
iHash;
|
|
1339
|
+
blockLen;
|
|
1340
|
+
outputLen;
|
|
1341
|
+
finished = !1;
|
|
1342
|
+
destroyed = !1;
|
|
1343
|
+
constructor(e, n) {
|
|
1344
|
+
if (Ur(e), k(n, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function")
|
|
1345
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1346
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1347
|
+
const r = this.blockLen, o = new Uint8Array(r);
|
|
1348
|
+
o.set(n.length > r ? e.create().update(n).digest() : n);
|
|
1349
|
+
for (let s = 0; s < o.length; s++)
|
|
1350
|
+
o[s] ^= 54;
|
|
1351
|
+
this.iHash.update(o), this.oHash = e.create();
|
|
1352
|
+
for (let s = 0; s < o.length; s++)
|
|
1353
|
+
o[s] ^= 106;
|
|
1354
|
+
this.oHash.update(o), Ot(o);
|
|
1355
|
+
}
|
|
1356
|
+
update(e) {
|
|
1357
|
+
return oe(this), this.iHash.update(e), this;
|
|
1358
|
+
}
|
|
1359
|
+
digestInto(e) {
|
|
1360
|
+
oe(this), k(e, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
|
|
1361
|
+
}
|
|
1362
|
+
digest() {
|
|
1363
|
+
const e = new Uint8Array(this.oHash.outputLen);
|
|
1364
|
+
return this.digestInto(e), e;
|
|
1365
|
+
}
|
|
1366
|
+
_cloneInto(e) {
|
|
1367
|
+
e ||= Object.create(Object.getPrototypeOf(this), {});
|
|
1368
|
+
const { oHash: n, iHash: r, finished: o, destroyed: s, blockLen: i, outputLen: c } = this;
|
|
1369
|
+
return e = e, e.finished = o, e.destroyed = s, e.blockLen = i, e.outputLen = c, e.oHash = n._cloneInto(e.oHash), e.iHash = r._cloneInto(e.iHash), e;
|
|
1370
|
+
}
|
|
1371
|
+
clone() {
|
|
1372
|
+
return this._cloneInto();
|
|
1373
|
+
}
|
|
1374
|
+
destroy() {
|
|
1375
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
const Jr = (t, e, n) => new Qr(t, e).update(n).digest();
|
|
1379
|
+
Jr.create = (t, e) => new Qr(t, e);
|
|
1380
|
+
const pr = (t, e) => (t + (t >= 0 ? e : -e) / tn) / e;
|
|
1381
|
+
function Ho(t, e, n) {
|
|
1382
|
+
const [[r, o], [s, i]] = e, c = pr(i * t, n), a = pr(-o * t, n);
|
|
1383
|
+
let f = t - c * r - a * s, d = -c * o - a * i;
|
|
1384
|
+
const u = f < it, g = d < it;
|
|
1385
|
+
u && (f = -f), g && (d = -d);
|
|
1386
|
+
const l = Me(Math.ceil(Eo(n) / 2)) + It;
|
|
1387
|
+
if (f < it || f >= l || d < it || d >= l)
|
|
1388
|
+
throw new Error("splitScalar (endomorphism): failed, k=" + t);
|
|
1389
|
+
return { k1neg: u, k1: f, k2neg: g, k2: d };
|
|
1390
|
+
}
|
|
1391
|
+
function _e(t) {
|
|
1392
|
+
if (!["compact", "recovered", "der"].includes(t))
|
|
1393
|
+
throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
1394
|
+
return t;
|
|
1395
|
+
}
|
|
1396
|
+
function $e(t, e) {
|
|
1397
|
+
const n = {};
|
|
1398
|
+
for (let r of Object.keys(e))
|
|
1399
|
+
n[r] = t[r] === void 0 ? e[r] : t[r];
|
|
1400
|
+
return ie(n.lowS, "lowS"), ie(n.prehash, "prehash"), n.format !== void 0 && _e(n.format), n;
|
|
1401
|
+
}
|
|
1402
|
+
class Lo extends Error {
|
|
1403
|
+
constructor(e = "") {
|
|
1404
|
+
super(e);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
const pt = {
|
|
1408
|
+
// asn.1 DER encoding utils
|
|
1409
|
+
Err: Lo,
|
|
1410
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
1411
|
+
_tlv: {
|
|
1412
|
+
encode: (t, e) => {
|
|
1413
|
+
const { Err: n } = pt;
|
|
1414
|
+
if (t < 0 || t > 256)
|
|
1415
|
+
throw new n("tlv.encode: wrong tag");
|
|
1416
|
+
if (e.length & 1)
|
|
1417
|
+
throw new n("tlv.encode: unpadded data");
|
|
1418
|
+
const r = e.length / 2, o = Yt(r);
|
|
1419
|
+
if (o.length / 2 & 128)
|
|
1420
|
+
throw new n("tlv.encode: long form length too big");
|
|
1421
|
+
const s = r > 127 ? Yt(o.length / 2 | 128) : "";
|
|
1422
|
+
return Yt(t) + s + o + e;
|
|
1423
|
+
},
|
|
1424
|
+
// v - value, l - left bytes (unparsed)
|
|
1425
|
+
decode(t, e) {
|
|
1426
|
+
const { Err: n } = pt;
|
|
1427
|
+
let r = 0;
|
|
1428
|
+
if (t < 0 || t > 256)
|
|
1429
|
+
throw new n("tlv.encode: wrong tag");
|
|
1430
|
+
if (e.length < 2 || e[r++] !== t)
|
|
1431
|
+
throw new n("tlv.decode: wrong tlv");
|
|
1432
|
+
const o = e[r++], s = !!(o & 128);
|
|
1433
|
+
let i = 0;
|
|
1434
|
+
if (!s)
|
|
1435
|
+
i = o;
|
|
1436
|
+
else {
|
|
1437
|
+
const a = o & 127;
|
|
1438
|
+
if (!a)
|
|
1439
|
+
throw new n("tlv.decode(long): indefinite length not supported");
|
|
1440
|
+
if (a > 4)
|
|
1441
|
+
throw new n("tlv.decode(long): byte length is too big");
|
|
1442
|
+
const f = e.subarray(r, r + a);
|
|
1443
|
+
if (f.length !== a)
|
|
1444
|
+
throw new n("tlv.decode: length bytes not complete");
|
|
1445
|
+
if (f[0] === 0)
|
|
1446
|
+
throw new n("tlv.decode(long): zero leftmost byte");
|
|
1447
|
+
for (const d of f)
|
|
1448
|
+
i = i << 8 | d;
|
|
1449
|
+
if (r += a, i < 128)
|
|
1450
|
+
throw new n("tlv.decode(long): not minimal encoding");
|
|
1451
|
+
}
|
|
1452
|
+
const c = e.subarray(r, r + i);
|
|
1453
|
+
if (c.length !== i)
|
|
1454
|
+
throw new n("tlv.decode: wrong value length");
|
|
1455
|
+
return { v: c, l: e.subarray(r + i) };
|
|
1456
|
+
}
|
|
1457
|
+
},
|
|
1458
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
1459
|
+
// since we always use positive integers here. It must always be empty:
|
|
1460
|
+
// - add zero byte if exists
|
|
1461
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
1462
|
+
_int: {
|
|
1463
|
+
encode(t) {
|
|
1464
|
+
const { Err: e } = pt;
|
|
1465
|
+
if (t < it)
|
|
1466
|
+
throw new e("integer: negative integers are not allowed");
|
|
1467
|
+
let n = Yt(t);
|
|
1468
|
+
if (Number.parseInt(n[0], 16) & 8 && (n = "00" + n), n.length & 1)
|
|
1469
|
+
throw new e("unexpected DER parsing assertion: unpadded hex");
|
|
1470
|
+
return n;
|
|
1471
|
+
},
|
|
1472
|
+
decode(t) {
|
|
1473
|
+
const { Err: e } = pt;
|
|
1474
|
+
if (t[0] & 128)
|
|
1475
|
+
throw new e("invalid signature integer: negative");
|
|
1476
|
+
if (t[0] === 0 && !(t[1] & 128))
|
|
1477
|
+
throw new e("invalid signature integer: unnecessary leading zero");
|
|
1478
|
+
return ut(t);
|
|
1479
|
+
}
|
|
1480
|
+
},
|
|
1481
|
+
toSig(t) {
|
|
1482
|
+
const { Err: e, _int: n, _tlv: r } = pt, o = k(t, void 0, "signature"), { v: s, l: i } = r.decode(48, o);
|
|
1483
|
+
if (i.length)
|
|
1484
|
+
throw new e("invalid signature: left bytes after parsing");
|
|
1485
|
+
const { v: c, l: a } = r.decode(2, s), { v: f, l: d } = r.decode(2, a);
|
|
1486
|
+
if (d.length)
|
|
1487
|
+
throw new e("invalid signature: left bytes after parsing");
|
|
1488
|
+
return { r: n.decode(c), s: n.decode(f) };
|
|
1489
|
+
},
|
|
1490
|
+
hexFromSig(t) {
|
|
1491
|
+
const { _tlv: e, _int: n } = pt, r = e.encode(2, n.encode(t.r)), o = e.encode(2, n.encode(t.s)), s = r + o;
|
|
1492
|
+
return e.encode(48, s);
|
|
1493
|
+
}
|
|
1494
|
+
}, it = BigInt(0), It = BigInt(1), tn = BigInt(2), Xt = BigInt(3), To = BigInt(4);
|
|
1495
|
+
function No(t, e = {}) {
|
|
1496
|
+
const n = _o("weierstrass", t, e), { Fp: r, Fn: o } = n;
|
|
1497
|
+
let s = n.CURVE;
|
|
1498
|
+
const { h: i, n: c } = s;
|
|
1499
|
+
We(e, {}, {
|
|
1500
|
+
allowInfinityPoint: "boolean",
|
|
1501
|
+
clearCofactor: "function",
|
|
1502
|
+
isTorsionFree: "function",
|
|
1503
|
+
fromBytes: "function",
|
|
1504
|
+
toBytes: "function",
|
|
1505
|
+
endo: "object"
|
|
1506
|
+
});
|
|
1507
|
+
const { endo: a } = e;
|
|
1508
|
+
if (a && (!r.is0(s.a) || typeof a.beta != "bigint" || !Array.isArray(a.basises)))
|
|
1509
|
+
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
1510
|
+
const f = rn(r, o);
|
|
1511
|
+
function d() {
|
|
1512
|
+
if (!r.isOdd)
|
|
1513
|
+
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
1514
|
+
}
|
|
1515
|
+
function u(R, w, p) {
|
|
1516
|
+
const { x: h, y } = w.toAffine(), m = r.toBytes(h);
|
|
1517
|
+
if (ie(p, "isCompressed"), p) {
|
|
1518
|
+
d();
|
|
1519
|
+
const A = !r.isOdd(y);
|
|
1520
|
+
return et(en(A), m);
|
|
1521
|
+
} else
|
|
1522
|
+
return et(Uint8Array.of(4), m, r.toBytes(y));
|
|
1523
|
+
}
|
|
1524
|
+
function g(R) {
|
|
1525
|
+
k(R, void 0, "Point");
|
|
1526
|
+
const { publicKey: w, publicKeyUncompressed: p } = f, h = R.length, y = R[0], m = R.subarray(1);
|
|
1527
|
+
if (h === w && (y === 2 || y === 3)) {
|
|
1528
|
+
const A = r.fromBytes(m);
|
|
1529
|
+
if (!r.isValid(A))
|
|
1530
|
+
throw new Error("bad point: is not on curve, wrong x");
|
|
1531
|
+
const x = v(A);
|
|
1532
|
+
let E;
|
|
1533
|
+
try {
|
|
1534
|
+
E = r.sqrt(x);
|
|
1535
|
+
} catch (L) {
|
|
1536
|
+
const P = L instanceof Error ? ": " + L.message : "";
|
|
1537
|
+
throw new Error("bad point: is not on curve, sqrt error" + P);
|
|
1538
|
+
}
|
|
1539
|
+
d();
|
|
1540
|
+
const B = r.isOdd(E);
|
|
1541
|
+
return (y & 1) === 1 !== B && (E = r.neg(E)), { x: A, y: E };
|
|
1542
|
+
} else if (h === p && y === 4) {
|
|
1543
|
+
const A = r.BYTES, x = r.fromBytes(m.subarray(0, A)), E = r.fromBytes(m.subarray(A, A * 2));
|
|
1544
|
+
if (!S(x, E))
|
|
1545
|
+
throw new Error("bad point: is not on curve");
|
|
1546
|
+
return { x, y: E };
|
|
1547
|
+
} else
|
|
1548
|
+
throw new Error(`bad point: got length ${h}, expected compressed=${w} or uncompressed=${p}`);
|
|
1549
|
+
}
|
|
1550
|
+
const l = e.toBytes || u, b = e.fromBytes || g;
|
|
1551
|
+
function v(R) {
|
|
1552
|
+
const w = r.sqr(R), p = r.mul(w, R);
|
|
1553
|
+
return r.add(r.add(p, r.mul(R, s.a)), s.b);
|
|
1554
|
+
}
|
|
1555
|
+
function S(R, w) {
|
|
1556
|
+
const p = r.sqr(w), h = v(R);
|
|
1557
|
+
return r.eql(p, h);
|
|
1558
|
+
}
|
|
1559
|
+
if (!S(s.Gx, s.Gy))
|
|
1560
|
+
throw new Error("bad curve params: generator point");
|
|
1561
|
+
const O = r.mul(r.pow(s.a, Xt), To), V = r.mul(r.sqr(s.b), BigInt(27));
|
|
1562
|
+
if (r.is0(r.add(O, V)))
|
|
1563
|
+
throw new Error("bad curve params: a or b");
|
|
1564
|
+
function F(R, w, p = !1) {
|
|
1565
|
+
if (!r.isValid(w) || p && r.is0(w))
|
|
1566
|
+
throw new Error(`bad point coordinate ${R}`);
|
|
1567
|
+
return w;
|
|
1568
|
+
}
|
|
1569
|
+
function M(R) {
|
|
1570
|
+
if (!(R instanceof U))
|
|
1571
|
+
throw new Error("Weierstrass Point expected");
|
|
1572
|
+
}
|
|
1573
|
+
function C(R) {
|
|
1574
|
+
if (!a || !a.basises)
|
|
1575
|
+
throw new Error("no endo");
|
|
1576
|
+
return Ho(R, a.basises, o.ORDER);
|
|
1577
|
+
}
|
|
1578
|
+
const z = cr((R, w) => {
|
|
1579
|
+
const { X: p, Y: h, Z: y } = R;
|
|
1580
|
+
if (r.eql(y, r.ONE))
|
|
1581
|
+
return { x: p, y: h };
|
|
1582
|
+
const m = R.is0();
|
|
1583
|
+
w == null && (w = m ? r.ONE : r.inv(y));
|
|
1584
|
+
const A = r.mul(p, w), x = r.mul(h, w), E = r.mul(y, w);
|
|
1585
|
+
if (m)
|
|
1586
|
+
return { x: r.ZERO, y: r.ZERO };
|
|
1587
|
+
if (!r.eql(E, r.ONE))
|
|
1588
|
+
throw new Error("invZ was invalid");
|
|
1589
|
+
return { x: A, y: x };
|
|
1590
|
+
}), Ae = cr((R) => {
|
|
1591
|
+
if (R.is0()) {
|
|
1592
|
+
if (e.allowInfinityPoint && !r.is0(R.Y))
|
|
1593
|
+
return;
|
|
1594
|
+
throw new Error("bad point: ZERO");
|
|
1595
|
+
}
|
|
1596
|
+
const { x: w, y: p } = R.toAffine();
|
|
1597
|
+
if (!r.isValid(w) || !r.isValid(p))
|
|
1598
|
+
throw new Error("bad point: x or y not field elements");
|
|
1599
|
+
if (!S(w, p))
|
|
1600
|
+
throw new Error("bad point: equation left != right");
|
|
1601
|
+
if (!R.isTorsionFree())
|
|
1602
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
1603
|
+
return !0;
|
|
1604
|
+
});
|
|
1605
|
+
function Tt(R, w, p, h, y) {
|
|
1606
|
+
return p = new U(r.mul(p.X, R), p.Y, p.Z), w = ce(h, w), p = ce(y, p), w.add(p);
|
|
1607
|
+
}
|
|
1608
|
+
class U {
|
|
1609
|
+
// base / generator point
|
|
1610
|
+
static BASE = new U(s.Gx, s.Gy, r.ONE);
|
|
1611
|
+
// zero / infinity / identity point
|
|
1612
|
+
static ZERO = new U(r.ZERO, r.ONE, r.ZERO);
|
|
1613
|
+
// 0, 1, 0
|
|
1614
|
+
// math field
|
|
1615
|
+
static Fp = r;
|
|
1616
|
+
// scalar field
|
|
1617
|
+
static Fn = o;
|
|
1618
|
+
X;
|
|
1619
|
+
Y;
|
|
1620
|
+
Z;
|
|
1621
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1622
|
+
constructor(w, p, h) {
|
|
1623
|
+
this.X = F("x", w), this.Y = F("y", p, !0), this.Z = F("z", h), Object.freeze(this);
|
|
1624
|
+
}
|
|
1625
|
+
static CURVE() {
|
|
1626
|
+
return s;
|
|
1627
|
+
}
|
|
1628
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1629
|
+
static fromAffine(w) {
|
|
1630
|
+
const { x: p, y: h } = w || {};
|
|
1631
|
+
if (!w || !r.isValid(p) || !r.isValid(h))
|
|
1632
|
+
throw new Error("invalid affine point");
|
|
1633
|
+
if (w instanceof U)
|
|
1634
|
+
throw new Error("projective point not allowed");
|
|
1635
|
+
return r.is0(p) && r.is0(h) ? U.ZERO : new U(p, h, r.ONE);
|
|
1636
|
+
}
|
|
1637
|
+
static fromBytes(w) {
|
|
1638
|
+
const p = U.fromAffine(b(k(w, void 0, "point")));
|
|
1639
|
+
return p.assertValidity(), p;
|
|
1640
|
+
}
|
|
1641
|
+
static fromHex(w) {
|
|
1642
|
+
return U.fromBytes(se(w));
|
|
1643
|
+
}
|
|
1644
|
+
get x() {
|
|
1645
|
+
return this.toAffine().x;
|
|
1646
|
+
}
|
|
1647
|
+
get y() {
|
|
1648
|
+
return this.toAffine().y;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
*
|
|
1652
|
+
* @param windowSize
|
|
1653
|
+
* @param isLazy true will defer table computation until the first multiplication
|
|
1654
|
+
* @returns
|
|
1655
|
+
*/
|
|
1656
|
+
precompute(w = 8, p = !0) {
|
|
1657
|
+
return gt.createCache(this, w), p || this.multiply(Xt), this;
|
|
1658
|
+
}
|
|
1659
|
+
// TODO: return `this`
|
|
1660
|
+
/** A point on curve is valid if it conforms to equation. */
|
|
1661
|
+
assertValidity() {
|
|
1662
|
+
Ae(this);
|
|
1663
|
+
}
|
|
1664
|
+
hasEvenY() {
|
|
1665
|
+
const { y: w } = this.toAffine();
|
|
1666
|
+
if (!r.isOdd)
|
|
1667
|
+
throw new Error("Field doesn't support isOdd");
|
|
1668
|
+
return !r.isOdd(w);
|
|
1669
|
+
}
|
|
1670
|
+
/** Compare one point to another. */
|
|
1671
|
+
equals(w) {
|
|
1672
|
+
M(w);
|
|
1673
|
+
const { X: p, Y: h, Z: y } = this, { X: m, Y: A, Z: x } = w, E = r.eql(r.mul(p, x), r.mul(m, y)), B = r.eql(r.mul(h, x), r.mul(A, y));
|
|
1674
|
+
return E && B;
|
|
1675
|
+
}
|
|
1676
|
+
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
1677
|
+
negate() {
|
|
1678
|
+
return new U(this.X, r.neg(this.Y), this.Z);
|
|
1679
|
+
}
|
|
1680
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
1681
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1682
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1683
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1684
|
+
double() {
|
|
1685
|
+
const { a: w, b: p } = s, h = r.mul(p, Xt), { X: y, Y: m, Z: A } = this;
|
|
1686
|
+
let x = r.ZERO, E = r.ZERO, B = r.ZERO, I = r.mul(y, y), L = r.mul(m, m), P = r.mul(A, A), $ = r.mul(y, m);
|
|
1687
|
+
return $ = r.add($, $), B = r.mul(y, A), B = r.add(B, B), x = r.mul(w, B), E = r.mul(h, P), E = r.add(x, E), x = r.sub(L, E), E = r.add(L, E), E = r.mul(x, E), x = r.mul($, x), B = r.mul(h, B), P = r.mul(w, P), $ = r.sub(I, P), $ = r.mul(w, $), $ = r.add($, B), B = r.add(I, I), I = r.add(B, I), I = r.add(I, P), I = r.mul(I, $), E = r.add(E, I), P = r.mul(m, A), P = r.add(P, P), I = r.mul(P, $), x = r.sub(x, I), B = r.mul(P, L), B = r.add(B, B), B = r.add(B, B), new U(x, E, B);
|
|
1688
|
+
}
|
|
1689
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
1690
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1691
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1692
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1693
|
+
add(w) {
|
|
1694
|
+
M(w);
|
|
1695
|
+
const { X: p, Y: h, Z: y } = this, { X: m, Y: A, Z: x } = w;
|
|
1696
|
+
let E = r.ZERO, B = r.ZERO, I = r.ZERO;
|
|
1697
|
+
const L = s.a, P = r.mul(s.b, Xt);
|
|
1698
|
+
let $ = r.mul(p, m), _ = r.mul(h, A), D = r.mul(y, x), J = r.add(p, h), H = r.add(m, A);
|
|
1699
|
+
J = r.mul(J, H), H = r.add($, _), J = r.sub(J, H), H = r.add(p, y);
|
|
1700
|
+
let W = r.add(m, x);
|
|
1701
|
+
return H = r.mul(H, W), W = r.add($, D), H = r.sub(H, W), W = r.add(h, y), E = r.add(A, x), W = r.mul(W, E), E = r.add(_, D), W = r.sub(W, E), I = r.mul(L, H), E = r.mul(P, D), I = r.add(E, I), E = r.sub(_, I), I = r.add(_, I), B = r.mul(E, I), _ = r.add($, $), _ = r.add(_, $), D = r.mul(L, D), H = r.mul(P, H), _ = r.add(_, D), D = r.sub($, D), D = r.mul(L, D), H = r.add(H, D), $ = r.mul(_, H), B = r.add(B, $), $ = r.mul(W, H), E = r.mul(J, E), E = r.sub(E, $), $ = r.mul(J, _), I = r.mul(W, I), I = r.add(I, $), new U(E, B, I);
|
|
1702
|
+
}
|
|
1703
|
+
subtract(w) {
|
|
1704
|
+
return this.add(w.negate());
|
|
1705
|
+
}
|
|
1706
|
+
is0() {
|
|
1707
|
+
return this.equals(U.ZERO);
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Constant time multiplication.
|
|
1711
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
1712
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
1713
|
+
* Uses precomputes when available.
|
|
1714
|
+
* Uses endomorphism for Koblitz curves.
|
|
1715
|
+
* @param scalar by which the point would be multiplied
|
|
1716
|
+
* @returns New point
|
|
1717
|
+
*/
|
|
1718
|
+
multiply(w) {
|
|
1719
|
+
const { endo: p } = e;
|
|
1720
|
+
if (!o.isValidNot0(w))
|
|
1721
|
+
throw new Error("invalid scalar: out of range");
|
|
1722
|
+
let h, y;
|
|
1723
|
+
const m = (A) => gt.cached(this, A, (x) => ur(U, x));
|
|
1724
|
+
if (p) {
|
|
1725
|
+
const { k1neg: A, k1: x, k2neg: E, k2: B } = C(w), { p: I, f: L } = m(x), { p: P, f: $ } = m(B);
|
|
1726
|
+
y = L.add($), h = Tt(p.beta, I, P, A, E);
|
|
1727
|
+
} else {
|
|
1728
|
+
const { p: A, f: x } = m(w);
|
|
1729
|
+
h = A, y = x;
|
|
1730
|
+
}
|
|
1731
|
+
return ur(U, [h, y])[0];
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1735
|
+
* It's faster, but should only be used when you don't care about
|
|
1736
|
+
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
1737
|
+
*/
|
|
1738
|
+
multiplyUnsafe(w) {
|
|
1739
|
+
const { endo: p } = e, h = this;
|
|
1740
|
+
if (!o.isValid(w))
|
|
1741
|
+
throw new Error("invalid scalar: out of range");
|
|
1742
|
+
if (w === it || h.is0())
|
|
1743
|
+
return U.ZERO;
|
|
1744
|
+
if (w === It)
|
|
1745
|
+
return h;
|
|
1746
|
+
if (gt.hasCache(this))
|
|
1747
|
+
return this.multiply(w);
|
|
1748
|
+
if (p) {
|
|
1749
|
+
const { k1neg: y, k1: m, k2neg: A, k2: x } = C(w), { p1: E, p2: B } = Po(U, h, m, x);
|
|
1750
|
+
return Tt(p.beta, E, B, y, A);
|
|
1751
|
+
} else
|
|
1752
|
+
return gt.unsafe(h, w);
|
|
1753
|
+
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Converts Projective point to affine (x, y) coordinates.
|
|
1756
|
+
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
1757
|
+
*/
|
|
1758
|
+
toAffine(w) {
|
|
1759
|
+
return z(this, w);
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
1763
|
+
* Always torsion-free for cofactor=1 curves.
|
|
1764
|
+
*/
|
|
1765
|
+
isTorsionFree() {
|
|
1766
|
+
const { isTorsionFree: w } = e;
|
|
1767
|
+
return i === It ? !0 : w ? w(U, this) : gt.unsafe(this, c).is0();
|
|
1768
|
+
}
|
|
1769
|
+
clearCofactor() {
|
|
1770
|
+
const { clearCofactor: w } = e;
|
|
1771
|
+
return i === It ? this : w ? w(U, this) : this.multiplyUnsafe(i);
|
|
1772
|
+
}
|
|
1773
|
+
isSmallOrder() {
|
|
1774
|
+
return this.multiplyUnsafe(i).is0();
|
|
1775
|
+
}
|
|
1776
|
+
toBytes(w = !0) {
|
|
1777
|
+
return ie(w, "isCompressed"), this.assertValidity(), l(U, this, w);
|
|
1778
|
+
}
|
|
1779
|
+
toHex(w = !0) {
|
|
1780
|
+
return le(this.toBytes(w));
|
|
1781
|
+
}
|
|
1782
|
+
toString() {
|
|
1783
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
const Ft = o.BITS, gt = new ko(U, e.endo ? Math.ceil(Ft / 2) : Ft);
|
|
1787
|
+
return U.BASE.precompute(8), U;
|
|
1788
|
+
}
|
|
1789
|
+
function en(t) {
|
|
1790
|
+
return Uint8Array.of(t ? 2 : 3);
|
|
1791
|
+
}
|
|
1792
|
+
function rn(t, e) {
|
|
1793
|
+
return {
|
|
1794
|
+
secretKey: e.BYTES,
|
|
1795
|
+
publicKey: 1 + t.BYTES,
|
|
1796
|
+
publicKeyUncompressed: 1 + 2 * t.BYTES,
|
|
1797
|
+
publicKeyHasPrefix: !0,
|
|
1798
|
+
signature: 2 * e.BYTES
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
function Co(t, e = {}) {
|
|
1802
|
+
const { Fn: n } = t, r = e.randomBytes || pe, o = Object.assign(rn(t.Fp, n), { seed: Zr(n.ORDER) });
|
|
1803
|
+
function s(l) {
|
|
1804
|
+
try {
|
|
1805
|
+
const b = n.fromBytes(l);
|
|
1806
|
+
return n.isValidNot0(b);
|
|
1807
|
+
} catch {
|
|
1808
|
+
return !1;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
function i(l, b) {
|
|
1812
|
+
const { publicKey: v, publicKeyUncompressed: S } = o;
|
|
1813
|
+
try {
|
|
1814
|
+
const O = l.length;
|
|
1815
|
+
return b === !0 && O !== v || b === !1 && O !== S ? !1 : !!t.fromBytes(l);
|
|
1816
|
+
} catch {
|
|
1817
|
+
return !1;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
function c(l = r(o.seed)) {
|
|
1821
|
+
return zr(k(l, o.seed, "seed"), n.ORDER);
|
|
1822
|
+
}
|
|
1823
|
+
function a(l, b = !0) {
|
|
1824
|
+
return t.BASE.multiply(n.fromBytes(l)).toBytes(b);
|
|
1825
|
+
}
|
|
1826
|
+
function f(l) {
|
|
1827
|
+
const { secretKey: b, publicKey: v, publicKeyUncompressed: S } = o;
|
|
1828
|
+
if (!Ke(l) || "_lengths" in n && n._lengths || b === v)
|
|
1829
|
+
return;
|
|
1830
|
+
const O = k(l, void 0, "key").length;
|
|
1831
|
+
return O === v || O === S;
|
|
1832
|
+
}
|
|
1833
|
+
function d(l, b, v = !0) {
|
|
1834
|
+
if (f(l) === !0)
|
|
1835
|
+
throw new Error("first arg must be private key");
|
|
1836
|
+
if (f(b) === !1)
|
|
1837
|
+
throw new Error("second arg must be public key");
|
|
1838
|
+
const S = n.fromBytes(l);
|
|
1839
|
+
return t.fromBytes(b).multiply(S).toBytes(v);
|
|
1840
|
+
}
|
|
1841
|
+
const u = {
|
|
1842
|
+
isValidSecretKey: s,
|
|
1843
|
+
isValidPublicKey: i,
|
|
1844
|
+
randomSecretKey: c
|
|
1845
|
+
}, g = Xr(c, a);
|
|
1846
|
+
return Object.freeze({ getPublicKey: a, getSharedSecret: d, keygen: g, Point: t, utils: u, lengths: o });
|
|
1847
|
+
}
|
|
1848
|
+
function Do(t, e, n = {}) {
|
|
1849
|
+
Ur(e), We(n, {}, {
|
|
1850
|
+
hmac: "function",
|
|
1851
|
+
lowS: "boolean",
|
|
1852
|
+
randomBytes: "function",
|
|
1853
|
+
bits2int: "function",
|
|
1854
|
+
bits2int_modN: "function"
|
|
1855
|
+
}), n = Object.assign({}, n);
|
|
1856
|
+
const r = n.randomBytes || pe, o = n.hmac || ((p, h) => Jr(e, p, h)), { Fp: s, Fn: i } = t, { ORDER: c, BITS: a } = i, { keygen: f, getPublicKey: d, getSharedSecret: u, utils: g, lengths: l } = Co(t, n), b = {
|
|
1857
|
+
prehash: !0,
|
|
1858
|
+
lowS: typeof n.lowS == "boolean" ? n.lowS : !0,
|
|
1859
|
+
format: "compact",
|
|
1860
|
+
extraEntropy: !1
|
|
1861
|
+
}, v = c * tn < s.ORDER;
|
|
1862
|
+
function S(p) {
|
|
1863
|
+
const h = c >> It;
|
|
1864
|
+
return p > h;
|
|
1865
|
+
}
|
|
1866
|
+
function O(p, h) {
|
|
1867
|
+
if (!i.isValidNot0(h))
|
|
1868
|
+
throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);
|
|
1869
|
+
return h;
|
|
1870
|
+
}
|
|
1871
|
+
function V() {
|
|
1872
|
+
if (v)
|
|
1873
|
+
throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
|
|
1874
|
+
}
|
|
1875
|
+
function F(p, h) {
|
|
1876
|
+
_e(h);
|
|
1877
|
+
const y = l.signature, m = h === "compact" ? y : h === "recovered" ? y + 1 : void 0;
|
|
1878
|
+
return k(p, m);
|
|
1879
|
+
}
|
|
1880
|
+
class M {
|
|
1881
|
+
r;
|
|
1882
|
+
s;
|
|
1883
|
+
recovery;
|
|
1884
|
+
constructor(h, y, m) {
|
|
1885
|
+
if (this.r = O("r", h), this.s = O("s", y), m != null) {
|
|
1886
|
+
if (V(), ![0, 1, 2, 3].includes(m))
|
|
1887
|
+
throw new Error("invalid recovery id");
|
|
1888
|
+
this.recovery = m;
|
|
1889
|
+
}
|
|
1890
|
+
Object.freeze(this);
|
|
1891
|
+
}
|
|
1892
|
+
static fromBytes(h, y = b.format) {
|
|
1893
|
+
F(h, y);
|
|
1894
|
+
let m;
|
|
1895
|
+
if (y === "der") {
|
|
1896
|
+
const { r: B, s: I } = pt.toSig(k(h));
|
|
1897
|
+
return new M(B, I);
|
|
1898
|
+
}
|
|
1899
|
+
y === "recovered" && (m = h[0], y = "compact", h = h.subarray(1));
|
|
1900
|
+
const A = l.signature / 2, x = h.subarray(0, A), E = h.subarray(A, A * 2);
|
|
1901
|
+
return new M(i.fromBytes(x), i.fromBytes(E), m);
|
|
1902
|
+
}
|
|
1903
|
+
static fromHex(h, y) {
|
|
1904
|
+
return this.fromBytes(se(h), y);
|
|
1905
|
+
}
|
|
1906
|
+
assertRecovery() {
|
|
1907
|
+
const { recovery: h } = this;
|
|
1908
|
+
if (h == null)
|
|
1909
|
+
throw new Error("invalid recovery id: must be present");
|
|
1910
|
+
return h;
|
|
1911
|
+
}
|
|
1912
|
+
addRecoveryBit(h) {
|
|
1913
|
+
return new M(this.r, this.s, h);
|
|
1914
|
+
}
|
|
1915
|
+
recoverPublicKey(h) {
|
|
1916
|
+
const { r: y, s: m } = this, A = this.assertRecovery(), x = A === 2 || A === 3 ? y + c : y;
|
|
1917
|
+
if (!s.isValid(x))
|
|
1918
|
+
throw new Error("invalid recovery id: sig.r+curve.n != R.x");
|
|
1919
|
+
const E = s.toBytes(x), B = t.fromBytes(et(en((A & 1) === 0), E)), I = i.inv(x), L = z(k(h, void 0, "msgHash")), P = i.create(-L * I), $ = i.create(m * I), _ = t.BASE.multiplyUnsafe(P).add(B.multiplyUnsafe($));
|
|
1920
|
+
if (_.is0())
|
|
1921
|
+
throw new Error("invalid recovery: point at infinify");
|
|
1922
|
+
return _.assertValidity(), _;
|
|
1923
|
+
}
|
|
1924
|
+
// Signatures should be low-s, to prevent malleability.
|
|
1925
|
+
hasHighS() {
|
|
1926
|
+
return S(this.s);
|
|
1927
|
+
}
|
|
1928
|
+
toBytes(h = b.format) {
|
|
1929
|
+
if (_e(h), h === "der")
|
|
1930
|
+
return se(pt.hexFromSig(this));
|
|
1931
|
+
const { r: y, s: m } = this, A = i.toBytes(y), x = i.toBytes(m);
|
|
1932
|
+
return h === "recovered" ? (V(), et(Uint8Array.of(this.assertRecovery()), A, x)) : et(A, x);
|
|
1933
|
+
}
|
|
1934
|
+
toHex(h) {
|
|
1935
|
+
return le(this.toBytes(h));
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
const C = n.bits2int || function(h) {
|
|
1939
|
+
if (h.length > 8192)
|
|
1940
|
+
throw new Error("input is too large");
|
|
1941
|
+
const y = ut(h), m = h.length * 8 - a;
|
|
1942
|
+
return m > 0 ? y >> BigInt(m) : y;
|
|
1943
|
+
}, z = n.bits2int_modN || function(h) {
|
|
1944
|
+
return i.create(C(h));
|
|
1945
|
+
}, Ae = Me(a);
|
|
1946
|
+
function Tt(p) {
|
|
1947
|
+
return bo("num < 2^" + a, p, it, Ae), i.toBytes(p);
|
|
1948
|
+
}
|
|
1949
|
+
function U(p, h) {
|
|
1950
|
+
return k(p, void 0, "message"), h ? k(e(p), void 0, "prehashed message") : p;
|
|
1951
|
+
}
|
|
1952
|
+
function Ft(p, h, y) {
|
|
1953
|
+
const { lowS: m, prehash: A, extraEntropy: x } = $e(y, b);
|
|
1954
|
+
p = U(p, A);
|
|
1955
|
+
const E = z(p), B = i.fromBytes(h);
|
|
1956
|
+
if (!i.isValidNot0(B))
|
|
1957
|
+
throw new Error("invalid private key");
|
|
1958
|
+
const I = [Tt(B), Tt(E)];
|
|
1959
|
+
if (x != null && x !== !1) {
|
|
1960
|
+
const _ = x === !0 ? r(l.secretKey) : x;
|
|
1961
|
+
I.push(k(_, void 0, "extraEntropy"));
|
|
1962
|
+
}
|
|
1963
|
+
const L = et(...I), P = E;
|
|
1964
|
+
function $(_) {
|
|
1965
|
+
const D = C(_);
|
|
1966
|
+
if (!i.isValidNot0(D))
|
|
1967
|
+
return;
|
|
1968
|
+
const J = i.inv(D), H = t.BASE.multiply(D).toAffine(), W = i.create(H.x);
|
|
1969
|
+
if (W === it)
|
|
1970
|
+
return;
|
|
1971
|
+
const Zt = i.create(J * i.create(P + W * B));
|
|
1972
|
+
if (Zt === it)
|
|
1973
|
+
return;
|
|
1974
|
+
let Je = (H.x === W ? 0 : 2) | Number(H.y & It), tr = Zt;
|
|
1975
|
+
return m && S(Zt) && (tr = i.neg(Zt), Je ^= 1), new M(W, tr, v ? void 0 : Je);
|
|
1976
|
+
}
|
|
1977
|
+
return { seed: L, k2sig: $ };
|
|
1978
|
+
}
|
|
1979
|
+
function gt(p, h, y = {}) {
|
|
1980
|
+
const { seed: m, k2sig: A } = Ft(p, h, y);
|
|
1981
|
+
return mo(e.outputLen, i.BYTES, o)(m, A).toBytes(y.format);
|
|
1982
|
+
}
|
|
1983
|
+
function R(p, h, y, m = {}) {
|
|
1984
|
+
const { lowS: A, prehash: x, format: E } = $e(m, b);
|
|
1985
|
+
if (y = k(y, void 0, "publicKey"), h = U(h, x), !Ke(p)) {
|
|
1986
|
+
const B = p instanceof M ? ", use sig.toBytes()" : "";
|
|
1987
|
+
throw new Error("verify expects Uint8Array signature" + B);
|
|
1988
|
+
}
|
|
1989
|
+
F(p, E);
|
|
1990
|
+
try {
|
|
1991
|
+
const B = M.fromBytes(p, E), I = t.fromBytes(y);
|
|
1992
|
+
if (A && B.hasHighS())
|
|
1993
|
+
return !1;
|
|
1994
|
+
const { r: L, s: P } = B, $ = z(h), _ = i.inv(P), D = i.create($ * _), J = i.create(L * _), H = t.BASE.multiplyUnsafe(D).add(I.multiplyUnsafe(J));
|
|
1995
|
+
return H.is0() ? !1 : i.create(H.x) === L;
|
|
1996
|
+
} catch {
|
|
1997
|
+
return !1;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
function w(p, h, y = {}) {
|
|
2001
|
+
const { prehash: m } = $e(y, b);
|
|
2002
|
+
return h = U(h, m), M.fromBytes(p, "recovered").recoverPublicKey(h).toBytes();
|
|
2003
|
+
}
|
|
2004
|
+
return Object.freeze({
|
|
2005
|
+
keygen: f,
|
|
2006
|
+
getPublicKey: d,
|
|
2007
|
+
getSharedSecret: u,
|
|
2008
|
+
utils: g,
|
|
2009
|
+
lengths: l,
|
|
2010
|
+
Point: t,
|
|
2011
|
+
sign: gt,
|
|
2012
|
+
verify: R,
|
|
2013
|
+
recoverPublicKey: w,
|
|
2014
|
+
Signature: M,
|
|
2015
|
+
hash: e
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
const ye = {
|
|
2019
|
+
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
2020
|
+
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
2021
|
+
h: BigInt(1),
|
|
2022
|
+
a: BigInt(0),
|
|
2023
|
+
b: BigInt(7),
|
|
2024
|
+
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
2025
|
+
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
2026
|
+
}, Ko = {
|
|
2027
|
+
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
2028
|
+
basises: [
|
|
2029
|
+
[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
|
|
2030
|
+
[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
|
|
2031
|
+
]
|
|
2032
|
+
}, Vo = /* @__PURE__ */ BigInt(0), He = /* @__PURE__ */ BigInt(2);
|
|
2033
|
+
function Mo(t) {
|
|
2034
|
+
const e = ye.p, n = BigInt(3), r = BigInt(6), o = BigInt(11), s = BigInt(22), i = BigInt(23), c = BigInt(44), a = BigInt(88), f = t * t * t % e, d = f * f * t % e, u = G(d, n, e) * d % e, g = G(u, n, e) * d % e, l = G(g, He, e) * f % e, b = G(l, o, e) * l % e, v = G(b, s, e) * b % e, S = G(v, c, e) * v % e, O = G(S, a, e) * S % e, V = G(O, c, e) * v % e, F = G(V, n, e) * d % e, M = G(F, i, e) * b % e, C = G(M, r, e) * f % e, z = G(C, He, e);
|
|
2035
|
+
if (!ae.eql(ae.sqr(z), t))
|
|
2036
|
+
throw new Error("Cannot find square root");
|
|
2037
|
+
return z;
|
|
2038
|
+
}
|
|
2039
|
+
const ae = ge(ye.p, { sqrt: Mo }), Bt = /* @__PURE__ */ No(ye, {
|
|
2040
|
+
Fp: ae,
|
|
2041
|
+
endo: Ko
|
|
2042
|
+
}), vt = /* @__PURE__ */ Do(Bt, at), wr = {};
|
|
2043
|
+
function fe(t, ...e) {
|
|
2044
|
+
let n = wr[t];
|
|
2045
|
+
if (n === void 0) {
|
|
2046
|
+
const r = at(go(t));
|
|
2047
|
+
n = et(r, r), wr[t] = n;
|
|
2048
|
+
}
|
|
2049
|
+
return at(et(n, ...e));
|
|
2050
|
+
}
|
|
2051
|
+
const je = (t) => t.toBytes(!0).slice(1), Fe = (t) => t % He === Vo;
|
|
2052
|
+
function Le(t) {
|
|
2053
|
+
const { Fn: e, BASE: n } = Bt, r = e.fromBytes(t), o = n.multiply(r);
|
|
2054
|
+
return { scalar: Fe(o.y) ? r : e.neg(r), bytes: je(o) };
|
|
2055
|
+
}
|
|
2056
|
+
function nn(t) {
|
|
2057
|
+
const e = ae;
|
|
2058
|
+
if (!e.isValidNot0(t))
|
|
2059
|
+
throw new Error("invalid x: Fail if x ≥ p");
|
|
2060
|
+
const n = e.create(t * t), r = e.create(n * t + BigInt(7));
|
|
2061
|
+
let o = e.sqrt(r);
|
|
2062
|
+
Fe(o) || (o = e.neg(o));
|
|
2063
|
+
const s = Bt.fromAffine({ x: t, y: o });
|
|
2064
|
+
return s.assertValidity(), s;
|
|
2065
|
+
}
|
|
2066
|
+
const Dt = ut;
|
|
2067
|
+
function on(...t) {
|
|
2068
|
+
return Bt.Fn.create(Dt(fe("BIP0340/challenge", ...t)));
|
|
2069
|
+
}
|
|
2070
|
+
function gr(t) {
|
|
2071
|
+
return Le(t).bytes;
|
|
2072
|
+
}
|
|
2073
|
+
function Wo(t, e, n = pe(32)) {
|
|
2074
|
+
const { Fn: r } = Bt, o = k(t, void 0, "message"), { bytes: s, scalar: i } = Le(e), c = k(n, 32, "auxRand"), a = r.toBytes(i ^ Dt(fe("BIP0340/aux", c))), f = fe("BIP0340/nonce", a, s, o), { bytes: d, scalar: u } = Le(f), g = on(d, s, o), l = new Uint8Array(64);
|
|
2075
|
+
if (l.set(d, 0), l.set(r.toBytes(r.create(u + g * i)), 32), !sn(l, o, s))
|
|
2076
|
+
throw new Error("sign: Invalid signature produced");
|
|
2077
|
+
return l;
|
|
2078
|
+
}
|
|
2079
|
+
function sn(t, e, n) {
|
|
2080
|
+
const { Fp: r, Fn: o, BASE: s } = Bt, i = k(t, 64, "signature"), c = k(e, void 0, "message"), a = k(n, 32, "publicKey");
|
|
2081
|
+
try {
|
|
2082
|
+
const f = nn(Dt(a)), d = Dt(i.subarray(0, 32));
|
|
2083
|
+
if (!r.isValidNot0(d))
|
|
2084
|
+
return !1;
|
|
2085
|
+
const u = Dt(i.subarray(32, 64));
|
|
2086
|
+
if (!o.isValidNot0(u))
|
|
2087
|
+
return !1;
|
|
2088
|
+
const g = on(o.toBytes(d), je(f), c), l = s.multiplyUnsafe(u).add(f.multiplyUnsafe(o.neg(g))), { x: b, y: v } = l.toAffine();
|
|
2089
|
+
return !(l.is0() || !Fe(v) || b !== d);
|
|
2090
|
+
} catch {
|
|
2091
|
+
return !1;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
const St = /* @__PURE__ */ (() => {
|
|
2095
|
+
const n = (r = pe(48)) => zr(r, ye.n);
|
|
2096
|
+
return {
|
|
2097
|
+
keygen: Xr(n, gr),
|
|
2098
|
+
getPublicKey: gr,
|
|
2099
|
+
sign: Wo,
|
|
2100
|
+
verify: sn,
|
|
2101
|
+
Point: Bt,
|
|
2102
|
+
utils: {
|
|
2103
|
+
randomSecretKey: n,
|
|
2104
|
+
taggedHash: fe,
|
|
2105
|
+
lift_x: nn,
|
|
2106
|
+
pointToBytes: je
|
|
2107
|
+
},
|
|
2108
|
+
lengths: {
|
|
2109
|
+
secretKey: 32,
|
|
2110
|
+
publicKey: 32,
|
|
2111
|
+
publicKeyHasPrefix: !1,
|
|
2112
|
+
signature: 64,
|
|
2113
|
+
seed: 48
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
})(), qo = /* @__PURE__ */ Uint8Array.from([
|
|
2117
|
+
7,
|
|
2118
|
+
4,
|
|
2119
|
+
13,
|
|
2120
|
+
1,
|
|
2121
|
+
10,
|
|
2122
|
+
6,
|
|
2123
|
+
15,
|
|
2124
|
+
3,
|
|
2125
|
+
12,
|
|
2126
|
+
0,
|
|
2127
|
+
9,
|
|
2128
|
+
5,
|
|
2129
|
+
2,
|
|
2130
|
+
14,
|
|
2131
|
+
11,
|
|
2132
|
+
8
|
|
2133
|
+
]), cn = Uint8Array.from(new Array(16).fill(0).map((t, e) => e)), jo = cn.map((t) => (9 * t + 5) % 16), an = /* @__PURE__ */ (() => {
|
|
2134
|
+
const n = [[cn], [jo]];
|
|
2135
|
+
for (let r = 0; r < 4; r++)
|
|
2136
|
+
for (let o of n)
|
|
2137
|
+
o.push(o[r].map((s) => qo[s]));
|
|
2138
|
+
return n;
|
|
2139
|
+
})(), fn = an[0], un = an[1], dn = /* @__PURE__ */ [
|
|
2140
|
+
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
2141
|
+
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
2142
|
+
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
2143
|
+
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
2144
|
+
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
2145
|
+
].map((t) => Uint8Array.from(t)), Fo = /* @__PURE__ */ fn.map((t, e) => t.map((n) => dn[e][n])), Zo = /* @__PURE__ */ un.map((t, e) => t.map((n) => dn[e][n])), zo = /* @__PURE__ */ Uint32Array.from([
|
|
2146
|
+
0,
|
|
2147
|
+
1518500249,
|
|
2148
|
+
1859775393,
|
|
2149
|
+
2400959708,
|
|
2150
|
+
2840853838
|
|
2151
|
+
]), Go = /* @__PURE__ */ Uint32Array.from([
|
|
2152
|
+
1352829926,
|
|
2153
|
+
1548603684,
|
|
2154
|
+
1836072691,
|
|
2155
|
+
2053994217,
|
|
2156
|
+
0
|
|
2157
|
+
]);
|
|
2158
|
+
function yr(t, e, n, r) {
|
|
2159
|
+
return t === 0 ? e ^ n ^ r : t === 1 ? e & n | ~e & r : t === 2 ? (e | ~n) ^ r : t === 3 ? e & r | n & ~r : e ^ (n | ~r);
|
|
2160
|
+
}
|
|
2161
|
+
const Qt = /* @__PURE__ */ new Uint32Array(16);
|
|
2162
|
+
class Yo extends _r {
|
|
2163
|
+
h0 = 1732584193;
|
|
2164
|
+
h1 = -271733879;
|
|
2165
|
+
h2 = -1732584194;
|
|
2166
|
+
h3 = 271733878;
|
|
2167
|
+
h4 = -1009589776;
|
|
2168
|
+
constructor() {
|
|
2169
|
+
super(64, 20, 8, !0);
|
|
2170
|
+
}
|
|
2171
|
+
get() {
|
|
2172
|
+
const { h0: e, h1: n, h2: r, h3: o, h4: s } = this;
|
|
2173
|
+
return [e, n, r, o, s];
|
|
2174
|
+
}
|
|
2175
|
+
set(e, n, r, o, s) {
|
|
2176
|
+
this.h0 = e | 0, this.h1 = n | 0, this.h2 = r | 0, this.h3 = o | 0, this.h4 = s | 0;
|
|
2177
|
+
}
|
|
2178
|
+
process(e, n) {
|
|
2179
|
+
for (let l = 0; l < 16; l++, n += 4)
|
|
2180
|
+
Qt[l] = e.getUint32(n, !0);
|
|
2181
|
+
let r = this.h0 | 0, o = r, s = this.h1 | 0, i = s, c = this.h2 | 0, a = c, f = this.h3 | 0, d = f, u = this.h4 | 0, g = u;
|
|
2182
|
+
for (let l = 0; l < 5; l++) {
|
|
2183
|
+
const b = 4 - l, v = zo[l], S = Go[l], O = fn[l], V = un[l], F = Fo[l], M = Zo[l];
|
|
2184
|
+
for (let C = 0; C < 16; C++) {
|
|
2185
|
+
const z = Gt(r + yr(l, s, c, f) + Qt[O[C]] + v, F[C]) + u | 0;
|
|
2186
|
+
r = u, u = f, f = Gt(c, 10) | 0, c = s, s = z;
|
|
2187
|
+
}
|
|
2188
|
+
for (let C = 0; C < 16; C++) {
|
|
2189
|
+
const z = Gt(o + yr(b, i, a, d) + Qt[V[C]] + S, M[C]) + g | 0;
|
|
2190
|
+
o = g, g = d, d = Gt(a, 10) | 0, a = i, i = z;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
this.set(this.h1 + c + d | 0, this.h2 + f + g | 0, this.h3 + u + o | 0, this.h4 + r + i | 0, this.h0 + s + a | 0);
|
|
2194
|
+
}
|
|
2195
|
+
roundClean() {
|
|
2196
|
+
Ot(Qt);
|
|
2197
|
+
}
|
|
2198
|
+
destroy() {
|
|
2199
|
+
this.destroyed = !0, Ot(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
const Xo = /* @__PURE__ */ Pr(() => new Yo()), Qo = /* @__PURE__ */ Uint8Array.of(), si = /* @__PURE__ */ Uint8Array.of(0);
|
|
2203
|
+
function Ut(t, e) {
|
|
2204
|
+
if (t.length !== e.length)
|
|
2205
|
+
return !1;
|
|
2206
|
+
for (let n = 0; n < t.length; n++)
|
|
2207
|
+
if (t[n] !== e[n])
|
|
2208
|
+
return !1;
|
|
2209
|
+
return !0;
|
|
2210
|
+
}
|
|
2211
|
+
function Y(t) {
|
|
2212
|
+
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
2213
|
+
}
|
|
2214
|
+
function Jo(...t) {
|
|
2215
|
+
let e = 0;
|
|
2216
|
+
for (let r = 0; r < t.length; r++) {
|
|
2217
|
+
const o = t[r];
|
|
2218
|
+
if (!Y(o))
|
|
2219
|
+
throw new Error("Uint8Array expected");
|
|
2220
|
+
e += o.length;
|
|
2221
|
+
}
|
|
2222
|
+
const n = new Uint8Array(e);
|
|
2223
|
+
for (let r = 0, o = 0; r < t.length; r++) {
|
|
2224
|
+
const s = t[r];
|
|
2225
|
+
n.set(s, o), o += s.length;
|
|
2226
|
+
}
|
|
2227
|
+
return n;
|
|
2228
|
+
}
|
|
2229
|
+
const hn = (t) => new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
2230
|
+
function Wt(t) {
|
|
2231
|
+
return Object.prototype.toString.call(t) === "[object Object]";
|
|
2232
|
+
}
|
|
2233
|
+
function ot(t) {
|
|
2234
|
+
return Number.isSafeInteger(t);
|
|
2235
|
+
}
|
|
2236
|
+
const Ze = {
|
|
2237
|
+
equalBytes: Ut,
|
|
2238
|
+
isBytes: Y,
|
|
2239
|
+
concatBytes: Jo
|
|
2240
|
+
}, ln = (t) => {
|
|
2241
|
+
if (t !== null && typeof t != "string" && !Q(t) && !Y(t) && !ot(t))
|
|
2242
|
+
throw new Error(`lengthCoder: expected null | number | Uint8Array | CoderType, got ${t} (${typeof t})`);
|
|
2243
|
+
return {
|
|
2244
|
+
encodeStream(e, n) {
|
|
2245
|
+
if (t === null)
|
|
2246
|
+
return;
|
|
2247
|
+
if (Q(t))
|
|
2248
|
+
return t.encodeStream(e, n);
|
|
2249
|
+
let r;
|
|
2250
|
+
if (typeof t == "number" ? r = t : typeof t == "string" && (r = ft.resolve(e.stack, t)), typeof r == "bigint" && (r = Number(r)), r === void 0 || r !== n)
|
|
2251
|
+
throw e.err(`Wrong length: ${r} len=${t} exp=${n} (${typeof n})`);
|
|
2252
|
+
},
|
|
2253
|
+
decodeStream(e) {
|
|
2254
|
+
let n;
|
|
2255
|
+
if (Q(t) ? n = Number(t.decodeStream(e)) : typeof t == "number" ? n = t : typeof t == "string" && (n = ft.resolve(e.stack, t)), typeof n == "bigint" && (n = Number(n)), typeof n != "number")
|
|
2256
|
+
throw e.err(`Wrong length: ${n}`);
|
|
2257
|
+
return n;
|
|
2258
|
+
}
|
|
2259
|
+
};
|
|
2260
|
+
}, T = {
|
|
2261
|
+
BITS: 32,
|
|
2262
|
+
FULL_MASK: -1 >>> 0,
|
|
2263
|
+
// 1<<32 will overflow
|
|
2264
|
+
len: (t) => Math.ceil(t / 32),
|
|
2265
|
+
create: (t) => new Uint32Array(T.len(t)),
|
|
2266
|
+
clean: (t) => t.fill(0),
|
|
2267
|
+
debug: (t) => Array.from(t).map((e) => (e >>> 0).toString(2).padStart(32, "0")),
|
|
2268
|
+
checkLen: (t, e) => {
|
|
2269
|
+
if (T.len(e) !== t.length)
|
|
2270
|
+
throw new Error(`wrong length=${t.length}. Expected: ${T.len(e)}`);
|
|
2271
|
+
},
|
|
2272
|
+
chunkLen: (t, e, n) => {
|
|
2273
|
+
if (e < 0)
|
|
2274
|
+
throw new Error(`wrong pos=${e}`);
|
|
2275
|
+
if (e + n > t)
|
|
2276
|
+
throw new Error(`wrong range=${e}/${n} of ${t}`);
|
|
2277
|
+
},
|
|
2278
|
+
set: (t, e, n, r = !0) => !r && (t[e] & n) !== 0 ? !1 : (t[e] |= n, !0),
|
|
2279
|
+
pos: (t, e) => ({
|
|
2280
|
+
chunk: Math.floor((t + e) / 32),
|
|
2281
|
+
mask: 1 << 32 - (t + e) % 32 - 1
|
|
2282
|
+
}),
|
|
2283
|
+
indices: (t, e, n = !1) => {
|
|
2284
|
+
T.checkLen(t, e);
|
|
2285
|
+
const { FULL_MASK: r, BITS: o } = T, s = o - e % o, i = s ? r >>> s << s : r, c = [];
|
|
2286
|
+
for (let a = 0; a < t.length; a++) {
|
|
2287
|
+
let f = t[a];
|
|
2288
|
+
if (n && (f = ~f), a === t.length - 1 && (f &= i), f !== 0)
|
|
2289
|
+
for (let d = 0; d < o; d++) {
|
|
2290
|
+
const u = 1 << o - d - 1;
|
|
2291
|
+
f & u && c.push(a * o + d);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
return c;
|
|
2295
|
+
},
|
|
2296
|
+
range: (t) => {
|
|
2297
|
+
const e = [];
|
|
2298
|
+
let n;
|
|
2299
|
+
for (const r of t)
|
|
2300
|
+
n === void 0 || r !== n.pos + n.length ? e.push(n = { pos: r, length: 1 }) : n.length += 1;
|
|
2301
|
+
return e;
|
|
2302
|
+
},
|
|
2303
|
+
rangeDebug: (t, e, n = !1) => `[${T.range(T.indices(t, e, n)).map((r) => `(${r.pos}/${r.length})`).join(", ")}]`,
|
|
2304
|
+
setRange: (t, e, n, r, o = !0) => {
|
|
2305
|
+
T.chunkLen(e, n, r);
|
|
2306
|
+
const { FULL_MASK: s, BITS: i } = T, c = n % i ? Math.floor(n / i) : void 0, a = n + r, f = a % i ? Math.floor(a / i) : void 0;
|
|
2307
|
+
if (c !== void 0 && c === f)
|
|
2308
|
+
return T.set(t, c, s >>> i - r << i - r - n, o);
|
|
2309
|
+
if (c !== void 0 && !T.set(t, c, s >>> n % i, o))
|
|
2310
|
+
return !1;
|
|
2311
|
+
const d = c !== void 0 ? c + 1 : n / i, u = f !== void 0 ? f : a / i;
|
|
2312
|
+
for (let g = d; g < u; g++)
|
|
2313
|
+
if (!T.set(t, g, s, o))
|
|
2314
|
+
return !1;
|
|
2315
|
+
return !(f !== void 0 && c !== f && !T.set(t, f, s << i - a % i, o));
|
|
2316
|
+
}
|
|
2317
|
+
}, ft = {
|
|
2318
|
+
/**
|
|
2319
|
+
* Internal method for handling stack of paths (debug, errors, dynamic fields via path)
|
|
2320
|
+
* This is looks ugly (callback), but allows us to force stack cleaning by construction (.pop always after function).
|
|
2321
|
+
* Also, this makes impossible:
|
|
2322
|
+
* - pushing field when stack is empty
|
|
2323
|
+
* - pushing field inside of field (real bug)
|
|
2324
|
+
* NOTE: we don't want to do '.pop' on error!
|
|
2325
|
+
*/
|
|
2326
|
+
pushObj: (t, e, n) => {
|
|
2327
|
+
const r = { obj: e };
|
|
2328
|
+
t.push(r), n((o, s) => {
|
|
2329
|
+
r.field = o, s(), r.field = void 0;
|
|
2330
|
+
}), t.pop();
|
|
2331
|
+
},
|
|
2332
|
+
path: (t) => {
|
|
2333
|
+
const e = [];
|
|
2334
|
+
for (const n of t)
|
|
2335
|
+
n.field !== void 0 && e.push(n.field);
|
|
2336
|
+
return e.join("/");
|
|
2337
|
+
},
|
|
2338
|
+
err: (t, e, n) => {
|
|
2339
|
+
const r = new Error(`${t}(${ft.path(e)}): ${typeof n == "string" ? n : n.message}`);
|
|
2340
|
+
return n instanceof Error && n.stack && (r.stack = n.stack), r;
|
|
2341
|
+
},
|
|
2342
|
+
resolve: (t, e) => {
|
|
2343
|
+
const n = e.split("/"), r = t.map((i) => i.obj);
|
|
2344
|
+
let o = 0;
|
|
2345
|
+
for (; o < n.length && n[o] === ".."; o++)
|
|
2346
|
+
r.pop();
|
|
2347
|
+
let s = r.pop();
|
|
2348
|
+
for (; o < n.length; o++) {
|
|
2349
|
+
if (!s || s[n[o]] === void 0)
|
|
2350
|
+
return;
|
|
2351
|
+
s = s[n[o]];
|
|
2352
|
+
}
|
|
2353
|
+
return s;
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
class ze {
|
|
2357
|
+
pos = 0;
|
|
2358
|
+
data;
|
|
2359
|
+
opts;
|
|
2360
|
+
stack;
|
|
2361
|
+
parent;
|
|
2362
|
+
parentOffset;
|
|
2363
|
+
bitBuf = 0;
|
|
2364
|
+
bitPos = 0;
|
|
2365
|
+
bs;
|
|
2366
|
+
// bitset
|
|
2367
|
+
view;
|
|
2368
|
+
constructor(e, n = {}, r = [], o = void 0, s = 0) {
|
|
2369
|
+
this.data = e, this.opts = n, this.stack = r, this.parent = o, this.parentOffset = s, this.view = hn(e);
|
|
2370
|
+
}
|
|
2371
|
+
/** Internal method for pointers. */
|
|
2372
|
+
_enablePointers() {
|
|
2373
|
+
if (this.parent)
|
|
2374
|
+
return this.parent._enablePointers();
|
|
2375
|
+
this.bs || (this.bs = T.create(this.data.length), T.setRange(this.bs, this.data.length, 0, this.pos, this.opts.allowMultipleReads));
|
|
2376
|
+
}
|
|
2377
|
+
markBytesBS(e, n) {
|
|
2378
|
+
return this.parent ? this.parent.markBytesBS(this.parentOffset + e, n) : !n || !this.bs ? !0 : T.setRange(this.bs, this.data.length, e, n, !1);
|
|
2379
|
+
}
|
|
2380
|
+
markBytes(e) {
|
|
2381
|
+
const n = this.pos;
|
|
2382
|
+
this.pos += e;
|
|
2383
|
+
const r = this.markBytesBS(n, e);
|
|
2384
|
+
if (!this.opts.allowMultipleReads && !r)
|
|
2385
|
+
throw this.err(`multiple read pos=${this.pos} len=${e}`);
|
|
2386
|
+
return r;
|
|
2387
|
+
}
|
|
2388
|
+
pushObj(e, n) {
|
|
2389
|
+
return ft.pushObj(this.stack, e, n);
|
|
2390
|
+
}
|
|
2391
|
+
readView(e, n) {
|
|
2392
|
+
if (!Number.isFinite(e))
|
|
2393
|
+
throw this.err(`readView: wrong length=${e}`);
|
|
2394
|
+
if (this.pos + e > this.data.length)
|
|
2395
|
+
throw this.err("readView: Unexpected end of buffer");
|
|
2396
|
+
const r = n(this.view, this.pos);
|
|
2397
|
+
return this.markBytes(e), r;
|
|
2398
|
+
}
|
|
2399
|
+
// read bytes by absolute offset
|
|
2400
|
+
absBytes(e) {
|
|
2401
|
+
if (e > this.data.length)
|
|
2402
|
+
throw new Error("Unexpected end of buffer");
|
|
2403
|
+
return this.data.subarray(e);
|
|
2404
|
+
}
|
|
2405
|
+
finish() {
|
|
2406
|
+
if (!this.opts.allowUnreadBytes) {
|
|
2407
|
+
if (this.bitPos)
|
|
2408
|
+
throw this.err(`${this.bitPos} bits left after unpack: ${rt.encode(this.data.slice(this.pos))}`);
|
|
2409
|
+
if (this.bs && !this.parent) {
|
|
2410
|
+
const e = T.indices(this.bs, this.data.length, !0);
|
|
2411
|
+
if (e.length) {
|
|
2412
|
+
const n = T.range(e).map(({ pos: r, length: o }) => `(${r}/${o})[${rt.encode(this.data.subarray(r, r + o))}]`).join(", ");
|
|
2413
|
+
throw this.err(`unread byte ranges: ${n} (total=${this.data.length})`);
|
|
2414
|
+
} else
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
if (!this.isEnd())
|
|
2418
|
+
throw this.err(`${this.leftBytes} bytes ${this.bitPos} bits left after unpack: ${rt.encode(this.data.slice(this.pos))}`);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
// User methods
|
|
2422
|
+
err(e) {
|
|
2423
|
+
return ft.err("Reader", this.stack, e);
|
|
2424
|
+
}
|
|
2425
|
+
offsetReader(e) {
|
|
2426
|
+
if (e > this.data.length)
|
|
2427
|
+
throw this.err("offsetReader: Unexpected end of buffer");
|
|
2428
|
+
return new ze(this.absBytes(e), this.opts, this.stack, this, e);
|
|
2429
|
+
}
|
|
2430
|
+
bytes(e, n = !1) {
|
|
2431
|
+
if (this.bitPos)
|
|
2432
|
+
throw this.err("readBytes: bitPos not empty");
|
|
2433
|
+
if (!Number.isFinite(e))
|
|
2434
|
+
throw this.err(`readBytes: wrong length=${e}`);
|
|
2435
|
+
if (this.pos + e > this.data.length)
|
|
2436
|
+
throw this.err("readBytes: Unexpected end of buffer");
|
|
2437
|
+
const r = this.data.subarray(this.pos, this.pos + e);
|
|
2438
|
+
return n || this.markBytes(e), r;
|
|
2439
|
+
}
|
|
2440
|
+
byte(e = !1) {
|
|
2441
|
+
if (this.bitPos)
|
|
2442
|
+
throw this.err("readByte: bitPos not empty");
|
|
2443
|
+
if (this.pos + 1 > this.data.length)
|
|
2444
|
+
throw this.err("readBytes: Unexpected end of buffer");
|
|
2445
|
+
const n = this.data[this.pos];
|
|
2446
|
+
return e || this.markBytes(1), n;
|
|
2447
|
+
}
|
|
2448
|
+
get leftBytes() {
|
|
2449
|
+
return this.data.length - this.pos;
|
|
2450
|
+
}
|
|
2451
|
+
get totalBytes() {
|
|
2452
|
+
return this.data.length;
|
|
2453
|
+
}
|
|
2454
|
+
isEnd() {
|
|
2455
|
+
return this.pos >= this.data.length && !this.bitPos;
|
|
2456
|
+
}
|
|
2457
|
+
// bits are read in BE mode (left to right): (0b1000_0000).readBits(1) == 1
|
|
2458
|
+
bits(e) {
|
|
2459
|
+
if (e > 32)
|
|
2460
|
+
throw this.err("BitReader: cannot read more than 32 bits in single call");
|
|
2461
|
+
let n = 0;
|
|
2462
|
+
for (; e; ) {
|
|
2463
|
+
this.bitPos || (this.bitBuf = this.byte(), this.bitPos = 8);
|
|
2464
|
+
const r = Math.min(e, this.bitPos);
|
|
2465
|
+
this.bitPos -= r, n = n << r | this.bitBuf >> this.bitPos & 2 ** r - 1, this.bitBuf &= 2 ** this.bitPos - 1, e -= r;
|
|
2466
|
+
}
|
|
2467
|
+
return n >>> 0;
|
|
2468
|
+
}
|
|
2469
|
+
find(e, n = this.pos) {
|
|
2470
|
+
if (!Y(e))
|
|
2471
|
+
throw this.err(`find: needle is not bytes! ${e}`);
|
|
2472
|
+
if (this.bitPos)
|
|
2473
|
+
throw this.err("findByte: bitPos not empty");
|
|
2474
|
+
if (!e.length)
|
|
2475
|
+
throw this.err("find: needle is empty");
|
|
2476
|
+
for (let r = n; (r = this.data.indexOf(e[0], r)) !== -1; r++) {
|
|
2477
|
+
if (r === -1 || this.data.length - r < e.length)
|
|
2478
|
+
return;
|
|
2479
|
+
if (Ut(e, this.data.subarray(r, r + e.length)))
|
|
2480
|
+
return r;
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
class ts {
|
|
2485
|
+
pos = 0;
|
|
2486
|
+
stack;
|
|
2487
|
+
// We could have a single buffer here and re-alloc it with
|
|
2488
|
+
// x1.5-2 size each time it full, but it will be slower:
|
|
2489
|
+
// basic/encode bench: 395ns -> 560ns
|
|
2490
|
+
buffers = [];
|
|
2491
|
+
ptrs = [];
|
|
2492
|
+
bitBuf = 0;
|
|
2493
|
+
bitPos = 0;
|
|
2494
|
+
viewBuf = new Uint8Array(8);
|
|
2495
|
+
view;
|
|
2496
|
+
finished = !1;
|
|
2497
|
+
constructor(e = []) {
|
|
2498
|
+
this.stack = e, this.view = hn(this.viewBuf);
|
|
2499
|
+
}
|
|
2500
|
+
pushObj(e, n) {
|
|
2501
|
+
return ft.pushObj(this.stack, e, n);
|
|
2502
|
+
}
|
|
2503
|
+
writeView(e, n) {
|
|
2504
|
+
if (this.finished)
|
|
2505
|
+
throw this.err("buffer: finished");
|
|
2506
|
+
if (!ot(e) || e > 8)
|
|
2507
|
+
throw new Error(`wrong writeView length=${e}`);
|
|
2508
|
+
n(this.view), this.bytes(this.viewBuf.slice(0, e)), this.viewBuf.fill(0);
|
|
2509
|
+
}
|
|
2510
|
+
// User methods
|
|
2511
|
+
err(e) {
|
|
2512
|
+
if (this.finished)
|
|
2513
|
+
throw this.err("buffer: finished");
|
|
2514
|
+
return ft.err("Reader", this.stack, e);
|
|
2515
|
+
}
|
|
2516
|
+
bytes(e) {
|
|
2517
|
+
if (this.finished)
|
|
2518
|
+
throw this.err("buffer: finished");
|
|
2519
|
+
if (this.bitPos)
|
|
2520
|
+
throw this.err("writeBytes: ends with non-empty bit buffer");
|
|
2521
|
+
this.buffers.push(e), this.pos += e.length;
|
|
2522
|
+
}
|
|
2523
|
+
byte(e) {
|
|
2524
|
+
if (this.finished)
|
|
2525
|
+
throw this.err("buffer: finished");
|
|
2526
|
+
if (this.bitPos)
|
|
2527
|
+
throw this.err("writeByte: ends with non-empty bit buffer");
|
|
2528
|
+
this.buffers.push(new Uint8Array([e])), this.pos++;
|
|
2529
|
+
}
|
|
2530
|
+
finish(e = !0) {
|
|
2531
|
+
if (this.finished)
|
|
2532
|
+
throw this.err("buffer: finished");
|
|
2533
|
+
if (this.bitPos)
|
|
2534
|
+
throw this.err("buffer: ends with non-empty bit buffer");
|
|
2535
|
+
const n = this.buffers.concat(this.ptrs.map((s) => s.buffer)), r = n.map((s) => s.length).reduce((s, i) => s + i, 0), o = new Uint8Array(r);
|
|
2536
|
+
for (let s = 0, i = 0; s < n.length; s++) {
|
|
2537
|
+
const c = n[s];
|
|
2538
|
+
o.set(c, i), i += c.length;
|
|
2539
|
+
}
|
|
2540
|
+
for (let s = this.pos, i = 0; i < this.ptrs.length; i++) {
|
|
2541
|
+
const c = this.ptrs[i];
|
|
2542
|
+
o.set(c.ptr.encode(s), c.pos), s += c.buffer.length;
|
|
2543
|
+
}
|
|
2544
|
+
if (e) {
|
|
2545
|
+
this.buffers = [];
|
|
2546
|
+
for (const s of this.ptrs)
|
|
2547
|
+
s.buffer.fill(0);
|
|
2548
|
+
this.ptrs = [], this.finished = !0, this.bitBuf = 0;
|
|
2549
|
+
}
|
|
2550
|
+
return o;
|
|
2551
|
+
}
|
|
2552
|
+
bits(e, n) {
|
|
2553
|
+
if (n > 32)
|
|
2554
|
+
throw this.err("writeBits: cannot write more than 32 bits in single call");
|
|
2555
|
+
if (e >= 2 ** n)
|
|
2556
|
+
throw this.err(`writeBits: value (${e}) >= 2**bits (${n})`);
|
|
2557
|
+
for (; n; ) {
|
|
2558
|
+
const r = Math.min(n, 8 - this.bitPos);
|
|
2559
|
+
this.bitBuf = this.bitBuf << r | e >> n - r, this.bitPos += r, n -= r, e &= 2 ** n - 1, this.bitPos === 8 && (this.bitPos = 0, this.buffers.push(new Uint8Array([this.bitBuf])), this.pos++);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
const Te = (t) => Uint8Array.from(t).reverse();
|
|
2564
|
+
function es(t, e, n) {
|
|
2565
|
+
if (n) {
|
|
2566
|
+
const r = 2n ** (e - 1n);
|
|
2567
|
+
if (t < -r || t >= r)
|
|
2568
|
+
throw new Error(`value out of signed bounds. Expected ${-r} <= ${t} < ${r}`);
|
|
2569
|
+
} else if (0n > t || t >= 2n ** e)
|
|
2570
|
+
throw new Error(`value out of unsigned bounds. Expected 0 <= ${t} < ${2n ** e}`);
|
|
2571
|
+
}
|
|
2572
|
+
function pn(t) {
|
|
2573
|
+
return {
|
|
2574
|
+
// NOTE: we cannot export validate here, since it is likely mistake.
|
|
2575
|
+
encodeStream: t.encodeStream,
|
|
2576
|
+
decodeStream: t.decodeStream,
|
|
2577
|
+
size: t.size,
|
|
2578
|
+
encode: (e) => {
|
|
2579
|
+
const n = new ts();
|
|
2580
|
+
return t.encodeStream(n, e), n.finish();
|
|
2581
|
+
},
|
|
2582
|
+
decode: (e, n = {}) => {
|
|
2583
|
+
const r = new ze(e, n), o = t.decodeStream(r);
|
|
2584
|
+
return r.finish(), o;
|
|
2585
|
+
}
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
function be(t, e) {
|
|
2589
|
+
if (!Q(t))
|
|
2590
|
+
throw new Error(`validate: invalid inner value ${t}`);
|
|
2591
|
+
if (typeof e != "function")
|
|
2592
|
+
throw new Error("validate: fn should be function");
|
|
2593
|
+
return pn({
|
|
2594
|
+
size: t.size,
|
|
2595
|
+
encodeStream: (n, r) => {
|
|
2596
|
+
let o;
|
|
2597
|
+
try {
|
|
2598
|
+
o = e(r);
|
|
2599
|
+
} catch (s) {
|
|
2600
|
+
throw n.err(s);
|
|
2601
|
+
}
|
|
2602
|
+
t.encodeStream(n, o);
|
|
2603
|
+
},
|
|
2604
|
+
decodeStream: (n) => {
|
|
2605
|
+
const r = t.decodeStream(n);
|
|
2606
|
+
try {
|
|
2607
|
+
return e(r);
|
|
2608
|
+
} catch (o) {
|
|
2609
|
+
throw n.err(o);
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
const Z = (t) => {
|
|
2615
|
+
const e = pn(t);
|
|
2616
|
+
return t.validate ? be(e, t.validate) : e;
|
|
2617
|
+
}, Ee = (t) => Wt(t) && typeof t.decode == "function" && typeof t.encode == "function";
|
|
2618
|
+
function Q(t) {
|
|
2619
|
+
return Wt(t) && Ee(t) && typeof t.encodeStream == "function" && typeof t.decodeStream == "function" && (t.size === void 0 || ot(t.size));
|
|
2620
|
+
}
|
|
2621
|
+
function rs() {
|
|
2622
|
+
return {
|
|
2623
|
+
encode: (t) => {
|
|
2624
|
+
if (!Array.isArray(t))
|
|
2625
|
+
throw new Error("array expected");
|
|
2626
|
+
const e = {};
|
|
2627
|
+
for (const n of t) {
|
|
2628
|
+
if (!Array.isArray(n) || n.length !== 2)
|
|
2629
|
+
throw new Error("array of two elements expected");
|
|
2630
|
+
const r = n[0], o = n[1];
|
|
2631
|
+
if (e[r] !== void 0)
|
|
2632
|
+
throw new Error(`key(${r}) appears twice in struct`);
|
|
2633
|
+
e[r] = o;
|
|
2634
|
+
}
|
|
2635
|
+
return e;
|
|
2636
|
+
},
|
|
2637
|
+
decode: (t) => {
|
|
2638
|
+
if (!Wt(t))
|
|
2639
|
+
throw new Error(`expected plain object, got ${t}`);
|
|
2640
|
+
return Object.entries(t);
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
const ns = {
|
|
2645
|
+
encode: (t) => {
|
|
2646
|
+
if (typeof t != "bigint")
|
|
2647
|
+
throw new Error(`expected bigint, got ${typeof t}`);
|
|
2648
|
+
if (t > BigInt(Number.MAX_SAFE_INTEGER))
|
|
2649
|
+
throw new Error(`element bigger than MAX_SAFE_INTEGER=${t}`);
|
|
2650
|
+
return Number(t);
|
|
2651
|
+
},
|
|
2652
|
+
decode: (t) => {
|
|
2653
|
+
if (!ot(t))
|
|
2654
|
+
throw new Error("element is not a safe integer");
|
|
2655
|
+
return BigInt(t);
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
function os(t) {
|
|
2659
|
+
if (!Wt(t))
|
|
2660
|
+
throw new Error("plain object expected");
|
|
2661
|
+
return {
|
|
2662
|
+
encode: (e) => {
|
|
2663
|
+
if (!ot(e) || !(e in t))
|
|
2664
|
+
throw new Error(`wrong value ${e}`);
|
|
2665
|
+
return t[e];
|
|
2666
|
+
},
|
|
2667
|
+
decode: (e) => {
|
|
2668
|
+
if (typeof e != "string")
|
|
2669
|
+
throw new Error(`wrong value ${typeof e}`);
|
|
2670
|
+
return t[e];
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
}
|
|
2674
|
+
function ss(t, e = !1) {
|
|
2675
|
+
if (!ot(t))
|
|
2676
|
+
throw new Error(`decimal/precision: wrong value ${t}`);
|
|
2677
|
+
if (typeof e != "boolean")
|
|
2678
|
+
throw new Error(`decimal/round: expected boolean, got ${typeof e}`);
|
|
2679
|
+
const n = 10n ** BigInt(t);
|
|
2680
|
+
return {
|
|
2681
|
+
encode: (r) => {
|
|
2682
|
+
if (typeof r != "bigint")
|
|
2683
|
+
throw new Error(`expected bigint, got ${typeof r}`);
|
|
2684
|
+
let o = (r < 0n ? -r : r).toString(10), s = o.length - t;
|
|
2685
|
+
s < 0 && (o = o.padStart(o.length - s, "0"), s = 0);
|
|
2686
|
+
let i = o.length - 1;
|
|
2687
|
+
for (; i >= s && o[i] === "0"; i--)
|
|
2688
|
+
;
|
|
2689
|
+
let c = o.slice(0, s), a = o.slice(s, i + 1);
|
|
2690
|
+
return c || (c = "0"), r < 0n && (c = "-" + c), a ? `${c}.${a}` : c;
|
|
2691
|
+
},
|
|
2692
|
+
decode: (r) => {
|
|
2693
|
+
if (typeof r != "string")
|
|
2694
|
+
throw new Error(`expected string, got ${typeof r}`);
|
|
2695
|
+
if (r === "-0")
|
|
2696
|
+
throw new Error("negative zero is not allowed");
|
|
2697
|
+
let o = !1;
|
|
2698
|
+
if (r.startsWith("-") && (o = !0, r = r.slice(1)), !/^(0|[1-9]\d*)(\.\d+)?$/.test(r))
|
|
2699
|
+
throw new Error(`wrong string value=${r}`);
|
|
2700
|
+
let s = r.indexOf(".");
|
|
2701
|
+
s = s === -1 ? r.length : s;
|
|
2702
|
+
const i = r.slice(0, s), c = r.slice(s + 1).replace(/0+$/, ""), a = BigInt(i) * n;
|
|
2703
|
+
if (!e && c.length > t)
|
|
2704
|
+
throw new Error(`fractional part cannot be represented with this precision (num=${r}, prec=${t})`);
|
|
2705
|
+
const f = Math.min(c.length, t), d = BigInt(c.slice(0, f)) * 10n ** BigInt(t - f), u = a + d;
|
|
2706
|
+
return o ? -u : u;
|
|
2707
|
+
}
|
|
2708
|
+
};
|
|
2709
|
+
}
|
|
2710
|
+
function is(t) {
|
|
2711
|
+
if (!Array.isArray(t))
|
|
2712
|
+
throw new Error(`expected array, got ${typeof t}`);
|
|
2713
|
+
for (const e of t)
|
|
2714
|
+
if (!Ee(e))
|
|
2715
|
+
throw new Error(`wrong base coder ${e}`);
|
|
2716
|
+
return {
|
|
2717
|
+
encode: (e) => {
|
|
2718
|
+
for (const n of t) {
|
|
2719
|
+
const r = n.encode(e);
|
|
2720
|
+
if (r !== void 0)
|
|
2721
|
+
return r;
|
|
2722
|
+
}
|
|
2723
|
+
throw new Error(`match/encode: cannot find match in ${e}`);
|
|
2724
|
+
},
|
|
2725
|
+
decode: (e) => {
|
|
2726
|
+
for (const n of t) {
|
|
2727
|
+
const r = n.decode(e);
|
|
2728
|
+
if (r !== void 0)
|
|
2729
|
+
return r;
|
|
2730
|
+
}
|
|
2731
|
+
throw new Error(`match/decode: cannot find match in ${e}`);
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
const wn = (t) => {
|
|
2736
|
+
if (!Ee(t))
|
|
2737
|
+
throw new Error("BaseCoder expected");
|
|
2738
|
+
return { encode: t.decode, decode: t.encode };
|
|
2739
|
+
}, gn = { dict: rs, numberBigint: ns, tsEnum: os, decimal: ss, match: is, reverse: wn }, Ge = (t, e = !1, n = !1, r = !0) => {
|
|
2740
|
+
if (!ot(t))
|
|
2741
|
+
throw new Error(`bigint/size: wrong value ${t}`);
|
|
2742
|
+
if (typeof e != "boolean")
|
|
2743
|
+
throw new Error(`bigint/le: expected boolean, got ${typeof e}`);
|
|
2744
|
+
if (typeof n != "boolean")
|
|
2745
|
+
throw new Error(`bigint/signed: expected boolean, got ${typeof n}`);
|
|
2746
|
+
if (typeof r != "boolean")
|
|
2747
|
+
throw new Error(`bigint/sized: expected boolean, got ${typeof r}`);
|
|
2748
|
+
const o = BigInt(t), s = 2n ** (8n * o - 1n);
|
|
2749
|
+
return Z({
|
|
2750
|
+
size: r ? t : void 0,
|
|
2751
|
+
encodeStream: (i, c) => {
|
|
2752
|
+
n && c < 0 && (c = c | s);
|
|
2753
|
+
const a = [];
|
|
2754
|
+
for (let d = 0; d < t; d++)
|
|
2755
|
+
a.push(Number(c & 255n)), c >>= 8n;
|
|
2756
|
+
let f = new Uint8Array(a).reverse();
|
|
2757
|
+
if (!r) {
|
|
2758
|
+
let d = 0;
|
|
2759
|
+
for (d = 0; d < f.length && f[d] === 0; d++)
|
|
2760
|
+
;
|
|
2761
|
+
f = f.subarray(d);
|
|
2762
|
+
}
|
|
2763
|
+
i.bytes(e ? f.reverse() : f);
|
|
2764
|
+
},
|
|
2765
|
+
decodeStream: (i) => {
|
|
2766
|
+
const c = i.bytes(r ? t : Math.min(t, i.leftBytes)), a = e ? c : Te(c);
|
|
2767
|
+
let f = 0n;
|
|
2768
|
+
for (let d = 0; d < a.length; d++)
|
|
2769
|
+
f |= BigInt(a[d]) << 8n * BigInt(d);
|
|
2770
|
+
return n && f & s && (f = (f ^ s) - s), f;
|
|
2771
|
+
},
|
|
2772
|
+
validate: (i) => {
|
|
2773
|
+
if (typeof i != "bigint")
|
|
2774
|
+
throw new Error(`bigint: invalid value: ${i}`);
|
|
2775
|
+
return es(i, 8n * o, !!n), i;
|
|
2776
|
+
}
|
|
2777
|
+
});
|
|
2778
|
+
}, ii = /* @__PURE__ */ Ge(32, !1), cs = /* @__PURE__ */ Ge(8, !0), ci = /* @__PURE__ */ Ge(8, !0, !0), as = (t, e) => Z({
|
|
2779
|
+
size: t,
|
|
2780
|
+
encodeStream: (n, r) => n.writeView(t, (o) => e.write(o, r)),
|
|
2781
|
+
decodeStream: (n) => n.readView(t, e.read),
|
|
2782
|
+
validate: (n) => {
|
|
2783
|
+
if (typeof n != "number")
|
|
2784
|
+
throw new Error(`viewCoder: expected number, got ${typeof n}`);
|
|
2785
|
+
return e.validate && e.validate(n), n;
|
|
2786
|
+
}
|
|
2787
|
+
}), qt = (t, e, n) => {
|
|
2788
|
+
const r = t * 8, o = 2 ** (r - 1), s = (a) => {
|
|
2789
|
+
if (!ot(a))
|
|
2790
|
+
throw new Error(`sintView: value is not safe integer: ${a}`);
|
|
2791
|
+
if (a < -o || a >= o)
|
|
2792
|
+
throw new Error(`sintView: value out of bounds. Expected ${-o} <= ${a} < ${o}`);
|
|
2793
|
+
}, i = 2 ** r, c = (a) => {
|
|
2794
|
+
if (!ot(a))
|
|
2795
|
+
throw new Error(`uintView: value is not safe integer: ${a}`);
|
|
2796
|
+
if (0 > a || a >= i)
|
|
2797
|
+
throw new Error(`uintView: value out of bounds. Expected 0 <= ${a} < ${i}`);
|
|
2798
|
+
};
|
|
2799
|
+
return as(t, {
|
|
2800
|
+
write: n.write,
|
|
2801
|
+
read: n.read,
|
|
2802
|
+
validate: e ? s : c
|
|
2803
|
+
});
|
|
2804
|
+
}, xt = /* @__PURE__ */ qt(4, !1, {
|
|
2805
|
+
read: (t, e) => t.getUint32(e, !0),
|
|
2806
|
+
write: (t, e) => t.setUint32(0, e, !0)
|
|
2807
|
+
}), ai = /* @__PURE__ */ qt(4, !1, {
|
|
2808
|
+
read: (t, e) => t.getUint32(e, !1),
|
|
2809
|
+
write: (t, e) => t.setUint32(0, e, !1)
|
|
2810
|
+
}), yn = /* @__PURE__ */ qt(4, !0, {
|
|
2811
|
+
read: (t, e) => t.getInt32(e, !0),
|
|
2812
|
+
write: (t, e) => t.setInt32(0, e, !0)
|
|
2813
|
+
}), br = /* @__PURE__ */ qt(2, !1, {
|
|
2814
|
+
read: (t, e) => t.getUint16(e, !0),
|
|
2815
|
+
write: (t, e) => t.setUint16(0, e, !0)
|
|
2816
|
+
}), fs = /* @__PURE__ */ qt(1, !1, {
|
|
2817
|
+
read: (t, e) => t.getUint8(e),
|
|
2818
|
+
write: (t, e) => t.setUint8(0, e)
|
|
2819
|
+
}), jt = (t, e = !1) => {
|
|
2820
|
+
if (typeof e != "boolean")
|
|
2821
|
+
throw new Error(`bytes/le: expected boolean, got ${typeof e}`);
|
|
2822
|
+
const n = ln(t), r = Y(t);
|
|
2823
|
+
return Z({
|
|
2824
|
+
size: typeof t == "number" ? t : void 0,
|
|
2825
|
+
encodeStream: (o, s) => {
|
|
2826
|
+
r || n.encodeStream(o, s.length), o.bytes(e ? Te(s) : s), r && o.bytes(t);
|
|
2827
|
+
},
|
|
2828
|
+
decodeStream: (o) => {
|
|
2829
|
+
let s;
|
|
2830
|
+
if (r) {
|
|
2831
|
+
const i = o.find(t);
|
|
2832
|
+
if (!i)
|
|
2833
|
+
throw o.err("bytes: cannot find terminator");
|
|
2834
|
+
s = o.bytes(i - o.pos), o.bytes(t.length);
|
|
2835
|
+
} else
|
|
2836
|
+
s = o.bytes(t === null ? o.leftBytes : n.decodeStream(o));
|
|
2837
|
+
return e ? Te(s) : s;
|
|
2838
|
+
},
|
|
2839
|
+
validate: (o) => {
|
|
2840
|
+
if (!Y(o))
|
|
2841
|
+
throw new Error(`bytes: invalid value ${o}`);
|
|
2842
|
+
return o;
|
|
2843
|
+
}
|
|
2844
|
+
});
|
|
2845
|
+
};
|
|
2846
|
+
function fi(t, e) {
|
|
2847
|
+
if (!Q(e))
|
|
2848
|
+
throw new Error(`prefix: invalid inner value ${e}`);
|
|
2849
|
+
return kt(jt(t), wn(e));
|
|
2850
|
+
}
|
|
2851
|
+
const ui = (t, e = !1) => be(kt(jt(t, e), no), (n) => {
|
|
2852
|
+
if (typeof n != "string")
|
|
2853
|
+
throw new Error(`expected string, got ${typeof n}`);
|
|
2854
|
+
return n;
|
|
2855
|
+
}), di = (t, e = { isLE: !1, with0x: !1 }) => {
|
|
2856
|
+
let n = kt(jt(t, e.isLE), rt);
|
|
2857
|
+
const r = e.with0x;
|
|
2858
|
+
if (typeof r != "boolean")
|
|
2859
|
+
throw new Error(`hex/with0x: expected boolean, got ${typeof r}`);
|
|
2860
|
+
return r && (n = kt(n, {
|
|
2861
|
+
encode: (o) => `0x${o}`,
|
|
2862
|
+
decode: (o) => {
|
|
2863
|
+
if (!o.startsWith("0x"))
|
|
2864
|
+
throw new Error("hex(with0x=true).encode input should start with 0x");
|
|
2865
|
+
return o.slice(2);
|
|
2866
|
+
}
|
|
2867
|
+
})), n;
|
|
2868
|
+
};
|
|
2869
|
+
function kt(t, e) {
|
|
2870
|
+
if (!Q(t))
|
|
2871
|
+
throw new Error(`apply: invalid inner value ${t}`);
|
|
2872
|
+
if (!Ee(e))
|
|
2873
|
+
throw new Error(`apply: invalid base value ${t}`);
|
|
2874
|
+
return Z({
|
|
2875
|
+
size: t.size,
|
|
2876
|
+
encodeStream: (n, r) => {
|
|
2877
|
+
let o;
|
|
2878
|
+
try {
|
|
2879
|
+
o = e.decode(r);
|
|
2880
|
+
} catch (s) {
|
|
2881
|
+
throw n.err("" + s);
|
|
2882
|
+
}
|
|
2883
|
+
return t.encodeStream(n, o);
|
|
2884
|
+
},
|
|
2885
|
+
decodeStream: (n) => {
|
|
2886
|
+
const r = t.decodeStream(n);
|
|
2887
|
+
try {
|
|
2888
|
+
return e.encode(r);
|
|
2889
|
+
} catch (o) {
|
|
2890
|
+
throw n.err("" + o);
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
const us = (t, e = !1) => {
|
|
2896
|
+
if (!Y(t))
|
|
2897
|
+
throw new Error(`flag/flagValue: expected Uint8Array, got ${typeof t}`);
|
|
2898
|
+
if (typeof e != "boolean")
|
|
2899
|
+
throw new Error(`flag/xor: expected boolean, got ${typeof e}`);
|
|
2900
|
+
return Z({
|
|
2901
|
+
size: t.length,
|
|
2902
|
+
encodeStream: (n, r) => {
|
|
2903
|
+
!!r !== e && n.bytes(t);
|
|
2904
|
+
},
|
|
2905
|
+
decodeStream: (n) => {
|
|
2906
|
+
let r = n.leftBytes >= t.length;
|
|
2907
|
+
return r && (r = Ut(n.bytes(t.length, !0), t), r && n.bytes(t.length)), r !== e;
|
|
2908
|
+
},
|
|
2909
|
+
validate: (n) => {
|
|
2910
|
+
if (n !== void 0 && typeof n != "boolean")
|
|
2911
|
+
throw new Error(`flag: expected boolean value or undefined, got ${typeof n}`);
|
|
2912
|
+
return n;
|
|
2913
|
+
}
|
|
2914
|
+
});
|
|
2915
|
+
};
|
|
2916
|
+
function ds(t, e, n) {
|
|
2917
|
+
if (!Q(e))
|
|
2918
|
+
throw new Error(`flagged: invalid inner value ${e}`);
|
|
2919
|
+
return Z({
|
|
2920
|
+
encodeStream: (r, o) => {
|
|
2921
|
+
ft.resolve(r.stack, t) && e.encodeStream(r, o);
|
|
2922
|
+
},
|
|
2923
|
+
decodeStream: (r) => {
|
|
2924
|
+
let o = !1;
|
|
2925
|
+
if (o = !!ft.resolve(r.stack, t), o)
|
|
2926
|
+
return e.decodeStream(r);
|
|
2927
|
+
}
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
function hi(t, e, n = !0) {
|
|
2931
|
+
if (!Q(t))
|
|
2932
|
+
throw new Error(`magic: invalid inner value ${t}`);
|
|
2933
|
+
if (typeof n != "boolean")
|
|
2934
|
+
throw new Error(`magic: expected boolean, got ${typeof n}`);
|
|
2935
|
+
return Z({
|
|
2936
|
+
size: t.size,
|
|
2937
|
+
encodeStream: (r, o) => t.encodeStream(r, e),
|
|
2938
|
+
decodeStream: (r) => {
|
|
2939
|
+
const o = t.decodeStream(r);
|
|
2940
|
+
if (n && typeof o != "object" && o !== e || Y(e) && !Ut(e, o))
|
|
2941
|
+
throw r.err(`magic: invalid value: ${o} !== ${e}`);
|
|
2942
|
+
},
|
|
2943
|
+
validate: (r) => {
|
|
2944
|
+
if (r !== void 0)
|
|
2945
|
+
throw new Error(`magic: wrong value=${typeof r}`);
|
|
2946
|
+
return r;
|
|
2947
|
+
}
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
function bn(t) {
|
|
2951
|
+
let e = 0;
|
|
2952
|
+
for (const n of t) {
|
|
2953
|
+
if (n.size === void 0)
|
|
2954
|
+
return;
|
|
2955
|
+
if (!ot(n.size))
|
|
2956
|
+
throw new Error(`sizeof: wrong element size=${e}`);
|
|
2957
|
+
e += n.size;
|
|
2958
|
+
}
|
|
2959
|
+
return e;
|
|
2960
|
+
}
|
|
2961
|
+
function me(t) {
|
|
2962
|
+
if (!Wt(t))
|
|
2963
|
+
throw new Error(`struct: expected plain object, got ${t}`);
|
|
2964
|
+
for (const e in t)
|
|
2965
|
+
if (!Q(t[e]))
|
|
2966
|
+
throw new Error(`struct: field ${e} is not CoderType`);
|
|
2967
|
+
return Z({
|
|
2968
|
+
size: bn(Object.values(t)),
|
|
2969
|
+
encodeStream: (e, n) => {
|
|
2970
|
+
e.pushObj(n, (r) => {
|
|
2971
|
+
for (const o in t)
|
|
2972
|
+
r(o, () => t[o].encodeStream(e, n[o]));
|
|
2973
|
+
});
|
|
2974
|
+
},
|
|
2975
|
+
decodeStream: (e) => {
|
|
2976
|
+
const n = {};
|
|
2977
|
+
return e.pushObj(n, (r) => {
|
|
2978
|
+
for (const o in t)
|
|
2979
|
+
r(o, () => n[o] = t[o].decodeStream(e));
|
|
2980
|
+
}), n;
|
|
2981
|
+
},
|
|
2982
|
+
validate: (e) => {
|
|
2983
|
+
if (typeof e != "object" || e === null)
|
|
2984
|
+
throw new Error(`struct: invalid value ${e}`);
|
|
2985
|
+
return e;
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
function li(t) {
|
|
2990
|
+
if (!Array.isArray(t))
|
|
2991
|
+
throw new Error(`Packed.Tuple: got ${typeof t} instead of array`);
|
|
2992
|
+
for (let e = 0; e < t.length; e++)
|
|
2993
|
+
if (!Q(t[e]))
|
|
2994
|
+
throw new Error(`tuple: field ${e} is not CoderType`);
|
|
2995
|
+
return Z({
|
|
2996
|
+
size: bn(t),
|
|
2997
|
+
encodeStream: (e, n) => {
|
|
2998
|
+
if (!Array.isArray(n))
|
|
2999
|
+
throw e.err(`tuple: invalid value ${n}`);
|
|
3000
|
+
e.pushObj(n, (r) => {
|
|
3001
|
+
for (let o = 0; o < t.length; o++)
|
|
3002
|
+
r(`${o}`, () => t[o].encodeStream(e, n[o]));
|
|
3003
|
+
});
|
|
3004
|
+
},
|
|
3005
|
+
decodeStream: (e) => {
|
|
3006
|
+
const n = [];
|
|
3007
|
+
return e.pushObj(n, (r) => {
|
|
3008
|
+
for (let o = 0; o < t.length; o++)
|
|
3009
|
+
r(`${o}`, () => n.push(t[o].decodeStream(e)));
|
|
3010
|
+
}), n;
|
|
3011
|
+
},
|
|
3012
|
+
validate: (e) => {
|
|
3013
|
+
if (!Array.isArray(e))
|
|
3014
|
+
throw new Error(`tuple: invalid value ${e}`);
|
|
3015
|
+
if (e.length !== t.length)
|
|
3016
|
+
throw new Error(`tuple: wrong length=${e.length}, expected ${t.length}`);
|
|
3017
|
+
return e;
|
|
3018
|
+
}
|
|
3019
|
+
});
|
|
3020
|
+
}
|
|
3021
|
+
function Ye(t, e) {
|
|
3022
|
+
if (!Q(e))
|
|
3023
|
+
throw new Error(`array: invalid inner value ${e}`);
|
|
3024
|
+
const n = ln(typeof t == "string" ? `../${t}` : t);
|
|
3025
|
+
return Z({
|
|
3026
|
+
size: typeof t == "number" && e.size ? t * e.size : void 0,
|
|
3027
|
+
encodeStream: (r, o) => {
|
|
3028
|
+
const s = r;
|
|
3029
|
+
s.pushObj(o, (i) => {
|
|
3030
|
+
Y(t) || n.encodeStream(r, o.length);
|
|
3031
|
+
for (let c = 0; c < o.length; c++)
|
|
3032
|
+
i(`${c}`, () => {
|
|
3033
|
+
const a = o[c], f = r.pos;
|
|
3034
|
+
if (e.encodeStream(r, a), Y(t)) {
|
|
3035
|
+
if (t.length > s.pos - f)
|
|
3036
|
+
return;
|
|
3037
|
+
const d = s.finish(!1).subarray(f, s.pos);
|
|
3038
|
+
if (Ut(d.subarray(0, t.length), t))
|
|
3039
|
+
throw s.err(`array: inner element encoding same as separator. elm=${a} data=${d}`);
|
|
3040
|
+
}
|
|
3041
|
+
});
|
|
3042
|
+
}), Y(t) && r.bytes(t);
|
|
3043
|
+
},
|
|
3044
|
+
decodeStream: (r) => {
|
|
3045
|
+
const o = [];
|
|
3046
|
+
return r.pushObj(o, (s) => {
|
|
3047
|
+
if (t === null)
|
|
3048
|
+
for (let i = 0; !r.isEnd() && (s(`${i}`, () => o.push(e.decodeStream(r))), !(e.size && r.leftBytes < e.size)); i++)
|
|
3049
|
+
;
|
|
3050
|
+
else if (Y(t))
|
|
3051
|
+
for (let i = 0; ; i++) {
|
|
3052
|
+
if (Ut(r.bytes(t.length, !0), t)) {
|
|
3053
|
+
r.bytes(t.length);
|
|
3054
|
+
break;
|
|
3055
|
+
}
|
|
3056
|
+
s(`${i}`, () => o.push(e.decodeStream(r)));
|
|
3057
|
+
}
|
|
3058
|
+
else {
|
|
3059
|
+
let i;
|
|
3060
|
+
s("arrayLen", () => i = n.decodeStream(r));
|
|
3061
|
+
for (let c = 0; c < i; c++)
|
|
3062
|
+
s(`${c}`, () => o.push(e.decodeStream(r)));
|
|
3063
|
+
}
|
|
3064
|
+
}), o;
|
|
3065
|
+
},
|
|
3066
|
+
validate: (r) => {
|
|
3067
|
+
if (!Array.isArray(r))
|
|
3068
|
+
throw new Error(`array: invalid value ${r}`);
|
|
3069
|
+
return r;
|
|
3070
|
+
}
|
|
3071
|
+
});
|
|
3072
|
+
}
|
|
3073
|
+
const Ht = vt.Point, Er = Ht.Fn, En = Ht.Fn.ORDER, mn = (t) => t % 2n === 0n, N = Ze.isBytes, xn = Ze.concatBytes, An = Ze.equalBytes, Xe = (t) => Xo(at(t)), pi = (...t) => at(at(xn(...t))), wi = St.getPublicKey, gi = vt.getPublicKey, mr = (t) => t.r < En / 2n;
|
|
3074
|
+
function yi(t, e, n = !1) {
|
|
3075
|
+
let r = vt.Signature.fromBytes(vt.sign(t, e, { prehash: !1 }));
|
|
3076
|
+
if (n && !mr(r)) {
|
|
3077
|
+
const o = new Uint8Array(32);
|
|
3078
|
+
let s = 0;
|
|
3079
|
+
for (; !mr(r); )
|
|
3080
|
+
if (o.set(xt.encode(s++)), r = vt.Signature.fromBytes(vt.sign(t, e, { prehash: !1, extraEntropy: o })), s > 4294967295)
|
|
3081
|
+
throw new Error("lowR counter overflow: report the error");
|
|
3082
|
+
}
|
|
3083
|
+
return r.toBytes("der");
|
|
3084
|
+
}
|
|
3085
|
+
const bi = St.sign, hs = St.utils.taggedHash, ct = {
|
|
3086
|
+
ecdsa: 0,
|
|
3087
|
+
schnorr: 1
|
|
3088
|
+
};
|
|
3089
|
+
function ls(t, e) {
|
|
3090
|
+
const n = t.length;
|
|
3091
|
+
if (e === ct.ecdsa) {
|
|
3092
|
+
if (n === 32)
|
|
3093
|
+
throw new Error("Expected non-Schnorr key");
|
|
3094
|
+
return Ht.fromBytes(t), t;
|
|
3095
|
+
} else if (e === ct.schnorr) {
|
|
3096
|
+
if (n !== 32)
|
|
3097
|
+
throw new Error("Expected 32-byte Schnorr key");
|
|
3098
|
+
return St.utils.lift_x(ut(t)), t;
|
|
3099
|
+
} else
|
|
3100
|
+
throw new Error("Unknown key type");
|
|
3101
|
+
}
|
|
3102
|
+
function Bn(t, e) {
|
|
3103
|
+
const r = St.utils.taggedHash("TapTweak", t, e), o = ut(r);
|
|
3104
|
+
if (o >= En)
|
|
3105
|
+
throw new Error("tweak higher than curve order");
|
|
3106
|
+
return o;
|
|
3107
|
+
}
|
|
3108
|
+
function Ei(t, e = Uint8Array.of()) {
|
|
3109
|
+
const n = St.utils, r = ut(t), o = Ht.BASE.multiply(r), s = mn(o.y) ? r : Er.neg(r), i = n.pointToBytes(o), c = Bn(i, e);
|
|
3110
|
+
return we(Er.add(s, c), 32);
|
|
3111
|
+
}
|
|
3112
|
+
function ps(t, e) {
|
|
3113
|
+
const n = St.utils, r = Bn(t, e), s = n.lift_x(ut(t)).add(Ht.BASE.multiply(r)), i = mn(s.y) ? 0 : 1;
|
|
3114
|
+
return [n.pointToBytes(s), i];
|
|
3115
|
+
}
|
|
3116
|
+
const ws = at(Ht.BASE.toBytes(!1)), At = {
|
|
3117
|
+
bech32: "bc",
|
|
3118
|
+
pubKeyHash: 0,
|
|
3119
|
+
scriptHash: 5,
|
|
3120
|
+
wif: 128
|
|
3121
|
+
}, gs = {
|
|
3122
|
+
bech32: "tb",
|
|
3123
|
+
pubKeyHash: 111,
|
|
3124
|
+
scriptHash: 196,
|
|
3125
|
+
wif: 239
|
|
3126
|
+
};
|
|
3127
|
+
function mi(t, e) {
|
|
3128
|
+
if (!N(t) || !N(e))
|
|
3129
|
+
throw new Error(`cmp: wrong type a=${typeof t} b=${typeof e}`);
|
|
3130
|
+
const n = Math.min(t.length, e.length);
|
|
3131
|
+
for (let r = 0; r < n; r++)
|
|
3132
|
+
if (t[r] != e[r])
|
|
3133
|
+
return Math.sign(t[r] - e[r]);
|
|
3134
|
+
return Math.sign(t.length - e.length);
|
|
3135
|
+
}
|
|
3136
|
+
function ys(t) {
|
|
3137
|
+
const e = {};
|
|
3138
|
+
for (const n in t) {
|
|
3139
|
+
if (e[t[n]] !== void 0)
|
|
3140
|
+
throw new Error("duplicate key");
|
|
3141
|
+
e[t[n]] = n;
|
|
3142
|
+
}
|
|
3143
|
+
return e;
|
|
3144
|
+
}
|
|
3145
|
+
const K = {
|
|
3146
|
+
OP_0: 0,
|
|
3147
|
+
PUSHDATA1: 76,
|
|
3148
|
+
PUSHDATA2: 77,
|
|
3149
|
+
PUSHDATA4: 78,
|
|
3150
|
+
"1NEGATE": 79,
|
|
3151
|
+
RESERVED: 80,
|
|
3152
|
+
OP_1: 81,
|
|
3153
|
+
OP_2: 82,
|
|
3154
|
+
OP_3: 83,
|
|
3155
|
+
OP_4: 84,
|
|
3156
|
+
OP_5: 85,
|
|
3157
|
+
OP_6: 86,
|
|
3158
|
+
OP_7: 87,
|
|
3159
|
+
OP_8: 88,
|
|
3160
|
+
OP_9: 89,
|
|
3161
|
+
OP_10: 90,
|
|
3162
|
+
OP_11: 91,
|
|
3163
|
+
OP_12: 92,
|
|
3164
|
+
OP_13: 93,
|
|
3165
|
+
OP_14: 94,
|
|
3166
|
+
OP_15: 95,
|
|
3167
|
+
OP_16: 96,
|
|
3168
|
+
// Control
|
|
3169
|
+
NOP: 97,
|
|
3170
|
+
VER: 98,
|
|
3171
|
+
IF: 99,
|
|
3172
|
+
NOTIF: 100,
|
|
3173
|
+
VERIF: 101,
|
|
3174
|
+
VERNOTIF: 102,
|
|
3175
|
+
ELSE: 103,
|
|
3176
|
+
ENDIF: 104,
|
|
3177
|
+
VERIFY: 105,
|
|
3178
|
+
RETURN: 106,
|
|
3179
|
+
// Stack
|
|
3180
|
+
TOALTSTACK: 107,
|
|
3181
|
+
FROMALTSTACK: 108,
|
|
3182
|
+
"2DROP": 109,
|
|
3183
|
+
"2DUP": 110,
|
|
3184
|
+
"3DUP": 111,
|
|
3185
|
+
"2OVER": 112,
|
|
3186
|
+
"2ROT": 113,
|
|
3187
|
+
"2SWAP": 114,
|
|
3188
|
+
IFDUP: 115,
|
|
3189
|
+
DEPTH: 116,
|
|
3190
|
+
DROP: 117,
|
|
3191
|
+
DUP: 118,
|
|
3192
|
+
NIP: 119,
|
|
3193
|
+
OVER: 120,
|
|
3194
|
+
PICK: 121,
|
|
3195
|
+
ROLL: 122,
|
|
3196
|
+
ROT: 123,
|
|
3197
|
+
SWAP: 124,
|
|
3198
|
+
TUCK: 125,
|
|
3199
|
+
// Splice
|
|
3200
|
+
CAT: 126,
|
|
3201
|
+
SUBSTR: 127,
|
|
3202
|
+
LEFT: 128,
|
|
3203
|
+
RIGHT: 129,
|
|
3204
|
+
SIZE: 130,
|
|
3205
|
+
// Boolean logic
|
|
3206
|
+
INVERT: 131,
|
|
3207
|
+
AND: 132,
|
|
3208
|
+
OR: 133,
|
|
3209
|
+
XOR: 134,
|
|
3210
|
+
EQUAL: 135,
|
|
3211
|
+
EQUALVERIFY: 136,
|
|
3212
|
+
RESERVED1: 137,
|
|
3213
|
+
RESERVED2: 138,
|
|
3214
|
+
// Numbers
|
|
3215
|
+
"1ADD": 139,
|
|
3216
|
+
"1SUB": 140,
|
|
3217
|
+
"2MUL": 141,
|
|
3218
|
+
"2DIV": 142,
|
|
3219
|
+
NEGATE: 143,
|
|
3220
|
+
ABS: 144,
|
|
3221
|
+
NOT: 145,
|
|
3222
|
+
"0NOTEQUAL": 146,
|
|
3223
|
+
ADD: 147,
|
|
3224
|
+
SUB: 148,
|
|
3225
|
+
MUL: 149,
|
|
3226
|
+
DIV: 150,
|
|
3227
|
+
MOD: 151,
|
|
3228
|
+
LSHIFT: 152,
|
|
3229
|
+
RSHIFT: 153,
|
|
3230
|
+
BOOLAND: 154,
|
|
3231
|
+
BOOLOR: 155,
|
|
3232
|
+
NUMEQUAL: 156,
|
|
3233
|
+
NUMEQUALVERIFY: 157,
|
|
3234
|
+
NUMNOTEQUAL: 158,
|
|
3235
|
+
LESSTHAN: 159,
|
|
3236
|
+
GREATERTHAN: 160,
|
|
3237
|
+
LESSTHANOREQUAL: 161,
|
|
3238
|
+
GREATERTHANOREQUAL: 162,
|
|
3239
|
+
MIN: 163,
|
|
3240
|
+
MAX: 164,
|
|
3241
|
+
WITHIN: 165,
|
|
3242
|
+
// Crypto
|
|
3243
|
+
RIPEMD160: 166,
|
|
3244
|
+
SHA1: 167,
|
|
3245
|
+
SHA256: 168,
|
|
3246
|
+
HASH160: 169,
|
|
3247
|
+
HASH256: 170,
|
|
3248
|
+
CODESEPARATOR: 171,
|
|
3249
|
+
CHECKSIG: 172,
|
|
3250
|
+
CHECKSIGVERIFY: 173,
|
|
3251
|
+
CHECKMULTISIG: 174,
|
|
3252
|
+
CHECKMULTISIGVERIFY: 175,
|
|
3253
|
+
// Expansion
|
|
3254
|
+
NOP1: 176,
|
|
3255
|
+
CHECKLOCKTIMEVERIFY: 177,
|
|
3256
|
+
CHECKSEQUENCEVERIFY: 178,
|
|
3257
|
+
NOP4: 179,
|
|
3258
|
+
NOP5: 180,
|
|
3259
|
+
NOP6: 181,
|
|
3260
|
+
NOP7: 182,
|
|
3261
|
+
NOP8: 183,
|
|
3262
|
+
NOP9: 184,
|
|
3263
|
+
NOP10: 185,
|
|
3264
|
+
// BIP 342
|
|
3265
|
+
CHECKSIGADD: 186,
|
|
3266
|
+
// Invalid
|
|
3267
|
+
INVALID: 255
|
|
3268
|
+
}, bs = ys(K);
|
|
3269
|
+
function Sn(t = 6, e = !1) {
|
|
3270
|
+
return Z({
|
|
3271
|
+
encodeStream: (n, r) => {
|
|
3272
|
+
if (r === 0n)
|
|
3273
|
+
return;
|
|
3274
|
+
const o = r < 0, s = BigInt(r), i = [];
|
|
3275
|
+
for (let c = o ? -s : s; c; c >>= 8n)
|
|
3276
|
+
i.push(Number(c & 0xffn));
|
|
3277
|
+
i[i.length - 1] >= 128 ? i.push(o ? 128 : 0) : o && (i[i.length - 1] |= 128), n.bytes(new Uint8Array(i));
|
|
3278
|
+
},
|
|
3279
|
+
decodeStream: (n) => {
|
|
3280
|
+
const r = n.leftBytes;
|
|
3281
|
+
if (r > t)
|
|
3282
|
+
throw new Error(`ScriptNum: number (${r}) bigger than limit=${t}`);
|
|
3283
|
+
if (r === 0)
|
|
3284
|
+
return 0n;
|
|
3285
|
+
if (e) {
|
|
3286
|
+
const i = n.bytes(r, !0);
|
|
3287
|
+
if ((i[i.length - 1] & 127) === 0 && (r <= 1 || (i[i.length - 2] & 128) === 0))
|
|
3288
|
+
throw new Error("Non-minimally encoded ScriptNum");
|
|
3289
|
+
}
|
|
3290
|
+
let o = 0, s = 0n;
|
|
3291
|
+
for (let i = 0; i < r; ++i)
|
|
3292
|
+
o = n.byte(), s |= BigInt(o) << 8n * BigInt(i);
|
|
3293
|
+
return o >= 128 && (s &= 2n ** BigInt(r * 8) - 1n >> 1n, s = -s), s;
|
|
3294
|
+
}
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
function Es(t, e = 4, n = !0) {
|
|
3298
|
+
if (typeof t == "number")
|
|
3299
|
+
return t;
|
|
3300
|
+
if (N(t))
|
|
3301
|
+
try {
|
|
3302
|
+
const r = Sn(e, n).decode(t);
|
|
3303
|
+
return r > Number.MAX_SAFE_INTEGER ? void 0 : Number(r);
|
|
3304
|
+
} catch {
|
|
3305
|
+
return;
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
const Kt = Z({
|
|
3309
|
+
encodeStream: (t, e) => {
|
|
3310
|
+
for (let n of e) {
|
|
3311
|
+
if (typeof n == "string") {
|
|
3312
|
+
if (K[n] === void 0)
|
|
3313
|
+
throw new Error(`Unknown opcode=${n}`);
|
|
3314
|
+
t.byte(K[n]);
|
|
3315
|
+
continue;
|
|
3316
|
+
} else if (typeof n == "number") {
|
|
3317
|
+
if (n === 0) {
|
|
3318
|
+
t.byte(0);
|
|
3319
|
+
continue;
|
|
3320
|
+
} else if (1 <= n && n <= 16) {
|
|
3321
|
+
t.byte(K.OP_1 - 1 + n);
|
|
3322
|
+
continue;
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
if (typeof n == "number" && (n = Sn().encode(BigInt(n))), !N(n))
|
|
3326
|
+
throw new Error(`Wrong Script OP=${n} (${typeof n})`);
|
|
3327
|
+
const r = n.length;
|
|
3328
|
+
r < K.PUSHDATA1 ? t.byte(r) : r <= 255 ? (t.byte(K.PUSHDATA1), t.byte(r)) : r <= 65535 ? (t.byte(K.PUSHDATA2), t.bytes(br.encode(r))) : (t.byte(K.PUSHDATA4), t.bytes(xt.encode(r))), t.bytes(n);
|
|
3329
|
+
}
|
|
3330
|
+
},
|
|
3331
|
+
decodeStream: (t) => {
|
|
3332
|
+
const e = [];
|
|
3333
|
+
for (; !t.isEnd(); ) {
|
|
3334
|
+
const n = t.byte();
|
|
3335
|
+
if (K.OP_0 < n && n <= K.PUSHDATA4) {
|
|
3336
|
+
let r;
|
|
3337
|
+
if (n < K.PUSHDATA1)
|
|
3338
|
+
r = n;
|
|
3339
|
+
else if (n === K.PUSHDATA1)
|
|
3340
|
+
r = fs.decodeStream(t);
|
|
3341
|
+
else if (n === K.PUSHDATA2)
|
|
3342
|
+
r = br.decodeStream(t);
|
|
3343
|
+
else if (n === K.PUSHDATA4)
|
|
3344
|
+
r = xt.decodeStream(t);
|
|
3345
|
+
else
|
|
3346
|
+
throw new Error("Should be not possible");
|
|
3347
|
+
e.push(t.bytes(r));
|
|
3348
|
+
} else if (n === 0)
|
|
3349
|
+
e.push(0);
|
|
3350
|
+
else if (K.OP_1 <= n && n <= K.OP_16)
|
|
3351
|
+
e.push(n - (K.OP_1 - 1));
|
|
3352
|
+
else {
|
|
3353
|
+
const r = bs[n];
|
|
3354
|
+
if (r === void 0)
|
|
3355
|
+
throw new Error(`Unknown opcode=${n.toString(16)}`);
|
|
3356
|
+
e.push(r);
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
return e;
|
|
3360
|
+
}
|
|
3361
|
+
}), xr = {
|
|
3362
|
+
253: [253, 2, 253n, 65535n],
|
|
3363
|
+
254: [254, 4, 65536n, 4294967295n],
|
|
3364
|
+
255: [255, 8, 4294967296n, 18446744073709551615n]
|
|
3365
|
+
}, Qe = Z({
|
|
3366
|
+
encodeStream: (t, e) => {
|
|
3367
|
+
if (typeof e == "number" && (e = BigInt(e)), 0n <= e && e <= 252n)
|
|
3368
|
+
return t.byte(Number(e));
|
|
3369
|
+
for (const [n, r, o, s] of Object.values(xr))
|
|
3370
|
+
if (!(o > e || e > s)) {
|
|
3371
|
+
t.byte(n);
|
|
3372
|
+
for (let i = 0; i < r; i++)
|
|
3373
|
+
t.byte(Number(e >> 8n * BigInt(i) & 0xffn));
|
|
3374
|
+
return;
|
|
3375
|
+
}
|
|
3376
|
+
throw t.err(`VarInt too big: ${e}`);
|
|
3377
|
+
},
|
|
3378
|
+
decodeStream: (t) => {
|
|
3379
|
+
const e = t.byte();
|
|
3380
|
+
if (e <= 252)
|
|
3381
|
+
return BigInt(e);
|
|
3382
|
+
const [n, r, o] = xr[e];
|
|
3383
|
+
let s = 0n;
|
|
3384
|
+
for (let i = 0; i < r; i++)
|
|
3385
|
+
s |= BigInt(t.byte()) << 8n * BigInt(i);
|
|
3386
|
+
if (s < o)
|
|
3387
|
+
throw t.err(`Wrong CompactSize(${8 * r})`);
|
|
3388
|
+
return s;
|
|
3389
|
+
}
|
|
3390
|
+
}), ms = kt(Qe, gn.numberBigint), xe = jt(Qe), xs = Ye(ms, xe), ue = (t) => Ye(Qe, t), vn = me({
|
|
3391
|
+
txid: jt(32, !0),
|
|
3392
|
+
// hash(prev_tx),
|
|
3393
|
+
index: xt,
|
|
3394
|
+
// output number of previous tx
|
|
3395
|
+
finalScriptSig: xe,
|
|
3396
|
+
// btc merges input and output script, executes it. If ok = tx passes
|
|
3397
|
+
sequence: xt
|
|
3398
|
+
// ?
|
|
3399
|
+
}), In = me({ amount: cs, script: xe }), As = me({
|
|
3400
|
+
version: yn,
|
|
3401
|
+
segwitFlag: us(new Uint8Array([0, 1])),
|
|
3402
|
+
inputs: ue(vn),
|
|
3403
|
+
outputs: ue(In),
|
|
3404
|
+
witnesses: ds("segwitFlag", Ye("inputs/length", xs)),
|
|
3405
|
+
// < 500000000 Block number at which this transaction is unlocked
|
|
3406
|
+
// >= 500000000 UNIX timestamp at which this transaction is unlocked
|
|
3407
|
+
// Handled as part of PSBTv2
|
|
3408
|
+
lockTime: xt
|
|
3409
|
+
});
|
|
3410
|
+
function Bs(t) {
|
|
3411
|
+
if (t.segwitFlag && t.witnesses && !t.witnesses.length)
|
|
3412
|
+
throw new Error("Segwit flag with empty witnesses array");
|
|
3413
|
+
return t;
|
|
3414
|
+
}
|
|
3415
|
+
const xi = be(As, Bs), Ai = me({
|
|
3416
|
+
version: yn,
|
|
3417
|
+
inputs: ue(vn),
|
|
3418
|
+
outputs: ue(In),
|
|
3419
|
+
lockTime: xt
|
|
3420
|
+
}), Ss = {
|
|
3421
|
+
encode(t) {
|
|
3422
|
+
if (!(t.length !== 2 || t[0] !== 1 || !N(t[1]) || rt.encode(t[1]) !== "4e73"))
|
|
3423
|
+
return { type: "p2a", script: Kt.encode(t) };
|
|
3424
|
+
},
|
|
3425
|
+
decode: (t) => {
|
|
3426
|
+
if (t.type === "p2a")
|
|
3427
|
+
return [1, rt.decode("4e73")];
|
|
3428
|
+
}
|
|
3429
|
+
};
|
|
3430
|
+
function Et(t, e) {
|
|
3431
|
+
try {
|
|
3432
|
+
return ls(t, e), !0;
|
|
3433
|
+
} catch {
|
|
3434
|
+
return !1;
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
const vs = {
|
|
3438
|
+
encode(t) {
|
|
3439
|
+
if (!(t.length !== 2 || !N(t[0]) || !Et(t[0], ct.ecdsa) || t[1] !== "CHECKSIG"))
|
|
3440
|
+
return { type: "pk", pubkey: t[0] };
|
|
3441
|
+
},
|
|
3442
|
+
decode: (t) => t.type === "pk" ? [t.pubkey, "CHECKSIG"] : void 0
|
|
3443
|
+
}, Is = {
|
|
3444
|
+
encode(t) {
|
|
3445
|
+
if (!(t.length !== 5 || t[0] !== "DUP" || t[1] !== "HASH160" || !N(t[2])) && !(t[3] !== "EQUALVERIFY" || t[4] !== "CHECKSIG"))
|
|
3446
|
+
return { type: "pkh", hash: t[2] };
|
|
3447
|
+
},
|
|
3448
|
+
decode: (t) => t.type === "pkh" ? ["DUP", "HASH160", t.hash, "EQUALVERIFY", "CHECKSIG"] : void 0
|
|
3449
|
+
}, $s = {
|
|
3450
|
+
encode(t) {
|
|
3451
|
+
if (!(t.length !== 3 || t[0] !== "HASH160" || !N(t[1]) || t[2] !== "EQUAL"))
|
|
3452
|
+
return { type: "sh", hash: t[1] };
|
|
3453
|
+
},
|
|
3454
|
+
decode: (t) => t.type === "sh" ? ["HASH160", t.hash, "EQUAL"] : void 0
|
|
3455
|
+
}, Os = {
|
|
3456
|
+
encode(t) {
|
|
3457
|
+
if (!(t.length !== 2 || t[0] !== 0 || !N(t[1])) && t[1].length === 32)
|
|
3458
|
+
return { type: "wsh", hash: t[1] };
|
|
3459
|
+
},
|
|
3460
|
+
decode: (t) => t.type === "wsh" ? [0, t.hash] : void 0
|
|
3461
|
+
}, Rs = {
|
|
3462
|
+
encode(t) {
|
|
3463
|
+
if (!(t.length !== 2 || t[0] !== 0 || !N(t[1])) && t[1].length === 20)
|
|
3464
|
+
return { type: "wpkh", hash: t[1] };
|
|
3465
|
+
},
|
|
3466
|
+
decode: (t) => t.type === "wpkh" ? [0, t.hash] : void 0
|
|
3467
|
+
}, Us = {
|
|
3468
|
+
encode(t) {
|
|
3469
|
+
const e = t.length - 1;
|
|
3470
|
+
if (t[e] !== "CHECKMULTISIG")
|
|
3471
|
+
return;
|
|
3472
|
+
const n = t[0], r = t[e - 1];
|
|
3473
|
+
if (typeof n != "number" || typeof r != "number")
|
|
3474
|
+
return;
|
|
3475
|
+
const o = t.slice(1, -2);
|
|
3476
|
+
if (r === o.length) {
|
|
3477
|
+
for (const s of o)
|
|
3478
|
+
if (!N(s))
|
|
3479
|
+
return;
|
|
3480
|
+
return { type: "ms", m: n, pubkeys: o };
|
|
3481
|
+
}
|
|
3482
|
+
},
|
|
3483
|
+
// checkmultisig(n, ..pubkeys, m)
|
|
3484
|
+
decode: (t) => t.type === "ms" ? [t.m, ...t.pubkeys, t.pubkeys.length, "CHECKMULTISIG"] : void 0
|
|
3485
|
+
}, ks = {
|
|
3486
|
+
encode(t) {
|
|
3487
|
+
if (!(t.length !== 2 || t[0] !== 1 || !N(t[1])))
|
|
3488
|
+
return { type: "tr", pubkey: t[1] };
|
|
3489
|
+
},
|
|
3490
|
+
decode: (t) => t.type === "tr" ? [1, t.pubkey] : void 0
|
|
3491
|
+
}, Ps = {
|
|
3492
|
+
encode(t) {
|
|
3493
|
+
const e = t.length - 1;
|
|
3494
|
+
if (t[e] !== "CHECKSIG")
|
|
3495
|
+
return;
|
|
3496
|
+
const n = [];
|
|
3497
|
+
for (let r = 0; r < e; r++) {
|
|
3498
|
+
const o = t[r];
|
|
3499
|
+
if (r & 1) {
|
|
3500
|
+
if (o !== "CHECKSIGVERIFY" || r === e - 1)
|
|
3501
|
+
return;
|
|
3502
|
+
continue;
|
|
3503
|
+
}
|
|
3504
|
+
if (!N(o))
|
|
3505
|
+
return;
|
|
3506
|
+
n.push(o);
|
|
3507
|
+
}
|
|
3508
|
+
return { type: "tr_ns", pubkeys: n };
|
|
3509
|
+
},
|
|
3510
|
+
decode: (t) => {
|
|
3511
|
+
if (t.type !== "tr_ns")
|
|
3512
|
+
return;
|
|
3513
|
+
const e = [];
|
|
3514
|
+
for (let n = 0; n < t.pubkeys.length - 1; n++)
|
|
3515
|
+
e.push(t.pubkeys[n], "CHECKSIGVERIFY");
|
|
3516
|
+
return e.push(t.pubkeys[t.pubkeys.length - 1], "CHECKSIG"), e;
|
|
3517
|
+
}
|
|
3518
|
+
}, _s = {
|
|
3519
|
+
encode(t) {
|
|
3520
|
+
const e = t.length - 1;
|
|
3521
|
+
if (t[e] !== "NUMEQUAL" || t[1] !== "CHECKSIG")
|
|
3522
|
+
return;
|
|
3523
|
+
const n = [], r = Es(t[e - 1]);
|
|
3524
|
+
if (typeof r == "number") {
|
|
3525
|
+
for (let o = 0; o < e - 1; o++) {
|
|
3526
|
+
const s = t[o];
|
|
3527
|
+
if (o & 1) {
|
|
3528
|
+
if (s !== (o === 1 ? "CHECKSIG" : "CHECKSIGADD"))
|
|
3529
|
+
throw new Error("OutScript.encode/tr_ms: wrong element");
|
|
3530
|
+
continue;
|
|
3531
|
+
}
|
|
3532
|
+
if (!N(s))
|
|
3533
|
+
throw new Error("OutScript.encode/tr_ms: wrong key element");
|
|
3534
|
+
n.push(s);
|
|
3535
|
+
}
|
|
3536
|
+
return { type: "tr_ms", pubkeys: n, m: r };
|
|
3537
|
+
}
|
|
3538
|
+
},
|
|
3539
|
+
decode: (t) => {
|
|
3540
|
+
if (t.type !== "tr_ms")
|
|
3541
|
+
return;
|
|
3542
|
+
const e = [t.pubkeys[0], "CHECKSIG"];
|
|
3543
|
+
for (let n = 1; n < t.pubkeys.length; n++)
|
|
3544
|
+
e.push(t.pubkeys[n], "CHECKSIGADD");
|
|
3545
|
+
return e.push(t.m, "NUMEQUAL"), e;
|
|
3546
|
+
}
|
|
3547
|
+
}, Hs = {
|
|
3548
|
+
encode(t) {
|
|
3549
|
+
return { type: "unknown", script: Kt.encode(t) };
|
|
3550
|
+
},
|
|
3551
|
+
decode: (t) => t.type === "unknown" ? Kt.decode(t.script) : void 0
|
|
3552
|
+
}, Ls = [
|
|
3553
|
+
Ss,
|
|
3554
|
+
vs,
|
|
3555
|
+
Is,
|
|
3556
|
+
$s,
|
|
3557
|
+
Os,
|
|
3558
|
+
Rs,
|
|
3559
|
+
Us,
|
|
3560
|
+
ks,
|
|
3561
|
+
Ps,
|
|
3562
|
+
_s,
|
|
3563
|
+
Hs
|
|
3564
|
+
], Ts = kt(Kt, gn.match(Ls)), nt = be(Ts, (t) => {
|
|
3565
|
+
if (t.type === "pk" && !Et(t.pubkey, ct.ecdsa))
|
|
3566
|
+
throw new Error("OutScript/pk: wrong key");
|
|
3567
|
+
if ((t.type === "pkh" || t.type === "sh" || t.type === "wpkh") && (!N(t.hash) || t.hash.length !== 20))
|
|
3568
|
+
throw new Error(`OutScript/${t.type}: wrong hash`);
|
|
3569
|
+
if (t.type === "wsh" && (!N(t.hash) || t.hash.length !== 32))
|
|
3570
|
+
throw new Error("OutScript/wsh: wrong hash");
|
|
3571
|
+
if (t.type === "tr" && (!N(t.pubkey) || !Et(t.pubkey, ct.schnorr)))
|
|
3572
|
+
throw new Error("OutScript/tr: wrong taproot public key");
|
|
3573
|
+
if ((t.type === "ms" || t.type === "tr_ns" || t.type === "tr_ms") && !Array.isArray(t.pubkeys))
|
|
3574
|
+
throw new Error("OutScript/multisig: wrong pubkeys array");
|
|
3575
|
+
if (t.type === "ms") {
|
|
3576
|
+
const e = t.pubkeys.length;
|
|
3577
|
+
for (const n of t.pubkeys)
|
|
3578
|
+
if (!Et(n, ct.ecdsa))
|
|
3579
|
+
throw new Error("OutScript/multisig: wrong pubkey");
|
|
3580
|
+
if (t.m <= 0 || e > 16 || t.m > e)
|
|
3581
|
+
throw new Error("OutScript/multisig: invalid params");
|
|
3582
|
+
}
|
|
3583
|
+
if (t.type === "tr_ns" || t.type === "tr_ms") {
|
|
3584
|
+
for (const e of t.pubkeys)
|
|
3585
|
+
if (!Et(e, ct.schnorr))
|
|
3586
|
+
throw new Error(`OutScript/${t.type}: wrong pubkey`);
|
|
3587
|
+
}
|
|
3588
|
+
if (t.type === "tr_ms") {
|
|
3589
|
+
const e = t.pubkeys.length;
|
|
3590
|
+
if (t.m <= 0 || e > 999 || t.m > e)
|
|
3591
|
+
throw new Error("OutScript/tr_ms: invalid params");
|
|
3592
|
+
}
|
|
3593
|
+
return t;
|
|
3594
|
+
});
|
|
3595
|
+
function Ar(t, e) {
|
|
3596
|
+
if (!An(t.hash, at(e)))
|
|
3597
|
+
throw new Error("checkScript: wsh wrong witnessScript hash");
|
|
3598
|
+
const n = nt.decode(e);
|
|
3599
|
+
if (n.type === "tr" || n.type === "tr_ns" || n.type === "tr_ms")
|
|
3600
|
+
throw new Error(`checkScript: P2${n.type} cannot be wrapped in P2SH`);
|
|
3601
|
+
if (n.type === "wpkh" || n.type === "sh")
|
|
3602
|
+
throw new Error(`checkScript: P2${n.type} cannot be wrapped in P2WSH`);
|
|
3603
|
+
}
|
|
3604
|
+
function Ns(t, e, n) {
|
|
3605
|
+
if (t) {
|
|
3606
|
+
const r = nt.decode(t);
|
|
3607
|
+
if (r.type === "tr_ns" || r.type === "tr_ms" || r.type === "ms" || r.type == "pk")
|
|
3608
|
+
throw new Error(`checkScript: non-wrapped ${r.type}`);
|
|
3609
|
+
if (r.type === "sh" && e) {
|
|
3610
|
+
if (!An(r.hash, Xe(e)))
|
|
3611
|
+
throw new Error("checkScript: sh wrong redeemScript hash");
|
|
3612
|
+
const o = nt.decode(e);
|
|
3613
|
+
if (o.type === "tr" || o.type === "tr_ns" || o.type === "tr_ms")
|
|
3614
|
+
throw new Error(`checkScript: P2${o.type} cannot be wrapped in P2SH`);
|
|
3615
|
+
if (o.type === "sh")
|
|
3616
|
+
throw new Error("checkScript: P2SH cannot be wrapped in P2SH");
|
|
3617
|
+
}
|
|
3618
|
+
r.type === "wsh" && n && Ar(r, n);
|
|
3619
|
+
}
|
|
3620
|
+
if (e) {
|
|
3621
|
+
const r = nt.decode(e);
|
|
3622
|
+
r.type === "wsh" && n && Ar(r, n);
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
const Cs = (t, e = At) => {
|
|
3626
|
+
const n = t.script;
|
|
3627
|
+
if (!N(n))
|
|
3628
|
+
throw new Error(`Wrong script: ${typeof t.script}, expected Uint8Array`);
|
|
3629
|
+
const r = Xe(n), o = nt.encode({ type: "sh", hash: r });
|
|
3630
|
+
return Ns(o, n, t.witnessScript), t.witnessScript ? {
|
|
3631
|
+
type: "sh",
|
|
3632
|
+
redeemScript: n,
|
|
3633
|
+
script: nt.encode({ type: "sh", hash: r }),
|
|
3634
|
+
address: Vt(e).encode({ type: "sh", hash: r }),
|
|
3635
|
+
hash: r,
|
|
3636
|
+
witnessScript: t.witnessScript
|
|
3637
|
+
} : {
|
|
3638
|
+
type: "sh",
|
|
3639
|
+
redeemScript: n,
|
|
3640
|
+
script: nt.encode({ type: "sh", hash: r }),
|
|
3641
|
+
address: Vt(e).encode({ type: "sh", hash: r }),
|
|
3642
|
+
hash: r
|
|
3643
|
+
};
|
|
3644
|
+
}, Ds = (t, e = At) => {
|
|
3645
|
+
if (!Et(t, ct.ecdsa))
|
|
3646
|
+
throw new Error("P2WPKH: invalid publicKey");
|
|
3647
|
+
if (t.length === 65)
|
|
3648
|
+
throw new Error("P2WPKH: uncompressed public key");
|
|
3649
|
+
const n = Xe(t);
|
|
3650
|
+
return {
|
|
3651
|
+
type: "wpkh",
|
|
3652
|
+
script: nt.encode({ type: "wpkh", hash: n }),
|
|
3653
|
+
address: Vt(e).encode({ type: "wpkh", hash: n }),
|
|
3654
|
+
hash: n
|
|
3655
|
+
};
|
|
3656
|
+
}, Ks = 192, Bi = (t, e = Ks) => hs("TapLeaf", new Uint8Array([e]), xe.encode(t));
|
|
3657
|
+
function Vs(t, e, n = At, r = !1, o) {
|
|
3658
|
+
if (!t)
|
|
3659
|
+
throw new Error("p2tr: should have pubKey or scriptTree (or both)");
|
|
3660
|
+
const s = typeof t == "string" ? rt.decode(t) : t || ws;
|
|
3661
|
+
if (!Et(s, ct.schnorr))
|
|
3662
|
+
throw new Error("p2tr: non-schnorr pubkey");
|
|
3663
|
+
{
|
|
3664
|
+
const i = ps(s, Qo)[0];
|
|
3665
|
+
return {
|
|
3666
|
+
type: "tr",
|
|
3667
|
+
script: nt.encode({ type: "tr", pubkey: i }),
|
|
3668
|
+
address: Vt(n).encode({ type: "tr", pubkey: i }),
|
|
3669
|
+
// For tests
|
|
3670
|
+
tweakedPubkey: i,
|
|
3671
|
+
// PSBT stuff
|
|
3672
|
+
tapInternalKey: s
|
|
3673
|
+
};
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
const $n = ro(at);
|
|
3677
|
+
function On(t, e) {
|
|
3678
|
+
if (e.length < 2 || e.length > 40)
|
|
3679
|
+
throw new Error("Witness: invalid length");
|
|
3680
|
+
if (t > 16)
|
|
3681
|
+
throw new Error("Witness: invalid version");
|
|
3682
|
+
if (t === 0 && !(e.length === 20 || e.length === 32))
|
|
3683
|
+
throw new Error("Witness: invalid length for version");
|
|
3684
|
+
}
|
|
3685
|
+
function Oe(t, e, n = At) {
|
|
3686
|
+
On(t, e);
|
|
3687
|
+
const r = t === 0 ? ke : Rr;
|
|
3688
|
+
return r.encode(n.bech32, [t].concat(r.toWords(e)));
|
|
3689
|
+
}
|
|
3690
|
+
function Br(t, e) {
|
|
3691
|
+
return $n.encode(xn(Uint8Array.from(e), t));
|
|
3692
|
+
}
|
|
3693
|
+
function Vt(t = At) {
|
|
3694
|
+
return {
|
|
3695
|
+
encode(e) {
|
|
3696
|
+
const { type: n } = e;
|
|
3697
|
+
if (n === "wpkh")
|
|
3698
|
+
return Oe(0, e.hash, t);
|
|
3699
|
+
if (n === "wsh")
|
|
3700
|
+
return Oe(0, e.hash, t);
|
|
3701
|
+
if (n === "tr")
|
|
3702
|
+
return Oe(1, e.pubkey, t);
|
|
3703
|
+
if (n === "pkh")
|
|
3704
|
+
return Br(e.hash, [t.pubKeyHash]);
|
|
3705
|
+
if (n === "sh")
|
|
3706
|
+
return Br(e.hash, [t.scriptHash]);
|
|
3707
|
+
throw new Error(`Unknown address type=${n}`);
|
|
3708
|
+
},
|
|
3709
|
+
decode(e) {
|
|
3710
|
+
if (e.length < 14 || e.length > 74)
|
|
3711
|
+
throw new Error("Invalid address length");
|
|
3712
|
+
if (t.bech32 && e.toLowerCase().startsWith(`${t.bech32}1`)) {
|
|
3713
|
+
let r;
|
|
3714
|
+
try {
|
|
3715
|
+
if (r = ke.decode(e), r.words[0] !== 0)
|
|
3716
|
+
throw new Error(`bech32: wrong version=${r.words[0]}`);
|
|
3717
|
+
} catch {
|
|
3718
|
+
if (r = Rr.decode(e), r.words[0] === 0)
|
|
3719
|
+
throw new Error(`bech32m: wrong version=${r.words[0]}`);
|
|
3720
|
+
}
|
|
3721
|
+
if (r.prefix !== t.bech32)
|
|
3722
|
+
throw new Error(`wrong bech32 prefix=${r.prefix}`);
|
|
3723
|
+
const [o, ...s] = r.words, i = ke.fromWords(s);
|
|
3724
|
+
if (On(o, i), o === 0 && i.length === 32)
|
|
3725
|
+
return { type: "wsh", hash: i };
|
|
3726
|
+
if (o === 0 && i.length === 20)
|
|
3727
|
+
return { type: "wpkh", hash: i };
|
|
3728
|
+
if (o === 1 && i.length === 32)
|
|
3729
|
+
return { type: "tr", pubkey: i };
|
|
3730
|
+
throw new Error("Unknown witness program");
|
|
3731
|
+
}
|
|
3732
|
+
const n = $n.decode(e);
|
|
3733
|
+
if (n.length !== 21)
|
|
3734
|
+
throw new Error("Invalid base58 address");
|
|
3735
|
+
if (n[0] === t.pubKeyHash)
|
|
3736
|
+
return { type: "pkh", hash: n.slice(1) };
|
|
3737
|
+
if (n[0] === t.scriptHash)
|
|
3738
|
+
return {
|
|
3739
|
+
type: "sh",
|
|
3740
|
+
hash: n.slice(1)
|
|
3741
|
+
};
|
|
3742
|
+
throw new Error(`Invalid address prefix=${n[0]}`);
|
|
3743
|
+
}
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
function Si(t) {
|
|
3747
|
+
return t === "mainnet" ? At : t === "testnet" ? gs : At;
|
|
3748
|
+
}
|
|
3749
|
+
function Lt(t) {
|
|
3750
|
+
return t.bech32 === "bc";
|
|
3751
|
+
}
|
|
3752
|
+
function Ms(t, e) {
|
|
3753
|
+
return Ws(t, e) ? "p2pkh" : qs(t, e) ? "p2sh" : Rn(t, e) ? "p2wpkh" : js(t, e) ? "p2wsh" : Un(t, e) ? "p2tr" : "unknown";
|
|
3754
|
+
}
|
|
3755
|
+
function Ws(t, e) {
|
|
3756
|
+
return Lt(t) ? e.startsWith("1") : e.startsWith("m") || e.startsWith("n");
|
|
3757
|
+
}
|
|
3758
|
+
function qs(t, e) {
|
|
3759
|
+
return Lt(t) ? e.startsWith("3") : e.startsWith("2");
|
|
3760
|
+
}
|
|
3761
|
+
function Rn(t, e) {
|
|
3762
|
+
return Lt(t) ? e.startsWith("bc1q") : e.startsWith("tb1q");
|
|
3763
|
+
}
|
|
3764
|
+
function Un(t, e) {
|
|
3765
|
+
return Lt(t) ? e.startsWith("bc1p") : e.startsWith("tb1p");
|
|
3766
|
+
}
|
|
3767
|
+
function js(t, e) {
|
|
3768
|
+
return Un(t, e) || Rn(t, e) ? !1 : Lt(t) ? e.startsWith("bc1") : e.startsWith("tb1");
|
|
3769
|
+
}
|
|
3770
|
+
function Fs(t, e) {
|
|
3771
|
+
if (e.byteLength !== 33)
|
|
3772
|
+
throw new Error("Invalid public key length");
|
|
3773
|
+
return e.slice(1);
|
|
3774
|
+
}
|
|
3775
|
+
function vi(t, e) {
|
|
3776
|
+
return Vs(
|
|
3777
|
+
Fs(t, e),
|
|
3778
|
+
void 0,
|
|
3779
|
+
t
|
|
3780
|
+
).tapInternalKey;
|
|
3781
|
+
}
|
|
3782
|
+
function Ii(t, e) {
|
|
3783
|
+
return Cs(Ds(e, t), t).redeemScript;
|
|
3784
|
+
}
|
|
3785
|
+
function Zs(t, e) {
|
|
3786
|
+
const n = Vt(t).decode(e);
|
|
3787
|
+
return nt.encode(n);
|
|
3788
|
+
}
|
|
3789
|
+
function zs(t, e) {
|
|
3790
|
+
return rt.encode(Zs(t, e));
|
|
3791
|
+
}
|
|
3792
|
+
const Gs = "0000000000000000000000000000000000000000000000000000000000000000", kn = "0000000000000000000000000000000000000000000000000000000000000000", Ys = rt.encode(
|
|
3793
|
+
Kt.encode(["OP_1", rt.decode(kn), "OP_1", "CHECKMULTISIG"])
|
|
3794
|
+
);
|
|
3795
|
+
class $i {
|
|
3796
|
+
constructor(e, n, r) {
|
|
3797
|
+
this.network = e, this.inner = n, this.addresses = r;
|
|
3798
|
+
}
|
|
3799
|
+
async connect() {
|
|
3800
|
+
await this.inner.connect();
|
|
3801
|
+
}
|
|
3802
|
+
async disconnect() {
|
|
3803
|
+
await this.inner.disconnect();
|
|
3804
|
+
}
|
|
3805
|
+
async getAddresses() {
|
|
3806
|
+
const e = await this.inner.getAddresses(), n = (s, i) => {
|
|
3807
|
+
const c = Ms(this.network, i.address), a = c === "p2tr" ? zt.P2TR : c === "p2sh" ? zt.P2SH_P2WPKH : c === "p2wpkh" ? zt.P2WPKH : c === "p2pkh" ? zt.P2PKH : void 0;
|
|
3808
|
+
if (a == null)
|
|
3809
|
+
throw new Nt(
|
|
3810
|
+
`[MockAddressWalletAdapter] Please provide a supported ${s} address`
|
|
3811
|
+
);
|
|
3812
|
+
return {
|
|
3813
|
+
network: Lt(this.network) ? er.MAINNET : er.TESTNET,
|
|
3814
|
+
purposes: i.purposes,
|
|
3815
|
+
addressType: a,
|
|
3816
|
+
address: i.address,
|
|
3817
|
+
scriptPubKey: zs(this.network, i.address),
|
|
3818
|
+
publicKey: kn,
|
|
3819
|
+
redeemScript: Ys,
|
|
3820
|
+
tapInternalKey: Gs
|
|
3821
|
+
};
|
|
3822
|
+
};
|
|
3823
|
+
let r, o;
|
|
3824
|
+
return this.addresses.bitcoin != null && (r = n("bitcoin", {
|
|
3825
|
+
...this.addresses.bitcoin,
|
|
3826
|
+
purposes: [dt.Bitcoin]
|
|
3827
|
+
})), this.addresses.ordinals != null && (o = n("ordinals", {
|
|
3828
|
+
...this.addresses.ordinals,
|
|
3829
|
+
purposes: [
|
|
3830
|
+
dt.Ordinals,
|
|
3831
|
+
dt.BRC20,
|
|
3832
|
+
dt.Runes
|
|
3833
|
+
]
|
|
3834
|
+
})), e.flatMap((s) => {
|
|
3835
|
+
const i = [];
|
|
3836
|
+
let c = s.purposes;
|
|
3837
|
+
return r != null && c.includes(dt.Bitcoin) && (i.push(r), c = c.filter(
|
|
3838
|
+
(a) => a !== dt.Bitcoin
|
|
3839
|
+
)), o != null && c.includes(dt.Ordinals) && (i.push(o), c = c.filter(
|
|
3840
|
+
(a) => a !== dt.Ordinals
|
|
3841
|
+
)), c.length > 0 && i.push({ ...s, purposes: c }), i;
|
|
3842
|
+
});
|
|
3843
|
+
}
|
|
3844
|
+
async signMessage(e, n) {
|
|
3845
|
+
throw new Nt(
|
|
3846
|
+
"[MockAddressWalletAdapter] it's a mock adapter, can't send inscription"
|
|
3847
|
+
);
|
|
3848
|
+
}
|
|
3849
|
+
get sendBitcoinFeeRateCapability() {
|
|
3850
|
+
return this.inner.sendBitcoinFeeRateCapability;
|
|
3851
|
+
}
|
|
3852
|
+
get sendInscriptionFeeRateCapability() {
|
|
3853
|
+
return this.inner.sendInscriptionFeeRateCapability;
|
|
3854
|
+
}
|
|
3855
|
+
sendBitcoin(e, n, r) {
|
|
3856
|
+
throw new Nt(
|
|
3857
|
+
"[MockAddressWalletAdapter] it's a mock adapter, can't send bitcoin"
|
|
3858
|
+
);
|
|
3859
|
+
}
|
|
3860
|
+
sendInscription(e, n, r) {
|
|
3861
|
+
throw new Nt(
|
|
3862
|
+
"[MockAddressWalletAdapter] it's a mock adapter, can't send inscription"
|
|
3863
|
+
);
|
|
3864
|
+
}
|
|
3865
|
+
signAndFinalizePsbt(e) {
|
|
3866
|
+
throw new Nt(
|
|
3867
|
+
"[MockAddressWalletAdapter] it's a mock adapter, can't sign transaction"
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3870
|
+
onAddressesChanged(e) {
|
|
3871
|
+
return {
|
|
3872
|
+
unsubscribe: () => {
|
|
3873
|
+
}
|
|
3874
|
+
};
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
export {
|
|
3878
|
+
cs as $,
|
|
3879
|
+
mi as A,
|
|
3880
|
+
Qs as B,
|
|
3881
|
+
ms as C,
|
|
3882
|
+
kt as D,
|
|
3883
|
+
Qo as E,
|
|
3884
|
+
gn as F,
|
|
3885
|
+
li as G,
|
|
3886
|
+
di as H,
|
|
3887
|
+
ci as I,
|
|
3888
|
+
Qe as J,
|
|
3889
|
+
pi as K,
|
|
3890
|
+
Js as L,
|
|
3891
|
+
ti as M,
|
|
3892
|
+
si as N,
|
|
3893
|
+
ei as O,
|
|
3894
|
+
ct as P,
|
|
3895
|
+
At as Q,
|
|
3896
|
+
xs as R,
|
|
3897
|
+
Vt as S,
|
|
3898
|
+
nt as T,
|
|
3899
|
+
ri as U,
|
|
3900
|
+
xe as V,
|
|
3901
|
+
Ns as W,
|
|
3902
|
+
ni as X,
|
|
3903
|
+
ii as Y,
|
|
3904
|
+
Kt as Z,
|
|
3905
|
+
yn as _,
|
|
3906
|
+
$i as a,
|
|
3907
|
+
at as a0,
|
|
3908
|
+
xn as a1,
|
|
3909
|
+
Bi as a2,
|
|
3910
|
+
hs as a3,
|
|
3911
|
+
N as a4,
|
|
3912
|
+
wi as a5,
|
|
3913
|
+
ps as a6,
|
|
3914
|
+
bi as a7,
|
|
3915
|
+
gi as a8,
|
|
3916
|
+
Xe as a9,
|
|
3917
|
+
yi as aa,
|
|
3918
|
+
ys as ab,
|
|
3919
|
+
Ei as ac,
|
|
3920
|
+
Si as b,
|
|
3921
|
+
Zs as c,
|
|
3922
|
+
Ms as d,
|
|
3923
|
+
Ii as e,
|
|
3924
|
+
Sr as f,
|
|
3925
|
+
vi as g,
|
|
3926
|
+
rt as h,
|
|
3927
|
+
oi as i,
|
|
3928
|
+
Cn as j,
|
|
3929
|
+
jt as k,
|
|
3930
|
+
xt as l,
|
|
3931
|
+
In as m,
|
|
3932
|
+
xi as n,
|
|
3933
|
+
Ye as o,
|
|
3934
|
+
An as p,
|
|
3935
|
+
ls as q,
|
|
3936
|
+
hi as r,
|
|
3937
|
+
me as s,
|
|
3938
|
+
ui as t,
|
|
3939
|
+
ai as u,
|
|
3940
|
+
be as v,
|
|
3941
|
+
fs as w,
|
|
3942
|
+
Z as x,
|
|
3943
|
+
Ai as y,
|
|
3944
|
+
fi as z
|
|
3945
|
+
};
|
|
3946
|
+
//# sourceMappingURL=index-D7YwhNAG.mjs.map
|