@account-kit/infra 4.28.3 → 4.29.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.
@@ -1,8 +1,8 @@
1
1
  import { ChainNotFoundError, ConnectionConfigSchema, split, } from "@aa-sdk/core";
2
2
  import { createTransport, http, } from "viem";
3
+ import { mutateRemoveTrackingHeaders } from "./alchemyTrackerHeaders.js";
3
4
  import { AlchemyChainSchema } from "./schema.js";
4
5
  import { VERSION } from "./version.js";
5
- import { mutateRemoveTrackingHeaders } from "./alchemyTrackerHeaders.js";
6
6
  const alchemyMethods = [
7
7
  "eth_sendUserOperation",
8
8
  "eth_estimateUserOperationGas",
@@ -14,6 +14,15 @@ const alchemyMethods = [
14
14
  "pm_getPaymasterStubData",
15
15
  "alchemy_requestGasAndPaymasterAndData",
16
16
  ];
17
+ const chainAgnosticMethods = [
18
+ "wallet_prepareCalls",
19
+ "wallet_sendPreparedCalls",
20
+ "wallet_requestAccount",
21
+ "wallet_createAccount",
22
+ "wallet_listAccounts",
23
+ "wallet_createSession",
24
+ "wallet_getCallsStatus",
25
+ ];
17
26
  /**
18
27
  * A type guard for the transport to determine if it is an Alchemy transport.
19
28
  * Used in cases where we would like to do switching depending on the transport, where there used
@@ -80,10 +89,10 @@ export function alchemy(config) {
80
89
  ...headersAsObject,
81
90
  "Alchemy-AA-Sdk-Version": VERSION,
82
91
  };
83
- if (connectionConfig.jwt != null) {
92
+ if (connectionConfig.jwt != null || connectionConfig.apiKey != null) {
84
93
  fetchOptions.headers = {
85
94
  ...fetchOptions.headers,
86
- Authorization: `Bearer ${connectionConfig.jwt}`,
95
+ Authorization: `Bearer ${connectionConfig.jwt ?? connectionConfig.apiKey}`,
87
96
  };
88
97
  }
89
98
  const transport = (opts) => {
@@ -93,7 +102,10 @@ export function alchemy(config) {
93
102
  }
94
103
  const chain = AlchemyChainSchema.parse(chain_);
95
104
  const rpcUrl = connectionConfig.rpcUrl == null
96
- ? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? ""}`
105
+ ? `${chain.rpcUrls.alchemy.http[0]}/`
106
+ : connectionConfig.rpcUrl;
107
+ const chainAgnosticRpcUrl = connectionConfig.rpcUrl == null
108
+ ? "https://api.g.alchemy.com/v2/"
97
109
  : connectionConfig.rpcUrl;
98
110
  const innerTransport = (() => {
99
111
  mutateRemoveTrackingHeaders(config?.fetchOptions?.headers);
@@ -104,13 +116,25 @@ export function alchemy(config) {
104
116
  methods: alchemyMethods,
105
117
  transport: http(rpcUrl, { fetchOptions }),
106
118
  },
119
+ {
120
+ methods: chainAgnosticMethods,
121
+ transport: http(chainAgnosticRpcUrl, { fetchOptions }),
122
+ },
107
123
  ],
108
124
  fallback: http(config.nodeRpcUrl, {
109
125
  fetchOptions: config.fetchOptions,
110
126
  }),
111
127
  });
112
128
  }
113
- return http(rpcUrl, { fetchOptions });
129
+ return split({
130
+ overrides: [
131
+ {
132
+ methods: chainAgnosticMethods,
133
+ transport: http(chainAgnosticRpcUrl, { fetchOptions }),
134
+ },
135
+ ],
136
+ fallback: http(rpcUrl, { fetchOptions }),
137
+ });
114
138
  })();
115
139
  return createTransport({
116
140
  key: "alchemy",
@@ -1 +1 @@
1
- {"version":3,"file":"alchemyTransport.js","sourceRoot":"","sources":["../../src/alchemyTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,GAGN,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,IAAI,GAOL,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAazE,MAAM,cAAc,GAAG;IACrB,uBAAuB;IACvB,8BAA8B;IAC9B,6BAA6B;IAC7B,4BAA4B;IAC5B,0BAA0B;IAC1B,8BAA8B;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AY,CAAC,OAAO,GAAG;gBACrB,GAAG,YAAY,CAAC,OAAO;gBACvB,GAAG,UAAU;aACd,CAAC;QACJ,CAAC;QACD,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAAqB,EACG,EAAE;IAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,EAA4B,CAAC;QACnD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC7B,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACpC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAA4B,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {\n ChainNotFoundError,\n ConnectionConfigSchema,\n split,\n type ConnectionConfig,\n type NoUndefined,\n} from \"@aa-sdk/core\";\nimport {\n createTransport,\n http,\n type Chain,\n type EIP1193RequestFn,\n type HttpTransportConfig,\n type PublicRpcSchema,\n type Transport,\n type TransportConfig,\n} from \"viem\";\nimport type { AlchemyRpcSchema } from \"./client/types.js\";\nimport { AlchemyChainSchema } from \"./schema.js\";\nimport { VERSION } from \"./version.js\";\nimport { mutateRemoveTrackingHeaders } from \"./alchemyTrackerHeaders.js\";\n\ntype Never<T> = T extends object\n ? {\n [K in keyof T]?: never;\n }\n : never;\n\ntype SplitTransportConfig = {\n alchemyConnection: ConnectionConfig;\n nodeRpcUrl: string;\n};\n\nconst alchemyMethods = [\n \"eth_sendUserOperation\",\n \"eth_estimateUserOperationGas\",\n \"eth_getUserOperationReceipt\",\n \"eth_getUserOperationByHash\",\n \"eth_supportedEntryPoints\",\n \"rundler_maxPriorityFeePerGas\",\n \"pm_getPaymasterData\",\n \"pm_getPaymasterStubData\",\n \"alchemy_requestGasAndPaymasterAndData\",\n];\n\nexport type AlchemyTransportConfig = (\n | (ConnectionConfig & Never<SplitTransportConfig>)\n | (SplitTransportConfig & Never<ConnectionConfig>)\n) & {\n /** The max number of times to retry. */\n retryCount?: TransportConfig[\"retryCount\"] | undefined;\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig[\"retryDelay\"] | undefined;\n fetchOptions?: NoUndefined<HttpTransportConfig[\"fetchOptions\"]>;\n};\n\ntype AlchemyTransportBase = Transport<\n \"alchemy\",\n {\n alchemyRpcUrl: string;\n fetchOptions?: AlchemyTransportConfig[\"fetchOptions\"];\n },\n EIP1193RequestFn<[...PublicRpcSchema, ...AlchemyRpcSchema]>\n>;\n\nexport type AlchemyTransport = AlchemyTransportBase & {\n updateHeaders(newHeaders: HeadersInit): void;\n config: AlchemyTransportConfig;\n dynamicFetchOptions: AlchemyTransportConfig[\"fetchOptions\"];\n};\n\n/**\n * A type guard for the transport to determine if it is an Alchemy transport.\n * Used in cases where we would like to do switching depending on the transport, where there used\n * to be two clients for a alchemy and a non alchemy, and with this switch we don't need the two seperate clients. *\n *\n * @param {Transport} transport The transport to check\n * @param {Chain} chain Chain for the transport to run its function to return the transport config\n * @returns {boolean} `true` if the transport is an Alchemy transport, otherwise `false`\n */\nexport function isAlchemyTransport(\n transport: Transport,\n chain: Chain\n): transport is AlchemyTransport {\n return transport({ chain }).config.type === \"alchemy\";\n}\n\n/**\n * Creates an Alchemy transport with the specified configuration options.\n * When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt.\n * If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.\n *\n * @example\n * ### Basic Example\n * If the chain you're using is supported for both Bundler and Node RPCs, then you can do the following:\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * // NOTE: you can also pass in an rpcUrl or jwt here or rpcUrl and jwt\n * apiKey: \"your-api-key\",\n * });\n * ```\n *\n * ### AA Only Chains\n * For AA-only chains, you need to specify the alchemyConnection and nodeRpcUrl since Alchemy only\n * handles the Bundler and Paymaster RPCs for these chains.\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * alchemyConnection: {\n * apiKey: \"your-api-key\",\n * },\n * nodeRpcUrl: \"https://zora.rpc.url\",\n * });\n * ```\n *\n * @param {AlchemyTransportConfig} config The configuration object for the Alchemy transport.\n * @param {number} config.retryDelay Optional The delay between retries, in milliseconds.\n * @param {number} config.retryCount Optional The number of retry attempts.\n * @param {string} [config.alchemyConnection] Optional Alchemy connection configuration (if this is passed in, nodeRpcUrl is required).\n * @param {string} [config.fetchOptions] Optional fetch options for HTTP requests.\n * @param {string} [config.nodeRpcUrl] Optional RPC URL for node (if this is passed in, alchemyConnection is required).\n * @param {string} [config.rpcUrl] Optional RPC URL.\n * @param {string} [config.apiKey] Optional API key for Alchemy.\n * @param {string} [config.jwt] Optional JSON Web Token for authorization.\n * @returns {AlchemyTransport} The configured Alchemy transport object.\n */\nexport function alchemy(config: AlchemyTransportConfig): AlchemyTransport {\n const { retryDelay, retryCount } = config;\n // we create a copy here in case we create a split transport down below\n // we don't want to add alchemy headers to 3rd party nodes\n const fetchOptions = { ...config.fetchOptions };\n\n const connectionConfig = ConnectionConfigSchema.parse(\n config.alchemyConnection ?? config\n );\n\n const headersAsObject = convertHeadersToObject(fetchOptions.headers);\n\n // TODO: we probably should just log these headers during telemetry logging instead of doing this mutable header stuff\n fetchOptions.headers = {\n ...headersAsObject,\n \"Alchemy-AA-Sdk-Version\": VERSION,\n };\n\n if (connectionConfig.jwt != null) {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n Authorization: `Bearer ${connectionConfig.jwt}`,\n };\n }\n\n const transport: AlchemyTransportBase = (opts) => {\n const { chain: chain_ } = opts;\n if (!chain_) {\n throw new ChainNotFoundError();\n }\n const chain = AlchemyChainSchema.parse(chain_);\n\n const rpcUrl =\n connectionConfig.rpcUrl == null\n ? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? \"\"}`\n : connectionConfig.rpcUrl;\n\n const innerTransport = (() => {\n mutateRemoveTrackingHeaders(config?.fetchOptions?.headers);\n if (config.alchemyConnection && config.nodeRpcUrl) {\n return split({\n overrides: [\n {\n methods: alchemyMethods,\n transport: http(rpcUrl, { fetchOptions }),\n },\n ],\n fallback: http(config.nodeRpcUrl, {\n fetchOptions: config.fetchOptions,\n }),\n });\n }\n\n return http(rpcUrl, { fetchOptions });\n })();\n\n return createTransport(\n {\n key: \"alchemy\",\n name: \"Alchemy Transport\",\n request: innerTransport(opts).request,\n retryCount: retryCount ?? opts?.retryCount,\n retryDelay,\n type: \"alchemy\",\n },\n { alchemyRpcUrl: rpcUrl, fetchOptions }\n );\n };\n\n return Object.assign(transport, {\n dynamicFetchOptions: fetchOptions,\n updateHeaders(newHeaders_: HeadersInit) {\n const newHeaders = convertHeadersToObject(newHeaders_);\n\n fetchOptions.headers = {\n ...fetchOptions.headers,\n ...newHeaders,\n };\n },\n config,\n });\n}\n\nexport const convertHeadersToObject = (\n headers?: HeadersInit\n): Record<string, string> => {\n if (!headers) {\n return {};\n }\n\n if (headers instanceof Headers) {\n const headersObject = {} as Record<string, string>;\n headers.forEach((value, key) => {\n headersObject[key] = value;\n });\n return headersObject;\n }\n\n if (Array.isArray(headers)) {\n return headers.reduce((acc, header) => {\n acc[header[0]] = header[1];\n return acc;\n }, {} as Record<string, string>);\n }\n\n return headers;\n};\n"]}
1
+ {"version":3,"file":"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EACG,EAAE;IAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,EAA4B,CAAC;QACnD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC7B,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACpC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAA4B,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {\n ChainNotFoundError,\n ConnectionConfigSchema,\n split,\n type ConnectionConfig,\n type NoUndefined,\n} from \"@aa-sdk/core\";\nimport {\n createTransport,\n http,\n type Chain,\n type EIP1193RequestFn,\n type HttpTransportConfig,\n type PublicRpcSchema,\n type Transport,\n type TransportConfig,\n} from \"viem\";\nimport { mutateRemoveTrackingHeaders } from \"./alchemyTrackerHeaders.js\";\nimport type { AlchemyRpcSchema } from \"./client/types.js\";\nimport { AlchemyChainSchema } from \"./schema.js\";\nimport { VERSION } from \"./version.js\";\n\ntype Never<T> = T extends object\n ? {\n [K in keyof T]?: never;\n }\n : never;\n\ntype SplitTransportConfig = {\n alchemyConnection: ConnectionConfig;\n nodeRpcUrl: string;\n};\n\nconst alchemyMethods = [\n \"eth_sendUserOperation\",\n \"eth_estimateUserOperationGas\",\n \"eth_getUserOperationReceipt\",\n \"eth_getUserOperationByHash\",\n \"eth_supportedEntryPoints\",\n \"rundler_maxPriorityFeePerGas\",\n \"pm_getPaymasterData\",\n \"pm_getPaymasterStubData\",\n \"alchemy_requestGasAndPaymasterAndData\",\n];\n\nconst chainAgnosticMethods = [\n \"wallet_prepareCalls\",\n \"wallet_sendPreparedCalls\",\n \"wallet_requestAccount\",\n \"wallet_createAccount\",\n \"wallet_listAccounts\",\n \"wallet_createSession\",\n \"wallet_getCallsStatus\",\n];\n\nexport type AlchemyTransportConfig = (\n | (ConnectionConfig & Never<SplitTransportConfig>)\n | (SplitTransportConfig & Never<ConnectionConfig>)\n) & {\n /** The max number of times to retry. */\n retryCount?: TransportConfig[\"retryCount\"] | undefined;\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig[\"retryDelay\"] | undefined;\n fetchOptions?: NoUndefined<HttpTransportConfig[\"fetchOptions\"]>;\n};\n\ntype AlchemyTransportBase = Transport<\n \"alchemy\",\n {\n alchemyRpcUrl: string;\n fetchOptions?: AlchemyTransportConfig[\"fetchOptions\"];\n },\n EIP1193RequestFn<[...PublicRpcSchema, ...AlchemyRpcSchema]>\n>;\n\nexport type AlchemyTransport = AlchemyTransportBase & {\n updateHeaders(newHeaders: HeadersInit): void;\n config: AlchemyTransportConfig;\n dynamicFetchOptions: AlchemyTransportConfig[\"fetchOptions\"];\n};\n\n/**\n * A type guard for the transport to determine if it is an Alchemy transport.\n * Used in cases where we would like to do switching depending on the transport, where there used\n * to be two clients for a alchemy and a non alchemy, and with this switch we don't need the two seperate clients. *\n *\n * @param {Transport} transport The transport to check\n * @param {Chain} chain Chain for the transport to run its function to return the transport config\n * @returns {boolean} `true` if the transport is an Alchemy transport, otherwise `false`\n */\nexport function isAlchemyTransport(\n transport: Transport,\n chain: Chain\n): transport is AlchemyTransport {\n return transport({ chain }).config.type === \"alchemy\";\n}\n\n/**\n * Creates an Alchemy transport with the specified configuration options.\n * When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt.\n * If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.\n *\n * @example\n * ### Basic Example\n * If the chain you're using is supported for both Bundler and Node RPCs, then you can do the following:\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * // NOTE: you can also pass in an rpcUrl or jwt here or rpcUrl and jwt\n * apiKey: \"your-api-key\",\n * });\n * ```\n *\n * ### AA Only Chains\n * For AA-only chains, you need to specify the alchemyConnection and nodeRpcUrl since Alchemy only\n * handles the Bundler and Paymaster RPCs for these chains.\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * alchemyConnection: {\n * apiKey: \"your-api-key\",\n * },\n * nodeRpcUrl: \"https://zora.rpc.url\",\n * });\n * ```\n *\n * @param {AlchemyTransportConfig} config The configuration object for the Alchemy transport.\n * @param {number} config.retryDelay Optional The delay between retries, in milliseconds.\n * @param {number} config.retryCount Optional The number of retry attempts.\n * @param {string} [config.alchemyConnection] Optional Alchemy connection configuration (if this is passed in, nodeRpcUrl is required).\n * @param {string} [config.fetchOptions] Optional fetch options for HTTP requests.\n * @param {string} [config.nodeRpcUrl] Optional RPC URL for node (if this is passed in, alchemyConnection is required).\n * @param {string} [config.rpcUrl] Optional RPC URL.\n * @param {string} [config.apiKey] Optional API key for Alchemy.\n * @param {string} [config.jwt] Optional JSON Web Token for authorization.\n * @returns {AlchemyTransport} The configured Alchemy transport object.\n */\nexport function alchemy(config: AlchemyTransportConfig): AlchemyTransport {\n const { retryDelay, retryCount } = config;\n // we create a copy here in case we create a split transport down below\n // we don't want to add alchemy headers to 3rd party nodes\n const fetchOptions = { ...config.fetchOptions };\n\n const connectionConfig = ConnectionConfigSchema.parse(\n config.alchemyConnection ?? config\n );\n\n const headersAsObject = convertHeadersToObject(fetchOptions.headers);\n\n // TODO: we probably should just log these headers during telemetry logging instead of doing this mutable header stuff\n fetchOptions.headers = {\n ...headersAsObject,\n \"Alchemy-AA-Sdk-Version\": VERSION,\n };\n\n if (connectionConfig.jwt != null || connectionConfig.apiKey != null) {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n Authorization: `Bearer ${\n connectionConfig.jwt ?? connectionConfig.apiKey\n }`,\n };\n }\n\n const transport: AlchemyTransportBase = (opts) => {\n const { chain: chain_ } = opts;\n if (!chain_) {\n throw new ChainNotFoundError();\n }\n const chain = AlchemyChainSchema.parse(chain_);\n\n const rpcUrl =\n connectionConfig.rpcUrl == null\n ? `${chain.rpcUrls.alchemy.http[0]}/`\n : connectionConfig.rpcUrl;\n\n const chainAgnosticRpcUrl =\n connectionConfig.rpcUrl == null\n ? \"https://api.g.alchemy.com/v2/\"\n : connectionConfig.rpcUrl;\n\n const innerTransport = (() => {\n mutateRemoveTrackingHeaders(config?.fetchOptions?.headers);\n if (config.alchemyConnection && config.nodeRpcUrl) {\n return split({\n overrides: [\n {\n methods: alchemyMethods,\n transport: http(rpcUrl, { fetchOptions }),\n },\n {\n methods: chainAgnosticMethods,\n transport: http(chainAgnosticRpcUrl, { fetchOptions }),\n },\n ],\n fallback: http(config.nodeRpcUrl, {\n fetchOptions: config.fetchOptions,\n }),\n });\n }\n\n return split({\n overrides: [\n {\n methods: chainAgnosticMethods,\n transport: http(chainAgnosticRpcUrl, { fetchOptions }),\n },\n ],\n fallback: http(rpcUrl, { fetchOptions }),\n });\n })();\n\n return createTransport(\n {\n key: \"alchemy\",\n name: \"Alchemy Transport\",\n request: innerTransport(opts).request,\n retryCount: retryCount ?? opts?.retryCount,\n retryDelay,\n type: \"alchemy\",\n },\n { alchemyRpcUrl: rpcUrl, fetchOptions }\n );\n };\n\n return Object.assign(transport, {\n dynamicFetchOptions: fetchOptions,\n updateHeaders(newHeaders_: HeadersInit) {\n const newHeaders = convertHeadersToObject(newHeaders_);\n\n fetchOptions.headers = {\n ...fetchOptions.headers,\n ...newHeaders,\n };\n },\n config,\n });\n}\n\nexport const convertHeadersToObject = (\n headers?: HeadersInit\n): Record<string, string> => {\n if (!headers) {\n return {};\n }\n\n if (headers instanceof Headers) {\n const headersObject = {} as Record<string, string>;\n headers.forEach((value, key) => {\n headersObject[key] = value;\n });\n return headersObject;\n }\n\n if (Array.isArray(headers)) {\n return headers.reduce((acc, header) => {\n acc[header[0]] = header[1];\n return acc;\n }, {} as Record<string, string>);\n }\n\n return headers;\n};\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.28.3";
1
+ export declare const VERSION = "4.29.0";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.28.3";
3
+ export const VERSION = "4.29.0";
4
4
  //# sourceMappingURL=version.js.map
@@ -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.28.3\";\n"]}
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.29.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"alchemyTransport.d.ts","sourceRoot":"","sources":["../../src/alchemyTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,KAAK,EACV,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,eAAe,EACrB,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,gBAAgB,EAA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,oBAAoB,GAAG,SAAS,CACnC,SAAS,EACT;IACE,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;CACvD,EACD,gBAAgB,CAAC,CAAC,GAAG,eAAe,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAC5D,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG;IACpD,aAAa,CAAC,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAC7C,MAAM,EAAE,sBAAsB,CAAC;IAC/B,mBAAmB,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,GACX,SAAS,IAAI,gBAAgB,CAE/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,sBAAsB,GAAG,gBAAgB,CAoGxE;AAED,eAAO,MAAM,sBAAsB,aACvB,WAAW,KACpB,OAAO,MAAM,EAAE,MAAM,CAqBvB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.28.3";
1
+ export declare const VERSION = "4.29.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@account-kit/infra",
3
- "version": "4.28.3",
3
+ "version": "4.29.0",
4
4
  "description": "adapters for @aa-sdk/core for interacting with alchemy services",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -46,8 +46,8 @@
46
46
  "vitest": "^2.0.4"
47
47
  },
48
48
  "dependencies": {
49
- "@aa-sdk/core": "^4.28.3",
50
- "@account-kit/logging": "^4.28.3",
49
+ "@aa-sdk/core": "^4.29.0",
50
+ "@account-kit/logging": "^4.29.0",
51
51
  "eventemitter3": "^5.0.1",
52
52
  "zod": "^3.22.4"
53
53
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
67
67
  },
68
68
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
69
- "gitHead": "95b777fd0ecce84f751da959372a07837cc71c52",
69
+ "gitHead": "fd5d4c4fb6cab8a930a9b2006df92b6c641304c3",
70
70
  "optionalDependencies": {
71
71
  "alchemy-sdk": "^3.0.0"
72
72
  }
@@ -15,10 +15,10 @@ import {
15
15
  type Transport,
16
16
  type TransportConfig,
17
17
  } from "viem";
18
+ import { mutateRemoveTrackingHeaders } from "./alchemyTrackerHeaders.js";
18
19
  import type { AlchemyRpcSchema } from "./client/types.js";
19
20
  import { AlchemyChainSchema } from "./schema.js";
20
21
  import { VERSION } from "./version.js";
21
- import { mutateRemoveTrackingHeaders } from "./alchemyTrackerHeaders.js";
22
22
 
23
23
  type Never<T> = T extends object
24
24
  ? {
@@ -43,6 +43,16 @@ const alchemyMethods = [
43
43
  "alchemy_requestGasAndPaymasterAndData",
44
44
  ];
45
45
 
46
+ const chainAgnosticMethods = [
47
+ "wallet_prepareCalls",
48
+ "wallet_sendPreparedCalls",
49
+ "wallet_requestAccount",
50
+ "wallet_createAccount",
51
+ "wallet_listAccounts",
52
+ "wallet_createSession",
53
+ "wallet_getCallsStatus",
54
+ ];
55
+
46
56
  export type AlchemyTransportConfig = (
47
57
  | (ConnectionConfig & Never<SplitTransportConfig>)
48
58
  | (SplitTransportConfig & Never<ConnectionConfig>)
@@ -145,10 +155,12 @@ export function alchemy(config: AlchemyTransportConfig): AlchemyTransport {
145
155
  "Alchemy-AA-Sdk-Version": VERSION,
146
156
  };
147
157
 
148
- if (connectionConfig.jwt != null) {
158
+ if (connectionConfig.jwt != null || connectionConfig.apiKey != null) {
149
159
  fetchOptions.headers = {
150
160
  ...fetchOptions.headers,
151
- Authorization: `Bearer ${connectionConfig.jwt}`,
161
+ Authorization: `Bearer ${
162
+ connectionConfig.jwt ?? connectionConfig.apiKey
163
+ }`,
152
164
  };
153
165
  }
154
166
 
@@ -161,7 +173,12 @@ export function alchemy(config: AlchemyTransportConfig): AlchemyTransport {
161
173
 
162
174
  const rpcUrl =
163
175
  connectionConfig.rpcUrl == null
164
- ? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? ""}`
176
+ ? `${chain.rpcUrls.alchemy.http[0]}/`
177
+ : connectionConfig.rpcUrl;
178
+
179
+ const chainAgnosticRpcUrl =
180
+ connectionConfig.rpcUrl == null
181
+ ? "https://api.g.alchemy.com/v2/"
165
182
  : connectionConfig.rpcUrl;
166
183
 
167
184
  const innerTransport = (() => {
@@ -173,6 +190,10 @@ export function alchemy(config: AlchemyTransportConfig): AlchemyTransport {
173
190
  methods: alchemyMethods,
174
191
  transport: http(rpcUrl, { fetchOptions }),
175
192
  },
193
+ {
194
+ methods: chainAgnosticMethods,
195
+ transport: http(chainAgnosticRpcUrl, { fetchOptions }),
196
+ },
176
197
  ],
177
198
  fallback: http(config.nodeRpcUrl, {
178
199
  fetchOptions: config.fetchOptions,
@@ -180,7 +201,15 @@ export function alchemy(config: AlchemyTransportConfig): AlchemyTransport {
180
201
  });
181
202
  }
182
203
 
183
- return http(rpcUrl, { fetchOptions });
204
+ return split({
205
+ overrides: [
206
+ {
207
+ methods: chainAgnosticMethods,
208
+ transport: http(chainAgnosticRpcUrl, { fetchOptions }),
209
+ },
210
+ ],
211
+ fallback: http(rpcUrl, { fetchOptions }),
212
+ });
184
213
  })();
185
214
 
186
215
  return createTransport(
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.28.3";
3
+ export const VERSION = "4.29.0";