From e49204d2c32da4b275a121d17ac96990b817d0cb Mon Sep 17 00:00:00 2001 From: Nguyen Anh Tu Date: Tue, 10 Dec 2024 16:01:53 +0700 Subject: [PATCH 1/2] refactor(app): account abstraction - use eoa wallet client instead of owner provider --- .../account-abstraction-provider/package.json | 4 ++-- .../src/providers/AccountAbstractionProvider.ts | 13 +++++++++++-- .../providers/smartAccounts/BiconomySmartAccount.ts | 7 +++---- .../providers/smartAccounts/KernelSmartAccount.ts | 7 +++---- .../providers/smartAccounts/LightSmartAccount.ts | 7 +++---- .../providers/smartAccounts/NexusSmartAccount.ts | 7 +++---- .../src/providers/smartAccounts/SafeSmartAccount.ts | 7 +++---- .../providers/smartAccounts/SimpleSmartAccount.ts | 7 +++---- .../providers/smartAccounts/TrustSmartAccount.ts | 7 +++---- .../src/providers/smartAccounts/types.ts | 6 +++--- .../src/providers/utils.ts | 4 +--- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/providers/account-abstraction-provider/package.json b/packages/providers/account-abstraction-provider/package.json index bc0085478..cdba8ae39 100644 --- a/packages/providers/account-abstraction-provider/package.json +++ b/packages/providers/account-abstraction-provider/package.json @@ -27,8 +27,8 @@ "@web3auth/base-provider": "^9.5.0-alpha.1", "@web3auth/ethereum-provider": "^9.5.0-alpha.2", "ethers": "^6.13.4", - "permissionless": "^0.2.20", - "viem": "^2.21.52" + "permissionless": "^0.2.22", + "viem": "^2.21.54" }, "peerDependencies": { "@babel/runtime": "7.x" diff --git a/packages/providers/account-abstraction-provider/src/providers/AccountAbstractionProvider.ts b/packages/providers/account-abstraction-provider/src/providers/AccountAbstractionProvider.ts index 0cd389b53..8786528f2 100644 --- a/packages/providers/account-abstraction-provider/src/providers/AccountAbstractionProvider.ts +++ b/packages/providers/account-abstraction-provider/src/providers/AccountAbstractionProvider.ts @@ -1,7 +1,7 @@ import { JRPCEngine, providerErrors, providerFromEngine } from "@web3auth/auth"; import { CHAIN_NAMESPACES, CustomChainConfig, IProvider, WalletInitializationError } from "@web3auth/base"; import { BaseProvider, BaseProviderConfig, BaseProviderState } from "@web3auth/base-provider"; -import { Client, createPublicClient, defineChain, http } from "viem"; +import { Client, createPublicClient, createWalletClient, custom, defineChain, Hex, http } from "viem"; import { BundlerClient, createBundlerClient, createPaymasterClient, PaymasterClient, SmartAccount } from "viem/account-abstraction"; import { createAaMiddleware, eoaProviderAsMiddleware } from "../rpc/ethRpcMiddlewares"; @@ -99,9 +99,18 @@ export class AccountAbstractionProvider extends BaseProvider({ method: "eth_accounts" }); + const walletClient = createWalletClient({ + account: eoaAddress as Hex, + chain, + transport: custom(eoaProvider), + }); this._smartAccount = await this.config.smartAccountInit.getSmartAccount({ - owner: eoaProvider, client: this._publicClient, + walletClient, }); // setup bundler and paymaster 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..ca393fe00 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/BiconomySmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/BiconomySmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toBiconomySmartAccount, ToBiconomySmartAccountParameters } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { entryPoint06Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -18,7 +17,7 @@ export class BiconomySmartAccount implements ISmartAccount { } async getSmartAccount( - params: { owner: IProvider; client: Client } & Pick + params: { walletClient: WalletClient; client: Client } & Pick ): Promise { return toBiconomySmartAccount({ ...(this.options || {}), @@ -27,7 +26,7 @@ export class BiconomySmartAccount implements ISmartAccount { version: this.options?.entryPoint?.version || "0.6", }, ...params, - owners: [params.owner as EIP1193Provider], + owners: [params.walletClient], client: params.client, }); } 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..5eaadc54e 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/KernelSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/KernelSmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toEcdsaKernelSmartAccount } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -20,12 +19,12 @@ export class KernelSmartAccount implements ISmartAccount { } async getSmartAccount( - params: { owner: IProvider; client: Client } & Pick + params: { walletClient: WalletClient; client: Client } & Pick ): Promise { return toEcdsaKernelSmartAccount({ ...(this.options || {}), ...params, - owners: [params.owner as EIP1193Provider], + owners: [params.walletClient], client: params.client, }); } 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..7e6995569 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/LightSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/LightSmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toLightSmartAccount, ToLightSmartAccountParameters } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -18,7 +17,7 @@ export class LightSmartAccount implements ISmartAccount { } async getSmartAccount( - params: { owner: IProvider; client: Client } & Pick + params: { walletClient: WalletClient; client: Client } & Pick ): Promise { return toLightSmartAccount({ ...(this.options || {}), @@ -27,7 +26,7 @@ export class LightSmartAccount implements ISmartAccount { version: this.options?.entryPoint?.version || "0.7", }, version: this.options?.version || "2.0.0", - owner: params.owner as EIP1193Provider, + owner: params.walletClient, client: params.client, }); } 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..2a4de8e3e 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/NexusSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/NexusSmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toNexusSmartAccount, ToNexusSmartAccountParameters } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -18,7 +17,7 @@ export class NexusSmartAccount implements ISmartAccount { } async getSmartAccount( - params: { owner: IProvider; client: Client } & Pick + params: { walletClient: WalletClient; client: Client } & Pick ): Promise { return toNexusSmartAccount({ ...(this.options || {}), @@ -28,7 +27,7 @@ export class NexusSmartAccount implements ISmartAccount { }, version: this.options?.version || "1.0.0", ...params, - owners: [params.owner as EIP1193Provider], + owners: [params.walletClient], client: params.client, }); } 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..c91849193 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SafeSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SafeSmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toSafeSmartAccount } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -23,7 +22,7 @@ export class SafeSmartAccount implements ISmartAccount { } async getSmartAccount( - params: { owner: IProvider; client: Client } & Pick< + params: { walletClient: WalletClient; client: Client } & Pick< SafeSmartAccountParameters, "address" | "nonceKey" | "saltNonce" | "validUntil" | "validAfter" > @@ -36,7 +35,7 @@ export class SafeSmartAccount implements ISmartAccount { }, version: this.options?.version || "1.4.1", ...params, - owners: [params.owner as EIP1193Provider], + owners: [params.walletClient], client: params.client, }); } 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..149be8d77 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SimpleSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/SimpleSmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toSimpleSmartAccount } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { entryPoint07Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -19,14 +18,14 @@ export class SimpleSmartAccount implements ISmartAccount { this.options = options; } - async getSmartAccount(params: { owner: IProvider; client: Client }): Promise { + async getSmartAccount(params: { walletClient: WalletClient; client: Client }): Promise { return toSimpleSmartAccount({ ...(this.options || {}), entryPoint: { address: this.options?.entryPoint?.address || entryPoint07Address, version: this.options?.entryPoint?.version || "0.7", }, - owner: params.owner as EIP1193Provider, + owner: params.walletClient, client: params.client, }); } 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..4353a88f2 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/TrustSmartAccount.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/TrustSmartAccount.ts @@ -1,6 +1,5 @@ -import { IProvider } from "@web3auth/base"; import { toTrustSmartAccount } from "permissionless/accounts"; -import { Client, EIP1193Provider } from "viem"; +import { Client, WalletClient } from "viem"; import { entryPoint06Address, SmartAccount } from "viem/account-abstraction"; import { SMART_ACCOUNT } from "./constants"; @@ -20,7 +19,7 @@ export class TrustSmartAccount implements ISmartAccount { } async getSmartAccount( - params: { owner: IProvider; client: Client } & Pick + params: { walletClient: WalletClient; client: Client } & Pick ): Promise { return toTrustSmartAccount({ ...(this.options || {}), @@ -29,7 +28,7 @@ export class TrustSmartAccount implements ISmartAccount { version: this.options?.entryPoint?.version || "0.6", }, ...params, - owner: params.owner as EIP1193Provider, + owner: params.walletClient, client: params.client, }); } 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..061e93a9b 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,7 @@ -import { IBaseSmartAccount, IProvider } from "@web3auth/base"; -import { Client } from "viem"; +import { IBaseSmartAccount } from "@web3auth/base"; +import { Client, WalletClient } from "viem"; import { SmartAccount } from "viem/account-abstraction"; export interface ISmartAccount extends IBaseSmartAccount { - getSmartAccount(params: { owner: IProvider; client: Client }): Promise; + getSmartAccount(params: { client: Client; walletClient: WalletClient }): Promise; } diff --git a/packages/providers/account-abstraction-provider/src/providers/utils.ts b/packages/providers/account-abstraction-provider/src/providers/utils.ts index eec4421ce..8261e192b 100644 --- a/packages/providers/account-abstraction-provider/src/providers/utils.ts +++ b/packages/providers/account-abstraction-provider/src/providers/utils.ts @@ -1,6 +1,6 @@ import { addHexPrefix, isHexString } from "@ethereumjs/util"; import { JRPCRequest, providerErrors } from "@web3auth/auth"; -import { IProvider, log } from "@web3auth/base"; +import { IProvider } from "@web3auth/base"; import { IProviderHandlers, MessageParams, SignTypedDataMessageV4, TransactionParams, TypedMessageParams } from "@web3auth/ethereum-provider"; import { Chain, createWalletClient, Hex, http } from "viem"; import { BundlerClient, SendUserOperationParameters, SmartAccount } from "viem/account-abstraction"; @@ -28,8 +28,6 @@ export function getProviderHandlers({ smartAccount.getAddress(), eoaProvider.request({ method: "eth_accounts" }), ]); - log.info("smartAccounts", smartAccounts); - log.info("eoaAccounts", eoaAccounts); return [smartAccounts, ...eoaAccounts]; }, getPrivateKey: async (_: JRPCRequest) => { From 862a413680c19ec8d56a5c28ffc559f5fbad6851 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Tu Date: Tue, 10 Dec 2024 16:02:49 +0700 Subject: [PATCH 2/2] feat(app): account abstraction - add support for metamask delegation toolkit smart account --- demo/vue-app-new/package-lock.json | 149 ++++++++--------- demo/vue-app-new/src/MainView.vue | 4 + demo/vue-app-new/src/config.ts | 3 +- package-lock.json | 157 +++++++++++++++--- .../account-abstraction-provider/package.json | 1 + .../smartAccounts/MetamaskSmartAccount.ts | 91 ++++++++++ .../src/providers/smartAccounts/constants.ts | 1 + .../src/providers/smartAccounts/index.ts | 1 + 8 files changed, 306 insertions(+), 101 deletions(-) create mode 100644 packages/providers/account-abstraction-provider/src/providers/smartAccounts/MetamaskSmartAccount.ts diff --git a/demo/vue-app-new/package-lock.json b/demo/vue-app-new/package-lock.json index 10d3058ac..bcfa477d6 100644 --- a/demo/vue-app-new/package-lock.json +++ b/demo/vue-app-new/package-lock.json @@ -58,12 +58,12 @@ }, "../../packages/adapters/auth-adapter": { "name": "@web3auth/auth-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", "deepmerge": "^4.3.1" }, "engines": { @@ -76,11 +76,11 @@ }, "../../packages/adapters/base-evm-adapter": { "name": "@web3auth/base-evm-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^6.3.2", - "@web3auth/base": "^9.4.5" + "@web3auth/base": "^9.5.0-alpha.1" }, "engines": { "node": ">=18.x", @@ -92,11 +92,11 @@ }, "../../packages/adapters/base-solana-adapter": { "name": "@web3auth/base-solana-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^6.3.2", - "@web3auth/base": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", "bs58": "^5.0.0" }, "devDependencies": { @@ -112,11 +112,11 @@ }, "../../packages/adapters/coinbase-adapter": { "name": "@web3auth/coinbase-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { - "@web3auth/base": "^9.4.5", - "@web3auth/base-evm-adapter": "^9.4.5" + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-evm-adapter": "^9.5.0-alpha.1" }, "devDependencies": { "@coinbase/wallet-sdk": "^4.2.3" @@ -132,12 +132,12 @@ }, "../../packages/adapters/default-evm-adapter": { "name": "@web3auth/default-evm-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { - "@web3auth/base": "^9.4.5", - "@web3auth/base-evm-adapter": "^9.4.5", - "@web3auth/wallet-connect-v2-adapter": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-evm-adapter": "^9.5.0-alpha.1", + "@web3auth/wallet-connect-v2-adapter": "^9.5.0-alpha.2", "mipd": "^0.0.7" }, "engines": { @@ -150,7 +150,7 @@ }, "../../packages/adapters/default-solana-adapter": { "name": "@web3auth/default-solana-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { "@solana/wallet-standard-features": "^1.2.0", @@ -159,10 +159,10 @@ "@wallet-standard/base": "^1.1.0", "@wallet-standard/features": "^1.1.0", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-solana-adapter": "^9.4.5", - "@web3auth/solana-provider": "^9.4.5", - "@web3auth/wallet-connect-v2-adapter": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-solana-adapter": "^9.5.0-alpha.1", + "@web3auth/solana-provider": "^9.5.0-alpha.1", + "@web3auth/wallet-connect-v2-adapter": "^9.5.0-alpha.2", "bn.js": "^5.2.1" }, "engines": { @@ -175,12 +175,12 @@ }, "../../packages/adapters/torus-evm-adapter": { "name": "@web3auth/torus-evm-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/torus-embed": "^5.0.0", - "@web3auth/base": "^9.4.5", - "@web3auth/base-evm-adapter": "^9.4.5" + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-evm-adapter": "^9.5.0-alpha.1" }, "engines": { "node": ">=18.x", @@ -192,14 +192,14 @@ }, "../../packages/adapters/torus-solana-adapter": { "name": "@web3auth/torus-solana-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/solana-embed": "^2.1.0", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", - "@web3auth/base-solana-adapter": "^9.4.5", - "@web3auth/solana-provider": "^9.4.5" + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", + "@web3auth/base-solana-adapter": "^9.5.0-alpha.1", + "@web3auth/solana-provider": "^9.5.0-alpha.1" }, "engines": { "node": ">=18.x", @@ -212,7 +212,7 @@ }, "../../packages/adapters/wallet-connect-v2-adapter": { "name": "@web3auth/wallet-connect-v2-adapter", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { "@solana/web3.js": "^1.95.5", @@ -221,10 +221,10 @@ "@walletconnect/types": "^2.17.2", "@walletconnect/utils": "^2.17.2", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", - "@web3auth/ethereum-provider": "^9.4.5", - "@web3auth/solana-provider": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", + "@web3auth/ethereum-provider": "^9.5.0-alpha.2", + "@web3auth/solana-provider": "^9.5.0-alpha.1", "bs58": "^5.0.0", "deepmerge": "^4.3.1" }, @@ -241,7 +241,7 @@ }, "../../packages/base": { "name": "@web3auth/base", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^6.3.2", @@ -262,15 +262,15 @@ }, "../../packages/composables/modal-vue-composables": { "name": "@web3auth/modal-vue-composables", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { - "@web3auth/base": "^9.4.5", - "@web3auth/modal": "^9.4.5" + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/modal": "^9.5.0-alpha.2" }, "devDependencies": { "@web3auth/auth": "^9.5.3", - "@web3auth/auth-adapter": "^9.4.5" + "@web3auth/auth-adapter": "^9.5.0-alpha.1" }, "engines": { "node": ">=18.x", @@ -283,22 +283,22 @@ }, "../../packages/modal": { "name": "@web3auth/modal", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { - "@web3auth/auth-adapter": "^9.4.5", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", - "@web3auth/no-modal": "^9.4.5", - "@web3auth/ui": "^9.4.5", + "@web3auth/auth-adapter": "^9.5.0-alpha.1", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", + "@web3auth/no-modal": "^9.5.0-alpha.2", + "@web3auth/ui": "^9.5.0-alpha.1", "deepmerge": "^4.3.1" }, "devDependencies": { "@svgr/webpack": "^8.1.0", "@toruslabs/isomorphic-style-loader": "^5.3.3", - "@web3auth/account-abstraction-provider": "^9.4.5", + "@web3auth/account-abstraction-provider": "^9.5.0-alpha.2", "@web3auth/auth": "^9.5.3", - "@web3auth/wallet-connect-v2-adapter": "^9.4.5", + "@web3auth/wallet-connect-v2-adapter": "^9.5.0-alpha.2", "css-loader": "^7.1.2", "postcss-prefix-selector": "^2.1.0", "style-loader": "^4.0.0", @@ -320,18 +320,18 @@ }, "../../packages/no-modal": { "name": "@web3auth/no-modal", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", "deepmerge": "^4.3.1" }, "devDependencies": { - "@web3auth/account-abstraction-provider": "^9.4.5", - "@web3auth/auth-adapter": "^9.4.5", - "@web3auth/wallet-connect-v2-adapter": "^9.4.5" + "@web3auth/account-abstraction-provider": "^9.5.0-alpha.2", + "@web3auth/auth-adapter": "^9.5.0-alpha.1", + "@web3auth/wallet-connect-v2-adapter": "^9.5.0-alpha.2" }, "engines": { "node": ">=18.x", @@ -353,12 +353,12 @@ }, "../../packages/plugins/nft-checkout-plugin": { "name": "@web3auth/nft-checkout-plugin", - "version": "9.3.2", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^6.2.4", "@web3auth/auth": "^9.4.1", - "@web3auth/base": "^9.3.0", + "@web3auth/base": "^9.5.0-alpha.1", "loglevel": "^1.9.2" }, "engines": { @@ -371,13 +371,13 @@ }, "../../packages/plugins/solana-wallet-connector-plugin": { "name": "@web3auth/solana-wallet-connector-plugin", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { "@toruslabs/solana-embed": "^2.1.0", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/no-modal": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/no-modal": "^9.5.0-alpha.2", "loglevel": "^1.9.2" }, "engines": { @@ -390,13 +390,13 @@ }, "../../packages/plugins/wallet-services-plugin": { "name": "@web3auth/wallet-services-plugin", - "version": "9.5.0-alpha.0", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { - "@web3auth/account-abstraction-provider": "^9.3.1", + "@web3auth/account-abstraction-provider": "^9.5.0-alpha.2", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/no-modal": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/no-modal": "^9.5.0-alpha.2", "@web3auth/ws-embed": "^3.2.1", "loglevel": "^1.9.2" }, @@ -413,18 +413,19 @@ }, "../../packages/providers/account-abstraction-provider": { "name": "@web3auth/account-abstraction-provider", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { + "@codefi/delegator-core-viem": "^0.4.0", "@ethereumjs/util": "^9.1.0", "@toruslabs/base-controllers": "^6.3.2", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", - "@web3auth/ethereum-provider": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", + "@web3auth/ethereum-provider": "^9.5.0-alpha.2", "ethers": "^6.13.4", - "permissionless": "^0.2.20", - "viem": "^2.21.52" + "permissionless": "^0.2.22", + "viem": "^2.21.54" }, "engines": { "node": ">=18.x", @@ -498,12 +499,12 @@ }, "../../packages/providers/base-provider": { "name": "@web3auth/base-provider", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^6.3.2", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", "json-rpc-random-id": "^1.0.1" }, "devDependencies": { @@ -519,7 +520,7 @@ }, "../../packages/providers/ethereum-provider": { "name": "@web3auth/ethereum-provider", - "version": "9.4.5", + "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { "@ethereumjs/util": "^9.1.0", @@ -527,8 +528,8 @@ "@toruslabs/eccrypto": "^5.0.4", "@toruslabs/http-helpers": "^7.0.0", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", "assert": "^2.1.0", "bignumber.js": "^9.1.2", "bn.js": "^5.2.1", @@ -550,14 +551,14 @@ }, "../../packages/providers/solana-provider": { "name": "@web3auth/solana-provider", - "version": "9.4.5", + "version": "9.5.0-alpha.1", "license": "ISC", "dependencies": { "@toruslabs/base-controllers": "^6.3.2", "@toruslabs/tweetnacl-js": "^1.0.4", "@web3auth/auth": "^9.5.3", - "@web3auth/base": "^9.4.5", - "@web3auth/base-provider": "^9.4.5", + "@web3auth/base": "^9.5.0-alpha.1", + "@web3auth/base-provider": "^9.5.0-alpha.1", "bn.js": "^5.2.1", "bs58": "^5.0.0", "json-rpc-random-id": "^1.0.1" diff --git a/demo/vue-app-new/src/MainView.vue b/demo/vue-app-new/src/MainView.vue index dc31b0c6d..db3054b37 100644 --- a/demo/vue-app-new/src/MainView.vue +++ b/demo/vue-app-new/src/MainView.vue @@ -3,6 +3,7 @@ import { AccountAbstractionProvider, ISmartAccount, KernelSmartAccount, + MetamaskSmartAccount, NexusSmartAccount, // LightSmartAccount, SafeSmartAccount, @@ -109,6 +110,9 @@ const accountAbstractionProvider = computed((): IBaseProvider | undef case "trust": smartAccountInit = new TrustSmartAccount(); break; + case "metamask": + smartAccountInit = new MetamaskSmartAccount(); + break; // case "light": // smartAccountInit = new LightSmartAccount(); // break; diff --git a/demo/vue-app-new/src/config.ts b/demo/vue-app-new/src/config.ts index 7fba43845..8c91122a6 100644 --- a/demo/vue-app-new/src/config.ts +++ b/demo/vue-app-new/src/config.ts @@ -153,13 +153,14 @@ export const defaultLoginMethod: Record {} as Record ); -export type SmartAccountType = "safe" | "kernel" | "nexus" | "trust"; +export type SmartAccountType = "safe" | "kernel" | "nexus" | "trust" | "metamask"; export const SmartAccountOptions: { name: string; value: SmartAccountType }[] = [ { name: "Safe", value: "safe" }, { name: "Nexus", value: "nexus" }, { name: "Kernel", value: "kernel" }, { name: "Trust", value: "trust" }, + { name: "Metamask", value: "metamask" }, // { name: "Light", value: "light" }, // { name: "Simple", value: "simple" }, ]; diff --git a/package-lock.json b/package-lock.json index 04f814527..4f600f91e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1742,6 +1742,57 @@ "node": ">=6.9.0" } }, + "node_modules/@codefi/delegation-abis": { + "version": "0.4.0", + "resolved": "https://nexus.eu-west-3.codefi.network/repository/npm-hosted/@codefi/delegation-abis/-/delegation-abis-0.4.0.tgz", + "integrity": "sha512-cf8TR+joKSpFExh4pfiMDE5EqOOQyk2TK0+M5CguuAb+XD+0mTaYNtM4lyXH6I0mn8GKdniEQV/St/cOwKhbag==" + }, + "node_modules/@codefi/delegation-deployments": { + "version": "0.4.0", + "resolved": "https://nexus.eu-west-3.codefi.network/repository/npm-hosted/@codefi/delegation-deployments/-/delegation-deployments-0.4.0.tgz", + "integrity": "sha512-yJrczTy4HyIlE4mBOP/nF3mA51cDQyRBeX3aWHSd0TZpU3DWiEZBTUm8vHqta2KvfhMm/XP1k4V5JOzRQrcHJg==" + }, + "node_modules/@codefi/delegation-utils": { + "version": "0.4.0", + "resolved": "https://nexus.eu-west-3.codefi.network/repository/npm-hosted/@codefi/delegation-utils/-/delegation-utils-0.4.0.tgz", + "integrity": "sha512-jML+jywMXHI0Xlo26+seFXI8cEaX1TzLihF8N5BIrAzwQvSeF/ytpw0N1KgvkpSCTes11y6D7xsjLQ5JEp3cUg==", + "dependencies": { + "@codefi/delegation-abis": "^0.4.0", + "@codefi/delegation-deployments": "^0.4.0", + "buffer": "^6.0.3" + }, + "peerDependencies": { + "viem": ">=2.18.2 <3.0.0" + } + }, + "node_modules/@codefi/delegator-core-viem": { + "version": "0.4.0", + "resolved": "https://nexus.eu-west-3.codefi.network/repository/npm-hosted/@codefi/delegator-core-viem/-/delegator-core-viem-0.4.0.tgz", + "integrity": "sha512-Z3XiHth+U05u03HAzuvt6QrJFzqtmC2GU6a2nHDvIqurLmRXfGx4qH/B62vM93WcM3fhIgLQF9bDiqqoVu64XQ==", + "dependencies": { + "@codefi/delegation-utils": "^0.4.0", + "webauthn-p256": "^0.0.5" + }, + "peerDependencies": { + "viem": ">=2.18.2 <3.0.0" + } + }, + "node_modules/@codefi/delegator-core-viem/node_modules/webauthn-p256": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/webauthn-p256/-/webauthn-p256-0.0.5.tgz", + "integrity": "sha512-drMGNWKdaixZNobeORVIqq7k5DsRC9FnG201K2QjeOoQLmtSDaSsVZdkg6n5jUALJKcAG++zBPJXmv6hy0nWFg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/wevm" + } + ], + "license": "MIT", + "dependencies": { + "@noble/curves": "^1.4.0", + "@noble/hashes": "^1.4.0" + } + }, "node_modules/@coinbase/wallet-sdk": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/@coinbase/wallet-sdk/-/wallet-sdk-4.2.3.tgz", @@ -7362,9 +7413,9 @@ } }, "node_modules/abitype": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/abitype/-/abitype-1.0.6.tgz", - "integrity": "sha512-MMSqYh4+C/aVqI2RQaWqbvI4Kxo5cQV40WQ4QFtDnNzCkqChm8MuENhElmynZlO0qUy/ObkEUaXtKqYnx1Kp3A==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/abitype/-/abitype-1.0.7.tgz", + "integrity": "sha512-ZfYYSktDQUwc2eduYu8C4wOs+RDPmnRYMh7zNfzeMtGGgb0U+6tLGjixUic6mXf5xKKCcgT5Qp6cv39tOARVFw==", "license": "MIT", "funding": { "url": "https://github.com/sponsors/wevm" @@ -19468,11 +19519,13 @@ } }, "node_modules/permissionless": { - "version": "0.2.21", - "resolved": "https://registry.npmjs.org/permissionless/-/permissionless-0.2.21.tgz", - "integrity": "sha512-hNrRR/I5InbqkKgRBLhXQY5R0j9biqp688ECBxsW5AO99jOv9HPjz82EdRT87OG4XkCjO4AY20hi4ZPoc+XjRg==", + "version": "0.2.22", + "resolved": "https://registry.npmjs.org/permissionless/-/permissionless-0.2.22.tgz", + "integrity": "sha512-6pyXxSXomHXmCgwST4/MM0CM3ISBhj8R0Il+g46RlDOZgVOWwwQxaVmbbg7vZBNulIg5PYFjVaFCNISc2Ia2uA==", + "license": "MIT", "peerDependencies": { - "viem": "^2.21.22" + "viem": "^2.21.54", + "webauthn-p256": "0.0.10" } }, "node_modules/picocolors": { @@ -25516,21 +25569,22 @@ } }, "node_modules/viem": { - "version": "2.21.53", - "resolved": "https://registry.npmjs.org/viem/-/viem-2.21.53.tgz", - "integrity": "sha512-0pY8clBacAwzc59iV1vY4a6U4xvRlA5tAuhClJCKvqA6rXJzmNMMvxQ0EG79lkHr7WtBEruXz8nAmONXwnq4EQ==", + "version": "2.21.54", + "resolved": "https://registry.npmjs.org/viem/-/viem-2.21.54.tgz", + "integrity": "sha512-G9mmtbua3UtnVY9BqAtWdNp+3AO+oWhD0B9KaEsZb6gcrOWgmA4rz02yqEMg+qW9m6KgKGie7q3zcHqJIw6AqA==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/wevm" } ], + "license": "MIT", "dependencies": { - "@noble/curves": "1.6.0", - "@noble/hashes": "1.5.0", - "@scure/bip32": "1.5.0", - "@scure/bip39": "1.4.0", - "abitype": "1.0.6", + "@noble/curves": "1.7.0", + "@noble/hashes": "1.6.1", + "@scure/bip32": "1.6.0", + "@scure/bip39": "1.5.0", + "abitype": "1.0.7", "isows": "1.0.6", "ox": "0.1.2", "webauthn-p256": "0.0.10", @@ -25545,26 +25599,76 @@ } } }, + "node_modules/viem/node_modules/@noble/curves": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.7.0.tgz", + "integrity": "sha512-UTMhXK9SeDhFJVrHeUJ5uZlI6ajXg10O6Ddocf9S6GjbSBVZsJo88HzKwXznNfGpMTRDyJkqMjNDPYgf0qFWnw==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "1.6.0" + }, + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/viem/node_modules/@noble/curves/node_modules/@noble/hashes": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.0.tgz", + "integrity": "sha512-YUULf0Uk4/mAA89w+k3+yUYh6NrEvxZa5T6SY3wlMvE2chHkxFUUIDI8/XW1QSC357iA5pSnqt7XEhvFOqmDyQ==", + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/viem/node_modules/@noble/hashes": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.1.tgz", + "integrity": "sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==", + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/viem/node_modules/@scure/base": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.2.1.tgz", + "integrity": "sha512-DGmGtC8Tt63J5GfHgfl5CuAXh96VF/LD8K9Hr/Gv0J2lAoRGlPOMpqMpMbCTOoOJMZCk2Xt+DskdDyn6dEFdzQ==", + "license": "MIT", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/viem/node_modules/@scure/bip32": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.5.0.tgz", - "integrity": "sha512-8EnFYkqEQdnkuGBVpCzKxyIwDCBLDVj3oiX0EKUFre/tOjL/Hqba1D6n/8RcmaQy4f95qQFrO2A8Sr6ybh4NRw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.6.0.tgz", + "integrity": "sha512-82q1QfklrUUdXJzjuRU7iG7D7XiFx5PHYVS0+oeNKhyDLT7WPqs6pBcM2W5ZdwOwKCwoE1Vy1se+DHjcXwCYnA==", "license": "MIT", "dependencies": { - "@noble/curves": "~1.6.0", - "@noble/hashes": "~1.5.0", - "@scure/base": "~1.1.7" + "@noble/curves": "~1.7.0", + "@noble/hashes": "~1.6.0", + "@scure/base": "~1.2.1" }, "funding": { "url": "https://paulmillr.com/funding/" } }, "node_modules/viem/node_modules/@scure/bip39": { - "version": "1.4.0", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.5.0.tgz", + "integrity": "sha512-Dop+ASYhnrwm9+HA/HwXg7j2ZqM6yk2fyLWb5znexjctFY3+E+eU8cIWI0Pql0Qx4hPZCijlGq4OL71g+Uz30A==", "license": "MIT", "dependencies": { - "@noble/hashes": "~1.5.0", - "@scure/base": "~1.1.8" + "@noble/hashes": "~1.6.0", + "@scure/base": "~1.2.1" }, "funding": { "url": "https://paulmillr.com/funding/" @@ -27029,6 +27133,7 @@ "version": "9.5.0-alpha.2", "license": "ISC", "dependencies": { + "@codefi/delegator-core-viem": "^0.4.0", "@ethereumjs/util": "^9.1.0", "@toruslabs/base-controllers": "^6.3.2", "@web3auth/auth": "^9.5.3", @@ -27036,8 +27141,8 @@ "@web3auth/base-provider": "^9.5.0-alpha.1", "@web3auth/ethereum-provider": "^9.5.0-alpha.2", "ethers": "^6.13.4", - "permissionless": "^0.2.20", - "viem": "^2.21.52" + "permissionless": "^0.2.22", + "viem": "^2.21.54" }, "engines": { "node": ">=18.x", diff --git a/packages/providers/account-abstraction-provider/package.json b/packages/providers/account-abstraction-provider/package.json index cdba8ae39..6ab28f025 100644 --- a/packages/providers/account-abstraction-provider/package.json +++ b/packages/providers/account-abstraction-provider/package.json @@ -20,6 +20,7 @@ "pre-commit": "lint-staged --cwd ." }, "dependencies": { + "@codefi/delegator-core-viem": "^0.4.0", "@ethereumjs/util": "^9.1.0", "@toruslabs/base-controllers": "^6.3.2", "@web3auth/auth": "^9.5.3", diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/MetamaskSmartAccount.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/MetamaskSmartAccount.ts new file mode 100644 index 000000000..384fab544 --- /dev/null +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/MetamaskSmartAccount.ts @@ -0,0 +1,91 @@ +import { + HybridDeleGatorDeployParams, + HybridSignatoryConfig, + Implementation, + MultiSigDeleGatorDeployParams, + MultiSigSignatoryConfig, + toMetaMaskSmartAccount, + ToMetaMaskSmartAccountParameters, +} from "@codefi/delegator-core-viem"; +import { Client, Hex, WalletClient } from "viem"; +import { SmartAccount, WebAuthnAccount } from "viem/account-abstraction"; + +import { SMART_ACCOUNT } from "./constants"; +import { ISmartAccount } from "./types"; + +type MetamaskSmartAccountConfig = Partial< + Omit, "client" | "signatory" | "deployParams" | "address"> +> & { + hybridParams?: { + p256KeyIds?: string[]; + p256XValues?: bigint[]; + p256YValues?: bigint[]; + webAuthnAccount?: WebAuthnAccount; + keyId?: Hex; + }; + multiSigParams?: { + additionalSignerAddresses: Hex[]; + additonalSignerWalletClients: WalletClient[]; + threshold: bigint; + }; +}; + +function isImplementationHybrid(implementation: Implementation): implementation is Implementation.Hybrid { + return implementation === Implementation.Hybrid; +} + +export class MetamaskSmartAccount implements ISmartAccount { + readonly name: string = SMART_ACCOUNT.METAMASK; + + private options?: MetamaskSmartAccountConfig; + + constructor(options?: MetamaskSmartAccountConfig) { + this.options = options; + } + + async getSmartAccount(params: { client: Client; walletClient: WalletClient }): Promise { + const implementation: Implementation = this.options?.implementation ?? Implementation.Hybrid; + const [eoaAddress] = await params.walletClient.getAddresses(); + + const hybridDeployParams = [ + eoaAddress, + [...(this.options?.hybridParams?.p256KeyIds || [])], + [...(this.options?.hybridParams?.p256XValues || [])], + [...(this.options?.hybridParams?.p256YValues || [])], + ] as HybridDeleGatorDeployParams; + const multiSigDeployParams = [ + [eoaAddress, ...(this.options?.multiSigParams?.additionalSignerAddresses || [])], + this.options?.multiSigParams?.threshold ?? BigInt(1 + (this.options?.multiSigParams?.additonalSignerWalletClients?.length || 0)), + ] as MultiSigDeleGatorDeployParams; + + const hybridSignatory = { + walletClient: params.walletClient, + webAuthnAccount: this.options?.hybridParams?.webAuthnAccount, + keyId: this.options?.hybridParams?.keyId, + } as HybridSignatoryConfig; + const multiSigSignatory = [ + { + walletClient: params.walletClient, + }, + ...(this.options?.multiSigParams?.additonalSignerWalletClients || []).map((walletClient) => ({ + walletClient, + })), + ] as MultiSigSignatoryConfig; + + return toMetaMaskSmartAccount({ + ...this.options, + implementation, + client: params.client, + deploySalt: this.options?.deploySalt ?? "0x", + ...(isImplementationHybrid(implementation) + ? { + deployParams: hybridDeployParams, + signatory: hybridSignatory, + } + : { + deployParams: multiSigDeployParams, + signatory: multiSigSignatory, + }), + }); + } +} diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/constants.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/constants.ts index cad4566fd..6056341de 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/constants.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/constants.ts @@ -6,4 +6,5 @@ export const SMART_ACCOUNT = { SAFE: "safe", SIMPLE: "simple", TRUST: "trust", + METAMASK: "metamask", }; diff --git a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/index.ts b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/index.ts index 12eb12708..c0a0b621c 100644 --- a/packages/providers/account-abstraction-provider/src/providers/smartAccounts/index.ts +++ b/packages/providers/account-abstraction-provider/src/providers/smartAccounts/index.ts @@ -1,5 +1,6 @@ export * from "./BiconomySmartAccount"; export * from "./KernelSmartAccount"; +export * from "./MetamaskSmartAccount"; export * from "./NexusSmartAccount"; export * from "./SafeSmartAccount"; export * from "./TrustSmartAccount";