@dynamic-labs/embedded-wallet 3.0.0-alpha.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +620 -0
- package/_virtual/_tslib.cjs +15 -0
- package/_virtual/_tslib.js +14 -1
- package/package.json +9 -7
- package/src/index.cjs +12 -2
- package/src/index.d.ts +3 -2
- package/src/index.js +3 -2
- package/src/lib/AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.cjs +6 -5
- package/src/lib/AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.d.ts +588 -42
- package/src/lib/AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.js +4 -3
- package/src/lib/ExportHandler/ExportHandler.cjs +18 -5
- package/src/lib/ExportHandler/ExportHandler.d.ts +588 -42
- package/src/lib/ExportHandler/ExportHandler.js +16 -3
- package/src/lib/TurnkeyWalletConnectorBase/TurnkeyWalletConnectorBase.cjs +43 -18
- package/src/lib/TurnkeyWalletConnectorBase/TurnkeyWalletConnectorBase.d.ts +16 -7
- package/src/lib/TurnkeyWalletConnectorBase/TurnkeyWalletConnectorBase.js +43 -18
- package/src/lib/constants.cjs +21 -0
- package/src/lib/constants.d.ts +7 -0
- package/src/lib/constants.js +15 -1
- package/src/lib/utils/PasskeyService/PasskeyService.cjs +10 -6
- package/src/lib/utils/PasskeyService/PasskeyService.d.ts +2 -2
- package/src/lib/utils/PasskeyService/PasskeyService.js +10 -6
- package/src/lib/utils/PasskeyService/utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.cjs +2 -2
- package/src/lib/utils/PasskeyService/utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.js +2 -2
- package/src/lib/utils/findTurnkeyVerifiedCredentials/findTurnkeyVerifiedCredentials.cjs +19 -0
- package/src/lib/utils/findTurnkeyVerifiedCredentials/findTurnkeyVerifiedCredentials.d.ts +7 -0
- package/src/lib/utils/findTurnkeyVerifiedCredentials/findTurnkeyVerifiedCredentials.js +14 -0
- package/src/lib/utils/findTurnkeyVerifiedCredentials/index.d.ts +2 -0
- package/src/lib/utils/index.d.ts +2 -1
- package/src/lib/utils/logger/index.d.ts +1 -0
- package/src/lib/utils/logger/logger.cjs +29 -0
- package/src/lib/utils/logger/logger.d.ts +6 -0
- package/src/lib/utils/logger/logger.js +24 -0
- package/src/types.d.ts +8 -0
- package/src/lib/utils/findTurnkeyVerifiedCredential/findTurnkeyVerifiedCredential.cjs +0 -8
- package/src/lib/utils/findTurnkeyVerifiedCredential/findTurnkeyVerifiedCredential.d.ts +0 -2
- package/src/lib/utils/findTurnkeyVerifiedCredential/findTurnkeyVerifiedCredential.js +0 -4
- package/src/lib/utils/findTurnkeyVerifiedCredential/index.d.ts +0 -1
|
@@ -3,9 +3,10 @@ import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { IframeStamper, KeyFormat } from '@turnkey/iframe-stamper';
|
|
4
4
|
import { TurnkeyClient } from '@turnkey/http';
|
|
5
5
|
import { getTLD, PlatformService, DynamicError } from '@dynamic-labs/utils';
|
|
6
|
-
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
7
6
|
import { turnkeyAuthenticatorRecoveryHandler } from '../AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.js';
|
|
8
7
|
import { PasskeyService } from '../utils/PasskeyService/PasskeyService.js';
|
|
8
|
+
import '../utils/convertAttestationTransports/convertAttestationTransports.js';
|
|
9
|
+
import { logger } from '../utils/logger/logger.js';
|
|
9
10
|
|
|
10
11
|
const turnkeyBaseUrl = 'https://api.turnkey.com';
|
|
11
12
|
const turnkeyExportUrl = 'https://export.turnkey.com';
|
|
@@ -79,6 +80,12 @@ class ExportHandler {
|
|
|
79
80
|
}
|
|
80
81
|
exportPrivateKey(_a) {
|
|
81
82
|
return __awaiter(this, arguments, void 0, function* ({ privateKeyId, organizationId, }) {
|
|
83
|
+
const apiKeyStamper = ExportHandler === null || ExportHandler === void 0 ? void 0 : ExportHandler.apiKeyStamper;
|
|
84
|
+
if (apiKeyStamper) {
|
|
85
|
+
this.__turnkeyClient = new TurnkeyClient({
|
|
86
|
+
baseUrl: turnkeyBaseUrl,
|
|
87
|
+
}, apiKeyStamper);
|
|
88
|
+
}
|
|
82
89
|
if (!this.__iframeStamper ||
|
|
83
90
|
!this.__publicKey ||
|
|
84
91
|
!this.__turnkeyClient ||
|
|
@@ -95,13 +102,19 @@ class ExportHandler {
|
|
|
95
102
|
return newActivity.activity;
|
|
96
103
|
}
|
|
97
104
|
catch (err) {
|
|
98
|
-
logger.error('Error while completing export private key process', err);
|
|
105
|
+
logger.error('[TK] Error while completing export private key process', err);
|
|
99
106
|
throw err;
|
|
100
107
|
}
|
|
101
108
|
});
|
|
102
109
|
}
|
|
103
110
|
exportWallet(_a) {
|
|
104
111
|
return __awaiter(this, arguments, void 0, function* ({ walletId, organizationId, address, }) {
|
|
112
|
+
const apiKeyStamper = ExportHandler === null || ExportHandler === void 0 ? void 0 : ExportHandler.apiKeyStamper;
|
|
113
|
+
if (apiKeyStamper) {
|
|
114
|
+
this.__turnkeyClient = new TurnkeyClient({
|
|
115
|
+
baseUrl: turnkeyBaseUrl,
|
|
116
|
+
}, apiKeyStamper);
|
|
117
|
+
}
|
|
105
118
|
if (!this.__iframeStamper ||
|
|
106
119
|
!this.__publicKey ||
|
|
107
120
|
!this.__turnkeyClient ||
|
|
@@ -127,7 +140,7 @@ class ExportHandler {
|
|
|
127
140
|
return newActivity.activity;
|
|
128
141
|
}
|
|
129
142
|
catch (err) {
|
|
130
|
-
logger.error('Error while completing export wallet process', err);
|
|
143
|
+
logger.error('[TK] Error while completing export wallet process', err);
|
|
131
144
|
throw err;
|
|
132
145
|
}
|
|
133
146
|
});
|
|
@@ -10,6 +10,7 @@ var utils = require('@dynamic-labs/utils');
|
|
|
10
10
|
var base64UrlEncode = require('../utils/base64UrlEncode/base64UrlEncode.cjs');
|
|
11
11
|
var generateRandomBuffer = require('../utils/generateRandomBuffer/generateRandomBuffer.cjs');
|
|
12
12
|
var convertAttestationTransports = require('../utils/convertAttestationTransports/convertAttestationTransports.cjs');
|
|
13
|
+
var logger = require('../utils/logger/logger.cjs');
|
|
13
14
|
var TurnkeyAuthenticatorRecoveryHandler = require('../AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.cjs');
|
|
14
15
|
var ExportHandler = require('../ExportHandler/ExportHandler.cjs');
|
|
15
16
|
var PasskeyService = require('../utils/PasskeyService/PasskeyService.cjs');
|
|
@@ -77,7 +78,7 @@ class TurnkeyWalletConnectorBase extends walletConnectorCore.WalletConnectorBase
|
|
|
77
78
|
attestation = yield PasskeyService.PasskeyService.getWebAuthnAttestation(webAuthnCreateParams);
|
|
78
79
|
}
|
|
79
80
|
catch (error) {
|
|
80
|
-
|
|
81
|
+
logger.logger.warn(`Unable to register webauthn credential on the current page's TLD ${utils.getTLD()}. Falling back to using hostname. ${utils.PlatformService.getHostname()}`, error);
|
|
81
82
|
// Create the passkey on the hostname instead.
|
|
82
83
|
webAuthnCreateParams.publicKey.rp.id = utils.PlatformService.getHostname();
|
|
83
84
|
attestation = yield PasskeyService.PasskeyService.getWebAuthnAttestation(webAuthnCreateParams);
|
|
@@ -130,17 +131,13 @@ class TurnkeyWalletConnectorBase extends walletConnectorCore.WalletConnectorBase
|
|
|
130
131
|
}
|
|
131
132
|
getConnectedAccounts() {
|
|
132
133
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return [address];
|
|
134
|
+
const verifiedCredentials = this.verifiedCredentials || [];
|
|
135
|
+
const addresses = verifiedCredentials
|
|
136
|
+
.map((vc) => vc === null || vc === void 0 ? void 0 : vc.address)
|
|
137
|
+
.filter((a) => typeof a === 'string');
|
|
138
|
+
return addresses;
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
-
getMobileOrInstalledWallet() {
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
141
|
get turnkeyAddress() {
|
|
145
142
|
var _a;
|
|
146
143
|
const { address } = (_a = this.verifiedCredential) !== null && _a !== void 0 ? _a : {};
|
|
@@ -151,6 +148,12 @@ class TurnkeyWalletConnectorBase extends walletConnectorCore.WalletConnectorBase
|
|
|
151
148
|
return walletProperties;
|
|
152
149
|
}
|
|
153
150
|
// Private methods
|
|
151
|
+
set verifiedCredentials(verifiedCredentials) {
|
|
152
|
+
this._verifiedCredentials = verifiedCredentials;
|
|
153
|
+
}
|
|
154
|
+
get verifiedCredentials() {
|
|
155
|
+
return this._verifiedCredentials;
|
|
156
|
+
}
|
|
154
157
|
set verifiedCredential(verifiedCredential) {
|
|
155
158
|
this._verifiedCredential = verifiedCredential;
|
|
156
159
|
}
|
|
@@ -164,26 +167,32 @@ class TurnkeyWalletConnectorBase extends walletConnectorCore.WalletConnectorBase
|
|
|
164
167
|
this.removeSessionKeysFunction = func;
|
|
165
168
|
}
|
|
166
169
|
createOrRestoreSession() {
|
|
167
|
-
return _tslib.__awaiter(this,
|
|
168
|
-
|
|
170
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ ignoreRestore, } = {}) {
|
|
171
|
+
if (!this.isSessionKeyCompatible() ||
|
|
172
|
+
TurnkeyWalletConnectorBase.isLoadingSession) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
169
175
|
if (!this.createOrRestoreSessionFetcherFunction) {
|
|
170
176
|
throw new utils.DynamicError('Cannot register session key to init provider');
|
|
171
177
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
const { sessionKeys } = TurnkeyWalletConnectorBase;
|
|
179
|
+
if (sessionKeys === null || sessionKeys === void 0 ? void 0 : sessionKeys.publicKey) {
|
|
180
|
+
const isExpired = new Date() >= new Date(sessionKeys.expirationDate);
|
|
181
|
+
if (!isExpired)
|
|
182
|
+
return sessionKeys.publicKey;
|
|
177
183
|
}
|
|
178
184
|
try {
|
|
179
185
|
TurnkeyWalletConnectorBase.isLoadingSession = true;
|
|
180
|
-
const sessionKeys = yield this.createOrRestoreSessionFetcherFunction(
|
|
186
|
+
const sessionKeys = yield this.createOrRestoreSessionFetcherFunction({
|
|
187
|
+
ignoreRestore,
|
|
188
|
+
});
|
|
181
189
|
TurnkeyWalletConnectorBase.sessionKeys = sessionKeys;
|
|
182
190
|
TurnkeyWalletConnectorBase.apiKeyStamper = new apiKeyStamper.ApiKeyStamper({
|
|
183
191
|
apiPrivateKey: sessionKeys.privateKey,
|
|
184
192
|
apiPublicKey: sessionKeys.publicKey,
|
|
185
193
|
});
|
|
186
194
|
ExportHandler.ExportHandler.apiKeyStamper = TurnkeyWalletConnectorBase.apiKeyStamper;
|
|
195
|
+
logger.logger.setMetaData('sessionApiPublicKey', sessionKeys.publicKey);
|
|
187
196
|
return sessionKeys.publicKey;
|
|
188
197
|
}
|
|
189
198
|
catch (error) {
|
|
@@ -211,6 +220,22 @@ class TurnkeyWalletConnectorBase extends walletConnectorCore.WalletConnectorBase
|
|
|
211
220
|
get sessionKeys() {
|
|
212
221
|
return TurnkeyWalletConnectorBase.sessionKeys;
|
|
213
222
|
}
|
|
223
|
+
setLoggerMetadata() {
|
|
224
|
+
var _a, _b, _c;
|
|
225
|
+
logger.logger.setMetaData('turnkeySubOrganizationId', (_b = (_a = this._verifiedCredential) === null || _a === void 0 ? void 0 : _a.walletProperties) === null || _b === void 0 ? void 0 : _b.turnkeySubOrganizationId);
|
|
226
|
+
logger.logger.setMetaData('walletId', (_c = this._verifiedCredential) === null || _c === void 0 ? void 0 : _c.id);
|
|
227
|
+
let authMethod = 'Unknown';
|
|
228
|
+
if (this.isSessionKeyCompatible()) {
|
|
229
|
+
authMethod = 'SessionKeys';
|
|
230
|
+
}
|
|
231
|
+
else if (this.__authenticatorMethodHandler.recoveryType === 'passkey') {
|
|
232
|
+
authMethod = 'Passkey';
|
|
233
|
+
}
|
|
234
|
+
else if (this.__authenticatorMethodHandler.recoveryType === 'email') {
|
|
235
|
+
authMethod = 'EmailAuth';
|
|
236
|
+
}
|
|
237
|
+
logger.logger.setMetaData('authMethod', authMethod);
|
|
238
|
+
}
|
|
214
239
|
}
|
|
215
240
|
TurnkeyWalletConnectorBase.isLoadingSession = false;
|
|
216
241
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ApiKeyStamper } from '@turnkey/api-key-stamper';
|
|
2
|
-
import {
|
|
2
|
+
import { TurnkeyWalletProperties } from '@dynamic-labs/sdk-api-core';
|
|
3
3
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
4
4
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
-
import type { AuthenticatorRecoveryHandler, IEmailWalletConnector, IPasskeyWalletConnector, ISMSWalletConnector
|
|
5
|
+
import type { AuthenticatorRecoveryHandler, IEmailWalletConnector, IPasskeyWalletConnector, ISMSWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import { JwtVerifiedCredentialWithSmartWalletRef } from '../utils';
|
|
6
7
|
import { TurnkeyWalletConnectorNameAndKey } from '../../types';
|
|
7
8
|
import { ExportHandler } from '../ExportHandler';
|
|
8
9
|
export type TurnkeyConnectorBaseProps = {
|
|
@@ -12,6 +13,7 @@ export type TurnkeyConnectorBaseProps = {
|
|
|
12
13
|
export type SessionKeys = {
|
|
13
14
|
publicKey: string;
|
|
14
15
|
privateKey: string;
|
|
16
|
+
expirationDate: string;
|
|
15
17
|
};
|
|
16
18
|
type ITurnkeyWalletConnector = IEmailWalletConnector & IPasskeyWalletConnector & ISMSWalletConnector;
|
|
17
19
|
export declare abstract class TurnkeyWalletConnectorBase extends WalletConnectorBase implements ITurnkeyWalletConnector {
|
|
@@ -24,11 +26,14 @@ export declare abstract class TurnkeyWalletConnectorBase extends WalletConnector
|
|
|
24
26
|
private _phone;
|
|
25
27
|
private _passkeyIdentifier;
|
|
26
28
|
private _verifiedCredential;
|
|
29
|
+
private _verifiedCredentials;
|
|
27
30
|
private __authenticatorMethodHandler;
|
|
28
31
|
private __exportHandler;
|
|
29
32
|
static sessionKeys: SessionKeys | undefined;
|
|
30
33
|
static apiKeyStamper: ApiKeyStamper | undefined;
|
|
31
|
-
createOrRestoreSessionFetcherFunction: ((
|
|
34
|
+
createOrRestoreSessionFetcherFunction: (({ ignoreRestore }: {
|
|
35
|
+
ignoreRestore?: boolean;
|
|
36
|
+
}) => Promise<SessionKeys>) | undefined;
|
|
32
37
|
removeSessionKeysFunction: (() => Promise<void>) | undefined;
|
|
33
38
|
constructor(nameAndKey: TurnkeyWalletConnectorNameAndKey, props: TurnkeyConnectorBaseProps);
|
|
34
39
|
getWebAuthnAttestation(): Promise<{
|
|
@@ -52,17 +57,21 @@ export declare abstract class TurnkeyWalletConnectorBase extends WalletConnector
|
|
|
52
57
|
clearEmail(): void;
|
|
53
58
|
getAddress(): Promise<string | undefined>;
|
|
54
59
|
getConnectedAccounts(): Promise<string[]>;
|
|
55
|
-
getMobileOrInstalledWallet(): WalletConnector;
|
|
56
60
|
get turnkeyAddress(): string | undefined;
|
|
57
61
|
get walletProperties(): TurnkeyWalletProperties | undefined;
|
|
58
|
-
set
|
|
59
|
-
get
|
|
62
|
+
set verifiedCredentials(verifiedCredentials: JwtVerifiedCredentialWithSmartWalletRef[] | undefined);
|
|
63
|
+
get verifiedCredentials(): JwtVerifiedCredentialWithSmartWalletRef[] | undefined;
|
|
64
|
+
set verifiedCredential(verifiedCredential: JwtVerifiedCredentialWithSmartWalletRef | undefined);
|
|
65
|
+
get verifiedCredential(): JwtVerifiedCredentialWithSmartWalletRef | undefined;
|
|
60
66
|
setSessionKeyFetcher(func: () => Promise<SessionKeys>): void;
|
|
61
67
|
setSessionKeyRemoveFunction(func: () => Promise<void>): void;
|
|
62
68
|
removeSessionKeys: () => Promise<void>;
|
|
63
|
-
createOrRestoreSession(
|
|
69
|
+
createOrRestoreSession({ ignoreRestore, }?: {
|
|
70
|
+
ignoreRestore?: boolean;
|
|
71
|
+
}): Promise<string | undefined>;
|
|
64
72
|
isSessionKeyCompatible(): boolean;
|
|
65
73
|
isSessionActive(): Promise<boolean>;
|
|
66
74
|
get sessionKeys(): SessionKeys | undefined;
|
|
75
|
+
protected setLoggerMetadata(): void;
|
|
67
76
|
}
|
|
68
77
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
3
|
import { ApiKeyStamper } from '@turnkey/api-key-stamper';
|
|
4
|
-
import { WalletConnectorBase
|
|
4
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { getTLD, PlatformService, DynamicError } from '@dynamic-labs/utils';
|
|
6
6
|
import { base64UrlEncode } from '../utils/base64UrlEncode/base64UrlEncode.js';
|
|
7
7
|
import { generateRandomBuffer } from '../utils/generateRandomBuffer/generateRandomBuffer.js';
|
|
8
8
|
import { convertAttestationTransports } from '../utils/convertAttestationTransports/convertAttestationTransports.js';
|
|
9
|
+
import { logger } from '../utils/logger/logger.js';
|
|
9
10
|
import { turnkeyAuthenticatorRecoveryHandler } from '../AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.js';
|
|
10
11
|
import { ExportHandler } from '../ExportHandler/ExportHandler.js';
|
|
11
12
|
import { PasskeyService } from '../utils/PasskeyService/PasskeyService.js';
|
|
@@ -126,17 +127,13 @@ class TurnkeyWalletConnectorBase extends WalletConnectorBase {
|
|
|
126
127
|
}
|
|
127
128
|
getConnectedAccounts() {
|
|
128
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return [address];
|
|
130
|
+
const verifiedCredentials = this.verifiedCredentials || [];
|
|
131
|
+
const addresses = verifiedCredentials
|
|
132
|
+
.map((vc) => vc === null || vc === void 0 ? void 0 : vc.address)
|
|
133
|
+
.filter((a) => typeof a === 'string');
|
|
134
|
+
return addresses;
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
getMobileOrInstalledWallet() {
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
137
|
get turnkeyAddress() {
|
|
141
138
|
var _a;
|
|
142
139
|
const { address } = (_a = this.verifiedCredential) !== null && _a !== void 0 ? _a : {};
|
|
@@ -147,6 +144,12 @@ class TurnkeyWalletConnectorBase extends WalletConnectorBase {
|
|
|
147
144
|
return walletProperties;
|
|
148
145
|
}
|
|
149
146
|
// Private methods
|
|
147
|
+
set verifiedCredentials(verifiedCredentials) {
|
|
148
|
+
this._verifiedCredentials = verifiedCredentials;
|
|
149
|
+
}
|
|
150
|
+
get verifiedCredentials() {
|
|
151
|
+
return this._verifiedCredentials;
|
|
152
|
+
}
|
|
150
153
|
set verifiedCredential(verifiedCredential) {
|
|
151
154
|
this._verifiedCredential = verifiedCredential;
|
|
152
155
|
}
|
|
@@ -160,26 +163,32 @@ class TurnkeyWalletConnectorBase extends WalletConnectorBase {
|
|
|
160
163
|
this.removeSessionKeysFunction = func;
|
|
161
164
|
}
|
|
162
165
|
createOrRestoreSession() {
|
|
163
|
-
return __awaiter(this,
|
|
164
|
-
|
|
166
|
+
return __awaiter(this, arguments, void 0, function* ({ ignoreRestore, } = {}) {
|
|
167
|
+
if (!this.isSessionKeyCompatible() ||
|
|
168
|
+
TurnkeyWalletConnectorBase.isLoadingSession) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
165
171
|
if (!this.createOrRestoreSessionFetcherFunction) {
|
|
166
172
|
throw new DynamicError('Cannot register session key to init provider');
|
|
167
173
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
const { sessionKeys } = TurnkeyWalletConnectorBase;
|
|
175
|
+
if (sessionKeys === null || sessionKeys === void 0 ? void 0 : sessionKeys.publicKey) {
|
|
176
|
+
const isExpired = new Date() >= new Date(sessionKeys.expirationDate);
|
|
177
|
+
if (!isExpired)
|
|
178
|
+
return sessionKeys.publicKey;
|
|
173
179
|
}
|
|
174
180
|
try {
|
|
175
181
|
TurnkeyWalletConnectorBase.isLoadingSession = true;
|
|
176
|
-
const sessionKeys = yield this.createOrRestoreSessionFetcherFunction(
|
|
182
|
+
const sessionKeys = yield this.createOrRestoreSessionFetcherFunction({
|
|
183
|
+
ignoreRestore,
|
|
184
|
+
});
|
|
177
185
|
TurnkeyWalletConnectorBase.sessionKeys = sessionKeys;
|
|
178
186
|
TurnkeyWalletConnectorBase.apiKeyStamper = new ApiKeyStamper({
|
|
179
187
|
apiPrivateKey: sessionKeys.privateKey,
|
|
180
188
|
apiPublicKey: sessionKeys.publicKey,
|
|
181
189
|
});
|
|
182
190
|
ExportHandler.apiKeyStamper = TurnkeyWalletConnectorBase.apiKeyStamper;
|
|
191
|
+
logger.setMetaData('sessionApiPublicKey', sessionKeys.publicKey);
|
|
183
192
|
return sessionKeys.publicKey;
|
|
184
193
|
}
|
|
185
194
|
catch (error) {
|
|
@@ -207,6 +216,22 @@ class TurnkeyWalletConnectorBase extends WalletConnectorBase {
|
|
|
207
216
|
get sessionKeys() {
|
|
208
217
|
return TurnkeyWalletConnectorBase.sessionKeys;
|
|
209
218
|
}
|
|
219
|
+
setLoggerMetadata() {
|
|
220
|
+
var _a, _b, _c;
|
|
221
|
+
logger.setMetaData('turnkeySubOrganizationId', (_b = (_a = this._verifiedCredential) === null || _a === void 0 ? void 0 : _a.walletProperties) === null || _b === void 0 ? void 0 : _b.turnkeySubOrganizationId);
|
|
222
|
+
logger.setMetaData('walletId', (_c = this._verifiedCredential) === null || _c === void 0 ? void 0 : _c.id);
|
|
223
|
+
let authMethod = 'Unknown';
|
|
224
|
+
if (this.isSessionKeyCompatible()) {
|
|
225
|
+
authMethod = 'SessionKeys';
|
|
226
|
+
}
|
|
227
|
+
else if (this.__authenticatorMethodHandler.recoveryType === 'passkey') {
|
|
228
|
+
authMethod = 'Passkey';
|
|
229
|
+
}
|
|
230
|
+
else if (this.__authenticatorMethodHandler.recoveryType === 'email') {
|
|
231
|
+
authMethod = 'EmailAuth';
|
|
232
|
+
}
|
|
233
|
+
logger.setMetaData('authMethod', authMethod);
|
|
234
|
+
}
|
|
210
235
|
}
|
|
211
236
|
TurnkeyWalletConnectorBase.isLoadingSession = false;
|
|
212
237
|
|
package/src/lib/constants.cjs
CHANGED
|
@@ -4,5 +4,26 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
const TURNKEY_API_BASE_URL = 'https://api.turnkey.com';
|
|
7
|
+
const TURNKEY_API_KEY_EXPIRY_MESSAGE = 'Turnkey error 16: expired api key';
|
|
8
|
+
const TURNKEY_API_KEY_NOT_FOUND_MESSAGE = 'Turnkey error 16: could not find public key';
|
|
9
|
+
const WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE = 'The operation either timed out or was not allowed';
|
|
10
|
+
const WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE = 'The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.';
|
|
11
|
+
const INVALID_PASSKEY_SELECTED = 'Turnkey error 5: webauthn authenticator not found in organization or parent organization';
|
|
12
|
+
const TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS = [
|
|
13
|
+
TURNKEY_API_KEY_EXPIRY_MESSAGE,
|
|
14
|
+
TURNKEY_API_KEY_NOT_FOUND_MESSAGE,
|
|
15
|
+
];
|
|
16
|
+
const TURNKEY_SDK_BENIGN_ERRORS = [
|
|
17
|
+
WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE,
|
|
18
|
+
WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE,
|
|
19
|
+
INVALID_PASSKEY_SELECTED,
|
|
20
|
+
];
|
|
7
21
|
|
|
22
|
+
exports.INVALID_PASSKEY_SELECTED = INVALID_PASSKEY_SELECTED;
|
|
8
23
|
exports.TURNKEY_API_BASE_URL = TURNKEY_API_BASE_URL;
|
|
24
|
+
exports.TURNKEY_API_KEY_EXPIRY_MESSAGE = TURNKEY_API_KEY_EXPIRY_MESSAGE;
|
|
25
|
+
exports.TURNKEY_API_KEY_NOT_FOUND_MESSAGE = TURNKEY_API_KEY_NOT_FOUND_MESSAGE;
|
|
26
|
+
exports.TURNKEY_SDK_BENIGN_ERRORS = TURNKEY_SDK_BENIGN_ERRORS;
|
|
27
|
+
exports.TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS = TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS;
|
|
28
|
+
exports.WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE = WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE;
|
|
29
|
+
exports.WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE = WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE;
|
package/src/lib/constants.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
1
|
export declare const TURNKEY_API_BASE_URL = "https://api.turnkey.com";
|
|
2
|
+
export declare const TURNKEY_API_KEY_EXPIRY_MESSAGE = "Turnkey error 16: expired api key";
|
|
3
|
+
export declare const TURNKEY_API_KEY_NOT_FOUND_MESSAGE = "Turnkey error 16: could not find public key";
|
|
4
|
+
export declare const WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE = "The operation either timed out or was not allowed";
|
|
5
|
+
export declare const WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE = "The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.";
|
|
6
|
+
export declare const INVALID_PASSKEY_SELECTED = "Turnkey error 5: webauthn authenticator not found in organization or parent organization";
|
|
7
|
+
export declare const TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS: string[];
|
|
8
|
+
export declare const TURNKEY_SDK_BENIGN_ERRORS: string[];
|
package/src/lib/constants.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
const TURNKEY_API_BASE_URL = 'https://api.turnkey.com';
|
|
3
|
+
const TURNKEY_API_KEY_EXPIRY_MESSAGE = 'Turnkey error 16: expired api key';
|
|
4
|
+
const TURNKEY_API_KEY_NOT_FOUND_MESSAGE = 'Turnkey error 16: could not find public key';
|
|
5
|
+
const WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE = 'The operation either timed out or was not allowed';
|
|
6
|
+
const WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE = 'The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.';
|
|
7
|
+
const INVALID_PASSKEY_SELECTED = 'Turnkey error 5: webauthn authenticator not found in organization or parent organization';
|
|
8
|
+
const TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS = [
|
|
9
|
+
TURNKEY_API_KEY_EXPIRY_MESSAGE,
|
|
10
|
+
TURNKEY_API_KEY_NOT_FOUND_MESSAGE,
|
|
11
|
+
];
|
|
12
|
+
const TURNKEY_SDK_BENIGN_ERRORS = [
|
|
13
|
+
WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE,
|
|
14
|
+
WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE,
|
|
15
|
+
INVALID_PASSKEY_SELECTED,
|
|
16
|
+
];
|
|
3
17
|
|
|
4
|
-
export { TURNKEY_API_BASE_URL };
|
|
18
|
+
export { INVALID_PASSKEY_SELECTED, TURNKEY_API_BASE_URL, TURNKEY_API_KEY_EXPIRY_MESSAGE, TURNKEY_API_KEY_NOT_FOUND_MESSAGE, TURNKEY_SDK_BENIGN_ERRORS, TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS, WEBAUTHN_NOT_SUPPORTED_OR_CANCELLED_ERROR_MESSAGE, WEBAUTHN_NOT_SUPPORTED_OR_DISABLED_ERROR_MESSAGE };
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
+
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
6
7
|
var createTurnkeyPasskeyService = require('./utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.cjs');
|
|
7
8
|
|
|
9
|
+
var _a, _PasskeyService_implementation;
|
|
8
10
|
class PasskeyService {
|
|
9
11
|
/**
|
|
10
12
|
* Gets the current passkey service implementation.
|
|
@@ -12,30 +14,32 @@ class PasskeyService {
|
|
|
12
14
|
* @returns {IPasskeyService} The passkey service implementation.
|
|
13
15
|
*/
|
|
14
16
|
static get implementation() {
|
|
15
|
-
if (!
|
|
17
|
+
if (!_tslib.__classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation)) {
|
|
16
18
|
return createTurnkeyPasskeyService.createTurnkeyPasskeyService();
|
|
17
19
|
}
|
|
18
|
-
return
|
|
20
|
+
return _tslib.__classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation);
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Sets the passkey service implementation.
|
|
22
24
|
* @param {IPasskeyService} implementation The passkey service implementation to set.
|
|
23
25
|
*/
|
|
24
|
-
static
|
|
25
|
-
|
|
26
|
+
static set implementation(implementation) {
|
|
27
|
+
_tslib.__classPrivateFieldSet(_a, _a, implementation, "f", _PasskeyService_implementation);
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Gets the WebAuthn attestation method from the current implementation.
|
|
29
31
|
*/
|
|
30
32
|
static get getWebAuthnAttestation() {
|
|
31
|
-
return
|
|
33
|
+
return _a.implementation.getWebAuthnAttestation;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Gets the createWebauthnStamper method from the current implementation.
|
|
35
37
|
*/
|
|
36
38
|
static get createWebauthnStamper() {
|
|
37
|
-
return
|
|
39
|
+
return _a.implementation.createWebauthnStamper;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
42
|
+
_a = PasskeyService;
|
|
43
|
+
_PasskeyService_implementation = { value: void 0 };
|
|
40
44
|
|
|
41
45
|
exports.PasskeyService = PasskeyService;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IPasskeyService } from './types';
|
|
2
2
|
export declare class PasskeyService {
|
|
3
|
-
|
|
3
|
+
#private;
|
|
4
4
|
/**
|
|
5
5
|
* Gets the current passkey service implementation.
|
|
6
6
|
* If no implementation is set, it will create a new turnkey passkey service.
|
|
@@ -11,7 +11,7 @@ export declare class PasskeyService {
|
|
|
11
11
|
* Sets the passkey service implementation.
|
|
12
12
|
* @param {IPasskeyService} implementation The passkey service implementation to set.
|
|
13
13
|
*/
|
|
14
|
-
static
|
|
14
|
+
static set implementation(implementation: IPasskeyService);
|
|
15
15
|
/**
|
|
16
16
|
* Gets the WebAuthn attestation method from the current implementation.
|
|
17
17
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from '../../../../_virtual/_tslib.js';
|
|
2
3
|
import { createTurnkeyPasskeyService } from './utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.js';
|
|
3
4
|
|
|
5
|
+
var _a, _PasskeyService_implementation;
|
|
4
6
|
class PasskeyService {
|
|
5
7
|
/**
|
|
6
8
|
* Gets the current passkey service implementation.
|
|
@@ -8,30 +10,32 @@ class PasskeyService {
|
|
|
8
10
|
* @returns {IPasskeyService} The passkey service implementation.
|
|
9
11
|
*/
|
|
10
12
|
static get implementation() {
|
|
11
|
-
if (!
|
|
13
|
+
if (!__classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation)) {
|
|
12
14
|
return createTurnkeyPasskeyService();
|
|
13
15
|
}
|
|
14
|
-
return
|
|
16
|
+
return __classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation);
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Sets the passkey service implementation.
|
|
18
20
|
* @param {IPasskeyService} implementation The passkey service implementation to set.
|
|
19
21
|
*/
|
|
20
|
-
static
|
|
21
|
-
|
|
22
|
+
static set implementation(implementation) {
|
|
23
|
+
__classPrivateFieldSet(_a, _a, implementation, "f", _PasskeyService_implementation);
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Gets the WebAuthn attestation method from the current implementation.
|
|
25
27
|
*/
|
|
26
28
|
static get getWebAuthnAttestation() {
|
|
27
|
-
return
|
|
29
|
+
return _a.implementation.getWebAuthnAttestation;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Gets the createWebauthnStamper method from the current implementation.
|
|
31
33
|
*/
|
|
32
34
|
static get createWebauthnStamper() {
|
|
33
|
-
return
|
|
35
|
+
return _a.implementation.createWebauthnStamper;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
_a = PasskeyService;
|
|
39
|
+
_PasskeyService_implementation = { value: void 0 };
|
|
36
40
|
|
|
37
41
|
export { PasskeyService };
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var http = require('@turnkey/http');
|
|
7
6
|
var webauthnStamper = require('@turnkey/webauthn-stamper');
|
|
7
|
+
var webauthn = require('@dynamic-labs/webauthn');
|
|
8
8
|
|
|
9
9
|
const createTurnkeyPasskeyService = () => ({
|
|
10
10
|
createWebauthnStamper: (config) => new webauthnStamper.WebauthnStamper(config),
|
|
11
|
-
getWebAuthnAttestation:
|
|
11
|
+
getWebAuthnAttestation: webauthn.getWebAuthnAttestationTurnkeyAdapter,
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
exports.createTurnkeyPasskeyService = createTurnkeyPasskeyService;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { getWebAuthnAttestation } from '@turnkey/http';
|
|
3
2
|
import { WebauthnStamper } from '@turnkey/webauthn-stamper';
|
|
3
|
+
import { getWebAuthnAttestationTurnkeyAdapter } from '@dynamic-labs/webauthn';
|
|
4
4
|
|
|
5
5
|
const createTurnkeyPasskeyService = () => ({
|
|
6
6
|
createWebauthnStamper: (config) => new WebauthnStamper(config),
|
|
7
|
-
getWebAuthnAttestation,
|
|
7
|
+
getWebAuthnAttestation: getWebAuthnAttestationTurnkeyAdapter,
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
export { createTurnkeyPasskeyService };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const findTurnkeyVerifiedCredentials = (verifiedCredentials, chain) => verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.filter(({ walletName, chain: vcChain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) && chain === vcChain);
|
|
7
|
+
const findTurnkeyVerifiedCredentialsWithSmartWalletRef = (verifiedCredentials, chain) => verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.reduce((acc, vc) => {
|
|
8
|
+
var _a;
|
|
9
|
+
if (((_a = vc.walletName) === null || _a === void 0 ? void 0 : _a.startsWith('turnkey')) && chain === vc.chain) {
|
|
10
|
+
const smartWallet = verifiedCredentials.find((v) => v.signerRefId === vc.id);
|
|
11
|
+
const smartWalletRefId = smartWallet === null || smartWallet === void 0 ? void 0 : smartWallet.id;
|
|
12
|
+
const smartWalletRefAddress = smartWallet === null || smartWallet === void 0 ? void 0 : smartWallet.address;
|
|
13
|
+
acc.push(Object.assign(Object.assign({}, vc), { smartWalletRefAddress, smartWalletRefId }));
|
|
14
|
+
}
|
|
15
|
+
return acc;
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
exports.findTurnkeyVerifiedCredentials = findTurnkeyVerifiedCredentials;
|
|
19
|
+
exports.findTurnkeyVerifiedCredentialsWithSmartWalletRef = findTurnkeyVerifiedCredentialsWithSmartWalletRef;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
export declare const findTurnkeyVerifiedCredentials: (verifiedCredentials: JwtVerifiedCredential[], chain: string) => JwtVerifiedCredential[];
|
|
3
|
+
export interface JwtVerifiedCredentialWithSmartWalletRef extends JwtVerifiedCredential {
|
|
4
|
+
smartWalletRefId?: string;
|
|
5
|
+
smartWalletRefAddress?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const findTurnkeyVerifiedCredentialsWithSmartWalletRef: (verifiedCredentials: JwtVerifiedCredential[], chain: string) => JwtVerifiedCredentialWithSmartWalletRef[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const findTurnkeyVerifiedCredentials = (verifiedCredentials, chain) => verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.filter(({ walletName, chain: vcChain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) && chain === vcChain);
|
|
3
|
+
const findTurnkeyVerifiedCredentialsWithSmartWalletRef = (verifiedCredentials, chain) => verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.reduce((acc, vc) => {
|
|
4
|
+
var _a;
|
|
5
|
+
if (((_a = vc.walletName) === null || _a === void 0 ? void 0 : _a.startsWith('turnkey')) && chain === vc.chain) {
|
|
6
|
+
const smartWallet = verifiedCredentials.find((v) => v.signerRefId === vc.id);
|
|
7
|
+
const smartWalletRefId = smartWallet === null || smartWallet === void 0 ? void 0 : smartWallet.id;
|
|
8
|
+
const smartWalletRefAddress = smartWallet === null || smartWallet === void 0 ? void 0 : smartWallet.address;
|
|
9
|
+
acc.push(Object.assign(Object.assign({}, vc), { smartWalletRefAddress, smartWalletRefId }));
|
|
10
|
+
}
|
|
11
|
+
return acc;
|
|
12
|
+
}, []);
|
|
13
|
+
|
|
14
|
+
export { findTurnkeyVerifiedCredentials, findTurnkeyVerifiedCredentialsWithSmartWalletRef };
|
package/src/lib/utils/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
7
|
+
var constants = require('../../constants.cjs');
|
|
8
|
+
|
|
9
|
+
class DynamicEmbeddedWalletsLogger extends logger$1.Logger {
|
|
10
|
+
constructor(name, level) {
|
|
11
|
+
super(name, level);
|
|
12
|
+
}
|
|
13
|
+
error(message, ...args) {
|
|
14
|
+
const [err] = args;
|
|
15
|
+
if (!(err === null || err === void 0 ? void 0 : err.message) ||
|
|
16
|
+
!constants.TURNKEY_SDK_BENIGN_ERRORS.some((errorMsg) => err.message.includes(errorMsg))) {
|
|
17
|
+
logger$1.Logger.events.emit('error', message);
|
|
18
|
+
this.log(logger$1.LogLevel.ERROR, message, ...args);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// log benign turnkey sdk errors as WARN
|
|
22
|
+
this.warn(message, ...args);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const logger = new DynamicEmbeddedWalletsLogger('Dynamic embedded wallets', logger$1.LogLevel.INFO);
|
|
27
|
+
|
|
28
|
+
exports.DynamicEmbeddedWalletsLogger = DynamicEmbeddedWalletsLogger;
|
|
29
|
+
exports.logger = logger;
|