@babylonlabs-io/ts-sdk 5.1.0 → 6.0.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 (71) hide show
  1. package/dist/{PayoutManager-BHeiLQ1j.js → PayoutManager-3-MzBVLj.js} +2 -2
  2. package/dist/{PayoutManager-BHeiLQ1j.js.map → PayoutManager-3-MzBVLj.js.map} +1 -1
  3. package/dist/{PayoutManager-B5nR0x1t.cjs → PayoutManager-PQqeqX41.cjs} +2 -2
  4. package/dist/{PayoutManager-B5nR0x1t.cjs.map → PayoutManager-PQqeqX41.cjs.map} +1 -1
  5. package/dist/{PeginManager-6ghglb4r.cjs → PeginManager-D_ZUfbIy.cjs} +2 -2
  6. package/dist/{PeginManager-6ghglb4r.cjs.map → PeginManager-D_ZUfbIy.cjs.map} +1 -1
  7. package/dist/{PeginManager-CXNqbgA4.js → PeginManager-m3IlM4wS.js} +4 -4
  8. package/dist/{PeginManager-CXNqbgA4.js.map → PeginManager-m3IlM4wS.js.map} +1 -1
  9. package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs → buildAndBroadcastReclaim-CMjlyooo.cjs} +2 -2
  10. package/dist/{buildAndBroadcastReclaim-Cf05JFP-.cjs.map → buildAndBroadcastReclaim-CMjlyooo.cjs.map} +1 -1
  11. package/dist/{buildAndBroadcastReclaim-Acz637Vf.js → buildAndBroadcastReclaim-D8l-QJWo.js} +793 -772
  12. package/dist/{buildAndBroadcastReclaim-Acz637Vf.js.map → buildAndBroadcastReclaim-D8l-QJWo.js.map} +1 -1
  13. package/dist/{challengeAssert-CuX_8Twt.cjs → challengeAssert-DlzX_kjF.cjs} +2 -2
  14. package/dist/{challengeAssert-CuX_8Twt.cjs.map → challengeAssert-DlzX_kjF.cjs.map} +1 -1
  15. package/dist/{challengeAssert-D_lRvsO0.js → challengeAssert-hpOHGPXX.js} +2 -2
  16. package/dist/{challengeAssert-D_lRvsO0.js.map → challengeAssert-hpOHGPXX.js.map} +1 -1
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.js +312 -309
  19. package/dist/index.js.map +1 -1
  20. package/dist/peginState-B4t_PDgj.cjs.map +1 -1
  21. package/dist/peginState-CXdbSit3.js.map +1 -1
  22. package/dist/tbv/core/index.cjs +1 -1
  23. package/dist/tbv/core/index.js +306 -303
  24. package/dist/tbv/core/index.js.map +1 -1
  25. package/dist/tbv/core/managers/index.cjs +1 -1
  26. package/dist/tbv/core/managers/index.js +2 -2
  27. package/dist/tbv/core/primitives/index.cjs +1 -1
  28. package/dist/tbv/core/primitives/index.d.ts +5 -0
  29. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  30. package/dist/tbv/core/primitives/index.js +31 -29
  31. package/dist/tbv/core/primitives/index.js.map +1 -1
  32. package/dist/tbv/core/primitives/psbt/__tests__/signetPeginHashlockSpend.fixture.d.ts +19 -0
  33. package/dist/tbv/core/primitives/psbt/__tests__/signetPeginHashlockSpend.fixture.d.ts.map +1 -0
  34. package/dist/tbv/core/primitives/psbt/__tests__/verifyPeginHashlockSpend.test.d.ts +9 -0
  35. package/dist/tbv/core/primitives/psbt/__tests__/verifyPeginHashlockSpend.test.d.ts.map +1 -0
  36. package/dist/tbv/core/primitives/psbt/verifyPeginHashlockSpend.d.ts +73 -0
  37. package/dist/tbv/core/primitives/psbt/verifyPeginHashlockSpend.d.ts.map +1 -0
  38. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts +6 -0
  39. package/dist/tbv/core/recovery/reconstructPeginParams.d.ts.map +1 -1
  40. package/dist/tbv/core/recovery/toRefundInputs.d.ts +0 -2
  41. package/dist/tbv/core/recovery/toRefundInputs.d.ts.map +1 -1
  42. package/dist/tbv/core/services/deposit/peginState.d.ts +16 -5
  43. package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
  44. package/dist/tbv/core/services/index.cjs +1 -1
  45. package/dist/tbv/core/services/index.js +74 -73
  46. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +6 -2
  47. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  48. package/dist/tbv/core/services/refund/errors.d.ts +15 -0
  49. package/dist/tbv/core/services/refund/errors.d.ts.map +1 -1
  50. package/dist/tbv/core/services/refund/index.d.ts +1 -1
  51. package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
  52. package/dist/tbv/index.cjs +1 -1
  53. package/dist/tbv/index.js +306 -303
  54. package/dist/tbv/index.js.map +1 -1
  55. package/dist/{toRefundInputs-DwXpKQxN.js → toRefundInputs-D5tx3eeA.js} +152 -152
  56. package/dist/{toRefundInputs-DwXpKQxN.js.map → toRefundInputs-D5tx3eeA.js.map} +1 -1
  57. package/dist/{toRefundInputs-BzyN0zvj.cjs → toRefundInputs-Df6eRITl.cjs} +2 -2
  58. package/dist/{toRefundInputs-BzyN0zvj.cjs.map → toRefundInputs-Df6eRITl.cjs.map} +1 -1
  59. package/dist/{verifyKeyPathSchnorrSignature-BVrAmVL3.cjs → verifyKeyPathSchnorrSignature-B7Za6aa1.cjs} +2 -2
  60. package/dist/{verifyKeyPathSchnorrSignature-BVrAmVL3.cjs.map → verifyKeyPathSchnorrSignature-B7Za6aa1.cjs.map} +1 -1
  61. package/dist/{verifyKeyPathSchnorrSignature-CIE3jlVt.js → verifyKeyPathSchnorrSignature-dw7xhm5Y.js} +2 -2
  62. package/dist/{verifyKeyPathSchnorrSignature-CIE3jlVt.js.map → verifyKeyPathSchnorrSignature-dw7xhm5Y.js.map} +1 -1
  63. package/dist/verifyPeginHashlockSpend-CdTFR2K6.js +167 -0
  64. package/dist/verifyPeginHashlockSpend-CdTFR2K6.js.map +1 -0
  65. package/dist/verifyPeginHashlockSpend-CisfqMuT.cjs +2 -0
  66. package/dist/verifyPeginHashlockSpend-CisfqMuT.cjs.map +1 -0
  67. package/dist/{verifyScriptPathSchnorrSignature-DLNGgm4j.js → verifyScriptPathSchnorrSignature-BVGPEZXW.js} +9 -8
  68. package/dist/{verifyScriptPathSchnorrSignature-DLNGgm4j.js.map → verifyScriptPathSchnorrSignature-BVGPEZXW.js.map} +1 -1
  69. package/dist/{verifyScriptPathSchnorrSignature-BHskbJJx.cjs → verifyScriptPathSchnorrSignature-p3sVoWQi.cjs} +2 -2
  70. package/dist/{verifyScriptPathSchnorrSignature-BHskbJJx.cjs.map → verifyScriptPathSchnorrSignature-p3sVoWQi.cjs.map} +1 -1
  71. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -10,12 +10,12 @@ import { getUtxoInfo as de } from "./tbv/core/clients/mempool/index.js";
10
10
  import { M as D } from "./validation-OSC0xTHB.js";
11
11
  import { keccak256 as J, toHex as me, encodeAbiParameters as pe, isAddress as ge, zeroAddress as fe } from "viem";
12
12
  import { s as Pe } from "./sha2-YqVHJiFj.js";
13
- import { d as _ } from "./PayoutManager-BHeiLQ1j.js";
14
- import { b as ve, a as be } from "./PeginManager-CXNqbgA4.js";
13
+ import { d as _ } from "./PayoutManager-3-MzBVLj.js";
14
+ import { b as ve, a as be } from "./PeginManager-m3IlM4wS.js";
15
15
  import { computeMinClaimValue as Y, computeMinPeginFee as Z, peginP2aAnchorOutput as ee, getPrePeginHtlcConnectorInfo as we, expandAuthAnchor as ye } from "./tbv/core/wasm/index.js";
16
- import { d as Ce } from "./deriveVaultRoot-BcvmER1E.js";
17
- import { p as xe } from "./parseFundingOutpoints-GSM-IaaK.js";
18
- import { o as Ee, H as U } from "./verifyScriptPathSchnorrSignature-DLNGgm4j.js";
16
+ import { d as xe } from "./deriveVaultRoot-BcvmER1E.js";
17
+ import { p as Ce } from "./parseFundingOutpoints-GSM-IaaK.js";
18
+ import { p as Ee, H as U } from "./verifyScriptPathSchnorrSignature-BVGPEZXW.js";
19
19
  import { c as j } from "./fundPeginTransaction-CwhRbCQC.js";
20
20
  const Re = [
21
21
  "vaultCoreVersion",
@@ -29,7 +29,7 @@ const Re = [
29
29
  function Ve(e, t) {
30
30
  const o = t.depositor.toLowerCase(), r = S(t).toLowerCase();
31
31
  return e.filter(
32
- (n) => n.vaultId !== t.vaultId && n.depositor.toLowerCase() === o && S(n).toLowerCase() === r
32
+ (s) => s.vaultId !== t.vaultId && s.depositor.toLowerCase() === o && S(s).toLowerCase() === r
33
33
  );
34
34
  }
35
35
  function $e(e, t) {
@@ -57,7 +57,7 @@ function Ae(e) {
57
57
  return t.forEach((o, r) => {
58
58
  if (o.vault.protocol.htlcVout !== r)
59
59
  throw new Error(
60
- `Sibling discovery produced a non-contiguous HTLC vector (${t.map((n) => n.vault.protocol.htlcVout).join(", ")}).`
60
+ `Sibling discovery produced a non-contiguous HTLC vector (${t.map((s) => s.vault.protocol.htlcVout).join(", ")}).`
61
61
  );
62
62
  }), t.map((o) => ({
63
63
  hashlock: o.vault.protocol.hashlock,
@@ -79,27 +79,27 @@ function dt(e) {
79
79
  return t.name === te && t.reason === "device-envelope";
80
80
  }
81
81
  async function Be(e, t) {
82
- const o = M.fromHex(f(e)), n = (await Promise.all(
82
+ const o = M.fromHex(f(e)), s = (await Promise.all(
83
83
  o.ins.map(
84
- (a) => (
84
+ (c) => (
85
85
  // Bitcoin stores the prev-txid in reverse (internal) byte order.
86
86
  de(
87
- he.from(a.hash).reverse().toString("hex"),
88
- a.index,
87
+ he.from(c.hash).reverse().toString("hex"),
88
+ c.index,
89
89
  t
90
90
  )
91
91
  )
92
92
  )
93
- )).reduce((a, i) => a + BigInt(i.value), 0n), c = o.outs.reduce((a, i) => a + BigInt(i.value), 0n), s = n - c;
94
- if (s <= 0n)
93
+ )).reduce((c, n) => c + BigInt(n.value), 0n), i = o.outs.reduce((c, n) => c + BigInt(n.value), 0n), a = s - i;
94
+ if (a <= 0n)
95
95
  throw new Error(
96
- `The funded Pre-PegIn transaction's inputs do not cover its outputs plus a fee (computed fee: ${s} sats).`
96
+ `The funded Pre-PegIn transaction's inputs do not cover its outputs plus a fee (computed fee: ${a} sats).`
97
97
  );
98
- if (s > D)
98
+ if (a > D)
99
99
  throw new Error(
100
- `The funded Pre-PegIn transaction's computed fee (${s} sats) exceeds the maximum reasonable fee (${D} sats); the mempool API may have returned manipulated prevout data.`
100
+ `The funded Pre-PegIn transaction's computed fee (${a} sats) exceeds the maximum reasonable fee (${D} sats); the mempool API may have returned manipulated prevout data.`
101
101
  );
102
- return s;
102
+ return a;
103
103
  }
104
104
  async function oe(e) {
105
105
  const t = e.siblings.length;
@@ -107,10 +107,10 @@ async function oe(e) {
107
107
  throw new Error(
108
108
  "rebuildDepositTermsCore: at least one sibling is required"
109
109
  );
110
- for (const [m, d] of e.siblings.entries())
111
- if (d.amount <= 0n)
110
+ for (const [m, h] of e.siblings.entries())
111
+ if (h.amount <= 0n)
112
112
  throw new Error(
113
- `rebuildDepositTermsCore: sibling[${m}] has non-positive on-chain pegin amount ${d.amount}; the chain-read vault record is invalid. Resume refused.`
113
+ `rebuildDepositTermsCore: sibling[${m}] has non-positive on-chain pegin amount ${h.amount}; the chain-read vault record is invalid. Resume refused.`
114
114
  );
115
115
  if (e.prepeginMaxFee <= 0n)
116
116
  throw new Error(
@@ -123,51 +123,51 @@ async function oe(e) {
123
123
  throw new Error(
124
124
  `Funded Pre-PegIn tx hashes to ${r}, expected ${o} (on-chain prepeginTxid). Resume refused.`
125
125
  );
126
- const n = _(
126
+ const s = _(
127
127
  f(e.fundedPrePeginTxHex)
128
128
  );
129
- if (n === void 0)
129
+ if (s === void 0)
130
130
  throw new Error(
131
131
  "Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN commitment — it either predates auth anchoring or is malformed. The intent resume path requires the anchor to prove sibling completeness. Resume refused."
132
132
  );
133
- if (n.vout !== t)
133
+ if (s.vout !== t)
134
134
  throw new Error(
135
- `Auth-anchor OP_RETURN at vout ${n.vout} does not match the discovered sibling count ${t}; the discovered sibling set does not cover this transaction's HTLC outputs (a lagging index can cause this — retry later). Resume refused.`
135
+ `Auth-anchor OP_RETURN at vout ${s.vout} does not match the discovered sibling count ${t}; the discovered sibling set does not cover this transaction's HTLC outputs (a lagging index can cause this — retry later). Resume refused.`
136
136
  );
137
- const c = e.vaultKeeperBtcPubkeys.length, s = e.universalChallengerBtcPubkeys.length, a = await Y(
137
+ const i = e.vaultKeeperBtcPubkeys.length, a = e.universalChallengerBtcPubkeys.length, c = await Y(
138
138
  e.vaultCoreVersion,
139
- c,
140
- s,
139
+ i,
140
+ a,
141
141
  e.councilQuorum,
142
142
  e.councilSize,
143
143
  e.protocolFeeRate
144
- ), i = await Z(
144
+ ), n = await Z(
145
145
  e.vaultCoreVersion,
146
- c,
147
- s,
146
+ i,
147
+ a,
148
148
  e.minPeginFeeRate
149
- ), { value: l } = await ee(
149
+ ), { value: d } = await ee(
150
150
  e.vaultCoreVersion
151
151
  );
152
- if (a <= 0n)
152
+ if (c <= 0n)
153
153
  throw new Error(
154
- `WASM returned non-positive depositorClaimValue ${a}; expected > 0. Resume refused.`
154
+ `WASM returned non-positive depositorClaimValue ${c}; expected > 0. Resume refused.`
155
155
  );
156
- if (i <= 0n)
156
+ if (n <= 0n)
157
157
  throw new Error(
158
- `WASM returned non-positive peginMaxFee ${i}; expected > 0. Resume refused.`
158
+ `WASM returned non-positive peginMaxFee ${n}; expected > 0. Resume refused.`
159
159
  );
160
- if (l < 0n)
160
+ if (d < 0n)
161
161
  throw new Error(
162
- `WASM returned negative P2A anchor value ${l}. Resume refused.`
162
+ `WASM returned negative P2A anchor value ${d}. Resume refused.`
163
163
  );
164
- const u = i + l, h = e.minPeginFeeRate * j;
165
- if (u <= 0n || u > h)
164
+ const u = n + d, l = e.minPeginFeeRate * j;
165
+ if (u <= 0n || u > l)
166
166
  throw new Error(
167
- `WASM implied PegIn reserve ${u} sat is outside (0, ${h}] (minPeginFeeRate=${e.minPeginFeeRate} × ${j} vbytes). Resume refused.`
167
+ `WASM implied PegIn reserve ${u} sat is outside (0, ${l}] (minPeginFeeRate=${e.minPeginFeeRate} × ${j} vbytes). Resume refused.`
168
168
  );
169
169
  const w = e.siblings.map(
170
- (m) => m.amount + a + i + l
170
+ (m) => m.amount + c + n + d
171
171
  ), y = await Promise.all(
172
172
  e.siblings.map(async (m) => (await we({
173
173
  txGraphVersion: e.vaultCoreVersion,
@@ -179,11 +179,11 @@ async function oe(e) {
179
179
  timelockRefund: e.timelockRefund,
180
180
  network: e.network
181
181
  })).scriptPubKey)
182
- ), C = M.fromHex(
182
+ ), x = M.fromHex(
183
183
  f(e.fundedPrePeginTxHex)
184
184
  ).outs.map((m) => ({ value: m.value, script: m.script }));
185
185
  return Ee(
186
- C,
186
+ x,
187
187
  w,
188
188
  y
189
189
  ), ve({
@@ -199,8 +199,8 @@ async function oe(e) {
199
199
  universalChallengerBtcPubkeys: e.universalChallengerBtcPubkeys,
200
200
  maxAcceptableCommissionBps: e.maxAcceptableCommissionBps,
201
201
  peginAmounts: e.siblings.map((m) => m.amount),
202
- depositorClaimValue: a,
203
- peginMaxFee: i
202
+ depositorClaimValue: c,
203
+ peginMaxFee: n
204
204
  });
205
205
  }
206
206
  async function mt(e) {
@@ -209,40 +209,40 @@ async function mt(e) {
209
209
  throw new Error(
210
210
  "Connected wallet key is not the vault's depositor key; select the account that made the deposit."
211
211
  );
212
- const r = f(t.prePeginTxHash).toLowerCase(), n = f(
212
+ const r = f(t.prePeginTxHash).toLowerCase(), s = f(
213
213
  H(e.fundedPrePeginTxHex)
214
214
  ).toLowerCase();
215
- if (n !== r)
215
+ if (s !== r)
216
216
  throw new Error(
217
- `Funded Pre-PegIn tx hashes to ${n}, expected ${r} (on-chain prePeginTxHash).`
217
+ `Funded Pre-PegIn tx hashes to ${s}, expected ${r} (on-chain prePeginTxHash).`
218
218
  );
219
- const c = await Promise.all(
219
+ const i = await Promise.all(
220
220
  Ve(
221
221
  t.registrationRecords,
222
222
  t.registrationRecord
223
- ).map(async (l) => {
224
- const u = await e.siblingReader.getVaultData(l.vaultId);
225
- if (u.protocol.prePeginTxHash.toLowerCase() !== S(l).toLowerCase())
223
+ ).map(async (d) => {
224
+ const u = await e.siblingReader.getVaultData(d.vaultId);
225
+ if (u.protocol.prePeginTxHash.toLowerCase() !== S(d).toLowerCase())
226
226
  throw new Error(
227
- `Sibling ${l.vaultId} is registered against a different Pre-PegIn on chain than its registration log records; refusing an inconsistent node.`
227
+ `Sibling ${d.vaultId} is registered against a different Pre-PegIn on chain than its registration log records; refusing an inconsistent node.`
228
228
  );
229
229
  return {
230
230
  vault: u,
231
- maxAcceptableCommissionBps: l.maxAcceptableCommissionBps
231
+ maxAcceptableCommissionBps: d.maxAcceptableCommissionBps
232
232
  };
233
233
  })
234
- ), s = {
234
+ ), a = {
235
235
  vault: t.vault,
236
236
  maxAcceptableCommissionBps: t.registrationRecord.maxAcceptableCommissionBps
237
237
  };
238
- $e(s, c);
239
- const a = Ae([s, ...c]), i = await Be(
238
+ $e(a, i);
239
+ const c = Ae([a, ...i]), n = await Be(
240
240
  e.fundedPrePeginTxHex,
241
241
  e.mempoolApiUrl
242
242
  );
243
243
  return oe({
244
244
  vaultCoreVersion: t.vault.protocol.vaultCoreVersion,
245
- siblings: a,
245
+ siblings: c,
246
246
  fundedPrePeginTxHex: e.fundedPrePeginTxHex,
247
247
  depositorBtcPubkey: o,
248
248
  vaultProviderBtcPubkey: t.participantKeys.vaultProvider.operationBtcPubkey,
@@ -256,7 +256,7 @@ async function mt(e) {
256
256
  timelockAssert: t.context.timelockAssert,
257
257
  timelockRefund: t.offchainParams.tRefund,
258
258
  prepeginTxid: r,
259
- prepeginMaxFee: i,
259
+ prepeginMaxFee: n,
260
260
  // The submitted ceiling, verbatim: the device must see the terms the
261
261
  // depositor originally approved.
262
262
  maxAcceptableCommissionBps: t.registrationRecord.maxAcceptableCommissionBps,
@@ -401,40 +401,40 @@ class $ extends Error {
401
401
  }
402
402
  }
403
403
  async function Pt(e) {
404
- const { wallet: t, depositorBtcPubkey: o, fundedPrePeginTxHex: r } = e, n = f(r), c = _(n);
405
- if (c === void 0)
404
+ const { wallet: t, depositorBtcPubkey: o, fundedPrePeginTxHex: r } = e, s = f(r), i = _(s);
405
+ if (i === void 0)
406
406
  throw new K(
407
407
  "Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN, so the number of HTLC outputs it funds cannot be determined. Legacy pre-anchor deposits are not recoverable by this path."
408
408
  );
409
- const s = c.vout;
410
- if (s === 0)
409
+ const a = i.vout;
410
+ if (a === 0)
411
411
  throw new K(
412
412
  "Pre-PegIn's auth-anchor OP_RETURN is at vout 0, implying zero HTLC outputs; there is nothing to recover."
413
413
  );
414
- const a = xe(n), i = await Ce(t, {
414
+ const c = Ce(s), n = await xe(t, {
415
415
  // The vault context takes the 32-byte x-only key; a wallet's compressed
416
416
  // key would otherwise fail a byte-length check deep in the encoder with
417
417
  // nothing pointing back at the caller.
418
418
  depositorBtcPubkey: ce(
419
419
  q(o)
420
420
  ),
421
- fundingOutpoints: a
421
+ fundingOutpoints: c
422
422
  });
423
423
  try {
424
- const u = await ye(i);
425
- let h;
424
+ const u = await ye(n);
425
+ let l;
426
426
  try {
427
- h = ue(Pe(u));
427
+ l = ue(Pe(u));
428
428
  } finally {
429
429
  u.fill(0);
430
430
  }
431
- if (h !== c.hash)
432
- throw new Oe(h, c.hash);
431
+ if (l !== i.hash)
432
+ throw new Oe(l, i.hash);
433
433
  } catch (u) {
434
- throw i.fill(0), u;
434
+ throw n.fill(0), u;
435
435
  }
436
- const { hashlocks: l } = await be(i, s);
437
- return { vaultCount: s, hashlocks: l, authAnchorHash: c.hash };
436
+ const { hashlocks: d } = await be(n, a);
437
+ return { vaultCount: a, hashlocks: d, authAnchorHash: i.hash };
438
438
  }
439
439
  function vt(e) {
440
440
  const { vaultCoreVersion: t, offchainParams: o, participantKeySets: r } = e;
@@ -450,15 +450,15 @@ function vt(e) {
450
450
  throw new Error(
451
451
  "buildPeginParamsCandidates: at least one participant key set is required"
452
452
  );
453
- const n = [];
454
- for (const c of o)
455
- for (const s of r)
456
- n.push({
453
+ const s = [];
454
+ for (const i of o)
455
+ for (const a of r)
456
+ s.push({
457
457
  vaultCoreVersion: t,
458
- offchainParams: c,
459
- participants: s
458
+ offchainParams: i,
459
+ participants: a
460
460
  });
461
- return n;
461
+ return s;
462
462
  }
463
463
  function Ue(e) {
464
464
  return `${e.axis} v${e.version} (${e.reason})`;
@@ -487,11 +487,11 @@ function Ge(e) {
487
487
  ].join("|");
488
488
  }
489
489
  async function Qe(e) {
490
- const { offchainParams: t, participants: o } = e, r = o.vaultKeeperBtcPubkeys.length, n = o.universalChallengerBtcPubkeys.length, [c, s, a] = await Promise.all([
490
+ const { offchainParams: t, participants: o } = e, r = o.vaultKeeperBtcPubkeys.length, s = o.universalChallengerBtcPubkeys.length, [i, a, c] = await Promise.all([
491
491
  Y(
492
492
  e.vaultCoreVersion,
493
493
  r,
494
- n,
494
+ s,
495
495
  t.councilQuorum,
496
496
  t.councilSize,
497
497
  t.protocolFeeRate
@@ -499,64 +499,64 @@ async function Qe(e) {
499
499
  Z(
500
500
  e.vaultCoreVersion,
501
501
  r,
502
- n,
502
+ s,
503
503
  t.minPeginFeeRate
504
504
  ),
505
505
  ee(e.vaultCoreVersion)
506
- ]), i = a.value;
507
- if (c <= 0n)
506
+ ]), n = c.value;
507
+ if (i <= 0n)
508
508
  throw new $(
509
- `WASM returned non-positive depositorClaimValue ${c} for graph version ${e.vaultCoreVersion}`
509
+ `WASM returned non-positive depositorClaimValue ${i} for graph version ${e.vaultCoreVersion}`
510
510
  );
511
- if (s <= 0n)
511
+ if (a <= 0n)
512
512
  throw new $(
513
- `WASM returned non-positive peginMaxFee ${s} for graph version ${e.vaultCoreVersion}`
513
+ `WASM returned non-positive peginMaxFee ${a} for graph version ${e.vaultCoreVersion}`
514
514
  );
515
- if (i < 0n)
515
+ if (n < 0n)
516
516
  throw new $(
517
- `WASM returned negative P2A anchor value ${i} for graph version ${e.vaultCoreVersion}`
517
+ `WASM returned negative P2A anchor value ${n} for graph version ${e.vaultCoreVersion}`
518
518
  );
519
- return { depositorClaimValue: c, peginMaxFee: s, p2aAnchorValue: i };
519
+ return { depositorClaimValue: i, peginMaxFee: a, p2aAnchorValue: n };
520
520
  }
521
521
  async function bt(e) {
522
522
  const {
523
523
  hashlocks: t,
524
524
  fundedPrePeginTxHex: o,
525
525
  depositorBtcPubkey: r,
526
- prepeginMaxFee: n,
527
- maxAcceptableCommissionBps: c,
528
- network: s,
529
- candidates: a,
530
- unresolvedVersions: i
526
+ prepeginMaxFee: s,
527
+ maxAcceptableCommissionBps: i,
528
+ network: a,
529
+ candidates: c,
530
+ unresolvedVersions: n
531
531
  } = e;
532
532
  if (t.length === 0)
533
533
  throw new Error(
534
534
  "reconstructPeginParams: at least one hashlock is required"
535
535
  );
536
- if (a.length === 0)
536
+ if (c.length === 0)
537
537
  throw new Error("reconstructPeginParams: candidate space is empty");
538
- const l = q(r), u = f(o), h = _(u);
539
- if (h === void 0)
538
+ const d = q(r), u = f(o), l = _(u);
539
+ if (l === void 0)
540
540
  throw new K(
541
541
  "Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN; the sibling set cannot be proven complete. Reconstruction refused."
542
542
  );
543
- if (h.vout !== t.length)
543
+ if (l.vout !== t.length)
544
544
  throw new Error(
545
- `reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${h.vout}, so the transaction funds ${h.vout} HTLC output(s). Reconstruction refused.`
545
+ `reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${l.vout}, so the transaction funds ${l.vout} HTLC output(s). Reconstruction refused.`
546
546
  );
547
- const w = M.fromHex(u).outs, y = t.map((p, g) => BigInt(w[g].value)), C = f(
547
+ const w = M.fromHex(u).outs, y = t.map((p, g) => BigInt(w[g].value)), x = f(
548
548
  H(u)
549
- ).toLowerCase(), m = /* @__PURE__ */ new Map(), d = [], A = [], T = [];
549
+ ).toLowerCase(), m = /* @__PURE__ */ new Map(), h = [], A = [], T = [];
550
550
  let N = 0;
551
- for (const p of a)
551
+ for (const p of c)
552
552
  try {
553
553
  const g = Ge(p);
554
554
  let P = m.get(g);
555
555
  P === void 0 && (P = await Qe(p), m.set(g, P));
556
- const x = P.depositorClaimValue + P.peginMaxFee + P.p2aAnchorValue, E = y.map((R) => R - x), k = E.findIndex((R) => R <= 0n);
556
+ const C = P.depositorClaimValue + P.peginMaxFee + P.p2aAnchorValue, E = y.map((R) => R - C), k = E.findIndex((R) => R <= 0n);
557
557
  if (k !== -1)
558
558
  throw new U(
559
- `HTLC output[${k}] value ${y[k]} is not above this candidate's reserve ${x}, so it implies a non-positive pegin amount ${E[k]}.`
559
+ `HTLC output[${k}] value ${y[k]} is not above this candidate's reserve ${C}, so it implies a non-positive pegin amount ${E[k]}.`
560
560
  );
561
561
  const { offchainParams: b, participants: B } = p, L = await oe({
562
562
  vaultCoreVersion: p.vaultCoreVersion,
@@ -565,7 +565,7 @@ async function bt(e) {
565
565
  amount: E[ne]
566
566
  })),
567
567
  fundedPrePeginTxHex: u,
568
- depositorBtcPubkey: l,
568
+ depositorBtcPubkey: d,
569
569
  vaultProviderBtcPubkey: B.vaultProviderBtcPubkey,
570
570
  vaultKeeperBtcPubkeys: B.vaultKeeperBtcPubkeys,
571
571
  universalChallengerBtcPubkeys: B.universalChallengerBtcPubkeys,
@@ -576,12 +576,12 @@ async function bt(e) {
576
576
  timelockPegin: b.timelockPegin,
577
577
  timelockAssert: b.timelockAssert,
578
578
  timelockRefund: b.timelockRefund,
579
- prepeginTxid: C,
580
- prepeginMaxFee: n,
581
- maxAcceptableCommissionBps: c,
582
- network: s
579
+ prepeginTxid: x,
580
+ prepeginMaxFee: s,
581
+ maxAcceptableCommissionBps: i,
582
+ network: a
583
583
  });
584
- d.push({
584
+ h.push({
585
585
  candidate: p,
586
586
  terms: L,
587
587
  peginAmounts: E,
@@ -590,82 +590,82 @@ async function bt(e) {
590
590
  } catch (g) {
591
591
  if (g instanceof $)
592
592
  throw g;
593
- const P = F(p), x = g instanceof Error ? g.message : String(g);
594
- g instanceof U ? A.length < X && A.push(`[${P}] ${x}`) : (N++, T.length < X && T.push(`${P} (${x})`));
593
+ const P = F(p), C = g instanceof Error ? g.message : String(g);
594
+ g instanceof U ? A.length < X && A.push(`[${P}] ${C}`) : (N++, T.length < X && T.push(`${P} (${C})`));
595
595
  }
596
- const re = i.length + N, O = [
597
- ...i.map(Ue),
596
+ const re = n.length + N, O = [
597
+ ...n.map(Ue),
598
598
  ...T
599
599
  ];
600
- if (d.length === 0)
601
- throw new Le(a.length, A, O);
602
- if (new Set(d.map((p) => p.fingerprint)).size > 1)
600
+ if (h.length === 0)
601
+ throw new Le(c.length, A, O);
602
+ if (new Set(h.map((p) => p.fingerprint)).size > 1)
603
603
  throw new ze(
604
- d.map((p) => F(p.candidate))
604
+ h.map((p) => F(p.candidate))
605
605
  );
606
606
  if (re > 0)
607
607
  throw new De(
608
- F(d[0].candidate),
608
+ F(h[0].candidate),
609
609
  O
610
610
  );
611
611
  return {
612
- candidate: d[0].candidate,
613
- terms: d[0].terms,
614
- peginAmounts: d[0].peginAmounts,
615
- authAnchorHash: h.hash,
616
- candidatesTried: a.length,
617
- matchedCandidates: d.map((p) => p.candidate)
612
+ candidate: h[0].candidate,
613
+ terms: h[0].terms,
614
+ peginAmounts: h[0].peginAmounts,
615
+ authAnchorHash: l.hash,
616
+ fundedPrePeginTxHex: u,
617
+ candidatesTried: c.length,
618
+ matchedCandidates: h.map((p) => p.candidate)
618
619
  };
619
620
  }
620
621
  function wt(e, t) {
621
622
  const {
622
623
  htlcVout: o,
623
624
  depositorBtcPubkey: r,
624
- applicationEntryPoint: n,
625
- fundedPrePeginTxHex: c,
626
- hashlocks: s,
625
+ applicationEntryPoint: s,
626
+ hashlocks: i,
627
627
  network: a
628
- } = t, { candidate: i, peginAmounts: l } = e, { offchainParams: u, participants: h } = i;
629
- if (s.length !== l.length)
628
+ } = t, { candidate: c, peginAmounts: n, fundedPrePeginTxHex: d } = e, { offchainParams: u, participants: l } = c;
629
+ if (i.length !== n.length)
630
630
  throw new Error(
631
- `toRefundInputs: ${s.length} hashlock(s) but ${l.length} reconstructed amount(s); the reconstruction and the hashlock vector describe different transactions.`
631
+ `toRefundInputs: ${i.length} hashlock(s) but ${n.length} reconstructed amount(s); the reconstruction and the hashlock vector describe different transactions.`
632
632
  );
633
- if (!Number.isInteger(o) || o < 0 || o >= l.length)
633
+ if (!Number.isInteger(o) || o < 0 || o >= n.length)
634
634
  throw new Error(
635
- `toRefundInputs: htlcVout ${o} is outside the reconstructed batch of ${l.length} vault(s).`
635
+ `toRefundInputs: htlcVout ${o} is outside the reconstructed batch of ${n.length} vault(s).`
636
636
  );
637
- const w = l.map((m, d) => ({
638
- hashlock: le(s[d]),
637
+ const w = n.map((m, h) => ({
638
+ hashlock: le(i[h]),
639
639
  amount: m,
640
- htlcVout: d
640
+ htlcVout: h
641
641
  })), y = {
642
- vaultCoreVersion: i.vaultCoreVersion,
642
+ vaultCoreVersion: c.vaultCoreVersion,
643
643
  hashlock: w[o].hashlock,
644
644
  htlcVout: o,
645
645
  offchainParamsVersion: u.version,
646
- appVaultKeepersVersion: h.appVaultKeepersVersion,
647
- universalChallengersVersion: h.universalChallengersVersion,
648
- vaultProvider: h.vaultProvider,
649
- applicationEntryPoint: n,
650
- amount: l[o],
651
- unsignedPrePeginTxHex: c,
646
+ appVaultKeepersVersion: l.appVaultKeepersVersion,
647
+ universalChallengersVersion: l.universalChallengersVersion,
648
+ vaultProvider: l.vaultProvider,
649
+ applicationEntryPoint: s,
650
+ amount: n[o],
651
+ unsignedPrePeginTxHex: d,
652
652
  depositorBtcPubkey: r,
653
653
  batch: w
654
- }, C = {
655
- vaultProviderPubkey: h.vaultProviderBtcPubkey,
656
- vaultKeeperPubkeys: h.vaultKeeperBtcPubkeys,
657
- universalChallengerPubkeys: h.universalChallengerBtcPubkeys,
654
+ }, x = {
655
+ vaultProviderPubkey: l.vaultProviderBtcPubkey,
656
+ vaultKeeperPubkeys: l.vaultKeeperBtcPubkeys,
657
+ universalChallengerPubkeys: l.universalChallengerBtcPubkeys,
658
658
  timelockRefund: u.timelockRefund,
659
659
  feeRate: u.protocolFeeRate,
660
660
  minPeginFeeRate: u.minPeginFeeRate,
661
661
  // Depositor-as-claimer: the local-challenger count is the keeper count,
662
662
  // the vault provider excluded — btc-vault graph.rs derive_challengers.
663
- numLocalChallengers: h.vaultKeeperBtcPubkeys.length,
663
+ numLocalChallengers: l.vaultKeeperBtcPubkeys.length,
664
664
  councilQuorum: u.councilQuorum,
665
665
  councilSize: u.councilSize,
666
666
  network: a
667
667
  };
668
- return { vault: y, context: C };
668
+ return { vault: y, context: x };
669
669
  }
670
670
  export {
671
671
  te as D,
@@ -697,4 +697,4 @@ export {
697
697
  $ as w,
698
698
  wt as x
699
699
  };
700
- //# sourceMappingURL=toRefundInputs-DwXpKQxN.js.map
700
+ //# sourceMappingURL=toRefundInputs-D5tx3eeA.js.map