-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dda0f94
commit ac43e91
Showing
4 changed files
with
104 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/adapters/default-evm-adapter/src/injectedAdapters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
CHAIN_NAMESPACES, | ||
CustomChainConfig, | ||
getChainConfig, | ||
IAdapter, | ||
IProvider, | ||
IWeb3AuthCoreOptions, | ||
normalizeWalletName, | ||
WalletInitializationError, | ||
} from "@web3auth/base"; | ||
import { createStore as createMipd } from "mipd"; | ||
|
||
import { InjectedEvmAdapter } from "./injectedEvmAdapter"; | ||
|
||
export const getInjectedAdapters = (params: { options: IWeb3AuthCoreOptions }): IAdapter<unknown>[] => { | ||
const { options } = params; | ||
const { clientId, chainConfig, sessionTime, web3AuthNetwork, useCoreKitKey } = options; | ||
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace)) | ||
throw WalletInitializationError.invalidParams(`Invalid chainNamespace: ${chainConfig.chainNamespace}`); | ||
const finalChainConfig = { | ||
...(getChainConfig(chainConfig.chainNamespace, chainConfig?.chainId) as CustomChainConfig), | ||
...(chainConfig || {}), | ||
}; | ||
// EIP-6963: multiple injected provider discovery | ||
const mipd = createMipd(); | ||
// We assume that all extensions have emitted by here. | ||
// TODO: Ideally, we must use reactive listening. We will do that with v9 | ||
const injectedProviders = mipd.getProviders().map((providerDetail) => { | ||
return new InjectedEvmAdapter({ | ||
name: normalizeWalletName(providerDetail.info.name), | ||
provider: providerDetail.provider as IProvider, | ||
chainConfig: finalChainConfig, | ||
clientId, | ||
sessionTime, | ||
web3AuthNetwork, | ||
useCoreKitKey, | ||
}); | ||
}); | ||
|
||
return injectedProviders; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,9 @@ | ||
import { SolanaSignAndSendTransaction, SolanaSignMessage, SolanaSignTransaction } from "@solana/wallet-standard-features"; | ||
import { getWallets } from "@wallet-standard/app"; | ||
import { StandardConnect } from "@wallet-standard/features"; | ||
import { | ||
BaseAdapter, | ||
CHAIN_NAMESPACES, | ||
CustomChainConfig, | ||
getChainConfig, | ||
IAdapter, | ||
IWeb3AuthCoreOptions, | ||
normalizeWalletName, | ||
WalletInitializationError, | ||
} from "@web3auth/base"; | ||
import { IAdapter, IWeb3AuthCoreOptions } from "@web3auth/base"; | ||
|
||
import { WalletStandardAdapter } from "./walletStandardAdapter"; | ||
import { getInjectedAdapters } from "./injectedAdapters"; | ||
|
||
export const getInjectedAdapters = async (params: { options: IWeb3AuthCoreOptions }): Promise<IAdapter<unknown>[]> => { | ||
const { options } = params; | ||
const { clientId, chainConfig, sessionTime, web3AuthNetwork, useCoreKitKey } = options; | ||
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace)) | ||
throw WalletInitializationError.invalidParams(`Invalid chainNamespace: ${chainConfig.chainNamespace}`); | ||
const finalChainConfig = { | ||
...(getChainConfig(chainConfig.chainNamespace, chainConfig?.chainId) as CustomChainConfig), | ||
...(chainConfig || {}), | ||
}; | ||
|
||
// get installed wallets that support standard wallet | ||
const standardWalletAdapters = [] as BaseAdapter<void>[]; | ||
const wallets = getWallets().get(); | ||
wallets.forEach((wallet) => { | ||
const { name, chains, features } = wallet; | ||
const isSolana = chains.some((chain) => chain.startsWith("solana")); | ||
if (!isSolana) return; | ||
const hasRequiredFeatures = [StandardConnect, SolanaSignMessage, SolanaSignTransaction, SolanaSignAndSendTransaction].every((feature) => | ||
Object.keys(features).includes(feature) | ||
); | ||
if (!hasRequiredFeatures) return; | ||
|
||
standardWalletAdapters.push( | ||
new WalletStandardAdapter({ | ||
name: normalizeWalletName(name), | ||
wallet, | ||
chainConfig: finalChainConfig, | ||
clientId, | ||
sessionTime, | ||
web3AuthNetwork, | ||
useCoreKitKey, | ||
}) | ||
); | ||
}); | ||
return standardWalletAdapters; | ||
}; | ||
|
||
export const getDefaultExternalAdapters = async (params: { options: IWeb3AuthCoreOptions }): Promise<IAdapter<unknown>[]> => { | ||
export const getDefaultExternalAdapters = (params: { options: IWeb3AuthCoreOptions }): IAdapter<unknown>[] => { | ||
return getInjectedAdapters(params); | ||
}; | ||
|
||
export { getInjectedAdapters }; |
52 changes: 52 additions & 0 deletions
52
packages/adapters/default-solana-adapter/src/injectedAdapters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { SolanaSignAndSendTransaction, SolanaSignMessage, SolanaSignTransaction } from "@solana/wallet-standard-features"; | ||
import { getWallets } from "@wallet-standard/app"; | ||
import { StandardConnect } from "@wallet-standard/features"; | ||
import { | ||
BaseAdapter, | ||
CHAIN_NAMESPACES, | ||
CustomChainConfig, | ||
getChainConfig, | ||
IAdapter, | ||
IWeb3AuthCoreOptions, | ||
normalizeWalletName, | ||
WalletInitializationError, | ||
} from "@web3auth/base"; | ||
|
||
import { WalletStandardAdapter } from "./walletStandardAdapter"; | ||
|
||
export const getInjectedAdapters = (params: { options: IWeb3AuthCoreOptions }): IAdapter<unknown>[] => { | ||
const { options } = params; | ||
const { clientId, chainConfig, sessionTime, web3AuthNetwork, useCoreKitKey } = options; | ||
if (!Object.values(CHAIN_NAMESPACES).includes(chainConfig.chainNamespace)) | ||
throw WalletInitializationError.invalidParams(`Invalid chainNamespace: ${chainConfig.chainNamespace}`); | ||
const finalChainConfig = { | ||
...(getChainConfig(chainConfig.chainNamespace, chainConfig?.chainId) as CustomChainConfig), | ||
...(chainConfig || {}), | ||
}; | ||
|
||
// get installed wallets that support standard wallet | ||
const standardWalletAdapters = [] as BaseAdapter<void>[]; | ||
const wallets = getWallets().get(); | ||
wallets.forEach((wallet) => { | ||
const { name, chains, features } = wallet; | ||
const isSolana = chains.some((chain) => chain.startsWith("solana")); | ||
if (!isSolana) return; | ||
const hasRequiredFeatures = [StandardConnect, SolanaSignMessage, SolanaSignTransaction, SolanaSignAndSendTransaction].every((feature) => | ||
Object.keys(features).includes(feature) | ||
); | ||
if (!hasRequiredFeatures) return; | ||
|
||
standardWalletAdapters.push( | ||
new WalletStandardAdapter({ | ||
name: normalizeWalletName(name), | ||
wallet, | ||
chainConfig: finalChainConfig, | ||
clientId, | ||
sessionTime, | ||
web3AuthNetwork, | ||
useCoreKitKey, | ||
}) | ||
); | ||
}); | ||
return standardWalletAdapters; | ||
}; |