@dynamic-labs/sdk-react-core 4.0.0-alpha.10 → 4.0.0-alpha.11
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 +7 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -11
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +28 -28
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +28 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.0.0-alpha.11](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.10...v4.0.0-alpha.11) (2024-10-15)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* missing null check in property accessor ([#7122](https://github.com/dynamic-labs/dynamic-auth/issues/7122)) ([bbb5e76](https://github.com/dynamic-labs/dynamic-auth/commit/bbb5e76c1284edad2829605444dda24971027a57))
|
|
8
|
+
|
|
2
9
|
## [4.0.0-alpha.10](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.9...v4.0.0-alpha.10) (2024-10-15)
|
|
3
10
|
|
|
4
11
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.11",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@dynamic-labs/sdk-api-core": "0.0.545",
|
|
6
6
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"react-i18next": "13.5.0",
|
|
13
13
|
"yup": "0.32.11",
|
|
14
14
|
"react-international-phone": "4.2.5",
|
|
15
|
-
"@dynamic-labs/assert-package-version": "4.0.0-alpha.
|
|
16
|
-
"@dynamic-labs/iconic": "4.0.0-alpha.
|
|
17
|
-
"@dynamic-labs/logger": "4.0.0-alpha.
|
|
18
|
-
"@dynamic-labs/multi-wallet": "4.0.0-alpha.
|
|
19
|
-
"@dynamic-labs/rpc-providers": "4.0.0-alpha.
|
|
20
|
-
"@dynamic-labs/store": "4.0.0-alpha.
|
|
21
|
-
"@dynamic-labs/types": "4.0.0-alpha.
|
|
22
|
-
"@dynamic-labs/utils": "4.0.0-alpha.
|
|
23
|
-
"@dynamic-labs/wallet-book": "4.0.0-alpha.
|
|
24
|
-
"@dynamic-labs/wallet-connector-core": "4.0.0-alpha.
|
|
15
|
+
"@dynamic-labs/assert-package-version": "4.0.0-alpha.11",
|
|
16
|
+
"@dynamic-labs/iconic": "4.0.0-alpha.11",
|
|
17
|
+
"@dynamic-labs/logger": "4.0.0-alpha.11",
|
|
18
|
+
"@dynamic-labs/multi-wallet": "4.0.0-alpha.11",
|
|
19
|
+
"@dynamic-labs/rpc-providers": "4.0.0-alpha.11",
|
|
20
|
+
"@dynamic-labs/store": "4.0.0-alpha.11",
|
|
21
|
+
"@dynamic-labs/types": "4.0.0-alpha.11",
|
|
22
|
+
"@dynamic-labs/utils": "4.0.0-alpha.11",
|
|
23
|
+
"@dynamic-labs/wallet-book": "4.0.0-alpha.11",
|
|
24
|
+
"@dynamic-labs/wallet-connector-core": "4.0.0-alpha.11",
|
|
25
25
|
"eventemitter3": "5.0.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -125,7 +125,7 @@ const isConnectorSessionKeyActive = (connector) => {
|
|
|
125
125
|
* }
|
|
126
126
|
*/
|
|
127
127
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
128
|
-
var _a, _b, _c, _d;
|
|
128
|
+
var _a, _b, _c, _d, _e;
|
|
129
129
|
const { projectSettings, primaryWallet, user: user$1, environmentId, walletConnectorOptions, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
130
130
|
const { addedWalletsIds } = UserWalletsContext.useInternalUserWallets();
|
|
131
131
|
const { createTurnkeyWallet } = useTurnkey.useTurnkey();
|
|
@@ -149,13 +149,13 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
149
149
|
* @returns Promise<Wallet | undefined>
|
|
150
150
|
*/
|
|
151
151
|
const createEmbeddedWallet = React.useCallback((chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
-
var
|
|
152
|
+
var _f;
|
|
153
153
|
if (!user$1) {
|
|
154
154
|
throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
|
|
155
155
|
}
|
|
156
156
|
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(user$1);
|
|
157
157
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user$1, chains);
|
|
158
|
-
const isManualMode = ((
|
|
158
|
+
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
159
159
|
// if user has a wallet and it's not embedded,
|
|
160
160
|
// throw error to follow another flow and set up the right wallet
|
|
161
161
|
// However, if the user is in manual mode continue.
|
|
@@ -174,14 +174,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
174
174
|
* @param chain - chain parameter to create the wallet for
|
|
175
175
|
* @returns Promise<UserProfile | undefined>
|
|
176
176
|
*/
|
|
177
|
-
const createEmbeddedWalletAccount = React.useCallback((
|
|
178
|
-
var
|
|
177
|
+
const createEmbeddedWalletAccount = React.useCallback((_g) => _tslib.__awaiter(void 0, [_g], void 0, function* ({ chain }) {
|
|
178
|
+
var _h, _j, _k;
|
|
179
179
|
if (!user$1) {
|
|
180
180
|
throw new Error(errors.USER_NOT_LOGGED_IN);
|
|
181
181
|
}
|
|
182
182
|
validateTurnkeyProviderEnabled.validateTurnkeyProviderEnabled(projectSettings);
|
|
183
183
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user$1);
|
|
184
|
-
const turnkeyWalletId = (
|
|
184
|
+
const turnkeyWalletId = (_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.turnkeyHDWalletId;
|
|
185
185
|
if (!turnkeyWalletId) {
|
|
186
186
|
throw new utils.DynamicError('No HD wallet was found for this user to derive a wallet account. Use createEmbeddedWallet first', 'NoHdWalletFound');
|
|
187
187
|
}
|
|
@@ -190,14 +190,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
190
190
|
environmentId,
|
|
191
191
|
});
|
|
192
192
|
if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
193
|
-
yield ((
|
|
193
|
+
yield ((_j = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _j === void 0 ? void 0 : _j.createOrRestoreSession({
|
|
194
194
|
ignoreRestore: true,
|
|
195
195
|
}));
|
|
196
196
|
}
|
|
197
197
|
else if (yield shouldInitRecovery()) {
|
|
198
198
|
yield initPasskeyRecoveryProcess('email');
|
|
199
199
|
}
|
|
200
|
-
const signedRequest = yield ((
|
|
200
|
+
const signedRequest = yield ((_k = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _k === void 0 ? void 0 : _k.stampCreateWalletAccountRequest({
|
|
201
201
|
request: requestToStamp,
|
|
202
202
|
}));
|
|
203
203
|
const verifiedUser = yield embeddedWallets.createEmbeddedWalletAccount({
|
|
@@ -225,7 +225,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
225
225
|
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
226
226
|
*/
|
|
227
227
|
const createOrRestoreSession = React.useCallback((options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
228
|
-
var
|
|
228
|
+
var _l, _m, _o, _p, _q, _r;
|
|
229
229
|
if (!user$1) {
|
|
230
230
|
throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
|
|
231
231
|
}
|
|
@@ -244,12 +244,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
244
244
|
}
|
|
245
245
|
const turnkeyAuthIframeContainerRef = createRootElement(constants.iframeContainerId);
|
|
246
246
|
// try to restore session if possible
|
|
247
|
-
if (passkeyRecovery.canRestoreEmbeddedWalletSession((
|
|
247
|
+
if (passkeyRecovery.canRestoreEmbeddedWalletSession((_l = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _l === void 0 ? void 0 : _l.sessionKeyDuration)) {
|
|
248
248
|
try {
|
|
249
249
|
const sessionRestored = yield passkeyRecovery.restoreEmbeddedWalletSession({
|
|
250
250
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
251
251
|
iframeElementId: constants.iframeElementId,
|
|
252
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((
|
|
252
|
+
sessionExpiration: getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_o = (_m = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _m === void 0 ? void 0 : _m.embeddedWallets) === null || _o === void 0 ? void 0 : _o.sessionKeyDuration),
|
|
253
253
|
user: user$1,
|
|
254
254
|
wallet: primaryWallet,
|
|
255
255
|
});
|
|
@@ -268,7 +268,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
268
268
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
269
269
|
throw new utils.DynamicError('User does not have a secure enclave wallet or a verified email', errors.INVALID_WALLET_DATA);
|
|
270
270
|
}
|
|
271
|
-
const organizationId = (
|
|
271
|
+
const organizationId = (_r = (_q = (_p = user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials) === null || _p === void 0 ? void 0 : _p.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _q === void 0 ? void 0 : _q.walletProperties) === null || _r === void 0 ? void 0 : _r.turnkeySubOrganizationId;
|
|
272
272
|
yield turnkeyRecoveryHandler.verifyRecoveryCode(options.oneTimeCode, organizationId);
|
|
273
273
|
const sessionSettings = {
|
|
274
274
|
createdAt: new Date().getTime(),
|
|
@@ -292,12 +292,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
292
292
|
* @returns Promise<WebAuthnAttestation>
|
|
293
293
|
*/
|
|
294
294
|
const createPasskey = React.useCallback((options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
295
|
-
var
|
|
295
|
+
var _s, _t;
|
|
296
296
|
if (!user$1) {
|
|
297
297
|
throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
|
|
298
298
|
}
|
|
299
299
|
validateTurnkeyProviderEnabled.validateTurnkeyProviderEnabled(projectSettings);
|
|
300
|
-
const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
300
|
+
const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_s = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _s === void 0 ? void 0 : _s.chainConfigurations, user$1.verifiedCredentials);
|
|
301
301
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
302
302
|
throw new utils.DynamicError('Wallet connector not found', errors.INVALID_WALLET_DATA);
|
|
303
303
|
}
|
|
@@ -312,7 +312,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
312
312
|
if (!('id' in turnkeyWallet) || !hasEmailVC) {
|
|
313
313
|
return walletConnector.getWebAuthnAttestation();
|
|
314
314
|
}
|
|
315
|
-
const turnkeySubOrganizationId = (
|
|
315
|
+
const turnkeySubOrganizationId = (_t = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _t === void 0 ? void 0 : _t.turnkeySubOrganizationId;
|
|
316
316
|
if (!turnkeySubOrganizationId) {
|
|
317
317
|
throw new utils.DynamicError('No sub organization id found for the wallet', errors.INVALID_WALLET_DATA);
|
|
318
318
|
}
|
|
@@ -376,16 +376,16 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
376
376
|
* and the html container id to render the iframe into
|
|
377
377
|
* @returns Promise<string> - returns the embedded wallet recovery phrase or private key
|
|
378
378
|
*/
|
|
379
|
-
const revealEmbeddedWalletKey = React.useCallback((
|
|
380
|
-
var
|
|
379
|
+
const revealEmbeddedWalletKey = React.useCallback((_u) => _tslib.__awaiter(void 0, [_u], void 0, function* ({ type, htmlContainerId, }) {
|
|
380
|
+
var _v, _w, _x, _y, _z, _0;
|
|
381
381
|
if (!user$1) {
|
|
382
382
|
throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
|
|
383
383
|
}
|
|
384
384
|
yield turnkeyExport.cleanupExport({
|
|
385
385
|
wallet: wallet,
|
|
386
386
|
});
|
|
387
|
-
const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
388
|
-
const turnkeyHDWalletId = (
|
|
387
|
+
const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_v = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _v === void 0 ? void 0 : _v.chainConfigurations, user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials);
|
|
388
|
+
const turnkeyHDWalletId = (_w = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _w === void 0 ? void 0 : _w.turnkeyHDWalletId;
|
|
389
389
|
if (type === 'recoveryPhrase' && !turnkeyHDWalletId) {
|
|
390
390
|
type = 'privateKey';
|
|
391
391
|
}
|
|
@@ -394,7 +394,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
394
394
|
// since it will show unrelated turnkey content
|
|
395
395
|
iframeContainerElement.current.style.display = 'none';
|
|
396
396
|
if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
397
|
-
yield ((
|
|
397
|
+
yield ((_x = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _x === void 0 ? void 0 : _x.createOrRestoreSession());
|
|
398
398
|
}
|
|
399
399
|
yield turnkeyExport.initExport({
|
|
400
400
|
iframeContainer: iframeContainerElement.current,
|
|
@@ -409,11 +409,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
409
409
|
wallet: wallet,
|
|
410
410
|
});
|
|
411
411
|
}
|
|
412
|
-
catch (
|
|
412
|
+
catch (_1) {
|
|
413
413
|
if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
414
|
-
((
|
|
415
|
-
yield ((
|
|
416
|
-
yield ((
|
|
414
|
+
((_y = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _y === void 0 ? void 0 : _y.removeSessionKeys)) {
|
|
415
|
+
yield ((_z = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _z === void 0 ? void 0 : _z.removeSessionKeys());
|
|
416
|
+
yield ((_0 = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _0 === void 0 ? void 0 : _0.createOrRestoreSession({
|
|
417
417
|
ignoreRestore: true,
|
|
418
418
|
}));
|
|
419
419
|
}
|
|
@@ -432,7 +432,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
432
432
|
createRootElement,
|
|
433
433
|
environmentId,
|
|
434
434
|
wallet,
|
|
435
|
-
(_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk
|
|
435
|
+
(_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.embeddedWallets) === null || _e === void 0 ? void 0 : _e.chainConfigurations,
|
|
436
436
|
user$1,
|
|
437
437
|
walletConnectorOptions,
|
|
438
438
|
]);
|
|
@@ -441,11 +441,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
441
441
|
* @returns Promise<'code_sent'>
|
|
442
442
|
*/
|
|
443
443
|
const sendOneTimeCode = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
444
|
-
var
|
|
444
|
+
var _2, _3;
|
|
445
445
|
if (!user$1) {
|
|
446
446
|
throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
|
|
447
447
|
}
|
|
448
|
-
const targetTurnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
448
|
+
const targetTurnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_2 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _2 === void 0 ? void 0 : _2.chainConfigurations, user$1.verifiedCredentials);
|
|
449
449
|
if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
|
|
450
450
|
throw new utils.DynamicError('User does not have a valid secure enclave wallet', errors.INVALID_WALLET_DATA);
|
|
451
451
|
}
|
|
@@ -456,7 +456,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
456
456
|
throw new utils.DynamicError('Session is active. No need to create a new one', errors.ACTIVE_SESSION);
|
|
457
457
|
}
|
|
458
458
|
const turnkeyAuthIframeContainerRef = createRootElement(constants.iframeContainerId);
|
|
459
|
-
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, constants.iframeElementId, getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((
|
|
459
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, constants.iframeElementId, getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_3 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _3 === void 0 ? void 0 : _3.sessionKeyDuration));
|
|
460
460
|
if (!publicKey) {
|
|
461
461
|
throw new utils.DynamicError(errors.ERROR_SENDING_CODE);
|
|
462
462
|
}
|
|
@@ -121,7 +121,7 @@ const isConnectorSessionKeyActive = (connector) => {
|
|
|
121
121
|
* }
|
|
122
122
|
*/
|
|
123
123
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
124
|
-
var _a, _b, _c, _d;
|
|
124
|
+
var _a, _b, _c, _d, _e;
|
|
125
125
|
const { projectSettings, primaryWallet, user, environmentId, walletConnectorOptions, } = useInternalDynamicContext();
|
|
126
126
|
const { addedWalletsIds } = useInternalUserWallets();
|
|
127
127
|
const { createTurnkeyWallet } = useTurnkey();
|
|
@@ -145,13 +145,13 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
145
145
|
* @returns Promise<Wallet | undefined>
|
|
146
146
|
*/
|
|
147
147
|
const createEmbeddedWallet = useCallback((chains, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
|
-
var
|
|
148
|
+
var _f;
|
|
149
149
|
if (!user) {
|
|
150
150
|
throw new DynamicError(USER_NOT_LOGGED_IN);
|
|
151
151
|
}
|
|
152
152
|
const userWalletsCredentials = getUserWalletsFromVerifiedCredentials(user);
|
|
153
153
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user, chains);
|
|
154
|
-
const isManualMode = ((
|
|
154
|
+
const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
|
|
155
155
|
// if user has a wallet and it's not embedded,
|
|
156
156
|
// throw error to follow another flow and set up the right wallet
|
|
157
157
|
// However, if the user is in manual mode continue.
|
|
@@ -170,14 +170,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
170
170
|
* @param chain - chain parameter to create the wallet for
|
|
171
171
|
* @returns Promise<UserProfile | undefined>
|
|
172
172
|
*/
|
|
173
|
-
const createEmbeddedWalletAccount$1 = useCallback((
|
|
174
|
-
var
|
|
173
|
+
const createEmbeddedWalletAccount$1 = useCallback((_g) => __awaiter(void 0, [_g], void 0, function* ({ chain }) {
|
|
174
|
+
var _h, _j, _k;
|
|
175
175
|
if (!user) {
|
|
176
176
|
throw new Error(USER_NOT_LOGGED_IN);
|
|
177
177
|
}
|
|
178
178
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
179
179
|
const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user);
|
|
180
|
-
const turnkeyWalletId = (
|
|
180
|
+
const turnkeyWalletId = (_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.turnkeyHDWalletId;
|
|
181
181
|
if (!turnkeyWalletId) {
|
|
182
182
|
throw new DynamicError('No HD wallet was found for this user to derive a wallet account. Use createEmbeddedWallet first', 'NoHdWalletFound');
|
|
183
183
|
}
|
|
@@ -186,14 +186,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
186
186
|
environmentId,
|
|
187
187
|
});
|
|
188
188
|
if (isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
189
|
-
yield ((
|
|
189
|
+
yield ((_j = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _j === void 0 ? void 0 : _j.createOrRestoreSession({
|
|
190
190
|
ignoreRestore: true,
|
|
191
191
|
}));
|
|
192
192
|
}
|
|
193
193
|
else if (yield shouldInitRecovery()) {
|
|
194
194
|
yield initPasskeyRecoveryProcess('email');
|
|
195
195
|
}
|
|
196
|
-
const signedRequest = yield ((
|
|
196
|
+
const signedRequest = yield ((_k = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _k === void 0 ? void 0 : _k.stampCreateWalletAccountRequest({
|
|
197
197
|
request: requestToStamp,
|
|
198
198
|
}));
|
|
199
199
|
const verifiedUser = yield createEmbeddedWalletAccount({
|
|
@@ -221,7 +221,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
221
221
|
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
222
222
|
*/
|
|
223
223
|
const createOrRestoreSession = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
-
var
|
|
224
|
+
var _l, _m, _o, _p, _q, _r;
|
|
225
225
|
if (!user) {
|
|
226
226
|
throw new DynamicError(USER_NOT_LOGGED_IN);
|
|
227
227
|
}
|
|
@@ -240,12 +240,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
240
240
|
}
|
|
241
241
|
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
242
242
|
// try to restore session if possible
|
|
243
|
-
if (canRestoreEmbeddedWalletSession((
|
|
243
|
+
if (canRestoreEmbeddedWalletSession((_l = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _l === void 0 ? void 0 : _l.sessionKeyDuration)) {
|
|
244
244
|
try {
|
|
245
245
|
const sessionRestored = yield restoreEmbeddedWalletSession({
|
|
246
246
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
247
247
|
iframeElementId,
|
|
248
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration((
|
|
248
|
+
sessionExpiration: getEmbeddedWalletSessionExpiration((_o = (_m = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _m === void 0 ? void 0 : _m.embeddedWallets) === null || _o === void 0 ? void 0 : _o.sessionKeyDuration),
|
|
249
249
|
user,
|
|
250
250
|
wallet: primaryWallet,
|
|
251
251
|
});
|
|
@@ -264,7 +264,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
264
264
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
265
265
|
throw new DynamicError('User does not have a secure enclave wallet or a verified email', INVALID_WALLET_DATA);
|
|
266
266
|
}
|
|
267
|
-
const organizationId = (
|
|
267
|
+
const organizationId = (_r = (_q = (_p = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _p === void 0 ? void 0 : _p.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _q === void 0 ? void 0 : _q.walletProperties) === null || _r === void 0 ? void 0 : _r.turnkeySubOrganizationId;
|
|
268
268
|
yield turnkeyRecoveryHandler.verifyRecoveryCode(options.oneTimeCode, organizationId);
|
|
269
269
|
const sessionSettings = {
|
|
270
270
|
createdAt: new Date().getTime(),
|
|
@@ -288,12 +288,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
288
288
|
* @returns Promise<WebAuthnAttestation>
|
|
289
289
|
*/
|
|
290
290
|
const createPasskey = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
-
var
|
|
291
|
+
var _s, _t;
|
|
292
292
|
if (!user) {
|
|
293
293
|
throw new DynamicError(USER_NOT_LOGGED_IN);
|
|
294
294
|
}
|
|
295
295
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
296
|
-
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
296
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_s = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _s === void 0 ? void 0 : _s.chainConfigurations, user.verifiedCredentials);
|
|
297
297
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
298
298
|
throw new DynamicError('Wallet connector not found', INVALID_WALLET_DATA);
|
|
299
299
|
}
|
|
@@ -308,7 +308,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
308
308
|
if (!('id' in turnkeyWallet) || !hasEmailVC) {
|
|
309
309
|
return walletConnector.getWebAuthnAttestation();
|
|
310
310
|
}
|
|
311
|
-
const turnkeySubOrganizationId = (
|
|
311
|
+
const turnkeySubOrganizationId = (_t = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _t === void 0 ? void 0 : _t.turnkeySubOrganizationId;
|
|
312
312
|
if (!turnkeySubOrganizationId) {
|
|
313
313
|
throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
|
|
314
314
|
}
|
|
@@ -372,16 +372,16 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
372
372
|
* and the html container id to render the iframe into
|
|
373
373
|
* @returns Promise<string> - returns the embedded wallet recovery phrase or private key
|
|
374
374
|
*/
|
|
375
|
-
const revealEmbeddedWalletKey = useCallback((
|
|
376
|
-
var
|
|
375
|
+
const revealEmbeddedWalletKey = useCallback((_u) => __awaiter(void 0, [_u], void 0, function* ({ type, htmlContainerId, }) {
|
|
376
|
+
var _v, _w, _x, _y, _z, _0;
|
|
377
377
|
if (!user) {
|
|
378
378
|
throw new DynamicError(USER_NOT_LOGGED_IN);
|
|
379
379
|
}
|
|
380
380
|
yield cleanupExport({
|
|
381
381
|
wallet: wallet,
|
|
382
382
|
});
|
|
383
|
-
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
384
|
-
const turnkeyHDWalletId = (
|
|
383
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_v = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _v === void 0 ? void 0 : _v.chainConfigurations, user === null || user === void 0 ? void 0 : user.verifiedCredentials);
|
|
384
|
+
const turnkeyHDWalletId = (_w = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _w === void 0 ? void 0 : _w.turnkeyHDWalletId;
|
|
385
385
|
if (type === 'recoveryPhrase' && !turnkeyHDWalletId) {
|
|
386
386
|
type = 'privateKey';
|
|
387
387
|
}
|
|
@@ -390,7 +390,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
390
390
|
// since it will show unrelated turnkey content
|
|
391
391
|
iframeContainerElement.current.style.display = 'none';
|
|
392
392
|
if (isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
393
|
-
yield ((
|
|
393
|
+
yield ((_x = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _x === void 0 ? void 0 : _x.createOrRestoreSession());
|
|
394
394
|
}
|
|
395
395
|
yield initExport({
|
|
396
396
|
iframeContainer: iframeContainerElement.current,
|
|
@@ -405,11 +405,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
405
405
|
wallet: wallet,
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
catch (
|
|
408
|
+
catch (_1) {
|
|
409
409
|
if (isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
410
|
-
((
|
|
411
|
-
yield ((
|
|
412
|
-
yield ((
|
|
410
|
+
((_y = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _y === void 0 ? void 0 : _y.removeSessionKeys)) {
|
|
411
|
+
yield ((_z = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _z === void 0 ? void 0 : _z.removeSessionKeys());
|
|
412
|
+
yield ((_0 = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _0 === void 0 ? void 0 : _0.createOrRestoreSession({
|
|
413
413
|
ignoreRestore: true,
|
|
414
414
|
}));
|
|
415
415
|
}
|
|
@@ -428,7 +428,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
428
428
|
createRootElement,
|
|
429
429
|
environmentId,
|
|
430
430
|
wallet,
|
|
431
|
-
(_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk
|
|
431
|
+
(_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.embeddedWallets) === null || _e === void 0 ? void 0 : _e.chainConfigurations,
|
|
432
432
|
user,
|
|
433
433
|
walletConnectorOptions,
|
|
434
434
|
]);
|
|
@@ -437,11 +437,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
437
437
|
* @returns Promise<'code_sent'>
|
|
438
438
|
*/
|
|
439
439
|
const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
440
|
-
var
|
|
440
|
+
var _2, _3;
|
|
441
441
|
if (!user) {
|
|
442
442
|
throw new DynamicError(USER_NOT_LOGGED_IN);
|
|
443
443
|
}
|
|
444
|
-
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
444
|
+
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_2 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _2 === void 0 ? void 0 : _2.chainConfigurations, user.verifiedCredentials);
|
|
445
445
|
if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
|
|
446
446
|
throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
|
|
447
447
|
}
|
|
@@ -452,7 +452,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
452
452
|
throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
|
|
453
453
|
}
|
|
454
454
|
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
455
|
-
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((
|
|
455
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((_3 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _3 === void 0 ? void 0 : _3.sessionKeyDuration));
|
|
456
456
|
if (!publicKey) {
|
|
457
457
|
throw new DynamicError(ERROR_SENDING_CODE);
|
|
458
458
|
}
|