@dynamic-labs-sdk/zerodev 0.5.0 → 0.7.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/index.esm.js CHANGED
@@ -1,12 +1,13 @@
1
- import { c as getSignerForSmartWalletAccount, d as ZERODEV_METADATA, f as name, i as shouldUseEIP7702, l as getZerodevChainProviderForNetworkId, n as getPaymasterConfig, p as version, r as createKernelAccount$1, t as getZerodevRpc } from "./getZerodevRpc-B2f3gKD3.esm.js";
1
+ import { c as getSignerForSmartWalletAccount, d as ZERODEV_METADATA, f as name, i as shouldUseEIP7702, l as getZerodevChainProviderForNetworkId, n as getPaymasterConfig, p as version, r as createKernelAccount$1, t as getZerodevRpc } from "./getZerodevRpc-DlpB-rlp.esm.js";
2
2
  import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
3
3
  import { WalletProviderPriority, assertDefined, formatWalletProviderGroupKey, formatWalletProviderKey, getActiveNetworkIdFromLastKnownRegistry, getChainFromVerifiedCredentialChain, getDefaultClient, getNetworkDataForNetworkId, getWalletProviderRegistry, hasExtension, registerExtension, switchActiveNetworkInLastKnownRegistry } from "@dynamic-labs-sdk/client/core";
4
4
  import { InvalidParamError, UnrecognizedNetworkError, getActiveNetworkData, getOwnerWalletAccountForSmartWalletAccount, signMessage } from "@dynamic-labs-sdk/client";
5
5
  import { isEvmWalletAccount } from "@dynamic-labs-sdk/evm";
6
6
  import { WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
7
- import { createKernelAccountClient, getUserOperationGasPrice } from "@zerodev/sdk";
7
+ import { constants, createKernelAccountClient, getUserOperationGasPrice } from "@zerodev/sdk";
8
8
  import { mapNetworkDataToViemChain } from "@dynamic-labs-sdk/evm/viem";
9
9
  import { createPublicClient, http } from "viem";
10
+ import { signAuthorization } from "viem/actions";
10
11
 
11
12
  //#region src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts
12
13
  const getAllUserZerodevAddresses = (client) => {
@@ -26,10 +27,13 @@ const getAllUserZerodevAddresses = (client) => {
26
27
  * @param [params.paymasterRpc] - A custom paymaster RPC to use
27
28
  * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token
28
29
  * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).
30
+ * @param [params.eip7702Auth] - A pre-signed EIP-7702 authorization. When provided, the kernel client uses
31
+ * this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need
32
+ * to separate the authorization signing step from the transaction step.
29
33
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
30
34
  * @returns A promise that resolves to a KernelClient instance.
31
35
  */
32
- const createKernelClientForWalletAccount = async ({ smartWalletAccount, withSponsorship = true, bundlerProvider, networkId, bundlerRpc: bundlerRpcOverride, paymasterRpc: paymasterRpcOverride, gasTokenAddress }, client = getDefaultClient()) => {
36
+ const createKernelClientForWalletAccount = async ({ smartWalletAccount, withSponsorship = true, bundlerProvider, networkId, bundlerRpc: bundlerRpcOverride, paymasterRpc: paymasterRpcOverride, gasTokenAddress, eip7702Auth }, client = getDefaultClient()) => {
33
37
  let networkData;
34
38
  if (networkId) {
35
39
  networkData = getNetworkDataForNetworkId({
@@ -52,6 +56,7 @@ const createKernelClientForWalletAccount = async ({ smartWalletAccount, withSpon
52
56
  transport: bundlerTransport
53
57
  });
54
58
  const account = await createKernelAccount$1({
59
+ eip7702Auth,
55
60
  publicClient,
56
61
  smartWalletAccount
57
62
  }, client);
@@ -244,10 +249,44 @@ const isGasSponsorshipError = (err) => {
244
249
  return err?.message?.includes("userOp did not match any gas sponsoring policies") || false;
245
250
  };
246
251
 
252
+ //#endregion
253
+ //#region src/signEip7702Authorization/signEip7702Authorization.ts
254
+ /**
255
+ * Signs an EIP-7702 authorization for ZeroDev kernel delegation.
256
+ *
257
+ * This function creates a signed authorization that allows a wallet to delegate
258
+ * its execution to the ZeroDev kernel contract. The signed authorization can then
259
+ * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.
260
+ *
261
+ * @param params - The parameters for signing the authorization.
262
+ * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.
263
+ * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.
264
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
265
+ * @returns A promise that resolves to the signed EIP-7702 authorization.
266
+ */
267
+ const signEip7702Authorization = async ({ smartWalletAccount, networkId }, client = getDefaultClient()) => {
268
+ const walletClient = await getSignerForSmartWalletAccount({ smartWalletAccount }, client);
269
+ let networkData;
270
+ if (networkId) {
271
+ networkData = getNetworkDataForNetworkId({
272
+ chain: "EVM",
273
+ networkId
274
+ }, client);
275
+ assertDefined(networkData, `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`);
276
+ } else {
277
+ networkData = (await getActiveNetworkData({ walletAccount: smartWalletAccount }, client)).networkData;
278
+ assertDefined(networkData, "No active network data found for this wallet account.");
279
+ }
280
+ return signAuthorization(walletClient, {
281
+ chainId: mapNetworkDataToViemChain(networkData).id,
282
+ contractAddress: constants.KERNEL_7702_DELEGATION_ADDRESS
283
+ });
284
+ };
285
+
247
286
  //#endregion
248
287
  //#region src/exports/index.ts
249
288
  assertPackageVersion(name, version);
250
289
 
251
290
  //#endregion
252
- export { addZerodevExtension, canSponsorTransaction, createKernelClientForWalletAccount, estimateTransactionGas, getSignerForSmartWalletAccount, isGasSponsorshipError };
291
+ export { addZerodevExtension, canSponsorTransaction, createKernelClientForWalletAccount, estimateTransactionGas, getSignerForSmartWalletAccount, isGasSponsorshipError, signEip7702Authorization };
253
292
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","names":["networkData: NetworkData | undefined","createKernelAccount","signMessage","signMessageWithWalletAccount","chain: Chain","signMessage","signMessageUtils"],"sources":["../src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts","../src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts","../src/utils/shouldSignWithEoa/shouldSignWithEoa.ts","../src/utils/signMessage/signMessage.ts","../src/utils/createZerodevWalletProvider/createZerodevWalletProvider.ts","../src/addZerodevExtension/addZerodevExtension.ts","../src/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.ts","../src/canSponsorTransaction/canSponsorTransaction.ts","../src/utils/calculateGasForUserOperation/calculateGasForUserOperation.ts","../src/estimateTransactionGas/estimateTransactionGas.ts","../src/isGasSponsorshipError/isGasSponsorshipError.ts","../src/exports/index.ts"],"sourcesContent":["import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getChainFromVerifiedCredentialChain } from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\n\nexport const getAllUserZerodevAddresses = (client: DynamicClient): string[] => {\n const zerodevWalletCredentials =\n client.user?.verifiedCredentials.filter(\n (credential) =>\n credential.walletProvider === WalletProviderEnum.SmartContractWallet &&\n credential.walletName\n ?.toLowerCase()\n .startsWith(ZERODEV_METADATA.normalizedWalletName) &&\n credential.address &&\n credential.chain &&\n getChainFromVerifiedCredentialChain(credential.chain) === 'EVM'\n ) ?? [];\n\n const zerodevAddresses: string[] = zerodevWalletCredentials.map(\n // casting because we're already filtering out credentials without an address\n (credential) => credential.address as string\n );\n\n return zerodevAddresses;\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport type { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';\nimport {\n createKernelAccountClient,\n getUserOperationGasPrice,\n} from '@zerodev/sdk';\nimport type { Hex } from 'viem';\nimport { createPublicClient, http } from 'viem';\n\nimport type { KernelClient } from '../KernelClient.types';\nimport { createKernelAccount } from '../utils/createKernelAccount';\nimport { getPaymasterConfig } from '../utils/getPaymasterConfig';\nimport { getZerodevRpc } from '../utils/getZerodevRpc';\n\ntype CreateKernelClientForWalletAccountParams = {\n bundlerProvider?: ZerodevBundlerProvider;\n bundlerRpc?: string;\n gasTokenAddress?: Hex;\n networkId?: string;\n paymasterRpc?: string;\n smartWalletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\n/**\n * Creates a KernelClient instance for a given smart wallet account.\n *\n * @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.\n * @param [params.bundlerProvider] - A custom bundler provider to use\n * @param [params.bundlerRpc] - A custom bundler RPC to use\n * @param [params.networkId] - The network ID to use for the KernelClient.\n * If not provided, the network ID will be fetched from the active network data.\n * @param [params.paymasterRpc] - A custom paymaster RPC to use\n * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token\n * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a KernelClient instance.\n */\nexport const createKernelClientForWalletAccount = async (\n {\n smartWalletAccount,\n withSponsorship = true,\n bundlerProvider,\n networkId,\n bundlerRpc: bundlerRpcOverride,\n paymasterRpc: paymasterRpcOverride,\n gasTokenAddress,\n }: CreateKernelClientForWalletAccountParams,\n client = getDefaultClient()\n): Promise<KernelClient> => {\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n `No active network data found for this wallet account.`\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n const bundlerRpc =\n bundlerRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'bundler',\n },\n client\n );\n\n const bundlerTransport = http(bundlerRpc);\n\n const publicClient = createPublicClient({\n chain: viemChain,\n transport: bundlerTransport,\n });\n\n const account = await createKernelAccount(\n {\n publicClient,\n smartWalletAccount,\n },\n client\n );\n\n const paymasterRpc =\n paymasterRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'paymaster',\n },\n client\n );\n\n const paymasterConfig = withSponsorship\n ? getPaymasterConfig({\n chain: viemChain,\n gasTokenAddress,\n paymasterRpc,\n })\n : {};\n\n return createKernelAccountClient({\n account,\n bundlerTransport,\n chain: viemChain,\n client: publicClient,\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) =>\n getUserOperationGasPrice(bundlerClient),\n },\n ...paymasterConfig,\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { KernelClient } from '../../KernelClient.types';\nimport { shouldUseEIP7702 } from '../shouldUseEIP7702';\n\ntype ShouldSignWithEoaParams = {\n kernelClient: KernelClient;\n smartWalletAccount: EvmWalletAccount;\n};\n\nexport const shouldSignWithEoa = async (\n { kernelClient, smartWalletAccount }: ShouldSignWithEoaParams,\n client: DynamicClient\n) => {\n const useEIP7702 = shouldUseEIP7702({ smartWalletAccount }, client);\n\n if (!useEIP7702) {\n return false;\n }\n\n const isDeployed = await kernelClient.account.isDeployed();\n\n return !isDeployed;\n};\n","import {\n type DynamicClient,\n getOwnerWalletAccountForSmartWalletAccount,\n signMessage as signMessageWithWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport { createKernelClientForWalletAccount } from '../../createKernelClientForWalletAccount';\nimport { shouldSignWithEoa } from '../shouldSignWithEoa';\n\ntype SignMessageParams = {\n message: string;\n walletAccount: EvmWalletAccount;\n};\n\nexport const signMessage = async (\n { walletAccount, message }: SignMessageParams,\n client: DynamicClient\n): Promise<{ signature: string }> => {\n const kernelClient = await createKernelClientForWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n const shouldUseEoa = await shouldSignWithEoa(\n {\n kernelClient,\n smartWalletAccount: walletAccount,\n },\n client\n );\n\n if (shouldUseEoa) {\n const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n assertDefined(eoaWalletAccount, 'Eoa wallet account not found');\n\n const { signature } = await signMessageWithWalletAccount({\n message,\n walletAccount: eoaWalletAccount,\n });\n\n return { signature };\n }\n\n const signature = await kernelClient.signMessage({ message });\n return { signature };\n};\n","import {\n type Chain,\n type DynamicClient,\n InvalidParamError,\n UnrecognizedNetworkError,\n type WalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n formatWalletProviderGroupKey,\n formatWalletProviderKey,\n getActiveNetworkIdFromLastKnownRegistry,\n switchActiveNetworkInLastKnownRegistry,\n} from '@dynamic-labs-sdk/client/core';\nimport {\n type EvmWalletProvider,\n isEvmWalletAccount,\n} from '@dynamic-labs-sdk/evm';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\nimport { getAllUserZerodevAddresses } from '../getAllUserZerodevAddresses';\nimport { getZerodevChainProviderForNetworkId } from '../getZerodevChainProviderForNetworkId';\nimport { signMessage as signMessageUtils } from '../signMessage';\n\nexport const createZerodevWalletProvider = (\n client: DynamicClient\n): EvmWalletProvider => {\n const chain: Chain = 'EVM';\n const walletProviderType = WalletProviderEnum.SmartContractWallet;\n const key = formatWalletProviderKey({\n chain,\n displayName: ZERODEV_METADATA.displayName,\n walletProviderType,\n });\n\n const getActiveNetworkId = async () =>\n getActiveNetworkIdFromLastKnownRegistry({\n client,\n walletProviderKey: key,\n });\n\n const getConnectedAddresses = async () => {\n const zerodevAddresses = getAllUserZerodevAddresses(client);\n\n return {\n addresses: zerodevAddresses,\n };\n };\n\n const signMessage = async ({\n walletAccount,\n message,\n }: {\n message: string;\n walletAccount?: WalletAccount;\n }) => {\n assertDefined(walletAccount, 'Wallet account is required');\n\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError(`walletAccount is not an EVM wallet account`);\n }\n\n return signMessageUtils({ message, walletAccount }, client);\n };\n\n const switchActiveNetwork = async ({ networkId }: { networkId: string }) => {\n const isNetworkEnabled = getZerodevChainProviderForNetworkId(\n { networkId },\n client\n );\n\n if (!isNetworkEnabled) {\n throw new UnrecognizedNetworkError({\n networkId,\n originalError: null,\n walletProviderKey: key,\n });\n }\n\n return switchActiveNetworkInLastKnownRegistry({\n client,\n networkId,\n walletProviderKey: key,\n });\n };\n\n return {\n chain,\n getActiveNetworkId,\n getConnectedAddresses,\n groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),\n key,\n metadata: {\n displayName: ZERODEV_METADATA.displayName,\n icon: ZERODEV_METADATA.icon,\n },\n signMessage,\n switchActiveNetwork,\n walletProviderType,\n };\n};\n","import {\n WalletProviderPriority,\n getDefaultClient,\n getWalletProviderRegistry,\n hasExtension,\n registerExtension,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { createZerodevWalletProvider } from '../utils/createZerodevWalletProvider';\n\nexport const ZERODEV_EXTENSION_KEY = 'zerodev';\n\n/**\n * Adds the ZeroDev extension to the Dynamic client.\n *\n * This extension enables Account Abstraction integration with ZeroDev\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addZerodevExtension = (client = getDefaultClient()) => {\n if (hasExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client)) {\n return;\n }\n\n registerExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client);\n\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = createZerodevWalletProvider(client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n};\n","import type { Hex } from 'viem';\n\nimport type { KernelClient } from '../../KernelClient.types';\n\ntype PrepareUserOperationWithKernelClientParams = {\n kernelClient: KernelClient;\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\nexport const prepareUserOperationWithKernelClient = async ({\n kernelClient,\n transaction,\n}: PrepareUserOperationWithKernelClientParams) => {\n const callData = await kernelClient.account.encodeCalls([\n {\n data: transaction.data ?? '0x',\n to: transaction.to,\n value: transaction.value,\n },\n ]);\n\n return kernelClient.prepareUserOperation({\n callData,\n });\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\ntype CanSponsorTransactionBaseParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\ntype CanSponsorTransactionWithWalletParams = CanSponsorTransactionBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n};\n\ntype CanSponsorTransactionWithClientParams = CanSponsorTransactionBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n};\n\nexport type CanSponsorTransactionParams =\n | CanSponsorTransactionWithWalletParams\n | CanSponsorTransactionWithClientParams;\n\n/**\n * Checks if a transaction can be sponsored\n * @param params.transaction - The transaction to check if it can be sponsored\n * @param params.kernelClient - The kernel client to use to check if the transaction can be sponsored. If no provided, a walletAccount is required to create a kernel client with sponsorship.\n * @param params.walletAccount - The wallet account that will be used to send the transaction, Only required if no kernel client is provided\n * @returns True if the transaction can be sponsored, false otherwise\n */\nexport const canSponsorTransaction = async ({\n walletAccount,\n transaction,\n kernelClient,\n}: CanSponsorTransactionParams): Promise<boolean> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n });\n }\n\n try {\n const sponsorResult = await prepareUserOperationWithKernelClient({\n kernelClient: kernelClientToUse,\n transaction,\n });\n\n const hasPaymaster = sponsorResult.paymasterAndData !== '0x';\n\n return hasPaymaster;\n } catch {\n return false;\n }\n};\n","import type { UserOperation } from 'viem/account-abstraction';\n\ntype CalculateGasForUserOperationParams = {\n userOperationData: Pick<\n UserOperation,\n | 'callGasLimit'\n | 'verificationGasLimit'\n | 'preVerificationGas'\n | 'maxFeePerGas'\n >;\n};\n\nexport const calculateGasForUserOperation = ({\n userOperationData,\n}: CalculateGasForUserOperationParams): bigint => {\n // Sum all gas units\n const totalGasUnits =\n userOperationData.callGasLimit +\n userOperationData.verificationGasLimit +\n userOperationData.preVerificationGas;\n\n // Multiply by maxFeePerGas to get the total gas cost in wei\n const gasCost = totalGasUnits * userOperationData.maxFeePerGas;\n\n return gasCost;\n};\n","import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport { calculateGasForUserOperation } from '../utils/calculateGasForUserOperation';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\nexport type EstimateTransactionGasParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Estimates the total gas for a transaction\n * @param params.transaction - The transaction to estimate the gas for\n * @param params.walletAccount - The wallet account that will be used to send the transaction\n * @returns The gas for the transaction in wei\n */\nexport const estimateTransactionGas = async ({\n walletAccount,\n transaction,\n}: EstimateTransactionGasParams): Promise<bigint | null> => {\n try {\n const kernelClientWithoutSponsorship =\n await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship: false,\n });\n\n const unsponsoredUserOperation = await prepareUserOperationWithKernelClient(\n {\n kernelClient: kernelClientWithoutSponsorship,\n transaction,\n }\n );\n\n return calculateGasForUserOperation({\n userOperationData: unsponsoredUserOperation,\n });\n } catch {\n return null;\n }\n};\n","export const isGasSponsorshipError = (err: unknown): boolean => {\n const errorWithMessage = err as { message?: string } | undefined;\n\n return (\n errorWithMessage?.message?.includes(\n 'userOp did not match any gas sponsoring policies'\n ) || false\n );\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { addZerodevExtension } from '../addZerodevExtension';\nexport { canSponsorTransaction } from '../canSponsorTransaction';\nexport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nexport { estimateTransactionGas } from '../estimateTransactionGas';\nexport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\nexport { isGasSponsorshipError } from '../isGasSponsorshipError';\nexport type { KernelClient } from '../KernelClient.types';\n"],"mappings":";;;;;;;;;;;AAMA,MAAa,8BAA8B,WAAoC;AAkB7E,SAhBE,OAAO,MAAM,oBAAoB,QAC9B,eACC,WAAW,mBAAmB,mBAAmB,uBACjD,WAAW,YACP,aAAa,CACd,WAAW,iBAAiB,qBAAqB,IACpD,WAAW,WACX,WAAW,SACX,oCAAoC,WAAW,MAAM,KAAK,MAC7D,IAAI,EAAE,EAEmD,KAEzD,eAAe,WAAW,QAC5B;;;;;;;;;;;;;;;;;;;ACwBH,MAAa,qCAAqC,OAChD,EACE,oBACA,kBAAkB,MAClB,iBACA,WACA,YAAY,oBACZ,cAAc,sBACd,mBAEF,SAAS,kBAAkB,KACD;CAC1B,IAAIA;AAEJ,KAAI,WAAW;AACb,gBAAc,2BACZ;GAAE,OAAO;GAAO;GAAW,EAC3B,OACD;AAED,gBACE,aACA,mDAAmD,UAAU,sDAC9D;QACI;AAML,iBAL0B,MAAM,qBAC9B,EA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,QAAQ;EAC1B,IAAI,YAAY;EAChB,OAAO,YAAY;EACpB,CACF,CAAC;AAEF,QAAO,aAAa,qBAAqB,EACvC,UACD,CAAC;;;;;;;;;;;;ACUJ,MAAa,wBAAwB,OAAO,EAC1C,eACA,aACA,mBACmD;CACnD,IAAI,oBAAoB;AAExB,KAAI,CAAC,mBAAmB;AACtB,gBACE,eACA,8EACD;AAED,sBAAoB,MAAM,mCAAmC,EAC3D,oBAAoB,eACrB,CAAC;;AAGJ,KAAI;AAQF,UAPsB,MAAM,qCAAqC;GAC/D,cAAc;GACd;GACD,CAAC,EAEiC,qBAAqB;SAGlD;AACN,SAAO;;;;;;ACrDX,MAAa,gCAAgC,EAC3C,wBACgD;AAUhD,SAPE,kBAAkB,eAClB,kBAAkB,uBAClB,kBAAkB,sBAGY,kBAAkB;;;;;;;;;;;ACApD,MAAa,yBAAyB,OAAO,EAC3C,eACA,kBAC0D;AAC1D,KAAI;AAcF,SAAO,6BAA6B,EAClC,mBAR+B,MAAM,qCACrC;GACE,cAPF,MAAM,mCAAmC;IACvC,oBAAoB;IACpB,iBAAiB;IAClB,CAAC;GAKA;GACD,CACF,EAIA,CAAC;SACI;AACN,SAAO;;;;;;AC5CX,MAAa,yBAAyB,QAA0B;AAG9D,QAFyB,KAGL,SAAS,SACzB,mDACD,IAAI;;;;;ACFT,qBAAqB,MAAM,QAAQ"}
1
+ {"version":3,"file":"index.esm.js","names":["networkData: NetworkData | undefined","createKernelAccount","signMessage","signMessageWithWalletAccount","chain: Chain","signMessage","signMessageUtils","networkData: NetworkData | undefined"],"sources":["../src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts","../src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts","../src/utils/shouldSignWithEoa/shouldSignWithEoa.ts","../src/utils/signMessage/signMessage.ts","../src/utils/createZerodevWalletProvider/createZerodevWalletProvider.ts","../src/addZerodevExtension/addZerodevExtension.ts","../src/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.ts","../src/canSponsorTransaction/canSponsorTransaction.ts","../src/utils/calculateGasForUserOperation/calculateGasForUserOperation.ts","../src/estimateTransactionGas/estimateTransactionGas.ts","../src/isGasSponsorshipError/isGasSponsorshipError.ts","../src/signEip7702Authorization/signEip7702Authorization.ts","../src/exports/index.ts"],"sourcesContent":["import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getChainFromVerifiedCredentialChain } from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\n\nexport const getAllUserZerodevAddresses = (client: DynamicClient): string[] => {\n const zerodevWalletCredentials =\n client.user?.verifiedCredentials.filter(\n (credential) =>\n credential.walletProvider === WalletProviderEnum.SmartContractWallet &&\n credential.walletName\n ?.toLowerCase()\n .startsWith(ZERODEV_METADATA.normalizedWalletName) &&\n credential.address &&\n credential.chain &&\n getChainFromVerifiedCredentialChain(credential.chain) === 'EVM'\n ) ?? [];\n\n const zerodevAddresses: string[] = zerodevWalletCredentials.map(\n // casting because we're already filtering out credentials without an address\n (credential) => credential.address as string\n );\n\n return zerodevAddresses;\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport type { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';\nimport {\n createKernelAccountClient,\n getUserOperationGasPrice,\n} from '@zerodev/sdk';\nimport type { Hex } from 'viem';\nimport { createPublicClient, http } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { KernelClient } from '../KernelClient.types';\nimport { createKernelAccount } from '../utils/createKernelAccount';\nimport { getPaymasterConfig } from '../utils/getPaymasterConfig';\nimport { getZerodevRpc } from '../utils/getZerodevRpc';\n\nexport type Eip7702Authorization = SignAuthorizationReturnType;\n\ntype CreateKernelClientForWalletAccountParams = {\n bundlerProvider?: ZerodevBundlerProvider;\n bundlerRpc?: string;\n eip7702Auth?: SignAuthorizationReturnType;\n gasTokenAddress?: Hex;\n networkId?: string;\n paymasterRpc?: string;\n smartWalletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\n/**\n * Creates a KernelClient instance for a given smart wallet account.\n *\n * @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.\n * @param [params.bundlerProvider] - A custom bundler provider to use\n * @param [params.bundlerRpc] - A custom bundler RPC to use\n * @param [params.networkId] - The network ID to use for the KernelClient.\n * If not provided, the network ID will be fetched from the active network data.\n * @param [params.paymasterRpc] - A custom paymaster RPC to use\n * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token\n * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).\n * @param [params.eip7702Auth] - A pre-signed EIP-7702 authorization. When provided, the kernel client uses \n * this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need\n * to separate the authorization signing step from the transaction step.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a KernelClient instance.\n */\nexport const createKernelClientForWalletAccount = async (\n {\n smartWalletAccount,\n withSponsorship = true,\n bundlerProvider,\n networkId,\n bundlerRpc: bundlerRpcOverride,\n paymasterRpc: paymasterRpcOverride,\n gasTokenAddress,\n eip7702Auth,\n }: CreateKernelClientForWalletAccountParams,\n client = getDefaultClient()\n): Promise<KernelClient> => {\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n `No active network data found for this wallet account.`\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n const bundlerRpc =\n bundlerRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'bundler',\n },\n client\n );\n\n const bundlerTransport = http(bundlerRpc);\n\n const publicClient = createPublicClient({\n chain: viemChain,\n transport: bundlerTransport,\n });\n\n const account = await createKernelAccount(\n {\n eip7702Auth,\n publicClient,\n smartWalletAccount,\n },\n client\n );\n\n const paymasterRpc =\n paymasterRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'paymaster',\n },\n client\n );\n\n const paymasterConfig = withSponsorship\n ? getPaymasterConfig({\n chain: viemChain,\n gasTokenAddress,\n paymasterRpc,\n })\n : {};\n\n return createKernelAccountClient({\n account,\n bundlerTransport,\n chain: viemChain,\n client: publicClient,\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) =>\n getUserOperationGasPrice(bundlerClient),\n },\n ...paymasterConfig,\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { KernelClient } from '../../KernelClient.types';\nimport { shouldUseEIP7702 } from '../shouldUseEIP7702';\n\ntype ShouldSignWithEoaParams = {\n kernelClient: KernelClient;\n smartWalletAccount: EvmWalletAccount;\n};\n\nexport const shouldSignWithEoa = async (\n { kernelClient, smartWalletAccount }: ShouldSignWithEoaParams,\n client: DynamicClient\n) => {\n const useEIP7702 = shouldUseEIP7702({ smartWalletAccount }, client);\n\n if (!useEIP7702) {\n return false;\n }\n\n const isDeployed = await kernelClient.account.isDeployed();\n\n return !isDeployed;\n};\n","import {\n type DynamicClient,\n getOwnerWalletAccountForSmartWalletAccount,\n signMessage as signMessageWithWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport { createKernelClientForWalletAccount } from '../../createKernelClientForWalletAccount';\nimport { shouldSignWithEoa } from '../shouldSignWithEoa';\n\ntype SignMessageParams = {\n message: string;\n walletAccount: EvmWalletAccount;\n};\n\nexport const signMessage = async (\n { walletAccount, message }: SignMessageParams,\n client: DynamicClient\n): Promise<{ signature: string }> => {\n const kernelClient = await createKernelClientForWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n const shouldUseEoa = await shouldSignWithEoa(\n {\n kernelClient,\n smartWalletAccount: walletAccount,\n },\n client\n );\n\n if (shouldUseEoa) {\n const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n assertDefined(eoaWalletAccount, 'Eoa wallet account not found');\n\n const { signature } = await signMessageWithWalletAccount({\n message,\n walletAccount: eoaWalletAccount,\n });\n\n return { signature };\n }\n\n const signature = await kernelClient.signMessage({ message });\n return { signature };\n};\n","import {\n type Chain,\n type DynamicClient,\n InvalidParamError,\n UnrecognizedNetworkError,\n type WalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n formatWalletProviderGroupKey,\n formatWalletProviderKey,\n getActiveNetworkIdFromLastKnownRegistry,\n switchActiveNetworkInLastKnownRegistry,\n} from '@dynamic-labs-sdk/client/core';\nimport {\n type EvmWalletProvider,\n isEvmWalletAccount,\n} from '@dynamic-labs-sdk/evm';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\nimport { getAllUserZerodevAddresses } from '../getAllUserZerodevAddresses';\nimport { getZerodevChainProviderForNetworkId } from '../getZerodevChainProviderForNetworkId';\nimport { signMessage as signMessageUtils } from '../signMessage';\n\nexport const createZerodevWalletProvider = (\n client: DynamicClient\n): EvmWalletProvider => {\n const chain: Chain = 'EVM';\n const walletProviderType = WalletProviderEnum.SmartContractWallet;\n const key = formatWalletProviderKey({\n chain,\n displayName: ZERODEV_METADATA.displayName,\n walletProviderType,\n });\n\n const getActiveNetworkId = async () =>\n getActiveNetworkIdFromLastKnownRegistry({\n client,\n walletProviderKey: key,\n });\n\n const getConnectedAddresses = async () => {\n const zerodevAddresses = getAllUserZerodevAddresses(client);\n\n return {\n addresses: zerodevAddresses,\n };\n };\n\n const signMessage = async ({\n walletAccount,\n message,\n }: {\n message: string;\n walletAccount?: WalletAccount;\n }) => {\n assertDefined(walletAccount, 'Wallet account is required');\n\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError(`walletAccount is not an EVM wallet account`);\n }\n\n return signMessageUtils({ message, walletAccount }, client);\n };\n\n const switchActiveNetwork = async ({ networkId }: { networkId: string }) => {\n const isNetworkEnabled = getZerodevChainProviderForNetworkId(\n { networkId },\n client\n );\n\n if (!isNetworkEnabled) {\n throw new UnrecognizedNetworkError({\n networkId,\n originalError: null,\n walletProviderKey: key,\n });\n }\n\n return switchActiveNetworkInLastKnownRegistry({\n client,\n networkId,\n walletProviderKey: key,\n });\n };\n\n return {\n chain,\n getActiveNetworkId,\n getConnectedAddresses,\n groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),\n key,\n metadata: {\n displayName: ZERODEV_METADATA.displayName,\n icon: ZERODEV_METADATA.icon,\n },\n signMessage,\n switchActiveNetwork,\n walletProviderType,\n };\n};\n","import {\n WalletProviderPriority,\n getDefaultClient,\n getWalletProviderRegistry,\n hasExtension,\n registerExtension,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { createZerodevWalletProvider } from '../utils/createZerodevWalletProvider';\n\nexport const ZERODEV_EXTENSION_KEY = 'zerodev';\n\n/**\n * Adds the ZeroDev extension to the Dynamic client.\n *\n * This extension enables Account Abstraction integration with ZeroDev\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addZerodevExtension = (client = getDefaultClient()) => {\n if (hasExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client)) {\n return;\n }\n\n registerExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client);\n\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = createZerodevWalletProvider(client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n};\n","import type { Hex } from 'viem';\n\nimport type { KernelClient } from '../../KernelClient.types';\n\ntype PrepareUserOperationWithKernelClientParams = {\n kernelClient: KernelClient;\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\nexport const prepareUserOperationWithKernelClient = async ({\n kernelClient,\n transaction,\n}: PrepareUserOperationWithKernelClientParams) => {\n const callData = await kernelClient.account.encodeCalls([\n {\n data: transaction.data ?? '0x',\n to: transaction.to,\n value: transaction.value,\n },\n ]);\n\n return kernelClient.prepareUserOperation({\n callData,\n });\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\ntype CanSponsorTransactionBaseParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\ntype CanSponsorTransactionWithWalletParams = CanSponsorTransactionBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n};\n\ntype CanSponsorTransactionWithClientParams = CanSponsorTransactionBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n};\n\nexport type CanSponsorTransactionParams =\n | CanSponsorTransactionWithWalletParams\n | CanSponsorTransactionWithClientParams;\n\n/**\n * Checks if a transaction can be sponsored\n * @param params.transaction - The transaction to check if it can be sponsored\n * @param params.kernelClient - The kernel client to use to check if the transaction can be sponsored. If no provided, a walletAccount is required to create a kernel client with sponsorship.\n * @param params.walletAccount - The wallet account that will be used to send the transaction, Only required if no kernel client is provided\n * @returns True if the transaction can be sponsored, false otherwise\n */\nexport const canSponsorTransaction = async ({\n walletAccount,\n transaction,\n kernelClient,\n}: CanSponsorTransactionParams): Promise<boolean> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n });\n }\n\n try {\n const sponsorResult = await prepareUserOperationWithKernelClient({\n kernelClient: kernelClientToUse,\n transaction,\n });\n\n const hasPaymaster = sponsorResult.paymasterAndData !== '0x';\n\n return hasPaymaster;\n } catch {\n return false;\n }\n};\n","import type { UserOperation } from 'viem/account-abstraction';\n\ntype CalculateGasForUserOperationParams = {\n userOperationData: Pick<\n UserOperation,\n | 'callGasLimit'\n | 'verificationGasLimit'\n | 'preVerificationGas'\n | 'maxFeePerGas'\n >;\n};\n\nexport const calculateGasForUserOperation = ({\n userOperationData,\n}: CalculateGasForUserOperationParams): bigint => {\n // Sum all gas units\n const totalGasUnits =\n userOperationData.callGasLimit +\n userOperationData.verificationGasLimit +\n userOperationData.preVerificationGas;\n\n // Multiply by maxFeePerGas to get the total gas cost in wei\n const gasCost = totalGasUnits * userOperationData.maxFeePerGas;\n\n return gasCost;\n};\n","import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport { calculateGasForUserOperation } from '../utils/calculateGasForUserOperation';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\nexport type EstimateTransactionGasParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Estimates the total gas for a transaction\n * @param params.transaction - The transaction to estimate the gas for\n * @param params.walletAccount - The wallet account that will be used to send the transaction\n * @returns The gas for the transaction in wei\n */\nexport const estimateTransactionGas = async ({\n walletAccount,\n transaction,\n}: EstimateTransactionGasParams): Promise<bigint | null> => {\n try {\n const kernelClientWithoutSponsorship =\n await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship: false,\n });\n\n const unsponsoredUserOperation = await prepareUserOperationWithKernelClient(\n {\n kernelClient: kernelClientWithoutSponsorship,\n transaction,\n }\n );\n\n return calculateGasForUserOperation({\n userOperationData: unsponsoredUserOperation,\n });\n } catch {\n return null;\n }\n};\n","export const isGasSponsorshipError = (err: unknown): boolean => {\n const errorWithMessage = err as { message?: string } | undefined;\n\n return (\n errorWithMessage?.message?.includes(\n 'userOp did not match any gas sponsoring policies'\n ) || false\n );\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport { constants } from '@zerodev/sdk';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\nimport { signAuthorization } from 'viem/actions';\n\nimport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\n\nexport type SignEip7702AuthorizationParams = {\n networkId?: string;\n smartWalletAccount: EvmWalletAccount;\n};\n\n/**\n * Signs an EIP-7702 authorization for ZeroDev kernel delegation.\n *\n * This function creates a signed authorization that allows a wallet to delegate\n * its execution to the ZeroDev kernel contract. The signed authorization can then\n * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.\n *\n * @param params - The parameters for signing the authorization.\n * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.\n * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the signed EIP-7702 authorization.\n */\nexport const signEip7702Authorization = async (\n { smartWalletAccount, networkId }: SignEip7702AuthorizationParams,\n client = getDefaultClient()\n): Promise<SignAuthorizationReturnType> => {\n const walletClient = await getSignerForSmartWalletAccount(\n { smartWalletAccount },\n client\n );\n\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n 'No active network data found for this wallet account.'\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n return signAuthorization(walletClient, {\n chainId: viemChain.id,\n contractAddress: constants.KERNEL_7702_DELEGATION_ADDRESS,\n });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { addZerodevExtension } from '../addZerodevExtension';\nexport { canSponsorTransaction } from '../canSponsorTransaction';\nexport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nexport type { Eip7702Authorization } from '../createKernelClientForWalletAccount';\nexport { estimateTransactionGas } from '../estimateTransactionGas';\nexport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\nexport { isGasSponsorshipError } from '../isGasSponsorshipError';\nexport type { KernelClient } from '../KernelClient.types';\nexport { signEip7702Authorization } from '../signEip7702Authorization';\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,8BAA8B,WAAoC;AAkB7E,SAhBE,OAAO,MAAM,oBAAoB,QAC9B,eACC,WAAW,mBAAmB,mBAAmB,uBACjD,WAAW,YACP,aAAa,CACd,WAAW,iBAAiB,qBAAqB,IACpD,WAAW,WACX,WAAW,SACX,oCAAoC,WAAW,MAAM,KAAK,MAC7D,IAAI,EAAE,EAEmD,KAEzD,eAAe,WAAW,QAC5B;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,eAAe,MAAM,+BACzB,EAAE,oBAAoB,EACtB,OACD;CAED,IAAIC;AAEJ,KAAI,WAAW;AACb,gBAAc,2BACZ;GAAE,OAAO;GAAO;GAAW,EAC3B,OACD;AAED,gBACE,aACA,mDAAmD,UAAU,sDAC9D;QACI;AAML,iBAL0B,MAAM,qBAC9B,EAAE,eAAe,oBAAoB,EACrC,OACD,EAE+B;AAEhC,gBACE,aACA,wDACD;;AAKH,QAAO,kBAAkB,cAAc;EACrC,SAHgB,0BAA0B,YAAY,CAGnC;EACnB,iBAAiB,UAAU;EAC5B,CAAC;;;;;ACrEJ,qBAAqB,MAAM,QAAQ"}
@@ -0,0 +1,2 @@
1
+ export { signEip7702Authorization } from './signEip7702Authorization';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signEip7702Authorization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';
2
+ import type { SignAuthorizationReturnType } from 'viem/accounts';
3
+ export type SignEip7702AuthorizationParams = {
4
+ networkId?: string;
5
+ smartWalletAccount: EvmWalletAccount;
6
+ };
7
+ /**
8
+ * Signs an EIP-7702 authorization for ZeroDev kernel delegation.
9
+ *
10
+ * This function creates a signed authorization that allows a wallet to delegate
11
+ * its execution to the ZeroDev kernel contract. The signed authorization can then
12
+ * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.
13
+ *
14
+ * @param params - The parameters for signing the authorization.
15
+ * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.
16
+ * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.
17
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
18
+ * @returns A promise that resolves to the signed EIP-7702 authorization.
19
+ */
20
+ export declare const signEip7702Authorization: ({ smartWalletAccount, networkId }: SignEip7702AuthorizationParams, client?: import("@dynamic-labs-sdk/client").DynamicClient) => Promise<SignAuthorizationReturnType>;
21
+ //# sourceMappingURL=signEip7702Authorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signEip7702Authorization.d.ts","sourceRoot":"","sources":["../../src/signEip7702Authorization/signEip7702Authorization.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAKjE,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,gBAAgB,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,sCACA,8BAA8B,gEAEhE,OAAO,CAAC,2BAA2B,CAsCrC,CAAC"}