@dynamic-labs-sdk/client 0.2.3 → 0.2.4
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/{InvalidParamError-DkpF0xkO.esm.js → InvalidParamError-Cigi7zsS.esm.js} +2 -2
- package/dist/{InvalidParamError-DkpF0xkO.esm.js.map → InvalidParamError-Cigi7zsS.esm.js.map} +1 -1
- package/dist/{InvalidParamError-CJIvJNbF.cjs.js → InvalidParamError-DQv6ejTe.cjs.js} +2 -2
- package/dist/{InvalidParamError-CJIvJNbF.cjs.js.map → InvalidParamError-DQv6ejTe.cjs.js.map} +1 -1
- package/dist/{NotWaasWalletAccountError-EM-jS7v3.esm.js → NotWaasWalletAccountError-CbHIr6GK.esm.js} +3 -3
- package/dist/{NotWaasWalletAccountError-EM-jS7v3.esm.js.map → NotWaasWalletAccountError-CbHIr6GK.esm.js.map} +1 -1
- package/dist/{NotWaasWalletAccountError-hsivqekP.cjs.js → NotWaasWalletAccountError-zV4xv0h6.cjs.js} +3 -3
- package/dist/{NotWaasWalletAccountError-hsivqekP.cjs.js.map → NotWaasWalletAccountError-zV4xv0h6.cjs.js.map} +1 -1
- package/dist/{constants-DHMXlIUo.esm.js → constants-8IkZb4R4.esm.js} +2 -2
- package/dist/{constants-DHMXlIUo.esm.js.map → constants-8IkZb4R4.esm.js.map} +1 -1
- package/dist/{constants-B_XuwMeC.cjs.js → constants-B3wr3A32.cjs.js} +3 -3
- package/dist/{constants-B_XuwMeC.cjs.js.map → constants-B3wr3A32.cjs.js.map} +1 -1
- package/dist/{constants-vfnggq88.cjs.js → constants-Bj3GZ9o6.cjs.js} +2 -2
- package/dist/{constants-vfnggq88.cjs.js.map → constants-Bj3GZ9o6.cjs.js.map} +1 -1
- package/dist/{constants-CWf6oCKJ.esm.js → constants-DQfjH5fu.esm.js} +2 -2
- package/dist/{constants-CWf6oCKJ.esm.js.map → constants-DQfjH5fu.esm.js.map} +1 -1
- package/dist/core.cjs.js +5 -5
- package/dist/core.esm.js +5 -5
- package/dist/{getNetworkProviderFromNetworkId-D8BsiPYZ.esm.js → getNetworkProviderFromNetworkId-Bccco0Dv.esm.js} +3 -3
- package/dist/{getNetworkProviderFromNetworkId-D8BsiPYZ.esm.js.map → getNetworkProviderFromNetworkId-Bccco0Dv.esm.js.map} +1 -1
- package/dist/{getNetworkProviderFromNetworkId-BHsPtt_G.cjs.js → getNetworkProviderFromNetworkId-DKrjrs7X.cjs.js} +3 -3
- package/dist/{getNetworkProviderFromNetworkId-BHsPtt_G.cjs.js.map → getNetworkProviderFromNetworkId-DKrjrs7X.cjs.js.map} +1 -1
- package/dist/{getSignedSessionId-CLTOI68w.cjs.js → getSignedSessionId-B9i1VIX7.cjs.js} +3 -3
- package/dist/{getSignedSessionId-CLTOI68w.cjs.js.map → getSignedSessionId-B9i1VIX7.cjs.js.map} +1 -1
- package/dist/{getSignedSessionId-lPL9Oude.esm.js → getSignedSessionId-D7cjzDUp.esm.js} +3 -3
- package/dist/{getSignedSessionId-lPL9Oude.esm.js.map → getSignedSessionId-D7cjzDUp.esm.js.map} +1 -1
- package/dist/{getVerifiedCredentialForWalletAccount-HCLyjhLC.cjs.js → getVerifiedCredentialForWalletAccount-CR5wGUFK.cjs.js} +3 -3
- package/dist/{getVerifiedCredentialForWalletAccount-HCLyjhLC.cjs.js.map → getVerifiedCredentialForWalletAccount-CR5wGUFK.cjs.js.map} +1 -1
- package/dist/{getVerifiedCredentialForWalletAccount-Bh27tpbm.esm.js → getVerifiedCredentialForWalletAccount-cVOVjcUI.esm.js} +2 -2
- package/dist/{getVerifiedCredentialForWalletAccount-Bh27tpbm.esm.js.map → getVerifiedCredentialForWalletAccount-cVOVjcUI.esm.js.map} +1 -1
- package/dist/index.cjs.js +6 -6
- package/dist/index.esm.js +6 -6
- package/dist/{isMfaRequiredForAction-CBvaJAqD.cjs.js → isMfaRequiredForAction-Bwphi7AF.cjs.js} +2 -2
- package/dist/{isMfaRequiredForAction-CBvaJAqD.cjs.js.map → isMfaRequiredForAction-Bwphi7AF.cjs.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-DDWwiFPT.esm.js → isMfaRequiredForAction-YAISA589.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-DDWwiFPT.esm.js.map → isMfaRequiredForAction-YAISA589.esm.js.map} +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/waas.cjs.js +5 -5
- package/dist/waas.esm.js +4 -4
- package/dist/waasCore.cjs.js +6 -6
- package/dist/waasCore.esm.js +5 -5
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVerifiedCredentialForWalletAccount-HCLyjhLC.cjs.js","names":["getDefaultClient","getCore","BaseError","WalletProviderEnum","getCore","getChainFromVerifiedCredentialChain","getChainFromVerifiedCredentialChain","walletAccountsMap: Map<string, WalletAccount>","JwtVerifiedCredentialFormatEnum","getDefaultClient","getCore","BaseError","getCore","getCore","getCore","newState: Partial<DynamicCoreState>","isCookieEnabled","walletProvider"],"sources":["../src/utils/setCookie/setCookie.ts","../src/modules/clientEvents/clientEvents.ts","../src/errors/InvalidWalletProviderKeyError.ts","../src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts","../src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts","../src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts","../src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts","../src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts","../src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts","../src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts","../src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts","../src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts","../src/modules/wallets/getWalletAccounts/getWalletAccounts.ts","../src/errors/NoWalletProviderFoundError.ts","../src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts","../src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts","../src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts","../src/modules/auth/consts.ts","../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["/**\n * Sefelly sets the cookie in the browser.\n */\nexport const setCookie = (cookie: string) => {\n // eslint-disable-next-line no-restricted-globals\n document.cookie = cookie;\n};\n","import { getCore } from '../../client/core/getCore';\nimport { getDefaultClient } from '../../client/defaultClient';\nimport type { DynamicClient } from '../../client/types';\nimport type {\n DynamicEvents,\n EmitEventParams,\n OffEventParams,\n OnEventParams,\n OnceEventParams,\n} from './clientEvents.types';\n\n/**\n * Adds an event listener for Dynamic client events.\n *\n * This function allows you to listen for various events emitted by the Dynamic client,\n * such as authentication state changes, wallet connections, and more.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener.\n */\nexport const onEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.on(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Removes an event listener from Dynamic client events.\n *\n * This function unsubscribes a previously registered event listener\n * from the specified Dynamic client event.\n *\n * @param params.event - The event name to remove the listener from.\n * @param params.listener - The callback function to remove.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const offEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OffEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.off(event, listener);\n};\n\n/**\n * Adds a one-time event listener for Dynamic client events.\n *\n * This function listens for an event that will automatically remove itself\n * after being triggered once.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener before it fires.\n */\nexport const onceEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnceEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.once(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Emits a Dynamic client event.\n *\n * This function triggers an event that will be received by all registered\n * listeners for the specified event type.\n *\n * @param params.event - The event name to emit.\n * @param params.args - The arguments to pass to event listeners.\n * @param client - The Dynamic client instance.\n */\nexport const emitEvent = <E extends keyof DynamicEvents>(\n { event, args }: EmitEventParams<E>,\n client: DynamicClient\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.emit(event, args);\n};\n","import { BaseError } from './base';\n\nexport class InvalidWalletProviderKeyError extends BaseError {\n constructor(value: string) {\n super({\n cause: null,\n code: 'invalid_wallet_provider_key',\n docsUrl: null,\n name: 'InvalidWalletProviderKeyError',\n shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`,\n });\n }\n}\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { InvalidWalletProviderKeyError } from '../../../../errors/InvalidWalletProviderKeyError';\n\ntype SplitWalletProviderKeyResult = {\n normalizedWalletNameWithChain: string;\n suffix: string | undefined;\n walletProviderType: WalletProviderEnum;\n};\n\nexport const splitWalletProviderKey = (\n walletProviderKey: string\n): SplitWalletProviderKeyResult => {\n const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] =\n walletProviderKey.split(':');\n\n if (\n !normalizedWalletNameWithChain ||\n !Object.values(WalletProviderEnum).includes(\n walletProviderType as WalletProviderEnum\n ) ||\n rest.length > 0\n ) {\n throw new InvalidWalletProviderKeyError(walletProviderKey);\n }\n\n return {\n normalizedWalletNameWithChain,\n suffix,\n walletProviderType: walletProviderType as WalletProviderEnum,\n };\n};\n","import type { Chain } from '../../../chain';\n\nexport const normalizeAddress = (address: string, chain: Chain) => {\n let normalizedAddress = address;\n\n if (normalizedAddress?.startsWith('0x')) {\n normalizedAddress = normalizedAddress.slice(2);\n }\n\n /**\n * These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md\n * see also: https://github.com/ChainAgnostic/namespaces\n * note: no standard namespace currently exists for flow\n */\n const chainsThatRequireLowercaseAddress: Chain[] = ['EVM', 'FLOW'];\n\n normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain)\n ? normalizedAddress?.toLowerCase()\n : normalizedAddress;\n\n return normalizedAddress;\n};\n","import type { Chain } from '../../../chain';\nimport { splitWalletProviderKey } from '../../walletProvider/splitWalletProviderKey';\nimport { normalizeAddress } from '../normalizeAddress';\n\ntype CreateWalletAccountIdParams = {\n address: string;\n chain: Chain;\n walletProviderKey: string;\n};\n\nexport const formatWalletAccountId = ({\n address,\n chain,\n walletProviderKey,\n}: CreateWalletAccountIdParams): string => {\n const { normalizedWalletNameWithChain } =\n splitWalletProviderKey(walletProviderKey);\n\n const normalizedAddress = normalizeAddress(address, chain);\n\n return `${normalizedWalletNameWithChain}:${normalizedAddress}`;\n};\n","import type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport type { WalletAccount } from '../../walletAccount';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertUnverifiedWalletAccountToWalletAccountParams = {\n unverifiedWalletAccount: UnverifiedWalletAccount;\n};\n\nexport const convertUnverifiedWalletAccountToWalletAccount = ({\n unverifiedWalletAccount,\n}: ConvertUnverifiedWalletAccountToWalletAccountParams): WalletAccount => ({\n address: unverifiedWalletAccount.address,\n addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,\n chain: unverifiedWalletAccount.chain,\n id: formatWalletAccountId({\n address: unverifiedWalletAccount.address,\n chain: unverifiedWalletAccount.chain,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n }),\n lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,\n verifiedCredentialId: null,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n});\n","import type { Chain } from '../../../chain';\n\ntype NormalizeWalletNameWithChainParams = {\n chain: Chain;\n displayName: string;\n};\n\n/**\n * Format the raw wallet name and chain to get the value we can use for\n * verified credentials' `walletName` field.\n */\nexport const normalizeWalletNameWithChain = ({\n displayName,\n chain,\n}: NormalizeWalletNameWithChainParams): string => {\n const sanitizedWalletName = displayName\n .replace(/[^a-zA-Z0-9]/g, '')\n .toLowerCase();\n\n const chainLowered = chain.toLocaleLowerCase();\n\n if (sanitizedWalletName.endsWith(chainLowered)) {\n return sanitizedWalletName;\n }\n\n return `${sanitizedWalletName}${chainLowered}`;\n};\n","import type { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { Chain } from '../../../chain';\nimport { normalizeWalletNameWithChain } from '../normalizeWalletNameWithChain';\n\ntype FormatWalletProviderKeyParams = {\n chain: Chain;\n displayName: string;\n suffix?: string;\n walletProviderType: WalletProviderEnum;\n};\n\n/**\n * Assembles the wallet provider key from the wallet name, chain, and wallet provider type.\n *\n * The suffix is optional and can be used to add a uniquely identifying string to the key, which\n * might be necessary for some wallet providers (like Wallet Connect).\n *\n * IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account\n * to not be able to find its wallet provider when connecting to a new device (it won't be possible\n * to determine the full key just from the Verified Credential data).\n */\nexport const formatWalletProviderKey = ({\n suffix,\n chain,\n displayName,\n walletProviderType,\n}: FormatWalletProviderKeyParams) => {\n const normalizedNameWithChain = normalizeWalletNameWithChain({\n chain,\n displayName,\n });\n\n return `${normalizedNameWithChain}:${walletProviderType}${\n suffix ? `:${suffix}` : ''\n }`;\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../../client/types';\nimport { assertDefined } from '../../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../../utils/getChainFromVerifiedCredentialChain';\nimport { formatWalletProviderKey } from '../../../utils/formatWalletProviderKey';\n\ntype GetWalletProviderKeyFromVerifiedCredentialParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const getWalletProviderKeyFromVerifiedCredential = (\n { verifiedCredential }: GetWalletProviderKeyFromVerifiedCredentialParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const { walletProviderKeyMap } = core.state.get();\n\n const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];\n\n if (storedWalletProviderKey) {\n return { walletProviderKey: storedWalletProviderKey };\n }\n\n /**\n * We fallback to comprising the wallet provider key from walletName and walletProvider.\n *\n * Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider\n * keys, so this won't be enough for them.\n * Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider\n * and will require reconnection.\n * Read walletProvider.types.ts for more info.\n */\n assertDefined(\n verifiedCredential.walletName,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`\n );\n\n assertDefined(\n verifiedCredential.walletProvider,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`\n );\n\n assertDefined(\n verifiedCredential.chain,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`\n );\n\n /**\n * Historically, walletNames did not include the chain name as a suffix.\n * This piece of logic simply ensures we normalize any legacy walletNames to conform.\n */\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const walletProviderKey = formatWalletProviderKey({\n chain,\n displayName: verifiedCredential.walletName,\n walletProviderType: verifiedCredential.walletProvider,\n });\n\n return { walletProviderKey };\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport { assertDefined } from '../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../utils/getChainFromVerifiedCredentialChain';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderKeyFromVerifiedCredential } from '../../walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertVerifiedCredentialToWalletAccountParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const convertVerifiedCredentialToWalletAccount = (\n { verifiedCredential }: ConvertVerifiedCredentialToWalletAccountParams,\n client: DynamicClient\n): WalletAccount => {\n assertDefined(\n verifiedCredential.address,\n 'Missing address in verified credential'\n );\n assertDefined(\n verifiedCredential.chain,\n 'Missing chain in verified credential'\n );\n\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential(\n {\n verifiedCredential,\n },\n client\n );\n\n const walletAccountId = formatWalletAccountId({\n address: verifiedCredential.address,\n chain,\n walletProviderKey,\n });\n\n return {\n address: verifiedCredential.address,\n addressesWithTypes: verifiedCredential.walletAdditionalAddresses,\n chain,\n id: walletAccountId,\n lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,\n verifiedCredentialId: verifiedCredential.id,\n walletProviderKey,\n };\n};\n","import type { SdkUser } from '@dynamic-labs/sdk-api-core';\nimport { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport { convertUnverifiedWalletAccountToWalletAccount } from '../../utils/convertUnverifiedWalletAccountToWalletAccount';\nimport { convertVerifiedCredentialToWalletAccount } from '../../utils/convertVerifiedCredentialToWalletAccount';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetWalletAccountsFromStateParams = {\n unverifiedWalletAccounts: UnverifiedWalletAccount[];\n user: SdkUser | null;\n};\n\nexport const getWalletAccountsFromState = (\n { unverifiedWalletAccounts, user }: GetWalletAccountsFromStateParams,\n client: DynamicClient\n): WalletAccount[] => {\n const walletAccountsMap: Map<string, WalletAccount> = new Map();\n\n /**\n * Handle the unverified wallet accounts before the user verified credentials\n * so the later verified wallet accounts can override the unverified wallet accounts\n */\n unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {\n const walletAccount = convertUnverifiedWalletAccountToWalletAccount({\n unverifiedWalletAccount,\n });\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n /**\n * Handle user verified credentials\n */\n const verifiedCredentials = user?.verifiedCredentials ?? [];\n\n verifiedCredentials\n .filter(\n (verified) =>\n verified.format === JwtVerifiedCredentialFormatEnum.Blockchain\n )\n .forEach((verifiedWalletAccount) => {\n const walletAccount = convertVerifiedCredentialToWalletAccount(\n {\n verifiedCredential: verifiedWalletAccount,\n },\n client\n );\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n return Array.from(walletAccountsMap.values());\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport type { WalletAccount } from '../walletAccount';\nimport { getWalletAccountsFromState } from './getWalletAccountsFromState';\n\n/**\n * Retrieves all wallet accounts associated with the current session.\n *\n * This function returns both verified and unverified wallet accounts,\n * combining data from user credentials and local unverified accounts.\n * You can differentiate between verified and unverified wallet accounts by\n * checking the `verifiedCredentialId` property.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An array of wallet accounts associated with the session.\n */\nexport const getWalletAccounts = (\n client = getDefaultClient()\n): WalletAccount[] => {\n const core = getCore(client);\n const { unverifiedWalletAccounts, user } = core.state.get();\n\n return getWalletAccountsFromState({ unverifiedWalletAccounts, user }, client);\n};\n","import { BaseError } from './base';\n\ntype NoWalletProviderFoundErrorParams = {\n walletProviderKey: string;\n};\n\nexport class NoWalletProviderFoundError extends BaseError {\n constructor({ walletProviderKey }: NoWalletProviderFoundErrorParams) {\n super({\n cause: null,\n code: 'no_wallet_provider_found_error',\n docsUrl: null,\n name: 'NoWalletProviderFoundError',\n shortMessage: `No wallet provider found with key: ${walletProviderKey}`,\n });\n }\n}\n","import type { DynamicClient } from '../../../client/types/DynamicClient';\nimport { getCore } from '../../../client/core/getCore';\n\n/**\n * Creates a service accessor function that manages service instantiation and caching.\n * The returned function will either retrieve an existing service from the registry or\n * create a new one using the provided builder function.\n *\n * @template - The type of service to be created/accessed\n * @param key - Unique identifier for the service in the registry\n * @param builder - Function that creates the service instance when called with a DynamicClient\n */\nexport const createRuntimeServiceAccessKey =\n <T>(key: string, builder: (client: DynamicClient) => T) =>\n (client: DynamicClient): T => {\n const { runtimeServices } = getCore(client);\n\n const currentService = runtimeServices.getByKey<T>(key);\n\n if (currentService) {\n return currentService;\n }\n\n const service = builder(client);\n\n runtimeServices.register(key, service);\n\n return service;\n };\n","import type { DynamicClient } from '../../../../client/types';\nimport { emitEvent } from '../../../clientEvents';\nimport type { WalletProvider } from '../../walletProvider/walletProvider.types';\nimport type { WalletProviderRegistry } from '../walletProviderRegistry.types';\n\n/**\n * Creates a new wallet provider registry that manages wallet providers with priority-based registration.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * const registry = createWalletProviderRegistry();\n *\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * const provider = registry.getByKey('my-wallet-key');\n * const providers = registry.listProviders();\n * ```\n */\nexport const createWalletProviderRegistry = (\n client: DynamicClient\n): WalletProviderRegistry => {\n const registry = new Map<\n string,\n { priority: number; walletProvider: WalletProvider }\n >();\n\n return {\n getByKey: (key) => registry.get(key)?.walletProvider,\n listProviders: () =>\n Array.from(registry.values()).map((v) => v.walletProvider),\n register: (args) => {\n const existingEntry = registry.get(args.walletProvider.key);\n\n if (existingEntry) {\n if (existingEntry.priority < args.priority) {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n } else {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProvider: args.walletProvider },\n event: 'walletProviderRegistered',\n },\n client\n );\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n },\n unregister: (key) => {\n registry.delete(key);\n\n emitEvent(\n {\n args: { walletProviderKey: key },\n event: 'walletProviderUnregistered',\n },\n client\n );\n },\n };\n};\n","import { createRuntimeServiceAccessKey } from '../../../../services/runtimeServices';\nimport { createWalletProviderRegistry } from '../createWalletProviderRegistry';\n\n/**\n * This function provides access to a shared instance of the wallet provider registry.\n *\n * It ensures that the same registry instance is used throughout the client to maintaining\n * consistency of registered wallet providers across different parts of the codebase.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * // Get the registry instance\n * const registry = getWalletProviderRegistry();\n *\n * // Register a wallet provider\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * // Retrieve a specific provider\n * const provider = registry.getByKey('metamaskevm');\n * ```\n */\nexport const getWalletProviderRegistry = createRuntimeServiceAccessKey(\n 'walletProviderRegistry',\n (client) => createWalletProviderRegistry(client)\n);\n","import type { WalletProvider } from '../walletProvider/walletProvider.types';\n\nexport enum WalletProviderPriority {\n /**\n * Highest priority should be used by wallet providers that implement\n * the most reliable wallet integration.\n * example: The SDK provided by the wallet provider.\n */\n WALLET_SDK = 100,\n /**\n * Medium priority should be used by wallet providers that implement\n * a wallet integration via some reliable standard.\n * example: A wallet provider that uses EIP6963 announcement.\n */\n WALLET_SELF_ANNOUNCEMENT_STANDARD = 50,\n /**\n * Low priority should be used by wallet providers that implement\n * a wallet integration on a less reliable standard.\n * example: A wallet provider that uses window.ethereum, where the\n * window key can be overridden by other extensions.\n */\n WINDOW_INJECT = 20,\n}\n\nexport type WalletProviderRegistry = {\n /**\n * Retrieves a wallet provider by its key.\n * @param key - The key of the wallet provider.\n * @returns The wallet provider.\n */\n getByKey: (key: string) => WalletProvider | undefined;\n /**\n * Retrieves all wallet providers.\n * @returns The wallet providers.\n */\n listProviders: () => WalletProvider[];\n /**\n * Registers a wallet provider.\n * @param args - The arguments for the wallet provider.\n */\n register: (args: {\n priority: WalletProviderPriority;\n walletProvider: WalletProvider;\n }) => void;\n /**\n * Unregisters a wallet provider.\n * @param key - The key of the wallet provider.\n */\n unregister: (key: string) => void;\n};\n","import type { DynamicClient } from '../../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../../errors/NoWalletProviderFoundError';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderRegistry } from '../../walletProviderRegistry';\n\ntype GetWalletProviderFromWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getWalletProviderFromWalletAccount = (\n { walletAccount }: GetWalletProviderFromWalletAccountParams,\n client: DynamicClient\n) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = walletProviderRegistry.getByKey(\n walletAccount.walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({\n walletProviderKey: walletAccount.walletProviderKey,\n });\n }\n\n return walletProvider;\n};\n","export const DYNAMIC_AUTH_COOKIE_NAME = 'DYNAMIC_JWT_TOKEN';\n","import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n */\nexport const emitWalletAccountsChangedEvent = (client: DynamicClient): void => {\n const walletAccounts = getWalletAccounts(client);\n\n emitEvent(\n {\n args: { walletAccounts },\n event: 'walletAccountsChanged',\n },\n client\n );\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { emitWalletAccountsChangedEvent } from '../../../wallets/emitWalletAccountsChangedEvent';\nimport { getWalletAccountsFromState } from '../../../wallets/getWalletAccounts/getWalletAccountsFromState';\n\ntype CheckAndRaiseWalletAccountsChangedEventParams = {\n previousState: Readonly<DynamicCoreState>;\n};\n\nexport const checkAndRaiseWalletAccountsChangedEvent = (\n { previousState }: CheckAndRaiseWalletAccountsChangedEventParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletAccountsHashBefore = getWalletAccountsHash(previousState, client);\n\n const walletAccountsHashAfter = getWalletAccountsHash(\n core.state.get(),\n client\n );\n\n if (walletAccountsHashBefore !== walletAccountsHashAfter) {\n emitWalletAccountsChangedEvent(client);\n }\n};\n\nconst getWalletAccountsHash = (\n state: Readonly<DynamicCoreState>,\n client: DynamicClient\n) =>\n getWalletAccountsFromState(state, client)\n .map((walletAccount) => JSON.stringify(walletAccount))\n .sort()\n .join('-');\n","import type { VerifyResponse } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../client/core/getCore';\nimport type { DynamicCoreState } from '../../../client/core/types';\nimport type { DynamicClient } from '../../../client/types';\nimport { setCookie } from '../../../utils/setCookie';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\nexport const updateAuthFromVerifyResponse = (\n { response }: UpdateAuthFromVerifyResponseParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const previousState = { ...core.state.get() };\n\n const { user, minifiedJwt, jwt, expiresAt, mfaToken } = response;\n\n // Expires at is in seconds, so we need to convert it to milliseconds\n const sessionExpiresAt = new Date(expiresAt * 1000);\n\n const newState: Partial<DynamicCoreState> = {\n legacyToken: jwt ?? null,\n sessionExpiresAt: sessionExpiresAt,\n token: minifiedJwt ?? null,\n user,\n };\n\n // only override the mfaToken if a new one is provided in the response\n if (mfaToken) {\n newState.mfaToken = mfaToken;\n }\n\n core.state.set(newState);\n\n /**\n * For customers using a sandbox environment with cookies enabled, we need to set the cookie\n * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically\n * so customers can access the cookie from document.cookie consistently between sandbox and live environments.\n */\n if (minifiedJwt && isCookieEnabled(client)) {\n const expireDate = sessionExpiresAt.toUTCString();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`\n );\n }\n\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getWalletProviderRegistry } from '../walletProviderRegistry';\n\n/**\n * Get all available wallet providers to interact with internally.\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n"],"mappings":";;;;;;;;AAGA,MAAa,aAAa,WAAmB;AAE3C,UAAS,SAAS;;;;;;;;;;;;;;;;ACiBpB,MAAa,WACX,EAAE,OAAO,YACT,SAASA,oCAAkB,KACxB;CACH,MAAM,EAAE,iBAAiBC,0BAAQ,OAAO;AAExC,cAAa,GAAG,OAAO,SAAS;AAEhC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,YACX,EAAE,OAAO,YACT,SAASD,oCAAkB,KACxB;CACH,MAAM,EAAE,iBAAiBC,0BAAQ,OAAO;AAExC,cAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcnC,MAAa,aACX,EAAE,OAAO,YACT,SAASD,oCAAkB,KACxB;CACH,MAAM,EAAE,iBAAiBC,0BAAQ,OAAO;AAExC,cAAa,KAAK,OAAO,SAAS;AAElC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,aACX,EAAE,OAAO,QACT,WACG;CACH,MAAM,EAAE,iBAAiBA,0BAAQ,OAAO;AAExC,cAAa,KAAK,OAAO,KAAK;;;;;AC5FhC,IAAa,gCAAb,cAAmDC,4BAAU;CAC3D,YAAY,OAAe;AACzB,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc,gCAAgC,MAAM;GACrD,CAAC;;;;;;ACAN,MAAa,0BACX,sBACiC;CACjC,MAAM,CAAC,+BAA+B,oBAAoB,QAAQ,GAAG,Q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AY,IAAK;CAEnD,MAAMC,WAAsC;EAC1C,aAAa,OAAO;EACF;EAClB,OAAO,eAAe;EACtB;EACD;AAGD,KAAI,SACF,UAAS,WAAW;AAGtB,MAAK,MAAM,IAAI,SAAS;;;;;;AAOxB,KAAI,eAAeC,kCAAgB,OAAO,CAGxC,WACE,GAAG,yBAAyB,GAAG,YAAY,YAH1B,iBAAiB,aAAa,CAGmB,wBACnE;AAGH,yCAAwC,EAAE,eAAe,EAAE,OAAO;;;;;;;;AChDpE,MAAa,sBAAsB,WAA0B;AAG3D,QAF+B,0BAA0B,OAAO,CAElC,eAAe;;;;;ACD/C,MAAa,0BACX,EAAE,qBACF,WACG;CAGH,MAAM,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBC,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO;;;;;ACfT,MAAa,yCACX,EAAE,iBACF,WACG;AACH,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC"}
|
|
1
|
+
{"version":3,"file":"getVerifiedCredentialForWalletAccount-CR5wGUFK.cjs.js","names":["getDefaultClient","getCore","BaseError","WalletProviderEnum","getCore","getChainFromVerifiedCredentialChain","getChainFromVerifiedCredentialChain","walletAccountsMap: Map<string, WalletAccount>","JwtVerifiedCredentialFormatEnum","getDefaultClient","getCore","BaseError","getCore","getCore","getCore","newState: Partial<DynamicCoreState>","isCookieEnabled","walletProvider"],"sources":["../src/utils/setCookie/setCookie.ts","../src/modules/clientEvents/clientEvents.ts","../src/errors/InvalidWalletProviderKeyError.ts","../src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts","../src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts","../src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts","../src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts","../src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts","../src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts","../src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts","../src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts","../src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts","../src/modules/wallets/getWalletAccounts/getWalletAccounts.ts","../src/errors/NoWalletProviderFoundError.ts","../src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts","../src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts","../src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts","../src/modules/auth/consts.ts","../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["/**\n * Sefelly sets the cookie in the browser.\n */\nexport const setCookie = (cookie: string) => {\n // eslint-disable-next-line no-restricted-globals\n document.cookie = cookie;\n};\n","import { getCore } from '../../client/core/getCore';\nimport { getDefaultClient } from '../../client/defaultClient';\nimport type { DynamicClient } from '../../client/types';\nimport type {\n DynamicEvents,\n EmitEventParams,\n OffEventParams,\n OnEventParams,\n OnceEventParams,\n} from './clientEvents.types';\n\n/**\n * Adds an event listener for Dynamic client events.\n *\n * This function allows you to listen for various events emitted by the Dynamic client,\n * such as authentication state changes, wallet connections, and more.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener.\n */\nexport const onEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.on(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Removes an event listener from Dynamic client events.\n *\n * This function unsubscribes a previously registered event listener\n * from the specified Dynamic client event.\n *\n * @param params.event - The event name to remove the listener from.\n * @param params.listener - The callback function to remove.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const offEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OffEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.off(event, listener);\n};\n\n/**\n * Adds a one-time event listener for Dynamic client events.\n *\n * This function listens for an event that will automatically remove itself\n * after being triggered once.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener before it fires.\n */\nexport const onceEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnceEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.once(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Emits a Dynamic client event.\n *\n * This function triggers an event that will be received by all registered\n * listeners for the specified event type.\n *\n * @param params.event - The event name to emit.\n * @param params.args - The arguments to pass to event listeners.\n * @param client - The Dynamic client instance.\n */\nexport const emitEvent = <E extends keyof DynamicEvents>(\n { event, args }: EmitEventParams<E>,\n client: DynamicClient\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.emit(event, args);\n};\n","import { BaseError } from './base';\n\nexport class InvalidWalletProviderKeyError extends BaseError {\n constructor(value: string) {\n super({\n cause: null,\n code: 'invalid_wallet_provider_key',\n docsUrl: null,\n name: 'InvalidWalletProviderKeyError',\n shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`,\n });\n }\n}\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { InvalidWalletProviderKeyError } from '../../../../errors/InvalidWalletProviderKeyError';\n\ntype SplitWalletProviderKeyResult = {\n normalizedWalletNameWithChain: string;\n suffix: string | undefined;\n walletProviderType: WalletProviderEnum;\n};\n\nexport const splitWalletProviderKey = (\n walletProviderKey: string\n): SplitWalletProviderKeyResult => {\n const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] =\n walletProviderKey.split(':');\n\n if (\n !normalizedWalletNameWithChain ||\n !Object.values(WalletProviderEnum).includes(\n walletProviderType as WalletProviderEnum\n ) ||\n rest.length > 0\n ) {\n throw new InvalidWalletProviderKeyError(walletProviderKey);\n }\n\n return {\n normalizedWalletNameWithChain,\n suffix,\n walletProviderType: walletProviderType as WalletProviderEnum,\n };\n};\n","import type { Chain } from '../../../chain';\n\nexport const normalizeAddress = (address: string, chain: Chain) => {\n let normalizedAddress = address;\n\n if (normalizedAddress?.startsWith('0x')) {\n normalizedAddress = normalizedAddress.slice(2);\n }\n\n /**\n * These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md\n * see also: https://github.com/ChainAgnostic/namespaces\n * note: no standard namespace currently exists for flow\n */\n const chainsThatRequireLowercaseAddress: Chain[] = ['EVM', 'FLOW'];\n\n normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain)\n ? normalizedAddress?.toLowerCase()\n : normalizedAddress;\n\n return normalizedAddress;\n};\n","import type { Chain } from '../../../chain';\nimport { splitWalletProviderKey } from '../../walletProvider/splitWalletProviderKey';\nimport { normalizeAddress } from '../normalizeAddress';\n\ntype CreateWalletAccountIdParams = {\n address: string;\n chain: Chain;\n walletProviderKey: string;\n};\n\nexport const formatWalletAccountId = ({\n address,\n chain,\n walletProviderKey,\n}: CreateWalletAccountIdParams): string => {\n const { normalizedWalletNameWithChain } =\n splitWalletProviderKey(walletProviderKey);\n\n const normalizedAddress = normalizeAddress(address, chain);\n\n return `${normalizedWalletNameWithChain}:${normalizedAddress}`;\n};\n","import type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport type { WalletAccount } from '../../walletAccount';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertUnverifiedWalletAccountToWalletAccountParams = {\n unverifiedWalletAccount: UnverifiedWalletAccount;\n};\n\nexport const convertUnverifiedWalletAccountToWalletAccount = ({\n unverifiedWalletAccount,\n}: ConvertUnverifiedWalletAccountToWalletAccountParams): WalletAccount => ({\n address: unverifiedWalletAccount.address,\n addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,\n chain: unverifiedWalletAccount.chain,\n id: formatWalletAccountId({\n address: unverifiedWalletAccount.address,\n chain: unverifiedWalletAccount.chain,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n }),\n lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,\n verifiedCredentialId: null,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n});\n","import type { Chain } from '../../../chain';\n\ntype NormalizeWalletNameWithChainParams = {\n chain: Chain;\n displayName: string;\n};\n\n/**\n * Format the raw wallet name and chain to get the value we can use for\n * verified credentials' `walletName` field.\n */\nexport const normalizeWalletNameWithChain = ({\n displayName,\n chain,\n}: NormalizeWalletNameWithChainParams): string => {\n const sanitizedWalletName = displayName\n .replace(/[^a-zA-Z0-9]/g, '')\n .toLowerCase();\n\n const chainLowered = chain.toLocaleLowerCase();\n\n if (sanitizedWalletName.endsWith(chainLowered)) {\n return sanitizedWalletName;\n }\n\n return `${sanitizedWalletName}${chainLowered}`;\n};\n","import type { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { Chain } from '../../../chain';\nimport { normalizeWalletNameWithChain } from '../normalizeWalletNameWithChain';\n\ntype FormatWalletProviderKeyParams = {\n chain: Chain;\n displayName: string;\n suffix?: string;\n walletProviderType: WalletProviderEnum;\n};\n\n/**\n * Assembles the wallet provider key from the wallet name, chain, and wallet provider type.\n *\n * The suffix is optional and can be used to add a uniquely identifying string to the key, which\n * might be necessary for some wallet providers (like Wallet Connect).\n *\n * IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account\n * to not be able to find its wallet provider when connecting to a new device (it won't be possible\n * to determine the full key just from the Verified Credential data).\n */\nexport const formatWalletProviderKey = ({\n suffix,\n chain,\n displayName,\n walletProviderType,\n}: FormatWalletProviderKeyParams) => {\n const normalizedNameWithChain = normalizeWalletNameWithChain({\n chain,\n displayName,\n });\n\n return `${normalizedNameWithChain}:${walletProviderType}${\n suffix ? `:${suffix}` : ''\n }`;\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../../client/types';\nimport { assertDefined } from '../../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../../utils/getChainFromVerifiedCredentialChain';\nimport { formatWalletProviderKey } from '../../../utils/formatWalletProviderKey';\n\ntype GetWalletProviderKeyFromVerifiedCredentialParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const getWalletProviderKeyFromVerifiedCredential = (\n { verifiedCredential }: GetWalletProviderKeyFromVerifiedCredentialParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const { walletProviderKeyMap } = core.state.get();\n\n const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];\n\n if (storedWalletProviderKey) {\n return { walletProviderKey: storedWalletProviderKey };\n }\n\n /**\n * We fallback to comprising the wallet provider key from walletName and walletProvider.\n *\n * Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider\n * keys, so this won't be enough for them.\n * Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider\n * and will require reconnection.\n * Read walletProvider.types.ts for more info.\n */\n assertDefined(\n verifiedCredential.walletName,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`\n );\n\n assertDefined(\n verifiedCredential.walletProvider,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`\n );\n\n assertDefined(\n verifiedCredential.chain,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`\n );\n\n /**\n * Historically, walletNames did not include the chain name as a suffix.\n * This piece of logic simply ensures we normalize any legacy walletNames to conform.\n */\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const walletProviderKey = formatWalletProviderKey({\n chain,\n displayName: verifiedCredential.walletName,\n walletProviderType: verifiedCredential.walletProvider,\n });\n\n return { walletProviderKey };\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport { assertDefined } from '../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../utils/getChainFromVerifiedCredentialChain';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderKeyFromVerifiedCredential } from '../../walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertVerifiedCredentialToWalletAccountParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const convertVerifiedCredentialToWalletAccount = (\n { verifiedCredential }: ConvertVerifiedCredentialToWalletAccountParams,\n client: DynamicClient\n): WalletAccount => {\n assertDefined(\n verifiedCredential.address,\n 'Missing address in verified credential'\n );\n assertDefined(\n verifiedCredential.chain,\n 'Missing chain in verified credential'\n );\n\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential(\n {\n verifiedCredential,\n },\n client\n );\n\n const walletAccountId = formatWalletAccountId({\n address: verifiedCredential.address,\n chain,\n walletProviderKey,\n });\n\n return {\n address: verifiedCredential.address,\n addressesWithTypes: verifiedCredential.walletAdditionalAddresses,\n chain,\n id: walletAccountId,\n lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,\n verifiedCredentialId: verifiedCredential.id,\n walletProviderKey,\n };\n};\n","import type { SdkUser } from '@dynamic-labs/sdk-api-core';\nimport { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport { convertUnverifiedWalletAccountToWalletAccount } from '../../utils/convertUnverifiedWalletAccountToWalletAccount';\nimport { convertVerifiedCredentialToWalletAccount } from '../../utils/convertVerifiedCredentialToWalletAccount';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetWalletAccountsFromStateParams = {\n unverifiedWalletAccounts: UnverifiedWalletAccount[];\n user: SdkUser | null;\n};\n\nexport const getWalletAccountsFromState = (\n { unverifiedWalletAccounts, user }: GetWalletAccountsFromStateParams,\n client: DynamicClient\n): WalletAccount[] => {\n const walletAccountsMap: Map<string, WalletAccount> = new Map();\n\n /**\n * Handle the unverified wallet accounts before the user verified credentials\n * so the later verified wallet accounts can override the unverified wallet accounts\n */\n unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {\n const walletAccount = convertUnverifiedWalletAccountToWalletAccount({\n unverifiedWalletAccount,\n });\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n /**\n * Handle user verified credentials\n */\n const verifiedCredentials = user?.verifiedCredentials ?? [];\n\n verifiedCredentials\n .filter(\n (verified) =>\n verified.format === JwtVerifiedCredentialFormatEnum.Blockchain\n )\n .forEach((verifiedWalletAccount) => {\n const walletAccount = convertVerifiedCredentialToWalletAccount(\n {\n verifiedCredential: verifiedWalletAccount,\n },\n client\n );\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n return Array.from(walletAccountsMap.values());\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport type { WalletAccount } from '../walletAccount';\nimport { getWalletAccountsFromState } from './getWalletAccountsFromState';\n\n/**\n * Retrieves all wallet accounts associated with the current session.\n *\n * This function returns both verified and unverified wallet accounts,\n * combining data from user credentials and local unverified accounts.\n * You can differentiate between verified and unverified wallet accounts by\n * checking the `verifiedCredentialId` property.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An array of wallet accounts associated with the session.\n */\nexport const getWalletAccounts = (\n client = getDefaultClient()\n): WalletAccount[] => {\n const core = getCore(client);\n const { unverifiedWalletAccounts, user } = core.state.get();\n\n return getWalletAccountsFromState({ unverifiedWalletAccounts, user }, client);\n};\n","import { BaseError } from './base';\n\ntype NoWalletProviderFoundErrorParams = {\n walletProviderKey: string;\n};\n\nexport class NoWalletProviderFoundError extends BaseError {\n constructor({ walletProviderKey }: NoWalletProviderFoundErrorParams) {\n super({\n cause: null,\n code: 'no_wallet_provider_found_error',\n docsUrl: null,\n name: 'NoWalletProviderFoundError',\n shortMessage: `No wallet provider found with key: ${walletProviderKey}`,\n });\n }\n}\n","import type { DynamicClient } from '../../../client/types/DynamicClient';\nimport { getCore } from '../../../client/core/getCore';\n\n/**\n * Creates a service accessor function that manages service instantiation and caching.\n * The returned function will either retrieve an existing service from the registry or\n * create a new one using the provided builder function.\n *\n * @template - The type of service to be created/accessed\n * @param key - Unique identifier for the service in the registry\n * @param builder - Function that creates the service instance when called with a DynamicClient\n */\nexport const createRuntimeServiceAccessKey =\n <T>(key: string, builder: (client: DynamicClient) => T) =>\n (client: DynamicClient): T => {\n const { runtimeServices } = getCore(client);\n\n const currentService = runtimeServices.getByKey<T>(key);\n\n if (currentService) {\n return currentService;\n }\n\n const service = builder(client);\n\n runtimeServices.register(key, service);\n\n return service;\n };\n","import type { DynamicClient } from '../../../../client/types';\nimport { emitEvent } from '../../../clientEvents';\nimport type { WalletProvider } from '../../walletProvider/walletProvider.types';\nimport type { WalletProviderRegistry } from '../walletProviderRegistry.types';\n\n/**\n * Creates a new wallet provider registry that manages wallet providers with priority-based registration.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * const registry = createWalletProviderRegistry();\n *\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * const provider = registry.getByKey('my-wallet-key');\n * const providers = registry.listProviders();\n * ```\n */\nexport const createWalletProviderRegistry = (\n client: DynamicClient\n): WalletProviderRegistry => {\n const registry = new Map<\n string,\n { priority: number; walletProvider: WalletProvider }\n >();\n\n return {\n getByKey: (key) => registry.get(key)?.walletProvider,\n listProviders: () =>\n Array.from(registry.values()).map((v) => v.walletProvider),\n register: (args) => {\n const existingEntry = registry.get(args.walletProvider.key);\n\n if (existingEntry) {\n if (existingEntry.priority < args.priority) {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n } else {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProvider: args.walletProvider },\n event: 'walletProviderRegistered',\n },\n client\n );\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n },\n unregister: (key) => {\n registry.delete(key);\n\n emitEvent(\n {\n args: { walletProviderKey: key },\n event: 'walletProviderUnregistered',\n },\n client\n );\n },\n };\n};\n","import { createRuntimeServiceAccessKey } from '../../../../services/runtimeServices';\nimport { createWalletProviderRegistry } from '../createWalletProviderRegistry';\n\n/**\n * This function provides access to a shared instance of the wallet provider registry.\n *\n * It ensures that the same registry instance is used throughout the client to maintaining\n * consistency of registered wallet providers across different parts of the codebase.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * // Get the registry instance\n * const registry = getWalletProviderRegistry();\n *\n * // Register a wallet provider\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * // Retrieve a specific provider\n * const provider = registry.getByKey('metamaskevm');\n * ```\n */\nexport const getWalletProviderRegistry = createRuntimeServiceAccessKey(\n 'walletProviderRegistry',\n (client) => createWalletProviderRegistry(client)\n);\n","import type { WalletProvider } from '../walletProvider/walletProvider.types';\n\nexport enum WalletProviderPriority {\n /**\n * Highest priority should be used by wallet providers that implement\n * the most reliable wallet integration.\n * example: The SDK provided by the wallet provider.\n */\n WALLET_SDK = 100,\n /**\n * Medium priority should be used by wallet providers that implement\n * a wallet integration via some reliable standard.\n * example: A wallet provider that uses EIP6963 announcement.\n */\n WALLET_SELF_ANNOUNCEMENT_STANDARD = 50,\n /**\n * Low priority should be used by wallet providers that implement\n * a wallet integration on a less reliable standard.\n * example: A wallet provider that uses window.ethereum, where the\n * window key can be overridden by other extensions.\n */\n WINDOW_INJECT = 20,\n}\n\nexport type WalletProviderRegistry = {\n /**\n * Retrieves a wallet provider by its key.\n * @param key - The key of the wallet provider.\n * @returns The wallet provider.\n */\n getByKey: (key: string) => WalletProvider | undefined;\n /**\n * Retrieves all wallet providers.\n * @returns The wallet providers.\n */\n listProviders: () => WalletProvider[];\n /**\n * Registers a wallet provider.\n * @param args - The arguments for the wallet provider.\n */\n register: (args: {\n priority: WalletProviderPriority;\n walletProvider: WalletProvider;\n }) => void;\n /**\n * Unregisters a wallet provider.\n * @param key - The key of the wallet provider.\n */\n unregister: (key: string) => void;\n};\n","import type { DynamicClient } from '../../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../../errors/NoWalletProviderFoundError';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderRegistry } from '../../walletProviderRegistry';\n\ntype GetWalletProviderFromWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getWalletProviderFromWalletAccount = (\n { walletAccount }: GetWalletProviderFromWalletAccountParams,\n client: DynamicClient\n) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = walletProviderRegistry.getByKey(\n walletAccount.walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({\n walletProviderKey: walletAccount.walletProviderKey,\n });\n }\n\n return walletProvider;\n};\n","export const DYNAMIC_AUTH_COOKIE_NAME = 'DYNAMIC_JWT_TOKEN';\n","import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n */\nexport const emitWalletAccountsChangedEvent = (client: DynamicClient): void => {\n const walletAccounts = getWalletAccounts(client);\n\n emitEvent(\n {\n args: { walletAccounts },\n event: 'walletAccountsChanged',\n },\n client\n );\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { emitWalletAccountsChangedEvent } from '../../../wallets/emitWalletAccountsChangedEvent';\nimport { getWalletAccountsFromState } from '../../../wallets/getWalletAccounts/getWalletAccountsFromState';\n\ntype CheckAndRaiseWalletAccountsChangedEventParams = {\n previousState: Readonly<DynamicCoreState>;\n};\n\nexport const checkAndRaiseWalletAccountsChangedEvent = (\n { previousState }: CheckAndRaiseWalletAccountsChangedEventParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletAccountsHashBefore = getWalletAccountsHash(previousState, client);\n\n const walletAccountsHashAfter = getWalletAccountsHash(\n core.state.get(),\n client\n );\n\n if (walletAccountsHashBefore !== walletAccountsHashAfter) {\n emitWalletAccountsChangedEvent(client);\n }\n};\n\nconst getWalletAccountsHash = (\n state: Readonly<DynamicCoreState>,\n client: DynamicClient\n) =>\n getWalletAccountsFromState(state, client)\n .map((walletAccount) => JSON.stringify(walletAccount))\n .sort()\n .join('-');\n","import type { VerifyResponse } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../client/core/getCore';\nimport type { DynamicCoreState } from '../../../client/core/types';\nimport type { DynamicClient } from '../../../client/types';\nimport { setCookie } from '../../../utils/setCookie';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\nexport const updateAuthFromVerifyResponse = (\n { response }: UpdateAuthFromVerifyResponseParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const previousState = { ...core.state.get() };\n\n const { user, minifiedJwt, jwt, expiresAt, mfaToken } = response;\n\n // Expires at is in seconds, so we need to convert it to milliseconds\n const sessionExpiresAt = new Date(expiresAt * 1000);\n\n const newState: Partial<DynamicCoreState> = {\n legacyToken: jwt ?? null,\n sessionExpiresAt: sessionExpiresAt,\n token: minifiedJwt ?? null,\n user,\n };\n\n // only override the mfaToken if a new one is provided in the response\n if (mfaToken) {\n newState.mfaToken = mfaToken;\n }\n\n core.state.set(newState);\n\n /**\n * For customers using a sandbox environment with cookies enabled, we need to set the cookie\n * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically\n * so customers can access the cookie from document.cookie consistently between sandbox and live environments.\n */\n if (minifiedJwt && isCookieEnabled(client)) {\n const expireDate = sessionExpiresAt.toUTCString();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`\n );\n }\n\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getWalletProviderRegistry } from '../walletProviderRegistry';\n\n/**\n * Get all available wallet providers to interact with internally.\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n"],"mappings":";;;;;;;;AAGA,MAAa,aAAa,WAAmB;AAE3C,UAAS,SAAS;;;;;;;;;;;;;;;;ACiBpB,MAAa,WACX,EAAE,OAAO,YACT,SAASA,oCAAkB,KACxB;CACH,MAAM,EAAE,iBAAiBC,0BAAQ,OAAO;AAExC,cAAa,GAAG,OAAO,SAAS;AAEhC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,YACX,EAAE,OAAO,YACT,SAASD,oCAAkB,KACxB;CACH,MAAM,EAAE,iBAAiBC,0BAAQ,OAAO;AAExC,cAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcnC,MAAa,aACX,EAAE,OAAO,YACT,SAASD,oCAAkB,KACxB;CACH,MAAM,EAAE,iBAAiBC,0BAAQ,OAAO;AAExC,cAAa,KAAK,OAAO,SAAS;AAElC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,aACX,EAAE,OAAO,QACT,WACG;CAC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A2B,OAAO,OAAO,CACtC,KAAK,kBAAkB,KAAK,UAAU,cAAc,CAAC,CACrD,MAAM,CACN,KAAK,IAAI;;;;ACpBd,MAAa,gCACX,EAAE,YACF,WACG;CACH,MAAM,OAAOC,0BAAQ,OAAO;CAE5B,MAAM,gBAAgB,EAAE,GAAG,KAAK,MAAM,KAAK,EAAE;CAE7C,MAAM,EAAE,MAAM,aAAa,KAAK,WAAW,aAAa;CAGxD,MAAM,mCAAmB,IAAI,KAAK,YAAY,IAAK;CAEnD,MAAMC,WAAsC;EAC1C,aAAa,OAAO;EACF;EAClB,OAAO,eAAe;EACtB;EACD;AAGD,KAAI,SACF,UAAS,WAAW;AAGtB,MAAK,MAAM,IAAI,SAAS;;;;;;AAOxB,KAAI,eAAeC,kCAAgB,OAAO,CAGxC,WACE,GAAG,yBAAyB,GAAG,YAAY,YAH1B,iBAAiB,aAAa,CAGmB,wBACnE;AAGH,yCAAwC,EAAE,eAAe,EAAE,OAAO;;;;;;;;AChDpE,MAAa,sBAAsB,WAA0B;AAG3D,QAF+B,0BAA0B,OAAO,CAElC,eAAe;;;;;ACD/C,MAAa,0BACX,EAAE,qBACF,WACG;CAGH,MAAM,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBC,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO;;;;;ACfT,MAAa,yCACX,EAAE,iBACF,WACG;AACH,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as BaseError, b as getDefaultClient, h as assertDefined, m as isCookieEnabled, r as getChainFromVerifiedCredentialChain, w as getCore } from "./constants-
|
|
1
|
+
import { C as BaseError, b as getDefaultClient, h as assertDefined, m as isCookieEnabled, r as getChainFromVerifiedCredentialChain, w as getCore } from "./constants-DQfjH5fu.esm.js";
|
|
2
2
|
import { JwtVerifiedCredentialFormatEnum, WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/setCookie/setCookie.ts
|
|
@@ -478,4 +478,4 @@ const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client) => {
|
|
|
478
478
|
|
|
479
479
|
//#endregion
|
|
480
480
|
export { onceEvent as C, onEvent as S, normalizeAddress as _, checkAndRaiseWalletAccountsChangedEvent as a, emitEvent as b, getWalletProviderFromWalletAccount as c, createRuntimeServiceAccessKey as d, NoWalletProviderFoundError as f, formatWalletAccountId as g, normalizeWalletNameWithChain as h, updateAuthFromVerifyResponse as i, WalletProviderPriority as l, formatWalletProviderKey as m, getWalletProviderByKey as n, emitWalletAccountsChangedEvent as o, getWalletAccounts as p, getWalletProviders as r, DYNAMIC_AUTH_COOKIE_NAME as s, getVerifiedCredentialForWalletAccount as t, getWalletProviderRegistry as u, splitWalletProviderKey as v, setCookie as w, offEvent as x, InvalidWalletProviderKeyError as y };
|
|
481
|
-
//# sourceMappingURL=getVerifiedCredentialForWalletAccount-
|
|
481
|
+
//# sourceMappingURL=getVerifiedCredentialForWalletAccount-cVOVjcUI.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVerifiedCredentialForWalletAccount-Bh27tpbm.esm.js","names":["walletAccountsMap: Map<string, WalletAccount>","newState: Partial<DynamicCoreState>","walletProvider"],"sources":["../src/utils/setCookie/setCookie.ts","../src/modules/clientEvents/clientEvents.ts","../src/errors/InvalidWalletProviderKeyError.ts","../src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts","../src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts","../src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts","../src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts","../src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts","../src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts","../src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts","../src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts","../src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts","../src/modules/wallets/getWalletAccounts/getWalletAccounts.ts","../src/errors/NoWalletProviderFoundError.ts","../src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts","../src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts","../src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts","../src/modules/auth/consts.ts","../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["/**\n * Sefelly sets the cookie in the browser.\n */\nexport const setCookie = (cookie: string) => {\n // eslint-disable-next-line no-restricted-globals\n document.cookie = cookie;\n};\n","import { getCore } from '../../client/core/getCore';\nimport { getDefaultClient } from '../../client/defaultClient';\nimport type { DynamicClient } from '../../client/types';\nimport type {\n DynamicEvents,\n EmitEventParams,\n OffEventParams,\n OnEventParams,\n OnceEventParams,\n} from './clientEvents.types';\n\n/**\n * Adds an event listener for Dynamic client events.\n *\n * This function allows you to listen for various events emitted by the Dynamic client,\n * such as authentication state changes, wallet connections, and more.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener.\n */\nexport const onEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.on(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Removes an event listener from Dynamic client events.\n *\n * This function unsubscribes a previously registered event listener\n * from the specified Dynamic client event.\n *\n * @param params.event - The event name to remove the listener from.\n * @param params.listener - The callback function to remove.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const offEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OffEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.off(event, listener);\n};\n\n/**\n * Adds a one-time event listener for Dynamic client events.\n *\n * This function listens for an event that will automatically remove itself\n * after being triggered once.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener before it fires.\n */\nexport const onceEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnceEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.once(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Emits a Dynamic client event.\n *\n * This function triggers an event that will be received by all registered\n * listeners for the specified event type.\n *\n * @param params.event - The event name to emit.\n * @param params.args - The arguments to pass to event listeners.\n * @param client - The Dynamic client instance.\n */\nexport const emitEvent = <E extends keyof DynamicEvents>(\n { event, args }: EmitEventParams<E>,\n client: DynamicClient\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.emit(event, args);\n};\n","import { BaseError } from './base';\n\nexport class InvalidWalletProviderKeyError extends BaseError {\n constructor(value: string) {\n super({\n cause: null,\n code: 'invalid_wallet_provider_key',\n docsUrl: null,\n name: 'InvalidWalletProviderKeyError',\n shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`,\n });\n }\n}\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { InvalidWalletProviderKeyError } from '../../../../errors/InvalidWalletProviderKeyError';\n\ntype SplitWalletProviderKeyResult = {\n normalizedWalletNameWithChain: string;\n suffix: string | undefined;\n walletProviderType: WalletProviderEnum;\n};\n\nexport const splitWalletProviderKey = (\n walletProviderKey: string\n): SplitWalletProviderKeyResult => {\n const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] =\n walletProviderKey.split(':');\n\n if (\n !normalizedWalletNameWithChain ||\n !Object.values(WalletProviderEnum).includes(\n walletProviderType as WalletProviderEnum\n ) ||\n rest.length > 0\n ) {\n throw new InvalidWalletProviderKeyError(walletProviderKey);\n }\n\n return {\n normalizedWalletNameWithChain,\n suffix,\n walletProviderType: walletProviderType as WalletProviderEnum,\n };\n};\n","import type { Chain } from '../../../chain';\n\nexport const normalizeAddress = (address: string, chain: Chain) => {\n let normalizedAddress = address;\n\n if (normalizedAddress?.startsWith('0x')) {\n normalizedAddress = normalizedAddress.slice(2);\n }\n\n /**\n * These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md\n * see also: https://github.com/ChainAgnostic/namespaces\n * note: no standard namespace currently exists for flow\n */\n const chainsThatRequireLowercaseAddress: Chain[] = ['EVM', 'FLOW'];\n\n normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain)\n ? normalizedAddress?.toLowerCase()\n : normalizedAddress;\n\n return normalizedAddress;\n};\n","import type { Chain } from '../../../chain';\nimport { splitWalletProviderKey } from '../../walletProvider/splitWalletProviderKey';\nimport { normalizeAddress } from '../normalizeAddress';\n\ntype CreateWalletAccountIdParams = {\n address: string;\n chain: Chain;\n walletProviderKey: string;\n};\n\nexport const formatWalletAccountId = ({\n address,\n chain,\n walletProviderKey,\n}: CreateWalletAccountIdParams): string => {\n const { normalizedWalletNameWithChain } =\n splitWalletProviderKey(walletProviderKey);\n\n const normalizedAddress = normalizeAddress(address, chain);\n\n return `${normalizedWalletNameWithChain}:${normalizedAddress}`;\n};\n","import type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport type { WalletAccount } from '../../walletAccount';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertUnverifiedWalletAccountToWalletAccountParams = {\n unverifiedWalletAccount: UnverifiedWalletAccount;\n};\n\nexport const convertUnverifiedWalletAccountToWalletAccount = ({\n unverifiedWalletAccount,\n}: ConvertUnverifiedWalletAccountToWalletAccountParams): WalletAccount => ({\n address: unverifiedWalletAccount.address,\n addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,\n chain: unverifiedWalletAccount.chain,\n id: formatWalletAccountId({\n address: unverifiedWalletAccount.address,\n chain: unverifiedWalletAccount.chain,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n }),\n lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,\n verifiedCredentialId: null,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n});\n","import type { Chain } from '../../../chain';\n\ntype NormalizeWalletNameWithChainParams = {\n chain: Chain;\n displayName: string;\n};\n\n/**\n * Format the raw wallet name and chain to get the value we can use for\n * verified credentials' `walletName` field.\n */\nexport const normalizeWalletNameWithChain = ({\n displayName,\n chain,\n}: NormalizeWalletNameWithChainParams): string => {\n const sanitizedWalletName = displayName\n .replace(/[^a-zA-Z0-9]/g, '')\n .toLowerCase();\n\n const chainLowered = chain.toLocaleLowerCase();\n\n if (sanitizedWalletName.endsWith(chainLowered)) {\n return sanitizedWalletName;\n }\n\n return `${sanitizedWalletName}${chainLowered}`;\n};\n","import type { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { Chain } from '../../../chain';\nimport { normalizeWalletNameWithChain } from '../normalizeWalletNameWithChain';\n\ntype FormatWalletProviderKeyParams = {\n chain: Chain;\n displayName: string;\n suffix?: string;\n walletProviderType: WalletProviderEnum;\n};\n\n/**\n * Assembles the wallet provider key from the wallet name, chain, and wallet provider type.\n *\n * The suffix is optional and can be used to add a uniquely identifying string to the key, which\n * might be necessary for some wallet providers (like Wallet Connect).\n *\n * IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account\n * to not be able to find its wallet provider when connecting to a new device (it won't be possible\n * to determine the full key just from the Verified Credential data).\n */\nexport const formatWalletProviderKey = ({\n suffix,\n chain,\n displayName,\n walletProviderType,\n}: FormatWalletProviderKeyParams) => {\n const normalizedNameWithChain = normalizeWalletNameWithChain({\n chain,\n displayName,\n });\n\n return `${normalizedNameWithChain}:${walletProviderType}${\n suffix ? `:${suffix}` : ''\n }`;\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../../client/types';\nimport { assertDefined } from '../../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../../utils/getChainFromVerifiedCredentialChain';\nimport { formatWalletProviderKey } from '../../../utils/formatWalletProviderKey';\n\ntype GetWalletProviderKeyFromVerifiedCredentialParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const getWalletProviderKeyFromVerifiedCredential = (\n { verifiedCredential }: GetWalletProviderKeyFromVerifiedCredentialParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const { walletProviderKeyMap } = core.state.get();\n\n const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];\n\n if (storedWalletProviderKey) {\n return { walletProviderKey: storedWalletProviderKey };\n }\n\n /**\n * We fallback to comprising the wallet provider key from walletName and walletProvider.\n *\n * Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider\n * keys, so this won't be enough for them.\n * Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider\n * and will require reconnection.\n * Read walletProvider.types.ts for more info.\n */\n assertDefined(\n verifiedCredential.walletName,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`\n );\n\n assertDefined(\n verifiedCredential.walletProvider,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`\n );\n\n assertDefined(\n verifiedCredential.chain,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`\n );\n\n /**\n * Historically, walletNames did not include the chain name as a suffix.\n * This piece of logic simply ensures we normalize any legacy walletNames to conform.\n */\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const walletProviderKey = formatWalletProviderKey({\n chain,\n displayName: verifiedCredential.walletName,\n walletProviderType: verifiedCredential.walletProvider,\n });\n\n return { walletProviderKey };\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport { assertDefined } from '../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../utils/getChainFromVerifiedCredentialChain';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderKeyFromVerifiedCredential } from '../../walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertVerifiedCredentialToWalletAccountParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const convertVerifiedCredentialToWalletAccount = (\n { verifiedCredential }: ConvertVerifiedCredentialToWalletAccountParams,\n client: DynamicClient\n): WalletAccount => {\n assertDefined(\n verifiedCredential.address,\n 'Missing address in verified credential'\n );\n assertDefined(\n verifiedCredential.chain,\n 'Missing chain in verified credential'\n );\n\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential(\n {\n verifiedCredential,\n },\n client\n );\n\n const walletAccountId = formatWalletAccountId({\n address: verifiedCredential.address,\n chain,\n walletProviderKey,\n });\n\n return {\n address: verifiedCredential.address,\n addressesWithTypes: verifiedCredential.walletAdditionalAddresses,\n chain,\n id: walletAccountId,\n lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,\n verifiedCredentialId: verifiedCredential.id,\n walletProviderKey,\n };\n};\n","import type { SdkUser } from '@dynamic-labs/sdk-api-core';\nimport { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport { convertUnverifiedWalletAccountToWalletAccount } from '../../utils/convertUnverifiedWalletAccountToWalletAccount';\nimport { convertVerifiedCredentialToWalletAccount } from '../../utils/convertVerifiedCredentialToWalletAccount';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetWalletAccountsFromStateParams = {\n unverifiedWalletAccounts: UnverifiedWalletAccount[];\n user: SdkUser | null;\n};\n\nexport const getWalletAccountsFromState = (\n { unverifiedWalletAccounts, user }: GetWalletAccountsFromStateParams,\n client: DynamicClient\n): WalletAccount[] => {\n const walletAccountsMap: Map<string, WalletAccount> = new Map();\n\n /**\n * Handle the unverified wallet accounts before the user verified credentials\n * so the later verified wallet accounts can override the unverified wallet accounts\n */\n unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {\n const walletAccount = convertUnverifiedWalletAccountToWalletAccount({\n unverifiedWalletAccount,\n });\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n /**\n * Handle user verified credentials\n */\n const verifiedCredentials = user?.verifiedCredentials ?? [];\n\n verifiedCredentials\n .filter(\n (verified) =>\n verified.format === JwtVerifiedCredentialFormatEnum.Blockchain\n )\n .forEach((verifiedWalletAccount) => {\n const walletAccount = convertVerifiedCredentialToWalletAccount(\n {\n verifiedCredential: verifiedWalletAccount,\n },\n client\n );\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n return Array.from(walletAccountsMap.values());\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport type { WalletAccount } from '../walletAccount';\nimport { getWalletAccountsFromState } from './getWalletAccountsFromState';\n\n/**\n * Retrieves all wallet accounts associated with the current session.\n *\n * This function returns both verified and unverified wallet accounts,\n * combining data from user credentials and local unverified accounts.\n * You can differentiate between verified and unverified wallet accounts by\n * checking the `verifiedCredentialId` property.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An array of wallet accounts associated with the session.\n */\nexport const getWalletAccounts = (\n client = getDefaultClient()\n): WalletAccount[] => {\n const core = getCore(client);\n const { unverifiedWalletAccounts, user } = core.state.get();\n\n return getWalletAccountsFromState({ unverifiedWalletAccounts, user }, client);\n};\n","import { BaseError } from './base';\n\ntype NoWalletProviderFoundErrorParams = {\n walletProviderKey: string;\n};\n\nexport class NoWalletProviderFoundError extends BaseError {\n constructor({ walletProviderKey }: NoWalletProviderFoundErrorParams) {\n super({\n cause: null,\n code: 'no_wallet_provider_found_error',\n docsUrl: null,\n name: 'NoWalletProviderFoundError',\n shortMessage: `No wallet provider found with key: ${walletProviderKey}`,\n });\n }\n}\n","import type { DynamicClient } from '../../../client/types/DynamicClient';\nimport { getCore } from '../../../client/core/getCore';\n\n/**\n * Creates a service accessor function that manages service instantiation and caching.\n * The returned function will either retrieve an existing service from the registry or\n * create a new one using the provided builder function.\n *\n * @template - The type of service to be created/accessed\n * @param key - Unique identifier for the service in the registry\n * @param builder - Function that creates the service instance when called with a DynamicClient\n */\nexport const createRuntimeServiceAccessKey =\n <T>(key: string, builder: (client: DynamicClient) => T) =>\n (client: DynamicClient): T => {\n const { runtimeServices } = getCore(client);\n\n const currentService = runtimeServices.getByKey<T>(key);\n\n if (currentService) {\n return currentService;\n }\n\n const service = builder(client);\n\n runtimeServices.register(key, service);\n\n return service;\n };\n","import type { DynamicClient } from '../../../../client/types';\nimport { emitEvent } from '../../../clientEvents';\nimport type { WalletProvider } from '../../walletProvider/walletProvider.types';\nimport type { WalletProviderRegistry } from '../walletProviderRegistry.types';\n\n/**\n * Creates a new wallet provider registry that manages wallet providers with priority-based registration.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * const registry = createWalletProviderRegistry();\n *\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * const provider = registry.getByKey('my-wallet-key');\n * const providers = registry.listProviders();\n * ```\n */\nexport const createWalletProviderRegistry = (\n client: DynamicClient\n): WalletProviderRegistry => {\n const registry = new Map<\n string,\n { priority: number; walletProvider: WalletProvider }\n >();\n\n return {\n getByKey: (key) => registry.get(key)?.walletProvider,\n listProviders: () =>\n Array.from(registry.values()).map((v) => v.walletProvider),\n register: (args) => {\n const existingEntry = registry.get(args.walletProvider.key);\n\n if (existingEntry) {\n if (existingEntry.priority < args.priority) {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n } else {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProvider: args.walletProvider },\n event: 'walletProviderRegistered',\n },\n client\n );\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n },\n unregister: (key) => {\n registry.delete(key);\n\n emitEvent(\n {\n args: { walletProviderKey: key },\n event: 'walletProviderUnregistered',\n },\n client\n );\n },\n };\n};\n","import { createRuntimeServiceAccessKey } from '../../../../services/runtimeServices';\nimport { createWalletProviderRegistry } from '../createWalletProviderRegistry';\n\n/**\n * This function provides access to a shared instance of the wallet provider registry.\n *\n * It ensures that the same registry instance is used throughout the client to maintaining\n * consistency of registered wallet providers across different parts of the codebase.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * // Get the registry instance\n * const registry = getWalletProviderRegistry();\n *\n * // Register a wallet provider\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * // Retrieve a specific provider\n * const provider = registry.getByKey('metamaskevm');\n * ```\n */\nexport const getWalletProviderRegistry = createRuntimeServiceAccessKey(\n 'walletProviderRegistry',\n (client) => createWalletProviderRegistry(client)\n);\n","import type { WalletProvider } from '../walletProvider/walletProvider.types';\n\nexport enum WalletProviderPriority {\n /**\n * Highest priority should be used by wallet providers that implement\n * the most reliable wallet integration.\n * example: The SDK provided by the wallet provider.\n */\n WALLET_SDK = 100,\n /**\n * Medium priority should be used by wallet providers that implement\n * a wallet integration via some reliable standard.\n * example: A wallet provider that uses EIP6963 announcement.\n */\n WALLET_SELF_ANNOUNCEMENT_STANDARD = 50,\n /**\n * Low priority should be used by wallet providers that implement\n * a wallet integration on a less reliable standard.\n * example: A wallet provider that uses window.ethereum, where the\n * window key can be overridden by other extensions.\n */\n WINDOW_INJECT = 20,\n}\n\nexport type WalletProviderRegistry = {\n /**\n * Retrieves a wallet provider by its key.\n * @param key - The key of the wallet provider.\n * @returns The wallet provider.\n */\n getByKey: (key: string) => WalletProvider | undefined;\n /**\n * Retrieves all wallet providers.\n * @returns The wallet providers.\n */\n listProviders: () => WalletProvider[];\n /**\n * Registers a wallet provider.\n * @param args - The arguments for the wallet provider.\n */\n register: (args: {\n priority: WalletProviderPriority;\n walletProvider: WalletProvider;\n }) => void;\n /**\n * Unregisters a wallet provider.\n * @param key - The key of the wallet provider.\n */\n unregister: (key: string) => void;\n};\n","import type { DynamicClient } from '../../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../../errors/NoWalletProviderFoundError';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderRegistry } from '../../walletProviderRegistry';\n\ntype GetWalletProviderFromWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getWalletProviderFromWalletAccount = (\n { walletAccount }: GetWalletProviderFromWalletAccountParams,\n client: DynamicClient\n) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = walletProviderRegistry.getByKey(\n walletAccount.walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({\n walletProviderKey: walletAccount.walletProviderKey,\n });\n }\n\n return walletProvider;\n};\n","export const DYNAMIC_AUTH_COOKIE_NAME = 'DYNAMIC_JWT_TOKEN';\n","import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n */\nexport const emitWalletAccountsChangedEvent = (client: DynamicClient): void => {\n const walletAccounts = getWalletAccounts(client);\n\n emitEvent(\n {\n args: { walletAccounts },\n event: 'walletAccountsChanged',\n },\n client\n );\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { emitWalletAccountsChangedEvent } from '../../../wallets/emitWalletAccountsChangedEvent';\nimport { getWalletAccountsFromState } from '../../../wallets/getWalletAccounts/getWalletAccountsFromState';\n\ntype CheckAndRaiseWalletAccountsChangedEventParams = {\n previousState: Readonly<DynamicCoreState>;\n};\n\nexport const checkAndRaiseWalletAccountsChangedEvent = (\n { previousState }: CheckAndRaiseWalletAccountsChangedEventParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletAccountsHashBefore = getWalletAccountsHash(previousState, client);\n\n const walletAccountsHashAfter = getWalletAccountsHash(\n core.state.get(),\n client\n );\n\n if (walletAccountsHashBefore !== walletAccountsHashAfter) {\n emitWalletAccountsChangedEvent(client);\n }\n};\n\nconst getWalletAccountsHash = (\n state: Readonly<DynamicCoreState>,\n client: DynamicClient\n) =>\n getWalletAccountsFromState(state, client)\n .map((walletAccount) => JSON.stringify(walletAccount))\n .sort()\n .join('-');\n","import type { VerifyResponse } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../client/core/getCore';\nimport type { DynamicCoreState } from '../../../client/core/types';\nimport type { DynamicClient } from '../../../client/types';\nimport { setCookie } from '../../../utils/setCookie';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\nexport const updateAuthFromVerifyResponse = (\n { response }: UpdateAuthFromVerifyResponseParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const previousState = { ...core.state.get() };\n\n const { user, minifiedJwt, jwt, expiresAt, mfaToken } = response;\n\n // Expires at is in seconds, so we need to convert it to milliseconds\n const sessionExpiresAt = new Date(expiresAt * 1000);\n\n const newState: Partial<DynamicCoreState> = {\n legacyToken: jwt ?? null,\n sessionExpiresAt: sessionExpiresAt,\n token: minifiedJwt ?? null,\n user,\n };\n\n // only override the mfaToken if a new one is provided in the response\n if (mfaToken) {\n newState.mfaToken = mfaToken;\n }\n\n core.state.set(newState);\n\n /**\n * For customers using a sandbox environment with cookies enabled, we need to set the cookie\n * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically\n * so customers can access the cookie from document.cookie consistently between sandbox and live environments.\n */\n if (minifiedJwt && isCookieEnabled(client)) {\n const expireDate = sessionExpiresAt.toUTCString();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`\n );\n }\n\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getWalletProviderRegistry } from '../walletProviderRegistry';\n\n/**\n * Get all available wallet providers to interact with internally.\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n"],"mappings":";;;;;;;AAGA,MAAa,aAAa,WAAmB;AAE3C,UAAS,SAAS;;;;;;;;;;;;;;;;ACiBpB,MAAa,WACX,EAAE,OAAO,YACT,SAAS,kBAAkB,KACxB;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,GAAG,OAAO,SAAS;AAEhC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,YACX,EAAE,OAAO,YACT,SAAS,kBAAkB,KACxB;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcnC,MAAa,aACX,EAAE,OAAO,YACT,SAAS,kBAAkB,KACxB;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,KAAK,OAAO,SAAS;AAElC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,aACX,EAAE,OAAO,QACT,WACG;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,KAAK,OAAO,KAAK;;;;;AC5F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AAa,gCACX,EAAE,YACF,WACG;CACH,MAAM,OAAO,QAAQ,OAAO;CAE5B,MAAM,gBAAgB,EAAE,GAAG,KAAK,MAAM,KAAK,EAAE;CAE7C,MAAM,EAAE,MAAM,aAAa,KAAK,WAAW,aAAa;CAGxD,MAAM,mCAAmB,IAAI,KAAK,YAAY,IAAK;CAEnD,MAAMC,WAAsC;EAC1C,aAAa,OAAO;EACF;EAClB,OAAO,eAAe;EACtB;EACD;AAGD,KAAI,SACF,UAAS,WAAW;AAGtB,MAAK,MAAM,IAAI,SAAS;;;;;;AAOxB,KAAI,eAAe,gBAAgB,OAAO,CAGxC,WACE,GAAG,yBAAyB,GAAG,YAAY,YAH1B,iBAAiB,aAAa,CAGmB,wBACnE;AAGH,yCAAwC,EAAE,eAAe,EAAE,OAAO;;;;;;;;AChDpE,MAAa,sBAAsB,WAA0B;AAG3D,QAF+B,0BAA0B,OAAO,CAElC,eAAe;;;;;ACD/C,MAAa,0BACX,EAAE,qBACF,WACG;CAGH,MAAM,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBC,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO;;;;;ACfT,MAAa,yCACX,EAAE,iBACF,WACG;AACH,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC"}
|
|
1
|
+
{"version":3,"file":"getVerifiedCredentialForWalletAccount-cVOVjcUI.esm.js","names":["walletAccountsMap: Map<string, WalletAccount>","newState: Partial<DynamicCoreState>","walletProvider"],"sources":["../src/utils/setCookie/setCookie.ts","../src/modules/clientEvents/clientEvents.ts","../src/errors/InvalidWalletProviderKeyError.ts","../src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts","../src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts","../src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts","../src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts","../src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts","../src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts","../src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts","../src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts","../src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts","../src/modules/wallets/getWalletAccounts/getWalletAccounts.ts","../src/errors/NoWalletProviderFoundError.ts","../src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts","../src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts","../src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts","../src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts","../src/modules/auth/consts.ts","../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["/**\n * Sefelly sets the cookie in the browser.\n */\nexport const setCookie = (cookie: string) => {\n // eslint-disable-next-line no-restricted-globals\n document.cookie = cookie;\n};\n","import { getCore } from '../../client/core/getCore';\nimport { getDefaultClient } from '../../client/defaultClient';\nimport type { DynamicClient } from '../../client/types';\nimport type {\n DynamicEvents,\n EmitEventParams,\n OffEventParams,\n OnEventParams,\n OnceEventParams,\n} from './clientEvents.types';\n\n/**\n * Adds an event listener for Dynamic client events.\n *\n * This function allows you to listen for various events emitted by the Dynamic client,\n * such as authentication state changes, wallet connections, and more.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener.\n */\nexport const onEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.on(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Removes an event listener from Dynamic client events.\n *\n * This function unsubscribes a previously registered event listener\n * from the specified Dynamic client event.\n *\n * @param params.event - The event name to remove the listener from.\n * @param params.listener - The callback function to remove.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const offEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OffEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.off(event, listener);\n};\n\n/**\n * Adds a one-time event listener for Dynamic client events.\n *\n * This function listens for an event that will automatically remove itself\n * after being triggered once.\n *\n * @param params.event - The event name to listen for.\n * @param params.listener - The callback function to execute when the event is fired.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A function that can be called to remove the listener before it fires.\n */\nexport const onceEvent = <E extends keyof DynamicEvents>(\n { event, listener }: OnceEventParams<E>,\n client = getDefaultClient()\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.once(event, listener);\n\n return () => {\n eventEmitter.off(event, listener);\n };\n};\n\n/**\n * Emits a Dynamic client event.\n *\n * This function triggers an event that will be received by all registered\n * listeners for the specified event type.\n *\n * @param params.event - The event name to emit.\n * @param params.args - The arguments to pass to event listeners.\n * @param client - The Dynamic client instance.\n */\nexport const emitEvent = <E extends keyof DynamicEvents>(\n { event, args }: EmitEventParams<E>,\n client: DynamicClient\n) => {\n const { eventEmitter } = getCore(client);\n\n eventEmitter.emit(event, args);\n};\n","import { BaseError } from './base';\n\nexport class InvalidWalletProviderKeyError extends BaseError {\n constructor(value: string) {\n super({\n cause: null,\n code: 'invalid_wallet_provider_key',\n docsUrl: null,\n name: 'InvalidWalletProviderKeyError',\n shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`,\n });\n }\n}\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { InvalidWalletProviderKeyError } from '../../../../errors/InvalidWalletProviderKeyError';\n\ntype SplitWalletProviderKeyResult = {\n normalizedWalletNameWithChain: string;\n suffix: string | undefined;\n walletProviderType: WalletProviderEnum;\n};\n\nexport const splitWalletProviderKey = (\n walletProviderKey: string\n): SplitWalletProviderKeyResult => {\n const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] =\n walletProviderKey.split(':');\n\n if (\n !normalizedWalletNameWithChain ||\n !Object.values(WalletProviderEnum).includes(\n walletProviderType as WalletProviderEnum\n ) ||\n rest.length > 0\n ) {\n throw new InvalidWalletProviderKeyError(walletProviderKey);\n }\n\n return {\n normalizedWalletNameWithChain,\n suffix,\n walletProviderType: walletProviderType as WalletProviderEnum,\n };\n};\n","import type { Chain } from '../../../chain';\n\nexport const normalizeAddress = (address: string, chain: Chain) => {\n let normalizedAddress = address;\n\n if (normalizedAddress?.startsWith('0x')) {\n normalizedAddress = normalizedAddress.slice(2);\n }\n\n /**\n * These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md\n * see also: https://github.com/ChainAgnostic/namespaces\n * note: no standard namespace currently exists for flow\n */\n const chainsThatRequireLowercaseAddress: Chain[] = ['EVM', 'FLOW'];\n\n normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain)\n ? normalizedAddress?.toLowerCase()\n : normalizedAddress;\n\n return normalizedAddress;\n};\n","import type { Chain } from '../../../chain';\nimport { splitWalletProviderKey } from '../../walletProvider/splitWalletProviderKey';\nimport { normalizeAddress } from '../normalizeAddress';\n\ntype CreateWalletAccountIdParams = {\n address: string;\n chain: Chain;\n walletProviderKey: string;\n};\n\nexport const formatWalletAccountId = ({\n address,\n chain,\n walletProviderKey,\n}: CreateWalletAccountIdParams): string => {\n const { normalizedWalletNameWithChain } =\n splitWalletProviderKey(walletProviderKey);\n\n const normalizedAddress = normalizeAddress(address, chain);\n\n return `${normalizedWalletNameWithChain}:${normalizedAddress}`;\n};\n","import type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport type { WalletAccount } from '../../walletAccount';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertUnverifiedWalletAccountToWalletAccountParams = {\n unverifiedWalletAccount: UnverifiedWalletAccount;\n};\n\nexport const convertUnverifiedWalletAccountToWalletAccount = ({\n unverifiedWalletAccount,\n}: ConvertUnverifiedWalletAccountToWalletAccountParams): WalletAccount => ({\n address: unverifiedWalletAccount.address,\n addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,\n chain: unverifiedWalletAccount.chain,\n id: formatWalletAccountId({\n address: unverifiedWalletAccount.address,\n chain: unverifiedWalletAccount.chain,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n }),\n lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,\n verifiedCredentialId: null,\n walletProviderKey: unverifiedWalletAccount.walletProviderKey,\n});\n","import type { Chain } from '../../../chain';\n\ntype NormalizeWalletNameWithChainParams = {\n chain: Chain;\n displayName: string;\n};\n\n/**\n * Format the raw wallet name and chain to get the value we can use for\n * verified credentials' `walletName` field.\n */\nexport const normalizeWalletNameWithChain = ({\n displayName,\n chain,\n}: NormalizeWalletNameWithChainParams): string => {\n const sanitizedWalletName = displayName\n .replace(/[^a-zA-Z0-9]/g, '')\n .toLowerCase();\n\n const chainLowered = chain.toLocaleLowerCase();\n\n if (sanitizedWalletName.endsWith(chainLowered)) {\n return sanitizedWalletName;\n }\n\n return `${sanitizedWalletName}${chainLowered}`;\n};\n","import type { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { Chain } from '../../../chain';\nimport { normalizeWalletNameWithChain } from '../normalizeWalletNameWithChain';\n\ntype FormatWalletProviderKeyParams = {\n chain: Chain;\n displayName: string;\n suffix?: string;\n walletProviderType: WalletProviderEnum;\n};\n\n/**\n * Assembles the wallet provider key from the wallet name, chain, and wallet provider type.\n *\n * The suffix is optional and can be used to add a uniquely identifying string to the key, which\n * might be necessary for some wallet providers (like Wallet Connect).\n *\n * IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account\n * to not be able to find its wallet provider when connecting to a new device (it won't be possible\n * to determine the full key just from the Verified Credential data).\n */\nexport const formatWalletProviderKey = ({\n suffix,\n chain,\n displayName,\n walletProviderType,\n}: FormatWalletProviderKeyParams) => {\n const normalizedNameWithChain = normalizeWalletNameWithChain({\n chain,\n displayName,\n });\n\n return `${normalizedNameWithChain}:${walletProviderType}${\n suffix ? `:${suffix}` : ''\n }`;\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../../client/types';\nimport { assertDefined } from '../../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../../utils/getChainFromVerifiedCredentialChain';\nimport { formatWalletProviderKey } from '../../../utils/formatWalletProviderKey';\n\ntype GetWalletProviderKeyFromVerifiedCredentialParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const getWalletProviderKeyFromVerifiedCredential = (\n { verifiedCredential }: GetWalletProviderKeyFromVerifiedCredentialParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const { walletProviderKeyMap } = core.state.get();\n\n const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];\n\n if (storedWalletProviderKey) {\n return { walletProviderKey: storedWalletProviderKey };\n }\n\n /**\n * We fallback to comprising the wallet provider key from walletName and walletProvider.\n *\n * Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider\n * keys, so this won't be enough for them.\n * Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider\n * and will require reconnection.\n * Read walletProvider.types.ts for more info.\n */\n assertDefined(\n verifiedCredential.walletName,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`\n );\n\n assertDefined(\n verifiedCredential.walletProvider,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`\n );\n\n assertDefined(\n verifiedCredential.chain,\n `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`\n );\n\n /**\n * Historically, walletNames did not include the chain name as a suffix.\n * This piece of logic simply ensures we normalize any legacy walletNames to conform.\n */\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const walletProviderKey = formatWalletProviderKey({\n chain,\n displayName: verifiedCredential.walletName,\n walletProviderType: verifiedCredential.walletProvider,\n });\n\n return { walletProviderKey };\n};\n","import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport { assertDefined } from '../../../../utils/assertDefined';\nimport { getChainFromVerifiedCredentialChain } from '../../../../utils/getChainFromVerifiedCredentialChain';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderKeyFromVerifiedCredential } from '../../walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential';\nimport { formatWalletAccountId } from '../formatWalletAccountId';\n\ntype ConvertVerifiedCredentialToWalletAccountParams = {\n verifiedCredential: JwtVerifiedCredential;\n};\n\nexport const convertVerifiedCredentialToWalletAccount = (\n { verifiedCredential }: ConvertVerifiedCredentialToWalletAccountParams,\n client: DynamicClient\n): WalletAccount => {\n assertDefined(\n verifiedCredential.address,\n 'Missing address in verified credential'\n );\n assertDefined(\n verifiedCredential.chain,\n 'Missing chain in verified credential'\n );\n\n const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);\n\n const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential(\n {\n verifiedCredential,\n },\n client\n );\n\n const walletAccountId = formatWalletAccountId({\n address: verifiedCredential.address,\n chain,\n walletProviderKey,\n });\n\n return {\n address: verifiedCredential.address,\n addressesWithTypes: verifiedCredential.walletAdditionalAddresses,\n chain,\n id: walletAccountId,\n lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,\n verifiedCredentialId: verifiedCredential.id,\n walletProviderKey,\n };\n};\n","import type { SdkUser } from '@dynamic-labs/sdk-api-core';\nimport { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../../client/types';\nimport type { UnverifiedWalletAccount } from '../../unverifiedWalletAccounts';\nimport { convertUnverifiedWalletAccountToWalletAccount } from '../../utils/convertUnverifiedWalletAccountToWalletAccount';\nimport { convertVerifiedCredentialToWalletAccount } from '../../utils/convertVerifiedCredentialToWalletAccount';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetWalletAccountsFromStateParams = {\n unverifiedWalletAccounts: UnverifiedWalletAccount[];\n user: SdkUser | null;\n};\n\nexport const getWalletAccountsFromState = (\n { unverifiedWalletAccounts, user }: GetWalletAccountsFromStateParams,\n client: DynamicClient\n): WalletAccount[] => {\n const walletAccountsMap: Map<string, WalletAccount> = new Map();\n\n /**\n * Handle the unverified wallet accounts before the user verified credentials\n * so the later verified wallet accounts can override the unverified wallet accounts\n */\n unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {\n const walletAccount = convertUnverifiedWalletAccountToWalletAccount({\n unverifiedWalletAccount,\n });\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n /**\n * Handle user verified credentials\n */\n const verifiedCredentials = user?.verifiedCredentials ?? [];\n\n verifiedCredentials\n .filter(\n (verified) =>\n verified.format === JwtVerifiedCredentialFormatEnum.Blockchain\n )\n .forEach((verifiedWalletAccount) => {\n const walletAccount = convertVerifiedCredentialToWalletAccount(\n {\n verifiedCredential: verifiedWalletAccount,\n },\n client\n );\n\n walletAccountsMap.set(walletAccount.id, walletAccount);\n });\n\n return Array.from(walletAccountsMap.values());\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport type { WalletAccount } from '../walletAccount';\nimport { getWalletAccountsFromState } from './getWalletAccountsFromState';\n\n/**\n * Retrieves all wallet accounts associated with the current session.\n *\n * This function returns both verified and unverified wallet accounts,\n * combining data from user credentials and local unverified accounts.\n * You can differentiate between verified and unverified wallet accounts by\n * checking the `verifiedCredentialId` property.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An array of wallet accounts associated with the session.\n */\nexport const getWalletAccounts = (\n client = getDefaultClient()\n): WalletAccount[] => {\n const core = getCore(client);\n const { unverifiedWalletAccounts, user } = core.state.get();\n\n return getWalletAccountsFromState({ unverifiedWalletAccounts, user }, client);\n};\n","import { BaseError } from './base';\n\ntype NoWalletProviderFoundErrorParams = {\n walletProviderKey: string;\n};\n\nexport class NoWalletProviderFoundError extends BaseError {\n constructor({ walletProviderKey }: NoWalletProviderFoundErrorParams) {\n super({\n cause: null,\n code: 'no_wallet_provider_found_error',\n docsUrl: null,\n name: 'NoWalletProviderFoundError',\n shortMessage: `No wallet provider found with key: ${walletProviderKey}`,\n });\n }\n}\n","import type { DynamicClient } from '../../../client/types/DynamicClient';\nimport { getCore } from '../../../client/core/getCore';\n\n/**\n * Creates a service accessor function that manages service instantiation and caching.\n * The returned function will either retrieve an existing service from the registry or\n * create a new one using the provided builder function.\n *\n * @template - The type of service to be created/accessed\n * @param key - Unique identifier for the service in the registry\n * @param builder - Function that creates the service instance when called with a DynamicClient\n */\nexport const createRuntimeServiceAccessKey =\n <T>(key: string, builder: (client: DynamicClient) => T) =>\n (client: DynamicClient): T => {\n const { runtimeServices } = getCore(client);\n\n const currentService = runtimeServices.getByKey<T>(key);\n\n if (currentService) {\n return currentService;\n }\n\n const service = builder(client);\n\n runtimeServices.register(key, service);\n\n return service;\n };\n","import type { DynamicClient } from '../../../../client/types';\nimport { emitEvent } from '../../../clientEvents';\nimport type { WalletProvider } from '../../walletProvider/walletProvider.types';\nimport type { WalletProviderRegistry } from '../walletProviderRegistry.types';\n\n/**\n * Creates a new wallet provider registry that manages wallet providers with priority-based registration.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * const registry = createWalletProviderRegistry();\n *\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * const provider = registry.getByKey('my-wallet-key');\n * const providers = registry.listProviders();\n * ```\n */\nexport const createWalletProviderRegistry = (\n client: DynamicClient\n): WalletProviderRegistry => {\n const registry = new Map<\n string,\n { priority: number; walletProvider: WalletProvider }\n >();\n\n return {\n getByKey: (key) => registry.get(key)?.walletProvider,\n listProviders: () =>\n Array.from(registry.values()).map((v) => v.walletProvider),\n register: (args) => {\n const existingEntry = registry.get(args.walletProvider.key);\n\n if (existingEntry) {\n if (existingEntry.priority < args.priority) {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n } else {\n registry.set(args.walletProvider.key, args);\n\n emitEvent(\n {\n args: { walletProvider: args.walletProvider },\n event: 'walletProviderRegistered',\n },\n client\n );\n\n emitEvent(\n {\n args: { walletProviderKey: args.walletProvider.key },\n event: 'walletProviderChanged',\n },\n client\n );\n }\n },\n unregister: (key) => {\n registry.delete(key);\n\n emitEvent(\n {\n args: { walletProviderKey: key },\n event: 'walletProviderUnregistered',\n },\n client\n );\n },\n };\n};\n","import { createRuntimeServiceAccessKey } from '../../../../services/runtimeServices';\nimport { createWalletProviderRegistry } from '../createWalletProviderRegistry';\n\n/**\n * This function provides access to a shared instance of the wallet provider registry.\n *\n * It ensures that the same registry instance is used throughout the client to maintaining\n * consistency of registered wallet providers across different parts of the codebase.\n *\n * @returns The wallet provider registry instance\n *\n * @example\n * ```typescript\n * // Get the registry instance\n * const registry = getWalletProviderRegistry();\n *\n * // Register a wallet provider\n * registry.register({\n * priority: WalletProviderPriority.WALLET_SDK,\n * walletProvider: myWalletProvider\n * });\n *\n * // Retrieve a specific provider\n * const provider = registry.getByKey('metamaskevm');\n * ```\n */\nexport const getWalletProviderRegistry = createRuntimeServiceAccessKey(\n 'walletProviderRegistry',\n (client) => createWalletProviderRegistry(client)\n);\n","import type { WalletProvider } from '../walletProvider/walletProvider.types';\n\nexport enum WalletProviderPriority {\n /**\n * Highest priority should be used by wallet providers that implement\n * the most reliable wallet integration.\n * example: The SDK provided by the wallet provider.\n */\n WALLET_SDK = 100,\n /**\n * Medium priority should be used by wallet providers that implement\n * a wallet integration via some reliable standard.\n * example: A wallet provider that uses EIP6963 announcement.\n */\n WALLET_SELF_ANNOUNCEMENT_STANDARD = 50,\n /**\n * Low priority should be used by wallet providers that implement\n * a wallet integration on a less reliable standard.\n * example: A wallet provider that uses window.ethereum, where the\n * window key can be overridden by other extensions.\n */\n WINDOW_INJECT = 20,\n}\n\nexport type WalletProviderRegistry = {\n /**\n * Retrieves a wallet provider by its key.\n * @param key - The key of the wallet provider.\n * @returns The wallet provider.\n */\n getByKey: (key: string) => WalletProvider | undefined;\n /**\n * Retrieves all wallet providers.\n * @returns The wallet providers.\n */\n listProviders: () => WalletProvider[];\n /**\n * Registers a wallet provider.\n * @param args - The arguments for the wallet provider.\n */\n register: (args: {\n priority: WalletProviderPriority;\n walletProvider: WalletProvider;\n }) => void;\n /**\n * Unregisters a wallet provider.\n * @param key - The key of the wallet provider.\n */\n unregister: (key: string) => void;\n};\n","import type { DynamicClient } from '../../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../../errors/NoWalletProviderFoundError';\nimport type { WalletAccount } from '../../walletAccount';\nimport { getWalletProviderRegistry } from '../../walletProviderRegistry';\n\ntype GetWalletProviderFromWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getWalletProviderFromWalletAccount = (\n { walletAccount }: GetWalletProviderFromWalletAccountParams,\n client: DynamicClient\n) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = walletProviderRegistry.getByKey(\n walletAccount.walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({\n walletProviderKey: walletAccount.walletProviderKey,\n });\n }\n\n return walletProvider;\n};\n","export const DYNAMIC_AUTH_COOKIE_NAME = 'DYNAMIC_JWT_TOKEN';\n","import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n */\nexport const emitWalletAccountsChangedEvent = (client: DynamicClient): void => {\n const walletAccounts = getWalletAccounts(client);\n\n emitEvent(\n {\n args: { walletAccounts },\n event: 'walletAccountsChanged',\n },\n client\n );\n};\n","import { getCore } from '../../../../client/core/getCore';\nimport type { DynamicClient } from '../../../../client/types';\nimport { emitWalletAccountsChangedEvent } from '../../../wallets/emitWalletAccountsChangedEvent';\nimport { getWalletAccountsFromState } from '../../../wallets/getWalletAccounts/getWalletAccountsFromState';\n\ntype CheckAndRaiseWalletAccountsChangedEventParams = {\n previousState: Readonly<DynamicCoreState>;\n};\n\nexport const checkAndRaiseWalletAccountsChangedEvent = (\n { previousState }: CheckAndRaiseWalletAccountsChangedEventParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const walletAccountsHashBefore = getWalletAccountsHash(previousState, client);\n\n const walletAccountsHashAfter = getWalletAccountsHash(\n core.state.get(),\n client\n );\n\n if (walletAccountsHashBefore !== walletAccountsHashAfter) {\n emitWalletAccountsChangedEvent(client);\n }\n};\n\nconst getWalletAccountsHash = (\n state: Readonly<DynamicCoreState>,\n client: DynamicClient\n) =>\n getWalletAccountsFromState(state, client)\n .map((walletAccount) => JSON.stringify(walletAccount))\n .sort()\n .join('-');\n","import type { VerifyResponse } from '@dynamic-labs/sdk-api-core';\n\nimport { getCore } from '../../../client/core/getCore';\nimport type { DynamicCoreState } from '../../../client/core/types';\nimport type { DynamicClient } from '../../../client/types';\nimport { setCookie } from '../../../utils/setCookie';\nimport { isCookieEnabled } from '../../projectSettings/isCookieEnabled';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\nexport const updateAuthFromVerifyResponse = (\n { response }: UpdateAuthFromVerifyResponseParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n const previousState = { ...core.state.get() };\n\n const { user, minifiedJwt, jwt, expiresAt, mfaToken } = response;\n\n // Expires at is in seconds, so we need to convert it to milliseconds\n const sessionExpiresAt = new Date(expiresAt * 1000);\n\n const newState: Partial<DynamicCoreState> = {\n legacyToken: jwt ?? null,\n sessionExpiresAt: sessionExpiresAt,\n token: minifiedJwt ?? null,\n user,\n };\n\n // only override the mfaToken if a new one is provided in the response\n if (mfaToken) {\n newState.mfaToken = mfaToken;\n }\n\n core.state.set(newState);\n\n /**\n * For customers using a sandbox environment with cookies enabled, we need to set the cookie\n * programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically\n * so customers can access the cookie from document.cookie consistently between sandbox and live environments.\n */\n if (minifiedJwt && isCookieEnabled(client)) {\n const expireDate = sessionExpiresAt.toUTCString();\n\n setCookie(\n `${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${expireDate}; path=/; SameSite=Lax`\n );\n }\n\n checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { getWalletProviderRegistry } from '../walletProviderRegistry';\n\n/**\n * Get all available wallet providers to interact with internally.\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { NoWalletProviderFoundError } from '../../../errors/NoWalletProviderFoundError';\nimport { getWalletProviders } from '../getWalletProviders';\n\ntype GetWalletProviderByKeyParams = {\n walletProviderKey: string;\n};\n\nexport const getWalletProviderByKey = (\n { walletProviderKey }: GetWalletProviderByKeyParams,\n client: DynamicClient\n) => {\n const walletProviders = getWalletProviders(client);\n\n const walletProvider = walletProviders.find(\n (walletProvider) => walletProvider.key === walletProviderKey\n );\n\n if (!walletProvider) {\n throw new NoWalletProviderFoundError({ walletProviderKey });\n }\n\n return walletProvider;\n};\n","import type { DynamicClient } from '../../../../client/types/DynamicClient';\nimport type { WalletAccount } from '../../walletAccount';\n\ntype GetVerifiedCredentialForWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\nexport const getVerifiedCredentialForWalletAccount = (\n { walletAccount }: GetVerifiedCredentialForWalletAccountParams,\n client: DynamicClient\n) => {\n return client.user?.verifiedCredentials.find(\n (vc) => vc.id === walletAccount.verifiedCredentialId\n );\n};\n"],"mappings":";;;;;;;AAGA,MAAa,aAAa,WAAmB;AAE3C,UAAS,SAAS;;;;;;;;;;;;;;;;ACiBpB,MAAa,WACX,EAAE,OAAO,YACT,SAAS,kBAAkB,KACxB;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,GAAG,OAAO,SAAS;AAEhC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcrC,MAAa,YACX,EAAE,OAAO,YACT,SAAS,kBAAkB,KACxB;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;AAcnC,MAAa,aACX,EAAE,OAAO,YACT,SAAS,kBAAkB,KACxB;CACH,MAAM,EAAE,iBAAiB,QAAQ,OAAO;AAExC,cAAa,KAAK,OAAO,SAAS;AAElC,cAAa;AACX,eAAa,IAAI,OAAO,SAAS;;;;;;;;;;;;;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,OACA,WAEA,2BAA2B,OAAO,OAAO,CACtC,KAAK,kBAAkB,KAAK,UAAU,cAAc,CAAC,CACrD,MAAM,CACN,KAAK,IAAI;;;;ACpBd,MAAa,gCACX,EAAE,YACF,WACG;CACH,MAAM,OAAO,QAAQ,OAAO;CAE5B,MAAM,gBAAgB,EAAE,GAAG,KAAK,MAAM,KAAK,EAAE;CAE7C,MAAM,EAAE,MAAM,aAAa,KAAK,WAAW,aAAa;CAGxD,MAAM,mCAAmB,IAAI,KAAK,YAAY,IAAK;CAEnD,MAAMC,WAAsC;EAC1C,aAAa,OAAO;EACF;EAClB,OAAO,eAAe;EACtB;EACD;AAGD,KAAI,SACF,UAAS,WAAW;AAGtB,MAAK,MAAM,IAAI,SAAS;;;;;;AAOxB,KAAI,eAAe,gBAAgB,OAAO,CAGxC,WACE,GAAG,yBAAyB,GAAG,YAAY,YAH1B,iBAAiB,aAAa,CAGmB,wBACnE;AAGH,yCAAwC,EAAE,eAAe,EAAE,OAAO;;;;;;;;AChDpE,MAAa,sBAAsB,WAA0B;AAG3D,QAF+B,0BAA0B,OAAO,CAElC,eAAe;;;;;ACD/C,MAAa,0BACX,EAAE,qBACF,WACG;CAGH,MAAM,iBAFkB,mBAAmB,OAAO,CAEX,MACpC,qBAAmBC,iBAAe,QAAQ,kBAC5C;AAED,KAAI,CAAC,eACH,OAAM,IAAI,2BAA2B,EAAE,mBAAmB,CAAC;AAG7D,QAAO;;;;;ACfT,MAAa,yCACX,EAAE,iBACF,WACG;AACH,QAAO,OAAO,MAAM,oBAAoB,MACrC,OAAO,GAAG,OAAO,cAAc,qBACjC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-
|
|
2
|
-
const require_constants = require('./constants-
|
|
3
|
-
const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-
|
|
4
|
-
const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-
|
|
5
|
-
const require_NotWaasWalletAccountError = require('./NotWaasWalletAccountError-
|
|
6
|
-
const require_InvalidParamError = require('./InvalidParamError-
|
|
1
|
+
const require_getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId-DKrjrs7X.cjs.js');
|
|
2
|
+
const require_constants = require('./constants-B3wr3A32.cjs.js');
|
|
3
|
+
const require_getVerifiedCredentialForWalletAccount = require('./getVerifiedCredentialForWalletAccount-CR5wGUFK.cjs.js');
|
|
4
|
+
const require_isMfaRequiredForAction = require('./isMfaRequiredForAction-Bwphi7AF.cjs.js');
|
|
5
|
+
const require_NotWaasWalletAccountError = require('./NotWaasWalletAccountError-zV4xv0h6.cjs.js');
|
|
6
|
+
const require_InvalidParamError = require('./InvalidParamError-DQv6ejTe.cjs.js');
|
|
7
7
|
let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
|
|
8
8
|
let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
|
|
9
9
|
let zod_mini = require("zod/mini");
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as BaseError, E as version, T as name, _ as randomString, a as createApiClient, b as getDefaultClient, c as MfaInvalidOtpError, d as APIError, g as ValueMustBeDefinedError, h as assertDefined, i as CHAINS_INFO_MAP, l as LinkCredentialError, m as isCookieEnabled, n as SDK_API_CORE_VERSION, o as SandboxMaximumThresholdReachedError, p as getBuffer, r as getChainFromVerifiedCredentialChain, s as MfaRateLimitedError, t as DYNAMIC_ICONIC_SPRITE_URL, u as InvalidExternalAuthError, v as CLIENT_SDK_NAME, w as getCore, x as setDefaultClient } from "./constants-
|
|
2
|
-
import { A as isEqualShallow, C as INITIALIZE_STORAGE_SYNC_TRACKER_KEY, E as createStorage, O as createLocalStorageAdapter, S as GENERATE_SESSION_KEYS_TRACKER_KEY, T as createStorageKeySchema, _ as NoNetworkProvidersError, a as updateWalletProviderKeysForVerifiedCredentials, b as createDeferredPromise, c as createSignInMessageStatement, d as createVisit, f as hasExtension, g as WalletAlreadyLinkedToAnotherUserError, h as isCaptchaRequired, i as getNetworksData, k as subscribeWithSelector, l as formatSignInMessage, m as consumeCaptchaToken, o as verifyMessageSignatureOwnership, p as setCaptchaToken, s as removeUnverifiedWalletAccount, t as getNetworkProviderFromNetworkId, u as setUnverifiedWalletAccounts, v as createLogger, w as REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY, x as FETCH_PROJECT_SETTINGS_TRACKER_KEY, y as CannotTrackError } from "./getNetworkProviderFromNetworkId-
|
|
3
|
-
import { C as onceEvent, S as onEvent, _ as normalizeAddress, a as checkAndRaiseWalletAccountsChangedEvent, b as emitEvent, c as getWalletProviderFromWalletAccount, f as NoWalletProviderFoundError, g as formatWalletAccountId, i as updateAuthFromVerifyResponse, n as getWalletProviderByKey, o as emitWalletAccountsChangedEvent, p as getWalletAccounts, r as getWalletProviders, s as DYNAMIC_AUTH_COOKIE_NAME, t as getVerifiedCredentialForWalletAccount, v as splitWalletProviderKey, w as setCookie, x as offEvent } from "./getVerifiedCredentialForWalletAccount-
|
|
4
|
-
import { i as bufferToHex, n as getMfaMethods, r as consumeMfaToken, t as isMfaRequiredForAction } from "./isMfaRequiredForAction-
|
|
5
|
-
import { n as refreshUser, t as NotWaasWalletAccountError } from "./NotWaasWalletAccountError-
|
|
6
|
-
import { t as InvalidParamError } from "./InvalidParamError-
|
|
1
|
+
import { C as BaseError, E as version, T as name, _ as randomString, a as createApiClient, b as getDefaultClient, c as MfaInvalidOtpError, d as APIError, g as ValueMustBeDefinedError, h as assertDefined, i as CHAINS_INFO_MAP, l as LinkCredentialError, m as isCookieEnabled, n as SDK_API_CORE_VERSION, o as SandboxMaximumThresholdReachedError, p as getBuffer, r as getChainFromVerifiedCredentialChain, s as MfaRateLimitedError, t as DYNAMIC_ICONIC_SPRITE_URL, u as InvalidExternalAuthError, v as CLIENT_SDK_NAME, w as getCore, x as setDefaultClient } from "./constants-DQfjH5fu.esm.js";
|
|
2
|
+
import { A as isEqualShallow, C as INITIALIZE_STORAGE_SYNC_TRACKER_KEY, E as createStorage, O as createLocalStorageAdapter, S as GENERATE_SESSION_KEYS_TRACKER_KEY, T as createStorageKeySchema, _ as NoNetworkProvidersError, a as updateWalletProviderKeysForVerifiedCredentials, b as createDeferredPromise, c as createSignInMessageStatement, d as createVisit, f as hasExtension, g as WalletAlreadyLinkedToAnotherUserError, h as isCaptchaRequired, i as getNetworksData, k as subscribeWithSelector, l as formatSignInMessage, m as consumeCaptchaToken, o as verifyMessageSignatureOwnership, p as setCaptchaToken, s as removeUnverifiedWalletAccount, t as getNetworkProviderFromNetworkId, u as setUnverifiedWalletAccounts, v as createLogger, w as REFRESH_USER_STATE_FROM_COOKIE_TRACKER_KEY, x as FETCH_PROJECT_SETTINGS_TRACKER_KEY, y as CannotTrackError } from "./getNetworkProviderFromNetworkId-Bccco0Dv.esm.js";
|
|
3
|
+
import { C as onceEvent, S as onEvent, _ as normalizeAddress, a as checkAndRaiseWalletAccountsChangedEvent, b as emitEvent, c as getWalletProviderFromWalletAccount, f as NoWalletProviderFoundError, g as formatWalletAccountId, i as updateAuthFromVerifyResponse, n as getWalletProviderByKey, o as emitWalletAccountsChangedEvent, p as getWalletAccounts, r as getWalletProviders, s as DYNAMIC_AUTH_COOKIE_NAME, t as getVerifiedCredentialForWalletAccount, v as splitWalletProviderKey, w as setCookie, x as offEvent } from "./getVerifiedCredentialForWalletAccount-cVOVjcUI.esm.js";
|
|
4
|
+
import { i as bufferToHex, n as getMfaMethods, r as consumeMfaToken, t as isMfaRequiredForAction } from "./isMfaRequiredForAction-YAISA589.esm.js";
|
|
5
|
+
import { n as refreshUser, t as NotWaasWalletAccountError } from "./NotWaasWalletAccountError-CbHIr6GK.esm.js";
|
|
6
|
+
import { t as InvalidParamError } from "./InvalidParamError-Cigi7zsS.esm.js";
|
|
7
7
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
8
8
|
import { AuthModeEnum, JwtVerifiedCredentialFormatEnum, MFAAction, MfaBackupCodeAcknowledgement, ProviderEnum } from "@dynamic-labs/sdk-api-core";
|
|
9
9
|
import * as z from "zod/mini";
|
package/dist/{isMfaRequiredForAction-CBvaJAqD.cjs.js → isMfaRequiredForAction-Bwphi7AF.cjs.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_constants = require('./constants-
|
|
1
|
+
const require_constants = require('./constants-B3wr3A32.cjs.js');
|
|
2
2
|
|
|
3
3
|
//#region src/utils/bufferToHex/bufferToHex.ts
|
|
4
4
|
/**
|
|
@@ -89,4 +89,4 @@ Object.defineProperty(exports, 'isMfaRequiredForAction', {
|
|
|
89
89
|
return isMfaRequiredForAction;
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
|
-
//# sourceMappingURL=isMfaRequiredForAction-
|
|
92
|
+
//# sourceMappingURL=isMfaRequiredForAction-Bwphi7AF.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isMfaRequiredForAction-
|
|
1
|
+
{"version":3,"file":"isMfaRequiredForAction-Bwphi7AF.cjs.js","names":["getDefaultClient","getCore","getDefaultClient","getCore","createApiClient","getDefaultClient"],"sources":["../src/utils/bufferToHex/bufferToHex.ts","../src/modules/mfa/consumeMfaToken/consumeMfaToken.ts","../src/modules/mfa/getMfaMethods/getMfaMethods.ts","../src/modules/mfa/isMfaRequiredForAction/isMfaRequiredForAction.ts"],"sourcesContent":["/**\n * Converts an ArrayBuffer to a hex-encoded string\n */\nexport const bufferToHex = (buffer: ArrayBufferLike) =>\n [...new Uint8Array(buffer)]\n .map((x) => x.toString(16).padStart(2, '0'))\n .join('');\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Consumes and clears the current MFA token from the client state.\n *\n * This function retrieves the MFA token obtained from a successful MFA authentication,\n * and removes it from the client, to prevent it from being used again.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The MFA token that was consumed.\n * @throws Error if no MFA token is found.\n */\nexport const consumeMfaToken = (client = getDefaultClient()) => {\n const core = getCore(client);\n\n const mfaToken = core.state.get().mfaToken;\n\n assertDefined(mfaToken, 'No MFA token found');\n\n core.state.set({\n mfaToken: null,\n });\n\n return mfaToken;\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { createApiClient } from '../../apiClient';\n\n/**\n * Retrieves the available MFA methods for the current user.\n *\n * This function fetches information about which multi-factor authentication\n * methods are available and configured for the user's account.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the user's MFA methods configuration.\n */\nexport const getMfaMethods = async (client = getDefaultClient()) => {\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const userMfaMethods = await apiClient.getUserMfaMethods({\n environmentId: core.environmentId,\n verifiedOnly: true,\n });\n\n return userMfaMethods;\n};\n","import type { MFAAction } from '@dynamic-labs/sdk-api-core';\n\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { getMfaMethods } from '../getMfaMethods';\n\ntype IsMfaRequiredForActionParams = {\n mfaAction: MFAAction;\n};\n\n/**\n * Checks if MFA is required for a specific action.\n *\n * This function determines whether multi-factor authentication is required\n * for the specified action based on project settings and user configuration.\n *\n * @param params.mfaAction - The action to check MFA requirements for.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to true if MFA is required for the action, false otherwise.\n */\nexport const isMfaRequiredForAction = async (\n { mfaAction }: IsMfaRequiredForActionParams,\n client = getDefaultClient()\n) => {\n const projectSettings = client.projectSettings;\n\n const isRequiredForAction = projectSettings?.security?.mfa?.actions?.some(\n (action) => action.action === mfaAction && action.required\n );\n\n // if mfa is not required for the action, return false\n // no matter if general mfa is set to required or not\n if (!isRequiredForAction) {\n return false;\n }\n\n const isMfaMethodRequired = projectSettings?.security?.mfa?.required;\n\n // if mfa is required for the action and also set as required in general, return true\n if (isMfaMethodRequired) {\n return true;\n }\n\n const mfaMethods = await getMfaMethods(client);\n // if general mfa is optional, but user has registered methods,\n // then it should be required for the action\n return mfaMethods.userHasVerifiedMfaMethods;\n};\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,WAC1B,CAAC,GAAG,IAAI,WAAW,OAAO,CAAC,CACxB,KAAK,MAAM,EAAE,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAC3C,KAAK,GAAG;;;;;;;;;;;;;;ACQb,MAAa,mBAAmB,SAASA,oCAAkB,KAAK;CAC9D,MAAM,OAAOC,0BAAQ,OAAO;CAE5B,MAAM,WAAW,KAAK,MAAM,KAAK,CAAC;AAElC,iCAAc,UAAU,qBAAqB;AAE7C,MAAK,MAAM,IAAI,EACb,UAAU,MACX,CAAC;AAEF,QAAO;;;;;;;;;;;;;;ACZT,MAAa,gBAAgB,OAAO,SAASC,oCAAkB,KAAK;CAClE,MAAM,OAAOC,0BAAQ,OAAO;AAQ5B,QALuB,MAFLC,kCAAgB,EAAE,EAAE,OAAO,CAEN,kBAAkB;EACvD,eAAe,KAAK;EACpB,cAAc;EACf,CAAC;;;;;;;;;;;;;;;ACDJ,MAAa,yBAAyB,OACpC,EAAE,aACF,SAASC,oCAAkB,KACxB;CACH,MAAM,kBAAkB,OAAO;AAQ/B,KAAI,CANwB,iBAAiB,UAAU,KAAK,SAAS,MAClE,WAAW,OAAO,WAAW,aAAa,OAAO,SACnD,CAKC,QAAO;AAMT,KAH4B,iBAAiB,UAAU,KAAK,SAI1D,QAAO;AAMT,SAHmB,MAAM,cAAc,OAAO,EAG5B"}
|
package/dist/{isMfaRequiredForAction-DDWwiFPT.esm.js → isMfaRequiredForAction-YAISA589.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createApiClient, b as getDefaultClient, h as assertDefined, w as getCore } from "./constants-
|
|
1
|
+
import { a as createApiClient, b as getDefaultClient, h as assertDefined, w as getCore } from "./constants-DQfjH5fu.esm.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/bufferToHex/bufferToHex.ts
|
|
4
4
|
/**
|
|
@@ -66,4 +66,4 @@ const isMfaRequiredForAction = async ({ mfaAction }, client = getDefaultClient()
|
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
68
|
export { bufferToHex as i, getMfaMethods as n, consumeMfaToken as r, isMfaRequiredForAction as t };
|
|
69
|
-
//# sourceMappingURL=isMfaRequiredForAction-
|
|
69
|
+
//# sourceMappingURL=isMfaRequiredForAction-YAISA589.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isMfaRequiredForAction-
|
|
1
|
+
{"version":3,"file":"isMfaRequiredForAction-YAISA589.esm.js","names":[],"sources":["../src/utils/bufferToHex/bufferToHex.ts","../src/modules/mfa/consumeMfaToken/consumeMfaToken.ts","../src/modules/mfa/getMfaMethods/getMfaMethods.ts","../src/modules/mfa/isMfaRequiredForAction/isMfaRequiredForAction.ts"],"sourcesContent":["/**\n * Converts an ArrayBuffer to a hex-encoded string\n */\nexport const bufferToHex = (buffer: ArrayBufferLike) =>\n [...new Uint8Array(buffer)]\n .map((x) => x.toString(16).padStart(2, '0'))\n .join('');\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Consumes and clears the current MFA token from the client state.\n *\n * This function retrieves the MFA token obtained from a successful MFA authentication,\n * and removes it from the client, to prevent it from being used again.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The MFA token that was consumed.\n * @throws Error if no MFA token is found.\n */\nexport const consumeMfaToken = (client = getDefaultClient()) => {\n const core = getCore(client);\n\n const mfaToken = core.state.get().mfaToken;\n\n assertDefined(mfaToken, 'No MFA token found');\n\n core.state.set({\n mfaToken: null,\n });\n\n return mfaToken;\n};\n","import { getCore } from '../../../client/core/getCore';\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { createApiClient } from '../../apiClient';\n\n/**\n * Retrieves the available MFA methods for the current user.\n *\n * This function fetches information about which multi-factor authentication\n * methods are available and configured for the user's account.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the user's MFA methods configuration.\n */\nexport const getMfaMethods = async (client = getDefaultClient()) => {\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const userMfaMethods = await apiClient.getUserMfaMethods({\n environmentId: core.environmentId,\n verifiedOnly: true,\n });\n\n return userMfaMethods;\n};\n","import type { MFAAction } from '@dynamic-labs/sdk-api-core';\n\nimport { getDefaultClient } from '../../../client/defaultClient';\nimport { getMfaMethods } from '../getMfaMethods';\n\ntype IsMfaRequiredForActionParams = {\n mfaAction: MFAAction;\n};\n\n/**\n * Checks if MFA is required for a specific action.\n *\n * This function determines whether multi-factor authentication is required\n * for the specified action based on project settings and user configuration.\n *\n * @param params.mfaAction - The action to check MFA requirements for.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to true if MFA is required for the action, false otherwise.\n */\nexport const isMfaRequiredForAction = async (\n { mfaAction }: IsMfaRequiredForActionParams,\n client = getDefaultClient()\n) => {\n const projectSettings = client.projectSettings;\n\n const isRequiredForAction = projectSettings?.security?.mfa?.actions?.some(\n (action) => action.action === mfaAction && action.required\n );\n\n // if mfa is not required for the action, return false\n // no matter if general mfa is set to required or not\n if (!isRequiredForAction) {\n return false;\n }\n\n const isMfaMethodRequired = projectSettings?.security?.mfa?.required;\n\n // if mfa is required for the action and also set as required in general, return true\n if (isMfaMethodRequired) {\n return true;\n }\n\n const mfaMethods = await getMfaMethods(client);\n // if general mfa is optional, but user has registered methods,\n // then it should be required for the action\n return mfaMethods.userHasVerifiedMfaMethods;\n};\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,WAC1B,CAAC,GAAG,IAAI,WAAW,OAAO,CAAC,CACxB,KAAK,MAAM,EAAE,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAC3C,KAAK,GAAG;;;;;;;;;;;;;;ACQb,MAAa,mBAAmB,SAAS,kBAAkB,KAAK;CAC9D,MAAM,OAAO,QAAQ,OAAO;CAE5B,MAAM,WAAW,KAAK,MAAM,KAAK,CAAC;AAElC,eAAc,UAAU,qBAAqB;AAE7C,MAAK,MAAM,IAAI,EACb,UAAU,MACX,CAAC;AAEF,QAAO;;;;;;;;;;;;;;ACZT,MAAa,gBAAgB,OAAO,SAAS,kBAAkB,KAAK;CAClE,MAAM,OAAO,QAAQ,OAAO;AAQ5B,QALuB,MAFL,gBAAgB,EAAE,EAAE,OAAO,CAEN,kBAAkB;EACvD,eAAe,KAAK;EACpB,cAAc;EACf,CAAC;;;;;;;;;;;;;;;ACDJ,MAAa,yBAAyB,OACpC,EAAE,aACF,SAAS,kBAAkB,KACxB;CACH,MAAM,kBAAkB,OAAO;AAQ/B,KAAI,CANwB,iBAAiB,UAAU,KAAK,SAAS,MAClE,WAAW,OAAO,WAAW,aAAa,OAAO,SACnD,CAKC,QAAO;AAMT,KAH4B,iBAAiB,UAAU,KAAK,SAI1D,QAAO;AAMT,SAHmB,MAAM,cAAc,OAAO,EAG5B"}
|