@babylonlabs-io/ts-sdk 0.57.1 → 0.58.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 (141) hide show
  1. package/dist/{PeginManager-CnX3uFb0.js → PeginManager-C8ixWlUM.js} +319 -298
  2. package/dist/PeginManager-C8ixWlUM.js.map +1 -0
  3. package/dist/PeginManager-CogqZaa2.cjs +2 -0
  4. package/dist/PeginManager-CogqZaa2.cjs.map +1 -0
  5. package/dist/{batchPoll-DTYXoTEc.js → batchPoll-B0VxT62K.js} +4 -4
  6. package/dist/{batchPoll-DTYXoTEc.js.map → batchPoll-B0VxT62K.js.map} +1 -1
  7. package/dist/{batchPoll-BXIy3R7h.cjs → batchPoll-D5IDDOa8.cjs} +2 -2
  8. package/dist/{batchPoll-BXIy3R7h.cjs.map → batchPoll-D5IDDOa8.cjs.map} +1 -1
  9. package/dist/{bitcoin-B5aNKtsk.js → bitcoin-d9eaaZB_.js} +49 -46
  10. package/dist/bitcoin-d9eaaZB_.js.map +1 -0
  11. package/dist/bitcoin-m84N5a8o.cjs +2 -0
  12. package/dist/bitcoin-m84N5a8o.cjs.map +1 -0
  13. package/dist/buildAndBroadcastRefund-BL8u-Ti4.cjs +2 -0
  14. package/dist/buildAndBroadcastRefund-BL8u-Ti4.cjs.map +1 -0
  15. package/dist/{buildAndBroadcastRefund-Bo3AlqCk.js → buildAndBroadcastRefund-DBA-Mp4I.js} +557 -484
  16. package/dist/buildAndBroadcastRefund-DBA-Mp4I.js.map +1 -0
  17. package/dist/{challengeAssert-Cu-PtJ1g.cjs → challengeAssert-BFRE2DM-.cjs} +2 -2
  18. package/dist/{challengeAssert-Cu-PtJ1g.cjs.map → challengeAssert-BFRE2DM-.cjs.map} +1 -1
  19. package/dist/{challengeAssert-BVQq50su.js → challengeAssert-C7PzyJ7g.js} +2 -2
  20. package/dist/{challengeAssert-BVQq50su.js.map → challengeAssert-C7PzyJ7g.js.map} +1 -1
  21. package/dist/constants-DU5CGcqO.cjs +2 -0
  22. package/dist/{constants-BqU1Uz15.cjs.map → constants-DU5CGcqO.cjs.map} +1 -1
  23. package/dist/constants-GjWXdaqV.js +23 -0
  24. package/dist/{constants-CDQE812z.js.map → constants-GjWXdaqV.js.map} +1 -1
  25. package/dist/{deriveVaultRoot-B_gEOTD6.js → deriveVaultRoot-D0RY5GJc.js} +2 -2
  26. package/dist/{deriveVaultRoot-B_gEOTD6.js.map → deriveVaultRoot-D0RY5GJc.js.map} +1 -1
  27. package/dist/{deriveVaultRoot-CebLadyJ.cjs → deriveVaultRoot-p4uGsM7w.cjs} +2 -2
  28. package/dist/{deriveVaultRoot-CebLadyJ.cjs.map → deriveVaultRoot-p4uGsM7w.cjs.map} +1 -1
  29. package/dist/errors-2aF9oRwM.cjs +2 -0
  30. package/dist/errors-2aF9oRwM.cjs.map +1 -0
  31. package/dist/errors-kXGQXKxZ.js +28 -0
  32. package/dist/errors-kXGQXKxZ.js.map +1 -0
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +188 -180
  35. package/dist/{mempoolApi-C0olk43O.js → mempoolApi-CMHEz4ez.js} +3 -3
  36. package/dist/{mempoolApi-C0olk43O.js.map → mempoolApi-CMHEz4ez.js.map} +1 -1
  37. package/dist/{mempoolApi-Dsm2VPXp.cjs → mempoolApi-DfD3_Y6v.cjs} +2 -2
  38. package/dist/{mempoolApi-Dsm2VPXp.cjs.map → mempoolApi-DfD3_Y6v.cjs.map} +1 -1
  39. package/dist/{noPayout-CI4l1qu2.js → noPayout-DuE-UyhQ.js} +5 -5
  40. package/dist/{noPayout-CI4l1qu2.js.map → noPayout-DuE-UyhQ.js.map} +1 -1
  41. package/dist/{noPayout-Djrv31V5.cjs → noPayout-qUEtRKc_.cjs} +2 -2
  42. package/dist/{noPayout-Djrv31V5.cjs.map → noPayout-qUEtRKc_.cjs.map} +1 -1
  43. package/dist/{onChainBtcPubkey-Cd9kpz-S.cjs → onChainBtcPubkey-C_a2L3kL.cjs} +2 -2
  44. package/dist/{onChainBtcPubkey-Cd9kpz-S.cjs.map → onChainBtcPubkey-C_a2L3kL.cjs.map} +1 -1
  45. package/dist/{onChainBtcPubkey-aPY5ib3Q.js → onChainBtcPubkey-DeF4cKoO.js} +2 -2
  46. package/dist/{onChainBtcPubkey-aPY5ib3Q.js.map → onChainBtcPubkey-DeF4cKoO.js.map} +1 -1
  47. package/dist/peginInput-Ci921gTl.cjs +2 -0
  48. package/dist/peginInput-Ci921gTl.cjs.map +1 -0
  49. package/dist/peginInput-HQPWZfly.js +123 -0
  50. package/dist/peginInput-HQPWZfly.js.map +1 -0
  51. package/dist/{reservation-cHDRn4DA.js → reservation-CbAXa7VG.js} +2 -2
  52. package/dist/{reservation-cHDRn4DA.js.map → reservation-CbAXa7VG.js.map} +1 -1
  53. package/dist/{reservation-ClEs2X0H.cjs → reservation-RGKvg2x6.cjs} +2 -2
  54. package/dist/{reservation-ClEs2X0H.cjs.map → reservation-RGKvg2x6.cjs.map} +1 -1
  55. package/dist/signPsbtsWithFallback-Xs4jZw5z.cjs +2 -0
  56. package/dist/signPsbtsWithFallback-Xs4jZw5z.cjs.map +1 -0
  57. package/dist/{signPsbtsWithFallback-CzZFZf0I.js → signPsbtsWithFallback-eY1YgV13.js} +69 -67
  58. package/dist/signPsbtsWithFallback-eY1YgV13.js.map +1 -0
  59. package/dist/tbv/core/clients/index.cjs +1 -1
  60. package/dist/tbv/core/clients/index.js +3 -3
  61. package/dist/tbv/core/deposit-terms/__tests__/depositTermsErrors.test.d.ts +2 -0
  62. package/dist/tbv/core/deposit-terms/__tests__/depositTermsErrors.test.d.ts.map +1 -0
  63. package/dist/tbv/core/deposit-terms/buildDepositTerms.d.ts.map +1 -1
  64. package/dist/tbv/core/deposit-terms/depositTerms.d.ts +72 -25
  65. package/dist/tbv/core/deposit-terms/depositTerms.d.ts.map +1 -1
  66. package/dist/tbv/core/deposit-terms/depositTermsErrors.d.ts +24 -0
  67. package/dist/tbv/core/deposit-terms/depositTermsErrors.d.ts.map +1 -0
  68. package/dist/tbv/core/deposit-terms/index.d.ts +2 -1
  69. package/dist/tbv/core/deposit-terms/index.d.ts.map +1 -1
  70. package/dist/tbv/core/index.cjs +1 -1
  71. package/dist/tbv/core/index.js +179 -171
  72. package/dist/tbv/core/managers/PayoutManager.d.ts +2 -0
  73. package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
  74. package/dist/tbv/core/managers/PeginManager.d.ts +16 -3
  75. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  76. package/dist/tbv/core/managers/index.cjs +1 -1
  77. package/dist/tbv/core/managers/index.js +2 -2
  78. package/dist/tbv/core/primitives/index.cjs +1 -1
  79. package/dist/tbv/core/primitives/index.d.ts +1 -1
  80. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  81. package/dist/tbv/core/primitives/index.js +16 -15
  82. package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts +14 -32
  83. package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts.map +1 -1
  84. package/dist/tbv/core/primitives/psbt/constants.d.ts +10 -1
  85. package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
  86. package/dist/tbv/core/primitives/psbt/payout.d.ts +8 -2
  87. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  88. package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
  89. package/dist/tbv/core/primitives/utils/bitcoin.d.ts +25 -1
  90. package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
  91. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +1 -1
  92. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  93. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +1 -1
  94. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  95. package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
  96. package/dist/tbv/core/services/index.cjs +1 -1
  97. package/dist/tbv/core/services/index.js +35 -31
  98. package/dist/tbv/core/services/participants/__tests__/indexerKeyHint.test.d.ts +9 -0
  99. package/dist/tbv/core/services/participants/__tests__/indexerKeyHint.test.d.ts.map +1 -0
  100. package/dist/tbv/core/services/participants/index.d.ts +2 -0
  101. package/dist/tbv/core/services/participants/index.d.ts.map +1 -1
  102. package/dist/tbv/core/services/participants/indexerKeyHint.d.ts +61 -0
  103. package/dist/tbv/core/services/participants/indexerKeyHint.d.ts.map +1 -0
  104. package/dist/tbv/core/utils/index.cjs +1 -1
  105. package/dist/tbv/core/utils/index.js +3 -3
  106. package/dist/tbv/core/vault-secrets/index.cjs +1 -1
  107. package/dist/tbv/core/vault-secrets/index.js +1 -1
  108. package/dist/tbv/index.cjs +1 -1
  109. package/dist/tbv/index.js +179 -171
  110. package/dist/testing/index.cjs +1 -1
  111. package/dist/testing/index.js +1 -1
  112. package/dist/{verifyScriptPathSchnorrSignature-Xoo9DOHW.js → verifyScriptPathSchnorrSignature-Bav08_7R.js} +268 -240
  113. package/dist/verifyScriptPathSchnorrSignature-Bav08_7R.js.map +1 -0
  114. package/dist/verifyScriptPathSchnorrSignature-CYjK4IP_.cjs +2 -0
  115. package/dist/verifyScriptPathSchnorrSignature-CYjK4IP_.cjs.map +1 -0
  116. package/package.json +1 -1
  117. package/dist/PeginManager-CnX3uFb0.js.map +0 -1
  118. package/dist/PeginManager-iDbqXsKD.cjs +0 -2
  119. package/dist/PeginManager-iDbqXsKD.cjs.map +0 -1
  120. package/dist/bitcoin-B5aNKtsk.js.map +0 -1
  121. package/dist/bitcoin-CHfKAhcI.cjs +0 -2
  122. package/dist/bitcoin-CHfKAhcI.cjs.map +0 -1
  123. package/dist/buildAndBroadcastRefund-4uAl7OIk.cjs +0 -2
  124. package/dist/buildAndBroadcastRefund-4uAl7OIk.cjs.map +0 -1
  125. package/dist/buildAndBroadcastRefund-Bo3AlqCk.js.map +0 -1
  126. package/dist/constants-BqU1Uz15.cjs +0 -2
  127. package/dist/constants-CDQE812z.js +0 -21
  128. package/dist/errors-B-H0seUG.js +0 -8
  129. package/dist/errors-B-H0seUG.js.map +0 -1
  130. package/dist/errors-Bfjxg_iJ.cjs +0 -2
  131. package/dist/errors-Bfjxg_iJ.cjs.map +0 -1
  132. package/dist/peginInput-BKD_b3gq.js +0 -105
  133. package/dist/peginInput-BKD_b3gq.js.map +0 -1
  134. package/dist/peginInput-CAiiDZeO.cjs +0 -2
  135. package/dist/peginInput-CAiiDZeO.cjs.map +0 -1
  136. package/dist/signPsbtsWithFallback-C01N6Kdo.cjs +0 -2
  137. package/dist/signPsbtsWithFallback-C01N6Kdo.cjs.map +0 -1
  138. package/dist/signPsbtsWithFallback-CzZFZf0I.js.map +0 -1
  139. package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs +0 -2
  140. package/dist/verifyScriptPathSchnorrSignature-C-84KJ6U.cjs.map +0 -1
  141. package/dist/verifyScriptPathSchnorrSignature-Xoo9DOHW.js.map +0 -1
@@ -1,35 +1,35 @@
1
- var de = Object.defineProperty;
2
- var ge = (e, t, r) => t in e ? de(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var I = (e, t, r) => ge(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { B as fe } from "./BTCVaultRegistry.abi-CixOlp3B.js";
5
- import { e as ve, v as ye, s as d, u as re, p as B, f as k } from "./bitcoin-B5aNKtsk.js";
6
- import { v as Pe, b as me, s as be, P as we, d as xe } from "./signPsbtsWithFallback-CzZFZf0I.js";
7
- import { D as x, c as ke, b as Ee, R as Te, d as oe } from "./json-rpc-client-DuUARJvV.js";
8
- import { Transaction as S, Psbt as Ce } from "bitcoinjs-lib";
9
- import { c as Se, d as D, e as F, f as M } from "./verifyScriptPathSchnorrSignature-Xoo9DOHW.js";
10
- import { c as _e, a as $e, b as Re } from "./noPayout-CI4l1qu2.js";
11
- import { c as U } from "./signing-DaLvGwQe.js";
12
- import { a as Q } from "./onChainBtcPubkey-aPY5ib3Q.js";
13
- import { a as Ae } from "./constants-CDQE812z.js";
14
- const Be = /^0x[0-9a-fA-F]{64}$/, Ve = /^0x[0-9a-fA-F]{40}$/, Ie = /^0x([0-9a-fA-F]{2})*$/;
15
- function K(e, t) {
1
+ var he = Object.defineProperty;
2
+ var de = (e, t, r) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var A = (e, t, r) => de(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { B as ge } from "./BTCVaultRegistry.abi-CixOlp3B.js";
5
+ import { e as fe, v as ye, s as d, u as te, p as L, c as k, f as C } from "./bitcoin-d9eaaZB_.js";
6
+ import { v as ve, b as Pe, s as me, P as be, d as we } from "./signPsbtsWithFallback-eY1YgV13.js";
7
+ import { D as E, c as ke, b as xe, R as Ee, d as re } from "./json-rpc-client-DuUARJvV.js";
8
+ import { Transaction as $, Psbt as Ce } from "bitcoinjs-lib";
9
+ import { c as Te, d as N, e as D, f as F } from "./verifyScriptPathSchnorrSignature-Bav08_7R.js";
10
+ import { c as Se, a as $e, b as _e } from "./noPayout-DuE-UyhQ.js";
11
+ import { c as M } from "./signing-DaLvGwQe.js";
12
+ import { a as X } from "./onChainBtcPubkey-DeF4cKoO.js";
13
+ import { a as Be } from "./constants-GjWXdaqV.js";
14
+ const Ae = /^0x[0-9a-fA-F]{64}$/, Re = /^0x[0-9a-fA-F]{40}$/, Ke = /^0x([0-9a-fA-F]{2})*$/;
15
+ function R(e, t) {
16
16
  if (e.length !== 66)
17
17
  throw new Error(
18
18
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
19
19
  );
20
- if (!Be.test(e))
20
+ if (!Ae.test(e))
21
21
  throw new Error(
22
22
  `${t} must contain only hex characters after the 0x prefix`
23
23
  );
24
24
  }
25
- function Ke(e, t) {
26
- if (!Ve.test(e))
25
+ function Ve(e, t) {
26
+ if (!Re.test(e))
27
27
  throw new Error(
28
28
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
29
29
  );
30
30
  }
31
- function Oe(e, t) {
32
- if (!Ie.test(e))
31
+ function Ie(e, t) {
32
+ if (!Ke.test(e))
33
33
  throw new Error(
34
34
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
35
35
  );
@@ -38,91 +38,92 @@ async function _t(e) {
38
38
  const {
39
39
  btcVaultRegistryAddress: t,
40
40
  vaultId: r,
41
- hashlock: o,
42
- activationMetadata: a,
41
+ hashlock: n,
42
+ activationMetadata: s,
43
43
  writeContract: l,
44
- signal: n
44
+ signal: o
45
45
  } = e;
46
- n == null || n.throwIfAborted(), Ke(t, "btcVaultRegistryAddress"), K(r, "vaultId");
47
- const s = ve(e.secret);
48
- if (K(s, "secret"), o !== void 0 && (K(o, "hashlock"), !Pe(s, o)))
46
+ o == null || o.throwIfAborted(), Ve(t, "btcVaultRegistryAddress"), R(r, "vaultId");
47
+ const a = fe(e.secret);
48
+ if (R(a, "secret"), n !== void 0 && (R(n, "hashlock"), !ve(a, n)))
49
49
  throw new Error(
50
50
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
51
51
  );
52
- return Oe(a, "activationMetadata"), l({
52
+ return Ie(s, "activationMetadata"), l({
53
53
  address: t,
54
- abi: fe,
54
+ abi: ge,
55
55
  functionName: "activateVaultWithSecret",
56
- args: [r, s, a]
56
+ args: [r, a, s]
57
57
  });
58
58
  }
59
- const Y = 1, Ne = 1;
59
+ const G = 1, Oe = 1;
60
60
  function He(e, t) {
61
- const r = d(t).toLowerCase(), a = e.map((l) => d(l).toLowerCase()).filter((l) => l !== r);
62
- if (a.length === 0)
61
+ const r = d(t).toLowerCase(), s = e.map((l) => d(l).toLowerCase()).filter((l) => l !== r);
62
+ if (s.length === 0)
63
63
  throw new Error(
64
64
  "Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
65
65
  );
66
- if (new Set(a).size !== a.length)
66
+ if (new Set(s).size !== s.length)
67
67
  throw new Error(
68
68
  "Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
69
69
  );
70
- return a;
70
+ return s;
71
71
  }
72
- function De(e, t, r) {
73
- const o = r.map(
72
+ function Ne(e, t, r) {
73
+ const n = r.map(
74
74
  (c) => d(c).toLowerCase()
75
- ), a = t.filter((c) => o.includes(c));
76
- if (a.length > 0)
75
+ ), s = t.filter((c) => n.includes(c));
76
+ if (s.length > 0)
77
77
  throw new Error(
78
- `Cannot validate challenger set: vault keepers and universal challengers overlap (${a.join(", ")})`
78
+ `Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
79
79
  );
80
- const l = [...t, ...o], n = e.map(
80
+ const l = [...t, ...n], o = e.map(
81
81
  (c) => d(c.challenger_pubkey).toLowerCase()
82
- ), s = new Set(n);
83
- if (s.size !== n.length)
82
+ ), a = new Set(o);
83
+ if (a.size !== o.length)
84
84
  throw new Error(
85
85
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
86
86
  );
87
- const u = new Set(l), i = l.filter((c) => !s.has(c)), p = n.filter((c) => !u.has(c));
87
+ const u = new Set(l), i = l.filter((c) => !a.has(c)), p = o.filter((c) => !u.has(c));
88
88
  if (i.length > 0 || p.length > 0)
89
89
  throw new Error(
90
90
  "Depositor graph challenger set does not match expected (local ∪ universal)" + (i.length > 0 ? ` (missing: ${i.join(", ")})` : "") + (p.length > 0 ? ` (unexpected: ${p.join(", ")})` : "")
91
91
  );
92
92
  }
93
- function Fe(e, t) {
93
+ function De(e, t) {
94
94
  const r = e.ins[t];
95
- return re(new Uint8Array(r.hash).slice().reverse());
95
+ return te(new Uint8Array(r.hash).slice().reverse());
96
96
  }
97
- function O(e, t, r, o, a) {
97
+ function K(e, t, r, n, s) {
98
98
  const l = e.ins[t];
99
99
  if (l.index !== 0)
100
100
  throw new Error(
101
- `NoPayout (challenger ${a}) input ${t} expected to spend ${o} vout 0, got vout ${l.index}`
101
+ `NoPayout (challenger ${s}) input ${t} expected to spend ${n} vout 0, got vout ${l.index}`
102
102
  );
103
- const n = r.getId(), s = Fe(e, t);
104
- if (s !== n)
103
+ const o = r.getId(), a = De(e, t);
104
+ if (a !== o)
105
105
  throw new Error(
106
- `NoPayout (challenger ${a}) input ${t} does not reference ${o} (expected txid ${n}, got ${s})`
106
+ `NoPayout (challenger ${s}) input ${t} does not reference ${n} (expected txid ${o}, got ${a})`
107
107
  );
108
108
  }
109
- async function Me(e, t, r) {
110
- const o = [], a = [], l = [], n = He(
109
+ async function Fe(e, t, r) {
110
+ const n = [], s = [], l = [], o = He(
111
111
  r.vaultKeeperBtcPubkeys,
112
112
  r.depositorBtcPubkey
113
113
  );
114
- De(
114
+ Ne(
115
115
  e.challenger_presign_data,
116
- n,
116
+ o,
117
117
  r.universalChallengerBtcPubkeys
118
118
  );
119
- const s = await Se({
119
+ const a = await Te({
120
120
  vaultCoreVersion: r.vaultCoreVersion,
121
121
  vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
122
122
  vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
123
123
  payoutTxHex: e.payout_tx.tx_hex,
124
124
  peginTxHex: r.peginTxHex,
125
125
  assertTxHex: e.assert_tx.tx_hex,
126
+ timelockAssert: r.timelockAssert,
126
127
  depositorBtcPubkey: r.depositorBtcPubkey,
127
128
  vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
128
129
  vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
@@ -131,79 +132,79 @@ async function Me(e, t, r) {
131
132
  network: r.network,
132
133
  claimerBtcPubkey: r.depositorBtcPubkey,
133
134
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
134
- commissionBps: Ne,
135
+ commissionBps: Oe,
135
136
  protocolFeeRate: r.protocolFeeRate,
136
137
  councilSize: r.councilMembers.length
137
138
  });
138
- o.push(s.psbtHex), a.push(
139
- U(
139
+ n.push(a.psbtHex), s.push(
140
+ M(
140
141
  t,
141
- Y
142
+ G
142
143
  )
143
144
  );
144
- const u = d(r.depositorBtcPubkey), i = S.fromHex(
145
+ const u = d(r.depositorBtcPubkey), i = $.fromHex(
145
146
  d(e.assert_tx.tx_hex)
146
147
  );
147
148
  for (const p of e.challenger_presign_data) {
148
- const c = d(p.challenger_pubkey), h = o.length, v = await Ue({
149
+ const c = d(p.challenger_pubkey), h = n.length, f = await Me({
149
150
  challenger: p,
150
151
  challengerPubkey: c,
151
152
  claimerPubkey: u,
152
- localChallengers: n,
153
+ localChallengers: o,
153
154
  assertTxParsed: i,
154
155
  ctx: r
155
156
  });
156
- o.push(v), a.push(
157
- U(
157
+ n.push(f), s.push(
158
+ M(
158
159
  t,
159
- Y
160
+ G
160
161
  )
161
162
  ), l.push({
162
163
  challengerPubkey: c,
163
164
  noPayoutIdx: h
164
165
  });
165
166
  }
166
- return { psbtHexes: o, signOptions: a, challengerEntries: l };
167
+ return { psbtHexes: n, signOptions: s, challengerEntries: l };
167
168
  }
168
- async function Ue(e) {
169
+ async function Me(e) {
169
170
  const {
170
171
  challenger: t,
171
172
  challengerPubkey: r,
172
- claimerPubkey: o,
173
- localChallengers: a,
173
+ claimerPubkey: n,
174
+ localChallengers: s,
174
175
  assertTxParsed: l,
175
- ctx: n
176
+ ctx: o
176
177
  } = e;
177
- _e(
178
+ Se(
178
179
  t.nopayout_tx.tx_hex,
179
180
  r,
180
- n.network
181
+ o.network
181
182
  );
182
- const s = S.fromHex(
183
+ const a = $.fromHex(
183
184
  d(t.nopayout_tx.tx_hex)
184
- ), u = S.fromHex(
185
+ ), u = $.fromHex(
185
186
  d(t.challenge_assert_x_tx.tx_hex)
186
- ), i = S.fromHex(
187
+ ), i = $.fromHex(
187
188
  d(t.challenge_assert_y_tx.tx_hex)
188
189
  );
189
- if (s.ins.length !== 3)
190
+ if (a.ins.length !== 3)
190
191
  throw new Error(
191
- `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${s.ins.length}`
192
+ `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${a.ins.length}`
192
193
  );
193
- O(
194
- s,
194
+ K(
195
+ a,
195
196
  0,
196
197
  l,
197
198
  "Assert",
198
199
  r
199
- ), O(
200
- s,
200
+ ), K(
201
+ a,
201
202
  1,
202
203
  u,
203
204
  "ChallengeAssertX",
204
205
  r
205
- ), O(
206
- s,
206
+ ), K(
207
+ a,
207
208
  2,
208
209
  i,
209
210
  "ChallengeAssertY",
@@ -214,7 +215,7 @@ async function Ue(e) {
214
215
  u.outs[0],
215
216
  i.outs[0]
216
217
  ].map((c) => ({
217
- script_pubkey: re(new Uint8Array(c.script)),
218
+ script_pubkey: te(new Uint8Array(c.script)),
218
219
  value: c.value
219
220
  }));
220
221
  return $e({
@@ -222,68 +223,68 @@ async function Ue(e) {
222
223
  challengerPubkey: r,
223
224
  prevouts: p,
224
225
  connectorParams: {
225
- txGraphVersion: n.vaultCoreVersion,
226
- claimer: o,
227
- localChallengers: a,
228
- universalChallengers: n.universalChallengerBtcPubkeys,
229
- timelockAssert: n.timelockAssert,
230
- councilMembers: n.councilMembers,
231
- councilQuorum: n.councilQuorum
226
+ txGraphVersion: o.vaultCoreVersion,
227
+ claimer: n,
228
+ localChallengers: s,
229
+ universalChallengers: o.universalChallengerBtcPubkeys,
230
+ timelockAssert: o.timelockAssert,
231
+ councilMembers: o.councilMembers,
232
+ councilQuorum: o.councilQuorum
232
233
  }
233
234
  });
234
235
  }
235
- function Le(e, t, r) {
236
- D(e[0]);
237
- const a = F(
236
+ function Ue(e, t, r) {
237
+ N(e[0]);
238
+ const s = D(
238
239
  e[0].returnedPsbtHex,
239
240
  r
240
241
  );
241
- M({
242
+ F({
242
243
  requestedPsbtHex: e[0].requestedPsbtHex,
243
- signatureHex: a,
244
+ signatureHex: s,
244
245
  signerXOnlyPubkeyHex: r,
245
246
  inputIndex: 0
246
247
  });
247
248
  const l = {};
248
- for (const n of t) {
249
- D(e[n.noPayoutIdx]);
250
- const s = F(
251
- e[n.noPayoutIdx].returnedPsbtHex,
249
+ for (const o of t) {
250
+ N(e[o.noPayoutIdx]);
251
+ const a = D(
252
+ e[o.noPayoutIdx].returnedPsbtHex,
252
253
  r
253
254
  );
254
- M({
255
- requestedPsbtHex: e[n.noPayoutIdx].requestedPsbtHex,
256
- signatureHex: s,
255
+ F({
256
+ requestedPsbtHex: e[o.noPayoutIdx].requestedPsbtHex,
257
+ signatureHex: a,
257
258
  signerXOnlyPubkeyHex: r,
258
259
  inputIndex: 0
259
- }), l[n.challengerPubkey] = {
260
- nopayout_signature: s
260
+ }), l[o.challengerPubkey] = {
261
+ nopayout_signature: a
261
262
  };
262
263
  }
263
264
  return {
264
265
  payout_signatures: {
265
- payout_signature: a
266
+ payout_signature: s
266
267
  },
267
268
  per_challenger: l
268
269
  };
269
270
  }
270
- async function Xe(e) {
271
- const { depositorGraph: t, btcWallet: r, signingContext: o } = e, a = await r.getPublicKeyHex(), { depositorPubkey: l } = ye(
272
- a,
273
- d(o.depositorBtcPubkey)
274
- ), { psbtHexes: n, signOptions: s, challengerEntries: u } = await Me(
271
+ async function Le(e) {
272
+ const { depositorGraph: t, btcWallet: r, signingContext: n } = e, s = await r.getPublicKeyHex(), { depositorPubkey: l } = ye(
273
+ s,
274
+ d(n.depositorBtcPubkey)
275
+ ), { psbtHexes: o, signOptions: a, challengerEntries: u } = await Fe(
275
276
  t,
276
- a,
277
- o
278
- ), i = await me(
277
+ s,
278
+ n
279
+ ), i = await Pe(
279
280
  r,
280
- n,
281
- s
282
- ), p = n.map((c, h) => ({
281
+ o,
282
+ a
283
+ ), p = o.map((c, h) => ({
283
284
  requestedPsbtHex: c,
284
285
  returnedPsbtHex: i[h]
285
286
  }));
286
- return Le(
287
+ return Ue(
287
288
  p,
288
289
  u,
289
290
  l
@@ -294,98 +295,130 @@ async function ne(e) {
294
295
  const {
295
296
  statusReader: t,
296
297
  peginTxid: r,
297
- targetStatuses: o,
298
- timeoutMs: a,
298
+ targetStatuses: n,
299
+ timeoutMs: s,
299
300
  pollIntervalMs: l = ze,
300
- signal: n
301
- } = e, s = Date.now();
301
+ signal: o
302
+ } = e, a = Date.now();
302
303
  for (; ; ) {
303
- if (n != null && n.aborted)
304
+ if (o != null && o.aborted)
304
305
  throw new Error(
305
- `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
306
+ `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
306
307
  );
307
- if (Date.now() - s >= a)
308
+ if (Date.now() - a >= s)
308
309
  throw new Error(
309
- `Polling timeout after ${a}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
310
+ `Polling timeout after ${s}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
310
311
  );
311
312
  try {
312
313
  const u = await t.getPeginStatus(
313
314
  { pegin_txid: r },
314
- n
315
+ o
315
316
  );
316
317
  if (u.pegin_txid.toLowerCase() !== r.toLowerCase())
317
318
  throw new Error(
318
319
  `getPeginStatus returned status for pegin ${u.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
319
320
  );
320
321
  const i = u.status;
321
- if (o.has(i) || i === x.ACTIVATED)
322
+ if (n.has(i) || i === E.ACTIVATED)
322
323
  return i;
323
- if (i === x.EXPIRED || ke.has(i))
324
+ if (i === E.EXPIRED || ke.has(i))
324
325
  throw new Error(
325
- `Pegin ${r.slice(0, 8)}… reached terminal status "${i}" while waiting for ${[...o].join(", ")}`
326
+ `Pegin ${r.slice(0, 8)}… reached terminal status "${i}" while waiting for ${[...n].join(", ")}`
326
327
  );
327
328
  } catch (u) {
328
- if (!(u instanceof Ee && u.code === Te.PEGIN_NOT_FOUND))
329
+ if (!(u instanceof xe && u.code === Ee.PEGIN_NOT_FOUND))
329
330
  throw u;
330
331
  }
331
332
  await new Promise((u, i) => {
332
333
  const p = () => {
333
334
  clearTimeout(c), i(
334
335
  new Error(
335
- `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
336
+ `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
336
337
  )
337
338
  );
338
339
  }, c = setTimeout(() => {
339
- n == null || n.removeEventListener("abort", p), u();
340
+ o == null || o.removeEventListener("abort", p), u();
340
341
  }, l);
341
- n == null || n.addEventListener("abort", p, { once: !0 });
342
+ o == null || o.addEventListener("abort", p, { once: !0 });
342
343
  });
343
344
  }
344
345
  }
345
- const Ge = 1200 * 1e3, ae = /* @__PURE__ */ new Set([
346
- x.PENDING_ACKS,
347
- x.PENDING_ACTIVATION,
348
- x.ACTIVATED_PENDING_BROADCAST,
349
- x.ACTIVATED
350
- ]), qe = /* @__PURE__ */ new Set([
351
- x.PENDING_DEPOSITOR_SIGNATURES,
352
- ...ae
346
+ const Xe = 1200 * 1e3, oe = /* @__PURE__ */ new Set([
347
+ E.PENDING_ACKS,
348
+ E.PENDING_ACTIVATION,
349
+ E.ACTIVATED_PENDING_BROADCAST,
350
+ E.ACTIVATED
351
+ ]), Ge = /* @__PURE__ */ new Set([
352
+ E.PENDING_DEPOSITOR_SIGNATURES,
353
+ ...oe
353
354
  ]);
354
355
  function je(e) {
355
356
  return e.map((t) => ({
356
- claimerPubkeyXOnly: B(t.claimer_pubkey),
357
+ claimerPubkeyXOnly: L(t.claimer_pubkey),
357
358
  payoutTxHex: t.payout_tx.tx_hex,
358
359
  assertTxHex: t.assert_tx.tx_hex
359
360
  }));
360
361
  }
361
- function T(e) {
362
- return B(e).toLowerCase();
362
+ function w(e) {
363
+ return L(e).toLowerCase();
364
+ }
365
+ function qe(e, t) {
366
+ const r = (a, u, i) => {
367
+ throw new Error(
368
+ `Deposit terms ${a} (${String(u)}) does not match the vault's version-locked signing context (${String(i)}); refusing to sign payouts against terms that describe a different graph.`
369
+ );
370
+ };
371
+ e.protocolFeeRate !== t.protocolFeeRate && r("protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate);
372
+ const n = (a) => a.map(w).sort(), s = (a, u) => {
373
+ const i = n(a), p = n(u);
374
+ return i.length === p.length && i.every((c, h) => c === p[h]);
375
+ };
376
+ s(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
377
+ "vaultKeeperBtcPubkeys",
378
+ e.vaultKeeperBtcPubkeys.join(","),
379
+ t.vaultKeeperBtcPubkeys.join(",")
380
+ ), s(
381
+ e.universalChallengerBtcPubkeys,
382
+ t.universalChallengerBtcPubkeys
383
+ ) || r(
384
+ "universalChallengerBtcPubkeys",
385
+ e.universalChallengerBtcPubkeys.join(","),
386
+ t.universalChallengerBtcPubkeys.join(",")
387
+ );
388
+ const l = w(t.vaultProviderBtcPubkey), o = e.vaults.map(
389
+ (a) => w(a.vaultProviderBtcPubkey)
390
+ );
391
+ o.includes(l) || r(
392
+ "vaults[].vaultProviderBtcPubkey",
393
+ o.join(",") || "<no vaults>",
394
+ t.vaultProviderBtcPubkey
395
+ );
363
396
  }
364
- function Qe(e, t, r, o) {
365
- const a = T(o), l = [
366
- T(t),
367
- ...r.map(T)
368
- ], n = new Set(l);
369
- if (n.size !== l.length)
397
+ function Qe(e, t, r, n) {
398
+ const s = w(n), l = [
399
+ w(t),
400
+ ...r.map(w)
401
+ ], o = new Set(l);
402
+ if (o.size !== l.length)
370
403
  throw new Error(
371
404
  "Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
372
405
  );
373
- if (n.has(a))
406
+ if (o.has(s))
374
407
  throw new Error(
375
408
  "Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
376
409
  );
377
- const s = e.map(
378
- (h) => T(h.claimer_pubkey)
410
+ const a = e.map(
411
+ (h) => w(h.claimer_pubkey)
379
412
  );
380
- if (new Set(s).size !== s.length)
413
+ if (new Set(a).size !== a.length)
381
414
  throw new Error("Presign response contains duplicate claimer entries");
382
- const u = s.filter((h) => h !== a), i = new Set(u), p = l.filter((h) => !i.has(h)), c = u.filter((h) => !n.has(h));
415
+ const u = a.filter((h) => h !== s), i = new Set(u), p = l.filter((h) => !i.has(h)), c = u.filter((h) => !o.has(h));
383
416
  if (p.length > 0 || c.length > 0)
384
417
  throw new Error(
385
418
  "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (p.length > 0 ? ` (missing: ${p.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
386
419
  );
387
420
  }
388
- function W(e, t) {
421
+ function j(e, t) {
389
422
  return {
390
423
  vaultCoreVersion: t.vaultCoreVersion,
391
424
  payoutTxHex: e.payoutTxHex,
@@ -396,6 +429,7 @@ function W(e, t) {
396
429
  universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
397
430
  depositorBtcPubkey: t.depositorBtcPubkey,
398
431
  timelockPegin: t.timelockPegin,
432
+ timelockAssert: t.timelockAssert,
399
433
  registeredPayoutScriptPubKey: t.registeredPayoutScriptPubKey,
400
434
  claimerBtcPubkey: e.claimerPubkeyXOnly,
401
435
  commissionBps: t.commissionBps,
@@ -405,116 +439,112 @@ function W(e, t) {
405
439
  vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
406
440
  };
407
441
  }
408
- async function Ye(e, t, r, o) {
409
- const a = new we({
442
+ async function Ye(e, t, r, n) {
443
+ const s = new be({
410
444
  network: t.network,
411
445
  btcWallet: e
412
446
  }), l = r.length;
413
- o == null || o(0, l);
414
- let n;
415
- if (a.supportsBatchSigning())
416
- n = (await a.signPayoutTransactionsBatch(
417
- r.map((i) => W(i, t))
447
+ n == null || n(0, l);
448
+ let o;
449
+ if (s.supportsBatchSigning())
450
+ o = (await s.signPayoutTransactionsBatch(
451
+ r.map((i) => j(i, t))
418
452
  )).map((i) => i.payoutSignature);
419
453
  else {
420
- n = [];
454
+ o = [];
421
455
  for (let u = 0; u < r.length; u++) {
422
- o == null || o(u, l);
423
- const i = await a.signPayoutTransaction(
424
- W(r[u], t)
456
+ n == null || n(u, l);
457
+ const i = await s.signPayoutTransaction(
458
+ j(r[u], t)
425
459
  );
426
- n.push(i.signature);
460
+ o.push(i.signature);
427
461
  }
428
462
  }
429
- const s = {};
463
+ const a = {};
430
464
  for (let u = 0; u < r.length; u++)
431
- s[r[u].claimerPubkeyXOnly] = {
432
- payout_signature: n[u]
465
+ a[r[u].claimerPubkeyXOnly] = {
466
+ payout_signature: o[u]
433
467
  };
434
- return o == null || o(l, l), s;
468
+ return n == null || n(l, l), a;
435
469
  }
436
- async function $t(e) {
470
+ async function Bt(e) {
437
471
  const {
438
472
  statusReader: t,
439
473
  presignClient: r,
440
- btcWallet: o,
441
- peginTxid: a,
474
+ btcWallet: n,
475
+ peginTxid: s,
442
476
  depositorPk: l,
443
- signingContext: n,
444
- depositTerms: s,
445
- timeoutMs: u = Ge,
477
+ signingContext: o,
478
+ depositTerms: a,
479
+ timeoutMs: u = Xe,
446
480
  signal: i,
447
481
  onProgress: p
448
482
  } = e, c = await ne({
449
483
  statusReader: t,
450
- peginTxid: a,
451
- targetStatuses: qe,
484
+ peginTxid: s,
485
+ targetStatuses: Ge,
452
486
  timeoutMs: u,
453
487
  signal: i
454
488
  });
455
- if (ae.has(c))
489
+ if (oe.has(c))
456
490
  return;
457
- if (i == null || i.throwIfAborted(), s !== void 0 && s.baseFeeRate !== n.protocolFeeRate)
458
- throw new Error(
459
- `Deposit terms baseFeeRate (${s.baseFeeRate} sat/vB) does not match the vault's version-locked protocolFeeRate (${n.protocolFeeRate} sat/vB); refusing to sign payouts against terms built from a different params version.`
460
- );
461
- if (be(o)) {
462
- if (!s)
491
+ if (i == null || i.throwIfAborted(), a !== void 0 && qe(a, o), me(n)) {
492
+ if (!a)
463
493
  throw new Error(
464
494
  "runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume-path rebuild is not wired yet."
465
495
  );
466
- await o.approveDepositTerms(s);
496
+ await n.approveDepositTerms(a);
467
497
  }
468
498
  const h = await r.requestDepositorPresignTransactions(
469
499
  {
470
- pegin_txid: a,
500
+ pegin_txid: s,
471
501
  depositor_pk: l
472
502
  },
473
503
  i
474
504
  );
475
505
  i == null || i.throwIfAborted();
476
- const v = T(l);
506
+ const f = w(l);
477
507
  Qe(
478
508
  h.txs,
479
- n.vaultProviderBtcPubkey,
480
- n.vaultKeeperBtcPubkeys,
509
+ o.vaultProviderBtcPubkey,
510
+ o.vaultKeeperBtcPubkeys,
481
511
  l
482
512
  );
483
513
  const y = h.txs.filter(
484
- (P) => T(P.claimer_pubkey) !== v
485
- ), E = je(y), w = await Ye(
486
- o,
514
+ (v) => w(v.claimer_pubkey) !== f
515
+ ), T = je(y), x = await Ye(
487
516
  n,
488
- E,
517
+ o,
518
+ T,
489
519
  p
490
520
  );
491
521
  i == null || i.throwIfAborted();
492
- const m = await Xe({
522
+ const m = await Le({
493
523
  depositorGraph: h.depositor_graph,
494
- btcWallet: o,
524
+ btcWallet: n,
495
525
  signingContext: {
496
- vaultCoreVersion: n.vaultCoreVersion,
497
- peginTxHex: n.peginTxHex,
526
+ vaultCoreVersion: o.vaultCoreVersion,
527
+ peginTxHex: o.peginTxHex,
498
528
  depositorBtcPubkey: l,
499
- vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
500
- vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
501
- universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
502
- timelockPegin: n.timelockPegin,
503
- timelockAssert: n.timelockAssert,
504
- councilMembers: n.councilMembers,
505
- councilQuorum: n.councilQuorum,
506
- network: n.network,
507
- registeredPayoutScriptPubKey: n.registeredPayoutScriptPubKey,
508
- protocolFeeRate: n.protocolFeeRate,
509
- vkClaimerPayoutScriptPubKeys: n.vkClaimerPayoutScriptPubKeys,
510
- vpCommissionScriptPubKey: n.vpCommissionScriptPubKey
529
+ vaultProviderBtcPubkey: o.vaultProviderBtcPubkey,
530
+ vaultKeeperBtcPubkeys: o.vaultKeeperBtcPubkeys,
531
+ universalChallengerBtcPubkeys: o.universalChallengerBtcPubkeys,
532
+ timelockPegin: o.timelockPegin,
533
+ timelockAssert: o.timelockAssert,
534
+ councilMembers: o.councilMembers,
535
+ councilQuorum: o.councilQuorum,
536
+ network: o.network,
537
+ registeredPayoutScriptPubKey: o.registeredPayoutScriptPubKey,
538
+ protocolFeeRate: o.protocolFeeRate,
539
+ vkClaimerPayoutScriptPubKeys: o.vkClaimerPayoutScriptPubKeys,
540
+ vpCommissionScriptPubKey: o.vpCommissionScriptPubKey
511
541
  }
512
542
  });
513
543
  i == null || i.throwIfAborted();
514
- const b = { ...w };
544
+ const b = { ...x };
515
545
  b[d(l)] = m.payout_signatures, await r.submitDepositorPresignatures(
516
546
  {
517
- pegin_txid: a,
547
+ pegin_txid: s,
518
548
  depositor_pk: l,
519
549
  signatures: b,
520
550
  depositor_claimer_presignatures: m
@@ -523,248 +553,287 @@ async function $t(e) {
523
553
  );
524
554
  }
525
555
  const We = 300 * 1e3, Je = /* @__PURE__ */ new Set([
526
- x.PENDING_DEPOSITOR_WOTS_PK,
527
- ...oe
556
+ E.PENDING_DEPOSITOR_WOTS_PK,
557
+ ...re
528
558
  ]);
529
- async function Rt(e) {
559
+ async function At(e) {
530
560
  const {
531
561
  statusReader: t,
532
562
  wotsSubmitter: r,
533
- peginTxid: o,
534
- depositorPk: a,
563
+ peginTxid: n,
564
+ depositorPk: s,
535
565
  wotsPublicKeys: l,
536
- timeoutMs: n = We,
537
- signal: s
566
+ timeoutMs: o = We,
567
+ signal: a
538
568
  } = e;
539
- s == null || s.throwIfAborted();
569
+ a == null || a.throwIfAborted();
540
570
  const u = await ne({
541
571
  statusReader: t,
542
- peginTxid: o,
572
+ peginTxid: n,
543
573
  targetStatuses: Je,
544
- timeoutMs: n,
545
- signal: s
574
+ timeoutMs: o,
575
+ signal: a
546
576
  });
547
- oe.has(u) || (s == null || s.throwIfAborted(), await r.submitDepositorWotsKey(
577
+ re.has(u) || (a == null || a.throwIfAborted(), await r.submitDepositorWotsKey(
548
578
  {
549
- pegin_txid: o,
550
- depositor_pk: a,
579
+ pegin_txid: n,
580
+ depositor_pk: s,
551
581
  wots_public_keys: l
552
582
  },
553
- s
583
+ a
554
584
  ));
555
585
  }
556
- function N(e, t, r) {
557
- const o = `${e} operation key (admin=${t.ethAddress})`, a = Q(
586
+ function V(e) {
587
+ return e.registration || e.operation;
588
+ }
589
+ function Ze(e, t, r) {
590
+ const n = k(e);
591
+ return {
592
+ registration: n === k(t),
593
+ operation: n === k(r)
594
+ };
595
+ }
596
+ function q(e, t, r) {
597
+ const n = I(e);
598
+ return {
599
+ registration: Q(n, I(t)),
600
+ operation: Q(n, I(r))
601
+ };
602
+ }
603
+ function I(e) {
604
+ return e.map(k).sort();
605
+ }
606
+ function Q(e, t) {
607
+ return e.length === t.length && e.every((r, n) => r === t[n]);
608
+ }
609
+ async function Rt(e) {
610
+ const {
611
+ vaultProviderEthAddress: t,
612
+ hintBtcPubkey: r,
613
+ registrationBtcPubkey: n,
614
+ readCurrentOperationBtcPubkey: s,
615
+ context: l
616
+ } = e;
617
+ if (!r) return;
618
+ const o = k(r);
619
+ if (o === k(n)) return;
620
+ const a = k(
621
+ await s()
622
+ );
623
+ if (o !== a)
624
+ throw new Error(
625
+ `Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${l ? ` ${l}` : ""}`
626
+ );
627
+ }
628
+ function O(e, t, r) {
629
+ const n = `${e} operation key (admin=${t.ethAddress})`, s = X(
558
630
  t.btcPubKey,
559
631
  `${e} roster key (admin=${t.ethAddress})`
560
- ), l = Q(r, o);
632
+ ), l = X(r, n);
561
633
  return {
562
634
  adminAddress: t.ethAddress,
563
- genesisBtcPubkey: a,
635
+ genesisBtcPubkey: s,
564
636
  operationBtcPubkey: l,
565
- rotated: l !== a
637
+ rotated: l !== s
566
638
  };
567
639
  }
568
- function Ze(e) {
640
+ function et(e) {
569
641
  const t = /* @__PURE__ */ new Map();
570
642
  for (const r of e) {
571
- const o = t.get(r.operationBtcPubkey);
572
- if (o)
643
+ const n = t.get(r.operationBtcPubkey);
644
+ if (n)
573
645
  throw new Error(
574
- `Participant operation key collision: ${o} and ${r.adminAddress} both resolve to operation key ${r.operationBtcPubkey}`
646
+ `Participant operation key collision: ${n} and ${r.adminAddress} both resolve to operation key ${r.operationBtcPubkey}`
575
647
  );
576
648
  t.set(r.operationBtcPubkey, r.adminAddress);
577
649
  }
578
650
  }
579
- function se(e, t, r) {
651
+ function ae(e, t, r) {
580
652
  if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
581
653
  throw new Error(
582
654
  `Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
583
655
  );
584
- const o = N(
656
+ const n = O(
585
657
  "vault provider",
586
658
  {
587
659
  ethAddress: e.vaultProviderEthAddress,
588
660
  btcPubKey: e.vaultProviderGenesisBtcPubkey
589
661
  },
590
662
  t.vaultProvider
591
- ), a = e.vaultKeepers.map(
592
- (n, s) => N("vault keeper", n, t.vaultKeepers[s])
663
+ ), s = e.vaultKeepers.map(
664
+ (o, a) => O("vault keeper", o, t.vaultKeepers[a])
593
665
  ), l = e.universalChallengers.map(
594
- (n, s) => N("universal challenger", n, t.universalChallengers[s])
666
+ (o, a) => O("universal challenger", o, t.universalChallengers[a])
595
667
  );
596
- return Ze([
597
- o,
598
- ...a,
668
+ return et([
669
+ n,
670
+ ...s,
599
671
  ...l
600
672
  ]), {
601
- vaultProvider: o,
602
- vaultKeepers: a,
673
+ vaultProvider: n,
674
+ vaultKeepers: s,
603
675
  universalChallengers: l,
604
676
  // Derived from the pairs, never the reverse — see ParticipantKeySet.
605
- vaultKeeperOperationKeysSorted: a.map((n) => n.operationBtcPubkey).sort(),
606
- universalChallengerOperationKeysSorted: l.map((n) => n.operationBtcPubkey).sort(),
677
+ vaultKeeperOperationKeysSorted: s.map((o) => o.operationBtcPubkey).sort(),
678
+ universalChallengerOperationKeysSorted: l.map((o) => o.operationBtcPubkey).sort(),
607
679
  resolvedAt: r,
608
680
  query: e
609
681
  };
610
682
  }
611
- async function et(e) {
683
+ async function tt(e) {
612
684
  const t = await e.operationKeyReader.getCurrentOperationKeys(
613
685
  e.query
614
686
  );
615
- return se(e.query, t, { mode: "current" });
687
+ return ae(e.query, t, { mode: "current" });
616
688
  }
617
- async function tt(e) {
689
+ async function rt(e) {
618
690
  const t = await e.operationKeyReader.getOperationKeysAtEpochs(
619
691
  e.query,
620
692
  e.epochs
621
693
  );
622
- return se(e.query, t, {
694
+ return ae(e.query, t, {
623
695
  mode: "epochs",
624
696
  epochs: e.epochs
625
697
  });
626
698
  }
627
- const L = (e) => B(e).toLowerCase(), R = (e) => e.map(L).sort();
628
- function A(e, t) {
629
- return e.length === t.length && e.every((r, o) => r === t[o]);
630
- }
631
- async function At(e) {
699
+ const Y = (e) => e.map(k).sort();
700
+ async function Kt(e) {
632
701
  const {
633
702
  vaultRegistryReader: t,
634
703
  vaultKeeperReader: r,
635
- universalChallengerReader: o,
636
- vaultProviderEthAddress: a,
704
+ universalChallengerReader: n,
705
+ vaultProviderEthAddress: s,
637
706
  applicationEntryPoint: l,
638
- expectedVaultProviderBtcPubkey: n,
639
- expectedVaultKeeperBtcPubkeys: s,
707
+ expectedVaultProviderBtcPubkey: o,
708
+ expectedVaultKeeperBtcPubkeys: a,
640
709
  expectedUniversalChallengerBtcPubkeys: u,
641
710
  operationKeyReader: i,
642
711
  onIndexerServingOperationKeys: p,
643
712
  onIndexerHintsInconsistent: c
644
713
  } = e, [
645
714
  h,
646
- v,
715
+ f,
647
716
  y
648
717
  ] = await Promise.all([
649
- t.getVaultProviderBtcPubKey(a),
718
+ t.getVaultProviderBtcPubKey(s),
650
719
  r.getCurrentVaultKeepersVersion(l),
651
- o.getLatestUniversalChallengersVersion()
652
- ]), [E, w] = await Promise.all([
720
+ n.getLatestUniversalChallengersVersion()
721
+ ]), [T, x] = await Promise.all([
653
722
  r.getVaultKeepersByVersion(
654
723
  l,
655
- v
724
+ f
656
725
  ),
657
- o.getUniversalChallengersByVersion(
726
+ n.getUniversalChallengersByVersion(
658
727
  y
659
728
  )
660
729
  ]), m = {
661
- vaultProvider: L(h),
662
- vaultKeepers: R(E.map((f) => f.btcPubKey)),
663
- universalChallengers: R(w.map((f) => f.btcPubKey))
664
- }, b = await et({
730
+ vaultProvider: k(h),
731
+ vaultKeepers: Y(T.map((P) => P.btcPubKey)),
732
+ universalChallengers: Y(x.map((P) => P.btcPubKey))
733
+ }, b = await tt({
665
734
  operationKeyReader: i,
666
735
  query: {
667
- vaultProviderEthAddress: a,
736
+ vaultProviderEthAddress: s,
668
737
  vaultProviderGenesisBtcPubkey: `0x${h}`,
669
738
  applicationEntryPoint: l,
670
- vaultKeepers: E,
671
- universalChallengers: w
739
+ vaultKeepers: T,
740
+ universalChallengers: x
672
741
  }
673
- }), P = {
742
+ }), v = {
674
743
  vaultProvider: b.vaultProvider.operationBtcPubkey,
675
744
  vaultKeepers: [...b.vaultKeeperOperationKeysSorted],
676
745
  universalChallengers: [
677
746
  ...b.universalChallengerOperationKeysSorted
678
747
  ]
679
- }, C = L(n), _ = R(s), $ = R(u), g = {
680
- registration: C === m.vaultProvider,
681
- operation: C === P.vaultProvider
682
- }, z = {
683
- registration: A(_, m.vaultKeepers),
684
- operation: A(_, P.vaultKeepers)
685
- }, G = {
686
- registration: A(
687
- $,
688
- m.universalChallengers
689
- ),
690
- operation: A($, P.universalChallengers)
691
- }, V = (f) => f.registration || f.operation;
692
- if (!V(g))
748
+ }, S = Ze(
749
+ o,
750
+ m.vaultProvider,
751
+ v.vaultProvider
752
+ ), _ = q(
753
+ a,
754
+ m.vaultKeepers,
755
+ v.vaultKeepers
756
+ ), B = q(
757
+ u,
758
+ m.universalChallengers,
759
+ v.universalChallengers
760
+ );
761
+ if (!V(S))
693
762
  throw new Error(
694
- `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
763
+ `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
695
764
  );
696
- if (!V(z))
765
+ if (!V(_))
697
766
  throw new Error(
698
- `Vault keeper BTC pubkeys (v${v}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
767
+ `Vault keeper BTC pubkeys (v${f}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
699
768
  );
700
- if (!V(G))
769
+ if (!V(B))
701
770
  throw new Error(
702
771
  `Universal challenger BTC pubkeys (v${y}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
703
772
  );
704
- const q = [g, z, G], he = q.some((f) => f.registration && !f.operation), j = q.some((f) => f.operation && !f.registration);
705
- if (he && j) {
706
- const f = `Indexer participant hints are internally inconsistent for vault provider ${a}: some roles match the registration keys while others match the rotated operation keys.`;
707
- throw c == null || c(f), new Error(`${f} Refresh and try again.`);
773
+ const g = [S, _, B], pe = g.some((P) => P.registration && !P.operation), z = g.some((P) => P.operation && !P.registration);
774
+ if (pe && z) {
775
+ const P = `Indexer participant hints are internally inconsistent for vault provider ${s}: some roles match the registration keys while others match the rotated operation keys.`;
776
+ throw c == null || c(P), new Error(`${P} Refresh and try again.`);
708
777
  }
709
- return j && (p == null || p(
710
- `Indexer is serving rotated operation keys for vault provider ${a}`
778
+ return z && (p == null || p(
779
+ `Indexer is serving rotated operation keys for vault provider ${s}`
711
780
  )), {
712
- vaultProviderBtcPubkeyXOnly: P.vaultProvider,
713
- vaultKeeperBtcPubkeysSorted: P.vaultKeepers,
714
- universalChallengerBtcPubkeysSorted: P.universalChallengers,
715
- expectedAppVaultKeepersVersion: v,
781
+ vaultProviderBtcPubkeyXOnly: v.vaultProvider,
782
+ vaultKeeperBtcPubkeysSorted: v.vaultKeepers,
783
+ universalChallengerBtcPubkeysSorted: v.universalChallengers,
784
+ expectedAppVaultKeepersVersion: f,
716
785
  expectedUniversalChallengersVersion: y,
717
786
  registrationKeys: m,
718
787
  participantKeys: b
719
788
  };
720
789
  }
721
- function rt(e) {
790
+ function nt(e) {
722
791
  return /^[0-9a-fA-F]{64}$/.test(e);
723
792
  }
724
- function Bt(e) {
793
+ function Vt(e) {
725
794
  const {
726
795
  amountSats: t,
727
796
  minDeposit: r,
728
- maxDeposit: o,
729
- btcBalance: a,
797
+ maxDeposit: n,
798
+ btcBalance: s,
730
799
  estimatedFeeSats: l,
731
- depositorClaimValue: n
800
+ depositorClaimValue: o
732
801
  } = e;
733
- return !(t <= 0n || t < r || o && o > 0n && t > o || l == null || n == null || t + l + n > a);
802
+ return !(t <= 0n || t < r || n && n > 0n && t > n || l == null || o == null || t + l + o > s);
734
803
  }
735
- function Vt(e, t, r) {
804
+ function It(e, t, r) {
736
805
  return e <= 0n ? {
737
806
  valid: !1,
738
807
  error: "Deposit amount must be greater than zero"
739
808
  } : e < t ? {
740
809
  valid: !1,
741
- error: `Minimum deposit is ${k(t)} BTC`
810
+ error: `Minimum deposit is ${C(t)} BTC`
742
811
  } : r && r > 0n && e > r ? {
743
812
  valid: !1,
744
- error: `Maximum deposit is ${k(r)} BTC`
813
+ error: `Maximum deposit is ${C(r)} BTC`
745
814
  } : { valid: !0 };
746
815
  }
747
- function It(e) {
816
+ function Ot(e) {
748
817
  const { amount: t, effectiveRemaining: r } = e;
749
818
  return r === null ? { valid: !0 } : r === 0n ? {
750
819
  valid: !1,
751
820
  error: "Supply cap reached — deposits temporarily paused"
752
821
  } : t > r ? {
753
822
  valid: !1,
754
- error: `Vault size exceeds remaining capacity (${k(r)} BTC)`
823
+ error: `Vault size exceeds remaining capacity (${C(r)} BTC)`
755
824
  } : { valid: !0 };
756
825
  }
757
- function Kt(e, t) {
826
+ function Ht(e, t) {
758
827
  if (!e || e.length === 0)
759
828
  return {
760
829
  valid: !1,
761
830
  error: "At least one vault provider must be selected"
762
831
  };
763
832
  const r = t.map(
764
- (a) => a.toLowerCase()
833
+ (s) => s.toLowerCase()
765
834
  );
766
835
  return e.filter(
767
- (a) => !r.includes(a.toLowerCase())
836
+ (s) => !r.includes(s.toLowerCase())
768
837
  ).length > 0 ? {
769
838
  valid: !1,
770
839
  error: "Invalid vault provider selected"
@@ -776,191 +845,191 @@ function ot(e, t, r) {
776
845
  valid: !1,
777
846
  error: "At least one vault amount required"
778
847
  };
779
- for (let o = 0; o < e.length; o++) {
780
- const a = e[o];
781
- if (a <= 0n)
848
+ for (let n = 0; n < e.length; n++) {
849
+ const s = e[n];
850
+ if (s <= 0n)
782
851
  return {
783
852
  valid: !1,
784
- error: `Vault ${o + 1} amount must be positive`
853
+ error: `Vault ${n + 1} amount must be positive`
785
854
  };
786
- if (t && a < t)
855
+ if (t && s < t)
787
856
  return {
788
857
  valid: !1,
789
- error: `Vault ${o + 1} amount ${k(a)} BTC is below minimum deposit ${k(t)} BTC`
858
+ error: `Vault ${n + 1} amount ${C(s)} BTC is below minimum deposit ${C(t)} BTC`
790
859
  };
791
- if (r && a > r)
860
+ if (r && s > r)
792
861
  return {
793
862
  valid: !1,
794
- error: `Vault ${o + 1} amount ${k(a)} BTC exceeds maximum deposit ${k(r)} BTC`
863
+ error: `Vault ${n + 1} amount ${C(s)} BTC exceeds maximum deposit ${C(r)} BTC`
795
864
  };
796
865
  }
797
866
  return { valid: !0 };
798
867
  }
799
- function nt(e) {
868
+ function at(e) {
800
869
  const t = d(e);
801
- return rt(t) ? { valid: !0 } : {
870
+ return nt(t) ? { valid: !0 } : {
802
871
  valid: !1,
803
872
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
804
873
  };
805
874
  }
806
- function at(e) {
875
+ function st(e) {
807
876
  if (!e || e.length === 0)
808
877
  throw new Error(
809
878
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
810
879
  );
811
880
  }
812
- function st(e) {
881
+ function it(e) {
813
882
  if (!e || e.length === 0)
814
883
  throw new Error(
815
884
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
816
885
  );
817
886
  }
818
- function it(e) {
887
+ function ut(e) {
819
888
  if (e.length === 0)
820
889
  throw new Error("No spendable UTXOs available");
821
890
  }
822
- function Ot(e) {
891
+ function Nt(e) {
823
892
  const {
824
893
  vaultAmounts: t,
825
894
  confirmedUTXOs: r,
826
- vaultProviderBtcPubkey: o,
827
- vaultKeeperBtcPubkeys: a,
895
+ vaultProviderBtcPubkey: n,
896
+ vaultKeeperBtcPubkeys: s,
828
897
  universalChallengerBtcPubkeys: l,
829
- minDeposit: n,
830
- maxDeposit: s
898
+ minDeposit: o,
899
+ maxDeposit: a
831
900
  } = e, u = ot(
832
901
  t,
833
- n,
834
- s
902
+ o,
903
+ a
835
904
  );
836
905
  if (!u.valid)
837
906
  throw new Error(u.error);
838
- const i = nt(o);
907
+ const i = at(n);
839
908
  if (!i.valid)
840
909
  throw new Error(i.error);
841
- at(a), st(l), it(r);
910
+ st(s), it(l), ut(r);
842
911
  }
843
- class ie extends Error {
912
+ class se extends Error {
844
913
  constructor(t) {
845
914
  super(t), this.name = "ParticipantKeyDriftError";
846
915
  }
847
916
  }
848
- function Nt(e) {
849
- return e instanceof ie || e instanceof Error && e.name === "ParticipantKeyDriftError";
917
+ function Dt(e) {
918
+ return e instanceof se || e instanceof Error && e.name === "ParticipantKeyDriftError";
850
919
  }
851
- function J(e, t, r) {
852
- return t.length === r.length && t.every((o, a) => o === r[a]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
920
+ function W(e, t, r) {
921
+ return t.length === r.length && t.every((n, s) => n === r[s]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
853
922
  }
854
- async function Ht(e) {
855
- const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: a } = e, l = a.query;
856
- if (o.length === 0) return;
857
- const n = await t.getVaultKeyEpochsBatch(o), s = [];
858
- for (const [u, i] of n.entries()) {
859
- const p = o[u];
923
+ async function Ft(e) {
924
+ const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: n, expected: s } = e, l = s.query;
925
+ if (n.length === 0) return;
926
+ const o = await t.getVaultKeyEpochsBatch(n), a = [];
927
+ for (const [u, i] of o.entries()) {
928
+ const p = n[u];
860
929
  let c;
861
930
  try {
862
- c = await tt({
931
+ c = await rt({
863
932
  operationKeyReader: r,
864
933
  query: l,
865
934
  epochs: i
866
935
  });
867
936
  } catch (y) {
868
- s.push(
937
+ a.push(
869
938
  `vault ${p}: could not resolve participants at frozen epochs (vp=${i.vpKeyEpoch}, keeper=${i.appKeeperKeyEpoch}, uc=${i.ucKeyEpoch}): ${y.message}`
870
939
  );
871
940
  continue;
872
941
  }
873
- c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && s.push(
874
- `vault ${p}: vault provider key expected ${a.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
942
+ c.vaultProvider.operationBtcPubkey !== s.vaultProvider.operationBtcPubkey && a.push(
943
+ `vault ${p}: vault provider key expected ${s.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
875
944
  );
876
- const h = J(
945
+ const h = W(
877
946
  `vault ${p}: vault keeper keys`,
878
- a.vaultKeeperOperationKeysSorted,
947
+ s.vaultKeeperOperationKeysSorted,
879
948
  c.vaultKeeperOperationKeysSorted
880
949
  );
881
- h && s.push(h);
882
- const v = J(
950
+ h && a.push(h);
951
+ const f = W(
883
952
  `vault ${p}: universal challenger keys`,
884
- a.universalChallengerOperationKeysSorted,
953
+ s.universalChallengerOperationKeysSorted,
885
954
  c.universalChallengerOperationKeysSorted
886
955
  );
887
- v && s.push(v);
956
+ f && a.push(f);
888
957
  }
889
- if (s.length > 0)
890
- throw new ie(
891
- `Aborting BTC broadcast: participant operation keys changed during registration (${s.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
958
+ if (a.length > 0)
959
+ throw new se(
960
+ `Aborting BTC broadcast: participant operation keys changed during registration (${a.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
892
961
  );
893
962
  }
894
- class ue extends Error {
963
+ class ie extends Error {
895
964
  constructor(t) {
896
965
  super(t), this.name = "RegisteredVaultVersionMismatchError";
897
966
  }
898
967
  }
899
- function Dt(e) {
900
- return e instanceof ue || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
968
+ function Mt(e) {
969
+ return e instanceof ie || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
901
970
  }
902
- async function Ft(e) {
971
+ async function Ut(e) {
903
972
  const {
904
973
  vaultRegistryReader: t,
905
974
  vaultIds: r,
906
- expectedOffchainParamsVersion: o,
907
- expectedAppVaultKeepersVersion: a,
975
+ expectedOffchainParamsVersion: n,
976
+ expectedAppVaultKeepersVersion: s,
908
977
  expectedUniversalChallengersVersion: l,
909
- expectedVaultCoreVersion: n
910
- } = e, s = await t.getProtocolInfoBatch(r), u = [];
911
- if (s.forEach((i, p) => {
978
+ expectedVaultCoreVersion: o
979
+ } = e, a = await t.getProtocolInfoBatch(r), u = [];
980
+ if (a.forEach((i, p) => {
912
981
  const c = r[p];
913
- i.offchainParamsVersion !== o && u.push(
914
- `vault ${c}: offchainParams expected v${o}, got v${i.offchainParamsVersion}`
915
- ), i.appVaultKeepersVersion !== a && u.push(
916
- `vault ${c}: appVaultKeepers expected v${a}, got v${i.appVaultKeepersVersion}`
982
+ i.offchainParamsVersion !== n && u.push(
983
+ `vault ${c}: offchainParams expected v${n}, got v${i.offchainParamsVersion}`
984
+ ), i.appVaultKeepersVersion !== s && u.push(
985
+ `vault ${c}: appVaultKeepers expected v${s}, got v${i.appVaultKeepersVersion}`
917
986
  ), i.universalChallengersVersion !== l && u.push(
918
987
  `vault ${c}: universalChallengers expected v${l}, got v${i.universalChallengersVersion}`
919
- ), i.vaultCoreVersion !== n && u.push(
920
- `vault ${c}: vaultCoreVersion expected v${n} (build-time active), got v${i.vaultCoreVersion}`
988
+ ), i.vaultCoreVersion !== o && u.push(
989
+ `vault ${c}: vaultCoreVersion expected v${o} (build-time active), got v${i.vaultCoreVersion}`
921
990
  );
922
991
  }), u.length > 0)
923
- throw new ue(
992
+ throw new ie(
924
993
  `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${u.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
925
994
  );
926
995
  }
927
- var le = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(le || {});
928
- const ut = /* @__PURE__ */ new Set([
996
+ var ue = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ue || {});
997
+ const lt = /* @__PURE__ */ new Set([
929
998
  "PayoutBroadcast",
930
999
  "PayoutBlocked"
931
1000
  /* PAYOUT_BLOCKED */
932
1001
  ]);
933
- function Mt(e) {
934
- return Object.values(le).includes(
1002
+ function Lt(e) {
1003
+ return Object.values(ue).includes(
935
1004
  e
936
1005
  );
937
1006
  }
938
- function Ut(e) {
939
- return !!e && ut.has(e);
1007
+ function zt(e) {
1008
+ return !!e && lt.has(e);
940
1009
  }
941
- class lt extends Error {
942
- constructor(r, o) {
943
- super(`Refund not yet mature (BIP68 not final): ${o.message}`);
944
- I(this, "vaultId");
945
- I(this, "cause");
946
- this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
1010
+ class ct extends Error {
1011
+ constructor(r, n) {
1012
+ super(`Refund not yet mature (BIP68 not final): ${n.message}`);
1013
+ A(this, "vaultId");
1014
+ A(this, "cause");
1015
+ this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
947
1016
  }
948
1017
  }
949
- const ct = /^0x[0-9a-fA-F]{64}$/, pt = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, ce = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, pe = 160, Z = 2e3, ee = 10n, te = 100n;
950
- function Lt(e) {
1018
+ const pt = /^0x[0-9a-fA-F]{64}$/, ht = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, le = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, ce = 160, J = 2e3, Z = 10n, ee = 100n;
1019
+ function Xt(e) {
951
1020
  if (!Number.isFinite(e) || e <= 0)
952
1021
  throw new Error(
953
1022
  `feeRateSatsVb must be a positive finite number, got ${e}`
954
1023
  );
955
- return BigInt(Math.ceil(e * pe));
1024
+ return BigInt(Math.ceil(e * ce));
956
1025
  }
957
- const ht = 1, dt = /non-BIP68-final/i;
958
- function X(e, t) {
1026
+ const dt = 1, gt = /non-BIP68-final/i;
1027
+ function U(e, t) {
959
1028
  if (e.length !== 66)
960
1029
  throw new Error(
961
1030
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
962
1031
  );
963
- if (!ct.test(e))
1032
+ if (!pt.test(e))
964
1033
  throw new Error(
965
1034
  `${t} must contain only hex characters after the 0x prefix`
966
1035
  );
@@ -969,8 +1038,8 @@ function H(e, t) {
969
1038
  if (!Number.isInteger(e) || e < 0)
970
1039
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
971
1040
  }
972
- function gt(e) {
973
- if (X(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1041
+ function ft(e) {
1042
+ if (U(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
974
1043
  throw new Error(
975
1044
  `htlcVout must be a non-negative integer, got ${e.htlcVout}`
976
1045
  );
@@ -981,14 +1050,14 @@ function gt(e) {
981
1050
  `htlcVout ${e.htlcVout} is out of range for batch of size ${e.batch.length}`
982
1051
  );
983
1052
  for (let r = 0; r < e.batch.length; r++) {
984
- const o = e.batch[r];
985
- if (X(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1053
+ const n = e.batch[r];
1054
+ if (U(n.hashlock, `batch[${r}].hashlock`), !Number.isInteger(n.htlcVout) || n.htlcVout !== r)
986
1055
  throw new Error(
987
- `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
1056
+ `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${n.htlcVout}`
988
1057
  );
989
- if (typeof o.amount != "bigint" || o.amount <= 0n)
1058
+ if (typeof n.amount != "bigint" || n.amount <= 0n)
990
1059
  throw new Error(
991
- `batch[${r}].amount must be a positive bigint, got ${o.amount}`
1060
+ `batch[${r}].amount must be a positive bigint, got ${n.amount}`
992
1061
  );
993
1062
  }
994
1063
  const t = e.batch[e.htlcVout];
@@ -1003,24 +1072,24 @@ function gt(e) {
1003
1072
  if (H(e.offchainParamsVersion, "offchainParamsVersion"), H(e.appVaultKeepersVersion, "appVaultKeepersVersion"), H(
1004
1073
  e.universalChallengersVersion,
1005
1074
  "universalChallengersVersion"
1006
- ), Ae(
1075
+ ), Be(
1007
1076
  e.vaultCoreVersion,
1008
1077
  "VaultRefundData.vaultCoreVersion"
1009
1078
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
1010
1079
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
1011
- if (!pt.test(e.unsignedPrePeginTxHex))
1080
+ if (!ht.test(e.unsignedPrePeginTxHex))
1012
1081
  throw new Error(
1013
1082
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
1014
1083
  );
1015
- if (!e.depositorBtcPubkey || !ce.test(e.depositorBtcPubkey))
1084
+ if (!e.depositorBtcPubkey || !le.test(e.depositorBtcPubkey))
1016
1085
  throw new Error(
1017
1086
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
1018
1087
  );
1019
1088
  if (typeof e.amount != "bigint" || e.amount <= 0n)
1020
1089
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
1021
1090
  }
1022
- function ft(e) {
1023
- if (!e.vaultProviderPubkey || !ce.test(e.vaultProviderPubkey))
1091
+ function yt(e) {
1092
+ if (!e.vaultProviderPubkey || !le.test(e.vaultProviderPubkey))
1024
1093
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
1025
1094
  if (e.vaultKeeperPubkeys.length === 0)
1026
1095
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -1050,59 +1119,59 @@ function vt(e) {
1050
1119
  try {
1051
1120
  t.finalizeAllInputs();
1052
1121
  } catch (r) {
1053
- const o = r instanceof Error ? r.message : String(r);
1054
- if (!o.includes("already finalized"))
1055
- throw new Error(`Failed to finalize refund PSBT: ${o}`);
1122
+ const n = r instanceof Error ? r.message : String(r);
1123
+ if (!n.includes("already finalized"))
1124
+ throw new Error(`Failed to finalize refund PSBT: ${n}`);
1056
1125
  }
1057
1126
  return t.extractTransaction().toHex();
1058
1127
  }
1059
- async function Xt(e) {
1128
+ async function Gt(e) {
1060
1129
  const {
1061
1130
  vaultId: t,
1062
1131
  readVault: r,
1063
- readPrePeginContext: o,
1064
- feeRate: a,
1132
+ readPrePeginContext: n,
1133
+ feeRate: s,
1065
1134
  signPsbt: l,
1066
- broadcastTx: n,
1067
- signal: s
1135
+ broadcastTx: o,
1136
+ signal: a
1068
1137
  } = e;
1069
- s == null || s.throwIfAborted(), X(t, "vaultId");
1138
+ a == null || a.throwIfAborted(), U(t, "vaultId");
1070
1139
  const u = await r();
1071
- gt(u), s == null || s.throwIfAborted();
1072
- const i = await o(u);
1073
- if (ft(i), s == null || s.throwIfAborted(), !Number.isFinite(a) || a <= 0)
1074
- throw new Error(`feeRate must be a positive number, got ${a}`);
1075
- if (a > Z)
1140
+ ft(u), a == null || a.throwIfAborted();
1141
+ const i = await n(u);
1142
+ if (yt(i), a == null || a.throwIfAborted(), !Number.isFinite(s) || s <= 0)
1143
+ throw new Error(`feeRate must be a positive number, got ${s}`);
1144
+ if (s > J)
1076
1145
  throw new Error(
1077
- `feeRate ${a} sat/vB exceeds refund safety cap ${Z} sat/vB; refusing to sign refund.`
1146
+ `feeRate ${s} sat/vB exceeds refund safety cap ${J} sat/vB; refusing to sign refund.`
1078
1147
  );
1079
- const p = BigInt(Math.ceil(a * pe)), c = u.amount * ee / te;
1148
+ const p = BigInt(Math.ceil(s * ce)), c = u.amount * Z / ee;
1080
1149
  if (p > c)
1081
1150
  throw new Error(
1082
- `Refund fee ${p} sats exceeds the per-vault safety cap of ${c} sats (${ee}/${te} of vault.amount=${u.amount}); refusing to sign refund.`
1151
+ `Refund fee ${p} sats exceeds the per-vault safety cap of ${c} sats (${Z}/${ee} of vault.amount=${u.amount}); refusing to sign refund.`
1083
1152
  );
1084
- s == null || s.throwIfAborted();
1085
- const h = B(
1153
+ a == null || a.throwIfAborted();
1154
+ const h = L(
1086
1155
  u.depositorBtcPubkey
1087
- ), v = d(u.unsignedPrePeginTxHex), y = xe(v);
1156
+ ), f = d(u.unsignedPrePeginTxHex), y = we(f);
1088
1157
  if (y !== void 0 && y.vout !== u.batch.length)
1089
1158
  throw new Error(
1090
1159
  `Auth-anchor OP_RETURN at vout ${y.vout} does not match batch size (${u.batch.length} HTLC outputs expect the anchor at vout ${u.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
1091
1160
  );
1092
- const E = y == null ? void 0 : y.hash;
1093
- let w;
1161
+ const T = y == null ? void 0 : y.hash;
1162
+ let x;
1094
1163
  try {
1095
- w = S.fromHex(v);
1164
+ x = $.fromHex(f);
1096
1165
  } catch (g) {
1097
1166
  throw new Error(
1098
1167
  `Failed to parse funded Pre-PegIn transaction hex: ${g instanceof Error ? g.message : String(g)}`
1099
1168
  );
1100
1169
  }
1101
- if (w.outs.length < u.batch.length)
1170
+ if (x.outs.length < u.batch.length)
1102
1171
  throw new Error(
1103
- `Funded Pre-PegIn tx has ${w.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1172
+ `Funded Pre-PegIn tx has ${x.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1104
1173
  );
1105
- const { psbtHex: m } = await Re({
1174
+ const { psbtHex: m } = await _e({
1106
1175
  prePeginParams: {
1107
1176
  vaultCoreVersion: u.vaultCoreVersion,
1108
1177
  depositorPubkey: h,
@@ -1124,9 +1193,9 @@ async function Xt(e) {
1124
1193
  councilQuorum: i.councilQuorum,
1125
1194
  councilSize: i.councilSize,
1126
1195
  network: i.network,
1127
- authAnchorHash: E
1196
+ authAnchorHash: T
1128
1197
  },
1129
- fundedPrePeginTxHex: v,
1198
+ fundedPrePeginTxHex: f,
1130
1199
  htlcVout: u.htlcVout,
1131
1200
  refundFee: p,
1132
1201
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
@@ -1135,65 +1204,69 @@ async function Xt(e) {
1135
1204
  // unspendable PSBT. Match the `hashlocks` array handling above.
1136
1205
  hashlock: d(u.hashlock)
1137
1206
  });
1138
- s == null || s.throwIfAborted();
1139
- const b = U(
1207
+ a == null || a.throwIfAborted();
1208
+ const b = M(
1140
1209
  u.depositorBtcPubkey,
1141
- ht
1142
- ), P = await l(m, b);
1143
- D({
1210
+ dt
1211
+ ), v = await l(m, b);
1212
+ N({
1144
1213
  requestedPsbtHex: m,
1145
- returnedPsbtHex: P
1214
+ returnedPsbtHex: v
1146
1215
  });
1147
- const C = 0, _ = F(
1148
- P,
1216
+ const S = 0, _ = D(
1217
+ v,
1149
1218
  h,
1150
- C
1219
+ S
1151
1220
  );
1152
- M({
1221
+ F({
1153
1222
  requestedPsbtHex: m,
1154
1223
  signatureHex: _,
1155
1224
  signerXOnlyPubkeyHex: h,
1156
- inputIndex: C
1225
+ inputIndex: S
1157
1226
  });
1158
- const $ = vt(P);
1159
- s == null || s.throwIfAborted();
1227
+ const B = vt(v);
1228
+ a == null || a.throwIfAborted();
1160
1229
  try {
1161
- return await n($);
1230
+ return await o(B);
1162
1231
  } catch (g) {
1163
- throw g instanceof Error && dt.test(g.message) ? new lt(t, g) : g;
1232
+ throw g instanceof Error && gt.test(g.message) ? new ct(t, g) : g;
1164
1233
  }
1165
1234
  }
1166
1235
  export {
1167
- pe as A,
1168
- lt as B,
1169
- le as C,
1170
- ie as P,
1171
- ue as R,
1236
+ Xt as A,
1237
+ ct as B,
1238
+ ue as C,
1239
+ ee as D,
1240
+ Z as E,
1241
+ J as F,
1242
+ ce as G,
1243
+ se as P,
1244
+ ie as R,
1172
1245
  _t as a,
1173
- Rt as b,
1174
- Vt as c,
1175
- Ot as d,
1176
- Kt as e,
1177
- It as f,
1246
+ At as b,
1247
+ It as c,
1248
+ Nt as d,
1249
+ Ht as e,
1250
+ Ot as f,
1178
1251
  ot as g,
1179
- nt as h,
1180
- Bt as i,
1181
- Nt as j,
1182
- Ht as k,
1183
- Dt as l,
1184
- Ft as m,
1185
- et as n,
1186
- tt as o,
1187
- Mt as p,
1188
- Ut as q,
1189
- $t as r,
1190
- Xe as s,
1191
- Xt as t,
1192
- Lt as u,
1193
- At as v,
1252
+ at as h,
1253
+ Vt as i,
1254
+ Dt as j,
1255
+ Ft as k,
1256
+ Mt as l,
1257
+ Ut as m,
1258
+ Rt as n,
1259
+ V as o,
1260
+ Ze as p,
1261
+ q,
1262
+ Bt as r,
1263
+ Le as s,
1264
+ tt as t,
1265
+ rt as u,
1266
+ Kt as v,
1194
1267
  ne as w,
1195
- te as x,
1196
- ee as y,
1197
- Z as z
1268
+ Lt as x,
1269
+ zt as y,
1270
+ Gt as z
1198
1271
  };
1199
- //# sourceMappingURL=buildAndBroadcastRefund-Bo3AlqCk.js.map
1272
+ //# sourceMappingURL=buildAndBroadcastRefund-DBA-Mp4I.js.map