@babylonlabs-io/ts-sdk 2.0.1 → 3.0.0

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