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