From 9c61bd39452a09692010f96ac6b2713a51b5ad6e Mon Sep 17 00:00:00 2001 From: Lionell Briones Date: Tue, 14 Jan 2025 22:42:21 +0800 Subject: [PATCH 1/2] pass smart account config to wallet service --- .../wallet-services-plugin/src/plugin.ts | 2 + .../smartAccounts/BiconomySmartAccount.ts | 6 +-- .../smartAccounts/KernelSmartAccount.ts | 8 +--- .../smartAccounts/LightSmartAccount.ts | 6 +-- .../smartAccounts/NexusSmartAccount.ts | 6 +-- .../smartAccounts/SafeSmartAccount.ts | 11 +---- .../smartAccounts/SimpleSmartAccount.ts | 8 +--- .../smartAccounts/TrustSmartAccount.ts | 8 +--- .../src/providers/smartAccounts/types.ts | 42 +++++++++++++++++++ 9 files changed, 58 insertions(+), 39 deletions(-) diff --git a/packages/plugins/wallet-services-plugin/src/plugin.ts b/packages/plugins/wallet-services-plugin/src/plugin.ts index 1fde5037c..aabe6a26a 100644 --- a/packages/plugins/wallet-services-plugin/src/plugin.ts +++ b/packages/plugins/wallet-services-plugin/src/plugin.ts @@ -111,6 +111,7 @@ export class WalletServicesPlugin extends SafeEventEmitter implements IPlugin { const smartAccountType = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config.smartAccountInit.name; const paymasterConfig = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config?.paymasterConfig; const bundlerConfig = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config?.bundlerConfig; + const smartAccountConfig = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config.smartAccountInit.options; // TODO: fix this type casting when we start using accountAbstractionController accountAbstractionConfig = { @@ -118,6 +119,7 @@ export class WalletServicesPlugin extends SafeEventEmitter implements IPlugin { smartAccountType: smartAccountType || undefined, paymasterConfig: paymasterConfig || undefined, bundlerConfig: bundlerConfig || undefined, + smartAccountConfig: smartAccountConfig || undefined, } as AccountAbstractionConfig; } diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/BiconomySmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/BiconomySmartAccount.ts index 7a944e799..b5550d2f1 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/BiconomySmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/BiconomySmartAccount.ts @@ -4,14 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { entryPoint06Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type BiconomySmartAccountConfig = Pick; +import { BiconomySmartAccountConfig, ISmartAccount } from "./types"; export class BiconomySmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.BICONOMY; - private options: BiconomySmartAccountConfig; + public options: BiconomySmartAccountConfig; constructor(options?: BiconomySmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/KernelSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/KernelSmartAccount.ts index d91c82bd3..dfd09e9aa 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/KernelSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/KernelSmartAccount.ts @@ -4,16 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type KernelSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type - -type KernelSmartAccountConfig = Omit; +import { ISmartAccount, KernelSmartAccountConfig, KernelSmartAccountParameters } from "./types"; export class KernelSmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.KERNEL; - private options: KernelSmartAccountConfig; + public options: KernelSmartAccountConfig; constructor(options?: KernelSmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/LightSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/LightSmartAccount.ts index 87a1c6c2d..c2714fabc 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/LightSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/LightSmartAccount.ts @@ -4,14 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type LightSmartAccountConfig = Omit; +import { ISmartAccount, LightSmartAccountConfig } from "./types"; export class LightSmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.LIGHT; - private options: LightSmartAccountConfig; + public options: LightSmartAccountConfig; constructor(options?: LightSmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/NexusSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/NexusSmartAccount.ts index b23e7cad9..c248d5e5f 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/NexusSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/NexusSmartAccount.ts @@ -4,14 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type NexusSmartAccountConfig = Omit; +import { ISmartAccount, NexusSmartAccountConfig } from "./types"; export class NexusSmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.NEXUS; - private options: NexusSmartAccountConfig; + public options: NexusSmartAccountConfig; constructor(options?: NexusSmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SafeSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SafeSmartAccount.ts index 91891e21d..acce60711 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SafeSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SafeSmartAccount.ts @@ -4,19 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type SafeSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type - -type SafeSmartAccountConfig = Omit< - SafeSmartAccountParameters, - "owners" | "client" | "address" | "nonceKey" | "saltNonce" | "validUntil" | "validAfter" ->; +import { ISmartAccount, SafeSmartAccountConfig, SafeSmartAccountParameters } from "./types"; export class SafeSmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.SAFE; - private options: SafeSmartAccountConfig; + public options: SafeSmartAccountConfig; constructor(options?: SafeSmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SimpleSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SimpleSmartAccount.ts index 18ca1d7c6..90ade63fe 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SimpleSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SimpleSmartAccount.ts @@ -4,16 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type SimpleSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type - -type SimpleSmartAccountConfig = Omit; +import { ISmartAccount, SimpleSmartAccountConfig } from "./types"; export class SimpleSmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.SIMPLE; - private options: SimpleSmartAccountConfig; + public options: SimpleSmartAccountConfig; constructor(options?: SimpleSmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/TrustSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/TrustSmartAccount.ts index efe6548b9..7f8849cc4 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/TrustSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/TrustSmartAccount.ts @@ -4,16 +4,12 @@ import { Client, EIP1193Provider } from "viem"; import { entryPoint06Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; -import { ISmartAccount } from "./types"; - -type TrustSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type - -type TrustSmartAccountConfig = Omit; +import { ISmartAccount, TrustSmartAccountConfig, TrustSmartAccountParameters } from "./types"; export class TrustSmartAccount implements ISmartAccount { readonly name: string = SMART_ACCOUNT.TRUST; - private options: TrustSmartAccountConfig; + public options: TrustSmartAccountConfig; constructor(options?: TrustSmartAccountConfig) { this.options = options; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/types.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/types.ts index 1346d6928..0a82b76ea 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/types.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/types.ts @@ -1,7 +1,49 @@ import { IBaseSmartAccount, IProvider } from "@web3auth/base"; +import { + ToBiconomySmartAccountParameters, + toEcdsaKernelSmartAccount, + ToLightSmartAccountParameters, + ToNexusSmartAccountParameters, + toSafeSmartAccount, + toSimpleSmartAccount, + toTrustSmartAccount, +} from "permissionless/accounts"; import { Client } from "viem"; import { SmartAccount } from "viem/account-abstraction"; +export type BiconomySmartAccountConfig = Pick; + +export type KernelSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type + +export type KernelSmartAccountConfig = Omit; + +export type LightSmartAccountConfig = Omit; + +export type NexusSmartAccountConfig = Omit; + +export type SafeSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type + +export type SafeSmartAccountConfig = Omit< + SafeSmartAccountParameters, + "owners" | "client" | "address" | "nonceKey" | "saltNonce" | "validUntil" | "validAfter" +>; + +export type SimpleSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type + +export type SimpleSmartAccountConfig = Omit; + +export type TrustSmartAccountParameters = Parameters[0]; // use type of function so we don't need to pass in generic to parameter type + +export type TrustSmartAccountConfig = Omit; + export interface ISmartAccount extends IBaseSmartAccount { + options: + | BiconomySmartAccountConfig + | KernelSmartAccountConfig + | NexusSmartAccountConfig + | SafeSmartAccountConfig + | TrustSmartAccountConfig + | LightSmartAccountConfig + | SimpleSmartAccountConfig; getSmartAccount(params: { owner: IProvider; client: Client }): Promise; } From 443b812fd8078afdf2fc50ac5d04bc0182a51db0 Mon Sep 17 00:00:00 2001 From: Lionell Briones Date: Wed, 15 Jan 2025 17:57:55 +0800 Subject: [PATCH 2/2] updated controller dependency --- packages/plugins/wallet-services-plugin/package.json | 4 ++-- packages/plugins/wallet-services-plugin/src/plugin.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugins/wallet-services-plugin/package.json b/packages/plugins/wallet-services-plugin/package.json index bd1ed6378..8ae9731ce 100644 --- a/packages/plugins/wallet-services-plugin/package.json +++ b/packages/plugins/wallet-services-plugin/package.json @@ -31,14 +31,14 @@ "dist" ], "devDependencies": { - "@toruslabs/ethereum-controllers": "^7.0.1" + "@toruslabs/ethereum-controllers": "^7.1.3" }, "dependencies": { "@web3auth/account-abstraction-provider": "^9.5.2", "@web3auth/auth": "^9.6.2", "@web3auth/base": "^9.5.2", "@web3auth/no-modal": "^9.5.2", - "@web3auth/ws-embed": "^3.4.0", + "@web3auth/ws-embed": "^3.4.4", "loglevel": "^1.9.2" }, "peerDependencies": { diff --git a/packages/plugins/wallet-services-plugin/src/plugin.ts b/packages/plugins/wallet-services-plugin/src/plugin.ts index 9b0da25ef..ff82a89d6 100644 --- a/packages/plugins/wallet-services-plugin/src/plugin.ts +++ b/packages/plugins/wallet-services-plugin/src/plugin.ts @@ -1,5 +1,5 @@ import { type BaseEmbedControllerState } from "@toruslabs/base-controllers"; -import type { EthereumProviderConfig } from "@toruslabs/ethereum-controllers"; +import type { AccountAbstractionConfig, EthereumProviderConfig } from "@toruslabs/ethereum-controllers"; import { AccountAbstractionProvider } from "@web3auth/account-abstraction-provider"; import { SafeEventEmitter, type WhiteLabelData } from "@web3auth/auth"; import { @@ -21,7 +21,7 @@ import { WALLET_ADAPTERS, WalletServicesPluginError, } from "@web3auth/base"; -import WsEmbed, { AccountAbstractionConfig, CtorArgs, WsEmbedParams } from "@web3auth/ws-embed"; +import WsEmbed, { CtorArgs, WsEmbedParams } from "@web3auth/ws-embed"; type WsPluginEmbedParams = Omit & { /**