@babylonlabs-io/ts-sdk 0.73.0 → 0.74.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/{PeginManager-E-UHA1un.cjs → PeginManager-DEByBX5R.cjs} +2 -2
  2. package/dist/{PeginManager-E-UHA1un.cjs.map → PeginManager-DEByBX5R.cjs.map} +1 -1
  3. package/dist/{PeginManager-C9RPOd0L.js → PeginManager-DNimKlmw.js} +11 -11
  4. package/dist/{PeginManager-C9RPOd0L.js.map → PeginManager-DNimKlmw.js.map} +1 -1
  5. package/dist/{bip322Verify-D6sBBUHE.js → bip322Verify-DSco3Yhl.js} +2 -2
  6. package/dist/{bip322Verify-D6sBBUHE.js.map → bip322Verify-DSco3Yhl.js.map} +1 -1
  7. package/dist/buildAndBroadcastReclaim-Cqc6Jiqk.cjs +2 -0
  8. package/dist/{buildAndBroadcastReclaim-U-PyFfDg.cjs.map → buildAndBroadcastReclaim-Cqc6Jiqk.cjs.map} +1 -1
  9. package/dist/{buildAndBroadcastReclaim-BXclIcu_.js → buildAndBroadcastReclaim-DCGcupg7.js} +6 -6
  10. package/dist/{buildAndBroadcastReclaim-BXclIcu_.js.map → buildAndBroadcastReclaim-DCGcupg7.js.map} +1 -1
  11. package/dist/constants-BTZdyOuk.cjs +2 -0
  12. package/dist/constants-BTZdyOuk.cjs.map +1 -0
  13. package/dist/constants-D5vORbQE.js +29 -0
  14. package/dist/constants-D5vORbQE.js.map +1 -0
  15. package/dist/fundPeginTransaction-54-Rwb2k.cjs +2 -0
  16. package/dist/fundPeginTransaction-54-Rwb2k.cjs.map +1 -0
  17. package/dist/fundPeginTransaction-CwhRbCQC.js +88 -0
  18. package/dist/fundPeginTransaction-CwhRbCQC.js.map +1 -0
  19. package/dist/{index-Cs7_Evtk.cjs → index-CK1Xvq4K.cjs} +2 -2
  20. package/dist/{index-Cs7_Evtk.cjs.map → index-CK1Xvq4K.cjs.map} +1 -1
  21. package/dist/{index-LgmJhdEN.js → index-DQ5bfoT3.js} +2 -2
  22. package/dist/{index-LgmJhdEN.js.map → index-DQ5bfoT3.js.map} +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +166 -161
  25. package/dist/noPayout-4RZB2g1e.cjs +2 -0
  26. package/dist/noPayout-4RZB2g1e.cjs.map +1 -0
  27. package/dist/noPayout-DiGr4eas.js +361 -0
  28. package/dist/noPayout-DiGr4eas.js.map +1 -0
  29. package/dist/{parseFundingOutpoints-B67CoXpF.js → parseFundingOutpoints-BQWvINfm.js} +2 -2
  30. package/dist/{parseFundingOutpoints-B67CoXpF.js.map → parseFundingOutpoints-BQWvINfm.js.map} +1 -1
  31. package/dist/pegin-registration-client-CXK3B_D1.js +882 -0
  32. package/dist/pegin-registration-client-CXK3B_D1.js.map +1 -0
  33. package/dist/pegin-registration-client-DLsMNm8Z.cjs +2 -0
  34. package/dist/pegin-registration-client-DLsMNm8Z.cjs.map +1 -0
  35. package/dist/{primeVpAuth-DBHohVKM.cjs → primeVpAuth-BOGKniTl.cjs} +2 -2
  36. package/dist/{primeVpAuth-DBHohVKM.cjs.map → primeVpAuth-BOGKniTl.cjs.map} +1 -1
  37. package/dist/{primeVpAuth-DvaD45q_.js → primeVpAuth-DdfHSC53.js} +4 -4
  38. package/dist/{primeVpAuth-DvaD45q_.js.map → primeVpAuth-DdfHSC53.js.map} +1 -1
  39. package/dist/{psbtInputFields-BIxBpPj2.cjs → psbtInputFields-BrV_ZfL_.cjs} +2 -2
  40. package/dist/{psbtInputFields-BIxBpPj2.cjs.map → psbtInputFields-BrV_ZfL_.cjs.map} +1 -1
  41. package/dist/{psbtInputFields-B3e05Xe6.js → psbtInputFields-CCVyaQMi.js} +2 -2
  42. package/dist/{psbtInputFields-B3e05Xe6.js.map → psbtInputFields-CCVyaQMi.js.map} +1 -1
  43. package/dist/secp256k1-D-H9jmd7.js +1766 -0
  44. package/dist/secp256k1-D-H9jmd7.js.map +1 -0
  45. package/dist/secp256k1-DDHQ1_za.cjs +2 -0
  46. package/dist/secp256k1-DDHQ1_za.cjs.map +1 -0
  47. package/dist/{sha2-CrlWM5S8.js → sha2-CLpQd0Rd.js} +8 -8
  48. package/dist/{sha2-CrlWM5S8.js.map → sha2-CLpQd0Rd.js.map} +1 -1
  49. package/dist/{signPsbtsWithFallback-DMSpIQWH.cjs → signPsbtsWithFallback-DtwzL5AA.cjs} +2 -2
  50. package/dist/{signPsbtsWithFallback-DMSpIQWH.cjs.map → signPsbtsWithFallback-DtwzL5AA.cjs.map} +1 -1
  51. package/dist/{signPsbtsWithFallback-0VBALhjS.js → signPsbtsWithFallback-f7QLp0q8.js} +4 -4
  52. package/dist/{signPsbtsWithFallback-0VBALhjS.js.map → signPsbtsWithFallback-f7QLp0q8.js.map} +1 -1
  53. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  54. package/dist/tbv/core/clients/eth/index.js +3 -3
  55. package/dist/tbv/core/clients/index.cjs +1 -1
  56. package/dist/tbv/core/clients/index.js +5 -5
  57. package/dist/tbv/core/clients/vault-provider/status/index.cjs +1 -1
  58. package/dist/tbv/core/clients/vault-provider/status/index.js +1 -1
  59. package/dist/tbv/core/index.cjs +1 -1
  60. package/dist/tbv/core/index.d.ts +3 -0
  61. package/dist/tbv/core/index.d.ts.map +1 -1
  62. package/dist/tbv/core/index.js +159 -154
  63. package/dist/tbv/core/managers/index.cjs +1 -1
  64. package/dist/tbv/core/managers/index.js +2 -2
  65. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.golden.test.d.ts +62 -0
  66. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.golden.test.d.ts.map +1 -0
  67. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.test.d.ts +15 -0
  68. package/dist/tbv/core/pegin-fingerprint/__tests__/peginFingerprint.test.d.ts.map +1 -0
  69. package/dist/tbv/core/pegin-fingerprint/index.d.ts +14 -0
  70. package/dist/tbv/core/pegin-fingerprint/index.d.ts.map +1 -0
  71. package/dist/tbv/core/pegin-fingerprint/peginFingerprint.d.ts +141 -0
  72. package/dist/tbv/core/pegin-fingerprint/peginFingerprint.d.ts.map +1 -0
  73. package/dist/tbv/core/primitives/index.cjs +1 -1
  74. package/dist/tbv/core/primitives/index.js +4 -4
  75. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts +5 -6
  76. package/dist/tbv/core/primitives/psbt/__tests__/assertPeginTxShape.test.d.ts.map +1 -1
  77. package/dist/tbv/core/primitives/psbt/__tests__/assertWasmPeginSizing.test.d.ts +2 -2
  78. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +36 -14
  79. package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
  80. package/dist/tbv/core/primitives/psbt/constants.d.ts +39 -0
  81. package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
  82. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  83. package/dist/tbv/core/primitives/psbt/peginInput.d.ts.map +1 -1
  84. package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
  85. package/dist/tbv/core/services/index.cjs +1 -1
  86. package/dist/tbv/core/services/index.js +2 -2
  87. package/dist/tbv/core/utils/fee/constants.d.ts +4 -4
  88. package/dist/tbv/core/utils/index.cjs +1 -1
  89. package/dist/tbv/core/utils/index.js +2 -2
  90. package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -1
  91. package/dist/tbv/core/vault-secrets/index.js +1 -1
  92. package/dist/tbv/index.cjs +1 -1
  93. package/dist/tbv/index.js +159 -154
  94. package/dist/test/setup.browser.d.ts +2 -0
  95. package/dist/test/setup.browser.d.ts.map +1 -0
  96. package/dist/testing/index.js +1 -1
  97. package/dist/{toRefundInputs-BkcFhvDp.js → toRefundInputs-BNSXIymn.js} +238 -140
  98. package/dist/toRefundInputs-BNSXIymn.js.map +1 -0
  99. package/dist/toRefundInputs-meTyor7r.cjs +2 -0
  100. package/dist/toRefundInputs-meTyor7r.cjs.map +1 -0
  101. package/dist/{types-DSlcXtog.cjs → types-BzSOthHH.cjs} +2 -2
  102. package/dist/{types-DSlcXtog.cjs.map → types-BzSOthHH.cjs.map} +1 -1
  103. package/dist/{types-CPDLZm3l.js → types-C5DyrC8F.js} +2 -2
  104. package/dist/{types-CPDLZm3l.js.map → types-C5DyrC8F.js.map} +1 -1
  105. package/dist/verifyKeyPathSchnorrSignature-BVtNwgK6.js +360 -0
  106. package/dist/verifyKeyPathSchnorrSignature-BVtNwgK6.js.map +1 -0
  107. package/dist/verifyKeyPathSchnorrSignature-BjB8Znly.cjs +2 -0
  108. package/dist/verifyKeyPathSchnorrSignature-BjB8Znly.cjs.map +1 -0
  109. package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js +1140 -0
  110. package/dist/verifyScriptPathSchnorrSignature-D_epga4j.js.map +1 -0
  111. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs +2 -0
  112. package/dist/verifyScriptPathSchnorrSignature-DaRqvEgW.cjs.map +1 -0
  113. package/package.json +5 -2
  114. package/dist/buildAndBroadcastReclaim-U-PyFfDg.cjs +0 -2
  115. package/dist/constants-Bh38W9mq.cjs +0 -2
  116. package/dist/constants-Bh38W9mq.cjs.map +0 -1
  117. package/dist/constants-CPzppOdq.js +0 -17
  118. package/dist/constants-CPzppOdq.js.map +0 -1
  119. package/dist/fundPeginTransaction-B2wyjqp0.js +0 -83
  120. package/dist/fundPeginTransaction-B2wyjqp0.js.map +0 -1
  121. package/dist/fundPeginTransaction-BLD8FRL9.cjs +0 -2
  122. package/dist/fundPeginTransaction-BLD8FRL9.cjs.map +0 -1
  123. package/dist/noPayout-DpGRzidi.js +0 -353
  124. package/dist/noPayout-DpGRzidi.js.map +0 -1
  125. package/dist/noPayout-zEifyecV.cjs +0 -2
  126. package/dist/noPayout-zEifyecV.cjs.map +0 -1
  127. package/dist/pegin-registration-client-6vLk2itL.cjs +0 -2
  128. package/dist/pegin-registration-client-6vLk2itL.cjs.map +0 -1
  129. package/dist/pegin-registration-client-BdRiR8br.js +0 -2635
  130. package/dist/pegin-registration-client-BdRiR8br.js.map +0 -1
  131. package/dist/toRefundInputs-BkcFhvDp.js.map +0 -1
  132. package/dist/toRefundInputs-CatCKniS.cjs +0 -2
  133. package/dist/toRefundInputs-CatCKniS.cjs.map +0 -1
  134. package/dist/vaultCoreVersion-DYfw3qed.cjs +0 -2
  135. package/dist/vaultCoreVersion-DYfw3qed.cjs.map +0 -1
  136. package/dist/vaultCoreVersion-D_fP9P3C.js +0 -10
  137. package/dist/vaultCoreVersion-D_fP9P3C.js.map +0 -1
  138. package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs +0 -2
  139. package/dist/verifyKeyPathSchnorrSignature-BedSbH2D.cjs.map +0 -1
  140. package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js +0 -372
  141. package/dist/verifyKeyPathSchnorrSignature-BrgUJmV0.js.map +0 -1
  142. package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs +0 -2
  143. package/dist/verifyScriptPathSchnorrSignature-BfNUSgA7.cjs.map +0 -1
  144. package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js +0 -951
  145. package/dist/verifyScriptPathSchnorrSignature-Ciq_xZhw.js.map +0 -1
@@ -1,53 +1,54 @@
1
- var J = Object.defineProperty;
2
- var X = (e, t, r) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var I = (e, t, r) => X(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { s as G } from "./sha2-CrlWM5S8.js";
5
- import { a as F } from "./signPsbtsWithFallback-0VBALhjS.js";
6
- import { b as Y, f as Z } from "./PeginManager-C9RPOd0L.js";
7
- import { s as P, h as ee, p as z, u as te, e as re } from "./bitcoin-C-TuHb-v.js";
8
- import { computeMinClaimValue as N, computeMinPeginFee as D, peginP2aAnchorOutput as U, getPrePeginHtlcConnectorInfo as ne, expandAuthAnchor as oe } from "./tbv/core/wasm/index.js";
9
- import { p as se, d as ae } from "./parseFundingOutpoints-B67CoXpF.js";
10
- import { Transaction as j } from "bitcoinjs-lib";
11
- import { m as ie, H as K } from "./verifyScriptPathSchnorrSignature-Ciq_xZhw.js";
12
- import { c as O } from "./fundPeginTransaction-B2wyjqp0.js";
13
- import { c as L } from "./signing-Cm-McVR2.js";
14
- const W = "DepositTermsRejectedError";
15
- class ce extends Error {
1
+ var re = Object.defineProperty;
2
+ var ne = (e, t, r) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var _ = (e, t, r) => ne(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { keccak256 as G, toHex as oe, encodeAbiParameters as se, isAddress as ae, zeroAddress as ie } from "viem";
5
+ import { s as ce } from "./sha2-CLpQd0Rd.js";
6
+ import { a as M } from "./signPsbtsWithFallback-f7QLp0q8.js";
7
+ import { b as ue, f as le } from "./PeginManager-DNimKlmw.js";
8
+ import { s as P, h as he, p as W, u as de, e as me } from "./bitcoin-C-TuHb-v.js";
9
+ import { computeMinClaimValue as Q, computeMinPeginFee as X, peginP2aAnchorOutput as q, getPrePeginHtlcConnectorInfo as pe, expandAuthAnchor as ge } from "./tbv/core/wasm/index.js";
10
+ import { p as Pe, d as fe } from "./parseFundingOutpoints-BQWvINfm.js";
11
+ import { Transaction as J } from "bitcoinjs-lib";
12
+ import { o as ve, H as z } from "./verifyScriptPathSchnorrSignature-D_epga4j.js";
13
+ import { c as O } from "./fundPeginTransaction-CwhRbCQC.js";
14
+ import { c as Y } from "./signing-Cm-McVR2.js";
15
+ const Z = "DepositTermsRejectedError";
16
+ class be extends Error {
16
17
  constructor(r, n = "device-envelope") {
17
18
  super(r);
18
- I(this, "reason");
19
- this.name = W, this.reason = n;
19
+ _(this, "reason");
20
+ this.name = Z, this.reason = n;
20
21
  }
21
22
  }
22
- function Ae(e) {
23
- if (e instanceof ce) return !0;
23
+ function qe(e) {
24
+ if (e instanceof be) return !0;
24
25
  if (typeof e != "object" || e === null) return !1;
25
26
  const t = e;
26
- return t.name === W && t.reason === "device-envelope";
27
+ return t.name === Z && t.reason === "device-envelope";
27
28
  }
28
- async function ue(e) {
29
+ async function ye(e) {
29
30
  const t = e.siblings.length;
30
31
  if (t === 0)
31
32
  throw new Error(
32
33
  "rebuildDepositTermsCore: at least one sibling is required"
33
34
  );
34
- for (const [o, v] of e.siblings.entries())
35
- if (v.amount <= 0n)
35
+ for (const [o, b] of e.siblings.entries())
36
+ if (b.amount <= 0n)
36
37
  throw new Error(
37
- `rebuildDepositTermsCore: sibling[${o}] has non-positive on-chain pegin amount ${v.amount}; the chain-read vault record is invalid. Resume refused.`
38
+ `rebuildDepositTermsCore: sibling[${o}] has non-positive on-chain pegin amount ${b.amount}; the chain-read vault record is invalid. Resume refused.`
38
39
  );
39
40
  if (e.prepeginMaxFee <= 0n)
40
41
  throw new Error(
41
42
  `rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${e.prepeginMaxFee}`
42
43
  );
43
44
  const r = P(e.prepeginTxid).toLowerCase(), n = P(
44
- L(e.fundedPrePeginTxHex)
45
+ Y(e.fundedPrePeginTxHex)
45
46
  ).toLowerCase();
46
47
  if (n !== r)
47
48
  throw new Error(
48
49
  `Funded Pre-PegIn tx hashes to ${n}, expected ${r} (on-chain prepeginTxid). Resume refused.`
49
50
  );
50
- const h = F(
51
+ const h = M(
51
52
  P(e.fundedPrePeginTxHex)
52
53
  );
53
54
  if (h === void 0)
@@ -58,19 +59,19 @@ async function ue(e) {
58
59
  throw new Error(
59
60
  `Auth-anchor OP_RETURN at vout ${h.vout} does not match the discovered sibling count ${t}; the discovered sibling set does not cover this transaction's HTLC outputs (a lagging index can cause this — retry later). Resume refused.`
60
61
  );
61
- const c = e.vaultKeeperBtcPubkeys.length, u = e.universalChallengerBtcPubkeys.length, l = await N(
62
+ const c = e.vaultKeeperBtcPubkeys.length, u = e.universalChallengerBtcPubkeys.length, l = await Q(
62
63
  e.vaultCoreVersion,
63
64
  c,
64
65
  u,
65
66
  e.councilQuorum,
66
67
  e.councilSize,
67
68
  e.protocolFeeRate
68
- ), i = await D(
69
+ ), i = await X(
69
70
  e.vaultCoreVersion,
70
71
  c,
71
72
  u,
72
73
  e.minPeginFeeRate
73
- ), d = await U(e.vaultCoreVersion), s = (d == null ? void 0 : d.value) ?? 0n;
74
+ ), d = await q(e.vaultCoreVersion), s = (d == null ? void 0 : d.value) ?? 0n;
74
75
  if (l <= 0n)
75
76
  throw new Error(
76
77
  `WASM returned non-positive depositorClaimValue ${l}; expected > 0. Resume refused.`
@@ -83,15 +84,15 @@ async function ue(e) {
83
84
  throw new Error(
84
85
  `WASM returned negative P2A anchor value ${s}. Resume refused.`
85
86
  );
86
- const a = i + s, f = e.minPeginFeeRate * O;
87
- if (a <= 0n || a > f)
87
+ const a = i + s, v = e.minPeginFeeRate * O;
88
+ if (a <= 0n || a > v)
88
89
  throw new Error(
89
- `WASM implied PegIn reserve ${a} sat is outside (0, ${f}] (minPeginFeeRate=${e.minPeginFeeRate} × ${O} vbytes). Resume refused.`
90
+ `WASM implied PegIn reserve ${a} sat is outside (0, ${v}] (minPeginFeeRate=${e.minPeginFeeRate} × ${O} vbytes). Resume refused.`
90
91
  );
91
92
  const w = e.siblings.map(
92
93
  (o) => o.amount + l + i + s
93
- ), y = await Promise.all(
94
- e.siblings.map(async (o) => (await ne({
94
+ ), C = await Promise.all(
95
+ e.siblings.map(async (o) => (await pe({
95
96
  txGraphVersion: e.vaultCoreVersion,
96
97
  depositorPubkey: e.depositorBtcPubkey,
97
98
  vaultProviderPubkey: e.vaultProviderBtcPubkey,
@@ -101,14 +102,14 @@ async function ue(e) {
101
102
  timelockRefund: e.timelockRefund,
102
103
  network: e.network
103
104
  })).scriptPubKey)
104
- ), k = j.fromHex(
105
+ ), E = J.fromHex(
105
106
  P(e.fundedPrePeginTxHex)
106
107
  ).outs.map((o) => ({ value: o.value, script: o.script }));
107
- return ie(
108
- k,
108
+ return ve(
109
+ E,
109
110
  w,
110
- y
111
- ), Y({
111
+ C
112
+ ), ue({
112
113
  vaultCoreVersion: e.vaultCoreVersion,
113
114
  protocolFeeRate: e.protocolFeeRate,
114
115
  timelockPegin: e.timelockPegin,
@@ -125,85 +126,177 @@ async function ue(e) {
125
126
  peginMaxFee: i
126
127
  });
127
128
  }
128
- function Be(e) {
129
+ function Je(e) {
129
130
  const t = (e instanceof Error ? e.message : typeof e == "string" ? e : "").toLowerCase();
130
131
  return t.includes("wots") && t.includes("hash") && t.includes("does not match");
131
132
  }
132
- class le extends Error {
133
+ const we = "TBV.PeginFingerprint.v1", Ee = G(
134
+ oe(we)
135
+ ), U = 65535, D = 2n ** 64n - 1n, Ce = 2n ** 256n - 1n, Re = /^0x[0-9a-fA-F]{64}$/, L = 1;
136
+ class f extends Error {
137
+ constructor(t) {
138
+ super(t), this.name = "PeginFingerprintInputError";
139
+ }
140
+ }
141
+ function B(e, t, r, n) {
142
+ if (typeof t != "bigint")
143
+ throw new f(
144
+ `${e} must be a bigint (Solidity ${n}), got ${typeof t}`
145
+ );
146
+ if (t < 0n || t > r)
147
+ throw new f(
148
+ `${e} must fit Solidity ${n} (0..${r}), got ${t}`
149
+ );
150
+ }
151
+ function $(e, t) {
152
+ if (!Number.isInteger(t) || t < 0 || t > U)
153
+ throw new f(
154
+ `${e} must be an integer fitting Solidity uint16 (0..${U}), got ${t}`
155
+ );
156
+ }
157
+ function ke(e, t) {
158
+ if (!Re.test(t))
159
+ throw new f(
160
+ `${e} must be 32 bytes as 0x-prefixed hex (66 characters), got "${t}"`
161
+ );
162
+ return t.toLowerCase();
163
+ }
164
+ function xe(e) {
165
+ if (!ae(e, { strict: !1 }))
166
+ throw new f(
167
+ `registryAddress must be a 20-byte 0x-prefixed address, got "${e}"`
168
+ );
169
+ const t = e.toLowerCase();
170
+ if (t === ie)
171
+ throw new f(
172
+ "registryAddress must not be the zero address; a zero here means the registry address was never resolved"
173
+ );
174
+ return t;
175
+ }
176
+ const Ve = [
177
+ { name: "domain", type: "bytes32" },
178
+ { name: "chainId", type: "uint256" },
179
+ { name: "registry", type: "address" },
180
+ { name: "vaultProviderBtcKey", type: "bytes32" },
181
+ { name: "appKeeperKeyEpoch", type: "uint64" },
182
+ { name: "ucKeyEpoch", type: "uint64" },
183
+ { name: "appVaultKeepersVersion", type: "uint16" },
184
+ { name: "universalChallengersVersion", type: "uint16" },
185
+ { name: "offchainParamsVersion", type: "uint16" },
186
+ { name: "vaultCoreVersion", type: "uint16" }
187
+ ];
188
+ function $e(e) {
189
+ if (B("chainId", e.chainId, Ce, "uint256"), e.chainId === 0n)
190
+ throw new f(
191
+ "chainId must not be 0; a zero here means the chain id was never resolved"
192
+ );
193
+ const t = xe(e.registryAddress), r = ke(
194
+ "vaultProviderBtcKey",
195
+ e.vaultProviderBtcKey
196
+ );
197
+ if (B(
198
+ "appKeeperKeyEpoch",
199
+ e.appKeeperKeyEpoch,
200
+ D,
201
+ "uint64"
202
+ ), B("ucKeyEpoch", e.ucKeyEpoch, D, "uint64"), $("appVaultKeepersVersion", e.appVaultKeepersVersion), $(
203
+ "universalChallengersVersion",
204
+ e.universalChallengersVersion
205
+ ), $("offchainParamsVersion", e.offchainParamsVersion), $("vaultCoreVersion", e.vaultCoreVersion), e.vaultCoreVersion < L)
206
+ throw new f(
207
+ `vaultCoreVersion must be at least ${L}; ${e.vaultCoreVersion} means the version was never resolved`
208
+ );
209
+ return se(Ve, [
210
+ Ee,
211
+ e.chainId,
212
+ t,
213
+ r,
214
+ e.appKeeperKeyEpoch,
215
+ e.ucKeyEpoch,
216
+ e.appVaultKeepersVersion,
217
+ e.universalChallengersVersion,
218
+ e.offchainParamsVersion,
219
+ e.vaultCoreVersion
220
+ ]);
221
+ }
222
+ function Ye(e) {
223
+ return G($e(e));
224
+ }
225
+ class Te extends Error {
133
226
  constructor(t, r) {
134
227
  super(
135
228
  `Re-derived vault root does not match this Pre-PegIn: derived auth-anchor hash ${t}, transaction commits to ${r}. Connect the same wallet, on the same account and the same network, that created the deposit.`
136
229
  ), this.derivedAuthAnchorHash = t, this.onChainAuthAnchorHash = r, this.name = "VaultRootMismatchError";
137
230
  }
138
231
  }
139
- class B extends Error {
232
+ class K extends Error {
140
233
  constructor(t) {
141
234
  super(t), this.name = "UnanchoredPrePeginError";
142
235
  }
143
236
  }
144
- class he extends Error {
237
+ class Ae extends Error {
145
238
  constructor(t, r, n = []) {
146
239
  super(
147
240
  `No candidate parameter set reproduces this Pre-PegIn's HTLC outputs (${t} candidate(s) tried). ` + (n.length > 0 ? `${n.length} version(s) could not be resolved and may hold the answer: ${n.join(" | ")}. ` : "") + `Sample rejections: ${r.join(" | ")}`
148
241
  ), this.candidatesTried = t, this.sampleRejections = r, this.unresolvedLabels = n, this.name = "PeginParamsNotFoundError";
149
242
  }
150
243
  }
151
- class de extends Error {
244
+ class Ie extends Error {
152
245
  constructor(t) {
153
246
  super(
154
247
  `${t.length} candidate parameter sets reproduce this Pre-PegIn's HTLC outputs, so the vault's stamped versions cannot be determined: ${t.join(" | ")}. Reconstruction refused.`
155
248
  ), this.survivorLabels = t, this.name = "PeginParamsAmbiguousError";
156
249
  }
157
250
  }
158
- class me extends Error {
251
+ class Be extends Error {
159
252
  constructor(t, r) {
160
253
  super(
161
254
  `A candidate matched this Pre-PegIn (${t}), but ${r.length} version(s) could not be resolved, so the search space did not provably contain the true parameters: ${r.join(" | ")}. A version sharing the matched timelockRefund and participants is indistinguishable from the true one, so the match cannot be trusted. Reconstruction refused.`
162
255
  ), this.matchedLabel = t, this.unresolvedLabels = r, this.name = "PeginParamsIncompleteSpaceError";
163
256
  }
164
257
  }
165
- class $ extends Error {
258
+ class T extends Error {
166
259
  constructor(t) {
167
260
  super(`${t}. Reconstruction refused.`), this.name = "PeginSizingIntegrityError";
168
261
  }
169
262
  }
170
- async function Fe(e) {
171
- const { wallet: t, depositorBtcPubkey: r, fundedPrePeginTxHex: n } = e, h = P(n), c = F(h);
263
+ async function Ze(e) {
264
+ const { wallet: t, depositorBtcPubkey: r, fundedPrePeginTxHex: n } = e, h = P(n), c = M(h);
172
265
  if (c === void 0)
173
- throw new B(
266
+ throw new K(
174
267
  "Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN, so the number of HTLC outputs it funds cannot be determined. Legacy pre-anchor deposits are not recoverable by this path."
175
268
  );
176
269
  const u = c.vout;
177
270
  if (u === 0)
178
- throw new B(
271
+ throw new K(
179
272
  "Pre-PegIn's auth-anchor OP_RETURN is at vout 0, implying zero HTLC outputs; there is nothing to recover."
180
273
  );
181
- const l = se(h), i = await ae(t, {
274
+ const l = Pe(h), i = await fe(t, {
182
275
  // The vault context takes the 32-byte x-only key; a wallet's compressed
183
276
  // key would otherwise fail a byte-length check deep in the encoder with
184
277
  // nothing pointing back at the caller.
185
- depositorBtcPubkey: ee(
186
- z(r)
278
+ depositorBtcPubkey: he(
279
+ W(r)
187
280
  ),
188
281
  fundingOutpoints: l
189
282
  });
190
283
  try {
191
- const s = await oe(i);
284
+ const s = await ge(i);
192
285
  let a;
193
286
  try {
194
- a = te(G(s));
287
+ a = de(ce(s));
195
288
  } finally {
196
289
  s.fill(0);
197
290
  }
198
291
  if (a !== c.hash)
199
- throw new le(a, c.hash);
292
+ throw new Te(a, c.hash);
200
293
  } catch (s) {
201
294
  throw i.fill(0), s;
202
295
  }
203
- const { hashlocks: d } = await Z(i, u);
296
+ const { hashlocks: d } = await le(i, u);
204
297
  return { vaultCount: u, hashlocks: d, authAnchorHash: c.hash };
205
298
  }
206
- function He(e) {
299
+ function et(e) {
207
300
  const { vaultCoreVersion: t, offchainParams: r, participantKeySets: n } = e;
208
301
  if (!Number.isInteger(t) || t < 1)
209
302
  throw new Error(
@@ -227,21 +320,21 @@ function He(e) {
227
320
  });
228
321
  return h;
229
322
  }
230
- function pe(e) {
323
+ function Fe(e) {
231
324
  return `${e.axis} v${e.version} (${e.reason})`;
232
325
  }
233
- function A(e) {
326
+ function F(e) {
234
327
  const { participants: t } = e;
235
328
  return `core=${e.vaultCoreVersion} offchain=${e.offchainParams.version} keepers=${t.appVaultKeepersVersion} challengers=${t.universalChallengersVersion} vp=${t.vaultProvider}`;
236
329
  }
237
- const _ = 5;
238
- function ge(e, t) {
330
+ const j = 5;
331
+ function Ke(e, t) {
239
332
  return JSON.stringify(
240
333
  { terms: e, peginAmounts: t },
241
334
  (r, n) => typeof n == "bigint" ? `${n}` : n
242
335
  );
243
336
  }
244
- function Pe(e) {
337
+ function Me(e) {
245
338
  const { offchainParams: t, participants: r } = e;
246
339
  return [
247
340
  e.vaultCoreVersion,
@@ -253,9 +346,9 @@ function Pe(e) {
253
346
  t.minPeginFeeRate
254
347
  ].join("|");
255
348
  }
256
- async function fe(e) {
349
+ async function Se(e) {
257
350
  const { offchainParams: t, participants: r } = e, n = r.vaultKeeperBtcPubkeys.length, h = r.universalChallengerBtcPubkeys.length, [c, u, l] = await Promise.all([
258
- N(
351
+ Q(
259
352
  e.vaultCoreVersion,
260
353
  n,
261
354
  h,
@@ -263,29 +356,29 @@ async function fe(e) {
263
356
  t.councilSize,
264
357
  t.protocolFeeRate
265
358
  ),
266
- D(
359
+ X(
267
360
  e.vaultCoreVersion,
268
361
  n,
269
362
  h,
270
363
  t.minPeginFeeRate
271
364
  ),
272
- U(e.vaultCoreVersion)
365
+ q(e.vaultCoreVersion)
273
366
  ]), i = (l == null ? void 0 : l.value) ?? 0n;
274
367
  if (c <= 0n)
275
- throw new $(
368
+ throw new T(
276
369
  `WASM returned non-positive depositorClaimValue ${c} for graph version ${e.vaultCoreVersion}`
277
370
  );
278
371
  if (u <= 0n)
279
- throw new $(
372
+ throw new T(
280
373
  `WASM returned non-positive peginMaxFee ${u} for graph version ${e.vaultCoreVersion}`
281
374
  );
282
375
  if (i < 0n)
283
- throw new $(
376
+ throw new T(
284
377
  `WASM returned negative P2A anchor value ${i} for graph version ${e.vaultCoreVersion}`
285
378
  );
286
379
  return { depositorClaimValue: c, peginMaxFee: u, p2aAnchorValue: i };
287
380
  }
288
- async function Se(e) {
381
+ async function tt(e) {
289
382
  const {
290
383
  hashlocks: t,
291
384
  fundedPrePeginTxHex: r,
@@ -302,78 +395,78 @@ async function Se(e) {
302
395
  );
303
396
  if (l.length === 0)
304
397
  throw new Error("reconstructPeginParams: candidate space is empty");
305
- const d = z(n), s = P(r), a = F(s);
398
+ const d = W(n), s = P(r), a = M(s);
306
399
  if (a === void 0)
307
- throw new B(
400
+ throw new K(
308
401
  "Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN; the sibling set cannot be proven complete. Reconstruction refused."
309
402
  );
310
403
  if (a.vout !== t.length)
311
404
  throw new Error(
312
405
  `reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${a.vout}, so the transaction funds ${a.vout} HTLC output(s). Reconstruction refused.`
313
406
  );
314
- const f = j.fromHex(s).outs, w = t.map((m, p) => BigInt(f[p].value)), y = P(
315
- L(s)
316
- ).toLowerCase(), k = /* @__PURE__ */ new Map(), o = [], v = [], V = [];
317
- let H = 0;
407
+ const v = J.fromHex(s).outs, w = t.map((m, p) => BigInt(v[p].value)), C = P(
408
+ Y(s)
409
+ ).toLowerCase(), E = /* @__PURE__ */ new Map(), o = [], b = [], A = [];
410
+ let S = 0;
318
411
  for (const m of l)
319
412
  try {
320
- const p = Pe(m);
321
- let g = k.get(p);
322
- g === void 0 && (g = await fe(m), k.set(p, g));
323
- const C = g.depositorClaimValue + g.peginMaxFee + g.p2aAnchorValue, R = w.map((x) => x - C), E = R.findIndex((x) => x <= 0n);
324
- if (E !== -1)
325
- throw new K(
326
- `HTLC output[${E}] value ${w[E]} is not above this candidate's reserve ${C}, so it implies a non-positive pegin amount ${R[E]}.`
413
+ const p = Me(m);
414
+ let g = E.get(p);
415
+ g === void 0 && (g = await Se(m), E.set(p, g));
416
+ const R = g.depositorClaimValue + g.peginMaxFee + g.p2aAnchorValue, k = w.map((x) => x - R), V = k.findIndex((x) => x <= 0n);
417
+ if (V !== -1)
418
+ throw new z(
419
+ `HTLC output[${V}] value ${w[V]} is not above this candidate's reserve ${R}, so it implies a non-positive pegin amount ${k[V]}.`
327
420
  );
328
- const { offchainParams: b, participants: T } = m, M = await ue({
421
+ const { offchainParams: y, participants: I } = m, N = await ye({
329
422
  vaultCoreVersion: m.vaultCoreVersion,
330
- siblings: t.map((x, q) => ({
423
+ siblings: t.map((x, te) => ({
331
424
  hashlock: x,
332
- amount: R[q]
425
+ amount: k[te]
333
426
  })),
334
427
  fundedPrePeginTxHex: s,
335
428
  depositorBtcPubkey: d,
336
- vaultProviderBtcPubkey: T.vaultProviderBtcPubkey,
337
- vaultKeeperBtcPubkeys: T.vaultKeeperBtcPubkeys,
338
- universalChallengerBtcPubkeys: T.universalChallengerBtcPubkeys,
339
- protocolFeeRate: b.protocolFeeRate,
340
- minPeginFeeRate: b.minPeginFeeRate,
341
- councilQuorum: b.councilQuorum,
342
- councilSize: b.councilSize,
343
- timelockPegin: b.timelockPegin,
344
- timelockAssert: b.timelockAssert,
345
- timelockRefund: b.timelockRefund,
346
- prepeginTxid: y,
429
+ vaultProviderBtcPubkey: I.vaultProviderBtcPubkey,
430
+ vaultKeeperBtcPubkeys: I.vaultKeeperBtcPubkeys,
431
+ universalChallengerBtcPubkeys: I.universalChallengerBtcPubkeys,
432
+ protocolFeeRate: y.protocolFeeRate,
433
+ minPeginFeeRate: y.minPeginFeeRate,
434
+ councilQuorum: y.councilQuorum,
435
+ councilSize: y.councilSize,
436
+ timelockPegin: y.timelockPegin,
437
+ timelockAssert: y.timelockAssert,
438
+ timelockRefund: y.timelockRefund,
439
+ prepeginTxid: C,
347
440
  prepeginMaxFee: h,
348
441
  maxAcceptableCommissionBps: c,
349
442
  network: u
350
443
  });
351
444
  o.push({
352
445
  candidate: m,
353
- terms: M,
354
- peginAmounts: R,
355
- fingerprint: ge(M, R)
446
+ terms: N,
447
+ peginAmounts: k,
448
+ fingerprint: Ke(N, k)
356
449
  });
357
450
  } catch (p) {
358
- if (p instanceof $)
451
+ if (p instanceof T)
359
452
  throw p;
360
- const g = A(m), C = p instanceof Error ? p.message : String(p);
361
- p instanceof K ? v.length < _ && v.push(`[${g}] ${C}`) : (H++, V.length < _ && V.push(`${g} (${C})`));
453
+ const g = F(m), R = p instanceof Error ? p.message : String(p);
454
+ p instanceof z ? b.length < j && b.push(`[${g}] ${R}`) : (S++, A.length < j && A.push(`${g} (${R})`));
362
455
  }
363
- const Q = i.length + H, S = [
364
- ...i.map(pe),
365
- ...V
456
+ const ee = i.length + S, H = [
457
+ ...i.map(Fe),
458
+ ...A
366
459
  ];
367
460
  if (o.length === 0)
368
- throw new he(l.length, v, S);
461
+ throw new Ae(l.length, b, H);
369
462
  if (new Set(o.map((m) => m.fingerprint)).size > 1)
370
- throw new de(
371
- o.map((m) => A(m.candidate))
463
+ throw new Ie(
464
+ o.map((m) => F(m.candidate))
372
465
  );
373
- if (Q > 0)
374
- throw new me(
375
- A(o[0].candidate),
376
- S
466
+ if (ee > 0)
467
+ throw new Be(
468
+ F(o[0].candidate),
469
+ H
377
470
  );
378
471
  return {
379
472
  candidate: o[0].candidate,
@@ -384,7 +477,7 @@ async function Se(e) {
384
477
  matchedCandidates: o.map((m) => m.candidate)
385
478
  };
386
479
  }
387
- function Me(e, t) {
480
+ function rt(e, t) {
388
481
  const {
389
482
  htlcVout: r,
390
483
  depositorBtcPubkey: n,
@@ -401,13 +494,13 @@ function Me(e, t) {
401
494
  throw new Error(
402
495
  `toRefundInputs: htlcVout ${r} is outside the reconstructed batch of ${d.length} vault(s).`
403
496
  );
404
- const f = d.map((k, o) => ({
405
- hashlock: re(u[o]),
406
- amount: k,
497
+ const v = d.map((E, o) => ({
498
+ hashlock: me(u[o]),
499
+ amount: E,
407
500
  htlcVout: o
408
501
  })), w = {
409
502
  vaultCoreVersion: i.vaultCoreVersion,
410
- hashlock: f[r].hashlock,
503
+ hashlock: v[r].hashlock,
411
504
  htlcVout: r,
412
505
  offchainParamsVersion: s.version,
413
506
  appVaultKeepersVersion: a.appVaultKeepersVersion,
@@ -417,8 +510,8 @@ function Me(e, t) {
417
510
  amount: d[r],
418
511
  unsignedPrePeginTxHex: c,
419
512
  depositorBtcPubkey: n,
420
- batch: f
421
- }, y = {
513
+ batch: v
514
+ }, C = {
422
515
  vaultProviderPubkey: a.vaultProviderBtcPubkey,
423
516
  vaultKeeperPubkeys: a.vaultKeeperBtcPubkeys,
424
517
  universalChallengerPubkeys: a.universalChallengerBtcPubkeys,
@@ -432,25 +525,30 @@ function Me(e, t) {
432
525
  councilSize: s.councilSize,
433
526
  network: l
434
527
  };
435
- return { vault: w, context: y };
528
+ return { vault: w, context: C };
436
529
  }
437
530
  export {
438
- W as D,
439
- he as P,
440
- B as U,
441
- le as V,
442
- ce as a,
443
- Ae as b,
444
- He as c,
445
- Fe as d,
446
- pe as e,
447
- A as f,
448
- Se as g,
449
- de as h,
450
- Be as i,
451
- me as j,
452
- $ as k,
453
- ue as r,
454
- Me as t
531
+ Z as D,
532
+ Ee as P,
533
+ K as U,
534
+ Te as V,
535
+ we as a,
536
+ f as b,
537
+ Ye as c,
538
+ be as d,
539
+ $e as e,
540
+ qe as f,
541
+ Ze as g,
542
+ et as h,
543
+ Je as i,
544
+ Fe as j,
545
+ F as k,
546
+ tt as l,
547
+ Ae as m,
548
+ Ie as n,
549
+ Be as o,
550
+ T as p,
551
+ ye as r,
552
+ rt as t
455
553
  };
456
- //# sourceMappingURL=toRefundInputs-BkcFhvDp.js.map
554
+ //# sourceMappingURL=toRefundInputs-BNSXIymn.js.map