@dynamic-labs-sdk/client 0.1.0-alpha.12 → 0.1.0-alpha.13
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/CHANGELOG.md +14 -0
- package/core.cjs.js +4 -3
- package/core.esm.js +5 -5
- package/getChainFromVerifiedCredentialChain.cjs.js +1 -1
- package/getChainFromVerifiedCredentialChain.esm.js +1 -1
- package/getNetworkProviderFromNetworkId.cjs.js +6 -0
- package/getNetworkProviderFromNetworkId.esm.js +6 -1
- package/getWalletProviderByKey.cjs.js +11 -3
- package/getWalletProviderByKey.esm.js +11 -3
- package/index.cjs.js +134 -13
- package/index.esm.js +135 -17
- package/package.json +2 -2
- package/src/client/core/createCore/createCore.d.ts.map +1 -1
- package/src/client/core/types/DynamicCore.d.ts +8 -0
- package/src/client/core/types/DynamicCore.d.ts.map +1 -1
- package/src/errors/NoSmartWalletAccountSignerFoundError.d.ts +5 -0
- package/src/errors/NoSmartWalletAccountSignerFoundError.d.ts.map +1 -0
- package/src/exports/core.d.ts +1 -0
- package/src/exports/core.d.ts.map +1 -1
- package/src/exports/index.d.ts +4 -1
- package/src/exports/index.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/index.d.ts +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/index.d.ts.map +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/redirectStateStorageSchema.d.ts +1 -1
- package/src/modules/auth/social/oauth/redirectStateStorageSchema/redirectStateStorageSchema.d.ts.map +1 -1
- package/src/modules/balances/getMultichainBalances/getMultichainBalances.d.ts +1 -2
- package/src/modules/balances/getMultichainBalances/getMultichainBalances.d.ts.map +1 -1
- package/src/modules/balances/getMultichainBalances/index.d.ts +1 -1
- package/src/modules/balances/getMultichainBalances/index.d.ts.map +1 -1
- package/src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.d.ts +1 -1
- package/src/modules/projectSettings/fetchProjectSettings/projectSettingsExpirationScheme.d.ts.map +1 -1
- package/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.d.ts.map +1 -1
- package/src/modules/storageSync/schema.d.ts +8 -1
- package/src/modules/storageSync/schema.d.ts.map +1 -1
- package/src/modules/storageSync/syncStateWithStorage/syncStateWithStorage.d.ts.map +1 -1
- package/src/modules/waas/createWaasWalletAccounts/createWaasWalletAccounts.d.ts.map +1 -1
- package/src/modules/wallets/connectWithWalletProvider/connectWithWalletProvider.d.ts.map +1 -1
- package/src/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.d.ts +2 -6
- package/src/modules/wallets/getAvailableWalletProvidersData/getAvailableWalletProvidersData.d.ts.map +1 -1
- package/src/modules/wallets/getSignerWalletAccountForSmartWalletAccount/getSignerWalletAccountForSmartWalletAccount.d.ts +7 -0
- package/src/modules/wallets/getSignerWalletAccountForSmartWalletAccount/getSignerWalletAccountForSmartWalletAccount.d.ts.map +1 -0
- package/src/modules/wallets/getSignerWalletAccountForSmartWalletAccount/index.d.ts +2 -0
- package/src/modules/wallets/getSignerWalletAccountForSmartWalletAccount/index.d.ts.map +1 -0
- package/src/modules/wallets/getWalletProviderDataByKey/getWalletProviderDataByKey.d.ts +14 -0
- package/src/modules/wallets/getWalletProviderDataByKey/getWalletProviderDataByKey.d.ts.map +1 -0
- package/src/modules/wallets/getWalletProviderDataByKey/index.d.ts +2 -0
- package/src/modules/wallets/getWalletProviderDataByKey/index.d.ts.map +1 -0
- package/src/modules/wallets/networks/lastKnownNetworkRegistry/createLastKnownNetworkRegistry/createLastKnownNetworkRegistry.d.ts.map +1 -1
- package/src/modules/wallets/networks/lastKnownNetworkRegistry/createLastKnownNetworkRegistry/schema.d.ts +1 -1
- package/src/modules/wallets/networks/lastKnownNetworkRegistry/createLastKnownNetworkRegistry/schema.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/removeUnverifiedWalletAccount/removeUnverifiedWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/unverifiedWalletAccounts/setUnverifiedWalletAccounts/setUnverifiedWalletAccounts.d.ts +2 -0
- package/src/modules/wallets/unverifiedWalletAccounts/setUnverifiedWalletAccounts/setUnverifiedWalletAccounts.d.ts.map +1 -1
- package/src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.d.ts.map +1 -1
- package/src/modules/wallets/utils/createWalletAccountId/createWalletAccountId.d.ts +7 -1
- package/src/modules/wallets/utils/createWalletAccountId/createWalletAccountId.d.ts.map +1 -1
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.d.ts +8 -0
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/getVerifiedCredentialForWalletAccount.d.ts.map +1 -0
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/index.d.ts +2 -0
- package/src/modules/wallets/utils/getVerifiedCredentialForWalletAccount/index.d.ts.map +1 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/createDebouncedMutex.d.ts +3 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/createDebouncedMutex.d.ts.map +1 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/index.d.ts +2 -0
- package/src/utils/debouncedMutex/createDebouncedMutex/index.d.ts.map +1 -0
- package/src/utils/debouncedMutex/debouncedMutex.types.d.ts +39 -0
- package/src/utils/debouncedMutex/debouncedMutex.types.d.ts.map +1 -0
- package/src/utils/debouncedMutex/index.d.ts +2 -0
- package/src/utils/debouncedMutex/index.d.ts.map +1 -0
- package/waas.cjs.js +5 -2
- package/waas.esm.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 0.1.0-alpha.13 (2025-09-30)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- persist unverified wallets in local storage ([#448](https://github.com/dynamic-labs/dynamic-sdk/pull/448))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- update how wallet account id is computed to support multiple wallet accounts with the same address ([#481](https://github.com/dynamic-labs/dynamic-sdk/pull/481))
|
|
10
|
+
|
|
11
|
+
### 🔧 Refactors
|
|
12
|
+
|
|
13
|
+
- rename schemas ([#471](https://github.com/dynamic-labs/dynamic-sdk/pull/471))
|
|
14
|
+
|
|
1
15
|
## 0.1.0-alpha.12 (2025-09-23)
|
|
2
16
|
|
|
3
17
|
This was a version bump only, there were no code changes.
|
package/core.cjs.js
CHANGED
|
@@ -92,7 +92,7 @@ const createBaseNetworkProvider = (chain, networkData)=>({
|
|
|
92
92
|
testnet: networkData.testnet
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
const
|
|
95
|
+
const networkRegistryStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
96
96
|
key: 'lastKnownNetworkRegistry',
|
|
97
97
|
schema: z__namespace.record(z__namespace.string(), z__namespace.string())
|
|
98
98
|
});
|
|
@@ -116,7 +116,7 @@ const networkRegistrySchema = getNetworkProviderFromNetworkId.createStorageKeySc
|
|
|
116
116
|
networkId: walletProviderKeyToNetworkId.get(walletProviderKey)
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
const storageRecords = await core.storage.getItem(
|
|
119
|
+
const storageRecords = await core.storage.getItem(networkRegistryStorageKeySchema);
|
|
120
120
|
if (storageRecords && storageRecords[walletProviderKey]) {
|
|
121
121
|
const networkId = storageRecords[walletProviderKey];
|
|
122
122
|
walletProviderKeyToNetworkId.set(walletProviderKey, networkId);
|
|
@@ -141,7 +141,7 @@ const networkRegistrySchema = getNetworkProviderFromNetworkId.createStorageKeySc
|
|
|
141
141
|
};
|
|
142
142
|
const setNetworkId = async ({ networkId, walletProviderKey })=>{
|
|
143
143
|
walletProviderKeyToNetworkId.set(walletProviderKey, networkId);
|
|
144
|
-
await core.storage.setItem(
|
|
144
|
+
await core.storage.setItem(networkRegistryStorageKeySchema, Object.fromEntries(walletProviderKeyToNetworkId.entries()));
|
|
145
145
|
};
|
|
146
146
|
return {
|
|
147
147
|
getNetworkId,
|
|
@@ -250,6 +250,7 @@ exports.formatSignInMessage = getNetworkProviderFromNetworkId.formatSignInMessag
|
|
|
250
250
|
exports.getNetworkProviderBuilderRegistry = getNetworkProviderFromNetworkId.getNetworkProviderBuilderRegistry;
|
|
251
251
|
exports.getNetworkProviderFromNetworkId = getNetworkProviderFromNetworkId.getNetworkProviderFromNetworkId;
|
|
252
252
|
exports.getNetworkProviders = getNetworkProviderFromNetworkId.getNetworkProviders;
|
|
253
|
+
exports.getVerifiedCredentialForWalletAccount = getNetworkProviderFromNetworkId.getVerifiedCredentialForWalletAccount;
|
|
253
254
|
exports.hasExtension = getNetworkProviderFromNetworkId.hasExtension;
|
|
254
255
|
exports.setCaptchaToken = getNetworkProviderFromNetworkId.setCaptchaToken;
|
|
255
256
|
exports.subscribeWithSelector = getNetworkProviderFromNetworkId.subscribeWithSelector;
|
package/core.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';
|
|
2
2
|
import { B as BaseError, a as getCore, e as assertDefined, b as getBuffer, n as name, v as version } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
3
3
|
export { A as APIError, j as ClientNotFoundError, D as DYNAMIC_SDK_API_VERSION, V as ValueMustBeDefinedError, c as createApiClient, k as getChainFromVerifiedCredentialChain, g as getDefaultClient, i as isCookieEnabled } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
4
|
-
import { c as createStorageKeySchema,
|
|
5
|
-
export { C as CannotTrackError, I as InvalidStorageSet, e as consumeCaptchaToken, d as createLocalStorageAdapter, a as createLogger, b as createStorage, f as formatSignInMessage,
|
|
4
|
+
import { c as createStorageKeySchema, n as getNetworkProviders, N as NoNetworkProvidersError } from './getNetworkProviderFromNetworkId.esm.js';
|
|
5
|
+
export { C as CannotTrackError, I as InvalidStorageSet, e as consumeCaptchaToken, d as createLocalStorageAdapter, a as createLogger, b as createStorage, f as formatSignInMessage, o as getNetworkProviderBuilderRegistry, j as getNetworkProviderFromNetworkId, g as getVerifiedCredentialForWalletAccount, m as hasExtension, l as setCaptchaToken, s as subscribeWithSelector } from './getNetworkProviderFromNetworkId.esm.js';
|
|
6
6
|
import { b as getWalletProviderByKey, j as createRuntimeServiceAccessKey } from './getWalletProviderByKey.esm.js';
|
|
7
7
|
export { N as NoWalletProviderFoundError, W as WalletProviderPriority, e as emitEvent, k as formatWalletProviderKey, a as getWalletProviderFromWalletAccount, l as getWalletProviderRegistry, f as getWalletProviders, u as updateAuthFromVerifyResponse } from './getWalletProviderByKey.esm.js';
|
|
8
8
|
export { c as consumeMfaTokenIfRequiredForAction, g as getSignedSessionId } from './getSignedSessionId.esm.js';
|
|
@@ -74,7 +74,7 @@ const createBaseNetworkProvider = (chain, networkData)=>({
|
|
|
74
74
|
testnet: networkData.testnet
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
const
|
|
77
|
+
const networkRegistryStorageKeySchema = createStorageKeySchema({
|
|
78
78
|
key: 'lastKnownNetworkRegistry',
|
|
79
79
|
schema: z.record(z.string(), z.string())
|
|
80
80
|
});
|
|
@@ -98,7 +98,7 @@ const networkRegistrySchema = createStorageKeySchema({
|
|
|
98
98
|
networkId: walletProviderKeyToNetworkId.get(walletProviderKey)
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
const storageRecords = await core.storage.getItem(
|
|
101
|
+
const storageRecords = await core.storage.getItem(networkRegistryStorageKeySchema);
|
|
102
102
|
if (storageRecords && storageRecords[walletProviderKey]) {
|
|
103
103
|
const networkId = storageRecords[walletProviderKey];
|
|
104
104
|
walletProviderKeyToNetworkId.set(walletProviderKey, networkId);
|
|
@@ -123,7 +123,7 @@ const networkRegistrySchema = createStorageKeySchema({
|
|
|
123
123
|
};
|
|
124
124
|
const setNetworkId = async ({ networkId, walletProviderKey })=>{
|
|
125
125
|
walletProviderKeyToNetworkId.set(walletProviderKey, networkId);
|
|
126
|
-
await core.storage.setItem(
|
|
126
|
+
await core.storage.setItem(networkRegistryStorageKeySchema, Object.fromEntries(walletProviderKeyToNetworkId.entries()));
|
|
127
127
|
};
|
|
128
128
|
return {
|
|
129
129
|
getNetworkId,
|
|
@@ -4,7 +4,7 @@ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
|
4
4
|
var buffer = require('buffer');
|
|
5
5
|
|
|
6
6
|
var name = "@dynamic-labs-sdk/client";
|
|
7
|
-
var version = "0.1.0-alpha.
|
|
7
|
+
var version = "0.1.0-alpha.13";
|
|
8
8
|
var dependencies = {
|
|
9
9
|
"@dynamic-labs/sdk-api-core": "0.0.762"};
|
|
10
10
|
|
|
@@ -2,7 +2,7 @@ import { AuthStorageEnum, SDKApi, Configuration } from '@dynamic-labs/sdk-api-co
|
|
|
2
2
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
3
3
|
|
|
4
4
|
var name = "@dynamic-labs-sdk/client";
|
|
5
|
-
var version = "0.1.0-alpha.
|
|
5
|
+
var version = "0.1.0-alpha.13";
|
|
6
6
|
var dependencies = {
|
|
7
7
|
"@dynamic-labs/sdk-api-core": "0.0.762"};
|
|
8
8
|
|
|
@@ -317,6 +317,11 @@ const isCaptchaRequired = (client = getChainFromVerifiedCredentialChain.getDefau
|
|
|
317
317
|
].join('\n');
|
|
318
318
|
};
|
|
319
319
|
|
|
320
|
+
const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client)=>{
|
|
321
|
+
var _client_user;
|
|
322
|
+
return (_client_user = client.user) == null ? void 0 : _client_user.verifiedCredentials.find((vc)=>vc.id === walletAccount.verifiedCredentialId);
|
|
323
|
+
};
|
|
324
|
+
|
|
320
325
|
/**
|
|
321
326
|
* Maps the chain name from the API to the SDK chain name
|
|
322
327
|
*/ const getSdkChainFromApiChainName = (chainName)=>{
|
|
@@ -423,6 +428,7 @@ exports.getNetworkProviderBuilderRegistry = getNetworkProviderBuilderRegistry;
|
|
|
423
428
|
exports.getNetworkProviderFromNetworkId = getNetworkProviderFromNetworkId;
|
|
424
429
|
exports.getNetworkProviders = getNetworkProviders;
|
|
425
430
|
exports.getNetworksData = getNetworksData;
|
|
431
|
+
exports.getVerifiedCredentialForWalletAccount = getVerifiedCredentialForWalletAccount;
|
|
426
432
|
exports.hasExtension = hasExtension;
|
|
427
433
|
exports.isCaptchaRequired = isCaptchaRequired;
|
|
428
434
|
exports.isEqualShallow = isEqualShallow;
|
|
@@ -315,6 +315,11 @@ const isCaptchaRequired = (client = getDefaultClient())=>{
|
|
|
315
315
|
].join('\n');
|
|
316
316
|
};
|
|
317
317
|
|
|
318
|
+
const getVerifiedCredentialForWalletAccount = ({ walletAccount }, client)=>{
|
|
319
|
+
var _client_user;
|
|
320
|
+
return (_client_user = client.user) == null ? void 0 : _client_user.verifiedCredentials.find((vc)=>vc.id === walletAccount.verifiedCredentialId);
|
|
321
|
+
};
|
|
322
|
+
|
|
318
323
|
/**
|
|
319
324
|
* Maps the chain name from the API to the SDK chain name
|
|
320
325
|
*/ const getSdkChainFromApiChainName = (chainName)=>{
|
|
@@ -408,4 +413,4 @@ const getNetworkProviderFromNetworkId = ({ networkId, chain }, client)=>{
|
|
|
408
413
|
return networkProvider;
|
|
409
414
|
};
|
|
410
415
|
|
|
411
|
-
export { CannotTrackError as C, InvalidStorageSet as I, NoNetworkProvidersError as N, createLogger as a, createStorage as b, createStorageKeySchema as c, createLocalStorageAdapter as d, consumeCaptchaToken as e, formatSignInMessage as f,
|
|
416
|
+
export { CannotTrackError as C, InvalidStorageSet as I, NoNetworkProvidersError as N, createLogger as a, createStorage as b, createStorageKeySchema as c, createLocalStorageAdapter as d, consumeCaptchaToken as e, formatSignInMessage as f, getVerifiedCredentialForWalletAccount as g, getNetworksData as h, isEqualShallow as i, getNetworkProviderFromNetworkId as j, isCaptchaRequired as k, setCaptchaToken as l, hasExtension as m, getNetworkProviders as n, getNetworkProviderBuilderRegistry as o, subscribeWithSelector as s };
|
|
@@ -88,12 +88,16 @@ const normalizeAddress = (address, chain)=>{
|
|
|
88
88
|
return normalizedAddress;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const createWalletAccountId = (chain,
|
|
91
|
+
const createWalletAccountId = ({ address, chain, walletProviderKey })=>`${walletProviderKey}-${normalizeAddress(address, chain)}`;
|
|
92
92
|
|
|
93
93
|
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
94
94
|
address: unverifiedWalletAccount.address,
|
|
95
95
|
chain: unverifiedWalletAccount.chain,
|
|
96
|
-
id: createWalletAccountId(
|
|
96
|
+
id: createWalletAccountId({
|
|
97
|
+
address: unverifiedWalletAccount.address,
|
|
98
|
+
chain: unverifiedWalletAccount.chain,
|
|
99
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
100
|
+
}),
|
|
97
101
|
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
98
102
|
verifiedCredentialId: null,
|
|
99
103
|
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
@@ -120,7 +124,11 @@ const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
|
120
124
|
return {
|
|
121
125
|
address: verified.address,
|
|
122
126
|
chain,
|
|
123
|
-
id: createWalletAccountId(
|
|
127
|
+
id: createWalletAccountId({
|
|
128
|
+
address: verified.address,
|
|
129
|
+
chain,
|
|
130
|
+
walletProviderKey
|
|
131
|
+
}),
|
|
124
132
|
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
125
133
|
verifiedCredentialId: verified.id,
|
|
126
134
|
walletProviderKey
|
|
@@ -86,12 +86,16 @@ const normalizeAddress = (address, chain)=>{
|
|
|
86
86
|
return normalizedAddress;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
const createWalletAccountId = (chain,
|
|
89
|
+
const createWalletAccountId = ({ address, chain, walletProviderKey })=>`${walletProviderKey}-${normalizeAddress(address, chain)}`;
|
|
90
90
|
|
|
91
91
|
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
92
92
|
address: unverifiedWalletAccount.address,
|
|
93
93
|
chain: unverifiedWalletAccount.chain,
|
|
94
|
-
id: createWalletAccountId(
|
|
94
|
+
id: createWalletAccountId({
|
|
95
|
+
address: unverifiedWalletAccount.address,
|
|
96
|
+
chain: unverifiedWalletAccount.chain,
|
|
97
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
98
|
+
}),
|
|
95
99
|
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
96
100
|
verifiedCredentialId: null,
|
|
97
101
|
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
@@ -118,7 +122,11 @@ const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
|
118
122
|
return {
|
|
119
123
|
address: verified.address,
|
|
120
124
|
chain,
|
|
121
|
-
id: createWalletAccountId(
|
|
125
|
+
id: createWalletAccountId({
|
|
126
|
+
address: verified.address,
|
|
127
|
+
chain,
|
|
128
|
+
walletProviderKey
|
|
129
|
+
}),
|
|
122
130
|
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
123
131
|
verifiedCredentialId: verified.id,
|
|
124
132
|
walletProviderKey
|
package/index.cjs.js
CHANGED
|
@@ -92,7 +92,7 @@ const retryOnFail = async ({ delay = 0, fn, maxRetries })=>{
|
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* The schema to track the expiration time of the project settings.
|
|
95
|
-
*/ const
|
|
95
|
+
*/ const projectSettingsExpirationStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
96
96
|
key: 'projectSettingsExpiration',
|
|
97
97
|
schema: z__namespace.number()
|
|
98
98
|
});
|
|
@@ -111,7 +111,7 @@ const retryOnFail = async ({ delay = 0, fn, maxRetries })=>{
|
|
|
111
111
|
* @returns A promise that resolves to the updated project settings.
|
|
112
112
|
*/ const fetchProjectSettings = async (client = getChainFromVerifiedCredentialChain.getDefaultClient())=>{
|
|
113
113
|
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
114
|
-
const currentExpiration = await core.storage.getItem(
|
|
114
|
+
const currentExpiration = await core.storage.getItem(projectSettingsExpirationStorageKeySchema);
|
|
115
115
|
const hasProjectSettings = Boolean(client.projectSettings);
|
|
116
116
|
const isExpired = currentExpiration && currentExpiration < Date.now();
|
|
117
117
|
// We want to cache the project settings if its valid and user is connected.
|
|
@@ -133,7 +133,7 @@ const retryOnFail = async ({ delay = 0, fn, maxRetries })=>{
|
|
|
133
133
|
core.state.set({
|
|
134
134
|
projectSettings: projectSettings != null ? projectSettings : null
|
|
135
135
|
});
|
|
136
|
-
await core.storage.setItem(
|
|
136
|
+
await core.storage.setItem(projectSettingsExpirationStorageKeySchema, Date.now() + PROJECT_SETTINGS_EXPIRATION_TIME);
|
|
137
137
|
return projectSettings;
|
|
138
138
|
};
|
|
139
139
|
|
|
@@ -369,15 +369,24 @@ const raiseStateEvents = (client)=>{
|
|
|
369
369
|
|
|
370
370
|
const SDK_API_CORE_VERSION = getChainFromVerifiedCredentialChain.dependencies['@dynamic-labs/sdk-api-core'];
|
|
371
371
|
|
|
372
|
+
const unverifiedWalletAccountSchema = z__namespace.object({
|
|
373
|
+
address: z__namespace.string(),
|
|
374
|
+
chain: z__namespace.custom((val)=>typeof val === 'string'),
|
|
375
|
+
id: z__namespace.string(),
|
|
376
|
+
lastSelectedAt: z__namespace.nullable(z__namespace.date()),
|
|
377
|
+
walletProviderKey: z__namespace.string()
|
|
378
|
+
});
|
|
379
|
+
|
|
372
380
|
const stateStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
373
381
|
key: 'state',
|
|
374
382
|
schema: z__namespace.object({
|
|
375
383
|
apiVersion: z__namespace.string(),
|
|
376
384
|
projectSettings: z__namespace.custom(),
|
|
385
|
+
unverifiedWalletAccounts: z__namespace.array(unverifiedWalletAccountSchema),
|
|
377
386
|
user: z__namespace.custom()
|
|
378
387
|
})
|
|
379
388
|
});
|
|
380
|
-
const
|
|
389
|
+
const sessionStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
381
390
|
key: 'session',
|
|
382
391
|
schema: z__namespace.object({
|
|
383
392
|
/**
|
|
@@ -407,7 +416,7 @@ const hydrateStateWithStorage = async (client)=>{
|
|
|
407
416
|
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
408
417
|
const stateChanges = {};
|
|
409
418
|
// ================ TOKEN =================
|
|
410
|
-
const session = await core.storage.getItem(
|
|
419
|
+
const session = await core.storage.getItem(sessionStorageKeySchema);
|
|
411
420
|
const isSessionValid = (session == null ? void 0 : session.sessionExpiration) && session.sessionExpiration > Date.now();
|
|
412
421
|
if (isSessionValid) {
|
|
413
422
|
stateChanges.token = session.token;
|
|
@@ -421,6 +430,7 @@ const hydrateStateWithStorage = async (client)=>{
|
|
|
421
430
|
const storedState = await core.storage.getItem(stateStorageKeySchema);
|
|
422
431
|
// Only hydrate state if it came from an API with the same version as the current SDK
|
|
423
432
|
if ((storedState == null ? void 0 : storedState.apiVersion) === SDK_API_CORE_VERSION) {
|
|
433
|
+
stateChanges.unverifiedWalletAccounts = storedState.unverifiedWalletAccounts;
|
|
424
434
|
// Variables that should only be hydrated if the session is valid
|
|
425
435
|
if (isSessionValid) {
|
|
426
436
|
stateChanges.user = storedState.user;
|
|
@@ -436,9 +446,9 @@ const syncStateWithStorage = (client)=>{
|
|
|
436
446
|
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
437
447
|
core.state.subscribe((state)=>{
|
|
438
448
|
if (state.sessionExpiresAt === null) {
|
|
439
|
-
void core.storage.removeItem(
|
|
449
|
+
void core.storage.removeItem(sessionStorageKeySchema);
|
|
440
450
|
} else {
|
|
441
|
-
void core.storage.setItem(
|
|
451
|
+
void core.storage.setItem(sessionStorageKeySchema, {
|
|
442
452
|
captchaToken: state.captchaToken,
|
|
443
453
|
legacyToken: state.legacyToken,
|
|
444
454
|
mfaToken: state.mfaToken,
|
|
@@ -450,6 +460,7 @@ const syncStateWithStorage = (client)=>{
|
|
|
450
460
|
void core.storage.setItem(stateStorageKeySchema, {
|
|
451
461
|
apiVersion: SDK_API_CORE_VERSION,
|
|
452
462
|
projectSettings: state.projectSettings,
|
|
463
|
+
unverifiedWalletAccounts: state.unverifiedWalletAccounts,
|
|
453
464
|
user: state.user
|
|
454
465
|
});
|
|
455
466
|
});
|
|
@@ -690,6 +701,63 @@ class UnavailableInServerSideError extends getChainFromVerifiedCredentialChain.B
|
|
|
690
701
|
register: (options)=>browser.startRegistration(options)
|
|
691
702
|
});
|
|
692
703
|
|
|
704
|
+
const createDebouncedMutex = ()=>{
|
|
705
|
+
const mutexState = new Map();
|
|
706
|
+
return async ({ lockKey, callback, debounceTime = 0 })=>{
|
|
707
|
+
const resolutionPromise = createDeferredPromise();
|
|
708
|
+
// Prefill the state for this key if it doesn't exist to avoid needing to check for existence later.
|
|
709
|
+
if (!mutexState.has(lockKey)) {
|
|
710
|
+
mutexState.set(lockKey, {
|
|
711
|
+
nextCallback: null,
|
|
712
|
+
queuePromise: Promise.resolve(),
|
|
713
|
+
resolutionPromises: [],
|
|
714
|
+
timer: null
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
const currentState = mutexState.get(lockKey);
|
|
718
|
+
// This should never happen, but we'll assert it for TS safety.
|
|
719
|
+
getChainFromVerifiedCredentialChain.assertDefined(currentState, `Mutex state for key ${lockKey} not found`);
|
|
720
|
+
currentState.resolutionPromises.push(resolutionPromise);
|
|
721
|
+
if (currentState.timer) {
|
|
722
|
+
clearTimeout(currentState.timer);
|
|
723
|
+
}
|
|
724
|
+
// The last invocation wins. Always.
|
|
725
|
+
currentState.nextCallback = callback;
|
|
726
|
+
const addCallbackToQueue = async ()=>{
|
|
727
|
+
currentState.queuePromise = currentState.queuePromise.then(async ()=>{
|
|
728
|
+
if (!currentState.nextCallback) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
// We can't just use the callback param directly because later invocations
|
|
732
|
+
// should override previous ones.
|
|
733
|
+
// Scenario to illustrate this (none of these will use the timer param for simplicity):
|
|
734
|
+
// 1. Very long running promise callback A runs
|
|
735
|
+
// 2. While it's running, we invoke callback B, which queues itself with "then" and overrides nextCallback with B.
|
|
736
|
+
// 3. While A is still running, we invoke callback C, same thing happens, now nextCallback is C.
|
|
737
|
+
// 4. A resolves, nextCallback is invoked with C.
|
|
738
|
+
// 5. After C resolves, nextCallback is invoked with null, so it doesn't run.
|
|
739
|
+
// Conclusion: B was never executed and only the last invocation runs.
|
|
740
|
+
const { nextCallback } = currentState;
|
|
741
|
+
currentState.nextCallback = null;
|
|
742
|
+
const promisesToResolve = currentState.resolutionPromises;
|
|
743
|
+
currentState.resolutionPromises = [];
|
|
744
|
+
try {
|
|
745
|
+
await nextCallback();
|
|
746
|
+
promisesToResolve.forEach((resolutionPromise)=>resolutionPromise.resolve());
|
|
747
|
+
} catch (error) {
|
|
748
|
+
promisesToResolve.forEach((resolutionPromise)=>resolutionPromise.reject(error));
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
};
|
|
752
|
+
if (debounceTime > 0) {
|
|
753
|
+
currentState.timer = setTimeout(addCallbackToQueue, debounceTime);
|
|
754
|
+
} else {
|
|
755
|
+
await addCallbackToQueue();
|
|
756
|
+
}
|
|
757
|
+
return resolutionPromise.promise;
|
|
758
|
+
};
|
|
759
|
+
};
|
|
760
|
+
|
|
693
761
|
class InvalidStorageValue extends getChainFromVerifiedCredentialChain.BaseError {
|
|
694
762
|
constructor(key, value){
|
|
695
763
|
super({
|
|
@@ -812,6 +880,7 @@ class InvalidStorageValue extends getChainFromVerifiedCredentialChain.BaseError
|
|
|
812
880
|
var _config_coreConfig_navigate;
|
|
813
881
|
const navigate = (_config_coreConfig_navigate = (_config_coreConfig5 = config.coreConfig) == null ? void 0 : _config_coreConfig5.navigate) != null ? _config_coreConfig_navigate : createNavigationHandler();
|
|
814
882
|
const state = createObservableState(getInitialState);
|
|
883
|
+
const debouncedMutex = createDebouncedMutex();
|
|
815
884
|
const eventEmitter = createEventEmitter();
|
|
816
885
|
const initTrack = createAsyncTrack();
|
|
817
886
|
const runtimeServices = createRuntimeServices();
|
|
@@ -820,6 +889,7 @@ class InvalidStorageValue extends getChainFromVerifiedCredentialChain.BaseError
|
|
|
820
889
|
var _config_coreConfig_getApiHeaders;
|
|
821
890
|
return {
|
|
822
891
|
apiBaseUrl,
|
|
892
|
+
debouncedMutex,
|
|
823
893
|
environmentId: config.environmentId,
|
|
824
894
|
eventEmitter,
|
|
825
895
|
extensions: new Set(),
|
|
@@ -965,6 +1035,18 @@ class NoPasskeyCredentialsFoundError extends getChainFromVerifiedCredentialChain
|
|
|
965
1035
|
}
|
|
966
1036
|
}
|
|
967
1037
|
|
|
1038
|
+
class NoSmartWalletAccountSignerFoundError extends getChainFromVerifiedCredentialChain.BaseError {
|
|
1039
|
+
constructor(smartWalletAddress){
|
|
1040
|
+
super({
|
|
1041
|
+
cause: null,
|
|
1042
|
+
code: 'no_smart_wallet_account_signer_found_error',
|
|
1043
|
+
docsUrl: null,
|
|
1044
|
+
name: 'NoSmartWalletAccountSignerFoundError',
|
|
1045
|
+
shortMessage: `No signer wallet account found for smart wallet account ${smartWalletAddress}`
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
968
1050
|
class NoWebAuthNSupportError extends getChainFromVerifiedCredentialChain.BaseError {
|
|
969
1051
|
constructor(){
|
|
970
1052
|
super({
|
|
@@ -1232,7 +1314,7 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
1232
1314
|
return response;
|
|
1233
1315
|
};
|
|
1234
1316
|
|
|
1235
|
-
/** The schema to track the state of the OAuth flow. */ const
|
|
1317
|
+
/** The schema to track the state of the OAuth flow. */ const redirectStateStorageKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema({
|
|
1236
1318
|
key: 'redirectState',
|
|
1237
1319
|
schema: z__namespace.object({
|
|
1238
1320
|
codeVerifier: z__namespace.optional(z__namespace.string()),
|
|
@@ -1264,7 +1346,7 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
1264
1346
|
if (!dynamicOauthCode) {
|
|
1265
1347
|
throw new MissingSocialUrlParamError('dynamicOauthCode');
|
|
1266
1348
|
}
|
|
1267
|
-
const storedSocialRedirectState = await core.storage.getItem(
|
|
1349
|
+
const storedSocialRedirectState = await core.storage.getItem(redirectStateStorageKeySchema);
|
|
1268
1350
|
if (!storedSocialRedirectState) {
|
|
1269
1351
|
throw new MissingRedirectStorageStateError();
|
|
1270
1352
|
}
|
|
@@ -1272,7 +1354,7 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
1272
1354
|
throw new InvalidRedirectStorageStateError();
|
|
1273
1355
|
}
|
|
1274
1356
|
const { provider, codeVerifier } = storedSocialRedirectState;
|
|
1275
|
-
await core.storage.removeItem(
|
|
1357
|
+
await core.storage.removeItem(redirectStateStorageKeySchema);
|
|
1276
1358
|
const response = await apiClient.oauthSignIn({
|
|
1277
1359
|
environmentId: core.environmentId,
|
|
1278
1360
|
oauthRequest: {
|
|
@@ -1307,7 +1389,7 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
1307
1389
|
}
|
|
1308
1390
|
// Wait for SDK to load
|
|
1309
1391
|
await core.initTrack.waitForAll();
|
|
1310
|
-
const storedSocialRedirectState = await core.storage.getItem(
|
|
1392
|
+
const storedSocialRedirectState = await core.storage.getItem(redirectStateStorageKeySchema);
|
|
1311
1393
|
if (!storedSocialRedirectState || storedSocialRedirectState.state !== dynamicOauthState) {
|
|
1312
1394
|
return false;
|
|
1313
1395
|
}
|
|
@@ -1432,7 +1514,7 @@ const providersRequiringPkce = [
|
|
|
1432
1514
|
},
|
|
1433
1515
|
providerType
|
|
1434
1516
|
});
|
|
1435
|
-
await core.storage.setItem(
|
|
1517
|
+
await core.storage.setItem(redirectStateStorageKeySchema, {
|
|
1436
1518
|
codeVerifier,
|
|
1437
1519
|
provider: providerType,
|
|
1438
1520
|
state
|
|
@@ -2925,7 +3007,12 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2925
3007
|
|
|
2926
3008
|
/**
|
|
2927
3009
|
* Updates the unverified wallet account in the client state.
|
|
3010
|
+
* This will add new wallet accounts and override those with matching ids,
|
|
3011
|
+
* but will leave other preexisting wallet accounts unchanged.
|
|
2928
3012
|
*/ const setUnverifiedWalletAccounts = ({ unverifiedWalletAccountsToUpdate }, client)=>{
|
|
3013
|
+
if (unverifiedWalletAccountsToUpdate.length === 0) {
|
|
3014
|
+
return;
|
|
3015
|
+
}
|
|
2929
3016
|
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
2930
3017
|
const unverifiedWalletAccountsToUpdateIds = unverifiedWalletAccountsToUpdate.map(({ id })=>id);
|
|
2931
3018
|
const filteredUnverifiedWalletAccounts = core.state.get().unverifiedWalletAccounts.filter((unverifiedWalletAccount)=>!unverifiedWalletAccountsToUpdateIds.includes(unverifiedWalletAccount.id));
|
|
@@ -2991,7 +3078,11 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2991
3078
|
const walletAccount = {
|
|
2992
3079
|
address: selectedAddress,
|
|
2993
3080
|
chain: walletProvider.chain,
|
|
2994
|
-
id: getWalletProviderByKey.createWalletAccountId(
|
|
3081
|
+
id: getWalletProviderByKey.createWalletAccountId({
|
|
3082
|
+
address: selectedAddress,
|
|
3083
|
+
chain: walletProvider.chain,
|
|
3084
|
+
walletProviderKey: walletProvider.key
|
|
3085
|
+
}),
|
|
2995
3086
|
lastSelectedAt: null,
|
|
2996
3087
|
verifiedCredentialId: null,
|
|
2997
3088
|
walletProviderKey: walletProvider.key
|
|
@@ -3112,6 +3203,7 @@ const getSignInMessage = async ({ walletAccount }, client)=>{
|
|
|
3112
3203
|
core.state.set({
|
|
3113
3204
|
unverifiedWalletAccounts: filteredUnverifiedWalletAccounts
|
|
3114
3205
|
});
|
|
3206
|
+
getWalletProviderByKey.emitWalletAccountsChangedEvent(client);
|
|
3115
3207
|
};
|
|
3116
3208
|
|
|
3117
3209
|
const isSameAddress = (left, right, chain)=>getWalletProviderByKey.normalizeAddress(left, chain) === getWalletProviderByKey.normalizeAddress(right, chain);
|
|
@@ -3243,6 +3335,32 @@ const isSameAddress = (left, right, chain)=>getWalletProviderByKey.normalizeAddr
|
|
|
3243
3335
|
return walletProvider.getConnectedAddresses();
|
|
3244
3336
|
};
|
|
3245
3337
|
|
|
3338
|
+
const getSignerWalletAccountForSmartWalletAccount = ({ smartWalletAccount }, client = getChainFromVerifiedCredentialChain.getDefaultClient())=>{
|
|
3339
|
+
const smartWalletVerifiedCredential = getNetworkProviderFromNetworkId.getVerifiedCredentialForWalletAccount({
|
|
3340
|
+
walletAccount: smartWalletAccount
|
|
3341
|
+
}, client);
|
|
3342
|
+
getChainFromVerifiedCredentialChain.assertDefined(smartWalletVerifiedCredential == null ? void 0 : smartWalletVerifiedCredential.signerRefId, 'Invalid smart wallet account');
|
|
3343
|
+
return getWalletProviderByKey.getWalletAccounts(client).find((walletAccount)=>walletAccount.verifiedCredentialId === smartWalletVerifiedCredential.signerRefId);
|
|
3344
|
+
};
|
|
3345
|
+
|
|
3346
|
+
/**
|
|
3347
|
+
* Retrieves data for a specific wallet provider that can be used for display or connection.
|
|
3348
|
+
*
|
|
3349
|
+
* @param params.walletProviderKey - The key of the wallet provider to retrieve data for.
|
|
3350
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3351
|
+
* @returns The data for the wallet provider.
|
|
3352
|
+
*/ const getWalletProviderDataByKey = ({ walletProviderKey }, client = getChainFromVerifiedCredentialChain.getDefaultClient())=>{
|
|
3353
|
+
const { chain, groupKey, key, metadata } = getWalletProviderByKey.getWalletProviderByKey({
|
|
3354
|
+
walletProviderKey
|
|
3355
|
+
}, client);
|
|
3356
|
+
return {
|
|
3357
|
+
chain,
|
|
3358
|
+
groupKey,
|
|
3359
|
+
key,
|
|
3360
|
+
metadata
|
|
3361
|
+
};
|
|
3362
|
+
};
|
|
3363
|
+
|
|
3246
3364
|
/**
|
|
3247
3365
|
* Retrieves the network configuration data for the currently active network.
|
|
3248
3366
|
*
|
|
@@ -3582,6 +3700,7 @@ exports.MissingSocialUrlParamError = MissingSocialUrlParamError;
|
|
|
3582
3700
|
exports.NetworkSwitchingUnavailableError = NetworkSwitchingUnavailableError;
|
|
3583
3701
|
exports.NoAddressFoundError = NoAddressFoundError;
|
|
3584
3702
|
exports.NoPasskeyCredentialsFoundError = NoPasskeyCredentialsFoundError;
|
|
3703
|
+
exports.NoSmartWalletAccountSignerFoundError = NoSmartWalletAccountSignerFoundError;
|
|
3585
3704
|
exports.NoWebAuthNSupportError = NoWebAuthNSupportError;
|
|
3586
3705
|
exports.UnavailableInServerSideError = UnavailableInServerSideError;
|
|
3587
3706
|
exports.UnrecognizedNetworkError = UnrecognizedNetworkError;
|
|
@@ -3617,7 +3736,9 @@ exports.getMfaRecoveryCodes = getMfaRecoveryCodes;
|
|
|
3617
3736
|
exports.getMultichainBalances = getMultichainBalances;
|
|
3618
3737
|
exports.getPasskeys = getPasskeys;
|
|
3619
3738
|
exports.getPrimaryWalletAccount = getPrimaryWalletAccount;
|
|
3739
|
+
exports.getSignerWalletAccountForSmartWalletAccount = getSignerWalletAccountForSmartWalletAccount;
|
|
3620
3740
|
exports.getWalletAccountFromAddress = getWalletAccountFromAddress;
|
|
3741
|
+
exports.getWalletProviderDataByKey = getWalletProviderDataByKey;
|
|
3621
3742
|
exports.initializeClient = initializeClient;
|
|
3622
3743
|
exports.isMobile = isMobile;
|
|
3623
3744
|
exports.isPendingRecoveryCodesAcknowledgment = isPendingRecoveryCodesAcknowledgment;
|