@babylonlabs-io/ts-sdk 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/{PeginManager-CKf7Bjmj.js → PeginManager-D8WGB8eN.js} +2 -2
  2. package/dist/{PeginManager-CKf7Bjmj.js.map → PeginManager-D8WGB8eN.js.map} +1 -1
  3. package/dist/{PeginManager-Dt2Z5ljw.cjs → PeginManager-IgDHy_eU.cjs} +2 -2
  4. package/dist/{PeginManager-Dt2Z5ljw.cjs.map → PeginManager-IgDHy_eU.cjs.map} +1 -1
  5. package/dist/{buildAndBroadcastReclaim-T5ZFPUpM.js → buildAndBroadcastReclaim-C55KaRJF.js} +834 -825
  6. package/dist/buildAndBroadcastReclaim-C55KaRJF.js.map +1 -0
  7. package/dist/buildAndBroadcastReclaim-CefzR6i_.cjs +2 -0
  8. package/dist/buildAndBroadcastReclaim-CefzR6i_.cjs.map +1 -0
  9. package/dist/index-D2mybjXD.js +522 -0
  10. package/dist/index-D2mybjXD.js.map +1 -0
  11. package/dist/index-MRdle0fs.cjs +2 -0
  12. package/dist/index-MRdle0fs.cjs.map +1 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.js +215 -214
  15. package/dist/pegin-registration-client-B0j6ugt9.cjs +2 -0
  16. package/dist/pegin-registration-client-B0j6ugt9.cjs.map +1 -0
  17. package/dist/{pegin-registration-client-C5Hktrja.js → pegin-registration-client-ilkV1mLP.js} +103 -88
  18. package/dist/pegin-registration-client-ilkV1mLP.js.map +1 -0
  19. package/dist/primeVpAuth-BDWBKYhv.cjs +2 -0
  20. package/dist/primeVpAuth-BDWBKYhv.cjs.map +1 -0
  21. package/dist/primeVpAuth-D0ZnsjRi.js +805 -0
  22. package/dist/primeVpAuth-D0ZnsjRi.js.map +1 -0
  23. package/dist/state-C4WoNCy1.cjs +2 -0
  24. package/dist/state-C4WoNCy1.cjs.map +1 -0
  25. package/dist/{state-mE-QfITd.js → state-CFn1rT74.js} +128 -101
  26. package/dist/state-CFn1rT74.js.map +1 -0
  27. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  28. package/dist/tbv/core/clients/eth/index.js +2 -2
  29. package/dist/tbv/core/clients/eth/types.d.ts +12 -5
  30. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  31. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +12 -3
  32. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  33. package/dist/tbv/core/clients/index.cjs +1 -1
  34. package/dist/tbv/core/clients/index.js +52 -51
  35. package/dist/tbv/core/clients/mempool/index.cjs +1 -1
  36. package/dist/tbv/core/clients/mempool/index.cjs.map +1 -1
  37. package/dist/tbv/core/clients/mempool/index.d.ts +1 -1
  38. package/dist/tbv/core/clients/mempool/index.d.ts.map +1 -1
  39. package/dist/tbv/core/clients/mempool/index.js +85 -71
  40. package/dist/tbv/core/clients/mempool/index.js.map +1 -1
  41. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +10 -0
  42. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
  43. package/dist/tbv/core/clients/vault-provider/api.d.ts +17 -14
  44. package/dist/tbv/core/clients/vault-provider/api.d.ts.map +1 -1
  45. package/dist/tbv/core/clients/vault-provider/auth/createAuthenticatedVpClient.d.ts +8 -0
  46. package/dist/tbv/core/clients/vault-provider/auth/createAuthenticatedVpClient.d.ts.map +1 -1
  47. package/dist/tbv/core/clients/vault-provider/auth/index.d.ts +1 -1
  48. package/dist/tbv/core/clients/vault-provider/auth/index.d.ts.map +1 -1
  49. package/dist/tbv/core/clients/vault-provider/auth/primeVpAuth.d.ts +8 -0
  50. package/dist/tbv/core/clients/vault-provider/auth/primeVpAuth.d.ts.map +1 -1
  51. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts +18 -2
  52. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts.map +1 -1
  53. package/dist/tbv/core/clients/vault-provider/auth/tokenRegistry.d.ts +26 -6
  54. package/dist/tbv/core/clients/vault-provider/auth/tokenRegistry.d.ts.map +1 -1
  55. package/dist/tbv/core/clients/vault-provider/batchAttribution.d.ts +17 -15
  56. package/dist/tbv/core/clients/vault-provider/batchAttribution.d.ts.map +1 -1
  57. package/dist/tbv/core/clients/vault-provider/batchPoll.d.ts +15 -9
  58. package/dist/tbv/core/clients/vault-provider/batchPoll.d.ts.map +1 -1
  59. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +3 -2
  60. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
  61. package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
  62. package/dist/tbv/core/clients/vault-provider/status/index.js +2 -2
  63. package/dist/tbv/core/clients/vault-provider/types.d.ts +36 -23
  64. package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
  65. package/dist/tbv/core/clients/vault-provider/validators.d.ts +12 -4
  66. package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
  67. package/dist/tbv/core/index.cjs +1 -1
  68. package/dist/tbv/core/index.js +213 -212
  69. package/dist/tbv/core/managers/index.cjs +1 -1
  70. package/dist/tbv/core/managers/index.js +1 -1
  71. package/dist/tbv/core/services/deposit/interfaces.d.ts +2 -2
  72. package/dist/tbv/core/services/deposit/interfaces.d.ts.map +1 -1
  73. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +3 -1
  74. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
  75. package/dist/tbv/core/services/deposit/submitWotsPublicKey.d.ts +3 -1
  76. package/dist/tbv/core/services/deposit/submitWotsPublicKey.d.ts.map +1 -1
  77. package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts +11 -2
  78. package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts.map +1 -1
  79. package/dist/tbv/core/services/index.cjs +1 -1
  80. package/dist/tbv/core/services/index.js +2 -2
  81. package/dist/tbv/core/services/pegout/state.d.ts +2 -2
  82. package/dist/tbv/index.cjs +1 -1
  83. package/dist/tbv/index.js +213 -212
  84. package/dist/{toRefundInputs-DIIdhjvu.js → toRefundInputs-10RYIfh1.js} +2 -2
  85. package/dist/{toRefundInputs-DIIdhjvu.js.map → toRefundInputs-10RYIfh1.js.map} +1 -1
  86. package/dist/{toRefundInputs-B_GlIXjk.cjs → toRefundInputs-a-0HRyrl.cjs} +2 -2
  87. package/dist/{toRefundInputs-B_GlIXjk.cjs.map → toRefundInputs-a-0HRyrl.cjs.map} +1 -1
  88. package/dist/{types-DJxOEU3P.cjs → types-BueQoMjO.cjs} +2 -2
  89. package/dist/{types-DJxOEU3P.cjs.map → types-BueQoMjO.cjs.map} +1 -1
  90. package/dist/{types-Dz1kVqn6.js → types-DGkejGZH.js} +2 -2
  91. package/dist/{types-Dz1kVqn6.js.map → types-DGkejGZH.js.map} +1 -1
  92. package/package.json +1 -1
  93. package/dist/buildAndBroadcastReclaim-BDc-SK9i.cjs +0 -2
  94. package/dist/buildAndBroadcastReclaim-BDc-SK9i.cjs.map +0 -1
  95. package/dist/buildAndBroadcastReclaim-T5ZFPUpM.js.map +0 -1
  96. package/dist/index-B6w5MM-8.js +0 -528
  97. package/dist/index-B6w5MM-8.js.map +0 -1
  98. package/dist/index-EHLYplSd.cjs +0 -2
  99. package/dist/index-EHLYplSd.cjs.map +0 -1
  100. package/dist/pegin-registration-client-BdJ6c7si.cjs +0 -2
  101. package/dist/pegin-registration-client-BdJ6c7si.cjs.map +0 -1
  102. package/dist/pegin-registration-client-C5Hktrja.js.map +0 -1
  103. package/dist/primeVpAuth-Bdy_B_Sq.js +0 -745
  104. package/dist/primeVpAuth-Bdy_B_Sq.js.map +0 -1
  105. package/dist/primeVpAuth-CQRsu6VB.cjs +0 -2
  106. package/dist/primeVpAuth-CQRsu6VB.cjs.map +0 -1
  107. package/dist/state-DMFlvLL3.cjs +0 -2
  108. package/dist/state-DMFlvLL3.cjs.map +0 -1
  109. package/dist/state-mE-QfITd.js.map +0 -1
@@ -1,81 +1,81 @@
1
- var at = Object.defineProperty;
2
- var it = (e, t, r) => t in e ? at(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var O = (e, t, r) => it(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { B as Ne } from "./BTCVaultRegistry.abi-B0x9_Bza.js";
5
- import { e as He, s as f, i as ut, c as $, v as ct, u as Ke, p as j, f as V } from "./bitcoin-C-TuHb-v.js";
6
- import { v as lt, d as De, s as ht, P as pt, a as dt } from "./PayoutManager-BSwbUQeF.js";
1
+ var ut = Object.defineProperty;
2
+ var ct = (e, t, r) => t in e ? ut(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var N = (e, t, r) => ct(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { B as Ke } from "./BTCVaultRegistry.abi-B0x9_Bza.js";
5
+ import { e as De, s as f, i as lt, c as C, v as ht, u as Me, p as j, f as V } from "./bitcoin-C-TuHb-v.js";
6
+ import { v as pt, d as Fe, s as dt, P as gt, a as ft } from "./PayoutManager-BSwbUQeF.js";
7
7
  import { Buffer as I } from "buffer";
8
- import { b as gt, a as M, c as ft } from "./signing-Dhr2t0Z6.js";
9
- import { buildClaimPsbt as yt, buildAssertClaimerPsbt as bt, buildPayoutClaimerPsbt as mt, buildWronglyChallengedPsbts as Pt, buildPayoutDepositorPsbt as vt, finalizeClaimTx as wt, buildWatchtowerArtifacts as xt, extractTapScriptSig as Et, expandWotsSeed as kt, wotsKeypairFromSeed as _t, validateWotsKeypairAgainstGraph as Tt, verifyWatchtowerArtifacts as $t, deriveVaultId as Ct } from "./tbv/core/wasm/index.js";
10
- import { p as Me, P as le, f as At, i as F, g as U, j as L } from "./verifyScriptPathSchnorrSignature-CpjSTfMj.js";
11
- import { Psbt as Fe, Transaction as B } from "bitcoinjs-lib";
12
- import { m as he, n as pe, N as q, o as de, D as ge } from "./constants-D5vORbQE.js";
13
- import { d as St } from "./deriveVaultRoot-BcvmER1E.js";
14
- import { d as It, a as fe } from "./onChainBtcPubkey-CCTdl53s.js";
15
- import { zeroAddress as Rt, isAddress as Bt, isAddressEqual as Vt } from "viem";
16
- import { D as R, c as Ot, b as Nt, R as Ht, d as Ue } from "./state-mE-QfITd.js";
17
- import { h as ye, b as Kt, s as Dt, j as Mt } from "./sha2-YqVHJiFj.js";
18
- import { d as Ft, c as Ut, b as Lt, f as Le, e as Gt, a as Xt } from "./noPayout-qBXWKwav.js";
19
- import { a as jt } from "./secp256k1-D-H9jmd7.js";
20
- const qt = /^0x[0-9a-fA-F]{64}$/, zt = /^0x[0-9a-fA-F]{40}$/, Wt = /^0x([0-9a-fA-F]{2})*$/;
21
- function z(e, t) {
8
+ import { b as yt, a as F, c as bt } from "./signing-Dhr2t0Z6.js";
9
+ import { buildClaimPsbt as mt, buildAssertClaimerPsbt as vt, buildPayoutClaimerPsbt as Pt, buildWronglyChallengedPsbts as wt, buildPayoutDepositorPsbt as xt, finalizeClaimTx as Et, buildWatchtowerArtifacts as kt, extractTapScriptSig as _t, expandWotsSeed as Tt, wotsKeypairFromSeed as $t, validateWotsKeypairAgainstGraph as Ct, verifyWatchtowerArtifacts as At, deriveVaultId as St } from "./tbv/core/wasm/index.js";
10
+ import { p as Le, P as he, f as It, i as L, g as U, j as G } from "./verifyScriptPathSchnorrSignature-CpjSTfMj.js";
11
+ import { Psbt as Ue, Transaction as B } from "bitcoinjs-lib";
12
+ import { m as pe, n as de, N as z, o as ge, D as fe } from "./constants-D5vORbQE.js";
13
+ import { d as Rt } from "./deriveVaultRoot-BcvmER1E.js";
14
+ import { d as Bt, a as ye } from "./onChainBtcPubkey-CCTdl53s.js";
15
+ import { zeroAddress as Vt, isAddress as Ot, isAddressEqual as Nt } from "viem";
16
+ import { v as be, D as R, c as Ht, b as Kt, R as Dt, d as Ge } from "./state-CFn1rT74.js";
17
+ import { h as me, b as Mt, s as Ft, j as Lt } from "./sha2-YqVHJiFj.js";
18
+ import { d as Ut, c as Gt, b as Xt, f as Xe, e as qt, a as jt } from "./noPayout-qBXWKwav.js";
19
+ import { a as zt } from "./secp256k1-D-H9jmd7.js";
20
+ const Wt = /^0x[0-9a-fA-F]{64}$/, Yt = /^0x[0-9a-fA-F]{40}$/, Qt = /^0x([0-9a-fA-F]{2})*$/;
21
+ function W(e, t) {
22
22
  if (e.length !== 66)
23
23
  throw new Error(
24
24
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
25
25
  );
26
- if (!qt.test(e))
26
+ if (!Wt.test(e))
27
27
  throw new Error(
28
28
  `${t} must contain only hex characters after the 0x prefix`
29
29
  );
30
30
  }
31
- function Yt(e, t) {
32
- if (!zt.test(e))
31
+ function Jt(e, t) {
32
+ if (!Yt.test(e))
33
33
  throw new Error(
34
34
  `${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
35
35
  );
36
36
  }
37
- function Qt(e, t) {
38
- if (!Wt.test(e))
37
+ function Zt(e, t) {
38
+ if (!Qt.test(e))
39
39
  throw new Error(
40
40
  `${t} must be a 0x-prefixed hex string with an even number of hex chars`
41
41
  );
42
42
  }
43
- function Ge(e) {
44
- Yt(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), z(e.vaultId, "vaultId");
45
- const t = He(e.secret);
46
- if (z(t, "secret"), e.hashlock !== void 0 && (z(e.hashlock, "hashlock"), !lt(t, e.hashlock)))
43
+ function qe(e) {
44
+ Jt(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), W(e.vaultId, "vaultId");
45
+ const t = De(e.secret);
46
+ if (W(t, "secret"), e.hashlock !== void 0 && (W(e.hashlock, "hashlock"), !pt(t, e.hashlock)))
47
47
  throw new Error(
48
48
  "Invalid secret: SHA256(secret) does not match the provided hashlock"
49
49
  );
50
50
  return t;
51
51
  }
52
- async function Bo(e) {
52
+ async function Oo(e) {
53
53
  const {
54
54
  btcVaultRegistryAddress: t,
55
55
  vaultId: r,
56
56
  hashlock: o,
57
57
  activationMetadata: n,
58
- writeContract: a,
59
- signal: s
58
+ writeContract: i,
59
+ signal: a
60
60
  } = e;
61
- s == null || s.throwIfAborted();
62
- const i = Ge({
61
+ a == null || a.throwIfAborted();
62
+ const s = qe({
63
63
  btcVaultRegistryAddress: t,
64
64
  vaultId: r,
65
65
  secret: e.secret,
66
66
  hashlock: o
67
67
  });
68
- return Qt(n, "activationMetadata"), a({
68
+ return Zt(n, "activationMetadata"), i({
69
69
  address: t,
70
- abi: Ne,
70
+ abi: Ke,
71
71
  functionName: "activateVaultWithSecret",
72
- args: [r, i, n]
72
+ args: [r, s, n]
73
73
  });
74
74
  }
75
- async function Vo(e) {
76
- const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: n, signal: a } = e;
77
- a == null || a.throwIfAborted();
78
- const s = Ge({
75
+ async function No(e) {
76
+ const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: n, signal: i } = e;
77
+ i == null || i.throwIfAborted();
78
+ const a = qe({
79
79
  btcVaultRegistryAddress: t,
80
80
  vaultId: r,
81
81
  secret: e.secret,
@@ -83,82 +83,82 @@ async function Vo(e) {
83
83
  });
84
84
  return n({
85
85
  address: t,
86
- abi: Ne,
86
+ abi: Ke,
87
87
  functionName: "activateVaultWithSecretAndRedeem",
88
- args: [r, s]
88
+ args: [r, a]
89
89
  });
90
90
  }
91
- class Jt extends Error {
91
+ class er extends Error {
92
92
  constructor(t, r) {
93
93
  super(
94
94
  "Transaction graph's challenger set does not match the vault's (local ∪ universal)" + (t.length > 0 ? ` (missing: ${t.join(", ")})` : "") + (r.length > 0 ? ` (unexpected: ${r.join(", ")})` : "") + ". Refusing to sign an incomplete or padded challenger set."
95
95
  ), this.missing = t, this.unexpected = r, this.name = "ChallengerSetMismatchError";
96
96
  }
97
97
  }
98
- function Zt(e) {
99
- const t = Me({
98
+ function tr(e) {
99
+ const t = Le({
100
100
  claimerBtcPubkey: e.depositorBtcPubkey,
101
101
  depositorBtcPubkey: e.depositorBtcPubkey,
102
102
  vaultProviderBtcPubkey: e.vaultProviderBtcPubkey,
103
103
  vaultKeeperBtcPubkeys: e.vaultKeeperBtcPubkeys
104
- }), r = e.universalChallengerBtcPubkeys.map(be), o = t.filter((h) => r.includes(h));
104
+ }), r = e.universalChallengerBtcPubkeys.map(ve), o = t.filter((l) => r.includes(l));
105
105
  if (o.length > 0)
106
106
  throw new Error(
107
107
  `Cannot check the challenger set: vault keepers and universal challengers overlap (${o.join(", ")}).`
108
108
  );
109
- const n = e.graphChallengerPubkeys.map(be), a = new Set(n);
110
- if (a.size !== n.length)
109
+ const n = e.graphChallengerPubkeys.map(ve), i = new Set(n);
110
+ if (i.size !== n.length)
111
111
  throw new Error(
112
112
  "Transaction graph lists the same challenger more than once."
113
113
  );
114
- const s = [...t, ...r], i = new Set(s), u = s.filter((h) => !a.has(h)), c = n.filter((h) => !i.has(h));
114
+ const a = [...t, ...r], s = new Set(a), u = a.filter((l) => !i.has(l)), c = n.filter((l) => !s.has(l));
115
115
  if (u.length > 0 || c.length > 0)
116
- throw new Jt(u, c);
116
+ throw new er(u, c);
117
117
  }
118
- function be(e) {
118
+ function ve(e) {
119
119
  return f(e).toLowerCase();
120
120
  }
121
- const Xe = 0;
122
- class er extends Error {
121
+ const je = 0;
122
+ class rr extends Error {
123
123
  constructor(t, r) {
124
124
  super(
125
- `Payout transaction output ${Xe} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
125
+ `Payout transaction output ${je} pays ${r}, not the vault's registered payout script ${t}. Refusing to sign a payout to another destination.`
126
126
  ), this.expectedScriptHex = t, this.actualScriptHex = r, this.name = "PayoutDestinationError";
127
127
  }
128
128
  }
129
- function tr(e) {
129
+ function or(e) {
130
130
  let t;
131
131
  try {
132
- t = Fe.fromBase64(e.payoutPsbtBase64);
132
+ t = Ue.fromBase64(e.payoutPsbtBase64);
133
133
  } catch (u) {
134
134
  throw new Error("Payout PSBT cannot be parsed.", { cause: u });
135
135
  }
136
- const { version: r, locktime: o, outs: n } = rr(t);
137
- if (r !== he || o !== pe)
136
+ const { version: r, locktime: o, outs: n } = nr(t);
137
+ if (r !== pe || o !== de)
138
138
  throw new Error(
139
- `Payout transaction has version ${r} and locktime ${o}, expected ${he} and ${pe}.`
139
+ `Payout transaction has version ${r} and locktime ${o}, expected ${pe} and ${de}.`
140
140
  );
141
- if (n.length !== q)
141
+ if (n.length !== z)
142
142
  throw new Error(
143
- `Payout transaction has ${n.length} output(s), expected exactly ${q} for a depositor-as-claimer payout.`
143
+ `Payout transaction has ${n.length} output(s), expected exactly ${z} for a depositor-as-claimer payout.`
144
144
  );
145
- const a = f(
145
+ const i = f(
146
146
  e.registeredPayoutScriptPubKey
147
147
  ).toLowerCase();
148
- if (a.length === 0)
148
+ if (i.length === 0)
149
149
  throw new Error(
150
150
  "registeredPayoutScriptPubKey is empty; the vault's on-chain payout script is required to check the Payout destination."
151
151
  );
152
- const s = n[Xe].script.toString("hex").toLowerCase();
153
- if (!I.from(s, "hex").equals(I.from(a, "hex")))
154
- throw new er(a, s);
155
- const i = n[q - 1];
156
- if (i.value !== de)
152
+ const a = n[je].script.toString("hex").toLowerCase();
153
+ if (!I.from(a, "hex").equals(I.from(i, "hex")))
154
+ throw new rr(i, a);
155
+ const s = n[z - 1];
156
+ if (s.value !== ge)
157
157
  throw new Error(
158
- `Payout CPFP anchor value ${i.value} sats must equal ${de} sats.`
158
+ `Payout CPFP anchor value ${s.value} sats must equal ${ge} sats.`
159
159
  );
160
160
  }
161
- function rr(e) {
161
+ function nr(e) {
162
162
  return {
163
163
  version: e.version,
164
164
  locktime: e.locktime,
@@ -168,109 +168,109 @@ function rr(e) {
168
168
  }))
169
169
  };
170
170
  }
171
- const je = 0;
172
- class or extends Error {
171
+ const ze = 0;
172
+ class sr extends Error {
173
173
  constructor(t, r, o) {
174
174
  super(
175
175
  `Transaction graph does not belong to vault ${t}: its Claim spends PegIn ${o}, which derives vault ${r}. Refusing to sign for a graph served for another vault.`
176
176
  ), this.expectedVaultId = t, this.derivedVaultId = r, this.peginTxid = o, this.name = "VaultIdBindingError";
177
177
  }
178
178
  }
179
- function nr(e) {
179
+ function ar(e) {
180
180
  let t;
181
181
  try {
182
- t = Fe.fromBase64(e);
182
+ t = Ue.fromBase64(e);
183
183
  } catch (o) {
184
184
  throw new Error("Claim PSBT cannot be parsed.", { cause: o });
185
185
  }
186
- const r = t.txInputs[je];
186
+ const r = t.txInputs[ze];
187
187
  if (!r)
188
188
  throw new Error("Claim PSBT carries no PegIn input to bind the vault to.");
189
- return ze(r.hash);
189
+ return Ye(r.hash);
190
190
  }
191
- function sr(e) {
192
- const t = e.ins[je];
191
+ function ir(e) {
192
+ const t = e.ins[ze];
193
193
  if (!t)
194
194
  throw new Error(
195
195
  "Artifacts file's claim_tx carries no PegIn input to bind the vault to."
196
196
  );
197
- return ze(t.hash);
197
+ return Ye(t.hash);
198
198
  }
199
- function qe(e) {
200
- const t = G(
201
- It(e.peginTxid, e.depositorEthAddress)
202
- ), r = G(e.expectedVaultId);
199
+ function We(e) {
200
+ const t = X(
201
+ Bt(e.peginTxid, e.depositorEthAddress)
202
+ ), r = X(e.expectedVaultId);
203
203
  if (t !== r)
204
- throw new or(r, t, e.peginTxid);
204
+ throw new sr(r, t, e.peginTxid);
205
205
  }
206
- function G(e) {
206
+ function X(e) {
207
207
  return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
208
208
  }
209
- function ze(e) {
209
+ function Ye(e) {
210
210
  return I.from(e).reverse().toString("hex");
211
211
  }
212
- const ar = 0, ir = 0, ur = 1, cr = 0, lr = 0;
213
- async function Oo(e) {
214
- const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n, a, s] = await Promise.all([
215
- yt(t, r),
216
- bt(t, r),
212
+ const ur = 0, cr = 0, lr = 1, hr = 0, pr = 0;
213
+ async function Ho(e) {
214
+ const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n, i, a] = await Promise.all([
217
215
  mt(t, r),
218
- Pt(t, r)
216
+ vt(t, r),
217
+ Pt(t, r),
218
+ wt(t, r)
219
219
  ]);
220
- qe({
221
- peginTxid: nr(o),
220
+ We({
221
+ peginTxid: ar(o),
222
222
  depositorEthAddress: e.vault.depositorEthAddress,
223
223
  expectedVaultId: e.vault.vaultId
224
224
  });
225
- const i = await vt(
225
+ const s = await xt(
226
226
  t,
227
227
  r
228
228
  );
229
- for (const x of [a, i])
230
- tr({
231
- payoutPsbtBase64: x,
229
+ for (const w of [i, s])
230
+ or({
231
+ payoutPsbtBase64: w,
232
232
  registeredPayoutScriptPubKey: e.vault.registeredPayoutScriptPubKey
233
233
  });
234
- Zt({
235
- graphChallengerPubkeys: Object.keys(s),
234
+ tr({
235
+ graphChallengerPubkeys: Object.keys(a),
236
236
  depositorBtcPubkey: e.depositorPublicKey,
237
237
  vaultProviderBtcPubkey: e.vault.vaultProviderBtcPubkey,
238
238
  vaultKeeperBtcPubkeys: e.vault.vaultKeeperBtcPubkeys,
239
239
  universalChallengerBtcPubkeys: e.vault.universalChallengerBtcPubkeys
240
240
  });
241
241
  const u = [
242
- { psbtBase64: o, inputIndex: ar },
243
- { psbtBase64: n, inputIndex: ir },
244
- { psbtBase64: a, inputIndex: ur },
242
+ { psbtBase64: o, inputIndex: ur },
243
+ { psbtBase64: n, inputIndex: cr },
244
+ { psbtBase64: i, inputIndex: lr },
245
245
  {
246
- psbtBase64: i,
247
- inputIndex: cr
246
+ psbtBase64: s,
247
+ inputIndex: hr
248
248
  }
249
- ], c = Object.keys(s);
250
- for (const x of c)
251
- for (const w of s[x])
252
- u.push({ psbtBase64: w, inputIndex: lr });
253
- const h = await pr(
249
+ ], c = Object.keys(a);
250
+ for (const w of c)
251
+ for (const x of a[w])
252
+ u.push({ psbtBase64: x, inputIndex: pr });
253
+ const l = await gr(
254
254
  e.btcWallet,
255
255
  e.depositorPublicKey,
256
256
  e.btcNetwork,
257
257
  u
258
258
  );
259
- let l = 0;
260
- const p = h[l++], d = h[l++], g = h[l++], b = h[l++], y = {};
261
- for (const x of c) {
262
- const w = s[x].length;
263
- y[x] = h.slice(
264
- l,
265
- l + w
266
- ), l += w;
259
+ let h = 0;
260
+ const p = l[h++], d = l[h++], g = l[h++], b = l[h++], y = {};
261
+ for (const w of c) {
262
+ const x = a[w].length;
263
+ y[w] = l.slice(
264
+ h,
265
+ h + x
266
+ ), h += x;
267
267
  }
268
- const m = await wt(
268
+ const m = await Et(
269
269
  t,
270
270
  r,
271
271
  p
272
272
  );
273
- return xt({
273
+ return kt({
274
274
  txGraphVersion: t,
275
275
  graphJson: r,
276
276
  signedClaimTxHex: m,
@@ -286,7 +286,7 @@ async function Oo(e) {
286
286
  expectedVaultCoreVersion: e.vault.vaultCoreVersion
287
287
  });
288
288
  }
289
- function me(e) {
289
+ function Pe(e) {
290
290
  const t = e.replace(/^0x/, "").toLowerCase();
291
291
  if (t.length === 66) return t.slice(2);
292
292
  if (t.length === 64) return t;
@@ -294,62 +294,62 @@ function me(e) {
294
294
  `Public key must be 33-byte compressed or 32-byte x-only hex, got ${t.length / 2} bytes.`
295
295
  );
296
296
  }
297
- async function hr(e, t, r) {
297
+ async function dr(e, t, r) {
298
298
  const o = await e.getPublicKeyHex();
299
- if (me(o) !== me(t))
299
+ if (Pe(o) !== Pe(t))
300
300
  throw new Error(
301
301
  "Connected wallet does not hold the vault's depositor key. Select the account that made the deposit, then try again."
302
302
  );
303
303
  const n = await e.getAddress();
304
- if (!ut(n, t, r))
304
+ if (!lt(n, t, r))
305
305
  throw new Error(
306
306
  `Connected wallet reports address "${n}", which is not derived from the vault's depositor key. Select the account that made the deposit, then try again.`
307
307
  );
308
308
  return n;
309
309
  }
310
- async function pr(e, t, r, o) {
311
- const n = await hr(
310
+ async function gr(e, t, r, o) {
311
+ const n = await dr(
312
312
  e,
313
313
  t,
314
314
  r
315
- ), a = await De(
315
+ ), i = await Fe(
316
316
  e,
317
- o.map((s) => dr(s.psbtBase64)),
317
+ o.map((a) => fr(a.psbtBase64)),
318
318
  o.map(
319
- (s) => gt(
319
+ (a) => yt(
320
320
  t,
321
- s.inputIndex,
321
+ a.inputIndex,
322
322
  n
323
323
  )
324
324
  )
325
325
  );
326
326
  return Promise.all(
327
- a.map(
328
- (s, i) => Et(gr(s), o[i].inputIndex)
327
+ i.map(
328
+ (a, s) => _t(yr(a), o[s].inputIndex)
329
329
  )
330
330
  );
331
331
  }
332
- function dr(e) {
332
+ function fr(e) {
333
333
  return I.from(e, "base64").toString("hex");
334
334
  }
335
- function gr(e) {
335
+ function yr(e) {
336
336
  return I.from(e, "hex").toString("base64");
337
337
  }
338
- async function No(e) {
339
- const t = await St(e.btcWallet, e.vaultContext);
338
+ async function Ko(e) {
339
+ const t = await Rt(e.btcWallet, e.vaultContext);
340
340
  let r;
341
341
  try {
342
- r = await kt(t, e.htlcVout);
342
+ r = await Tt(t, e.htlcVout);
343
343
  } finally {
344
344
  t.fill(0);
345
345
  }
346
346
  let o;
347
347
  try {
348
- o = await _t(r);
348
+ o = await $t(r);
349
349
  } finally {
350
350
  r.fill(0);
351
351
  }
352
- return fr(o.pk_hash, e.expectedWotsPkHash), await Tt(
352
+ return br(o.pk_hash, e.expectedWotsPkHash), await Ct(
353
353
  e.txGraphVersion,
354
354
  o.keypair,
355
355
  e.txGraphJson
@@ -358,61 +358,61 @@ async function No(e) {
358
358
  pkHash: o.pk_hash
359
359
  };
360
360
  }
361
- function fr(e, t) {
362
- if (D(e) !== D(t))
361
+ function br(e, t) {
362
+ if (M(e) !== M(t))
363
363
  throw new Error(
364
- `Derived WOTS public-key hash ${D(e)} does not match the vault's on-chain depositorWotsPkHash ${D(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
364
+ `Derived WOTS public-key hash ${M(e)} does not match the vault's on-chain depositorWotsPkHash ${M(t)}. The wallet, the HTLC output index, or the derivation itself is not the one this vault was created with.`
365
365
  );
366
366
  }
367
- function D(e) {
367
+ function M(e) {
368
368
  return `0x${(e.startsWith("0x") ? e.slice(2) : e).toLowerCase()}`;
369
369
  }
370
- const yr = 3;
371
- class br extends Error {
370
+ const mr = 3;
371
+ class vr extends Error {
372
372
  constructor(t, r) {
373
373
  super(
374
374
  `Artifacts belong to vault ${r}, not ${t}. Select the artifacts file saved for this vault.`
375
375
  ), this.expectedVaultId = t, this.actualVaultId = r, this.name = "ArtifactsVaultMismatchError";
376
376
  }
377
377
  }
378
- function mr(e) {
378
+ function Pr(e) {
379
379
  let t;
380
380
  try {
381
381
  t = JSON.parse(e);
382
- } catch (s) {
383
- throw new Error("Artifacts file is not valid JSON.", { cause: s });
382
+ } catch (a) {
383
+ throw new Error("Artifacts file is not valid JSON.", { cause: a });
384
384
  }
385
- const r = Pe(t.vault_id, "vault_id"), o = Pr(Pe(t.claim_tx, "claim_tx")), n = W(
385
+ const r = we(t.vault_id, "vault_id"), o = wr(we(t.claim_tx, "claim_tx")), n = Y(
386
386
  t.prover_circuit_version,
387
387
  "prover_circuit_version"
388
- ), a = t.claimable_event_block_number === void 0 ? 0n : BigInt(
389
- W(
388
+ ), i = t.claimable_event_block_number === void 0 ? 0n : BigInt(
389
+ Y(
390
390
  t.claimable_event_block_number,
391
391
  "claimable_event_block_number"
392
392
  )
393
393
  );
394
394
  return {
395
- vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : W(t.vault_core_version, "vault_core_version"),
395
+ vaultCoreVersion: t.vault_core_version === void 0 ? void 0 : Y(t.vault_core_version, "vault_core_version"),
396
396
  vaultId: r,
397
397
  claimTxid: o.getId(),
398
- peginTxid: sr(o),
398
+ peginTxid: ir(o),
399
399
  proverCircuitVersion: n,
400
- claimableEventBlockNumber: a,
400
+ claimableEventBlockNumber: i,
401
401
  babeSessionChallengerPubkeys: Object.keys(
402
- vr(t.babe_sessions, "babe_sessions")
402
+ xr(t.babe_sessions, "babe_sessions")
403
403
  )
404
404
  };
405
405
  }
406
- async function Ho(e) {
407
- const t = mr(e.artifactsJson), r = G(e.expectedVaultId), o = G(t.vaultId);
406
+ async function Do(e) {
407
+ const t = Pr(e.artifactsJson), r = X(e.expectedVaultId), o = X(t.vaultId);
408
408
  if (r !== o)
409
- throw new br(r, o);
410
- qe({
409
+ throw new vr(r, o);
410
+ We({
411
411
  peginTxid: t.peginTxid,
412
412
  depositorEthAddress: e.depositorEthAddress,
413
413
  expectedVaultId: r
414
414
  });
415
- const n = e.txGraphVersion ?? yr;
415
+ const n = e.txGraphVersion ?? mr;
416
416
  if (t.vaultCoreVersion !== void 0 && t.vaultCoreVersion !== n)
417
417
  throw new Error(
418
418
  `Artifacts record vault core version ${t.vaultCoreVersion}, but verification was asked for version ${n}.`
@@ -421,9 +421,9 @@ async function Ho(e) {
421
421
  throw new Error(
422
422
  "Artifacts carry no claimable event block number. They were assembled before the Ethereum withdrawal was initiated; assemble them again."
423
423
  );
424
- return await $t(n, e.artifactsJson), t;
424
+ return await At(n, e.artifactsJson), t;
425
425
  }
426
- function Pr(e) {
426
+ function wr(e) {
427
427
  try {
428
428
  return B.fromHex(e);
429
429
  } catch (t) {
@@ -432,52 +432,52 @@ function Pr(e) {
432
432
  });
433
433
  }
434
434
  }
435
- function Pe(e, t) {
435
+ function we(e, t) {
436
436
  if (typeof e != "string" || e.length === 0)
437
437
  throw new Error(`Artifacts file is missing a usable "${t}".`);
438
438
  return e;
439
439
  }
440
- function W(e, t) {
440
+ function Y(e, t) {
441
441
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0)
442
442
  throw new Error(`Artifacts file is missing a usable "${t}".`);
443
443
  return e;
444
444
  }
445
- function vr(e, t) {
445
+ function xr(e, t) {
446
446
  if (e === void 0) return {};
447
447
  if (typeof e != "object" || e === null || Array.isArray(e))
448
448
  throw new Error(`Artifacts file is missing a usable "${t}".`);
449
449
  return e;
450
450
  }
451
- const wr = 8, xr = 6e3, Er = 10 * 6e4, kr = 10;
452
- class We extends Error {
451
+ const Er = 8, kr = 6e3, _r = 10 * 6e4, Tr = 10;
452
+ class Qe extends Error {
453
453
  constructor(t) {
454
454
  super(t), this.name = "PeginRegistrationMissingError";
455
455
  }
456
456
  }
457
- class Ye extends Error {
457
+ class Je extends Error {
458
458
  constructor(t) {
459
459
  super(t), this.name = "PeginRegistrationNotFinalError";
460
460
  }
461
461
  }
462
- function _r(e) {
463
- return e instanceof We || e instanceof Error && e.name === "PeginRegistrationMissingError";
462
+ function $r(e) {
463
+ return e instanceof Qe || e instanceof Error && e.name === "PeginRegistrationMissingError";
464
464
  }
465
- function Ko(e) {
466
- return e instanceof Ye || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
465
+ function Mo(e) {
466
+ return e instanceof Je || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
467
467
  }
468
- function ve(e) {
468
+ function xe(e) {
469
469
  const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
470
470
  return o < 0n ? 0 : Number(o);
471
471
  }
472
- async function Do(e) {
472
+ async function Fo(e) {
473
473
  const {
474
474
  vaultRegistryReader: t,
475
475
  getBlockNumber: r,
476
476
  vaultIds: o,
477
- required: n = wr,
478
- pollIntervalMs: a = xr,
479
- timeoutMs: s = Er,
480
- signal: i,
477
+ required: n = Er,
478
+ pollIntervalMs: i = kr,
479
+ timeoutMs: a = _r,
480
+ signal: s,
481
481
  onProgress: u
482
482
  } = e;
483
483
  if (o.length === 0)
@@ -485,51 +485,51 @@ async function Do(e) {
485
485
  "waitForPeginRegistrationDepth requires at least one vault ID"
486
486
  );
487
487
  const c = Date.now();
488
- let h = !1, l = 0, p;
488
+ let l = !1, h = 0, p;
489
489
  for (; ; ) {
490
- if (i != null && i.aborted)
490
+ if (s != null && s.aborted)
491
491
  throw new Error(
492
492
  `Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
493
493
  );
494
- if (Date.now() - c >= s)
495
- throw new Ye(
496
- `Peg-in registration did not reach ${n} Ethereum confirmations within ${s}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (p instanceof Error ? ` Last read error: ${p.message}` : "")
494
+ if (Date.now() - c >= a)
495
+ throw new Je(
496
+ `Peg-in registration did not reach ${n} Ethereum confirmations within ${a}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (p instanceof Error ? ` Last read error: ${p.message}` : "")
497
497
  );
498
498
  try {
499
499
  const d = await r(), g = await Promise.all(
500
500
  o.map((y) => t.getVaultBasicInfo(y))
501
501
  ), b = g.findIndex(
502
- (y) => y.depositor === Rt || y.createdAt === 0n
502
+ (y) => y.depositor === Vt || y.createdAt === 0n
503
503
  );
504
504
  if (b !== -1) {
505
- if (l += 1, !h && l > kr)
506
- throw new We(
507
- `Vault ${o[b]} is still not visible on-chain after ${l} reads — the registration does not exist.`
505
+ if (h += 1, !l && h > Tr)
506
+ throw new Qe(
507
+ `Vault ${o[b]} is still not visible on-chain after ${h} reads — the registration does not exist.`
508
508
  );
509
509
  console.warn(
510
510
  `Peg-in registration for vault ${o[b]} is not visible in chain state at block ${d} — a lagging RPC backend or an Ethereum reorg. Still polling.`
511
511
  ), u == null || u({ confirmations: 0, required: n });
512
512
  } else {
513
- h = !0, l = 0, p = void 0;
514
- let y = g[0], m = ve({
513
+ l = !0, h = 0, p = void 0;
514
+ let y = g[0], m = xe({
515
515
  currentBlock: d,
516
516
  createdAtBlock: g[0].createdAt
517
517
  });
518
- for (const x of g.slice(1)) {
519
- const w = ve({
518
+ for (const w of g.slice(1)) {
519
+ const x = xe({
520
520
  currentBlock: d,
521
- createdAtBlock: x.createdAt
521
+ createdAtBlock: w.createdAt
522
522
  });
523
- w < m && (m = w, y = x);
523
+ x < m && (m = x, y = w);
524
524
  }
525
525
  if (u == null || u({ confirmations: m, required: n }), m >= n)
526
526
  return { confirmations: m, basicInfo: y };
527
527
  }
528
528
  } catch (d) {
529
- if (_r(d))
529
+ if ($r(d))
530
530
  throw d;
531
531
  console.warn(
532
- `Registration-depth read failed (retrying in ${a}ms): ` + (d instanceof Error ? d.message : String(d))
532
+ `Registration-depth read failed (retrying in ${i}ms): ` + (d instanceof Error ? d.message : String(d))
533
533
  ), p = d;
534
534
  }
535
535
  await new Promise((d, g) => {
@@ -540,14 +540,14 @@ async function Do(e) {
540
540
  )
541
541
  );
542
542
  }, y = setTimeout(() => {
543
- i == null || i.removeEventListener("abort", b), d();
544
- }, a);
545
- i == null || i.addEventListener("abort", b, { once: !0 });
543
+ s == null || s.removeEventListener("abort", b), d();
544
+ }, i);
545
+ s == null || s.addEventListener("abort", b, { once: !0 });
546
546
  });
547
547
  }
548
548
  }
549
- const Tr = /^(?:[0-9a-f]{2})*$/, $r = /^[0-9a-f]{64}$/, Cr = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Ar = -2147483648, Sr = 2147483647, Y = 4294967295, we = 2, xe = 2;
550
- class v extends Error {
549
+ const Cr = /^(?:[0-9a-f]{2})*$/, Ar = /^[0-9a-f]{64}$/, Sr = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Ir = -2147483648, Rr = 2147483647, Q = 4294967295, Ee = 2, ke = 2;
550
+ class P extends Error {
551
551
  constructor(t) {
552
552
  super(t), this.name = "GraphFingerprintError";
553
553
  }
@@ -555,264 +555,264 @@ class v extends Error {
555
555
  function E(e, t, r) {
556
556
  const o = e[t];
557
557
  if (o === void 0)
558
- throw new v(`Graph tx ${r} is missing "${t}"`);
558
+ throw new P(`Graph tx ${r} is missing "${t}"`);
559
559
  return o;
560
560
  }
561
- function K(e, t) {
561
+ function D(e, t) {
562
562
  if (!Array.isArray(e))
563
- throw new v(`Graph tx ${t} is not an array`);
563
+ throw new P(`Graph tx ${t} is not an array`);
564
564
  return e;
565
565
  }
566
566
  function A(e, t) {
567
567
  if (e === null || typeof e != "object" || Array.isArray(e))
568
- throw new v(`Graph tx ${t} is not an object`);
568
+ throw new P(`Graph tx ${t} is not an object`);
569
569
  return e;
570
570
  }
571
- function N(e, t, r, o) {
571
+ function H(e, t, r, o) {
572
572
  if (typeof e != "number" || !Number.isSafeInteger(e) || e < r || e > o)
573
- throw new v(
573
+ throw new P(
574
574
  `Graph tx ${t} is not an integer in [${r}, ${o}]`
575
575
  );
576
576
  return e;
577
577
  }
578
- function Q(e, t) {
579
- if (typeof e != "string" || !Tr.test(e))
580
- throw new v(
578
+ function J(e, t) {
579
+ if (typeof e != "string" || !Cr.test(e))
580
+ throw new P(
581
581
  `Graph tx ${t} is not lowercase hex without a prefix`
582
582
  );
583
583
  return I.from(e, "hex");
584
584
  }
585
- function X(e, t) {
586
- if (typeof e != "string" || !$r.test(e))
587
- throw new v(
585
+ function q(e, t) {
586
+ if (typeof e != "string" || !Ar.test(e))
587
+ throw new P(
588
588
  `Graph ${t} is not 32 bytes of lowercase hex`
589
589
  );
590
590
  return e;
591
591
  }
592
- function Ee(e, t) {
592
+ function _e(e, t) {
593
593
  const r = A(e, t), o = new B();
594
- return o.version = N(
594
+ return o.version = H(
595
595
  E(r, "version", t),
596
596
  `${t}.version`,
597
- Ar,
598
- Sr
599
- ), o.locktime = N(
597
+ Ir,
598
+ Rr
599
+ ), o.locktime = H(
600
600
  E(r, "lock_time", t),
601
601
  `${t}.lock_time`,
602
602
  0,
603
- Y
604
- ), K(E(r, "input", t), `${t}.input`).forEach((n, a) => {
605
- const s = `${t}.input[${a}]`, i = A(n, s), u = E(i, "previous_output", s), c = typeof u == "string" && Cr.exec(u);
603
+ Q
604
+ ), D(E(r, "input", t), `${t}.input`).forEach((n, i) => {
605
+ const a = `${t}.input[${i}]`, s = A(n, a), u = E(s, "previous_output", a), c = typeof u == "string" && Sr.exec(u);
606
606
  if (!c)
607
- throw new v(
608
- `Graph tx ${s}.previous_output is not "<txid>:<vout>"`
607
+ throw new P(
608
+ `Graph tx ${a}.previous_output is not "<txid>:<vout>"`
609
609
  );
610
- const h = N(Number(c[2]), `${s}.previous_output vout`, 0, Y);
610
+ const l = H(Number(c[2]), `${a}.previous_output vout`, 0, Q);
611
611
  o.addInput(
612
612
  I.from(c[1], "hex").reverse(),
613
- h,
614
- N(E(i, "sequence", s), `${s}.sequence`, 0, Y),
615
- Q(E(i, "script_sig", s), `${s}.script_sig`)
616
- ), o.ins[a].witness = K(
617
- E(i, "witness", s),
618
- `${s}.witness`
619
- ).map((l, p) => Q(l, `${s}.witness[${p}]`));
620
- }), K(E(r, "output", t), `${t}.output`).forEach((n, a) => {
621
- const s = `${t}.output[${a}]`, i = A(n, s);
613
+ l,
614
+ H(E(s, "sequence", a), `${a}.sequence`, 0, Q),
615
+ J(E(s, "script_sig", a), `${a}.script_sig`)
616
+ ), o.ins[i].witness = D(
617
+ E(s, "witness", a),
618
+ `${a}.witness`
619
+ ).map((h, p) => J(h, `${a}.witness[${p}]`));
620
+ }), D(E(r, "output", t), `${t}.output`).forEach((n, i) => {
621
+ const a = `${t}.output[${i}]`, s = A(n, a);
622
622
  o.addOutput(
623
- Q(E(i, "script_pubkey", s), `${s}.script_pubkey`),
624
- N(E(i, "value", s), `${s}.value`, 0, Number.MAX_SAFE_INTEGER)
623
+ J(E(s, "script_pubkey", a), `${a}.script_pubkey`),
624
+ H(E(s, "value", a), `${a}.value`, 0, Number.MAX_SAFE_INTEGER)
625
625
  );
626
626
  }), new Uint8Array(o.toBuffer());
627
627
  }
628
- function H(e, t) {
628
+ function K(e, t) {
629
629
  const r = f(e).toLowerCase();
630
630
  let o;
631
631
  try {
632
632
  o = B.fromHex(r);
633
633
  } catch (n) {
634
- throw new v(
634
+ throw new P(
635
635
  `Presign ${t} is not one transaction: ${n instanceof Error ? n.message : String(n)}`
636
636
  );
637
637
  }
638
638
  if (o.toHex() !== r)
639
- throw new v(
639
+ throw new P(
640
640
  `Presign ${t} is not a canonical transaction encoding`
641
641
  );
642
642
  return o;
643
643
  }
644
- function Ir(e, t) {
644
+ function Br(e, t) {
645
645
  const [r, ...o] = e.ins;
646
646
  if (!r || o.length > 0)
647
- throw new v(
647
+ throw new P(
648
648
  `Presign claim_tx must have exactly one input, got ${e.ins.length}`
649
649
  );
650
650
  const n = I.from(r.hash).reverse().toString("hex");
651
- if (n !== t || r.index !== le)
652
- throw new v(
653
- `Presign claim_tx must spend ${t}:${le}, got ${n}:${r.index}`
651
+ if (n !== t || r.index !== he)
652
+ throw new P(
653
+ `Presign claim_tx must spend ${t}:${he}, got ${n}:${r.index}`
654
654
  );
655
- if (e.version !== we)
656
- throw new v(
657
- `Presign claim_tx version must be ${we}, got ${e.version}`
655
+ if (e.version !== Ee)
656
+ throw new P(
657
+ `Presign claim_tx version must be ${Ee}, got ${e.version}`
658
658
  );
659
659
  if (r.witness.length > 0)
660
- throw new v(
660
+ throw new P(
661
661
  `Presign claim_tx input must have an empty witness, got ${r.witness.length} item(s)`
662
662
  );
663
- if (e.outs.length !== xe)
664
- throw new v(
665
- `Presign claim_tx must have exactly ${xe} outputs, got ${e.outs.length}`
663
+ if (e.outs.length !== ke)
664
+ throw new P(
665
+ `Presign claim_tx must have exactly ${ke} outputs, got ${e.outs.length}`
666
666
  );
667
667
  }
668
- function Qe(e) {
668
+ function Ze(e) {
669
669
  const t = [...e.challengers].sort(
670
670
  (o, n) => o.pubkey < n.pubkey ? -1 : o.pubkey > n.pubkey ? 1 : 0
671
671
  ), r = [e.peginTx, e.claimTx, e.assertTx, e.payoutTx];
672
672
  return t.forEach((o, n) => {
673
- const a = X(o.pubkey, "challenger pubkey");
674
- if (n > 0 && t[n - 1].pubkey === a)
675
- throw new v(`Graph lists challenger ${a} twice`);
676
- r.push(ye(a), o.nopayoutTx);
677
- for (const s of o.outputLabelHashes)
678
- r.push(ye(X(s, "output_label_hashes entry")));
679
- }), Kt(Dt(Mt(...r)));
680
- }
681
- function Rr(e) {
682
- const t = f(e.peginTxid).toLowerCase(), r = H(e.peginTxHex, "pegin_tx");
673
+ const i = q(o.pubkey, "challenger pubkey");
674
+ if (n > 0 && t[n - 1].pubkey === i)
675
+ throw new P(`Graph lists challenger ${i} twice`);
676
+ r.push(me(i), o.nopayoutTx);
677
+ for (const a of o.outputLabelHashes)
678
+ r.push(me(q(a, "output_label_hashes entry")));
679
+ }), Mt(Ft(Lt(...r)));
680
+ }
681
+ function Vr(e) {
682
+ const t = f(e.peginTxid).toLowerCase(), r = K(e.peginTxHex, "pegin_tx");
683
683
  if (r.getId() !== t)
684
- throw new v(
684
+ throw new P(
685
685
  `Presign pegin_tx hashes to ${r.getId()}, expected ${t}`
686
686
  );
687
- const o = H(e.claimTxHex, "claim_tx");
688
- Ir(o, t);
689
- const n = (a) => new Uint8Array(a.toBuffer());
690
- return Qe({
687
+ const o = K(e.claimTxHex, "claim_tx");
688
+ Br(o, t);
689
+ const n = (i) => new Uint8Array(i.toBuffer());
690
+ return Ze({
691
691
  peginTx: n(r),
692
692
  claimTx: n(o),
693
- assertTx: n(H(e.assertTxHex, "assert_tx")),
694
- payoutTx: n(H(e.payoutTxHex, "payout_tx")),
695
- challengers: e.challengers.map((a) => ({
696
- pubkey: $(a.challenger_pubkey),
697
- nopayoutTx: n(H(a.nopayout_tx.tx_hex, "nopayout_tx")),
698
- outputLabelHashes: a.output_label_hashes.map(
699
- (s) => f(s).toLowerCase()
693
+ assertTx: n(K(e.assertTxHex, "assert_tx")),
694
+ payoutTx: n(K(e.payoutTxHex, "payout_tx")),
695
+ challengers: e.challengers.map((i) => ({
696
+ pubkey: C(i.challenger_pubkey),
697
+ nopayoutTx: n(K(i.nopayout_tx.tx_hex, "nopayout_tx")),
698
+ outputLabelHashes: i.output_label_hashes.map(
699
+ (a) => f(a).toLowerCase()
700
700
  )
701
701
  }))
702
702
  });
703
703
  }
704
- function Br(e) {
705
- const t = (o) => Ee(A(E(e, o, "graph"), o).tx, o), r = A(
704
+ function Or(e) {
705
+ const t = (o) => _e(A(E(e, o, "graph"), o).tx, o), r = A(
706
706
  E(e, "challenger_subgraphs", "graph"),
707
707
  "challenger_subgraphs"
708
708
  );
709
- return Qe({
709
+ return Ze({
710
710
  peginTx: t("pegin_tx"),
711
711
  claimTx: t("claim_tx"),
712
712
  assertTx: t("assert_tx"),
713
713
  payoutTx: t("payout_tx"),
714
714
  challengers: Object.entries(r).map(([o, n]) => {
715
- const a = `challenger_subgraphs[${o}]`, s = A(n, a);
715
+ const i = `challenger_subgraphs[${o}]`, a = A(n, i);
716
716
  return {
717
717
  pubkey: o,
718
- nopayoutTx: Ee(
719
- A(E(s, "nopayout_tx", a), `${a}.nopayout_tx`).tx,
720
- `${a}.nopayout_tx`
718
+ nopayoutTx: _e(
719
+ A(E(a, "nopayout_tx", i), `${i}.nopayout_tx`).tx,
720
+ `${i}.nopayout_tx`
721
721
  ),
722
- outputLabelHashes: K(
723
- E(s, "output_label_hashes", a),
724
- `${a}.output_label_hashes`
722
+ outputLabelHashes: D(
723
+ E(a, "output_label_hashes", i),
724
+ `${i}.output_label_hashes`
725
725
  ).map(
726
- (i, u) => X(i, `${a}.output_label_hashes[${u}]`)
726
+ (s, u) => q(s, `${i}.output_label_hashes[${u}]`)
727
727
  )
728
728
  };
729
729
  })
730
730
  });
731
731
  }
732
- function Vr(e) {
732
+ function Nr(e) {
733
733
  const t = A(
734
734
  E(e, "challenger_pubkeys", "graph"),
735
735
  "challenger_pubkeys"
736
736
  ), r = /* @__PURE__ */ new Set();
737
737
  for (const o of ["local", "universal"])
738
- K(
738
+ D(
739
739
  E(t, o, "challenger_pubkeys"),
740
740
  `challenger_pubkeys.${o}`
741
- ).forEach((n, a) => {
742
- const s = X(n, `challenger_pubkeys.${o}[${a}]`);
743
- if (r.has(s))
744
- throw new v(
745
- `Graph declares challenger ${s} more than once`
741
+ ).forEach((n, i) => {
742
+ const a = q(n, `challenger_pubkeys.${o}[${i}]`);
743
+ if (r.has(a))
744
+ throw new P(
745
+ `Graph declares challenger ${a} more than once`
746
746
  );
747
- r.add(s);
747
+ r.add(a);
748
748
  });
749
749
  return r;
750
750
  }
751
- function Mo(e, t) {
752
- const r = Br(e);
751
+ function Lo(e, t) {
752
+ const r = Or(e);
753
753
  if (r !== t)
754
- throw new v(
754
+ throw new P(
755
755
  `Graph fingerprint ${r} does not match the presign fingerprint ${t}`
756
756
  );
757
757
  const o = Object.keys(
758
758
  A(e.challenger_subgraphs, "challenger_subgraphs")
759
- ), n = Vr(e);
760
- if (o.length !== n.size || o.some((a) => !n.has(a)))
761
- throw new v(
759
+ ), n = Nr(e);
760
+ if (o.length !== n.size || o.some((i) => !n.has(i)))
761
+ throw new P(
762
762
  `Graph challenger_subgraphs keys ${o.join(", ")} do not match challenger_pubkeys ${[...n].join(", ")}`
763
763
  );
764
764
  }
765
- const Or = 1;
766
- function Nr(e, t, r) {
765
+ const Hr = 1;
766
+ function Kr(e, t, r) {
767
767
  const o = r.map(
768
- (l) => f(l).toLowerCase()
769
- ), n = t.filter((l) => o.includes(l));
768
+ (h) => f(h).toLowerCase()
769
+ ), n = t.filter((h) => o.includes(h));
770
770
  if (n.length > 0)
771
771
  throw new Error(
772
772
  `Cannot validate challenger set: vault keepers and universal challengers overlap (${n.join(", ")})`
773
773
  );
774
- const a = [...t, ...o], s = e.map(
775
- (l) => f(l.challenger_pubkey).toLowerCase()
776
- ), i = new Set(s);
777
- if (i.size !== s.length)
774
+ const i = [...t, ...o], a = e.map(
775
+ (h) => f(h.challenger_pubkey).toLowerCase()
776
+ ), s = new Set(a);
777
+ if (s.size !== a.length)
778
778
  throw new Error(
779
779
  "Depositor graph contains duplicate challenger entries in challenger_presign_data"
780
780
  );
781
- const u = new Set(a), c = a.filter((l) => !i.has(l)), h = s.filter((l) => !u.has(l));
782
- if (c.length > 0 || h.length > 0)
781
+ const u = new Set(i), c = i.filter((h) => !s.has(h)), l = a.filter((h) => !u.has(h));
782
+ if (c.length > 0 || l.length > 0)
783
783
  throw new Error(
784
- "Depositor graph challenger set does not match expected (local ∪ universal)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
784
+ "Depositor graph challenger set does not match expected (local ∪ universal)" + (c.length > 0 ? ` (missing: ${c.join(", ")})` : "") + (l.length > 0 ? ` (unexpected: ${l.join(", ")})` : "")
785
785
  );
786
786
  }
787
- function Hr(e, t) {
787
+ function Dr(e, t) {
788
788
  const r = e.ins[t];
789
- return Ke(new Uint8Array(r.hash).slice().reverse());
789
+ return Me(new Uint8Array(r.hash).slice().reverse());
790
790
  }
791
- function J(e, t, r, o, n) {
792
- const a = e.ins[t];
793
- if (a.index !== 0)
791
+ function Z(e, t, r, o, n) {
792
+ const i = e.ins[t];
793
+ if (i.index !== 0)
794
794
  throw new Error(
795
- `NoPayout (challenger ${n}) input ${t} expected to spend ${o} vout 0, got vout ${a.index}`
795
+ `NoPayout (challenger ${n}) input ${t} expected to spend ${o} vout 0, got vout ${i.index}`
796
796
  );
797
- const s = r.getId(), i = Hr(e, t);
798
- if (i !== s)
797
+ const a = r.getId(), s = Dr(e, t);
798
+ if (s !== a)
799
799
  throw new Error(
800
- `NoPayout (challenger ${n}) input ${t} does not reference ${o} (expected txid ${s}, got ${i})`
800
+ `NoPayout (challenger ${n}) input ${t} does not reference ${o} (expected txid ${a}, got ${s})`
801
801
  );
802
802
  }
803
- async function Kr(e, t, r) {
804
- const o = [], n = [], a = [], s = Me({
803
+ async function Mr(e, t, r) {
804
+ const o = [], n = [], i = [], a = Le({
805
805
  claimerBtcPubkey: r.depositorBtcPubkey,
806
806
  depositorBtcPubkey: r.depositorBtcPubkey,
807
807
  vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
808
808
  vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
809
809
  });
810
- Nr(
810
+ Kr(
811
811
  e.challenger_presign_data,
812
- s,
812
+ a,
813
813
  r.universalChallengerBtcPubkeys
814
814
  );
815
- const i = await At({
815
+ const s = await It({
816
816
  vaultCoreVersion: r.vaultCoreVersion,
817
817
  vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
818
818
  vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
@@ -828,228 +828,233 @@ async function Kr(e, t, r) {
828
828
  network: r.network,
829
829
  claimerBtcPubkey: r.depositorBtcPubkey,
830
830
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
831
- commissionBps: Or,
831
+ commissionBps: Hr,
832
832
  protocolFeeRate: r.protocolFeeRate,
833
833
  councilMembers: r.councilMembers,
834
834
  councilQuorum: r.councilQuorum
835
835
  });
836
- o.push(i.psbtHex), n.push(
837
- M(
836
+ o.push(s.psbtHex), n.push(
837
+ F(
838
838
  t,
839
- ge
839
+ fe
840
840
  )
841
841
  );
842
842
  const u = f(r.depositorBtcPubkey), c = B.fromHex(
843
843
  f(e.assert_tx.tx_hex)
844
844
  );
845
- for (const h of e.challenger_presign_data) {
846
- const l = f(h.challenger_pubkey), p = o.length, d = await Dr({
847
- challenger: h,
848
- challengerPubkey: l,
845
+ for (const l of e.challenger_presign_data) {
846
+ const h = f(l.challenger_pubkey), p = o.length, d = await Fr({
847
+ challenger: l,
848
+ challengerPubkey: h,
849
849
  claimerPubkey: u,
850
- localChallengers: s,
850
+ localChallengers: a,
851
851
  assertTxParsed: c,
852
852
  ctx: r
853
853
  });
854
854
  o.push(d), n.push(
855
- M(
855
+ F(
856
856
  t,
857
- ge
857
+ fe
858
858
  )
859
- ), a.push({
860
- challengerPubkey: l,
859
+ ), i.push({
860
+ challengerPubkey: h,
861
861
  noPayoutIdx: p
862
862
  });
863
863
  }
864
- return { psbtHexes: o, signOptions: n, challengerEntries: a };
864
+ return { psbtHexes: o, signOptions: n, challengerEntries: i };
865
865
  }
866
- async function Dr(e) {
866
+ async function Fr(e) {
867
867
  const {
868
868
  challenger: t,
869
869
  challengerPubkey: r,
870
870
  claimerPubkey: o,
871
871
  localChallengers: n,
872
- assertTxParsed: a,
873
- ctx: s
872
+ assertTxParsed: i,
873
+ ctx: a
874
874
  } = e;
875
- Ft(
875
+ Ut(
876
876
  t.nopayout_tx.tx_hex,
877
877
  r,
878
- s.network
878
+ a.network
879
879
  );
880
- const i = B.fromHex(
880
+ const s = B.fromHex(
881
881
  f(t.nopayout_tx.tx_hex)
882
882
  ), u = B.fromHex(
883
883
  f(t.challenge_assert_x_tx.tx_hex)
884
884
  ), c = B.fromHex(
885
885
  f(t.challenge_assert_y_tx.tx_hex)
886
886
  );
887
- if (i.ins.length !== 3)
887
+ if (s.ins.length !== 3)
888
888
  throw new Error(
889
- `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
889
+ `NoPayout (challenger ${r}) must have exactly 3 inputs, got ${s.ins.length}`
890
890
  );
891
- J(
892
- i,
891
+ Z(
892
+ s,
893
893
  0,
894
- a,
894
+ i,
895
895
  "Assert",
896
896
  r
897
- ), J(
898
- i,
897
+ ), Z(
898
+ s,
899
899
  1,
900
900
  u,
901
901
  "ChallengeAssertX",
902
902
  r
903
- ), J(
904
- i,
903
+ ), Z(
904
+ s,
905
905
  2,
906
906
  c,
907
907
  "ChallengeAssertY",
908
908
  r
909
909
  );
910
- const h = [
911
- a.outs[0],
910
+ const l = [
911
+ i.outs[0],
912
912
  u.outs[0],
913
913
  c.outs[0]
914
- ].map((l) => ({
915
- script_pubkey: Ke(new Uint8Array(l.script)),
916
- value: l.value
914
+ ].map((h) => ({
915
+ script_pubkey: Me(new Uint8Array(h.script)),
916
+ value: h.value
917
917
  }));
918
- return Ut({
918
+ return Gt({
919
919
  noPayoutTxHex: t.nopayout_tx.tx_hex,
920
920
  challengerPubkey: r,
921
- prevouts: h,
921
+ prevouts: l,
922
922
  connectorParams: {
923
- txGraphVersion: s.vaultCoreVersion,
923
+ txGraphVersion: a.vaultCoreVersion,
924
924
  claimer: o,
925
925
  localChallengers: n,
926
- universalChallengers: s.universalChallengerBtcPubkeys,
927
- timelockAssert: s.timelockAssert,
928
- councilMembers: s.councilMembers,
929
- councilQuorum: s.councilQuorum
926
+ universalChallengers: a.universalChallengerBtcPubkeys,
927
+ timelockAssert: a.timelockAssert,
928
+ councilMembers: a.councilMembers,
929
+ councilQuorum: a.councilQuorum
930
930
  }
931
931
  });
932
932
  }
933
- function Mr(e, t, r) {
934
- F(e[0]);
933
+ function Lr(e, t, r) {
934
+ L(e[0]);
935
935
  const n = U(
936
936
  e[0].returnedPsbtHex,
937
937
  r
938
938
  );
939
- L({
939
+ G({
940
940
  requestedPsbtHex: e[0].requestedPsbtHex,
941
941
  signatureHex: n,
942
942
  signerXOnlyPubkeyHex: r,
943
943
  inputIndex: 0
944
944
  });
945
- const a = {};
946
- for (const s of t) {
947
- F(e[s.noPayoutIdx]);
948
- const i = U(
949
- e[s.noPayoutIdx].returnedPsbtHex,
945
+ const i = {};
946
+ for (const a of t) {
947
+ L(e[a.noPayoutIdx]);
948
+ const s = U(
949
+ e[a.noPayoutIdx].returnedPsbtHex,
950
950
  r
951
951
  );
952
- L({
953
- requestedPsbtHex: e[s.noPayoutIdx].requestedPsbtHex,
954
- signatureHex: i,
952
+ G({
953
+ requestedPsbtHex: e[a.noPayoutIdx].requestedPsbtHex,
954
+ signatureHex: s,
955
955
  signerXOnlyPubkeyHex: r,
956
956
  inputIndex: 0
957
- }), a[s.challengerPubkey] = {
958
- nopayout_signature: i
957
+ }), i[a.challengerPubkey] = {
958
+ nopayout_signature: s
959
959
  };
960
960
  }
961
961
  return {
962
962
  payout_signatures: {
963
963
  payout_signature: n
964
964
  },
965
- per_challenger: a
965
+ per_challenger: i
966
966
  };
967
967
  }
968
- async function Fr(e) {
969
- const { depositorGraph: t, btcWallet: r, signingContext: o } = e, n = await r.getPublicKeyHex(), { depositorPubkey: a } = ct(
968
+ async function Ur(e) {
969
+ const { depositorGraph: t, btcWallet: r, signingContext: o } = e, n = await r.getPublicKeyHex(), { depositorPubkey: i } = ht(
970
970
  n,
971
971
  f(o.depositorBtcPubkey)
972
- ), { psbtHexes: s, signOptions: i, challengerEntries: u } = await Kr(
972
+ ), { psbtHexes: a, signOptions: s, challengerEntries: u } = await Mr(
973
973
  t,
974
974
  n,
975
975
  o
976
- ), c = await De(
976
+ ), c = await Fe(
977
977
  r,
978
- s,
979
- i
980
- ), h = s.map((l, p) => ({
981
- requestedPsbtHex: l,
978
+ a,
979
+ s
980
+ ), l = a.map((h, p) => ({
981
+ requestedPsbtHex: h,
982
982
  returnedPsbtHex: c[p]
983
983
  }));
984
- return Mr(
985
- h,
984
+ return Lr(
985
+ l,
986
986
  u,
987
- a
987
+ i
988
988
  );
989
989
  }
990
- const Ur = 1e4;
991
- async function Je(e) {
990
+ const Gr = 1e4, O = 10;
991
+ async function et(e) {
992
992
  const {
993
993
  statusReader: t,
994
- peginTxid: r,
995
- targetStatuses: o,
996
- timeoutMs: n,
997
- pollIntervalMs: a = Ur,
994
+ vaultId: r,
995
+ peginTxid: o,
996
+ targetStatuses: n,
997
+ timeoutMs: i,
998
+ pollIntervalMs: a = Gr,
998
999
  signal: s
999
- } = e, i = Date.now();
1000
+ } = e, u = Date.now();
1000
1001
  for (; ; ) {
1001
1002
  if (s != null && s.aborted)
1002
1003
  throw new Error(
1003
- `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
1004
+ `Polling aborted for vault ${r.slice(0, O)}… (target: ${[...n].join(", ")})`
1004
1005
  );
1005
- if (Date.now() - i >= n)
1006
+ if (Date.now() - u >= i)
1006
1007
  throw new Error(
1007
- `Polling timeout after ${n}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
1008
+ `Polling timeout after ${i}ms for vault ${r.slice(0, O)}… (target: ${[...n].join(", ")})`
1008
1009
  );
1009
1010
  try {
1010
- const u = await t.getPeginStatus(
1011
- { pegin_txid: r },
1011
+ const c = await t.getPeginStatusByVaultId(
1012
+ { vault_id: r },
1012
1013
  s
1013
1014
  );
1014
- if (u.pegin_txid.toLowerCase() !== r.toLowerCase())
1015
+ if (be(c.vault_id) !== be(r))
1015
1016
  throw new Error(
1016
- `getPeginStatus returned status for pegin ${u.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
1017
+ `getPeginStatusByVaultId returned status for vault ${c.vault_id.slice(0, O)}…, requested ${r.slice(0, O)}…`
1017
1018
  );
1018
- const c = u.status;
1019
- if (o.has(c) || c === R.ACTIVATED)
1020
- return c;
1021
- if (c === R.EXPIRED || Ot.has(c))
1019
+ if (c.pegin_txid.toLowerCase() !== o.toLowerCase())
1022
1020
  throw new Error(
1023
- `Pegin ${r.slice(0, 8)}… reached terminal status "${c}" while waiting for ${[...o].join(", ")}`
1021
+ `getPeginStatusByVaultId returned status for pegin ${c.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
1024
1022
  );
1025
- } catch (u) {
1026
- if (!(u instanceof Nt && u.code === Ht.PEGIN_NOT_FOUND))
1027
- throw u;
1023
+ const l = c.status;
1024
+ if (n.has(l) || l === R.ACTIVATED)
1025
+ return l;
1026
+ if (l === R.EXPIRED || Ht.has(l))
1027
+ throw new Error(
1028
+ `Vault ${r.slice(0, O)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
1029
+ );
1030
+ } catch (c) {
1031
+ if (!(c instanceof Kt && c.code === Dt.PEGIN_NOT_FOUND))
1032
+ throw c;
1028
1033
  }
1029
- await new Promise((u, c) => {
1034
+ await new Promise((c, l) => {
1030
1035
  const h = () => {
1031
- clearTimeout(l), c(
1036
+ clearTimeout(p), l(
1032
1037
  new Error(
1033
- `Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
1038
+ `Polling aborted for vault ${r.slice(0, O)}… (target: ${[...n].join(", ")})`
1034
1039
  )
1035
1040
  );
1036
- }, l = setTimeout(() => {
1037
- s == null || s.removeEventListener("abort", h), u();
1041
+ }, p = setTimeout(() => {
1042
+ s == null || s.removeEventListener("abort", h), c();
1038
1043
  }, a);
1039
1044
  s == null || s.addEventListener("abort", h, { once: !0 });
1040
1045
  });
1041
1046
  }
1042
1047
  }
1043
- const Lr = 1200 * 1e3, Ze = /* @__PURE__ */ new Set([
1048
+ const Xr = 1200 * 1e3, tt = /* @__PURE__ */ new Set([
1044
1049
  R.PENDING_ACKS,
1045
1050
  R.PENDING_ACTIVATION,
1046
1051
  R.ACTIVATED_PENDING_BROADCAST,
1047
1052
  R.ACTIVATED
1048
- ]), Gr = /* @__PURE__ */ new Set([
1053
+ ]), qr = /* @__PURE__ */ new Set([
1049
1054
  R.PENDING_DEPOSITOR_SIGNATURES,
1050
- ...Ze
1055
+ ...tt
1051
1056
  ]);
1052
- function Xr(e) {
1057
+ function jr(e) {
1053
1058
  return e.map((t) => ({
1054
1059
  claimerPubkeyXOnly: j(t.claimer_pubkey),
1055
1060
  payoutTxHex: t.payout_tx.tx_hex,
@@ -1059,10 +1064,10 @@ function Xr(e) {
1059
1064
  function S(e) {
1060
1065
  return j(e).toLowerCase();
1061
1066
  }
1062
- function jr(e, t) {
1063
- const r = (u, c, h) => {
1067
+ function zr(e, t) {
1068
+ const r = (u, c, l) => {
1064
1069
  throw new Error(
1065
- `Deposit terms ${u} (${String(c)}) does not match the vault's version-locked signing context (${String(h)}); refusing to sign payouts against terms that describe a different graph.`
1070
+ `Deposit terms ${u} (${String(c)}) does not match the vault's version-locked signing context (${String(l)}); refusing to sign payouts against terms that describe a different graph.`
1066
1071
  );
1067
1072
  }, o = [
1068
1073
  ["protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate],
@@ -1070,17 +1075,17 @@ function jr(e, t) {
1070
1075
  ["timelockPegin", e.timelockPegin, t.timelockPegin],
1071
1076
  ["timelockAssert", e.timelockAssert, t.timelockAssert]
1072
1077
  ];
1073
- for (const [u, c, h] of o)
1074
- c !== h && r(u, c, h);
1075
- const n = (u) => u.map(S).sort(), a = (u, c) => {
1076
- const h = n(u), l = n(c);
1077
- return h.length === l.length && h.every((p, d) => p === l[d]);
1078
+ for (const [u, c, l] of o)
1079
+ c !== l && r(u, c, l);
1080
+ const n = (u) => u.map(S).sort(), i = (u, c) => {
1081
+ const l = n(u), h = n(c);
1082
+ return l.length === h.length && l.every((p, d) => p === h[d]);
1078
1083
  };
1079
- a(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
1084
+ i(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
1080
1085
  "vaultKeeperBtcPubkeys",
1081
1086
  e.vaultKeeperBtcPubkeys.join(","),
1082
1087
  t.vaultKeeperBtcPubkeys.join(",")
1083
- ), a(
1088
+ ), i(
1084
1089
  e.universalChallengerBtcPubkeys,
1085
1090
  t.universalChallengerBtcPubkeys
1086
1091
  ) || r(
@@ -1088,40 +1093,40 @@ function jr(e, t) {
1088
1093
  e.universalChallengerBtcPubkeys.join(","),
1089
1094
  t.universalChallengerBtcPubkeys.join(",")
1090
1095
  );
1091
- const s = S(t.vaultProviderBtcPubkey), i = e.vaults.map(
1096
+ const a = S(t.vaultProviderBtcPubkey), s = e.vaults.map(
1092
1097
  (u) => S(u.vaultProviderBtcPubkey)
1093
1098
  );
1094
- i.includes(s) || r(
1099
+ s.includes(a) || r(
1095
1100
  "vaults[].vaultProviderBtcPubkey",
1096
- i.join(",") || "<no vaults>",
1101
+ s.join(",") || "<no vaults>",
1097
1102
  t.vaultProviderBtcPubkey
1098
1103
  );
1099
1104
  }
1100
- function qr(e, t, r, o) {
1101
- const n = S(o), a = [
1105
+ function Wr(e, t, r, o) {
1106
+ const n = S(o), i = [
1102
1107
  S(t),
1103
1108
  ...r.map(S)
1104
- ], s = new Set(a);
1105
- if (s.size !== a.length)
1109
+ ], a = new Set(i);
1110
+ if (a.size !== i.length)
1106
1111
  throw new Error(
1107
1112
  "Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
1108
1113
  );
1109
- if (s.has(n))
1114
+ if (a.has(n))
1110
1115
  throw new Error(
1111
1116
  "Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
1112
1117
  );
1113
- const i = e.map(
1118
+ const s = e.map(
1114
1119
  (p) => S(p.claimer_pubkey)
1115
1120
  );
1116
- if (new Set(i).size !== i.length)
1121
+ if (new Set(s).size !== s.length)
1117
1122
  throw new Error("Presign response contains duplicate claimer entries");
1118
- const u = i.filter((p) => p !== n), c = new Set(u), h = a.filter((p) => !c.has(p)), l = u.filter((p) => !s.has(p));
1119
- if (h.length > 0 || l.length > 0)
1123
+ const u = s.filter((p) => p !== n), c = new Set(u), l = i.filter((p) => !c.has(p)), h = u.filter((p) => !a.has(p));
1124
+ if (l.length > 0 || h.length > 0)
1120
1125
  throw new Error(
1121
- "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (l.length > 0 ? ` (unexpected: ${l.join(", ")})` : "")
1126
+ "Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
1122
1127
  );
1123
1128
  }
1124
- function ke(e, t) {
1129
+ function Te(e, t) {
1125
1130
  return {
1126
1131
  vaultCoreVersion: t.vaultCoreVersion,
1127
1132
  payoutTxHex: e.payoutTxHex,
@@ -1143,96 +1148,98 @@ function ke(e, t) {
1143
1148
  vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
1144
1149
  };
1145
1150
  }
1146
- async function zr(e, t, r, o) {
1147
- const n = new pt({
1151
+ async function Yr(e, t, r, o) {
1152
+ const n = new gt({
1148
1153
  network: t.network,
1149
1154
  btcWallet: e
1150
- }), a = r.length;
1151
- o == null || o(0, a);
1152
- let s;
1155
+ }), i = r.length;
1156
+ o == null || o(0, i);
1157
+ let a;
1153
1158
  if (n.supportsBatchSigning())
1154
- s = (await n.signPayoutTransactionsBatch(
1155
- r.map((c) => ke(c, t))
1159
+ a = (await n.signPayoutTransactionsBatch(
1160
+ r.map((c) => Te(c, t))
1156
1161
  )).map((c) => c.payoutSignature);
1157
1162
  else {
1158
- s = [];
1163
+ a = [];
1159
1164
  for (let u = 0; u < r.length; u++) {
1160
- o == null || o(u, a);
1165
+ o == null || o(u, i);
1161
1166
  const c = await n.signPayoutTransaction(
1162
- ke(r[u], t)
1167
+ Te(r[u], t)
1163
1168
  );
1164
- s.push(c.signature);
1169
+ a.push(c.signature);
1165
1170
  }
1166
1171
  }
1167
- const i = {};
1172
+ const s = {};
1168
1173
  for (let u = 0; u < r.length; u++)
1169
- i[r[u].claimerPubkeyXOnly] = {
1170
- payout_signature: s[u]
1174
+ s[r[u].claimerPubkeyXOnly] = {
1175
+ payout_signature: a[u]
1171
1176
  };
1172
- return o == null || o(a, a), i;
1177
+ return o == null || o(i, i), s;
1173
1178
  }
1174
- async function Fo(e) {
1179
+ async function Uo(e) {
1175
1180
  const {
1176
1181
  statusReader: t,
1177
1182
  presignClient: r,
1178
1183
  btcWallet: o,
1179
- peginTxid: n,
1184
+ vaultId: n,
1185
+ peginTxid: i,
1180
1186
  depositorPk: a,
1181
1187
  signingContext: s,
1182
- depositTerms: i,
1183
- timeoutMs: u = Lr,
1184
- signal: c,
1188
+ depositTerms: u,
1189
+ timeoutMs: c = Xr,
1190
+ signal: l,
1185
1191
  onProgress: h,
1186
- recordGraphFingerprint: l
1187
- } = e, p = await Je({
1192
+ recordGraphFingerprint: p
1193
+ } = e, d = await et({
1188
1194
  statusReader: t,
1189
- peginTxid: n,
1190
- targetStatuses: Gr,
1191
- timeoutMs: u,
1192
- signal: c
1195
+ vaultId: n,
1196
+ peginTxid: i,
1197
+ targetStatuses: qr,
1198
+ timeoutMs: c,
1199
+ signal: l
1193
1200
  });
1194
- if (Ze.has(p))
1201
+ if (tt.has(d))
1195
1202
  return;
1196
- if (c == null || c.throwIfAborted(), i !== void 0 && jr(i, s), ht(o)) {
1197
- if (!i)
1203
+ if (l == null || l.throwIfAborted(), u !== void 0 && zr(u, s), dt(o)) {
1204
+ if (!u)
1198
1205
  throw new Error(
1199
1206
  "runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume flows must rebuild them from on-chain state (the vault app's rebuildDepositTerms)."
1200
1207
  );
1201
- typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(i), await o.approveDepositTerms(i);
1208
+ typeof o.validateDepositTerms == "function" && await o.validateDepositTerms(u), await o.approveDepositTerms(u);
1202
1209
  }
1203
- const d = await r.requestDepositorPresignTransactions(
1210
+ const g = await r.requestDepositorPresignTransactions(
1204
1211
  {
1205
- pegin_txid: n,
1212
+ pegin_txid: i,
1206
1213
  depositor_pk: a
1207
1214
  },
1208
- c
1215
+ l
1209
1216
  );
1210
- c == null || c.throwIfAborted();
1211
- const g = Rr({
1212
- peginTxid: n,
1217
+ l == null || l.throwIfAborted();
1218
+ const b = Vr({
1219
+ peginTxid: i,
1213
1220
  peginTxHex: s.peginTxHex,
1214
- claimTxHex: d.depositor_graph.claim_tx.tx_hex,
1215
- assertTxHex: d.depositor_graph.assert_tx.tx_hex,
1216
- payoutTxHex: d.depositor_graph.payout_tx.tx_hex,
1217
- challengers: d.depositor_graph.challenger_presign_data
1218
- }), b = S(a);
1219
- qr(
1220
- d.txs,
1221
+ claimTxHex: g.depositor_graph.claim_tx.tx_hex,
1222
+ assertTxHex: g.depositor_graph.assert_tx.tx_hex,
1223
+ payoutTxHex: g.depositor_graph.payout_tx.tx_hex,
1224
+ challengers: g.depositor_graph.challenger_presign_data
1225
+ }), y = S(a);
1226
+ Wr(
1227
+ g.txs,
1221
1228
  s.vaultProviderBtcPubkey,
1222
1229
  s.vaultKeeperBtcPubkeys,
1223
1230
  a
1224
1231
  );
1225
- const y = d.txs.filter(
1226
- (_) => S(_.claimer_pubkey) !== b
1227
- ), m = Xr(y), x = await zr(
1232
+ const m = g.txs.filter(
1233
+ ($) => S($.claimer_pubkey) !== y
1234
+ ), w = jr(m), x = await Yr(
1228
1235
  o,
1229
1236
  s,
1230
- m,
1237
+ w,
1231
1238
  h
1232
1239
  );
1233
- c == null || c.throwIfAborted();
1234
- const w = await Fr({
1235
- depositorGraph: d.depositor_graph,
1240
+ l == null || l.throwIfAborted();
1241
+ const k = await Ur({
1242
+ depositorGraph: g.depositor_graph,
1236
1243
  btcWallet: o,
1237
1244
  signingContext: {
1238
1245
  vaultCoreVersion: s.vaultCoreVersion,
@@ -1252,104 +1259,106 @@ async function Fo(e) {
1252
1259
  vpCommissionScriptPubKey: s.vpCommissionScriptPubKey
1253
1260
  }
1254
1261
  });
1255
- c == null || c.throwIfAborted(), await l(g), c == null || c.throwIfAborted();
1256
- const k = { ...x };
1257
- k[f(a)] = w.payout_signatures, await r.submitDepositorPresignatures(
1262
+ l == null || l.throwIfAborted(), await p(b), l == null || l.throwIfAborted();
1263
+ const _ = { ...x };
1264
+ _[f(a)] = k.payout_signatures, await r.submitDepositorPresignatures(
1258
1265
  {
1259
- pegin_txid: n,
1266
+ pegin_txid: i,
1260
1267
  depositor_pk: a,
1261
- signatures: k,
1262
- depositor_claimer_presignatures: w
1268
+ signatures: _,
1269
+ depositor_claimer_presignatures: k
1263
1270
  },
1264
- c
1271
+ l
1265
1272
  );
1266
1273
  }
1267
- const Wr = 300 * 1e3, Yr = /* @__PURE__ */ new Set([
1274
+ const Qr = 300 * 1e3, Jr = /* @__PURE__ */ new Set([
1268
1275
  R.PENDING_DEPOSITOR_WOTS_PK,
1269
- ...Ue
1276
+ ...Ge
1270
1277
  ]);
1271
- async function Uo(e) {
1278
+ async function Go(e) {
1272
1279
  const {
1273
1280
  statusReader: t,
1274
1281
  wotsSubmitter: r,
1275
- peginTxid: o,
1276
- depositorPk: n,
1282
+ vaultId: o,
1283
+ peginTxid: n,
1284
+ depositorPk: i,
1277
1285
  wotsPublicKeys: a,
1278
- timeoutMs: s = Wr,
1279
- signal: i
1286
+ timeoutMs: s = Qr,
1287
+ signal: u
1280
1288
  } = e;
1281
- i == null || i.throwIfAborted();
1282
- const u = await Je({
1289
+ u == null || u.throwIfAborted();
1290
+ const c = await et({
1283
1291
  statusReader: t,
1284
- peginTxid: o,
1285
- targetStatuses: Yr,
1292
+ vaultId: o,
1293
+ peginTxid: n,
1294
+ targetStatuses: Jr,
1286
1295
  timeoutMs: s,
1287
- signal: i
1296
+ signal: u
1288
1297
  });
1289
- Ue.has(u) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
1298
+ Ge.has(c) || (u == null || u.throwIfAborted(), await r.submitDepositorWotsKey(
1290
1299
  {
1291
- pegin_txid: o,
1292
- depositor_pk: n,
1300
+ pegin_txid: n,
1301
+ depositor_pk: i,
1293
1302
  wots_public_keys: a
1294
1303
  },
1295
- i
1304
+ u
1296
1305
  ));
1297
1306
  }
1298
- function Z(e) {
1307
+ function ee(e) {
1299
1308
  return e.registration || e.operation;
1300
1309
  }
1301
- function Qr(e, t, r) {
1302
- const o = $(e);
1310
+ function Zr(e, t, r) {
1311
+ const o = C(e);
1303
1312
  return {
1304
- registration: o === $(t),
1305
- operation: o === $(r)
1313
+ registration: o === C(t),
1314
+ operation: o === C(r)
1306
1315
  };
1307
1316
  }
1308
- function _e(e, t, r) {
1309
- const o = ee(e);
1317
+ function $e(e, t, r) {
1318
+ const o = te(e);
1310
1319
  return {
1311
- registration: Te(o, ee(t)),
1312
- operation: Te(o, ee(r))
1320
+ registration: Ce(o, te(t)),
1321
+ operation: Ce(o, te(r))
1313
1322
  };
1314
1323
  }
1315
- function ee(e) {
1316
- return e.map($).sort();
1324
+ function te(e) {
1325
+ return e.map(C).sort();
1317
1326
  }
1318
- function Te(e, t) {
1327
+ function Ce(e, t) {
1319
1328
  return e.length === t.length && e.every((r, o) => r === t[o]);
1320
1329
  }
1321
- async function Lo(e) {
1330
+ async function Xo(e) {
1322
1331
  const {
1323
1332
  vaultProviderEthAddress: t,
1324
1333
  hintBtcPubkey: r,
1325
1334
  registrationBtcPubkey: o,
1326
1335
  readCurrentOperationBtcPubkey: n,
1327
- context: a
1336
+ context: i
1328
1337
  } = e;
1329
1338
  if (!r) return;
1330
- const s = $(r);
1331
- if (s === $(o)) return;
1332
- const i = $(
1339
+ const a = C(r);
1340
+ if (a === C(o)) return;
1341
+ const s = C(
1333
1342
  await n()
1334
1343
  );
1335
- if (s !== i)
1344
+ if (a !== s)
1336
1345
  throw new Error(
1337
- `Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${a ? ` ${a}` : ""}`
1346
+ `Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${i ? ` ${i}` : ""}`
1338
1347
  );
1339
1348
  }
1340
- function te(e, t, r) {
1341
- const o = `${e} operation key (admin=${t.ethAddress})`, n = fe(
1349
+ function re(e, t, r) {
1350
+ const o = `${e} operation key (admin=${t.ethAddress})`, n = ye(
1342
1351
  t.btcPubKey,
1343
1352
  `${e} roster key (admin=${t.ethAddress})`
1344
- ), a = fe(r, o);
1353
+ ), i = ye(r, o);
1345
1354
  return {
1346
1355
  adminAddress: t.ethAddress,
1347
1356
  genesisBtcPubkey: n,
1348
- operationBtcPubkey: a,
1349
- rotated: a !== n
1357
+ operationBtcPubkey: i,
1358
+ rotated: i !== n
1350
1359
  };
1351
1360
  }
1352
- function Jr(e) {
1361
+ function eo(e) {
1353
1362
  const t = /* @__PURE__ */ new Map();
1354
1363
  for (const r of e) {
1355
1364
  const o = t.get(r.operationBtcPubkey);
@@ -1360,12 +1369,12 @@ function Jr(e) {
1360
1369
  t.set(r.operationBtcPubkey, r.adminAddress);
1361
1370
  }
1362
1371
  }
1363
- function et(e, t, r) {
1372
+ function rt(e, t, r) {
1364
1373
  if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
1365
1374
  throw new Error(
1366
1375
  `Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
1367
1376
  );
1368
- const o = te(
1377
+ const o = re(
1369
1378
  "vault provider",
1370
1379
  {
1371
1380
  ethAddress: e.vaultProviderEthAddress,
@@ -1373,64 +1382,64 @@ function et(e, t, r) {
1373
1382
  },
1374
1383
  t.vaultProvider
1375
1384
  ), n = e.vaultKeepers.map(
1376
- (s, i) => te("vault keeper", s, t.vaultKeepers[i])
1377
- ), a = e.universalChallengers.map(
1378
- (s, i) => te("universal challenger", s, t.universalChallengers[i])
1385
+ (a, s) => re("vault keeper", a, t.vaultKeepers[s])
1386
+ ), i = e.universalChallengers.map(
1387
+ (a, s) => re("universal challenger", a, t.universalChallengers[s])
1379
1388
  );
1380
- return Jr([
1389
+ return eo([
1381
1390
  o,
1382
1391
  ...n,
1383
- ...a
1392
+ ...i
1384
1393
  ]), {
1385
1394
  vaultProvider: o,
1386
1395
  vaultKeepers: n,
1387
- universalChallengers: a,
1396
+ universalChallengers: i,
1388
1397
  // Derived from the pairs, never the reverse — see ParticipantKeySet.
1389
- vaultKeeperOperationKeysSorted: n.map((s) => s.operationBtcPubkey).sort(),
1390
- universalChallengerOperationKeysSorted: a.map((s) => s.operationBtcPubkey).sort(),
1398
+ vaultKeeperOperationKeysSorted: n.map((a) => a.operationBtcPubkey).sort(),
1399
+ universalChallengerOperationKeysSorted: i.map((a) => a.operationBtcPubkey).sort(),
1391
1400
  resolvedAt: r,
1392
1401
  query: e
1393
1402
  };
1394
1403
  }
1395
- async function Zr(e) {
1404
+ async function to(e) {
1396
1405
  const t = await e.operationKeyReader.getCurrentOperationKeys(
1397
1406
  e.query,
1398
1407
  e.blockNumber
1399
1408
  );
1400
- return et(e.query, t, { mode: "current" });
1409
+ return rt(e.query, t, { mode: "current" });
1401
1410
  }
1402
- async function eo(e) {
1411
+ async function ro(e) {
1403
1412
  const t = await e.operationKeyReader.getOperationKeysAtEpochs(
1404
1413
  e.query,
1405
1414
  e.epochs
1406
1415
  );
1407
- return et(e.query, t, {
1416
+ return rt(e.query, t, {
1408
1417
  mode: "epochs",
1409
1418
  epochs: e.epochs
1410
1419
  });
1411
1420
  }
1412
- class oe extends Error {
1421
+ class ne extends Error {
1413
1422
  constructor(t) {
1414
1423
  super(t), this.name = "ApplicationEntryPointMismatchError";
1415
1424
  }
1416
1425
  }
1417
- function Go(e) {
1418
- return e instanceof oe || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
1426
+ function qo(e) {
1427
+ return e instanceof ne || e instanceof Error && e.name === "ApplicationEntryPointMismatchError";
1419
1428
  }
1420
- const $e = (e) => e.map($).sort();
1421
- async function Xo(e) {
1429
+ const Ae = (e) => e.map(C).sort();
1430
+ async function jo(e) {
1422
1431
  const {
1423
1432
  vaultRegistryReader: t,
1424
1433
  vaultKeeperReader: r,
1425
1434
  universalChallengerReader: o,
1426
1435
  vaultProviderEthAddress: n,
1427
- applicationEntryPoint: a,
1428
- expectedVaultProviderBtcPubkey: s,
1429
- expectedVaultKeeperBtcPubkeys: i,
1436
+ applicationEntryPoint: i,
1437
+ expectedVaultProviderBtcPubkey: a,
1438
+ expectedVaultKeeperBtcPubkeys: s,
1430
1439
  expectedUniversalChallengerBtcPubkeys: u,
1431
1440
  operationKeyReader: c,
1432
- onIndexerServingOperationKeys: h,
1433
- onIndexerHintsInconsistent: l,
1441
+ onIndexerServingOperationKeys: l,
1442
+ onIndexerHintsInconsistent: h,
1434
1443
  blockNumber: p
1435
1444
  } = e, [
1436
1445
  d,
@@ -1449,15 +1458,15 @@ async function Xo(e) {
1449
1458
  o.getLatestUniversalChallengersVersion(p),
1450
1459
  o.getCurrentUcKeyEpoch(p)
1451
1460
  ]);
1452
- if (!Bt(a, { strict: !1 }))
1453
- throw new oe(
1454
- `The application entry point this deposit was prepared for is not a valid address: ${a}`
1461
+ if (!Ot(i, { strict: !1 }))
1462
+ throw new ne(
1463
+ `The application entry point this deposit was prepared for is not a valid address: ${i}`
1455
1464
  );
1456
- if (!Vt(d, a))
1457
- throw new oe(
1458
- `Vault provider ${n} is registered to application ${d}, but this deposit was prepared for ${a}. Refusing to build: the vault keeper roster, its version, and the keeper key epoch would all resolve against a different application than the one selected.`
1465
+ if (!Nt(d, i))
1466
+ throw new ne(
1467
+ `Vault provider ${n} is registered to application ${d}, but this deposit was prepared for ${i}. Refusing to build: the vault keeper roster, its version, and the keeper key epoch would all resolve against a different application than the one selected.`
1459
1468
  );
1460
- const [m, x] = await Promise.all(
1469
+ const [m, w] = await Promise.all(
1461
1470
  [
1462
1471
  r.getCurrentVaultKeepersVersion(
1463
1472
  d,
@@ -1468,7 +1477,7 @@ async function Xo(e) {
1468
1477
  p
1469
1478
  )
1470
1479
  ]
1471
- ), [w, k] = await Promise.all([
1480
+ ), [x, k] = await Promise.all([
1472
1481
  r.getVaultKeepersByVersion(
1473
1482
  d,
1474
1483
  m,
@@ -1479,84 +1488,84 @@ async function Xo(e) {
1479
1488
  p
1480
1489
  )
1481
1490
  ]), _ = {
1482
- vaultProvider: $(g),
1483
- vaultKeepers: $e(w.map((T) => T.btcPubKey)),
1484
- universalChallengers: $e(k.map((T) => T.btcPubKey))
1485
- }, C = await Zr({
1491
+ vaultProvider: C(g),
1492
+ vaultKeepers: Ae(x.map((T) => T.btcPubKey)),
1493
+ universalChallengers: Ae(k.map((T) => T.btcPubKey))
1494
+ }, $ = await to({
1486
1495
  operationKeyReader: c,
1487
1496
  query: {
1488
1497
  vaultProviderEthAddress: n,
1489
1498
  vaultProviderGenesisBtcPubkey: `0x${g}`,
1490
1499
  applicationEntryPoint: d,
1491
- vaultKeepers: w,
1500
+ vaultKeepers: x,
1492
1501
  universalChallengers: k
1493
1502
  },
1494
1503
  blockNumber: p
1495
- }), P = {
1496
- vaultProvider: C.vaultProvider.operationBtcPubkey,
1497
- vaultKeepers: [...C.vaultKeeperOperationKeysSorted],
1504
+ }), v = {
1505
+ vaultProvider: $.vaultProvider.operationBtcPubkey,
1506
+ vaultKeepers: [...$.vaultKeeperOperationKeysSorted],
1498
1507
  universalChallengers: [
1499
- ...C.universalChallengerOperationKeysSorted
1508
+ ...$.universalChallengerOperationKeysSorted
1500
1509
  ]
1501
- }, se = Qr(
1502
- s,
1510
+ }, ae = Zr(
1511
+ a,
1503
1512
  _.vaultProvider,
1504
- P.vaultProvider
1505
- ), ae = _e(
1506
- i,
1513
+ v.vaultProvider
1514
+ ), ie = $e(
1515
+ s,
1507
1516
  _.vaultKeepers,
1508
- P.vaultKeepers
1509
- ), ie = _e(
1517
+ v.vaultKeepers
1518
+ ), ue = $e(
1510
1519
  u,
1511
1520
  _.universalChallengers,
1512
- P.universalChallengers
1521
+ v.universalChallengers
1513
1522
  );
1514
- if (!Z(se))
1523
+ if (!ee(ae))
1515
1524
  throw new Error(
1516
1525
  `Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${n}. Refresh and try again.`
1517
1526
  );
1518
- if (!Z(ae))
1527
+ if (!ee(ie))
1519
1528
  throw new Error(
1520
1529
  `Vault keeper BTC pubkeys (v${m}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
1521
1530
  );
1522
- if (!Z(ie))
1531
+ if (!ee(ue))
1523
1532
  throw new Error(
1524
1533
  `Universal challenger BTC pubkeys (v${b}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
1525
1534
  );
1526
- const ue = [se, ae, ie], st = ue.some((T) => T.registration && !T.operation), ce = ue.some((T) => T.operation && !T.registration);
1527
- if (st && ce) {
1535
+ const ce = [ae, ie, ue], it = ce.some((T) => T.registration && !T.operation), le = ce.some((T) => T.operation && !T.registration);
1536
+ if (it && le) {
1528
1537
  const T = `Indexer participant hints are internally inconsistent for vault provider ${n}: some roles match the registration keys while others match the rotated operation keys.`;
1529
- throw l == null || l(T), new Error(`${T} Refresh and try again.`);
1538
+ throw h == null || h(T), new Error(`${T} Refresh and try again.`);
1530
1539
  }
1531
- return ce && (h == null || h(
1540
+ return le && (l == null || l(
1532
1541
  `Indexer is serving rotated operation keys for vault provider ${n}`
1533
1542
  )), {
1534
- vaultProviderBtcPubkeyXOnly: P.vaultProvider,
1535
- vaultKeeperBtcPubkeysSorted: P.vaultKeepers,
1536
- universalChallengerBtcPubkeysSorted: P.universalChallengers,
1543
+ vaultProviderBtcPubkeyXOnly: v.vaultProvider,
1544
+ vaultKeeperBtcPubkeysSorted: v.vaultKeepers,
1545
+ universalChallengerBtcPubkeysSorted: v.universalChallengers,
1537
1546
  expectedAppVaultKeepersVersion: m,
1538
1547
  expectedUniversalChallengersVersion: b,
1539
- appKeeperKeyEpoch: x,
1548
+ appKeeperKeyEpoch: w,
1540
1549
  ucKeyEpoch: y,
1541
1550
  registrationKeys: _,
1542
- participantKeys: C
1551
+ participantKeys: $
1543
1552
  };
1544
1553
  }
1545
- function to(e) {
1554
+ function oo(e) {
1546
1555
  return /^[0-9a-fA-F]{64}$/.test(e);
1547
1556
  }
1548
- function jo(e) {
1557
+ function zo(e) {
1549
1558
  const {
1550
1559
  amountSats: t,
1551
1560
  minDeposit: r,
1552
1561
  maxDeposit: o,
1553
1562
  btcBalance: n,
1554
- estimatedFeeSats: a,
1555
- depositorClaimValue: s
1563
+ estimatedFeeSats: i,
1564
+ depositorClaimValue: a
1556
1565
  } = e;
1557
- return !(t <= 0n || t < r || o && o > 0n && t > o || a == null || s == null || t + a + s > n);
1566
+ return !(t <= 0n || t < r || o && o > 0n && t > o || i == null || a == null || t + i + a > n);
1558
1567
  }
1559
- function qo(e, t, r) {
1568
+ function Wo(e, t, r) {
1560
1569
  return e <= 0n ? {
1561
1570
  valid: !1,
1562
1571
  error: "Deposit amount must be greater than zero"
@@ -1568,7 +1577,7 @@ function qo(e, t, r) {
1568
1577
  error: `Maximum deposit is ${V(r)} BTC`
1569
1578
  } : { valid: !0 };
1570
1579
  }
1571
- function zo(e) {
1580
+ function Yo(e) {
1572
1581
  const { amount: t, effectiveRemaining: r } = e;
1573
1582
  return r === null ? { valid: !0 } : r === 0n ? {
1574
1583
  valid: !1,
@@ -1578,7 +1587,7 @@ function zo(e) {
1578
1587
  error: `Vault size exceeds remaining capacity (${V(r)} BTC)`
1579
1588
  } : { valid: !0 };
1580
1589
  }
1581
- function Wo(e, t) {
1590
+ function Qo(e, t) {
1582
1591
  if (!e || e.length === 0)
1583
1592
  return {
1584
1593
  valid: !1,
@@ -1594,7 +1603,7 @@ function Wo(e, t) {
1594
1603
  error: "Invalid vault provider selected"
1595
1604
  } : { valid: !0 };
1596
1605
  }
1597
- function ro(e, t, r) {
1606
+ function no(e, t, r) {
1598
1607
  if (!e || e.length === 0)
1599
1608
  return {
1600
1609
  valid: !1,
@@ -1620,167 +1629,167 @@ function ro(e, t, r) {
1620
1629
  }
1621
1630
  return { valid: !0 };
1622
1631
  }
1623
- function oo(e) {
1632
+ function so(e) {
1624
1633
  const t = f(e);
1625
- return to(t) ? { valid: !0 } : {
1634
+ return oo(t) ? { valid: !0 } : {
1626
1635
  valid: !1,
1627
1636
  error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
1628
1637
  };
1629
1638
  }
1630
- function no(e) {
1639
+ function ao(e) {
1631
1640
  if (!e || e.length === 0)
1632
1641
  throw new Error(
1633
1642
  "No vault keepers available. The system requires at least one vault keeper to create a deposit."
1634
1643
  );
1635
1644
  }
1636
- function so(e) {
1645
+ function io(e) {
1637
1646
  if (!e || e.length === 0)
1638
1647
  throw new Error(
1639
1648
  "No universal challengers available. The system requires at least one universal challenger to create a deposit."
1640
1649
  );
1641
1650
  }
1642
- function ao(e) {
1651
+ function uo(e) {
1643
1652
  if (e.length === 0)
1644
1653
  throw new Error("No spendable UTXOs available");
1645
1654
  }
1646
- function Yo(e) {
1655
+ function Jo(e) {
1647
1656
  const {
1648
1657
  vaultAmounts: t,
1649
1658
  confirmedUTXOs: r,
1650
1659
  vaultProviderBtcPubkey: o,
1651
1660
  vaultKeeperBtcPubkeys: n,
1652
- universalChallengerBtcPubkeys: a,
1653
- minDeposit: s,
1654
- maxDeposit: i
1655
- } = e, u = ro(
1661
+ universalChallengerBtcPubkeys: i,
1662
+ minDeposit: a,
1663
+ maxDeposit: s
1664
+ } = e, u = no(
1656
1665
  t,
1657
- s,
1658
- i
1666
+ a,
1667
+ s
1659
1668
  );
1660
1669
  if (!u.valid)
1661
1670
  throw new Error(u.error);
1662
- const c = oo(o);
1671
+ const c = so(o);
1663
1672
  if (!c.valid)
1664
1673
  throw new Error(c.error);
1665
- no(n), so(a), ao(r);
1674
+ ao(n), io(i), uo(r);
1666
1675
  }
1667
- class tt extends Error {
1676
+ class ot extends Error {
1668
1677
  constructor(t) {
1669
1678
  super(t), this.name = "ParticipantKeyDriftError";
1670
1679
  }
1671
1680
  }
1672
- function Qo(e) {
1673
- return e instanceof tt || e instanceof Error && e.name === "ParticipantKeyDriftError";
1681
+ function Zo(e) {
1682
+ return e instanceof ot || e instanceof Error && e.name === "ParticipantKeyDriftError";
1674
1683
  }
1675
- function Ce(e, t, r) {
1684
+ function Se(e, t, r) {
1676
1685
  return t.length === r.length && t.every((o, n) => o === r[n]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
1677
1686
  }
1678
- async function Jo(e) {
1679
- const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: n } = e, a = n.query;
1687
+ async function en(e) {
1688
+ const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: n } = e, i = n.query;
1680
1689
  if (o.length === 0) return;
1681
- const s = await t.getVaultKeyEpochsBatch(o), i = [];
1682
- for (const [u, c] of s.entries()) {
1683
- const h = o[u];
1684
- let l;
1690
+ const a = await t.getVaultKeyEpochsBatch(o), s = [];
1691
+ for (const [u, c] of a.entries()) {
1692
+ const l = o[u];
1693
+ let h;
1685
1694
  try {
1686
- l = await eo({
1695
+ h = await ro({
1687
1696
  operationKeyReader: r,
1688
- query: a,
1697
+ query: i,
1689
1698
  epochs: c
1690
1699
  });
1691
1700
  } catch (g) {
1692
- i.push(
1693
- `vault ${h}: could not resolve participants at frozen epochs (vp=${c.vpKeyEpoch}, keeper=${c.appKeeperKeyEpoch}, uc=${c.ucKeyEpoch}): ${g.message}`
1701
+ s.push(
1702
+ `vault ${l}: could not resolve participants at frozen epochs (vp=${c.vpKeyEpoch}, keeper=${c.appKeeperKeyEpoch}, uc=${c.ucKeyEpoch}): ${g.message}`
1694
1703
  );
1695
1704
  continue;
1696
1705
  }
1697
- l.vaultProvider.operationBtcPubkey !== n.vaultProvider.operationBtcPubkey && i.push(
1698
- `vault ${h}: vault provider key expected ${n.vaultProvider.operationBtcPubkey}, got ${l.vaultProvider.operationBtcPubkey}`
1706
+ h.vaultProvider.operationBtcPubkey !== n.vaultProvider.operationBtcPubkey && s.push(
1707
+ `vault ${l}: vault provider key expected ${n.vaultProvider.operationBtcPubkey}, got ${h.vaultProvider.operationBtcPubkey}`
1699
1708
  );
1700
- const p = Ce(
1701
- `vault ${h}: vault keeper keys`,
1709
+ const p = Se(
1710
+ `vault ${l}: vault keeper keys`,
1702
1711
  n.vaultKeeperOperationKeysSorted,
1703
- l.vaultKeeperOperationKeysSorted
1712
+ h.vaultKeeperOperationKeysSorted
1704
1713
  );
1705
- p && i.push(p);
1706
- const d = Ce(
1707
- `vault ${h}: universal challenger keys`,
1714
+ p && s.push(p);
1715
+ const d = Se(
1716
+ `vault ${l}: universal challenger keys`,
1708
1717
  n.universalChallengerOperationKeysSorted,
1709
- l.universalChallengerOperationKeysSorted
1718
+ h.universalChallengerOperationKeysSorted
1710
1719
  );
1711
- d && i.push(d);
1720
+ d && s.push(d);
1712
1721
  }
1713
- if (i.length > 0)
1714
- throw new tt(
1715
- `Aborting BTC broadcast: participant operation keys changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1722
+ if (s.length > 0)
1723
+ throw new ot(
1724
+ `Aborting BTC broadcast: participant operation keys changed during registration (${s.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1716
1725
  );
1717
1726
  }
1718
- class rt extends Error {
1727
+ class nt extends Error {
1719
1728
  constructor(t) {
1720
1729
  super(t), this.name = "RegisteredVaultVersionMismatchError";
1721
1730
  }
1722
1731
  }
1723
- function Zo(e) {
1724
- return e instanceof rt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1732
+ function tn(e) {
1733
+ return e instanceof nt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1725
1734
  }
1726
- async function en(e) {
1735
+ async function rn(e) {
1727
1736
  const {
1728
1737
  vaultRegistryReader: t,
1729
1738
  vaultIds: r,
1730
1739
  expectedOffchainParamsVersion: o,
1731
1740
  expectedAppVaultKeepersVersion: n,
1732
- expectedUniversalChallengersVersion: a,
1733
- expectedVaultCoreVersion: s
1734
- } = e, i = await t.getProtocolInfoBatch(r), u = [];
1735
- if (i.forEach((c, h) => {
1736
- const l = r[h];
1741
+ expectedUniversalChallengersVersion: i,
1742
+ expectedVaultCoreVersion: a
1743
+ } = e, s = await t.getProtocolInfoBatch(r), u = [];
1744
+ if (s.forEach((c, l) => {
1745
+ const h = r[l];
1737
1746
  c.offchainParamsVersion !== o && u.push(
1738
- `vault ${l}: offchainParams expected v${o}, got v${c.offchainParamsVersion}`
1747
+ `vault ${h}: offchainParams expected v${o}, got v${c.offchainParamsVersion}`
1739
1748
  ), c.appVaultKeepersVersion !== n && u.push(
1740
- `vault ${l}: appVaultKeepers expected v${n}, got v${c.appVaultKeepersVersion}`
1741
- ), c.universalChallengersVersion !== a && u.push(
1742
- `vault ${l}: universalChallengers expected v${a}, got v${c.universalChallengersVersion}`
1743
- ), c.vaultCoreVersion !== s && u.push(
1744
- `vault ${l}: vaultCoreVersion expected v${s} (build-time active), got v${c.vaultCoreVersion}`
1749
+ `vault ${h}: appVaultKeepers expected v${n}, got v${c.appVaultKeepersVersion}`
1750
+ ), c.universalChallengersVersion !== i && u.push(
1751
+ `vault ${h}: universalChallengers expected v${i}, got v${c.universalChallengersVersion}`
1752
+ ), c.vaultCoreVersion !== a && u.push(
1753
+ `vault ${h}: vaultCoreVersion expected v${a} (build-time active), got v${c.vaultCoreVersion}`
1745
1754
  );
1746
1755
  }), u.length > 0)
1747
- throw new rt(
1756
+ throw new nt(
1748
1757
  `Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${u.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
1749
1758
  );
1750
1759
  }
1751
- class io extends Error {
1760
+ class co extends Error {
1752
1761
  constructor(r, o) {
1753
1762
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
1754
- O(this, "vaultId");
1755
- O(this, "cause");
1763
+ N(this, "vaultId");
1764
+ N(this, "cause");
1756
1765
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
1757
1766
  }
1758
1767
  }
1759
- const uo = /^0x[0-9a-fA-F]{64}$/, co = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, ot = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, nt = 160, Ae = 2e3, Se = 10n, Ie = 100n;
1760
- function tn(e) {
1768
+ const lo = /^0x[0-9a-fA-F]{64}$/, ho = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, st = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, at = 160, Ie = 2e3, Re = 10n, Be = 100n;
1769
+ function on(e) {
1761
1770
  if (!Number.isFinite(e) || e <= 0)
1762
1771
  throw new Error(
1763
1772
  `feeRateSatsVb must be a positive finite number, got ${e}`
1764
1773
  );
1765
- return BigInt(Math.ceil(e * nt));
1774
+ return BigInt(Math.ceil(e * at));
1766
1775
  }
1767
- const lo = 1, ho = /non-BIP68-final/i;
1768
- function ne(e, t) {
1776
+ const po = 1, go = /non-BIP68-final/i;
1777
+ function se(e, t) {
1769
1778
  if (e.length !== 66)
1770
1779
  throw new Error(
1771
1780
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
1772
1781
  );
1773
- if (!uo.test(e))
1782
+ if (!lo.test(e))
1774
1783
  throw new Error(
1775
1784
  `${t} must contain only hex characters after the 0x prefix`
1776
1785
  );
1777
1786
  }
1778
- function re(e, t) {
1787
+ function oe(e, t) {
1779
1788
  if (!Number.isInteger(e) || e < 0)
1780
1789
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
1781
1790
  }
1782
- function po(e) {
1783
- if (ne(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1791
+ function fo(e) {
1792
+ if (se(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1784
1793
  throw new Error(
1785
1794
  `htlcVout must be a non-negative integer, got ${e.htlcVout}`
1786
1795
  );
@@ -1792,7 +1801,7 @@ function po(e) {
1792
1801
  );
1793
1802
  for (let r = 0; r < e.batch.length; r++) {
1794
1803
  const o = e.batch[r];
1795
- if (ne(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1804
+ if (se(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
1796
1805
  throw new Error(
1797
1806
  `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
1798
1807
  );
@@ -1810,27 +1819,27 @@ function po(e) {
1810
1819
  throw new Error(
1811
1820
  `batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
1812
1821
  );
1813
- if (re(e.offchainParamsVersion, "offchainParamsVersion"), re(e.appVaultKeepersVersion, "appVaultKeepersVersion"), re(
1822
+ if (oe(e.offchainParamsVersion, "offchainParamsVersion"), oe(e.appVaultKeepersVersion, "appVaultKeepersVersion"), oe(
1814
1823
  e.universalChallengersVersion,
1815
1824
  "universalChallengersVersion"
1816
- ), jt(
1825
+ ), zt(
1817
1826
  e.vaultCoreVersion,
1818
1827
  "VaultRefundData.vaultCoreVersion"
1819
1828
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
1820
1829
  throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
1821
- if (!co.test(e.unsignedPrePeginTxHex))
1830
+ if (!ho.test(e.unsignedPrePeginTxHex))
1822
1831
  throw new Error(
1823
1832
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
1824
1833
  );
1825
- if (!e.depositorBtcPubkey || !ot.test(e.depositorBtcPubkey))
1834
+ if (!e.depositorBtcPubkey || !st.test(e.depositorBtcPubkey))
1826
1835
  throw new Error(
1827
1836
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
1828
1837
  );
1829
1838
  if (typeof e.amount != "bigint" || e.amount <= 0n)
1830
1839
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
1831
1840
  }
1832
- function go(e) {
1833
- if (!e.vaultProviderPubkey || !ot.test(e.vaultProviderPubkey))
1841
+ function yo(e) {
1842
+ if (!e.vaultProviderPubkey || !st.test(e.vaultProviderPubkey))
1834
1843
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
1835
1844
  if (e.vaultKeeperPubkeys.length === 0)
1836
1845
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -1855,35 +1864,35 @@ function go(e) {
1855
1864
  `councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
1856
1865
  );
1857
1866
  }
1858
- async function rn(e) {
1867
+ async function nn(e) {
1859
1868
  const {
1860
1869
  vaultId: t,
1861
1870
  readVault: r,
1862
1871
  readPrePeginContext: o,
1863
1872
  feeRate: n,
1864
- signPsbt: a,
1865
- broadcastTx: s,
1866
- signal: i
1873
+ signPsbt: i,
1874
+ broadcastTx: a,
1875
+ signal: s
1867
1876
  } = e;
1868
- i == null || i.throwIfAborted(), ne(t, "vaultId");
1877
+ s == null || s.throwIfAborted(), se(t, "vaultId");
1869
1878
  const u = await r();
1870
- po(u), i == null || i.throwIfAborted();
1879
+ fo(u), s == null || s.throwIfAborted();
1871
1880
  const c = await o(u);
1872
- if (go(c), i == null || i.throwIfAborted(), !Number.isFinite(n) || n <= 0)
1881
+ if (yo(c), s == null || s.throwIfAborted(), !Number.isFinite(n) || n <= 0)
1873
1882
  throw new Error(`feeRate must be a positive number, got ${n}`);
1874
- if (n > Ae)
1883
+ if (n > Ie)
1875
1884
  throw new Error(
1876
- `feeRate ${n} sat/vB exceeds refund safety cap ${Ae} sat/vB; refusing to sign refund.`
1885
+ `feeRate ${n} sat/vB exceeds refund safety cap ${Ie} sat/vB; refusing to sign refund.`
1877
1886
  );
1878
- const h = BigInt(Math.ceil(n * nt)), l = u.amount * Se / Ie;
1879
- if (h > l)
1887
+ const l = BigInt(Math.ceil(n * at)), h = u.amount * Re / Be;
1888
+ if (l > h)
1880
1889
  throw new Error(
1881
- `Refund fee ${h} sats exceeds the per-vault safety cap of ${l} sats (${Se}/${Ie} of vault.amount=${u.amount}); refusing to sign refund.`
1890
+ `Refund fee ${l} sats exceeds the per-vault safety cap of ${h} sats (${Re}/${Be} of vault.amount=${u.amount}); refusing to sign refund.`
1882
1891
  );
1883
- i == null || i.throwIfAborted();
1892
+ s == null || s.throwIfAborted();
1884
1893
  const p = j(
1885
1894
  u.depositorBtcPubkey
1886
- ), d = f(u.unsignedPrePeginTxHex), g = dt(d);
1895
+ ), d = f(u.unsignedPrePeginTxHex), g = ft(d);
1887
1896
  if (g !== void 0 && g.vout !== u.batch.length)
1888
1897
  throw new Error(
1889
1898
  `Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${u.batch.length} HTLC outputs expect the anchor at vout ${u.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
@@ -1892,23 +1901,23 @@ async function rn(e) {
1892
1901
  let y;
1893
1902
  try {
1894
1903
  y = B.fromHex(d);
1895
- } catch (P) {
1904
+ } catch (v) {
1896
1905
  throw new Error(
1897
- `Failed to parse funded Pre-PegIn transaction hex: ${P instanceof Error ? P.message : String(P)}`
1906
+ `Failed to parse funded Pre-PegIn transaction hex: ${v instanceof Error ? v.message : String(v)}`
1898
1907
  );
1899
1908
  }
1900
1909
  if (y.outs.length < u.batch.length)
1901
1910
  throw new Error(
1902
1911
  `Funded Pre-PegIn tx has ${y.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
1903
1912
  );
1904
- const { psbtHex: m } = await Lt({
1913
+ const { psbtHex: m } = await Xt({
1905
1914
  prePeginParams: {
1906
1915
  vaultCoreVersion: u.vaultCoreVersion,
1907
1916
  depositorPubkey: p,
1908
1917
  vaultProviderPubkey: f(c.vaultProviderPubkey),
1909
1918
  vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(f),
1910
1919
  universalChallengerPubkeys: c.universalChallengerPubkeys.map(f),
1911
- hashlocks: u.batch.map((P) => f(P.hashlock)),
1920
+ hashlocks: u.batch.map((v) => f(v.hashlock)),
1912
1921
  timelockRefund: c.timelockRefund,
1913
1922
  // `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
1914
1923
  // is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
@@ -1916,7 +1925,7 @@ async function rn(e) {
1916
1925
  // HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
1917
1926
  // to the funded tx bytes, refusing the refund if the template's HTLC value
1918
1927
  // disagrees with the on-chain commitment.
1919
- pegInAmounts: u.batch.map((P) => P.amount),
1928
+ pegInAmounts: u.batch.map((v) => v.amount),
1920
1929
  feeRate: c.feeRate,
1921
1930
  minPeginFeeRate: c.minPeginFeeRate,
1922
1931
  numLocalChallengers: c.numLocalChallengers,
@@ -1927,88 +1936,88 @@ async function rn(e) {
1927
1936
  },
1928
1937
  fundedPrePeginTxHex: d,
1929
1938
  htlcVout: u.htlcVout,
1930
- refundFee: h,
1939
+ refundFee: l,
1931
1940
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
1932
1941
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
1933
1942
  // value would derive the wrong refund script leaf and yield an
1934
1943
  // unspendable PSBT. Match the `hashlocks` array handling above.
1935
1944
  hashlock: f(u.hashlock)
1936
1945
  });
1937
- i == null || i.throwIfAborted();
1938
- const x = M(
1946
+ s == null || s.throwIfAborted();
1947
+ const w = F(
1939
1948
  u.depositorBtcPubkey,
1940
- lo
1941
- ), w = await a(m, x);
1942
- F({
1949
+ po
1950
+ ), x = await i(m, w);
1951
+ L({
1943
1952
  requestedPsbtHex: m,
1944
- returnedPsbtHex: w
1953
+ returnedPsbtHex: x
1945
1954
  });
1946
1955
  const k = 0, _ = U(
1947
- w,
1956
+ x,
1948
1957
  p,
1949
1958
  k
1950
1959
  );
1951
- L({
1960
+ G({
1952
1961
  requestedPsbtHex: m,
1953
1962
  signatureHex: _,
1954
1963
  signerXOnlyPubkeyHex: p,
1955
1964
  inputIndex: k
1956
1965
  });
1957
- const C = Le({
1966
+ const $ = Xe({
1958
1967
  requestedPsbtHex: m,
1959
1968
  signaturesHex: [_],
1960
1969
  signerXOnlyPubkeyHex: p
1961
1970
  });
1962
- i == null || i.throwIfAborted();
1971
+ s == null || s.throwIfAborted();
1963
1972
  try {
1964
- return await s(C);
1965
- } catch (P) {
1966
- throw P instanceof Error && ho.test(P.message) ? new io(t, P) : P;
1973
+ return await a($);
1974
+ } catch (v) {
1975
+ throw v instanceof Error && go.test(v.message) ? new co(t, v) : v;
1967
1976
  }
1968
1977
  }
1969
- class Re extends Error {
1978
+ class Ve extends Error {
1970
1979
  constructor(r, o, n) {
1971
1980
  super(r);
1972
1981
  /** Fee the reclaim would have paid, in satoshis. */
1973
- O(this, "feeSats");
1982
+ N(this, "feeSats");
1974
1983
  /** Sum of the reserves the reclaim would have swept, in satoshis. */
1975
- O(this, "sweptTotalSats");
1984
+ N(this, "sweptTotalSats");
1976
1985
  this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = n;
1977
1986
  }
1978
1987
  }
1979
- const Be = 2e3, Ve = 25n, Oe = 100n, on = 10n;
1980
- async function fo(e, t, r) {
1988
+ const Oe = 2e3, Ne = 25n, He = 100n, sn = 10n;
1989
+ async function bo(e, t, r) {
1981
1990
  for (let o = 0; o < e.length; o++) {
1982
- const n = ft(e[o].depositorSignedPeginTxHex), a = He(
1983
- await Ct(
1991
+ const n = bt(e[o].depositorSignedPeginTxHex), i = De(
1992
+ await St(
1984
1993
  f(n),
1985
1994
  f(r)
1986
1995
  )
1987
1996
  ).toLowerCase();
1988
- if (a !== t[o].toLowerCase())
1997
+ if (i !== t[o].toLowerCase())
1989
1998
  throw new Error(
1990
- `Reserve ${o} belongs to vault ${a}, not the requested ${t[o].toLowerCase()}. Refusing to sweep a reserve whose vault is not the one the caller asked for — the reserve funds that vault's claim transaction and cannot be replaced.`
1999
+ `Reserve ${o} belongs to vault ${i}, not the requested ${t[o].toLowerCase()}. Refusing to sweep a reserve whose vault is not the one the caller asked for — the reserve funds that vault's claim transaction and cannot be replaced.`
1991
2000
  );
1992
2001
  }
1993
2002
  }
1994
- async function nn(e) {
2003
+ async function an(e) {
1995
2004
  const {
1996
2005
  vaultIds: t,
1997
2006
  depositorEthAddress: r,
1998
2007
  depositorBtcPubkey: o,
1999
2008
  readVaults: n,
2000
- feeRate: a,
2001
- signPsbt: s,
2002
- broadcastTx: i,
2009
+ feeRate: i,
2010
+ signPsbt: a,
2011
+ broadcastTx: s,
2003
2012
  signal: u
2004
2013
  } = e;
2005
2014
  if (u == null || u.throwIfAborted(), t.length === 0)
2006
2015
  throw new Error("Reclaim requires at least one vault id; got none.");
2007
- if (!Number.isFinite(a) || a <= 0)
2008
- throw new Error(`feeRate must be a positive number, got ${a}`);
2009
- if (a > Be)
2010
- throw new Re(
2011
- `Fee rate ${a} sat/vB exceeds the reclaim safety cap of ${Be} sat/vB; refusing to sign.`,
2016
+ if (!Number.isFinite(i) || i <= 0)
2017
+ throw new Error(`feeRate must be a positive number, got ${i}`);
2018
+ if (i > Oe)
2019
+ throw new Ve(
2020
+ `Fee rate ${i} sat/vB exceeds the reclaim safety cap of ${Oe} sat/vB; refusing to sign.`,
2012
2021
  0n,
2013
2022
  0n
2014
2023
  );
@@ -2017,114 +2026,114 @@ async function nn(e) {
2017
2026
  throw new Error(
2018
2027
  `readVaults returned ${c.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
2019
2028
  );
2020
- await fo(c, t, r), u == null || u.throwIfAborted();
2021
- const h = j(o), l = c.map((k) => ({
2029
+ await bo(c, t, r), u == null || u.throwIfAborted();
2030
+ const l = j(o), h = c.map((k) => ({
2022
2031
  depositorSignedPeginTxHex: k.depositorSignedPeginTxHex,
2023
2032
  observed: k.observed,
2024
2033
  expectedValue: k.expectedClaimValue
2025
- })), p = Gt(a, l.length), d = l.reduce((k, _) => k + _.expectedValue, 0n), g = d * Ve / Oe;
2034
+ })), p = qt(i, h.length), d = h.reduce((k, _) => k + _.expectedValue, 0n), g = d * Ne / He;
2026
2035
  if (p > g)
2027
- throw new Re(
2028
- `Reclaim fee ${p} sats exceeds ${Ve}/${Oe} of the swept total (${d} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
2036
+ throw new Ve(
2037
+ `Reclaim fee ${p} sats exceeds ${Ne}/${He} of the swept total (${d} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
2029
2038
  p,
2030
2039
  d
2031
2040
  );
2032
2041
  u == null || u.throwIfAborted();
2033
- const { psbtHex: b } = Xt({
2034
- depositorPubkey: h,
2035
- inputs: l,
2042
+ const { psbtHex: b } = jt({
2043
+ depositorPubkey: l,
2044
+ inputs: h,
2036
2045
  feeSats: p
2037
2046
  });
2038
2047
  u == null || u.throwIfAborted();
2039
- const y = M(
2048
+ const y = F(
2040
2049
  o,
2041
- l.length
2042
- ), m = await s(b, y);
2043
- F({
2050
+ h.length
2051
+ ), m = await a(b, y);
2052
+ L({
2044
2053
  requestedPsbtHex: b,
2045
2054
  returnedPsbtHex: m
2046
2055
  });
2047
- const x = l.map((k, _) => {
2048
- const C = U(
2056
+ const w = h.map((k, _) => {
2057
+ const $ = U(
2049
2058
  m,
2050
- h,
2059
+ l,
2051
2060
  _
2052
2061
  );
2053
- return L({
2062
+ return G({
2054
2063
  requestedPsbtHex: b,
2055
- signatureHex: C,
2056
- signerXOnlyPubkeyHex: h,
2064
+ signatureHex: $,
2065
+ signerXOnlyPubkeyHex: l,
2057
2066
  inputIndex: _
2058
- }), C;
2059
- }), w = Le({
2067
+ }), $;
2068
+ }), x = Xe({
2060
2069
  requestedPsbtHex: b,
2061
- signaturesHex: x,
2062
- signerXOnlyPubkeyHex: h
2070
+ signaturesHex: w,
2071
+ signerXOnlyPubkeyHex: l
2063
2072
  });
2064
- return u == null || u.throwIfAborted(), i(w);
2073
+ return u == null || u.throwIfAborted(), s(x);
2065
2074
  }
2066
2075
  export {
2067
- Se as $,
2068
- br as A,
2069
- Wo as B,
2070
- Jt as C,
2071
- yr as D,
2072
- zo as E,
2073
- ro as F,
2074
- v as G,
2075
- oo as H,
2076
- tt as I,
2077
- Qo as J,
2078
- Jo as K,
2079
- Zo as L,
2080
- en as M,
2081
- Je as N,
2082
- Lo as O,
2083
- er as P,
2084
- Z as Q,
2085
- rt as R,
2086
- Qr as S,
2087
- _e as T,
2088
- Zr as U,
2089
- or as V,
2090
- eo as W,
2091
- io as X,
2092
- rn as Y,
2093
- tn as Z,
2094
- Ie as _,
2095
- Bo as a,
2096
- Ae as a0,
2097
- nt as a1,
2098
- Re as a2,
2099
- nn as a3,
2100
- Oe as a4,
2101
- Ve as a5,
2102
- Be as a6,
2103
- on as a7,
2104
- Vo as b,
2105
- Oo as c,
2106
- No as d,
2107
- Ho as e,
2108
- Zt as f,
2109
- tr as g,
2110
- qe as h,
2111
- wr as i,
2112
- We as j,
2113
- Ye as k,
2114
- _r as l,
2115
- Ko as m,
2116
- Mo as n,
2117
- Br as o,
2118
- Fr as p,
2119
- Uo as q,
2120
- Fo as r,
2121
- mr as s,
2122
- oe as t,
2123
- Go as u,
2124
- Xo as v,
2125
- Do as w,
2126
- jo as x,
2127
- qo as y,
2128
- Yo as z
2076
+ Re as $,
2077
+ vr as A,
2078
+ Qo as B,
2079
+ er as C,
2080
+ mr as D,
2081
+ Yo as E,
2082
+ no as F,
2083
+ P as G,
2084
+ so as H,
2085
+ ot as I,
2086
+ Zo as J,
2087
+ en as K,
2088
+ tn as L,
2089
+ rn as M,
2090
+ et as N,
2091
+ Xo as O,
2092
+ rr as P,
2093
+ ee as Q,
2094
+ nt as R,
2095
+ Zr as S,
2096
+ $e as T,
2097
+ to as U,
2098
+ sr as V,
2099
+ ro as W,
2100
+ co as X,
2101
+ nn as Y,
2102
+ on as Z,
2103
+ Be as _,
2104
+ Oo as a,
2105
+ Ie as a0,
2106
+ at as a1,
2107
+ Ve as a2,
2108
+ an as a3,
2109
+ He as a4,
2110
+ Ne as a5,
2111
+ Oe as a6,
2112
+ sn as a7,
2113
+ No as b,
2114
+ Ho as c,
2115
+ Ko as d,
2116
+ Do as e,
2117
+ tr as f,
2118
+ or as g,
2119
+ We as h,
2120
+ Er as i,
2121
+ Qe as j,
2122
+ Je as k,
2123
+ $r as l,
2124
+ Mo as m,
2125
+ Lo as n,
2126
+ Or as o,
2127
+ Ur as p,
2128
+ Go as q,
2129
+ Uo as r,
2130
+ Pr as s,
2131
+ ne as t,
2132
+ qo as u,
2133
+ jo as v,
2134
+ Fo as w,
2135
+ zo as x,
2136
+ Wo as y,
2137
+ Jo as z
2129
2138
  };
2130
- //# sourceMappingURL=buildAndBroadcastReclaim-T5ZFPUpM.js.map
2139
+ //# sourceMappingURL=buildAndBroadcastReclaim-C55KaRJF.js.map