@babylonlabs-io/ts-sdk 2.0.2 → 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 (113) hide show
  1. package/dist/{PeginManager-CKf7Bjmj.js → PeginManager-D8WGB8eN.js} +2 -2
  2. package/dist/PeginManager-D8WGB8eN.js.map +1 -0
  3. package/dist/{PeginManager-Dt2Z5ljw.cjs → PeginManager-IgDHy_eU.cjs} +2 -2
  4. package/dist/PeginManager-IgDHy_eU.cjs.map +1 -0
  5. package/dist/{buildAndBroadcastReclaim-B19cyK69.js → buildAndBroadcastReclaim-C55KaRJF.js} +783 -791
  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/{json-rpc-client-CQLbpuKK.js → state-CFn1rT74.js} +136 -88
  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 -13
  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 +216 -215
  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 +75 -74
  81. package/dist/tbv/core/services/index.js.map +1 -1
  82. package/dist/tbv/core/services/pegout/state.d.ts +10 -5
  83. package/dist/tbv/core/services/pegout/state.d.ts.map +1 -1
  84. package/dist/tbv/index.cjs +1 -1
  85. package/dist/tbv/index.js +216 -215
  86. package/dist/{toRefundInputs-DIIdhjvu.js → toRefundInputs-10RYIfh1.js} +2 -2
  87. package/dist/{toRefundInputs-DIIdhjvu.js.map → toRefundInputs-10RYIfh1.js.map} +1 -1
  88. package/dist/{toRefundInputs-B_GlIXjk.cjs → toRefundInputs-a-0HRyrl.cjs} +2 -2
  89. package/dist/{toRefundInputs-B_GlIXjk.cjs.map → toRefundInputs-a-0HRyrl.cjs.map} +1 -1
  90. package/dist/{types-DJxOEU3P.cjs → types-BueQoMjO.cjs} +2 -2
  91. package/dist/{types-DJxOEU3P.cjs.map → types-BueQoMjO.cjs.map} +1 -1
  92. package/dist/{types-Dz1kVqn6.js → types-DGkejGZH.js} +2 -2
  93. package/dist/{types-Dz1kVqn6.js.map → types-DGkejGZH.js.map} +1 -1
  94. package/package.json +1 -1
  95. package/dist/PeginManager-CKf7Bjmj.js.map +0 -1
  96. package/dist/PeginManager-Dt2Z5ljw.cjs.map +0 -1
  97. package/dist/buildAndBroadcastReclaim-B19cyK69.js.map +0 -1
  98. package/dist/buildAndBroadcastReclaim-DcbsjJdf.cjs +0 -2
  99. package/dist/buildAndBroadcastReclaim-DcbsjJdf.cjs.map +0 -1
  100. package/dist/index-Bnavi_r3.js +0 -521
  101. package/dist/index-Bnavi_r3.js.map +0 -1
  102. package/dist/index-CcdCNFLM.cjs +0 -2
  103. package/dist/index-CcdCNFLM.cjs.map +0 -1
  104. package/dist/json-rpc-client-CQLbpuKK.js.map +0 -1
  105. package/dist/json-rpc-client-DbpFfa_o.cjs +0 -2
  106. package/dist/json-rpc-client-DbpFfa_o.cjs.map +0 -1
  107. package/dist/pegin-registration-client-BdJ6c7si.cjs +0 -2
  108. package/dist/pegin-registration-client-BdJ6c7si.cjs.map +0 -1
  109. package/dist/pegin-registration-client-C5Hktrja.js.map +0 -1
  110. package/dist/primeVpAuth-D21PXgg2.cjs +0 -2
  111. package/dist/primeVpAuth-D21PXgg2.cjs.map +0 -1
  112. package/dist/primeVpAuth-PiUJksAq.js +0 -745
  113. package/dist/primeVpAuth-PiUJksAq.js.map +0 -1
@@ -1,49 +1,49 @@
1
- var it = Object.defineProperty;
2
- var ut = (e, t, r) => t in e ? it(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var O = (e, t, r) => ut(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 ct, c as $, v as lt, u as Ke, p as j, f as V } from "./bitcoin-C-TuHb-v.js";
6
- import { v as ht, d as De, s as pt, P as dt, a as gt } 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 ft, a as M, c as yt } from "./signing-Dhr2t0Z6.js";
9
- import { buildClaimPsbt as bt, buildAssertClaimerPsbt as mt, buildPayoutClaimerPsbt as Pt, buildWronglyChallengedPsbts as vt, buildPayoutDepositorPsbt as wt, finalizeClaimTx as xt, buildWatchtowerArtifacts as Et, extractTapScriptSig as kt, expandWotsSeed as _t, wotsKeypairFromSeed as Tt, validateWotsKeypairAgainstGraph as $t, verifyWatchtowerArtifacts as At, deriveVaultId as Ct } from "./tbv/core/wasm/index.js";
10
- import { p as Me, P as le, f as St, 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 It } from "./deriveVaultRoot-BcvmER1E.js";
14
- import { d as Rt, a as fe } from "./onChainBtcPubkey-CCTdl53s.js";
15
- import { zeroAddress as Bt, isAddress as Vt, isAddressEqual as Ot } from "viem";
16
- import { D as R, c as Nt, b as Ht, R as Kt, d as Ue } from "./json-rpc-client-CQLbpuKK.js";
17
- import { h as ye, b as Dt, s as Mt, j as Ft } from "./sha2-YqVHJiFj.js";
18
- import { d as Ut, c as Lt, b as Gt, f as Le, e as Xt, a as jt } from "./noPayout-qBXWKwav.js";
19
- import { a as qt } from "./secp256k1-D-H9jmd7.js";
20
- const zt = /^0x[0-9a-fA-F]{64}$/, Wt = /^0x[0-9a-fA-F]{40}$/, Yt = /^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 (!zt.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 Qt(e, t) {
32
- if (!Wt.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 Jt(e, t) {
38
- if (!Yt.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
- Qt(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"), !ht(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
  );
@@ -55,27 +55,27 @@ async function Oo(e) {
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 Jt(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
75
  async function No(e) {
76
- const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: n, signal: a } = e;
77
- a == null || a.throwIfAborted();
78
- const s = Ge({
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 No(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 Zt 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 er(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 Zt(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 tr 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 rr(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 } = or(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 tr(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 or(e) {
161
+ function nr(e) {
162
162
  return {
163
163
  version: e.version,
164
164
  locktime: e.locktime,
@@ -168,109 +168,109 @@ function or(e) {
168
168
  }))
169
169
  };
170
170
  }
171
- const je = 0;
172
- class nr 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 sr(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 ar(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
- Rt(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 nr(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 ir = 0, ur = 0, cr = 1, lr = 0, hr = 0;
212
+ const ur = 0, cr = 0, lr = 1, hr = 0, pr = 0;
213
213
  async function Ho(e) {
214
- const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n, a, s] = await Promise.all([
215
- bt(t, r),
214
+ const { txGraphVersion: t } = e.vault, r = e.source.txGraphJson, [o, n, i, a] = await Promise.all([
216
215
  mt(t, r),
216
+ vt(t, r),
217
217
  Pt(t, r),
218
- vt(t, r)
218
+ wt(t, r)
219
219
  ]);
220
- qe({
221
- peginTxid: sr(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 wt(
225
+ const s = await xt(
226
226
  t,
227
227
  r
228
228
  );
229
- for (const x of [a, i])
230
- rr({
231
- payoutPsbtBase64: x,
229
+ for (const w of [i, s])
230
+ or({
231
+ payoutPsbtBase64: w,
232
232
  registeredPayoutScriptPubKey: e.vault.registeredPayoutScriptPubKey
233
233
  });
234
- er({
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: ir },
243
- { psbtBase64: n, inputIndex: ur },
244
- { psbtBase64: a, inputIndex: cr },
242
+ { psbtBase64: o, inputIndex: ur },
243
+ { psbtBase64: n, inputIndex: cr },
244
+ { psbtBase64: i, inputIndex: lr },
245
245
  {
246
- psbtBase64: i,
247
- inputIndex: lr
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: hr });
253
- const h = await dr(
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 xt(
268
+ const m = await Et(
269
269
  t,
270
270
  r,
271
271
  p
272
272
  );
273
- return Et({
273
+ return kt({
274
274
  txGraphVersion: t,
275
275
  graphJson: r,
276
276
  signedClaimTxHex: m,
@@ -286,7 +286,7 @@ async function Ho(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 pr(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 (!ct(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 dr(e, t, r, o) {
311
- const n = await pr(
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) => gr(s.psbtBase64)),
317
+ o.map((a) => fr(a.psbtBase64)),
318
318
  o.map(
319
- (s) => ft(
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) => kt(fr(s), o[i].inputIndex)
327
+ i.map(
328
+ (a, s) => _t(yr(a), o[s].inputIndex)
329
329
  )
330
330
  );
331
331
  }
332
- function gr(e) {
332
+ function fr(e) {
333
333
  return I.from(e, "base64").toString("hex");
334
334
  }
335
- function fr(e) {
335
+ function yr(e) {
336
336
  return I.from(e, "hex").toString("base64");
337
337
  }
338
338
  async function Ko(e) {
339
- const t = await It(e.btcWallet, e.vaultContext);
339
+ const t = await Rt(e.btcWallet, e.vaultContext);
340
340
  let r;
341
341
  try {
342
- r = await _t(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 Tt(r);
348
+ o = await $t(r);
349
349
  } finally {
350
350
  r.fill(0);
351
351
  }
352
- return yr(o.pk_hash, e.expectedWotsPkHash), await $t(
352
+ return br(o.pk_hash, e.expectedWotsPkHash), await Ct(
353
353
  e.txGraphVersion,
354
354
  o.keypair,
355
355
  e.txGraphJson
@@ -358,17 +358,17 @@ async function Ko(e) {
358
358
  pkHash: o.pk_hash
359
359
  };
360
360
  }
361
- function yr(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 br = 3;
371
- class mr 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.`
@@ -379,40 +379,40 @@ 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 = vr(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: ar(o),
398
+ peginTxid: ir(o),
399
399
  proverCircuitVersion: n,
400
- claimableEventBlockNumber: a,
400
+ claimableEventBlockNumber: i,
401
401
  babeSessionChallengerPubkeys: Object.keys(
402
- wr(t.babe_sessions, "babe_sessions")
402
+ xr(t.babe_sessions, "babe_sessions")
403
403
  )
404
404
  };
405
405
  }
406
406
  async function Do(e) {
407
- const t = Pr(e.artifactsJson), r = G(e.expectedVaultId), o = G(t.vaultId);
407
+ const t = Pr(e.artifactsJson), r = X(e.expectedVaultId), o = X(t.vaultId);
408
408
  if (r !== o)
409
- throw new mr(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 ?? br;
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}.`
@@ -423,7 +423,7 @@ async function Do(e) {
423
423
  );
424
424
  return await At(n, e.artifactsJson), t;
425
425
  }
426
- function vr(e) {
426
+ function wr(e) {
427
427
  try {
428
428
  return B.fromHex(e);
429
429
  } catch (t) {
@@ -432,40 +432,40 @@ function vr(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 wr(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 xr = 8, Er = 6e3, kr = 10 * 6e4, _r = 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 Tr(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
465
  function Mo(e) {
466
- return e instanceof Ye || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
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
  }
@@ -474,10 +474,10 @@ async function Fo(e) {
474
474
  vaultRegistryReader: t,
475
475
  getBlockNumber: r,
476
476
  vaultIds: o,
477
- required: n = xr,
478
- pollIntervalMs: a = Er,
479
- timeoutMs: s = kr,
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 Fo(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 === Bt || y.createdAt === 0n
502
+ (y) => y.depositor === Vt || y.createdAt === 0n
503
503
  );
504
504
  if (b !== -1) {
505
- if (l += 1, !h && l > _r)
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 (Tr(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 Fo(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 $r = /^(?:[0-9a-f]{2})*$/, Ar = /^[0-9a-f]{64}$/, Cr = /^([0-9a-f]{64}):(0|[1-9][0-9]*)$/, Sr = -2147483648, Ir = 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
- function C(e, t) {
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" || !$r.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) {
585
+ function q(e, t) {
586
586
  if (typeof e != "string" || !Ar.test(e))
587
- throw new v(
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) {
593
- const r = C(e, t), o = new B();
594
- return o.version = N(
592
+ function _e(e, t) {
593
+ const r = A(e, t), o = new B();
594
+ return o.version = H(
595
595
  E(r, "version", t),
596
596
  `${t}.version`,
597
- Sr,
598
- Ir
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 = C(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 = C(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 Rr(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
- }), Dt(Mt(Ft(...r)));
680
- }
681
- function Br(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
- Rr(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 Vr(e) {
705
- const t = (o) => Ee(C(E(e, o, "graph"), o).tx, o), r = C(
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 = C(n, a);
715
+ const i = `challenger_subgraphs[${o}]`, a = A(n, i);
716
716
  return {
717
717
  pubkey: o,
718
- nopayoutTx: Ee(
719
- C(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 Or(e) {
733
- const t = C(
732
+ function Nr(e) {
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 Uo(e, t) {
752
- const r = Vr(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
- C(e.challenger_subgraphs, "challenger_subgraphs")
759
- ), n = Or(e);
760
- if (o.length !== n.size || o.some((a) => !n.has(a)))
761
- throw new v(
758
+ A(e.challenger_subgraphs, "challenger_subgraphs")
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 Nr = 1;
766
- function Hr(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 Kr(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 = Kr(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 Dr(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
- Hr(
810
+ Kr(
811
811
  e.challenger_presign_data,
812
- s,
812
+ a,
813
813
  r.universalChallengerBtcPubkeys
814
814
  );
815
- const i = await St({
815
+ const s = await It({
816
816
  vaultCoreVersion: r.vaultCoreVersion,
817
817
  vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
818
818
  vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
@@ -828,226 +828,231 @@ async function Dr(e, t, r) {
828
828
  network: r.network,
829
829
  claimerBtcPubkey: r.depositorBtcPubkey,
830
830
  registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
831
- commissionBps: Nr,
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 Mr({
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 Mr(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
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 Lt({
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 Fr(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
968
  async function Ur(e) {
969
- const { depositorGraph: t, btcWallet: r, signingContext: o } = e, n = await r.getPublicKeyHex(), { depositorPubkey: a } = lt(
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 Dr(
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 Fr(
985
- h,
984
+ return Lr(
985
+ l,
986
986
  u,
987
- a
987
+ i
988
988
  );
989
989
  }
990
- const Lr = 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 = Lr,
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))
1016
+ throw new Error(
1017
+ `getPeginStatusByVaultId returned status for vault ${c.vault_id.slice(0, O)}…, requested ${r.slice(0, O)}…`
1018
+ );
1019
+ if (c.pegin_txid.toLowerCase() !== o.toLowerCase())
1015
1020
  throw new Error(
1016
- `getPeginStatus returned status for pegin ${u.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
1021
+ `getPeginStatusByVaultId returned status for pegin ${c.pegin_txid.slice(0, 8)}…, requested ${o.slice(0, 8)}…`
1017
1022
  );
1018
- const c = u.status;
1019
- if (o.has(c) || c === R.ACTIVATED)
1020
- return c;
1021
- if (c === R.EXPIRED || Nt.has(c))
1023
+ const l = c.status;
1024
+ if (n.has(l) || l === R.ACTIVATED)
1025
+ return l;
1026
+ if (l === R.EXPIRED || Ht.has(l))
1022
1027
  throw new Error(
1023
- `Pegin ${r.slice(0, 8)}… reached terminal status "${c}" while waiting for ${[...o].join(", ")}`
1028
+ `Vault ${r.slice(0, O)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
1024
1029
  );
1025
- } catch (u) {
1026
- if (!(u instanceof Ht && u.code === Kt.PEGIN_NOT_FOUND))
1027
- throw u;
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 Gr = 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
- ]), Xr = /* @__PURE__ */ new Set([
1053
+ ]), qr = /* @__PURE__ */ new Set([
1049
1054
  R.PENDING_DEPOSITOR_SIGNATURES,
1050
- ...Ze
1055
+ ...tt
1051
1056
  ]);
1052
1057
  function jr(e) {
1053
1058
  return e.map((t) => ({
@@ -1059,10 +1064,10 @@ function jr(e) {
1059
1064
  function S(e) {
1060
1065
  return j(e).toLowerCase();
1061
1066
  }
1062
- function qr(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 qr(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 qr(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 zr(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 Wr(e, t, r, o) {
1147
- const n = new dt({
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 Lo(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 = Gr,
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: Xr,
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 && qr(i, s), pt(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 = Br({
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
- zr(
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 = jr(y), x = await Wr(
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 Ur({
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,70 +1259,72 @@ async function Lo(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 Yr = 300 * 1e3, Qr = /* @__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
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 = Yr,
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: Qr,
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 Jr(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
1330
  async function Xo(e) {
@@ -1324,32 +1333,32 @@ async function Xo(e) {
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 Zr(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 Zr(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 Zr([
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 eo(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 to(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 jo(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 qo(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 qo(e) {
1449
1458
  o.getLatestUniversalChallengersVersion(p),
1450
1459
  o.getCurrentUcKeyEpoch(p)
1451
1460
  ]);
1452
- if (!Vt(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 (!Ot(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 qo(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,70 +1488,70 @@ async function qo(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
- }, A = await eo({
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: A.vaultProvider.operationBtcPubkey,
1497
- vaultKeepers: [...A.vaultKeeperOperationKeysSorted],
1504
+ }), v = {
1505
+ vaultProvider: $.vaultProvider.operationBtcPubkey,
1506
+ vaultKeepers: [...$.vaultKeeperOperationKeysSorted],
1498
1507
  universalChallengers: [
1499
- ...A.universalChallengerOperationKeysSorted
1508
+ ...$.universalChallengerOperationKeysSorted
1500
1509
  ]
1501
- }, se = Jr(
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], at = ue.some((T) => T.registration && !T.operation), ce = ue.some((T) => T.operation && !T.registration);
1527
- if (at && 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: A
1551
+ participantKeys: $
1543
1552
  };
1544
1553
  }
1545
- function ro(e) {
1554
+ function oo(e) {
1546
1555
  return /^[0-9a-fA-F]{64}$/.test(e);
1547
1556
  }
1548
1557
  function zo(e) {
@@ -1551,10 +1560,10 @@ function zo(e) {
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
1568
  function Wo(e, t, r) {
1560
1569
  return e <= 0n ? {
@@ -1594,7 +1603,7 @@ function Qo(e, t) {
1594
1603
  error: "Invalid vault provider selected"
1595
1604
  } : { valid: !0 };
1596
1605
  }
1597
- function oo(e, t, r) {
1606
+ function no(e, t, r) {
1598
1607
  if (!e || e.length === 0)
1599
1608
  return {
1600
1609
  valid: !1,
@@ -1620,26 +1629,26 @@ function oo(e, t, r) {
1620
1629
  }
1621
1630
  return { valid: !0 };
1622
1631
  }
1623
- function no(e) {
1632
+ function so(e) {
1624
1633
  const t = f(e);
1625
- return ro(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 so(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 ao(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 io(e) {
1651
+ function uo(e) {
1643
1652
  if (e.length === 0)
1644
1653
  throw new Error("No spendable UTXOs available");
1645
1654
  }
@@ -1649,79 +1658,79 @@ function Jo(e) {
1649
1658
  confirmedUTXOs: r,
1650
1659
  vaultProviderBtcPubkey: o,
1651
1660
  vaultKeeperBtcPubkeys: n,
1652
- universalChallengerBtcPubkeys: a,
1653
- minDeposit: s,
1654
- maxDeposit: i
1655
- } = e, u = oo(
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 = no(o);
1671
+ const c = so(o);
1663
1672
  if (!c.valid)
1664
1673
  throw new Error(c.error);
1665
- so(n), ao(a), io(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
1681
  function Zo(e) {
1673
- return e instanceof tt || e instanceof Error && e.name === "ParticipantKeyDriftError";
1682
+ return e instanceof ot || e instanceof Error && e.name === "ParticipantKeyDriftError";
1674
1683
  }
1675
- function Ae(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
1687
  async function en(e) {
1679
- const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: n } = e, a = n.query;
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 to({
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 = Ae(
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 = Ae(
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
1732
  function tn(e) {
1724
- return e instanceof rt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1733
+ return e instanceof nt || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
1725
1734
  }
1726
1735
  async function rn(e) {
1727
1736
  const {
@@ -1729,57 +1738,43 @@ async function rn(e) {
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
- var ot = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ot || {});
1752
- const uo = /* @__PURE__ */ new Set([
1753
- "PayoutBroadcast",
1754
- "PayoutBlocked"
1755
- /* PAYOUT_BLOCKED */
1756
- ]);
1757
- function on(e) {
1758
- return Object.values(ot).includes(
1759
- e
1760
- );
1761
- }
1762
- function nn(e) {
1763
- return !!e && uo.has(e);
1764
- }
1765
1760
  class co extends Error {
1766
1761
  constructor(r, o) {
1767
1762
  super(`Refund not yet mature (BIP68 not final): ${o.message}`);
1768
- O(this, "vaultId");
1769
- O(this, "cause");
1763
+ N(this, "vaultId");
1764
+ N(this, "cause");
1770
1765
  this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
1771
1766
  }
1772
1767
  }
1773
- const lo = /^0x[0-9a-fA-F]{64}$/, ho = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, nt = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, st = 160, Ce = 2e3, Se = 10n, Ie = 100n;
1774
- function sn(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) {
1775
1770
  if (!Number.isFinite(e) || e <= 0)
1776
1771
  throw new Error(
1777
1772
  `feeRateSatsVb must be a positive finite number, got ${e}`
1778
1773
  );
1779
- return BigInt(Math.ceil(e * st));
1774
+ return BigInt(Math.ceil(e * at));
1780
1775
  }
1781
1776
  const po = 1, go = /non-BIP68-final/i;
1782
- function ne(e, t) {
1777
+ function se(e, t) {
1783
1778
  if (e.length !== 66)
1784
1779
  throw new Error(
1785
1780
  `${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
@@ -1789,12 +1784,12 @@ function ne(e, t) {
1789
1784
  `${t} must contain only hex characters after the 0x prefix`
1790
1785
  );
1791
1786
  }
1792
- function re(e, t) {
1787
+ function oe(e, t) {
1793
1788
  if (!Number.isInteger(e) || e < 0)
1794
1789
  throw new Error(`${t} must be a non-negative integer, got ${e}`);
1795
1790
  }
1796
1791
  function fo(e) {
1797
- if (ne(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1792
+ if (se(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
1798
1793
  throw new Error(
1799
1794
  `htlcVout must be a non-negative integer, got ${e.htlcVout}`
1800
1795
  );
@@ -1806,7 +1801,7 @@ function fo(e) {
1806
1801
  );
1807
1802
  for (let r = 0; r < e.batch.length; r++) {
1808
1803
  const o = e.batch[r];
1809
- 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)
1810
1805
  throw new Error(
1811
1806
  `batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
1812
1807
  );
@@ -1824,10 +1819,10 @@ function fo(e) {
1824
1819
  throw new Error(
1825
1820
  `batch[${e.htlcVout}].amount (${t.amount}) does not match target amount (${e.amount})`
1826
1821
  );
1827
- if (re(e.offchainParamsVersion, "offchainParamsVersion"), re(e.appVaultKeepersVersion, "appVaultKeepersVersion"), re(
1822
+ if (oe(e.offchainParamsVersion, "offchainParamsVersion"), oe(e.appVaultKeepersVersion, "appVaultKeepersVersion"), oe(
1828
1823
  e.universalChallengersVersion,
1829
1824
  "universalChallengersVersion"
1830
- ), qt(
1825
+ ), zt(
1831
1826
  e.vaultCoreVersion,
1832
1827
  "VaultRefundData.vaultCoreVersion"
1833
1828
  ), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
@@ -1836,7 +1831,7 @@ function fo(e) {
1836
1831
  throw new Error(
1837
1832
  "unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
1838
1833
  );
1839
- if (!e.depositorBtcPubkey || !nt.test(e.depositorBtcPubkey))
1834
+ if (!e.depositorBtcPubkey || !st.test(e.depositorBtcPubkey))
1840
1835
  throw new Error(
1841
1836
  "depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
1842
1837
  );
@@ -1844,7 +1839,7 @@ function fo(e) {
1844
1839
  throw new Error(`amount must be a positive bigint, got ${e.amount}`);
1845
1840
  }
1846
1841
  function yo(e) {
1847
- if (!e.vaultProviderPubkey || !nt.test(e.vaultProviderPubkey))
1842
+ if (!e.vaultProviderPubkey || !st.test(e.vaultProviderPubkey))
1848
1843
  throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
1849
1844
  if (e.vaultKeeperPubkeys.length === 0)
1850
1845
  throw new Error("vaultKeeperPubkeys must be non-empty");
@@ -1869,35 +1864,35 @@ function yo(e) {
1869
1864
  `councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
1870
1865
  );
1871
1866
  }
1872
- async function an(e) {
1867
+ async function nn(e) {
1873
1868
  const {
1874
1869
  vaultId: t,
1875
1870
  readVault: r,
1876
1871
  readPrePeginContext: o,
1877
1872
  feeRate: n,
1878
- signPsbt: a,
1879
- broadcastTx: s,
1880
- signal: i
1873
+ signPsbt: i,
1874
+ broadcastTx: a,
1875
+ signal: s
1881
1876
  } = e;
1882
- i == null || i.throwIfAborted(), ne(t, "vaultId");
1877
+ s == null || s.throwIfAborted(), se(t, "vaultId");
1883
1878
  const u = await r();
1884
- fo(u), i == null || i.throwIfAborted();
1879
+ fo(u), s == null || s.throwIfAborted();
1885
1880
  const c = await o(u);
1886
- if (yo(c), i == null || i.throwIfAborted(), !Number.isFinite(n) || n <= 0)
1881
+ if (yo(c), s == null || s.throwIfAborted(), !Number.isFinite(n) || n <= 0)
1887
1882
  throw new Error(`feeRate must be a positive number, got ${n}`);
1888
- if (n > Ce)
1883
+ if (n > Ie)
1889
1884
  throw new Error(
1890
- `feeRate ${n} sat/vB exceeds refund safety cap ${Ce} sat/vB; refusing to sign refund.`
1885
+ `feeRate ${n} sat/vB exceeds refund safety cap ${Ie} sat/vB; refusing to sign refund.`
1891
1886
  );
1892
- const h = BigInt(Math.ceil(n * st)), l = u.amount * Se / Ie;
1893
- if (h > l)
1887
+ const l = BigInt(Math.ceil(n * at)), h = u.amount * Re / Be;
1888
+ if (l > h)
1894
1889
  throw new Error(
1895
- `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.`
1896
1891
  );
1897
- i == null || i.throwIfAborted();
1892
+ s == null || s.throwIfAborted();
1898
1893
  const p = j(
1899
1894
  u.depositorBtcPubkey
1900
- ), d = f(u.unsignedPrePeginTxHex), g = gt(d);
1895
+ ), d = f(u.unsignedPrePeginTxHex), g = ft(d);
1901
1896
  if (g !== void 0 && g.vout !== u.batch.length)
1902
1897
  throw new Error(
1903
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.`
@@ -1906,23 +1901,23 @@ async function an(e) {
1906
1901
  let y;
1907
1902
  try {
1908
1903
  y = B.fromHex(d);
1909
- } catch (P) {
1904
+ } catch (v) {
1910
1905
  throw new Error(
1911
- `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)}`
1912
1907
  );
1913
1908
  }
1914
1909
  if (y.outs.length < u.batch.length)
1915
1910
  throw new Error(
1916
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.`
1917
1912
  );
1918
- const { psbtHex: m } = await Gt({
1913
+ const { psbtHex: m } = await Xt({
1919
1914
  prePeginParams: {
1920
1915
  vaultCoreVersion: u.vaultCoreVersion,
1921
1916
  depositorPubkey: p,
1922
1917
  vaultProviderPubkey: f(c.vaultProviderPubkey),
1923
1918
  vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(f),
1924
1919
  universalChallengerPubkeys: c.universalChallengerPubkeys.map(f),
1925
- hashlocks: u.batch.map((P) => f(P.hashlock)),
1920
+ hashlocks: u.batch.map((v) => f(v.hashlock)),
1926
1921
  timelockRefund: c.timelockRefund,
1927
1922
  // `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
1928
1923
  // is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
@@ -1930,7 +1925,7 @@ async function an(e) {
1930
1925
  // HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
1931
1926
  // to the funded tx bytes, refusing the refund if the template's HTLC value
1932
1927
  // disagrees with the on-chain commitment.
1933
- pegInAmounts: u.batch.map((P) => P.amount),
1928
+ pegInAmounts: u.batch.map((v) => v.amount),
1934
1929
  feeRate: c.feeRate,
1935
1930
  minPeginFeeRate: c.minPeginFeeRate,
1936
1931
  numLocalChallengers: c.numLocalChallengers,
@@ -1941,88 +1936,88 @@ async function an(e) {
1941
1936
  },
1942
1937
  fundedPrePeginTxHex: d,
1943
1938
  htlcVout: u.htlcVout,
1944
- refundFee: h,
1939
+ refundFee: l,
1945
1940
  // buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
1946
1941
  // prefix" and flows into the WASM HTLC connector derivation; a prefixed
1947
1942
  // value would derive the wrong refund script leaf and yield an
1948
1943
  // unspendable PSBT. Match the `hashlocks` array handling above.
1949
1944
  hashlock: f(u.hashlock)
1950
1945
  });
1951
- i == null || i.throwIfAborted();
1952
- const x = M(
1946
+ s == null || s.throwIfAborted();
1947
+ const w = F(
1953
1948
  u.depositorBtcPubkey,
1954
1949
  po
1955
- ), w = await a(m, x);
1956
- F({
1950
+ ), x = await i(m, w);
1951
+ L({
1957
1952
  requestedPsbtHex: m,
1958
- returnedPsbtHex: w
1953
+ returnedPsbtHex: x
1959
1954
  });
1960
1955
  const k = 0, _ = U(
1961
- w,
1956
+ x,
1962
1957
  p,
1963
1958
  k
1964
1959
  );
1965
- L({
1960
+ G({
1966
1961
  requestedPsbtHex: m,
1967
1962
  signatureHex: _,
1968
1963
  signerXOnlyPubkeyHex: p,
1969
1964
  inputIndex: k
1970
1965
  });
1971
- const A = Le({
1966
+ const $ = Xe({
1972
1967
  requestedPsbtHex: m,
1973
1968
  signaturesHex: [_],
1974
1969
  signerXOnlyPubkeyHex: p
1975
1970
  });
1976
- i == null || i.throwIfAborted();
1971
+ s == null || s.throwIfAborted();
1977
1972
  try {
1978
- return await s(A);
1979
- } catch (P) {
1980
- throw P instanceof Error && go.test(P.message) ? new co(t, P) : P;
1973
+ return await a($);
1974
+ } catch (v) {
1975
+ throw v instanceof Error && go.test(v.message) ? new co(t, v) : v;
1981
1976
  }
1982
1977
  }
1983
- class Re extends Error {
1978
+ class Ve extends Error {
1984
1979
  constructor(r, o, n) {
1985
1980
  super(r);
1986
1981
  /** Fee the reclaim would have paid, in satoshis. */
1987
- O(this, "feeSats");
1982
+ N(this, "feeSats");
1988
1983
  /** Sum of the reserves the reclaim would have swept, in satoshis. */
1989
- O(this, "sweptTotalSats");
1984
+ N(this, "sweptTotalSats");
1990
1985
  this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = n;
1991
1986
  }
1992
1987
  }
1993
- const Be = 2e3, Ve = 25n, Oe = 100n, un = 10n;
1988
+ const Oe = 2e3, Ne = 25n, He = 100n, sn = 10n;
1994
1989
  async function bo(e, t, r) {
1995
1990
  for (let o = 0; o < e.length; o++) {
1996
- const n = yt(e[o].depositorSignedPeginTxHex), a = He(
1997
- await Ct(
1991
+ const n = bt(e[o].depositorSignedPeginTxHex), i = De(
1992
+ await St(
1998
1993
  f(n),
1999
1994
  f(r)
2000
1995
  )
2001
1996
  ).toLowerCase();
2002
- if (a !== t[o].toLowerCase())
1997
+ if (i !== t[o].toLowerCase())
2003
1998
  throw new Error(
2004
- `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.`
2005
2000
  );
2006
2001
  }
2007
2002
  }
2008
- async function cn(e) {
2003
+ async function an(e) {
2009
2004
  const {
2010
2005
  vaultIds: t,
2011
2006
  depositorEthAddress: r,
2012
2007
  depositorBtcPubkey: o,
2013
2008
  readVaults: n,
2014
- feeRate: a,
2015
- signPsbt: s,
2016
- broadcastTx: i,
2009
+ feeRate: i,
2010
+ signPsbt: a,
2011
+ broadcastTx: s,
2017
2012
  signal: u
2018
2013
  } = e;
2019
2014
  if (u == null || u.throwIfAborted(), t.length === 0)
2020
2015
  throw new Error("Reclaim requires at least one vault id; got none.");
2021
- if (!Number.isFinite(a) || a <= 0)
2022
- throw new Error(`feeRate must be a positive number, got ${a}`);
2023
- if (a > Be)
2024
- throw new Re(
2025
- `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.`,
2026
2021
  0n,
2027
2022
  0n
2028
2023
  );
@@ -2032,116 +2027,113 @@ async function cn(e) {
2032
2027
  `readVaults returned ${c.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
2033
2028
  );
2034
2029
  await bo(c, t, r), u == null || u.throwIfAborted();
2035
- const h = j(o), l = c.map((k) => ({
2030
+ const l = j(o), h = c.map((k) => ({
2036
2031
  depositorSignedPeginTxHex: k.depositorSignedPeginTxHex,
2037
2032
  observed: k.observed,
2038
2033
  expectedValue: k.expectedClaimValue
2039
- })), p = Xt(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;
2040
2035
  if (p > g)
2041
- throw new Re(
2042
- `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.`,
2043
2038
  p,
2044
2039
  d
2045
2040
  );
2046
2041
  u == null || u.throwIfAborted();
2047
2042
  const { psbtHex: b } = jt({
2048
- depositorPubkey: h,
2049
- inputs: l,
2043
+ depositorPubkey: l,
2044
+ inputs: h,
2050
2045
  feeSats: p
2051
2046
  });
2052
2047
  u == null || u.throwIfAborted();
2053
- const y = M(
2048
+ const y = F(
2054
2049
  o,
2055
- l.length
2056
- ), m = await s(b, y);
2057
- F({
2050
+ h.length
2051
+ ), m = await a(b, y);
2052
+ L({
2058
2053
  requestedPsbtHex: b,
2059
2054
  returnedPsbtHex: m
2060
2055
  });
2061
- const x = l.map((k, _) => {
2062
- const A = U(
2056
+ const w = h.map((k, _) => {
2057
+ const $ = U(
2063
2058
  m,
2064
- h,
2059
+ l,
2065
2060
  _
2066
2061
  );
2067
- return L({
2062
+ return G({
2068
2063
  requestedPsbtHex: b,
2069
- signatureHex: A,
2070
- signerXOnlyPubkeyHex: h,
2064
+ signatureHex: $,
2065
+ signerXOnlyPubkeyHex: l,
2071
2066
  inputIndex: _
2072
- }), A;
2073
- }), w = Le({
2067
+ }), $;
2068
+ }), x = Xe({
2074
2069
  requestedPsbtHex: b,
2075
- signaturesHex: x,
2076
- signerXOnlyPubkeyHex: h
2070
+ signaturesHex: w,
2071
+ signerXOnlyPubkeyHex: l
2077
2072
  });
2078
- return u == null || u.throwIfAborted(), i(w);
2073
+ return u == null || u.throwIfAborted(), s(x);
2079
2074
  }
2080
2075
  export {
2081
- an as $,
2082
- mr as A,
2076
+ Re as $,
2077
+ vr as A,
2083
2078
  Qo as B,
2084
- Zt as C,
2085
- br as D,
2079
+ er as C,
2080
+ mr as D,
2086
2081
  Yo as E,
2087
- oo as F,
2088
- v as G,
2089
- no as H,
2090
- tt as I,
2082
+ no as F,
2083
+ P as G,
2084
+ so as H,
2085
+ ot as I,
2091
2086
  Zo as J,
2092
2087
  en as K,
2093
2088
  tn as L,
2094
2089
  rn as M,
2095
- Je as N,
2090
+ et as N,
2096
2091
  Xo as O,
2097
- tr as P,
2098
- Z as Q,
2099
- rt as R,
2100
- Jr as S,
2101
- _e as T,
2102
- eo as U,
2103
- nr as V,
2104
- to as W,
2105
- ot as X,
2106
- on as Y,
2107
- nn as Z,
2108
- co as _,
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 _,
2109
2104
  Oo as a,
2110
- sn as a0,
2111
- Ie as a1,
2112
- Se as a2,
2113
- Ce as a3,
2114
- st as a4,
2115
- Re as a5,
2116
- cn as a6,
2117
- Oe as a7,
2118
- Ve as a8,
2119
- Be as a9,
2120
- un as aa,
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,
2121
2113
  No as b,
2122
2114
  Ho as c,
2123
2115
  Ko as d,
2124
2116
  Do as e,
2125
- er as f,
2126
- rr as g,
2127
- qe as h,
2128
- xr as i,
2129
- We as j,
2130
- Ye as k,
2131
- Tr as l,
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,
2132
2124
  Mo as m,
2133
- Uo as n,
2134
- Vr as o,
2125
+ Lo as n,
2126
+ Or as o,
2135
2127
  Ur as p,
2136
2128
  Go as q,
2137
- Lo as r,
2129
+ Uo as r,
2138
2130
  Pr as s,
2139
- oe as t,
2140
- jo as u,
2141
- qo as v,
2131
+ ne as t,
2132
+ qo as u,
2133
+ jo as v,
2142
2134
  Fo as w,
2143
2135
  zo as x,
2144
2136
  Wo as y,
2145
2137
  Jo as z
2146
2138
  };
2147
- //# sourceMappingURL=buildAndBroadcastReclaim-B19cyK69.js.map
2139
+ //# sourceMappingURL=buildAndBroadcastReclaim-C55KaRJF.js.map