@babylonlabs-io/ts-sdk 0.63.0 → 0.65.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 (69) hide show
  1. package/dist/{PeginManager-ozwQaRwj.js → PeginManager-BBl4xkWz.js} +5 -4
  2. package/dist/{PeginManager-ozwQaRwj.js.map → PeginManager-BBl4xkWz.js.map} +1 -1
  3. package/dist/{PeginManager-n__EsW8a.cjs → PeginManager-p-ajwSxG.cjs} +2 -2
  4. package/dist/{PeginManager-n__EsW8a.cjs.map → PeginManager-p-ajwSxG.cjs.map} +1 -1
  5. package/dist/{buildAndBroadcastRefund-DpfBZfLw.js → buildAndBroadcastRefund-C4LiPATK.js} +204 -204
  6. package/dist/buildAndBroadcastRefund-C4LiPATK.js.map +1 -0
  7. package/dist/buildAndBroadcastRefund-Daw5ZUKR.cjs +2 -0
  8. package/dist/buildAndBroadcastRefund-Daw5ZUKR.cjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +156 -145
  11. package/dist/{noPayout-oaUVsEjk.js → noPayout-BaZGRLD2.js} +2 -2
  12. package/dist/{noPayout-oaUVsEjk.js.map → noPayout-BaZGRLD2.js.map} +1 -1
  13. package/dist/{noPayout-CbxQqBw1.cjs → noPayout-CnQ1WLtr.cjs} +2 -2
  14. package/dist/{noPayout-CbxQqBw1.cjs.map → noPayout-CnQ1WLtr.cjs.map} +1 -1
  15. package/dist/reconstructPeginParams-BVA67Iv8.js +400 -0
  16. package/dist/reconstructPeginParams-BVA67Iv8.js.map +1 -0
  17. package/dist/reconstructPeginParams-BmUVK7F_.cjs +2 -0
  18. package/dist/reconstructPeginParams-BmUVK7F_.cjs.map +1 -0
  19. package/dist/{signPsbtsWithFallback-DC4rUCsy.js → signPsbtsWithFallback-Bb66DfY5.js} +2 -2
  20. package/dist/{signPsbtsWithFallback-DC4rUCsy.js.map → signPsbtsWithFallback-Bb66DfY5.js.map} +1 -1
  21. package/dist/{signPsbtsWithFallback-DbOmw8Ou.cjs → signPsbtsWithFallback-PTgWxsG3.cjs} +2 -2
  22. package/dist/{signPsbtsWithFallback-DbOmw8Ou.cjs.map → signPsbtsWithFallback-PTgWxsG3.cjs.map} +1 -1
  23. package/dist/tbv/core/index.cjs +1 -1
  24. package/dist/tbv/core/index.d.ts +3 -0
  25. package/dist/tbv/core/index.d.ts.map +1 -1
  26. package/dist/tbv/core/index.js +151 -140
  27. package/dist/tbv/core/managers/index.cjs +1 -1
  28. package/dist/tbv/core/managers/index.js +2 -2
  29. package/dist/tbv/core/primitives/index.cjs +1 -1
  30. package/dist/tbv/core/primitives/index.js +2 -2
  31. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +16 -2
  32. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  33. package/dist/tbv/core/recovery/__tests__/deriveHashlocksFromPrePegin.test.d.ts +10 -0
  34. package/dist/tbv/core/recovery/__tests__/deriveHashlocksFromPrePegin.test.d.ts.map +1 -0
  35. package/dist/tbv/core/recovery/__tests__/peginSizingIntegrity.test.d.ts +16 -0
  36. package/dist/tbv/core/recovery/__tests__/peginSizingIntegrity.test.d.ts.map +1 -0
  37. package/dist/tbv/core/recovery/__tests__/reconstructPeginParams.test.d.ts +14 -0
  38. package/dist/tbv/core/recovery/__tests__/reconstructPeginParams.test.d.ts.map +1 -0
  39. package/dist/tbv/core/recovery/deriveHashlocksFromPrePegin.d.ts +37 -0
  40. package/dist/tbv/core/recovery/deriveHashlocksFromPrePegin.d.ts.map +1 -0
  41. package/dist/tbv/core/recovery/index.d.ts +18 -0
  42. package/dist/tbv/core/recovery/index.d.ts.map +1 -0
  43. package/dist/tbv/core/recovery/peginParamsCandidates.d.ts +98 -0
  44. package/dist/tbv/core/recovery/peginParamsCandidates.d.ts.map +1 -0
  45. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts +112 -0
  46. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -0
  47. package/dist/tbv/core/recovery/recoveryErrors.d.ts +97 -0
  48. package/dist/tbv/core/recovery/recoveryErrors.d.ts.map +1 -0
  49. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +3 -2
  50. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  51. package/dist/tbv/core/services/index.cjs +1 -1
  52. package/dist/tbv/core/services/index.js +2 -2
  53. package/dist/tbv/index.cjs +1 -1
  54. package/dist/tbv/index.js +151 -140
  55. package/dist/verifyScriptPathSchnorrSignature-DPAd_qke.cjs +2 -0
  56. package/dist/verifyScriptPathSchnorrSignature-DPAd_qke.cjs.map +1 -0
  57. package/dist/{verifyScriptPathSchnorrSignature-XsICweGG.js → verifyScriptPathSchnorrSignature-i-koT139.js} +176 -170
  58. package/dist/verifyScriptPathSchnorrSignature-i-koT139.js.map +1 -0
  59. package/package.json +1 -1
  60. package/dist/buildAndBroadcastRefund-DpfBZfLw.js.map +0 -1
  61. package/dist/buildAndBroadcastRefund-DsCd90qJ.cjs +0 -2
  62. package/dist/buildAndBroadcastRefund-DsCd90qJ.cjs.map +0 -1
  63. package/dist/errors-BXzrXswV.js +0 -137
  64. package/dist/errors-BXzrXswV.js.map +0 -1
  65. package/dist/errors-BzBVottO.cjs +0 -2
  66. package/dist/errors-BzBVottO.cjs.map +0 -1
  67. package/dist/verifyScriptPathSchnorrSignature-B8zK1ctE.cjs +0 -2
  68. package/dist/verifyScriptPathSchnorrSignature-B8zK1ctE.cjs.map +0 -1
  69. package/dist/verifyScriptPathSchnorrSignature-XsICweGG.js.map +0 -1
@@ -1,11 +1,11 @@
1
- import { computeMinClaimValue as J, peginP2aAnchorOutput as ee, computeMinPeginFee as re, buildPeginTxFromPrePegin as ie, createPrePeginTransaction as se, validatePeginP2aAnchor as ue, tapInternalPubkey as te, createPayoutConnector as ce, computePayoutFeeFloor as ae } from "@babylonlabs-io/babylon-tbv-rust-wasm";
1
+ import { computeMinClaimValue as ee, peginP2aAnchorOutput as te, computeMinPeginFee as ie, buildPeginTxFromPrePegin as se, createPrePeginTransaction as ue, validatePeginP2aAnchor as ce, tapInternalPubkey as ne, createPayoutConnector as ae, computePayoutFeeFloor as le } from "@babylonlabs-io/babylon-tbv-rust-wasm";
2
2
  import { Buffer as p } from "buffer";
3
- import { Transaction as x, script as le, opcodes as he, payments as de, Psbt as C, crypto as pe } from "bitcoinjs-lib";
4
- import { c as V, d as Pe } from "./fundPeginTransaction-B2wyjqp0.js";
5
- import { s as g, u as _, h as y, j as ge, T as b, d as fe, S as T, X as H } from "./bitcoin-d9eaaZB_.js";
6
- import { D as O, P as L, b as R, c as U, M as K, d as N, e as we, A as ve, B as $e, V as Se, N as F } from "./constants-GjWXdaqV.js";
7
- import * as me from "@bitcoin-js/tiny-secp256k1-asmjs";
8
- async function xe(e, t) {
3
+ import { Transaction as x, script as he, opcodes as de, payments as pe, Psbt as C, crypto as Pe } from "bitcoinjs-lib";
4
+ import { c as T, d as ge } from "./fundPeginTransaction-B2wyjqp0.js";
5
+ import { s as g, u as k, h as y, j as fe, T as I, d as we, S as H, X as O } from "./bitcoin-d9eaaZB_.js";
6
+ import { D as L, P as R, b as U, c as K, M as N, d as F, e as ve, A as $e, B as me, V as Se, N as q } from "./constants-GjWXdaqV.js";
7
+ import * as xe from "@bitcoin-js/tiny-secp256k1-asmjs";
8
+ async function ye(e, t) {
9
9
  const n = t.pegInAmounts.length;
10
10
  if (e.htlcValues.length !== n)
11
11
  throw new Error(
@@ -19,7 +19,7 @@ async function xe(e, t) {
19
19
  throw new Error(
20
20
  `WASM Pre-PegIn returned non-positive depositorClaimValue ${e.depositorClaimValue}; expected > 0.`
21
21
  );
22
- const o = await J(
22
+ const o = await ee(
23
23
  // Must price the same graph version the builder constructed.
24
24
  t.vaultCoreVersion,
25
25
  t.numLocalChallengers,
@@ -32,12 +32,12 @@ async function xe(e, t) {
32
32
  throw new Error(
33
33
  `WASM Pre-PegIn depositorClaimValue ${e.depositorClaimValue} does not match the independently computed minimum claim value ${o} (vaultCoreVersion=${t.vaultCoreVersion}, numLocalChallengers=${t.numLocalChallengers}, numUniversalChallengers=${t.universalChallengerPubkeys.length}, councilQuorum=${t.councilQuorum}, councilSize=${t.councilSize}, feeRate=${t.feeRate}).`
34
34
  );
35
- const r = await ee(t.vaultCoreVersion), i = (r == null ? void 0 : r.value) ?? 0n, s = await re(
35
+ const r = await te(t.vaultCoreVersion), i = (r == null ? void 0 : r.value) ?? 0n, s = await ie(
36
36
  t.vaultCoreVersion,
37
37
  t.vaultKeeperPubkeys.length,
38
38
  t.universalChallengerPubkeys.length,
39
39
  t.minPeginFeeRate
40
- ), u = s + i, h = t.minPeginFeeRate * V;
40
+ ), u = s + i, h = t.minPeginFeeRate * T;
41
41
  for (let c = 0; c < n; c++) {
42
42
  const l = t.pegInAmounts[c], a = e.peginAmounts[c], f = e.htlcValues[c];
43
43
  if (a !== l)
@@ -59,7 +59,7 @@ async function xe(e, t) {
59
59
  );
60
60
  if (d > h)
61
61
  throw new Error(
62
- `WASM Pre-PegIn implied reserve for HTLC[${c}] (${d} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${V} vbytes); htlcValue ${f} appears grossly inflated.`
62
+ `WASM Pre-PegIn implied reserve for HTLC[${c}] (${d} sat) exceeds the plausibility cap ${h} sat (minPeginFeeRate=${t.minPeginFeeRate} × ${T} vbytes); htlcValue ${f} appears grossly inflated.`
63
63
  );
64
64
  if (d !== u)
65
65
  throw new Error(
@@ -68,27 +68,32 @@ async function xe(e, t) {
68
68
  }
69
69
  return s;
70
70
  }
71
- function ye(e, t, n) {
71
+ class b extends Error {
72
+ constructor(t) {
73
+ super(t), this.name = "HtlcOutputMismatchError";
74
+ }
75
+ }
76
+ function Ee(e, t, n) {
72
77
  if (e.length < t.length)
73
- throw new Error(
78
+ throw new b(
74
79
  `Encoded Pre-PegIn tx has ${e.length} output(s), fewer than the ${t.length} HTLC output(s) the cross-check validated.`
75
80
  );
76
81
  for (let o = 0; o < t.length; o++) {
77
82
  const r = BigInt(e[o].value);
78
83
  if (r !== t[o])
79
- throw new Error(
84
+ throw new b(
80
85
  `Encoded Pre-PegIn HTLC output[${o}] value ${r} does not match the cross-checked htlcValue ${t[o]}; the funded/signed tx would not pay the validated amount.`
81
86
  );
82
87
  const i = e[o].script.toString("hex").toLowerCase(), s = n[o].toLowerCase();
83
88
  if (i !== s)
84
- throw new Error(
89
+ throw new b(
85
90
  `Encoded Pre-PegIn HTLC output[${o}] scriptPubKey ${i} does not match the cross-checked htlcScriptPubKey ${s}.`
86
91
  );
87
92
  }
88
93
  }
89
- const q = 64, Ee = /^[0-9a-fA-F]+$/;
90
- async function at(e) {
91
- const t = ne(e.authAnchorHash), n = await se({
94
+ const M = 64, Ce = /^[0-9a-fA-F]+$/;
95
+ async function lt(e) {
96
+ const t = oe(e.authAnchorHash), n = await ue({
92
97
  txGraphVersion: e.vaultCoreVersion,
93
98
  depositorPubkey: e.depositorPubkey,
94
99
  vaultProviderPubkey: e.vaultProviderPubkey,
@@ -104,8 +109,8 @@ async function at(e) {
104
109
  councilSize: e.councilSize,
105
110
  network: e.network,
106
111
  authAnchorHash: t
107
- }), o = await xe(n, e), r = Pe(n.txHex);
108
- ye(
112
+ }), o = await ye(n, e), r = ge(n.txHex);
113
+ Ee(
109
114
  r.outputs,
110
115
  n.htlcValues,
111
116
  n.htlcScriptPubKeys
@@ -126,17 +131,17 @@ async function at(e) {
126
131
  minPeginFee: o
127
132
  };
128
133
  }
129
- function ne(e) {
134
+ function oe(e) {
130
135
  if (e === void 0) return;
131
136
  const t = e.startsWith("0x") || e.startsWith("0X") ? e.slice(2) : e;
132
- if (t.length !== q || !Ee.test(t))
137
+ if (t.length !== M || !Ce.test(t))
133
138
  throw new Error(
134
- `authAnchorHash must be 32-byte hex (${q} chars, no 0x prefix); got length ${t.length}`
139
+ `authAnchorHash must be 32-byte hex (${M} chars, no 0x prefix); got length ${t.length}`
135
140
  );
136
141
  return t.toLowerCase();
137
142
  }
138
- async function lt(e) {
139
- const t = await ie(
143
+ async function ht(e) {
144
+ const t = await se(
140
145
  {
141
146
  txGraphVersion: e.prePeginParams.vaultCoreVersion,
142
147
  depositorPubkey: e.prePeginParams.depositorPubkey,
@@ -152,7 +157,7 @@ async function lt(e) {
152
157
  councilQuorum: e.prePeginParams.councilQuorum,
153
158
  councilSize: e.prePeginParams.councilSize,
154
159
  network: e.prePeginParams.network,
155
- authAnchorHash: ne(
160
+ authAnchorHash: oe(
156
161
  e.prePeginParams.authAnchorHash
157
162
  )
158
163
  },
@@ -160,25 +165,25 @@ async function lt(e) {
160
165
  e.fundedPrePeginTxHex,
161
166
  e.htlcVout
162
167
  );
163
- return await be(t, e), {
168
+ return await Ie(t, e), {
164
169
  txHex: t.txHex,
165
170
  txid: t.txid,
166
171
  vaultScriptPubKey: t.vaultScriptPubKey,
167
172
  vaultValue: t.vaultValue
168
173
  };
169
174
  }
170
- const Ce = 2, Ae = 1;
171
- async function be(e, t) {
175
+ const Ae = 2, be = 1;
176
+ async function Ie(e, t) {
172
177
  const n = t.prePeginParams.vaultCoreVersion;
173
- await ue(n, e.txHex);
174
- const o = await ee(n), r = Ce + (o ? 1 : 0), i = x.fromHex(g(e.txHex));
178
+ await ce(n, e.txHex);
179
+ const o = await te(n), r = Ae + (o ? 1 : 0), i = x.fromHex(g(e.txHex));
175
180
  if (i.ins.length !== 1)
176
181
  throw new Error(
177
182
  `PegIn tx has ${i.ins.length} input(s), expected exactly 1 (the Pre-PegIn HTLC outpoint).`
178
183
  );
179
184
  const s = x.fromHex(
180
185
  g(t.fundedPrePeginTxHex)
181
- ).getId(), u = _(
186
+ ).getId(), u = k(
182
187
  new Uint8Array(i.ins[0].hash).slice().reverse()
183
188
  );
184
189
  if (u !== s)
@@ -215,32 +220,32 @@ async function be(e, t) {
215
220
  throw new Error(
216
221
  `Encoded PegIn txid ${f} does not match the WASM-reported txid ${e.txid}.`
217
222
  );
218
- const d = await J(
223
+ const d = await ee(
219
224
  n,
220
225
  t.prePeginParams.numLocalChallengers,
221
226
  t.prePeginParams.universalChallengerPubkeys.length,
222
227
  t.prePeginParams.councilQuorum,
223
228
  t.prePeginParams.councilSize,
224
229
  t.prePeginParams.feeRate
225
- ), S = i.outs[Ae];
226
- if (BigInt(S.value) !== d)
230
+ ), m = i.outs[be];
231
+ if (BigInt(m.value) !== d)
227
232
  throw new Error(
228
- `Encoded PegIn depositor-claim output value ${S.value} does not match the independently computed claim value ${d} for vaultCoreVersion ${n}.`
233
+ `Encoded PegIn depositor-claim output value ${m.value} does not match the independently computed claim value ${d} for vaultCoreVersion ${n}.`
229
234
  );
230
- const w = Ie(
235
+ const w = _e(
231
236
  t.prePeginParams.depositorPubkey
232
237
  );
233
- if (!S.script.equals(w))
238
+ if (!m.script.equals(w))
234
239
  throw new Error(
235
- `Encoded PegIn depositor-claim output scriptPubKey ${S.script.toString("hex")} does not pay to the depositor's claim script (expected ${w.toString("hex")}).`
240
+ `Encoded PegIn depositor-claim output scriptPubKey ${m.script.toString("hex")} does not pay to the depositor's claim script (expected ${w.toString("hex")}).`
236
241
  );
237
242
  }
238
- function Ie(e) {
239
- const t = le.compile([
243
+ function _e(e) {
244
+ const t = he.compile([
240
245
  p.from(y(e)),
241
- he.OP_CHECKSIG
242
- ]), { output: n } = de.p2tr({
243
- internalPubkey: p.from(te),
246
+ de.OP_CHECKSIG
247
+ ]), { output: n } = pe.p2tr({
248
+ internalPubkey: p.from(ne),
244
249
  scriptTree: { output: t }
245
250
  });
246
251
  if (!n)
@@ -249,8 +254,8 @@ function Ie(e) {
249
254
  );
250
255
  return n;
251
256
  }
252
- async function _e(e) {
253
- const t = await ce(
257
+ async function ke(e) {
258
+ const t = await ae(
254
259
  {
255
260
  txGraphVersion: e.vaultCoreVersion,
256
261
  depositor: e.depositor,
@@ -269,23 +274,23 @@ async function _e(e) {
269
274
  payoutControlBlock: t.payoutControlBlock
270
275
  };
271
276
  }
272
- const ke = 256, Ve = 1500, B = 256, M = 0xffffffffn, Te = 500, He = 55, Oe = 34;
273
- function Le(e) {
274
- if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > M)
277
+ const Ve = 256, Te = 1500, B = 256, W = 0xffffffffn, He = 500, Oe = 55, Le = 34;
278
+ function Re(e) {
279
+ if (typeof e.protocolFeeRate != "bigint" || e.protocolFeeRate <= 0n || e.protocolFeeRate > W)
275
280
  throw new Error(
276
- `protocolFeeRate must be in [1, ${M}] sat/vB, got ${e.protocolFeeRate}`
281
+ `protocolFeeRate must be in [1, ${W}] sat/vB, got ${e.protocolFeeRate}`
277
282
  );
278
283
  for (const [t, n, o, r] of [
279
284
  [
280
285
  "keepers",
281
286
  e.numVaultKeepers,
282
- ke,
287
+ Ve,
283
288
  "fee-floor model limit"
284
289
  ],
285
290
  [
286
291
  "challengers",
287
292
  e.numUniversalChallengers,
288
- Ve,
293
+ Te,
289
294
  "protocol maximum"
290
295
  ]
291
296
  ])
@@ -298,13 +303,13 @@ function Le(e) {
298
303
  `councilSize must be an integer in [1, ${B}], got ${e.councilSize}`
299
304
  );
300
305
  }
301
- async function Re(e, t) {
302
- const { implicitFeeSats: n, out0Len: o, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(n), u = Math.max(0, o - Oe), h = Te + He * i + u, c = e.protocolFeeRate * BigInt(h);
306
+ async function Ue(e, t) {
307
+ const { implicitFeeSats: n, out0Len: o, out1Len: r } = t, i = e.numVaultKeepers + e.numUniversalChallengers, s = BigInt(n), u = Math.max(0, o - Le), h = He + Oe * i + u, c = e.protocolFeeRate * BigInt(h);
303
308
  if (s > c)
304
309
  throw new Error(
305
310
  `Payout implicit fee ${n} sats exceeds the safety cap of ${c} sats (${e.protocolFeeRate} sat/vB x ${h} vB for ${i} participants); refusing to sign payout.`
306
311
  );
307
- const l = await ae(
312
+ const l = await le(
308
313
  e.vaultCoreVersion,
309
314
  e.numVaultKeepers,
310
315
  e.numUniversalChallengers,
@@ -319,23 +324,23 @@ async function Re(e, t) {
319
324
  `Payout implicit fee ${n} sats is below the floor of ${l} sats (the smallest fee any known vault-provider build produces for this shape); refusing to sign payout.`
320
325
  );
321
326
  }
322
- const Ue = 22, Ke = 34, Ne = 34, Fe = 25, qe = 23;
327
+ const Ke = 22, Ne = 34, Fe = 34, qe = 25, Me = 23;
323
328
  function Be(e) {
324
- return e.length === Ue * 2 && e.startsWith("0014");
325
- }
326
- function Me(e) {
327
- return e.length === Ke * 2 && e.startsWith("0020");
329
+ return e.length === Ke * 2 && e.startsWith("0014");
328
330
  }
329
331
  function We(e) {
330
- return e.length === Ne * 2 && e.startsWith("5120");
332
+ return e.length === Ne * 2 && e.startsWith("0020");
331
333
  }
332
334
  function Xe(e) {
333
- return e.length === Fe * 2 && e.startsWith("76a914") && e.endsWith("88ac");
335
+ return e.length === Fe * 2 && e.startsWith("5120");
334
336
  }
335
337
  function ze(e) {
336
- return e.length === qe * 2 && e.startsWith("a914") && e.endsWith("87");
338
+ return e.length === qe * 2 && e.startsWith("76a914") && e.endsWith("88ac");
339
+ }
340
+ function De(e) {
341
+ return e.length === Me * 2 && e.startsWith("a914") && e.endsWith("87");
337
342
  }
338
- function W(e, t) {
343
+ function X(e, t) {
339
344
  const n = g(e).toLowerCase();
340
345
  if (n.length === 0)
341
346
  throw new Error(`${t} is empty`);
@@ -345,13 +350,13 @@ function W(e, t) {
345
350
  throw new Error(
346
351
  `${t} is an OP_RETURN output, which is provably unspendable`
347
352
  );
348
- if (!We(n) && !Be(n) && !Me(n) && !Xe(n) && !ze(n))
353
+ if (!Xe(n) && !Be(n) && !We(n) && !ze(n) && !De(n))
349
354
  throw new Error(
350
355
  `${t} is not a standard scriptPubKey (expected P2TR, P2WPKH, P2WSH, P2PKH, or P2SH; got ${n.length / 2} bytes: ${n})`
351
356
  );
352
357
  }
353
- const X = 3;
354
- async function ht(e) {
358
+ const z = 3;
359
+ async function dt(e) {
355
360
  const t = {
356
361
  vaultCoreVersion: e.vaultCoreVersion,
357
362
  numVaultKeepers: e.vaultKeeperBtcPubkeys.length,
@@ -359,43 +364,43 @@ async function ht(e) {
359
364
  councilSize: e.councilSize,
360
365
  protocolFeeRate: e.protocolFeeRate
361
366
  };
362
- Le(t);
367
+ Re(t);
363
368
  const n = x.fromHex(g(e.payoutTxHex)), o = x.fromHex(g(e.peginTxHex)), r = x.fromHex(g(e.assertTxHex));
364
- if (n.ins.length !== O)
369
+ if (n.ins.length !== L)
365
370
  throw new Error(
366
- `Payout transaction must have exactly ${O} inputs, got ${n.ins.length}`
371
+ `Payout transaction must have exactly ${L} inputs, got ${n.ins.length}`
367
372
  );
368
- if (n.version !== L)
373
+ if (n.version !== R)
369
374
  throw new Error(
370
- `Payout transaction version ${n.version} must be ${L}; refusing to sign payout.`
375
+ `Payout transaction version ${n.version} must be ${R}; refusing to sign payout.`
371
376
  );
372
- if (n.locktime !== R)
377
+ if (n.locktime !== U)
373
378
  throw new Error(
374
- `Payout transaction locktime ${n.locktime} must be ${R}; refusing to sign payout.`
379
+ `Payout transaction locktime ${n.locktime} must be ${U}; refusing to sign payout.`
375
380
  );
376
- const i = z(
381
+ const i = D(
377
382
  n.ins[0],
378
383
  0,
379
384
  o,
380
385
  "PegIn",
381
- we
386
+ ve
382
387
  );
383
388
  if (n.ins[0].sequence !== e.timelockPegin)
384
389
  throw new Error(
385
390
  `Payout input 0 sequence ${n.ins[0].sequence} must equal the PegIn CSV timelock ${e.timelockPegin}; refusing to sign payout.`
386
391
  );
387
- const s = z(
392
+ const s = D(
388
393
  n.ins[1],
389
394
  1,
390
395
  r,
391
396
  "Assert",
392
- ve
397
+ $e
393
398
  );
394
399
  if (n.ins[1].sequence !== e.timelockAssert)
395
400
  throw new Error(
396
401
  `Payout input 1 sequence ${n.ins[1].sequence} must equal the Assert CSV timelock ${e.timelockAssert}; refusing to sign payout.`
397
402
  );
398
- const { out0Len: u, out1Len: h } = Ge(
403
+ const { out0Len: u, out1Len: h } = Ye(
399
404
  n,
400
405
  i.value,
401
406
  e
@@ -407,12 +412,12 @@ async function ht(e) {
407
412
  `Payout outputs (${l} sats) exceed inputs (${c} sats); invalid transaction.`
408
413
  );
409
414
  const a = c - l;
410
- await Re(t, {
415
+ await Ue(t, {
411
416
  implicitFeeSats: a,
412
417
  out0Len: u,
413
418
  out1Len: h
414
419
  });
415
- const f = await _e({
420
+ const f = await ke({
416
421
  vaultCoreVersion: e.vaultCoreVersion,
417
422
  depositor: e.depositorBtcPubkey,
418
423
  vaultProvider: e.vaultProviderBtcPubkey,
@@ -422,7 +427,7 @@ async function ht(e) {
422
427
  network: e.network
423
428
  });
424
429
  return {
425
- psbtHex: De(
430
+ psbtHex: Ge(
426
431
  n,
427
432
  i,
428
433
  s,
@@ -430,8 +435,8 @@ async function ht(e) {
430
435
  )
431
436
  };
432
437
  }
433
- function z(e, t, n, o, r) {
434
- const i = _(
438
+ function D(e, t, n, o, r) {
439
+ const i = k(
435
440
  new Uint8Array(e.hash).slice().reverse()
436
441
  ), s = n.getId();
437
442
  if (i !== s || e.index !== r)
@@ -445,7 +450,7 @@ function z(e, t, n, o, r) {
445
450
  );
446
451
  return u;
447
452
  }
448
- function De(e, t, n, o) {
453
+ function Ge(e, t, n, o) {
449
454
  const r = new C();
450
455
  r.setVersion(e.version), r.setLocktime(e.locktime);
451
456
  const [i, s] = e.ins;
@@ -459,14 +464,14 @@ function De(e, t, n, o) {
459
464
  },
460
465
  tapLeafScript: [
461
466
  {
462
- leafVersion: b,
467
+ leafVersion: I,
463
468
  script: p.from(y(o.payoutScript)),
464
469
  controlBlock: p.from(
465
470
  y(o.payoutControlBlock)
466
471
  )
467
472
  }
468
473
  ],
469
- tapInternalKey: p.from(te)
474
+ tapInternalKey: p.from(ne)
470
475
  // sighashType omitted - defaults to SIGHASH_DEFAULT (0x00) for Taproot
471
476
  }), r.addInput({
472
477
  hash: s.hash,
@@ -484,16 +489,16 @@ function De(e, t, n, o) {
484
489
  });
485
490
  return r.toHex();
486
491
  }
487
- function D(e, t) {
492
+ function G(e, t) {
488
493
  const n = g(e).toLowerCase(), o = g(
489
- fe(t)
494
+ we(t)
490
495
  ).toLowerCase();
491
496
  return n === o ? [n] : [n, o];
492
497
  }
493
- function G(e, t) {
498
+ function Y(e, t) {
494
499
  return t.some((n) => e.equals(p.from(n, "hex")));
495
500
  }
496
- function Ge(e, t, n) {
501
+ function Ye(e, t, n) {
497
502
  const {
498
503
  claimerBtcPubkey: o,
499
504
  vaultProviderBtcPubkey: r,
@@ -504,27 +509,27 @@ function Ge(e, t, n) {
504
509
  vkClaimerPayoutScriptPubKeys: c,
505
510
  vpCommissionScriptPubKey: l
506
511
  } = n;
507
- if (!ge(u))
512
+ if (!fe(u))
508
513
  throw new Error("Invalid registeredPayoutScriptPubKey: not valid hex");
509
- const a = g(o).toLowerCase(), f = g(r).toLowerCase(), d = g(i).toLowerCase(), S = s.map(
510
- (m) => g(m).toLowerCase()
514
+ const a = g(o).toLowerCase(), f = g(r).toLowerCase(), d = g(i).toLowerCase(), m = s.map(
515
+ (S) => g(S).toLowerCase()
511
516
  );
512
517
  let w, P, v;
513
518
  if (a === f)
514
519
  w = "vp-claimer", P = Se, v = [g(u)];
515
520
  else if (a === d)
516
- w = "depositor-as-claimer", P = F, v = [g(u)];
517
- else if (S.includes(a)) {
518
- w = "vk-claimer", P = F;
519
- const m = c[a];
520
- if (m === void 0)
521
+ w = "depositor-as-claimer", P = q, v = [g(u)];
522
+ else if (m.includes(a)) {
523
+ w = "vk-claimer", P = q;
524
+ const S = c[a];
525
+ if (S === void 0)
521
526
  throw new Error(
522
527
  `No registered payout script resolved for vault keeper claimer ${a}`
523
528
  );
524
- W(
525
- m,
529
+ X(
530
+ S,
526
531
  `Vault keeper payout script for claimer ${a}`
527
- ), v = D(m, a);
532
+ ), v = G(S, a);
528
533
  } else
529
534
  throw new Error(
530
535
  `Unknown claimer pubkey ${a}: not VP, depositor, or a registered vault keeper`
@@ -533,49 +538,49 @@ function Ge(e, t, n) {
533
538
  throw new Error(
534
539
  `Payout transaction has ${e.outs.length} output(s), expected exactly ${P} for role ${w}.`
535
540
  );
536
- if (!G(e.outs[0].script, v))
541
+ if (!Y(e.outs[0].script, v))
537
542
  throw new Error(
538
543
  `Payout transaction output 0 does not pay the expected scriptPubKey for role ${w}. Accepted: ${v.join(" or ")}; got ${e.outs[0].script.toString("hex")}`
539
544
  );
540
545
  const A = P - 1;
541
- if (e.outs[A].value !== U)
546
+ if (e.outs[A].value !== K)
542
547
  throw new Error(
543
- `Payout CPFP anchor (out ${A}) value ${e.outs[A].value} sats must equal ${U} sats`
548
+ `Payout CPFP anchor (out ${A}) value ${e.outs[A].value} sats must equal ${K} sats`
544
549
  );
545
550
  if (w === "vp-claimer") {
546
- W(
551
+ X(
547
552
  l,
548
553
  "Vault provider commission payout script"
549
554
  );
550
- const m = D(
555
+ const S = G(
551
556
  l,
552
557
  f
553
558
  );
554
- if (!G(e.outs[1].script, m))
559
+ if (!Y(e.outs[1].script, S))
555
560
  throw new Error(
556
- `Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${m.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
561
+ `Payout transaction output 1 does not pay the vault provider's commission scriptPubKey. Accepted: ${S.join(" or ")}; got ${e.outs[1].script.toString("hex")}`
557
562
  );
558
- if (!Number.isInteger(h) || h < 0 || h >= K)
563
+ if (!Number.isInteger(h) || h < 0 || h >= N)
559
564
  throw new Error(
560
- `commissionBps must be an integer in [0, ${K}), got ${h}`
565
+ `commissionBps must be an integer in [0, ${N}), got ${h}`
561
566
  );
562
- const k = Math.floor(
563
- t * h / $e
567
+ const V = Math.floor(
568
+ t * h / me
564
569
  );
565
- if (e.outs[1].value > k)
570
+ if (e.outs[1].value > V)
566
571
  throw new Error(
567
- `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${k} sats (${h} bps of peginValue=${t})`
572
+ `Payout VP commission (out 1) value ${e.outs[1].value} sats exceeds cap ${V} sats (${h} bps of peginValue=${t})`
568
573
  );
569
574
  }
570
575
  const E = e.outs[0].script.length;
571
- if (E === 0 || E > N)
576
+ if (E === 0 || E > F)
572
577
  throw new Error(
573
- `Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${N}]; refusing to sign payout.`
578
+ `Payout receiver scriptPubKey length ${E} is outside the contract's registration cap [1, ${F}]; refusing to sign payout.`
574
579
  );
575
- const oe = w === "vp-claimer" ? e.outs[1].script.length : void 0;
576
- return { out0Len: E, out1Len: oe };
580
+ const re = w === "vp-claimer" ? e.outs[1].script.length : void 0;
581
+ return { out0Len: E, out1Len: re };
577
582
  }
578
- function dt(e, t, n = 0) {
583
+ function pt(e, t, n = 0) {
579
584
  const o = C.fromHex(e);
580
585
  if (n >= o.data.inputs.length)
581
586
  throw new Error(
@@ -586,33 +591,33 @@ function dt(e, t, n = 0) {
586
591
  const i = y(t);
587
592
  for (const s of r.tapScriptSig)
588
593
  if (s.pubkey.equals(p.from(i)))
589
- return Y(s.signature, n);
594
+ return Q(s.signature, n);
590
595
  throw new Error(
591
596
  `No signature found for depositor pubkey: ${t} at input ${n}`
592
597
  );
593
598
  }
594
599
  if (r.finalScriptWitness && r.finalScriptWitness.length > 0) {
595
- const i = Ye(r.finalScriptWitness);
596
- if (i.length !== X)
600
+ const i = Qe(r.finalScriptWitness);
601
+ if (i.length !== z)
597
602
  throw new Error(
598
- `Unexpected finalized witness stack size at input ${n}: expected ${X} items (signature, script, controlBlock), got ${i.length}`
603
+ `Unexpected finalized witness stack size at input ${n}: expected ${z} items (signature, script, controlBlock), got ${i.length}`
599
604
  );
600
- return Y(i[0], n);
605
+ return Q(i[0], n);
601
606
  }
602
607
  throw new Error(
603
608
  `No tapScriptSig or finalScriptWitness found in signed PSBT at input ${n}`
604
609
  );
605
610
  }
606
- function Y(e, t) {
611
+ function Q(e, t) {
607
612
  if (e.length === 64)
608
- return _(new Uint8Array(e));
613
+ return k(new Uint8Array(e));
609
614
  throw e.length === 65 ? new Error(
610
615
  `Unexpected sighash byte 0x${e[64].toString(16).padStart(2, "0")} at input ${t}. Expected implicit SIGHASH_DEFAULT as a 64-byte signature.`
611
616
  ) : new Error(
612
617
  `Unexpected signature length at input ${t}: ${e.length}`
613
618
  );
614
619
  }
615
- function Ye(e) {
620
+ function Qe(e) {
616
621
  const t = [];
617
622
  let n = 0;
618
623
  const o = (s) => {
@@ -655,7 +660,7 @@ class $ extends Error {
655
660
  ), this.name = "PsbtSubstitutionError";
656
661
  }
657
662
  }
658
- function Q(e, t) {
663
+ function Z(e, t) {
659
664
  try {
660
665
  return C.fromHex(t);
661
666
  } catch (n) {
@@ -663,16 +668,16 @@ function Q(e, t) {
663
668
  throw new Error(`Failed to parse ${e} PSBT: ${o}`);
664
669
  }
665
670
  }
666
- const Qe = 8;
667
- function I(e) {
668
- return `${e.toString("hex").slice(0, Qe)}…`;
671
+ const Ze = 8;
672
+ function _(e) {
673
+ return `${e.toString("hex").slice(0, Ze)}…`;
669
674
  }
670
- function Z(e) {
675
+ function j(e) {
671
676
  const t = p.from(e).reverse();
672
- return I(t);
677
+ return _(t);
673
678
  }
674
- function pt(e) {
675
- const t = Q("requested", e.requestedPsbtHex), n = Q("returned", e.returnedPsbtHex);
679
+ function Pt(e) {
680
+ const t = Z("requested", e.requestedPsbtHex), n = Z("returned", e.returnedPsbtHex);
676
681
  if (t.version !== n.version)
677
682
  throw new $(
678
683
  `tx version differs (requested=${t.version}, returned=${n.version})`
@@ -693,7 +698,7 @@ function pt(e) {
693
698
  const r = t.txInputs[o], i = n.txInputs[o];
694
699
  if (!r.hash.equals(i.hash))
695
700
  throw new $(
696
- `input ${o} prevout txid differs (requested=${Z(r.hash)}, returned=${Z(i.hash)})`
701
+ `input ${o} prevout txid differs (requested=${j(r.hash)}, returned=${j(i.hash)})`
697
702
  );
698
703
  if (r.index !== i.index)
699
704
  throw new $(
@@ -708,7 +713,7 @@ function pt(e) {
708
713
  const r = t.txOutputs[o], i = n.txOutputs[o];
709
714
  if (!r.script.equals(i.script))
710
715
  throw new $(
711
- `output ${o} scriptPubKey differs (requested=${I(r.script)}, returned=${I(i.script)})`
716
+ `output ${o} scriptPubKey differs (requested=${_(r.script)}, returned=${_(i.script)})`
712
717
  );
713
718
  if (r.value !== i.value)
714
719
  throw new $(
@@ -716,39 +721,39 @@ function pt(e) {
716
721
  );
717
722
  }
718
723
  }
719
- const j = 253, Ze = 254, je = 65535, Je = 4294967295;
720
- function et(e) {
721
- if (e < j)
724
+ const J = 253, je = 254, Je = 65535, et = 4294967295;
725
+ function tt(e) {
726
+ if (e < J)
722
727
  return p.from([e]);
723
- if (e <= je) {
728
+ if (e <= Je) {
724
729
  const t = p.alloc(2);
725
- return t.writeUInt16LE(e), p.concat([p.from([j]), t]);
730
+ return t.writeUInt16LE(e), p.concat([p.from([J]), t]);
726
731
  }
727
- if (e <= Je) {
732
+ if (e <= et) {
728
733
  const t = p.alloc(4);
729
- return t.writeUInt32LE(e), p.concat([p.from([Ze]), t]);
734
+ return t.writeUInt32LE(e), p.concat([p.from([je]), t]);
730
735
  }
731
736
  throw new Error(`Script too large to encode as CompactSize: ${e} bytes`);
732
737
  }
733
- const tt = "TapLeaf";
734
- function nt(e, t) {
738
+ const nt = "TapLeaf";
739
+ function ot(e, t) {
735
740
  const n = p.concat([
736
741
  p.from([e]),
737
- et(t.length),
742
+ tt(t.length),
738
743
  p.from(t)
739
744
  ]);
740
- return pe.taggedHash(tt, n);
745
+ return Pe.taggedHash(nt, n);
741
746
  }
742
- function Pt(e) {
747
+ function gt(e) {
743
748
  const { requestedPsbtHex: t, signatureHex: n, signerXOnlyPubkeyHex: o, inputIndex: r } = e, i = g(n);
744
- if (i.length !== T)
749
+ if (i.length !== H)
745
750
  throw new Error(
746
- `Schnorr signature for input ${r} must be ${T} hex chars (64 bytes), got ${i.length}.`
751
+ `Schnorr signature for input ${r} must be ${H} hex chars (64 bytes), got ${i.length}.`
747
752
  );
748
753
  const s = g(o);
749
- if (s.length !== H)
754
+ if (s.length !== O)
750
755
  throw new Error(
751
- `Signer x-only pubkey for input ${r} must be ${H} hex chars (32 bytes), got ${s.length}.`
756
+ `Signer x-only pubkey for input ${r} must be ${O} hex chars (32 bytes), got ${s.length}.`
752
757
  );
753
758
  const u = C.fromHex(t);
754
759
  if (r < 0 || r >= u.data.inputs.length)
@@ -770,25 +775,25 @@ function Pt(e) {
770
775
  `Cannot verify signature: input ${r} of the requested PSBT must have exactly one tapLeafScript, got ${(l == null ? void 0 : l.length) ?? 0}.`
771
776
  );
772
777
  const a = l[0];
773
- if (a.leafVersion !== b)
778
+ if (a.leafVersion !== I)
774
779
  throw new Error(
775
- `Cannot verify signature: input ${r} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${b.toString(16)}.`
780
+ `Cannot verify signature: input ${r} tapLeafScript has leaf version 0x${a.leafVersion.toString(16)}, expected 0x${I.toString(16)}.`
776
781
  );
777
- const f = nt(a.leafVersion, a.script), d = new x();
782
+ const f = ot(a.leafVersion, a.script), d = new x();
778
783
  d.version = u.version, d.locktime = u.locktime;
779
784
  for (const P of u.txInputs)
780
785
  d.addInput(P.hash, P.index, P.sequence);
781
786
  for (const P of u.txOutputs)
782
787
  d.addOutput(P.script, P.value);
783
- const S = d.hashForWitnessV1(
788
+ const m = d.hashForWitnessV1(
784
789
  r,
785
790
  h,
786
791
  c,
787
792
  x.SIGHASH_DEFAULT,
788
793
  f
789
794
  );
790
- if (!me.verifySchnorr(
791
- S,
795
+ if (!xe.verifySchnorr(
796
+ m,
792
797
  y(s),
793
798
  y(i)
794
799
  ))
@@ -797,15 +802,16 @@ function Pt(e) {
797
802
  );
798
803
  }
799
804
  export {
805
+ b as H,
800
806
  $ as P,
801
- at as a,
802
- lt as b,
803
- ht as c,
804
- pt as d,
805
- dt as e,
806
- Pt as f,
807
- _e as g,
808
- ye as h,
809
- ne as n
807
+ lt as a,
808
+ ht as b,
809
+ dt as c,
810
+ Pt as d,
811
+ pt as e,
812
+ gt as f,
813
+ ke as g,
814
+ Ee as h,
815
+ oe as n
810
816
  };
811
- //# sourceMappingURL=verifyScriptPathSchnorrSignature-XsICweGG.js.map
817
+ //# sourceMappingURL=verifyScriptPathSchnorrSignature-i-koT139.js.map