@babylonlabs-io/ts-sdk 0.13.1 → 0.13.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/dist/{errors-Ci-2cgfS.js → errors-D19BQSaj.js} +405 -401
- package/dist/errors-D19BQSaj.js.map +1 -0
- package/dist/errors-vxNv_NdZ.cjs +2 -0
- package/dist/errors-vxNv_NdZ.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +7 -3
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +1 -1
- package/package.json +1 -1
- package/dist/errors-CPd0qvSk.cjs +0 -2
- package/dist/errors-CPd0qvSk.cjs.map +0 -1
- package/dist/errors-Ci-2cgfS.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var ce = Object.defineProperty;
|
|
2
2
|
var ue = (e, t, n) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
-
var
|
|
3
|
+
var d = (e, t, n) => ue(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
import * as le from "bitcoinjs-lib";
|
|
5
|
-
import { script as he, Transaction as
|
|
5
|
+
import { script as he, Transaction as q, address as fe, Psbt as dt } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as S } from "buffer";
|
|
7
|
-
import { P as de, y as pe, D as Vt, M as Tt, B as be, T as ge, G as pt, u as
|
|
8
|
-
import { createPublicClient as
|
|
9
|
-
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
-
function
|
|
7
|
+
import { P as de, y as pe, D as Vt, M as Tt, B as be, T as ge, G as pt, u as $, b as xe, A as ye, E as we, a as me, d as Pe, e as Te, f as ve, s as z, q as ke, x as vt, h as kt, i as Ht, r as He } from "./challengeAssert-CenzzhZU.js";
|
|
8
|
+
import { createPublicClient as It, http as Et, encodeFunctionData as Ie, zeroAddress as Ee } from "viem";
|
|
9
|
+
import { deriveVaultId as Se } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
function Ae(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}`
|
|
@@ -26,20 +26,20 @@ function Se(e, t, n, s) {
|
|
|
26
26
|
let a = 0n, c = 0n;
|
|
27
27
|
for (const u of o) {
|
|
28
28
|
i.push(u), a += BigInt(u.value);
|
|
29
|
-
const h = i.length * de, l = s * Tt,
|
|
30
|
-
if (c = BigInt(Math.ceil(
|
|
31
|
-
const
|
|
29
|
+
const h = i.length * de, l = s * Tt, f = h + l + ge;
|
|
30
|
+
if (c = BigInt(Math.ceil(f * n)) + BigInt(pe(n)), a - t - c > Vt) {
|
|
31
|
+
const b = BigInt(
|
|
32
32
|
Math.ceil(Tt * 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,17 +47,17 @@ function Se(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 Zn(e) {
|
|
51
51
|
return e > Vt;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function Jn() {
|
|
54
54
|
return be;
|
|
55
55
|
}
|
|
56
56
|
function St(e) {
|
|
57
57
|
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
58
|
-
return `0x${
|
|
58
|
+
return `0x${q.fromHex(t).getId()}`;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function Yn(e, t, n) {
|
|
61
61
|
if (e.length === 0)
|
|
62
62
|
throw new Error("No input UTXOs provided for split transaction");
|
|
63
63
|
if (t.length === 0)
|
|
@@ -67,7 +67,7 @@ function Jn(e, t, n) {
|
|
|
67
67
|
throw new Error(
|
|
68
68
|
`Invalid output amount for ${c.address}: ${c.amount} satoshis. Amount must be greater than zero.`
|
|
69
69
|
);
|
|
70
|
-
const s = pt(n), r = new
|
|
70
|
+
const s = pt(n), r = new q();
|
|
71
71
|
r.version = 2;
|
|
72
72
|
for (const c of e) {
|
|
73
73
|
const u = S.from(c.txid, "hex").reverse();
|
|
@@ -101,8 +101,8 @@ function Jn(e, t, n) {
|
|
|
101
101
|
outputs: o
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
const s =
|
|
104
|
+
function Qn(e, t, n) {
|
|
105
|
+
const s = q.fromHex(e), r = new dt();
|
|
106
106
|
if (r.setVersion(s.version), r.setLocktime(s.locktime), !S.isBuffer(n) || n.length !== 32)
|
|
107
107
|
throw new Error(
|
|
108
108
|
`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${S.isBuffer(n) ? `${n.length}-byte Buffer` : typeof n}`
|
|
@@ -126,7 +126,7 @@ function Yn(e, t, n) {
|
|
|
126
126
|
throw new Error(
|
|
127
127
|
`Input ${o} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${a.scriptPubKey.substring(0, 20)}...`
|
|
128
128
|
);
|
|
129
|
-
const
|
|
129
|
+
const f = {
|
|
130
130
|
script: S.from(a.scriptPubKey, "hex"),
|
|
131
131
|
value: a.value
|
|
132
132
|
};
|
|
@@ -134,7 +134,7 @@ function Yn(e, t, n) {
|
|
|
134
134
|
hash: i.hash,
|
|
135
135
|
index: i.index,
|
|
136
136
|
sequence: i.sequence,
|
|
137
|
-
witnessUtxo:
|
|
137
|
+
witnessUtxo: f,
|
|
138
138
|
tapInternalKey: n
|
|
139
139
|
});
|
|
140
140
|
}
|
|
@@ -145,8 +145,8 @@ function Yn(e, t, n) {
|
|
|
145
145
|
});
|
|
146
146
|
return r.toHex();
|
|
147
147
|
}
|
|
148
|
-
var
|
|
149
|
-
function
|
|
148
|
+
var st = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(st || {});
|
|
149
|
+
function Be(e) {
|
|
150
150
|
const t = e.length;
|
|
151
151
|
return t === 25 && e[0] === 118 && // OP_DUP
|
|
152
152
|
e[1] === 169 && // OP_HASH160
|
|
@@ -159,17 +159,17 @@ function Ae(e) {
|
|
|
159
159
|
e[1] === 32 ? "P2WSH" : t === 34 && e[0] === 81 && // OP_1
|
|
160
160
|
e[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
161
161
|
}
|
|
162
|
-
function
|
|
163
|
-
const n = S.from(e.scriptPubKey, "hex"), s =
|
|
162
|
+
function $e(e, t) {
|
|
163
|
+
const n = S.from(e.scriptPubKey, "hex"), s = Be(n);
|
|
164
164
|
switch (s) {
|
|
165
|
-
case
|
|
165
|
+
case st.P2WPKH:
|
|
166
166
|
return {
|
|
167
167
|
witnessUtxo: {
|
|
168
168
|
script: n,
|
|
169
169
|
value: e.value
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
case
|
|
172
|
+
case st.P2WSH: {
|
|
173
173
|
if (!e.witnessScript)
|
|
174
174
|
throw new Error("Missing witnessScript for P2WSH input");
|
|
175
175
|
return {
|
|
@@ -180,7 +180,7 @@ function Be(e, t) {
|
|
|
180
180
|
witnessScript: S.from(e.witnessScript, "hex")
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
-
case
|
|
183
|
+
case st.P2TR: {
|
|
184
184
|
if (t && t.length !== 32)
|
|
185
185
|
throw new Error(
|
|
186
186
|
`Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`
|
|
@@ -210,22 +210,22 @@ function bt(e, t) {
|
|
|
210
210
|
}))
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
const
|
|
213
|
+
const Ue = 21e6 * 1e8, Kt = 1e4;
|
|
214
214
|
function Dt(e) {
|
|
215
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
215
|
+
return Number.isInteger(e) && e > 0 && e <= Ue;
|
|
216
216
|
}
|
|
217
|
-
function
|
|
217
|
+
function Fe(e) {
|
|
218
218
|
return Number.isInteger(e) && e > 0 && e <= Kt;
|
|
219
219
|
}
|
|
220
220
|
function Mt(e, t) {
|
|
221
221
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
222
222
|
}
|
|
223
|
-
const
|
|
223
|
+
const Oe = {
|
|
224
224
|
mainnet: "https://mempool.space/api",
|
|
225
225
|
testnet: "https://mempool.space/testnet/api",
|
|
226
226
|
signet: "https://mempool.space/signet/api"
|
|
227
227
|
};
|
|
228
|
-
async function
|
|
228
|
+
async function ot(e, t) {
|
|
229
229
|
try {
|
|
230
230
|
const n = await fetch(e, t);
|
|
231
231
|
if (!n.ok) {
|
|
@@ -240,7 +240,7 @@ async function st(e, t) {
|
|
|
240
240
|
throw n instanceof Error ? new Error(`Failed to fetch from mempool API: ${n.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
async function
|
|
243
|
+
async function Le(e, t) {
|
|
244
244
|
try {
|
|
245
245
|
const n = await fetch(`${t}/tx`, {
|
|
246
246
|
method: "POST",
|
|
@@ -266,10 +266,10 @@ async function Oe(e, t) {
|
|
|
266
266
|
throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
async function
|
|
270
|
-
return
|
|
269
|
+
async function Ce(e, t) {
|
|
270
|
+
return ot(`${t}/tx/${e}`);
|
|
271
271
|
}
|
|
272
|
-
async function
|
|
272
|
+
async function ts(e, t) {
|
|
273
273
|
try {
|
|
274
274
|
const n = await fetch(`${t}/tx/${e}/hex`);
|
|
275
275
|
if (!n.ok) {
|
|
@@ -283,8 +283,8 @@ async function Qn(e, t) {
|
|
|
283
283
|
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`);
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
async function
|
|
287
|
-
const s = await
|
|
286
|
+
async function _e(e, t, n) {
|
|
287
|
+
const s = await Ce(e, n);
|
|
288
288
|
if (!Mt(t, s.vout.length))
|
|
289
289
|
throw new Error(
|
|
290
290
|
`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
|
|
@@ -299,9 +299,9 @@ async function Ce(e, t, n) {
|
|
|
299
299
|
scriptPubKey: r.scriptpubkey
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
|
-
async function
|
|
302
|
+
async function es(e, t) {
|
|
303
303
|
try {
|
|
304
|
-
const n = await
|
|
304
|
+
const n = await ot(`${t}/address/${e}/utxo`), s = await ot(`${t}/v1/validate-address/${e}`);
|
|
305
305
|
if (!s.isvalid)
|
|
306
306
|
throw new Error(
|
|
307
307
|
`Invalid Bitcoin address: ${e}. Mempool API validation failed.`
|
|
@@ -329,13 +329,13 @@ async function ts(e, t) {
|
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
function
|
|
333
|
-
return
|
|
332
|
+
function ns(e) {
|
|
333
|
+
return Oe[e];
|
|
334
334
|
}
|
|
335
|
-
async function
|
|
336
|
-
return
|
|
335
|
+
async function ss(e, t) {
|
|
336
|
+
return ot(`${t}/address/${e}/txs`);
|
|
337
337
|
}
|
|
338
|
-
async function
|
|
338
|
+
async function rs(e) {
|
|
339
339
|
const t = await fetch(`${e}/v1/fees/recommended`);
|
|
340
340
|
if (!t.ok)
|
|
341
341
|
throw new Error(
|
|
@@ -349,7 +349,7 @@ async function ss(e) {
|
|
|
349
349
|
"minimumFee"
|
|
350
350
|
];
|
|
351
351
|
for (const r of s)
|
|
352
|
-
if (!
|
|
352
|
+
if (!Fe(n[r]))
|
|
353
353
|
throw new Error(
|
|
354
354
|
`Invalid fee rate ${r}=${n[r]} from mempool API: expected a positive number ≤ ${Kt}`
|
|
355
355
|
);
|
|
@@ -624,7 +624,7 @@ const ct = [
|
|
|
624
624
|
name: "PeginSignaturesIncomplete",
|
|
625
625
|
inputs: []
|
|
626
626
|
}
|
|
627
|
-
],
|
|
627
|
+
], N = {
|
|
628
628
|
// VaultAlreadyExists()
|
|
629
629
|
"0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
|
|
630
630
|
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
@@ -654,7 +654,7 @@ const ct = [
|
|
|
654
654
|
// InvalidPeginFee(uint256,uint256)
|
|
655
655
|
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
656
656
|
};
|
|
657
|
-
function
|
|
657
|
+
function xt(e) {
|
|
658
658
|
if (!e || typeof e != "object") return;
|
|
659
659
|
const t = e;
|
|
660
660
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -673,24 +673,24 @@ function yt(e) {
|
|
|
673
673
|
if (i)
|
|
674
674
|
return i[1];
|
|
675
675
|
}
|
|
676
|
-
function
|
|
677
|
-
const t =
|
|
676
|
+
function os(e) {
|
|
677
|
+
const t = xt(e);
|
|
678
678
|
if (t) {
|
|
679
679
|
const n = t.substring(0, 10);
|
|
680
|
-
return
|
|
680
|
+
return N[t] ?? N[n];
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
|
-
function
|
|
684
|
-
const t =
|
|
683
|
+
function is(e) {
|
|
684
|
+
const t = xt(e);
|
|
685
685
|
if (t === void 0) return !1;
|
|
686
686
|
const n = t.substring(0, 10);
|
|
687
|
-
return t in
|
|
687
|
+
return t in N || n in N;
|
|
688
688
|
}
|
|
689
689
|
function ut(e) {
|
|
690
690
|
console.error("[Contract Error] Raw error:", e);
|
|
691
|
-
const t =
|
|
691
|
+
const t = xt(e);
|
|
692
692
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
693
|
-
const s = t.substring(0, 10), r =
|
|
693
|
+
const s = t.substring(0, 10), r = N[t] ?? N[s];
|
|
694
694
|
if (r)
|
|
695
695
|
throw console.error("[Contract Error] Known error:", r), new Error(r);
|
|
696
696
|
}
|
|
@@ -708,24 +708,24 @@ function ut(e) {
|
|
|
708
708
|
}
|
|
709
709
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
710
710
|
}
|
|
711
|
-
function
|
|
711
|
+
function We(e, t, n, s) {
|
|
712
712
|
const r = n == null ? void 0 : n[`${e}:${t}`];
|
|
713
713
|
return r ? Promise.resolve({
|
|
714
714
|
txid: e,
|
|
715
715
|
vout: t,
|
|
716
716
|
value: r.value,
|
|
717
717
|
scriptPubKey: r.scriptPubKey
|
|
718
|
-
}) :
|
|
718
|
+
}) : _e(e, t, s);
|
|
719
719
|
}
|
|
720
|
-
const
|
|
721
|
-
class
|
|
720
|
+
const Re = 12e4;
|
|
721
|
+
class as {
|
|
722
722
|
/**
|
|
723
723
|
* Creates a new PeginManager instance.
|
|
724
724
|
*
|
|
725
725
|
* @param config - Manager configuration including wallets and contract addresses
|
|
726
726
|
*/
|
|
727
727
|
constructor(t) {
|
|
728
|
-
|
|
728
|
+
d(this, "config");
|
|
729
729
|
this.config = t;
|
|
730
730
|
}
|
|
731
731
|
/**
|
|
@@ -749,7 +749,7 @@ class is {
|
|
|
749
749
|
* @throws Error if wallet operations fail or insufficient funds
|
|
750
750
|
*/
|
|
751
751
|
async preparePegin(t) {
|
|
752
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r =
|
|
752
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, r = $(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map($), i = t.universalChallengerBtcPubkeys.map($);
|
|
753
753
|
if (t.hashlocks.length !== t.amounts.length)
|
|
754
754
|
throw new Error(
|
|
755
755
|
`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
|
|
@@ -769,59 +769,59 @@ class is {
|
|
|
769
769
|
councilQuorum: t.councilQuorum,
|
|
770
770
|
councilSize: t.councilSize,
|
|
771
771
|
network: this.config.btcNetwork
|
|
772
|
-
}, u = await
|
|
772
|
+
}, u = await xe(c), h = Ae(
|
|
773
773
|
[...t.availableUTXOs],
|
|
774
774
|
u.totalOutputValue,
|
|
775
775
|
t.mempoolFeeRate,
|
|
776
|
-
|
|
777
|
-
), l = pt(this.config.btcNetwork),
|
|
776
|
+
ye(u.htlcValues.length)
|
|
777
|
+
), l = pt(this.config.btcNetwork), f = we({
|
|
778
778
|
unfundedTxHex: u.psbtHex,
|
|
779
779
|
selectedUTXOs: h.selectedUTXOs,
|
|
780
780
|
changeAddress: t.changeAddress,
|
|
781
781
|
changeAmount: h.changeAmount,
|
|
782
782
|
network: l
|
|
783
|
-
}), g =
|
|
784
|
-
for (let
|
|
783
|
+
}), g = $(St(f)), b = [], w = [], x = [];
|
|
784
|
+
for (let p = 0; p < t.hashlocks.length; p++) {
|
|
785
785
|
const P = await me({
|
|
786
786
|
prePeginParams: c,
|
|
787
787
|
timelockPegin: t.timelockPegin,
|
|
788
|
-
fundedPrePeginTxHex:
|
|
789
|
-
htlcVout:
|
|
790
|
-
}),
|
|
788
|
+
fundedPrePeginTxHex: f,
|
|
789
|
+
htlcVout: p
|
|
790
|
+
}), v = await Pe({
|
|
791
791
|
peginTxHex: P.txHex,
|
|
792
|
-
fundedPrePeginTxHex:
|
|
792
|
+
fundedPrePeginTxHex: f,
|
|
793
793
|
depositorPubkey: s,
|
|
794
794
|
vaultProviderPubkey: r,
|
|
795
795
|
vaultKeeperPubkeys: o,
|
|
796
796
|
universalChallengerPubkeys: i,
|
|
797
|
-
hashlock: t.hashlocks[
|
|
797
|
+
hashlock: t.hashlocks[p],
|
|
798
798
|
timelockRefund: t.timelockRefund,
|
|
799
799
|
network: this.config.btcNetwork
|
|
800
800
|
});
|
|
801
|
-
|
|
801
|
+
b.push(P), w.push(v.psbtHex), x.push(
|
|
802
802
|
bt(n, 1)
|
|
803
803
|
);
|
|
804
804
|
}
|
|
805
|
-
const
|
|
805
|
+
const y = await this.signPsbtsWithFallback(
|
|
806
806
|
w,
|
|
807
|
-
|
|
807
|
+
x
|
|
808
808
|
), m = [];
|
|
809
|
-
for (let
|
|
809
|
+
for (let p = 0; p < y.length; p++) {
|
|
810
810
|
const P = Te(
|
|
811
|
-
|
|
811
|
+
y[p],
|
|
812
812
|
s
|
|
813
|
-
),
|
|
813
|
+
), v = ve(y[p]);
|
|
814
814
|
m.push({
|
|
815
|
-
htlcVout:
|
|
816
|
-
htlcValue: u.htlcValues[
|
|
817
|
-
peginTxHex:
|
|
818
|
-
peginTxid: p
|
|
815
|
+
htlcVout: p,
|
|
816
|
+
htlcValue: u.htlcValues[p],
|
|
817
|
+
peginTxHex: v,
|
|
818
|
+
peginTxid: b[p].txid,
|
|
819
819
|
peginInputSignature: P,
|
|
820
|
-
vaultScriptPubKey: p
|
|
820
|
+
vaultScriptPubKey: b[p].vaultScriptPubKey
|
|
821
821
|
});
|
|
822
822
|
}
|
|
823
823
|
return {
|
|
824
|
-
fundedPrePeginTxHex:
|
|
824
|
+
fundedPrePeginTxHex: f,
|
|
825
825
|
prePeginTxid: g,
|
|
826
826
|
unsignedPrePeginTxHex: u.psbtHex,
|
|
827
827
|
perVault: m,
|
|
@@ -875,7 +875,7 @@ class is {
|
|
|
875
875
|
* @throws Error if signing or broadcasting fails
|
|
876
876
|
*/
|
|
877
877
|
async signAndBroadcast(t) {
|
|
878
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o =
|
|
878
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, r = n.startsWith("0x") ? n.slice(2) : n, o = q.fromHex(r);
|
|
879
879
|
if (o.ins.length === 0)
|
|
880
880
|
throw new Error("Transaction has no inputs");
|
|
881
881
|
const i = new dt();
|
|
@@ -890,45 +890,45 @@ class is {
|
|
|
890
890
|
throw new Error(
|
|
891
891
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
892
892
|
);
|
|
893
|
-
const u = this.config.mempoolApiUrl, h = o.ins.map((
|
|
894
|
-
const
|
|
895
|
-
return
|
|
896
|
-
(
|
|
893
|
+
const u = this.config.mempoolApiUrl, h = o.ins.map((x) => {
|
|
894
|
+
const y = S.from(x.hash).reverse().toString("hex"), m = x.index;
|
|
895
|
+
return We(y, m, t.localPrevouts, u).then(
|
|
896
|
+
(p) => ({ input: x, utxoData: p, txid: y, vout: m })
|
|
897
897
|
);
|
|
898
898
|
}), l = await Promise.all(h);
|
|
899
|
-
for (const { input:
|
|
900
|
-
const P =
|
|
899
|
+
for (const { input: x, utxoData: y, txid: m, vout: p } of l) {
|
|
900
|
+
const P = $e(
|
|
901
901
|
{
|
|
902
|
-
value:
|
|
903
|
-
scriptPubKey:
|
|
902
|
+
value: y.value,
|
|
903
|
+
scriptPubKey: y.scriptPubKey
|
|
904
904
|
},
|
|
905
905
|
c
|
|
906
906
|
);
|
|
907
907
|
i.addInput({
|
|
908
|
-
hash:
|
|
909
|
-
index:
|
|
910
|
-
sequence:
|
|
908
|
+
hash: x.hash,
|
|
909
|
+
index: x.index,
|
|
910
|
+
sequence: x.sequence,
|
|
911
911
|
...P
|
|
912
912
|
});
|
|
913
913
|
}
|
|
914
|
-
for (const
|
|
914
|
+
for (const x of o.outs)
|
|
915
915
|
i.addOutput({
|
|
916
|
-
script:
|
|
917
|
-
value:
|
|
916
|
+
script: x.script,
|
|
917
|
+
value: x.value
|
|
918
918
|
});
|
|
919
|
-
const
|
|
919
|
+
const f = await this.config.btcWallet.signPsbt(i.toHex()), g = dt.fromHex(f);
|
|
920
920
|
try {
|
|
921
921
|
g.finalizeAllInputs();
|
|
922
|
-
} catch (
|
|
922
|
+
} catch (x) {
|
|
923
923
|
if (!g.data.inputs.every(
|
|
924
924
|
(m) => m.finalScriptWitness || m.finalScriptSig
|
|
925
925
|
))
|
|
926
926
|
throw new Error(
|
|
927
|
-
`PSBT finalization failed and wallet did not auto-finalize: ${
|
|
927
|
+
`PSBT finalization failed and wallet did not auto-finalize: ${x}`
|
|
928
928
|
);
|
|
929
929
|
}
|
|
930
|
-
const
|
|
931
|
-
return await
|
|
930
|
+
const b = g.extractTransaction().toHex();
|
|
931
|
+
return await Le(b, u);
|
|
932
932
|
}
|
|
933
933
|
/**
|
|
934
934
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -962,25 +962,28 @@ class is {
|
|
|
962
962
|
} = t;
|
|
963
963
|
if (!this.config.ethWallet.account)
|
|
964
964
|
throw new Error("Ethereum wallet account not found");
|
|
965
|
-
const
|
|
966
|
-
|
|
965
|
+
const f = this.config.ethWallet.account.address, g = await this.resolvePopSignature(
|
|
966
|
+
f,
|
|
967
967
|
l
|
|
968
968
|
);
|
|
969
969
|
c && await c();
|
|
970
|
-
const
|
|
970
|
+
const b = z(n), w = z(s), x = z(r), y = await this.resolvePayoutScriptPubKey(
|
|
971
971
|
u
|
|
972
|
-
), m = St(
|
|
973
|
-
|
|
972
|
+
), m = St(x), p = await Se(
|
|
973
|
+
$(m),
|
|
974
|
+
$(f)
|
|
975
|
+
), P = z(p);
|
|
976
|
+
if (await this.checkVaultExists(P))
|
|
974
977
|
throw new Error(
|
|
975
|
-
`Vault already exists
|
|
978
|
+
`Vault already exists (ID: ${P}, peginTxHash: ${m}). 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.`
|
|
976
979
|
);
|
|
977
|
-
const
|
|
980
|
+
const T = It({
|
|
978
981
|
chain: this.config.ethChain,
|
|
979
|
-
transport:
|
|
982
|
+
transport: Et()
|
|
980
983
|
});
|
|
981
|
-
let
|
|
984
|
+
let E;
|
|
982
985
|
try {
|
|
983
|
-
|
|
986
|
+
E = await T.readContract({
|
|
984
987
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
985
988
|
abi: ct,
|
|
986
989
|
functionName: "getPegInFee",
|
|
@@ -991,57 +994,58 @@ class is {
|
|
|
991
994
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
992
995
|
);
|
|
993
996
|
}
|
|
994
|
-
const
|
|
997
|
+
const H = Ie({
|
|
995
998
|
abi: ct,
|
|
996
999
|
functionName: "submitPeginRequest",
|
|
997
1000
|
args: [
|
|
998
|
-
|
|
999
|
-
|
|
1001
|
+
f,
|
|
1002
|
+
b,
|
|
1000
1003
|
g,
|
|
1001
1004
|
w,
|
|
1002
|
-
|
|
1005
|
+
x,
|
|
1003
1006
|
o,
|
|
1004
1007
|
i,
|
|
1005
1008
|
a,
|
|
1006
|
-
|
|
1009
|
+
y,
|
|
1007
1010
|
h
|
|
1008
1011
|
]
|
|
1009
1012
|
});
|
|
1010
1013
|
let I;
|
|
1011
1014
|
try {
|
|
1012
|
-
I = await
|
|
1015
|
+
I = await T.estimateGas({
|
|
1013
1016
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1014
|
-
data:
|
|
1015
|
-
value:
|
|
1017
|
+
data: H,
|
|
1018
|
+
value: E,
|
|
1016
1019
|
account: this.config.ethWallet.account.address
|
|
1017
1020
|
});
|
|
1018
|
-
} catch (
|
|
1019
|
-
ut(
|
|
1021
|
+
} catch (O) {
|
|
1022
|
+
ut(O);
|
|
1020
1023
|
}
|
|
1021
|
-
let
|
|
1024
|
+
let F;
|
|
1022
1025
|
try {
|
|
1023
|
-
|
|
1026
|
+
F = await this.config.ethWallet.sendTransaction({
|
|
1024
1027
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1025
|
-
data:
|
|
1026
|
-
value:
|
|
1028
|
+
data: H,
|
|
1029
|
+
value: E,
|
|
1027
1030
|
account: this.config.ethWallet.account,
|
|
1028
1031
|
chain: this.config.ethChain,
|
|
1029
1032
|
gas: I
|
|
1030
1033
|
});
|
|
1031
|
-
} catch (
|
|
1032
|
-
ut(
|
|
1034
|
+
} catch (O) {
|
|
1035
|
+
ut(O);
|
|
1033
1036
|
}
|
|
1034
|
-
const
|
|
1035
|
-
hash:
|
|
1036
|
-
timeout:
|
|
1037
|
+
const K = await T.waitForTransactionReceipt({
|
|
1038
|
+
hash: F,
|
|
1039
|
+
timeout: Re
|
|
1037
1040
|
});
|
|
1038
|
-
return
|
|
1041
|
+
return K.status === "reverted" && ut(
|
|
1039
1042
|
new Error(
|
|
1040
|
-
`Transaction reverted. Hash: ${
|
|
1043
|
+
`Transaction reverted. Hash: ${F}. Check the transaction on block explorer for details.`
|
|
1041
1044
|
)
|
|
1042
1045
|
), {
|
|
1043
|
-
ethTxHash:
|
|
1044
|
-
vaultId:
|
|
1046
|
+
ethTxHash: K.transactionHash,
|
|
1047
|
+
vaultId: P,
|
|
1048
|
+
peginTxHash: m,
|
|
1045
1049
|
btcPopSignature: g
|
|
1046
1050
|
};
|
|
1047
1051
|
}
|
|
@@ -1053,15 +1057,15 @@ class is {
|
|
|
1053
1057
|
*/
|
|
1054
1058
|
async checkVaultExists(t) {
|
|
1055
1059
|
try {
|
|
1056
|
-
return (await
|
|
1060
|
+
return (await It({
|
|
1057
1061
|
chain: this.config.ethChain,
|
|
1058
|
-
transport:
|
|
1062
|
+
transport: Et()
|
|
1059
1063
|
}).readContract({
|
|
1060
1064
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1061
1065
|
abi: ct,
|
|
1062
1066
|
functionName: "getBTCVault",
|
|
1063
1067
|
args: [t]
|
|
1064
|
-
})).depositor !==
|
|
1068
|
+
})).depositor !== Ee;
|
|
1065
1069
|
} catch {
|
|
1066
1070
|
return !1;
|
|
1067
1071
|
}
|
|
@@ -1130,14 +1134,14 @@ class is {
|
|
|
1130
1134
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1131
1135
|
}
|
|
1132
1136
|
}
|
|
1133
|
-
class
|
|
1137
|
+
class cs {
|
|
1134
1138
|
/**
|
|
1135
1139
|
* Creates a new PayoutManager instance.
|
|
1136
1140
|
*
|
|
1137
1141
|
* @param config - Manager configuration including wallet
|
|
1138
1142
|
*/
|
|
1139
1143
|
constructor(t) {
|
|
1140
|
-
|
|
1144
|
+
d(this, "config");
|
|
1141
1145
|
this.config = t;
|
|
1142
1146
|
}
|
|
1143
1147
|
/**
|
|
@@ -1284,9 +1288,9 @@ class as {
|
|
|
1284
1288
|
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1285
1289
|
);
|
|
1286
1290
|
const s = S.from(
|
|
1287
|
-
|
|
1291
|
+
$(n),
|
|
1288
1292
|
"hex"
|
|
1289
|
-
), r =
|
|
1293
|
+
), r = q.fromHex($(t));
|
|
1290
1294
|
if (r.outs.length === 0)
|
|
1291
1295
|
throw new Error("Payout transaction has no outputs");
|
|
1292
1296
|
if (!r.outs.reduce(
|
|
@@ -1297,17 +1301,17 @@ class as {
|
|
|
1297
1301
|
);
|
|
1298
1302
|
}
|
|
1299
1303
|
}
|
|
1300
|
-
function
|
|
1304
|
+
function Ve(e) {
|
|
1301
1305
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1302
1306
|
}
|
|
1303
|
-
function
|
|
1307
|
+
function R(e, t = "") {
|
|
1304
1308
|
if (!Number.isSafeInteger(e) || e < 0) {
|
|
1305
1309
|
const n = t && `"${t}" `;
|
|
1306
1310
|
throw new Error(`${n}expected integer >= 0, got ${e}`);
|
|
1307
1311
|
}
|
|
1308
1312
|
}
|
|
1309
|
-
function
|
|
1310
|
-
const s =
|
|
1313
|
+
function V(e, t, n = "") {
|
|
1314
|
+
const s = Ve(e), r = e == null ? void 0 : e.length, o = t !== void 0;
|
|
1311
1315
|
if (!s || o && r !== t) {
|
|
1312
1316
|
const i = n && `"${n}" `, a = o ? ` of length ${t}` : "", c = s ? `length=${r}` : `type=${typeof e}`;
|
|
1313
1317
|
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
@@ -1317,60 +1321,60 @@ function R(e, t, n = "") {
|
|
|
1317
1321
|
function Nt(e) {
|
|
1318
1322
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1319
1323
|
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1320
|
-
|
|
1324
|
+
R(e.outputLen), R(e.blockLen);
|
|
1321
1325
|
}
|
|
1322
|
-
function
|
|
1326
|
+
function X(e, t = !0) {
|
|
1323
1327
|
if (e.destroyed)
|
|
1324
1328
|
throw new Error("Hash instance has been destroyed");
|
|
1325
1329
|
if (t && e.finished)
|
|
1326
1330
|
throw new Error("Hash#digest() has already been called");
|
|
1327
1331
|
}
|
|
1328
1332
|
function Xt(e, t) {
|
|
1329
|
-
|
|
1333
|
+
V(e, void 0, "digestInto() output");
|
|
1330
1334
|
const n = t.outputLen;
|
|
1331
1335
|
if (e.length < n)
|
|
1332
1336
|
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1333
1337
|
}
|
|
1334
|
-
function
|
|
1338
|
+
function Ke(e) {
|
|
1335
1339
|
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1336
1340
|
}
|
|
1337
1341
|
function A(...e) {
|
|
1338
1342
|
for (let t = 0; t < e.length; t++)
|
|
1339
1343
|
e[t].fill(0);
|
|
1340
1344
|
}
|
|
1341
|
-
function
|
|
1345
|
+
function rt(e) {
|
|
1342
1346
|
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
1343
1347
|
}
|
|
1344
1348
|
function B(e, t) {
|
|
1345
1349
|
return e << 32 - t | e >>> t;
|
|
1346
1350
|
}
|
|
1347
|
-
function
|
|
1351
|
+
function Z(e, t) {
|
|
1348
1352
|
return e << t | e >>> 32 - t >>> 0;
|
|
1349
1353
|
}
|
|
1350
|
-
const
|
|
1351
|
-
function
|
|
1354
|
+
const De = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1355
|
+
function Me(e) {
|
|
1352
1356
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1353
1357
|
}
|
|
1354
|
-
function
|
|
1358
|
+
function Ne(e) {
|
|
1355
1359
|
for (let t = 0; t < e.length; t++)
|
|
1356
|
-
e[t] =
|
|
1360
|
+
e[t] = Me(e[t]);
|
|
1357
1361
|
return e;
|
|
1358
1362
|
}
|
|
1359
|
-
const At =
|
|
1360
|
-
function
|
|
1363
|
+
const At = De ? (e) => e : Ne;
|
|
1364
|
+
function Xe(e) {
|
|
1361
1365
|
if (typeof e != "string")
|
|
1362
1366
|
throw new Error("string expected");
|
|
1363
1367
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1364
1368
|
}
|
|
1365
1369
|
function Bt(e, t = "") {
|
|
1366
|
-
return typeof e == "string" ?
|
|
1370
|
+
return typeof e == "string" ? Xe(e) : V(e, void 0, t);
|
|
1367
1371
|
}
|
|
1368
|
-
function
|
|
1372
|
+
function Ge(e, t) {
|
|
1369
1373
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1370
1374
|
throw new Error("options must be object or undefined");
|
|
1371
1375
|
return Object.assign(e, t);
|
|
1372
1376
|
}
|
|
1373
|
-
function
|
|
1377
|
+
function it(e, t = {}) {
|
|
1374
1378
|
const n = (r, o) => e(o).update(r).digest(), s = e(void 0);
|
|
1375
1379
|
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (r) => e(r), Object.assign(n, t), Object.freeze(n);
|
|
1376
1380
|
}
|
|
@@ -1379,13 +1383,13 @@ const Gt = (e) => ({
|
|
|
1379
1383
|
});
|
|
1380
1384
|
class jt {
|
|
1381
1385
|
constructor(t, n) {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
if (Nt(t),
|
|
1386
|
+
d(this, "oHash");
|
|
1387
|
+
d(this, "iHash");
|
|
1388
|
+
d(this, "blockLen");
|
|
1389
|
+
d(this, "outputLen");
|
|
1390
|
+
d(this, "finished", !1);
|
|
1391
|
+
d(this, "destroyed", !1);
|
|
1392
|
+
if (Nt(t), V(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1389
1393
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1390
1394
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1391
1395
|
const s = this.blockLen, r = new Uint8Array(s);
|
|
@@ -1398,10 +1402,10 @@ class jt {
|
|
|
1398
1402
|
this.oHash.update(r), A(r);
|
|
1399
1403
|
}
|
|
1400
1404
|
update(t) {
|
|
1401
|
-
return
|
|
1405
|
+
return X(this), this.iHash.update(t), this;
|
|
1402
1406
|
}
|
|
1403
1407
|
digestInto(t) {
|
|
1404
|
-
|
|
1408
|
+
X(this), V(t, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
1405
1409
|
}
|
|
1406
1410
|
digest() {
|
|
1407
1411
|
const t = new Uint8Array(this.oHash.outputLen);
|
|
@@ -1419,36 +1423,36 @@ class jt {
|
|
|
1419
1423
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1420
1424
|
}
|
|
1421
1425
|
}
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
function
|
|
1426
|
+
const yt = (e, t, n) => new jt(e, t).update(n).digest();
|
|
1427
|
+
yt.create = (e, t) => new jt(e, t);
|
|
1428
|
+
function je(e, t, n) {
|
|
1425
1429
|
return e & t ^ ~e & n;
|
|
1426
1430
|
}
|
|
1427
|
-
function
|
|
1431
|
+
function qe(e, t, n) {
|
|
1428
1432
|
return e & t ^ e & n ^ t & n;
|
|
1429
1433
|
}
|
|
1430
1434
|
class wt {
|
|
1431
1435
|
constructor(t, n, s, r) {
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
+
d(this, "blockLen");
|
|
1437
|
+
d(this, "outputLen");
|
|
1438
|
+
d(this, "padOffset");
|
|
1439
|
+
d(this, "isLE");
|
|
1436
1440
|
// For partial updates less than block size
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view =
|
|
1441
|
+
d(this, "buffer");
|
|
1442
|
+
d(this, "view");
|
|
1443
|
+
d(this, "finished", !1);
|
|
1444
|
+
d(this, "length", 0);
|
|
1445
|
+
d(this, "pos", 0);
|
|
1446
|
+
d(this, "destroyed", !1);
|
|
1447
|
+
this.blockLen = t, this.outputLen = n, this.padOffset = s, this.isLE = r, this.buffer = new Uint8Array(t), this.view = rt(this.buffer);
|
|
1444
1448
|
}
|
|
1445
1449
|
update(t) {
|
|
1446
|
-
|
|
1450
|
+
X(this), V(t);
|
|
1447
1451
|
const { view: n, buffer: s, blockLen: r } = this, o = t.length;
|
|
1448
1452
|
for (let i = 0; i < o; ) {
|
|
1449
1453
|
const a = Math.min(r - this.pos, o - i);
|
|
1450
1454
|
if (a === r) {
|
|
1451
|
-
const c =
|
|
1455
|
+
const c = rt(t);
|
|
1452
1456
|
for (; r <= o - i; i += r)
|
|
1453
1457
|
this.process(c, i);
|
|
1454
1458
|
continue;
|
|
@@ -1458,14 +1462,14 @@ class wt {
|
|
|
1458
1462
|
return this.length += t.length, this.roundClean(), this;
|
|
1459
1463
|
}
|
|
1460
1464
|
digestInto(t) {
|
|
1461
|
-
|
|
1465
|
+
X(this), Xt(t, this), this.finished = !0;
|
|
1462
1466
|
const { buffer: n, view: s, blockLen: r, isLE: o } = this;
|
|
1463
1467
|
let { pos: i } = this;
|
|
1464
1468
|
n[i++] = 128, A(this.buffer.subarray(i)), this.padOffset > r - i && (this.process(s, 0), i = 0);
|
|
1465
1469
|
for (let l = i; l < r; l++)
|
|
1466
1470
|
n[l] = 0;
|
|
1467
1471
|
s.setBigUint64(r - 8, BigInt(this.length * 8), o), this.process(s, 0);
|
|
1468
|
-
const a =
|
|
1472
|
+
const a = rt(t), c = this.outputLen;
|
|
1469
1473
|
if (c % 4)
|
|
1470
1474
|
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
1471
1475
|
const u = c / 4, h = this.get();
|
|
@@ -1489,7 +1493,7 @@ class wt {
|
|
|
1489
1493
|
return this._cloneInto();
|
|
1490
1494
|
}
|
|
1491
1495
|
}
|
|
1492
|
-
const
|
|
1496
|
+
const L = /* @__PURE__ */ Uint32Array.from([
|
|
1493
1497
|
1779033703,
|
|
1494
1498
|
3144134277,
|
|
1495
1499
|
1013904242,
|
|
@@ -1498,7 +1502,7 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1498
1502
|
2600822924,
|
|
1499
1503
|
528734635,
|
|
1500
1504
|
1541459225
|
|
1501
|
-
]),
|
|
1505
|
+
]), k = /* @__PURE__ */ Uint32Array.from([
|
|
1502
1506
|
1779033703,
|
|
1503
1507
|
4089235720,
|
|
1504
1508
|
3144134277,
|
|
@@ -1515,7 +1519,7 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1515
1519
|
4215389547,
|
|
1516
1520
|
1541459225,
|
|
1517
1521
|
327033209
|
|
1518
|
-
]),
|
|
1522
|
+
]), ze = /* @__PURE__ */ Uint8Array.from([
|
|
1519
1523
|
7,
|
|
1520
1524
|
4,
|
|
1521
1525
|
13,
|
|
@@ -1532,11 +1536,11 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1532
1536
|
14,
|
|
1533
1537
|
11,
|
|
1534
1538
|
8
|
|
1535
|
-
]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)),
|
|
1536
|
-
const n = [[qt], [
|
|
1539
|
+
]), qt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ze = qt.map((e) => (9 * e + 5) % 16), zt = /* @__PURE__ */ (() => {
|
|
1540
|
+
const n = [[qt], [Ze]];
|
|
1537
1541
|
for (let s = 0; s < 4; s++)
|
|
1538
1542
|
for (let r of n)
|
|
1539
|
-
r.push(r[s].map((o) =>
|
|
1543
|
+
r.push(r[s].map((o) => ze[o]));
|
|
1540
1544
|
return n;
|
|
1541
1545
|
})(), Zt = zt[0], Jt = zt[1], Yt = /* @__PURE__ */ [
|
|
1542
1546
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
@@ -1544,13 +1548,13 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1544
1548
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1545
1549
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1546
1550
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1547
|
-
].map((e) => Uint8Array.from(e)),
|
|
1551
|
+
].map((e) => Uint8Array.from(e)), Je = /* @__PURE__ */ Zt.map((e, t) => e.map((n) => Yt[t][n])), Ye = /* @__PURE__ */ Jt.map((e, t) => e.map((n) => Yt[t][n])), Qe = /* @__PURE__ */ Uint32Array.from([
|
|
1548
1552
|
0,
|
|
1549
1553
|
1518500249,
|
|
1550
1554
|
1859775393,
|
|
1551
1555
|
2400959708,
|
|
1552
1556
|
2840853838
|
|
1553
|
-
]),
|
|
1557
|
+
]), tn = /* @__PURE__ */ Uint32Array.from([
|
|
1554
1558
|
1352829926,
|
|
1555
1559
|
1548603684,
|
|
1556
1560
|
1836072691,
|
|
@@ -1560,15 +1564,15 @@ const F = /* @__PURE__ */ Uint32Array.from([
|
|
|
1560
1564
|
function $t(e, t, n, s) {
|
|
1561
1565
|
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);
|
|
1562
1566
|
}
|
|
1563
|
-
const
|
|
1564
|
-
class
|
|
1567
|
+
const J = /* @__PURE__ */ new Uint32Array(16);
|
|
1568
|
+
class en extends wt {
|
|
1565
1569
|
constructor() {
|
|
1566
1570
|
super(64, 20, 8, !0);
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1571
|
+
d(this, "h0", 1732584193);
|
|
1572
|
+
d(this, "h1", -271733879);
|
|
1573
|
+
d(this, "h2", -1732584194);
|
|
1574
|
+
d(this, "h3", 271733878);
|
|
1575
|
+
d(this, "h4", -1009589776);
|
|
1572
1576
|
}
|
|
1573
1577
|
get() {
|
|
1574
1578
|
const { h0: n, h1: s, h2: r, h3: o, h4: i } = this;
|
|
@@ -1578,48 +1582,48 @@ class tn extends wt {
|
|
|
1578
1582
|
this.h0 = n | 0, this.h1 = s | 0, this.h2 = r | 0, this.h3 = o | 0, this.h4 = i | 0;
|
|
1579
1583
|
}
|
|
1580
1584
|
process(n, s) {
|
|
1581
|
-
for (let
|
|
1582
|
-
|
|
1583
|
-
let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, h = this.h3 | 0, l = h,
|
|
1584
|
-
for (let
|
|
1585
|
-
const w = 4 -
|
|
1586
|
-
for (let
|
|
1587
|
-
const
|
|
1588
|
-
r =
|
|
1585
|
+
for (let b = 0; b < 16; b++, s += 4)
|
|
1586
|
+
J[b] = n.getUint32(s, !0);
|
|
1587
|
+
let r = this.h0 | 0, o = r, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, h = this.h3 | 0, l = h, f = this.h4 | 0, g = f;
|
|
1588
|
+
for (let b = 0; b < 5; b++) {
|
|
1589
|
+
const w = 4 - b, x = Qe[b], y = tn[b], m = Zt[b], p = Jt[b], P = Je[b], v = Ye[b];
|
|
1590
|
+
for (let T = 0; T < 16; T++) {
|
|
1591
|
+
const E = Z(r + $t(b, i, c, h) + J[m[T]] + x, P[T]) + f | 0;
|
|
1592
|
+
r = f, f = h, h = Z(c, 10) | 0, c = i, i = E;
|
|
1589
1593
|
}
|
|
1590
|
-
for (let
|
|
1591
|
-
const
|
|
1592
|
-
o = g, g = l, l =
|
|
1594
|
+
for (let T = 0; T < 16; T++) {
|
|
1595
|
+
const E = Z(o + $t(w, a, u, l) + J[p[T]] + y, v[T]) + g | 0;
|
|
1596
|
+
o = g, g = l, l = Z(u, 10) | 0, u = a, a = E;
|
|
1593
1597
|
}
|
|
1594
1598
|
}
|
|
1595
|
-
this.set(this.h1 + c + l | 0, this.h2 + h + g | 0, this.h3 +
|
|
1599
|
+
this.set(this.h1 + c + l | 0, this.h2 + h + g | 0, this.h3 + f + o | 0, this.h4 + r + a | 0, this.h0 + i + u | 0);
|
|
1596
1600
|
}
|
|
1597
1601
|
roundClean() {
|
|
1598
|
-
A(
|
|
1602
|
+
A(J);
|
|
1599
1603
|
}
|
|
1600
1604
|
destroy() {
|
|
1601
1605
|
this.destroyed = !0, A(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1602
1606
|
}
|
|
1603
1607
|
}
|
|
1604
|
-
const
|
|
1605
|
-
function
|
|
1606
|
-
return t ? { h: Number(e &
|
|
1608
|
+
const nn = /* @__PURE__ */ it(() => new en()), Y = /* @__PURE__ */ BigInt(2 ** 32 - 1), Ut = /* @__PURE__ */ BigInt(32);
|
|
1609
|
+
function sn(e, t = !1) {
|
|
1610
|
+
return t ? { h: Number(e & Y), l: Number(e >> Ut & Y) } : { h: Number(e >> Ut & Y) | 0, l: Number(e & Y) | 0 };
|
|
1607
1611
|
}
|
|
1608
1612
|
function Qt(e, t = !1) {
|
|
1609
1613
|
const n = e.length;
|
|
1610
1614
|
let s = new Uint32Array(n), r = new Uint32Array(n);
|
|
1611
1615
|
for (let o = 0; o < n; o++) {
|
|
1612
|
-
const { h: i, l: a } =
|
|
1616
|
+
const { h: i, l: a } = sn(e[o], t);
|
|
1613
1617
|
[s[o], r[o]] = [i, a];
|
|
1614
1618
|
}
|
|
1615
1619
|
return [s, r];
|
|
1616
1620
|
}
|
|
1617
|
-
const Ft = (e, t, n) => e >>> n, Ot = (e, t, n) => e << 32 - n | t >>> n,
|
|
1618
|
-
function
|
|
1621
|
+
const Ft = (e, t, n) => e >>> n, Ot = (e, t, n) => e << 32 - n | t >>> n, D = (e, t, n) => e >>> n | t << 32 - n, M = (e, t, n) => e << 32 - n | t >>> n, Q = (e, t, n) => e << 64 - n | t >>> n - 32, tt = (e, t, n) => e >>> n - 32 | t << 64 - n, rn = (e, t, n) => e << n | t >>> 32 - n, on = (e, t, n) => t << n | e >>> 32 - n, an = (e, t, n) => t << n - 32 | e >>> 64 - n, cn = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1622
|
+
function U(e, t, n, s) {
|
|
1619
1623
|
const r = (t >>> 0) + (s >>> 0);
|
|
1620
1624
|
return { h: e + n + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
1621
1625
|
}
|
|
1622
|
-
const
|
|
1626
|
+
const un = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), ln = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, hn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), fn = (e, t, n, s, r) => t + n + s + r + (e / 2 ** 32 | 0) | 0, dn = (e, t, n, s, r) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0) + (r >>> 0), pn = (e, t, n, s, r, o) => t + n + s + r + o + (e / 2 ** 32 | 0) | 0, bn = /* @__PURE__ */ Uint32Array.from([
|
|
1623
1627
|
1116352408,
|
|
1624
1628
|
1899447441,
|
|
1625
1629
|
3049323471,
|
|
@@ -1684,8 +1688,8 @@ const cn = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), un = (e, t, n, s) =>
|
|
|
1684
1688
|
2756734187,
|
|
1685
1689
|
3204031479,
|
|
1686
1690
|
3329325298
|
|
1687
|
-
]),
|
|
1688
|
-
class
|
|
1691
|
+
]), C = /* @__PURE__ */ new Uint32Array(64);
|
|
1692
|
+
class gn extends wt {
|
|
1689
1693
|
constructor(t) {
|
|
1690
1694
|
super(64, t, 8, !1);
|
|
1691
1695
|
}
|
|
@@ -1699,38 +1703,38 @@ class bn extends wt {
|
|
|
1699
1703
|
}
|
|
1700
1704
|
process(t, n) {
|
|
1701
1705
|
for (let l = 0; l < 16; l++, n += 4)
|
|
1702
|
-
|
|
1706
|
+
C[l] = t.getUint32(n, !1);
|
|
1703
1707
|
for (let l = 16; l < 64; l++) {
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1708
|
+
const f = C[l - 15], g = C[l - 2], b = B(f, 7) ^ B(f, 18) ^ f >>> 3, w = B(g, 17) ^ B(g, 19) ^ g >>> 10;
|
|
1709
|
+
C[l] = w + C[l - 7] + b + C[l - 16] | 0;
|
|
1706
1710
|
}
|
|
1707
1711
|
let { A: s, B: r, C: o, D: i, E: a, F: c, G: u, H: h } = this;
|
|
1708
1712
|
for (let l = 0; l < 64; l++) {
|
|
1709
|
-
const
|
|
1713
|
+
const f = B(a, 6) ^ B(a, 11) ^ B(a, 25), g = h + f + je(a, c, u) + bn[l] + C[l] | 0, w = (B(s, 2) ^ B(s, 13) ^ B(s, 22)) + qe(s, r, o) | 0;
|
|
1710
1714
|
h = u, u = c, c = a, a = i + g | 0, i = o, o = r, r = s, s = g + w | 0;
|
|
1711
1715
|
}
|
|
1712
1716
|
s = s + this.A | 0, r = r + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, u = u + this.G | 0, h = h + this.H | 0, this.set(s, r, o, i, a, c, u, h);
|
|
1713
1717
|
}
|
|
1714
1718
|
roundClean() {
|
|
1715
|
-
A(
|
|
1719
|
+
A(C);
|
|
1716
1720
|
}
|
|
1717
1721
|
destroy() {
|
|
1718
1722
|
this.set(0, 0, 0, 0, 0, 0, 0, 0), A(this.buffer);
|
|
1719
1723
|
}
|
|
1720
1724
|
}
|
|
1721
|
-
class
|
|
1725
|
+
class xn extends gn {
|
|
1722
1726
|
constructor() {
|
|
1723
1727
|
super(32);
|
|
1724
1728
|
// We cannot use array here since array allows indexing by variable
|
|
1725
1729
|
// which means optimizer/compiler cannot use registers.
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1730
|
+
d(this, "A", L[0] | 0);
|
|
1731
|
+
d(this, "B", L[1] | 0);
|
|
1732
|
+
d(this, "C", L[2] | 0);
|
|
1733
|
+
d(this, "D", L[3] | 0);
|
|
1734
|
+
d(this, "E", L[4] | 0);
|
|
1735
|
+
d(this, "F", L[5] | 0);
|
|
1736
|
+
d(this, "G", L[6] | 0);
|
|
1737
|
+
d(this, "H", L[7] | 0);
|
|
1734
1738
|
}
|
|
1735
1739
|
}
|
|
1736
1740
|
const te = Qt([
|
|
@@ -1814,88 +1818,88 @@ const te = Qt([
|
|
|
1814
1818
|
"0x597f299cfc657e2a",
|
|
1815
1819
|
"0x5fcb6fab3ad6faec",
|
|
1816
1820
|
"0x6c44198c4a475817"
|
|
1817
|
-
].map((e) => BigInt(e))), yn = te[0],
|
|
1818
|
-
class
|
|
1821
|
+
].map((e) => BigInt(e))), yn = te[0], wn = te[1], _ = /* @__PURE__ */ new Uint32Array(80), W = /* @__PURE__ */ new Uint32Array(80);
|
|
1822
|
+
class mn extends wt {
|
|
1819
1823
|
constructor(t) {
|
|
1820
1824
|
super(128, t, 16, !1);
|
|
1821
1825
|
}
|
|
1822
1826
|
// prettier-ignore
|
|
1823
1827
|
get() {
|
|
1824
|
-
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: u, El: h, Fh: l, Fl:
|
|
1825
|
-
return [t, n, s, r, o, i, a, c, u, h, l,
|
|
1828
|
+
const { Ah: t, Al: n, Bh: s, Bl: r, Ch: o, Cl: i, Dh: a, Dl: c, Eh: u, El: h, Fh: l, Fl: f, Gh: g, Gl: b, Hh: w, Hl: x } = this;
|
|
1829
|
+
return [t, n, s, r, o, i, a, c, u, h, l, f, g, b, w, x];
|
|
1826
1830
|
}
|
|
1827
1831
|
// prettier-ignore
|
|
1828
|
-
set(t, n, s, r, o, i, a, c, u, h, l,
|
|
1829
|
-
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = u | 0, this.El = h | 0, this.Fh = l | 0, this.Fl =
|
|
1832
|
+
set(t, n, s, r, o, i, a, c, u, h, l, f, g, b, w, x) {
|
|
1833
|
+
this.Ah = t | 0, this.Al = n | 0, this.Bh = s | 0, this.Bl = r | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = u | 0, this.El = h | 0, this.Fh = l | 0, this.Fl = f | 0, this.Gh = g | 0, this.Gl = b | 0, this.Hh = w | 0, this.Hl = x | 0;
|
|
1830
1834
|
}
|
|
1831
1835
|
process(t, n) {
|
|
1832
|
-
for (let
|
|
1833
|
-
|
|
1834
|
-
for (let
|
|
1835
|
-
const P =
|
|
1836
|
-
|
|
1836
|
+
for (let p = 0; p < 16; p++, n += 4)
|
|
1837
|
+
_[p] = t.getUint32(n), W[p] = t.getUint32(n += 4);
|
|
1838
|
+
for (let p = 16; p < 80; p++) {
|
|
1839
|
+
const P = _[p - 15] | 0, v = W[p - 15] | 0, T = D(P, v, 1) ^ D(P, v, 8) ^ Ft(P, v, 7), E = M(P, v, 1) ^ M(P, v, 8) ^ Ot(P, v, 7), H = _[p - 2] | 0, I = W[p - 2] | 0, F = D(H, I, 19) ^ Q(H, I, 61) ^ Ft(H, I, 6), K = M(H, I, 19) ^ tt(H, I, 61) ^ Ot(H, I, 6), O = hn(E, K, W[p - 7], W[p - 16]), at = fn(O, T, F, _[p - 7], _[p - 16]);
|
|
1840
|
+
_[p] = at | 0, W[p] = O | 0;
|
|
1837
1841
|
}
|
|
1838
|
-
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: u, Dl: h, Eh: l, El:
|
|
1839
|
-
for (let
|
|
1840
|
-
const P =
|
|
1841
|
-
|
|
1842
|
-
const Pt =
|
|
1843
|
-
s =
|
|
1842
|
+
let { Ah: s, Al: r, Bh: o, Bl: i, Ch: a, Cl: c, Dh: u, Dl: h, Eh: l, El: f, Fh: g, Fl: b, Gh: w, Gl: x, Hh: y, Hl: m } = this;
|
|
1843
|
+
for (let p = 0; p < 80; p++) {
|
|
1844
|
+
const P = D(l, f, 14) ^ D(l, f, 18) ^ Q(l, f, 41), v = M(l, f, 14) ^ M(l, f, 18) ^ tt(l, f, 41), T = l & g ^ ~l & w, E = f & b ^ ~f & x, H = dn(m, v, E, wn[p], W[p]), I = pn(H, y, P, T, yn[p], _[p]), F = H | 0, K = D(s, r, 28) ^ Q(s, r, 34) ^ Q(s, r, 39), O = M(s, r, 28) ^ tt(s, r, 34) ^ tt(s, r, 39), at = s & o ^ s & a ^ o & a, ae = r & i ^ r & c ^ i & c;
|
|
1845
|
+
y = w | 0, m = x | 0, w = g | 0, x = b | 0, g = l | 0, b = f | 0, { h: l, l: f } = U(u | 0, h | 0, I | 0, F | 0), u = a | 0, h = c | 0, a = o | 0, c = i | 0, o = s | 0, i = r | 0;
|
|
1846
|
+
const Pt = un(F, O, ae);
|
|
1847
|
+
s = ln(Pt, I, K, at), r = Pt | 0;
|
|
1844
1848
|
}
|
|
1845
|
-
({ h: s, l: r } =
|
|
1849
|
+
({ h: s, l: r } = U(this.Ah | 0, this.Al | 0, s | 0, r | 0)), { h: o, l: i } = U(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: c } = U(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: u, l: h } = U(this.Dh | 0, this.Dl | 0, u | 0, h | 0), { h: l, l: f } = U(this.Eh | 0, this.El | 0, l | 0, f | 0), { h: g, l: b } = U(this.Fh | 0, this.Fl | 0, g | 0, b | 0), { h: w, l: x } = U(this.Gh | 0, this.Gl | 0, w | 0, x | 0), { h: y, l: m } = U(this.Hh | 0, this.Hl | 0, y | 0, m | 0), this.set(s, r, o, i, a, c, u, h, l, f, g, b, w, x, y, m);
|
|
1846
1850
|
}
|
|
1847
1851
|
roundClean() {
|
|
1848
|
-
A(
|
|
1852
|
+
A(_, W);
|
|
1849
1853
|
}
|
|
1850
1854
|
destroy() {
|
|
1851
1855
|
A(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1852
1856
|
}
|
|
1853
1857
|
}
|
|
1854
|
-
class
|
|
1858
|
+
class Pn extends mn {
|
|
1855
1859
|
constructor() {
|
|
1856
1860
|
super(64);
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
const
|
|
1876
|
-
() => new
|
|
1861
|
+
d(this, "Ah", k[0] | 0);
|
|
1862
|
+
d(this, "Al", k[1] | 0);
|
|
1863
|
+
d(this, "Bh", k[2] | 0);
|
|
1864
|
+
d(this, "Bl", k[3] | 0);
|
|
1865
|
+
d(this, "Ch", k[4] | 0);
|
|
1866
|
+
d(this, "Cl", k[5] | 0);
|
|
1867
|
+
d(this, "Dh", k[6] | 0);
|
|
1868
|
+
d(this, "Dl", k[7] | 0);
|
|
1869
|
+
d(this, "Eh", k[8] | 0);
|
|
1870
|
+
d(this, "El", k[9] | 0);
|
|
1871
|
+
d(this, "Fh", k[10] | 0);
|
|
1872
|
+
d(this, "Fl", k[11] | 0);
|
|
1873
|
+
d(this, "Gh", k[12] | 0);
|
|
1874
|
+
d(this, "Gl", k[13] | 0);
|
|
1875
|
+
d(this, "Hh", k[14] | 0);
|
|
1876
|
+
d(this, "Hl", k[15] | 0);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
const Tn = /* @__PURE__ */ it(
|
|
1880
|
+
() => new xn(),
|
|
1877
1881
|
/* @__PURE__ */ Gt(1)
|
|
1878
|
-
), ee = /* @__PURE__ */
|
|
1879
|
-
() => new
|
|
1882
|
+
), ee = /* @__PURE__ */ it(
|
|
1883
|
+
() => new Pn(),
|
|
1880
1884
|
/* @__PURE__ */ Gt(3)
|
|
1881
|
-
),
|
|
1882
|
-
for (let e = 0, t =
|
|
1885
|
+
), vn = BigInt(0), G = BigInt(1), kn = BigInt(2), Hn = BigInt(7), In = BigInt(256), En = BigInt(113), ne = [], se = [], re = [];
|
|
1886
|
+
for (let e = 0, t = G, n = 1, s = 0; e < 24; e++) {
|
|
1883
1887
|
[n, s] = [s, (2 * n + 3 * s) % 5], ne.push(2 * (5 * s + n)), se.push((e + 1) * (e + 2) / 2 % 64);
|
|
1884
|
-
let r =
|
|
1888
|
+
let r = vn;
|
|
1885
1889
|
for (let o = 0; o < 7; o++)
|
|
1886
|
-
t = (t <<
|
|
1890
|
+
t = (t << G ^ (t >> Hn) * En) % In, t & kn && (r ^= G << (G << BigInt(o)) - G);
|
|
1887
1891
|
re.push(r);
|
|
1888
1892
|
}
|
|
1889
|
-
const oe = Qt(re, !0),
|
|
1890
|
-
function
|
|
1893
|
+
const oe = Qt(re, !0), Sn = oe[0], An = oe[1], Lt = (e, t, n) => n > 32 ? an(e, t, n) : rn(e, t, n), Ct = (e, t, n) => n > 32 ? cn(e, t, n) : on(e, t, n);
|
|
1894
|
+
function Bn(e, t = 24) {
|
|
1891
1895
|
const n = new Uint32Array(10);
|
|
1892
1896
|
for (let s = 24 - t; s < 24; s++) {
|
|
1893
1897
|
for (let i = 0; i < 10; i++)
|
|
1894
1898
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1895
1899
|
for (let i = 0; i < 10; i += 2) {
|
|
1896
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l = Lt(u, h, 1) ^ n[a],
|
|
1900
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, u = n[c], h = n[c + 1], l = Lt(u, h, 1) ^ n[a], f = Ct(u, h, 1) ^ n[a + 1];
|
|
1897
1901
|
for (let g = 0; g < 50; g += 10)
|
|
1898
|
-
e[i + g] ^= l, e[i + g + 1] ^=
|
|
1902
|
+
e[i + g] ^= l, e[i + g + 1] ^= f;
|
|
1899
1903
|
}
|
|
1900
1904
|
let r = e[2], o = e[3];
|
|
1901
1905
|
for (let i = 0; i < 24; i++) {
|
|
@@ -1908,36 +1912,36 @@ function An(e, t = 24) {
|
|
|
1908
1912
|
for (let a = 0; a < 10; a++)
|
|
1909
1913
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1910
1914
|
}
|
|
1911
|
-
e[0] ^=
|
|
1915
|
+
e[0] ^= Sn[s], e[1] ^= An[s];
|
|
1912
1916
|
}
|
|
1913
1917
|
A(n);
|
|
1914
1918
|
}
|
|
1915
1919
|
class mt {
|
|
1916
1920
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1917
1921
|
constructor(t, n, s, r = !1, o = 24) {
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o,
|
|
1922
|
+
d(this, "state");
|
|
1923
|
+
d(this, "pos", 0);
|
|
1924
|
+
d(this, "posOut", 0);
|
|
1925
|
+
d(this, "finished", !1);
|
|
1926
|
+
d(this, "state32");
|
|
1927
|
+
d(this, "destroyed", !1);
|
|
1928
|
+
d(this, "blockLen");
|
|
1929
|
+
d(this, "suffix");
|
|
1930
|
+
d(this, "outputLen");
|
|
1931
|
+
d(this, "enableXOF", !1);
|
|
1932
|
+
d(this, "rounds");
|
|
1933
|
+
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = r, this.rounds = o, R(s, "outputLen"), !(0 < t && t < 200))
|
|
1930
1934
|
throw new Error("only keccak-f1600 function is supported");
|
|
1931
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
1935
|
+
this.state = new Uint8Array(200), this.state32 = Ke(this.state);
|
|
1932
1936
|
}
|
|
1933
1937
|
clone() {
|
|
1934
1938
|
return this._cloneInto();
|
|
1935
1939
|
}
|
|
1936
1940
|
keccak() {
|
|
1937
|
-
At(this.state32),
|
|
1941
|
+
At(this.state32), Bn(this.state32, this.rounds), At(this.state32), this.posOut = 0, this.pos = 0;
|
|
1938
1942
|
}
|
|
1939
1943
|
update(t) {
|
|
1940
|
-
|
|
1944
|
+
X(this), V(t);
|
|
1941
1945
|
const { blockLen: n, state: s } = this, r = t.length;
|
|
1942
1946
|
for (let o = 0; o < r; ) {
|
|
1943
1947
|
const i = Math.min(n - this.pos, r - o);
|
|
@@ -1955,7 +1959,7 @@ class mt {
|
|
|
1955
1959
|
t[s] ^= n, (n & 128) !== 0 && s === r - 1 && this.keccak(), t[r - 1] ^= 128, this.keccak();
|
|
1956
1960
|
}
|
|
1957
1961
|
writeInto(t) {
|
|
1958
|
-
|
|
1962
|
+
X(this, !1), V(t), this.finish();
|
|
1959
1963
|
const n = this.state, { blockLen: s } = this;
|
|
1960
1964
|
for (let r = 0, o = t.length; r < o; ) {
|
|
1961
1965
|
this.posOut >= s && this.keccak();
|
|
@@ -1970,7 +1974,7 @@ class mt {
|
|
|
1970
1974
|
return this.writeInto(t);
|
|
1971
1975
|
}
|
|
1972
1976
|
xof(t) {
|
|
1973
|
-
return
|
|
1977
|
+
return R(t), this.xofInto(new Uint8Array(t));
|
|
1974
1978
|
}
|
|
1975
1979
|
digestInto(t) {
|
|
1976
1980
|
if (Xt(t, this), this.finished)
|
|
@@ -1988,50 +1992,50 @@ class mt {
|
|
|
1988
1992
|
return t || (t = new mt(n, s, r, i, o)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = o, t.suffix = s, t.outputLen = r, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
1989
1993
|
}
|
|
1990
1994
|
}
|
|
1991
|
-
const
|
|
1992
|
-
function
|
|
1995
|
+
const $n = (e, t, n, s = {}) => it(() => new mt(t, e, n), s), Un = /* @__PURE__ */ $n(1, 136, 32);
|
|
1996
|
+
function Fn(e, t, n, s) {
|
|
1993
1997
|
Nt(e);
|
|
1994
|
-
const r =
|
|
1995
|
-
if (
|
|
1998
|
+
const r = Ge({ dkLen: 32, asyncTick: 10 }, s), { c: o, dkLen: i, asyncTick: a } = r;
|
|
1999
|
+
if (R(o, "c"), R(i, "dkLen"), R(a, "asyncTick"), o < 1)
|
|
1996
2000
|
throw new Error("iterations (c) must be >= 1");
|
|
1997
|
-
const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l =
|
|
1998
|
-
return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt:
|
|
2001
|
+
const c = Bt(t, "password"), u = Bt(n, "salt"), h = new Uint8Array(i), l = yt.create(e, c), f = l._cloneInto().update(u);
|
|
2002
|
+
return { c: o, dkLen: i, asyncTick: a, DK: h, PRF: l, PRFSalt: f };
|
|
1999
2003
|
}
|
|
2000
|
-
function
|
|
2004
|
+
function On(e, t, n, s, r) {
|
|
2001
2005
|
return e.destroy(), t.destroy(), s && s.destroy(), A(r), n;
|
|
2002
2006
|
}
|
|
2003
|
-
function
|
|
2004
|
-
const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } =
|
|
2007
|
+
function Ln(e, t, n, s) {
|
|
2008
|
+
const { c: r, dkLen: o, DK: i, PRF: a, PRFSalt: c } = Fn(e, t, n, s);
|
|
2005
2009
|
let u;
|
|
2006
|
-
const h = new Uint8Array(4), l =
|
|
2007
|
-
for (let g = 1,
|
|
2008
|
-
const w = i.subarray(
|
|
2009
|
-
l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(
|
|
2010
|
-
for (let
|
|
2011
|
-
a._cloneInto(u).update(
|
|
2012
|
-
for (let
|
|
2013
|
-
w[
|
|
2010
|
+
const h = new Uint8Array(4), l = rt(h), f = new Uint8Array(a.outputLen);
|
|
2011
|
+
for (let g = 1, b = 0; b < o; g++, b += a.outputLen) {
|
|
2012
|
+
const w = i.subarray(b, b + a.outputLen);
|
|
2013
|
+
l.setInt32(0, g, !1), (u = c._cloneInto(u)).update(h).digestInto(f), w.set(f.subarray(0, w.length));
|
|
2014
|
+
for (let x = 1; x < r; x++) {
|
|
2015
|
+
a._cloneInto(u).update(f).digestInto(f);
|
|
2016
|
+
for (let y = 0; y < w.length; y++)
|
|
2017
|
+
w[y] ^= f[y];
|
|
2014
2018
|
}
|
|
2015
2019
|
}
|
|
2016
|
-
return
|
|
2020
|
+
return On(a, c, i, u, f);
|
|
2017
2021
|
}
|
|
2018
2022
|
function ie(e) {
|
|
2019
2023
|
if (typeof e != "string")
|
|
2020
2024
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
2021
2025
|
return e.normalize("NFKD");
|
|
2022
2026
|
}
|
|
2023
|
-
function
|
|
2027
|
+
function Cn(e) {
|
|
2024
2028
|
const t = ie(e), n = t.split(" ");
|
|
2025
2029
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
2026
2030
|
throw new Error("Invalid mnemonic");
|
|
2027
2031
|
return { nfkd: t, words: n };
|
|
2028
2032
|
}
|
|
2029
|
-
const
|
|
2030
|
-
function
|
|
2031
|
-
return
|
|
2033
|
+
const _n = (e) => ie("mnemonic" + e);
|
|
2034
|
+
function Wn(e, t = "") {
|
|
2035
|
+
return Ln(ee, Cn(e).nfkd, _n(t), { c: 2048, dkLen: 64 });
|
|
2032
2036
|
}
|
|
2033
|
-
const
|
|
2034
|
-
function
|
|
2037
|
+
const Rn = 508, _t = 16, et = 32, nt = 64, Wt = 5, Vn = 4;
|
|
2038
|
+
function j(...e) {
|
|
2035
2039
|
const t = e.reduce((r, o) => r + o.length, 0), n = new Uint8Array(t);
|
|
2036
2040
|
let s = 0;
|
|
2037
2041
|
for (const r of e)
|
|
@@ -2042,59 +2046,59 @@ function lt(e) {
|
|
|
2042
2046
|
return new TextEncoder().encode(e);
|
|
2043
2047
|
}
|
|
2044
2048
|
function ht(e) {
|
|
2045
|
-
const t = new Uint8Array(
|
|
2046
|
-
return new DataView(t.buffer).setUint32(0, e.length, !1),
|
|
2049
|
+
const t = new Uint8Array(Vn);
|
|
2050
|
+
return new DataView(t.buffer).setUint32(0, e.length, !1), j(t, e);
|
|
2047
2051
|
}
|
|
2048
2052
|
function ft(e, t) {
|
|
2049
|
-
return
|
|
2053
|
+
return yt(ee, e, t);
|
|
2050
2054
|
}
|
|
2051
2055
|
function Rt(e) {
|
|
2052
|
-
return
|
|
2056
|
+
return nn(Tn(e));
|
|
2053
2057
|
}
|
|
2054
2058
|
const gt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2055
|
-
function
|
|
2056
|
-
const t =
|
|
2059
|
+
function Kn(e) {
|
|
2060
|
+
const t = Wn(e), n = new Uint8Array(t);
|
|
2057
2061
|
return t.fill(0), n;
|
|
2058
2062
|
}
|
|
2059
|
-
async function
|
|
2060
|
-
if (e.length !==
|
|
2063
|
+
async function Dn(e, t, n, s) {
|
|
2064
|
+
if (e.length !== nt)
|
|
2061
2065
|
throw new Error(
|
|
2062
|
-
`WOTS seed must be ${
|
|
2066
|
+
`WOTS seed must be ${nt} bytes, got ${e.length}`
|
|
2063
2067
|
);
|
|
2064
|
-
t =
|
|
2065
|
-
const r = e.slice(
|
|
2068
|
+
t = $(t), n = $(n);
|
|
2069
|
+
const r = e.slice(et, nt), o = e.slice(0, et), i = [r, o];
|
|
2066
2070
|
try {
|
|
2067
|
-
const a =
|
|
2071
|
+
const a = j(
|
|
2068
2072
|
ht(lt(t)),
|
|
2069
2073
|
ht(lt(n)),
|
|
2070
2074
|
ht(lt(s))
|
|
2071
|
-
), c =
|
|
2075
|
+
), c = j(o, a);
|
|
2072
2076
|
i.push(c);
|
|
2073
2077
|
const u = ft(r, c);
|
|
2074
2078
|
i.push(u);
|
|
2075
|
-
const h = u.slice(0,
|
|
2079
|
+
const h = u.slice(0, et), l = u.slice(et, nt);
|
|
2076
2080
|
i.push(h, l);
|
|
2077
|
-
const
|
|
2078
|
-
let
|
|
2081
|
+
const f = [], g = [], b = [], w = [];
|
|
2082
|
+
let x = !1;
|
|
2079
2083
|
try {
|
|
2080
|
-
for (let
|
|
2084
|
+
for (let y = 0; y < Rn; y++) {
|
|
2081
2085
|
const m = new Uint8Array(Wt);
|
|
2082
|
-
m[0] = 0, new DataView(m.buffer).setUint32(1,
|
|
2083
|
-
const
|
|
2084
|
-
|
|
2085
|
-
const P =
|
|
2086
|
+
m[0] = 0, new DataView(m.buffer).setUint32(1, y, !1);
|
|
2087
|
+
const p = new Uint8Array(Wt);
|
|
2088
|
+
p[0] = 1, new DataView(p.buffer).setUint32(1, y, !1);
|
|
2089
|
+
const P = j(h, m), v = j(h, p), T = ft(l, P), E = ft(l, v);
|
|
2086
2090
|
try {
|
|
2087
|
-
const
|
|
2088
|
-
|
|
2091
|
+
const H = T.slice(0, _t), I = E.slice(0, _t);
|
|
2092
|
+
f.push(H), g.push(I), b.push(Rt(H)), w.push(Rt(I));
|
|
2089
2093
|
} finally {
|
|
2090
|
-
P.fill(0),
|
|
2094
|
+
P.fill(0), v.fill(0), T.fill(0), E.fill(0);
|
|
2091
2095
|
}
|
|
2092
2096
|
}
|
|
2093
|
-
return
|
|
2097
|
+
return x = !0, { falsePreimages: f, truePreimages: g, falseHashes: b, trueHashes: w };
|
|
2094
2098
|
} finally {
|
|
2095
|
-
if (!
|
|
2096
|
-
for (const
|
|
2097
|
-
for (const
|
|
2099
|
+
if (!x) {
|
|
2100
|
+
for (const y of f) y.fill(0);
|
|
2101
|
+
for (const y of g) y.fill(0);
|
|
2098
2102
|
}
|
|
2099
2103
|
}
|
|
2100
2104
|
} finally {
|
|
@@ -2102,13 +2106,13 @@ async function Kn(e, t, n, s) {
|
|
|
2102
2106
|
a.fill(0);
|
|
2103
2107
|
}
|
|
2104
2108
|
}
|
|
2105
|
-
function
|
|
2109
|
+
function us(e) {
|
|
2106
2110
|
return {
|
|
2107
2111
|
false_list: e.falseHashes.map(gt),
|
|
2108
2112
|
true_list: e.trueHashes.map(gt)
|
|
2109
2113
|
};
|
|
2110
2114
|
}
|
|
2111
|
-
function
|
|
2115
|
+
function Mn(e) {
|
|
2112
2116
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2113
2117
|
throw new Error(
|
|
2114
2118
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
@@ -2119,20 +2123,20 @@ function Dn(e) {
|
|
|
2119
2123
|
s.set(i, r), r += t;
|
|
2120
2124
|
for (const i of e.trueHashes)
|
|
2121
2125
|
s.set(i, r), r += t;
|
|
2122
|
-
const o =
|
|
2126
|
+
const o = Un(s);
|
|
2123
2127
|
return `0x${gt(o)}`;
|
|
2124
2128
|
}
|
|
2125
|
-
async function
|
|
2126
|
-
const r =
|
|
2129
|
+
async function ls(e, t, n, s) {
|
|
2130
|
+
const r = Kn(e);
|
|
2127
2131
|
try {
|
|
2128
|
-
const o = await
|
|
2132
|
+
const o = await Dn(
|
|
2129
2133
|
r,
|
|
2130
2134
|
t,
|
|
2131
2135
|
n,
|
|
2132
2136
|
s
|
|
2133
2137
|
);
|
|
2134
2138
|
try {
|
|
2135
|
-
return
|
|
2139
|
+
return Mn(o);
|
|
2136
2140
|
} finally {
|
|
2137
2141
|
for (const i of o.falsePreimages) i.fill(0);
|
|
2138
2142
|
for (const i of o.truePreimages) i.fill(0);
|
|
@@ -2141,43 +2145,43 @@ async function us(e, t, n, s) {
|
|
|
2141
2145
|
r.fill(0);
|
|
2142
2146
|
}
|
|
2143
2147
|
}
|
|
2144
|
-
function
|
|
2148
|
+
function hs(e) {
|
|
2145
2149
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2146
2150
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2147
2151
|
}
|
|
2148
2152
|
export {
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2153
|
+
Mn as A,
|
|
2154
|
+
st as B,
|
|
2155
|
+
N as C,
|
|
2156
|
+
ls as D,
|
|
2157
|
+
hs as E,
|
|
2158
|
+
Oe as M,
|
|
2159
|
+
as as P,
|
|
2160
|
+
Zn as a,
|
|
2161
|
+
Yn as b,
|
|
2158
2162
|
St as c,
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
+
Qn as d,
|
|
2164
|
+
Be as e,
|
|
2165
|
+
$e as f,
|
|
2166
|
+
Jn as g,
|
|
2163
2167
|
bt as h,
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2168
|
+
cs as i,
|
|
2169
|
+
ss as j,
|
|
2170
|
+
es as k,
|
|
2171
|
+
ns as l,
|
|
2172
|
+
rs as m,
|
|
2173
|
+
ts as n,
|
|
2174
|
+
Ce as o,
|
|
2175
|
+
_e as p,
|
|
2176
|
+
Le as q,
|
|
2173
2177
|
ct as r,
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
+
Ae as s,
|
|
2179
|
+
xt as t,
|
|
2180
|
+
os as u,
|
|
2181
|
+
is as v,
|
|
2178
2182
|
ut as w,
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2183
|
+
Kn as x,
|
|
2184
|
+
Dn as y,
|
|
2185
|
+
us as z
|
|
2182
2186
|
};
|
|
2183
|
-
//# sourceMappingURL=errors-
|
|
2187
|
+
//# sourceMappingURL=errors-D19BQSaj.js.map
|