@babylonlabs-io/ts-sdk 0.36.3 → 0.37.2

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