@laceio/sdk 0.1.1 → 0.1.2-canary.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 (388) hide show
  1. package/dist/{TransactionBuilder-DrB3NVTi.cjs → TransactionBuilder-CCjOn7NA.cjs} +42 -0
  2. package/dist/{TransactionBuilder-V6aLx4SV.js → TransactionBuilder-CIzdw18M.js} +1 -1
  3. package/dist/{_polyfill-buffer-patch-BnPVerlG.cjs → _polyfill-buffer-patch-CM8X7JiY.cjs} +21 -2
  4. package/dist/_polyfill-buffer-patch-yNxN4d5E.js +1467 -0
  5. package/dist/_web-crypto-random-bytes-Bo-GTcRS.js +197 -0
  6. package/dist/acc-module-4iIUv6My.cjs +27654 -0
  7. package/dist/acc-module-Cmj8EsIb.js +27624 -0
  8. package/dist/account-BOQruszJ.js +6 -0
  9. package/dist/account-BUOj4pYJ.cjs +11 -0
  10. package/dist/account-call-7wnopBq0.cjs +5 -0
  11. package/dist/account-call-B9d_2Xwi.js +4 -0
  12. package/dist/account-call-Bd4Rpbvt.cjs +323 -0
  13. package/dist/account-call-C3CkDqEC.js +276 -0
  14. package/dist/account-guards-BtjTGxDZ.cjs +42 -0
  15. package/dist/account-guards-D9Lu5T3W.js +36 -0
  16. package/dist/account-tokens-DvkOFVON.js +16 -0
  17. package/dist/account-tokens-nwcvwLu4.cjs +21 -0
  18. package/dist/{activity-type.stable-BJEfeLxL.cjs → activity-type-Ch6ljxBy.cjs} +2 -1
  19. package/dist/{activity-type.stable-C76_hWd7.js → activity-type-GsJGWs-3.js} +2 -1
  20. package/dist/address-B9ntKL8K.js +13761 -0
  21. package/dist/address-BXp-mY8H.cjs +11270 -0
  22. package/dist/{address-book-address-validator-DIUolI-s.js → address-book-address-validator-0J9XAADH.js} +2 -2
  23. package/dist/address-book-address-validator-DK0dnsRS.cjs +41 -0
  24. package/dist/address-book-address-validator-Di_ywo8M.js +39 -0
  25. package/dist/{address-book-address-validator-DNwQGlOB.cjs → address-book-address-validator-Dte_YQ2L.cjs} +2 -2
  26. package/dist/artefact-loader-BWWYAD7E.cjs +183 -0
  27. package/dist/artefact-loader-Dik4HIfv.js +160 -0
  28. package/dist/auto-dismiss-failure-on-success-C-qoJuid.cjs +37 -0
  29. package/dist/auto-dismiss-failure-on-success-s8MGDEIu.js +31 -0
  30. package/dist/bip32-D6wd_QMn.cjs +3851 -0
  31. package/dist/bitcoin-data-provider-BYPSmuZS.js +21 -0
  32. package/dist/bitcoin-data-provider-w1oEDSU3.cjs +26 -0
  33. package/dist/bitcoin.cjs +45 -0
  34. package/dist/bitcoin.d.ts +29906 -1
  35. package/dist/bitcoin.js +20 -0
  36. package/dist/{blockfrost-tx-submit-provider-DPTrapz-.js → blockfrost-tx-submit-provider-CBWQ0wK9.js} +5 -157
  37. package/dist/{blockfrost-tx-submit-provider-BAIzV5o3.cjs → blockfrost-tx-submit-provider-CLNQ5ycR.cjs} +3 -167
  38. package/dist/bn-d3nSOIf7.cjs +2553 -0
  39. package/dist/browser-B1eMbDwh.js +7468 -0
  40. package/dist/bytes.vo-BB7_4JK6.js +23 -0
  41. package/dist/bytes.vo-BNRquqaO.cjs +34 -0
  42. package/dist/cardano-DfPwhwm-.js +3 -0
  43. package/dist/{cardano-network-id.vo-DSxrFk9S.cjs → cardano-network-id.vo-BEDPn6Li.cjs} +1 -1
  44. package/dist/{cardano-network-id.vo-CK1tNQDg.js → cardano-network-id.vo-Cfpvbod9.js} +1 -1
  45. package/dist/cardano.cjs +22 -18
  46. package/dist/cardano.d.ts +16956 -1716
  47. package/dist/cardano.js +16 -11
  48. package/dist/client-DXBLHk7K.cjs +808 -0
  49. package/dist/codecs-Cswkg7Tm.cjs +4051 -0
  50. package/dist/codecs-Dc1Krpbt.js +3903 -0
  51. package/dist/{const-C84qHkjp.js → const-BJfIK_G-.js} +4 -4
  52. package/dist/const-BhYOdznB.cjs +42 -0
  53. package/dist/const-BsnjG2_Q.cjs +32071 -0
  54. package/dist/const-CUnCl5U0.js +13 -0
  55. package/dist/{const-DXk2tFyv.js → const-CjmfjBP3.js} +1 -1
  56. package/dist/{const-BDEg2Trq.cjs → const-D-eZIS4n.cjs} +4 -4
  57. package/dist/const-D0CbQlo4.js +154 -0
  58. package/dist/{const-BY8B3_0_.cjs → const-iwzZEE_w.cjs} +1 -1
  59. package/dist/contract-1R86jhSw.js +171 -0
  60. package/dist/contract-MKLzYVkW.cjs +189 -0
  61. package/dist/create-add-accounts-Brqk84vF.js +102 -0
  62. package/dist/create-add-accounts-DzXIh7Ot.cjs +114 -0
  63. package/dist/{delegation-tx-builder-CRpLP6jH.cjs → delegation-tx-builder-CCjiakoy.cjs} +6 -6
  64. package/dist/{delegation-tx-builder-CGVqlaFE.js → delegation-tx-builder-DZFjHDS8.js} +5 -5
  65. package/dist/{deregistration-tx-builder-B-CrUyX6.js → deregistration-tx-builder-Bf6xAYp4.js} +5 -5
  66. package/dist/{deregistration-tx-builder-DZGwB4cz.cjs → deregistration-tx-builder-CQP35yex.cjs} +6 -6
  67. package/dist/device-commitment-hex.vo-5wFtQvDS.js +26 -0
  68. package/dist/device-commitment-hex.vo-CT3RmAug.cjs +31 -0
  69. package/dist/device-readers-CUHYoYOH.js +145 -0
  70. package/dist/device-readers-CdxS2btd.cjs +168 -0
  71. package/dist/device-readers-D_JZeNL2.cjs +8 -0
  72. package/dist/device-readers-DwSNCGPP.js +4 -0
  73. package/dist/dist-BMi5ZjEq.cjs +43175 -0
  74. package/dist/dist-BtIq4XFn.cjs +535 -0
  75. package/dist/dist-C3SHC_Ho.cjs +1394 -0
  76. package/dist/dist-CykEjYEX.cjs +3814 -0
  77. package/dist/dist-Dcsxh3be.cjs +3452 -0
  78. package/dist/dist-DqJfSlTd.cjs +4413 -0
  79. package/dist/dist-nTZ70qj7.cjs +1306 -0
  80. package/dist/{earn-rewards-tx-builder-BDbTDZmD.js → earn-rewards-tx-builder-Bsga3yFb.js} +5 -5
  81. package/dist/{earn-rewards-tx-builder-D5sUT5v8.cjs → earn-rewards-tx-builder-GuxofYns.cjs} +6 -6
  82. package/dist/enc-key-circuits-B7BjgUL9.js +13 -0
  83. package/dist/enc-key-circuits-BLrZrBVI.cjs +24 -0
  84. package/dist/english-Byb9M0E_.cjs +2057 -0
  85. package/dist/envelopes-BGoO_v8m.js +1621 -0
  86. package/dist/envelopes-CH25R-DN.cjs +1722 -0
  87. package/dist/errors-BIftM8ZN.cjs +688 -0
  88. package/dist/errors-DSq5wUwt.js +466 -0
  89. package/dist/esm-HBSUQw3w.js +384 -0
  90. package/dist/esm-LZuaZjMf.cjs +389 -0
  91. package/dist/experimental.cjs +7349 -0
  92. package/dist/experimental.d.ts +86273 -0
  93. package/dist/experimental.js +7184 -0
  94. package/dist/gated-call-CDCVZIK-.cjs +5 -0
  95. package/dist/gated-call-D-tT7P_t.js +722 -0
  96. package/dist/gated-call-D_VT2quk.js +4 -0
  97. package/dist/gated-call-DgJm1Mi_.cjs +787 -0
  98. package/dist/grant-circuits-DswmW3nI.cjs +71 -0
  99. package/dist/grant-circuits-Jxb5y1HW.js +42 -0
  100. package/dist/grant-rules-By07_eDi.js +6824 -0
  101. package/dist/grant-rules-BzVTWXS7.cjs +7099 -0
  102. package/dist/grant-spend-B3Md9L0n.js +215 -0
  103. package/dist/grant-spend-oWmzRsjH.cjs +217 -0
  104. package/dist/grant-status-B2y49iIu.js +2688 -0
  105. package/dist/grant-status-DOr3t_u8.cjs +2820 -0
  106. package/dist/grants-2BZ-qEVQ.js +5 -0
  107. package/dist/grants-BPoLSiMt.cjs +18 -0
  108. package/dist/grants-BoI5uwSF.cjs +272 -0
  109. package/dist/grants-CtofFu-e.js +213 -0
  110. package/dist/{group-cardano-addresses-by-account-B533oVXR.cjs → group-cardano-addresses-by-account-Bp0g4wEY.cjs} +3 -39
  111. package/dist/{group-cardano-addresses-by-account-RHKoEskR.js → group-cardano-addresses-by-account-SR8MMrZf.js} +5 -35
  112. package/dist/{guarded-transaction-signer-Bxl6_XNd.cjs → guarded-transaction-signer-MFpPg98D.cjs} +17 -18
  113. package/dist/{guarded-transaction-signer-CpKLj8Kp.js → guarded-transaction-signer-P6Rp1faj.js} +8 -15
  114. package/dist/hex-D9ITYbwt.cjs +263 -0
  115. package/dist/hex-mkXcV3pN.js +191 -0
  116. package/dist/http-client-B3N-TMxu.cjs +167 -0
  117. package/dist/http-client-TRlhDZGh.js +155 -0
  118. package/dist/identity-BMLuufva.cjs +263 -0
  119. package/dist/identity-DII6f-h7.js +233 -0
  120. package/dist/in-memory-wallet-integration-B2xzxORj.cjs +20741 -0
  121. package/dist/in-memory-wallet-integration-CBRiPjLO.js +130 -0
  122. package/dist/in-memory-wallet-integration-CULUB5Tf.cjs +240 -0
  123. package/dist/{in-memory-wallet-integration-D-qn65Kx.js → in-memory-wallet-integration-ChIOirMW.js} +5 -2
  124. package/dist/{in-memory-wallet-integration-Croiuopx.js → in-memory-wallet-integration-CljprQQV.js} +7 -104
  125. package/dist/{in-memory-wallet-integration-DVh9sRXa.cjs → in-memory-wallet-integration-Cm6P8sk6.cjs} +3 -2
  126. package/dist/in-memory-wallet-integration-TM9bBphA.js +20738 -0
  127. package/dist/{in-memory-wallet-integration-CnLYeX4-.cjs → in-memory-wallet-integration-t9I00R_V.cjs} +17 -108
  128. package/dist/index.cjs +84 -47
  129. package/dist/index.d.ts +37496 -10033
  130. package/dist/index.js +52 -24
  131. package/dist/{init-CLHuAMB-.js → init-0zzs9aqU.js} +4 -4
  132. package/dist/{init-U8c9yHYx.cjs → init-5KcGcBb5.cjs} +1 -1
  133. package/dist/init-8v_n8boO.js +1177 -0
  134. package/dist/{init-CigestoM.js → init-B3-1ghyx.js} +2 -2
  135. package/dist/init-B8U3ABhS.cjs +107 -0
  136. package/dist/init-BJn-8_hf.js +141 -0
  137. package/dist/init-BPU3j8sT.cjs +6 -0
  138. package/dist/init-BRzH6xu-2.cjs +2797 -0
  139. package/dist/init-BmzfDaKL.js +1142 -0
  140. package/dist/{init-C-jErzp5.cjs → init-BopV9ed4.cjs} +2 -2
  141. package/dist/init-BpHTq2R5.js +105 -0
  142. package/dist/init-BpSITBfF.js +39 -0
  143. package/dist/{init-DX4WyB0R.cjs → init-BrdVzxei.cjs} +3 -3
  144. package/dist/{init-LfyMo-sS.cjs → init-BwkU0ruo.cjs} +2 -2
  145. package/dist/{init-CB__aLD7.cjs → init-C-G32J12.cjs} +2 -2
  146. package/dist/init-C00gw1zi.js +422 -0
  147. package/dist/{init-TkPq_Ny_.js → init-C2RgrfZe.js} +1 -1
  148. package/dist/{init-DcYY6zMD.js → init-C8URA2OX.js} +1 -1
  149. package/dist/init-CDkRynJa.js +2796 -0
  150. package/dist/{init-Cg9XdAru.js → init-CNM5m7M2.js} +4 -4
  151. package/dist/init-CR7BfztQ.cjs +18 -0
  152. package/dist/{init-CSHwHnfg.cjs → init-CSDpdu0Q.cjs} +2 -2
  153. package/dist/{init-aJHl-7AO.js → init-CX0AMQUn.js} +2 -2
  154. package/dist/{init-FMGDET-9.js → init-CfTbSEKy.js} +259 -60
  155. package/dist/{init-CR6tpw1B.js → init-Cigr_tKx.js} +47 -43
  156. package/dist/init-CuW7rHNA.js +3584 -0
  157. package/dist/{init-CFYsq82V.js → init-CyAY4Lzl.js} +1 -1
  158. package/dist/init-Cz0rz5fU.cjs +3585 -0
  159. package/dist/{init-BKhH6mVR.cjs → init-D6BxBs7e.cjs} +1 -1
  160. package/dist/init-D8OeObDF.cjs +1141 -0
  161. package/dist/init-D9g1HXYf.cjs +40 -0
  162. package/dist/{init-CNLGJJRx.js → init-DA7zmptx.js} +1 -1
  163. package/dist/{init-DkIc5nqF.cjs → init-DFMiP2ZH.cjs} +1 -1
  164. package/dist/{init-zSzCjoor.js → init-DFjT8YvT.js} +4 -4
  165. package/dist/init-DGjXwWs2.cjs +143 -0
  166. package/dist/init-DHrCbpkW.cjs +121 -0
  167. package/dist/{init-B64zCLxG.cjs → init-DUF4ar8P.cjs} +4 -4
  168. package/dist/init-DlqJuHhl.js +119 -0
  169. package/dist/{init-y2Ra0vZP.js → init-Dnsv155v.js} +3 -3
  170. package/dist/init-DrRdf5sZ.cjs +1176 -0
  171. package/dist/init-DuYENxci.js +17 -0
  172. package/dist/{init-D6DBUsD3.cjs → init-Dv3zKj0r.cjs} +4 -4
  173. package/dist/{init-BtzMZ7Pk.cjs → init-Dy-05ktr.cjs} +1 -1
  174. package/dist/{init-BsCBAGWf.cjs → init-EP0CUWNK.cjs} +2 -2
  175. package/dist/{init-BJVU54pI.cjs → init-EhzD7a8i.cjs} +1 -1
  176. package/dist/{init-w9GEs73W.js → init-Fw89ZmrR.js} +2 -2
  177. package/dist/init-GsT2AEa4.cjs +424 -0
  178. package/dist/{init-Rxohwpmu.js → init-NCjgwCZy.js} +2 -2
  179. package/dist/{init-DxUHsN53.cjs → init-NdhG_VrF.cjs} +6 -6
  180. package/dist/{init-DDdhguVC.js → init-SZ01tARX2.js} +2 -2
  181. package/dist/{init-BAJJzBza.js → init-Y3mkB4XS.js} +2 -2
  182. package/dist/init-c4l6r-o-.js +5 -0
  183. package/dist/{init-Dku4b2lG.js → init-kEfUTuG2.js} +1 -1
  184. package/dist/{init-C7IeJwQR.cjs → init-lzHt4Cli.cjs} +256 -59
  185. package/dist/{init-anYu6XB7.cjs → init-rmt7-fQE.cjs} +2 -2
  186. package/dist/{init-C4Bkib9u.cjs → init-zU-_9Gsp.cjs} +67 -65
  187. package/dist/{is-retriable-error-BU0e3hVI.js → is-retriable-error-BUiVJDwH.js} +1 -1
  188. package/dist/{is-retriable-error-CeeuHqDa.cjs → is-retriable-error-Dpt860if.cjs} +1 -1
  189. package/dist/jubjub-authoriser-D7zDXu3V.js +86 -0
  190. package/dist/jubjub-authoriser-Dgu6o3Sv.cjs +87 -0
  191. package/dist/key-source-5oUBFiC7.cjs +583 -0
  192. package/dist/key-source-B08HukZg.js +2550 -0
  193. package/dist/keyDerivation-D3k9XyHg.js +4077 -0
  194. package/dist/keyDerivation-u0nBA93T.cjs +274 -0
  195. package/dist/{lace-context-CZcNHr4M.js → lace-context-BZciB9c7.js} +4 -4
  196. package/dist/{lace-context-fJTDghdp.cjs → lace-context-DgR6vLli.cjs} +4 -4
  197. package/dist/lib--iqvW4O_.js +2354 -0
  198. package/dist/lib-Yk6Upl5D.cjs +2359 -0
  199. package/dist/{libsodium-wrappers-UH0LaOUE.js → libsodium-wrappers-BhbOA8dQ.js} +3 -1647
  200. package/dist/midnight-account-id.vo-0x9X-r3l.cjs +10 -0
  201. package/dist/midnight-account-id.vo-DjCAGcqc.js +5 -0
  202. package/dist/midnight-engine-DpemplKO.js +5 -0
  203. package/dist/midnight-engine-xU1wotne.cjs +6 -0
  204. package/dist/midnight-wallet-DIsAlSn6.js +18 -0
  205. package/dist/midnight-wallet-XTZc2li7.cjs +24 -0
  206. package/dist/midnight.cjs +1408 -0
  207. package/dist/midnight.d.ts +28934 -0
  208. package/dist/midnight.js +1352 -0
  209. package/dist/modules-cardano-B1nDUWqy.js +995 -0
  210. package/dist/modules-cardano-BYeYHrRm.cjs +1108 -0
  211. package/dist/node-relay-DWe1U0w2.cjs +49 -0
  212. package/dist/node-relay-h4i5IlAQ.js +48 -0
  213. package/dist/outputs-Bd2yZVjx.js +720 -0
  214. package/dist/outputs-CJoQBIA2.cjs +990 -0
  215. package/dist/pbkdf2-CIW-oWrm.cjs +1337 -0
  216. package/dist/pending-operation-B0_P78Jo.cjs +26 -0
  217. package/dist/pending-operation-BIS6mpjB.js +21 -0
  218. package/dist/providers-FjhM47BH.cjs +388 -0
  219. package/dist/providers-WtiSuxFu.js +365 -0
  220. package/dist/redacted-BmE2aXqr.js +81 -0
  221. package/dist/redacted-CRZJLS3w.cjs +86 -0
  222. package/dist/{retry-config-DC5IMaH7.cjs → retry-config-BaCfVC1H.cjs} +1 -1
  223. package/dist/{retry-config-BcUmMS--.js → retry-config-Dmgt28wM.js} +1 -1
  224. package/dist/safe-buffer-B_vMqJWU.js +43 -0
  225. package/dist/safe-buffer-DYOwEfHB.cjs +48 -0
  226. package/dist/sdk-Cb-gZnS9.js +1241 -0
  227. package/dist/sdk-DffwmX8b.cjs +1439 -0
  228. package/dist/sdk-init-Bln9rFtn.js +4138 -0
  229. package/dist/sdk-init-CYViTJY_.cjs +3841 -0
  230. package/dist/{seam-cardano-CATqBEyK.js → seam-cardano-B_etH4F4.js} +1 -1
  231. package/dist/{bytes.vo-TgiwogWF.js → secret-box-DUR0ACYz.js} +3 -25
  232. package/dist/{bytes.vo-Ck5u40RA.cjs → secret-box-DrjLZuS1.cjs} +1 -35
  233. package/dist/send-proof-progress-C-ljq1x5.js +30 -0
  234. package/dist/send-proof-progress-vmsaSfbz.cjs +47 -0
  235. package/dist/side-effects-BnqYz7Nl.js +768 -0
  236. package/dist/side-effects-CngaeXi0.cjs +804 -0
  237. package/dist/sign-bitcoin-transaction-with-seed-D4z62-jV.js +147 -0
  238. package/dist/sign-bitcoin-transaction-with-seed-DsLYXnCY.cjs +158 -0
  239. package/dist/signer-3fk8lZtE.cjs +7 -0
  240. package/dist/signer-CsL28DrK.cjs +121 -0
  241. package/dist/signer-DGluibtn.js +92 -0
  242. package/dist/signer-RqB5pu3K.js +2 -0
  243. package/dist/signer-factory-BA7WFJVZ.js +282 -0
  244. package/dist/signer-factory-Cwd6o-lG.cjs +281 -0
  245. package/dist/{signer-factory-9URFliA5.js → signer-factory-DObB55D4.js} +6 -3
  246. package/dist/signer-factory-DhZiE03y.cjs +149 -0
  247. package/dist/{signer-factory-BWGUmnvm.cjs → signer-factory-Ds6G2AZk.cjs} +4 -3
  248. package/dist/signer-factory-hzSRaIw2.js +148 -0
  249. package/dist/{slice-CuHUaPZx.cjs → slice-7G2xxYKJ.cjs} +3 -3
  250. package/dist/{slice-DZmQJNV8.cjs → slice-B4CdYoPu.cjs} +2 -2
  251. package/dist/slice-BPNuHKfw.js +9091 -0
  252. package/dist/{slice-DGcNrbPR.cjs → slice-Bg6HEr3K.cjs} +4 -4
  253. package/dist/{slice-DtaO72qY.cjs → slice-Bs2aMERu.cjs} +3 -3
  254. package/dist/{slice-HeHCv3bl.cjs → slice-C34iOOUH.cjs} +7 -7
  255. package/dist/{slice-Do2R2CYW.cjs → slice-C9TT5KhY.cjs} +6 -6
  256. package/dist/{slice-eIwcwKHI.js → slice-CK07EBCo.js} +4 -4
  257. package/dist/{slice-CnyWevM9.js → slice-CU80pbiu.js} +3 -3
  258. package/dist/{slice-CobanYgn.js → slice-CwyYrh1H.js} +2 -2
  259. package/dist/slice-Czfp6t84.cjs +436 -0
  260. package/dist/{slice-d0p6-xj5.js → slice-D-9aPKG-.js} +6 -6
  261. package/dist/{slice-maaskdUn.js → slice-DBpJ2QGf.js} +6 -6
  262. package/dist/{slice-mxLQ_FeY.cjs → slice-DTZTiJle.cjs} +352 -39
  263. package/dist/{slice-zJ9XVYjZ.js → slice-Da426sf9.js} +1 -1
  264. package/dist/{slice-D11m2EKl.cjs → slice-DayJvMRD.cjs} +1 -1
  265. package/dist/slice-DnBWfA-k.cjs +9109 -0
  266. package/dist/{slice-oqm_r1cS.cjs → slice-DnG-yvpI.cjs} +2 -2
  267. package/dist/{slice-BNu73oBa.js → slice-DyNs7oWp.js} +2 -2
  268. package/dist/{slice-CB4SnzMm.js → slice-GwiiJRoq.js} +3 -3
  269. package/dist/slice-oWnc7YVD.js +412 -0
  270. package/dist/{slice-B2PhoWAg.js → slice-qt0uBExh.js} +325 -37
  271. package/dist/slice-t8Gzj55G2.cjs +106 -0
  272. package/dist/slice-t8Q1cHm-.js +88 -0
  273. package/dist/src-BDzYIksE.cjs +20637 -0
  274. package/dist/src-BFoefPv_.js +20755 -0
  275. package/dist/store-B1Lq3cEf.cjs +66 -0
  276. package/dist/store-DuBG8qh5.js +37 -0
  277. package/dist/submit-Bs77dPn_.cjs +413 -0
  278. package/dist/submit-DOv8Z0Vf.js +336 -0
  279. package/dist/submit-bitcoin-tx-D6oYgH5S.js +983 -0
  280. package/dist/submit-bitcoin-tx-goFuRL7K.cjs +1049 -0
  281. package/dist/{sync-operation-utils-BYXLO80m.js → sync-operation-utils-31iFLExW.js} +2 -38
  282. package/dist/{sync-operation-utils-SdPbwFoD.cjs → sync-operation-utils-COIZ66-I.cjs} +1 -67
  283. package/dist/token-id-mapper-Bnds3xKH.cjs +18 -0
  284. package/dist/{token-id-mapper-DsPAL6Nh.cjs → token-id-mapper-CVyQJUKY.cjs} +2 -2
  285. package/dist/token-id-mapper-CnKHQ8DV.js +16 -0
  286. package/dist/{token-id-mapper-B2ivlLv3.js → token-id-mapper-D29Ggv8h.js} +2 -2
  287. package/dist/tokens-Cevp7rdU.cjs +62 -0
  288. package/dist/tokens-Diw4MLRM.js +44 -0
  289. package/dist/types-B8uiJn-X.js +12 -0
  290. package/dist/types-BHC12eSa.js +33 -0
  291. package/dist/types-CJT6XF2c.js +10 -0
  292. package/dist/types-CLRUYpfe.cjs +23 -0
  293. package/dist/types-Cc3mC8u0.cjs +50 -0
  294. package/dist/types-DWbVZpnF.cjs +15 -0
  295. package/dist/unwrap-provider-result-BZSiwabU.js +32 -0
  296. package/dist/unwrap-provider-result-ZqfBsTkk.cjs +39 -0
  297. package/dist/{util-CGzqQ8IV.cjs → util-Bu4W5lF4.cjs} +1 -1
  298. package/dist/{util-BaLzwa32.js → util-Cp5cZkfK.js} +1 -1
  299. package/dist/{utils-o8aMjfln.js → utils-BfBEUvWA.js} +2 -2
  300. package/dist/utils-DFwzEvbv.js +65 -0
  301. package/dist/{utils-5JvjbqH3.cjs → utils-DsElZgCI.cjs} +7 -1
  302. package/dist/utils-IXxR-Djh.cjs +112 -0
  303. package/dist/v8Signatures-CO_Uloy7.cjs +71 -0
  304. package/dist/{vote-delegation-tx-builder-BpEMSti4.cjs → vote-delegation-tx-builder-BUg1S2Ep.cjs} +6 -6
  305. package/dist/{vote-delegation-tx-builder-CmKv6GoG.js → vote-delegation-tx-builder-C6FiS7zI.js} +5 -5
  306. package/dist/watch-CUEvcP-V.js +21997 -0
  307. package/dist/watch-DMF2s-II.cjs +52281 -0
  308. package/package.json +96 -4
  309. package/dist/account-guards.stable-B1DSSh9D.cjs +0 -10
  310. package/dist/account-guards.stable-JRQ5qx2V.js +0 -5
  311. package/dist/codecs-B7X9pAsK.cjs +0 -1945
  312. package/dist/codecs-CC1Xjntz.js +0 -1882
  313. package/dist/init-Bv53hpLM.js +0 -19
  314. package/dist/init-CRbjI7p1.js +0 -3494
  315. package/dist/init-DAna1KCg.cjs +0 -3495
  316. package/dist/init-DGe47B22.cjs +0 -364
  317. package/dist/init-DMtyvYfC.cjs +0 -21
  318. package/dist/init-TkPDD750.js +0 -363
  319. package/dist/modules-cardano-BDvuL4Xx.js +0 -5248
  320. package/dist/modules-cardano-D2G3De2P.cjs +0 -5432
  321. package/dist/slice-CGVHXHDt.cjs +0 -125
  322. package/dist/slice-DhvF7L6X.js +0 -107
  323. /package/dist/{account-id.vo-LvCBVn5r.cjs → account-id.vo-DwqFjK5u.cjs} +0 -0
  324. /package/dist/{account-id.vo-MYSI7YFm.js → account-id.vo-OPz2v-JZ.js} +0 -0
  325. /package/dist/{actions-DdGbj7c7.cjs → actions-B2BJ4RTy.cjs} +0 -0
  326. /package/dist/{actions-9QSQR-GB.js → actions-iLXdgL5Y.js} +0 -0
  327. /package/dist/{apply-vkey-witnesses-ClZbpk5w.js → apply-vkey-witnesses-BKx3lcs0.js} +0 -0
  328. /package/dist/{apply-vkey-witnesses-CLzVSWxl.cjs → apply-vkey-witnesses-ZnFS0jnJ.cjs} +0 -0
  329. /package/dist/{asyncoption-Cw07zPH7.js → asyncoption-CruEYOBI.js} +0 -0
  330. /package/dist/{asyncoption-DYoGuQfP.cjs → asyncoption-i0VbqVTq.cjs} +0 -0
  331. /package/dist/{bignum.vo-B0rK_PQ1.js → bignum.vo-CEXOIew0.js} +0 -0
  332. /package/dist/{bignum.vo-DsG3kNiZ.cjs → bignum.vo-hx2kuqlA.cjs} +0 -0
  333. /package/dist/{bip32ed25519-1ApqeAZk.cjs → bip32ed25519-B7Yat217.cjs} +0 -0
  334. /package/dist/{bip32ed25519-DetAdGwD.js → bip32ed25519-FQ8qvdcq.js} +0 -0
  335. /package/dist/{blake2b-DOEVc57D.js → blake2b-BiQTw3GC.js} +0 -0
  336. /package/dist/{blake2b-B9tftbvG.cjs → blake2b-DEeVUdKR.cjs} +0 -0
  337. /package/dist/{blockchain-network-id.vo-BXpZhvvQ.cjs → blockchain-network-id.vo-BAKEwGjG.cjs} +0 -0
  338. /package/dist/{blockchain-network-id.vo-DNRkuT5B.js → blockchain-network-id.vo-CiVykuqG.js} +0 -0
  339. /package/dist/{blockingWithLatestFrom-C5wp_uA-.js → blockingWithLatestFrom-Cd8c8EPG.js} +0 -0
  340. /package/dist/{blockingWithLatestFrom-DY8OPg0w.cjs → blockingWithLatestFrom-D8kBPBMX.cjs} +0 -0
  341. /package/dist/{cardano-network-id-to-network-type-CrZfUcyP.js → cardano-network-id-to-network-type-BWwzeEtM.js} +0 -0
  342. /package/dist/{cardano-network-id-to-network-type-BDTF-HmK.cjs → cardano-network-id-to-network-type-C0ufJOyE.cjs} +0 -0
  343. /package/dist/{cardano-tx-id.vo-BPhV-AmZ.cjs → cardano-tx-id.vo-TLjJZHCI.cjs} +0 -0
  344. /package/dist/{cardano-tx-id.vo-DF9NzZXk.js → cardano-tx-id.vo-eVnKuzlm.js} +0 -0
  345. /package/dist/{composite-signer-factory-_46QsNBz.js → composite-signer-factory-CR8YHA1y.js} +0 -0
  346. /package/dist/{composite-signer-factory-BpF1mIYA.cjs → composite-signer-factory-m5cVs9h_.cjs} +0 -0
  347. /package/dist/{error-CNIquqT5.cjs → error-Cb3EnD0u.cjs} +0 -0
  348. /package/dist/{error-BCp9NkPi.js → error-DIZOY2Lw.js} +0 -0
  349. /package/dist/{esm-browser-C93Q-EOI.js → esm-browser-MG97cre9.js} +0 -0
  350. /package/dist/{esm-browser-DTc9IK3D.cjs → esm-browser-bweqfBlL.cjs} +0 -0
  351. /package/dist/{feature-flag-key.vo-ofrB6ZVQ.js → feature-flag-key.vo-DN_-4-sG.js} +0 -0
  352. /package/dist/{feature-flag-key.vo-BPz-ZAp6.cjs → feature-flag-key.vo-RlfHL3hq.cjs} +0 -0
  353. /package/dist/{first-state-of-status-OROkXcRv.cjs → first-state-of-status-CbT7hPa4.cjs} +0 -0
  354. /package/dist/{first-state-of-status-DQnMT3ya.js → first-state-of-status-unPynOuM.js} +0 -0
  355. /package/dist/{init-Es3wHW7D.js → init-829HRYcz.js} +0 -0
  356. /package/dist/{init-CKipPE_c.js → init-A-VyGSNW2.js} +0 -0
  357. /package/dist/{init-DFQQ9dTW.cjs → init-Atisw4x2.cjs} +0 -0
  358. /package/dist/{init-C5CEZ1m0.cjs → init-BFcvPHL-.cjs} +0 -0
  359. /package/dist/{init-IAk_CkGa.cjs → init-BgNobbNq.cjs} +0 -0
  360. /package/dist/{init-cqN3uX2j.js → init-atCFur0v.js} +0 -0
  361. /package/dist/{is-redux-persist-state-CTn3WZVh.cjs → is-redux-persist-state-BCFnSm36.cjs} +0 -0
  362. /package/dist/{is-redux-persist-state-Cxcd0_bM.js → is-redux-persist-state-yBfq0h_E.js} +0 -0
  363. /package/dist/{key-value-store-8cMzeNyG.js → key-value-store--W3SrMaw.js} +0 -0
  364. /package/dist/{key-value-store-DUAepXQf.cjs → key-value-store-C2Xt5Emp.cjs} +0 -0
  365. /package/dist/{repo-slice-WxetRhMY.cjs → repo-slice-7X4AYYVm.cjs} +0 -0
  366. /package/dist/{repo-slice-DwyMhCR1.js → repo-slice-RxFm0zDZ.js} +0 -0
  367. /package/dist/{reselect-CRDqmQY9.cjs → reselect-Bd94u0K-.cjs} +0 -0
  368. /package/dist/{reselect-C06X06oX.js → reselect-CGoLzEPv.js} +0 -0
  369. /package/dist/{serializable-B8GahgE1.js → serializable-BHdKIgk3.js} +0 -0
  370. /package/dist/{serializable-CRdnFaLZ.cjs → serializable-BxHkoPdk.cjs} +0 -0
  371. /package/dist/{slice-D11FHQuQ.cjs → slice-BiRsDKOK.cjs} +0 -0
  372. /package/dist/{slice-Be7hj4Iy.js → slice-Bk0Sv05J.js} +0 -0
  373. /package/dist/{slice-FioKeHtA.cjs → slice-Dqw1ecum.cjs} +0 -0
  374. /package/dist/{slice-B87b52iM.js → slice-obCSLm1x.js} +0 -0
  375. /package/dist/{src-vq1wS9sZ.js → src-BlxEp6Mm.js} +0 -0
  376. /package/dist/{src-BTPIvlDI.cjs → src-Cqp0B2M_.cjs} +0 -0
  377. /package/dist/{time.vo-CQ8pSXz2.cjs → time.vo-D3wWRw9L.cjs} +0 -0
  378. /package/dist/{time.vo-DkYYGYp6.js → time.vo-tNheinXm.js} +0 -0
  379. /package/dist/{toEmpty-CgAl3097.js → toEmpty-8Zax1MPd.js} +0 -0
  380. /package/dist/{toEmpty-DAMmNB5r.cjs → toEmpty-CYAbupM4.cjs} +0 -0
  381. /package/dist/{token-id.vo-ClsroxHO.js → token-id.vo-Bvwhr3ZE.js} +0 -0
  382. /package/dist/{token-id.vo-BxG9TG0O.cjs → token-id.vo-DXv5uS9n.cjs} +0 -0
  383. /package/dist/{util-DxzlYNS5.js → util-C8a4fA9p.js} +0 -0
  384. /package/dist/{util-CmdAhheh.cjs → util-CzeB3hfa.cjs} +0 -0
  385. /package/dist/{util-selector-CcK-GAdE.js → util-selector-BSTsxgne.js} +0 -0
  386. /package/dist/{util-selector-BcAncU4L.cjs → util-selector-BWPH68_l.cjs} +0 -0
  387. /package/dist/{while-active-BpppWuCs.js → while-active-B0lWy_6l.js} +0 -0
  388. /package/dist/{while-active-Dhc2LwOm.cjs → while-active-Dsowp0Fi.cjs} +0 -0
@@ -0,0 +1,1306 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-Br2OG8yv.cjs");
2
+ const require__polyfill_buffer_patch = require("./_polyfill-buffer-patch-CM8X7JiY.cjs");
3
+ require("./bn-d3nSOIf7.cjs");
4
+ require("./client-DXBLHk7K.cjs");
5
+ const require_dist = require("./dist-BMi5ZjEq.cjs");
6
+ const require_v8Signatures = require("./v8Signatures-CO_Uloy7.cjs");
7
+ const require_dist$1 = require("./dist-DqJfSlTd.cjs");
8
+ const require_dist$2 = require("./dist-Dcsxh3be.cjs");
9
+ const require_dist$3 = require("./dist-CykEjYEX.cjs");
10
+ let rxjs = require("rxjs");
11
+ let _midnight_ntwrk_ledger_v8 = require("@midnight-ntwrk/ledger-v8");
12
+ _midnight_ntwrk_ledger_v8 = require_rolldown_runtime.__toESM(_midnight_ntwrk_ledger_v8);
13
+ let _midnightntwrk_ledger_v9 = require("@midnightntwrk/ledger-v9");
14
+ _midnightntwrk_ledger_v9 = require_rolldown_runtime.__toESM(_midnightntwrk_ledger_v9);
15
+ //#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-facade/dist/transaction.js
16
+ require__polyfill_buffer_patch.init__polyfill_buffer_patch();
17
+ /**
18
+ * The key under which a transaction's history entry is stored.
19
+ *
20
+ * Prefer the ledger transaction hash — it's the canonical chain identifier and the value the indexer reports a
21
+ * confirmed tx under. `transactionHash()` is only defined for proven + signed + bound transactions, though; it throws
22
+ * for the other variants, notably the proof-erased transactions the simulator produces. In that case fall back to the
23
+ * hex of the tx's serialized bytes: `serialize()` is total over every variant (it's the same encoding used to submit
24
+ * the tx), so a key is always available — unlike `identifiers[0]`, which is an identifier, not a hash of the
25
+ * transaction.
26
+ *
27
+ * Both the submit (pending) and revert (rejected) sides route through this one function so they can never disagree on
28
+ * the key. The fallback is deterministic: the same transaction object yields the same bytes every time, and the
29
+ * auto-revert path reverts the very object it submitted, so the rejected entry lands on the pending entry in place.
30
+ * (Serialization differs across lifecycle states, so this is only stable for a fixed tx — which is exactly the
31
+ * submit→revert flow.)
32
+ */
33
+ const txHistoryHash = (tx) => {
34
+ try {
35
+ return String(tx.transactionHash());
36
+ } catch {
37
+ return require__polyfill_buffer_patch.import_buffer.Buffer.from(tx.serialize()).toString("hex");
38
+ }
39
+ };
40
+ const v9FinalizedTransactionTrait = {
41
+ areAllTxIdsIncluded(tx, txIds) {
42
+ const txIdsSet = require_dist.fromIterable$1(tx.identifiers());
43
+ const expectedIdSet = require_dist.fromIterable$1(txIds);
44
+ return require_dist.isSubset(txIdsSet, expectedIdSet);
45
+ },
46
+ deserialize(serialized) {
47
+ return _midnightntwrk_ledger_v9.Transaction.deserialize("signature", "proof", "binding", serialized);
48
+ },
49
+ firstId(tx) {
50
+ return tx.identifiers()[0];
51
+ },
52
+ hasTTLExpired(tx, creationTime, now) {
53
+ const defaultShieldedGracePeriod = _midnightntwrk_ledger_v9.LedgerParameters.initialParameters().dust.dustGracePeriodSeconds;
54
+ const intentTTLs = require_dist.pipe(tx.intents?.values().toArray() ?? [], require_dist.map$3((i) => i.ttl), require_dist.filterMap$1(require_dist.make$1));
55
+ const hasDustPayments = require_dist.pipe(tx.intents?.values().toArray() ?? [], require_dist.flatMap$2((i) => i.dustActions?.spends ?? []), require_dist.isNonEmptyArray);
56
+ const hasShieldedOffers = tx.guaranteedOffer != null || (tx.fallibleOffer?.size ?? 0) == 0;
57
+ const maybeShieldedTTL = hasDustPayments || hasShieldedOffers ? require_dist.pipe(creationTime, require_dist.addDuration(require_dist.seconds(Number(defaultShieldedGracePeriod))), require_dist.of) : require_dist.empty$2();
58
+ return require_dist.pipe(intentTTLs, require_dist.appendAll(maybeShieldedTTL), (arr) => require_dist.isNonEmptyReadonlyArray(arr) ? require_dist.some(require_dist.min(arr, require_dist.mapInput(require_dist.Date, require_dist.toDate))) : require_dist.none(), require_dist.match$1({
59
+ onNone: () => false,
60
+ onSome: (finalTTL) => require_dist.distance(finalTTL, now) > 0
61
+ }));
62
+ },
63
+ ids(tx) {
64
+ return tx.identifiers();
65
+ },
66
+ isOneIncludedInOther(tx, otherTx) {
67
+ const txIds = require_dist.fromIterable$1(tx.identifiers());
68
+ const otherTxIds = require_dist.fromIterable$1(otherTx.identifiers());
69
+ const smallerSize = require_dist.min$1(require_dist.number)(require_dist.size(txIds), require_dist.size(otherTxIds));
70
+ const intersection$1 = require_dist.intersection(txIds, otherTxIds);
71
+ return require_dist.size(intersection$1) == smallerSize;
72
+ },
73
+ isTx(tx) {
74
+ return tx instanceof _midnightntwrk_ledger_v9.Transaction;
75
+ },
76
+ serialize(tx) {
77
+ return tx.serialize();
78
+ }
79
+ };
80
+ /**
81
+ * The ledger-v8's reading of a pending transaction.
82
+ *
83
+ * @remarks
84
+ * Structurally the same as ledger-v9's — identifiers, a TTL, bytes — against a different ledger version's classes. It
85
+ * is the classes that make this a separate trait: `instanceof` distinguishes them, each deserializer refuses the
86
+ * other's bytes, and a grace period is read off that version's own initial parameters.
87
+ */
88
+ const v8FinalizedTransactionTrait = {
89
+ areAllTxIdsIncluded(tx, txIds) {
90
+ return require_dist.isSubset(require_dist.fromIterable$1(tx.identifiers()), require_dist.fromIterable$1(txIds));
91
+ },
92
+ deserialize(serialized) {
93
+ return _midnight_ntwrk_ledger_v8.Transaction.deserialize("signature", "proof", "binding", serialized);
94
+ },
95
+ firstId(tx) {
96
+ return tx.identifiers()[0];
97
+ },
98
+ hasTTLExpired(tx, creationTime, now) {
99
+ const defaultShieldedGracePeriod = _midnight_ntwrk_ledger_v8.LedgerParameters.initialParameters().dust.dustGracePeriodSeconds;
100
+ const intentTTLs = require_dist.pipe(tx.intents?.values().toArray() ?? [], require_dist.map$3((i) => i.ttl), require_dist.filterMap$1(require_dist.make$1));
101
+ const hasDustPayments = require_dist.pipe(tx.intents?.values().toArray() ?? [], require_dist.flatMap$2((i) => i.dustActions?.spends ?? []), require_dist.isNonEmptyArray);
102
+ const hasShieldedOffers = tx.guaranteedOffer != null || (tx.fallibleOffer?.size ?? 0) == 0;
103
+ const maybeShieldedTTL = hasDustPayments || hasShieldedOffers ? require_dist.pipe(creationTime, require_dist.addDuration(require_dist.seconds(Number(defaultShieldedGracePeriod))), require_dist.of) : require_dist.empty$2();
104
+ return require_dist.pipe(intentTTLs, require_dist.appendAll(maybeShieldedTTL), (arr) => require_dist.isNonEmptyReadonlyArray(arr) ? require_dist.some(require_dist.min(arr, require_dist.mapInput(require_dist.Date, require_dist.toDate))) : require_dist.none(), require_dist.match$1({
105
+ onNone: () => false,
106
+ onSome: (finalTTL) => require_dist.distance(finalTTL, now) > 0
107
+ }));
108
+ },
109
+ ids(tx) {
110
+ return tx.identifiers();
111
+ },
112
+ isOneIncludedInOther(tx, otherTx) {
113
+ const txIds = require_dist.fromIterable$1(tx.identifiers());
114
+ const otherTxIds = require_dist.fromIterable$1(otherTx.identifiers());
115
+ const smallerSize = require_dist.min$1(require_dist.number)(require_dist.size(txIds), require_dist.size(otherTxIds));
116
+ return require_dist.size(require_dist.intersection(txIds, otherTxIds)) == smallerSize;
117
+ },
118
+ isTx(tx) {
119
+ return tx instanceof _midnight_ntwrk_ledger_v8.Transaction;
120
+ },
121
+ serialize(tx) {
122
+ return tx.serialize();
123
+ }
124
+ };
125
+ /**
126
+ * Lifts one ledger version's trait onto the handle the facade actually carries.
127
+ *
128
+ * @remarks
129
+ * The router has already chosen this trait by the version stamped on the handle, so unwrapping at the same epoch is a
130
+ * restatement of the choice rather than a second one — but it is where a handle that does not belong is refused
131
+ * rather than handed to a reader that would misread it. A handle it cannot read is reported as not being its
132
+ * transaction at all, which is precisely what `isTx` is for.
133
+ * @param trait The ledger version's own reading of a transaction.
134
+ * @param epoch The range of protocol versions that ledger version answers for.
135
+ * @returns The same reading, in terms of handles.
136
+ */
137
+ const overHandles = (trait, epoch) => {
138
+ const [stamp] = epoch;
139
+ const carried = (handle) => require_dist.getOrThrow$1(require_dist.WalletTransaction.unwrapWithin(handle, epoch));
140
+ return {
141
+ ids: (tx) => trait.ids(carried(tx)),
142
+ firstId: (tx) => trait.firstId(carried(tx)),
143
+ areAllTxIdsIncluded: (tx, txIds) => trait.areAllTxIdsIncluded(carried(tx), txIds),
144
+ isOneIncludedInOther: (tx, otherTx) => trait.isOneIncludedInOther(carried(tx), carried(otherTx)),
145
+ hasTTLExpired: (tx, creationTime, now) => trait.hasTTLExpired(carried(tx), creationTime, now),
146
+ serialize: (tx) => trait.serialize(carried(tx)),
147
+ deserialize: (serialized) => require_dist.WalletTransaction.adopt("Finalized", trait.deserialize(serialized), stamp),
148
+ isTx: (tx) => require_dist.WalletTransaction.is(tx) && require_dist.match$2(require_dist.WalletTransaction.unwrapWithin(tx, epoch), {
149
+ onLeft: () => false,
150
+ onRight: (carried) => trait.isTx(carried)
151
+ })
152
+ };
153
+ };
154
+ /**
155
+ * The traits pending transactions are read with, split at the protocol version this chain forks at.
156
+ *
157
+ * @remarks
158
+ * One trait per ledger version, each reading the handle it is registered for and refusing the other's. That is what
159
+ * lets a transaction authored before the v9 fork be recognised as stranded once the wallets cross — its bytes can
160
+ * never be included afterwards — instead of waiting out a TTL for an inclusion that can never happen.
161
+ * @param forkVersion The protocol version this chain forks at.
162
+ * @returns The registry the pending transaction service reads with.
163
+ */
164
+ const finalizedTransactionTraits = (forkVersion) => require_dist.getOrThrow$1(require_dist.makeRegistryFromActivations(forkVersion > require_dist.MinSupportedVersion ? [{
165
+ sinceVersion: require_dist.MinSupportedVersion,
166
+ value: overHandles(v8FinalizedTransactionTrait, require_dist.epochOf(require_dist.MinSupportedVersion, forkVersion))
167
+ }, {
168
+ sinceVersion: forkVersion,
169
+ value: overHandles(v9FinalizedTransactionTrait, require_dist.epochOf(forkVersion, forkVersion))
170
+ }] : [{
171
+ sinceVersion: require_dist.MinSupportedVersion,
172
+ value: overHandles(v9FinalizedTransactionTrait, require_dist.epochOf(require_dist.MinSupportedVersion, require_dist.MinSupportedVersion))
173
+ }]));
174
+ //#endregion
175
+ //#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-facade/dist/index.js
176
+ /**
177
+ * Why the wallet gave up on a transaction, for the history entry.
178
+ *
179
+ * @remarks
180
+ * A chain rejection speaks for itself through the entry's status; an orphaned transaction has no chain verdict at all,
181
+ * so the entry is the only place the reason can be recorded.
182
+ */
183
+ const rejectionReason = (result) => result.status === "ORPHANED_BY_FORK" ? "orphaned-by-protocol-upgrade" : void 0;
184
+ /**
185
+ * Full entry schema for transaction history. The common entry data and wallet-specific sections (`shielded`,
186
+ * `unshielded`, `dust`) live on every entry regardless of lifecycle; the `lifecycle` field is the only discriminator.
187
+ * Pass this to `InMemoryTransactionHistoryStorage` to enable serialize/restore.
188
+ */
189
+ const WalletEntrySchema = require_dist.extendEntrySchema({
190
+ shielded: require_dist.optional(require_dist$2.ShieldedSectionSchema$1),
191
+ unshielded: require_dist.optional(require_dist$3.UnshieldedSectionSchema$1),
192
+ dust: require_dist.optional(require_dist$1.DustSectionSchema$1)
193
+ });
194
+ const isPendingWalletEntry = (entry) => entry.lifecycle.status === "pending";
195
+ const isFinalizedWalletEntry = (entry) => entry.lifecycle.status === "finalized";
196
+ /**
197
+ * Merge two wallet entries arriving under the same hash. Treats the entry as `T × lifecycle` per the storage model:
198
+ *
199
+ * - **Shared scalar facts about the tx** (`protocolVersion`, `status`, `timestamp`, `fees`) — first writer wins. Once any
200
+ * wallet has set the value, later writes are no-ops for these fields. This is correct because the value is the same
201
+ * across all wallets (it's a property of the on-chain tx, not the wallet's view of it).
202
+ * - **`identifiers`** — unioned (each wallet may surface a different identifier subset).
203
+ * - **`lifecycle`** — incoming wins, except that a late rejection cannot overwrite recorded on-chain inclusion.
204
+ * - **Wallet sections** (`shielded`, `unshielded`, `dust`) — combined via per-section merge when both sides have them;
205
+ * otherwise whichever side is present is used.
206
+ */
207
+ /**
208
+ * Combine two optional values under a merge function: if both sides have it, delegate to `merge`; otherwise return
209
+ * whichever side is present (or `undefined` if neither). Encapsulates the four-way pattern used for every wallet
210
+ * section in {@link mergeWalletEntries}.
211
+ */
212
+ const mergeOptionalSection = (existing, incoming, merge) => {
213
+ if (existing !== void 0 && incoming !== void 0) return merge(existing, incoming);
214
+ return existing ?? incoming;
215
+ };
216
+ function mergeWalletEntries(existing, incoming) {
217
+ const identifiers = Array.from(new Set([...existing.identifiers, ...incoming.identifiers]));
218
+ const shielded = mergeOptionalSection(existing.shielded, incoming.shielded, require_dist$2.mergeShieldedSections$1);
219
+ const unshielded = mergeOptionalSection(existing.unshielded, incoming.unshielded, require_dist$3.mergeUnshieldedSections$1);
220
+ const dust = mergeOptionalSection(existing.dust, incoming.dust, require_dist$1.mergeDustSections$1);
221
+ return {
222
+ hash: existing.hash,
223
+ identifiers,
224
+ protocolVersion: existing.protocolVersion ?? incoming.protocolVersion,
225
+ status: existing.status ?? incoming.status,
226
+ timestamp: existing.timestamp ?? incoming.timestamp,
227
+ fees: existing.fees ?? incoming.fees,
228
+ lifecycle: existing.lifecycle.status === "finalized" && incoming.lifecycle.status === "rejected" ? existing.lifecycle : incoming.lifecycle,
229
+ ...shielded !== void 0 ? { shielded } : {},
230
+ ...unshielded !== void 0 ? { unshielded } : {},
231
+ ...dust !== void 0 ? { dust } : {}
232
+ };
233
+ }
234
+ /**
235
+ * Storage key for a tx we're about to submit (record as pending). The hash comes from {@link txHistoryHash}, which the
236
+ * revert side uses too — so a tx keyed here while pending resolves to the same key when later confirmed or reverted.
237
+ */
238
+ const submitTxHistoryKey = (tx) => ({
239
+ hash: txHistoryHash(tx),
240
+ identifiers: tx.identifiers()
241
+ });
242
+ /**
243
+ * Storage key for a tx we're about to revert (record as rejected). Shares {@link txHistoryHash} with the submit side so
244
+ * the rejected entry lands on the pending entry in place. Returns `undefined` only when the tx has no identifiers at
245
+ * all (nothing to revert).
246
+ */
247
+ const revertTxHistoryKey = (tx) => {
248
+ const identifiers = tx.identifiers();
249
+ if (identifiers.length === 0) return void 0;
250
+ return {
251
+ hash: txHistoryHash(tx),
252
+ identifiers
253
+ };
254
+ };
255
+ const v9Authoring = {
256
+ sampleSigningKey: () => _midnightntwrk_ledger_v9.sampleSigningKey(),
257
+ signatureVerifyingKey: (signingKey) => _midnightntwrk_ledger_v9.signatureVerifyingKey(signingKey),
258
+ signData: (signingKey, data) => _midnightntwrk_ledger_v9.signData(signingKey, data),
259
+ deserializers: {
260
+ Unproven: (bytes) => _midnightntwrk_ledger_v9.Transaction.deserialize("signature", "pre-proof", "pre-binding", bytes),
261
+ Unbound: (bytes) => _midnightntwrk_ledger_v9.Transaction.deserialize("signature", "proof", "pre-binding", bytes),
262
+ Finalized: (bytes) => _midnightntwrk_ledger_v9.Transaction.deserialize("signature", "proof", "binding", bytes)
263
+ }
264
+ };
265
+ const v8Authoring = {
266
+ sampleSigningKey: () => _midnight_ntwrk_ledger_v8.sampleSigningKey(),
267
+ signatureVerifyingKey: (signingKey) => require_v8Signatures.liftSignatureVerifyingKey(_midnight_ntwrk_ledger_v8.signatureVerifyingKey(signingKey)),
268
+ signData: (signingKey, data) => require_v8Signatures.liftSignature(_midnight_ntwrk_ledger_v8.signData(signingKey, data)),
269
+ deserializers: {
270
+ Unproven: (bytes) => _midnight_ntwrk_ledger_v8.Transaction.deserialize("signature", "pre-proof", "pre-binding", bytes),
271
+ Unbound: (bytes) => _midnight_ntwrk_ledger_v8.Transaction.deserialize("signature", "proof", "pre-binding", bytes),
272
+ Finalized: (bytes) => _midnight_ntwrk_ledger_v8.Transaction.deserialize("signature", "proof", "binding", bytes)
273
+ }
274
+ };
275
+ const TokenKindsToBalance = new class {
276
+ allTokenKinds = [
277
+ "shielded",
278
+ "unshielded",
279
+ "dust"
280
+ ];
281
+ toFlags = (tokenKinds) => {
282
+ return require_dist.pipe(tokenKinds, (kinds) => kinds === "all" ? this.allTokenKinds : kinds, (kinds) => ({
283
+ shouldBalanceUnshielded: kinds.includes("unshielded"),
284
+ shouldBalanceShielded: kinds.includes("shielded"),
285
+ shouldBalanceDust: kinds.includes("dust")
286
+ }));
287
+ };
288
+ }();
289
+ const BalancingRecipe = {
290
+ isRecipe: (value) => {
291
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string" && [
292
+ "FINALIZED_TRANSACTION",
293
+ "UNBOUND_TRANSACTION",
294
+ "UNPROVEN_TRANSACTION"
295
+ ].includes(value.type);
296
+ },
297
+ getTransactions: (recipe) => {
298
+ switch (recipe.type) {
299
+ case "FINALIZED_TRANSACTION": return [recipe.originalTransaction, recipe.balancingTransaction];
300
+ case "UNBOUND_TRANSACTION": {
301
+ const balancingPart = recipe.balancingTransaction ? [recipe.balancingTransaction] : [];
302
+ return [recipe.baseTransaction, ...balancingPart];
303
+ }
304
+ case "UNPROVEN_TRANSACTION": return [recipe.transaction];
305
+ }
306
+ }
307
+ };
308
+ /**
309
+ * The lowest of the protocol versions the three wallets have reached.
310
+ *
311
+ * @remarks
312
+ * The three wallets follow the same chain but not in lock-step: each recognises a protocol version change when its own
313
+ * synchronization reaches it, so around a fork they disagree for a while. A transaction spans all three, so the one
314
+ * still behind is what bounds the facade as a whole — the highest version every wallet is known to be at.
315
+ * @param versions The version each wallet has reached.
316
+ * @returns The lowest of the three.
317
+ */
318
+ const lowestProtocolVersion = (versions) => [
319
+ versions.shielded,
320
+ versions.unshielded,
321
+ versions.dust
322
+ ].reduce((lowest, candidate) => candidate < lowest ? candidate : lowest);
323
+ /**
324
+ * The ledger-v9 key objects the wallets' own `start` takes, from whichever material the caller supplied.
325
+ *
326
+ * @remarks
327
+ * Only the ledger-v9 side is needed here: a wallet built from seeds or from both versions' keys already holds what its
328
+ * V1 variant needs, retained when it was built. What `start` supplies is the side the wallet's own API speaks.
329
+ */
330
+ const v9KeysOf = (material) => "v9" in material ? material.v9 : {
331
+ shielded: _midnightntwrk_ledger_v9.ZswapSecretKeys.fromSeed(material.shielded),
332
+ dust: _midnightntwrk_ledger_v9.DustSecretKey.fromSeed(material.dust)
333
+ };
334
+ /** The three wallets in a fixed order, so {@link protocolPhaseOf} reports them the same way every time. */
335
+ const walletKinds = [
336
+ "shielded",
337
+ "unshielded",
338
+ "dust"
339
+ ];
340
+ /**
341
+ * Reads whether the wallets are settled on one side of a protocol boundary, or still crossing it.
342
+ *
343
+ * @remarks
344
+ * Derived entirely from the version each wallet has reported and where the boundary lies — the same two facts every
345
+ * other version-routing decision in the SDK is made from, so this reading cannot disagree with them.
346
+ * @param versions The version each wallet has reached.
347
+ * @param forkVersion The version at which the chain hands over to the next ledger version.
348
+ * @returns The reading. See {@link ProtocolPhase}.
349
+ */
350
+ const protocolPhaseOf = (versions, forkVersion) => {
351
+ const reported = walletKinds.map((kind) => [kind, versions[kind]]);
352
+ const from = lowestProtocolVersion(versions);
353
+ const epoch = require_dist.epochOf(from, forkVersion);
354
+ const crossed = reported.filter(([, version]) => !require_dist.withinRange(version, epoch));
355
+ if (crossed.length === 0) return {
356
+ _tag: "Settled",
357
+ version: from
358
+ };
359
+ return {
360
+ _tag: "Crossing",
361
+ from,
362
+ to: crossed.reduce((highest, [, version]) => version > highest ? version : highest, crossed[0][1]),
363
+ behind: reported.filter(([, version]) => require_dist.withinRange(version, epoch)).map(([kind]) => kind)
364
+ };
365
+ };
366
+ /** Reads what has become of a transaction from the verdict the pending set holds, if it holds one. */
367
+ const pendingStatusOf = (result) => {
368
+ if (result === void 0) return { _tag: "Submitted" };
369
+ switch (result.status) {
370
+ case "SUCCESS": return {
371
+ _tag: "Confirmed",
372
+ segments: result.segments
373
+ };
374
+ case "FAILURE":
375
+ case "PARTIAL_SUCCESS": return {
376
+ _tag: "Rejected",
377
+ segments: result.segments
378
+ };
379
+ case "ORPHANED_BY_FORK": return {
380
+ _tag: "Orphaned",
381
+ authoredFor: result.authoredFor,
382
+ chainNow: result.chainNow
383
+ };
384
+ }
385
+ };
386
+ /**
387
+ * The pending transactions as an application reads them.
388
+ *
389
+ * @remarks
390
+ * A projection over the pending set the services keep, not a second copy of it: the facts are the same, stated as a
391
+ * list of transactions with a status each rather than as the bag the machinery works in.
392
+ * @param pending The pending set.
393
+ * @returns One entry per transaction, in the order the wallet recorded them.
394
+ */
395
+ const pendingTransactionsOf = (pending) => pending.all.map((item) => ({
396
+ transaction: item.tx,
397
+ submittedAt: item.creationTime,
398
+ authoredFor: item.protocolVersion,
399
+ status: pendingStatusOf("result" in item ? item.result : void 0)
400
+ }));
401
+ var FacadeState = class {
402
+ shielded;
403
+ unshielded;
404
+ dust;
405
+ pending;
406
+ /** The protocol version each of the three wallets has reached. */
407
+ get protocolVersion() {
408
+ return {
409
+ shielded: this.shielded.protocolVersion,
410
+ unshielded: this.unshielded.protocolVersion,
411
+ dust: this.dust.protocolVersion
412
+ };
413
+ }
414
+ /**
415
+ * The protocol version the facade as a whole can act at: the lowest the three wallets have reached.
416
+ *
417
+ * @remarks
418
+ * Around a protocol boundary the three wallets cross at slightly different moments, and a transaction needs all
419
+ * three. This is the version every one of them is known to understand.
420
+ */
421
+ get activeProtocolVersion() {
422
+ return lowestProtocolVersion(this.protocolVersion);
423
+ }
424
+ /**
425
+ * Whether the three wallets are settled on one side of the protocol boundary, or still crossing it.
426
+ *
427
+ * @remarks
428
+ * Additive, and the reading `protocolVersion` alone cannot give: three versions that differ tell an application
429
+ * nothing about whether the difference matters. See {@link ProtocolPhase}.
430
+ */
431
+ get protocol() {
432
+ return protocolPhaseOf(this.protocolVersion, this.#forkVersion);
433
+ }
434
+ get isSynced() {
435
+ return this.shielded.state.progress.isStrictlyComplete() && this.dust.state.progress.isStrictlyComplete() && this.unshielded.progress.isStrictlyComplete();
436
+ }
437
+ /** Where the chain hands over from one ledger version to the next, which is what {@link protocol} is read against. */
438
+ #forkVersion;
439
+ constructor(shielded, unshielded, dust, pending, forkVersion = require_dist.MinSupportedVersion) {
440
+ this.shielded = shielded;
441
+ this.unshielded = unshielded;
442
+ this.dust = dust;
443
+ this.pending = pendingTransactionsOf(pending);
444
+ this.#forkVersion = forkVersion;
445
+ }
446
+ };
447
+ const DEFAULT_TTL_MS = 3600 * 1e3;
448
+ /**
449
+ * The fork schedule the facade presets when a configuration names none: {@link ProtocolVersion.V9NativeForkSchedule},
450
+ * ledger-v9 from the version a 2.x node reports.
451
+ *
452
+ * @remarks
453
+ * Where a chain forks is a fact about the chain, which is why each wallet package requires `forks` and presets nothing.
454
+ * The facade is the one place a preset decides nothing the SDK has not already decided: every chain the 2.x node line
455
+ * runs hands over at this version, so an application copying the constant into its configuration only restates it. A
456
+ * chain that hands over elsewhere states its own `forks`, which wins.
457
+ */
458
+ const DefaultForkSchedule = require_dist.V9NativeForkSchedule;
459
+ var WalletFacade = class WalletFacade {
460
+ static makeDefaultSubmissionService(config) {
461
+ return require_dist.makeDefaultSubmissionService(config);
462
+ }
463
+ static makeDefaultPendingTransactionsService(config) {
464
+ return require_dist.PendingTransactionsServiceImpl.init({
465
+ configuration: config,
466
+ txTraits: finalizedTransactionTraits(config.forks.v9)
467
+ });
468
+ }
469
+ /**
470
+ * Builds the proving service a configuration describes.
471
+ *
472
+ * @remarks
473
+ * Handed the same fork schedule the wallets are built with, because a proving backend is chosen by the epoch a
474
+ * transaction belongs to and the two ends of that question must not be able to compute the boundary differently.
475
+ */
476
+ static makeDefaultProvingService(config) {
477
+ return require_dist.getOrThrowWith(require_dist.makeDefaultVersionedProvingService(config, config.forks), (error) => new Error(error.message));
478
+ }
479
+ /**
480
+ * Fills in what the facade presets — `forks`, as {@link DefaultForkSchedule} — so that the result is a configuration a
481
+ * wallet package can be built from.
482
+ *
483
+ * @remarks
484
+ * {@link WalletFacade.init} does this itself, once and before anything is built, so the wallets, the default services
485
+ * and the facade's own boundary cannot be given different schedules, and no factory needs to call it. It is public
486
+ * for code outside a factory that needs the configuration the facade will use: an application building a wallet
487
+ * package directly, or reading `forks` back to author a transaction for the right ledger version. Resolving twice
488
+ * is the same as resolving once, so `init` may be handed the result.
489
+ * @example
490
+ * ```typescript
491
+ * const configuration = WalletFacade.resolveConfiguration({ networkId: 'undeployed', ... });
492
+ * const facade = await WalletFacade.init({ configuration, shielded: (config) => ShieldedWallet(config), ... });
493
+ * const authoredForV9 = protocolVersion >= configuration.forks.v9;
494
+ * ```;
495
+ *
496
+ * @param configuration The configuration as given, with or without `forks`.
497
+ * @returns The same configuration with `forks` present: the schedule it named, or {@link DefaultForkSchedule}.
498
+ */
499
+ static resolveConfiguration(configuration) {
500
+ return {
501
+ ...configuration,
502
+ forks: configuration.forks ?? DefaultForkSchedule
503
+ };
504
+ }
505
+ /**
506
+ * Fetches the current Terms and Conditions from the network indexer.
507
+ *
508
+ * This is a static, pre-initialization utility — no wallet instance is required. Wallet builders should call this
509
+ * before or independently of wallet initialization to display the current T&C to end users and obtain the hash for
510
+ * content verification.
511
+ *
512
+ * The returned `hash` is the hex-encoded SHA-256 hash of the document at `url`. Wallet builders are responsible for
513
+ * fetching and rendering the document content via `url` in whatever manner suits their application.
514
+ *
515
+ * @param configuration - An object with an `indexerClientConnection.indexerHttpUrl`. Any wallet configuration that
516
+ * satisfies {@link FetchTermsAndConditionsConfiguration} can be passed directly.
517
+ * @returns A promise resolving to the current {@link TermsAndConditions}, or rejecting if no Terms and Conditions have
518
+ * been set on the network yet.
519
+ */
520
+ static async fetchTermsAndConditions(configuration) {
521
+ const tc = (await require_dist.runPromise(require_dist.FetchTermsAndConditions, {}, { url: configuration.indexerClientConnection.indexerHttpUrl })).block?.systemParameters?.termsAndConditions;
522
+ if (!tc) throw new Error("Terms and Conditions are not currently set on the network.");
523
+ return tc;
524
+ }
525
+ /**
526
+ * Default initialization for {@link WalletFacade}. It is a static method, which takes an object holding configuration
527
+ * and initialization of necessary components. Specifically - it requires following fields:
528
+ *
529
+ * - `configuration` - holding a configuration, which needs to extend {@link DefaultConfiguration} - this way allows to
530
+ * convey use-case-specific settings in the same way, as the SDK works by default. `forks` may be left out; every
531
+ * factory below is handed a {@link ResolvedConfiguration}, which always has it — what
532
+ * {@link WalletFacade.resolveConfiguration} returns
533
+ * - `shielded` - a function taking the configuration and returning shielded wallet (or a promise with such)
534
+ * implementing {@link ShieldedWalletAPI}
535
+ * - `unshielded` - a function taking the configuration and returning unshielded wallet (or a promise with such)
536
+ * implementing {@link UnshieldedWalletAPI}
537
+ * - `dust` - a function taking the configuration and returning Dust wallet (or a promise with such) implementing
538
+ * {@link DustWalletAPI} There are some optional services/abstractions to provide, too. If not provided - default
539
+ * implementations will be used, each of them is initialized by a function taking the configuration and returning
540
+ * proper implementation (wrapped in a {@link Promise} or not).
541
+ * - `submissionService` - needs to implement {@link SubmissionService} for a {@link ledgerV9.FinalizedTransaction} to
542
+ * submit transactions to the network, default uses Node RPC connection
543
+ * - `pendingTransactionsService` - needs to implement {@link PendingTransactionsService} for a
544
+ * {@link ledgerV9.FinalizedTransaction} to keep track of pending transactions, default uses in-memory
545
+ * implementation
546
+ * - `provingService` - needs to implement {@link VersionedProvingService} to prove it, default uses proving server
547
+ * - `clock` - needs to implement {@link Clock.Clock} for getting current time, default uses system clock
548
+ */
549
+ static async init(initParams) {
550
+ const configuration = WalletFacade.resolveConfiguration(initParams.configuration);
551
+ const submissionService = await Promise.resolve(initParams.submissionService ? initParams.submissionService(configuration) : WalletFacade.makeDefaultSubmissionService(configuration));
552
+ const pendingTransactionsService = await Promise.resolve(initParams.pendingTransactionsService ? initParams.pendingTransactionsService(configuration) : WalletFacade.makeDefaultPendingTransactionsService(configuration));
553
+ const provingService = await Promise.resolve(initParams.provingService ? initParams.provingService(configuration) : WalletFacade.makeDefaultProvingService(configuration));
554
+ const shielded = await Promise.resolve(initParams.shielded(configuration));
555
+ const unshielded = await Promise.resolve(initParams.unshielded(configuration));
556
+ const dust = await Promise.resolve(initParams.dust(configuration));
557
+ const clock = await Promise.resolve(initParams.clock ? initParams.clock(configuration) : require_dist.systemClock);
558
+ const fetchBlockData = await Promise.resolve(initParams.fetchBlockData ? initParams.fetchBlockData(configuration) : require_dist.makeDefaultBlockDataFetcher(configuration));
559
+ return new WalletFacade(shielded, unshielded, dust, submissionService, pendingTransactionsService, provingService, await Promise.resolve(initParams.validationService ? initParams.validationService(configuration, {
560
+ fetchBlockData,
561
+ clock
562
+ }) : require_dist.makeDefaultVersionedValidationService({
563
+ fetchBlockData,
564
+ networkId: configuration.networkId,
565
+ clock
566
+ }, configuration.forks.v9)), configuration.txHistoryStorage, configuration.forks.v9, clock);
567
+ }
568
+ shielded;
569
+ unshielded;
570
+ dust;
571
+ submissionService;
572
+ pendingTransactionsService;
573
+ provingService;
574
+ validationService;
575
+ #txHistoryStorage;
576
+ clock;
577
+ #pendingSubscription;
578
+ #protocolVersionSubscription;
579
+ /**
580
+ * The protocol version the wallets have all reached, as last observed.
581
+ *
582
+ * @remarks
583
+ * `Option.none()` until the three wallets have each emitted once. A transaction stamped with `none` is never
584
+ * orphaned, so an unobserved version costs a transaction nothing but the ability to be given up on early.
585
+ */
586
+ #observedProtocolVersion = new rxjs.BehaviorSubject(require_dist.none());
587
+ /** Where the chain hands over from one ledger version to the next, which is what divides the two epochs. */
588
+ #forkVersion;
589
+ /**
590
+ * Constructor is private on purpose - much of initialization of the facade is potentially asynchronous, and adding
591
+ * new parameters is a breaking change to the users Use {@link WalletFacade.init} instead
592
+ *
593
+ * @private
594
+ */
595
+ constructor(shieldedWallet, unshieldedWallet, dustWallet, submissionService, pendingTransactionsService, provingService, validationService, txHistoryStorage, forkVersion, clock = require_dist.systemClock) {
596
+ this.shielded = shieldedWallet;
597
+ this.unshielded = unshieldedWallet;
598
+ this.dust = dustWallet;
599
+ this.submissionService = submissionService;
600
+ this.pendingTransactionsService = pendingTransactionsService;
601
+ this.provingService = provingService;
602
+ this.validationService = validationService;
603
+ this.#txHistoryStorage = txHistoryStorage;
604
+ this.#forkVersion = forkVersion;
605
+ this.clock = clock;
606
+ this.#pendingSubscription = this.pendingTransactionsService.state().pipe((0, rxjs.concatMap)((pending) => require_dist.allRejected(pending)), (0, rxjs.concatMap)(async (item) => {
607
+ if (!await this.reconcileFinalizedTransaction(item.tx, await this.#txHistoryStorage.getAll())) await this.revert(item.tx, rejectionReason(item.result));
608
+ })).subscribe();
609
+ this.#protocolVersionSubscription = (0, rxjs.combineLatest)([
610
+ this.shielded.state,
611
+ this.unshielded.state,
612
+ this.dust.state
613
+ ]).pipe((0, rxjs.map)(([shieldedState, unshieldedState, dustState]) => lowestProtocolVersion({
614
+ shielded: shieldedState.protocolVersion,
615
+ unshielded: unshieldedState.protocolVersion,
616
+ dust: dustState.protocolVersion
617
+ })), (0, rxjs.distinctUntilChanged)(), (0, rxjs.tap)((version) => this.#observedProtocolVersion.next(require_dist.some(version))), (0, rxjs.concatMap)((version) => this.pendingTransactionsService.orphanBeyond(version))).subscribe();
618
+ }
619
+ /**
620
+ * The protocol version the facade is currently acting at.
621
+ *
622
+ * @remarks
623
+ * The lowest the three wallets have reached, once they have all reported; the minimum supported version until then,
624
+ * which is the epoch a wallet with no history belongs to. It is what a transaction the facade builds is stamped
625
+ * with, and what the side of the boundary it accepts transactions from is measured against.
626
+ */
627
+ currentVersion() {
628
+ return require_dist.getOrElse(this.#observedProtocolVersion.getValue(), () => require_dist.MinSupportedVersion);
629
+ }
630
+ /** The range of protocol versions on the same side of the boundary as a given one. */
631
+ epochOf(version) {
632
+ return require_dist.epochOf(version, this.#forkVersion);
633
+ }
634
+ /** The range of protocol versions on the facade's current side of the boundary. */
635
+ currentEpoch() {
636
+ return this.epochOf(this.currentVersion());
637
+ }
638
+ /**
639
+ * Reads a transaction an application handed in, refusing one built on the other side of the boundary.
640
+ *
641
+ * @remarks
642
+ * The enforcement point for everything that enters the facade — a transaction the wallets built, or one an
643
+ * application authored and sealed with `WalletTransaction.adopt`. Only the current epoch is accepted, because a
644
+ * transaction of the other one cannot be merged, proved or submitted alongside anything the facade would build for
645
+ * it. Both a stranded ledger-v8 transaction after the crossing and a ledger-v9 transaction offered before it are
646
+ * refused here, by name, with the versions written down.
647
+ * @param handle The handle to read.
648
+ * @returns The carried transaction.
649
+ * @throws {@link ProtocolVersionMismatchError} When the transaction was built on the other side of the boundary.
650
+ */
651
+ accept(handle) {
652
+ return require_dist.getOrThrowWith(require_dist.WalletTransaction.unwrapWithin(handle, this.currentEpoch()), (error) => error);
653
+ }
654
+ /**
655
+ * Seals a transaction the facade or a wallet produced, at the version its bytes were fixed by.
656
+ *
657
+ * @remarks
658
+ * The version is the caller's to state, never read from the facade here, because the two can differ: a crossing can
659
+ * land while a transaction is at the prover, and what comes back is still the bytes of the ledger version that made
660
+ * them. A caller sealing something it has just built passes the version it is building at; a caller sealing
661
+ * something that has travelled through an await passes the version stamped on the handle it started from.
662
+ * @param stage How far along the building of the transaction the sealed handle is.
663
+ * @param transaction The transaction to seal.
664
+ * @param protocolVersion The version the transaction's bytes were fixed by.
665
+ * @returns The sealed handle.
666
+ */
667
+ seal(stage, transaction, protocolVersion) {
668
+ return require_dist.WalletTransaction.adopt(stage, transaction, protocolVersion);
669
+ }
670
+ /** The ledger primitives the facade signs with on its current side of the boundary. */
671
+ authoring() {
672
+ return this.currentVersion() < this.#forkVersion ? v8Authoring : v9Authoring;
673
+ }
674
+ /**
675
+ * Reads a transaction from bytes that name no protocol version, at the version the facade is acting at.
676
+ *
677
+ * @remarks
678
+ * For bytes that reach the wallet from outside the SDK — a dApp connector's serialized transaction above all, whose
679
+ * contract carries no version alongside them. The bytes cannot say which ledger version wrote them, so this answers
680
+ * with the only version the facade could act at anyway, and reads them with that version's ledger. Bytes the other
681
+ * ledger version wrote are refused here rather than misread, because the markers a stage names are part of what the
682
+ * ledger checks as it reads.
683
+ *
684
+ * The version is the facade's rather than the caller's, which is the point: a caller that reads
685
+ * {@link FacadeState.activeProtocolVersion} and seals a handle itself is answering the same question a moment
686
+ * earlier, with a crossing able to land in between. It is still only the version at the moment of the call — a
687
+ * crossing can land before the handle is used, and {@link ProtocolVersionMismatchError} from the operation that uses
688
+ * it is what says so.
689
+ * @example
690
+ * Balancing a transaction a dApp connector handed over as hex:
691
+ *
692
+ * ```typescript
693
+ * const handle = facade.adoptTransaction(Buffer.from(txHex, 'hex'), 'Unbound');
694
+ * const recipe = await facade.balanceUnboundTransaction(handle, { ttl });
695
+ * ```;
696
+ *
697
+ * @param bytes The transaction's own serialization, as the ledger version that wrote it produced it.
698
+ * @param stage How far along the building of the transaction these bytes are, which decides the markers they are read
699
+ * with.
700
+ * @returns The sealed handle, stamped with the protocol version the facade is acting at.
701
+ * @throws {@link WireFormatError} When the bytes are not a transaction of that version at that stage — which is what
702
+ * a transaction authored on the other side of a protocol boundary looks like from here.
703
+ */
704
+ adoptTransaction(bytes, stage) {
705
+ const protocolVersion = this.currentVersion();
706
+ return require_dist.getOrThrowWith(require_dist.try_$1({
707
+ try: () => this.authoring().deserializers[stage](bytes),
708
+ catch: (cause) => new require_dist.WireFormatError({
709
+ message: `These bytes are not a transaction of protocol version ${protocolVersion} at stage ${stage} — that is the version this wallet is acting at, and a transaction built for another one has to be built again for it.`,
710
+ cause
711
+ })
712
+ }).pipe(require_dist.map$6((transaction) => require_dist.WalletTransaction.adopt(stage, transaction, protocolVersion))), (error) => error);
713
+ }
714
+ defaultTtl() {
715
+ return new Date(this.clock.now().getTime() + DEFAULT_TTL_MS);
716
+ }
717
+ /**
718
+ * Checks whether a transaction is structurally well-formed before passing it to a balance or submit method.
719
+ *
720
+ * Highly recommended in particular for transactions received from a 3rd party (e.g., a dApp or partner service)
721
+ * before forwarding them to a balance or submit method.
722
+ *
723
+ * TTL expiry, Network ID mismatch, and transaction structure are always enforced regardless of `flags`. All three
724
+ * configurable flags must be supplied explicitly — there are no defaults, so callers must be intentional about each
725
+ * check.
726
+ *
727
+ * Recommended flags per call site:
728
+ *
729
+ * | Method | enforceBalancing | verifySignatures | enforceLimits |
730
+ * | ----------------------------- | ---------------- | ---------------- | ------------- |
731
+ * | `submitTransaction` | `true` | `true` | `true` |
732
+ * | `balanceFinalizedTransaction` | `false` | `true` | `false` |
733
+ * | `balanceUnboundTransaction` | `false` | `false` | `false` |
734
+ * | `balanceUnprovenTransaction` | `false` | `false` | `false` |
735
+ *
736
+ * Real on-chain ledger parameters are always used — `options.blockData` is used if provided, otherwise the service
737
+ * fetches the latest block data via the configured fetcher. Pass `recipe.blockData` to reuse the fetch performed
738
+ * during balancing and avoid a redundant network call.
739
+ *
740
+ * @example
741
+ * ```typescript
742
+ * // Reuse the block data captured during balancing — no extra fetch
743
+ * const recipe = await facade.balanceFinalizedTransaction(tx, secretKeys, options);
744
+ * const finalizedTx = await facade.finalizeRecipe(recipe);
745
+ * await facade.validateTransaction(finalizedTx, {
746
+ * flags: { enforceBalancing: true, verifySignatures: true, enforceLimits: true },
747
+ * blockData: recipe.blockData,
748
+ * });
749
+ * await facade.submitTransaction(finalizedTx);
750
+ *
751
+ * // No recipe to source blockData from — the service fetches automatically
752
+ * await facade.validateTransaction(tx, {
753
+ * flags: { enforceBalancing: false, verifySignatures: false, enforceLimits: false },
754
+ * });
755
+ * ```;
756
+ *
757
+ * @param tx - The transaction to validate (`FinalizedTransaction`, `UnboundTransaction`, or `UnprovenTransaction`).
758
+ * @param options - Strictness flags and optional `blockData` to skip the fetch.
759
+ * @throws {@link WellFormedError} If the transaction fails any enabled check.
760
+ * @throws {@link ValidationFetchError} If the block-data fetch fails.
761
+ */
762
+ async validateTransaction(tx, options) {
763
+ return this.validationService.validateTx(require_dist.getOrThrowWith(require_dist.WalletTransaction.unwrapWithin(tx, require_dist.epochOf(tx.protocolVersion, this.#forkVersion)), (error) => error), tx.protocolVersion, options);
764
+ }
765
+ /**
766
+ * Merges two unproven transactions of the same epoch, or returns whichever there is.
767
+ *
768
+ * @remarks
769
+ * Both are unwrapped before merging, which is where a pair from different epochs is refused: a merge across the
770
+ * boundary is not a failure to compute, it is unrepresentable, and saying so is the whole point of the stamp.
771
+ */
772
+ mergeUnprovenTransactions(a, b) {
773
+ if (a && b) return this.seal("Unproven", this.accept(a).merge(this.accept(b)), this.currentVersion());
774
+ return a ?? b;
775
+ }
776
+ async createDustActionTransaction(action, nightUtxos, nightVerifyingKey, signDustRegistration) {
777
+ const ttl = this.defaultTtl();
778
+ const now = this.clock.now();
779
+ const isRegistration = action.type === "registration";
780
+ const dustReceiverAddress = isRegistration ? action.dustReceiverAddress : void 0;
781
+ const split = await this.dust.splitNightUtxosForDustRegistration(now, nightUtxos.map(({ utxo, meta }) => ({
782
+ ...utxo,
783
+ ctime: meta.ctime,
784
+ registeredForDustGeneration: meta.registeredForDustGeneration
785
+ })), isRegistration);
786
+ const toUnshieldedUtxoWithMeta = (u) => ({
787
+ utxo: {
788
+ value: u.utxo.value,
789
+ type: u.utxo.type,
790
+ owner: u.utxo.owner,
791
+ intentHash: u.utxo.intentHash,
792
+ outputNo: u.utxo.outputNo
793
+ },
794
+ meta: {
795
+ ctime: u.utxo.ctime,
796
+ registeredForDustGeneration: u.utxo.registeredForDustGeneration
797
+ }
798
+ });
799
+ const guaranteedForUnshielded = split.guaranteedUtxos.map(toUnshieldedUtxoWithMeta);
800
+ const fallibleForUnshielded = split.fallibleUtxos.map(toUnshieldedUtxoWithMeta);
801
+ const txWithOffers = await this.unshielded.rotateUtxos(guaranteedForUnshielded, fallibleForUnshielded, nightVerifyingKey, ttl);
802
+ let txWithDustActions;
803
+ try {
804
+ txWithDustActions = await this.dust.attachDustRegistration(txWithOffers, now, nightVerifyingKey, dustReceiverAddress, split.feePayment);
805
+ } catch (error) {
806
+ await this.unshielded.revertTransaction(txWithOffers);
807
+ throw error;
808
+ }
809
+ const hasUnregisteredGuaranteed = split.guaranteedUtxos.some((u) => !u.utxo.registeredForDustGeneration);
810
+ if (isRegistration && hasUnregisteredGuaranteed) {
811
+ const fee = await this.dust.calculateFee([txWithDustActions]);
812
+ if (split.feePayment < fee) {
813
+ await this.unshielded.revertTransaction(txWithOffers);
814
+ throw Error(`Insufficient generated dust to cover registration fee (have ${split.feePayment}, need ${fee}). Use WalletFacade.waitForGeneratedDust(utxos, ${fee}) before retrying.`);
815
+ }
816
+ }
817
+ try {
818
+ const signedRecipe = await this.signRecipe({
819
+ type: "UNPROVEN_TRANSACTION",
820
+ protocolVersion: this.currentVersion(),
821
+ transaction: txWithDustActions
822
+ }, signDustRegistration);
823
+ if (signedRecipe.type !== "UNPROVEN_TRANSACTION") throw Error("signRecipe returned unexpected recipe type for dust action transaction.");
824
+ return signedRecipe.transaction;
825
+ } catch (error) {
826
+ await this.unshielded.revertTransaction(txWithOffers);
827
+ throw error;
828
+ }
829
+ }
830
+ state() {
831
+ return (0, rxjs.combineLatest)([
832
+ this.shielded.state,
833
+ this.unshielded.state,
834
+ this.dust.state,
835
+ this.pendingTransactionsService.state()
836
+ ]).pipe((0, rxjs.map)(([shieldedState, unshieldedState, dustState, pending]) => new FacadeState(shieldedState, unshieldedState, dustState, pending, this.#forkVersion)));
837
+ }
838
+ async waitForSyncedState() {
839
+ const [shieldedState, unshieldedState, dustState, pending] = await Promise.all([
840
+ this.shielded.waitForSyncedState(),
841
+ this.unshielded.waitForSyncedState(),
842
+ this.dust.waitForSyncedState(),
843
+ (0, rxjs.firstValueFrom)(this.pendingTransactionsService.state())
844
+ ]);
845
+ return new FacadeState(shieldedState, unshieldedState, dustState, pending, this.#forkVersion);
846
+ }
847
+ /**
848
+ * Submits a finalized transaction to the network and tracks it as pending until finalized or discarded.
849
+ *
850
+ * Call {@link validateTransaction} with `{ enforceBalancing: true, verifySignatures: true, enforceLimits: true }`
851
+ * before this method to surface structural errors with a clear diagnostic instead of a cryptic network rejection.
852
+ *
853
+ * @param tx - The finalized transaction to submit.
854
+ * @returns The transaction identifier.
855
+ * @throws {@link WellFormedError} — call {@link validateTransaction} first to get this error early.
856
+ */
857
+ async submitTransaction(tx) {
858
+ const carried = this.accept(tx);
859
+ const identifiers = carried.identifiers();
860
+ try {
861
+ await this.pendingTransactionsService.addPendingTransaction(tx, this.#observedProtocolVersion.getValue());
862
+ const key = submitTxHistoryKey(carried);
863
+ await this.#txHistoryStorage.gotPending({
864
+ ...key,
865
+ submittedAt: this.clock.now()
866
+ });
867
+ await this.submissionService.submitTransaction(tx, "Finalized");
868
+ return identifiers.at(-1);
869
+ } catch (error) {
870
+ await this.revert(tx);
871
+ throw error;
872
+ }
873
+ }
874
+ /**
875
+ * Balances a finalized transaction by adding shielded, unshielded, and dust inputs/outputs as needed.
876
+ *
877
+ * Call {@link validateTransaction} with `{ enforceBalancing: false, verifySignatures: true, enforceLimits: false }`
878
+ * before this method to surface structural errors early. `enforceBalancing` is `false` because the transaction is not
879
+ * yet balanced at this stage; `verifySignatures` is `true` because signatures are already present and must be valid.
880
+ *
881
+ * @param tx - The finalized transaction to balance.
882
+ * @param secretKeys - Secret keys for shielded and dust coin selection.
883
+ * @param options - TTL for the balancing transaction, and optional subset of token kinds to balance.
884
+ * @returns A {@link FinalizedTransactionRecipe} containing the original and balancing transactions.
885
+ */
886
+ async balanceFinalizedTransaction(tx, options) {
887
+ const { ttl, tokenKindsToBalance = "all" } = options;
888
+ const { shouldBalanceDust, shouldBalanceShielded, shouldBalanceUnshielded } = TokenKindsToBalance.toFlags(tokenKindsToBalance);
889
+ const unshieldedBalancingTx = shouldBalanceUnshielded ? await this.unshielded.balanceFinalizedTransaction(tx) : void 0;
890
+ const shieldedBalancingTx = shouldBalanceShielded ? await this.shielded.balanceTransaction(tx) : void 0;
891
+ const mergedBalancingTx = this.mergeUnprovenTransactions(shieldedBalancingTx, unshieldedBalancingTx);
892
+ const dustResult = shouldBalanceDust ? await this.dust.balanceTransactions(mergedBalancingTx ? [tx, mergedBalancingTx] : [tx], ttl) : void 0;
893
+ const feeBalancingTx = dustResult?.transaction;
894
+ const balancingTx = this.mergeUnprovenTransactions(mergedBalancingTx, feeBalancingTx);
895
+ if (!balancingTx) throw new Error("No balancing transaction was created. Please check your transaction.");
896
+ return {
897
+ type: "FINALIZED_TRANSACTION",
898
+ protocolVersion: this.currentVersion(),
899
+ originalTransaction: tx,
900
+ balancingTransaction: balancingTx,
901
+ ...dustResult ? { blockData: dustResult.blockData } : {}
902
+ };
903
+ }
904
+ /**
905
+ * Balances an unbound (proven, pre-binding) transaction by adding shielded, unshielded, and dust inputs/outputs.
906
+ *
907
+ * Call {@link validateTransaction} with `{ enforceBalancing: false, verifySignatures: false, enforceLimits: false }`
908
+ * before this method to surface structural errors early. All configurable flags are `false` because the transaction
909
+ * is not yet balanced and signatures are not yet present.
910
+ *
911
+ * @param tx - The unbound transaction to balance.
912
+ * @param secretKeys - Secret keys for shielded and dust coin selection.
913
+ * @param options - TTL for the balancing transaction, and optional subset of token kinds to balance.
914
+ * @returns An {@link UnboundTransactionRecipe} containing the base and optional balancing transactions.
915
+ */
916
+ async balanceUnboundTransaction(tx, options) {
917
+ const { ttl, tokenKindsToBalance = "all" } = options;
918
+ const { shouldBalanceDust, shouldBalanceShielded, shouldBalanceUnshielded } = TokenKindsToBalance.toFlags(tokenKindsToBalance);
919
+ const shieldedBalancingTx = shouldBalanceShielded ? await this.shielded.balanceTransaction(tx) : void 0;
920
+ const balancedUnshieldedTx = shouldBalanceUnshielded ? await this.unshielded.balanceUnboundTransaction(tx) : void 0;
921
+ const baseTx = balancedUnshieldedTx ?? tx;
922
+ const dustResult = shouldBalanceDust ? await this.dust.balanceTransactions(shieldedBalancingTx ? [baseTx, shieldedBalancingTx] : [baseTx], ttl) : void 0;
923
+ const feeBalancingTransaction = dustResult?.transaction;
924
+ const balancingTransaction = this.mergeUnprovenTransactions(shieldedBalancingTx, feeBalancingTransaction);
925
+ if (!balancingTransaction && !balancedUnshieldedTx) throw new Error("No balancing transaction was created. Please check your transaction.");
926
+ return {
927
+ type: "UNBOUND_TRANSACTION",
928
+ protocolVersion: this.currentVersion(),
929
+ baseTransaction: baseTx,
930
+ balancingTransaction: balancingTransaction ?? void 0,
931
+ ...dustResult ? { blockData: dustResult.blockData } : {}
932
+ };
933
+ }
934
+ /**
935
+ * Balances an unproven transaction by adding shielded, unshielded, and dust inputs/outputs.
936
+ *
937
+ * Call {@link validateTransaction} with `{ enforceBalancing: false, verifySignatures: false, enforceLimits: false }`
938
+ * before this method to surface structural errors early. All configurable flags are `false` because the transaction
939
+ * is not yet balanced and signatures are not yet present.
940
+ *
941
+ * @param tx - The unproven transaction to balance.
942
+ * @param secretKeys - Secret keys for shielded and dust coin selection.
943
+ * @param options - TTL for the balancing transaction, and optional subset of token kinds to balance.
944
+ * @returns An {@link UnprovenTransactionRecipe} containing the balanced transaction.
945
+ */
946
+ async balanceUnprovenTransaction(tx, options) {
947
+ const { ttl, tokenKindsToBalance = "all" } = options;
948
+ const { shouldBalanceDust, shouldBalanceShielded, shouldBalanceUnshielded } = TokenKindsToBalance.toFlags(tokenKindsToBalance);
949
+ const shieldedBalancingTx = shouldBalanceShielded ? await this.shielded.balanceTransaction(tx) : void 0;
950
+ const baseTx = (shouldBalanceUnshielded ? await this.unshielded.balanceUnprovenTransaction(tx) : void 0) ?? tx;
951
+ const mergedTx = this.mergeUnprovenTransactions(baseTx, shieldedBalancingTx);
952
+ const dustResult = shouldBalanceDust ? await this.dust.balanceTransactions([mergedTx], ttl) : void 0;
953
+ const feeBalancingTx = dustResult?.transaction;
954
+ const balancedTx = this.mergeUnprovenTransactions(mergedTx, feeBalancingTx);
955
+ return {
956
+ type: "UNPROVEN_TRANSACTION",
957
+ protocolVersion: this.currentVersion(),
958
+ transaction: balancedTx,
959
+ ...dustResult ? { blockData: dustResult.blockData } : {}
960
+ };
961
+ }
962
+ async finalizeRecipe(recipe) {
963
+ return Promise.resolve(recipe).then(async (recipe) => {
964
+ switch (recipe.type) {
965
+ case "FINALIZED_TRANSACTION": {
966
+ const finalizedBalancing = await this.finalizeTransaction(recipe.balancingTransaction);
967
+ return this.seal("Finalized", this.accept(recipe.originalTransaction).merge(this.accept(finalizedBalancing)), recipe.originalTransaction.protocolVersion);
968
+ }
969
+ case "UNBOUND_TRANSACTION": {
970
+ const finalizedBalancingTx = recipe.balancingTransaction ? await this.finalizeTransaction(recipe.balancingTransaction) : void 0;
971
+ const finalizedTransaction = this.accept(recipe.baseTransaction).bind();
972
+ return this.seal("Finalized", finalizedBalancingTx ? finalizedTransaction.merge(this.accept(finalizedBalancingTx)) : finalizedTransaction, recipe.baseTransaction.protocolVersion);
973
+ }
974
+ case "UNPROVEN_TRANSACTION": return await this.finalizeTransaction(recipe.transaction);
975
+ }
976
+ }).then(async (finalizedTx) => {
977
+ await this.pendingTransactionsService.addPendingTransaction(finalizedTx, require_dist.some(finalizedTx.protocolVersion));
978
+ return finalizedTx;
979
+ });
980
+ }
981
+ async signRecipe(recipe, signSegment) {
982
+ switch (recipe.type) {
983
+ case "FINALIZED_TRANSACTION": {
984
+ const signedBalancingTx = await this.signUnprovenTransaction(recipe.balancingTransaction, signSegment);
985
+ const withDustSig = await this.#signDustRegistrationIfPresent(signedBalancingTx, signSegment);
986
+ return {
987
+ type: "FINALIZED_TRANSACTION",
988
+ protocolVersion: recipe.protocolVersion,
989
+ originalTransaction: recipe.originalTransaction,
990
+ balancingTransaction: withDustSig,
991
+ ...recipe.blockData ? { blockData: recipe.blockData } : {}
992
+ };
993
+ }
994
+ case "UNBOUND_TRANSACTION": {
995
+ const signedBalancingTx = recipe.balancingTransaction ? await this.signUnprovenTransaction(recipe.balancingTransaction, signSegment).then((tx) => this.#signDustRegistrationIfPresent(tx, signSegment)) : void 0;
996
+ const signedBaseTx = await this.signUnboundTransaction(recipe.baseTransaction, signSegment);
997
+ return {
998
+ type: "UNBOUND_TRANSACTION",
999
+ protocolVersion: recipe.protocolVersion,
1000
+ baseTransaction: signedBaseTx,
1001
+ balancingTransaction: signedBalancingTx,
1002
+ ...recipe.blockData ? { blockData: recipe.blockData } : {}
1003
+ };
1004
+ }
1005
+ case "UNPROVEN_TRANSACTION": {
1006
+ const signedTx = await this.signUnprovenTransaction(recipe.transaction, signSegment);
1007
+ const withDustSig = await this.#signDustRegistrationIfPresent(signedTx, signSegment);
1008
+ return {
1009
+ type: "UNPROVEN_TRANSACTION",
1010
+ protocolVersion: recipe.protocolVersion,
1011
+ transaction: withDustSig,
1012
+ ...recipe.blockData ? { blockData: recipe.blockData } : {}
1013
+ };
1014
+ }
1015
+ }
1016
+ }
1017
+ async #signDustRegistrationIfPresent(tx, signSegment) {
1018
+ const intent = this.accept(tx).intents?.get(1);
1019
+ const registrations = intent?.dustActions?.registrations ?? [];
1020
+ if (!intent || registrations.length === 0) return tx;
1021
+ const signature = await signSegment(intent.signatureData(1));
1022
+ return await this.dust.addDustRegistrationSignature(tx, signature);
1023
+ }
1024
+ async signUnprovenTransaction(tx, signSegment) {
1025
+ return await this.unshielded.signUnprovenTransaction(tx, signSegment);
1026
+ }
1027
+ async signUnboundTransaction(tx, signSegment) {
1028
+ return await this.unshielded.signUnboundTransaction(tx, signSegment);
1029
+ }
1030
+ /**
1031
+ * Proves and binds an unproven transaction, and records it as pending.
1032
+ *
1033
+ * @remarks
1034
+ * Proved at the version stamped on the transaction itself, which is the version that fixed its bytes, and sealed at
1035
+ * that same version: proving is a long await, so the wallets can move under it, and neither the prover a
1036
+ * transaction is routed to nor the stamp it comes back with may be decided by where they have moved to.
1037
+ *
1038
+ * Where they have moved to decides one thing only, and it is decided again once the proof is back: a crossing while
1039
+ * the transaction was in flight leaves it belonging to an epoch the wallets have left, and no chain they are on can
1040
+ * include it. Such a transaction is refused rather than sealed, and nothing is recorded as pending for it — a
1041
+ * pending entry would only wait out a TTL for an inclusion that cannot happen — while the reservations it made in
1042
+ * the three wallets are given back like those of any other failure here.
1043
+ * @param tx The unproven transaction.
1044
+ * @returns The finalized transaction, stamped with the version it was authored at.
1045
+ * @throws {@link ProtocolVersionMismatchError} When the wallets left the transaction's epoch while it was being
1046
+ * proved, or were never in it.
1047
+ */
1048
+ async finalizeTransaction(tx) {
1049
+ try {
1050
+ const unboundTx = await this.provingService.prove(this.accept(tx), tx.protocolVersion);
1051
+ this.accept(tx);
1052
+ const finalizedTx = this.seal("Finalized", unboundTx.bind(), tx.protocolVersion);
1053
+ await this.pendingTransactionsService.addPendingTransaction(finalizedTx, require_dist.some(finalizedTx.protocolVersion));
1054
+ return finalizedTx;
1055
+ } catch (error) {
1056
+ await Promise.allSettled([
1057
+ this.shielded.revertTransaction(tx),
1058
+ this.unshielded.revertTransaction(tx),
1059
+ this.dust.revertTransaction(tx)
1060
+ ]);
1061
+ throw error;
1062
+ }
1063
+ }
1064
+ /** Estimates the fee for the given transaction only. This lacks the fees of the balancing transaction. */
1065
+ async calculateTransactionFee(tx) {
1066
+ return await this.dust.calculateFee([tx]);
1067
+ }
1068
+ /** Calculates the total fee for the given transaction plus the fee of the balancing transaction. */
1069
+ async estimateTransactionFee(tx, options) {
1070
+ const ttl = options?.ttl ?? this.defaultTtl();
1071
+ return await this.dust.estimateFee([tx], ttl, options?.currentTime);
1072
+ }
1073
+ async transferTransaction(outputs, options) {
1074
+ const { ttl, payFees = true } = options;
1075
+ const unshieldedOutputs = outputs.filter((output) => output.type === "unshielded").flatMap((output) => output.outputs);
1076
+ const shieldedOutputs = outputs.filter((output) => output.type === "shielded").flatMap((output) => output.outputs);
1077
+ if (unshieldedOutputs.length === 0 && shieldedOutputs.length === 0) throw Error("At least one shielded or unshielded output is required.");
1078
+ const shieldedTx = shieldedOutputs.length > 0 ? await this.shielded.transferTransaction(shieldedOutputs) : void 0;
1079
+ const unshieldedTx = unshieldedOutputs.length > 0 ? await this.unshielded.transferTransaction(unshieldedOutputs, ttl) : void 0;
1080
+ const mergedTxs = this.mergeUnprovenTransactions(shieldedTx, unshieldedTx);
1081
+ const dustResult = payFees ? await this.dust.balanceTransactions([mergedTxs], ttl) : void 0;
1082
+ const feeBalancingTx = dustResult?.transaction;
1083
+ const finalTx = this.mergeUnprovenTransactions(mergedTxs, feeBalancingTx);
1084
+ return {
1085
+ type: "UNPROVEN_TRANSACTION",
1086
+ protocolVersion: this.currentVersion(),
1087
+ transaction: finalTx,
1088
+ ...dustResult ? { blockData: dustResult.blockData } : {}
1089
+ };
1090
+ }
1091
+ /**
1092
+ * Provides estimate of the fee of issuing registration transaction with provided UTxOs
1093
+ *
1094
+ * @param nightUtxos - Night UTxOs to use for the registration
1095
+ * @returns And object informing about fee at the moment, as well as estimation of dust generation of the UTxO(s),
1096
+ * that would be used for paying the fee. These include data that allows to compute when the fee could be paid
1097
+ */
1098
+ async estimateRegistration(nightUtxos) {
1099
+ const now = this.clock.now();
1100
+ const dustState = await this.dust.waitForSyncedState();
1101
+ const dustGenerationEstimations = require_dist.pipe(nightUtxos, require_dist.map$3(({ utxo, meta }) => ({
1102
+ ...utxo,
1103
+ ctime: meta.ctime,
1104
+ registeredForDustGeneration: meta.registeredForDustGeneration
1105
+ })), (utxosWithMeta) => dustState.estimateDustGeneration(utxosWithMeta, now), (estimatedUtxos) => dustState.splitNightUtxos(estimatedUtxos), (split) => split.guaranteed);
1106
+ const authoring = this.authoring();
1107
+ const fakeSigningKey = authoring.sampleSigningKey();
1108
+ const fakeVerifyingKey = authoring.signatureVerifyingKey(fakeSigningKey);
1109
+ const ttl = this.defaultTtl();
1110
+ const fakeUnsignedTx = await this.dust.createDustGenerationTransaction(void 0, ttl, nightUtxos.map(({ utxo, meta }) => ({
1111
+ ...utxo,
1112
+ ctime: meta.ctime,
1113
+ registeredForDustGeneration: meta.registeredForDustGeneration
1114
+ })), fakeVerifyingKey, dustState.address);
1115
+ const intent = this.accept(fakeUnsignedTx).intents?.get(1);
1116
+ if (!intent) throw Error("Dust generation transaction is missing intent segment 1.");
1117
+ const signature = authoring.signData(fakeSigningKey, intent.signatureData(1));
1118
+ const fakeSignedTx = await this.dust.addDustGenerationSignature(fakeUnsignedTx, signature);
1119
+ const finalizedFakeTx = this.seal("Finalized", this.accept(fakeSignedTx).mockProve().bind(), this.currentVersion());
1120
+ return {
1121
+ fee: await this.calculateTransactionFee(finalizedFakeTx),
1122
+ dustGenerationEstimations
1123
+ };
1124
+ }
1125
+ async initSwap(desiredInputs, desiredOutputs, options) {
1126
+ const { ttl, payFees = false } = options;
1127
+ const { shielded: shieldedInputs, unshielded: unshieldedInputs } = desiredInputs;
1128
+ const shieldedOutputs = desiredOutputs.filter((output) => output.type === "shielded").flatMap((output) => output.outputs);
1129
+ const unshieldedOutputs = desiredOutputs.filter((output) => output.type === "unshielded").flatMap((output) => output.outputs);
1130
+ const hasShieldedPart = shieldedInputs && Object.keys(shieldedInputs).length > 0 || shieldedOutputs.length > 0;
1131
+ const hasUnshieldedPart = unshieldedInputs && Object.keys(unshieldedInputs).length > 0 || unshieldedOutputs.length > 0;
1132
+ if (!hasShieldedPart && !hasUnshieldedPart) throw Error("At least one shielded or unshielded swap is required.");
1133
+ const shieldedTx = hasShieldedPart ? await this.shielded.initSwap(shieldedInputs ?? {}, shieldedOutputs) : void 0;
1134
+ const unshieldedTx = hasUnshieldedPart ? await this.unshielded.initSwap(unshieldedInputs ?? {}, unshieldedOutputs, ttl) : void 0;
1135
+ const combinedTx = this.mergeUnprovenTransactions(shieldedTx, unshieldedTx);
1136
+ if (!combinedTx) throw Error("Unexpected transaction state.");
1137
+ const dustResult = payFees ? await this.dust.balanceTransactions([combinedTx], ttl) : void 0;
1138
+ const feeBalancingTx = dustResult?.transaction;
1139
+ const finalTx = this.mergeUnprovenTransactions(combinedTx, feeBalancingTx);
1140
+ return {
1141
+ type: "UNPROVEN_TRANSACTION",
1142
+ protocolVersion: this.currentVersion(),
1143
+ transaction: finalTx,
1144
+ ...dustResult ? { blockData: dustResult.blockData } : {}
1145
+ };
1146
+ }
1147
+ async registerNightUtxosForDustGeneration(nightUtxos, nightVerifyingKey, signDustRegistration, dustReceiverAddress) {
1148
+ if (nightUtxos.length === 0) throw Error("At least one Night UTXO is required.");
1149
+ const receiverAddress = dustReceiverAddress ?? await this.dust.getAddress();
1150
+ const dustRegistrationTx = await this.createDustActionTransaction({
1151
+ type: "registration",
1152
+ dustReceiverAddress: receiverAddress
1153
+ }, nightUtxos, nightVerifyingKey, signDustRegistration);
1154
+ return {
1155
+ type: "UNPROVEN_TRANSACTION",
1156
+ protocolVersion: this.currentVersion(),
1157
+ transaction: dustRegistrationTx
1158
+ };
1159
+ }
1160
+ /**
1161
+ * Waits until the dust projected to be generated by the given Night UTxOs reaches `requiredAmount`, re-checking every
1162
+ * second. Pair with {@link estimateRegistration} to pick `requiredAmount`, then call before
1163
+ * {@link registerNightUtxosForDustGeneration} so the registration covers its own fee.
1164
+ *
1165
+ * @param nightUtxos - Night UTxOs to project generation for; the same set passed to the registration.
1166
+ * @param requiredAmount - Dust threshold to wait for. Resolves immediately if `<= 0n`.
1167
+ * @param opts.timeoutMs - Deadline, in ms, for the threshold to be reached. Rejects otherwise. Default `300_000`.
1168
+ * @throws If `nightUtxos` is empty, or if `requiredAmount` is not reached within `opts.timeoutMs`.
1169
+ */
1170
+ async waitForGeneratedDust(nightUtxos, requiredAmount, opts) {
1171
+ await this.dust.waitForGeneratedDust(nightUtxos.map(({ utxo, meta }) => ({
1172
+ ...utxo,
1173
+ ctime: meta.ctime,
1174
+ registeredForDustGeneration: meta.registeredForDustGeneration
1175
+ })), requiredAmount, this.clock, opts);
1176
+ }
1177
+ async deregisterFromDustGeneration(nightUtxos, nightVerifyingKey, signDustRegistration) {
1178
+ const dustDeregistrationTx = await this.createDustActionTransaction({ type: "deregistration" }, nightUtxos, nightVerifyingKey, signDustRegistration);
1179
+ return {
1180
+ type: "UNPROVEN_TRANSACTION",
1181
+ protocolVersion: this.currentVersion(),
1182
+ transaction: dustDeregistrationTx
1183
+ };
1184
+ }
1185
+ async revert(txOrRecipe, reason) {
1186
+ const transactionsToRevert = BalancingRecipe.isRecipe(txOrRecipe) ? BalancingRecipe.getTransactions(txOrRecipe) : [txOrRecipe];
1187
+ await Promise.all(transactionsToRevert.map((tx) => this.revertTransaction(tx, reason)));
1188
+ }
1189
+ /**
1190
+ * The finalized entry recording `tx`, if sync has written one, even under the hash aggregation gave it on-chain. A
1191
+ * transaction whose stamp no epoch can read has no entry, rather than an error, so a verdict on it still resolves.
1192
+ */
1193
+ finalizedEntryFor(tx, history) {
1194
+ return require_dist.match$1(require_dist.getRight(require_dist.WalletTransaction.unwrapWithin(tx, this.epochOf(tx.protocolVersion))), {
1195
+ onNone: () => void 0,
1196
+ onSome: (carried) => {
1197
+ const key = submitTxHistoryKey(carried);
1198
+ return history.find((entry) => isFinalizedWalletEntry(entry) && require_dist.coversTransaction(entry, key));
1199
+ }
1200
+ });
1201
+ }
1202
+ /** Sync can record inclusion before the independent pending-status poller observes it. */
1203
+ async reconcileFinalizedTransaction(tx, history) {
1204
+ const entry = this.finalizedEntryFor(tx, history);
1205
+ if (entry === void 0) return false;
1206
+ if (entry.status === "FAILURE" || entry.status === "PARTIAL_SUCCESS") await this.revertTransaction(tx);
1207
+ else await this.pendingTransactionsService.clear(tx);
1208
+ return true;
1209
+ }
1210
+ async revertTransaction(tx, reason) {
1211
+ await Promise.all([
1212
+ this.shielded.revertTransaction(tx),
1213
+ this.unshielded.revertTransaction(tx),
1214
+ this.dust.revertTransaction(tx)
1215
+ ]).then(async () => {
1216
+ await this.pendingTransactionsService.clear(tx);
1217
+ const key = require_dist.match$1(require_dist.getRight(require_dist.WalletTransaction.unwrapWithin(tx, this.epochOf(tx.protocolVersion))), {
1218
+ onNone: () => void 0,
1219
+ onSome: revertTxHistoryKey
1220
+ });
1221
+ if (key !== void 0) await this.#txHistoryStorage.gotRejected({
1222
+ ...key,
1223
+ rejectedAt: this.clock.now(),
1224
+ ...reason !== void 0 ? { reason } : {}
1225
+ });
1226
+ });
1227
+ }
1228
+ /**
1229
+ * Starts the wallets and their background synchronization.
1230
+ *
1231
+ * @remarks
1232
+ * Seeds, not key objects. A seed is the only key material that crosses a protocol boundary — every ledger version
1233
+ * derives its own keys from the same seed and arrives at the same identity — so a wallet started from seeds can
1234
+ * follow the chain across a fork, and one started from key objects of a single ledger version cannot. Derive them
1235
+ * once with `WalletSeeds.fromMasterSeed` and hand them over.
1236
+ *
1237
+ * {@link FacadeKeysByEpoch} is the escape hatch for a caller that will not part with a seed. It requires **both**
1238
+ * ledger versions' key objects, because a wallet holding one side could not read the other side of the chain, and
1239
+ * it costs the caller an import of both ledger packages and the same derivation performed twice. A seed costs
1240
+ * neither.
1241
+ * @example
1242
+ * ```typescript
1243
+ * await facade.start(WalletSeeds.fromMasterSeed(masterSeed));
1244
+ * ```;
1245
+ *
1246
+ * @param material The three wallets' seeds, or both ledger versions' key objects.
1247
+ * @param options `manualSync` leaves the dust wallet unstarted in the background; drive it explicitly with
1248
+ * {@link doSync} instead (requires a dust wallet built with the projections sync service, see
1249
+ * `makeEventLessSyncService`).
1250
+ */
1251
+ async start(material, options = {}) {
1252
+ const keys = v9KeysOf(material);
1253
+ await Promise.all([
1254
+ this.shielded.start(keys.shielded),
1255
+ this.unshielded.start(),
1256
+ !options.manualSync ? this.dust.start(keys.dust) : void 0,
1257
+ this.pendingTransactionsService.start()
1258
+ ]);
1259
+ }
1260
+ /**
1261
+ * Runs a single dust synchronization pass and resolves when it completes. Only the dust wallet supports manual sync;
1262
+ * the shielded and unshielded wallets keep syncing in the background via {@link start}.
1263
+ *
1264
+ * @param material The same material {@link start} was given.
1265
+ */
1266
+ async doSync(material) {
1267
+ await this.dust.stepSync(v9KeysOf(material).dust);
1268
+ }
1269
+ async stop() {
1270
+ await Promise.all([
1271
+ this.shielded.stop(),
1272
+ this.unshielded.stop(),
1273
+ this.dust.stop(),
1274
+ this.submissionService.close(),
1275
+ this.pendingTransactionsService.stop(),
1276
+ Promise.resolve(this.#pendingSubscription?.unsubscribe()),
1277
+ Promise.resolve(this.#protocolVersionSubscription?.unsubscribe())
1278
+ ]);
1279
+ }
1280
+ async queryTxHistoryByHash(hash) {
1281
+ return this.#txHistoryStorage.get(hash);
1282
+ }
1283
+ async getAllFromTxHistory() {
1284
+ return [...await this.#txHistoryStorage.getAll()];
1285
+ }
1286
+ };
1287
+ //#endregion
1288
+ exports.BalancingRecipe = BalancingRecipe;
1289
+ Object.defineProperty(exports, "Clock", {
1290
+ enumerable: true,
1291
+ get: function() {
1292
+ return require_dist.Clock_exports;
1293
+ }
1294
+ });
1295
+ exports.DefaultForkSchedule = DefaultForkSchedule;
1296
+ exports.FacadeState = FacadeState;
1297
+ exports.ValidationFetchError = require_dist.ValidationFetchError;
1298
+ exports.WalletEntrySchema = WalletEntrySchema;
1299
+ exports.WalletFacade = WalletFacade;
1300
+ exports.WellFormedError = require_dist.WellFormedError;
1301
+ exports.isFinalizedWalletEntry = isFinalizedWalletEntry;
1302
+ exports.isPendingWalletEntry = isPendingWalletEntry;
1303
+ exports.lowestProtocolVersion = lowestProtocolVersion;
1304
+ exports.mergeWalletEntries = mergeWalletEntries;
1305
+ exports.pendingTransactionsOf = pendingTransactionsOf;
1306
+ exports.protocolPhaseOf = protocolPhaseOf;