@mentaproject/core 0.5.15 → 0.6.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/clients/index.js +62 -1
- package/dist/clients/index.js.map +1 -1
- package/dist/clients/index.mjs +62 -1
- package/dist/clients/index.mjs.map +1 -1
- package/dist/types/CoreClient.d.ts +10 -1
- package/dist/types/MentaAccount.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/createRoutedTransport.d.ts +22 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +59 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +59 -1
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/clients/createMentaAccount.ts +9 -1
- package/src/types/CoreClient.ts +13 -1
- package/src/types/MentaAccount.ts +3 -0
- package/src/types/index.ts +1 -1
- package/src/utils/createRoutedTransport.ts +65 -0
- package/src/utils/index.ts +2 -1
package/dist/clients/index.js
CHANGED
|
@@ -5939,6 +5939,64 @@ const getValidatorAddress = (entryPoint, kernelVersion, validatorContractVersion
|
|
|
5939
5939
|
return validatorAddress ?? passKeyValidatorAddress ?? viem.zeroAddress;
|
|
5940
5940
|
};
|
|
5941
5941
|
|
|
5942
|
+
/**
|
|
5943
|
+
* RPC methods that should be routed to the bundler.
|
|
5944
|
+
* All other methods will be routed to the public RPC.
|
|
5945
|
+
*/
|
|
5946
|
+
const BUNDLER_METHODS = new Set([
|
|
5947
|
+
// ERC-4337 standard methods
|
|
5948
|
+
"eth_sendUserOperation",
|
|
5949
|
+
"eth_estimateUserOperationGas",
|
|
5950
|
+
"eth_getUserOperationByHash",
|
|
5951
|
+
"eth_getUserOperationReceipt",
|
|
5952
|
+
"eth_supportedEntryPoints",
|
|
5953
|
+
// Pimlico-specific methods
|
|
5954
|
+
"pimlico_getUserOperationGasPrice",
|
|
5955
|
+
"pimlico_getUserOperationStatus",
|
|
5956
|
+
"pimlico_sendCompressedUserOperation",
|
|
5957
|
+
// pm_ paymaster methods (used by some bundlers)
|
|
5958
|
+
"pm_getPaymasterData",
|
|
5959
|
+
"pm_getPaymasterStubData",
|
|
5960
|
+
"pm_sponsorUserOperation",
|
|
5961
|
+
"pm_validateSponsorshipPolicies",
|
|
5962
|
+
]);
|
|
5963
|
+
/**
|
|
5964
|
+
* Creates a transport that routes requests between a public RPC and a bundler RPC.
|
|
5965
|
+
*
|
|
5966
|
+
* Bundler-specific methods (ERC-4337) are routed to the bundler transport,
|
|
5967
|
+
* while all other methods (eth_getBlockByNumber, eth_call, etc.) are routed
|
|
5968
|
+
* to the public transport.
|
|
5969
|
+
*
|
|
5970
|
+
* @param publicTransport - Transport for standard Ethereum RPC calls
|
|
5971
|
+
* @param bundlerTransport - Transport for ERC-4337 bundler calls
|
|
5972
|
+
* @returns A unified transport that routes requests appropriately
|
|
5973
|
+
*
|
|
5974
|
+
* @example
|
|
5975
|
+
* import { http } from 'viem';
|
|
5976
|
+
* import { createRoutedTransport } from '@mentaproject/core/utils';
|
|
5977
|
+
*
|
|
5978
|
+
* const transport = createRoutedTransport(
|
|
5979
|
+
* http('https://eth-mainnet.g.alchemy.com/v2/...'),
|
|
5980
|
+
* http('https://api.pimlico.io/v2/1/rpc?apikey=...')
|
|
5981
|
+
* );
|
|
5982
|
+
*/
|
|
5983
|
+
function createRoutedTransport(publicTransport, bundlerTransport) {
|
|
5984
|
+
return (params) => {
|
|
5985
|
+
const publicClient = publicTransport(params);
|
|
5986
|
+
const bundlerClient = bundlerTransport(params);
|
|
5987
|
+
const request = async ({ method, params: reqParams }) => {
|
|
5988
|
+
if (BUNDLER_METHODS.has(method)) {
|
|
5989
|
+
return bundlerClient.request({ method, params: reqParams });
|
|
5990
|
+
}
|
|
5991
|
+
return publicClient.request({ method, params: reqParams });
|
|
5992
|
+
};
|
|
5993
|
+
return {
|
|
5994
|
+
...publicClient,
|
|
5995
|
+
request,
|
|
5996
|
+
};
|
|
5997
|
+
};
|
|
5998
|
+
}
|
|
5999
|
+
|
|
5942
6000
|
async function createMentaAccount(client, params) {
|
|
5943
6001
|
const validator = await toPasskeyValidator(client, {
|
|
5944
6002
|
webAuthnKey: params.signer,
|
|
@@ -5953,9 +6011,12 @@ async function createMentaAccount(client, params) {
|
|
|
5953
6011
|
owners: [validator],
|
|
5954
6012
|
client: client,
|
|
5955
6013
|
});
|
|
6014
|
+
// Create a routed transport that sends bundler methods to the bundler
|
|
6015
|
+
// and all other RPC calls to the public transport
|
|
6016
|
+
const routedTransport = createRoutedTransport(params.publicTransport, params.bundlerTransport);
|
|
5956
6017
|
return permissionless.createSmartAccountClient({
|
|
5957
6018
|
account: kernel,
|
|
5958
|
-
bundlerTransport:
|
|
6019
|
+
bundlerTransport: routedTransport,
|
|
5959
6020
|
}).extend(erc7579.erc7579Actions());
|
|
5960
6021
|
}
|
|
5961
6022
|
|