Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/modal/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type UIConfig } from "./ui";
import { type UIConfig } from "./ui/interfaces";

export const getLoginModalAnalyticsProperties = (uiConfig?: UIConfig) => {
return {
Expand Down
5 changes: 2 additions & 3 deletions packages/no-modal/src/base/connector/baseConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import type { Wallet } from "@wallet-standard/base";
import { SafeEventEmitter } from "@web3auth/auth";

import { CHAIN_NAMESPACES, type ChainNamespaceType, CONNECTOR_NAMESPACES, ConnectorNamespaceType, CustomChainConfig } from "../chain/IChainInterface";
import { type BaseConnectorSettings } from "../core/IWeb3AuthOptions";
import { WalletInitializationError, WalletLoginError } from "../errors";
import { log } from "../loglevel";
import { citadelServerUrl } from "../utils";
import { WALLET_CONNECTOR_TYPE, WALLET_CONNECTORS } from "../wallet";
import { CAN_AUTHORIZE_STATUSES, CONNECTED_STATUSES } from "./connectorStatus";
import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from "./constants";
import { CONNECTOR_EVENTS, CONNECTOR_STATUS, type CONNECTOR_STATUS_TYPE } from "./constants";
import type {
AuthTokenInfo,
BaseConnectorLoginParams,
BaseConnectorSettings,
Connection,
CONNECTOR_CATEGORY_TYPE,
CONNECTOR_STATUS_TYPE,
ConnectorEvents,
ConnectorInitOptions,
IConnector,
Expand Down
3 changes: 1 addition & 2 deletions packages/no-modal/src/base/connector/connectorStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CONNECTOR_STATUS } from "./constants";
import { CONNECTOR_STATUS_TYPE } from "./interfaces";
import { CONNECTOR_STATUS, type CONNECTOR_STATUS_TYPE } from "./constants";

export const CONNECTED_STATUSES: CONNECTOR_STATUS_TYPE[] = [CONNECTOR_STATUS.CONNECTED, CONNECTOR_STATUS.AUTHORIZED];

Expand Down
2 changes: 2 additions & 0 deletions packages/no-modal/src/base/connector/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const CONNECTOR_STATUS = {
CONSENT_REQUIRING: "consent_requiring",
} as const;

export type CONNECTOR_STATUS_TYPE = (typeof CONNECTOR_STATUS)[keyof typeof CONNECTOR_STATUS];

export const CONNECTOR_EVENTS = {
...CONNECTOR_STATUS,
CONNECTOR_DATA_UPDATED: "connector_data_updated",
Expand Down
23 changes: 4 additions & 19 deletions packages/no-modal/src/base/connector/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import {
type WEB3AUTH_NETWORK_TYPE,
} from "@web3auth/auth";

import { type Analytics } from "../analytics";
import type { ChainNamespaceType, ConnectorNamespaceType, CustomChainConfig } from "../chain/IChainInterface";
import type { IWeb3AuthCoreOptions } from "../core/IWeb3Auth";
import { Web3AuthError } from "../errors";
import type { LoginModeType, ProjectConfig } from "../interfaces";
import type { LoginModeType } from "../interfaces";
import type { ProviderEvents, SafeEventEmitterProvider } from "../provider/IProvider";
import { WALLET_CONNECTOR_TYPE } from "../wallet";
import { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_STATUS } from "./constants";
import { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, type CONNECTOR_STATUS_TYPE } from "./constants";

export type { CONNECTOR_STATUS_TYPE } from "./constants";

export type UserInfo = AuthUserInfo;

Expand All @@ -45,15 +45,8 @@ export interface ConnectorInitOptions {
getAuthTokenInfo?: boolean;
}

export type CONNECTOR_STATUS_TYPE = (typeof CONNECTOR_STATUS)[keyof typeof CONNECTOR_STATUS];

export type AuthTokenInfo = { idToken: string; accessToken?: string; refreshToken?: string };

export interface BaseConnectorSettings {
coreOptions: IWeb3AuthCoreOptions;
analytics?: Analytics;
}

export interface IProvider extends SafeEventEmitter<ProviderEvents> {
get chainId(): string;
request<S, R>(args: RequestArguments<S>): Promise<Maybe<R>>;
Expand Down Expand Up @@ -99,19 +92,11 @@ export interface IConnector<T> extends SafeEventEmitter {
cleanup?(): Promise<void>;
}

export type ConnectorParams = {
projectConfig?: ProjectConfig;
coreOptions: IWeb3AuthCoreOptions;
analytics: Analytics;
};

export type BaseConnectorLoginParams = {
chainId: string;
getAuthTokenInfo: boolean;
};

export type ConnectorFn = (params: ConnectorParams) => IConnector<unknown>;

export type CONNECTED_EVENT_DATA = Connection & {
reconnected: boolean;
pendingUserConsent?: boolean;
Expand Down
194 changes: 7 additions & 187 deletions packages/no-modal/src/base/core/IWeb3Auth.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
import { type AccountAbstractionMultiChainConfig } from "@toruslabs/ethereum-controllers";
import {
type BUILD_ENV_TYPE,
type CookieOptions,
type LoginParams,
MfaLevelType,
MfaSettings,
SafeEventEmitter,
type StorageConfig,
UX_MODE_TYPE,
type WhiteLabelData,
} from "@web3auth/auth";
import { type WsEmbedParams } from "@web3auth/ws-embed";
import { type LoginParams, SafeEventEmitter } from "@web3auth/auth";

import { type ChainNamespaceType, type CustomChainConfig } from "../chain/IChainInterface";
import {
type AuthTokenInfo,
CONNECTED_EVENT_DATA,
type Connection,
CONNECTOR_EVENTS,
CONNECTOR_INITIAL_AUTHENTICATION_MODE,
type CONNECTOR_STATUS_TYPE,
ConnectorEvents,
type ConnectorFn,
type IBaseProvider,
type IConnector,
type UserInfo,
type WEB3AUTH_NETWORK_TYPE,
} from "../connector";
import { CONNECTOR_EVENTS, type CONNECTOR_STATUS_TYPE } from "../connector/constants";
import type { AuthTokenInfo, CONNECTED_EVENT_DATA, Connection, ConnectorEvents, IConnector, UserInfo } from "../connector/interfaces";
import { Web3AuthError } from "../errors";
import { LoginModeType } from "../interfaces";
import { type IPlugin, type PluginFn } from "../plugin";
import type { IPlugin } from "../plugin/IPlugin";
import { type WALLET_CONNECTOR_TYPE, WALLET_CONNECTORS } from "../wallet";
import type { IWeb3AuthCoreOptions } from "./IWeb3AuthOptions";

export * from "./IWeb3AuthOptions";

export type AuthLoginParams = LoginParams & {
// to maintain backward compatibility
Expand All @@ -39,163 +18,6 @@ export type AuthLoginParams = LoginParams & {
idToken?: string;
};

export type WalletServicesConfig = Omit<
WsEmbedParams,
"buildEnv" | "enableLogging" | "chainId" | "chains" | "confirmationStrategy" | "accountAbstractionConfig"
> & {
/**
* Determines how to show confirmation screens
* @defaultValue default
*
* default & auto-approve
* - use auto-approve as default
* - if wallet connect request use modal
*
* modal
* - use modal always
*/
confirmationStrategy?: Exclude<WsEmbedParams["confirmationStrategy"], "popup">;
modalZIndex?: number;
};

export interface UIConfig extends WhiteLabelData {
/**
* UX Mode for the auth connector
*/
uxMode?: UX_MODE_TYPE;
}

export type ConnectorInitialAuthenticationModeType =
(typeof CONNECTOR_INITIAL_AUTHENTICATION_MODE)[keyof typeof CONNECTOR_INITIAL_AUTHENTICATION_MODE];

export interface IWeb3AuthCoreOptions {
/**
* Client id for web3auth.
* You can obtain your client id from the web3auth developer dashboard.
* You can set any random string for this on localhost.
*/
clientId: string;

/**
* multiple chain configurations,
* only provided chains will be used
*/
chains?: CustomChainConfig[];

/**
* default chain Id to use
*/
defaultChainId?: string;

/**
* setting to true will enable logs
*
* @defaultValue false
*/
enableLogging?: boolean;

/**
* Custom storage adapters for auth tokens (sessionId, accessToken, refreshToken, idToken).
* @defaultValue localStorage-based adapters
*/
storage?: StorageConfig;

/**
* Cookie configuration used when storage adapters are cookie-based.
*/
cookieOptions?: CookieOptions;

/**
* sessionTime (in seconds) for idToken issued by Web3Auth for server side verification.
* @defaultValue 7 * 86400
*
* Note: max value can be 30 days (86400 * 30) and min can be 1 sec (1)
*/
sessionTime?: number;

/**
* Web3Auth Network to use for the session.
*/
web3AuthNetwork: WEB3AUTH_NETWORK_TYPE;

/**
* Uses core-kit key with web3auth provider
* @defaultValue false
*/
useSFAKey?: boolean;

/**
* WhiteLabel options for web3auth
*/
uiConfig?: UIConfig;

/**
* Account abstraction config for your chain namespace
*/
accountAbstractionConfig?: AccountAbstractionMultiChainConfig;

/**
* Whether to use AA with external wallet
*/
useAAWithExternalWallet?: boolean;

/**
* Connectors to use
*/
connectors?: ConnectorFn[];

/**
* Plugins to use
*/
plugins?: PluginFn[];

/**
* Whether to enable multi injected provider discovery
* @defaultValue true
*/
multiInjectedProviderDiscovery?: boolean;

/**
* Wallet services config
*/
walletServicesConfig?: WalletServicesConfig;

/**
* Private key provider for xrpl cases
*/
privateKeyProvider?: IBaseProvider<string>;

/**
* Whether to enable SSR mode
*
* @defaultValue false
*/
ssr?: boolean;

/**
* Build environment for Auth connector
* @internal
* @defaultValue BUILD_ENV.PRODUCTION
*/
authBuildEnv?: BUILD_ENV_TYPE;

/**
* MFA settings for the auth connector
*/
mfaSettings?: MfaSettings;

/**
* MFA level for the auth connector
*/
mfaLevel?: MfaLevelType;

/**
* Initial authentication mode for the auth connector.
* @defaultValue "connect-and-sign"
*/
initialAuthenticationMode?: ConnectorInitialAuthenticationModeType;
}

export type LoginParamMap = {
[WALLET_CONNECTORS.AUTH]: Partial<AuthLoginParams>;
[WALLET_CONNECTORS.METAMASK]: { chainNamespace: ChainNamespaceType };
Expand Down Expand Up @@ -246,5 +68,3 @@ export type Web3AuthNoModalEvents = Omit<ConnectorEvents, "connected" | "errored
[CONNECTOR_EVENTS.ERRORED]: (error: Web3AuthError, loginMode: LoginModeType) => void;
MODAL_VISIBILITY: (visibility: boolean) => void;
};

export type Web3AuthNoModalOptions = IWeb3AuthCoreOptions;
Loading
Loading