@toruslabs/ethereum-controllers 8.4.2 → 8.4.3
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.
- package/dist/ethereumControllers.umd.min.js +1 -1
- package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +37 -1
- package/dist/lib.cjs/Network/createEthereumMiddleware.js +2 -1
- package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +8 -6
- package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +1 -0
- package/dist/lib.cjs/types/utils/constants.d.ts +2 -0
- package/dist/lib.cjs/utils/constants.js +2 -0
- package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +37 -1
- package/dist/lib.esm/Network/createEthereumMiddleware.js +2 -1
- package/dist/lib.esm/utils/constants.js +2 -0
- package/package.json +7 -7
|
@@ -147,7 +147,7 @@ class AccountAbstractionController extends baseControllers.BaseController {
|
|
|
147
147
|
calls: [{
|
|
148
148
|
to: txParams.to,
|
|
149
149
|
// Explicit conversation required to avoid value being passed as hex
|
|
150
|
-
value: BigInt(txParams.value),
|
|
150
|
+
value: txParams.value ? BigInt(txParams.value) : undefined,
|
|
151
151
|
data: txParams.data
|
|
152
152
|
}],
|
|
153
153
|
maxFeePerGas: txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined,
|
|
@@ -186,6 +186,42 @@ class AccountAbstractionController extends baseControllers.BaseController {
|
|
|
186
186
|
});
|
|
187
187
|
return txReceipt.receipt.transactionHash;
|
|
188
188
|
}
|
|
189
|
+
async signTransaction(id, tx, address) {
|
|
190
|
+
var _txParams$chainId2;
|
|
191
|
+
if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) {
|
|
192
|
+
throw new Error("Invalid address");
|
|
193
|
+
}
|
|
194
|
+
const txParams = tx;
|
|
195
|
+
const userOpMeta = {
|
|
196
|
+
transactionParams: txParams,
|
|
197
|
+
chainId: (_txParams$chainId2 = txParams.chainId) !== null && _txParams$chainId2 !== void 0 ? _txParams$chainId2 : this.getProviderConfig().chainId,
|
|
198
|
+
createdAt: new Date(),
|
|
199
|
+
status: baseControllers.TransactionStatus.approved
|
|
200
|
+
};
|
|
201
|
+
this.updateUserOpMeta(id, userOpMeta);
|
|
202
|
+
const request = await this.bundlerClient.prepareUserOperation({
|
|
203
|
+
account: this.smartAccount,
|
|
204
|
+
calls: [{
|
|
205
|
+
to: txParams.to,
|
|
206
|
+
// Explicit conversation required to avoid value being passed as hex
|
|
207
|
+
value: txParams.value ? BigInt(txParams.value) : undefined,
|
|
208
|
+
data: txParams.data
|
|
209
|
+
}],
|
|
210
|
+
maxFeePerGas: txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined,
|
|
211
|
+
maxPriorityFeePerGas: txParams.maxPriorityFeePerGas ? BigInt(txParams.maxPriorityFeePerGas) : undefined,
|
|
212
|
+
callGasLimit: txParams.callGasLimit ? BigInt(txParams.callGasLimit) : undefined,
|
|
213
|
+
preVerificationGas: txParams.preVerificationGas ? BigInt(txParams.preVerificationGas) : undefined,
|
|
214
|
+
verificationGasLimit: txParams.verificationGasLimit ? BigInt(txParams.verificationGasLimit) : undefined,
|
|
215
|
+
paymasterVerificationGasLimit: txParams.paymasterVerificationGasLimit ? BigInt(txParams.paymasterVerificationGasLimit) : undefined,
|
|
216
|
+
paymasterPostOpGasLimit: txParams.paymasterPostOpGasLimit ? BigInt(txParams.paymasterPostOpGasLimit) : undefined
|
|
217
|
+
});
|
|
218
|
+
const signature = await this.smartAccount.signUserOperation(request);
|
|
219
|
+
this.updateUserOpMeta(id, {
|
|
220
|
+
signature,
|
|
221
|
+
status: baseControllers.TransactionStatus.signed
|
|
222
|
+
});
|
|
223
|
+
return signature;
|
|
224
|
+
}
|
|
189
225
|
async estimateGas(txParams, address) {
|
|
190
226
|
if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) throw new Error("Invalid address");
|
|
191
227
|
const calls = [{
|
|
@@ -295,6 +295,7 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
295
295
|
requestAccounts,
|
|
296
296
|
getAccounts,
|
|
297
297
|
getPrivateKey,
|
|
298
|
+
getPublicKey,
|
|
298
299
|
processTransaction,
|
|
299
300
|
processSignTransaction,
|
|
300
301
|
processEstimateUserOperationGas,
|
|
@@ -316,7 +317,7 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
316
317
|
requestAccounts
|
|
317
318
|
}), createGetAccountsMiddleware({
|
|
318
319
|
getAccounts
|
|
319
|
-
}), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.ETH_PRIVATE_KEY, getPrivateKey), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.PRIVATE_KEY, getPrivateKey), createProcessTransactionMiddleware({
|
|
320
|
+
}), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.ETH_PRIVATE_KEY, getPrivateKey), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.PRIVATE_KEY, getPrivateKey), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.ETH_PUBLIC_KEY, getPublicKey), baseControllers.createGenericJRPCMiddleware(constants.METHOD_TYPES.PUBLIC_KEY, getPublicKey), createProcessTransactionMiddleware({
|
|
320
321
|
processTransaction
|
|
321
322
|
}), createProcessSignTransactionMiddleware({
|
|
322
323
|
processSignTransaction
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { BaseConfig, BaseController, BaseState, TransactionStatus } from "@toruslabs/base-controllers";
|
|
2
|
-
import { JRPCMiddleware, JRPCRequest, JRPCResponse, SafeEventEmitterProvider } from "@web3auth/auth";
|
|
3
|
-
import { WalletClient } from "viem";
|
|
4
|
-
import { BundlerClient, SmartAccount } from "viem/account-abstraction";
|
|
5
|
-
import { NetworkController } from "../Network/NetworkController";
|
|
6
|
-
import { BundlerConfig, EthereumNetworkState, ISmartAccount, PaymasterConfig, SignTypedDataMessageV4, SmartAccountType, TransactionParams, UserOperationGas } from "../utils/interfaces";
|
|
1
|
+
import { type BaseConfig, BaseController, type BaseState, TransactionStatus } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCMiddleware, type JRPCRequest, type JRPCResponse, type SafeEventEmitterProvider } from "@web3auth/auth";
|
|
3
|
+
import { type WalletClient } from "viem";
|
|
4
|
+
import { type BundlerClient, type SmartAccount } from "viem/account-abstraction";
|
|
5
|
+
import { type NetworkController } from "../Network/NetworkController";
|
|
6
|
+
import type { BundlerConfig, EthereumNetworkState, ISmartAccount, PaymasterConfig, SignTypedDataMessageV4, SmartAccountType, TransactionParams, UserOperationGas } from "../utils/interfaces";
|
|
7
7
|
export interface UserOperationMeta {
|
|
8
8
|
transactionParams: TransactionParams;
|
|
9
9
|
userOpHash?: string;
|
|
10
10
|
status: TransactionStatus;
|
|
11
11
|
chainId: string;
|
|
12
|
+
signature?: string;
|
|
12
13
|
createdAt: Date;
|
|
13
14
|
receipt?: {
|
|
14
15
|
transactionHash: string;
|
|
@@ -50,6 +51,7 @@ export declare class AccountAbstractionController extends BaseController<Account
|
|
|
50
51
|
get walletClient(): WalletClient | null;
|
|
51
52
|
setupProvider(eoaProvider: SafeEventEmitterProvider, eoaAddress: string): Promise<void>;
|
|
52
53
|
sendTransaction(id: string, tx: TransactionParams, address: string): Promise<string>;
|
|
54
|
+
signTransaction(id: string, tx: TransactionParams, address: string): Promise<string>;
|
|
53
55
|
estimateGas(txParams: TransactionParams, address: string): Promise<UserOperationGas>;
|
|
54
56
|
signMessage(message: string, address: string): Promise<string>;
|
|
55
57
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
@@ -6,6 +6,7 @@ export interface IProviderHandlers {
|
|
|
6
6
|
requestAccounts?: (req: JRPCRequest<string[]>) => Promise<string[]>;
|
|
7
7
|
getAccounts: (req: JRPCRequest<string[]>) => Promise<string[]>;
|
|
8
8
|
getPrivateKey?: (req: JRPCRequest<unknown>) => Promise<string>;
|
|
9
|
+
getPublicKey?: (req: JRPCRequest<unknown>) => Promise<string>;
|
|
9
10
|
processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
|
|
10
11
|
processSignTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
|
|
11
12
|
processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
@@ -46,6 +46,8 @@ export declare const METHOD_TYPES: {
|
|
|
46
46
|
readonly ETH_GET_GAS_PRICE: "eth_gasPrice";
|
|
47
47
|
readonly ETH_PRIVATE_KEY: "eth_privateKey";
|
|
48
48
|
readonly PRIVATE_KEY: "private_key";
|
|
49
|
+
readonly ETH_PUBLIC_KEY: "eth_publicKey";
|
|
50
|
+
readonly PUBLIC_KEY: "public_key";
|
|
49
51
|
readonly SWITCH_CHAIN: "wallet_switchEthereumChain";
|
|
50
52
|
readonly ADD_CHAIN: "wallet_addEthereumChain";
|
|
51
53
|
};
|
|
@@ -246,6 +246,8 @@ const METHOD_TYPES = {
|
|
|
246
246
|
ETH_GET_GAS_PRICE: "eth_gasPrice",
|
|
247
247
|
ETH_PRIVATE_KEY: "eth_privateKey",
|
|
248
248
|
PRIVATE_KEY: "private_key",
|
|
249
|
+
ETH_PUBLIC_KEY: "eth_publicKey",
|
|
250
|
+
PUBLIC_KEY: "public_key",
|
|
249
251
|
SWITCH_CHAIN: "wallet_switchEthereumChain",
|
|
250
252
|
ADD_CHAIN: "wallet_addEthereumChain"
|
|
251
253
|
};
|
|
@@ -146,7 +146,7 @@ class AccountAbstractionController extends BaseController {
|
|
|
146
146
|
calls: [{
|
|
147
147
|
to: txParams.to,
|
|
148
148
|
// Explicit conversation required to avoid value being passed as hex
|
|
149
|
-
value: BigInt(txParams.value),
|
|
149
|
+
value: txParams.value ? BigInt(txParams.value) : undefined,
|
|
150
150
|
data: txParams.data
|
|
151
151
|
}],
|
|
152
152
|
maxFeePerGas: txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined,
|
|
@@ -185,6 +185,42 @@ class AccountAbstractionController extends BaseController {
|
|
|
185
185
|
});
|
|
186
186
|
return txReceipt.receipt.transactionHash;
|
|
187
187
|
}
|
|
188
|
+
async signTransaction(id, tx, address) {
|
|
189
|
+
var _txParams$chainId2;
|
|
190
|
+
if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) {
|
|
191
|
+
throw new Error("Invalid address");
|
|
192
|
+
}
|
|
193
|
+
const txParams = tx;
|
|
194
|
+
const userOpMeta = {
|
|
195
|
+
transactionParams: txParams,
|
|
196
|
+
chainId: (_txParams$chainId2 = txParams.chainId) !== null && _txParams$chainId2 !== void 0 ? _txParams$chainId2 : this.getProviderConfig().chainId,
|
|
197
|
+
createdAt: new Date(),
|
|
198
|
+
status: TransactionStatus.approved
|
|
199
|
+
};
|
|
200
|
+
this.updateUserOpMeta(id, userOpMeta);
|
|
201
|
+
const request = await this.bundlerClient.prepareUserOperation({
|
|
202
|
+
account: this.smartAccount,
|
|
203
|
+
calls: [{
|
|
204
|
+
to: txParams.to,
|
|
205
|
+
// Explicit conversation required to avoid value being passed as hex
|
|
206
|
+
value: txParams.value ? BigInt(txParams.value) : undefined,
|
|
207
|
+
data: txParams.data
|
|
208
|
+
}],
|
|
209
|
+
maxFeePerGas: txParams.maxFeePerGas ? BigInt(txParams.maxFeePerGas) : undefined,
|
|
210
|
+
maxPriorityFeePerGas: txParams.maxPriorityFeePerGas ? BigInt(txParams.maxPriorityFeePerGas) : undefined,
|
|
211
|
+
callGasLimit: txParams.callGasLimit ? BigInt(txParams.callGasLimit) : undefined,
|
|
212
|
+
preVerificationGas: txParams.preVerificationGas ? BigInt(txParams.preVerificationGas) : undefined,
|
|
213
|
+
verificationGasLimit: txParams.verificationGasLimit ? BigInt(txParams.verificationGasLimit) : undefined,
|
|
214
|
+
paymasterVerificationGasLimit: txParams.paymasterVerificationGasLimit ? BigInt(txParams.paymasterVerificationGasLimit) : undefined,
|
|
215
|
+
paymasterPostOpGasLimit: txParams.paymasterPostOpGasLimit ? BigInt(txParams.paymasterPostOpGasLimit) : undefined
|
|
216
|
+
});
|
|
217
|
+
const signature = await this.smartAccount.signUserOperation(request);
|
|
218
|
+
this.updateUserOpMeta(id, {
|
|
219
|
+
signature,
|
|
220
|
+
status: TransactionStatus.signed
|
|
221
|
+
});
|
|
222
|
+
return signature;
|
|
223
|
+
}
|
|
188
224
|
async estimateGas(txParams, address) {
|
|
189
225
|
if (address.toLowerCase() !== this.smartAccount.address.toLowerCase()) throw new Error("Invalid address");
|
|
190
226
|
const calls = [{
|
|
@@ -293,6 +293,7 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
293
293
|
requestAccounts,
|
|
294
294
|
getAccounts,
|
|
295
295
|
getPrivateKey,
|
|
296
|
+
getPublicKey,
|
|
296
297
|
processTransaction,
|
|
297
298
|
processSignTransaction,
|
|
298
299
|
processEstimateUserOperationGas,
|
|
@@ -314,7 +315,7 @@ function createEthereumMiddleware(providerHandlers) {
|
|
|
314
315
|
requestAccounts
|
|
315
316
|
}), createGetAccountsMiddleware({
|
|
316
317
|
getAccounts
|
|
317
|
-
}), createGenericJRPCMiddleware(METHOD_TYPES.ETH_PRIVATE_KEY, getPrivateKey), createGenericJRPCMiddleware(METHOD_TYPES.PRIVATE_KEY, getPrivateKey), createProcessTransactionMiddleware({
|
|
318
|
+
}), createGenericJRPCMiddleware(METHOD_TYPES.ETH_PRIVATE_KEY, getPrivateKey), createGenericJRPCMiddleware(METHOD_TYPES.PRIVATE_KEY, getPrivateKey), createGenericJRPCMiddleware(METHOD_TYPES.ETH_PUBLIC_KEY, getPublicKey), createGenericJRPCMiddleware(METHOD_TYPES.PUBLIC_KEY, getPublicKey), createProcessTransactionMiddleware({
|
|
318
319
|
processTransaction
|
|
319
320
|
}), createProcessSignTransactionMiddleware({
|
|
320
321
|
processSignTransaction
|
|
@@ -244,6 +244,8 @@ const METHOD_TYPES = {
|
|
|
244
244
|
ETH_GET_GAS_PRICE: "eth_gasPrice",
|
|
245
245
|
ETH_PRIVATE_KEY: "eth_privateKey",
|
|
246
246
|
PRIVATE_KEY: "private_key",
|
|
247
|
+
ETH_PUBLIC_KEY: "eth_publicKey",
|
|
248
|
+
PUBLIC_KEY: "public_key",
|
|
247
249
|
SWITCH_CHAIN: "wallet_switchEthereumChain",
|
|
248
250
|
ADD_CHAIN: "wallet_addEthereumChain"
|
|
249
251
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toruslabs/ethereum-controllers",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.3",
|
|
4
4
|
"homepage": "https://github.com/torusresearch/controllers#readme",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -21,20 +21,20 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@ethereumjs/util": "^9.1.0",
|
|
23
23
|
"@metamask/delegation-toolkit": "^0.10.2",
|
|
24
|
-
"@toruslabs/base-controllers": "^8.4.
|
|
24
|
+
"@toruslabs/base-controllers": "^8.4.3",
|
|
25
25
|
"@toruslabs/http-helpers": "^8.1.1",
|
|
26
26
|
"@web3auth/auth": "^10.4.0",
|
|
27
27
|
"async-mutex": "^0.5.0",
|
|
28
28
|
"bignumber.js": "^9.2.1",
|
|
29
|
-
"bn.js": "^5.2.
|
|
29
|
+
"bn.js": "^5.2.2",
|
|
30
30
|
"deepmerge": "^4.3.1",
|
|
31
|
-
"ethers": "^6.13.
|
|
31
|
+
"ethers": "^6.13.7",
|
|
32
32
|
"fast-json-patch": "^3.1.1",
|
|
33
33
|
"fast-safe-stringify": "^2.1.1",
|
|
34
34
|
"jsonschema": "^1.5.0",
|
|
35
35
|
"loglevel": "^1.9.2",
|
|
36
|
-
"permissionless": "^0.2.
|
|
37
|
-
"viem": "^2.
|
|
36
|
+
"permissionless": "^0.2.43",
|
|
37
|
+
"viem": "^2.23.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@babel/runtime": "7.x"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "2cfad6d6b757e41cc91efa040e6cf489cdd3eb65",
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@typechain/ethers-v6": "^0.5.1",
|
|
69
69
|
"typechain": "^8.3.2"
|