@dynamic-labs-sdk/client 0.24.0 → 0.25.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-B5NwKSKU.native.esm.js +1177 -0
- package/dist/InvalidParamError-B5NwKSKU.native.esm.js.map +1 -0
- package/dist/{InvalidParamError-kLBXFKhe.esm.js → InvalidParamError-BiVmL7nM.esm.js} +4 -4
- package/dist/InvalidParamError-BiVmL7nM.esm.js.map +1 -0
- package/dist/{InvalidParamError-BgmShvv_.cjs.js → InvalidParamError-D-d-UfBL.cjs.js} +5 -5
- package/dist/InvalidParamError-D-d-UfBL.cjs.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-qK9GIBpr.cjs.js → NotWaasWalletAccountError-BJaemI4V.cjs.js} +3 -3
- package/dist/{NotWaasWalletAccountError-qK9GIBpr.cjs.js.map → NotWaasWalletAccountError-BJaemI4V.cjs.js.map} +1 -1
- package/dist/NotWaasWalletAccountError-BX5lUnKT.native.esm.js +50 -0
- package/dist/NotWaasWalletAccountError-BX5lUnKT.native.esm.js.map +1 -0
- package/dist/{NotWaasWalletAccountError-VJL72OTC.esm.js → NotWaasWalletAccountError-Bo4VhW4n.esm.js} +3 -3
- package/dist/{NotWaasWalletAccountError-VJL72OTC.esm.js.map → NotWaasWalletAccountError-Bo4VhW4n.esm.js.map} +1 -1
- package/dist/client/core/createCore/createCore.d.ts.map +1 -1
- package/dist/client/core/types/DynamicCore.d.ts +4 -0
- package/dist/client/core/types/DynamicCore.d.ts.map +1 -1
- package/dist/client/types/DynamicClientConfig.d.ts +10 -0
- package/dist/client/types/DynamicClientConfig.d.ts.map +1 -1
- package/dist/core.cjs.js +5 -5
- package/dist/core.cjs.js.map +1 -1
- package/dist/core.esm.js +5 -5
- package/dist/core.esm.js.map +1 -1
- package/dist/core.native.esm.js +377 -0
- package/dist/core.native.esm.js.map +1 -0
- package/dist/errors/APIError/APIError.d.ts.map +1 -1
- package/dist/errors/InvalidParamError.d.ts.map +1 -1
- package/dist/errors/InvalidStorageValue.d.ts.map +1 -1
- package/dist/errors/InvalidWalletProviderKeyError.d.ts.map +1 -1
- package/dist/errors/MethodNotImplementedError.d.ts.map +1 -1
- package/dist/errors/MissingSocialUrlParamError.d.ts.map +1 -1
- package/dist/errors/NoSmartWalletAccountSignerFoundError.d.ts.map +1 -1
- package/dist/errors/UnavailableInServerSideError.d.ts.map +1 -1
- package/dist/errors/ValueMustBeDefinedError.d.ts.map +1 -1
- package/dist/errors/WalletAccountAlreadyVerifiedError.d.ts.map +1 -1
- package/dist/exports/index.d.ts +4 -4
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/{getNetworkProviderFromNetworkId-RlnraKJN.esm.js → getNetworkProviderFromNetworkId-5dK99mQR.esm.js} +5 -5
- package/dist/getNetworkProviderFromNetworkId-5dK99mQR.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-B8OjAdet.cjs.js → getNetworkProviderFromNetworkId-Cl2XDWo9.cjs.js} +5 -5
- package/dist/getNetworkProviderFromNetworkId-Cl2XDWo9.cjs.js.map +1 -0
- package/dist/getNetworkProviderFromNetworkId-DWOYr3uv.native.esm.js +1302 -0
- package/dist/getNetworkProviderFromNetworkId-DWOYr3uv.native.esm.js.map +1 -0
- package/dist/{getSignedSessionId-DBQS7lht.cjs.js → getSignedSessionId-BbhZjeRt.cjs.js} +3 -3
- package/dist/{getSignedSessionId-DBQS7lht.cjs.js.map → getSignedSessionId-BbhZjeRt.cjs.js.map} +1 -1
- package/dist/{getSignedSessionId-CvNFnwt1.esm.js → getSignedSessionId-DakTrfSz.esm.js} +3 -3
- package/dist/{getSignedSessionId-CvNFnwt1.esm.js.map → getSignedSessionId-DakTrfSz.esm.js.map} +1 -1
- package/dist/getSignedSessionId-Dk3_TQLq.native.esm.js +67 -0
- package/dist/getSignedSessionId-Dk3_TQLq.native.esm.js.map +1 -0
- package/dist/{getVerifiedCredentialForWalletAccount-CBJrrV08.cjs.js → getVerifiedCredentialForWalletAccount-BDvkZbtb.cjs.js} +3 -3
- package/dist/getVerifiedCredentialForWalletAccount-BDvkZbtb.cjs.js.map +1 -0
- package/dist/{getVerifiedCredentialForWalletAccount-8VlwTOBc.esm.js → getVerifiedCredentialForWalletAccount-ByUSFAHs.esm.js} +2 -2
- package/dist/getVerifiedCredentialForWalletAccount-ByUSFAHs.esm.js.map +1 -0
- package/dist/getVerifiedCredentialForWalletAccount-Dhqf6Tdl.native.esm.js +783 -0
- package/dist/getVerifiedCredentialForWalletAccount-Dhqf6Tdl.native.esm.js.map +1 -0
- package/dist/index.cjs.js +73 -49
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +73 -49
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +7000 -0
- package/dist/index.native.esm.js.map +1 -0
- package/dist/{isMfaRequiredForAction-9NDyQhHS.cjs.js → isMfaRequiredForAction-CYrluCK-.cjs.js} +2 -2
- package/dist/{isMfaRequiredForAction-9NDyQhHS.cjs.js.map → isMfaRequiredForAction-CYrluCK-.cjs.js.map} +1 -1
- package/dist/{isMfaRequiredForAction-8NlpzYe6.esm.js → isMfaRequiredForAction-SFbQW5j5.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-8NlpzYe6.esm.js.map → isMfaRequiredForAction-SFbQW5j5.esm.js.map} +1 -1
- package/dist/isMfaRequiredForAction-y15A_lhP.native.esm.js +89 -0
- package/dist/isMfaRequiredForAction-y15A_lhP.native.esm.js.map +1 -0
- package/dist/modules/auth/decodeJwt/decodeJwt.d.ts.map +1 -1
- package/dist/modules/auth/externalAuth/signInWithExternalJwt/signInWithExternalJwt.d.ts +0 -1
- package/dist/modules/auth/externalAuth/signInWithExternalJwt/signInWithExternalJwt.d.ts.map +1 -1
- package/dist/modules/auth/extractSessionId/extractSessionId.d.ts.map +1 -1
- package/dist/modules/auth/initializeAuth/setLongTimeout/setLongTimeout.d.ts.map +1 -1
- package/dist/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/addOAuthUrlParams/addOAuthUrlParams.d.ts.map +1 -1
- package/dist/modules/auth/social/oauth/authenticateWithSocial/buildOAuthUrl/buildOAuthUrl.d.ts.map +1 -1
- package/dist/modules/auth/social/removeDynamicOauthParamsFromUrl/removeDynamicOauthParamsFromUrl.d.ts.map +1 -1
- package/dist/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.d.ts.map +1 -1
- package/dist/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.d.ts.map +1 -1
- package/dist/modules/checkout/attachCheckoutTransactionSource/attachCheckoutTransactionSource.d.ts +34 -6
- package/dist/modules/checkout/attachCheckoutTransactionSource/attachCheckoutTransactionSource.d.ts.map +1 -1
- package/dist/modules/checkout/broadcastCheckoutTransaction/broadcastCheckoutTransaction.d.ts +11 -3
- package/dist/modules/checkout/broadcastCheckoutTransaction/broadcastCheckoutTransaction.d.ts.map +1 -1
- package/dist/modules/checkout/checkout.types.d.ts +1 -0
- package/dist/modules/checkout/checkout.types.d.ts.map +1 -1
- package/dist/modules/checkout/trackCheckoutTransaction/trackCheckoutTransaction.d.ts +7 -3
- package/dist/modules/checkout/trackCheckoutTransaction/trackCheckoutTransaction.d.ts.map +1 -1
- package/dist/modules/checkout/utils/createCheckoutSessionTokenStorageKey/createCheckoutSessionTokenStorageKey.d.ts.map +1 -1
- package/dist/modules/checkout/utils/subscribeToCheckoutTransaction/subscribeToCheckoutTransaction.d.ts.map +1 -1
- package/dist/modules/instrumentation/setInstrumentationEnabled/setInstrumentationEnabled.d.ts.map +1 -1
- package/dist/modules/keychainMigration/migrateSessionKeyToKeychain/KeyMigrationError.d.ts.map +1 -1
- package/dist/modules/legacyWalletBook/getWalletConnectCatalog/shouldFilterWallet/shouldFilterWallet.d.ts.map +1 -1
- package/dist/modules/otp/sendEmailOTP/sendEmailOTP.d.ts +0 -1
- package/dist/modules/otp/sendEmailOTP/sendEmailOTP.d.ts.map +1 -1
- package/dist/modules/otp/sendSmsOTP/sendSmsOTP.d.ts +0 -1
- package/dist/modules/otp/sendSmsOTP/sendSmsOTP.d.ts.map +1 -1
- package/dist/modules/user/updateUser/updateUser.d.ts +0 -1
- package/dist/modules/user/updateUser/updateUser.d.ts.map +1 -1
- package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
- package/dist/modules/waas/createWaasProvider/createWaasProvider.d.ts.map +1 -1
- package/dist/modules/waas/getWaasChainNameFromChain/getWaasChainNameFromChain.d.ts.map +1 -1
- package/dist/modules/wallets/networks/createBaseNetworkProvider/createBaseNetworkProvider.d.ts.map +1 -1
- package/dist/modules/wallets/networks/getSdkChainFromApiChainName/getSdkChainFromApiChainName.d.ts.map +1 -1
- package/dist/modules/wallets/utils/assertWalletProviderMethodDefined/assertWalletProviderMethodDefined.d.ts.map +1 -1
- package/dist/modules/wallets/utils/getAllProvidersFromWindow/getAllProvidersFromWindow.d.ts.map +1 -1
- package/dist/modules/wallets/utils/getInjectedProviderFromWindow/getInjectedProviderFromWindow.d.ts.map +1 -1
- package/dist/modules/wallets/utils/isSameAddress/isSameAddress.d.ts.map +1 -1
- package/dist/modules/wallets/utils/normalizeAddress/normalizeAddress.d.ts.map +1 -1
- package/dist/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.d.ts.map +1 -1
- package/dist/services/instrumentation/createInstrumentation/createInstrumentation.d.ts.map +1 -1
- package/dist/services/instrumentation/instrumentFunction/extractParams/extractParams.d.ts.map +1 -1
- package/dist/services/keychain/createIndexedDBKeychainService/KeyNotFoundError.d.ts.map +1 -1
- package/dist/services/keychain/createIndexedDBKeychainService/createIndexedDBKeychainService.d.ts.map +1 -1
- package/dist/services/keychain/createIndexedDBKeychainService/utils/deleteIndexedDBItem.d.ts.map +1 -1
- package/dist/services/keychain/createIndexedDBKeychainService/utils/getIndexedDBItem.d.ts.map +1 -1
- package/dist/services/keychain/createIndexedDBKeychainService/utils/setIndexedDBItem.d.ts.map +1 -1
- package/dist/services/logger/createLogger/createLogger.d.ts.map +1 -1
- package/dist/services/realtime/createRealtimeService/createRealtimeService.d.ts.map +1 -1
- package/dist/services/realtime/realtime.types.d.ts +1 -0
- package/dist/services/realtime/realtime.types.d.ts.map +1 -1
- package/dist/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.d.ts.map +1 -1
- package/dist/services/runtimeServices/createRuntimeServices/createRuntimeServices.d.ts.map +1 -1
- package/dist/services/storage/createStorage/formatForStorage/isValidDateISOString/isValidDateISOString.d.ts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/assertDefined/assertDefined.d.ts.map +1 -1
- package/dist/utils/base64UrlDecode/base64UrlDecode.d.ts.map +1 -1
- package/dist/utils/digestSHA256/digestSHA256.d.ts.map +1 -1
- package/dist/utils/getChainFromVerifiedCredentialChain/getChainFromVerifiedCredentialChain.d.ts.map +1 -1
- package/dist/utils/isEqualShallow/isEqualShallow.d.ts.map +1 -1
- package/dist/utils/isErrorWithCode/isErrorWithCode.d.ts.map +1 -1
- package/dist/utils/isMobile/isMobile.d.ts.map +1 -1
- package/dist/utils/observable/createObservableState/createObservableState.d.ts.map +1 -1
- package/dist/utils/observable/subscribeWithSelector/subscribeWithSelector.d.ts.map +1 -1
- package/dist/utils/retryOnFail/InvalidRetryOnFailCallError.d.ts.map +1 -1
- package/dist/utils/setCookie/setCookie.d.ts.map +1 -1
- package/dist/waas.cjs.js +4 -4
- package/dist/waas.esm.js +3 -3
- package/dist/waas.native.esm.js +506 -0
- package/dist/waas.native.esm.js.map +1 -0
- package/dist/waasCore.cjs.js +7 -5
- package/dist/waasCore.cjs.js.map +1 -1
- package/dist/waasCore.esm.js +6 -4
- package/dist/waasCore.esm.js.map +1 -1
- package/dist/waasCore.native.esm.js +253 -0
- package/dist/waasCore.native.esm.js.map +1 -0
- package/package.json +8 -4
- package/dist/InvalidParamError-BgmShvv_.cjs.js.map +0 -1
- package/dist/InvalidParamError-kLBXFKhe.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-B8OjAdet.cjs.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-RlnraKJN.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-8VlwTOBc.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-CBJrrV08.cjs.js.map +0 -1
|
@@ -0,0 +1,783 @@
|
|
|
1
|
+
import { F as getDefaultClient, O as isCookieEnabled, R as BaseError, i as DYNAMIC_WAAS_METADATA, k as assertDefined, s as __getChainFromVerifiedCredentialChain_wrapped, t as InvalidParamError, w as instrumentFunction, z as getCore } from "./InvalidParamError-B5NwKSKU.native.esm.js";
|
|
2
|
+
import { JwtVerifiedCredentialFormatEnum, WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/setCookie/setCookie.ts
|
|
5
|
+
/**
|
|
6
|
+
* Sefelly sets the cookie in the browser.
|
|
7
|
+
* @not-instrumented
|
|
8
|
+
*/
|
|
9
|
+
const setCookie = (cookie) => {
|
|
10
|
+
document.cookie = cookie;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/modules/clientEvents/clientEvents.ts
|
|
15
|
+
/**
|
|
16
|
+
* Adds an event listener for Dynamic client events.
|
|
17
|
+
*
|
|
18
|
+
* This function allows you to listen for various events emitted by the Dynamic client,
|
|
19
|
+
* such as authentication state changes, wallet connections, and more.
|
|
20
|
+
*
|
|
21
|
+
* @param params.event - The event name to listen for.
|
|
22
|
+
* @param params.listener - The callback function to execute when the event is fired.
|
|
23
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
24
|
+
* @returns A function that can be called to remove the listener.
|
|
25
|
+
* @instrumented
|
|
26
|
+
*/
|
|
27
|
+
const onEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
28
|
+
const { eventEmitter } = getCore(client);
|
|
29
|
+
eventEmitter.on(event, listener);
|
|
30
|
+
return () => {
|
|
31
|
+
eventEmitter.off(event, listener);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Removes an event listener from Dynamic client events.
|
|
36
|
+
*
|
|
37
|
+
* This function unsubscribes a previously registered event listener
|
|
38
|
+
* from the specified Dynamic client event.
|
|
39
|
+
*
|
|
40
|
+
* @param params.event - The event name to remove the listener from.
|
|
41
|
+
* @param params.listener - The callback function to remove.
|
|
42
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
43
|
+
* @instrumented
|
|
44
|
+
*/
|
|
45
|
+
const offEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
46
|
+
const { eventEmitter } = getCore(client);
|
|
47
|
+
eventEmitter.off(event, listener);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Adds a one-time event listener for Dynamic client events.
|
|
51
|
+
*
|
|
52
|
+
* This function listens for an event that will automatically remove itself
|
|
53
|
+
* after being triggered once.
|
|
54
|
+
*
|
|
55
|
+
* @param params.event - The event name to listen for.
|
|
56
|
+
* @param params.listener - The callback function to execute when the event is fired.
|
|
57
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
58
|
+
* @returns A function that can be called to remove the listener before it fires.
|
|
59
|
+
* @instrumented
|
|
60
|
+
*/
|
|
61
|
+
const onceEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
62
|
+
const { eventEmitter } = getCore(client);
|
|
63
|
+
eventEmitter.once(event, listener);
|
|
64
|
+
return () => {
|
|
65
|
+
eventEmitter.off(event, listener);
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Emits a Dynamic client event.
|
|
70
|
+
*
|
|
71
|
+
* This function triggers an event that will be received by all registered
|
|
72
|
+
* listeners for the specified event type.
|
|
73
|
+
*
|
|
74
|
+
* @param params.event - The event name to emit.
|
|
75
|
+
* @param params.args - The arguments to pass to event listeners.
|
|
76
|
+
* @param client - The Dynamic client instance.
|
|
77
|
+
* @not-instrumented
|
|
78
|
+
*/
|
|
79
|
+
const emitEvent = ({ event, args }, client) => {
|
|
80
|
+
const { eventEmitter } = getCore(client);
|
|
81
|
+
eventEmitter.emit(event, args);
|
|
82
|
+
};
|
|
83
|
+
const __onEvent_impl = onEvent;
|
|
84
|
+
const __onEvent_wrapped = instrumentFunction({
|
|
85
|
+
fn: __onEvent_impl,
|
|
86
|
+
functionName: "onEvent",
|
|
87
|
+
getCore: () => {
|
|
88
|
+
try {
|
|
89
|
+
return getCore(getDefaultClient());
|
|
90
|
+
} catch {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const __offEvent_impl = offEvent;
|
|
96
|
+
const __offEvent_wrapped = instrumentFunction({
|
|
97
|
+
fn: __offEvent_impl,
|
|
98
|
+
functionName: "offEvent",
|
|
99
|
+
getCore: () => {
|
|
100
|
+
try {
|
|
101
|
+
return getCore(getDefaultClient());
|
|
102
|
+
} catch {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const __onceEvent_impl = onceEvent;
|
|
108
|
+
const __onceEvent_wrapped = instrumentFunction({
|
|
109
|
+
fn: __onceEvent_impl,
|
|
110
|
+
functionName: "onceEvent",
|
|
111
|
+
getCore: () => {
|
|
112
|
+
try {
|
|
113
|
+
return getCore(getDefaultClient());
|
|
114
|
+
} catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/errors/InvalidWalletProviderKeyError.ts
|
|
122
|
+
var InvalidWalletProviderKeyError = class extends BaseError {
|
|
123
|
+
constructor(value) {
|
|
124
|
+
super({
|
|
125
|
+
cause: null,
|
|
126
|
+
code: "invalid_wallet_provider_key",
|
|
127
|
+
docsUrl: null,
|
|
128
|
+
name: "InvalidWalletProviderKeyError",
|
|
129
|
+
shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts
|
|
136
|
+
/** @not-instrumented */
|
|
137
|
+
const splitWalletProviderKey = (walletProviderKey) => {
|
|
138
|
+
const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] = walletProviderKey.split(":");
|
|
139
|
+
if (!normalizedWalletNameWithChain || !Object.values(WalletProviderEnum).includes(walletProviderType) || rest.length > 0) throw new InvalidWalletProviderKeyError(walletProviderKey);
|
|
140
|
+
return {
|
|
141
|
+
normalizedWalletNameWithChain,
|
|
142
|
+
suffix,
|
|
143
|
+
walletProviderType
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts
|
|
149
|
+
/** @not-instrumented */
|
|
150
|
+
const normalizeAddress = (address, chain) => {
|
|
151
|
+
let normalizedAddress = address;
|
|
152
|
+
if (normalizedAddress?.startsWith("0x")) normalizedAddress = normalizedAddress.slice(2);
|
|
153
|
+
normalizedAddress = ["EVM", "FLOW"].includes(chain) ? normalizedAddress?.toLowerCase() : normalizedAddress;
|
|
154
|
+
return normalizedAddress;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts
|
|
159
|
+
/** @not-instrumented */
|
|
160
|
+
const formatWalletAccountId = ({ address, chain, walletProviderKey }) => {
|
|
161
|
+
const { normalizedWalletNameWithChain } = splitWalletProviderKey(walletProviderKey);
|
|
162
|
+
return `${normalizedWalletNameWithChain}:${normalizeAddress(address, chain)}`;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts
|
|
167
|
+
/** @not-instrumented */
|
|
168
|
+
const convertUnverifiedWalletAccountToWalletAccount = ({ unverifiedWalletAccount }) => ({
|
|
169
|
+
address: unverifiedWalletAccount.address,
|
|
170
|
+
addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,
|
|
171
|
+
chain: unverifiedWalletAccount.chain,
|
|
172
|
+
id: formatWalletAccountId({
|
|
173
|
+
address: unverifiedWalletAccount.address,
|
|
174
|
+
chain: unverifiedWalletAccount.chain,
|
|
175
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
176
|
+
}),
|
|
177
|
+
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
178
|
+
verifiedCredentialId: null,
|
|
179
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts
|
|
184
|
+
/**
|
|
185
|
+
* Format the raw wallet name and chain to get the value we can use for
|
|
186
|
+
* verified credentials' `walletName` field.
|
|
187
|
+
* @not-instrumented
|
|
188
|
+
*/
|
|
189
|
+
const normalizeWalletNameWithChain = ({ displayName, chain }) => {
|
|
190
|
+
const sanitizedWalletName = displayName.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
191
|
+
const chainLowered = chain.toLocaleLowerCase();
|
|
192
|
+
if (sanitizedWalletName.endsWith(chainLowered)) return sanitizedWalletName;
|
|
193
|
+
return `${sanitizedWalletName}${chainLowered}`;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts
|
|
198
|
+
/**
|
|
199
|
+
* Assembles the wallet provider key from the wallet name, chain, and wallet provider type.
|
|
200
|
+
*
|
|
201
|
+
* The suffix is optional and can be used to add a uniquely identifying string to the key, which
|
|
202
|
+
* might be necessary for some wallet providers (like Wallet Connect).
|
|
203
|
+
*
|
|
204
|
+
* IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account
|
|
205
|
+
* to not be able to find its wallet provider when connecting to a new device (it won't be possible
|
|
206
|
+
* to determine the full key just from the Verified Credential data).
|
|
207
|
+
* @not-instrumented
|
|
208
|
+
*/
|
|
209
|
+
const formatWalletProviderKey = ({ suffix, chain, displayName, walletProviderType }) => {
|
|
210
|
+
return `${normalizeWalletNameWithChain({
|
|
211
|
+
chain,
|
|
212
|
+
displayName
|
|
213
|
+
})}:${walletProviderType}${suffix ? `:${suffix}` : ""}`;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts
|
|
218
|
+
/** @not-instrumented */
|
|
219
|
+
const getWalletProviderKeyFromVerifiedCredential = ({ verifiedCredential }, client) => {
|
|
220
|
+
const { walletProviderKeyMap } = getCore(client).state.get();
|
|
221
|
+
const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];
|
|
222
|
+
if (storedWalletProviderKey) return { walletProviderKey: storedWalletProviderKey };
|
|
223
|
+
/**
|
|
224
|
+
* We fallback to comprising the wallet provider key from walletName and walletProvider.
|
|
225
|
+
*
|
|
226
|
+
* Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider
|
|
227
|
+
* keys, so this won't be enough for them.
|
|
228
|
+
* Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider
|
|
229
|
+
* and will require reconnection.
|
|
230
|
+
* Read walletProvider.types.ts for more info.
|
|
231
|
+
*/
|
|
232
|
+
assertDefined(verifiedCredential.walletName, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`);
|
|
233
|
+
assertDefined(verifiedCredential.walletProvider, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`);
|
|
234
|
+
assertDefined(verifiedCredential.chain, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`);
|
|
235
|
+
return { walletProviderKey: formatWalletProviderKey({
|
|
236
|
+
chain: __getChainFromVerifiedCredentialChain_wrapped(verifiedCredential.chain),
|
|
237
|
+
displayName: verifiedCredential.walletName,
|
|
238
|
+
walletProviderType: verifiedCredential.walletProvider
|
|
239
|
+
}) };
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts
|
|
244
|
+
/** @not-instrumented */
|
|
245
|
+
const convertVerifiedCredentialToWalletAccount = ({ verifiedCredential }, client) => {
|
|
246
|
+
assertDefined(verifiedCredential.address, "Missing address in verified credential");
|
|
247
|
+
assertDefined(verifiedCredential.chain, "Missing chain in verified credential");
|
|
248
|
+
const chain = __getChainFromVerifiedCredentialChain_wrapped(verifiedCredential.chain);
|
|
249
|
+
const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential({ verifiedCredential }, client);
|
|
250
|
+
const walletAccountId = formatWalletAccountId({
|
|
251
|
+
address: verifiedCredential.address,
|
|
252
|
+
chain,
|
|
253
|
+
walletProviderKey
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
address: verifiedCredential.address,
|
|
257
|
+
addressesWithTypes: verifiedCredential.walletAdditionalAddresses,
|
|
258
|
+
chain,
|
|
259
|
+
hardwareWalletVendor: verifiedCredential.walletProperties?.hardwareWallet,
|
|
260
|
+
id: walletAccountId,
|
|
261
|
+
lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,
|
|
262
|
+
verifiedCredentialId: verifiedCredential.id,
|
|
263
|
+
walletProviderKey
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts
|
|
269
|
+
/** @not-instrumented */
|
|
270
|
+
const getWalletAccountsFromState = ({ unverifiedWalletAccounts, user }, client) => {
|
|
271
|
+
const walletAccountsMap = /* @__PURE__ */ new Map();
|
|
272
|
+
/**
|
|
273
|
+
* Handle the unverified wallet accounts before the user verified credentials
|
|
274
|
+
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
275
|
+
*/
|
|
276
|
+
unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {
|
|
277
|
+
const walletAccount = convertUnverifiedWalletAccountToWalletAccount({ unverifiedWalletAccount });
|
|
278
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
279
|
+
});
|
|
280
|
+
(user?.verifiedCredentials ?? []).filter((verified) => verified.format === JwtVerifiedCredentialFormatEnum.Blockchain).forEach((verifiedWalletAccount) => {
|
|
281
|
+
const walletAccount = convertVerifiedCredentialToWalletAccount({ verifiedCredential: verifiedWalletAccount }, client);
|
|
282
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
283
|
+
});
|
|
284
|
+
return Array.from(walletAccountsMap.values());
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/modules/wallets/getWalletAccounts/getWalletAccounts.ts
|
|
289
|
+
/**
|
|
290
|
+
* Retrieves all wallet accounts associated with the current session.
|
|
291
|
+
*
|
|
292
|
+
* This function returns both verified and unverified wallet accounts,
|
|
293
|
+
* combining data from user credentials and local unverified accounts.
|
|
294
|
+
* You can differentiate between verified and unverified wallet accounts by
|
|
295
|
+
* checking the `verifiedCredentialId` property.
|
|
296
|
+
*
|
|
297
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
298
|
+
* @returns An array of wallet accounts associated with the session.
|
|
299
|
+
* @instrumented
|
|
300
|
+
*/
|
|
301
|
+
const getWalletAccounts = (client = getDefaultClient()) => {
|
|
302
|
+
const { unverifiedWalletAccounts, user } = getCore(client).state.get();
|
|
303
|
+
return getWalletAccountsFromState({
|
|
304
|
+
unverifiedWalletAccounts,
|
|
305
|
+
user
|
|
306
|
+
}, client);
|
|
307
|
+
};
|
|
308
|
+
const __getWalletAccounts_impl = getWalletAccounts;
|
|
309
|
+
const __getWalletAccounts_wrapped = instrumentFunction({
|
|
310
|
+
fn: __getWalletAccounts_impl,
|
|
311
|
+
functionName: "getWalletAccounts",
|
|
312
|
+
getCore: () => {
|
|
313
|
+
try {
|
|
314
|
+
return getCore(getDefaultClient());
|
|
315
|
+
} catch {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/errors/NoWalletProviderFoundError.ts
|
|
323
|
+
var NoWalletProviderFoundError = class extends BaseError {
|
|
324
|
+
constructor({ walletProviderKey }) {
|
|
325
|
+
super({
|
|
326
|
+
cause: null,
|
|
327
|
+
code: "no_wallet_provider_found_error",
|
|
328
|
+
docsUrl: null,
|
|
329
|
+
name: "NoWalletProviderFoundError",
|
|
330
|
+
shortMessage: `No wallet provider found with key: ${walletProviderKey}`
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts
|
|
337
|
+
/**
|
|
338
|
+
* Creates a service accessor function that manages service instantiation and caching.
|
|
339
|
+
* The returned function will either retrieve an existing service from the registry or
|
|
340
|
+
* create a new one using the provided builder function.
|
|
341
|
+
*
|
|
342
|
+
* @template - The type of service to be created/accessed
|
|
343
|
+
* @param key - Unique identifier for the service in the registry
|
|
344
|
+
* @param builder - Function that creates the service instance when called with a DynamicClient
|
|
345
|
+
* @instrumented
|
|
346
|
+
*/
|
|
347
|
+
const createRuntimeServiceAccessKey = (key, builder) => (client) => {
|
|
348
|
+
const { runtimeServices } = getCore(client);
|
|
349
|
+
const currentService = runtimeServices.getByKey(key);
|
|
350
|
+
if (currentService) return currentService;
|
|
351
|
+
const service = builder(client);
|
|
352
|
+
runtimeServices.register(key, service);
|
|
353
|
+
return service;
|
|
354
|
+
};
|
|
355
|
+
const __createRuntimeServiceAccessKey_impl = createRuntimeServiceAccessKey;
|
|
356
|
+
const __createRuntimeServiceAccessKey_wrapped = instrumentFunction({
|
|
357
|
+
fn: __createRuntimeServiceAccessKey_impl,
|
|
358
|
+
functionName: "createRuntimeServiceAccessKey",
|
|
359
|
+
getCore: () => {
|
|
360
|
+
try {
|
|
361
|
+
return getCore(getDefaultClient());
|
|
362
|
+
} catch {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts
|
|
370
|
+
/**
|
|
371
|
+
* Creates a new wallet provider registry that manages wallet providers with priority-based registration.
|
|
372
|
+
*
|
|
373
|
+
* @returns The wallet provider registry instance
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const registry = createWalletProviderRegistry();
|
|
378
|
+
*
|
|
379
|
+
* registry.register({
|
|
380
|
+
* priority: WalletProviderPriority.WALLET_SDK,
|
|
381
|
+
* walletProvider: myWalletProvider
|
|
382
|
+
* });
|
|
383
|
+
*
|
|
384
|
+
* const provider = registry.getByKey('my-wallet-key');
|
|
385
|
+
* const providers = registry.listProviders();
|
|
386
|
+
* ```
|
|
387
|
+
* @not-instrumented
|
|
388
|
+
*/
|
|
389
|
+
const createWalletProviderRegistry = (client) => {
|
|
390
|
+
const registry = /* @__PURE__ */ new Map();
|
|
391
|
+
return {
|
|
392
|
+
getByKey: (key) => registry.get(key)?.walletProvider,
|
|
393
|
+
listProviders: () => Array.from(registry.values()).map((v) => v.walletProvider),
|
|
394
|
+
register: (args) => {
|
|
395
|
+
const existingEntry = registry.get(args.walletProvider.key);
|
|
396
|
+
if (existingEntry) {
|
|
397
|
+
if (existingEntry.priority < args.priority) {
|
|
398
|
+
registry.set(args.walletProvider.key, args);
|
|
399
|
+
emitEvent({
|
|
400
|
+
args: { walletProviderKey: args.walletProvider.key },
|
|
401
|
+
event: "walletProviderChanged"
|
|
402
|
+
}, client);
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
registry.set(args.walletProvider.key, args);
|
|
406
|
+
emitEvent({
|
|
407
|
+
args: { walletProvider: args.walletProvider },
|
|
408
|
+
event: "walletProviderRegistered"
|
|
409
|
+
}, client);
|
|
410
|
+
emitEvent({
|
|
411
|
+
args: { walletProviderKey: args.walletProvider.key },
|
|
412
|
+
event: "walletProviderChanged"
|
|
413
|
+
}, client);
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
unregister: (key) => {
|
|
417
|
+
registry.delete(key);
|
|
418
|
+
emitEvent({
|
|
419
|
+
args: { walletProviderKey: key },
|
|
420
|
+
event: "walletProviderUnregistered"
|
|
421
|
+
}, client);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts
|
|
428
|
+
/**
|
|
429
|
+
* This function provides access to a shared instance of the wallet provider registry.
|
|
430
|
+
*
|
|
431
|
+
* It ensures that the same registry instance is used throughout the client to maintaining
|
|
432
|
+
* consistency of registered wallet providers across different parts of the codebase.
|
|
433
|
+
*
|
|
434
|
+
* @returns The wallet provider registry instance
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* // Get the registry instance
|
|
439
|
+
* const registry = getWalletProviderRegistry();
|
|
440
|
+
*
|
|
441
|
+
* // Register a wallet provider
|
|
442
|
+
* registry.register({
|
|
443
|
+
* priority: WalletProviderPriority.WALLET_SDK,
|
|
444
|
+
* walletProvider: myWalletProvider
|
|
445
|
+
* });
|
|
446
|
+
*
|
|
447
|
+
* // Retrieve a specific provider
|
|
448
|
+
* const provider = registry.getByKey('metamaskevm');
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
const getWalletProviderRegistry = __createRuntimeServiceAccessKey_wrapped("walletProviderRegistry", (client) => createWalletProviderRegistry(client));
|
|
452
|
+
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts
|
|
455
|
+
let WalletProviderPriority = /* @__PURE__ */ function(WalletProviderPriority$1) {
|
|
456
|
+
/**
|
|
457
|
+
* Highest priority should be used by wallet providers that implement
|
|
458
|
+
* the most reliable wallet integration.
|
|
459
|
+
* example: The SDK provided by the wallet provider.
|
|
460
|
+
*/
|
|
461
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SDK"] = 100] = "WALLET_SDK";
|
|
462
|
+
/**
|
|
463
|
+
* Medium priority should be used by wallet providers that implement
|
|
464
|
+
* a wallet integration via some reliable standard.
|
|
465
|
+
* example: A wallet provider that uses EIP6963 announcement.
|
|
466
|
+
*/
|
|
467
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SELF_ANNOUNCEMENT_STANDARD"] = 50] = "WALLET_SELF_ANNOUNCEMENT_STANDARD";
|
|
468
|
+
/**
|
|
469
|
+
* Low priority should be used by wallet providers that implement
|
|
470
|
+
* a wallet integration on a less reliable standard.
|
|
471
|
+
* example: A wallet provider that uses window.ethereum, where the
|
|
472
|
+
* window key can be overridden by other extensions.
|
|
473
|
+
*/
|
|
474
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WINDOW_INJECT"] = 20] = "WINDOW_INJECT";
|
|
475
|
+
return WalletProviderPriority$1;
|
|
476
|
+
}({});
|
|
477
|
+
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts
|
|
480
|
+
/** @instrumented */
|
|
481
|
+
const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
|
|
482
|
+
const walletProvider = getWalletProviderRegistry(client).getByKey(walletAccount.walletProviderKey);
|
|
483
|
+
if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey: walletAccount.walletProviderKey });
|
|
484
|
+
return walletProvider;
|
|
485
|
+
};
|
|
486
|
+
const __getWalletProviderFromWalletAccount_impl = getWalletProviderFromWalletAccount;
|
|
487
|
+
const __getWalletProviderFromWalletAccount_wrapped = instrumentFunction({
|
|
488
|
+
fn: __getWalletProviderFromWalletAccount_impl,
|
|
489
|
+
functionName: "getWalletProviderFromWalletAccount",
|
|
490
|
+
getCore: () => {
|
|
491
|
+
try {
|
|
492
|
+
return getCore(getDefaultClient());
|
|
493
|
+
} catch {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/modules/auth/consts.ts
|
|
501
|
+
const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
|
|
502
|
+
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/modules/wallets/emitWalletAccountsChangedEvent/emitWalletAccountsChangedEvent.ts
|
|
505
|
+
/**
|
|
506
|
+
* Emits the `walletAccountsChanged` event.
|
|
507
|
+
* @not-instrumented
|
|
508
|
+
*/
|
|
509
|
+
const emitWalletAccountsChangedEvent = (client) => {
|
|
510
|
+
emitEvent({
|
|
511
|
+
args: { walletAccounts: __getWalletAccounts_wrapped(client) },
|
|
512
|
+
event: "walletAccountsChanged"
|
|
513
|
+
}, client);
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/checkAndRaiseWalletAccountsChangedEvent/checkAndRaiseWalletAccountsChangedEvent.ts
|
|
518
|
+
/** @not-instrumented */
|
|
519
|
+
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client) => {
|
|
520
|
+
const core = getCore(client);
|
|
521
|
+
if (getWalletAccountsHash(previousState, client) !== getWalletAccountsHash(core.state.get(), client)) emitWalletAccountsChangedEvent(client);
|
|
522
|
+
};
|
|
523
|
+
const getWalletAccountsHash = (state, client) => getWalletAccountsFromState(state, client).map((walletAccount) => JSON.stringify(walletAccount)).sort().join("-");
|
|
524
|
+
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/modules/wallets/getWalletProviders/getWalletProviders.ts
|
|
527
|
+
/**
|
|
528
|
+
* Get all available wallet providers to interact with internally.
|
|
529
|
+
* @instrumented
|
|
530
|
+
*/
|
|
531
|
+
const getWalletProviders = (client) => {
|
|
532
|
+
return getWalletProviderRegistry(client).listProviders();
|
|
533
|
+
};
|
|
534
|
+
const __getWalletProviders_impl = getWalletProviders;
|
|
535
|
+
const __getWalletProviders_wrapped = instrumentFunction({
|
|
536
|
+
fn: __getWalletProviders_impl,
|
|
537
|
+
functionName: "getWalletProviders",
|
|
538
|
+
getCore: () => {
|
|
539
|
+
try {
|
|
540
|
+
return getCore(getDefaultClient());
|
|
541
|
+
} catch {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/modules/waas/isWaasWalletProvider/isWaasWalletProvider.ts
|
|
549
|
+
/** @not-instrumented */
|
|
550
|
+
const isWaasWalletProvider = (walletProvider) => {
|
|
551
|
+
return walletProvider.key.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/modules/waas/findWaasWalletProviderByChain/findWaasWalletProviderByChain.ts
|
|
556
|
+
/** @not-instrumented */
|
|
557
|
+
const findWaasWalletProviderByChain = ({ chain }, client) => {
|
|
558
|
+
const providers = __getWalletProviders_wrapped(client);
|
|
559
|
+
const waasProviderKey = formatWalletProviderKey({
|
|
560
|
+
chain,
|
|
561
|
+
displayName: DYNAMIC_WAAS_METADATA.displayName,
|
|
562
|
+
walletProviderType: WalletProviderEnum.EmbeddedWallet
|
|
563
|
+
});
|
|
564
|
+
const waasProvider = providers.find((provider) => provider.key === waasProviderKey && provider.chain === chain);
|
|
565
|
+
if (!waasProvider || !isWaasWalletProvider(waasProvider)) return null;
|
|
566
|
+
return waasProvider;
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/modules/waas/isWaasWalletAccount/isWaasWalletAccount.ts
|
|
571
|
+
/**
|
|
572
|
+
* This function determines whether the provided wallet account is a Dynamic
|
|
573
|
+
* WaaS wallet account.
|
|
574
|
+
*
|
|
575
|
+
* @param params.walletAccount - The wallet account to check.
|
|
576
|
+
* @returns True if the wallet account is a WaaS wallet account, false otherwise.
|
|
577
|
+
* @not-instrumented
|
|
578
|
+
*/
|
|
579
|
+
const isWaasWalletAccount = ({ walletAccount }) => {
|
|
580
|
+
return walletAccount.walletProviderKey.includes(DYNAMIC_WAAS_METADATA.normalizedWalletName);
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/modules/waas/restoreUserSharesForAllWalletAccounts/restoreUserSharesForAllWalletAccounts.ts
|
|
585
|
+
/** @not-instrumented */
|
|
586
|
+
const restoreUserSharesForAllWalletAccounts = async (client) => {
|
|
587
|
+
const waasWalletAccounts = __getWalletAccounts_wrapped(client).filter((walletAccount) => isWaasWalletAccount({ walletAccount }));
|
|
588
|
+
await Promise.all(waasWalletAccounts.map(async (walletAccount) => {
|
|
589
|
+
const provider = findWaasWalletProviderByChain({ chain: walletAccount.chain }, client);
|
|
590
|
+
/**
|
|
591
|
+
* The environment might not have the embedded wallet extensions installed.
|
|
592
|
+
* In that case there is no provider for the chain and we can skip restoring the user share.
|
|
593
|
+
*/
|
|
594
|
+
if (!provider) return;
|
|
595
|
+
return provider.restoreUserShareForWalletAccount({ walletAccount });
|
|
596
|
+
}));
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region src/modules/auth/decodeJwt/decodeJwt.ts
|
|
601
|
+
/**
|
|
602
|
+
* Decodes a JWT token and returns the full payload.
|
|
603
|
+
*
|
|
604
|
+
* This function extracts and returns the complete JWT payload including scopes,
|
|
605
|
+
* expiration time, and other claims.
|
|
606
|
+
*
|
|
607
|
+
* @param jwt - The JWT token string.
|
|
608
|
+
* @returns The decoded JWT payload object.
|
|
609
|
+
* @throws InvalidParamError if the token is invalid or cannot be decoded.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```typescript
|
|
613
|
+
* const payload = decodeJwt(jwt);
|
|
614
|
+
* // Returns: { scopes: ['wallet:export'], exp: 1234567890, ... }
|
|
615
|
+
* ```
|
|
616
|
+
* @not-instrumented
|
|
617
|
+
*/
|
|
618
|
+
const decodeJwt = (jwt) => {
|
|
619
|
+
try {
|
|
620
|
+
const parts = jwt.split(".");
|
|
621
|
+
if (parts.length !== 3) throw new InvalidParamError("Invalid JWT format");
|
|
622
|
+
const base64Payload = parts[1].replaceAll("-", "+").replaceAll("_", "/");
|
|
623
|
+
const paddedPayload = base64Payload + "=".repeat((4 - base64Payload.length % 4) % 4);
|
|
624
|
+
const decodedPayload = atob(paddedPayload);
|
|
625
|
+
return JSON.parse(decodedPayload);
|
|
626
|
+
} catch (error) {
|
|
627
|
+
if (error instanceof InvalidParamError) throw error;
|
|
628
|
+
throw new InvalidParamError(`Failed to decode JWT: ${error instanceof Error ? error.message : String(error)}`);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/normalizeScopes/normalizeScopes.ts
|
|
634
|
+
/**
|
|
635
|
+
* Normalizes scopes by deduplicating and sorting them.
|
|
636
|
+
* This creates a canonical representation for comparison.
|
|
637
|
+
*
|
|
638
|
+
* @param scopes - Array of scope strings (may contain duplicates)
|
|
639
|
+
* @returns Normalized, sorted array of unique scopes
|
|
640
|
+
* @not-instrumented
|
|
641
|
+
*/
|
|
642
|
+
const normalizeScopes = (scopes) => {
|
|
643
|
+
return [...new Set(scopes)].sort((a, b) => a.localeCompare(b));
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/parseElevatedAccessToken/parseElevatedAccessToken.ts
|
|
648
|
+
/**
|
|
649
|
+
* Validates and parses an elevated access token from a JWT string.
|
|
650
|
+
* Extracts scopes, expiration, and validates the token structure.
|
|
651
|
+
*
|
|
652
|
+
* Policy decisions:
|
|
653
|
+
* - Tokens without scopes are rejected (returns null)
|
|
654
|
+
* - Tokens with empty scopes array are rejected (returns null)
|
|
655
|
+
* - Tokens without exp field are rejected (returns null)
|
|
656
|
+
* - Expired tokens are rejected (returns null)
|
|
657
|
+
*
|
|
658
|
+
* @param token - JWT string containing the elevated access token
|
|
659
|
+
* @param now - Current date for expiration validation (defaults to new Date())
|
|
660
|
+
* @returns Parsed token data or null if token is invalid/expired
|
|
661
|
+
* @not-instrumented
|
|
662
|
+
*/
|
|
663
|
+
const parseElevatedAccessToken = (token, now = /* @__PURE__ */ new Date()) => {
|
|
664
|
+
const payload = decodeJwt(token);
|
|
665
|
+
const filteredScopes = ((payload?.scope)?.split(" ") ?? []).filter((s) => s.length > 0);
|
|
666
|
+
const singleUse = payload.singleUse ?? false;
|
|
667
|
+
if (!filteredScopes || filteredScopes.length === 0) return null;
|
|
668
|
+
if (!payload.exp) return null;
|
|
669
|
+
const expiresAt = /* @__PURE__ */ new Date(payload.exp * 1e3);
|
|
670
|
+
if (expiresAt <= now) return null;
|
|
671
|
+
return {
|
|
672
|
+
expiresAt,
|
|
673
|
+
normalizedScopes: normalizeScopes(filteredScopes),
|
|
674
|
+
scopes: filteredScopes,
|
|
675
|
+
singleUse,
|
|
676
|
+
token
|
|
677
|
+
};
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/elevatedAccessTokens/upsertElevatedAccessToken/upsertElevatedAccessToken.ts
|
|
682
|
+
/**
|
|
683
|
+
* Upserts an elevated access token into the current tokens array.
|
|
684
|
+
*
|
|
685
|
+
* Policy: Only one token per normalized scope-set is allowed.
|
|
686
|
+
* If a token with the same normalized scopes exists, it is replaced.
|
|
687
|
+
* This ensures we don't accumulate multiple tokens for the same scope combination.
|
|
688
|
+
*
|
|
689
|
+
* @param currentTokens - Current array of elevated access tokens
|
|
690
|
+
* @param newToken - New token to upsert
|
|
691
|
+
* @returns Updated array of tokens with the new token upserted
|
|
692
|
+
* @not-instrumented
|
|
693
|
+
*/
|
|
694
|
+
const upsertElevatedAccessToken = ({ currentTokens, newToken }) => {
|
|
695
|
+
const newScopeKey = normalizeScopes(newToken.scopes).join(" ");
|
|
696
|
+
return [...currentTokens.filter((existingToken) => {
|
|
697
|
+
return normalizeScopes(existingToken.scopes).join(" ") !== newScopeKey;
|
|
698
|
+
}), {
|
|
699
|
+
expiresAt: newToken.expiresAt,
|
|
700
|
+
scopes: newToken.scopes,
|
|
701
|
+
singleUse: newToken.singleUse,
|
|
702
|
+
token: newToken.token
|
|
703
|
+
}];
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
//#endregion
|
|
707
|
+
//#region src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts
|
|
708
|
+
/** @instrumented */
|
|
709
|
+
const updateAuthFromVerifyResponse = ({ response }, client) => {
|
|
710
|
+
const core = getCore(client);
|
|
711
|
+
const previousState = { ...core.state.get() };
|
|
712
|
+
const { user, minifiedJwt, jwt, expiresAt, mfaToken, elevatedAccessToken } = response;
|
|
713
|
+
const sessionExpiresAt = /* @__PURE__ */ new Date(expiresAt * 1e3);
|
|
714
|
+
const newState = {
|
|
715
|
+
legacyToken: jwt ?? null,
|
|
716
|
+
sessionExpiresAt,
|
|
717
|
+
token: minifiedJwt ?? null,
|
|
718
|
+
user
|
|
719
|
+
};
|
|
720
|
+
if (mfaToken) newState.mfaToken = mfaToken;
|
|
721
|
+
const currentTokens = core.state.get().elevatedAccessTokens || [];
|
|
722
|
+
newState.elevatedAccessTokens = currentTokens;
|
|
723
|
+
if (elevatedAccessToken) {
|
|
724
|
+
const parsedToken = parseElevatedAccessToken(elevatedAccessToken);
|
|
725
|
+
if (parsedToken) newState.elevatedAccessTokens = upsertElevatedAccessToken({
|
|
726
|
+
currentTokens,
|
|
727
|
+
newToken: parsedToken
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
core.state.set(newState);
|
|
731
|
+
/**
|
|
732
|
+
* For customers using a sandbox environment with cookies enabled, we need to set the cookie
|
|
733
|
+
* programmatically because Redcoast won't set the cookie via headers. We set the cookie programmatically
|
|
734
|
+
* so customers can access the cookie from document.cookie consistently between sandbox and live environments.
|
|
735
|
+
*/
|
|
736
|
+
if (minifiedJwt && isCookieEnabled(client)) setCookie(`${DYNAMIC_AUTH_COOKIE_NAME}=${minifiedJwt}; expires=${sessionExpiresAt.toUTCString()}; path=/; SameSite=Lax`);
|
|
737
|
+
checkAndRaiseWalletAccountsChangedEvent({ previousState }, client);
|
|
738
|
+
if (!previousState.user && Boolean(newState.user)) restoreUserSharesForAllWalletAccounts(client);
|
|
739
|
+
};
|
|
740
|
+
const __updateAuthFromVerifyResponse_impl = updateAuthFromVerifyResponse;
|
|
741
|
+
const __updateAuthFromVerifyResponse_wrapped = instrumentFunction({
|
|
742
|
+
fn: __updateAuthFromVerifyResponse_impl,
|
|
743
|
+
functionName: "updateAuthFromVerifyResponse",
|
|
744
|
+
getCore: () => {
|
|
745
|
+
try {
|
|
746
|
+
return getCore(getDefaultClient());
|
|
747
|
+
} catch {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
//#endregion
|
|
754
|
+
//#region src/modules/wallets/getWalletProviderByKey/getWalletProviderByKey.ts
|
|
755
|
+
/** @not-instrumented */
|
|
756
|
+
const getWalletProviderByKey = ({ walletProviderKey }, client) => {
|
|
757
|
+
const walletProvider = __getWalletProviders_wrapped(client).find((walletProvider$1) => walletProvider$1.key === walletProviderKey);
|
|
758
|
+
if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey });
|
|
759
|
+
return walletProvider;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
//#endregion
|
|
763
|
+
//#region src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.ts
|
|
764
|
+
/** @instrumented */
|
|
765
|
+
const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client) => {
|
|
766
|
+
return client.user?.verifiedCredentials.find((vc) => vc.id === walletAccount.verifiedCredentialId);
|
|
767
|
+
};
|
|
768
|
+
const __getVerifiedCredentialForWalletAccount_impl = getVerifiedCredentialForWalletAccount;
|
|
769
|
+
const __getVerifiedCredentialForWalletAccount_wrapped = instrumentFunction({
|
|
770
|
+
fn: __getVerifiedCredentialForWalletAccount_impl,
|
|
771
|
+
functionName: "getVerifiedCredentialForWalletAccount",
|
|
772
|
+
getCore: () => {
|
|
773
|
+
try {
|
|
774
|
+
return getCore(getDefaultClient());
|
|
775
|
+
} catch {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
//#endregion
|
|
782
|
+
export { setCookie as A, normalizeAddress as C, __onEvent_wrapped as D, __offEvent_wrapped as E, __onceEvent_wrapped as O, formatWalletAccountId as S, InvalidWalletProviderKeyError as T, __createRuntimeServiceAccessKey_wrapped as _, parseElevatedAccessToken as a, formatWalletProviderKey as b, findWaasWalletProviderByChain as c, checkAndRaiseWalletAccountsChangedEvent as d, emitWalletAccountsChangedEvent as f, getWalletProviderRegistry as g, WalletProviderPriority as h, upsertElevatedAccessToken as i, emitEvent as k, isWaasWalletProvider as l, __getWalletProviderFromWalletAccount_wrapped as m, getWalletProviderByKey as n, restoreUserSharesForAllWalletAccounts as o, DYNAMIC_AUTH_COOKIE_NAME as p, __updateAuthFromVerifyResponse_wrapped as r, isWaasWalletAccount as s, __getVerifiedCredentialForWalletAccount_wrapped as t, __getWalletProviders_wrapped as u, NoWalletProviderFoundError as v, splitWalletProviderKey as w, normalizeWalletNameWithChain as x, __getWalletAccounts_wrapped as y };
|
|
783
|
+
//# sourceMappingURL=getVerifiedCredentialForWalletAccount-Dhqf6Tdl.native.esm.js.map
|