@dynamic-labs-sdk/client 1.4.0 → 1.5.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-DEmLKJKZ.cjs → InvalidParamError-DKJhDrK8.cjs} +1007 -116
- package/dist/InvalidParamError-DKJhDrK8.cjs.map +1 -0
- package/dist/{InvalidParamError-BPMi0iWC.esm.js → InvalidParamError-DWjMfOZ5.esm.js} +800 -92
- package/dist/InvalidParamError-DWjMfOZ5.esm.js.map +1 -0
- package/dist/{InvalidParamError-CDmVW2DS.native.esm.js → InvalidParamError-DkAMYJOW.native.esm.js} +833 -92
- package/dist/InvalidParamError-DkAMYJOW.native.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-Cntietge.esm.js → NotWaasWalletAccountError-BVrvQzLz.native.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-BVrvQzLz.native.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-Chpne8_Q.native.esm.js → NotWaasWalletAccountError-C7NUlvvM.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-C7NUlvvM.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-BZsBHRQe.cjs → NotWaasWalletAccountError-CHzpa9kk.cjs} +4 -4
- package/dist/NotWaasWalletAccountError-CHzpa9kk.cjs.map +1 -0
- package/dist/core.cjs +45 -23
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +29 -8
- 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/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-szJOsbQN.cjs → getNetworkProviderFromNetworkId-BJ27N-7S.cjs} +44 -341
- package/dist/getNetworkProviderFromNetworkId-BJ27N-7S.cjs.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-JGrKwBj7.native.esm.js → getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js} +38 -299
- package/dist/getNetworkProviderFromNetworkId-Bs1kQdWk.native.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-CEeFL-gV.esm.js → getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js} +42 -270
- package/dist/getNetworkProviderFromNetworkId-Cqp9eRSs.esm.js.map +1 -0
- package/dist/{getSignedSessionId-BOx1nFt_.esm.js → getSignedSessionId-CDdKrnw6.esm.js} +3 -3
- package/dist/{getSignedSessionId-BOx1nFt_.esm.js.map → getSignedSessionId-CDdKrnw6.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-BxOK-Tdo.cjs → getSignedSessionId-CHDHr-hY.cjs} +3 -3
- package/dist/{getSignedSessionId-BxOK-Tdo.cjs.map → getSignedSessionId-CHDHr-hY.cjs.map} +1 -1
- package/dist/{getSignedSessionId-B5DikCap.native.esm.js → getSignedSessionId-D3KQrN8W.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-B5DikCap.native.esm.js.map → getSignedSessionId-D3KQrN8W.native.esm.js.map} +1 -1
- package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js +269 -0
- package/dist/getVerifiedCredentialForWalletAccount-BuUCX040.esm.js.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js +269 -0
- package/dist/getVerifiedCredentialForWalletAccount-Ciac5d5L.native.esm.js.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs +346 -0
- package/dist/getVerifiedCredentialForWalletAccount-gCx0smU8.cjs.map +1 -0
- package/dist/index.cjs +580 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +514 -194
- 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-B0xNvBpU.native.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-DUvZEpjA.native.esm.js.map → isMfaRequiredForAction-B0xNvBpU.native.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-6N6JB7wa.cjs → isMfaRequiredForAction-CLMvTTwl.cjs} +2 -2
- package/dist/{isMfaRequiredForAction-6N6JB7wa.cjs.map → isMfaRequiredForAction-CLMvTTwl.cjs.map} +1 -1
- package/dist/{isMfaRequiredForAction-D9p_du8C.esm.js → isMfaRequiredForAction-C_QPI1LH.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-D9p_du8C.esm.js.map → isMfaRequiredForAction-C_QPI1LH.esm.js.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/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.native.esm.js +3 -3
- package/package.json +4 -4
- 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/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
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
2
28
|
let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
|
|
29
|
+
let zod_mini = require("zod/mini");
|
|
30
|
+
zod_mini = __toESM(zod_mini);
|
|
3
31
|
|
|
4
32
|
//#region package.json
|
|
5
33
|
var name = "@dynamic-labs-sdk/client";
|
|
6
|
-
var version = "1.
|
|
34
|
+
var version = "1.5.0";
|
|
7
35
|
var dependencies = {
|
|
8
36
|
"@dynamic-labs-sdk/assert-package-version": "workspace:*",
|
|
9
|
-
"@dynamic-labs-wallet/browser-wallet-client": "
|
|
10
|
-
"@dynamic-labs-wallet/forward-mpc-client": "0.
|
|
37
|
+
"@dynamic-labs-wallet/browser-wallet-client": "1.0.7",
|
|
38
|
+
"@dynamic-labs-wallet/forward-mpc-client": "0.10.1",
|
|
11
39
|
"@dynamic-labs/sdk-api-core": "catalog:",
|
|
12
40
|
"@simplewebauthn/browser": "13.1.0",
|
|
13
41
|
"ably": "2.17.1",
|
|
@@ -909,109 +937,186 @@ const createDeviceSignatureHeadersMiddleware = (client) => {
|
|
|
909
937
|
};
|
|
910
938
|
|
|
911
939
|
//#endregion
|
|
912
|
-
//#region src/
|
|
913
|
-
|
|
914
|
-
|
|
940
|
+
//#region src/utils/setCookie/setCookie.ts
|
|
941
|
+
/**
|
|
942
|
+
* Sefelly sets the cookie in the browser.
|
|
943
|
+
* @not-instrumented
|
|
944
|
+
*/
|
|
945
|
+
const setCookie = (cookie) => {
|
|
946
|
+
document.cookie = cookie;
|
|
947
|
+
};
|
|
948
|
+
|
|
949
|
+
//#endregion
|
|
950
|
+
//#region src/modules/clientEvents/clientEvents.ts
|
|
951
|
+
/**
|
|
952
|
+
* Adds an event listener for Dynamic client events.
|
|
953
|
+
*
|
|
954
|
+
* This function allows you to listen for various events emitted by the Dynamic client,
|
|
955
|
+
* such as authentication state changes, wallet connections, and more.
|
|
956
|
+
*
|
|
957
|
+
* @param params.event - The event name to listen for.
|
|
958
|
+
* @param params.listener - The callback function to execute when the event is fired.
|
|
959
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
960
|
+
* @returns A function that can be called to remove the listener.
|
|
961
|
+
* @not-instrumented
|
|
962
|
+
*/
|
|
963
|
+
const onEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
964
|
+
const { eventEmitter } = getCore(client);
|
|
965
|
+
eventEmitter.on(event, listener);
|
|
966
|
+
return () => {
|
|
967
|
+
eventEmitter.off(event, listener);
|
|
968
|
+
};
|
|
969
|
+
};
|
|
970
|
+
/**
|
|
971
|
+
* Removes an event listener from Dynamic client events.
|
|
972
|
+
*
|
|
973
|
+
* This function unsubscribes a previously registered event listener
|
|
974
|
+
* from the specified Dynamic client event.
|
|
975
|
+
*
|
|
976
|
+
* @param params.event - The event name to remove the listener from.
|
|
977
|
+
* @param params.listener - The callback function to remove.
|
|
978
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
979
|
+
* @not-instrumented
|
|
980
|
+
*/
|
|
981
|
+
const offEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
982
|
+
const { eventEmitter } = getCore(client);
|
|
983
|
+
eventEmitter.off(event, listener);
|
|
984
|
+
};
|
|
985
|
+
/**
|
|
986
|
+
* Adds a one-time event listener for Dynamic client events.
|
|
987
|
+
*
|
|
988
|
+
* This function listens for an event that will automatically remove itself
|
|
989
|
+
* after being triggered once.
|
|
990
|
+
*
|
|
991
|
+
* @param params.event - The event name to listen for.
|
|
992
|
+
* @param params.listener - The callback function to execute when the event is fired.
|
|
993
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
994
|
+
* @returns A function that can be called to remove the listener before it fires.
|
|
995
|
+
* @not-instrumented
|
|
996
|
+
*/
|
|
997
|
+
const onceEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
998
|
+
const { eventEmitter } = getCore(client);
|
|
999
|
+
eventEmitter.once(event, listener);
|
|
1000
|
+
return () => {
|
|
1001
|
+
eventEmitter.off(event, listener);
|
|
1002
|
+
};
|
|
1003
|
+
};
|
|
1004
|
+
/**
|
|
1005
|
+
* Emits a Dynamic client event.
|
|
1006
|
+
*
|
|
1007
|
+
* This function triggers an event that will be received by all registered
|
|
1008
|
+
* listeners for the specified event type.
|
|
1009
|
+
*
|
|
1010
|
+
* @param params.event - The event name to emit.
|
|
1011
|
+
* @param params.args - The arguments to pass to event listeners.
|
|
1012
|
+
* @param client - The Dynamic client instance.
|
|
1013
|
+
* @not-instrumented
|
|
1014
|
+
*/
|
|
1015
|
+
const emitEvent = ({ event, args }, client) => {
|
|
1016
|
+
const { eventEmitter } = getCore(client);
|
|
1017
|
+
eventEmitter.emit(event, args);
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
|
|
1022
|
+
/**
|
|
1023
|
+
* This error is thrown when the `retryOnFail` function is called with an invalid
|
|
1024
|
+
* number of retries (i.e. less than 0).
|
|
1025
|
+
*/
|
|
1026
|
+
var InvalidRetryOnFailCallError = class extends BaseError {
|
|
1027
|
+
constructor(maxRetries) {
|
|
915
1028
|
super({
|
|
916
|
-
cause,
|
|
917
|
-
code: "
|
|
1029
|
+
cause: null,
|
|
1030
|
+
code: "invalid_retry_on_fail_call_error",
|
|
918
1031
|
docsUrl: null,
|
|
919
|
-
name: "
|
|
920
|
-
shortMessage:
|
|
1032
|
+
name: "InvalidRetryOnFailCallError",
|
|
1033
|
+
shortMessage: `Invalid retries parameter for retryOnFail call: ${maxRetries}`
|
|
921
1034
|
});
|
|
922
1035
|
}
|
|
923
1036
|
};
|
|
924
1037
|
|
|
925
1038
|
//#endregion
|
|
926
|
-
//#region src/
|
|
1039
|
+
//#region src/utils/retryOnFail/retryOnFail.ts
|
|
927
1040
|
/** @not-instrumented */
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
} catch {}
|
|
935
|
-
throw new UnauthorizedError({ cause });
|
|
1041
|
+
const retryOnFail = async ({ delay = 0, fn, maxRetries }) => {
|
|
1042
|
+
for (let retry = 0; retry <= maxRetries; retry++) try {
|
|
1043
|
+
return await fn();
|
|
1044
|
+
} catch (error) {
|
|
1045
|
+
if (retry >= maxRetries) throw error;
|
|
1046
|
+
if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
|
|
936
1047
|
}
|
|
937
|
-
|
|
938
|
-
|
|
1048
|
+
/**
|
|
1049
|
+
* Reaching this point should never happen and this
|
|
1050
|
+
* error is thrown to help us debug the issue.
|
|
1051
|
+
*/
|
|
1052
|
+
throw new InvalidRetryOnFailCallError(maxRetries);
|
|
1053
|
+
};
|
|
939
1054
|
|
|
940
1055
|
//#endregion
|
|
941
|
-
//#region src/
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
const settings = {
|
|
952
|
-
basePath: core.apiBaseUrl,
|
|
953
|
-
headers: {
|
|
954
|
-
"Content-Type": "application/json",
|
|
955
|
-
[DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
|
|
956
|
-
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
957
|
-
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
958
|
-
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
959
|
-
...core.getApiHeaders(),
|
|
960
|
-
...options.headers
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
964
|
-
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
965
|
-
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
966
|
-
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
967
|
-
if (options.elevatedAccessTokenScope) {
|
|
968
|
-
const elevatedToken = __getElevatedAccessToken_wrapped({ scope: options.elevatedAccessTokenScope }, client);
|
|
969
|
-
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
1056
|
+
//#region src/errors/InvalidWalletProviderKeyError.ts
|
|
1057
|
+
var InvalidWalletProviderKeyError = class extends BaseError {
|
|
1058
|
+
constructor(value) {
|
|
1059
|
+
super({
|
|
1060
|
+
cause: null,
|
|
1061
|
+
code: "invalid_wallet_provider_key",
|
|
1062
|
+
docsUrl: null,
|
|
1063
|
+
name: "InvalidWalletProviderKeyError",
|
|
1064
|
+
shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`
|
|
1065
|
+
});
|
|
970
1066
|
}
|
|
971
|
-
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
972
|
-
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
973
|
-
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
974
|
-
return new _dynamic_labs_sdk_api_core.SDKApi(new _dynamic_labs_sdk_api_core.Configuration({
|
|
975
|
-
...settings,
|
|
976
|
-
fetchApi: core.fetch,
|
|
977
|
-
middleware: [
|
|
978
|
-
createDeviceSignatureHeadersMiddleware(client),
|
|
979
|
-
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
980
|
-
createUnauthorizedMiddleware()
|
|
981
|
-
]
|
|
982
|
-
}));
|
|
983
1067
|
};
|
|
984
1068
|
|
|
985
1069
|
//#endregion
|
|
986
|
-
//#region src/
|
|
987
|
-
/**
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
*/
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
});
|
|
1070
|
+
//#region src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts
|
|
1071
|
+
/** @not-instrumented */
|
|
1072
|
+
const splitWalletProviderKey = (walletProviderKey) => {
|
|
1073
|
+
const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] = walletProviderKey.split(":");
|
|
1074
|
+
if (!normalizedWalletNameWithChain || !Object.values(_dynamic_labs_sdk_api_core.WalletProviderEnum).includes(walletProviderType) || rest.length > 0) throw new InvalidWalletProviderKeyError(walletProviderKey);
|
|
1075
|
+
return {
|
|
1076
|
+
normalizedWalletNameWithChain,
|
|
1077
|
+
suffix,
|
|
1078
|
+
walletProviderType
|
|
1079
|
+
};
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
//#endregion
|
|
1083
|
+
//#region src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts
|
|
1084
|
+
/** @not-instrumented */
|
|
1085
|
+
const normalizeAddress = ({ address, chain }) => {
|
|
1086
|
+
let normalizedAddress = address;
|
|
1087
|
+
if (normalizedAddress?.startsWith("0x")) normalizedAddress = normalizedAddress.slice(2);
|
|
1088
|
+
normalizedAddress = ["EVM", "FLOW"].includes(chain) ? normalizedAddress?.toLowerCase() : normalizedAddress;
|
|
1089
|
+
return normalizedAddress;
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
//#endregion
|
|
1093
|
+
//#region src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts
|
|
1094
|
+
/** @not-instrumented */
|
|
1095
|
+
const formatWalletAccountId = ({ address, chain, walletProviderKey }) => {
|
|
1096
|
+
const { normalizedWalletNameWithChain } = splitWalletProviderKey(walletProviderKey);
|
|
1097
|
+
return `${normalizedWalletNameWithChain}:${normalizeAddress({
|
|
1098
|
+
address,
|
|
1099
|
+
chain
|
|
1100
|
+
})}`;
|
|
1013
1101
|
};
|
|
1014
1102
|
|
|
1103
|
+
//#endregion
|
|
1104
|
+
//#region src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts
|
|
1105
|
+
/** @not-instrumented */
|
|
1106
|
+
const convertUnverifiedWalletAccountToWalletAccount = ({ unverifiedWalletAccount }) => ({
|
|
1107
|
+
address: unverifiedWalletAccount.address,
|
|
1108
|
+
addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,
|
|
1109
|
+
chain: unverifiedWalletAccount.chain,
|
|
1110
|
+
id: formatWalletAccountId({
|
|
1111
|
+
address: unverifiedWalletAccount.address,
|
|
1112
|
+
chain: unverifiedWalletAccount.chain,
|
|
1113
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
1114
|
+
}),
|
|
1115
|
+
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
1116
|
+
verifiedCredentialId: null,
|
|
1117
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1015
1120
|
//#endregion
|
|
1016
1121
|
//#region src/modules/wallets/constants.ts
|
|
1017
1122
|
const CHAINS_INFO_MAP = {
|
|
@@ -1033,6 +1138,7 @@ const CHAINS_INFO_MAP = {
|
|
|
1033
1138
|
BTC: {
|
|
1034
1139
|
apiChainName: "bitcoin",
|
|
1035
1140
|
blockchainName: "Bitcoin",
|
|
1141
|
+
legacyWalletBookAliases: ["btc"],
|
|
1036
1142
|
verifiedCredentialChainName: "bip122"
|
|
1037
1143
|
},
|
|
1038
1144
|
COSMOS: {
|
|
@@ -1063,6 +1169,7 @@ const CHAINS_INFO_MAP = {
|
|
|
1063
1169
|
SOL: {
|
|
1064
1170
|
apiChainName: "solana",
|
|
1065
1171
|
blockchainName: "Solana",
|
|
1172
|
+
legacyWalletBookAliases: ["sol"],
|
|
1066
1173
|
verifiedCredentialChainName: "solana",
|
|
1067
1174
|
waasChainNameOverride: "SVM"
|
|
1068
1175
|
},
|
|
@@ -1074,6 +1181,7 @@ const CHAINS_INFO_MAP = {
|
|
|
1074
1181
|
STARK: {
|
|
1075
1182
|
apiChainName: "starknet",
|
|
1076
1183
|
blockchainName: "Starknet",
|
|
1184
|
+
legacyWalletBookAliases: ["stark"],
|
|
1077
1185
|
verifiedCredentialChainName: "starknet"
|
|
1078
1186
|
},
|
|
1079
1187
|
STELLAR: {
|
|
@@ -1113,44 +1221,671 @@ const getChainFromVerifiedCredentialChain = (verifiedCredentialChain) => {
|
|
|
1113
1221
|
};
|
|
1114
1222
|
|
|
1115
1223
|
//#endregion
|
|
1116
|
-
//#region src/
|
|
1117
|
-
|
|
1118
|
-
|
|
1224
|
+
//#region src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts
|
|
1225
|
+
/**
|
|
1226
|
+
* Format the raw wallet name and chain to get the value we can use for
|
|
1227
|
+
* verified credentials' `walletName` field.
|
|
1228
|
+
* @not-instrumented
|
|
1229
|
+
*/
|
|
1230
|
+
const normalizeWalletNameWithChain = ({ displayName, chain }) => {
|
|
1231
|
+
const sanitizedWalletName = displayName.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
1232
|
+
const chainLowered = chain.toLocaleLowerCase();
|
|
1233
|
+
if (sanitizedWalletName.endsWith(chainLowered)) return sanitizedWalletName;
|
|
1234
|
+
return `${sanitizedWalletName}${chainLowered}`;
|
|
1235
|
+
};
|
|
1119
1236
|
|
|
1120
1237
|
//#endregion
|
|
1121
|
-
//#region src/modules/
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1238
|
+
//#region src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts
|
|
1239
|
+
/**
|
|
1240
|
+
* Assembles the wallet provider key from the wallet name, chain, and wallet provider type.
|
|
1241
|
+
*
|
|
1242
|
+
* The suffix is optional and can be used to add a uniquely identifying string to the key, which
|
|
1243
|
+
* might be necessary for some wallet providers (like Wallet Connect).
|
|
1244
|
+
*
|
|
1245
|
+
* IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account
|
|
1246
|
+
* to not be able to find its wallet provider when connecting to a new device (it won't be possible
|
|
1247
|
+
* to determine the full key just from the Verified Credential data).
|
|
1248
|
+
* @not-instrumented
|
|
1249
|
+
*/
|
|
1250
|
+
const formatWalletProviderKey = ({ suffix, chain, displayName, walletProviderType }) => {
|
|
1251
|
+
return `${normalizeWalletNameWithChain({
|
|
1252
|
+
chain,
|
|
1253
|
+
displayName
|
|
1254
|
+
})}:${walletProviderType}${suffix ? `:${suffix}` : ""}`;
|
|
1128
1255
|
};
|
|
1129
1256
|
|
|
1130
1257
|
//#endregion
|
|
1131
|
-
//#region src/
|
|
1132
|
-
|
|
1133
|
-
|
|
1258
|
+
//#region src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts
|
|
1259
|
+
/** @not-instrumented */
|
|
1260
|
+
const getWalletProviderKeyFromVerifiedCredential = ({ verifiedCredential }, client) => {
|
|
1261
|
+
const { walletProviderKeyMap } = getCore(client).state.get();
|
|
1262
|
+
const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];
|
|
1263
|
+
if (storedWalletProviderKey) return { walletProviderKey: storedWalletProviderKey };
|
|
1264
|
+
/**
|
|
1265
|
+
* We fallback to comprising the wallet provider key from walletName and walletProvider.
|
|
1266
|
+
*
|
|
1267
|
+
* Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider
|
|
1268
|
+
* keys, so this won't be enough for them.
|
|
1269
|
+
* Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider
|
|
1270
|
+
* and will require reconnection.
|
|
1271
|
+
* Read walletProvider.types.ts for more info.
|
|
1272
|
+
*/
|
|
1273
|
+
assertDefined(verifiedCredential.walletName, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`);
|
|
1274
|
+
assertDefined(verifiedCredential.walletProvider, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`);
|
|
1275
|
+
assertDefined(verifiedCredential.chain, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`);
|
|
1276
|
+
return { walletProviderKey: formatWalletProviderKey({
|
|
1277
|
+
chain: getChainFromVerifiedCredentialChain(verifiedCredential.chain),
|
|
1278
|
+
displayName: verifiedCredential.walletName,
|
|
1279
|
+
walletProviderType: verifiedCredential.walletProvider
|
|
1280
|
+
}) };
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
//#endregion
|
|
1284
|
+
//#region src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts
|
|
1285
|
+
/** @not-instrumented */
|
|
1286
|
+
const convertVerifiedCredentialToWalletAccount = ({ verifiedCredential }, client) => {
|
|
1287
|
+
assertDefined(verifiedCredential.address, "Missing address in verified credential");
|
|
1288
|
+
assertDefined(verifiedCredential.chain, "Missing chain in verified credential");
|
|
1289
|
+
const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);
|
|
1290
|
+
const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential({ verifiedCredential }, client);
|
|
1291
|
+
const walletAccountId = formatWalletAccountId({
|
|
1292
|
+
address: verifiedCredential.address,
|
|
1293
|
+
chain,
|
|
1294
|
+
walletProviderKey
|
|
1295
|
+
});
|
|
1296
|
+
return {
|
|
1297
|
+
address: verifiedCredential.address,
|
|
1298
|
+
addressesWithTypes: verifiedCredential.walletAdditionalAddresses,
|
|
1299
|
+
chain,
|
|
1300
|
+
hardwareWalletVendor: verifiedCredential.walletProperties?.hardwareWallet,
|
|
1301
|
+
id: walletAccountId,
|
|
1302
|
+
lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,
|
|
1303
|
+
verifiedCredentialId: verifiedCredential.id,
|
|
1304
|
+
walletProviderKey
|
|
1305
|
+
};
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
//#endregion
|
|
1309
|
+
//#region src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts
|
|
1310
|
+
/** @not-instrumented */
|
|
1311
|
+
const getWalletAccountsFromState = ({ unverifiedWalletAccounts, user }, client) => {
|
|
1312
|
+
const walletAccountsMap = /* @__PURE__ */ new Map();
|
|
1313
|
+
/**
|
|
1314
|
+
* Handle the unverified wallet accounts before the user verified credentials
|
|
1315
|
+
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
1316
|
+
*/
|
|
1317
|
+
unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {
|
|
1318
|
+
const walletAccount = convertUnverifiedWalletAccountToWalletAccount({ unverifiedWalletAccount });
|
|
1319
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
1320
|
+
});
|
|
1321
|
+
(user?.verifiedCredentials ?? []).filter((verified) => verified.format === _dynamic_labs_sdk_api_core.JwtVerifiedCredentialFormatEnum.Blockchain).forEach((verifiedWalletAccount) => {
|
|
1322
|
+
const walletAccount = convertVerifiedCredentialToWalletAccount({ verifiedCredential: verifiedWalletAccount }, client);
|
|
1323
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
1324
|
+
});
|
|
1325
|
+
return Array.from(walletAccountsMap.values());
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
//#endregion
|
|
1329
|
+
//#region src/modules/wallets/getWalletAccounts/getWalletAccounts.ts
|
|
1330
|
+
/**
|
|
1331
|
+
* Retrieves all wallet accounts associated with the current session.
|
|
1332
|
+
*
|
|
1333
|
+
* This function returns both verified and unverified wallet accounts,
|
|
1334
|
+
* combining data from user credentials and local unverified accounts.
|
|
1335
|
+
* You can differentiate between verified and unverified wallet accounts by
|
|
1336
|
+
* checking the `verifiedCredentialId` property.
|
|
1337
|
+
*
|
|
1338
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1339
|
+
* @returns An array of wallet accounts associated with the session.
|
|
1340
|
+
* @not-instrumented
|
|
1341
|
+
*/
|
|
1342
|
+
const getWalletAccounts = (client = getDefaultClient()) => {
|
|
1343
|
+
const { unverifiedWalletAccounts, user } = getCore(client).state.get();
|
|
1344
|
+
return getWalletAccountsFromState({
|
|
1345
|
+
unverifiedWalletAccounts,
|
|
1346
|
+
user
|
|
1347
|
+
}, client);
|
|
1348
|
+
};
|
|
1349
|
+
|
|
1350
|
+
//#endregion
|
|
1351
|
+
//#region src/modules/auth/isSignedIn/isSignedIn.ts
|
|
1352
|
+
/**
|
|
1353
|
+
* Checks if the user is currently signed in to the Dynamic client.
|
|
1354
|
+
*
|
|
1355
|
+
* The client is considered to be in a signed in state if a user has
|
|
1356
|
+
* authenticated or if the client has at least one wallet connected.
|
|
1357
|
+
*
|
|
1358
|
+
* @deprecated What counts as "signed in" is your app's business logic, not the
|
|
1359
|
+
* SDK's. This helper bakes in one opinion (a user OR any connected wallet),
|
|
1360
|
+
* which rarely matches every app and forces a dependency on us for every
|
|
1361
|
+
* variation. Compose your own check from the underlying primitives instead —
|
|
1362
|
+
* e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
|
|
1363
|
+
* layer in whatever your app requires (device registration, completed
|
|
1364
|
+
* onboarding, satisfied MFA, a required embedded wallet, …). See the
|
|
1365
|
+
* "Check if signed in" guide:
|
|
1366
|
+
* https://www.dynamic.xyz/docs/javascript/user-session-management
|
|
1367
|
+
*
|
|
1368
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1369
|
+
* @returns True if the user is signed in, false otherwise.
|
|
1370
|
+
* @not-instrumented
|
|
1371
|
+
*/
|
|
1372
|
+
const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
|
|
1373
|
+
|
|
1374
|
+
//#endregion
|
|
1375
|
+
//#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
|
|
1376
|
+
/** @not-instrumented */
|
|
1377
|
+
const createStorageKeySchema = (params) => {
|
|
1378
|
+
return params;
|
|
1379
|
+
};
|
|
1380
|
+
|
|
1381
|
+
//#endregion
|
|
1382
|
+
//#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
|
|
1383
|
+
/**
|
|
1384
|
+
* The schema to track the expiration time of the project settings.
|
|
1385
|
+
*/
|
|
1386
|
+
const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
|
|
1387
|
+
key: "projectSettingsExpiration",
|
|
1388
|
+
schema: zod_mini.number()
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
//#endregion
|
|
1392
|
+
//#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
|
|
1393
|
+
/**
|
|
1394
|
+
* Expiration time of the project settings in milliseconds.
|
|
1395
|
+
*/
|
|
1396
|
+
const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
|
|
1397
|
+
/**
|
|
1398
|
+
* Fetches and updates the project settings from the API.
|
|
1399
|
+
*
|
|
1400
|
+
* This function retrieves the latest project configuration settings
|
|
1401
|
+
* from Dynamic's servers, including authentication options, enabled chains,
|
|
1402
|
+
* and security configurations. The settings are cached for performance.
|
|
1403
|
+
*
|
|
1404
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1405
|
+
* @returns A promise that resolves to the updated project settings.
|
|
1406
|
+
* @not-instrumented
|
|
1407
|
+
*/
|
|
1408
|
+
const fetchProjectSettings = async (client = getDefaultClient()) => {
|
|
1409
|
+
const core = getCore(client);
|
|
1410
|
+
const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
|
|
1411
|
+
if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
|
|
1412
|
+
const apiClient = createApiClient({}, client);
|
|
1413
|
+
core.logger.debug("[fetchProjectSettings] Fetching project settings...");
|
|
1414
|
+
const doFetch = async () => apiClient.getEnvironmentSettings({
|
|
1415
|
+
environmentId: core.environmentId,
|
|
1416
|
+
sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
|
|
1417
|
+
}, { credentials: "omit" });
|
|
1418
|
+
const projectSettings = await retryOnFail({
|
|
1419
|
+
fn: doFetch,
|
|
1420
|
+
maxRetries: 2
|
|
1421
|
+
});
|
|
1422
|
+
core.state.set({ projectSettings: projectSettings ?? null });
|
|
1423
|
+
await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
|
|
1424
|
+
return projectSettings;
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
//#endregion
|
|
1428
|
+
//#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
|
|
1429
|
+
/** @not-instrumented */
|
|
1430
|
+
const generateSessionKeys = async (client) => {
|
|
1431
|
+
const core = getCore(client);
|
|
1432
|
+
await core.keychain.removeKey("session");
|
|
1433
|
+
const publicKey = await core.keychain.generateKey("session");
|
|
1434
|
+
assertDefined(publicKey, "Public key not found");
|
|
1435
|
+
core.state.set({ sessionKeys: publicKey });
|
|
1436
|
+
return { publicKey };
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
//#endregion
|
|
1440
|
+
//#region src/errors/NoWalletProviderFoundError.ts
|
|
1441
|
+
var NoWalletProviderFoundError = class extends BaseError {
|
|
1442
|
+
constructor({ walletProviderKey }) {
|
|
1134
1443
|
super({
|
|
1135
1444
|
cause: null,
|
|
1136
|
-
code: "
|
|
1445
|
+
code: "no_wallet_provider_found_error",
|
|
1137
1446
|
docsUrl: null,
|
|
1138
|
-
name: "
|
|
1139
|
-
shortMessage:
|
|
1447
|
+
name: "NoWalletProviderFoundError",
|
|
1448
|
+
shortMessage: `No wallet provider found with key: ${walletProviderKey}`
|
|
1140
1449
|
});
|
|
1141
1450
|
}
|
|
1142
1451
|
};
|
|
1143
1452
|
|
|
1144
1453
|
//#endregion
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1454
|
+
//#region src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts
|
|
1455
|
+
/**
|
|
1456
|
+
* Creates a service accessor function that manages service instantiation and caching.
|
|
1457
|
+
* The returned function will either retrieve an existing service from the registry or
|
|
1458
|
+
* create a new one using the provided builder function.
|
|
1459
|
+
*
|
|
1460
|
+
* @template - The type of service to be created/accessed
|
|
1461
|
+
* @param key - Unique identifier for the service in the registry
|
|
1462
|
+
* @param builder - Function that creates the service instance when called with a DynamicClient
|
|
1463
|
+
* @not-instrumented
|
|
1464
|
+
*/
|
|
1465
|
+
const createRuntimeServiceAccessKey = (key, builder) => (client) => {
|
|
1466
|
+
const { runtimeServices } = getCore(client);
|
|
1467
|
+
const currentService = runtimeServices.getByKey(key);
|
|
1468
|
+
if (currentService) return currentService;
|
|
1469
|
+
const service = builder(client);
|
|
1470
|
+
runtimeServices.register(key, service);
|
|
1471
|
+
return service;
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1474
|
+
//#endregion
|
|
1475
|
+
//#region src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts
|
|
1476
|
+
/**
|
|
1477
|
+
* Creates a new wallet provider registry that manages wallet providers with priority-based registration.
|
|
1478
|
+
*
|
|
1479
|
+
* @returns The wallet provider registry instance
|
|
1480
|
+
*
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```typescript
|
|
1483
|
+
* const registry = createWalletProviderRegistry();
|
|
1484
|
+
*
|
|
1485
|
+
* registry.register({
|
|
1486
|
+
* priority: WalletProviderPriority.WALLET_SDK,
|
|
1487
|
+
* walletProvider: myWalletProvider
|
|
1488
|
+
* });
|
|
1489
|
+
*
|
|
1490
|
+
* const provider = registry.getByKey('my-wallet-key');
|
|
1491
|
+
* const providers = registry.listProviders();
|
|
1492
|
+
* ```
|
|
1493
|
+
* @not-instrumented
|
|
1494
|
+
*/
|
|
1495
|
+
const createWalletProviderRegistry = (client) => {
|
|
1496
|
+
const registry = /* @__PURE__ */ new Map();
|
|
1497
|
+
return {
|
|
1498
|
+
getByKey: (key) => registry.get(key)?.walletProvider,
|
|
1499
|
+
listProviderEntries: () => Array.from(registry.values()),
|
|
1500
|
+
listProviders: () => Array.from(registry.values()).map((v) => v.walletProvider),
|
|
1501
|
+
register: (args) => {
|
|
1502
|
+
const existingEntry = registry.get(args.walletProvider.key);
|
|
1503
|
+
if (existingEntry) {
|
|
1504
|
+
if (existingEntry.priority < args.priority) {
|
|
1505
|
+
registry.set(args.walletProvider.key, args);
|
|
1506
|
+
emitEvent({
|
|
1507
|
+
args: { walletProviderKey: args.walletProvider.key },
|
|
1508
|
+
event: "walletProviderChanged"
|
|
1509
|
+
}, client);
|
|
1510
|
+
}
|
|
1511
|
+
} else {
|
|
1512
|
+
registry.set(args.walletProvider.key, args);
|
|
1513
|
+
emitEvent({
|
|
1514
|
+
args: { walletProvider: args.walletProvider },
|
|
1515
|
+
event: "walletProviderRegistered"
|
|
1516
|
+
}, client);
|
|
1517
|
+
emitEvent({
|
|
1518
|
+
args: { walletProviderKey: args.walletProvider.key },
|
|
1519
|
+
event: "walletProviderChanged"
|
|
1520
|
+
}, client);
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
unregister: (key) => {
|
|
1524
|
+
registry.delete(key);
|
|
1525
|
+
emitEvent({
|
|
1526
|
+
args: { walletProviderKey: key },
|
|
1527
|
+
event: "walletProviderUnregistered"
|
|
1528
|
+
}, client);
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
|
+
//#endregion
|
|
1534
|
+
//#region src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts
|
|
1535
|
+
/**
|
|
1536
|
+
* This function provides access to a shared instance of the wallet provider registry.
|
|
1537
|
+
*
|
|
1538
|
+
* It ensures that the same registry instance is used throughout the client to maintaining
|
|
1539
|
+
* consistency of registered wallet providers across different parts of the codebase.
|
|
1540
|
+
*
|
|
1541
|
+
* @returns The wallet provider registry instance
|
|
1542
|
+
*
|
|
1543
|
+
* @example
|
|
1544
|
+
* ```typescript
|
|
1545
|
+
* // Get the registry instance
|
|
1546
|
+
* const registry = getWalletProviderRegistry();
|
|
1547
|
+
*
|
|
1548
|
+
* // Register a wallet provider
|
|
1549
|
+
* registry.register({
|
|
1550
|
+
* priority: WalletProviderPriority.WALLET_SDK,
|
|
1551
|
+
* walletProvider: myWalletProvider
|
|
1552
|
+
* });
|
|
1553
|
+
*
|
|
1554
|
+
* // Retrieve a specific provider
|
|
1555
|
+
* const provider = registry.getByKey('metamaskevm');
|
|
1556
|
+
* ```
|
|
1557
|
+
*/
|
|
1558
|
+
const getWalletProviderRegistry = createRuntimeServiceAccessKey("walletProviderRegistry", (client) => createWalletProviderRegistry(client));
|
|
1559
|
+
|
|
1560
|
+
//#endregion
|
|
1561
|
+
//#region src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts
|
|
1562
|
+
let WalletProviderPriority = /* @__PURE__ */ function(WalletProviderPriority$1) {
|
|
1563
|
+
/**
|
|
1564
|
+
* Highest priority should be used by wallet providers that implement
|
|
1565
|
+
* the most reliable wallet integration.
|
|
1566
|
+
* example: The SDK provided by the wallet provider.
|
|
1567
|
+
*/
|
|
1568
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SDK"] = 100] = "WALLET_SDK";
|
|
1569
|
+
/**
|
|
1570
|
+
* Medium priority should be used by wallet providers that implement
|
|
1571
|
+
* a wallet integration via some reliable standard.
|
|
1572
|
+
* example: A wallet provider that uses EIP6963 announcement.
|
|
1573
|
+
*/
|
|
1574
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SELF_ANNOUNCEMENT_STANDARD"] = 50] = "WALLET_SELF_ANNOUNCEMENT_STANDARD";
|
|
1575
|
+
/**
|
|
1576
|
+
* Low priority should be used by wallet providers that implement
|
|
1577
|
+
* a wallet integration on a less reliable standard.
|
|
1578
|
+
* example: A wallet provider that uses window.ethereum, where the
|
|
1579
|
+
* window key can be overridden by other extensions.
|
|
1580
|
+
*/
|
|
1581
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WINDOW_INJECT"] = 20] = "WINDOW_INJECT";
|
|
1582
|
+
return WalletProviderPriority$1;
|
|
1583
|
+
}({});
|
|
1584
|
+
|
|
1585
|
+
//#endregion
|
|
1586
|
+
//#region src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts
|
|
1587
|
+
/** @not-instrumented */
|
|
1588
|
+
const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
|
|
1589
|
+
const walletProvider = getWalletProviderRegistry(client).getByKey(walletAccount.walletProviderKey);
|
|
1590
|
+
if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey: walletAccount.walletProviderKey });
|
|
1591
|
+
return walletProvider;
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1594
|
+
//#endregion
|
|
1595
|
+
//#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
|
|
1596
|
+
/** @not-instrumented */
|
|
1597
|
+
const getAvailableWalletProvidersFromWalletAccounts = (client) => {
|
|
1598
|
+
const core = getCore(client);
|
|
1599
|
+
const walletProvidersMap = /* @__PURE__ */ new Map();
|
|
1600
|
+
getWalletAccounts(client).forEach((walletAccount) => {
|
|
1601
|
+
if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
|
|
1602
|
+
try {
|
|
1603
|
+
const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
1604
|
+
walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
|
|
1605
|
+
} catch (error) {
|
|
1606
|
+
core.logger.debug("Wallet provider not found for wallet account", {
|
|
1607
|
+
error,
|
|
1608
|
+
walletAccount: walletAccount.address
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
return Array.from(walletProvidersMap.values());
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
//#endregion
|
|
1616
|
+
//#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
|
|
1617
|
+
/**
|
|
1618
|
+
* Tear down every wallet provider on the client.
|
|
1619
|
+
*
|
|
1620
|
+
* Each provider's `destroy` is responsible for its own local + remote
|
|
1621
|
+
* cleanup. We swallow errors so a failing destroy on one provider does not
|
|
1622
|
+
* block teardown of the others (e.g. during logout).
|
|
1623
|
+
*
|
|
1624
|
+
* @not-instrumented
|
|
1625
|
+
*/
|
|
1626
|
+
const destroyWalletProviders = async ({ reason }, client) => {
|
|
1627
|
+
const core = getCore(client);
|
|
1628
|
+
const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
|
|
1629
|
+
await Promise.all(walletProviders.map(async (walletProvider) => {
|
|
1630
|
+
if (!walletProvider.destroy) return;
|
|
1631
|
+
try {
|
|
1632
|
+
await walletProvider.destroy({ reason });
|
|
1633
|
+
} catch (err) {
|
|
1634
|
+
core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
|
|
1635
|
+
}
|
|
1636
|
+
}));
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
//#endregion
|
|
1640
|
+
//#region src/modules/auth/consts.ts
|
|
1641
|
+
const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
|
|
1642
|
+
|
|
1643
|
+
//#endregion
|
|
1644
|
+
//#region src/modules/auth/logoutWithReason/logoutWithReason.ts
|
|
1645
|
+
/**
|
|
1646
|
+
* Logs the user out with an explicit reason.
|
|
1647
|
+
*
|
|
1648
|
+
* Revokes the session, clears auth state, terminates wallet providers, and
|
|
1649
|
+
* emits the `logout` client event with the given reason. The reason is also
|
|
1650
|
+
* captured as an argument on the function-instrumentation event, which is
|
|
1651
|
+
* how Datadog distinguishes between different logout causes.
|
|
1652
|
+
*
|
|
1653
|
+
* Use this instead of the public `logout` when triggering a logout from
|
|
1654
|
+
* internal or extension code — the caller owns the reason string, so the
|
|
1655
|
+
* telemetry correctly attributes *why* the logout happened.
|
|
1656
|
+
*
|
|
1657
|
+
* @param params - The logout params.
|
|
1658
|
+
* @param params.reason - Why the logout is being triggered. Extension authors
|
|
1659
|
+
* needing a reason outside the SDK catalog can cast with `as LogoutReason`.
|
|
1660
|
+
* @param client - The Dynamic client instance.
|
|
1661
|
+
* @instrumented
|
|
1662
|
+
*/
|
|
1663
|
+
const logoutWithReason = async ({ reason }, client) => {
|
|
1664
|
+
const core = getCore(client);
|
|
1665
|
+
core.logger.debug("[logoutWithReason] Logging out...", { reason });
|
|
1666
|
+
await destroyWalletProviders({ reason }, client);
|
|
1667
|
+
if (client.user !== null) {
|
|
1668
|
+
const apiClient = createApiClient({ skipSessionExpiryLogout: true }, client);
|
|
1669
|
+
try {
|
|
1670
|
+
await apiClient.revokeSession({ environmentId: core.environmentId });
|
|
1671
|
+
} catch (error) {
|
|
1672
|
+
core.logger.error("Failed to revoke session", error);
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* This deletes the auth cookie if it exists.
|
|
1676
|
+
* If the cookie doesn't exist, this sets a new cookie that expires immediately.
|
|
1677
|
+
*/
|
|
1678
|
+
if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
|
|
1679
|
+
}
|
|
1680
|
+
await core.keychain.removeKey("session");
|
|
1681
|
+
core.state.set({
|
|
1682
|
+
captchaToken: null,
|
|
1683
|
+
elevatedAccessTokens: [],
|
|
1684
|
+
legacyToken: null,
|
|
1685
|
+
mfaToken: null,
|
|
1686
|
+
sessionExpiresAt: null,
|
|
1687
|
+
sessionKeys: null,
|
|
1688
|
+
token: null,
|
|
1689
|
+
unverifiedWalletAccounts: [],
|
|
1690
|
+
user: null
|
|
1691
|
+
});
|
|
1692
|
+
emitEvent({
|
|
1693
|
+
args: { reason },
|
|
1694
|
+
event: "logout"
|
|
1695
|
+
}, client);
|
|
1696
|
+
fetchProjectSettings(client);
|
|
1697
|
+
generateSessionKeys(client);
|
|
1698
|
+
};
|
|
1699
|
+
const __logoutWithReason_impl = logoutWithReason;
|
|
1700
|
+
const __logoutWithReason_wrapped = instrumentFunction({
|
|
1701
|
+
fn: __logoutWithReason_impl,
|
|
1702
|
+
functionName: "logoutWithReason",
|
|
1703
|
+
getCore: () => {
|
|
1704
|
+
try {
|
|
1705
|
+
return getCore(getDefaultClient());
|
|
1706
|
+
} catch {
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
|
|
1712
|
+
//#endregion
|
|
1713
|
+
//#region src/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.ts
|
|
1714
|
+
const UNAUTHORIZED_STATUS = 401;
|
|
1715
|
+
/**
|
|
1716
|
+
* Creates middleware that ends the local session when an *authenticated*
|
|
1717
|
+
* request is rejected with a 401.
|
|
1718
|
+
*
|
|
1719
|
+
* A 401 on a request that carried an authenticated session means the backend
|
|
1720
|
+
* rejected our credentials, so the local session is stale and must be cleared.
|
|
1721
|
+
* The check is purely local (`client.user`) — we deliberately do not
|
|
1722
|
+
* re-validate over the network, because the 401 itself is the rejection signal
|
|
1723
|
+
* and re-validating would route back through this same middleware.
|
|
1724
|
+
*
|
|
1725
|
+
* Requests made without an authenticated session (e.g. pre-auth probes) are
|
|
1726
|
+
* ignored — there is no session to invalidate. Endpoints that legitimately
|
|
1727
|
+
* return 401 for non-session reasons opt out of this behavior by omitting the
|
|
1728
|
+
* middleware (see `skipSessionExpiryLogout` on `createApiClient`).
|
|
1729
|
+
*
|
|
1730
|
+
* This middleware runs before the error-conversion middleware so it observes
|
|
1731
|
+
* every 401 regardless of response body. The logout is fired as a side effect
|
|
1732
|
+
* and the response is returned unchanged, so the downstream error middleware
|
|
1733
|
+
* still throws the typed error to the caller.
|
|
1734
|
+
*
|
|
1735
|
+
* @param client - The Dynamic client instance.
|
|
1736
|
+
* @not-instrumented
|
|
1737
|
+
*/
|
|
1738
|
+
const createSessionExpiryLogoutMiddleware = (client) => ({ post: async (context) => {
|
|
1739
|
+
if (context.response.status === UNAUTHORIZED_STATUS && client.user !== null) __logoutWithReason_wrapped({ reason: "session-revoked" }, client).catch((error) => {
|
|
1740
|
+
getCore(client).logger.error("Failed to log out after unauthorized response", error);
|
|
1741
|
+
});
|
|
1742
|
+
return context.response;
|
|
1743
|
+
} });
|
|
1744
|
+
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region src/errors/UnauthorizedError.ts
|
|
1747
|
+
var UnauthorizedError = class extends BaseError {
|
|
1748
|
+
constructor({ cause }) {
|
|
1749
|
+
super({
|
|
1750
|
+
cause,
|
|
1751
|
+
code: "unauthorized_error",
|
|
1752
|
+
docsUrl: null,
|
|
1753
|
+
name: "UnauthorizedError",
|
|
1754
|
+
shortMessage: "Unauthorized"
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
//#endregion
|
|
1760
|
+
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
1761
|
+
/** @not-instrumented */
|
|
1762
|
+
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
1763
|
+
if (context.response.status === 401) {
|
|
1764
|
+
let cause = null;
|
|
1765
|
+
try {
|
|
1766
|
+
const errorBody = await context.response.clone().json();
|
|
1767
|
+
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
1768
|
+
} catch {}
|
|
1769
|
+
throw new UnauthorizedError({ cause });
|
|
1770
|
+
}
|
|
1771
|
+
return context.response;
|
|
1772
|
+
} });
|
|
1773
|
+
|
|
1774
|
+
//#endregion
|
|
1775
|
+
//#region src/modules/apiClient/createApiClient.ts
|
|
1776
|
+
/**
|
|
1777
|
+
* Returns a new instance of the SDK API client.
|
|
1778
|
+
*
|
|
1779
|
+
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
1780
|
+
* @not-instrumented
|
|
1781
|
+
*/
|
|
1782
|
+
const createApiClient = (options = {}, client) => {
|
|
1783
|
+
const core = getCore(client);
|
|
1784
|
+
const coreState = core.state.get();
|
|
1785
|
+
const settings = {
|
|
1786
|
+
basePath: core.apiBaseUrl,
|
|
1787
|
+
headers: {
|
|
1788
|
+
"Content-Type": "application/json",
|
|
1789
|
+
[DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
|
|
1790
|
+
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
1791
|
+
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
1792
|
+
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
1793
|
+
...core.getApiHeaders(),
|
|
1794
|
+
...options.headers
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
1798
|
+
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
1799
|
+
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
1800
|
+
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
1801
|
+
if (options.elevatedAccessTokenScope) {
|
|
1802
|
+
const elevatedToken = __getElevatedAccessToken_wrapped({ scope: options.elevatedAccessTokenScope }, client);
|
|
1803
|
+
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
1804
|
+
}
|
|
1805
|
+
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
1806
|
+
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
1807
|
+
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
1808
|
+
return new _dynamic_labs_sdk_api_core.SDKApi(new _dynamic_labs_sdk_api_core.Configuration({
|
|
1809
|
+
...settings,
|
|
1810
|
+
fetchApi: core.fetch,
|
|
1811
|
+
middleware: [
|
|
1812
|
+
createDeviceSignatureHeadersMiddleware(client),
|
|
1813
|
+
...options.skipSessionExpiryLogout ? [] : [createSessionExpiryLogoutMiddleware(client)],
|
|
1814
|
+
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
1815
|
+
createUnauthorizedMiddleware()
|
|
1816
|
+
]
|
|
1817
|
+
}));
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1820
|
+
//#endregion
|
|
1821
|
+
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
1822
|
+
/**
|
|
1823
|
+
* Fetches a batch of nonces from the API.
|
|
1824
|
+
*
|
|
1825
|
+
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
1826
|
+
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
1827
|
+
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
1828
|
+
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
1829
|
+
* `getNonce` can return synchronously from cache and the deeplink fires
|
|
1830
|
+
* without an interrupting network round-trip.
|
|
1831
|
+
*
|
|
1832
|
+
* New nonces are **appended** to the existing pool so that unconsumed entries
|
|
1833
|
+
* are not discarded by a background refetch.
|
|
1834
|
+
* @not-instrumented
|
|
1835
|
+
*/
|
|
1836
|
+
const fetchAndStoreNonces = async (client) => {
|
|
1837
|
+
const core = getCore(client);
|
|
1838
|
+
const { environmentId } = core;
|
|
1839
|
+
const { nonces } = await createApiClient({}, client).getNonces({
|
|
1840
|
+
count: NONCE_POOL_SIZE,
|
|
1841
|
+
environmentId
|
|
1842
|
+
});
|
|
1843
|
+
const existing = core.state.get().prefetchedNonces;
|
|
1844
|
+
core.state.set({
|
|
1845
|
+
prefetchedNonces: [...existing, ...nonces],
|
|
1846
|
+
prefetchedNoncesExpiration: Date.now() + NONCE_POOL_EXPIRATION_TIME
|
|
1847
|
+
});
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1850
|
+
//#endregion
|
|
1851
|
+
//#region src/constants.ts
|
|
1852
|
+
const SDK_API_CORE_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
1853
|
+
const DYNAMIC_ICONIC_SPRITE_URL = "https://iconic.dynamic-static-assets.com/icons/sprite.svg";
|
|
1854
|
+
|
|
1855
|
+
//#endregion
|
|
1856
|
+
//#region src/modules/waas/constants.ts
|
|
1857
|
+
const DEFAULT_WAAS_BASE_API_URL = "https://app.dynamicauth.com";
|
|
1858
|
+
const DEFAULT_WAAS_BASE_MPC_RELAY_API_URL = "https://relay.dynamicauth.com";
|
|
1859
|
+
const DYNAMIC_WAAS_METADATA = {
|
|
1860
|
+
displayName: "Dynamic WaaS",
|
|
1861
|
+
icon: `${DYNAMIC_ICONIC_SPRITE_URL}#dynamicwaas`,
|
|
1862
|
+
normalizedWalletName: "dynamicwaas"
|
|
1863
|
+
};
|
|
1864
|
+
|
|
1865
|
+
//#endregion
|
|
1866
|
+
//#region src/errors/InvalidParamError.ts
|
|
1867
|
+
var InvalidParamError = class extends BaseError {
|
|
1868
|
+
constructor(message) {
|
|
1869
|
+
super({
|
|
1870
|
+
cause: null,
|
|
1871
|
+
code: "invalid_param_error",
|
|
1872
|
+
docsUrl: null,
|
|
1873
|
+
name: "InvalidParamError",
|
|
1874
|
+
shortMessage: message
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
//#endregion
|
|
1880
|
+
Object.defineProperty(exports, 'APIError', {
|
|
1881
|
+
enumerable: true,
|
|
1882
|
+
get: function () {
|
|
1883
|
+
return APIError;
|
|
1884
|
+
}
|
|
1885
|
+
});
|
|
1886
|
+
Object.defineProperty(exports, 'BaseError', {
|
|
1887
|
+
enumerable: true,
|
|
1888
|
+
get: function () {
|
|
1154
1889
|
return BaseError;
|
|
1155
1890
|
}
|
|
1156
1891
|
});
|
|
@@ -1190,6 +1925,12 @@ Object.defineProperty(exports, 'DEFAULT_WAAS_BASE_MPC_RELAY_API_URL', {
|
|
|
1190
1925
|
return DEFAULT_WAAS_BASE_MPC_RELAY_API_URL;
|
|
1191
1926
|
}
|
|
1192
1927
|
});
|
|
1928
|
+
Object.defineProperty(exports, 'DYNAMIC_AUTH_COOKIE_NAME', {
|
|
1929
|
+
enumerable: true,
|
|
1930
|
+
get: function () {
|
|
1931
|
+
return DYNAMIC_AUTH_COOKIE_NAME;
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1193
1934
|
Object.defineProperty(exports, 'DYNAMIC_ICONIC_SPRITE_URL', {
|
|
1194
1935
|
enumerable: true,
|
|
1195
1936
|
get: function () {
|
|
@@ -1220,6 +1961,12 @@ Object.defineProperty(exports, 'InvalidParamError', {
|
|
|
1220
1961
|
return InvalidParamError;
|
|
1221
1962
|
}
|
|
1222
1963
|
});
|
|
1964
|
+
Object.defineProperty(exports, 'InvalidWalletProviderKeyError', {
|
|
1965
|
+
enumerable: true,
|
|
1966
|
+
get: function () {
|
|
1967
|
+
return InvalidWalletProviderKeyError;
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1223
1970
|
Object.defineProperty(exports, 'LinkCredentialError', {
|
|
1224
1971
|
enumerable: true,
|
|
1225
1972
|
get: function () {
|
|
@@ -1244,6 +1991,12 @@ Object.defineProperty(exports, 'NONCE_POOL_SIZE', {
|
|
|
1244
1991
|
return NONCE_POOL_SIZE;
|
|
1245
1992
|
}
|
|
1246
1993
|
});
|
|
1994
|
+
Object.defineProperty(exports, 'NoWalletProviderFoundError', {
|
|
1995
|
+
enumerable: true,
|
|
1996
|
+
get: function () {
|
|
1997
|
+
return NoWalletProviderFoundError;
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
1247
2000
|
Object.defineProperty(exports, 'SDK_API_CORE_VERSION', {
|
|
1248
2001
|
enumerable: true,
|
|
1249
2002
|
get: function () {
|
|
@@ -1268,12 +2021,30 @@ Object.defineProperty(exports, 'ValueMustBeDefinedError', {
|
|
|
1268
2021
|
return ValueMustBeDefinedError;
|
|
1269
2022
|
}
|
|
1270
2023
|
});
|
|
2024
|
+
Object.defineProperty(exports, 'WalletProviderPriority', {
|
|
2025
|
+
enumerable: true,
|
|
2026
|
+
get: function () {
|
|
2027
|
+
return WalletProviderPriority;
|
|
2028
|
+
}
|
|
2029
|
+
});
|
|
1271
2030
|
Object.defineProperty(exports, '__getElevatedAccessToken_wrapped', {
|
|
1272
2031
|
enumerable: true,
|
|
1273
2032
|
get: function () {
|
|
1274
2033
|
return __getElevatedAccessToken_wrapped;
|
|
1275
2034
|
}
|
|
1276
2035
|
});
|
|
2036
|
+
Object.defineProperty(exports, '__logoutWithReason_wrapped', {
|
|
2037
|
+
enumerable: true,
|
|
2038
|
+
get: function () {
|
|
2039
|
+
return __logoutWithReason_wrapped;
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
Object.defineProperty(exports, '__toESM', {
|
|
2043
|
+
enumerable: true,
|
|
2044
|
+
get: function () {
|
|
2045
|
+
return __toESM;
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
1277
2048
|
Object.defineProperty(exports, 'assertDefined', {
|
|
1278
2049
|
enumerable: true,
|
|
1279
2050
|
get: function () {
|
|
@@ -1292,6 +2063,24 @@ Object.defineProperty(exports, 'createDeviceSignatureHeadersMiddleware', {
|
|
|
1292
2063
|
return createDeviceSignatureHeadersMiddleware;
|
|
1293
2064
|
}
|
|
1294
2065
|
});
|
|
2066
|
+
Object.defineProperty(exports, 'createRuntimeServiceAccessKey', {
|
|
2067
|
+
enumerable: true,
|
|
2068
|
+
get: function () {
|
|
2069
|
+
return createRuntimeServiceAccessKey;
|
|
2070
|
+
}
|
|
2071
|
+
});
|
|
2072
|
+
Object.defineProperty(exports, 'createStorageKeySchema', {
|
|
2073
|
+
enumerable: true,
|
|
2074
|
+
get: function () {
|
|
2075
|
+
return createStorageKeySchema;
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2078
|
+
Object.defineProperty(exports, 'emitEvent', {
|
|
2079
|
+
enumerable: true,
|
|
2080
|
+
get: function () {
|
|
2081
|
+
return emitEvent;
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
1295
2084
|
Object.defineProperty(exports, 'extractSessionId', {
|
|
1296
2085
|
enumerable: true,
|
|
1297
2086
|
get: function () {
|
|
@@ -1304,6 +2093,30 @@ Object.defineProperty(exports, 'fetchAndStoreNonces', {
|
|
|
1304
2093
|
return fetchAndStoreNonces;
|
|
1305
2094
|
}
|
|
1306
2095
|
});
|
|
2096
|
+
Object.defineProperty(exports, 'fetchProjectSettings', {
|
|
2097
|
+
enumerable: true,
|
|
2098
|
+
get: function () {
|
|
2099
|
+
return fetchProjectSettings;
|
|
2100
|
+
}
|
|
2101
|
+
});
|
|
2102
|
+
Object.defineProperty(exports, 'formatWalletAccountId', {
|
|
2103
|
+
enumerable: true,
|
|
2104
|
+
get: function () {
|
|
2105
|
+
return formatWalletAccountId;
|
|
2106
|
+
}
|
|
2107
|
+
});
|
|
2108
|
+
Object.defineProperty(exports, 'formatWalletProviderKey', {
|
|
2109
|
+
enumerable: true,
|
|
2110
|
+
get: function () {
|
|
2111
|
+
return formatWalletProviderKey;
|
|
2112
|
+
}
|
|
2113
|
+
});
|
|
2114
|
+
Object.defineProperty(exports, 'generateSessionKeys', {
|
|
2115
|
+
enumerable: true,
|
|
2116
|
+
get: function () {
|
|
2117
|
+
return generateSessionKeys;
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
1307
2120
|
Object.defineProperty(exports, 'getChainFromVerifiedCredentialChain', {
|
|
1308
2121
|
enumerable: true,
|
|
1309
2122
|
get: function () {
|
|
@@ -1352,6 +2165,30 @@ Object.defineProperty(exports, 'getUserAgent', {
|
|
|
1352
2165
|
return getUserAgent;
|
|
1353
2166
|
}
|
|
1354
2167
|
});
|
|
2168
|
+
Object.defineProperty(exports, 'getWalletAccounts', {
|
|
2169
|
+
enumerable: true,
|
|
2170
|
+
get: function () {
|
|
2171
|
+
return getWalletAccounts;
|
|
2172
|
+
}
|
|
2173
|
+
});
|
|
2174
|
+
Object.defineProperty(exports, 'getWalletAccountsFromState', {
|
|
2175
|
+
enumerable: true,
|
|
2176
|
+
get: function () {
|
|
2177
|
+
return getWalletAccountsFromState;
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
2180
|
+
Object.defineProperty(exports, 'getWalletProviderFromWalletAccount', {
|
|
2181
|
+
enumerable: true,
|
|
2182
|
+
get: function () {
|
|
2183
|
+
return getWalletProviderFromWalletAccount;
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2186
|
+
Object.defineProperty(exports, 'getWalletProviderRegistry', {
|
|
2187
|
+
enumerable: true,
|
|
2188
|
+
get: function () {
|
|
2189
|
+
return getWalletProviderRegistry;
|
|
2190
|
+
}
|
|
2191
|
+
});
|
|
1355
2192
|
Object.defineProperty(exports, 'instrumentFunction', {
|
|
1356
2193
|
enumerable: true,
|
|
1357
2194
|
get: function () {
|
|
@@ -1364,34 +2201,88 @@ Object.defineProperty(exports, 'isCookieEnabled', {
|
|
|
1364
2201
|
return isCookieEnabled;
|
|
1365
2202
|
}
|
|
1366
2203
|
});
|
|
2204
|
+
Object.defineProperty(exports, 'isSignedIn', {
|
|
2205
|
+
enumerable: true,
|
|
2206
|
+
get: function () {
|
|
2207
|
+
return isSignedIn;
|
|
2208
|
+
}
|
|
2209
|
+
});
|
|
1367
2210
|
Object.defineProperty(exports, 'name', {
|
|
1368
2211
|
enumerable: true,
|
|
1369
2212
|
get: function () {
|
|
1370
2213
|
return name;
|
|
1371
2214
|
}
|
|
1372
2215
|
});
|
|
2216
|
+
Object.defineProperty(exports, 'normalizeAddress', {
|
|
2217
|
+
enumerable: true,
|
|
2218
|
+
get: function () {
|
|
2219
|
+
return normalizeAddress;
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
Object.defineProperty(exports, 'normalizeWalletNameWithChain', {
|
|
2223
|
+
enumerable: true,
|
|
2224
|
+
get: function () {
|
|
2225
|
+
return normalizeWalletNameWithChain;
|
|
2226
|
+
}
|
|
2227
|
+
});
|
|
2228
|
+
Object.defineProperty(exports, 'offEvent', {
|
|
2229
|
+
enumerable: true,
|
|
2230
|
+
get: function () {
|
|
2231
|
+
return offEvent;
|
|
2232
|
+
}
|
|
2233
|
+
});
|
|
2234
|
+
Object.defineProperty(exports, 'onEvent', {
|
|
2235
|
+
enumerable: true,
|
|
2236
|
+
get: function () {
|
|
2237
|
+
return onEvent;
|
|
2238
|
+
}
|
|
2239
|
+
});
|
|
2240
|
+
Object.defineProperty(exports, 'onceEvent', {
|
|
2241
|
+
enumerable: true,
|
|
2242
|
+
get: function () {
|
|
2243
|
+
return onceEvent;
|
|
2244
|
+
}
|
|
2245
|
+
});
|
|
1373
2246
|
Object.defineProperty(exports, 'randomString', {
|
|
1374
2247
|
enumerable: true,
|
|
1375
2248
|
get: function () {
|
|
1376
2249
|
return randomString;
|
|
1377
2250
|
}
|
|
1378
2251
|
});
|
|
2252
|
+
Object.defineProperty(exports, 'retryOnFail', {
|
|
2253
|
+
enumerable: true,
|
|
2254
|
+
get: function () {
|
|
2255
|
+
return retryOnFail;
|
|
2256
|
+
}
|
|
2257
|
+
});
|
|
1379
2258
|
Object.defineProperty(exports, 'scrubParameters', {
|
|
1380
2259
|
enumerable: true,
|
|
1381
2260
|
get: function () {
|
|
1382
2261
|
return scrubParameters;
|
|
1383
2262
|
}
|
|
1384
2263
|
});
|
|
2264
|
+
Object.defineProperty(exports, 'setCookie', {
|
|
2265
|
+
enumerable: true,
|
|
2266
|
+
get: function () {
|
|
2267
|
+
return setCookie;
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
1385
2270
|
Object.defineProperty(exports, 'setDefaultClient', {
|
|
1386
2271
|
enumerable: true,
|
|
1387
2272
|
get: function () {
|
|
1388
2273
|
return setDefaultClient;
|
|
1389
2274
|
}
|
|
1390
2275
|
});
|
|
2276
|
+
Object.defineProperty(exports, 'splitWalletProviderKey', {
|
|
2277
|
+
enumerable: true,
|
|
2278
|
+
get: function () {
|
|
2279
|
+
return splitWalletProviderKey;
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
1391
2282
|
Object.defineProperty(exports, 'version', {
|
|
1392
2283
|
enumerable: true,
|
|
1393
2284
|
get: function () {
|
|
1394
2285
|
return version;
|
|
1395
2286
|
}
|
|
1396
2287
|
});
|
|
1397
|
-
//# sourceMappingURL=InvalidParamError-
|
|
2288
|
+
//# sourceMappingURL=InvalidParamError-DKJhDrK8.cjs.map
|