@toruslabs/ethereum-controllers 8.13.0 → 8.15.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.
@@ -28,6 +28,8 @@
28
28
 
29
29
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
30
30
 
31
+ /*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
32
+
31
33
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
32
34
 
33
35
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
@@ -36,6 +38,8 @@
36
38
 
37
39
  /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
38
40
 
41
+ /*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
42
+
39
43
  /**
40
44
  * @license
41
45
  * Lodash <https://lodash.com/>
@@ -130,7 +130,6 @@ class AccountAbstractionController extends baseControllers.BaseController {
130
130
  throw new Error("Invalid address");
131
131
  }
132
132
  const txParams = tx;
133
- // @ts-expect-error TODO: viem types are too deep
134
133
  const userOperationParams = {
135
134
  account: this.smartAccount,
136
135
  calls: [{
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- var delegationToolkit = require('@metamask/delegation-toolkit');
5
+ var smartAccountsKit = require('@metamask/smart-accounts-kit');
6
6
  var constants = require('../../utils/constants.js');
7
7
 
8
8
  class MetamaskSmartAccount {
@@ -28,21 +28,21 @@ class MetamaskSmartAccount {
28
28
  client: input.client,
29
29
  deploySalt: (_this$options$deployS = (_this$options0 = this.options) === null || _this$options0 === void 0 ? void 0 : _this$options0.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
30
30
  };
31
- const implementation = (_this$options$impleme = (_this$options1 = this.options) === null || _this$options1 === void 0 ? void 0 : _this$options1.implementation) !== null && _this$options$impleme !== void 0 ? _this$options$impleme : delegationToolkit.Implementation.Hybrid;
32
- if (implementation === delegationToolkit.Implementation.Hybrid) {
31
+ const implementation = (_this$options$impleme = (_this$options1 = this.options) === null || _this$options1 === void 0 ? void 0 : _this$options1.implementation) !== null && _this$options$impleme !== void 0 ? _this$options$impleme : smartAccountsKit.Implementation.Hybrid;
32
+ if (implementation === smartAccountsKit.Implementation.Hybrid) {
33
33
  const params = _objectSpread(_objectSpread({}, baseParams), {}, {
34
34
  implementation,
35
35
  deployParams: hybridDeployParams,
36
36
  signer: hybridSignatory
37
37
  });
38
- return delegationToolkit.toMetaMaskSmartAccount(params);
39
- } else if (implementation === delegationToolkit.Implementation.MultiSig) {
38
+ return smartAccountsKit.toMetaMaskSmartAccount(params);
39
+ } else if (implementation === smartAccountsKit.Implementation.MultiSig) {
40
40
  const params = _objectSpread(_objectSpread({}, baseParams), {}, {
41
41
  implementation,
42
42
  deployParams: multiSigDeployParams,
43
43
  signer: multiSigSignatory
44
44
  });
45
- return delegationToolkit.toMetaMaskSmartAccount(params);
45
+ return smartAccountsKit.toMetaMaskSmartAccount(params);
46
46
  } else {
47
47
  throw new Error(`MetamaskSmartAccount - unsupported implementation: ${implementation}`);
48
48
  }
@@ -3,6 +3,7 @@
3
3
  var baseControllers = require('@toruslabs/base-controllers');
4
4
  var auth = require('@web3auth/auth');
5
5
  var constants = require('../utils/constants.js');
6
+ var transaction = require('../utils/transaction.js');
6
7
 
7
8
  function createGetAccountsMiddleware({
8
9
  getAccounts
@@ -321,7 +322,8 @@ function createAAMiddleware({
321
322
  const bundlerFetchMiddleware = baseControllers.createFetchMiddleware({
322
323
  rpcTarget: bundlerUrl,
323
324
  providerConfig,
324
- analytics
325
+ analytics,
326
+ transactionDecoder: transaction.transactionDecoder
325
327
  });
326
328
  middlewares.push(idNumberRemapMiddleware);
327
329
  middlewares.push((request, response, next, end) => {
@@ -334,7 +336,8 @@ function createAAMiddleware({
334
336
  const paymasterFetchMiddleware = baseControllers.createFetchMiddleware({
335
337
  rpcTarget: paymasterUrl,
336
338
  providerConfig,
337
- analytics
339
+ analytics,
340
+ transactionDecoder: transaction.transactionDecoder
338
341
  });
339
342
  middlewares.push((request, response, next, end) => {
340
343
  if (!constants.PAYMASTER_METHOD_TYPES.includes(request.method)) {
@@ -4,6 +4,7 @@ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var baseControllers = require('@toruslabs/base-controllers');
5
5
  var auth = require('@web3auth/auth');
6
6
  var PollingBlockTracker = require('../Block/PollingBlockTracker.js');
7
+ var transaction = require('../utils/transaction.js');
7
8
  var cacheIdentifier = require('./cacheIdentifier.js');
8
9
 
9
10
  function createChainIdMiddleware(chainId) {
@@ -37,7 +38,8 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
37
38
  const fetchMiddleware = baseControllers.createFetchMiddleware({
38
39
  rpcTarget,
39
40
  providerConfig,
40
- analytics
41
+ analytics,
42
+ transactionDecoder: transaction.transactionDecoder
41
43
  });
42
44
  const blockProvider = auth.providerFromMiddleware(fetchMiddleware);
43
45
  const blockTracker = new PollingBlockTracker.PollingBlockTracker({
@@ -1,4 +1,4 @@
1
- import { Implementation } from "@metamask/delegation-toolkit";
1
+ import { Implementation } from "@metamask/smart-accounts-kit";
2
2
  import { Client, WalletClient } from "viem";
3
3
  import { SmartAccount } from "viem/account-abstraction";
4
4
  import { ISmartAccount, MetamaskSmartAccountConfig } from "../../utils/interfaces";
@@ -1,4 +1,4 @@
1
- import { Implementation, toMetaMaskSmartAccount } from "@metamask/delegation-toolkit";
1
+ import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit";
2
2
  import { BASE_TX_EVENT_TYPE, BaseBlockTrackerState, BaseControllerEvents, BaseFormattedTransactionActivity, BaseTokenInfo, BaseTransactionEvents, MESSAGE_EVENTS, MessageStatus, NetworkConfig, NetworkState, PaymentTransaction, PollingBlockTrackerConfig, PopupWhitelabelData, ProviderConfig, TRANSACTION_TYPE, TransactionMeta, TransactionState, TransactionStatus, TX_CONFIRMED_EVENT_TYPE, TX_DROPPED_EVENT_TYPE, TX_EVENTS, TX_FAILED_EVENT_TYPE, TX_WARNING_EVENT_TYPE, User } from "@toruslabs/base-controllers";
3
3
  import { JRPCRequest, Json } from "@web3auth/auth";
4
4
  import { MutexInterface } from "async-mutex";
@@ -0,0 +1,6 @@
1
+ import { JRPCRequest } from "@web3auth/auth";
2
+ /**
3
+ * Transaction decoder for analytics.
4
+ * Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
5
+ */
6
+ export declare const transactionDecoder: (req: JRPCRequest<unknown>, chainId: string) => [string, string];
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var common = require('@ethereumjs/common');
4
+ var tx = require('@ethereumjs/tx');
5
+ var util = require('@ethereumjs/util');
6
+ var log = require('loglevel');
7
+ var constants = require('./constants.js');
8
+
9
+ /**
10
+ * Transaction decoder for analytics.
11
+ * Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
12
+ */
13
+ const transactionDecoder = (req, chainId) => {
14
+ let sender = "";
15
+ let txHash = "";
16
+ try {
17
+ if (req.method === constants.METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
18
+ const rawTx = req.params[0];
19
+ const txBytes = util.hexToBytes(util.addHexPrefix(rawTx));
20
+ const tx$1 = tx.createTxFromRLP(txBytes, {
21
+ common: common.createCustomCommon({
22
+ chainId
23
+ }, common.Mainnet)
24
+ });
25
+ sender = tx$1.getSenderAddress().toString();
26
+ txHash = util.bytesToHex(tx$1.hash());
27
+ } else if (req.method === constants.METHOD_TYPES.ETH_SEND_USER_OPERATION) {
28
+ const userOpReq = req;
29
+ sender = userOpReq.params.map(p => p.sender).join(",");
30
+ }
31
+ } catch (error) {
32
+ log.error("Error decoding transaction", error, {
33
+ req,
34
+ chainId
35
+ });
36
+ }
37
+ return [sender, txHash];
38
+ };
39
+
40
+ exports.transactionDecoder = transactionDecoder;
@@ -129,7 +129,6 @@ class AccountAbstractionController extends BaseController {
129
129
  throw new Error("Invalid address");
130
130
  }
131
131
  const txParams = tx;
132
- // @ts-expect-error TODO: viem types are too deep
133
132
  const userOperationParams = {
134
133
  account: this.smartAccount,
135
134
  calls: [{
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit';
3
+ import { Implementation, toMetaMaskSmartAccount } from '@metamask/smart-accounts-kit';
4
4
  import { SMART_ACCOUNT } from '../../utils/constants.js';
5
5
 
6
6
  class MetamaskSmartAccount {
@@ -1,6 +1,7 @@
1
1
  import { PROVIDER_JRPC_METHODS, createFetchMiddleware, createGenericJRPCMiddleware } from '@toruslabs/base-controllers';
2
2
  import { createAsyncMiddleware, mergeMiddleware, createScaffoldMiddleware } from '@web3auth/auth';
3
3
  import { METHOD_TYPES, TRANSACTION_ENVELOPE_TYPES, BUNDLER_METHOD_TYPES, PAYMASTER_METHOD_TYPES } from '../utils/constants.js';
4
+ import { transactionDecoder } from '../utils/transaction.js';
4
5
 
5
6
  function createGetAccountsMiddleware({
6
7
  getAccounts
@@ -321,7 +322,8 @@ function createAAMiddleware({
321
322
  const bundlerFetchMiddleware = createFetchMiddleware({
322
323
  rpcTarget: bundlerUrl,
323
324
  providerConfig,
324
- analytics
325
+ analytics,
326
+ transactionDecoder
325
327
  });
326
328
  middlewares.push(idNumberRemapMiddleware);
327
329
  middlewares.push((request, response, next, end) => {
@@ -334,7 +336,8 @@ function createAAMiddleware({
334
336
  const paymasterFetchMiddleware = createFetchMiddleware({
335
337
  rpcTarget: paymasterUrl,
336
338
  providerConfig,
337
- analytics
339
+ analytics,
340
+ transactionDecoder
338
341
  });
339
342
  middlewares.push((request, response, next, end) => {
340
343
  if (!PAYMASTER_METHOD_TYPES.includes(request.method)) {
@@ -2,6 +2,7 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import { createFetchMiddleware, createInflightCacheMiddleware } from '@toruslabs/base-controllers';
3
3
  import { providerFromMiddleware, mergeMiddleware } from '@web3auth/auth';
4
4
  import { PollingBlockTracker } from '../Block/PollingBlockTracker.js';
5
+ import { transactionDecoder } from '../utils/transaction.js';
5
6
  import { cacheIdentifierForRequest } from './cacheIdentifier.js';
6
7
 
7
8
  function createChainIdMiddleware(chainId) {
@@ -35,7 +36,8 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
35
36
  const fetchMiddleware = createFetchMiddleware({
36
37
  rpcTarget,
37
38
  providerConfig,
38
- analytics
39
+ analytics,
40
+ transactionDecoder
39
41
  });
40
42
  const blockProvider = providerFromMiddleware(fetchMiddleware);
41
43
  const blockTracker = new PollingBlockTracker({
@@ -0,0 +1,38 @@
1
+ import { createCustomCommon, Mainnet } from '@ethereumjs/common';
2
+ import { createTxFromRLP } from '@ethereumjs/tx';
3
+ import { hexToBytes, addHexPrefix, bytesToHex } from '@ethereumjs/util';
4
+ import log from 'loglevel';
5
+ import { METHOD_TYPES } from './constants.js';
6
+
7
+ /**
8
+ * Transaction decoder for analytics.
9
+ * Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
10
+ */
11
+ const transactionDecoder = (req, chainId) => {
12
+ let sender = "";
13
+ let txHash = "";
14
+ try {
15
+ if (req.method === METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
16
+ const rawTx = req.params[0];
17
+ const txBytes = hexToBytes(addHexPrefix(rawTx));
18
+ const tx = createTxFromRLP(txBytes, {
19
+ common: createCustomCommon({
20
+ chainId
21
+ }, Mainnet)
22
+ });
23
+ sender = tx.getSenderAddress().toString();
24
+ txHash = bytesToHex(tx.hash());
25
+ } else if (req.method === METHOD_TYPES.ETH_SEND_USER_OPERATION) {
26
+ const userOpReq = req;
27
+ sender = userOpReq.params.map(p => p.sender).join(",");
28
+ }
29
+ } catch (error) {
30
+ log.error("Error decoding transaction", error, {
31
+ req,
32
+ chainId
33
+ });
34
+ }
35
+ return [sender, txHash];
36
+ };
37
+
38
+ export { transactionDecoder };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "8.13.0",
3
+ "version": "8.15.0",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "sideEffects": false,
@@ -19,22 +19,24 @@
19
19
  "test": "vitest run --config test/configs/browsers.config.mts --coverage"
20
20
  },
21
21
  "dependencies": {
22
+ "@ethereumjs/common": "^10.1.0",
23
+ "@ethereumjs/tx": "^10.1.0",
22
24
  "@ethereumjs/util": "^10.1.0",
23
- "@metamask/delegation-toolkit": "~0.13.0",
24
- "@toruslabs/base-controllers": "^8.13.0",
25
+ "@metamask/smart-accounts-kit": "~0.3.0",
26
+ "@toruslabs/base-controllers": "^8.15.0",
25
27
  "@toruslabs/http-helpers": "^8.1.1",
26
- "@web3auth/auth": "^10.7.0",
28
+ "@web3auth/auth": "^10.8.0",
27
29
  "async-mutex": "^0.5.0",
28
30
  "bignumber.js": "^9.3.1",
29
31
  "bn.js": "^5.2.2",
30
32
  "deepmerge": "^4.3.1",
31
33
  "ethereum-cryptography": "^3.2.0",
32
- "ethers": "^6.15.0",
34
+ "ethers": "^6.16.0",
33
35
  "fast-json-patch": "^3.1.1",
34
36
  "fast-safe-stringify": "^2.1.1",
35
37
  "jsonschema": "^1.5.0",
36
38
  "loglevel": "^1.9.2",
37
- "permissionless": "^0.2.57"
39
+ "permissionless": "^0.3.2"
38
40
  },
39
41
  "peerDependencies": {
40
42
  "@babel/runtime": "7.x",
@@ -64,7 +66,7 @@
64
66
  "publishConfig": {
65
67
  "access": "public"
66
68
  },
67
- "gitHead": "d0504d55cda8ab22e439c812ce24ea685d73e36b",
69
+ "gitHead": "34e5c37fb5f516e1d5900bbe46c6c879ceb90bd3",
68
70
  "devDependencies": {
69
71
  "@typechain/ethers-v6": "^0.5.1",
70
72
  "typechain": "^8.3.2"