@web3auth/no-modal 10.16.0 → 11.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs/account-linking/index.js +8 -0
- package/dist/lib.cjs/account-linking/react.js +95 -0
- package/dist/lib.cjs/account-linking/rest.js +54 -0
- package/dist/lib.cjs/account-linking/vue.js +98 -0
- package/dist/lib.cjs/base/analytics.js +13 -1
- package/dist/lib.cjs/base/connector/baseConnector.js +104 -2
- package/dist/lib.cjs/base/connector/connectorStatus.js +2 -0
- package/dist/lib.cjs/base/connector/constants.js +6 -2
- package/dist/lib.cjs/base/connector/utils.js +0 -21
- package/dist/lib.cjs/base/constants.js +4 -0
- package/dist/lib.cjs/base/cookie.js +6 -20
- package/dist/lib.cjs/base/errors/index.js +84 -12
- package/dist/lib.cjs/base/utils.js +22 -11
- package/dist/lib.cjs/base/wallet/index.js +7 -0
- package/dist/lib.cjs/base/wallet/solana.js +83 -0
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +566 -93
- package/dist/lib.cjs/connectors/auth-connector/authSolanaWallet.js +187 -0
- package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +55 -58
- package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +57 -66
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +19 -14
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +18 -13
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +24 -36
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +350 -131
- package/dist/lib.cjs/connectors/utils.js +8 -2
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +12 -38
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/config.js +4 -3
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +111 -73
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +24 -51
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +144 -0
- package/dist/lib.cjs/index.js +55 -83
- package/dist/lib.cjs/noModal.js +957 -169
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +23 -39
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +12 -10
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +8 -6
- package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +47 -44
- package/dist/lib.cjs/providers/base-provider/CommonJRPCProvider.js +1 -3
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +69 -35
- package/dist/lib.cjs/providers/base-provider/commonPrivateKeyProvider.js +8 -11
- package/dist/lib.cjs/providers/base-provider/index.js +0 -1
- package/dist/lib.cjs/providers/base-provider/jrpcClient.js +18 -19
- package/dist/lib.cjs/providers/base-provider/utils.js +0 -3
- package/dist/lib.cjs/providers/ethereum-provider/rpc/ethRpcMiddlewares.js +22 -43
- package/dist/lib.cjs/providers/ethereum-provider/rpc/jrpcClient.js +18 -19
- package/dist/lib.cjs/providers/ethereum-provider/rpc/walletMiddleware.js +200 -0
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +9 -18
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.js +2 -1
- package/dist/lib.cjs/providers/xrpl-provider/rpc/JrpcClient.js +19 -26
- package/dist/lib.cjs/providers/xrpl-provider/rpc/xrplRpcMiddlewares.js +46 -37
- package/dist/lib.cjs/react/context/WalletServicesInnerContext.js +2 -69
- package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +6 -161
- package/dist/lib.cjs/react/context/useWalletServicesContextValue.js +76 -0
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +216 -0
- package/dist/lib.cjs/react/hooks/{useIdentityToken.js → useAuthTokenInfo.js} +6 -7
- package/dist/lib.cjs/react/hooks/useCheckout.js +4 -2
- package/dist/lib.cjs/react/hooks/useFunding.js +4 -2
- package/dist/lib.cjs/react/hooks/useReceive.js +4 -2
- package/dist/lib.cjs/react/hooks/useSwap.js +4 -2
- package/dist/lib.cjs/react/hooks/useWalletConnectScanner.js +4 -2
- package/dist/lib.cjs/react/hooks/useWalletServicesPlugin.js +3 -10
- package/dist/lib.cjs/react/hooks/useWalletUI.js +4 -2
- package/dist/lib.cjs/react/hooks/useWallets.js +51 -0
- package/dist/lib.cjs/react/hooks/useWeb3Auth.js +1 -22
- package/dist/lib.cjs/react/hooks/useWeb3AuthConnect.js +2 -2
- package/dist/lib.cjs/react/hooks/useWeb3AuthInner.js +4 -2
- package/dist/lib.cjs/react/index.js +12 -2
- package/dist/lib.cjs/react/solana/hooks/useSignAndSendTransaction.js +22 -4
- package/dist/lib.cjs/react/solana/hooks/useSignMessage.js +20 -2
- package/dist/lib.cjs/react/solana/hooks/useSignTransaction.js +22 -3
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +34 -51
- package/dist/lib.cjs/react/solana/index.js +2 -0
- package/dist/lib.cjs/react/solana/provider.js +169 -0
- package/dist/lib.cjs/react/wagmi/provider.js +10 -8
- package/dist/lib.cjs/types/account-linking/index.d.ts +2 -0
- package/dist/lib.cjs/types/account-linking/interfaces.d.ts +90 -0
- package/dist/lib.cjs/types/account-linking/react.d.ts +19 -0
- package/dist/lib.cjs/types/account-linking/rest.d.ts +9 -0
- package/dist/lib.cjs/types/account-linking/vue.d.ts +20 -0
- package/dist/lib.cjs/types/base/analytics.d.ts +9 -0
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +26 -5
- package/dist/lib.cjs/types/base/connector/connectorStatus.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/constants.d.ts +5 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +72 -16
- package/dist/lib.cjs/types/base/connector/utils.d.ts +0 -3
- package/dist/lib.cjs/types/base/constants.d.ts +1 -0
- package/dist/lib.cjs/types/base/cookie.d.ts +0 -7
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +57 -13
- package/dist/lib.cjs/types/base/errors/index.d.ts +15 -3
- package/dist/lib.cjs/types/base/hooks/index.d.ts +2 -2
- package/dist/lib.cjs/types/base/interfaces.d.ts +8 -2
- package/dist/lib.cjs/types/base/utils.d.ts +9 -2
- package/dist/lib.cjs/types/base/wallet/index.d.ts +3 -0
- package/dist/lib.cjs/types/base/wallet/solana.d.ts +19 -0
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +37 -8
- package/dist/lib.cjs/types/connectors/auth-connector/authSolanaWallet.d.ts +35 -0
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +77 -2
- package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +8 -2
- package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +8 -2
- package/dist/lib.cjs/types/connectors/injected-evm-connector/injectedEvmConnector.d.ts +2 -2
- package/dist/lib.cjs/types/connectors/injected-solana-connector/walletStandardConnector.d.ts +10 -7
- package/dist/lib.cjs/types/connectors/metamask-connector/metamaskConnector.d.ts +35 -3
- package/dist/lib.cjs/types/connectors/utils.d.ts +2 -0
- package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.d.ts +0 -1
- package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/walletConnectV2Utils.d.ts +1 -5
- package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/wcSolanaWallet.d.ts +26 -0
- package/dist/lib.cjs/types/index.d.ts +1 -0
- package/dist/lib.cjs/types/noModal.d.ts +113 -10
- package/dist/lib.cjs/types/plugins/wallet-services-plugin/plugin.d.ts +1 -4
- package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +4 -4
- package/dist/lib.cjs/types/providers/base-provider/baseProvider.d.ts +7 -0
- package/dist/lib.cjs/types/providers/base-provider/jrpcClient.d.ts +2 -5
- package/dist/lib.cjs/types/providers/base-provider/utils.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/rpc/ethRpcMiddlewares.d.ts +4 -4
- package/dist/lib.cjs/types/providers/ethereum-provider/rpc/index.d.ts +1 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/rpc/jrpcClient.d.ts +2 -5
- package/dist/lib.cjs/types/providers/ethereum-provider/rpc/walletMiddleware.d.ts +3 -0
- package/dist/lib.cjs/types/providers/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.d.ts +0 -1
- package/dist/lib.cjs/types/providers/xrpl-provider/rpc/JrpcClient.d.ts +3 -7
- package/dist/lib.cjs/types/providers/xrpl-provider/rpc/xrplRpcMiddlewares.d.ts +5 -12
- package/dist/lib.cjs/types/react/context/index.d.ts +4 -0
- package/dist/lib.cjs/types/react/context/useWalletServicesContextValue.d.ts +12 -0
- package/dist/lib.cjs/types/react/context/useWeb3AuthInnerContextValue.d.ts +26 -0
- package/dist/lib.cjs/types/react/hooks/index.d.ts +2 -1
- package/dist/lib.cjs/types/react/hooks/{useIdentityToken.d.ts → useAuthTokenInfo.d.ts} +4 -4
- package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +8 -0
- package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +1 -2
- package/dist/lib.cjs/types/react/hooks/useWeb3AuthConnect.d.ts +2 -2
- package/dist/lib.cjs/types/react/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/solana/hooks/useSignAndSendTransaction.d.ts +7 -2
- package/dist/lib.cjs/types/react/solana/hooks/useSignTransaction.d.ts +8 -3
- package/dist/lib.cjs/types/react/solana/hooks/useSolanaWallet.d.ts +17 -4
- package/dist/lib.cjs/types/react/solana/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/solana/provider.d.ts +26 -0
- package/dist/lib.cjs/types/vue/composables/index.d.ts +3 -1
- package/dist/lib.cjs/types/vue/composables/{useIdentityToken.d.ts → useAuthTokenInfo.d.ts} +3 -3
- package/dist/lib.cjs/types/vue/composables/useInjectedWeb3AuthInnerContext.d.ts +1 -0
- package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useWeb3Auth.d.ts +1 -2
- package/dist/lib.cjs/types/vue/composables/useWeb3AuthConnect.d.ts +2 -2
- package/dist/lib.cjs/types/vue/index.d.ts +2 -0
- package/dist/lib.cjs/types/vue/interfaces.d.ts +2 -2
- package/dist/lib.cjs/types/vue/solana/composables/index.d.ts +1 -0
- package/dist/lib.cjs/types/vue/solana/composables/useSignAndSendTransaction.d.ts +7 -2
- package/dist/lib.cjs/types/vue/solana/composables/useSignTransaction.d.ts +8 -3
- package/dist/lib.cjs/types/vue/solana/composables/useSolanaClient.d.ts +7 -0
- package/dist/lib.cjs/types/vue/solana/composables/useSolanaWallet.d.ts +17 -4
- package/dist/lib.cjs/types/vue/solana/constants.d.ts +3 -0
- package/dist/lib.cjs/types/vue/solana/index.d.ts +2 -0
- package/dist/lib.cjs/types/vue/solana/provider.d.ts +8 -0
- package/dist/lib.cjs/types/vue/useWalletServicesInnerContextValue.d.ts +13 -0
- package/dist/lib.cjs/types/vue/useWeb3AuthInnerContextValue.d.ts +26 -0
- package/dist/lib.cjs/types/x402/index.d.ts +43 -0
- package/dist/lib.cjs/types/x402/interfaces.d.ts +11 -0
- package/dist/lib.cjs/types/x402/react.d.ts +17 -0
- package/dist/lib.cjs/types/x402/vue.d.ts +18 -0
- package/dist/lib.cjs/vue/WalletServicesInnerProvider.js +9 -54
- package/dist/lib.cjs/vue/Web3AuthProvider.js +16 -177
- package/dist/lib.cjs/vue/composables/{useIdentityToken.js → useAuthTokenInfo.js} +10 -8
- package/dist/lib.cjs/vue/composables/useCheckout.js +4 -2
- package/dist/lib.cjs/vue/composables/useEnableMFA.js +4 -2
- package/dist/lib.cjs/vue/composables/useFunding.js +4 -2
- package/dist/lib.cjs/vue/composables/useInjectedWeb3AuthInnerContext.js +29 -0
- package/dist/lib.cjs/vue/composables/useManageMFA.js +4 -2
- package/dist/lib.cjs/vue/composables/useReceive.js +4 -2
- package/dist/lib.cjs/vue/composables/useSwap.js +4 -2
- package/dist/lib.cjs/vue/composables/useSwitchChain.js +4 -2
- package/dist/lib.cjs/vue/composables/useWalletConnectScanner.js +4 -2
- package/dist/lib.cjs/vue/composables/useWalletUI.js +4 -2
- package/dist/lib.cjs/vue/composables/useWallets.js +52 -0
- package/dist/lib.cjs/vue/composables/useWeb3Auth.js +1 -26
- package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +6 -4
- package/dist/lib.cjs/vue/composables/useWeb3AuthDisconnect.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthInner.js +2 -20
- package/dist/lib.cjs/vue/composables/useWeb3AuthUser.js +4 -2
- package/dist/lib.cjs/vue/index.js +10 -2
- package/dist/lib.cjs/vue/solana/composables/useSignAndSendTransaction.js +6 -3
- package/dist/lib.cjs/vue/solana/composables/useSignMessage.js +6 -3
- package/dist/lib.cjs/vue/solana/composables/useSignTransaction.js +6 -3
- package/dist/lib.cjs/vue/solana/composables/useSolanaClient.js +14 -0
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +60 -41
- package/dist/lib.cjs/vue/solana/constants.js +5 -0
- package/dist/lib.cjs/vue/solana/index.js +6 -0
- package/dist/lib.cjs/vue/solana/provider.js +110 -0
- package/dist/lib.cjs/vue/useWalletServicesInnerContextValue.js +75 -0
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +226 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +28 -12
- package/dist/lib.cjs/x402/index.js +175 -0
- package/dist/lib.cjs/x402/interfaces.js +5 -0
- package/dist/lib.cjs/x402/react.js +64 -0
- package/dist/lib.cjs/x402/vue.js +58 -0
- package/dist/lib.esm/account-linking/index.js +1 -0
- package/dist/lib.esm/account-linking/react.js +74 -0
- package/dist/lib.esm/account-linking/rest.js +51 -0
- package/dist/lib.esm/account-linking/vue.js +78 -0
- package/dist/lib.esm/base/analytics.js +13 -1
- package/dist/lib.esm/base/connector/baseConnector.js +104 -2
- package/dist/lib.esm/base/connector/connectorStatus.js +2 -1
- package/dist/lib.esm/base/connector/constants.js +6 -2
- package/dist/lib.esm/base/connector/utils.js +1 -19
- package/dist/lib.esm/base/constants.js +4 -1
- package/dist/lib.esm/base/cookie.js +7 -20
- package/dist/lib.esm/base/errors/index.js +84 -13
- package/dist/lib.esm/base/utils.js +22 -7
- package/dist/lib.esm/base/wallet/index.js +2 -1
- package/dist/lib.esm/base/wallet/solana.js +81 -0
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +527 -57
- package/dist/lib.esm/connectors/auth-connector/authSolanaWallet.js +175 -0
- package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +55 -58
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +57 -66
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +16 -13
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +16 -13
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +22 -34
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +366 -132
- package/dist/lib.esm/connectors/utils.js +9 -4
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +12 -31
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/config.js +1 -1
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +110 -73
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +21 -49
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +130 -0
- package/dist/lib.esm/index.js +12 -19
- package/dist/lib.esm/noModal.js +975 -177
- package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +20 -39
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +9 -9
- package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +3 -3
- package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +48 -45
- package/dist/lib.esm/providers/base-provider/CommonJRPCProvider.js +2 -4
- package/dist/lib.esm/providers/base-provider/baseProvider.js +68 -38
- package/dist/lib.esm/providers/base-provider/commonPrivateKeyProvider.js +9 -12
- package/dist/lib.esm/providers/base-provider/index.js +1 -1
- package/dist/lib.esm/providers/base-provider/jrpcClient.js +20 -19
- package/dist/lib.esm/providers/base-provider/utils.js +1 -3
- package/dist/lib.esm/providers/ethereum-provider/rpc/ethRpcMiddlewares.js +23 -44
- package/dist/lib.esm/providers/ethereum-provider/rpc/jrpcClient.js +20 -19
- package/dist/lib.esm/providers/ethereum-provider/rpc/walletMiddleware.js +201 -0
- package/dist/lib.esm/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +6 -17
- package/dist/lib.esm/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.js +2 -1
- package/dist/lib.esm/providers/xrpl-provider/rpc/JrpcClient.js +21 -25
- package/dist/lib.esm/providers/xrpl-provider/rpc/xrplRpcMiddlewares.js +48 -38
- package/dist/lib.esm/react/context/WalletServicesInnerContext.js +3 -57
- package/dist/lib.esm/react/context/Web3AuthInnerContext.js +7 -152
- package/dist/lib.esm/react/context/useWalletServicesContextValue.js +59 -0
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +203 -0
- package/dist/lib.esm/react/hooks/{useIdentityToken.js → useAuthTokenInfo.js} +6 -7
- package/dist/lib.esm/react/hooks/useWalletServicesPlugin.js +3 -10
- package/dist/lib.esm/react/hooks/useWallets.js +33 -0
- package/dist/lib.esm/react/hooks/useWeb3Auth.js +1 -22
- package/dist/lib.esm/react/hooks/useWeb3AuthConnect.js +2 -2
- package/dist/lib.esm/react/index.js +6 -1
- package/dist/lib.esm/react/solana/hooks/useSignAndSendTransaction.js +6 -4
- package/dist/lib.esm/react/solana/hooks/useSignMessage.js +4 -2
- package/dist/lib.esm/react/solana/hooks/useSignTransaction.js +6 -3
- package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +33 -28
- package/dist/lib.esm/react/solana/index.js +1 -0
- package/dist/lib.esm/react/solana/provider.js +153 -0
- package/dist/lib.esm/react/wagmi/provider.js +8 -8
- package/dist/lib.esm/vue/WalletServicesInnerProvider.js +4 -54
- package/dist/lib.esm/vue/Web3AuthProvider.js +7 -179
- package/dist/lib.esm/vue/composables/{useIdentityToken.js → useAuthTokenInfo.js} +6 -6
- package/dist/lib.esm/vue/composables/useCheckout.js +1 -1
- package/dist/lib.esm/vue/composables/useFunding.js +1 -1
- package/dist/lib.esm/vue/composables/useInjectedWeb3AuthInnerContext.js +11 -0
- package/dist/lib.esm/vue/composables/useReceive.js +1 -1
- package/dist/lib.esm/vue/composables/useSwap.js +1 -1
- package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +1 -1
- package/dist/lib.esm/vue/composables/useWalletUI.js +1 -1
- package/dist/lib.esm/vue/composables/useWallets.js +35 -0
- package/dist/lib.esm/vue/composables/useWeb3Auth.js +1 -26
- package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -2
- package/dist/lib.esm/vue/composables/useWeb3AuthInner.js +2 -6
- package/dist/lib.esm/vue/index.js +5 -1
- package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +2 -1
- package/dist/lib.esm/vue/solana/composables/useSignMessage.js +2 -1
- package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +3 -2
- package/dist/lib.esm/vue/solana/composables/useSolanaClient.js +12 -0
- package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +53 -35
- package/dist/lib.esm/vue/solana/constants.js +3 -0
- package/dist/lib.esm/vue/solana/index.js +3 -0
- package/dist/lib.esm/vue/solana/provider.js +99 -0
- package/dist/lib.esm/vue/useWalletServicesInnerContextValue.js +58 -0
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +213 -0
- package/dist/lib.esm/vue/wagmi/provider.js +26 -12
- package/dist/lib.esm/x402/index.js +170 -0
- package/dist/lib.esm/x402/interfaces.js +3 -0
- package/dist/lib.esm/x402/react.js +59 -0
- package/dist/lib.esm/x402/vue.js +54 -0
- package/package.json +102 -53
- package/dist/lib.cjs/providers/ethereum-mpc-provider/index.js +0 -7
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +0 -224
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +0 -177
- package/dist/lib.cjs/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.js +0 -21
- package/dist/lib.cjs/providers/ethereum-provider/providers/converter.js +0 -88
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.js +0 -27
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +0 -383
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.js +0 -8
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.js +0 -93
- package/dist/lib.cjs/providers/ethereum-provider/providers/utils.js +0 -29
- package/dist/lib.cjs/providers/ethereum-provider/rpc/walletMidddleware.js +0 -251
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +0 -65
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/providerHandlers.js +0 -45
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/utils.js +0 -16
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +0 -103
- package/dist/lib.cjs/providers/solana-provider/rpc/JrpcClient.js +0 -47
- package/dist/lib.cjs/providers/solana-provider/rpc/solanaRpcMiddlewares.js +0 -97
- package/dist/lib.cjs/providers/solana-provider/solanaWallet.js +0 -91
- package/dist/lib.cjs/types/connectors/injected-solana-connector/utils.d.ts +0 -3
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.d.ts +0 -74
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/signingProviders/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.d.ts +0 -12
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.d.ts +0 -3
- package/dist/lib.cjs/types/providers/ethereum-mpc-provider/rpc/interfaces.d.ts +0 -15
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/converter.d.ts +0 -14
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.d.ts +0 -16
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.d.ts +0 -28
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/index.d.ts +0 -4
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.d.ts +0 -46
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.d.ts +0 -11
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/utils.d.ts +0 -5
- package/dist/lib.cjs/types/providers/ethereum-provider/rpc/walletMidddleware.d.ts +0 -3
- package/dist/lib.cjs/types/providers/solana-provider/index.d.ts +0 -4
- package/dist/lib.cjs/types/providers/solana-provider/interface.d.ts +0 -22
- package/dist/lib.cjs/types/providers/solana-provider/providers/index.d.ts +0 -1
- package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.d.ts +0 -16
- package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/base/providerHandlers.d.ts +0 -3
- package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/index.d.ts +0 -2
- package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/utils.d.ts +0 -3
- package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/walletStandardProvider.d.ts +0 -9
- package/dist/lib.cjs/types/providers/solana-provider/rpc/JrpcClient.d.ts +0 -9
- package/dist/lib.cjs/types/providers/solana-provider/rpc/index.d.ts +0 -3
- package/dist/lib.cjs/types/providers/solana-provider/rpc/interfaces.d.ts +0 -27
- package/dist/lib.cjs/types/providers/solana-provider/rpc/solanaRpcMiddlewares.d.ts +0 -20
- package/dist/lib.cjs/types/providers/solana-provider/solanaWallet.d.ts +0 -29
- package/dist/lib.esm/providers/ethereum-mpc-provider/index.js +0 -1
- package/dist/lib.esm/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +0 -206
- package/dist/lib.esm/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +0 -163
- package/dist/lib.esm/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.js +0 -20
- package/dist/lib.esm/providers/ethereum-provider/providers/converter.js +0 -85
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.js +0 -21
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +0 -378
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.js +0 -8
- package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.js +0 -88
- package/dist/lib.esm/providers/ethereum-provider/providers/utils.js +0 -24
- package/dist/lib.esm/providers/ethereum-provider/rpc/walletMidddleware.js +0 -258
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +0 -47
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/base/providerHandlers.js +0 -43
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/utils.js +0 -14
- package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +0 -91
- package/dist/lib.esm/providers/solana-provider/rpc/JrpcClient.js +0 -42
- package/dist/lib.esm/providers/solana-provider/rpc/solanaRpcMiddlewares.js +0 -89
- package/dist/lib.esm/providers/solana-provider/solanaWallet.js +0 -92
- package/dist/noModal.umd.min.js +0 -2
- package/dist/noModal.umd.min.js.LICENSE.txt +0 -46
package/dist/lib.esm/noModal.js
CHANGED
|
@@ -2,48 +2,58 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
2
2
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import { CHAIN_NAMESPACES, BUTTON_POSITION, CONFIRMATION_STRATEGY } from '@toruslabs/base-controllers';
|
|
5
|
-
import {
|
|
5
|
+
import { SMART_ACCOUNT_EIP_STANDARD, EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES } from '@toruslabs/ethereum-controllers';
|
|
6
|
+
import { SafeEventEmitter, serializeError, UX_MODE, cloneDeep, CookieStorage, LocalStorageAdapter, MemoryStorage } from '@web3auth/auth';
|
|
6
7
|
import deepmerge from 'deepmerge';
|
|
7
|
-
import { cookieStorage } from './base/cookie.js';
|
|
8
8
|
import { deserialize } from './base/deserialize.js';
|
|
9
|
+
import { WalletInitializationError, WalletLoginError, AccountLinkingError } from './base/errors/index.js';
|
|
9
10
|
import { LOGIN_MODE, SMART_ACCOUNT_WALLET_SCOPE, WEB3AUTH_STATE_STORAGE_KEY } from './base/constants.js';
|
|
10
|
-
import {
|
|
11
|
+
import { log } from './base/loglevel.js';
|
|
11
12
|
import { CONNECTOR_STATUS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_EVENTS } from './base/connector/constants.js';
|
|
12
|
-
import {
|
|
13
|
+
import { Analytics, ANALYTICS_INTEGRATION_TYPE, ANALYTICS_SDK_TYPE, ANALYTICS_EVENTS } from './base/analytics.js';
|
|
14
|
+
import { sdkVersion, fetchProjectConfig, withAbort, getErrorAnalyticsProperties, getCaipChainId, isHexStrict, getHostname, getWhitelabelAnalyticsProperties, getAaAnalyticsProperties, getWalletServicesAnalyticsProperties, isBrowser, parseChainNamespaceFromCitadelResponse, normalizeWalletName } from './base/utils.js';
|
|
15
|
+
import { WALLET_CONNECTORS } from './base/wallet/index.js';
|
|
16
|
+
import { CONNECTOR_NAMESPACES } from './base/chain/IChainInterface.js';
|
|
17
|
+
import { CONNECTED_STATUSES, CAN_LOGOUT_STATUSES, CAN_AUTHORIZE_STATUSES } from './base/connector/connectorStatus.js';
|
|
18
|
+
import { assertAuthConnector, authConnector, isAuthConnector } from './connectors/auth-connector/authConnector.js';
|
|
13
19
|
import { CommonJRPCProvider } from './providers/base-provider/CommonJRPCProvider.js';
|
|
14
|
-
import { authConnector } from './connectors/auth-connector/authConnector.js';
|
|
15
20
|
import { walletServicesPlugin } from './plugins/wallet-services-plugin/plugin.js';
|
|
16
|
-
import { storageAvailable } from './base/connector/utils.js';
|
|
17
21
|
import { metaMaskConnector } from './connectors/metamask-connector/metamaskConnector.js';
|
|
18
|
-
import {
|
|
19
|
-
import { log } from './base/loglevel.js';
|
|
20
|
-
import { WALLET_CONNECTORS } from './base/wallet/index.js';
|
|
21
|
-
import { CONNECTOR_NAMESPACES } from './base/chain/IChainInterface.js';
|
|
22
|
-
import { CONNECTED_STATUSES, CAN_AUTHORIZE_STATUSES } from './base/connector/connectorStatus.js';
|
|
22
|
+
import { storageAvailable } from './base/connector/utils.js';
|
|
23
23
|
import { PLUGIN_STATUS, PLUGIN_NAMESPACES } from './base/plugin/IPlugin.js';
|
|
24
24
|
|
|
25
|
-
const _excluded = ["walletScope"];
|
|
25
|
+
const _excluded = ["walletScope", "eipStandard"];
|
|
26
|
+
const PRIMARY_CONNECTED_WALLET_KEY = "__primary__";
|
|
26
27
|
class Web3AuthNoModal extends SafeEventEmitter {
|
|
27
28
|
constructor(options, initialState) {
|
|
28
29
|
super();
|
|
29
30
|
_defineProperty(this, "coreOptions", void 0);
|
|
30
31
|
_defineProperty(this, "status", CONNECTOR_STATUS.NOT_READY);
|
|
32
|
+
_defineProperty(this, "loginMode", LOGIN_MODE.NO_MODAL);
|
|
31
33
|
_defineProperty(this, "aaProvider", null);
|
|
32
34
|
_defineProperty(this, "connectors", []);
|
|
33
35
|
_defineProperty(this, "commonJRPCProvider", null);
|
|
34
36
|
_defineProperty(this, "analytics", void 0);
|
|
35
37
|
_defineProperty(this, "plugins", {});
|
|
38
|
+
_defineProperty(this, "consentRequired", false);
|
|
39
|
+
_defineProperty(this, "projectConfig", null);
|
|
36
40
|
_defineProperty(this, "storage", void 0);
|
|
41
|
+
_defineProperty(this, "connectionReconnected", false);
|
|
42
|
+
/** Connected wallet state keyed by linked account id; the primary session uses a reserved key. */
|
|
43
|
+
_defineProperty(this, "connectedWalletConnectorMap", new Map());
|
|
44
|
+
_defineProperty(this, "activeWalletConnectorKey", PRIMARY_CONNECTED_WALLET_KEY);
|
|
37
45
|
_defineProperty(this, "state", {
|
|
38
|
-
|
|
46
|
+
primaryConnectorName: null,
|
|
39
47
|
cachedConnector: null,
|
|
40
48
|
currentChainId: null,
|
|
41
|
-
idToken: null
|
|
49
|
+
idToken: null,
|
|
50
|
+
accessToken: null,
|
|
51
|
+
refreshToken: null,
|
|
52
|
+
activeAccount: null
|
|
42
53
|
});
|
|
43
|
-
_defineProperty(this, "loginMode", LOGIN_MODE.NO_MODAL);
|
|
44
54
|
if (!options.clientId) throw WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
45
55
|
if (options.enableLogging) log.enableAll();else log.setLevel("error");
|
|
46
|
-
if (!options.
|
|
56
|
+
if (!options.initialAuthenticationMode) options.initialAuthenticationMode = CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
47
57
|
this.coreOptions = options;
|
|
48
58
|
this.storage = this.getStorageMethod();
|
|
49
59
|
this.analytics = new Analytics();
|
|
@@ -53,11 +63,12 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
53
63
|
this.analytics.setGlobalProperties({
|
|
54
64
|
integration_type: ANALYTICS_INTEGRATION_TYPE.NATIVE_SDK
|
|
55
65
|
});
|
|
56
|
-
this.loadState(initialState)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
this.loadState(initialState).then(() => {
|
|
67
|
+
if (this.state.idToken && this.coreOptions.ssr && !this.consentRequired) {
|
|
68
|
+
this.status = this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN ? CONNECTOR_STATUS.AUTHORIZED : CONNECTOR_STATUS.CONNECTED;
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}).catch(() => {});
|
|
61
72
|
}
|
|
62
73
|
get currentChain() {
|
|
63
74
|
var _this$coreOptions$cha;
|
|
@@ -65,16 +76,13 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
65
76
|
return (_this$coreOptions$cha = this.coreOptions.chains) === null || _this$coreOptions$cha === void 0 ? void 0 : _this$coreOptions$cha.find(chain => chain.chainId === this.currentChainId);
|
|
66
77
|
}
|
|
67
78
|
get connected() {
|
|
68
|
-
return Boolean(this.
|
|
79
|
+
return Boolean(this.primaryConnector);
|
|
69
80
|
}
|
|
70
|
-
get
|
|
71
|
-
|
|
72
|
-
return this.commonJRPCProvider;
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
81
|
+
get connection() {
|
|
82
|
+
return this.getConnectedWalletConnectionByKey(this.activeWalletConnectorKey);
|
|
75
83
|
}
|
|
76
|
-
get
|
|
77
|
-
return this.state.
|
|
84
|
+
get primaryConnectorName() {
|
|
85
|
+
return this.state.primaryConnectorName;
|
|
78
86
|
}
|
|
79
87
|
get cachedConnector() {
|
|
80
88
|
return this.state.cachedConnector;
|
|
@@ -83,9 +91,13 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
83
91
|
var _this$coreOptions$cha2;
|
|
84
92
|
return this.state.currentChainId || this.coreOptions.defaultChainId || ((_this$coreOptions$cha2 = this.coreOptions.chains) === null || _this$coreOptions$cha2 === void 0 || (_this$coreOptions$cha2 = _this$coreOptions$cha2[0]) === null || _this$coreOptions$cha2 === void 0 ? void 0 : _this$coreOptions$cha2.chainId) || null;
|
|
85
93
|
}
|
|
86
|
-
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* This is always the primary connector that is connected to the user.
|
|
97
|
+
*/
|
|
98
|
+
get primaryConnector() {
|
|
87
99
|
var _this$currentChain;
|
|
88
|
-
return this.getConnector(this.
|
|
100
|
+
return this.getConnector(this.primaryConnectorName, (_this$currentChain = this.currentChain) === null || _this$currentChain === void 0 ? void 0 : _this$currentChain.chainNamespace);
|
|
89
101
|
}
|
|
90
102
|
get accountAbstractionProvider() {
|
|
91
103
|
return this.aaProvider;
|
|
@@ -93,6 +105,29 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
93
105
|
get idToken() {
|
|
94
106
|
return this.state.idToken || null;
|
|
95
107
|
}
|
|
108
|
+
get accessToken() {
|
|
109
|
+
return this.state.accessToken || null;
|
|
110
|
+
}
|
|
111
|
+
get refreshToken() {
|
|
112
|
+
return this.state.refreshToken || null;
|
|
113
|
+
}
|
|
114
|
+
get activeAccount() {
|
|
115
|
+
return this.state.activeAccount;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* This is the current active connector.
|
|
120
|
+
*/
|
|
121
|
+
get activeConnector() {
|
|
122
|
+
const activeConnectedWallet = this.getConnectedWalletConnectorStateByKey(this.activeWalletConnectorKey);
|
|
123
|
+
if (activeConnectedWallet) {
|
|
124
|
+
return activeConnectedWallet.connector;
|
|
125
|
+
}
|
|
126
|
+
if (this.activeWalletConnectorKey !== PRIMARY_CONNECTED_WALLET_KEY) {
|
|
127
|
+
throw new Error(`Signing connector not found for account "${this.activeWalletConnectorKey}".`);
|
|
128
|
+
}
|
|
129
|
+
return this.primaryConnector;
|
|
130
|
+
}
|
|
96
131
|
set provider(_) {
|
|
97
132
|
throw new Error("Not implemented");
|
|
98
133
|
}
|
|
@@ -135,9 +170,10 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
135
170
|
}
|
|
136
171
|
|
|
137
172
|
// init config
|
|
173
|
+
this.projectConfig = projectConfig;
|
|
138
174
|
this.initAccountAbstractionConfig(projectConfig);
|
|
139
175
|
this.initChainsConfig(projectConfig);
|
|
140
|
-
this.initCachedConnectorAndChainId();
|
|
176
|
+
await this.initCachedConnectorAndChainId();
|
|
141
177
|
this.initUIConfig(projectConfig);
|
|
142
178
|
this.initWalletServicesConfig(projectConfig);
|
|
143
179
|
this.initSessionTimeConfig(projectConfig);
|
|
@@ -205,12 +241,19 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
205
241
|
return true;
|
|
206
242
|
}) || null;
|
|
207
243
|
}
|
|
208
|
-
clearCache() {
|
|
209
|
-
this.
|
|
210
|
-
|
|
244
|
+
async clearCache() {
|
|
245
|
+
this.connectedWalletConnectorMap.clear();
|
|
246
|
+
this.activeWalletConnectorKey = PRIMARY_CONNECTED_WALLET_KEY;
|
|
247
|
+
this.connectionReconnected = false;
|
|
248
|
+
await this.setState({
|
|
249
|
+
primaryConnectorName: null,
|
|
211
250
|
cachedConnector: null,
|
|
212
251
|
currentChainId: null,
|
|
213
|
-
idToken: null
|
|
252
|
+
idToken: null,
|
|
253
|
+
accessToken: null,
|
|
254
|
+
refreshToken: null,
|
|
255
|
+
activeAccount: null,
|
|
256
|
+
hasUserConsent: undefined
|
|
214
257
|
});
|
|
215
258
|
}
|
|
216
259
|
async cleanup() {
|
|
@@ -223,8 +266,16 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
223
266
|
if (params.chainId === ((_this$currentChain2 = this.currentChain) === null || _this$currentChain2 === void 0 ? void 0 : _this$currentChain2.chainId)) return;
|
|
224
267
|
const newChainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
|
|
225
268
|
if (!newChainConfig) throw WalletInitializationError.invalidParams("Invalid chainId");
|
|
226
|
-
if (CONNECTED_STATUSES.includes(this.status)
|
|
227
|
-
|
|
269
|
+
if (CONNECTED_STATUSES.includes(this.status)) {
|
|
270
|
+
const activeConnector = this.activeConnector;
|
|
271
|
+
if (!activeConnector) throw WalletInitializationError.notReady("Active signing connector is not ready");
|
|
272
|
+
|
|
273
|
+
// Single-namespace connectors cannot cross namespace boundaries — MULTICHAIN connectors
|
|
274
|
+
// (Auth, WC) enforce their own switchChain policy internally.
|
|
275
|
+
if (activeConnector.connectorNamespace !== CONNECTOR_NAMESPACES.MULTICHAIN && activeConnector.connectorNamespace !== newChainConfig.chainNamespace) {
|
|
276
|
+
throw WalletLoginError.connectionError(`Cannot switch between chain namespaces with ${activeConnector.name}. Disconnect and reconnect with the target chain.`);
|
|
277
|
+
}
|
|
278
|
+
await activeConnector.switchChain(params);
|
|
228
279
|
return;
|
|
229
280
|
}
|
|
230
281
|
if (this.commonJRPCProvider) {
|
|
@@ -245,7 +296,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
245
296
|
const initialChain = this.getInitialChainIdForConnector(connector);
|
|
246
297
|
const finalLoginParams = _objectSpread(_objectSpread({}, loginParams), {}, {
|
|
247
298
|
chainId: initialChain.chainId,
|
|
248
|
-
|
|
299
|
+
getAuthTokenInfo: this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN
|
|
249
300
|
});
|
|
250
301
|
|
|
251
302
|
// track connection started event
|
|
@@ -301,27 +352,24 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
301
352
|
};
|
|
302
353
|
const checkCompletion = async () => {
|
|
303
354
|
// In CONNECT_AND_SIGN mode, wait for both connected event and authorized event
|
|
304
|
-
if (finalLoginParams.
|
|
355
|
+
if (finalLoginParams.getAuthTokenInfo) {
|
|
305
356
|
if (connectedEventCompleted && authorizedEventReceived) {
|
|
306
357
|
await completeConnection();
|
|
307
358
|
}
|
|
308
|
-
} else {
|
|
309
|
-
|
|
310
|
-
if (connectedEventCompleted) {
|
|
311
|
-
await completeConnection();
|
|
312
|
-
}
|
|
359
|
+
} else if (connectedEventCompleted) {
|
|
360
|
+
await completeConnection();
|
|
313
361
|
}
|
|
314
362
|
};
|
|
315
363
|
const completeConnection = async () => {
|
|
316
364
|
try {
|
|
317
365
|
// track connection completed event
|
|
318
|
-
const userInfo = await
|
|
366
|
+
const userInfo = await this.getUserInfo();
|
|
319
367
|
this.analytics.track(ANALYTICS_EVENTS.CONNECTION_COMPLETED, _objectSpread(_objectSpread({}, eventData), {}, {
|
|
320
368
|
is_mfa_enabled: userInfo === null || userInfo === void 0 ? void 0 : userInfo.isMfaEnabled,
|
|
321
369
|
duration: Date.now() - startTime
|
|
322
370
|
}));
|
|
323
371
|
cleanup();
|
|
324
|
-
resolve(this.
|
|
372
|
+
resolve(this.connection);
|
|
325
373
|
} catch (error) {
|
|
326
374
|
cleanup();
|
|
327
375
|
reject(error);
|
|
@@ -344,7 +392,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
344
392
|
reject(err);
|
|
345
393
|
};
|
|
346
394
|
this.once(CONNECTOR_EVENTS.CONNECTED, onConnected);
|
|
347
|
-
if (finalLoginParams.
|
|
395
|
+
if (finalLoginParams.getAuthTokenInfo) {
|
|
348
396
|
this.once(CONNECTOR_EVENTS.AUTHORIZED, onAuthorized);
|
|
349
397
|
}
|
|
350
398
|
this.once(CONNECTOR_EVENTS.ERRORED, onErrored);
|
|
@@ -355,28 +403,60 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
355
403
|
async logout(options = {
|
|
356
404
|
cleanup: false
|
|
357
405
|
}) {
|
|
358
|
-
if (!
|
|
359
|
-
if (this.
|
|
360
|
-
await this.
|
|
406
|
+
if (!CAN_LOGOUT_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
407
|
+
if (this.primaryConnector.status === CONNECTOR_STATUS.DISCONNECTING) return;
|
|
408
|
+
await this.primaryConnector.disconnect(options);
|
|
361
409
|
}
|
|
362
410
|
async getUserInfo() {
|
|
363
|
-
var _this$
|
|
364
|
-
log.debug("Getting user info", this.status, (_this$
|
|
365
|
-
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.
|
|
366
|
-
|
|
411
|
+
var _this$primaryConnecto, _userInfo$linkedAccou, _userInfo$linkedAccou2;
|
|
412
|
+
log.debug("Getting user info", this.status, (_this$primaryConnecto = this.primaryConnector) === null || _this$primaryConnecto === void 0 ? void 0 : _this$primaryConnecto.name);
|
|
413
|
+
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
414
|
+
const userInfo = await this.primaryConnector.getUserInfo();
|
|
415
|
+
const linkedAccounts = (_userInfo$linkedAccou = (_userInfo$linkedAccou2 = userInfo.linkedAccounts) === null || _userInfo$linkedAccou2 === void 0 ? void 0 : _userInfo$linkedAccou2.map(account => _objectSpread(_objectSpread({}, account), {}, {
|
|
416
|
+
active: this.state.activeAccount ? account.id === this.state.activeAccount.id : account.isPrimary
|
|
417
|
+
}))) !== null && _userInfo$linkedAccou !== void 0 ? _userInfo$linkedAccou : [];
|
|
418
|
+
this.syncConnectedWalletLinkedAccounts(linkedAccounts);
|
|
419
|
+
return _objectSpread(_objectSpread({}, userInfo), {}, {
|
|
420
|
+
linkedAccounts
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
async getLinkedAccounts() {
|
|
424
|
+
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
425
|
+
assertAuthConnector(this.primaryConnector, "Linked accounts can only be fetched when connected with the AUTH connector.");
|
|
426
|
+
const linkedAccounts = await this.primaryConnector.getLinkedAccounts();
|
|
427
|
+
const resolvedLinkedAccounts = linkedAccounts.map(account => _objectSpread(_objectSpread({}, account), {}, {
|
|
428
|
+
active: this.state.activeAccount ? account.id === this.state.activeAccount.id : account.isPrimary
|
|
429
|
+
}));
|
|
430
|
+
this.syncConnectedWalletLinkedAccounts(resolvedLinkedAccounts);
|
|
431
|
+
return resolvedLinkedAccounts;
|
|
432
|
+
}
|
|
433
|
+
getConnectedAccountsWithProviders() {
|
|
434
|
+
if (!CONNECTED_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
435
|
+
if (this.status !== CONNECTOR_STATUS.AUTHORIZED) {
|
|
436
|
+
// before the wallet is authorized, we don't have the user info, so we return an empty array
|
|
437
|
+
return [];
|
|
438
|
+
}
|
|
439
|
+
const connectedAccounts = [];
|
|
440
|
+
for (const [, value] of this.connectedWalletConnectorMap.entries()) {
|
|
441
|
+
const hasWalletProvider = Boolean(value.signingProvider || value.solanaWallet);
|
|
442
|
+
if (hasWalletProvider && this.hasUsableConnectedSwitchConnector(value.connector)) {
|
|
443
|
+
connectedAccounts.push(value);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return connectedAccounts;
|
|
367
447
|
}
|
|
368
448
|
async enableMFA(loginParams) {
|
|
369
449
|
var _authConnector$authIn2;
|
|
370
|
-
if (!CONNECTED_STATUSES.includes(this.status) || !this.
|
|
371
|
-
if (this.
|
|
372
|
-
const authConnector = this.
|
|
450
|
+
if (!CONNECTED_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
451
|
+
if (this.primaryConnector.name !== WALLET_CONNECTORS.AUTH) throw WalletLoginError.unsupportedOperation(`EnableMFA is not supported for this connector.`);
|
|
452
|
+
const authConnector = this.primaryConnector;
|
|
373
453
|
const trackData = {
|
|
374
|
-
connector: this.
|
|
454
|
+
connector: this.primaryConnector.name,
|
|
375
455
|
auth_ux_mode: (_authConnector$authIn2 = authConnector.authInstance) === null || _authConnector$authIn2 === void 0 || (_authConnector$authIn2 = _authConnector$authIn2.options) === null || _authConnector$authIn2 === void 0 ? void 0 : _authConnector$authIn2.uxMode
|
|
376
456
|
};
|
|
377
457
|
try {
|
|
378
458
|
this.analytics.track(ANALYTICS_EVENTS.MFA_ENABLEMENT_STARTED, trackData);
|
|
379
|
-
await this.
|
|
459
|
+
await this.primaryConnector.enableMFA(loginParams);
|
|
380
460
|
} catch (error) {
|
|
381
461
|
this.analytics.track(ANALYTICS_EVENTS.MFA_ENABLEMENT_FAILED, _objectSpread(_objectSpread({}, trackData), getErrorAnalyticsProperties(error)));
|
|
382
462
|
throw error;
|
|
@@ -384,31 +464,33 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
384
464
|
}
|
|
385
465
|
async manageMFA(loginParams) {
|
|
386
466
|
var _authConnector$authIn3;
|
|
387
|
-
if (!CONNECTED_STATUSES.includes(this.status) || !this.
|
|
388
|
-
if (this.
|
|
389
|
-
const authConnector = this.
|
|
467
|
+
if (!CONNECTED_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
468
|
+
if (this.primaryConnector.name !== WALLET_CONNECTORS.AUTH) throw WalletLoginError.unsupportedOperation(`ManageMFA is not supported for this connector.`);
|
|
469
|
+
const authConnector = this.primaryConnector;
|
|
390
470
|
const trackData = {
|
|
391
|
-
connector: this.
|
|
471
|
+
connector: this.primaryConnector.name,
|
|
392
472
|
auth_ux_mode: (_authConnector$authIn3 = authConnector.authInstance) === null || _authConnector$authIn3 === void 0 || (_authConnector$authIn3 = _authConnector$authIn3.options) === null || _authConnector$authIn3 === void 0 ? void 0 : _authConnector$authIn3.uxMode
|
|
393
473
|
};
|
|
394
474
|
try {
|
|
395
475
|
this.analytics.track(ANALYTICS_EVENTS.MFA_MANAGEMENT_SELECTED, trackData);
|
|
396
|
-
await this.
|
|
476
|
+
await this.primaryConnector.manageMFA(loginParams);
|
|
397
477
|
} catch (error) {
|
|
398
478
|
this.analytics.track(ANALYTICS_EVENTS.MFA_MANAGEMENT_FAILED, _objectSpread(_objectSpread({}, trackData), getErrorAnalyticsProperties(error)));
|
|
399
479
|
throw error;
|
|
400
480
|
}
|
|
401
481
|
}
|
|
402
|
-
async
|
|
403
|
-
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.
|
|
482
|
+
async getAuthTokenInfo() {
|
|
483
|
+
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.primaryConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
404
484
|
const trackData = {
|
|
405
|
-
connector: this.
|
|
485
|
+
connector: this.primaryConnector.name
|
|
406
486
|
};
|
|
407
487
|
try {
|
|
408
488
|
this.analytics.track(ANALYTICS_EVENTS.IDENTITY_TOKEN_STARTED, trackData);
|
|
409
|
-
const
|
|
489
|
+
const authTokenInfo = await this.primaryConnector.getAuthTokenInfo();
|
|
410
490
|
this.analytics.track(ANALYTICS_EVENTS.IDENTITY_TOKEN_COMPLETED, trackData);
|
|
411
|
-
return
|
|
491
|
+
return {
|
|
492
|
+
idToken: authTokenInfo.idToken
|
|
493
|
+
};
|
|
412
494
|
} catch (error) {
|
|
413
495
|
this.analytics.track(ANALYTICS_EVENTS.IDENTITY_TOKEN_FAILED, _objectSpread(_objectSpread({}, trackData), getErrorAnalyticsProperties(error)));
|
|
414
496
|
throw error;
|
|
@@ -417,10 +499,81 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
417
499
|
getPlugin(name) {
|
|
418
500
|
return this.plugins[name] || null;
|
|
419
501
|
}
|
|
502
|
+
async switchAccount(account) {
|
|
503
|
+
const authConnector = this.getMainAuthConnector();
|
|
504
|
+
const switchResult = await authConnector.switchAccount(account, {
|
|
505
|
+
activeAccount: this.state.activeAccount,
|
|
506
|
+
currentChainId: this.currentChainId
|
|
507
|
+
});
|
|
508
|
+
if (!switchResult) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
try {
|
|
512
|
+
var _this$projectConfig;
|
|
513
|
+
await this.processSwitchAccountResult(authConnector, switchResult, {
|
|
514
|
+
projectConfig: (_this$projectConfig = this.projectConfig) !== null && _this$projectConfig !== void 0 ? _this$projectConfig : undefined
|
|
515
|
+
});
|
|
516
|
+
await authConnector.trackSwitchAccountCompleted(switchResult.targetAccount);
|
|
517
|
+
} catch (error) {
|
|
518
|
+
await authConnector.trackSwitchAccountFailed(switchResult.targetAccount, error);
|
|
519
|
+
throw error;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async linkAccount(params) {
|
|
523
|
+
if (!(params !== null && params !== void 0 && params.connectorName)) {
|
|
524
|
+
throw WalletInitializationError.invalidParams("connectorName is required when calling linkAccount on the no-modal SDK");
|
|
525
|
+
}
|
|
526
|
+
const chainId = this.resolveLinkAccountChainId(params.chainId);
|
|
527
|
+
const isolatedConnector = await this.createLinkingWalletConnector(params.connectorName, chainId);
|
|
528
|
+
return this.linkAccountWithConnector(params.connectorName, chainId, isolatedConnector);
|
|
529
|
+
}
|
|
530
|
+
async unlinkAccount(address) {
|
|
531
|
+
var _await$authConnector$, _this$state$activeAcc;
|
|
532
|
+
const authConnector = this.getMainAuthConnector();
|
|
533
|
+
const linkedAccounts = (_await$authConnector$ = (await authConnector.getUserInfo()).linkedAccounts) !== null && _await$authConnector$ !== void 0 ? _await$authConnector$ : [];
|
|
534
|
+
const targetAccount = this.findLinkedAccountByAddress(linkedAccounts, address);
|
|
535
|
+
if (!targetAccount) {
|
|
536
|
+
throw AccountLinkingError.accountNotLinked(`Account with address "${address}" is not linked`);
|
|
537
|
+
}
|
|
538
|
+
if (targetAccount.connector === WALLET_CONNECTORS.AUTH || targetAccount.isPrimary) {
|
|
539
|
+
throw AccountLinkingError.cannotUnlinkPrimaryAccount();
|
|
540
|
+
}
|
|
541
|
+
if (((_this$state$activeAcc = this.state.activeAccount) === null || _this$state$activeAcc === void 0 ? void 0 : _this$state$activeAcc.id) === targetAccount.id) {
|
|
542
|
+
throw AccountLinkingError.cannotUnlinkActiveAccount();
|
|
543
|
+
}
|
|
544
|
+
const result = await authConnector.unlinkAccount({
|
|
545
|
+
address,
|
|
546
|
+
authSessionTokens: {
|
|
547
|
+
accessToken: this.accessToken,
|
|
548
|
+
idToken: this.idToken
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
await this.setState({
|
|
552
|
+
idToken: result.idToken
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
// disconnect the connector for unlinked account
|
|
556
|
+
const connectorToDisconnect = this.getConnectedWalletConnector(targetAccount);
|
|
557
|
+
if (connectorToDisconnect) {
|
|
558
|
+
try {
|
|
559
|
+
if (connectorToDisconnect.connected) {
|
|
560
|
+
await connectorToDisconnect.disconnect({
|
|
561
|
+
cleanup: true
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
} catch (error) {
|
|
565
|
+
log.debug(`Failed to disconnect linked account "${targetAccount.id}" during unlink`, error);
|
|
566
|
+
} finally {
|
|
567
|
+
this.deleteConnectedWalletConnector(targetAccount);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
420
572
|
setAnalyticsProperties(properties) {
|
|
421
573
|
this.analytics.setGlobalProperties(properties);
|
|
422
574
|
}
|
|
423
575
|
initChainsConfig(projectConfig) {
|
|
576
|
+
var _this$coreOptions$acc2;
|
|
424
577
|
// merge chains from project config with core options, core options chains will take precedence over project config chains
|
|
425
578
|
const chainMap = new Map();
|
|
426
579
|
const allChains = [...(projectConfig.chains || []), ...(this.coreOptions.chains || [])];
|
|
@@ -456,8 +609,9 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
456
609
|
}
|
|
457
610
|
}
|
|
458
611
|
|
|
459
|
-
// if AA is enabled, filter out chains that are not AA-supported
|
|
460
|
-
|
|
612
|
+
// if AA is enabled and smart account is not 7702, filter out chains that are not AA-supported
|
|
613
|
+
const is7702SmartAccount = ((_this$coreOptions$acc2 = this.coreOptions.accountAbstractionConfig) === null || _this$coreOptions$acc2 === void 0 ? void 0 : _this$coreOptions$acc2.smartAccountEipStandard) === SMART_ACCOUNT_EIP_STANDARD.EIP_7702;
|
|
614
|
+
if (this.coreOptions.accountAbstractionConfig && !is7702SmartAccount) {
|
|
461
615
|
// write a for loop over accountAbstractionConfig.chains and check if the chainId is valid
|
|
462
616
|
if (this.coreOptions.accountAbstractionConfig.chains.length === 0) {
|
|
463
617
|
log.error("Please configure chains for smart accounts on dashboard at https://dashboard.web3auth.io");
|
|
@@ -495,26 +649,39 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
495
649
|
}
|
|
496
650
|
}
|
|
497
651
|
initAccountAbstractionConfig(projectConfig) {
|
|
498
|
-
var _this$coreOptions$
|
|
652
|
+
var _this$coreOptions$acc3;
|
|
499
653
|
const isAAEnabled = Boolean(this.coreOptions.accountAbstractionConfig || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.smartAccounts));
|
|
500
654
|
if (!isAAEnabled) return;
|
|
501
655
|
|
|
502
656
|
// merge smart account config from project config with core options, core options will take precedence over project config
|
|
503
657
|
const _ref = (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.smartAccounts) || {},
|
|
504
658
|
{
|
|
505
|
-
walletScope
|
|
659
|
+
walletScope,
|
|
660
|
+
eipStandard
|
|
506
661
|
} = _ref,
|
|
507
662
|
configWithoutWalletScope = _objectWithoutProperties(_ref, _excluded);
|
|
508
663
|
const aaChainMap = new Map();
|
|
509
|
-
const allAaChains = [...((configWithoutWalletScope === null || configWithoutWalletScope === void 0 ? void 0 : configWithoutWalletScope.chains) || []), ...(((_this$coreOptions$
|
|
664
|
+
const allAaChains = [...((configWithoutWalletScope === null || configWithoutWalletScope === void 0 ? void 0 : configWithoutWalletScope.chains) || []), ...(((_this$coreOptions$acc3 = this.coreOptions.accountAbstractionConfig) === null || _this$coreOptions$acc3 === void 0 ? void 0 : _this$coreOptions$acc3.chains) || [])];
|
|
510
665
|
for (const chain of allAaChains) {
|
|
511
666
|
const existingChain = aaChainMap.get(chain.chainId);
|
|
512
667
|
if (!existingChain) aaChainMap.set(chain.chainId, chain);else aaChainMap.set(chain.chainId, _objectSpread(_objectSpread({}, existingChain), chain));
|
|
513
668
|
}
|
|
514
|
-
this.coreOptions.accountAbstractionConfig = _objectSpread(_objectSpread({
|
|
669
|
+
this.coreOptions.accountAbstractionConfig = _objectSpread(_objectSpread({
|
|
670
|
+
smartAccountEipStandard: eipStandard
|
|
671
|
+
}, deepmerge(configWithoutWalletScope || {}, this.coreOptions.accountAbstractionConfig || {})), {}, {
|
|
515
672
|
chains: Array.from(aaChainMap.values())
|
|
516
673
|
});
|
|
517
674
|
|
|
675
|
+
// if eipStandard is 7702, validate smart account type
|
|
676
|
+
const {
|
|
677
|
+
smartAccountEipStandard,
|
|
678
|
+
smartAccountType
|
|
679
|
+
} = this.coreOptions.accountAbstractionConfig;
|
|
680
|
+
const is7702SmartAccount = smartAccountEipStandard === SMART_ACCOUNT_EIP_STANDARD.EIP_7702;
|
|
681
|
+
if (is7702SmartAccount && smartAccountType && !EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES.includes(smartAccountType)) {
|
|
682
|
+
throw WalletInitializationError.invalidParams(`Smart account type "${smartAccountType}" does not support EIP-7702. Supported: ${EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES.join(", ")}`);
|
|
683
|
+
}
|
|
684
|
+
|
|
518
685
|
// determine if we should use AA with external wallet
|
|
519
686
|
if (this.coreOptions.useAAWithExternalWallet === undefined) {
|
|
520
687
|
this.coreOptions.useAAWithExternalWallet = walletScope === SMART_ACCOUNT_WALLET_SCOPE.ALL;
|
|
@@ -530,13 +697,13 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
530
697
|
if (this.coreOptions.sessionTime) return;
|
|
531
698
|
if (projectConfig.sessionTime) this.coreOptions.sessionTime = projectConfig.sessionTime;
|
|
532
699
|
}
|
|
533
|
-
initCachedConnectorAndChainId() {
|
|
700
|
+
async initCachedConnectorAndChainId() {
|
|
534
701
|
// init chainId using cached chainId if it exists and is valid, otherwise use the defaultChainId or the first chain
|
|
535
702
|
const cachedChainId = this.state.currentChainId;
|
|
536
703
|
const isCachedChainIdValid = cachedChainId && this.coreOptions.chains.some(chain => chain.chainId === cachedChainId);
|
|
537
704
|
if (this.coreOptions.defaultChainId && !isHexStrict(this.coreOptions.defaultChainId)) throw WalletInitializationError.invalidParams("Please provide a valid defaultChainId in constructor");
|
|
538
705
|
const currentChainId = isCachedChainIdValid ? cachedChainId : this.coreOptions.defaultChainId || this.coreOptions.chains[0].chainId;
|
|
539
|
-
this.setState({
|
|
706
|
+
await this.setState({
|
|
540
707
|
currentChainId
|
|
541
708
|
});
|
|
542
709
|
}
|
|
@@ -596,7 +763,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
596
763
|
default_chain_id: defaultChain ? getCaipChainId(defaultChain) : undefined,
|
|
597
764
|
default_chain_name: defaultChain === null || defaultChain === void 0 ? void 0 : defaultChain.displayName,
|
|
598
765
|
logging_enabled: this.coreOptions.enableLogging,
|
|
599
|
-
|
|
766
|
+
custom_storage: Boolean(this.coreOptions.storage),
|
|
600
767
|
session_time: this.coreOptions.sessionTime,
|
|
601
768
|
sfa_key_enabled: this.coreOptions.useSFAKey,
|
|
602
769
|
mipd_enabled: this.coreOptions.multiInjectedProviderDiscovery,
|
|
@@ -620,7 +787,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
620
787
|
});
|
|
621
788
|
|
|
622
789
|
// sync chainId
|
|
623
|
-
this.commonJRPCProvider.on("chainChanged", chainId => this.setCurrentChain(chainId));
|
|
790
|
+
this.commonJRPCProvider.on("chainChanged", async chainId => this.setCurrentChain(chainId));
|
|
624
791
|
}
|
|
625
792
|
async setupConnector(connector) {
|
|
626
793
|
this.subscribeToConnectorEvents(connector);
|
|
@@ -630,7 +797,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
630
797
|
await connector.init({
|
|
631
798
|
autoConnect,
|
|
632
799
|
chainId: initialChain.chainId,
|
|
633
|
-
|
|
800
|
+
getAuthTokenInfo: this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN
|
|
634
801
|
});
|
|
635
802
|
} catch (e) {
|
|
636
803
|
log.error(e, connector.name);
|
|
@@ -658,7 +825,9 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
658
825
|
if (isBrowser() && chainNamespaces.has(CHAIN_NAMESPACES.EIP155)) {
|
|
659
826
|
// only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
|
|
660
827
|
connectorFns.push(metaMaskConnector(modalMode ? {
|
|
661
|
-
|
|
828
|
+
ui: {
|
|
829
|
+
headless: true
|
|
830
|
+
}
|
|
662
831
|
} : undefined));
|
|
663
832
|
}
|
|
664
833
|
if (isMipdEnabled && isBrowser()) {
|
|
@@ -737,82 +906,139 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
737
906
|
}
|
|
738
907
|
subscribeToConnectorEvents(connector) {
|
|
739
908
|
connector.on(CONNECTOR_EVENTS.CONNECTED, async data => {
|
|
740
|
-
|
|
909
|
+
if (this.primaryConnectorName && this.primaryConnectorName !== data.connectorName) {
|
|
910
|
+
// Ignore registered connectors that are not the active primary session connector.
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
741
913
|
if (!this.commonJRPCProvider) throw WalletInitializationError.notFound(`CommonJrpcProvider not found`);
|
|
742
914
|
const {
|
|
743
|
-
|
|
744
|
-
|
|
915
|
+
ethereumProvider,
|
|
916
|
+
solanaWallet
|
|
745
917
|
} = data;
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
918
|
+
// Seed the primary connector synchronously so AUTHORIZED can resolve a connection
|
|
919
|
+
// even while we are still restoring a previously active linked wallet.
|
|
920
|
+
this.setConnectedWalletConnectorState(this.buildImmediateConnectedWalletConnectorState({
|
|
921
|
+
connector,
|
|
922
|
+
ethereumProvider,
|
|
923
|
+
solanaWallet,
|
|
924
|
+
usePrimaryProxy: true
|
|
925
|
+
}));
|
|
926
|
+
this.setActiveWalletConnectorKey();
|
|
927
|
+
this.connectionReconnected = data.reconnected;
|
|
928
|
+
const connectedChainId = ethereumProvider === null || ethereumProvider === void 0 ? void 0 : ethereumProvider.chainId;
|
|
751
929
|
|
|
752
930
|
// when ssr is enabled, we need to get the idToken from the connector.
|
|
753
931
|
if (this.coreOptions.ssr) {
|
|
754
932
|
try {
|
|
755
|
-
|
|
933
|
+
var _data$accessToken, _data$refreshToken;
|
|
934
|
+
const data = await connector.getAuthTokenInfo();
|
|
756
935
|
if (!data.idToken) throw WalletLoginError.connectionError("No idToken found");
|
|
757
|
-
this.setState({
|
|
758
|
-
idToken: data.idToken
|
|
936
|
+
await this.setState({
|
|
937
|
+
idToken: data.idToken,
|
|
938
|
+
accessToken: (_data$accessToken = data.accessToken) !== null && _data$accessToken !== void 0 ? _data$accessToken : null,
|
|
939
|
+
refreshToken: (_data$refreshToken = data.refreshToken) !== null && _data$refreshToken !== void 0 ? _data$refreshToken : null
|
|
759
940
|
});
|
|
760
941
|
} catch (error) {
|
|
761
942
|
log.error(error);
|
|
943
|
+
this.deleteConnectedWalletConnector();
|
|
944
|
+
this.setActiveWalletConnectorKey();
|
|
762
945
|
this.status = CONNECTOR_STATUS.ERRORED;
|
|
763
946
|
this.emit(CONNECTOR_EVENTS.ERRORED, error, this.loginMode);
|
|
764
947
|
return;
|
|
765
948
|
}
|
|
766
949
|
}
|
|
767
|
-
|
|
950
|
+
// The following block only hits during rehydration
|
|
768
951
|
|
|
769
|
-
// setup AA provider if AA is enabled
|
|
770
952
|
const {
|
|
771
|
-
|
|
772
|
-
} = this.
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
provider: eoaProvider,
|
|
789
|
-
chain: this.currentChain,
|
|
790
|
-
chains: this.coreOptions.chains.filter(chain => aaChainIds.has(chain.chainId)),
|
|
791
|
-
useProviderAsTransport: data.connector === WALLET_CONNECTORS.AUTH
|
|
792
|
-
});
|
|
793
|
-
this.aaProvider = aaProvider;
|
|
794
|
-
|
|
795
|
-
// if external wallet is used and AA is enabled for external wallets, use AA provider
|
|
796
|
-
// for embedded wallets, we use ws-embed provider which already supports AA
|
|
797
|
-
if (data.connector !== WALLET_CONNECTORS.AUTH && this.coreOptions.useAAWithExternalWallet) {
|
|
798
|
-
finalProvider = this.aaProvider;
|
|
953
|
+
activeAccount
|
|
954
|
+
} = this.state;
|
|
955
|
+
// if the active account is not the primary account, i.e. not `null`, create an isolated connector and connect to the chain
|
|
956
|
+
if (activeAccount && !activeAccount.isPrimary && activeAccount.connector !== WALLET_CONNECTORS.AUTH) {
|
|
957
|
+
var _ref3, _walletConnector$prov, _linkedAccountConnect, _ref4, _walletConnector$sola, _linkedAccountConnect2;
|
|
958
|
+
const accountLinkingConnector = isAuthConnector(connector) ? connector : this.getConnector(WALLET_CONNECTORS.AUTH);
|
|
959
|
+
assertAuthConnector(accountLinkingConnector, "Account switching requires the AUTH connector to be available.");
|
|
960
|
+
const targetChainId = accountLinkingConnector.getChainIdForLinkedAccount(activeAccount, connectedChainId);
|
|
961
|
+
const walletConnector = await this.createIsolatedWalletConnector(activeAccount.connector, targetChainId);
|
|
962
|
+
let linkedAccountConnection = null;
|
|
963
|
+
if (!this.hasUsableConnectedSwitchConnector(walletConnector)) {
|
|
964
|
+
linkedAccountConnection = await walletConnector.connect({
|
|
965
|
+
chainId: targetChainId
|
|
966
|
+
});
|
|
967
|
+
if (!linkedAccountConnection) {
|
|
968
|
+
throw AccountLinkingError.requestFailed(`Failed to connect isolated connector "${activeAccount.connector}" for account switch.`);
|
|
969
|
+
}
|
|
799
970
|
}
|
|
971
|
+
const connectedWalletState = await this.resolveConnectedWalletConnectorState({
|
|
972
|
+
connector: walletConnector,
|
|
973
|
+
ethereumProvider: (_ref3 = (_walletConnector$prov = walletConnector.provider) !== null && _walletConnector$prov !== void 0 ? _walletConnector$prov : (_linkedAccountConnect = linkedAccountConnection) === null || _linkedAccountConnect === void 0 ? void 0 : _linkedAccountConnect.ethereumProvider) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
974
|
+
solanaWallet: (_ref4 = (_walletConnector$sola = walletConnector.solanaWallet) !== null && _walletConnector$sola !== void 0 ? _walletConnector$sola : (_linkedAccountConnect2 = linkedAccountConnection) === null || _linkedAccountConnect2 === void 0 ? void 0 : _linkedAccountConnect2.solanaWallet) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
975
|
+
usePrimaryProxy: false,
|
|
976
|
+
account: activeAccount
|
|
977
|
+
});
|
|
978
|
+
this.setConnectedWalletConnectorState(connectedWalletState, activeAccount);
|
|
979
|
+
this.setActiveWalletConnectorKey(activeAccount);
|
|
800
980
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
981
|
+
if (ethereumProvider) {
|
|
982
|
+
await this.bindPrimaryEthereumSigningProxy(ethereumProvider, data.connectorName);
|
|
983
|
+
}
|
|
984
|
+
const primaryConnectedWalletState = await this.resolveConnectedWalletConnectorState({
|
|
985
|
+
connector,
|
|
986
|
+
ethereumProvider,
|
|
987
|
+
solanaWallet,
|
|
988
|
+
usePrimaryProxy: true
|
|
804
989
|
});
|
|
805
|
-
this.
|
|
806
|
-
this.
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
this.
|
|
812
|
-
|
|
813
|
-
|
|
990
|
+
this.setConnectedWalletConnectorState(primaryConnectedWalletState);
|
|
991
|
+
await this.setState({
|
|
992
|
+
primaryConnectorName: data.connectorName,
|
|
993
|
+
currentChainId: connectedChainId
|
|
994
|
+
});
|
|
995
|
+
this.cacheWallet(data.connectorName);
|
|
996
|
+
const isConnectAndSign = this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
997
|
+
if (this.consentRequired && !isConnectAndSign && !this.state.hasUserConsent) {
|
|
998
|
+
this.status = CONNECTOR_STATUS.CONSENT_REQUIRING;
|
|
999
|
+
this.emit(CONNECTOR_EVENTS.CONSENT_REQUIRING);
|
|
1000
|
+
log.debug("consent_requiring", this.status, this.primaryConnectorName);
|
|
1001
|
+
} else {
|
|
1002
|
+
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
1003
|
+
log.debug("connected", this.status, this.primaryConnectorName);
|
|
1004
|
+
this.connectToPlugins(_objectSpread(_objectSpread({}, data), {}, {
|
|
1005
|
+
connector: data.connectorName
|
|
1006
|
+
}));
|
|
1007
|
+
this.emit(CONNECTOR_EVENTS.CONNECTED, _objectSpread(_objectSpread({}, data), {}, {
|
|
1008
|
+
loginMode: this.loginMode
|
|
1009
|
+
}));
|
|
1010
|
+
}
|
|
814
1011
|
});
|
|
815
|
-
connector.on(CONNECTOR_EVENTS.DISCONNECTED, async
|
|
1012
|
+
connector.on(CONNECTOR_EVENTS.DISCONNECTED, async data => {
|
|
1013
|
+
if (this.shouldIgnoreInactiveConnectorEvent(connector, CONNECTOR_EVENTS.DISCONNECTED)) return;
|
|
1014
|
+
const disconnectedConnector = data === null || data === void 0 ? void 0 : data.connector;
|
|
1015
|
+
const {
|
|
1016
|
+
activeAccount
|
|
1017
|
+
} = this.state;
|
|
1018
|
+
if (!activeAccount || activeAccount && activeAccount.isPrimary || disconnectedConnector === WALLET_CONNECTORS.AUTH) {
|
|
1019
|
+
// If the primary session disconnects, tear down every other connected wallet connector
|
|
1020
|
+
// and clear the entire map.
|
|
1021
|
+
await Promise.all(Array.from(this.connectedWalletConnectorMap.entries()).map(async ([accountId, connectedWallet]) => {
|
|
1022
|
+
if (connectedWallet.connector === connector) {
|
|
1023
|
+
this.connectedWalletConnectorMap.delete(accountId);
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
try {
|
|
1027
|
+
if (connectedWallet.connected && connectedWallet.connector.connected) {
|
|
1028
|
+
await connectedWallet.connector.disconnect({
|
|
1029
|
+
cleanup: true
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
log.debug("Connected wallet connector disconnect on primary disconnect", error);
|
|
1034
|
+
} finally {
|
|
1035
|
+
this.connectedWalletConnectorMap.delete(accountId);
|
|
1036
|
+
}
|
|
1037
|
+
}));
|
|
1038
|
+
}
|
|
1039
|
+
this.connectedWalletConnectorMap.clear();
|
|
1040
|
+
this.activeWalletConnectorKey = PRIMARY_CONNECTED_WALLET_KEY;
|
|
1041
|
+
this.connectionReconnected = false;
|
|
816
1042
|
// re-setup commonJRPCProvider
|
|
817
1043
|
this.commonJRPCProvider.removeAllListeners();
|
|
818
1044
|
this.setupCommonJRPCProvider();
|
|
@@ -820,10 +1046,10 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
820
1046
|
// get back to ready state for rehydrating.
|
|
821
1047
|
this.status = CONNECTOR_STATUS.READY;
|
|
822
1048
|
const cachedConnector = this.state.cachedConnector;
|
|
823
|
-
if (this.
|
|
824
|
-
this.clearCache();
|
|
1049
|
+
if (this.primaryConnectorName === cachedConnector) {
|
|
1050
|
+
await this.clearCache();
|
|
825
1051
|
}
|
|
826
|
-
log.debug("disconnected", this.status, this.
|
|
1052
|
+
log.debug("disconnected", this.status, this.primaryConnectorName);
|
|
827
1053
|
await Promise.all(Object.values(this.plugins).map(async plugin => {
|
|
828
1054
|
if (!plugin.SUPPORTED_CONNECTORS.includes(connector.name)) return;
|
|
829
1055
|
if (plugin.status !== PLUGIN_STATUS.CONNECTED) return;
|
|
@@ -836,44 +1062,61 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
836
1062
|
log.error(error);
|
|
837
1063
|
});
|
|
838
1064
|
}));
|
|
839
|
-
this.setState({
|
|
840
|
-
|
|
1065
|
+
await this.setState({
|
|
1066
|
+
primaryConnectorName: null,
|
|
1067
|
+
hasUserConsent: undefined,
|
|
1068
|
+
activeAccount: null
|
|
841
1069
|
});
|
|
842
1070
|
this.emit(CONNECTOR_EVENTS.DISCONNECTED);
|
|
843
1071
|
});
|
|
844
1072
|
connector.on(CONNECTOR_EVENTS.CONNECTING, data => {
|
|
845
1073
|
this.status = CONNECTOR_STATUS.CONNECTING;
|
|
846
1074
|
this.emit(CONNECTOR_EVENTS.CONNECTING, data);
|
|
847
|
-
log.debug("connecting", this.status, this.
|
|
1075
|
+
log.debug("connecting", this.status, this.primaryConnectorName);
|
|
848
1076
|
});
|
|
849
|
-
connector.on(CONNECTOR_EVENTS.ERRORED, data => {
|
|
1077
|
+
connector.on(CONNECTOR_EVENTS.ERRORED, async data => {
|
|
1078
|
+
if (this.shouldIgnoreInactiveConnectorEvent(connector, CONNECTOR_EVENTS.ERRORED)) {
|
|
1079
|
+
log.error("Inactive connector emitted errored event", {
|
|
1080
|
+
connector: connector.name,
|
|
1081
|
+
error: data
|
|
1082
|
+
});
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
850
1085
|
this.status = CONNECTOR_STATUS.ERRORED;
|
|
851
|
-
this.clearCache();
|
|
1086
|
+
await this.clearCache();
|
|
852
1087
|
this.emit(CONNECTOR_EVENTS.ERRORED, data, this.loginMode);
|
|
853
|
-
log.debug("errored", this.status, this.
|
|
1088
|
+
log.debug("errored", this.status, this.primaryConnectorName);
|
|
854
1089
|
});
|
|
855
|
-
connector.on(CONNECTOR_EVENTS.REHYDRATION_ERROR, error => {
|
|
1090
|
+
connector.on(CONNECTOR_EVENTS.REHYDRATION_ERROR, async error => {
|
|
1091
|
+
if (this.shouldIgnoreInactiveConnectorEvent(connector, CONNECTOR_EVENTS.REHYDRATION_ERROR)) {
|
|
1092
|
+
log.error("Inactive connector emitted rehydration error", {
|
|
1093
|
+
connector: connector.name,
|
|
1094
|
+
error
|
|
1095
|
+
});
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
856
1098
|
this.status = CONNECTOR_STATUS.READY;
|
|
857
|
-
this.clearCache();
|
|
1099
|
+
await this.clearCache();
|
|
858
1100
|
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
859
1101
|
});
|
|
860
1102
|
connector.on(CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, data => {
|
|
861
1103
|
log.debug("connector data updated", data);
|
|
862
1104
|
this.emit(CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, data);
|
|
863
1105
|
});
|
|
864
|
-
connector.on(CONNECTOR_EVENTS.CACHE_CLEAR, data => {
|
|
1106
|
+
connector.on(CONNECTOR_EVENTS.CACHE_CLEAR, async data => {
|
|
1107
|
+
if (this.shouldIgnoreInactiveConnectorEvent(connector, CONNECTOR_EVENTS.CACHE_CLEAR)) return;
|
|
865
1108
|
log.debug("connector cache clear", data);
|
|
866
|
-
this.clearCache();
|
|
1109
|
+
await this.clearCache();
|
|
867
1110
|
});
|
|
868
1111
|
connector.on(CONNECTOR_EVENTS.MFA_ENABLED, isMFAEnabled => {
|
|
869
1112
|
var _authConnector$authIn4;
|
|
870
1113
|
log.debug("mfa enabled", isMFAEnabled);
|
|
871
|
-
const authConnector = this.
|
|
1114
|
+
const authConnector = this.primaryConnector;
|
|
872
1115
|
|
|
873
1116
|
// mfa_enabled event is only emitted when using "popup" ux_mode
|
|
874
1117
|
// TODO: handle mfa_enabled event when using "redirect" ux_mode
|
|
875
1118
|
this.analytics.track(ANALYTICS_EVENTS.MFA_ENABLEMENT_COMPLETED, {
|
|
876
|
-
connector: this.
|
|
1119
|
+
connector: this.primaryConnector.name,
|
|
877
1120
|
auth_ux_mode: (_authConnector$authIn4 = authConnector.authInstance) === null || _authConnector$authIn4 === void 0 || (_authConnector$authIn4 = _authConnector$authIn4.options) === null || _authConnector$authIn4 === void 0 ? void 0 : _authConnector$authIn4.uxMode,
|
|
878
1121
|
is_mfa_enabled: isMFAEnabled
|
|
879
1122
|
});
|
|
@@ -882,24 +1125,34 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
882
1125
|
connector.on(CONNECTOR_EVENTS.AUTHORIZING, data => {
|
|
883
1126
|
this.status = CONNECTOR_STATUS.AUTHORIZING;
|
|
884
1127
|
this.emit(CONNECTOR_EVENTS.AUTHORIZING, data);
|
|
885
|
-
log.debug("authorizing", this.status, this.
|
|
1128
|
+
log.debug("authorizing", this.status, this.primaryConnectorName);
|
|
886
1129
|
});
|
|
887
|
-
connector.on(CONNECTOR_EVENTS.AUTHORIZED, data => {
|
|
888
|
-
|
|
889
|
-
this.setState({
|
|
890
|
-
idToken: data.
|
|
1130
|
+
connector.on(CONNECTOR_EVENTS.AUTHORIZED, async data => {
|
|
1131
|
+
var _data$authTokenInfo$a, _data$authTokenInfo$r;
|
|
1132
|
+
await this.setState({
|
|
1133
|
+
idToken: data.authTokenInfo.idToken,
|
|
1134
|
+
accessToken: (_data$authTokenInfo$a = data.authTokenInfo.accessToken) !== null && _data$authTokenInfo$a !== void 0 ? _data$authTokenInfo$a : null,
|
|
1135
|
+
refreshToken: (_data$authTokenInfo$r = data.authTokenInfo.refreshToken) !== null && _data$authTokenInfo$r !== void 0 ? _data$authTokenInfo$r : null
|
|
891
1136
|
});
|
|
892
|
-
|
|
893
|
-
|
|
1137
|
+
// if the user has not consented yet, we will ask for consent
|
|
1138
|
+
if (this.consentRequired && this.connection && !this.state.hasUserConsent) {
|
|
1139
|
+
this.status = CONNECTOR_STATUS.CONSENT_REQUIRING;
|
|
1140
|
+
this.emit(CONNECTOR_EVENTS.CONSENT_REQUIRING);
|
|
1141
|
+
log.debug("consent_requiring", this.status, this.primaryConnectorName);
|
|
1142
|
+
} else {
|
|
1143
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
1144
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, data);
|
|
1145
|
+
log.debug("authorized", this.status, this.primaryConnectorName);
|
|
1146
|
+
}
|
|
894
1147
|
});
|
|
895
1148
|
}
|
|
896
1149
|
checkInitRequirements() {
|
|
897
1150
|
if (this.status === CONNECTOR_STATUS.READY) throw WalletInitializationError.notReady("Connector is already initialized");
|
|
898
1151
|
}
|
|
899
1152
|
checkIfAutoConnect(connector) {
|
|
900
|
-
var _this$
|
|
1153
|
+
var _this$currentChain3;
|
|
901
1154
|
let autoConnect = this.cachedConnector === connector.name;
|
|
902
|
-
if (autoConnect && (_this$
|
|
1155
|
+
if (autoConnect && (_this$currentChain3 = this.currentChain) !== null && _this$currentChain3 !== void 0 && _this$currentChain3.chainNamespace) {
|
|
903
1156
|
if (connector.connectorNamespace === CONNECTOR_NAMESPACES.MULTICHAIN) autoConnect = true;else autoConnect = connector.connectorNamespace === this.currentChain.chainNamespace;
|
|
904
1157
|
}
|
|
905
1158
|
return autoConnect;
|
|
@@ -918,27 +1171,425 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
918
1171
|
}
|
|
919
1172
|
return initialChain;
|
|
920
1173
|
}
|
|
921
|
-
|
|
922
|
-
this.
|
|
1174
|
+
async completeConsentAcceptance() {
|
|
1175
|
+
const connection = this.connection;
|
|
1176
|
+
if (!connection) {
|
|
1177
|
+
throw WalletLoginError.connectionError("Cannot accept consent: no active connection");
|
|
1178
|
+
}
|
|
1179
|
+
if (this.status !== CONNECTOR_STATUS.CONSENT_REQUIRING) {
|
|
1180
|
+
throw WalletLoginError.connectionError("Cannot accept consent: not in consent_requiring state");
|
|
1181
|
+
}
|
|
1182
|
+
await this.setState({
|
|
1183
|
+
hasUserConsent: true
|
|
1184
|
+
});
|
|
1185
|
+
const isConnectAndSign = this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
1186
|
+
if (isConnectAndSign && this.state.idToken) {
|
|
1187
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
1188
|
+
log.debug("consent accepted, authorized", this.status, this.primaryConnectorName);
|
|
1189
|
+
} else {
|
|
1190
|
+
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
1191
|
+
log.debug("consent accepted, connected", this.status, this.primaryConnectorName);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// connect to wallet-service plugin
|
|
1195
|
+
if (this.primaryConnectorName === WALLET_CONNECTORS.AUTH) {
|
|
1196
|
+
this.connectToPlugins({
|
|
1197
|
+
connector: this.primaryConnectorName
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
this.emit(CONNECTOR_EVENTS.CONSENT_ACCEPTED, {
|
|
1201
|
+
reconnected: this.connectionReconnected
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
resolveLinkAccountChainId(chainId) {
|
|
1205
|
+
const finalChainId = chainId || this.state.currentChainId;
|
|
1206
|
+
if (!finalChainId) {
|
|
1207
|
+
throw AccountLinkingError.walletProofFailed("No chainId is available. Please specify chainId in LinkAccountParams or ensure the SDK has an active chain.");
|
|
1208
|
+
}
|
|
1209
|
+
return finalChainId;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Resolves the chain ID for a switch account operation.
|
|
1214
|
+
* If the account's chain namespace is the same as the current chain namespace, return the current chain ID.
|
|
1215
|
+
* If the account's chain namespace is different from the current chain namespace, return the chainId the account was linked in.
|
|
1216
|
+
*
|
|
1217
|
+
* @param account - The account to switch to.
|
|
1218
|
+
* @param activeChainId - The current active chain ID.
|
|
1219
|
+
* @returns The resolved chain ID.
|
|
1220
|
+
*/
|
|
1221
|
+
resolveSwitchAccountChainId(account, activeChainId) {
|
|
1222
|
+
const targetChainNamespace = account.chainNamespace ? parseChainNamespaceFromCitadelResponse(account.chainNamespace) : null;
|
|
1223
|
+
if (targetChainNamespace && this.currentChain.chainNamespace === targetChainNamespace) {
|
|
1224
|
+
return this.currentChain.chainId;
|
|
1225
|
+
}
|
|
1226
|
+
return activeChainId;
|
|
1227
|
+
}
|
|
1228
|
+
async createLinkingWalletConnector(connectorName, chainId, config) {
|
|
1229
|
+
return this.createIsolatedWalletConnector(connectorName, chainId, config);
|
|
1230
|
+
}
|
|
1231
|
+
async createSwitchingWalletConnector(connectorName, chainId, config) {
|
|
1232
|
+
return this.createIsolatedWalletConnector(connectorName, chainId, config);
|
|
1233
|
+
}
|
|
1234
|
+
getConnectedWalletConnector(account) {
|
|
1235
|
+
var _this$getConnectedWal, _this$getConnectedWal2;
|
|
1236
|
+
return (_this$getConnectedWal = (_this$getConnectedWal2 = this.getConnectedWalletConnectorState(account)) === null || _this$getConnectedWal2 === void 0 ? void 0 : _this$getConnectedWal2.connector) !== null && _this$getConnectedWal !== void 0 ? _this$getConnectedWal : null;
|
|
1237
|
+
}
|
|
1238
|
+
getConnectedWalletConnectorState(account) {
|
|
1239
|
+
return this.getConnectedWalletConnectorStateByKey(this.getConnectedWalletConnectorKey(account));
|
|
1240
|
+
}
|
|
1241
|
+
setConnectedWalletConnectorState(connectedWallet, account) {
|
|
1242
|
+
this.connectedWalletConnectorMap.set(this.getConnectedWalletConnectorKey(account), connectedWallet);
|
|
1243
|
+
}
|
|
1244
|
+
setConnectedWalletConnector(connector, account) {
|
|
1245
|
+
var _connector$solanaWall;
|
|
1246
|
+
this.setConnectedWalletConnectorState(_objectSpread(_objectSpread({}, this.getConnectedWalletLinkedAccountInfo(account)), {}, {
|
|
1247
|
+
connector,
|
|
1248
|
+
signingProvider: connector.provider,
|
|
1249
|
+
solanaWallet: (_connector$solanaWall = connector.solanaWallet) !== null && _connector$solanaWall !== void 0 ? _connector$solanaWall : null,
|
|
1250
|
+
connected: connector.connected || connector.status === CONNECTOR_STATUS.CONNECTED
|
|
1251
|
+
}), account);
|
|
1252
|
+
}
|
|
1253
|
+
deleteConnectedWalletConnector(account) {
|
|
1254
|
+
this.connectedWalletConnectorMap.delete(this.getConnectedWalletConnectorKey(account));
|
|
1255
|
+
}
|
|
1256
|
+
getConnectedWalletConnection(account) {
|
|
1257
|
+
return this.getConnectedWalletConnectionByKey(this.getConnectedWalletConnectorKey(account));
|
|
1258
|
+
}
|
|
1259
|
+
hasUsableConnectedSwitchConnector(connector) {
|
|
1260
|
+
if (!connector) return false;
|
|
1261
|
+
const isConnected = connector.connected || connector.status === CONNECTOR_STATUS.CONNECTED;
|
|
1262
|
+
return Boolean(isConnected && (connector.provider || connector.solanaWallet));
|
|
1263
|
+
}
|
|
1264
|
+
setActiveWalletConnectorKey(account) {
|
|
1265
|
+
this.activeWalletConnectorKey = this.getConnectedWalletConnectorKey(account);
|
|
1266
|
+
}
|
|
1267
|
+
getConnectedWalletConnectorKey(account) {
|
|
1268
|
+
return !account || account.isPrimary ? PRIMARY_CONNECTED_WALLET_KEY : account.id;
|
|
1269
|
+
}
|
|
1270
|
+
getConnectedWalletConnectorStateByKey(accountKey) {
|
|
1271
|
+
var _this$connectedWallet;
|
|
1272
|
+
return (_this$connectedWallet = this.connectedWalletConnectorMap.get(accountKey)) !== null && _this$connectedWallet !== void 0 ? _this$connectedWallet : null;
|
|
1273
|
+
}
|
|
1274
|
+
isLinkedAccountInfo(account) {
|
|
1275
|
+
return Boolean(account && "connector" in account);
|
|
1276
|
+
}
|
|
1277
|
+
toConnectedWalletLinkedAccountInfo(account) {
|
|
1278
|
+
return {
|
|
1279
|
+
id: account.id,
|
|
1280
|
+
isPrimary: account.isPrimary,
|
|
1281
|
+
eoaAddress: account.eoaAddress,
|
|
1282
|
+
aaAddress: account.aaAddress,
|
|
1283
|
+
aaProvider: account.aaProvider,
|
|
1284
|
+
active: account.active,
|
|
1285
|
+
accountType: account.accountType,
|
|
1286
|
+
address: account.address,
|
|
1287
|
+
authConnectionId: account.authConnectionId,
|
|
1288
|
+
groupedAuthConnectionId: account.groupedAuthConnectionId,
|
|
1289
|
+
chainNamespace: account.chainNamespace
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
getConnectedWalletLinkedAccountInfo(account) {
|
|
1293
|
+
const existingConnectedWallet = this.getConnectedWalletConnectorState(account);
|
|
1294
|
+
const resolvedAccount = this.isLinkedAccountInfo(account) ? account : existingConnectedWallet;
|
|
1295
|
+
if (resolvedAccount) {
|
|
1296
|
+
return this.toConnectedWalletLinkedAccountInfo(resolvedAccount);
|
|
1297
|
+
}
|
|
1298
|
+
const isPrimaryAccount = !account || account.isPrimary;
|
|
1299
|
+
const accountId = account && !account.isPrimary ? account.id : PRIMARY_CONNECTED_WALLET_KEY;
|
|
1300
|
+
return {
|
|
1301
|
+
id: accountId,
|
|
1302
|
+
isPrimary: isPrimaryAccount,
|
|
1303
|
+
eoaAddress: "",
|
|
1304
|
+
aaAddress: undefined,
|
|
1305
|
+
aaProvider: undefined,
|
|
1306
|
+
active: this.state.activeAccount ? this.state.activeAccount.id === accountId : isPrimaryAccount,
|
|
1307
|
+
accountType: "",
|
|
1308
|
+
address: null,
|
|
1309
|
+
authConnectionId: null,
|
|
1310
|
+
groupedAuthConnectionId: null,
|
|
1311
|
+
chainNamespace: null
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
syncConnectedWalletLinkedAccounts(linkedAccounts) {
|
|
1315
|
+
for (const linkedAccount of linkedAccounts) {
|
|
1316
|
+
const accountKey = this.getConnectedWalletConnectorKey(linkedAccount);
|
|
1317
|
+
const connectedWallet = this.connectedWalletConnectorMap.get(accountKey);
|
|
1318
|
+
if (!connectedWallet) {
|
|
1319
|
+
continue;
|
|
1320
|
+
}
|
|
1321
|
+
this.connectedWalletConnectorMap.set(accountKey, _objectSpread(_objectSpread({}, connectedWallet), this.toConnectedWalletLinkedAccountInfo(linkedAccount)));
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
refreshConnectedWalletActiveStates(activeAccount) {
|
|
1325
|
+
for (const [accountKey, connectedWallet] of this.connectedWalletConnectorMap.entries()) {
|
|
1326
|
+
const isPrimaryAccount = accountKey === PRIMARY_CONNECTED_WALLET_KEY || connectedWallet.isPrimary;
|
|
1327
|
+
this.connectedWalletConnectorMap.set(accountKey, _objectSpread(_objectSpread({}, connectedWallet), {}, {
|
|
1328
|
+
active: activeAccount ? connectedWallet.id === activeAccount.id : isPrimaryAccount
|
|
1329
|
+
}));
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
getConnectedWalletConnectionByKey(accountKey) {
|
|
1333
|
+
const connectedWallet = this.getConnectedWalletConnectorStateByKey(accountKey);
|
|
1334
|
+
if (!connectedWallet) {
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
if (!connectedWallet.signingProvider && !connectedWallet.solanaWallet) {
|
|
1338
|
+
throw new Error(`Connected connector "${connectedWallet.connector.name}" is not ready.`);
|
|
1339
|
+
}
|
|
1340
|
+
return this.buildConnectionFromConnectedWalletConnectorState(connectedWallet);
|
|
1341
|
+
}
|
|
1342
|
+
buildConnectionFromConnectedWalletConnectorState(connectedWallet) {
|
|
1343
|
+
var _connectedWallet$sola;
|
|
1344
|
+
return {
|
|
1345
|
+
ethereumProvider: connectedWallet.signingProvider,
|
|
1346
|
+
solanaWallet: (_connectedWallet$sola = connectedWallet.solanaWallet) !== null && _connectedWallet$sola !== void 0 ? _connectedWallet$sola : null,
|
|
1347
|
+
connectorName: connectedWallet.connector.name
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
buildImmediateConnectedWalletConnectorState(params) {
|
|
1351
|
+
var _this$commonJRPCProvi;
|
|
1352
|
+
const {
|
|
1353
|
+
connector,
|
|
1354
|
+
ethereumProvider,
|
|
1355
|
+
solanaWallet,
|
|
1356
|
+
usePrimaryProxy,
|
|
1357
|
+
account
|
|
1358
|
+
} = params;
|
|
1359
|
+
const isSolanaOnly = connector.connectorNamespace === CHAIN_NAMESPACES.SOLANA;
|
|
1360
|
+
const connectedWallet = _objectSpread(_objectSpread({}, this.getConnectedWalletLinkedAccountInfo(account)), {}, {
|
|
1361
|
+
connector,
|
|
1362
|
+
signingProvider: isSolanaOnly ? null : ethereumProvider ? usePrimaryProxy ? (_this$commonJRPCProvi = this.commonJRPCProvider) !== null && _this$commonJRPCProvi !== void 0 ? _this$commonJRPCProvi : ethereumProvider : ethereumProvider : null,
|
|
1363
|
+
solanaWallet: solanaWallet !== null && solanaWallet !== void 0 ? solanaWallet : null,
|
|
1364
|
+
connected: connector.connected || connector.status === CONNECTOR_STATUS.CONNECTED || connector.status === CONNECTOR_STATUS.AUTHORIZED
|
|
1365
|
+
});
|
|
1366
|
+
return connectedWallet;
|
|
1367
|
+
}
|
|
1368
|
+
async resolveConnectedWalletConnectorState(params) {
|
|
1369
|
+
const {
|
|
1370
|
+
connector,
|
|
1371
|
+
ethereumProvider,
|
|
1372
|
+
solanaWallet,
|
|
1373
|
+
usePrimaryProxy,
|
|
1374
|
+
account
|
|
1375
|
+
} = params;
|
|
1376
|
+
return this.buildImmediateConnectedWalletConnectorState({
|
|
1377
|
+
connector,
|
|
1378
|
+
ethereumProvider,
|
|
1379
|
+
solanaWallet,
|
|
1380
|
+
usePrimaryProxy,
|
|
1381
|
+
account
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
async linkAccountWithConnector(connectorName, chainId, walletConnector) {
|
|
1385
|
+
const authConnector = this.getMainAuthConnector();
|
|
1386
|
+
const result = await authConnector.linkAccount({
|
|
1387
|
+
connectorName,
|
|
1388
|
+
chainId,
|
|
1389
|
+
walletConnector,
|
|
1390
|
+
authSessionTokens: {
|
|
1391
|
+
accessToken: this.accessToken,
|
|
1392
|
+
idToken: this.idToken
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
await this.setState({
|
|
1396
|
+
idToken: result.idToken
|
|
1397
|
+
});
|
|
1398
|
+
await this.cacheConnectedLinkedWalletConnector(authConnector, walletConnector);
|
|
1399
|
+
return result;
|
|
1400
|
+
}
|
|
1401
|
+
getMainAuthConnector() {
|
|
1402
|
+
if (!CONNECTED_STATUSES.includes(this.status) || !this.primaryConnector) {
|
|
1403
|
+
throw WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before unlinking an account.");
|
|
1404
|
+
}
|
|
1405
|
+
const mainConnector = this.primaryConnector;
|
|
1406
|
+
assertAuthConnector(mainConnector, "Account linking is only supported when connected with the AUTH connector.");
|
|
1407
|
+
return mainConnector;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Processes the result of a switch account operation.
|
|
1412
|
+
*
|
|
1413
|
+
* - If the target account is a primary account, we will switch back to the primary account.
|
|
1414
|
+
* - If the target account is an external account and already connected (i.e. connector is available with connected state), we will just switch to it without re-connecting again.
|
|
1415
|
+
* - If the target account is an external account and not connected (i.e. connector is not available with connected state), we will create a new isolated connector and connect to it.
|
|
1416
|
+
* @param authConnector - The main auth connector to use.
|
|
1417
|
+
* @param switchResult - The result of the switch account operation.
|
|
1418
|
+
* @param options - The options for the switch account operation.
|
|
1419
|
+
* @returns A promise that resolves when the switch account operation is complete.
|
|
1420
|
+
*/
|
|
1421
|
+
async processSwitchAccountResult(authConnector, switchResult, options = {}) {
|
|
1422
|
+
const resolvedSwitchChainId = this.resolveSwitchAccountChainId(switchResult.targetAccount, switchResult.activeChainId);
|
|
1423
|
+
if (switchResult.kind === "primary") {
|
|
1424
|
+
var _primaryConnectedWall, _this$commonJRPCProvi2, _switchResult$solanaW;
|
|
1425
|
+
const existingPrimaryConnectedWalletState = this.getConnectedWalletConnectorState();
|
|
1426
|
+
const primaryConnectedWalletState = existingPrimaryConnectedWalletState !== null && existingPrimaryConnectedWalletState !== void 0 ? existingPrimaryConnectedWalletState : await this.resolveConnectedWalletConnectorState({
|
|
1427
|
+
connector: authConnector,
|
|
1428
|
+
ethereumProvider: switchResult.ethereumProvider,
|
|
1429
|
+
solanaWallet: switchResult.solanaWallet,
|
|
1430
|
+
usePrimaryProxy: true,
|
|
1431
|
+
account: switchResult.targetAccount
|
|
1432
|
+
});
|
|
1433
|
+
this.setConnectedWalletConnectorState(_objectSpread(_objectSpread({}, primaryConnectedWalletState), {}, {
|
|
1434
|
+
connector: authConnector,
|
|
1435
|
+
signingProvider: (_primaryConnectedWall = primaryConnectedWalletState.signingProvider) !== null && _primaryConnectedWall !== void 0 ? _primaryConnectedWall : switchResult.ethereumProvider ? (_this$commonJRPCProvi2 = this.commonJRPCProvider) !== null && _this$commonJRPCProvi2 !== void 0 ? _this$commonJRPCProvi2 : switchResult.ethereumProvider : null,
|
|
1436
|
+
solanaWallet: (_switchResult$solanaW = switchResult.solanaWallet) !== null && _switchResult$solanaW !== void 0 ? _switchResult$solanaW : primaryConnectedWalletState.solanaWallet,
|
|
1437
|
+
connected: authConnector.connected || authConnector.status === CONNECTOR_STATUS.CONNECTED
|
|
1438
|
+
}));
|
|
1439
|
+
this.setActiveWalletConnectorKey();
|
|
1440
|
+
} else {
|
|
1441
|
+
var _ref5, _options$walletConnec;
|
|
1442
|
+
const walletConnector = (_ref5 = (_options$walletConnec = options.walletConnector) !== null && _options$walletConnec !== void 0 ? _options$walletConnec : this.getConnectedWalletConnector(switchResult.targetAccount)) !== null && _ref5 !== void 0 ? _ref5 : await this.createSwitchingWalletConnector(switchResult.targetAccount.connector, resolvedSwitchChainId, options.projectConfig);
|
|
1443
|
+
let linkedAccountConnection = null;
|
|
1444
|
+
try {
|
|
1445
|
+
var _ref6, _walletConnector$prov2, _linkedAccountConnect3, _ref7, _walletConnector$sola2, _linkedAccountConnect4;
|
|
1446
|
+
if (!this.hasUsableConnectedSwitchConnector(walletConnector)) {
|
|
1447
|
+
const switchChainConfig = this.coreOptions.chains.find(c => c.chainId === resolvedSwitchChainId);
|
|
1448
|
+
if (!switchChainConfig) {
|
|
1449
|
+
throw WalletLoginError.connectionError(`Chain config is not available for chain ${resolvedSwitchChainId}`);
|
|
1450
|
+
}
|
|
1451
|
+
const caipChainId = getCaipChainId(switchChainConfig);
|
|
1452
|
+
const caipAccountId = `${caipChainId}:${switchResult.targetAccount.eoaAddress}`;
|
|
1453
|
+
linkedAccountConnection = await walletConnector.connect({
|
|
1454
|
+
chainId: resolvedSwitchChainId,
|
|
1455
|
+
caipAccountIds: [caipAccountId]
|
|
1456
|
+
});
|
|
1457
|
+
if (!linkedAccountConnection) {
|
|
1458
|
+
throw AccountLinkingError.requestFailed(`Failed to connect isolated connector "${switchResult.targetAccount.connector}" for account switch.`);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
await authConnector.assertSwitchAccountConnectorMatchesTarget(walletConnector, switchResult.targetAccount);
|
|
1462
|
+
const connectedWalletState = await this.resolveConnectedWalletConnectorState({
|
|
1463
|
+
connector: walletConnector,
|
|
1464
|
+
ethereumProvider: (_ref6 = (_walletConnector$prov2 = walletConnector.provider) !== null && _walletConnector$prov2 !== void 0 ? _walletConnector$prov2 : (_linkedAccountConnect3 = linkedAccountConnection) === null || _linkedAccountConnect3 === void 0 ? void 0 : _linkedAccountConnect3.ethereumProvider) !== null && _ref6 !== void 0 ? _ref6 : null,
|
|
1465
|
+
solanaWallet: (_ref7 = (_walletConnector$sola2 = walletConnector.solanaWallet) !== null && _walletConnector$sola2 !== void 0 ? _walletConnector$sola2 : (_linkedAccountConnect4 = linkedAccountConnection) === null || _linkedAccountConnect4 === void 0 ? void 0 : _linkedAccountConnect4.solanaWallet) !== null && _ref7 !== void 0 ? _ref7 : null,
|
|
1466
|
+
usePrimaryProxy: false,
|
|
1467
|
+
account: switchResult.targetAccount
|
|
1468
|
+
});
|
|
1469
|
+
this.setConnectedWalletConnectorState(connectedWalletState, switchResult.targetAccount);
|
|
1470
|
+
this.setActiveWalletConnectorKey(switchResult.targetAccount);
|
|
1471
|
+
} catch (error) {
|
|
1472
|
+
throw authConnector.toSwitchAccountConnectorError(switchResult.targetAccount, error);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
await this.setCurrentChain(resolvedSwitchChainId);
|
|
1476
|
+
await this.setState({
|
|
1477
|
+
activeAccount: switchResult.activeAccount
|
|
1478
|
+
});
|
|
1479
|
+
this.syncConnectedWalletLinkedAccounts([switchResult.targetAccount]);
|
|
1480
|
+
this.refreshConnectedWalletActiveStates(switchResult.activeAccount);
|
|
1481
|
+
const connection = this.connection;
|
|
1482
|
+
if (!connection) {
|
|
1483
|
+
throw WalletLoginError.connectionError("Failed to resolve the active connection after switching accounts.");
|
|
1484
|
+
}
|
|
1485
|
+
this.emit(CONNECTOR_EVENTS.CONNECTION_UPDATED, {
|
|
1486
|
+
ethereumProvider: connection.ethereumProvider,
|
|
1487
|
+
solanaWallet: connection.solanaWallet,
|
|
1488
|
+
connectorName: connection.connectorName
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
isActiveConnectorEventSource(connector) {
|
|
1492
|
+
if (!this.primaryConnectorName) return true;
|
|
1493
|
+
const activeConnector = this.primaryConnector;
|
|
1494
|
+
if (activeConnector) return activeConnector === connector;
|
|
1495
|
+
return connector.name === this.primaryConnectorName;
|
|
1496
|
+
}
|
|
1497
|
+
shouldIgnoreInactiveConnectorEvent(connector, event) {
|
|
1498
|
+
if (this.isActiveConnectorEventSource(connector)) return false;
|
|
1499
|
+
log.debug("Ignoring connector lifecycle event from inactive connector", {
|
|
1500
|
+
event,
|
|
1501
|
+
sourceConnector: connector.name,
|
|
1502
|
+
activeConnector: this.primaryConnectorName
|
|
1503
|
+
});
|
|
1504
|
+
return true;
|
|
1505
|
+
}
|
|
1506
|
+
findLinkedAccountByAddress(linkedAccounts, address) {
|
|
1507
|
+
var _linkedAccounts$find;
|
|
1508
|
+
const normalizedAddress = address.toLowerCase();
|
|
1509
|
+
return (_linkedAccounts$find = linkedAccounts.find(account => {
|
|
1510
|
+
var _account$address, _account$eoaAddress;
|
|
1511
|
+
if (!account.chainNamespace || parseChainNamespaceFromCitadelResponse(account.chainNamespace) !== CHAIN_NAMESPACES.EIP155) {
|
|
1512
|
+
return false;
|
|
1513
|
+
}
|
|
1514
|
+
return ((_account$address = account.address) === null || _account$address === void 0 ? void 0 : _account$address.toLowerCase()) === normalizedAddress || ((_account$eoaAddress = account.eoaAddress) === null || _account$eoaAddress === void 0 ? void 0 : _account$eoaAddress.toLowerCase()) === normalizedAddress;
|
|
1515
|
+
})) !== null && _linkedAccounts$find !== void 0 ? _linkedAccounts$find : null;
|
|
1516
|
+
}
|
|
1517
|
+
findLinkedAccountByWalletAddress(linkedAccounts, address) {
|
|
1518
|
+
var _linkedAccounts$find2;
|
|
1519
|
+
return (_linkedAccounts$find2 = linkedAccounts.find(account => {
|
|
1520
|
+
if (!account.chainNamespace) {
|
|
1521
|
+
return false;
|
|
1522
|
+
}
|
|
1523
|
+
const chainNamespace = parseChainNamespaceFromCitadelResponse(account.chainNamespace);
|
|
1524
|
+
if (chainNamespace === CHAIN_NAMESPACES.EIP155) {
|
|
1525
|
+
var _account$address2, _account$eoaAddress2;
|
|
1526
|
+
const normalizedAddress = address.toLowerCase();
|
|
1527
|
+
return ((_account$address2 = account.address) === null || _account$address2 === void 0 ? void 0 : _account$address2.toLowerCase()) === normalizedAddress || ((_account$eoaAddress2 = account.eoaAddress) === null || _account$eoaAddress2 === void 0 ? void 0 : _account$eoaAddress2.toLowerCase()) === normalizedAddress;
|
|
1528
|
+
}
|
|
1529
|
+
if (chainNamespace === CHAIN_NAMESPACES.SOLANA) {
|
|
1530
|
+
return account.address === address || account.eoaAddress === address;
|
|
1531
|
+
}
|
|
1532
|
+
return false;
|
|
1533
|
+
})) !== null && _linkedAccounts$find2 !== void 0 ? _linkedAccounts$find2 : null;
|
|
1534
|
+
}
|
|
1535
|
+
async getConnectedWalletAddress(connector) {
|
|
1536
|
+
var _connector$solanaWall2, _accounts$;
|
|
1537
|
+
const solanaAddress = (_connector$solanaWall2 = connector.solanaWallet) === null || _connector$solanaWall2 === void 0 || (_connector$solanaWall2 = _connector$solanaWall2.accounts) === null || _connector$solanaWall2 === void 0 || (_connector$solanaWall2 = _connector$solanaWall2[0]) === null || _connector$solanaWall2 === void 0 ? void 0 : _connector$solanaWall2.address;
|
|
1538
|
+
if (solanaAddress) {
|
|
1539
|
+
return solanaAddress;
|
|
1540
|
+
}
|
|
1541
|
+
if (!connector.provider) {
|
|
1542
|
+
return null;
|
|
1543
|
+
}
|
|
1544
|
+
const accounts = await connector.provider.request({
|
|
1545
|
+
method: "eth_accounts"
|
|
1546
|
+
});
|
|
1547
|
+
return (_accounts$ = accounts === null || accounts === void 0 ? void 0 : accounts[0]) !== null && _accounts$ !== void 0 ? _accounts$ : null;
|
|
1548
|
+
}
|
|
1549
|
+
async cacheConnectedLinkedWalletConnector(authConnector, walletConnector) {
|
|
1550
|
+
try {
|
|
1551
|
+
var _await$authConnector$2;
|
|
1552
|
+
const connectedWalletAddress = await this.getConnectedWalletAddress(walletConnector);
|
|
1553
|
+
if (!connectedWalletAddress) {
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
const linkedAccounts = (_await$authConnector$2 = await authConnector.getLinkedAccounts()) !== null && _await$authConnector$2 !== void 0 ? _await$authConnector$2 : [];
|
|
1557
|
+
const linkedAccount = this.findLinkedAccountByWalletAddress(linkedAccounts, connectedWalletAddress);
|
|
1558
|
+
if (linkedAccount && !linkedAccount.isPrimary) {
|
|
1559
|
+
const connectedWalletState = await this.resolveConnectedWalletConnectorState({
|
|
1560
|
+
connector: walletConnector,
|
|
1561
|
+
ethereumProvider: walletConnector.provider,
|
|
1562
|
+
solanaWallet: walletConnector.solanaWallet,
|
|
1563
|
+
usePrimaryProxy: false,
|
|
1564
|
+
account: linkedAccount
|
|
1565
|
+
});
|
|
1566
|
+
this.setConnectedWalletConnectorState(connectedWalletState, linkedAccount);
|
|
1567
|
+
}
|
|
1568
|
+
} catch (error) {
|
|
1569
|
+
log.debug("Failed to cache connected linked wallet connector", error);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
async cacheWallet(walletName) {
|
|
1573
|
+
await this.setState({
|
|
923
1574
|
cachedConnector: walletName
|
|
924
1575
|
});
|
|
925
1576
|
}
|
|
926
|
-
setCurrentChain(chainId) {
|
|
1577
|
+
async setCurrentChain(chainId) {
|
|
927
1578
|
if (chainId === this.currentChainId) return;
|
|
928
1579
|
const newChain = this.coreOptions.chains.find(chain => chain.chainId === chainId);
|
|
929
1580
|
if (!newChain) throw WalletInitializationError.invalidParams(`Invalid chainId: ${chainId}`);
|
|
930
|
-
this.setState({
|
|
1581
|
+
await this.setState({
|
|
931
1582
|
currentChainId: chainId
|
|
932
1583
|
});
|
|
933
1584
|
}
|
|
934
1585
|
connectToPlugins(data) {
|
|
935
1586
|
Object.values(this.plugins).map(async plugin => {
|
|
936
1587
|
try {
|
|
937
|
-
var _this$
|
|
1588
|
+
var _this$currentChain4;
|
|
938
1589
|
// skip if it's not compatible with the connector
|
|
939
1590
|
if (!plugin.SUPPORTED_CONNECTORS.includes(data.connector)) return;
|
|
940
1591
|
// skip if it's not compatible with the current chain
|
|
941
|
-
if (plugin.pluginNamespace !== PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== ((_this$
|
|
1592
|
+
if (plugin.pluginNamespace !== PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== ((_this$currentChain4 = this.currentChain) === null || _this$currentChain4 === void 0 ? void 0 : _this$currentChain4.chainNamespace)) return;
|
|
942
1593
|
// skip if it's already connected
|
|
943
1594
|
if (plugin.status === PLUGIN_STATUS.CONNECTED) return;
|
|
944
1595
|
await plugin.initWithWeb3Auth(this, this.coreOptions.uiConfig, this.analytics);
|
|
@@ -952,27 +1603,174 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
952
1603
|
}
|
|
953
1604
|
});
|
|
954
1605
|
}
|
|
955
|
-
|
|
1606
|
+
async bindPrimaryEthereumSigningProxy(ethereumProvider, connectorName) {
|
|
1607
|
+
var _this$currentChain5, _accountAbstractionCo;
|
|
1608
|
+
if (!this.commonJRPCProvider) throw WalletInitializationError.notFound(`CommonJrpcProvider not found`);
|
|
1609
|
+
let finalProvider = (ethereumProvider === null || ethereumProvider === void 0 ? void 0 : ethereumProvider.provider) || ethereumProvider;
|
|
1610
|
+
const {
|
|
1611
|
+
accountAbstractionConfig
|
|
1612
|
+
} = this.coreOptions;
|
|
1613
|
+
const is7702 = (accountAbstractionConfig === null || accountAbstractionConfig === void 0 ? void 0 : accountAbstractionConfig.smartAccountEipStandard) === SMART_ACCOUNT_EIP_STANDARD["EIP_7702"];
|
|
1614
|
+
const isAaSupportedForCurrentChain = ((_this$currentChain5 = this.currentChain) === null || _this$currentChain5 === void 0 ? void 0 : _this$currentChain5.chainNamespace) === CHAIN_NAMESPACES.EIP155 && (accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo = accountAbstractionConfig.chains) === null || _accountAbstractionCo === void 0 ? void 0 : _accountAbstractionCo.some(chain => {
|
|
1615
|
+
var _this$currentChain6;
|
|
1616
|
+
return chain.chainId === ((_this$currentChain6 = this.currentChain) === null || _this$currentChain6 === void 0 ? void 0 : _this$currentChain6.chainId);
|
|
1617
|
+
}));
|
|
1618
|
+
|
|
1619
|
+
// setup AA provider if AA is enabled (skip for EIP-7702; 7702 uses EOA + 5792/7702 RPC only)
|
|
1620
|
+
if (!is7702 && isAaSupportedForCurrentChain && (connectorName === WALLET_CONNECTORS.AUTH || this.coreOptions.useAAWithExternalWallet)) {
|
|
1621
|
+
var _accountAbstractionCo2;
|
|
1622
|
+
const {
|
|
1623
|
+
accountAbstractionProvider,
|
|
1624
|
+
toEoaProvider
|
|
1625
|
+
} = await import('./providers/account-abstraction-provider/index.js');
|
|
1626
|
+
const eoaProvider = connectorName === WALLET_CONNECTORS.AUTH ? await toEoaProvider(ethereumProvider) : ethereumProvider;
|
|
1627
|
+
const aaChainIds = new Set((accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo2 = accountAbstractionConfig.chains) === null || _accountAbstractionCo2 === void 0 ? void 0 : _accountAbstractionCo2.map(chain => chain.chainId)) || []);
|
|
1628
|
+
const aaProvider = await accountAbstractionProvider({
|
|
1629
|
+
accountAbstractionConfig,
|
|
1630
|
+
provider: eoaProvider,
|
|
1631
|
+
chain: this.currentChain,
|
|
1632
|
+
chains: this.coreOptions.chains.filter(chain => aaChainIds.has(chain.chainId)),
|
|
1633
|
+
useProviderAsTransport: connectorName === WALLET_CONNECTORS.AUTH
|
|
1634
|
+
});
|
|
1635
|
+
this.aaProvider = aaProvider;
|
|
1636
|
+
if (connectorName !== WALLET_CONNECTORS.AUTH && this.coreOptions.useAAWithExternalWallet) {
|
|
1637
|
+
finalProvider = this.aaProvider;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
this.commonJRPCProvider.updateProviderEngineProxy(finalProvider);
|
|
1641
|
+
}
|
|
1642
|
+
getChainConfigForIsolatedConnector(chainId) {
|
|
1643
|
+
const chainConfig = this.coreOptions.chains.find(chain => chain.chainId === chainId);
|
|
1644
|
+
if (!chainConfig) {
|
|
1645
|
+
throw WalletInitializationError.invalidParams(`Chain config is not available for chain ${chainId}`);
|
|
1646
|
+
}
|
|
1647
|
+
return chainConfig;
|
|
1648
|
+
}
|
|
1649
|
+
async resolveInstalledDiscoveredWalletConnector(params) {
|
|
1650
|
+
const {
|
|
1651
|
+
connectorName,
|
|
1652
|
+
chainConfig,
|
|
1653
|
+
config,
|
|
1654
|
+
isMipdEnabled
|
|
1655
|
+
} = params;
|
|
1656
|
+
if (!isBrowser() || !isMipdEnabled) return null;
|
|
1657
|
+
if (chainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155) {
|
|
1658
|
+
const {
|
|
1659
|
+
createMipd,
|
|
1660
|
+
injectedEvmConnector
|
|
1661
|
+
} = await import('./connectors/injected-evm-connector/index.js');
|
|
1662
|
+
const providerDetail = createMipd().getProviders().find(detail => normalizeWalletName(detail.info.name) === connectorName);
|
|
1663
|
+
if (providerDetail) {
|
|
1664
|
+
return injectedEvmConnector(providerDetail)(config);
|
|
1665
|
+
}
|
|
1666
|
+
return null;
|
|
1667
|
+
}
|
|
1668
|
+
if (chainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
|
|
1669
|
+
const {
|
|
1670
|
+
createSolanaMipd,
|
|
1671
|
+
hasSolanaWalletStandardFeatures,
|
|
1672
|
+
walletStandardConnector
|
|
1673
|
+
} = await import('./connectors/injected-solana-connector/index.js');
|
|
1674
|
+
const wallet = createSolanaMipd().get().find(candidate => hasSolanaWalletStandardFeatures(candidate) && normalizeWalletName(candidate.name) === connectorName);
|
|
1675
|
+
if (wallet) {
|
|
1676
|
+
return walletStandardConnector(wallet)(config);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return null;
|
|
1680
|
+
}
|
|
1681
|
+
async resolveDiscoveredWalletConnector(connectorName, chainId, config, effectiveProjectConfig) {
|
|
1682
|
+
var _this$coreOptions$mul2;
|
|
1683
|
+
const chainConfig = this.getChainConfigForIsolatedConnector(chainId);
|
|
1684
|
+
const isExternalWalletEnabled = Boolean(effectiveProjectConfig === null || effectiveProjectConfig === void 0 ? void 0 : effectiveProjectConfig.externalWalletAuth);
|
|
1685
|
+
const isMipdEnabled = isExternalWalletEnabled && ((_this$coreOptions$mul2 = this.coreOptions.multiInjectedProviderDiscovery) !== null && _this$coreOptions$mul2 !== void 0 ? _this$coreOptions$mul2 : true);
|
|
1686
|
+
const installedConnector = await this.resolveInstalledDiscoveredWalletConnector({
|
|
1687
|
+
connectorName,
|
|
1688
|
+
chainConfig,
|
|
1689
|
+
config,
|
|
1690
|
+
isMipdEnabled
|
|
1691
|
+
});
|
|
1692
|
+
if (installedConnector) {
|
|
1693
|
+
return installedConnector;
|
|
1694
|
+
}
|
|
1695
|
+
const isBuiltInConnectorName = Object.values(WALLET_CONNECTORS).includes(connectorName);
|
|
1696
|
+
const supportsWalletConnectFallback = chainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155 || chainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA;
|
|
1697
|
+
|
|
1698
|
+
// Named discovered wallets (for example Phantom) can reuse WalletConnect as a transport fallback
|
|
1699
|
+
// when an injected connector for the target chain namespace is unavailable.
|
|
1700
|
+
if (!isBuiltInConnectorName && isExternalWalletEnabled && supportsWalletConnectFallback) {
|
|
1701
|
+
const {
|
|
1702
|
+
walletConnectV2Connector
|
|
1703
|
+
} = await import('./connectors/wallet-connect-v2-connector/index.js');
|
|
1704
|
+
return walletConnectV2Connector()(config);
|
|
1705
|
+
}
|
|
1706
|
+
throw AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking. ` + `Use ${WALLET_CONNECTORS.METAMASK}, ${WALLET_CONNECTORS.WALLET_CONNECT_V2}, or an installed compatible wallet.`);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Create a new connector instance that is NOT registered in this.connectors and NOT
|
|
1711
|
+
* subscribed to the main SDK event loop. Its lifecycle events are therefore isolated
|
|
1712
|
+
* and will not mutate any global SDK state (connectedConnectorName, connection, idToken).
|
|
1713
|
+
*/
|
|
1714
|
+
async createIsolatedWalletConnector(connectorName, chainId, projectConfig) {
|
|
1715
|
+
var _ref8;
|
|
1716
|
+
const effectiveProjectConfig = (_ref8 = projectConfig !== null && projectConfig !== void 0 ? projectConfig : this.projectConfig) !== null && _ref8 !== void 0 ? _ref8 : undefined;
|
|
1717
|
+
const config = {
|
|
1718
|
+
projectConfig: effectiveProjectConfig,
|
|
1719
|
+
coreOptions: this.coreOptions,
|
|
1720
|
+
analytics: this.analytics
|
|
1721
|
+
};
|
|
1722
|
+
let connector;
|
|
1723
|
+
switch (connectorName) {
|
|
1724
|
+
case WALLET_CONNECTORS.METAMASK:
|
|
1725
|
+
connector = metaMaskConnector()(config);
|
|
1726
|
+
break;
|
|
1727
|
+
case WALLET_CONNECTORS.WALLET_CONNECT_V2:
|
|
1728
|
+
{
|
|
1729
|
+
const {
|
|
1730
|
+
walletConnectV2Connector
|
|
1731
|
+
} = await import('./connectors/wallet-connect-v2-connector/index.js');
|
|
1732
|
+
connector = walletConnectV2Connector()(config);
|
|
1733
|
+
break;
|
|
1734
|
+
}
|
|
1735
|
+
case WALLET_CONNECTORS.AUTH:
|
|
1736
|
+
throw AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking.`);
|
|
1737
|
+
default:
|
|
1738
|
+
{
|
|
1739
|
+
connector = await this.resolveDiscoveredWalletConnector(connectorName, chainId, config, effectiveProjectConfig);
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
// Init the isolated connector WITHOUT subscribing to the main event loop.
|
|
1745
|
+
// This is the key difference from setupConnector(), which calls subscribeToConnectorEvents().
|
|
1746
|
+
// autoConnect: false ensures the connector does not attempt to rehydrate a previous session.
|
|
1747
|
+
await connector.init({
|
|
1748
|
+
chainId,
|
|
1749
|
+
autoConnect: false
|
|
1750
|
+
});
|
|
1751
|
+
return connector;
|
|
1752
|
+
}
|
|
1753
|
+
async setState(newState) {
|
|
956
1754
|
this.state = _objectSpread(_objectSpread({}, this.state), newState);
|
|
957
|
-
this.storage.
|
|
1755
|
+
await this.storage.set(WEB3AUTH_STATE_STORAGE_KEY, JSON.stringify(this.state));
|
|
958
1756
|
}
|
|
959
|
-
loadState(initialState) {
|
|
1757
|
+
async loadState(initialState) {
|
|
960
1758
|
if (initialState) {
|
|
961
|
-
this.state = initialState;
|
|
1759
|
+
this.state = _objectSpread(_objectSpread({}, this.state), initialState);
|
|
962
1760
|
return;
|
|
963
1761
|
}
|
|
964
|
-
const state = this.storage.
|
|
1762
|
+
const state = await this.storage.get(WEB3AUTH_STATE_STORAGE_KEY);
|
|
965
1763
|
if (!state) return;
|
|
966
1764
|
this.state = deserialize(state);
|
|
967
1765
|
}
|
|
968
1766
|
getStorageMethod() {
|
|
969
|
-
|
|
970
|
-
|
|
1767
|
+
var _this$coreOptions$sto;
|
|
1768
|
+
if ((_this$coreOptions$sto = this.coreOptions.storage) !== null && _this$coreOptions$sto !== void 0 && _this$coreOptions$sto.sessionId) return this.coreOptions.storage.sessionId;
|
|
1769
|
+
if (this.coreOptions.ssr) return new CookieStorage({
|
|
1770
|
+
maxAge: this.coreOptions.sessionTime
|
|
971
1771
|
});
|
|
972
|
-
if (
|
|
973
|
-
|
|
974
|
-
// If no storage is available, use a memory store.
|
|
975
|
-
return new MemoryStore();
|
|
1772
|
+
if (storageAvailable("localStorage")) return new LocalStorageAdapter();
|
|
1773
|
+
return new MemoryStorage();
|
|
976
1774
|
}
|
|
977
1775
|
}
|
|
978
1776
|
|