@babylonlabs-io/ts-sdk 0.8.0 → 0.8.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/{PayoutManager-CvWBwdzd.js → PayoutManager-6IBl1Fdt.js} +166 -135
- package/dist/PayoutManager-6IBl1Fdt.js.map +1 -0
- package/dist/PayoutManager-EZFN4Y4Z.cjs +2 -0
- package/dist/PayoutManager-EZFN4Y4Z.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/tbv/core/clients/mempool/__tests__/mempoolApi.test.d.ts +2 -0
- package/dist/tbv/core/clients/mempool/__tests__/mempoolApi.test.d.ts.map +1 -0
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +1 -1
- package/package.json +1 -1
- package/dist/PayoutManager-9qwA76_B.cjs +0 -2
- package/dist/PayoutManager-9qwA76_B.cjs.map +0 -1
- package/dist/PayoutManager-CvWBwdzd.js.map +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import * as
|
|
5
|
-
import { script as
|
|
1
|
+
var Z = Object.defineProperty;
|
|
2
|
+
var G = (n, t, e) => t in n ? Z(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var S = (n, t, e) => G(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import * as Q from "bitcoinjs-lib";
|
|
5
|
+
import { script as Y, Transaction as $, address as tt, Psbt as F } from "bitcoinjs-lib";
|
|
6
6
|
import { Buffer as g } from "buffer";
|
|
7
|
-
import { P as
|
|
8
|
-
import { createPublicClient as M, http as X, encodeFunctionData as
|
|
7
|
+
import { P as et, x as nt, D as q, M as R, B as rt, T as st, A as C, t as k, b as ot, z as at, a as it, d as ct, e as ut, f as lt, r as B, p as dt, w as W, g as N, h as K } from "./challengeAssert-D50t_Qyo.js";
|
|
8
|
+
import { createPublicClient as M, http as X, encodeFunctionData as pt, zeroAddress as ht } from "viem";
|
|
9
9
|
import { c as O } from "./signOptions-Drwr3bXB.js";
|
|
10
10
|
import { SINGLE_DEPOSIT_HTLC_VOUT as D } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
11
|
-
function
|
|
11
|
+
function ft(n, t, e) {
|
|
12
12
|
if (n.length === 0)
|
|
13
13
|
throw new Error("Insufficient funds: no UTXOs available");
|
|
14
14
|
const r = n.filter((a) => {
|
|
15
15
|
const u = g.from(a.scriptPubKey, "hex");
|
|
16
|
-
return !!
|
|
16
|
+
return !!Y.decompile(u);
|
|
17
17
|
});
|
|
18
18
|
if (r.length === 0)
|
|
19
19
|
throw new Error(
|
|
@@ -23,20 +23,20 @@ function dt(n, t, e) {
|
|
|
23
23
|
let c = 0n, i = 0n;
|
|
24
24
|
for (const a of o) {
|
|
25
25
|
s.push(a), c += BigInt(a.value);
|
|
26
|
-
const u = s.length *
|
|
27
|
-
if (i = BigInt(Math.ceil(p * e)) + BigInt(
|
|
28
|
-
const
|
|
29
|
-
Math.ceil(
|
|
26
|
+
const u = s.length * et, l = 2 * R, p = u + l + st;
|
|
27
|
+
if (i = BigInt(Math.ceil(p * e)) + BigInt(nt(e)), c - t - i > q) {
|
|
28
|
+
const y = BigInt(
|
|
29
|
+
Math.ceil(R * e)
|
|
30
30
|
);
|
|
31
|
-
i +=
|
|
31
|
+
i += y;
|
|
32
32
|
}
|
|
33
33
|
if (c >= t + i) {
|
|
34
|
-
const
|
|
34
|
+
const y = c - t - i;
|
|
35
35
|
return {
|
|
36
36
|
selectedUTXOs: s,
|
|
37
37
|
totalValue: c,
|
|
38
38
|
fee: i,
|
|
39
|
-
changeAmount:
|
|
39
|
+
changeAmount: y
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -44,17 +44,17 @@ function dt(n, t, e) {
|
|
|
44
44
|
`Insufficient funds: need ${t + i} sats (${t} pegin + ${i} fee), have ${c} sats`
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function Ht(n) {
|
|
48
48
|
return n > q;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
50
|
+
function Ft() {
|
|
51
|
+
return rt;
|
|
52
52
|
}
|
|
53
53
|
function _(n) {
|
|
54
54
|
const t = n.startsWith("0x") ? n.slice(2) : n;
|
|
55
|
-
return `0x${
|
|
55
|
+
return `0x${$.fromHex(t).getId()}`;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function Ct(n, t, e) {
|
|
58
58
|
if (n.length === 0)
|
|
59
59
|
throw new Error("No input UTXOs provided for split transaction");
|
|
60
60
|
if (t.length === 0)
|
|
@@ -64,7 +64,7 @@ function Bt(n, t, e) {
|
|
|
64
64
|
throw new Error(
|
|
65
65
|
`Invalid output amount for ${a.address}: ${a.amount} satoshis. Amount must be greater than zero.`
|
|
66
66
|
);
|
|
67
|
-
const r =
|
|
67
|
+
const r = C(e), o = new $();
|
|
68
68
|
o.version = 2;
|
|
69
69
|
for (const a of n) {
|
|
70
70
|
const u = g.from(a.txid, "hex").reverse();
|
|
@@ -75,7 +75,7 @@ function Bt(n, t, e) {
|
|
|
75
75
|
const u = t[a];
|
|
76
76
|
let l;
|
|
77
77
|
try {
|
|
78
|
-
l =
|
|
78
|
+
l = tt.toOutputScript(u.address, r);
|
|
79
79
|
} catch (p) {
|
|
80
80
|
throw new Error(
|
|
81
81
|
`Failed to decode address "${u.address}": ${p instanceof Error ? p.message : String(p)}`
|
|
@@ -98,8 +98,8 @@ function Bt(n, t, e) {
|
|
|
98
98
|
outputs: s
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
const r =
|
|
101
|
+
function Ot(n, t, e) {
|
|
102
|
+
const r = $.fromHex(n), o = new F();
|
|
103
103
|
if (o.setVersion(r.version), o.setLocktime(r.locktime), !g.isBuffer(e) || e.length !== 32)
|
|
104
104
|
throw new Error(
|
|
105
105
|
`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${g.isBuffer(e) ? `${e.length}-byte Buffer` : typeof e}`
|
|
@@ -143,7 +143,7 @@ function It(n, t, e) {
|
|
|
143
143
|
return o.toHex();
|
|
144
144
|
}
|
|
145
145
|
var E = /* @__PURE__ */ ((n) => (n.P2PKH = "P2PKH", n.P2SH = "P2SH", n.P2WPKH = "P2WPKH", n.P2WSH = "P2WSH", n.P2TR = "P2TR", n.UNKNOWN = "UNKNOWN", n))(E || {});
|
|
146
|
-
function
|
|
146
|
+
function gt(n) {
|
|
147
147
|
const t = n.length;
|
|
148
148
|
return t === 25 && n[0] === 118 && // OP_DUP
|
|
149
149
|
n[1] === 169 && // OP_HASH160
|
|
@@ -156,8 +156,8 @@ function pt(n) {
|
|
|
156
156
|
n[1] === 32 ? "P2WSH" : t === 34 && n[0] === 81 && // OP_1
|
|
157
157
|
n[1] === 32 ? "P2TR" : "UNKNOWN";
|
|
158
158
|
}
|
|
159
|
-
function
|
|
160
|
-
const e = g.from(n.scriptPubKey, "hex"), r =
|
|
159
|
+
function yt(n, t) {
|
|
160
|
+
const e = g.from(n.scriptPubKey, "hex"), r = gt(e);
|
|
161
161
|
switch (r) {
|
|
162
162
|
case E.P2WPKH:
|
|
163
163
|
return {
|
|
@@ -195,12 +195,22 @@ function ht(n, t) {
|
|
|
195
195
|
throw new Error(`Unsupported script type: ${r}`);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
const
|
|
198
|
+
const bt = 21e6 * 1e8, L = 1e4;
|
|
199
|
+
function j(n) {
|
|
200
|
+
return Number.isInteger(n) && n > 0 && n <= bt;
|
|
201
|
+
}
|
|
202
|
+
function mt(n) {
|
|
203
|
+
return Number.isInteger(n) && n > 0 && n <= L;
|
|
204
|
+
}
|
|
205
|
+
function J(n, t) {
|
|
206
|
+
return !Number.isInteger(n) || n < 0 ? !1 : t === void 0 || n < t;
|
|
207
|
+
}
|
|
208
|
+
const Pt = {
|
|
199
209
|
mainnet: "https://mempool.space/api",
|
|
200
210
|
testnet: "https://mempool.space/testnet/api",
|
|
201
211
|
signet: "https://mempool.space/signet/api"
|
|
202
212
|
};
|
|
203
|
-
async function
|
|
213
|
+
async function I(n, t) {
|
|
204
214
|
try {
|
|
205
215
|
const e = await fetch(n, t);
|
|
206
216
|
if (!e.ok) {
|
|
@@ -215,7 +225,7 @@ async function S(n, t) {
|
|
|
215
225
|
throw e instanceof Error ? new Error(`Failed to fetch from mempool API: ${e.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
|
|
216
226
|
}
|
|
217
227
|
}
|
|
218
|
-
async function
|
|
228
|
+
async function xt(n, t) {
|
|
219
229
|
try {
|
|
220
230
|
const e = await fetch(`${t}/tx`, {
|
|
221
231
|
method: "POST",
|
|
@@ -241,10 +251,10 @@ async function gt(n, t) {
|
|
|
241
251
|
throw e instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${e.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
|
|
242
252
|
}
|
|
243
253
|
}
|
|
244
|
-
async function
|
|
245
|
-
return
|
|
254
|
+
async function wt(n, t) {
|
|
255
|
+
return I(`${t}/tx/${n}`);
|
|
246
256
|
}
|
|
247
|
-
async function
|
|
257
|
+
async function Ut(n, t) {
|
|
248
258
|
try {
|
|
249
259
|
const e = await fetch(`${t}/tx/${n}/hex`);
|
|
250
260
|
if (!e.ok) {
|
|
@@ -258,13 +268,15 @@ async function Ht(n, t) {
|
|
|
258
268
|
throw e instanceof Error ? new Error(`Failed to get transaction hex for ${n}: ${e.message}`) : new Error(`Failed to get transaction hex for ${n}: Unknown error`);
|
|
259
269
|
}
|
|
260
270
|
}
|
|
261
|
-
async function
|
|
262
|
-
const r = await
|
|
263
|
-
if (t
|
|
271
|
+
async function Tt(n, t, e) {
|
|
272
|
+
const r = await wt(n, e);
|
|
273
|
+
if (!J(t, r.vout.length))
|
|
264
274
|
throw new Error(
|
|
265
275
|
`Invalid vout ${t} for transaction ${n} (has ${r.vout.length} outputs)`
|
|
266
276
|
);
|
|
267
277
|
const o = r.vout[t];
|
|
278
|
+
if (!j(o.value))
|
|
279
|
+
throw new Error(`Invalid UTXO value ${o.value} for ${n}:${t}`);
|
|
268
280
|
return {
|
|
269
281
|
txid: n,
|
|
270
282
|
vout: t,
|
|
@@ -272,13 +284,21 @@ async function bt(n, t, e) {
|
|
|
272
284
|
scriptPubKey: o.scriptpubkey
|
|
273
285
|
};
|
|
274
286
|
}
|
|
275
|
-
async function
|
|
287
|
+
async function At(n, t) {
|
|
276
288
|
try {
|
|
277
|
-
const e = await
|
|
289
|
+
const e = await I(`${t}/address/${n}/utxo`), r = await I(`${t}/v1/validate-address/${n}`);
|
|
278
290
|
if (!r.isvalid)
|
|
279
291
|
throw new Error(
|
|
280
292
|
`Invalid Bitcoin address: ${n}. Mempool API validation failed.`
|
|
281
293
|
);
|
|
294
|
+
for (const s of e) {
|
|
295
|
+
if (!J(s.vout))
|
|
296
|
+
throw new Error(`Invalid vout ${s.vout} for ${s.txid}`);
|
|
297
|
+
if (!j(s.value))
|
|
298
|
+
throw new Error(
|
|
299
|
+
`Invalid UTXO value ${s.value} for ${s.txid}:${s.vout}`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
282
302
|
return e.sort((s, c) => c.value - s.value).map((s) => ({
|
|
283
303
|
txid: s.txid,
|
|
284
304
|
vout: s.vout,
|
|
@@ -294,26 +314,37 @@ async function $t(n, t) {
|
|
|
294
314
|
);
|
|
295
315
|
}
|
|
296
316
|
}
|
|
297
|
-
function
|
|
298
|
-
return
|
|
317
|
+
function Vt(n) {
|
|
318
|
+
return Pt[n];
|
|
299
319
|
}
|
|
300
|
-
async function
|
|
301
|
-
return
|
|
320
|
+
async function Rt(n, t) {
|
|
321
|
+
return I(`${t}/address/${n}/txs`);
|
|
302
322
|
}
|
|
303
|
-
async function
|
|
323
|
+
async function Wt(n) {
|
|
304
324
|
const t = await fetch(`${n}/v1/fees/recommended`);
|
|
305
325
|
if (!t.ok)
|
|
306
326
|
throw new Error(
|
|
307
327
|
`Failed to fetch network fees: ${t.status} ${t.statusText}`
|
|
308
328
|
);
|
|
309
|
-
const e = await t.json()
|
|
310
|
-
|
|
329
|
+
const e = await t.json(), r = [
|
|
330
|
+
"fastestFee",
|
|
331
|
+
"halfHourFee",
|
|
332
|
+
"hourFee",
|
|
333
|
+
"economyFee",
|
|
334
|
+
"minimumFee"
|
|
335
|
+
];
|
|
336
|
+
for (const o of r)
|
|
337
|
+
if (!mt(e[o]))
|
|
338
|
+
throw new Error(
|
|
339
|
+
`Invalid fee rate ${o}=${e[o]} from mempool API: expected a positive number ≤ ${L}`
|
|
340
|
+
);
|
|
341
|
+
if (e.minimumFee > e.economyFee || e.economyFee > e.hourFee || e.hourFee > e.halfHourFee || e.halfHourFee > e.fastestFee)
|
|
311
342
|
throw new Error(
|
|
312
|
-
|
|
343
|
+
`Fee rate ordering violation from mempool API: expected minimumFee (${e.minimumFee}) <= economyFee (${e.economyFee}) <= hourFee (${e.hourFee}) <= halfHourFee (${e.halfHourFee}) <= fastestFee (${e.fastestFee}).`
|
|
313
344
|
);
|
|
314
345
|
return e;
|
|
315
346
|
}
|
|
316
|
-
const
|
|
347
|
+
const H = [
|
|
317
348
|
{
|
|
318
349
|
type: "function",
|
|
319
350
|
name: "submitPeginRequest",
|
|
@@ -572,7 +603,7 @@ const $ = [
|
|
|
572
603
|
name: "PeginSignaturesIncomplete",
|
|
573
604
|
inputs: []
|
|
574
605
|
}
|
|
575
|
-
],
|
|
606
|
+
], P = {
|
|
576
607
|
// VaultAlreadyExists()
|
|
577
608
|
"0x04aabf33": "Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.",
|
|
578
609
|
// ScriptPubKeyMismatch() - taproot output doesn't match expected script
|
|
@@ -602,7 +633,7 @@ const $ = [
|
|
|
602
633
|
// InvalidPeginFee(uint256,uint256)
|
|
603
634
|
"0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
|
|
604
635
|
};
|
|
605
|
-
function
|
|
636
|
+
function U(n) {
|
|
606
637
|
if (!n || typeof n != "object") return;
|
|
607
638
|
const t = n;
|
|
608
639
|
if (typeof t.data == "string" && t.data.startsWith("0x"))
|
|
@@ -621,24 +652,24 @@ function A(n) {
|
|
|
621
652
|
if (c)
|
|
622
653
|
return c[1];
|
|
623
654
|
}
|
|
624
|
-
function
|
|
625
|
-
const t =
|
|
655
|
+
function Nt(n) {
|
|
656
|
+
const t = U(n);
|
|
626
657
|
if (t) {
|
|
627
658
|
const e = t.substring(0, 10);
|
|
628
|
-
return
|
|
659
|
+
return P[t] ?? P[e];
|
|
629
660
|
}
|
|
630
661
|
}
|
|
631
|
-
function
|
|
632
|
-
const t =
|
|
662
|
+
function Kt(n) {
|
|
663
|
+
const t = U(n);
|
|
633
664
|
if (t === void 0) return !1;
|
|
634
665
|
const e = t.substring(0, 10);
|
|
635
|
-
return t in
|
|
666
|
+
return t in P || e in P;
|
|
636
667
|
}
|
|
637
668
|
function z(n) {
|
|
638
669
|
console.error("[Contract Error] Raw error:", n);
|
|
639
|
-
const t =
|
|
670
|
+
const t = U(n);
|
|
640
671
|
if (console.error("[Contract Error] Extracted error data:", t), t) {
|
|
641
|
-
const r = t.substring(0, 10), o =
|
|
672
|
+
const r = t.substring(0, 10), o = P[t] ?? P[r];
|
|
642
673
|
if (o)
|
|
643
674
|
throw console.error("[Contract Error] Known error:", o), new Error(o);
|
|
644
675
|
}
|
|
@@ -656,14 +687,14 @@ function z(n) {
|
|
|
656
687
|
}
|
|
657
688
|
throw n instanceof Error ? (console.error("[Contract Error] Unhandled error:", n.message), n) : new Error(`Contract call failed: ${String(n)}`);
|
|
658
689
|
}
|
|
659
|
-
class
|
|
690
|
+
class Mt {
|
|
660
691
|
/**
|
|
661
692
|
* Creates a new PeginManager instance.
|
|
662
693
|
*
|
|
663
694
|
* @param config - Manager configuration including wallets and contract addresses
|
|
664
695
|
*/
|
|
665
696
|
constructor(t) {
|
|
666
|
-
|
|
697
|
+
S(this, "config");
|
|
667
698
|
this.config = t;
|
|
668
699
|
}
|
|
669
700
|
/**
|
|
@@ -705,23 +736,23 @@ class Ft {
|
|
|
705
736
|
councilQuorum: t.councilQuorum,
|
|
706
737
|
councilSize: t.councilSize,
|
|
707
738
|
network: this.config.btcNetwork
|
|
708
|
-
}, u = await
|
|
739
|
+
}, u = await ot(a), l = ft(
|
|
709
740
|
[...t.availableUTXOs],
|
|
710
741
|
u.totalOutputValue,
|
|
711
742
|
t.mempoolFeeRate
|
|
712
|
-
), p =
|
|
743
|
+
), p = C(this.config.btcNetwork), h = at({
|
|
713
744
|
unfundedTxHex: u.psbtHex,
|
|
714
745
|
selectedUTXOs: l.selectedUTXOs,
|
|
715
746
|
changeAddress: t.changeAddress,
|
|
716
747
|
changeAmount: l.changeAmount,
|
|
717
748
|
network: p
|
|
718
|
-
}),
|
|
749
|
+
}), y = k(_(h)), m = await it({
|
|
719
750
|
prePeginParams: a,
|
|
720
751
|
timelockPegin: t.timelockPegin,
|
|
721
752
|
fundedPrePeginTxHex: h,
|
|
722
753
|
htlcVout: D
|
|
723
|
-
}), x = await
|
|
724
|
-
peginTxHex:
|
|
754
|
+
}), x = await ct({
|
|
755
|
+
peginTxHex: m.txHex,
|
|
725
756
|
fundedPrePeginTxHex: h,
|
|
726
757
|
depositorPubkey: r,
|
|
727
758
|
vaultProviderPubkey: o,
|
|
@@ -733,19 +764,19 @@ class Ft {
|
|
|
733
764
|
}), d = await this.config.btcWallet.signPsbt(
|
|
734
765
|
x.psbtHex,
|
|
735
766
|
O(e, 1)
|
|
736
|
-
),
|
|
767
|
+
), f = ut(
|
|
737
768
|
d,
|
|
738
769
|
r
|
|
739
|
-
), b =
|
|
770
|
+
), b = lt(d);
|
|
740
771
|
return {
|
|
741
772
|
fundedPrePeginTxHex: h,
|
|
742
773
|
htlcValue: u.htlcValue,
|
|
743
774
|
signedPeginInputPsbtHex: d,
|
|
744
|
-
peginInputSignature:
|
|
745
|
-
vaultScriptPubKey:
|
|
775
|
+
peginInputSignature: f,
|
|
776
|
+
vaultScriptPubKey: m.vaultScriptPubKey,
|
|
746
777
|
peginTxHex: b,
|
|
747
|
-
prePeginTxid:
|
|
748
|
-
peginTxid:
|
|
778
|
+
prePeginTxid: y,
|
|
779
|
+
peginTxid: m.txid,
|
|
749
780
|
selectedUTXOs: l.selectedUTXOs,
|
|
750
781
|
fee: l.fee,
|
|
751
782
|
changeAmount: l.changeAmount
|
|
@@ -767,10 +798,10 @@ class Ft {
|
|
|
767
798
|
* @throws Error if signing or broadcasting fails
|
|
768
799
|
*/
|
|
769
800
|
async signAndBroadcast(t) {
|
|
770
|
-
const { fundedPrePeginTxHex: e, depositorBtcPubkey: r } = t, o = e.startsWith("0x") ? e.slice(2) : e, s =
|
|
801
|
+
const { fundedPrePeginTxHex: e, depositorBtcPubkey: r } = t, o = e.startsWith("0x") ? e.slice(2) : e, s = $.fromHex(o);
|
|
771
802
|
if (s.ins.length === 0)
|
|
772
803
|
throw new Error("Transaction has no inputs");
|
|
773
|
-
const c = new
|
|
804
|
+
const c = new F();
|
|
774
805
|
c.setVersion(s.version), c.setLocktime(s.locktime);
|
|
775
806
|
const i = r.startsWith("0x") ? r.slice(2) : r;
|
|
776
807
|
if (i.length !== 64 || !/^[0-9a-fA-F]+$/.test(i))
|
|
@@ -783,19 +814,19 @@ class Ft {
|
|
|
783
814
|
`Invalid depositorBtcPubkey length: expected 32 bytes, got ${a.length}`
|
|
784
815
|
);
|
|
785
816
|
const u = this.config.mempoolApiUrl, l = s.ins.map((d) => {
|
|
786
|
-
const
|
|
787
|
-
return
|
|
817
|
+
const f = g.from(d.hash).reverse().toString("hex"), b = d.index;
|
|
818
|
+
return Tt(f, b, u).then((w) => ({
|
|
788
819
|
input: d,
|
|
789
820
|
utxoData: w,
|
|
790
|
-
txid:
|
|
821
|
+
txid: f,
|
|
791
822
|
vout: b
|
|
792
823
|
}));
|
|
793
824
|
}), p = await Promise.all(l);
|
|
794
|
-
for (const { input: d, utxoData:
|
|
795
|
-
const T =
|
|
825
|
+
for (const { input: d, utxoData: f, txid: b, vout: w } of p) {
|
|
826
|
+
const T = yt(
|
|
796
827
|
{
|
|
797
|
-
value:
|
|
798
|
-
scriptPubKey:
|
|
828
|
+
value: f.value,
|
|
829
|
+
scriptPubKey: f.scriptPubKey
|
|
799
830
|
},
|
|
800
831
|
a
|
|
801
832
|
);
|
|
@@ -811,19 +842,19 @@ class Ft {
|
|
|
811
842
|
script: d.script,
|
|
812
843
|
value: d.value
|
|
813
844
|
});
|
|
814
|
-
const h = await this.config.btcWallet.signPsbt(c.toHex()),
|
|
845
|
+
const h = await this.config.btcWallet.signPsbt(c.toHex()), y = F.fromHex(h);
|
|
815
846
|
try {
|
|
816
|
-
|
|
847
|
+
y.finalizeAllInputs();
|
|
817
848
|
} catch (d) {
|
|
818
|
-
if (!
|
|
849
|
+
if (!y.data.inputs.every(
|
|
819
850
|
(b) => b.finalScriptWitness || b.finalScriptSig
|
|
820
851
|
))
|
|
821
852
|
throw new Error(
|
|
822
853
|
`PSBT finalization failed and wallet did not auto-finalize: ${d}`
|
|
823
854
|
);
|
|
824
855
|
}
|
|
825
|
-
const
|
|
826
|
-
return await
|
|
856
|
+
const m = y.extractTransaction().toHex();
|
|
857
|
+
return await xt(m, u);
|
|
827
858
|
}
|
|
828
859
|
/**
|
|
829
860
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -861,12 +892,12 @@ class Ft {
|
|
|
861
892
|
l
|
|
862
893
|
);
|
|
863
894
|
i && await i();
|
|
864
|
-
const
|
|
895
|
+
const y = B(e), m = B(r), x = B(o), d = await this.resolvePayoutScriptPubKey(
|
|
865
896
|
a
|
|
866
|
-
),
|
|
867
|
-
if (await this.checkVaultExists(
|
|
897
|
+
), f = _(x);
|
|
898
|
+
if (await this.checkVaultExists(f))
|
|
868
899
|
throw new Error(
|
|
869
|
-
`Vault already exists for this transaction (ID: ${
|
|
900
|
+
`Vault already exists for this transaction (ID: ${f}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`
|
|
870
901
|
);
|
|
871
902
|
const w = M({
|
|
872
903
|
chain: this.config.ethChain,
|
|
@@ -876,7 +907,7 @@ class Ft {
|
|
|
876
907
|
try {
|
|
877
908
|
T = await w.readContract({
|
|
878
909
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
879
|
-
abi:
|
|
910
|
+
abi: H,
|
|
880
911
|
functionName: "getPegInFee",
|
|
881
912
|
args: [s]
|
|
882
913
|
});
|
|
@@ -885,14 +916,14 @@ class Ft {
|
|
|
885
916
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
|
|
886
917
|
);
|
|
887
918
|
}
|
|
888
|
-
const
|
|
889
|
-
abi:
|
|
919
|
+
const A = pt({
|
|
920
|
+
abi: H,
|
|
890
921
|
functionName: "submitPeginRequest",
|
|
891
922
|
args: [
|
|
892
923
|
p,
|
|
893
|
-
|
|
924
|
+
y,
|
|
894
925
|
h,
|
|
895
|
-
|
|
926
|
+
m,
|
|
896
927
|
x,
|
|
897
928
|
s,
|
|
898
929
|
c,
|
|
@@ -901,11 +932,11 @@ class Ft {
|
|
|
901
932
|
u
|
|
902
933
|
]
|
|
903
934
|
});
|
|
904
|
-
let
|
|
935
|
+
let V;
|
|
905
936
|
try {
|
|
906
|
-
|
|
937
|
+
V = await w.estimateGas({
|
|
907
938
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
908
|
-
data:
|
|
939
|
+
data: A,
|
|
909
940
|
value: T,
|
|
910
941
|
account: this.config.ethWallet.account.address
|
|
911
942
|
});
|
|
@@ -916,13 +947,13 @@ class Ft {
|
|
|
916
947
|
return {
|
|
917
948
|
ethTxHash: await this.config.ethWallet.sendTransaction({
|
|
918
949
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
919
|
-
data:
|
|
950
|
+
data: A,
|
|
920
951
|
value: T,
|
|
921
952
|
account: this.config.ethWallet.account,
|
|
922
953
|
chain: this.config.ethChain,
|
|
923
|
-
gas:
|
|
954
|
+
gas: V
|
|
924
955
|
}),
|
|
925
|
-
vaultId:
|
|
956
|
+
vaultId: f,
|
|
926
957
|
btcPopSignature: h
|
|
927
958
|
};
|
|
928
959
|
} catch (v) {
|
|
@@ -942,10 +973,10 @@ class Ft {
|
|
|
942
973
|
transport: X()
|
|
943
974
|
}).readContract({
|
|
944
975
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
945
|
-
abi:
|
|
976
|
+
abi: H,
|
|
946
977
|
functionName: "getBTCVault",
|
|
947
978
|
args: [t]
|
|
948
|
-
})).depositor !==
|
|
979
|
+
})).depositor !== ht;
|
|
949
980
|
} catch {
|
|
950
981
|
return !1;
|
|
951
982
|
}
|
|
@@ -964,7 +995,7 @@ class Ft {
|
|
|
964
995
|
else {
|
|
965
996
|
e = await this.config.btcWallet.getAddress();
|
|
966
997
|
const o = await this.config.btcWallet.getPublicKeyHex();
|
|
967
|
-
if (!
|
|
998
|
+
if (!dt(
|
|
968
999
|
e,
|
|
969
1000
|
o,
|
|
970
1001
|
this.config.btcNetwork
|
|
@@ -973,9 +1004,9 @@ class Ft {
|
|
|
973
1004
|
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
974
1005
|
);
|
|
975
1006
|
}
|
|
976
|
-
const r =
|
|
1007
|
+
const r = C(this.config.btcNetwork);
|
|
977
1008
|
try {
|
|
978
|
-
return `0x${
|
|
1009
|
+
return `0x${Q.address.toOutputScript(e, r).toString("hex")}`;
|
|
979
1010
|
} catch {
|
|
980
1011
|
throw new Error(
|
|
981
1012
|
`Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1014,14 +1045,14 @@ class Ft {
|
|
|
1014
1045
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1015
1046
|
}
|
|
1016
1047
|
}
|
|
1017
|
-
class
|
|
1048
|
+
class Xt {
|
|
1018
1049
|
/**
|
|
1019
1050
|
* Creates a new PayoutManager instance.
|
|
1020
1051
|
*
|
|
1021
1052
|
* @param config - Manager configuration including wallet
|
|
1022
1053
|
*/
|
|
1023
1054
|
constructor(t) {
|
|
1024
|
-
|
|
1055
|
+
S(this, "config");
|
|
1025
1056
|
this.config = t;
|
|
1026
1057
|
}
|
|
1027
1058
|
/**
|
|
@@ -1050,7 +1081,7 @@ class Vt {
|
|
|
1050
1081
|
const e = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: r } = W(
|
|
1051
1082
|
e,
|
|
1052
1083
|
t.depositorBtcPubkey
|
|
1053
|
-
), o = await
|
|
1084
|
+
), o = await N({
|
|
1054
1085
|
payoutTxHex: t.payoutTxHex,
|
|
1055
1086
|
peginTxHex: t.peginTxHex,
|
|
1056
1087
|
assertTxHex: t.assertTxHex,
|
|
@@ -1065,7 +1096,7 @@ class Vt {
|
|
|
1065
1096
|
O(e, 1)
|
|
1066
1097
|
);
|
|
1067
1098
|
return {
|
|
1068
|
-
signature:
|
|
1099
|
+
signature: K(s, r),
|
|
1069
1100
|
depositorBtcPubkey: r
|
|
1070
1101
|
};
|
|
1071
1102
|
}
|
|
@@ -1106,7 +1137,7 @@ class Vt {
|
|
|
1106
1137
|
a.depositorBtcPubkey
|
|
1107
1138
|
);
|
|
1108
1139
|
s.push(u);
|
|
1109
|
-
const l = await
|
|
1140
|
+
const l = await N({
|
|
1110
1141
|
payoutTxHex: a.payoutTxHex,
|
|
1111
1142
|
peginTxHex: a.peginTxHex,
|
|
1112
1143
|
assertTxHex: a.assertTxHex,
|
|
@@ -1129,7 +1160,7 @@ class Vt {
|
|
|
1129
1160
|
);
|
|
1130
1161
|
const i = [];
|
|
1131
1162
|
for (let a = 0; a < t.length; a++) {
|
|
1132
|
-
const u = s[a], l =
|
|
1163
|
+
const u = s[a], l = K(
|
|
1133
1164
|
c[a],
|
|
1134
1165
|
u
|
|
1135
1166
|
);
|
|
@@ -1143,30 +1174,30 @@ class Vt {
|
|
|
1143
1174
|
}
|
|
1144
1175
|
export {
|
|
1145
1176
|
E as B,
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1177
|
+
P as C,
|
|
1178
|
+
Pt as M,
|
|
1179
|
+
Mt as P,
|
|
1180
|
+
Ht as a,
|
|
1181
|
+
Ct as b,
|
|
1151
1182
|
_ as c,
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1183
|
+
Ot as d,
|
|
1184
|
+
gt as e,
|
|
1185
|
+
yt as f,
|
|
1186
|
+
Ft as g,
|
|
1187
|
+
Xt as h,
|
|
1188
|
+
Rt as i,
|
|
1189
|
+
At as j,
|
|
1190
|
+
Vt as k,
|
|
1191
|
+
Wt as l,
|
|
1192
|
+
Ut as m,
|
|
1193
|
+
wt as n,
|
|
1194
|
+
Tt as o,
|
|
1195
|
+
xt as p,
|
|
1196
|
+
H as q,
|
|
1197
|
+
U as r,
|
|
1198
|
+
ft as s,
|
|
1199
|
+
Nt as t,
|
|
1200
|
+
Kt as u,
|
|
1170
1201
|
z as v
|
|
1171
1202
|
};
|
|
1172
|
-
//# sourceMappingURL=PayoutManager-
|
|
1203
|
+
//# sourceMappingURL=PayoutManager-6IBl1Fdt.js.map
|