@web3auth/no-modal 9.5.4 → 10.0.0-alpha.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/757.noModal.cjs.js +226 -0
- package/dist/lib.cjs/adapters/auth-adapter/authAdapter.js +262 -0
- package/dist/lib.cjs/adapters/auth-adapter/config.js +17 -0
- package/dist/lib.cjs/adapters/base-evm-adapter/baseEvmAdapter.js +72 -0
- package/dist/lib.cjs/adapters/base-solana-adapter/baseSolanaAdapter.js +76 -0
- package/dist/lib.cjs/adapters/coinbase-adapter/coinbaseAdapter.js +156 -0
- package/dist/lib.cjs/adapters/default-evm-adapter/index.js +40 -0
- package/dist/lib.cjs/adapters/default-evm-adapter/injectedAdapters.js +42 -0
- package/dist/lib.cjs/adapters/default-evm-adapter/injectedEvmAdapter.js +160 -0
- package/dist/lib.cjs/adapters/default-solana-adapter/index.js +40 -0
- package/dist/lib.cjs/adapters/default-solana-adapter/injectedAdapters.js +53 -0
- package/dist/lib.cjs/adapters/default-solana-adapter/utils.js +16 -0
- package/dist/lib.cjs/adapters/default-solana-adapter/walletStandardAdapter.js +138 -0
- package/dist/lib.cjs/adapters/default-solana-adapter/walletStandardHandler.js +77 -0
- package/dist/lib.cjs/adapters/wallet-connect-v2-adapter/WalletConnectV2Provider.js +278 -0
- package/dist/lib.cjs/adapters/wallet-connect-v2-adapter/config.js +183 -0
- package/dist/lib.cjs/adapters/wallet-connect-v2-adapter/walletConnectV2Utils.js +165 -0
- package/dist/lib.cjs/adapters/wallet-connect-v2-adapter/walletConnectV2adapter.js +376 -0
- package/dist/lib.cjs/base/adapter/baseAdapter.js +117 -0
- package/dist/lib.cjs/base/adapter/constants.js +24 -0
- package/dist/lib.cjs/base/adapter/utils.js +66 -0
- package/dist/lib.cjs/base/chain/IChainInterface.js +22 -0
- package/dist/lib.cjs/base/chain/config.js +281 -0
- package/dist/lib.cjs/base/composables/index.js +5 -0
- package/dist/lib.cjs/base/errors/index.js +244 -0
- package/dist/lib.cjs/base/loglevel.js +7 -0
- package/dist/lib.cjs/base/plugin/IPlugin.js +31 -0
- package/dist/lib.cjs/base/plugin/errors.js +107 -0
- package/dist/lib.cjs/base/provider/IProvider.js +8 -0
- package/dist/lib.cjs/base/utils.js +56 -0
- package/dist/lib.cjs/base/wallet/index.js +31 -0
- package/dist/lib.cjs/index.js +200 -0
- package/dist/lib.cjs/noModal.js +98 -90
- package/dist/lib.cjs/plugins/nft-checkout-plugin/embed.js +134 -0
- package/dist/lib.cjs/plugins/nft-checkout-plugin/enums.js +24 -0
- package/dist/lib.cjs/plugins/nft-checkout-plugin/plugin.js +71 -0
- package/dist/lib.cjs/plugins/nft-checkout-plugin/utils.js +18 -0
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +285 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +164 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/smartAccounts/BiconomySmartAccount.js +29 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/smartAccounts/KernelSmartAccount.js +22 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/smartAccounts/NexusSmartAccount.js +30 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/smartAccounts/SafeSmartAccount.js +30 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/smartAccounts/TrustSmartAccount.js +29 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/smartAccounts/constants.js +11 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +134 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +174 -0
- package/dist/lib.cjs/providers/base-provider/CommonJRPCProvider.js +79 -0
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +127 -0
- package/dist/lib.cjs/providers/base-provider/commonPrivateKeyProvider.js +89 -0
- package/dist/lib.cjs/providers/base-provider/jrpcClient.js +41 -0
- package/dist/lib.cjs/providers/base-provider/utils.js +12 -0
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +199 -0
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +165 -0
- package/dist/lib.cjs/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.js +22 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/converter.js +89 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/EthereumPrivateKeyProvider.js +185 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.js +27 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +380 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.js +10 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.js +94 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/ethPrivatekeyUtils.js +106 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/utils.js +29 -0
- package/dist/lib.cjs/providers/ethereum-provider/rpc/ethRpcMiddlewares.js +75 -0
- package/dist/lib.cjs/providers/ethereum-provider/rpc/jrpcClient.js +41 -0
- package/dist/lib.cjs/providers/ethereum-provider/rpc/walletMidddleware.js +179 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +51 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/providerHandlers.js +47 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/injectedProviderProxy.js +12 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/torus/providerHandlers.js +75 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/torus/torusInjectedProvider.js +109 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +12 -0
- package/dist/lib.cjs/providers/solana-provider/providers/privateKeyProvider/solanaPrivateKeyProvider.js +180 -0
- package/dist/lib.cjs/providers/solana-provider/providers/privateKeyProvider/solanaPrivateKeyUtils.js +103 -0
- package/dist/lib.cjs/providers/solana-provider/rpc/JrpcClient.js +47 -0
- package/dist/lib.cjs/providers/solana-provider/rpc/solanaRpcMiddlewares.js +97 -0
- package/dist/lib.cjs/providers/solana-provider/solanaWallet.js +62 -0
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +158 -0
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.js +89 -0
- package/dist/lib.cjs/providers/xrpl-provider/rpc/JrpcClient.js +48 -0
- package/dist/lib.cjs/providers/xrpl-provider/rpc/xrplRpcMiddlewares.js +73 -0
- package/dist/lib.cjs/react/index.js +16 -0
- package/dist/lib.cjs/react/no-modal/Web3AuthInnerContext.js +216 -0
- package/dist/lib.cjs/react/no-modal/Web3AuthProvider.js +15 -0
- package/dist/lib.cjs/react/no-modal/hooks/useWeb3Auth.js +15 -0
- package/dist/lib.cjs/react/wallet-services-plugin/WalletServicesContext.js +86 -0
- package/dist/lib.cjs/react/wallet-services-plugin/WalletServicesProvider.js +16 -0
- package/dist/lib.cjs/react/wallet-services-plugin/hooks/useWalletServicesPlugin.js +15 -0
- package/dist/lib.cjs/vue/index.js +15 -0
- package/dist/lib.cjs/vue/no-modal/Web3AuthProvider.js +222 -0
- package/dist/lib.cjs/vue/no-modal/composables/useWeb3Auth.js +13 -0
- package/dist/lib.cjs/vue/wallet-services-plugin/WalletServicesProvider.js +86 -0
- package/dist/lib.cjs/vue/wallet-services-plugin/composables/useWalletServicesPlugin.js +13 -0
- package/dist/lib.cjs/vue/wallet-services-plugin/context.js +5 -0
- package/dist/lib.esm/adapters/auth-adapter/authAdapter.js +260 -0
- package/dist/lib.esm/adapters/auth-adapter/config.js +15 -0
- package/dist/lib.esm/adapters/base-evm-adapter/baseEvmAdapter.js +70 -0
- package/dist/lib.esm/adapters/base-solana-adapter/baseSolanaAdapter.js +74 -0
- package/dist/lib.esm/adapters/coinbase-adapter/coinbaseAdapter.js +154 -0
- package/dist/lib.esm/adapters/default-evm-adapter/index.js +37 -0
- package/dist/lib.esm/adapters/default-evm-adapter/injectedAdapters.js +40 -0
- package/dist/lib.esm/adapters/default-evm-adapter/injectedEvmAdapter.js +158 -0
- package/dist/lib.esm/adapters/default-solana-adapter/index.js +37 -0
- package/dist/lib.esm/adapters/default-solana-adapter/injectedAdapters.js +51 -0
- package/dist/lib.esm/adapters/default-solana-adapter/utils.js +14 -0
- package/dist/lib.esm/adapters/default-solana-adapter/walletStandardAdapter.js +136 -0
- package/dist/lib.esm/adapters/default-solana-adapter/walletStandardHandler.js +75 -0
- package/dist/lib.esm/adapters/wallet-connect-v2-adapter/WalletConnectV2Provider.js +276 -0
- package/dist/lib.esm/adapters/wallet-connect-v2-adapter/config.js +172 -0
- package/dist/lib.esm/adapters/wallet-connect-v2-adapter/walletConnectV2Utils.js +158 -0
- package/dist/lib.esm/adapters/wallet-connect-v2-adapter/walletConnectV2adapter.js +374 -0
- package/dist/lib.esm/base/adapter/baseAdapter.js +115 -0
- package/dist/lib.esm/base/adapter/constants.js +20 -0
- package/dist/lib.esm/base/adapter/utils.js +60 -0
- package/dist/lib.esm/base/chain/IChainInterface.js +19 -0
- package/dist/lib.esm/base/chain/config.js +276 -0
- package/dist/lib.esm/base/composables/index.js +3 -0
- package/dist/lib.esm/base/errors/index.js +237 -0
- package/dist/lib.esm/base/loglevel.js +5 -0
- package/dist/lib.esm/base/plugin/IPlugin.js +24 -0
- package/dist/lib.esm/base/plugin/errors.js +104 -0
- package/dist/lib.esm/base/provider/IProvider.js +6 -0
- package/dist/lib.esm/base/utils.js +46 -0
- package/dist/lib.esm/base/wallet/index.js +25 -0
- package/dist/lib.esm/index.js +58 -0
- package/dist/lib.esm/noModal.js +12 -4
- package/dist/lib.esm/plugins/nft-checkout-plugin/embed.js +132 -0
- package/dist/lib.esm/plugins/nft-checkout-plugin/enums.js +20 -0
- package/dist/lib.esm/plugins/nft-checkout-plugin/plugin.js +69 -0
- package/dist/lib.esm/plugins/nft-checkout-plugin/utils.js +15 -0
- package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +276 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +162 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/smartAccounts/BiconomySmartAccount.js +27 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/smartAccounts/KernelSmartAccount.js +20 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/smartAccounts/NexusSmartAccount.js +28 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/smartAccounts/SafeSmartAccount.js +28 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/smartAccounts/TrustSmartAccount.js +27 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/smartAccounts/constants.js +9 -0
- package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +132 -0
- package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +171 -0
- package/dist/lib.esm/providers/base-provider/CommonJRPCProvider.js +77 -0
- package/dist/lib.esm/providers/base-provider/baseProvider.js +125 -0
- package/dist/lib.esm/providers/base-provider/commonPrivateKeyProvider.js +87 -0
- package/dist/lib.esm/providers/base-provider/jrpcClient.js +37 -0
- package/dist/lib.esm/providers/base-provider/utils.js +6 -0
- package/dist/lib.esm/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +197 -0
- package/dist/lib.esm/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +163 -0
- package/dist/lib.esm/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.js +20 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/converter.js +85 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/EthereumPrivateKeyProvider.js +183 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.js +21 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +378 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.js +8 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.js +88 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/ethPrivatekeyUtils.js +104 -0
- package/dist/lib.esm/providers/ethereum-provider/providers/utils.js +24 -0
- package/dist/lib.esm/providers/ethereum-provider/rpc/ethRpcMiddlewares.js +71 -0
- package/dist/lib.esm/providers/ethereum-provider/rpc/jrpcClient.js +37 -0
- package/dist/lib.esm/providers/ethereum-provider/rpc/walletMidddleware.js +177 -0
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +49 -0
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/base/providerHandlers.js +45 -0
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/injectedProviderProxy.js +10 -0
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/torus/providerHandlers.js +73 -0
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/torus/torusInjectedProvider.js +107 -0
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +10 -0
- package/dist/lib.esm/providers/solana-provider/providers/privateKeyProvider/solanaPrivateKeyProvider.js +178 -0
- package/dist/lib.esm/providers/solana-provider/providers/privateKeyProvider/solanaPrivateKeyUtils.js +101 -0
- package/dist/lib.esm/providers/solana-provider/rpc/JrpcClient.js +42 -0
- package/dist/lib.esm/providers/solana-provider/rpc/solanaRpcMiddlewares.js +89 -0
- package/dist/lib.esm/providers/solana-provider/solanaWallet.js +60 -0
- package/dist/lib.esm/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +156 -0
- package/dist/lib.esm/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.js +87 -0
- package/dist/lib.esm/providers/xrpl-provider/rpc/JrpcClient.js +43 -0
- package/dist/lib.esm/providers/xrpl-provider/rpc/xrplRpcMiddlewares.js +67 -0
- package/dist/lib.esm/react/index.js +5 -0
- package/dist/lib.esm/react/no-modal/Web3AuthInnerContext.js +213 -0
- package/dist/lib.esm/react/no-modal/Web3AuthProvider.js +13 -0
- package/dist/lib.esm/react/no-modal/hooks/useWeb3Auth.js +13 -0
- package/dist/lib.esm/react/wallet-services-plugin/WalletServicesContext.js +83 -0
- package/dist/lib.esm/react/wallet-services-plugin/WalletServicesProvider.js +14 -0
- package/dist/lib.esm/react/wallet-services-plugin/hooks/useWalletServicesPlugin.js +13 -0
- package/dist/lib.esm/vue/index.js +5 -0
- package/dist/lib.esm/vue/no-modal/Web3AuthProvider.js +220 -0
- package/dist/lib.esm/vue/no-modal/composables/useWeb3Auth.js +11 -0
- package/dist/lib.esm/vue/wallet-services-plugin/WalletServicesProvider.js +84 -0
- package/dist/lib.esm/vue/wallet-services-plugin/composables/useWalletServicesPlugin.js +11 -0
- package/dist/lib.esm/vue/wallet-services-plugin/context.js +3 -0
- package/dist/noModal.cjs.js +26314 -364
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +54 -0
- package/dist/types/adapters/auth-adapter/authAdapter.d.ts +42 -0
- package/dist/types/adapters/auth-adapter/config.d.ts +2 -0
- package/dist/types/adapters/auth-adapter/index.d.ts +3 -0
- package/dist/types/adapters/auth-adapter/interface.d.ts +11 -0
- package/dist/types/adapters/base-evm-adapter/baseEvmAdapter.d.ts +7 -0
- package/dist/types/adapters/base-evm-adapter/index.d.ts +1 -0
- package/dist/types/adapters/base-solana-adapter/baseSolanaAdapter.d.ts +7 -0
- package/dist/types/adapters/base-solana-adapter/index.d.ts +1 -0
- package/dist/types/adapters/coinbase-adapter/coinbaseAdapter.d.ts +33 -0
- package/dist/types/adapters/coinbase-adapter/index.d.ts +1 -0
- package/dist/types/adapters/default-evm-adapter/index.d.ts +6 -0
- package/dist/types/adapters/default-evm-adapter/injectedAdapters.d.ts +4 -0
- package/dist/types/adapters/default-evm-adapter/injectedEvmAdapter.d.ts +30 -0
- package/dist/types/adapters/default-solana-adapter/index.d.ts +6 -0
- package/dist/types/adapters/default-solana-adapter/injectedAdapters.d.ts +4 -0
- package/dist/types/adapters/default-solana-adapter/utils.d.ts +3 -0
- package/dist/types/adapters/default-solana-adapter/walletStandardAdapter.d.ts +31 -0
- package/dist/types/adapters/default-solana-adapter/walletStandardHandler.d.ts +27 -0
- package/dist/types/adapters/index.d.ts +7 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/WalletConnectV2Provider.d.ts +36 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/config.d.ts +35 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/index.d.ts +4 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/interface.d.ts +18 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/utils.d.ts +3 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/walletConnectV2Utils.d.ts +23 -0
- package/dist/types/adapters/wallet-connect-v2-adapter/walletConnectV2adapter.d.ts +42 -0
- package/dist/types/base/adapter/baseAdapter.d.ts +44 -0
- package/dist/types/base/adapter/constants.d.ts +22 -0
- package/dist/types/base/adapter/index.d.ts +4 -0
- package/dist/types/base/adapter/interfaces.d.ts +143 -0
- package/dist/types/base/adapter/utils.d.ts +5 -0
- package/dist/types/base/chain/IChainInterface.d.ts +59 -0
- package/dist/types/base/chain/config.d.ts +5 -0
- package/dist/types/base/composables/index.d.ts +1 -0
- package/dist/types/base/core/IWeb3Auth.d.ts +101 -0
- package/dist/types/base/errors/index.d.ts +69 -0
- package/dist/types/base/hooks/index.d.ts +37 -0
- package/dist/types/base/index.d.ts +13 -0
- package/dist/types/base/interfaces.d.ts +44 -0
- package/dist/types/base/loglevel.d.ts +2 -0
- package/dist/types/base/plugin/IPlugin.d.ts +53 -0
- package/dist/types/base/plugin/errors.d.ts +28 -0
- package/dist/types/base/plugin/index.d.ts +2 -0
- package/dist/types/base/provider/IProvider.d.ts +16 -0
- package/dist/types/base/utils.d.ts +9 -0
- package/dist/types/base/wallet/index.d.ts +33 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/noModal.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +2 -0
- package/dist/types/plugins/nft-checkout-plugin/embed.d.ts +24 -0
- package/dist/types/plugins/nft-checkout-plugin/enums.d.ts +14 -0
- package/dist/types/plugins/nft-checkout-plugin/index.d.ts +2 -0
- package/dist/types/plugins/nft-checkout-plugin/plugin.d.ts +23 -0
- package/dist/types/plugins/nft-checkout-plugin/utils.d.ts +3 -0
- package/dist/types/plugins/wallet-services-plugin/index.d.ts +1 -0
- package/dist/types/plugins/wallet-services-plugin/plugin.d.ts +51 -0
- package/dist/types/providers/account-abstraction-provider/index.d.ts +1 -0
- package/dist/types/providers/account-abstraction-provider/providers/AccountAbstractionProvider.d.ts +46 -0
- package/dist/types/providers/account-abstraction-provider/providers/index.d.ts +3 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/BiconomySmartAccount.d.ts +14 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/KernelSmartAccount.d.ts +13 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/LightSmartAccount.d.ts +14 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/NexusSmartAccount.d.ts +14 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/SafeSmartAccount.d.ts +13 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/SimpleSmartAccount.d.ts +13 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/TrustSmartAccount.d.ts +13 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/constants.d.ts +9 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/index.d.ts +6 -0
- package/dist/types/providers/account-abstraction-provider/providers/smartAccounts/types.d.ts +22 -0
- package/dist/types/providers/account-abstraction-provider/providers/types.d.ts +17 -0
- package/dist/types/providers/account-abstraction-provider/providers/utils.d.ts +10 -0
- package/dist/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +8 -0
- package/dist/types/providers/account-abstraction-provider/rpc/index.d.ts +1 -0
- package/dist/types/providers/base-provider/CommonJRPCProvider.d.ts +20 -0
- package/dist/types/providers/base-provider/baseProvider.d.ts +39 -0
- package/dist/types/providers/base-provider/commonPrivateKeyProvider.d.ts +31 -0
- package/dist/types/providers/base-provider/index.d.ts +5 -0
- package/dist/types/providers/base-provider/interfaces.d.ts +3 -0
- package/dist/types/providers/base-provider/jrpcClient.d.ts +8 -0
- package/dist/types/providers/base-provider/utils.d.ts +2 -0
- package/dist/types/providers/ethereum-mpc-provider/index.d.ts +1 -0
- package/dist/types/providers/ethereum-mpc-provider/providers/index.d.ts +1 -0
- package/dist/types/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.d.ts +65 -0
- package/dist/types/providers/ethereum-mpc-provider/providers/signingProviders/index.d.ts +1 -0
- package/dist/types/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.d.ts +12 -0
- package/dist/types/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.d.ts +3 -0
- package/dist/types/providers/ethereum-mpc-provider/rpc/interfaces.d.ts +15 -0
- package/dist/types/providers/ethereum-provider/index.d.ts +2 -0
- package/dist/types/providers/ethereum-provider/providers/converter.d.ts +15 -0
- package/dist/types/providers/ethereum-provider/providers/index.d.ts +1 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/EthereumPrivateKeyProvider.d.ts +30 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.d.ts +16 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.d.ts +28 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/index.d.ts +4 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.d.ts +46 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.d.ts +12 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/ethPrivatekeyUtils.d.ts +9 -0
- package/dist/types/providers/ethereum-provider/providers/privateKeyProviders/index.d.ts +2 -0
- package/dist/types/providers/ethereum-provider/providers/utils.d.ts +5 -0
- package/dist/types/providers/ethereum-provider/rpc/ethRpcMiddlewares.d.ts +5 -0
- package/dist/types/providers/ethereum-provider/rpc/index.d.ts +4 -0
- package/dist/types/providers/ethereum-provider/rpc/interfaces.d.ts +65 -0
- package/dist/types/providers/ethereum-provider/rpc/jrpcClient.d.ts +8 -0
- package/dist/types/providers/ethereum-provider/rpc/walletMidddleware.d.ts +3 -0
- package/dist/types/providers/index.d.ts +6 -0
- package/dist/types/providers/solana-provider/index.d.ts +4 -0
- package/dist/types/providers/solana-provider/interface.d.ts +39 -0
- package/dist/types/providers/solana-provider/providers/index.d.ts +2 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.d.ts +16 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/base/providerHandlers.d.ts +3 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/index.d.ts +3 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/injectedProviderProxy.d.ts +3 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/interface.d.ts +5 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/torus/providerHandlers.d.ts +3 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/torus/torusInjectedProvider.d.ts +18 -0
- package/dist/types/providers/solana-provider/providers/injectedProviders/walletStandardProvider.d.ts +6 -0
- package/dist/types/providers/solana-provider/providers/privateKeyProvider/index.d.ts +1 -0
- package/dist/types/providers/solana-provider/providers/privateKeyProvider/solanaPrivateKeyProvider.d.ts +31 -0
- package/dist/types/providers/solana-provider/providers/privateKeyProvider/solanaPrivateKeyUtils.d.ts +7 -0
- package/dist/types/providers/solana-provider/rpc/JrpcClient.d.ts +9 -0
- package/dist/types/providers/solana-provider/rpc/index.d.ts +3 -0
- package/dist/types/providers/solana-provider/rpc/interfaces.d.ts +42 -0
- package/dist/types/providers/solana-provider/rpc/solanaRpcMiddlewares.d.ts +20 -0
- package/dist/types/providers/solana-provider/solanaWallet.d.ts +14 -0
- package/dist/types/providers/xrpl-provider/index.d.ts +1 -0
- package/dist/types/providers/xrpl-provider/providers/index.d.ts +1 -0
- package/dist/types/providers/xrpl-provider/providers/privateKeyProviders/constants.d.ts +5 -0
- package/dist/types/providers/xrpl-provider/providers/privateKeyProviders/index.d.ts +3 -0
- package/dist/types/providers/xrpl-provider/providers/privateKeyProviders/interface.d.ts +2 -0
- package/dist/types/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.d.ts +26 -0
- package/dist/types/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.d.ts +7 -0
- package/dist/types/providers/xrpl-provider/rpc/JrpcClient.d.ts +9 -0
- package/dist/types/providers/xrpl-provider/rpc/xrplRpcMiddlewares.d.ts +52 -0
- package/dist/types/react/index.d.ts +2 -0
- package/dist/types/react/no-modal/Web3AuthInnerContext.d.ts +4 -0
- package/dist/types/react/no-modal/Web3AuthProvider.d.ts +3 -0
- package/dist/types/react/no-modal/hooks/index.d.ts +1 -0
- package/dist/types/react/no-modal/hooks/useWeb3Auth.d.ts +2 -0
- package/dist/types/react/no-modal/index.d.ts +3 -0
- package/dist/types/react/no-modal/interfaces.d.ts +15 -0
- package/dist/types/react/wallet-services-plugin/WalletServicesContext.d.ts +7 -0
- package/dist/types/react/wallet-services-plugin/WalletServicesProvider.d.ts +7 -0
- package/dist/types/react/wallet-services-plugin/hooks/index.d.ts +1 -0
- package/dist/types/react/wallet-services-plugin/hooks/useWalletServicesPlugin.d.ts +2 -0
- package/dist/types/react/wallet-services-plugin/index.d.ts +4 -0
- package/dist/types/react/wallet-services-plugin/interfaces.d.ts +5 -0
- package/dist/types/vue/index.d.ts +2 -0
- package/dist/types/vue/no-modal/Web3AuthProvider.d.ts +13 -0
- package/dist/types/vue/no-modal/composables/index.d.ts +1 -0
- package/dist/types/vue/no-modal/composables/useWeb3Auth.d.ts +2 -0
- package/dist/types/vue/no-modal/index.d.ts +3 -0
- package/dist/types/vue/no-modal/interfaces.d.ts +42 -0
- package/dist/types/vue/wallet-services-plugin/WalletServicesProvider.d.ts +1 -0
- package/dist/types/vue/wallet-services-plugin/composables/index.d.ts +1 -0
- package/dist/types/vue/wallet-services-plugin/composables/useWalletServicesPlugin.d.ts +2 -0
- package/dist/types/vue/wallet-services-plugin/context.d.ts +3 -0
- package/dist/types/vue/wallet-services-plugin/index.d.ts +4 -0
- package/dist/types/vue/wallet-services-plugin/interfaces.d.ts +13 -0
- package/package.json +76 -15
- package/README.md +0 -82
- package/dist/noModal.esm.js +0 -359
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
+
import { addHexPrefix, stripHexPrefix } from '@ethereumjs/util';
|
|
4
|
+
import { BigNumber } from 'bignumber.js';
|
|
5
|
+
import { log } from '../../../../../base/loglevel.js';
|
|
6
|
+
import { hexWEIToDecGWEI, decGWEIToHexWEI } from '../../converter.js';
|
|
7
|
+
import { bnLessThan, hexToBn, BnMultiplyByFraction, bnToHex } from '../../utils.js';
|
|
8
|
+
import { TRANSACTION_ENVELOPE_TYPES, EIP1559APIEndpoint, GAS_ESTIMATE_TYPES, LegacyGasAPIEndpoint, TRANSACTION_TYPES } from './constants.js';
|
|
9
|
+
import { fetchEip1159GasEstimates, fetchLegacyGasPriceEstimates } from './utils.js';
|
|
10
|
+
|
|
11
|
+
class TransactionFormatter {
|
|
12
|
+
constructor({
|
|
13
|
+
getProviderEngineProxy
|
|
14
|
+
}) {
|
|
15
|
+
// https://0x.org/docs/introduction/0x-cheat-sheet#swap-api-endpoints
|
|
16
|
+
_defineProperty(this, "API_SUPPORTED_CHAINIDS", new Set(["0x1", "0x5", "0x13881", "0xa4b1", "0xa86a", "0x2105", "0x38", "0xfa", "0xa", "0x89"]));
|
|
17
|
+
_defineProperty(this, "chainConfig", null);
|
|
18
|
+
_defineProperty(this, "getProviderEngineProxy", void 0);
|
|
19
|
+
_defineProperty(this, "isEIP1559Compatible", false);
|
|
20
|
+
this.getProviderEngineProxy = getProviderEngineProxy;
|
|
21
|
+
}
|
|
22
|
+
get providerProxy() {
|
|
23
|
+
return this.getProviderEngineProxy();
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
this.chainConfig = await this.providerProxy.request({
|
|
27
|
+
method: "eth_provider_config"
|
|
28
|
+
});
|
|
29
|
+
this.isEIP1559Compatible = await this.getEIP1559Compatibility();
|
|
30
|
+
}
|
|
31
|
+
async formatTransaction(txParams) {
|
|
32
|
+
if (!this.chainConfig) throw new Error("Chain config not initialized");
|
|
33
|
+
const clonedTxParams = _objectSpread({}, txParams);
|
|
34
|
+
if (clonedTxParams.nonce === undefined) clonedTxParams.nonce = await this.providerProxy.request({
|
|
35
|
+
method: "eth_getTransactionCount",
|
|
36
|
+
params: [txParams.from, "latest"]
|
|
37
|
+
});
|
|
38
|
+
if (!this.isEIP1559Compatible && clonedTxParams.gasPrice) {
|
|
39
|
+
if (clonedTxParams.maxFeePerGas) delete clonedTxParams.maxFeePerGas;
|
|
40
|
+
if (clonedTxParams.maxPriorityFeePerGas) delete clonedTxParams.maxPriorityFeePerGas;
|
|
41
|
+
// if user provides gas Limit, we should use it instead
|
|
42
|
+
// if gas is not provided explicitly, estimate it.
|
|
43
|
+
if (!clonedTxParams.gasLimit) {
|
|
44
|
+
if (!clonedTxParams.gas) {
|
|
45
|
+
const defaultGasLimit = await this.getDefaultGasLimit(clonedTxParams);
|
|
46
|
+
if (defaultGasLimit) {
|
|
47
|
+
clonedTxParams.gasLimit = defaultGasLimit;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
clonedTxParams.gasLimit = addHexPrefix(clonedTxParams.gas);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return clonedTxParams;
|
|
54
|
+
}
|
|
55
|
+
if (!clonedTxParams.gasLimit) {
|
|
56
|
+
if (!clonedTxParams.gas) {
|
|
57
|
+
const defaultGasLimit = await this.getDefaultGasLimit(clonedTxParams);
|
|
58
|
+
if (defaultGasLimit) {
|
|
59
|
+
clonedTxParams.gasLimit = defaultGasLimit;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
clonedTxParams.gasLimit = addHexPrefix(clonedTxParams.gas);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const {
|
|
66
|
+
gasPrice: defaultGasPrice,
|
|
67
|
+
maxFeePerGas: defaultMaxFeePerGas,
|
|
68
|
+
maxPriorityFeePerGas: defaultMaxPriorityFeePerGas
|
|
69
|
+
} = await this.getDefaultGasFees(clonedTxParams);
|
|
70
|
+
if (this.isEIP1559Compatible) {
|
|
71
|
+
// If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas
|
|
72
|
+
// then we set maxFeePerGas and maxPriorityFeePerGas to the suggested gasPrice.
|
|
73
|
+
if (clonedTxParams.gasPrice && !clonedTxParams.maxFeePerGas && !clonedTxParams.maxPriorityFeePerGas) {
|
|
74
|
+
clonedTxParams.maxFeePerGas = clonedTxParams.gasPrice;
|
|
75
|
+
clonedTxParams.maxPriorityFeePerGas = bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? stripHexPrefix(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof clonedTxParams.gasPrice === "string" ? stripHexPrefix(clonedTxParams.gasPrice) : clonedTxParams.gasPrice.toString()) ? addHexPrefix(defaultMaxPriorityFeePerGas) : addHexPrefix(clonedTxParams.gasPrice.toString());
|
|
76
|
+
} else {
|
|
77
|
+
if (defaultMaxFeePerGas && !clonedTxParams.maxFeePerGas) {
|
|
78
|
+
// If the dapp has not set the gasPrice or the maxFeePerGas, then we set maxFeePerGas
|
|
79
|
+
// with the one returned by the gasFeeController, if that is available.
|
|
80
|
+
clonedTxParams.maxFeePerGas = addHexPrefix(defaultMaxFeePerGas);
|
|
81
|
+
}
|
|
82
|
+
if (defaultMaxPriorityFeePerGas && !clonedTxParams.maxPriorityFeePerGas) {
|
|
83
|
+
// If the dapp has not set the gasPrice or the maxPriorityFeePerGas, then we set maxPriorityFeePerGas
|
|
84
|
+
// with the one returned by the gasFeeController, if that is available.
|
|
85
|
+
clonedTxParams.maxPriorityFeePerGas = addHexPrefix(defaultMaxPriorityFeePerGas);
|
|
86
|
+
}
|
|
87
|
+
if (defaultGasPrice && !clonedTxParams.maxFeePerGas) {
|
|
88
|
+
// If the dapp has not set the gasPrice or the maxFeePerGas, and no maxFeePerGas is available
|
|
89
|
+
// then we set maxFeePerGas to the defaultGasPrice, assuming it is
|
|
90
|
+
// available.
|
|
91
|
+
clonedTxParams.maxFeePerGas = addHexPrefix(defaultGasPrice);
|
|
92
|
+
}
|
|
93
|
+
if (clonedTxParams.maxFeePerGas && !clonedTxParams.maxPriorityFeePerGas) {
|
|
94
|
+
// If the dapp has not set the gasPrice or the maxPriorityFeePerGas, and no maxPriorityFeePerGas is
|
|
95
|
+
// available then we set maxPriorityFeePerGas to
|
|
96
|
+
// clonedTxParams.maxFeePerGas, which will either be the gasPrice from the controller, the maxFeePerGas
|
|
97
|
+
// set by the dapp, or the maxFeePerGas from the controller.
|
|
98
|
+
clonedTxParams.maxPriorityFeePerGas = clonedTxParams.maxFeePerGas;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// We remove the gasPrice param entirely when on an eip1559 compatible network
|
|
103
|
+
|
|
104
|
+
delete clonedTxParams.gasPrice;
|
|
105
|
+
} else {
|
|
106
|
+
// We ensure that maxFeePerGas and maxPriorityFeePerGas are not in the transaction params
|
|
107
|
+
// when not on a EIP1559 compatible network
|
|
108
|
+
|
|
109
|
+
delete clonedTxParams.maxPriorityFeePerGas;
|
|
110
|
+
delete clonedTxParams.maxFeePerGas;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// If we have gotten to this point, and none of gasPrice, maxPriorityFeePerGas or maxFeePerGas are
|
|
114
|
+
// set on txParams, it means that either we are on a non-EIP1559 network and the dapp didn't suggest
|
|
115
|
+
// a gas price, or we are on an EIP1559 network, and none of gasPrice, maxPriorityFeePerGas or maxFeePerGas
|
|
116
|
+
// were available from either the dapp or the network.
|
|
117
|
+
if (defaultGasPrice && !clonedTxParams.gasPrice && !clonedTxParams.maxPriorityFeePerGas && !clonedTxParams.maxFeePerGas) {
|
|
118
|
+
clonedTxParams.gasPrice = defaultGasPrice;
|
|
119
|
+
}
|
|
120
|
+
clonedTxParams.type = Number.parseInt(this.isEIP1559Compatible ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY, 16);
|
|
121
|
+
clonedTxParams.chainId = this.chainConfig.chainId;
|
|
122
|
+
return clonedTxParams;
|
|
123
|
+
}
|
|
124
|
+
async fetchEthGasPriceEstimate() {
|
|
125
|
+
const gasPrice = await this.providerProxy.request({
|
|
126
|
+
method: "eth_gasPrice",
|
|
127
|
+
params: []
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
gasPrice: hexWEIToDecGWEI(gasPrice).toString()
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async fetchGasEstimatesViaEthFeeHistory() {
|
|
134
|
+
const noOfBlocks = 10;
|
|
135
|
+
const newestBlock = "latest";
|
|
136
|
+
// get the 10, 50 and 95th percentile of the tip fees from the last 10 blocks
|
|
137
|
+
const percentileValues = [10, 50, 95];
|
|
138
|
+
const feeHistory = await this.providerProxy.request({
|
|
139
|
+
method: "eth_feeHistory",
|
|
140
|
+
params: [noOfBlocks, newestBlock, percentileValues]
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// this is in hex wei
|
|
144
|
+
const finalBaseFeePerGas = feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 1];
|
|
145
|
+
// this is in hex wei
|
|
146
|
+
const priorityFeeCalcs = feeHistory.reward.reduce((acc, curr) => {
|
|
147
|
+
return {
|
|
148
|
+
slow: acc.slow.plus(new BigNumber(curr[0], 16)),
|
|
149
|
+
average: acc.average.plus(new BigNumber(curr[1], 16)),
|
|
150
|
+
fast: acc.fast.plus(new BigNumber(curr[2], 16))
|
|
151
|
+
};
|
|
152
|
+
}, {
|
|
153
|
+
slow: new BigNumber(0),
|
|
154
|
+
average: new BigNumber(0),
|
|
155
|
+
fast: new BigNumber(0)
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
estimatedBaseFee: hexWEIToDecGWEI(finalBaseFeePerGas).toString(),
|
|
159
|
+
high: {
|
|
160
|
+
maxWaitTimeEstimate: 30000,
|
|
161
|
+
minWaitTimeEstimate: 15000,
|
|
162
|
+
suggestedMaxFeePerGas: hexWEIToDecGWEI(priorityFeeCalcs.fast.plus(finalBaseFeePerGas).toString(16)).toString(),
|
|
163
|
+
suggestedMaxPriorityFeePerGas: hexWEIToDecGWEI(priorityFeeCalcs.fast.toString(16)).toString()
|
|
164
|
+
},
|
|
165
|
+
medium: {
|
|
166
|
+
maxWaitTimeEstimate: 45000,
|
|
167
|
+
minWaitTimeEstimate: 15000,
|
|
168
|
+
suggestedMaxFeePerGas: hexWEIToDecGWEI(priorityFeeCalcs.average.plus(finalBaseFeePerGas).toString(16)).toString(),
|
|
169
|
+
suggestedMaxPriorityFeePerGas: hexWEIToDecGWEI(priorityFeeCalcs.average.toString(16)).toString()
|
|
170
|
+
},
|
|
171
|
+
low: {
|
|
172
|
+
maxWaitTimeEstimate: 60000,
|
|
173
|
+
minWaitTimeEstimate: 15000,
|
|
174
|
+
suggestedMaxFeePerGas: hexWEIToDecGWEI(priorityFeeCalcs.slow.plus(finalBaseFeePerGas).toString(16)).toString(),
|
|
175
|
+
suggestedMaxPriorityFeePerGas: hexWEIToDecGWEI(priorityFeeCalcs.slow.toString(16)).toString()
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
async getEIP1559Compatibility() {
|
|
180
|
+
const latestBlock = await this.providerProxy.request({
|
|
181
|
+
method: "eth_getBlockByNumber",
|
|
182
|
+
params: ["latest", false]
|
|
183
|
+
});
|
|
184
|
+
const supportsEIP1559 = latestBlock && latestBlock.baseFeePerGas !== undefined;
|
|
185
|
+
return !!supportsEIP1559;
|
|
186
|
+
}
|
|
187
|
+
async fetchGasFeeEstimateData() {
|
|
188
|
+
if (!this.chainConfig) throw new Error("Chain config not initialized");
|
|
189
|
+
const isLegacyGasAPICompatible = this.chainConfig.chainId === "0x1";
|
|
190
|
+
const chainId = Number.parseInt(this.chainConfig.chainId, 16);
|
|
191
|
+
let gasData;
|
|
192
|
+
try {
|
|
193
|
+
if (this.isEIP1559Compatible) {
|
|
194
|
+
let estimates;
|
|
195
|
+
try {
|
|
196
|
+
if (this.API_SUPPORTED_CHAINIDS.has(this.chainConfig.chainId)) {
|
|
197
|
+
estimates = await fetchEip1159GasEstimates(EIP1559APIEndpoint.replace("<chain_id>", `${chainId}`));
|
|
198
|
+
} else {
|
|
199
|
+
throw new Error("Chain id not supported by api");
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
estimates = await this.fetchGasEstimatesViaEthFeeHistory();
|
|
203
|
+
}
|
|
204
|
+
gasData = {
|
|
205
|
+
gasFeeEstimates: estimates,
|
|
206
|
+
gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET
|
|
207
|
+
};
|
|
208
|
+
} else if (isLegacyGasAPICompatible) {
|
|
209
|
+
const estimates = await fetchLegacyGasPriceEstimates(LegacyGasAPIEndpoint.replace("<chain_id>", `${chainId}`));
|
|
210
|
+
gasData = {
|
|
211
|
+
gasFeeEstimates: estimates,
|
|
212
|
+
gasEstimateType: GAS_ESTIMATE_TYPES.LEGACY
|
|
213
|
+
};
|
|
214
|
+
} else {
|
|
215
|
+
throw new Error("Main gas fee/price estimation failed. Use fallback");
|
|
216
|
+
}
|
|
217
|
+
} catch (e) {
|
|
218
|
+
try {
|
|
219
|
+
const estimates = await this.fetchEthGasPriceEstimate();
|
|
220
|
+
gasData = {
|
|
221
|
+
gasFeeEstimates: estimates,
|
|
222
|
+
gasEstimateType: GAS_ESTIMATE_TYPES.ETH_GASPRICE
|
|
223
|
+
};
|
|
224
|
+
} catch (error) {
|
|
225
|
+
throw new Error(`Gas fee/price estimation failed. Message: ${error.message}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return gasData;
|
|
229
|
+
}
|
|
230
|
+
async getDefaultGasFees(txParams) {
|
|
231
|
+
if (!this.isEIP1559Compatible && txParams.gasPrice || this.isEIP1559Compatible && txParams.maxFeePerGas && txParams.maxPriorityFeePerGas) {
|
|
232
|
+
return {};
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const {
|
|
236
|
+
gasFeeEstimates,
|
|
237
|
+
gasEstimateType
|
|
238
|
+
} = await this.fetchGasFeeEstimateData();
|
|
239
|
+
if (this.isEIP1559Compatible && gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
240
|
+
const {
|
|
241
|
+
medium: {
|
|
242
|
+
suggestedMaxPriorityFeePerGas,
|
|
243
|
+
suggestedMaxFeePerGas
|
|
244
|
+
} = {}
|
|
245
|
+
} = gasFeeEstimates;
|
|
246
|
+
if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
|
|
247
|
+
return {
|
|
248
|
+
maxFeePerGas: addHexPrefix(decGWEIToHexWEI(suggestedMaxFeePerGas)),
|
|
249
|
+
maxPriorityFeePerGas: addHexPrefix(decGWEIToHexWEI(suggestedMaxPriorityFeePerGas))
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
} else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {
|
|
253
|
+
// The LEGACY type includes low, medium and high estimates of
|
|
254
|
+
// gas price values.
|
|
255
|
+
return {
|
|
256
|
+
gasPrice: addHexPrefix(decGWEIToHexWEI(gasFeeEstimates.medium))
|
|
257
|
+
};
|
|
258
|
+
} else if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
|
|
259
|
+
// The ETH_GASPRICE type just includes a single gas price property,
|
|
260
|
+
// which we can assume was retrieved from eth_gasPrice
|
|
261
|
+
return {
|
|
262
|
+
gasPrice: addHexPrefix(decGWEIToHexWEI(gasFeeEstimates.gasPrice))
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
log.error(error);
|
|
267
|
+
}
|
|
268
|
+
const {
|
|
269
|
+
gasPrice
|
|
270
|
+
} = await this.fetchEthGasPriceEstimate();
|
|
271
|
+
return {
|
|
272
|
+
gasPrice: addHexPrefix(decGWEIToHexWEI(gasPrice))
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async estimateTxGas(txMeta) {
|
|
276
|
+
const txParams = _objectSpread({}, txMeta);
|
|
277
|
+
|
|
278
|
+
// `eth_estimateGas` can fail if the user has insufficient balance for the
|
|
279
|
+
// value being sent, or for the gas cost. We don't want to check their
|
|
280
|
+
// balance here, we just want the gas estimate. The gas price is removed
|
|
281
|
+
// to skip those balance checks. We check balance elsewhere. We also delete
|
|
282
|
+
// maxFeePerGas and maxPriorityFeePerGas to support EIP-1559 txs.
|
|
283
|
+
delete txParams.gasPrice;
|
|
284
|
+
delete txParams.maxFeePerGas;
|
|
285
|
+
delete txParams.maxPriorityFeePerGas;
|
|
286
|
+
const gas = await this.providerProxy.request({
|
|
287
|
+
method: "eth_estimateGas",
|
|
288
|
+
params: [txParams]
|
|
289
|
+
});
|
|
290
|
+
return gas;
|
|
291
|
+
}
|
|
292
|
+
async analyzeGasUsage(txMeta) {
|
|
293
|
+
const block = await this.providerProxy.request({
|
|
294
|
+
method: "eth_getBlockByNumber",
|
|
295
|
+
params: ["latest", false]
|
|
296
|
+
});
|
|
297
|
+
// fallback to block gasLimit
|
|
298
|
+
const blockGasLimitBN = hexToBn(block.gasLimit);
|
|
299
|
+
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20);
|
|
300
|
+
let estimatedGasHex = bnToHex(saferGasLimitBN);
|
|
301
|
+
try {
|
|
302
|
+
estimatedGasHex = await this.estimateTxGas(txMeta);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
log.warn(error);
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
blockGasLimit: block.gasLimit,
|
|
308
|
+
estimatedGasHex
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
addGasBuffer(initialGasLimitHex, blockGasLimitHex, multiplier = 1.5) {
|
|
312
|
+
const initialGasLimitBn = hexToBn(initialGasLimitHex);
|
|
313
|
+
const blockGasLimitBn = hexToBn(blockGasLimitHex);
|
|
314
|
+
const upperGasLimitBn = blockGasLimitBn.muln(0.9);
|
|
315
|
+
const bufferedGasLimitBn = initialGasLimitBn.muln(multiplier);
|
|
316
|
+
|
|
317
|
+
// if initialGasLimit is above blockGasLimit, dont modify it
|
|
318
|
+
if (initialGasLimitBn.gt(upperGasLimitBn)) return bnToHex(initialGasLimitBn);
|
|
319
|
+
// if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
|
|
320
|
+
if (bufferedGasLimitBn.lt(upperGasLimitBn)) return bnToHex(bufferedGasLimitBn);
|
|
321
|
+
// otherwise use blockGasLimit
|
|
322
|
+
return bnToHex(upperGasLimitBn);
|
|
323
|
+
}
|
|
324
|
+
async determineTransactionCategory(txParameters) {
|
|
325
|
+
const {
|
|
326
|
+
data,
|
|
327
|
+
to
|
|
328
|
+
} = txParameters;
|
|
329
|
+
let code = "";
|
|
330
|
+
let txCategory;
|
|
331
|
+
if (data && !to) {
|
|
332
|
+
txCategory = TRANSACTION_TYPES.DEPLOY_CONTRACT;
|
|
333
|
+
} else {
|
|
334
|
+
try {
|
|
335
|
+
code = await this.providerProxy.request({
|
|
336
|
+
method: "eth_getCode",
|
|
337
|
+
params: [to, "latest"]
|
|
338
|
+
});
|
|
339
|
+
} catch (error) {
|
|
340
|
+
log.warn(error);
|
|
341
|
+
}
|
|
342
|
+
const codeIsEmpty = !code || code === "0x" || code === "0x0";
|
|
343
|
+
txCategory = codeIsEmpty ? TRANSACTION_TYPES.SENT_ETHER : TRANSACTION_TYPES.CONTRACT_INTERACTION;
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
transactionCategory: txCategory,
|
|
347
|
+
code
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
async getDefaultGasLimit(txParams) {
|
|
351
|
+
const {
|
|
352
|
+
transactionCategory
|
|
353
|
+
} = await this.determineTransactionCategory(_objectSpread({}, txParams));
|
|
354
|
+
if (txParams.gas) {
|
|
355
|
+
return addHexPrefix(txParams.gas);
|
|
356
|
+
}
|
|
357
|
+
if (txParams.to && transactionCategory === TRANSACTION_TYPES.SENT_ETHER) {
|
|
358
|
+
// if there's data in the params, but there's no contract code, it's not a valid transaction
|
|
359
|
+
if (txParams.data) {
|
|
360
|
+
throw Error("TxGasUtil - Trying to call a function on a non-contract address");
|
|
361
|
+
}
|
|
362
|
+
const TWENTY_ONE_THOUSAND = 21000;
|
|
363
|
+
|
|
364
|
+
// This is a standard ether simple send, gas requirement is exactly 21k
|
|
365
|
+
return addHexPrefix(TWENTY_ONE_THOUSAND.toString(16));
|
|
366
|
+
}
|
|
367
|
+
const {
|
|
368
|
+
blockGasLimit,
|
|
369
|
+
estimatedGasHex
|
|
370
|
+
} = await this.analyzeGasUsage(txParams);
|
|
371
|
+
|
|
372
|
+
// add additional gas buffer to our estimation for safety
|
|
373
|
+
const gasLimit = this.addGasBuffer(addHexPrefix(estimatedGasHex), blockGasLimit);
|
|
374
|
+
return gasLimit;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export { TransactionFormatter };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
+
import { isValidAddress } from '@ethereumjs/util';
|
|
3
|
+
import { get } from '@toruslabs/http-helpers';
|
|
4
|
+
import { decGWEIToHexWEI, hexWEIToDecGWEI } from '../../converter.js';
|
|
5
|
+
|
|
6
|
+
function normalizeGWEIDecimalNumbers(n) {
|
|
7
|
+
const numberAsWEIHex = decGWEIToHexWEI(n);
|
|
8
|
+
const numberAsGWEI = hexWEIToDecGWEI(numberAsWEIHex).toString();
|
|
9
|
+
return numberAsGWEI;
|
|
10
|
+
}
|
|
11
|
+
async function fetchEip1159GasEstimates(url) {
|
|
12
|
+
const estimates = await get(url);
|
|
13
|
+
const normalizedEstimates = _objectSpread(_objectSpread({}, estimates), {}, {
|
|
14
|
+
estimatedBaseFee: normalizeGWEIDecimalNumbers(estimates.estimatedBaseFee),
|
|
15
|
+
low: _objectSpread(_objectSpread({}, estimates.low), {}, {
|
|
16
|
+
suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.low.suggestedMaxPriorityFeePerGas),
|
|
17
|
+
suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.low.suggestedMaxFeePerGas)
|
|
18
|
+
}),
|
|
19
|
+
medium: _objectSpread(_objectSpread({}, estimates.medium), {}, {
|
|
20
|
+
suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.medium.suggestedMaxPriorityFeePerGas),
|
|
21
|
+
suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.medium.suggestedMaxFeePerGas)
|
|
22
|
+
}),
|
|
23
|
+
high: _objectSpread(_objectSpread({}, estimates.high), {}, {
|
|
24
|
+
suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.high.suggestedMaxPriorityFeePerGas),
|
|
25
|
+
suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.high.suggestedMaxFeePerGas)
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
return normalizedEstimates;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium
|
|
33
|
+
* high values from that API.
|
|
34
|
+
*/
|
|
35
|
+
async function fetchLegacyGasPriceEstimates(url) {
|
|
36
|
+
const result = await get(url, {
|
|
37
|
+
referrer: url,
|
|
38
|
+
referrerPolicy: "no-referrer-when-downgrade",
|
|
39
|
+
method: "GET",
|
|
40
|
+
mode: "cors"
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
low: result.SafeGasPrice,
|
|
44
|
+
medium: result.ProposeGasPrice,
|
|
45
|
+
high: result.FastGasPrice
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function validateAddress(address, propertyName) {
|
|
49
|
+
if (!address || typeof address !== "string" || !isValidAddress(address)) {
|
|
50
|
+
throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function validateTypedSignMessageDataV4(messageData, currentChainId) {
|
|
54
|
+
validateAddress(messageData.from, "from");
|
|
55
|
+
if (!messageData.data || Array.isArray(messageData.data) || typeof messageData.data !== "object" && typeof messageData.data !== "string") {
|
|
56
|
+
throw new Error(`Invalid message "data": Must be a valid string or object.`);
|
|
57
|
+
}
|
|
58
|
+
let data;
|
|
59
|
+
if (typeof messageData.data === "object") {
|
|
60
|
+
data = messageData.data;
|
|
61
|
+
} else {
|
|
62
|
+
try {
|
|
63
|
+
data = JSON.parse(messageData.data);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throw new Error("Data must be passed as a valid JSON string.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!currentChainId) {
|
|
69
|
+
throw new Error("Current chainId cannot be null or undefined.");
|
|
70
|
+
}
|
|
71
|
+
let {
|
|
72
|
+
chainId
|
|
73
|
+
} = data.domain;
|
|
74
|
+
if (chainId) {
|
|
75
|
+
if (typeof chainId === "string") {
|
|
76
|
+
chainId = parseInt(chainId, chainId.startsWith("0x") ? 16 : 10);
|
|
77
|
+
}
|
|
78
|
+
const activeChainId = parseInt(currentChainId, 16);
|
|
79
|
+
if (Number.isNaN(activeChainId)) {
|
|
80
|
+
throw new Error(`Cannot sign messages for chainId "${chainId}", because Web3Auth is switching networks.`);
|
|
81
|
+
}
|
|
82
|
+
if (chainId !== activeChainId) {
|
|
83
|
+
throw new Error(`Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { fetchEip1159GasEstimates, fetchLegacyGasPriceEstimates, normalizeGWEIDecimalNumbers, validateAddress, validateTypedSignMessageDataV4 };
|
package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/ethPrivatekeyUtils.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
+
import { isHexString, stripHexPrefix, addHexPrefix, privateToAddress } from '@ethereumjs/util';
|
|
3
|
+
import { signMessage } from '@toruslabs/base-controllers';
|
|
4
|
+
import { getPublicCompressed } from '@toruslabs/eccrypto';
|
|
5
|
+
import { providerErrors } from '@web3auth/auth';
|
|
6
|
+
import { SigningKey, hashMessage } from 'ethers';
|
|
7
|
+
import { validateTypedData, hashTypedData } from 'viem';
|
|
8
|
+
import { log } from '../../../../base/loglevel.js';
|
|
9
|
+
import { validateTypedSignMessageDataV4 } from './TransactionFormatter/utils.js';
|
|
10
|
+
|
|
11
|
+
async function signTx(txParams, privKey, txFormatter) {
|
|
12
|
+
const finalTxParams = await txFormatter.formatTransaction(txParams);
|
|
13
|
+
const {
|
|
14
|
+
Transaction
|
|
15
|
+
} = await import('ethers');
|
|
16
|
+
const ethTx = Transaction.from(_objectSpread(_objectSpread({}, finalTxParams), {}, {
|
|
17
|
+
from: undefined // from is already calculated inside Transaction.from and is not allowed to be passed in
|
|
18
|
+
}));
|
|
19
|
+
const signKey = new SigningKey(addHexPrefix(privKey));
|
|
20
|
+
ethTx.signature = signKey.sign(ethTx.unsignedHash);
|
|
21
|
+
return ethTx.serialized;
|
|
22
|
+
}
|
|
23
|
+
function getProviderHandlers({
|
|
24
|
+
txFormatter,
|
|
25
|
+
privKey,
|
|
26
|
+
keyExportEnabled,
|
|
27
|
+
getProviderEngineProxy
|
|
28
|
+
}) {
|
|
29
|
+
return {
|
|
30
|
+
getAccounts: async _ => [`0x${Buffer.from(privateToAddress(Buffer.from(privKey, "hex"))).toString("hex")}`],
|
|
31
|
+
getPublicKey: async _ => {
|
|
32
|
+
const publicKey = getPublicCompressed(Buffer.from(stripHexPrefix(privKey), "hex"));
|
|
33
|
+
return `0x${Buffer.from(publicKey).toString("hex")}`;
|
|
34
|
+
},
|
|
35
|
+
getPrivateKey: async _ => {
|
|
36
|
+
if (!keyExportEnabled) throw providerErrors.custom({
|
|
37
|
+
message: "Private key export is disabled",
|
|
38
|
+
code: 4902
|
|
39
|
+
});
|
|
40
|
+
return privKey;
|
|
41
|
+
},
|
|
42
|
+
processTransaction: async (txParams, _) => {
|
|
43
|
+
const providerEngineProxy = getProviderEngineProxy();
|
|
44
|
+
if (!providerEngineProxy) throw providerErrors.custom({
|
|
45
|
+
message: "Provider is not initialized",
|
|
46
|
+
code: 4902
|
|
47
|
+
});
|
|
48
|
+
if (txParams.input && !txParams.data) txParams.data = addHexPrefix(txParams.input);
|
|
49
|
+
const serializedTx = await signTx(txParams, privKey, txFormatter);
|
|
50
|
+
const txHash = await providerEngineProxy.request({
|
|
51
|
+
method: "eth_sendRawTransaction",
|
|
52
|
+
params: [serializedTx]
|
|
53
|
+
});
|
|
54
|
+
return txHash;
|
|
55
|
+
},
|
|
56
|
+
processSignTransaction: async (txParams, _) => {
|
|
57
|
+
const providerEngineProxy = getProviderEngineProxy();
|
|
58
|
+
if (!providerEngineProxy) throw providerErrors.custom({
|
|
59
|
+
message: "Provider is not initialized",
|
|
60
|
+
code: 4902
|
|
61
|
+
});
|
|
62
|
+
if (txParams.input && !txParams.data) txParams.data = addHexPrefix(txParams.input);
|
|
63
|
+
const serializedTx = await signTx(txParams, privKey, txFormatter);
|
|
64
|
+
return serializedTx;
|
|
65
|
+
},
|
|
66
|
+
processEthSignMessage: async (msgParams, _) => {
|
|
67
|
+
const rawMessageSig = signMessage(privKey, msgParams.data);
|
|
68
|
+
return rawMessageSig;
|
|
69
|
+
},
|
|
70
|
+
processPersonalMessage: async (msgParams, _) => {
|
|
71
|
+
const privKeyBuffer = Buffer.from(privKey, "hex");
|
|
72
|
+
const ethersKey = new SigningKey(privKeyBuffer);
|
|
73
|
+
const {
|
|
74
|
+
data
|
|
75
|
+
} = msgParams;
|
|
76
|
+
// we need to check if the data is hex or not
|
|
77
|
+
// For historical reasons, you must submit the message to sign in hex-encoded UTF-8.
|
|
78
|
+
// https://docs.metamask.io/wallet/how-to/sign-data/#use-personal_sign
|
|
79
|
+
const message = isHexString(data) ? Buffer.from(stripHexPrefix(data), "hex") : Buffer.from(data);
|
|
80
|
+
const signature = ethersKey.sign(hashMessage(message));
|
|
81
|
+
return signature.serialized;
|
|
82
|
+
},
|
|
83
|
+
processTypedMessageV4: async (msgParams, _) => {
|
|
84
|
+
log.debug("processTypedMessageV4", msgParams);
|
|
85
|
+
const privKeyBuffer = Buffer.from(privKey, "hex");
|
|
86
|
+
const providerEngineProxy = getProviderEngineProxy();
|
|
87
|
+
if (!providerEngineProxy) throw providerErrors.custom({
|
|
88
|
+
message: "Provider is not initialized",
|
|
89
|
+
code: 4902
|
|
90
|
+
});
|
|
91
|
+
const chainId = await providerEngineProxy.request({
|
|
92
|
+
method: "eth_chainId"
|
|
93
|
+
});
|
|
94
|
+
await validateTypedSignMessageDataV4(msgParams, chainId);
|
|
95
|
+
const data = typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data;
|
|
96
|
+
const ethersPrivateKey = new SigningKey(privKeyBuffer);
|
|
97
|
+
validateTypedData(data);
|
|
98
|
+
const signature = ethersPrivateKey.sign(hashTypedData(data)).serialized;
|
|
99
|
+
return signature;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { getProviderHandlers };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { stripHexPrefix, addHexPrefix } from '@ethereumjs/util';
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import BN from 'bn.js';
|
|
4
|
+
|
|
5
|
+
function bnLessThan(a, b) {
|
|
6
|
+
if (a === null || a === undefined || b === null || b === undefined) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return new BigNumber(a, 10).lt(b, 10);
|
|
10
|
+
}
|
|
11
|
+
function bnToHex(inputBn) {
|
|
12
|
+
return addHexPrefix(inputBn.toString(16));
|
|
13
|
+
}
|
|
14
|
+
function hexToBn(inputHex) {
|
|
15
|
+
if (BN.isBN(inputHex)) return inputHex;
|
|
16
|
+
return new BN(stripHexPrefix(inputHex), 16);
|
|
17
|
+
}
|
|
18
|
+
function BnMultiplyByFraction(targetBN, numerator, denominator) {
|
|
19
|
+
const numberBN = new BN(numerator);
|
|
20
|
+
const denomBN = new BN(denominator);
|
|
21
|
+
return targetBN.mul(numberBN).div(denomBN);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { BnMultiplyByFraction, bnLessThan, bnToHex, hexToBn };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { mergeMiddleware, createScaffoldMiddleware, createAsyncMiddleware, rpcErrors } from '@web3auth/auth';
|
|
2
|
+
import { createWalletMiddleware } from './walletMidddleware.js';
|
|
3
|
+
|
|
4
|
+
function createEthMiddleware(providerHandlers) {
|
|
5
|
+
const {
|
|
6
|
+
getAccounts,
|
|
7
|
+
getPrivateKey,
|
|
8
|
+
getPublicKey,
|
|
9
|
+
processTransaction,
|
|
10
|
+
processSignTransaction,
|
|
11
|
+
processEthSignMessage,
|
|
12
|
+
processTypedMessageV4,
|
|
13
|
+
processPersonalMessage
|
|
14
|
+
} = providerHandlers;
|
|
15
|
+
const ethMiddleware = mergeMiddleware([createScaffoldMiddleware({
|
|
16
|
+
eth_syncing: false
|
|
17
|
+
}), createWalletMiddleware({
|
|
18
|
+
getAccounts,
|
|
19
|
+
getPrivateKey,
|
|
20
|
+
getPublicKey,
|
|
21
|
+
processTransaction,
|
|
22
|
+
processEthSignMessage,
|
|
23
|
+
processSignTransaction,
|
|
24
|
+
processTypedMessageV4,
|
|
25
|
+
processPersonalMessage
|
|
26
|
+
})]);
|
|
27
|
+
return ethMiddleware;
|
|
28
|
+
}
|
|
29
|
+
function createEthChainSwitchMiddleware({
|
|
30
|
+
addChain,
|
|
31
|
+
switchChain
|
|
32
|
+
}) {
|
|
33
|
+
async function addNewChain(req, res) {
|
|
34
|
+
var _req$params;
|
|
35
|
+
const chainParams = (_req$params = req.params) !== null && _req$params !== void 0 && _req$params.length ? req.params[0] : undefined;
|
|
36
|
+
if (!chainParams) throw rpcErrors.invalidParams("Missing chain params");
|
|
37
|
+
if (!chainParams.chainId) throw rpcErrors.invalidParams("Missing chainId in chainParams");
|
|
38
|
+
if (!chainParams.rpcUrls || chainParams.rpcUrls.length === 0) throw rpcErrors.invalidParams("Missing rpcUrls in chainParams");
|
|
39
|
+
if (!chainParams.nativeCurrency) throw rpcErrors.invalidParams("Missing nativeCurrency in chainParams");
|
|
40
|
+
res.result = await addChain(chainParams);
|
|
41
|
+
}
|
|
42
|
+
async function updateChain(req, res) {
|
|
43
|
+
var _req$params2;
|
|
44
|
+
const chainParams = (_req$params2 = req.params) !== null && _req$params2 !== void 0 && _req$params2.length ? req.params[0] : undefined;
|
|
45
|
+
if (!chainParams) throw rpcErrors.invalidParams("Missing chainId");
|
|
46
|
+
res.result = await switchChain(chainParams);
|
|
47
|
+
}
|
|
48
|
+
return createScaffoldMiddleware({
|
|
49
|
+
wallet_addEthereumChain: createAsyncMiddleware(addNewChain),
|
|
50
|
+
wallet_switchEthereumChain: createAsyncMiddleware(updateChain)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// #region account middlewares
|
|
55
|
+
function createEthAccountMiddleware({
|
|
56
|
+
updatePrivatekey
|
|
57
|
+
}) {
|
|
58
|
+
async function updateAccount(req, res) {
|
|
59
|
+
var _req$params3;
|
|
60
|
+
const accountParams = (_req$params3 = req.params) !== null && _req$params3 !== void 0 && _req$params3.length ? req.params[0] : undefined;
|
|
61
|
+
if (!(accountParams !== null && accountParams !== void 0 && accountParams.privateKey)) throw rpcErrors.invalidParams("Missing privateKey");
|
|
62
|
+
res.result = await updatePrivatekey(accountParams);
|
|
63
|
+
}
|
|
64
|
+
return createScaffoldMiddleware({
|
|
65
|
+
wallet_updateAccount: createAsyncMiddleware(updateAccount)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// #endregion account middlewares
|
|
70
|
+
|
|
71
|
+
export { createEthAccountMiddleware, createEthChainSwitchMiddleware, createEthMiddleware };
|