@turnkey/sdk-browser 1.16.0 → 2.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/__clients__/base-client.d.ts +7 -0
  3. package/dist/__clients__/base-client.d.ts.map +1 -0
  4. package/dist/__clients__/base-client.js +13 -0
  5. package/dist/__clients__/base-client.js.map +1 -0
  6. package/dist/__clients__/base-client.mjs +11 -0
  7. package/dist/__clients__/base-client.mjs.map +1 -0
  8. package/dist/__clients__/browser-clients.d.ts +243 -0
  9. package/dist/__clients__/browser-clients.d.ts.map +1 -0
  10. package/dist/__clients__/browser-clients.js +633 -0
  11. package/dist/__clients__/browser-clients.js.map +1 -0
  12. package/dist/__clients__/browser-clients.mjs +628 -0
  13. package/dist/__clients__/browser-clients.mjs.map +1 -0
  14. package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
  15. package/dist/__generated__/sdk-client-base.js +106 -110
  16. package/dist/__generated__/sdk-client-base.js.map +1 -1
  17. package/dist/__generated__/sdk-client-base.mjs +106 -110
  18. package/dist/__generated__/sdk-client-base.mjs.map +1 -1
  19. package/dist/__generated__/version.d.ts +1 -1
  20. package/dist/__generated__/version.d.ts.map +1 -1
  21. package/dist/__generated__/version.js +1 -1
  22. package/dist/__generated__/version.mjs +1 -1
  23. package/dist/__types__/base.d.ts +12 -0
  24. package/dist/__types__/base.d.ts.map +1 -1
  25. package/dist/__types__/base.js +5 -0
  26. package/dist/__types__/base.js.map +1 -1
  27. package/dist/__types__/base.mjs +6 -1
  28. package/dist/__types__/base.mjs.map +1 -1
  29. package/dist/constants.d.ts +2 -0
  30. package/dist/constants.d.ts.map +1 -0
  31. package/dist/constants.js +6 -0
  32. package/dist/constants.js.map +1 -0
  33. package/dist/constants.mjs +4 -0
  34. package/dist/constants.mjs.map +1 -0
  35. package/dist/index.d.ts +4 -4
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +9 -4
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +3 -2
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/models.d.ts +1 -1
  42. package/dist/models.d.ts.map +1 -1
  43. package/dist/sdk-client.d.ts +14 -186
  44. package/dist/sdk-client.d.ts.map +1 -1
  45. package/dist/sdk-client.js +75 -437
  46. package/dist/sdk-client.js.map +1 -1
  47. package/dist/sdk-client.mjs +69 -431
  48. package/dist/sdk-client.mjs.map +1 -1
  49. package/dist/storage.d.ts +23 -3
  50. package/dist/storage.d.ts.map +1 -1
  51. package/dist/storage.js +17 -0
  52. package/dist/storage.js.map +1 -1
  53. package/dist/storage.mjs +17 -1
  54. package/dist/storage.mjs.map +1 -1
  55. package/package.json +6 -5
@@ -0,0 +1,628 @@
1
+ import { getWebAuthnAttestation } from '@turnkey/http';
2
+ import { TurnkeyBaseClient } from './base-client.mjs';
3
+ import { SessionType, AuthClient } from '../__types__/base.mjs';
4
+ import { generateRandomBuffer, base64UrlEncode, createEmbeddedAPIKey } from '../utils.mjs';
5
+ import { saveSession, storeSession, getStorageValue, StorageKeys } from '../storage.mjs';
6
+ import { DEFAULT_SESSION_EXPIRATION_IN_SECONDS } from '../constants.mjs';
7
+
8
+ class TurnkeyBrowserClient extends TurnkeyBaseClient {
9
+ constructor(config, authClient) {
10
+ super(config, authClient);
11
+ this.login = async (config) => {
12
+ const readOnlySessionResult = await this.createReadOnlySession(config || {});
13
+ await saveSession(readOnlySessionResult, this.authClient);
14
+ return readOnlySessionResult;
15
+ };
16
+ /**
17
+ * Creates a read-write session. This method infers the current user's organization ID and target userId.
18
+ * To be used in conjunction with an `iframeStamper`: the resulting session's credential bundle can be
19
+ * injected into an iframeStamper to create a session that enables both read and write requests.
20
+ *
21
+ * @param targetEmbeddedKey
22
+ * @param expirationSeconds
23
+ * @param userId
24
+ * @returns {Promise<void>}
25
+ */
26
+ this.refereshSession = async (sessionType = SessionType.READ_WRITE, targetPublicKey, // TODO: eventually we want to automatically pull this from localStorage/iframe
27
+ expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS) => {
28
+ try {
29
+ if (sessionType === SessionType.READ_ONLY) {
30
+ if (this instanceof TurnkeyPasskeyClient) {
31
+ throw new Error("You must use a passkey client to refresh a read session"); // TODO: support wallet client
32
+ }
33
+ const readOnlySessionResult = await this.createReadOnlySession({});
34
+ const session = {
35
+ sessionType: SessionType.READ_ONLY,
36
+ userId: readOnlySessionResult.userId,
37
+ organizationId: readOnlySessionResult.organizationId,
38
+ expiry: Number(readOnlySessionResult.sessionExpiry),
39
+ token: readOnlySessionResult.session,
40
+ };
41
+ await storeSession(session, AuthClient.Passkey);
42
+ }
43
+ if (sessionType === SessionType.READ_WRITE) {
44
+ if (!targetPublicKey) {
45
+ throw new Error("You must provide a targetPublicKey to refresh a read-write session.");
46
+ }
47
+ const readWriteSessionResult = await this.createReadWriteSession({
48
+ targetPublicKey,
49
+ expirationSeconds,
50
+ invalidateExisting: true,
51
+ });
52
+ const session = {
53
+ sessionType: SessionType.READ_WRITE,
54
+ userId: readWriteSessionResult.userId,
55
+ organizationId: readWriteSessionResult.organizationId,
56
+ expiry: Date.now() + Number(expirationSeconds) * 1000,
57
+ token: readWriteSessionResult.credentialBundle,
58
+ };
59
+ if (this instanceof TurnkeyIframeClient) {
60
+ await this.injectCredentialBundle(session.token);
61
+ }
62
+ else {
63
+ // Throw an error if the client is not an iframe client
64
+ throw new Error("You must use an iframe client to refresh a read-write session");
65
+ }
66
+ await storeSession(session, AuthClient.Iframe);
67
+ }
68
+ }
69
+ catch (error) {
70
+ throw new Error("Unable to refresh session.");
71
+ }
72
+ };
73
+ /**
74
+ * Log in with a bundle. This method uses a bundle sent to the end user email
75
+ * To be used in conjunction with an `iframeStamper`.
76
+ *
77
+ * @param bundle
78
+ * @param expirationSeconds
79
+ * @returns {Promise<void>}
80
+ */
81
+ this.loginWithBundle = async (bundle, // we need a way to get the expiry of this token. Either it lives in the token itself or is returned from the server action and passed again here
82
+ expirationSeconds) => {
83
+ if (this instanceof TurnkeyIframeClient) {
84
+ await this.injectCredentialBundle(bundle);
85
+ }
86
+ else {
87
+ // Throw an error if the client is not an iframe client
88
+ throw new Error("You must use an iframe client to log in with a session."); //should we default to a "localStorage" client?
89
+ }
90
+ const whoAmI = await this.getWhoami();
91
+ const session = {
92
+ sessionType: SessionType.READ_WRITE,
93
+ userId: whoAmI.userId,
94
+ organizationId: whoAmI.organizationId,
95
+ expiry: Date.now() + Number(expirationSeconds) * 1000,
96
+ token: bundle,
97
+ };
98
+ await storeSession(session, AuthClient.Iframe);
99
+ };
100
+ /**
101
+ * Log in with a session object. This method uses a session object from server actions and stores it and the active client in local storage
102
+ * To be used in conjunction with an `iframeStamper`.
103
+ *
104
+ * @param session
105
+ * @returns {Promise<void>}
106
+ */
107
+ this.loginWithSession = async (session) => {
108
+ if (this instanceof TurnkeyIframeClient) {
109
+ await this.injectCredentialBundle(session.token);
110
+ }
111
+ else {
112
+ // Throw an error if the client is not an iframe client
113
+ throw new Error("You must use an iframe client to log in with a session."); //should we default to a "localStorage" client?
114
+ }
115
+ await storeSession(session, AuthClient.Iframe);
116
+ };
117
+ /**
118
+ * Log in with a passkey.
119
+ * To be used in conjunction with a `passkeyStamper`
120
+ *
121
+ * @param session
122
+ * @returns {Promise<void>}
123
+ */
124
+ this.loginWithPasskey = async (sessionType = SessionType.READ_WRITE, iframeClient, targetPublicKey, // TODO: eventually we want to automatically pull this from localStorage/iframe
125
+ expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS) => {
126
+ try {
127
+ // Create a read-only session
128
+ if (sessionType === SessionType.READ_ONLY) {
129
+ const readOnlySessionResult = await this.createReadOnlySession({});
130
+ const session = {
131
+ sessionType: SessionType.READ_ONLY,
132
+ userId: readOnlySessionResult.userId,
133
+ organizationId: readOnlySessionResult.organizationId,
134
+ expiry: Number(readOnlySessionResult.sessionExpiry),
135
+ token: readOnlySessionResult.session,
136
+ };
137
+ await storeSession(session, AuthClient.Passkey);
138
+ }
139
+ // Create a read-write session
140
+ if (sessionType === SessionType.READ_WRITE) {
141
+ if (!targetPublicKey) {
142
+ throw new Error("You must provide a targetPublicKey to create a read-write session.");
143
+ }
144
+ const readWriteSessionResult = await this.createReadWriteSession({
145
+ targetPublicKey,
146
+ expirationSeconds,
147
+ });
148
+ const session = {
149
+ sessionType: SessionType.READ_WRITE,
150
+ userId: readWriteSessionResult.userId,
151
+ organizationId: readWriteSessionResult.organizationId,
152
+ expiry: Date.now() + Number(expirationSeconds) * 1000,
153
+ token: readWriteSessionResult.credentialBundle,
154
+ };
155
+ if (!iframeClient) {
156
+ throw new Error("You must provide an iframe client to log in with a passkey.");
157
+ }
158
+ await iframeClient.injectCredentialBundle(session.token);
159
+ await storeSession(session, AuthClient.Iframe);
160
+ }
161
+ else {
162
+ throw new Error("Invalid session type passed.");
163
+ }
164
+ }
165
+ catch (error) {
166
+ throw new Error("Unable to log in with the provided passkey.");
167
+ }
168
+ };
169
+ /**
170
+ * Log in with a browser wallet.
171
+ *
172
+ * @param session
173
+ * @returns {Promise<void>}
174
+ */
175
+ this.loginWithWallet = async (sessionType = SessionType.READ_WRITE, iframeClient, targetPublicKey, // TODO: eventually we want to automatically pull this from localStorage/iframe
176
+ expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS) => {
177
+ // Create a read-only session
178
+ if (sessionType === SessionType.READ_ONLY) {
179
+ const readOnlySessionResult = await this.createReadOnlySession({});
180
+ const session = {
181
+ sessionType: SessionType.READ_ONLY,
182
+ userId: readOnlySessionResult.userId,
183
+ organizationId: readOnlySessionResult.organizationId,
184
+ expiry: Number(readOnlySessionResult.sessionExpiry),
185
+ token: readOnlySessionResult.session,
186
+ };
187
+ await storeSession(session, AuthClient.Wallet);
188
+ }
189
+ // Create a read-write session
190
+ if (sessionType === SessionType.READ_WRITE) {
191
+ if (!targetPublicKey) {
192
+ throw new Error("You must provide a targetPublicKey to create a read-write session.");
193
+ }
194
+ const readWriteSessionResult = await this.createReadWriteSession({
195
+ targetPublicKey,
196
+ expirationSeconds,
197
+ });
198
+ const session = {
199
+ sessionType: SessionType.READ_WRITE,
200
+ userId: readWriteSessionResult.userId,
201
+ organizationId: readWriteSessionResult.organizationId,
202
+ expiry: Date.now() + Number(expirationSeconds) * 1000,
203
+ token: readWriteSessionResult.credentialBundle,
204
+ };
205
+ if (!iframeClient) {
206
+ throw new Error("You must provide an iframe client to log in with a wallet.");
207
+ }
208
+ await iframeClient.injectCredentialBundle(session.token);
209
+ await storeSession(session, AuthClient.Iframe);
210
+ }
211
+ else {
212
+ throw new Error("Invalid session type passed.");
213
+ }
214
+ };
215
+ /**
216
+ * Creates a read-write session. This method infers the current user's organization ID and target userId.
217
+ * To be used in conjunction with an `iframeStamper`: the resulting session's credential bundle can be
218
+ * injected into an iframeStamper to create a session that enables both read and write requests.
219
+ *
220
+ * @param targetEmbeddedKey
221
+ * @param expirationSeconds
222
+ * @param userId
223
+ * @returns {Promise<SdkApiTypes.TCreateReadWriteSessionResponse>}
224
+ */
225
+ this.loginWithReadWriteSession = async (targetEmbeddedKey, expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, userId) => {
226
+ try {
227
+ const readWriteSessionResult = await this.createReadWriteSession({
228
+ targetPublicKey: targetEmbeddedKey,
229
+ expirationSeconds,
230
+ userId: userId,
231
+ });
232
+ // Ensure session and sessionExpiry are included in the object
233
+ const readWriteSessionResultWithSession = {
234
+ ...readWriteSessionResult,
235
+ credentialBundle: readWriteSessionResult.credentialBundle,
236
+ sessionExpiry: Date.now() + Number(expirationSeconds) * 1000,
237
+ };
238
+ // store auth bundle in local storage
239
+ await saveSession(readWriteSessionResultWithSession, this.authClient);
240
+ return readWriteSessionResultWithSession;
241
+ }
242
+ catch (error) {
243
+ throw new Error("Unable to log in with the provided read-write session.");
244
+ }
245
+ };
246
+ /**
247
+ * Logs in with an existing auth bundle. this bundle enables both read and write requests.
248
+ *
249
+ * @param credentialBundle
250
+ * @param expirationSeconds
251
+ * @returns {Promise<boolean>}
252
+ */
253
+ this.loginWithAuthBundle = async (credentialBundle, expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS) => {
254
+ try {
255
+ const whoAmIResult = await this.getWhoami();
256
+ const readWriteSessionResultWithSession = {
257
+ ...whoAmIResult,
258
+ credentialBundle: credentialBundle,
259
+ sessionExpiry: Date.now() + Number(expirationSeconds) * 1000,
260
+ };
261
+ await saveSession(readWriteSessionResultWithSession, this.authClient);
262
+ return true;
263
+ }
264
+ catch {
265
+ throw new Error("Unable to log in with the provided auth bundle.");
266
+ }
267
+ };
268
+ /**
269
+ * Removes authentication factors from an end user.
270
+ *
271
+ * This function allows selectively removing:
272
+ * - Phone number
273
+ * - Email
274
+ * - Authenticators (by ID)
275
+ * - OAuth providers (by ID)
276
+ * - API keys (by ID)
277
+ *
278
+ * All removal operations are executed in parallel if multiple
279
+ * parameters are provided.
280
+ *
281
+ * @param params - A structured object containing all the removal parameters
282
+ * @param params.userId - Unique identifier of the user
283
+ * @param params.phoneNumber - true to remove the phone number
284
+ * @param params.email - true to remove the email
285
+ * @param params.authenticatorIds - Array of authenticator IDs to remove
286
+ * @param params.oauthProviderIds - Array of OAuth provider IDs to remove
287
+ * @param params.apiKeyIds - Array of API key IDs to remove
288
+ * @returns A promise that resolves to an array of results from each removal operation
289
+ */
290
+ this.deleteUserAuth = async (params) => {
291
+ try {
292
+ const { userId, phoneNumber, email, authenticatorIds, oauthProviderIds, apiKeyIds, } = params;
293
+ const promises = [];
294
+ if (phoneNumber) {
295
+ promises.push(this.updateUser({ userId, userPhoneNumber: "", userTagIds: [] }));
296
+ }
297
+ if (email) {
298
+ promises.push(this.updateUser({ userId, userEmail: "", userTagIds: [] }));
299
+ }
300
+ if (authenticatorIds && authenticatorIds.length > 0) {
301
+ promises.push(this.deleteAuthenticators({ userId, authenticatorIds }));
302
+ }
303
+ if (oauthProviderIds && oauthProviderIds.length > 0) {
304
+ promises.push(this.deleteOauthProviders({ userId, providerIds: oauthProviderIds }));
305
+ }
306
+ if (apiKeyIds && apiKeyIds.length > 0) {
307
+ promises.push(this.deleteApiKeys({ userId, apiKeyIds }));
308
+ }
309
+ // Execute all removal operations in parallel
310
+ return await Promise.all(promises);
311
+ }
312
+ catch (error) {
313
+ // Surface error
314
+ throw error;
315
+ }
316
+ };
317
+ /**
318
+ * Adds or updates authentication factors for an end user.
319
+ *
320
+ * This function allows selectively adding:
321
+ * - Phone number
322
+ * - Email
323
+ * - Authenticators
324
+ * - OAuth providers
325
+ * - API keys
326
+ *
327
+ * All additions/updates are executed in parallel if multiple
328
+ * parameters are provided.
329
+ *
330
+ * @param params - A structured object containing all the addition/update parameters
331
+ * @param params.userId - Unique identifier of the user
332
+ * @param params.phoneNumber - New phone number for the user
333
+ * @param params.email - New email address for the user
334
+ * @param params.authenticators - Array of authenticator objects to create
335
+ * @param params.oauthProviders - Array of OAuth provider objects to create
336
+ * @param params.apiKeys - Array of API key objects to create
337
+ * @returns A promise that resolves to an array of results from each addition or update
338
+ */
339
+ this.addUserAuth = async (params) => {
340
+ try {
341
+ const { userId, phoneNumber, email, authenticators, oauthProviders, apiKeys, } = params;
342
+ const promises = [];
343
+ if (phoneNumber) {
344
+ promises.push(this.updateUser({
345
+ userId,
346
+ userPhoneNumber: phoneNumber,
347
+ userTagIds: [],
348
+ }));
349
+ }
350
+ if (email) {
351
+ promises.push(this.updateUser({ userId, userEmail: email, userTagIds: [] }));
352
+ }
353
+ if (authenticators && authenticators.length > 0) {
354
+ promises.push(this.createAuthenticators({ userId, authenticators }));
355
+ }
356
+ if (oauthProviders && oauthProviders.length > 0) {
357
+ promises.push(this.createOauthProviders({ userId, oauthProviders }));
358
+ }
359
+ if (apiKeys && apiKeys.length > 0) {
360
+ promises.push(this.createApiKeys({ userId, apiKeys }));
361
+ }
362
+ // Execute all additions/updates operations in parallel
363
+ return await Promise.all(promises);
364
+ }
365
+ catch (error) {
366
+ // Surface error
367
+ throw error;
368
+ }
369
+ };
370
+ }
371
+ /**
372
+ * Comprehensive authentication update for an end user.
373
+ * Combines add/update and delete operations into a single call.
374
+ *
375
+ * The behavior is driven by whether values are set to:
376
+ * - A string/array (to create or update)
377
+ * - `null` or an array of IDs (to remove)
378
+ *
379
+ * All operations are executed in parallel where applicable.
380
+ *
381
+ * @param params - A structured object containing all the update parameters
382
+ * @param params.userId - Unique identifier of the user
383
+ * @param params.phoneNumber - String to set (new phone) or `null` to remove
384
+ * @param params.email - String to set (new email) or `null` to remove
385
+ * @param params.authenticators - Object describing authenticators to add or remove
386
+ * @param params.oauthProviders - Object describing OAuth providers to add or remove
387
+ * @param params.apiKeys - Object describing API keys to add or remove
388
+ *
389
+ * @returns A promise that resolves to a boolean indicating overall success
390
+ */
391
+ async updateUserAuth(params) {
392
+ try {
393
+ const { userId, phoneNumber, email, authenticators, oauthProviders, apiKeys, } = params;
394
+ const promises = [];
395
+ // Handle phone/email in a single updateUser call if both are changing,
396
+ // or separate calls if only one is changing.
397
+ const userUpdates = {};
398
+ if (phoneNumber !== undefined) {
399
+ userUpdates.userPhoneNumber = phoneNumber === null ? "" : phoneNumber;
400
+ }
401
+ if (email !== undefined) {
402
+ userUpdates.userEmail = email === null ? "" : email;
403
+ }
404
+ if (Object.keys(userUpdates).length > 0) {
405
+ promises.push(this.updateUser({ userId, ...userUpdates, userTagIds: [] }));
406
+ }
407
+ // Handle authenticators
408
+ if (authenticators) {
409
+ if (authenticators.add?.length) {
410
+ promises.push(this.createAuthenticators({
411
+ userId,
412
+ authenticators: authenticators.add,
413
+ }));
414
+ }
415
+ if (authenticators.deleteIds?.length) {
416
+ promises.push(this.deleteAuthenticators({
417
+ userId,
418
+ authenticatorIds: authenticators.deleteIds,
419
+ }));
420
+ }
421
+ }
422
+ // Handle OAuth providers
423
+ if (oauthProviders) {
424
+ if (oauthProviders.add?.length) {
425
+ promises.push(this.createOauthProviders({
426
+ userId,
427
+ oauthProviders: oauthProviders.add,
428
+ }));
429
+ }
430
+ if (oauthProviders.deleteIds?.length) {
431
+ promises.push(this.deleteOauthProviders({
432
+ userId,
433
+ providerIds: oauthProviders.deleteIds,
434
+ }));
435
+ }
436
+ }
437
+ // Handle API keys
438
+ if (apiKeys) {
439
+ if (apiKeys.add?.length) {
440
+ promises.push(this.createApiKeys({
441
+ userId,
442
+ apiKeys: apiKeys.add,
443
+ }));
444
+ }
445
+ if (apiKeys.deleteIds?.length) {
446
+ promises.push(this.deleteApiKeys({
447
+ userId,
448
+ apiKeyIds: apiKeys.deleteIds,
449
+ }));
450
+ }
451
+ }
452
+ // Execute all requested operations in parallel
453
+ await Promise.all(promises);
454
+ return true;
455
+ }
456
+ catch (error) {
457
+ // Surface error
458
+ throw error;
459
+ }
460
+ }
461
+ }
462
+ class TurnkeyPasskeyClient extends TurnkeyBrowserClient {
463
+ constructor(config) {
464
+ super(config, AuthClient.Passkey);
465
+ /**
466
+ * Create a passkey for an end-user, taking care of various lower-level details.
467
+ *
468
+ * @returns {Promise<Passkey>}
469
+ */
470
+ this.createUserPasskey = async (config = {}) => {
471
+ const challenge = generateRandomBuffer();
472
+ const encodedChallenge = base64UrlEncode(challenge);
473
+ const authenticatorUserId = generateRandomBuffer();
474
+ // WebAuthn credential options options can be found here:
475
+ // https://www.w3.org/TR/webauthn-2/#sctn-sample-registration
476
+ //
477
+ // All pubkey algorithms can be found here: https://www.iana.org/assignments/cose/cose.xhtml#algorithms
478
+ // Turnkey only supports ES256 (-7) and RS256 (-257)
479
+ //
480
+ // The pubkey type only supports one value, "public-key"
481
+ // See https://www.w3.org/TR/webauthn-2/#enumdef-publickeycredentialtype for more details
482
+ // TODO: consider un-nesting these config params
483
+ const webauthnConfig = {
484
+ publicKey: {
485
+ rp: {
486
+ id: config.publicKey?.rp?.id ?? this.rpId,
487
+ name: config.publicKey?.rp?.name ?? "",
488
+ },
489
+ challenge: config.publicKey?.challenge ?? challenge,
490
+ pubKeyCredParams: config.publicKey?.pubKeyCredParams ?? [
491
+ {
492
+ type: "public-key",
493
+ alg: -7,
494
+ },
495
+ {
496
+ type: "public-key",
497
+ alg: -257,
498
+ },
499
+ ],
500
+ user: {
501
+ id: config.publicKey?.user?.id ?? authenticatorUserId,
502
+ name: config.publicKey?.user?.name ?? "Default User",
503
+ displayName: config.publicKey?.user?.displayName ?? "Default User",
504
+ },
505
+ authenticatorSelection: {
506
+ authenticatorAttachment: config.publicKey?.authenticatorSelection?.authenticatorAttachment ??
507
+ undefined,
508
+ requireResidentKey: config.publicKey?.authenticatorSelection?.requireResidentKey ??
509
+ true,
510
+ residentKey: config.publicKey?.authenticatorSelection?.residentKey ?? "required",
511
+ userVerification: config.publicKey?.authenticatorSelection?.userVerification ??
512
+ "preferred",
513
+ },
514
+ },
515
+ };
516
+ const attestation = await getWebAuthnAttestation(webauthnConfig);
517
+ return {
518
+ encodedChallenge: config.publicKey?.challenge
519
+ ? base64UrlEncode(config.publicKey?.challenge)
520
+ : encodedChallenge,
521
+ attestation,
522
+ };
523
+ };
524
+ /**
525
+ * Uses passkey authentication to create a read-write session, via an embedded API key,
526
+ * and stores + returns the resulting auth bundle that contains the encrypted API key.
527
+ * This auth bundle (also referred to as a credential bundle) can be injected into an `iframeStamper`,
528
+ * resulting in a touch-free authenticator. Unlike `loginWithReadWriteSession`, this method
529
+ * assumes the end-user's organization ID (i.e. the sub-organization ID) is already known.
530
+ *
531
+ * @param userId
532
+ * @param targetEmbeddedKey
533
+ * @param expirationSeconds
534
+ * @param curveType
535
+ * @returns {Promise<ReadWriteSession>}
536
+ */
537
+ this.createPasskeySession = async (userId, targetEmbeddedKey, expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, organizationId) => {
538
+ try {
539
+ const session = await getStorageValue(StorageKeys.Session);
540
+ organizationId = organizationId ?? session?.organizationId;
541
+ userId = userId ?? session?.userId;
542
+ if (!organizationId) {
543
+ throw new Error("Error creating passkey session: Organization ID is required");
544
+ }
545
+ if (!userId) {
546
+ throw new Error("Error creating passkey session: User ID is required");
547
+ }
548
+ const { authBundle: credentialBundle, publicKey } = await createEmbeddedAPIKey(targetEmbeddedKey);
549
+ // add API key to Turnkey User
550
+ await this.createApiKeys({
551
+ organizationId,
552
+ userId,
553
+ apiKeys: [
554
+ {
555
+ apiKeyName: `Session Key ${String(Date.now())}`,
556
+ publicKey,
557
+ expirationSeconds,
558
+ curveType: "API_KEY_CURVE_P256",
559
+ },
560
+ ],
561
+ });
562
+ const whoAmI = await this.getWhoami();
563
+ const expiry = Date.now() + Number(expirationSeconds) * 1000;
564
+ await saveSession({
565
+ organizationId,
566
+ organizationName: whoAmI?.organizationName ?? "",
567
+ userId,
568
+ username: whoAmI?.username ?? "",
569
+ credentialBundle,
570
+ sessionExpiry: expiry,
571
+ }, this.authClient);
572
+ return {
573
+ credentialBundle,
574
+ expiry,
575
+ };
576
+ }
577
+ catch (error) {
578
+ throw new Error("Unable to create passkey session.");
579
+ }
580
+ };
581
+ this.rpId = this.stamper.rpId;
582
+ }
583
+ }
584
+ /**
585
+ * TurnkeyIframeClient is a client that uses an iframe to interact with the Turnkey API.
586
+ * It is used to create read-write sessions, and to inject credential bundles into the iframe.
587
+ * It is also used to extract encrypted credential bundles from the iframe.
588
+ * @extends TurnkeyBrowserClient
589
+ */
590
+ class TurnkeyIframeClient extends TurnkeyBrowserClient {
591
+ constructor(config) {
592
+ super(config, AuthClient.Iframe);
593
+ this.injectCredentialBundle = async (credentialBundle) => {
594
+ return await this.stamper.injectCredentialBundle(credentialBundle);
595
+ };
596
+ this.injectWalletExportBundle = async (credentialBundle, organizationId) => {
597
+ return await this.stamper.injectWalletExportBundle(credentialBundle, organizationId);
598
+ };
599
+ this.injectKeyExportBundle = async (credentialBundle, organizationId, keyFormat) => {
600
+ return await this.stamper.injectKeyExportBundle(credentialBundle, organizationId, keyFormat);
601
+ };
602
+ this.injectImportBundle = async (bundle, organizationId, userId) => {
603
+ return await this.stamper.injectImportBundle(bundle, organizationId, userId);
604
+ };
605
+ this.extractWalletEncryptedBundle = async () => {
606
+ return await this.stamper.extractWalletEncryptedBundle();
607
+ };
608
+ this.extractKeyEncryptedBundle = async () => {
609
+ return await this.stamper.extractKeyEncryptedBundle();
610
+ };
611
+ this.iframePublicKey = this.stamper.iframePublicKey;
612
+ }
613
+ }
614
+ class TurnkeyWalletClient extends TurnkeyBrowserClient {
615
+ constructor(config) {
616
+ super(config, AuthClient.Wallet);
617
+ this.wallet = config.wallet;
618
+ }
619
+ async getPublicKey() {
620
+ return this.wallet.getPublicKey();
621
+ }
622
+ getWalletInterface() {
623
+ return this.wallet;
624
+ }
625
+ }
626
+
627
+ export { TurnkeyBrowserClient, TurnkeyIframeClient, TurnkeyPasskeyClient, TurnkeyWalletClient };
628
+ //# sourceMappingURL=browser-clients.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-clients.mjs","sources":["../../src/__clients__/browser-clients.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAmGM,MAAO,oBAAqB,SAAQ,iBAAiB,CAAA;IACzD,WAAY,CAAA,MAA8B,EAAE,UAAuB,EAAA;AACjE,QAAA,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAG5B,QAAA,IAAA,CAAA,KAAK,GAAG,OAAO,MAEd,KAAyD;YACxD,MAAM,qBAAqB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAC5D,MAAM,IAAI,EAAE,CACb,CAAC;YACF,MAAM,WAAW,CAAC,qBAAqB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAE1D,YAAA,OAAO,qBAAsB,CAAC;AAChC,SAAC,CAAC;AAEF;;;;;;;;;AASG;QACH,IAAe,CAAA,eAAA,GAAG,OAChB,WAA2B,GAAA,WAAW,CAAC,UAAU,EACjD,eAAwB;QACxB,iBAA4B,GAAA,qCAAqC,KAChD;YACjB,IAAI;AACF,gBAAA,IAAI,WAAW,KAAK,WAAW,CAAC,SAAS,EAAE;oBACzC,IAAI,IAAK,YAAY,oBAAoB,EAAE;AACzC,wBAAA,MAAM,IAAI,KAAK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