@babylonlabs-io/ts-sdk 0.2.1-rc.3 → 0.4.0

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.
Files changed (51) hide show
  1. package/LICENSE +169 -0
  2. package/dist/{PayoutManager-rMj54HDh.js → PayoutManager-BK1jKgL5.js} +404 -361
  3. package/dist/PayoutManager-BK1jKgL5.js.map +1 -0
  4. package/dist/PayoutManager-CzKMN6xT.cjs +2 -0
  5. package/dist/PayoutManager-CzKMN6xT.cjs.map +1 -0
  6. package/dist/challengeAssert-DOa5L0kv.cjs +2 -0
  7. package/dist/challengeAssert-DOa5L0kv.cjs.map +1 -0
  8. package/dist/challengeAssert-Dvcg38_y.js +606 -0
  9. package/dist/challengeAssert-Dvcg38_y.js.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +62 -57
  12. package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts +50 -4
  13. package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts.map +1 -1
  14. package/dist/tbv/core/index.cjs +1 -1
  15. package/dist/tbv/core/index.js +62 -57
  16. package/dist/tbv/core/managers/PeginManager.d.ts +89 -48
  17. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  18. package/dist/tbv/core/managers/__tests__/PeginManager.test.d.ts +1 -1
  19. package/dist/tbv/core/managers/index.d.ts +4 -4
  20. package/dist/tbv/core/managers/index.d.ts.map +1 -1
  21. package/dist/tbv/core/primitives/index.cjs +1 -1
  22. package/dist/tbv/core/primitives/index.d.ts +5 -3
  23. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  24. package/dist/tbv/core/primitives/index.js +22 -18
  25. package/dist/tbv/core/primitives/psbt/__tests__/pegin.test.d.ts +1 -1
  26. package/dist/tbv/core/primitives/psbt/index.d.ts +8 -3
  27. package/dist/tbv/core/primitives/psbt/index.d.ts.map +1 -1
  28. package/dist/tbv/core/primitives/psbt/pegin.d.ts +76 -59
  29. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  30. package/dist/tbv/core/primitives/psbt/peginInput.d.ts +69 -0
  31. package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -0
  32. package/dist/tbv/core/primitives/utils/bitcoin.d.ts +11 -0
  33. package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
  34. package/dist/tbv/core/primitives/utils/index.d.ts +1 -1
  35. package/dist/tbv/core/primitives/utils/index.d.ts.map +1 -1
  36. package/dist/tbv/core/utils/fee/constants.d.ts +7 -0
  37. package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -1
  38. package/dist/tbv/index.cjs +1 -1
  39. package/dist/tbv/index.js +62 -57
  40. package/dist/tbv/integrations/aave/clients/abis/AaveIntegrationController.abi.json.d.ts +16 -1
  41. package/dist/tbv/integrations/aave/index.cjs +1 -1
  42. package/dist/tbv/integrations/aave/index.cjs.map +1 -1
  43. package/dist/tbv/integrations/aave/index.js +3 -3
  44. package/package.json +19 -19
  45. package/dist/PayoutManager-Dg_i_S7w.cjs +0 -2
  46. package/dist/PayoutManager-Dg_i_S7w.cjs.map +0 -1
  47. package/dist/PayoutManager-rMj54HDh.js.map +0 -1
  48. package/dist/challengeAssert-34HqeVFH.cjs +0 -2
  49. package/dist/challengeAssert-34HqeVFH.cjs.map +0 -1
  50. package/dist/challengeAssert-DVErOd8l.js +0 -423
  51. package/dist/challengeAssert-DVErOd8l.js.map +0 -1
@@ -1,195 +1,148 @@
1
- var X = Object.defineProperty;
2
- var L = (n, t, e) => t in n ? X(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var I = (n, t, e) => L(n, typeof t != "symbol" ? t + "" : t, e);
4
- import * as $ from "bitcoinjs-lib";
5
- import { script as D, Transaction as E, address as q, Psbt as S } from "bitcoinjs-lib";
6
- import { Buffer as p } from "buffer";
7
- import { m as C, s as T, b as z, k as j, v as A, a as O, e as W } from "./challengeAssert-DVErOd8l.js";
8
- import { createPublicClient as F, http as M, encodeFunctionData as Y, zeroAddress as J } from "viem";
1
+ var q = Object.defineProperty;
2
+ var _ = (n, t, e) => t in n ? q(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var H = (n, t, e) => _(n, typeof t != "symbol" ? t + "" : t, e);
4
+ import * as L from "bitcoinjs-lib";
5
+ import { script as j, Transaction as S, address as J, Psbt as C } from "bitcoinjs-lib";
6
+ import { Buffer as g } from "buffer";
7
+ import { P as Z, r as G, D as z, M as W, B as Q, T as Y, y as U, s as k, b as tt, x as et, a as nt, c as st, e as rt, p as I, n as at, v as V, d as M, f as R } from "./challengeAssert-Dvcg38_y.js";
8
+ import { createPublicClient as K, http as N, encodeFunctionData as ot, zeroAddress as it } from "viem";
9
9
  import "@babylonlabs-io/babylon-tbv-rust-wasm";
10
- import "@bitcoin-js/tiny-secp256k1-asmjs";
11
- const Z = 58, V = 43, G = 11, N = 546, H = BigInt(N), Q = 30, tt = 2, mt = 1.1;
12
- function et(n) {
13
- return n <= tt ? Q : 0;
14
- }
15
- function nt(n, t, e) {
10
+ function ct(n, t, e) {
16
11
  if (n.length === 0)
17
12
  throw new Error("Insufficient funds: no UTXOs available");
18
- const s = n.filter((r) => {
19
- const c = p.from(r.scriptPubKey, "hex");
20
- return !!D.decompile(c);
13
+ const s = n.filter((a) => {
14
+ const u = g.from(a.scriptPubKey, "hex");
15
+ return !!j.decompile(u);
21
16
  });
22
17
  if (s.length === 0)
23
18
  throw new Error(
24
19
  "Insufficient funds: no valid UTXOs available (all have invalid scripts)"
25
20
  );
26
- const a = [...s].sort((r, c) => c.value - r.value), o = [];
27
- let u = 0n, i = 0n;
28
- for (const r of a) {
29
- o.push(r), u += BigInt(r.value);
30
- const c = o.length * Z, l = 2 * V, d = c + l + G;
31
- if (i = BigInt(Math.ceil(d * e)) + BigInt(et(e)), u - t - i > H) {
32
- const g = BigInt(
33
- Math.ceil(V * e)
21
+ const o = [...s].sort((a, u) => u.value - a.value), r = [];
22
+ let c = 0n, i = 0n;
23
+ for (const a of o) {
24
+ r.push(a), c += BigInt(a.value);
25
+ const u = r.length * Z, l = 2 * W, d = u + l + Y;
26
+ if (i = BigInt(Math.ceil(d * e)) + BigInt(G(e)), c - t - i > z) {
27
+ const h = BigInt(
28
+ Math.ceil(W * e)
34
29
  );
35
- i += g;
30
+ i += h;
36
31
  }
37
- if (u >= t + i) {
38
- const g = u - t - i;
32
+ if (c >= t + i) {
33
+ const h = c - t - i;
39
34
  return {
40
- selectedUTXOs: o,
41
- totalValue: u,
35
+ selectedUTXOs: r,
36
+ totalValue: c,
42
37
  fee: i,
43
- changeAmount: g
38
+ changeAmount: h
44
39
  };
45
40
  }
46
41
  }
47
42
  throw new Error(
48
- `Insufficient funds: need ${t + i} sats (${t} pegin + ${i} fee), have ${u} sats`
43
+ `Insufficient funds: need ${t + i} sats (${t} pegin + ${i} fee), have ${c} sats`
49
44
  );
50
45
  }
51
46
  function wt(n) {
52
- return n > H;
47
+ return n > z;
53
48
  }
54
- function xt() {
55
- return N;
49
+ function Tt() {
50
+ return Q;
56
51
  }
57
- function st(n) {
58
- const e = n.substring(8, 12) === "0001" ? 12 : 8, s = parseInt(
59
- n.substring(e, e + 2),
60
- 16
61
- ), a = parseInt(
62
- n.substring(e + 2, e + 4),
63
- 16
64
- );
65
- if (s !== 0)
66
- throw new Error(`Expected 0 inputs from WASM, got ${s}`);
67
- if (a === 0)
68
- throw new Error("Expected at least 1 output from WASM, got 0");
69
- const o = p.from(n.substring(0, 8), "hex").readUInt32LE(0), u = p.from(
70
- n.substring(n.length - 8),
71
- "hex"
72
- ).readUInt32LE(0), i = [];
73
- let r = e + 4;
74
- for (let c = 0; c < a; c++) {
75
- const l = n.substring(r, r + 16), d = Number(p.from(l, "hex").readBigUInt64LE(0));
76
- r += 16;
77
- const f = parseInt(n.substring(r, r + 2), 16);
78
- r += 2;
79
- const g = n.substring(r, r + f * 2), b = p.from(g, "hex");
80
- r += f * 2, i.push({ value: d, script: b });
81
- }
82
- return { version: o, locktime: u, outputs: i };
83
- }
84
- function rt(n) {
85
- const { unfundedTxHex: t, selectedUTXOs: e, changeAddress: s, changeAmount: a, network: o } = n, { version: u, locktime: i, outputs: r } = st(t), c = new $.Transaction();
86
- c.version = u, c.locktime = i;
87
- for (const l of e) {
88
- const d = p.from(l.txid, "hex").reverse();
89
- c.addInput(d, l.vout);
90
- }
91
- for (const l of r)
92
- c.addOutput(l.script, l.value);
93
- if (a > H) {
94
- const l = $.address.toOutputScript(s, o);
95
- c.addOutput(l, Number(a));
96
- }
97
- return c.toHex();
98
- }
99
- function R(n) {
52
+ function X(n) {
100
53
  const t = n.startsWith("0x") ? n.slice(2) : n;
101
- return `0x${E.fromHex(t).getId()}`;
54
+ return `0x${S.fromHex(t).getId()}`;
102
55
  }
103
- function Pt(n, t, e) {
56
+ function vt(n, t, e) {
104
57
  if (n.length === 0)
105
58
  throw new Error("No input UTXOs provided for split transaction");
106
59
  if (t.length === 0)
107
60
  throw new Error("No outputs specified for split transaction");
108
- for (const r of t)
109
- if (r.amount <= 0n)
61
+ for (const a of t)
62
+ if (a.amount <= 0n)
110
63
  throw new Error(
111
- `Invalid output amount for ${r.address}: ${r.amount} satoshis. Amount must be greater than zero.`
64
+ `Invalid output amount for ${a.address}: ${a.amount} satoshis. Amount must be greater than zero.`
112
65
  );
113
- const s = C(e), a = new E();
114
- a.version = 2;
115
- for (const r of n) {
116
- const c = p.from(r.txid, "hex").reverse();
117
- a.addInput(c, r.vout);
66
+ const s = U(e), o = new S();
67
+ o.version = 2;
68
+ for (const a of n) {
69
+ const u = g.from(a.txid, "hex").reverse();
70
+ o.addInput(u, a.vout);
118
71
  }
119
- const o = [];
120
- for (let r = 0; r < t.length; r++) {
121
- const c = t[r];
72
+ const r = [];
73
+ for (let a = 0; a < t.length; a++) {
74
+ const u = t[a];
122
75
  let l;
123
76
  try {
124
- l = q.toOutputScript(c.address, s);
77
+ l = J.toOutputScript(u.address, s);
125
78
  } catch (d) {
126
79
  throw new Error(
127
- `Failed to decode address "${c.address}": ${d instanceof Error ? d.message : String(d)}`
80
+ `Failed to decode address "${u.address}": ${d instanceof Error ? d.message : String(d)}`
128
81
  );
129
82
  }
130
- a.addOutput(l, Number(c.amount)), o.push({
83
+ o.addOutput(l, Number(u.amount)), r.push({
131
84
  txid: "",
132
85
  // Will be set after txid calculation
133
- vout: r,
134
- value: Number(c.amount),
86
+ vout: a,
87
+ value: Number(u.amount),
135
88
  scriptPubKey: l.toString("hex")
136
89
  });
137
90
  }
138
- const u = a.toHex(), i = a.getId();
139
- for (const r of o)
140
- r.txid = i;
91
+ const c = o.toHex(), i = o.getId();
92
+ for (const a of r)
93
+ a.txid = i;
141
94
  return {
142
- txHex: u,
95
+ txHex: c,
143
96
  txid: i,
144
- outputs: o
97
+ outputs: r
145
98
  };
146
99
  }
147
- function Tt(n, t, e) {
148
- const s = E.fromHex(n), a = new S();
149
- if (a.setVersion(s.version), a.setLocktime(s.locktime), !p.isBuffer(e) || e.length !== 32)
100
+ function kt(n, t, e) {
101
+ const s = S.fromHex(n), o = new C();
102
+ if (o.setVersion(s.version), o.setLocktime(s.locktime), !g.isBuffer(e) || e.length !== 32)
150
103
  throw new Error(
151
- `Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${p.isBuffer(e) ? `${e.length}-byte Buffer` : typeof e}`
104
+ `Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${g.isBuffer(e) ? `${e.length}-byte Buffer` : typeof e}`
152
105
  );
153
106
  if (t.length !== s.ins.length)
154
107
  throw new Error(
155
108
  `UTXO count mismatch: transaction has ${s.ins.length} input${s.ins.length !== 1 ? "s" : ""}, but ${t.length} UTXO${t.length !== 1 ? "s were" : " was"} provided`
156
109
  );
157
- for (let o = 0; o < s.ins.length; o++) {
158
- const u = s.ins[o], i = t[o];
110
+ for (let r = 0; r < s.ins.length; r++) {
111
+ const c = s.ins[r], i = t[r];
159
112
  if (!i)
160
- throw new Error(`Missing UTXO data for input ${o}`);
161
- const r = p.from(u.hash).reverse().toString("hex"), c = u.index;
162
- if (i.txid !== r || i.vout !== c)
113
+ throw new Error(`Missing UTXO data for input ${r}`);
114
+ const a = g.from(c.hash).reverse().toString("hex"), u = c.index;
115
+ if (i.txid !== a || i.vout !== u)
163
116
  throw new Error(
164
- `Input ${o} outpoint mismatch: transaction expects ${r}:${c}, but UTXO ${i.txid}:${i.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
117
+ `Input ${r} outpoint mismatch: transaction expects ${a}:${u}, but UTXO ${i.txid}:${i.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`
165
118
  );
166
- const l = p.from(i.scriptPubKey, "hex");
119
+ const l = g.from(i.scriptPubKey, "hex");
167
120
  if (!(l.length === 34 && l[0] === 81 && // OP_1 (witness version 1)
168
121
  l[1] === 32))
169
122
  throw new Error(
170
- `Input ${o} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${i.scriptPubKey.substring(0, 20)}...`
123
+ `Input ${r} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${i.scriptPubKey.substring(0, 20)}...`
171
124
  );
172
125
  const f = {
173
- script: p.from(i.scriptPubKey, "hex"),
126
+ script: g.from(i.scriptPubKey, "hex"),
174
127
  value: i.value
175
128
  };
176
- a.addInput({
177
- hash: u.hash,
178
- index: u.index,
179
- sequence: u.sequence,
129
+ o.addInput({
130
+ hash: c.hash,
131
+ index: c.index,
132
+ sequence: c.sequence,
180
133
  witnessUtxo: f,
181
134
  tapInternalKey: e
182
135
  });
183
136
  }
184
- for (const o of s.outs)
185
- a.addOutput({
186
- script: o.script,
187
- value: o.value
137
+ for (const r of s.outs)
138
+ o.addOutput({
139
+ script: r.script,
140
+ value: r.value
188
141
  });
189
- return a.toHex();
142
+ return o.toHex();
190
143
  }
191
- var v = /* @__PURE__ */ ((n) => (n.P2PKH = "P2PKH", n.P2SH = "P2SH", n.P2WPKH = "P2WPKH", n.P2WSH = "P2WSH", n.P2TR = "P2TR", n.UNKNOWN = "UNKNOWN", n))(v || {});
192
- function ot(n) {
144
+ var B = /* @__PURE__ */ ((n) => (n.P2PKH = "P2PKH", n.P2SH = "P2SH", n.P2WPKH = "P2WPKH", n.P2WSH = "P2WSH", n.P2TR = "P2TR", n.UNKNOWN = "UNKNOWN", n))(B || {});
145
+ function ut(n) {
193
146
  const t = n.length;
194
147
  return t === 25 && n[0] === 118 && // OP_DUP
195
148
  n[1] === 169 && // OP_HASH160
@@ -202,17 +155,17 @@ function ot(n) {
202
155
  n[1] === 32 ? "P2WSH" : t === 34 && n[0] === 81 && // OP_1
203
156
  n[1] === 32 ? "P2TR" : "UNKNOWN";
204
157
  }
205
- function at(n, t) {
206
- const e = p.from(n.scriptPubKey, "hex"), s = ot(e);
158
+ function lt(n, t) {
159
+ const e = g.from(n.scriptPubKey, "hex"), s = ut(e);
207
160
  switch (s) {
208
- case v.P2WPKH:
161
+ case B.P2WPKH:
209
162
  return {
210
163
  witnessUtxo: {
211
164
  script: e,
212
165
  value: n.value
213
166
  }
214
167
  };
215
- case v.P2WSH: {
168
+ case B.P2WSH: {
216
169
  if (!n.witnessScript)
217
170
  throw new Error("Missing witnessScript for P2WSH input");
218
171
  return {
@@ -220,10 +173,10 @@ function at(n, t) {
220
173
  script: e,
221
174
  value: n.value
222
175
  },
223
- witnessScript: p.from(n.witnessScript, "hex")
176
+ witnessScript: g.from(n.witnessScript, "hex")
224
177
  };
225
178
  }
226
- case v.P2TR: {
179
+ case B.P2TR: {
227
180
  if (t && t.length !== 32)
228
181
  throw new Error(
229
182
  `Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`
@@ -241,18 +194,18 @@ function at(n, t) {
241
194
  throw new Error(`Unsupported script type: ${s}`);
242
195
  }
243
196
  }
244
- const it = {
197
+ const dt = {
245
198
  mainnet: "https://mempool.space/api",
246
199
  testnet: "https://mempool.space/testnet/api",
247
200
  signet: "https://mempool.space/signet/api"
248
201
  };
249
- async function k(n, t) {
202
+ async function E(n, t) {
250
203
  try {
251
204
  const e = await fetch(n, t);
252
205
  if (!e.ok) {
253
- const a = await e.text();
206
+ const o = await e.text();
254
207
  throw new Error(
255
- `Mempool API error (${e.status}): ${a || e.statusText}`
208
+ `Mempool API error (${e.status}): ${o || e.statusText}`
256
209
  );
257
210
  }
258
211
  const s = e.headers.get("content-type");
@@ -261,7 +214,7 @@ async function k(n, t) {
261
214
  throw e instanceof Error ? new Error(`Failed to fetch from mempool API: ${e.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
262
215
  }
263
216
  }
264
- async function ct(n, t) {
217
+ async function pt(n, t) {
265
218
  try {
266
219
  const e = await fetch(`${t}/tx`, {
267
220
  method: "POST",
@@ -271,15 +224,15 @@ async function ct(n, t) {
271
224
  }
272
225
  });
273
226
  if (!e.ok) {
274
- const a = await e.text();
275
- let o;
227
+ const o = await e.text();
228
+ let r;
276
229
  try {
277
- o = JSON.parse(a).message;
230
+ r = JSON.parse(o).message;
278
231
  } catch {
279
- o = a;
232
+ r = o;
280
233
  }
281
234
  throw new Error(
282
- o || `Failed to broadcast transaction: ${e.statusText}`
235
+ r || `Failed to broadcast transaction: ${e.statusText}`
283
236
  );
284
237
  }
285
238
  return await e.text();
@@ -287,10 +240,10 @@ async function ct(n, t) {
287
240
  throw e instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${e.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
288
241
  }
289
242
  }
290
- async function ut(n, t) {
291
- return k(`${t}/tx/${n}`);
243
+ async function ht(n, t) {
244
+ return E(`${t}/tx/${n}`);
292
245
  }
293
- async function vt(n, t) {
246
+ async function Bt(n, t) {
294
247
  try {
295
248
  const e = await fetch(`${t}/tx/${n}/hex`);
296
249
  if (!e.ok) {
@@ -304,33 +257,33 @@ async function vt(n, t) {
304
257
  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`);
305
258
  }
306
259
  }
307
- async function lt(n, t, e) {
308
- const s = await ut(n, e);
260
+ async function gt(n, t, e) {
261
+ const s = await ht(n, e);
309
262
  if (t >= s.vout.length)
310
263
  throw new Error(
311
264
  `Invalid vout ${t} for transaction ${n} (has ${s.vout.length} outputs)`
312
265
  );
313
- const a = s.vout[t];
266
+ const o = s.vout[t];
314
267
  return {
315
268
  txid: n,
316
269
  vout: t,
317
- value: a.value,
318
- scriptPubKey: a.scriptpubkey
270
+ value: o.value,
271
+ scriptPubKey: o.scriptpubkey
319
272
  };
320
273
  }
321
- async function kt(n, t) {
274
+ async function Et(n, t) {
322
275
  try {
323
- const e = await k(`${t}/address/${n}/utxo`), s = await k(`${t}/v1/validate-address/${n}`);
276
+ const e = await E(`${t}/address/${n}/utxo`), s = await E(`${t}/v1/validate-address/${n}`);
324
277
  if (!s.isvalid)
325
278
  throw new Error(
326
279
  `Invalid Bitcoin address: ${n}. Mempool API validation failed.`
327
280
  );
328
- return e.sort((o, u) => u.value - o.value).map((o) => ({
329
- txid: o.txid,
330
- vout: o.vout,
331
- value: o.value,
281
+ return e.sort((r, c) => c.value - r.value).map((r) => ({
282
+ txid: r.txid,
283
+ vout: r.vout,
284
+ value: r.value,
332
285
  scriptPubKey: s.scriptPubKey,
333
- confirmed: o.status.confirmed
286
+ confirmed: r.status.confirmed
334
287
  }));
335
288
  } catch (e) {
336
289
  throw e instanceof Error ? new Error(
@@ -340,13 +293,13 @@ async function kt(n, t) {
340
293
  );
341
294
  }
342
295
  }
343
- function Et(n) {
344
- return it[n];
296
+ function St(n) {
297
+ return dt[n];
345
298
  }
346
- async function It(n, t) {
347
- return k(`${t}/address/${n}/txs`);
299
+ async function Ht(n, t) {
300
+ return E(`${t}/address/${n}/txs`);
348
301
  }
349
- async function Bt(n) {
302
+ async function It(n) {
350
303
  const t = await fetch(`${n}/v1/fees/recommended`);
351
304
  if (!t.ok)
352
305
  throw new Error(
@@ -359,7 +312,7 @@ async function Bt(n) {
359
312
  );
360
313
  return e;
361
314
  }
362
- const B = [
315
+ const $ = [
363
316
  {
364
317
  type: "function",
365
318
  name: "submitPeginRequest",
@@ -380,7 +333,12 @@ const B = [
380
333
  internalType: "bytes"
381
334
  },
382
335
  {
383
- name: "unsignedPegInTx",
336
+ name: "unsignedPrePeginTx",
337
+ type: "bytes",
338
+ internalType: "bytes"
339
+ },
340
+ {
341
+ name: "depositorSignedPeginTx",
384
342
  type: "bytes",
385
343
  internalType: "bytes"
386
344
  },
@@ -389,6 +347,11 @@ const B = [
389
347
  type: "address",
390
348
  internalType: "address"
391
349
  },
350
+ {
351
+ name: "hashlock",
352
+ type: "bytes32",
353
+ internalType: "bytes32"
354
+ },
392
355
  {
393
356
  name: "depositorPayoutBtcAddress",
394
357
  type: "bytes",
@@ -429,7 +392,12 @@ const B = [
429
392
  internalType: "bytes"
430
393
  },
431
394
  {
432
- name: "unsignedPegInTx",
395
+ name: "unsignedPrePeginTx",
396
+ type: "bytes",
397
+ internalType: "bytes"
398
+ },
399
+ {
400
+ name: "depositorSignedPeginTx",
433
401
  type: "bytes",
434
402
  internalType: "bytes"
435
403
  },
@@ -438,6 +406,11 @@ const B = [
438
406
  type: "address",
439
407
  internalType: "address"
440
408
  },
409
+ {
410
+ name: "hashlock",
411
+ type: "bytes32",
412
+ internalType: "bytes32"
413
+ },
441
414
  {
442
415
  name: "referralCode",
443
416
  type: "uint32",
@@ -463,6 +436,24 @@ const B = [
463
436
  ],
464
437
  stateMutability: "payable"
465
438
  },
439
+ {
440
+ type: "function",
441
+ name: "activateVaultWithSecret",
442
+ inputs: [
443
+ {
444
+ name: "vaultId",
445
+ type: "bytes32",
446
+ internalType: "bytes32"
447
+ },
448
+ {
449
+ name: "s",
450
+ type: "bytes32",
451
+ internalType: "bytes32"
452
+ }
453
+ ],
454
+ outputs: [],
455
+ stateMutability: "nonpayable"
456
+ },
466
457
  {
467
458
  type: "function",
468
459
  name: "getPegInFee",
@@ -500,7 +491,7 @@ const B = [
500
491
  components: [
501
492
  { name: "depositor", type: "address", internalType: "address" },
502
493
  { name: "depositorBtcPubKey", type: "bytes32", internalType: "bytes32" },
503
- { name: "unsignedPegInTx", type: "bytes", internalType: "bytes" },
494
+ { name: "depositorSignedPeginTx", type: "bytes", internalType: "bytes" },
504
495
  { name: "amount", type: "uint256", internalType: "uint256" },
505
496
  { name: "vaultProvider", type: "address", internalType: "address" },
506
497
  { name: "status", type: "uint8", internalType: "enum IBTCVaultsManager.BTCVaultStatus" },
@@ -508,9 +499,11 @@ const B = [
508
499
  { name: "universalChallengersVersion", type: "uint16", internalType: "uint16" },
509
500
  { name: "appVaultKeepersVersion", type: "uint16", internalType: "uint16" },
510
501
  { name: "offchainParamsVersion", type: "uint16", internalType: "uint16" },
502
+ { name: "vkVersion", type: "uint16", internalType: "uint16" },
511
503
  { name: "createdAt", type: "uint256", internalType: "uint256" },
512
504
  { name: "verifiedAt", type: "uint256", internalType: "uint256" },
513
- { name: "depositorLamportPkHash", type: "bytes32", internalType: "bytes32" }
505
+ { name: "depositorLamportPkHash", type: "bytes32", internalType: "bytes32" },
506
+ { name: "hashlock", type: "bytes32", internalType: "bytes32" }
514
507
  ]
515
508
  }
516
509
  ],
@@ -531,6 +524,16 @@ const B = [
531
524
  internalType: "uint256"
532
525
  }
533
526
  ]
527
+ },
528
+ {
529
+ type: "error",
530
+ name: "InvalidSecret",
531
+ inputs: []
532
+ },
533
+ {
534
+ type: "error",
535
+ name: "ActivationDeadlineExpired",
536
+ inputs: []
534
537
  }
535
538
  ], x = {
536
539
  // VaultAlreadyExists()
@@ -562,7 +565,7 @@ const B = [
562
565
  // InvalidPeginFee(uint256,uint256)
563
566
  "0x979f4518": "Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."
564
567
  };
565
- function U(n) {
568
+ function O(n) {
566
569
  if (!n || typeof n != "object") return;
567
570
  const t = n;
568
571
  if (typeof t.data == "string" && t.data.startsWith("0x"))
@@ -570,37 +573,37 @@ function U(n) {
570
573
  if (typeof t.details == "string" && t.details.startsWith("0x"))
571
574
  return t.details;
572
575
  let e = t.cause, s = 0;
573
- const a = 5;
574
- for (; e && typeof e == "object" && s < a; ) {
576
+ const o = 5;
577
+ for (; e && typeof e == "object" && s < o; ) {
575
578
  const i = e;
576
579
  if (typeof i.data == "string" && i.data.startsWith("0x"))
577
580
  return i.data;
578
581
  e = i.cause, s++;
579
582
  }
580
- const u = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
581
- if (u)
582
- return u[1];
583
+ const c = (typeof t.message == "string" ? t.message : "").match(/\b(0x[a-fA-F0-9]{8})\b/);
584
+ if (c)
585
+ return c[1];
583
586
  }
584
587
  function $t(n) {
585
- const t = U(n);
588
+ const t = O(n);
586
589
  if (t) {
587
590
  const e = t.substring(0, 10);
588
591
  return x[t] ?? x[e];
589
592
  }
590
593
  }
591
- function St(n) {
592
- const t = U(n);
594
+ function Ct(n) {
595
+ const t = O(n);
593
596
  if (t === void 0) return !1;
594
597
  const e = t.substring(0, 10);
595
598
  return t in x || e in x;
596
599
  }
597
- function K(n) {
600
+ function D(n) {
598
601
  console.error("[Contract Error] Raw error:", n);
599
- const t = U(n);
602
+ const t = O(n);
600
603
  if (console.error("[Contract Error] Extracted error data:", t), t) {
601
- const s = t.substring(0, 10), a = x[t] ?? x[s];
602
- if (a)
603
- throw console.error("[Contract Error] Known error:", a), new Error(a);
604
+ const s = t.substring(0, 10), o = x[t] ?? x[s];
605
+ if (o)
606
+ throw console.error("[Contract Error] Known error:", o), new Error(o);
604
607
  }
605
608
  const e = (n == null ? void 0 : n.message) || "";
606
609
  if (e.includes("gas limit too high") || e.includes("21000000") || e.includes("Internal JSON-RPC error")) {
@@ -616,61 +619,102 @@ function K(n) {
616
619
  }
617
620
  throw n instanceof Error ? (console.error("[Contract Error] Unhandled error:", n.message), n) : new Error(`Contract call failed: ${String(n)}`);
618
621
  }
619
- class Ct {
622
+ class Ut {
620
623
  /**
621
624
  * Creates a new PeginManager instance.
622
625
  *
623
626
  * @param config - Manager configuration including wallets and contract addresses
624
627
  */
625
628
  constructor(t) {
626
- I(this, "config");
629
+ H(this, "config");
627
630
  this.config = t;
628
631
  }
629
632
  /**
630
- * Prepares a peg-in transaction by building and funding it.
633
+ * Prepares an atomic swap peg-in by building the Pre-PegIn HTLC transaction,
634
+ * funding it, constructing the PegIn transaction, and signing the PegIn input.
631
635
  *
632
636
  * This method orchestrates the following steps:
633
637
  * 1. Get depositor BTC public key from wallet
634
- * 2. Build unfunded PSBT using primitives
635
- * 3. Select UTXOs using iterative fee calculation
636
- * 4. Fund transaction by adding inputs and change output
638
+ * 2. Build unfunded Pre-PegIn transaction (HTLC output) using primitives
639
+ * 3. Select UTXOs to cover the HTLC value
640
+ * 4. Fund the Pre-PegIn transaction
641
+ * 5. Derive the PegIn transaction from the funded Pre-PegIn txid
642
+ * 6. Build PSBT for signing the PegIn input (HTLC leaf 0)
643
+ * 7. Sign via BTC wallet and extract depositor signature
637
644
  *
638
- * The returned transaction is funded but unsigned. Use `signAndBroadcast()`
639
- * to complete the Bitcoin side, and `registerPeginOnChain()` for Ethereum.
645
+ * The returned `fundedPrePeginTxHex` is funded but unsigned (inputs unsigned).
646
+ * Use `signAndBroadcast()` AFTER registering on Ethereum to broadcast it.
640
647
  *
641
- * @param params - Peg-in parameters including amount, provider, UTXOs, and fee rate
642
- * @returns Peg-in result with funded transaction and selection details
648
+ * @param params - Atomic pegin parameters including amount, HTLC params, UTXOs
649
+ * @returns Atomic pegin result with funded Pre-PegIn tx, signed PegIn input, and signatures
643
650
  * @throws Error if wallet operations fail or insufficient funds
644
651
  */
645
- async preparePegin(t) {
646
- const e = await this.config.btcWallet.getPublicKeyHex(), s = e.length === 66 ? e.slice(2) : e, a = T(t.vaultProviderBtcPubkey), o = t.vaultKeeperBtcPubkeys.map(T), u = t.universalChallengerBtcPubkeys.map(T), i = await z({
652
+ async prepareAtomicPegin(t) {
653
+ const e = await this.config.btcWallet.getPublicKeyHex(), s = e.length === 66 ? e.slice(2) : e, o = k(t.vaultProviderBtcPubkey), r = t.vaultKeeperBtcPubkeys.map(k), c = t.universalChallengerBtcPubkeys.map(k), i = {
647
654
  depositorPubkey: s,
648
- vaultProviderPubkey: a,
649
- vaultKeeperPubkeys: o,
650
- universalChallengerPubkeys: u,
651
- timelockPegin: t.timelockPegin,
655
+ vaultProviderPubkey: o,
656
+ vaultKeeperPubkeys: r,
657
+ universalChallengerPubkeys: c,
658
+ hashH: t.hashH,
659
+ timelockRefund: t.timelockRefund,
652
660
  pegInAmount: t.amount,
653
- depositorClaimValue: t.depositorClaimValue,
661
+ feeRate: BigInt(t.feeRate),
662
+ numLocalChallengers: t.numLocalChallengers,
663
+ councilQuorum: t.councilQuorum,
664
+ councilSize: t.councilSize,
654
665
  network: this.config.btcNetwork
655
- }), r = t.amount + t.depositorClaimValue, c = nt(
656
- t.availableUTXOs,
657
- r,
666
+ }, a = await tt(i), u = ct(
667
+ [...t.availableUTXOs],
668
+ a.totalOutputValue,
658
669
  t.feeRate
659
- ), l = C(this.config.btcNetwork), d = rt({
660
- unfundedTxHex: i.psbtHex,
661
- selectedUTXOs: c.selectedUTXOs,
670
+ ), l = U(this.config.btcNetwork), d = et({
671
+ unfundedTxHex: a.psbtHex,
672
+ selectedUTXOs: u.selectedUTXOs,
662
673
  changeAddress: t.changeAddress,
663
- changeAmount: c.changeAmount,
674
+ changeAmount: u.changeAmount,
664
675
  network: l
665
- }), f = R(d);
676
+ }), f = k(X(d)), h = await nt({
677
+ prePeginParams: i,
678
+ timelockPegin: t.timelockPegin,
679
+ fundedPrePeginTxid: f
680
+ }), m = await st({
681
+ peginTxHex: h.txHex,
682
+ fundedPrePeginTxHex: d,
683
+ depositorPubkey: s,
684
+ vaultProviderPubkey: o,
685
+ vaultKeeperPubkeys: r,
686
+ universalChallengerPubkeys: c,
687
+ hashH: t.hashH,
688
+ timelockRefund: t.timelockRefund,
689
+ network: this.config.btcNetwork
690
+ }), P = await this.config.btcWallet.signPsbt(
691
+ m.psbtHex,
692
+ {
693
+ autoFinalized: !1,
694
+ signInputs: [
695
+ {
696
+ index: 0,
697
+ publicKey: e,
698
+ disableTweakSigner: !0
699
+ }
700
+ ]
701
+ }
702
+ ), p = rt(
703
+ P,
704
+ s
705
+ );
666
706
  return {
667
- btcTxHash: T(f),
668
- fundedTxHex: d,
669
- vaultScriptPubKey: i.vaultScriptPubKey,
670
- selectedUTXOs: c.selectedUTXOs,
671
- fee: c.fee,
672
- changeAmount: c.changeAmount,
673
- ethTxHash: null
707
+ fundedPrePeginTxHex: d,
708
+ htlcValue: a.htlcValue,
709
+ signedPeginInputPsbtHex: P,
710
+ peginInputSignature: p,
711
+ vaultScriptPubKey: h.vaultScriptPubKey,
712
+ peginTxHex: h.txHex,
713
+ prePeginTxid: f,
714
+ peginTxid: h.txid,
715
+ selectedUTXOs: u.selectedUTXOs,
716
+ fee: u.fee,
717
+ changeAmount: u.changeAmount
674
718
  };
675
719
  }
676
720
  /**
@@ -689,57 +733,63 @@ class Ct {
689
733
  * @throws Error if signing or broadcasting fails
690
734
  */
691
735
  async signAndBroadcast(t) {
692
- const { fundedTxHex: e, depositorBtcPubkey: s } = t, a = e.startsWith("0x") ? e.slice(2) : e, o = E.fromHex(a);
693
- if (o.ins.length === 0)
736
+ const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = S.fromHex(o);
737
+ if (r.ins.length === 0)
694
738
  throw new Error("Transaction has no inputs");
695
- const u = new S();
696
- u.setVersion(o.version), u.setLocktime(o.locktime);
739
+ const c = new C();
740
+ c.setVersion(r.version), c.setLocktime(r.locktime);
697
741
  const i = s.startsWith("0x") ? s.slice(2) : s;
698
742
  if (i.length !== 64 || !/^[0-9a-fA-F]+$/.test(i))
699
743
  throw new Error(
700
744
  "Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)"
701
745
  );
702
- const r = p.from(i, "hex");
703
- if (r.length !== 32)
746
+ const a = g.from(i, "hex");
747
+ if (a.length !== 32)
704
748
  throw new Error(
705
- `Invalid depositorBtcPubkey length: expected 32 bytes, got ${r.length}`
749
+ `Invalid depositorBtcPubkey length: expected 32 bytes, got ${a.length}`
706
750
  );
707
- const c = this.config.mempoolApiUrl, l = o.ins.map((h) => {
708
- const y = p.from(h.hash).reverse().toString("hex"), m = h.index;
709
- return lt(y, m, c).then((P) => ({
710
- input: h,
711
- utxoData: P,
751
+ const u = this.config.mempoolApiUrl, l = r.ins.map((p) => {
752
+ const y = g.from(p.hash).reverse().toString("hex"), b = p.index;
753
+ return gt(y, b, u).then((w) => ({
754
+ input: p,
755
+ utxoData: w,
712
756
  txid: y,
713
- vout: m
757
+ vout: b
714
758
  }));
715
759
  }), d = await Promise.all(l);
716
- for (const { input: h, utxoData: y, txid: m, vout: P } of d) {
717
- const w = at(
760
+ for (const { input: p, utxoData: y, txid: b, vout: w } of d) {
761
+ const T = lt(
718
762
  {
719
763
  value: y.value,
720
764
  scriptPubKey: y.scriptPubKey
721
765
  },
722
- r
766
+ a
723
767
  );
724
- u.addInput({
725
- hash: h.hash,
726
- index: h.index,
727
- sequence: h.sequence,
728
- ...w
768
+ c.addInput({
769
+ hash: p.hash,
770
+ index: p.index,
771
+ sequence: p.sequence,
772
+ ...T
729
773
  });
730
774
  }
731
- for (const h of o.outs)
732
- u.addOutput({
733
- script: h.script,
734
- value: h.value
775
+ for (const p of r.outs)
776
+ c.addOutput({
777
+ script: p.script,
778
+ value: p.value
735
779
  });
736
- const f = await this.config.btcWallet.signPsbt(u.toHex()), g = S.fromHex(f);
780
+ const f = await this.config.btcWallet.signPsbt(c.toHex()), h = C.fromHex(f);
737
781
  try {
738
- g.finalizeAllInputs();
739
- } catch {
782
+ h.finalizeAllInputs();
783
+ } catch (p) {
784
+ if (!h.data.inputs.every(
785
+ (b) => b.finalScriptWitness || b.finalScriptSig
786
+ ))
787
+ throw new Error(
788
+ `PSBT finalization failed and wallet did not auto-finalize: ${p}`
789
+ );
740
790
  }
741
- const b = g.extractTransaction().toHex();
742
- return await ct(b, c);
791
+ const m = h.extractTransaction().toHex();
792
+ return await pt(m, u);
743
793
  }
744
794
  /**
745
795
  * Registers a peg-in on Ethereum by calling the BTCVaultsManager contract.
@@ -761,83 +811,87 @@ class Ct {
761
811
  async registerPeginOnChain(t) {
762
812
  const {
763
813
  depositorBtcPubkey: e,
764
- unsignedBtcTx: s,
765
- vaultProvider: a,
766
- onPopSigned: o,
767
- depositorPayoutBtcAddress: u,
768
- depositorLamportPkHash: i,
769
- preSignedBtcPopSignature: r
814
+ unsignedPrePeginTx: s,
815
+ depositorSignedPeginTx: o,
816
+ vaultProvider: r,
817
+ hashlock: c,
818
+ onPopSigned: i,
819
+ depositorPayoutBtcAddress: a,
820
+ depositorLamportPkHash: u,
821
+ preSignedBtcPopSignature: l
770
822
  } = t;
771
823
  if (!this.config.ethWallet.account)
772
824
  throw new Error("Ethereum wallet account not found");
773
- const c = this.config.ethWallet.account.address, l = await this.resolvePopSignature(
774
- c,
775
- r
825
+ const d = this.config.ethWallet.account.address, f = await this.resolvePopSignature(
826
+ d,
827
+ l
776
828
  );
777
- o && await o();
778
- const d = e.startsWith("0x") ? e : `0x${e}`, f = s.startsWith("0x") ? s : `0x${s}`, g = await this.resolvePayoutScriptPubKey(
779
- u
780
- ), b = R(f);
781
- if (await this.checkVaultExists(b))
829
+ i && await i();
830
+ const h = I(e), m = I(s), P = I(o), p = await this.resolvePayoutScriptPubKey(
831
+ a
832
+ ), y = X(P);
833
+ if (await this.checkVaultExists(y))
782
834
  throw new Error(
783
- `Vault already exists for this transaction (ID: ${b}). 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.`
835
+ `Vault already exists for this transaction (ID: ${y}). 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.`
784
836
  );
785
- const h = F({
837
+ const w = K({
786
838
  chain: this.config.ethChain,
787
- transport: M()
839
+ transport: N()
788
840
  });
789
- let y;
841
+ let T;
790
842
  try {
791
- y = await h.readContract({
843
+ T = await w.readContract({
792
844
  address: this.config.vaultContracts.btcVaultsManager,
793
- abi: B,
845
+ abi: $,
794
846
  functionName: "getPegInFee",
795
- args: [a]
847
+ args: [r]
796
848
  });
797
849
  } catch {
798
850
  throw new Error(
799
851
  "Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct."
800
852
  );
801
853
  }
802
- const m = Y({
803
- abi: B,
854
+ const A = ot({
855
+ abi: $,
804
856
  functionName: "submitPeginRequest",
805
857
  args: [
806
- c,
807
858
  d,
808
- l,
859
+ h,
809
860
  f,
810
- a,
811
- g,
812
- i
861
+ m,
862
+ P,
863
+ r,
864
+ c,
865
+ p,
866
+ u
813
867
  ]
814
868
  });
815
- let P;
869
+ let F;
816
870
  try {
817
- P = await h.estimateGas({
871
+ F = await w.estimateGas({
818
872
  to: this.config.vaultContracts.btcVaultsManager,
819
- data: m,
820
- value: y,
873
+ data: A,
874
+ value: T,
821
875
  account: this.config.ethWallet.account.address
822
876
  });
823
- } catch (w) {
824
- K(w);
877
+ } catch (v) {
878
+ D(v);
825
879
  }
826
880
  try {
827
881
  return {
828
882
  ethTxHash: await this.config.ethWallet.sendTransaction({
829
883
  to: this.config.vaultContracts.btcVaultsManager,
830
- data: m,
831
- value: y,
884
+ data: A,
885
+ value: T,
832
886
  account: this.config.ethWallet.account,
833
887
  chain: this.config.ethChain,
834
- gas: P
888
+ gas: F
835
889
  }),
836
- vaultId: b,
837
- btcPopSignature: l
890
+ vaultId: y,
891
+ btcPopSignature: f
838
892
  };
839
- } catch (w) {
840
- K(w);
893
+ } catch (v) {
894
+ D(v);
841
895
  }
842
896
  }
843
897
  /**
@@ -848,15 +902,15 @@ class Ct {
848
902
  */
849
903
  async checkVaultExists(t) {
850
904
  try {
851
- return (await F({
905
+ return (await K({
852
906
  chain: this.config.ethChain,
853
- transport: M()
907
+ transport: N()
854
908
  }).readContract({
855
909
  address: this.config.vaultContracts.btcVaultsManager,
856
- abi: B,
910
+ abi: $,
857
911
  functionName: "getBTCVault",
858
912
  args: [t]
859
- })).depositor !== J;
913
+ })).depositor !== it;
860
914
  } catch {
861
915
  return !1;
862
916
  }
@@ -874,19 +928,19 @@ class Ct {
874
928
  e = t;
875
929
  else {
876
930
  e = await this.config.btcWallet.getAddress();
877
- const a = await this.config.btcWallet.getPublicKeyHex();
878
- if (!j(
931
+ const o = await this.config.btcWallet.getPublicKeyHex();
932
+ if (!at(
879
933
  e,
880
- a,
934
+ o,
881
935
  this.config.btcNetwork
882
936
  ))
883
937
  throw new Error(
884
938
  "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)."
885
939
  );
886
940
  }
887
- const s = C(this.config.btcNetwork);
941
+ const s = U(this.config.btcNetwork);
888
942
  try {
889
- return `0x${$.address.toOutputScript(e, s).toString("hex")}`;
943
+ return `0x${L.address.toOutputScript(e, s).toString("hex")}`;
890
944
  } catch {
891
945
  throw new Error(
892
946
  `Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
@@ -902,11 +956,11 @@ class Ct {
902
956
  async resolvePopSignature(t, e) {
903
957
  if (e)
904
958
  return e;
905
- const s = this.config.vaultContracts.btcVaultsManager, a = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, o = await this.config.btcWallet.signMessage(
906
- a,
959
+ const s = this.config.vaultContracts.btcVaultsManager, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
960
+ o,
907
961
  "bip322-simple"
908
962
  );
909
- return o.startsWith("0x") ? o : `0x${p.from(o, "base64").toString("hex")}`;
963
+ return r.startsWith("0x") ? r : `0x${g.from(r, "base64").toString("hex")}`;
910
964
  }
911
965
  /**
912
966
  * Gets the configured Bitcoin network.
@@ -925,14 +979,14 @@ class Ct {
925
979
  return this.config.vaultContracts.btcVaultsManager;
926
980
  }
927
981
  }
928
- class Ht {
982
+ class Ot {
929
983
  /**
930
984
  * Creates a new PayoutManager instance.
931
985
  *
932
986
  * @param config - Manager configuration including wallet
933
987
  */
934
988
  constructor(t) {
935
- I(this, "config");
989
+ H(this, "config");
936
990
  this.config = t;
937
991
  }
938
992
  /**
@@ -958,10 +1012,10 @@ class Ht {
958
1012
  * @throws Error if wallet operations fail or signature extraction fails
959
1013
  */
960
1014
  async signPayoutTransaction(t) {
961
- const e = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = A(
1015
+ const e = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: s } = V(
962
1016
  e,
963
1017
  t.depositorBtcPubkey
964
- ), a = await O({
1018
+ ), o = await M({
965
1019
  payoutTxHex: t.payoutTxHex,
966
1020
  peginTxHex: t.peginTxHex,
967
1021
  assertTxHex: t.assertTxHex,
@@ -971,8 +1025,8 @@ class Ht {
971
1025
  universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
972
1026
  timelockPegin: t.timelockPegin,
973
1027
  network: this.config.network
974
- }), o = await this.config.btcWallet.signPsbt(
975
- a.psbtHex,
1028
+ }), r = await this.config.btcWallet.signPsbt(
1029
+ o.psbtHex,
976
1030
  {
977
1031
  autoFinalized: !1,
978
1032
  signInputs: [
@@ -985,7 +1039,7 @@ class Ht {
985
1039
  }
986
1040
  );
987
1041
  return {
988
- signature: W(o, s),
1042
+ signature: R(r, s),
989
1043
  depositorBtcPubkey: s
990
1044
  };
991
1045
  }
@@ -1019,25 +1073,25 @@ class Ht {
1019
1073
  throw new Error(
1020
1074
  "Wallet does not support batch signing (signPsbts method not available)"
1021
1075
  );
1022
- const e = await this.config.btcWallet.getPublicKeyHex(), s = [], a = [], o = [];
1023
- for (const r of t) {
1024
- const { depositorPubkey: c } = A(
1076
+ const e = await this.config.btcWallet.getPublicKeyHex(), s = [], o = [], r = [];
1077
+ for (const a of t) {
1078
+ const { depositorPubkey: u } = V(
1025
1079
  e,
1026
- r.depositorBtcPubkey
1080
+ a.depositorBtcPubkey
1027
1081
  );
1028
- o.push(c);
1029
- const l = await O({
1030
- payoutTxHex: r.payoutTxHex,
1031
- peginTxHex: r.peginTxHex,
1032
- assertTxHex: r.assertTxHex,
1033
- depositorBtcPubkey: c,
1034
- vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
1035
- vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
1036
- universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys,
1037
- timelockPegin: r.timelockPegin,
1082
+ r.push(u);
1083
+ const l = await M({
1084
+ payoutTxHex: a.payoutTxHex,
1085
+ peginTxHex: a.peginTxHex,
1086
+ assertTxHex: a.assertTxHex,
1087
+ depositorBtcPubkey: u,
1088
+ vaultProviderBtcPubkey: a.vaultProviderBtcPubkey,
1089
+ vaultKeeperBtcPubkeys: a.vaultKeeperBtcPubkeys,
1090
+ universalChallengerBtcPubkeys: a.universalChallengerBtcPubkeys,
1091
+ timelockPegin: a.timelockPegin,
1038
1092
  network: this.config.network
1039
1093
  });
1040
- s.push(l.psbtHex), a.push({
1094
+ s.push(l.psbtHex), o.push({
1041
1095
  autoFinalized: !1,
1042
1096
  signInputs: [
1043
1097
  {
@@ -1048,65 +1102,54 @@ class Ht {
1048
1102
  ]
1049
1103
  });
1050
1104
  }
1051
- const u = await this.config.btcWallet.signPsbts(
1105
+ const c = await this.config.btcWallet.signPsbts(
1052
1106
  s,
1053
- a
1107
+ o
1054
1108
  );
1055
- if (u.length !== t.length)
1109
+ if (c.length !== t.length)
1056
1110
  throw new Error(
1057
- `Expected ${t.length} signed PSBTs but received ${u.length}`
1111
+ `Expected ${t.length} signed PSBTs but received ${c.length}`
1058
1112
  );
1059
1113
  const i = [];
1060
- for (let r = 0; r < t.length; r++) {
1061
- const c = o[r], l = W(
1062
- u[r],
1063
- c
1114
+ for (let a = 0; a < t.length; a++) {
1115
+ const u = r[a], l = R(
1116
+ c[a],
1117
+ u
1064
1118
  );
1065
1119
  i.push({
1066
1120
  payoutSignature: l,
1067
- depositorBtcPubkey: c
1121
+ depositorBtcPubkey: u
1068
1122
  });
1069
1123
  }
1070
1124
  return i;
1071
1125
  }
1072
1126
  }
1073
1127
  export {
1074
- St as A,
1075
- N as B,
1128
+ B,
1076
1129
  x as C,
1077
- H as D,
1078
- K as E,
1079
- mt as F,
1080
- Q as L,
1081
- V as M,
1082
- Z as P,
1083
- G as T,
1084
- tt as W,
1130
+ dt as M,
1131
+ Ut as P,
1085
1132
  wt as a,
1086
- Pt as b,
1087
- R as c,
1088
- Tt as d,
1089
- v as e,
1090
- rt as f,
1091
- xt as g,
1092
- ot as h,
1093
- at as i,
1094
- Ct as j,
1095
- Ht as k,
1133
+ vt as b,
1134
+ X as c,
1135
+ kt as d,
1136
+ ut as e,
1137
+ lt as f,
1138
+ Tt as g,
1139
+ Ot as h,
1140
+ Ht as i,
1141
+ Et as j,
1142
+ St as k,
1096
1143
  It as l,
1097
- kt as m,
1098
- Et as n,
1099
- Bt as o,
1100
- st as p,
1101
- vt as q,
1102
- et as r,
1103
- nt as s,
1104
- ut as t,
1105
- lt as u,
1106
- it as v,
1107
- ct as w,
1108
- B as x,
1109
- U as y,
1110
- $t as z
1144
+ Bt as m,
1145
+ ht as n,
1146
+ gt as o,
1147
+ pt as p,
1148
+ $ as q,
1149
+ O as r,
1150
+ ct as s,
1151
+ $t as t,
1152
+ Ct as u,
1153
+ D as v
1111
1154
  };
1112
- //# sourceMappingURL=PayoutManager-rMj54HDh.js.map
1155
+ //# sourceMappingURL=PayoutManager-BK1jKgL5.js.map