@laceio/sdk 0.1.1 → 0.1.2-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{TransactionBuilder-DrB3NVTi.cjs → TransactionBuilder-X1H9Gze6.cjs} +64 -14
- package/dist/{TransactionBuilder-V6aLx4SV.js → TransactionBuilder-bp2aMDhg.js} +23 -15
- package/dist/{_polyfill-buffer-patch-BnPVerlG.cjs → _polyfill-buffer-patch-CM8X7JiY.cjs} +21 -2
- package/dist/_polyfill-buffer-patch-yNxN4d5E.js +1467 -0
- package/dist/_web-crypto-random-bytes-Bo-GTcRS.js +197 -0
- package/dist/acc-module-4iIUv6My.cjs +27654 -0
- package/dist/acc-module-Cmj8EsIb.js +27624 -0
- package/dist/account-BOQruszJ.js +6 -0
- package/dist/account-BUOj4pYJ.cjs +11 -0
- package/dist/account-call-7wnopBq0.cjs +5 -0
- package/dist/account-call-B9d_2Xwi.js +4 -0
- package/dist/account-call-Bd4Rpbvt.cjs +323 -0
- package/dist/account-call-C3CkDqEC.js +276 -0
- package/dist/account-guards-BtjTGxDZ.cjs +42 -0
- package/dist/account-guards-D9Lu5T3W.js +36 -0
- package/dist/account-tokens-DvkOFVON.js +16 -0
- package/dist/account-tokens-nwcvwLu4.cjs +21 -0
- package/dist/{activity-type.stable-BJEfeLxL.cjs → activity-type-Ch6ljxBy.cjs} +2 -1
- package/dist/{activity-type.stable-C76_hWd7.js → activity-type-GsJGWs-3.js} +2 -1
- package/dist/address-B9ntKL8K.js +13761 -0
- package/dist/address-BXp-mY8H.cjs +11270 -0
- package/dist/{address-book-address-validator-DIUolI-s.js → address-book-address-validator-0J9XAADH.js} +2 -2
- package/dist/address-book-address-validator-DK0dnsRS.cjs +41 -0
- package/dist/address-book-address-validator-Di_ywo8M.js +39 -0
- package/dist/{address-book-address-validator-DNwQGlOB.cjs → address-book-address-validator-Dte_YQ2L.cjs} +2 -2
- package/dist/artefact-loader-BWWYAD7E.cjs +183 -0
- package/dist/artefact-loader-Dik4HIfv.js +160 -0
- package/dist/auto-dismiss-failure-on-success-C-qoJuid.cjs +37 -0
- package/dist/auto-dismiss-failure-on-success-s8MGDEIu.js +31 -0
- package/dist/bip32-D6wd_QMn.cjs +3851 -0
- package/dist/bitcoin-data-provider-BYPSmuZS.js +21 -0
- package/dist/bitcoin-data-provider-w1oEDSU3.cjs +26 -0
- package/dist/bitcoin.cjs +45 -0
- package/dist/bitcoin.d.ts +29906 -1
- package/dist/bitcoin.js +20 -0
- package/dist/{blockfrost-tx-submit-provider-DPTrapz-.js → blockfrost-tx-submit-provider-CBWQ0wK9.js} +5 -157
- package/dist/{blockfrost-tx-submit-provider-BAIzV5o3.cjs → blockfrost-tx-submit-provider-CLNQ5ycR.cjs} +3 -167
- package/dist/bn-d3nSOIf7.cjs +2553 -0
- package/dist/browser-B1eMbDwh.js +7468 -0
- package/dist/bytes.vo-BB7_4JK6.js +23 -0
- package/dist/bytes.vo-BNRquqaO.cjs +34 -0
- package/dist/cardano-DfPwhwm-.js +3 -0
- package/dist/{cardano-network-id.vo-DSxrFk9S.cjs → cardano-network-id.vo-BEDPn6Li.cjs} +1 -1
- package/dist/{cardano-network-id.vo-CK1tNQDg.js → cardano-network-id.vo-Cfpvbod9.js} +1 -1
- package/dist/cardano.cjs +22 -18
- package/dist/cardano.d.ts +16962 -1716
- package/dist/cardano.js +16 -11
- package/dist/client-DXBLHk7K.cjs +808 -0
- package/dist/codecs-Cswkg7Tm.cjs +4051 -0
- package/dist/codecs-Dc1Krpbt.js +3903 -0
- package/dist/{const-C84qHkjp.js → const-BJfIK_G-.js} +4 -4
- package/dist/const-BhYOdznB.cjs +42 -0
- package/dist/const-BsnjG2_Q.cjs +32071 -0
- package/dist/const-CUnCl5U0.js +13 -0
- package/dist/{const-DXk2tFyv.js → const-CjmfjBP3.js} +1 -1
- package/dist/{const-BDEg2Trq.cjs → const-D-eZIS4n.cjs} +4 -4
- package/dist/const-D0CbQlo4.js +154 -0
- package/dist/{const-BY8B3_0_.cjs → const-iwzZEE_w.cjs} +1 -1
- package/dist/contract-1R86jhSw.js +171 -0
- package/dist/contract-MKLzYVkW.cjs +189 -0
- package/dist/create-add-accounts-Brqk84vF.js +102 -0
- package/dist/create-add-accounts-DzXIh7Ot.cjs +114 -0
- package/dist/{delegation-tx-builder-CRpLP6jH.cjs → delegation-tx-builder-Dof_0N_d.cjs} +6 -6
- package/dist/{delegation-tx-builder-CGVqlaFE.js → delegation-tx-builder-Dy3-2Auz.js} +5 -5
- package/dist/{deregistration-tx-builder-DZGwB4cz.cjs → deregistration-tx-builder-CcLwyFpj.cjs} +6 -6
- package/dist/{deregistration-tx-builder-B-CrUyX6.js → deregistration-tx-builder-QkWW_gWl.js} +5 -5
- package/dist/device-commitment-hex.vo-5wFtQvDS.js +26 -0
- package/dist/device-commitment-hex.vo-CT3RmAug.cjs +31 -0
- package/dist/device-readers-CUHYoYOH.js +145 -0
- package/dist/device-readers-CdxS2btd.cjs +168 -0
- package/dist/device-readers-D_JZeNL2.cjs +8 -0
- package/dist/device-readers-DwSNCGPP.js +4 -0
- package/dist/dist-BMi5ZjEq.cjs +43175 -0
- package/dist/dist-BtIq4XFn.cjs +535 -0
- package/dist/dist-C3SHC_Ho.cjs +1394 -0
- package/dist/dist-CykEjYEX.cjs +3814 -0
- package/dist/dist-Dcsxh3be.cjs +3452 -0
- package/dist/dist-DqJfSlTd.cjs +4413 -0
- package/dist/dist-nTZ70qj7.cjs +1306 -0
- package/dist/{earn-rewards-tx-builder-D5sUT5v8.cjs → earn-rewards-tx-builder-BP5JMIKS.cjs} +6 -6
- package/dist/{earn-rewards-tx-builder-BDbTDZmD.js → earn-rewards-tx-builder-Cku4BmNU.js} +5 -5
- package/dist/enc-key-circuits-B7BjgUL9.js +13 -0
- package/dist/enc-key-circuits-BLrZrBVI.cjs +24 -0
- package/dist/english-Byb9M0E_.cjs +2057 -0
- package/dist/envelopes-BGoO_v8m.js +1621 -0
- package/dist/envelopes-CH25R-DN.cjs +1722 -0
- package/dist/errors-BIftM8ZN.cjs +688 -0
- package/dist/errors-DSq5wUwt.js +466 -0
- package/dist/esm-HBSUQw3w.js +384 -0
- package/dist/esm-LZuaZjMf.cjs +389 -0
- package/dist/experimental.cjs +7349 -0
- package/dist/experimental.d.ts +86279 -0
- package/dist/experimental.js +7184 -0
- package/dist/gated-call-CDCVZIK-.cjs +5 -0
- package/dist/gated-call-D-tT7P_t.js +722 -0
- package/dist/gated-call-D_VT2quk.js +4 -0
- package/dist/gated-call-DgJm1Mi_.cjs +787 -0
- package/dist/grant-circuits-DswmW3nI.cjs +71 -0
- package/dist/grant-circuits-Jxb5y1HW.js +42 -0
- package/dist/grant-rules-By07_eDi.js +6824 -0
- package/dist/grant-rules-BzVTWXS7.cjs +7099 -0
- package/dist/grant-spend-B3Md9L0n.js +215 -0
- package/dist/grant-spend-oWmzRsjH.cjs +217 -0
- package/dist/grant-status-B2y49iIu.js +2688 -0
- package/dist/grant-status-DOr3t_u8.cjs +2820 -0
- package/dist/grants-2BZ-qEVQ.js +5 -0
- package/dist/grants-BPoLSiMt.cjs +18 -0
- package/dist/grants-BoI5uwSF.cjs +272 -0
- package/dist/grants-CtofFu-e.js +213 -0
- package/dist/{group-cardano-addresses-by-account-B533oVXR.cjs → group-cardano-addresses-by-account-Bp0g4wEY.cjs} +3 -39
- package/dist/{group-cardano-addresses-by-account-RHKoEskR.js → group-cardano-addresses-by-account-SR8MMrZf.js} +5 -35
- package/dist/{guarded-transaction-signer-Bxl6_XNd.cjs → guarded-transaction-signer-MFpPg98D.cjs} +17 -18
- package/dist/{guarded-transaction-signer-CpKLj8Kp.js → guarded-transaction-signer-P6Rp1faj.js} +8 -15
- package/dist/hex-D9ITYbwt.cjs +263 -0
- package/dist/hex-mkXcV3pN.js +191 -0
- package/dist/http-client-B3N-TMxu.cjs +167 -0
- package/dist/http-client-TRlhDZGh.js +155 -0
- package/dist/identity-BMLuufva.cjs +263 -0
- package/dist/identity-DII6f-h7.js +233 -0
- package/dist/in-memory-wallet-integration-B2xzxORj.cjs +20741 -0
- package/dist/in-memory-wallet-integration-CBRiPjLO.js +130 -0
- package/dist/in-memory-wallet-integration-CULUB5Tf.cjs +240 -0
- package/dist/{in-memory-wallet-integration-D-qn65Kx.js → in-memory-wallet-integration-ChIOirMW.js} +5 -2
- package/dist/{in-memory-wallet-integration-Croiuopx.js → in-memory-wallet-integration-CljprQQV.js} +7 -104
- package/dist/{in-memory-wallet-integration-DVh9sRXa.cjs → in-memory-wallet-integration-Cm6P8sk6.cjs} +3 -2
- package/dist/in-memory-wallet-integration-TM9bBphA.js +20738 -0
- package/dist/{in-memory-wallet-integration-CnLYeX4-.cjs → in-memory-wallet-integration-t9I00R_V.cjs} +17 -108
- package/dist/index.cjs +84 -47
- package/dist/index.d.ts +37505 -10036
- package/dist/index.js +52 -24
- package/dist/{init-CLHuAMB-.js → init-0zzs9aqU.js} +4 -4
- package/dist/{init-U8c9yHYx.cjs → init-5KcGcBb5.cjs} +1 -1
- package/dist/{init-CigestoM.js → init-B3-1ghyx.js} +2 -2
- package/dist/init-B8U3ABhS.cjs +107 -0
- package/dist/init-BJn-8_hf.js +141 -0
- package/dist/init-BPU3j8sT.cjs +6 -0
- package/dist/init-BRzH6xu-2.cjs +2797 -0
- package/dist/init-BmzfDaKL.js +1142 -0
- package/dist/{init-C-jErzp5.cjs → init-BopV9ed4.cjs} +2 -2
- package/dist/init-BpHTq2R5.js +105 -0
- package/dist/init-BpSITBfF.js +39 -0
- package/dist/{init-DX4WyB0R.cjs → init-BrdVzxei.cjs} +3 -3
- package/dist/{init-LfyMo-sS.cjs → init-BwkU0ruo.cjs} +2 -2
- package/dist/{init-CB__aLD7.cjs → init-C-G32J12.cjs} +2 -2
- package/dist/init-C00gw1zi.js +422 -0
- package/dist/{init-TkPq_Ny_.js → init-C2RgrfZe.js} +1 -1
- package/dist/init-C5mYyFTv.js +3584 -0
- package/dist/{init-DcYY6zMD.js → init-C8URA2OX.js} +1 -1
- package/dist/init-CDkRynJa.js +2796 -0
- package/dist/{init-Cg9XdAru.js → init-CNM5m7M2.js} +4 -4
- package/dist/init-CR7BfztQ.cjs +18 -0
- package/dist/{init-CSHwHnfg.cjs → init-CSDpdu0Q.cjs} +2 -2
- package/dist/{init-aJHl-7AO.js → init-CX0AMQUn.js} +2 -2
- package/dist/{init-FMGDET-9.js → init-CfTbSEKy.js} +259 -60
- package/dist/{init-CR6tpw1B.js → init-Cigr_tKx.js} +47 -43
- package/dist/init-Clu8pxwQ.cjs +1181 -0
- package/dist/{init-CFYsq82V.js → init-CyAY4Lzl.js} +1 -1
- package/dist/{init-BKhH6mVR.cjs → init-D6BxBs7e.cjs} +1 -1
- package/dist/init-D8OeObDF.cjs +1141 -0
- package/dist/init-D9g1HXYf.cjs +40 -0
- package/dist/{init-CNLGJJRx.js → init-DA7zmptx.js} +1 -1
- package/dist/{init-DkIc5nqF.cjs → init-DFMiP2ZH.cjs} +1 -1
- package/dist/{init-zSzCjoor.js → init-DFjT8YvT.js} +4 -4
- package/dist/init-DGjXwWs2.cjs +143 -0
- package/dist/init-DHrCbpkW.cjs +121 -0
- package/dist/init-DRzJR02G.cjs +3585 -0
- package/dist/{init-B64zCLxG.cjs → init-DUF4ar8P.cjs} +4 -4
- package/dist/init-DlqJuHhl.js +119 -0
- package/dist/{init-y2Ra0vZP.js → init-Dnsv155v.js} +3 -3
- package/dist/init-DuYENxci.js +17 -0
- package/dist/{init-D6DBUsD3.cjs → init-Dv3zKj0r.cjs} +4 -4
- package/dist/{init-BtzMZ7Pk.cjs → init-Dy-05ktr.cjs} +1 -1
- package/dist/{init-BsCBAGWf.cjs → init-EP0CUWNK.cjs} +2 -2
- package/dist/{init-BJVU54pI.cjs → init-EhzD7a8i.cjs} +1 -1
- package/dist/{init-w9GEs73W.js → init-Fw89ZmrR.js} +2 -2
- package/dist/init-GsT2AEa4.cjs +424 -0
- package/dist/{init-Rxohwpmu.js → init-NCjgwCZy.js} +2 -2
- package/dist/{init-DxUHsN53.cjs → init-NdhG_VrF.cjs} +6 -6
- package/dist/{init-DDdhguVC.js → init-SZ01tARX2.js} +2 -2
- package/dist/{init-BAJJzBza.js → init-Y3mkB4XS.js} +2 -2
- package/dist/init-c4l6r-o-.js +5 -0
- package/dist/{init-Dku4b2lG.js → init-kEfUTuG2.js} +1 -1
- package/dist/{init-C7IeJwQR.cjs → init-lzHt4Cli.cjs} +256 -59
- package/dist/init-qSEd_Spq.js +1182 -0
- package/dist/{init-anYu6XB7.cjs → init-rmt7-fQE.cjs} +2 -2
- package/dist/{init-C4Bkib9u.cjs → init-zU-_9Gsp.cjs} +67 -65
- package/dist/{is-retriable-error-BU0e3hVI.js → is-retriable-error-BUiVJDwH.js} +1 -1
- package/dist/{is-retriable-error-CeeuHqDa.cjs → is-retriable-error-Dpt860if.cjs} +1 -1
- package/dist/jubjub-authoriser-D7zDXu3V.js +86 -0
- package/dist/jubjub-authoriser-Dgu6o3Sv.cjs +87 -0
- package/dist/key-source-5oUBFiC7.cjs +583 -0
- package/dist/key-source-B08HukZg.js +2550 -0
- package/dist/keyDerivation-D3k9XyHg.js +4077 -0
- package/dist/keyDerivation-u0nBA93T.cjs +274 -0
- package/dist/{lace-context-CZcNHr4M.js → lace-context-BZciB9c7.js} +4 -4
- package/dist/{lace-context-fJTDghdp.cjs → lace-context-DgR6vLli.cjs} +4 -4
- package/dist/lib--iqvW4O_.js +2354 -0
- package/dist/lib-Yk6Upl5D.cjs +2359 -0
- package/dist/{libsodium-wrappers-UH0LaOUE.js → libsodium-wrappers-BhbOA8dQ.js} +3 -1647
- package/dist/midnight-account-id.vo-0x9X-r3l.cjs +10 -0
- package/dist/midnight-account-id.vo-DjCAGcqc.js +5 -0
- package/dist/midnight-engine-DpemplKO.js +5 -0
- package/dist/midnight-engine-xU1wotne.cjs +6 -0
- package/dist/midnight-wallet-DIsAlSn6.js +18 -0
- package/dist/midnight-wallet-XTZc2li7.cjs +24 -0
- package/dist/midnight.cjs +1408 -0
- package/dist/midnight.d.ts +28934 -0
- package/dist/midnight.js +1352 -0
- package/dist/modules-cardano-D9Gs2j60.cjs +1108 -0
- package/dist/modules-cardano-VIM8fKu-.js +995 -0
- package/dist/node-relay-DWe1U0w2.cjs +49 -0
- package/dist/node-relay-h4i5IlAQ.js +48 -0
- package/dist/outputs-Bd2yZVjx.js +720 -0
- package/dist/outputs-CJoQBIA2.cjs +990 -0
- package/dist/pbkdf2-CIW-oWrm.cjs +1337 -0
- package/dist/pending-operation-B0_P78Jo.cjs +26 -0
- package/dist/pending-operation-BIS6mpjB.js +21 -0
- package/dist/providers-FjhM47BH.cjs +388 -0
- package/dist/providers-WtiSuxFu.js +365 -0
- package/dist/redacted-BmE2aXqr.js +81 -0
- package/dist/redacted-CRZJLS3w.cjs +86 -0
- package/dist/{retry-config-DC5IMaH7.cjs → retry-config-BaCfVC1H.cjs} +1 -1
- package/dist/{retry-config-BcUmMS--.js → retry-config-Dmgt28wM.js} +1 -1
- package/dist/safe-buffer-B_vMqJWU.js +43 -0
- package/dist/safe-buffer-DYOwEfHB.cjs +48 -0
- package/dist/sdk-Cb-gZnS9.js +1241 -0
- package/dist/sdk-DffwmX8b.cjs +1439 -0
- package/dist/sdk-init-Bln9rFtn.js +4138 -0
- package/dist/sdk-init-CYViTJY_.cjs +3841 -0
- package/dist/{seam-cardano-CATqBEyK.js → seam-cardano-B_etH4F4.js} +1 -1
- package/dist/{bytes.vo-TgiwogWF.js → secret-box-DUR0ACYz.js} +3 -25
- package/dist/{bytes.vo-Ck5u40RA.cjs → secret-box-DrjLZuS1.cjs} +1 -35
- package/dist/send-proof-progress-C-ljq1x5.js +30 -0
- package/dist/send-proof-progress-vmsaSfbz.cjs +47 -0
- package/dist/side-effects-BnqYz7Nl.js +768 -0
- package/dist/side-effects-CngaeXi0.cjs +804 -0
- package/dist/sign-bitcoin-transaction-with-seed-D4z62-jV.js +147 -0
- package/dist/sign-bitcoin-transaction-with-seed-DsLYXnCY.cjs +158 -0
- package/dist/signer-3fk8lZtE.cjs +7 -0
- package/dist/signer-CsL28DrK.cjs +121 -0
- package/dist/signer-DGluibtn.js +92 -0
- package/dist/signer-RqB5pu3K.js +2 -0
- package/dist/signer-factory-BA7WFJVZ.js +282 -0
- package/dist/signer-factory-Cwd6o-lG.cjs +281 -0
- package/dist/{signer-factory-9URFliA5.js → signer-factory-DObB55D4.js} +6 -3
- package/dist/signer-factory-DhZiE03y.cjs +149 -0
- package/dist/{signer-factory-BWGUmnvm.cjs → signer-factory-Ds6G2AZk.cjs} +4 -3
- package/dist/signer-factory-hzSRaIw2.js +148 -0
- package/dist/{slice-CuHUaPZx.cjs → slice-7G2xxYKJ.cjs} +3 -3
- package/dist/{slice-DZmQJNV8.cjs → slice-B4CdYoPu.cjs} +2 -2
- package/dist/slice-BPNuHKfw.js +9091 -0
- package/dist/{slice-DGcNrbPR.cjs → slice-Bg6HEr3K.cjs} +4 -4
- package/dist/{slice-DtaO72qY.cjs → slice-Bs2aMERu.cjs} +3 -3
- package/dist/{slice-HeHCv3bl.cjs → slice-C34iOOUH.cjs} +7 -7
- package/dist/{slice-Do2R2CYW.cjs → slice-C9TT5KhY.cjs} +6 -6
- package/dist/{slice-eIwcwKHI.js → slice-CK07EBCo.js} +4 -4
- package/dist/{slice-CnyWevM9.js → slice-CU80pbiu.js} +3 -3
- package/dist/{slice-CobanYgn.js → slice-CwyYrh1H.js} +2 -2
- package/dist/slice-Czfp6t84.cjs +436 -0
- package/dist/{slice-d0p6-xj5.js → slice-D-9aPKG-.js} +6 -6
- package/dist/{slice-maaskdUn.js → slice-DBpJ2QGf.js} +6 -6
- package/dist/{slice-mxLQ_FeY.cjs → slice-DTZTiJle.cjs} +352 -39
- package/dist/{slice-zJ9XVYjZ.js → slice-Da426sf9.js} +1 -1
- package/dist/{slice-D11m2EKl.cjs → slice-DayJvMRD.cjs} +1 -1
- package/dist/slice-DnBWfA-k.cjs +9109 -0
- package/dist/{slice-oqm_r1cS.cjs → slice-DnG-yvpI.cjs} +2 -2
- package/dist/{slice-BNu73oBa.js → slice-DyNs7oWp.js} +2 -2
- package/dist/{slice-CB4SnzMm.js → slice-GwiiJRoq.js} +3 -3
- package/dist/slice-oWnc7YVD.js +412 -0
- package/dist/{slice-B2PhoWAg.js → slice-qt0uBExh.js} +325 -37
- package/dist/slice-t8Gzj55G2.cjs +106 -0
- package/dist/slice-t8Q1cHm-.js +88 -0
- package/dist/src-BDzYIksE.cjs +20637 -0
- package/dist/src-BFoefPv_.js +20755 -0
- package/dist/store-B1Lq3cEf.cjs +66 -0
- package/dist/store-DuBG8qh5.js +37 -0
- package/dist/submit-Bs77dPn_.cjs +413 -0
- package/dist/submit-DOv8Z0Vf.js +336 -0
- package/dist/submit-bitcoin-tx-D6oYgH5S.js +983 -0
- package/dist/submit-bitcoin-tx-goFuRL7K.cjs +1049 -0
- package/dist/{sync-operation-utils-BYXLO80m.js → sync-operation-utils-31iFLExW.js} +2 -38
- package/dist/{sync-operation-utils-SdPbwFoD.cjs → sync-operation-utils-COIZ66-I.cjs} +1 -67
- package/dist/token-id-mapper-Bnds3xKH.cjs +18 -0
- package/dist/{token-id-mapper-DsPAL6Nh.cjs → token-id-mapper-CVyQJUKY.cjs} +2 -2
- package/dist/token-id-mapper-CnKHQ8DV.js +16 -0
- package/dist/{token-id-mapper-B2ivlLv3.js → token-id-mapper-D29Ggv8h.js} +2 -2
- package/dist/tokens-Cevp7rdU.cjs +62 -0
- package/dist/tokens-Diw4MLRM.js +44 -0
- package/dist/types-B8uiJn-X.js +12 -0
- package/dist/types-BHC12eSa.js +33 -0
- package/dist/types-CJT6XF2c.js +10 -0
- package/dist/types-CLRUYpfe.cjs +23 -0
- package/dist/types-Cc3mC8u0.cjs +50 -0
- package/dist/types-DWbVZpnF.cjs +15 -0
- package/dist/unwrap-provider-result-BZSiwabU.js +32 -0
- package/dist/unwrap-provider-result-ZqfBsTkk.cjs +39 -0
- package/dist/{util-CGzqQ8IV.cjs → util-Bu4W5lF4.cjs} +1 -1
- package/dist/{util-BaLzwa32.js → util-Cp5cZkfK.js} +1 -1
- package/dist/{utils-o8aMjfln.js → utils-BfBEUvWA.js} +2 -2
- package/dist/utils-DFwzEvbv.js +65 -0
- package/dist/{utils-5JvjbqH3.cjs → utils-DsElZgCI.cjs} +7 -1
- package/dist/utils-IXxR-Djh.cjs +112 -0
- package/dist/v8Signatures-CO_Uloy7.cjs +71 -0
- package/dist/{vote-delegation-tx-builder-CmKv6GoG.js → vote-delegation-tx-builder-BsBSDmcX.js} +5 -5
- package/dist/{vote-delegation-tx-builder-BpEMSti4.cjs → vote-delegation-tx-builder-DSs8nybk.cjs} +6 -6
- package/dist/watch-CUEvcP-V.js +21997 -0
- package/dist/watch-DMF2s-II.cjs +52281 -0
- package/package.json +96 -4
- package/dist/account-guards.stable-B1DSSh9D.cjs +0 -10
- package/dist/account-guards.stable-JRQ5qx2V.js +0 -5
- package/dist/codecs-B7X9pAsK.cjs +0 -1945
- package/dist/codecs-CC1Xjntz.js +0 -1882
- package/dist/init-Bv53hpLM.js +0 -19
- package/dist/init-CRbjI7p1.js +0 -3494
- package/dist/init-DAna1KCg.cjs +0 -3495
- package/dist/init-DGe47B22.cjs +0 -364
- package/dist/init-DMtyvYfC.cjs +0 -21
- package/dist/init-TkPDD750.js +0 -363
- package/dist/modules-cardano-BDvuL4Xx.js +0 -5248
- package/dist/modules-cardano-D2G3De2P.cjs +0 -5432
- package/dist/slice-CGVHXHDt.cjs +0 -125
- package/dist/slice-DhvF7L6X.js +0 -107
- /package/dist/{account-id.vo-LvCBVn5r.cjs → account-id.vo-DwqFjK5u.cjs} +0 -0
- /package/dist/{account-id.vo-MYSI7YFm.js → account-id.vo-OPz2v-JZ.js} +0 -0
- /package/dist/{actions-DdGbj7c7.cjs → actions-B2BJ4RTy.cjs} +0 -0
- /package/dist/{actions-9QSQR-GB.js → actions-iLXdgL5Y.js} +0 -0
- /package/dist/{apply-vkey-witnesses-ClZbpk5w.js → apply-vkey-witnesses-BKx3lcs0.js} +0 -0
- /package/dist/{apply-vkey-witnesses-CLzVSWxl.cjs → apply-vkey-witnesses-ZnFS0jnJ.cjs} +0 -0
- /package/dist/{asyncoption-Cw07zPH7.js → asyncoption-CruEYOBI.js} +0 -0
- /package/dist/{asyncoption-DYoGuQfP.cjs → asyncoption-i0VbqVTq.cjs} +0 -0
- /package/dist/{bignum.vo-B0rK_PQ1.js → bignum.vo-CEXOIew0.js} +0 -0
- /package/dist/{bignum.vo-DsG3kNiZ.cjs → bignum.vo-hx2kuqlA.cjs} +0 -0
- /package/dist/{bip32ed25519-1ApqeAZk.cjs → bip32ed25519-B7Yat217.cjs} +0 -0
- /package/dist/{bip32ed25519-DetAdGwD.js → bip32ed25519-FQ8qvdcq.js} +0 -0
- /package/dist/{blake2b-DOEVc57D.js → blake2b-BiQTw3GC.js} +0 -0
- /package/dist/{blake2b-B9tftbvG.cjs → blake2b-DEeVUdKR.cjs} +0 -0
- /package/dist/{blockchain-network-id.vo-BXpZhvvQ.cjs → blockchain-network-id.vo-BAKEwGjG.cjs} +0 -0
- /package/dist/{blockchain-network-id.vo-DNRkuT5B.js → blockchain-network-id.vo-CiVykuqG.js} +0 -0
- /package/dist/{blockingWithLatestFrom-C5wp_uA-.js → blockingWithLatestFrom-Cd8c8EPG.js} +0 -0
- /package/dist/{blockingWithLatestFrom-DY8OPg0w.cjs → blockingWithLatestFrom-D8kBPBMX.cjs} +0 -0
- /package/dist/{cardano-network-id-to-network-type-CrZfUcyP.js → cardano-network-id-to-network-type-BWwzeEtM.js} +0 -0
- /package/dist/{cardano-network-id-to-network-type-BDTF-HmK.cjs → cardano-network-id-to-network-type-C0ufJOyE.cjs} +0 -0
- /package/dist/{cardano-tx-id.vo-BPhV-AmZ.cjs → cardano-tx-id.vo-TLjJZHCI.cjs} +0 -0
- /package/dist/{cardano-tx-id.vo-DF9NzZXk.js → cardano-tx-id.vo-eVnKuzlm.js} +0 -0
- /package/dist/{composite-signer-factory-_46QsNBz.js → composite-signer-factory-CR8YHA1y.js} +0 -0
- /package/dist/{composite-signer-factory-BpF1mIYA.cjs → composite-signer-factory-m5cVs9h_.cjs} +0 -0
- /package/dist/{error-CNIquqT5.cjs → error-Cb3EnD0u.cjs} +0 -0
- /package/dist/{error-BCp9NkPi.js → error-DIZOY2Lw.js} +0 -0
- /package/dist/{esm-browser-C93Q-EOI.js → esm-browser-MG97cre9.js} +0 -0
- /package/dist/{esm-browser-DTc9IK3D.cjs → esm-browser-bweqfBlL.cjs} +0 -0
- /package/dist/{feature-flag-key.vo-ofrB6ZVQ.js → feature-flag-key.vo-DN_-4-sG.js} +0 -0
- /package/dist/{feature-flag-key.vo-BPz-ZAp6.cjs → feature-flag-key.vo-RlfHL3hq.cjs} +0 -0
- /package/dist/{first-state-of-status-OROkXcRv.cjs → first-state-of-status-CbT7hPa4.cjs} +0 -0
- /package/dist/{first-state-of-status-DQnMT3ya.js → first-state-of-status-unPynOuM.js} +0 -0
- /package/dist/{init-Es3wHW7D.js → init-829HRYcz.js} +0 -0
- /package/dist/{init-CKipPE_c.js → init-A-VyGSNW2.js} +0 -0
- /package/dist/{init-DFQQ9dTW.cjs → init-Atisw4x2.cjs} +0 -0
- /package/dist/{init-C5CEZ1m0.cjs → init-BFcvPHL-.cjs} +0 -0
- /package/dist/{init-IAk_CkGa.cjs → init-BgNobbNq.cjs} +0 -0
- /package/dist/{init-cqN3uX2j.js → init-atCFur0v.js} +0 -0
- /package/dist/{is-redux-persist-state-CTn3WZVh.cjs → is-redux-persist-state-BCFnSm36.cjs} +0 -0
- /package/dist/{is-redux-persist-state-Cxcd0_bM.js → is-redux-persist-state-yBfq0h_E.js} +0 -0
- /package/dist/{key-value-store-8cMzeNyG.js → key-value-store--W3SrMaw.js} +0 -0
- /package/dist/{key-value-store-DUAepXQf.cjs → key-value-store-C2Xt5Emp.cjs} +0 -0
- /package/dist/{repo-slice-WxetRhMY.cjs → repo-slice-7X4AYYVm.cjs} +0 -0
- /package/dist/{repo-slice-DwyMhCR1.js → repo-slice-RxFm0zDZ.js} +0 -0
- /package/dist/{reselect-CRDqmQY9.cjs → reselect-Bd94u0K-.cjs} +0 -0
- /package/dist/{reselect-C06X06oX.js → reselect-CGoLzEPv.js} +0 -0
- /package/dist/{serializable-B8GahgE1.js → serializable-BHdKIgk3.js} +0 -0
- /package/dist/{serializable-CRdnFaLZ.cjs → serializable-BxHkoPdk.cjs} +0 -0
- /package/dist/{slice-D11FHQuQ.cjs → slice-BiRsDKOK.cjs} +0 -0
- /package/dist/{slice-Be7hj4Iy.js → slice-Bk0Sv05J.js} +0 -0
- /package/dist/{slice-FioKeHtA.cjs → slice-Dqw1ecum.cjs} +0 -0
- /package/dist/{slice-B87b52iM.js → slice-obCSLm1x.js} +0 -0
- /package/dist/{src-vq1wS9sZ.js → src-BlxEp6Mm.js} +0 -0
- /package/dist/{src-BTPIvlDI.cjs → src-Cqp0B2M_.cjs} +0 -0
- /package/dist/{time.vo-CQ8pSXz2.cjs → time.vo-D3wWRw9L.cjs} +0 -0
- /package/dist/{time.vo-DkYYGYp6.js → time.vo-tNheinXm.js} +0 -0
- /package/dist/{toEmpty-CgAl3097.js → toEmpty-8Zax1MPd.js} +0 -0
- /package/dist/{toEmpty-DAMmNB5r.cjs → toEmpty-CYAbupM4.cjs} +0 -0
- /package/dist/{token-id.vo-ClsroxHO.js → token-id.vo-Bvwhr3ZE.js} +0 -0
- /package/dist/{token-id.vo-BxG9TG0O.cjs → token-id.vo-DXv5uS9n.cjs} +0 -0
- /package/dist/{util-DxzlYNS5.js → util-C8a4fA9p.js} +0 -0
- /package/dist/{util-CmdAhheh.cjs → util-CzeB3hfa.cjs} +0 -0
- /package/dist/{util-selector-CcK-GAdE.js → util-selector-BSTsxgne.js} +0 -0
- /package/dist/{util-selector-BcAncU4L.cjs → util-selector-BWPH68_l.cjs} +0 -0
- /package/dist/{while-active-BpppWuCs.js → while-active-B0lWy_6l.js} +0 -0
- /package/dist/{while-active-Dhc2LwOm.cjs → while-active-Dsowp0Fi.cjs} +0 -0
|
@@ -0,0 +1,983 @@
|
|
|
1
|
+
import { a as __toESM, r as __exportAll } from "./rolldown-runtime-OvD0k9op.js";
|
|
2
|
+
import { n as import_buffer, r as init__polyfill_buffer_patch } from "./_polyfill-buffer-patch-yNxN4d5E.js";
|
|
3
|
+
import { a as validateBitcoinAddress, i as isP2trAddress, l as require_src, n as AddressValidationResult, s as BitcoinNetworkId } from "./address-B9ntKL8K.js";
|
|
4
|
+
import { a as getExtendedPubKeys, o as bitcoinFullDerivationPath } from "./keyDerivation-D3k9XyHg.js";
|
|
5
|
+
import { t as require_src$1 } from "./src-BFoefPv_.js";
|
|
6
|
+
import { n as HexBytes, t as ByteArray } from "./bytes.vo-BB7_4JK6.js";
|
|
7
|
+
import { A as ContractName, C as walletRepoStoreContract, S as WalletType, _ as walletActiveStateDependencyContract, b as addressesStoreContract, j as ModuleName, l as signerFactoryAddonContract, n as sdk_default$4, o as inMemoryIntegrationAddonContract, r as sdk_default$3, s as AuthSecret, t as sdk_default$5, v as tokensStoreContract, w as networkStoreContract, x as activitiesStoreContract, y as syncStoreContract } from "./sdk-Cb-gZnS9.js";
|
|
8
|
+
import { n as Ok, t as Err } from "./asyncoption-CruEYOBI.js";
|
|
9
|
+
import { a as inferStoreContext, i as inferModuleContext, n as combineContracts, r as inferContractContext } from "./store-DuBG8qh5.js";
|
|
10
|
+
import { t as ActivityType } from "./activity-type-GsJGWs-3.js";
|
|
11
|
+
import { t as CompositeSignerFactory } from "./composite-signer-factory-CR8YHA1y.js";
|
|
12
|
+
import { t as AuthenticationCancelledError } from "./types-CJT6XF2c.js";
|
|
13
|
+
import { n as addressBookAddressValidatorAddonContract, r as LazyWalletMismatchError, t as tokenIdMapperAddonContract } from "./contract-1R86jhSw.js";
|
|
14
|
+
import { n as BitcoinNetwork } from "./types-B8uiJn-X.js";
|
|
15
|
+
import { n as BITCOIN_MEMPOOL_FEE_MARKET_FEATURE_FLAG, t as BITCOIN_FEATURE_FLAG } from "./const-CUnCl5U0.js";
|
|
16
|
+
import { i as bitcoinContextActions, n as bitcoinAccountWallets$, o as bitcoinContextSelectors, r as SyncStatus } from "./side-effects-BnqYz7Nl.js";
|
|
17
|
+
import { n as encodeUnsignedTxToString, t as signBitcoinTransactionWithSeed } from "./sign-bitcoin-transaction-with-seed-D4z62-jV.js";
|
|
18
|
+
import { Observable, combineLatest, filter, firstValueFrom, forkJoin, map, of, switchMap, take, throwError, timeout } from "rxjs";
|
|
19
|
+
import isEqual from "lodash/isEqual.js";
|
|
20
|
+
//#region ../../packages/contract/bitcoin-context/src/contract.ts
|
|
21
|
+
const bitcoinProviderContract = inferContractContext({
|
|
22
|
+
name: ContractName("bitcoin-provider"),
|
|
23
|
+
instance: "exactly-one",
|
|
24
|
+
contractType: "sideEffectDependency"
|
|
25
|
+
});
|
|
26
|
+
const bitcoinFeeMarketProvider = inferContractContext({
|
|
27
|
+
name: ContractName("bitcoin-fee-market-provider"),
|
|
28
|
+
instance: "exactly-one",
|
|
29
|
+
contractType: "sideEffectDependency"
|
|
30
|
+
});
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region ../../packages/contract/bitcoin-context/src/fee-rate.ts
|
|
33
|
+
const SATOSHIS_PER_BITCOIN = 1e8;
|
|
34
|
+
const BYTES_PER_KILOBYTE = 1e3;
|
|
35
|
+
/**
|
|
36
|
+
* Upper bound for a caller-supplied fee rate, in sat/vB. Far above any real
|
|
37
|
+
* mempool spike, so it catches a unit mix-up (a BTC/kB figure arriving where
|
|
38
|
+
* sat/vB is expected, or a stray exponent) without refusing an urgent send.
|
|
39
|
+
*/
|
|
40
|
+
const MAX_FEE_RATE_SATS_PER_VBYTE = 1e4;
|
|
41
|
+
/**
|
|
42
|
+
* Converts a fee rate given in sat/vB — the unit dApp APIs and the fee input
|
|
43
|
+
* speak — into the BTC-per-kilobyte rate that
|
|
44
|
+
* `BitcoinBlockchainSpecificTxData.feeRate.customFeeRate` carries.
|
|
45
|
+
*
|
|
46
|
+
* Returns `undefined` for a rate that must not be built against: not a finite
|
|
47
|
+
* number, not positive, or above {@link MAX_FEE_RATE_SATS_PER_VBYTE}. Callers
|
|
48
|
+
* are expected to refuse the request rather than substitute a default — a
|
|
49
|
+
* zero rate yields a transaction no node relays, and an unconverted sat/vB
|
|
50
|
+
* figure overpays by five orders of magnitude.
|
|
51
|
+
*/
|
|
52
|
+
const feeRateFromSatsPerVByte = (satsPerVByte) => Number.isFinite(satsPerVByte) && satsPerVByte > 0 && satsPerVByte <= MAX_FEE_RATE_SATS_PER_VBYTE ? satsPerVByte * BYTES_PER_KILOBYTE / SATOSHIS_PER_BITCOIN : void 0;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region ../../packages/module/blockchain-bitcoin/src/store/index.ts
|
|
55
|
+
var store_default$2 = inferStoreContext({
|
|
56
|
+
load: async () => import("./init-DuYENxci.js"),
|
|
57
|
+
context: {
|
|
58
|
+
actions: bitcoinContextActions,
|
|
59
|
+
selectors: bitcoinContextSelectors
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region ../../packages/module/blockchain-bitcoin/src/input-selection/GreedyInputSelector.ts
|
|
64
|
+
/**
|
|
65
|
+
* A concrete implementation of InputSelector that uses a simple greedy algorithm.
|
|
66
|
+
*/
|
|
67
|
+
var GreedyInputSelector = class {
|
|
68
|
+
selectInputs(props) {
|
|
69
|
+
const { changeAddress, utxos, outputs, feeRate, hasOpReturn } = props;
|
|
70
|
+
const selected = [];
|
|
71
|
+
const totalOutput = outputs.reduce((accumulator, output) => accumulator + output.value, 0);
|
|
72
|
+
let inputSum = 0;
|
|
73
|
+
let fee = 0;
|
|
74
|
+
for (const utxo of utxos) {
|
|
75
|
+
selected.push(utxo);
|
|
76
|
+
inputSum += utxo.satoshis;
|
|
77
|
+
fee = this.computeFee({
|
|
78
|
+
inputCount: selected.length,
|
|
79
|
+
outputCount: outputs.length,
|
|
80
|
+
feeRate,
|
|
81
|
+
hasOpReturn
|
|
82
|
+
});
|
|
83
|
+
if (inputSum >= totalOutput + fee) break;
|
|
84
|
+
}
|
|
85
|
+
if (inputSum < totalOutput + fee) return null;
|
|
86
|
+
let change = inputSum - totalOutput - fee;
|
|
87
|
+
if (change > 0 && change < 546) {
|
|
88
|
+
const { change: newChange, fee: feeDelta } = this.attemptDustRescue({
|
|
89
|
+
change,
|
|
90
|
+
feeRate,
|
|
91
|
+
selected,
|
|
92
|
+
remaining: utxos.slice(selected.length),
|
|
93
|
+
inputSum,
|
|
94
|
+
totalOutput,
|
|
95
|
+
outputsCount: outputs.length,
|
|
96
|
+
hasOpReturn
|
|
97
|
+
});
|
|
98
|
+
change = newChange;
|
|
99
|
+
fee += feeDelta;
|
|
100
|
+
if (change < 546) {
|
|
101
|
+
fee += change;
|
|
102
|
+
change = 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const finalOutputs = outputs.map(({ address, value }) => ({
|
|
106
|
+
address,
|
|
107
|
+
value
|
|
108
|
+
}));
|
|
109
|
+
if (change >= 546) finalOutputs.push({
|
|
110
|
+
address: changeAddress,
|
|
111
|
+
value: change
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
selectedUTxOs: selected,
|
|
115
|
+
outputs: finalOutputs,
|
|
116
|
+
fee
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Estimate the fee for a given input / output count */
|
|
120
|
+
computeFee(params) {
|
|
121
|
+
const { inputCount, outputCount, feeRate, hasOpReturn } = params;
|
|
122
|
+
const size = inputCount * 68 + (outputCount + (hasOpReturn ? 1 : 0)) * 31 + 10;
|
|
123
|
+
return Math.ceil(size * feeRate);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Try to pull one more UTxO so that change exceeds the dust threshold if
|
|
127
|
+
* the value rescued is worth more than the added fee.
|
|
128
|
+
*/
|
|
129
|
+
attemptDustRescue({ change, feeRate, selected, remaining, inputSum, totalOutput, outputsCount, hasOpReturn }) {
|
|
130
|
+
if (change === 0 || change >= 546) return {
|
|
131
|
+
change,
|
|
132
|
+
fee: 0
|
|
133
|
+
};
|
|
134
|
+
const originalChange = change;
|
|
135
|
+
let feeDelta = 0;
|
|
136
|
+
for (const utxo of remaining) {
|
|
137
|
+
const newInputSum = inputSum + utxo.satoshis;
|
|
138
|
+
const newFee = this.computeFee({
|
|
139
|
+
inputCount: selected.length + 1,
|
|
140
|
+
outputCount: outputsCount + 1,
|
|
141
|
+
feeRate,
|
|
142
|
+
hasOpReturn
|
|
143
|
+
});
|
|
144
|
+
const newChange = newInputSum - totalOutput - newFee;
|
|
145
|
+
if (newChange - originalChange >= Math.ceil(68 * feeRate) && newChange >= 546) {
|
|
146
|
+
selected.push(utxo);
|
|
147
|
+
feeDelta = newFee - this.computeFee({
|
|
148
|
+
inputCount: selected.length - 1,
|
|
149
|
+
outputCount: outputsCount + 1,
|
|
150
|
+
feeRate,
|
|
151
|
+
hasOpReturn
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
change: newChange,
|
|
155
|
+
fee: feeDelta
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
change,
|
|
161
|
+
fee: 0
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region ../../packages/module/blockchain-bitcoin/src/tx-builder/errors.ts
|
|
167
|
+
/**
|
|
168
|
+
* The reason a Bitcoin payment cannot be built.
|
|
169
|
+
*/
|
|
170
|
+
let BitcoinTxBuildErrorCode = /* @__PURE__ */ function(BitcoinTxBuildErrorCode) {
|
|
171
|
+
/** The funding UTxO set is empty (e.g. the only UTxO is spent by a pending tx). */
|
|
172
|
+
BitcoinTxBuildErrorCode["NoUtxos"] = "NoUtxos";
|
|
173
|
+
/** UTxOs exist but cannot cover the requested amount plus the network fee. */
|
|
174
|
+
BitcoinTxBuildErrorCode["InsufficientFunds"] = "InsufficientFunds";
|
|
175
|
+
/** No transaction outputs were provided. */
|
|
176
|
+
BitcoinTxBuildErrorCode["NoOutputs"] = "NoOutputs";
|
|
177
|
+
/** Change address was never set (internal invariant). */
|
|
178
|
+
BitcoinTxBuildErrorCode["ChangeAddressNotSet"] = "ChangeAddressNotSet";
|
|
179
|
+
/** The change address failed validation. */
|
|
180
|
+
BitcoinTxBuildErrorCode["InvalidChangeAddress"] = "InvalidChangeAddress";
|
|
181
|
+
/** A recipient address failed validation. */
|
|
182
|
+
BitcoinTxBuildErrorCode["InvalidRecipientAddress"] = "InvalidRecipientAddress";
|
|
183
|
+
/** A selected UTxO's address could not be matched to a known signing address. */
|
|
184
|
+
BitcoinTxBuildErrorCode["UnresolvedUtxoAddress"] = "UnresolvedUtxoAddress";
|
|
185
|
+
/** The OP_RETURN message exceeds the 80-byte limit. */
|
|
186
|
+
BitcoinTxBuildErrorCode["MessageTooLong"] = "MessageTooLong";
|
|
187
|
+
/** The resolved fee rate is not a positive number, so the tx would pay no fee. */
|
|
188
|
+
BitcoinTxBuildErrorCode["InvalidFeeRate"] = "InvalidFeeRate";
|
|
189
|
+
return BitcoinTxBuildErrorCode;
|
|
190
|
+
}({});
|
|
191
|
+
/**
|
|
192
|
+
* The error a Bitcoin payment build fails with, identified by its `code`.
|
|
193
|
+
*/
|
|
194
|
+
var BitcoinTxBuildError = class extends Error {
|
|
195
|
+
/** The reason the payment cannot be built. */
|
|
196
|
+
code;
|
|
197
|
+
constructor(code, message) {
|
|
198
|
+
super(message);
|
|
199
|
+
this.name = "BitcoinTxBuildError";
|
|
200
|
+
this.code = code;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
BitcoinTxBuildErrorCode.NoUtxos, BitcoinTxBuildErrorCode.InsufficientFunds, BitcoinTxBuildErrorCode.NoOutputs, BitcoinTxBuildErrorCode.ChangeAddressNotSet, BitcoinTxBuildErrorCode.InvalidChangeAddress, BitcoinTxBuildErrorCode.InvalidRecipientAddress, BitcoinTxBuildErrorCode.UnresolvedUtxoAddress, BitcoinTxBuildErrorCode.MessageTooLong, BitcoinTxBuildErrorCode.InvalidFeeRate;
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region ../../packages/module/blockchain-bitcoin/src/tx-builder/TransactionBuilder.ts
|
|
206
|
+
init__polyfill_buffer_patch();
|
|
207
|
+
var import_src$1 = /* @__PURE__ */ __toESM(require_src());
|
|
208
|
+
/**
|
|
209
|
+
* A class to build Bitcoin transactions using a flexible input and output management system.
|
|
210
|
+
*/
|
|
211
|
+
var TransactionBuilder = class {
|
|
212
|
+
psbt;
|
|
213
|
+
network;
|
|
214
|
+
feeRate;
|
|
215
|
+
knownAddresses;
|
|
216
|
+
outputs = [];
|
|
217
|
+
utxos = [];
|
|
218
|
+
changeAddress;
|
|
219
|
+
changeDerivation;
|
|
220
|
+
changeMasterFingerprint;
|
|
221
|
+
signers = [];
|
|
222
|
+
inputSelector = new GreedyInputSelector();
|
|
223
|
+
opReturnData;
|
|
224
|
+
/**
|
|
225
|
+
* Initializes the transaction builder.
|
|
226
|
+
*
|
|
227
|
+
* @param network - The Bitcoin network (Mainnet or Testnet).
|
|
228
|
+
* @param feeRate - The fee rate in BTC per kilobyte.
|
|
229
|
+
* @param knownAddresses - The list of known addresses with their public keys.
|
|
230
|
+
*/
|
|
231
|
+
constructor(network, feeRate, knownAddresses) {
|
|
232
|
+
this.feeRate = feeRate;
|
|
233
|
+
this.knownAddresses = knownAddresses;
|
|
234
|
+
this.network = network;
|
|
235
|
+
this.psbt = new import_src$1.Psbt({ network: network === BitcoinNetwork.Mainnet ? import_src$1.networks.bitcoin : import_src$1.networks.testnet });
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Sets the UTXO set that will be used to fund the transaction.
|
|
239
|
+
*
|
|
240
|
+
* @param utxos - Array of available UTXOs.
|
|
241
|
+
* @returns The builder instance for chaining.
|
|
242
|
+
*/
|
|
243
|
+
setUtxoSet(utxos) {
|
|
244
|
+
this.utxos = utxos;
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Sets the change address where any remaining funds will be sent.
|
|
249
|
+
*
|
|
250
|
+
* @param changeAddress - The change address.
|
|
251
|
+
* @returns The builder instance for chaining.
|
|
252
|
+
*/
|
|
253
|
+
setChangeAddress(changeAddress) {
|
|
254
|
+
if (validateBitcoinAddress(changeAddress, this.network) !== AddressValidationResult.Valid) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.InvalidChangeAddress, "Invalid change address");
|
|
255
|
+
this.changeAddress = changeAddress;
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Sets the change address together with its derivation and the account master
|
|
260
|
+
* fingerprint, so the change output can be stamped with a BIP-32 key-origin an
|
|
261
|
+
* air-gapped device uses to recognize change. When the master fingerprint is
|
|
262
|
+
* absent (in-memory accounts) no key-origin is stamped.
|
|
263
|
+
*
|
|
264
|
+
* @param changeDerivation - The change address and its derivation path/pubkey.
|
|
265
|
+
* @param masterFingerprint - Device xfp as 8-char hex, or undefined.
|
|
266
|
+
* @returns The builder instance for chaining.
|
|
267
|
+
*/
|
|
268
|
+
setChange(changeDerivation, masterFingerprint) {
|
|
269
|
+
this.setChangeAddress(changeDerivation.address);
|
|
270
|
+
this.changeDerivation = changeDerivation;
|
|
271
|
+
this.changeMasterFingerprint = masterFingerprint;
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Sets the input selection strategy.
|
|
276
|
+
*
|
|
277
|
+
* @param inputSelector - An implementation of the InputSelector interface.
|
|
278
|
+
* @returns The builder instance for chaining.
|
|
279
|
+
*/
|
|
280
|
+
setInputSelection(inputSelector) {
|
|
281
|
+
this.inputSelector = inputSelector;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Adds an output to the transaction.
|
|
286
|
+
*
|
|
287
|
+
* @param address - The destination address.
|
|
288
|
+
* @param value - The amount to send (in satoshis as bigint).
|
|
289
|
+
* @returns The builder instance for chaining.
|
|
290
|
+
*/
|
|
291
|
+
addOutput(address, value) {
|
|
292
|
+
if (validateBitcoinAddress(address, this.network) !== AddressValidationResult.Valid) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.InvalidRecipientAddress, "Invalid recipient address");
|
|
293
|
+
this.outputs.push({
|
|
294
|
+
address,
|
|
295
|
+
value
|
|
296
|
+
});
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Adds an OP_RETURN message to the transaction.
|
|
301
|
+
*
|
|
302
|
+
* @param message - The message to embed (string, UTF-8). Max 80 bytes after encoding.
|
|
303
|
+
* If null, removes any existing OP_RETURN data.
|
|
304
|
+
* @returns The builder instance for chaining.
|
|
305
|
+
*/
|
|
306
|
+
addOpReturnOutput(message) {
|
|
307
|
+
if (!message?.trim()) {
|
|
308
|
+
this.opReturnData = void 0;
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
const data = import_buffer.Buffer.from(message, "utf8");
|
|
312
|
+
if (data.length > 80) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.MessageTooLong, `OP_RETURN message exceeds 80 bytes (actual: ${data.length}).`);
|
|
313
|
+
this.opReturnData = data;
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Builds the transaction by selecting UTXOs (using either the provided input selector or a fallback),
|
|
318
|
+
* adding inputs and outputs (including a change output if needed), and calculating fees.
|
|
319
|
+
* If the change amount is below the dust threshold, it is added to the fee instead.
|
|
320
|
+
*
|
|
321
|
+
* @returns An UnsignedTransaction containing the PSBT context, fee, estimated virtual bytes, signers, and outputs.
|
|
322
|
+
* @throws Error if funds are insufficient, no UTXOs are set, or if the change address is not provided.
|
|
323
|
+
*/
|
|
324
|
+
build() {
|
|
325
|
+
if (!this.utxos || this.utxos.length === 0) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.NoUtxos, "No UTXOs available to fund the transaction.");
|
|
326
|
+
if (!this.changeAddress) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.ChangeAddressNotSet, "Change address not set.");
|
|
327
|
+
if (this.outputs.length === 0) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.NoOutputs, "No outputs have been added.");
|
|
328
|
+
const feeRateSatoshis = this.feeRate * 1e8 / 1e3;
|
|
329
|
+
let selectedUTxOs = [];
|
|
330
|
+
let fee = 0;
|
|
331
|
+
let coinselectOutputs = [];
|
|
332
|
+
const result = this.inputSelector.selectInputs({
|
|
333
|
+
changeAddress: this.changeAddress,
|
|
334
|
+
utxos: this.utxos,
|
|
335
|
+
outputs: this.outputs,
|
|
336
|
+
feeRate: feeRateSatoshis,
|
|
337
|
+
hasOpReturn: !!this.opReturnData
|
|
338
|
+
});
|
|
339
|
+
if (!result) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.InsufficientFunds, "Insufficient funds or coin selection failed.");
|
|
340
|
+
selectedUTxOs = result.selectedUTxOs;
|
|
341
|
+
fee = result.fee;
|
|
342
|
+
coinselectOutputs = result.outputs;
|
|
343
|
+
for (const utxo of selectedUTxOs) {
|
|
344
|
+
const knownAddr = this.knownAddresses.find((addr) => addr.address === utxo.address);
|
|
345
|
+
if (!knownAddr) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.UnresolvedUtxoAddress, "Unknown address in UTXO set.");
|
|
346
|
+
this.signers.push(knownAddr);
|
|
347
|
+
const net = this.network === BitcoinNetwork.Mainnet ? import_src$1.networks.bitcoin : import_src$1.networks.testnet;
|
|
348
|
+
this.psbt.addInput({
|
|
349
|
+
hash: utxo.txId,
|
|
350
|
+
index: utxo.index,
|
|
351
|
+
witnessUtxo: {
|
|
352
|
+
script: import_src$1.payments.p2wpkh({
|
|
353
|
+
pubkey: import_buffer.Buffer.from(knownAddr.publicKeyHex, "hex"),
|
|
354
|
+
network: net
|
|
355
|
+
}).output,
|
|
356
|
+
value: utxo.satoshis
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
coinselectOutputs.forEach(({ address, value }) => {
|
|
361
|
+
if (isP2trAddress(address)) {
|
|
362
|
+
const taprootPubKey = import_buffer.Buffer.from(import_src$1.address.fromBech32(address).data);
|
|
363
|
+
this.psbt.addOutput({
|
|
364
|
+
script: import_src$1.script.compile([import_src$1.opcodes.OP_1, taprootPubKey]),
|
|
365
|
+
value
|
|
366
|
+
});
|
|
367
|
+
} else this.psbt.addOutput({
|
|
368
|
+
address,
|
|
369
|
+
value
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
if (this.opReturnData) {
|
|
373
|
+
const embed = import_src$1.payments.embed({ data: [this.opReturnData] });
|
|
374
|
+
this.psbt.addOutput({
|
|
375
|
+
script: embed.output,
|
|
376
|
+
value: 0
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
this.stampChangeOutput(coinselectOutputs);
|
|
380
|
+
const opReturnOutput = this.opReturnData ? 1 : 0;
|
|
381
|
+
const vBytes = selectedUTxOs.length * 68 + (coinselectOutputs.length + opReturnOutput) * 31 + 10;
|
|
382
|
+
return {
|
|
383
|
+
context: this.psbt,
|
|
384
|
+
toAddress: this.outputs[0].address,
|
|
385
|
+
fee,
|
|
386
|
+
amount: this.outputs[0].value,
|
|
387
|
+
vBytes,
|
|
388
|
+
signers: this.signers
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Stamps the change output with a BIP-32 key-origin (master fingerprint +
|
|
393
|
+
* change pubkey + full derivation path) so an air-gapped device recognizes it
|
|
394
|
+
* as the wallet's own change instead of a third-party spend. No-ops unless a
|
|
395
|
+
* change output is present, its derivation was provided via setChange, and a
|
|
396
|
+
* master fingerprint is known (in-memory accounts skip stamping, leaving the
|
|
397
|
+
* PSBT byte-identical for that path).
|
|
398
|
+
*
|
|
399
|
+
* @param finalOutputs - The outputs selected by coin selection, in PSBT order.
|
|
400
|
+
*/
|
|
401
|
+
stampChangeOutput(finalOutputs) {
|
|
402
|
+
const { changeDerivation, changeMasterFingerprint } = this;
|
|
403
|
+
if (!changeDerivation || !changeMasterFingerprint) return;
|
|
404
|
+
const changeOutputIndex = finalOutputs.findLastIndex((output) => output.address === changeDerivation.address);
|
|
405
|
+
if (changeOutputIndex === -1) return;
|
|
406
|
+
this.psbt.updateOutput(changeOutputIndex, { bip32Derivation: [{
|
|
407
|
+
masterFingerprint: import_buffer.Buffer.from(changeMasterFingerprint, "hex"),
|
|
408
|
+
pubkey: import_buffer.Buffer.from(changeDerivation.publicKeyHex, "hex"),
|
|
409
|
+
path: bitcoinFullDerivationPath({
|
|
410
|
+
addressType: changeDerivation.addressType,
|
|
411
|
+
network: this.network,
|
|
412
|
+
account: changeDerivation.account,
|
|
413
|
+
chain: changeDerivation.chain,
|
|
414
|
+
index: changeDerivation.index
|
|
415
|
+
})
|
|
416
|
+
}] });
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region ../../packages/module/blockchain-bitcoin/src/tx-builder/build-bitcoin-payment.ts
|
|
421
|
+
init__polyfill_buffer_patch();
|
|
422
|
+
const getBitcoinInFlight = (activity) => {
|
|
423
|
+
if (activity.type !== ActivityType.Pending) return void 0;
|
|
424
|
+
return activity.blockchainSpecific?.Bitcoin;
|
|
425
|
+
};
|
|
426
|
+
const outpointKey = (ref) => `${ref.txId}#${ref.index}`;
|
|
427
|
+
/**
|
|
428
|
+
* Drops the outpoints consumed by pending transactions from the spendable set.
|
|
429
|
+
* Unconfirmed outputs produced by those transactions are not added: spending
|
|
430
|
+
* unconfirmed Bitcoin outputs is unsafe under RBF and bounded by mempool
|
|
431
|
+
* ancestor limits.
|
|
432
|
+
*
|
|
433
|
+
* @param utxos - The confirmed UTxOs of the account.
|
|
434
|
+
* @param _accountAddresses - The addresses of the account.
|
|
435
|
+
* @param pendingActivities - The pending activities of the account.
|
|
436
|
+
*/
|
|
437
|
+
const applyInFlightUtxoAdjustments = (utxos, _accountAddresses, pendingActivities) => {
|
|
438
|
+
const spent = /* @__PURE__ */ new Set();
|
|
439
|
+
for (const activity of pendingActivities) {
|
|
440
|
+
const inFlight = getBitcoinInFlight(activity);
|
|
441
|
+
if (!inFlight) continue;
|
|
442
|
+
for (const input of inFlight.consumedInputs) spent.add(outpointKey(input));
|
|
443
|
+
}
|
|
444
|
+
if (spent.size === 0) return [...utxos];
|
|
445
|
+
return utxos.filter((utxo) => !spent.has(outpointKey(utxo)));
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* Resolves the rate to build against, in BTC per kilobyte.
|
|
449
|
+
*
|
|
450
|
+
* The market is read ONLY for the three quoted tiers. `Custom` is a rate the
|
|
451
|
+
* user typed and must stay buildable while mempool.space is unreachable, so
|
|
452
|
+
* the fetch must not be hoisted above that branch, or an unreachable market
|
|
453
|
+
* fails every Bitcoin build. A tier build still fails when the market cannot
|
|
454
|
+
* be read.
|
|
455
|
+
*
|
|
456
|
+
* @param feeRate - The chosen option, plus the typed rate when it is `Custom`.
|
|
457
|
+
* @param getCurrentFeeMarket - Fetches the market; called only for a tier.
|
|
458
|
+
*/
|
|
459
|
+
const resolveFeeRate = async (feeRate, getCurrentFeeMarket) => {
|
|
460
|
+
if (feeRate.feeOption === "Custom") return feeRate.customFeeRate ?? 0;
|
|
461
|
+
const market = (await firstValueFrom(getCurrentFeeMarket())).unwrap();
|
|
462
|
+
switch (feeRate.feeOption) {
|
|
463
|
+
case "Fast": return market.fast.feeRate;
|
|
464
|
+
case "Average": return market.standard.feeRate;
|
|
465
|
+
case "Low": return market.slow.feeRate;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Embeds each input's full previous transaction (nonWitnessUtxo) into the
|
|
470
|
+
* PSBT so it is self-contained for hardware signers: Ledger requires the
|
|
471
|
+
* previous transaction for segwit-v0 inputs and Trezor consumes it as refTxs.
|
|
472
|
+
* Duplicate previous transactions are fetched only once and all fetches run
|
|
473
|
+
* concurrently. Each fetched transaction is verified to hash to the requested
|
|
474
|
+
* txid so a wrong provider response fails the build locally instead of as an
|
|
475
|
+
* opaque device-side rejection. Throws if any fetch fails, failing the build
|
|
476
|
+
* instead of producing a PSBT a device would reject.
|
|
477
|
+
*
|
|
478
|
+
* @param psbt - The freshly built PSBT whose inputs carry only witnessUtxo.
|
|
479
|
+
* @param getRawTransaction - Fetches the raw transaction hex for a tx id.
|
|
480
|
+
*/
|
|
481
|
+
const embedPreviousTransactions = async (psbt, getRawTransaction) => {
|
|
482
|
+
const inputTxIds = psbt.txInputs.map((input) => import_buffer.Buffer.from(input.hash).reverse().toString("hex"));
|
|
483
|
+
const uniqueTxIds = [...new Set(inputTxIds)];
|
|
484
|
+
if (uniqueTxIds.length === 0) return;
|
|
485
|
+
const rawTxResults = await firstValueFrom(forkJoin(uniqueTxIds.map((txId) => getRawTransaction(txId))));
|
|
486
|
+
const rawTxByTxId = /* @__PURE__ */ new Map();
|
|
487
|
+
uniqueTxIds.forEach((txId, index) => {
|
|
488
|
+
const rawTx = import_buffer.Buffer.from(rawTxResults[index].unwrap(), "hex");
|
|
489
|
+
if (import_src$1.Transaction.fromBuffer(rawTx).getId() !== txId) throw new Error(`Fetched previous transaction does not match requested txid ${txId}`);
|
|
490
|
+
rawTxByTxId.set(txId, rawTx);
|
|
491
|
+
});
|
|
492
|
+
inputTxIds.forEach((txId, index) => {
|
|
493
|
+
psbt.updateInput(index, { nonWitnessUtxo: rawTxByTxId.get(txId) });
|
|
494
|
+
});
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* Builds an unsigned Bitcoin payment from the account wallet's current UTxOs
|
|
498
|
+
* and addresses. Outpoints consumed by pending activities are not spent
|
|
499
|
+
* again, change goes to the wallet address, and hardware accounts (those with
|
|
500
|
+
* a master fingerprint) get each input's previous transaction embedded.
|
|
501
|
+
*
|
|
502
|
+
* @param params - The wallet, pending activities, recipients, fee option and memo.
|
|
503
|
+
* @returns The serialized unsigned transaction and the fee it pays.
|
|
504
|
+
* @throws {@link BitcoinTxBuildError} when the payment cannot be built, for example
|
|
505
|
+
* when the fee rate is not positive or the funds do not cover it.
|
|
506
|
+
*/
|
|
507
|
+
const buildBitcoinPayment = async ({ wallet, pendingActivities, outputs, feeRate, memo, logger }) => {
|
|
508
|
+
const network = wallet.network;
|
|
509
|
+
const utxos = await firstValueFrom(wallet.utxos$);
|
|
510
|
+
const addresses = await firstValueFrom(wallet.addresses$);
|
|
511
|
+
const rateToUse = await resolveFeeRate(feeRate, () => wallet.getCurrentFeeMarket());
|
|
512
|
+
if (!Number.isFinite(rateToUse) || rateToUse <= 0) throw new BitcoinTxBuildError(BitcoinTxBuildErrorCode.InvalidFeeRate, `Invalid fee rate: ${rateToUse}`);
|
|
513
|
+
logger?.debug(`Bitcoin buildTx: Using fee rate of ${rateToUse} BTC/kB`);
|
|
514
|
+
const txBuilder = new TransactionBuilder(network, rateToUse, addresses);
|
|
515
|
+
const adjustedUtxos = applyInFlightUtxoAdjustments(utxos, new Set(addresses.map((a) => a.address)), pendingActivities);
|
|
516
|
+
txBuilder.setChange(wallet.address, wallet.masterFingerprint).setUtxoSet(adjustedUtxos);
|
|
517
|
+
for (const output of outputs) {
|
|
518
|
+
txBuilder.addOutput(output.address, output.amount);
|
|
519
|
+
logger?.debug(`Bitcoin buildTx: Adding output to address: ${output.address} with amount from txParams: ${output.amount}`);
|
|
520
|
+
}
|
|
521
|
+
if (memo) {
|
|
522
|
+
logger?.debug(`Bitcoin buildTx: Adding OP_RETURN memo: ${memo}`);
|
|
523
|
+
txBuilder.addOpReturnOutput(memo);
|
|
524
|
+
}
|
|
525
|
+
const tx = txBuilder.build();
|
|
526
|
+
tx.network = network;
|
|
527
|
+
if (wallet.masterFingerprint) await embedPreviousTransactions(tx.context, (txId) => wallet.getRawTransaction(txId));
|
|
528
|
+
return {
|
|
529
|
+
serializedTx: encodeUnsignedTxToString(tx),
|
|
530
|
+
fee: BigInt(tx.fee)
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region ../../packages/module/blockchain-bitcoin/src/sdk.ts
|
|
535
|
+
const implementsContracts = combineContracts([
|
|
536
|
+
inMemoryIntegrationAddonContract,
|
|
537
|
+
tokensStoreContract,
|
|
538
|
+
addressesStoreContract,
|
|
539
|
+
syncStoreContract,
|
|
540
|
+
addressBookAddressValidatorAddonContract,
|
|
541
|
+
tokenIdMapperAddonContract,
|
|
542
|
+
signerFactoryAddonContract
|
|
543
|
+
]);
|
|
544
|
+
const dependsOnContracts = combineContracts([
|
|
545
|
+
bitcoinProviderContract,
|
|
546
|
+
bitcoinFeeMarketProvider,
|
|
547
|
+
networkStoreContract,
|
|
548
|
+
walletRepoStoreContract,
|
|
549
|
+
walletActiveStateDependencyContract,
|
|
550
|
+
activitiesStoreContract,
|
|
551
|
+
tokensStoreContract
|
|
552
|
+
]);
|
|
553
|
+
/**
|
|
554
|
+
* Bitcoin accounts: their addresses, tokens and sync, in-memory wallet
|
|
555
|
+
* creation and signing, without any user interface or send flow. Loads when
|
|
556
|
+
* `BITCOIN_FEATURE_FLAG` is enabled, and needs a Bitcoin provider module such
|
|
557
|
+
* as `m.bitcoinProviderMaestro` and a fee market module such as
|
|
558
|
+
* `m.bitcoinMempoolFeeMarket`.
|
|
559
|
+
*/
|
|
560
|
+
var sdk_default$2 = inferModuleContext({
|
|
561
|
+
moduleName: ModuleName("blockchain-bitcoin"),
|
|
562
|
+
implements: implementsContracts,
|
|
563
|
+
dependsOn: dependsOnContracts,
|
|
564
|
+
feature: {
|
|
565
|
+
willLoad: (featureFlags) => featureFlags.some((flag) => flag.key === BITCOIN_FEATURE_FLAG),
|
|
566
|
+
metadata: {
|
|
567
|
+
name: "Bitcoin",
|
|
568
|
+
description: "Bitcoin blockchain support"
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
store: store_default$2,
|
|
572
|
+
addons: {
|
|
573
|
+
loadInMemoryWalletIntegration: async () => import("./in-memory-wallet-integration-TM9bBphA.js"),
|
|
574
|
+
loadAddressBookAddressValidators: async () => import("./address-book-address-validator-Di_ywo8M.js"),
|
|
575
|
+
loadTokenIdMapper: async () => import("./token-id-mapper-CnKHQ8DV.js"),
|
|
576
|
+
loadSignerFactory: async () => import("./signer-factory-BA7WFJVZ.js")
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region ../../packages/module/bitcoin-mempool-fee-market/src/store/index.ts
|
|
581
|
+
var store_default$1 = inferStoreContext({
|
|
582
|
+
load: async () => import("./init-DlqJuHhl.js"),
|
|
583
|
+
context: {
|
|
584
|
+
actions: {},
|
|
585
|
+
selectors: {}
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region ../../packages/module/bitcoin-mempool-fee-market/src/sdk.ts
|
|
590
|
+
/**
|
|
591
|
+
* Bitcoin fee rate estimates from mempool.space. Loads when
|
|
592
|
+
* `BITCOIN_MEMPOOL_FEE_MARKET_FEATURE_FLAG` is enabled.
|
|
593
|
+
*/
|
|
594
|
+
var sdk_default$1 = inferModuleContext({
|
|
595
|
+
moduleName: ModuleName("bitcoin-mempool-fee-market"),
|
|
596
|
+
dependsOn: combineContracts([]),
|
|
597
|
+
implements: combineContracts([bitcoinFeeMarketProvider]),
|
|
598
|
+
store: store_default$1,
|
|
599
|
+
feature: {
|
|
600
|
+
willLoad: (featureFlags) => featureFlags.some((flag) => flag.key === BITCOIN_MEMPOOL_FEE_MARKET_FEATURE_FLAG),
|
|
601
|
+
metadata: {
|
|
602
|
+
name: "Mempool.space fee market provider",
|
|
603
|
+
description: "Mempool.space fee market provider for Bitcoin"
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
addons: {}
|
|
607
|
+
});
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region ../../packages/module/bitcoin-provider-maestro/src/store/index.ts
|
|
610
|
+
var store_default = inferStoreContext({
|
|
611
|
+
load: async () => import("./init-C00gw1zi.js"),
|
|
612
|
+
context: {
|
|
613
|
+
actions: {},
|
|
614
|
+
selectors: {}
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region ../../packages/module/bitcoin-provider-maestro/src/sdk.ts
|
|
619
|
+
/**
|
|
620
|
+
* Bitcoin chain data through Maestro: UTxOs, transactions and fee estimates.
|
|
621
|
+
* Loads when `BITCOIN_FEATURE_FLAG` is enabled.
|
|
622
|
+
*/
|
|
623
|
+
var sdk_default = inferModuleContext({
|
|
624
|
+
moduleName: ModuleName("bitcoin-provider-maestro"),
|
|
625
|
+
dependsOn: combineContracts([]),
|
|
626
|
+
implements: combineContracts([bitcoinProviderContract]),
|
|
627
|
+
store: store_default,
|
|
628
|
+
feature: {
|
|
629
|
+
willLoad: (featureFlags) => featureFlags.some((flag) => flag.key === BITCOIN_FEATURE_FLAG),
|
|
630
|
+
metadata: {
|
|
631
|
+
name: "Maestro",
|
|
632
|
+
description: "Maestro provider for Bitcoin"
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
addons: {}
|
|
636
|
+
});
|
|
637
|
+
//#endregion
|
|
638
|
+
//#region src/bitcoin/modules.ts
|
|
639
|
+
var modules_exports = /* @__PURE__ */ __exportAll({
|
|
640
|
+
bitcoinMempoolFeeMarket: () => sdk_default$1,
|
|
641
|
+
bitcoinProviderMaestro: () => sdk_default,
|
|
642
|
+
blockchainBitcoin: () => sdk_default$2,
|
|
643
|
+
featureDev: () => sdk_default$3,
|
|
644
|
+
storageInMemory: () => sdk_default$4,
|
|
645
|
+
storageWebIndexeddb: () => sdk_default$5
|
|
646
|
+
});
|
|
647
|
+
//#endregion
|
|
648
|
+
//#region src/bitcoin/bitcoin-lazy-in-memory-signer-factory.ts
|
|
649
|
+
var import_src = /* @__PURE__ */ __toESM(require_src$1(), 1);
|
|
650
|
+
/**
|
|
651
|
+
* Signer factory for {@link WalletType.LazyInMemory} Bitcoin accounts.
|
|
652
|
+
*
|
|
653
|
+
* The seed is never persisted by Lace: each signature asks for the recovery
|
|
654
|
+
* words, derives the seed, and wipes it once signing settles. The words must
|
|
655
|
+
* derive the account's stored extended public keys, regardless of their
|
|
656
|
+
* source, or nothing is signed.
|
|
657
|
+
*
|
|
658
|
+
* Like the Cardano lazy signer, each signature first asks the user to confirm
|
|
659
|
+
* through `auth.authenticate()`. The auth secret is never read, because there
|
|
660
|
+
* is no encrypted seed to open.
|
|
661
|
+
*/
|
|
662
|
+
var BitcoinLazyInMemorySignerFactory = class {
|
|
663
|
+
#withMnemonicWords;
|
|
664
|
+
constructor(props) {
|
|
665
|
+
this.#withMnemonicWords = props.withMnemonicWords;
|
|
666
|
+
}
|
|
667
|
+
canSign(account) {
|
|
668
|
+
return account.accountType === "LazyInMemory" && account.blockchainName === "Bitcoin";
|
|
669
|
+
}
|
|
670
|
+
createTransactionSigner(context) {
|
|
671
|
+
const accountProps = this.#extractAccountProps(context);
|
|
672
|
+
const { auth } = context;
|
|
673
|
+
return { sign: (request) => this.#sign(request, accountProps, auth) };
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Message signing is not offered for lazy Bitcoin accounts.
|
|
677
|
+
*
|
|
678
|
+
* @throws Always.
|
|
679
|
+
*/
|
|
680
|
+
createDataSigner(_context) {
|
|
681
|
+
throw new Error("Data signing is not supported for lazy Bitcoin accounts.");
|
|
682
|
+
}
|
|
683
|
+
#sign(request, accountProps, auth) {
|
|
684
|
+
return auth.authenticate().pipe(switchMap((confirmed) => {
|
|
685
|
+
if (!confirmed) return throwError(() => new AuthenticationCancelledError());
|
|
686
|
+
return this.#signWithWords(request, accountProps);
|
|
687
|
+
}));
|
|
688
|
+
}
|
|
689
|
+
#signWithWords(request, accountProps) {
|
|
690
|
+
return new Observable((subscriber) => {
|
|
691
|
+
const assertActive = () => {
|
|
692
|
+
if (subscriber.closed) throw new Error("Signing request cancelled.");
|
|
693
|
+
};
|
|
694
|
+
this.#withMnemonicWords(async (words) => {
|
|
695
|
+
assertActive();
|
|
696
|
+
const seed = await import_src.mnemonicToSeed(words.join(" "));
|
|
697
|
+
try {
|
|
698
|
+
assertActive();
|
|
699
|
+
const derivedKeys = getExtendedPubKeys(seed, accountProps.accountIndex);
|
|
700
|
+
if (!isEqual(accountProps.network === BitcoinNetwork.Mainnet ? derivedKeys.mainnet : derivedKeys.testnet4, accountProps.extendedAccountPublicKeys)) throw new LazyWalletMismatchError();
|
|
701
|
+
return signBitcoinTransactionWithSeed(request.serializedTx, seed);
|
|
702
|
+
} finally {
|
|
703
|
+
seed.fill(0);
|
|
704
|
+
}
|
|
705
|
+
}).then((result) => {
|
|
706
|
+
if (!subscriber.closed) {
|
|
707
|
+
subscriber.next(result);
|
|
708
|
+
subscriber.complete();
|
|
709
|
+
}
|
|
710
|
+
}, (error) => {
|
|
711
|
+
if (!subscriber.closed) subscriber.error(error);
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
#extractAccountProps(context) {
|
|
716
|
+
const account = context.wallet.accounts.find((a) => a.accountId === context.accountId);
|
|
717
|
+
if (!account || !this.canSign(account)) throw new Error(`BitcoinLazyInMemorySignerFactory does not support account type: ${account?.accountType ?? "unknown"}`);
|
|
718
|
+
const { accountIndex, extendedAccountPublicKeys, networkId } = account.blockchainSpecific;
|
|
719
|
+
const network = BitcoinNetworkId.getBitcoinNetwork(networkId ?? account.blockchainNetworkId);
|
|
720
|
+
if (!network) throw new Error(`Cannot resolve Bitcoin network from networkId: ${String(networkId ?? account.blockchainNetworkId)}`);
|
|
721
|
+
return {
|
|
722
|
+
accountIndex,
|
|
723
|
+
network,
|
|
724
|
+
extendedAccountPublicKeys
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/bitcoin/create-bitcoin-lazy-in-memory-vault-module.ts
|
|
730
|
+
/**
|
|
731
|
+
* Builds a vault module that signs for {@link WalletType.LazyInMemory}
|
|
732
|
+
* Bitcoin accounts by asking `withMnemonicWords` for the recovery words at
|
|
733
|
+
* each signature. The words must derive the account's stored extended public
|
|
734
|
+
* keys, or signing fails with `LazyWalletMismatchError`. The seed derived
|
|
735
|
+
* from the words is wiped once each signature settles. Only transactions are
|
|
736
|
+
* signed: lazy Bitcoin accounts do not sign messages.
|
|
737
|
+
*
|
|
738
|
+
* Pass the returned module to `createLaceWallet({ modules: [...] })`. Only the
|
|
739
|
+
* `signer-factory-addon` contract is implemented, because the SDK has no
|
|
740
|
+
* encrypted vault to expose to features such as account management or
|
|
741
|
+
* password verification.
|
|
742
|
+
*
|
|
743
|
+
* @param props - The source of the recovery words.
|
|
744
|
+
* @returns A module for the `modules` array of `createLaceWallet`.
|
|
745
|
+
*/
|
|
746
|
+
const createBitcoinLazyInMemoryVaultModule = (props) => {
|
|
747
|
+
const signerFactory = new BitcoinLazyInMemorySignerFactory(props);
|
|
748
|
+
const implementsContracts = combineContracts([signerFactoryAddonContract]);
|
|
749
|
+
return inferModuleContext({
|
|
750
|
+
moduleName: ModuleName("bitcoin-lazy-in-memory-vault"),
|
|
751
|
+
implements: implementsContracts,
|
|
752
|
+
addons: { loadSignerFactory: async () => ({ default: () => signerFactory }) }
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region src/bitcoin/resolve-bitcoin-account.ts
|
|
757
|
+
/**
|
|
758
|
+
* Picks the Bitcoin account a transaction is for, among the accounts of
|
|
759
|
+
* `wallets` on the active networks: the requested one, or the only one when
|
|
760
|
+
* none is requested.
|
|
761
|
+
*
|
|
762
|
+
* @param wallets - The wallet entities whose accounts may be picked.
|
|
763
|
+
* @param activeNetworkIds - The networks the wallet is on.
|
|
764
|
+
* @param requestedAccountId - The account asked for, if any.
|
|
765
|
+
* @returns `Ok` with the account and its wallet entity, or `Err` when the
|
|
766
|
+
* requested account is not found, or no account or several accounts match.
|
|
767
|
+
*/
|
|
768
|
+
const resolveBitcoinAccount = (wallets, activeNetworkIds, requestedAccountId) => {
|
|
769
|
+
const bitcoinAccounts = wallets.flatMap((walletEntity) => walletEntity.accounts.filter((account) => account.blockchainName === "Bitcoin" && activeNetworkIds.includes(account.blockchainNetworkId)).map((account) => ({
|
|
770
|
+
account,
|
|
771
|
+
walletEntity
|
|
772
|
+
})));
|
|
773
|
+
if (requestedAccountId) {
|
|
774
|
+
const found = bitcoinAccounts.find(({ account }) => account.accountId === requestedAccountId);
|
|
775
|
+
return found ? Ok(found) : Err(/* @__PURE__ */ new Error(`Bitcoin account "${requestedAccountId}" not found on the active network`));
|
|
776
|
+
}
|
|
777
|
+
if (bitcoinAccounts.length === 0) return Err(/* @__PURE__ */ new Error("No Bitcoin accounts found on the active network"));
|
|
778
|
+
if (bitcoinAccounts.length > 1) return Err(/* @__PURE__ */ new Error(`Multiple Bitcoin accounts found (${bitcoinAccounts.length}): specify accountId to disambiguate`));
|
|
779
|
+
return Ok(bitcoinAccounts[0]);
|
|
780
|
+
};
|
|
781
|
+
/**
|
|
782
|
+
* Picks the Bitcoin account a transaction is for from the wallet's current
|
|
783
|
+
* state, by the rules of {@link resolveBitcoinAccount}.
|
|
784
|
+
*
|
|
785
|
+
* @param stateObservables - The wallet's wallets and networks.
|
|
786
|
+
* @param requestedAccountId - The account asked for, if any.
|
|
787
|
+
* @returns `Ok` with the account id, or `Err` when no single account matches.
|
|
788
|
+
*/
|
|
789
|
+
const resolveBitcoinAccountId = async (stateObservables, requestedAccountId) => {
|
|
790
|
+
const resolved = resolveBitcoinAccount(await firstValueFrom(stateObservables.wallets.selectAll$), await firstValueFrom(stateObservables.network.selectAllActiveNetworkIds$), requestedAccountId);
|
|
791
|
+
return resolved.isErr() ? Err(resolved.error) : Ok(resolved.value.account.accountId);
|
|
792
|
+
};
|
|
793
|
+
/**
|
|
794
|
+
* Finds the Bitcoin wallet that syncs an account. Every wallet in a
|
|
795
|
+
* JavaScript realm registers its accounts in one shared registry, so an
|
|
796
|
+
* account must be loaded by at most one wallet per realm.
|
|
797
|
+
*
|
|
798
|
+
* @param accountId - The account to find.
|
|
799
|
+
* @returns `Ok` with the account's Bitcoin wallet, or `Err` when the account
|
|
800
|
+
* has not started syncing yet.
|
|
801
|
+
*/
|
|
802
|
+
const findBitcoinAccountWallet = (accountId) => {
|
|
803
|
+
const accountWallet = bitcoinAccountWallets$.value[accountId];
|
|
804
|
+
return accountWallet ? Ok(accountWallet) : Err(/* @__PURE__ */ new Error(`Bitcoin account "${accountId}" has not started syncing yet`));
|
|
805
|
+
};
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region src/bitcoin/build-bitcoin-tx.ts
|
|
808
|
+
const isPositiveSatoshiAmount = (amount) => Number.isSafeInteger(amount) && amount > 0;
|
|
809
|
+
const validateRecipients = (recipients) => {
|
|
810
|
+
if (recipients.length === 0) return Err(/* @__PURE__ */ new Error("At least one recipient is required"));
|
|
811
|
+
const invalid = recipients.find(({ amount }) => !isPositiveSatoshiAmount(amount));
|
|
812
|
+
if (invalid) return Err(/* @__PURE__ */ new Error(`Invalid amount ${invalid.amount} for ${invalid.address}: amounts are positive whole numbers of satoshis`));
|
|
813
|
+
const dust = recipients.find(({ amount }) => amount < 546);
|
|
814
|
+
return dust ? Err(/* @__PURE__ */ new Error(`Amount ${dust.amount} for ${dust.address} is below the dust limit of 546 satoshis`)) : Ok(void 0);
|
|
815
|
+
};
|
|
816
|
+
const toPaymentFeeRate = (feeRate) => {
|
|
817
|
+
if (feeRate.feeOption !== "Custom") return Ok(feeRate);
|
|
818
|
+
const customFeeRate = feeRateFromSatsPerVByte(feeRate.satsPerVByte);
|
|
819
|
+
return customFeeRate === void 0 ? Err(/* @__PURE__ */ new Error(`Invalid fee rate ${feeRate.satsPerVByte}: custom rates are positive numbers of satoshis per virtual byte, at most 10,000`)) : Ok({
|
|
820
|
+
feeOption: "Custom",
|
|
821
|
+
customFeeRate
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Builds an unsigned Bitcoin payment from the account's synced UTxOs. Outputs
|
|
826
|
+
* spent by the account's pending transactions are not spent again, and the
|
|
827
|
+
* change goes back to the account. The account is `props.accountId`, or the
|
|
828
|
+
* only Bitcoin account on the active network.
|
|
829
|
+
*
|
|
830
|
+
* The account must have synced first: await
|
|
831
|
+
* {@link waitForBitcoinAccountSync} after adding the wallet. A Bitcoin
|
|
832
|
+
* account must be loaded by at most one wallet per JavaScript realm, since
|
|
833
|
+
* the account's synced state is shared across the realm by account id.
|
|
834
|
+
*
|
|
835
|
+
* @param wallet - A wallet holding the paying account (see
|
|
836
|
+
* {@link WalletWithBitcoinTxBuilding}).
|
|
837
|
+
* @param props - The recipients, with amounts in satoshis, the fee rate, and
|
|
838
|
+
* the account and memo when needed.
|
|
839
|
+
* @returns `Ok` with the unsigned transaction and its fee, or `Err` when an
|
|
840
|
+
* amount is not a positive whole number of satoshis or is below the dust
|
|
841
|
+
* limit of 546 satoshis, a custom fee rate is out of range, no account
|
|
842
|
+
* matches, the account has not started syncing, or the payment cannot be
|
|
843
|
+
* built, for example when the funds do not cover it. It never rejects.
|
|
844
|
+
*/
|
|
845
|
+
const buildBitcoinTx = async (wallet, props) => {
|
|
846
|
+
const { accountId: requestedAccountId, recipients, feeRate, memo } = props;
|
|
847
|
+
try {
|
|
848
|
+
const validRecipients = validateRecipients(recipients);
|
|
849
|
+
if (validRecipients.isErr()) return Err(validRecipients.error);
|
|
850
|
+
const paymentFeeRate = toPaymentFeeRate(feeRate);
|
|
851
|
+
if (paymentFeeRate.isErr()) return Err(paymentFeeRate.error);
|
|
852
|
+
const accountId = await resolveBitcoinAccountId(wallet.stateObservables, requestedAccountId);
|
|
853
|
+
if (accountId.isErr()) return Err(accountId.error);
|
|
854
|
+
const accountWallet = findBitcoinAccountWallet(accountId.value);
|
|
855
|
+
if (accountWallet.isErr()) return Err(accountWallet.error);
|
|
856
|
+
const pendingActivities = await firstValueFrom(wallet.stateObservables.activities.selectPendingActivitiesByAccount$);
|
|
857
|
+
const { serializedTx, fee } = await buildBitcoinPayment({
|
|
858
|
+
wallet: accountWallet.value,
|
|
859
|
+
pendingActivities: pendingActivities[accountId.value] ?? [],
|
|
860
|
+
outputs: recipients,
|
|
861
|
+
feeRate: paymentFeeRate.value,
|
|
862
|
+
memo
|
|
863
|
+
});
|
|
864
|
+
return Ok({
|
|
865
|
+
serializedTx,
|
|
866
|
+
fee
|
|
867
|
+
});
|
|
868
|
+
} catch (error) {
|
|
869
|
+
return Err(error instanceof Error ? error : new Error(String(error)));
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
/**
|
|
873
|
+
* Returns a promise that resolves once a Bitcoin account is on the active
|
|
874
|
+
* network and has synced its UTxOs with the provider. Await it after adding
|
|
875
|
+
* a wallet, before {@link buildBitcoinTx}, so the build sees the account's
|
|
876
|
+
* funds. A Bitcoin account must be loaded by at most one wallet per
|
|
877
|
+
* JavaScript realm: with two, the promise may resolve on the other wallet's
|
|
878
|
+
* sync.
|
|
879
|
+
*
|
|
880
|
+
* @param wallet - A wallet holding the account (see
|
|
881
|
+
* {@link WalletWithBitcoinTxBuilding}).
|
|
882
|
+
* @param options - Optional configuration.
|
|
883
|
+
* @returns A promise that resolves once the account has synced.
|
|
884
|
+
* @throws A `TimeoutError` when the account has not synced within
|
|
885
|
+
* `options.timeout`.
|
|
886
|
+
*/
|
|
887
|
+
const waitForBitcoinAccountSync = async (wallet, options) => {
|
|
888
|
+
const { wallets, network } = wallet.stateObservables;
|
|
889
|
+
await firstValueFrom(combineLatest([wallets.selectAll$, network.selectAllActiveNetworkIds$]).pipe(map(([allWallets, activeNetworkIds]) => resolveBitcoinAccount(allWallets, activeNetworkIds, options?.accountId)), filter((resolved) => resolved.isOk()), map((resolved) => resolved.unwrap().account.accountId), take(1), switchMap((accountId) => bitcoinAccountWallets$.pipe(map((accountWallets) => accountWallets[accountId]))), filter((accountWallet) => !!accountWallet), switchMap((accountWallet) => accountWallet.syncStatus$), filter(({ status }) => status === SyncStatus.Synced), options?.timeout != null ? timeout({ first: options.timeout }) : passthrough()));
|
|
890
|
+
};
|
|
891
|
+
const passthrough = () => (source$) => source$;
|
|
892
|
+
//#endregion
|
|
893
|
+
//#region src/bitcoin/sign-bitcoin-tx.ts
|
|
894
|
+
const isSignableBitcoinWallet = (wallet) => wallet.type === WalletType.InMemory || wallet.type === WalletType.LazyInMemory;
|
|
895
|
+
/**
|
|
896
|
+
* Signs a Bitcoin transaction with the wallet's keys, through the signer of
|
|
897
|
+
* its wallet kind, with no confirmation prompt of the SDK's own: confirm with
|
|
898
|
+
* the user before calling it. The account is `props.accountId`, or the only
|
|
899
|
+
* signable Bitcoin account on the active network. A `LazyInMemory` account
|
|
900
|
+
* signs through the vault module of `createBitcoinLazyInMemoryVaultModule`.
|
|
901
|
+
*
|
|
902
|
+
* @param wallet - A wallet holding the signing account (see
|
|
903
|
+
* {@link WalletWithBitcoinSigning}).
|
|
904
|
+
* @param props - The unsigned transaction from `buildBitcoinTx`, and the
|
|
905
|
+
* password and account when needed.
|
|
906
|
+
* @returns `Ok` with the signed transaction, ready for `submitBitcoinTx`, or
|
|
907
|
+
* `Err` when no account matches, the password is missing or signing fails.
|
|
908
|
+
* It never rejects.
|
|
909
|
+
*/
|
|
910
|
+
const signBitcoinTx = async (wallet, props) => {
|
|
911
|
+
const { serializedTx, password, accountId: requestedAccountId } = props;
|
|
912
|
+
try {
|
|
913
|
+
const { stateObservables: obs } = wallet;
|
|
914
|
+
const allWallets = await firstValueFrom(obs.wallets.selectAll$);
|
|
915
|
+
const activeNetworkIds = await firstValueFrom(obs.network.selectAllActiveNetworkIds$);
|
|
916
|
+
const resolved = resolveBitcoinAccount(allWallets.filter(isSignableBitcoinWallet), activeNetworkIds, requestedAccountId);
|
|
917
|
+
if (resolved.isErr()) return Err(resolved.error);
|
|
918
|
+
const { account, walletEntity } = resolved.value;
|
|
919
|
+
if (walletEntity.type === WalletType.InMemory && !password) return Err(/* @__PURE__ */ new Error("password is required for InMemory wallets: supply props.password or use a LazyInMemory wallet"));
|
|
920
|
+
const auth = {
|
|
921
|
+
authenticate: () => of(true),
|
|
922
|
+
accessAuthSecret: (callback) => password ? callback(AuthSecret(ByteArray(password))) : throwError(() => /* @__PURE__ */ new Error("accessAuthSecret called on a wallet that has no password: this is a LazyInMemory wallet; signer factories must not access the auth secret"))
|
|
923
|
+
};
|
|
924
|
+
const signerFactory = new CompositeSignerFactory(await wallet._loadModules("addons.loadSignerFactory"));
|
|
925
|
+
const context = {
|
|
926
|
+
wallet: walletEntity,
|
|
927
|
+
accountId: account.accountId,
|
|
928
|
+
auth
|
|
929
|
+
};
|
|
930
|
+
return Ok(await firstValueFrom(signerFactory.createTransactionSigner(context).sign({ serializedTx: HexBytes(serializedTx) })));
|
|
931
|
+
} catch (error) {
|
|
932
|
+
return Err(error instanceof Error ? error : new Error(String(error)));
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region src/bitcoin/submit-bitcoin-tx.ts
|
|
937
|
+
const SUBMIT_TX_TIMEOUT_MS = 6e4;
|
|
938
|
+
const isBitcoinNetwork = (network) => Object.values(BitcoinNetwork).includes(network);
|
|
939
|
+
const decodeSignedTx = (serializedTx) => {
|
|
940
|
+
const payload = JSON.parse(HexBytes.toUTF8(HexBytes(serializedTx)));
|
|
941
|
+
if (typeof payload?.hex !== "string" || !isBitcoinNetwork(payload.network)) throw new Error("Not a signed Bitcoin transaction");
|
|
942
|
+
return {
|
|
943
|
+
network: payload.network,
|
|
944
|
+
hex: payload.hex
|
|
945
|
+
};
|
|
946
|
+
};
|
|
947
|
+
/**
|
|
948
|
+
* Submits a signed transaction through the account's Bitcoin wallet, which
|
|
949
|
+
* adds it to the account's pending transactions once the provider accepts it,
|
|
950
|
+
* and waits up to 60 seconds for the provider's answer. The account is
|
|
951
|
+
* `props.accountId`, or the only Bitcoin account on the active network. A
|
|
952
|
+
* Bitcoin account must be loaded by at most one wallet per JavaScript realm,
|
|
953
|
+
* since the account's pending transactions are shared across the realm by
|
|
954
|
+
* account id.
|
|
955
|
+
*
|
|
956
|
+
* @param wallet - A wallet with the Bitcoin modules loaded (see
|
|
957
|
+
* {@link WalletWithBitcoinSubmit}).
|
|
958
|
+
* @param props - The signed transaction, and the account when needed.
|
|
959
|
+
* @returns `Ok` with the transaction ID once the provider accepts it, or
|
|
960
|
+
* `Err` when no account matches, the account has not started syncing, the
|
|
961
|
+
* transaction is for another network, the provider refuses it or the wait
|
|
962
|
+
* times out. It never rejects.
|
|
963
|
+
*/
|
|
964
|
+
const submitBitcoinTx = async (wallet, props) => {
|
|
965
|
+
const { serializedTx, accountId: requestedAccountId } = props;
|
|
966
|
+
try {
|
|
967
|
+
const { network, hex } = decodeSignedTx(serializedTx);
|
|
968
|
+
const resolved = await resolveBitcoinAccountId(wallet.stateObservables, requestedAccountId);
|
|
969
|
+
if (resolved.isErr()) return Err(resolved.error);
|
|
970
|
+
const accountId = resolved.value;
|
|
971
|
+
const foundWallet = findBitcoinAccountWallet(accountId);
|
|
972
|
+
if (foundWallet.isErr()) return Err(foundWallet.error);
|
|
973
|
+
const accountWallet = foundWallet.value;
|
|
974
|
+
if (accountWallet.network !== network) return Err(/* @__PURE__ */ new Error(`The transaction is for the Bitcoin ${network} network, but account "${accountId}" is on ${accountWallet.network}`));
|
|
975
|
+
const result = await firstValueFrom(accountWallet.submitTransaction(hex).pipe(timeout(SUBMIT_TX_TIMEOUT_MS)));
|
|
976
|
+
if (result.isErr()) return Err(new Error(`Transaction submission failed: ${result.error.reason}`, { cause: result.error }));
|
|
977
|
+
return Ok({ txId: result.value });
|
|
978
|
+
} catch (error) {
|
|
979
|
+
return Err(error instanceof Error ? error : new Error(String(error)));
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
//#endregion
|
|
983
|
+
export { createBitcoinLazyInMemoryVaultModule as a, sdk_default$1 as c, BitcoinTxBuildErrorCode as d, waitForBitcoinAccountSync as i, sdk_default$2 as l, signBitcoinTx as n, modules_exports as o, buildBitcoinTx as r, sdk_default as s, submitBitcoinTx as t, BitcoinTxBuildError as u };
|