@babylonlabs-io/ts-sdk 0.18.0 → 0.20.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 (195) hide show
  1. package/README.md +56 -12
  2. package/dist/bitcoin-CNnPFU6Y.cjs +2 -0
  3. package/dist/bitcoin-CNnPFU6Y.cjs.map +1 -0
  4. package/dist/{constants-Q7v2O7Ps.js → bitcoin-nOOgeRyl.js} +64 -76
  5. package/dist/bitcoin-nOOgeRyl.js.map +1 -0
  6. package/dist/buildAndBroadcastRefund-DWEQvj9T.cjs +2 -0
  7. package/dist/buildAndBroadcastRefund-DWEQvj9T.cjs.map +1 -0
  8. package/dist/buildAndBroadcastRefund-DnTQkCgG.js +1331 -0
  9. package/dist/buildAndBroadcastRefund-DnTQkCgG.js.map +1 -0
  10. package/dist/challengeAssert-D1lpvuMv.js +283 -0
  11. package/dist/challengeAssert-D1lpvuMv.js.map +1 -0
  12. package/dist/challengeAssert-nYlgeAI8.cjs +2 -0
  13. package/dist/challengeAssert-nYlgeAI8.cjs.map +1 -0
  14. package/dist/errors-BZON3Wmn.cjs +2 -0
  15. package/dist/errors-BZON3Wmn.cjs.map +1 -0
  16. package/dist/errors-CHY4WNi-.js +1226 -0
  17. package/dist/errors-CHY4WNi-.js.map +1 -0
  18. package/dist/fundPeginTransaction-BLYXxLBv.js +70 -0
  19. package/dist/fundPeginTransaction-BLYXxLBv.js.map +1 -0
  20. package/dist/fundPeginTransaction-DxNOeyNI.cjs +2 -0
  21. package/dist/fundPeginTransaction-DxNOeyNI.cjs.map +1 -0
  22. package/dist/index-BpXpESWu.cjs +2 -0
  23. package/dist/index-BpXpESWu.cjs.map +1 -0
  24. package/dist/index-CFwoGJNQ.js +1141 -0
  25. package/dist/index-CFwoGJNQ.js.map +1 -0
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.js +134 -100
  28. package/dist/payout-DzGsAnhf.js +261 -0
  29. package/dist/payout-DzGsAnhf.js.map +1 -0
  30. package/dist/payout-RFIh7GLN.cjs +2 -0
  31. package/dist/payout-RFIh7GLN.cjs.map +1 -0
  32. package/dist/psbtInputFields-C-zYR1z7.cjs +2 -0
  33. package/dist/psbtInputFields-C-zYR1z7.cjs.map +1 -0
  34. package/dist/psbtInputFields-Dx41_IoI.js +229 -0
  35. package/dist/psbtInputFields-Dx41_IoI.js.map +1 -0
  36. package/dist/signing-DeWVBl7m.js +64 -0
  37. package/dist/signing-DeWVBl7m.js.map +1 -0
  38. package/dist/signing-cl-lowxV.cjs +2 -0
  39. package/dist/signing-cl-lowxV.cjs.map +1 -0
  40. package/dist/tbv/core/clients/eth/__tests__/protocol-params-reader.test.d.ts +2 -0
  41. package/dist/tbv/core/clients/eth/__tests__/protocol-params-reader.test.d.ts.map +1 -0
  42. package/dist/tbv/core/clients/eth/__tests__/signer-set-reader.test.d.ts +2 -0
  43. package/dist/tbv/core/clients/eth/__tests__/signer-set-reader.test.d.ts.map +1 -0
  44. package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts +18 -0
  45. package/dist/tbv/core/clients/eth/contract-address-resolver.d.ts.map +1 -0
  46. package/dist/tbv/core/clients/eth/index.d.ts +4 -1
  47. package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
  48. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +27 -0
  49. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -0
  50. package/dist/tbv/core/clients/eth/signer-set-reader.d.ts +37 -0
  51. package/dist/tbv/core/clients/eth/signer-set-reader.d.ts.map +1 -0
  52. package/dist/tbv/core/clients/eth/types.d.ts +80 -0
  53. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  54. package/dist/tbv/core/clients/index.cjs +1 -1
  55. package/dist/tbv/core/clients/index.js +25 -21
  56. package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts +74 -0
  57. package/dist/tbv/core/contracts/abis/ApplicationRegistry.abi.d.ts.map +1 -0
  58. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +20 -0
  59. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  60. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +233 -0
  61. package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts.map +1 -0
  62. package/dist/tbv/core/contracts/index.d.ts +2 -0
  63. package/dist/tbv/core/contracts/index.d.ts.map +1 -1
  64. package/dist/tbv/core/index.cjs +1 -1
  65. package/dist/tbv/core/index.d.ts +3 -1
  66. package/dist/tbv/core/index.d.ts.map +1 -1
  67. package/dist/tbv/core/index.js +129 -95
  68. package/dist/tbv/core/managers/PeginManager.d.ts +1 -1
  69. package/dist/tbv/core/primitives/index.cjs +1 -1
  70. package/dist/tbv/core/primitives/index.d.ts +3 -2
  71. package/dist/tbv/core/primitives/index.d.ts.map +1 -1
  72. package/dist/tbv/core/primitives/index.js +24 -23
  73. package/dist/tbv/core/primitives/psbt/__tests__/helpers.d.ts +1 -1
  74. package/dist/tbv/core/primitives/psbt/index.d.ts +1 -1
  75. package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
  76. package/dist/tbv/core/primitives/psbt/pegin.d.ts +2 -3
  77. package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
  78. package/dist/tbv/core/primitives/utils/bitcoin.d.ts +4 -0
  79. package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
  80. package/dist/tbv/core/primitives/utils/index.d.ts +1 -1
  81. package/dist/tbv/core/primitives/utils/index.d.ts.map +1 -1
  82. package/dist/tbv/core/services/activation/__tests__/activateVault.test.d.ts +2 -0
  83. package/dist/tbv/core/services/activation/__tests__/activateVault.test.d.ts.map +1 -0
  84. package/dist/tbv/core/services/activation/activateVault.d.ts +77 -0
  85. package/dist/tbv/core/services/activation/activateVault.d.ts.map +1 -0
  86. package/dist/tbv/core/services/activation/index.d.ts +7 -0
  87. package/dist/tbv/core/services/activation/index.d.ts.map +1 -0
  88. package/dist/tbv/core/services/deposit/__tests__/peginState.test.d.ts +2 -0
  89. package/dist/tbv/core/services/deposit/__tests__/peginState.test.d.ts.map +1 -0
  90. package/dist/tbv/core/services/deposit/__tests__/validation.test.d.ts +5 -0
  91. package/dist/tbv/core/services/deposit/__tests__/validation.test.d.ts.map +1 -0
  92. package/dist/tbv/core/services/deposit/index.d.ts +4 -0
  93. package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
  94. package/dist/tbv/core/services/deposit/peginState.d.ts +93 -0
  95. package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -0
  96. package/dist/tbv/core/services/deposit/validation.d.ts +114 -0
  97. package/dist/tbv/core/services/deposit/validation.d.ts.map +1 -0
  98. package/dist/tbv/core/services/htlc/__tests__/htlc.test.d.ts +2 -0
  99. package/dist/tbv/core/services/htlc/__tests__/htlc.test.d.ts.map +1 -0
  100. package/dist/tbv/core/services/htlc/index.d.ts +25 -0
  101. package/dist/tbv/core/services/htlc/index.d.ts.map +1 -0
  102. package/dist/tbv/core/services/index.cjs +1 -1
  103. package/dist/tbv/core/services/index.d.ts +4 -0
  104. package/dist/tbv/core/services/index.d.ts.map +1 -1
  105. package/dist/tbv/core/services/index.js +25 -5
  106. package/dist/tbv/core/services/index.js.map +1 -1
  107. package/dist/tbv/core/services/pegout/__tests__/state.test.d.ts +2 -0
  108. package/dist/tbv/core/services/pegout/__tests__/state.test.d.ts.map +1 -0
  109. package/dist/tbv/core/services/pegout/index.d.ts +2 -0
  110. package/dist/tbv/core/services/pegout/index.d.ts.map +1 -0
  111. package/dist/tbv/core/services/pegout/state.d.ts +30 -0
  112. package/dist/tbv/core/services/pegout/state.d.ts.map +1 -0
  113. package/dist/tbv/core/services/refund/__tests__/buildAndBroadcastRefund.test.d.ts +2 -0
  114. package/dist/tbv/core/services/refund/__tests__/buildAndBroadcastRefund.test.d.ts.map +1 -0
  115. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +103 -0
  116. package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -0
  117. package/dist/tbv/core/services/refund/errors.d.ts +13 -0
  118. package/dist/tbv/core/services/refund/errors.d.ts.map +1 -0
  119. package/dist/tbv/core/services/refund/index.d.ts +8 -0
  120. package/dist/tbv/core/services/refund/index.d.ts.map +1 -0
  121. package/dist/tbv/core/utils/index.cjs +1 -1
  122. package/dist/tbv/core/utils/index.js +30 -24
  123. package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts +1 -1
  124. package/dist/tbv/core/utils/utxo/__tests__/availability.test.d.ts +3 -0
  125. package/dist/tbv/core/utils/utxo/__tests__/availability.test.d.ts.map +1 -0
  126. package/dist/tbv/core/utils/utxo/__tests__/reservation.test.d.ts +3 -0
  127. package/dist/tbv/core/utils/utxo/__tests__/reservation.test.d.ts.map +1 -0
  128. package/dist/tbv/core/utils/utxo/availability.d.ts +62 -0
  129. package/dist/tbv/core/utils/utxo/availability.d.ts.map +1 -0
  130. package/dist/tbv/core/utils/utxo/index.d.ts +2 -0
  131. package/dist/tbv/core/utils/utxo/index.d.ts.map +1 -1
  132. package/dist/tbv/core/utils/utxo/reservation.d.ts +65 -0
  133. package/dist/tbv/core/utils/utxo/reservation.d.ts.map +1 -0
  134. package/dist/tbv/core/wots/__tests__/blockDerivation.test.d.ts +2 -0
  135. package/dist/tbv/core/wots/__tests__/blockDerivation.test.d.ts.map +1 -0
  136. package/dist/tbv/core/wots/blockDerivation.d.ts +36 -0
  137. package/dist/tbv/core/wots/blockDerivation.d.ts.map +1 -0
  138. package/dist/tbv/core/wots/index.d.ts +1 -0
  139. package/dist/tbv/core/wots/index.d.ts.map +1 -1
  140. package/dist/tbv/index.cjs +1 -1
  141. package/dist/tbv/index.js +129 -95
  142. package/dist/tbv/integrations/aave/index.cjs +1 -1
  143. package/dist/tbv/integrations/aave/index.cjs.map +1 -1
  144. package/dist/tbv/integrations/aave/index.d.ts +3 -3
  145. package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
  146. package/dist/tbv/integrations/aave/index.js +145 -169
  147. package/dist/tbv/integrations/aave/index.js.map +1 -1
  148. package/dist/tbv/integrations/aave/utils/healthFactor.d.ts +0 -30
  149. package/dist/tbv/integrations/aave/utils/healthFactor.d.ts.map +1 -1
  150. package/dist/tbv/integrations/aave/utils/index.d.ts +2 -2
  151. package/dist/tbv/integrations/aave/utils/index.d.ts.map +1 -1
  152. package/dist/types-B-p4dhEH.cjs +2 -0
  153. package/dist/types-B-p4dhEH.cjs.map +1 -0
  154. package/dist/types-DWjaqVfP.js +608 -0
  155. package/dist/types-DWjaqVfP.js.map +1 -0
  156. package/package.json +5 -1
  157. package/dist/challengeAssert-D_k_ADgP.cjs +0 -2
  158. package/dist/challengeAssert-D_k_ADgP.cjs.map +0 -1
  159. package/dist/challengeAssert-k5_LWUtO.js +0 -362
  160. package/dist/challengeAssert-k5_LWUtO.js.map +0 -1
  161. package/dist/constants-EiyZkXce.cjs +0 -2
  162. package/dist/constants-EiyZkXce.cjs.map +0 -1
  163. package/dist/constants-Q7v2O7Ps.js.map +0 -1
  164. package/dist/errors-DAKpPfl7.cjs +0 -2
  165. package/dist/errors-DAKpPfl7.cjs.map +0 -1
  166. package/dist/errors-DARTQrP3.js +0 -1510
  167. package/dist/errors-DARTQrP3.js.map +0 -1
  168. package/dist/fundPeginTransaction-DpwnDslW.js +0 -50
  169. package/dist/fundPeginTransaction-DpwnDslW.js.map +0 -1
  170. package/dist/fundPeginTransaction-EbrZzlrh.cjs +0 -2
  171. package/dist/fundPeginTransaction-EbrZzlrh.cjs.map +0 -1
  172. package/dist/index-DKfhZvdn.cjs +0 -2
  173. package/dist/index-DKfhZvdn.cjs.map +0 -1
  174. package/dist/index-qIcjkxLw.js +0 -911
  175. package/dist/index-qIcjkxLw.js.map +0 -1
  176. package/dist/payout-Ce9vSs9e.js +0 -164
  177. package/dist/payout-Ce9vSs9e.js.map +0 -1
  178. package/dist/payout-CfsDnjKI.cjs +0 -2
  179. package/dist/payout-CfsDnjKI.cjs.map +0 -1
  180. package/dist/psbtInputFields-C0nKn_GD.cjs +0 -2
  181. package/dist/psbtInputFields-C0nKn_GD.cjs.map +0 -1
  182. package/dist/psbtInputFields-DO0ELwiv.js +0 -116
  183. package/dist/psbtInputFields-DO0ELwiv.js.map +0 -1
  184. package/dist/signAndSubmitPayouts-CAOEAQp9.js +0 -490
  185. package/dist/signAndSubmitPayouts-CAOEAQp9.js.map +0 -1
  186. package/dist/signAndSubmitPayouts-CSJmcPQN.cjs +0 -2
  187. package/dist/signAndSubmitPayouts-CSJmcPQN.cjs.map +0 -1
  188. package/dist/signing-Deg5lCoC.cjs +0 -2
  189. package/dist/signing-Deg5lCoC.cjs.map +0 -1
  190. package/dist/signing-Drwr3bXB.js +0 -16
  191. package/dist/signing-Drwr3bXB.js.map +0 -1
  192. package/dist/types-D1rYwwCu.js +0 -235
  193. package/dist/types-D1rYwwCu.js.map +0 -1
  194. package/dist/types-DEWiqXYp.cjs +0 -2
  195. package/dist/types-DEWiqXYp.cjs.map +0 -1
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Vault status — combines on-chain contract status (0-4) with indexer-derived
3
+ * statuses (5-7). The contract enum (BTCVaultRegistry.sol BTCVaultStatus) only
4
+ * has: Pending(0), Verified(1), Active(2), Redeemed(3), Expired(4).
5
+ * The indexer maps these and adds extra statuses for UI display.
6
+ *
7
+ * IMPORTANT: With the new contract architecture:
8
+ * - Core vault status (BTCVaultRegistry) does NOT change when used by applications
9
+ * - Vaults remain at ACTIVE status even when used in DeFi positions
10
+ * - Application usage status is tracked separately by each integration controller
11
+ */
12
+ export declare enum ContractStatus {
13
+ /** Status 0: Request submitted, waiting for ACKs */
14
+ PENDING = 0,
15
+ /** Status 1: All ACKs collected, ready for secret activation */
16
+ VERIFIED = 1,
17
+ /** Status 2: HTLC secret revealed, vault is active and usable (stays here even when used by apps) */
18
+ ACTIVE = 2,
19
+ /** Status 3: Vault has been redeemed, BTC is claimable */
20
+ REDEEMED = 3,
21
+ /** Status 4 (indexer-only): Vault was liquidated (collateral seized due to unpaid debt) */
22
+ LIQUIDATED = 4,
23
+ /** Status 5 (indexer-only): Vault is invalid — BTC UTXOs were spent in a different transaction */
24
+ INVALID = 5,
25
+ /** Status 6 (indexer-only): Depositor has withdrawn their BTC (redemption complete) */
26
+ DEPOSITOR_WITHDRAWN = 6,
27
+ /** Status 7 (indexer-only): Vault expired due to AckTimeout or ActivationTimeout */
28
+ EXPIRED = 7
29
+ }
30
+ /** Reason why a vault expired */
31
+ export type ExpirationReason = "ack_timeout" | "proof_timeout" | "activation_timeout";
32
+ /**
33
+ * Available actions user can take
34
+ */
35
+ export declare enum PeginAction {
36
+ /** Submit WOTS key (re-enter mnemonic) */
37
+ SUBMIT_WOTS_KEY = "SUBMIT_WOTS_KEY",
38
+ /** Sign payout transactions */
39
+ SIGN_PAYOUT_TRANSACTIONS = "SIGN_PAYOUT_TRANSACTIONS",
40
+ /** Sign and broadcast peg-in transaction to Bitcoin */
41
+ SIGN_AND_BROADCAST_TO_BITCOIN = "SIGN_AND_BROADCAST_TO_BITCOIN",
42
+ /** Reveal HTLC secret on Ethereum to activate vault */
43
+ ACTIVATE_VAULT = "ACTIVATE_VAULT",
44
+ /** Sign and broadcast HTLC refund transaction for an expired vault */
45
+ REFUND_HTLC = "REFUND_HTLC"
46
+ }
47
+ /**
48
+ * Protocol-level peg-in state (framework-agnostic)
49
+ */
50
+ export interface PeginProtocolState {
51
+ /** Smart contract status (source of truth for on-chain state) */
52
+ contractStatus: ContractStatus;
53
+ /** Available user actions (empty array when no action is available) */
54
+ availableActions: PeginAction[];
55
+ }
56
+ /**
57
+ * Options for getPeginProtocolState function.
58
+ *
59
+ * All fields represent protocol-level state from the vault provider or
60
+ * on-chain contracts. Client-side tracking (localStorage, polling state)
61
+ * is NOT included — consumers handle that in their own layer.
62
+ */
63
+ export interface GetPeginProtocolStateOptions {
64
+ /** Whether claim/payout transactions are ready from VP */
65
+ transactionsReady?: boolean;
66
+ /** Whether the vault provider is waiting for the depositor's WOTS public key */
67
+ needsWotsKey?: boolean;
68
+ /** Whether the vault provider hasn't ingested this peg-in yet */
69
+ pendingIngestion?: boolean;
70
+ /** Whether the depositor can refund the HTLC (Pre-PegIn tx available) */
71
+ canRefund?: boolean;
72
+ /** Whether the vault provider reported a terminal failure */
73
+ hasProviderTerminalFailure?: boolean;
74
+ }
75
+ /**
76
+ * Determine the current protocol state and available actions based on contract
77
+ * status and vault provider state. Framework-agnostic: returns only
78
+ * protocol-level data with no display labels, messages, or UI concerns.
79
+ *
80
+ * Client-side tracking overrides (e.g. suppressing actions after the user
81
+ * has already acted but on-chain state hasn't caught up) are the caller's
82
+ * responsibility.
83
+ *
84
+ * @param contractStatus - On-chain contract status (source of truth)
85
+ * @param options - Vault provider state
86
+ * @returns Protocol state with available actions
87
+ */
88
+ export declare function getPeginProtocolState(contractStatus: ContractStatus, options?: GetPeginProtocolStateOptions): PeginProtocolState;
89
+ /**
90
+ * Check if a specific action is available in the current state
91
+ */
92
+ export declare function canPerformAction(state: PeginProtocolState, action: PeginAction): boolean;
93
+ //# sourceMappingURL=peginState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peginState.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/deposit/peginState.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,oBAAY,cAAc;IACxB,oDAAoD;IACpD,OAAO,IAAI;IACX,gEAAgE;IAChE,QAAQ,IAAI;IACZ,qGAAqG;IACrG,MAAM,IAAI;IACV,0DAA0D;IAC1D,QAAQ,IAAI;IACZ,2FAA2F;IAC3F,UAAU,IAAI;IACd,kGAAkG;IAClG,OAAO,IAAI;IACX,uFAAuF;IACvF,mBAAmB,IAAI;IACvB,oFAAoF;IACpF,OAAO,IAAI;CACZ;AAED,iCAAiC;AACjC,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,eAAe,GACf,oBAAoB,CAAC;AAMzB;;GAEG;AACH,oBAAY,WAAW;IACrB,0CAA0C;IAC1C,eAAe,oBAAoB;IACnC,+BAA+B;IAC/B,wBAAwB,6BAA6B;IACrD,uDAAuD;IACvD,6BAA6B,kCAAkC;IAC/D,uDAAuD;IACvD,cAAc,mBAAmB;IACjC,sEAAsE;IACtE,WAAW,gBAAgB;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,cAAc,EAAE,cAAc,CAAC;IAC/B,uEAAuE;IACvE,gBAAgB,EAAE,WAAW,EAAE,CAAC;CACjC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,4BAA4B;IAC3C,0DAA0D;IAC1D,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gFAAgF;IAChF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,yEAAyE;IACzE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6DAA6D;IAC7D,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,cAAc,EAC9B,OAAO,GAAE,4BAAiC,GACzC,kBAAkB,CA6EpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,WAAW,GAClB,OAAO,CAET"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Pure validation functions for deposit operations.
3
+ *
4
+ * All validations return a consistent {@link ValidationResult} format or throw
5
+ * on critical failures (e.g. missing protocol participants).
6
+ *
7
+ * Business rules (single-provider limit, max vault count) and form-flow
8
+ * checks (wallet connected) belong in the consumer layer.
9
+ *
10
+ * @module tbv/core/services/deposit/validation
11
+ */
12
+ export interface ValidationResult {
13
+ valid: boolean;
14
+ error?: string;
15
+ warnings?: string[];
16
+ }
17
+ /**
18
+ * Parameters for checking if a deposit form is valid.
19
+ */
20
+ export interface DepositFormValidityParams {
21
+ /** Deposit amount in satoshis */
22
+ amountSats: bigint;
23
+ /** Minimum deposit from protocol params */
24
+ minDeposit: bigint;
25
+ /** Maximum deposit from protocol params (optional) */
26
+ maxDeposit?: bigint;
27
+ /** User's available BTC balance in satoshis */
28
+ btcBalance: bigint;
29
+ /** Estimated transaction fee in satoshis */
30
+ estimatedFeeSats?: bigint;
31
+ /** Depositor claim value in satoshis (required output for challenge transactions) */
32
+ depositorClaimValue?: bigint;
33
+ }
34
+ export interface RemainingCapacityParams {
35
+ /** Requested deposit amount in satoshis */
36
+ amount: bigint;
37
+ /**
38
+ * Effective remaining capacity in satoshis (min of protocol-total and
39
+ * per-address remaining). `null` means no cap applies.
40
+ */
41
+ effectiveRemaining: bigint | null;
42
+ }
43
+ /** Narrow structural type for UTXO — avoids importing vault-specific types. */
44
+ interface UtxoLike {
45
+ txid: string;
46
+ vout: number;
47
+ value: number;
48
+ }
49
+ /**
50
+ * Parameters for validating multi-vault deposit flow inputs.
51
+ *
52
+ * Callers must resolve any async loading states before calling — the SDK
53
+ * validates resolved data, not React hook state.
54
+ *
55
+ * Form-flow checks (wallet connected, provider selected) are the caller's
56
+ * responsibility and are NOT performed here.
57
+ */
58
+ export interface MultiVaultDepositFlowInputs {
59
+ vaultAmounts: bigint[];
60
+ confirmedUTXOs: UtxoLike[];
61
+ vaultProviderBtcPubkey: string;
62
+ vaultKeeperBtcPubkeys: string[];
63
+ universalChallengerBtcPubkeys: string[];
64
+ /** Protocol minimum deposit per vault (satoshis) */
65
+ minDeposit: bigint;
66
+ /** Protocol maximum deposit per vault (satoshis) */
67
+ maxDeposit?: bigint;
68
+ /** Number of HTLC secret hexes — must match vaultAmounts.length */
69
+ htlcSecretHexesLength: number;
70
+ /** Number of depositor secret hashes — must match vaultAmounts.length */
71
+ depositorSecretHashesLength: number;
72
+ }
73
+ /**
74
+ * Check if deposit amount is within valid range and affordable.
75
+ *
76
+ * Returns false when fees/claim value are not yet known (still loading),
77
+ * and includes them in the balance check once available.
78
+ */
79
+ export declare function isDepositAmountValid(params: DepositFormValidityParams): boolean;
80
+ /**
81
+ * Validate deposit amount against minimum and maximum constraints.
82
+ */
83
+ export declare function validateDepositAmount(amount: bigint, minDeposit: bigint, maxDeposit?: bigint): ValidationResult;
84
+ /**
85
+ * Validate that the requested deposit fits within the effective remaining cap.
86
+ */
87
+ export declare function validateRemainingCapacity(params: RemainingCapacityParams): ValidationResult;
88
+ /**
89
+ * Validate that selected providers exist in the available set.
90
+ *
91
+ * Business rules (e.g. single-provider limit) are the caller's responsibility.
92
+ */
93
+ export declare function validateProviderSelection(selectedProviders: string[], availableProviders: string[]): ValidationResult;
94
+ /**
95
+ * Validate vault amounts array for multi-vault deposits.
96
+ * Checks count, positivity, and per-vault min/max protocol limits.
97
+ *
98
+ * Max vault count limits are the caller's responsibility.
99
+ */
100
+ export declare function validateVaultAmounts(amounts: bigint[], minDeposit?: bigint, maxDeposit?: bigint): ValidationResult;
101
+ /**
102
+ * Validate vault provider BTC public key format.
103
+ */
104
+ export declare function validateVaultProviderPubkey(pubkey: string): ValidationResult;
105
+ /**
106
+ * Validate protocol-level multi-vault deposit inputs.
107
+ * Throws an error if any validation fails.
108
+ *
109
+ * Form-flow checks (wallet connections, provider selection) must be
110
+ * performed by the caller before invoking this function.
111
+ */
112
+ export declare function validateMultiVaultDepositInputs(params: MultiVaultDepositFlowInputs): void;
113
+ export {};
114
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/deposit/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,qFAAqF;IACrF,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,uBAAuB;IACtC,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,+EAA+E;AAC/E,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,cAAc,EAAE,QAAQ,EAAE,CAAC;IAC3B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,6BAA6B,EAAE,MAAM,EAAE,CAAC;IACxC,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yEAAyE;IACzE,2BAA2B,EAAE,MAAM,CAAC;CACrC;AAcD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAoBT;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB,CAuBlB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,uBAAuB,GAC9B,gBAAgB,CAmBlB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,kBAAkB,EAAE,MAAM,EAAE,GAC3B,gBAAgB,CAuBlB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB,CA+BlB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAU5E;AAqCD;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,2BAA2B,GAClC,IAAI,CA4CN"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=htlc.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"htlc.test.d.ts","sourceRoot":"","sources":["../../../../../../src/tbv/core/services/htlc/__tests__/htlc.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { Hex } from 'viem';
2
+ /**
3
+ * Compute the SHA-256 hashlock from a secret preimage.
4
+ *
5
+ * Matches the on-chain validation: `sha256(abi.encodePacked(s))` where `s` is a `bytes32`.
6
+ * `abi.encodePacked(bytes32)` is just the raw 32 bytes — no ABI padding.
7
+ *
8
+ * @param secret - 0x-prefixed bytes32 secret (66 hex chars)
9
+ * @returns 0x-prefixed bytes32 SHA-256 hash
10
+ * @throws if secret is not exactly 32 bytes
11
+ */
12
+ export declare function computeHashlock(secret: Hex): Hex;
13
+ /**
14
+ * Validate that a secret's SHA-256 hash matches the expected hashlock.
15
+ *
16
+ * Use this for client-side pre-validation before sending the activation
17
+ * transaction to avoid wasting gas on a contract revert.
18
+ *
19
+ * @param secret - 0x-prefixed bytes32 secret (66 hex chars)
20
+ * @param hashlock - 0x-prefixed bytes32 expected hashlock from the vault
21
+ * @returns true if SHA-256(secret) matches the hashlock
22
+ * @throws if secret or hashlock is not exactly 32 bytes
23
+ */
24
+ export declare function validateSecretAgainstHashlock(secret: Hex, hashlock: Hex): boolean;
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/htlc/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAgDhC;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAKhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,GAAG,EACX,QAAQ,EAAE,GAAG,GACZ,OAAO,CAQT"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../signAndSubmitPayouts-CSJmcPQN.cjs");exports.pollAndSignPayouts=t.pollAndSignPayouts;exports.signDepositorGraph=t.signDepositorGraph;exports.submitWotsPublicKey=t.submitWotsPublicKey;exports.waitForPeginStatus=t.waitForPeginStatus;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../buildAndBroadcastRefund-DWEQvj9T.cjs"),a=require("../../../signing-cl-lowxV.cjs");exports.BIP68NotMatureError=t.BIP68NotMatureError;exports.ClaimerPegoutStatusValue=t.ClaimerPegoutStatusValue;exports.activateVault=t.activateVault;exports.buildAndBroadcastRefund=t.buildAndBroadcastRefund;exports.computeHashlock=t.computeHashlock;exports.isDepositAmountValid=t.isDepositAmountValid;exports.isPegoutTerminalStatus=t.isPegoutTerminalStatus;exports.isRecognizedPegoutStatus=t.isRecognizedPegoutStatus;exports.pollAndSignPayouts=t.pollAndSignPayouts;exports.signDepositorGraph=t.signDepositorGraph;exports.submitWotsPublicKey=t.submitWotsPublicKey;exports.validateDepositAmount=t.validateDepositAmount;exports.validateMultiVaultDepositInputs=t.validateMultiVaultDepositInputs;exports.validateProviderSelection=t.validateProviderSelection;exports.validateRemainingCapacity=t.validateRemainingCapacity;exports.validateSecretAgainstHashlock=t.validateSecretAgainstHashlock;exports.validateVaultAmounts=t.validateVaultAmounts;exports.validateVaultProviderPubkey=t.validateVaultProviderPubkey;exports.waitForPeginStatus=t.waitForPeginStatus;exports.ContractStatus=a.ContractStatus;exports.PeginAction=a.PeginAction;exports.canPerformAction=a.canPerformAction;exports.getPeginProtocolState=a.getPeginProtocolState;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -6,5 +6,9 @@
6
6
  *
7
7
  * @module services
8
8
  */
9
+ export * from './activation';
9
10
  export * from './deposit';
11
+ export * from './htlc';
12
+ export * from './pegout';
13
+ export * from './refund';
10
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/services/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tbv/core/services/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -1,8 +1,28 @@
1
- import { p as o, a as t, s as i, w as p } from "../../../signAndSubmitPayouts-CAOEAQp9.js";
1
+ import { B as s, C as e, a as i, m as o, h as u, i as l, l as r, k as n, p as d, b as c, s as P, v as g, g as m, d as p, c as v, j as S, e as A, f as V, w as b } from "../../../buildAndBroadcastRefund-DnTQkCgG.js";
2
+ import { C, P as h, a as k, g as y } from "../../../signing-DeWVBl7m.js";
2
3
  export {
3
- o as pollAndSignPayouts,
4
- t as signDepositorGraph,
5
- i as submitWotsPublicKey,
6
- p as waitForPeginStatus
4
+ s as BIP68NotMatureError,
5
+ e as ClaimerPegoutStatusValue,
6
+ C as ContractStatus,
7
+ h as PeginAction,
8
+ i as activateVault,
9
+ o as buildAndBroadcastRefund,
10
+ k as canPerformAction,
11
+ u as computeHashlock,
12
+ y as getPeginProtocolState,
13
+ l as isDepositAmountValid,
14
+ r as isPegoutTerminalStatus,
15
+ n as isRecognizedPegoutStatus,
16
+ d as pollAndSignPayouts,
17
+ c as signDepositorGraph,
18
+ P as submitWotsPublicKey,
19
+ g as validateDepositAmount,
20
+ m as validateMultiVaultDepositInputs,
21
+ p as validateProviderSelection,
22
+ v as validateRemainingCapacity,
23
+ S as validateSecretAgainstHashlock,
24
+ A as validateVaultAmounts,
25
+ V as validateVaultProviderPubkey,
26
+ b as waitForPeginStatus
7
27
  };
8
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=state.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.test.d.ts","sourceRoot":"","sources":["../../../../../../src/tbv/core/services/pegout/__tests__/state.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { ClaimerPegoutStatusValue, isRecognizedPegoutStatus, isPegoutTerminalStatus, } from './state';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/pegout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Pegout state definitions and protocol-level terminal checks.
3
+ *
4
+ * Maps VP-reported pegout statuses from `vaultProvider_getPegoutStatus`
5
+ * to protocol lifecycle states.
6
+ *
7
+ * Lifecycle:
8
+ * ClaimEventReceived -> ClaimBroadcast -> AssertBroadcast -> PayoutBroadcast (success)
9
+ * > ChallengeAssertObserved -> WronglyChallengedBroadcast -> PayoutBroadcast
10
+ * > ChallengeAssertObserved -> Failed (challenger won)
11
+ */
12
+ /** Claimer-side pegout statuses reported by the VP. */
13
+ export declare enum ClaimerPegoutStatusValue {
14
+ CLAIM_EVENT_RECEIVED = "ClaimEventReceived",
15
+ CLAIM_BROADCAST = "ClaimBroadcast",
16
+ ASSERT_BROADCAST = "AssertBroadcast",
17
+ CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved",
18
+ WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast",
19
+ PAYOUT_BROADCAST = "PayoutBroadcast",
20
+ FAILED = "Failed"
21
+ }
22
+ /** Whether a claimer status string maps to a known pegout state. */
23
+ export declare function isRecognizedPegoutStatus(status: string): boolean;
24
+ /**
25
+ * Whether a claimer status is a hard-terminal pegout status
26
+ * (PayoutBroadcast or Failed). Soft-terminal conditions (polling
27
+ * thresholds) are a consumer-side concern.
28
+ */
29
+ export declare function isPegoutTerminalStatus(claimerStatus: string | undefined): boolean;
30
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/pegout/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,uDAAuD;AACvD,oBAAY,wBAAwB;IAClC,oBAAoB,uBAAuB;IAC3C,eAAe,mBAAmB;IAClC,gBAAgB,oBAAoB;IACpC,yBAAyB,4BAA4B;IACrD,4BAA4B,+BAA+B;IAC3D,gBAAgB,oBAAoB;IACpC,MAAM,WAAW;CAClB;AAOD,oEAAoE;AACpE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAIhE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,OAAO,CAET"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=buildAndBroadcastRefund.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildAndBroadcastRefund.test.d.ts","sourceRoot":"","sources":["../../../../../../src/tbv/core/services/refund/__tests__/buildAndBroadcastRefund.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,103 @@
1
+ import { Network } from '@babylonlabs-io/babylon-tbv-rust-wasm';
2
+ import { Address, Hex } from 'viem';
3
+ import { SignPsbtOptions } from '../../../../shared/wallets/interfaces/BitcoinWallet';
4
+ /**
5
+ * Authoritative vault fields needed to build a refund. Versioning fields,
6
+ * the hashlock, and htlcVout must come from the on-chain contract (never the
7
+ * indexer). The amount + `unsignedPrePeginTxHex` + `depositorBtcPubkey` can
8
+ * come from the indexer since they are not security-critical for signing
9
+ * (the PSBT builder re-derives the HTLC script from on-chain params).
10
+ */
11
+ export interface VaultRefundData {
12
+ hashlock: Hex;
13
+ htlcVout: number;
14
+ offchainParamsVersion: number;
15
+ appVaultKeepersVersion: number;
16
+ universalChallengersVersion: number;
17
+ vaultProvider: Address;
18
+ applicationEntryPoint: Address;
19
+ /** Pre-PegIn HTLC output value in satoshis. */
20
+ amount: bigint;
21
+ /** Funded (but pre-witness) Pre-PegIn transaction hex. 0x prefix optional. */
22
+ unsignedPrePeginTxHex: string;
23
+ /** Depositor's BTC public key (x-only or compressed hex; 0x prefix optional). */
24
+ depositorBtcPubkey: string;
25
+ }
26
+ /**
27
+ * Version-resolved protocol context that parameterises the HTLC's taproot
28
+ * scripts. The *signer-set* fields (`vaultKeeperPubkeys`,
29
+ * `universalChallengerPubkeys`) and the version-locked numeric protocol
30
+ * params **must** be sourced from the on-chain contract at the version
31
+ * pinned in {@link VaultRefundData} — this is the trust boundary.
32
+ * `vaultProviderPubkey` today is sourced from the GraphQL indexer via
33
+ * `fetchVaultProviderById`; the caller is responsible for any additional
34
+ * cross-check it requires. Keeper and challenger pubkey arrays must be
35
+ * pre-sorted the same way the Rust protocol sorts them (canonical for
36
+ * script derivation).
37
+ */
38
+ export interface RefundPrePeginContext {
39
+ vaultProviderPubkey: string;
40
+ vaultKeeperPubkeys: readonly string[];
41
+ universalChallengerPubkeys: readonly string[];
42
+ timelockRefund: number;
43
+ feeRate: bigint;
44
+ numLocalChallengers: number;
45
+ councilQuorum: number;
46
+ councilSize: number;
47
+ network: Network;
48
+ }
49
+ /** Minimum shape required from a broadcast result. */
50
+ export interface BtcBroadcastResult {
51
+ txId: string;
52
+ }
53
+ export type BtcBroadcaster<R extends BtcBroadcastResult = BtcBroadcastResult> = (signedTxHex: string) => Promise<R>;
54
+ export type RefundPsbtSigner = (psbtHex: string, opts: SignPsbtOptions) => Promise<string>;
55
+ export interface RefundInput<R extends BtcBroadcastResult = BtcBroadcastResult> {
56
+ vaultId: Hex;
57
+ /**
58
+ * Fetch authoritative on-chain + indexer vault data. The SDK passes no
59
+ * arguments — the caller closes over `vaultId` (or any other context it
60
+ * needs).
61
+ */
62
+ readVault: () => Promise<VaultRefundData>;
63
+ /**
64
+ * Fetch the version-pinned refund context (sorted pubkeys, timelock, etc.)
65
+ * derived from the vault's locked versions.
66
+ */
67
+ readPrePeginContext: (vault: VaultRefundData) => Promise<RefundPrePeginContext>;
68
+ /**
69
+ * Mempool-derived sat/vB fee rate to use for the refund tx (positive
70
+ * number). Caller fetches this before invoking — it does not depend on
71
+ * any value the SDK computes, and folding it into the call keeps the
72
+ * orchestration honest.
73
+ */
74
+ feeRate: number;
75
+ /** BTC wallet signer; receives a PSBT hex + taproot script-path options. */
76
+ signPsbt: RefundPsbtSigner;
77
+ /** Broadcast callback — returns whatever shape the caller needs. */
78
+ broadcastTx: BtcBroadcaster<R>;
79
+ /** Checked at every async boundary. */
80
+ signal?: AbortSignal;
81
+ }
82
+ /**
83
+ * Build, sign, and broadcast a refund transaction for an expired vault.
84
+ *
85
+ * Trust boundary: `readVault` must source the hashlock, htlcVout, and
86
+ * versioning fields from the on-chain contract — an indexer-only path
87
+ * leaves the refund flow open to signer-set substitution. The SDK does
88
+ * not enforce this; it is the caller's responsibility.
89
+ *
90
+ * The broadcast transport is expected to surface Bitcoin's `non-BIP68-final`
91
+ * policy rejection as an `Error` whose message contains that string; when
92
+ * it does, the SDK wraps it in {@link BIP68NotMatureError}. All other
93
+ * transport errors propagate unchanged.
94
+ *
95
+ * @returns whatever the injected `broadcastTx` returns (generic pass-through)
96
+ * @throws `Error` if any validation fails
97
+ * @throws {@link BIP68NotMatureError} if the broadcast is rejected because
98
+ * the refund CSV timelock has not yet matured
99
+ * @throws anything `readVault`, `readPrePeginContext`,
100
+ * `signPsbt`, or `broadcastTx` throws
101
+ */
102
+ export declare function buildAndBroadcastRefund<R extends BtcBroadcastResult = BtcBroadcastResult>(input: RefundInput<R>): Promise<R>;
103
+ //# sourceMappingURL=buildAndBroadcastRefund.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildAndBroadcastRefund.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/refund/buildAndBroadcastRefund.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qDAAqD,CAAC;AA4C3F;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,2BAA2B,EAAE,MAAM,CAAC;IACpC,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iFAAiF;IACjF,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,qBAAqB;IACpC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,0BAA0B,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9C,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,sDAAsD;AACtD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,cAAc,CACxB,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,IAC/C,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAExC,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,eAAe,KAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,WAAW,WAAW,CAC1B,CAAC,SAAS,kBAAkB,GAAG,kBAAkB;IAEjD,OAAO,EAAE,GAAG,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;IAC1C;;;OAGG;IACH,mBAAmB,EAAE,CACnB,KAAK,EAAE,eAAe,KACnB,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,oEAAoE;IACpE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC/B,uCAAuC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAqGD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,uBAAuB,CAC3C,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,EACjD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAuEnC"}
@@ -0,0 +1,13 @@
1
+ import { Hex } from 'viem';
2
+ /**
3
+ * Thrown when the broadcast transport rejects the refund tx because the CSV
4
+ * timelock has not yet matured (BIP68 non-final). Callers can surface a
5
+ * friendly "wait until block N" message; the original transport error is
6
+ * available via {@link cause}.
7
+ */
8
+ export declare class BIP68NotMatureError extends Error {
9
+ readonly vaultId: Hex;
10
+ readonly cause: Error;
11
+ constructor(vaultId: Hex, cause: Error);
12
+ }
13
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/refund/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,OAAO,EAAE,GAAG,CAAC;IAC7B,SAAyB,KAAK,EAAE,KAAK,CAAC;gBAE1B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK;CAMvC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Vault refund service — reclaim BTC from an expired Pre-PegIn HTLC.
3
+ *
4
+ * @module services/refund
5
+ */
6
+ export { BIP68NotMatureError } from './errors';
7
+ export { buildAndBroadcastRefund, type BtcBroadcastResult, type BtcBroadcaster, type RefundInput, type RefundPrePeginContext, type RefundPsbtSigner, type VaultRefundData, } from './buildAndBroadcastRefund';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tbv/core/services/refund/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,2BAA2B,CAAC"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../constants-EiyZkXce.cjs"),e=require("../../../psbtInputFields-C0nKn_GD.cjs"),T=require("../../../fundPeginTransaction-EbrZzlrh.cjs"),_=require("../../../signing-Deg5lCoC.cjs");exports.BTC_DUST_SAT=t.BTC_DUST_SAT;exports.DUST_THRESHOLD=t.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=t.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=t.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=t.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=t.P2TR_INPUT_SIZE;exports.PEGIN_FIXED_OUTPUTS=t.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=t.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=t.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=t.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.getNetwork=t.getNetwork;exports.peginOutputCount=t.peginOutputCount;exports.rateBasedTxBufferFee=t.rateBasedTxBufferFee;exports.BitcoinScriptType=e.BitcoinScriptType;exports.calculateBtcTxHash=e.calculateBtcTxHash;exports.getDustThreshold=e.getDustThreshold;exports.getPsbtInputFields=e.getPsbtInputFields;exports.getScriptType=e.getScriptType;exports.selectUtxosForPegin=e.selectUtxosForPegin;exports.shouldAddChangeOutput=e.shouldAddChangeOutput;exports.fundPeginTransaction=T.fundPeginTransaction;exports.parseUnfundedWasmTransaction=T.parseUnfundedWasmTransaction;exports.createTaprootScriptPathSignOptions=_.createTaprootScriptPathSignOptions;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../../signing-cl-lowxV.cjs"),t=require("../../../fundPeginTransaction-DxNOeyNI.cjs"),e=require("../../../psbtInputFields-C-zYR1z7.cjs"),s=require("../../../bitcoin-CNnPFU6Y.cjs");exports.createTaprootScriptPathSignOptions=T.createTaprootScriptPathSignOptions;exports.BTC_DUST_SAT=t.BTC_DUST_SAT;exports.DUST_THRESHOLD=t.DUST_THRESHOLD;exports.FEE_SAFETY_MARGIN=t.FEE_SAFETY_MARGIN;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=t.LOW_RATE_ESTIMATION_ACCURACY_BUFFER;exports.MAX_NON_LEGACY_OUTPUT_SIZE=t.MAX_NON_LEGACY_OUTPUT_SIZE;exports.P2TR_INPUT_SIZE=t.P2TR_INPUT_SIZE;exports.PEGIN_FIXED_OUTPUTS=t.PEGIN_FIXED_OUTPUTS;exports.SPLIT_TX_FEE_SAFETY_MULTIPLIER=t.SPLIT_TX_FEE_SAFETY_MULTIPLIER;exports.TX_BUFFER_SIZE_OVERHEAD=t.TX_BUFFER_SIZE_OVERHEAD;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=t.WALLET_RELAY_FEE_RATE_THRESHOLD;exports.fundPeginTransaction=t.fundPeginTransaction;exports.parseUnfundedWasmTransaction=t.parseUnfundedWasmTransaction;exports.peginOutputCount=t.peginOutputCount;exports.rateBasedTxBufferFee=t.rateBasedTxBufferFee;exports.BitcoinScriptType=e.BitcoinScriptType;exports.UtxoNotAvailableError=e.UtxoNotAvailableError;exports.assertUtxosAvailable=e.assertUtxosAvailable;exports.calculateBtcTxHash=e.calculateBtcTxHash;exports.collectReservedUtxoRefs=e.collectReservedUtxoRefs;exports.extractInputsFromTransaction=e.extractInputsFromTransaction;exports.getDustThreshold=e.getDustThreshold;exports.getPsbtInputFields=e.getPsbtInputFields;exports.getScriptType=e.getScriptType;exports.selectUtxosForDeposit=e.selectUtxosForDeposit;exports.selectUtxosForPegin=e.selectUtxosForPegin;exports.shouldAddChangeOutput=e.shouldAddChangeOutput;exports.validateUtxosAvailable=e.validateUtxosAvailable;exports.getNetwork=s.getNetwork;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,30 +1,36 @@
1
- import { B as t, D as T, F as e, L as _, M as E, P as r, c as o, S, T as p, W as n, g as A, f as c, r as F } from "../../../constants-Q7v2O7Ps.js";
2
- import { B as I, c as U, g as u, d as P, b as R, s as g, a as L } from "../../../psbtInputFields-DO0ELwiv.js";
3
- import { f as d, p as f } from "../../../fundPeginTransaction-DpwnDslW.js";
4
- import { c as D } from "../../../signing-Drwr3bXB.js";
1
+ import { c as t } from "../../../signing-DeWVBl7m.js";
2
+ import { B as T, D as o, F as r, L as _, M as E, P as i, a as n, S as p, T as U, W as c, f as A, b as S, p as l, r as F } from "../../../fundPeginTransaction-BLYXxLBv.js";
3
+ import { B as R, U as u, a as x, f as d, c as P, e as f, g, i as L, h as O, s as B, b as D, d as N, v as h } from "../../../psbtInputFields-Dx41_IoI.js";
4
+ import { g as b } from "../../../bitcoin-nOOgeRyl.js";
5
5
  export {
6
- t as BTC_DUST_SAT,
7
- I as BitcoinScriptType,
8
- T as DUST_THRESHOLD,
9
- e as FEE_SAFETY_MARGIN,
6
+ T as BTC_DUST_SAT,
7
+ R as BitcoinScriptType,
8
+ o as DUST_THRESHOLD,
9
+ r as FEE_SAFETY_MARGIN,
10
10
  _ as LOW_RATE_ESTIMATION_ACCURACY_BUFFER,
11
11
  E as MAX_NON_LEGACY_OUTPUT_SIZE,
12
- r as P2TR_INPUT_SIZE,
13
- o as PEGIN_FIXED_OUTPUTS,
14
- S as SPLIT_TX_FEE_SAFETY_MULTIPLIER,
15
- p as TX_BUFFER_SIZE_OVERHEAD,
16
- n as WALLET_RELAY_FEE_RATE_THRESHOLD,
17
- U as calculateBtcTxHash,
18
- D as createTaprootScriptPathSignOptions,
19
- d as fundPeginTransaction,
20
- u as getDustThreshold,
21
- A as getNetwork,
22
- P as getPsbtInputFields,
23
- R as getScriptType,
24
- f as parseUnfundedWasmTransaction,
25
- c as peginOutputCount,
12
+ i as P2TR_INPUT_SIZE,
13
+ n as PEGIN_FIXED_OUTPUTS,
14
+ p as SPLIT_TX_FEE_SAFETY_MULTIPLIER,
15
+ U as TX_BUFFER_SIZE_OVERHEAD,
16
+ u as UtxoNotAvailableError,
17
+ c as WALLET_RELAY_FEE_RATE_THRESHOLD,
18
+ x as assertUtxosAvailable,
19
+ d as calculateBtcTxHash,
20
+ P as collectReservedUtxoRefs,
21
+ t as createTaprootScriptPathSignOptions,
22
+ f as extractInputsFromTransaction,
23
+ A as fundPeginTransaction,
24
+ g as getDustThreshold,
25
+ b as getNetwork,
26
+ L as getPsbtInputFields,
27
+ O as getScriptType,
28
+ S as parseUnfundedWasmTransaction,
29
+ l as peginOutputCount,
26
30
  F as rateBasedTxBufferFee,
27
- g as selectUtxosForPegin,
28
- L as shouldAddChangeOutput
31
+ B as selectUtxosForDeposit,
32
+ D as selectUtxosForPegin,
33
+ N as shouldAddChangeOutput,
34
+ h as validateUtxosAvailable
29
35
  };
30
36
  //# sourceMappingURL=index.js.map
@@ -7,7 +7,7 @@ import { UTXO } from '../utxo/selectUtxos';
7
7
  * UTXO inputs and change outputs, creating a transaction ready for wallet signing.
8
8
  *
9
9
  * Transaction Flow:
10
- * 1. SDK buildPeginPsbt() → unfunded transaction (0 inputs, vault + depositor claim outputs)
10
+ * 1. SDK buildPrePeginPsbt() → unfunded Pre-PegIn tx (0 inputs, HTLC + CPFP outputs)
11
11
  * 2. selectUtxosForPegin() → select UTXOs and calculate fees
12
12
  * 3. fundPeginTransaction() → add inputs/change, create funded transaction
13
13
  *
@@ -0,0 +1,3 @@
1
+ /** Tests for UTXO availability validation. */
2
+ export {};
3
+ //# sourceMappingURL=availability.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"availability.test.d.ts","sourceRoot":"","sources":["../../../../../../src/tbv/core/utils/utxo/__tests__/availability.test.ts"],"names":[],"mappings":"AAAA,8CAA8C"}
@@ -0,0 +1,3 @@
1
+ /** Tests for UTXO reservation utilities. */
2
+ export {};
3
+ //# sourceMappingURL=reservation.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reservation.test.d.ts","sourceRoot":"","sources":["../../../../../../src/tbv/core/utils/utxo/__tests__/reservation.test.ts"],"names":[],"mappings":"AAAA,4CAA4C"}