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