@toruslabs/ethereum-controllers 8.3.3 → 8.4.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.
@@ -15,7 +15,7 @@ class MetamaskSmartAccount {
15
15
  this.options = options;
16
16
  }
17
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;
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, _this$options10, _this$options$impleme, _this$options11;
19
19
  const hybridSignatory = {
20
20
  walletClient: input.walletClient,
21
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,
@@ -31,18 +31,19 @@ class MetamaskSmartAccount {
31
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
32
  const baseParams = {
33
33
  client: input.client,
34
- deploySalt: (_this$options$deployS = this.options.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
34
+ deploySalt: (_this$options$deployS = (_this$options10 = this.options) === null || _this$options10 === void 0 ? void 0 : _this$options10.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
35
35
  };
36
- if (isImplementationHybrid(this.options.implementation)) {
36
+ const implementation = (_this$options$impleme = (_this$options11 = this.options) === null || _this$options11 === void 0 ? void 0 : _this$options11.implementation) !== null && _this$options$impleme !== void 0 ? _this$options$impleme : delegationToolkit.Implementation.Hybrid;
37
+ if (isImplementationHybrid(implementation)) {
37
38
  const params = _objectSpread(_objectSpread({}, baseParams), {}, {
38
- implementation: this.options.implementation,
39
+ implementation,
39
40
  deployParams: hybridDeployParams,
40
41
  signatory: hybridSignatory
41
42
  });
42
43
  return delegationToolkit.toMetaMaskSmartAccount(params);
43
44
  } else {
44
45
  const params = _objectSpread(_objectSpread({}, baseParams), {}, {
45
- implementation: this.options.implementation,
46
+ implementation,
46
47
  deployParams: multiSigDeployParams,
47
48
  signatory: multiSigSignatory
48
49
  });
@@ -29,6 +29,18 @@ function createProcessTransactionMiddleware({
29
29
  response.result = await processTransaction(request.params, request);
30
30
  });
31
31
  }
32
+ function createProcessSignTransactionMiddleware({
33
+ processSignTransaction
34
+ }) {
35
+ return auth.createAsyncMiddleware(async (request, response, next) => {
36
+ const {
37
+ method
38
+ } = request;
39
+ if (method !== constants.METHOD_TYPES.ETH_SIGN_TRANSACTION) return next();
40
+ if (!processSignTransaction) throw new Error("WalletMiddleware - opts.processSignTransaction not provided");
41
+ response.result = await processSignTransaction(request.params, request);
42
+ });
43
+ }
32
44
  function createProcessEstimateUserOperationGasMiddleware({
33
45
  processEstimateUserOperationGas
34
46
  }) {
@@ -284,6 +296,7 @@ function createEthereumMiddleware(providerHandlers) {
284
296
  getAccounts,
285
297
  getPrivateKey,
286
298
  processTransaction,
299
+ processSignTransaction,
287
300
  processEstimateUserOperationGas,
288
301
  processEthSignMessage,
289
302
  processTypedMessageV4,
@@ -305,6 +318,8 @@ function createEthereumMiddleware(providerHandlers) {
305
318
  getAccounts
306
319
  }), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.ETH_PRIVATE_KEY, getPrivateKey), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.PRIVATE_KEY, getPrivateKey), createProcessTransactionMiddleware({
307
320
  processTransaction
321
+ }), createProcessSignTransactionMiddleware({
322
+ processSignTransaction
308
323
  }), createProcessEstimateUserOperationGasMiddleware({
309
324
  processEstimateUserOperationGas
310
325
  }), createProcessEthSignMessage({
@@ -334,6 +349,7 @@ exports.createProcessAddEthereumChain = createProcessAddEthereumChain;
334
349
  exports.createProcessEstimateUserOperationGasMiddleware = createProcessEstimateUserOperationGasMiddleware;
335
350
  exports.createProcessEthSignMessage = createProcessEthSignMessage;
336
351
  exports.createProcessPersonalMessage = createProcessPersonalMessage;
352
+ exports.createProcessSignTransactionMiddleware = createProcessSignTransactionMiddleware;
337
353
  exports.createProcessSwitchEthereumChain = createProcessSwitchEthereumChain;
338
354
  exports.createProcessTransactionMiddleware = createProcessTransactionMiddleware;
339
355
  exports.createProcessTypedMessageV4 = createProcessTypedMessageV4;
@@ -93,6 +93,9 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
93
93
  if (msg.status === baseControllers.TransactionStatus.failed) {
94
94
  return reject(auth.rpcErrors.internal(`Transaction Signature: failed to sign message ${msg.error}`));
95
95
  }
96
+ if (msg.status === baseControllers.TransactionStatus.signed && msg.isSignOnly) {
97
+ return resolve(msg.rawTransaction);
98
+ }
96
99
  if (msg.status === baseControllers.TransactionStatus.submitted) {
97
100
  return resolve(msg.transactionHash);
98
101
  }
@@ -126,8 +129,11 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
126
129
  txMeta.nonceDetails = nonceLock.nonceDetails;
127
130
  this.updateTransactionInState(txMeta, "transactions#approveTransaction");
128
131
  // sign transaction
129
- const rawTx = await this.signTransaction(transactionID);
130
- await this.publishTransaction(transactionID, rawTx);
132
+ await this.signTransaction(transactionID, txMeta.isSignOnly);
133
+ // publish if not signOnly
134
+ if (!txMeta.isSignOnly) {
135
+ await this.publishTransaction(transactionID);
136
+ }
131
137
  nonceLock.releaseLock();
132
138
  } catch (err) {
133
139
  try {
@@ -145,7 +151,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
145
151
  this.inProcessOfSigning.delete(transactionID);
146
152
  }
147
153
  }
148
- async signTransaction(txId) {
154
+ async signTransaction(txId, isSignOnly) {
149
155
  const txMeta = this.getTransaction(txId);
150
156
  const chainId = this.getCurrentChainId();
151
157
  const type = TransactionUtils.isEIP1559Transaction(txMeta) ? constants.TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : constants.TRANSACTION_ENVELOPE_TYPES.LEGACY;
@@ -168,15 +174,15 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
168
174
  txMeta.r = signedEthTx.signature.r;
169
175
  txMeta.s = signedEthTx.signature.s;
170
176
  txMeta.v = util.addHexPrefix(signedEthTx.signature.v.toString(16));
171
- this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
172
- this.setTxStatusSigned(txId);
173
177
  const rawTx = signedEthTx.serialized;
178
+ txMeta.rawTransaction = rawTx;
179
+ this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values and rawTx");
180
+ this.setTxStatusSigned(txId, isSignOnly);
174
181
  return rawTx;
175
182
  }
176
- async publishTransaction(txId, rawTx) {
183
+ async publishTransaction(txId) {
177
184
  const txMeta = this.getTransaction(txId);
178
- txMeta.rawTransaction = rawTx;
179
- this.updateTransactionInState(txMeta, "transactions#publishTransaction");
185
+ const rawTx = txMeta.rawTransaction;
180
186
  let txHash;
181
187
  try {
182
188
  txHash = await this.provider.request({
@@ -406,6 +412,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
406
412
  txMeta.transactionCategory = category;
407
413
  txMeta.methodParams = methodParams;
408
414
  txMeta.isUserOperation = req.isUserOperation;
415
+ txMeta.isSignOnly = req.isSignOnly;
409
416
  txMeta.transaction.value = txMeta.transaction.value ? util.addHexPrefix(txMeta.transaction.value) : "0x0";
410
417
  this.emit(`${txMeta.id}:unapproved`, txMeta);
411
418
  txMeta = this.addTransactionToState(txMeta);
@@ -74,6 +74,7 @@ exports.createProcessAddEthereumChain = createEthereumMiddleware.createProcessAd
74
74
  exports.createProcessEstimateUserOperationGasMiddleware = createEthereumMiddleware.createProcessEstimateUserOperationGasMiddleware;
75
75
  exports.createProcessEthSignMessage = createEthereumMiddleware.createProcessEthSignMessage;
76
76
  exports.createProcessPersonalMessage = createEthereumMiddleware.createProcessPersonalMessage;
77
+ exports.createProcessSignTransactionMiddleware = createEthereumMiddleware.createProcessSignTransactionMiddleware;
77
78
  exports.createProcessSwitchEthereumChain = createEthereumMiddleware.createProcessSwitchEthereumChain;
78
79
  exports.createProcessTransactionMiddleware = createEthereumMiddleware.createProcessTransactionMiddleware;
79
80
  exports.createProcessTypedMessageV4 = createEthereumMiddleware.createProcessTypedMessageV4;
@@ -7,6 +7,7 @@ export interface IProviderHandlers {
7
7
  getAccounts: (req: JRPCRequest<string[]>) => Promise<string[]>;
8
8
  getPrivateKey?: (req: JRPCRequest<unknown>) => Promise<string>;
9
9
  processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
10
+ processSignTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
10
11
  processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
11
12
  processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
12
13
  processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
@@ -30,6 +31,9 @@ export declare function createGetAccountsMiddleware({ getAccounts }: {
30
31
  export declare function createProcessTransactionMiddleware({ processTransaction, }: {
31
32
  processTransaction: IProviderHandlers["processTransaction"];
32
33
  }): JRPCMiddleware<TransactionParams, string>;
34
+ export declare function createProcessSignTransactionMiddleware({ processSignTransaction, }: {
35
+ processSignTransaction: IProviderHandlers["processTransaction"];
36
+ }): JRPCMiddleware<TransactionParams, string>;
33
37
  export declare function createProcessEstimateUserOperationGasMiddleware({ processEstimateUserOperationGas, }: {
34
38
  processEstimateUserOperationGas: IProviderHandlers["processEstimateUserOperationGas"];
35
39
  }): JRPCMiddleware<TransactionParams, string | UserOperationGas>;
@@ -41,8 +41,8 @@ export declare class TransactionController extends TransactionStateManager imple
41
41
  }): Promise<string>;
42
42
  processApproval(txMeta: EthereumTransactionMeta): Promise<string>;
43
43
  approveTransaction(transactionID: string): Promise<void>;
44
- signTransaction(txId: string): Promise<string>;
45
- publishTransaction(txId: string, rawTx: string): Promise<void>;
44
+ signTransaction(txId: string, isSignOnly?: boolean): Promise<string>;
45
+ publishTransaction(txId: string): Promise<void>;
46
46
  confirmTransaction(params: TX_CONFIRMED_EVENT_TYPE): Promise<void>;
47
47
  cancelTransaction?(transactionID: string): Promise<void>;
48
48
  getEIP1559Compatibility(fromAddress?: string): Promise<boolean>;
@@ -30,6 +30,7 @@ export declare const SUPPORTED_NETWORKS: Record<string, EthereumProviderConfig>;
30
30
  export declare const METHOD_TYPES: {
31
31
  readonly GET_ACCOUNTS: "eth_accounts";
32
32
  readonly ETH_TRANSACTION: "eth_sendTransaction";
33
+ readonly ETH_SIGN_TRANSACTION: "eth_signTransaction";
33
34
  readonly ETH_ESTIMATE_USER_OPERATION_GAS: "eth_estimateUserOperationGas";
34
35
  readonly ETH_REQUEST_ACCOUNTS: "eth_requestAccounts";
35
36
  readonly ETH_SEND_RAW_TRANSACTION: "eth_sendRawTransaction";
@@ -435,7 +435,8 @@ export type PaymasterConfig = Omit<Parameters<typeof createPaymasterClient>[0],
435
435
  export type BiconomySmartAccountConfig = Pick<ToBiconomySmartAccountParameters, "entryPoint" | "ecdsaModuleAddress" | "factoryAddress">;
436
436
  export type KernelSmartAccountParameters = Parameters<typeof toEcdsaKernelSmartAccount>[0];
437
437
  export type KernelSmartAccountConfig = Omit<KernelSmartAccountParameters, "owners" | "client" | "address" | "nonceKey" | "index">;
438
- export type MetamaskSmartAccountConfig<TImplementation extends Implementation> = Omit<ToMetaMaskSmartAccountParameters<TImplementation>, "client" | "signatory" | "deployParams"> & {
438
+ export type MetamaskSmartAccountConfig<TImplementation extends Implementation = Implementation.Hybrid> = Omit<ToMetaMaskSmartAccountParameters<TImplementation>, "client" | "signatory" | "deployParams" | "implementation"> & {
439
+ implementation?: TImplementation;
439
440
  hybridParams?: {
440
441
  p256KeyIds?: string[];
441
442
  p256XValues?: bigint[];
@@ -465,19 +466,9 @@ export interface ISmartAccount {
465
466
  }
466
467
  export type SmartAccountType = (typeof SMART_ACCOUNT)[keyof typeof SMART_ACCOUNT];
467
468
  export type SmartAccountConfig<TImplementation extends Implementation = Implementation.Hybrid> = BiconomySmartAccountConfig | KernelSmartAccountConfig | NexusSmartAccountConfig | SafeSmartAccountConfig | TrustSmartAccountConfig | MetamaskSmartAccountConfig<TImplementation>;
468
- /**
469
- * @deprecated Use MultiChainAccountAbstractionConfig instead, will be deprecated in v8
470
- */
471
- export interface AccountAbstractionConfig {
472
- smartAccountType: SmartAccountType;
473
- smartAccountAddress?: string;
474
- bundlerConfig: BundlerConfig;
475
- paymasterConfig?: PaymasterConfig;
476
- smartAccountConfig?: SmartAccountConfig;
477
- }
478
469
  export type AccountAbstractionMultiChainConfig = {
479
470
  smartAccountType: SmartAccountType;
480
- chains: {
471
+ chains?: {
481
472
  chainId: string;
482
473
  bundlerConfig: BundlerConfig;
483
474
  paymasterConfig?: PaymasterConfig;
@@ -230,6 +230,7 @@ const SUPPORTED_NETWORKS = {
230
230
  const METHOD_TYPES = {
231
231
  GET_ACCOUNTS: "eth_accounts",
232
232
  ETH_TRANSACTION: "eth_sendTransaction",
233
+ ETH_SIGN_TRANSACTION: "eth_signTransaction",
233
234
  ETH_ESTIMATE_USER_OPERATION_GAS: "eth_estimateUserOperationGas",
234
235
  ETH_REQUEST_ACCOUNTS: "eth_requestAccounts",
235
236
  ETH_SEND_RAW_TRANSACTION: "eth_sendRawTransaction",
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import { toMetaMaskSmartAccount, Implementation } from '@metamask/delegation-toolkit';
3
+ import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit';
4
4
  import { SMART_ACCOUNT } from '../../utils/constants.js';
5
5
 
6
6
  function isImplementationHybrid(implementation) {
@@ -13,7 +13,7 @@ class MetamaskSmartAccount {
13
13
  this.options = options;
14
14
  }
15
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;
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, _this$options10, _this$options$impleme, _this$options11;
17
17
  const hybridSignatory = {
18
18
  walletClient: input.walletClient,
19
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,
@@ -29,18 +29,19 @@ class MetamaskSmartAccount {
29
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
30
  const baseParams = {
31
31
  client: input.client,
32
- deploySalt: (_this$options$deployS = this.options.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
32
+ deploySalt: (_this$options$deployS = (_this$options10 = this.options) === null || _this$options10 === void 0 ? void 0 : _this$options10.deploySalt) !== null && _this$options$deployS !== void 0 ? _this$options$deployS : "0x0"
33
33
  };
34
- if (isImplementationHybrid(this.options.implementation)) {
34
+ const implementation = (_this$options$impleme = (_this$options11 = this.options) === null || _this$options11 === void 0 ? void 0 : _this$options11.implementation) !== null && _this$options$impleme !== void 0 ? _this$options$impleme : Implementation.Hybrid;
35
+ if (isImplementationHybrid(implementation)) {
35
36
  const params = _objectSpread(_objectSpread({}, baseParams), {}, {
36
- implementation: this.options.implementation,
37
+ implementation,
37
38
  deployParams: hybridDeployParams,
38
39
  signatory: hybridSignatory
39
40
  });
40
41
  return toMetaMaskSmartAccount(params);
41
42
  } else {
42
43
  const params = _objectSpread(_objectSpread({}, baseParams), {}, {
43
- implementation: this.options.implementation,
44
+ implementation,
44
45
  deployParams: multiSigDeployParams,
45
46
  signatory: multiSigSignatory
46
47
  });
@@ -27,6 +27,18 @@ function createProcessTransactionMiddleware({
27
27
  response.result = await processTransaction(request.params, request);
28
28
  });
29
29
  }
30
+ function createProcessSignTransactionMiddleware({
31
+ processSignTransaction
32
+ }) {
33
+ return createAsyncMiddleware(async (request, response, next) => {
34
+ const {
35
+ method
36
+ } = request;
37
+ if (method !== METHOD_TYPES.ETH_SIGN_TRANSACTION) return next();
38
+ if (!processSignTransaction) throw new Error("WalletMiddleware - opts.processSignTransaction not provided");
39
+ response.result = await processSignTransaction(request.params, request);
40
+ });
41
+ }
30
42
  function createProcessEstimateUserOperationGasMiddleware({
31
43
  processEstimateUserOperationGas
32
44
  }) {
@@ -282,6 +294,7 @@ function createEthereumMiddleware(providerHandlers) {
282
294
  getAccounts,
283
295
  getPrivateKey,
284
296
  processTransaction,
297
+ processSignTransaction,
285
298
  processEstimateUserOperationGas,
286
299
  processEthSignMessage,
287
300
  processTypedMessageV4,
@@ -303,6 +316,8 @@ function createEthereumMiddleware(providerHandlers) {
303
316
  getAccounts
304
317
  }), createGenericJRPCMiddleware(METHOD_TYPES.ETH_PRIVATE_KEY, getPrivateKey), createGenericJRPCMiddleware(METHOD_TYPES.PRIVATE_KEY, getPrivateKey), createProcessTransactionMiddleware({
305
318
  processTransaction
319
+ }), createProcessSignTransactionMiddleware({
320
+ processSignTransaction
306
321
  }), createProcessEstimateUserOperationGasMiddleware({
307
322
  processEstimateUserOperationGas
308
323
  }), createProcessEthSignMessage({
@@ -324,4 +339,4 @@ function createEthereumMiddleware(providerHandlers) {
324
339
  })]);
325
340
  }
326
341
 
327
- export { createEthereumMiddleware, createGetAccountsMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult };
342
+ export { createEthereumMiddleware, createGetAccountsMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSignTransactionMiddleware, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult };
@@ -91,6 +91,9 @@ class TransactionController extends TransactionStateManager {
91
91
  if (msg.status === TransactionStatus.failed) {
92
92
  return reject(rpcErrors.internal(`Transaction Signature: failed to sign message ${msg.error}`));
93
93
  }
94
+ if (msg.status === TransactionStatus.signed && msg.isSignOnly) {
95
+ return resolve(msg.rawTransaction);
96
+ }
94
97
  if (msg.status === TransactionStatus.submitted) {
95
98
  return resolve(msg.transactionHash);
96
99
  }
@@ -124,8 +127,11 @@ class TransactionController extends TransactionStateManager {
124
127
  txMeta.nonceDetails = nonceLock.nonceDetails;
125
128
  this.updateTransactionInState(txMeta, "transactions#approveTransaction");
126
129
  // sign transaction
127
- const rawTx = await this.signTransaction(transactionID);
128
- await this.publishTransaction(transactionID, rawTx);
130
+ await this.signTransaction(transactionID, txMeta.isSignOnly);
131
+ // publish if not signOnly
132
+ if (!txMeta.isSignOnly) {
133
+ await this.publishTransaction(transactionID);
134
+ }
129
135
  nonceLock.releaseLock();
130
136
  } catch (err) {
131
137
  try {
@@ -143,7 +149,7 @@ class TransactionController extends TransactionStateManager {
143
149
  this.inProcessOfSigning.delete(transactionID);
144
150
  }
145
151
  }
146
- async signTransaction(txId) {
152
+ async signTransaction(txId, isSignOnly) {
147
153
  const txMeta = this.getTransaction(txId);
148
154
  const chainId = this.getCurrentChainId();
149
155
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
@@ -166,15 +172,15 @@ class TransactionController extends TransactionStateManager {
166
172
  txMeta.r = signedEthTx.signature.r;
167
173
  txMeta.s = signedEthTx.signature.s;
168
174
  txMeta.v = addHexPrefix(signedEthTx.signature.v.toString(16));
169
- this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
170
- this.setTxStatusSigned(txId);
171
175
  const rawTx = signedEthTx.serialized;
176
+ txMeta.rawTransaction = rawTx;
177
+ this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values and rawTx");
178
+ this.setTxStatusSigned(txId, isSignOnly);
172
179
  return rawTx;
173
180
  }
174
- async publishTransaction(txId, rawTx) {
181
+ async publishTransaction(txId) {
175
182
  const txMeta = this.getTransaction(txId);
176
- txMeta.rawTransaction = rawTx;
177
- this.updateTransactionInState(txMeta, "transactions#publishTransaction");
183
+ const rawTx = txMeta.rawTransaction;
178
184
  let txHash;
179
185
  try {
180
186
  txHash = await this.provider.request({
@@ -410,6 +416,7 @@ class TransactionController extends TransactionStateManager {
410
416
  txMeta.transactionCategory = category;
411
417
  txMeta.methodParams = methodParams;
412
418
  txMeta.isUserOperation = req.isUserOperation;
419
+ txMeta.isSignOnly = req.isSignOnly;
413
420
  txMeta.transaction.value = txMeta.transaction.value ? addHexPrefix(txMeta.transaction.value) : "0x0";
414
421
  this.emit(`${txMeta.id}:unapproved`, txMeta);
415
422
  txMeta = this.addTransactionToState(txMeta);
@@ -10,7 +10,7 @@ export { PersonalMessageController } from './Message/PersonalMessageController.j
10
10
  export { SwitchChainController } from './Message/SwitchChainController.js';
11
11
  export { TypedMessageController } from './Message/TypedMessageController.js';
12
12
  export { normalizeMessageData, validateAddChainData, validateAddress, validateSignMessageData, validateSwitchChainData, validateTypedSignMessageDataV4 } from './Message/utils.js';
13
- export { createEthereumMiddleware, createGetAccountsMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult } from './Network/createEthereumMiddleware.js';
13
+ export { createEthereumMiddleware, createGetAccountsMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSignTransactionMiddleware, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult } from './Network/createEthereumMiddleware.js';
14
14
  export { createChainIdMiddleware, createJsonRpcClient, createProviderConfigMiddleware } from './Network/createJsonRpcClient.js';
15
15
  export { NetworkController } from './Network/NetworkController.js';
16
16
  export { NftHandler } from './Nfts/NftHandler.js';
@@ -228,6 +228,7 @@ const SUPPORTED_NETWORKS = {
228
228
  const METHOD_TYPES = {
229
229
  GET_ACCOUNTS: "eth_accounts",
230
230
  ETH_TRANSACTION: "eth_sendTransaction",
231
+ ETH_SIGN_TRANSACTION: "eth_signTransaction",
231
232
  ETH_ESTIMATE_USER_OPERATION_GAS: "eth_estimateUserOperationGas",
232
233
  ETH_REQUEST_ACCOUNTS: "eth_requestAccounts",
233
234
  ETH_SEND_RAW_TRANSACTION: "eth_sendRawTransaction",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "8.3.3",
3
+ "version": "8.4.0",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "sideEffects": false,
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@ethereumjs/util": "^9.1.0",
23
23
  "@metamask/delegation-toolkit": "^0.10.0",
24
- "@toruslabs/base-controllers": "^8.3.3",
24
+ "@toruslabs/base-controllers": "^8.4.0",
25
25
  "@toruslabs/http-helpers": "^8.1.1",
26
26
  "@web3auth/auth": "^10.4.0",
27
27
  "async-mutex": "^0.5.0",
@@ -63,7 +63,7 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "09e5ada086122b3e4e2eb8a35d41ffe71e2406d4",
66
+ "gitHead": "d20cc13ccfb25f7edaf033b6c5d08fff47e27407",
67
67
  "devDependencies": {
68
68
  "@typechain/ethers-v6": "^0.5.1",
69
69
  "typechain": "^8.3.2"