@toruslabs/ethereum-controllers 9.0.0 → 9.1.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.
- package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +18 -20
- package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.cjs/Gas/GasFeeController.js +2 -3
- package/dist/lib.cjs/Keyring/KeyringController.js +8 -10
- package/dist/lib.cjs/Message/utils.js +3 -6
- package/dist/lib.cjs/Network/NetworkController.js +7 -9
- package/dist/lib.cjs/Network/createEthereumMiddleware.js +373 -285
- package/dist/lib.cjs/Network/createJsonRpcClient.js +21 -21
- package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
- package/dist/lib.cjs/Transaction/TransactionController.js +13 -13
- package/dist/lib.cjs/Transaction/TransactionGasUtil.js +8 -8
- package/dist/lib.cjs/Transaction/TransactionUtils.js +20 -20
- package/dist/lib.cjs/index.js +9 -0
- package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +3 -3
- package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +1 -1
- package/dist/lib.cjs/types/Eip7702/walletUpgradeAccount.d.ts +1 -1
- package/dist/lib.cjs/types/Network/NetworkController.d.ts +1 -1
- package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +28 -90
- package/dist/lib.cjs/types/Network/createJsonRpcClient.d.ts +4 -4
- package/dist/lib.cjs/types/Network/index.d.ts +5 -0
- package/dist/lib.cjs/types/Network/interfaces.d.ts +58 -0
- package/dist/lib.cjs/types/index.d.ts +1 -3
- package/dist/lib.cjs/types/utils/eip5792Types.d.ts +1 -1
- package/dist/lib.cjs/types/utils/eip7702Types.d.ts +1 -1
- package/dist/lib.cjs/types/utils/interfaces.d.ts +2 -2
- package/dist/lib.cjs/utils/conversionUtils.js +2 -2
- package/dist/lib.cjs/utils/helpers.js +4 -4
- package/dist/lib.cjs/utils/transaction.js +2 -2
- package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +19 -21
- package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.esm/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.esm/Gas/GasFeeController.js +2 -3
- package/dist/lib.esm/Keyring/KeyringController.js +9 -11
- package/dist/lib.esm/Message/utils.js +4 -7
- package/dist/lib.esm/Network/NetworkController.js +8 -10
- package/dist/lib.esm/Network/createEthereumMiddleware.js +387 -290
- package/dist/lib.esm/Network/createJsonRpcClient.js +22 -22
- package/dist/lib.esm/Preferences/PreferencesController.js +2 -2
- package/dist/lib.esm/Transaction/TransactionController.js +13 -13
- package/dist/lib.esm/Transaction/TransactionGasUtil.js +8 -8
- package/dist/lib.esm/Transaction/TransactionUtils.js +20 -20
- package/dist/lib.esm/index.js +4 -3
- package/dist/lib.esm/utils/conversionUtils.js +2 -2
- package/dist/lib.esm/utils/helpers.js +3 -3
- package/dist/lib.esm/utils/transaction.js +2 -2
- package/package.json +5 -5
- package/dist/lib.cjs/types/utils/hex.d.ts +0 -9
- package/dist/lib.cjs/utils/hex.js +0 -23
- package/dist/lib.esm/utils/hex.js +0 -21
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { InPageWalletProviderState, SwitchChainMessageParams } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCRequest } from "@web3auth/auth";
|
|
3
|
+
import { TransactionStateManager } from "../Transaction/TransactionStateManager";
|
|
4
|
+
import { Eip5792SendCallsParams, TransactionBatchRequest } from "../utils/eip5792Types";
|
|
5
|
+
import { AddChainMessageParams, EthereumTransactionMeta, GetEthCodeFn, MessageParams, TransactionParams, TypedMessageParams, UserOperationGas, UserRequestApprovalParams } from "../utils/interfaces";
|
|
6
|
+
export interface IProviderHandlers {
|
|
7
|
+
version: string;
|
|
8
|
+
aaConfig?: {
|
|
9
|
+
bundlerUrl: string;
|
|
10
|
+
paymasterUrl?: string;
|
|
11
|
+
};
|
|
12
|
+
requestAccounts?: (req: JRPCRequest<string[]>) => Promise<string[]>;
|
|
13
|
+
getAccounts: (req: JRPCRequest<string[]>) => Promise<string[]>;
|
|
14
|
+
getPrivateKey?: (req: JRPCRequest<unknown>) => Promise<string>;
|
|
15
|
+
getPublicKey?: (req: JRPCRequest<unknown>) => Promise<string>;
|
|
16
|
+
processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
|
|
17
|
+
processTransactionBatch?: (batchRequest: TransactionBatchRequest, req: JRPCRequest<Eip5792SendCallsParams>) => Promise<string>;
|
|
18
|
+
processSignTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
|
|
19
|
+
processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
20
|
+
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
21
|
+
processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
22
|
+
processSwitchEthereumChain?: (msgParams: SwitchChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
23
|
+
processWalletSwitchChain?: (msgParams: SwitchChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
24
|
+
processAddEthereumChain?: (msgParams: AddChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
|
|
25
|
+
processEstimateUserOperationGas?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams>) => Promise<UserOperationGas>;
|
|
26
|
+
getPendingNonce?: (nonceParams: {
|
|
27
|
+
address: string;
|
|
28
|
+
blockReference: string;
|
|
29
|
+
}, req: JRPCRequest<{
|
|
30
|
+
address: string;
|
|
31
|
+
blockReference: string;
|
|
32
|
+
}>) => Promise<string>;
|
|
33
|
+
getPendingTransactionByHash?: (hash: string, req: JRPCRequest<string>) => Promise<EthereumTransactionMeta>;
|
|
34
|
+
getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"];
|
|
35
|
+
getProviderState: () => Promise<InPageWalletProviderState>;
|
|
36
|
+
/**
|
|
37
|
+
* Query the deployment bytecode of an address. (eth_getCode)
|
|
38
|
+
*/
|
|
39
|
+
getEthCode?: GetEthCodeFn;
|
|
40
|
+
/**
|
|
41
|
+
* EIP-5792 configuration for wallet capabilities and batch calls.
|
|
42
|
+
*/
|
|
43
|
+
eip5792Config?: {
|
|
44
|
+
/**
|
|
45
|
+
* Get the list of supported chain IDs for EIP-5792/EIP-7702.
|
|
46
|
+
*/
|
|
47
|
+
getSupportedChains: () => `0x${string}`[];
|
|
48
|
+
/**
|
|
49
|
+
* Get cached delegation addresses.
|
|
50
|
+
* Key format: `${walletAddress}-${chainId}`
|
|
51
|
+
*/
|
|
52
|
+
getCachedDelegations?: () => Record<string, `0x${string}` | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Update the delegation cache.
|
|
55
|
+
*/
|
|
56
|
+
updateDelegationCache?: (walletAddress: `0x${string}`, chainId: `0x${string}`, delegation: `0x${string}` | null) => void;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -15,9 +15,7 @@ export * from "./Message/SwitchChainController";
|
|
|
15
15
|
export * from "./Message/TypedMessageController";
|
|
16
16
|
export * from "./Message/types";
|
|
17
17
|
export * from "./Message/utils";
|
|
18
|
-
export * from "./Network
|
|
19
|
-
export * from "./Network/createJsonRpcClient";
|
|
20
|
-
export { NetworkController } from "./Network/NetworkController";
|
|
18
|
+
export * from "./Network";
|
|
21
19
|
export * from "./Nfts/INftsController";
|
|
22
20
|
export * from "./Nfts/NftHandler";
|
|
23
21
|
export * from "./Nfts/NftsController";
|
|
@@ -51,7 +51,7 @@ export declare const GetCallsStatusCode: {
|
|
|
51
51
|
/**
|
|
52
52
|
* Response for wallet_getCallsStatus (EIP-5792)
|
|
53
53
|
*/
|
|
54
|
-
export interface Eip5792GetCallsStatusResponse {
|
|
54
|
+
export interface Eip5792GetCallsStatusResponse extends Record<string, unknown> {
|
|
55
55
|
id: string;
|
|
56
56
|
chainId: `0x${string}`;
|
|
57
57
|
atomic: boolean;
|
|
@@ -48,7 +48,7 @@ export interface Eip7702Params extends TransactionParams {
|
|
|
48
48
|
*/
|
|
49
49
|
implementation?: Hex;
|
|
50
50
|
}
|
|
51
|
-
export interface Eip7702WalletGetUpgradeStatusResponse {
|
|
51
|
+
export interface Eip7702WalletGetUpgradeStatusResponse extends Record<string, boolean | Hex> {
|
|
52
52
|
/**
|
|
53
53
|
* Whether the account is upgraded.
|
|
54
54
|
*/
|
|
@@ -230,7 +230,7 @@ export interface TransactionReceipt {
|
|
|
230
230
|
}
|
|
231
231
|
export type BlockTag = "earliest" | "finalized" | "safe" | "latest" | "pending";
|
|
232
232
|
export type BlockParams = string | BlockTag;
|
|
233
|
-
export interface TransactionRPCMeta {
|
|
233
|
+
export interface TransactionRPCMeta extends Record<string, unknown> {
|
|
234
234
|
v: string;
|
|
235
235
|
r: string;
|
|
236
236
|
s: string;
|
|
@@ -504,7 +504,7 @@ export type AccountAbstractionMultiChainConfig = {
|
|
|
504
504
|
smartAccountConfig?: SmartAccountConfig;
|
|
505
505
|
}[];
|
|
506
506
|
};
|
|
507
|
-
export interface UserOperationGas {
|
|
507
|
+
export interface UserOperationGas extends Record<string, string> {
|
|
508
508
|
callGasLimit: string;
|
|
509
509
|
preVerificationGas: string;
|
|
510
510
|
verificationGasLimit: string;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructuringEmpty');
|
|
4
4
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
5
5
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
6
|
+
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
6
7
|
var bignumber_js = require('bignumber.js');
|
|
7
|
-
var hex = require('./hex.js');
|
|
8
8
|
|
|
9
9
|
const _excluded = ["aBase", "bBase"],
|
|
10
10
|
_excluded2 = ["aBase", "bBase"],
|
|
@@ -15,7 +15,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new bignumber_js.BigNumber("1000000000");
|
|
|
15
15
|
const BIG_NUMBER_ETH_MULTIPLIER = new bignumber_js.BigNumber("1");
|
|
16
16
|
// Setter Maps
|
|
17
17
|
const toBigNumber = {
|
|
18
|
-
hex: n => new bignumber_js.BigNumber(
|
|
18
|
+
hex: n => new bignumber_js.BigNumber(metadataHelpers.remove0x(n), 16),
|
|
19
19
|
dec: n => new bignumber_js.BigNumber(String(n), 10),
|
|
20
20
|
BN: n => new bignumber_js.BigNumber(n.toString(16), 16)
|
|
21
21
|
};
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
4
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
5
|
+
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
5
6
|
var bignumber_js = require('bignumber.js');
|
|
6
7
|
var log = require('loglevel');
|
|
7
8
|
var viem = require('viem');
|
|
8
9
|
var TransactionUtils = require('../Transaction/TransactionUtils.js');
|
|
9
10
|
var constants = require('./constants.js');
|
|
10
|
-
var hex = require('./hex.js');
|
|
11
11
|
|
|
12
|
-
function hexToBn(hex
|
|
13
|
-
return new bignumber_js.BigNumber(
|
|
12
|
+
function hexToBn(hex) {
|
|
13
|
+
return new bignumber_js.BigNumber(metadataHelpers.remove0x(hex), 16);
|
|
14
14
|
}
|
|
15
15
|
function BNToHex(bn) {
|
|
16
|
-
return
|
|
16
|
+
return metadataHelpers.add0x(bn.toString(16));
|
|
17
17
|
}
|
|
18
18
|
function getEtherScanHashLink(txHash, chainId) {
|
|
19
19
|
if (!constants.SUPPORTED_NETWORKS[chainId]) return "";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var metadataHelpers = require('@toruslabs/metadata-helpers');
|
|
3
4
|
var log = require('loglevel');
|
|
4
5
|
var viem = require('viem');
|
|
5
6
|
var constants = require('./constants.js');
|
|
6
|
-
var hex = require('./hex.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Transaction decoder for analytics.
|
|
@@ -15,7 +15,7 @@ const transactionDecoder = async (req, chainId) => {
|
|
|
15
15
|
try {
|
|
16
16
|
if (req.method === constants.METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
|
|
17
17
|
const rawTx = req.params[0];
|
|
18
|
-
const normalizedRawTx =
|
|
18
|
+
const normalizedRawTx = metadataHelpers.add0x(rawTx);
|
|
19
19
|
sender = await viem.recoverTransactionAddress({
|
|
20
20
|
serializedTransaction: normalizedRawTx
|
|
21
21
|
});
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { BaseController, TransactionStatus } from '@toruslabs/base-controllers';
|
|
4
|
-
import {
|
|
4
|
+
import { JRPCEngineV2, providerFromEngineV2 } from '@web3auth/auth';
|
|
5
5
|
import log from 'loglevel';
|
|
6
6
|
import { defineChain, createPublicClient, http, createWalletClient, custom, toHex, parseEther, isHex } from 'viem';
|
|
7
7
|
import { createPaymasterClient, createBundlerClient } from 'viem/account-abstraction';
|
|
8
8
|
|
|
9
|
-
const eoaInterceptorMiddleware = eoaAddress => (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const eoaInterceptorMiddleware = eoaAddress => async ({
|
|
10
|
+
request,
|
|
11
|
+
next,
|
|
12
|
+
context
|
|
13
|
+
}) => {
|
|
14
|
+
context.set("isAAProviderRequest", true);
|
|
15
|
+
if (request.method === "eth_accounts" || request.method === "eth_requestAccounts") {
|
|
16
|
+
return [eoaAddress];
|
|
15
17
|
}
|
|
16
|
-
next();
|
|
18
|
+
return next();
|
|
17
19
|
};
|
|
18
20
|
function eoaProviderAsMiddleware(provider) {
|
|
19
|
-
return async (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return end();
|
|
25
|
-
} catch (error) {
|
|
26
|
-
return end(error);
|
|
27
|
-
}
|
|
21
|
+
return async ({
|
|
22
|
+
request
|
|
23
|
+
}) => {
|
|
24
|
+
const result = await provider.request(request);
|
|
25
|
+
return result;
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
class AccountAbstractionController extends BaseController {
|
|
@@ -91,10 +89,10 @@ class AccountAbstractionController extends BaseController {
|
|
|
91
89
|
});
|
|
92
90
|
|
|
93
91
|
// viem wallet client using json-rpc account from eoaProvider
|
|
94
|
-
const aaEngine =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const provider =
|
|
92
|
+
const aaEngine = JRPCEngineV2.create({
|
|
93
|
+
middleware: [eoaInterceptorMiddleware(eoaAddress), eoaProviderAsMiddleware(eoaProvider)]
|
|
94
|
+
});
|
|
95
|
+
const provider = providerFromEngineV2(aaEngine);
|
|
98
96
|
// need to hoist the account address https://viem.sh/docs/clients/wallet#optional-hoist-the-account
|
|
99
97
|
const eoaWalletClient = createWalletClient({
|
|
100
98
|
account: eoaAddress,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionStatus } from '@toruslabs/base-controllers';
|
|
2
|
+
import { add0x } from '@toruslabs/metadata-helpers';
|
|
2
3
|
import { rpcErrors, JsonRpcError } from '@web3auth/auth';
|
|
3
4
|
import { GetCallsStatusCode, EIP_5792_METHODS, EIP5792ErrorCode } from '../utils/eip5792Types.js';
|
|
4
|
-
import { addHexPrefix } from '../utils/hex.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Maps a TransactionStatus to an EIP-5792 GetCallsStatusCode.
|
|
@@ -67,7 +67,7 @@ function walletGetCallsStatus(request, getTransactionByBatchId) {
|
|
|
67
67
|
return {
|
|
68
68
|
status: mapTransactionStatusToEip5792Status(batchTx.status),
|
|
69
69
|
id: batchId,
|
|
70
|
-
chainId:
|
|
70
|
+
chainId: add0x(batchTx.chainId),
|
|
71
71
|
atomic: true,
|
|
72
72
|
receipts: batchTx.txReceipt ? [batchTx.txReceipt] : []
|
|
73
73
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { add0x } from '@toruslabs/metadata-helpers';
|
|
1
2
|
import { zeroAddress, encodeAbiParameters, parseAbiParameters, encodeFunctionData } from 'viem';
|
|
2
3
|
import { erc7821Abi } from '../utils/abis.js';
|
|
3
4
|
import { SUPPORTED_NETWORKS } from '../utils/constants.js';
|
|
4
5
|
import { EIP_7702_PREFIX } from '../utils/eip7702Types.js';
|
|
5
|
-
import { addHexPrefix } from '../utils/hex.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The MetaMask EIP-7702 Stateless Delegator contract address.
|
|
@@ -12,10 +12,10 @@ const MetaMask_EIP7702_Stateless_Delegator = "0x63c0c19a282a1B52b07dD5a65b58948A
|
|
|
12
12
|
async function getDelegationAddress(walletAddress, chainId, getEthCode) {
|
|
13
13
|
// query eth_getCode
|
|
14
14
|
const code = await getEthCode(walletAddress, chainId);
|
|
15
|
-
const normalizedCode = code ?
|
|
15
|
+
const normalizedCode = code ? add0x(code).toLowerCase() : "0x0";
|
|
16
16
|
const hasDelegation = normalizedCode.length === 48 && normalizedCode.startsWith(EIP_7702_PREFIX);
|
|
17
17
|
if (hasDelegation) {
|
|
18
|
-
const delegationAddress =
|
|
18
|
+
const delegationAddress = add0x(normalizedCode.slice(EIP_7702_PREFIX.length));
|
|
19
19
|
return delegationAddress;
|
|
20
20
|
}
|
|
21
21
|
return null;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
2
|
import { BaseController, PollingManager, cloneDeep } from '@toruslabs/base-controllers';
|
|
3
|
+
import { isHexString } from '@toruslabs/metadata-helpers';
|
|
3
4
|
import log from 'loglevel';
|
|
4
|
-
import { isHex } from 'viem';
|
|
5
5
|
import { GAS_ESTIMATE_TYPES } from '../utils/constants.js';
|
|
6
|
-
import { addHexPrefix } from '../utils/hex.js';
|
|
7
6
|
import { fetchGasEstimates, fetchEthGasPriceEstimate, fetchLegacyGasPriceEstimates, fetchGasEstimatesViaEthFeeHistory, calculateTimeEstimate } from './gasUtil.js';
|
|
8
7
|
|
|
9
8
|
const GAS_FEE_API = "https://mock-gas-server.herokuapp.com/";
|
|
@@ -120,7 +119,7 @@ class GasFeeController extends BaseController {
|
|
|
120
119
|
const chainId = this.getNetworkIdentifier();
|
|
121
120
|
if (chainId === "loading") return;
|
|
122
121
|
let chainIdInt;
|
|
123
|
-
if (
|
|
122
|
+
if (isHexString(chainId)) {
|
|
124
123
|
chainIdInt = Number.parseInt(chainId, 16);
|
|
125
124
|
}
|
|
126
125
|
try {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import { BaseKeyringController, ecsignature, concatSig } from '@toruslabs/base-controllers';
|
|
3
|
-
import { hexToBytes } from '@toruslabs/metadata-helpers';
|
|
3
|
+
import { add0x, remove0x, hexToBytes } from '@toruslabs/metadata-helpers';
|
|
4
4
|
import { serializeTransaction, keccak256, parseSignature, toHex, isHex } from 'viem';
|
|
5
5
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
6
|
-
import { addHexPrefix, stripHexPrefix } from '../utils/hex.js';
|
|
7
6
|
import { prepareViemTx } from '../utils/viem.js';
|
|
8
7
|
|
|
9
8
|
class KeyringController extends BaseKeyringController {
|
|
@@ -22,7 +21,7 @@ class KeyringController extends BaseKeyringController {
|
|
|
22
21
|
}
|
|
23
22
|
async signTransaction(tx, address) {
|
|
24
23
|
const wallet = this._getWalletForAccount(address);
|
|
25
|
-
const account = privateKeyToAccount(
|
|
24
|
+
const account = privateKeyToAccount(add0x(wallet.privateKey));
|
|
26
25
|
const localTx = tx;
|
|
27
26
|
const txToSign = prepareViemTx(localTx);
|
|
28
27
|
// NOTE: don't use account.signTransaction directly because it only return signed serialized transaction
|
|
@@ -42,7 +41,7 @@ class KeyringController extends BaseKeyringController {
|
|
|
42
41
|
}
|
|
43
42
|
async signEip7702Authorization(authorization, address) {
|
|
44
43
|
const wallet = this._getWalletForAccount(address);
|
|
45
|
-
const account = privateKeyToAccount(
|
|
44
|
+
const account = privateKeyToAccount(add0x(wallet.privateKey));
|
|
46
45
|
|
|
47
46
|
// Convert hex strings to proper types for RLP encoding
|
|
48
47
|
// EIP-7702 authorization tuple: [chain_id_decimal, address, nonce_decimal]
|
|
@@ -67,8 +66,8 @@ class KeyringController extends BaseKeyringController {
|
|
|
67
66
|
}
|
|
68
67
|
async importAccount(accountPrivateKey) {
|
|
69
68
|
try {
|
|
70
|
-
const hexPrivateKey = accountPrivateKey.padStart(64, "0");
|
|
71
|
-
const account = privateKeyToAccount(
|
|
69
|
+
const hexPrivateKey = remove0x(accountPrivateKey).padStart(64, "0");
|
|
70
|
+
const account = privateKeyToAccount(add0x(hexPrivateKey));
|
|
72
71
|
const publicKey = account.publicKey;
|
|
73
72
|
const address = account.address;
|
|
74
73
|
const existingWallet = this.state.wallets.find(w => w.address === address);
|
|
@@ -99,8 +98,7 @@ class KeyringController extends BaseKeyringController {
|
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
getPrivateKeyBytes(privateKey) {
|
|
102
|
-
|
|
103
|
-
return hexToBytes(stripped);
|
|
101
|
+
return hexToBytes(privateKey);
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
// For eth_sign, we need to sign arbitrary data:
|
|
@@ -110,14 +108,14 @@ class KeyringController extends BaseKeyringController {
|
|
|
110
108
|
}
|
|
111
109
|
const wallet = this._getWalletForAccount(address);
|
|
112
110
|
const privKey = this.getPrivateKeyBytes(wallet.privateKey);
|
|
113
|
-
const payload = hexToBytes(
|
|
111
|
+
const payload = hexToBytes(data);
|
|
114
112
|
const messageSig = ecsignature(payload, privKey);
|
|
115
113
|
const sig = concatSig(messageSig.v, messageSig.r, messageSig.s);
|
|
116
114
|
return sig;
|
|
117
115
|
}
|
|
118
116
|
async signPersonalMessage(data, address) {
|
|
119
117
|
const wallet = this._getWalletForAccount(address);
|
|
120
|
-
const account = privateKeyToAccount(
|
|
118
|
+
const account = privateKeyToAccount(add0x(wallet.privateKey));
|
|
121
119
|
// we need to check if the data is hex or not
|
|
122
120
|
// For historical reasons, you must submit the message to sign in hex-encoded UTF-8.
|
|
123
121
|
// https://docs.metamask.io/wallet/how-to/sign-data/#use-personal_sign
|
|
@@ -132,7 +130,7 @@ class KeyringController extends BaseKeyringController {
|
|
|
132
130
|
// personal_signTypedData, signs data along with the schema
|
|
133
131
|
async signTypedData(typedData, address) {
|
|
134
132
|
const wallet = this._getWalletForAccount(address);
|
|
135
|
-
const account = privateKeyToAccount(
|
|
133
|
+
const account = privateKeyToAccount(add0x(wallet.privateKey));
|
|
136
134
|
delete typedData.types.EIP712Domain;
|
|
137
135
|
const primaryType = typedData.primaryType;
|
|
138
136
|
if (!primaryType) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
2
|
-
import { bytesToHex, utf8ToBytes } from '@toruslabs/metadata-helpers';
|
|
2
|
+
import { isHexString, add0x, bytesToHex, utf8ToBytes } from '@toruslabs/metadata-helpers';
|
|
3
3
|
import { isHex, createPublicClient, http, toHex, isAddress } from 'viem';
|
|
4
|
-
import { stripHexPrefix, addHexPrefix } from '../utils/hex.js';
|
|
5
4
|
|
|
6
|
-
const hexRe = /^[0-9A-Fa-f]+$/gu;
|
|
7
5
|
function validateAddress(address, propertyName) {
|
|
8
6
|
if (!address || typeof address !== "string" || !isAddress(address)) {
|
|
9
7
|
throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
|
|
@@ -21,14 +19,13 @@ function validateSignMessageData(messageData) {
|
|
|
21
19
|
}
|
|
22
20
|
function normalizeMessageData(data) {
|
|
23
21
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return addHexPrefix(stripped);
|
|
22
|
+
if (isHexString(data)) {
|
|
23
|
+
return add0x(data);
|
|
27
24
|
}
|
|
28
25
|
} catch {
|
|
29
26
|
// do nothing
|
|
30
27
|
}
|
|
31
|
-
return
|
|
28
|
+
return add0x(bytesToHex(utf8ToBytes(data)));
|
|
32
29
|
}
|
|
33
30
|
async function validateTypedSignMessageDataV4(messageData, currentChainId) {
|
|
34
31
|
validateAddress(messageData.from, "from");
|
|
@@ -2,7 +2,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
2
2
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import { BaseController, createAnalyticsMiddleware, createSwappableProxy, createEventEmitterProxy } from '@toruslabs/base-controllers';
|
|
5
|
-
import {
|
|
5
|
+
import { JRPCEngineV2, providerFromEngineV2 } from '@web3auth/auth';
|
|
6
6
|
import { Mutex } from 'async-mutex';
|
|
7
7
|
import log from 'loglevel';
|
|
8
8
|
import { SUPPORTED_NETWORKS, MAINNET_CHAIN_ID } from '../utils/constants.js';
|
|
@@ -151,15 +151,13 @@ class NetworkController extends BaseController {
|
|
|
151
151
|
networkMiddleware,
|
|
152
152
|
blockTracker
|
|
153
153
|
}) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
})
|
|
160
|
-
engine
|
|
161
|
-
engine.push(networkMiddleware);
|
|
162
|
-
const provider = providerFromEngine(engine);
|
|
154
|
+
const engine = JRPCEngineV2.create({
|
|
155
|
+
middleware: [createAnalyticsMiddleware({
|
|
156
|
+
providerConfig: this.getProviderConfig(),
|
|
157
|
+
analytics: this.analytics
|
|
158
|
+
}), createEthereumMiddleware(this.baseProviderHandlers, this.getProviderConfig(), this.analytics), networkMiddleware]
|
|
159
|
+
});
|
|
160
|
+
const provider = providerFromEngineV2(engine);
|
|
163
161
|
this.setProvider({
|
|
164
162
|
provider,
|
|
165
163
|
blockTracker
|