@babylonlabs-io/ts-sdk 0.15.2 → 0.15.4-rc-0.16.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 (42) hide show
  1. package/dist/{challengeAssert-CenzzhZU.js → challengeAssert-C5DQSUnp.js} +249 -265
  2. package/dist/challengeAssert-C5DQSUnp.js.map +1 -0
  3. package/dist/challengeAssert-D7SqsNpQ.cjs +2 -0
  4. package/dist/challengeAssert-D7SqsNpQ.cjs.map +1 -0
  5. package/dist/{errors-C5aW6wrA.js → errors-BEUjAw2k.js} +278 -367
  6. package/dist/errors-BEUjAw2k.js.map +1 -0
  7. package/dist/errors-DnMc1lLU.cjs +2 -0
  8. package/dist/errors-DnMc1lLU.cjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +31 -33
  11. package/dist/tbv/core/index.cjs +1 -1
  12. package/dist/tbv/core/index.js +33 -35
  13. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  14. package/dist/tbv/core/primitives/index.cjs +1 -1
  15. package/dist/tbv/core/primitives/index.js +1 -1
  16. package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts +2 -13
  17. package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts.map +1 -1
  18. package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
  19. package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -1
  20. package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
  21. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  22. package/dist/tbv/core/primitives/scripts/payout.d.ts +7 -0
  23. package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -1
  24. package/dist/tbv/core/primitives/utils/bitcoin.d.ts +17 -0
  25. package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
  26. package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
  27. package/dist/tbv/core/utils/transaction/index.d.ts +0 -1
  28. package/dist/tbv/core/utils/transaction/index.d.ts.map +1 -1
  29. package/dist/tbv/index.cjs +1 -1
  30. package/dist/tbv/index.js +33 -35
  31. package/package.json +20 -20
  32. package/LICENSE +0 -169
  33. package/dist/challengeAssert-BpzES0KW.cjs +0 -2
  34. package/dist/challengeAssert-BpzES0KW.cjs.map +0 -1
  35. package/dist/challengeAssert-CenzzhZU.js.map +0 -1
  36. package/dist/errors-C5aW6wrA.js.map +0 -1
  37. package/dist/errors-DD3lnhb0.cjs +0 -2
  38. package/dist/errors-DD3lnhb0.cjs.map +0 -1
  39. package/dist/tbv/core/utils/transaction/__tests__/createSplitTransaction.test.d.ts +0 -5
  40. package/dist/tbv/core/utils/transaction/__tests__/createSplitTransaction.test.d.ts.map +0 -1
  41. package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts +0 -106
  42. package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts.map +0 -1
@@ -1,35 +1,36 @@
1
- import { createPrePeginTransaction as W, buildPeginTxFromPrePegin as K, getPrePeginHtlcConnectorInfo as O, tapInternalPubkey as b, initWasm as q, WasmPrePeginTx as N, createPayoutConnector as z, getPeginPayoutScript as M, getAssertNoPayoutScriptInfo as D, getChallengeAssertScriptInfo as X } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
- import * as U from "bitcoinjs-lib";
3
- import { payments as T, networks as I, initEccLib as A, Transaction as x, Psbt as v } from "bitcoinjs-lib";
4
- import { Buffer as a } from "buffer";
5
- import * as $ from "@bitcoin-js/tiny-secp256k1-asmjs";
1
+ import { createPrePeginTransaction as W, buildPeginTxFromPrePegin as F, getPrePeginHtlcConnectorInfo as _, tapInternalPubkey as m, initWasm as N, WasmPrePeginTx as q, createPayoutConnector as z, getPeginPayoutScriptInfo as M, getAssertNoPayoutScriptInfo as D, getChallengeAssertScriptInfo as X } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
+ import * as B from "bitcoinjs-lib";
3
+ import { payments as R, networks as I, initEccLib as G, Transaction as y, Psbt as w } from "bitcoinjs-lib";
4
+ import { Buffer as l } from "buffer";
5
+ import * as Q from "@bitcoin-js/tiny-secp256k1-asmjs";
6
+ const E = 192;
6
7
  function g(t) {
7
8
  return t.startsWith("0x") ? t.slice(2) : t;
8
9
  }
9
- function pt(t) {
10
+ function lt(t) {
10
11
  return t.startsWith("0x") ? t : `0x${t}`;
11
12
  }
12
- function h(t) {
13
+ function d(t) {
13
14
  const e = g(t);
14
- if (!B(e))
15
+ if (!A(e))
15
16
  throw new Error(`Invalid hex string: ${t}`);
16
17
  const n = new Uint8Array(e.length / 2);
17
18
  for (let r = 0; r < e.length; r += 2)
18
19
  n[r / 2] = parseInt(e.slice(r, r + 2), 16);
19
20
  return n;
20
21
  }
21
- function w(t) {
22
+ function v(t) {
22
23
  return Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
23
24
  }
24
- function G(t) {
25
+ function Y(t) {
25
26
  return t.length === 32 ? t : t.slice(1, 33);
26
27
  }
27
- function B(t) {
28
+ function A(t) {
28
29
  return /^[0-9a-fA-F]*$/.test(t) && t.length % 2 === 0;
29
30
  }
30
31
  function C(t) {
31
32
  const e = g(t);
32
- if (!B(e))
33
+ if (!A(e))
33
34
  throw new Error(`Invalid hex characters in public key: ${t}`);
34
35
  if (e.length === 64)
35
36
  return e;
@@ -37,14 +38,14 @@ function C(t) {
37
38
  throw new Error(
38
39
  `Invalid public key length: ${e.length} (expected 64, 66, or 130 hex chars)`
39
40
  );
40
- const n = h(e);
41
- return w(G(n));
41
+ const n = d(e);
42
+ return v(Y(n));
42
43
  }
43
- function ft(t) {
44
+ function pt(t) {
44
45
  const e = g(t);
45
- return B(e);
46
+ return A(e);
46
47
  }
47
- function dt(t, e) {
48
+ function ft(t, e) {
48
49
  const n = C(t), r = e ?? n;
49
50
  if (n.toLowerCase() !== r.toLowerCase())
50
51
  throw new Error(
@@ -52,9 +53,9 @@ function dt(t, e) {
52
53
  );
53
54
  return { walletPubkeyRaw: t, walletPubkeyXOnly: n, depositorPubkey: r };
54
55
  }
55
- let _ = !1;
56
- function Q() {
57
- _ || (A($), _ = !0);
56
+ let L = !1;
57
+ function O() {
58
+ L || (G(Q), L = !0);
58
59
  }
59
60
  function V(t) {
60
61
  switch (t) {
@@ -69,24 +70,24 @@ function V(t) {
69
70
  throw new Error(`Unknown network: ${t}`);
70
71
  }
71
72
  }
72
- function Y(t, e) {
73
- Q();
74
- const n = h(C(t)), { address: r } = T.p2tr({
75
- internalPubkey: a.from(n),
73
+ function Z(t, e) {
74
+ O();
75
+ const n = d(C(t)), { address: r } = R.p2tr({
76
+ internalPubkey: l.from(n),
76
77
  network: V(e)
77
78
  });
78
79
  if (!r)
79
80
  throw new Error("Failed to derive taproot address from public key");
80
81
  return r;
81
82
  }
82
- function Z(t, e) {
83
+ function j(t, e) {
83
84
  const n = g(t);
84
85
  if (n.length !== 66)
85
86
  throw new Error(
86
87
  `Native SegWit requires a compressed public key (66 hex chars), got ${n.length}`
87
88
  );
88
- const { address: r } = T.p2wpkh({
89
- pubkey: a.from(h(n)),
89
+ const { address: r } = R.p2wpkh({
90
+ pubkey: l.from(d(n)),
90
91
  network: V(e)
91
92
  });
92
93
  if (!r)
@@ -95,10 +96,10 @@ function Z(t, e) {
95
96
  );
96
97
  return r;
97
98
  }
98
- function ht(t, e, n) {
99
+ function dt(t, e, n) {
99
100
  const r = g(e);
100
101
  try {
101
- if (t === Y(r, n))
102
+ if (t === Z(r, n))
102
103
  return !0;
103
104
  } catch {
104
105
  }
@@ -106,7 +107,7 @@ function ht(t, e, n) {
106
107
  r.length === 66 ? o.push(r) : r.length === 64 && o.push(`02${r}`, `03${r}`);
107
108
  for (const s of o)
108
109
  try {
109
- if (t === Z(s, n))
110
+ if (t === j(s, n))
110
111
  return !0;
111
112
  } catch {
112
113
  }
@@ -115,23 +116,23 @@ function ht(t, e, n) {
115
116
  function H(t) {
116
117
  return C(t).toLowerCase();
117
118
  }
118
- function gt(t, e, n) {
119
+ function ht(t, e, n) {
119
120
  const r = /* @__PURE__ */ new Set();
120
121
  r.add(H(t));
121
122
  for (const o of e)
122
123
  r.add(H(o));
123
124
  return r.delete(H(n)), r.size;
124
125
  }
125
- const Pt = 58, yt = 43, xt = 11, j = 546, J = BigInt(j), tt = 30, et = 2, kt = 1.1;
126
- function wt(t) {
127
- return t <= et ? tt : 0;
126
+ const gt = 58, Pt = 43, xt = 11, J = 546, tt = BigInt(J), et = 30, nt = 2, yt = 1.1;
127
+ function kt(t) {
128
+ return t <= nt ? et : 0;
128
129
  }
129
- const nt = 1;
130
+ const rt = 1;
130
131
  function vt(t) {
131
- return t + nt;
132
+ return t + rt;
132
133
  }
133
- const bt = 5;
134
- function F(t) {
134
+ const wt = 5;
135
+ function K(t) {
135
136
  const n = t.substring(8, 12) === "0001" ? 12 : 8, r = parseInt(
136
137
  t.substring(n, n + 2),
137
138
  16
@@ -143,33 +144,34 @@ function F(t) {
143
144
  throw new Error(`Expected 0 inputs from WASM, got ${r}`);
144
145
  if (o === 0)
145
146
  throw new Error("Expected at least 1 output from WASM, got 0");
146
- const s = a.from(t.substring(0, 8), "hex").readUInt32LE(0), c = a.from(
147
+ const s = l.from(t.substring(0, 8), "hex").readUInt32LE(0), c = l.from(
147
148
  t.substring(t.length - 8),
148
149
  "hex"
149
- ).readUInt32LE(0), i = [];
150
- let u = n + 4;
150
+ ).readUInt32LE(0), u = [];
151
+ let i = n + 4;
151
152
  for (let p = 0; p < o; p++) {
152
- const l = t.substring(u, u + 16), f = Number(a.from(l, "hex").readBigUInt64LE(0));
153
- u += 16;
154
- const d = parseInt(t.substring(u, u + 2), 16);
155
- u += 2;
156
- const P = t.substring(u, u + d * 2), y = a.from(P, "hex");
157
- u += d * 2, i.push({ value: f, script: y });
153
+ const a = t.substring(i, i + 16), f = Number(l.from(a, "hex").readBigUInt64LE(0));
154
+ i += 16;
155
+ const h = parseInt(t.substring(i, i + 2), 16);
156
+ i += 2;
157
+ const P = t.substring(i, i + h * 2), x = l.from(P, "hex");
158
+ i += h * 2, u.push({ value: f, script: x });
158
159
  }
159
- return { version: s, locktime: c, outputs: i };
160
- }
161
- function mt(t) {
162
- const { unfundedTxHex: e, selectedUTXOs: n, changeAddress: r, changeAmount: o, network: s } = t, { version: c, locktime: i, outputs: u } = F(e), p = new U.Transaction();
163
- p.version = c, p.locktime = i;
164
- for (const l of n) {
165
- const f = a.from(l.txid, "hex").reverse();
166
- p.addInput(f, l.vout);
160
+ return { version: s, locktime: c, outputs: u };
161
+ }
162
+ function bt(t) {
163
+ O();
164
+ const { unfundedTxHex: e, selectedUTXOs: n, changeAddress: r, changeAmount: o, network: s } = t, { version: c, locktime: u, outputs: i } = K(e), p = new B.Transaction();
165
+ p.version = c, p.locktime = u;
166
+ for (const a of n) {
167
+ const f = l.from(a.txid, "hex").reverse();
168
+ p.addInput(f, a.vout);
167
169
  }
168
- for (const l of u)
169
- p.addOutput(l.script, l.value);
170
- if (o > J) {
171
- const l = U.address.toOutputScript(r, s);
172
- p.addOutput(l, Number(o));
170
+ for (const a of i)
171
+ p.addOutput(a.script, a.value);
172
+ if (o > tt) {
173
+ const a = B.address.toOutputScript(r, s);
174
+ p.addOutput(a, Number(o));
173
175
  }
174
176
  return p.toHex();
175
177
  }
@@ -187,7 +189,7 @@ async function St(t) {
187
189
  councilQuorum: t.councilQuorum,
188
190
  councilSize: t.councilSize,
189
191
  network: t.network
190
- }), r = F(e.txHex).outputs.reduce(
192
+ }), r = K(e.txHex).outputs.reduce(
191
193
  (o, s) => o + BigInt(s.value),
192
194
  0n
193
195
  );
@@ -201,8 +203,8 @@ async function St(t) {
201
203
  depositorClaimValue: e.depositorClaimValue
202
204
  };
203
205
  }
204
- async function Et(t) {
205
- const e = await K(
206
+ async function mt(t) {
207
+ const e = await F(
206
208
  {
207
209
  depositorPubkey: t.prePeginParams.depositorPubkey,
208
210
  vaultProviderPubkey: t.prePeginParams.vaultProviderPubkey,
@@ -228,8 +230,8 @@ async function Et(t) {
228
230
  vaultValue: e.vaultValue
229
231
  };
230
232
  }
231
- async function Tt(t) {
232
- const e = g(t.peginTxHex), n = g(t.fundedPrePeginTxHex), r = await O({
233
+ async function Et(t) {
234
+ const e = g(t.peginTxHex), n = g(t.fundedPrePeginTxHex), r = await _({
233
235
  depositorPubkey: t.depositorPubkey,
234
236
  vaultProviderPubkey: t.vaultProviderPubkey,
235
237
  vaultKeeperPubkeys: t.vaultKeeperPubkeys,
@@ -237,25 +239,25 @@ async function Tt(t) {
237
239
  hashlock: t.hashlock,
238
240
  timelockRefund: t.timelockRefund,
239
241
  network: t.network
240
- }), o = x.fromHex(e), s = x.fromHex(n);
242
+ }), o = y.fromHex(e), s = y.fromHex(n);
241
243
  if (o.ins.length !== 1)
242
244
  throw new Error(
243
245
  `PegIn transaction must have exactly 1 input, got ${o.ins.length}`
244
246
  );
245
- const c = o.ins[0], i = s.getId(), u = w(
247
+ const c = o.ins[0], u = s.getId(), i = v(
246
248
  new Uint8Array(c.hash).slice().reverse()
247
249
  );
248
- if (u !== i)
250
+ if (i !== u)
249
251
  throw new Error(
250
- `PegIn input does not reference the Pre-PegIn transaction. Expected ${i}, got ${u}`
252
+ `PegIn input does not reference the Pre-PegIn transaction. Expected ${u}, got ${i}`
251
253
  );
252
254
  const p = s.outs[c.index];
253
255
  if (!p)
254
256
  throw new Error(
255
257
  `Pre-PegIn output ${c.index} not found (Pre-PegIn has ${s.outs.length} outputs)`
256
258
  );
257
- const l = h(r.hashlockScript), f = h(r.hashlockControlBlock), d = new v();
258
- d.setVersion(o.version), d.setLocktime(o.locktime), d.addInput({
259
+ const a = d(r.hashlockScript), f = d(r.hashlockControlBlock), h = new w();
260
+ h.setVersion(o.version), h.setLocktime(o.locktime), h.addInput({
259
261
  hash: c.hash,
260
262
  index: c.index,
261
263
  sequence: c.sequence,
@@ -265,32 +267,32 @@ async function Tt(t) {
265
267
  },
266
268
  tapLeafScript: [
267
269
  {
268
- leafVersion: 192,
269
- script: a.from(l),
270
- controlBlock: a.from(f)
270
+ leafVersion: E,
271
+ script: l.from(a),
272
+ controlBlock: l.from(f)
271
273
  }
272
274
  ],
273
- tapInternalKey: a.from(b)
275
+ tapInternalKey: l.from(m)
274
276
  // sighashType omitted — defaults to SIGHASH_DEFAULT (0x00) for Taproot
275
277
  });
276
278
  for (const P of o.outs)
277
- d.addOutput({
279
+ h.addOutput({
278
280
  script: P.script,
279
281
  value: P.value
280
282
  });
281
- return { psbtHex: d.toHex() };
283
+ return { psbtHex: h.toHex() };
282
284
  }
283
- function It(t, e) {
284
- const r = v.fromHex(t).data.inputs[0];
285
+ function Tt(t, e) {
286
+ const r = w.fromHex(t).data.inputs[0];
285
287
  if (!r)
286
288
  throw new Error("PegIn PSBT has no inputs");
287
289
  if (r.tapScriptSig && r.tapScriptSig.length > 0) {
288
- const o = a.from(
289
- h(e)
290
+ const o = l.from(
291
+ d(e)
290
292
  );
291
293
  for (const s of r.tapScriptSig)
292
294
  if (s.pubkey.equals(o))
293
- return rt(s.signature);
295
+ return ot(s.signature);
294
296
  throw new Error(
295
297
  `No PegIn input signature found for depositor pubkey: ${e}`
296
298
  );
@@ -301,8 +303,8 @@ function It(t, e) {
301
303
  "No tapScriptSig or finalScriptWitness found in signed PegIn input PSBT"
302
304
  );
303
305
  }
304
- function Ht(t) {
305
- const e = v.fromHex(t);
306
+ function It(t) {
307
+ const e = w.fromHex(t);
306
308
  try {
307
309
  e.finalizeAllInputs();
308
310
  } catch (n) {
@@ -315,16 +317,16 @@ function Ht(t) {
315
317
  }
316
318
  return e.extractTransaction().toHex();
317
319
  }
318
- function rt(t) {
320
+ function ot(t) {
319
321
  if (t.length === 64)
320
- return w(new Uint8Array(t));
322
+ return v(new Uint8Array(t));
321
323
  if (t.length === 65)
322
- return w(new Uint8Array(t.subarray(0, 64)));
324
+ return v(new Uint8Array(t.subarray(0, 64)));
323
325
  throw new Error(`Unexpected PegIn input signature length: ${t.length}`);
324
326
  }
325
- async function At(t) {
326
- await q();
327
- const { prePeginParams: e, fundedPrePeginTxHex: n, htlcVout: r, refundFee: o, hashlock: s } = t, c = new N(
327
+ async function Ht(t) {
328
+ await N();
329
+ const { prePeginParams: e, fundedPrePeginTxHex: n, htlcVout: r, refundFee: o, hashlock: s } = t, c = new q(
328
330
  e.depositorPubkey,
329
331
  e.vaultProviderPubkey,
330
332
  e.vaultKeeperPubkeys,
@@ -338,10 +340,10 @@ async function At(t) {
338
340
  e.councilSize,
339
341
  e.network
340
342
  );
341
- let i = null;
343
+ let u = null;
342
344
  try {
343
- i = c.fromFundedTransaction(n);
344
- const u = i.buildRefundTx(o, r), p = await O({
345
+ u = c.fromFundedTransaction(n);
346
+ const i = u.buildRefundTx(o, r), p = await _({
345
347
  depositorPubkey: e.depositorPubkey,
346
348
  vaultProviderPubkey: e.vaultProviderPubkey,
347
349
  vaultKeeperPubkeys: e.vaultKeeperPubkeys,
@@ -349,46 +351,46 @@ async function At(t) {
349
351
  hashlock: s,
350
352
  timelockRefund: e.timelockRefund,
351
353
  network: e.network
352
- }), l = n.startsWith("0x") ? n.slice(2) : n, f = x.fromHex(l), d = f.outs[r];
353
- if (!d)
354
+ }), a = n.startsWith("0x") ? n.slice(2) : n, f = y.fromHex(a), h = f.outs[r];
355
+ if (!h)
354
356
  throw new Error(
355
357
  `HTLC output at vout ${r} not found in funded Pre-PegIn tx (tx has ${f.outs.length} outputs)`
356
358
  );
357
- const P = x.fromHex(u);
359
+ const P = y.fromHex(i);
358
360
  if (P.ins.length !== 1)
359
361
  throw new Error(
360
362
  `Refund transaction must have exactly 1 input, got ${P.ins.length}`
361
363
  );
362
- const y = P.ins[0], m = f.getId(), E = w(
363
- new Uint8Array(y.hash).slice().reverse()
364
+ const x = P.ins[0], b = f.getId(), T = v(
365
+ new Uint8Array(x.hash).slice().reverse()
364
366
  );
365
- if (E !== m)
367
+ if (T !== b)
366
368
  throw new Error(
367
- `Refund input does not reference the Pre-PegIn transaction. Expected ${m}, got ${E}`
369
+ `Refund input does not reference the Pre-PegIn transaction. Expected ${b}, got ${T}`
368
370
  );
369
- if (y.index !== r)
371
+ if (x.index !== r)
370
372
  throw new Error(
371
- `Refund input index ${y.index} does not match expected htlcVout ${r}`
373
+ `Refund input index ${x.index} does not match expected htlcVout ${r}`
372
374
  );
373
- const k = new v();
375
+ const k = new w();
374
376
  k.setVersion(P.version), k.setLocktime(P.locktime), k.addInput({
375
- hash: y.hash,
376
- index: y.index,
377
- sequence: y.sequence,
377
+ hash: x.hash,
378
+ index: x.index,
379
+ sequence: x.sequence,
378
380
  witnessUtxo: {
379
- script: d.script,
380
- value: d.value
381
+ script: h.script,
382
+ value: h.value
381
383
  },
382
384
  tapLeafScript: [
383
385
  {
384
- leafVersion: 192,
385
- script: a.from(h(p.refundScript)),
386
- controlBlock: a.from(
387
- h(p.refundControlBlock)
386
+ leafVersion: E,
387
+ script: l.from(d(p.refundScript)),
388
+ controlBlock: l.from(
389
+ d(p.refundControlBlock)
388
390
  )
389
391
  }
390
392
  ],
391
- tapInternalKey: a.from(b)
393
+ tapInternalKey: l.from(m)
392
394
  });
393
395
  for (const S of P.outs)
394
396
  k.addOutput({
@@ -397,10 +399,10 @@ async function At(t) {
397
399
  });
398
400
  return { psbtHex: k.toHex() };
399
401
  } finally {
400
- i == null || i.free(), c.free();
402
+ u == null || u.free(), c.free();
401
403
  }
402
404
  }
403
- async function ot(t) {
405
+ async function st(t) {
404
406
  const e = await z(
405
407
  {
406
408
  depositor: t.depositor,
@@ -415,48 +417,48 @@ async function ot(t) {
415
417
  payoutScript: e.payoutScript,
416
418
  taprootScriptHash: e.taprootScriptHash,
417
419
  scriptPubKey: e.scriptPubKey,
418
- address: e.address
420
+ address: e.address,
421
+ payoutControlBlock: e.payoutControlBlock
419
422
  };
420
423
  }
421
- A($);
422
- async function $t(t) {
423
- const e = g(t.payoutTxHex), n = g(t.peginTxHex), r = g(t.assertTxHex), o = await ot({
424
+ async function At(t) {
425
+ const e = g(t.payoutTxHex), n = g(t.peginTxHex), r = g(t.assertTxHex), o = await st({
424
426
  depositor: t.depositorBtcPubkey,
425
427
  vaultProvider: t.vaultProviderBtcPubkey,
426
428
  vaultKeepers: t.vaultKeeperBtcPubkeys,
427
429
  universalChallengers: t.universalChallengerBtcPubkeys,
428
430
  timelockPegin: t.timelockPegin,
429
431
  network: t.network
430
- }), s = h(o.payoutScript), c = it(b, s), i = x.fromHex(e), u = x.fromHex(n), p = x.fromHex(r), l = new v();
431
- if (l.setVersion(i.version), l.setLocktime(i.locktime), i.ins.length !== 2)
432
+ }), s = d(o.payoutScript), c = d(o.payoutControlBlock), u = y.fromHex(e), i = y.fromHex(n), p = y.fromHex(r), a = new w();
433
+ if (a.setVersion(u.version), a.setLocktime(u.locktime), u.ins.length !== 2)
432
434
  throw new Error(
433
- `Payout transaction must have exactly 2 inputs, got ${i.ins.length}`
435
+ `Payout transaction must have exactly 2 inputs, got ${u.ins.length}`
434
436
  );
435
- const f = i.ins[0], d = i.ins[1], P = w(
437
+ const f = u.ins[0], h = u.ins[1], P = v(
436
438
  new Uint8Array(f.hash).slice().reverse()
437
- ), y = u.getId();
438
- if (P !== y)
439
+ ), x = i.getId();
440
+ if (P !== x)
439
441
  throw new Error(
440
- `Input 0 does not reference pegin transaction. Expected ${y}, got ${P}`
442
+ `Input 0 does not reference pegin transaction. Expected ${x}, got ${P}`
441
443
  );
442
- const m = w(
443
- new Uint8Array(d.hash).slice().reverse()
444
- ), E = p.getId();
445
- if (m !== E)
444
+ const b = v(
445
+ new Uint8Array(h.hash).slice().reverse()
446
+ ), T = p.getId();
447
+ if (b !== T)
446
448
  throw new Error(
447
- `Input 1 does not reference assert transaction. Expected ${E}, got ${m}`
449
+ `Input 1 does not reference assert transaction. Expected ${T}, got ${b}`
448
450
  );
449
- const k = u.outs[f.index];
451
+ const k = i.outs[f.index];
450
452
  if (!k)
451
453
  throw new Error(
452
454
  `Previous output not found for input 0 (txid: ${P}, index: ${f.index})`
453
455
  );
454
- const S = p.outs[d.index];
456
+ const S = p.outs[h.index];
455
457
  if (!S)
456
458
  throw new Error(
457
- `Previous output not found for input 1 (txid: ${m}, index: ${d.index})`
459
+ `Previous output not found for input 1 (txid: ${b}, index: ${h.index})`
458
460
  );
459
- l.addInput({
461
+ a.addInput({
460
462
  hash: f.hash,
461
463
  index: f.index,
462
464
  sequence: f.sequence,
@@ -466,73 +468,73 @@ async function $t(t) {
466
468
  },
467
469
  tapLeafScript: [
468
470
  {
469
- leafVersion: 192,
470
- script: a.from(s),
471
- controlBlock: a.from(c)
471
+ leafVersion: E,
472
+ script: l.from(s),
473
+ controlBlock: l.from(c)
472
474
  }
473
475
  ],
474
- tapInternalKey: a.from(b)
476
+ tapInternalKey: l.from(m)
475
477
  // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
476
- }), l.addInput({
477
- hash: d.hash,
478
- index: d.index,
479
- sequence: d.sequence,
478
+ }), a.addInput({
479
+ hash: h.hash,
480
+ index: h.index,
481
+ sequence: h.sequence,
480
482
  witnessUtxo: {
481
483
  script: S.script,
482
484
  value: S.value
483
485
  }
484
486
  // No tapLeafScript - depositor doesn't sign this input
485
487
  });
486
- for (const L of i.outs)
487
- l.addOutput({
488
- script: L.script,
489
- value: L.value
488
+ for (const $ of u.outs)
489
+ a.addOutput({
490
+ script: $.script,
491
+ value: $.value
490
492
  });
491
493
  return {
492
- psbtHex: l.toHex()
494
+ psbtHex: a.toHex()
493
495
  };
494
496
  }
495
- function Bt(t, e, n = 0) {
496
- const r = v.fromHex(t);
497
+ function Ct(t, e, n = 0) {
498
+ const r = w.fromHex(t);
497
499
  if (n >= r.data.inputs.length)
498
500
  throw new Error(
499
501
  `Input index ${n} out of range (${r.data.inputs.length} inputs)`
500
502
  );
501
503
  const o = r.data.inputs[n];
502
504
  if (o.tapScriptSig && o.tapScriptSig.length > 0) {
503
- const s = h(e);
505
+ const s = d(e);
504
506
  for (const c of o.tapScriptSig)
505
- if (c.pubkey.equals(a.from(s)))
506
- return R(c.signature, n);
507
+ if (c.pubkey.equals(l.from(s)))
508
+ return U(c.signature, n);
507
509
  throw new Error(
508
510
  `No signature found for depositor pubkey: ${e} at input ${n}`
509
511
  );
510
512
  }
511
513
  if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
512
- const s = st(o.finalScriptWitness);
514
+ const s = it(o.finalScriptWitness);
513
515
  if (s.length >= 1)
514
- return R(s[0], n);
516
+ return U(s[0], n);
515
517
  }
516
518
  throw new Error(
517
519
  `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
518
520
  );
519
521
  }
520
- function R(t, e) {
522
+ function U(t, e) {
521
523
  if (t.length === 64)
522
- return w(new Uint8Array(t));
524
+ return v(new Uint8Array(t));
523
525
  if (t.length === 65) {
524
526
  const n = t[64];
525
- if (n !== x.SIGHASH_ALL)
527
+ if (n !== y.SIGHASH_ALL)
526
528
  throw new Error(
527
529
  `Unexpected sighash type 0x${n.toString(16).padStart(2, "0")} at input ${e}. Expected SIGHASH_ALL (0x01).`
528
530
  );
529
- return w(new Uint8Array(t.subarray(0, 64)));
531
+ return v(new Uint8Array(t.subarray(0, 64)));
530
532
  }
531
533
  throw new Error(
532
534
  `Unexpected signature length at input ${e}: ${t.length}`
533
535
  );
534
536
  }
535
- function st(t) {
537
+ function it(t) {
536
538
  const e = [];
537
539
  let n = 0;
538
540
  const r = () => {
@@ -554,123 +556,104 @@ function st(t) {
554
556
  }
555
557
  return e;
556
558
  }
557
- function it(t, e) {
558
- const n = { output: a.from(e) }, o = T.p2tr({
559
- internalPubkey: a.from(t),
560
- scriptTree: n
561
- }).pubkey;
562
- if (!o)
563
- throw new Error("Failed to compute output key");
564
- const s = 192, c = o[0] === 3 ? 1 : 0, i = s | c, u = new Uint8Array(1 + t.length);
565
- return u[0] = i, u.set(t, 1), u;
566
- }
567
- A($);
568
- async function Ct(t) {
569
- const e = g(t.payoutTxHex), n = x.fromHex(e), r = await M(t.connectorParams), o = h(r), s = ut(b, o), c = new v();
570
- c.setVersion(n.version), c.setLocktime(n.locktime);
559
+ async function $t(t) {
560
+ const e = g(t.payoutTxHex), n = y.fromHex(e), { payoutScript: r, payoutControlBlock: o } = await M(
561
+ t.connectorParams
562
+ ), s = d(r), c = d(o), u = new w();
563
+ u.setVersion(n.version), u.setLocktime(n.locktime);
571
564
  for (let i = 0; i < n.ins.length; i++) {
572
- const u = n.ins[i], p = t.prevouts[i];
573
- if (!p)
565
+ const p = n.ins[i], a = t.prevouts[i];
566
+ if (!a)
574
567
  throw new Error(`Missing prevout data for input ${i}`);
575
- const l = {
576
- hash: u.hash,
577
- index: u.index,
578
- sequence: u.sequence,
568
+ const f = {
569
+ hash: p.hash,
570
+ index: p.index,
571
+ sequence: p.sequence,
579
572
  witnessUtxo: {
580
- script: a.from(h(g(p.script_pubkey))),
581
- value: p.value
573
+ script: l.from(d(g(a.script_pubkey))),
574
+ value: a.value
582
575
  }
583
576
  };
584
- i === 0 && (l.tapLeafScript = [
577
+ i === 0 && (f.tapLeafScript = [
585
578
  {
586
- leafVersion: 192,
587
- script: a.from(o),
588
- controlBlock: a.from(s)
579
+ leafVersion: E,
580
+ script: l.from(s),
581
+ controlBlock: l.from(c)
589
582
  }
590
- ], l.tapInternalKey = a.from(b)), c.addInput(l);
583
+ ], f.tapInternalKey = l.from(m)), u.addInput(f);
591
584
  }
592
585
  for (const i of n.outs)
593
- c.addOutput({
586
+ u.addOutput({
594
587
  script: i.script,
595
588
  value: i.value
596
589
  });
597
- return c.toHex();
598
- }
599
- function ut(t, e) {
600
- const n = { output: a.from(e) }, o = T.p2tr({
601
- internalPubkey: a.from(t),
602
- scriptTree: n
603
- }).pubkey;
604
- if (!o)
605
- throw new Error("Failed to compute output key");
606
- const s = 192, c = o[0] === 3 ? 1 : 0, i = s | c, u = new Uint8Array(1 + t.length);
607
- return u[0] = i, u.set(t, 1), u;
590
+ return u.toHex();
608
591
  }
609
- async function Lt(t) {
610
- const e = g(t.noPayoutTxHex), n = x.fromHex(e), { noPayoutScript: r, noPayoutControlBlock: o } = await D(
592
+ async function Bt(t) {
593
+ const e = g(t.noPayoutTxHex), n = y.fromHex(e), { noPayoutScript: r, noPayoutControlBlock: o } = await D(
611
594
  t.connectorParams,
612
595
  t.challengerPubkey
613
- ), s = h(r), c = h(o), i = new v();
614
- i.setVersion(n.version), i.setLocktime(n.locktime);
615
- for (let u = 0; u < n.ins.length; u++) {
616
- const p = n.ins[u], l = t.prevouts[u];
617
- if (!l)
618
- throw new Error(`Missing prevout data for input ${u}`);
596
+ ), s = d(r), c = d(o), u = new w();
597
+ u.setVersion(n.version), u.setLocktime(n.locktime);
598
+ for (let i = 0; i < n.ins.length; i++) {
599
+ const p = n.ins[i], a = t.prevouts[i];
600
+ if (!a)
601
+ throw new Error(`Missing prevout data for input ${i}`);
619
602
  const f = {
620
603
  hash: p.hash,
621
604
  index: p.index,
622
605
  sequence: p.sequence,
623
606
  witnessUtxo: {
624
- script: a.from(h(g(l.script_pubkey))),
625
- value: l.value
607
+ script: l.from(d(g(a.script_pubkey))),
608
+ value: a.value
626
609
  }
627
610
  };
628
- u === 0 && (f.tapLeafScript = [
611
+ i === 0 && (f.tapLeafScript = [
629
612
  {
630
- leafVersion: 192,
631
- script: a.from(s),
632
- controlBlock: a.from(c)
613
+ leafVersion: E,
614
+ script: l.from(s),
615
+ controlBlock: l.from(c)
633
616
  }
634
- ], f.tapInternalKey = a.from(b)), i.addInput(f);
617
+ ], f.tapInternalKey = l.from(m)), u.addInput(f);
635
618
  }
636
- for (const u of n.outs)
637
- i.addOutput({
638
- script: u.script,
639
- value: u.value
619
+ for (const i of n.outs)
620
+ u.addOutput({
621
+ script: i.script,
622
+ value: i.value
640
623
  });
641
- return i.toHex();
624
+ return u.toHex();
642
625
  }
643
- async function Ut(t) {
644
- const e = g(t.challengeAssertTxHex), n = x.fromHex(e);
626
+ async function Lt(t) {
627
+ const e = g(t.challengeAssertTxHex), n = y.fromHex(e);
645
628
  if (t.connectorParamsPerInput.length !== n.ins.length)
646
629
  throw new Error(
647
630
  `Expected ${n.ins.length} connector params, got ${t.connectorParamsPerInput.length}`
648
631
  );
649
632
  const r = await Promise.all(
650
633
  t.connectorParamsPerInput.map((s) => X(s))
651
- ), o = new v();
634
+ ), o = new w();
652
635
  o.setVersion(n.version), o.setLocktime(n.locktime);
653
636
  for (let s = 0; s < n.ins.length; s++) {
654
- const c = n.ins[s], i = t.prevouts[s];
655
- if (!i)
637
+ const c = n.ins[s], u = t.prevouts[s];
638
+ if (!u)
656
639
  throw new Error(`Missing prevout data for input ${s}`);
657
- const { script: u, controlBlock: p } = r[s], l = h(u), f = h(p);
640
+ const { script: i, controlBlock: p } = r[s], a = d(i), f = d(p);
658
641
  o.addInput({
659
642
  hash: c.hash,
660
643
  index: c.index,
661
644
  sequence: c.sequence,
662
645
  witnessUtxo: {
663
- script: a.from(h(g(i.script_pubkey))),
664
- value: i.value
646
+ script: l.from(d(g(u.script_pubkey))),
647
+ value: u.value
665
648
  },
666
649
  tapLeafScript: [
667
650
  {
668
- leafVersion: 192,
669
- script: a.from(l),
670
- controlBlock: a.from(f)
651
+ leafVersion: E,
652
+ script: l.from(a),
653
+ controlBlock: l.from(f)
671
654
  }
672
655
  ],
673
- tapInternalKey: a.from(b)
656
+ tapInternalKey: l.from(m)
674
657
  });
675
658
  }
676
659
  for (const s of n.outs)
@@ -682,43 +665,44 @@ async function Ut(t) {
682
665
  }
683
666
  export {
684
667
  vt as A,
685
- j as B,
686
- F as C,
687
- J as D,
688
- mt as E,
689
- kt as F,
668
+ J as B,
669
+ K as C,
670
+ tt as D,
671
+ bt as E,
672
+ yt as F,
690
673
  V as G,
691
- tt as L,
692
- yt as M,
693
- Pt as P,
694
- bt as S,
674
+ O as H,
675
+ et as L,
676
+ Pt as M,
677
+ gt as P,
678
+ wt as S,
695
679
  xt as T,
696
- et as W,
697
- Et as a,
680
+ nt as W,
681
+ mt as a,
698
682
  St as b,
699
- gt as c,
700
- Tt as d,
701
- It as e,
702
- Ht as f,
703
- At as g,
704
- $t as h,
705
- Bt as i,
706
- Ct as j,
707
- Lt as k,
708
- Ut as l,
709
- ot as m,
710
- Z as n,
711
- Y as o,
712
- h as p,
713
- ht as q,
714
- ft as r,
715
- pt as s,
683
+ ht as c,
684
+ Et as d,
685
+ Tt as e,
686
+ It as f,
687
+ Ht as g,
688
+ At as h,
689
+ Ct as i,
690
+ $t as j,
691
+ Bt as k,
692
+ Lt as l,
693
+ st as m,
694
+ j as n,
695
+ Z as o,
696
+ d as p,
697
+ dt as q,
698
+ pt as r,
699
+ lt as s,
716
700
  C as t,
717
701
  g as u,
718
- G as v,
719
- w,
720
- dt as x,
721
- wt as y,
722
- nt as z
702
+ Y as v,
703
+ v as w,
704
+ ft as x,
705
+ kt as y,
706
+ rt as z
723
707
  };
724
- //# sourceMappingURL=challengeAssert-CenzzhZU.js.map
708
+ //# sourceMappingURL=challengeAssert-C5DQSUnp.js.map