@babylonlabs-io/ts-sdk 0.6.0 → 0.8.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 (81) hide show
  1. package/README.md +1 -1
  2. package/dist/PayoutManager-9qwA76_B.cjs +2 -0
  3. package/dist/PayoutManager-9qwA76_B.cjs.map +1 -0
  4. package/dist/{PayoutManager-CgS9Y0KB.js → PayoutManager-CvWBwdzd.js} +285 -268
  5. package/dist/PayoutManager-CvWBwdzd.js.map +1 -0
  6. package/dist/{challengeAssert-BpX9FQ-i.js → challengeAssert-D50t_Qyo.js} +102 -101
  7. package/dist/challengeAssert-D50t_Qyo.js.map +1 -0
  8. package/dist/challengeAssert-DDceAi0r.cjs +2 -0
  9. package/dist/challengeAssert-DDceAi0r.cjs.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +72 -69
  12. package/dist/index.js.map +1 -1
  13. package/dist/shared/index.cjs +1 -1
  14. package/dist/shared/index.d.ts +1 -0
  15. package/dist/shared/index.d.ts.map +1 -1
  16. package/dist/shared/index.js +5 -3
  17. package/dist/shared/index.js.map +1 -1
  18. package/dist/shared/wallets/__tests__/signOptions.test.d.ts +2 -0
  19. package/dist/shared/wallets/__tests__/signOptions.test.d.ts.map +1 -0
  20. package/dist/shared/wallets/index.d.ts +1 -0
  21. package/dist/shared/wallets/index.d.ts.map +1 -1
  22. package/dist/shared/wallets/signOptions.d.ts +15 -0
  23. package/dist/shared/wallets/signOptions.d.ts.map +1 -0
  24. package/dist/signOptions-Deg5lCoC.cjs +2 -0
  25. package/dist/signOptions-Deg5lCoC.cjs.map +1 -0
  26. package/dist/signOptions-Drwr3bXB.js +16 -0
  27. package/dist/signOptions-Drwr3bXB.js.map +1 -0
  28. package/dist/tbv/core/contracts/abis/{BTCVaultsManager.abi.d.ts → BTCVaultRegistry.abi.d.ts} +41 -9
  29. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -0
  30. package/dist/tbv/core/contracts/index.d.ts +1 -1
  31. package/dist/tbv/core/index.cjs +1 -1
  32. package/dist/tbv/core/index.js +38 -37
  33. package/dist/tbv/core/managers/PayoutManager.d.ts +1 -1
  34. package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
  35. package/dist/tbv/core/managers/PeginManager.d.ts +22 -22
  36. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  37. package/dist/tbv/core/managers/__tests__/PeginManager.test.d.ts +1 -1
  38. package/dist/tbv/core/managers/index.d.ts +4 -4
  39. package/dist/tbv/core/managers/index.d.ts.map +1 -1
  40. package/dist/tbv/core/primitives/index.cjs +1 -1
  41. package/dist/tbv/core/primitives/index.d.ts +1 -1
  42. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  43. package/dist/tbv/core/primitives/index.js +10 -9
  44. package/dist/tbv/core/primitives/psbt/pegin.d.ts +11 -8
  45. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  46. package/dist/tbv/core/primitives/psbt/peginInput.d.ts +1 -1
  47. package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
  48. package/dist/tbv/core/utils/transaction/btcTxHash.d.ts +1 -1
  49. package/dist/tbv/index.cjs +1 -1
  50. package/dist/tbv/index.js +38 -37
  51. package/dist/tbv/integrations/aave/clients/abis/{AaveIntegrationController.abi.json.d.ts → AaveIntegrationAdapter.abi.json.d.ts} +46 -4
  52. package/dist/tbv/integrations/aave/clients/index.d.ts +1 -1
  53. package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
  54. package/dist/tbv/integrations/aave/clients/query.d.ts +3 -3
  55. package/dist/tbv/integrations/aave/clients/transaction.d.ts +19 -7
  56. package/dist/tbv/integrations/aave/clients/transaction.d.ts.map +1 -1
  57. package/dist/tbv/integrations/aave/constants.d.ts +2 -0
  58. package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
  59. package/dist/tbv/integrations/aave/index.cjs +1 -1
  60. package/dist/tbv/integrations/aave/index.cjs.map +1 -1
  61. package/dist/tbv/integrations/aave/index.d.ts +6 -6
  62. package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
  63. package/dist/tbv/integrations/aave/index.js +143 -96
  64. package/dist/tbv/integrations/aave/index.js.map +1 -1
  65. package/dist/tbv/integrations/aave/types.d.ts +1 -1
  66. package/dist/tbv/integrations/aave/utils/__tests__/seizureSimulation.test.d.ts +5 -0
  67. package/dist/tbv/integrations/aave/utils/__tests__/seizureSimulation.test.d.ts.map +1 -0
  68. package/dist/tbv/integrations/aave/utils/index.d.ts +2 -0
  69. package/dist/tbv/integrations/aave/utils/index.d.ts.map +1 -1
  70. package/dist/tbv/integrations/aave/utils/seizureSimulation.d.ts +109 -0
  71. package/dist/tbv/integrations/aave/utils/seizureSimulation.d.ts.map +1 -0
  72. package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts +1 -0
  73. package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts.map +1 -1
  74. package/package.json +1 -1
  75. package/dist/PayoutManager-AJJ-3vvu.cjs +0 -2
  76. package/dist/PayoutManager-AJJ-3vvu.cjs.map +0 -1
  77. package/dist/PayoutManager-CgS9Y0KB.js.map +0 -1
  78. package/dist/challengeAssert-BMSvVtzu.cjs +0 -2
  79. package/dist/challengeAssert-BMSvVtzu.cjs.map +0 -1
  80. package/dist/challengeAssert-BpX9FQ-i.js.map +0 -1
  81. package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
- import { createPrePeginTransaction as R, buildPeginTxFromPrePegin as W, getPrePeginHtlcConnectorInfo as K, tapInternalPubkey as k, createPayoutConnector as N, getPeginPayoutScript as q, getAssertNoPayoutScriptInfo as z, getChallengeAssertScriptInfo as M } from "@babylonlabs-io/babylon-tbv-rust-wasm";
1
+ import { createPrePeginTransaction as R, buildPeginTxFromPrePegin as W, getPrePeginHtlcConnectorInfo as K, tapInternalPubkey as w, createPayoutConnector as N, getPeginPayoutScript as q, getAssertNoPayoutScriptInfo as z, getChallengeAssertScriptInfo as M } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
2
  import * as U from "bitcoinjs-lib";
3
- import { payments as b, networks as T, initEccLib as H, Transaction as P, Psbt as w } from "bitcoinjs-lib";
3
+ import { payments as b, networks as T, initEccLib as H, Transaction as P, Psbt as k } from "bitcoinjs-lib";
4
4
  import { Buffer as a } from "buffer";
5
5
  import * as A from "@bitcoin-js/tiny-secp256k1-asmjs";
6
6
  function h(t) {
@@ -14,8 +14,8 @@ function d(t) {
14
14
  if (!B(n))
15
15
  throw new Error(`Invalid hex string: ${t}`);
16
16
  const e = new Uint8Array(n.length / 2);
17
- for (let r = 0; r < n.length; r += 2)
18
- e[r / 2] = parseInt(n.slice(r, r + 2), 16);
17
+ for (let o = 0; o < n.length; o += 2)
18
+ e[o / 2] = parseInt(n.slice(o, o + 2), 16);
19
19
  return e;
20
20
  }
21
21
  function x(t) {
@@ -45,12 +45,12 @@ function at(t) {
45
45
  return B(n);
46
46
  }
47
47
  function lt(t, n) {
48
- const e = $(t), r = n ?? e;
49
- if (e.toLowerCase() !== r.toLowerCase())
48
+ const e = $(t), o = n ?? e;
49
+ if (e.toLowerCase() !== o.toLowerCase())
50
50
  throw new Error(
51
- `Wallet public key does not match vault depositor. Expected: ${r}, Got: ${e}. Please connect the wallet that was used to create this vault.`
51
+ `Wallet public key does not match vault depositor. Expected: ${o}, Got: ${e}. Please connect the wallet that was used to create this vault.`
52
52
  );
53
- return { walletPubkeyRaw: t, walletPubkeyXOnly: e, depositorPubkey: r };
53
+ return { walletPubkeyRaw: t, walletPubkeyXOnly: e, depositorPubkey: o };
54
54
  }
55
55
  let _ = !1;
56
56
  function X() {
@@ -71,13 +71,13 @@ function V(t) {
71
71
  }
72
72
  function G(t, n) {
73
73
  X();
74
- const e = d($(t)), { address: r } = b.p2tr({
74
+ const e = d($(t)), { address: o } = b.p2tr({
75
75
  internalPubkey: a.from(e),
76
76
  network: V(n)
77
77
  });
78
- if (!r)
78
+ if (!o)
79
79
  throw new Error("Failed to derive taproot address from public key");
80
- return r;
80
+ return o;
81
81
  }
82
82
  function Y(t, n) {
83
83
  const e = h(t);
@@ -85,26 +85,26 @@ function Y(t, n) {
85
85
  throw new Error(
86
86
  `Native SegWit requires a compressed public key (66 hex chars), got ${e.length}`
87
87
  );
88
- const { address: r } = b.p2wpkh({
88
+ const { address: o } = b.p2wpkh({
89
89
  pubkey: a.from(d(e)),
90
90
  network: V(n)
91
91
  });
92
- if (!r)
92
+ if (!o)
93
93
  throw new Error(
94
94
  "Failed to derive native segwit address from public key"
95
95
  );
96
- return r;
96
+ return o;
97
97
  }
98
98
  function pt(t, n, e) {
99
- const r = h(n);
99
+ const o = h(n);
100
100
  try {
101
- if (t === G(r, e))
101
+ if (t === G(o, e))
102
102
  return !0;
103
103
  } catch {
104
104
  }
105
- const o = [];
106
- r.length === 66 ? o.push(r) : r.length === 64 && o.push(`02${r}`, `03${r}`);
107
- for (const s of o)
105
+ const r = [];
106
+ o.length === 66 ? r.push(o) : o.length === 64 && r.push(`02${o}`, `03${o}`);
107
+ for (const s of r)
108
108
  try {
109
109
  if (t === Y(s, e))
110
110
  return !0;
@@ -116,11 +116,11 @@ function I(t) {
116
116
  return $(t).toLowerCase();
117
117
  }
118
118
  function ft(t, n, e) {
119
- const r = /* @__PURE__ */ new Set();
120
- r.add(I(t));
121
- for (const o of n)
122
- r.add(I(o));
123
- return r.delete(I(e)), r.size;
119
+ const o = /* @__PURE__ */ new Set();
120
+ o.add(I(t));
121
+ for (const r of n)
122
+ o.add(I(r));
123
+ return o.delete(I(e)), o.size;
124
124
  }
125
125
  const ht = 58, dt = 43, gt = 11, Q = 546, Z = BigInt(Q), j = 30, J = 2, Pt = 1.1;
126
126
  function yt(t) {
@@ -128,23 +128,23 @@ function yt(t) {
128
128
  }
129
129
  const xt = 5;
130
130
  function F(t) {
131
- const e = t.substring(8, 12) === "0001" ? 12 : 8, r = parseInt(
131
+ const e = t.substring(8, 12) === "0001" ? 12 : 8, o = parseInt(
132
132
  t.substring(e, e + 2),
133
133
  16
134
- ), o = parseInt(
134
+ ), r = parseInt(
135
135
  t.substring(e + 2, e + 4),
136
136
  16
137
137
  );
138
- if (r !== 0)
139
- throw new Error(`Expected 0 inputs from WASM, got ${r}`);
140
- if (o === 0)
138
+ if (o !== 0)
139
+ throw new Error(`Expected 0 inputs from WASM, got ${o}`);
140
+ if (r === 0)
141
141
  throw new Error("Expected at least 1 output from WASM, got 0");
142
142
  const s = a.from(t.substring(0, 8), "hex").readUInt32LE(0), u = a.from(
143
143
  t.substring(t.length - 8),
144
144
  "hex"
145
145
  ).readUInt32LE(0), c = [];
146
146
  let i = e + 4;
147
- for (let p = 0; p < o; p++) {
147
+ for (let p = 0; p < r; p++) {
148
148
  const l = t.substring(i, i + 16), f = Number(a.from(l, "hex").readBigUInt64LE(0));
149
149
  i += 16;
150
150
  const g = parseInt(t.substring(i, i + 2), 16);
@@ -154,8 +154,8 @@ function F(t) {
154
154
  }
155
155
  return { version: s, locktime: u, outputs: c };
156
156
  }
157
- function wt(t) {
158
- const { unfundedTxHex: n, selectedUTXOs: e, changeAddress: r, changeAmount: o, network: s } = t, { version: u, locktime: c, outputs: i } = F(n), p = new U.Transaction();
157
+ function kt(t) {
158
+ const { unfundedTxHex: n, selectedUTXOs: e, changeAddress: o, changeAmount: r, network: s } = t, { version: u, locktime: c, outputs: i } = F(n), p = new U.Transaction();
159
159
  p.version = u, p.locktime = c;
160
160
  for (const l of e) {
161
161
  const f = a.from(l.txid, "hex").reverse();
@@ -163,19 +163,19 @@ function wt(t) {
163
163
  }
164
164
  for (const l of i)
165
165
  p.addOutput(l.script, l.value);
166
- if (o > Z) {
167
- const l = U.address.toOutputScript(r, s);
168
- p.addOutput(l, Number(o));
166
+ if (r > Z) {
167
+ const l = U.address.toOutputScript(o, s);
168
+ p.addOutput(l, Number(r));
169
169
  }
170
170
  return p.toHex();
171
171
  }
172
- async function kt(t) {
172
+ async function wt(t) {
173
173
  const n = await R({
174
174
  depositorPubkey: t.depositorPubkey,
175
175
  vaultProviderPubkey: t.vaultProviderPubkey,
176
176
  vaultKeeperPubkeys: t.vaultKeeperPubkeys,
177
177
  universalChallengerPubkeys: t.universalChallengerPubkeys,
178
- hashH: t.hashH,
178
+ hashlocks: [...t.hashlocks],
179
179
  timelockRefund: t.timelockRefund,
180
180
  pegInAmount: t.pegInAmount,
181
181
  feeRate: t.feeRate,
@@ -183,13 +183,13 @@ async function kt(t) {
183
183
  councilQuorum: t.councilQuorum,
184
184
  councilSize: t.councilSize,
185
185
  network: t.network
186
- }), r = F(n.txHex).outputs.reduce(
187
- (o, s) => o + BigInt(s.value),
186
+ }), o = F(n.txHex).outputs.reduce(
187
+ (r, s) => r + BigInt(s.value),
188
188
  0n
189
189
  );
190
190
  return {
191
191
  psbtHex: n.txHex,
192
- totalOutputValue: r,
192
+ totalOutputValue: o,
193
193
  htlcValue: n.htlcValue,
194
194
  htlcScriptPubKey: n.htlcScriptPubKey,
195
195
  htlcAddress: n.htlcAddress,
@@ -204,7 +204,7 @@ async function vt(t) {
204
204
  vaultProviderPubkey: t.prePeginParams.vaultProviderPubkey,
205
205
  vaultKeeperPubkeys: t.prePeginParams.vaultKeeperPubkeys,
206
206
  universalChallengerPubkeys: t.prePeginParams.universalChallengerPubkeys,
207
- hashH: t.prePeginParams.hashH,
207
+ hashlocks: [...t.prePeginParams.hashlocks],
208
208
  timelockRefund: t.prePeginParams.timelockRefund,
209
209
  pegInAmount: t.prePeginParams.pegInAmount,
210
210
  feeRate: t.prePeginParams.feeRate,
@@ -214,7 +214,8 @@ async function vt(t) {
214
214
  network: t.prePeginParams.network
215
215
  },
216
216
  t.timelockPegin,
217
- t.fundedPrePeginTxid
217
+ t.fundedPrePeginTxHex,
218
+ t.htlcVout
218
219
  );
219
220
  return {
220
221
  txHex: n.txHex,
@@ -224,20 +225,20 @@ async function vt(t) {
224
225
  };
225
226
  }
226
227
  async function bt(t) {
227
- const n = h(t.peginTxHex), e = h(t.fundedPrePeginTxHex), r = await K({
228
+ const n = h(t.peginTxHex), e = h(t.fundedPrePeginTxHex), o = await K({
228
229
  depositorPubkey: t.depositorPubkey,
229
230
  vaultProviderPubkey: t.vaultProviderPubkey,
230
231
  vaultKeeperPubkeys: t.vaultKeeperPubkeys,
231
232
  universalChallengerPubkeys: t.universalChallengerPubkeys,
232
- hashH: t.hashH,
233
+ hashlock: t.hashlock,
233
234
  timelockRefund: t.timelockRefund,
234
235
  network: t.network
235
- }), o = P.fromHex(n), s = P.fromHex(e);
236
- if (o.ins.length !== 1)
236
+ }), r = P.fromHex(n), s = P.fromHex(e);
237
+ if (r.ins.length !== 1)
237
238
  throw new Error(
238
- `PegIn transaction must have exactly 1 input, got ${o.ins.length}`
239
+ `PegIn transaction must have exactly 1 input, got ${r.ins.length}`
239
240
  );
240
- const u = o.ins[0], c = s.getId(), i = x(
241
+ const u = r.ins[0], c = s.getId(), i = x(
241
242
  new Uint8Array(u.hash).slice().reverse()
242
243
  );
243
244
  if (i !== c)
@@ -249,8 +250,8 @@ async function bt(t) {
249
250
  throw new Error(
250
251
  `Pre-PegIn output ${u.index} not found (Pre-PegIn has ${s.outs.length} outputs)`
251
252
  );
252
- const l = d(r.hashlockScript), f = d(r.hashlockControlBlock), g = new w();
253
- g.setVersion(o.version), g.setLocktime(o.locktime), g.addInput({
253
+ const l = d(o.hashlockScript), f = d(o.hashlockControlBlock), g = new k();
254
+ g.setVersion(r.version), g.setLocktime(r.locktime), g.addInput({
254
255
  hash: u.hash,
255
256
  index: u.index,
256
257
  sequence: u.sequence,
@@ -265,10 +266,10 @@ async function bt(t) {
265
266
  controlBlock: a.from(f)
266
267
  }
267
268
  ],
268
- tapInternalKey: a.from(k)
269
+ tapInternalKey: a.from(w)
269
270
  // sighashType omitted — defaults to SIGHASH_DEFAULT (0x00) for Taproot
270
271
  });
271
- for (const y of o.outs)
272
+ for (const y of r.outs)
272
273
  g.addOutput({
273
274
  script: y.script,
274
275
  value: y.value
@@ -276,33 +277,33 @@ async function bt(t) {
276
277
  return { psbtHex: g.toHex() };
277
278
  }
278
279
  function St(t, n) {
279
- const r = w.fromHex(t).data.inputs[0];
280
- if (!r)
280
+ const o = k.fromHex(t).data.inputs[0];
281
+ if (!o)
281
282
  throw new Error("PegIn PSBT has no inputs");
282
- if (r.tapScriptSig && r.tapScriptSig.length > 0) {
283
- const o = a.from(
283
+ if (o.tapScriptSig && o.tapScriptSig.length > 0) {
284
+ const r = a.from(
284
285
  d(n)
285
286
  );
286
- for (const s of r.tapScriptSig)
287
- if (s.pubkey.equals(o))
287
+ for (const s of o.tapScriptSig)
288
+ if (s.pubkey.equals(r))
288
289
  return tt(s.signature);
289
290
  throw new Error(
290
291
  `No PegIn input signature found for depositor pubkey: ${n}`
291
292
  );
292
293
  }
293
- throw r.finalScriptWitness && r.finalScriptWitness.length > 0 ? new Error(
294
+ throw o.finalScriptWitness && o.finalScriptWitness.length > 0 ? new Error(
294
295
  "PegIn input PSBT is already finalized. Cannot reliably extract the depositor signature from the witness stack. Ensure the wallet returns a non-finalized PSBT with tapScriptSig entries."
295
296
  ) : new Error(
296
297
  "No tapScriptSig or finalScriptWitness found in signed PegIn input PSBT"
297
298
  );
298
299
  }
299
300
  function mt(t) {
300
- const n = w.fromHex(t);
301
+ const n = k.fromHex(t);
301
302
  try {
302
303
  n.finalizeAllInputs();
303
304
  } catch (e) {
304
305
  if (!n.data.inputs.every(
305
- (o) => o.finalScriptWitness || o.finalScriptSig
306
+ (r) => r.finalScriptWitness || r.finalScriptSig
306
307
  ))
307
308
  throw new Error(
308
309
  `PSBT finalization failed and wallet did not auto-finalize: ${e}`
@@ -337,14 +338,14 @@ async function et(t) {
337
338
  }
338
339
  H(A);
339
340
  async function Et(t) {
340
- const n = h(t.payoutTxHex), e = h(t.peginTxHex), r = h(t.assertTxHex), o = await et({
341
+ const n = h(t.payoutTxHex), e = h(t.peginTxHex), o = h(t.assertTxHex), r = await et({
341
342
  depositor: t.depositorBtcPubkey,
342
343
  vaultProvider: t.vaultProviderBtcPubkey,
343
344
  vaultKeepers: t.vaultKeeperBtcPubkeys,
344
345
  universalChallengers: t.universalChallengerBtcPubkeys,
345
346
  timelockPegin: t.timelockPegin,
346
347
  network: t.network
347
- }), s = d(o.payoutScript), u = rt(k, s), c = P.fromHex(n), i = P.fromHex(e), p = P.fromHex(r), l = new w();
348
+ }), s = d(r.payoutScript), u = ot(w, s), c = P.fromHex(n), i = P.fromHex(e), p = P.fromHex(o), l = new k();
348
349
  if (l.setVersion(c.version), l.setLocktime(c.locktime), c.ins.length !== 2)
349
350
  throw new Error(
350
351
  `Payout transaction must have exactly 2 inputs, got ${c.ins.length}`
@@ -388,7 +389,7 @@ async function Et(t) {
388
389
  controlBlock: a.from(u)
389
390
  }
390
391
  ],
391
- tapInternalKey: a.from(k)
392
+ tapInternalKey: a.from(w)
392
393
  // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
393
394
  }), l.addInput({
394
395
  hash: g.hash,
@@ -410,23 +411,23 @@ async function Et(t) {
410
411
  };
411
412
  }
412
413
  function Tt(t, n, e = 0) {
413
- const r = w.fromHex(t);
414
- if (e >= r.data.inputs.length)
414
+ const o = k.fromHex(t);
415
+ if (e >= o.data.inputs.length)
415
416
  throw new Error(
416
- `Input index ${e} out of range (${r.data.inputs.length} inputs)`
417
+ `Input index ${e} out of range (${o.data.inputs.length} inputs)`
417
418
  );
418
- const o = r.data.inputs[e];
419
- if (o.tapScriptSig && o.tapScriptSig.length > 0) {
419
+ const r = o.data.inputs[e];
420
+ if (r.tapScriptSig && r.tapScriptSig.length > 0) {
420
421
  const s = d(n);
421
- for (const u of o.tapScriptSig)
422
+ for (const u of r.tapScriptSig)
422
423
  if (u.pubkey.equals(a.from(s)))
423
424
  return O(u.signature, e);
424
425
  throw new Error(
425
426
  `No signature found for depositor pubkey: ${n} at input ${e}`
426
427
  );
427
428
  }
428
- if (o.finalScriptWitness && o.finalScriptWitness.length > 0) {
429
- const s = nt(o.finalScriptWitness);
429
+ if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
430
+ const s = nt(r.finalScriptWitness);
430
431
  if (s.length >= 1)
431
432
  return O(s[0], e);
432
433
  }
@@ -452,7 +453,7 @@ function O(t, n) {
452
453
  function nt(t) {
453
454
  const n = [];
454
455
  let e = 0;
455
- const r = () => {
456
+ const o = () => {
456
457
  const s = t[e++];
457
458
  if (s < 253) return s;
458
459
  if (s === 253) {
@@ -464,26 +465,26 @@ function nt(t) {
464
465
  return e += 4, u;
465
466
  }
466
467
  return e += 8, 0;
467
- }, o = r();
468
- for (let s = 0; s < o; s++) {
469
- const u = r();
468
+ }, r = o();
469
+ for (let s = 0; s < r; s++) {
470
+ const u = o();
470
471
  n.push(t.subarray(e, e + u)), e += u;
471
472
  }
472
473
  return n;
473
474
  }
474
- function rt(t, n) {
475
- const e = { output: a.from(n) }, o = b.p2tr({
475
+ function ot(t, n) {
476
+ const e = { output: a.from(n) }, r = b.p2tr({
476
477
  internalPubkey: a.from(t),
477
478
  scriptTree: e
478
479
  }).pubkey;
479
- if (!o)
480
+ if (!r)
480
481
  throw new Error("Failed to compute output key");
481
- const s = 192, u = o[0] === 3 ? 1 : 0, c = s | u, i = new Uint8Array(1 + t.length);
482
+ const s = 192, u = r[0] === 3 ? 1 : 0, c = s | u, i = new Uint8Array(1 + t.length);
482
483
  return i[0] = c, i.set(t, 1), i;
483
484
  }
484
485
  H(A);
485
486
  async function It(t) {
486
- const n = h(t.payoutTxHex), e = P.fromHex(n), r = await q(t.connectorParams), o = d(r), s = ot(k, o), u = new w();
487
+ const n = h(t.payoutTxHex), e = P.fromHex(n), o = await q(t.connectorParams), r = d(o), s = rt(w, r), u = new k();
487
488
  u.setVersion(e.version), u.setLocktime(e.locktime);
488
489
  for (let c = 0; c < e.ins.length; c++) {
489
490
  const i = e.ins[c], p = t.prevouts[c];
@@ -501,10 +502,10 @@ async function It(t) {
501
502
  c === 0 && (l.tapLeafScript = [
502
503
  {
503
504
  leafVersion: 192,
504
- script: a.from(o),
505
+ script: a.from(r),
505
506
  controlBlock: a.from(s)
506
507
  }
507
- ], l.tapInternalKey = a.from(k)), u.addInput(l);
508
+ ], l.tapInternalKey = a.from(w)), u.addInput(l);
508
509
  }
509
510
  for (const c of e.outs)
510
511
  u.addOutput({
@@ -513,21 +514,21 @@ async function It(t) {
513
514
  });
514
515
  return u.toHex();
515
516
  }
516
- function ot(t, n) {
517
- const e = { output: a.from(n) }, o = b.p2tr({
517
+ function rt(t, n) {
518
+ const e = { output: a.from(n) }, r = b.p2tr({
518
519
  internalPubkey: a.from(t),
519
520
  scriptTree: e
520
521
  }).pubkey;
521
- if (!o)
522
+ if (!r)
522
523
  throw new Error("Failed to compute output key");
523
- const s = 192, u = o[0] === 3 ? 1 : 0, c = s | u, i = new Uint8Array(1 + t.length);
524
+ const s = 192, u = r[0] === 3 ? 1 : 0, c = s | u, i = new Uint8Array(1 + t.length);
524
525
  return i[0] = c, i.set(t, 1), i;
525
526
  }
526
527
  async function Ht(t) {
527
- const n = h(t.noPayoutTxHex), e = P.fromHex(n), { noPayoutScript: r, noPayoutControlBlock: o } = await z(
528
+ const n = h(t.noPayoutTxHex), e = P.fromHex(n), { noPayoutScript: o, noPayoutControlBlock: r } = await z(
528
529
  t.connectorParams,
529
530
  t.challengerPubkey
530
- ), s = d(r), u = d(o), c = new w();
531
+ ), s = d(o), u = d(r), c = new k();
531
532
  c.setVersion(e.version), c.setLocktime(e.locktime);
532
533
  for (let i = 0; i < e.ins.length; i++) {
533
534
  const p = e.ins[i], l = t.prevouts[i];
@@ -548,7 +549,7 @@ async function Ht(t) {
548
549
  script: a.from(s),
549
550
  controlBlock: a.from(u)
550
551
  }
551
- ], f.tapInternalKey = a.from(k)), c.addInput(f);
552
+ ], f.tapInternalKey = a.from(w)), c.addInput(f);
552
553
  }
553
554
  for (const i of e.outs)
554
555
  c.addOutput({
@@ -563,16 +564,16 @@ async function At(t) {
563
564
  throw new Error(
564
565
  `Expected ${e.ins.length} connector params, got ${t.connectorParamsPerInput.length}`
565
566
  );
566
- const r = await Promise.all(
567
+ const o = await Promise.all(
567
568
  t.connectorParamsPerInput.map((s) => M(s))
568
- ), o = new w();
569
- o.setVersion(e.version), o.setLocktime(e.locktime);
569
+ ), r = new k();
570
+ r.setVersion(e.version), r.setLocktime(e.locktime);
570
571
  for (let s = 0; s < e.ins.length; s++) {
571
572
  const u = e.ins[s], c = t.prevouts[s];
572
573
  if (!c)
573
574
  throw new Error(`Missing prevout data for input ${s}`);
574
- const { script: i, controlBlock: p } = r[s], l = d(i), f = d(p);
575
- o.addInput({
575
+ const { script: i, controlBlock: p } = o[s], l = d(i), f = d(p);
576
+ r.addInput({
576
577
  hash: u.hash,
577
578
  index: u.index,
578
579
  sequence: u.sequence,
@@ -587,15 +588,15 @@ async function At(t) {
587
588
  controlBlock: a.from(f)
588
589
  }
589
590
  ],
590
- tapInternalKey: a.from(k)
591
+ tapInternalKey: a.from(w)
591
592
  });
592
593
  }
593
594
  for (const s of e.outs)
594
- o.addOutput({
595
+ r.addOutput({
595
596
  script: s.script,
596
597
  value: s.value
597
598
  });
598
- return o.toHex();
599
+ return r.toHex();
599
600
  }
600
601
  export {
601
602
  V as A,
@@ -609,7 +610,7 @@ export {
609
610
  gt as T,
610
611
  J as W,
611
612
  vt as a,
612
- kt as b,
613
+ wt as b,
613
614
  ft as c,
614
615
  bt as d,
615
616
  St as e,
@@ -633,6 +634,6 @@ export {
633
634
  lt as w,
634
635
  yt as x,
635
636
  F as y,
636
- wt as z
637
+ kt as z
637
638
  };
638
- //# sourceMappingURL=challengeAssert-BpX9FQ-i.js.map
639
+ //# sourceMappingURL=challengeAssert-D50t_Qyo.js.map