@toruslabs/ethereum-controllers 8.2.0 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/ethereumControllers.umd.min.js +1 -1
  2. package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +8 -1
  3. package/dist/lib.cjs/AccountAbstraction/smartAccounts/BiconomySmartAccount.js +1 -1
  4. package/dist/lib.cjs/AccountAbstraction/smartAccounts/KernelSmartAccount.js +1 -1
  5. package/dist/lib.cjs/AccountAbstraction/smartAccounts/MetamaskSmartAccount.js +54 -0
  6. package/dist/lib.cjs/AccountAbstraction/smartAccounts/NexusSmartAccount.js +1 -1
  7. package/dist/lib.cjs/AccountAbstraction/smartAccounts/SafeSmartAccount.js +1 -1
  8. package/dist/lib.cjs/AccountAbstraction/smartAccounts/TrustSmartAccount.js +1 -1
  9. package/dist/lib.cjs/index.js +2 -0
  10. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/BiconomySmartAccount.d.ts +2 -2
  11. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/KernelSmartAccount.d.ts +2 -2
  12. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/LightSmartAccount.d.ts +2 -2
  13. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/MetamaskSmartAccount.d.ts +28 -0
  14. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/NexusSmartAccount.d.ts +2 -2
  15. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/SafeSmartAccount.d.ts +2 -2
  16. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/SimpleSmartAccount.d.ts +2 -2
  17. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/TrustSmartAccount.d.ts +2 -2
  18. package/dist/lib.cjs/types/AccountAbstraction/smartAccounts/index.d.ts +1 -0
  19. package/dist/lib.cjs/types/utils/constants.d.ts +1 -0
  20. package/dist/lib.cjs/types/utils/helpers.d.ts +1 -1
  21. package/dist/lib.cjs/types/utils/interfaces.d.ts +2 -2
  22. package/dist/lib.cjs/utils/constants.js +2 -1
  23. package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +10 -2
  24. package/dist/lib.esm/AccountAbstraction/smartAccounts/BiconomySmartAccount.js +1 -1
  25. package/dist/lib.esm/AccountAbstraction/smartAccounts/KernelSmartAccount.js +1 -1
  26. package/dist/lib.esm/AccountAbstraction/smartAccounts/MetamaskSmartAccount.js +52 -0
  27. package/dist/lib.esm/AccountAbstraction/smartAccounts/NexusSmartAccount.js +1 -1
  28. package/dist/lib.esm/AccountAbstraction/smartAccounts/SafeSmartAccount.js +1 -1
  29. package/dist/lib.esm/AccountAbstraction/smartAccounts/TrustSmartAccount.js +1 -1
  30. package/dist/lib.esm/index.js +1 -0
  31. package/dist/lib.esm/utils/constants.js +2 -1
  32. package/package.json +8 -7
@@ -98,12 +98,19 @@ class AccountAbstractionController extends baseControllers.BaseController {
98
98
  chain,
99
99
  transport: viem.http(providerConfig.rpcTarget)
100
100
  });
101
+ // viem wallet client using json-rpc account from eoaProvider
101
102
  const aaEngine = new auth.JRPCEngine();
102
103
  aaEngine.push(eoaInterceptorMiddleware(eoaAddress));
103
104
  aaEngine.push(eoaProviderAsMiddleware(eoaProvider));
104
105
  const provider = auth.providerFromEngine(aaEngine);
106
+ // need to hoist the account address https://viem.sh/docs/clients/wallet#optional-hoist-the-account
107
+ const eoaWalletClient = viem.createWalletClient({
108
+ account: eoaAddress,
109
+ chain,
110
+ transport: viem.custom(provider)
111
+ });
105
112
  this._smartAccount = await this.config.smartAccountInit.getSmartAccount({
106
- owner: provider,
113
+ walletClient: eoaWalletClient,
107
114
  client: this._publicClient
108
115
  });
109
116
  if (this.config.paymasterConfig) {
@@ -20,7 +20,7 @@ class BiconomySmartAccount {
20
20
  version: ((_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.entryPoint) === null || _this$options2 === void 0 ? void 0 : _this$options2.version) || "0.6"
21
21
  }
22
22
  }, params), {}, {
23
- owners: [params.owner],
23
+ owners: [params.walletClient],
24
24
  client: params.client
25
25
  }));
26
26
  }
@@ -13,7 +13,7 @@ class KernelSmartAccount {
13
13
  }
14
14
  async getSmartAccount(params) {
15
15
  return accounts.toEcdsaKernelSmartAccount(_objectSpread(_objectSpread(_objectSpread({}, this.options || {}), params), {}, {
16
- owners: [params.owner],
16
+ owners: [params.walletClient],
17
17
  client: params.client
18
18
  }));
19
19
  }
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
+ var delegationToolkit = require('@metamask/delegation-toolkit');
6
+ var constants = require('../../utils/constants.js');
7
+
8
+ function isImplementationHybrid(implementation) {
9
+ return implementation === delegationToolkit.Implementation.Hybrid;
10
+ }
11
+ class MetamaskSmartAccount {
12
+ constructor(options) {
13
+ _defineProperty(this, "name", constants.SMART_ACCOUNT.METAMASK);
14
+ _defineProperty(this, "options", void 0);
15
+ this.options = options;
16
+ }
17
+ async getSmartAccount(input) {
18
+ var _this$options, _this$options2, _this$options3, _this$options4, _this$options5, _this$options6, _this$options7, _this$options$multiSi, _this$options8, _this$options9, _this$options$deployS;
19
+ const hybridSignatory = {
20
+ walletClient: input.walletClient,
21
+ webAuthnAccount: (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.hybridParams) === null || _this$options === void 0 ? void 0 : _this$options.webAuthnAccount,
22
+ keyId: (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.hybridParams) === null || _this$options2 === void 0 ? void 0 : _this$options2.keyId
23
+ };
24
+ const multiSigSignatory = [{
25
+ walletClient: input.walletClient
26
+ }, ...(((_this$options3 = this.options) === null || _this$options3 === void 0 || (_this$options3 = _this$options3.multiSigParams) === null || _this$options3 === void 0 ? void 0 : _this$options3.additionalSignerWalletClients) || []).map(walletClient => ({
27
+ walletClient
28
+ }))];
29
+ const [eoaAddress] = await input.walletClient.getAddresses();
30
+ const hybridDeployParams = [eoaAddress, [...(((_this$options4 = this.options) === null || _this$options4 === void 0 || (_this$options4 = _this$options4.hybridParams) === null || _this$options4 === void 0 ? void 0 : _this$options4.p256KeyIds) || [])], [...(((_this$options5 = this.options) === null || _this$options5 === void 0 || (_this$options5 = _this$options5.hybridParams) === null || _this$options5 === void 0 ? void 0 : _this$options5.p256XValues) || [])], [...(((_this$options6 = this.options) === null || _this$options6 === void 0 || (_this$options6 = _this$options6.hybridParams) === null || _this$options6 === void 0 ? void 0 : _this$options6.p256YValues) || [])]];
31
+ const multiSigDeployParams = [[eoaAddress, ...(((_this$options7 = this.options) === null || _this$options7 === void 0 || (_this$options7 = _this$options7.multiSigParams) === null || _this$options7 === void 0 ? void 0 : _this$options7.additionalSignerAddresses) || [])], (_this$options$multiSi = (_this$options8 = this.options) === null || _this$options8 === void 0 || (_this$options8 = _this$options8.multiSigParams) === null || _this$options8 === void 0 ? void 0 : _this$options8.threshold) !== null && _this$options$multiSi !== void 0 ? _this$options$multiSi : BigInt(1 + (((_this$options9 = this.options) === null || _this$options9 === void 0 || (_this$options9 = _this$options9.multiSigParams) === null || _this$options9 === void 0 || (_this$options9 = _this$options9.additionalSignerWalletClients) === null || _this$options9 === void 0 ? void 0 : _this$options9.length) || 0))];
32
+ const baseParams = {
33
+ client: input.client,
34
+ deploySalt: (_this$options$deployS = this.options.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
35
+ };
36
+ if (isImplementationHybrid(this.options.implementation)) {
37
+ const params = _objectSpread(_objectSpread({}, baseParams), {}, {
38
+ implementation: this.options.implementation,
39
+ deployParams: hybridDeployParams,
40
+ signatory: hybridSignatory
41
+ });
42
+ return delegationToolkit.toMetaMaskSmartAccount(params);
43
+ } else {
44
+ const params = _objectSpread(_objectSpread({}, baseParams), {}, {
45
+ implementation: this.options.implementation,
46
+ deployParams: multiSigDeployParams,
47
+ signatory: multiSigSignatory
48
+ });
49
+ return delegationToolkit.toMetaMaskSmartAccount(params);
50
+ }
51
+ }
52
+ }
53
+
54
+ exports.MetamaskSmartAccount = MetamaskSmartAccount;
@@ -21,7 +21,7 @@ class NexusSmartAccount {
21
21
  },
22
22
  version: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.version) || "1.0.0"
23
23
  }, params), {}, {
24
- owners: [params.owner],
24
+ owners: [params.walletClient],
25
25
  client: params.client
26
26
  }));
27
27
  }
@@ -21,7 +21,7 @@ class SafeSmartAccount {
21
21
  },
22
22
  version: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.version) || "1.4.1"
23
23
  }, params), {}, {
24
- owners: [params.owner],
24
+ owners: [params.walletClient],
25
25
  client: params.client
26
26
  }));
27
27
  }
@@ -20,7 +20,7 @@ class TrustSmartAccount {
20
20
  version: ((_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.entryPoint) === null || _this$options2 === void 0 ? void 0 : _this$options2.version) || "0.6"
21
21
  }
22
22
  }, params), {}, {
23
- owner: params.owner,
23
+ owner: params.walletClient,
24
24
  client: params.client
25
25
  }));
26
26
  }
@@ -4,6 +4,7 @@ var AccountTrackerController = require('./Account/AccountTrackerController.js');
4
4
  var AccountAbstractionController = require('./AccountAbstraction/AccountAbstractionController.js');
5
5
  var BiconomySmartAccount = require('./AccountAbstraction/smartAccounts/BiconomySmartAccount.js');
6
6
  var KernelSmartAccount = require('./AccountAbstraction/smartAccounts/KernelSmartAccount.js');
7
+ var MetamaskSmartAccount = require('./AccountAbstraction/smartAccounts/MetamaskSmartAccount.js');
7
8
  var NexusSmartAccount = require('./AccountAbstraction/smartAccounts/NexusSmartAccount.js');
8
9
  var SafeSmartAccount = require('./AccountAbstraction/smartAccounts/SafeSmartAccount.js');
9
10
  var TrustSmartAccount = require('./AccountAbstraction/smartAccounts/TrustSmartAccount.js');
@@ -46,6 +47,7 @@ exports.eoaInterceptorMiddleware = AccountAbstractionController.eoaInterceptorMi
46
47
  exports.eoaProviderAsMiddleware = AccountAbstractionController.eoaProviderAsMiddleware;
47
48
  exports.BiconomySmartAccount = BiconomySmartAccount.BiconomySmartAccount;
48
49
  exports.KernelSmartAccount = KernelSmartAccount.KernelSmartAccount;
50
+ exports.MetamaskSmartAccount = MetamaskSmartAccount.MetamaskSmartAccount;
49
51
  exports.NexusSmartAccount = NexusSmartAccount.NexusSmartAccount;
50
52
  exports.SafeSmartAccount = SafeSmartAccount.SafeSmartAccount;
51
53
  exports.TrustSmartAccount = TrustSmartAccount.TrustSmartAccount;
@@ -1,5 +1,5 @@
1
1
  import { ToBiconomySmartAccountParameters } from "permissionless/accounts";
2
- import { Client, EIP1193Provider } from "viem";
2
+ import { Client, WalletClient } from "viem";
3
3
  import { SmartAccount } from "viem/account-abstraction";
4
4
  import { BiconomySmartAccountConfig, ISmartAccount } from "../../utils/interfaces";
5
5
  export declare class BiconomySmartAccount implements ISmartAccount {
@@ -7,7 +7,7 @@ export declare class BiconomySmartAccount implements ISmartAccount {
7
7
  private options;
8
8
  constructor(options?: BiconomySmartAccountConfig);
9
9
  getSmartAccount(params: {
10
- owner: EIP1193Provider;
10
+ walletClient: WalletClient;
11
11
  client: Client;
12
12
  } & Pick<ToBiconomySmartAccountParameters, "index" | "nonceKey" | "address">): Promise<SmartAccount>;
13
13
  }
@@ -1,4 +1,4 @@
1
- import { Client, EIP1193Provider } from "viem";
1
+ import { Client, WalletClient } from "viem";
2
2
  import { SmartAccount } from "viem/account-abstraction";
3
3
  import { ISmartAccount, KernelSmartAccountConfig, KernelSmartAccountParameters } from "../../utils/interfaces";
4
4
  export declare class KernelSmartAccount implements ISmartAccount {
@@ -6,7 +6,7 @@ export declare class KernelSmartAccount implements ISmartAccount {
6
6
  private options;
7
7
  constructor(options?: KernelSmartAccountConfig);
8
8
  getSmartAccount(params: {
9
- owner: EIP1193Provider;
9
+ walletClient: WalletClient;
10
10
  client: Client;
11
11
  } & Pick<KernelSmartAccountParameters, "address" | "nonceKey" | "index">): Promise<SmartAccount>;
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import { ToLightSmartAccountParameters } from "permissionless/accounts";
2
- import { Client, EIP1193Provider } from "viem";
2
+ import { Client, WalletClient } from "viem";
3
3
  import { SmartAccount } from "viem/account-abstraction";
4
4
  import { ISmartAccount, LightSmartAccountConfig } from "../../utils/interfaces";
5
5
  export declare class LightSmartAccount implements ISmartAccount {
@@ -7,7 +7,7 @@ export declare class LightSmartAccount implements ISmartAccount {
7
7
  private options;
8
8
  constructor(options?: LightSmartAccountConfig);
9
9
  getSmartAccount(params: {
10
- owner: EIP1193Provider;
10
+ walletClient: WalletClient;
11
11
  client: Client;
12
12
  } & Pick<ToLightSmartAccountParameters, "address" | "index" | "nonceKey">): Promise<SmartAccount>;
13
13
  }
@@ -0,0 +1,28 @@
1
+ import { Implementation, ToMetaMaskSmartAccountParameters } from "@metamask/delegation-toolkit";
2
+ import { Client, Hex, WalletClient } from "viem";
3
+ import { SmartAccount, WebAuthnAccount } from "viem/account-abstraction";
4
+ import { ISmartAccount } from "../../utils/interfaces";
5
+ type MetamaskSmartAccountConfig<TImplementation extends Implementation> = Omit<ToMetaMaskSmartAccountParameters<TImplementation>, "client" | "signatory" | "deployParams"> & {
6
+ hybridParams?: {
7
+ p256KeyIds?: string[];
8
+ p256XValues?: bigint[];
9
+ p256YValues?: bigint[];
10
+ webAuthnAccount?: WebAuthnAccount;
11
+ keyId?: Hex;
12
+ };
13
+ multiSigParams?: {
14
+ additionalSignerAddresses: Hex[];
15
+ additionalSignerWalletClients: WalletClient[];
16
+ threshold: bigint;
17
+ };
18
+ };
19
+ export declare class MetamaskSmartAccount<TImplementation extends Implementation> implements ISmartAccount {
20
+ readonly name: string;
21
+ private options;
22
+ constructor(options?: MetamaskSmartAccountConfig<TImplementation>);
23
+ getSmartAccount(input: {
24
+ walletClient: WalletClient;
25
+ client: Client;
26
+ }): Promise<SmartAccount>;
27
+ }
28
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { ToNexusSmartAccountParameters } from "permissionless/accounts";
2
- import { Client, EIP1193Provider } from "viem";
2
+ import { Client, WalletClient } from "viem";
3
3
  import { SmartAccount } from "viem/account-abstraction";
4
4
  import { ISmartAccount, NexusSmartAccountConfig } from "../../utils/interfaces";
5
5
  export declare class NexusSmartAccount implements ISmartAccount {
@@ -7,7 +7,7 @@ export declare class NexusSmartAccount implements ISmartAccount {
7
7
  private options;
8
8
  constructor(options?: NexusSmartAccountConfig);
9
9
  getSmartAccount(params: {
10
- owner: EIP1193Provider;
10
+ walletClient: WalletClient;
11
11
  client: Client;
12
12
  } & Pick<ToNexusSmartAccountParameters, "index" | "address">): Promise<SmartAccount>;
13
13
  }
@@ -1,4 +1,4 @@
1
- import { Client, EIP1193Provider } from "viem";
1
+ import { Client, WalletClient } from "viem";
2
2
  import { SmartAccount } from "viem/account-abstraction";
3
3
  import { ISmartAccount, SafeSmartAccountConfig, SafeSmartAccountParameters } from "../../utils/interfaces";
4
4
  export declare class SafeSmartAccount implements ISmartAccount {
@@ -6,7 +6,7 @@ export declare class SafeSmartAccount implements ISmartAccount {
6
6
  private options;
7
7
  constructor(options?: SafeSmartAccountConfig);
8
8
  getSmartAccount(params: {
9
- owner: EIP1193Provider;
9
+ walletClient: WalletClient;
10
10
  client: Client;
11
11
  } & Pick<SafeSmartAccountParameters, "address" | "nonceKey" | "saltNonce" | "validUntil" | "validAfter">): Promise<SmartAccount>;
12
12
  }
@@ -1,4 +1,4 @@
1
- import { Client, EIP1193Provider } from "viem";
1
+ import { Client, WalletClient } from "viem";
2
2
  import { SmartAccount } from "viem/account-abstraction";
3
3
  import { ISmartAccount, SimpleSmartAccountConfig } from "../../utils/interfaces";
4
4
  export declare class SimpleSmartAccount implements ISmartAccount {
@@ -6,7 +6,7 @@ export declare class SimpleSmartAccount implements ISmartAccount {
6
6
  private options;
7
7
  constructor(options?: SimpleSmartAccountConfig);
8
8
  getSmartAccount(params: {
9
- owner: EIP1193Provider;
9
+ walletClient: WalletClient;
10
10
  client: Client;
11
11
  }): Promise<SmartAccount>;
12
12
  }
@@ -1,4 +1,4 @@
1
- import { Client, EIP1193Provider } from "viem";
1
+ import { Client, WalletClient } from "viem";
2
2
  import { SmartAccount } from "viem/account-abstraction";
3
3
  import { ISmartAccount, TrustSmartAccountConfig, TrustSmartAccountParameters } from "../../utils/interfaces";
4
4
  export declare class TrustSmartAccount implements ISmartAccount {
@@ -6,7 +6,7 @@ export declare class TrustSmartAccount implements ISmartAccount {
6
6
  private options;
7
7
  constructor(options?: TrustSmartAccountConfig);
8
8
  getSmartAccount(params: {
9
- owner: EIP1193Provider;
9
+ walletClient: WalletClient;
10
10
  client: Client;
11
11
  } & Pick<TrustSmartAccountParameters, "address" | "nonceKey" | "index">): Promise<SmartAccount>;
12
12
  }
@@ -1,5 +1,6 @@
1
1
  export * from "./BiconomySmartAccount";
2
2
  export * from "./KernelSmartAccount";
3
+ export * from "./MetamaskSmartAccount";
3
4
  export * from "./NexusSmartAccount";
4
5
  export * from "./SafeSmartAccount";
5
6
  export * from "./TrustSmartAccount";
@@ -83,4 +83,5 @@ export declare const SMART_ACCOUNT: {
83
83
  LIGHT: string;
84
84
  SIMPLE: string;
85
85
  NEXUS: string;
86
+ METAMASK: string;
86
87
  };
@@ -25,7 +25,7 @@ export declare const GAS_LIMITS: {
25
25
  export declare function bnLessThan(a: string | number, b: string | number): boolean;
26
26
  export declare const getIpfsEndpoint: (path: string) => string;
27
27
  export declare function sanitizeNftMetdataUrl(url: string): string;
28
- export declare function getChainType(chainId: string): "mainnet" | "testnet" | "custom";
28
+ export declare function getChainType(chainId: string): "custom" | "mainnet" | "testnet";
29
29
  export declare const addEtherscanTransactions: (params: {
30
30
  txn: EtherscanTransaction[];
31
31
  lowerCaseSelectedAddress: string;
@@ -3,7 +3,7 @@ import { JRPCRequest, Json } from "@web3auth/auth";
3
3
  import { MutexInterface } from "async-mutex";
4
4
  import { AccessList, TypedDataDomain, TypedDataField } from "ethers";
5
5
  import { ToBiconomySmartAccountParameters, toEcdsaKernelSmartAccount, ToLightSmartAccountParameters, ToNexusSmartAccountParameters, toSafeSmartAccount, toSimpleSmartAccount, toTrustSmartAccount } from "permissionless/accounts";
6
- import { Client, EIP1193Provider } from "viem";
6
+ import { Client, WalletClient } from "viem";
7
7
  import { createBundlerClient, createPaymasterClient, SmartAccount, UserOperationReceipt } from "viem/account-abstraction";
8
8
  import { METHOD_TYPES, SMART_ACCOUNT, TRANSACTION_ENVELOPE_TYPES } from "./constants";
9
9
  export type CustomTokenInfo = BaseTokenInfo & {
@@ -444,7 +444,7 @@ export type TrustSmartAccountParameters = Parameters<typeof toTrustSmartAccount>
444
444
  export type TrustSmartAccountConfig = Omit<TrustSmartAccountParameters, "owner" | "client" | "address" | "nonceKey" | "index">;
445
445
  export interface ISmartAccount {
446
446
  getSmartAccount(params: {
447
- owner: EIP1193Provider;
447
+ walletClient: WalletClient;
448
448
  client: Client;
449
449
  }): Promise<SmartAccount>;
450
450
  }
@@ -334,7 +334,8 @@ const SMART_ACCOUNT = {
334
334
  // TODO: disabled because of pimlico issues
335
335
  LIGHT: "light",
336
336
  SIMPLE: "simple",
337
- NEXUS: "nexus"
337
+ NEXUS: "nexus",
338
+ METAMASK: "metamask"
338
339
  };
339
340
 
340
341
  exports.ARBITRUM_MAINNET_CHAIN_ID = ARBITRUM_MAINNET_CHAIN_ID;
@@ -5,7 +5,7 @@ import { BaseController, TransactionStatus } from '@toruslabs/base-controllers';
5
5
  import { JRPCEngine, providerFromEngine } from '@web3auth/auth';
6
6
  import { isHexString } from 'ethers';
7
7
  import log from 'loglevel';
8
- import { defineChain, createPublicClient, http, createWalletClient, parseEther, toHex } from 'viem';
8
+ import { defineChain, createPublicClient, http, createWalletClient, custom, parseEther, toHex } from 'viem';
9
9
  import { createPaymasterClient, createBundlerClient } from 'viem/account-abstraction';
10
10
 
11
11
  const eoaInterceptorMiddleware = eoaAddress => (req, res, next, end) => {
@@ -96,12 +96,20 @@ class AccountAbstractionController extends BaseController {
96
96
  chain,
97
97
  transport: http(providerConfig.rpcTarget)
98
98
  });
99
+
100
+ // viem wallet client using json-rpc account from eoaProvider
99
101
  const aaEngine = new JRPCEngine();
100
102
  aaEngine.push(eoaInterceptorMiddleware(eoaAddress));
101
103
  aaEngine.push(eoaProviderAsMiddleware(eoaProvider));
102
104
  const provider = providerFromEngine(aaEngine);
105
+ // need to hoist the account address https://viem.sh/docs/clients/wallet#optional-hoist-the-account
106
+ const eoaWalletClient = createWalletClient({
107
+ account: eoaAddress,
108
+ chain,
109
+ transport: custom(provider)
110
+ });
103
111
  this._smartAccount = await this.config.smartAccountInit.getSmartAccount({
104
- owner: provider,
112
+ walletClient: eoaWalletClient,
105
113
  client: this._publicClient
106
114
  });
107
115
  if (this.config.paymasterConfig) {
@@ -18,7 +18,7 @@ class BiconomySmartAccount {
18
18
  version: ((_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.entryPoint) === null || _this$options2 === void 0 ? void 0 : _this$options2.version) || "0.6"
19
19
  }
20
20
  }, params), {}, {
21
- owners: [params.owner],
21
+ owners: [params.walletClient],
22
22
  client: params.client
23
23
  }));
24
24
  }
@@ -11,7 +11,7 @@ class KernelSmartAccount {
11
11
  }
12
12
  async getSmartAccount(params) {
13
13
  return toEcdsaKernelSmartAccount(_objectSpread(_objectSpread(_objectSpread({}, this.options || {}), params), {}, {
14
- owners: [params.owner],
14
+ owners: [params.walletClient],
15
15
  client: params.client
16
16
  }));
17
17
  }
@@ -0,0 +1,52 @@
1
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
+ import { toMetaMaskSmartAccount, Implementation } from '@metamask/delegation-toolkit';
4
+ import { SMART_ACCOUNT } from '../../utils/constants.js';
5
+
6
+ function isImplementationHybrid(implementation) {
7
+ return implementation === Implementation.Hybrid;
8
+ }
9
+ class MetamaskSmartAccount {
10
+ constructor(options) {
11
+ _defineProperty(this, "name", SMART_ACCOUNT.METAMASK);
12
+ _defineProperty(this, "options", void 0);
13
+ this.options = options;
14
+ }
15
+ async getSmartAccount(input) {
16
+ var _this$options, _this$options2, _this$options3, _this$options4, _this$options5, _this$options6, _this$options7, _this$options$multiSi, _this$options8, _this$options9, _this$options$deployS;
17
+ const hybridSignatory = {
18
+ walletClient: input.walletClient,
19
+ webAuthnAccount: (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.hybridParams) === null || _this$options === void 0 ? void 0 : _this$options.webAuthnAccount,
20
+ keyId: (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.hybridParams) === null || _this$options2 === void 0 ? void 0 : _this$options2.keyId
21
+ };
22
+ const multiSigSignatory = [{
23
+ walletClient: input.walletClient
24
+ }, ...(((_this$options3 = this.options) === null || _this$options3 === void 0 || (_this$options3 = _this$options3.multiSigParams) === null || _this$options3 === void 0 ? void 0 : _this$options3.additionalSignerWalletClients) || []).map(walletClient => ({
25
+ walletClient
26
+ }))];
27
+ const [eoaAddress] = await input.walletClient.getAddresses();
28
+ const hybridDeployParams = [eoaAddress, [...(((_this$options4 = this.options) === null || _this$options4 === void 0 || (_this$options4 = _this$options4.hybridParams) === null || _this$options4 === void 0 ? void 0 : _this$options4.p256KeyIds) || [])], [...(((_this$options5 = this.options) === null || _this$options5 === void 0 || (_this$options5 = _this$options5.hybridParams) === null || _this$options5 === void 0 ? void 0 : _this$options5.p256XValues) || [])], [...(((_this$options6 = this.options) === null || _this$options6 === void 0 || (_this$options6 = _this$options6.hybridParams) === null || _this$options6 === void 0 ? void 0 : _this$options6.p256YValues) || [])]];
29
+ const multiSigDeployParams = [[eoaAddress, ...(((_this$options7 = this.options) === null || _this$options7 === void 0 || (_this$options7 = _this$options7.multiSigParams) === null || _this$options7 === void 0 ? void 0 : _this$options7.additionalSignerAddresses) || [])], (_this$options$multiSi = (_this$options8 = this.options) === null || _this$options8 === void 0 || (_this$options8 = _this$options8.multiSigParams) === null || _this$options8 === void 0 ? void 0 : _this$options8.threshold) !== null && _this$options$multiSi !== void 0 ? _this$options$multiSi : BigInt(1 + (((_this$options9 = this.options) === null || _this$options9 === void 0 || (_this$options9 = _this$options9.multiSigParams) === null || _this$options9 === void 0 || (_this$options9 = _this$options9.additionalSignerWalletClients) === null || _this$options9 === void 0 ? void 0 : _this$options9.length) || 0))];
30
+ const baseParams = {
31
+ client: input.client,
32
+ deploySalt: (_this$options$deployS = this.options.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
33
+ };
34
+ if (isImplementationHybrid(this.options.implementation)) {
35
+ const params = _objectSpread(_objectSpread({}, baseParams), {}, {
36
+ implementation: this.options.implementation,
37
+ deployParams: hybridDeployParams,
38
+ signatory: hybridSignatory
39
+ });
40
+ return toMetaMaskSmartAccount(params);
41
+ } else {
42
+ const params = _objectSpread(_objectSpread({}, baseParams), {}, {
43
+ implementation: this.options.implementation,
44
+ deployParams: multiSigDeployParams,
45
+ signatory: multiSigSignatory
46
+ });
47
+ return toMetaMaskSmartAccount(params);
48
+ }
49
+ }
50
+ }
51
+
52
+ export { MetamaskSmartAccount };
@@ -19,7 +19,7 @@ class NexusSmartAccount {
19
19
  },
20
20
  version: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.version) || "1.0.0"
21
21
  }, params), {}, {
22
- owners: [params.owner],
22
+ owners: [params.walletClient],
23
23
  client: params.client
24
24
  }));
25
25
  }
@@ -19,7 +19,7 @@ class SafeSmartAccount {
19
19
  },
20
20
  version: ((_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.version) || "1.4.1"
21
21
  }, params), {}, {
22
- owners: [params.owner],
22
+ owners: [params.walletClient],
23
23
  client: params.client
24
24
  }));
25
25
  }
@@ -18,7 +18,7 @@ class TrustSmartAccount {
18
18
  version: ((_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.entryPoint) === null || _this$options2 === void 0 ? void 0 : _this$options2.version) || "0.6"
19
19
  }
20
20
  }, params), {}, {
21
- owner: params.owner,
21
+ owner: params.walletClient,
22
22
  client: params.client
23
23
  }));
24
24
  }
@@ -32,6 +32,7 @@ export { addCurrencies, conversionGTE, conversionGreaterThan, conversionLTE, con
32
32
  export { BNToHex, GAS_LIMITS, addEtherscanTransactions, bnLessThan, formatDate, formatPastTx, formatTime, getChainType, getEthTxStatus, getEtherScanHashLink, getIpfsEndpoint, hexToBn, isAddressByChainId, sanitizeNftMetdataUrl, toChecksumAddressByChainId } from './utils/helpers.js';
33
33
  export { BiconomySmartAccount } from './AccountAbstraction/smartAccounts/BiconomySmartAccount.js';
34
34
  export { KernelSmartAccount } from './AccountAbstraction/smartAccounts/KernelSmartAccount.js';
35
+ export { MetamaskSmartAccount } from './AccountAbstraction/smartAccounts/MetamaskSmartAccount.js';
35
36
  export { NexusSmartAccount } from './AccountAbstraction/smartAccounts/NexusSmartAccount.js';
36
37
  export { SafeSmartAccount } from './AccountAbstraction/smartAccounts/SafeSmartAccount.js';
37
38
  export { TrustSmartAccount } from './AccountAbstraction/smartAccounts/TrustSmartAccount.js';
@@ -333,7 +333,8 @@ const SMART_ACCOUNT = {
333
333
  // TODO: disabled because of pimlico issues
334
334
  LIGHT: "light",
335
335
  SIMPLE: "simple",
336
- NEXUS: "nexus"
336
+ NEXUS: "nexus",
337
+ METAMASK: "metamask"
337
338
  };
338
339
 
339
340
  export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ETH, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "8.2.0",
3
+ "version": "8.3.0",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "sideEffects": false,
@@ -20,11 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@ethereumjs/util": "^9.1.0",
23
- "@toruslabs/base-controllers": "^8.1.0",
23
+ "@metamask/delegation-toolkit": "^0.9.0",
24
+ "@toruslabs/base-controllers": "^8.3.0",
24
25
  "@toruslabs/http-helpers": "^8.1.1",
25
- "@web3auth/auth": "^10.2.3",
26
+ "@web3auth/auth": "^10.4.0",
26
27
  "async-mutex": "^0.5.0",
27
- "bignumber.js": "^9.1.2",
28
+ "bignumber.js": "^9.2.1",
28
29
  "bn.js": "^5.2.1",
29
30
  "deepmerge": "^4.3.1",
30
31
  "ethers": "^6.13.5",
@@ -32,8 +33,8 @@
32
33
  "fast-safe-stringify": "^2.1.1",
33
34
  "jsonschema": "^1.5.0",
34
35
  "loglevel": "^1.9.2",
35
- "permissionless": "^0.2.38",
36
- "viem": "^2.23.15"
36
+ "permissionless": "^0.2.41",
37
+ "viem": "^2.26.5"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "@babel/runtime": "7.x"
@@ -62,7 +63,7 @@
62
63
  "publishConfig": {
63
64
  "access": "public"
64
65
  },
65
- "gitHead": "ca2533b18b1b9783d87b76f412d2a9ef0873f8c8",
66
+ "gitHead": "2a59a607de44fd524f284cf61584861b5f798f25",
66
67
  "devDependencies": {
67
68
  "@typechain/ethers-v6": "^0.5.1",
68
69
  "typechain": "^8.3.2"