@babylonlabs-io/ts-sdk 0.16.1 → 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-Ld-2tiK3.js → errors-BeFfs5_J.js} +327 -345
- 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/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-Bk7eb5h3.cjs +0 -2
- package/dist/errors-Bk7eb5h3.cjs.map +0 -1
- package/dist/errors-Ld-2tiK3.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var fe = Object.defineProperty;
|
|
2
2
|
var pe = (e, t, n) => t in e ? fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var p = (e, t, n) => pe(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
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 lt, http as ht, encodeFunctionData as Ht, zeroAddress as
|
|
8
|
-
import { P as xe, y as
|
|
9
|
-
import { deriveVaultId as
|
|
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
10
|
function Ue(e, t, n, s) {
|
|
11
11
|
if (!Number.isInteger(s) || s < 1)
|
|
12
12
|
throw new Error(
|
|
@@ -16,7 +16,7 @@ function Ue(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 Ue(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 * xe, u = s *
|
|
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,11 +47,11 @@ function Ue(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
|
|
50
|
+
function Qn(e) {
|
|
51
51
|
return e > Xt;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
53
|
+
function Yn() {
|
|
54
|
+
return me;
|
|
55
55
|
}
|
|
56
56
|
function dt(e) {
|
|
57
57
|
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
@@ -71,7 +71,7 @@ function Fe(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
|
|
74
|
+
function Ce(e, t) {
|
|
75
75
|
const n = W.from(e.scriptPubKey, "hex"), s = Fe(n);
|
|
76
76
|
switch (s) {
|
|
77
77
|
case ot.P2WPKH:
|
|
@@ -110,7 +110,7 @@ function $e(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,11 +122,11 @@ function bt(e, t) {
|
|
|
122
122
|
}))
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
const
|
|
125
|
+
const $e = 21e6 * 1e8, Ft = 3e4;
|
|
126
126
|
async function at(e, t) {
|
|
127
127
|
const n = new AbortController(), s = setTimeout(
|
|
128
128
|
() => n.abort(),
|
|
129
|
-
|
|
129
|
+
Ft
|
|
130
130
|
), o = [n.signal, t == null ? void 0 : t.signal].filter(
|
|
131
131
|
Boolean
|
|
132
132
|
);
|
|
@@ -137,21 +137,21 @@ async function at(e, t) {
|
|
|
137
137
|
});
|
|
138
138
|
} catch (r) {
|
|
139
139
|
throw clearTimeout(s), r != null && typeof r == "object" && "name" in r && r.name === "AbortError" ? new Error(
|
|
140
|
-
`Mempool API request timed out after ${
|
|
140
|
+
`Mempool API request timed out after ${Ft}ms: ${e}`
|
|
141
141
|
) : r;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const qt = 1e4;
|
|
145
145
|
function Gt(e) {
|
|
146
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
146
|
+
return Number.isInteger(e) && e > 0 && e <= $e;
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function Oe(e) {
|
|
149
149
|
return Number.isInteger(e) && e > 0 && e <= qt;
|
|
150
150
|
}
|
|
151
151
|
function jt(e, t) {
|
|
152
152
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
153
153
|
}
|
|
154
|
-
const
|
|
154
|
+
const Le = {
|
|
155
155
|
mainnet: "https://mempool.space/api",
|
|
156
156
|
testnet: "https://mempool.space/testnet/api",
|
|
157
157
|
signet: "https://mempool.space/signet/api"
|
|
@@ -171,7 +171,7 @@ async function it(e, t) {
|
|
|
171
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");
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
async function
|
|
174
|
+
async function _e(e, t) {
|
|
175
175
|
try {
|
|
176
176
|
const n = await at(`${t}/tx`, {
|
|
177
177
|
method: "POST",
|
|
@@ -197,10 +197,10 @@ async function Re(e, t) {
|
|
|
197
197
|
throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
async function
|
|
200
|
+
async function Re(e, t) {
|
|
201
201
|
return it(`${t}/tx/${e}`);
|
|
202
202
|
}
|
|
203
|
-
async function
|
|
203
|
+
async function ts(e, t) {
|
|
204
204
|
try {
|
|
205
205
|
const n = await at(`${t}/tx/${e}/hex`);
|
|
206
206
|
if (!n.ok) {
|
|
@@ -214,8 +214,8 @@ async function es(e, t) {
|
|
|
214
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`);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
async function
|
|
218
|
-
const s = await
|
|
217
|
+
async function We(e, t, n) {
|
|
218
|
+
const s = await Re(e, n);
|
|
219
219
|
if (!jt(t, s.vout.length))
|
|
220
220
|
throw new Error(
|
|
221
221
|
`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
|
|
@@ -230,7 +230,7 @@ async function Ve(e, t, n) {
|
|
|
230
230
|
scriptPubKey: o.scriptpubkey
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
|
-
async function
|
|
233
|
+
async function es(e, t) {
|
|
234
234
|
try {
|
|
235
235
|
const n = await it(`${t}/address/${e}/utxo`), s = await it(`${t}/v1/validate-address/${e}`);
|
|
236
236
|
if (!s.isvalid)
|
|
@@ -260,13 +260,13 @@ async function ns(e, t) {
|
|
|
260
260
|
);
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
function
|
|
264
|
-
return
|
|
263
|
+
function ns(e) {
|
|
264
|
+
return Le[e];
|
|
265
265
|
}
|
|
266
|
-
async function
|
|
266
|
+
async function ss(e, t) {
|
|
267
267
|
return it(`${t}/address/${e}/txs`);
|
|
268
268
|
}
|
|
269
|
-
async function
|
|
269
|
+
async function os(e) {
|
|
270
270
|
const t = await at(`${e}/v1/fees/recommended`);
|
|
271
271
|
if (!t.ok)
|
|
272
272
|
throw new Error(
|
|
@@ -280,7 +280,7 @@ async function rs(e) {
|
|
|
280
280
|
"minimumFee"
|
|
281
281
|
];
|
|
282
282
|
for (const o of s)
|
|
283
|
-
if (!
|
|
283
|
+
if (!Oe(n[o]))
|
|
284
284
|
throw new Error(
|
|
285
285
|
`Invalid fee rate ${o}=${n[o]} from mempool API: expected a positive number ≤ ${qt}`
|
|
286
286
|
);
|
|
@@ -496,7 +496,7 @@ const j = [
|
|
|
496
496
|
},
|
|
497
497
|
{
|
|
498
498
|
type: "function",
|
|
499
|
-
name: "
|
|
499
|
+
name: "getBtcVaultBasicInfo",
|
|
500
500
|
inputs: [
|
|
501
501
|
{
|
|
502
502
|
name: "vaultId",
|
|
@@ -505,30 +505,13 @@ const j = [
|
|
|
505
505
|
}
|
|
506
506
|
],
|
|
507
507
|
outputs: [
|
|
508
|
-
{
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
{ name: "depositorSignedPeginTx", type: "bytes", internalType: "bytes" },
|
|
516
|
-
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
517
|
-
{ name: "vaultProvider", type: "address", internalType: "address" },
|
|
518
|
-
{ name: "status", type: "uint8", internalType: "enum IBTCVaultRegistry.BTCVaultStatus" },
|
|
519
|
-
{ name: "applicationEntryPoint", type: "address", internalType: "address" },
|
|
520
|
-
{ name: "universalChallengersVersion", type: "uint16", internalType: "uint16" },
|
|
521
|
-
{ name: "appVaultKeepersVersion", type: "uint16", internalType: "uint16" },
|
|
522
|
-
{ name: "offchainParamsVersion", type: "uint16", internalType: "uint16" },
|
|
523
|
-
{ name: "createdAt", type: "uint256", internalType: "uint256" },
|
|
524
|
-
{ name: "verifiedAt", type: "uint256", internalType: "uint256" },
|
|
525
|
-
{ name: "depositorWotsPkHash", type: "bytes32", internalType: "bytes32" },
|
|
526
|
-
{ name: "hashlock", type: "bytes32", internalType: "bytes32" },
|
|
527
|
-
{ name: "htlcVout", type: "uint8", internalType: "uint8" },
|
|
528
|
-
{ name: "depositorPopSignature", type: "bytes", internalType: "bytes" },
|
|
529
|
-
{ name: "prePeginTxHash", type: "bytes32", internalType: "bytes32" }
|
|
530
|
-
]
|
|
531
|
-
}
|
|
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" }
|
|
532
515
|
],
|
|
533
516
|
stateMutability: "view"
|
|
534
517
|
},
|
|
@@ -613,7 +596,7 @@ const j = [
|
|
|
613
596
|
// InvalidPeginFee(uint256,uint256)
|
|
614
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."
|
|
615
598
|
};
|
|
616
|
-
function
|
|
599
|
+
function wt(e) {
|
|
617
600
|
if (!e || typeof e != "object") return;
|
|
618
601
|
const t = e;
|
|
619
602
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -632,22 +615,22 @@ function mt(e) {
|
|
|
632
615
|
if (i)
|
|
633
616
|
return i[1];
|
|
634
617
|
}
|
|
635
|
-
function
|
|
636
|
-
const t =
|
|
618
|
+
function rs(e) {
|
|
619
|
+
const t = wt(e);
|
|
637
620
|
if (t) {
|
|
638
621
|
const n = t.substring(0, 10);
|
|
639
622
|
return q[t] ?? q[n];
|
|
640
623
|
}
|
|
641
624
|
}
|
|
642
|
-
function
|
|
643
|
-
const t =
|
|
625
|
+
function is(e) {
|
|
626
|
+
const t = wt(e);
|
|
644
627
|
if (t === void 0) return !1;
|
|
645
628
|
const n = t.substring(0, 10);
|
|
646
629
|
return t in q || n in q;
|
|
647
630
|
}
|
|
648
|
-
function
|
|
631
|
+
function K(e) {
|
|
649
632
|
console.error("[Contract Error] Raw error:", e);
|
|
650
|
-
const t =
|
|
633
|
+
const t = wt(e);
|
|
651
634
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
652
635
|
const s = t.substring(0, 10), o = q[t] ?? q[s];
|
|
653
636
|
if (o)
|
|
@@ -667,18 +650,18 @@ function M(e) {
|
|
|
667
650
|
}
|
|
668
651
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
669
652
|
}
|
|
670
|
-
const
|
|
671
|
-
function
|
|
653
|
+
const Ve = 0;
|
|
654
|
+
function De(e, t, n, s) {
|
|
672
655
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
673
656
|
return o ? Promise.resolve({
|
|
674
657
|
txid: e,
|
|
675
658
|
vout: t,
|
|
676
659
|
value: o.value,
|
|
677
660
|
scriptPubKey: o.scriptPubKey
|
|
678
|
-
}) :
|
|
661
|
+
}) : We(e, t, s);
|
|
679
662
|
}
|
|
680
|
-
const
|
|
681
|
-
class
|
|
663
|
+
const Ct = 12e4;
|
|
664
|
+
class as {
|
|
682
665
|
/**
|
|
683
666
|
* Creates a new PeginManager instance.
|
|
684
667
|
*
|
|
@@ -709,7 +692,7 @@ class cs {
|
|
|
709
692
|
* @throws Error if wallet operations fail or insufficient funds
|
|
710
693
|
*/
|
|
711
694
|
async preparePegin(t) {
|
|
712
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, o =
|
|
695
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, o = B(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(B), i = t.universalChallengerBtcPubkeys.map(B);
|
|
713
696
|
if (t.hashlocks.length !== t.amounts.length)
|
|
714
697
|
throw new Error(
|
|
715
698
|
`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
|
|
@@ -734,21 +717,21 @@ class cs {
|
|
|
734
717
|
l.totalOutputValue,
|
|
735
718
|
t.mempoolFeeRate,
|
|
736
719
|
ve(l.htlcValues.length)
|
|
737
|
-
), u =
|
|
720
|
+
), u = Et(this.config.btcNetwork), d = ke({
|
|
738
721
|
unfundedTxHex: l.psbtHex,
|
|
739
722
|
selectedUTXOs: h.selectedUTXOs,
|
|
740
723
|
changeAddress: t.changeAddress,
|
|
741
724
|
changeAmount: h.changeAmount,
|
|
742
725
|
network: u
|
|
743
|
-
}),
|
|
726
|
+
}), y = B(dt(d)), b = [], x = [], P = [];
|
|
744
727
|
for (let f = 0; f < t.hashlocks.length; f++) {
|
|
745
|
-
const
|
|
728
|
+
const w = await He({
|
|
746
729
|
prePeginParams: c,
|
|
747
730
|
timelockPegin: t.timelockPegin,
|
|
748
731
|
fundedPrePeginTxHex: d,
|
|
749
732
|
htlcVout: f
|
|
750
|
-
}), v = await
|
|
751
|
-
peginTxHex:
|
|
733
|
+
}), v = await Ie({
|
|
734
|
+
peginTxHex: w.txHex,
|
|
752
735
|
fundedPrePeginTxHex: d,
|
|
753
736
|
depositorPubkey: s,
|
|
754
737
|
vaultProviderPubkey: o,
|
|
@@ -758,33 +741,33 @@ class cs {
|
|
|
758
741
|
timelockRefund: t.timelockRefund,
|
|
759
742
|
network: this.config.btcNetwork
|
|
760
743
|
});
|
|
761
|
-
|
|
762
|
-
|
|
744
|
+
b.push(w), x.push(v.psbtHex), P.push(
|
|
745
|
+
gt(n, 1)
|
|
763
746
|
);
|
|
764
747
|
}
|
|
765
|
-
const
|
|
748
|
+
const m = await this.signPsbtsWithFallback(
|
|
766
749
|
x,
|
|
767
750
|
P
|
|
768
|
-
),
|
|
769
|
-
for (let f = 0; f <
|
|
770
|
-
const
|
|
771
|
-
|
|
751
|
+
), g = [];
|
|
752
|
+
for (let f = 0; f < m.length; f++) {
|
|
753
|
+
const w = Ee(
|
|
754
|
+
m[f],
|
|
772
755
|
s
|
|
773
|
-
), v =
|
|
774
|
-
|
|
756
|
+
), v = Be(m[f]);
|
|
757
|
+
g.push({
|
|
775
758
|
htlcVout: f,
|
|
776
759
|
htlcValue: l.htlcValues[f],
|
|
777
760
|
peginTxHex: v,
|
|
778
|
-
peginTxid:
|
|
779
|
-
peginInputSignature:
|
|
780
|
-
vaultScriptPubKey:
|
|
761
|
+
peginTxid: b[f].txid,
|
|
762
|
+
peginInputSignature: w,
|
|
763
|
+
vaultScriptPubKey: b[f].vaultScriptPubKey
|
|
781
764
|
});
|
|
782
765
|
}
|
|
783
766
|
return {
|
|
784
767
|
fundedPrePeginTxHex: d,
|
|
785
|
-
prePeginTxid:
|
|
768
|
+
prePeginTxid: y,
|
|
786
769
|
unsignedPrePeginTxHex: l.psbtHex,
|
|
787
|
-
perVault:
|
|
770
|
+
perVault: g,
|
|
788
771
|
selectedUTXOs: h.selectedUTXOs,
|
|
789
772
|
fee: h.fee,
|
|
790
773
|
changeAmount: h.changeAmount
|
|
@@ -850,24 +833,24 @@ class cs {
|
|
|
850
833
|
throw new Error(
|
|
851
834
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
852
835
|
);
|
|
853
|
-
const l = this.config.mempoolApiUrl, h = r.ins.map((
|
|
854
|
-
const f = W.from(
|
|
855
|
-
return
|
|
856
|
-
(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 })
|
|
857
840
|
);
|
|
858
841
|
}), u = await Promise.all(h), d = u.reduce(
|
|
859
|
-
(
|
|
842
|
+
(g, f) => g + BigInt(f.utxoData.value),
|
|
860
843
|
0n
|
|
861
|
-
),
|
|
862
|
-
(
|
|
844
|
+
), y = r.outs.reduce(
|
|
845
|
+
(g, f) => g + BigInt(f.value),
|
|
863
846
|
0n
|
|
864
847
|
);
|
|
865
|
-
if (d <
|
|
848
|
+
if (d < y)
|
|
866
849
|
throw new Error(
|
|
867
|
-
`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.`
|
|
868
851
|
);
|
|
869
|
-
for (const { input:
|
|
870
|
-
const T =
|
|
852
|
+
for (const { input: g, utxoData: f, txid: w, vout: v } of u) {
|
|
853
|
+
const T = Ce(
|
|
871
854
|
{
|
|
872
855
|
value: f.value,
|
|
873
856
|
scriptPubKey: f.scriptPubKey
|
|
@@ -875,30 +858,30 @@ class cs {
|
|
|
875
858
|
c
|
|
876
859
|
);
|
|
877
860
|
i.addInput({
|
|
878
|
-
hash:
|
|
879
|
-
index:
|
|
880
|
-
sequence:
|
|
861
|
+
hash: g.hash,
|
|
862
|
+
index: g.index,
|
|
863
|
+
sequence: g.sequence,
|
|
881
864
|
...T
|
|
882
865
|
});
|
|
883
866
|
}
|
|
884
|
-
for (const
|
|
867
|
+
for (const g of r.outs)
|
|
885
868
|
i.addOutput({
|
|
886
|
-
script:
|
|
887
|
-
value:
|
|
869
|
+
script: g.script,
|
|
870
|
+
value: g.value
|
|
888
871
|
});
|
|
889
|
-
const
|
|
872
|
+
const b = await this.config.btcWallet.signPsbt(i.toHex()), x = kt.fromHex(b);
|
|
890
873
|
try {
|
|
891
874
|
x.finalizeAllInputs();
|
|
892
|
-
} catch (
|
|
875
|
+
} catch (g) {
|
|
893
876
|
if (!x.data.inputs.every(
|
|
894
|
-
(
|
|
877
|
+
(w) => w.finalScriptWitness || w.finalScriptSig
|
|
895
878
|
))
|
|
896
879
|
throw new Error(
|
|
897
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
880
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${g}`
|
|
898
881
|
);
|
|
899
882
|
}
|
|
900
883
|
const P = x.extractTransaction().toHex();
|
|
901
|
-
return await
|
|
884
|
+
return await _e(P, l);
|
|
902
885
|
}
|
|
903
886
|
/**
|
|
904
887
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -932,20 +915,20 @@ class cs {
|
|
|
932
915
|
} = t;
|
|
933
916
|
if (!this.config.ethWallet.account)
|
|
934
917
|
throw new Error("Ethereum wallet account not found");
|
|
935
|
-
const d = this.config.ethWallet.account.address,
|
|
918
|
+
const d = this.config.ethWallet.account.address, y = await this.resolvePopSignature(
|
|
936
919
|
d,
|
|
937
920
|
u
|
|
938
921
|
);
|
|
939
922
|
c && await c();
|
|
940
|
-
const
|
|
923
|
+
const b = U(n), x = U(s), P = U(o), m = await this.resolvePayoutScriptPubKey(
|
|
941
924
|
l
|
|
942
|
-
),
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
),
|
|
946
|
-
if (await this.checkVaultExists(
|
|
925
|
+
), g = dt(P), f = await Ut(
|
|
926
|
+
B(g),
|
|
927
|
+
B(d)
|
|
928
|
+
), w = U(f);
|
|
929
|
+
if (await this.checkVaultExists(w))
|
|
947
930
|
throw new Error(
|
|
948
|
-
`Vault already exists (ID: ${
|
|
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.`
|
|
949
932
|
);
|
|
950
933
|
const T = lt({
|
|
951
934
|
chain: this.config.ethChain,
|
|
@@ -964,59 +947,59 @@ class cs {
|
|
|
964
947
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
965
948
|
);
|
|
966
949
|
}
|
|
967
|
-
const
|
|
950
|
+
const I = Ht({
|
|
968
951
|
abi: j,
|
|
969
952
|
functionName: "submitPeginRequest",
|
|
970
953
|
args: [
|
|
971
954
|
d,
|
|
955
|
+
b,
|
|
972
956
|
y,
|
|
973
|
-
g,
|
|
974
957
|
x,
|
|
975
958
|
P,
|
|
976
959
|
r,
|
|
977
960
|
i,
|
|
978
961
|
a,
|
|
979
|
-
|
|
962
|
+
m,
|
|
980
963
|
h
|
|
981
964
|
]
|
|
982
965
|
});
|
|
983
|
-
let
|
|
966
|
+
let E;
|
|
984
967
|
try {
|
|
985
|
-
|
|
968
|
+
E = await T.estimateGas({
|
|
986
969
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
987
|
-
data:
|
|
970
|
+
data: I,
|
|
988
971
|
value: H,
|
|
989
972
|
account: this.config.ethWallet.account.address
|
|
990
973
|
});
|
|
991
974
|
} catch ($) {
|
|
992
|
-
|
|
975
|
+
K($);
|
|
993
976
|
}
|
|
994
|
-
let
|
|
977
|
+
let C;
|
|
995
978
|
try {
|
|
996
|
-
|
|
979
|
+
C = await this.config.ethWallet.sendTransaction({
|
|
997
980
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
998
|
-
data:
|
|
981
|
+
data: I,
|
|
999
982
|
value: H,
|
|
1000
983
|
account: this.config.ethWallet.account,
|
|
1001
984
|
chain: this.config.ethChain,
|
|
1002
|
-
gas:
|
|
985
|
+
gas: E
|
|
1003
986
|
});
|
|
1004
987
|
} catch ($) {
|
|
1005
|
-
|
|
988
|
+
K($);
|
|
1006
989
|
}
|
|
1007
|
-
const
|
|
1008
|
-
hash:
|
|
1009
|
-
timeout:
|
|
990
|
+
const M = await T.waitForTransactionReceipt({
|
|
991
|
+
hash: C,
|
|
992
|
+
timeout: Ct
|
|
1010
993
|
});
|
|
1011
|
-
return
|
|
994
|
+
return M.status === "reverted" && K(
|
|
1012
995
|
new Error(
|
|
1013
|
-
`Transaction reverted. Hash: ${
|
|
996
|
+
`Transaction reverted. Hash: ${C}. Check the transaction on block explorer for details.`
|
|
1014
997
|
)
|
|
1015
998
|
), {
|
|
1016
|
-
ethTxHash:
|
|
1017
|
-
vaultId:
|
|
1018
|
-
peginTxHash:
|
|
1019
|
-
btcPopSignature:
|
|
999
|
+
ethTxHash: M.transactionHash,
|
|
1000
|
+
vaultId: w,
|
|
1001
|
+
peginTxHash: g,
|
|
1002
|
+
btcPopSignature: y
|
|
1020
1003
|
};
|
|
1021
1004
|
}
|
|
1022
1005
|
/**
|
|
@@ -1041,23 +1024,23 @@ class cs {
|
|
|
1041
1024
|
);
|
|
1042
1025
|
r && await r();
|
|
1043
1026
|
const c = [];
|
|
1044
|
-
for (const
|
|
1027
|
+
for (const g of s)
|
|
1045
1028
|
c.push(
|
|
1046
|
-
await this.resolvePayoutScriptPubKey(
|
|
1029
|
+
await this.resolvePayoutScriptPubKey(g.depositorPayoutBtcAddress)
|
|
1047
1030
|
);
|
|
1048
1031
|
const l = [];
|
|
1049
|
-
for (const
|
|
1050
|
-
const f =
|
|
1051
|
-
|
|
1052
|
-
),
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
), T =
|
|
1032
|
+
for (const g of s) {
|
|
1033
|
+
const f = U(
|
|
1034
|
+
g.depositorSignedPeginTx
|
|
1035
|
+
), w = dt(f), v = await Ut(
|
|
1036
|
+
B(w),
|
|
1037
|
+
B(i)
|
|
1038
|
+
), T = U(v);
|
|
1056
1039
|
if (await this.checkVaultExists(T))
|
|
1057
1040
|
throw new Error(
|
|
1058
|
-
`Vault already exists (ID: ${T}, peginTxHash: ${
|
|
1041
|
+
`Vault already exists (ID: ${T}, peginTxHash: ${w}). To create a new vault, use different UTXOs or a different amount.`
|
|
1059
1042
|
);
|
|
1060
|
-
l.push({ vaultId: T, peginTxHash:
|
|
1043
|
+
l.push({ vaultId: T, peginTxHash: w });
|
|
1061
1044
|
}
|
|
1062
1045
|
const h = lt({
|
|
1063
1046
|
chain: this.config.ethChain,
|
|
@@ -1076,57 +1059,57 @@ class cs {
|
|
|
1076
1059
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
1077
1060
|
);
|
|
1078
1061
|
}
|
|
1079
|
-
const d = u * BigInt(s.length),
|
|
1080
|
-
depositorBtcPubKey:
|
|
1062
|
+
const d = u * BigInt(s.length), y = s.map((g, f) => ({
|
|
1063
|
+
depositorBtcPubKey: U(g.depositorBtcPubkey),
|
|
1081
1064
|
btcPopSignature: a,
|
|
1082
|
-
unsignedPrePeginTx:
|
|
1083
|
-
depositorSignedPeginTx:
|
|
1084
|
-
|
|
1065
|
+
unsignedPrePeginTx: U(g.unsignedPrePeginTx),
|
|
1066
|
+
depositorSignedPeginTx: U(
|
|
1067
|
+
g.depositorSignedPeginTx
|
|
1085
1068
|
),
|
|
1086
|
-
hashlock:
|
|
1087
|
-
htlcVout:
|
|
1088
|
-
referralCode:
|
|
1069
|
+
hashlock: g.hashlock,
|
|
1070
|
+
htlcVout: g.htlcVout,
|
|
1071
|
+
referralCode: Ve,
|
|
1089
1072
|
depositorPayoutBtcAddress: c[f],
|
|
1090
|
-
depositorWotsPkHash:
|
|
1091
|
-
})),
|
|
1073
|
+
depositorWotsPkHash: g.depositorWotsPkHash
|
|
1074
|
+
})), b = Ht({
|
|
1092
1075
|
abi: j,
|
|
1093
1076
|
functionName: "submitPeginRequestBatch",
|
|
1094
|
-
args: [i, n,
|
|
1077
|
+
args: [i, n, y]
|
|
1095
1078
|
});
|
|
1096
1079
|
let x;
|
|
1097
1080
|
try {
|
|
1098
1081
|
x = await h.estimateGas({
|
|
1099
1082
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1100
|
-
data:
|
|
1083
|
+
data: b,
|
|
1101
1084
|
value: d,
|
|
1102
1085
|
account: this.config.ethWallet.account.address
|
|
1103
1086
|
});
|
|
1104
|
-
} catch (
|
|
1105
|
-
|
|
1087
|
+
} catch (g) {
|
|
1088
|
+
K(g);
|
|
1106
1089
|
}
|
|
1107
1090
|
let P;
|
|
1108
1091
|
try {
|
|
1109
1092
|
P = await this.config.ethWallet.sendTransaction({
|
|
1110
1093
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1111
|
-
data:
|
|
1094
|
+
data: b,
|
|
1112
1095
|
value: d,
|
|
1113
1096
|
account: this.config.ethWallet.account,
|
|
1114
1097
|
chain: this.config.ethChain,
|
|
1115
1098
|
gas: x
|
|
1116
1099
|
});
|
|
1117
|
-
} catch (
|
|
1118
|
-
|
|
1100
|
+
} catch (g) {
|
|
1101
|
+
K(g);
|
|
1119
1102
|
}
|
|
1120
|
-
const
|
|
1103
|
+
const m = await h.waitForTransactionReceipt({
|
|
1121
1104
|
hash: P,
|
|
1122
|
-
timeout:
|
|
1105
|
+
timeout: Ct
|
|
1123
1106
|
});
|
|
1124
|
-
return
|
|
1107
|
+
return m.status === "reverted" && K(
|
|
1125
1108
|
new Error(
|
|
1126
1109
|
`Batch transaction reverted. Hash: ${P}. Check the transaction on block explorer for details.`
|
|
1127
1110
|
)
|
|
1128
1111
|
), {
|
|
1129
|
-
ethTxHash:
|
|
1112
|
+
ethTxHash: m.transactionHash,
|
|
1130
1113
|
vaults: l,
|
|
1131
1114
|
btcPopSignature: a
|
|
1132
1115
|
};
|
|
@@ -1145,9 +1128,9 @@ class cs {
|
|
|
1145
1128
|
}).readContract({
|
|
1146
1129
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1147
1130
|
abi: j,
|
|
1148
|
-
functionName: "
|
|
1131
|
+
functionName: "getBtcVaultBasicInfo",
|
|
1149
1132
|
args: [t]
|
|
1150
|
-
}))
|
|
1133
|
+
}))[0] !== ye;
|
|
1151
1134
|
} catch {
|
|
1152
1135
|
return !1;
|
|
1153
1136
|
}
|
|
@@ -1160,14 +1143,13 @@ class cs {
|
|
|
1160
1143
|
* wallet's public key to guard against a compromised wallet provider.
|
|
1161
1144
|
*/
|
|
1162
1145
|
async resolvePayoutScriptPubKey(t) {
|
|
1163
|
-
Be();
|
|
1164
1146
|
let n;
|
|
1165
1147
|
if (t)
|
|
1166
1148
|
n = t;
|
|
1167
1149
|
else {
|
|
1168
1150
|
n = await this.config.btcWallet.getAddress();
|
|
1169
1151
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1170
|
-
if (!
|
|
1152
|
+
if (!Se(
|
|
1171
1153
|
n,
|
|
1172
1154
|
o,
|
|
1173
1155
|
this.config.btcNetwork
|
|
@@ -1176,9 +1158,9 @@ class cs {
|
|
|
1176
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)."
|
|
1177
1159
|
);
|
|
1178
1160
|
}
|
|
1179
|
-
const s =
|
|
1161
|
+
const s = Et(this.config.btcNetwork);
|
|
1180
1162
|
try {
|
|
1181
|
-
return `0x${
|
|
1163
|
+
return `0x${be.address.toOutputScript(n, s).toString("hex")}`;
|
|
1182
1164
|
} catch {
|
|
1183
1165
|
throw new Error(
|
|
1184
1166
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1217,7 +1199,7 @@ class cs {
|
|
|
1217
1199
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1218
1200
|
}
|
|
1219
1201
|
}
|
|
1220
|
-
class
|
|
1202
|
+
class cs {
|
|
1221
1203
|
/**
|
|
1222
1204
|
* Creates a new PayoutManager instance.
|
|
1223
1205
|
*
|
|
@@ -1254,10 +1236,10 @@ class us {
|
|
|
1254
1236
|
t.payoutTxHex,
|
|
1255
1237
|
t.registeredPayoutScriptPubKey
|
|
1256
1238
|
);
|
|
1257
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } =
|
|
1239
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = Bt(
|
|
1258
1240
|
n,
|
|
1259
1241
|
t.depositorBtcPubkey
|
|
1260
|
-
), o = await
|
|
1242
|
+
), o = await St({
|
|
1261
1243
|
payoutTxHex: t.payoutTxHex,
|
|
1262
1244
|
peginTxHex: t.peginTxHex,
|
|
1263
1245
|
assertTxHex: t.assertTxHex,
|
|
@@ -1269,7 +1251,7 @@ class us {
|
|
|
1269
1251
|
network: this.config.network
|
|
1270
1252
|
}), r = await this.config.btcWallet.signPsbt(
|
|
1271
1253
|
o.psbtHex,
|
|
1272
|
-
|
|
1254
|
+
gt(n, 1)
|
|
1273
1255
|
);
|
|
1274
1256
|
return {
|
|
1275
1257
|
signature: At(r, s),
|
|
@@ -1312,12 +1294,12 @@ class us {
|
|
|
1312
1294
|
c.payoutTxHex,
|
|
1313
1295
|
c.registeredPayoutScriptPubKey
|
|
1314
1296
|
);
|
|
1315
|
-
const { depositorPubkey: l } =
|
|
1297
|
+
const { depositorPubkey: l } = Bt(
|
|
1316
1298
|
n,
|
|
1317
1299
|
c.depositorBtcPubkey
|
|
1318
1300
|
);
|
|
1319
1301
|
r.push(l);
|
|
1320
|
-
const h = await
|
|
1302
|
+
const h = await St({
|
|
1321
1303
|
payoutTxHex: c.payoutTxHex,
|
|
1322
1304
|
peginTxHex: c.peginTxHex,
|
|
1323
1305
|
assertTxHex: c.assertTxHex,
|
|
@@ -1328,7 +1310,7 @@ class us {
|
|
|
1328
1310
|
timelockPegin: c.timelockPegin,
|
|
1329
1311
|
network: this.config.network
|
|
1330
1312
|
});
|
|
1331
|
-
s.push(h.psbtHex), o.push(
|
|
1313
|
+
s.push(h.psbtHex), o.push(gt(n, 1));
|
|
1332
1314
|
}
|
|
1333
1315
|
const i = await this.config.btcWallet.signPsbts(
|
|
1334
1316
|
s,
|
|
@@ -1366,14 +1348,14 @@ class us {
|
|
|
1366
1348
|
* @throws Error if the largest output does not pay to the registered address
|
|
1367
1349
|
*/
|
|
1368
1350
|
validatePayoutOutputs(t, n) {
|
|
1369
|
-
if (!
|
|
1351
|
+
if (!Ae(n))
|
|
1370
1352
|
throw new Error(
|
|
1371
1353
|
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1372
1354
|
);
|
|
1373
1355
|
const s = W.from(
|
|
1374
|
-
|
|
1356
|
+
B(n),
|
|
1375
1357
|
"hex"
|
|
1376
|
-
), o = xt.fromHex(
|
|
1358
|
+
), o = xt.fromHex(B(t));
|
|
1377
1359
|
if (o.outs.length === 0)
|
|
1378
1360
|
throw new Error("Payout transaction has no outputs");
|
|
1379
1361
|
if (!o.outs.reduce(
|
|
@@ -1418,10 +1400,10 @@ function Zt(e, t) {
|
|
|
1418
1400
|
if (e.length < n)
|
|
1419
1401
|
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1420
1402
|
}
|
|
1421
|
-
function
|
|
1403
|
+
function Ke(e) {
|
|
1422
1404
|
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1423
1405
|
}
|
|
1424
|
-
function
|
|
1406
|
+
function S(...e) {
|
|
1425
1407
|
for (let t = 0; t < e.length; t++)
|
|
1426
1408
|
e[t].fill(0);
|
|
1427
1409
|
}
|
|
@@ -1434,25 +1416,25 @@ function A(e, t) {
|
|
|
1434
1416
|
function J(e, t) {
|
|
1435
1417
|
return e << t | e >>> 32 - t >>> 0;
|
|
1436
1418
|
}
|
|
1437
|
-
const
|
|
1438
|
-
function
|
|
1419
|
+
const Ne = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1420
|
+
function Xe(e) {
|
|
1439
1421
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1440
1422
|
}
|
|
1441
|
-
function
|
|
1423
|
+
function qe(e) {
|
|
1442
1424
|
for (let t = 0; t < e.length; t++)
|
|
1443
|
-
e[t] =
|
|
1425
|
+
e[t] = Xe(e[t]);
|
|
1444
1426
|
return e;
|
|
1445
1427
|
}
|
|
1446
|
-
const $t =
|
|
1447
|
-
function
|
|
1428
|
+
const $t = Ne ? (e) => e : qe;
|
|
1429
|
+
function Ge(e) {
|
|
1448
1430
|
if (typeof e != "string")
|
|
1449
1431
|
throw new Error("string expected");
|
|
1450
1432
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1451
1433
|
}
|
|
1452
1434
|
function Ot(e, t = "") {
|
|
1453
|
-
return typeof e == "string" ?
|
|
1435
|
+
return typeof e == "string" ? Ge(e) : D(e, void 0, t);
|
|
1454
1436
|
}
|
|
1455
|
-
function
|
|
1437
|
+
function je(e, t) {
|
|
1456
1438
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1457
1439
|
throw new Error("options must be object or undefined");
|
|
1458
1440
|
return Object.assign(e, t);
|
|
@@ -1482,7 +1464,7 @@ class Qt {
|
|
|
1482
1464
|
this.iHash.update(o), this.oHash = t.create();
|
|
1483
1465
|
for (let r = 0; r < o.length; r++)
|
|
1484
1466
|
o[r] ^= 106;
|
|
1485
|
-
this.oHash.update(o),
|
|
1467
|
+
this.oHash.update(o), S(o);
|
|
1486
1468
|
}
|
|
1487
1469
|
update(t) {
|
|
1488
1470
|
return G(this), this.iHash.update(t), this;
|
|
@@ -1506,12 +1488,12 @@ class Qt {
|
|
|
1506
1488
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1507
1489
|
}
|
|
1508
1490
|
}
|
|
1509
|
-
const
|
|
1510
|
-
|
|
1511
|
-
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) {
|
|
1512
1494
|
return e & t ^ ~e & n;
|
|
1513
1495
|
}
|
|
1514
|
-
function
|
|
1496
|
+
function Ze(e, t, n) {
|
|
1515
1497
|
return e & t ^ e & n ^ t & n;
|
|
1516
1498
|
}
|
|
1517
1499
|
class Pt {
|
|
@@ -1548,7 +1530,7 @@ class Pt {
|
|
|
1548
1530
|
G(this), Zt(t, this), this.finished = !0;
|
|
1549
1531
|
const { buffer: n, view: s, blockLen: o, isLE: r } = this;
|
|
1550
1532
|
let { pos: i } = this;
|
|
1551
|
-
n[i++] = 128,
|
|
1533
|
+
n[i++] = 128, S(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(s, 0), i = 0);
|
|
1552
1534
|
for (let u = i; u < o; u++)
|
|
1553
1535
|
n[u] = 0;
|
|
1554
1536
|
s.setBigUint64(o - 8, BigInt(this.length * 8), r), this.process(s, 0);
|
|
@@ -1602,7 +1584,7 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1602
1584
|
4215389547,
|
|
1603
1585
|
1541459225,
|
|
1604
1586
|
327033209
|
|
1605
|
-
]),
|
|
1587
|
+
]), Je = /* @__PURE__ */ Uint8Array.from([
|
|
1606
1588
|
7,
|
|
1607
1589
|
4,
|
|
1608
1590
|
13,
|
|
@@ -1619,11 +1601,11 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1619
1601
|
14,
|
|
1620
1602
|
11,
|
|
1621
1603
|
8
|
|
1622
|
-
]), Yt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)),
|
|
1623
|
-
const n = [[Yt], [
|
|
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]];
|
|
1624
1606
|
for (let s = 0; s < 4; s++)
|
|
1625
1607
|
for (let o of n)
|
|
1626
|
-
o.push(o[s].map((r) =>
|
|
1608
|
+
o.push(o[s].map((r) => Je[r]));
|
|
1627
1609
|
return n;
|
|
1628
1610
|
})(), ee = te[0], ne = te[1], se = /* @__PURE__ */ [
|
|
1629
1611
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
@@ -1631,13 +1613,13 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1631
1613
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1632
1614
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1633
1615
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1634
|
-
].map((e) => Uint8Array.from(e)),
|
|
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([
|
|
1635
1617
|
0,
|
|
1636
1618
|
1518500249,
|
|
1637
1619
|
1859775393,
|
|
1638
1620
|
2400959708,
|
|
1639
1621
|
2840853838
|
|
1640
|
-
]),
|
|
1622
|
+
]), nn = /* @__PURE__ */ Uint32Array.from([
|
|
1641
1623
|
1352829926,
|
|
1642
1624
|
1548603684,
|
|
1643
1625
|
1836072691,
|
|
@@ -1648,7 +1630,7 @@ function Lt(e, t, n, s) {
|
|
|
1648
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);
|
|
1649
1631
|
}
|
|
1650
1632
|
const Q = /* @__PURE__ */ new Uint32Array(16);
|
|
1651
|
-
class
|
|
1633
|
+
class sn extends Pt {
|
|
1652
1634
|
constructor() {
|
|
1653
1635
|
super(64, 20, 8, !0);
|
|
1654
1636
|
p(this, "h0", 1732584193);
|
|
@@ -1665,48 +1647,48 @@ class on extends Pt {
|
|
|
1665
1647
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
1666
1648
|
}
|
|
1667
1649
|
process(n, s) {
|
|
1668
|
-
for (let
|
|
1669
|
-
Q[
|
|
1670
|
-
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,
|
|
1671
|
-
for (let
|
|
1672
|
-
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];
|
|
1673
1655
|
for (let T = 0; T < 16; T++) {
|
|
1674
|
-
const H = J(o + Lt(
|
|
1656
|
+
const H = J(o + Lt(b, i, c, h) + Q[g[T]] + P, w[T]) + d | 0;
|
|
1675
1657
|
o = d, d = h, h = J(c, 10) | 0, c = i, i = H;
|
|
1676
1658
|
}
|
|
1677
1659
|
for (let T = 0; T < 16; T++) {
|
|
1678
|
-
const H = J(r + Lt(x, a, l, u) + Q[f[T]] +
|
|
1679
|
-
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;
|
|
1680
1662
|
}
|
|
1681
1663
|
}
|
|
1682
|
-
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);
|
|
1683
1665
|
}
|
|
1684
1666
|
roundClean() {
|
|
1685
|
-
|
|
1667
|
+
S(Q);
|
|
1686
1668
|
}
|
|
1687
1669
|
destroy() {
|
|
1688
|
-
this.destroyed = !0,
|
|
1670
|
+
this.destroyed = !0, S(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1689
1671
|
}
|
|
1690
1672
|
}
|
|
1691
|
-
const
|
|
1692
|
-
function
|
|
1673
|
+
const on = /* @__PURE__ */ ct(() => new sn()), Y = /* @__PURE__ */ BigInt(2 ** 32 - 1), _t = /* @__PURE__ */ BigInt(32);
|
|
1674
|
+
function rn(e, t = !1) {
|
|
1693
1675
|
return t ? { h: Number(e & Y), l: Number(e >> _t & Y) } : { h: Number(e >> _t & Y) | 0, l: Number(e & Y) | 0 };
|
|
1694
1676
|
}
|
|
1695
1677
|
function oe(e, t = !1) {
|
|
1696
1678
|
const n = e.length;
|
|
1697
1679
|
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
1698
1680
|
for (let r = 0; r < n; r++) {
|
|
1699
|
-
const { h: i, l: a } =
|
|
1681
|
+
const { h: i, l: a } = rn(e[r], t);
|
|
1700
1682
|
[s[r], o[r]] = [i, a];
|
|
1701
1683
|
}
|
|
1702
1684
|
return [s, o];
|
|
1703
1685
|
}
|
|
1704
|
-
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,
|
|
1705
|
-
function
|
|
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;
|
|
1687
|
+
function F(e, t, n, s) {
|
|
1706
1688
|
const o = (t >>> 0) + (s >>> 0);
|
|
1707
1689
|
return { h: e + n + (o / 2 ** 32 | 0) | 0, l: o | 0 };
|
|
1708
1690
|
}
|
|
1709
|
-
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([
|
|
1710
1692
|
1116352408,
|
|
1711
1693
|
1899447441,
|
|
1712
1694
|
3049323471,
|
|
@@ -1772,7 +1754,7 @@ const dn = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), fn = (e, t, n, s) =>
|
|
|
1772
1754
|
3204031479,
|
|
1773
1755
|
3329325298
|
|
1774
1756
|
]), L = /* @__PURE__ */ new Uint32Array(64);
|
|
1775
|
-
class
|
|
1757
|
+
class xn extends Pt {
|
|
1776
1758
|
constructor(t) {
|
|
1777
1759
|
super(64, t, 8, !1);
|
|
1778
1760
|
}
|
|
@@ -1788,24 +1770,24 @@ class mn extends Pt {
|
|
|
1788
1770
|
for (let u = 0; u < 16; u++, n += 4)
|
|
1789
1771
|
L[u] = t.getUint32(n, !1);
|
|
1790
1772
|
for (let u = 16; u < 64; u++) {
|
|
1791
|
-
const d = L[u - 15],
|
|
1792
|
-
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;
|
|
1793
1775
|
}
|
|
1794
1776
|
let { A: s, B: o, C: r, D: i, E: a, F: c, G: l, H: h } = this;
|
|
1795
1777
|
for (let u = 0; u < 64; u++) {
|
|
1796
|
-
const d = A(a, 6) ^ A(a, 11) ^ A(a, 25),
|
|
1797
|
-
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;
|
|
1798
1780
|
}
|
|
1799
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);
|
|
1800
1782
|
}
|
|
1801
1783
|
roundClean() {
|
|
1802
|
-
|
|
1784
|
+
S(L);
|
|
1803
1785
|
}
|
|
1804
1786
|
destroy() {
|
|
1805
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0),
|
|
1787
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), S(this.buffer);
|
|
1806
1788
|
}
|
|
1807
1789
|
}
|
|
1808
|
-
class wn extends
|
|
1790
|
+
class wn extends xn {
|
|
1809
1791
|
constructor() {
|
|
1810
1792
|
super(32);
|
|
1811
1793
|
// We cannot use array here since array allows indexing by variable
|
|
@@ -1901,44 +1883,44 @@ const re = oe([
|
|
|
1901
1883
|
"0x597f299cfc657e2a",
|
|
1902
1884
|
"0x5fcb6fab3ad6faec",
|
|
1903
1885
|
"0x6c44198c4a475817"
|
|
1904
|
-
].map((e) => BigInt(e))),
|
|
1905
|
-
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 {
|
|
1906
1888
|
constructor(t) {
|
|
1907
1889
|
super(128, t, 16, !1);
|
|
1908
1890
|
}
|
|
1909
1891
|
// prettier-ignore
|
|
1910
1892
|
get() {
|
|
1911
|
-
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:
|
|
1912
|
-
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];
|
|
1913
1895
|
}
|
|
1914
1896
|
// prettier-ignore
|
|
1915
|
-
set(t, n, s, o, r, i, a, c, l, h, u, d,
|
|
1916
|
-
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;
|
|
1917
1899
|
}
|
|
1918
1900
|
process(t, n) {
|
|
1919
1901
|
for (let f = 0; f < 16; f++, n += 4)
|
|
1920
1902
|
_[f] = t.getUint32(n), R[f] = t.getUint32(n += 4);
|
|
1921
1903
|
for (let f = 16; f < 80; f++) {
|
|
1922
|
-
const
|
|
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]);
|
|
1923
1905
|
_[f] = ut | 0, R[f] = $ | 0;
|
|
1924
1906
|
}
|
|
1925
|
-
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;
|
|
1926
1908
|
for (let f = 0; f < 80; f++) {
|
|
1927
|
-
const
|
|
1928
|
-
|
|
1929
|
-
const vt =
|
|
1930
|
-
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;
|
|
1931
1913
|
}
|
|
1932
|
-
({ h: s, l: o } =
|
|
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);
|
|
1933
1915
|
}
|
|
1934
1916
|
roundClean() {
|
|
1935
|
-
|
|
1917
|
+
S(_, R);
|
|
1936
1918
|
}
|
|
1937
1919
|
destroy() {
|
|
1938
|
-
|
|
1920
|
+
S(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1939
1921
|
}
|
|
1940
1922
|
}
|
|
1941
|
-
class
|
|
1923
|
+
class vn extends Tn {
|
|
1942
1924
|
constructor() {
|
|
1943
1925
|
super(64);
|
|
1944
1926
|
p(this, "Ah", k[0] | 0);
|
|
@@ -1959,21 +1941,21 @@ class kn extends vn {
|
|
|
1959
1941
|
p(this, "Hl", k[15] | 0);
|
|
1960
1942
|
}
|
|
1961
1943
|
}
|
|
1962
|
-
const
|
|
1944
|
+
const kn = /* @__PURE__ */ ct(
|
|
1963
1945
|
() => new wn(),
|
|
1964
1946
|
/* @__PURE__ */ Jt(1)
|
|
1965
1947
|
), ie = /* @__PURE__ */ ct(
|
|
1966
|
-
() => new
|
|
1948
|
+
() => new vn(),
|
|
1967
1949
|
/* @__PURE__ */ Jt(3)
|
|
1968
|
-
),
|
|
1950
|
+
), Hn = BigInt(0), z = BigInt(1), In = BigInt(2), En = BigInt(7), Bn = BigInt(256), Sn = BigInt(113), ae = [], ce = [], ue = [];
|
|
1969
1951
|
for (let e = 0, t = z, n = 1, s = 0; e < 24; e++) {
|
|
1970
1952
|
[n, s] = [s, (2 * n + 3 * s) % 5], ae.push(2 * (5 * s + n)), ce.push((e + 1) * (e + 2) / 2 % 64);
|
|
1971
|
-
let o =
|
|
1953
|
+
let o = Hn;
|
|
1972
1954
|
for (let r = 0; r < 7; r++)
|
|
1973
|
-
t = (t << z ^ (t >>
|
|
1955
|
+
t = (t << z ^ (t >> En) * Sn) % Bn, t & In && (o ^= z << (z << BigInt(r)) - z);
|
|
1974
1956
|
ue.push(o);
|
|
1975
1957
|
}
|
|
1976
|
-
const le = oe(ue, !0),
|
|
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);
|
|
1977
1959
|
function Fn(e, t = 24) {
|
|
1978
1960
|
const n = new Uint32Array(10);
|
|
1979
1961
|
for (let s = 24 - t; s < 24; s++) {
|
|
@@ -1981,8 +1963,8 @@ function Fn(e, t = 24) {
|
|
|
1981
1963
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1982
1964
|
for (let i = 0; i < 10; i += 2) {
|
|
1983
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];
|
|
1984
|
-
for (let
|
|
1985
|
-
e[i +
|
|
1966
|
+
for (let y = 0; y < 50; y += 10)
|
|
1967
|
+
e[i + y] ^= u, e[i + y + 1] ^= d;
|
|
1986
1968
|
}
|
|
1987
1969
|
let o = e[2], r = e[3];
|
|
1988
1970
|
for (let i = 0; i < 24; i++) {
|
|
@@ -1995,9 +1977,9 @@ function Fn(e, t = 24) {
|
|
|
1995
1977
|
for (let a = 0; a < 10; a++)
|
|
1996
1978
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1997
1979
|
}
|
|
1998
|
-
e[0] ^=
|
|
1980
|
+
e[0] ^= An[s], e[1] ^= Un[s];
|
|
1999
1981
|
}
|
|
2000
|
-
|
|
1982
|
+
S(n);
|
|
2001
1983
|
}
|
|
2002
1984
|
class Tt {
|
|
2003
1985
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
@@ -2015,7 +1997,7 @@ class Tt {
|
|
|
2015
1997
|
p(this, "rounds");
|
|
2016
1998
|
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, V(s, "outputLen"), !(0 < t && t < 200))
|
|
2017
1999
|
throw new Error("only keccak-f1600 function is supported");
|
|
2018
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
2000
|
+
this.state = new Uint8Array(200), this.state32 = Ke(this.state);
|
|
2019
2001
|
}
|
|
2020
2002
|
clone() {
|
|
2021
2003
|
return this._cloneInto();
|
|
@@ -2068,56 +2050,56 @@ class Tt {
|
|
|
2068
2050
|
return this.digestInto(new Uint8Array(this.outputLen));
|
|
2069
2051
|
}
|
|
2070
2052
|
destroy() {
|
|
2071
|
-
this.destroyed = !0,
|
|
2053
|
+
this.destroyed = !0, S(this.state);
|
|
2072
2054
|
}
|
|
2073
2055
|
_cloneInto(t) {
|
|
2074
2056
|
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
2075
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;
|
|
2076
2058
|
}
|
|
2077
2059
|
}
|
|
2078
|
-
const
|
|
2079
|
-
function
|
|
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) {
|
|
2080
2062
|
zt(e);
|
|
2081
|
-
const o =
|
|
2063
|
+
const o = je({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
2082
2064
|
if (V(r, "c"), V(i, "dkLen"), V(a, "asyncTick"), r < 1)
|
|
2083
2065
|
throw new Error("iterations (c) must be >= 1");
|
|
2084
|
-
const c = Ot(t, "password"), l = Ot(n, "salt"), h = new Uint8Array(i), u =
|
|
2066
|
+
const c = Ot(t, "password"), l = Ot(n, "salt"), h = new Uint8Array(i), u = mt.create(e, c), d = u._cloneInto().update(l);
|
|
2085
2067
|
return { c: r, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
|
|
2086
2068
|
}
|
|
2087
|
-
function
|
|
2088
|
-
return e.destroy(), t.destroy(), s && s.destroy(),
|
|
2069
|
+
function Ln(e, t, n, s, o) {
|
|
2070
|
+
return e.destroy(), t.destroy(), s && s.destroy(), S(o), n;
|
|
2089
2071
|
}
|
|
2090
|
-
function
|
|
2091
|
-
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);
|
|
2092
2074
|
let l;
|
|
2093
2075
|
const h = new Uint8Array(4), u = rt(h), d = new Uint8Array(a.outputLen);
|
|
2094
|
-
for (let
|
|
2095
|
-
const x = i.subarray(
|
|
2096
|
-
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));
|
|
2097
2079
|
for (let P = 1; P < o; P++) {
|
|
2098
2080
|
a._cloneInto(l).update(d).digestInto(d);
|
|
2099
|
-
for (let
|
|
2100
|
-
x[
|
|
2081
|
+
for (let m = 0; m < x.length; m++)
|
|
2082
|
+
x[m] ^= d[m];
|
|
2101
2083
|
}
|
|
2102
2084
|
}
|
|
2103
|
-
return
|
|
2085
|
+
return Ln(a, c, i, l, d);
|
|
2104
2086
|
}
|
|
2105
2087
|
function he(e) {
|
|
2106
2088
|
if (typeof e != "string")
|
|
2107
2089
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
2108
2090
|
return e.normalize("NFKD");
|
|
2109
2091
|
}
|
|
2110
|
-
function
|
|
2092
|
+
function Rn(e) {
|
|
2111
2093
|
const t = he(e), n = t.split(" ");
|
|
2112
2094
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
2113
2095
|
throw new Error("Invalid mnemonic");
|
|
2114
2096
|
return { nfkd: t, words: n };
|
|
2115
2097
|
}
|
|
2116
|
-
const
|
|
2117
|
-
function
|
|
2118
|
-
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 });
|
|
2119
2101
|
}
|
|
2120
|
-
const
|
|
2102
|
+
const Dn = 508, Mt = 16, nt = 32, st = 64, Kt = 5, Mn = 4;
|
|
2121
2103
|
function Z(...e) {
|
|
2122
2104
|
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
2123
2105
|
let s = 0;
|
|
@@ -2132,23 +2114,23 @@ function pt(e) {
|
|
|
2132
2114
|
const t = new Uint8Array(Mn);
|
|
2133
2115
|
return new DataView(t.buffer).setUint32(0, e.length, !1), Z(t, e);
|
|
2134
2116
|
}
|
|
2135
|
-
function
|
|
2136
|
-
return
|
|
2117
|
+
function bt(e, t) {
|
|
2118
|
+
return mt(ie, e, t);
|
|
2137
2119
|
}
|
|
2138
2120
|
function Nt(e) {
|
|
2139
|
-
return
|
|
2121
|
+
return on(kn(e));
|
|
2140
2122
|
}
|
|
2141
|
-
const
|
|
2142
|
-
function
|
|
2143
|
-
const t =
|
|
2123
|
+
const yt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2124
|
+
function Kn(e) {
|
|
2125
|
+
const t = Vn(e), n = new Uint8Array(t);
|
|
2144
2126
|
return t.fill(0), n;
|
|
2145
2127
|
}
|
|
2146
|
-
async function
|
|
2128
|
+
async function Nn(e, t, n, s) {
|
|
2147
2129
|
if (e.length !== st)
|
|
2148
2130
|
throw new Error(
|
|
2149
2131
|
`WOTS seed must be ${st} bytes, got ${e.length}`
|
|
2150
2132
|
);
|
|
2151
|
-
t =
|
|
2133
|
+
t = B(t), n = B(n);
|
|
2152
2134
|
const o = e.slice(nt, st), r = e.slice(0, nt), i = [o, r];
|
|
2153
2135
|
try {
|
|
2154
2136
|
const a = Z(
|
|
@@ -2157,31 +2139,31 @@ async function Xn(e, t, n, s) {
|
|
|
2157
2139
|
pt(ft(s))
|
|
2158
2140
|
), c = Z(r, a);
|
|
2159
2141
|
i.push(c);
|
|
2160
|
-
const l =
|
|
2142
|
+
const l = bt(o, c);
|
|
2161
2143
|
i.push(l);
|
|
2162
2144
|
const h = l.slice(0, nt), u = l.slice(nt, st);
|
|
2163
2145
|
i.push(h, u);
|
|
2164
|
-
const d = [],
|
|
2146
|
+
const d = [], y = [], b = [], x = [];
|
|
2165
2147
|
let P = !1;
|
|
2166
2148
|
try {
|
|
2167
|
-
for (let
|
|
2168
|
-
const
|
|
2169
|
-
|
|
2170
|
-
const f = new Uint8Array(
|
|
2171
|
-
f[0] = 1, new DataView(f.buffer).setUint32(1,
|
|
2172
|
-
const
|
|
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);
|
|
2153
|
+
f[0] = 1, new DataView(f.buffer).setUint32(1, m, !1);
|
|
2154
|
+
const w = Z(h, g), v = Z(h, f), T = bt(u, w), H = bt(u, v);
|
|
2173
2155
|
try {
|
|
2174
|
-
const
|
|
2175
|
-
d.push(
|
|
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));
|
|
2176
2158
|
} finally {
|
|
2177
|
-
|
|
2159
|
+
w.fill(0), v.fill(0), T.fill(0), H.fill(0);
|
|
2178
2160
|
}
|
|
2179
2161
|
}
|
|
2180
|
-
return P = !0, { falsePreimages: d, truePreimages:
|
|
2162
|
+
return P = !0, { falsePreimages: d, truePreimages: y, falseHashes: b, trueHashes: x };
|
|
2181
2163
|
} finally {
|
|
2182
2164
|
if (!P) {
|
|
2183
|
-
for (const
|
|
2184
|
-
for (const
|
|
2165
|
+
for (const m of d) m.fill(0);
|
|
2166
|
+
for (const m of y) m.fill(0);
|
|
2185
2167
|
}
|
|
2186
2168
|
}
|
|
2187
2169
|
} finally {
|
|
@@ -2189,13 +2171,13 @@ async function Xn(e, t, n, s) {
|
|
|
2189
2171
|
a.fill(0);
|
|
2190
2172
|
}
|
|
2191
2173
|
}
|
|
2192
|
-
function
|
|
2174
|
+
function us(e) {
|
|
2193
2175
|
return {
|
|
2194
|
-
false_list: e.falseHashes.map(
|
|
2195
|
-
true_list: e.trueHashes.map(
|
|
2176
|
+
false_list: e.falseHashes.map(yt),
|
|
2177
|
+
true_list: e.trueHashes.map(yt)
|
|
2196
2178
|
};
|
|
2197
2179
|
}
|
|
2198
|
-
function
|
|
2180
|
+
function Xn(e) {
|
|
2199
2181
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2200
2182
|
throw new Error(
|
|
2201
2183
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
@@ -2206,20 +2188,20 @@ function qn(e) {
|
|
|
2206
2188
|
s.set(i, o), o += t;
|
|
2207
2189
|
for (const i of e.trueHashes)
|
|
2208
2190
|
s.set(i, o), o += t;
|
|
2209
|
-
const r =
|
|
2210
|
-
return `0x${
|
|
2191
|
+
const r = $n(s);
|
|
2192
|
+
return `0x${yt(r)}`;
|
|
2211
2193
|
}
|
|
2212
|
-
async function
|
|
2213
|
-
const o =
|
|
2194
|
+
async function ls(e, t, n, s) {
|
|
2195
|
+
const o = Kn(e);
|
|
2214
2196
|
try {
|
|
2215
|
-
const r = await
|
|
2197
|
+
const r = await Nn(
|
|
2216
2198
|
o,
|
|
2217
2199
|
t,
|
|
2218
2200
|
n,
|
|
2219
2201
|
s
|
|
2220
2202
|
);
|
|
2221
2203
|
try {
|
|
2222
|
-
return
|
|
2204
|
+
return Xn(r);
|
|
2223
2205
|
} finally {
|
|
2224
2206
|
for (const i of r.falsePreimages) i.fill(0);
|
|
2225
2207
|
for (const i of r.truePreimages) i.fill(0);
|
|
@@ -2228,41 +2210,41 @@ async function hs(e, t, n, s) {
|
|
|
2228
2210
|
o.fill(0);
|
|
2229
2211
|
}
|
|
2230
2212
|
}
|
|
2231
|
-
function
|
|
2213
|
+
function hs(e) {
|
|
2232
2214
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2233
2215
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2234
2216
|
}
|
|
2235
2217
|
export {
|
|
2236
|
-
|
|
2218
|
+
hs as A,
|
|
2237
2219
|
ot as B,
|
|
2238
2220
|
q as C,
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2221
|
+
Le as M,
|
|
2222
|
+
as as P,
|
|
2223
|
+
Qn as a,
|
|
2242
2224
|
Fe as b,
|
|
2243
2225
|
dt as c,
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2226
|
+
Ce as d,
|
|
2227
|
+
gt as e,
|
|
2228
|
+
cs as f,
|
|
2229
|
+
Yn as g,
|
|
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,
|
|
2255
2237
|
j as o,
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2238
|
+
_e as p,
|
|
2239
|
+
wt as q,
|
|
2240
|
+
rs as r,
|
|
2259
2241
|
Ue as s,
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2242
|
+
is as t,
|
|
2243
|
+
K as u,
|
|
2244
|
+
Kn as v,
|
|
2245
|
+
Nn as w,
|
|
2246
|
+
us as x,
|
|
2247
|
+
Xn as y,
|
|
2248
|
+
ls as z
|
|
2267
2249
|
};
|
|
2268
|
-
//# sourceMappingURL=errors-
|
|
2250
|
+
//# sourceMappingURL=errors-BeFfs5_J.js.map
|