From 862a413680c19ec8d56a5c28ffc559f5fbad6851 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Tu Date: Tue, 10 Dec 2024 16:02:49 +0700 Subject: [PATCH] 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";