@aa-sdk/core 4.34.1 → 4.35.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/esm/client/smartAccountClient.js +5 -8
- package/dist/esm/client/smartAccountClient.js.map +1 -1
- package/dist/esm/transport/split.js +1 -1
- package/dist/esm/transport/split.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/client/smartAccountClient.d.ts.map +1 -1
- package/dist/types/transport/split.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/smartAccountClient.ts +87 -93
- package/src/transport/split.ts +8 -11
- package/src/version.ts +1 -1
|
@@ -3,11 +3,11 @@ import { z } from "zod";
|
|
|
3
3
|
import { AccountNotFoundError } from "../errors/account.js";
|
|
4
4
|
import { ChainNotFoundError } from "../errors/client.js";
|
|
5
5
|
import { middlewareActions } from "../middleware/actions.js";
|
|
6
|
-
import { ADD_BREADCRUMB } from "./addBreadcrumb.js";
|
|
7
6
|
import { createBundlerClient } from "./bundlerClient.js";
|
|
8
7
|
import {} from "./decorators/bundlerClient.js";
|
|
9
8
|
import { smartAccountClientActions, } from "./decorators/smartAccountClient.js";
|
|
10
9
|
import { SmartAccountClientOptsSchema } from "./schema.js";
|
|
10
|
+
import { ADD_BREADCRUMB } from "./addBreadcrumb.js";
|
|
11
11
|
/**
|
|
12
12
|
* Creates a smart account client using the provided configuration. This client handles various Ethereum transactions and message signing operations.
|
|
13
13
|
*
|
|
@@ -69,8 +69,7 @@ export function createSmartAccountClient(config) {
|
|
|
69
69
|
throw new AccountNotFoundError();
|
|
70
70
|
}
|
|
71
71
|
const [address, data] = params;
|
|
72
|
-
if (address?.toLowerCase() !==
|
|
73
|
-
client.account.address.toLowerCase()) {
|
|
72
|
+
if (address?.toLowerCase() !== client.account.address.toLowerCase()) {
|
|
74
73
|
throw new Error("cannot sign for address that is not the current account");
|
|
75
74
|
}
|
|
76
75
|
return client.signMessage({
|
|
@@ -82,8 +81,7 @@ export function createSmartAccountClient(config) {
|
|
|
82
81
|
throw new AccountNotFoundError();
|
|
83
82
|
}
|
|
84
83
|
const [data, address] = params;
|
|
85
|
-
if (address?.toLowerCase() !==
|
|
86
|
-
client.account.address.toLowerCase()) {
|
|
84
|
+
if (address?.toLowerCase() !== client.account.address.toLowerCase()) {
|
|
87
85
|
throw new Error("cannot sign for address that is not the current account");
|
|
88
86
|
}
|
|
89
87
|
return client.signMessage({
|
|
@@ -96,8 +94,7 @@ export function createSmartAccountClient(config) {
|
|
|
96
94
|
throw new AccountNotFoundError();
|
|
97
95
|
}
|
|
98
96
|
const [address, dataParams] = params;
|
|
99
|
-
if (address?.toLowerCase() !==
|
|
100
|
-
client.account.address.toLowerCase()) {
|
|
97
|
+
if (address?.toLowerCase() !== client.account.address.toLowerCase()) {
|
|
101
98
|
throw new Error("cannot sign for address that is not the current account");
|
|
102
99
|
}
|
|
103
100
|
try {
|
|
@@ -123,7 +120,7 @@ export function createSmartAccountClient(config) {
|
|
|
123
120
|
return rpcTransport.request({ method, params });
|
|
124
121
|
}
|
|
125
122
|
},
|
|
126
|
-
}
|
|
123
|
+
})(opts);
|
|
127
124
|
},
|
|
128
125
|
})
|
|
129
126
|
.extend(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountClient.js","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,GAUP,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAA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AAC;QACP,OAAO;YACL,GAAG,4BAA4B,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACxD,GAAG,cAAc;SAClB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;SACjC,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAErC,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;AAC7B,CAAC;AAgCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,oCAAoC,CAClD,MAEC;IAED,OAAO,wBAAwB,CAAC;QAC9B,GAAG,MAAM;QACT,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;QAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n custom,\n type Chain,\n type Client,\n type ClientConfig,\n type CustomTransport,\n type FormattedTransactionRequest,\n type PublicActions,\n type PublicRpcSchema,\n type RpcSchema,\n type Transport,\n} from \"viem\";\nimport { z } from \"zod\";\nimport type { SmartContractAccount } from \"../account/smartContractAccount.js\";\nimport type { UserOperationContext } from \"../actions/smartAccount/types.js\";\nimport { AccountNotFoundError } from \"../errors/account.js\";\nimport { ChainNotFoundError } from \"../errors/client.js\";\nimport { middlewareActions } from \"../middleware/actions.js\";\nimport type { ClientMiddleware } from \"../middleware/types.js\";\nimport type { Prettify } from \"../utils/index.js\";\nimport { ADD_BREADCRUMB } from \"./addBreadcrumb.js\";\nimport { createBundlerClient, type BundlerClient } from \"./bundlerClient.js\";\nimport {\n type BundlerActions,\n type BundlerRpcSchema,\n} from \"./decorators/bundlerClient.js\";\nimport {\n smartAccountClientActions,\n type BaseSmartAccountClientActions,\n} from \"./decorators/smartAccountClient.js\";\nimport { SmartAccountClientOptsSchema } from \"./schema.js\";\nimport type { ClientMiddlewareConfig } from \"./types.js\";\n\ntype SmartAccountClientOpts = z.output<typeof SmartAccountClientOptsSchema>;\n\nexport type SmartAccountClientConfig<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n Pick<\n ClientConfig<transport, chain, account>,\n | \"cacheTime\"\n | \"chain\"\n | \"key\"\n | \"name\"\n | \"pollingInterval\"\n | \"transport\"\n | \"type\"\n > & {\n account?: account;\n opts?: z.input<typeof SmartAccountClientOptsSchema>;\n /**\n * A function that adds a breadcrumb to the current context\n * Note, most implementations will override the client with the default alchemy transport and this\n * leads to the fact that a transport could be overwritten and not known until later.\n *\n * @param crumb A crumb, or span is telling that we are in a next step part of a multi step action\n * @returns\n */\n addBreadCrumb?: <T>(crumb: string) => T;\n } & ClientMiddlewareConfig<context>\n>;\n\nexport type SmartAccountClientRpcSchema = [\n ...BundlerRpcSchema,\n ...PublicRpcSchema\n];\n\n// [!region SmartAccountClientActions]\nexport type SmartAccountClientActions<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = BaseSmartAccountClientActions<chain, account, context> &\n BundlerActions &\n PublicActions;\n// [!endregion SmartAccountClientActions]\n\n// [!region SmartAccountClient]\nexport type SmartAccountClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n rpcSchema extends RpcSchema = SmartAccountClientRpcSchema,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n Client<\n transport,\n chain,\n account,\n rpcSchema,\n actions & SmartAccountClientActions<chain, account, context>\n >\n>;\n// [!endregion SmartAccountClient]\n\nexport type BaseSmartAccountClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n Client<\n transport,\n chain,\n account,\n [...BundlerRpcSchema, ...PublicRpcSchema],\n {\n middleware: ClientMiddleware<context>;\n } & SmartAccountClientOpts &\n BundlerActions &\n PublicActions\n >\n>;\n\nexport function createSmartAccountClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>(\n config: SmartAccountClientConfig<TTransport, TChain, TAccount, TContext>\n): SmartAccountClient<TTransport, TChain, TAccount>;\n\n/**\n * Creates a smart account client using the provided configuration. This client handles various Ethereum transactions and message signing operations.\n *\n * @example\n * ```ts\n * import { createSmartAccountClient, toSmartContractAccount } from \"@aa-sdk/core\";\n * import { http } from \"viem\";\n * import { sepolia } from \"viem/chains\";\n *\n * const client = createSmartAccountClient({\n * chain: sepolia,\n * transport: http(\"RPC_URL\"),\n * // optionally hoist the account\n * account: toSmartContractAccount(...),\n * });\n * ```\n *\n * @param {SmartAccountClientConfig} config The configuration for creating the smart account client\n * @returns {SmartAccountClient} A smart account client capable of handling transactions, message signing, and other operations on a smart account\n */\nexport function createSmartAccountClient(\n config: SmartAccountClientConfig\n): SmartAccountClient {\n const {\n key = \"account\",\n name = \"account provider\",\n transport,\n type = \"SmartAccountClient\",\n addBreadCrumb,\n ...params\n } = config;\n\n const client: SmartAccountClient = createBundlerClient({\n ...params,\n key,\n name,\n // we start out with this because the base methods for a SmartAccountClient\n // require a smart account client, but once we have completed building everything\n // we want to override this value with the one passed in by the extender\n type: \"SmartAccountClient\",\n // TODO: this needs to be tested\n transport: (opts) => {\n const rpcTransport = transport(opts);\n\n return custom(\n {\n name: \"SmartAccountClientTransport\",\n async request({ method, params }) {\n switch (method) {\n case \"eth_accounts\": {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n return [client.account.address];\n }\n case \"eth_sendTransaction\":\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n const [tx] = params as [FormattedTransactionRequest];\n return client.sendTransaction({\n ...tx,\n account: client.account,\n chain: client.chain,\n });\n case \"eth_sign\":\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n const [address, data] = params!;\n if (\n address?.toLowerCase() !==\n client.account.address.toLowerCase()\n ) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n return client.signMessage({\n message: data,\n account: client.account,\n });\n case \"personal_sign\": {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n const [data, address] = params!;\n if (\n address?.toLowerCase() !==\n client.account.address.toLowerCase()\n ) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n return client.signMessage({\n message: data,\n account: client.account,\n });\n }\n case \"eth_signTypedData_v4\": {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n const [address, dataParams] = params!;\n if (\n address?.toLowerCase() !==\n client.account.address.toLowerCase()\n ) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n try {\n return client.signTypedData({\n account: client.account,\n typedData:\n typeof dataParams === \"string\"\n ? JSON.parse(dataParams)\n : dataParams,\n });\n } catch {\n throw new Error(\"invalid JSON data params\");\n }\n }\n case \"eth_chainId\":\n if (!opts.chain) {\n throw new ChainNotFoundError();\n }\n\n return opts.chain.id;\n default:\n // TODO: there's probably a number of methods we just don't support, will need to test most of them out\n // first let's get something working though\n return rpcTransport.request({ method, params });\n }\n },\n },\n { retryCount: 0 }\n )(opts);\n },\n })\n .extend(() => {\n const addBreadCrumbs = addBreadCrumb\n ? {\n [ADD_BREADCRUMB]: addBreadCrumb,\n }\n : {};\n return {\n ...SmartAccountClientOptsSchema.parse(config.opts ?? {}),\n ...addBreadCrumbs,\n };\n })\n .extend(middlewareActions(config))\n .extend(smartAccountClientActions);\n\n return { ...client, type };\n}\n\nexport function createSmartAccountClientFromExisting<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TClient extends BundlerClient<TTransport> = BundlerClient<TTransport>,\n TActions extends SmartAccountClientActions<\n TChain,\n TAccount,\n TContext\n > = SmartAccountClientActions<TChain, TAccount>,\n TRpcSchema extends SmartAccountClientRpcSchema = SmartAccountClientRpcSchema,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>(\n config: Omit<\n SmartAccountClientConfig<Transport, TChain, TAccount, TContext>,\n \"transport\" | \"chain\"\n > & { client: TClient }\n): SmartAccountClient<\n CustomTransport,\n TChain,\n TAccount,\n TActions,\n TRpcSchema,\n TContext\n>;\n\n/**\n * Creates a smart account client using an existing client and specific configuration. This function can be used to reuse a pre-existing BundlerClient while customizing other aspects of the smart account.\n *\n * @example\n * ```ts\n * import {\n * createBundlerClient,\n * createSmartAccountClientFromExisting,\n * toSmartContractAccount\n * } from \"@aa-sdk/core\";\n *\n * const bundlerClient = createBundlerClient(...);\n * const client = createSmartAccountClientFromExisting({\n * client,\n * account: toSmartContractAccount(...),\n * })\n * ```\n *\n * @param {Omit<SmartAccountClientConfig, \"transport\" | \"chain\"> & {client: BundlerClient}} config the configuration object which includes the client\n * @returns {SmartAccountClient} A smart account client created from the existing BundlerClient\n */\nexport function createSmartAccountClientFromExisting(\n config: Omit<SmartAccountClientConfig, \"transport\" | \"chain\"> & {\n client: BundlerClient;\n }\n): SmartAccountClient {\n return createSmartAccountClient({\n ...config,\n chain: config.client.chain,\n transport: custom(config.client),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"smartAccountClient.js","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,GAUP,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,o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ACF,CAAC;SACC,MAAM,CAAC,GAAG,EAAE;QACX,MAAM,cAAc,GAAG,aAAa;YAClC,CAAC,CAAC;gBACE,CAAC,cAAc,CAAC,EAAE,aAAa;aAChC;YACH,CAAC,CAAC,EAAE,CAAC;QACP,OAAO;YACL,GAAG,4BAA4B,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACxD,GAAG,cAAc;SAClB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;SACjC,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAErC,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;AAC7B,CAAC;AAgCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,oCAAoC,CAClD,MAEC;IAED,OAAO,wBAAwB,CAAC;QAC9B,GAAG,MAAM;QACT,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;QAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n custom,\n type Chain,\n type Client,\n type ClientConfig,\n type CustomTransport,\n type FormattedTransactionRequest,\n type PublicActions,\n type PublicRpcSchema,\n type RpcSchema,\n type Transport,\n} from \"viem\";\nimport { z } from \"zod\";\nimport type { SmartContractAccount } from \"../account/smartContractAccount.js\";\nimport type { UserOperationContext } from \"../actions/smartAccount/types.js\";\nimport { AccountNotFoundError } from \"../errors/account.js\";\nimport { ChainNotFoundError } from \"../errors/client.js\";\nimport { middlewareActions } from \"../middleware/actions.js\";\nimport type { ClientMiddleware } from \"../middleware/types.js\";\nimport type { Prettify } from \"../utils/index.js\";\nimport { createBundlerClient, type BundlerClient } from \"./bundlerClient.js\";\nimport {\n type BundlerActions,\n type BundlerRpcSchema,\n} from \"./decorators/bundlerClient.js\";\nimport {\n smartAccountClientActions,\n type BaseSmartAccountClientActions,\n} from \"./decorators/smartAccountClient.js\";\nimport { SmartAccountClientOptsSchema } from \"./schema.js\";\nimport type { ClientMiddlewareConfig } from \"./types.js\";\nimport { ADD_BREADCRUMB } from \"./addBreadcrumb.js\";\n\ntype SmartAccountClientOpts = z.output<typeof SmartAccountClientOptsSchema>;\n\nexport type SmartAccountClientConfig<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n Pick<\n ClientConfig<transport, chain, account>,\n | \"cacheTime\"\n | \"chain\"\n | \"key\"\n | \"name\"\n | \"pollingInterval\"\n | \"transport\"\n | \"type\"\n > & {\n account?: account;\n opts?: z.input<typeof SmartAccountClientOptsSchema>;\n /**\n * A function that adds a breadcrumb to the current context\n * Note, most implementations will override the client with the default alchemy transport and this\n * leads to the fact that a transport could be overwritten and not known until later.\n *\n * @param crumb A crumb, or span is telling that we are in a next step part of a multi step action\n * @returns\n */\n addBreadCrumb?: <T>(crumb: string) => T;\n } & ClientMiddlewareConfig<context>\n>;\n\nexport type SmartAccountClientRpcSchema = [\n ...BundlerRpcSchema,\n ...PublicRpcSchema\n];\n\n// [!region SmartAccountClientActions]\nexport type SmartAccountClientActions<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = BaseSmartAccountClientActions<chain, account, context> &\n BundlerActions &\n PublicActions;\n// [!endregion SmartAccountClientActions]\n\n// [!region SmartAccountClient]\nexport type SmartAccountClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n rpcSchema extends RpcSchema = SmartAccountClientRpcSchema,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n Client<\n transport,\n chain,\n account,\n rpcSchema,\n actions & SmartAccountClientActions<chain, account, context>\n >\n>;\n// [!endregion SmartAccountClient]\n\nexport type BaseSmartAccountClient<\n transport extends Transport = Transport,\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Prettify<\n Client<\n transport,\n chain,\n account,\n [...BundlerRpcSchema, ...PublicRpcSchema],\n {\n middleware: ClientMiddleware<context>;\n } & SmartAccountClientOpts &\n BundlerActions &\n PublicActions\n >\n>;\n\nexport function createSmartAccountClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>(\n config: SmartAccountClientConfig<TTransport, TChain, TAccount, TContext>\n): SmartAccountClient<TTransport, TChain, TAccount>;\n\n/**\n * Creates a smart account client using the provided configuration. This client handles various Ethereum transactions and message signing operations.\n *\n * @example\n * ```ts\n * import { createSmartAccountClient, toSmartContractAccount } from \"@aa-sdk/core\";\n * import { http } from \"viem\";\n * import { sepolia } from \"viem/chains\";\n *\n * const client = createSmartAccountClient({\n * chain: sepolia,\n * transport: http(\"RPC_URL\"),\n * // optionally hoist the account\n * account: toSmartContractAccount(...),\n * });\n * ```\n *\n * @param {SmartAccountClientConfig} config The configuration for creating the smart account client\n * @returns {SmartAccountClient} A smart account client capable of handling transactions, message signing, and other operations on a smart account\n */\nexport function createSmartAccountClient(\n config: SmartAccountClientConfig\n): SmartAccountClient {\n const {\n key = \"account\",\n name = \"account provider\",\n transport,\n type = \"SmartAccountClient\",\n addBreadCrumb,\n ...params\n } = config;\n\n const client: SmartAccountClient = createBundlerClient({\n ...params,\n key,\n name,\n // we start out with this because the base methods for a SmartAccountClient\n // require a smart account client, but once we have completed building everything\n // we want to override this value with the one passed in by the extender\n type: \"SmartAccountClient\",\n // TODO: this needs to be tested\n transport: (opts) => {\n const rpcTransport = transport(opts);\n\n return custom({\n name: \"SmartAccountClientTransport\",\n async request({ method, params }) {\n switch (method) {\n case \"eth_accounts\": {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n return [client.account.address];\n }\n case \"eth_sendTransaction\":\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n const [tx] = params as [FormattedTransactionRequest];\n return client.sendTransaction({\n ...tx,\n account: client.account,\n chain: client.chain,\n });\n case \"eth_sign\":\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n const [address, data] = params!;\n if (\n address?.toLowerCase() !== client.account.address.toLowerCase()\n ) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n return client.signMessage({\n message: data,\n account: client.account,\n });\n case \"personal_sign\": {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n const [data, address] = params!;\n if (\n address?.toLowerCase() !== client.account.address.toLowerCase()\n ) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n return client.signMessage({\n message: data,\n account: client.account,\n });\n }\n case \"eth_signTypedData_v4\": {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n const [address, dataParams] = params!;\n if (\n address?.toLowerCase() !== client.account.address.toLowerCase()\n ) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n try {\n return client.signTypedData({\n account: client.account,\n typedData:\n typeof dataParams === \"string\"\n ? JSON.parse(dataParams)\n : dataParams,\n });\n } catch {\n throw new Error(\"invalid JSON data params\");\n }\n }\n case \"eth_chainId\":\n if (!opts.chain) {\n throw new ChainNotFoundError();\n }\n\n return opts.chain.id;\n default:\n // TODO: there's probably a number of methods we just don't support, will need to test most of them out\n // first let's get something working though\n return rpcTransport.request({ method, params });\n }\n },\n })(opts);\n },\n })\n .extend(() => {\n const addBreadCrumbs = addBreadCrumb\n ? {\n [ADD_BREADCRUMB]: addBreadCrumb,\n }\n : {};\n return {\n ...SmartAccountClientOptsSchema.parse(config.opts ?? {}),\n ...addBreadCrumbs,\n };\n })\n .extend(middlewareActions(config))\n .extend(smartAccountClientActions);\n\n return { ...client, type };\n}\n\nexport function createSmartAccountClientFromExisting<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TClient extends BundlerClient<TTransport> = BundlerClient<TTransport>,\n TActions extends SmartAccountClientActions<\n TChain,\n TAccount,\n TContext\n > = SmartAccountClientActions<TChain, TAccount>,\n TRpcSchema extends SmartAccountClientRpcSchema = SmartAccountClientRpcSchema,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>(\n config: Omit<\n SmartAccountClientConfig<Transport, TChain, TAccount, TContext>,\n \"transport\" | \"chain\"\n > & { client: TClient }\n): SmartAccountClient<\n CustomTransport,\n TChain,\n TAccount,\n TActions,\n TRpcSchema,\n TContext\n>;\n\n/**\n * Creates a smart account client using an existing client and specific configuration. This function can be used to reuse a pre-existing BundlerClient while customizing other aspects of the smart account.\n *\n * @example\n * ```ts\n * import {\n * createBundlerClient,\n * createSmartAccountClientFromExisting,\n * toSmartContractAccount\n * } from \"@aa-sdk/core\";\n *\n * const bundlerClient = createBundlerClient(...);\n * const client = createSmartAccountClientFromExisting({\n * client,\n * account: toSmartContractAccount(...),\n * })\n * ```\n *\n * @param {Omit<SmartAccountClientConfig, \"transport\" | \"chain\"> & {client: BundlerClient}} config the configuration object which includes the client\n * @returns {SmartAccountClient} A smart account client created from the existing BundlerClient\n */\nexport function createSmartAccountClientFromExisting(\n config: Omit<SmartAccountClientConfig, \"transport\" | \"chain\"> & {\n client: BundlerClient;\n }\n): SmartAccountClient {\n return createSmartAccountClient({\n ...config,\n chain: config.client.chain,\n transport: custom(config.client),\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../../src/transport/split.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M,CAAC,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;gBAC9D,MAAM,IAAI,KAAK,CACb,uDAAuD,CACxD,CAAC;YACJ,CAAC;YAED,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,IAAI,GAAG,EAAqB,CAAC,CAAC;IAEjC,OAAO,CAAC,IAAI,EAAE,EAAE,CACd,MAAM,CAAC;QACL,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACtB,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvD,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;gBAC9B,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC;YAED,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC,IAAI,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { custom, type CustomTransport, type Transport } from \"viem\";\n\nexport interface SplitTransportParams {\n overrides: {\n methods: string[];\n transport: Transport;\n }[];\n fallback: Transport;\n}\n\n/**\n * The Split Transport allows you to split RPC traffic for specific methods across\n * different RPC providers. This is done by specifying the methods you want handled\n * specially as overrides and providing a fallback transport for all other methods.\n *\n * @example\n * ```ts\n * import { createPublicClient, http } from \"viem\";\n * import { split } from \"@aa-sdk/core\";\n *\n * const bundlerMethods = [\n * \"eth_sendUserOperation\",\n * \"eth_estimateUserOperationGas\",\n * \"eth_getUserOperationReceipt\",\n * \"eth_getUserOperationByHash\",\n * \"eth_supportedEntryPoints\"\n * ];\n *\n * const clientWithSplit = createPublicClient({\n * transport: split({\n * overrides: [{\n * methods: bundlerMethods,\n * transport: http(BUNDLER_RPC_URL)\n * }],\n * fallback: http(OTHER_RPC_URL)\n * }),\n * });\n * ```\n *\n * @param {SplitTransportParams} params split transport configuration containing the methods overrides and fallback transport\n * @returns {CustomTransport} a viem Transport that splits traffic\n */\nexport const split = (params: SplitTransportParams): CustomTransport => {\n const overrideMap = params.overrides.reduce((accum, curr) => {\n curr.methods.forEach((method) => {\n if (accum.has(method) && accum.get(method) !== curr.transport) {\n throw new Error(\n \"A method cannot be handled by more than one transport\"\n );\n }\n\n accum.set(method, curr.transport);\n });\n\n return accum;\n }, new Map<string, Transport>());\n\n return (opts) =>\n custom({\n request: async (args) => {\n const transportOverride = overrideMap.get(args.method);\n if (transportOverride != null) {\n return transportOverride(opts).request(args);\n }\n\n return params.fallback(opts).request(args);\n },\n })(opts);\n};\n"]}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.35.0";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.35.0\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountClient.d.ts","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AA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IACJ,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,KAAK,WAAY,oBAAoB,KAAG,
|
|
1
|
+
{"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../../src/transport/split.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,MAAM,CAAC;AAEpE,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE;QACT,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,SAAS,EAAE,SAAS,CAAC;KACtB,EAAE,CAAC;IACJ,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,KAAK,WAAY,oBAAoB,KAAG,eA0BpD,CAAC"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.35.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aa-sdk/core",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.35.0",
|
|
5
5
|
"description": "viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts",
|
|
6
6
|
"author": "Alchemy",
|
|
7
7
|
"type": "module",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
66
66
|
},
|
|
67
67
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "3e5736311d16ae0eeaef9a869da2aff1e361a3f9"
|
|
69
69
|
}
|
|
@@ -18,7 +18,6 @@ import { ChainNotFoundError } from "../errors/client.js";
|
|
|
18
18
|
import { middlewareActions } from "../middleware/actions.js";
|
|
19
19
|
import type { ClientMiddleware } from "../middleware/types.js";
|
|
20
20
|
import type { Prettify } from "../utils/index.js";
|
|
21
|
-
import { ADD_BREADCRUMB } from "./addBreadcrumb.js";
|
|
22
21
|
import { createBundlerClient, type BundlerClient } from "./bundlerClient.js";
|
|
23
22
|
import {
|
|
24
23
|
type BundlerActions,
|
|
@@ -30,6 +29,7 @@ import {
|
|
|
30
29
|
} from "./decorators/smartAccountClient.js";
|
|
31
30
|
import { SmartAccountClientOptsSchema } from "./schema.js";
|
|
32
31
|
import type { ClientMiddlewareConfig } from "./types.js";
|
|
32
|
+
import { ADD_BREADCRUMB } from "./addBreadcrumb.js";
|
|
33
33
|
|
|
34
34
|
type SmartAccountClientOpts = z.output<typeof SmartAccountClientOptsSchema>;
|
|
35
35
|
|
|
@@ -189,106 +189,100 @@ export function createSmartAccountClient(
|
|
|
189
189
|
transport: (opts) => {
|
|
190
190
|
const rpcTransport = transport(opts);
|
|
191
191
|
|
|
192
|
-
return custom(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
192
|
+
return custom({
|
|
193
|
+
name: "SmartAccountClientTransport",
|
|
194
|
+
async request({ method, params }) {
|
|
195
|
+
switch (method) {
|
|
196
|
+
case "eth_accounts": {
|
|
197
|
+
if (!client.account) {
|
|
198
|
+
throw new AccountNotFoundError();
|
|
199
|
+
}
|
|
201
200
|
|
|
202
|
-
|
|
201
|
+
return [client.account.address];
|
|
202
|
+
}
|
|
203
|
+
case "eth_sendTransaction":
|
|
204
|
+
if (!client.account) {
|
|
205
|
+
throw new AccountNotFoundError();
|
|
203
206
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
207
|
+
if (!client.chain) {
|
|
208
|
+
throw new ChainNotFoundError();
|
|
209
|
+
}
|
|
210
|
+
const [tx] = params as [FormattedTransactionRequest];
|
|
211
|
+
return client.sendTransaction({
|
|
212
|
+
...tx,
|
|
213
|
+
account: client.account,
|
|
214
|
+
chain: client.chain,
|
|
215
|
+
});
|
|
216
|
+
case "eth_sign":
|
|
217
|
+
if (!client.account) {
|
|
218
|
+
throw new AccountNotFoundError();
|
|
219
|
+
}
|
|
220
|
+
const [address, data] = params!;
|
|
221
|
+
if (
|
|
222
|
+
address?.toLowerCase() !== client.account.address.toLowerCase()
|
|
223
|
+
) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
"cannot sign for address that is not the current account"
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return client.signMessage({
|
|
229
|
+
message: data,
|
|
230
|
+
account: client.account,
|
|
231
|
+
});
|
|
232
|
+
case "personal_sign": {
|
|
233
|
+
if (!client.account) {
|
|
234
|
+
throw new AccountNotFoundError();
|
|
235
|
+
}
|
|
236
|
+
const [data, address] = params!;
|
|
237
|
+
if (
|
|
238
|
+
address?.toLowerCase() !== client.account.address.toLowerCase()
|
|
239
|
+
) {
|
|
240
|
+
throw new Error(
|
|
241
|
+
"cannot sign for address that is not the current account"
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return client.signMessage({
|
|
245
|
+
message: data,
|
|
246
|
+
account: client.account,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
case "eth_signTypedData_v4": {
|
|
250
|
+
if (!client.account) {
|
|
251
|
+
throw new AccountNotFoundError();
|
|
252
|
+
}
|
|
253
|
+
const [address, dataParams] = params!;
|
|
254
|
+
if (
|
|
255
|
+
address?.toLowerCase() !== client.account.address.toLowerCase()
|
|
256
|
+
) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
"cannot sign for address that is not the current account"
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
return client.signTypedData({
|
|
249
263
|
account: client.account,
|
|
264
|
+
typedData:
|
|
265
|
+
typeof dataParams === "string"
|
|
266
|
+
? JSON.parse(dataParams)
|
|
267
|
+
: dataParams,
|
|
250
268
|
});
|
|
269
|
+
} catch {
|
|
270
|
+
throw new Error("invalid JSON data params");
|
|
251
271
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const [address, dataParams] = params!;
|
|
257
|
-
if (
|
|
258
|
-
address?.toLowerCase() !==
|
|
259
|
-
client.account.address.toLowerCase()
|
|
260
|
-
) {
|
|
261
|
-
throw new Error(
|
|
262
|
-
"cannot sign for address that is not the current account"
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
return client.signTypedData({
|
|
267
|
-
account: client.account,
|
|
268
|
-
typedData:
|
|
269
|
-
typeof dataParams === "string"
|
|
270
|
-
? JSON.parse(dataParams)
|
|
271
|
-
: dataParams,
|
|
272
|
-
});
|
|
273
|
-
} catch {
|
|
274
|
-
throw new Error("invalid JSON data params");
|
|
275
|
-
}
|
|
272
|
+
}
|
|
273
|
+
case "eth_chainId":
|
|
274
|
+
if (!opts.chain) {
|
|
275
|
+
throw new ChainNotFoundError();
|
|
276
276
|
}
|
|
277
|
-
case "eth_chainId":
|
|
278
|
-
if (!opts.chain) {
|
|
279
|
-
throw new ChainNotFoundError();
|
|
280
|
-
}
|
|
281
277
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
},
|
|
278
|
+
return opts.chain.id;
|
|
279
|
+
default:
|
|
280
|
+
// TODO: there's probably a number of methods we just don't support, will need to test most of them out
|
|
281
|
+
// first let's get something working though
|
|
282
|
+
return rpcTransport.request({ method, params });
|
|
283
|
+
}
|
|
289
284
|
},
|
|
290
|
-
|
|
291
|
-
)(opts);
|
|
285
|
+
})(opts);
|
|
292
286
|
},
|
|
293
287
|
})
|
|
294
288
|
.extend(() => {
|
package/src/transport/split.ts
CHANGED
|
@@ -56,17 +56,14 @@ export const split = (params: SplitTransportParams): CustomTransport => {
|
|
|
56
56
|
}, new Map<string, Transport>());
|
|
57
57
|
|
|
58
58
|
return (opts) =>
|
|
59
|
-
custom(
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
59
|
+
custom({
|
|
60
|
+
request: async (args) => {
|
|
61
|
+
const transportOverride = overrideMap.get(args.method);
|
|
62
|
+
if (transportOverride != null) {
|
|
63
|
+
return transportOverride(opts).request(args);
|
|
64
|
+
}
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
},
|
|
66
|
+
return params.fallback(opts).request(args);
|
|
69
67
|
},
|
|
70
|
-
|
|
71
|
-
)(opts);
|
|
68
|
+
})(opts);
|
|
72
69
|
};
|
package/src/version.ts
CHANGED