@babylonlabs-io/ts-sdk 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/challengeAssert-BpzES0KW.cjs +2 -0
  2. package/dist/challengeAssert-BpzES0KW.cjs.map +1 -0
  3. package/dist/challengeAssert-CenzzhZU.js +724 -0
  4. package/dist/challengeAssert-CenzzhZU.js.map +1 -0
  5. package/dist/errors-CPd0qvSk.cjs +2 -0
  6. package/dist/errors-CPd0qvSk.cjs.map +1 -0
  7. package/dist/{errors-DOJdtNTD.js → errors-Ci-2cgfS.js} +331 -285
  8. package/dist/errors-Ci-2cgfS.js.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +59 -58
  11. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +15 -7
  12. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  13. package/dist/tbv/core/index.cjs +1 -1
  14. package/dist/tbv/core/index.d.ts +1 -1
  15. package/dist/tbv/core/index.d.ts.map +1 -1
  16. package/dist/tbv/core/index.js +59 -58
  17. package/dist/tbv/core/managers/PayoutManager.d.ts +21 -0
  18. package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
  19. package/dist/tbv/core/managers/PeginManager.d.ts +2 -2
  20. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  21. package/dist/tbv/core/primitives/index.cjs +1 -1
  22. package/dist/tbv/core/primitives/index.d.ts +2 -0
  23. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  24. package/dist/tbv/core/primitives/index.js +21 -20
  25. package/dist/tbv/core/primitives/psbt/refund.d.ts +42 -0
  26. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -0
  27. package/dist/tbv/core/wots/__tests__/derivation.test.d.ts.map +1 -0
  28. package/dist/tbv/core/{lamport → wots}/derivation.d.ts +16 -16
  29. package/dist/tbv/core/wots/derivation.d.ts.map +1 -0
  30. package/dist/tbv/core/wots/deriveWotsPkHash.d.ts +9 -0
  31. package/dist/tbv/core/wots/deriveWotsPkHash.d.ts.map +1 -0
  32. package/dist/tbv/core/wots/errors.d.ts +7 -0
  33. package/dist/tbv/core/wots/errors.d.ts.map +1 -0
  34. package/dist/tbv/core/wots/index.d.ts +5 -0
  35. package/dist/tbv/core/wots/index.d.ts.map +1 -0
  36. package/dist/tbv/core/{lamport → wots}/types.d.ts +8 -8
  37. package/dist/tbv/core/wots/types.d.ts.map +1 -0
  38. package/dist/tbv/index.cjs +1 -1
  39. package/dist/tbv/index.js +59 -58
  40. package/dist/tbv/integrations/aave/clients/abis/AaveIntegrationAdapter.abi.json.d.ts +459 -485
  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 +91 -91
  44. package/package.json +3 -3
  45. package/dist/challengeAssert-DW0sEUgn.cjs +0 -2
  46. package/dist/challengeAssert-DW0sEUgn.cjs.map +0 -1
  47. package/dist/challengeAssert-DnnliaRt.js +0 -645
  48. package/dist/challengeAssert-DnnliaRt.js.map +0 -1
  49. package/dist/errors-DOJdtNTD.js.map +0 -1
  50. package/dist/errors-DbATYfYA.cjs +0 -2
  51. package/dist/errors-DbATYfYA.cjs.map +0 -1
  52. package/dist/tbv/core/lamport/__tests__/derivation.test.d.ts.map +0 -1
  53. package/dist/tbv/core/lamport/derivation.d.ts.map +0 -1
  54. package/dist/tbv/core/lamport/deriveLamportPkHash.d.ts +0 -9
  55. package/dist/tbv/core/lamport/deriveLamportPkHash.d.ts.map +0 -1
  56. package/dist/tbv/core/lamport/errors.d.ts +0 -7
  57. package/dist/tbv/core/lamport/errors.d.ts.map +0 -1
  58. package/dist/tbv/core/lamport/index.d.ts +0 -5
  59. package/dist/tbv/core/lamport/index.d.ts.map +0 -1
  60. package/dist/tbv/core/lamport/types.d.ts.map +0 -1
  61. /package/dist/tbv/core/{lamport → wots}/__tests__/derivation.test.d.ts +0 -0
@@ -1,645 +0,0 @@
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
- import * as U from "bitcoinjs-lib";
3
- import { payments as b, networks as T, initEccLib as H, Transaction as P, Psbt as k } from "bitcoinjs-lib";
4
- import { Buffer as a } from "buffer";
5
- import * as A from "@bitcoin-js/tiny-secp256k1-asmjs";
6
- function h(t) {
7
- return t.startsWith("0x") ? t.slice(2) : t;
8
- }
9
- function at(t) {
10
- return t.startsWith("0x") ? t : `0x${t}`;
11
- }
12
- function d(t) {
13
- const n = h(t);
14
- if (!B(n))
15
- throw new Error(`Invalid hex string: ${t}`);
16
- const e = new Uint8Array(n.length / 2);
17
- for (let o = 0; o < n.length; o += 2)
18
- e[o / 2] = parseInt(n.slice(o, o + 2), 16);
19
- return e;
20
- }
21
- function x(t) {
22
- return Array.from(t).map((n) => n.toString(16).padStart(2, "0")).join("");
23
- }
24
- function D(t) {
25
- return t.length === 32 ? t : t.slice(1, 33);
26
- }
27
- function B(t) {
28
- return /^[0-9a-fA-F]*$/.test(t) && t.length % 2 === 0;
29
- }
30
- function $(t) {
31
- const n = h(t);
32
- if (!B(n))
33
- throw new Error(`Invalid hex characters in public key: ${t}`);
34
- if (n.length === 64)
35
- return n;
36
- if (n.length !== 66 && n.length !== 130)
37
- throw new Error(
38
- `Invalid public key length: ${n.length} (expected 64, 66, or 130 hex chars)`
39
- );
40
- const e = d(n);
41
- return x(D(e));
42
- }
43
- function lt(t) {
44
- const n = h(t);
45
- return B(n);
46
- }
47
- function pt(t, n) {
48
- const e = $(t), o = n ?? e;
49
- if (e.toLowerCase() !== o.toLowerCase())
50
- throw new Error(
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
- );
53
- return { walletPubkeyRaw: t, walletPubkeyXOnly: e, depositorPubkey: o };
54
- }
55
- let _ = !1;
56
- function X() {
57
- _ || (H(A), _ = !0);
58
- }
59
- function V(t) {
60
- switch (t) {
61
- case "bitcoin":
62
- return T.bitcoin;
63
- case "testnet":
64
- case "signet":
65
- return T.testnet;
66
- case "regtest":
67
- return T.regtest;
68
- default:
69
- throw new Error(`Unknown network: ${t}`);
70
- }
71
- }
72
- function G(t, n) {
73
- X();
74
- const e = d($(t)), { address: o } = b.p2tr({
75
- internalPubkey: a.from(e),
76
- network: V(n)
77
- });
78
- if (!o)
79
- throw new Error("Failed to derive taproot address from public key");
80
- return o;
81
- }
82
- function Y(t, n) {
83
- const e = h(t);
84
- if (e.length !== 66)
85
- throw new Error(
86
- `Native SegWit requires a compressed public key (66 hex chars), got ${e.length}`
87
- );
88
- const { address: o } = b.p2wpkh({
89
- pubkey: a.from(d(e)),
90
- network: V(n)
91
- });
92
- if (!o)
93
- throw new Error(
94
- "Failed to derive native segwit address from public key"
95
- );
96
- return o;
97
- }
98
- function ft(t, n, e) {
99
- const o = h(n);
100
- try {
101
- if (t === G(o, e))
102
- return !0;
103
- } catch {
104
- }
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
- try {
109
- if (t === Y(s, e))
110
- return !0;
111
- } catch {
112
- }
113
- return !1;
114
- }
115
- function I(t) {
116
- return $(t).toLowerCase();
117
- }
118
- function ht(t, n, e) {
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
- }
125
- const dt = 58, gt = 43, Pt = 11, Q = 546, Z = BigInt(Q), j = 30, J = 2, yt = 1.1;
126
- function xt(t) {
127
- return t <= J ? j : 0;
128
- }
129
- const tt = 1;
130
- function kt(t) {
131
- return t + tt;
132
- }
133
- const wt = 5;
134
- function F(t) {
135
- const e = t.substring(8, 12) === "0001" ? 12 : 8, o = parseInt(
136
- t.substring(e, e + 2),
137
- 16
138
- ), r = parseInt(
139
- t.substring(e + 2, e + 4),
140
- 16
141
- );
142
- if (o !== 0)
143
- throw new Error(`Expected 0 inputs from WASM, got ${o}`);
144
- if (r === 0)
145
- throw new Error("Expected at least 1 output from WASM, got 0");
146
- const s = a.from(t.substring(0, 8), "hex").readUInt32LE(0), u = a.from(
147
- t.substring(t.length - 8),
148
- "hex"
149
- ).readUInt32LE(0), c = [];
150
- let i = e + 4;
151
- for (let p = 0; p < r; p++) {
152
- const l = t.substring(i, i + 16), f = Number(a.from(l, "hex").readBigUInt64LE(0));
153
- i += 16;
154
- const g = parseInt(t.substring(i, i + 2), 16);
155
- i += 2;
156
- const y = t.substring(i, i + g * 2), v = a.from(y, "hex");
157
- i += g * 2, c.push({ value: f, script: v });
158
- }
159
- return { version: s, locktime: u, outputs: c };
160
- }
161
- function vt(t) {
162
- const { unfundedTxHex: n, selectedUTXOs: e, changeAddress: o, changeAmount: r, network: s } = t, { version: u, locktime: c, outputs: i } = F(n), p = new U.Transaction();
163
- p.version = u, p.locktime = c;
164
- for (const l of e) {
165
- const f = a.from(l.txid, "hex").reverse();
166
- p.addInput(f, l.vout);
167
- }
168
- for (const l of i)
169
- p.addOutput(l.script, l.value);
170
- if (r > Z) {
171
- const l = U.address.toOutputScript(o, s);
172
- p.addOutput(l, Number(r));
173
- }
174
- return p.toHex();
175
- }
176
- async function bt(t) {
177
- const n = await R({
178
- depositorPubkey: t.depositorPubkey,
179
- vaultProviderPubkey: t.vaultProviderPubkey,
180
- vaultKeeperPubkeys: t.vaultKeeperPubkeys,
181
- universalChallengerPubkeys: t.universalChallengerPubkeys,
182
- hashlocks: [...t.hashlocks],
183
- timelockRefund: t.timelockRefund,
184
- pegInAmounts: [...t.pegInAmounts],
185
- feeRate: t.feeRate,
186
- numLocalChallengers: t.numLocalChallengers,
187
- councilQuorum: t.councilQuorum,
188
- councilSize: t.councilSize,
189
- network: t.network
190
- }), o = F(n.txHex).outputs.reduce(
191
- (r, s) => r + BigInt(s.value),
192
- 0n
193
- );
194
- return {
195
- psbtHex: n.txHex,
196
- totalOutputValue: o,
197
- htlcValues: n.htlcValues,
198
- htlcScriptPubKeys: n.htlcScriptPubKeys,
199
- htlcAddresses: n.htlcAddresses,
200
- peginAmounts: n.peginAmounts,
201
- depositorClaimValue: n.depositorClaimValue
202
- };
203
- }
204
- async function St(t) {
205
- const n = await W(
206
- {
207
- depositorPubkey: t.prePeginParams.depositorPubkey,
208
- vaultProviderPubkey: t.prePeginParams.vaultProviderPubkey,
209
- vaultKeeperPubkeys: t.prePeginParams.vaultKeeperPubkeys,
210
- universalChallengerPubkeys: t.prePeginParams.universalChallengerPubkeys,
211
- hashlocks: [...t.prePeginParams.hashlocks],
212
- timelockRefund: t.prePeginParams.timelockRefund,
213
- pegInAmounts: [...t.prePeginParams.pegInAmounts],
214
- feeRate: t.prePeginParams.feeRate,
215
- numLocalChallengers: t.prePeginParams.numLocalChallengers,
216
- councilQuorum: t.prePeginParams.councilQuorum,
217
- councilSize: t.prePeginParams.councilSize,
218
- network: t.prePeginParams.network
219
- },
220
- t.timelockPegin,
221
- t.fundedPrePeginTxHex,
222
- t.htlcVout
223
- );
224
- return {
225
- txHex: n.txHex,
226
- txid: n.txid,
227
- vaultScriptPubKey: n.vaultScriptPubKey,
228
- vaultValue: n.vaultValue
229
- };
230
- }
231
- async function mt(t) {
232
- const n = h(t.peginTxHex), e = h(t.fundedPrePeginTxHex), o = await K({
233
- depositorPubkey: t.depositorPubkey,
234
- vaultProviderPubkey: t.vaultProviderPubkey,
235
- vaultKeeperPubkeys: t.vaultKeeperPubkeys,
236
- universalChallengerPubkeys: t.universalChallengerPubkeys,
237
- hashlock: t.hashlock,
238
- timelockRefund: t.timelockRefund,
239
- network: t.network
240
- }), r = P.fromHex(n), s = P.fromHex(e);
241
- if (r.ins.length !== 1)
242
- throw new Error(
243
- `PegIn transaction must have exactly 1 input, got ${r.ins.length}`
244
- );
245
- const u = r.ins[0], c = s.getId(), i = x(
246
- new Uint8Array(u.hash).slice().reverse()
247
- );
248
- if (i !== c)
249
- throw new Error(
250
- `PegIn input does not reference the Pre-PegIn transaction. Expected ${c}, got ${i}`
251
- );
252
- const p = s.outs[u.index];
253
- if (!p)
254
- throw new Error(
255
- `Pre-PegIn output ${u.index} not found (Pre-PegIn has ${s.outs.length} outputs)`
256
- );
257
- const l = d(o.hashlockScript), f = d(o.hashlockControlBlock), g = new k();
258
- g.setVersion(r.version), g.setLocktime(r.locktime), g.addInput({
259
- hash: u.hash,
260
- index: u.index,
261
- sequence: u.sequence,
262
- witnessUtxo: {
263
- script: p.script,
264
- value: p.value
265
- },
266
- tapLeafScript: [
267
- {
268
- leafVersion: 192,
269
- script: a.from(l),
270
- controlBlock: a.from(f)
271
- }
272
- ],
273
- tapInternalKey: a.from(w)
274
- // sighashType omitted — defaults to SIGHASH_DEFAULT (0x00) for Taproot
275
- });
276
- for (const y of r.outs)
277
- g.addOutput({
278
- script: y.script,
279
- value: y.value
280
- });
281
- return { psbtHex: g.toHex() };
282
- }
283
- function Et(t, n) {
284
- const o = k.fromHex(t).data.inputs[0];
285
- if (!o)
286
- throw new Error("PegIn PSBT has no inputs");
287
- if (o.tapScriptSig && o.tapScriptSig.length > 0) {
288
- const r = a.from(
289
- d(n)
290
- );
291
- for (const s of o.tapScriptSig)
292
- if (s.pubkey.equals(r))
293
- return et(s.signature);
294
- throw new Error(
295
- `No PegIn input signature found for depositor pubkey: ${n}`
296
- );
297
- }
298
- throw o.finalScriptWitness && o.finalScriptWitness.length > 0 ? new Error(
299
- "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."
300
- ) : new Error(
301
- "No tapScriptSig or finalScriptWitness found in signed PegIn input PSBT"
302
- );
303
- }
304
- function Tt(t) {
305
- const n = k.fromHex(t);
306
- try {
307
- n.finalizeAllInputs();
308
- } catch (e) {
309
- if (!n.data.inputs.every(
310
- (r) => r.finalScriptWitness || r.finalScriptSig
311
- ))
312
- throw new Error(
313
- `PSBT finalization failed and wallet did not auto-finalize: ${e}`
314
- );
315
- }
316
- return n.extractTransaction().toHex();
317
- }
318
- function et(t) {
319
- if (t.length === 64)
320
- return x(new Uint8Array(t));
321
- if (t.length === 65)
322
- return x(new Uint8Array(t.subarray(0, 64)));
323
- throw new Error(`Unexpected PegIn input signature length: ${t.length}`);
324
- }
325
- async function nt(t) {
326
- const n = await N(
327
- {
328
- depositor: t.depositor,
329
- vaultProvider: t.vaultProvider,
330
- vaultKeepers: t.vaultKeepers,
331
- universalChallengers: t.universalChallengers,
332
- timelockPegin: t.timelockPegin
333
- },
334
- t.network
335
- );
336
- return {
337
- payoutScript: n.payoutScript,
338
- taprootScriptHash: n.taprootScriptHash,
339
- scriptPubKey: n.scriptPubKey,
340
- address: n.address
341
- };
342
- }
343
- H(A);
344
- async function It(t) {
345
- const n = h(t.payoutTxHex), e = h(t.peginTxHex), o = h(t.assertTxHex), r = await nt({
346
- depositor: t.depositorBtcPubkey,
347
- vaultProvider: t.vaultProviderBtcPubkey,
348
- vaultKeepers: t.vaultKeeperBtcPubkeys,
349
- universalChallengers: t.universalChallengerBtcPubkeys,
350
- timelockPegin: t.timelockPegin,
351
- network: t.network
352
- }), s = d(r.payoutScript), u = rt(w, s), c = P.fromHex(n), i = P.fromHex(e), p = P.fromHex(o), l = new k();
353
- if (l.setVersion(c.version), l.setLocktime(c.locktime), c.ins.length !== 2)
354
- throw new Error(
355
- `Payout transaction must have exactly 2 inputs, got ${c.ins.length}`
356
- );
357
- const f = c.ins[0], g = c.ins[1], y = x(
358
- new Uint8Array(f.hash).slice().reverse()
359
- ), v = i.getId();
360
- if (y !== v)
361
- throw new Error(
362
- `Input 0 does not reference pegin transaction. Expected ${v}, got ${y}`
363
- );
364
- const S = x(
365
- new Uint8Array(g.hash).slice().reverse()
366
- ), C = p.getId();
367
- if (S !== C)
368
- throw new Error(
369
- `Input 1 does not reference assert transaction. Expected ${C}, got ${S}`
370
- );
371
- const m = i.outs[f.index];
372
- if (!m)
373
- throw new Error(
374
- `Previous output not found for input 0 (txid: ${y}, index: ${f.index})`
375
- );
376
- const E = p.outs[g.index];
377
- if (!E)
378
- throw new Error(
379
- `Previous output not found for input 1 (txid: ${S}, index: ${g.index})`
380
- );
381
- l.addInput({
382
- hash: f.hash,
383
- index: f.index,
384
- sequence: f.sequence,
385
- witnessUtxo: {
386
- script: m.script,
387
- value: m.value
388
- },
389
- tapLeafScript: [
390
- {
391
- leafVersion: 192,
392
- script: a.from(s),
393
- controlBlock: a.from(u)
394
- }
395
- ],
396
- tapInternalKey: a.from(w)
397
- // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
398
- }), l.addInput({
399
- hash: g.hash,
400
- index: g.index,
401
- sequence: g.sequence,
402
- witnessUtxo: {
403
- script: E.script,
404
- value: E.value
405
- }
406
- // No tapLeafScript - depositor doesn't sign this input
407
- });
408
- for (const L of c.outs)
409
- l.addOutput({
410
- script: L.script,
411
- value: L.value
412
- });
413
- return {
414
- psbtHex: l.toHex()
415
- };
416
- }
417
- function Ht(t, n, e = 0) {
418
- const o = k.fromHex(t);
419
- if (e >= o.data.inputs.length)
420
- throw new Error(
421
- `Input index ${e} out of range (${o.data.inputs.length} inputs)`
422
- );
423
- const r = o.data.inputs[e];
424
- if (r.tapScriptSig && r.tapScriptSig.length > 0) {
425
- const s = d(n);
426
- for (const u of r.tapScriptSig)
427
- if (u.pubkey.equals(a.from(s)))
428
- return O(u.signature, e);
429
- throw new Error(
430
- `No signature found for depositor pubkey: ${n} at input ${e}`
431
- );
432
- }
433
- if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
434
- const s = ot(r.finalScriptWitness);
435
- if (s.length >= 1)
436
- return O(s[0], e);
437
- }
438
- throw new Error(
439
- `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${e}`
440
- );
441
- }
442
- function O(t, n) {
443
- if (t.length === 64)
444
- return x(new Uint8Array(t));
445
- if (t.length === 65) {
446
- const e = t[64];
447
- if (e !== P.SIGHASH_ALL)
448
- throw new Error(
449
- `Unexpected sighash type 0x${e.toString(16).padStart(2, "0")} at input ${n}. Expected SIGHASH_ALL (0x01).`
450
- );
451
- return x(new Uint8Array(t.subarray(0, 64)));
452
- }
453
- throw new Error(
454
- `Unexpected signature length at input ${n}: ${t.length}`
455
- );
456
- }
457
- function ot(t) {
458
- const n = [];
459
- let e = 0;
460
- const o = () => {
461
- const s = t[e++];
462
- if (s < 253) return s;
463
- if (s === 253) {
464
- const u = t[e] | t[e + 1] << 8;
465
- return e += 2, u;
466
- }
467
- if (s === 254) {
468
- const u = t[e] | t[e + 1] << 8 | t[e + 2] << 16 | t[e + 3] << 24;
469
- return e += 4, u;
470
- }
471
- return e += 8, 0;
472
- }, r = o();
473
- for (let s = 0; s < r; s++) {
474
- const u = o();
475
- n.push(t.subarray(e, e + u)), e += u;
476
- }
477
- return n;
478
- }
479
- function rt(t, n) {
480
- const e = { output: a.from(n) }, r = b.p2tr({
481
- internalPubkey: a.from(t),
482
- scriptTree: e
483
- }).pubkey;
484
- if (!r)
485
- throw new Error("Failed to compute output key");
486
- const s = 192, u = r[0] === 3 ? 1 : 0, c = s | u, i = new Uint8Array(1 + t.length);
487
- return i[0] = c, i.set(t, 1), i;
488
- }
489
- H(A);
490
- async function At(t) {
491
- const n = h(t.payoutTxHex), e = P.fromHex(n), o = await q(t.connectorParams), r = d(o), s = st(w, r), u = new k();
492
- u.setVersion(e.version), u.setLocktime(e.locktime);
493
- for (let c = 0; c < e.ins.length; c++) {
494
- const i = e.ins[c], p = t.prevouts[c];
495
- if (!p)
496
- throw new Error(`Missing prevout data for input ${c}`);
497
- const l = {
498
- hash: i.hash,
499
- index: i.index,
500
- sequence: i.sequence,
501
- witnessUtxo: {
502
- script: a.from(d(h(p.script_pubkey))),
503
- value: p.value
504
- }
505
- };
506
- c === 0 && (l.tapLeafScript = [
507
- {
508
- leafVersion: 192,
509
- script: a.from(r),
510
- controlBlock: a.from(s)
511
- }
512
- ], l.tapInternalKey = a.from(w)), u.addInput(l);
513
- }
514
- for (const c of e.outs)
515
- u.addOutput({
516
- script: c.script,
517
- value: c.value
518
- });
519
- return u.toHex();
520
- }
521
- function st(t, n) {
522
- const e = { output: a.from(n) }, r = b.p2tr({
523
- internalPubkey: a.from(t),
524
- scriptTree: e
525
- }).pubkey;
526
- if (!r)
527
- throw new Error("Failed to compute output key");
528
- const s = 192, u = r[0] === 3 ? 1 : 0, c = s | u, i = new Uint8Array(1 + t.length);
529
- return i[0] = c, i.set(t, 1), i;
530
- }
531
- async function Bt(t) {
532
- const n = h(t.noPayoutTxHex), e = P.fromHex(n), { noPayoutScript: o, noPayoutControlBlock: r } = await z(
533
- t.connectorParams,
534
- t.challengerPubkey
535
- ), s = d(o), u = d(r), c = new k();
536
- c.setVersion(e.version), c.setLocktime(e.locktime);
537
- for (let i = 0; i < e.ins.length; i++) {
538
- const p = e.ins[i], l = t.prevouts[i];
539
- if (!l)
540
- throw new Error(`Missing prevout data for input ${i}`);
541
- const f = {
542
- hash: p.hash,
543
- index: p.index,
544
- sequence: p.sequence,
545
- witnessUtxo: {
546
- script: a.from(d(h(l.script_pubkey))),
547
- value: l.value
548
- }
549
- };
550
- i === 0 && (f.tapLeafScript = [
551
- {
552
- leafVersion: 192,
553
- script: a.from(s),
554
- controlBlock: a.from(u)
555
- }
556
- ], f.tapInternalKey = a.from(w)), c.addInput(f);
557
- }
558
- for (const i of e.outs)
559
- c.addOutput({
560
- script: i.script,
561
- value: i.value
562
- });
563
- return c.toHex();
564
- }
565
- async function $t(t) {
566
- const n = h(t.challengeAssertTxHex), e = P.fromHex(n);
567
- if (t.connectorParamsPerInput.length !== e.ins.length)
568
- throw new Error(
569
- `Expected ${e.ins.length} connector params, got ${t.connectorParamsPerInput.length}`
570
- );
571
- const o = await Promise.all(
572
- t.connectorParamsPerInput.map((s) => M(s))
573
- ), r = new k();
574
- r.setVersion(e.version), r.setLocktime(e.locktime);
575
- for (let s = 0; s < e.ins.length; s++) {
576
- const u = e.ins[s], c = t.prevouts[s];
577
- if (!c)
578
- throw new Error(`Missing prevout data for input ${s}`);
579
- const { script: i, controlBlock: p } = o[s], l = d(i), f = d(p);
580
- r.addInput({
581
- hash: u.hash,
582
- index: u.index,
583
- sequence: u.sequence,
584
- witnessUtxo: {
585
- script: a.from(d(h(c.script_pubkey))),
586
- value: c.value
587
- },
588
- tapLeafScript: [
589
- {
590
- leafVersion: 192,
591
- script: a.from(l),
592
- controlBlock: a.from(f)
593
- }
594
- ],
595
- tapInternalKey: a.from(w)
596
- });
597
- }
598
- for (const s of e.outs)
599
- r.addOutput({
600
- script: s.script,
601
- value: s.value
602
- });
603
- return r.toHex();
604
- }
605
- export {
606
- F as A,
607
- Q as B,
608
- vt as C,
609
- Z as D,
610
- V as E,
611
- yt as F,
612
- j as L,
613
- gt as M,
614
- dt as P,
615
- wt as S,
616
- Pt as T,
617
- J as W,
618
- St as a,
619
- bt as b,
620
- ht as c,
621
- mt as d,
622
- Et as e,
623
- Tt as f,
624
- It as g,
625
- Ht as h,
626
- At as i,
627
- Bt as j,
628
- $t as k,
629
- nt as l,
630
- Y as m,
631
- G as n,
632
- d as o,
633
- ft as p,
634
- lt as q,
635
- at as r,
636
- $ as s,
637
- h as t,
638
- D as u,
639
- x as v,
640
- pt as w,
641
- xt as x,
642
- tt as y,
643
- kt as z
644
- };
645
- //# sourceMappingURL=challengeAssert-DnnliaRt.js.map