@web3auth/no-modal
Version:
Multi chain wallet aggregator for web3Auth
183 lines (182 loc) • 11.4 kB
TypeScript
import { SafeEventEmitter } from "@web3auth/auth";
import { type LinkAccountParams, type LinkAccountResult, UnlinkAccountResult } from "./account-linking";
import { Analytics, type AuthTokenInfo, type ChainNamespaceType, ConnectedAccountsWithProviders, type Connection, type CONNECTOR_STATUS_TYPE, type CustomChainConfig, type IConnector, type IPlugin, type IProvider, type IWeb3Auth, type IWeb3AuthCoreOptions, IWeb3AuthState, LinkedAccountInfo, LoginModeType, type LoginParamMap, type ProjectConfig, type UserInfo, type WALLET_CONNECTOR_TYPE, type Web3AuthNoModalEvents } from "./base";
import { type AuthConnectorSwitchAccountResult, type AuthConnectorType } from "./connectors/auth-connector";
import { type AccountAbstractionProvider } from "./providers/account-abstraction-provider";
import { CommonJRPCProvider } from "./providers/base-provider";
type ConnectedWalletAccountRef = LinkedAccountInfo | Pick<LinkedAccountInfo, "id" | "isPrimary"> | null | undefined;
export declare class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> implements IWeb3Auth {
readonly coreOptions: IWeb3AuthCoreOptions;
status: CONNECTOR_STATUS_TYPE;
loginMode: LoginModeType;
protected aaProvider: AccountAbstractionProvider | null;
protected connectors: IConnector<unknown>[];
protected commonJRPCProvider: CommonJRPCProvider | null;
protected analytics: Analytics;
protected plugins: Record<string, IPlugin>;
protected consentRequired: boolean;
protected projectConfig: ProjectConfig | null;
private storage;
private connectionReconnected;
/** Connected wallet state keyed by linked account id; the primary session uses a reserved key. */
private connectedWalletConnectorMap;
private activeWalletConnectorKey;
private state;
constructor(options: IWeb3AuthCoreOptions, initialState?: Partial<IWeb3AuthState>);
get currentChain(): CustomChainConfig | undefined;
get connected(): boolean;
get connection(): Connection | null;
get primaryConnectorName(): WALLET_CONNECTOR_TYPE | null;
get cachedConnector(): string | null;
get currentChainId(): string | null;
/**
* This is always the primary connector that is connected to the user.
*/
get primaryConnector(): IConnector<unknown> | null;
get accountAbstractionProvider(): AccountAbstractionProvider | null;
get idToken(): string | null;
get accessToken(): string | null;
get refreshToken(): string | null;
protected get activeAccount(): LinkedAccountInfo | null;
/**
* This is the current active connector.
*/
private get activeConnector();
set provider(_: IProvider | null);
init(options?: {
signal?: AbortSignal;
}): Promise<void>;
getConnector(connectorName: WALLET_CONNECTOR_TYPE, chainNamespace?: ChainNamespaceType): IConnector<unknown> | null;
clearCache(): Promise<void>;
cleanup(): Promise<void>;
switchChain(params: {
chainId: string;
}): Promise<void>;
/**
* Connect to a specific wallet connector
* @param connectorName - Key of the wallet connector to use.
*/
connectTo<T extends WALLET_CONNECTOR_TYPE>(connectorName: T, loginParams?: LoginParamMap[T], loginMode?: LoginModeType): Promise<Connection | null>;
logout(options?: {
cleanup: boolean;
}): Promise<void>;
getUserInfo(): Promise<Partial<UserInfo>>;
getLinkedAccounts(): Promise<LinkedAccountInfo[]>;
getConnectedAccountsWithProviders(): ConnectedAccountsWithProviders[];
enableMFA<T>(loginParams?: T): Promise<void>;
manageMFA<T>(loginParams?: T): Promise<void>;
getAuthTokenInfo(): Promise<Pick<AuthTokenInfo, "idToken">>;
getPlugin(name: string): IPlugin | null;
switchAccount(account: LinkedAccountInfo): Promise<void>;
linkAccount(params?: LinkAccountParams): Promise<LinkAccountResult>;
unlinkAccount(address: string): Promise<UnlinkAccountResult>;
setAnalyticsProperties(properties: Record<string, unknown>): void;
protected initChainsConfig(projectConfig: ProjectConfig): void;
protected initAccountAbstractionConfig(projectConfig?: ProjectConfig): void;
protected initUIConfig(projectConfig: ProjectConfig): void;
protected initSessionTimeConfig(projectConfig: ProjectConfig): void;
protected initCachedConnectorAndChainId(): Promise<void>;
protected initWalletServicesConfig(projectConfig: ProjectConfig): void;
protected getInitializationTrackData(): {};
protected setupCommonJRPCProvider(): Promise<void>;
protected setupConnector(connector: IConnector<unknown>): Promise<void>;
protected loadConnectors({ projectConfig, modalMode }: {
projectConfig: ProjectConfig;
modalMode?: boolean;
}): Promise<void>;
protected initPlugins(): Promise<void>;
protected setConnectors(connectors: IConnector<unknown>[]): void;
protected subscribeToConnectorEvents(connector: IConnector<unknown>): void;
protected checkInitRequirements(): void;
protected checkIfAutoConnect(connector: IConnector<unknown>): boolean;
/**
* Gets the initial chain configuration for a connector
* @throws WalletInitializationError If no chain is found for the connector's namespace
*/
protected getInitialChainIdForConnector(connector: IConnector<unknown>): CustomChainConfig;
protected completeConsentAcceptance(): Promise<void>;
protected resolveLinkAccountChainConfig(chainId?: string | null): CustomChainConfig;
/**
* Resolves the chain ID for a switch account operation.
* If the account's chain namespace is the same as the current chain namespace, return the current chain ID.
* If the account's chain namespace is different from the current chain namespace, return the chainId the account was linked in.
*
* @param account - The account to switch to.
* @param activeChainId - The current active chain ID.
* @returns The resolved chain ID.
*/
protected resolveSwitchAccountChainId(account: Pick<LinkedAccountInfo, "chainNamespace">, activeChainId: string): string;
protected createLinkingWalletConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string, config?: ProjectConfig): Promise<IConnector<unknown>>;
protected createSwitchingWalletConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string, config?: ProjectConfig): Promise<IConnector<unknown>>;
protected getConnectedWalletConnector(account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): IConnector<unknown> | null;
protected getConnectedWalletConnectorState(account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): ConnectedAccountsWithProviders | null;
protected setConnectedWalletConnectorState(connectedWallet: ConnectedAccountsWithProviders, account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): void;
protected setConnectedWalletConnector(connector: IConnector<unknown>, account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): void;
protected deleteConnectedWalletConnector(account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): void;
protected getConnectedWalletConnection(account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): Connection | null;
protected hasUsableConnectedSwitchConnector(connector: IConnector<unknown> | null): boolean;
protected setActiveWalletConnectorKey(account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): void;
protected getConnectedWalletConnectorKey(account?: Pick<LinkedAccountInfo, "id" | "isPrimary"> | null): string;
protected getConnectedWalletConnectorStateByKey(accountKey: string): ConnectedAccountsWithProviders | null;
protected isLinkedAccountInfo(account: ConnectedWalletAccountRef): account is LinkedAccountInfo;
protected toConnectedWalletLinkedAccountInfo(account: Omit<LinkedAccountInfo, "connector">): Omit<LinkedAccountInfo, "connector">;
protected getConnectedWalletLinkedAccountInfo(account?: ConnectedWalletAccountRef): Omit<LinkedAccountInfo, "connector">;
protected syncConnectedWalletLinkedAccounts(linkedAccounts: LinkedAccountInfo[]): void;
protected refreshConnectedWalletActiveStates(activeAccount: LinkedAccountInfo | null): void;
protected getConnectedWalletConnectionByKey(accountKey: string): Connection | null;
protected buildConnectionFromConnectedWalletConnectorState(connectedWallet: ConnectedAccountsWithProviders): Connection;
protected buildImmediateConnectedWalletConnectorState(params: {
connector: IConnector<unknown>;
ethereumProvider: IProvider | null;
solanaWallet: Connection["solanaWallet"];
usePrimaryProxy: boolean;
account?: ConnectedWalletAccountRef;
}): ConnectedAccountsWithProviders;
protected resolveConnectedWalletConnectorState(params: {
connector: IConnector<unknown>;
ethereumProvider: IProvider | null;
solanaWallet: Connection["solanaWallet"];
usePrimaryProxy: boolean;
account?: ConnectedWalletAccountRef;
}): Promise<ConnectedAccountsWithProviders>;
protected linkAccountWithConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string, connectorToLink: IConnector<unknown>): Promise<LinkAccountResult>;
protected getMainAuthConnector(): AuthConnectorType;
/**
* Processes the result of a switch account operation.
*
* - If the target account is a primary account, we will switch back to the primary account.
* - 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.
* - 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.
* @param authConnector - The main auth connector to use.
* @param switchResult - The result of the switch account operation.
* @param options - The options for the switch account operation.
* @returns A promise that resolves when the switch account operation is complete.
*/
protected processSwitchAccountResult(authConnector: AuthConnectorType, switchResult: AuthConnectorSwitchAccountResult, options?: {
walletConnector?: IConnector<unknown>;
projectConfig?: ProjectConfig;
}): Promise<void>;
private isActiveConnectorEventSource;
private shouldIgnoreInactiveConnectorEvent;
private findLinkedAccountByAddress;
private findLinkedAccountByWalletAddress;
private getConnectedWalletAddress;
private cacheConnectedLinkedWalletConnector;
private cacheWallet;
private setCurrentChain;
private connectToPlugins;
private bindPrimaryEthereumSigningProxy;
private getChainConfigForIsolatedConnector;
private resolveInstalledDiscoveredWalletConnector;
private resolveDiscoveredWalletConnector;
/**
* Create a new connector instance that is NOT registered in this.connectors and NOT
* subscribed to the main SDK event loop. Its lifecycle events are therefore isolated
* and will not mutate any global SDK state (connectedConnectorName, connection, idToken).
*/
private createIsolatedWalletConnector;
private setState;
private loadState;
private getStorageMethod;
}
export {};