@babylonlabs-io/ts-sdk 0.37.3 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/BTCVaultRegistry.abi-CHFGevwa.cjs +2 -0
  2. package/dist/BTCVaultRegistry.abi-CHFGevwa.cjs.map +1 -0
  3. package/dist/{BTCVaultRegistry.abi-DbJ5lsFJ.js → BTCVaultRegistry.abi-Cq9-JlqT.js} +38 -2
  4. package/dist/BTCVaultRegistry.abi-Cq9-JlqT.js.map +1 -0
  5. package/dist/PayoutManager-D29D-K-V.js +250 -0
  6. package/dist/PayoutManager-D29D-K-V.js.map +1 -0
  7. package/dist/PayoutManager-DERMRuUU.cjs +2 -0
  8. package/dist/PayoutManager-DERMRuUU.cjs.map +1 -0
  9. package/dist/{PeginManager-HCYTUzh6.js → PeginManager-Cp2Tn5sH.js} +444 -406
  10. package/dist/PeginManager-Cp2Tn5sH.js.map +1 -0
  11. package/dist/PeginManager-DaDs-bGr.cjs +2 -0
  12. package/dist/PeginManager-DaDs-bGr.cjs.map +1 -0
  13. package/dist/{ProtocolParams.abi-DXu8L0Fn.js → ProtocolParams.abi-C2brDWTI.js} +8 -3
  14. package/dist/ProtocolParams.abi-C2brDWTI.js.map +1 -0
  15. package/dist/ProtocolParams.abi-DQhcqsNr.cjs +2 -0
  16. package/dist/ProtocolParams.abi-DQhcqsNr.cjs.map +1 -0
  17. package/dist/assertPsbtUnsignedTxMatches-fNkAaZZm.cjs +2 -0
  18. package/dist/assertPsbtUnsignedTxMatches-fNkAaZZm.cjs.map +1 -0
  19. package/dist/assertPsbtUnsignedTxMatches-mTAnLhCz.js +340 -0
  20. package/dist/assertPsbtUnsignedTxMatches-mTAnLhCz.js.map +1 -0
  21. package/dist/{buildAndBroadcastRefund-CI_x6OtX.js → buildAndBroadcastRefund-B5cOyUzj.js} +234 -227
  22. package/dist/buildAndBroadcastRefund-B5cOyUzj.js.map +1 -0
  23. package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs +2 -0
  24. package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs.map +1 -0
  25. package/dist/{challengeAssert-D7OCrDIc.js → challengeAssert-CBp4mEs0.js} +2 -2
  26. package/dist/{challengeAssert-D7OCrDIc.js.map → challengeAssert-CBp4mEs0.js.map} +1 -1
  27. package/dist/{challengeAssert-CMb7r-je.cjs → challengeAssert-CNRdpCzm.cjs} +2 -2
  28. package/dist/{challengeAssert-CMb7r-je.cjs.map → challengeAssert-CNRdpCzm.cjs.map} +1 -1
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.js +38 -38
  31. package/dist/noPayout-jtZsoOzY.cjs +2 -0
  32. package/dist/noPayout-jtZsoOzY.cjs.map +1 -0
  33. package/dist/noPayout-qbaSEKGC.js +145 -0
  34. package/dist/noPayout-qbaSEKGC.js.map +1 -0
  35. package/dist/peginInput-BPRB9tUi.js +104 -0
  36. package/dist/peginInput-BPRB9tUi.js.map +1 -0
  37. package/dist/peginInput-DH6X4ITS.cjs +2 -0
  38. package/dist/peginInput-DH6X4ITS.cjs.map +1 -0
  39. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
  40. package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
  41. package/dist/tbv/core/clients/eth/types.d.ts +12 -1
  42. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  43. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  44. package/dist/tbv/core/clients/index.cjs +1 -1
  45. package/dist/tbv/core/clients/index.js +9 -9
  46. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +0 -9
  47. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
  48. package/dist/tbv/core/clients/vault-provider/types.d.ts +38 -21
  49. package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
  50. package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
  51. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +36 -2
  52. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  53. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +6 -2
  54. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -1
  55. package/dist/tbv/core/contracts/index.cjs +1 -1
  56. package/dist/tbv/core/contracts/index.js +2 -2
  57. package/dist/tbv/core/index.cjs +1 -1
  58. package/dist/tbv/core/index.js +25 -25
  59. package/dist/tbv/core/managers/PeginManager.d.ts +5 -0
  60. package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
  61. package/dist/tbv/core/managers/index.cjs +1 -1
  62. package/dist/tbv/core/managers/index.js +2 -2
  63. package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts +37 -0
  64. package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts.map +1 -1
  65. package/dist/tbv/core/managers/pegin/index.d.ts +1 -1
  66. package/dist/tbv/core/managers/pegin/index.d.ts.map +1 -1
  67. package/dist/tbv/core/primitives/index.cjs +1 -1
  68. package/dist/tbv/core/primitives/index.js +17 -17
  69. package/dist/tbv/core/primitives/psbt/__tests__/refund.test.d.ts +12 -0
  70. package/dist/tbv/core/primitives/psbt/__tests__/refund.test.d.ts.map +1 -0
  71. package/dist/tbv/core/primitives/psbt/pegin.d.ts +5 -0
  72. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  73. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
  74. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  75. package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
  76. package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts +4 -2
  77. package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts.map +1 -1
  78. package/dist/tbv/core/services/index.cjs +1 -1
  79. package/dist/tbv/core/services/index.js +2 -2
  80. package/dist/tbv/core/services/pegout/state.d.ts +5 -8
  81. package/dist/tbv/core/services/pegout/state.d.ts.map +1 -1
  82. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
  83. package/dist/tbv/index.cjs +1 -1
  84. package/dist/tbv/index.js +25 -25
  85. package/dist/tbv/integrations/aave/clients/query.d.ts.map +1 -1
  86. package/dist/tbv/integrations/aave/index.cjs +1 -1
  87. package/dist/tbv/integrations/aave/index.cjs.map +1 -1
  88. package/dist/tbv/integrations/aave/index.js +23 -22
  89. package/dist/tbv/integrations/aave/index.js.map +1 -1
  90. package/dist/tbv/integrations/aave/types.d.ts +6 -0
  91. package/dist/tbv/integrations/aave/types.d.ts.map +1 -1
  92. package/dist/types-D2jcXfm7.cjs +2 -0
  93. package/dist/types-D2jcXfm7.cjs.map +1 -0
  94. package/dist/types-TOmEvvRy.js +322 -0
  95. package/dist/types-TOmEvvRy.js.map +1 -0
  96. package/dist/{vault-registry-reader-Blhu9FW2.js → vault-registry-reader-BrARgFre.js} +207 -202
  97. package/dist/vault-registry-reader-BrARgFre.js.map +1 -0
  98. package/dist/vault-registry-reader-CbJHSxVe.cjs +2 -0
  99. package/dist/vault-registry-reader-CbJHSxVe.cjs.map +1 -0
  100. package/package.json +1 -1
  101. package/dist/BTCVaultRegistry.abi-DbJ5lsFJ.js.map +0 -1
  102. package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs +0 -2
  103. package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs.map +0 -1
  104. package/dist/PayoutManager-BfT0V-tm.cjs +0 -2
  105. package/dist/PayoutManager-BfT0V-tm.cjs.map +0 -1
  106. package/dist/PayoutManager-Cf51DBcu.js +0 -208
  107. package/dist/PayoutManager-Cf51DBcu.js.map +0 -1
  108. package/dist/PeginManager-CTznAVPT.cjs +0 -2
  109. package/dist/PeginManager-CTznAVPT.cjs.map +0 -1
  110. package/dist/PeginManager-HCYTUzh6.js.map +0 -1
  111. package/dist/ProtocolParams.abi-BmvHwQJV.cjs +0 -2
  112. package/dist/ProtocolParams.abi-BmvHwQJV.cjs.map +0 -1
  113. package/dist/ProtocolParams.abi-DXu8L0Fn.js.map +0 -1
  114. package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs +0 -2
  115. package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs.map +0 -1
  116. package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js +0 -266
  117. package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js.map +0 -1
  118. package/dist/buildAndBroadcastRefund-Bj2e94CC.cjs +0 -2
  119. package/dist/buildAndBroadcastRefund-Bj2e94CC.cjs.map +0 -1
  120. package/dist/buildAndBroadcastRefund-CI_x6OtX.js.map +0 -1
  121. package/dist/noPayout-B6s8vrW6.cjs +0 -2
  122. package/dist/noPayout-B6s8vrW6.cjs.map +0 -1
  123. package/dist/noPayout-BhgknZBx.js +0 -141
  124. package/dist/noPayout-BhgknZBx.js.map +0 -1
  125. package/dist/peginInput-57FK2O99.cjs +0 -2
  126. package/dist/peginInput-57FK2O99.cjs.map +0 -1
  127. package/dist/peginInput-CYJzbuwA.js +0 -177
  128. package/dist/peginInput-CYJzbuwA.js.map +0 -1
  129. package/dist/types-DnyyBNcC.cjs +0 -2
  130. package/dist/types-DnyyBNcC.cjs.map +0 -1
  131. package/dist/types-TiIjyo2b.js +0 -320
  132. package/dist/types-TiIjyo2b.js.map +0 -1
  133. package/dist/vault-registry-reader-7gOYnrQD.cjs +0 -2
  134. package/dist/vault-registry-reader-7gOYnrQD.cjs.map +0 -1
  135. package/dist/vault-registry-reader-Blhu9FW2.js.map +0 -1
@@ -1,16 +1,16 @@
1
- var W = Object.defineProperty;
2
- var Q = (e, t, r) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var C = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { B as j } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
5
- import { e as Y, v as q, s as h, u as N, p as k, d as J, f as m } from "./bitcoin-B5aNKtsk.js";
6
- import { v as Z, P as ee } from "./PayoutManager-Cf51DBcu.js";
7
- import { c as te, a as re, R as ne, d as L, D as x } from "./types-TiIjyo2b.js";
8
- import { Transaction as T, Psbt as oe } from "bitcoinjs-lib";
9
- import { a as se, b as ae, c as R, e as I } from "./assertPsbtUnsignedTxMatches-Dry5dTfl.js";
10
- import { c as ie, a as ue, b as le } from "./noPayout-BhgknZBx.js";
1
+ var G = Object.defineProperty;
2
+ var Q = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var S = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { B as j } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
5
+ import { e as q, v as W, s as h, u as N, p as k, d as Y, f as x } from "./bitcoin-B5aNKtsk.js";
6
+ import { v as J, P as Z, f as ee } from "./PayoutManager-D29D-K-V.js";
7
+ import { D as v, c as te, a as re, R as ne, d as O } from "./types-TOmEvvRy.js";
8
+ import { Transaction as _, Psbt as oe } from "bitcoinjs-lib";
9
+ import { c as se, d as ae, f as V, e as I } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
10
+ import { c as ie, a as ue, b as le } from "./noPayout-qbaSEKGC.js";
11
11
  import { c as $ } from "./signing-DaLvGwQe.js";
12
12
  const ce = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^0x([0-9a-fA-F]{2})*$/;
13
- function S(e, t) {
13
+ function A(e, t) {
14
14
  if (e.length !== 66)
15
15
  throw new Error(
16
16
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
@@ -26,7 +26,7 @@ function pe(e, t) {
26
26
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
27
27
  );
28
28
  }
29
- function ge(e, t) {
29
+ function fe(e, t) {
30
30
  if (!he.test(e))
31
31
  throw new Error(
32
32
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
@@ -37,31 +37,31 @@ async function tt(e) {
37
37
  btcVaultRegistryAddress: t,
38
38
  vaultId: r,
39
39
  hashlock: n,
40
- activationMetadata: s,
40
+ activationMetadata: o,
41
41
  writeContract: u,
42
42
  signal: a
43
43
  } = e;
44
- a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), S(r, "vaultId");
45
- const i = Y(e.secret);
46
- if (S(i, "secret"), n !== void 0 && (S(n, "hashlock"), !Z(i, n)))
44
+ a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), A(r, "vaultId");
45
+ const i = q(e.secret);
46
+ if (A(i, "secret"), n !== void 0 && (A(n, "hashlock"), !J(i, n)))
47
47
  throw new Error(
48
48
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
49
49
  );
50
- return ge(s, "activationMetadata"), u({
50
+ return fe(o, "activationMetadata"), u({
51
51
  address: t,
52
52
  abi: j,
53
53
  functionName: "activateVaultWithSecret",
54
- args: [r, i, s]
54
+ args: [r, i, o]
55
55
  });
56
56
  }
57
- const fe = 1e4;
57
+ const ge = 1e4;
58
58
  async function D(e) {
59
59
  const {
60
60
  statusReader: t,
61
61
  peginTxid: r,
62
62
  targetStatuses: n,
63
- timeoutMs: s,
64
- pollIntervalMs: u = fe,
63
+ timeoutMs: o,
64
+ pollIntervalMs: u = ge,
65
65
  signal: a
66
66
  } = e, i = Date.now();
67
67
  for (; ; ) {
@@ -69,31 +69,31 @@ async function D(e) {
69
69
  throw new Error(
70
70
  `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
71
71
  );
72
- if (Date.now() - i >= s)
72
+ if (Date.now() - i >= o)
73
73
  throw new Error(
74
- `Polling timeout after ${s}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
74
+ `Polling timeout after ${o}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
75
75
  );
76
76
  try {
77
- const o = await t.getPeginStatus(
77
+ const s = await t.getPeginStatus(
78
78
  { pegin_txid: r },
79
79
  a
80
80
  );
81
- if (o.pegin_txid.toLowerCase() !== r.toLowerCase())
81
+ if (s.pegin_txid.toLowerCase() !== r.toLowerCase())
82
82
  throw new Error(
83
- `getPeginStatus returned status for pegin ${o.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
83
+ `getPeginStatus returned status for pegin ${s.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
84
84
  );
85
- const l = o.status;
86
- if (n.has(l))
85
+ const l = s.status;
86
+ if (n.has(l) || l === v.ACTIVATED)
87
87
  return l;
88
- if (te.has(l) && !n.has(l))
88
+ if (l === v.EXPIRED || te.has(l))
89
89
  throw new Error(
90
90
  `Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
91
91
  );
92
- } catch (o) {
93
- if (!(o instanceof re && o.code === ne.NOT_FOUND || o instanceof Error && o.message.includes("PegIn not found")))
94
- throw o;
92
+ } catch (s) {
93
+ if (!(s instanceof re && s.code === ne.PEGIN_NOT_FOUND))
94
+ throw s;
95
95
  }
96
- await new Promise((o, l) => {
96
+ await new Promise((s, l) => {
97
97
  const d = () => {
98
98
  clearTimeout(c), l(
99
99
  new Error(
@@ -101,38 +101,38 @@ async function D(e) {
101
101
  )
102
102
  );
103
103
  }, c = setTimeout(() => {
104
- a == null || a.removeEventListener("abort", d), o();
104
+ a == null || a.removeEventListener("abort", d), s();
105
105
  }, u);
106
106
  a == null || a.addEventListener("abort", d, { once: !0 });
107
107
  });
108
108
  }
109
109
  }
110
- const ye = 300 * 1e3, Pe = /* @__PURE__ */ new Set([
111
- x.PENDING_DEPOSITOR_WOTS_PK,
112
- ...L
110
+ const Pe = 300 * 1e3, ye = /* @__PURE__ */ new Set([
111
+ v.PENDING_DEPOSITOR_WOTS_PK,
112
+ ...O
113
113
  ]);
114
114
  async function rt(e) {
115
115
  const {
116
116
  statusReader: t,
117
117
  wotsSubmitter: r,
118
118
  peginTxid: n,
119
- depositorPk: s,
119
+ depositorPk: o,
120
120
  wotsPublicKeys: u,
121
- timeoutMs: a = ye,
121
+ timeoutMs: a = Pe,
122
122
  signal: i
123
123
  } = e;
124
124
  i == null || i.throwIfAborted();
125
- const o = await D({
125
+ const s = await D({
126
126
  statusReader: t,
127
127
  peginTxid: n,
128
- targetStatuses: Pe,
128
+ targetStatuses: ye,
129
129
  timeoutMs: a,
130
130
  signal: i
131
131
  });
132
- L.has(o) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
132
+ O.has(s) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
133
133
  {
134
134
  pegin_txid: n,
135
- depositor_pk: s,
135
+ depositor_pk: o,
136
136
  wots_public_keys: u
137
137
  },
138
138
  i
@@ -140,24 +140,24 @@ async function rt(e) {
140
140
  }
141
141
  const H = 1;
142
142
  function be(e, t) {
143
- const r = h(t).toLowerCase(), s = e.map((u) => h(u).toLowerCase()).filter((u) => u !== r);
144
- if (s.length === 0)
143
+ const r = h(t).toLowerCase(), o = e.map((u) => h(u).toLowerCase()).filter((u) => u !== r);
144
+ if (o.length === 0)
145
145
  throw new Error(
146
146
  "Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
147
147
  );
148
- if (new Set(s).size !== s.length)
148
+ if (new Set(o).size !== o.length)
149
149
  throw new Error(
150
150
  "Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
151
151
  );
152
- return s;
152
+ return o;
153
153
  }
154
154
  function me(e, t, r) {
155
155
  const n = r.map(
156
156
  (c) => h(c).toLowerCase()
157
- ), s = t.filter((c) => n.includes(c));
158
- if (s.length > 0)
157
+ ), o = t.filter((c) => n.includes(c));
158
+ if (o.length > 0)
159
159
  throw new Error(
160
- `Cannot validate challenger set: vault keepers and universal challengers overlap (${s.join(", ")})`
160
+ `Cannot validate challenger set: vault keepers and universal challengers overlap (${o.join(", ")})`
161
161
  );
162
162
  const u = [...t, ...n], a = e.map(
163
163
  (c) => h(c.challenger_pubkey).toLowerCase()
@@ -166,30 +166,30 @@ function me(e, t, r) {
166
166
  throw new Error(
167
167
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
168
168
  );
169
- const o = new Set(u), l = u.filter((c) => !i.has(c)), d = a.filter((c) => !o.has(c));
169
+ const s = new Set(u), l = u.filter((c) => !i.has(c)), d = a.filter((c) => !s.has(c));
170
170
  if (l.length > 0 || d.length > 0)
171
171
  throw new Error(
172
172
  "Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
173
173
  );
174
174
  }
175
- function we(e, t) {
175
+ function ve(e, t) {
176
176
  const r = e.ins[t];
177
177
  return N(new Uint8Array(r.hash).slice().reverse());
178
178
  }
179
- function B(e, t, r, n, s) {
179
+ function B(e, t, r, n, o) {
180
180
  const u = e.ins[t];
181
181
  if (u.index !== 0)
182
182
  throw new Error(
183
- `NoPayout (challenger ${s}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
183
+ `NoPayout (challenger ${o}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
184
184
  );
185
- const a = r.getId(), i = we(e, t);
185
+ const a = r.getId(), i = ve(e, t);
186
186
  if (i !== a)
187
187
  throw new Error(
188
- `NoPayout (challenger ${s}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
188
+ `NoPayout (challenger ${o}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
189
189
  );
190
190
  }
191
- async function ve(e, t, r) {
192
- const n = [], s = [], u = [], a = be(
191
+ async function we(e, t, r) {
192
+ const n = [], o = [], u = [], a = be(
193
193
  r.vaultKeeperBtcPubkeys,
194
194
  r.depositorBtcPubkey
195
195
  );
@@ -212,25 +212,25 @@ async function ve(e, t, r) {
212
212
  timelockPegin: r.timelockPegin,
213
213
  network: r.network
214
214
  });
215
- n.push(i.psbtHex), s.push(
215
+ n.push(i.psbtHex), o.push(
216
216
  $(
217
217
  t,
218
218
  H
219
219
  )
220
220
  );
221
- const o = h(r.depositorBtcPubkey), l = T.fromHex(
221
+ const s = h(r.depositorBtcPubkey), l = _.fromHex(
222
222
  h(e.assert_tx.tx_hex)
223
223
  );
224
224
  for (const d of e.challenger_presign_data) {
225
225
  const c = h(d.challenger_pubkey), g = n.length, P = await xe({
226
226
  challenger: d,
227
227
  challengerPubkey: c,
228
- claimerPubkey: o,
228
+ claimerPubkey: s,
229
229
  localChallengers: a,
230
230
  assertTxParsed: l,
231
231
  ctx: r
232
232
  });
233
- n.push(P), s.push(
233
+ n.push(P), o.push(
234
234
  $(
235
235
  t,
236
236
  H
@@ -240,14 +240,14 @@ async function ve(e, t, r) {
240
240
  noPayoutIdx: g
241
241
  });
242
242
  }
243
- return { psbtHexes: n, signOptions: s, challengerEntries: u };
243
+ return { psbtHexes: n, signOptions: o, challengerEntries: u };
244
244
  }
245
245
  async function xe(e) {
246
246
  const {
247
247
  challenger: t,
248
248
  challengerPubkey: r,
249
249
  claimerPubkey: n,
250
- localChallengers: s,
250
+ localChallengers: o,
251
251
  assertTxParsed: u,
252
252
  ctx: a
253
253
  } = e;
@@ -256,11 +256,11 @@ async function xe(e) {
256
256
  r,
257
257
  a.network
258
258
  );
259
- const i = T.fromHex(
259
+ const i = _.fromHex(
260
260
  h(t.nopayout_tx.tx_hex)
261
- ), o = T.fromHex(
261
+ ), s = _.fromHex(
262
262
  h(t.challenge_assert_x_tx.tx_hex)
263
- ), l = T.fromHex(
263
+ ), l = _.fromHex(
264
264
  h(t.challenge_assert_y_tx.tx_hex)
265
265
  );
266
266
  if (i.ins.length !== 3)
@@ -276,7 +276,7 @@ async function xe(e) {
276
276
  ), B(
277
277
  i,
278
278
  1,
279
- o,
279
+ s,
280
280
  "ChallengeAssertX",
281
281
  r
282
282
  ), B(
@@ -288,7 +288,7 @@ async function xe(e) {
288
288
  );
289
289
  const d = [
290
290
  u.outs[0],
291
- o.outs[0],
291
+ s.outs[0],
292
292
  l.outs[0]
293
293
  ].map((c) => ({
294
294
  script_pubkey: N(new Uint8Array(c.script)),
@@ -300,7 +300,7 @@ async function xe(e) {
300
300
  prevouts: d,
301
301
  connectorParams: {
302
302
  claimer: n,
303
- localChallengers: s,
303
+ localChallengers: o,
304
304
  universalChallengers: a.universalChallengerBtcPubkeys,
305
305
  timelockAssert: a.timelockAssert,
306
306
  councilMembers: a.councilMembers,
@@ -308,14 +308,14 @@ async function xe(e) {
308
308
  }
309
309
  });
310
310
  }
311
- function ke(e, t, r) {
312
- R(e[0]);
311
+ function Te(e, t, r) {
312
+ V(e[0]);
313
313
  const n = I(
314
314
  e[0].returnedPsbtHex,
315
315
  r
316
- ), s = {};
316
+ ), o = {};
317
317
  for (const u of t)
318
- R(e[u.noPayoutIdx]), s[u.challengerPubkey] = {
318
+ V(e[u.noPayoutIdx]), o[u.challengerPubkey] = {
319
319
  nopayout_signature: I(
320
320
  e[u.noPayoutIdx].returnedPsbtHex,
321
321
  r
@@ -325,26 +325,26 @@ function ke(e, t, r) {
325
325
  payout_signatures: {
326
326
  payout_signature: n
327
327
  },
328
- per_challenger: s
328
+ per_challenger: o
329
329
  };
330
330
  }
331
- async function Te(e, t, r) {
331
+ async function ke(e, t, r) {
332
332
  if (typeof e.signPsbts == "function")
333
333
  return e.signPsbts(t, r);
334
334
  const n = [];
335
- for (let s = 0; s < t.length; s++)
336
- n.push(await e.signPsbt(t[s], r == null ? void 0 : r[s]));
335
+ for (let o = 0; o < t.length; o++)
336
+ n.push(await e.signPsbt(t[o], r == null ? void 0 : r[o]));
337
337
  return n;
338
338
  }
339
339
  async function Ee(e) {
340
- const { depositorGraph: t, btcWallet: r, signingContext: n } = e, s = await r.getPublicKeyHex(), { depositorPubkey: u } = q(
341
- s,
340
+ const { depositorGraph: t, btcWallet: r, signingContext: n } = e, o = await r.getPublicKeyHex(), { depositorPubkey: u } = W(
341
+ o,
342
342
  h(n.depositorBtcPubkey)
343
- ), { psbtHexes: a, signOptions: i, challengerEntries: o } = await ve(
343
+ ), { psbtHexes: a, signOptions: i, challengerEntries: s } = await we(
344
344
  t,
345
- s,
345
+ o,
346
346
  n
347
- ), l = await Te(
347
+ ), l = await ke(
348
348
  r,
349
349
  a,
350
350
  i
@@ -357,19 +357,20 @@ async function Ee(e) {
357
357
  requestedPsbtHex: c,
358
358
  returnedPsbtHex: l[g]
359
359
  }));
360
- return ke(
360
+ return Te(
361
361
  d,
362
- o,
362
+ s,
363
363
  u
364
364
  );
365
365
  }
366
- const _e = 1200 * 1e3, M = /* @__PURE__ */ new Set([
367
- x.PENDING_ACKS,
368
- x.PENDING_ACTIVATION,
369
- x.ACTIVATED
366
+ const _e = 1200 * 1e3, L = /* @__PURE__ */ new Set([
367
+ v.PENDING_ACKS,
368
+ v.PENDING_ACTIVATION,
369
+ v.ACTIVATED_PENDING_BROADCAST,
370
+ v.ACTIVATED
370
371
  ]), Ce = /* @__PURE__ */ new Set([
371
- x.PENDING_DEPOSITOR_SIGNATURES,
372
- ...M
372
+ v.PENDING_DEPOSITOR_SIGNATURES,
373
+ ...L
373
374
  ]);
374
375
  function Se(e) {
375
376
  return e.map((t) => ({
@@ -378,13 +379,13 @@ function Se(e) {
378
379
  assertTxHex: t.assert_tx.tx_hex
379
380
  }));
380
381
  }
381
- function Be(e, t) {
382
+ function Ae(e, t) {
382
383
  const r = h(e).toLowerCase(), n = h(
383
384
  t.vaultProviderBtcPubkey
384
- ).toLowerCase(), s = h(
385
+ ).toLowerCase(), o = h(
385
386
  t.depositorBtcPubkey
386
387
  ).toLowerCase();
387
- if (r === n || r === s)
388
+ if (r === n || r === o)
388
389
  return t.registeredPayoutScriptPubKey;
389
390
  if (!t.vaultKeeperBtcPubkeys.some(
390
391
  (a) => h(a).toLowerCase() === r
@@ -392,7 +393,7 @@ function Be(e, t) {
392
393
  throw new Error(
393
394
  `Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
394
395
  );
395
- return J(r);
396
+ return Y(r);
396
397
  }
397
398
  function K(e, t) {
398
399
  return {
@@ -404,37 +405,37 @@ function K(e, t) {
404
405
  universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
405
406
  depositorBtcPubkey: t.depositorBtcPubkey,
406
407
  timelockPegin: t.timelockPegin,
407
- registeredPayoutScriptPubKey: Be(
408
+ registeredPayoutScriptPubKey: Ae(
408
409
  e.claimerPubkeyXOnly,
409
410
  t
410
411
  )
411
412
  };
412
413
  }
413
- async function Ae(e, t, r, n) {
414
- const s = new ee({
414
+ async function Be(e, t, r, n) {
415
+ const o = new Z({
415
416
  network: t.network,
416
417
  btcWallet: e
417
418
  }), u = r.length;
418
419
  n == null || n(0, u);
419
420
  let a;
420
- if (s.supportsBatchSigning())
421
- a = (await s.signPayoutTransactionsBatch(
421
+ if (o.supportsBatchSigning())
422
+ a = (await o.signPayoutTransactionsBatch(
422
423
  r.map((l) => K(l, t))
423
424
  )).map((l) => l.payoutSignature);
424
425
  else {
425
426
  a = [];
426
- for (let o = 0; o < r.length; o++) {
427
- n == null || n(o, u);
428
- const l = await s.signPayoutTransaction(
429
- K(r[o], t)
427
+ for (let s = 0; s < r.length; s++) {
428
+ n == null || n(s, u);
429
+ const l = await o.signPayoutTransaction(
430
+ K(r[s], t)
430
431
  );
431
432
  a.push(l.signature);
432
433
  }
433
434
  }
434
435
  const i = {};
435
- for (let o = 0; o < r.length; o++)
436
- i[r[o].claimerPubkeyXOnly] = {
437
- payout_signature: a[o]
436
+ for (let s = 0; s < r.length; s++)
437
+ i[r[s].claimerPubkeyXOnly] = {
438
+ payout_signature: a[s]
438
439
  };
439
440
  return n == null || n(u, u), i;
440
441
  }
@@ -443,40 +444,40 @@ async function nt(e) {
443
444
  statusReader: t,
444
445
  presignClient: r,
445
446
  btcWallet: n,
446
- peginTxid: s,
447
+ peginTxid: o,
447
448
  depositorPk: u,
448
449
  signingContext: a,
449
450
  timeoutMs: i = _e,
450
- signal: o,
451
+ signal: s,
451
452
  onProgress: l
452
453
  } = e, d = await D({
453
454
  statusReader: t,
454
- peginTxid: s,
455
+ peginTxid: o,
455
456
  targetStatuses: Ce,
456
457
  timeoutMs: i,
457
- signal: o
458
+ signal: s
458
459
  });
459
- if (M.has(d))
460
+ if (L.has(d))
460
461
  return;
461
- o == null || o.throwIfAborted();
462
+ s == null || s.throwIfAborted();
462
463
  const c = await r.requestDepositorPresignTransactions(
463
464
  {
464
- pegin_txid: s,
465
+ pegin_txid: o,
465
466
  depositor_pk: u
466
467
  },
467
- o
468
+ s
468
469
  );
469
- o == null || o.throwIfAborted();
470
+ s == null || s.throwIfAborted();
470
471
  const g = k(u), P = c.txs.filter(
471
- (v) => k(v.claimer_pubkey) !== g
472
- ), b = Se(P), f = await Ae(
472
+ (b) => k(b.claimer_pubkey) !== g
473
+ ), p = Se(P), y = await Be(
473
474
  n,
474
475
  a,
475
- b,
476
+ p,
476
477
  l
477
478
  );
478
- o == null || o.throwIfAborted();
479
- const y = await Ee({
479
+ s == null || s.throwIfAborted();
480
+ const T = await Ee({
480
481
  depositorGraph: c.depositor_graph,
481
482
  btcWallet: n,
482
483
  signingContext: {
@@ -493,16 +494,16 @@ async function nt(e) {
493
494
  registeredPayoutScriptPubKey: a.registeredPayoutScriptPubKey
494
495
  }
495
496
  });
496
- o == null || o.throwIfAborted();
497
- const w = { ...f };
498
- w[h(u)] = y.payout_signatures, await r.submitDepositorPresignatures(
497
+ s == null || s.throwIfAborted();
498
+ const w = { ...y };
499
+ w[h(u)] = T.payout_signatures, await r.submitDepositorPresignatures(
499
500
  {
500
- pegin_txid: s,
501
+ pegin_txid: o,
501
502
  depositor_pk: u,
502
503
  signatures: w,
503
- depositor_claimer_presignatures: y
504
+ depositor_claimer_presignatures: T
504
505
  },
505
- o
506
+ s
506
507
  );
507
508
  }
508
509
  function Re(e) {
@@ -513,11 +514,11 @@ function ot(e) {
513
514
  amountSats: t,
514
515
  minDeposit: r,
515
516
  maxDeposit: n,
516
- btcBalance: s,
517
+ btcBalance: o,
517
518
  estimatedFeeSats: u,
518
519
  depositorClaimValue: a
519
520
  } = e;
520
- return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > s);
521
+ return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > o);
521
522
  }
522
523
  function st(e, t, r) {
523
524
  return e <= 0n ? {
@@ -525,10 +526,10 @@ function st(e, t, r) {
525
526
  error: "Deposit amount must be greater than zero"
526
527
  } : e < t ? {
527
528
  valid: !1,
528
- error: `Minimum deposit is ${m(t)} BTC`
529
+ error: `Minimum deposit is ${x(t)} BTC`
529
530
  } : r && r > 0n && e > r ? {
530
531
  valid: !1,
531
- error: `Maximum deposit is ${m(r)} BTC`
532
+ error: `Maximum deposit is ${x(r)} BTC`
532
533
  } : { valid: !0 };
533
534
  }
534
535
  function at(e) {
@@ -538,7 +539,7 @@ function at(e) {
538
539
  error: "Supply cap reached — deposits temporarily paused"
539
540
  } : t > r ? {
540
541
  valid: !1,
541
- error: `Vault size exceeds remaining capacity (${m(r)} BTC)`
542
+ error: `Vault size exceeds remaining capacity (${x(r)} BTC)`
542
543
  } : { valid: !0 };
543
544
  }
544
545
  function it(e, t) {
@@ -548,42 +549,42 @@ function it(e, t) {
548
549
  error: "At least one vault provider must be selected"
549
550
  };
550
551
  const r = t.map(
551
- (s) => s.toLowerCase()
552
+ (o) => o.toLowerCase()
552
553
  );
553
554
  return e.filter(
554
- (s) => !r.includes(s.toLowerCase())
555
+ (o) => !r.includes(o.toLowerCase())
555
556
  ).length > 0 ? {
556
557
  valid: !1,
557
558
  error: "Invalid vault provider selected"
558
559
  } : { valid: !0 };
559
560
  }
560
- function $e(e, t, r) {
561
+ function Ve(e, t, r) {
561
562
  if (!e || e.length === 0)
562
563
  return {
563
564
  valid: !1,
564
565
  error: "At least one vault amount required"
565
566
  };
566
567
  for (let n = 0; n < e.length; n++) {
567
- const s = e[n];
568
- if (s <= 0n)
568
+ const o = e[n];
569
+ if (o <= 0n)
569
570
  return {
570
571
  valid: !1,
571
572
  error: `Vault ${n + 1} amount must be positive`
572
573
  };
573
- if (t && s < t)
574
+ if (t && o < t)
574
575
  return {
575
576
  valid: !1,
576
- error: `Vault ${n + 1} amount ${m(s)} BTC is below minimum deposit ${m(t)} BTC`
577
+ error: `Vault ${n + 1} amount ${x(o)} BTC is below minimum deposit ${x(t)} BTC`
577
578
  };
578
- if (r && s > r)
579
+ if (r && o > r)
579
580
  return {
580
581
  valid: !1,
581
- error: `Vault ${n + 1} amount ${m(s)} BTC exceeds maximum deposit ${m(r)} BTC`
582
+ error: `Vault ${n + 1} amount ${x(o)} BTC exceeds maximum deposit ${x(r)} BTC`
582
583
  };
583
584
  }
584
585
  return { valid: !0 };
585
586
  }
586
- function Ve(e) {
587
+ function $e(e) {
587
588
  const t = h(e);
588
589
  return Re(t) ? { valid: !0 } : {
589
590
  valid: !1,
@@ -611,38 +612,38 @@ function ut(e) {
611
612
  vaultAmounts: t,
612
613
  confirmedUTXOs: r,
613
614
  vaultProviderBtcPubkey: n,
614
- vaultKeeperBtcPubkeys: s,
615
+ vaultKeeperBtcPubkeys: o,
615
616
  universalChallengerBtcPubkeys: u,
616
617
  minDeposit: a,
617
618
  maxDeposit: i
618
- } = e, o = $e(
619
+ } = e, s = Ve(
619
620
  t,
620
621
  a,
621
622
  i
622
623
  );
623
- if (!o.valid)
624
- throw new Error(o.error);
625
- const l = Ve(n);
624
+ if (!s.valid)
625
+ throw new Error(s.error);
626
+ const l = $e(n);
626
627
  if (!l.valid)
627
628
  throw new Error(l.error);
628
- Ie(s), He(u), Ke(r);
629
+ Ie(o), He(u), Ke(r);
629
630
  }
630
631
  async function lt(e) {
631
632
  const {
632
633
  vaultRegistryReader: t,
633
634
  vaultKeeperReader: r,
634
635
  universalChallengerReader: n,
635
- vaultProviderEthAddress: s,
636
+ vaultProviderEthAddress: o,
636
637
  applicationEntryPoint: u,
637
638
  expectedVaultProviderBtcPubkey: a,
638
639
  expectedVaultKeeperBtcPubkeys: i,
639
- expectedUniversalChallengerBtcPubkeys: o
640
+ expectedUniversalChallengerBtcPubkeys: s
640
641
  } = e, [
641
642
  l,
642
643
  d,
643
644
  c
644
645
  ] = await Promise.all([
645
- t.getVaultProviderBtcPubKey(s),
646
+ t.getVaultProviderBtcPubKey(o),
646
647
  r.getCurrentVaultKeepersVersion(u),
647
648
  n.getLatestUniversalChallengersVersion()
648
649
  ]), [g, P] = await Promise.all([
@@ -653,29 +654,29 @@ async function lt(e) {
653
654
  n.getUniversalChallengersByVersion(
654
655
  c
655
656
  )
656
- ]), b = (p) => k(p).toLowerCase(), f = (p) => p.map(b).sort();
657
- if (b(a) !== l)
657
+ ]), p = (f) => k(f).toLowerCase(), y = (f) => f.map(p).sort();
658
+ if (p(a) !== l)
658
659
  throw new Error(
659
- `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${s}. Refresh and try again.`
660
+ `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${o}. Refresh and try again.`
660
661
  );
661
- const w = f(i), v = f(
662
- g.map((p) => p.btcPubKey)
662
+ const w = y(i), b = y(
663
+ g.map((f) => f.btcPubKey)
663
664
  );
664
- if (w.length !== v.length || w.some((p, _) => p !== v[_]))
665
+ if (w.length !== b.length || w.some((f, C) => f !== b[C]))
665
666
  throw new Error(
666
667
  `Vault keeper BTC pubkeys (v${d}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
667
668
  );
668
- const V = f(o), E = f(
669
- P.map((p) => p.btcPubKey)
669
+ const E = y(s), m = y(
670
+ P.map((f) => f.btcPubKey)
670
671
  );
671
- if (V.length !== E.length || V.some((p, _) => p !== E[_]))
672
+ if (E.length !== m.length || E.some((f, C) => f !== m[C]))
672
673
  throw new Error(
673
674
  `Universal challenger BTC pubkeys (v${c}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
674
675
  );
675
676
  return {
676
677
  vaultProviderBtcPubkeyXOnly: l,
677
- vaultKeeperBtcPubkeysSorted: v,
678
- universalChallengerBtcPubkeysSorted: E,
678
+ vaultKeeperBtcPubkeysSorted: b,
679
+ universalChallengerBtcPubkeysSorted: m,
679
680
  expectedAppVaultKeepersVersion: d,
680
681
  expectedUniversalChallengersVersion: c
681
682
  };
@@ -693,83 +694,83 @@ async function dt(e) {
693
694
  vaultRegistryReader: t,
694
695
  vaultIds: r,
695
696
  expectedOffchainParamsVersion: n,
696
- expectedAppVaultKeepersVersion: s,
697
+ expectedAppVaultKeepersVersion: o,
697
698
  expectedUniversalChallengersVersion: u
698
699
  } = e, a = await t.getProtocolInfoBatch(r), i = [];
699
- if (a.forEach((o, l) => {
700
+ if (a.forEach((s, l) => {
700
701
  const d = r[l];
701
- o.offchainParamsVersion !== n && i.push(
702
- `vault ${d}: offchainParams expected v${n}, got v${o.offchainParamsVersion}`
703
- ), o.appVaultKeepersVersion !== s && i.push(
704
- `vault ${d}: appVaultKeepers expected v${s}, got v${o.appVaultKeepersVersion}`
705
- ), o.universalChallengersVersion !== u && i.push(
706
- `vault ${d}: universalChallengers expected v${u}, got v${o.universalChallengersVersion}`
702
+ s.offchainParamsVersion !== n && i.push(
703
+ `vault ${d}: offchainParams expected v${n}, got v${s.offchainParamsVersion}`
704
+ ), s.appVaultKeepersVersion !== o && i.push(
705
+ `vault ${d}: appVaultKeepers expected v${o}, got v${s.appVaultKeepersVersion}`
706
+ ), s.universalChallengersVersion !== u && i.push(
707
+ `vault ${d}: universalChallengers expected v${u}, got v${s.universalChallengersVersion}`
707
708
  );
708
709
  }), i.length > 0)
709
710
  throw new U(
710
711
  `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
711
712
  );
712
713
  }
713
- var F = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved", e.WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.FAILED = "Failed", e))(F || {});
714
- const Oe = /* @__PURE__ */ new Set([
714
+ var M = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(M || {});
715
+ const Ne = /* @__PURE__ */ new Set([
715
716
  "PayoutBroadcast",
716
- "Failed"
717
- /* FAILED */
717
+ "PayoutBlocked"
718
+ /* PAYOUT_BLOCKED */
718
719
  ]);
719
720
  function ht(e) {
720
- return Object.values(F).includes(
721
+ return Object.values(M).includes(
721
722
  e
722
723
  );
723
724
  }
724
725
  function pt(e) {
725
- return !!e && Oe.has(e);
726
+ return !!e && Ne.has(e);
726
727
  }
727
- class Ne extends Error {
728
+ class Oe extends Error {
728
729
  constructor(r, n) {
729
730
  super(`Refund not yet mature (BIP68 not final): ${n.message}`);
730
- C(this, "vaultId");
731
- C(this, "cause");
731
+ S(this, "vaultId");
732
+ S(this, "cause");
732
733
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
733
734
  }
734
735
  }
735
- const Le = /^0x[0-9a-fA-F]{64}$/, De = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, X = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, z = 160;
736
- function gt(e) {
736
+ const De = /^0x[0-9a-fA-F]{64}$/, Le = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, X = 160;
737
+ function ft(e) {
737
738
  if (!Number.isFinite(e) || e <= 0)
738
739
  throw new Error(
739
740
  `feeRateSatsVb must be a positive finite number, got ${e}`
740
741
  );
741
- return BigInt(Math.ceil(e * z));
742
+ return BigInt(Math.ceil(e * X));
742
743
  }
743
- const Me = 1, O = 65535, Ue = /non-BIP68-final/i;
744
- function G(e, t) {
744
+ const Ue = 1, Me = /non-BIP68-final/i;
745
+ function z(e, t) {
745
746
  if (e.length !== 66)
746
747
  throw new Error(
747
748
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
748
749
  );
749
- if (!Le.test(e))
750
+ if (!De.test(e))
750
751
  throw new Error(
751
752
  `${t} must contain only hex characters after the 0x prefix`
752
753
  );
753
754
  }
754
- function A(e, t) {
755
+ function R(e, t) {
755
756
  if (!Number.isInteger(e) || e < 0)
756
757
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
757
758
  }
758
759
  function Fe(e) {
759
- if (G(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > O)
760
+ if (z(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout !== 0)
760
761
  throw new Error(
761
- `htlcVout must be an integer 0-${O}, got ${e.htlcVout}`
762
+ `Multi-vault Pre-PegIn refund is not supported by this SDK call (htlcVout=${e.htlcVout}, expected 0). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
762
763
  );
763
- if (A(e.offchainParamsVersion, "offchainParamsVersion"), A(e.appVaultKeepersVersion, "appVaultKeepersVersion"), A(
764
+ if (R(e.offchainParamsVersion, "offchainParamsVersion"), R(e.appVaultKeepersVersion, "appVaultKeepersVersion"), R(
764
765
  e.universalChallengersVersion,
765
766
  "universalChallengersVersion"
766
767
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
767
768
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
768
- if (!De.test(e.unsignedPrePeginTxHex))
769
+ if (!Le.test(e.unsignedPrePeginTxHex))
769
770
  throw new Error(
770
771
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
771
772
  );
772
- if (!e.depositorBtcPubkey || !X.test(e.depositorBtcPubkey))
773
+ if (!e.depositorBtcPubkey || !F.test(e.depositorBtcPubkey))
773
774
  throw new Error(
774
775
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
775
776
  );
@@ -777,7 +778,7 @@ function Fe(e) {
777
778
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
778
779
  }
779
780
  function Xe(e) {
780
- if (!e.vaultProviderPubkey || !X.test(e.vaultProviderPubkey))
781
+ if (!e.vaultProviderPubkey || !F.test(e.vaultProviderPubkey))
781
782
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
782
783
  if (e.vaultKeeperPubkeys.length === 0)
783
784
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -809,77 +810,83 @@ function ze(e) {
809
810
  }
810
811
  return t.extractTransaction().toHex();
811
812
  }
812
- async function ft(e) {
813
+ async function gt(e) {
813
814
  const {
814
815
  vaultId: t,
815
816
  readVault: r,
816
817
  readPrePeginContext: n,
817
- feeRate: s,
818
+ feeRate: o,
818
819
  signPsbt: u,
819
820
  broadcastTx: a,
820
821
  signal: i
821
822
  } = e;
822
- i == null || i.throwIfAborted(), G(t, "vaultId");
823
- const o = await r();
824
- Fe(o), i == null || i.throwIfAborted();
825
- const l = await n(o);
826
- if (Xe(l), i == null || i.throwIfAborted(), !Number.isFinite(s) || s <= 0)
827
- throw new Error(`feeRate must be a positive number, got ${s}`);
828
- const d = BigInt(Math.ceil(s * z));
823
+ i == null || i.throwIfAborted(), z(t, "vaultId");
824
+ const s = await r();
825
+ Fe(s), i == null || i.throwIfAborted();
826
+ const l = await n(s);
827
+ if (Xe(l), i == null || i.throwIfAborted(), !Number.isFinite(o) || o <= 0)
828
+ throw new Error(`feeRate must be a positive number, got ${o}`);
829
+ const d = BigInt(Math.ceil(o * X));
829
830
  i == null || i.throwIfAborted();
830
831
  const c = k(
831
- o.depositorBtcPubkey
832
- ), { psbtHex: g } = await le({
832
+ s.depositorBtcPubkey
833
+ ), g = h(s.unsignedPrePeginTxHex), P = 1, p = ee(g);
834
+ if (p !== void 0 && p.vout !== P)
835
+ throw new Error(
836
+ `Multi-vault Pre-PegIn refund is not supported by this SDK call (auth-anchor OP_RETURN at vout ${p.vout}; single-vault refund expects vout ${P}). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
837
+ );
838
+ const y = p == null ? void 0 : p.hash, { psbtHex: T } = await le({
833
839
  prePeginParams: {
834
840
  depositorPubkey: c,
835
841
  vaultProviderPubkey: h(l.vaultProviderPubkey),
836
842
  vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(h),
837
843
  universalChallengerPubkeys: l.universalChallengerPubkeys.map(h),
838
- hashlocks: [h(o.hashlock)],
844
+ hashlocks: [h(s.hashlock)],
839
845
  timelockRefund: l.timelockRefund,
840
- pegInAmounts: [o.amount],
846
+ pegInAmounts: [s.amount],
841
847
  feeRate: l.feeRate,
842
848
  numLocalChallengers: l.numLocalChallengers,
843
849
  councilQuorum: l.councilQuorum,
844
850
  councilSize: l.councilSize,
845
- network: l.network
851
+ network: l.network,
852
+ authAnchorHash: y
846
853
  },
847
- fundedPrePeginTxHex: h(o.unsignedPrePeginTxHex),
848
- htlcVout: o.htlcVout,
854
+ fundedPrePeginTxHex: g,
855
+ htlcVout: s.htlcVout,
849
856
  refundFee: d,
850
857
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
851
858
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
852
859
  // value would derive the wrong refund script leaf and yield an
853
860
  // unspendable PSBT. Match the `hashlocks` array handling above.
854
- hashlock: h(o.hashlock)
861
+ hashlock: h(s.hashlock)
855
862
  });
856
863
  i == null || i.throwIfAborted();
857
- const P = $(
858
- o.depositorBtcPubkey,
859
- Me
860
- ), b = await u(g, P);
861
- R({
862
- requestedPsbtHex: g,
864
+ const w = $(
865
+ s.depositorBtcPubkey,
866
+ Ue
867
+ ), b = await u(T, w);
868
+ V({
869
+ requestedPsbtHex: T,
863
870
  returnedPsbtHex: b
864
871
  });
865
- const f = ze(b);
872
+ const E = ze(b);
866
873
  i == null || i.throwIfAborted();
867
874
  try {
868
- return await a(f);
869
- } catch (y) {
870
- throw y instanceof Error && Ue.test(y.message) ? new Ne(t, y) : y;
875
+ return await a(E);
876
+ } catch (m) {
877
+ throw m instanceof Error && Me.test(m.message) ? new Oe(t, m) : m;
871
878
  }
872
879
  }
873
880
  export {
874
- Ne as B,
875
- F as C,
881
+ Oe as B,
882
+ M as C,
876
883
  U as R,
877
884
  tt as a,
878
885
  Ee as b,
879
886
  at as c,
880
887
  it as d,
881
- $e as e,
882
- Ve as f,
888
+ Ve as e,
889
+ $e as f,
883
890
  ut as g,
884
891
  lt as h,
885
892
  ot as i,
@@ -887,12 +894,12 @@ export {
887
894
  dt as k,
888
895
  ht as l,
889
896
  pt as m,
890
- ft as n,
891
- gt as o,
892
- z as p,
897
+ gt as n,
898
+ ft as o,
899
+ X as p,
893
900
  nt as r,
894
901
  rt as s,
895
902
  st as v,
896
903
  D as w
897
904
  };
898
- //# sourceMappingURL=buildAndBroadcastRefund-CI_x6OtX.js.map
905
+ //# sourceMappingURL=buildAndBroadcastRefund-B5cOyUzj.js.map