@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.
- package/dist/{TransactionBuilder-DrB3NVTi.cjs → TransactionBuilder-CCjOn7NA.cjs} +42 -0
- package/dist/{TransactionBuilder-V6aLx4SV.js → TransactionBuilder-CIzdw18M.js} +1 -1
- 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 +16956 -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-CCjiakoy.cjs} +6 -6
- package/dist/{delegation-tx-builder-CGVqlaFE.js → delegation-tx-builder-DZFjHDS8.js} +5 -5
- package/dist/{deregistration-tx-builder-B-CrUyX6.js → deregistration-tx-builder-Bf6xAYp4.js} +5 -5
- package/dist/{deregistration-tx-builder-DZGwB4cz.cjs → deregistration-tx-builder-CQP35yex.cjs} +6 -6
- 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-BDbTDZmD.js → earn-rewards-tx-builder-Bsga3yFb.js} +5 -5
- package/dist/{earn-rewards-tx-builder-D5sUT5v8.cjs → earn-rewards-tx-builder-GuxofYns.cjs} +6 -6
- 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 +86273 -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 +37496 -10033
- 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-8v_n8boO.js +1177 -0
- 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-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-CuW7rHNA.js +3584 -0
- package/dist/{init-CFYsq82V.js → init-CyAY4Lzl.js} +1 -1
- package/dist/init-Cz0rz5fU.cjs +3585 -0
- 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-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-DrRdf5sZ.cjs +1176 -0
- 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-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-B1nDUWqy.js +995 -0
- package/dist/modules-cardano-BYeYHrRm.cjs +1108 -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-BpEMSti4.cjs → vote-delegation-tx-builder-BUg1S2Ep.cjs} +6 -6
- package/dist/{vote-delegation-tx-builder-CmKv6GoG.js → vote-delegation-tx-builder-C6FiS7zI.js} +5 -5
- 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,3452 @@
|
|
|
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
|
+
let rxjs = require("rxjs");
|
|
7
|
+
rxjs = require_rolldown_runtime.__toESM(rxjs);
|
|
8
|
+
let _midnight_ntwrk_ledger_v8 = require("@midnight-ntwrk/ledger-v8");
|
|
9
|
+
_midnight_ntwrk_ledger_v8 = require_rolldown_runtime.__toESM(_midnight_ntwrk_ledger_v8);
|
|
10
|
+
let _midnightntwrk_ledger_v9 = require("@midnightntwrk/ledger-v9");
|
|
11
|
+
_midnightntwrk_ledger_v9 = require_rolldown_runtime.__toESM(_midnightntwrk_ledger_v9);
|
|
12
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/ShieldedWalletAPI.js
|
|
13
|
+
var ShieldedWalletState = class ShieldedWalletState {
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a state emission with the capabilities of the variant that produced it.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Call this inside a branch that has narrowed on the emission's `variantTag`, so `variant` and `state` are known to
|
|
19
|
+
* belong together. It is generic over the state type precisely so that pairing is checked.
|
|
20
|
+
*/
|
|
21
|
+
static fromVariant = (variant, state) => new ShieldedWalletState(state.version, state.state, {
|
|
22
|
+
balances: () => variant.coinsAndBalances.getAvailableBalances(state.state),
|
|
23
|
+
totalCoins: () => variant.coinsAndBalances.getTotalCoins(state.state),
|
|
24
|
+
availableCoins: () => variant.coinsAndBalances.getAvailableCoins(state.state),
|
|
25
|
+
pendingCoins: () => variant.coinsAndBalances.getPendingCoins(state.state),
|
|
26
|
+
coinPublicKey: () => variant.keys.getCoinPublicKey(state.state),
|
|
27
|
+
encryptionPublicKey: () => variant.keys.getEncryptionPublicKey(state.state),
|
|
28
|
+
address: () => variant.keys.getAddress(state.state),
|
|
29
|
+
serialize: () => variant.serialization.serialize(state.state)
|
|
30
|
+
});
|
|
31
|
+
protocolVersion;
|
|
32
|
+
state;
|
|
33
|
+
#projections;
|
|
34
|
+
get balances() {
|
|
35
|
+
return this.#projections.balances();
|
|
36
|
+
}
|
|
37
|
+
get totalCoins() {
|
|
38
|
+
return this.#projections.totalCoins();
|
|
39
|
+
}
|
|
40
|
+
get availableCoins() {
|
|
41
|
+
return this.#projections.availableCoins();
|
|
42
|
+
}
|
|
43
|
+
get pendingCoins() {
|
|
44
|
+
return this.#projections.pendingCoins();
|
|
45
|
+
}
|
|
46
|
+
get coinPublicKey() {
|
|
47
|
+
return this.#projections.coinPublicKey();
|
|
48
|
+
}
|
|
49
|
+
get encryptionPublicKey() {
|
|
50
|
+
return this.#projections.encryptionPublicKey();
|
|
51
|
+
}
|
|
52
|
+
get address() {
|
|
53
|
+
return this.#projections.address();
|
|
54
|
+
}
|
|
55
|
+
get progress() {
|
|
56
|
+
return this.state.progress;
|
|
57
|
+
}
|
|
58
|
+
constructor(protocolVersion, state, projections) {
|
|
59
|
+
this.protocolVersion = protocolVersion;
|
|
60
|
+
this.state = state;
|
|
61
|
+
this.#projections = projections;
|
|
62
|
+
}
|
|
63
|
+
serialize() {
|
|
64
|
+
return this.#projections.serialize();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The protocol version a ledger-v9-native chain hands over at.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated Use {@link ProtocolVersion.V9NativeForkVersion} from `@midnightntwrk/wallet-sdk-abstractions` (or the
|
|
71
|
+
* umbrella package) — the value is a property of the chain, not of the shielded wallet, and lives with the version
|
|
72
|
+
* type now. This alias is the same value and will be removed in a later release.
|
|
73
|
+
*/
|
|
74
|
+
const V9_NATIVE_FORK_VERSION = require_dist.V9NativeForkVersion;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/Restore.js
|
|
77
|
+
var Restore_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
78
|
+
UnsupportedSnapshotVersionError: () => UnsupportedSnapshotVersionError,
|
|
79
|
+
peekProtocolVersion: () => peekProtocolVersion,
|
|
80
|
+
variantForSnapshot: () => variantForSnapshot
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* Raised when a snapshot declares a protocol version that no registered variant is able to read.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* A wallet built for one range of protocol versions cannot invent a reader for a snapshot written outside it, and
|
|
87
|
+
* guessing — handing the bytes to whichever variant happens to be registered — would decode them with the wrong
|
|
88
|
+
* ledger. The version is carried on the error so an application can say which one it was.
|
|
89
|
+
*/
|
|
90
|
+
var UnsupportedSnapshotVersionError = class extends require_dist.TaggedError("@midnightntwrk/wallet-sdk-shielded/Restore/UnsupportedSnapshotVersionError") {};
|
|
91
|
+
/**
|
|
92
|
+
* The envelope the peek reads.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* Deliberately the smallest possible description of a snapshot: one optional field, every other ignored. It has to read
|
|
96
|
+
* snapshots written by _any_ variant, including ones whose full schema this build does not have, so it must not
|
|
97
|
+
* assert anything it does not need. Everything it cannot make sense of is reported as "no version declared", leaving
|
|
98
|
+
* the real diagnosis to the deserializer that eventually reads the whole thing.
|
|
99
|
+
*/
|
|
100
|
+
const EnvelopeSchema = require_dist.Struct({ protocolVersion: require_dist.optional(require_dist.ProtocolVersionSchema) });
|
|
101
|
+
/**
|
|
102
|
+
* Reads the protocol version a serialized wallet snapshot declares.
|
|
103
|
+
*
|
|
104
|
+
* @param serialized The serialized wallet state.
|
|
105
|
+
* @returns The declared version, or `Option.none()` when the snapshot declares none or cannot be read at all.
|
|
106
|
+
*/
|
|
107
|
+
const peekProtocolVersion = (serialized) => require_dist.decodeUnknownOption(require_dist.parseJson(EnvelopeSchema))(serialized).pipe(require_dist.flatMap$3((envelope) => require_dist.fromNullable(envelope.protocolVersion)));
|
|
108
|
+
/**
|
|
109
|
+
* Chooses the variant that should read a serialized wallet snapshot.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* A snapshot that declares no version predates snapshots declaring one, and can only have been written by the variant
|
|
113
|
+
* that shipped before the question arose — the head variant. The same fallback covers an envelope this function
|
|
114
|
+
* cannot read at all: refusing it here would replace the deserializer's precise error with a vaguer one.
|
|
115
|
+
* @param serialized The serialized wallet state.
|
|
116
|
+
* @param variantFor Resolves the variant registered for a protocol version.
|
|
117
|
+
* @param headVariant The variant a snapshot with no declared version is restored into.
|
|
118
|
+
* @returns The variant to restore with, or {@link UnsupportedSnapshotVersionError} when the declared version is one no
|
|
119
|
+
* registered variant owns.
|
|
120
|
+
*/
|
|
121
|
+
const variantForSnapshot = (serialized, variantFor, headVariant) => require_dist.match$1(peekProtocolVersion(serialized), {
|
|
122
|
+
onNone: () => require_dist.right(headVariant),
|
|
123
|
+
onSome: (protocolVersion) => require_dist.fromOption(variantFor(protocolVersion), () => new UnsupportedSnapshotVersionError({
|
|
124
|
+
message: `No registered variant reads shielded wallet snapshots of protocol version ${protocolVersion}.`,
|
|
125
|
+
protocolVersion
|
|
126
|
+
}))
|
|
127
|
+
});
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/WalletError.js
|
|
130
|
+
const WalletError$1 = {
|
|
131
|
+
other(err) {
|
|
132
|
+
let message;
|
|
133
|
+
if (err) if (typeof err == "object" && "message" in err) message = String(err.message);
|
|
134
|
+
else if (typeof err == "string") message = err;
|
|
135
|
+
else message = "";
|
|
136
|
+
else message = "";
|
|
137
|
+
return new OtherWalletError$1({
|
|
138
|
+
message: `Other wallet error: ${message}`,
|
|
139
|
+
cause: err
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
submission(err) {
|
|
143
|
+
return new SubmissionError$1({
|
|
144
|
+
message: `Transaction submission error: ${err && typeof err == "object" && "message" in err ? String(err.message) : ""}`,
|
|
145
|
+
cause: err
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var OtherWalletError$1 = class extends require_dist.TaggedError("Wallet.Other") {};
|
|
150
|
+
var SyncWalletError$1 = class extends require_dist.TaggedError("Wallet.Sync") {};
|
|
151
|
+
var SubmissionError$1 = class extends require_dist.TaggedError("Wallet.SubmissionWalletError") {};
|
|
152
|
+
var InsufficientFundsError$1 = class extends require_dist.TaggedError("Wallet.InsufficientFunds") {};
|
|
153
|
+
var InvalidCoinHashesError$1 = class extends require_dist.TaggedError("Wallet.InvalidCoinHashes") {};
|
|
154
|
+
var TransactionHistoryError$1 = class extends require_dist.TaggedError("Wallet.TransactionHistory") {};
|
|
155
|
+
/**
|
|
156
|
+
* A batch of zswap ledger events was not in ascending id order: an event arrived at or below the one before it, or at
|
|
157
|
+
* or below the applied cursor.
|
|
158
|
+
*
|
|
159
|
+
* @remarks
|
|
160
|
+
* Order is all the wallet can check: zswap events share one id sequence with dust and contract events in the indexer,
|
|
161
|
+
* so gaps in the stream are normal and a skipped event is only ever caught by the ledger's own insertion check. The
|
|
162
|
+
* whole batch is refused, nothing is applied and the cursor stays, so the running variant retries from the same
|
|
163
|
+
* place.
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* if (error._tag === 'Wallet.OutOfOrderSyncUpdate') console.warn(`expected above ${error.expected}, got ${error.received}`);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
var OutOfOrderSyncUpdateError$1 = class extends require_dist.TaggedError("Wallet.OutOfOrderSyncUpdate") {};
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/CoreWallet.js
|
|
172
|
+
const PublicKeys$1 = { fromSecretKeys: (secretKeys) => {
|
|
173
|
+
return {
|
|
174
|
+
coinPublicKey: secretKeys.coinPublicKey,
|
|
175
|
+
encryptionPublicKey: secretKeys.encryptionPublicKey
|
|
176
|
+
};
|
|
177
|
+
} };
|
|
178
|
+
const CoinHashesMap$1 = {
|
|
179
|
+
empty: {},
|
|
180
|
+
pickAllCoins(state) {
|
|
181
|
+
return [...state.coins, ...state.pendingOutputs.values().map(([coin]) => coin)];
|
|
182
|
+
},
|
|
183
|
+
assertValid(map$8, state) {
|
|
184
|
+
const coins = CoinHashesMap$1.pickAllCoins(state);
|
|
185
|
+
const coinNonces = new Set(require_dist.map$4(coins, (coin) => coin.nonce));
|
|
186
|
+
const definedNonces = new Set(Object.keys(map$8));
|
|
187
|
+
const missingNonces = coinNonces.difference(definedNonces);
|
|
188
|
+
return missingNonces.size === 0 ? require_dist.void_ : require_dist.left(missingNonces);
|
|
189
|
+
},
|
|
190
|
+
updateWithCoins(secretKeys, existing, coins) {
|
|
191
|
+
return require_dist.fromIterableWith(coins, (coin) => [coin.nonce, existing[coin.nonce] ?? {
|
|
192
|
+
commitment: _midnightntwrk_ledger_v9.coinCommitment(coin, secretKeys.coinPublicKey),
|
|
193
|
+
nullifier: _midnightntwrk_ledger_v9.coinNullifier(coin, secretKeys.coinSecretKey)
|
|
194
|
+
}]);
|
|
195
|
+
},
|
|
196
|
+
updateWithNewCoins(secretKeys, existing, coins) {
|
|
197
|
+
const newMap = CoinHashesMap$1.updateWithCoins(secretKeys, CoinHashesMap$1.empty, coins);
|
|
198
|
+
return require_dist.union$2(existing, newMap, (a) => a);
|
|
199
|
+
},
|
|
200
|
+
init(secretKeys, coins) {
|
|
201
|
+
return CoinHashesMap$1.updateWithCoins(secretKeys, {}, coins);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Releases every coin reservation a wallet carried across the ledger-version boundary.
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* `pendingSpends` crosses with the rest of the local state, and on the far side its entries name transactions of a
|
|
209
|
+
* ledger version the chain has left behind: none of them can be included, so no inclusion will ever clear them, and a
|
|
210
|
+
* coin held for one would sit outside the available set for the rest of the wallet's life. Re-deriving each spend and
|
|
211
|
+
* reporting it failed is the ledger's own way of un-booking one: the reservation goes, and the coin stays at the
|
|
212
|
+
* Merkle index the chain gave it, in a tree of unchanged height and root.
|
|
213
|
+
* @param state The local state as it crossed.
|
|
214
|
+
* @param secretKeys The keys the first sync update arrived with.
|
|
215
|
+
* @returns The same state with nothing reserved.
|
|
216
|
+
*/
|
|
217
|
+
const releaseStrandedSpends = (state, secretKeys) => require_dist.pipe([...state.pendingSpends.values()], require_dist.reduce(state, (released, [coin]) => require_dist.pipe(require_dist.ledgerTry(() => {
|
|
218
|
+
const [reserved, input] = released.spend(secretKeys, coin, 0);
|
|
219
|
+
return reserved.applyFailed(_midnightntwrk_ledger_v9.ZswapOffer.fromInput(input, coin.type, coin.value));
|
|
220
|
+
}), require_dist.getOrElse$1(() => released))));
|
|
221
|
+
const CoreWallet$1 = {
|
|
222
|
+
init(localState, secretKeys, networkId) {
|
|
223
|
+
return {
|
|
224
|
+
state: localState,
|
|
225
|
+
publicKeys: PublicKeys$1.fromSecretKeys(secretKeys),
|
|
226
|
+
networkId,
|
|
227
|
+
coinHashes: CoinHashesMap$1.init(secretKeys, CoinHashesMap$1.pickAllCoins(localState)),
|
|
228
|
+
progress: require_dist.createSyncProgress(),
|
|
229
|
+
protocolVersion: require_dist.MinSupportedVersion
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
empty(publicKeys, networkId) {
|
|
233
|
+
return {
|
|
234
|
+
state: new _midnightntwrk_ledger_v9.ZswapLocalState(),
|
|
235
|
+
publicKeys,
|
|
236
|
+
networkId,
|
|
237
|
+
coinHashes: CoinHashesMap$1.empty,
|
|
238
|
+
progress: require_dist.createSyncProgress(),
|
|
239
|
+
protocolVersion: require_dist.MinSupportedVersion
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
restore(localState, secretKeys, syncProgress, protocolVersion, networkId) {
|
|
243
|
+
return {
|
|
244
|
+
state: localState,
|
|
245
|
+
publicKeys: PublicKeys$1.fromSecretKeys(secretKeys),
|
|
246
|
+
networkId,
|
|
247
|
+
coinHashes: CoinHashesMap$1.init(secretKeys, CoinHashesMap$1.pickAllCoins(localState)),
|
|
248
|
+
progress: require_dist.createSyncProgress(syncProgress),
|
|
249
|
+
protocolVersion: require_dist.ProtocolVersion(protocolVersion)
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
restoreWithCoinHashes(publicKeys, localState, coinHashes, syncProgress, protocolVersion, networkId) {
|
|
253
|
+
return CoinHashesMap$1.assertValid(coinHashes, localState).pipe(require_dist.mapBoth({
|
|
254
|
+
onLeft: (missingNonces) => new InvalidCoinHashesError$1({
|
|
255
|
+
message: "Missing coin hashes for coins present in the state",
|
|
256
|
+
missingNonces
|
|
257
|
+
}),
|
|
258
|
+
onRight: () => ({
|
|
259
|
+
state: localState,
|
|
260
|
+
publicKeys,
|
|
261
|
+
networkId,
|
|
262
|
+
coinHashes,
|
|
263
|
+
progress: require_dist.createSyncProgress(syncProgress),
|
|
264
|
+
protocolVersion: require_dist.ProtocolVersion(protocolVersion)
|
|
265
|
+
})
|
|
266
|
+
}));
|
|
267
|
+
},
|
|
268
|
+
restoreWithPendingCoinHashes(publicKeys, localState, syncProgress, protocolVersion, networkId) {
|
|
269
|
+
return {
|
|
270
|
+
state: localState,
|
|
271
|
+
publicKeys,
|
|
272
|
+
networkId,
|
|
273
|
+
coinHashes: CoinHashesMap$1.empty,
|
|
274
|
+
coinHashesPending: true,
|
|
275
|
+
progress: require_dist.createSyncProgress(syncProgress),
|
|
276
|
+
protocolVersion: require_dist.ProtocolVersion(protocolVersion)
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
initEmpty(keys, networkId) {
|
|
280
|
+
return this.empty(PublicKeys$1.fromSecretKeys(keys), networkId);
|
|
281
|
+
},
|
|
282
|
+
withProtocolVersion(wallet, version) {
|
|
283
|
+
return version > wallet.protocolVersion ? {
|
|
284
|
+
...wallet,
|
|
285
|
+
protocolVersion: version
|
|
286
|
+
} : wallet;
|
|
287
|
+
},
|
|
288
|
+
fromPreviousVersion(previous) {
|
|
289
|
+
return {
|
|
290
|
+
state: previous.state,
|
|
291
|
+
publicKeys: previous.publicKeys,
|
|
292
|
+
networkId: previous.networkId,
|
|
293
|
+
coinHashes: CoinHashesMap$1.empty,
|
|
294
|
+
coinHashesPending: true,
|
|
295
|
+
progress: require_dist.createSyncProgress({
|
|
296
|
+
...previous.progress,
|
|
297
|
+
isConnected: false
|
|
298
|
+
}),
|
|
299
|
+
protocolVersion: require_dist.ProtocolVersion(previous.protocolVersion)
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
completeCrossing(wallet, secretKeys) {
|
|
303
|
+
return wallet.coinHashesPending === void 0 ? wallet : CoreWallet$1.resolveCoinHashes({
|
|
304
|
+
...wallet,
|
|
305
|
+
state: releaseStrandedSpends(wallet.state, secretKeys)
|
|
306
|
+
}, secretKeys);
|
|
307
|
+
},
|
|
308
|
+
resolveCoinHashes(wallet, secretKeys) {
|
|
309
|
+
return wallet.coinHashesPending === void 0 ? wallet : {
|
|
310
|
+
state: wallet.state,
|
|
311
|
+
publicKeys: wallet.publicKeys,
|
|
312
|
+
networkId: wallet.networkId,
|
|
313
|
+
coinHashes: CoinHashesMap$1.init(secretKeys, CoinHashesMap$1.pickAllCoins(wallet.state)),
|
|
314
|
+
progress: wallet.progress,
|
|
315
|
+
protocolVersion: wallet.protocolVersion
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
applyCollapsedUpdate(wallet, collapsed) {
|
|
319
|
+
const newState = wallet.state.applyCollapsedUpdate(collapsed);
|
|
320
|
+
return {
|
|
321
|
+
...wallet,
|
|
322
|
+
state: newState
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
apply(wallet, secretKeys, offer) {
|
|
326
|
+
const newState = wallet.state.apply(secretKeys, offer);
|
|
327
|
+
const newCoinHashes = CoinHashesMap$1.updateWithCoins(secretKeys, wallet.coinHashes, CoinHashesMap$1.pickAllCoins(newState));
|
|
328
|
+
return {
|
|
329
|
+
...wallet,
|
|
330
|
+
state: newState,
|
|
331
|
+
coinHashes: newCoinHashes
|
|
332
|
+
};
|
|
333
|
+
},
|
|
334
|
+
replayEventsWithChanges(wallet, secretKeys, events) {
|
|
335
|
+
const stateWithChanges = wallet.state.replayEventsWithChanges(secretKeys, events);
|
|
336
|
+
const newState = stateWithChanges.state;
|
|
337
|
+
const newCoinHashes = CoinHashesMap$1.updateWithCoins(secretKeys, wallet.coinHashes, CoinHashesMap$1.pickAllCoins(newState));
|
|
338
|
+
return [{
|
|
339
|
+
...wallet,
|
|
340
|
+
state: newState,
|
|
341
|
+
coinHashes: newCoinHashes
|
|
342
|
+
}, stateWithChanges.changes];
|
|
343
|
+
},
|
|
344
|
+
updateProgress(wallet, { appliedIndex, highestRelevantWalletIndex, highestIndex, highestRelevantIndex, isConnected }) {
|
|
345
|
+
const updatedProgress = require_dist.createSyncProgress({
|
|
346
|
+
appliedIndex: appliedIndex ?? wallet.progress.appliedIndex,
|
|
347
|
+
highestRelevantWalletIndex: highestRelevantWalletIndex ?? wallet.progress.highestRelevantWalletIndex,
|
|
348
|
+
highestIndex: highestIndex ?? wallet.progress.highestIndex,
|
|
349
|
+
highestRelevantIndex: highestRelevantIndex ?? wallet.progress.highestRelevantIndex,
|
|
350
|
+
isConnected: isConnected ?? wallet.progress.isConnected
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
...wallet,
|
|
354
|
+
progress: updatedProgress
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
addTransaction(wallet, _tx) {
|
|
358
|
+
return wallet;
|
|
359
|
+
},
|
|
360
|
+
revertTransaction(wallet, tx) {
|
|
361
|
+
const newState = wallet.state.revertTransaction(tx);
|
|
362
|
+
return {
|
|
363
|
+
...wallet,
|
|
364
|
+
state: newState
|
|
365
|
+
};
|
|
366
|
+
},
|
|
367
|
+
updateTxHistory(wallet, _newTxs) {
|
|
368
|
+
return wallet;
|
|
369
|
+
},
|
|
370
|
+
spendCoins(wallet, secretKeys, coins, segment) {
|
|
371
|
+
const [offers, newLocalState] = require_dist.pipe(coins, require_dist.reduce([[], wallet.state], ([accOffers, localState], coinToSpend) => {
|
|
372
|
+
const [nextState, newInput] = localState.spend(secretKeys, coinToSpend, segment);
|
|
373
|
+
const inputOffer = _midnightntwrk_ledger_v9.ZswapOffer.fromInput(newInput, coinToSpend.type, coinToSpend.value);
|
|
374
|
+
return [accOffers.concat([inputOffer]), nextState];
|
|
375
|
+
}));
|
|
376
|
+
return [offers, {
|
|
377
|
+
...wallet,
|
|
378
|
+
state: newLocalState
|
|
379
|
+
}];
|
|
380
|
+
},
|
|
381
|
+
watchCoins(wallet, secretKeys, coins) {
|
|
382
|
+
const newLocalState = coins.reduce((localState, coin) => localState.watchFor(wallet.publicKeys.coinPublicKey, coin), wallet.state);
|
|
383
|
+
const newCoinHashes = CoinHashesMap$1.updateWithNewCoins(secretKeys, wallet.coinHashes, coins);
|
|
384
|
+
return {
|
|
385
|
+
...wallet,
|
|
386
|
+
state: newLocalState,
|
|
387
|
+
coinHashes: newCoinHashes
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/Migration.js
|
|
393
|
+
/**
|
|
394
|
+
* The migration used when there is no previous wallet at all.
|
|
395
|
+
*
|
|
396
|
+
* @remarks
|
|
397
|
+
* It backs `WalletLike.startEmpty`, which builds a wallet before any key material exists. The resulting state has no
|
|
398
|
+
* coins and public keys derived from a fixed placeholder seed; it is a scaffold to be replaced by a real start, not a
|
|
399
|
+
* wallet anybody can transact with. Preserved verbatim from the ledger-v8 implementation so that `startEmpty` behaves
|
|
400
|
+
* exactly as it did.
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* const builder = new V2Builder().withDefaults().withMigration(makeEmptyWalletMigration({ networkId }));
|
|
404
|
+
* ```;
|
|
405
|
+
*
|
|
406
|
+
* @param configuration Supplies the network the scaffold state claims to be on.
|
|
407
|
+
* @returns A migration from `null`.
|
|
408
|
+
*/
|
|
409
|
+
const makeEmptyWalletMigration$1 = (configuration) => ({ migrate: () => {
|
|
410
|
+
const seed = require_dist.fromString("0000000000000000000000000000000000000000000000000000000000000001");
|
|
411
|
+
return require_dist.succeed(CoreWallet$1.empty(PublicKeys$1.fromSecretKeys(_midnightntwrk_ledger_v9.ZswapSecretKeys.fromSeed(seed)), configuration.networkId));
|
|
412
|
+
} });
|
|
413
|
+
/**
|
|
414
|
+
* The migration across a ledger-version boundary: the local state crosses as bytes, identity and position beside it.
|
|
415
|
+
*
|
|
416
|
+
* @remarks
|
|
417
|
+
* The chain's state translation carries every commitment across the fork in place — the ledger-v9 tree continues at the
|
|
418
|
+
* index the ledger-v8 tree reached, and the indexer does **not** replay the ledger-v8 timeline as new-version events.
|
|
419
|
+
* So the wallet's own state must cross with it, or the coins are gone.
|
|
420
|
+
*
|
|
421
|
+
* It crosses as bytes. The two ledger majors either side of this boundary serialize `ZswapLocalState` under the same
|
|
422
|
+
* `zswap-local-state` codec — the transaction codec moved at the fork, this one did not — so the previous version's
|
|
423
|
+
* serialization is something this version can simply read. The crossing is therefore a round-trip and not a
|
|
424
|
+
* reconstruction, and everything survives it: the coins at the Merkle indices the chain gave them, the height the
|
|
425
|
+
* tree had reached, and the outputs the wallet was still expecting, which no reconstruction from spendable coins
|
|
426
|
+
* could have recovered. `src/v2/test/byteCrossing.test.ts` pins that codec against both real ledgers, and states what
|
|
427
|
+
* to do if it ever goes red.
|
|
428
|
+
*
|
|
429
|
+
* **The coins booked for transactions still in flight cross too, and are released at the first sync update.** Those
|
|
430
|
+
* transactions belong to the ledger version the chain has left behind, so none of them can ever be included and no
|
|
431
|
+
* inclusion will ever clear the reservations they left in `pendingSpends` — the coins would simply stop being
|
|
432
|
+
* spendable. The release cannot happen here, because un-booking a spend needs the secret keys a migration is by
|
|
433
|
+
* design handed none of; it happens at the first sync update instead, which is where keys and carried state meet
|
|
434
|
+
* (`CoreWallet.completeCrossing`). The change outputs those same transactions would have paid back are left as they
|
|
435
|
+
* are, and nothing ever removes them: these entries carry no TTL and `ZswapLocalState.clearPending` does nothing in
|
|
436
|
+
* either ledger, so they sit in `pendingOutputs` for the life of the wallet. A known limitation, and a mild one —
|
|
437
|
+
* they overstate the pending balance, but they reserve no coin and block no spending.
|
|
438
|
+
*
|
|
439
|
+
* Read through `LedgerOps.ledgerTry`, so a codec that has moved is a `WalletError` at the boundary and never a throw:
|
|
440
|
+
* the failure mode of a future major moving `zswap-local-state` is loud, and lands here, where the
|
|
441
|
+
* {@link StateMigration} seam can be given the ledger team's own translation instead.
|
|
442
|
+
*
|
|
443
|
+
* Sync progress is **parked at the fork** rather than rewound: the indexer numbers ledger-v9 events onwards from
|
|
444
|
+
* whatever id it had reached when the fork happened, never from zero, so the inherited cursor is exactly where this
|
|
445
|
+
* wallet's reading resumes. A wallet that rewound to zero would wait on a stretch of the timeline this ledger
|
|
446
|
+
* version's events do not occupy.
|
|
447
|
+
* @returns A migration from a previous-ledger-version wallet.
|
|
448
|
+
*/
|
|
449
|
+
const makeCrossLedgerMigration = () => ({ migrate: (previousState) => require_dist.pipe(require_dist.ledgerTry(() => _midnightntwrk_ledger_v9.ZswapLocalState.deserialize(previousState.state.serialize())), require_dist.map$6((state) => CoreWallet$1.fromPreviousVersion({
|
|
450
|
+
state,
|
|
451
|
+
publicKeys: previousState.publicKeys,
|
|
452
|
+
networkId: previousState.networkId,
|
|
453
|
+
protocolVersion: previousState.protocolVersion,
|
|
454
|
+
progress: previousState.progress
|
|
455
|
+
})), require_dist.toEffect) });
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/RunningV2Variant.js
|
|
458
|
+
const progress$1 = (state) => {
|
|
459
|
+
const appliedIndex = state.progress?.appliedIndex ?? 0n;
|
|
460
|
+
const highestRelevantWalletIndex = state.progress?.highestRelevantWalletIndex ?? 0n;
|
|
461
|
+
const sourceGap = (state.progress?.highestIndex ?? 0n) - (state.progress?.highestRelevantIndex ?? 0n);
|
|
462
|
+
const applyGap = highestRelevantWalletIndex - appliedIndex;
|
|
463
|
+
return [require_dist.ProgressUpdate({
|
|
464
|
+
sourceGap,
|
|
465
|
+
applyGap
|
|
466
|
+
})];
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Reports the protocol version a state observation implies, if any.
|
|
470
|
+
*
|
|
471
|
+
* @remarks
|
|
472
|
+
* Two situations call for a signal. The ordinary one is a transition: sync annotated the state with a version it did
|
|
473
|
+
* not have before, and the runtime decides whether that is a re-annotation inside this variant's range or a hand-over
|
|
474
|
+
* to the next one.
|
|
475
|
+
*
|
|
476
|
+
* The other is a state that arrives already outside this variant's range — a snapshot serialized in the window between
|
|
477
|
+
* the annotation and the migration it should have caused, or one written by an older protocol version entirely.
|
|
478
|
+
* Nothing further will change that value, so waiting for a transition would strand the wallet on a version it does
|
|
479
|
+
* not own. Emitting on sight heals it.
|
|
480
|
+
*/
|
|
481
|
+
const protocolVersionChange$1 = (previous, current, isInitial, activationRange) => {
|
|
482
|
+
const transitioned = previous.protocolVersion != current.protocolVersion;
|
|
483
|
+
const strandedOutsideRange = isInitial && !require_dist.withinRange(current.protocolVersion, activationRange);
|
|
484
|
+
return transitioned || strandedOutsideRange ? [require_dist.VersionChange({ change: require_dist.Version({ version: require_dist.ProtocolVersion(current.protocolVersion) }) })] : [];
|
|
485
|
+
};
|
|
486
|
+
const V2Tag = Symbol("V2");
|
|
487
|
+
var RunningV2Variant = class {
|
|
488
|
+
__polyTag__ = V2Tag;
|
|
489
|
+
#scope;
|
|
490
|
+
#context;
|
|
491
|
+
#v2Context;
|
|
492
|
+
#txHistoryPermits = require_dist.makeSemaphore(8).pipe(require_dist.runSync);
|
|
493
|
+
state;
|
|
494
|
+
constructor(scope, context, v2Context) {
|
|
495
|
+
this.#scope = scope;
|
|
496
|
+
this.#context = context;
|
|
497
|
+
this.#v2Context = v2Context;
|
|
498
|
+
this.state = require_dist.fromEffect(context.stateRef.get).pipe(require_dist.flatMap((initialState) => context.stateRef.changes.pipe(require_dist.mapAccum({
|
|
499
|
+
previous: initialState,
|
|
500
|
+
isInitial: true
|
|
501
|
+
}, (seen, current) => [{
|
|
502
|
+
previous: current,
|
|
503
|
+
isInitial: false
|
|
504
|
+
}, [
|
|
505
|
+
seen.previous,
|
|
506
|
+
current,
|
|
507
|
+
seen.isInitial
|
|
508
|
+
]]))), require_dist.mapConcat(([previous, current, isInitial]) => {
|
|
509
|
+
return [
|
|
510
|
+
require_dist.State({ state: current }),
|
|
511
|
+
...progress$1(current),
|
|
512
|
+
...protocolVersionChange$1(previous, current, isInitial, context.activationRange)
|
|
513
|
+
];
|
|
514
|
+
}));
|
|
515
|
+
}
|
|
516
|
+
startSyncInBackground(startAux) {
|
|
517
|
+
return this.startSync(startAux).pipe(require_dist.runScoped(require_dist.drain), require_dist.forkScoped, require_dist.provideService(require_dist.Scope, this.#scope));
|
|
518
|
+
}
|
|
519
|
+
startSync(startAux) {
|
|
520
|
+
return require_dist.pipe(require_dist.get(this.#context.stateRef), require_dist.fromEffect, require_dist.flatMap((state) => this.#v2Context.syncService.updates(state, startAux)), require_dist.mapEffect((update) => require_dist.modifyEffect(this.#context.stateRef, (state) => require_dist.try_({
|
|
521
|
+
try: () => {
|
|
522
|
+
const [newState, changesResult] = this.#v2Context.syncCapability.applyUpdate(state, update, this.#context.activationRange);
|
|
523
|
+
return [changesResult, newState];
|
|
524
|
+
},
|
|
525
|
+
catch: (err) => new OtherWalletError$1({
|
|
526
|
+
message: "Error while applying sync update",
|
|
527
|
+
cause: err
|
|
528
|
+
})
|
|
529
|
+
})).pipe(require_dist.flatMap$1(({ changes, protocolVersion }) => changes.length === 0 ? require_dist._void : require_dist.pipe(require_dist.forEach(changes, (change) => require_dist.pipe(this.#txHistoryPermits.withPermits(1)(require_dist.pipe(this.#v2Context.transactionHistoryService.getTransactionDetails(change.source), require_dist.flatMap$1((metadata) => this.#v2Context.transactionHistoryService.put(change, metadata, protocolVersion)))), require_dist.catchAllCause((cause) => require_dist.logError(cause, `Failed to record shielded tx-history section for ${change.source}`))), {
|
|
530
|
+
discard: true,
|
|
531
|
+
concurrency: 8
|
|
532
|
+
}), require_dist.forkScoped)), require_dist.provideService(require_dist.Scope, this.#scope))), require_dist.tapError((error$2) => require_dist.error(error$2)), require_dist.retry(require_dist.pipe(require_dist.exponential(require_dist.seconds(1), 2), require_dist.map$1((delay) => {
|
|
533
|
+
const maxDelay = require_dist.minutes(2);
|
|
534
|
+
const jitter = require_dist.millis(Math.floor(Math.random() * 1e3));
|
|
535
|
+
const delayWithJitter = require_dist.toMillis(delay) + require_dist.toMillis(jitter);
|
|
536
|
+
return require_dist.millis(Math.min(delayWithJitter, require_dist.toMillis(maxDelay)));
|
|
537
|
+
}))));
|
|
538
|
+
}
|
|
539
|
+
balanceTransaction(secretKeys, tx) {
|
|
540
|
+
return require_dist.modifyEffect(this.#context.stateRef, (state) => {
|
|
541
|
+
return require_dist.pipe(this.#v2Context.transactingCapability.balanceTransaction(secretKeys, state, tx), require_dist.toEffect);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
transferTransaction(secretKeys, outputs) {
|
|
545
|
+
return require_dist.modifyEffect(this.#context.stateRef, (state) => {
|
|
546
|
+
return require_dist.pipe(this.#v2Context.transactingCapability.makeTransfer(secretKeys, state, outputs), require_dist.toEffect);
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
initSwap(secretKeys, desiredInputs, desiredOutputs) {
|
|
550
|
+
return require_dist.modifyEffect(this.#context.stateRef, (state) => {
|
|
551
|
+
return require_dist.pipe(this.#v2Context.transactingCapability.initSwap(secretKeys, state, desiredInputs, desiredOutputs), require_dist.toEffect);
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
revertTransaction(transaction) {
|
|
555
|
+
return require_dist.updateEffect(this.#context.stateRef, (state) => {
|
|
556
|
+
return require_dist.pipe(this.#v2Context.transactingCapability.revertTransaction(state, transaction), require_dist.toEffect);
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
serializeState(state) {
|
|
560
|
+
return this.#v2Context.serializationCapability.serialize(state);
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
//#endregion
|
|
564
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/Serialization.js
|
|
565
|
+
const StateSchema$1 = require_dist.declare((input) => input instanceof _midnightntwrk_ledger_v9.ZswapLocalState).annotations({ identifier: "ledger.ZswapLocalState" });
|
|
566
|
+
const Uint8ArraySchema$3 = require_dist.declare((input) => input instanceof Uint8Array).annotations({ identifier: "Uint8Array" });
|
|
567
|
+
const StateFromUInt8Array$1 = () => require_dist.asSchema(require_dist.transformOrFail(Uint8ArraySchema$3, StateSchema$1, {
|
|
568
|
+
encode: (state) => {
|
|
569
|
+
return require_dist.try_({
|
|
570
|
+
try: () => {
|
|
571
|
+
return state.serialize();
|
|
572
|
+
},
|
|
573
|
+
catch: (err) => {
|
|
574
|
+
return new require_dist.Unexpected(err, "Could not serialize local state");
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
},
|
|
578
|
+
decode: (bytes) => require_dist.try_({
|
|
579
|
+
try: () => _midnightntwrk_ledger_v9.ZswapLocalState.deserialize(bytes),
|
|
580
|
+
catch: (err) => {
|
|
581
|
+
return new require_dist.Unexpected(err, "Could not deserialize local state");
|
|
582
|
+
}
|
|
583
|
+
})
|
|
584
|
+
}));
|
|
585
|
+
const HexedState$1 = () => require_dist.pipe(require_dist.Uint8ArrayFromHex, require_dist.compose(StateFromUInt8Array$1()));
|
|
586
|
+
const makeDefaultV2SerializationCapability = () => {
|
|
587
|
+
const SnapshotSchema = require_dist.Struct({
|
|
588
|
+
publicKeys: require_dist.Struct({
|
|
589
|
+
coinPublicKey: require_dist.String$,
|
|
590
|
+
encryptionPublicKey: require_dist.String$
|
|
591
|
+
}),
|
|
592
|
+
state: HexedState$1(),
|
|
593
|
+
protocolVersion: require_dist.BigInt$,
|
|
594
|
+
offset: require_dist.optional(require_dist.BigInt$),
|
|
595
|
+
networkId: require_dist.String$,
|
|
596
|
+
coinHashes: require_dist.Record({
|
|
597
|
+
key: require_dist.String$,
|
|
598
|
+
value: require_dist.Struct({
|
|
599
|
+
nullifier: require_dist.String$,
|
|
600
|
+
commitment: require_dist.String$
|
|
601
|
+
})
|
|
602
|
+
}),
|
|
603
|
+
coinHashesPending: require_dist.optional(require_dist.Literal(true))
|
|
604
|
+
});
|
|
605
|
+
return {
|
|
606
|
+
serialize: (wallet) => {
|
|
607
|
+
const buildSnapshot = (w) => ({
|
|
608
|
+
publicKeys: w.publicKeys,
|
|
609
|
+
state: w.state,
|
|
610
|
+
protocolVersion: w.protocolVersion,
|
|
611
|
+
networkId: w.networkId,
|
|
612
|
+
offset: w.progress?.appliedIndex,
|
|
613
|
+
coinHashes: w.coinHashes,
|
|
614
|
+
...w.coinHashesPending !== void 0 ? { coinHashesPending: w.coinHashesPending } : {}
|
|
615
|
+
});
|
|
616
|
+
return require_dist.pipe(wallet, buildSnapshot, require_dist.encodeSync(SnapshotSchema), JSON.stringify);
|
|
617
|
+
},
|
|
618
|
+
deserialize: (aux, serialized) => {
|
|
619
|
+
return require_dist.pipe(serialized, require_dist.decodeUnknownEither(require_dist.parseJson(SnapshotSchema)), require_dist.mapLeft((err) => WalletError$1.other(err)), require_dist.flatMap$4((snapshot) => {
|
|
620
|
+
const progress = {
|
|
621
|
+
appliedIndex: snapshot.offset ?? 0n,
|
|
622
|
+
highestRelevantWalletIndex: 0n,
|
|
623
|
+
highestIndex: 0n,
|
|
624
|
+
highestRelevantIndex: 0n,
|
|
625
|
+
isConnected: false
|
|
626
|
+
};
|
|
627
|
+
return snapshot.coinHashesPending === true ? require_dist.right(CoreWallet$1.restoreWithPendingCoinHashes(snapshot.publicKeys, snapshot.state, progress, snapshot.protocolVersion, snapshot.networkId)) : CoreWallet$1.restoreWithCoinHashes(snapshot.publicKeys, snapshot.state, snapshot.coinHashes, progress, snapshot.protocolVersion, snapshot.networkId);
|
|
628
|
+
}));
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/Sync.js
|
|
634
|
+
/**
|
|
635
|
+
* Splits a batch of version-tagged items at the end of a variant's activation range.
|
|
636
|
+
*
|
|
637
|
+
* @remarks
|
|
638
|
+
* The split is positional, not a filter: everything from the first out-of-range item onwards is deferred, even if a
|
|
639
|
+
* later item reports an in-range version again. A batch is a contiguous slice of one timeline, so applying past a
|
|
640
|
+
* boundary and then resuming behind it would leave a hole no cursor can describe.
|
|
641
|
+
*
|
|
642
|
+
* This is the one place the boundary rule lives; both the indexer capability (per event) and the simulator capability
|
|
643
|
+
* (per block) go through it, so they cannot drift apart.
|
|
644
|
+
* @param items The batch, in source order.
|
|
645
|
+
* @param versionOf Reads the protocol version an item was reported at.
|
|
646
|
+
* @param activeRange The variant's half-open activation range.
|
|
647
|
+
* @returns The applied/deferred split and the version to record.
|
|
648
|
+
*/
|
|
649
|
+
const splitAtVersionBoundary$1 = (items, versionOf, activeRange) => {
|
|
650
|
+
const [, end] = activeRange;
|
|
651
|
+
const boundary = items.findIndex((item) => BigInt(versionOf(item)) >= end);
|
|
652
|
+
const [applied, deferred] = boundary < 0 ? [items, []] : [items.slice(0, boundary), items.slice(boundary)];
|
|
653
|
+
const signalling = deferred.at(0) ?? applied.at(-1);
|
|
654
|
+
return {
|
|
655
|
+
applied,
|
|
656
|
+
deferred,
|
|
657
|
+
observedVersion: signalling === void 0 ? require_dist.none() : require_dist.some(require_dist.ProtocolVersion(BigInt(versionOf(signalling))))
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
/**
|
|
661
|
+
* Checks that freshly delivered events arrive in strictly ascending id order.
|
|
662
|
+
*
|
|
663
|
+
* @remarks
|
|
664
|
+
* Order is all that can be checked, never contiguity: zswap events share one id sequence with dust and contract events
|
|
665
|
+
* in the indexer, so gaps in a zswap stream are normal. A skipped commitment-inserting event is caught by the
|
|
666
|
+
* ledger's own insertion check instead. An empty batch is trivially ordered.
|
|
667
|
+
* @param fresh The events left after the cursor filter, in source order.
|
|
668
|
+
* @param appliedIndex The highest event id already applied; the first fresh id must exceed it.
|
|
669
|
+
* @returns The batch unchanged, or the first id that fails to exceed its predecessor as an
|
|
670
|
+
* {@link OutOfOrderSyncUpdateError}.
|
|
671
|
+
*/
|
|
672
|
+
const expectAscending$1 = (fresh, appliedIndex) => require_dist.pipe(require_dist.zipWith(fresh, require_dist.prepend(require_dist.map$3(fresh, (item) => BigInt(item.id)), appliedIndex), (item, previous) => ({
|
|
673
|
+
item,
|
|
674
|
+
previous
|
|
675
|
+
})), require_dist.findFirst(({ item, previous }) => BigInt(item.id) <= previous), require_dist.match$1({
|
|
676
|
+
onNone: () => require_dist.right(fresh),
|
|
677
|
+
onSome: ({ item, previous }) => require_dist.left(new OutOfOrderSyncUpdateError$1({
|
|
678
|
+
message: `Zswap event ${item.id} delivered at or below its predecessor ${previous}; batch refused, applied index stays at ${appliedIndex}`,
|
|
679
|
+
expected: previous,
|
|
680
|
+
received: BigInt(item.id)
|
|
681
|
+
}))
|
|
682
|
+
}));
|
|
683
|
+
/** Records a batch's observed protocol version on the state, monotonically. A batch that observed none is a no-op. */
|
|
684
|
+
const annotateVersion$1 = (state, observedVersion) => require_dist.match$1(observedVersion, {
|
|
685
|
+
onNone: () => state,
|
|
686
|
+
onSome: (version) => CoreWallet$1.withProtocolVersion(state, version)
|
|
687
|
+
});
|
|
688
|
+
const Uint8ArraySchema$2 = require_dist.declare((input) => input instanceof Uint8Array).annotations({ identifier: "Uint8Array" });
|
|
689
|
+
const VersionSignalSyncUpdate$1 = { create: (version, highestEventId) => {
|
|
690
|
+
return {
|
|
691
|
+
_tag: "VersionSignal",
|
|
692
|
+
version,
|
|
693
|
+
highestEventId
|
|
694
|
+
};
|
|
695
|
+
} };
|
|
696
|
+
const WalletSyncUpdate$1 = { create: (updates, secretKeys) => {
|
|
697
|
+
return {
|
|
698
|
+
_tag: "Events",
|
|
699
|
+
updates,
|
|
700
|
+
secretKeys
|
|
701
|
+
};
|
|
702
|
+
} };
|
|
703
|
+
const LedgerEventSchema$1 = require_dist.declare((input) => input instanceof _midnightntwrk_ledger_v9.Event).annotations({ identifier: "ledger.Event" });
|
|
704
|
+
const LedgerEventFromUint8Array$1 = require_dist.transformOrFail(Uint8ArraySchema$2, LedgerEventSchema$1, {
|
|
705
|
+
encode: (event) => require_dist.try_({
|
|
706
|
+
try: () => event.serialize(),
|
|
707
|
+
catch: (error) => new require_dist.Unexpected(error, "Could not serialize ledger event")
|
|
708
|
+
}),
|
|
709
|
+
decode: (bytes) => require_dist.try_({
|
|
710
|
+
try: () => _midnightntwrk_ledger_v9.Event.deserialize(bytes),
|
|
711
|
+
catch: (error) => new require_dist.Unexpected(error, "Could not deserialize ledger event")
|
|
712
|
+
})
|
|
713
|
+
});
|
|
714
|
+
const HexedLedgerEvent$1 = require_dist.pipe(require_dist.Uint8ArrayFromHex, require_dist.compose(LedgerEventFromUint8Array$1));
|
|
715
|
+
const EventsSyncUpdatePayload$1 = require_dist.Struct({
|
|
716
|
+
id: require_dist.Number$,
|
|
717
|
+
raw: require_dist.String$,
|
|
718
|
+
protocolVersion: require_dist.Number$,
|
|
719
|
+
maxId: require_dist.Number$
|
|
720
|
+
});
|
|
721
|
+
/**
|
|
722
|
+
* One event of the source's timeline, still encoded.
|
|
723
|
+
*
|
|
724
|
+
* @remarks
|
|
725
|
+
* The event is carried as the source served it rather than as a `ledger.Event`, because whether this ledger version may
|
|
726
|
+
* read it at all is not the source's question to answer. A batch spanning a protocol boundary carries events of the
|
|
727
|
+
* version that follows this one, which this ledger version cannot deserialize — the serialization header names a
|
|
728
|
+
* different version — and after a hand-over the inclusive cursor re-delivers an event of the version that preceded
|
|
729
|
+
* it, which it equally cannot. Both are ordinary, and neither is an error: they belong to the variant either side.
|
|
730
|
+
*
|
|
731
|
+
* So the bytes travel undecoded and only the capability, which knows the activation range, reads the ones it is about
|
|
732
|
+
* to apply — see {@link readEvent}. Decoding here would fail the whole batch on an event nobody intended to apply.
|
|
733
|
+
*/
|
|
734
|
+
const EventsSyncUpdate$1 = require_dist.TaggedStruct("EventsSyncUpdate", {
|
|
735
|
+
id: require_dist.Number$,
|
|
736
|
+
protocolVersion: require_dist.Number$,
|
|
737
|
+
maxId: require_dist.Number$,
|
|
738
|
+
raw: require_dist.String$
|
|
739
|
+
});
|
|
740
|
+
const EventsSyncUpdateFromPayload$1 = require_dist.transform(EventsSyncUpdatePayload$1, EventsSyncUpdate$1, {
|
|
741
|
+
strict: true,
|
|
742
|
+
decode: (input) => ({
|
|
743
|
+
_tag: "EventsSyncUpdate",
|
|
744
|
+
id: input.id,
|
|
745
|
+
protocolVersion: input.protocolVersion,
|
|
746
|
+
maxId: input.maxId,
|
|
747
|
+
raw: input.raw
|
|
748
|
+
}),
|
|
749
|
+
encode: (update) => ({
|
|
750
|
+
id: update.id,
|
|
751
|
+
raw: update.raw,
|
|
752
|
+
protocolVersion: update.protocolVersion,
|
|
753
|
+
maxId: update.maxId
|
|
754
|
+
})
|
|
755
|
+
});
|
|
756
|
+
/**
|
|
757
|
+
* Reads an event this variant is going to apply.
|
|
758
|
+
*
|
|
759
|
+
* @remarks
|
|
760
|
+
* The counterpart of {@link EventsSyncUpdate} carrying its event encoded: a capability calls this on the batch prefix it
|
|
761
|
+
* owns, and never on what it defers. Failure here is a genuine one — an event this variant claimed and cannot read —
|
|
762
|
+
* and is raised rather than returned, because `SyncCapability.applyUpdate` is total in its own domain and the variant
|
|
763
|
+
* already turns a throw from it into a typed synchronization error.
|
|
764
|
+
* @param update The update to read.
|
|
765
|
+
* @returns The event it carries.
|
|
766
|
+
* @throws ParseError if the bytes are not an event this ledger version can deserialize.
|
|
767
|
+
*/
|
|
768
|
+
const readEvent$1 = (update) => require_dist.decodeSync(HexedLedgerEvent$1)(update.raw);
|
|
769
|
+
/** How often the chain is asked its version when the configuration does not say. */
|
|
770
|
+
const DEFAULT_VERSION_WATCH_INTERVAL_MS$1 = 3e4;
|
|
771
|
+
/**
|
|
772
|
+
* How long one event-id probe is given to produce its single answer.
|
|
773
|
+
*
|
|
774
|
+
* @remarks
|
|
775
|
+
* Only a stall guard. The probe subscribes at a cursor whose event provably exists, so the answer arrives at once or
|
|
776
|
+
* the transport is broken; without a bound, a half-open socket would leave the poll loop parked on a tick that never
|
|
777
|
+
* completes and the wallet would stop asking altogether. A bound turns that into a skipped tick.
|
|
778
|
+
*/
|
|
779
|
+
const EVENT_TIP_PROBE_TIMEOUT$1 = require_dist.seconds(10);
|
|
780
|
+
/**
|
|
781
|
+
* Asks the source how far its zswap event timeline goes.
|
|
782
|
+
*
|
|
783
|
+
* @remarks
|
|
784
|
+
* Over the event subscription rather than a query, because the schema has no query that reaches a zswap ledger event:
|
|
785
|
+
* `block`/`transactions` reach one only through a block that happens to contain zswap events, which on a quiet chain
|
|
786
|
+
* is precisely the block that does not. `maxId` is a property of the whole timeline, so any single event answers it —
|
|
787
|
+
* the first one delivered is taken and the subscription closed.
|
|
788
|
+
*
|
|
789
|
+
* The cursor is the wallet's own. The event it last applied provably exists, so the source answers immediately and has
|
|
790
|
+
* the least backfill to abandon; a wallet that has applied nothing asks from the start, where the first event is.
|
|
791
|
+
* @param config The sync configuration, for the keep-alive the source's subscriptions use.
|
|
792
|
+
* @param url Where to subscribe.
|
|
793
|
+
* @param resumeFrom The wallet's cursor; below zero means "from the very start".
|
|
794
|
+
* @returns The highest event id, or nothing if the source did not answer.
|
|
795
|
+
*/
|
|
796
|
+
const highestEventId$1 = (config, url, resumeFrom) => require_dist.pipe(require_dist.ZswapEventTip.run({ id: resumeFrom < 0n ? null : Number(resumeFrom) }), require_dist.runHead, require_dist.map$2(require_dist.map$5((answer) => answer.zswapLedgerEvents.maxId)), require_dist.provide(require_dist.layer({
|
|
797
|
+
url,
|
|
798
|
+
keepAlive: config.indexerClientConnection.keepAlive
|
|
799
|
+
})), require_dist.scoped, require_dist.timeout(EVENT_TIP_PROBE_TIMEOUT$1));
|
|
800
|
+
/**
|
|
801
|
+
* One check of the chain's protocol version, gated on the wallet being caught up on the source's event ids.
|
|
802
|
+
*
|
|
803
|
+
* @remarks
|
|
804
|
+
* The order of the two questions is load-bearing. The tip is read **first**: a tip reported at a version means the
|
|
805
|
+
* source has indexed through the block that carries it, so every event below it is already counted in the `maxId`
|
|
806
|
+
* read afterwards. Asked the other way round, an event indexed between the two answers could be one of the version
|
|
807
|
+
* that preceded the tip — unread, uncounted, and exactly what the gate exists to catch.
|
|
808
|
+
*
|
|
809
|
+
* Two short-circuits, both of them answers rather than shortcuts. A tip at or below the version the wallet already held
|
|
810
|
+
* is a signal that could only be a no-op, so no probe is opened and nothing is emitted — which is what keeps a
|
|
811
|
+
* settled wallet from polling a subscription for the rest of its life. And a tip whose commitment tree has never
|
|
812
|
+
* grown cannot have had a nullifier spent against it either, so such a chain provably holds no zswap event: nothing
|
|
813
|
+
* can be unread, and the signal goes out with `null`.
|
|
814
|
+
*
|
|
815
|
+
* Everything else is swallowed. A tick that fails says nothing about the chain, so it must neither reach the state nor
|
|
816
|
+
* take the sync stream down with it; the next tick is the retry, and costs nothing to wait for.
|
|
817
|
+
* @param config The sync configuration, for the indexer to ask.
|
|
818
|
+
* @param url Where to run the event-id probe.
|
|
819
|
+
* @param resumeFrom The wallet's cursor, for the probe.
|
|
820
|
+
* @param knownVersion The version the wallet already held when this stream opened — a lower bound on what it holds now.
|
|
821
|
+
* @returns The signal, or nothing when there is nothing to say or nobody said it.
|
|
822
|
+
*/
|
|
823
|
+
const readVersionSignal$1 = (config, url, resumeFrom, knownVersion) => require_dist.pipe(require_dist.BlockHash.run({ offset: null }), require_dist.provide(require_dist.layer$1({ url: config.indexerClientConnection.indexerHttpUrl })), require_dist.scoped, require_dist.flatMap$1((answer) => require_dist.match$1(require_dist.fromNullable(answer.block), {
|
|
824
|
+
onNone: () => require_dist.succeedNone,
|
|
825
|
+
onSome: (tip) => BigInt(tip.protocolVersion) <= knownVersion ? require_dist.succeedNone : tip.zswapEndIndex === 0 ? require_dist.succeedSome(VersionSignalSyncUpdate$1.create(tip.protocolVersion, null)) : require_dist.pipe(highestEventId$1(config, url, resumeFrom), require_dist.map$2(require_dist.map$5((maxId) => VersionSignalSyncUpdate$1.create(tip.protocolVersion, maxId))))
|
|
826
|
+
})), require_dist.catchAll(() => require_dist.succeedNone));
|
|
827
|
+
/**
|
|
828
|
+
* The chain's version, re-asked on a timer for as long as sync runs.
|
|
829
|
+
*
|
|
830
|
+
* @remarks
|
|
831
|
+
* Deliberately silent about ticks that say nothing: a tick that finds the chain where the wallet left it, or that
|
|
832
|
+
* cannot reach the chain at all, emits no element rather than an empty one, so nothing downstream has to know that
|
|
833
|
+
* polling is how the answer was arrived at.
|
|
834
|
+
* @param config The sync configuration, carrying the interval.
|
|
835
|
+
* @param url Where to run the event-id probe.
|
|
836
|
+
* @param resumeFrom The wallet's cursor, for the probe.
|
|
837
|
+
* @param knownVersion The version the wallet held when this stream opened.
|
|
838
|
+
* @returns The signals, or an empty stream when watching is turned off.
|
|
839
|
+
*/
|
|
840
|
+
const versionWatch$1 = (config, url, resumeFrom, knownVersion) => {
|
|
841
|
+
const intervalMs = config.versionWatch?.intervalMs ?? DEFAULT_VERSION_WATCH_INTERVAL_MS$1;
|
|
842
|
+
return intervalMs <= 0 ? require_dist.empty : require_dist.pipe(require_dist.fromSchedule(require_dist.spaced(require_dist.millis(intervalMs))), require_dist.mapEffect(() => readVersionSignal$1(config, url, resumeFrom, knownVersion)), require_dist.filterMap(require_dist.identity));
|
|
843
|
+
};
|
|
844
|
+
const makeEventsSyncService$1 = (config) => {
|
|
845
|
+
return { updates: (state, secretKeys) => {
|
|
846
|
+
const { indexerClientConnection } = config;
|
|
847
|
+
const webSocketUrlResult = require_dist.createWebSocketUrl(indexerClientConnection.indexerHttpUrl, indexerClientConnection.indexerWsUrl);
|
|
848
|
+
if (require_dist.isLeft(webSocketUrlResult)) return require_dist.fail(new SyncWalletError$1(/* @__PURE__ */ new Error(`Could not derive WebSocket URL from indexer HTTP URL: ${webSocketUrlResult.left.message}`)));
|
|
849
|
+
const indexerWsUrlResult = require_dist.make(webSocketUrlResult.right);
|
|
850
|
+
if (require_dist.isLeft(indexerWsUrlResult)) return require_dist.fail(new SyncWalletError$1(/* @__PURE__ */ new Error(`Invalid indexer WS URL: ${indexerWsUrlResult.left.message}`)));
|
|
851
|
+
const indexerWsUrl = indexerWsUrlResult.right;
|
|
852
|
+
const resumeFrom = (state.progress?.appliedIndex ?? 0n) - 1n;
|
|
853
|
+
const batchSize = config.batchUpdates?.size ?? 10;
|
|
854
|
+
const batchTimeout = require_dist.millis(config.batchUpdates?.timeout ?? 1);
|
|
855
|
+
const batchSpacing = config.batchUpdates?.spacing ?? 4;
|
|
856
|
+
const bufferSize = config.indexerClientConnection.bufferSize ?? 1e4;
|
|
857
|
+
const resumeThreshold = config.indexerClientConnection.resumeThreshold ?? 100;
|
|
858
|
+
const eventsStream = require_dist.pipe(require_dist.ZswapEvents.runWithBackpressure({
|
|
859
|
+
bufferSize,
|
|
860
|
+
resumeThreshold,
|
|
861
|
+
from: resumeFrom,
|
|
862
|
+
variables: (cursor) => ({ id: cursor < 0n ? null : Number(cursor) }),
|
|
863
|
+
key: (r) => BigInt(r.zswapLedgerEvents.id)
|
|
864
|
+
}), require_dist.provideLayer(require_dist.layer({
|
|
865
|
+
url: indexerWsUrl,
|
|
866
|
+
keepAlive: config.indexerClientConnection.keepAlive
|
|
867
|
+
})), require_dist.mapError((error) => new SyncWalletError$1(error)), require_dist.mapEffect((subscription) => require_dist.pipe(subscription.zswapLedgerEvents, require_dist.decodeUnknownEither(EventsSyncUpdateFromPayload$1), require_dist.mapLeft((err) => new SyncWalletError$1(err)), require_dist.toEffect)), require_dist.groupedWithin(batchSize, batchTimeout), require_dist.map(require_dist.toArray), require_dist.map((data) => WalletSyncUpdate$1.create(data, secretKeys)));
|
|
868
|
+
const timeline = batchSpacing > 0 ? require_dist.schedule(eventsStream, require_dist.spaced(require_dist.millis(batchSpacing))) : eventsStream;
|
|
869
|
+
return require_dist.merge(timeline, versionWatch$1(config, indexerWsUrl, resumeFrom, state.protocolVersion), { haltStrategy: "left" });
|
|
870
|
+
} };
|
|
871
|
+
};
|
|
872
|
+
/** The result of an update that observed nothing of the chain. */
|
|
873
|
+
const noChanges$1 = (state) => ({
|
|
874
|
+
changes: [],
|
|
875
|
+
protocolVersion: Number(state.protocolVersion)
|
|
876
|
+
});
|
|
877
|
+
/**
|
|
878
|
+
* Folds what the chain said about its own version into the wallet state.
|
|
879
|
+
*
|
|
880
|
+
* @remarks
|
|
881
|
+
* The same recording the event path makes through {@link annotateVersion}, and nothing else: no cursor moves, no coin
|
|
882
|
+
* changes hands, no tree grows. A signal is an observation about the chain, not a piece of it — which is also why it
|
|
883
|
+
* does not resolve pending coin hashes: it carries no keys, and the first batch of the timeline does.
|
|
884
|
+
*
|
|
885
|
+
* One situation makes the observation unsafe to record, and it leaves the state exactly as it was: unread events below
|
|
886
|
+
* the source's tip mean the hand-over would park the cursor in front of history the next variant cannot read — and
|
|
887
|
+
* those events carry the version themselves, so nothing is lost by waiting for them. Not an error: the next tick asks
|
|
888
|
+
* again.
|
|
889
|
+
*
|
|
890
|
+
* A version at or below the one already recorded needs no guard of its own — {@link annotateVersion} never goes
|
|
891
|
+
* backwards — so a source briefly answering from a lagging replica cannot drag a wallet back over a boundary.
|
|
892
|
+
* @param wallet The wallet to record on.
|
|
893
|
+
* @param update What the chain said, and how far its event timeline goes.
|
|
894
|
+
* @returns The wallet, annotated or untouched, and an empty result.
|
|
895
|
+
*/
|
|
896
|
+
const applyVersionSignal$1 = (wallet, update) => {
|
|
897
|
+
const appliedIndex = wallet.progress?.appliedIndex ?? 0n;
|
|
898
|
+
return [update.highestEventId !== null && BigInt(update.highestEventId) > appliedIndex ? wallet : annotateVersion$1(wallet, require_dist.some(require_dist.ProtocolVersion(BigInt(update.version)))), noChanges$1(wallet)];
|
|
899
|
+
};
|
|
900
|
+
const makeEventsSyncCapability$1 = () => {
|
|
901
|
+
return { applyUpdate: (wallet, wrappedUpdate, activeRange) => {
|
|
902
|
+
if (wrappedUpdate._tag === "VersionSignal") return applyVersionSignal$1(wallet, wrappedUpdate);
|
|
903
|
+
const state = CoreWallet$1.completeCrossing(wallet, wrappedUpdate.secretKeys);
|
|
904
|
+
if (wrappedUpdate.updates.length === 0) return [state, noChanges$1(state)];
|
|
905
|
+
const appliedIndex = state.progress?.appliedIndex ?? 0n;
|
|
906
|
+
const freshUpdates = wrappedUpdate.updates.filter((u) => BigInt(u.id) > appliedIndex);
|
|
907
|
+
const lastUpdate = wrappedUpdate.updates.at(-1);
|
|
908
|
+
const highestRelevantWalletIndex = BigInt(lastUpdate.maxId);
|
|
909
|
+
const { applied, observedVersion } = splitAtVersionBoundary$1(require_dist.getOrThrowWith(expectAscending$1(freshUpdates, appliedIndex), require_dist.identity), (update) => update.protocolVersion, activeRange);
|
|
910
|
+
const [newState, newChanges] = applied.length === 0 ? [state, []] : CoreWallet$1.replayEventsWithChanges(state, wrappedUpdate.secretKeys, applied.map(readEvent$1));
|
|
911
|
+
return [CoreWallet$1.updateProgress(annotateVersion$1(newState, observedVersion), {
|
|
912
|
+
highestRelevantWalletIndex,
|
|
913
|
+
appliedIndex: applied.length === 0 ? appliedIndex : BigInt(applied.at(-1).id),
|
|
914
|
+
isConnected: true
|
|
915
|
+
}), {
|
|
916
|
+
changes: newChanges,
|
|
917
|
+
protocolVersion: applied.at(-1)?.protocolVersion ?? Number(state.protocolVersion)
|
|
918
|
+
}];
|
|
919
|
+
} };
|
|
920
|
+
};
|
|
921
|
+
//#endregion
|
|
922
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/TransactionImbalances.js
|
|
923
|
+
const ShieldedCostModel$1 = {
|
|
924
|
+
inputFeeOverhead: 0n,
|
|
925
|
+
outputFeeOverhead: 0n
|
|
926
|
+
};
|
|
927
|
+
const TransactionImbalances$1 = new class {
|
|
928
|
+
empty = () => {
|
|
929
|
+
return {
|
|
930
|
+
guaranteed: require_dist.Imbalances.empty(),
|
|
931
|
+
fallible: /* @__PURE__ */ new Map()
|
|
932
|
+
};
|
|
933
|
+
};
|
|
934
|
+
areBalanced = (imbalances) => {
|
|
935
|
+
const areGuaranteedAllZeroes = imbalances.guaranteed.entries().every(([, value]) => value === 0n);
|
|
936
|
+
const areFallibleAllZeroes = Array.from(imbalances.fallible.values()).every((segmentImbalances) => segmentImbalances.entries().every(([, value]) => value === 0n));
|
|
937
|
+
return areGuaranteedAllZeroes && areFallibleAllZeroes;
|
|
938
|
+
};
|
|
939
|
+
}();
|
|
940
|
+
//#endregion
|
|
941
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/TransactionOps.js
|
|
942
|
+
const TransactionOps$1 = new class {
|
|
943
|
+
default = {
|
|
944
|
+
getImbalances(tx) {
|
|
945
|
+
return TransactionOps$1.shared.getImbalances(tx);
|
|
946
|
+
},
|
|
947
|
+
id(tx) {
|
|
948
|
+
return tx.identifiers().at(0);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
proofErased = {
|
|
952
|
+
getImbalances(tx) {
|
|
953
|
+
return TransactionOps$1.shared.getImbalances(tx);
|
|
954
|
+
},
|
|
955
|
+
id(tx) {
|
|
956
|
+
return tx.identifiers().at(0);
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
unproven = {
|
|
960
|
+
getImbalances(tx) {
|
|
961
|
+
return TransactionOps$1.shared.getImbalances(tx);
|
|
962
|
+
},
|
|
963
|
+
id(tx) {
|
|
964
|
+
return tx.identifiers().at(0);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
shared = {
|
|
968
|
+
getImbalances(tx) {
|
|
969
|
+
return {
|
|
970
|
+
guaranteed: TransactionOps$1.shared.getGuaranteedImbalances(tx),
|
|
971
|
+
fallible: TransactionOps$1.shared.getFallibleImbalances(tx)
|
|
972
|
+
};
|
|
973
|
+
},
|
|
974
|
+
getGuaranteedImbalances: (tx) => {
|
|
975
|
+
const rawGuaranteedImbalances = tx.imbalances(0).entries().filter(([token]) => token.tag === "shielded").map(([token, value]) => {
|
|
976
|
+
return [token.raw, value];
|
|
977
|
+
});
|
|
978
|
+
return require_dist.Imbalances.fromEntries(rawGuaranteedImbalances);
|
|
979
|
+
},
|
|
980
|
+
getFallibleImbalances: (tx) => {
|
|
981
|
+
const fallibleImbalances = Array.from(tx.fallibleOffer?.keys() ?? []).flatMap((segment) => {
|
|
982
|
+
const rawImbalances = tx.imbalances(segment).entries().filter(([token]) => token.tag === "shielded").map(([token, value]) => {
|
|
983
|
+
return [token.raw, value];
|
|
984
|
+
});
|
|
985
|
+
return [[segment, require_dist.Imbalances.fromEntries(rawImbalances)]];
|
|
986
|
+
});
|
|
987
|
+
return new Map(fallibleImbalances);
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
}();
|
|
991
|
+
//#endregion
|
|
992
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/Transacting.js
|
|
993
|
+
const makeDefaultTransactingCapability$1 = (config, getContext) => {
|
|
994
|
+
return new TransactingCapabilityImplementation$1(config.networkId, () => getContext().coinSelection, () => getContext().coinsAndBalancesCapability, () => getContext().keysCapability, TransactionOps$1.default);
|
|
995
|
+
};
|
|
996
|
+
var TransactingCapabilityImplementation$1 = class {
|
|
997
|
+
networkId;
|
|
998
|
+
getCoinSelection;
|
|
999
|
+
txOps;
|
|
1000
|
+
getCoins;
|
|
1001
|
+
getKeys;
|
|
1002
|
+
constructor(networkId, getCoinSelection, getCoins, getKeys, txOps) {
|
|
1003
|
+
this.getCoins = getCoins;
|
|
1004
|
+
this.networkId = networkId;
|
|
1005
|
+
this.getCoinSelection = getCoinSelection;
|
|
1006
|
+
this.getKeys = getKeys;
|
|
1007
|
+
this.txOps = txOps;
|
|
1008
|
+
}
|
|
1009
|
+
balanceTransaction(secretKeys, state, tx) {
|
|
1010
|
+
return require_dist.gen$1(this, function* () {
|
|
1011
|
+
const coinSelection = this.getCoinSelection();
|
|
1012
|
+
const initialImbalances = this.txOps.getImbalances(tx);
|
|
1013
|
+
if (TransactionImbalances$1.areBalanced(initialImbalances)) return [void 0, state];
|
|
1014
|
+
const { newState: afterFallible, fallibleOffers } = yield* this.balanceFallibleSection(secretKeys, state, initialImbalances, coinSelection);
|
|
1015
|
+
const { newState: afterGuaranteed, offer: guaranteed } = yield* this.#balanceGuaranteedSection(secretKeys, afterFallible, initialImbalances, coinSelection, require_dist.Imbalances.empty());
|
|
1016
|
+
return [Array.from(fallibleOffers.entries()).reduce((tx, [segment, offer]) => tx.addZswapOffer({
|
|
1017
|
+
tag: "specific",
|
|
1018
|
+
value: segment
|
|
1019
|
+
}, offer), _midnightntwrk_ledger_v9.Transaction.fromParts(this.networkId, guaranteed)), afterGuaranteed];
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
makeTransfer(secretKeys, state, transfers) {
|
|
1023
|
+
return require_dist.gen$1(this, function* () {
|
|
1024
|
+
const positiveTransfers = yield* require_dist.pipe(transfers, require_dist.filter$1((t) => t.amount > 0n), require_dist.match({
|
|
1025
|
+
onEmpty: () => require_dist.left(new OtherWalletError$1({ message: "The amount needs to be positive" })),
|
|
1026
|
+
onNonEmpty: (nonEmpty) => require_dist.right(nonEmpty)
|
|
1027
|
+
}));
|
|
1028
|
+
const networkId = this.networkId;
|
|
1029
|
+
const { initialOffersAndCoins, selfCoins } = yield* this.#processDesiredOutputs(state, positiveTransfers);
|
|
1030
|
+
const offerToBalance = require_dist.pipe(initialOffersAndCoins, require_dist.map$3((o) => o.outputOffer), require_dist.fold((a, b) => a.merge(b)));
|
|
1031
|
+
const unprovenTxToBalance = _midnightntwrk_ledger_v9.Transaction.fromParts(networkId, offerToBalance);
|
|
1032
|
+
const imbalances = TransactionOps$1.unproven.getImbalances(unprovenTxToBalance);
|
|
1033
|
+
const { offer, newState } = yield* this.#balanceGuaranteedSection(secretKeys, state, imbalances, this.getCoinSelection(), require_dist.Imbalances.empty());
|
|
1034
|
+
const finalState = CoreWallet$1.watchCoins(newState, secretKeys, selfCoins);
|
|
1035
|
+
return [unprovenTxToBalance.merge(_midnightntwrk_ledger_v9.Transaction.fromParts(networkId, offer)), finalState];
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
initSwap(secretKeys, state, desiredInputs, desiredOutputs) {
|
|
1039
|
+
return require_dist.gen$1(this, function* () {
|
|
1040
|
+
if (!desiredOutputs.every((output) => output.amount > 0n)) return yield* require_dist.left(new OtherWalletError$1({ message: "The amount needs to be positive" }));
|
|
1041
|
+
if (!Object.entries(desiredInputs).every(([, amount]) => amount > 0n)) return yield* require_dist.left(new OtherWalletError$1({ message: "The input amounts need to be positive" }));
|
|
1042
|
+
const outputsParseResult = yield* this.#processDesiredOutputsPossiblyEmpty(state, desiredOutputs);
|
|
1043
|
+
const inputsParseResult = require_dist.Imbalances.fromEntries(require_dist.toEntries(desiredInputs));
|
|
1044
|
+
const networkId = this.networkId;
|
|
1045
|
+
const { offer, newState } = yield* this.#balanceGuaranteedSection(secretKeys, state, TransactionImbalances$1.empty(), this.getCoinSelection(), inputsParseResult);
|
|
1046
|
+
const finalState = CoreWallet$1.watchCoins(newState, secretKeys, outputsParseResult.selfCoins);
|
|
1047
|
+
const balancingTx = _midnightntwrk_ledger_v9.Transaction.fromParts(networkId, offer);
|
|
1048
|
+
return [outputsParseResult.unprovenTxToBalance ? outputsParseResult.unprovenTxToBalance.merge(balancingTx) : balancingTx, finalState];
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
revertTransaction(state, transaction) {
|
|
1052
|
+
return require_dist.try_$1({
|
|
1053
|
+
try: () => {
|
|
1054
|
+
return CoreWallet$1.revertTransaction(state, transaction);
|
|
1055
|
+
},
|
|
1056
|
+
catch: (err) => {
|
|
1057
|
+
return new OtherWalletError$1({
|
|
1058
|
+
message: `Error while reverting transaction ${transaction.identifiers().at(0)}`,
|
|
1059
|
+
cause: err
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
#prepareOffer(secretKeys, state, recipe, segment) {
|
|
1065
|
+
const [inputOffers, stateAfterSpends] = CoreWallet$1.spendCoins(state, secretKeys, recipe.inputs, segment);
|
|
1066
|
+
const stateAfterWatches = CoreWallet$1.watchCoins(stateAfterSpends, secretKeys, recipe.outputs);
|
|
1067
|
+
const outputOffers = recipe.outputs.map((coin) => {
|
|
1068
|
+
const output = _midnightntwrk_ledger_v9.ZswapOutput.new(coin, segment, this.getKeys().getCoinPublicKey(state).toHexString(), this.getKeys().getEncryptionPublicKey(state).toHexString());
|
|
1069
|
+
return _midnightntwrk_ledger_v9.ZswapOffer.fromOutput(output, coin.type, coin.value);
|
|
1070
|
+
});
|
|
1071
|
+
return require_dist.pipe(require_dist.appendAll(inputOffers, outputOffers), require_dist.match({
|
|
1072
|
+
onEmpty: () => require_dist.none(),
|
|
1073
|
+
onNonEmpty: (nonEmpty) => require_dist.pipe(nonEmpty, require_dist.fold((a, b) => a.merge(b)), require_dist.some)
|
|
1074
|
+
}), require_dist.map$5((offer) => ({
|
|
1075
|
+
offer,
|
|
1076
|
+
newState: stateAfterWatches
|
|
1077
|
+
})));
|
|
1078
|
+
}
|
|
1079
|
+
balanceFallibleSection(secretKeys, state, imbalances, coinSelection) {
|
|
1080
|
+
return Array.from(imbalances.fallible.entries()).reduce((acc, [segment, segmentImbalances]) => require_dist.flatMap$4(acc, ({ fallibleOffers, newState }) => require_dist.pipe(require_dist.try_$1({
|
|
1081
|
+
try: () => {
|
|
1082
|
+
const fallibleBalanceRecipe = require_dist.getBalanceRecipe({
|
|
1083
|
+
coins: this.getCoins().getAvailableCoins(newState).map((c) => c.coin),
|
|
1084
|
+
initialImbalances: segmentImbalances,
|
|
1085
|
+
transactionCostModel: ShieldedCostModel$1,
|
|
1086
|
+
feeTokenType: "",
|
|
1087
|
+
coinSelection,
|
|
1088
|
+
createOutput: (coin) => _midnightntwrk_ledger_v9.createShieldedCoinInfo(coin.type, coin.value),
|
|
1089
|
+
isCoinEqual: (a, b) => a.nonce === b.nonce
|
|
1090
|
+
});
|
|
1091
|
+
return this.#prepareOffer(secretKeys, newState, fallibleBalanceRecipe, segment);
|
|
1092
|
+
},
|
|
1093
|
+
catch: (err) => {
|
|
1094
|
+
if (err instanceof require_dist.InsufficientFundsError) return new InsufficientFundsError$1({
|
|
1095
|
+
message: `Insufficient funds for fallible segment ${segment}`,
|
|
1096
|
+
tokenType: err.tokenType,
|
|
1097
|
+
amount: segmentImbalances.get(err.tokenType) ?? 0n
|
|
1098
|
+
});
|
|
1099
|
+
return new OtherWalletError$1({
|
|
1100
|
+
message: `Balancing fallible segment ${segment} failed`,
|
|
1101
|
+
cause: err
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
}), require_dist.map$6(require_dist.match$1({
|
|
1105
|
+
onNone: () => ({
|
|
1106
|
+
fallibleOffers,
|
|
1107
|
+
newState
|
|
1108
|
+
}),
|
|
1109
|
+
onSome: (res) => ({
|
|
1110
|
+
fallibleOffers: new Map([...fallibleOffers, [segment, res.offer]]),
|
|
1111
|
+
newState: res.newState
|
|
1112
|
+
})
|
|
1113
|
+
})))), require_dist.right({
|
|
1114
|
+
fallibleOffers: /* @__PURE__ */ new Map(),
|
|
1115
|
+
newState: state
|
|
1116
|
+
}));
|
|
1117
|
+
}
|
|
1118
|
+
#balanceGuaranteedSection(secretKeys, state, imbalances, coinSelection, targetImbalances) {
|
|
1119
|
+
return require_dist.gen$1(this, function* () {
|
|
1120
|
+
const balanceRecipe = yield* require_dist.try_$1({
|
|
1121
|
+
try: () => require_dist.getBalanceRecipe({
|
|
1122
|
+
coins: this.getCoins().getAvailableCoins(state).map((c) => c.coin),
|
|
1123
|
+
initialImbalances: imbalances.guaranteed,
|
|
1124
|
+
transactionCostModel: ShieldedCostModel$1,
|
|
1125
|
+
feeTokenType: "",
|
|
1126
|
+
coinSelection,
|
|
1127
|
+
createOutput: (coin) => _midnightntwrk_ledger_v9.createShieldedCoinInfo(coin.type, coin.value),
|
|
1128
|
+
isCoinEqual: (a, b) => a.nonce === b.nonce,
|
|
1129
|
+
targetImbalances
|
|
1130
|
+
}),
|
|
1131
|
+
catch: (err) => {
|
|
1132
|
+
if (err instanceof require_dist.InsufficientFundsError) return new InsufficientFundsError$1({
|
|
1133
|
+
message: "Insufficient funds",
|
|
1134
|
+
tokenType: err.tokenType,
|
|
1135
|
+
amount: imbalances.guaranteed.get(err.tokenType) ?? 0n
|
|
1136
|
+
});
|
|
1137
|
+
else return new OtherWalletError$1({
|
|
1138
|
+
message: "Balancing guaranteed section failed",
|
|
1139
|
+
cause: err
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
return require_dist.pipe(this.#prepareOffer(secretKeys, state, balanceRecipe, 0), require_dist.match$1({
|
|
1144
|
+
onNone: () => ({
|
|
1145
|
+
offer: void 0,
|
|
1146
|
+
newState: state
|
|
1147
|
+
}),
|
|
1148
|
+
onSome: (result) => result
|
|
1149
|
+
}));
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
#processDesiredOutputs(state, transfers) {
|
|
1153
|
+
return require_dist.try_$1({
|
|
1154
|
+
try: () => {
|
|
1155
|
+
const initialOffersAndCoins = require_dist.pipe(transfers, require_dist.map$3((transfer) => {
|
|
1156
|
+
const { receiverAddress, type, amount } = transfer;
|
|
1157
|
+
const coin = _midnightntwrk_ledger_v9.createShieldedCoinInfo(type, amount);
|
|
1158
|
+
const output = _midnightntwrk_ledger_v9.ZswapOutput.new(coin, 0, receiverAddress.coinPublicKey.toHexString(), receiverAddress.encryptionPublicKey.toHexString());
|
|
1159
|
+
return {
|
|
1160
|
+
coin,
|
|
1161
|
+
outputOffer: _midnightntwrk_ledger_v9.ZswapOffer.fromOutput(output, type, amount),
|
|
1162
|
+
isForSelf: receiverAddress.coinPublicKey.equals(this.getKeys().getCoinPublicKey(state))
|
|
1163
|
+
};
|
|
1164
|
+
}));
|
|
1165
|
+
return {
|
|
1166
|
+
initialOffersAndCoins,
|
|
1167
|
+
selfCoins: require_dist.flatMap$2(initialOffersAndCoins, ({ coin, isForSelf }) => {
|
|
1168
|
+
if (isForSelf) return [coin];
|
|
1169
|
+
else return [];
|
|
1170
|
+
})
|
|
1171
|
+
};
|
|
1172
|
+
},
|
|
1173
|
+
catch: (err) => {
|
|
1174
|
+
return new OtherWalletError$1({
|
|
1175
|
+
message: "Failed to process desired outputs",
|
|
1176
|
+
cause: err
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
#processDesiredOutputsPossiblyEmpty(state, desiredOutputs) {
|
|
1182
|
+
return require_dist.pipe(desiredOutputs, require_dist.match({
|
|
1183
|
+
onEmpty: () => {
|
|
1184
|
+
return require_dist.right({
|
|
1185
|
+
imbalances: TransactionImbalances$1.empty(),
|
|
1186
|
+
selfCoins: [],
|
|
1187
|
+
unprovenTxToBalance: null
|
|
1188
|
+
});
|
|
1189
|
+
},
|
|
1190
|
+
onNonEmpty: (desiredOutputs) => {
|
|
1191
|
+
return require_dist.pipe(this.#processDesiredOutputs(state, desiredOutputs), require_dist.map$6(({ initialOffersAndCoins, selfCoins }) => {
|
|
1192
|
+
const networkId = this.networkId;
|
|
1193
|
+
const offerToBalance = require_dist.pipe(initialOffersAndCoins, require_dist.map$3((o) => o.outputOffer), require_dist.fold((a, b) => a.merge(b)));
|
|
1194
|
+
const unprovenTxToBalance = _midnightntwrk_ledger_v9.Transaction.fromParts(networkId, offerToBalance);
|
|
1195
|
+
return {
|
|
1196
|
+
imbalances: TransactionOps$1.unproven.getImbalances(unprovenTxToBalance),
|
|
1197
|
+
selfCoins,
|
|
1198
|
+
unprovenTxToBalance
|
|
1199
|
+
};
|
|
1200
|
+
}));
|
|
1201
|
+
}
|
|
1202
|
+
}));
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
//#endregion
|
|
1206
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/CoinsAndBalances.js
|
|
1207
|
+
const calculateBalances$1 = (coins) => coins.reduce((acc, { coin }) => ({
|
|
1208
|
+
...acc,
|
|
1209
|
+
[coin.type]: acc[coin.type] === void 0 ? coin.value : acc[coin.type] + coin.value
|
|
1210
|
+
}), {});
|
|
1211
|
+
const makeDefaultCoinsAndBalancesCapability$1 = () => {
|
|
1212
|
+
const getAvailableBalances = (state) => {
|
|
1213
|
+
return calculateBalances$1(getAvailableCoins(state));
|
|
1214
|
+
};
|
|
1215
|
+
const getPendingBalances = (state) => {
|
|
1216
|
+
return calculateBalances$1(getPendingCoins(state));
|
|
1217
|
+
};
|
|
1218
|
+
const getTotalBalances = (state) => {
|
|
1219
|
+
return require_dist.pipe([getAvailableBalances(state), getPendingBalances(state)], require_dist.mergeWithAccumulator(0n, (a, b) => a + b));
|
|
1220
|
+
};
|
|
1221
|
+
const getAvailableCoins = (state) => {
|
|
1222
|
+
const pendingSpends = new Set([...state.state.pendingSpends.values()].map(([coin]) => coin.nonce));
|
|
1223
|
+
return require_dist.pipe([...state.state.coins], require_dist.filter$1((coin) => !pendingSpends.has(coin.nonce)), require_dist.filterMap$1((coin) => require_dist.pipe(require_dist.fromNullable(state.coinHashes[coin.nonce]), require_dist.map$5(({ commitment, nullifier }) => ({
|
|
1224
|
+
coin,
|
|
1225
|
+
commitment,
|
|
1226
|
+
nullifier
|
|
1227
|
+
})))));
|
|
1228
|
+
};
|
|
1229
|
+
const getPendingCoins = (state) => require_dist.pipe([...state.state.pendingOutputs.values()], require_dist.filterMap$1(([coin, ttl]) => require_dist.pipe(require_dist.fromNullable(state.coinHashes[coin.nonce]), require_dist.map$5(({ commitment, nullifier }) => ({
|
|
1230
|
+
coin,
|
|
1231
|
+
ttl,
|
|
1232
|
+
commitment,
|
|
1233
|
+
nullifier
|
|
1234
|
+
})))));
|
|
1235
|
+
const getTotalCoins = (state) => [...getAvailableCoins(state), ...getPendingCoins(state)];
|
|
1236
|
+
return {
|
|
1237
|
+
getAvailableBalances,
|
|
1238
|
+
getPendingBalances,
|
|
1239
|
+
getTotalBalances,
|
|
1240
|
+
getAvailableCoins,
|
|
1241
|
+
getPendingCoins,
|
|
1242
|
+
getTotalCoins
|
|
1243
|
+
};
|
|
1244
|
+
};
|
|
1245
|
+
//#endregion
|
|
1246
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/Keys.js
|
|
1247
|
+
require__polyfill_buffer_patch.init__polyfill_buffer_patch();
|
|
1248
|
+
const makeDefaultKeysCapability$1 = () => {
|
|
1249
|
+
return {
|
|
1250
|
+
getCoinPublicKey: (state) => {
|
|
1251
|
+
return new require_dist.ShieldedCoinPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.coinPublicKey, "hex"));
|
|
1252
|
+
},
|
|
1253
|
+
getEncryptionPublicKey: (state) => {
|
|
1254
|
+
return new require_dist.ShieldedEncryptionPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.encryptionPublicKey, "hex"));
|
|
1255
|
+
},
|
|
1256
|
+
getAddress: (state) => {
|
|
1257
|
+
return new require_dist.ShieldedAddress(new require_dist.ShieldedCoinPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.coinPublicKey, "hex")), new require_dist.ShieldedEncryptionPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.encryptionPublicKey, "hex")));
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
};
|
|
1261
|
+
//#endregion
|
|
1262
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/TransactionHistory.js
|
|
1263
|
+
const QualifiedShieldedCoinInfoSchema$1 = require_dist.Struct({
|
|
1264
|
+
type: require_dist.String$,
|
|
1265
|
+
nonce: require_dist.String$,
|
|
1266
|
+
value: require_dist.BigInt$,
|
|
1267
|
+
mtIndex: require_dist.BigInt$
|
|
1268
|
+
});
|
|
1269
|
+
const ShieldedSectionSchema = require_dist.Struct({
|
|
1270
|
+
receivedCoins: require_dist.Array$(QualifiedShieldedCoinInfoSchema$1),
|
|
1271
|
+
spentCoins: require_dist.Array$(QualifiedShieldedCoinInfoSchema$1)
|
|
1272
|
+
});
|
|
1273
|
+
require_dist.extendEntrySchema({ shielded: require_dist.optional(ShieldedSectionSchema) });
|
|
1274
|
+
const coinEquals$1 = require_dist.equivalence(QualifiedShieldedCoinInfoSchema$1);
|
|
1275
|
+
const mergeShieldedSections = (existing, incoming) => ({
|
|
1276
|
+
receivedCoins: require_dist.unionWith(existing.receivedCoins, incoming.receivedCoins, coinEquals$1),
|
|
1277
|
+
spentCoins: require_dist.unionWith(existing.spentCoins, incoming.spentCoins, coinEquals$1)
|
|
1278
|
+
});
|
|
1279
|
+
const convertUpdateToFinalizedInput$1 = (changes, metadata, protocolVersion) => ({
|
|
1280
|
+
hash: changes.source,
|
|
1281
|
+
protocolVersion,
|
|
1282
|
+
status: metadata.status,
|
|
1283
|
+
identifiers: metadata.identifiers,
|
|
1284
|
+
finalizedBlock: {
|
|
1285
|
+
hash: metadata.block.hash,
|
|
1286
|
+
height: metadata.block.height,
|
|
1287
|
+
timestamp: new Date(metadata.block.timestamp)
|
|
1288
|
+
},
|
|
1289
|
+
shielded: {
|
|
1290
|
+
receivedCoins: changes.receivedCoins.map(({ mt_index, ...rest }) => ({
|
|
1291
|
+
...rest,
|
|
1292
|
+
mtIndex: mt_index
|
|
1293
|
+
})),
|
|
1294
|
+
spentCoins: changes.spentCoins.map(({ mt_index, ...rest }) => ({
|
|
1295
|
+
...rest,
|
|
1296
|
+
mtIndex: mt_index
|
|
1297
|
+
}))
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
const gotFinalizedShielded$1 = (txHistoryStorage, input) => require_dist.tryPromise({
|
|
1301
|
+
try: () => txHistoryStorage.gotFinalized(input),
|
|
1302
|
+
catch: (e) => new TransactionHistoryError$1({
|
|
1303
|
+
message: `Failed to record finalized history entry for ${input.hash}`,
|
|
1304
|
+
cause: e
|
|
1305
|
+
})
|
|
1306
|
+
});
|
|
1307
|
+
const makeDefaultTransactionHistoryService$1 = (config, _getContext) => {
|
|
1308
|
+
const txHistoryStorage = config.txHistoryStorage;
|
|
1309
|
+
const queryClientLayer = require_dist.layer$1({ url: config.indexerClientConnection.indexerHttpUrl });
|
|
1310
|
+
const retryWindow = config.transactionDetailsRetryWindow ?? require_dist.minutes(2);
|
|
1311
|
+
return {
|
|
1312
|
+
put: (changes, metadata, protocolVersion) => gotFinalizedShielded$1(txHistoryStorage, convertUpdateToFinalizedInput$1(changes, metadata, protocolVersion)),
|
|
1313
|
+
getTransactionDetails: (hash) => require_dist.gen(function* () {
|
|
1314
|
+
const result = yield* (yield* require_dist.TransactionHistoryDetail)({ transactionHash: hash });
|
|
1315
|
+
const tx = yield* require_dist.head$1(result.transactions).pipe(require_dist.orElseFail(() => new TransactionHistoryError$1({ message: `Indexer has not yet indexed transaction ${hash}` })));
|
|
1316
|
+
const rawStatus = tx.__typename === "RegularTransaction" ? tx.transactionResult.status : void 0;
|
|
1317
|
+
const status = rawStatus === "FAILURE" || rawStatus === "PARTIAL_SUCCESS" ? rawStatus : "SUCCESS";
|
|
1318
|
+
const identifiers = tx.__typename === "RegularTransaction" ? tx.identifiers : [];
|
|
1319
|
+
return {
|
|
1320
|
+
hash: tx.hash,
|
|
1321
|
+
block: {
|
|
1322
|
+
hash: tx.block.hash,
|
|
1323
|
+
height: tx.block.height,
|
|
1324
|
+
timestamp: tx.block.timestamp
|
|
1325
|
+
},
|
|
1326
|
+
status,
|
|
1327
|
+
identifiers
|
|
1328
|
+
};
|
|
1329
|
+
}).pipe(require_dist.provide(queryClientLayer), require_dist.scoped, require_dist.retry$1({
|
|
1330
|
+
schedule: require_dist.exponential(require_dist.seconds(1)).pipe(require_dist.either(require_dist.spaced(require_dist.seconds(10))), require_dist.jittered, require_dist.upTo(retryWindow)),
|
|
1331
|
+
while: (error) => error instanceof TransactionHistoryError$1
|
|
1332
|
+
}), require_dist.mapError$2((error) => error instanceof TransactionHistoryError$1 ? error : new TransactionHistoryError$1({
|
|
1333
|
+
message: `Failed to fetch transaction metadata for ${hash}`,
|
|
1334
|
+
cause: error
|
|
1335
|
+
})))
|
|
1336
|
+
};
|
|
1337
|
+
};
|
|
1338
|
+
//#endregion
|
|
1339
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v2/V2Builder.js
|
|
1340
|
+
var V2Builder = class V2Builder {
|
|
1341
|
+
#buildState;
|
|
1342
|
+
constructor(buildState = {}) {
|
|
1343
|
+
this.#buildState = buildState;
|
|
1344
|
+
}
|
|
1345
|
+
withDefaults() {
|
|
1346
|
+
return this.withDefaultTransactionType().withSyncDefaults().withSerializationDefaults().withTransactingDefaults().withCoinsAndBalancesDefaults().withTransactionHistoryDefaults().withKeysDefaults().withStartAuxDefaults().withCoinSelectionDefaults();
|
|
1347
|
+
}
|
|
1348
|
+
withTransactionType() {
|
|
1349
|
+
return new V2Builder({
|
|
1350
|
+
...this.#buildState,
|
|
1351
|
+
transactingCapability: void 0,
|
|
1352
|
+
transactionHistoryService: void 0
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
withDefaultTransactionType() {
|
|
1356
|
+
return this.withTransactionType();
|
|
1357
|
+
}
|
|
1358
|
+
withSyncDefaults() {
|
|
1359
|
+
return this.withSync(makeEventsSyncService$1, makeEventsSyncCapability$1);
|
|
1360
|
+
}
|
|
1361
|
+
withSync(syncService, syncCapability) {
|
|
1362
|
+
return new V2Builder({
|
|
1363
|
+
...this.#buildState,
|
|
1364
|
+
syncService,
|
|
1365
|
+
syncCapability,
|
|
1366
|
+
startAux: void 0
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
withSerializationDefaults() {
|
|
1370
|
+
return this.withSerialization(makeDefaultV2SerializationCapability);
|
|
1371
|
+
}
|
|
1372
|
+
withSerialization(serializationCapability) {
|
|
1373
|
+
return new V2Builder({
|
|
1374
|
+
...this.#buildState,
|
|
1375
|
+
serializationCapability
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
withTransactingDefaults() {
|
|
1379
|
+
return this.withTransacting(makeDefaultTransactingCapability$1);
|
|
1380
|
+
}
|
|
1381
|
+
withTransacting(transactingCapability) {
|
|
1382
|
+
return new V2Builder({
|
|
1383
|
+
...this.#buildState,
|
|
1384
|
+
transactingCapability
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
withCoinSelection(coinSelection) {
|
|
1388
|
+
return new V2Builder({
|
|
1389
|
+
...this.#buildState,
|
|
1390
|
+
coinSelection
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
withCoinSelectionDefaults() {
|
|
1394
|
+
return this.withCoinSelection(() => require_dist.chooseCoin);
|
|
1395
|
+
}
|
|
1396
|
+
withCoinsAndBalancesDefaults() {
|
|
1397
|
+
return this.withCoinsAndBalances(makeDefaultCoinsAndBalancesCapability$1);
|
|
1398
|
+
}
|
|
1399
|
+
withCoinsAndBalances(coinsAndBalancesCapability) {
|
|
1400
|
+
return new V2Builder({
|
|
1401
|
+
...this.#buildState,
|
|
1402
|
+
coinsAndBalancesCapability
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
withTransactionHistoryDefaults() {
|
|
1406
|
+
return this.withTransactionHistory(makeDefaultTransactionHistoryService$1);
|
|
1407
|
+
}
|
|
1408
|
+
withTransactionHistory(transactionHistoryService) {
|
|
1409
|
+
return new V2Builder({
|
|
1410
|
+
...this.#buildState,
|
|
1411
|
+
transactionHistoryService
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
withKeysDefaults() {
|
|
1415
|
+
return this.withKeys(makeDefaultKeysCapability$1);
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Uses the default start-aux derivation: this ledger version's Zswap secret keys, derived from the seed.
|
|
1419
|
+
*
|
|
1420
|
+
* @remarks
|
|
1421
|
+
* The seed is the only key material that crosses a protocol boundary, so every variant must be able to produce its
|
|
1422
|
+
* own from one. This is that derivation for this ledger version; a builder whose sync service expects something
|
|
1423
|
+
* else supplies its own with {@link V2Builder.withStartAux}.
|
|
1424
|
+
*/
|
|
1425
|
+
withStartAuxDefaults() {
|
|
1426
|
+
return this.withStartAux({ fromSeed: (seed) => _midnightntwrk_ledger_v9.ZswapSecretKeys.fromSeed(seed) });
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Chooses how this variant derives the key material its synchronization is started with from a seed.
|
|
1430
|
+
*
|
|
1431
|
+
* @param startAux The derivation.
|
|
1432
|
+
* @returns A builder that produces a variant able to start sync from a seed alone.
|
|
1433
|
+
*/
|
|
1434
|
+
withStartAux(startAux) {
|
|
1435
|
+
return new V2Builder({
|
|
1436
|
+
...this.#buildState,
|
|
1437
|
+
startAux
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Uses the default migration: an empty wallet built from nothing.
|
|
1442
|
+
*
|
|
1443
|
+
* @remarks
|
|
1444
|
+
* This is what an unconfigured builder already does, so calling it changes no behaviour — it states the choice rather
|
|
1445
|
+
* than inheriting it. Registering this variant as the target of a real fork means calling
|
|
1446
|
+
* {@link V2Builder.withMigration} with {@link makeCrossLedgerMigration} instead.
|
|
1447
|
+
*/
|
|
1448
|
+
withMigrationDefaults() {
|
|
1449
|
+
return this.withMigration((configuration) => makeEmptyWalletMigration$1(configuration));
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Chooses how this variant produces its first state from the state that preceded it.
|
|
1453
|
+
*
|
|
1454
|
+
* @remarks
|
|
1455
|
+
* The strategy's input type becomes the variant's `TPreviousState`, which is what the runtime type-checks a
|
|
1456
|
+
* registration against: a variant declaring it migrates from a ledger-v8 wallet cannot be registered after one that
|
|
1457
|
+
* produces something else.
|
|
1458
|
+
* @example
|
|
1459
|
+
* ```typescript
|
|
1460
|
+
* const forkTarget = new V2Builder().withDefaults().withMigration(makeCrossLedgerMigration);
|
|
1461
|
+
* ```;
|
|
1462
|
+
*
|
|
1463
|
+
* @param migration Builds the migration from the configuration and the sibling capabilities.
|
|
1464
|
+
*/
|
|
1465
|
+
withMigration(migration) {
|
|
1466
|
+
const capabilities = this.#buildState;
|
|
1467
|
+
return new V2Builder({
|
|
1468
|
+
...capabilities,
|
|
1469
|
+
migration
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
withKeys(keysCapability) {
|
|
1473
|
+
return new V2Builder({
|
|
1474
|
+
...this.#buildState,
|
|
1475
|
+
keysCapability
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
build(configuration) {
|
|
1479
|
+
const v2Context = this.#buildContextFromBuildState(configuration);
|
|
1480
|
+
const migration = this.#resolveMigration(configuration, () => v2Context);
|
|
1481
|
+
return {
|
|
1482
|
+
__polyTag__: V2Tag,
|
|
1483
|
+
coinsAndBalances: v2Context.coinsAndBalancesCapability,
|
|
1484
|
+
keys: v2Context.keysCapability,
|
|
1485
|
+
serialization: v2Context.serializationCapability,
|
|
1486
|
+
transactionHistory: v2Context.transactionHistoryService,
|
|
1487
|
+
startAux: this.#resolveStartAux(),
|
|
1488
|
+
start(context) {
|
|
1489
|
+
return require_dist.gen(function* () {
|
|
1490
|
+
return new RunningV2Variant(yield* require_dist.Scope, context, v2Context);
|
|
1491
|
+
});
|
|
1492
|
+
},
|
|
1493
|
+
migrateState: (previousState) => migration.migrate(previousState).pipe(require_dist.mapError$2((error) => new require_dist.WalletRuntimeError({
|
|
1494
|
+
message: "Failed to migrate shielded wallet state into this variant",
|
|
1495
|
+
cause: error
|
|
1496
|
+
}))),
|
|
1497
|
+
deserializeState: (serialized) => {
|
|
1498
|
+
return v2Context.serializationCapability.deserialize(null, serialized);
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* Resolves the configured migration, or the empty-wallet fallback when none was configured.
|
|
1504
|
+
*
|
|
1505
|
+
* @remarks
|
|
1506
|
+
* The fallback is written as a nullary function on purpose. It ignores whatever preceded it — it builds an empty
|
|
1507
|
+
* wallet from nothing — which makes it a valid migration from _any_ previous state, but a `StateMigration<null>`
|
|
1508
|
+
* value could only be widened to `StateMigration<TPreviousState>` through a cast. Declaring no parameter says the
|
|
1509
|
+
* same thing to the type system without one.
|
|
1510
|
+
*/
|
|
1511
|
+
/**
|
|
1512
|
+
* Resolves the configured start-aux derivation.
|
|
1513
|
+
*
|
|
1514
|
+
* @remarks
|
|
1515
|
+
* Unlike the migration there is no sensible fallback: the default derivation produces this ledger version's secret
|
|
1516
|
+
* keys, which is only correct for a builder that kept a sync service expecting them. A builder that replaced sync
|
|
1517
|
+
* and did not say how to derive its own key material is misconfigured, and is told so at build time rather than
|
|
1518
|
+
* silently handed key objects of the wrong shape at the first migration.
|
|
1519
|
+
*/
|
|
1520
|
+
#resolveStartAux() {
|
|
1521
|
+
const configured = this.#buildState.startAux;
|
|
1522
|
+
if (configured === void 0) throw new Error("Not all components are configured in V2 Builder: startAux");
|
|
1523
|
+
return configured;
|
|
1524
|
+
}
|
|
1525
|
+
#resolveMigration(configuration, getContext) {
|
|
1526
|
+
const configured = this.#buildState.migration;
|
|
1527
|
+
return configured === void 0 ? { migrate: () => makeEmptyWalletMigration$1(configuration).migrate(null) } : configured(configuration, getContext);
|
|
1528
|
+
}
|
|
1529
|
+
#buildContextFromBuildState(configuration) {
|
|
1530
|
+
if (!isBuildStateFull$1(this.#buildState)) throw new Error("Not all components are configured in V2 Builder");
|
|
1531
|
+
const { syncCapability, syncService, transactingCapability, serializationCapability, coinSelection, coinsAndBalancesCapability, keysCapability, transactionHistoryService } = this.#buildState;
|
|
1532
|
+
const getContext = () => context;
|
|
1533
|
+
const context = {
|
|
1534
|
+
serializationCapability: serializationCapability(configuration, getContext),
|
|
1535
|
+
syncCapability: syncCapability(configuration, getContext),
|
|
1536
|
+
syncService: syncService(configuration, getContext),
|
|
1537
|
+
transactingCapability: transactingCapability(configuration, getContext),
|
|
1538
|
+
coinsAndBalancesCapability: coinsAndBalancesCapability(configuration, getContext),
|
|
1539
|
+
keysCapability: keysCapability(configuration, getContext),
|
|
1540
|
+
coinSelection: coinSelection(configuration, getContext),
|
|
1541
|
+
transactionHistoryService: transactionHistoryService(configuration, getContext)
|
|
1542
|
+
};
|
|
1543
|
+
return context;
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
const isBuildStateFull$1 = (buildState) => {
|
|
1547
|
+
return [
|
|
1548
|
+
"syncService",
|
|
1549
|
+
"syncCapability",
|
|
1550
|
+
"transactingCapability",
|
|
1551
|
+
"coinSelection",
|
|
1552
|
+
"serializationCapability",
|
|
1553
|
+
"coinsAndBalancesCapability",
|
|
1554
|
+
"keysCapability",
|
|
1555
|
+
"transactionHistoryService"
|
|
1556
|
+
].every((key) => typeof buildState[key] == "function");
|
|
1557
|
+
};
|
|
1558
|
+
//#endregion
|
|
1559
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/SingleVariantShieldedWallet.js
|
|
1560
|
+
/**
|
|
1561
|
+
* A shielded wallet composed from a single variant, which answers for the whole protocol timeline.
|
|
1562
|
+
*
|
|
1563
|
+
* @remarks
|
|
1564
|
+
* The composition for a wallet that is not expected to meet a protocol boundary — a test harness, a simulator-driven
|
|
1565
|
+
* wallet, an application pinned to one protocol version. Its one variant is registered from the minimum supported
|
|
1566
|
+
* version, so it stamps every transaction at that floor and accepts one of any version; the price is that it cannot
|
|
1567
|
+
* cross a protocol boundary. The wallet that can is `ShieldedWallet`, in `ShieldedWallet.ts`.
|
|
1568
|
+
*/
|
|
1569
|
+
/**
|
|
1570
|
+
* Builds a shielded wallet class over a single variant.
|
|
1571
|
+
*
|
|
1572
|
+
* @remarks
|
|
1573
|
+
* One variant, and therefore one ledger version: this is the composition for a wallet that is not expected to meet a
|
|
1574
|
+
* protocol boundary — a test harness, a simulator-driven wallet, an application pinned to one protocol version. The
|
|
1575
|
+
* wallet this package ships is `ShieldedWallet`, which registers a variant either side of the boundary.
|
|
1576
|
+
* @param configuration What the variant is built from.
|
|
1577
|
+
* @param builder The variant builder.
|
|
1578
|
+
* @returns The wallet class.
|
|
1579
|
+
*/
|
|
1580
|
+
function CustomShieldedWallet(configuration, builder) {
|
|
1581
|
+
const buildArgs = [configuration];
|
|
1582
|
+
const BaseWallet = require_dist.WalletBuilder.init().withVariant(require_dist.MinSupportedVersion, builder).build(...buildArgs);
|
|
1583
|
+
return class CustomShieldedWalletImplementation extends BaseWallet {
|
|
1584
|
+
static startWithSecretKeys(secretKeys) {
|
|
1585
|
+
return CustomShieldedWalletImplementation.startFirst(CustomShieldedWalletImplementation, CoreWallet$1.initEmpty(secretKeys, CustomShieldedWalletImplementation.configuration.networkId));
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Builds a wallet from a seed, and remembers the seed.
|
|
1589
|
+
*
|
|
1590
|
+
* @remarks
|
|
1591
|
+
* The seed is the only key material that crosses a protocol boundary, so a wallet built this way can start
|
|
1592
|
+
* synchronization on any variant it is ever migrated to — each derives its own from the seed. A wallet built from
|
|
1593
|
+
* key objects instead can only start the variants it was given objects for.
|
|
1594
|
+
*/
|
|
1595
|
+
static startWithSeed(seed) {
|
|
1596
|
+
const walletSeed = require_dist.WalletSeed(seed);
|
|
1597
|
+
const secretKeys = _midnightntwrk_ledger_v9.ZswapSecretKeys.fromSeed(walletSeed);
|
|
1598
|
+
const wallet = CustomShieldedWalletImplementation.startWithSecretKeys(secretKeys);
|
|
1599
|
+
wallet.#retainSeed(walletSeed);
|
|
1600
|
+
return wallet;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Restores a wallet from a snapshot, into whichever registered variant wrote it.
|
|
1604
|
+
*
|
|
1605
|
+
* @remarks
|
|
1606
|
+
* The snapshot declares the protocol version it was written at, so the variant that can read it is a lookup rather
|
|
1607
|
+
* than an assumption. A snapshot written before snapshots declared a version, or a serialization format this
|
|
1608
|
+
* wallet does not recognise as an envelope at all, restores into the head variant — which is what every restore
|
|
1609
|
+
* did before there was more than one variant to choose between.
|
|
1610
|
+
* @param serializedState The serialized wallet state.
|
|
1611
|
+
* @returns A wallet started from that state, on the variant that owns its protocol version.
|
|
1612
|
+
* @throws UnsupportedSnapshotVersionError if the snapshot declares a version no registered variant reads.
|
|
1613
|
+
*/
|
|
1614
|
+
static restore(serializedState) {
|
|
1615
|
+
const headVariant = require_dist.head(CustomShieldedWalletImplementation.allVariants());
|
|
1616
|
+
const variant = (typeof serializedState === "string" ? variantForSnapshot(serializedState, (version) => CustomShieldedWalletImplementation.variantFor(version), headVariant) : require_dist.right(headVariant)).pipe(require_dist.getOrThrow$1);
|
|
1617
|
+
const deserialized = variant.variant.deserializeState(serializedState).pipe(require_dist.getOrThrow$1);
|
|
1618
|
+
return CustomShieldedWalletImplementation.startAtVariant(CustomShieldedWalletImplementation, variant, deserialized);
|
|
1619
|
+
}
|
|
1620
|
+
state;
|
|
1621
|
+
/**
|
|
1622
|
+
* What the application started this wallet with, kept so synchronization can be started again.
|
|
1623
|
+
*
|
|
1624
|
+
* @remarks
|
|
1625
|
+
* A migration starts a fresh variant whose sync has never run, and sync needs key material. That material cannot
|
|
1626
|
+
* come from the state — it is deliberately absent from anything serialized — and does not exist when the wallet
|
|
1627
|
+
* is first constructed, so it is held here, in memory, for the lifetime of the wallet. Cleared by {@link stop} so
|
|
1628
|
+
* a stopped wallet cannot be silently resurrected by a late activation.
|
|
1629
|
+
*
|
|
1630
|
+
* A retained seed answers for every variant. Retained key objects answer only for the variants they were supplied
|
|
1631
|
+
* for, and accumulate per variant tag as `start` is called, which is the same product a caller holding key
|
|
1632
|
+
* objects for both protocol versions would hand over at once.
|
|
1633
|
+
*/
|
|
1634
|
+
#retainedStartMaterial = require_dist.unsafeMake(require_dist.none());
|
|
1635
|
+
/** Remembers a seed, which supersedes any key objects retained for individual variants. */
|
|
1636
|
+
#retainSeed(seed) {
|
|
1637
|
+
require_dist.set(this.#retainedStartMaterial, require_dist.some(require_dist.fromSeed(seed))).pipe(require_dist.runSync);
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Starts synchronization on a variant that has just become current, with key material it can use.
|
|
1641
|
+
*
|
|
1642
|
+
* @remarks
|
|
1643
|
+
* The derivation is the activating variant's own, so a wallet retaining a seed hands each variant key material
|
|
1644
|
+
* built by its own ledger version. A wallet retaining key objects for other variants only cannot answer, and says
|
|
1645
|
+
* so rather than handing over keys the variant would silently misuse.
|
|
1646
|
+
*/
|
|
1647
|
+
#resumeSyncOn(variantTag, running) {
|
|
1648
|
+
return require_dist.get$1(this.#retainedStartMaterial).pipe(require_dist.flatMap$1(require_dist.match$1({
|
|
1649
|
+
onNone: () => require_dist._void,
|
|
1650
|
+
onSome: (retained) => require_dist.toEffect(require_dist.requireAuxFor(retained, variantTag, (seed) => CustomShieldedWalletImplementation.allVariantsRecord()[variantTag].variant.startAux.fromSeed(seed))).pipe(require_dist.flatMap$1((aux) => running.startSyncInBackground(aux)))
|
|
1651
|
+
})));
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Whether the activation watcher has been registered.
|
|
1655
|
+
*
|
|
1656
|
+
* @remarks
|
|
1657
|
+
* Registration is per wallet, not per `start`: watchers accumulate, so registering on every call would restart sync
|
|
1658
|
+
* once per historical `start` on the next activation. Flipped with `getAndSet` so concurrent `start` calls cannot
|
|
1659
|
+
* both observe it unset.
|
|
1660
|
+
*/
|
|
1661
|
+
#watcherRegistered = require_dist.unsafeMake(false);
|
|
1662
|
+
constructor(runtime, scope) {
|
|
1663
|
+
super(runtime, scope);
|
|
1664
|
+
this.state = this.rawState.pipe(rxjs.map((emission) => ShieldedWalletState.fromVariant(CustomShieldedWalletImplementation.allVariantsRecord()[V2Tag].variant, emission)), rxjs.shareReplay({
|
|
1665
|
+
refCount: true,
|
|
1666
|
+
bufferSize: 1
|
|
1667
|
+
}));
|
|
1668
|
+
}
|
|
1669
|
+
start(secretKeys) {
|
|
1670
|
+
return require_dist.gen(this, function* () {
|
|
1671
|
+
const current = yield* this.runtime.currentVariant;
|
|
1672
|
+
yield* require_dist.update(this.#retainedStartMaterial, (retained) => require_dist.some(require_dist.match$1(retained, {
|
|
1673
|
+
onNone: () => require_dist.forVariant(require_dist.getTag(current), secretKeys),
|
|
1674
|
+
onSome: (existing) => existing._tag === "FromSeed" ? existing : require_dist.forVariants([...existing.byTag, [require_dist.getTag(current), secretKeys]])
|
|
1675
|
+
})));
|
|
1676
|
+
if (!(yield* require_dist.getAndSet(this.#watcherRegistered, true))) yield* this.runtime.onVariantActivation({ [V2Tag]: (v2) => this.#resumeSyncOn(V2Tag, v2) });
|
|
1677
|
+
yield* this.runtime.dispatch({ [V2Tag]: (v2) => v2.startSyncInBackground(secretKeys) });
|
|
1678
|
+
}).pipe(require_dist.runPromise$1);
|
|
1679
|
+
}
|
|
1680
|
+
async stop() {
|
|
1681
|
+
require_dist.set(this.#retainedStartMaterial, require_dist.none()).pipe(require_dist.runSync);
|
|
1682
|
+
await super.stop();
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* The key material this wallet's one variant uses, from what it was started with.
|
|
1686
|
+
*
|
|
1687
|
+
* @remarks
|
|
1688
|
+
* Typed as the variant's own start-aux, which for a single-variant wallet is whatever the application handed to
|
|
1689
|
+
* `start` — there is no other variant to derive for, so a retained seed is only ever used through the variant's
|
|
1690
|
+
* own derivation.
|
|
1691
|
+
*/
|
|
1692
|
+
#requireAux() {
|
|
1693
|
+
return require_dist.gen(this, function* () {
|
|
1694
|
+
const current = yield* this.runtime.currentVariant;
|
|
1695
|
+
const variantTag = require_dist.getTag(current);
|
|
1696
|
+
const retained = yield* require_dist.get$1(this.#retainedStartMaterial);
|
|
1697
|
+
return yield* require_dist.match$1(retained, {
|
|
1698
|
+
onNone: () => require_dist.fail$2(new require_dist.MissingStartAuxError({
|
|
1699
|
+
message: "This wallet holds no key material: it has not been started, or it has been stopped. Start it before asking it to build a transaction.",
|
|
1700
|
+
variantTag
|
|
1701
|
+
})),
|
|
1702
|
+
onSome: (material) => require_dist.toEffect(require_dist.requireAuxFor(material, variantTag, (seed) => CustomShieldedWalletImplementation.allVariantsRecord()[V2Tag].variant.startAux.fromSeed(seed)))
|
|
1703
|
+
});
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
/** The whole of the protocol timeline: one variant answers for every version this wallet will ever see. */
|
|
1707
|
+
static #epoch = require_dist.epochOf(require_dist.MinSupportedVersion, require_dist.MinSupportedVersion);
|
|
1708
|
+
balanceTransaction(tx) {
|
|
1709
|
+
return this.runtime.dispatch({ [V2Tag]: (v2) => require_dist.all([this.#requireAux(), require_dist.toEffect(require_dist.WalletTransaction.unwrapWithin(tx, CustomShieldedWalletImplementation.#epoch))]).pipe(require_dist.flatMap$1(([keys, unwrapped]) => v2.balanceTransaction(keys, unwrapped)), require_dist.map$2((result) => result === void 0 ? void 0 : require_dist.WalletTransaction.adopt("Unproven", result, require_dist.MinSupportedVersion))) }).pipe(require_dist.runPromise$1);
|
|
1710
|
+
}
|
|
1711
|
+
transferTransaction(outputs) {
|
|
1712
|
+
return this.runtime.dispatch({ [V2Tag]: (v2) => this.#requireAux().pipe(require_dist.flatMap$1((keys) => v2.transferTransaction(keys, outputs)), require_dist.map$2((tx) => require_dist.WalletTransaction.adopt("Unproven", tx, require_dist.MinSupportedVersion))) }).pipe(require_dist.runPromise$1);
|
|
1713
|
+
}
|
|
1714
|
+
initSwap(desiredInputs, desiredOutputs) {
|
|
1715
|
+
return this.runtime.dispatch({ [V2Tag]: (v2) => this.#requireAux().pipe(require_dist.flatMap$1((keys) => v2.initSwap(keys, desiredInputs, desiredOutputs)), require_dist.map$2((tx) => require_dist.WalletTransaction.adopt("Unproven", tx, require_dist.MinSupportedVersion))) }).pipe(require_dist.runPromise$1);
|
|
1716
|
+
}
|
|
1717
|
+
revertTransaction(transaction) {
|
|
1718
|
+
return this.runtime.dispatch({ [V2Tag]: (v2) => require_dist.match$2(require_dist.WalletTransaction.unwrapWithin(transaction, CustomShieldedWalletImplementation.#epoch), {
|
|
1719
|
+
onLeft: () => require_dist._void,
|
|
1720
|
+
onRight: (unwrapped) => v2.revertTransaction(unwrapped)
|
|
1721
|
+
}) }).pipe(require_dist.runPromise$1);
|
|
1722
|
+
}
|
|
1723
|
+
waitForSyncedState(allowedGap = 0n) {
|
|
1724
|
+
return rxjs.firstValueFrom(this.state.pipe(rxjs.filter((state) => state.state.progress.isCompleteWithin(allowedGap))));
|
|
1725
|
+
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Serializes the most recent state It's preferable to use [[ShieldedWalletState.serialize]] instead, to know
|
|
1728
|
+
* exactly, which state is serialized
|
|
1729
|
+
*/
|
|
1730
|
+
serializeState() {
|
|
1731
|
+
return rxjs.firstValueFrom(this.state).then((state) => state.serialize());
|
|
1732
|
+
}
|
|
1733
|
+
getAddress() {
|
|
1734
|
+
return rxjs.firstValueFrom(this.state).then((state) => state.address);
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
//#endregion
|
|
1739
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/WalletError.js
|
|
1740
|
+
const WalletError = {
|
|
1741
|
+
other(err) {
|
|
1742
|
+
let message;
|
|
1743
|
+
if (err) if (typeof err == "object" && "message" in err) message = String(err.message);
|
|
1744
|
+
else if (typeof err == "string") message = err;
|
|
1745
|
+
else message = "";
|
|
1746
|
+
else message = "";
|
|
1747
|
+
return new OtherWalletError({
|
|
1748
|
+
message: `Other wallet error: ${message}`,
|
|
1749
|
+
cause: err
|
|
1750
|
+
});
|
|
1751
|
+
},
|
|
1752
|
+
submission(err) {
|
|
1753
|
+
return new SubmissionError({
|
|
1754
|
+
message: `Transaction submission error: ${err && typeof err == "object" && "message" in err ? String(err.message) : ""}`,
|
|
1755
|
+
cause: err
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
var OtherWalletError = class extends require_dist.TaggedError("Wallet.Other") {};
|
|
1760
|
+
var SyncWalletError = class extends require_dist.TaggedError("Wallet.Sync") {};
|
|
1761
|
+
var SubmissionError = class extends require_dist.TaggedError("Wallet.SubmissionWalletError") {};
|
|
1762
|
+
var InsufficientFundsError = class extends require_dist.TaggedError("Wallet.InsufficientFunds") {};
|
|
1763
|
+
var InvalidCoinHashesError = class extends require_dist.TaggedError("Wallet.InvalidCoinHashes") {};
|
|
1764
|
+
var TransactionHistoryError = class extends require_dist.TaggedError("Wallet.TransactionHistory") {};
|
|
1765
|
+
/**
|
|
1766
|
+
* A batch of zswap ledger events was not in ascending id order: an event arrived at or below the one before it, or at
|
|
1767
|
+
* or below the applied cursor.
|
|
1768
|
+
*
|
|
1769
|
+
* @remarks
|
|
1770
|
+
* Order is all the wallet can check: zswap events share one id sequence with dust and contract events in the indexer,
|
|
1771
|
+
* so gaps in the stream are normal and a skipped event is only ever caught by the ledger's own insertion check. The
|
|
1772
|
+
* whole batch is refused, nothing is applied and the cursor stays, so the running variant retries from the same
|
|
1773
|
+
* place.
|
|
1774
|
+
* @example
|
|
1775
|
+
* ```ts
|
|
1776
|
+
* if (error._tag === 'Wallet.OutOfOrderSyncUpdate') console.warn(`expected above ${error.expected}, got ${error.received}`);
|
|
1777
|
+
* ```
|
|
1778
|
+
*/
|
|
1779
|
+
var OutOfOrderSyncUpdateError = class extends require_dist.TaggedError("Wallet.OutOfOrderSyncUpdate") {};
|
|
1780
|
+
//#endregion
|
|
1781
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/CoreWallet.js
|
|
1782
|
+
const PublicKeys = { fromSecretKeys: (secretKeys) => {
|
|
1783
|
+
return {
|
|
1784
|
+
coinPublicKey: secretKeys.coinPublicKey,
|
|
1785
|
+
encryptionPublicKey: secretKeys.encryptionPublicKey
|
|
1786
|
+
};
|
|
1787
|
+
} };
|
|
1788
|
+
const CoinHashesMap = {
|
|
1789
|
+
empty: {},
|
|
1790
|
+
pickAllCoins(state) {
|
|
1791
|
+
return [...state.coins, ...state.pendingOutputs.values().map(([coin]) => coin)];
|
|
1792
|
+
},
|
|
1793
|
+
assertValid(map$7, state) {
|
|
1794
|
+
const coins = CoinHashesMap.pickAllCoins(state);
|
|
1795
|
+
const coinNonces = new Set(require_dist.map$4(coins, (coin) => coin.nonce));
|
|
1796
|
+
const definedNonces = new Set(Object.keys(map$7));
|
|
1797
|
+
const missingNonces = coinNonces.difference(definedNonces);
|
|
1798
|
+
return missingNonces.size === 0 ? require_dist.void_ : require_dist.left(missingNonces);
|
|
1799
|
+
},
|
|
1800
|
+
updateWithCoins(secretKeys, existing, coins) {
|
|
1801
|
+
return require_dist.fromIterableWith(coins, (coin) => [coin.nonce, existing[coin.nonce] ?? {
|
|
1802
|
+
commitment: _midnight_ntwrk_ledger_v8.coinCommitment(coin, secretKeys.coinPublicKey),
|
|
1803
|
+
nullifier: _midnight_ntwrk_ledger_v8.coinNullifier(coin, secretKeys.coinSecretKey)
|
|
1804
|
+
}]);
|
|
1805
|
+
},
|
|
1806
|
+
updateWithNewCoins(secretKeys, existing, coins) {
|
|
1807
|
+
const newMap = CoinHashesMap.updateWithCoins(secretKeys, CoinHashesMap.empty, coins);
|
|
1808
|
+
return require_dist.union$2(existing, newMap, (a) => a);
|
|
1809
|
+
},
|
|
1810
|
+
init(secretKeys, coins) {
|
|
1811
|
+
return CoinHashesMap.updateWithCoins(secretKeys, {}, coins);
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
const CoreWallet = {
|
|
1815
|
+
init(localState, secretKeys, networkId) {
|
|
1816
|
+
return {
|
|
1817
|
+
state: localState,
|
|
1818
|
+
publicKeys: PublicKeys.fromSecretKeys(secretKeys),
|
|
1819
|
+
networkId,
|
|
1820
|
+
coinHashes: CoinHashesMap.init(secretKeys, CoinHashesMap.pickAllCoins(localState)),
|
|
1821
|
+
progress: require_dist.createSyncProgress(),
|
|
1822
|
+
protocolVersion: require_dist.MinSupportedVersion
|
|
1823
|
+
};
|
|
1824
|
+
},
|
|
1825
|
+
empty(publicKeys, networkId) {
|
|
1826
|
+
return {
|
|
1827
|
+
state: new _midnight_ntwrk_ledger_v8.ZswapLocalState(),
|
|
1828
|
+
publicKeys,
|
|
1829
|
+
networkId,
|
|
1830
|
+
coinHashes: CoinHashesMap.empty,
|
|
1831
|
+
progress: require_dist.createSyncProgress(),
|
|
1832
|
+
protocolVersion: require_dist.MinSupportedVersion
|
|
1833
|
+
};
|
|
1834
|
+
},
|
|
1835
|
+
restore(localState, secretKeys, syncProgress, protocolVersion, networkId) {
|
|
1836
|
+
return {
|
|
1837
|
+
state: localState,
|
|
1838
|
+
publicKeys: PublicKeys.fromSecretKeys(secretKeys),
|
|
1839
|
+
networkId,
|
|
1840
|
+
coinHashes: CoinHashesMap.init(secretKeys, CoinHashesMap.pickAllCoins(localState)),
|
|
1841
|
+
progress: require_dist.createSyncProgress(syncProgress),
|
|
1842
|
+
protocolVersion: require_dist.ProtocolVersion(protocolVersion)
|
|
1843
|
+
};
|
|
1844
|
+
},
|
|
1845
|
+
restoreWithCoinHashes(publicKeys, localState, coinHashes, syncProgress, protocolVersion, networkId) {
|
|
1846
|
+
return CoinHashesMap.assertValid(coinHashes, localState).pipe(require_dist.mapBoth({
|
|
1847
|
+
onLeft: (missingNonces) => new InvalidCoinHashesError({
|
|
1848
|
+
message: "Missing coin hashes for coins present in the state",
|
|
1849
|
+
missingNonces
|
|
1850
|
+
}),
|
|
1851
|
+
onRight: () => ({
|
|
1852
|
+
state: localState,
|
|
1853
|
+
publicKeys,
|
|
1854
|
+
networkId,
|
|
1855
|
+
coinHashes,
|
|
1856
|
+
progress: require_dist.createSyncProgress(syncProgress),
|
|
1857
|
+
protocolVersion: require_dist.ProtocolVersion(protocolVersion)
|
|
1858
|
+
})
|
|
1859
|
+
}));
|
|
1860
|
+
},
|
|
1861
|
+
initEmpty(keys, networkId) {
|
|
1862
|
+
return this.empty(PublicKeys.fromSecretKeys(keys), networkId);
|
|
1863
|
+
},
|
|
1864
|
+
withProtocolVersion(wallet, version) {
|
|
1865
|
+
return version > wallet.protocolVersion ? {
|
|
1866
|
+
...wallet,
|
|
1867
|
+
protocolVersion: version
|
|
1868
|
+
} : wallet;
|
|
1869
|
+
},
|
|
1870
|
+
fromPreviousVersion(previous) {
|
|
1871
|
+
return {
|
|
1872
|
+
state: new _midnight_ntwrk_ledger_v8.ZswapLocalState(),
|
|
1873
|
+
publicKeys: previous.publicKeys,
|
|
1874
|
+
networkId: previous.networkId,
|
|
1875
|
+
coinHashes: CoinHashesMap.empty,
|
|
1876
|
+
progress: require_dist.createSyncProgress({
|
|
1877
|
+
...previous.progress,
|
|
1878
|
+
isConnected: false
|
|
1879
|
+
}),
|
|
1880
|
+
protocolVersion: require_dist.ProtocolVersion(previous.protocolVersion)
|
|
1881
|
+
};
|
|
1882
|
+
},
|
|
1883
|
+
applyCollapsedUpdate(wallet, collapsed) {
|
|
1884
|
+
const newState = wallet.state.applyCollapsedUpdate(collapsed);
|
|
1885
|
+
return {
|
|
1886
|
+
...wallet,
|
|
1887
|
+
state: newState
|
|
1888
|
+
};
|
|
1889
|
+
},
|
|
1890
|
+
apply(wallet, secretKeys, offer) {
|
|
1891
|
+
const newState = wallet.state.apply(secretKeys, offer);
|
|
1892
|
+
const newCoinHashes = CoinHashesMap.updateWithCoins(secretKeys, wallet.coinHashes, CoinHashesMap.pickAllCoins(newState));
|
|
1893
|
+
return {
|
|
1894
|
+
...wallet,
|
|
1895
|
+
state: newState,
|
|
1896
|
+
coinHashes: newCoinHashes
|
|
1897
|
+
};
|
|
1898
|
+
},
|
|
1899
|
+
replayEventsWithChanges(wallet, secretKeys, events) {
|
|
1900
|
+
const stateWithChanges = wallet.state.replayEventsWithChanges(secretKeys, events);
|
|
1901
|
+
const newState = stateWithChanges.state;
|
|
1902
|
+
const newCoinHashes = CoinHashesMap.updateWithCoins(secretKeys, wallet.coinHashes, CoinHashesMap.pickAllCoins(newState));
|
|
1903
|
+
return [{
|
|
1904
|
+
...wallet,
|
|
1905
|
+
state: newState,
|
|
1906
|
+
coinHashes: newCoinHashes
|
|
1907
|
+
}, stateWithChanges.changes];
|
|
1908
|
+
},
|
|
1909
|
+
updateProgress(wallet, { appliedIndex, highestRelevantWalletIndex, highestIndex, highestRelevantIndex, isConnected }) {
|
|
1910
|
+
const updatedProgress = require_dist.createSyncProgress({
|
|
1911
|
+
appliedIndex: appliedIndex ?? wallet.progress.appliedIndex,
|
|
1912
|
+
highestRelevantWalletIndex: highestRelevantWalletIndex ?? wallet.progress.highestRelevantWalletIndex,
|
|
1913
|
+
highestIndex: highestIndex ?? wallet.progress.highestIndex,
|
|
1914
|
+
highestRelevantIndex: highestRelevantIndex ?? wallet.progress.highestRelevantIndex,
|
|
1915
|
+
isConnected: isConnected ?? wallet.progress.isConnected
|
|
1916
|
+
});
|
|
1917
|
+
return {
|
|
1918
|
+
...wallet,
|
|
1919
|
+
progress: updatedProgress
|
|
1920
|
+
};
|
|
1921
|
+
},
|
|
1922
|
+
addTransaction(wallet, _tx) {
|
|
1923
|
+
return wallet;
|
|
1924
|
+
},
|
|
1925
|
+
revertTransaction(wallet, tx) {
|
|
1926
|
+
const newState = wallet.state.revertTransaction(tx);
|
|
1927
|
+
return {
|
|
1928
|
+
...wallet,
|
|
1929
|
+
state: newState
|
|
1930
|
+
};
|
|
1931
|
+
},
|
|
1932
|
+
updateTxHistory(wallet, _newTxs) {
|
|
1933
|
+
return wallet;
|
|
1934
|
+
},
|
|
1935
|
+
spendCoins(wallet, secretKeys, coins, segment) {
|
|
1936
|
+
const [offers, newLocalState] = require_dist.pipe(coins, require_dist.reduce([[], wallet.state], ([accOffers, localState], coinToSpend) => {
|
|
1937
|
+
const [nextState, newInput] = localState.spend(secretKeys, coinToSpend, segment);
|
|
1938
|
+
const inputOffer = _midnight_ntwrk_ledger_v8.ZswapOffer.fromInput(newInput, coinToSpend.type, coinToSpend.value);
|
|
1939
|
+
return [accOffers.concat([inputOffer]), nextState];
|
|
1940
|
+
}));
|
|
1941
|
+
return [offers, {
|
|
1942
|
+
...wallet,
|
|
1943
|
+
state: newLocalState
|
|
1944
|
+
}];
|
|
1945
|
+
},
|
|
1946
|
+
watchCoins(wallet, secretKeys, coins) {
|
|
1947
|
+
const newLocalState = coins.reduce((localState, coin) => localState.watchFor(wallet.publicKeys.coinPublicKey, coin), wallet.state);
|
|
1948
|
+
const newCoinHashes = CoinHashesMap.updateWithNewCoins(secretKeys, wallet.coinHashes, coins);
|
|
1949
|
+
return {
|
|
1950
|
+
...wallet,
|
|
1951
|
+
state: newLocalState,
|
|
1952
|
+
coinHashes: newCoinHashes
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
//#endregion
|
|
1957
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/Migration.js
|
|
1958
|
+
/**
|
|
1959
|
+
* The migration used when there is no previous wallet at all.
|
|
1960
|
+
*
|
|
1961
|
+
* @remarks
|
|
1962
|
+
* It backs `WalletLike.startEmpty`, which builds a wallet before any key material exists. The resulting state has no
|
|
1963
|
+
* coins and public keys derived from a fixed placeholder seed; it is a scaffold to be replaced by a real start, not a
|
|
1964
|
+
* wallet anybody can transact with. Preserved verbatim from the ledger-v8 implementation so that `startEmpty` behaves
|
|
1965
|
+
* exactly as it did.
|
|
1966
|
+
* @example
|
|
1967
|
+
* ```typescript
|
|
1968
|
+
* const builder = new V2Builder().withDefaults().withMigration(makeEmptyWalletMigration({ networkId }));
|
|
1969
|
+
* ```;
|
|
1970
|
+
*
|
|
1971
|
+
* @param configuration Supplies the network the scaffold state claims to be on.
|
|
1972
|
+
* @returns A migration from `null`.
|
|
1973
|
+
*/
|
|
1974
|
+
const makeEmptyWalletMigration = (configuration) => ({ migrate: () => {
|
|
1975
|
+
const seed = require_dist.fromString("0000000000000000000000000000000000000000000000000000000000000001");
|
|
1976
|
+
return require_dist.succeed(CoreWallet.empty(PublicKeys.fromSecretKeys(_midnight_ntwrk_ledger_v8.ZswapSecretKeys.fromSeed(seed)), configuration.networkId));
|
|
1977
|
+
} });
|
|
1978
|
+
//#endregion
|
|
1979
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/RunningV1Variant.js
|
|
1980
|
+
const progress = (state) => {
|
|
1981
|
+
const appliedIndex = state.progress?.appliedIndex ?? 0n;
|
|
1982
|
+
const highestRelevantWalletIndex = state.progress?.highestRelevantWalletIndex ?? 0n;
|
|
1983
|
+
const sourceGap = (state.progress?.highestIndex ?? 0n) - (state.progress?.highestRelevantIndex ?? 0n);
|
|
1984
|
+
const applyGap = highestRelevantWalletIndex - appliedIndex;
|
|
1985
|
+
return [require_dist.ProgressUpdate({
|
|
1986
|
+
sourceGap,
|
|
1987
|
+
applyGap
|
|
1988
|
+
})];
|
|
1989
|
+
};
|
|
1990
|
+
/**
|
|
1991
|
+
* Reports the protocol version a state observation implies, if any.
|
|
1992
|
+
*
|
|
1993
|
+
* @remarks
|
|
1994
|
+
* Two situations call for a signal. The ordinary one is a transition: sync annotated the state with a version it did
|
|
1995
|
+
* not have before, and the runtime decides whether that is a re-annotation inside this variant's range or a hand-over
|
|
1996
|
+
* to the next one.
|
|
1997
|
+
*
|
|
1998
|
+
* The other is a state that arrives already outside this variant's range — a snapshot serialized in the window between
|
|
1999
|
+
* the annotation and the migration it should have caused, or one written by an older protocol version entirely.
|
|
2000
|
+
* Nothing further will change that value, so waiting for a transition would strand the wallet on a version it does
|
|
2001
|
+
* not own. Emitting on sight heals it.
|
|
2002
|
+
*/
|
|
2003
|
+
const protocolVersionChange = (previous, current, isInitial, activationRange) => {
|
|
2004
|
+
const transitioned = previous.protocolVersion != current.protocolVersion;
|
|
2005
|
+
const strandedOutsideRange = isInitial && !require_dist.withinRange(current.protocolVersion, activationRange);
|
|
2006
|
+
return transitioned || strandedOutsideRange ? [require_dist.VersionChange({ change: require_dist.Version({ version: require_dist.ProtocolVersion(current.protocolVersion) }) })] : [];
|
|
2007
|
+
};
|
|
2008
|
+
const V1Tag = Symbol("V1");
|
|
2009
|
+
var RunningV1Variant = class {
|
|
2010
|
+
__polyTag__ = V1Tag;
|
|
2011
|
+
#scope;
|
|
2012
|
+
#context;
|
|
2013
|
+
#v1Context;
|
|
2014
|
+
#txHistoryPermits = require_dist.makeSemaphore(8).pipe(require_dist.runSync);
|
|
2015
|
+
state;
|
|
2016
|
+
constructor(scope, context, v1Context) {
|
|
2017
|
+
this.#scope = scope;
|
|
2018
|
+
this.#context = context;
|
|
2019
|
+
this.#v1Context = v1Context;
|
|
2020
|
+
this.state = require_dist.fromEffect(context.stateRef.get).pipe(require_dist.flatMap((initialState) => context.stateRef.changes.pipe(require_dist.mapAccum({
|
|
2021
|
+
previous: initialState,
|
|
2022
|
+
isInitial: true
|
|
2023
|
+
}, (seen, current) => [{
|
|
2024
|
+
previous: current,
|
|
2025
|
+
isInitial: false
|
|
2026
|
+
}, [
|
|
2027
|
+
seen.previous,
|
|
2028
|
+
current,
|
|
2029
|
+
seen.isInitial
|
|
2030
|
+
]]))), require_dist.mapConcat(([previous, current, isInitial]) => {
|
|
2031
|
+
return [
|
|
2032
|
+
require_dist.State({ state: current }),
|
|
2033
|
+
...progress(current),
|
|
2034
|
+
...protocolVersionChange(previous, current, isInitial, context.activationRange)
|
|
2035
|
+
];
|
|
2036
|
+
}));
|
|
2037
|
+
}
|
|
2038
|
+
startSyncInBackground(startAux) {
|
|
2039
|
+
return this.startSync(startAux).pipe(require_dist.runScoped(require_dist.drain), require_dist.forkScoped, require_dist.provideService(require_dist.Scope, this.#scope));
|
|
2040
|
+
}
|
|
2041
|
+
startSync(startAux) {
|
|
2042
|
+
return require_dist.pipe(require_dist.get(this.#context.stateRef), require_dist.fromEffect, require_dist.flatMap((state) => this.#v1Context.syncService.updates(state, startAux)), require_dist.mapEffect((update) => require_dist.modifyEffect(this.#context.stateRef, (state) => require_dist.try_({
|
|
2043
|
+
try: () => {
|
|
2044
|
+
const [newState, changesResult] = this.#v1Context.syncCapability.applyUpdate(state, update, this.#context.activationRange);
|
|
2045
|
+
return [changesResult, newState];
|
|
2046
|
+
},
|
|
2047
|
+
catch: (err) => new OtherWalletError({
|
|
2048
|
+
message: "Error while applying sync update",
|
|
2049
|
+
cause: err
|
|
2050
|
+
})
|
|
2051
|
+
})).pipe(require_dist.flatMap$1(({ changes, protocolVersion }) => changes.length === 0 ? require_dist._void : require_dist.pipe(require_dist.forEach(changes, (change) => require_dist.pipe(this.#txHistoryPermits.withPermits(1)(require_dist.pipe(this.#v1Context.transactionHistoryService.getTransactionDetails(change.source), require_dist.flatMap$1((metadata) => this.#v1Context.transactionHistoryService.put(change, metadata, protocolVersion)))), require_dist.catchAllCause((cause) => require_dist.logError(cause, `Failed to record shielded tx-history section for ${change.source}`))), {
|
|
2052
|
+
discard: true,
|
|
2053
|
+
concurrency: 8
|
|
2054
|
+
}), require_dist.forkScoped)), require_dist.provideService(require_dist.Scope, this.#scope))), require_dist.tapError((error$1) => require_dist.error(error$1)), require_dist.retry(require_dist.pipe(require_dist.exponential(require_dist.seconds(1), 2), require_dist.map$1((delay) => {
|
|
2055
|
+
const maxDelay = require_dist.minutes(2);
|
|
2056
|
+
const jitter = require_dist.millis(Math.floor(Math.random() * 1e3));
|
|
2057
|
+
const delayWithJitter = require_dist.toMillis(delay) + require_dist.toMillis(jitter);
|
|
2058
|
+
return require_dist.millis(Math.min(delayWithJitter, require_dist.toMillis(maxDelay)));
|
|
2059
|
+
}))));
|
|
2060
|
+
}
|
|
2061
|
+
balanceTransaction(secretKeys, tx) {
|
|
2062
|
+
return require_dist.modifyEffect(this.#context.stateRef, (state) => {
|
|
2063
|
+
return require_dist.pipe(this.#v1Context.transactingCapability.balanceTransaction(secretKeys, state, tx), require_dist.toEffect);
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
transferTransaction(secretKeys, outputs) {
|
|
2067
|
+
return require_dist.modifyEffect(this.#context.stateRef, (state) => {
|
|
2068
|
+
return require_dist.pipe(this.#v1Context.transactingCapability.makeTransfer(secretKeys, state, outputs), require_dist.toEffect);
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
initSwap(secretKeys, desiredInputs, desiredOutputs) {
|
|
2072
|
+
return require_dist.modifyEffect(this.#context.stateRef, (state) => {
|
|
2073
|
+
return require_dist.pipe(this.#v1Context.transactingCapability.initSwap(secretKeys, state, desiredInputs, desiredOutputs), require_dist.toEffect);
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
revertTransaction(transaction) {
|
|
2077
|
+
return require_dist.updateEffect(this.#context.stateRef, (state) => {
|
|
2078
|
+
return require_dist.pipe(this.#v1Context.transactingCapability.revertTransaction(state, transaction), require_dist.toEffect);
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2081
|
+
serializeState(state) {
|
|
2082
|
+
return this.#v1Context.serializationCapability.serialize(state);
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
//#endregion
|
|
2086
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/Serialization.js
|
|
2087
|
+
const StateSchema = require_dist.declare((input) => input instanceof _midnight_ntwrk_ledger_v8.ZswapLocalState).annotations({ identifier: "ledger.ZswapLocalState" });
|
|
2088
|
+
const Uint8ArraySchema$1 = require_dist.declare((input) => input instanceof Uint8Array).annotations({ identifier: "Uint8Array" });
|
|
2089
|
+
const StateFromUInt8Array = () => require_dist.asSchema(require_dist.transformOrFail(Uint8ArraySchema$1, StateSchema, {
|
|
2090
|
+
encode: (state) => {
|
|
2091
|
+
return require_dist.try_({
|
|
2092
|
+
try: () => {
|
|
2093
|
+
return state.serialize();
|
|
2094
|
+
},
|
|
2095
|
+
catch: (err) => {
|
|
2096
|
+
return new require_dist.Unexpected(err, "Could not serialize local state");
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
},
|
|
2100
|
+
decode: (bytes) => require_dist.try_({
|
|
2101
|
+
try: () => _midnight_ntwrk_ledger_v8.ZswapLocalState.deserialize(bytes),
|
|
2102
|
+
catch: (err) => {
|
|
2103
|
+
return new require_dist.Unexpected(err, "Could not deserialize local state");
|
|
2104
|
+
}
|
|
2105
|
+
})
|
|
2106
|
+
}));
|
|
2107
|
+
const HexedState = () => require_dist.pipe(require_dist.Uint8ArrayFromHex, require_dist.compose(StateFromUInt8Array()));
|
|
2108
|
+
const makeDefaultV1SerializationCapability = () => {
|
|
2109
|
+
const SnapshotSchema = require_dist.Struct({
|
|
2110
|
+
publicKeys: require_dist.Struct({
|
|
2111
|
+
coinPublicKey: require_dist.String$,
|
|
2112
|
+
encryptionPublicKey: require_dist.String$
|
|
2113
|
+
}),
|
|
2114
|
+
state: HexedState(),
|
|
2115
|
+
protocolVersion: require_dist.BigInt$,
|
|
2116
|
+
offset: require_dist.optional(require_dist.BigInt$),
|
|
2117
|
+
networkId: require_dist.String$,
|
|
2118
|
+
coinHashes: require_dist.Record({
|
|
2119
|
+
key: require_dist.String$,
|
|
2120
|
+
value: require_dist.Struct({
|
|
2121
|
+
nullifier: require_dist.String$,
|
|
2122
|
+
commitment: require_dist.String$
|
|
2123
|
+
})
|
|
2124
|
+
})
|
|
2125
|
+
});
|
|
2126
|
+
return {
|
|
2127
|
+
serialize: (wallet) => {
|
|
2128
|
+
const buildSnapshot = (w) => ({
|
|
2129
|
+
publicKeys: w.publicKeys,
|
|
2130
|
+
state: w.state,
|
|
2131
|
+
protocolVersion: w.protocolVersion,
|
|
2132
|
+
networkId: w.networkId,
|
|
2133
|
+
offset: w.progress?.appliedIndex,
|
|
2134
|
+
coinHashes: w.coinHashes
|
|
2135
|
+
});
|
|
2136
|
+
return require_dist.pipe(wallet, buildSnapshot, require_dist.encodeSync(SnapshotSchema), JSON.stringify);
|
|
2137
|
+
},
|
|
2138
|
+
deserialize: (aux, serialized) => {
|
|
2139
|
+
return require_dist.pipe(serialized, require_dist.decodeUnknownEither(require_dist.parseJson(SnapshotSchema)), require_dist.mapLeft((err) => WalletError.other(err)), require_dist.flatMap$4((snapshot) => CoreWallet.restoreWithCoinHashes(snapshot.publicKeys, snapshot.state, snapshot.coinHashes, {
|
|
2140
|
+
appliedIndex: snapshot.offset ?? 0n,
|
|
2141
|
+
highestRelevantWalletIndex: 0n,
|
|
2142
|
+
highestIndex: 0n,
|
|
2143
|
+
highestRelevantIndex: 0n,
|
|
2144
|
+
isConnected: false
|
|
2145
|
+
}, snapshot.protocolVersion, snapshot.networkId)));
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
};
|
|
2149
|
+
//#endregion
|
|
2150
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/Sync.js
|
|
2151
|
+
/**
|
|
2152
|
+
* Splits a batch of version-tagged items at the end of a variant's activation range.
|
|
2153
|
+
*
|
|
2154
|
+
* @remarks
|
|
2155
|
+
* The split is positional, not a filter: everything from the first out-of-range item onwards is deferred, even if a
|
|
2156
|
+
* later item reports an in-range version again. A batch is a contiguous slice of one timeline, so applying past a
|
|
2157
|
+
* boundary and then resuming behind it would leave a hole no cursor can describe.
|
|
2158
|
+
*
|
|
2159
|
+
* This is the one place the boundary rule lives; both the indexer capability (per event) and the simulator capability
|
|
2160
|
+
* (per block) go through it, so they cannot drift apart.
|
|
2161
|
+
* @param items The batch, in source order.
|
|
2162
|
+
* @param versionOf Reads the protocol version an item was reported at.
|
|
2163
|
+
* @param activeRange The variant's half-open activation range.
|
|
2164
|
+
* @returns The applied/deferred split and the version to record.
|
|
2165
|
+
*/
|
|
2166
|
+
const splitAtVersionBoundary = (items, versionOf, activeRange) => {
|
|
2167
|
+
const [, end] = activeRange;
|
|
2168
|
+
const boundary = items.findIndex((item) => BigInt(versionOf(item)) >= end);
|
|
2169
|
+
const [applied, deferred] = boundary < 0 ? [items, []] : [items.slice(0, boundary), items.slice(boundary)];
|
|
2170
|
+
const signalling = deferred.at(0) ?? applied.at(-1);
|
|
2171
|
+
return {
|
|
2172
|
+
applied,
|
|
2173
|
+
deferred,
|
|
2174
|
+
observedVersion: signalling === void 0 ? require_dist.none() : require_dist.some(require_dist.ProtocolVersion(BigInt(versionOf(signalling))))
|
|
2175
|
+
};
|
|
2176
|
+
};
|
|
2177
|
+
/**
|
|
2178
|
+
* Checks that freshly delivered events arrive in strictly ascending id order.
|
|
2179
|
+
*
|
|
2180
|
+
* @remarks
|
|
2181
|
+
* Order is all that can be checked, never contiguity: zswap events share one id sequence with dust and contract events
|
|
2182
|
+
* in the indexer, so gaps in a zswap stream are normal. A skipped commitment-inserting event is caught by the
|
|
2183
|
+
* ledger's own insertion check instead. An empty batch is trivially ordered.
|
|
2184
|
+
* @param fresh The events left after the cursor filter, in source order.
|
|
2185
|
+
* @param appliedIndex The highest event id already applied; the first fresh id must exceed it.
|
|
2186
|
+
* @returns The batch unchanged, or the first id that fails to exceed its predecessor as an
|
|
2187
|
+
* {@link OutOfOrderSyncUpdateError}.
|
|
2188
|
+
*/
|
|
2189
|
+
const expectAscending = (fresh, appliedIndex) => require_dist.pipe(require_dist.zipWith(fresh, require_dist.prepend(require_dist.map$3(fresh, (item) => BigInt(item.id)), appliedIndex), (item, previous) => ({
|
|
2190
|
+
item,
|
|
2191
|
+
previous
|
|
2192
|
+
})), require_dist.findFirst(({ item, previous }) => BigInt(item.id) <= previous), require_dist.match$1({
|
|
2193
|
+
onNone: () => require_dist.right(fresh),
|
|
2194
|
+
onSome: ({ item, previous }) => require_dist.left(new OutOfOrderSyncUpdateError({
|
|
2195
|
+
message: `Zswap event ${item.id} delivered at or below its predecessor ${previous}; batch refused, applied index stays at ${appliedIndex}`,
|
|
2196
|
+
expected: previous,
|
|
2197
|
+
received: BigInt(item.id)
|
|
2198
|
+
}))
|
|
2199
|
+
}));
|
|
2200
|
+
/** Records a batch's observed protocol version on the state, monotonically. A batch that observed none is a no-op. */
|
|
2201
|
+
const annotateVersion = (state, observedVersion) => require_dist.match$1(observedVersion, {
|
|
2202
|
+
onNone: () => state,
|
|
2203
|
+
onSome: (version) => CoreWallet.withProtocolVersion(state, version)
|
|
2204
|
+
});
|
|
2205
|
+
const Uint8ArraySchema = require_dist.declare((input) => input instanceof Uint8Array).annotations({ identifier: "Uint8Array" });
|
|
2206
|
+
const VersionSignalSyncUpdate = { create: (version, highestEventId) => {
|
|
2207
|
+
return {
|
|
2208
|
+
_tag: "VersionSignal",
|
|
2209
|
+
version,
|
|
2210
|
+
highestEventId
|
|
2211
|
+
};
|
|
2212
|
+
} };
|
|
2213
|
+
const WalletSyncUpdate = { create: (updates, secretKeys) => {
|
|
2214
|
+
return {
|
|
2215
|
+
_tag: "Events",
|
|
2216
|
+
updates,
|
|
2217
|
+
secretKeys
|
|
2218
|
+
};
|
|
2219
|
+
} };
|
|
2220
|
+
const LedgerEventSchema = require_dist.declare((input) => input instanceof _midnight_ntwrk_ledger_v8.Event).annotations({ identifier: "ledger.Event" });
|
|
2221
|
+
const LedgerEventFromUint8Array = require_dist.transformOrFail(Uint8ArraySchema, LedgerEventSchema, {
|
|
2222
|
+
encode: (event) => require_dist.try_({
|
|
2223
|
+
try: () => event.serialize(),
|
|
2224
|
+
catch: (error) => new require_dist.Unexpected(error, "Could not serialize ledger event")
|
|
2225
|
+
}),
|
|
2226
|
+
decode: (bytes) => require_dist.try_({
|
|
2227
|
+
try: () => _midnight_ntwrk_ledger_v8.Event.deserialize(bytes),
|
|
2228
|
+
catch: (error) => new require_dist.Unexpected(error, "Could not deserialize ledger event")
|
|
2229
|
+
})
|
|
2230
|
+
});
|
|
2231
|
+
const HexedLedgerEvent = require_dist.pipe(require_dist.Uint8ArrayFromHex, require_dist.compose(LedgerEventFromUint8Array));
|
|
2232
|
+
const EventsSyncUpdatePayload = require_dist.Struct({
|
|
2233
|
+
id: require_dist.Number$,
|
|
2234
|
+
raw: require_dist.String$,
|
|
2235
|
+
protocolVersion: require_dist.Number$,
|
|
2236
|
+
maxId: require_dist.Number$
|
|
2237
|
+
});
|
|
2238
|
+
/**
|
|
2239
|
+
* One event of the source's timeline, still encoded.
|
|
2240
|
+
*
|
|
2241
|
+
* @remarks
|
|
2242
|
+
* The event is carried as the source served it rather than as a `ledger.Event`, because whether this ledger version may
|
|
2243
|
+
* read it at all is not the source's question to answer. A batch spanning a protocol boundary carries events of the
|
|
2244
|
+
* version that follows this one, which this ledger version cannot deserialize — the serialization header names a
|
|
2245
|
+
* different version — and after a hand-over the inclusive cursor re-delivers an event of the version that preceded
|
|
2246
|
+
* it, which it equally cannot. Both are ordinary, and neither is an error: they belong to the variant either side.
|
|
2247
|
+
*
|
|
2248
|
+
* So the bytes travel undecoded and only the capability, which knows the activation range, reads the ones it is about
|
|
2249
|
+
* to apply — see {@link readEvent}. Decoding here would fail the whole batch on an event nobody intended to apply.
|
|
2250
|
+
*/
|
|
2251
|
+
const EventsSyncUpdate = require_dist.TaggedStruct("EventsSyncUpdate", {
|
|
2252
|
+
id: require_dist.Number$,
|
|
2253
|
+
protocolVersion: require_dist.Number$,
|
|
2254
|
+
maxId: require_dist.Number$,
|
|
2255
|
+
raw: require_dist.String$
|
|
2256
|
+
});
|
|
2257
|
+
const EventsSyncUpdateFromPayload = require_dist.transform(EventsSyncUpdatePayload, EventsSyncUpdate, {
|
|
2258
|
+
strict: true,
|
|
2259
|
+
decode: (input) => ({
|
|
2260
|
+
_tag: "EventsSyncUpdate",
|
|
2261
|
+
id: input.id,
|
|
2262
|
+
protocolVersion: input.protocolVersion,
|
|
2263
|
+
maxId: input.maxId,
|
|
2264
|
+
raw: input.raw
|
|
2265
|
+
}),
|
|
2266
|
+
encode: (update) => ({
|
|
2267
|
+
id: update.id,
|
|
2268
|
+
raw: update.raw,
|
|
2269
|
+
protocolVersion: update.protocolVersion,
|
|
2270
|
+
maxId: update.maxId
|
|
2271
|
+
})
|
|
2272
|
+
});
|
|
2273
|
+
/**
|
|
2274
|
+
* Reads an event this variant is going to apply.
|
|
2275
|
+
*
|
|
2276
|
+
* @remarks
|
|
2277
|
+
* The counterpart of {@link EventsSyncUpdate} carrying its event encoded: a capability calls this on the batch prefix it
|
|
2278
|
+
* owns, and never on what it defers. Failure here is a genuine one — an event this variant claimed and cannot read —
|
|
2279
|
+
* and is raised rather than returned, because `SyncCapability.applyUpdate` is total in its own domain and the variant
|
|
2280
|
+
* already turns a throw from it into a typed synchronization error.
|
|
2281
|
+
* @param update The update to read.
|
|
2282
|
+
* @returns The event it carries.
|
|
2283
|
+
* @throws ParseError if the bytes are not an event this ledger version can deserialize.
|
|
2284
|
+
*/
|
|
2285
|
+
const readEvent = (update) => require_dist.decodeSync(HexedLedgerEvent)(update.raw);
|
|
2286
|
+
/** How often the chain is asked its version when the configuration does not say. */
|
|
2287
|
+
const DEFAULT_VERSION_WATCH_INTERVAL_MS = 3e4;
|
|
2288
|
+
/**
|
|
2289
|
+
* How long one event-id probe is given to produce its single answer.
|
|
2290
|
+
*
|
|
2291
|
+
* @remarks
|
|
2292
|
+
* Only a stall guard. The probe subscribes at a cursor whose event provably exists, so the answer arrives at once or
|
|
2293
|
+
* the transport is broken; without a bound, a half-open socket would leave the poll loop parked on a tick that never
|
|
2294
|
+
* completes and the wallet would stop asking altogether. A bound turns that into a skipped tick.
|
|
2295
|
+
*/
|
|
2296
|
+
const EVENT_TIP_PROBE_TIMEOUT = require_dist.seconds(10);
|
|
2297
|
+
/**
|
|
2298
|
+
* Asks the source how far its zswap event timeline goes.
|
|
2299
|
+
*
|
|
2300
|
+
* @remarks
|
|
2301
|
+
* Over the event subscription rather than a query, because the schema has no query that reaches a zswap ledger event:
|
|
2302
|
+
* `block`/`transactions` reach one only through a block that happens to contain zswap events, which on a quiet chain
|
|
2303
|
+
* is precisely the block that does not. `maxId` is a property of the whole timeline, so any single event answers it —
|
|
2304
|
+
* the first one delivered is taken and the subscription closed.
|
|
2305
|
+
*
|
|
2306
|
+
* The cursor is the wallet's own. The event it last applied provably exists, so the source answers immediately and has
|
|
2307
|
+
* the least backfill to abandon; a wallet that has applied nothing asks from the start, where the first event is.
|
|
2308
|
+
* @param config The sync configuration, for the keep-alive the source's subscriptions use.
|
|
2309
|
+
* @param url Where to subscribe.
|
|
2310
|
+
* @param resumeFrom The wallet's cursor; below zero means "from the very start".
|
|
2311
|
+
* @returns The highest event id, or nothing if the source did not answer.
|
|
2312
|
+
*/
|
|
2313
|
+
const highestEventId = (config, url, resumeFrom) => require_dist.pipe(require_dist.ZswapEventTip.run({ id: resumeFrom < 0n ? null : Number(resumeFrom) }), require_dist.runHead, require_dist.map$2(require_dist.map$5((answer) => answer.zswapLedgerEvents.maxId)), require_dist.provide(require_dist.layer({
|
|
2314
|
+
url,
|
|
2315
|
+
keepAlive: config.indexerClientConnection.keepAlive
|
|
2316
|
+
})), require_dist.scoped, require_dist.timeout(EVENT_TIP_PROBE_TIMEOUT));
|
|
2317
|
+
/**
|
|
2318
|
+
* One check of the chain's protocol version, gated on the wallet being caught up on the source's event ids.
|
|
2319
|
+
*
|
|
2320
|
+
* @remarks
|
|
2321
|
+
* The order of the two questions is load-bearing. The tip is read **first**: a tip reported at a version means the
|
|
2322
|
+
* source has indexed through the block that carries it, so every event below it is already counted in the `maxId`
|
|
2323
|
+
* read afterwards. Asked the other way round, an event indexed between the two answers could be one of the version
|
|
2324
|
+
* that preceded the tip — unread, uncounted, and exactly what the gate exists to catch.
|
|
2325
|
+
*
|
|
2326
|
+
* Two short-circuits, both of them answers rather than shortcuts. A tip at or below the version the wallet already held
|
|
2327
|
+
* is a signal that could only be a no-op, so no probe is opened and nothing is emitted — which is what keeps a
|
|
2328
|
+
* settled wallet from polling a subscription for the rest of its life. And a tip whose commitment tree has never
|
|
2329
|
+
* grown cannot have had a nullifier spent against it either, so such a chain provably holds no zswap event: nothing
|
|
2330
|
+
* can be unread, and the signal goes out with `null`.
|
|
2331
|
+
*
|
|
2332
|
+
* Everything else is swallowed. A tick that fails says nothing about the chain, so it must neither reach the state nor
|
|
2333
|
+
* take the sync stream down with it; the next tick is the retry, and costs nothing to wait for.
|
|
2334
|
+
* @param config The sync configuration, for the indexer to ask.
|
|
2335
|
+
* @param url Where to run the event-id probe.
|
|
2336
|
+
* @param resumeFrom The wallet's cursor, for the probe.
|
|
2337
|
+
* @param knownVersion The version the wallet already held when this stream opened — a lower bound on what it holds now.
|
|
2338
|
+
* @returns The signal, or nothing when there is nothing to say or nobody said it.
|
|
2339
|
+
*/
|
|
2340
|
+
const readVersionSignal = (config, url, resumeFrom, knownVersion) => require_dist.pipe(require_dist.BlockHash.run({ offset: null }), require_dist.provide(require_dist.layer$1({ url: config.indexerClientConnection.indexerHttpUrl })), require_dist.scoped, require_dist.flatMap$1((answer) => require_dist.match$1(require_dist.fromNullable(answer.block), {
|
|
2341
|
+
onNone: () => require_dist.succeedNone,
|
|
2342
|
+
onSome: (tip) => BigInt(tip.protocolVersion) <= knownVersion ? require_dist.succeedNone : tip.zswapEndIndex === 0 ? require_dist.succeedSome(VersionSignalSyncUpdate.create(tip.protocolVersion, null)) : require_dist.pipe(highestEventId(config, url, resumeFrom), require_dist.map$2(require_dist.map$5((maxId) => VersionSignalSyncUpdate.create(tip.protocolVersion, maxId))))
|
|
2343
|
+
})), require_dist.catchAll(() => require_dist.succeedNone));
|
|
2344
|
+
/**
|
|
2345
|
+
* The chain's version, re-asked on a timer for as long as sync runs.
|
|
2346
|
+
*
|
|
2347
|
+
* @remarks
|
|
2348
|
+
* Deliberately silent about ticks that say nothing: a tick that finds the chain where the wallet left it, or that
|
|
2349
|
+
* cannot reach the chain at all, emits no element rather than an empty one, so nothing downstream has to know that
|
|
2350
|
+
* polling is how the answer was arrived at.
|
|
2351
|
+
* @param config The sync configuration, carrying the interval.
|
|
2352
|
+
* @param url Where to run the event-id probe.
|
|
2353
|
+
* @param resumeFrom The wallet's cursor, for the probe.
|
|
2354
|
+
* @param knownVersion The version the wallet held when this stream opened.
|
|
2355
|
+
* @returns The signals, or an empty stream when watching is turned off.
|
|
2356
|
+
*/
|
|
2357
|
+
const versionWatch = (config, url, resumeFrom, knownVersion) => {
|
|
2358
|
+
const intervalMs = config.versionWatch?.intervalMs ?? DEFAULT_VERSION_WATCH_INTERVAL_MS;
|
|
2359
|
+
return intervalMs <= 0 ? require_dist.empty : require_dist.pipe(require_dist.fromSchedule(require_dist.spaced(require_dist.millis(intervalMs))), require_dist.mapEffect(() => readVersionSignal(config, url, resumeFrom, knownVersion)), require_dist.filterMap(require_dist.identity));
|
|
2360
|
+
};
|
|
2361
|
+
const makeEventsSyncService = (config) => {
|
|
2362
|
+
return { updates: (state, secretKeys) => {
|
|
2363
|
+
const { indexerClientConnection } = config;
|
|
2364
|
+
const webSocketUrlResult = require_dist.createWebSocketUrl(indexerClientConnection.indexerHttpUrl, indexerClientConnection.indexerWsUrl);
|
|
2365
|
+
if (require_dist.isLeft(webSocketUrlResult)) return require_dist.fail(new SyncWalletError(/* @__PURE__ */ new Error(`Could not derive WebSocket URL from indexer HTTP URL: ${webSocketUrlResult.left.message}`)));
|
|
2366
|
+
const indexerWsUrlResult = require_dist.make(webSocketUrlResult.right);
|
|
2367
|
+
if (require_dist.isLeft(indexerWsUrlResult)) return require_dist.fail(new SyncWalletError(/* @__PURE__ */ new Error(`Invalid indexer WS URL: ${indexerWsUrlResult.left.message}`)));
|
|
2368
|
+
const indexerWsUrl = indexerWsUrlResult.right;
|
|
2369
|
+
const resumeFrom = (state.progress?.appliedIndex ?? 0n) - 1n;
|
|
2370
|
+
const batchSize = config.batchUpdates?.size ?? 10;
|
|
2371
|
+
const batchTimeout = require_dist.millis(config.batchUpdates?.timeout ?? 1);
|
|
2372
|
+
const batchSpacing = config.batchUpdates?.spacing ?? 4;
|
|
2373
|
+
const bufferSize = config.indexerClientConnection.bufferSize ?? 1e4;
|
|
2374
|
+
const resumeThreshold = config.indexerClientConnection.resumeThreshold ?? 100;
|
|
2375
|
+
const eventsStream = require_dist.pipe(require_dist.ZswapEvents.runWithBackpressure({
|
|
2376
|
+
bufferSize,
|
|
2377
|
+
resumeThreshold,
|
|
2378
|
+
from: resumeFrom,
|
|
2379
|
+
variables: (cursor) => ({ id: cursor < 0n ? null : Number(cursor) }),
|
|
2380
|
+
key: (r) => BigInt(r.zswapLedgerEvents.id)
|
|
2381
|
+
}), require_dist.provideLayer(require_dist.layer({
|
|
2382
|
+
url: indexerWsUrl,
|
|
2383
|
+
keepAlive: config.indexerClientConnection.keepAlive
|
|
2384
|
+
})), require_dist.mapError((error) => new SyncWalletError(error)), require_dist.mapEffect((subscription) => require_dist.pipe(subscription.zswapLedgerEvents, require_dist.decodeUnknownEither(EventsSyncUpdateFromPayload), require_dist.mapLeft((err) => new SyncWalletError(err)), require_dist.toEffect)), require_dist.groupedWithin(batchSize, batchTimeout), require_dist.map(require_dist.toArray), require_dist.map((data) => WalletSyncUpdate.create(data, secretKeys)));
|
|
2385
|
+
const timeline = batchSpacing > 0 ? require_dist.schedule(eventsStream, require_dist.spaced(require_dist.millis(batchSpacing))) : eventsStream;
|
|
2386
|
+
return require_dist.merge(timeline, versionWatch(config, indexerWsUrl, resumeFrom, state.protocolVersion), { haltStrategy: "left" });
|
|
2387
|
+
} };
|
|
2388
|
+
};
|
|
2389
|
+
/** The result of an update that observed nothing of the chain. */
|
|
2390
|
+
const noChanges = (state) => ({
|
|
2391
|
+
changes: [],
|
|
2392
|
+
protocolVersion: Number(state.protocolVersion)
|
|
2393
|
+
});
|
|
2394
|
+
/**
|
|
2395
|
+
* Folds what the chain said about its own version into the wallet state.
|
|
2396
|
+
*
|
|
2397
|
+
* @remarks
|
|
2398
|
+
* The same recording the event path makes through {@link annotateVersion}, and nothing else: no cursor moves, no coin
|
|
2399
|
+
* changes hands, no tree grows. A signal is an observation about the chain, not a piece of it.
|
|
2400
|
+
*
|
|
2401
|
+
* Unread events below the source's tip make the observation unsafe to record, and leave the state exactly as it was:
|
|
2402
|
+
* the hand-over would park the cursor in front of history the next variant cannot read — and those events carry the
|
|
2403
|
+
* version themselves, so nothing is lost by waiting for them. That is not an error; the next tick asks again.
|
|
2404
|
+
*
|
|
2405
|
+
* A version at or below the one already recorded needs no guard of its own — {@link annotateVersion} never goes
|
|
2406
|
+
* backwards — so a source briefly answering from a lagging replica cannot drag a wallet back over a boundary.
|
|
2407
|
+
* @param state The wallet to record on.
|
|
2408
|
+
* @param update What the chain said, and how far its event timeline goes.
|
|
2409
|
+
* @returns The wallet, annotated or untouched, and an empty result.
|
|
2410
|
+
*/
|
|
2411
|
+
const applyVersionSignal = (state, update) => {
|
|
2412
|
+
const appliedIndex = state.progress?.appliedIndex ?? 0n;
|
|
2413
|
+
return [update.highestEventId !== null && BigInt(update.highestEventId) > appliedIndex ? state : annotateVersion(state, require_dist.some(require_dist.ProtocolVersion(BigInt(update.version)))), noChanges(state)];
|
|
2414
|
+
};
|
|
2415
|
+
const makeEventsSyncCapability = () => {
|
|
2416
|
+
return { applyUpdate: (state, wrappedUpdate, activeRange) => {
|
|
2417
|
+
if (wrappedUpdate._tag === "VersionSignal") return applyVersionSignal(state, wrappedUpdate);
|
|
2418
|
+
if (wrappedUpdate.updates.length === 0) return [state, noChanges(state)];
|
|
2419
|
+
const appliedIndex = state.progress?.appliedIndex ?? 0n;
|
|
2420
|
+
const freshUpdates = wrappedUpdate.updates.filter((u) => BigInt(u.id) > appliedIndex);
|
|
2421
|
+
const lastUpdate = wrappedUpdate.updates.at(-1);
|
|
2422
|
+
const highestRelevantWalletIndex = BigInt(lastUpdate.maxId);
|
|
2423
|
+
const { applied, observedVersion } = splitAtVersionBoundary(require_dist.getOrThrowWith(expectAscending(freshUpdates, appliedIndex), require_dist.identity), (update) => update.protocolVersion, activeRange);
|
|
2424
|
+
const [newState, newChanges] = applied.length === 0 ? [state, []] : CoreWallet.replayEventsWithChanges(state, wrappedUpdate.secretKeys, applied.map(readEvent));
|
|
2425
|
+
return [CoreWallet.updateProgress(annotateVersion(newState, observedVersion), {
|
|
2426
|
+
highestRelevantWalletIndex,
|
|
2427
|
+
appliedIndex: applied.length === 0 ? appliedIndex : BigInt(applied.at(-1).id),
|
|
2428
|
+
isConnected: true
|
|
2429
|
+
}), {
|
|
2430
|
+
changes: newChanges,
|
|
2431
|
+
protocolVersion: applied.at(-1)?.protocolVersion ?? Number(state.protocolVersion)
|
|
2432
|
+
}];
|
|
2433
|
+
} };
|
|
2434
|
+
};
|
|
2435
|
+
//#endregion
|
|
2436
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/TransactionImbalances.js
|
|
2437
|
+
const ShieldedCostModel = {
|
|
2438
|
+
inputFeeOverhead: 0n,
|
|
2439
|
+
outputFeeOverhead: 0n
|
|
2440
|
+
};
|
|
2441
|
+
const TransactionImbalances = new class {
|
|
2442
|
+
empty = () => {
|
|
2443
|
+
return {
|
|
2444
|
+
guaranteed: require_dist.Imbalances.empty(),
|
|
2445
|
+
fallible: /* @__PURE__ */ new Map()
|
|
2446
|
+
};
|
|
2447
|
+
};
|
|
2448
|
+
areBalanced = (imbalances) => {
|
|
2449
|
+
const areGuaranteedAllZeroes = imbalances.guaranteed.entries().every(([, value]) => value === 0n);
|
|
2450
|
+
const areFallibleAllZeroes = Array.from(imbalances.fallible.values()).every((segmentImbalances) => segmentImbalances.entries().every(([, value]) => value === 0n));
|
|
2451
|
+
return areGuaranteedAllZeroes && areFallibleAllZeroes;
|
|
2452
|
+
};
|
|
2453
|
+
}();
|
|
2454
|
+
//#endregion
|
|
2455
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/TransactionOps.js
|
|
2456
|
+
const TransactionOps = new class {
|
|
2457
|
+
default = {
|
|
2458
|
+
getImbalances(tx) {
|
|
2459
|
+
return TransactionOps.shared.getImbalances(tx);
|
|
2460
|
+
},
|
|
2461
|
+
id(tx) {
|
|
2462
|
+
return tx.identifiers().at(0);
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
proofErased = {
|
|
2466
|
+
getImbalances(tx) {
|
|
2467
|
+
return TransactionOps.shared.getImbalances(tx);
|
|
2468
|
+
},
|
|
2469
|
+
id(tx) {
|
|
2470
|
+
return tx.identifiers().at(0);
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
unproven = {
|
|
2474
|
+
getImbalances(tx) {
|
|
2475
|
+
return TransactionOps.shared.getImbalances(tx);
|
|
2476
|
+
},
|
|
2477
|
+
id(tx) {
|
|
2478
|
+
return tx.identifiers().at(0);
|
|
2479
|
+
}
|
|
2480
|
+
};
|
|
2481
|
+
shared = {
|
|
2482
|
+
getImbalances(tx) {
|
|
2483
|
+
return {
|
|
2484
|
+
guaranteed: TransactionOps.shared.getGuaranteedImbalances(tx),
|
|
2485
|
+
fallible: TransactionOps.shared.getFallibleImbalances(tx)
|
|
2486
|
+
};
|
|
2487
|
+
},
|
|
2488
|
+
getGuaranteedImbalances: (tx) => {
|
|
2489
|
+
const rawGuaranteedImbalances = tx.imbalances(0).entries().filter(([token]) => token.tag === "shielded").map(([token, value]) => {
|
|
2490
|
+
return [token.raw, value];
|
|
2491
|
+
});
|
|
2492
|
+
return require_dist.Imbalances.fromEntries(rawGuaranteedImbalances);
|
|
2493
|
+
},
|
|
2494
|
+
getFallibleImbalances: (tx) => {
|
|
2495
|
+
const fallibleImbalances = Array.from(tx.fallibleOffer?.keys() ?? []).flatMap((segment) => {
|
|
2496
|
+
const rawImbalances = tx.imbalances(segment).entries().filter(([token]) => token.tag === "shielded").map(([token, value]) => {
|
|
2497
|
+
return [token.raw, value];
|
|
2498
|
+
});
|
|
2499
|
+
return [[segment, require_dist.Imbalances.fromEntries(rawImbalances)]];
|
|
2500
|
+
});
|
|
2501
|
+
return new Map(fallibleImbalances);
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
}();
|
|
2505
|
+
//#endregion
|
|
2506
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/Transacting.js
|
|
2507
|
+
const makeDefaultTransactingCapability = (config, getContext) => {
|
|
2508
|
+
return new TransactingCapabilityImplementation(config.networkId, () => getContext().coinSelection, () => getContext().coinsAndBalancesCapability, () => getContext().keysCapability, TransactionOps.default);
|
|
2509
|
+
};
|
|
2510
|
+
var TransactingCapabilityImplementation = class {
|
|
2511
|
+
networkId;
|
|
2512
|
+
getCoinSelection;
|
|
2513
|
+
txOps;
|
|
2514
|
+
getCoins;
|
|
2515
|
+
getKeys;
|
|
2516
|
+
constructor(networkId, getCoinSelection, getCoins, getKeys, txOps) {
|
|
2517
|
+
this.getCoins = getCoins;
|
|
2518
|
+
this.networkId = networkId;
|
|
2519
|
+
this.getCoinSelection = getCoinSelection;
|
|
2520
|
+
this.getKeys = getKeys;
|
|
2521
|
+
this.txOps = txOps;
|
|
2522
|
+
}
|
|
2523
|
+
balanceTransaction(secretKeys, state, tx) {
|
|
2524
|
+
return require_dist.gen$1(this, function* () {
|
|
2525
|
+
const coinSelection = this.getCoinSelection();
|
|
2526
|
+
const initialImbalances = this.txOps.getImbalances(tx);
|
|
2527
|
+
if (TransactionImbalances.areBalanced(initialImbalances)) return [void 0, state];
|
|
2528
|
+
const { newState: afterFallible, fallibleOffers } = yield* this.balanceFallibleSection(secretKeys, state, initialImbalances, coinSelection);
|
|
2529
|
+
const { newState: afterGuaranteed, offer: guaranteed } = yield* this.#balanceGuaranteedSection(secretKeys, afterFallible, initialImbalances, coinSelection, require_dist.Imbalances.empty());
|
|
2530
|
+
return [Array.from(fallibleOffers.entries()).reduce((tx, [segment, offer]) => tx.addZswapOffer({
|
|
2531
|
+
tag: "specific",
|
|
2532
|
+
value: segment
|
|
2533
|
+
}, offer), _midnight_ntwrk_ledger_v8.Transaction.fromParts(this.networkId, guaranteed)), afterGuaranteed];
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
makeTransfer(secretKeys, state, transfers) {
|
|
2537
|
+
return require_dist.gen$1(this, function* () {
|
|
2538
|
+
const positiveTransfers = yield* require_dist.pipe(transfers, require_dist.filter$1((t) => t.amount > 0n), require_dist.match({
|
|
2539
|
+
onEmpty: () => require_dist.left(new OtherWalletError({ message: "The amount needs to be positive" })),
|
|
2540
|
+
onNonEmpty: (nonEmpty) => require_dist.right(nonEmpty)
|
|
2541
|
+
}));
|
|
2542
|
+
const networkId = this.networkId;
|
|
2543
|
+
const { initialOffersAndCoins, selfCoins } = yield* this.#processDesiredOutputs(state, positiveTransfers);
|
|
2544
|
+
const offerToBalance = require_dist.pipe(initialOffersAndCoins, require_dist.map$3((o) => o.outputOffer), require_dist.fold((a, b) => a.merge(b)));
|
|
2545
|
+
const unprovenTxToBalance = _midnight_ntwrk_ledger_v8.Transaction.fromParts(networkId, offerToBalance);
|
|
2546
|
+
const imbalances = TransactionOps.unproven.getImbalances(unprovenTxToBalance);
|
|
2547
|
+
const { offer, newState } = yield* this.#balanceGuaranteedSection(secretKeys, state, imbalances, this.getCoinSelection(), require_dist.Imbalances.empty());
|
|
2548
|
+
const finalState = CoreWallet.watchCoins(newState, secretKeys, selfCoins);
|
|
2549
|
+
return [unprovenTxToBalance.merge(_midnight_ntwrk_ledger_v8.Transaction.fromParts(networkId, offer)), finalState];
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
initSwap(secretKeys, state, desiredInputs, desiredOutputs) {
|
|
2553
|
+
return require_dist.gen$1(this, function* () {
|
|
2554
|
+
if (!desiredOutputs.every((output) => output.amount > 0n)) return yield* require_dist.left(new OtherWalletError({ message: "The amount needs to be positive" }));
|
|
2555
|
+
if (!Object.entries(desiredInputs).every(([, amount]) => amount > 0n)) return yield* require_dist.left(new OtherWalletError({ message: "The input amounts need to be positive" }));
|
|
2556
|
+
const outputsParseResult = yield* this.#processDesiredOutputsPossiblyEmpty(state, desiredOutputs);
|
|
2557
|
+
const inputsParseResult = require_dist.Imbalances.fromEntries(require_dist.toEntries(desiredInputs));
|
|
2558
|
+
const networkId = this.networkId;
|
|
2559
|
+
const { offer, newState } = yield* this.#balanceGuaranteedSection(secretKeys, state, TransactionImbalances.empty(), this.getCoinSelection(), inputsParseResult);
|
|
2560
|
+
const finalState = CoreWallet.watchCoins(newState, secretKeys, outputsParseResult.selfCoins);
|
|
2561
|
+
const balancingTx = _midnight_ntwrk_ledger_v8.Transaction.fromParts(networkId, offer);
|
|
2562
|
+
return [outputsParseResult.unprovenTxToBalance ? outputsParseResult.unprovenTxToBalance.merge(balancingTx) : balancingTx, finalState];
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
revertTransaction(state, transaction) {
|
|
2566
|
+
return require_dist.try_$1({
|
|
2567
|
+
try: () => {
|
|
2568
|
+
return CoreWallet.revertTransaction(state, transaction);
|
|
2569
|
+
},
|
|
2570
|
+
catch: (err) => {
|
|
2571
|
+
return new OtherWalletError({
|
|
2572
|
+
message: `Error while reverting transaction ${transaction.identifiers().at(0)}`,
|
|
2573
|
+
cause: err
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
#prepareOffer(secretKeys, state, recipe, segment) {
|
|
2579
|
+
const [inputOffers, stateAfterSpends] = CoreWallet.spendCoins(state, secretKeys, recipe.inputs, segment);
|
|
2580
|
+
const stateAfterWatches = CoreWallet.watchCoins(stateAfterSpends, secretKeys, recipe.outputs);
|
|
2581
|
+
const outputOffers = recipe.outputs.map((coin) => {
|
|
2582
|
+
const output = _midnight_ntwrk_ledger_v8.ZswapOutput.new(coin, segment, this.getKeys().getCoinPublicKey(state).toHexString(), this.getKeys().getEncryptionPublicKey(state).toHexString());
|
|
2583
|
+
return _midnight_ntwrk_ledger_v8.ZswapOffer.fromOutput(output, coin.type, coin.value);
|
|
2584
|
+
});
|
|
2585
|
+
return require_dist.pipe(require_dist.appendAll(inputOffers, outputOffers), require_dist.match({
|
|
2586
|
+
onEmpty: () => require_dist.none(),
|
|
2587
|
+
onNonEmpty: (nonEmpty) => require_dist.pipe(nonEmpty, require_dist.fold((a, b) => a.merge(b)), require_dist.some)
|
|
2588
|
+
}), require_dist.map$5((offer) => ({
|
|
2589
|
+
offer,
|
|
2590
|
+
newState: stateAfterWatches
|
|
2591
|
+
})));
|
|
2592
|
+
}
|
|
2593
|
+
balanceFallibleSection(secretKeys, state, imbalances, coinSelection) {
|
|
2594
|
+
return Array.from(imbalances.fallible.entries()).reduce((acc, [segment, segmentImbalances]) => require_dist.flatMap$4(acc, ({ fallibleOffers, newState }) => require_dist.pipe(require_dist.try_$1({
|
|
2595
|
+
try: () => {
|
|
2596
|
+
const fallibleBalanceRecipe = require_dist.getBalanceRecipe({
|
|
2597
|
+
coins: this.getCoins().getAvailableCoins(newState).map((c) => c.coin),
|
|
2598
|
+
initialImbalances: segmentImbalances,
|
|
2599
|
+
transactionCostModel: ShieldedCostModel,
|
|
2600
|
+
feeTokenType: "",
|
|
2601
|
+
coinSelection,
|
|
2602
|
+
createOutput: (coin) => _midnight_ntwrk_ledger_v8.createShieldedCoinInfo(coin.type, coin.value),
|
|
2603
|
+
isCoinEqual: (a, b) => a.nonce === b.nonce
|
|
2604
|
+
});
|
|
2605
|
+
return this.#prepareOffer(secretKeys, newState, fallibleBalanceRecipe, segment);
|
|
2606
|
+
},
|
|
2607
|
+
catch: (err) => {
|
|
2608
|
+
if (err instanceof require_dist.InsufficientFundsError) return new InsufficientFundsError({
|
|
2609
|
+
message: `Insufficient funds for fallible segment ${segment}`,
|
|
2610
|
+
tokenType: err.tokenType,
|
|
2611
|
+
amount: segmentImbalances.get(err.tokenType) ?? 0n
|
|
2612
|
+
});
|
|
2613
|
+
return new OtherWalletError({
|
|
2614
|
+
message: `Balancing fallible segment ${segment} failed`,
|
|
2615
|
+
cause: err
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
}), require_dist.map$6(require_dist.match$1({
|
|
2619
|
+
onNone: () => ({
|
|
2620
|
+
fallibleOffers,
|
|
2621
|
+
newState
|
|
2622
|
+
}),
|
|
2623
|
+
onSome: (res) => ({
|
|
2624
|
+
fallibleOffers: new Map([...fallibleOffers, [segment, res.offer]]),
|
|
2625
|
+
newState: res.newState
|
|
2626
|
+
})
|
|
2627
|
+
})))), require_dist.right({
|
|
2628
|
+
fallibleOffers: /* @__PURE__ */ new Map(),
|
|
2629
|
+
newState: state
|
|
2630
|
+
}));
|
|
2631
|
+
}
|
|
2632
|
+
#balanceGuaranteedSection(secretKeys, state, imbalances, coinSelection, targetImbalances) {
|
|
2633
|
+
return require_dist.gen$1(this, function* () {
|
|
2634
|
+
const balanceRecipe = yield* require_dist.try_$1({
|
|
2635
|
+
try: () => require_dist.getBalanceRecipe({
|
|
2636
|
+
coins: this.getCoins().getAvailableCoins(state).map((c) => c.coin),
|
|
2637
|
+
initialImbalances: imbalances.guaranteed,
|
|
2638
|
+
transactionCostModel: ShieldedCostModel,
|
|
2639
|
+
feeTokenType: "",
|
|
2640
|
+
coinSelection,
|
|
2641
|
+
createOutput: (coin) => _midnight_ntwrk_ledger_v8.createShieldedCoinInfo(coin.type, coin.value),
|
|
2642
|
+
isCoinEqual: (a, b) => a.nonce === b.nonce,
|
|
2643
|
+
targetImbalances
|
|
2644
|
+
}),
|
|
2645
|
+
catch: (err) => {
|
|
2646
|
+
if (err instanceof require_dist.InsufficientFundsError) return new InsufficientFundsError({
|
|
2647
|
+
message: "Insufficient funds",
|
|
2648
|
+
tokenType: err.tokenType,
|
|
2649
|
+
amount: imbalances.guaranteed.get(err.tokenType) ?? 0n
|
|
2650
|
+
});
|
|
2651
|
+
else return new OtherWalletError({
|
|
2652
|
+
message: "Balancing guaranteed section failed",
|
|
2653
|
+
cause: err
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2656
|
+
});
|
|
2657
|
+
return require_dist.pipe(this.#prepareOffer(secretKeys, state, balanceRecipe, 0), require_dist.match$1({
|
|
2658
|
+
onNone: () => ({
|
|
2659
|
+
offer: void 0,
|
|
2660
|
+
newState: state
|
|
2661
|
+
}),
|
|
2662
|
+
onSome: (result) => result
|
|
2663
|
+
}));
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
#processDesiredOutputs(state, transfers) {
|
|
2667
|
+
return require_dist.try_$1({
|
|
2668
|
+
try: () => {
|
|
2669
|
+
const initialOffersAndCoins = require_dist.pipe(transfers, require_dist.map$3((transfer) => {
|
|
2670
|
+
const { receiverAddress, type, amount } = transfer;
|
|
2671
|
+
const coin = _midnight_ntwrk_ledger_v8.createShieldedCoinInfo(type, amount);
|
|
2672
|
+
const output = _midnight_ntwrk_ledger_v8.ZswapOutput.new(coin, 0, receiverAddress.coinPublicKey.toHexString(), receiverAddress.encryptionPublicKey.toHexString());
|
|
2673
|
+
return {
|
|
2674
|
+
coin,
|
|
2675
|
+
outputOffer: _midnight_ntwrk_ledger_v8.ZswapOffer.fromOutput(output, type, amount),
|
|
2676
|
+
isForSelf: receiverAddress.coinPublicKey.equals(this.getKeys().getCoinPublicKey(state))
|
|
2677
|
+
};
|
|
2678
|
+
}));
|
|
2679
|
+
return {
|
|
2680
|
+
initialOffersAndCoins,
|
|
2681
|
+
selfCoins: require_dist.flatMap$2(initialOffersAndCoins, ({ coin, isForSelf }) => {
|
|
2682
|
+
if (isForSelf) return [coin];
|
|
2683
|
+
else return [];
|
|
2684
|
+
})
|
|
2685
|
+
};
|
|
2686
|
+
},
|
|
2687
|
+
catch: (err) => {
|
|
2688
|
+
return new OtherWalletError({
|
|
2689
|
+
message: "Failed to process desired outputs",
|
|
2690
|
+
cause: err
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
#processDesiredOutputsPossiblyEmpty(state, desiredOutputs) {
|
|
2696
|
+
return require_dist.pipe(desiredOutputs, require_dist.match({
|
|
2697
|
+
onEmpty: () => {
|
|
2698
|
+
return require_dist.right({
|
|
2699
|
+
imbalances: TransactionImbalances.empty(),
|
|
2700
|
+
selfCoins: [],
|
|
2701
|
+
unprovenTxToBalance: null
|
|
2702
|
+
});
|
|
2703
|
+
},
|
|
2704
|
+
onNonEmpty: (desiredOutputs) => {
|
|
2705
|
+
return require_dist.pipe(this.#processDesiredOutputs(state, desiredOutputs), require_dist.map$6(({ initialOffersAndCoins, selfCoins }) => {
|
|
2706
|
+
const networkId = this.networkId;
|
|
2707
|
+
const offerToBalance = require_dist.pipe(initialOffersAndCoins, require_dist.map$3((o) => o.outputOffer), require_dist.fold((a, b) => a.merge(b)));
|
|
2708
|
+
const unprovenTxToBalance = _midnight_ntwrk_ledger_v8.Transaction.fromParts(networkId, offerToBalance);
|
|
2709
|
+
return {
|
|
2710
|
+
imbalances: TransactionOps.unproven.getImbalances(unprovenTxToBalance),
|
|
2711
|
+
selfCoins,
|
|
2712
|
+
unprovenTxToBalance
|
|
2713
|
+
};
|
|
2714
|
+
}));
|
|
2715
|
+
}
|
|
2716
|
+
}));
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
//#endregion
|
|
2720
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/CoinsAndBalances.js
|
|
2721
|
+
const calculateBalances = (coins) => coins.reduce((acc, { coin }) => ({
|
|
2722
|
+
...acc,
|
|
2723
|
+
[coin.type]: acc[coin.type] === void 0 ? coin.value : acc[coin.type] + coin.value
|
|
2724
|
+
}), {});
|
|
2725
|
+
const makeDefaultCoinsAndBalancesCapability = () => {
|
|
2726
|
+
const getAvailableBalances = (state) => {
|
|
2727
|
+
return calculateBalances(getAvailableCoins(state));
|
|
2728
|
+
};
|
|
2729
|
+
const getPendingBalances = (state) => {
|
|
2730
|
+
return calculateBalances(getPendingCoins(state));
|
|
2731
|
+
};
|
|
2732
|
+
const getTotalBalances = (state) => {
|
|
2733
|
+
return require_dist.pipe([getAvailableBalances(state), getPendingBalances(state)], require_dist.mergeWithAccumulator(0n, (a, b) => a + b));
|
|
2734
|
+
};
|
|
2735
|
+
const getAvailableCoins = (state) => {
|
|
2736
|
+
const pendingSpends = new Set([...state.state.pendingSpends.values()].map(([coin]) => coin.nonce));
|
|
2737
|
+
return require_dist.pipe([...state.state.coins], require_dist.filter$1((coin) => !pendingSpends.has(coin.nonce)), require_dist.map$3((coin) => {
|
|
2738
|
+
return {
|
|
2739
|
+
coin,
|
|
2740
|
+
commitment: state.coinHashes[coin.nonce].commitment,
|
|
2741
|
+
nullifier: state.coinHashes[coin.nonce].nullifier
|
|
2742
|
+
};
|
|
2743
|
+
}));
|
|
2744
|
+
};
|
|
2745
|
+
const getPendingCoins = (state) => require_dist.pipe([...state.state.pendingOutputs.values()], require_dist.map$3(([coin, ttl]) => ({
|
|
2746
|
+
coin,
|
|
2747
|
+
ttl,
|
|
2748
|
+
commitment: state.coinHashes[coin.nonce].commitment,
|
|
2749
|
+
nullifier: state.coinHashes[coin.nonce].nullifier
|
|
2750
|
+
})));
|
|
2751
|
+
const getTotalCoins = (state) => [...getAvailableCoins(state), ...getPendingCoins(state)];
|
|
2752
|
+
return {
|
|
2753
|
+
getAvailableBalances,
|
|
2754
|
+
getPendingBalances,
|
|
2755
|
+
getTotalBalances,
|
|
2756
|
+
getAvailableCoins,
|
|
2757
|
+
getPendingCoins,
|
|
2758
|
+
getTotalCoins
|
|
2759
|
+
};
|
|
2760
|
+
};
|
|
2761
|
+
//#endregion
|
|
2762
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/Keys.js
|
|
2763
|
+
require__polyfill_buffer_patch.init__polyfill_buffer_patch();
|
|
2764
|
+
const makeDefaultKeysCapability = () => {
|
|
2765
|
+
return {
|
|
2766
|
+
getCoinPublicKey: (state) => {
|
|
2767
|
+
return new require_dist.ShieldedCoinPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.coinPublicKey, "hex"));
|
|
2768
|
+
},
|
|
2769
|
+
getEncryptionPublicKey: (state) => {
|
|
2770
|
+
return new require_dist.ShieldedEncryptionPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.encryptionPublicKey, "hex"));
|
|
2771
|
+
},
|
|
2772
|
+
getAddress: (state) => {
|
|
2773
|
+
return new require_dist.ShieldedAddress(new require_dist.ShieldedCoinPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.coinPublicKey, "hex")), new require_dist.ShieldedEncryptionPublicKey(require__polyfill_buffer_patch.import_buffer.Buffer.from(state.publicKeys.encryptionPublicKey, "hex")));
|
|
2774
|
+
}
|
|
2775
|
+
};
|
|
2776
|
+
};
|
|
2777
|
+
//#endregion
|
|
2778
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/TransactionHistory.js
|
|
2779
|
+
const QualifiedShieldedCoinInfoSchema = require_dist.Struct({
|
|
2780
|
+
type: require_dist.String$,
|
|
2781
|
+
nonce: require_dist.String$,
|
|
2782
|
+
value: require_dist.BigInt$,
|
|
2783
|
+
mtIndex: require_dist.BigInt$
|
|
2784
|
+
});
|
|
2785
|
+
const ShieldedSectionSchema$1 = require_dist.Struct({
|
|
2786
|
+
receivedCoins: require_dist.Array$(QualifiedShieldedCoinInfoSchema),
|
|
2787
|
+
spentCoins: require_dist.Array$(QualifiedShieldedCoinInfoSchema)
|
|
2788
|
+
});
|
|
2789
|
+
require_dist.extendEntrySchema({ shielded: require_dist.optional(ShieldedSectionSchema$1) });
|
|
2790
|
+
require_dist.equivalence(QualifiedShieldedCoinInfoSchema);
|
|
2791
|
+
const convertUpdateToFinalizedInput = (changes, metadata, protocolVersion) => ({
|
|
2792
|
+
hash: changes.source,
|
|
2793
|
+
protocolVersion,
|
|
2794
|
+
status: metadata.status,
|
|
2795
|
+
identifiers: metadata.identifiers,
|
|
2796
|
+
finalizedBlock: {
|
|
2797
|
+
hash: metadata.block.hash,
|
|
2798
|
+
height: metadata.block.height,
|
|
2799
|
+
timestamp: new Date(metadata.block.timestamp)
|
|
2800
|
+
},
|
|
2801
|
+
shielded: {
|
|
2802
|
+
receivedCoins: changes.receivedCoins.map(({ mt_index, ...rest }) => ({
|
|
2803
|
+
...rest,
|
|
2804
|
+
mtIndex: mt_index
|
|
2805
|
+
})),
|
|
2806
|
+
spentCoins: changes.spentCoins.map(({ mt_index, ...rest }) => ({
|
|
2807
|
+
...rest,
|
|
2808
|
+
mtIndex: mt_index
|
|
2809
|
+
}))
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
const gotFinalizedShielded = (txHistoryStorage, input) => require_dist.tryPromise({
|
|
2813
|
+
try: () => txHistoryStorage.gotFinalized(input),
|
|
2814
|
+
catch: (e) => new TransactionHistoryError({
|
|
2815
|
+
message: `Failed to record finalized history entry for ${input.hash}`,
|
|
2816
|
+
cause: e
|
|
2817
|
+
})
|
|
2818
|
+
});
|
|
2819
|
+
const makeDefaultTransactionHistoryService = (config, _getContext) => {
|
|
2820
|
+
const txHistoryStorage = config.txHistoryStorage;
|
|
2821
|
+
const queryClientLayer = require_dist.layer$1({ url: config.indexerClientConnection.indexerHttpUrl });
|
|
2822
|
+
const retryWindow = config.transactionDetailsRetryWindow ?? require_dist.minutes(2);
|
|
2823
|
+
return {
|
|
2824
|
+
put: (changes, metadata, protocolVersion) => gotFinalizedShielded(txHistoryStorage, convertUpdateToFinalizedInput(changes, metadata, protocolVersion)),
|
|
2825
|
+
getTransactionDetails: (hash) => require_dist.gen(function* () {
|
|
2826
|
+
const result = yield* (yield* require_dist.TransactionHistoryDetail)({ transactionHash: hash });
|
|
2827
|
+
const tx = yield* require_dist.head$1(result.transactions).pipe(require_dist.orElseFail(() => new TransactionHistoryError({ message: `Indexer has not yet indexed transaction ${hash}` })));
|
|
2828
|
+
const rawStatus = tx.__typename === "RegularTransaction" ? tx.transactionResult.status : void 0;
|
|
2829
|
+
const status = rawStatus === "FAILURE" || rawStatus === "PARTIAL_SUCCESS" ? rawStatus : "SUCCESS";
|
|
2830
|
+
const identifiers = tx.__typename === "RegularTransaction" ? tx.identifiers : [];
|
|
2831
|
+
return {
|
|
2832
|
+
hash: tx.hash,
|
|
2833
|
+
block: {
|
|
2834
|
+
hash: tx.block.hash,
|
|
2835
|
+
height: tx.block.height,
|
|
2836
|
+
timestamp: tx.block.timestamp
|
|
2837
|
+
},
|
|
2838
|
+
status,
|
|
2839
|
+
identifiers
|
|
2840
|
+
};
|
|
2841
|
+
}).pipe(require_dist.provide(queryClientLayer), require_dist.scoped, require_dist.retry$1({
|
|
2842
|
+
schedule: require_dist.exponential(require_dist.seconds(1)).pipe(require_dist.either(require_dist.spaced(require_dist.seconds(10))), require_dist.jittered, require_dist.upTo(retryWindow)),
|
|
2843
|
+
while: (error) => error instanceof TransactionHistoryError
|
|
2844
|
+
}), require_dist.mapError$2((error) => error instanceof TransactionHistoryError ? error : new TransactionHistoryError({
|
|
2845
|
+
message: `Failed to fetch transaction metadata for ${hash}`,
|
|
2846
|
+
cause: error
|
|
2847
|
+
})))
|
|
2848
|
+
};
|
|
2849
|
+
};
|
|
2850
|
+
//#endregion
|
|
2851
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/v1/V1Builder.js
|
|
2852
|
+
var V1Builder = class V1Builder {
|
|
2853
|
+
#buildState;
|
|
2854
|
+
constructor(buildState = {}) {
|
|
2855
|
+
this.#buildState = buildState;
|
|
2856
|
+
}
|
|
2857
|
+
withDefaults() {
|
|
2858
|
+
return this.withDefaultTransactionType().withSyncDefaults().withSerializationDefaults().withTransactingDefaults().withCoinsAndBalancesDefaults().withTransactionHistoryDefaults().withKeysDefaults().withStartAuxDefaults().withCoinSelectionDefaults();
|
|
2859
|
+
}
|
|
2860
|
+
withTransactionType() {
|
|
2861
|
+
return new V1Builder({
|
|
2862
|
+
...this.#buildState,
|
|
2863
|
+
transactingCapability: void 0,
|
|
2864
|
+
transactionHistoryService: void 0
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2867
|
+
withDefaultTransactionType() {
|
|
2868
|
+
return this.withTransactionType();
|
|
2869
|
+
}
|
|
2870
|
+
withSyncDefaults() {
|
|
2871
|
+
return this.withSync(makeEventsSyncService, makeEventsSyncCapability);
|
|
2872
|
+
}
|
|
2873
|
+
withSync(syncService, syncCapability) {
|
|
2874
|
+
return new V1Builder({
|
|
2875
|
+
...this.#buildState,
|
|
2876
|
+
syncService,
|
|
2877
|
+
syncCapability,
|
|
2878
|
+
startAux: void 0
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
withSerializationDefaults() {
|
|
2882
|
+
return this.withSerialization(makeDefaultV1SerializationCapability);
|
|
2883
|
+
}
|
|
2884
|
+
withSerialization(serializationCapability) {
|
|
2885
|
+
return new V1Builder({
|
|
2886
|
+
...this.#buildState,
|
|
2887
|
+
serializationCapability
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
withTransactingDefaults() {
|
|
2891
|
+
return this.withTransacting(makeDefaultTransactingCapability);
|
|
2892
|
+
}
|
|
2893
|
+
withTransacting(transactingCapability) {
|
|
2894
|
+
return new V1Builder({
|
|
2895
|
+
...this.#buildState,
|
|
2896
|
+
transactingCapability
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
withCoinSelection(coinSelection) {
|
|
2900
|
+
return new V1Builder({
|
|
2901
|
+
...this.#buildState,
|
|
2902
|
+
coinSelection
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
withCoinSelectionDefaults() {
|
|
2906
|
+
return this.withCoinSelection(() => require_dist.chooseCoin);
|
|
2907
|
+
}
|
|
2908
|
+
withCoinsAndBalancesDefaults() {
|
|
2909
|
+
return this.withCoinsAndBalances(makeDefaultCoinsAndBalancesCapability);
|
|
2910
|
+
}
|
|
2911
|
+
withCoinsAndBalances(coinsAndBalancesCapability) {
|
|
2912
|
+
return new V1Builder({
|
|
2913
|
+
...this.#buildState,
|
|
2914
|
+
coinsAndBalancesCapability
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
withTransactionHistoryDefaults() {
|
|
2918
|
+
return this.withTransactionHistory(makeDefaultTransactionHistoryService);
|
|
2919
|
+
}
|
|
2920
|
+
withTransactionHistory(transactionHistoryService) {
|
|
2921
|
+
return new V1Builder({
|
|
2922
|
+
...this.#buildState,
|
|
2923
|
+
transactionHistoryService
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
withKeysDefaults() {
|
|
2927
|
+
return this.withKeys(makeDefaultKeysCapability);
|
|
2928
|
+
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Uses the default start-aux derivation: this ledger version's Zswap secret keys, derived from the seed.
|
|
2931
|
+
*
|
|
2932
|
+
* @remarks
|
|
2933
|
+
* The seed is the only key material that crosses a protocol boundary, so every variant must be able to produce its
|
|
2934
|
+
* own from one. This is that derivation for this ledger version; a builder whose sync service expects something
|
|
2935
|
+
* else supplies its own with {@link V1Builder.withStartAux}.
|
|
2936
|
+
*/
|
|
2937
|
+
withStartAuxDefaults() {
|
|
2938
|
+
return this.withStartAux({ fromSeed: (seed) => _midnight_ntwrk_ledger_v8.ZswapSecretKeys.fromSeed(seed) });
|
|
2939
|
+
}
|
|
2940
|
+
/**
|
|
2941
|
+
* Chooses how this variant derives the key material its synchronization is started with from a seed.
|
|
2942
|
+
*
|
|
2943
|
+
* @param startAux The derivation.
|
|
2944
|
+
* @returns A builder that produces a variant able to start sync from a seed alone.
|
|
2945
|
+
*/
|
|
2946
|
+
withStartAux(startAux) {
|
|
2947
|
+
return new V1Builder({
|
|
2948
|
+
...this.#buildState,
|
|
2949
|
+
startAux
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
/**
|
|
2953
|
+
* Uses the default migration: an empty wallet built from nothing.
|
|
2954
|
+
*
|
|
2955
|
+
* @remarks
|
|
2956
|
+
* This is what an unconfigured builder already does, so calling it changes no behaviour — it states the choice rather
|
|
2957
|
+
* than inheriting it. Registering this variant as the target of a real fork means calling
|
|
2958
|
+
* {@link V1Builder.withMigration} with {@link makeCrossLedgerMigration} instead.
|
|
2959
|
+
*/
|
|
2960
|
+
withMigrationDefaults() {
|
|
2961
|
+
return this.withMigration((configuration) => makeEmptyWalletMigration(configuration));
|
|
2962
|
+
}
|
|
2963
|
+
/**
|
|
2964
|
+
* Chooses how this variant produces its first state from the state that preceded it.
|
|
2965
|
+
*
|
|
2966
|
+
* @remarks
|
|
2967
|
+
* The strategy's input type becomes the variant's `TPreviousState`, which is what the runtime type-checks a
|
|
2968
|
+
* registration against: a variant declaring it migrates from a ledger-v8 wallet cannot be registered after one that
|
|
2969
|
+
* produces something else.
|
|
2970
|
+
* @example
|
|
2971
|
+
* ```typescript
|
|
2972
|
+
* const forkTarget = new V1Builder().withDefaults().withMigration(makeCrossLedgerMigration);
|
|
2973
|
+
* ```;
|
|
2974
|
+
*
|
|
2975
|
+
* @param migration Builds the migration from the configuration and the sibling capabilities.
|
|
2976
|
+
*/
|
|
2977
|
+
withMigration(migration) {
|
|
2978
|
+
const capabilities = this.#buildState;
|
|
2979
|
+
return new V1Builder({
|
|
2980
|
+
...capabilities,
|
|
2981
|
+
migration
|
|
2982
|
+
});
|
|
2983
|
+
}
|
|
2984
|
+
withKeys(keysCapability) {
|
|
2985
|
+
return new V1Builder({
|
|
2986
|
+
...this.#buildState,
|
|
2987
|
+
keysCapability
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
build(configuration) {
|
|
2991
|
+
const v1Context = this.#buildContextFromBuildState(configuration);
|
|
2992
|
+
const migration = this.#resolveMigration(configuration, () => v1Context);
|
|
2993
|
+
return {
|
|
2994
|
+
__polyTag__: V1Tag,
|
|
2995
|
+
coinsAndBalances: v1Context.coinsAndBalancesCapability,
|
|
2996
|
+
keys: v1Context.keysCapability,
|
|
2997
|
+
serialization: v1Context.serializationCapability,
|
|
2998
|
+
transactionHistory: v1Context.transactionHistoryService,
|
|
2999
|
+
startAux: this.#resolveStartAux(),
|
|
3000
|
+
start(context) {
|
|
3001
|
+
return require_dist.gen(function* () {
|
|
3002
|
+
return new RunningV1Variant(yield* require_dist.Scope, context, v1Context);
|
|
3003
|
+
});
|
|
3004
|
+
},
|
|
3005
|
+
migrateState: (previousState) => migration.migrate(previousState).pipe(require_dist.mapError$2((error) => new require_dist.WalletRuntimeError({
|
|
3006
|
+
message: "Failed to migrate shielded wallet state into this variant",
|
|
3007
|
+
cause: error
|
|
3008
|
+
}))),
|
|
3009
|
+
deserializeState: (serialized) => {
|
|
3010
|
+
return v1Context.serializationCapability.deserialize(null, serialized);
|
|
3011
|
+
}
|
|
3012
|
+
};
|
|
3013
|
+
}
|
|
3014
|
+
/**
|
|
3015
|
+
* Resolves the configured migration, or the empty-wallet fallback when none was configured.
|
|
3016
|
+
*
|
|
3017
|
+
* @remarks
|
|
3018
|
+
* The fallback is written as a nullary function on purpose. It ignores whatever preceded it — it builds an empty
|
|
3019
|
+
* wallet from nothing — which makes it a valid migration from _any_ previous state, but a `StateMigration<null>`
|
|
3020
|
+
* value could only be widened to `StateMigration<TPreviousState>` through a cast. Declaring no parameter says the
|
|
3021
|
+
* same thing to the type system without one.
|
|
3022
|
+
*/
|
|
3023
|
+
/**
|
|
3024
|
+
* Resolves the configured start-aux derivation.
|
|
3025
|
+
*
|
|
3026
|
+
* @remarks
|
|
3027
|
+
* Unlike the migration there is no sensible fallback: the default derivation produces this ledger version's secret
|
|
3028
|
+
* keys, which is only correct for a builder that kept a sync service expecting them. A builder that replaced sync
|
|
3029
|
+
* and did not say how to derive its own key material is misconfigured, and is told so at build time rather than
|
|
3030
|
+
* silently handed key objects of the wrong shape at the first migration.
|
|
3031
|
+
*/
|
|
3032
|
+
#resolveStartAux() {
|
|
3033
|
+
const configured = this.#buildState.startAux;
|
|
3034
|
+
if (configured === void 0) throw new Error("Not all components are configured in V1 Builder: startAux");
|
|
3035
|
+
return configured;
|
|
3036
|
+
}
|
|
3037
|
+
#resolveMigration(configuration, getContext) {
|
|
3038
|
+
const configured = this.#buildState.migration;
|
|
3039
|
+
return configured === void 0 ? { migrate: () => makeEmptyWalletMigration(configuration).migrate(null) } : configured(configuration, getContext);
|
|
3040
|
+
}
|
|
3041
|
+
#buildContextFromBuildState(configuration) {
|
|
3042
|
+
if (!isBuildStateFull(this.#buildState)) throw new Error("Not all components are configured in V1 Builder");
|
|
3043
|
+
const { syncCapability, syncService, transactingCapability, serializationCapability, coinSelection, coinsAndBalancesCapability, keysCapability, transactionHistoryService } = this.#buildState;
|
|
3044
|
+
const getContext = () => context;
|
|
3045
|
+
const context = {
|
|
3046
|
+
serializationCapability: serializationCapability(configuration, getContext),
|
|
3047
|
+
syncCapability: syncCapability(configuration, getContext),
|
|
3048
|
+
syncService: syncService(configuration, getContext),
|
|
3049
|
+
transactingCapability: transactingCapability(configuration, getContext),
|
|
3050
|
+
coinsAndBalancesCapability: coinsAndBalancesCapability(configuration, getContext),
|
|
3051
|
+
keysCapability: keysCapability(configuration, getContext),
|
|
3052
|
+
coinSelection: coinSelection(configuration, getContext),
|
|
3053
|
+
transactionHistoryService: transactionHistoryService(configuration, getContext)
|
|
3054
|
+
};
|
|
3055
|
+
return context;
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
const isBuildStateFull = (buildState) => {
|
|
3059
|
+
return [
|
|
3060
|
+
"syncService",
|
|
3061
|
+
"syncCapability",
|
|
3062
|
+
"transactingCapability",
|
|
3063
|
+
"coinSelection",
|
|
3064
|
+
"serializationCapability",
|
|
3065
|
+
"coinsAndBalancesCapability",
|
|
3066
|
+
"keysCapability",
|
|
3067
|
+
"transactionHistoryService"
|
|
3068
|
+
].every((key) => typeof buildState[key] == "function");
|
|
3069
|
+
};
|
|
3070
|
+
//#endregion
|
|
3071
|
+
//#region ../../packages/module/passport-account/node_modules/@midnightntwrk/wallet-sdk-shielded/dist/ShieldedWallet.js
|
|
3072
|
+
/**
|
|
3073
|
+
* Builds a shielded wallet class over a variant either side of a protocol boundary.
|
|
3074
|
+
*
|
|
3075
|
+
* @remarks
|
|
3076
|
+
* The boundary is `configuration.forks.v9` and nothing else: the V1 variant is registered from the minimum supported
|
|
3077
|
+
* version and the ledger-v9 one from the fork version, so the version at which the runtime hands over and the version
|
|
3078
|
+
* at which each variant stops applying are the same number, taken from one place.
|
|
3079
|
+
*
|
|
3080
|
+
* Each variant is built from its own configuration. What the wallet layer needs — the network it is on and where the
|
|
3081
|
+
* boundary lies — it takes separately, because neither variant knows there is another one.
|
|
3082
|
+
* @example
|
|
3083
|
+
* ```typescript
|
|
3084
|
+
* const Wallet = CustomForkingShieldedWallet(
|
|
3085
|
+
* { networkId, forks },
|
|
3086
|
+
* { builder: new V1Builder().withDefaults(), configuration: v1Configuration },
|
|
3087
|
+
* { builder: new V2Builder().withDefaults().withMigration(makeCrossLedgerMigration), configuration: v2Configuration },
|
|
3088
|
+
* );
|
|
3089
|
+
* const wallet = Wallet.startWithSeed(seed);
|
|
3090
|
+
* ```;
|
|
3091
|
+
*
|
|
3092
|
+
* @param configuration What the wallet layer needs: the network, and where the boundary lies.
|
|
3093
|
+
* @param v1 The variant that reads the chain below the boundary, with the configuration it is built from.
|
|
3094
|
+
* @param v2 The variant that reads it from the boundary, with the configuration it is built from.
|
|
3095
|
+
* @returns The wallet class.
|
|
3096
|
+
*/
|
|
3097
|
+
function CustomForkingShieldedWallet(configuration, v1, v2) {
|
|
3098
|
+
const v1Builder = v1.builder;
|
|
3099
|
+
const v2Builder = v2.builder;
|
|
3100
|
+
const BaseWallet = require_dist.WalletBuilder.init().withVariant(require_dist.MinSupportedVersion, v1Builder, v1.configuration).withVariant(configuration.forks.v9, v2Builder, v2.configuration).build();
|
|
3101
|
+
const variants = BaseWallet.allVariantsRecord();
|
|
3102
|
+
/** Nothing retained: never started, or stopped. */
|
|
3103
|
+
const noKeys = {
|
|
3104
|
+
v8: require_dist.none(),
|
|
3105
|
+
v9: require_dist.none()
|
|
3106
|
+
};
|
|
3107
|
+
/** Both sides, derived from one seed. */
|
|
3108
|
+
const keysFromSeed = (seed) => ({
|
|
3109
|
+
v8: require_dist.some(variants[V1Tag].variant.startAux.fromSeed(seed)),
|
|
3110
|
+
v9: require_dist.some(variants[V2Tag].variant.startAux.fromSeed(seed))
|
|
3111
|
+
});
|
|
3112
|
+
/**
|
|
3113
|
+
* What a variant can be started with, or why it cannot be.
|
|
3114
|
+
*
|
|
3115
|
+
* @remarks
|
|
3116
|
+
* Two different failures, deliberately distinguished: a wallet that was never started (or has been stopped) holds
|
|
3117
|
+
* nothing at all, while one started with the other side's key objects holds something it must not use here.
|
|
3118
|
+
*/
|
|
3119
|
+
const auxFor = (retained, side, variantTag) => require_dist.fromOption(side, () => new require_dist.MissingStartAuxError({
|
|
3120
|
+
message: require_dist.isNone(retained.v8) && require_dist.isNone(retained.v9) ? "This wallet holds no key material: it has not been started, or it has been stopped. Start it before asking it to synchronize or to build a transaction." : `This wallet holds key material of the other protocol version only, which the variant ${String(variantTag)} cannot use: key objects belong to one ledger version's runtime. Start this wallet with material that answers for either side — startWithSeed(seed), or startWithKeys({ v8, v9 }).`,
|
|
3121
|
+
variantTag
|
|
3122
|
+
}));
|
|
3123
|
+
const v8Aux = (retained) => auxFor(retained, retained.v8, V1Tag);
|
|
3124
|
+
const v9Aux = (retained) => auxFor(retained, retained.v9, V2Tag);
|
|
3125
|
+
/**
|
|
3126
|
+
* The protocol versions each variant owns, and the version a transaction it builds is stamped with.
|
|
3127
|
+
*
|
|
3128
|
+
* @remarks
|
|
3129
|
+
* The stamp is the version at which the variant that built the transaction became current — the floor of its epoch —
|
|
3130
|
+
* rather than the block height the chain happened to be at. Every decision the stamp is later read for asks which
|
|
3131
|
+
* side of the boundary the bytes belong to: which prover proves them, which validator checks them, which variant
|
|
3132
|
+
* may unwrap them. The epoch floor is the one value guaranteed to answer that the same way as any other version in
|
|
3133
|
+
* the same epoch, and it is derived here from the same `forks.v9` the variants are registered at.
|
|
3134
|
+
*/
|
|
3135
|
+
const v8Epoch = require_dist.epochOf(require_dist.MinSupportedVersion, configuration.forks.v9);
|
|
3136
|
+
const v9Epoch = require_dist.epochOf(configuration.forks.v9, configuration.forks.v9);
|
|
3137
|
+
const [v8Stamp] = v8Epoch;
|
|
3138
|
+
const [v9Stamp] = v9Epoch;
|
|
3139
|
+
/** Seals a balancing result, which is absent when the wallet had nothing of its own to add. */
|
|
3140
|
+
const sealV8 = (result) => result === void 0 ? void 0 : require_dist.WalletTransaction.adopt("Unproven", result, v8Stamp);
|
|
3141
|
+
const sealV9 = (result) => result === void 0 ? void 0 : require_dist.WalletTransaction.adopt("Unproven", result, v9Stamp);
|
|
3142
|
+
/**
|
|
3143
|
+
* How long a start waits for the chain to say which version it is on.
|
|
3144
|
+
*
|
|
3145
|
+
* @remarks
|
|
3146
|
+
* Short, because what is being bought is small: the alternative to an answer is the hand-over this wallet has always
|
|
3147
|
+
* done, which costs one migration and no correctness on a chain that produces events. It is a ceiling rather than a
|
|
3148
|
+
* typical cost — an unreachable indexer refuses a connection long before this — and it exists so that a probe which
|
|
3149
|
+
* neither answers nor fails cannot hold a start open indefinitely.
|
|
3150
|
+
*/
|
|
3151
|
+
const probeTimeout = require_dist.seconds(5);
|
|
3152
|
+
/**
|
|
3153
|
+
* The variant the chain's current version belongs to, or nothing.
|
|
3154
|
+
*
|
|
3155
|
+
* @remarks
|
|
3156
|
+
* Nothing covers every way the question can fail to produce an answer, and they are deliberately not distinguished:
|
|
3157
|
+
* no probe configured, a probe that rejected, a probe that outlived the wallet's patience, or a version no
|
|
3158
|
+
* registered variant claims. Each means the same thing to a caller — start where a wallet with no history starts —
|
|
3159
|
+
* and none of them is a reason to fail.
|
|
3160
|
+
*/
|
|
3161
|
+
const probedStart = configuration.chainVersionProbe === void 0 ? require_dist.succeedNone : require_dist.pipe(require_dist.tryPromise(configuration.chainVersionProbe), require_dist.timeout(probeTimeout), require_dist.map$2((version) => require_dist.map$5(BaseWallet.variantFor(version), (variant) => ({
|
|
3162
|
+
version,
|
|
3163
|
+
variant
|
|
3164
|
+
}))), require_dist.orElseSucceed(() => require_dist.none()));
|
|
3165
|
+
/**
|
|
3166
|
+
* A fresh state of the variant a probed start begins at, recording the version the chain reported.
|
|
3167
|
+
*
|
|
3168
|
+
* @remarks
|
|
3169
|
+
* Built exactly as the head-variant boot path builds its own — an empty state of that variant, from that ledger
|
|
3170
|
+
* version's keys — and then annotated with the observed version, which is what keeps a variant from starting
|
|
3171
|
+
* outside its own activation range and signalling backwards on sight.
|
|
3172
|
+
*/
|
|
3173
|
+
const freshStateAt = (variant, keys, version) => require_dist.getVersionedVariantTag(variant) === V2Tag ? CoreWallet$1.withProtocolVersion(CoreWallet$1.initEmpty(keys.v9, configuration.networkId), version) : CoreWallet.withProtocolVersion(CoreWallet.initEmpty(keys.v8, configuration.networkId), version);
|
|
3174
|
+
return class ForkingShieldedWalletImplementation extends BaseWallet {
|
|
3175
|
+
static configuration = configuration;
|
|
3176
|
+
/**
|
|
3177
|
+
* Starts at the variant the chain says it is on, or at the head variant when it does not say.
|
|
3178
|
+
*
|
|
3179
|
+
* @remarks
|
|
3180
|
+
* The second branch is the whole of this wallet's previous behaviour, unchanged and reached whenever the chain was
|
|
3181
|
+
* not asked or did not answer: the V1 variant, an empty state, and a hand-over on the first batch that reports a
|
|
3182
|
+
* version it does not own.
|
|
3183
|
+
* @param keys One ledger version's keys per side of the boundary, since either side may be the one that runs.
|
|
3184
|
+
* @returns The started wallet.
|
|
3185
|
+
*/
|
|
3186
|
+
static #startProbed(keys) {
|
|
3187
|
+
return require_dist.pipe(probedStart, require_dist.map$2(require_dist.match$1({
|
|
3188
|
+
onNone: () => ForkingShieldedWalletImplementation.startFirst(ForkingShieldedWalletImplementation, CoreWallet.initEmpty(keys.v8, configuration.networkId)),
|
|
3189
|
+
onSome: ({ version, variant }) => ForkingShieldedWalletImplementation.startAtVariant(ForkingShieldedWalletImplementation, variant, freshStateAt(variant, keys, version))
|
|
3190
|
+
})), require_dist.runPromise$1);
|
|
3191
|
+
}
|
|
3192
|
+
static async startWithSeed(seed) {
|
|
3193
|
+
const derived = keysFromSeed(require_dist.WalletSeed(seed));
|
|
3194
|
+
const wallet = await ForkingShieldedWalletImplementation.#startProbed({
|
|
3195
|
+
v8: require_dist.getOrThrow(derived.v8),
|
|
3196
|
+
v9: require_dist.getOrThrow(derived.v9)
|
|
3197
|
+
});
|
|
3198
|
+
wallet.#retainKeys(derived);
|
|
3199
|
+
return wallet;
|
|
3200
|
+
}
|
|
3201
|
+
static async startWithKeys(keys) {
|
|
3202
|
+
const wallet = await ForkingShieldedWalletImplementation.#startProbed(keys);
|
|
3203
|
+
wallet.#retainKeys({
|
|
3204
|
+
v8: require_dist.some(keys.v8),
|
|
3205
|
+
v9: require_dist.some(keys.v9)
|
|
3206
|
+
});
|
|
3207
|
+
return wallet;
|
|
3208
|
+
}
|
|
3209
|
+
static tryRestore(serializedState) {
|
|
3210
|
+
return variantForSnapshot(serializedState, (version) => ForkingShieldedWalletImplementation.variantFor(version), require_dist.head(ForkingShieldedWalletImplementation.allVariants())).pipe(require_dist.flatMap$4((variant) => {
|
|
3211
|
+
const deserialized = variant.variant.deserializeState(serializedState);
|
|
3212
|
+
return require_dist.map$6(deserialized, (state) => ForkingShieldedWalletImplementation.startAtVariant(ForkingShieldedWalletImplementation, variant, state));
|
|
3213
|
+
}));
|
|
3214
|
+
}
|
|
3215
|
+
static restore(serializedState) {
|
|
3216
|
+
return require_dist.getOrThrow$1(ForkingShieldedWalletImplementation.tryRestore(serializedState));
|
|
3217
|
+
}
|
|
3218
|
+
state;
|
|
3219
|
+
/**
|
|
3220
|
+
* What the application started this wallet with, kept so synchronization can be started again.
|
|
3221
|
+
*
|
|
3222
|
+
* @remarks
|
|
3223
|
+
* A migration starts a fresh variant whose sync has never run, and sync needs key material that is deliberately
|
|
3224
|
+
* absent from anything the wallet serializes. A retained seed answers for both variants; retained key objects
|
|
3225
|
+
* answer only for the ledger-v9 one, which is the ledger version this wallet's public API speaks. Cleared by
|
|
3226
|
+
* {@link stop} so a stopped wallet cannot be resurrected by a late activation.
|
|
3227
|
+
*/
|
|
3228
|
+
#retainedKeys = require_dist.unsafeMake(noKeys);
|
|
3229
|
+
/** Remembers key material for both sides of the boundary. */
|
|
3230
|
+
#retainKeys(keys) {
|
|
3231
|
+
require_dist.set(this.#retainedKeys, keys).pipe(require_dist.runSync);
|
|
3232
|
+
}
|
|
3233
|
+
/**
|
|
3234
|
+
* Starts synchronization on a variant that has just become current, with key material it can use.
|
|
3235
|
+
*
|
|
3236
|
+
* @param running The variant to start.
|
|
3237
|
+
* @param auxFor That variant's own resolution of what it can be started with.
|
|
3238
|
+
*/
|
|
3239
|
+
#resumeSyncOn(running, keysFor) {
|
|
3240
|
+
return require_dist.get$1(this.#retainedKeys).pipe(require_dist.flatMap$1((retained) => require_dist.isNone(retained.v8) && require_dist.isNone(retained.v9) ? require_dist._void : require_dist.toEffect(keysFor(retained)).pipe(require_dist.flatMap$1((aux) => running.startSyncInBackground(aux)))));
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* Whether the activation watcher has been registered.
|
|
3244
|
+
*
|
|
3245
|
+
* @remarks
|
|
3246
|
+
* Registration is per wallet, not per `start`: watchers accumulate, so registering on every call would restart sync
|
|
3247
|
+
* once per historical `start` on the next activation. Flipped with `getAndSet` so concurrent `start` calls cannot
|
|
3248
|
+
* both observe it unset.
|
|
3249
|
+
*/
|
|
3250
|
+
#watcherRegistered = require_dist.unsafeMake(false);
|
|
3251
|
+
constructor(runtime, scope) {
|
|
3252
|
+
super(runtime, scope);
|
|
3253
|
+
this.state = this.rawState.pipe(rxjs.map((emission) => emission.variantTag === V2Tag ? ShieldedWalletState.fromVariant(variants[V2Tag].variant, emission) : ShieldedWalletState.fromVariant(variants[V1Tag].variant, emission)), rxjs.shareReplay({
|
|
3254
|
+
refCount: true,
|
|
3255
|
+
bufferSize: 1
|
|
3256
|
+
}));
|
|
3257
|
+
}
|
|
3258
|
+
/**
|
|
3259
|
+
* Everything a start does once the wallet holds its key material: watch for the next variant, synchronize on this
|
|
3260
|
+
* one.
|
|
3261
|
+
*
|
|
3262
|
+
* @remarks
|
|
3263
|
+
* The same work whichever start was called — what the three differ in is only what they retained a moment earlier —
|
|
3264
|
+
* so it is stated once. The watcher is registered before the first dispatch and only once per wallet:
|
|
3265
|
+
* `onVariantActivation` resolves only after its subscription is live, so an activation racing a start is queued
|
|
3266
|
+
* rather than missed, and watchers accumulate, so registering per call would restart synchronization once per
|
|
3267
|
+
* historical start.
|
|
3268
|
+
*
|
|
3269
|
+
* Both branches of the dispatch resolve their keys from what was retained rather than from what the caller passed,
|
|
3270
|
+
* because the variant that is current is not the caller's to know: a wallet restored below the boundary is on the
|
|
3271
|
+
* ledger-v8 one whatever the application holds.
|
|
3272
|
+
*/
|
|
3273
|
+
#startSynchronizing() {
|
|
3274
|
+
return require_dist.gen(this, function* () {
|
|
3275
|
+
if (!(yield* require_dist.getAndSet(this.#watcherRegistered, true))) yield* this.runtime.onVariantActivation({
|
|
3276
|
+
[V1Tag]: (v1) => this.#resumeSyncOn(v1, v8Aux),
|
|
3277
|
+
[V2Tag]: (v2) => this.#resumeSyncOn(v2, v9Aux)
|
|
3278
|
+
});
|
|
3279
|
+
yield* this.runtime.dispatch({
|
|
3280
|
+
[V1Tag]: (v1) => this.#resumeSyncOn(v1, v8Aux),
|
|
3281
|
+
[V2Tag]: (v2) => this.#resumeSyncOn(v2, v9Aux)
|
|
3282
|
+
});
|
|
3283
|
+
});
|
|
3284
|
+
}
|
|
3285
|
+
/**
|
|
3286
|
+
* Starts background synchronization on whichever variant is current, and keeps the keys for the next one.
|
|
3287
|
+
*
|
|
3288
|
+
* @remarks
|
|
3289
|
+
* The keys are ledger-v9's, so they are retained against that variant alone and answer for it alone. A wallet still
|
|
3290
|
+
* on the V1 variant is started from whatever it holds for _that_ side — which a wallet built from a seed, or from
|
|
3291
|
+
* both versions' keys, can always answer and one holding only these cannot.
|
|
3292
|
+
*
|
|
3293
|
+
* That is the position of a wallet restored from a snapshot written below the boundary: a snapshot carries no key
|
|
3294
|
+
* material, so these keys leave it with nothing the running variant can use, and it says so rather than
|
|
3295
|
+
* pretending to have started. {@link ForkingShieldedWallet.startWithSeed} and
|
|
3296
|
+
* {@link ForkingShieldedWallet.startWithKeys} are the same wallet started with material that answers for either
|
|
3297
|
+
* side.
|
|
3298
|
+
* @param secretKeys The ledger-v9's Zswap secret keys.
|
|
3299
|
+
*/
|
|
3300
|
+
start(secretKeys) {
|
|
3301
|
+
return require_dist.gen(this, function* () {
|
|
3302
|
+
yield* require_dist.update(this.#retainedKeys, (retained) => ({
|
|
3303
|
+
...retained,
|
|
3304
|
+
v9: require_dist.some(secretKeys)
|
|
3305
|
+
}));
|
|
3306
|
+
yield* this.#startSynchronizing();
|
|
3307
|
+
}).pipe(require_dist.runPromise$1);
|
|
3308
|
+
}
|
|
3309
|
+
startWithSeed(seed) {
|
|
3310
|
+
return require_dist.gen(this, function* () {
|
|
3311
|
+
yield* require_dist.set(this.#retainedKeys, keysFromSeed(require_dist.WalletSeed(seed)));
|
|
3312
|
+
yield* this.#startSynchronizing();
|
|
3313
|
+
}).pipe(require_dist.runPromise$1);
|
|
3314
|
+
}
|
|
3315
|
+
startWithKeys(keys) {
|
|
3316
|
+
return require_dist.gen(this, function* () {
|
|
3317
|
+
yield* require_dist.set(this.#retainedKeys, {
|
|
3318
|
+
v8: require_dist.some(keys.v8),
|
|
3319
|
+
v9: require_dist.some(keys.v9)
|
|
3320
|
+
});
|
|
3321
|
+
yield* this.#startSynchronizing();
|
|
3322
|
+
}).pipe(require_dist.runPromise$1);
|
|
3323
|
+
}
|
|
3324
|
+
async stop() {
|
|
3325
|
+
require_dist.set(this.#retainedKeys, noKeys).pipe(require_dist.runSync);
|
|
3326
|
+
await super.stop();
|
|
3327
|
+
}
|
|
3328
|
+
/**
|
|
3329
|
+
* The key material the variant that is current can use, from what this wallet retained.
|
|
3330
|
+
*
|
|
3331
|
+
* @remarks
|
|
3332
|
+
* Transacting needs the same secrets synchronization does, and for the same reason: coin selection reads coins only
|
|
3333
|
+
* their owner can decrypt. A wallet that was never started, or one holding key objects of the other ledger
|
|
3334
|
+
* version, has none the current variant can use and says so by name.
|
|
3335
|
+
*/
|
|
3336
|
+
#requireAux(keysFor) {
|
|
3337
|
+
return require_dist.get$1(this.#retainedKeys).pipe(require_dist.flatMap$1((retained) => require_dist.toEffect(keysFor(retained))));
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Balances a transaction with shielded coins, on whichever side of the boundary it was built.
|
|
3341
|
+
*
|
|
3342
|
+
* @param tx The transaction to balance, which must have been built in the epoch this wallet is currently in.
|
|
3343
|
+
* @returns The balancing transaction, stamped with the version it was built at, or nothing when none is needed.
|
|
3344
|
+
*/
|
|
3345
|
+
balanceTransaction(tx) {
|
|
3346
|
+
return this.runtime.dispatch({
|
|
3347
|
+
[V1Tag]: (v1) => require_dist.all([this.#requireAux(v8Aux), require_dist.toEffect(require_dist.WalletTransaction.unwrapWithin(tx, v8Epoch))]).pipe(require_dist.flatMap$1(([keys, unwrapped]) => v1.balanceTransaction(keys, unwrapped)), require_dist.map$2(sealV8)),
|
|
3348
|
+
[V2Tag]: (v2) => require_dist.all([this.#requireAux(v9Aux), require_dist.toEffect(require_dist.WalletTransaction.unwrapWithin(tx, v9Epoch))]).pipe(require_dist.flatMap$1(([keys, unwrapped]) => v2.balanceTransaction(keys, unwrapped)), require_dist.map$2(sealV9))
|
|
3349
|
+
}).pipe(require_dist.runPromise$1);
|
|
3350
|
+
}
|
|
3351
|
+
transferTransaction(outputs) {
|
|
3352
|
+
return this.runtime.dispatch({
|
|
3353
|
+
[V1Tag]: (v1) => this.#requireAux(v8Aux).pipe(require_dist.flatMap$1((keys) => v1.transferTransaction(keys, outputs)), require_dist.map$2((tx) => require_dist.WalletTransaction.adopt("Unproven", tx, v8Stamp))),
|
|
3354
|
+
[V2Tag]: (v2) => this.#requireAux(v9Aux).pipe(require_dist.flatMap$1((keys) => v2.transferTransaction(keys, outputs)), require_dist.map$2((tx) => require_dist.WalletTransaction.adopt("Unproven", tx, v9Stamp)))
|
|
3355
|
+
}).pipe(require_dist.runPromise$1);
|
|
3356
|
+
}
|
|
3357
|
+
initSwap(desiredInputs, desiredOutputs) {
|
|
3358
|
+
return this.runtime.dispatch({
|
|
3359
|
+
[V1Tag]: (v1) => this.#requireAux(v8Aux).pipe(require_dist.flatMap$1((keys) => v1.initSwap(keys, desiredInputs, desiredOutputs)), require_dist.map$2((tx) => require_dist.WalletTransaction.adopt("Unproven", tx, v8Stamp))),
|
|
3360
|
+
[V2Tag]: (v2) => this.#requireAux(v9Aux).pipe(require_dist.flatMap$1((keys) => v2.initSwap(keys, desiredInputs, desiredOutputs)), require_dist.map$2((tx) => require_dist.WalletTransaction.adopt("Unproven", tx, v9Stamp)))
|
|
3361
|
+
}).pipe(require_dist.runPromise$1);
|
|
3362
|
+
}
|
|
3363
|
+
/**
|
|
3364
|
+
* Un-records a transaction this wallet produced, releasing the coins it had booked.
|
|
3365
|
+
*
|
|
3366
|
+
* @remarks
|
|
3367
|
+
* A transaction built on the other side of the boundary is not one the current variant could have booked coins for,
|
|
3368
|
+
* so there is nothing of it to release and this resolves having done nothing. That is the one place a version
|
|
3369
|
+
* mismatch is not an error: the facade reverts all three wallets together when a submission fails, and a refusal
|
|
3370
|
+
* here would strand that whole path over a transaction this wallet was never holding anything for.
|
|
3371
|
+
*
|
|
3372
|
+
* The coins a ledger-v8 transaction did book are not left behind by that no-op: they crossed the boundary as
|
|
3373
|
+
* reservations, and the first sync update after the crossing releases every one of them, because no transaction
|
|
3374
|
+
* of that ledger version can be included any more (`v2/CoreWallet.completeCrossing`).
|
|
3375
|
+
* @param transaction The transaction to un-record.
|
|
3376
|
+
*/
|
|
3377
|
+
revertTransaction(transaction) {
|
|
3378
|
+
return this.runtime.dispatch({
|
|
3379
|
+
[V1Tag]: (v1) => require_dist.match$2(require_dist.WalletTransaction.unwrapWithin(transaction, v8Epoch), {
|
|
3380
|
+
onLeft: () => require_dist._void,
|
|
3381
|
+
onRight: (unwrapped) => v1.revertTransaction(unwrapped)
|
|
3382
|
+
}),
|
|
3383
|
+
[V2Tag]: (v2) => require_dist.match$2(require_dist.WalletTransaction.unwrapWithin(transaction, v9Epoch), {
|
|
3384
|
+
onLeft: () => require_dist._void,
|
|
3385
|
+
onRight: (unwrapped) => v2.revertTransaction(unwrapped)
|
|
3386
|
+
})
|
|
3387
|
+
}).pipe(require_dist.runPromise$1);
|
|
3388
|
+
}
|
|
3389
|
+
waitForSyncedState(allowedGap = 0n) {
|
|
3390
|
+
return rxjs.firstValueFrom(this.state.pipe(rxjs.filter((state) => state.state.progress.isCompleteWithin(allowedGap))));
|
|
3391
|
+
}
|
|
3392
|
+
/**
|
|
3393
|
+
* Serializes the most recent state. It's preferable to use [[ShieldedWalletState.serialize]] instead, to know
|
|
3394
|
+
* exactly which state is serialized.
|
|
3395
|
+
*/
|
|
3396
|
+
serializeState() {
|
|
3397
|
+
return rxjs.firstValueFrom(this.state).then((state) => state.serialize());
|
|
3398
|
+
}
|
|
3399
|
+
getAddress() {
|
|
3400
|
+
return rxjs.firstValueFrom(this.state).then((state) => state.address);
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
}
|
|
3404
|
+
/**
|
|
3405
|
+
* Builds the shielded wallet this package ships: the default variant either side of `configuration.forks.v9`.
|
|
3406
|
+
*
|
|
3407
|
+
* @remarks
|
|
3408
|
+
* Both variants read the chain through the indexer and record transaction history in the same storage; each is built
|
|
3409
|
+
* from the same application configuration, because what they ask for happens to coincide. The V2 variant is
|
|
3410
|
+
* registered with the cross-ledger migration, which is what makes the hand-over carry identity and a cursor onto a
|
|
3411
|
+
* fresh state rather than start a wallet from nothing.
|
|
3412
|
+
*
|
|
3413
|
+
* **Transacting works on either side of the boundary**: the active variant builds with its own ledger and its own
|
|
3414
|
+
* derived keys, and every result travels as a handle stamped with the epoch that built it. Proving a ledger-v8
|
|
3415
|
+
* transaction still requires a proving server registered below the boundary.
|
|
3416
|
+
*
|
|
3417
|
+
* **The chain is asked where it is before a variant is chosen.** The indexer this wallet already syncs from answers
|
|
3418
|
+
* which protocol version the chain is on, so a start on a chain past the boundary begins on V2 rather than handing
|
|
3419
|
+
* over immediately. An application that would rather ask something else — a cache, a value it already holds —
|
|
3420
|
+
* supplies its own `chainVersionProbe`; one whose chain cannot be reached loses nothing, because the answer is
|
|
3421
|
+
* best-effort and its absence is the behaviour this wallet had before.
|
|
3422
|
+
* @param configuration What the wallet and both its variants are built from, including where the boundary lies.
|
|
3423
|
+
* @returns The wallet class.
|
|
3424
|
+
*/
|
|
3425
|
+
function ShieldedWallet(configuration) {
|
|
3426
|
+
return CustomForkingShieldedWallet({
|
|
3427
|
+
...configuration,
|
|
3428
|
+
chainVersionProbe: configuration.chainVersionProbe ?? require_dist.makeIndexerChainVersionProbe(configuration)
|
|
3429
|
+
}, {
|
|
3430
|
+
builder: new V1Builder().withDefaults(),
|
|
3431
|
+
configuration
|
|
3432
|
+
}, {
|
|
3433
|
+
builder: new V2Builder().withDefaults().withMigration(() => makeCrossLedgerMigration()),
|
|
3434
|
+
configuration
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
//#endregion
|
|
3438
|
+
exports.CustomForkingShieldedWallet = CustomForkingShieldedWallet;
|
|
3439
|
+
exports.CustomShieldedWallet = CustomShieldedWallet;
|
|
3440
|
+
Object.defineProperty(exports, "Restore", {
|
|
3441
|
+
enumerable: true,
|
|
3442
|
+
get: function() {
|
|
3443
|
+
return Restore_exports;
|
|
3444
|
+
}
|
|
3445
|
+
});
|
|
3446
|
+
exports.ShieldedSectionSchema = ShieldedSectionSchema;
|
|
3447
|
+
exports.ShieldedSectionSchema$1 = ShieldedSectionSchema;
|
|
3448
|
+
exports.ShieldedWallet = ShieldedWallet;
|
|
3449
|
+
exports.ShieldedWalletState = ShieldedWalletState;
|
|
3450
|
+
exports.V9_NATIVE_FORK_VERSION = V9_NATIVE_FORK_VERSION;
|
|
3451
|
+
exports.mergeShieldedSections = mergeShieldedSections;
|
|
3452
|
+
exports.mergeShieldedSections$1 = mergeShieldedSections;
|