@babylonlabs-io/ts-sdk 0.8.0 → 0.9.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/dist/errors-D_DWT0CT.js +2063 -0
- package/dist/errors-D_DWT0CT.js.map +1 -0
- package/dist/errors-tDgLyp-N.cjs +2 -0
- package/dist/errors-tDgLyp-N.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +59 -53
- package/dist/tbv/core/clients/mempool/__tests__/mempoolApi.test.d.ts +2 -0
- package/dist/tbv/core/clients/mempool/__tests__/mempoolApi.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.d.ts +1 -0
- package/dist/tbv/core/index.d.ts.map +1 -1
- package/dist/tbv/core/index.js +60 -54
- package/dist/tbv/core/lamport/__tests__/derivation.test.d.ts +2 -0
- package/dist/tbv/core/lamport/__tests__/derivation.test.d.ts.map +1 -0
- package/dist/tbv/core/lamport/derivation.d.ts +78 -0
- package/dist/tbv/core/lamport/derivation.d.ts.map +1 -0
- package/dist/tbv/core/lamport/deriveLamportPkHash.d.ts +9 -0
- package/dist/tbv/core/lamport/deriveLamportPkHash.d.ts.map +1 -0
- package/dist/tbv/core/lamport/errors.d.ts +7 -0
- package/dist/tbv/core/lamport/errors.d.ts.map +1 -0
- package/dist/tbv/core/lamport/index.d.ts +5 -0
- package/dist/tbv/core/lamport/index.d.ts.map +1 -0
- package/dist/tbv/core/lamport/types.d.ts +33 -0
- package/dist/tbv/core/lamport/types.d.ts.map +1 -0
- package/dist/tbv/core/managers/PeginManager.d.ts +10 -0
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +60 -54
- package/package.json +3 -1
- package/dist/PayoutManager-9qwA76_B.cjs +0 -2
- package/dist/PayoutManager-9qwA76_B.cjs.map +0 -1
- package/dist/PayoutManager-CvWBwdzd.js +0 -1172
- package/dist/PayoutManager-CvWBwdzd.js.map +0 -1
|
@@ -0,0 +1,2063 @@
|
|
|
1
|
+
var ue = Object.defineProperty;
|
|
2
|
+
var le = (e, t, n) => t in e ? ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var f = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as he from "bitcoinjs-lib";
|
|
5
|
+
import { script as fe, Transaction as st, address as de, Psbt as ft } from "bitcoinjs-lib";
|
|
6
|
+
import { Buffer as S } from "buffer";
|
|
7
|
+
import { P as pe, x as be, D as Dt, M as Pt, B as xe, T as ye, A as dt, t as W, b as ge, z as me, a as we, d as Pe, e as Te, f as ve, r as at, p as He, w as Tt, g as vt, h as Ht } from "./challengeAssert-D50t_Qyo.js";
|
|
8
|
+
import { createPublicClient as kt, http as It, encodeFunctionData as ke, zeroAddress as Ie } from "viem";
|
|
9
|
+
import { c as pt } from "./signOptions-Drwr3bXB.js";
|
|
10
|
+
import { SINGLE_DEPOSIT_HTLC_VOUT as Et } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
11
|
+
function Ee(e, t, n) {
|
|
12
|
+
if (e.length === 0)
|
|
13
|
+
throw new Error("Insufficient funds: no UTXOs available");
|
|
14
|
+
const s = e.filter((c) => {
|
|
15
|
+
const l = S.from(c.scriptPubKey, "hex");
|
|
16
|
+
return !!fe.decompile(l);
|
|
17
|
+
});
|
|
18
|
+
if (s.length === 0)
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Insufficient funds: no valid UTXOs available (all have invalid scripts)"
|
|
21
|
+
);
|
|
22
|
+
const r = [...s].sort((c, l) => l.value - c.value), o = [];
|
|
23
|
+
let i = 0n, a = 0n;
|
|
24
|
+
for (const c of r) {
|
|
25
|
+
o.push(c), i += BigInt(c.value);
|
|
26
|
+
const l = o.length * pe, h = 2 * Pt, u = l + h + ye;
|
|
27
|
+
if (a = BigInt(Math.ceil(u * n)) + BigInt(be(n)), i - t - a > Dt) {
|
|
28
|
+
const p = BigInt(
|
|
29
|
+
Math.ceil(Pt * n)
|
|
30
|
+
);
|
|
31
|
+
a += p;
|
|
32
|
+
}
|
|
33
|
+
if (i >= t + a) {
|
|
34
|
+
const p = i - t - a;
|
|
35
|
+
return {
|
|
36
|
+
selectedUTXOs: o,
|
|
37
|
+
totalValue: i,
|
|
38
|
+
fee: a,
|
|
39
|
+
changeAmount: p
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Insufficient funds: need ${t + a} sats (${t} pegin + ${a} fee), have ${i} sats`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
function zn(e) {
|
|
48
|
+
return e > Dt;
|
|
49
|
+
}
|
|
50
|
+
function qn() {
|
|
51
|
+
return xe;
|
|
52
|
+
}
|
|
53
|
+
function St(e) {
|
|
54
|
+
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
55
|
+
return `0x${st.fromHex(t).getId()}`;
|
|
56
|
+
}
|
|
57
|
+
function Zn(e, t, n) {
|
|
58
|
+
if (e.length === 0)
|
|
59
|
+
throw new Error("No input UTXOs provided for split transaction");
|
|
60
|
+
if (t.length === 0)
|
|
61
|
+
throw new Error("No outputs specified for split transaction");
|
|
62
|
+
for (const c of t)
|
|
63
|
+
if (c.amount <= 0n)
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Invalid output amount for ${c.address}: ${c.amount} satoshis. Amount must be greater than zero.`
|
|
66
|
+
);
|
|
67
|
+
const s = dt(n), r = new st();
|
|
68
|
+
r.version = 2;
|
|
69
|
+
for (const c of e) {
|
|
70
|
+
const l = S.from(c.txid, "hex").reverse();
|
|
71
|
+
r.addInput(l, c.vout);
|
|
72
|
+
}
|
|
73
|
+
const o = [];
|
|
74
|
+
for (let c = 0; c < t.length; c++) {
|
|
75
|
+
const l = t[c];
|
|
76
|
+
let h;
|
|
77
|
+
try {
|
|
78
|
+
h = de.toOutputScript(l.address, s);
|
|
79
|
+
} catch (u) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Failed to decode address "${l.address}": ${u instanceof Error ? u.message : String(u)}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
r.addOutput(h, Number(l.amount)), o.push({
|
|
85
|
+
txid: "",
|
|
86
|
+
// Will be set after txid calculation
|
|
87
|
+
vout: c,
|
|
88
|
+
value: Number(l.amount),
|
|
89
|
+
scriptPubKey: h.toString("hex")
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const i = r.toHex(), a = r.getId();
|
|
93
|
+
for (const c of o)
|
|
94
|
+
c.txid = a;
|
|
95
|
+
return {
|
|
96
|
+
txHex: i,
|
|
97
|
+
txid: a,
|
|
98
|
+
outputs: o
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function Jn(e, t, n) {
|
|
102
|
+
const s = st.fromHex(e), r = new ft();
|
|
103
|
+
if (r.setVersion(s.version), r.setLocktime(s.locktime), !S.isBuffer(n) || n.length !== 32)
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${S.isBuffer(n) ? `${n.length}-byte Buffer` : typeof n}`
|
|
106
|
+
);
|
|
107
|
+
if (t.length !== s.ins.length)
|
|
108
|
+
throw new Error(
|
|
109
|
+
`UTXO count mismatch: transaction has ${s.ins.length} input${s.ins.length !== 1 ? "s" : ""}, but ${t.length} UTXO${t.length !== 1 ? "s were" : " was"} provided`
|
|
110
|
+
);
|
|
111
|
+
for (let o = 0; o < s.ins.length; o++) {
|
|
112
|
+
const i = s.ins[o], a = t[o];
|
|
113
|
+
if (!a)
|
|
114
|
+
throw new Error(`Missing UTXO data for input ${o}`);
|
|
115
|
+
const c = S.from(i.hash).reverse().toString("hex"), l = i.index;
|
|
116
|
+
if (a.txid !== c || a.vout !== l)
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Input ${o} outpoint mismatch: transaction expects ${c}:${l}, but UTXO ${a.txid}:${a.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
|
|
119
|
+
);
|
|
120
|
+
const h = S.from(a.scriptPubKey, "hex");
|
|
121
|
+
if (!(h.length === 34 && h[0] === 81 && // OP_1 (witness version 1)
|
|
122
|
+
h[1] === 32))
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Input ${o} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${a.scriptPubKey.substring(0, 20)}...`
|
|
125
|
+
);
|
|
126
|
+
const d = {
|
|
127
|
+
script: S.from(a.scriptPubKey, "hex"),
|
|
128
|
+
value: a.value
|
|
129
|
+
};
|
|
130
|
+
r.addInput({
|
|
131
|
+
hash: i.hash,
|
|
132
|
+
index: i.index,
|
|
133
|
+
sequence: i.sequence,
|
|
134
|
+
witnessUtxo: d,
|
|
135
|
+
tapInternalKey: n
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
for (const o of s.outs)
|
|
139
|
+
r.addOutput({
|
|
140
|
+
script: o.script,
|
|
141
|
+
value: o.value
|
|
142
|
+
});
|
|
143
|
+
return r.toHex();
|
|
144
|
+
}
|
|
145
|
+
var tt = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(tt || {});
|
|
146
|
+
function Se(e) {
|
|
147
|
+
const t = e.length;
|
|
148
|
+
return t === 25 && e[0] === 118 && // OP_DUP
|
|
149
|
+
e[1] === 169 && // OP_HASH160
|
|
150
|
+
e[2] === 20 && // Push 20 bytes
|
|
151
|
+
e[23] === 136 && // OP_EQUALVERIFY
|
|
152
|
+
e[24] === 172 ? "P2PKH" : t === 23 && e[0] === 169 && // OP_HASH160
|
|
153
|
+
e[1] === 20 && // Push 20 bytes
|
|
154
|
+
e[22] === 135 ? "P2SH" : t === 22 && e[0] === 0 && // OP_0
|
|
155
|
+
e[1] === 20 ? "P2WPKH" : t === 34 && e[0] === 0 && // OP_0
|
|
156
|
+
e[1] === 32 ? "P2WSH" : t === 34 && e[0] === 81 && // OP_1
|
|
157
|
+
e[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
158
|
+
}
|
|
159
|
+
function Ae(e, t) {
|
|
160
|
+
const n = S.from(e.scriptPubKey, "hex"), s = Se(n);
|
|
161
|
+
switch (s) {
|
|
162
|
+
case tt.P2WPKH:
|
|
163
|
+
return {
|
|
164
|
+
witnessUtxo: {
|
|
165
|
+
script: n,
|
|
166
|
+
value: e.value
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
case tt.P2WSH: {
|
|
170
|
+
if (!e.witnessScript)
|
|
171
|
+
throw new Error("Missing witnessScript for P2WSH input");
|
|
172
|
+
return {
|
|
173
|
+
witnessUtxo: {
|
|
174
|
+
script: n,
|
|
175
|
+
value: e.value
|
|
176
|
+
},
|
|
177
|
+
witnessScript: S.from(e.witnessScript, "hex")
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
case tt.P2TR: {
|
|
181
|
+
if (t && t.length !== 32)
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`
|
|
184
|
+
);
|
|
185
|
+
return {
|
|
186
|
+
witnessUtxo: {
|
|
187
|
+
script: n,
|
|
188
|
+
value: e.value
|
|
189
|
+
},
|
|
190
|
+
// tapInternalKey is needed for Taproot signing
|
|
191
|
+
...t && { tapInternalKey: t }
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
default:
|
|
195
|
+
throw new Error(`Unsupported script type: ${s}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const Be = 21e6 * 1e8, Kt = 1e4;
|
|
199
|
+
function Mt(e) {
|
|
200
|
+
return Number.isInteger(e) && e > 0 && e <= Be;
|
|
201
|
+
}
|
|
202
|
+
function Ue(e) {
|
|
203
|
+
return Number.isInteger(e) && e > 0 && e <= Kt;
|
|
204
|
+
}
|
|
205
|
+
function Nt(e, t) {
|
|
206
|
+
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
207
|
+
}
|
|
208
|
+
const Le = {
|
|
209
|
+
mainnet: "https://mempool.space/api",
|
|
210
|
+
testnet: "https://mempool.space/testnet/api",
|
|
211
|
+
signet: "https://mempool.space/signet/api"
|
|
212
|
+
};
|
|
213
|
+
async function nt(e, t) {
|
|
214
|
+
try {
|
|
215
|
+
const n = await fetch(e, t);
|
|
216
|
+
if (!n.ok) {
|
|
217
|
+
const r = await n.text();
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Mempool API error (${n.status}): ${r || n.statusText}`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const s = n.headers.get("content-type");
|
|
223
|
+
return s != null && s.includes("application/json") ? await n.json() : await n.text();
|
|
224
|
+
} catch (n) {
|
|
225
|
+
throw n instanceof Error ? new Error(`Failed to fetch from mempool API: ${n.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async function $e(e, t) {
|
|
229
|
+
try {
|
|
230
|
+
const n = await fetch(`${t}/tx`, {
|
|
231
|
+
method: "POST",
|
|
232
|
+
body: e,
|
|
233
|
+
headers: {
|
|
234
|
+
"Content-Type": "text/plain"
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
if (!n.ok) {
|
|
238
|
+
const r = await n.text();
|
|
239
|
+
let o;
|
|
240
|
+
try {
|
|
241
|
+
o = JSON.parse(r).message;
|
|
242
|
+
} catch {
|
|
243
|
+
o = r;
|
|
244
|
+
}
|
|
245
|
+
throw new Error(
|
|
246
|
+
o || `Failed to broadcast transaction: ${n.statusText}`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
return await n.text();
|
|
250
|
+
} catch (n) {
|
|
251
|
+
throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function Fe(e, t) {
|
|
255
|
+
return nt(`${t}/tx/${e}`);
|
|
256
|
+
}
|
|
257
|
+
async function Yn(e, t) {
|
|
258
|
+
try {
|
|
259
|
+
const n = await fetch(`${t}/tx/${e}/hex`);
|
|
260
|
+
if (!n.ok) {
|
|
261
|
+
const s = await n.text();
|
|
262
|
+
throw new Error(
|
|
263
|
+
`Mempool API error (${n.status}): ${s || n.statusText}`
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return await n.text();
|
|
267
|
+
} catch (n) {
|
|
268
|
+
throw n instanceof Error ? new Error(`Failed to get transaction hex for ${e}: ${n.message}`) : new Error(`Failed to get transaction hex for ${e}: Unknown error`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function Oe(e, t, n) {
|
|
272
|
+
const s = await Fe(e, n);
|
|
273
|
+
if (!Nt(t, s.vout.length))
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
|
|
276
|
+
);
|
|
277
|
+
const r = s.vout[t];
|
|
278
|
+
if (!Mt(r.value))
|
|
279
|
+
throw new Error(`Invalid UTXO value ${r.value} for ${e}:${t}`);
|
|
280
|
+
return {
|
|
281
|
+
txid: e,
|
|
282
|
+
vout: t,
|
|
283
|
+
value: r.value,
|
|
284
|
+
scriptPubKey: r.scriptpubkey
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async function Qn(e, t) {
|
|
288
|
+
try {
|
|
289
|
+
const n = await nt(`${t}/address/${e}/utxo`), s = await nt(`${t}/v1/validate-address/${e}`);
|
|
290
|
+
if (!s.isvalid)
|
|
291
|
+
throw new Error(
|
|
292
|
+
`Invalid Bitcoin address: ${e}. Mempool API validation failed.`
|
|
293
|
+
);
|
|
294
|
+
for (const o of n) {
|
|
295
|
+
if (!Nt(o.vout))
|
|
296
|
+
throw new Error(`Invalid vout ${o.vout} for ${o.txid}`);
|
|
297
|
+
if (!Mt(o.value))
|
|
298
|
+
throw new Error(
|
|
299
|
+
`Invalid UTXO value ${o.value} for ${o.txid}:${o.vout}`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
return n.sort((o, i) => i.value - o.value).map((o) => ({
|
|
303
|
+
txid: o.txid,
|
|
304
|
+
vout: o.vout,
|
|
305
|
+
value: o.value,
|
|
306
|
+
scriptPubKey: s.scriptPubKey,
|
|
307
|
+
confirmed: o.status.confirmed
|
|
308
|
+
}));
|
|
309
|
+
} catch (n) {
|
|
310
|
+
throw n instanceof Error ? new Error(
|
|
311
|
+
`Failed to get UTXOs for address ${e}: ${n.message}`
|
|
312
|
+
) : new Error(
|
|
313
|
+
`Failed to get UTXOs for address ${e}: Unknown error`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function ts(e) {
|
|
318
|
+
return Le[e];
|
|
319
|
+
}
|
|
320
|
+
async function es(e, t) {
|
|
321
|
+
return nt(`${t}/address/${e}/txs`);
|
|
322
|
+
}
|
|
323
|
+
async function ns(e) {
|
|
324
|
+
const t = await fetch(`${e}/v1/fees/recommended`);
|
|
325
|
+
if (!t.ok)
|
|
326
|
+
throw new Error(
|
|
327
|
+
`Failed to fetch network fees: ${t.status} ${t.statusText}`
|
|
328
|
+
);
|
|
329
|
+
const n = await t.json(), s = [
|
|
330
|
+
"fastestFee",
|
|
331
|
+
"halfHourFee",
|
|
332
|
+
"hourFee",
|
|
333
|
+
"economyFee",
|
|
334
|
+
"minimumFee"
|
|
335
|
+
];
|
|
336
|
+
for (const r of s)
|
|
337
|
+
if (!Ue(n[r]))
|
|
338
|
+
throw new Error(
|
|
339
|
+
`Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Kt}`
|
|
340
|
+
);
|
|
341
|
+
if (n.minimumFee > n.economyFee || n.economyFee > n.hourFee || n.hourFee > n.halfHourFee || n.halfHourFee > n.fastestFee)
|
|
342
|
+
throw new Error(
|
|
343
|
+
`Fee rate ordering violation from mempool API: expected minimumFee (${n.minimumFee}) <= economyFee (${n.economyFee}) <= hourFee (${n.hourFee}) <= halfHourFee (${n.halfHourFee}) <= fastestFee (${n.fastestFee}).`
|
|
344
|
+
);
|
|
345
|
+
return n;
|
|
346
|
+
}
|
|
347
|
+
const ct = [
|
|
348
|
+
{
|
|
349
|
+
type: "function",
|
|
350
|
+
name: "submitPeginRequest",
|
|
351
|
+
inputs: [
|
|
352
|
+
{
|
|
353
|
+
name: "depositor",
|
|
354
|
+
type: "address",
|
|
355
|
+
internalType: "address"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: "depositorBtcPubKey",
|
|
359
|
+
type: "bytes32",
|
|
360
|
+
internalType: "bytes32"
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: "btcPopSignature",
|
|
364
|
+
type: "bytes",
|
|
365
|
+
internalType: "bytes"
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
name: "unsignedPrePeginTx",
|
|
369
|
+
type: "bytes",
|
|
370
|
+
internalType: "bytes"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "depositorSignedPeginTx",
|
|
374
|
+
type: "bytes",
|
|
375
|
+
internalType: "bytes"
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: "vaultProvider",
|
|
379
|
+
type: "address",
|
|
380
|
+
internalType: "address"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: "hashlock",
|
|
384
|
+
type: "bytes32",
|
|
385
|
+
internalType: "bytes32"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: "htlcVout",
|
|
389
|
+
type: "uint8",
|
|
390
|
+
internalType: "uint8"
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: "depositorPayoutBtcAddress",
|
|
394
|
+
type: "bytes",
|
|
395
|
+
internalType: "bytes"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
name: "depositorLamportPkHash",
|
|
399
|
+
type: "bytes32",
|
|
400
|
+
internalType: "bytes32"
|
|
401
|
+
}
|
|
402
|
+
],
|
|
403
|
+
outputs: [
|
|
404
|
+
{
|
|
405
|
+
name: "",
|
|
406
|
+
type: "bytes32",
|
|
407
|
+
internalType: "bytes32"
|
|
408
|
+
}
|
|
409
|
+
],
|
|
410
|
+
stateMutability: "payable"
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
type: "function",
|
|
414
|
+
name: "submitPeginRequest",
|
|
415
|
+
inputs: [
|
|
416
|
+
{
|
|
417
|
+
name: "depositor",
|
|
418
|
+
type: "address",
|
|
419
|
+
internalType: "address"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: "depositorBtcPubKey",
|
|
423
|
+
type: "bytes32",
|
|
424
|
+
internalType: "bytes32"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: "btcPopSignature",
|
|
428
|
+
type: "bytes",
|
|
429
|
+
internalType: "bytes"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: "unsignedPrePeginTx",
|
|
433
|
+
type: "bytes",
|
|
434
|
+
internalType: "bytes"
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: "depositorSignedPeginTx",
|
|
438
|
+
type: "bytes",
|
|
439
|
+
internalType: "bytes"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: "vaultProvider",
|
|
443
|
+
type: "address",
|
|
444
|
+
internalType: "address"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: "hashlock",
|
|
448
|
+
type: "bytes32",
|
|
449
|
+
internalType: "bytes32"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "htlcVout",
|
|
453
|
+
type: "uint8",
|
|
454
|
+
internalType: "uint8"
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: "referralCode",
|
|
458
|
+
type: "uint32",
|
|
459
|
+
internalType: "uint32"
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: "depositorPayoutBtcAddress",
|
|
463
|
+
type: "bytes",
|
|
464
|
+
internalType: "bytes"
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
name: "depositorLamportPkHash",
|
|
468
|
+
type: "bytes32",
|
|
469
|
+
internalType: "bytes32"
|
|
470
|
+
}
|
|
471
|
+
],
|
|
472
|
+
outputs: [
|
|
473
|
+
{
|
|
474
|
+
name: "",
|
|
475
|
+
type: "bytes32",
|
|
476
|
+
internalType: "bytes32"
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
stateMutability: "payable"
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
type: "function",
|
|
483
|
+
name: "activateVaultWithSecret",
|
|
484
|
+
inputs: [
|
|
485
|
+
{
|
|
486
|
+
name: "vaultId",
|
|
487
|
+
type: "bytes32",
|
|
488
|
+
internalType: "bytes32"
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
name: "s",
|
|
492
|
+
type: "bytes32",
|
|
493
|
+
internalType: "bytes32"
|
|
494
|
+
}
|
|
495
|
+
],
|
|
496
|
+
outputs: [],
|
|
497
|
+
stateMutability: "nonpayable"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
type: "function",
|
|
501
|
+
name: "getPegInFee",
|
|
502
|
+
inputs: [
|
|
503
|
+
{
|
|
504
|
+
name: "vaultProvider",
|
|
505
|
+
type: "address",
|
|
506
|
+
internalType: "address"
|
|
507
|
+
}
|
|
508
|
+
],
|
|
509
|
+
outputs: [
|
|
510
|
+
{
|
|
511
|
+
name: "totalFee",
|
|
512
|
+
type: "uint256",
|
|
513
|
+
internalType: "uint256"
|
|
514
|
+
}
|
|
515
|
+
],
|
|
516
|
+
stateMutability: "view"
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
type: "function",
|
|
520
|
+
name: "getBTCVault",
|
|
521
|
+
inputs: [
|
|
522
|
+
{
|
|
523
|
+
name: "vaultId",
|
|
524
|
+
type: "bytes32",
|
|
525
|
+
internalType: "bytes32"
|
|
526
|
+
}
|
|
527
|
+
],
|
|
528
|
+
outputs: [
|
|
529
|
+
{
|
|
530
|
+
name: "vault",
|
|
531
|
+
type: "tuple",
|
|
532
|
+
internalType: "struct IBTCVaultRegistry.BTCVault",
|
|
533
|
+
components: [
|
|
534
|
+
{ name: "depositor", type: "address", internalType: "address" },
|
|
535
|
+
{ name: "depositorBtcPubKey", type: "bytes32", internalType: "bytes32" },
|
|
536
|
+
{ name: "depositorSignedPeginTx", type: "bytes", internalType: "bytes" },
|
|
537
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
538
|
+
{ name: "vaultProvider", type: "address", internalType: "address" },
|
|
539
|
+
{ name: "status", type: "uint8", internalType: "enum IBTCVaultRegistry.BTCVaultStatus" },
|
|
540
|
+
{ name: "applicationEntryPoint", type: "address", internalType: "address" },
|
|
541
|
+
{ name: "universalChallengersVersion", type: "uint16", internalType: "uint16" },
|
|
542
|
+
{ name: "appVaultKeepersVersion", type: "uint16", internalType: "uint16" },
|
|
543
|
+
{ name: "offchainParamsVersion", type: "uint16", internalType: "uint16" },
|
|
544
|
+
{ name: "proverProgramVersion", type: "uint16", internalType: "uint16" },
|
|
545
|
+
{ name: "createdAt", type: "uint256", internalType: "uint256" },
|
|
546
|
+
{ name: "verifiedAt", type: "uint256", internalType: "uint256" },
|
|
547
|
+
{ name: "depositorLamportPkHash", type: "bytes32", internalType: "bytes32" },
|
|
548
|
+
{ name: "hashlock", type: "bytes32", internalType: "bytes32" },
|
|
549
|
+
{ name: "htlcVout", type: "uint8", internalType: "uint8" }
|
|
550
|
+
]
|
|
551
|
+
}
|
|
552
|
+
],
|
|
553
|
+
stateMutability: "view"
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
type: "error",
|
|
557
|
+
name: "InvalidPeginFee",
|
|
558
|
+
inputs: [
|
|
559
|
+
{
|
|
560
|
+
name: "provided",
|
|
561
|
+
type: "uint256",
|
|
562
|
+
internalType: "uint256"
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
name: "required",
|
|
566
|
+
type: "uint256",
|
|
567
|
+
internalType: "uint256"
|
|
568
|
+
}
|
|
569
|
+
]
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
type: "error",
|
|
573
|
+
name: "InvalidSecret",
|
|
574
|
+
inputs: []
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
type: "error",
|
|
578
|
+
name: "ActivationDeadlineExpired",
|
|
579
|
+
inputs: []
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
type: "error",
|
|
583
|
+
name: "InvalidHashlock",
|
|
584
|
+
inputs: []
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
type: "error",
|
|
588
|
+
name: "DuplicateHashlock",
|
|
589
|
+
inputs: []
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
type: "error",
|
|
593
|
+
name: "CapExceeded",
|
|
594
|
+
inputs: []
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
type: "error",
|
|
598
|
+
name: "InvalidOutputIndex",
|
|
599
|
+
inputs: []
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
type: "error",
|
|
603
|
+
name: "PeginSignaturesIncomplete",
|
|
604
|
+
inputs: []
|
|
605
|
+
}
|
|
606
|
+
], D = {
|
|
607
|
+
// VaultAlreadyExists()
|
|
608
|
+
"0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
|
|
609
|
+
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
610
|
+
"0x4fec082d": "Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.",
|
|
611
|
+
// InvalidBTCProofOfPossession()
|
|
612
|
+
"0x6cc363a5": "Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.",
|
|
613
|
+
// InvalidBTCPublicKey()
|
|
614
|
+
"0x6c3f2bf6": "Invalid BTC public key: The Bitcoin public key format is invalid.",
|
|
615
|
+
// InvalidAmount()
|
|
616
|
+
"0x2c5211c6": "Invalid amount: The deposit amount is invalid or below the minimum required.",
|
|
617
|
+
// ApplicationNotRegistered()
|
|
618
|
+
"0x0405f772": "Application not registered: The application controller is not registered in the system.",
|
|
619
|
+
// InvalidProviderStatus()
|
|
620
|
+
"0x24e165cc": "Invalid provider status: The vault provider is not in a valid state to accept deposits.",
|
|
621
|
+
// ZeroAddress()
|
|
622
|
+
"0xd92e233d": "Zero address: One of the required addresses is the zero address.",
|
|
623
|
+
// BtcKeyMismatch()
|
|
624
|
+
"0x65aa7007": "BTC key mismatch: The Bitcoin public key does not match the expected key.",
|
|
625
|
+
// Unauthorized()
|
|
626
|
+
"0x82b42900": "Unauthorized: You must be the depositor or vault provider to submit this transaction.",
|
|
627
|
+
// InvalidSignature() - common signature verification error
|
|
628
|
+
"0x8baa579f": "Invalid signature: The BTC proof of possession signature could not be verified.",
|
|
629
|
+
// InvalidBtcTransaction()
|
|
630
|
+
"0x2f9d01e9": "Invalid BTC transaction: The Bitcoin transaction format is invalid.",
|
|
631
|
+
// VaultProviderNotRegistered()
|
|
632
|
+
"0x5a3c6b3e": "Vault provider not registered: The selected vault provider is not registered.",
|
|
633
|
+
// InvalidPeginFee(uint256,uint256)
|
|
634
|
+
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
635
|
+
};
|
|
636
|
+
function xt(e) {
|
|
637
|
+
if (!e || typeof e != "object") return;
|
|
638
|
+
const t = e;
|
|
639
|
+
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
640
|
+
return t.data;
|
|
641
|
+
if (typeof t.details == "string" && t.details.startsWith("0x"))
|
|
642
|
+
return t.details;
|
|
643
|
+
let n = t.cause, s = 0;
|
|
644
|
+
const r = 5;
|
|
645
|
+
for (; n && typeof n == "object" && s < r; ) {
|
|
646
|
+
const a = n;
|
|
647
|
+
if (typeof a.data == "string" && a.data.startsWith("0x"))
|
|
648
|
+
return a.data;
|
|
649
|
+
n = a.cause, s++;
|
|
650
|
+
}
|
|
651
|
+
const i = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
|
|
652
|
+
if (i)
|
|
653
|
+
return i[1];
|
|
654
|
+
}
|
|
655
|
+
function ss(e) {
|
|
656
|
+
const t = xt(e);
|
|
657
|
+
if (t) {
|
|
658
|
+
const n = t.substring(0, 10);
|
|
659
|
+
return D[t] ?? D[n];
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function rs(e) {
|
|
663
|
+
const t = xt(e);
|
|
664
|
+
if (t === void 0) return !1;
|
|
665
|
+
const n = t.substring(0, 10);
|
|
666
|
+
return t in D || n in D;
|
|
667
|
+
}
|
|
668
|
+
function At(e) {
|
|
669
|
+
console.error("[Contract Error] Raw error:", e);
|
|
670
|
+
const t = xt(e);
|
|
671
|
+
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
672
|
+
const s = t.substring(0, 10), r = D[t] ?? D[s];
|
|
673
|
+
if (r)
|
|
674
|
+
throw console.error("[Contract Error] Known error:", r), new Error(r);
|
|
675
|
+
}
|
|
676
|
+
const n = (e == null ? void 0 : e.message) || "";
|
|
677
|
+
if (n.includes("gas limit too high") || n.includes("21000000") || n.includes("Internal JSON-RPC error")) {
|
|
678
|
+
const s = t ? ` (error code: ${t})` : "";
|
|
679
|
+
throw console.error(
|
|
680
|
+
"[Contract Error] Transaction rejected. Error code:",
|
|
681
|
+
t,
|
|
682
|
+
"Message:",
|
|
683
|
+
n
|
|
684
|
+
), new Error(
|
|
685
|
+
`Transaction failed: The contract rejected this transaction${s}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
689
|
+
}
|
|
690
|
+
function Ce(e, t, n, s) {
|
|
691
|
+
const r = n == null ? void 0 : n[`${e}:${t}`];
|
|
692
|
+
return r ? Promise.resolve({
|
|
693
|
+
txid: e,
|
|
694
|
+
vout: t,
|
|
695
|
+
value: r.value,
|
|
696
|
+
scriptPubKey: r.scriptPubKey
|
|
697
|
+
}) : Oe(e, t, s);
|
|
698
|
+
}
|
|
699
|
+
class os {
|
|
700
|
+
/**
|
|
701
|
+
* Creates a new PeginManager instance.
|
|
702
|
+
*
|
|
703
|
+
* @param config - Manager configuration including wallets and contract addresses
|
|
704
|
+
*/
|
|
705
|
+
constructor(t) {
|
|
706
|
+
f(this, "config");
|
|
707
|
+
this.config = t;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Prepares a peg-in by building the Pre-PegIn HTLC transaction,
|
|
711
|
+
* funding it, constructing the PegIn transaction, and signing the PegIn input.
|
|
712
|
+
*
|
|
713
|
+
* This method orchestrates the following steps:
|
|
714
|
+
* 1. Get depositor BTC public key from wallet
|
|
715
|
+
* 2. Build unfunded Pre-PegIn transaction (HTLC output) using primitives
|
|
716
|
+
* 3. Select UTXOs to cover the HTLC value
|
|
717
|
+
* 4. Fund the Pre-PegIn transaction
|
|
718
|
+
* 5. Derive the PegIn transaction from the funded Pre-PegIn txid
|
|
719
|
+
* 6. Build PSBT for signing the PegIn input (HTLC leaf 0)
|
|
720
|
+
* 7. Sign via BTC wallet and extract depositor signature
|
|
721
|
+
*
|
|
722
|
+
* The returned `fundedPrePeginTxHex` is funded but unsigned (inputs unsigned).
|
|
723
|
+
* Use `signAndBroadcast()` AFTER registering on Ethereum to broadcast it.
|
|
724
|
+
*
|
|
725
|
+
* @param params - Pegin parameters including amount, HTLC params, UTXOs
|
|
726
|
+
* @returns Pegin result with funded Pre-PegIn tx, signed PegIn input, and signatures
|
|
727
|
+
* @throws Error if wallet operations fail or insufficient funds
|
|
728
|
+
*/
|
|
729
|
+
async preparePegin(t) {
|
|
730
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r = W(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map(W), i = t.universalChallengerBtcPubkeys.map(W);
|
|
731
|
+
if (t.hashlocks.length !== 1)
|
|
732
|
+
throw new Error(
|
|
733
|
+
"hashlocks must contain exactly one entry (batched deposits not yet supported)"
|
|
734
|
+
);
|
|
735
|
+
const a = o.length, c = {
|
|
736
|
+
depositorPubkey: s,
|
|
737
|
+
vaultProviderPubkey: r,
|
|
738
|
+
vaultKeeperPubkeys: o,
|
|
739
|
+
universalChallengerPubkeys: i,
|
|
740
|
+
hashlocks: t.hashlocks,
|
|
741
|
+
timelockRefund: t.timelockRefund,
|
|
742
|
+
pegInAmount: t.amount,
|
|
743
|
+
feeRate: t.protocolFeeRate,
|
|
744
|
+
numLocalChallengers: a,
|
|
745
|
+
councilQuorum: t.councilQuorum,
|
|
746
|
+
councilSize: t.councilSize,
|
|
747
|
+
network: this.config.btcNetwork
|
|
748
|
+
}, l = await ge(c), h = Ee(
|
|
749
|
+
[...t.availableUTXOs],
|
|
750
|
+
l.totalOutputValue,
|
|
751
|
+
t.mempoolFeeRate
|
|
752
|
+
), u = dt(this.config.btcNetwork), d = me({
|
|
753
|
+
unfundedTxHex: l.psbtHex,
|
|
754
|
+
selectedUTXOs: h.selectedUTXOs,
|
|
755
|
+
changeAddress: t.changeAddress,
|
|
756
|
+
changeAmount: h.changeAmount,
|
|
757
|
+
network: u
|
|
758
|
+
}), p = W(St(d)), b = await we({
|
|
759
|
+
prePeginParams: c,
|
|
760
|
+
timelockPegin: t.timelockPegin,
|
|
761
|
+
fundedPrePeginTxHex: d,
|
|
762
|
+
htlcVout: Et
|
|
763
|
+
}), m = await Pe({
|
|
764
|
+
peginTxHex: b.txHex,
|
|
765
|
+
fundedPrePeginTxHex: d,
|
|
766
|
+
depositorPubkey: s,
|
|
767
|
+
vaultProviderPubkey: r,
|
|
768
|
+
vaultKeeperPubkeys: o,
|
|
769
|
+
universalChallengerPubkeys: i,
|
|
770
|
+
hashlock: t.hashlocks[0],
|
|
771
|
+
timelockRefund: t.timelockRefund,
|
|
772
|
+
network: this.config.btcNetwork
|
|
773
|
+
}), x = await this.config.btcWallet.signPsbt(
|
|
774
|
+
m.psbtHex,
|
|
775
|
+
pt(n, 1)
|
|
776
|
+
), g = Te(
|
|
777
|
+
x,
|
|
778
|
+
s
|
|
779
|
+
), w = ve(x);
|
|
780
|
+
return {
|
|
781
|
+
fundedPrePeginTxHex: d,
|
|
782
|
+
htlcValue: l.htlcValue,
|
|
783
|
+
signedPeginInputPsbtHex: x,
|
|
784
|
+
peginInputSignature: g,
|
|
785
|
+
vaultScriptPubKey: b.vaultScriptPubKey,
|
|
786
|
+
peginTxHex: w,
|
|
787
|
+
prePeginTxid: p,
|
|
788
|
+
peginTxid: b.txid,
|
|
789
|
+
selectedUTXOs: h.selectedUTXOs,
|
|
790
|
+
fee: h.fee,
|
|
791
|
+
changeAmount: h.changeAmount
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Signs and broadcasts a funded peg-in transaction to the Bitcoin network.
|
|
796
|
+
*
|
|
797
|
+
* This method:
|
|
798
|
+
* 1. Parses the funded transaction hex
|
|
799
|
+
* 2. Fetches UTXO data from mempool for each input
|
|
800
|
+
* 3. Creates a PSBT with proper witnessUtxo/tapInternalKey
|
|
801
|
+
* 4. Signs via btcWallet.signPsbt()
|
|
802
|
+
* 5. Finalizes and extracts the transaction
|
|
803
|
+
* 6. Broadcasts via mempool API
|
|
804
|
+
*
|
|
805
|
+
* @param params - Transaction hex and depositor public key
|
|
806
|
+
* @returns The broadcasted Bitcoin transaction ID
|
|
807
|
+
* @throws Error if signing or broadcasting fails
|
|
808
|
+
*/
|
|
809
|
+
async signAndBroadcast(t) {
|
|
810
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o = st.fromHex(r);
|
|
811
|
+
if (o.ins.length === 0)
|
|
812
|
+
throw new Error("Transaction has no inputs");
|
|
813
|
+
const i = new ft();
|
|
814
|
+
i.setVersion(o.version), i.setLocktime(o.locktime);
|
|
815
|
+
const a = s.startsWith("0x") ? s.slice(2) : s;
|
|
816
|
+
if (a.length !== 64 || !/^[0-9a-fA-F]+$/.test(a))
|
|
817
|
+
throw new Error(
|
|
818
|
+
"Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)"
|
|
819
|
+
);
|
|
820
|
+
const c = S.from(a, "hex");
|
|
821
|
+
if (c.length !== 32)
|
|
822
|
+
throw new Error(
|
|
823
|
+
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
824
|
+
);
|
|
825
|
+
const l = this.config.mempoolApiUrl, h = o.ins.map((x) => {
|
|
826
|
+
const g = S.from(x.hash).reverse().toString("hex"), w = x.index;
|
|
827
|
+
return Ce(g, w, t.localPrevouts, l).then(
|
|
828
|
+
(y) => ({ input: x, utxoData: y, txid: g, vout: w })
|
|
829
|
+
);
|
|
830
|
+
}), u = await Promise.all(h);
|
|
831
|
+
for (const { input: x, utxoData: g, txid: w, vout: y } of u) {
|
|
832
|
+
const P = Ae(
|
|
833
|
+
{
|
|
834
|
+
value: g.value,
|
|
835
|
+
scriptPubKey: g.scriptPubKey
|
|
836
|
+
},
|
|
837
|
+
c
|
|
838
|
+
);
|
|
839
|
+
i.addInput({
|
|
840
|
+
hash: x.hash,
|
|
841
|
+
index: x.index,
|
|
842
|
+
sequence: x.sequence,
|
|
843
|
+
...P
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
for (const x of o.outs)
|
|
847
|
+
i.addOutput({
|
|
848
|
+
script: x.script,
|
|
849
|
+
value: x.value
|
|
850
|
+
});
|
|
851
|
+
const d = await this.config.btcWallet.signPsbt(i.toHex()), p = ft.fromHex(d);
|
|
852
|
+
try {
|
|
853
|
+
p.finalizeAllInputs();
|
|
854
|
+
} catch (x) {
|
|
855
|
+
if (!p.data.inputs.every(
|
|
856
|
+
(w) => w.finalScriptWitness || w.finalScriptSig
|
|
857
|
+
))
|
|
858
|
+
throw new Error(
|
|
859
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${x}`
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
const b = p.extractTransaction().toHex();
|
|
863
|
+
return await $e(b, l);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
867
|
+
*
|
|
868
|
+
* This method:
|
|
869
|
+
* 1. Gets depositor ETH address from wallet
|
|
870
|
+
* 2. Creates proof of possession (BTC signature of ETH address)
|
|
871
|
+
* 3. Checks if vault already exists (pre-flight check)
|
|
872
|
+
* 4. Encodes the contract call using viem
|
|
873
|
+
* 5. Estimates gas (catches contract errors early with proper revert reasons)
|
|
874
|
+
* 6. Sends transaction with pre-estimated gas via ethWallet.sendTransaction()
|
|
875
|
+
*
|
|
876
|
+
* @param params - Registration parameters including BTC pubkey and unsigned tx
|
|
877
|
+
* @returns Result containing Ethereum transaction hash and vault ID
|
|
878
|
+
* @throws Error if signing or transaction fails
|
|
879
|
+
* @throws Error if vault already exists
|
|
880
|
+
* @throws Error if contract simulation fails (e.g., invalid signature, unauthorized)
|
|
881
|
+
*/
|
|
882
|
+
async registerPeginOnChain(t) {
|
|
883
|
+
const {
|
|
884
|
+
depositorBtcPubkey: n,
|
|
885
|
+
unsignedPrePeginTx: s,
|
|
886
|
+
depositorSignedPeginTx: r,
|
|
887
|
+
vaultProvider: o,
|
|
888
|
+
hashlock: i,
|
|
889
|
+
onPopSigned: a,
|
|
890
|
+
depositorPayoutBtcAddress: c,
|
|
891
|
+
depositorLamportPkHash: l,
|
|
892
|
+
preSignedBtcPopSignature: h
|
|
893
|
+
} = t;
|
|
894
|
+
if (!this.config.ethWallet.account)
|
|
895
|
+
throw new Error("Ethereum wallet account not found");
|
|
896
|
+
const u = this.config.ethWallet.account.address, d = await this.resolvePopSignature(
|
|
897
|
+
u,
|
|
898
|
+
h
|
|
899
|
+
);
|
|
900
|
+
a && await a();
|
|
901
|
+
const p = at(n), b = at(s), m = at(r), x = await this.resolvePayoutScriptPubKey(
|
|
902
|
+
c
|
|
903
|
+
), g = St(m);
|
|
904
|
+
if (await this.checkVaultExists(g))
|
|
905
|
+
throw new Error(
|
|
906
|
+
`Vault already exists for this transaction (ID: ${g}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
|
|
907
|
+
);
|
|
908
|
+
const y = kt({
|
|
909
|
+
chain: this.config.ethChain,
|
|
910
|
+
transport: It()
|
|
911
|
+
});
|
|
912
|
+
let P;
|
|
913
|
+
try {
|
|
914
|
+
P = await y.readContract({
|
|
915
|
+
address: this.config.vaultContracts.btcVaultRegistry,
|
|
916
|
+
abi: ct,
|
|
917
|
+
functionName: "getPegInFee",
|
|
918
|
+
args: [o]
|
|
919
|
+
});
|
|
920
|
+
} catch {
|
|
921
|
+
throw new Error(
|
|
922
|
+
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
const v = ke({
|
|
926
|
+
abi: ct,
|
|
927
|
+
functionName: "submitPeginRequest",
|
|
928
|
+
args: [
|
|
929
|
+
u,
|
|
930
|
+
p,
|
|
931
|
+
d,
|
|
932
|
+
b,
|
|
933
|
+
m,
|
|
934
|
+
o,
|
|
935
|
+
i,
|
|
936
|
+
Et,
|
|
937
|
+
x,
|
|
938
|
+
l
|
|
939
|
+
]
|
|
940
|
+
});
|
|
941
|
+
let T;
|
|
942
|
+
try {
|
|
943
|
+
T = await y.estimateGas({
|
|
944
|
+
to: this.config.vaultContracts.btcVaultRegistry,
|
|
945
|
+
data: v,
|
|
946
|
+
value: P,
|
|
947
|
+
account: this.config.ethWallet.account.address
|
|
948
|
+
});
|
|
949
|
+
} catch (k) {
|
|
950
|
+
At(k);
|
|
951
|
+
}
|
|
952
|
+
try {
|
|
953
|
+
return {
|
|
954
|
+
ethTxHash: await this.config.ethWallet.sendTransaction({
|
|
955
|
+
to: this.config.vaultContracts.btcVaultRegistry,
|
|
956
|
+
data: v,
|
|
957
|
+
value: P,
|
|
958
|
+
account: this.config.ethWallet.account,
|
|
959
|
+
chain: this.config.ethChain,
|
|
960
|
+
gas: T
|
|
961
|
+
}),
|
|
962
|
+
vaultId: g,
|
|
963
|
+
btcPopSignature: d
|
|
964
|
+
};
|
|
965
|
+
} catch (k) {
|
|
966
|
+
At(k);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Check if a vault already exists for a given vault ID.
|
|
971
|
+
*
|
|
972
|
+
* @param vaultId - The Bitcoin transaction hash (vault ID)
|
|
973
|
+
* @returns True if vault exists, false otherwise
|
|
974
|
+
*/
|
|
975
|
+
async checkVaultExists(t) {
|
|
976
|
+
try {
|
|
977
|
+
return (await kt({
|
|
978
|
+
chain: this.config.ethChain,
|
|
979
|
+
transport: It()
|
|
980
|
+
}).readContract({
|
|
981
|
+
address: this.config.vaultContracts.btcVaultRegistry,
|
|
982
|
+
abi: ct,
|
|
983
|
+
functionName: "getBTCVault",
|
|
984
|
+
args: [t]
|
|
985
|
+
})).depositor !== Ie;
|
|
986
|
+
} catch {
|
|
987
|
+
return !1;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Resolve the BTC payout address to a scriptPubKey hex for the contract.
|
|
992
|
+
*
|
|
993
|
+
* If a payout address is provided, converts it directly.
|
|
994
|
+
* If omitted, uses the wallet's address and validates it against the
|
|
995
|
+
* wallet's public key to guard against a compromised wallet provider.
|
|
996
|
+
*/
|
|
997
|
+
async resolvePayoutScriptPubKey(t) {
|
|
998
|
+
let n;
|
|
999
|
+
if (t)
|
|
1000
|
+
n = t;
|
|
1001
|
+
else {
|
|
1002
|
+
n = await this.config.btcWallet.getAddress();
|
|
1003
|
+
const r = await this.config.btcWallet.getPublicKeyHex();
|
|
1004
|
+
if (!He(
|
|
1005
|
+
n,
|
|
1006
|
+
r,
|
|
1007
|
+
this.config.btcNetwork
|
|
1008
|
+
))
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
const s = dt(this.config.btcNetwork);
|
|
1014
|
+
try {
|
|
1015
|
+
return `0x${he.address.toOutputScript(n, s).toString("hex")}`;
|
|
1016
|
+
} catch {
|
|
1017
|
+
throw new Error(
|
|
1018
|
+
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Resolve or create a BTC Proof-of-Possession signature.
|
|
1024
|
+
*
|
|
1025
|
+
* Reuses a pre-signed signature when provided (e.g. multi-vault deposits),
|
|
1026
|
+
* otherwise signs a BIP-322 message with the BTC wallet.
|
|
1027
|
+
*/
|
|
1028
|
+
async resolvePopSignature(t, n) {
|
|
1029
|
+
if (n)
|
|
1030
|
+
return n;
|
|
1031
|
+
const s = this.config.vaultContracts.btcVaultRegistry, r = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, o = await this.config.btcWallet.signMessage(
|
|
1032
|
+
r,
|
|
1033
|
+
"bip322-simple"
|
|
1034
|
+
);
|
|
1035
|
+
return o.startsWith("0x") ? o : `0x${S.from(o, "base64").toString("hex")}`;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Gets the configured Bitcoin network.
|
|
1039
|
+
*
|
|
1040
|
+
* @returns The Bitcoin network (mainnet, testnet, signet, regtest)
|
|
1041
|
+
*/
|
|
1042
|
+
getNetwork() {
|
|
1043
|
+
return this.config.btcNetwork;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Gets the configured BTCVaultRegistry contract address.
|
|
1047
|
+
*
|
|
1048
|
+
* @returns The Ethereum address of the BTCVaultRegistry contract
|
|
1049
|
+
*/
|
|
1050
|
+
getVaultContractAddress() {
|
|
1051
|
+
return this.config.vaultContracts.btcVaultRegistry;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
class is {
|
|
1055
|
+
/**
|
|
1056
|
+
* Creates a new PayoutManager instance.
|
|
1057
|
+
*
|
|
1058
|
+
* @param config - Manager configuration including wallet
|
|
1059
|
+
*/
|
|
1060
|
+
constructor(t) {
|
|
1061
|
+
f(this, "config");
|
|
1062
|
+
this.config = t;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Signs a Payout transaction and extracts the Schnorr signature.
|
|
1066
|
+
*
|
|
1067
|
+
* Flow:
|
|
1068
|
+
* 1. Vault provider submits Claim transaction
|
|
1069
|
+
* 2. Claimer submits Assert transaction to prove validity
|
|
1070
|
+
* 3. Payout can be executed (references Assert tx)
|
|
1071
|
+
*
|
|
1072
|
+
* This method orchestrates the following steps:
|
|
1073
|
+
* 1. Get wallet's public key and convert to x-only format
|
|
1074
|
+
* 2. Validate wallet pubkey matches on-chain depositor pubkey (if provided)
|
|
1075
|
+
* 3. Build unsigned PSBT using primitives
|
|
1076
|
+
* 4. Sign PSBT via btcWallet.signPsbt()
|
|
1077
|
+
* 5. Extract 64-byte Schnorr signature using primitives
|
|
1078
|
+
*
|
|
1079
|
+
* The returned signature can be submitted to the vault provider API.
|
|
1080
|
+
*
|
|
1081
|
+
* @param params - Payout signing parameters
|
|
1082
|
+
* @returns Signature result with 64-byte Schnorr signature and depositor pubkey
|
|
1083
|
+
* @throws Error if wallet pubkey doesn't match depositor pubkey
|
|
1084
|
+
* @throws Error if wallet operations fail or signature extraction fails
|
|
1085
|
+
*/
|
|
1086
|
+
async signPayoutTransaction(t) {
|
|
1087
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = Tt(
|
|
1088
|
+
n,
|
|
1089
|
+
t.depositorBtcPubkey
|
|
1090
|
+
), r = await vt({
|
|
1091
|
+
payoutTxHex: t.payoutTxHex,
|
|
1092
|
+
peginTxHex: t.peginTxHex,
|
|
1093
|
+
assertTxHex: t.assertTxHex,
|
|
1094
|
+
depositorBtcPubkey: s,
|
|
1095
|
+
vaultProviderBtcPubkey: t.vaultProviderBtcPubkey,
|
|
1096
|
+
vaultKeeperBtcPubkeys: t.vaultKeeperBtcPubkeys,
|
|
1097
|
+
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
1098
|
+
timelockPegin: t.timelockPegin,
|
|
1099
|
+
network: this.config.network
|
|
1100
|
+
}), o = await this.config.btcWallet.signPsbt(
|
|
1101
|
+
r.psbtHex,
|
|
1102
|
+
pt(n, 1)
|
|
1103
|
+
);
|
|
1104
|
+
return {
|
|
1105
|
+
signature: Ht(o, s),
|
|
1106
|
+
depositorBtcPubkey: s
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Gets the configured Bitcoin network.
|
|
1111
|
+
*
|
|
1112
|
+
* @returns The Bitcoin network (mainnet, testnet, signet, regtest)
|
|
1113
|
+
*/
|
|
1114
|
+
getNetwork() {
|
|
1115
|
+
return this.config.network;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Checks if the wallet supports batch signing (signPsbts).
|
|
1119
|
+
*
|
|
1120
|
+
* @returns true if batch signing is supported
|
|
1121
|
+
*/
|
|
1122
|
+
supportsBatchSigning() {
|
|
1123
|
+
return typeof this.config.btcWallet.signPsbts == "function";
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Batch signs multiple payout transactions (1 per claimer).
|
|
1127
|
+
* This allows signing all transactions with a single wallet interaction.
|
|
1128
|
+
*
|
|
1129
|
+
* @param transactions - Array of payout params to sign
|
|
1130
|
+
* @returns Array of signature results matching input order
|
|
1131
|
+
* @throws Error if wallet doesn't support batch signing
|
|
1132
|
+
* @throws Error if any signing operation fails
|
|
1133
|
+
*/
|
|
1134
|
+
async signPayoutTransactionsBatch(t) {
|
|
1135
|
+
if (!this.supportsBatchSigning())
|
|
1136
|
+
throw new Error(
|
|
1137
|
+
"Wallet does not support batch signing (signPsbts method not available)"
|
|
1138
|
+
);
|
|
1139
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = [], r = [], o = [];
|
|
1140
|
+
for (const c of t) {
|
|
1141
|
+
const { depositorPubkey: l } = Tt(
|
|
1142
|
+
n,
|
|
1143
|
+
c.depositorBtcPubkey
|
|
1144
|
+
);
|
|
1145
|
+
o.push(l);
|
|
1146
|
+
const h = await vt({
|
|
1147
|
+
payoutTxHex: c.payoutTxHex,
|
|
1148
|
+
peginTxHex: c.peginTxHex,
|
|
1149
|
+
assertTxHex: c.assertTxHex,
|
|
1150
|
+
depositorBtcPubkey: l,
|
|
1151
|
+
vaultProviderBtcPubkey: c.vaultProviderBtcPubkey,
|
|
1152
|
+
vaultKeeperBtcPubkeys: c.vaultKeeperBtcPubkeys,
|
|
1153
|
+
universalChallengerBtcPubkeys: c.universalChallengerBtcPubkeys,
|
|
1154
|
+
timelockPegin: c.timelockPegin,
|
|
1155
|
+
network: this.config.network
|
|
1156
|
+
});
|
|
1157
|
+
s.push(h.psbtHex), r.push(pt(n, 1));
|
|
1158
|
+
}
|
|
1159
|
+
const i = await this.config.btcWallet.signPsbts(
|
|
1160
|
+
s,
|
|
1161
|
+
r
|
|
1162
|
+
);
|
|
1163
|
+
if (i.length !== t.length)
|
|
1164
|
+
throw new Error(
|
|
1165
|
+
`Expected ${t.length} signed PSBTs but received ${i.length}`
|
|
1166
|
+
);
|
|
1167
|
+
const a = [];
|
|
1168
|
+
for (let c = 0; c < t.length; c++) {
|
|
1169
|
+
const l = o[c], h = Ht(
|
|
1170
|
+
i[c],
|
|
1171
|
+
l
|
|
1172
|
+
);
|
|
1173
|
+
a.push({
|
|
1174
|
+
payoutSignature: h,
|
|
1175
|
+
depositorBtcPubkey: l
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
return a;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
function _e(e) {
|
|
1182
|
+
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1183
|
+
}
|
|
1184
|
+
function C(e, t = "") {
|
|
1185
|
+
if (!Number.isSafeInteger(e) || e < 0) {
|
|
1186
|
+
const n = t && `"${t}" `;
|
|
1187
|
+
throw new Error(`${n}expected integer >= 0, got ${e}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
function _(e, t, n = "") {
|
|
1191
|
+
const s = _e(e), r = e == null ? void 0 : e.length, o = t !== void 0;
|
|
1192
|
+
if (!s || o && r !== t) {
|
|
1193
|
+
const i = n && `"${n}" `, a = o ? ` of length ${t}` : "", c = s ? `length=${r}` : `type=${typeof e}`;
|
|
1194
|
+
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
1195
|
+
}
|
|
1196
|
+
return e;
|
|
1197
|
+
}
|
|
1198
|
+
function Xt(e) {
|
|
1199
|
+
if (typeof e != "function" || typeof e.create != "function")
|
|
1200
|
+
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1201
|
+
C(e.outputLen), C(e.blockLen);
|
|
1202
|
+
}
|
|
1203
|
+
function K(e, t = !0) {
|
|
1204
|
+
if (e.destroyed)
|
|
1205
|
+
throw new Error("Hash instance has been destroyed");
|
|
1206
|
+
if (t && e.finished)
|
|
1207
|
+
throw new Error("Hash#digest() has already been called");
|
|
1208
|
+
}
|
|
1209
|
+
function Gt(e, t) {
|
|
1210
|
+
_(e, void 0, "digestInto() output");
|
|
1211
|
+
const n = t.outputLen;
|
|
1212
|
+
if (e.length < n)
|
|
1213
|
+
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1214
|
+
}
|
|
1215
|
+
function Re(e) {
|
|
1216
|
+
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1217
|
+
}
|
|
1218
|
+
function A(...e) {
|
|
1219
|
+
for (let t = 0; t < e.length; t++)
|
|
1220
|
+
e[t].fill(0);
|
|
1221
|
+
}
|
|
1222
|
+
function et(e) {
|
|
1223
|
+
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
1224
|
+
}
|
|
1225
|
+
function B(e, t) {
|
|
1226
|
+
return e << 32 - t | e >>> t;
|
|
1227
|
+
}
|
|
1228
|
+
function j(e, t) {
|
|
1229
|
+
return e << t | e >>> 32 - t >>> 0;
|
|
1230
|
+
}
|
|
1231
|
+
const Ve = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1232
|
+
function We(e) {
|
|
1233
|
+
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1234
|
+
}
|
|
1235
|
+
function De(e) {
|
|
1236
|
+
for (let t = 0; t < e.length; t++)
|
|
1237
|
+
e[t] = We(e[t]);
|
|
1238
|
+
return e;
|
|
1239
|
+
}
|
|
1240
|
+
const Bt = Ve ? (e) => e : De;
|
|
1241
|
+
function Ke(e) {
|
|
1242
|
+
if (typeof e != "string")
|
|
1243
|
+
throw new Error("string expected");
|
|
1244
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
1245
|
+
}
|
|
1246
|
+
function Ut(e, t = "") {
|
|
1247
|
+
return typeof e == "string" ? Ke(e) : _(e, void 0, t);
|
|
1248
|
+
}
|
|
1249
|
+
function Me(e, t) {
|
|
1250
|
+
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1251
|
+
throw new Error("options must be object or undefined");
|
|
1252
|
+
return Object.assign(e, t);
|
|
1253
|
+
}
|
|
1254
|
+
function rt(e, t = {}) {
|
|
1255
|
+
const n = (r, o) => e(o).update(r).digest(), s = e(void 0);
|
|
1256
|
+
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (r) => e(r), Object.assign(n, t), Object.freeze(n);
|
|
1257
|
+
}
|
|
1258
|
+
const jt = (e) => ({
|
|
1259
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
1260
|
+
});
|
|
1261
|
+
class zt {
|
|
1262
|
+
constructor(t, n) {
|
|
1263
|
+
f(this, "oHash");
|
|
1264
|
+
f(this, "iHash");
|
|
1265
|
+
f(this, "blockLen");
|
|
1266
|
+
f(this, "outputLen");
|
|
1267
|
+
f(this, "finished", !1);
|
|
1268
|
+
f(this, "destroyed", !1);
|
|
1269
|
+
if (Xt(t), _(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1270
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1271
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1272
|
+
const s = this.blockLen, r = new Uint8Array(s);
|
|
1273
|
+
r.set(n.length > s ? t.create().update(n).digest() : n);
|
|
1274
|
+
for (let o = 0; o < r.length; o++)
|
|
1275
|
+
r[o] ^= 54;
|
|
1276
|
+
this.iHash.update(r), this.oHash = t.create();
|
|
1277
|
+
for (let o = 0; o < r.length; o++)
|
|
1278
|
+
r[o] ^= 106;
|
|
1279
|
+
this.oHash.update(r), A(r);
|
|
1280
|
+
}
|
|
1281
|
+
update(t) {
|
|
1282
|
+
return K(this), this.iHash.update(t), this;
|
|
1283
|
+
}
|
|
1284
|
+
digestInto(t) {
|
|
1285
|
+
K(this), _(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1286
|
+
}
|
|
1287
|
+
digest() {
|
|
1288
|
+
const t = new Uint8Array(this.oHash.outputLen);
|
|
1289
|
+
return this.digestInto(t), t;
|
|
1290
|
+
}
|
|
1291
|
+
_cloneInto(t) {
|
|
1292
|
+
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
1293
|
+
const { oHash: n, iHash: s, finished: r, destroyed: o, blockLen: i, outputLen: a } = this;
|
|
1294
|
+
return t = t, t.finished = r, t.destroyed = o, t.blockLen = i, t.outputLen = a, t.oHash = n._cloneInto(t.oHash), t.iHash = s._cloneInto(t.iHash), t;
|
|
1295
|
+
}
|
|
1296
|
+
clone() {
|
|
1297
|
+
return this._cloneInto();
|
|
1298
|
+
}
|
|
1299
|
+
destroy() {
|
|
1300
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
const yt = (e, t, n) => new zt(e, t).update(n).digest();
|
|
1304
|
+
yt.create = (e, t) => new zt(e, t);
|
|
1305
|
+
function Ne(e, t, n) {
|
|
1306
|
+
return e & t ^ ~e & n;
|
|
1307
|
+
}
|
|
1308
|
+
function Xe(e, t, n) {
|
|
1309
|
+
return e & t ^ e & n ^ t & n;
|
|
1310
|
+
}
|
|
1311
|
+
class gt {
|
|
1312
|
+
constructor(t, n, s, r) {
|
|
1313
|
+
f(this, "blockLen");
|
|
1314
|
+
f(this, "outputLen");
|
|
1315
|
+
f(this, "padOffset");
|
|
1316
|
+
f(this, "isLE");
|
|
1317
|
+
// For partial updates less than block size
|
|
1318
|
+
f(this, "buffer");
|
|
1319
|
+
f(this, "view");
|
|
1320
|
+
f(this, "finished", !1);
|
|
1321
|
+
f(this, "length", 0);
|
|
1322
|
+
f(this, "pos", 0);
|
|
1323
|
+
f(this, "destroyed", !1);
|
|
1324
|
+
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = et(this.buffer);
|
|
1325
|
+
}
|
|
1326
|
+
update(t) {
|
|
1327
|
+
K(this), _(t);
|
|
1328
|
+
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
1329
|
+
for (let i = 0; i < o; ) {
|
|
1330
|
+
const a = Math.min(r - this.pos, o - i);
|
|
1331
|
+
if (a === r) {
|
|
1332
|
+
const c = et(t);
|
|
1333
|
+
for (; r <= o - i; i += r)
|
|
1334
|
+
this.process(c, i);
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
s.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos === r && (this.process(n, 0), this.pos = 0);
|
|
1338
|
+
}
|
|
1339
|
+
return this.length += t.length, this.roundClean(), this;
|
|
1340
|
+
}
|
|
1341
|
+
digestInto(t) {
|
|
1342
|
+
K(this), Gt(t, this), this.finished = !0;
|
|
1343
|
+
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
1344
|
+
let { pos: i } = this;
|
|
1345
|
+
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
1346
|
+
for (let u = i; u < r; u++)
|
|
1347
|
+
n[u] = 0;
|
|
1348
|
+
s.setBigUint64(r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
1349
|
+
const a = et(t), c = this.outputLen;
|
|
1350
|
+
if (c % 4)
|
|
1351
|
+
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
1352
|
+
const l = c / 4, h = this.get();
|
|
1353
|
+
if (l > h.length)
|
|
1354
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
1355
|
+
for (let u = 0; u < l; u++)
|
|
1356
|
+
a.setUint32(4 * u, h[u], o);
|
|
1357
|
+
}
|
|
1358
|
+
digest() {
|
|
1359
|
+
const { buffer: t, outputLen: n } = this;
|
|
1360
|
+
this.digestInto(t);
|
|
1361
|
+
const s = t.slice(0, n);
|
|
1362
|
+
return this.destroy(), s;
|
|
1363
|
+
}
|
|
1364
|
+
_cloneInto(t) {
|
|
1365
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
1366
|
+
const { blockLen: n, buffer: s, length: r, finished: o, destroyed: i, pos: a } = this;
|
|
1367
|
+
return t.destroyed = i, t.finished = o, t.length = r, t.pos = a, r % n && t.buffer.set(s), t;
|
|
1368
|
+
}
|
|
1369
|
+
clone() {
|
|
1370
|
+
return this._cloneInto();
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
const L = /* @__PURE__ */ Uint32Array.from([
|
|
1374
|
+
1779033703,
|
|
1375
|
+
3144134277,
|
|
1376
|
+
1013904242,
|
|
1377
|
+
2773480762,
|
|
1378
|
+
1359893119,
|
|
1379
|
+
2600822924,
|
|
1380
|
+
528734635,
|
|
1381
|
+
1541459225
|
|
1382
|
+
]), H = /* @__PURE__ */ Uint32Array.from([
|
|
1383
|
+
1779033703,
|
|
1384
|
+
4089235720,
|
|
1385
|
+
3144134277,
|
|
1386
|
+
2227873595,
|
|
1387
|
+
1013904242,
|
|
1388
|
+
4271175723,
|
|
1389
|
+
2773480762,
|
|
1390
|
+
1595750129,
|
|
1391
|
+
1359893119,
|
|
1392
|
+
2917565137,
|
|
1393
|
+
2600822924,
|
|
1394
|
+
725511199,
|
|
1395
|
+
528734635,
|
|
1396
|
+
4215389547,
|
|
1397
|
+
1541459225,
|
|
1398
|
+
327033209
|
|
1399
|
+
]), Ge = /* @__PURE__ */ Uint8Array.from([
|
|
1400
|
+
7,
|
|
1401
|
+
4,
|
|
1402
|
+
13,
|
|
1403
|
+
1,
|
|
1404
|
+
10,
|
|
1405
|
+
6,
|
|
1406
|
+
15,
|
|
1407
|
+
3,
|
|
1408
|
+
12,
|
|
1409
|
+
0,
|
|
1410
|
+
9,
|
|
1411
|
+
5,
|
|
1412
|
+
2,
|
|
1413
|
+
14,
|
|
1414
|
+
11,
|
|
1415
|
+
8
|
|
1416
|
+
]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), je = qt.map((e) => (9 * e + 5) % 16), Zt = /* @__PURE__ */ (() => {
|
|
1417
|
+
const n = [[qt], [je]];
|
|
1418
|
+
for (let s = 0; s < 4; s++)
|
|
1419
|
+
for (let r of n)
|
|
1420
|
+
r.push(r[s].map((o) => Ge[o]));
|
|
1421
|
+
return n;
|
|
1422
|
+
})(), Jt = Zt[0], Yt = Zt[1], Qt = /* @__PURE__ */ [
|
|
1423
|
+
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
1424
|
+
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
1425
|
+
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1426
|
+
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1427
|
+
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1428
|
+
].map((e) => Uint8Array.from(e)), ze = /* @__PURE__ */ Jt.map((e, t) => e.map((n) => Qt[t][n])), qe = /* @__PURE__ */ Yt.map((e, t) => e.map((n) => Qt[t][n])), Ze = /* @__PURE__ */ Uint32Array.from([
|
|
1429
|
+
0,
|
|
1430
|
+
1518500249,
|
|
1431
|
+
1859775393,
|
|
1432
|
+
2400959708,
|
|
1433
|
+
2840853838
|
|
1434
|
+
]), Je = /* @__PURE__ */ Uint32Array.from([
|
|
1435
|
+
1352829926,
|
|
1436
|
+
1548603684,
|
|
1437
|
+
1836072691,
|
|
1438
|
+
2053994217,
|
|
1439
|
+
0
|
|
1440
|
+
]);
|
|
1441
|
+
function Lt(e, t, n, s) {
|
|
1442
|
+
return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
|
|
1443
|
+
}
|
|
1444
|
+
const z = /* @__PURE__ */ new Uint32Array(16);
|
|
1445
|
+
class Ye extends gt {
|
|
1446
|
+
constructor() {
|
|
1447
|
+
super(64, 20, 8, !0);
|
|
1448
|
+
f(this, "h0", 1732584193);
|
|
1449
|
+
f(this, "h1", -271733879);
|
|
1450
|
+
f(this, "h2", -1732584194);
|
|
1451
|
+
f(this, "h3", 271733878);
|
|
1452
|
+
f(this, "h4", -1009589776);
|
|
1453
|
+
}
|
|
1454
|
+
get() {
|
|
1455
|
+
const { h0: n, h1: s, h2: r, h3: o, h4: i } = this;
|
|
1456
|
+
return [n, s, r, o, i];
|
|
1457
|
+
}
|
|
1458
|
+
set(n, s, r, o, i) {
|
|
1459
|
+
this.h0 = n | 0, this.h1 = s | 0, this.h2 = r | 0, this.h3 = o | 0, this.h4 = i | 0;
|
|
1460
|
+
}
|
|
1461
|
+
process(n, s) {
|
|
1462
|
+
for (let b = 0; b < 16; b++, s += 4)
|
|
1463
|
+
z[b] = n.getUint32(s, !0);
|
|
1464
|
+
let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, l = c, h = this.h3 | 0, u = h, d = this.h4 | 0, p = d;
|
|
1465
|
+
for (let b = 0; b < 5; b++) {
|
|
1466
|
+
const m = 4 - b, x = Ze[b], g = Je[b], w = Jt[b], y = Yt[b], P = ze[b], v = qe[b];
|
|
1467
|
+
for (let T = 0; T < 16; T++) {
|
|
1468
|
+
const k = j(r + Lt(b, i, c, h) + z[w[T]] + x, P[T]) + d | 0;
|
|
1469
|
+
r = d, d = h, h = j(c, 10) | 0, c = i, i = k;
|
|
1470
|
+
}
|
|
1471
|
+
for (let T = 0; T < 16; T++) {
|
|
1472
|
+
const k = j(o + Lt(m, a, l, u) + z[y[T]] + g, v[T]) + p | 0;
|
|
1473
|
+
o = p, p = u, u = j(l, 10) | 0, l = a, a = k;
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
this.set(this.h1 + c + u | 0, this.h2 + h + p | 0, this.h3 + d + o | 0, this.h4 + r + a | 0, this.h0 + i + l | 0);
|
|
1477
|
+
}
|
|
1478
|
+
roundClean() {
|
|
1479
|
+
A(z);
|
|
1480
|
+
}
|
|
1481
|
+
destroy() {
|
|
1482
|
+
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
const Qe = /* @__PURE__ */ rt(() => new Ye()), q = /* @__PURE__ */ BigInt(2 ** 32 - 1), $t = /* @__PURE__ */ BigInt(32);
|
|
1486
|
+
function tn(e, t = !1) {
|
|
1487
|
+
return t ? { h: Number(e & q), l: Number(e >> $t & q) } : { h: Number(e >> $t & q) | 0, l: Number(e & q) | 0 };
|
|
1488
|
+
}
|
|
1489
|
+
function te(e, t = !1) {
|
|
1490
|
+
const n = e.length;
|
|
1491
|
+
let s = new Uint32Array(n), r = new Uint32Array(n);
|
|
1492
|
+
for (let o = 0; o < n; o++) {
|
|
1493
|
+
const { h: i, l: a } = tn(e[o], t);
|
|
1494
|
+
[s[o], r[o]] = [i, a];
|
|
1495
|
+
}
|
|
1496
|
+
return [s, r];
|
|
1497
|
+
}
|
|
1498
|
+
const Ft = (e, t, n) => e >>> n, Ot = (e, t, n) => e << 32 - n | t >>> n, R = (e, t, n) => e >>> n | t << 32 - n, V = (e, t, n) => e << 32 - n | t >>> n, Z = (e, t, n) => e << 64 - n | t >>> n - 32, J = (e, t, n) => e >>> n - 32 | t << 64 - n, en = (e, t, n) => e << n | t >>> 32 - n, nn = (e, t, n) => t << n | e >>> 32 - n, sn = (e, t, n) => t << n - 32 | e >>> 64 - n, rn = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1499
|
+
function U(e, t, n, s) {
|
|
1500
|
+
const r = (t >>> 0) + (s >>> 0);
|
|
1501
|
+
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
1502
|
+
}
|
|
1503
|
+
const on = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), an = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, cn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), un = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, ln = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), hn = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, fn = /* @__PURE__ */ Uint32Array.from([
|
|
1504
|
+
1116352408,
|
|
1505
|
+
1899447441,
|
|
1506
|
+
3049323471,
|
|
1507
|
+
3921009573,
|
|
1508
|
+
961987163,
|
|
1509
|
+
1508970993,
|
|
1510
|
+
2453635748,
|
|
1511
|
+
2870763221,
|
|
1512
|
+
3624381080,
|
|
1513
|
+
310598401,
|
|
1514
|
+
607225278,
|
|
1515
|
+
1426881987,
|
|
1516
|
+
1925078388,
|
|
1517
|
+
2162078206,
|
|
1518
|
+
2614888103,
|
|
1519
|
+
3248222580,
|
|
1520
|
+
3835390401,
|
|
1521
|
+
4022224774,
|
|
1522
|
+
264347078,
|
|
1523
|
+
604807628,
|
|
1524
|
+
770255983,
|
|
1525
|
+
1249150122,
|
|
1526
|
+
1555081692,
|
|
1527
|
+
1996064986,
|
|
1528
|
+
2554220882,
|
|
1529
|
+
2821834349,
|
|
1530
|
+
2952996808,
|
|
1531
|
+
3210313671,
|
|
1532
|
+
3336571891,
|
|
1533
|
+
3584528711,
|
|
1534
|
+
113926993,
|
|
1535
|
+
338241895,
|
|
1536
|
+
666307205,
|
|
1537
|
+
773529912,
|
|
1538
|
+
1294757372,
|
|
1539
|
+
1396182291,
|
|
1540
|
+
1695183700,
|
|
1541
|
+
1986661051,
|
|
1542
|
+
2177026350,
|
|
1543
|
+
2456956037,
|
|
1544
|
+
2730485921,
|
|
1545
|
+
2820302411,
|
|
1546
|
+
3259730800,
|
|
1547
|
+
3345764771,
|
|
1548
|
+
3516065817,
|
|
1549
|
+
3600352804,
|
|
1550
|
+
4094571909,
|
|
1551
|
+
275423344,
|
|
1552
|
+
430227734,
|
|
1553
|
+
506948616,
|
|
1554
|
+
659060556,
|
|
1555
|
+
883997877,
|
|
1556
|
+
958139571,
|
|
1557
|
+
1322822218,
|
|
1558
|
+
1537002063,
|
|
1559
|
+
1747873779,
|
|
1560
|
+
1955562222,
|
|
1561
|
+
2024104815,
|
|
1562
|
+
2227730452,
|
|
1563
|
+
2361852424,
|
|
1564
|
+
2428436474,
|
|
1565
|
+
2756734187,
|
|
1566
|
+
3204031479,
|
|
1567
|
+
3329325298
|
|
1568
|
+
]), $ = /* @__PURE__ */ new Uint32Array(64);
|
|
1569
|
+
class dn extends gt {
|
|
1570
|
+
constructor(t) {
|
|
1571
|
+
super(64, t, 8, !1);
|
|
1572
|
+
}
|
|
1573
|
+
get() {
|
|
1574
|
+
const { A: t, B: n, C: s, D: r, E: o, F: i, G: a, H: c } = this;
|
|
1575
|
+
return [t, n, s, r, o, i, a, c];
|
|
1576
|
+
}
|
|
1577
|
+
// prettier-ignore
|
|
1578
|
+
set(t, n, s, r, o, i, a, c) {
|
|
1579
|
+
this.A = t | 0, this.B = n | 0, this.C = s | 0, this.D = r | 0, this.E = o | 0, this.F = i | 0, this.G = a | 0, this.H = c | 0;
|
|
1580
|
+
}
|
|
1581
|
+
process(t, n) {
|
|
1582
|
+
for (let u = 0; u < 16; u++, n += 4)
|
|
1583
|
+
$[u] = t.getUint32(n, !1);
|
|
1584
|
+
for (let u = 16; u < 64; u++) {
|
|
1585
|
+
const d = $[u - 15], p = $[u - 2], b = B(d, 7) ^ B(d, 18) ^ d >>> 3, m = B(p, 17) ^ B(p, 19) ^ p >>> 10;
|
|
1586
|
+
$[u] = m + $[u - 7] + b + $[u - 16] | 0;
|
|
1587
|
+
}
|
|
1588
|
+
let { A: s, B: r, C: o, D: i, E: a, F: c, G: l, H: h } = this;
|
|
1589
|
+
for (let u = 0; u < 64; u++) {
|
|
1590
|
+
const d = B(a, 6) ^ B(a, 11) ^ B(a, 25), p = h + d + Ne(a, c, l) + fn[u] + $[u] | 0, m = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + Xe(s, r, o) | 0;
|
|
1591
|
+
h = l, l = c, c = a, a = i + p | 0, i = o, o = r, r = s, s = p + m | 0;
|
|
1592
|
+
}
|
|
1593
|
+
s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, a, c, l, h);
|
|
1594
|
+
}
|
|
1595
|
+
roundClean() {
|
|
1596
|
+
A($);
|
|
1597
|
+
}
|
|
1598
|
+
destroy() {
|
|
1599
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
class pn extends dn {
|
|
1603
|
+
constructor() {
|
|
1604
|
+
super(32);
|
|
1605
|
+
// We cannot use array here since array allows indexing by variable
|
|
1606
|
+
// which means optimizer/compiler cannot use registers.
|
|
1607
|
+
f(this, "A", L[0] | 0);
|
|
1608
|
+
f(this, "B", L[1] | 0);
|
|
1609
|
+
f(this, "C", L[2] | 0);
|
|
1610
|
+
f(this, "D", L[3] | 0);
|
|
1611
|
+
f(this, "E", L[4] | 0);
|
|
1612
|
+
f(this, "F", L[5] | 0);
|
|
1613
|
+
f(this, "G", L[6] | 0);
|
|
1614
|
+
f(this, "H", L[7] | 0);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
const ee = te([
|
|
1618
|
+
"0x428a2f98d728ae22",
|
|
1619
|
+
"0x7137449123ef65cd",
|
|
1620
|
+
"0xb5c0fbcfec4d3b2f",
|
|
1621
|
+
"0xe9b5dba58189dbbc",
|
|
1622
|
+
"0x3956c25bf348b538",
|
|
1623
|
+
"0x59f111f1b605d019",
|
|
1624
|
+
"0x923f82a4af194f9b",
|
|
1625
|
+
"0xab1c5ed5da6d8118",
|
|
1626
|
+
"0xd807aa98a3030242",
|
|
1627
|
+
"0x12835b0145706fbe",
|
|
1628
|
+
"0x243185be4ee4b28c",
|
|
1629
|
+
"0x550c7dc3d5ffb4e2",
|
|
1630
|
+
"0x72be5d74f27b896f",
|
|
1631
|
+
"0x80deb1fe3b1696b1",
|
|
1632
|
+
"0x9bdc06a725c71235",
|
|
1633
|
+
"0xc19bf174cf692694",
|
|
1634
|
+
"0xe49b69c19ef14ad2",
|
|
1635
|
+
"0xefbe4786384f25e3",
|
|
1636
|
+
"0x0fc19dc68b8cd5b5",
|
|
1637
|
+
"0x240ca1cc77ac9c65",
|
|
1638
|
+
"0x2de92c6f592b0275",
|
|
1639
|
+
"0x4a7484aa6ea6e483",
|
|
1640
|
+
"0x5cb0a9dcbd41fbd4",
|
|
1641
|
+
"0x76f988da831153b5",
|
|
1642
|
+
"0x983e5152ee66dfab",
|
|
1643
|
+
"0xa831c66d2db43210",
|
|
1644
|
+
"0xb00327c898fb213f",
|
|
1645
|
+
"0xbf597fc7beef0ee4",
|
|
1646
|
+
"0xc6e00bf33da88fc2",
|
|
1647
|
+
"0xd5a79147930aa725",
|
|
1648
|
+
"0x06ca6351e003826f",
|
|
1649
|
+
"0x142929670a0e6e70",
|
|
1650
|
+
"0x27b70a8546d22ffc",
|
|
1651
|
+
"0x2e1b21385c26c926",
|
|
1652
|
+
"0x4d2c6dfc5ac42aed",
|
|
1653
|
+
"0x53380d139d95b3df",
|
|
1654
|
+
"0x650a73548baf63de",
|
|
1655
|
+
"0x766a0abb3c77b2a8",
|
|
1656
|
+
"0x81c2c92e47edaee6",
|
|
1657
|
+
"0x92722c851482353b",
|
|
1658
|
+
"0xa2bfe8a14cf10364",
|
|
1659
|
+
"0xa81a664bbc423001",
|
|
1660
|
+
"0xc24b8b70d0f89791",
|
|
1661
|
+
"0xc76c51a30654be30",
|
|
1662
|
+
"0xd192e819d6ef5218",
|
|
1663
|
+
"0xd69906245565a910",
|
|
1664
|
+
"0xf40e35855771202a",
|
|
1665
|
+
"0x106aa07032bbd1b8",
|
|
1666
|
+
"0x19a4c116b8d2d0c8",
|
|
1667
|
+
"0x1e376c085141ab53",
|
|
1668
|
+
"0x2748774cdf8eeb99",
|
|
1669
|
+
"0x34b0bcb5e19b48a8",
|
|
1670
|
+
"0x391c0cb3c5c95a63",
|
|
1671
|
+
"0x4ed8aa4ae3418acb",
|
|
1672
|
+
"0x5b9cca4f7763e373",
|
|
1673
|
+
"0x682e6ff3d6b2b8a3",
|
|
1674
|
+
"0x748f82ee5defb2fc",
|
|
1675
|
+
"0x78a5636f43172f60",
|
|
1676
|
+
"0x84c87814a1f0ab72",
|
|
1677
|
+
"0x8cc702081a6439ec",
|
|
1678
|
+
"0x90befffa23631e28",
|
|
1679
|
+
"0xa4506cebde82bde9",
|
|
1680
|
+
"0xbef9a3f7b2c67915",
|
|
1681
|
+
"0xc67178f2e372532b",
|
|
1682
|
+
"0xca273eceea26619c",
|
|
1683
|
+
"0xd186b8c721c0c207",
|
|
1684
|
+
"0xeada7dd6cde0eb1e",
|
|
1685
|
+
"0xf57d4f7fee6ed178",
|
|
1686
|
+
"0x06f067aa72176fba",
|
|
1687
|
+
"0x0a637dc5a2c898a6",
|
|
1688
|
+
"0x113f9804bef90dae",
|
|
1689
|
+
"0x1b710b35131c471b",
|
|
1690
|
+
"0x28db77f523047d84",
|
|
1691
|
+
"0x32caab7b40c72493",
|
|
1692
|
+
"0x3c9ebe0a15c9bebc",
|
|
1693
|
+
"0x431d67c49c100d4c",
|
|
1694
|
+
"0x4cc5d4becb3e42b6",
|
|
1695
|
+
"0x597f299cfc657e2a",
|
|
1696
|
+
"0x5fcb6fab3ad6faec",
|
|
1697
|
+
"0x6c44198c4a475817"
|
|
1698
|
+
].map((e) => BigInt(e))), bn = ee[0], xn = ee[1], F = /* @__PURE__ */ new Uint32Array(80), O = /* @__PURE__ */ new Uint32Array(80);
|
|
1699
|
+
class yn extends gt {
|
|
1700
|
+
constructor(t) {
|
|
1701
|
+
super(128, t, 16, !1);
|
|
1702
|
+
}
|
|
1703
|
+
// prettier-ignore
|
|
1704
|
+
get() {
|
|
1705
|
+
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: l, El: h, Fh: u, Fl: d, Gh: p, Gl: b, Hh: m, Hl: x } = this;
|
|
1706
|
+
return [t, n, s, r, o, i, a, c, l, h, u, d, p, b, m, x];
|
|
1707
|
+
}
|
|
1708
|
+
// prettier-ignore
|
|
1709
|
+
set(t, n, s, r, o, i, a, c, l, h, u, d, p, b, m, x) {
|
|
1710
|
+
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = u | 0, this.Fl = d | 0, this.Gh = p | 0, this.Gl = b | 0, this.Hh = m | 0, this.Hl = x | 0;
|
|
1711
|
+
}
|
|
1712
|
+
process(t, n) {
|
|
1713
|
+
for (let y = 0; y < 16; y++, n += 4)
|
|
1714
|
+
F[y] = t.getUint32(n), O[y] = t.getUint32(n += 4);
|
|
1715
|
+
for (let y = 16; y < 80; y++) {
|
|
1716
|
+
const P = F[y - 15] | 0, v = O[y - 15] | 0, T = R(P, v, 1) ^ R(P, v, 8) ^ Ft(P, v, 7), k = V(P, v, 1) ^ V(P, v, 8) ^ Ot(P, v, 7), I = F[y - 2] | 0, E = O[y - 2] | 0, X = R(I, E, 19) ^ Z(I, E, 61) ^ Ft(I, E, 6), ot = V(I, E, 19) ^ J(I, E, 61) ^ Ot(I, E, 6), G = cn(k, ot, O[y - 7], O[y - 16]), it = un(G, T, X, F[y - 7], F[y - 16]);
|
|
1717
|
+
F[y] = it | 0, O[y] = G | 0;
|
|
1718
|
+
}
|
|
1719
|
+
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh: p, Fl: b, Gh: m, Gl: x, Hh: g, Hl: w } = this;
|
|
1720
|
+
for (let y = 0; y < 80; y++) {
|
|
1721
|
+
const P = R(u, d, 14) ^ R(u, d, 18) ^ Z(u, d, 41), v = V(u, d, 14) ^ V(u, d, 18) ^ J(u, d, 41), T = u & p ^ ~u & m, k = d & b ^ ~d & x, I = ln(w, v, k, xn[y], O[y]), E = hn(I, g, P, T, bn[y], F[y]), X = I | 0, ot = R(s, r, 28) ^ Z(s, r, 34) ^ Z(s, r, 39), G = V(s, r, 28) ^ J(s, r, 34) ^ J(s, r, 39), it = s & o ^ s & a ^ o & a, ce = r & i ^ r & c ^ i & c;
|
|
1722
|
+
g = m | 0, w = x | 0, m = p | 0, x = b | 0, p = u | 0, b = d | 0, { h: u, l: d } = U(l | 0, h | 0, E | 0, X | 0), l = a | 0, h = c | 0, a = o | 0, c = i | 0, o = s | 0, i = r | 0;
|
|
1723
|
+
const wt = on(X, G, ce);
|
|
1724
|
+
s = an(wt, E, ot, it), r = wt | 0;
|
|
1725
|
+
}
|
|
1726
|
+
({ h: s, l: r } = U(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = U(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: c } = U(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = U(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: d } = U(this.Eh | 0, this.El | 0, u | 0, d | 0), { h: p, l: b } = U(this.Fh | 0, this.Fl | 0, p | 0, b | 0), { h: m, l: x } = U(this.Gh | 0, this.Gl | 0, m | 0, x | 0), { h: g, l: w } = U(this.Hh | 0, this.Hl | 0, g | 0, w | 0), this.set(s, r, o, i, a, c, l, h, u, d, p, b, m, x, g, w);
|
|
1727
|
+
}
|
|
1728
|
+
roundClean() {
|
|
1729
|
+
A(F, O);
|
|
1730
|
+
}
|
|
1731
|
+
destroy() {
|
|
1732
|
+
A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
class gn extends yn {
|
|
1736
|
+
constructor() {
|
|
1737
|
+
super(64);
|
|
1738
|
+
f(this, "Ah", H[0] | 0);
|
|
1739
|
+
f(this, "Al", H[1] | 0);
|
|
1740
|
+
f(this, "Bh", H[2] | 0);
|
|
1741
|
+
f(this, "Bl", H[3] | 0);
|
|
1742
|
+
f(this, "Ch", H[4] | 0);
|
|
1743
|
+
f(this, "Cl", H[5] | 0);
|
|
1744
|
+
f(this, "Dh", H[6] | 0);
|
|
1745
|
+
f(this, "Dl", H[7] | 0);
|
|
1746
|
+
f(this, "Eh", H[8] | 0);
|
|
1747
|
+
f(this, "El", H[9] | 0);
|
|
1748
|
+
f(this, "Fh", H[10] | 0);
|
|
1749
|
+
f(this, "Fl", H[11] | 0);
|
|
1750
|
+
f(this, "Gh", H[12] | 0);
|
|
1751
|
+
f(this, "Gl", H[13] | 0);
|
|
1752
|
+
f(this, "Hh", H[14] | 0);
|
|
1753
|
+
f(this, "Hl", H[15] | 0);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
const mn = /* @__PURE__ */ rt(
|
|
1757
|
+
() => new pn(),
|
|
1758
|
+
/* @__PURE__ */ jt(1)
|
|
1759
|
+
), ne = /* @__PURE__ */ rt(
|
|
1760
|
+
() => new gn(),
|
|
1761
|
+
/* @__PURE__ */ jt(3)
|
|
1762
|
+
), wn = BigInt(0), M = BigInt(1), Pn = BigInt(2), Tn = BigInt(7), vn = BigInt(256), Hn = BigInt(113), se = [], re = [], oe = [];
|
|
1763
|
+
for (let e = 0, t = M, n = 1, s = 0; e < 24; e++) {
|
|
1764
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], se.push(2 * (5 * s + n)), re.push((e + 1) * (e + 2) / 2 % 64);
|
|
1765
|
+
let r = wn;
|
|
1766
|
+
for (let o = 0; o < 7; o++)
|
|
1767
|
+
t = (t << M ^ (t >> Tn) * Hn) % vn, t & Pn && (r ^= M << (M << BigInt(o)) - M);
|
|
1768
|
+
oe.push(r);
|
|
1769
|
+
}
|
|
1770
|
+
const ie = te(oe, !0), kn = ie[0], In = ie[1], Ct = (e, t, n) => n > 32 ? sn(e, t, n) : en(e, t, n), _t = (e, t, n) => n > 32 ? rn(e, t, n) : nn(e, t, n);
|
|
1771
|
+
function En(e, t = 24) {
|
|
1772
|
+
const n = new Uint32Array(10);
|
|
1773
|
+
for (let s = 24 - t; s < 24; s++) {
|
|
1774
|
+
for (let i = 0; i < 10; i++)
|
|
1775
|
+
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1776
|
+
for (let i = 0; i < 10; i += 2) {
|
|
1777
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u = Ct(l, h, 1) ^ n[a], d = _t(l, h, 1) ^ n[a + 1];
|
|
1778
|
+
for (let p = 0; p < 50; p += 10)
|
|
1779
|
+
e[i + p] ^= u, e[i + p + 1] ^= d;
|
|
1780
|
+
}
|
|
1781
|
+
let r = e[2], o = e[3];
|
|
1782
|
+
for (let i = 0; i < 24; i++) {
|
|
1783
|
+
const a = re[i], c = Ct(r, o, a), l = _t(r, o, a), h = se[i];
|
|
1784
|
+
r = e[h], o = e[h + 1], e[h] = c, e[h + 1] = l;
|
|
1785
|
+
}
|
|
1786
|
+
for (let i = 0; i < 50; i += 10) {
|
|
1787
|
+
for (let a = 0; a < 10; a++)
|
|
1788
|
+
n[a] = e[i + a];
|
|
1789
|
+
for (let a = 0; a < 10; a++)
|
|
1790
|
+
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1791
|
+
}
|
|
1792
|
+
e[0] ^= kn[s], e[1] ^= In[s];
|
|
1793
|
+
}
|
|
1794
|
+
A(n);
|
|
1795
|
+
}
|
|
1796
|
+
class mt {
|
|
1797
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1798
|
+
constructor(t, n, s, r = !1, o = 24) {
|
|
1799
|
+
f(this, "state");
|
|
1800
|
+
f(this, "pos", 0);
|
|
1801
|
+
f(this, "posOut", 0);
|
|
1802
|
+
f(this, "finished", !1);
|
|
1803
|
+
f(this, "state32");
|
|
1804
|
+
f(this, "destroyed", !1);
|
|
1805
|
+
f(this, "blockLen");
|
|
1806
|
+
f(this, "suffix");
|
|
1807
|
+
f(this, "outputLen");
|
|
1808
|
+
f(this, "enableXOF", !1);
|
|
1809
|
+
f(this, "rounds");
|
|
1810
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, C(s, "outputLen"), !(0 < t && t < 200))
|
|
1811
|
+
throw new Error("only keccak-f1600 function is supported");
|
|
1812
|
+
this.state = new Uint8Array(200), this.state32 = Re(this.state);
|
|
1813
|
+
}
|
|
1814
|
+
clone() {
|
|
1815
|
+
return this._cloneInto();
|
|
1816
|
+
}
|
|
1817
|
+
keccak() {
|
|
1818
|
+
Bt(this.state32), En(this.state32, this.rounds), Bt(this.state32), this.posOut = 0, this.pos = 0;
|
|
1819
|
+
}
|
|
1820
|
+
update(t) {
|
|
1821
|
+
K(this), _(t);
|
|
1822
|
+
const { blockLen: n, state: s } = this, r = t.length;
|
|
1823
|
+
for (let o = 0; o < r; ) {
|
|
1824
|
+
const i = Math.min(n - this.pos, r - o);
|
|
1825
|
+
for (let a = 0; a < i; a++)
|
|
1826
|
+
s[this.pos++] ^= t[o++];
|
|
1827
|
+
this.pos === n && this.keccak();
|
|
1828
|
+
}
|
|
1829
|
+
return this;
|
|
1830
|
+
}
|
|
1831
|
+
finish() {
|
|
1832
|
+
if (this.finished)
|
|
1833
|
+
return;
|
|
1834
|
+
this.finished = !0;
|
|
1835
|
+
const { state: t, suffix: n, pos: s, blockLen: r } = this;
|
|
1836
|
+
t[s] ^= n, (n & 128) !== 0 && s === r - 1 && this.keccak(), t[r - 1] ^= 128, this.keccak();
|
|
1837
|
+
}
|
|
1838
|
+
writeInto(t) {
|
|
1839
|
+
K(this, !1), _(t), this.finish();
|
|
1840
|
+
const n = this.state, { blockLen: s } = this;
|
|
1841
|
+
for (let r = 0, o = t.length; r < o; ) {
|
|
1842
|
+
this.posOut >= s && this.keccak();
|
|
1843
|
+
const i = Math.min(s - this.posOut, o - r);
|
|
1844
|
+
t.set(n.subarray(this.posOut, this.posOut + i), r), this.posOut += i, r += i;
|
|
1845
|
+
}
|
|
1846
|
+
return t;
|
|
1847
|
+
}
|
|
1848
|
+
xofInto(t) {
|
|
1849
|
+
if (!this.enableXOF)
|
|
1850
|
+
throw new Error("XOF is not possible for this instance");
|
|
1851
|
+
return this.writeInto(t);
|
|
1852
|
+
}
|
|
1853
|
+
xof(t) {
|
|
1854
|
+
return C(t), this.xofInto(new Uint8Array(t));
|
|
1855
|
+
}
|
|
1856
|
+
digestInto(t) {
|
|
1857
|
+
if (Gt(t, this), this.finished)
|
|
1858
|
+
throw new Error("digest() was already called");
|
|
1859
|
+
return this.writeInto(t), this.destroy(), t;
|
|
1860
|
+
}
|
|
1861
|
+
digest() {
|
|
1862
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
1863
|
+
}
|
|
1864
|
+
destroy() {
|
|
1865
|
+
this.destroyed = !0, A(this.state);
|
|
1866
|
+
}
|
|
1867
|
+
_cloneInto(t) {
|
|
1868
|
+
const { blockLen: n, suffix: s, outputLen: r, rounds: o, enableXOF: i } = this;
|
|
1869
|
+
return t || (t = new mt(n, s, r, i, o)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = o, t.suffix = s, t.outputLen = r, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
const Sn = (e, t, n, s = {}) => rt(() => new mt(t, e, n), s), An = /* @__PURE__ */ Sn(1, 136, 32);
|
|
1873
|
+
function Bn(e, t, n, s) {
|
|
1874
|
+
Xt(e);
|
|
1875
|
+
const r = Me({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
|
|
1876
|
+
if (C(o, "c"), C(i, "dkLen"), C(a, "asyncTick"), o < 1)
|
|
1877
|
+
throw new Error("iterations (c) must be >= 1");
|
|
1878
|
+
const c = Ut(t, "password"), l = Ut(n, "salt"), h = new Uint8Array(i), u = yt.create(e, c), d = u._cloneInto().update(l);
|
|
1879
|
+
return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
|
|
1880
|
+
}
|
|
1881
|
+
function Un(e, t, n, s, r) {
|
|
1882
|
+
return e.destroy(), t.destroy(), s && s.destroy(), A(r), n;
|
|
1883
|
+
}
|
|
1884
|
+
function Ln(e, t, n, s) {
|
|
1885
|
+
const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = Bn(e, t, n, s);
|
|
1886
|
+
let l;
|
|
1887
|
+
const h = new Uint8Array(4), u = et(h), d = new Uint8Array(a.outputLen);
|
|
1888
|
+
for (let p = 1, b = 0; b < o; p++, b += a.outputLen) {
|
|
1889
|
+
const m = i.subarray(b, b + a.outputLen);
|
|
1890
|
+
u.setInt32(0, p, !1), (l = c._cloneInto(l)).update(h).digestInto(d), m.set(d.subarray(0, m.length));
|
|
1891
|
+
for (let x = 1; x < r; x++) {
|
|
1892
|
+
a._cloneInto(l).update(d).digestInto(d);
|
|
1893
|
+
for (let g = 0; g < m.length; g++)
|
|
1894
|
+
m[g] ^= d[g];
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
return Un(a, c, i, l, d);
|
|
1898
|
+
}
|
|
1899
|
+
function ae(e) {
|
|
1900
|
+
if (typeof e != "string")
|
|
1901
|
+
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
1902
|
+
return e.normalize("NFKD");
|
|
1903
|
+
}
|
|
1904
|
+
function $n(e) {
|
|
1905
|
+
const t = ae(e), n = t.split(" ");
|
|
1906
|
+
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
1907
|
+
throw new Error("Invalid mnemonic");
|
|
1908
|
+
return { nfkd: t, words: n };
|
|
1909
|
+
}
|
|
1910
|
+
const Fn = (e) => ae("mnemonic" + e);
|
|
1911
|
+
function On(e, t = "") {
|
|
1912
|
+
return Ln(ne, $n(e).nfkd, Fn(t), { c: 2048, dkLen: 64 });
|
|
1913
|
+
}
|
|
1914
|
+
const Cn = 508, Rt = 16, Y = 32, Q = 64, Vt = 5, _n = 4;
|
|
1915
|
+
function N(...e) {
|
|
1916
|
+
const t = e.reduce((r, o) => r + o.length, 0), n = new Uint8Array(t);
|
|
1917
|
+
let s = 0;
|
|
1918
|
+
for (const r of e)
|
|
1919
|
+
n.set(r, s), s += r.length;
|
|
1920
|
+
return n;
|
|
1921
|
+
}
|
|
1922
|
+
function ut(e) {
|
|
1923
|
+
return new TextEncoder().encode(e);
|
|
1924
|
+
}
|
|
1925
|
+
function lt(e) {
|
|
1926
|
+
const t = new Uint8Array(_n);
|
|
1927
|
+
return new DataView(t.buffer).setUint32(0, e.length, !1), N(t, e);
|
|
1928
|
+
}
|
|
1929
|
+
function ht(e, t) {
|
|
1930
|
+
return yt(ne, e, t);
|
|
1931
|
+
}
|
|
1932
|
+
function Wt(e) {
|
|
1933
|
+
return Qe(mn(e));
|
|
1934
|
+
}
|
|
1935
|
+
const bt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
1936
|
+
function Rn(e) {
|
|
1937
|
+
const t = On(e);
|
|
1938
|
+
return new Uint8Array(t);
|
|
1939
|
+
}
|
|
1940
|
+
async function Vn(e, t, n, s) {
|
|
1941
|
+
if (e.length !== Q)
|
|
1942
|
+
throw new Error(
|
|
1943
|
+
`Lamport seed must be ${Q} bytes, got ${e.length}`
|
|
1944
|
+
);
|
|
1945
|
+
t = W(t), n = W(n);
|
|
1946
|
+
const r = e.slice(Y, Q), o = e.slice(0, Y), i = [r, o];
|
|
1947
|
+
try {
|
|
1948
|
+
const a = N(
|
|
1949
|
+
lt(ut(t)),
|
|
1950
|
+
lt(ut(n)),
|
|
1951
|
+
lt(ut(s))
|
|
1952
|
+
), c = N(o, a);
|
|
1953
|
+
i.push(c);
|
|
1954
|
+
const l = ht(r, c);
|
|
1955
|
+
i.push(l);
|
|
1956
|
+
const h = l.slice(0, Y), u = l.slice(Y, Q);
|
|
1957
|
+
i.push(h, u);
|
|
1958
|
+
const d = [], p = [], b = [], m = [];
|
|
1959
|
+
let x = !1;
|
|
1960
|
+
try {
|
|
1961
|
+
for (let g = 0; g < Cn; g++) {
|
|
1962
|
+
const w = new Uint8Array(Vt);
|
|
1963
|
+
w[0] = 0, new DataView(w.buffer).setUint32(1, g, !1);
|
|
1964
|
+
const y = new Uint8Array(Vt);
|
|
1965
|
+
y[0] = 1, new DataView(y.buffer).setUint32(1, g, !1);
|
|
1966
|
+
const P = N(h, w), v = N(h, y), T = ht(u, P), k = ht(u, v);
|
|
1967
|
+
try {
|
|
1968
|
+
const I = T.slice(0, Rt), E = k.slice(0, Rt);
|
|
1969
|
+
d.push(I), p.push(E), b.push(Wt(I)), m.push(Wt(E));
|
|
1970
|
+
} finally {
|
|
1971
|
+
P.fill(0), v.fill(0), T.fill(0), k.fill(0);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
return x = !0, { falsePreimages: d, truePreimages: p, falseHashes: b, trueHashes: m };
|
|
1975
|
+
} finally {
|
|
1976
|
+
if (!x) {
|
|
1977
|
+
for (const g of d) g.fill(0);
|
|
1978
|
+
for (const g of p) g.fill(0);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
} finally {
|
|
1982
|
+
for (const a of i)
|
|
1983
|
+
a.fill(0);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
function as(e) {
|
|
1987
|
+
return {
|
|
1988
|
+
false_list: e.falseHashes.map(bt),
|
|
1989
|
+
true_list: e.trueHashes.map(bt)
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
function Wn(e) {
|
|
1993
|
+
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
1994
|
+
throw new Error(
|
|
1995
|
+
"computeLamportPkHash: keypair hash arrays must not be empty"
|
|
1996
|
+
);
|
|
1997
|
+
const t = e.falseHashes[0].length, n = (e.falseHashes.length + e.trueHashes.length) * t, s = new Uint8Array(n);
|
|
1998
|
+
let r = 0;
|
|
1999
|
+
for (const i of e.falseHashes)
|
|
2000
|
+
s.set(i, r), r += t;
|
|
2001
|
+
for (const i of e.trueHashes)
|
|
2002
|
+
s.set(i, r), r += t;
|
|
2003
|
+
const o = An(s);
|
|
2004
|
+
return `0x${bt(o)}`;
|
|
2005
|
+
}
|
|
2006
|
+
async function cs(e, t, n, s) {
|
|
2007
|
+
const r = Rn(e);
|
|
2008
|
+
try {
|
|
2009
|
+
const o = await Vn(
|
|
2010
|
+
r,
|
|
2011
|
+
t,
|
|
2012
|
+
n,
|
|
2013
|
+
s
|
|
2014
|
+
);
|
|
2015
|
+
try {
|
|
2016
|
+
return Wn(o);
|
|
2017
|
+
} finally {
|
|
2018
|
+
for (const i of o.falsePreimages) i.fill(0);
|
|
2019
|
+
for (const i of o.truePreimages) i.fill(0);
|
|
2020
|
+
}
|
|
2021
|
+
} finally {
|
|
2022
|
+
r.fill(0);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
function us(e) {
|
|
2026
|
+
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2027
|
+
return t.includes("lamport") && t.includes("hash") && t.includes("does not match");
|
|
2028
|
+
}
|
|
2029
|
+
export {
|
|
2030
|
+
cs as A,
|
|
2031
|
+
tt as B,
|
|
2032
|
+
D as C,
|
|
2033
|
+
us as D,
|
|
2034
|
+
Le as M,
|
|
2035
|
+
os as P,
|
|
2036
|
+
zn as a,
|
|
2037
|
+
Zn as b,
|
|
2038
|
+
St as c,
|
|
2039
|
+
Jn as d,
|
|
2040
|
+
Se as e,
|
|
2041
|
+
Ae as f,
|
|
2042
|
+
qn as g,
|
|
2043
|
+
is as h,
|
|
2044
|
+
es as i,
|
|
2045
|
+
Qn as j,
|
|
2046
|
+
ts as k,
|
|
2047
|
+
ns as l,
|
|
2048
|
+
Yn as m,
|
|
2049
|
+
Fe as n,
|
|
2050
|
+
Oe as o,
|
|
2051
|
+
$e as p,
|
|
2052
|
+
ct as q,
|
|
2053
|
+
xt as r,
|
|
2054
|
+
Ee as s,
|
|
2055
|
+
ss as t,
|
|
2056
|
+
rs as u,
|
|
2057
|
+
At as v,
|
|
2058
|
+
Rn as w,
|
|
2059
|
+
Vn as x,
|
|
2060
|
+
as as y,
|
|
2061
|
+
Wn as z
|
|
2062
|
+
};
|
|
2063
|
+
//# sourceMappingURL=errors-D_DWT0CT.js.map
|