{"version":3,"file":"createWalletClientForWalletAccount-C2ZSMduy.cjs","names":["InvalidParamError"],"sources":["../package.json","../src/viem/utils/mapNetworkDataToViemChain/mapNetworkDataToViemChain.ts","../src/viem/createPublicClientFromNetworkData/createPublicClientFromNetworkData.ts","../src/isEvmWalletProvider/isEvmWalletProvider.ts","../src/utils/isEIP1193Provider/isEIP1193Provider.ts","../src/viem/utils/walletProviderHasCustomWalletClient/isEvmWalletProviderWithCustomViemClient.ts","../src/viem/createWalletClientForWalletAccount/createWalletClientForWalletAccount.ts"],"sourcesContent":["","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport type { Chain } from 'viem';\n\n/**\n * Created a viem Chain object from a NetworkData object.\n  * @not-instrumented\n */\nexport const mapNetworkDataToViemChain = (networkData: NetworkData): Chain => ({\n  blockExplorers: networkData.blockExplorerUrls?.[0]\n    ? {\n        default: {\n          name: networkData.blockExplorerUrls[0],\n          url: networkData.blockExplorerUrls[0],\n        },\n      }\n    : undefined,\n  id: Number(networkData.networkId),\n  name: networkData.displayName,\n  nativeCurrency: networkData.nativeCurrency,\n  rpcUrls: {\n    default: { http: networkData.rpcUrls.http },\n  },\n});\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport type {\n  Chain,\n  HttpTransport,\n  HttpTransportConfig,\n  PublicClient,\n  PublicClientConfig,\n} from 'viem';\nimport { createPublicClient, http } from 'viem';\n\nimport { mapNetworkDataToViemChain } from '../utils/mapNetworkDataToViemChain';\n\ntype CreatePublicClientFromNetworkDataProps = {\n  httpTransportConfig?: HttpTransportConfig;\n  networkData: NetworkData;\n  publicClientConfig?: Partial<PublicClientConfig<HttpTransport, Chain>>;\n};\n\n/**\n * Creates a viem PublicClient from a given NetworkData object.\n *\n * This function configures a viem PublicClient instance for reading data from\n * an EVM-compatible blockchain using the network provider's RPC endpoint.\n *\n * @param props - The configuration object.\n * @param props.networkData - The NetworkData object containing network configuration.\n * @param props.publicClientConfig - Optional additional configuration for the viem PublicClient.\n * @param props.httpTransportConfig - Optional HTTP transport configuration.\n * @returns A configured viem PublicClient instance.\n  * @not-instrumented\n */\nexport const createPublicClientFromNetworkData = ({\n  networkData,\n  publicClientConfig = {},\n  httpTransportConfig = {},\n}: CreatePublicClientFromNetworkDataProps): PublicClient<\n  HttpTransport,\n  Chain\n> =>\n  createPublicClient({\n    chain: mapNetworkDataToViemChain(networkData),\n    transport: http(networkData.rpcUrls.http[0], httpTransportConfig),\n    ...publicClientConfig,\n  });\n","import type { WalletProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { EvmWalletProvider } from '../EvmWalletProvider.types';\n\n/** @not-instrumented */\nexport const isEvmWalletProvider = (\n  walletProvider: WalletProvider\n): walletProvider is EvmWalletProvider => walletProvider.chain === 'EVM';\n","import type { EIP1193Provider } from '../../EvmWalletProvider.types';\n\n/** @not-instrumented */\nexport const isEIP1193Provider = <T>(\n  provider: T\n): provider is EIP1193Provider & T => {\n  return (\n    provider !== null &&\n    provider !== undefined &&\n    typeof provider === 'object' &&\n    'request' in provider &&\n    typeof provider.request === 'function'\n  );\n};\n","import type { WalletProvider } from '@dynamic-labs-sdk/client/core';\n\nimport type { EvmWalletProviderWithCustomViemClient } from '../../EvmWalletProviderWithCustomViemClient.types';\n\n/** @not-instrumented */\nexport const isEvmWalletProviderWithCustomViemClient = (\n  walletProvider: WalletProvider\n): walletProvider is EvmWalletProviderWithCustomViemClient => {\n  return 'createViemWalletClient' in walletProvider;\n};\n","import {\n  InvalidParamError,\n  getActiveNetworkData,\n} from '@dynamic-labs-sdk/client';\nimport {\n  assertDefined,\n  getDefaultClient,\n  getWalletProviderFromWalletAccount,\n} from '@dynamic-labs-sdk/client/core';\nimport type {\n  Account,\n  Chain,\n  Hex,\n  HttpTransportConfig,\n  Transport,\n  WalletClient,\n  WalletClientConfig,\n} from 'viem';\nimport { createWalletClient, custom } from 'viem';\nimport { toAccount } from 'viem/accounts';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\nimport { isEvmWalletProvider } from '../../isEvmWalletProvider';\nimport { isEIP1193Provider } from '../../utils/isEIP1193Provider';\nimport { mapNetworkDataToViemChain } from '../utils/mapNetworkDataToViemChain';\nimport { isEvmWalletProviderWithCustomViemClient } from '../utils/walletProviderHasCustomWalletClient';\n\ntype CreateWalletClientForWalletAccountProps = {\n  httpTransportConfig?: HttpTransportConfig;\n  walletAccount: EvmWalletAccount;\n  walletClientConfig?: Omit<\n    WalletClientConfig,\n    'account' | 'chain' | 'transport'\n  >;\n};\n\n/**\n * Creates a viem WalletClient from an EVM WalletAccount object.\n *\n * This function configures a viem WalletClient instance for sending transactions\n * and signing messages using the specified wallet account. It automatically\n * handles network configuration and transport setup.\n *\n * @param props - The configuration object.\n * @param props.walletAccount - The EVM wallet account to create the client for.\n * @param [props.walletClientConfig] - Optional additional configuration for the viem WalletClient.\n * @param [props.httpTransportConfig] - Optional HTTP transport configuration.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a configured viem WalletClient instance.\n  * @not-instrumented\n */\nexport const createWalletClientForWalletAccount = async (\n  {\n    walletAccount,\n    walletClientConfig = {},\n    httpTransportConfig = {},\n  }: CreateWalletClientForWalletAccountProps,\n  client = getDefaultClient()\n): Promise<WalletClient<Transport, Chain, Account>> => {\n  const walletProvider = getWalletProviderFromWalletAccount(\n    { walletAccount },\n    client\n  );\n\n  if (!isEvmWalletProvider(walletProvider)) {\n    throw new InvalidParamError(\n      `${walletAccount.address} is not an EVM wallet account`\n    );\n  }\n\n  if (isEvmWalletProviderWithCustomViemClient(walletProvider)) {\n    return walletProvider.createViemWalletClient({\n      httpTransportConfig,\n      viemWalletClientConfig: walletClientConfig,\n      walletAccount,\n    });\n  }\n\n  const { networkData: activeNetworkData } = await getActiveNetworkData(\n    { walletAccount },\n    client\n  );\n\n  assertDefined(\n    activeNetworkData,\n    `No network data found for wallet account ${walletAccount.address}`\n  );\n\n  if (!isEIP1193Provider(walletProvider)) {\n    throw new InvalidParamError(\n      'Wallet provider does not implement the EIP1193Provider interface'\n    );\n  }\n\n  return createWalletClient({\n    account: toAccount(walletAccount.address as Hex),\n    chain: mapNetworkDataToViemChain(activeNetworkData),\n    transport: custom(walletProvider, httpTransportConfig),\n    ...walletClientConfig,\n  });\n};\n"],"mappings":";;;;;;;;;;;;;;;ACOA,MAAa,6BAA6B,iBAAqC;CAC7E,gBAAgB,YAAY,oBAAoB,KAC5C,EACE,SAAS;EACP,MAAM,YAAY,kBAAkB;EACpC,KAAK,YAAY,kBAAkB;EACpC,EACF,GACD;CACJ,IAAI,OAAO,YAAY,UAAU;CACjC,MAAM,YAAY;CAClB,gBAAgB,YAAY;CAC5B,SAAS,EACP,SAAS,EAAE,MAAM,YAAY,QAAQ,MAAM,EAC5C;CACF;;;;;;;;;;;;;;;;;ACSD,MAAa,qCAAqC,EAChD,aACA,qBAAqB,EAAE,EACvB,sBAAsB,EAAE,oCAKL;CACjB,OAAO,0BAA0B,YAAY;CAC7C,0BAAgB,YAAY,QAAQ,KAAK,IAAI,oBAAoB;CACjE,GAAG;CACJ,CAAC;;;;;ACtCJ,MAAa,uBACX,mBACwC,eAAe,UAAU;;;;;ACJnE,MAAa,qBACX,aACoC;AACpC,QACE,aAAa,QACb,aAAa,UACb,OAAO,aAAa,YACpB,aAAa,YACb,OAAO,SAAS,YAAY;;;;;;ACNhC,MAAa,2CACX,mBAC4D;AAC5D,QAAO,4BAA4B;;;;;;;;;;;;;;;;;;;;AC2CrC,MAAa,qCAAqC,OAChD,EACE,eACA,qBAAqB,EAAE,EACvB,sBAAsB,EAAE,IAE1B,8DAA2B,KAC0B;CACrD,MAAM,uFACJ,EAAE,eAAe,EACjB,OACD;AAED,KAAI,CAAC,oBAAoB,eAAe,CACtC,OAAM,IAAIA,2CACR,GAAG,cAAc,QAAQ,+BAC1B;AAGH,KAAI,wCAAwC,eAAe,CACzD,QAAO,eAAe,uBAAuB;EAC3C;EACA,wBAAwB;EACxB;EACD,CAAC;CAGJ,MAAM,EAAE,aAAa,sBAAsB,yDACzC,EAAE,eAAe,EACjB,OACD;AAED,kDACE,mBACA,4CAA4C,cAAc,UAC3D;AAED,KAAI,CAAC,kBAAkB,eAAe,CACpC,OAAM,IAAIA,2CACR,mEACD;AAGH,qCAA0B;EACxB,sCAAmB,cAAc,QAAe;EAChD,OAAO,0BAA0B,kBAAkB;EACnD,4BAAkB,gBAAgB,oBAAoB;EACtD,GAAG;EACJ,CAAC"}