@dynamic-labs-sdk/client 0.1.0-alpha.2 → 0.1.0-alpha.4
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 +10 -0
- package/core.cjs.js +1 -0
- package/core.esm.js +3 -3
- package/getChainFromVerifiedCredentialChain.cjs.js +2 -1
- package/getChainFromVerifiedCredentialChain.esm.js +2 -2
- package/getNetworkProviderFromNetworkId.esm.js +2 -2
- package/getSignedSessionId.esm.js +1 -1
- package/getWalletProviderByKey.cjs.js +124 -0
- package/getWalletProviderByKey.esm.js +121 -2
- package/index.cjs.js +35 -26
- package/index.esm.js +15 -7
- package/package.json +3 -3
- package/refreshUser.cjs.js +1 -124
- package/refreshUser.esm.js +3 -121
- package/src/client/core/createCore/getInitialState.d.ts.map +1 -1
- package/src/exports/core.d.ts +1 -0
- package/src/exports/core.d.ts.map +1 -1
- package/src/modules/auth/logout/logout.d.ts.map +1 -1
- package/src/modules/auth/state.d.ts +11 -0
- package/src/modules/auth/state.d.ts.map +1 -1
- package/src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.d.ts.map +1 -1
- package/src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.d.ts.map +1 -1
- package/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.d.ts.map +1 -1
- package/src/modules/storageSync/schema.d.ts +1 -0
- 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/createWaasClient/createWaasClient.d.ts.map +1 -1
- package/waas.esm.js +2 -2
- package/waasCore.cjs.js +2 -1
- package/waasCore.esm.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 0.1.0-alpha.4 (2025-09-10)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- set client version to project settings api call ([#414](https://github.com/dynamic-labs/dynamic-sdk/pull/414))
|
|
6
|
+
|
|
7
|
+
## 0.1.0-alpha.3 (2025-09-09)
|
|
8
|
+
|
|
9
|
+
This was a version bump only, there were no code changes.
|
|
10
|
+
|
|
1
11
|
## 0.1.0-alpha.2 (2025-09-08)
|
|
2
12
|
|
|
3
13
|
This was a version bump only, there were no code changes.
|
package/core.cjs.js
CHANGED
|
@@ -258,6 +258,7 @@ exports.formatWalletProviderKey = getWalletProviderByKey.formatWalletProviderKey
|
|
|
258
258
|
exports.getWalletProviderFromWalletAccount = getWalletProviderByKey.getWalletProviderFromWalletAccount;
|
|
259
259
|
exports.getWalletProviderRegistry = getWalletProviderByKey.getWalletProviderRegistry;
|
|
260
260
|
exports.getWalletProviders = getWalletProviderByKey.getWalletProviders;
|
|
261
|
+
exports.updateAuthFromVerifyResponse = getWalletProviderByKey.updateAuthFromVerifyResponse;
|
|
261
262
|
exports.consumeMfaTokenIfRequiredForAction = getSignedSessionId.consumeMfaTokenIfRequiredForAction;
|
|
262
263
|
exports.getSignedSessionId = getSignedSessionId.getSignedSessionId;
|
|
263
264
|
exports.ClientsDoNotMatchError = ClientsDoNotMatchError;
|
package/core.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
export { A as APIError,
|
|
3
|
+
export { A as APIError, i as ClientNotFoundError, D as DYNAMIC_SDK_API_VERSION, V as ValueMustBeDefinedError, c as createApiClient, k as getChainFromVerifiedCredentialChain, g as getDefaultClient, j as isCookieEnabled } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
4
4
|
import { c as createStorageKeySchema, d as getNetworkProviders, N as NoNetworkProvidersError } from './getNetworkProviderFromNetworkId.esm.js';
|
|
5
5
|
export { C as CannotTrackError, I as InvalidStorageSet, a as createLogger, f as formatSignInMessage, e as getNetworkProviderBuilderRegistry, b as getNetworkProviderFromNetworkId, h as hasExtension, s as subscribeWithSelector } from './getNetworkProviderFromNetworkId.esm.js';
|
|
6
|
-
import {
|
|
7
|
-
export { N as NoWalletProviderFoundError, W as WalletProviderPriority, e as emitEvent,
|
|
6
|
+
import { b as getWalletProviderByKey, j as createRuntimeServiceAccessKey } from './getWalletProviderByKey.esm.js';
|
|
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';
|
|
9
9
|
import * as z from 'zod/mini';
|
|
10
10
|
import EventEmitter from 'eventemitter3';
|
|
@@ -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.4";
|
|
8
8
|
var dependencies = {
|
|
9
9
|
"@dynamic-labs/sdk-api-core": "0.0.762"};
|
|
10
10
|
|
|
@@ -449,6 +449,7 @@ const getChainFromVerifiedCredentialChain = (verifiedCredentialChain)=>{
|
|
|
449
449
|
exports.APIError = APIError;
|
|
450
450
|
exports.BaseError = BaseError;
|
|
451
451
|
exports.CHAINS_INFO_MAP = CHAINS_INFO_MAP;
|
|
452
|
+
exports.CLIENT_SDK_NAME = CLIENT_SDK_NAME;
|
|
452
453
|
exports.ClientNotFoundError = ClientNotFoundError;
|
|
453
454
|
exports.DYNAMIC_SDK_API_VERSION = DYNAMIC_SDK_API_VERSION;
|
|
454
455
|
exports.InvalidExternalAuthError = InvalidExternalAuthError;
|
|
@@ -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.4";
|
|
6
6
|
var dependencies = {
|
|
7
7
|
"@dynamic-labs/sdk-api-core": "0.0.762"};
|
|
8
8
|
|
|
@@ -444,4 +444,4 @@ const getChainFromVerifiedCredentialChain = (verifiedCredentialChain)=>{
|
|
|
444
444
|
return chain;
|
|
445
445
|
};
|
|
446
446
|
|
|
447
|
-
export { APIError as A, BaseError as B,
|
|
447
|
+
export { APIError as A, BaseError as B, CLIENT_SDK_NAME as C, DYNAMIC_SDK_API_VERSION as D, InvalidExternalAuthError as I, MfaInvalidOtpError as M, SandboxMaximumThresholdReachedError as S, ValueMustBeDefinedError as V, _extends as _, getCore as a, getBuffer as b, createApiClient as c, dependencies as d, assertDefined as e, CHAINS_INFO_MAP as f, getDefaultClient as g, MfaRateLimitedError as h, ClientNotFoundError as i, isCookieEnabled as j, getChainFromVerifiedCredentialChain as k, getSessionKeys as l, name as n, randomString as r, setDefaultClient as s, version as v };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { B as BaseError, g as getDefaultClient, a as getCore,
|
|
1
|
+
import { B as BaseError, g as getDefaultClient, a as getCore, f as CHAINS_INFO_MAP, e as assertDefined } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
2
2
|
import { EventEmitter } from 'eventemitter3';
|
|
3
|
-
import {
|
|
3
|
+
import { j as createRuntimeServiceAccessKey } from './getWalletProviderByKey.esm.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Shallow compare two objects.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as isMfaRequiredForAction, c as consumeMfaToken, b as bufferToHex } from './isMfaRequiredForAction.esm.js';
|
|
2
|
-
import {
|
|
2
|
+
import { l as getSessionKeys, e as assertDefined, a as getCore } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
3
3
|
|
|
4
4
|
const consumeMfaTokenIfRequiredForAction = async ({ mfaAction }, client)=>{
|
|
5
5
|
const isRequiredForAction = await isMfaRequiredForAction({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var getChainFromVerifiedCredentialChain = require('./getChainFromVerifiedCredentialChain.cjs.js');
|
|
4
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Adds an event listener for Dynamic client events.
|
|
@@ -63,6 +64,34 @@ var getChainFromVerifiedCredentialChain = require('./getChainFromVerifiedCredent
|
|
|
63
64
|
eventEmitter.emit(event, args);
|
|
64
65
|
};
|
|
65
66
|
|
|
67
|
+
const normalizeAddress = (address, chain)=>{
|
|
68
|
+
let normalizedAddress = address;
|
|
69
|
+
if (normalizedAddress == null ? void 0 : normalizedAddress.startsWith('0x')) {
|
|
70
|
+
normalizedAddress = normalizedAddress.slice(2);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
74
|
+
* see also: https://github.com/ChainAgnostic/namespaces
|
|
75
|
+
* note: no standard namespace currently exists for flow
|
|
76
|
+
*/ const chainsThatRequireLowercaseAddress = [
|
|
77
|
+
'EVM',
|
|
78
|
+
'FLOW'
|
|
79
|
+
];
|
|
80
|
+
normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain) ? normalizedAddress == null ? void 0 : normalizedAddress.toLowerCase() : normalizedAddress;
|
|
81
|
+
return normalizedAddress;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const createWalletAccountId = (chain, address)=>`${chain}-${normalizeAddress(address, chain)}`;
|
|
85
|
+
|
|
86
|
+
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
87
|
+
address: unverifiedWalletAccount.address,
|
|
88
|
+
chain: unverifiedWalletAccount.chain,
|
|
89
|
+
id: createWalletAccountId(unverifiedWalletAccount.chain, unverifiedWalletAccount.address),
|
|
90
|
+
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
91
|
+
verifiedCredentialId: null,
|
|
92
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
93
|
+
});
|
|
94
|
+
|
|
66
95
|
/**
|
|
67
96
|
* Format the wallet name and chain to get a wallet provider key.
|
|
68
97
|
*/ const formatWalletProviderKey = (walletName, chain)=>{
|
|
@@ -70,6 +99,57 @@ var getChainFromVerifiedCredentialChain = require('./getChainFromVerifiedCredent
|
|
|
70
99
|
return `${sanitizedWalletName}${chain.toLocaleLowerCase()}`;
|
|
71
100
|
};
|
|
72
101
|
|
|
102
|
+
const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
103
|
+
getChainFromVerifiedCredentialChain.assertDefined(verified.address, 'Missing address in verified credential');
|
|
104
|
+
getChainFromVerifiedCredentialChain.assertDefined(verified.chain, 'Missing chain in verified credential');
|
|
105
|
+
getChainFromVerifiedCredentialChain.assertDefined(verified.walletName, 'Missing wallet name in verified credential');
|
|
106
|
+
const chain = getChainFromVerifiedCredentialChain.getChainFromVerifiedCredentialChain(verified.chain);
|
|
107
|
+
const hasChainInWalletName = verified.walletName.endsWith(chain.toLowerCase());
|
|
108
|
+
// we need to make sure the walletProviderKey follows the correct format ([walletName][chain])
|
|
109
|
+
// some walletNames will follow the legacy format (e.g. "phantom" instead of "phantomsol", "metamask" instead of "metamaskevm")
|
|
110
|
+
// so we need to make sure we parse it correctly
|
|
111
|
+
const walletProviderKey = hasChainInWalletName ? verified.walletName : formatWalletProviderKey(verified.walletName, chain);
|
|
112
|
+
var _verified_lastSelectedAt;
|
|
113
|
+
return {
|
|
114
|
+
address: verified.address,
|
|
115
|
+
chain,
|
|
116
|
+
id: createWalletAccountId(chain, verified.address),
|
|
117
|
+
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
118
|
+
verifiedCredentialId: verified.id,
|
|
119
|
+
walletProviderKey
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const getWalletAccountsFromState = (state)=>{
|
|
124
|
+
const { unverifiedWalletAccounts, user } = state;
|
|
125
|
+
const walletAccountsMap = new Map();
|
|
126
|
+
/**
|
|
127
|
+
* Handle the unverified wallet accounts before the user verified credentials
|
|
128
|
+
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
129
|
+
*/ unverifiedWalletAccounts.forEach((unverifiedWalletAccount)=>{
|
|
130
|
+
const walletAccount = convertUnverifiedWalletAccountToWalletAccount(unverifiedWalletAccount);
|
|
131
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
132
|
+
});
|
|
133
|
+
var _user_verifiedCredentials;
|
|
134
|
+
/**
|
|
135
|
+
* Handle user verified credentials
|
|
136
|
+
*/ const verifiedCredentials = (_user_verifiedCredentials = user == null ? void 0 : user.verifiedCredentials) != null ? _user_verifiedCredentials : [];
|
|
137
|
+
verifiedCredentials.filter((verified)=>verified.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain).map((verifiedWalletAccount)=>convertVerifiedCredentialToWalletAccount(verifiedWalletAccount)).forEach((verifiedWalletAccount)=>walletAccountsMap.set(verifiedWalletAccount.id, verifiedWalletAccount));
|
|
138
|
+
return Array.from(walletAccountsMap.values());
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves all wallet accounts associated with the current session.
|
|
143
|
+
*
|
|
144
|
+
* This function returns both verified and unverified wallet accounts,
|
|
145
|
+
* combining data from user credentials and local unverified accounts.
|
|
146
|
+
* You can differentiate between verified and unverified wallet accounts by
|
|
147
|
+
* checking the `verifiedCredentialId` property.
|
|
148
|
+
*
|
|
149
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
150
|
+
* @returns An array of wallet accounts associated with the session.
|
|
151
|
+
*/ const getWalletAccounts = (client = getChainFromVerifiedCredentialChain.getDefaultClient())=>getWalletAccountsFromState(getChainFromVerifiedCredentialChain.getCore(client).state.get());
|
|
152
|
+
|
|
73
153
|
class NoWalletProviderFoundError extends getChainFromVerifiedCredentialChain.BaseError {
|
|
74
154
|
constructor({ walletProviderKey }){
|
|
75
155
|
super({
|
|
@@ -212,6 +292,45 @@ const getWalletProviderFromWalletAccount = ({ walletAccount }, client)=>{
|
|
|
212
292
|
return walletProvider;
|
|
213
293
|
};
|
|
214
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Emits the `walletAccountsChanged` event.
|
|
297
|
+
*/ const emitWalletAccountsChangedEvent = (client)=>{
|
|
298
|
+
const walletAccounts = getWalletAccounts(client);
|
|
299
|
+
emitEvent({
|
|
300
|
+
args: {
|
|
301
|
+
walletAccounts
|
|
302
|
+
},
|
|
303
|
+
event: 'walletAccountsChanged'
|
|
304
|
+
}, client);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client)=>{
|
|
308
|
+
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
309
|
+
const walletAccountsHashBefore = getWalletAccountsHash(previousState);
|
|
310
|
+
const walletAccountsHashAfter = getWalletAccountsHash(core.state.get());
|
|
311
|
+
if (walletAccountsHashBefore !== walletAccountsHashAfter) {
|
|
312
|
+
emitWalletAccountsChangedEvent(client);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const getWalletAccountsHash = (state)=>getWalletAccountsFromState(state).map(({ id })=>id).sort().join('-');
|
|
316
|
+
|
|
317
|
+
const updateAuthFromVerifyResponse = ({ response }, client)=>{
|
|
318
|
+
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
319
|
+
const previousState = getChainFromVerifiedCredentialChain._extends({}, core.state.get());
|
|
320
|
+
const { user, minifiedJwt, jwt, expiresAt, mfaToken } = response;
|
|
321
|
+
core.state.set({
|
|
322
|
+
legacyToken: jwt != null ? jwt : null,
|
|
323
|
+
mfaToken: mfaToken != null ? mfaToken : null,
|
|
324
|
+
// Expires at is in seconds, so we need to convert it to milliseconds
|
|
325
|
+
sessionExpiresAt: new Date(expiresAt * 1000),
|
|
326
|
+
token: minifiedJwt != null ? minifiedJwt : null,
|
|
327
|
+
user
|
|
328
|
+
});
|
|
329
|
+
checkAndRaiseWalletAccountsChangedEvent({
|
|
330
|
+
previousState
|
|
331
|
+
}, client);
|
|
332
|
+
};
|
|
333
|
+
|
|
215
334
|
/**
|
|
216
335
|
* Get all available wallet providers to interact with internally.
|
|
217
336
|
*/ const getWalletProviders = (client)=>{
|
|
@@ -232,12 +351,17 @@ const getWalletProviderByKey = ({ walletProviderKey }, client)=>{
|
|
|
232
351
|
|
|
233
352
|
exports.NoWalletProviderFoundError = NoWalletProviderFoundError;
|
|
234
353
|
exports.createRuntimeServiceAccessKey = createRuntimeServiceAccessKey;
|
|
354
|
+
exports.createWalletAccountId = createWalletAccountId;
|
|
235
355
|
exports.emitEvent = emitEvent;
|
|
356
|
+
exports.emitWalletAccountsChangedEvent = emitWalletAccountsChangedEvent;
|
|
236
357
|
exports.formatWalletProviderKey = formatWalletProviderKey;
|
|
358
|
+
exports.getWalletAccounts = getWalletAccounts;
|
|
237
359
|
exports.getWalletProviderByKey = getWalletProviderByKey;
|
|
238
360
|
exports.getWalletProviderFromWalletAccount = getWalletProviderFromWalletAccount;
|
|
239
361
|
exports.getWalletProviderRegistry = getWalletProviderRegistry;
|
|
240
362
|
exports.getWalletProviders = getWalletProviders;
|
|
363
|
+
exports.normalizeAddress = normalizeAddress;
|
|
241
364
|
exports.offEvent = offEvent;
|
|
242
365
|
exports.onEvent = onEvent;
|
|
243
366
|
exports.onceEvent = onceEvent;
|
|
367
|
+
exports.updateAuthFromVerifyResponse = updateAuthFromVerifyResponse;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { g as getDefaultClient, a as getCore, B as BaseError } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
1
|
+
import { g as getDefaultClient, a as getCore, e as assertDefined, k as getChainFromVerifiedCredentialChain, B as BaseError, _ as _extends } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
2
|
+
import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Adds an event listener for Dynamic client events.
|
|
@@ -61,6 +62,34 @@ import { g as getDefaultClient, a as getCore, B as BaseError } from './getChainF
|
|
|
61
62
|
eventEmitter.emit(event, args);
|
|
62
63
|
};
|
|
63
64
|
|
|
65
|
+
const normalizeAddress = (address, chain)=>{
|
|
66
|
+
let normalizedAddress = address;
|
|
67
|
+
if (normalizedAddress == null ? void 0 : normalizedAddress.startsWith('0x')) {
|
|
68
|
+
normalizedAddress = normalizedAddress.slice(2);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
72
|
+
* see also: https://github.com/ChainAgnostic/namespaces
|
|
73
|
+
* note: no standard namespace currently exists for flow
|
|
74
|
+
*/ const chainsThatRequireLowercaseAddress = [
|
|
75
|
+
'EVM',
|
|
76
|
+
'FLOW'
|
|
77
|
+
];
|
|
78
|
+
normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain) ? normalizedAddress == null ? void 0 : normalizedAddress.toLowerCase() : normalizedAddress;
|
|
79
|
+
return normalizedAddress;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const createWalletAccountId = (chain, address)=>`${chain}-${normalizeAddress(address, chain)}`;
|
|
83
|
+
|
|
84
|
+
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
85
|
+
address: unverifiedWalletAccount.address,
|
|
86
|
+
chain: unverifiedWalletAccount.chain,
|
|
87
|
+
id: createWalletAccountId(unverifiedWalletAccount.chain, unverifiedWalletAccount.address),
|
|
88
|
+
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
89
|
+
verifiedCredentialId: null,
|
|
90
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
91
|
+
});
|
|
92
|
+
|
|
64
93
|
/**
|
|
65
94
|
* Format the wallet name and chain to get a wallet provider key.
|
|
66
95
|
*/ const formatWalletProviderKey = (walletName, chain)=>{
|
|
@@ -68,6 +97,57 @@ import { g as getDefaultClient, a as getCore, B as BaseError } from './getChainF
|
|
|
68
97
|
return `${sanitizedWalletName}${chain.toLocaleLowerCase()}`;
|
|
69
98
|
};
|
|
70
99
|
|
|
100
|
+
const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
101
|
+
assertDefined(verified.address, 'Missing address in verified credential');
|
|
102
|
+
assertDefined(verified.chain, 'Missing chain in verified credential');
|
|
103
|
+
assertDefined(verified.walletName, 'Missing wallet name in verified credential');
|
|
104
|
+
const chain = getChainFromVerifiedCredentialChain(verified.chain);
|
|
105
|
+
const hasChainInWalletName = verified.walletName.endsWith(chain.toLowerCase());
|
|
106
|
+
// we need to make sure the walletProviderKey follows the correct format ([walletName][chain])
|
|
107
|
+
// some walletNames will follow the legacy format (e.g. "phantom" instead of "phantomsol", "metamask" instead of "metamaskevm")
|
|
108
|
+
// so we need to make sure we parse it correctly
|
|
109
|
+
const walletProviderKey = hasChainInWalletName ? verified.walletName : formatWalletProviderKey(verified.walletName, chain);
|
|
110
|
+
var _verified_lastSelectedAt;
|
|
111
|
+
return {
|
|
112
|
+
address: verified.address,
|
|
113
|
+
chain,
|
|
114
|
+
id: createWalletAccountId(chain, verified.address),
|
|
115
|
+
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
116
|
+
verifiedCredentialId: verified.id,
|
|
117
|
+
walletProviderKey
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const getWalletAccountsFromState = (state)=>{
|
|
122
|
+
const { unverifiedWalletAccounts, user } = state;
|
|
123
|
+
const walletAccountsMap = new Map();
|
|
124
|
+
/**
|
|
125
|
+
* Handle the unverified wallet accounts before the user verified credentials
|
|
126
|
+
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
127
|
+
*/ unverifiedWalletAccounts.forEach((unverifiedWalletAccount)=>{
|
|
128
|
+
const walletAccount = convertUnverifiedWalletAccountToWalletAccount(unverifiedWalletAccount);
|
|
129
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
130
|
+
});
|
|
131
|
+
var _user_verifiedCredentials;
|
|
132
|
+
/**
|
|
133
|
+
* Handle user verified credentials
|
|
134
|
+
*/ const verifiedCredentials = (_user_verifiedCredentials = user == null ? void 0 : user.verifiedCredentials) != null ? _user_verifiedCredentials : [];
|
|
135
|
+
verifiedCredentials.filter((verified)=>verified.format === JwtVerifiedCredentialFormatEnum.Blockchain).map((verifiedWalletAccount)=>convertVerifiedCredentialToWalletAccount(verifiedWalletAccount)).forEach((verifiedWalletAccount)=>walletAccountsMap.set(verifiedWalletAccount.id, verifiedWalletAccount));
|
|
136
|
+
return Array.from(walletAccountsMap.values());
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves all wallet accounts associated with the current session.
|
|
141
|
+
*
|
|
142
|
+
* This function returns both verified and unverified wallet accounts,
|
|
143
|
+
* combining data from user credentials and local unverified accounts.
|
|
144
|
+
* You can differentiate between verified and unverified wallet accounts by
|
|
145
|
+
* checking the `verifiedCredentialId` property.
|
|
146
|
+
*
|
|
147
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
148
|
+
* @returns An array of wallet accounts associated with the session.
|
|
149
|
+
*/ const getWalletAccounts = (client = getDefaultClient())=>getWalletAccountsFromState(getCore(client).state.get());
|
|
150
|
+
|
|
71
151
|
class NoWalletProviderFoundError extends BaseError {
|
|
72
152
|
constructor({ walletProviderKey }){
|
|
73
153
|
super({
|
|
@@ -210,6 +290,45 @@ const getWalletProviderFromWalletAccount = ({ walletAccount }, client)=>{
|
|
|
210
290
|
return walletProvider;
|
|
211
291
|
};
|
|
212
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Emits the `walletAccountsChanged` event.
|
|
295
|
+
*/ const emitWalletAccountsChangedEvent = (client)=>{
|
|
296
|
+
const walletAccounts = getWalletAccounts(client);
|
|
297
|
+
emitEvent({
|
|
298
|
+
args: {
|
|
299
|
+
walletAccounts
|
|
300
|
+
},
|
|
301
|
+
event: 'walletAccountsChanged'
|
|
302
|
+
}, client);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client)=>{
|
|
306
|
+
const core = getCore(client);
|
|
307
|
+
const walletAccountsHashBefore = getWalletAccountsHash(previousState);
|
|
308
|
+
const walletAccountsHashAfter = getWalletAccountsHash(core.state.get());
|
|
309
|
+
if (walletAccountsHashBefore !== walletAccountsHashAfter) {
|
|
310
|
+
emitWalletAccountsChangedEvent(client);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const getWalletAccountsHash = (state)=>getWalletAccountsFromState(state).map(({ id })=>id).sort().join('-');
|
|
314
|
+
|
|
315
|
+
const updateAuthFromVerifyResponse = ({ response }, client)=>{
|
|
316
|
+
const core = getCore(client);
|
|
317
|
+
const previousState = _extends({}, core.state.get());
|
|
318
|
+
const { user, minifiedJwt, jwt, expiresAt, mfaToken } = response;
|
|
319
|
+
core.state.set({
|
|
320
|
+
legacyToken: jwt != null ? jwt : null,
|
|
321
|
+
mfaToken: mfaToken != null ? mfaToken : null,
|
|
322
|
+
// Expires at is in seconds, so we need to convert it to milliseconds
|
|
323
|
+
sessionExpiresAt: new Date(expiresAt * 1000),
|
|
324
|
+
token: minifiedJwt != null ? minifiedJwt : null,
|
|
325
|
+
user
|
|
326
|
+
});
|
|
327
|
+
checkAndRaiseWalletAccountsChangedEvent({
|
|
328
|
+
previousState
|
|
329
|
+
}, client);
|
|
330
|
+
};
|
|
331
|
+
|
|
213
332
|
/**
|
|
214
333
|
* Get all available wallet providers to interact with internally.
|
|
215
334
|
*/ const getWalletProviders = (client)=>{
|
|
@@ -228,4 +347,4 @@ const getWalletProviderByKey = ({ walletProviderKey }, client)=>{
|
|
|
228
347
|
return walletProvider;
|
|
229
348
|
};
|
|
230
349
|
|
|
231
|
-
export { NoWalletProviderFoundError as N, WalletProviderPriority as W,
|
|
350
|
+
export { NoWalletProviderFoundError as N, WalletProviderPriority as W, getWalletProviderFromWalletAccount as a, getWalletProviderByKey as b, createWalletAccountId as c, emitWalletAccountsChangedEvent as d, emitEvent as e, getWalletProviders as f, getWalletAccounts as g, onceEvent as h, onEvent as i, createRuntimeServiceAccessKey as j, formatWalletProviderKey as k, getWalletProviderRegistry as l, normalizeAddress as n, offEvent as o, updateAuthFromVerifyResponse as u };
|
package/index.cjs.js
CHANGED
|
@@ -4,12 +4,12 @@ var assertPackageVersion = require('@dynamic-labs-sdk/assert-package-version');
|
|
|
4
4
|
var getChainFromVerifiedCredentialChain = require('./getChainFromVerifiedCredentialChain.cjs.js');
|
|
5
5
|
var getNetworkProviderFromNetworkId = require('./getNetworkProviderFromNetworkId.cjs.js');
|
|
6
6
|
var getWalletProviderByKey = require('./getWalletProviderByKey.cjs.js');
|
|
7
|
-
var refreshUser = require('./refreshUser.cjs.js');
|
|
8
7
|
var z = require('zod/mini');
|
|
9
8
|
var isMfaRequiredForAction = require('./isMfaRequiredForAction.cjs.js');
|
|
10
9
|
var EventEmitter = require('eventemitter3');
|
|
11
10
|
var browser = require('@simplewebauthn/browser');
|
|
12
11
|
var InvalidParamError = require('./InvalidParamError.cjs.js');
|
|
12
|
+
var refreshUser = require('./refreshUser.cjs.js');
|
|
13
13
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
14
14
|
require('buffer');
|
|
15
15
|
|
|
@@ -84,7 +84,7 @@ const retryOnFail = async ({ delay = 0, fn, maxRetries })=>{
|
|
|
84
84
|
*
|
|
85
85
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
86
86
|
* @returns True if the user is signed in, false otherwise.
|
|
87
|
-
*/ const isSignedIn = (client = getChainFromVerifiedCredentialChain.getDefaultClient())=>Boolean(client.user ||
|
|
87
|
+
*/ const isSignedIn = (client = getChainFromVerifiedCredentialChain.getDefaultClient())=>Boolean(client.user || getWalletProviderByKey.getWalletAccounts(client).length > 0);
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Returns whether the given string is a valid ISO date string.
|
|
@@ -196,7 +196,7 @@ const parseFromStorage = (value)=>{
|
|
|
196
196
|
const apiClient = getChainFromVerifiedCredentialChain.createApiClient({}, client);
|
|
197
197
|
const doFetch = async ()=>apiClient.getEnvironmentSettings({
|
|
198
198
|
environmentId: core.environmentId,
|
|
199
|
-
sdkVersion:
|
|
199
|
+
sdkVersion: `${getChainFromVerifiedCredentialChain.CLIENT_SDK_NAME}/${core.version}`
|
|
200
200
|
}, {
|
|
201
201
|
credentials: 'omit'
|
|
202
202
|
});
|
|
@@ -292,7 +292,7 @@ const generateSessionKeys = async (client)=>{
|
|
|
292
292
|
const getAvailableWalletProvidersFromWalletAccounts = (client)=>{
|
|
293
293
|
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
294
294
|
const walletProvidersMap = new Map();
|
|
295
|
-
const walletAccounts =
|
|
295
|
+
const walletAccounts = getWalletProviderByKey.getWalletAccounts(client);
|
|
296
296
|
walletAccounts.forEach((walletAccount)=>{
|
|
297
297
|
if (walletProvidersMap.has(walletAccount.walletProviderKey)) {
|
|
298
298
|
return;
|
|
@@ -348,6 +348,7 @@ const getAvailableWalletProvidersFromWalletAccounts = (client)=>{
|
|
|
348
348
|
core.logger.error('Failed to revoke session', error);
|
|
349
349
|
}
|
|
350
350
|
core.state.set({
|
|
351
|
+
legacyToken: null,
|
|
351
352
|
sessionExpiresAt: null,
|
|
352
353
|
token: null,
|
|
353
354
|
user: null
|
|
@@ -442,6 +443,11 @@ const sessionKeySchema = getNetworkProviderFromNetworkId.createStorageKeySchema(
|
|
|
442
443
|
key: 'session',
|
|
443
444
|
schema: z__namespace.object({
|
|
444
445
|
/**
|
|
446
|
+
* Legacy token will be undefined in environments with cookie based sessions.
|
|
447
|
+
*
|
|
448
|
+
* @deprecated Use `token` instead.
|
|
449
|
+
*/ legacyToken: z__namespace.nullable(z__namespace.string()),
|
|
450
|
+
/**
|
|
445
451
|
* The current available MFA token.
|
|
446
452
|
*/ mfaToken: z__namespace.nullable(z__namespace.string()),
|
|
447
453
|
/**
|
|
@@ -464,6 +470,7 @@ const hydrateStateWithStorage = async (client)=>{
|
|
|
464
470
|
const isSessionValid = (session == null ? void 0 : session.sessionExpiration) && session.sessionExpiration > Date.now();
|
|
465
471
|
if (isSessionValid) {
|
|
466
472
|
stateChanges.token = session.token;
|
|
473
|
+
stateChanges.legacyToken = session.legacyToken;
|
|
467
474
|
stateChanges.sessionExpiresAt = new Date(session.sessionExpiration);
|
|
468
475
|
stateChanges.mfaToken = session.mfaToken;
|
|
469
476
|
stateChanges.sessionKeys = session.sessionKeys;
|
|
@@ -490,6 +497,7 @@ const syncStateWithStorage = (client)=>{
|
|
|
490
497
|
void core.storage.removeItem(sessionKeySchema);
|
|
491
498
|
} else {
|
|
492
499
|
void core.storage.setItem(sessionKeySchema, {
|
|
500
|
+
legacyToken: state.legacyToken,
|
|
493
501
|
mfaToken: state.mfaToken,
|
|
494
502
|
sessionExpiration: state.sessionExpiresAt.getTime(),
|
|
495
503
|
sessionKeys: state.sessionKeys,
|
|
@@ -794,6 +802,7 @@ class InvalidStorageValue extends getChainFromVerifiedCredentialChain.BaseError
|
|
|
794
802
|
* The initial values for the state of the client.
|
|
795
803
|
*/ const getInitialState = ()=>({
|
|
796
804
|
initStatus: 'uninitialized',
|
|
805
|
+
legacyToken: null,
|
|
797
806
|
mfaToken: null,
|
|
798
807
|
projectSettings: null,
|
|
799
808
|
sessionExpiresAt: null,
|
|
@@ -1090,7 +1099,7 @@ class WalletProviderMethodUnavailableError extends getChainFromVerifiedCredentia
|
|
|
1090
1099
|
sessionPublicKey
|
|
1091
1100
|
}
|
|
1092
1101
|
});
|
|
1093
|
-
|
|
1102
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1094
1103
|
response
|
|
1095
1104
|
}, client);
|
|
1096
1105
|
return response;
|
|
@@ -1175,7 +1184,7 @@ const serverRegisterPasskey = async ({ registration }, client)=>{
|
|
|
1175
1184
|
const response = await serverRegisterPasskey({
|
|
1176
1185
|
registration
|
|
1177
1186
|
}, client);
|
|
1178
|
-
|
|
1187
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1179
1188
|
response
|
|
1180
1189
|
}, client);
|
|
1181
1190
|
return response;
|
|
@@ -1228,7 +1237,7 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
1228
1237
|
const response = await serverSigninPasskey({
|
|
1229
1238
|
authentication
|
|
1230
1239
|
}, client);
|
|
1231
|
-
|
|
1240
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1232
1241
|
response
|
|
1233
1242
|
}, client);
|
|
1234
1243
|
return response;
|
|
@@ -1284,7 +1293,7 @@ const serverSigninPasskey = async ({ authentication, createMfaToken }, client)=>
|
|
|
1284
1293
|
},
|
|
1285
1294
|
providerType: provider
|
|
1286
1295
|
});
|
|
1287
|
-
|
|
1296
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1288
1297
|
response
|
|
1289
1298
|
}, client);
|
|
1290
1299
|
return response.user;
|
|
@@ -1479,7 +1488,7 @@ const providersRequiringPkce = [
|
|
|
1479
1488
|
environmentId: core.environmentId,
|
|
1480
1489
|
userFields
|
|
1481
1490
|
});
|
|
1482
|
-
|
|
1491
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1483
1492
|
response
|
|
1484
1493
|
}, client);
|
|
1485
1494
|
if (response.emailVerification) {
|
|
@@ -1535,7 +1544,7 @@ const providersRequiringPkce = [
|
|
|
1535
1544
|
createMfaToken: createMfaTokenOptions
|
|
1536
1545
|
}
|
|
1537
1546
|
});
|
|
1538
|
-
|
|
1547
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1539
1548
|
response
|
|
1540
1549
|
}, client);
|
|
1541
1550
|
getWalletProviderByKey.emitEvent({
|
|
@@ -1616,7 +1625,7 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1616
1625
|
authentication,
|
|
1617
1626
|
createMfaToken
|
|
1618
1627
|
}, client);
|
|
1619
|
-
|
|
1628
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1620
1629
|
response
|
|
1621
1630
|
}, client);
|
|
1622
1631
|
getWalletProviderByKey.emitEvent({
|
|
@@ -1660,7 +1669,7 @@ const serverAuthenticatePasskey = async ({ authentication, createMfaToken }, cli
|
|
|
1660
1669
|
id: deviceId
|
|
1661
1670
|
}
|
|
1662
1671
|
});
|
|
1663
|
-
|
|
1672
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
1664
1673
|
response
|
|
1665
1674
|
}, client);
|
|
1666
1675
|
getWalletProviderByKey.emitEvent({
|
|
@@ -2850,7 +2859,7 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2850
2859
|
otpVerification,
|
|
2851
2860
|
verificationToken
|
|
2852
2861
|
}, client);
|
|
2853
|
-
|
|
2862
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
2854
2863
|
response
|
|
2855
2864
|
}, client);
|
|
2856
2865
|
return response.user;
|
|
@@ -2968,7 +2977,7 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2968
2977
|
}, client);
|
|
2969
2978
|
assertWalletProviderMethodDefined(walletProvider, 'connect');
|
|
2970
2979
|
const { addresses: [selectedAddress] } = await walletProvider.connect();
|
|
2971
|
-
const currentAddresses =
|
|
2980
|
+
const currentAddresses = getWalletProviderByKey.getWalletAccounts(client).map(({ address })=>address);
|
|
2972
2981
|
/**
|
|
2973
2982
|
* This error is thrown in case the wallet has no addresses connected
|
|
2974
2983
|
* to the dapp. Then the error is thrown so the consumer can instruct the
|
|
@@ -2979,7 +2988,7 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2979
2988
|
const walletAccount = {
|
|
2980
2989
|
address: selectedAddress,
|
|
2981
2990
|
chain: walletProvider.chain,
|
|
2982
|
-
id:
|
|
2991
|
+
id: getWalletProviderByKey.createWalletAccountId(walletProvider.chain, selectedAddress),
|
|
2983
2992
|
lastSelectedAt: null,
|
|
2984
2993
|
verifiedCredentialId: null,
|
|
2985
2994
|
walletProviderKey: walletProvider.key
|
|
@@ -2991,7 +3000,7 @@ const verifyOTPForUserUpdate = async ({ otpVerification, verificationToken }, cl
|
|
|
2991
3000
|
setUnverifiedWalletAccount({
|
|
2992
3001
|
unverifiedWalletAccountToUpdate: walletAccount
|
|
2993
3002
|
}, client);
|
|
2994
|
-
|
|
3003
|
+
getWalletProviderByKey.emitWalletAccountsChangedEvent(client);
|
|
2995
3004
|
/*
|
|
2996
3005
|
* send information to backend to kick off background jobs
|
|
2997
3006
|
* this is an async work, but does not need to be awaited
|
|
@@ -3100,7 +3109,7 @@ const getSignInMessage = async ({ walletAccount }, client)=>{
|
|
|
3100
3109
|
});
|
|
3101
3110
|
};
|
|
3102
3111
|
|
|
3103
|
-
const isSameAddress = (left, right, chain)=>
|
|
3112
|
+
const isSameAddress = (left, right, chain)=>getWalletProviderByKey.normalizeAddress(left, chain) === getWalletProviderByKey.normalizeAddress(right, chain);
|
|
3104
3113
|
|
|
3105
3114
|
/**
|
|
3106
3115
|
* Verifies ownership of a wallet account and adds it to the user's profile.
|
|
@@ -3147,7 +3156,7 @@ const isSameAddress = (left, right, chain)=>refreshUser.normalizeAddress(left, c
|
|
|
3147
3156
|
/**
|
|
3148
3157
|
* Adds the user with the new wallet verified credential
|
|
3149
3158
|
* This will add the new verified wallet account to the client`s state
|
|
3150
|
-
*/
|
|
3159
|
+
*/ getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
3151
3160
|
response
|
|
3152
3161
|
}, client);
|
|
3153
3162
|
} catch (error) {
|
|
@@ -3158,7 +3167,7 @@ const isSameAddress = (left, right, chain)=>refreshUser.normalizeAddress(left, c
|
|
|
3158
3167
|
}
|
|
3159
3168
|
throw error;
|
|
3160
3169
|
}
|
|
3161
|
-
const verifiedWalletAccount =
|
|
3170
|
+
const verifiedWalletAccount = getWalletProviderByKey.getWalletAccounts(client).find(({ address })=>isSameAddress(address, walletAccount.address, walletAccount.chain));
|
|
3162
3171
|
getChainFromVerifiedCredentialChain.assertDefined(verifiedWalletAccount, 'Verified wallet account not found');
|
|
3163
3172
|
return verifiedWalletAccount;
|
|
3164
3173
|
};
|
|
@@ -3359,7 +3368,7 @@ const isSameAddress = (left, right, chain)=>refreshUser.normalizeAddress(left, c
|
|
|
3359
3368
|
* This information is stored in both unverified and verified wallet accounts.
|
|
3360
3369
|
* This function consolidates this information to determine which wallet was most recently selected.
|
|
3361
3370
|
*/ const getPrimaryWalletAccount = (client = getChainFromVerifiedCredentialChain.getDefaultClient())=>{
|
|
3362
|
-
const walletAccounts =
|
|
3371
|
+
const walletAccounts = getWalletProviderByKey.getWalletAccounts(client);
|
|
3363
3372
|
const sortedLastSelectedWalletAccounts = walletAccounts.filter((walletAccount)=>Boolean(walletAccount.lastSelectedAt)).sort((a, b)=>b.lastSelectedAt.getTime() - a.lastSelectedAt.getTime());
|
|
3364
3373
|
if (sortedLastSelectedWalletAccounts.length === 0) {
|
|
3365
3374
|
return null;
|
|
@@ -3384,7 +3393,7 @@ const isSameAddress = (left, right, chain)=>refreshUser.normalizeAddress(left, c
|
|
|
3384
3393
|
walletId: walletAccount.verifiedCredentialId
|
|
3385
3394
|
}
|
|
3386
3395
|
});
|
|
3387
|
-
|
|
3396
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
3388
3397
|
response
|
|
3389
3398
|
}, client);
|
|
3390
3399
|
} else {
|
|
@@ -3421,7 +3430,7 @@ const isSameAddress = (left, right, chain)=>refreshUser.normalizeAddress(left, c
|
|
|
3421
3430
|
walletId: walletAccount.verifiedCredentialId
|
|
3422
3431
|
}
|
|
3423
3432
|
});
|
|
3424
|
-
|
|
3433
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
3425
3434
|
response
|
|
3426
3435
|
}, client);
|
|
3427
3436
|
};
|
|
@@ -3461,7 +3470,7 @@ const isSameAddress = (left, right, chain)=>refreshUser.normalizeAddress(left, c
|
|
|
3461
3470
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
3462
3471
|
* @returns The matching wallet account, or undefined if not found.
|
|
3463
3472
|
*/ const getWalletAccountFromAddress = ({ address, chain }, client = getChainFromVerifiedCredentialChain.getDefaultClient())=>{
|
|
3464
|
-
const walletAccounts =
|
|
3473
|
+
const walletAccounts = getWalletProviderByKey.getWalletAccounts(client);
|
|
3465
3474
|
return walletAccounts.find((walletAccount)=>walletAccount.address === address && walletAccount.chain === chain);
|
|
3466
3475
|
};
|
|
3467
3476
|
|
|
@@ -3517,16 +3526,16 @@ exports.getDefaultClient = getChainFromVerifiedCredentialChain.getDefaultClient;
|
|
|
3517
3526
|
exports.NoNetworkProvidersError = getNetworkProviderFromNetworkId.NoNetworkProvidersError;
|
|
3518
3527
|
exports.getNetworksData = getNetworkProviderFromNetworkId.getNetworksData;
|
|
3519
3528
|
exports.hasExtension = getNetworkProviderFromNetworkId.hasExtension;
|
|
3529
|
+
exports.getWalletAccounts = getWalletProviderByKey.getWalletAccounts;
|
|
3520
3530
|
exports.offEvent = getWalletProviderByKey.offEvent;
|
|
3521
3531
|
exports.onEvent = getWalletProviderByKey.onEvent;
|
|
3522
3532
|
exports.onceEvent = getWalletProviderByKey.onceEvent;
|
|
3523
|
-
exports.NotWaasWalletAccountError = refreshUser.NotWaasWalletAccountError;
|
|
3524
|
-
exports.getWalletAccounts = refreshUser.getWalletAccounts;
|
|
3525
|
-
exports.refreshUser = refreshUser.refreshUser;
|
|
3526
3533
|
exports.consumeMfaToken = isMfaRequiredForAction.consumeMfaToken;
|
|
3527
3534
|
exports.getMfaMethods = isMfaRequiredForAction.getMfaMethods;
|
|
3528
3535
|
exports.isMfaRequiredForAction = isMfaRequiredForAction.isMfaRequiredForAction;
|
|
3529
3536
|
exports.InvalidParamError = InvalidParamError.InvalidParamError;
|
|
3537
|
+
exports.NotWaasWalletAccountError = refreshUser.NotWaasWalletAccountError;
|
|
3538
|
+
exports.refreshUser = refreshUser.refreshUser;
|
|
3530
3539
|
exports.ClientAlreadyInitializedError = ClientAlreadyInitializedError;
|
|
3531
3540
|
exports.InvalidRedirectStorageStateError = InvalidRedirectStorageStateError;
|
|
3532
3541
|
exports.MissingRedirectStorageStateError = MissingRedirectStorageStateError;
|
package/index.esm.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';
|
|
2
|
-
import { B as BaseError, g as getDefaultClient, a as getCore, c as createApiClient, b as getBuffer, d as dependencies, v as version, s as setDefaultClient, _ as _extends, e as assertDefined, r as randomString,
|
|
3
|
-
export { I as InvalidExternalAuthError, M as MfaInvalidOtpError,
|
|
2
|
+
import { B as BaseError, g as getDefaultClient, a as getCore, c as createApiClient, C as CLIENT_SDK_NAME, b as getBuffer, d as dependencies, v as version, s as setDefaultClient, _ as _extends, e as assertDefined, r as randomString, f as CHAINS_INFO_MAP, n as name } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
3
|
+
export { I as InvalidExternalAuthError, M as MfaInvalidOtpError, h as MfaRateLimitedError, S as SandboxMaximumThresholdReachedError } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
4
4
|
import { I as InvalidStorageSet, c as createStorageKeySchema, s as subscribeWithSelector, i as isEqualShallow, C as CannotTrackError, a as createLogger, f as formatSignInMessage, g as getNetworksData, b as getNetworkProviderFromNetworkId } from './getNetworkProviderFromNetworkId.esm.js';
|
|
5
5
|
export { N as NoNetworkProvidersError, h as hasExtension } from './getNetworkProviderFromNetworkId.esm.js';
|
|
6
|
-
import { g as getWalletProviderFromWalletAccount, e as emitEvent,
|
|
7
|
-
export { o as offEvent,
|
|
8
|
-
import { g as getWalletAccounts, u as updateAuthFromVerifyResponse, c as createWalletAccountId, e as emitWalletAccountsChangedEvent, n as normalizeAddress } from './refreshUser.esm.js';
|
|
9
|
-
export { N as NotWaasWalletAccountError, r as refreshUser } from './refreshUser.esm.js';
|
|
6
|
+
import { g as getWalletAccounts, a as getWalletProviderFromWalletAccount, e as emitEvent, u as updateAuthFromVerifyResponse, b as getWalletProviderByKey, c as createWalletAccountId, d as emitWalletAccountsChangedEvent, n as normalizeAddress, f as getWalletProviders } from './getWalletProviderByKey.esm.js';
|
|
7
|
+
export { o as offEvent, i as onEvent, h as onceEvent } from './getWalletProviderByKey.esm.js';
|
|
10
8
|
import * as z from 'zod/mini';
|
|
11
9
|
import { b as bufferToHex } from './isMfaRequiredForAction.esm.js';
|
|
12
10
|
export { c as consumeMfaToken, g as getMfaMethods, i as isMfaRequiredForAction } from './isMfaRequiredForAction.esm.js';
|
|
13
11
|
import EventEmitter$1, { EventEmitter } from 'eventemitter3';
|
|
14
12
|
import { startRegistration, browserSupportsWebAuthn, startAuthentication } from '@simplewebauthn/browser';
|
|
15
13
|
export { I as InvalidParamError } from './InvalidParamError.esm.js';
|
|
14
|
+
export { N as NotWaasWalletAccountError, r as refreshUser } from './refreshUser.esm.js';
|
|
16
15
|
import { ProviderEnum, MfaBackupCodeAcknowledgement, AuthModeEnum } from '@dynamic-labs/sdk-api-core';
|
|
17
16
|
import 'buffer';
|
|
18
17
|
|
|
@@ -180,7 +179,7 @@ const parseFromStorage = (value)=>{
|
|
|
180
179
|
const apiClient = createApiClient({}, client);
|
|
181
180
|
const doFetch = async ()=>apiClient.getEnvironmentSettings({
|
|
182
181
|
environmentId: core.environmentId,
|
|
183
|
-
sdkVersion:
|
|
182
|
+
sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
|
|
184
183
|
}, {
|
|
185
184
|
credentials: 'omit'
|
|
186
185
|
});
|
|
@@ -332,6 +331,7 @@ const getAvailableWalletProvidersFromWalletAccounts = (client)=>{
|
|
|
332
331
|
core.logger.error('Failed to revoke session', error);
|
|
333
332
|
}
|
|
334
333
|
core.state.set({
|
|
334
|
+
legacyToken: null,
|
|
335
335
|
sessionExpiresAt: null,
|
|
336
336
|
token: null,
|
|
337
337
|
user: null
|
|
@@ -426,6 +426,11 @@ const sessionKeySchema = createStorageKeySchema({
|
|
|
426
426
|
key: 'session',
|
|
427
427
|
schema: z.object({
|
|
428
428
|
/**
|
|
429
|
+
* Legacy token will be undefined in environments with cookie based sessions.
|
|
430
|
+
*
|
|
431
|
+
* @deprecated Use `token` instead.
|
|
432
|
+
*/ legacyToken: z.nullable(z.string()),
|
|
433
|
+
/**
|
|
429
434
|
* The current available MFA token.
|
|
430
435
|
*/ mfaToken: z.nullable(z.string()),
|
|
431
436
|
/**
|
|
@@ -448,6 +453,7 @@ const hydrateStateWithStorage = async (client)=>{
|
|
|
448
453
|
const isSessionValid = (session == null ? void 0 : session.sessionExpiration) && session.sessionExpiration > Date.now();
|
|
449
454
|
if (isSessionValid) {
|
|
450
455
|
stateChanges.token = session.token;
|
|
456
|
+
stateChanges.legacyToken = session.legacyToken;
|
|
451
457
|
stateChanges.sessionExpiresAt = new Date(session.sessionExpiration);
|
|
452
458
|
stateChanges.mfaToken = session.mfaToken;
|
|
453
459
|
stateChanges.sessionKeys = session.sessionKeys;
|
|
@@ -474,6 +480,7 @@ const syncStateWithStorage = (client)=>{
|
|
|
474
480
|
void core.storage.removeItem(sessionKeySchema);
|
|
475
481
|
} else {
|
|
476
482
|
void core.storage.setItem(sessionKeySchema, {
|
|
483
|
+
legacyToken: state.legacyToken,
|
|
477
484
|
mfaToken: state.mfaToken,
|
|
478
485
|
sessionExpiration: state.sessionExpiresAt.getTime(),
|
|
479
486
|
sessionKeys: state.sessionKeys,
|
|
@@ -778,6 +785,7 @@ class InvalidStorageValue extends BaseError {
|
|
|
778
785
|
* The initial values for the state of the client.
|
|
779
786
|
*/ const getInitialState = ()=>({
|
|
780
787
|
initStatus: 'uninitialized',
|
|
788
|
+
legacyToken: null,
|
|
781
789
|
mfaToken: null,
|
|
782
790
|
projectSettings: null,
|
|
783
791
|
sessionExpiresAt: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-sdk/client",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dynamic-labs-sdk/assert-package-version": "0.1.0-alpha.
|
|
32
|
+
"@dynamic-labs-sdk/assert-package-version": "0.1.0-alpha.4",
|
|
33
33
|
"@dynamic-labs/sdk-api-core": "0.0.762",
|
|
34
|
-
"@dynamic-labs-wallet/browser-wallet-client": "0.0.
|
|
34
|
+
"@dynamic-labs-wallet/browser-wallet-client": "0.0.155",
|
|
35
35
|
"@simplewebauthn/browser": "^13.1.0",
|
|
36
36
|
"buffer": "6.0.3",
|
|
37
37
|
"eventemitter3": "^5.0.1",
|
package/refreshUser.cjs.js
CHANGED
|
@@ -2,86 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var getChainFromVerifiedCredentialChain = require('./getChainFromVerifiedCredentialChain.cjs.js');
|
|
4
4
|
var getWalletProviderByKey = require('./getWalletProviderByKey.cjs.js');
|
|
5
|
-
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
6
|
-
|
|
7
|
-
const normalizeAddress = (address, chain)=>{
|
|
8
|
-
let normalizedAddress = address;
|
|
9
|
-
if (normalizedAddress == null ? void 0 : normalizedAddress.startsWith('0x')) {
|
|
10
|
-
normalizedAddress = normalizedAddress.slice(2);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
14
|
-
* see also: https://github.com/ChainAgnostic/namespaces
|
|
15
|
-
* note: no standard namespace currently exists for flow
|
|
16
|
-
*/ const chainsThatRequireLowercaseAddress = [
|
|
17
|
-
'EVM',
|
|
18
|
-
'FLOW'
|
|
19
|
-
];
|
|
20
|
-
normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain) ? normalizedAddress == null ? void 0 : normalizedAddress.toLowerCase() : normalizedAddress;
|
|
21
|
-
return normalizedAddress;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const createWalletAccountId = (chain, address)=>`${chain}-${normalizeAddress(address, chain)}`;
|
|
25
|
-
|
|
26
|
-
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
27
|
-
address: unverifiedWalletAccount.address,
|
|
28
|
-
chain: unverifiedWalletAccount.chain,
|
|
29
|
-
id: createWalletAccountId(unverifiedWalletAccount.chain, unverifiedWalletAccount.address),
|
|
30
|
-
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
31
|
-
verifiedCredentialId: null,
|
|
32
|
-
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
36
|
-
getChainFromVerifiedCredentialChain.assertDefined(verified.address, 'Missing address in verified credential');
|
|
37
|
-
getChainFromVerifiedCredentialChain.assertDefined(verified.chain, 'Missing chain in verified credential');
|
|
38
|
-
getChainFromVerifiedCredentialChain.assertDefined(verified.walletName, 'Missing wallet name in verified credential');
|
|
39
|
-
const chain = getChainFromVerifiedCredentialChain.getChainFromVerifiedCredentialChain(verified.chain);
|
|
40
|
-
const hasChainInWalletName = verified.walletName.endsWith(chain.toLowerCase());
|
|
41
|
-
// we need to make sure the walletProviderKey follows the correct format ([walletName][chain])
|
|
42
|
-
// some walletNames will follow the legacy format (e.g. "phantom" instead of "phantomsol", "metamask" instead of "metamaskevm")
|
|
43
|
-
// so we need to make sure we parse it correctly
|
|
44
|
-
const walletProviderKey = hasChainInWalletName ? verified.walletName : getWalletProviderByKey.formatWalletProviderKey(verified.walletName, chain);
|
|
45
|
-
var _verified_lastSelectedAt;
|
|
46
|
-
return {
|
|
47
|
-
address: verified.address,
|
|
48
|
-
chain,
|
|
49
|
-
id: createWalletAccountId(chain, verified.address),
|
|
50
|
-
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
51
|
-
verifiedCredentialId: verified.id,
|
|
52
|
-
walletProviderKey
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const getWalletAccountsFromState = (state)=>{
|
|
57
|
-
const { unverifiedWalletAccounts, user } = state;
|
|
58
|
-
const walletAccountsMap = new Map();
|
|
59
|
-
/**
|
|
60
|
-
* Handle the unverified wallet accounts before the user verified credentials
|
|
61
|
-
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
62
|
-
*/ unverifiedWalletAccounts.forEach((unverifiedWalletAccount)=>{
|
|
63
|
-
const walletAccount = convertUnverifiedWalletAccountToWalletAccount(unverifiedWalletAccount);
|
|
64
|
-
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
65
|
-
});
|
|
66
|
-
var _user_verifiedCredentials;
|
|
67
|
-
/**
|
|
68
|
-
* Handle user verified credentials
|
|
69
|
-
*/ const verifiedCredentials = (_user_verifiedCredentials = user == null ? void 0 : user.verifiedCredentials) != null ? _user_verifiedCredentials : [];
|
|
70
|
-
verifiedCredentials.filter((verified)=>verified.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain).map((verifiedWalletAccount)=>convertVerifiedCredentialToWalletAccount(verifiedWalletAccount)).forEach((verifiedWalletAccount)=>walletAccountsMap.set(verifiedWalletAccount.id, verifiedWalletAccount));
|
|
71
|
-
return Array.from(walletAccountsMap.values());
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Retrieves all wallet accounts associated with the current session.
|
|
76
|
-
*
|
|
77
|
-
* This function returns both verified and unverified wallet accounts,
|
|
78
|
-
* combining data from user credentials and local unverified accounts.
|
|
79
|
-
* You can differentiate between verified and unverified wallet accounts by
|
|
80
|
-
* checking the `verifiedCredentialId` property.
|
|
81
|
-
*
|
|
82
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
83
|
-
* @returns An array of wallet accounts associated with the session.
|
|
84
|
-
*/ const getWalletAccounts = (client = getChainFromVerifiedCredentialChain.getDefaultClient())=>getWalletAccountsFromState(getChainFromVerifiedCredentialChain.getCore(client).state.get());
|
|
85
5
|
|
|
86
6
|
class NotWaasWalletAccountError extends getChainFromVerifiedCredentialChain.BaseError {
|
|
87
7
|
constructor({ walletAddress }){
|
|
@@ -95,44 +15,6 @@ class NotWaasWalletAccountError extends getChainFromVerifiedCredentialChain.Base
|
|
|
95
15
|
}
|
|
96
16
|
}
|
|
97
17
|
|
|
98
|
-
/**
|
|
99
|
-
* Emits the `walletAccountsChanged` event.
|
|
100
|
-
*/ const emitWalletAccountsChangedEvent = (client)=>{
|
|
101
|
-
const walletAccounts = getWalletAccounts(client);
|
|
102
|
-
getWalletProviderByKey.emitEvent({
|
|
103
|
-
args: {
|
|
104
|
-
walletAccounts
|
|
105
|
-
},
|
|
106
|
-
event: 'walletAccountsChanged'
|
|
107
|
-
}, client);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client)=>{
|
|
111
|
-
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
112
|
-
const walletAccountsHashBefore = getWalletAccountsHash(previousState);
|
|
113
|
-
const walletAccountsHashAfter = getWalletAccountsHash(core.state.get());
|
|
114
|
-
if (walletAccountsHashBefore !== walletAccountsHashAfter) {
|
|
115
|
-
emitWalletAccountsChangedEvent(client);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const getWalletAccountsHash = (state)=>getWalletAccountsFromState(state).map(({ id })=>id).sort().join('-');
|
|
119
|
-
|
|
120
|
-
const updateAuthFromVerifyResponse = ({ response }, client)=>{
|
|
121
|
-
const core = getChainFromVerifiedCredentialChain.getCore(client);
|
|
122
|
-
const previousState = getChainFromVerifiedCredentialChain._extends({}, core.state.get());
|
|
123
|
-
const { user, minifiedJwt, expiresAt, mfaToken } = response;
|
|
124
|
-
core.state.set({
|
|
125
|
-
mfaToken: mfaToken != null ? mfaToken : null,
|
|
126
|
-
// Expires at is in seconds, so we need to convert it to milliseconds
|
|
127
|
-
sessionExpiresAt: new Date(expiresAt * 1000),
|
|
128
|
-
token: minifiedJwt != null ? minifiedJwt : null,
|
|
129
|
-
user
|
|
130
|
-
});
|
|
131
|
-
checkAndRaiseWalletAccountsChangedEvent({
|
|
132
|
-
previousState
|
|
133
|
-
}, client);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
18
|
/**
|
|
137
19
|
* Refreshes the current user's data from the server.
|
|
138
20
|
*
|
|
@@ -147,15 +29,10 @@ const updateAuthFromVerifyResponse = ({ response }, client)=>{
|
|
|
147
29
|
const response = await apiClient.refreshAuth({
|
|
148
30
|
environmentId: core.environmentId
|
|
149
31
|
});
|
|
150
|
-
updateAuthFromVerifyResponse({
|
|
32
|
+
getWalletProviderByKey.updateAuthFromVerifyResponse({
|
|
151
33
|
response
|
|
152
34
|
}, client);
|
|
153
35
|
};
|
|
154
36
|
|
|
155
37
|
exports.NotWaasWalletAccountError = NotWaasWalletAccountError;
|
|
156
|
-
exports.createWalletAccountId = createWalletAccountId;
|
|
157
|
-
exports.emitWalletAccountsChangedEvent = emitWalletAccountsChangedEvent;
|
|
158
|
-
exports.getWalletAccounts = getWalletAccounts;
|
|
159
|
-
exports.normalizeAddress = normalizeAddress;
|
|
160
38
|
exports.refreshUser = refreshUser;
|
|
161
|
-
exports.updateAuthFromVerifyResponse = updateAuthFromVerifyResponse;
|
package/refreshUser.esm.js
CHANGED
|
@@ -1,85 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
|
|
4
|
-
|
|
5
|
-
const normalizeAddress = (address, chain)=>{
|
|
6
|
-
let normalizedAddress = address;
|
|
7
|
-
if (normalizedAddress == null ? void 0 : normalizedAddress.startsWith('0x')) {
|
|
8
|
-
normalizedAddress = normalizedAddress.slice(2);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* These are standard from CAIP-2: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
12
|
-
* see also: https://github.com/ChainAgnostic/namespaces
|
|
13
|
-
* note: no standard namespace currently exists for flow
|
|
14
|
-
*/ const chainsThatRequireLowercaseAddress = [
|
|
15
|
-
'EVM',
|
|
16
|
-
'FLOW'
|
|
17
|
-
];
|
|
18
|
-
normalizedAddress = chainsThatRequireLowercaseAddress.includes(chain) ? normalizedAddress == null ? void 0 : normalizedAddress.toLowerCase() : normalizedAddress;
|
|
19
|
-
return normalizedAddress;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const createWalletAccountId = (chain, address)=>`${chain}-${normalizeAddress(address, chain)}`;
|
|
23
|
-
|
|
24
|
-
const convertUnverifiedWalletAccountToWalletAccount = (unverifiedWalletAccount)=>({
|
|
25
|
-
address: unverifiedWalletAccount.address,
|
|
26
|
-
chain: unverifiedWalletAccount.chain,
|
|
27
|
-
id: createWalletAccountId(unverifiedWalletAccount.chain, unverifiedWalletAccount.address),
|
|
28
|
-
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
29
|
-
verifiedCredentialId: null,
|
|
30
|
-
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const convertVerifiedCredentialToWalletAccount = (verified)=>{
|
|
34
|
-
assertDefined(verified.address, 'Missing address in verified credential');
|
|
35
|
-
assertDefined(verified.chain, 'Missing chain in verified credential');
|
|
36
|
-
assertDefined(verified.walletName, 'Missing wallet name in verified credential');
|
|
37
|
-
const chain = getChainFromVerifiedCredentialChain(verified.chain);
|
|
38
|
-
const hasChainInWalletName = verified.walletName.endsWith(chain.toLowerCase());
|
|
39
|
-
// we need to make sure the walletProviderKey follows the correct format ([walletName][chain])
|
|
40
|
-
// some walletNames will follow the legacy format (e.g. "phantom" instead of "phantomsol", "metamask" instead of "metamaskevm")
|
|
41
|
-
// so we need to make sure we parse it correctly
|
|
42
|
-
const walletProviderKey = hasChainInWalletName ? verified.walletName : formatWalletProviderKey(verified.walletName, chain);
|
|
43
|
-
var _verified_lastSelectedAt;
|
|
44
|
-
return {
|
|
45
|
-
address: verified.address,
|
|
46
|
-
chain,
|
|
47
|
-
id: createWalletAccountId(chain, verified.address),
|
|
48
|
-
lastSelectedAt: (_verified_lastSelectedAt = verified.lastSelectedAt) != null ? _verified_lastSelectedAt : null,
|
|
49
|
-
verifiedCredentialId: verified.id,
|
|
50
|
-
walletProviderKey
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const getWalletAccountsFromState = (state)=>{
|
|
55
|
-
const { unverifiedWalletAccounts, user } = state;
|
|
56
|
-
const walletAccountsMap = new Map();
|
|
57
|
-
/**
|
|
58
|
-
* Handle the unverified wallet accounts before the user verified credentials
|
|
59
|
-
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
60
|
-
*/ unverifiedWalletAccounts.forEach((unverifiedWalletAccount)=>{
|
|
61
|
-
const walletAccount = convertUnverifiedWalletAccountToWalletAccount(unverifiedWalletAccount);
|
|
62
|
-
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
63
|
-
});
|
|
64
|
-
var _user_verifiedCredentials;
|
|
65
|
-
/**
|
|
66
|
-
* Handle user verified credentials
|
|
67
|
-
*/ const verifiedCredentials = (_user_verifiedCredentials = user == null ? void 0 : user.verifiedCredentials) != null ? _user_verifiedCredentials : [];
|
|
68
|
-
verifiedCredentials.filter((verified)=>verified.format === JwtVerifiedCredentialFormatEnum.Blockchain).map((verifiedWalletAccount)=>convertVerifiedCredentialToWalletAccount(verifiedWalletAccount)).forEach((verifiedWalletAccount)=>walletAccountsMap.set(verifiedWalletAccount.id, verifiedWalletAccount));
|
|
69
|
-
return Array.from(walletAccountsMap.values());
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Retrieves all wallet accounts associated with the current session.
|
|
74
|
-
*
|
|
75
|
-
* This function returns both verified and unverified wallet accounts,
|
|
76
|
-
* combining data from user credentials and local unverified accounts.
|
|
77
|
-
* You can differentiate between verified and unverified wallet accounts by
|
|
78
|
-
* checking the `verifiedCredentialId` property.
|
|
79
|
-
*
|
|
80
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
81
|
-
* @returns An array of wallet accounts associated with the session.
|
|
82
|
-
*/ const getWalletAccounts = (client = getDefaultClient())=>getWalletAccountsFromState(getCore(client).state.get());
|
|
1
|
+
import { B as BaseError, g as getDefaultClient, a as getCore, c as createApiClient } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
2
|
+
import { u as updateAuthFromVerifyResponse } from './getWalletProviderByKey.esm.js';
|
|
83
3
|
|
|
84
4
|
class NotWaasWalletAccountError extends BaseError {
|
|
85
5
|
constructor({ walletAddress }){
|
|
@@ -93,44 +13,6 @@ class NotWaasWalletAccountError extends BaseError {
|
|
|
93
13
|
}
|
|
94
14
|
}
|
|
95
15
|
|
|
96
|
-
/**
|
|
97
|
-
* Emits the `walletAccountsChanged` event.
|
|
98
|
-
*/ const emitWalletAccountsChangedEvent = (client)=>{
|
|
99
|
-
const walletAccounts = getWalletAccounts(client);
|
|
100
|
-
emitEvent({
|
|
101
|
-
args: {
|
|
102
|
-
walletAccounts
|
|
103
|
-
},
|
|
104
|
-
event: 'walletAccountsChanged'
|
|
105
|
-
}, client);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const checkAndRaiseWalletAccountsChangedEvent = ({ previousState }, client)=>{
|
|
109
|
-
const core = getCore(client);
|
|
110
|
-
const walletAccountsHashBefore = getWalletAccountsHash(previousState);
|
|
111
|
-
const walletAccountsHashAfter = getWalletAccountsHash(core.state.get());
|
|
112
|
-
if (walletAccountsHashBefore !== walletAccountsHashAfter) {
|
|
113
|
-
emitWalletAccountsChangedEvent(client);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const getWalletAccountsHash = (state)=>getWalletAccountsFromState(state).map(({ id })=>id).sort().join('-');
|
|
117
|
-
|
|
118
|
-
const updateAuthFromVerifyResponse = ({ response }, client)=>{
|
|
119
|
-
const core = getCore(client);
|
|
120
|
-
const previousState = _extends({}, core.state.get());
|
|
121
|
-
const { user, minifiedJwt, expiresAt, mfaToken } = response;
|
|
122
|
-
core.state.set({
|
|
123
|
-
mfaToken: mfaToken != null ? mfaToken : null,
|
|
124
|
-
// Expires at is in seconds, so we need to convert it to milliseconds
|
|
125
|
-
sessionExpiresAt: new Date(expiresAt * 1000),
|
|
126
|
-
token: minifiedJwt != null ? minifiedJwt : null,
|
|
127
|
-
user
|
|
128
|
-
});
|
|
129
|
-
checkAndRaiseWalletAccountsChangedEvent({
|
|
130
|
-
previousState
|
|
131
|
-
}, client);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
16
|
/**
|
|
135
17
|
* Refreshes the current user's data from the server.
|
|
136
18
|
*
|
|
@@ -150,4 +32,4 @@ const updateAuthFromVerifyResponse = ({ response }, client)=>{
|
|
|
150
32
|
}, client);
|
|
151
33
|
};
|
|
152
34
|
|
|
153
|
-
export { NotWaasWalletAccountError as N,
|
|
35
|
+
export { NotWaasWalletAccountError as N, refreshUser as r };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInitialState.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/createCore/getInitialState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAO,
|
|
1
|
+
{"version":3,"file":"getInitialState.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/client/core/createCore/getInitialState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,eAAe,QAAO,gBAUjC,CAAC"}
|
package/src/exports/core.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { MultipleClientsFoundError } from '../errors/MultipleClientsFoundError';
|
|
|
11
11
|
export { NoWalletProviderFoundError } from '../errors/NoWalletProviderFoundError';
|
|
12
12
|
export { ValueMustBeDefinedError } from '../errors/ValueMustBeDefinedError';
|
|
13
13
|
export { createApiClient, DYNAMIC_SDK_API_VERSION } from '../modules/apiClient';
|
|
14
|
+
export { updateAuthFromVerifyResponse } from '../modules/auth/updateAuthFromVerifyResponse';
|
|
14
15
|
export { emitEvent } from '../modules/clientEvents';
|
|
15
16
|
export { hasExtension } from '../modules/extension/hasExtension';
|
|
16
17
|
export { registerExtension } from '../modules/extension/registerExtension';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/exports/core.ts"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/exports/core.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/auth/logout/logout.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/auth/logout/logout.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,MAAM,sEA6BlB,CAAC"}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { User } from '../user/user.types';
|
|
2
2
|
declare global {
|
|
3
3
|
interface DynamicCoreState {
|
|
4
|
+
/**
|
|
5
|
+
* The legacy JWT of the current user.
|
|
6
|
+
*
|
|
7
|
+
* This is full JWT that is used for legacy authentication.
|
|
8
|
+
*
|
|
9
|
+
* In cookie based environments, the token will always be null as the token is stored in the cookie.
|
|
10
|
+
* It is not possible to access the cookie from the client.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated use token instead
|
|
13
|
+
*/
|
|
14
|
+
legacyToken: string | null;
|
|
4
15
|
/**
|
|
5
16
|
* The expiration date of the current session.
|
|
6
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/modules/auth/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,gBAAgB;QACxB;;WAEG;QACH,gBAAgB,EAAE,IAAI,GAAG,IAAI,CAAC;QAE9B;;;;;WAKG;QACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAErB;;WAEG;QACH,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;KACnB;CACF"}
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/modules/auth/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,gBAAgB;QACxB;;;;;;;;;WASG;QACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAE3B;;WAEG;QACH,gBAAgB,EAAE,IAAI,GAAG,IAAI,CAAC;QAE9B;;;;;WAKG;QACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAErB;;WAEG;QACH,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;KACnB;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateAuthFromVerifyResponse.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,KAAK,kCAAkC,GAAG;IACxC,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,4BAA4B,iBACzB,kCAAkC,UACxC,aAAa,
|
|
1
|
+
{"version":3,"file":"updateAuthFromVerifyResponse.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/auth/updateAuthFromVerifyResponse/updateAuthFromVerifyResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,KAAK,kCAAkC,GAAG;IACxC,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,4BAA4B,iBACzB,kCAAkC,UACxC,aAAa,SAkBtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchProjectSettings.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchProjectSettings.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/projectSettings/fetchProjectSettings/fetchProjectSettings.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,eAAO,MAAM,gCAAgC,QAAgB,CAAC;AAE9D;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,6HA0ChC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrateStateWithStorage.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,eAAO,MAAM,uBAAuB,WAC1B,aAAa,KACpB,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"hydrateStateWithStorage.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/storageSync/hydrateStateWithStorage/hydrateStateWithStorage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,eAAO,MAAM,uBAAuB,WAC1B,aAAa,KACpB,OAAO,CAAC,IAAI,CAoCd,CAAC"}
|
|
@@ -5,6 +5,7 @@ export declare const stateStorageKeySchema: import("../../services/storage/stora
|
|
|
5
5
|
user: SdkUser | null;
|
|
6
6
|
}>;
|
|
7
7
|
export declare const sessionKeySchema: import("../../services/storage/storage.types").StorageKeySchema<{
|
|
8
|
+
legacyToken: string | null;
|
|
8
9
|
mfaToken: string | null;
|
|
9
10
|
sessionExpiration: number;
|
|
10
11
|
sessionKeys: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/modules/storageSync/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAK3E,eAAO,MAAM,qBAAqB;;;;EAOhC,CAAC;AAEH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/modules/storageSync/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAK3E,eAAO,MAAM,qBAAqB;;;;EAOhC,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;EA8B3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncStateWithStorage.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/storageSync/syncStateWithStorage/syncStateWithStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,eAAO,MAAM,oBAAoB,WAAY,aAAa,
|
|
1
|
+
{"version":3,"file":"syncStateWithStorage.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/storageSync/syncStateWithStorage/syncStateWithStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,eAAO,MAAM,oBAAoB,WAAY,aAAa,SAsBzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWaasClient.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/waas/createWaasClient/createWaasClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AAGjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"createWaasClient.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/modules/waas/createWaasClient/createWaasClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AAGjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAQzE,KAAK,sBAAsB,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,kBACZ,sBAAsB,UAC7B,aAAa,wBAiBtB,CAAC"}
|
package/waas.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';
|
|
2
|
-
import { B as BaseError, g as getDefaultClient,
|
|
2
|
+
import { B as BaseError, g as getDefaultClient, k as getChainFromVerifiedCredentialChain, e as assertDefined, n as name, v as version } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
3
3
|
import { N as NotWaasWalletAccountError, r as refreshUser } from './refreshUser.esm.js';
|
|
4
|
-
import {
|
|
4
|
+
import { a as getWalletProviderFromWalletAccount, k as formatWalletProviderKey, b as getWalletProviderByKey, N as NoWalletProviderFoundError, f as getWalletProviders } from './getWalletProviderByKey.esm.js';
|
|
5
5
|
import { D as DYNAMIC_WAAS_METADATA } from './constants.esm.js';
|
|
6
6
|
import { WalletProviderEnum, EmbeddedWalletVersionEnum, JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
|
|
7
7
|
import 'buffer';
|
package/waasCore.cjs.js
CHANGED
|
@@ -19,7 +19,8 @@ const createWaasClient = ({ chainName }, client)=>{
|
|
|
19
19
|
baseApiUrl: (core.apiBaseUrl || constants.DEFAULT_WAAS_BASE_API_URL).replace('/api/v0', ''),
|
|
20
20
|
baseMPCRelayApiUrl: ((_client_projectSettings = client.projectSettings) == null ? void 0 : (_client_projectSettings_sdk_waas = _client_projectSettings.sdk.waas) == null ? void 0 : _client_projectSettings_sdk_waas.relayUrl) || constants.DEFAULT_WAAS_BASE_MPC_RELAY_API_URL,
|
|
21
21
|
chainName,
|
|
22
|
-
environmentId: core.environmentId
|
|
22
|
+
environmentId: core.environmentId,
|
|
23
|
+
sdkVersion: `${getChainFromVerifiedCredentialChain.CLIENT_SDK_NAME}/${core.version}`
|
|
23
24
|
});
|
|
24
25
|
};
|
|
25
26
|
|
package/waasCore.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';
|
|
2
|
-
import { a as getCore,
|
|
2
|
+
import { a as getCore, C as CLIENT_SDK_NAME, j as isCookieEnabled, f as CHAINS_INFO_MAP, k as getChainFromVerifiedCredentialChain, n as name, v as version } from './getChainFromVerifiedCredentialChain.esm.js';
|
|
3
3
|
import { a as DEFAULT_WAAS_BASE_MPC_RELAY_API_URL, b as DEFAULT_WAAS_BASE_API_URL, D as DYNAMIC_WAAS_METADATA } from './constants.esm.js';
|
|
4
4
|
import { DynamicWalletClient, ThresholdSignatureScheme } from '@dynamic-labs-wallet/browser-wallet-client';
|
|
5
5
|
import { MFAAction, WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
@@ -17,7 +17,8 @@ const createWaasClient = ({ chainName }, client)=>{
|
|
|
17
17
|
baseApiUrl: (core.apiBaseUrl || DEFAULT_WAAS_BASE_API_URL).replace('/api/v0', ''),
|
|
18
18
|
baseMPCRelayApiUrl: ((_client_projectSettings = client.projectSettings) == null ? void 0 : (_client_projectSettings_sdk_waas = _client_projectSettings.sdk.waas) == null ? void 0 : _client_projectSettings_sdk_waas.relayUrl) || DEFAULT_WAAS_BASE_MPC_RELAY_API_URL,
|
|
19
19
|
chainName,
|
|
20
|
-
environmentId: core.environmentId
|
|
20
|
+
environmentId: core.environmentId,
|
|
21
|
+
sdkVersion: `${CLIENT_SDK_NAME}/${core.version}`
|
|
21
22
|
});
|
|
22
23
|
};
|
|
23
24
|
|