@dynamic-labs-sdk/client 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{InvalidParamError-DyXEKMWn.cjs → InvalidParamError-CTssOe86.cjs} +105 -993
- package/dist/InvalidParamError-CTssOe86.cjs.map +1 -0
- package/dist/{InvalidParamError-BIptAjbC.native.esm.js → InvalidParamError-Crwntjl7.native.esm.js} +90 -828
- package/dist/InvalidParamError-Crwntjl7.native.esm.js.map +1 -0
- package/dist/{InvalidParamError-BZ0LHaml.esm.js → InvalidParamError-fQLJaGBW.esm.js} +90 -795
- package/dist/InvalidParamError-fQLJaGBW.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-CElqwdQO.cjs → NotWaasWalletAccountError-2RaDipZu.cjs} +4 -4
- package/dist/NotWaasWalletAccountError-2RaDipZu.cjs.map +1 -0
- package/dist/{NotWaasWalletAccountError-nT4jrLbp.esm.js → NotWaasWalletAccountError-BJLGGYmU.native.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-BJLGGYmU.native.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-BbOA5rPd.native.esm.js → NotWaasWalletAccountError-DF_S7gqo.esm.js} +4 -4
- package/dist/NotWaasWalletAccountError-DF_S7gqo.esm.js.map +1 -0
- package/dist/core.cjs +23 -23
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +5 -5
- package/dist/core.native.esm.js +5 -5
- package/dist/{getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js → getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js} +310 -39
- package/dist/getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-BkAPIdRC.esm.js → getNetworkProviderFromNetworkId-BWhaD23J.esm.js} +276 -38
- package/dist/getNetworkProviderFromNetworkId-BWhaD23J.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-DbI5MZhq.cjs → getNetworkProviderFromNetworkId-C1p9Rrg3.cjs} +351 -44
- package/dist/getNetworkProviderFromNetworkId-C1p9Rrg3.cjs.map +1 -0
- package/dist/{getSignedSessionId-BF6n8gve.cjs → getSignedSessionId-CxxYNC_8.cjs} +3 -3
- package/dist/{getSignedSessionId-BF6n8gve.cjs.map → getSignedSessionId-CxxYNC_8.cjs.map} +1 -1
- package/dist/{getSignedSessionId-1TV-x__C.native.esm.js → getSignedSessionId-DPOXdh6y.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-1TV-x__C.native.esm.js.map → getSignedSessionId-DPOXdh6y.native.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-y3YtxFHZ.esm.js → getSignedSessionId-c7dS4PQ9.esm.js} +3 -3
- package/dist/{getSignedSessionId-y3YtxFHZ.esm.js.map → getSignedSessionId-c7dS4PQ9.esm.js.map} +1 -1
- package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js +701 -0
- package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs +887 -0
- package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js +701 -0
- package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js.map +1 -0
- package/dist/index.cjs +76 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +14 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +14 -14
- package/dist/index.native.esm.js.map +1 -1
- package/dist/{isMfaRequiredForAction-Dy4-S3mr.esm.js → isMfaRequiredForAction-BjRvPrU6.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-Dy4-S3mr.esm.js.map → isMfaRequiredForAction-BjRvPrU6.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-B2vKX31S.native.esm.js → isMfaRequiredForAction-D8G5PBAd.native.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-B2vKX31S.native.esm.js.map → isMfaRequiredForAction-D8G5PBAd.native.esm.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-K2Jh-3-j.cjs → isMfaRequiredForAction-hlhj0qAC.cjs} +2 -2
- package/dist/{isMfaRequiredForAction-K2Jh-3-j.cjs.map → isMfaRequiredForAction-hlhj0qAC.cjs.map} +1 -1
- package/dist/modules/apiClient/apiClient.types.d.ts +0 -12
- package/dist/modules/apiClient/apiClient.types.d.ts.map +1 -1
- package/dist/modules/apiClient/createApiClient.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/deviceRegistration/getRegisteredDevices/getRegisteredDevices.d.ts.map +1 -1
- package/dist/modules/user/refreshAuth/refreshAuth.d.ts.map +1 -1
- package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts +12 -1
- package/dist/modules/waas/backupWaasKeySharesToGoogleDrive/backupWaasKeySharesToGoogleDrive.d.ts.map +1 -1
- package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
- package/dist/modules/waas/waas.types.d.ts +1 -0
- package/dist/modules/waas/waas.types.d.ts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/waas.cjs +12 -9
- package/dist/waas.cjs.map +1 -1
- package/dist/waas.esm.js +6 -4
- package/dist/waas.esm.js.map +1 -1
- package/dist/waas.native.esm.js +6 -4
- package/dist/waas.native.esm.js.map +1 -1
- package/dist/waasCore.cjs +6 -4
- package/dist/waasCore.cjs.map +1 -1
- package/dist/waasCore.esm.js +5 -4
- package/dist/waasCore.esm.js.map +1 -1
- package/dist/waasCore.native.esm.js +5 -4
- package/dist/waasCore.native.esm.js.map +1 -1
- package/package.json +4 -2
- package/dist/InvalidParamError-BIptAjbC.native.esm.js.map +0 -1
- package/dist/InvalidParamError-BZ0LHaml.esm.js.map +0 -1
- package/dist/InvalidParamError-DyXEKMWn.cjs.map +0 -1
- package/dist/NotWaasWalletAccountError-BbOA5rPd.native.esm.js.map +0 -1
- package/dist/NotWaasWalletAccountError-CElqwdQO.cjs.map +0 -1
- package/dist/NotWaasWalletAccountError-nT4jrLbp.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-B7DIqT2T.native.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-BkAPIdRC.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-DbI5MZhq.cjs.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-BfJ29erz.cjs +0 -346
- package/dist/getVerifiedCredentialForWalletAccount-BfJ29erz.cjs.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js +0 -269
- package/dist/getVerifiedCredentialForWalletAccount-CLyC2nOl.native.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-etV50QRH.esm.js +0 -269
- package/dist/getVerifiedCredentialForWalletAccount-etV50QRH.esm.js.map +0 -1
- package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts +0 -27
- package/dist/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.d.ts.map +0 -1
package/dist/{InvalidParamError-BIptAjbC.native.esm.js → InvalidParamError-Crwntjl7.native.esm.js}
RENAMED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { AuthStorageEnum, Configuration,
|
|
2
|
-
import * as z from "zod/mini";
|
|
3
|
-
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
4
|
-
import { getGenericPassword, resetGenericPassword, setGenericPassword } from "react-native-keychain";
|
|
1
|
+
import { AuthStorageEnum, Configuration, SDKApi, isDeviceNonceSignatureRequiredForUrl } from "@dynamic-labs/sdk-api-core";
|
|
5
2
|
|
|
6
3
|
//#region package.json
|
|
7
4
|
var name = "@dynamic-labs-sdk/client";
|
|
8
|
-
var version = "1.
|
|
5
|
+
var version = "1.7.0";
|
|
9
6
|
var dependencies = {
|
|
10
7
|
"@dynamic-labs-sdk/assert-package-version": "workspace:*",
|
|
11
8
|
"@dynamic-labs-wallet/browser-wallet-client": "1.0.7",
|
|
@@ -917,186 +914,109 @@ const createDeviceSignatureHeadersMiddleware = (client) => {
|
|
|
917
914
|
};
|
|
918
915
|
|
|
919
916
|
//#endregion
|
|
920
|
-
//#region src/
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
* @not-instrumented
|
|
924
|
-
*/
|
|
925
|
-
const setCookie = (cookie) => {
|
|
926
|
-
document.cookie = cookie;
|
|
927
|
-
};
|
|
928
|
-
|
|
929
|
-
//#endregion
|
|
930
|
-
//#region src/modules/clientEvents/clientEvents.ts
|
|
931
|
-
/**
|
|
932
|
-
* Adds an event listener for Dynamic client events.
|
|
933
|
-
*
|
|
934
|
-
* This function allows you to listen for various events emitted by the Dynamic client,
|
|
935
|
-
* such as authentication state changes, wallet connections, and more.
|
|
936
|
-
*
|
|
937
|
-
* @param params.event - The event name to listen for.
|
|
938
|
-
* @param params.listener - The callback function to execute when the event is fired.
|
|
939
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
940
|
-
* @returns A function that can be called to remove the listener.
|
|
941
|
-
* @not-instrumented
|
|
942
|
-
*/
|
|
943
|
-
const onEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
944
|
-
const { eventEmitter } = getCore(client);
|
|
945
|
-
eventEmitter.on(event, listener);
|
|
946
|
-
return () => {
|
|
947
|
-
eventEmitter.off(event, listener);
|
|
948
|
-
};
|
|
949
|
-
};
|
|
950
|
-
/**
|
|
951
|
-
* Removes an event listener from Dynamic client events.
|
|
952
|
-
*
|
|
953
|
-
* This function unsubscribes a previously registered event listener
|
|
954
|
-
* from the specified Dynamic client event.
|
|
955
|
-
*
|
|
956
|
-
* @param params.event - The event name to remove the listener from.
|
|
957
|
-
* @param params.listener - The callback function to remove.
|
|
958
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
959
|
-
* @not-instrumented
|
|
960
|
-
*/
|
|
961
|
-
const offEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
962
|
-
const { eventEmitter } = getCore(client);
|
|
963
|
-
eventEmitter.off(event, listener);
|
|
964
|
-
};
|
|
965
|
-
/**
|
|
966
|
-
* Adds a one-time event listener for Dynamic client events.
|
|
967
|
-
*
|
|
968
|
-
* This function listens for an event that will automatically remove itself
|
|
969
|
-
* after being triggered once.
|
|
970
|
-
*
|
|
971
|
-
* @param params.event - The event name to listen for.
|
|
972
|
-
* @param params.listener - The callback function to execute when the event is fired.
|
|
973
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
974
|
-
* @returns A function that can be called to remove the listener before it fires.
|
|
975
|
-
* @not-instrumented
|
|
976
|
-
*/
|
|
977
|
-
const onceEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
978
|
-
const { eventEmitter } = getCore(client);
|
|
979
|
-
eventEmitter.once(event, listener);
|
|
980
|
-
return () => {
|
|
981
|
-
eventEmitter.off(event, listener);
|
|
982
|
-
};
|
|
983
|
-
};
|
|
984
|
-
/**
|
|
985
|
-
* Emits a Dynamic client event.
|
|
986
|
-
*
|
|
987
|
-
* This function triggers an event that will be received by all registered
|
|
988
|
-
* listeners for the specified event type.
|
|
989
|
-
*
|
|
990
|
-
* @param params.event - The event name to emit.
|
|
991
|
-
* @param params.args - The arguments to pass to event listeners.
|
|
992
|
-
* @param client - The Dynamic client instance.
|
|
993
|
-
* @not-instrumented
|
|
994
|
-
*/
|
|
995
|
-
const emitEvent = ({ event, args }, client) => {
|
|
996
|
-
const { eventEmitter } = getCore(client);
|
|
997
|
-
eventEmitter.emit(event, args);
|
|
998
|
-
};
|
|
999
|
-
|
|
1000
|
-
//#endregion
|
|
1001
|
-
//#region src/utils/retryOnFail/InvalidRetryOnFailCallError.ts
|
|
1002
|
-
/**
|
|
1003
|
-
* This error is thrown when the `retryOnFail` function is called with an invalid
|
|
1004
|
-
* number of retries (i.e. less than 0).
|
|
1005
|
-
*/
|
|
1006
|
-
var InvalidRetryOnFailCallError = class extends BaseError {
|
|
1007
|
-
constructor(maxRetries) {
|
|
917
|
+
//#region src/errors/UnauthorizedError.ts
|
|
918
|
+
var UnauthorizedError = class extends BaseError {
|
|
919
|
+
constructor({ cause }) {
|
|
1008
920
|
super({
|
|
1009
|
-
cause
|
|
1010
|
-
code: "
|
|
921
|
+
cause,
|
|
922
|
+
code: "unauthorized_error",
|
|
1011
923
|
docsUrl: null,
|
|
1012
|
-
name: "
|
|
1013
|
-
shortMessage:
|
|
924
|
+
name: "UnauthorizedError",
|
|
925
|
+
shortMessage: "Unauthorized"
|
|
1014
926
|
});
|
|
1015
927
|
}
|
|
1016
928
|
};
|
|
1017
929
|
|
|
1018
930
|
//#endregion
|
|
1019
|
-
//#region src/utils/
|
|
931
|
+
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
1020
932
|
/** @not-instrumented */
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
* Reaching this point should never happen and this
|
|
1030
|
-
* error is thrown to help us debug the issue.
|
|
1031
|
-
*/
|
|
1032
|
-
throw new InvalidRetryOnFailCallError(maxRetries);
|
|
1033
|
-
};
|
|
1034
|
-
|
|
1035
|
-
//#endregion
|
|
1036
|
-
//#region src/errors/InvalidWalletProviderKeyError.ts
|
|
1037
|
-
var InvalidWalletProviderKeyError = class extends BaseError {
|
|
1038
|
-
constructor(value) {
|
|
1039
|
-
super({
|
|
1040
|
-
cause: null,
|
|
1041
|
-
code: "invalid_wallet_provider_key",
|
|
1042
|
-
docsUrl: null,
|
|
1043
|
-
name: "InvalidWalletProviderKeyError",
|
|
1044
|
-
shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`
|
|
1045
|
-
});
|
|
933
|
+
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
934
|
+
if (context.response.status === 401) {
|
|
935
|
+
let cause = null;
|
|
936
|
+
try {
|
|
937
|
+
const errorBody = await context.response.clone().json();
|
|
938
|
+
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
939
|
+
} catch {}
|
|
940
|
+
throw new UnauthorizedError({ cause });
|
|
1046
941
|
}
|
|
1047
|
-
|
|
942
|
+
return context.response;
|
|
943
|
+
} });
|
|
1048
944
|
|
|
1049
945
|
//#endregion
|
|
1050
|
-
//#region src/modules/
|
|
1051
|
-
/**
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
946
|
+
//#region src/modules/apiClient/createApiClient.ts
|
|
947
|
+
/**
|
|
948
|
+
* Returns a new instance of the SDK API client.
|
|
949
|
+
*
|
|
950
|
+
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
951
|
+
* @not-instrumented
|
|
952
|
+
*/
|
|
953
|
+
const createApiClient = (options = {}, client) => {
|
|
954
|
+
const core = getCore(client);
|
|
955
|
+
const coreState = core.state.get();
|
|
956
|
+
const settings = {
|
|
957
|
+
basePath: core.apiBaseUrl,
|
|
958
|
+
headers: {
|
|
959
|
+
"Content-Type": "application/json",
|
|
960
|
+
[DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
|
|
961
|
+
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
962
|
+
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
963
|
+
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
964
|
+
...core.getApiHeaders(),
|
|
965
|
+
...options.headers
|
|
966
|
+
}
|
|
1059
967
|
};
|
|
968
|
+
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
969
|
+
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
970
|
+
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
971
|
+
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
972
|
+
if (options.elevatedAccessTokenScope) {
|
|
973
|
+
const elevatedToken = __getElevatedAccessToken_wrapped({ scope: options.elevatedAccessTokenScope }, client);
|
|
974
|
+
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
975
|
+
}
|
|
976
|
+
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
977
|
+
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
978
|
+
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
979
|
+
return new SDKApi(new Configuration({
|
|
980
|
+
...settings,
|
|
981
|
+
fetchApi: core.fetch,
|
|
982
|
+
middleware: [
|
|
983
|
+
createDeviceSignatureHeadersMiddleware(client),
|
|
984
|
+
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
985
|
+
createUnauthorizedMiddleware()
|
|
986
|
+
]
|
|
987
|
+
}));
|
|
1060
988
|
};
|
|
1061
989
|
|
|
1062
990
|
//#endregion
|
|
1063
|
-
//#region src/
|
|
1064
|
-
/**
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
991
|
+
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
992
|
+
/**
|
|
993
|
+
* Fetches a batch of nonces from the API.
|
|
994
|
+
*
|
|
995
|
+
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
996
|
+
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
997
|
+
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
998
|
+
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
999
|
+
* `getNonce` can return synchronously from cache and the deeplink fires
|
|
1000
|
+
* without an interrupting network round-trip.
|
|
1001
|
+
*
|
|
1002
|
+
* New nonces are **appended** to the existing pool so that unconsumed entries
|
|
1003
|
+
* are not discarded by a background refetch.
|
|
1004
|
+
* @not-instrumented
|
|
1005
|
+
*/
|
|
1006
|
+
const fetchAndStoreNonces = async (client) => {
|
|
1007
|
+
const core = getCore(client);
|
|
1008
|
+
const { environmentId } = core;
|
|
1009
|
+
const { nonces } = await createApiClient({}, client).getNonces({
|
|
1010
|
+
count: NONCE_POOL_SIZE,
|
|
1011
|
+
environmentId
|
|
1012
|
+
});
|
|
1013
|
+
const existing = core.state.get().prefetchedNonces;
|
|
1014
|
+
core.state.set({
|
|
1015
|
+
prefetchedNonces: [...existing, ...nonces],
|
|
1016
|
+
prefetchedNoncesExpiration: Date.now() + NONCE_POOL_EXPIRATION_TIME
|
|
1017
|
+
});
|
|
1081
1018
|
};
|
|
1082
1019
|
|
|
1083
|
-
//#endregion
|
|
1084
|
-
//#region src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts
|
|
1085
|
-
/** @not-instrumented */
|
|
1086
|
-
const convertUnverifiedWalletAccountToWalletAccount = ({ unverifiedWalletAccount }) => ({
|
|
1087
|
-
address: unverifiedWalletAccount.address,
|
|
1088
|
-
addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,
|
|
1089
|
-
chain: unverifiedWalletAccount.chain,
|
|
1090
|
-
id: formatWalletAccountId({
|
|
1091
|
-
address: unverifiedWalletAccount.address,
|
|
1092
|
-
chain: unverifiedWalletAccount.chain,
|
|
1093
|
-
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
1094
|
-
}),
|
|
1095
|
-
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
1096
|
-
verifiedCredentialId: null,
|
|
1097
|
-
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
1098
|
-
});
|
|
1099
|
-
|
|
1100
1020
|
//#endregion
|
|
1101
1021
|
//#region src/modules/wallets/constants.ts
|
|
1102
1022
|
const CHAINS_INFO_MAP = {
|
|
@@ -1200,664 +1120,6 @@ const getChainFromVerifiedCredentialChain = (verifiedCredentialChain) => {
|
|
|
1200
1120
|
return chain;
|
|
1201
1121
|
};
|
|
1202
1122
|
|
|
1203
|
-
//#endregion
|
|
1204
|
-
//#region src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts
|
|
1205
|
-
/**
|
|
1206
|
-
* Format the raw wallet name and chain to get the value we can use for
|
|
1207
|
-
* verified credentials' `walletName` field.
|
|
1208
|
-
* @not-instrumented
|
|
1209
|
-
*/
|
|
1210
|
-
const normalizeWalletNameWithChain = ({ displayName, chain }) => {
|
|
1211
|
-
const sanitizedWalletName = displayName.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
1212
|
-
const chainLowered = chain.toLocaleLowerCase();
|
|
1213
|
-
if (sanitizedWalletName.endsWith(chainLowered)) return sanitizedWalletName;
|
|
1214
|
-
return `${sanitizedWalletName}${chainLowered}`;
|
|
1215
|
-
};
|
|
1216
|
-
|
|
1217
|
-
//#endregion
|
|
1218
|
-
//#region src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts
|
|
1219
|
-
/**
|
|
1220
|
-
* Assembles the wallet provider key from the wallet name, chain, and wallet provider type.
|
|
1221
|
-
*
|
|
1222
|
-
* The suffix is optional and can be used to add a uniquely identifying string to the key, which
|
|
1223
|
-
* might be necessary for some wallet providers (like Wallet Connect).
|
|
1224
|
-
*
|
|
1225
|
-
* IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account
|
|
1226
|
-
* to not be able to find its wallet provider when connecting to a new device (it won't be possible
|
|
1227
|
-
* to determine the full key just from the Verified Credential data).
|
|
1228
|
-
* @not-instrumented
|
|
1229
|
-
*/
|
|
1230
|
-
const formatWalletProviderKey = ({ suffix, chain, displayName, walletProviderType }) => {
|
|
1231
|
-
return `${normalizeWalletNameWithChain({
|
|
1232
|
-
chain,
|
|
1233
|
-
displayName
|
|
1234
|
-
})}:${walletProviderType}${suffix ? `:${suffix}` : ""}`;
|
|
1235
|
-
};
|
|
1236
|
-
|
|
1237
|
-
//#endregion
|
|
1238
|
-
//#region src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts
|
|
1239
|
-
/** @not-instrumented */
|
|
1240
|
-
const getWalletProviderKeyFromVerifiedCredential = ({ verifiedCredential }, client) => {
|
|
1241
|
-
const { walletProviderKeyMap } = getCore(client).state.get();
|
|
1242
|
-
const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];
|
|
1243
|
-
if (storedWalletProviderKey) return { walletProviderKey: storedWalletProviderKey };
|
|
1244
|
-
/**
|
|
1245
|
-
* We fallback to comprising the wallet provider key from walletName and walletProvider.
|
|
1246
|
-
*
|
|
1247
|
-
* Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider
|
|
1248
|
-
* keys, so this won't be enough for them.
|
|
1249
|
-
* Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider
|
|
1250
|
-
* and will require reconnection.
|
|
1251
|
-
* Read walletProvider.types.ts for more info.
|
|
1252
|
-
*/
|
|
1253
|
-
assertDefined(verifiedCredential.walletName, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`);
|
|
1254
|
-
assertDefined(verifiedCredential.walletProvider, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`);
|
|
1255
|
-
assertDefined(verifiedCredential.chain, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`);
|
|
1256
|
-
return { walletProviderKey: formatWalletProviderKey({
|
|
1257
|
-
chain: getChainFromVerifiedCredentialChain(verifiedCredential.chain),
|
|
1258
|
-
displayName: verifiedCredential.walletName,
|
|
1259
|
-
walletProviderType: verifiedCredential.walletProvider
|
|
1260
|
-
}) };
|
|
1261
|
-
};
|
|
1262
|
-
|
|
1263
|
-
//#endregion
|
|
1264
|
-
//#region src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts
|
|
1265
|
-
/** @not-instrumented */
|
|
1266
|
-
const convertVerifiedCredentialToWalletAccount = ({ verifiedCredential }, client) => {
|
|
1267
|
-
assertDefined(verifiedCredential.address, "Missing address in verified credential");
|
|
1268
|
-
assertDefined(verifiedCredential.chain, "Missing chain in verified credential");
|
|
1269
|
-
const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);
|
|
1270
|
-
const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential({ verifiedCredential }, client);
|
|
1271
|
-
const walletAccountId = formatWalletAccountId({
|
|
1272
|
-
address: verifiedCredential.address,
|
|
1273
|
-
chain,
|
|
1274
|
-
walletProviderKey
|
|
1275
|
-
});
|
|
1276
|
-
return {
|
|
1277
|
-
address: verifiedCredential.address,
|
|
1278
|
-
addressesWithTypes: verifiedCredential.walletAdditionalAddresses,
|
|
1279
|
-
chain,
|
|
1280
|
-
hardwareWalletVendor: verifiedCredential.walletProperties?.hardwareWallet,
|
|
1281
|
-
id: walletAccountId,
|
|
1282
|
-
lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,
|
|
1283
|
-
verifiedCredentialId: verifiedCredential.id,
|
|
1284
|
-
walletProviderKey
|
|
1285
|
-
};
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
|
-
//#endregion
|
|
1289
|
-
//#region src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts
|
|
1290
|
-
/** @not-instrumented */
|
|
1291
|
-
const getWalletAccountsFromState = ({ unverifiedWalletAccounts, user }, client) => {
|
|
1292
|
-
const walletAccountsMap = /* @__PURE__ */ new Map();
|
|
1293
|
-
/**
|
|
1294
|
-
* Handle the unverified wallet accounts before the user verified credentials
|
|
1295
|
-
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
1296
|
-
*/
|
|
1297
|
-
unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {
|
|
1298
|
-
const walletAccount = convertUnverifiedWalletAccountToWalletAccount({ unverifiedWalletAccount });
|
|
1299
|
-
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
1300
|
-
});
|
|
1301
|
-
(user?.verifiedCredentials ?? []).filter((verified) => verified.format === JwtVerifiedCredentialFormatEnum.Blockchain).forEach((verifiedWalletAccount) => {
|
|
1302
|
-
const walletAccount = convertVerifiedCredentialToWalletAccount({ verifiedCredential: verifiedWalletAccount }, client);
|
|
1303
|
-
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
1304
|
-
});
|
|
1305
|
-
return Array.from(walletAccountsMap.values());
|
|
1306
|
-
};
|
|
1307
|
-
|
|
1308
|
-
//#endregion
|
|
1309
|
-
//#region src/modules/wallets/getWalletAccounts/getWalletAccounts.ts
|
|
1310
|
-
/**
|
|
1311
|
-
* Retrieves all wallet accounts associated with the current session.
|
|
1312
|
-
*
|
|
1313
|
-
* This function returns both verified and unverified wallet accounts,
|
|
1314
|
-
* combining data from user credentials and local unverified accounts.
|
|
1315
|
-
* You can differentiate between verified and unverified wallet accounts by
|
|
1316
|
-
* checking the `verifiedCredentialId` property.
|
|
1317
|
-
*
|
|
1318
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1319
|
-
* @returns An array of wallet accounts associated with the session.
|
|
1320
|
-
* @not-instrumented
|
|
1321
|
-
*/
|
|
1322
|
-
const getWalletAccounts = (client = getDefaultClient()) => {
|
|
1323
|
-
const { unverifiedWalletAccounts, user } = getCore(client).state.get();
|
|
1324
|
-
return getWalletAccountsFromState({
|
|
1325
|
-
unverifiedWalletAccounts,
|
|
1326
|
-
user
|
|
1327
|
-
}, client);
|
|
1328
|
-
};
|
|
1329
|
-
|
|
1330
|
-
//#endregion
|
|
1331
|
-
//#region src/modules/auth/isSignedIn/isSignedIn.ts
|
|
1332
|
-
/**
|
|
1333
|
-
* Checks if the user is currently signed in to the Dynamic client.
|
|
1334
|
-
*
|
|
1335
|
-
* The client is considered to be in a signed in state if a user has
|
|
1336
|
-
* authenticated or if the client has at least one wallet connected.
|
|
1337
|
-
*
|
|
1338
|
-
* @deprecated What counts as "signed in" is your app's business logic, not the
|
|
1339
|
-
* SDK's. This helper bakes in one opinion (a user OR any connected wallet),
|
|
1340
|
-
* which rarely matches every app and forces a dependency on us for every
|
|
1341
|
-
* variation. Compose your own check from the underlying primitives instead —
|
|
1342
|
-
* e.g. `Boolean(client.user) || isAnyWalletAccountConnected(client)` — and
|
|
1343
|
-
* layer in whatever your app requires (device registration, completed
|
|
1344
|
-
* onboarding, satisfied MFA, a required embedded wallet, …). See the
|
|
1345
|
-
* "Check if signed in" guide:
|
|
1346
|
-
* https://www.dynamic.xyz/docs/javascript/user-session-management
|
|
1347
|
-
*
|
|
1348
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1349
|
-
* @returns True if the user is signed in, false otherwise.
|
|
1350
|
-
* @not-instrumented
|
|
1351
|
-
*/
|
|
1352
|
-
const isSignedIn = (client = getDefaultClient()) => Boolean(client.user || getWalletAccounts(client).length > 0);
|
|
1353
|
-
|
|
1354
|
-
//#endregion
|
|
1355
|
-
//#region src/services/storage/createLocalStorageAdapter/createLocalStorageAdapter.native.ts
|
|
1356
|
-
const NAMESPACE = "dynamic";
|
|
1357
|
-
const namespaceKey = (key) => `${NAMESPACE}:${key}`;
|
|
1358
|
-
/**
|
|
1359
|
-
* Creates a localStorage adapter for React Native.
|
|
1360
|
-
* Routes operations based on the `storageTier` option:
|
|
1361
|
-
* - `'default'`: uses AsyncStorage
|
|
1362
|
-
* - `'secure'`: uses react-native-keychain
|
|
1363
|
-
* @not-instrumented
|
|
1364
|
-
*/
|
|
1365
|
-
const createLocalStorageAdapter = () => {
|
|
1366
|
-
return {
|
|
1367
|
-
getItem: async (key, options) => {
|
|
1368
|
-
if (options.storageTier === "secure") {
|
|
1369
|
-
const result = await getGenericPassword({ service: key });
|
|
1370
|
-
if (!result) return null;
|
|
1371
|
-
return result.password;
|
|
1372
|
-
} else return AsyncStorage.getItem(namespaceKey(key));
|
|
1373
|
-
},
|
|
1374
|
-
removeItem: async (key, options) => {
|
|
1375
|
-
if (options.storageTier === "secure") await resetGenericPassword({ service: key });
|
|
1376
|
-
else await AsyncStorage.removeItem(namespaceKey(key));
|
|
1377
|
-
},
|
|
1378
|
-
setItem: async (key, value, options) => {
|
|
1379
|
-
if (options.storageTier === "secure") await setGenericPassword(key, value, { service: key });
|
|
1380
|
-
else await AsyncStorage.setItem(namespaceKey(key), value);
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
};
|
|
1384
|
-
|
|
1385
|
-
//#endregion
|
|
1386
|
-
//#region src/services/storage/createStorageKeySchema/createStorageKeySchema.ts
|
|
1387
|
-
/** @not-instrumented */
|
|
1388
|
-
const createStorageKeySchema = (params) => {
|
|
1389
|
-
return params;
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
//#endregion
|
|
1393
|
-
//#region src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.ts
|
|
1394
|
-
/**
|
|
1395
|
-
* The schema to track the expiration time of the project settings.
|
|
1396
|
-
*/
|
|
1397
|
-
const projectSettingsExpirationStorageKeySchema = createStorageKeySchema({
|
|
1398
|
-
key: "projectSettingsExpiration",
|
|
1399
|
-
schema: z.number()
|
|
1400
|
-
});
|
|
1401
|
-
|
|
1402
|
-
//#endregion
|
|
1403
|
-
//#region src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts
|
|
1404
|
-
/**
|
|
1405
|
-
* Expiration time of the project settings in milliseconds.
|
|
1406
|
-
*/
|
|
1407
|
-
const PROJECT_SETTINGS_EXPIRATION_TIME = 1e3 * 60 * 5;
|
|
1408
|
-
/**
|
|
1409
|
-
* Fetches and updates the project settings from the API.
|
|
1410
|
-
*
|
|
1411
|
-
* This function retrieves the latest project configuration settings
|
|
1412
|
-
* from Dynamic's servers, including authentication options, enabled chains,
|
|
1413
|
-
* and security configurations. The settings are cached for performance.
|
|
1414
|
-
*
|
|
1415
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1416
|
-
* @returns A promise that resolves to the updated project settings.
|
|
1417
|
-
* @not-instrumented
|
|
1418
|
-
*/
|
|
1419
|
-
const fetchProjectSettings = async (client = getDefaultClient()) => {
|
|
1420
|
-
const core = getCore(client);
|
|
1421
|
-
const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
|
|
1422
|
-
if (Boolean(client.projectSettings) && !(currentExpiration && currentExpiration < Date.now()) && isSignedIn(client)) return client.projectSettings;
|
|
1423
|
-
const apiClient = createApiClient({}, client);
|
|
1424
|
-
core.logger.debug("[fetchProjectSettings] Fetching project settings...");
|
|
1425
|
-
const doFetch = async () => apiClient.getEnvironmentSettings({
|
|
1426
|
-
environmentId: core.environmentId,
|
|
1427
|
-
sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
|
|
1428
|
-
}, { credentials: "omit" });
|
|
1429
|
-
const projectSettings = await retryOnFail({
|
|
1430
|
-
fn: doFetch,
|
|
1431
|
-
maxRetries: 2
|
|
1432
|
-
});
|
|
1433
|
-
core.state.set({ projectSettings: projectSettings ?? null });
|
|
1434
|
-
await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
|
|
1435
|
-
return projectSettings;
|
|
1436
|
-
};
|
|
1437
|
-
|
|
1438
|
-
//#endregion
|
|
1439
|
-
//#region src/modules/sessionKeys/generateSessionKeys/generateSessionKeys.ts
|
|
1440
|
-
/** @not-instrumented */
|
|
1441
|
-
const generateSessionKeys = async (client) => {
|
|
1442
|
-
const core = getCore(client);
|
|
1443
|
-
await core.keychain.removeKey("session");
|
|
1444
|
-
const publicKey = await core.keychain.generateKey("session");
|
|
1445
|
-
assertDefined(publicKey, "Public key not found");
|
|
1446
|
-
core.state.set({ sessionKeys: publicKey });
|
|
1447
|
-
return { publicKey };
|
|
1448
|
-
};
|
|
1449
|
-
|
|
1450
|
-
//#endregion
|
|
1451
|
-
//#region src/errors/NoWalletProviderFoundError.ts
|
|
1452
|
-
var NoWalletProviderFoundError = class extends BaseError {
|
|
1453
|
-
constructor({ walletProviderKey }) {
|
|
1454
|
-
super({
|
|
1455
|
-
cause: null,
|
|
1456
|
-
code: "no_wallet_provider_found_error",
|
|
1457
|
-
docsUrl: null,
|
|
1458
|
-
name: "NoWalletProviderFoundError",
|
|
1459
|
-
shortMessage: `No wallet provider found with key: ${walletProviderKey}`
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
|
|
1464
|
-
//#endregion
|
|
1465
|
-
//#region src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts
|
|
1466
|
-
/**
|
|
1467
|
-
* Creates a service accessor function that manages service instantiation and caching.
|
|
1468
|
-
* The returned function will either retrieve an existing service from the registry or
|
|
1469
|
-
* create a new one using the provided builder function.
|
|
1470
|
-
*
|
|
1471
|
-
* @template - The type of service to be created/accessed
|
|
1472
|
-
* @param key - Unique identifier for the service in the registry
|
|
1473
|
-
* @param builder - Function that creates the service instance when called with a DynamicClient
|
|
1474
|
-
* @not-instrumented
|
|
1475
|
-
*/
|
|
1476
|
-
const createRuntimeServiceAccessKey = (key, builder) => (client) => {
|
|
1477
|
-
const { runtimeServices } = getCore(client);
|
|
1478
|
-
const currentService = runtimeServices.getByKey(key);
|
|
1479
|
-
if (currentService) return currentService;
|
|
1480
|
-
const service = builder(client);
|
|
1481
|
-
runtimeServices.register(key, service);
|
|
1482
|
-
return service;
|
|
1483
|
-
};
|
|
1484
|
-
|
|
1485
|
-
//#endregion
|
|
1486
|
-
//#region src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts
|
|
1487
|
-
/**
|
|
1488
|
-
* Creates a new wallet provider registry that manages wallet providers with priority-based registration.
|
|
1489
|
-
*
|
|
1490
|
-
* @returns The wallet provider registry instance
|
|
1491
|
-
*
|
|
1492
|
-
* @example
|
|
1493
|
-
* ```typescript
|
|
1494
|
-
* const registry = createWalletProviderRegistry();
|
|
1495
|
-
*
|
|
1496
|
-
* registry.register({
|
|
1497
|
-
* priority: WalletProviderPriority.WALLET_SDK,
|
|
1498
|
-
* walletProvider: myWalletProvider
|
|
1499
|
-
* });
|
|
1500
|
-
*
|
|
1501
|
-
* const provider = registry.getByKey('my-wallet-key');
|
|
1502
|
-
* const providers = registry.listProviders();
|
|
1503
|
-
* ```
|
|
1504
|
-
* @not-instrumented
|
|
1505
|
-
*/
|
|
1506
|
-
const createWalletProviderRegistry = (client) => {
|
|
1507
|
-
const registry = /* @__PURE__ */ new Map();
|
|
1508
|
-
return {
|
|
1509
|
-
getByKey: (key) => registry.get(key)?.walletProvider,
|
|
1510
|
-
listProviderEntries: () => Array.from(registry.values()),
|
|
1511
|
-
listProviders: () => Array.from(registry.values()).map((v) => v.walletProvider),
|
|
1512
|
-
register: (args) => {
|
|
1513
|
-
const existingEntry = registry.get(args.walletProvider.key);
|
|
1514
|
-
if (existingEntry) {
|
|
1515
|
-
if (existingEntry.priority < args.priority) {
|
|
1516
|
-
registry.set(args.walletProvider.key, args);
|
|
1517
|
-
emitEvent({
|
|
1518
|
-
args: { walletProviderKey: args.walletProvider.key },
|
|
1519
|
-
event: "walletProviderChanged"
|
|
1520
|
-
}, client);
|
|
1521
|
-
}
|
|
1522
|
-
} else {
|
|
1523
|
-
registry.set(args.walletProvider.key, args);
|
|
1524
|
-
emitEvent({
|
|
1525
|
-
args: { walletProvider: args.walletProvider },
|
|
1526
|
-
event: "walletProviderRegistered"
|
|
1527
|
-
}, client);
|
|
1528
|
-
emitEvent({
|
|
1529
|
-
args: { walletProviderKey: args.walletProvider.key },
|
|
1530
|
-
event: "walletProviderChanged"
|
|
1531
|
-
}, client);
|
|
1532
|
-
}
|
|
1533
|
-
},
|
|
1534
|
-
unregister: (key) => {
|
|
1535
|
-
registry.delete(key);
|
|
1536
|
-
emitEvent({
|
|
1537
|
-
args: { walletProviderKey: key },
|
|
1538
|
-
event: "walletProviderUnregistered"
|
|
1539
|
-
}, client);
|
|
1540
|
-
}
|
|
1541
|
-
};
|
|
1542
|
-
};
|
|
1543
|
-
|
|
1544
|
-
//#endregion
|
|
1545
|
-
//#region src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts
|
|
1546
|
-
/**
|
|
1547
|
-
* This function provides access to a shared instance of the wallet provider registry.
|
|
1548
|
-
*
|
|
1549
|
-
* It ensures that the same registry instance is used throughout the client to maintaining
|
|
1550
|
-
* consistency of registered wallet providers across different parts of the codebase.
|
|
1551
|
-
*
|
|
1552
|
-
* @returns The wallet provider registry instance
|
|
1553
|
-
*
|
|
1554
|
-
* @example
|
|
1555
|
-
* ```typescript
|
|
1556
|
-
* // Get the registry instance
|
|
1557
|
-
* const registry = getWalletProviderRegistry();
|
|
1558
|
-
*
|
|
1559
|
-
* // Register a wallet provider
|
|
1560
|
-
* registry.register({
|
|
1561
|
-
* priority: WalletProviderPriority.WALLET_SDK,
|
|
1562
|
-
* walletProvider: myWalletProvider
|
|
1563
|
-
* });
|
|
1564
|
-
*
|
|
1565
|
-
* // Retrieve a specific provider
|
|
1566
|
-
* const provider = registry.getByKey('metamaskevm');
|
|
1567
|
-
* ```
|
|
1568
|
-
*/
|
|
1569
|
-
const getWalletProviderRegistry = createRuntimeServiceAccessKey("walletProviderRegistry", (client) => createWalletProviderRegistry(client));
|
|
1570
|
-
|
|
1571
|
-
//#endregion
|
|
1572
|
-
//#region src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts
|
|
1573
|
-
let WalletProviderPriority = /* @__PURE__ */ function(WalletProviderPriority$1) {
|
|
1574
|
-
/**
|
|
1575
|
-
* Highest priority should be used by wallet providers that implement
|
|
1576
|
-
* the most reliable wallet integration.
|
|
1577
|
-
* example: The SDK provided by the wallet provider.
|
|
1578
|
-
*/
|
|
1579
|
-
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SDK"] = 100] = "WALLET_SDK";
|
|
1580
|
-
/**
|
|
1581
|
-
* Medium priority should be used by wallet providers that implement
|
|
1582
|
-
* a wallet integration via some reliable standard.
|
|
1583
|
-
* example: A wallet provider that uses EIP6963 announcement.
|
|
1584
|
-
*/
|
|
1585
|
-
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SELF_ANNOUNCEMENT_STANDARD"] = 50] = "WALLET_SELF_ANNOUNCEMENT_STANDARD";
|
|
1586
|
-
/**
|
|
1587
|
-
* Low priority should be used by wallet providers that implement
|
|
1588
|
-
* a wallet integration on a less reliable standard.
|
|
1589
|
-
* example: A wallet provider that uses window.ethereum, where the
|
|
1590
|
-
* window key can be overridden by other extensions.
|
|
1591
|
-
*/
|
|
1592
|
-
WalletProviderPriority$1[WalletProviderPriority$1["WINDOW_INJECT"] = 20] = "WINDOW_INJECT";
|
|
1593
|
-
return WalletProviderPriority$1;
|
|
1594
|
-
}({});
|
|
1595
|
-
|
|
1596
|
-
//#endregion
|
|
1597
|
-
//#region src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts
|
|
1598
|
-
/** @not-instrumented */
|
|
1599
|
-
const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
|
|
1600
|
-
const walletProvider = getWalletProviderRegistry(client).getByKey(walletAccount.walletProviderKey);
|
|
1601
|
-
if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey: walletAccount.walletProviderKey });
|
|
1602
|
-
return walletProvider;
|
|
1603
|
-
};
|
|
1604
|
-
|
|
1605
|
-
//#endregion
|
|
1606
|
-
//#region src/modules/wallets/utils/getAvailableWalletProvidersFromWalletAccounts/getAvailableWalletProvidersFromWalletAccounts.ts
|
|
1607
|
-
/** @not-instrumented */
|
|
1608
|
-
const getAvailableWalletProvidersFromWalletAccounts = (client) => {
|
|
1609
|
-
const core = getCore(client);
|
|
1610
|
-
const walletProvidersMap = /* @__PURE__ */ new Map();
|
|
1611
|
-
getWalletAccounts(client).forEach((walletAccount) => {
|
|
1612
|
-
if (walletProvidersMap.has(walletAccount.walletProviderKey)) return;
|
|
1613
|
-
try {
|
|
1614
|
-
const walletProvider = getWalletProviderFromWalletAccount({ walletAccount }, client);
|
|
1615
|
-
walletProvidersMap.set(walletAccount.walletProviderKey, walletProvider);
|
|
1616
|
-
} catch (error) {
|
|
1617
|
-
core.logger.debug("Wallet provider not found for wallet account", {
|
|
1618
|
-
error,
|
|
1619
|
-
walletAccount: walletAccount.address
|
|
1620
|
-
});
|
|
1621
|
-
}
|
|
1622
|
-
});
|
|
1623
|
-
return Array.from(walletProvidersMap.values());
|
|
1624
|
-
};
|
|
1625
|
-
|
|
1626
|
-
//#endregion
|
|
1627
|
-
//#region src/modules/wallets/destroyWalletProviders/destroyWalletProviders.ts
|
|
1628
|
-
/**
|
|
1629
|
-
* Tear down every wallet provider on the client.
|
|
1630
|
-
*
|
|
1631
|
-
* Each provider's `destroy` is responsible for its own local + remote
|
|
1632
|
-
* cleanup. We swallow errors so a failing destroy on one provider does not
|
|
1633
|
-
* block teardown of the others (e.g. during logout).
|
|
1634
|
-
*
|
|
1635
|
-
* @not-instrumented
|
|
1636
|
-
*/
|
|
1637
|
-
const destroyWalletProviders = async ({ reason }, client) => {
|
|
1638
|
-
const core = getCore(client);
|
|
1639
|
-
const walletProviders = getAvailableWalletProvidersFromWalletAccounts(client);
|
|
1640
|
-
await Promise.all(walletProviders.map(async (walletProvider) => {
|
|
1641
|
-
if (!walletProvider.destroy) return;
|
|
1642
|
-
try {
|
|
1643
|
-
await walletProvider.destroy({ reason });
|
|
1644
|
-
} catch (err) {
|
|
1645
|
-
core.logger.error(`Error destroying wallet provider ${walletProvider.key}`, err);
|
|
1646
|
-
}
|
|
1647
|
-
}));
|
|
1648
|
-
};
|
|
1649
|
-
|
|
1650
|
-
//#endregion
|
|
1651
|
-
//#region src/modules/auth/consts.ts
|
|
1652
|
-
const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
|
|
1653
|
-
|
|
1654
|
-
//#endregion
|
|
1655
|
-
//#region src/modules/auth/logoutWithReason/logoutWithReason.ts
|
|
1656
|
-
/**
|
|
1657
|
-
* Logs the user out with an explicit reason.
|
|
1658
|
-
*
|
|
1659
|
-
* Revokes the session, clears auth state, terminates wallet providers, and
|
|
1660
|
-
* emits the `logout` client event with the given reason. The reason is also
|
|
1661
|
-
* captured as an argument on the function-instrumentation event, which is
|
|
1662
|
-
* how Datadog distinguishes between different logout causes.
|
|
1663
|
-
*
|
|
1664
|
-
* Use this instead of the public `logout` when triggering a logout from
|
|
1665
|
-
* internal or extension code — the caller owns the reason string, so the
|
|
1666
|
-
* telemetry correctly attributes *why* the logout happened.
|
|
1667
|
-
*
|
|
1668
|
-
* @param params - The logout params.
|
|
1669
|
-
* @param params.reason - Why the logout is being triggered. Extension authors
|
|
1670
|
-
* needing a reason outside the SDK catalog can cast with `as LogoutReason`.
|
|
1671
|
-
* @param client - The Dynamic client instance.
|
|
1672
|
-
* @instrumented
|
|
1673
|
-
*/
|
|
1674
|
-
const logoutWithReason = async ({ reason }, client) => {
|
|
1675
|
-
const core = getCore(client);
|
|
1676
|
-
core.logger.debug("[logoutWithReason] Logging out...", { reason });
|
|
1677
|
-
await destroyWalletProviders({ reason }, client);
|
|
1678
|
-
if (client.user !== null) {
|
|
1679
|
-
const apiClient = createApiClient({ skipSessionExpiryLogout: true }, client);
|
|
1680
|
-
try {
|
|
1681
|
-
await apiClient.revokeSession({ environmentId: core.environmentId });
|
|
1682
|
-
} catch (error) {
|
|
1683
|
-
core.logger.error("Failed to revoke session", error);
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* This deletes the auth cookie if it exists.
|
|
1687
|
-
* If the cookie doesn't exist, this sets a new cookie that expires immediately.
|
|
1688
|
-
*/
|
|
1689
|
-
if (isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=; Max-Age=-99999999; path=/; SameSite=Lax`);
|
|
1690
|
-
}
|
|
1691
|
-
await core.keychain.removeKey("session");
|
|
1692
|
-
core.state.set({
|
|
1693
|
-
captchaToken: null,
|
|
1694
|
-
elevatedAccessTokens: [],
|
|
1695
|
-
legacyToken: null,
|
|
1696
|
-
mfaToken: null,
|
|
1697
|
-
sessionExpiresAt: null,
|
|
1698
|
-
sessionKeys: null,
|
|
1699
|
-
token: null,
|
|
1700
|
-
unverifiedWalletAccounts: [],
|
|
1701
|
-
user: null
|
|
1702
|
-
});
|
|
1703
|
-
emitEvent({
|
|
1704
|
-
args: { reason },
|
|
1705
|
-
event: "logout"
|
|
1706
|
-
}, client);
|
|
1707
|
-
fetchProjectSettings(client);
|
|
1708
|
-
generateSessionKeys(client);
|
|
1709
|
-
};
|
|
1710
|
-
const __logoutWithReason_impl = logoutWithReason;
|
|
1711
|
-
const __logoutWithReason_wrapped = instrumentFunction({
|
|
1712
|
-
fn: __logoutWithReason_impl,
|
|
1713
|
-
functionName: "logoutWithReason",
|
|
1714
|
-
getCore: () => {
|
|
1715
|
-
try {
|
|
1716
|
-
return getCore(getDefaultClient());
|
|
1717
|
-
} catch {
|
|
1718
|
-
return;
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
});
|
|
1722
|
-
|
|
1723
|
-
//#endregion
|
|
1724
|
-
//#region src/modules/apiClient/utils/sessionExpiryLogoutMiddleware/createSessionExpiryLogoutMiddleware.ts
|
|
1725
|
-
const UNAUTHORIZED_STATUS = 401;
|
|
1726
|
-
/**
|
|
1727
|
-
* Creates middleware that ends the local session when an *authenticated*
|
|
1728
|
-
* request is rejected with a 401.
|
|
1729
|
-
*
|
|
1730
|
-
* A 401 on a request that carried an authenticated session means the backend
|
|
1731
|
-
* rejected our credentials, so the local session is stale and must be cleared.
|
|
1732
|
-
* The check is purely local (`client.user`) — we deliberately do not
|
|
1733
|
-
* re-validate over the network, because the 401 itself is the rejection signal
|
|
1734
|
-
* and re-validating would route back through this same middleware.
|
|
1735
|
-
*
|
|
1736
|
-
* Requests made without an authenticated session (e.g. pre-auth probes) are
|
|
1737
|
-
* ignored — there is no session to invalidate. Endpoints that legitimately
|
|
1738
|
-
* return 401 for non-session reasons opt out of this behavior by omitting the
|
|
1739
|
-
* middleware (see `skipSessionExpiryLogout` on `createApiClient`).
|
|
1740
|
-
*
|
|
1741
|
-
* This middleware runs before the error-conversion middleware so it observes
|
|
1742
|
-
* every 401 regardless of response body. The logout is fired as a side effect
|
|
1743
|
-
* and the response is returned unchanged, so the downstream error middleware
|
|
1744
|
-
* still throws the typed error to the caller.
|
|
1745
|
-
*
|
|
1746
|
-
* @param client - The Dynamic client instance.
|
|
1747
|
-
* @not-instrumented
|
|
1748
|
-
*/
|
|
1749
|
-
const createSessionExpiryLogoutMiddleware = (client) => ({ post: async (context) => {
|
|
1750
|
-
if (context.response.status === UNAUTHORIZED_STATUS && client.user !== null) __logoutWithReason_wrapped({ reason: "session-revoked" }, client).catch((error) => {
|
|
1751
|
-
getCore(client).logger.error("Failed to log out after unauthorized response", error);
|
|
1752
|
-
});
|
|
1753
|
-
return context.response;
|
|
1754
|
-
} });
|
|
1755
|
-
|
|
1756
|
-
//#endregion
|
|
1757
|
-
//#region src/errors/UnauthorizedError.ts
|
|
1758
|
-
var UnauthorizedError = class extends BaseError {
|
|
1759
|
-
constructor({ cause }) {
|
|
1760
|
-
super({
|
|
1761
|
-
cause,
|
|
1762
|
-
code: "unauthorized_error",
|
|
1763
|
-
docsUrl: null,
|
|
1764
|
-
name: "UnauthorizedError",
|
|
1765
|
-
shortMessage: "Unauthorized"
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
};
|
|
1769
|
-
|
|
1770
|
-
//#endregion
|
|
1771
|
-
//#region src/modules/apiClient/utils/unauthorizedMiddleware/createUnauthorizedMiddleware.ts
|
|
1772
|
-
/** @not-instrumented */
|
|
1773
|
-
const createUnauthorizedMiddleware = () => ({ post: async (context) => {
|
|
1774
|
-
if (context.response.status === 401) {
|
|
1775
|
-
let cause = null;
|
|
1776
|
-
try {
|
|
1777
|
-
const errorBody = await context.response.clone().json();
|
|
1778
|
-
if (errorBody && "error" in errorBody && typeof errorBody.error === "string") cause = new Error(errorBody.error);
|
|
1779
|
-
} catch {}
|
|
1780
|
-
throw new UnauthorizedError({ cause });
|
|
1781
|
-
}
|
|
1782
|
-
return context.response;
|
|
1783
|
-
} });
|
|
1784
|
-
|
|
1785
|
-
//#endregion
|
|
1786
|
-
//#region src/modules/apiClient/createApiClient.ts
|
|
1787
|
-
/**
|
|
1788
|
-
* Returns a new instance of the SDK API client.
|
|
1789
|
-
*
|
|
1790
|
-
* This is not meant for storing, as it is very light we can create it whenever needed.
|
|
1791
|
-
* @not-instrumented
|
|
1792
|
-
*/
|
|
1793
|
-
const createApiClient = (options = {}, client) => {
|
|
1794
|
-
const core = getCore(client);
|
|
1795
|
-
const coreState = core.state.get();
|
|
1796
|
-
const settings = {
|
|
1797
|
-
basePath: core.apiBaseUrl,
|
|
1798
|
-
headers: {
|
|
1799
|
-
"Content-Type": "application/json",
|
|
1800
|
-
[DYNAMIC_API_VERSION_HEADER]: `API/${DYNAMIC_SDK_API_VERSION}`,
|
|
1801
|
-
[DYNAMIC_REQUEST_ID_HEADER]: randomString({ length: 50 }),
|
|
1802
|
-
[DYNAMIC_SDK_SESSION_ID_HEADER]: core.sdkSessionId,
|
|
1803
|
-
[DYNAMIC_SDK_VERSION_HEADER]: `${CLIENT_SDK_NAME}/${version}`,
|
|
1804
|
-
...core.getApiHeaders(),
|
|
1805
|
-
...options.headers
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
if (core.metadata?.universalLink) settings.headers["Origin"] = core.metadata.universalLink;
|
|
1809
|
-
if (client.token) settings.headers.Authorization = `Bearer ${client.token}`;
|
|
1810
|
-
if (client.projectSettings && isCookieEnabled(client)) settings.credentials = "include";
|
|
1811
|
-
if (options.includeMfaToken && coreState.mfaToken) settings.headers[MFA_TOKEN_HEADER] = coreState.mfaToken;
|
|
1812
|
-
if (options.elevatedAccessTokenScope) {
|
|
1813
|
-
const elevatedToken = __getElevatedAccessToken_wrapped({ scope: options.elevatedAccessTokenScope }, client);
|
|
1814
|
-
if (elevatedToken) settings.headers[ELEVATED_ACCESS_TOKEN_HEADER] = elevatedToken;
|
|
1815
|
-
}
|
|
1816
|
-
const sessionPublicKey = getSessionKeys(client)?.publicKey;
|
|
1817
|
-
const isSessionPublicKeyHeaderPresent = settings.headers[SESSION_PUBLIC_KEY_HEADER] !== void 0;
|
|
1818
|
-
if (sessionPublicKey && !isSessionPublicKeyHeaderPresent) settings.headers[SESSION_PUBLIC_KEY_HEADER] = sessionPublicKey;
|
|
1819
|
-
return new SDKApi(new Configuration({
|
|
1820
|
-
...settings,
|
|
1821
|
-
fetchApi: core.fetch,
|
|
1822
|
-
middleware: [
|
|
1823
|
-
createDeviceSignatureHeadersMiddleware(client),
|
|
1824
|
-
...options.skipSessionExpiryLogout ? [] : [createSessionExpiryLogoutMiddleware(client)],
|
|
1825
|
-
createConvertToApiErrorMiddleware({ errorMappers: [...options.errorMappers || [], clientErrorMapper] }),
|
|
1826
|
-
createUnauthorizedMiddleware()
|
|
1827
|
-
]
|
|
1828
|
-
}));
|
|
1829
|
-
};
|
|
1830
|
-
|
|
1831
|
-
//#endregion
|
|
1832
|
-
//#region src/utils/getNonce/fetchAndStoreNonces/fetchAndStoreNonces.ts
|
|
1833
|
-
/**
|
|
1834
|
-
* Fetches a batch of nonces from the API.
|
|
1835
|
-
*
|
|
1836
|
-
* Prefetching is critical for iOS deep link wallet providers (e.g. Phantom
|
|
1837
|
-
* redirect). On iOS, a network request (like fetching a nonce) between a user
|
|
1838
|
-
* action and a deeplink call will break the gesture chain, causing iOS to
|
|
1839
|
-
* silently ignore the deeplink. By prefetching nonces ahead of time,
|
|
1840
|
-
* `getNonce` can return synchronously from cache and the deeplink fires
|
|
1841
|
-
* without an interrupting network round-trip.
|
|
1842
|
-
*
|
|
1843
|
-
* New nonces are **appended** to the existing pool so that unconsumed entries
|
|
1844
|
-
* are not discarded by a background refetch.
|
|
1845
|
-
* @not-instrumented
|
|
1846
|
-
*/
|
|
1847
|
-
const fetchAndStoreNonces = async (client) => {
|
|
1848
|
-
const core = getCore(client);
|
|
1849
|
-
const { environmentId } = core;
|
|
1850
|
-
const { nonces } = await createApiClient({}, client).getNonces({
|
|
1851
|
-
count: NONCE_POOL_SIZE,
|
|
1852
|
-
environmentId
|
|
1853
|
-
});
|
|
1854
|
-
const existing = core.state.get().prefetchedNonces;
|
|
1855
|
-
core.state.set({
|
|
1856
|
-
prefetchedNonces: [...existing, ...nonces],
|
|
1857
|
-
prefetchedNoncesExpiration: Date.now() + NONCE_POOL_EXPIRATION_TIME
|
|
1858
|
-
});
|
|
1859
|
-
};
|
|
1860
|
-
|
|
1861
1123
|
//#endregion
|
|
1862
1124
|
//#region src/constants.ts
|
|
1863
1125
|
const SDK_API_CORE_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
@@ -1888,5 +1150,5 @@ var InvalidParamError = class extends BaseError {
|
|
|
1888
1150
|
};
|
|
1889
1151
|
|
|
1890
1152
|
//#endregion
|
|
1891
|
-
export {
|
|
1892
|
-
//# sourceMappingURL=InvalidParamError-
|
|
1153
|
+
export { getUserAgent as A, getCore as B, isCookieEnabled as C, instrumentFunction as D, __getElevatedAccessToken_wrapped as E, NONCE_POOL_SIZE as F, version as H, getDefaultClient as I, setDefaultClient as L, randomString as M, CLIENT_SDK_NAME as N, scrubParameters as O, DYNAMIC_SDK_API_VERSION as P, ClientNotFoundError as R, getSessionKeys as S, ValueMustBeDefinedError as T, name as V, MfaRateLimitedError as _, DYNAMIC_ICONIC_SPRITE_URL as a, InvalidExternalAuthError as b, CHAINS_INFO_MAP as c, UnauthorizedError as d, createDeviceSignatureHeadersMiddleware as f, SandboxMaximumThresholdReachedError as g, getNonce as h, DYNAMIC_WAAS_METADATA as i, extractSessionId as j, DEFAULT_PII_FIELDS as k, fetchAndStoreNonces as l, getDeviceSigner as m, DEFAULT_WAAS_BASE_API_URL as n, SDK_API_CORE_VERSION as o, getHeadersForNonceSignedByDeviceSigners as p, DEFAULT_WAAS_BASE_MPC_RELAY_API_URL as r, getChainFromVerifiedCredentialChain as s, InvalidParamError as t, createApiClient as u, MfaInvalidOtpError as v, assertDefined as w, APIError as x, LinkCredentialError as y, BaseError as z };
|
|
1154
|
+
//# sourceMappingURL=InvalidParamError-Crwntjl7.native.esm.js.map
|