@dynamic-labs-sdk/client 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{InvalidParamError-CDmVW2DS.native.esm.js → InvalidParamError-BIptAjbC.native.esm.js} +839 -93
- package/dist/InvalidParamError-BIptAjbC.native.esm.js.map +1 -0
- package/dist/{InvalidParamError-BPMi0iWC.esm.js → InvalidParamError-BZ0LHaml.esm.js} +806 -93
- package/dist/InvalidParamError-BZ0LHaml.esm.js.map +1 -0
- package/dist/{InvalidParamError-DEmLKJKZ.cjs → InvalidParamError-DyXEKMWn.cjs} +1012 -116
- package/dist/InvalidParamError-DyXEKMWn.cjs.map +1 -0
- package/dist/{NotWaasWalletAccountError-Cntietge.esm.js → NotWaasWalletAccountError-BbOA5rPd.native.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-BbOA5rPd.native.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-BZsBHRQe.cjs → NotWaasWalletAccountError-CElqwdQO.cjs} +4 -4
- package/dist/NotWaasWalletAccountError-CElqwdQO.cjs.map +1 -0
- package/dist/{NotWaasWalletAccountError-Chpne8_Q.native.esm.js → NotWaasWalletAccountError-nT4jrLbp.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-nT4jrLbp.esm.js.map +1 -0
- package/dist/core.cjs +45 -23
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +27 -6
- package/dist/core.esm.js.map +1 -1
- package/dist/core.native.esm.js +27 -6
- package/dist/core.native.esm.js.map +1 -1
- package/dist/errors/CorruptedKeyShareError.d.ts +19 -0
- package/dist/errors/CorruptedKeyShareError.d.ts.map +1 -0
- package/dist/errors/WebViewLoadFailedError.d.ts +32 -0
- package/dist/errors/WebViewLoadFailedError.d.ts.map +1 -0
- package/dist/errors/base/BaseError.d.ts.map +1 -1
- package/dist/exports/core.d.ts +4 -0
- package/dist/exports/core.d.ts.map +1 -1
- package/dist/exports/index.d.ts +12 -0
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/{getNetworkProviderFromNetworkId-JGrKwBj7.native.esm.js → getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js} +39 -328
- package/dist/getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-CEeFL-gV.esm.js → getNetworkProviderFromNetworkId-BkAPIdRC.esm.js} +38 -266
- package/dist/getNetworkProviderFromNetworkId-BkAPIdRC.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-szJOsbQN.cjs → getNetworkProviderFromNetworkId-DbI5MZhq.cjs} +44 -341
- package/dist/getNetworkProviderFromNetworkId-DbI5MZhq.cjs.map +1 -0
- package/dist/{getSignedSessionId-B5DikCap.native.esm.js → getSignedSessionId-1TV-x__C.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-B5DikCap.native.esm.js.map → getSignedSessionId-1TV-x__C.native.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-BxOK-Tdo.cjs → getSignedSessionId-BF6n8gve.cjs} +3 -3
- package/dist/{getSignedSessionId-BxOK-Tdo.cjs.map → getSignedSessionId-BF6n8gve.cjs.map} +1 -1
- package/dist/{getSignedSessionId-BOx1nFt_.esm.js → getSignedSessionId-y3YtxFHZ.esm.js} +3 -3
- package/dist/{getSignedSessionId-BOx1nFt_.esm.js.map → getSignedSessionId-y3YtxFHZ.esm.js.map} +1 -1
- package/dist/getVerifiedCredentialForWalletAccount-BfJ29erz.cjs +346 -0
- package/dist/getVerifiedCredentialForWalletAccount-BfJ29erz.cjs.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js +269 -0
- package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-etV50QRH.esm.js +269 -0
- package/dist/getVerifiedCredentialForWalletAccount-etV50QRH.esm.js.map +1 -0
- package/dist/index.cjs +580 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +511 -191
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +511 -191
- package/dist/index.native.esm.js.map +1 -1
- package/dist/{isMfaRequiredForAction-DUvZEpjA.native.esm.js → isMfaRequiredForAction-B2vKX31S.native.esm.js} +32 -3
- package/dist/isMfaRequiredForAction-B2vKX31S.native.esm.js.map +1 -0
- package/dist/{isMfaRequiredForAction-D9p_du8C.esm.js → isMfaRequiredForAction-Dy4-S3mr.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-D9p_du8C.esm.js.map → isMfaRequiredForAction-Dy4-S3mr.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-6N6JB7wa.cjs → isMfaRequiredForAction-K2Jh-3-j.cjs} +2 -2
- package/dist/{isMfaRequiredForAction-6N6JB7wa.cjs.map → isMfaRequiredForAction-K2Jh-3-j.cjs.map} +1 -1
- package/dist/modules/apiClient/apiClient.types.d.ts +12 -0
- package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
- package/dist/modules/apiClient/createApiClient.d.ts.map +1 -1
- package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +27 -0
- package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +1 -0
- package/dist/modules/auth/isSignedIn/isSignedIn.d.ts +11 -1
- package/dist/modules/auth/isSignedIn/isSignedIn.d.ts.map +1 -1
- package/dist/modules/auth/logoutReason.d.ts +1 -1
- package/dist/modules/auth/logoutReason.d.ts.map +1 -1
- package/dist/modules/auth/logoutWithReason/logoutWithReason.d.ts.map +1 -1
- package/dist/modules/balances/getBalances/getBalances.d.ts +9 -45
- package/dist/modules/balances/getBalances/getBalances.d.ts.map +1 -1
- package/dist/modules/balances/getMultichainBalances/getMultichainBalances.d.ts +13 -20
- package/dist/modules/balances/getMultichainBalances/getMultichainBalances.d.ts.map +1 -1
- package/dist/modules/balances/getMultichainTokenBalances/getMultichainTokenBalances.d.ts +26 -0
- package/dist/modules/balances/getMultichainTokenBalances/getMultichainTokenBalances.d.ts.map +1 -0
- package/dist/modules/balances/getMultichainTokenBalances/index.d.ts +2 -0
- package/dist/modules/balances/getMultichainTokenBalances/index.d.ts.map +1 -0
- package/dist/modules/balances/getTokenBalances/getTokenBalances.d.ts +56 -0
- package/dist/modules/balances/getTokenBalances/getTokenBalances.d.ts.map +1 -0
- package/dist/modules/balances/getTokenBalances/index.d.ts +3 -0
- package/dist/modules/balances/getTokenBalances/index.d.ts.map +1 -0
- package/dist/modules/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
- package/dist/modules/funding/moonpay/errors/MoonPayCurrenciesFetchError.d.ts +5 -0
- package/dist/modules/funding/moonpay/errors/MoonPayCurrenciesFetchError.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/errors/MoonPayInvalidUrlError.d.ts +5 -0
- package/dist/modules/funding/moonpay/errors/MoonPayInvalidUrlError.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/errors/MoonPayProviderNotAvailableError.d.ts +5 -0
- package/dist/modules/funding/moonpay/errors/MoonPayProviderNotAvailableError.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/getMoonPayCurrencies/getMoonPayCurrencies.d.ts +14 -0
- package/dist/modules/funding/moonpay/getMoonPayCurrencies/getMoonPayCurrencies.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/getMoonPayCurrencies/index.d.ts +2 -0
- package/dist/modules/funding/moonpay/getMoonPayCurrencies/index.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/getMoonPayUrl/getMoonPayUrl.d.ts +15 -0
- package/dist/modules/funding/moonpay/getMoonPayUrl/getMoonPayUrl.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/getMoonPayUrl/index.d.ts +2 -0
- package/dist/modules/funding/moonpay/getMoonPayUrl/index.d.ts.map +1 -0
- package/dist/modules/funding/moonpay/moonpay.types.d.ts +26 -0
- package/dist/modules/funding/moonpay/moonpay.types.d.ts.map +1 -0
- package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainFromWalletSchema/getChainFromWalletSchema.d.ts +12 -0
- package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainFromWalletSchema/getChainFromWalletSchema.d.ts.map +1 -1
- package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainsFromWalletSchema/getChainsFromWalletSchema.d.ts +26 -0
- package/dist/modules/legacyWalletBook/getWalletConnectCatalog/getChainsFromWalletSchema/getChainsFromWalletSchema.d.ts.map +1 -0
- package/dist/modules/legacyWalletBook/hasUsableDeeplink/hasUsableDeeplink.d.ts +18 -0
- package/dist/modules/legacyWalletBook/hasUsableDeeplink/hasUsableDeeplink.d.ts.map +1 -0
- package/dist/modules/legacyWalletBook/legacyWalletBook.types.d.ts +2 -2
- package/dist/modules/legacyWalletBook/legacyWalletBook.types.d.ts.map +1 -1
- package/dist/modules/swap/executeSwapTransaction/executeSwapTransaction.d.ts +13 -1
- package/dist/modules/swap/executeSwapTransaction/executeSwapTransaction.d.ts.map +1 -1
- package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
- package/dist/modules/waas/createWaasClient/createWaasClient.d.ts +2 -7
- package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
- package/dist/modules/waas/createWaasClient/createWaasClient.types.d.ts +8 -0
- package/dist/modules/waas/createWaasClient/createWaasClient.types.d.ts.map +1 -0
- package/dist/modules/waas/createWaasClient/createWaasSDKContainer.d.ts +15 -0
- package/dist/modules/waas/createWaasClient/createWaasSDKContainer.d.ts.map +1 -0
- package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts +18 -0
- package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts.map +1 -0
- package/dist/modules/walletOptionsCatalogue/buildMetaMaskSdkUriOptions/buildMetaMaskSdkUriOptions.d.ts +27 -0
- package/dist/modules/walletOptionsCatalogue/buildMetaMaskSdkUriOptions/buildMetaMaskSdkUriOptions.d.ts.map +1 -0
- package/dist/modules/walletOptionsCatalogue/buildWalletConnectOptions/buildWalletConnectOptions.d.ts +26 -0
- package/dist/modules/walletOptionsCatalogue/buildWalletConnectOptions/buildWalletConnectOptions.d.ts.map +1 -0
- package/dist/modules/walletOptionsCatalogue/buildWalletOption/buildWalletOption.d.ts +11 -4
- package/dist/modules/walletOptionsCatalogue/buildWalletOption/buildWalletOption.d.ts.map +1 -1
- package/dist/modules/walletOptionsCatalogue/buildWithWalletProviderOptions/buildWithWalletProviderOptions.d.ts.map +1 -1
- package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/getInstallationLinkForCurrentPlatform.d.ts +35 -0
- package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/getInstallationLinkForCurrentPlatform.d.ts.map +1 -0
- package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/index.d.ts +2 -0
- package/dist/modules/walletOptionsCatalogue/getInstallationLinkForCurrentPlatform/index.d.ts.map +1 -0
- package/dist/modules/walletOptionsCatalogue/getWalletOptionsCatalogue/getWalletOptionsCatalogue.d.ts +6 -1
- package/dist/modules/walletOptionsCatalogue/getWalletOptionsCatalogue/getWalletOptionsCatalogue.d.ts.map +1 -1
- package/dist/modules/walletOptionsCatalogue/walletOptionsCatalogue.types.d.ts +11 -0
- package/dist/modules/walletOptionsCatalogue/walletOptionsCatalogue.types.d.ts.map +1 -1
- package/dist/modules/wallets/constants.d.ts +7 -0
- package/dist/modules/wallets/constants.d.ts.map +1 -1
- package/dist/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.d.ts.map +1 -1
- package/dist/modules/wallets/hasWalletProviderConnectMethod/hasWalletProviderConnectMethod.d.ts +26 -0
- package/dist/modules/wallets/hasWalletProviderConnectMethod/hasWalletProviderConnectMethod.d.ts.map +1 -0
- package/dist/modules/wallets/hasWalletProviderConnectMethod/index.d.ts +2 -0
- package/dist/modules/wallets/hasWalletProviderConnectMethod/index.d.ts.map +1 -0
- package/dist/modules/wallets/isAnyWalletAccountConnected/index.d.ts +2 -0
- package/dist/modules/wallets/isAnyWalletAccountConnected/index.d.ts.map +1 -0
- package/dist/modules/wallets/isAnyWalletAccountConnected/isAnyWalletAccountConnected.d.ts +14 -0
- package/dist/modules/wallets/isAnyWalletAccountConnected/isAnyWalletAccountConnected.d.ts.map +1 -0
- package/dist/modules/wallets/networks/getBalance/getBalance.d.ts +6 -17
- package/dist/modules/wallets/networks/getBalance/getBalance.d.ts.map +1 -1
- package/dist/modules/wallets/networks/getNativeBalance/getNativeBalance.d.ts +24 -0
- package/dist/modules/wallets/networks/getNativeBalance/getNativeBalance.d.ts.map +1 -0
- package/dist/modules/wallets/networks/getNativeBalance/index.d.ts +2 -0
- package/dist/modules/wallets/networks/getNativeBalance/index.d.ts.map +1 -0
- package/dist/modules/wallets/walletProvider/walletProvider.types.d.ts +10 -0
- package/dist/modules/wallets/walletProvider/walletProvider.types.d.ts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/getChainFromWalletBookIdentifier/getChainFromWalletBookIdentifier.d.ts +22 -0
- package/dist/utils/getChainFromWalletBookIdentifier/getChainFromWalletBookIdentifier.d.ts.map +1 -0
- package/dist/utils/getChainFromWalletBookIdentifier/index.d.ts +2 -0
- package/dist/utils/getChainFromWalletBookIdentifier/index.d.ts.map +1 -0
- package/dist/utils/getNativeLinkScheme/getNativeLinkScheme.d.ts +18 -0
- package/dist/utils/getNativeLinkScheme/getNativeLinkScheme.d.ts.map +1 -0
- package/dist/utils/getNativeLinkScheme/index.d.ts +3 -0
- package/dist/utils/getNativeLinkScheme/index.d.ts.map +1 -0
- package/dist/utils/isMobile/isMobile.d.ts +8 -0
- package/dist/utils/isMobile/isMobile.d.ts.map +1 -1
- package/dist/waas.cjs +8 -9
- package/dist/waas.cjs.map +1 -1
- package/dist/waas.esm.js +3 -3
- package/dist/waas.native.esm.js +3 -3
- package/dist/waasCore.cjs +3 -4
- package/dist/waasCore.cjs.map +1 -1
- package/dist/waasCore.esm.js +3 -3
- package/dist/waasCore.esm.js.map +1 -1
- package/dist/waasCore.native.esm.js +208 -7
- package/dist/waasCore.native.esm.js.map +1 -1
- package/package.json +5 -5
- package/dist/InvalidParamError-BPMi0iWC.esm.js.map +0 -1
- package/dist/InvalidParamError-CDmVW2DS.native.esm.js.map +0 -1
- package/dist/InvalidParamError-DEmLKJKZ.cjs.map +0 -1
- package/dist/NotWaasWalletAccountError-BZsBHRQe.cjs.map +0 -1
- package/dist/NotWaasWalletAccountError-Chpne8_Q.native.esm.js.map +0 -1
- package/dist/NotWaasWalletAccountError-Cntietge.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-CEeFL-gV.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-JGrKwBj7.native.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-szJOsbQN.cjs.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-B46O0B48.cjs +0 -887
- package/dist/getVerifiedCredentialForWalletAccount-B46O0B48.cjs.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-CyykSi-M.native.esm.js +0 -701
- package/dist/getVerifiedCredentialForWalletAccount-CyykSi-M.native.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-DzwIoeHm.esm.js +0 -701
- package/dist/getVerifiedCredentialForWalletAccount-DzwIoeHm.esm.js.map +0 -1
- package/dist/isMfaRequiredForAction-DUvZEpjA.native.esm.js.map +0 -1
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/buildUriDeeplinkOptions.d.ts +0 -28
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/buildUriDeeplinkOptions.d.ts.map +0 -1
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/index.d.ts +0 -2
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/index.d.ts.map +0 -1
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/index.d.ts +0 -2
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/index.d.ts.map +0 -1
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/resolveUriConnectionType.d.ts +0 -17
- package/dist/modules/walletOptionsCatalogue/buildUriDeeplinkOptions/resolveUriConnectionType/resolveUriConnectionType.d.ts.map +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
const require_InvalidParamError = require('./InvalidParamError-DyXEKMWn.cjs');
|
|
2
|
+
let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
|
|
3
|
+
|
|
4
|
+
//#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
|
|
5
|
+
/**
|
|
6
|
+
* Emits the `walletAccountsChanged` event.
|
|
7
|
+
* @not-instrumented
|
|
8
|
+
*/
|
|
9
|
+
const emitWalletAccountsChangedEvent = (client) => {
|
|
10
|
+
require_InvalidParamError.emitEvent({
|
|
11
|
+
args: { walletAccounts: require_InvalidParamError.getWalletAccounts(client) },
|
|
12
|
+
event: "walletAccountsChanged"
|
|
13
|
+
}, client);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts
|
|
18
|
+
/** @not-instrumented */
|
|
19
|
+
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client) => {
|
|
20
|
+
const core = require_InvalidParamError.getCore(client);
|
|
21
|
+
if (getWalletAccountsHash(previousState, client) !== getWalletAccountsHash(core.state.get(), client)) emitWalletAccountsChangedEvent(client);
|
|
22
|
+
};
|
|
23
|
+
const getWalletAccountsHash = (state, client) => require_InvalidParamError.getWalletAccountsFromState(state, client).map((walletAccount) => JSON.stringify(walletAccount)).sort().join("-");
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the user requires additional MFA authentication.
|
|
29
|
+
*
|
|
30
|
+
* This function determines if the current user session requires
|
|
31
|
+
* additional multi-factor authentication to access certain features.
|
|
32
|
+
*
|
|
33
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
34
|
+
* @returns True if the user needs additional MFA authentication, false otherwise.
|
|
35
|
+
* @not-instrumented
|
|
36
|
+
*/
|
|
37
|
+
const isUserMissingMfaAuth = (client = require_InvalidParamError.getDefaultClient()) => {
|
|
38
|
+
const user = client.user;
|
|
39
|
+
require_InvalidParamError.assertDefined(user, "User not logged in");
|
|
40
|
+
return Boolean(user.scope?.includes("requiresAdditionalAuth"));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/modules/wallets/getWalletProviders/getWalletProviders.ts
|
|
45
|
+
/**
|
|
46
|
+
* Get all available wallet providers to interact with internally.
|
|
47
|
+
* @not-instrumented
|
|
48
|
+
*/
|
|
49
|
+
const getWalletProviders = (client) => {
|
|
50
|
+
return require_InvalidParamError.getWalletProviderRegistry(client).listProviders();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts
|
|
55
|
+
/** @not-instrumented */
|
|
56
|
+
const isWaasWalletProvider = (walletProvider) => {
|
|
57
|
+
return walletProvider.key.includes(require_InvalidParamError.DYNAMIC_WAAS_METADATA.normalizedWalletName);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts
|
|
62
|
+
/** @not-instrumented */
|
|
63
|
+
const findWaasWalletProviderByChain = ({ chain }, client) => {
|
|
64
|
+
const providers = getWalletProviders(client);
|
|
65
|
+
const waasProviderKey = require_InvalidParamError.formatWalletProviderKey({
|
|
66
|
+
chain,
|
|
67
|
+
displayName: require_InvalidParamError.DYNAMIC_WAAS_METADATA.displayName,
|
|
68
|
+
walletProviderType: _dynamic_labs_sdk_api_core.WalletProviderEnum.EmbeddedWallet
|
|
69
|
+
});
|
|
70
|
+
const waasProvider = providers.find((provider) => provider.key === waasProviderKey && provider.chain === chain);
|
|
71
|
+
if (!waasProvider || !isWaasWalletProvider(waasProvider)) return null;
|
|
72
|
+
return waasProvider;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts
|
|
77
|
+
/**
|
|
78
|
+
* This function determines whether the provided wallet account is a Dynamic
|
|
79
|
+
* WaaS wallet account.
|
|
80
|
+
*
|
|
81
|
+
* @param params.walletAccount - The wallet account to check.
|
|
82
|
+
* @returns True if the wallet account is a WaaS wallet account, false otherwise.
|
|
83
|
+
* @not-instrumented
|
|
84
|
+
*/
|
|
85
|
+
const isWaasWalletAccount = ({ walletAccount }) => {
|
|
86
|
+
return walletAccount.walletProviderKey.includes(require_InvalidParamError.DYNAMIC_WAAS_METADATA.normalizedWalletName);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts
|
|
91
|
+
/** @not-instrumented */
|
|
92
|
+
const restoreUserSharesForAllWalletAccounts = async (client) => {
|
|
93
|
+
/**
|
|
94
|
+
* Restoring the user shares will fails if the user is missing the MFA auth.
|
|
95
|
+
* This early return prevents the attempt to restore the user shares to fail
|
|
96
|
+
* when we know it will fails and just add noise to the logs.
|
|
97
|
+
*/
|
|
98
|
+
if (isUserMissingMfaAuth(client)) return;
|
|
99
|
+
const waasWalletAccounts = require_InvalidParamError.getWalletAccounts(client).filter((walletAccount) => isWaasWalletAccount({ walletAccount }));
|
|
100
|
+
await Promise.all(waasWalletAccounts.map(async (walletAccount) => {
|
|
101
|
+
const provider = findWaasWalletProviderByChain({ chain: walletAccount.chain }, client);
|
|
102
|
+
/**
|
|
103
|
+
* The environment might not have the embedded wallet extensions installed.
|
|
104
|
+
* In that case there is no provider for the chain and we can skip restoring the user share.
|
|
105
|
+
*/
|
|
106
|
+
if (!provider) return;
|
|
107
|
+
return provider.restoreUserShareForWalletAccount({ walletAccount });
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/modules/auth/decodeJwt/decodeJwt.ts
|
|
113
|
+
/**
|
|
114
|
+
* Decodes a JWT token and returns the full payload.
|
|
115
|
+
*
|
|
116
|
+
* This function extracts and returns the complete JWT payload including scopes,
|
|
117
|
+
* expiration time, and other claims.
|
|
118
|
+
*
|
|
119
|
+
* @param jwt - The JWT token string.
|
|
120
|
+
* @returns The decoded JWT payload object.
|
|
121
|
+
* @throws InvalidParamError if the token is invalid or cannot be decoded.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const payload = decodeJwt(jwt);
|
|
126
|
+
* // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }
|
|
127
|
+
* ```
|
|
128
|
+
* @not-instrumented
|
|
129
|
+
*/
|
|
130
|
+
const decodeJwt = (jwt) => {
|
|
131
|
+
try {
|
|
132
|
+
const parts = jwt.split(".");
|
|
133
|
+
if (parts.length !== 3) throw new require_InvalidParamError.InvalidParamError("Invalid JWT format");
|
|
134
|
+
const base64Payload = parts[1].replaceAll("-", "+").replaceAll("_", "/");
|
|
135
|
+
const paddedPayload = base64Payload + "=".repeat((4 - base64Payload.length % 4) % 4);
|
|
136
|
+
const decodedPayload = atob(paddedPayload);
|
|
137
|
+
return JSON.parse(decodedPayload);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error instanceof require_InvalidParamError.InvalidParamError) throw error;
|
|
140
|
+
throw new require_InvalidParamError.InvalidParamError(`Failed to decode JWT: ${error instanceof Error ? error.message : String(error)}`);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts
|
|
146
|
+
/**
|
|
147
|
+
* Normalizes scopes by deduplicating and sorting them.
|
|
148
|
+
* This creates a canonical representation for comparison.
|
|
149
|
+
*
|
|
150
|
+
* @param scopes - Array of scope strings (may contain duplicates)
|
|
151
|
+
* @returns Normalized, sorted array of unique scopes
|
|
152
|
+
* @not-instrumented
|
|
153
|
+
*/
|
|
154
|
+
const normalizeScopes = (scopes) => {
|
|
155
|
+
return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts
|
|
160
|
+
/**
|
|
161
|
+
* Validates and parses an elevated access token from a JWT string.
|
|
162
|
+
* Extracts scopes, expiration, and validates the token structure.
|
|
163
|
+
*
|
|
164
|
+
* Policy decisions:
|
|
165
|
+
* - Tokens without scopes are rejected (returns null)
|
|
166
|
+
* - Tokens with empty scopes array are rejected (returns null)
|
|
167
|
+
* - Tokens without exp field are rejected (returns null)
|
|
168
|
+
* - Expired tokens are rejected (returns null)
|
|
169
|
+
*
|
|
170
|
+
* @returns Parsed token data or null if token is invalid/expired
|
|
171
|
+
* @not-instrumented
|
|
172
|
+
*/
|
|
173
|
+
const parseElevatedAccessToken = ({ token }) => {
|
|
174
|
+
const payload = decodeJwt(token);
|
|
175
|
+
const filteredScopes = ((payload?.scope)?.split(" ") ?? []).filter((s) => s.length > 0);
|
|
176
|
+
const singleUse = payload.singleUse ?? false;
|
|
177
|
+
if (!filteredScopes || filteredScopes.length === 0) return null;
|
|
178
|
+
if (!payload.exp) return null;
|
|
179
|
+
const expiresAt = /* @__PURE__ */ new Date(payload.exp * 1e3);
|
|
180
|
+
if (expiresAt <= /* @__PURE__ */ new Date()) return null;
|
|
181
|
+
return {
|
|
182
|
+
expiresAt,
|
|
183
|
+
normalizedScopes: normalizeScopes(filteredScopes),
|
|
184
|
+
scopes: filteredScopes,
|
|
185
|
+
singleUse,
|
|
186
|
+
token
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts
|
|
192
|
+
/**
|
|
193
|
+
* Upserts an elevated access token into the current tokens array.
|
|
194
|
+
*
|
|
195
|
+
* Policy: Only one token per normalized scope-set is allowed.
|
|
196
|
+
* If a token with the same normalized scopes exists, it is replaced.
|
|
197
|
+
* This ensures we don't accumulate multiple tokens for the same scope combination.
|
|
198
|
+
*
|
|
199
|
+
* @param currentTokens - Current array of elevated access tokens
|
|
200
|
+
* @param newToken - New token to upsert
|
|
201
|
+
* @returns Updated array of tokens with the new token upserted
|
|
202
|
+
* @not-instrumented
|
|
203
|
+
*/
|
|
204
|
+
const upsertElevatedAccessToken = ({ currentTokens, newToken }) => {
|
|
205
|
+
const newScopeKey = normalizeScopes(newToken.scopes).join(" ");
|
|
206
|
+
return [...currentTokens.filter((existingToken) => {
|
|
207
|
+
return normalizeScopes(existingToken.scopes).join(" ") !== newScopeKey;
|
|
208
|
+
}), {
|
|
209
|
+
expiresAt: newToken.expiresAt,
|
|
210
|
+
scopes: newToken.scopes,
|
|
211
|
+
singleUse: newToken.singleUse,
|
|
212
|
+
token: newToken.token
|
|
213
|
+
}];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts
|
|
218
|
+
/** @not-instrumented */
|
|
219
|
+
const updateAuthFromVerifyResponse = ({ response }, client) => {
|
|
220
|
+
const core = require_InvalidParamError.getCore(client);
|
|
221
|
+
const previousState = { ...core.state.get() };
|
|
222
|
+
const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } = response;
|
|
223
|
+
const sessionExpiresAt = /* @__PURE__ */ new Date(expiresAt * 1e3);
|
|
224
|
+
const newState = {
|
|
225
|
+
legacyToken: jwt ?? null,
|
|
226
|
+
sessionExpiresAt,
|
|
227
|
+
token: minifiedJwt ?? null,
|
|
228
|
+
user
|
|
229
|
+
};
|
|
230
|
+
if (mfaToken) newState.mfaToken = mfaToken;
|
|
231
|
+
const currentTokens = core.state.get().elevatedAccessTokens || [];
|
|
232
|
+
newState.elevatedAccessTokens = currentTokens;
|
|
233
|
+
if (elevatedAccessToken) {
|
|
234
|
+
const parsedToken = parseElevatedAccessToken({ token: elevatedAccessToken });
|
|
235
|
+
if (parsedToken) newState.elevatedAccessTokens = upsertElevatedAccessToken({
|
|
236
|
+
currentTokens,
|
|
237
|
+
newToken: parsedToken
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
core.state.set(newState);
|
|
241
|
+
/**
|
|
242
|
+
* For customers using a sandbox environment with cookies enabled, we need to set the cookie
|
|
243
|
+
* programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically
|
|
244
|
+
* so customers can access the cookie from document.cookie consistently between sandbox and live environments.
|
|
245
|
+
*/
|
|
246
|
+
if (minifiedJwt && require_InvalidParamError.isCookieEnabled(client)) require_InvalidParamError.setCookie(`${require_InvalidParamError.DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${sessionExpiresAt.toUTCString()}; path=/; SameSite=Lax`);
|
|
247
|
+
checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
|
|
248
|
+
if (!previousState.user && Boolean(newState.user)) restoreUserSharesForAllWalletAccounts(client);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts
|
|
253
|
+
/** @not-instrumented */
|
|
254
|
+
const getWalletProviderByKey = ({ walletProviderKey }, client) => {
|
|
255
|
+
const walletProvider = getWalletProviders(client).find((walletProvider$1) => walletProvider$1.key === walletProviderKey);
|
|
256
|
+
if (!walletProvider) throw new require_InvalidParamError.NoWalletProviderFoundError({ walletProviderKey });
|
|
257
|
+
return walletProvider;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
|
|
262
|
+
/** @not-instrumented */
|
|
263
|
+
const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client) => {
|
|
264
|
+
return client.user?.verifiedCredentials.find((vc) => vc.id === walletAccount.verifiedCredentialId);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
Object.defineProperty(exports, 'checkAndRaiseWalletAccountsChangedEvent', {
|
|
269
|
+
enumerable: true,
|
|
270
|
+
get: function () {
|
|
271
|
+
return checkAndRaiseWalletAccountsChangedEvent;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
Object.defineProperty(exports, 'emitWalletAccountsChangedEvent', {
|
|
275
|
+
enumerable: true,
|
|
276
|
+
get: function () {
|
|
277
|
+
return emitWalletAccountsChangedEvent;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
Object.defineProperty(exports, 'findWaasWalletProviderByChain', {
|
|
281
|
+
enumerable: true,
|
|
282
|
+
get: function () {
|
|
283
|
+
return findWaasWalletProviderByChain;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
Object.defineProperty(exports, 'getVerifiedCredentialForWalletAccount', {
|
|
287
|
+
enumerable: true,
|
|
288
|
+
get: function () {
|
|
289
|
+
return getVerifiedCredentialForWalletAccount;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
Object.defineProperty(exports, 'getWalletProviderByKey', {
|
|
293
|
+
enumerable: true,
|
|
294
|
+
get: function () {
|
|
295
|
+
return getWalletProviderByKey;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
Object.defineProperty(exports, 'getWalletProviders', {
|
|
299
|
+
enumerable: true,
|
|
300
|
+
get: function () {
|
|
301
|
+
return getWalletProviders;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
Object.defineProperty(exports, 'isUserMissingMfaAuth', {
|
|
305
|
+
enumerable: true,
|
|
306
|
+
get: function () {
|
|
307
|
+
return isUserMissingMfaAuth;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
Object.defineProperty(exports, 'isWaasWalletAccount', {
|
|
311
|
+
enumerable: true,
|
|
312
|
+
get: function () {
|
|
313
|
+
return isWaasWalletAccount;
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
Object.defineProperty(exports, 'isWaasWalletProvider', {
|
|
317
|
+
enumerable: true,
|
|
318
|
+
get: function () {
|
|
319
|
+
return isWaasWalletProvider;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
Object.defineProperty(exports, 'parseElevatedAccessToken', {
|
|
323
|
+
enumerable: true,
|
|
324
|
+
get: function () {
|
|
325
|
+
return parseElevatedAccessToken;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
Object.defineProperty(exports, 'restoreUserSharesForAllWalletAccounts', {
|
|
329
|
+
enumerable: true,
|
|
330
|
+
get: function () {
|
|
331
|
+
return restoreUserSharesForAllWalletAccounts;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
Object.defineProperty(exports, 'updateAuthFromVerifyResponse', {
|
|
335
|
+
enumerable: true,
|
|
336
|
+
get: function () {
|
|
337
|
+
return updateAuthFromVerifyResponse;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
Object.defineProperty(exports, 'upsertElevatedAccessToken', {
|
|
341
|
+
enumerable: true,
|
|
342
|
+
get: function () {
|
|
343
|
+
return upsertElevatedAccessToken;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
//# sourceMappingURL=getVerifiedCredentialForWalletAccount-BfJ29erz.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVerifiedCredentialForWalletAccount-BfJ29erz.cjs","names":["getWalletAccounts","getCore","getWalletAccountsFromState","getDefaultClient","getWalletProviderRegistry","DYNAMIC_WAAS_METADATA","formatWalletProviderKey","DYNAMIC_WAAS_METADATA","WalletProviderEnum","DYNAMIC_WAAS_METADATA","getWalletAccounts","InvalidParamError","getCore","newState: Partial<DynamicCoreState>","isCookieEnabled","DYNAMIC_AUTH_COOKIE_NAME","walletProvider","NoWalletProviderFoundError"],"sources":["../src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts","../src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts","../src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts","../src/modules/wallets/getWalletProviders/getWalletProviders.ts","../src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts","../src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts","../src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts","../src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts","../src/modules/auth/decodeJwt/decodeJwt.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts","../src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts","../src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts","../src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts","../src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts"],"sourcesContent":["import type { DynamicClient } from '../../../client/types';\nimport { emitEvent } from '../../clientEvents';\nimport { getWalletAccounts } from '../getWalletAccounts';\n\n/**\n * Emits the `walletAccountsChanged` event.\n * @not-instrumented\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\n/** @not-instrumented */\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\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 { getDefaultClient } from '../../../client/defaultClient';\nimport { assertDefined } from '../../../utils/assertDefined';\n\n/**\n * Checks if the user requires additional MFA authentication.\n *\n * This function determines if the current user session requires\n * additional multi-factor authentication to access certain features.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns True if the user needs additional MFA authentication, false otherwise.\n * @not-instrumented\n */\nexport const isUserMissingMfaAuth = (client = getDefaultClient()) => {\n const user = client.user;\n\n assertDefined(user, 'User not logged in');\n\n return Boolean(user.scope?.includes('requiresAdditionalAuth'));\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 * @not-instrumented\n */\nexport const getWalletProviders = (client: DynamicClient) => {\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n return walletProviderRegistry.listProviders();\n};\n","import type { WalletProvider } from '../../wallets/walletProvider';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\nimport type { WaasWalletProvider } from '../waas.types';\n\n/** @not-instrumented */\nexport const isWaasWalletProvider = (\n walletProvider: WalletProvider\n): walletProvider is WaasWalletProvider => {\n return walletProvider.key.includes(\n DYNAMIC_WAAS_METADATA.normalizedWalletName\n );\n};\n","import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport type { DynamicClient } from '../../../client/types/DynamicClient';\nimport type { Chain } from '../../chain';\nimport { getWalletProviders } from '../../wallets/getWalletProviders';\nimport { formatWalletProviderKey } from '../../wallets/utils/formatWalletProviderKey';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\nimport { isWaasWalletProvider } from '../isWaasWalletProvider';\nimport type { WaasWalletProvider } from '../waas.types';\n\ntype FindWaasWalletProviderByChainParams = {\n chain: Chain;\n};\n\n/** @not-instrumented */\nexport const findWaasWalletProviderByChain = (\n { chain }: FindWaasWalletProviderByChainParams,\n client: DynamicClient\n): WaasWalletProvider | null => {\n const providers = getWalletProviders(client);\n\n const waasProviderKey = formatWalletProviderKey({\n chain,\n displayName: DYNAMIC_WAAS_METADATA.displayName,\n walletProviderType: WalletProviderEnum.EmbeddedWallet,\n });\n\n const waasProvider = providers.find(\n (provider) => provider.key === waasProviderKey && provider.chain === chain\n );\n\n if (!waasProvider || !isWaasWalletProvider(waasProvider)) {\n return null;\n }\n\n return waasProvider;\n};\n","import type { WalletAccount } from '../../wallets/walletAccount';\nimport { DYNAMIC_WAAS_METADATA } from '../constants';\n\ntype IsWaasWalletAccountParams = {\n walletAccount: WalletAccount;\n};\n\n/**\n * This function determines whether the provided wallet account is a Dynamic\n * WaaS wallet account.\n *\n * @param params.walletAccount - The wallet account to check.\n * @returns True if the wallet account is a WaaS wallet account, false otherwise.\n * @not-instrumented\n */\nexport const isWaasWalletAccount = ({\n walletAccount,\n}: IsWaasWalletAccountParams): boolean => {\n return walletAccount.walletProviderKey.includes(\n DYNAMIC_WAAS_METADATA.normalizedWalletName\n );\n};\n","import type { DynamicClient } from '../../../client/types';\nimport { isUserMissingMfaAuth } from '../../mfa/isUserMissingMfaAuth';\nimport { getWalletAccounts } from '../../wallets/getWalletAccounts';\nimport { findWaasWalletProviderByChain } from '../findWaasWalletProviderByChain';\nimport { isWaasWalletAccount } from '../isWaasWalletAccount';\n\n/** @not-instrumented */\nexport const restoreUserSharesForAllWalletAccounts = async (\n client: DynamicClient\n) => {\n /**\n * Restoring the user shares will fails if the user is missing the MFA auth.\n * This early return prevents the attempt to restore the user shares to fail\n * when we know it will fails and just add noise to the logs.\n */\n if (isUserMissingMfaAuth(client)) {\n return;\n }\n\n const walletAccounts = getWalletAccounts(client);\n\n const waasWalletAccounts = walletAccounts.filter((walletAccount) =>\n isWaasWalletAccount({ walletAccount })\n );\n\n await Promise.all(\n waasWalletAccounts.map(async (walletAccount) => {\n const provider = findWaasWalletProviderByChain(\n { chain: walletAccount.chain },\n client\n );\n\n /**\n * The environment might not have the embedded wallet extensions installed.\n * In that case there is no provider for the chain and we can skip restoring the user share.\n */\n if (!provider) return;\n\n return provider.restoreUserShareForWalletAccount({ walletAccount });\n })\n );\n};\n","import { InvalidParamError } from '../../../errors/InvalidParamError';\n\nexport type JwtPayload = {\n [key: string]: unknown;\n exp: number;\n iat: number;\n scope: string;\n singleUse?: boolean;\n sub: string;\n};\n\n/**\n * Decodes a JWT token and returns the full payload.\n *\n * This function extracts and returns the complete JWT payload including scopes,\n * expiration time, and other claims.\n *\n * @param jwt - The JWT token string.\n * @returns The decoded JWT payload object.\n * @throws InvalidParamError if the token is invalid or cannot be decoded.\n *\n * @example\n * ```typescript\n * const payload = decodeJwt(jwt);\n * // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }\n * ```\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const decodeJwt = (jwt: string): JwtPayload => {\n try {\n // JWT format: header.payload.signature\n const parts = jwt.split('.');\n if (parts.length !== 3) {\n throw new InvalidParamError('Invalid JWT format');\n }\n\n // Decode the payload (second part)\n // Base64URL decode: replace URL-safe characters and decode\n const base64Payload = parts[1].replaceAll('-', '+').replaceAll('_', '/');\n // Add padding if needed\n const paddedPayload =\n base64Payload + '='.repeat((4 - (base64Payload.length % 4)) % 4);\n const decodedPayload = atob(paddedPayload);\n const claims = JSON.parse(decodedPayload) as JwtPayload;\n\n return claims;\n } catch (error) {\n if (error instanceof InvalidParamError) {\n throw error;\n }\n throw new InvalidParamError(\n `Failed to decode JWT: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n};\n","/**\n * Normalizes scopes by deduplicating and sorting them.\n * This creates a canonical representation for comparison.\n *\n * @param scopes - Array of scope strings (may contain duplicates)\n * @returns Normalized, sorted array of unique scopes\n * @not-instrumented\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const normalizeScopes = (scopes: string[]): string[] => {\n return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));\n};\n","import { decodeJwt } from '../../../decodeJwt';\nimport type { ParsedElevatedAccessToken } from '../elevatedAccessTokens.types';\nimport { normalizeScopes } from '../normalizeScopes';\n\nexport type ParseElevatedAccessTokenOptions = {\n /** JWT string containing the elevated access token. */\n token: string;\n};\n\n/**\n * Validates and parses an elevated access token from a JWT string.\n * Extracts scopes, expiration, and validates the token structure.\n *\n * Policy decisions:\n * - Tokens without scopes are rejected (returns null)\n * - Tokens with empty scopes array are rejected (returns null)\n * - Tokens without exp field are rejected (returns null)\n * - Expired tokens are rejected (returns null)\n *\n * @returns Parsed token data or null if token is invalid/expired\n * @not-instrumented\n */\nexport const parseElevatedAccessToken = ({\n token,\n}: ParseElevatedAccessTokenOptions): ParsedElevatedAccessToken | null => {\n const payload = decodeJwt(token);\n const rawScopeClaim = payload?.scope;\n const processedScopes = rawScopeClaim?.split(' ') ?? [];\n const filteredScopes = processedScopes.filter((s) => s.length > 0);\n const singleUse = payload.singleUse ?? false;\n\n // Reject tokens without scopes or with empty scopes\n if (!filteredScopes || filteredScopes.length === 0) {\n return null;\n }\n\n // Reject tokens without exp field\n if (!payload.exp) {\n return null;\n }\n\n // Convert exp (seconds) to Date (milliseconds)\n const expiresAt = new Date(payload.exp * 1000);\n\n // Reject expired tokens\n if (expiresAt <= new Date()) {\n return null;\n }\n\n return {\n expiresAt,\n normalizedScopes: normalizeScopes(filteredScopes),\n scopes: filteredScopes,\n singleUse,\n token,\n };\n};\n","import type {\n ElevatedAccessToken,\n ParsedElevatedAccessToken,\n} from '../elevatedAccessTokens.types';\nimport { normalizeScopes } from '../normalizeScopes';\n\n/**\n * Upserts an elevated access token into the current tokens array.\n *\n * Policy: Only one token per normalized scope-set is allowed.\n * If a token with the same normalized scopes exists, it is replaced.\n * This ensures we don't accumulate multiple tokens for the same scope combination.\n *\n * @param currentTokens - Current array of elevated access tokens\n * @param newToken - New token to upsert\n * @returns Updated array of tokens with the new token upserted\n * @not-instrumented\n */\nexport const upsertElevatedAccessToken = ({\n currentTokens,\n newToken,\n}: {\n currentTokens: ElevatedAccessToken[];\n newToken: ParsedElevatedAccessToken;\n}): ElevatedAccessToken[] => {\n const newScopeKey = normalizeScopes(newToken.scopes).join(' ');\n\n // Remove any existing token with the same normalized scopes\n const filteredTokens = currentTokens.filter((existingToken) => {\n const existingScopeKey = normalizeScopes(existingToken.scopes).join(' ');\n return existingScopeKey !== newScopeKey;\n });\n\n // Add the new token\n return [\n ...filteredTokens,\n {\n expiresAt: newToken.expiresAt,\n scopes: newToken.scopes,\n singleUse: newToken.singleUse,\n token: newToken.token,\n },\n ];\n};\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 { restoreUserSharesForAllWalletAccounts } from '../../waas/restoreUserSharesForAllWalletAccounts';\nimport { DYNAMIC_AUTH_COOKIE_NAME } from '../consts';\nimport { checkAndRaiseWalletAccountsChangedEvent } from './checkAndRaiseWalletAccountsChangedEvent';\nimport { parseElevatedAccessToken } from './elevatedAccessTokens/parseElevatedAccessToken';\nimport { upsertElevatedAccessToken } from './elevatedAccessTokens/upsertElevatedAccessToken';\n\ntype UpdateAuthFromVerifyResponseParams = {\n response: VerifyResponse;\n};\n\n/** @not-instrumented */\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, elevatedAccessToken } =\n 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 // Add elevated access token to the array if a new one is provided in the response\n // Policy: Only one token per normalized scope-set is allowed (old tokens are replaced)\n // Always preserve existing tokens to ensure they're synced to storage\n const currentTokens = core.state.get().elevatedAccessTokens || [];\n newState.elevatedAccessTokens = currentTokens;\n \n if (elevatedAccessToken) {\n const parsedToken = parseElevatedAccessToken({\n token: elevatedAccessToken,\n });\n if (parsedToken) {\n newState.elevatedAccessTokens = upsertElevatedAccessToken({\n currentTokens,\n newToken: parsedToken,\n });\n }\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 // if the user is logging in, we should restore user shares\n // for all wallet accounts for performance reasons\n const isUserLoggingIn = !previousState.user && Boolean(newState.user);\n if (isUserLoggingIn) {\n void restoreUserSharesForAllWalletAccounts(client);\n }\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\n/** @not-instrumented */\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\n/** @not-instrumented */\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":"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"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { C as getWalletAccountsFromState, L as setCookie, N as emitEvent, S as getWalletAccounts, X as assertDefined, Y as isCookieEnabled, ct as getDefaultClient, d as DYNAMIC_AUTH_COOKIE_NAME, ft as getCore, g as NoWalletProviderFoundError, i as DYNAMIC_WAAS_METADATA, m as getWalletProviderRegistry, t as InvalidParamError, w as formatWalletProviderKey } from "./InvalidParamError-BIptAjbC.native.esm.js";
|
|
2
|
+
import { WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
|
|
3
|
+
|
|
4
|
+
//#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
|
|
5
|
+
/**
|
|
6
|
+
* Emits the `walletAccountsChanged` event.
|
|
7
|
+
* @not-instrumented
|
|
8
|
+
*/
|
|
9
|
+
const emitWalletAccountsChangedEvent = (client) => {
|
|
10
|
+
emitEvent({
|
|
11
|
+
args: { walletAccounts: getWalletAccounts(client) },
|
|
12
|
+
event: "walletAccountsChanged"
|
|
13
|
+
}, client);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts
|
|
18
|
+
/** @not-instrumented */
|
|
19
|
+
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client) => {
|
|
20
|
+
const core = getCore(client);
|
|
21
|
+
if (getWalletAccountsHash(previousState, client) !== getWalletAccountsHash(core.state.get(), client)) emitWalletAccountsChangedEvent(client);
|
|
22
|
+
};
|
|
23
|
+
const getWalletAccountsHash = (state, client) => getWalletAccountsFromState(state, client).map((walletAccount) => JSON.stringify(walletAccount)).sort().join("-");
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/modules/mfa/isUserMissingMfaAuth/isUserMissingMfaAuth.ts
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the user requires additional MFA authentication.
|
|
29
|
+
*
|
|
30
|
+
* This function determines if the current user session requires
|
|
31
|
+
* additional multi-factor authentication to access certain features.
|
|
32
|
+
*
|
|
33
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
34
|
+
* @returns True if the user needs additional MFA authentication, false otherwise.
|
|
35
|
+
* @not-instrumented
|
|
36
|
+
*/
|
|
37
|
+
const isUserMissingMfaAuth = (client = getDefaultClient()) => {
|
|
38
|
+
const user = client.user;
|
|
39
|
+
assertDefined(user, "User not logged in");
|
|
40
|
+
return Boolean(user.scope?.includes("requiresAdditionalAuth"));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/modules/wallets/getWalletProviders/getWalletProviders.ts
|
|
45
|
+
/**
|
|
46
|
+
* Get all available wallet providers to interact with internally.
|
|
47
|
+
* @not-instrumented
|
|
48
|
+
*/
|
|
49
|
+
const getWalletProviders = (client) => {
|
|
50
|
+
return getWalletProviderRegistry(client).listProviders();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts
|
|
55
|
+
/** @not-instrumented */
|
|
56
|
+
const isWaasWalletProvider = (walletProvider) => {
|
|
57
|
+
return walletProvider.key.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts
|
|
62
|
+
/** @not-instrumented */
|
|
63
|
+
const findWaasWalletProviderByChain = ({ chain }, client) => {
|
|
64
|
+
const providers = getWalletProviders(client);
|
|
65
|
+
const waasProviderKey = formatWalletProviderKey({
|
|
66
|
+
chain,
|
|
67
|
+
displayName: DYNAMIC_WAAS_METADATA.displayName,
|
|
68
|
+
walletProviderType: WalletProviderEnum.EmbeddedWallet
|
|
69
|
+
});
|
|
70
|
+
const waasProvider = providers.find((provider) => provider.key === waasProviderKey && provider.chain === chain);
|
|
71
|
+
if (!waasProvider || !isWaasWalletProvider(waasProvider)) return null;
|
|
72
|
+
return waasProvider;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts
|
|
77
|
+
/**
|
|
78
|
+
* This function determines whether the provided wallet account is a Dynamic
|
|
79
|
+
* WaaS wallet account.
|
|
80
|
+
*
|
|
81
|
+
* @param params.walletAccount - The wallet account to check.
|
|
82
|
+
* @returns True if the wallet account is a WaaS wallet account, false otherwise.
|
|
83
|
+
* @not-instrumented
|
|
84
|
+
*/
|
|
85
|
+
const isWaasWalletAccount = ({ walletAccount }) => {
|
|
86
|
+
return walletAccount.walletProviderKey.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts
|
|
91
|
+
/** @not-instrumented */
|
|
92
|
+
const restoreUserSharesForAllWalletAccounts = async (client) => {
|
|
93
|
+
/**
|
|
94
|
+
* Restoring the user shares will fails if the user is missing the MFA auth.
|
|
95
|
+
* This early return prevents the attempt to restore the user shares to fail
|
|
96
|
+
* when we know it will fails and just add noise to the logs.
|
|
97
|
+
*/
|
|
98
|
+
if (isUserMissingMfaAuth(client)) return;
|
|
99
|
+
const waasWalletAccounts = getWalletAccounts(client).filter((walletAccount) => isWaasWalletAccount({ walletAccount }));
|
|
100
|
+
await Promise.all(waasWalletAccounts.map(async (walletAccount) => {
|
|
101
|
+
const provider = findWaasWalletProviderByChain({ chain: walletAccount.chain }, client);
|
|
102
|
+
/**
|
|
103
|
+
* The environment might not have the embedded wallet extensions installed.
|
|
104
|
+
* In that case there is no provider for the chain and we can skip restoring the user share.
|
|
105
|
+
*/
|
|
106
|
+
if (!provider) return;
|
|
107
|
+
return provider.restoreUserShareForWalletAccount({ walletAccount });
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/modules/auth/decodeJwt/decodeJwt.ts
|
|
113
|
+
/**
|
|
114
|
+
* Decodes a JWT token and returns the full payload.
|
|
115
|
+
*
|
|
116
|
+
* This function extracts and returns the complete JWT payload including scopes,
|
|
117
|
+
* expiration time, and other claims.
|
|
118
|
+
*
|
|
119
|
+
* @param jwt - The JWT token string.
|
|
120
|
+
* @returns The decoded JWT payload object.
|
|
121
|
+
* @throws InvalidParamError if the token is invalid or cannot be decoded.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const payload = decodeJwt(jwt);
|
|
126
|
+
* // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }
|
|
127
|
+
* ```
|
|
128
|
+
* @not-instrumented
|
|
129
|
+
*/
|
|
130
|
+
const decodeJwt = (jwt) => {
|
|
131
|
+
try {
|
|
132
|
+
const parts = jwt.split(".");
|
|
133
|
+
if (parts.length !== 3) throw new InvalidParamError("Invalid JWT format");
|
|
134
|
+
const base64Payload = parts[1].replaceAll("-", "+").replaceAll("_", "/");
|
|
135
|
+
const paddedPayload = base64Payload + "=".repeat((4 - base64Payload.length % 4) % 4);
|
|
136
|
+
const decodedPayload = atob(paddedPayload);
|
|
137
|
+
return JSON.parse(decodedPayload);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error instanceof InvalidParamError) throw error;
|
|
140
|
+
throw new InvalidParamError(`Failed to decode JWT: ${error instanceof Error ? error.message : String(error)}`);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts
|
|
146
|
+
/**
|
|
147
|
+
* Normalizes scopes by deduplicating and sorting them.
|
|
148
|
+
* This creates a canonical representation for comparison.
|
|
149
|
+
*
|
|
150
|
+
* @param scopes - Array of scope strings (may contain duplicates)
|
|
151
|
+
* @returns Normalized, sorted array of unique scopes
|
|
152
|
+
* @not-instrumented
|
|
153
|
+
*/
|
|
154
|
+
const normalizeScopes = (scopes) => {
|
|
155
|
+
return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts
|
|
160
|
+
/**
|
|
161
|
+
* Validates and parses an elevated access token from a JWT string.
|
|
162
|
+
* Extracts scopes, expiration, and validates the token structure.
|
|
163
|
+
*
|
|
164
|
+
* Policy decisions:
|
|
165
|
+
* - Tokens without scopes are rejected (returns null)
|
|
166
|
+
* - Tokens with empty scopes array are rejected (returns null)
|
|
167
|
+
* - Tokens without exp field are rejected (returns null)
|
|
168
|
+
* - Expired tokens are rejected (returns null)
|
|
169
|
+
*
|
|
170
|
+
* @returns Parsed token data or null if token is invalid/expired
|
|
171
|
+
* @not-instrumented
|
|
172
|
+
*/
|
|
173
|
+
const parseElevatedAccessToken = ({ token }) => {
|
|
174
|
+
const payload = decodeJwt(token);
|
|
175
|
+
const filteredScopes = ((payload?.scope)?.split(" ") ?? []).filter((s) => s.length > 0);
|
|
176
|
+
const singleUse = payload.singleUse ?? false;
|
|
177
|
+
if (!filteredScopes || filteredScopes.length === 0) return null;
|
|
178
|
+
if (!payload.exp) return null;
|
|
179
|
+
const expiresAt = /* @__PURE__ */ new Date(payload.exp * 1e3);
|
|
180
|
+
if (expiresAt <= /* @__PURE__ */ new Date()) return null;
|
|
181
|
+
return {
|
|
182
|
+
expiresAt,
|
|
183
|
+
normalizedScopes: normalizeScopes(filteredScopes),
|
|
184
|
+
scopes: filteredScopes,
|
|
185
|
+
singleUse,
|
|
186
|
+
token
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts
|
|
192
|
+
/**
|
|
193
|
+
* Upserts an elevated access token into the current tokens array.
|
|
194
|
+
*
|
|
195
|
+
* Policy: Only one token per normalized scope-set is allowed.
|
|
196
|
+
* If a token with the same normalized scopes exists, it is replaced.
|
|
197
|
+
* This ensures we don't accumulate multiple tokens for the same scope combination.
|
|
198
|
+
*
|
|
199
|
+
* @param currentTokens - Current array of elevated access tokens
|
|
200
|
+
* @param newToken - New token to upsert
|
|
201
|
+
* @returns Updated array of tokens with the new token upserted
|
|
202
|
+
* @not-instrumented
|
|
203
|
+
*/
|
|
204
|
+
const upsertElevatedAccessToken = ({ currentTokens, newToken }) => {
|
|
205
|
+
const newScopeKey = normalizeScopes(newToken.scopes).join(" ");
|
|
206
|
+
return [...currentTokens.filter((existingToken) => {
|
|
207
|
+
return normalizeScopes(existingToken.scopes).join(" ") !== newScopeKey;
|
|
208
|
+
}), {
|
|
209
|
+
expiresAt: newToken.expiresAt,
|
|
210
|
+
scopes: newToken.scopes,
|
|
211
|
+
singleUse: newToken.singleUse,
|
|
212
|
+
token: newToken.token
|
|
213
|
+
}];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts
|
|
218
|
+
/** @not-instrumented */
|
|
219
|
+
const updateAuthFromVerifyResponse = ({ response }, client) => {
|
|
220
|
+
const core = getCore(client);
|
|
221
|
+
const previousState = { ...core.state.get() };
|
|
222
|
+
const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } = response;
|
|
223
|
+
const sessionExpiresAt = /* @__PURE__ */ new Date(expiresAt * 1e3);
|
|
224
|
+
const newState = {
|
|
225
|
+
legacyToken: jwt ?? null,
|
|
226
|
+
sessionExpiresAt,
|
|
227
|
+
token: minifiedJwt ?? null,
|
|
228
|
+
user
|
|
229
|
+
};
|
|
230
|
+
if (mfaToken) newState.mfaToken = mfaToken;
|
|
231
|
+
const currentTokens = core.state.get().elevatedAccessTokens || [];
|
|
232
|
+
newState.elevatedAccessTokens = currentTokens;
|
|
233
|
+
if (elevatedAccessToken) {
|
|
234
|
+
const parsedToken = parseElevatedAccessToken({ token: elevatedAccessToken });
|
|
235
|
+
if (parsedToken) newState.elevatedAccessTokens = upsertElevatedAccessToken({
|
|
236
|
+
currentTokens,
|
|
237
|
+
newToken: parsedToken
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
core.state.set(newState);
|
|
241
|
+
/**
|
|
242
|
+
* For customers using a sandbox environment with cookies enabled, we need to set the cookie
|
|
243
|
+
* programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically
|
|
244
|
+
* so customers can access the cookie from document.cookie consistently between sandbox and live environments.
|
|
245
|
+
*/
|
|
246
|
+
if (minifiedJwt && isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${sessionExpiresAt.toUTCString()}; path=/; SameSite=Lax`);
|
|
247
|
+
checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
|
|
248
|
+
if (!previousState.user && Boolean(newState.user)) restoreUserSharesForAllWalletAccounts(client);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts
|
|
253
|
+
/** @not-instrumented */
|
|
254
|
+
const getWalletProviderByKey = ({ walletProviderKey }, client) => {
|
|
255
|
+
const walletProvider = getWalletProviders(client).find((walletProvider$1) => walletProvider$1.key === walletProviderKey);
|
|
256
|
+
if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey });
|
|
257
|
+
return walletProvider;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
|
|
262
|
+
/** @not-instrumented */
|
|
263
|
+
const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client) => {
|
|
264
|
+
return client.user?.verifiedCredentials.find((vc) => vc.id === walletAccount.verifiedCredentialId);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
export { parseElevatedAccessToken as a, findWaasWalletProviderByChain as c, isUserMissingMfaAuth as d, checkAndRaiseWalletAccountsChangedEvent as f, upsertElevatedAccessToken as i, isWaasWalletProvider as l, getWalletProviderByKey as n, restoreUserSharesForAllWalletAccounts as o, emitWalletAccountsChangedEvent as p, updateAuthFromVerifyResponse as r, isWaasWalletAccount as s, getVerifiedCredentialForWalletAccount as t, getWalletProviders as u };
|
|
269
|
+
//# sourceMappingURL=getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js.map
|