@babylonlabs-io/ts-sdk 0.16.0 → 0.16.2
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 +17 -3
- package/dist/challengeAssert-CTajvPAY.cjs +2 -0
- package/dist/challengeAssert-CTajvPAY.cjs.map +1 -0
- package/dist/{challengeAssert-C5DQSUnp.js → challengeAssert-DtrQLG0c.js} +164 -161
- package/dist/challengeAssert-DtrQLG0c.js.map +1 -0
- package/dist/{errors-BEUjAw2k.js → errors-BeFfs5_J.js} +370 -369
- package/dist/errors-BeFfs5_J.js.map +1 -0
- package/dist/errors-CAFiRPYI.cjs +2 -0
- package/dist/errors-CAFiRPYI.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +29 -74
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +2 -2
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +0 -11
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +2 -2
- package/package.json +3 -3
- package/dist/challengeAssert-C5DQSUnp.js.map +0 -1
- package/dist/challengeAssert-D7SqsNpQ.cjs +0 -2
- package/dist/challengeAssert-D7SqsNpQ.cjs.map +0 -1
- package/dist/errors-BEUjAw2k.js.map +0 -1
- package/dist/errors-DnMc1lLU.cjs +0 -2
- package/dist/errors-DnMc1lLU.cjs.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var p = (e, t, n) =>
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
1
|
+
var fe = Object.defineProperty;
|
|
2
|
+
var pe = (e, t, n) => t in e ? fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var p = (e, t, n) => pe(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as be from "bitcoinjs-lib";
|
|
5
|
+
import { script as ge, Transaction as xt, Psbt as kt } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as W } from "buffer";
|
|
7
|
-
import { createPublicClient as
|
|
8
|
-
import { P as
|
|
9
|
-
import { deriveVaultId as
|
|
10
|
-
function
|
|
7
|
+
import { createPublicClient as lt, http as ht, encodeFunctionData as Ht, zeroAddress as ye } from "viem";
|
|
8
|
+
import { P as xe, y as we, D as Xt, M as It, B as me, T as Pe, u as B, b as Te, A as ve, G as Et, E as ke, a as He, d as Ie, e as Ee, f as Be, s as U, q as Se, x as Bt, h as St, i as At, r as Ae } from "./challengeAssert-DtrQLG0c.js";
|
|
9
|
+
import { deriveVaultId as Ut } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
function Ue(e, t, n, s) {
|
|
11
11
|
if (!Number.isInteger(s) || s < 1)
|
|
12
12
|
throw new Error(
|
|
13
13
|
`Invalid numOutputs: expected a positive integer, got ${s}`
|
|
@@ -16,7 +16,7 @@ function Ae(e, t, n, s) {
|
|
|
16
16
|
throw new Error("Insufficient funds: no UTXOs available");
|
|
17
17
|
const o = e.filter((l) => {
|
|
18
18
|
const h = W.from(l.scriptPubKey, "hex");
|
|
19
|
-
return !!
|
|
19
|
+
return !!ge.decompile(h);
|
|
20
20
|
});
|
|
21
21
|
if (o.length === 0)
|
|
22
22
|
throw new Error(
|
|
@@ -26,20 +26,20 @@ function Ae(e, t, n, s) {
|
|
|
26
26
|
let a = 0n, c = 0n;
|
|
27
27
|
for (const l of r) {
|
|
28
28
|
i.push(l), a += BigInt(l.value);
|
|
29
|
-
const h = i.length *
|
|
30
|
-
if (c = BigInt(Math.ceil(d * n)) + BigInt(
|
|
31
|
-
const
|
|
32
|
-
Math.ceil(
|
|
29
|
+
const h = i.length * xe, u = s * It, d = h + u + Pe;
|
|
30
|
+
if (c = BigInt(Math.ceil(d * n)) + BigInt(we(n)), a - t - c > Xt) {
|
|
31
|
+
const b = BigInt(
|
|
32
|
+
Math.ceil(It * n)
|
|
33
33
|
);
|
|
34
|
-
c +=
|
|
34
|
+
c += b;
|
|
35
35
|
}
|
|
36
36
|
if (a >= t + c) {
|
|
37
|
-
const
|
|
37
|
+
const b = a - t - c;
|
|
38
38
|
return {
|
|
39
39
|
selectedUTXOs: i,
|
|
40
40
|
totalValue: a,
|
|
41
41
|
fee: c,
|
|
42
|
-
changeAmount:
|
|
42
|
+
changeAmount: b
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -47,18 +47,18 @@ function Ae(e, t, n, s) {
|
|
|
47
47
|
`Insufficient funds: need ${t + c} sats (${t} pegin + ${c} fee), have ${a} sats`
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return e >
|
|
50
|
+
function Qn(e) {
|
|
51
|
+
return e > Xt;
|
|
52
52
|
}
|
|
53
53
|
function Yn() {
|
|
54
|
-
return
|
|
54
|
+
return me;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function dt(e) {
|
|
57
57
|
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
58
|
-
return `0x${
|
|
58
|
+
return `0x${xt.fromHex(t).getId()}`;
|
|
59
59
|
}
|
|
60
60
|
var ot = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(ot || {});
|
|
61
|
-
function
|
|
61
|
+
function Fe(e) {
|
|
62
62
|
const t = e.length;
|
|
63
63
|
return t === 25 && e[0] === 118 && // OP_DUP
|
|
64
64
|
e[1] === 169 && // OP_HASH160
|
|
@@ -71,8 +71,8 @@ function Ce(e) {
|
|
|
71
71
|
e[1] === 32 ? "P2WSH" : t === 34 && e[0] === 81 && // OP_1
|
|
72
72
|
e[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const n = W.from(e.scriptPubKey, "hex"), s =
|
|
74
|
+
function Ce(e, t) {
|
|
75
|
+
const n = W.from(e.scriptPubKey, "hex"), s = Fe(n);
|
|
76
76
|
switch (s) {
|
|
77
77
|
case ot.P2WPKH:
|
|
78
78
|
return {
|
|
@@ -110,7 +110,7 @@ function Fe(e, t) {
|
|
|
110
110
|
throw new Error(`Unsupported script type: ${s}`);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function gt(e, t) {
|
|
114
114
|
if (!Number.isInteger(t) || t < 1)
|
|
115
115
|
throw new Error(`inputCount must be a positive integer, got ${t}`);
|
|
116
116
|
return {
|
|
@@ -122,24 +122,43 @@ function yt(e, t) {
|
|
|
122
122
|
}))
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
function
|
|
127
|
-
|
|
125
|
+
const $e = 21e6 * 1e8, Ft = 3e4;
|
|
126
|
+
async function at(e, t) {
|
|
127
|
+
const n = new AbortController(), s = setTimeout(
|
|
128
|
+
() => n.abort(),
|
|
129
|
+
Ft
|
|
130
|
+
), o = [n.signal, t == null ? void 0 : t.signal].filter(
|
|
131
|
+
Boolean
|
|
132
|
+
);
|
|
133
|
+
try {
|
|
134
|
+
return await fetch(e, {
|
|
135
|
+
...t,
|
|
136
|
+
signal: AbortSignal.any(o)
|
|
137
|
+
});
|
|
138
|
+
} catch (r) {
|
|
139
|
+
throw clearTimeout(s), r != null && typeof r == "object" && "name" in r && r.name === "AbortError" ? new Error(
|
|
140
|
+
`Mempool API request timed out after ${Ft}ms: ${e}`
|
|
141
|
+
) : r;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const qt = 1e4;
|
|
145
|
+
function Gt(e) {
|
|
146
|
+
return Number.isInteger(e) && e > 0 && e <= $e;
|
|
128
147
|
}
|
|
129
|
-
function
|
|
130
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
148
|
+
function Oe(e) {
|
|
149
|
+
return Number.isInteger(e) && e > 0 && e <= qt;
|
|
131
150
|
}
|
|
132
|
-
function
|
|
151
|
+
function jt(e, t) {
|
|
133
152
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
134
153
|
}
|
|
135
|
-
const
|
|
154
|
+
const Le = {
|
|
136
155
|
mainnet: "https://mempool.space/api",
|
|
137
156
|
testnet: "https://mempool.space/testnet/api",
|
|
138
157
|
signet: "https://mempool.space/signet/api"
|
|
139
158
|
};
|
|
140
159
|
async function it(e, t) {
|
|
141
160
|
try {
|
|
142
|
-
const n = await
|
|
161
|
+
const n = await at(e, t);
|
|
143
162
|
if (!n.ok) {
|
|
144
163
|
const o = await n.text();
|
|
145
164
|
throw new Error(
|
|
@@ -152,9 +171,9 @@ async function it(e, t) {
|
|
|
152
171
|
throw n instanceof Error ? new Error(`Failed to fetch from mempool API: ${n.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
153
172
|
}
|
|
154
173
|
}
|
|
155
|
-
async function
|
|
174
|
+
async function _e(e, t) {
|
|
156
175
|
try {
|
|
157
|
-
const n = await
|
|
176
|
+
const n = await at(`${t}/tx`, {
|
|
158
177
|
method: "POST",
|
|
159
178
|
body: e,
|
|
160
179
|
headers: {
|
|
@@ -178,12 +197,12 @@ async function Le(e, t) {
|
|
|
178
197
|
throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
179
198
|
}
|
|
180
199
|
}
|
|
181
|
-
async function
|
|
200
|
+
async function Re(e, t) {
|
|
182
201
|
return it(`${t}/tx/${e}`);
|
|
183
202
|
}
|
|
184
|
-
async function
|
|
203
|
+
async function ts(e, t) {
|
|
185
204
|
try {
|
|
186
|
-
const n = await
|
|
205
|
+
const n = await at(`${t}/tx/${e}/hex`);
|
|
187
206
|
if (!n.ok) {
|
|
188
207
|
const s = await n.text();
|
|
189
208
|
throw new Error(
|
|
@@ -195,14 +214,14 @@ async function Qn(e, t) {
|
|
|
195
214
|
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`);
|
|
196
215
|
}
|
|
197
216
|
}
|
|
198
|
-
async function
|
|
199
|
-
const s = await
|
|
200
|
-
if (!
|
|
217
|
+
async function We(e, t, n) {
|
|
218
|
+
const s = await Re(e, n);
|
|
219
|
+
if (!jt(t, s.vout.length))
|
|
201
220
|
throw new Error(
|
|
202
221
|
`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
|
|
203
222
|
);
|
|
204
223
|
const o = s.vout[t];
|
|
205
|
-
if (!
|
|
224
|
+
if (!Gt(o.value))
|
|
206
225
|
throw new Error(`Invalid UTXO value ${o.value} for ${e}:${t}`);
|
|
207
226
|
return {
|
|
208
227
|
txid: e,
|
|
@@ -211,7 +230,7 @@ async function Re(e, t, n) {
|
|
|
211
230
|
scriptPubKey: o.scriptpubkey
|
|
212
231
|
};
|
|
213
232
|
}
|
|
214
|
-
async function
|
|
233
|
+
async function es(e, t) {
|
|
215
234
|
try {
|
|
216
235
|
const n = await it(`${t}/address/${e}/utxo`), s = await it(`${t}/v1/validate-address/${e}`);
|
|
217
236
|
if (!s.isvalid)
|
|
@@ -219,9 +238,9 @@ async function ts(e, t) {
|
|
|
219
238
|
`Invalid Bitcoin address: ${e}. Mempool API validation failed.`
|
|
220
239
|
);
|
|
221
240
|
for (const r of n) {
|
|
222
|
-
if (!
|
|
241
|
+
if (!jt(r.vout))
|
|
223
242
|
throw new Error(`Invalid vout ${r.vout} for ${r.txid}`);
|
|
224
|
-
if (!
|
|
243
|
+
if (!Gt(r.value))
|
|
225
244
|
throw new Error(
|
|
226
245
|
`Invalid UTXO value ${r.value} for ${r.txid}:${r.vout}`
|
|
227
246
|
);
|
|
@@ -241,14 +260,14 @@ async function ts(e, t) {
|
|
|
241
260
|
);
|
|
242
261
|
}
|
|
243
262
|
}
|
|
244
|
-
function
|
|
245
|
-
return
|
|
263
|
+
function ns(e) {
|
|
264
|
+
return Le[e];
|
|
246
265
|
}
|
|
247
|
-
async function
|
|
266
|
+
async function ss(e, t) {
|
|
248
267
|
return it(`${t}/address/${e}/txs`);
|
|
249
268
|
}
|
|
250
|
-
async function
|
|
251
|
-
const t = await
|
|
269
|
+
async function os(e) {
|
|
270
|
+
const t = await at(`${e}/v1/fees/recommended`);
|
|
252
271
|
if (!t.ok)
|
|
253
272
|
throw new Error(
|
|
254
273
|
`Failed to fetch network fees: ${t.status} ${t.statusText}`
|
|
@@ -261,9 +280,9 @@ async function ss(e) {
|
|
|
261
280
|
"minimumFee"
|
|
262
281
|
];
|
|
263
282
|
for (const o of s)
|
|
264
|
-
if (
|
|
283
|
+
if (!Oe(n[o]))
|
|
265
284
|
throw new Error(
|
|
266
|
-
`Invalid fee rate ${o}=${n[o]} from mempool API: expected a positive number ≤ ${
|
|
285
|
+
`Invalid fee rate ${o}=${n[o]} from mempool API: expected a positive number ≤ ${qt}`
|
|
267
286
|
);
|
|
268
287
|
if (n.minimumFee > n.economyFee || n.economyFee > n.hourFee || n.hourFee > n.halfHourFee || n.halfHourFee > n.fastestFee)
|
|
269
288
|
throw new Error(
|
|
@@ -477,7 +496,7 @@ const j = [
|
|
|
477
496
|
},
|
|
478
497
|
{
|
|
479
498
|
type: "function",
|
|
480
|
-
name: "
|
|
499
|
+
name: "getBtcVaultBasicInfo",
|
|
481
500
|
inputs: [
|
|
482
501
|
{
|
|
483
502
|
name: "vaultId",
|
|
@@ -486,30 +505,13 @@ const j = [
|
|
|
486
505
|
}
|
|
487
506
|
],
|
|
488
507
|
outputs: [
|
|
489
|
-
{
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
{ name: "depositorSignedPeginTx", type: "bytes", internalType: "bytes" },
|
|
497
|
-
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
498
|
-
{ name: "vaultProvider", type: "address", internalType: "address" },
|
|
499
|
-
{ name: "status", type: "uint8", internalType: "enum IBTCVaultRegistry.BTCVaultStatus" },
|
|
500
|
-
{ name: "applicationEntryPoint", type: "address", internalType: "address" },
|
|
501
|
-
{ name: "universalChallengersVersion", type: "uint16", internalType: "uint16" },
|
|
502
|
-
{ name: "appVaultKeepersVersion", type: "uint16", internalType: "uint16" },
|
|
503
|
-
{ name: "offchainParamsVersion", type: "uint16", internalType: "uint16" },
|
|
504
|
-
{ name: "createdAt", type: "uint256", internalType: "uint256" },
|
|
505
|
-
{ name: "verifiedAt", type: "uint256", internalType: "uint256" },
|
|
506
|
-
{ name: "depositorWotsPkHash", type: "bytes32", internalType: "bytes32" },
|
|
507
|
-
{ name: "hashlock", type: "bytes32", internalType: "bytes32" },
|
|
508
|
-
{ name: "htlcVout", type: "uint8", internalType: "uint8" },
|
|
509
|
-
{ name: "depositorPopSignature", type: "bytes", internalType: "bytes" },
|
|
510
|
-
{ name: "prePeginTxHash", type: "bytes32", internalType: "bytes32" }
|
|
511
|
-
]
|
|
512
|
-
}
|
|
508
|
+
{ name: "depositor", type: "address", internalType: "address" },
|
|
509
|
+
{ name: "depositorBtcPubKey", type: "bytes32", internalType: "bytes32" },
|
|
510
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
511
|
+
{ name: "vaultProvider", type: "address", internalType: "address" },
|
|
512
|
+
{ name: "status", type: "uint8", internalType: "enum IBTCVaultRegistry.BTCVaultStatus" },
|
|
513
|
+
{ name: "applicationEntryPoint", type: "address", internalType: "address" },
|
|
514
|
+
{ name: "createdAt", type: "uint256", internalType: "uint256" }
|
|
513
515
|
],
|
|
514
516
|
stateMutability: "view"
|
|
515
517
|
},
|
|
@@ -594,7 +596,7 @@ const j = [
|
|
|
594
596
|
// InvalidPeginFee(uint256,uint256)
|
|
595
597
|
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
596
598
|
};
|
|
597
|
-
function
|
|
599
|
+
function wt(e) {
|
|
598
600
|
if (!e || typeof e != "object") return;
|
|
599
601
|
const t = e;
|
|
600
602
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -613,22 +615,22 @@ function xt(e) {
|
|
|
613
615
|
if (i)
|
|
614
616
|
return i[1];
|
|
615
617
|
}
|
|
616
|
-
function
|
|
617
|
-
const t =
|
|
618
|
+
function rs(e) {
|
|
619
|
+
const t = wt(e);
|
|
618
620
|
if (t) {
|
|
619
621
|
const n = t.substring(0, 10);
|
|
620
622
|
return q[t] ?? q[n];
|
|
621
623
|
}
|
|
622
624
|
}
|
|
623
|
-
function
|
|
624
|
-
const t =
|
|
625
|
+
function is(e) {
|
|
626
|
+
const t = wt(e);
|
|
625
627
|
if (t === void 0) return !1;
|
|
626
628
|
const n = t.substring(0, 10);
|
|
627
629
|
return t in q || n in q;
|
|
628
630
|
}
|
|
629
|
-
function
|
|
631
|
+
function K(e) {
|
|
630
632
|
console.error("[Contract Error] Raw error:", e);
|
|
631
|
-
const t =
|
|
633
|
+
const t = wt(e);
|
|
632
634
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
633
635
|
const s = t.substring(0, 10), o = q[t] ?? q[s];
|
|
634
636
|
if (o)
|
|
@@ -648,18 +650,18 @@ function M(e) {
|
|
|
648
650
|
}
|
|
649
651
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
650
652
|
}
|
|
651
|
-
const
|
|
652
|
-
function
|
|
653
|
+
const Ve = 0;
|
|
654
|
+
function De(e, t, n, s) {
|
|
653
655
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
654
656
|
return o ? Promise.resolve({
|
|
655
657
|
txid: e,
|
|
656
658
|
vout: t,
|
|
657
659
|
value: o.value,
|
|
658
660
|
scriptPubKey: o.scriptPubKey
|
|
659
|
-
}) :
|
|
661
|
+
}) : We(e, t, s);
|
|
660
662
|
}
|
|
661
663
|
const Ct = 12e4;
|
|
662
|
-
class
|
|
664
|
+
class as {
|
|
663
665
|
/**
|
|
664
666
|
* Creates a new PeginManager instance.
|
|
665
667
|
*
|
|
@@ -710,25 +712,25 @@ class is {
|
|
|
710
712
|
councilQuorum: t.councilQuorum,
|
|
711
713
|
councilSize: t.councilSize,
|
|
712
714
|
network: this.config.btcNetwork
|
|
713
|
-
}, l = await
|
|
715
|
+
}, l = await Te(c), h = Ue(
|
|
714
716
|
[...t.availableUTXOs],
|
|
715
717
|
l.totalOutputValue,
|
|
716
718
|
t.mempoolFeeRate,
|
|
717
|
-
|
|
718
|
-
), u =
|
|
719
|
+
ve(l.htlcValues.length)
|
|
720
|
+
), u = Et(this.config.btcNetwork), d = ke({
|
|
719
721
|
unfundedTxHex: l.psbtHex,
|
|
720
722
|
selectedUTXOs: h.selectedUTXOs,
|
|
721
723
|
changeAddress: t.changeAddress,
|
|
722
724
|
changeAmount: h.changeAmount,
|
|
723
725
|
network: u
|
|
724
|
-
}),
|
|
726
|
+
}), y = B(dt(d)), b = [], x = [], P = [];
|
|
725
727
|
for (let f = 0; f < t.hashlocks.length; f++) {
|
|
726
|
-
const w = await
|
|
728
|
+
const w = await He({
|
|
727
729
|
prePeginParams: c,
|
|
728
730
|
timelockPegin: t.timelockPegin,
|
|
729
731
|
fundedPrePeginTxHex: d,
|
|
730
732
|
htlcVout: f
|
|
731
|
-
}), v = await
|
|
733
|
+
}), v = await Ie({
|
|
732
734
|
peginTxHex: w.txHex,
|
|
733
735
|
fundedPrePeginTxHex: d,
|
|
734
736
|
depositorPubkey: s,
|
|
@@ -739,33 +741,33 @@ class is {
|
|
|
739
741
|
timelockRefund: t.timelockRefund,
|
|
740
742
|
network: this.config.btcNetwork
|
|
741
743
|
});
|
|
742
|
-
|
|
743
|
-
|
|
744
|
+
b.push(w), x.push(v.psbtHex), P.push(
|
|
745
|
+
gt(n, 1)
|
|
744
746
|
);
|
|
745
747
|
}
|
|
746
748
|
const m = await this.signPsbtsWithFallback(
|
|
747
749
|
x,
|
|
748
750
|
P
|
|
749
|
-
),
|
|
751
|
+
), g = [];
|
|
750
752
|
for (let f = 0; f < m.length; f++) {
|
|
751
|
-
const w =
|
|
753
|
+
const w = Ee(
|
|
752
754
|
m[f],
|
|
753
755
|
s
|
|
754
|
-
), v =
|
|
755
|
-
|
|
756
|
+
), v = Be(m[f]);
|
|
757
|
+
g.push({
|
|
756
758
|
htlcVout: f,
|
|
757
759
|
htlcValue: l.htlcValues[f],
|
|
758
760
|
peginTxHex: v,
|
|
759
|
-
peginTxid:
|
|
761
|
+
peginTxid: b[f].txid,
|
|
760
762
|
peginInputSignature: w,
|
|
761
|
-
vaultScriptPubKey:
|
|
763
|
+
vaultScriptPubKey: b[f].vaultScriptPubKey
|
|
762
764
|
});
|
|
763
765
|
}
|
|
764
766
|
return {
|
|
765
767
|
fundedPrePeginTxHex: d,
|
|
766
|
-
prePeginTxid:
|
|
768
|
+
prePeginTxid: y,
|
|
767
769
|
unsignedPrePeginTxHex: l.psbtHex,
|
|
768
|
-
perVault:
|
|
770
|
+
perVault: g,
|
|
769
771
|
selectedUTXOs: h.selectedUTXOs,
|
|
770
772
|
fee: h.fee,
|
|
771
773
|
changeAmount: h.changeAmount
|
|
@@ -816,10 +818,10 @@ class is {
|
|
|
816
818
|
* @throws Error if signing or broadcasting fails
|
|
817
819
|
*/
|
|
818
820
|
async signAndBroadcast(t) {
|
|
819
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r =
|
|
821
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = xt.fromHex(o);
|
|
820
822
|
if (r.ins.length === 0)
|
|
821
823
|
throw new Error("Transaction has no inputs");
|
|
822
|
-
const i = new
|
|
824
|
+
const i = new kt();
|
|
823
825
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
824
826
|
const a = s.startsWith("0x") ? s.slice(2) : s;
|
|
825
827
|
if (a.length !== 64 || !/^[0-9a-fA-F]+$/.test(a))
|
|
@@ -831,24 +833,24 @@ class is {
|
|
|
831
833
|
throw new Error(
|
|
832
834
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
833
835
|
);
|
|
834
|
-
const l = this.config.mempoolApiUrl, h = r.ins.map((
|
|
835
|
-
const f = W.from(
|
|
836
|
-
return
|
|
837
|
-
(v) => ({ input:
|
|
836
|
+
const l = this.config.mempoolApiUrl, h = r.ins.map((g) => {
|
|
837
|
+
const f = W.from(g.hash).reverse().toString("hex"), w = g.index;
|
|
838
|
+
return De(f, w, t.localPrevouts, l).then(
|
|
839
|
+
(v) => ({ input: g, utxoData: v, txid: f, vout: w })
|
|
838
840
|
);
|
|
839
841
|
}), u = await Promise.all(h), d = u.reduce(
|
|
840
|
-
(
|
|
842
|
+
(g, f) => g + BigInt(f.utxoData.value),
|
|
841
843
|
0n
|
|
842
|
-
),
|
|
843
|
-
(
|
|
844
|
+
), y = r.outs.reduce(
|
|
845
|
+
(g, f) => g + BigInt(f.value),
|
|
844
846
|
0n
|
|
845
847
|
);
|
|
846
|
-
if (d <
|
|
848
|
+
if (d < y)
|
|
847
849
|
throw new Error(
|
|
848
|
-
`UTXO value mismatch: total input value (${d} sat) is less than total output value (${
|
|
850
|
+
`UTXO value mismatch: total input value (${d} sat) is less than total output value (${y} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
849
851
|
);
|
|
850
|
-
for (const { input:
|
|
851
|
-
const T =
|
|
852
|
+
for (const { input: g, utxoData: f, txid: w, vout: v } of u) {
|
|
853
|
+
const T = Ce(
|
|
852
854
|
{
|
|
853
855
|
value: f.value,
|
|
854
856
|
scriptPubKey: f.scriptPubKey
|
|
@@ -856,30 +858,30 @@ class is {
|
|
|
856
858
|
c
|
|
857
859
|
);
|
|
858
860
|
i.addInput({
|
|
859
|
-
hash:
|
|
860
|
-
index:
|
|
861
|
-
sequence:
|
|
861
|
+
hash: g.hash,
|
|
862
|
+
index: g.index,
|
|
863
|
+
sequence: g.sequence,
|
|
862
864
|
...T
|
|
863
865
|
});
|
|
864
866
|
}
|
|
865
|
-
for (const
|
|
867
|
+
for (const g of r.outs)
|
|
866
868
|
i.addOutput({
|
|
867
|
-
script:
|
|
868
|
-
value:
|
|
869
|
+
script: g.script,
|
|
870
|
+
value: g.value
|
|
869
871
|
});
|
|
870
|
-
const
|
|
872
|
+
const b = await this.config.btcWallet.signPsbt(i.toHex()), x = kt.fromHex(b);
|
|
871
873
|
try {
|
|
872
874
|
x.finalizeAllInputs();
|
|
873
|
-
} catch (
|
|
875
|
+
} catch (g) {
|
|
874
876
|
if (!x.data.inputs.every(
|
|
875
877
|
(w) => w.finalScriptWitness || w.finalScriptSig
|
|
876
878
|
))
|
|
877
879
|
throw new Error(
|
|
878
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
880
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${g}`
|
|
879
881
|
);
|
|
880
882
|
}
|
|
881
883
|
const P = x.extractTransaction().toHex();
|
|
882
|
-
return await
|
|
884
|
+
return await _e(P, l);
|
|
883
885
|
}
|
|
884
886
|
/**
|
|
885
887
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -913,24 +915,24 @@ class is {
|
|
|
913
915
|
} = t;
|
|
914
916
|
if (!this.config.ethWallet.account)
|
|
915
917
|
throw new Error("Ethereum wallet account not found");
|
|
916
|
-
const d = this.config.ethWallet.account.address,
|
|
918
|
+
const d = this.config.ethWallet.account.address, y = await this.resolvePopSignature(
|
|
917
919
|
d,
|
|
918
920
|
u
|
|
919
921
|
);
|
|
920
922
|
c && await c();
|
|
921
|
-
const
|
|
923
|
+
const b = U(n), x = U(s), P = U(o), m = await this.resolvePayoutScriptPubKey(
|
|
922
924
|
l
|
|
923
|
-
),
|
|
924
|
-
B(
|
|
925
|
+
), g = dt(P), f = await Ut(
|
|
926
|
+
B(g),
|
|
925
927
|
B(d)
|
|
926
|
-
), w =
|
|
928
|
+
), w = U(f);
|
|
927
929
|
if (await this.checkVaultExists(w))
|
|
928
930
|
throw new Error(
|
|
929
|
-
`Vault already exists (ID: ${w}, peginTxHash: ${
|
|
931
|
+
`Vault already exists (ID: ${w}, peginTxHash: ${g}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
|
|
930
932
|
);
|
|
931
|
-
const T =
|
|
933
|
+
const T = lt({
|
|
932
934
|
chain: this.config.ethChain,
|
|
933
|
-
transport:
|
|
935
|
+
transport: ht()
|
|
934
936
|
});
|
|
935
937
|
let H;
|
|
936
938
|
try {
|
|
@@ -945,13 +947,13 @@ class is {
|
|
|
945
947
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
946
948
|
);
|
|
947
949
|
}
|
|
948
|
-
const I =
|
|
950
|
+
const I = Ht({
|
|
949
951
|
abi: j,
|
|
950
952
|
functionName: "submitPeginRequest",
|
|
951
953
|
args: [
|
|
952
954
|
d,
|
|
955
|
+
b,
|
|
953
956
|
y,
|
|
954
|
-
g,
|
|
955
957
|
x,
|
|
956
958
|
P,
|
|
957
959
|
r,
|
|
@@ -970,11 +972,11 @@ class is {
|
|
|
970
972
|
account: this.config.ethWallet.account.address
|
|
971
973
|
});
|
|
972
974
|
} catch ($) {
|
|
973
|
-
|
|
975
|
+
K($);
|
|
974
976
|
}
|
|
975
|
-
let
|
|
977
|
+
let C;
|
|
976
978
|
try {
|
|
977
|
-
|
|
979
|
+
C = await this.config.ethWallet.sendTransaction({
|
|
978
980
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
979
981
|
data: I,
|
|
980
982
|
value: H,
|
|
@@ -983,21 +985,21 @@ class is {
|
|
|
983
985
|
gas: E
|
|
984
986
|
});
|
|
985
987
|
} catch ($) {
|
|
986
|
-
|
|
988
|
+
K($);
|
|
987
989
|
}
|
|
988
|
-
const
|
|
989
|
-
hash:
|
|
990
|
+
const M = await T.waitForTransactionReceipt({
|
|
991
|
+
hash: C,
|
|
990
992
|
timeout: Ct
|
|
991
993
|
});
|
|
992
|
-
return
|
|
994
|
+
return M.status === "reverted" && K(
|
|
993
995
|
new Error(
|
|
994
|
-
`Transaction reverted. Hash: ${
|
|
996
|
+
`Transaction reverted. Hash: ${C}. Check the transaction on block explorer for details.`
|
|
995
997
|
)
|
|
996
998
|
), {
|
|
997
|
-
ethTxHash:
|
|
999
|
+
ethTxHash: M.transactionHash,
|
|
998
1000
|
vaultId: w,
|
|
999
|
-
peginTxHash:
|
|
1000
|
-
btcPopSignature:
|
|
1001
|
+
peginTxHash: g,
|
|
1002
|
+
btcPopSignature: y
|
|
1001
1003
|
};
|
|
1002
1004
|
}
|
|
1003
1005
|
/**
|
|
@@ -1022,27 +1024,27 @@ class is {
|
|
|
1022
1024
|
);
|
|
1023
1025
|
r && await r();
|
|
1024
1026
|
const c = [];
|
|
1025
|
-
for (const
|
|
1027
|
+
for (const g of s)
|
|
1026
1028
|
c.push(
|
|
1027
|
-
await this.resolvePayoutScriptPubKey(
|
|
1029
|
+
await this.resolvePayoutScriptPubKey(g.depositorPayoutBtcAddress)
|
|
1028
1030
|
);
|
|
1029
1031
|
const l = [];
|
|
1030
|
-
for (const
|
|
1031
|
-
const f =
|
|
1032
|
-
|
|
1033
|
-
), w =
|
|
1032
|
+
for (const g of s) {
|
|
1033
|
+
const f = U(
|
|
1034
|
+
g.depositorSignedPeginTx
|
|
1035
|
+
), w = dt(f), v = await Ut(
|
|
1034
1036
|
B(w),
|
|
1035
1037
|
B(i)
|
|
1036
|
-
), T =
|
|
1038
|
+
), T = U(v);
|
|
1037
1039
|
if (await this.checkVaultExists(T))
|
|
1038
1040
|
throw new Error(
|
|
1039
1041
|
`Vault already exists (ID: ${T}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`
|
|
1040
1042
|
);
|
|
1041
1043
|
l.push({ vaultId: T, peginTxHash: w });
|
|
1042
1044
|
}
|
|
1043
|
-
const h =
|
|
1045
|
+
const h = lt({
|
|
1044
1046
|
chain: this.config.ethChain,
|
|
1045
|
-
transport:
|
|
1047
|
+
transport: ht()
|
|
1046
1048
|
});
|
|
1047
1049
|
let u;
|
|
1048
1050
|
try {
|
|
@@ -1057,52 +1059,52 @@ class is {
|
|
|
1057
1059
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1058
1060
|
);
|
|
1059
1061
|
}
|
|
1060
|
-
const d = u * BigInt(s.length),
|
|
1061
|
-
depositorBtcPubKey:
|
|
1062
|
+
const d = u * BigInt(s.length), y = s.map((g, f) => ({
|
|
1063
|
+
depositorBtcPubKey: U(g.depositorBtcPubkey),
|
|
1062
1064
|
btcPopSignature: a,
|
|
1063
|
-
unsignedPrePeginTx:
|
|
1064
|
-
depositorSignedPeginTx:
|
|
1065
|
-
|
|
1065
|
+
unsignedPrePeginTx: U(g.unsignedPrePeginTx),
|
|
1066
|
+
depositorSignedPeginTx: U(
|
|
1067
|
+
g.depositorSignedPeginTx
|
|
1066
1068
|
),
|
|
1067
|
-
hashlock:
|
|
1068
|
-
htlcVout:
|
|
1069
|
-
referralCode:
|
|
1069
|
+
hashlock: g.hashlock,
|
|
1070
|
+
htlcVout: g.htlcVout,
|
|
1071
|
+
referralCode: Ve,
|
|
1070
1072
|
depositorPayoutBtcAddress: c[f],
|
|
1071
|
-
depositorWotsPkHash:
|
|
1072
|
-
})),
|
|
1073
|
+
depositorWotsPkHash: g.depositorWotsPkHash
|
|
1074
|
+
})), b = Ht({
|
|
1073
1075
|
abi: j,
|
|
1074
1076
|
functionName: "submitPeginRequestBatch",
|
|
1075
|
-
args: [i, n,
|
|
1077
|
+
args: [i, n, y]
|
|
1076
1078
|
});
|
|
1077
1079
|
let x;
|
|
1078
1080
|
try {
|
|
1079
1081
|
x = await h.estimateGas({
|
|
1080
1082
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1081
|
-
data:
|
|
1083
|
+
data: b,
|
|
1082
1084
|
value: d,
|
|
1083
1085
|
account: this.config.ethWallet.account.address
|
|
1084
1086
|
});
|
|
1085
|
-
} catch (
|
|
1086
|
-
|
|
1087
|
+
} catch (g) {
|
|
1088
|
+
K(g);
|
|
1087
1089
|
}
|
|
1088
1090
|
let P;
|
|
1089
1091
|
try {
|
|
1090
1092
|
P = await this.config.ethWallet.sendTransaction({
|
|
1091
1093
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1092
|
-
data:
|
|
1094
|
+
data: b,
|
|
1093
1095
|
value: d,
|
|
1094
1096
|
account: this.config.ethWallet.account,
|
|
1095
1097
|
chain: this.config.ethChain,
|
|
1096
1098
|
gas: x
|
|
1097
1099
|
});
|
|
1098
|
-
} catch (
|
|
1099
|
-
|
|
1100
|
+
} catch (g) {
|
|
1101
|
+
K(g);
|
|
1100
1102
|
}
|
|
1101
1103
|
const m = await h.waitForTransactionReceipt({
|
|
1102
1104
|
hash: P,
|
|
1103
1105
|
timeout: Ct
|
|
1104
1106
|
});
|
|
1105
|
-
return m.status === "reverted" &&
|
|
1107
|
+
return m.status === "reverted" && K(
|
|
1106
1108
|
new Error(
|
|
1107
1109
|
`Batch transaction reverted. Hash: ${P}. Check the transaction on block explorer for details.`
|
|
1108
1110
|
)
|
|
@@ -1120,15 +1122,15 @@ class is {
|
|
|
1120
1122
|
*/
|
|
1121
1123
|
async checkVaultExists(t) {
|
|
1122
1124
|
try {
|
|
1123
|
-
return (await
|
|
1125
|
+
return (await lt({
|
|
1124
1126
|
chain: this.config.ethChain,
|
|
1125
|
-
transport:
|
|
1127
|
+
transport: ht()
|
|
1126
1128
|
}).readContract({
|
|
1127
1129
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1128
1130
|
abi: j,
|
|
1129
|
-
functionName: "
|
|
1131
|
+
functionName: "getBtcVaultBasicInfo",
|
|
1130
1132
|
args: [t]
|
|
1131
|
-
}))
|
|
1133
|
+
}))[0] !== ye;
|
|
1132
1134
|
} catch {
|
|
1133
1135
|
return !1;
|
|
1134
1136
|
}
|
|
@@ -1141,14 +1143,13 @@ class is {
|
|
|
1141
1143
|
* wallet's public key to guard against a compromised wallet provider.
|
|
1142
1144
|
*/
|
|
1143
1145
|
async resolvePayoutScriptPubKey(t) {
|
|
1144
|
-
Ee();
|
|
1145
1146
|
let n;
|
|
1146
1147
|
if (t)
|
|
1147
1148
|
n = t;
|
|
1148
1149
|
else {
|
|
1149
1150
|
n = await this.config.btcWallet.getAddress();
|
|
1150
1151
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1151
|
-
if (!
|
|
1152
|
+
if (!Se(
|
|
1152
1153
|
n,
|
|
1153
1154
|
o,
|
|
1154
1155
|
this.config.btcNetwork
|
|
@@ -1157,9 +1158,9 @@ class is {
|
|
|
1157
1158
|
"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)."
|
|
1158
1159
|
);
|
|
1159
1160
|
}
|
|
1160
|
-
const s =
|
|
1161
|
+
const s = Et(this.config.btcNetwork);
|
|
1161
1162
|
try {
|
|
1162
|
-
return `0x${
|
|
1163
|
+
return `0x${be.address.toOutputScript(n, s).toString("hex")}`;
|
|
1163
1164
|
} catch {
|
|
1164
1165
|
throw new Error(
|
|
1165
1166
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1198,7 +1199,7 @@ class is {
|
|
|
1198
1199
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1199
1200
|
}
|
|
1200
1201
|
}
|
|
1201
|
-
class
|
|
1202
|
+
class cs {
|
|
1202
1203
|
/**
|
|
1203
1204
|
* Creates a new PayoutManager instance.
|
|
1204
1205
|
*
|
|
@@ -1235,10 +1236,10 @@ class as {
|
|
|
1235
1236
|
t.payoutTxHex,
|
|
1236
1237
|
t.registeredPayoutScriptPubKey
|
|
1237
1238
|
);
|
|
1238
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } =
|
|
1239
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = Bt(
|
|
1239
1240
|
n,
|
|
1240
1241
|
t.depositorBtcPubkey
|
|
1241
|
-
), o = await
|
|
1242
|
+
), o = await St({
|
|
1242
1243
|
payoutTxHex: t.payoutTxHex,
|
|
1243
1244
|
peginTxHex: t.peginTxHex,
|
|
1244
1245
|
assertTxHex: t.assertTxHex,
|
|
@@ -1250,10 +1251,10 @@ class as {
|
|
|
1250
1251
|
network: this.config.network
|
|
1251
1252
|
}), r = await this.config.btcWallet.signPsbt(
|
|
1252
1253
|
o.psbtHex,
|
|
1253
|
-
|
|
1254
|
+
gt(n, 1)
|
|
1254
1255
|
);
|
|
1255
1256
|
return {
|
|
1256
|
-
signature:
|
|
1257
|
+
signature: At(r, s),
|
|
1257
1258
|
depositorBtcPubkey: s
|
|
1258
1259
|
};
|
|
1259
1260
|
}
|
|
@@ -1293,12 +1294,12 @@ class as {
|
|
|
1293
1294
|
c.payoutTxHex,
|
|
1294
1295
|
c.registeredPayoutScriptPubKey
|
|
1295
1296
|
);
|
|
1296
|
-
const { depositorPubkey: l } =
|
|
1297
|
+
const { depositorPubkey: l } = Bt(
|
|
1297
1298
|
n,
|
|
1298
1299
|
c.depositorBtcPubkey
|
|
1299
1300
|
);
|
|
1300
1301
|
r.push(l);
|
|
1301
|
-
const h = await
|
|
1302
|
+
const h = await St({
|
|
1302
1303
|
payoutTxHex: c.payoutTxHex,
|
|
1303
1304
|
peginTxHex: c.peginTxHex,
|
|
1304
1305
|
assertTxHex: c.assertTxHex,
|
|
@@ -1309,7 +1310,7 @@ class as {
|
|
|
1309
1310
|
timelockPegin: c.timelockPegin,
|
|
1310
1311
|
network: this.config.network
|
|
1311
1312
|
});
|
|
1312
|
-
s.push(h.psbtHex), o.push(
|
|
1313
|
+
s.push(h.psbtHex), o.push(gt(n, 1));
|
|
1313
1314
|
}
|
|
1314
1315
|
const i = await this.config.btcWallet.signPsbts(
|
|
1315
1316
|
s,
|
|
@@ -1321,7 +1322,7 @@ class as {
|
|
|
1321
1322
|
);
|
|
1322
1323
|
const a = [];
|
|
1323
1324
|
for (let c = 0; c < t.length; c++) {
|
|
1324
|
-
const l = r[c], h =
|
|
1325
|
+
const l = r[c], h = At(
|
|
1325
1326
|
i[c],
|
|
1326
1327
|
l
|
|
1327
1328
|
);
|
|
@@ -1347,14 +1348,14 @@ class as {
|
|
|
1347
1348
|
* @throws Error if the largest output does not pay to the registered address
|
|
1348
1349
|
*/
|
|
1349
1350
|
validatePayoutOutputs(t, n) {
|
|
1350
|
-
if (!
|
|
1351
|
+
if (!Ae(n))
|
|
1351
1352
|
throw new Error(
|
|
1352
1353
|
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1353
1354
|
);
|
|
1354
1355
|
const s = W.from(
|
|
1355
1356
|
B(n),
|
|
1356
1357
|
"hex"
|
|
1357
|
-
), o =
|
|
1358
|
+
), o = xt.fromHex(B(t));
|
|
1358
1359
|
if (o.outs.length === 0)
|
|
1359
1360
|
throw new Error("Payout transaction has no outputs");
|
|
1360
1361
|
if (!o.outs.reduce(
|
|
@@ -1365,7 +1366,7 @@ class as {
|
|
|
1365
1366
|
);
|
|
1366
1367
|
}
|
|
1367
1368
|
}
|
|
1368
|
-
function
|
|
1369
|
+
function Me(e) {
|
|
1369
1370
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1370
1371
|
}
|
|
1371
1372
|
function V(e, t = "") {
|
|
@@ -1375,14 +1376,14 @@ function V(e, t = "") {
|
|
|
1375
1376
|
}
|
|
1376
1377
|
}
|
|
1377
1378
|
function D(e, t, n = "") {
|
|
1378
|
-
const s =
|
|
1379
|
+
const s = Me(e), o = e == null ? void 0 : e.length, r = t !== void 0;
|
|
1379
1380
|
if (!s || r && o !== t) {
|
|
1380
1381
|
const i = n && `"${n}" `, a = r ? ` of length ${t}` : "", c = s ? `length=${o}` : `type=${typeof e}`;
|
|
1381
1382
|
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
1382
1383
|
}
|
|
1383
1384
|
return e;
|
|
1384
1385
|
}
|
|
1385
|
-
function
|
|
1386
|
+
function zt(e) {
|
|
1386
1387
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1387
1388
|
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1388
1389
|
V(e.outputLen), V(e.blockLen);
|
|
@@ -1393,7 +1394,7 @@ function G(e, t = !0) {
|
|
|
1393
1394
|
if (t && e.finished)
|
|
1394
1395
|
throw new Error("Hash#digest() has already been called");
|
|
1395
1396
|
}
|
|
1396
|
-
function
|
|
1397
|
+
function Zt(e, t) {
|
|
1397
1398
|
D(e, void 0, "digestInto() output");
|
|
1398
1399
|
const n = t.outputLen;
|
|
1399
1400
|
if (e.length < n)
|
|
@@ -1415,37 +1416,37 @@ function A(e, t) {
|
|
|
1415
1416
|
function J(e, t) {
|
|
1416
1417
|
return e << t | e >>> 32 - t >>> 0;
|
|
1417
1418
|
}
|
|
1418
|
-
const
|
|
1419
|
-
function
|
|
1419
|
+
const Ne = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1420
|
+
function Xe(e) {
|
|
1420
1421
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1421
1422
|
}
|
|
1422
|
-
function
|
|
1423
|
+
function qe(e) {
|
|
1423
1424
|
for (let t = 0; t < e.length; t++)
|
|
1424
|
-
e[t] =
|
|
1425
|
+
e[t] = Xe(e[t]);
|
|
1425
1426
|
return e;
|
|
1426
1427
|
}
|
|
1427
|
-
const
|
|
1428
|
-
function
|
|
1428
|
+
const $t = Ne ? (e) => e : qe;
|
|
1429
|
+
function Ge(e) {
|
|
1429
1430
|
if (typeof e != "string")
|
|
1430
1431
|
throw new Error("string expected");
|
|
1431
1432
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1432
1433
|
}
|
|
1433
|
-
function
|
|
1434
|
-
return typeof e == "string" ?
|
|
1434
|
+
function Ot(e, t = "") {
|
|
1435
|
+
return typeof e == "string" ? Ge(e) : D(e, void 0, t);
|
|
1435
1436
|
}
|
|
1436
|
-
function
|
|
1437
|
+
function je(e, t) {
|
|
1437
1438
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1438
1439
|
throw new Error("options must be object or undefined");
|
|
1439
1440
|
return Object.assign(e, t);
|
|
1440
1441
|
}
|
|
1441
|
-
function
|
|
1442
|
+
function ct(e, t = {}) {
|
|
1442
1443
|
const n = (o, r) => e(r).update(o).digest(), s = e(void 0);
|
|
1443
1444
|
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (o) => e(o), Object.assign(n, t), Object.freeze(n);
|
|
1444
1445
|
}
|
|
1445
|
-
const
|
|
1446
|
+
const Jt = (e) => ({
|
|
1446
1447
|
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
1447
1448
|
});
|
|
1448
|
-
class
|
|
1449
|
+
class Qt {
|
|
1449
1450
|
constructor(t, n) {
|
|
1450
1451
|
p(this, "oHash");
|
|
1451
1452
|
p(this, "iHash");
|
|
@@ -1453,7 +1454,7 @@ class Zt {
|
|
|
1453
1454
|
p(this, "outputLen");
|
|
1454
1455
|
p(this, "finished", !1);
|
|
1455
1456
|
p(this, "destroyed", !1);
|
|
1456
|
-
if (
|
|
1457
|
+
if (zt(t), D(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1457
1458
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1458
1459
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1459
1460
|
const s = this.blockLen, o = new Uint8Array(s);
|
|
@@ -1487,15 +1488,15 @@ class Zt {
|
|
|
1487
1488
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1488
1489
|
}
|
|
1489
1490
|
}
|
|
1490
|
-
const
|
|
1491
|
-
|
|
1492
|
-
function
|
|
1491
|
+
const mt = (e, t, n) => new Qt(e, t).update(n).digest();
|
|
1492
|
+
mt.create = (e, t) => new Qt(e, t);
|
|
1493
|
+
function ze(e, t, n) {
|
|
1493
1494
|
return e & t ^ ~e & n;
|
|
1494
1495
|
}
|
|
1495
|
-
function
|
|
1496
|
+
function Ze(e, t, n) {
|
|
1496
1497
|
return e & t ^ e & n ^ t & n;
|
|
1497
1498
|
}
|
|
1498
|
-
class
|
|
1499
|
+
class Pt {
|
|
1499
1500
|
constructor(t, n, s, o) {
|
|
1500
1501
|
p(this, "blockLen");
|
|
1501
1502
|
p(this, "outputLen");
|
|
@@ -1526,7 +1527,7 @@ class mt {
|
|
|
1526
1527
|
return this.length += t.length, this.roundClean(), this;
|
|
1527
1528
|
}
|
|
1528
1529
|
digestInto(t) {
|
|
1529
|
-
G(this),
|
|
1530
|
+
G(this), Zt(t, this), this.finished = !0;
|
|
1530
1531
|
const { buffer: n, view: s, blockLen: o, isLE: r } = this;
|
|
1531
1532
|
let { pos: i } = this;
|
|
1532
1533
|
n[i++] = 128, S(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(s, 0), i = 0);
|
|
@@ -1583,7 +1584,7 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1583
1584
|
4215389547,
|
|
1584
1585
|
1541459225,
|
|
1585
1586
|
327033209
|
|
1586
|
-
]),
|
|
1587
|
+
]), Je = /* @__PURE__ */ Uint8Array.from([
|
|
1587
1588
|
7,
|
|
1588
1589
|
4,
|
|
1589
1590
|
13,
|
|
@@ -1600,36 +1601,36 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1600
1601
|
14,
|
|
1601
1602
|
11,
|
|
1602
1603
|
8
|
|
1603
|
-
]),
|
|
1604
|
-
const n = [[
|
|
1604
|
+
]), Yt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Qe = Yt.map((e) => (9 * e + 5) % 16), te = /* @__PURE__ */ (() => {
|
|
1605
|
+
const n = [[Yt], [Qe]];
|
|
1605
1606
|
for (let s = 0; s < 4; s++)
|
|
1606
1607
|
for (let o of n)
|
|
1607
|
-
o.push(o[s].map((r) =>
|
|
1608
|
+
o.push(o[s].map((r) => Je[r]));
|
|
1608
1609
|
return n;
|
|
1609
|
-
})(),
|
|
1610
|
+
})(), ee = te[0], ne = te[1], se = /* @__PURE__ */ [
|
|
1610
1611
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
1611
1612
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
1612
1613
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1613
1614
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1614
1615
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1615
|
-
].map((e) => Uint8Array.from(e)), Ye = /* @__PURE__ */
|
|
1616
|
+
].map((e) => Uint8Array.from(e)), Ye = /* @__PURE__ */ ee.map((e, t) => e.map((n) => se[t][n])), tn = /* @__PURE__ */ ne.map((e, t) => e.map((n) => se[t][n])), en = /* @__PURE__ */ Uint32Array.from([
|
|
1616
1617
|
0,
|
|
1617
1618
|
1518500249,
|
|
1618
1619
|
1859775393,
|
|
1619
1620
|
2400959708,
|
|
1620
1621
|
2840853838
|
|
1621
|
-
]),
|
|
1622
|
+
]), nn = /* @__PURE__ */ Uint32Array.from([
|
|
1622
1623
|
1352829926,
|
|
1623
1624
|
1548603684,
|
|
1624
1625
|
1836072691,
|
|
1625
1626
|
2053994217,
|
|
1626
1627
|
0
|
|
1627
1628
|
]);
|
|
1628
|
-
function
|
|
1629
|
+
function Lt(e, t, n, s) {
|
|
1629
1630
|
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);
|
|
1630
1631
|
}
|
|
1631
|
-
const
|
|
1632
|
-
class
|
|
1632
|
+
const Q = /* @__PURE__ */ new Uint32Array(16);
|
|
1633
|
+
class sn extends Pt {
|
|
1633
1634
|
constructor() {
|
|
1634
1635
|
super(64, 20, 8, !0);
|
|
1635
1636
|
p(this, "h0", 1732584193);
|
|
@@ -1646,48 +1647,48 @@ class nn extends mt {
|
|
|
1646
1647
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
1647
1648
|
}
|
|
1648
1649
|
process(n, s) {
|
|
1649
|
-
for (let
|
|
1650
|
-
|
|
1651
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, l = c, h = this.h3 | 0, u = h, d = this.h4 | 0,
|
|
1652
|
-
for (let
|
|
1653
|
-
const x = 4 -
|
|
1650
|
+
for (let b = 0; b < 16; b++, s += 4)
|
|
1651
|
+
Q[b] = n.getUint32(s, !0);
|
|
1652
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, l = c, h = this.h3 | 0, u = h, d = this.h4 | 0, y = d;
|
|
1653
|
+
for (let b = 0; b < 5; b++) {
|
|
1654
|
+
const x = 4 - b, P = en[b], m = nn[b], g = ee[b], f = ne[b], w = Ye[b], v = tn[b];
|
|
1654
1655
|
for (let T = 0; T < 16; T++) {
|
|
1655
|
-
const H = J(o +
|
|
1656
|
+
const H = J(o + Lt(b, i, c, h) + Q[g[T]] + P, w[T]) + d | 0;
|
|
1656
1657
|
o = d, d = h, h = J(c, 10) | 0, c = i, i = H;
|
|
1657
1658
|
}
|
|
1658
1659
|
for (let T = 0; T < 16; T++) {
|
|
1659
|
-
const H = J(r +
|
|
1660
|
-
r =
|
|
1660
|
+
const H = J(r + Lt(x, a, l, u) + Q[f[T]] + m, v[T]) + y | 0;
|
|
1661
|
+
r = y, y = u, u = J(l, 10) | 0, l = a, a = H;
|
|
1661
1662
|
}
|
|
1662
1663
|
}
|
|
1663
|
-
this.set(this.h1 + c + u | 0, this.h2 + h +
|
|
1664
|
+
this.set(this.h1 + c + u | 0, this.h2 + h + y | 0, this.h3 + d + r | 0, this.h4 + o + a | 0, this.h0 + i + l | 0);
|
|
1664
1665
|
}
|
|
1665
1666
|
roundClean() {
|
|
1666
|
-
S(
|
|
1667
|
+
S(Q);
|
|
1667
1668
|
}
|
|
1668
1669
|
destroy() {
|
|
1669
1670
|
this.destroyed = !0, S(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1670
1671
|
}
|
|
1671
1672
|
}
|
|
1672
|
-
const
|
|
1673
|
-
function
|
|
1674
|
-
return t ? { h: Number(e &
|
|
1673
|
+
const on = /* @__PURE__ */ ct(() => new sn()), Y = /* @__PURE__ */ BigInt(2 ** 32 - 1), _t = /* @__PURE__ */ BigInt(32);
|
|
1674
|
+
function rn(e, t = !1) {
|
|
1675
|
+
return t ? { h: Number(e & Y), l: Number(e >> _t & Y) } : { h: Number(e >> _t & Y) | 0, l: Number(e & Y) | 0 };
|
|
1675
1676
|
}
|
|
1676
|
-
function
|
|
1677
|
+
function oe(e, t = !1) {
|
|
1677
1678
|
const n = e.length;
|
|
1678
1679
|
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
1679
1680
|
for (let r = 0; r < n; r++) {
|
|
1680
|
-
const { h: i, l: a } =
|
|
1681
|
+
const { h: i, l: a } = rn(e[r], t);
|
|
1681
1682
|
[s[r], o[r]] = [i, a];
|
|
1682
1683
|
}
|
|
1683
1684
|
return [s, o];
|
|
1684
1685
|
}
|
|
1685
|
-
const
|
|
1686
|
+
const Rt = (e, t, n) => e >>> n, Wt = (e, t, n) => e << 32 - n | t >>> n, N = (e, t, n) => e >>> n | t << 32 - n, X = (e, t, n) => e << 32 - n | t >>> n, tt = (e, t, n) => e << 64 - n | t >>> n - 32, et = (e, t, n) => e >>> n - 32 | t << 64 - n, an = (e, t, n) => e << n | t >>> 32 - n, cn = (e, t, n) => t << n | e >>> 32 - n, un = (e, t, n) => t << n - 32 | e >>> 64 - n, ln = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1686
1687
|
function F(e, t, n, s) {
|
|
1687
1688
|
const o = (t >>> 0) + (s >>> 0);
|
|
1688
1689
|
return { h: e + n + (o / 2 ** 32 | 0) | 0, l: o | 0 };
|
|
1689
1690
|
}
|
|
1690
|
-
const
|
|
1691
|
+
const hn = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), dn = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, fn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), pn = (e, t, n, s, o) => t + n + s + o + (e / 2 ** 32 | 0) | 0, bn = (e, t, n, s, o) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (o >>> 0), gn = (e, t, n, s, o, r) => t + n + s + o + r + (e / 2 ** 32 | 0) | 0, yn = /* @__PURE__ */ Uint32Array.from([
|
|
1691
1692
|
1116352408,
|
|
1692
1693
|
1899447441,
|
|
1693
1694
|
3049323471,
|
|
@@ -1753,7 +1754,7 @@ const ln = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), hn = (e, t, n, s) =>
|
|
|
1753
1754
|
3204031479,
|
|
1754
1755
|
3329325298
|
|
1755
1756
|
]), L = /* @__PURE__ */ new Uint32Array(64);
|
|
1756
|
-
class
|
|
1757
|
+
class xn extends Pt {
|
|
1757
1758
|
constructor(t) {
|
|
1758
1759
|
super(64, t, 8, !1);
|
|
1759
1760
|
}
|
|
@@ -1769,13 +1770,13 @@ class gn extends mt {
|
|
|
1769
1770
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1770
1771
|
L[u] = t.getUint32(n, !1);
|
|
1771
1772
|
for (let u = 16; u < 64; u++) {
|
|
1772
|
-
const d = L[u - 15],
|
|
1773
|
-
L[u] = x + L[u - 7] +
|
|
1773
|
+
const d = L[u - 15], y = L[u - 2], b = A(d, 7) ^ A(d, 18) ^ d >>> 3, x = A(y, 17) ^ A(y, 19) ^ y >>> 10;
|
|
1774
|
+
L[u] = x + L[u - 7] + b + L[u - 16] | 0;
|
|
1774
1775
|
}
|
|
1775
1776
|
let { A: s, B: o, C: r, D: i, E: a, F: c, G: l, H: h } = this;
|
|
1776
1777
|
for (let u = 0; u < 64; u++) {
|
|
1777
|
-
const d = A(a, 6) ^ A(a, 11) ^ A(a, 25),
|
|
1778
|
-
h = l, l = c, c = a, a = i +
|
|
1778
|
+
const d = A(a, 6) ^ A(a, 11) ^ A(a, 25), y = h + d + ze(a, c, l) + yn[u] + L[u] | 0, x = (A(s, 2) ^ A(s, 13) ^ A(s, 22)) + Ze(s, o, r) | 0;
|
|
1779
|
+
h = l, l = c, c = a, a = i + y | 0, i = r, r = o, o = s, s = y + x | 0;
|
|
1779
1780
|
}
|
|
1780
1781
|
s = s + this.A | 0, o = o + this.B | 0, r = r + 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, o, r, i, a, c, l, h);
|
|
1781
1782
|
}
|
|
@@ -1786,7 +1787,7 @@ class gn extends mt {
|
|
|
1786
1787
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), S(this.buffer);
|
|
1787
1788
|
}
|
|
1788
1789
|
}
|
|
1789
|
-
class
|
|
1790
|
+
class wn extends xn {
|
|
1790
1791
|
constructor() {
|
|
1791
1792
|
super(32);
|
|
1792
1793
|
// We cannot use array here since array allows indexing by variable
|
|
@@ -1801,7 +1802,7 @@ class xn extends gn {
|
|
|
1801
1802
|
p(this, "H", O[7] | 0);
|
|
1802
1803
|
}
|
|
1803
1804
|
}
|
|
1804
|
-
const
|
|
1805
|
+
const re = oe([
|
|
1805
1806
|
"0x428a2f98d728ae22",
|
|
1806
1807
|
"0x7137449123ef65cd",
|
|
1807
1808
|
"0xb5c0fbcfec4d3b2f",
|
|
@@ -1882,35 +1883,35 @@ const se = ne([
|
|
|
1882
1883
|
"0x597f299cfc657e2a",
|
|
1883
1884
|
"0x5fcb6fab3ad6faec",
|
|
1884
1885
|
"0x6c44198c4a475817"
|
|
1885
|
-
].map((e) => BigInt(e))),
|
|
1886
|
-
class
|
|
1886
|
+
].map((e) => BigInt(e))), mn = re[0], Pn = re[1], _ = /* @__PURE__ */ new Uint32Array(80), R = /* @__PURE__ */ new Uint32Array(80);
|
|
1887
|
+
class Tn extends Pt {
|
|
1887
1888
|
constructor(t) {
|
|
1888
1889
|
super(128, t, 16, !1);
|
|
1889
1890
|
}
|
|
1890
1891
|
// prettier-ignore
|
|
1891
1892
|
get() {
|
|
1892
|
-
const { Ah: t, Al: n, Bh: s, Bl: o, Ch: r, Cl: i, Dh: a, Dl: c, Eh: l, El: h, Fh: u, Fl: d, Gh:
|
|
1893
|
-
return [t, n, s, o, r, i, a, c, l, h, u, d,
|
|
1893
|
+
const { Ah: t, Al: n, Bh: s, Bl: o, Ch: r, Cl: i, Dh: a, Dl: c, Eh: l, El: h, Fh: u, Fl: d, Gh: y, Gl: b, Hh: x, Hl: P } = this;
|
|
1894
|
+
return [t, n, s, o, r, i, a, c, l, h, u, d, y, b, x, P];
|
|
1894
1895
|
}
|
|
1895
1896
|
// prettier-ignore
|
|
1896
|
-
set(t, n, s, o, r, i, a, c, l, h, u, d,
|
|
1897
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = o | 0, this.Ch = r | 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 =
|
|
1897
|
+
set(t, n, s, o, r, i, a, c, l, h, u, d, y, b, x, P) {
|
|
1898
|
+
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = o | 0, this.Ch = r | 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 = y | 0, this.Gl = b | 0, this.Hh = x | 0, this.Hl = P | 0;
|
|
1898
1899
|
}
|
|
1899
1900
|
process(t, n) {
|
|
1900
1901
|
for (let f = 0; f < 16; f++, n += 4)
|
|
1901
1902
|
_[f] = t.getUint32(n), R[f] = t.getUint32(n += 4);
|
|
1902
1903
|
for (let f = 16; f < 80; f++) {
|
|
1903
|
-
const w = _[f - 15] | 0, v = R[f - 15] | 0, T = N(w, v, 1) ^ N(w, v, 8) ^
|
|
1904
|
-
_[f] =
|
|
1904
|
+
const w = _[f - 15] | 0, v = R[f - 15] | 0, T = N(w, v, 1) ^ N(w, v, 8) ^ Rt(w, v, 7), H = X(w, v, 1) ^ X(w, v, 8) ^ Wt(w, v, 7), I = _[f - 2] | 0, E = R[f - 2] | 0, C = N(I, E, 19) ^ tt(I, E, 61) ^ Rt(I, E, 6), M = X(I, E, 19) ^ et(I, E, 61) ^ Wt(I, E, 6), $ = fn(H, M, R[f - 7], R[f - 16]), ut = pn($, T, C, _[f - 7], _[f - 16]);
|
|
1905
|
+
_[f] = ut | 0, R[f] = $ | 0;
|
|
1905
1906
|
}
|
|
1906
|
-
let { Ah: s, Al: o, Bh: r, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh:
|
|
1907
|
+
let { Ah: s, Al: o, Bh: r, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh: y, Fl: b, Gh: x, Gl: P, Hh: m, Hl: g } = this;
|
|
1907
1908
|
for (let f = 0; f < 80; f++) {
|
|
1908
|
-
const w = N(u, d, 14) ^ N(u, d, 18) ^ tt(u, d, 41), v = X(u, d, 14) ^ X(u, d, 18) ^ et(u, d, 41), T = u &
|
|
1909
|
-
m = x | 0,
|
|
1910
|
-
const
|
|
1911
|
-
s =
|
|
1909
|
+
const w = N(u, d, 14) ^ N(u, d, 18) ^ tt(u, d, 41), v = X(u, d, 14) ^ X(u, d, 18) ^ et(u, d, 41), T = u & y ^ ~u & x, H = d & b ^ ~d & P, I = bn(g, v, H, Pn[f], R[f]), E = gn(I, m, w, T, mn[f], _[f]), C = I | 0, M = N(s, o, 28) ^ tt(s, o, 34) ^ tt(s, o, 39), $ = X(s, o, 28) ^ et(s, o, 34) ^ et(s, o, 39), ut = s & r ^ s & a ^ r & a, de = o & i ^ o & c ^ i & c;
|
|
1910
|
+
m = x | 0, g = P | 0, x = y | 0, P = b | 0, y = u | 0, b = d | 0, { h: u, l: d } = F(l | 0, h | 0, E | 0, C | 0), l = a | 0, h = c | 0, a = r | 0, c = i | 0, r = s | 0, i = o | 0;
|
|
1911
|
+
const vt = hn(C, $, de);
|
|
1912
|
+
s = dn(vt, E, M, ut), o = vt | 0;
|
|
1912
1913
|
}
|
|
1913
|
-
({ h: s, l: o } = F(this.Ah | 0, this.Al | 0, s | 0, o | 0)), { h: r, l: i } = F(this.Bh | 0, this.Bl | 0, r | 0, i | 0), { h: a, l: c } = F(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = F(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: d } = F(this.Eh | 0, this.El | 0, u | 0, d | 0), { h:
|
|
1914
|
+
({ h: s, l: o } = F(this.Ah | 0, this.Al | 0, s | 0, o | 0)), { h: r, l: i } = F(this.Bh | 0, this.Bl | 0, r | 0, i | 0), { h: a, l: c } = F(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = F(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: d } = F(this.Eh | 0, this.El | 0, u | 0, d | 0), { h: y, l: b } = F(this.Fh | 0, this.Fl | 0, y | 0, b | 0), { h: x, l: P } = F(this.Gh | 0, this.Gl | 0, x | 0, P | 0), { h: m, l: g } = F(this.Hh | 0, this.Hl | 0, m | 0, g | 0), this.set(s, o, r, i, a, c, l, h, u, d, y, b, x, P, m, g);
|
|
1914
1915
|
}
|
|
1915
1916
|
roundClean() {
|
|
1916
1917
|
S(_, R);
|
|
@@ -1919,7 +1920,7 @@ class Pn extends mt {
|
|
|
1919
1920
|
S(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1920
1921
|
}
|
|
1921
1922
|
}
|
|
1922
|
-
class
|
|
1923
|
+
class vn extends Tn {
|
|
1923
1924
|
constructor() {
|
|
1924
1925
|
super(64);
|
|
1925
1926
|
p(this, "Ah", k[0] | 0);
|
|
@@ -1940,34 +1941,34 @@ class Tn extends Pn {
|
|
|
1940
1941
|
p(this, "Hl", k[15] | 0);
|
|
1941
1942
|
}
|
|
1942
1943
|
}
|
|
1943
|
-
const
|
|
1944
|
-
() => new
|
|
1945
|
-
/* @__PURE__ */
|
|
1946
|
-
),
|
|
1947
|
-
() => new
|
|
1948
|
-
/* @__PURE__ */
|
|
1949
|
-
),
|
|
1944
|
+
const kn = /* @__PURE__ */ ct(
|
|
1945
|
+
() => new wn(),
|
|
1946
|
+
/* @__PURE__ */ Jt(1)
|
|
1947
|
+
), ie = /* @__PURE__ */ ct(
|
|
1948
|
+
() => new vn(),
|
|
1949
|
+
/* @__PURE__ */ Jt(3)
|
|
1950
|
+
), Hn = BigInt(0), z = BigInt(1), In = BigInt(2), En = BigInt(7), Bn = BigInt(256), Sn = BigInt(113), ae = [], ce = [], ue = [];
|
|
1950
1951
|
for (let e = 0, t = z, n = 1, s = 0; e < 24; e++) {
|
|
1951
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
1952
|
-
let o =
|
|
1952
|
+
[n, s] = [s, (2 * n + 3 * s) % 5], ae.push(2 * (5 * s + n)), ce.push((e + 1) * (e + 2) / 2 % 64);
|
|
1953
|
+
let o = Hn;
|
|
1953
1954
|
for (let r = 0; r < 7; r++)
|
|
1954
|
-
t = (t << z ^ (t >>
|
|
1955
|
-
|
|
1955
|
+
t = (t << z ^ (t >> En) * Sn) % Bn, t & In && (o ^= z << (z << BigInt(r)) - z);
|
|
1956
|
+
ue.push(o);
|
|
1956
1957
|
}
|
|
1957
|
-
const
|
|
1958
|
-
function
|
|
1958
|
+
const le = oe(ue, !0), An = le[0], Un = le[1], Vt = (e, t, n) => n > 32 ? un(e, t, n) : an(e, t, n), Dt = (e, t, n) => n > 32 ? ln(e, t, n) : cn(e, t, n);
|
|
1959
|
+
function Fn(e, t = 24) {
|
|
1959
1960
|
const n = new Uint32Array(10);
|
|
1960
1961
|
for (let s = 24 - t; s < 24; s++) {
|
|
1961
1962
|
for (let i = 0; i < 10; i++)
|
|
1962
1963
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1963
1964
|
for (let i = 0; i < 10; i += 2) {
|
|
1964
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u =
|
|
1965
|
-
for (let
|
|
1966
|
-
e[i +
|
|
1965
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u = Vt(l, h, 1) ^ n[a], d = Dt(l, h, 1) ^ n[a + 1];
|
|
1966
|
+
for (let y = 0; y < 50; y += 10)
|
|
1967
|
+
e[i + y] ^= u, e[i + y + 1] ^= d;
|
|
1967
1968
|
}
|
|
1968
1969
|
let o = e[2], r = e[3];
|
|
1969
1970
|
for (let i = 0; i < 24; i++) {
|
|
1970
|
-
const a =
|
|
1971
|
+
const a = ce[i], c = Vt(o, r, a), l = Dt(o, r, a), h = ae[i];
|
|
1971
1972
|
o = e[h], r = e[h + 1], e[h] = c, e[h + 1] = l;
|
|
1972
1973
|
}
|
|
1973
1974
|
for (let i = 0; i < 50; i += 10) {
|
|
@@ -1976,11 +1977,11 @@ function Cn(e, t = 24) {
|
|
|
1976
1977
|
for (let a = 0; a < 10; a++)
|
|
1977
1978
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1978
1979
|
}
|
|
1979
|
-
e[0] ^=
|
|
1980
|
+
e[0] ^= An[s], e[1] ^= Un[s];
|
|
1980
1981
|
}
|
|
1981
1982
|
S(n);
|
|
1982
1983
|
}
|
|
1983
|
-
class
|
|
1984
|
+
class Tt {
|
|
1984
1985
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1985
1986
|
constructor(t, n, s, o = !1, r = 24) {
|
|
1986
1987
|
p(this, "state");
|
|
@@ -2002,7 +2003,7 @@ class Pt {
|
|
|
2002
2003
|
return this._cloneInto();
|
|
2003
2004
|
}
|
|
2004
2005
|
keccak() {
|
|
2005
|
-
|
|
2006
|
+
$t(this.state32), Fn(this.state32, this.rounds), $t(this.state32), this.posOut = 0, this.pos = 0;
|
|
2006
2007
|
}
|
|
2007
2008
|
update(t) {
|
|
2008
2009
|
G(this), D(t);
|
|
@@ -2041,7 +2042,7 @@ class Pt {
|
|
|
2041
2042
|
return V(t), this.xofInto(new Uint8Array(t));
|
|
2042
2043
|
}
|
|
2043
2044
|
digestInto(t) {
|
|
2044
|
-
if (
|
|
2045
|
+
if (Zt(t, this), this.finished)
|
|
2045
2046
|
throw new Error("digest() was already called");
|
|
2046
2047
|
return this.writeInto(t), this.destroy(), t;
|
|
2047
2048
|
}
|
|
@@ -2053,52 +2054,52 @@ class Pt {
|
|
|
2053
2054
|
}
|
|
2054
2055
|
_cloneInto(t) {
|
|
2055
2056
|
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
2056
|
-
return t || (t = new
|
|
2057
|
+
return t || (t = new Tt(n, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
2057
2058
|
}
|
|
2058
2059
|
}
|
|
2059
|
-
const
|
|
2060
|
-
function
|
|
2061
|
-
|
|
2062
|
-
const o =
|
|
2060
|
+
const Cn = (e, t, n, s = {}) => ct(() => new Tt(t, e, n), s), $n = /* @__PURE__ */ Cn(1, 136, 32);
|
|
2061
|
+
function On(e, t, n, s) {
|
|
2062
|
+
zt(e);
|
|
2063
|
+
const o = je({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
2063
2064
|
if (V(r, "c"), V(i, "dkLen"), V(a, "asyncTick"), r < 1)
|
|
2064
2065
|
throw new Error("iterations (c) must be >= 1");
|
|
2065
|
-
const c =
|
|
2066
|
+
const c = Ot(t, "password"), l = Ot(n, "salt"), h = new Uint8Array(i), u = mt.create(e, c), d = u._cloneInto().update(l);
|
|
2066
2067
|
return { c: r, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
|
|
2067
2068
|
}
|
|
2068
|
-
function
|
|
2069
|
+
function Ln(e, t, n, s, o) {
|
|
2069
2070
|
return e.destroy(), t.destroy(), s && s.destroy(), S(o), n;
|
|
2070
2071
|
}
|
|
2071
|
-
function
|
|
2072
|
-
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: c } =
|
|
2072
|
+
function _n(e, t, n, s) {
|
|
2073
|
+
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: c } = On(e, t, n, s);
|
|
2073
2074
|
let l;
|
|
2074
2075
|
const h = new Uint8Array(4), u = rt(h), d = new Uint8Array(a.outputLen);
|
|
2075
|
-
for (let
|
|
2076
|
-
const x = i.subarray(
|
|
2077
|
-
u.setInt32(0,
|
|
2076
|
+
for (let y = 1, b = 0; b < r; y++, b += a.outputLen) {
|
|
2077
|
+
const x = i.subarray(b, b + a.outputLen);
|
|
2078
|
+
u.setInt32(0, y, !1), (l = c._cloneInto(l)).update(h).digestInto(d), x.set(d.subarray(0, x.length));
|
|
2078
2079
|
for (let P = 1; P < o; P++) {
|
|
2079
2080
|
a._cloneInto(l).update(d).digestInto(d);
|
|
2080
2081
|
for (let m = 0; m < x.length; m++)
|
|
2081
2082
|
x[m] ^= d[m];
|
|
2082
2083
|
}
|
|
2083
2084
|
}
|
|
2084
|
-
return
|
|
2085
|
+
return Ln(a, c, i, l, d);
|
|
2085
2086
|
}
|
|
2086
|
-
function
|
|
2087
|
+
function he(e) {
|
|
2087
2088
|
if (typeof e != "string")
|
|
2088
2089
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
2089
2090
|
return e.normalize("NFKD");
|
|
2090
2091
|
}
|
|
2091
|
-
function
|
|
2092
|
-
const t =
|
|
2092
|
+
function Rn(e) {
|
|
2093
|
+
const t = he(e), n = t.split(" ");
|
|
2093
2094
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
2094
2095
|
throw new Error("Invalid mnemonic");
|
|
2095
2096
|
return { nfkd: t, words: n };
|
|
2096
2097
|
}
|
|
2097
|
-
const
|
|
2098
|
-
function
|
|
2099
|
-
return
|
|
2098
|
+
const Wn = (e) => he("mnemonic" + e);
|
|
2099
|
+
function Vn(e, t = "") {
|
|
2100
|
+
return _n(ie, Rn(e).nfkd, Wn(t), { c: 2048, dkLen: 64 });
|
|
2100
2101
|
}
|
|
2101
|
-
const
|
|
2102
|
+
const Dn = 508, Mt = 16, nt = 32, st = 64, Kt = 5, Mn = 4;
|
|
2102
2103
|
function Z(...e) {
|
|
2103
2104
|
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
2104
2105
|
let s = 0;
|
|
@@ -2106,25 +2107,25 @@ function Z(...e) {
|
|
|
2106
2107
|
n.set(o, s), s += o.length;
|
|
2107
2108
|
return n;
|
|
2108
2109
|
}
|
|
2109
|
-
function
|
|
2110
|
+
function ft(e) {
|
|
2110
2111
|
return new TextEncoder().encode(e);
|
|
2111
2112
|
}
|
|
2112
|
-
function
|
|
2113
|
-
const t = new Uint8Array(
|
|
2113
|
+
function pt(e) {
|
|
2114
|
+
const t = new Uint8Array(Mn);
|
|
2114
2115
|
return new DataView(t.buffer).setUint32(0, e.length, !1), Z(t, e);
|
|
2115
2116
|
}
|
|
2116
|
-
function
|
|
2117
|
-
return
|
|
2117
|
+
function bt(e, t) {
|
|
2118
|
+
return mt(ie, e, t);
|
|
2118
2119
|
}
|
|
2119
|
-
function
|
|
2120
|
-
return
|
|
2120
|
+
function Nt(e) {
|
|
2121
|
+
return on(kn(e));
|
|
2121
2122
|
}
|
|
2122
|
-
const
|
|
2123
|
+
const yt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2123
2124
|
function Kn(e) {
|
|
2124
|
-
const t =
|
|
2125
|
+
const t = Vn(e), n = new Uint8Array(t);
|
|
2125
2126
|
return t.fill(0), n;
|
|
2126
2127
|
}
|
|
2127
|
-
async function
|
|
2128
|
+
async function Nn(e, t, n, s) {
|
|
2128
2129
|
if (e.length !== st)
|
|
2129
2130
|
throw new Error(
|
|
2130
2131
|
`WOTS seed must be ${st} bytes, got ${e.length}`
|
|
@@ -2133,36 +2134,36 @@ async function Mn(e, t, n, s) {
|
|
|
2133
2134
|
const o = e.slice(nt, st), r = e.slice(0, nt), i = [o, r];
|
|
2134
2135
|
try {
|
|
2135
2136
|
const a = Z(
|
|
2136
|
-
ft(
|
|
2137
|
-
ft(
|
|
2138
|
-
ft(
|
|
2137
|
+
pt(ft(t)),
|
|
2138
|
+
pt(ft(n)),
|
|
2139
|
+
pt(ft(s))
|
|
2139
2140
|
), c = Z(r, a);
|
|
2140
2141
|
i.push(c);
|
|
2141
|
-
const l =
|
|
2142
|
+
const l = bt(o, c);
|
|
2142
2143
|
i.push(l);
|
|
2143
2144
|
const h = l.slice(0, nt), u = l.slice(nt, st);
|
|
2144
2145
|
i.push(h, u);
|
|
2145
|
-
const d = [],
|
|
2146
|
+
const d = [], y = [], b = [], x = [];
|
|
2146
2147
|
let P = !1;
|
|
2147
2148
|
try {
|
|
2148
|
-
for (let m = 0; m <
|
|
2149
|
-
const
|
|
2150
|
-
|
|
2151
|
-
const f = new Uint8Array(
|
|
2149
|
+
for (let m = 0; m < Dn; m++) {
|
|
2150
|
+
const g = new Uint8Array(Kt);
|
|
2151
|
+
g[0] = 0, new DataView(g.buffer).setUint32(1, m, !1);
|
|
2152
|
+
const f = new Uint8Array(Kt);
|
|
2152
2153
|
f[0] = 1, new DataView(f.buffer).setUint32(1, m, !1);
|
|
2153
|
-
const w = Z(h,
|
|
2154
|
+
const w = Z(h, g), v = Z(h, f), T = bt(u, w), H = bt(u, v);
|
|
2154
2155
|
try {
|
|
2155
|
-
const I = T.slice(0,
|
|
2156
|
-
d.push(I),
|
|
2156
|
+
const I = T.slice(0, Mt), E = H.slice(0, Mt);
|
|
2157
|
+
d.push(I), y.push(E), b.push(Nt(I)), x.push(Nt(E));
|
|
2157
2158
|
} finally {
|
|
2158
2159
|
w.fill(0), v.fill(0), T.fill(0), H.fill(0);
|
|
2159
2160
|
}
|
|
2160
2161
|
}
|
|
2161
|
-
return P = !0, { falsePreimages: d, truePreimages:
|
|
2162
|
+
return P = !0, { falsePreimages: d, truePreimages: y, falseHashes: b, trueHashes: x };
|
|
2162
2163
|
} finally {
|
|
2163
2164
|
if (!P) {
|
|
2164
2165
|
for (const m of d) m.fill(0);
|
|
2165
|
-
for (const m of
|
|
2166
|
+
for (const m of y) m.fill(0);
|
|
2166
2167
|
}
|
|
2167
2168
|
}
|
|
2168
2169
|
} finally {
|
|
@@ -2170,13 +2171,13 @@ async function Mn(e, t, n, s) {
|
|
|
2170
2171
|
a.fill(0);
|
|
2171
2172
|
}
|
|
2172
2173
|
}
|
|
2173
|
-
function
|
|
2174
|
+
function us(e) {
|
|
2174
2175
|
return {
|
|
2175
|
-
false_list: e.falseHashes.map(
|
|
2176
|
-
true_list: e.trueHashes.map(
|
|
2176
|
+
false_list: e.falseHashes.map(yt),
|
|
2177
|
+
true_list: e.trueHashes.map(yt)
|
|
2177
2178
|
};
|
|
2178
2179
|
}
|
|
2179
|
-
function
|
|
2180
|
+
function Xn(e) {
|
|
2180
2181
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2181
2182
|
throw new Error(
|
|
2182
2183
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
@@ -2187,20 +2188,20 @@ function Nn(e) {
|
|
|
2187
2188
|
s.set(i, o), o += t;
|
|
2188
2189
|
for (const i of e.trueHashes)
|
|
2189
2190
|
s.set(i, o), o += t;
|
|
2190
|
-
const r =
|
|
2191
|
-
return `0x${
|
|
2191
|
+
const r = $n(s);
|
|
2192
|
+
return `0x${yt(r)}`;
|
|
2192
2193
|
}
|
|
2193
|
-
async function
|
|
2194
|
+
async function ls(e, t, n, s) {
|
|
2194
2195
|
const o = Kn(e);
|
|
2195
2196
|
try {
|
|
2196
|
-
const r = await
|
|
2197
|
+
const r = await Nn(
|
|
2197
2198
|
o,
|
|
2198
2199
|
t,
|
|
2199
2200
|
n,
|
|
2200
2201
|
s
|
|
2201
2202
|
);
|
|
2202
2203
|
try {
|
|
2203
|
-
return
|
|
2204
|
+
return Xn(r);
|
|
2204
2205
|
} finally {
|
|
2205
2206
|
for (const i of r.falsePreimages) i.fill(0);
|
|
2206
2207
|
for (const i of r.truePreimages) i.fill(0);
|
|
@@ -2209,41 +2210,41 @@ async function us(e, t, n, s) {
|
|
|
2209
2210
|
o.fill(0);
|
|
2210
2211
|
}
|
|
2211
2212
|
}
|
|
2212
|
-
function
|
|
2213
|
+
function hs(e) {
|
|
2213
2214
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2214
2215
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2215
2216
|
}
|
|
2216
2217
|
export {
|
|
2217
|
-
|
|
2218
|
+
hs as A,
|
|
2218
2219
|
ot as B,
|
|
2219
2220
|
q as C,
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2221
|
+
Le as M,
|
|
2222
|
+
as as P,
|
|
2223
|
+
Qn as a,
|
|
2224
|
+
Fe as b,
|
|
2225
|
+
dt as c,
|
|
2226
|
+
Ce as d,
|
|
2227
|
+
gt as e,
|
|
2228
|
+
cs as f,
|
|
2228
2229
|
Yn as g,
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2230
|
+
ss as h,
|
|
2231
|
+
es as i,
|
|
2232
|
+
ns as j,
|
|
2233
|
+
os as k,
|
|
2234
|
+
ts as l,
|
|
2235
|
+
Re as m,
|
|
2236
|
+
We as n,
|
|
2236
2237
|
j as o,
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2238
|
+
_e as p,
|
|
2239
|
+
wt as q,
|
|
2240
|
+
rs as r,
|
|
2241
|
+
Ue as s,
|
|
2242
|
+
is as t,
|
|
2243
|
+
K as u,
|
|
2243
2244
|
Kn as v,
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2245
|
+
Nn as w,
|
|
2246
|
+
us as x,
|
|
2247
|
+
Xn as y,
|
|
2248
|
+
ls as z
|
|
2248
2249
|
};
|
|
2249
|
-
//# sourceMappingURL=errors-
|
|
2250
|
+
//# sourceMappingURL=errors-BeFfs5_J.js.map
|