@dynamic-labs/embedded-wallet 0.0.0-exp20240808.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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/_virtual/_tslib.cjs +51 -0
- package/_virtual/_tslib.js +45 -0
- package/package.json +40 -0
- package/src/index.cjs +32 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +10 -0
- package/src/lib/AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.cjs +227 -0
- package/src/lib/AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.d.ts +1640 -0
- package/src/lib/AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.js +223 -0
- package/src/lib/AuthenticatorHandler/index.d.ts +1 -0
- package/src/lib/ExportHandler/ExportHandler.cjs +154 -0
- package/src/lib/ExportHandler/ExportHandler.d.ts +1630 -0
- package/src/lib/ExportHandler/ExportHandler.js +150 -0
- package/src/lib/ExportHandler/index.d.ts +1 -0
- package/src/lib/TurnkeyWalletConnectorBase/TurnkeyWalletConnectorBase.cjs +238 -0
- package/src/lib/TurnkeyWalletConnectorBase/TurnkeyWalletConnectorBase.d.ts +73 -0
- package/src/lib/TurnkeyWalletConnectorBase/TurnkeyWalletConnectorBase.js +234 -0
- package/src/lib/TurnkeyWalletConnectorBase/index.d.ts +1 -0
- package/src/lib/constants.cjs +29 -0
- package/src/lib/constants.d.ts +8 -0
- package/src/lib/constants.js +18 -0
- package/src/lib/utils/PasskeyService/PasskeyService.cjs +45 -0
- package/src/lib/utils/PasskeyService/PasskeyService.d.ts +23 -0
- package/src/lib/utils/PasskeyService/PasskeyService.js +41 -0
- package/src/lib/utils/PasskeyService/index.d.ts +2 -0
- package/src/lib/utils/PasskeyService/types.d.ts +6 -0
- package/src/lib/utils/PasskeyService/utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.cjs +14 -0
- package/src/lib/utils/PasskeyService/utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.d.ts +2 -0
- package/src/lib/utils/PasskeyService/utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.js +10 -0
- package/src/lib/utils/PasskeyService/utils/createTurnkeyPasskeyService/index.d.ts +1 -0
- package/src/lib/utils/base64UrlEncode/base64UrlEncode.cjs +12 -0
- package/src/lib/utils/base64UrlEncode/base64UrlEncode.d.ts +1 -0
- package/src/lib/utils/base64UrlEncode/base64UrlEncode.js +8 -0
- package/src/lib/utils/base64UrlEncode/index.d.ts +1 -0
- package/src/lib/utils/convertAttestationTransports/convertAttestationTransports.cjs +17 -0
- package/src/lib/utils/convertAttestationTransports/convertAttestationTransports.d.ts +4 -0
- package/src/lib/utils/convertAttestationTransports/convertAttestationTransports.js +13 -0
- package/src/lib/utils/convertAttestationTransports/index.d.ts +1 -0
- package/src/lib/utils/findTurnkeyVerifiedCredential/findTurnkeyVerifiedCredential.cjs +8 -0
- package/src/lib/utils/findTurnkeyVerifiedCredential/findTurnkeyVerifiedCredential.d.ts +2 -0
- package/src/lib/utils/findTurnkeyVerifiedCredential/findTurnkeyVerifiedCredential.js +4 -0
- package/src/lib/utils/findTurnkeyVerifiedCredential/index.d.ts +1 -0
- package/src/lib/utils/generateRandomBuffer/generateRandomBuffer.cjs +12 -0
- package/src/lib/utils/generateRandomBuffer/generateRandomBuffer.d.ts +1 -0
- package/src/lib/utils/generateRandomBuffer/generateRandomBuffer.js +8 -0
- package/src/lib/utils/generateRandomBuffer/index.d.ts +1 -0
- package/src/lib/utils/index.d.ts +5 -0
- 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.cjs +17 -0
- package/src/types.d.ts +16 -0
- package/src/types.js +13 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { ApiKeyStamper } from '@turnkey/api-key-stamper';
|
|
4
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { getTLD, PlatformService, DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { base64UrlEncode } from '../utils/base64UrlEncode/base64UrlEncode.js';
|
|
7
|
+
import { generateRandomBuffer } from '../utils/generateRandomBuffer/generateRandomBuffer.js';
|
|
8
|
+
import { convertAttestationTransports } from '../utils/convertAttestationTransports/convertAttestationTransports.js';
|
|
9
|
+
import { logger } from '../utils/logger/logger.js';
|
|
10
|
+
import { turnkeyAuthenticatorRecoveryHandler } from '../AuthenticatorHandler/TurnkeyAuthenticatorRecoveryHandler.js';
|
|
11
|
+
import { ExportHandler } from '../ExportHandler/ExportHandler.js';
|
|
12
|
+
import { PasskeyService } from '../utils/PasskeyService/PasskeyService.js';
|
|
13
|
+
|
|
14
|
+
class TurnkeyWalletConnectorBase extends WalletConnectorBase {
|
|
15
|
+
constructor(nameAndKey, props) {
|
|
16
|
+
super(props);
|
|
17
|
+
// Public fields
|
|
18
|
+
this.requiresNonDynamicEmailOtp = false;
|
|
19
|
+
this.isEmbeddedWallet = true;
|
|
20
|
+
this.removeSessionKeys = () => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
TurnkeyWalletConnectorBase.sessionKeys = undefined;
|
|
22
|
+
TurnkeyWalletConnectorBase.apiKeyStamper = undefined;
|
|
23
|
+
ExportHandler.apiKeyStamper = undefined;
|
|
24
|
+
if (typeof (this === null || this === void 0 ? void 0 : this.removeSessionKeysFunction) === 'function') {
|
|
25
|
+
this.removeSessionKeysFunction();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (!props.appName) {
|
|
29
|
+
throw new Error('appName not set');
|
|
30
|
+
}
|
|
31
|
+
this.name = nameAndKey.name;
|
|
32
|
+
this.overrideKey = nameAndKey.key;
|
|
33
|
+
this.appName = props.appName;
|
|
34
|
+
this.__authenticatorMethodHandler = turnkeyAuthenticatorRecoveryHandler;
|
|
35
|
+
this.__exportHandler = new ExportHandler();
|
|
36
|
+
}
|
|
37
|
+
getWebAuthnAttestation() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const challenge = generateRandomBuffer();
|
|
40
|
+
const authenticatorUserId = generateRandomBuffer();
|
|
41
|
+
const { email, passkeyIdentifier } = this;
|
|
42
|
+
if (!email && !passkeyIdentifier) {
|
|
43
|
+
throw new Error('Email or passkeyIdentifier must be set to register a webauthn credential.');
|
|
44
|
+
}
|
|
45
|
+
const displayName = email || `${this.appName} - ${passkeyIdentifier}`;
|
|
46
|
+
const webAuthnCreateParams = {
|
|
47
|
+
publicKey: {
|
|
48
|
+
authenticatorSelection: {
|
|
49
|
+
authenticatorAttachment: undefined,
|
|
50
|
+
requireResidentKey: false,
|
|
51
|
+
residentKey: 'preferred',
|
|
52
|
+
userVerification: 'discouraged',
|
|
53
|
+
},
|
|
54
|
+
challenge,
|
|
55
|
+
pubKeyCredParams: [
|
|
56
|
+
{
|
|
57
|
+
alg: -7,
|
|
58
|
+
type: 'public-key',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
rp: {
|
|
62
|
+
id: getTLD(),
|
|
63
|
+
name: this.appName,
|
|
64
|
+
},
|
|
65
|
+
user: {
|
|
66
|
+
displayName,
|
|
67
|
+
id: authenticatorUserId,
|
|
68
|
+
name: email || `${this.appName} - ${passkeyIdentifier}`,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
let attestation;
|
|
73
|
+
try {
|
|
74
|
+
attestation = yield PasskeyService.getWebAuthnAttestation(webAuthnCreateParams);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
logger.warn(`Unable to register webauthn credential on the current page's TLD ${getTLD()}. Falling back to using hostname. ${PlatformService.getHostname()}`, error);
|
|
78
|
+
// Create the passkey on the hostname instead.
|
|
79
|
+
webAuthnCreateParams.publicKey.rp.id = PlatformService.getHostname();
|
|
80
|
+
attestation = yield PasskeyService.getWebAuthnAttestation(webAuthnCreateParams);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
attestation: {
|
|
84
|
+
attestationObject: attestation.attestationObject,
|
|
85
|
+
clientDataJson: attestation.clientDataJson,
|
|
86
|
+
credentialId: attestation.credentialId,
|
|
87
|
+
transports: convertAttestationTransports(attestation.transports),
|
|
88
|
+
},
|
|
89
|
+
challenge: base64UrlEncode(challenge),
|
|
90
|
+
displayName,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getAuthenticatorHandler() {
|
|
95
|
+
return this.__authenticatorMethodHandler;
|
|
96
|
+
}
|
|
97
|
+
getExportHandler() {
|
|
98
|
+
return this.__exportHandler;
|
|
99
|
+
}
|
|
100
|
+
// Public methods
|
|
101
|
+
get email() {
|
|
102
|
+
return this._email;
|
|
103
|
+
}
|
|
104
|
+
setEmail(email) {
|
|
105
|
+
this._email = email;
|
|
106
|
+
}
|
|
107
|
+
get phone() {
|
|
108
|
+
return this._phone;
|
|
109
|
+
}
|
|
110
|
+
setPhone(phone) {
|
|
111
|
+
this._phone = phone;
|
|
112
|
+
}
|
|
113
|
+
get passkeyIdentifier() {
|
|
114
|
+
return this._passkeyIdentifier;
|
|
115
|
+
}
|
|
116
|
+
setPasskeyIdentifier(passkeyIdentifier) {
|
|
117
|
+
this._passkeyIdentifier = passkeyIdentifier;
|
|
118
|
+
}
|
|
119
|
+
clearEmail() {
|
|
120
|
+
this._email = null;
|
|
121
|
+
}
|
|
122
|
+
getAddress() {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
var _a;
|
|
125
|
+
return (_a = this.verifiedCredential) === null || _a === void 0 ? void 0 : _a.address;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getConnectedAccounts() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
var _a;
|
|
131
|
+
const address = (_a = this.verifiedCredential) === null || _a === void 0 ? void 0 : _a.address;
|
|
132
|
+
if (!address) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return [address];
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
getMobileOrInstalledWallet() {
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
get turnkeyAddress() {
|
|
142
|
+
var _a;
|
|
143
|
+
const { address } = (_a = this.verifiedCredential) !== null && _a !== void 0 ? _a : {};
|
|
144
|
+
return address;
|
|
145
|
+
}
|
|
146
|
+
get walletProperties() {
|
|
147
|
+
const { walletProperties } = this.verifiedCredential || {};
|
|
148
|
+
return walletProperties;
|
|
149
|
+
}
|
|
150
|
+
// Private methods
|
|
151
|
+
set verifiedCredential(verifiedCredential) {
|
|
152
|
+
this._verifiedCredential = verifiedCredential;
|
|
153
|
+
}
|
|
154
|
+
get verifiedCredential() {
|
|
155
|
+
return this._verifiedCredential;
|
|
156
|
+
}
|
|
157
|
+
setSessionKeyFetcher(func) {
|
|
158
|
+
this.createOrRestoreSessionFetcherFunction = func;
|
|
159
|
+
}
|
|
160
|
+
setSessionKeyRemoveFunction(func) {
|
|
161
|
+
this.removeSessionKeysFunction = func;
|
|
162
|
+
}
|
|
163
|
+
createOrRestoreSession() {
|
|
164
|
+
return __awaiter(this, arguments, void 0, function* ({ ignoreRestore, } = {}) {
|
|
165
|
+
var _a;
|
|
166
|
+
if (!this.isSessionKeyCompatible() ||
|
|
167
|
+
TurnkeyWalletConnectorBase.isLoadingSession) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!this.createOrRestoreSessionFetcherFunction) {
|
|
171
|
+
throw new DynamicError('Cannot register session key to init provider');
|
|
172
|
+
}
|
|
173
|
+
if ((_a = TurnkeyWalletConnectorBase.sessionKeys) === null || _a === void 0 ? void 0 : _a.publicKey) {
|
|
174
|
+
return TurnkeyWalletConnectorBase.sessionKeys.publicKey;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
TurnkeyWalletConnectorBase.isLoadingSession = true;
|
|
178
|
+
const sessionKeys = yield this.createOrRestoreSessionFetcherFunction({
|
|
179
|
+
ignoreRestore,
|
|
180
|
+
});
|
|
181
|
+
TurnkeyWalletConnectorBase.sessionKeys = sessionKeys;
|
|
182
|
+
TurnkeyWalletConnectorBase.apiKeyStamper = new ApiKeyStamper({
|
|
183
|
+
apiPrivateKey: sessionKeys.privateKey,
|
|
184
|
+
apiPublicKey: sessionKeys.publicKey,
|
|
185
|
+
});
|
|
186
|
+
ExportHandler.apiKeyStamper = TurnkeyWalletConnectorBase.apiKeyStamper;
|
|
187
|
+
logger.setMetaData('sessionApiPublicKey', sessionKeys.publicKey);
|
|
188
|
+
return sessionKeys.publicKey;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw new DynamicError('Failed to create or restore session');
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
TurnkeyWalletConnectorBase.isLoadingSession = false;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
isSessionKeyCompatible() {
|
|
199
|
+
var _a;
|
|
200
|
+
const walletProperties = (_a = this.verifiedCredential) === null || _a === void 0 ? void 0 : _a.walletProperties;
|
|
201
|
+
const isSessionKeyCompatible = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.isSessionKeyCompatible;
|
|
202
|
+
return Boolean(isSessionKeyCompatible);
|
|
203
|
+
}
|
|
204
|
+
isSessionActive() {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const hasWallet = yield this.getAddress();
|
|
207
|
+
return Boolean(hasWallet &&
|
|
208
|
+
TurnkeyWalletConnectorBase.sessionKeys &&
|
|
209
|
+
TurnkeyWalletConnectorBase.apiKeyStamper);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
get sessionKeys() {
|
|
213
|
+
return TurnkeyWalletConnectorBase.sessionKeys;
|
|
214
|
+
}
|
|
215
|
+
setLoggerMetadata() {
|
|
216
|
+
var _a, _b, _c;
|
|
217
|
+
logger.setMetaData('turnkeySubOrganizationId', (_b = (_a = this._verifiedCredential) === null || _a === void 0 ? void 0 : _a.walletProperties) === null || _b === void 0 ? void 0 : _b.turnkeySubOrganizationId);
|
|
218
|
+
logger.setMetaData('walletId', (_c = this._verifiedCredential) === null || _c === void 0 ? void 0 : _c.id);
|
|
219
|
+
let authMethod = 'Unknown';
|
|
220
|
+
if (this.isSessionKeyCompatible()) {
|
|
221
|
+
authMethod = 'SessionKeys';
|
|
222
|
+
}
|
|
223
|
+
else if (this.__authenticatorMethodHandler.recoveryType === 'passkey') {
|
|
224
|
+
authMethod = 'Passkey';
|
|
225
|
+
}
|
|
226
|
+
else if (this.__authenticatorMethodHandler.recoveryType === 'email') {
|
|
227
|
+
authMethod = 'EmailAuth';
|
|
228
|
+
}
|
|
229
|
+
logger.setMetaData('authMethod', authMethod);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
TurnkeyWalletConnectorBase.isLoadingSession = false;
|
|
233
|
+
|
|
234
|
+
export { TurnkeyWalletConnectorBase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TurnkeyWalletConnectorBase';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
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
|
+
];
|
|
21
|
+
|
|
22
|
+
exports.INVALID_PASSKEY_SELECTED = INVALID_PASSKEY_SELECTED;
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
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
|
+
];
|
|
17
|
+
|
|
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 };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var createTurnkeyPasskeyService = require('./utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.cjs');
|
|
8
|
+
|
|
9
|
+
var _a, _PasskeyService_implementation;
|
|
10
|
+
class PasskeyService {
|
|
11
|
+
/**
|
|
12
|
+
* Gets the current passkey service implementation.
|
|
13
|
+
* If no implementation is set, it will create a new turnkey passkey service.
|
|
14
|
+
* @returns {IPasskeyService} The passkey service implementation.
|
|
15
|
+
*/
|
|
16
|
+
static get implementation() {
|
|
17
|
+
if (!_tslib.__classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation)) {
|
|
18
|
+
return createTurnkeyPasskeyService.createTurnkeyPasskeyService();
|
|
19
|
+
}
|
|
20
|
+
return _tslib.__classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets the passkey service implementation.
|
|
24
|
+
* @param {IPasskeyService} implementation The passkey service implementation to set.
|
|
25
|
+
*/
|
|
26
|
+
static set implementation(implementation) {
|
|
27
|
+
_tslib.__classPrivateFieldSet(_a, _a, implementation, "f", _PasskeyService_implementation);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets the WebAuthn attestation method from the current implementation.
|
|
31
|
+
*/
|
|
32
|
+
static get getWebAuthnAttestation() {
|
|
33
|
+
return _a.implementation.getWebAuthnAttestation;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the createWebauthnStamper method from the current implementation.
|
|
37
|
+
*/
|
|
38
|
+
static get createWebauthnStamper() {
|
|
39
|
+
return _a.implementation.createWebauthnStamper;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_a = PasskeyService;
|
|
43
|
+
_PasskeyService_implementation = { value: void 0 };
|
|
44
|
+
|
|
45
|
+
exports.PasskeyService = PasskeyService;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IPasskeyService } from './types';
|
|
2
|
+
export declare class PasskeyService {
|
|
3
|
+
#private;
|
|
4
|
+
/**
|
|
5
|
+
* Gets the current passkey service implementation.
|
|
6
|
+
* If no implementation is set, it will create a new turnkey passkey service.
|
|
7
|
+
* @returns {IPasskeyService} The passkey service implementation.
|
|
8
|
+
*/
|
|
9
|
+
static get implementation(): IPasskeyService;
|
|
10
|
+
/**
|
|
11
|
+
* Sets the passkey service implementation.
|
|
12
|
+
* @param {IPasskeyService} implementation The passkey service implementation to set.
|
|
13
|
+
*/
|
|
14
|
+
static set implementation(implementation: IPasskeyService);
|
|
15
|
+
/**
|
|
16
|
+
* Gets the WebAuthn attestation method from the current implementation.
|
|
17
|
+
*/
|
|
18
|
+
static get getWebAuthnAttestation(): typeof import("@turnkey/http").getWebAuthnAttestation;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the createWebauthnStamper method from the current implementation.
|
|
21
|
+
*/
|
|
22
|
+
static get createWebauthnStamper(): (config: import("@turnkey/webauthn-stamper").TWebauthnStamperConfig) => import("@turnkey/webauthn-stamper").WebauthnStamper;
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from '../../../../_virtual/_tslib.js';
|
|
3
|
+
import { createTurnkeyPasskeyService } from './utils/createTurnkeyPasskeyService/createTurnkeyPasskeyService.js';
|
|
4
|
+
|
|
5
|
+
var _a, _PasskeyService_implementation;
|
|
6
|
+
class PasskeyService {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the current passkey service implementation.
|
|
9
|
+
* If no implementation is set, it will create a new turnkey passkey service.
|
|
10
|
+
* @returns {IPasskeyService} The passkey service implementation.
|
|
11
|
+
*/
|
|
12
|
+
static get implementation() {
|
|
13
|
+
if (!__classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation)) {
|
|
14
|
+
return createTurnkeyPasskeyService();
|
|
15
|
+
}
|
|
16
|
+
return __classPrivateFieldGet(_a, _a, "f", _PasskeyService_implementation);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sets the passkey service implementation.
|
|
20
|
+
* @param {IPasskeyService} implementation The passkey service implementation to set.
|
|
21
|
+
*/
|
|
22
|
+
static set implementation(implementation) {
|
|
23
|
+
__classPrivateFieldSet(_a, _a, implementation, "f", _PasskeyService_implementation);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the WebAuthn attestation method from the current implementation.
|
|
27
|
+
*/
|
|
28
|
+
static get getWebAuthnAttestation() {
|
|
29
|
+
return _a.implementation.getWebAuthnAttestation;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the createWebauthnStamper method from the current implementation.
|
|
33
|
+
*/
|
|
34
|
+
static get createWebauthnStamper() {
|
|
35
|
+
return _a.implementation.createWebauthnStamper;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_a = PasskeyService;
|
|
39
|
+
_PasskeyService_implementation = { value: void 0 };
|
|
40
|
+
|
|
41
|
+
export { PasskeyService };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getWebAuthnAttestation } from '@turnkey/http';
|
|
2
|
+
import { TWebauthnStamperConfig, WebauthnStamper } from '@turnkey/webauthn-stamper';
|
|
3
|
+
export type IPasskeyService = {
|
|
4
|
+
getWebAuthnAttestation: typeof getWebAuthnAttestation;
|
|
5
|
+
createWebauthnStamper: (config: TWebauthnStamperConfig) => WebauthnStamper;
|
|
6
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var http = require('@turnkey/http');
|
|
7
|
+
var webauthnStamper = require('@turnkey/webauthn-stamper');
|
|
8
|
+
|
|
9
|
+
const createTurnkeyPasskeyService = () => ({
|
|
10
|
+
createWebauthnStamper: (config) => new webauthnStamper.WebauthnStamper(config),
|
|
11
|
+
getWebAuthnAttestation: http.getWebAuthnAttestation,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
exports.createTurnkeyPasskeyService = createTurnkeyPasskeyService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { getWebAuthnAttestation } from '@turnkey/http';
|
|
3
|
+
import { WebauthnStamper } from '@turnkey/webauthn-stamper';
|
|
4
|
+
|
|
5
|
+
const createTurnkeyPasskeyService = () => ({
|
|
6
|
+
createWebauthnStamper: (config) => new WebauthnStamper(config),
|
|
7
|
+
getWebAuthnAttestation,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { createTurnkeyPasskeyService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTurnkeyPasskeyService } from './createTurnkeyPasskeyService';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const base64UrlEncode = (challenge) => Buffer.from(challenge)
|
|
7
|
+
.toString('base64')
|
|
8
|
+
.replace(/\+/g, '-')
|
|
9
|
+
.replace(/\//g, '_')
|
|
10
|
+
.replace(/=/g, '');
|
|
11
|
+
|
|
12
|
+
exports.base64UrlEncode = base64UrlEncode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const base64UrlEncode: (challenge: ArrayBuffer) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { base64UrlEncode } from './base64UrlEncode';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
7
|
+
|
|
8
|
+
const transportMap = {
|
|
9
|
+
AUTHENTICATOR_TRANSPORT_BLE: sdkApiCore.AuthenticatorTransportProtocol.Ble,
|
|
10
|
+
AUTHENTICATOR_TRANSPORT_HYBRID: sdkApiCore.AuthenticatorTransportProtocol.Hybrid,
|
|
11
|
+
AUTHENTICATOR_TRANSPORT_INTERNAL: sdkApiCore.AuthenticatorTransportProtocol.Internal,
|
|
12
|
+
AUTHENTICATOR_TRANSPORT_NFC: sdkApiCore.AuthenticatorTransportProtocol.Nfc,
|
|
13
|
+
AUTHENTICATOR_TRANSPORT_USB: sdkApiCore.AuthenticatorTransportProtocol.Usb,
|
|
14
|
+
};
|
|
15
|
+
const convertAttestationTransports = (attestationTransports) => attestationTransports.map((transport) => transportMap[transport]);
|
|
16
|
+
|
|
17
|
+
exports.convertAttestationTransports = convertAttestationTransports;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AuthenticatorTransportProtocol } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
type AttestationTransports = 'AUTHENTICATOR_TRANSPORT_BLE' | 'AUTHENTICATOR_TRANSPORT_INTERNAL' | 'AUTHENTICATOR_TRANSPORT_NFC' | 'AUTHENTICATOR_TRANSPORT_HYBRID' | 'AUTHENTICATOR_TRANSPORT_USB';
|
|
3
|
+
export declare const convertAttestationTransports: (attestationTransports: AttestationTransports[]) => AuthenticatorTransportProtocol[];
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { AuthenticatorTransportProtocol } from '@dynamic-labs/sdk-api-core';
|
|
3
|
+
|
|
4
|
+
const transportMap = {
|
|
5
|
+
AUTHENTICATOR_TRANSPORT_BLE: AuthenticatorTransportProtocol.Ble,
|
|
6
|
+
AUTHENTICATOR_TRANSPORT_HYBRID: AuthenticatorTransportProtocol.Hybrid,
|
|
7
|
+
AUTHENTICATOR_TRANSPORT_INTERNAL: AuthenticatorTransportProtocol.Internal,
|
|
8
|
+
AUTHENTICATOR_TRANSPORT_NFC: AuthenticatorTransportProtocol.Nfc,
|
|
9
|
+
AUTHENTICATOR_TRANSPORT_USB: AuthenticatorTransportProtocol.Usb,
|
|
10
|
+
};
|
|
11
|
+
const convertAttestationTransports = (attestationTransports) => attestationTransports.map((transport) => transportMap[transport]);
|
|
12
|
+
|
|
13
|
+
export { convertAttestationTransports };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { convertAttestationTransports } from './convertAttestationTransports';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const findTurnkeyVerifiedCredential = (verifiedCredentials, chain) => verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find(({ walletName, chain: vcChain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) && chain === vcChain);
|
|
7
|
+
|
|
8
|
+
exports.findTurnkeyVerifiedCredential = findTurnkeyVerifiedCredential;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const findTurnkeyVerifiedCredential = (verifiedCredentials, chain) => verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find(({ walletName, chain: vcChain }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) && chain === vcChain);
|
|
3
|
+
|
|
4
|
+
export { findTurnkeyVerifiedCredential };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findTurnkeyVerifiedCredential } from './findTurnkeyVerifiedCredential';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const generateRandomBuffer = () => {
|
|
7
|
+
const arr = new Uint8Array(32);
|
|
8
|
+
crypto.getRandomValues(arr);
|
|
9
|
+
return arr.buffer;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.generateRandomBuffer = generateRandomBuffer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateRandomBuffer: () => ArrayBuffer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateRandomBuffer } from './generateRandomBuffer';
|
|
@@ -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;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LogLevel, Logger, Message } from '@dynamic-labs/logger';
|
|
2
|
+
export declare class DynamicEmbeddedWalletsLogger extends Logger {
|
|
3
|
+
constructor(name: string | string[], level?: LogLevel);
|
|
4
|
+
error(message: Message, ...args: any[]): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const logger: DynamicEmbeddedWalletsLogger;
|