Skip to content

Commit

Permalink
Merge pull request #1796 from Web3Auth/feat/hooks-optimizations
Browse files Browse the repository at this point in the history
Adds callback functions + add wallet services hook
  • Loading branch information
chaitanyapotti authored Apr 26, 2024
2 parents c8020df + 2bb7655 commit 7cf6c0c
Show file tree
Hide file tree
Showing 26 changed files with 314 additions and 235 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ await web3auth.connect();
| `@web3auth/phantom-adapter` | [![npm version](https://img.shields.io/npm/v/@web3auth/phantom-adapter?label=%22%22)](https://www.npmjs.com/package/@web3auth/phantom-adapter/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/phantom-adapter?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/phantom-adapter@latest) | Adds phantom chrome extension login functionality |
| `@web3auth/torus-evm-adapter` | [![npm version](https://img.shields.io/npm/v/@web3auth/torus-evm-adapter?label=%22%22)](https://www.npmjs.com/package/@web3auth/torus-evm-adapter/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/torus-evm-adapter?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/torus-evm-adapter@latest) | Adds Torus Wallet login functionality (https://app.tor.us) |
| `@web3auth/torus-solana-adapter` | [![npm version](https://img.shields.io/npm/v/@web3auth/torus-solana-adapter?label=%22%22)](https://www.npmjs.com/package/@web3auth/torus-solana-adapter/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/torus-solana-adapter?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/torus-solana-adapter@latest) | Adds Solana Torus Wallet login functionality (https://solana.tor.us) |
| `@web3auth/wallet-connect-v1-adapter` | [![npm version](https://img.shields.io/npm/v/@web3auth/wallet-connect-v1-adapter?label=%22%22)](https://www.npmjs.com/package/@web3auth/wallet-connect-v1-adapter/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/wallet-connect-v1-adapter?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/wallet-connect-v1-adapter@latest) | Adds wallet connect v1 login functionality + all supported adapters (eg: Metamask mobile, rainbow etc.) |
| `@web3auth/wallet-connect-v2-adapter` | [![npm version](https://img.shields.io/npm/v/@web3auth/wallet-connect-v2-adapter?label=%22%22)](https://www.npmjs.com/package/@web3auth/wallet-connect-v2-adapter/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/wallet-connect-v2-adapter?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/wallet-connect-v2-adapter@latest) | Adds wallet connect v2 login functionality + all supported adapters (eg: Metamask mobile, rainbow etc.) |
| 🐉 **Providers** |
| `@web3auth/base-provider` | [![npm version](https://img.shields.io/npm/v/@web3auth/base-provider?label=%22%22)](https://www.npmjs.com/package/@web3auth/base-provider/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/base-provider?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/base-provider@latest) | Base implementation of JRPC provider |
| `@web3auth/ethereum-provider` | [![npm version](https://img.shields.io/npm/v/@web3auth/ethereum-provider?label=%22%22)](https://www.npmjs.com/package/@web3auth/ethereum-provider/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/ethereum-provider?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/ethereum-provider@latest) | EIP-1193 compatible JRPC provider |
| `@web3auth/solana-provider` | [![npm version](https://img.shields.io/npm/v/@web3auth/solana-provider?label=%22%22)](https://www.npmjs.com/package/@web3auth/solana-provider/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/solana-provider?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/solana-provider@latest) | Solana chain compatible JRPC provider |
| 🐉 **Plugins** |
| `@web3auth/base-plugin` | [![npm version](https://img.shields.io/npm/v/@web3auth/base-plugin?label=%22%22)](https://www.npmjs.com/package/@web3auth/base-plugin/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/base-plugin?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/base-plugin@latest) | Base implementation of plugin |
| `@web3auth/torus-wallet-connector-plugin` | [![npm version](https://img.shields.io/npm/v/@web3auth/torus-wallet-connector-plugin?label=%22%22)](https://www.npmjs.com/package/@web3auth/torus-wallet-connector-plugin/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/torus-wallet-connector-plugin?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/torus-wallet-connector-plugin@latest) | Allows to inject your web3auth scoped private key into torus wallet UI (https://app.tor.us) |
| 🐉 **Plugins** | |
| `@web3auth/wallet-services-plugin` | [![npm version](https://img.shields.io/npm/v/@web3auth/wallet-services-plugin?label=%22%22)](https://www.npmjs.com/package/@web3auth/wallet-services-plugin/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/wallet-services-plugin?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/wallet-services-plugin@latest) | Allows to inject your web3auth scoped private key into Wallet Services UI |
| `@web3auth/solana-wallet-connector-plugin` | [![npm version](https://img.shields.io/npm/v/@web3auth/solana-wallet-connector-plugin?label=%22%22)](https://www.npmjs.com/package/@web3auth/solana-wallet-connector-plugin/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/solana-wallet-connector-plugin?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/solana-wallet-connector-plugin@latest) | Allows to inject your web3auth scoped private key into torus solana wallet UI (https://solana.tor.us) |
| 🐉 **Low-Level** |
| `@web3auth/base` | [![npm version](https://img.shields.io/npm/v/@web3auth/base?label=%22%22)](https://www.npmjs.com/package/@web3auth/base/v/latest) | [![minzip](https://img.shields.io/bundlephobia/minzip/@web3auth/base?label=%22%22)](https://bundlephobia.com/result?p=@web3auth/base@latest) | Base reusable functionalities for creating a web3auth instance |
Expand Down
25 changes: 13 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/adapters/default-evm-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, Web3AuthNoModalOptions } from "@web3auth/base";
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions } from "@web3auth/base";

export const getDefaultExternalAdapters = async (params: { options: Web3AuthNoModalOptions }): Promise<IAdapter<unknown>[]> => {
export const getDefaultExternalAdapters = 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 new Error(`Invalid chainNamespace: ${chainConfig.chainNamespace}`);
Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/default-solana-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, Web3AuthNoModalOptions } from "@web3auth/base";
import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IWeb3AuthCoreOptions } from "@web3auth/base";

export const getDefaultExternalAdapters = async (params: { options: Web3AuthNoModalOptions }): Promise<IAdapter<unknown>[]> => {
export const getDefaultExternalAdapters = 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 new Error(`Invalid chainNamespace: ${chainConfig.chainNamespace}`);
Expand Down
54 changes: 30 additions & 24 deletions packages/base/src/core/IWeb3Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,10 @@ import { WhiteLabelData } from "@toruslabs/openlogin-utils";

import { ADAPTER_STATUS_TYPE, IAdapter, IBaseProvider, IProvider, OPENLOGIN_NETWORK_TYPE, UserAuthInfo, UserInfo } from "../adapter/IAdapter";
import { CustomChainConfig } from "../chain/IChainInterface";
import { type IPlugin } from "../plugin";
import { WALLET_ADAPTER_TYPE } from "../wallet";

export interface IWeb3Auth extends SafeEventEmitter {
connected: boolean;
connectedAdapterName: string | null;
status: ADAPTER_STATUS_TYPE;
cachedAdapter: string | null;
provider: IProvider | null;
walletAdapters: Record<string, IAdapter<unknown>>;
init(): Promise<void>;
getAdapter(adapterName: WALLET_ADAPTER_TYPE): IAdapter<unknown> | null;
configureAdapter(adapter: IAdapter<unknown>): IWeb3Auth;
/**
* Connect to a specific wallet adapter
* @param walletName - Key of the walletAdapter to use.
*/
connectTo<T>(walletName: WALLET_ADAPTER_TYPE, loginParams?: T): Promise<IProvider | null>;
logout(options?: { cleanup: boolean }): Promise<void>;
getUserInfo(): Promise<Partial<UserInfo>>;
authenticateUser(): Promise<UserAuthInfo>;
addChain(chainConfig: CustomChainConfig): Promise<void>;
switchChain(params: { chainId: string }): Promise<void>;
enableMFA<T>(params: T): Promise<void>;
}

export interface Web3AuthNoModalOptions {
export interface IWeb3AuthCoreOptions {
/**
* Client id for web3auth.
* You can obtain your client id from the web3auth developer dashboard.
Expand Down Expand Up @@ -84,3 +62,31 @@ export interface Web3AuthNoModalOptions {
*/
privateKeyProvider?: IBaseProvider<string>;
}

export interface IWeb3Auth extends SafeEventEmitter {
readonly coreOptions: IWeb3AuthCoreOptions;
connected: boolean;
connectedAdapterName: string | null;
status: ADAPTER_STATUS_TYPE;
cachedAdapter: string | null;
provider: IProvider | null;
walletAdapters: Record<string, IAdapter<unknown>>;
init(): Promise<void>;
getAdapter(adapterName: WALLET_ADAPTER_TYPE): IAdapter<unknown> | null;
configureAdapter(adapter: IAdapter<unknown>): IWeb3Auth;
/**
* Connect to a specific wallet adapter
* @param walletName - Key of the walletAdapter to use.
*/
connectTo<T>(walletName: WALLET_ADAPTER_TYPE, loginParams?: T): Promise<IProvider | null>;
logout(options?: { cleanup: boolean }): Promise<void>;
getUserInfo(): Promise<Partial<UserInfo>>;
authenticateUser(): Promise<UserAuthInfo>;
addChain(chainConfig: CustomChainConfig): Promise<void>;
switchChain(params: { chainId: string }): Promise<void>;
enableMFA<T>(params: T): Promise<void>;
addPlugin(plugin: IPlugin): void;
getPlugin(pluginName: string): IPlugin | null;
}

export type Web3AuthNoModalOptions = IWeb3AuthCoreOptions;
1 change: 1 addition & 0 deletions packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./chain/IChainInterface";
export * from "./core/IWeb3Auth";
export * from "./errors";
export { default as log } from "./loglevel";
export * from "./plugin";
export * from "./provider/IProvider";
export * from "./utils";
export * from "./wallet";
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { CHAIN_NAMESPACES, IProvider, IWeb3Auth, UserInfo, WALLET_ADAPTER_TYPE } from "@web3auth/base";
import { type SafeEventEmitter } from "@toruslabs/openlogin-jrpc";

import { IProvider, UserInfo } from "../adapter";
import { CHAIN_NAMESPACES } from "../chain/IChainInterface";
import { type IWeb3Auth } from "../core/IWeb3Auth";
import { WALLET_ADAPTER_TYPE } from "../wallet";

export const PLUGIN_NAMESPACES = {
...CHAIN_NAMESPACES,
Expand Down Expand Up @@ -32,7 +37,7 @@ export const WALLET_PLUGINS = {
...SOLANA_PLUGINS,
} as const;

export interface IPlugin {
export interface IPlugin extends SafeEventEmitter {
name: string;
SUPPORTED_ADAPTERS: WALLET_ADAPTER_TYPE[];
pluginNamespace: PluginNamespace;
Expand Down
Loading

0 comments on commit 7cf6c0c

Please sign in to comment.