@babylonlabs-io/ts-sdk 0.16.0 → 0.16.1
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-Bk7eb5h3.cjs +2 -0
- package/dist/errors-Bk7eb5h3.cjs.map +1 -0
- package/dist/{errors-BEUjAw2k.js → errors-Ld-2tiK3.js} +335 -316
- package/dist/errors-Ld-2tiK3.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +1 -1
- package/package.json +1 -1
- package/dist/errors-BEUjAw2k.js.map +0 -1
- package/dist/errors-DnMc1lLU.cjs +0 -2
- package/dist/errors-DnMc1lLU.cjs.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var p = (e, t, n) =>
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
1
|
+
var fe = Object.defineProperty;
|
|
2
|
+
var pe = (e, t, n) => t in e ? fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var p = (e, t, n) => pe(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import * as ye from "bitcoinjs-lib";
|
|
5
|
+
import { script as be, Transaction as xt, Psbt as kt } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as W } from "buffer";
|
|
7
|
-
import { createPublicClient as
|
|
8
|
-
import { P as
|
|
9
|
-
import { deriveVaultId as
|
|
10
|
-
function
|
|
7
|
+
import { createPublicClient as lt, http as ht, encodeFunctionData as Ht, zeroAddress as ge } from "viem";
|
|
8
|
+
import { P as xe, y as me, D as Xt, M as Et, B as we, T as Pe, u as S, b as Te, A as ve, G as It, E as ke, a as He, d as Ee, e as Ie, f as Se, s as C, H as Be, q as Ae, x as St, h as Bt, i as At, r as Ce } from "./challengeAssert-C5DQSUnp.js";
|
|
9
|
+
import { deriveVaultId as Ct } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
10
|
+
function Ue(e, t, n, s) {
|
|
11
11
|
if (!Number.isInteger(s) || s < 1)
|
|
12
12
|
throw new Error(
|
|
13
13
|
`Invalid numOutputs: expected a positive integer, got ${s}`
|
|
@@ -16,7 +16,7 @@ function Ae(e, t, n, s) {
|
|
|
16
16
|
throw new Error("Insufficient funds: no UTXOs available");
|
|
17
17
|
const o = e.filter((l) => {
|
|
18
18
|
const h = W.from(l.scriptPubKey, "hex");
|
|
19
|
-
return !!
|
|
19
|
+
return !!be.decompile(h);
|
|
20
20
|
});
|
|
21
21
|
if (o.length === 0)
|
|
22
22
|
throw new Error(
|
|
@@ -26,10 +26,10 @@ function Ae(e, t, n, s) {
|
|
|
26
26
|
let a = 0n, c = 0n;
|
|
27
27
|
for (const l of r) {
|
|
28
28
|
i.push(l), a += BigInt(l.value);
|
|
29
|
-
const h = i.length *
|
|
30
|
-
if (c = BigInt(Math.ceil(d * n)) + BigInt(
|
|
29
|
+
const h = i.length * xe, u = s * Et, d = h + u + Pe;
|
|
30
|
+
if (c = BigInt(Math.ceil(d * n)) + BigInt(me(n)), a - t - c > Xt) {
|
|
31
31
|
const y = BigInt(
|
|
32
|
-
Math.ceil(
|
|
32
|
+
Math.ceil(Et * n)
|
|
33
33
|
);
|
|
34
34
|
c += y;
|
|
35
35
|
}
|
|
@@ -47,18 +47,18 @@ function Ae(e, t, n, s) {
|
|
|
47
47
|
`Insufficient funds: need ${t + c} sats (${t} pegin + ${c} fee), have ${a} sats`
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return e >
|
|
50
|
+
function Yn(e) {
|
|
51
|
+
return e > Xt;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
53
|
+
function ts() {
|
|
54
|
+
return we;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function dt(e) {
|
|
57
57
|
const t = e.startsWith("0x") ? e.slice(2) : e;
|
|
58
|
-
return `0x${
|
|
58
|
+
return `0x${xt.fromHex(t).getId()}`;
|
|
59
59
|
}
|
|
60
60
|
var ot = /* @__PURE__ */ ((e) => (e.P2PKH = "P2PKH", e.P2SH = "P2SH", e.P2WPKH = "P2WPKH", e.P2WSH = "P2WSH", e.P2TR = "P2TR", e.UNKNOWN = "UNKNOWN", e))(ot || {});
|
|
61
|
-
function
|
|
61
|
+
function Fe(e) {
|
|
62
62
|
const t = e.length;
|
|
63
63
|
return t === 25 && e[0] === 118 && // OP_DUP
|
|
64
64
|
e[1] === 169 && // OP_HASH160
|
|
@@ -71,8 +71,8 @@ function Ce(e) {
|
|
|
71
71
|
e[1] === 32 ? "P2WSH" : t === 34 && e[0] === 81 && // OP_1
|
|
72
72
|
e[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const n = W.from(e.scriptPubKey, "hex"), s =
|
|
74
|
+
function $e(e, t) {
|
|
75
|
+
const n = W.from(e.scriptPubKey, "hex"), s = Fe(n);
|
|
76
76
|
switch (s) {
|
|
77
77
|
case ot.P2WPKH:
|
|
78
78
|
return {
|
|
@@ -110,7 +110,7 @@ function Fe(e, t) {
|
|
|
110
110
|
throw new Error(`Unsupported script type: ${s}`);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function bt(e, t) {
|
|
114
114
|
if (!Number.isInteger(t) || t < 1)
|
|
115
115
|
throw new Error(`inputCount must be a positive integer, got ${t}`);
|
|
116
116
|
return {
|
|
@@ -122,24 +122,43 @@ function yt(e, t) {
|
|
|
122
122
|
}))
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
function
|
|
127
|
-
|
|
125
|
+
const Oe = 21e6 * 1e8, Ut = 3e4;
|
|
126
|
+
async function at(e, t) {
|
|
127
|
+
const n = new AbortController(), s = setTimeout(
|
|
128
|
+
() => n.abort(),
|
|
129
|
+
Ut
|
|
130
|
+
), o = [n.signal, t == null ? void 0 : t.signal].filter(
|
|
131
|
+
Boolean
|
|
132
|
+
);
|
|
133
|
+
try {
|
|
134
|
+
return await fetch(e, {
|
|
135
|
+
...t,
|
|
136
|
+
signal: AbortSignal.any(o)
|
|
137
|
+
});
|
|
138
|
+
} catch (r) {
|
|
139
|
+
throw clearTimeout(s), r != null && typeof r == "object" && "name" in r && r.name === "AbortError" ? new Error(
|
|
140
|
+
`Mempool API request timed out after ${Ut}ms: ${e}`
|
|
141
|
+
) : r;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const qt = 1e4;
|
|
145
|
+
function Gt(e) {
|
|
146
|
+
return Number.isInteger(e) && e > 0 && e <= Oe;
|
|
128
147
|
}
|
|
129
|
-
function
|
|
130
|
-
return Number.isInteger(e) && e > 0 && e <=
|
|
148
|
+
function Le(e) {
|
|
149
|
+
return Number.isInteger(e) && e > 0 && e <= qt;
|
|
131
150
|
}
|
|
132
|
-
function
|
|
151
|
+
function jt(e, t) {
|
|
133
152
|
return !Number.isInteger(e) || e < 0 ? !1 : t === void 0 || e < t;
|
|
134
153
|
}
|
|
135
|
-
const
|
|
154
|
+
const _e = {
|
|
136
155
|
mainnet: "https://mempool.space/api",
|
|
137
156
|
testnet: "https://mempool.space/testnet/api",
|
|
138
157
|
signet: "https://mempool.space/signet/api"
|
|
139
158
|
};
|
|
140
159
|
async function it(e, t) {
|
|
141
160
|
try {
|
|
142
|
-
const n = await
|
|
161
|
+
const n = await at(e, t);
|
|
143
162
|
if (!n.ok) {
|
|
144
163
|
const o = await n.text();
|
|
145
164
|
throw new Error(
|
|
@@ -152,9 +171,9 @@ async function it(e, t) {
|
|
|
152
171
|
throw n instanceof Error ? new Error(`Failed to fetch from mempool API: ${n.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
153
172
|
}
|
|
154
173
|
}
|
|
155
|
-
async function
|
|
174
|
+
async function Re(e, t) {
|
|
156
175
|
try {
|
|
157
|
-
const n = await
|
|
176
|
+
const n = await at(`${t}/tx`, {
|
|
158
177
|
method: "POST",
|
|
159
178
|
body: e,
|
|
160
179
|
headers: {
|
|
@@ -178,12 +197,12 @@ async function Le(e, t) {
|
|
|
178
197
|
throw n instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${n.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
179
198
|
}
|
|
180
199
|
}
|
|
181
|
-
async function
|
|
200
|
+
async function We(e, t) {
|
|
182
201
|
return it(`${t}/tx/${e}`);
|
|
183
202
|
}
|
|
184
|
-
async function
|
|
203
|
+
async function es(e, t) {
|
|
185
204
|
try {
|
|
186
|
-
const n = await
|
|
205
|
+
const n = await at(`${t}/tx/${e}/hex`);
|
|
187
206
|
if (!n.ok) {
|
|
188
207
|
const s = await n.text();
|
|
189
208
|
throw new Error(
|
|
@@ -195,14 +214,14 @@ async function Qn(e, t) {
|
|
|
195
214
|
throw n instanceof Error ? new Error(`Failed to get transaction hex for ${e}: ${n.message}`) : new Error(`Failed to get transaction hex for ${e}: Unknown error`);
|
|
196
215
|
}
|
|
197
216
|
}
|
|
198
|
-
async function
|
|
199
|
-
const s = await
|
|
200
|
-
if (!
|
|
217
|
+
async function Ve(e, t, n) {
|
|
218
|
+
const s = await We(e, n);
|
|
219
|
+
if (!jt(t, s.vout.length))
|
|
201
220
|
throw new Error(
|
|
202
221
|
`Invalid vout ${t} for transaction ${e} (has ${s.vout.length} outputs)`
|
|
203
222
|
);
|
|
204
223
|
const o = s.vout[t];
|
|
205
|
-
if (!
|
|
224
|
+
if (!Gt(o.value))
|
|
206
225
|
throw new Error(`Invalid UTXO value ${o.value} for ${e}:${t}`);
|
|
207
226
|
return {
|
|
208
227
|
txid: e,
|
|
@@ -211,7 +230,7 @@ async function Re(e, t, n) {
|
|
|
211
230
|
scriptPubKey: o.scriptpubkey
|
|
212
231
|
};
|
|
213
232
|
}
|
|
214
|
-
async function
|
|
233
|
+
async function ns(e, t) {
|
|
215
234
|
try {
|
|
216
235
|
const n = await it(`${t}/address/${e}/utxo`), s = await it(`${t}/v1/validate-address/${e}`);
|
|
217
236
|
if (!s.isvalid)
|
|
@@ -219,9 +238,9 @@ async function ts(e, t) {
|
|
|
219
238
|
`Invalid Bitcoin address: ${e}. Mempool API validation failed.`
|
|
220
239
|
);
|
|
221
240
|
for (const r of n) {
|
|
222
|
-
if (!
|
|
241
|
+
if (!jt(r.vout))
|
|
223
242
|
throw new Error(`Invalid vout ${r.vout} for ${r.txid}`);
|
|
224
|
-
if (!
|
|
243
|
+
if (!Gt(r.value))
|
|
225
244
|
throw new Error(
|
|
226
245
|
`Invalid UTXO value ${r.value} for ${r.txid}:${r.vout}`
|
|
227
246
|
);
|
|
@@ -241,14 +260,14 @@ async function ts(e, t) {
|
|
|
241
260
|
);
|
|
242
261
|
}
|
|
243
262
|
}
|
|
244
|
-
function
|
|
245
|
-
return
|
|
263
|
+
function ss(e) {
|
|
264
|
+
return _e[e];
|
|
246
265
|
}
|
|
247
|
-
async function
|
|
266
|
+
async function os(e, t) {
|
|
248
267
|
return it(`${t}/address/${e}/txs`);
|
|
249
268
|
}
|
|
250
|
-
async function
|
|
251
|
-
const t = await
|
|
269
|
+
async function rs(e) {
|
|
270
|
+
const t = await at(`${e}/v1/fees/recommended`);
|
|
252
271
|
if (!t.ok)
|
|
253
272
|
throw new Error(
|
|
254
273
|
`Failed to fetch network fees: ${t.status} ${t.statusText}`
|
|
@@ -261,9 +280,9 @@ async function ss(e) {
|
|
|
261
280
|
"minimumFee"
|
|
262
281
|
];
|
|
263
282
|
for (const o of s)
|
|
264
|
-
if (
|
|
283
|
+
if (!Le(n[o]))
|
|
265
284
|
throw new Error(
|
|
266
|
-
`Invalid fee rate ${o}=${n[o]} from mempool API: expected a positive number ≤ ${
|
|
285
|
+
`Invalid fee rate ${o}=${n[o]} from mempool API: expected a positive number ≤ ${qt}`
|
|
267
286
|
);
|
|
268
287
|
if (n.minimumFee > n.economyFee || n.economyFee > n.hourFee || n.hourFee > n.halfHourFee || n.halfHourFee > n.fastestFee)
|
|
269
288
|
throw new Error(
|
|
@@ -594,7 +613,7 @@ const j = [
|
|
|
594
613
|
// InvalidPeginFee(uint256,uint256)
|
|
595
614
|
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
596
615
|
};
|
|
597
|
-
function
|
|
616
|
+
function mt(e) {
|
|
598
617
|
if (!e || typeof e != "object") return;
|
|
599
618
|
const t = e;
|
|
600
619
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -613,22 +632,22 @@ function xt(e) {
|
|
|
613
632
|
if (i)
|
|
614
633
|
return i[1];
|
|
615
634
|
}
|
|
616
|
-
function
|
|
617
|
-
const t =
|
|
635
|
+
function is(e) {
|
|
636
|
+
const t = mt(e);
|
|
618
637
|
if (t) {
|
|
619
638
|
const n = t.substring(0, 10);
|
|
620
639
|
return q[t] ?? q[n];
|
|
621
640
|
}
|
|
622
641
|
}
|
|
623
|
-
function
|
|
624
|
-
const t =
|
|
642
|
+
function as(e) {
|
|
643
|
+
const t = mt(e);
|
|
625
644
|
if (t === void 0) return !1;
|
|
626
645
|
const n = t.substring(0, 10);
|
|
627
646
|
return t in q || n in q;
|
|
628
647
|
}
|
|
629
648
|
function M(e) {
|
|
630
649
|
console.error("[Contract Error] Raw error:", e);
|
|
631
|
-
const t =
|
|
650
|
+
const t = mt(e);
|
|
632
651
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
633
652
|
const s = t.substring(0, 10), o = q[t] ?? q[s];
|
|
634
653
|
if (o)
|
|
@@ -648,18 +667,18 @@ function M(e) {
|
|
|
648
667
|
}
|
|
649
668
|
throw e instanceof Error ? (console.error("[Contract Error] Unhandled error:", e.message), e) : new Error(`Contract call failed: ${String(e)}`);
|
|
650
669
|
}
|
|
651
|
-
const
|
|
652
|
-
function
|
|
670
|
+
const De = 0;
|
|
671
|
+
function Ke(e, t, n, s) {
|
|
653
672
|
const o = n == null ? void 0 : n[`${e}:${t}`];
|
|
654
673
|
return o ? Promise.resolve({
|
|
655
674
|
txid: e,
|
|
656
675
|
vout: t,
|
|
657
676
|
value: o.value,
|
|
658
677
|
scriptPubKey: o.scriptPubKey
|
|
659
|
-
}) :
|
|
678
|
+
}) : Ve(e, t, s);
|
|
660
679
|
}
|
|
661
|
-
const
|
|
662
|
-
class
|
|
680
|
+
const Ft = 12e4;
|
|
681
|
+
class cs {
|
|
663
682
|
/**
|
|
664
683
|
* Creates a new PeginManager instance.
|
|
665
684
|
*
|
|
@@ -690,7 +709,7 @@ class is {
|
|
|
690
709
|
* @throws Error if wallet operations fail or insufficient funds
|
|
691
710
|
*/
|
|
692
711
|
async preparePegin(t) {
|
|
693
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, o =
|
|
712
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), s = n.length === 66 ? n.slice(2) : n, o = S(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(S), i = t.universalChallengerBtcPubkeys.map(S);
|
|
694
713
|
if (t.hashlocks.length !== t.amounts.length)
|
|
695
714
|
throw new Error(
|
|
696
715
|
`hashlocks.length (${t.hashlocks.length}) must equal amounts.length (${t.amounts.length})`
|
|
@@ -710,26 +729,26 @@ class is {
|
|
|
710
729
|
councilQuorum: t.councilQuorum,
|
|
711
730
|
councilSize: t.councilSize,
|
|
712
731
|
network: this.config.btcNetwork
|
|
713
|
-
}, l = await
|
|
732
|
+
}, l = await Te(c), h = Ue(
|
|
714
733
|
[...t.availableUTXOs],
|
|
715
734
|
l.totalOutputValue,
|
|
716
735
|
t.mempoolFeeRate,
|
|
717
|
-
|
|
718
|
-
), u = It(this.config.btcNetwork), d =
|
|
736
|
+
ve(l.htlcValues.length)
|
|
737
|
+
), u = It(this.config.btcNetwork), d = ke({
|
|
719
738
|
unfundedTxHex: l.psbtHex,
|
|
720
739
|
selectedUTXOs: h.selectedUTXOs,
|
|
721
740
|
changeAddress: t.changeAddress,
|
|
722
741
|
changeAmount: h.changeAmount,
|
|
723
742
|
network: u
|
|
724
|
-
}), g =
|
|
743
|
+
}), g = S(dt(d)), y = [], x = [], P = [];
|
|
725
744
|
for (let f = 0; f < t.hashlocks.length; f++) {
|
|
726
|
-
const
|
|
745
|
+
const m = await He({
|
|
727
746
|
prePeginParams: c,
|
|
728
747
|
timelockPegin: t.timelockPegin,
|
|
729
748
|
fundedPrePeginTxHex: d,
|
|
730
749
|
htlcVout: f
|
|
731
|
-
}), v = await
|
|
732
|
-
peginTxHex:
|
|
750
|
+
}), v = await Ee({
|
|
751
|
+
peginTxHex: m.txHex,
|
|
733
752
|
fundedPrePeginTxHex: d,
|
|
734
753
|
depositorPubkey: s,
|
|
735
754
|
vaultProviderPubkey: o,
|
|
@@ -739,25 +758,25 @@ class is {
|
|
|
739
758
|
timelockRefund: t.timelockRefund,
|
|
740
759
|
network: this.config.btcNetwork
|
|
741
760
|
});
|
|
742
|
-
y.push(
|
|
743
|
-
|
|
761
|
+
y.push(m), x.push(v.psbtHex), P.push(
|
|
762
|
+
bt(n, 1)
|
|
744
763
|
);
|
|
745
764
|
}
|
|
746
|
-
const
|
|
765
|
+
const w = await this.signPsbtsWithFallback(
|
|
747
766
|
x,
|
|
748
767
|
P
|
|
749
768
|
), b = [];
|
|
750
|
-
for (let f = 0; f <
|
|
751
|
-
const
|
|
752
|
-
|
|
769
|
+
for (let f = 0; f < w.length; f++) {
|
|
770
|
+
const m = Ie(
|
|
771
|
+
w[f],
|
|
753
772
|
s
|
|
754
|
-
), v =
|
|
773
|
+
), v = Se(w[f]);
|
|
755
774
|
b.push({
|
|
756
775
|
htlcVout: f,
|
|
757
776
|
htlcValue: l.htlcValues[f],
|
|
758
777
|
peginTxHex: v,
|
|
759
778
|
peginTxid: y[f].txid,
|
|
760
|
-
peginInputSignature:
|
|
779
|
+
peginInputSignature: m,
|
|
761
780
|
vaultScriptPubKey: y[f].vaultScriptPubKey
|
|
762
781
|
});
|
|
763
782
|
}
|
|
@@ -816,10 +835,10 @@ class is {
|
|
|
816
835
|
* @throws Error if signing or broadcasting fails
|
|
817
836
|
*/
|
|
818
837
|
async signAndBroadcast(t) {
|
|
819
|
-
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r =
|
|
838
|
+
const { fundedPrePeginTxHex: n, depositorBtcPubkey: s } = t, o = n.startsWith("0x") ? n.slice(2) : n, r = xt.fromHex(o);
|
|
820
839
|
if (r.ins.length === 0)
|
|
821
840
|
throw new Error("Transaction has no inputs");
|
|
822
|
-
const i = new
|
|
841
|
+
const i = new kt();
|
|
823
842
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
824
843
|
const a = s.startsWith("0x") ? s.slice(2) : s;
|
|
825
844
|
if (a.length !== 64 || !/^[0-9a-fA-F]+$/.test(a))
|
|
@@ -832,9 +851,9 @@ class is {
|
|
|
832
851
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${c.length}`
|
|
833
852
|
);
|
|
834
853
|
const l = this.config.mempoolApiUrl, h = r.ins.map((b) => {
|
|
835
|
-
const f = W.from(b.hash).reverse().toString("hex"),
|
|
836
|
-
return
|
|
837
|
-
(v) => ({ input: b, utxoData: v, txid: f, vout:
|
|
854
|
+
const f = W.from(b.hash).reverse().toString("hex"), m = b.index;
|
|
855
|
+
return Ke(f, m, t.localPrevouts, l).then(
|
|
856
|
+
(v) => ({ input: b, utxoData: v, txid: f, vout: m })
|
|
838
857
|
);
|
|
839
858
|
}), u = await Promise.all(h), d = u.reduce(
|
|
840
859
|
(b, f) => b + BigInt(f.utxoData.value),
|
|
@@ -847,8 +866,8 @@ class is {
|
|
|
847
866
|
throw new Error(
|
|
848
867
|
`UTXO value mismatch: total input value (${d} sat) is less than total output value (${g} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
849
868
|
);
|
|
850
|
-
for (const { input: b, utxoData: f, txid:
|
|
851
|
-
const T =
|
|
869
|
+
for (const { input: b, utxoData: f, txid: m, vout: v } of u) {
|
|
870
|
+
const T = $e(
|
|
852
871
|
{
|
|
853
872
|
value: f.value,
|
|
854
873
|
scriptPubKey: f.scriptPubKey
|
|
@@ -867,19 +886,19 @@ class is {
|
|
|
867
886
|
script: b.script,
|
|
868
887
|
value: b.value
|
|
869
888
|
});
|
|
870
|
-
const y = await this.config.btcWallet.signPsbt(i.toHex()), x =
|
|
889
|
+
const y = await this.config.btcWallet.signPsbt(i.toHex()), x = kt.fromHex(y);
|
|
871
890
|
try {
|
|
872
891
|
x.finalizeAllInputs();
|
|
873
892
|
} catch (b) {
|
|
874
893
|
if (!x.data.inputs.every(
|
|
875
|
-
(
|
|
894
|
+
(m) => m.finalScriptWitness || m.finalScriptSig
|
|
876
895
|
))
|
|
877
896
|
throw new Error(
|
|
878
897
|
`PSBT finalization failed and wallet did not auto-finalize: ${b}`
|
|
879
898
|
);
|
|
880
899
|
}
|
|
881
900
|
const P = x.extractTransaction().toHex();
|
|
882
|
-
return await
|
|
901
|
+
return await Re(P, l);
|
|
883
902
|
}
|
|
884
903
|
/**
|
|
885
904
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -918,19 +937,19 @@ class is {
|
|
|
918
937
|
u
|
|
919
938
|
);
|
|
920
939
|
c && await c();
|
|
921
|
-
const y = C(n), x = C(s), P = C(o),
|
|
940
|
+
const y = C(n), x = C(s), P = C(o), w = await this.resolvePayoutScriptPubKey(
|
|
922
941
|
l
|
|
923
|
-
), b =
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
),
|
|
927
|
-
if (await this.checkVaultExists(
|
|
942
|
+
), b = dt(P), f = await Ct(
|
|
943
|
+
S(b),
|
|
944
|
+
S(d)
|
|
945
|
+
), m = C(f);
|
|
946
|
+
if (await this.checkVaultExists(m))
|
|
928
947
|
throw new Error(
|
|
929
|
-
`Vault already exists (ID: ${
|
|
948
|
+
`Vault already exists (ID: ${m}, peginTxHash: ${b}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
|
|
930
949
|
);
|
|
931
|
-
const T =
|
|
950
|
+
const T = lt({
|
|
932
951
|
chain: this.config.ethChain,
|
|
933
|
-
transport:
|
|
952
|
+
transport: ht()
|
|
934
953
|
});
|
|
935
954
|
let H;
|
|
936
955
|
try {
|
|
@@ -945,7 +964,7 @@ class is {
|
|
|
945
964
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
946
965
|
);
|
|
947
966
|
}
|
|
948
|
-
const
|
|
967
|
+
const E = Ht({
|
|
949
968
|
abi: j,
|
|
950
969
|
functionName: "submitPeginRequest",
|
|
951
970
|
args: [
|
|
@@ -957,45 +976,45 @@ class is {
|
|
|
957
976
|
r,
|
|
958
977
|
i,
|
|
959
978
|
a,
|
|
960
|
-
|
|
979
|
+
w,
|
|
961
980
|
h
|
|
962
981
|
]
|
|
963
982
|
});
|
|
964
|
-
let
|
|
983
|
+
let I;
|
|
965
984
|
try {
|
|
966
|
-
|
|
985
|
+
I = await T.estimateGas({
|
|
967
986
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
968
|
-
data:
|
|
987
|
+
data: E,
|
|
969
988
|
value: H,
|
|
970
989
|
account: this.config.ethWallet.account.address
|
|
971
990
|
});
|
|
972
991
|
} catch ($) {
|
|
973
992
|
M($);
|
|
974
993
|
}
|
|
975
|
-
let
|
|
994
|
+
let F;
|
|
976
995
|
try {
|
|
977
|
-
|
|
996
|
+
F = await this.config.ethWallet.sendTransaction({
|
|
978
997
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
979
|
-
data:
|
|
998
|
+
data: E,
|
|
980
999
|
value: H,
|
|
981
1000
|
account: this.config.ethWallet.account,
|
|
982
1001
|
chain: this.config.ethChain,
|
|
983
|
-
gas:
|
|
1002
|
+
gas: I
|
|
984
1003
|
});
|
|
985
1004
|
} catch ($) {
|
|
986
1005
|
M($);
|
|
987
1006
|
}
|
|
988
1007
|
const K = await T.waitForTransactionReceipt({
|
|
989
|
-
hash:
|
|
990
|
-
timeout:
|
|
1008
|
+
hash: F,
|
|
1009
|
+
timeout: Ft
|
|
991
1010
|
});
|
|
992
1011
|
return K.status === "reverted" && M(
|
|
993
1012
|
new Error(
|
|
994
|
-
`Transaction reverted. Hash: ${
|
|
1013
|
+
`Transaction reverted. Hash: ${F}. Check the transaction on block explorer for details.`
|
|
995
1014
|
)
|
|
996
1015
|
), {
|
|
997
1016
|
ethTxHash: K.transactionHash,
|
|
998
|
-
vaultId:
|
|
1017
|
+
vaultId: m,
|
|
999
1018
|
peginTxHash: b,
|
|
1000
1019
|
btcPopSignature: g
|
|
1001
1020
|
};
|
|
@@ -1030,19 +1049,19 @@ class is {
|
|
|
1030
1049
|
for (const b of s) {
|
|
1031
1050
|
const f = C(
|
|
1032
1051
|
b.depositorSignedPeginTx
|
|
1033
|
-
),
|
|
1034
|
-
|
|
1035
|
-
|
|
1052
|
+
), m = dt(f), v = await Ct(
|
|
1053
|
+
S(m),
|
|
1054
|
+
S(i)
|
|
1036
1055
|
), T = C(v);
|
|
1037
1056
|
if (await this.checkVaultExists(T))
|
|
1038
1057
|
throw new Error(
|
|
1039
|
-
`Vault already exists (ID: ${T}, peginTxHash: ${
|
|
1058
|
+
`Vault already exists (ID: ${T}, peginTxHash: ${m}). To create a new vault, use different UTXOs or a different amount.`
|
|
1040
1059
|
);
|
|
1041
|
-
l.push({ vaultId: T, peginTxHash:
|
|
1060
|
+
l.push({ vaultId: T, peginTxHash: m });
|
|
1042
1061
|
}
|
|
1043
|
-
const h =
|
|
1062
|
+
const h = lt({
|
|
1044
1063
|
chain: this.config.ethChain,
|
|
1045
|
-
transport:
|
|
1064
|
+
transport: ht()
|
|
1046
1065
|
});
|
|
1047
1066
|
let u;
|
|
1048
1067
|
try {
|
|
@@ -1066,10 +1085,10 @@ class is {
|
|
|
1066
1085
|
),
|
|
1067
1086
|
hashlock: b.hashlock,
|
|
1068
1087
|
htlcVout: b.htlcVout,
|
|
1069
|
-
referralCode:
|
|
1088
|
+
referralCode: De,
|
|
1070
1089
|
depositorPayoutBtcAddress: c[f],
|
|
1071
1090
|
depositorWotsPkHash: b.depositorWotsPkHash
|
|
1072
|
-
})), y =
|
|
1091
|
+
})), y = Ht({
|
|
1073
1092
|
abi: j,
|
|
1074
1093
|
functionName: "submitPeginRequestBatch",
|
|
1075
1094
|
args: [i, n, g]
|
|
@@ -1098,16 +1117,16 @@ class is {
|
|
|
1098
1117
|
} catch (b) {
|
|
1099
1118
|
M(b);
|
|
1100
1119
|
}
|
|
1101
|
-
const
|
|
1120
|
+
const w = await h.waitForTransactionReceipt({
|
|
1102
1121
|
hash: P,
|
|
1103
|
-
timeout:
|
|
1122
|
+
timeout: Ft
|
|
1104
1123
|
});
|
|
1105
|
-
return
|
|
1124
|
+
return w.status === "reverted" && M(
|
|
1106
1125
|
new Error(
|
|
1107
1126
|
`Batch transaction reverted. Hash: ${P}. Check the transaction on block explorer for details.`
|
|
1108
1127
|
)
|
|
1109
1128
|
), {
|
|
1110
|
-
ethTxHash:
|
|
1129
|
+
ethTxHash: w.transactionHash,
|
|
1111
1130
|
vaults: l,
|
|
1112
1131
|
btcPopSignature: a
|
|
1113
1132
|
};
|
|
@@ -1120,15 +1139,15 @@ class is {
|
|
|
1120
1139
|
*/
|
|
1121
1140
|
async checkVaultExists(t) {
|
|
1122
1141
|
try {
|
|
1123
|
-
return (await
|
|
1142
|
+
return (await lt({
|
|
1124
1143
|
chain: this.config.ethChain,
|
|
1125
|
-
transport:
|
|
1144
|
+
transport: ht()
|
|
1126
1145
|
}).readContract({
|
|
1127
1146
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1128
1147
|
abi: j,
|
|
1129
1148
|
functionName: "getBTCVault",
|
|
1130
1149
|
args: [t]
|
|
1131
|
-
})).depositor !==
|
|
1150
|
+
})).depositor !== ge;
|
|
1132
1151
|
} catch {
|
|
1133
1152
|
return !1;
|
|
1134
1153
|
}
|
|
@@ -1141,14 +1160,14 @@ class is {
|
|
|
1141
1160
|
* wallet's public key to guard against a compromised wallet provider.
|
|
1142
1161
|
*/
|
|
1143
1162
|
async resolvePayoutScriptPubKey(t) {
|
|
1144
|
-
|
|
1163
|
+
Be();
|
|
1145
1164
|
let n;
|
|
1146
1165
|
if (t)
|
|
1147
1166
|
n = t;
|
|
1148
1167
|
else {
|
|
1149
1168
|
n = await this.config.btcWallet.getAddress();
|
|
1150
1169
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
1151
|
-
if (!
|
|
1170
|
+
if (!Ae(
|
|
1152
1171
|
n,
|
|
1153
1172
|
o,
|
|
1154
1173
|
this.config.btcNetwork
|
|
@@ -1159,7 +1178,7 @@ class is {
|
|
|
1159
1178
|
}
|
|
1160
1179
|
const s = It(this.config.btcNetwork);
|
|
1161
1180
|
try {
|
|
1162
|
-
return `0x${
|
|
1181
|
+
return `0x${ye.address.toOutputScript(n, s).toString("hex")}`;
|
|
1163
1182
|
} catch {
|
|
1164
1183
|
throw new Error(
|
|
1165
1184
|
`Invalid BTC payout address: "${n}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1198,7 +1217,7 @@ class is {
|
|
|
1198
1217
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1199
1218
|
}
|
|
1200
1219
|
}
|
|
1201
|
-
class
|
|
1220
|
+
class us {
|
|
1202
1221
|
/**
|
|
1203
1222
|
* Creates a new PayoutManager instance.
|
|
1204
1223
|
*
|
|
@@ -1235,7 +1254,7 @@ class as {
|
|
|
1235
1254
|
t.payoutTxHex,
|
|
1236
1255
|
t.registeredPayoutScriptPubKey
|
|
1237
1256
|
);
|
|
1238
|
-
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } =
|
|
1257
|
+
const n = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = St(
|
|
1239
1258
|
n,
|
|
1240
1259
|
t.depositorBtcPubkey
|
|
1241
1260
|
), o = await Bt({
|
|
@@ -1250,10 +1269,10 @@ class as {
|
|
|
1250
1269
|
network: this.config.network
|
|
1251
1270
|
}), r = await this.config.btcWallet.signPsbt(
|
|
1252
1271
|
o.psbtHex,
|
|
1253
|
-
|
|
1272
|
+
bt(n, 1)
|
|
1254
1273
|
);
|
|
1255
1274
|
return {
|
|
1256
|
-
signature:
|
|
1275
|
+
signature: At(r, s),
|
|
1257
1276
|
depositorBtcPubkey: s
|
|
1258
1277
|
};
|
|
1259
1278
|
}
|
|
@@ -1293,7 +1312,7 @@ class as {
|
|
|
1293
1312
|
c.payoutTxHex,
|
|
1294
1313
|
c.registeredPayoutScriptPubKey
|
|
1295
1314
|
);
|
|
1296
|
-
const { depositorPubkey: l } =
|
|
1315
|
+
const { depositorPubkey: l } = St(
|
|
1297
1316
|
n,
|
|
1298
1317
|
c.depositorBtcPubkey
|
|
1299
1318
|
);
|
|
@@ -1309,7 +1328,7 @@ class as {
|
|
|
1309
1328
|
timelockPegin: c.timelockPegin,
|
|
1310
1329
|
network: this.config.network
|
|
1311
1330
|
});
|
|
1312
|
-
s.push(h.psbtHex), o.push(
|
|
1331
|
+
s.push(h.psbtHex), o.push(bt(n, 1));
|
|
1313
1332
|
}
|
|
1314
1333
|
const i = await this.config.btcWallet.signPsbts(
|
|
1315
1334
|
s,
|
|
@@ -1321,7 +1340,7 @@ class as {
|
|
|
1321
1340
|
);
|
|
1322
1341
|
const a = [];
|
|
1323
1342
|
for (let c = 0; c < t.length; c++) {
|
|
1324
|
-
const l = r[c], h =
|
|
1343
|
+
const l = r[c], h = At(
|
|
1325
1344
|
i[c],
|
|
1326
1345
|
l
|
|
1327
1346
|
);
|
|
@@ -1347,14 +1366,14 @@ class as {
|
|
|
1347
1366
|
* @throws Error if the largest output does not pay to the registered address
|
|
1348
1367
|
*/
|
|
1349
1368
|
validatePayoutOutputs(t, n) {
|
|
1350
|
-
if (!
|
|
1369
|
+
if (!Ce(n))
|
|
1351
1370
|
throw new Error(
|
|
1352
1371
|
"Invalid registeredPayoutScriptPubKey: not valid hex"
|
|
1353
1372
|
);
|
|
1354
1373
|
const s = W.from(
|
|
1355
|
-
|
|
1374
|
+
S(n),
|
|
1356
1375
|
"hex"
|
|
1357
|
-
), o =
|
|
1376
|
+
), o = xt.fromHex(S(t));
|
|
1358
1377
|
if (o.outs.length === 0)
|
|
1359
1378
|
throw new Error("Payout transaction has no outputs");
|
|
1360
1379
|
if (!o.outs.reduce(
|
|
@@ -1365,7 +1384,7 @@ class as {
|
|
|
1365
1384
|
);
|
|
1366
1385
|
}
|
|
1367
1386
|
}
|
|
1368
|
-
function
|
|
1387
|
+
function Me(e) {
|
|
1369
1388
|
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
1370
1389
|
}
|
|
1371
1390
|
function V(e, t = "") {
|
|
@@ -1375,14 +1394,14 @@ function V(e, t = "") {
|
|
|
1375
1394
|
}
|
|
1376
1395
|
}
|
|
1377
1396
|
function D(e, t, n = "") {
|
|
1378
|
-
const s =
|
|
1397
|
+
const s = Me(e), o = e == null ? void 0 : e.length, r = t !== void 0;
|
|
1379
1398
|
if (!s || r && o !== t) {
|
|
1380
1399
|
const i = n && `"${n}" `, a = r ? ` of length ${t}` : "", c = s ? `length=${o}` : `type=${typeof e}`;
|
|
1381
1400
|
throw new Error(i + "expected Uint8Array" + a + ", got " + c);
|
|
1382
1401
|
}
|
|
1383
1402
|
return e;
|
|
1384
1403
|
}
|
|
1385
|
-
function
|
|
1404
|
+
function zt(e) {
|
|
1386
1405
|
if (typeof e != "function" || typeof e.create != "function")
|
|
1387
1406
|
throw new Error("Hash must wrapped by utils.createHasher");
|
|
1388
1407
|
V(e.outputLen), V(e.blockLen);
|
|
@@ -1393,16 +1412,16 @@ function G(e, t = !0) {
|
|
|
1393
1412
|
if (t && e.finished)
|
|
1394
1413
|
throw new Error("Hash#digest() has already been called");
|
|
1395
1414
|
}
|
|
1396
|
-
function
|
|
1415
|
+
function Zt(e, t) {
|
|
1397
1416
|
D(e, void 0, "digestInto() output");
|
|
1398
1417
|
const n = t.outputLen;
|
|
1399
1418
|
if (e.length < n)
|
|
1400
1419
|
throw new Error('"digestInto() output" expected to be of length >=' + n);
|
|
1401
1420
|
}
|
|
1402
|
-
function
|
|
1421
|
+
function Ne(e) {
|
|
1403
1422
|
return new Uint32Array(e.buffer, e.byteOffset, Math.floor(e.byteLength / 4));
|
|
1404
1423
|
}
|
|
1405
|
-
function
|
|
1424
|
+
function B(...e) {
|
|
1406
1425
|
for (let t = 0; t < e.length; t++)
|
|
1407
1426
|
e[t].fill(0);
|
|
1408
1427
|
}
|
|
@@ -1415,37 +1434,37 @@ function A(e, t) {
|
|
|
1415
1434
|
function J(e, t) {
|
|
1416
1435
|
return e << t | e >>> 32 - t >>> 0;
|
|
1417
1436
|
}
|
|
1418
|
-
const
|
|
1419
|
-
function
|
|
1437
|
+
const Xe = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
1438
|
+
function qe(e) {
|
|
1420
1439
|
return e << 24 & 4278190080 | e << 8 & 16711680 | e >>> 8 & 65280 | e >>> 24 & 255;
|
|
1421
1440
|
}
|
|
1422
|
-
function
|
|
1441
|
+
function Ge(e) {
|
|
1423
1442
|
for (let t = 0; t < e.length; t++)
|
|
1424
|
-
e[t] =
|
|
1443
|
+
e[t] = qe(e[t]);
|
|
1425
1444
|
return e;
|
|
1426
1445
|
}
|
|
1427
|
-
const
|
|
1428
|
-
function
|
|
1446
|
+
const $t = Xe ? (e) => e : Ge;
|
|
1447
|
+
function je(e) {
|
|
1429
1448
|
if (typeof e != "string")
|
|
1430
1449
|
throw new Error("string expected");
|
|
1431
1450
|
return new Uint8Array(new TextEncoder().encode(e));
|
|
1432
1451
|
}
|
|
1433
|
-
function
|
|
1434
|
-
return typeof e == "string" ?
|
|
1452
|
+
function Ot(e, t = "") {
|
|
1453
|
+
return typeof e == "string" ? je(e) : D(e, void 0, t);
|
|
1435
1454
|
}
|
|
1436
|
-
function
|
|
1455
|
+
function ze(e, t) {
|
|
1437
1456
|
if (t !== void 0 && {}.toString.call(t) !== "[object Object]")
|
|
1438
1457
|
throw new Error("options must be object or undefined");
|
|
1439
1458
|
return Object.assign(e, t);
|
|
1440
1459
|
}
|
|
1441
|
-
function
|
|
1460
|
+
function ct(e, t = {}) {
|
|
1442
1461
|
const n = (o, r) => e(r).update(o).digest(), s = e(void 0);
|
|
1443
1462
|
return n.outputLen = s.outputLen, n.blockLen = s.blockLen, n.create = (o) => e(o), Object.assign(n, t), Object.freeze(n);
|
|
1444
1463
|
}
|
|
1445
|
-
const
|
|
1464
|
+
const Jt = (e) => ({
|
|
1446
1465
|
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, e])
|
|
1447
1466
|
});
|
|
1448
|
-
class
|
|
1467
|
+
class Qt {
|
|
1449
1468
|
constructor(t, n) {
|
|
1450
1469
|
p(this, "oHash");
|
|
1451
1470
|
p(this, "iHash");
|
|
@@ -1453,7 +1472,7 @@ class Zt {
|
|
|
1453
1472
|
p(this, "outputLen");
|
|
1454
1473
|
p(this, "finished", !1);
|
|
1455
1474
|
p(this, "destroyed", !1);
|
|
1456
|
-
if (
|
|
1475
|
+
if (zt(t), D(n, void 0, "key"), this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
1457
1476
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
1458
1477
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
1459
1478
|
const s = this.blockLen, o = new Uint8Array(s);
|
|
@@ -1463,7 +1482,7 @@ class Zt {
|
|
|
1463
1482
|
this.iHash.update(o), this.oHash = t.create();
|
|
1464
1483
|
for (let r = 0; r < o.length; r++)
|
|
1465
1484
|
o[r] ^= 106;
|
|
1466
|
-
this.oHash.update(o),
|
|
1485
|
+
this.oHash.update(o), B(o);
|
|
1467
1486
|
}
|
|
1468
1487
|
update(t) {
|
|
1469
1488
|
return G(this), this.iHash.update(t), this;
|
|
@@ -1487,15 +1506,15 @@ class Zt {
|
|
|
1487
1506
|
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
1488
1507
|
}
|
|
1489
1508
|
}
|
|
1490
|
-
const wt = (e, t, n) => new
|
|
1491
|
-
wt.create = (e, t) => new
|
|
1492
|
-
function
|
|
1509
|
+
const wt = (e, t, n) => new Qt(e, t).update(n).digest();
|
|
1510
|
+
wt.create = (e, t) => new Qt(e, t);
|
|
1511
|
+
function Ze(e, t, n) {
|
|
1493
1512
|
return e & t ^ ~e & n;
|
|
1494
1513
|
}
|
|
1495
|
-
function
|
|
1514
|
+
function Je(e, t, n) {
|
|
1496
1515
|
return e & t ^ e & n ^ t & n;
|
|
1497
1516
|
}
|
|
1498
|
-
class
|
|
1517
|
+
class Pt {
|
|
1499
1518
|
constructor(t, n, s, o) {
|
|
1500
1519
|
p(this, "blockLen");
|
|
1501
1520
|
p(this, "outputLen");
|
|
@@ -1526,10 +1545,10 @@ class mt {
|
|
|
1526
1545
|
return this.length += t.length, this.roundClean(), this;
|
|
1527
1546
|
}
|
|
1528
1547
|
digestInto(t) {
|
|
1529
|
-
G(this),
|
|
1548
|
+
G(this), Zt(t, this), this.finished = !0;
|
|
1530
1549
|
const { buffer: n, view: s, blockLen: o, isLE: r } = this;
|
|
1531
1550
|
let { pos: i } = this;
|
|
1532
|
-
n[i++] = 128,
|
|
1551
|
+
n[i++] = 128, B(this.buffer.subarray(i)), this.padOffset > o - i && (this.process(s, 0), i = 0);
|
|
1533
1552
|
for (let u = i; u < o; u++)
|
|
1534
1553
|
n[u] = 0;
|
|
1535
1554
|
s.setBigUint64(o - 8, BigInt(this.length * 8), r), this.process(s, 0);
|
|
@@ -1583,7 +1602,7 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1583
1602
|
4215389547,
|
|
1584
1603
|
1541459225,
|
|
1585
1604
|
327033209
|
|
1586
|
-
]),
|
|
1605
|
+
]), Qe = /* @__PURE__ */ Uint8Array.from([
|
|
1587
1606
|
7,
|
|
1588
1607
|
4,
|
|
1589
1608
|
13,
|
|
@@ -1600,36 +1619,36 @@ const O = /* @__PURE__ */ Uint32Array.from([
|
|
|
1600
1619
|
14,
|
|
1601
1620
|
11,
|
|
1602
1621
|
8
|
|
1603
|
-
]),
|
|
1604
|
-
const n = [[
|
|
1622
|
+
]), Yt = Uint8Array.from(new Array(16).fill(0).map((e, t) => t)), Ye = Yt.map((e) => (9 * e + 5) % 16), te = /* @__PURE__ */ (() => {
|
|
1623
|
+
const n = [[Yt], [Ye]];
|
|
1605
1624
|
for (let s = 0; s < 4; s++)
|
|
1606
1625
|
for (let o of n)
|
|
1607
|
-
o.push(o[s].map((r) =>
|
|
1626
|
+
o.push(o[s].map((r) => Qe[r]));
|
|
1608
1627
|
return n;
|
|
1609
|
-
})(),
|
|
1628
|
+
})(), ee = te[0], ne = te[1], se = /* @__PURE__ */ [
|
|
1610
1629
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
1611
1630
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
1612
1631
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
1613
1632
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
1614
1633
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
1615
|
-
].map((e) => Uint8Array.from(e)),
|
|
1634
|
+
].map((e) => Uint8Array.from(e)), tn = /* @__PURE__ */ ee.map((e, t) => e.map((n) => se[t][n])), en = /* @__PURE__ */ ne.map((e, t) => e.map((n) => se[t][n])), nn = /* @__PURE__ */ Uint32Array.from([
|
|
1616
1635
|
0,
|
|
1617
1636
|
1518500249,
|
|
1618
1637
|
1859775393,
|
|
1619
1638
|
2400959708,
|
|
1620
1639
|
2840853838
|
|
1621
|
-
]),
|
|
1640
|
+
]), sn = /* @__PURE__ */ Uint32Array.from([
|
|
1622
1641
|
1352829926,
|
|
1623
1642
|
1548603684,
|
|
1624
1643
|
1836072691,
|
|
1625
1644
|
2053994217,
|
|
1626
1645
|
0
|
|
1627
1646
|
]);
|
|
1628
|
-
function
|
|
1647
|
+
function Lt(e, t, n, s) {
|
|
1629
1648
|
return e === 0 ? t ^ n ^ s : e === 1 ? t & n | ~t & s : e === 2 ? (t | ~n) ^ s : e === 3 ? t & s | n & ~s : t ^ (n | ~s);
|
|
1630
1649
|
}
|
|
1631
|
-
const
|
|
1632
|
-
class
|
|
1650
|
+
const Q = /* @__PURE__ */ new Uint32Array(16);
|
|
1651
|
+
class on extends Pt {
|
|
1633
1652
|
constructor() {
|
|
1634
1653
|
super(64, 20, 8, !0);
|
|
1635
1654
|
p(this, "h0", 1732584193);
|
|
@@ -1647,47 +1666,47 @@ class nn extends mt {
|
|
|
1647
1666
|
}
|
|
1648
1667
|
process(n, s) {
|
|
1649
1668
|
for (let y = 0; y < 16; y++, s += 4)
|
|
1650
|
-
|
|
1669
|
+
Q[y] = n.getUint32(s, !0);
|
|
1651
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, g = d;
|
|
1652
1671
|
for (let y = 0; y < 5; y++) {
|
|
1653
|
-
const x = 4 - y, P =
|
|
1672
|
+
const x = 4 - y, P = nn[y], w = sn[y], b = ee[y], f = ne[y], m = tn[y], v = en[y];
|
|
1654
1673
|
for (let T = 0; T < 16; T++) {
|
|
1655
|
-
const H = J(o +
|
|
1674
|
+
const H = J(o + Lt(y, i, c, h) + Q[b[T]] + P, m[T]) + d | 0;
|
|
1656
1675
|
o = d, d = h, h = J(c, 10) | 0, c = i, i = H;
|
|
1657
1676
|
}
|
|
1658
1677
|
for (let T = 0; T < 16; T++) {
|
|
1659
|
-
const H = J(r +
|
|
1678
|
+
const H = J(r + Lt(x, a, l, u) + Q[f[T]] + w, v[T]) + g | 0;
|
|
1660
1679
|
r = g, g = u, u = J(l, 10) | 0, l = a, a = H;
|
|
1661
1680
|
}
|
|
1662
1681
|
}
|
|
1663
1682
|
this.set(this.h1 + c + u | 0, this.h2 + h + g | 0, this.h3 + d + r | 0, this.h4 + o + a | 0, this.h0 + i + l | 0);
|
|
1664
1683
|
}
|
|
1665
1684
|
roundClean() {
|
|
1666
|
-
|
|
1685
|
+
B(Q);
|
|
1667
1686
|
}
|
|
1668
1687
|
destroy() {
|
|
1669
|
-
this.destroyed = !0,
|
|
1688
|
+
this.destroyed = !0, B(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
1670
1689
|
}
|
|
1671
1690
|
}
|
|
1672
|
-
const
|
|
1673
|
-
function
|
|
1674
|
-
return t ? { h: Number(e &
|
|
1691
|
+
const rn = /* @__PURE__ */ ct(() => new on()), Y = /* @__PURE__ */ BigInt(2 ** 32 - 1), _t = /* @__PURE__ */ BigInt(32);
|
|
1692
|
+
function an(e, t = !1) {
|
|
1693
|
+
return t ? { h: Number(e & Y), l: Number(e >> _t & Y) } : { h: Number(e >> _t & Y) | 0, l: Number(e & Y) | 0 };
|
|
1675
1694
|
}
|
|
1676
|
-
function
|
|
1695
|
+
function oe(e, t = !1) {
|
|
1677
1696
|
const n = e.length;
|
|
1678
1697
|
let s = new Uint32Array(n), o = new Uint32Array(n);
|
|
1679
1698
|
for (let r = 0; r < n; r++) {
|
|
1680
|
-
const { h: i, l: a } =
|
|
1699
|
+
const { h: i, l: a } = an(e[r], t);
|
|
1681
1700
|
[s[r], o[r]] = [i, a];
|
|
1682
1701
|
}
|
|
1683
1702
|
return [s, o];
|
|
1684
1703
|
}
|
|
1685
|
-
const
|
|
1686
|
-
function
|
|
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, cn = (e, t, n) => e << n | t >>> 32 - n, un = (e, t, n) => t << n | e >>> 32 - n, ln = (e, t, n) => t << n - 32 | e >>> 64 - n, hn = (e, t, n) => e << n - 32 | t >>> 64 - n;
|
|
1705
|
+
function U(e, t, n, s) {
|
|
1687
1706
|
const o = (t >>> 0) + (s >>> 0);
|
|
1688
1707
|
return { h: e + n + (o / 2 ** 32 | 0) | 0, l: o | 0 };
|
|
1689
1708
|
}
|
|
1690
|
-
const
|
|
1709
|
+
const dn = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), fn = (e, t, n, s) => t + n + s + (e / 2 ** 32 | 0) | 0, pn = (e, t, n, s) => (e >>> 0) + (t >>> 0) + (n >>> 0) + (s >>> 0), yn = (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, xn = /* @__PURE__ */ Uint32Array.from([
|
|
1691
1710
|
1116352408,
|
|
1692
1711
|
1899447441,
|
|
1693
1712
|
3049323471,
|
|
@@ -1753,7 +1772,7 @@ const ln = (e, t, n) => (e >>> 0) + (t >>> 0) + (n >>> 0), hn = (e, t, n, s) =>
|
|
|
1753
1772
|
3204031479,
|
|
1754
1773
|
3329325298
|
|
1755
1774
|
]), L = /* @__PURE__ */ new Uint32Array(64);
|
|
1756
|
-
class
|
|
1775
|
+
class mn extends Pt {
|
|
1757
1776
|
constructor(t) {
|
|
1758
1777
|
super(64, t, 8, !1);
|
|
1759
1778
|
}
|
|
@@ -1774,19 +1793,19 @@ class gn extends mt {
|
|
|
1774
1793
|
}
|
|
1775
1794
|
let { A: s, B: o, C: r, D: i, E: a, F: c, G: l, H: h } = this;
|
|
1776
1795
|
for (let u = 0; u < 64; u++) {
|
|
1777
|
-
const d = A(a, 6) ^ A(a, 11) ^ A(a, 25), g = h + d +
|
|
1796
|
+
const d = A(a, 6) ^ A(a, 11) ^ A(a, 25), g = h + d + Ze(a, c, l) + xn[u] + L[u] | 0, x = (A(s, 2) ^ A(s, 13) ^ A(s, 22)) + Je(s, o, r) | 0;
|
|
1778
1797
|
h = l, l = c, c = a, a = i + g | 0, i = r, r = o, o = s, s = g + x | 0;
|
|
1779
1798
|
}
|
|
1780
1799
|
s = s + this.A | 0, o = o + this.B | 0, r = r + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(s, o, r, i, a, c, l, h);
|
|
1781
1800
|
}
|
|
1782
1801
|
roundClean() {
|
|
1783
|
-
|
|
1802
|
+
B(L);
|
|
1784
1803
|
}
|
|
1785
1804
|
destroy() {
|
|
1786
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0),
|
|
1805
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), B(this.buffer);
|
|
1787
1806
|
}
|
|
1788
1807
|
}
|
|
1789
|
-
class
|
|
1808
|
+
class wn extends mn {
|
|
1790
1809
|
constructor() {
|
|
1791
1810
|
super(32);
|
|
1792
1811
|
// We cannot use array here since array allows indexing by variable
|
|
@@ -1801,7 +1820,7 @@ class xn extends gn {
|
|
|
1801
1820
|
p(this, "H", O[7] | 0);
|
|
1802
1821
|
}
|
|
1803
1822
|
}
|
|
1804
|
-
const
|
|
1823
|
+
const re = oe([
|
|
1805
1824
|
"0x428a2f98d728ae22",
|
|
1806
1825
|
"0x7137449123ef65cd",
|
|
1807
1826
|
"0xb5c0fbcfec4d3b2f",
|
|
@@ -1882,8 +1901,8 @@ const se = ne([
|
|
|
1882
1901
|
"0x597f299cfc657e2a",
|
|
1883
1902
|
"0x5fcb6fab3ad6faec",
|
|
1884
1903
|
"0x6c44198c4a475817"
|
|
1885
|
-
].map((e) => BigInt(e))),
|
|
1886
|
-
class
|
|
1904
|
+
].map((e) => BigInt(e))), Pn = re[0], Tn = re[1], _ = /* @__PURE__ */ new Uint32Array(80), R = /* @__PURE__ */ new Uint32Array(80);
|
|
1905
|
+
class vn extends Pt {
|
|
1887
1906
|
constructor(t) {
|
|
1888
1907
|
super(128, t, 16, !1);
|
|
1889
1908
|
}
|
|
@@ -1900,26 +1919,26 @@ class Pn extends mt {
|
|
|
1900
1919
|
for (let f = 0; f < 16; f++, n += 4)
|
|
1901
1920
|
_[f] = t.getUint32(n), R[f] = t.getUint32(n += 4);
|
|
1902
1921
|
for (let f = 16; f < 80; f++) {
|
|
1903
|
-
const
|
|
1904
|
-
_[f] =
|
|
1922
|
+
const m = _[f - 15] | 0, v = R[f - 15] | 0, T = N(m, v, 1) ^ N(m, v, 8) ^ Rt(m, v, 7), H = X(m, v, 1) ^ X(m, v, 8) ^ Wt(m, v, 7), E = _[f - 2] | 0, I = R[f - 2] | 0, F = N(E, I, 19) ^ tt(E, I, 61) ^ Rt(E, I, 6), K = X(E, I, 19) ^ et(E, I, 61) ^ Wt(E, I, 6), $ = pn(H, K, R[f - 7], R[f - 16]), ut = yn($, T, F, _[f - 7], _[f - 16]);
|
|
1923
|
+
_[f] = ut | 0, R[f] = $ | 0;
|
|
1905
1924
|
}
|
|
1906
|
-
let { Ah: s, Al: o, Bh: r, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh: g, Fl: y, Gh: x, Gl: P, Hh:
|
|
1925
|
+
let { Ah: s, Al: o, Bh: r, Bl: i, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: d, Fh: g, Fl: y, Gh: x, Gl: P, Hh: w, Hl: b } = this;
|
|
1907
1926
|
for (let f = 0; f < 80; f++) {
|
|
1908
|
-
const
|
|
1909
|
-
|
|
1910
|
-
const
|
|
1911
|
-
s =
|
|
1927
|
+
const m = 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 & g ^ ~u & x, H = d & y ^ ~d & P, E = bn(b, v, H, Tn[f], R[f]), I = gn(E, w, m, T, Pn[f], _[f]), F = E | 0, K = 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;
|
|
1928
|
+
w = x | 0, b = P | 0, x = g | 0, P = y | 0, g = u | 0, y = d | 0, { h: u, l: d } = U(l | 0, h | 0, I | 0, F | 0), l = a | 0, h = c | 0, a = r | 0, c = i | 0, r = s | 0, i = o | 0;
|
|
1929
|
+
const vt = dn(F, $, de);
|
|
1930
|
+
s = fn(vt, I, K, ut), o = vt | 0;
|
|
1912
1931
|
}
|
|
1913
|
-
({ h: s, l: o } =
|
|
1932
|
+
({ h: s, l: o } = U(this.Ah | 0, this.Al | 0, s | 0, o | 0)), { h: r, l: i } = U(this.Bh | 0, this.Bl | 0, r | 0, i | 0), { h: a, l: c } = U(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = U(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: d } = U(this.Eh | 0, this.El | 0, u | 0, d | 0), { h: g, l: y } = U(this.Fh | 0, this.Fl | 0, g | 0, y | 0), { h: x, l: P } = U(this.Gh | 0, this.Gl | 0, x | 0, P | 0), { h: w, l: b } = U(this.Hh | 0, this.Hl | 0, w | 0, b | 0), this.set(s, o, r, i, a, c, l, h, u, d, g, y, x, P, w, b);
|
|
1914
1933
|
}
|
|
1915
1934
|
roundClean() {
|
|
1916
|
-
|
|
1935
|
+
B(_, R);
|
|
1917
1936
|
}
|
|
1918
1937
|
destroy() {
|
|
1919
|
-
|
|
1938
|
+
B(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1920
1939
|
}
|
|
1921
1940
|
}
|
|
1922
|
-
class
|
|
1941
|
+
class kn extends vn {
|
|
1923
1942
|
constructor() {
|
|
1924
1943
|
super(64);
|
|
1925
1944
|
p(this, "Ah", k[0] | 0);
|
|
@@ -1940,34 +1959,34 @@ class Tn extends Pn {
|
|
|
1940
1959
|
p(this, "Hl", k[15] | 0);
|
|
1941
1960
|
}
|
|
1942
1961
|
}
|
|
1943
|
-
const
|
|
1944
|
-
() => new
|
|
1945
|
-
/* @__PURE__ */
|
|
1946
|
-
),
|
|
1947
|
-
() => new
|
|
1948
|
-
/* @__PURE__ */
|
|
1949
|
-
),
|
|
1962
|
+
const Hn = /* @__PURE__ */ ct(
|
|
1963
|
+
() => new wn(),
|
|
1964
|
+
/* @__PURE__ */ Jt(1)
|
|
1965
|
+
), ie = /* @__PURE__ */ ct(
|
|
1966
|
+
() => new kn(),
|
|
1967
|
+
/* @__PURE__ */ Jt(3)
|
|
1968
|
+
), En = BigInt(0), z = BigInt(1), In = BigInt(2), Sn = BigInt(7), Bn = BigInt(256), An = BigInt(113), ae = [], ce = [], ue = [];
|
|
1950
1969
|
for (let e = 0, t = z, n = 1, s = 0; e < 24; e++) {
|
|
1951
|
-
[n, s] = [s, (2 * n + 3 * s) % 5],
|
|
1952
|
-
let o =
|
|
1970
|
+
[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 = En;
|
|
1953
1972
|
for (let r = 0; r < 7; r++)
|
|
1954
|
-
t = (t << z ^ (t >>
|
|
1955
|
-
|
|
1973
|
+
t = (t << z ^ (t >> Sn) * An) % Bn, t & In && (o ^= z << (z << BigInt(r)) - z);
|
|
1974
|
+
ue.push(o);
|
|
1956
1975
|
}
|
|
1957
|
-
const
|
|
1958
|
-
function
|
|
1976
|
+
const le = oe(ue, !0), Cn = le[0], Un = le[1], Vt = (e, t, n) => n > 32 ? ln(e, t, n) : cn(e, t, n), Dt = (e, t, n) => n > 32 ? hn(e, t, n) : un(e, t, n);
|
|
1977
|
+
function Fn(e, t = 24) {
|
|
1959
1978
|
const n = new Uint32Array(10);
|
|
1960
1979
|
for (let s = 24 - t; s < 24; s++) {
|
|
1961
1980
|
for (let i = 0; i < 10; i++)
|
|
1962
1981
|
n[i] = e[i] ^ e[i + 10] ^ e[i + 20] ^ e[i + 30] ^ e[i + 40];
|
|
1963
1982
|
for (let i = 0; i < 10; i += 2) {
|
|
1964
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, l = n[c], h = n[c + 1], u =
|
|
1983
|
+
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];
|
|
1965
1984
|
for (let g = 0; g < 50; g += 10)
|
|
1966
1985
|
e[i + g] ^= u, e[i + g + 1] ^= d;
|
|
1967
1986
|
}
|
|
1968
1987
|
let o = e[2], r = e[3];
|
|
1969
1988
|
for (let i = 0; i < 24; i++) {
|
|
1970
|
-
const a =
|
|
1989
|
+
const a = ce[i], c = Vt(o, r, a), l = Dt(o, r, a), h = ae[i];
|
|
1971
1990
|
o = e[h], r = e[h + 1], e[h] = c, e[h + 1] = l;
|
|
1972
1991
|
}
|
|
1973
1992
|
for (let i = 0; i < 50; i += 10) {
|
|
@@ -1976,11 +1995,11 @@ function Cn(e, t = 24) {
|
|
|
1976
1995
|
for (let a = 0; a < 10; a++)
|
|
1977
1996
|
e[i + a] ^= ~n[(a + 2) % 10] & n[(a + 4) % 10];
|
|
1978
1997
|
}
|
|
1979
|
-
e[0] ^=
|
|
1998
|
+
e[0] ^= Cn[s], e[1] ^= Un[s];
|
|
1980
1999
|
}
|
|
1981
|
-
|
|
2000
|
+
B(n);
|
|
1982
2001
|
}
|
|
1983
|
-
class
|
|
2002
|
+
class Tt {
|
|
1984
2003
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1985
2004
|
constructor(t, n, s, o = !1, r = 24) {
|
|
1986
2005
|
p(this, "state");
|
|
@@ -1996,13 +2015,13 @@ class Pt {
|
|
|
1996
2015
|
p(this, "rounds");
|
|
1997
2016
|
if (this.blockLen = t, this.suffix = n, this.outputLen = s, this.enableXOF = o, this.rounds = r, V(s, "outputLen"), !(0 < t && t < 200))
|
|
1998
2017
|
throw new Error("only keccak-f1600 function is supported");
|
|
1999
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
2018
|
+
this.state = new Uint8Array(200), this.state32 = Ne(this.state);
|
|
2000
2019
|
}
|
|
2001
2020
|
clone() {
|
|
2002
2021
|
return this._cloneInto();
|
|
2003
2022
|
}
|
|
2004
2023
|
keccak() {
|
|
2005
|
-
|
|
2024
|
+
$t(this.state32), Fn(this.state32, this.rounds), $t(this.state32), this.posOut = 0, this.pos = 0;
|
|
2006
2025
|
}
|
|
2007
2026
|
update(t) {
|
|
2008
2027
|
G(this), D(t);
|
|
@@ -2041,7 +2060,7 @@ class Pt {
|
|
|
2041
2060
|
return V(t), this.xofInto(new Uint8Array(t));
|
|
2042
2061
|
}
|
|
2043
2062
|
digestInto(t) {
|
|
2044
|
-
if (
|
|
2063
|
+
if (Zt(t, this), this.finished)
|
|
2045
2064
|
throw new Error("digest() was already called");
|
|
2046
2065
|
return this.writeInto(t), this.destroy(), t;
|
|
2047
2066
|
}
|
|
@@ -2049,27 +2068,27 @@ class Pt {
|
|
|
2049
2068
|
return this.digestInto(new Uint8Array(this.outputLen));
|
|
2050
2069
|
}
|
|
2051
2070
|
destroy() {
|
|
2052
|
-
this.destroyed = !0,
|
|
2071
|
+
this.destroyed = !0, B(this.state);
|
|
2053
2072
|
}
|
|
2054
2073
|
_cloneInto(t) {
|
|
2055
2074
|
const { blockLen: n, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
2056
|
-
return t || (t = new
|
|
2075
|
+
return t || (t = new Tt(n, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
2057
2076
|
}
|
|
2058
2077
|
}
|
|
2059
|
-
const
|
|
2060
|
-
function
|
|
2061
|
-
|
|
2062
|
-
const o =
|
|
2078
|
+
const $n = (e, t, n, s = {}) => ct(() => new Tt(t, e, n), s), On = /* @__PURE__ */ $n(1, 136, 32);
|
|
2079
|
+
function Ln(e, t, n, s) {
|
|
2080
|
+
zt(e);
|
|
2081
|
+
const o = ze({ dkLen: 32, asyncTick: 10 }, s), { c: r, dkLen: i, asyncTick: a } = o;
|
|
2063
2082
|
if (V(r, "c"), V(i, "dkLen"), V(a, "asyncTick"), r < 1)
|
|
2064
2083
|
throw new Error("iterations (c) must be >= 1");
|
|
2065
|
-
const c =
|
|
2084
|
+
const c = Ot(t, "password"), l = Ot(n, "salt"), h = new Uint8Array(i), u = wt.create(e, c), d = u._cloneInto().update(l);
|
|
2066
2085
|
return { c: r, dkLen: i, asyncTick: a, DK: h, PRF: u, PRFSalt: d };
|
|
2067
2086
|
}
|
|
2068
|
-
function
|
|
2069
|
-
return e.destroy(), t.destroy(), s && s.destroy(),
|
|
2087
|
+
function _n(e, t, n, s, o) {
|
|
2088
|
+
return e.destroy(), t.destroy(), s && s.destroy(), B(o), n;
|
|
2070
2089
|
}
|
|
2071
|
-
function
|
|
2072
|
-
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: c } =
|
|
2090
|
+
function Rn(e, t, n, s) {
|
|
2091
|
+
const { c: o, dkLen: r, DK: i, PRF: a, PRFSalt: c } = Ln(e, t, n, s);
|
|
2073
2092
|
let l;
|
|
2074
2093
|
const h = new Uint8Array(4), u = rt(h), d = new Uint8Array(a.outputLen);
|
|
2075
2094
|
for (let g = 1, y = 0; y < r; g++, y += a.outputLen) {
|
|
@@ -2077,28 +2096,28 @@ function Ln(e, t, n, s) {
|
|
|
2077
2096
|
u.setInt32(0, g, !1), (l = c._cloneInto(l)).update(h).digestInto(d), x.set(d.subarray(0, x.length));
|
|
2078
2097
|
for (let P = 1; P < o; P++) {
|
|
2079
2098
|
a._cloneInto(l).update(d).digestInto(d);
|
|
2080
|
-
for (let
|
|
2081
|
-
x[
|
|
2099
|
+
for (let w = 0; w < x.length; w++)
|
|
2100
|
+
x[w] ^= d[w];
|
|
2082
2101
|
}
|
|
2083
2102
|
}
|
|
2084
|
-
return
|
|
2103
|
+
return _n(a, c, i, l, d);
|
|
2085
2104
|
}
|
|
2086
|
-
function
|
|
2105
|
+
function he(e) {
|
|
2087
2106
|
if (typeof e != "string")
|
|
2088
2107
|
throw new TypeError("invalid mnemonic type: " + typeof e);
|
|
2089
2108
|
return e.normalize("NFKD");
|
|
2090
2109
|
}
|
|
2091
|
-
function
|
|
2092
|
-
const t =
|
|
2110
|
+
function Wn(e) {
|
|
2111
|
+
const t = he(e), n = t.split(" ");
|
|
2093
2112
|
if (![12, 15, 18, 21, 24].includes(n.length))
|
|
2094
2113
|
throw new Error("Invalid mnemonic");
|
|
2095
2114
|
return { nfkd: t, words: n };
|
|
2096
2115
|
}
|
|
2097
|
-
const
|
|
2098
|
-
function
|
|
2099
|
-
return
|
|
2116
|
+
const Vn = (e) => he("mnemonic" + e);
|
|
2117
|
+
function Dn(e, t = "") {
|
|
2118
|
+
return Rn(ie, Wn(e).nfkd, Vn(t), { c: 2048, dkLen: 64 });
|
|
2100
2119
|
}
|
|
2101
|
-
const
|
|
2120
|
+
const Kn = 508, Kt = 16, nt = 32, st = 64, Mt = 5, Mn = 4;
|
|
2102
2121
|
function Z(...e) {
|
|
2103
2122
|
const t = e.reduce((o, r) => o + r.length, 0), n = new Uint8Array(t);
|
|
2104
2123
|
let s = 0;
|
|
@@ -2106,63 +2125,63 @@ function Z(...e) {
|
|
|
2106
2125
|
n.set(o, s), s += o.length;
|
|
2107
2126
|
return n;
|
|
2108
2127
|
}
|
|
2109
|
-
function
|
|
2128
|
+
function ft(e) {
|
|
2110
2129
|
return new TextEncoder().encode(e);
|
|
2111
2130
|
}
|
|
2112
|
-
function
|
|
2113
|
-
const t = new Uint8Array(
|
|
2131
|
+
function pt(e) {
|
|
2132
|
+
const t = new Uint8Array(Mn);
|
|
2114
2133
|
return new DataView(t.buffer).setUint32(0, e.length, !1), Z(t, e);
|
|
2115
2134
|
}
|
|
2116
|
-
function
|
|
2117
|
-
return wt(
|
|
2135
|
+
function yt(e, t) {
|
|
2136
|
+
return wt(ie, e, t);
|
|
2118
2137
|
}
|
|
2119
|
-
function
|
|
2120
|
-
return
|
|
2138
|
+
function Nt(e) {
|
|
2139
|
+
return rn(Hn(e));
|
|
2121
2140
|
}
|
|
2122
|
-
const
|
|
2123
|
-
function
|
|
2124
|
-
const t =
|
|
2141
|
+
const gt = (e) => Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
2142
|
+
function Nn(e) {
|
|
2143
|
+
const t = Dn(e), n = new Uint8Array(t);
|
|
2125
2144
|
return t.fill(0), n;
|
|
2126
2145
|
}
|
|
2127
|
-
async function
|
|
2146
|
+
async function Xn(e, t, n, s) {
|
|
2128
2147
|
if (e.length !== st)
|
|
2129
2148
|
throw new Error(
|
|
2130
2149
|
`WOTS seed must be ${st} bytes, got ${e.length}`
|
|
2131
2150
|
);
|
|
2132
|
-
t =
|
|
2151
|
+
t = S(t), n = S(n);
|
|
2133
2152
|
const o = e.slice(nt, st), r = e.slice(0, nt), i = [o, r];
|
|
2134
2153
|
try {
|
|
2135
2154
|
const a = Z(
|
|
2136
|
-
ft(
|
|
2137
|
-
ft(
|
|
2138
|
-
ft(
|
|
2155
|
+
pt(ft(t)),
|
|
2156
|
+
pt(ft(n)),
|
|
2157
|
+
pt(ft(s))
|
|
2139
2158
|
), c = Z(r, a);
|
|
2140
2159
|
i.push(c);
|
|
2141
|
-
const l =
|
|
2160
|
+
const l = yt(o, c);
|
|
2142
2161
|
i.push(l);
|
|
2143
2162
|
const h = l.slice(0, nt), u = l.slice(nt, st);
|
|
2144
2163
|
i.push(h, u);
|
|
2145
2164
|
const d = [], g = [], y = [], x = [];
|
|
2146
2165
|
let P = !1;
|
|
2147
2166
|
try {
|
|
2148
|
-
for (let
|
|
2149
|
-
const b = new Uint8Array(
|
|
2150
|
-
b[0] = 0, new DataView(b.buffer).setUint32(1,
|
|
2151
|
-
const f = new Uint8Array(
|
|
2152
|
-
f[0] = 1, new DataView(f.buffer).setUint32(1,
|
|
2153
|
-
const
|
|
2167
|
+
for (let w = 0; w < Kn; w++) {
|
|
2168
|
+
const b = new Uint8Array(Mt);
|
|
2169
|
+
b[0] = 0, new DataView(b.buffer).setUint32(1, w, !1);
|
|
2170
|
+
const f = new Uint8Array(Mt);
|
|
2171
|
+
f[0] = 1, new DataView(f.buffer).setUint32(1, w, !1);
|
|
2172
|
+
const m = Z(h, b), v = Z(h, f), T = yt(u, m), H = yt(u, v);
|
|
2154
2173
|
try {
|
|
2155
|
-
const
|
|
2156
|
-
d.push(
|
|
2174
|
+
const E = T.slice(0, Kt), I = H.slice(0, Kt);
|
|
2175
|
+
d.push(E), g.push(I), y.push(Nt(E)), x.push(Nt(I));
|
|
2157
2176
|
} finally {
|
|
2158
|
-
|
|
2177
|
+
m.fill(0), v.fill(0), T.fill(0), H.fill(0);
|
|
2159
2178
|
}
|
|
2160
2179
|
}
|
|
2161
2180
|
return P = !0, { falsePreimages: d, truePreimages: g, falseHashes: y, trueHashes: x };
|
|
2162
2181
|
} finally {
|
|
2163
2182
|
if (!P) {
|
|
2164
|
-
for (const
|
|
2165
|
-
for (const
|
|
2183
|
+
for (const w of d) w.fill(0);
|
|
2184
|
+
for (const w of g) w.fill(0);
|
|
2166
2185
|
}
|
|
2167
2186
|
}
|
|
2168
2187
|
} finally {
|
|
@@ -2170,13 +2189,13 @@ async function Mn(e, t, n, s) {
|
|
|
2170
2189
|
a.fill(0);
|
|
2171
2190
|
}
|
|
2172
2191
|
}
|
|
2173
|
-
function
|
|
2192
|
+
function ls(e) {
|
|
2174
2193
|
return {
|
|
2175
|
-
false_list: e.falseHashes.map(
|
|
2176
|
-
true_list: e.trueHashes.map(
|
|
2194
|
+
false_list: e.falseHashes.map(gt),
|
|
2195
|
+
true_list: e.trueHashes.map(gt)
|
|
2177
2196
|
};
|
|
2178
2197
|
}
|
|
2179
|
-
function
|
|
2198
|
+
function qn(e) {
|
|
2180
2199
|
if (e.falseHashes.length === 0 || e.trueHashes.length === 0)
|
|
2181
2200
|
throw new Error(
|
|
2182
2201
|
"computeWotsPkHash: keypair hash arrays must not be empty"
|
|
@@ -2187,20 +2206,20 @@ function Nn(e) {
|
|
|
2187
2206
|
s.set(i, o), o += t;
|
|
2188
2207
|
for (const i of e.trueHashes)
|
|
2189
2208
|
s.set(i, o), o += t;
|
|
2190
|
-
const r =
|
|
2191
|
-
return `0x${
|
|
2209
|
+
const r = On(s);
|
|
2210
|
+
return `0x${gt(r)}`;
|
|
2192
2211
|
}
|
|
2193
|
-
async function
|
|
2194
|
-
const o =
|
|
2212
|
+
async function hs(e, t, n, s) {
|
|
2213
|
+
const o = Nn(e);
|
|
2195
2214
|
try {
|
|
2196
|
-
const r = await
|
|
2215
|
+
const r = await Xn(
|
|
2197
2216
|
o,
|
|
2198
2217
|
t,
|
|
2199
2218
|
n,
|
|
2200
2219
|
s
|
|
2201
2220
|
);
|
|
2202
2221
|
try {
|
|
2203
|
-
return
|
|
2222
|
+
return qn(r);
|
|
2204
2223
|
} finally {
|
|
2205
2224
|
for (const i of r.falsePreimages) i.fill(0);
|
|
2206
2225
|
for (const i of r.truePreimages) i.fill(0);
|
|
@@ -2209,41 +2228,41 @@ async function us(e, t, n, s) {
|
|
|
2209
2228
|
o.fill(0);
|
|
2210
2229
|
}
|
|
2211
2230
|
}
|
|
2212
|
-
function
|
|
2231
|
+
function ds(e) {
|
|
2213
2232
|
const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
|
|
2214
2233
|
return t.includes("wots") && t.includes("hash") && t.includes("does not match");
|
|
2215
2234
|
}
|
|
2216
2235
|
export {
|
|
2217
|
-
|
|
2236
|
+
ds as A,
|
|
2218
2237
|
ot as B,
|
|
2219
2238
|
q as C,
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2239
|
+
_e as M,
|
|
2240
|
+
cs as P,
|
|
2241
|
+
Yn as a,
|
|
2242
|
+
Fe as b,
|
|
2243
|
+
dt as c,
|
|
2244
|
+
$e as d,
|
|
2245
|
+
bt as e,
|
|
2246
|
+
us as f,
|
|
2247
|
+
ts as g,
|
|
2248
|
+
os as h,
|
|
2249
|
+
ns as i,
|
|
2250
|
+
ss as j,
|
|
2251
|
+
rs as k,
|
|
2252
|
+
es as l,
|
|
2253
|
+
We as m,
|
|
2254
|
+
Ve as n,
|
|
2236
2255
|
j as o,
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2256
|
+
Re as p,
|
|
2257
|
+
mt as q,
|
|
2258
|
+
is as r,
|
|
2259
|
+
Ue as s,
|
|
2260
|
+
as as t,
|
|
2242
2261
|
M as u,
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2262
|
+
Nn as v,
|
|
2263
|
+
Xn as w,
|
|
2264
|
+
ls as x,
|
|
2265
|
+
qn as y,
|
|
2266
|
+
hs as z
|
|
2248
2267
|
};
|
|
2249
|
-
//# sourceMappingURL=errors-
|
|
2268
|
+
//# sourceMappingURL=errors-Ld-2tiK3.js.map
|