@babylonlabs-io/ts-sdk 3.1.2 → 3.2.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 (88) hide show
  1. package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs +2 -0
  2. package/dist/BTCVaultRegistry.abi-BH2-LHxN.cjs.map +1 -0
  3. package/dist/{BTCVaultRegistry.abi-BmHpMUWD.js → BTCVaultRegistry.abi-BzNTa_EU.js} +19 -1
  4. package/dist/BTCVaultRegistry.abi-BzNTa_EU.js.map +1 -0
  5. package/dist/{PeginManager-PyKbfy5q.cjs → PeginManager-BHplS4dM.cjs} +2 -2
  6. package/dist/{PeginManager-PyKbfy5q.cjs.map → PeginManager-BHplS4dM.cjs.map} +1 -1
  7. package/dist/{PeginManager-Dfr5Qe1g.js → PeginManager-DcwGom01.js} +2 -2
  8. package/dist/{PeginManager-Dfr5Qe1g.js.map → PeginManager-DcwGom01.js.map} +1 -1
  9. package/dist/buildAndBroadcastReclaim-C7bq5wNM.cjs +2 -0
  10. package/dist/buildAndBroadcastReclaim-C7bq5wNM.cjs.map +1 -0
  11. package/dist/{buildAndBroadcastReclaim-R0HNpLMD.js → buildAndBroadcastReclaim-CcQ0b1be.js} +466 -456
  12. package/dist/buildAndBroadcastReclaim-CcQ0b1be.js.map +1 -0
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.js +74 -74
  15. package/dist/pegin-registration-client-BogzOk8B.cjs +2 -0
  16. package/dist/pegin-registration-client-BogzOk8B.cjs.map +1 -0
  17. package/dist/{pegin-registration-client-kdz4fT5_.js → pegin-registration-client-DvyrUNku.js} +44 -43
  18. package/dist/pegin-registration-client-DvyrUNku.js.map +1 -0
  19. package/dist/peginState-CIibG9S_.js +75 -0
  20. package/dist/peginState-CIibG9S_.js.map +1 -0
  21. package/dist/peginState-IyE22wWh.cjs +2 -0
  22. package/dist/peginState-IyE22wWh.cjs.map +1 -0
  23. package/dist/{reservation-DOAHVT3B.js → reservation-BZQABu4g.js} +2 -2
  24. package/dist/{reservation-DOAHVT3B.js.map → reservation-BZQABu4g.js.map} +1 -1
  25. package/dist/{reservation-ECxjZi5t.cjs → reservation-CA5knoQ0.cjs} +2 -2
  26. package/dist/{reservation-ECxjZi5t.cjs.map → reservation-CA5knoQ0.cjs.map} +1 -1
  27. package/dist/{signer-set-reader-DFAu6I-v.cjs → signer-set-reader-D-CyIYR5.cjs} +2 -2
  28. package/dist/{signer-set-reader-DFAu6I-v.cjs.map → signer-set-reader-D-CyIYR5.cjs.map} +1 -1
  29. package/dist/{signer-set-reader-BCtmSKUM.js → signer-set-reader-DFF9MgQN.js} +2 -2
  30. package/dist/{signer-set-reader-BCtmSKUM.js.map → signer-set-reader-DFF9MgQN.js.map} +1 -1
  31. package/dist/tbv/core/clients/eth/index.cjs +1 -1
  32. package/dist/tbv/core/clients/eth/index.js +2 -2
  33. package/dist/tbv/core/clients/eth/types.d.ts +8 -0
  34. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  35. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  36. package/dist/tbv/core/clients/index.cjs +1 -1
  37. package/dist/tbv/core/clients/index.js +2 -2
  38. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +14 -0
  39. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  40. package/dist/tbv/core/contracts/index.cjs +1 -1
  41. package/dist/tbv/core/contracts/index.js +1 -1
  42. package/dist/tbv/core/index.cjs +1 -1
  43. package/dist/tbv/core/index.js +84 -84
  44. package/dist/tbv/core/managers/index.cjs +1 -1
  45. package/dist/tbv/core/managers/index.js +1 -1
  46. package/dist/tbv/core/services/activation/activateVault.d.ts +50 -0
  47. package/dist/tbv/core/services/activation/activateVault.d.ts.map +1 -1
  48. package/dist/tbv/core/services/activation/index.d.ts +1 -1
  49. package/dist/tbv/core/services/activation/index.d.ts.map +1 -1
  50. package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts +9 -0
  51. package/dist/tbv/core/services/delegated-claim/__tests__/realWasmWatchtowerArtifacts.test.d.ts.map +1 -0
  52. package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts +5 -7
  53. package/dist/tbv/core/services/delegated-claim/assembleWatchtowerArtifacts.d.ts.map +1 -1
  54. package/dist/tbv/core/services/delegated-claim/index.d.ts +3 -4
  55. package/dist/tbv/core/services/delegated-claim/index.d.ts.map +1 -1
  56. package/dist/tbv/core/services/delegated-claim/planDelegatedClaimSigning.d.ts.map +1 -1
  57. package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts +14 -8
  58. package/dist/tbv/core/services/delegated-claim/readWatchtowerArtifacts.d.ts.map +1 -1
  59. package/dist/tbv/core/services/delegated-claim/types.d.ts +32 -19
  60. package/dist/tbv/core/services/delegated-claim/types.d.ts.map +1 -1
  61. package/dist/tbv/core/services/deposit/peginState.d.ts +20 -1
  62. package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
  63. package/dist/tbv/core/services/index.cjs +1 -1
  64. package/dist/tbv/core/services/index.js +58 -58
  65. package/dist/tbv/core/utils/index.cjs +1 -1
  66. package/dist/tbv/core/utils/index.js +1 -1
  67. package/dist/tbv/index.cjs +1 -1
  68. package/dist/tbv/index.js +84 -84
  69. package/dist/{toRefundInputs-BbAOOUg6.cjs → toRefundInputs-8DgBT_Bg.cjs} +2 -2
  70. package/dist/{toRefundInputs-BbAOOUg6.cjs.map → toRefundInputs-8DgBT_Bg.cjs.map} +1 -1
  71. package/dist/{toRefundInputs-DW14g6wH.js → toRefundInputs-CCMNAoRx.js} +2 -2
  72. package/dist/{toRefundInputs-DW14g6wH.js.map → toRefundInputs-CCMNAoRx.js.map} +1 -1
  73. package/dist/types-Bda75Od0.cjs.map +1 -1
  74. package/dist/types-C5jj3Cc-.js.map +1 -1
  75. package/package.json +1 -1
  76. package/dist/BTCVaultRegistry.abi-BmHpMUWD.js.map +0 -1
  77. package/dist/BTCVaultRegistry.abi-DffWFdpA.cjs +0 -2
  78. package/dist/BTCVaultRegistry.abi-DffWFdpA.cjs.map +0 -1
  79. package/dist/buildAndBroadcastReclaim-Da8rD5Z7.cjs +0 -2
  80. package/dist/buildAndBroadcastReclaim-Da8rD5Z7.cjs.map +0 -1
  81. package/dist/buildAndBroadcastReclaim-R0HNpLMD.js.map +0 -1
  82. package/dist/pegin-registration-client-C-abxMWq.cjs +0 -2
  83. package/dist/pegin-registration-client-C-abxMWq.cjs.map +0 -1
  84. package/dist/pegin-registration-client-kdz4fT5_.js.map +0 -1
  85. package/dist/peginState-BU2ONFXF.js +0 -68
  86. package/dist/peginState-BU2ONFXF.js.map +0 -1
  87. package/dist/peginState-DUv10EJR.cjs +0 -2
  88. package/dist/peginState-DUv10EJR.cjs.map +0 -1
package/dist/tbv/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { P as s, h as r, i as t, j as i, f as o, b as n, a as l, c as p, k as E, d as P, e as c, g as u } from "../verifyScriptPathSchnorrSignature-B3-VkvnK.js";
2
2
  import { a as g } from "../secp256k1-BuxBFUHm.js";
3
- import { attachFinalizedAssert as R, computeMinClaimValue as A, computeMinPeginFee as _, deriveVaultId as S, expandAuthAnchor as T, expandHashlockSecret as C, expandWotsSeed as I, finalizePayout as f, finalizeWronglyChallenged as h, peginP2aAnchorOutput as O, pinPegoutProof as V, supportedTxGraphVersions as b, validatePeginP2aAnchor as x } from "./core/wasm/index.js";
4
- import { a as N, c as M, b as y, e as D, f as v } from "../verifyKeyPathSchnorrSignature-DxPbeSdQ.js";
3
+ import { attachFinalizedAssert as R, computeMinClaimValue as A, computeMinPeginFee as _, deriveVaultId as S, expandAuthAnchor as T, expandHashlockSecret as C, expandWotsSeed as I, finalizePayout as f, finalizeWronglyChallenged as h, peginP2aAnchorOutput as V, pinPegoutProof as O, supportedTxGraphVersions as x, validatePeginP2aAnchor as b } from "./core/wasm/index.js";
4
+ import { a as N, c as M, b as y, e as v, f as D } from "../verifyKeyPathSchnorrSignature-DxPbeSdQ.js";
5
5
  import { c as U, a as H, b as L, e as K, f as X, r as G } from "../noPayout-B-vGXJ-V.js";
6
6
  import { b as W } from "../challengeAssert-Cp_GeRg8.js";
7
7
  import { c as z, d as Y, a as j, b as J, e as Z, f as q, k as Q, g as $, h as aa, i as ea, j as sa, p as ra, s as ta, t as ia, u as oa, v as na } from "../bitcoin-C-TuHb-v.js";
@@ -9,16 +9,16 @@ import { c as pa } from "../abortSignals-BPpAUL1Z.js";
9
9
  import { c as Pa, a as ca } from "../signing-C1rR4tqs.js";
10
10
  import { B as da, C as ga, H as ma, K as Ra, M as Aa, T as _a, X as Sa } from "../validation-OSC0xTHB.js";
11
11
  import { waitForTransactionReceiptSmartAware as Ca } from "./core/utils/eth/index.js";
12
- import { P as fa, b as ha, c as Oa, d as Va, e as ba } from "../PeginManager-Dfr5Qe1g.js";
13
- import { P as Fa, c as Na, f as Ma, r as ya, s as Da, v as va } from "../PayoutManager-BZ212yml.js";
12
+ import { P as fa, b as ha, c as Va, d as Oa, e as xa } from "../PeginManager-DcwGom01.js";
13
+ import { P as Fa, c as Na, f as Ma, r as ya, s as va, v as Da } from "../PayoutManager-BZ212yml.js";
14
14
  import { MEMPOOL_API_URLS as Ua, MempoolNotFoundError as Ha, getAddressTxs as La, getAddressUtxos as Ka, getMempoolApiUrl as Xa, getNetworkFees as Ga, getOutspend as ka, getTipHeight as Wa, getTxHex as wa, getTxInfo as za, getUtxoInfo as Ya, pushTx as ja } from "./core/clients/mempool/index.js";
15
15
  import { R as Za, V as qa, a as Qa, f as $a, d as ae, g as ee, e as se, i as re, r as te, v as ie, b as oe, c as ne } from "../registration-records-CKLAv3gw.js";
16
- import { V as pe, a as Ee, b as Pe, r as ce } from "../signer-set-reader-BCtmSKUM.js";
17
- import { C as de, M as ge, V as me, a as Re, c as Ae } from "../pegin-registration-client-kdz4fT5_.js";
16
+ import { V as pe, a as Ee, b as Pe, r as ce } from "../signer-set-reader-DFF9MgQN.js";
17
+ import { C as de, M as ge, V as me, a as Re, c as Ae } from "../pegin-registration-client-DvyrUNku.js";
18
18
  import { O as Se, V as Te } from "../types-C5jj3Cc-.js";
19
19
  import { A as Ie } from "../ApplicationRegistry.abi-s8cQ1ooR.js";
20
- import { B as he } from "../BTCVaultRegistry.abi-BmHpMUWD.js";
21
- import { B as Ve, C as be, E as xe, P as Fe, a as Ne, e as Me, g as ye, h as De, i as ve, b as Be } from "../BTCVaultRegistryKeyEpochs.abi-Btg0nBz1.js";
20
+ import { B as he } from "../BTCVaultRegistry.abi-BzNTa_EU.js";
21
+ import { B as Oe, C as xe, E as be, P as Fe, a as Ne, e as Me, g as ye, h as ve, i as De, b as Be } from "../BTCVaultRegistryKeyEpochs.abi-Btg0nBz1.js";
22
22
  import { P as He } from "../ProtocolParams.abi-CKOVqFJP.js";
23
23
  import { V as Ke } from "../VaultErrors.abi-Boz4w97c.js";
24
24
  import { b as Ge } from "../buildVaultContextInputForClaim-DhBoQKyN.js";
@@ -27,40 +27,39 @@ import { p as Ze } from "../parseFundingOutpoints-GSM-IaaK.js";
27
27
  import { c as Qe } from "../btcTxHash-BRZ8_EZq.js";
28
28
  import { B as as, a as es, c as ss, b as rs, d as ts, g as is, h as os, f as ns, s as ls, e as ps } from "../psbtInputFields-CCVyaQMi.js";
29
29
  import { B as Ps, D as cs, L as us, M as ds, c as gs, P as ms, b as Rs, a as As, S as _s, T as Ss, W as Ts, f as Cs, d as Is, p as fs, r as hs } from "../fundPeginTransaction-CwhRbCQC.js";
30
- import { U as Vs, a as bs, e as xs, f as Fs, v as Ns } from "../reservation-DOAHVT3B.js";
31
- import { V as ys, a as Ds, b as vs, i as Bs, v as Us } from "../index-CVBtBjQ5.js";
30
+ import { U as Os, a as xs, e as bs, f as Fs, v as Ns } from "../reservation-BZQABu4g.js";
31
+ import { V as ys, a as vs, b as Ds, i as Bs, v as Us } from "../index-CVBtBjQ5.js";
32
32
  import { A as Ls, C as Ks, D as Xs, J as Gs, a as ks, b as Ws, d as ws, P as zs, R as Ys, e as js, c as Js, V as Zs, i as qs, g as Qs, f as $s } from "../state-CFn1rT74.js";
33
33
  import { S as er, V as sr, c as rr, p as tr, v as ir, a as or } from "../primeVpAuth-CiCdRNGf.js";
34
- import { D as lr, g as pr, P as Er, a as Pr, b as cr, u as ur, v as dr, t as gr, w as mr, U as Rr, V as Ar, f as _r, m as Sr, j as Tr, c as Cr, l as Ir, p as fr, n as hr, e as Or, h as Vr, d as br, i as xr, o as Fr, r as Nr, k as Mr, q as yr, s as Dr, x as vr } from "../toRefundInputs-DW14g6wH.js";
35
- import { J as Ur, k as Hr, A as Lr, B as Kr, a8 as Xr, C as Gr, D as kr, m as Wr, G as wr, t as zr, W as Yr, P as jr, i as Jr, u as Zr, v as qr, ah as Qr, ai as $r, aj as at, ak as et, ab as st, ac as rt, ad as tt, ae as it, af as ot, Z as nt, S as lt, V as pt, a as Et, b as Pt, c as ct, d as ut, l as dt, e as gt, f as mt, q as Rt, h as At, z as _t, n as St, a1 as Tt, ag as Ct, a9 as It, j as ft, g as ht, aa as Ot, E as Vt, K as bt, M as xt, a2 as Ft, X as Nt, w as Mt, x as yt, _ as Dt, a3 as vt, a4 as Bt, p as Ut, r as Ht, a5 as Lt, a6 as Kt, a7 as Xt, F as Gt, o as kt, H as Wt, I as wt, s as zt, N as Yt, O as jt, L as Jt, Q as Zt, R as qt, T as Qt, U as $t, Y as ai, $ as ei, y as si, a0 as ri } from "../buildAndBroadcastReclaim-R0HNpLMD.js";
36
- import { C as ii, P as oi, a as ni, c as li, g as pi, i as Ei } from "../peginState-BU2ONFXF.js";
34
+ import { D as lr, g as pr, P as Er, a as Pr, b as cr, u as ur, v as dr, t as gr, w as mr, U as Rr, V as Ar, f as _r, m as Sr, j as Tr, c as Cr, l as Ir, p as fr, n as hr, e as Vr, h as Or, d as xr, i as br, o as Fr, r as Nr, k as Mr, q as yr, s as vr, x as Dr } from "../toRefundInputs-CCMNAoRx.js";
35
+ import { J as Ur, l as Hr, A as Lr, a8 as Kr, C as Xr, D as Gr, n as kr, G as Wr, u as wr, W as zr, P as Yr, j as jr, v as Jr, w as Zr, ah as qr, ai as Qr, aj as $r, ak as at, ab as et, ac as st, ad as rt, ae as tt, af as it, Z as ot, S as nt, V as lt, a as pt, b as Et, d as Pt, e as ct, m as ut, f as dt, g as gt, t as mt, i as Rt, B as At, o as _t, a1 as St, ag as Tt, a9 as Ct, c as It, k as ft, h as ht, aa as Vt, E as Ot, K as xt, M as bt, a2 as Ft, X as Nt, x as Mt, y as yt, _ as vt, a3 as Dt, a4 as Bt, p as Ut, r as Ht, a5 as Lt, a6 as Kt, a7 as Xt, F as Gt, q as kt, H as Wt, I as wt, s as zt, N as Yt, O as jt, L as Jt, Q as Zt, R as qt, T as Qt, U as $t, Y as ai, $ as ei, z as si, a0 as ri } from "../buildAndBroadcastReclaim-CcQ0b1be.js";
36
+ import { C as ii, P as oi, a as ni, c as li, g as pi, i as Ei } from "../peginState-CIibG9S_.js";
37
37
  export {
38
38
  Ls as AUTH_REJECTED_RPC_CODE,
39
39
  Ur as ApplicationEntryPointMismatchError,
40
40
  Ie as ApplicationRegistryABI,
41
41
  Hr as ArtifactsVaultMismatchError,
42
42
  Lr as AssertBindingError,
43
- Kr as BABE_SESSION_PLACEHOLDER_DECRYPTOR_HEX,
44
- Xr as BIP68NotMatureError,
43
+ Kr as BIP68NotMatureError,
45
44
  da as BITCOIN_ADDRESS_RE,
46
45
  he as BTCVaultRegistryABI,
47
- Ve as BTCVaultRegistryKeyEpochsABI,
46
+ Oe as BTCVaultRegistryKeyEpochsABI,
48
47
  Ps as BTC_DUST_SAT,
49
48
  as as BitcoinScriptType,
50
49
  de as COMMISSION_BPS_HEADROOM,
51
50
  ga as COMPRESSED_PUBKEY_HEX_LEN,
52
- be as CONTRACT_ERRORS,
53
- Gr as ChallengerSetMismatchError,
51
+ xe as CONTRACT_ERRORS,
52
+ Xr as ChallengerSetMismatchError,
54
53
  Ks as ClaimerPegoutStatusValue,
55
54
  ii as ContractStatus,
56
- kr as DELEGATED_CLAIM_TX_GRAPH_VERSION,
55
+ Gr as DELEGATED_CLAIM_TX_GRAPH_VERSION,
57
56
  lr as DEPOSIT_TERMS_REJECTED_ERROR_NAME,
58
57
  cs as DUST_THRESHOLD,
59
58
  Xs as DaemonStatus,
60
- Wr as DelegatedClaimSigningIncompleteError,
59
+ kr as DelegatedClaimSigningIncompleteError,
61
60
  pr as DepositTermsRejectedError,
62
- xe as EMPTY_REVERT_MESSAGE,
63
- wr as GraphFingerprintError,
61
+ be as EMPTY_REVERT_MESSAGE,
62
+ Wr as GraphFingerprintError,
64
63
  ma as HEX_RE,
65
64
  Gs as JSON_RPC_ERROR_CODES,
66
65
  ks as JsonRpcClient,
@@ -77,16 +76,16 @@ export {
77
76
  ms as P2TR_INPUT_SIZE,
78
77
  Rs as PEGIN_AUTH_ANCHOR_OUTPUTS,
79
78
  s as PEGIN_DEPOSITOR_CLAIM_VOUT,
80
- zr as PEGIN_ETH_CONFIRMATIONS,
79
+ wr as PEGIN_ETH_CONFIRMATIONS,
81
80
  Fe as PEGIN_FINGERPRINT_CHANGED_SELECTOR,
82
81
  Er as PEGIN_FINGERPRINT_DOMAIN,
83
82
  Pr as PEGIN_FINGERPRINT_DOMAIN_PREIMAGE,
84
83
  As as PEGIN_FIXED_OUTPUTS,
85
84
  ws as POST_WOTS_STATUSES,
86
85
  zs as PRE_DEPOSITOR_SIGNATURES_STATES,
87
- Yr as ParticipantKeyDriftError,
88
- jr as PayoutDestinationError,
89
- Jr as PayoutInputLeafError,
86
+ zr as ParticipantKeyDriftError,
87
+ Yr as PayoutDestinationError,
88
+ jr as PayoutInputLeafError,
90
89
  Fa as PayoutManager,
91
90
  oi as PeginAction,
92
91
  Ne as PeginFingerprintChangedError,
@@ -95,37 +94,37 @@ export {
95
94
  ur as PeginParamsAmbiguousError,
96
95
  dr as PeginParamsIncompleteSpaceError,
97
96
  gr as PeginParamsNotFoundError,
98
- Zr as PeginRegistrationMissingError,
99
- qr as PeginRegistrationNotFinalError,
97
+ Jr as PeginRegistrationMissingError,
98
+ Zr as PeginRegistrationNotFinalError,
100
99
  mr as PeginSizingIntegrityError,
101
100
  He as ProtocolParamsABI,
102
101
  r as PsbtSubstitutionError,
103
- Qr as RECLAIM_MAX_FEE_FRACTION_DENOMINATOR,
104
- $r as RECLAIM_MAX_FEE_FRACTION_NUMERATOR,
105
- at as RECLAIM_MAX_FEE_RATE_SATS_VB,
106
- et as RECLAIM_WARN_FEE_FRACTION_NUMERATOR,
107
- st as REFUND_MAX_FEE_FRACTION_DENOMINATOR,
108
- rt as REFUND_MAX_FEE_FRACTION_NUMERATOR,
109
- tt as REFUND_MAX_FEE_RATE_SATS_VB,
110
- it as REFUND_VSIZE,
111
- ot as ReclaimUneconomicalError,
112
- nt as RegisteredVaultVersionMismatchError,
102
+ qr as RECLAIM_MAX_FEE_FRACTION_DENOMINATOR,
103
+ Qr as RECLAIM_MAX_FEE_FRACTION_NUMERATOR,
104
+ $r as RECLAIM_MAX_FEE_RATE_SATS_VB,
105
+ at as RECLAIM_WARN_FEE_FRACTION_NUMERATOR,
106
+ et as REFUND_MAX_FEE_FRACTION_DENOMINATOR,
107
+ st as REFUND_MAX_FEE_FRACTION_NUMERATOR,
108
+ rt as REFUND_MAX_FEE_RATE_SATS_VB,
109
+ tt as REFUND_VSIZE,
110
+ it as ReclaimUneconomicalError,
111
+ ot as RegisteredVaultVersionMismatchError,
113
112
  Za as RegistrationLogsUnavailableError,
114
113
  Ys as RpcErrorCode,
115
114
  _s as SPLIT_TX_FEE_SAFETY_MULTIPLIER,
116
115
  er as ServerIdentityError,
117
- lt as SigningPlanMismatchError,
116
+ nt as SigningPlanMismatchError,
118
117
  _a as TXID_RE,
119
118
  Ss as TX_BUFFER_SIZE_OVERHEAD,
120
119
  Rr as UnanchoredPrePeginError,
121
- Vs as UtxoNotAvailableError,
120
+ Os as UtxoNotAvailableError,
122
121
  We as VAULT_APP_NAME,
123
122
  Ke as VAULT_ERROR_ABI,
124
123
  js as VP_BATCH_MAX_SIZE,
125
124
  Js as VP_TERMINAL_FAILURE_STATUSES,
126
125
  Zs as VP_TRANSIENT_STATUSES,
127
126
  qa as VaultClaimableByNotFoundError,
128
- pt as VaultIdBindingError,
127
+ lt as VaultIdBindingError,
129
128
  ys as VaultProviderRpcClient,
130
129
  Ar as VaultRootMismatchError,
131
130
  pe as ViemOperationKeyReader,
@@ -134,37 +133,37 @@ export {
134
133
  Ee as ViemUniversalChallengerReader,
135
134
  Pe as ViemVaultKeeperReader,
136
135
  Re as ViemVaultRegistryReader,
137
- Ds as VpResponseValidationError,
136
+ vs as VpResponseValidationError,
138
137
  sr as VpTokenRegistry,
139
138
  Ts as WALLET_RELAY_FEE_RATE_THRESHOLD,
140
139
  Sa as X_ONLY_PUBKEY_HEX_LEN,
141
- Et as activateVault,
142
- Pt as activateVaultAndRedeem,
140
+ pt as activateVault,
141
+ Et as activateVaultAndRedeem,
143
142
  ni as activationDeadlineBlocksRemaining,
144
143
  es as applyChangeOutputPolicy,
145
- ct as assembleWatchtowerArtifacts,
146
- ut as assembleWatchtowerArtifactsFromSignatures,
147
- dt as assertArtifactsUsableForVault,
148
- gt as assertAssertBindsClaimAndPayout,
149
- mt as assertChallengerSetMatchesVault,
144
+ Pt as assembleWatchtowerArtifacts,
145
+ ct as assembleWatchtowerArtifactsFromSignatures,
146
+ ut as assertArtifactsUsableForVault,
147
+ dt as assertAssertBindsClaimAndPayout,
148
+ gt as assertChallengerSetMatchesVault,
150
149
  _r as assertClaimBatchHomogeneous,
151
- Rt as assertClaimSpendsVault,
150
+ mt as assertClaimSpendsVault,
152
151
  N as assertKeyPathSchnorrSignature,
153
152
  Qa as assertOnChainBtcPubkey,
154
- At as assertPayoutPaysRegisteredScript,
153
+ Rt as assertPayoutPaysRegisteredScript,
155
154
  t as assertPsbtUnsignedTxMatches,
156
155
  $a as assertRegisteredPayoutScriptBounds,
157
- _t as assertReturnedGraphMatchesFingerprint,
156
+ At as assertReturnedGraphMatchesFingerprint,
158
157
  M as assertReturnedKeyPathSignatures,
159
158
  i as assertScriptPathSchnorrSignature,
160
- St as assertTermsMatchVault,
161
- bs as assertUtxosAvailable,
159
+ _t as assertTermsMatchVault,
160
+ xs as assertUtxosAvailable,
162
161
  g as assertValidVaultCoreVersion,
163
- Tt as assertVaultProviderHintAccepted,
162
+ St as assertVaultProviderHintAccepted,
164
163
  R as attachFinalizedAssert,
165
- vs as batchPollByProvider,
166
- Ct as buildAndBroadcastReclaim,
167
- It as buildAndBroadcastRefund,
164
+ Ds as batchPollByProvider,
165
+ Tt as buildAndBroadcastReclaim,
166
+ Ct as buildAndBroadcastRefund,
168
167
  W as buildChallengeAssertPsbt,
169
168
  ha as buildDepositTerms,
170
169
  we as buildFundingOutpointsCommitment,
@@ -182,6 +181,7 @@ export {
182
181
  li as canPerformAction,
183
182
  z as canonicalizeBtcPubkey,
184
183
  Ae as capMaxAcceptableCommissionBps,
184
+ It as claimExpiredVault,
185
185
  pa as combineAbortSignals,
186
186
  ss as computeChangeOutputFeeSats,
187
187
  Tr as computeFundedPrePeginFee,
@@ -192,7 +192,7 @@ export {
192
192
  p as computeNumLocalChallengers,
193
193
  ts as computePeginBaseFeeSats,
194
194
  Cr as computePeginFingerprint,
195
- Oa as computeWotsBlockPublicKeysHash,
195
+ Va as computeWotsBlockPublicKeysHash,
196
196
  ft as copyAssertConnectorLeaf,
197
197
  rr as createAuthenticatedVpClient,
198
198
  E as createPayoutScript,
@@ -208,28 +208,28 @@ export {
208
208
  J as deriveTaprootAddress,
209
209
  S as deriveVaultId,
210
210
  Ye as deriveVaultRoot,
211
- Va as deriveWotsBlocksFromSeed,
211
+ Oa as deriveWotsBlocksFromSeed,
212
212
  fr as describePeginParamsCandidate,
213
213
  hr as describeUnresolvedVersion,
214
- Or as encodePeginFingerprintPreimage,
214
+ Vr as encodePeginFingerprintPreimage,
215
215
  Z as ensureHexPrefix,
216
- ba as ensurePrePeginTermsApproval,
216
+ xa as ensurePrePeginTermsApproval,
217
217
  K as estimateReclaimFeeSats,
218
- Ot as estimateRefundFeeSats,
218
+ Vt as estimateRefundFeeSats,
219
219
  T as expandAuthAnchor,
220
220
  C as expandHashlockSecret,
221
221
  I as expandWotsSeed,
222
222
  Me as extractErrorData,
223
- xs as extractInputsFromTransaction,
223
+ bs as extractInputsFromTransaction,
224
224
  u as extractPayoutSignature,
225
- D as extractPeginInputSignature,
225
+ v as extractPeginInputSignature,
226
226
  f as finalizePayout,
227
- v as finalizePeginInputPsbt,
227
+ D as finalizePeginInputPsbt,
228
228
  X as finalizeScriptPathWithSignatures,
229
229
  h as finalizeWronglyChallenged,
230
230
  Fs as findOverlappingPendingVaults,
231
231
  ee as findRegistrationRecord,
232
- Vt as fingerprintReturnedGraph,
232
+ Ot as fingerprintReturnedGraph,
233
233
  q as formatSatoshisToBtc,
234
234
  Ma as forwardDepositApproval,
235
235
  je as forwardDeriveContextHash,
@@ -250,37 +250,37 @@ export {
250
250
  wa as getTxHex,
251
251
  za as getTxInfo,
252
252
  Ya as getUtxoInfo,
253
- De as handleContractError,
253
+ ve as handleContractError,
254
254
  aa as hexToUint8Array,
255
255
  Ei as isActivationDeadlinePassedOnChain,
256
256
  ea as isAddressFromPublicKey,
257
- bt as isApplicationEntryPointMismatchError,
257
+ xt as isApplicationEntryPointMismatchError,
258
258
  qs as isAuthRejectedError,
259
- xt as isDepositAmountValid,
260
- Vr as isDepositTermsRejectedError,
259
+ bt as isDepositAmountValid,
260
+ Or as isDepositTermsRejectedError,
261
261
  Ft as isHintAccepted,
262
- ve as isKnownContractError,
262
+ De as isKnownContractError,
263
263
  Nt as isParticipantKeyDriftError,
264
264
  Be as isPeginFingerprintChangedError,
265
- br as isPeginFingerprintInputError,
265
+ xr as isPeginFingerprintInputError,
266
266
  Mt as isPeginRegistrationMissingError,
267
267
  yt as isPeginRegistrationNotFinalError,
268
268
  Qs as isPegoutTerminalStatus,
269
269
  $s as isRecognizedPegoutStatus,
270
- Dt as isRegisteredVaultVersionMismatchError,
270
+ vt as isRegisteredVaultVersionMismatchError,
271
271
  se as isRegistrationLogsUnavailableError,
272
272
  Bs as isUnrecognizedDaemonStatusError,
273
273
  sa as isValidHex,
274
274
  re as isVaultClaimableByNotFoundError,
275
- xr as isWotsMismatchError,
276
- vt as matchKeyHint,
275
+ br as isWotsMismatchError,
276
+ Dt as matchKeyHint,
277
277
  Bt as matchKeySetHint,
278
278
  Fr as orderClaimBatchByHtlcVout,
279
279
  Ze as parseFundingOutpointsFromTx,
280
280
  Is as parseUnfundedWasmTransaction,
281
281
  fs as peginOutputCount,
282
- O as peginP2aAnchorOutput,
283
- V as pinPegoutProof,
282
+ V as peginP2aAnchorOutput,
283
+ O as pinPegoutProof,
284
284
  Ut as planDelegatedClaimSigning,
285
285
  tr as primeVpTokenRegistry,
286
286
  ra as processPublicKeyToXOnly,
@@ -298,7 +298,7 @@ export {
298
298
  Xt as resolveParticipantKeysAtEpochs,
299
299
  ce as resolveProtocolAddresses,
300
300
  Gt as runDepositorPresignFlow,
301
- Dr as selectSiblingRegistrations,
301
+ vr as selectSiblingRegistrations,
302
302
  ls as selectUtxosForPegin,
303
303
  ps as shouldAddChangeOutput,
304
304
  kt as signDelegatedClaimPlan,
@@ -306,9 +306,9 @@ export {
306
306
  ta as stripHexPrefix,
307
307
  wt as submitWotsPublicKey,
308
308
  zt as summarizeWatchtowerArtifacts,
309
- b as supportedTxGraphVersions,
310
- Da as supportsDepositApproval,
311
- vr as toRefundInputs,
309
+ x as supportedTxGraphVersions,
310
+ va as supportsDepositApproval,
311
+ Dr as toRefundInputs,
312
312
  ia as toXOnly,
313
313
  oa as uint8ArrayToHex,
314
314
  Yt as validateDepositAmount,
@@ -316,11 +316,11 @@ export {
316
316
  ie as validateOffchainParams,
317
317
  Jt as validateOnChainParticipantKeys,
318
318
  oe as validatePegInConfiguration,
319
- x as validatePeginP2aAnchor,
319
+ b as validatePeginP2aAnchor,
320
320
  Zt as validateProviderSelection,
321
321
  qt as validateRemainingCapacity,
322
322
  Us as validateRequestDepositorClaimerArtifactsResponse,
323
- va as validateSecretAgainstHashlock,
323
+ Da as validateSecretAgainstHashlock,
324
324
  ne as validateTBVProtocolParams,
325
325
  Ns as validateUtxosAvailable,
326
326
  Qt as validateVaultAmounts,
@@ -1,2 +1,2 @@
1
- "use strict";var Pe=Object.defineProperty;var fe=(e,t,r)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var j=(e,t,r)=>fe(e,typeof t!="symbol"?t+"":t,r);const M=require("./registration-records-DFQgBaYi.cjs"),p=require("./bitcoin-D-O2GjbC.cjs"),N=require("./btcTxHash-CGb5BqFL.cjs"),O=require("bitcoinjs-lib"),ve=require("buffer"),be=require("./tbv/core/clients/mempool/index.cjs"),X=require("./validation-C6XTfZak.cjs"),C=require("viem"),Ee=require("./sha2-Ce6KewYx.cjs"),D=require("./PayoutManager-DOdsgcUR.cjs"),ee=require("./PeginManager-PyKbfy5q.cjs"),v=require("./tbv/core/wasm/index.cjs"),xe=require("./deriveVaultRoot-C3uqnJto.cjs"),we=require("./parseFundingOutpoints-C_-PT9BT.cjs"),K=require("./verifyScriptPathSchnorrSignature-D2t1yACC.cjs"),Q=require("./fundPeginTransaction-54-Rwb2k.cjs"),ye=["vaultCoreVersion","offchainParamsVersion","appVaultKeepersVersion","universalChallengersVersion"],Ce=["applicationEntryPoint","vaultProvider"];function te(e,t){const r=t.depositor.toLowerCase(),n=M.registrationPrePeginTxHash(t).toLowerCase();return e.filter(o=>o.vaultId!==t.vaultId&&o.depositor.toLowerCase()===r&&M.registrationPrePeginTxHash(o).toLowerCase()===n)}function re(e,t){for(const r of t){for(const n of ye)if(r.vault.protocol[n]!==e.vault.protocol[n])throw new Error(`Sibling vaults of this Pre-PegIn disagree on ${n} (${r.vault.protocol[n]} vs ${e.vault.protocol[n]}); the batch cannot be described by one set of deposit terms.`);if(r.maxAcceptableCommissionBps!==e.maxAcceptableCommissionBps)throw new Error(`Sibling vaults of this Pre-PegIn disagree on maxAcceptableCommissionBps (${r.maxAcceptableCommissionBps} vs ${e.maxAcceptableCommissionBps}); the batch cannot be described by one set of deposit terms.`);for(const n of Ce)if(r.vault.basic[n].toLowerCase()!==e.vault.basic[n].toLowerCase())throw new Error(`Sibling vaults of this Pre-PegIn disagree on ${n} (${r.vault.basic[n]} vs ${e.vault.basic[n]}); the batch cannot be described by one set of deposit terms.`)}}function ne(e){const t=[...e].sort((r,n)=>r.vault.protocol.htlcVout-n.vault.protocol.htlcVout);return t.forEach((r,n)=>{if(r.vault.protocol.htlcVout!==n)throw new Error(`Sibling discovery produced a non-contiguous HTLC vector (${t.map(o=>o.vault.protocol.htlcVout).join(", ")}).`)}),t.map(r=>({hashlock:r.vault.protocol.hashlock,amount:r.vault.basic.amount}))}const L="DepositTermsRejectedError";class oe extends Error{constructor(r,n="device-envelope"){super(r);j(this,"reason");this.name=L,this.reason=n}}function Re(e){if(e instanceof oe)return!0;if(typeof e!="object"||e===null)return!1;const t=e;return t.name===L&&t.reason==="device-envelope"}async function se(e,t){const r=O.Transaction.fromHex(p.stripHexPrefix(e)),o=(await Promise.all(r.ins.map(i=>be.getUtxoInfo(ve.Buffer.from(i.hash).reverse().toString("hex"),i.index,t)))).reduce((i,a)=>i+BigInt(a.value),0n),u=r.outs.reduce((i,a)=>i+BigInt(a.value),0n),s=o-u;if(s<=0n)throw new Error(`The funded Pre-PegIn transaction's inputs do not cover its outputs plus a fee (computed fee: ${s} sats).`);if(s>X.MAX_REASONABLE_FEE_SATS)throw new Error(`The funded Pre-PegIn transaction's computed fee (${s} sats) exceeds the maximum reasonable fee (${X.MAX_REASONABLE_FEE_SATS} sats); the mempool API may have returned manipulated prevout data.`);return s}async function z(e){const t=e.siblings.length;if(t===0)throw new Error("rebuildDepositTermsCore: at least one sibling is required");for(const[l,E]of e.siblings.entries())if(E.amount<=0n)throw new Error(`rebuildDepositTermsCore: sibling[${l}] has non-positive on-chain pegin amount ${E.amount}; the chain-read vault record is invalid. Resume refused.`);if(e.prepeginMaxFee<=0n)throw new Error(`rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${e.prepeginMaxFee}`);const r=p.stripHexPrefix(e.prepeginTxid).toLowerCase(),n=p.stripHexPrefix(N.calculateBtcTxHash(e.fundedPrePeginTxHex)).toLowerCase();if(n!==r)throw new Error(`Funded Pre-PegIn tx hashes to ${n}, expected ${r} (on-chain prepeginTxid). Resume refused.`);const o=D.findAuthAnchorOpReturn(p.stripHexPrefix(e.fundedPrePeginTxHex));if(o===void 0)throw new Error("Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN commitment — it either predates auth anchoring or is malformed. The intent resume path requires the anchor to prove sibling completeness. Resume refused.");if(o.vout!==t)throw new Error(`Auth-anchor OP_RETURN at vout ${o.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.`);const u=e.vaultKeeperBtcPubkeys.length,s=e.universalChallengerBtcPubkeys.length,i=await v.computeMinClaimValue(e.vaultCoreVersion,u,s,e.councilQuorum,e.councilSize,e.protocolFeeRate),a=await v.computeMinPeginFee(e.vaultCoreVersion,u,s,e.minPeginFeeRate),d=await v.peginP2aAnchorOutput(e.vaultCoreVersion),c=(d==null?void 0:d.value)??0n;if(i<=0n)throw new Error(`WASM returned non-positive depositorClaimValue ${i}; expected > 0. Resume refused.`);if(a<=0n)throw new Error(`WASM returned non-positive peginMaxFee ${a}; expected > 0. Resume refused.`);if(c<0n)throw new Error(`WASM returned negative P2A anchor value ${c}. Resume refused.`);const h=a+c,b=e.minPeginFeeRate*Q.MAX_REASONABLE_PEGIN_VBYTES;if(h<=0n||h>b)throw new Error(`WASM implied PegIn reserve ${h} sat is outside (0, ${b}] (minPeginFeeRate=${e.minPeginFeeRate} × ${Q.MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`);const w=e.siblings.map(l=>l.amount+i+a+c),R=await Promise.all(e.siblings.map(async l=>(await v.getPrePeginHtlcConnectorInfo({txGraphVersion:e.vaultCoreVersion,depositorPubkey:e.depositorBtcPubkey,vaultProviderPubkey:e.vaultProviderBtcPubkey,vaultKeeperPubkeys:[...e.vaultKeeperBtcPubkeys],universalChallengerPubkeys:[...e.universalChallengerBtcPubkeys],hashlock:p.stripHexPrefix(l.hashlock),timelockRefund:e.timelockRefund,network:e.network})).scriptPubKey)),y=O.Transaction.fromHex(p.stripHexPrefix(e.fundedPrePeginTxHex)).outs.map(l=>({value:l.value,script:l.script}));return K.assertEncodedHtlcOutputsMatch(y,w,R),ee.buildDepositTerms({vaultCoreVersion:e.vaultCoreVersion,protocolFeeRate:e.protocolFeeRate,timelockPegin:e.timelockPegin,timelockAssert:e.timelockAssert,timelockRefund:e.timelockRefund,prepeginTxid:e.prepeginTxid,prepeginMaxFee:e.prepeginMaxFee,vaultProviderBtcPubkey:e.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:e.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:e.universalChallengerBtcPubkeys,maxAcceptableCommissionBps:e.maxAcceptableCommissionBps,peginAmounts:e.siblings.map(l=>l.amount),depositorClaimValue:i,peginMaxFee:a})}async function ke(e){const{read:t}=e,r=p.canonicalizeBtcPubkey(e.depositorBtcPubkey);if(r!==t.context.depositorBtcPubkey)throw new Error("Connected wallet key is not the vault's depositor key; select the account that made the deposit.");const n=p.stripHexPrefix(t.prePeginTxHash).toLowerCase(),o=p.stripHexPrefix(N.calculateBtcTxHash(e.fundedPrePeginTxHex)).toLowerCase();if(o!==n)throw new Error(`Funded Pre-PegIn tx hashes to ${o}, expected ${n} (on-chain prePeginTxHash).`);const u=await Promise.all(te(t.registrationRecords,t.registrationRecord).map(async d=>{const c=await e.siblingReader.getVaultData(d.vaultId);if(c.protocol.prePeginTxHash.toLowerCase()!==M.registrationPrePeginTxHash(d).toLowerCase())throw new Error(`Sibling ${d.vaultId} is registered against a different Pre-PegIn on chain than its registration log records; refusing an inconsistent node.`);return{vault:c,maxAcceptableCommissionBps:d.maxAcceptableCommissionBps}})),s={vault:t.vault,maxAcceptableCommissionBps:t.registrationRecord.maxAcceptableCommissionBps};re(s,u);const i=ne([s,...u]),a=await se(e.fundedPrePeginTxHex,e.mempoolApiUrl);return z({vaultCoreVersion:t.vault.protocol.vaultCoreVersion,siblings:i,fundedPrePeginTxHex:e.fundedPrePeginTxHex,depositorBtcPubkey:r,vaultProviderBtcPubkey:t.participantKeys.vaultProvider.operationBtcPubkey,vaultKeeperBtcPubkeys:t.participantKeys.vaultKeeperOperationKeysSorted,universalChallengerBtcPubkeys:t.participantKeys.universalChallengerOperationKeysSorted,protocolFeeRate:t.offchainParams.feeRate,minPeginFeeRate:t.offchainParams.minPeginFeeRate,councilQuorum:t.offchainParams.councilQuorum,councilSize:t.offchainParams.securityCouncilKeys.length,timelockPegin:t.context.timelockPegin,timelockAssert:t.context.timelockAssert,timelockRefund:t.offchainParams.tRefund,prepeginTxid:n,prepeginMaxFee:a,maxAcceptableCommissionBps:t.registrationRecord.maxAcceptableCommissionBps,network:e.network})}function Te(e){const t=(e instanceof Error?e.message:typeof e=="string"?e:"").toLowerCase();return t.includes("wots")&&t.includes("hash")&&t.includes("does not match")}const ie="TBV.PeginFingerprint.v1",ae=C.keccak256(C.toHex(ie)),W=65535,J=2n**64n-1n,Ae=2n**256n-1n,Ve=/^0x[0-9a-fA-F]{64}$/,Y=1;class P extends Error{constructor(t){super(t),this.name="PeginFingerprintInputError"}}function Ie(e){return e instanceof P||e instanceof Error&&e.name==="PeginFingerprintInputError"}function _(e,t,r,n){if(typeof t!="bigint")throw new P(`${e} must be a bigint (Solidity ${n}), got ${typeof t}`);if(t<0n||t>r)throw new P(`${e} must fit Solidity ${n} (0..${r}), got ${t}`)}function $(e,t){if(!Number.isInteger(t)||t<0||t>W)throw new P(`${e} must be an integer fitting Solidity uint16 (0..${W}), got ${t}`)}function $e(e,t){if(!Ve.test(t))throw new P(`${e} must be 32 bytes as 0x-prefixed hex (66 characters), got "${t}"`);return t.toLowerCase()}function Be(e){if(!C.isAddress(e,{strict:!1}))throw new P(`registryAddress must be a 20-byte 0x-prefixed address, got "${e}"`);const t=e.toLowerCase();if(t===C.zeroAddress)throw new P("registryAddress must not be the zero address; a zero here means the registry address was never resolved");return t}const Fe=[{name:"domain",type:"bytes32"},{name:"chainId",type:"uint256"},{name:"registry",type:"address"},{name:"vaultProviderBtcKey",type:"bytes32"},{name:"appKeeperKeyEpoch",type:"uint64"},{name:"ucKeyEpoch",type:"uint64"},{name:"appVaultKeepersVersion",type:"uint16"},{name:"universalChallengersVersion",type:"uint16"},{name:"offchainParamsVersion",type:"uint16"},{name:"vaultCoreVersion",type:"uint16"}];function ce(e){if(_("chainId",e.chainId,Ae,"uint256"),e.chainId===0n)throw new P("chainId must not be 0; a zero here means the chain id was never resolved");const t=Be(e.registryAddress),r=$e("vaultProviderBtcKey",e.vaultProviderBtcKey);if(_("appKeeperKeyEpoch",e.appKeeperKeyEpoch,J,"uint64"),_("ucKeyEpoch",e.ucKeyEpoch,J,"uint64"),$("appVaultKeepersVersion",e.appVaultKeepersVersion),$("universalChallengersVersion",e.universalChallengersVersion),$("offchainParamsVersion",e.offchainParamsVersion),$("vaultCoreVersion",e.vaultCoreVersion),e.vaultCoreVersion<Y)throw new P(`vaultCoreVersion must be at least ${Y}; ${e.vaultCoreVersion} means the version was never resolved`);return C.encodeAbiParameters(Fe,[ae,e.chainId,t,r,e.appKeeperKeyEpoch,e.ucKeyEpoch,e.appVaultKeepersVersion,e.universalChallengersVersion,e.offchainParamsVersion,e.vaultCoreVersion])}function Se(e){return C.keccak256(ce(e))}class ue extends Error{constructor(t,r){super(`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.`),this.derivedAuthAnchorHash=t,this.onChainAuthAnchorHash=r,this.name="VaultRootMismatchError"}}class F extends Error{constructor(t){super(t),this.name="UnanchoredPrePeginError"}}class le extends Error{constructor(t,r,n=[]){super(`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(" | ")}`),this.candidatesTried=t,this.sampleRejections=r,this.unresolvedLabels=n,this.name="PeginParamsNotFoundError"}}class he extends Error{constructor(t){super(`${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.`),this.survivorLabels=t,this.name="PeginParamsAmbiguousError"}}class de extends Error{constructor(t,r){super(`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.`),this.matchedLabel=t,this.unresolvedLabels=r,this.name="PeginParamsIncompleteSpaceError"}}class V extends Error{constructor(t){super(`${t}. Reconstruction refused.`),this.name="PeginSizingIntegrityError"}}async function He(e){const{wallet:t,depositorBtcPubkey:r,fundedPrePeginTxHex:n}=e,o=p.stripHexPrefix(n),u=D.findAuthAnchorOpReturn(o);if(u===void 0)throw new F("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.");const s=u.vout;if(s===0)throw new F("Pre-PegIn's auth-anchor OP_RETURN is at vout 0, implying zero HTLC outputs; there is nothing to recover.");const i=we.parseFundingOutpointsFromTx(o),a=await xe.deriveVaultRoot(t,{depositorBtcPubkey:p.hexToUint8Array(p.processPublicKeyToXOnly(r)),fundingOutpoints:i});try{const c=await v.expandAuthAnchor(a);let h;try{h=p.uint8ArrayToHex(Ee.sha256(c))}finally{c.fill(0)}if(h!==u.hash)throw new ue(h,u.hash)}catch(c){throw a.fill(0),c}const{hashlocks:d}=await ee.expandPerVaultSecrets(a,s);return{vaultCount:s,hashlocks:d,authAnchorHash:u.hash}}function _e(e){const{vaultCoreVersion:t,offchainParams:r,participantKeySets:n}=e;if(!Number.isInteger(t)||t<1)throw new Error(`buildPeginParamsCandidates: vaultCoreVersion must be a positive integer, got ${t}`);if(r.length===0)throw new Error("buildPeginParamsCandidates: at least one offchain-params version is required");if(n.length===0)throw new Error("buildPeginParamsCandidates: at least one participant key set is required");const o=[];for(const u of r)for(const s of n)o.push({vaultCoreVersion:t,offchainParams:u,participants:s});return o}function pe(e){return`${e.axis} v${e.version} (${e.reason})`}function B(e){const{participants:t}=e;return`core=${e.vaultCoreVersion} offchain=${e.offchainParams.version} keepers=${t.appVaultKeepersVersion} challengers=${t.universalChallengersVersion} vp=${t.vaultProvider}`}const Z=5;function Me(e,t){return JSON.stringify({terms:e,peginAmounts:t},(r,n)=>typeof n=="bigint"?`${n}`:n)}function Ke(e){const{offchainParams:t,participants:r}=e;return[e.vaultCoreVersion,r.vaultKeeperBtcPubkeys.length,r.universalChallengerBtcPubkeys.length,t.councilQuorum,t.councilSize,t.protocolFeeRate,t.minPeginFeeRate].join("|")}async function Ne(e){const{offchainParams:t,participants:r}=e,n=r.vaultKeeperBtcPubkeys.length,o=r.universalChallengerBtcPubkeys.length,[u,s,i]=await Promise.all([v.computeMinClaimValue(e.vaultCoreVersion,n,o,t.councilQuorum,t.councilSize,t.protocolFeeRate),v.computeMinPeginFee(e.vaultCoreVersion,n,o,t.minPeginFeeRate),v.peginP2aAnchorOutput(e.vaultCoreVersion)]),a=(i==null?void 0:i.value)??0n;if(u<=0n)throw new V(`WASM returned non-positive depositorClaimValue ${u} for graph version ${e.vaultCoreVersion}`);if(s<=0n)throw new V(`WASM returned non-positive peginMaxFee ${s} for graph version ${e.vaultCoreVersion}`);if(a<0n)throw new V(`WASM returned negative P2A anchor value ${a} for graph version ${e.vaultCoreVersion}`);return{depositorClaimValue:u,peginMaxFee:s,p2aAnchorValue:a}}async function Oe(e){const{hashlocks:t,fundedPrePeginTxHex:r,depositorBtcPubkey:n,prepeginMaxFee:o,maxAcceptableCommissionBps:u,network:s,candidates:i,unresolvedVersions:a}=e;if(t.length===0)throw new Error("reconstructPeginParams: at least one hashlock is required");if(i.length===0)throw new Error("reconstructPeginParams: candidate space is empty");const d=p.processPublicKeyToXOnly(n),c=p.stripHexPrefix(r),h=D.findAuthAnchorOpReturn(c);if(h===void 0)throw new F("Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN; the sibling set cannot be proven complete. Reconstruction refused.");if(h.vout!==t.length)throw new Error(`reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${h.vout}, so the transaction funds ${h.vout} HTLC output(s). Reconstruction refused.`);const b=O.Transaction.fromHex(c).outs,w=t.map((m,g)=>BigInt(b[g].value)),R=p.stripHexPrefix(N.calculateBtcTxHash(c)).toLowerCase(),y=new Map,l=[],E=[],S=[];let U=0;for(const m of i)try{const g=Ke(m);let f=y.get(g);f===void 0&&(f=await Ne(m),y.set(g,f));const k=f.depositorClaimValue+f.peginMaxFee+f.p2aAnchorValue,T=w.map(A=>A-k),I=T.findIndex(A=>A<=0n);if(I!==-1)throw new K.HtlcOutputMismatchError(`HTLC output[${I}] value ${w[I]} is not above this candidate's reserve ${k}, so it implies a non-positive pegin amount ${T[I]}.`);const{offchainParams:x,participants:H}=m,G=await z({vaultCoreVersion:m.vaultCoreVersion,siblings:t.map((A,ge)=>({hashlock:A,amount:T[ge]})),fundedPrePeginTxHex:c,depositorBtcPubkey:d,vaultProviderBtcPubkey:H.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:H.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:H.universalChallengerBtcPubkeys,protocolFeeRate:x.protocolFeeRate,minPeginFeeRate:x.minPeginFeeRate,councilQuorum:x.councilQuorum,councilSize:x.councilSize,timelockPegin:x.timelockPegin,timelockAssert:x.timelockAssert,timelockRefund:x.timelockRefund,prepeginTxid:R,prepeginMaxFee:o,maxAcceptableCommissionBps:u,network:s});l.push({candidate:m,terms:G,peginAmounts:T,fingerprint:Me(G,T)})}catch(g){if(g instanceof V)throw g;const f=B(m),k=g instanceof Error?g.message:String(g);g instanceof K.HtlcOutputMismatchError?E.length<Z&&E.push(`[${f}] ${k}`):(U++,S.length<Z&&S.push(`${f} (${k})`))}const me=a.length+U,q=[...a.map(pe),...S];if(l.length===0)throw new le(i.length,E,q);if(new Set(l.map(m=>m.fingerprint)).size>1)throw new he(l.map(m=>B(m.candidate)));if(me>0)throw new de(B(l[0].candidate),q);return{candidate:l[0].candidate,terms:l[0].terms,peginAmounts:l[0].peginAmounts,authAnchorHash:h.hash,candidatesTried:i.length,matchedCandidates:l.map(m=>m.candidate)}}function De(e,t){const{htlcVout:r,depositorBtcPubkey:n,applicationEntryPoint:o,fundedPrePeginTxHex:u,hashlocks:s,network:i}=t,{candidate:a,peginAmounts:d}=e,{offchainParams:c,participants:h}=a;if(s.length!==d.length)throw new Error(`toRefundInputs: ${s.length} hashlock(s) but ${d.length} reconstructed amount(s); the reconstruction and the hashlock vector describe different transactions.`);if(!Number.isInteger(r)||r<0||r>=d.length)throw new Error(`toRefundInputs: htlcVout ${r} is outside the reconstructed batch of ${d.length} vault(s).`);const b=d.map((y,l)=>({hashlock:p.ensureHexPrefix(s[l]),amount:y,htlcVout:l})),w={vaultCoreVersion:a.vaultCoreVersion,hashlock:b[r].hashlock,htlcVout:r,offchainParamsVersion:c.version,appVaultKeepersVersion:h.appVaultKeepersVersion,universalChallengersVersion:h.universalChallengersVersion,vaultProvider:h.vaultProvider,applicationEntryPoint:o,amount:d[r],unsignedPrePeginTxHex:u,depositorBtcPubkey:n,batch:b},R={vaultProviderPubkey:h.vaultProviderBtcPubkey,vaultKeeperPubkeys:h.vaultKeeperBtcPubkeys,universalChallengerPubkeys:h.universalChallengerBtcPubkeys,timelockRefund:c.timelockRefund,feeRate:c.protocolFeeRate,minPeginFeeRate:c.minPeginFeeRate,numLocalChallengers:h.vaultKeeperBtcPubkeys.length,councilQuorum:c.councilQuorum,councilSize:c.councilSize,network:i};return{vault:w,context:R}}exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=L;exports.DepositTermsRejectedError=oe;exports.PEGIN_FINGERPRINT_DOMAIN=ae;exports.PEGIN_FINGERPRINT_DOMAIN_PREIMAGE=ie;exports.PeginFingerprintInputError=P;exports.PeginParamsAmbiguousError=he;exports.PeginParamsIncompleteSpaceError=de;exports.PeginParamsNotFoundError=le;exports.PeginSizingIntegrityError=V;exports.UnanchoredPrePeginError=F;exports.VaultRootMismatchError=ue;exports.assertClaimBatchHomogeneous=re;exports.buildPeginParamsCandidates=_e;exports.computeFundedPrePeginFee=se;exports.computePeginFingerprint=Se;exports.deriveHashlocksFromPrePegin=He;exports.describePeginParamsCandidate=B;exports.describeUnresolvedVersion=pe;exports.encodePeginFingerprintPreimage=ce;exports.isDepositTermsRejectedError=Re;exports.isPeginFingerprintInputError=Ie;exports.isWotsMismatchError=Te;exports.orderClaimBatchByHtlcVout=ne;exports.rebuildDepositTermsCore=z;exports.rebuildDepositTermsForClaim=ke;exports.reconstructPeginParams=Oe;exports.selectSiblingRegistrations=te;exports.toRefundInputs=De;
2
- //# sourceMappingURL=toRefundInputs-BbAOOUg6.cjs.map
1
+ "use strict";var Pe=Object.defineProperty;var fe=(e,t,r)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var j=(e,t,r)=>fe(e,typeof t!="symbol"?t+"":t,r);const M=require("./registration-records-DFQgBaYi.cjs"),p=require("./bitcoin-D-O2GjbC.cjs"),N=require("./btcTxHash-CGb5BqFL.cjs"),O=require("bitcoinjs-lib"),ve=require("buffer"),be=require("./tbv/core/clients/mempool/index.cjs"),X=require("./validation-C6XTfZak.cjs"),C=require("viem"),Ee=require("./sha2-Ce6KewYx.cjs"),D=require("./PayoutManager-DOdsgcUR.cjs"),ee=require("./PeginManager-BHplS4dM.cjs"),v=require("./tbv/core/wasm/index.cjs"),xe=require("./deriveVaultRoot-C3uqnJto.cjs"),we=require("./parseFundingOutpoints-C_-PT9BT.cjs"),K=require("./verifyScriptPathSchnorrSignature-D2t1yACC.cjs"),Q=require("./fundPeginTransaction-54-Rwb2k.cjs"),ye=["vaultCoreVersion","offchainParamsVersion","appVaultKeepersVersion","universalChallengersVersion"],Ce=["applicationEntryPoint","vaultProvider"];function te(e,t){const r=t.depositor.toLowerCase(),n=M.registrationPrePeginTxHash(t).toLowerCase();return e.filter(o=>o.vaultId!==t.vaultId&&o.depositor.toLowerCase()===r&&M.registrationPrePeginTxHash(o).toLowerCase()===n)}function re(e,t){for(const r of t){for(const n of ye)if(r.vault.protocol[n]!==e.vault.protocol[n])throw new Error(`Sibling vaults of this Pre-PegIn disagree on ${n} (${r.vault.protocol[n]} vs ${e.vault.protocol[n]}); the batch cannot be described by one set of deposit terms.`);if(r.maxAcceptableCommissionBps!==e.maxAcceptableCommissionBps)throw new Error(`Sibling vaults of this Pre-PegIn disagree on maxAcceptableCommissionBps (${r.maxAcceptableCommissionBps} vs ${e.maxAcceptableCommissionBps}); the batch cannot be described by one set of deposit terms.`);for(const n of Ce)if(r.vault.basic[n].toLowerCase()!==e.vault.basic[n].toLowerCase())throw new Error(`Sibling vaults of this Pre-PegIn disagree on ${n} (${r.vault.basic[n]} vs ${e.vault.basic[n]}); the batch cannot be described by one set of deposit terms.`)}}function ne(e){const t=[...e].sort((r,n)=>r.vault.protocol.htlcVout-n.vault.protocol.htlcVout);return t.forEach((r,n)=>{if(r.vault.protocol.htlcVout!==n)throw new Error(`Sibling discovery produced a non-contiguous HTLC vector (${t.map(o=>o.vault.protocol.htlcVout).join(", ")}).`)}),t.map(r=>({hashlock:r.vault.protocol.hashlock,amount:r.vault.basic.amount}))}const L="DepositTermsRejectedError";class oe extends Error{constructor(r,n="device-envelope"){super(r);j(this,"reason");this.name=L,this.reason=n}}function Re(e){if(e instanceof oe)return!0;if(typeof e!="object"||e===null)return!1;const t=e;return t.name===L&&t.reason==="device-envelope"}async function se(e,t){const r=O.Transaction.fromHex(p.stripHexPrefix(e)),o=(await Promise.all(r.ins.map(i=>be.getUtxoInfo(ve.Buffer.from(i.hash).reverse().toString("hex"),i.index,t)))).reduce((i,a)=>i+BigInt(a.value),0n),u=r.outs.reduce((i,a)=>i+BigInt(a.value),0n),s=o-u;if(s<=0n)throw new Error(`The funded Pre-PegIn transaction's inputs do not cover its outputs plus a fee (computed fee: ${s} sats).`);if(s>X.MAX_REASONABLE_FEE_SATS)throw new Error(`The funded Pre-PegIn transaction's computed fee (${s} sats) exceeds the maximum reasonable fee (${X.MAX_REASONABLE_FEE_SATS} sats); the mempool API may have returned manipulated prevout data.`);return s}async function z(e){const t=e.siblings.length;if(t===0)throw new Error("rebuildDepositTermsCore: at least one sibling is required");for(const[l,E]of e.siblings.entries())if(E.amount<=0n)throw new Error(`rebuildDepositTermsCore: sibling[${l}] has non-positive on-chain pegin amount ${E.amount}; the chain-read vault record is invalid. Resume refused.`);if(e.prepeginMaxFee<=0n)throw new Error(`rebuildDepositTermsCore: prepeginMaxFee must be > 0, got ${e.prepeginMaxFee}`);const r=p.stripHexPrefix(e.prepeginTxid).toLowerCase(),n=p.stripHexPrefix(N.calculateBtcTxHash(e.fundedPrePeginTxHex)).toLowerCase();if(n!==r)throw new Error(`Funded Pre-PegIn tx hashes to ${n}, expected ${r} (on-chain prepeginTxid). Resume refused.`);const o=D.findAuthAnchorOpReturn(p.stripHexPrefix(e.fundedPrePeginTxHex));if(o===void 0)throw new Error("Funded Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN commitment — it either predates auth anchoring or is malformed. The intent resume path requires the anchor to prove sibling completeness. Resume refused.");if(o.vout!==t)throw new Error(`Auth-anchor OP_RETURN at vout ${o.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.`);const u=e.vaultKeeperBtcPubkeys.length,s=e.universalChallengerBtcPubkeys.length,i=await v.computeMinClaimValue(e.vaultCoreVersion,u,s,e.councilQuorum,e.councilSize,e.protocolFeeRate),a=await v.computeMinPeginFee(e.vaultCoreVersion,u,s,e.minPeginFeeRate),d=await v.peginP2aAnchorOutput(e.vaultCoreVersion),c=(d==null?void 0:d.value)??0n;if(i<=0n)throw new Error(`WASM returned non-positive depositorClaimValue ${i}; expected > 0. Resume refused.`);if(a<=0n)throw new Error(`WASM returned non-positive peginMaxFee ${a}; expected > 0. Resume refused.`);if(c<0n)throw new Error(`WASM returned negative P2A anchor value ${c}. Resume refused.`);const h=a+c,b=e.minPeginFeeRate*Q.MAX_REASONABLE_PEGIN_VBYTES;if(h<=0n||h>b)throw new Error(`WASM implied PegIn reserve ${h} sat is outside (0, ${b}] (minPeginFeeRate=${e.minPeginFeeRate} × ${Q.MAX_REASONABLE_PEGIN_VBYTES} vbytes). Resume refused.`);const w=e.siblings.map(l=>l.amount+i+a+c),R=await Promise.all(e.siblings.map(async l=>(await v.getPrePeginHtlcConnectorInfo({txGraphVersion:e.vaultCoreVersion,depositorPubkey:e.depositorBtcPubkey,vaultProviderPubkey:e.vaultProviderBtcPubkey,vaultKeeperPubkeys:[...e.vaultKeeperBtcPubkeys],universalChallengerPubkeys:[...e.universalChallengerBtcPubkeys],hashlock:p.stripHexPrefix(l.hashlock),timelockRefund:e.timelockRefund,network:e.network})).scriptPubKey)),y=O.Transaction.fromHex(p.stripHexPrefix(e.fundedPrePeginTxHex)).outs.map(l=>({value:l.value,script:l.script}));return K.assertEncodedHtlcOutputsMatch(y,w,R),ee.buildDepositTerms({vaultCoreVersion:e.vaultCoreVersion,protocolFeeRate:e.protocolFeeRate,timelockPegin:e.timelockPegin,timelockAssert:e.timelockAssert,timelockRefund:e.timelockRefund,prepeginTxid:e.prepeginTxid,prepeginMaxFee:e.prepeginMaxFee,vaultProviderBtcPubkey:e.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:e.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:e.universalChallengerBtcPubkeys,maxAcceptableCommissionBps:e.maxAcceptableCommissionBps,peginAmounts:e.siblings.map(l=>l.amount),depositorClaimValue:i,peginMaxFee:a})}async function ke(e){const{read:t}=e,r=p.canonicalizeBtcPubkey(e.depositorBtcPubkey);if(r!==t.context.depositorBtcPubkey)throw new Error("Connected wallet key is not the vault's depositor key; select the account that made the deposit.");const n=p.stripHexPrefix(t.prePeginTxHash).toLowerCase(),o=p.stripHexPrefix(N.calculateBtcTxHash(e.fundedPrePeginTxHex)).toLowerCase();if(o!==n)throw new Error(`Funded Pre-PegIn tx hashes to ${o}, expected ${n} (on-chain prePeginTxHash).`);const u=await Promise.all(te(t.registrationRecords,t.registrationRecord).map(async d=>{const c=await e.siblingReader.getVaultData(d.vaultId);if(c.protocol.prePeginTxHash.toLowerCase()!==M.registrationPrePeginTxHash(d).toLowerCase())throw new Error(`Sibling ${d.vaultId} is registered against a different Pre-PegIn on chain than its registration log records; refusing an inconsistent node.`);return{vault:c,maxAcceptableCommissionBps:d.maxAcceptableCommissionBps}})),s={vault:t.vault,maxAcceptableCommissionBps:t.registrationRecord.maxAcceptableCommissionBps};re(s,u);const i=ne([s,...u]),a=await se(e.fundedPrePeginTxHex,e.mempoolApiUrl);return z({vaultCoreVersion:t.vault.protocol.vaultCoreVersion,siblings:i,fundedPrePeginTxHex:e.fundedPrePeginTxHex,depositorBtcPubkey:r,vaultProviderBtcPubkey:t.participantKeys.vaultProvider.operationBtcPubkey,vaultKeeperBtcPubkeys:t.participantKeys.vaultKeeperOperationKeysSorted,universalChallengerBtcPubkeys:t.participantKeys.universalChallengerOperationKeysSorted,protocolFeeRate:t.offchainParams.feeRate,minPeginFeeRate:t.offchainParams.minPeginFeeRate,councilQuorum:t.offchainParams.councilQuorum,councilSize:t.offchainParams.securityCouncilKeys.length,timelockPegin:t.context.timelockPegin,timelockAssert:t.context.timelockAssert,timelockRefund:t.offchainParams.tRefund,prepeginTxid:n,prepeginMaxFee:a,maxAcceptableCommissionBps:t.registrationRecord.maxAcceptableCommissionBps,network:e.network})}function Te(e){const t=(e instanceof Error?e.message:typeof e=="string"?e:"").toLowerCase();return t.includes("wots")&&t.includes("hash")&&t.includes("does not match")}const ie="TBV.PeginFingerprint.v1",ae=C.keccak256(C.toHex(ie)),W=65535,J=2n**64n-1n,Ae=2n**256n-1n,Ve=/^0x[0-9a-fA-F]{64}$/,Y=1;class P extends Error{constructor(t){super(t),this.name="PeginFingerprintInputError"}}function Ie(e){return e instanceof P||e instanceof Error&&e.name==="PeginFingerprintInputError"}function _(e,t,r,n){if(typeof t!="bigint")throw new P(`${e} must be a bigint (Solidity ${n}), got ${typeof t}`);if(t<0n||t>r)throw new P(`${e} must fit Solidity ${n} (0..${r}), got ${t}`)}function $(e,t){if(!Number.isInteger(t)||t<0||t>W)throw new P(`${e} must be an integer fitting Solidity uint16 (0..${W}), got ${t}`)}function $e(e,t){if(!Ve.test(t))throw new P(`${e} must be 32 bytes as 0x-prefixed hex (66 characters), got "${t}"`);return t.toLowerCase()}function Be(e){if(!C.isAddress(e,{strict:!1}))throw new P(`registryAddress must be a 20-byte 0x-prefixed address, got "${e}"`);const t=e.toLowerCase();if(t===C.zeroAddress)throw new P("registryAddress must not be the zero address; a zero here means the registry address was never resolved");return t}const Fe=[{name:"domain",type:"bytes32"},{name:"chainId",type:"uint256"},{name:"registry",type:"address"},{name:"vaultProviderBtcKey",type:"bytes32"},{name:"appKeeperKeyEpoch",type:"uint64"},{name:"ucKeyEpoch",type:"uint64"},{name:"appVaultKeepersVersion",type:"uint16"},{name:"universalChallengersVersion",type:"uint16"},{name:"offchainParamsVersion",type:"uint16"},{name:"vaultCoreVersion",type:"uint16"}];function ce(e){if(_("chainId",e.chainId,Ae,"uint256"),e.chainId===0n)throw new P("chainId must not be 0; a zero here means the chain id was never resolved");const t=Be(e.registryAddress),r=$e("vaultProviderBtcKey",e.vaultProviderBtcKey);if(_("appKeeperKeyEpoch",e.appKeeperKeyEpoch,J,"uint64"),_("ucKeyEpoch",e.ucKeyEpoch,J,"uint64"),$("appVaultKeepersVersion",e.appVaultKeepersVersion),$("universalChallengersVersion",e.universalChallengersVersion),$("offchainParamsVersion",e.offchainParamsVersion),$("vaultCoreVersion",e.vaultCoreVersion),e.vaultCoreVersion<Y)throw new P(`vaultCoreVersion must be at least ${Y}; ${e.vaultCoreVersion} means the version was never resolved`);return C.encodeAbiParameters(Fe,[ae,e.chainId,t,r,e.appKeeperKeyEpoch,e.ucKeyEpoch,e.appVaultKeepersVersion,e.universalChallengersVersion,e.offchainParamsVersion,e.vaultCoreVersion])}function Se(e){return C.keccak256(ce(e))}class ue extends Error{constructor(t,r){super(`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.`),this.derivedAuthAnchorHash=t,this.onChainAuthAnchorHash=r,this.name="VaultRootMismatchError"}}class F extends Error{constructor(t){super(t),this.name="UnanchoredPrePeginError"}}class le extends Error{constructor(t,r,n=[]){super(`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(" | ")}`),this.candidatesTried=t,this.sampleRejections=r,this.unresolvedLabels=n,this.name="PeginParamsNotFoundError"}}class he extends Error{constructor(t){super(`${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.`),this.survivorLabels=t,this.name="PeginParamsAmbiguousError"}}class de extends Error{constructor(t,r){super(`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.`),this.matchedLabel=t,this.unresolvedLabels=r,this.name="PeginParamsIncompleteSpaceError"}}class V extends Error{constructor(t){super(`${t}. Reconstruction refused.`),this.name="PeginSizingIntegrityError"}}async function He(e){const{wallet:t,depositorBtcPubkey:r,fundedPrePeginTxHex:n}=e,o=p.stripHexPrefix(n),u=D.findAuthAnchorOpReturn(o);if(u===void 0)throw new F("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.");const s=u.vout;if(s===0)throw new F("Pre-PegIn's auth-anchor OP_RETURN is at vout 0, implying zero HTLC outputs; there is nothing to recover.");const i=we.parseFundingOutpointsFromTx(o),a=await xe.deriveVaultRoot(t,{depositorBtcPubkey:p.hexToUint8Array(p.processPublicKeyToXOnly(r)),fundingOutpoints:i});try{const c=await v.expandAuthAnchor(a);let h;try{h=p.uint8ArrayToHex(Ee.sha256(c))}finally{c.fill(0)}if(h!==u.hash)throw new ue(h,u.hash)}catch(c){throw a.fill(0),c}const{hashlocks:d}=await ee.expandPerVaultSecrets(a,s);return{vaultCount:s,hashlocks:d,authAnchorHash:u.hash}}function _e(e){const{vaultCoreVersion:t,offchainParams:r,participantKeySets:n}=e;if(!Number.isInteger(t)||t<1)throw new Error(`buildPeginParamsCandidates: vaultCoreVersion must be a positive integer, got ${t}`);if(r.length===0)throw new Error("buildPeginParamsCandidates: at least one offchain-params version is required");if(n.length===0)throw new Error("buildPeginParamsCandidates: at least one participant key set is required");const o=[];for(const u of r)for(const s of n)o.push({vaultCoreVersion:t,offchainParams:u,participants:s});return o}function pe(e){return`${e.axis} v${e.version} (${e.reason})`}function B(e){const{participants:t}=e;return`core=${e.vaultCoreVersion} offchain=${e.offchainParams.version} keepers=${t.appVaultKeepersVersion} challengers=${t.universalChallengersVersion} vp=${t.vaultProvider}`}const Z=5;function Me(e,t){return JSON.stringify({terms:e,peginAmounts:t},(r,n)=>typeof n=="bigint"?`${n}`:n)}function Ke(e){const{offchainParams:t,participants:r}=e;return[e.vaultCoreVersion,r.vaultKeeperBtcPubkeys.length,r.universalChallengerBtcPubkeys.length,t.councilQuorum,t.councilSize,t.protocolFeeRate,t.minPeginFeeRate].join("|")}async function Ne(e){const{offchainParams:t,participants:r}=e,n=r.vaultKeeperBtcPubkeys.length,o=r.universalChallengerBtcPubkeys.length,[u,s,i]=await Promise.all([v.computeMinClaimValue(e.vaultCoreVersion,n,o,t.councilQuorum,t.councilSize,t.protocolFeeRate),v.computeMinPeginFee(e.vaultCoreVersion,n,o,t.minPeginFeeRate),v.peginP2aAnchorOutput(e.vaultCoreVersion)]),a=(i==null?void 0:i.value)??0n;if(u<=0n)throw new V(`WASM returned non-positive depositorClaimValue ${u} for graph version ${e.vaultCoreVersion}`);if(s<=0n)throw new V(`WASM returned non-positive peginMaxFee ${s} for graph version ${e.vaultCoreVersion}`);if(a<0n)throw new V(`WASM returned negative P2A anchor value ${a} for graph version ${e.vaultCoreVersion}`);return{depositorClaimValue:u,peginMaxFee:s,p2aAnchorValue:a}}async function Oe(e){const{hashlocks:t,fundedPrePeginTxHex:r,depositorBtcPubkey:n,prepeginMaxFee:o,maxAcceptableCommissionBps:u,network:s,candidates:i,unresolvedVersions:a}=e;if(t.length===0)throw new Error("reconstructPeginParams: at least one hashlock is required");if(i.length===0)throw new Error("reconstructPeginParams: candidate space is empty");const d=p.processPublicKeyToXOnly(n),c=p.stripHexPrefix(r),h=D.findAuthAnchorOpReturn(c);if(h===void 0)throw new F("Pre-PegIn carries no single, unambiguous auth-anchor OP_RETURN; the sibling set cannot be proven complete. Reconstruction refused.");if(h.vout!==t.length)throw new Error(`reconstructPeginParams: ${t.length} hashlock(s) supplied but the auth-anchor OP_RETURN sits at vout ${h.vout}, so the transaction funds ${h.vout} HTLC output(s). Reconstruction refused.`);const b=O.Transaction.fromHex(c).outs,w=t.map((m,g)=>BigInt(b[g].value)),R=p.stripHexPrefix(N.calculateBtcTxHash(c)).toLowerCase(),y=new Map,l=[],E=[],S=[];let U=0;for(const m of i)try{const g=Ke(m);let f=y.get(g);f===void 0&&(f=await Ne(m),y.set(g,f));const k=f.depositorClaimValue+f.peginMaxFee+f.p2aAnchorValue,T=w.map(A=>A-k),I=T.findIndex(A=>A<=0n);if(I!==-1)throw new K.HtlcOutputMismatchError(`HTLC output[${I}] value ${w[I]} is not above this candidate's reserve ${k}, so it implies a non-positive pegin amount ${T[I]}.`);const{offchainParams:x,participants:H}=m,G=await z({vaultCoreVersion:m.vaultCoreVersion,siblings:t.map((A,ge)=>({hashlock:A,amount:T[ge]})),fundedPrePeginTxHex:c,depositorBtcPubkey:d,vaultProviderBtcPubkey:H.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:H.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:H.universalChallengerBtcPubkeys,protocolFeeRate:x.protocolFeeRate,minPeginFeeRate:x.minPeginFeeRate,councilQuorum:x.councilQuorum,councilSize:x.councilSize,timelockPegin:x.timelockPegin,timelockAssert:x.timelockAssert,timelockRefund:x.timelockRefund,prepeginTxid:R,prepeginMaxFee:o,maxAcceptableCommissionBps:u,network:s});l.push({candidate:m,terms:G,peginAmounts:T,fingerprint:Me(G,T)})}catch(g){if(g instanceof V)throw g;const f=B(m),k=g instanceof Error?g.message:String(g);g instanceof K.HtlcOutputMismatchError?E.length<Z&&E.push(`[${f}] ${k}`):(U++,S.length<Z&&S.push(`${f} (${k})`))}const me=a.length+U,q=[...a.map(pe),...S];if(l.length===0)throw new le(i.length,E,q);if(new Set(l.map(m=>m.fingerprint)).size>1)throw new he(l.map(m=>B(m.candidate)));if(me>0)throw new de(B(l[0].candidate),q);return{candidate:l[0].candidate,terms:l[0].terms,peginAmounts:l[0].peginAmounts,authAnchorHash:h.hash,candidatesTried:i.length,matchedCandidates:l.map(m=>m.candidate)}}function De(e,t){const{htlcVout:r,depositorBtcPubkey:n,applicationEntryPoint:o,fundedPrePeginTxHex:u,hashlocks:s,network:i}=t,{candidate:a,peginAmounts:d}=e,{offchainParams:c,participants:h}=a;if(s.length!==d.length)throw new Error(`toRefundInputs: ${s.length} hashlock(s) but ${d.length} reconstructed amount(s); the reconstruction and the hashlock vector describe different transactions.`);if(!Number.isInteger(r)||r<0||r>=d.length)throw new Error(`toRefundInputs: htlcVout ${r} is outside the reconstructed batch of ${d.length} vault(s).`);const b=d.map((y,l)=>({hashlock:p.ensureHexPrefix(s[l]),amount:y,htlcVout:l})),w={vaultCoreVersion:a.vaultCoreVersion,hashlock:b[r].hashlock,htlcVout:r,offchainParamsVersion:c.version,appVaultKeepersVersion:h.appVaultKeepersVersion,universalChallengersVersion:h.universalChallengersVersion,vaultProvider:h.vaultProvider,applicationEntryPoint:o,amount:d[r],unsignedPrePeginTxHex:u,depositorBtcPubkey:n,batch:b},R={vaultProviderPubkey:h.vaultProviderBtcPubkey,vaultKeeperPubkeys:h.vaultKeeperBtcPubkeys,universalChallengerPubkeys:h.universalChallengerBtcPubkeys,timelockRefund:c.timelockRefund,feeRate:c.protocolFeeRate,minPeginFeeRate:c.minPeginFeeRate,numLocalChallengers:h.vaultKeeperBtcPubkeys.length,councilQuorum:c.councilQuorum,councilSize:c.councilSize,network:i};return{vault:w,context:R}}exports.DEPOSIT_TERMS_REJECTED_ERROR_NAME=L;exports.DepositTermsRejectedError=oe;exports.PEGIN_FINGERPRINT_DOMAIN=ae;exports.PEGIN_FINGERPRINT_DOMAIN_PREIMAGE=ie;exports.PeginFingerprintInputError=P;exports.PeginParamsAmbiguousError=he;exports.PeginParamsIncompleteSpaceError=de;exports.PeginParamsNotFoundError=le;exports.PeginSizingIntegrityError=V;exports.UnanchoredPrePeginError=F;exports.VaultRootMismatchError=ue;exports.assertClaimBatchHomogeneous=re;exports.buildPeginParamsCandidates=_e;exports.computeFundedPrePeginFee=se;exports.computePeginFingerprint=Se;exports.deriveHashlocksFromPrePegin=He;exports.describePeginParamsCandidate=B;exports.describeUnresolvedVersion=pe;exports.encodePeginFingerprintPreimage=ce;exports.isDepositTermsRejectedError=Re;exports.isPeginFingerprintInputError=Ie;exports.isWotsMismatchError=Te;exports.orderClaimBatchByHtlcVout=ne;exports.rebuildDepositTermsCore=z;exports.rebuildDepositTermsForClaim=ke;exports.reconstructPeginParams=Oe;exports.selectSiblingRegistrations=te;exports.toRefundInputs=De;
2
+ //# sourceMappingURL=toRefundInputs-8DgBT_Bg.cjs.map