@account-kit/signer 4.0.0-beta.3 → 4.0.0-beta.5

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 (57) hide show
  1. package/dist/esm/base.d.ts +33 -1
  2. package/dist/esm/base.js +81 -7
  3. package/dist/esm/base.js.map +1 -1
  4. package/dist/esm/client/base.d.ts +28 -5
  5. package/dist/esm/client/base.js +25 -1
  6. package/dist/esm/client/base.js.map +1 -1
  7. package/dist/esm/client/index.d.ts +78 -5
  8. package/dist/esm/client/index.js +211 -6
  9. package/dist/esm/client/index.js.map +1 -1
  10. package/dist/esm/client/types.d.ts +25 -0
  11. package/dist/esm/client/types.js.map +1 -1
  12. package/dist/esm/oauth.d.ts +18 -0
  13. package/dist/esm/oauth.js +29 -0
  14. package/dist/esm/oauth.js.map +1 -0
  15. package/dist/esm/session/manager.d.ts +3 -2
  16. package/dist/esm/session/manager.js +28 -15
  17. package/dist/esm/session/manager.js.map +1 -1
  18. package/dist/esm/session/types.d.ts +1 -1
  19. package/dist/esm/session/types.js.map +1 -1
  20. package/dist/esm/signer.d.ts +39 -7
  21. package/dist/esm/signer.js.map +1 -1
  22. package/dist/esm/utils/typeAssertions.d.ts +1 -0
  23. package/dist/esm/utils/typeAssertions.js +4 -0
  24. package/dist/esm/utils/typeAssertions.js.map +1 -0
  25. package/dist/esm/version.d.ts +1 -1
  26. package/dist/esm/version.js +1 -1
  27. package/dist/esm/version.js.map +1 -1
  28. package/dist/types/base.d.ts +33 -1
  29. package/dist/types/base.d.ts.map +1 -1
  30. package/dist/types/client/base.d.ts +28 -5
  31. package/dist/types/client/base.d.ts.map +1 -1
  32. package/dist/types/client/index.d.ts +78 -5
  33. package/dist/types/client/index.d.ts.map +1 -1
  34. package/dist/types/client/types.d.ts +25 -0
  35. package/dist/types/client/types.d.ts.map +1 -1
  36. package/dist/types/oauth.d.ts +19 -0
  37. package/dist/types/oauth.d.ts.map +1 -0
  38. package/dist/types/session/manager.d.ts +3 -2
  39. package/dist/types/session/manager.d.ts.map +1 -1
  40. package/dist/types/session/types.d.ts +1 -1
  41. package/dist/types/session/types.d.ts.map +1 -1
  42. package/dist/types/signer.d.ts +39 -7
  43. package/dist/types/signer.d.ts.map +1 -1
  44. package/dist/types/utils/typeAssertions.d.ts +2 -0
  45. package/dist/types/utils/typeAssertions.d.ts.map +1 -0
  46. package/dist/types/version.d.ts +1 -1
  47. package/package.json +3 -3
  48. package/src/base.ts +80 -10
  49. package/src/client/base.ts +31 -3
  50. package/src/client/index.ts +244 -12
  51. package/src/client/types.ts +26 -0
  52. package/src/oauth.ts +38 -0
  53. package/src/session/manager.ts +45 -19
  54. package/src/session/types.ts +1 -1
  55. package/src/signer.ts +15 -1
  56. package/src/utils/typeAssertions.ts +3 -0
  57. package/src/version.ts +1 -1
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { BaseSignerClient } from "./base.js";
3
- import type { CreateAccountParams, CredentialCreationOptionOverrides, EmailAuthParams, ExportWalletParams, User } from "./types.js";
3
+ import type { AlchemySignerClientEvents, CreateAccountParams, CredentialCreationOptionOverrides, EmailAuthParams, ExportWalletParams, OauthConfig, User } from "./types.js";
4
+ import type { AuthParams } from "../signer.js";
4
5
  export declare const AlchemySignerClientParamsSchema: z.ZodObject<{
5
6
  connection: z.ZodUnion<[z.ZodObject<{
6
7
  rpcUrl: z.ZodOptional<z.ZodNever>;
@@ -63,6 +64,8 @@ export declare const AlchemySignerClientParamsSchema: z.ZodObject<{
63
64
  }>;
64
65
  rpId: z.ZodOptional<z.ZodString>;
65
66
  rootOrgId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
67
+ oauthCallbackUrl: z.ZodDefault<z.ZodOptional<z.ZodString>>;
68
+ enablePopupOauth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
66
69
  }, "strip", z.ZodTypeAny, {
67
70
  connection: {
68
71
  apiKey: string;
@@ -81,11 +84,13 @@ export declare const AlchemySignerClientParamsSchema: z.ZodObject<{
81
84
  jwt: string;
82
85
  apiKey?: undefined;
83
86
  };
84
- rootOrgId: string;
85
87
  iframeConfig: {
86
88
  iframeElementId: string;
87
89
  iframeContainerId: string;
88
90
  };
91
+ rootOrgId: string;
92
+ oauthCallbackUrl: string;
93
+ enablePopupOauth: boolean;
89
94
  rpId?: string | undefined;
90
95
  }, {
91
96
  connection: {
@@ -111,6 +116,8 @@ export declare const AlchemySignerClientParamsSchema: z.ZodObject<{
111
116
  };
112
117
  rpId?: string | undefined;
113
118
  rootOrgId?: string | undefined;
119
+ oauthCallbackUrl?: string | undefined;
120
+ enablePopupOauth?: boolean | undefined;
114
121
  }>;
115
122
  export type AlchemySignerClientParams = z.input<typeof AlchemySignerClientParamsSchema>;
116
123
  /**
@@ -120,6 +127,7 @@ export type AlchemySignerClientParams = z.input<typeof AlchemySignerClientParams
120
127
  export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams> {
121
128
  private iframeStamper;
122
129
  private webauthnStamper;
130
+ oauthCallbackUrl: string;
123
131
  iframeContainerId: string;
124
132
  /**
125
133
  * Initializes a new instance with the given parameters, setting up the connection, iframe configuration, and WebAuthn stamper.
@@ -195,7 +203,7 @@ export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalle
195
203
  orgId: string;
196
204
  }>;
197
205
  /**
198
- * Completes email auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.
206
+ * Completes auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.
199
207
  *
200
208
  * @example
201
209
  * ```ts
@@ -210,15 +218,16 @@ export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalle
210
218
  * },
211
219
  * });
212
220
  *
213
- * const account = await client.completeEmailAuth({ orgId: "user-org-id", bundle: "bundle-from-email" });
221
+ * const account = await client.completeAuthWithBundle({ orgId: "user-org-id", bundle: "bundle-from-email", connectedEventName: "connectedEmail" });
214
222
  * ```
215
223
  *
216
224
  * @param {{ bundle: string; orgId: string }} config The configuration object for the authentication function containing the credential bundle to inject and the organization id associated with the user
217
225
  * @returns {Promise<User>} A promise that resolves to the authenticated user information
218
226
  */
219
- completeEmailAuth: ({ bundle, orgId, }: {
227
+ completeAuthWithBundle: ({ bundle, orgId, connectedEventName, }: {
220
228
  bundle: string;
221
229
  orgId: string;
230
+ connectedEventName: keyof AlchemySignerClientEvents;
222
231
  }) => Promise<User>;
223
232
  /**
224
233
  * Asynchronously handles the authentication process using WebAuthn Stamper. If a user is provided, sets the user and returns it. Otherwise, retrieves the current user and initializes the WebAuthn stamper.
@@ -291,6 +300,68 @@ export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalle
291
300
  * ```
292
301
  */
293
302
  disconnect: () => Promise<void>;
303
+ /**
304
+ * Redirects the user to the OAuth provider URL based on the provided arguments. This function will always reject after 1 second if the redirection does not occur.
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * import { AlchemySignerWebClient } from "@account-kit/signer";
309
+ *
310
+ * const client = new AlchemySignerWebClient({
311
+ * connection: {
312
+ * apiKey: "your-api-key",
313
+ * },
314
+ * iframeConfig: {
315
+ * iframeContainerId: "signer-iframe-container",
316
+ * },
317
+ * });
318
+ *
319
+ * await client.oauthWithRedirect({
320
+ * type: "oauth",
321
+ * authProviderId: "google",
322
+ * mode: "redirect",
323
+ * redirectUrl: "/",
324
+ * });
325
+ * ```
326
+ *
327
+ * @param {Extract<AuthParams, { type: "oauth"; mode: "redirect" }>} args The arguments required to obtain the OAuth provider URL
328
+ * @returns {Promise<never>} A promise that will never resolve, only reject if the redirection fails
329
+ */
330
+ oauthWithRedirect: (args: Extract<AuthParams, {
331
+ type: "oauth";
332
+ mode: "redirect";
333
+ }>) => Promise<never>;
334
+ /**
335
+ * Initiates an OAuth authentication flow in a popup window and returns the authenticated user.
336
+ *
337
+ * @example
338
+ * ```ts
339
+ * import { AlchemySignerWebClient } from "@account-kit/signer";
340
+ *
341
+ * const client = new AlchemySignerWebClient({
342
+ * connection: {
343
+ * apiKey: "your-api-key",
344
+ * },
345
+ * iframeConfig: {
346
+ * iframeContainerId: "signer-iframe-container",
347
+ * },
348
+ * });
349
+ *
350
+ * const user = await client.oauthWithPopup({
351
+ * type: "oauth",
352
+ * authProviderId: "google",
353
+ * mode: "popup"
354
+ * });
355
+ * ```
356
+ *
357
+ * @param {Extract<AuthParams, { type: "oauth"; mode: "popup" }>} args The authentication parameters specifying OAuth type and popup mode
358
+ * @returns {Promise<User>} A promise that resolves to a `User` object containing the authenticated user information
359
+ */
360
+ oauthWithPopup: (args: Extract<AuthParams, {
361
+ type: "oauth";
362
+ mode: "popup";
363
+ }>) => Promise<User>;
364
+ private getOauthProviderUrl;
294
365
  private initIframeStamper;
295
366
  private initWebauthnStamper;
296
367
  protected getWebAuthnAttestation: (options?: CredentialCreationOptionOverrides, userDetails?: {
@@ -305,4 +376,6 @@ export declare class AlchemySignerWebClient extends BaseSignerClient<ExportWalle
305
376
  transports: ("AUTHENTICATOR_TRANSPORT_BLE" | "AUTHENTICATOR_TRANSPORT_INTERNAL" | "AUTHENTICATOR_TRANSPORT_NFC" | "AUTHENTICATOR_TRANSPORT_USB" | "AUTHENTICATOR_TRANSPORT_HYBRID")[];
306
377
  };
307
378
  }>;
379
+ protected getOauthConfig: () => Promise<OauthConfig>;
380
+ private getOauthConfigForMode;
308
381
  }
@@ -6,6 +6,8 @@ import { z } from "zod";
6
6
  import { base64UrlEncode } from "../utils/base64UrlEncode.js";
7
7
  import { generateRandomBuffer } from "../utils/generateRandomBuffer.js";
8
8
  import { BaseSignerClient } from "./base.js";
9
+ import { getDefaultScopeAndClaims, getOauthNonce } from "../oauth.js";
10
+ const CHECK_CLOSE_INTERVAL = 500;
9
11
  export const AlchemySignerClientParamsSchema = z.object({
10
12
  connection: ConnectionConfigSchema,
11
13
  iframeConfig: z.object({
@@ -17,6 +19,11 @@ export const AlchemySignerClientParamsSchema = z.object({
17
19
  .string()
18
20
  .optional()
19
21
  .default("24c1acf5-810f-41e0-a503-d5d13fa8e830"),
22
+ oauthCallbackUrl: z
23
+ .string()
24
+ .optional()
25
+ .default("https://signer.alchemy.com/callback"),
26
+ enablePopupOauth: z.boolean().optional().default(false),
20
27
  });
21
28
  /**
22
29
  * A lower level client used by the AlchemySigner used to communicate with
@@ -47,7 +54,7 @@ export class AlchemySignerWebClient extends BaseSignerClient {
47
54
  * @param {string} params.rootOrgId The root organization ID
48
55
  */
49
56
  constructor(params) {
50
- const { connection, iframeConfig, rpId, rootOrgId } = AlchemySignerClientParamsSchema.parse(params);
57
+ const { connection, iframeConfig, rpId, rootOrgId, oauthCallbackUrl } = AlchemySignerClientParamsSchema.parse(params);
51
58
  const iframeStamper = new IframeStamper({
52
59
  iframeElementId: iframeConfig.iframeElementId,
53
60
  iframeUrl: "https://auth.turnkey.com",
@@ -70,6 +77,12 @@ export class AlchemySignerWebClient extends BaseSignerClient {
70
77
  writable: true,
71
78
  value: void 0
72
79
  });
80
+ Object.defineProperty(this, "oauthCallbackUrl", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
73
86
  Object.defineProperty(this, "iframeContainerId", {
74
87
  enumerable: true,
75
88
  configurable: true,
@@ -175,7 +188,7 @@ export class AlchemySignerWebClient extends BaseSignerClient {
175
188
  }
176
189
  });
177
190
  /**
178
- * Completes email auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.
191
+ * Completes auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.
179
192
  *
180
193
  * @example
181
194
  * ```ts
@@ -190,17 +203,17 @@ export class AlchemySignerWebClient extends BaseSignerClient {
190
203
  * },
191
204
  * });
192
205
  *
193
- * const account = await client.completeEmailAuth({ orgId: "user-org-id", bundle: "bundle-from-email" });
206
+ * const account = await client.completeAuthWithBundle({ orgId: "user-org-id", bundle: "bundle-from-email", connectedEventName: "connectedEmail" });
194
207
  * ```
195
208
  *
196
209
  * @param {{ bundle: string; orgId: string }} config The configuration object for the authentication function containing the credential bundle to inject and the organization id associated with the user
197
210
  * @returns {Promise<User>} A promise that resolves to the authenticated user information
198
211
  */
199
- Object.defineProperty(this, "completeEmailAuth", {
212
+ Object.defineProperty(this, "completeAuthWithBundle", {
200
213
  enumerable: true,
201
214
  configurable: true,
202
215
  writable: true,
203
- value: async ({ bundle, orgId, }) => {
216
+ value: async ({ bundle, orgId, connectedEventName, }) => {
204
217
  this.eventEmitter.emit("authenticating");
205
218
  await this.initIframeStamper();
206
219
  const result = await this.iframeStamper.injectCredentialBundle(bundle);
@@ -208,7 +221,7 @@ export class AlchemySignerWebClient extends BaseSignerClient {
208
221
  throw new Error("Failed to inject credential bundle");
209
222
  }
210
223
  const user = await this.whoami(orgId);
211
- this.eventEmitter.emit("connectedEmail", user, bundle);
224
+ this.eventEmitter.emit(connectedEventName, user, bundle);
212
225
  return user;
213
226
  }
214
227
  });
@@ -329,6 +342,165 @@ export class AlchemySignerWebClient extends BaseSignerClient {
329
342
  this.iframeStamper.clear();
330
343
  }
331
344
  });
345
+ /**
346
+ * Redirects the user to the OAuth provider URL based on the provided arguments. This function will always reject after 1 second if the redirection does not occur.
347
+ *
348
+ * @example
349
+ * ```ts
350
+ * import { AlchemySignerWebClient } from "@account-kit/signer";
351
+ *
352
+ * const client = new AlchemySignerWebClient({
353
+ * connection: {
354
+ * apiKey: "your-api-key",
355
+ * },
356
+ * iframeConfig: {
357
+ * iframeContainerId: "signer-iframe-container",
358
+ * },
359
+ * });
360
+ *
361
+ * await client.oauthWithRedirect({
362
+ * type: "oauth",
363
+ * authProviderId: "google",
364
+ * mode: "redirect",
365
+ * redirectUrl: "/",
366
+ * });
367
+ * ```
368
+ *
369
+ * @param {Extract<AuthParams, { type: "oauth"; mode: "redirect" }>} args The arguments required to obtain the OAuth provider URL
370
+ * @returns {Promise<never>} A promise that will never resolve, only reject if the redirection fails
371
+ */
372
+ Object.defineProperty(this, "oauthWithRedirect", {
373
+ enumerable: true,
374
+ configurable: true,
375
+ writable: true,
376
+ value: async (args) => {
377
+ const providerUrl = await this.getOauthProviderUrl(args);
378
+ window.location.href = providerUrl;
379
+ return new Promise((_, reject) => setTimeout(() => reject("Failed to redirect to OAuth provider"), 1000));
380
+ }
381
+ });
382
+ /**
383
+ * Initiates an OAuth authentication flow in a popup window and returns the authenticated user.
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * import { AlchemySignerWebClient } from "@account-kit/signer";
388
+ *
389
+ * const client = new AlchemySignerWebClient({
390
+ * connection: {
391
+ * apiKey: "your-api-key",
392
+ * },
393
+ * iframeConfig: {
394
+ * iframeContainerId: "signer-iframe-container",
395
+ * },
396
+ * });
397
+ *
398
+ * const user = await client.oauthWithPopup({
399
+ * type: "oauth",
400
+ * authProviderId: "google",
401
+ * mode: "popup"
402
+ * });
403
+ * ```
404
+ *
405
+ * @param {Extract<AuthParams, { type: "oauth"; mode: "popup" }>} args The authentication parameters specifying OAuth type and popup mode
406
+ * @returns {Promise<User>} A promise that resolves to a `User` object containing the authenticated user information
407
+ */
408
+ Object.defineProperty(this, "oauthWithPopup", {
409
+ enumerable: true,
410
+ configurable: true,
411
+ writable: true,
412
+ value: async (args) => {
413
+ const providerUrl = await this.getOauthProviderUrl(args);
414
+ const popup = window.open(providerUrl, "_blank", "popup,width=500,height=600");
415
+ return new Promise((resolve, reject) => {
416
+ const handleMessage = (event) => {
417
+ if (!event.data) {
418
+ return;
419
+ }
420
+ const { alchemyBundle: bundle, alchemyOrgId: orgId } = event.data;
421
+ if (bundle && orgId) {
422
+ cleanup();
423
+ this.completeAuthWithBundle({
424
+ bundle,
425
+ orgId,
426
+ connectedEventName: "connectedOauth",
427
+ }).then(resolve, reject);
428
+ }
429
+ };
430
+ window.addEventListener("message", handleMessage);
431
+ const checkCloseIntervalId = setInterval(() => {
432
+ if (popup?.closed) {
433
+ cleanup();
434
+ reject(new Error("OAuth cancelled"));
435
+ }
436
+ }, CHECK_CLOSE_INTERVAL);
437
+ const cleanup = () => {
438
+ window.removeEventListener("message", handleMessage);
439
+ clearInterval(checkCloseIntervalId);
440
+ };
441
+ });
442
+ }
443
+ });
444
+ Object.defineProperty(this, "getOauthProviderUrl", {
445
+ enumerable: true,
446
+ configurable: true,
447
+ writable: true,
448
+ value: async (args) => {
449
+ const { authProviderId, isCustomProvider, scope: providedScope, claims: providedClaims, mode, redirectUrl, expirationSeconds, } = args;
450
+ const { codeChallenge, requestKey, authProviders } = await this.getOauthConfigForMode(mode);
451
+ const authProvider = authProviders.find((provider) => provider.id === authProviderId &&
452
+ !!provider.isCustomProvider === !!isCustomProvider);
453
+ if (!authProvider) {
454
+ throw new Error(`No auth provider found with id ${authProviderId}`);
455
+ }
456
+ let scope;
457
+ let claims;
458
+ if (providedScope) {
459
+ scope = providedScope;
460
+ claims = providedClaims;
461
+ }
462
+ else {
463
+ if (isCustomProvider) {
464
+ throw new Error("scope must be provided for a custom provider");
465
+ }
466
+ const scopeAndClaims = getDefaultScopeAndClaims(authProviderId);
467
+ if (!scopeAndClaims) {
468
+ throw new Error(`Default scope not known for provider ${authProviderId}`);
469
+ }
470
+ ({ scope, claims } = scopeAndClaims);
471
+ }
472
+ const { authEndpoint, clientId } = authProvider;
473
+ const turnkeyPublicKey = await this.initIframeStamper();
474
+ const nonce = getOauthNonce(turnkeyPublicKey);
475
+ const stateObject = {
476
+ authProviderId,
477
+ isCustomProvider,
478
+ requestKey,
479
+ turnkeyPublicKey,
480
+ expirationSeconds,
481
+ redirectUrl: mode === "redirect" ? resolveRelativeUrl(redirectUrl) : undefined,
482
+ openerOrigin: mode === "popup" ? window.location.origin : undefined,
483
+ };
484
+ const state = base64UrlEncode(new TextEncoder().encode(JSON.stringify(stateObject)));
485
+ const authUrl = new URL(authEndpoint);
486
+ const params = {
487
+ redirect_uri: this.oauthCallbackUrl,
488
+ response_type: "code",
489
+ scope,
490
+ state,
491
+ code_challenge: codeChallenge,
492
+ code_challenge_method: "S256",
493
+ prompt: "select_account",
494
+ client_id: clientId,
495
+ nonce,
496
+ };
497
+ if (claims) {
498
+ params.claims = claims;
499
+ }
500
+ authUrl.search = new URLSearchParams(params).toString();
501
+ return authUrl.toString();
502
+ }
503
+ });
332
504
  Object.defineProperty(this, "initIframeStamper", {
333
505
  enumerable: true,
334
506
  configurable: true,
@@ -412,11 +584,44 @@ export class AlchemySignerWebClient extends BaseSignerClient {
412
584
  return { challenge, authenticatorUserId, attestation };
413
585
  }
414
586
  });
587
+ Object.defineProperty(this, "getOauthConfig", {
588
+ enumerable: true,
589
+ configurable: true,
590
+ writable: true,
591
+ value: async () => {
592
+ const publicKey = await this.initIframeStamper();
593
+ const nonce = getOauthNonce(publicKey);
594
+ return this.request("/v1/prepare-oauth", { nonce });
595
+ }
596
+ });
597
+ Object.defineProperty(this, "getOauthConfigForMode", {
598
+ enumerable: true,
599
+ configurable: true,
600
+ writable: true,
601
+ value: async (mode) => {
602
+ if (this.oauthConfig) {
603
+ return this.oauthConfig;
604
+ }
605
+ else if (mode === "redirect") {
606
+ return this.initOauth();
607
+ }
608
+ else {
609
+ throw new Error("enablePopupOauth must be set in configuration or signer.preparePopupOauth must be called before using popup-based OAuth login");
610
+ }
611
+ }
612
+ });
415
613
  this.iframeStamper = iframeStamper;
416
614
  this.iframeContainerId = iframeConfig.iframeContainerId;
417
615
  this.webauthnStamper = new WebauthnStamper({
418
616
  rpId: rpId ?? window.location.hostname,
419
617
  });
618
+ this.oauthCallbackUrl = oauthCallbackUrl;
420
619
  }
421
620
  }
621
+ function resolveRelativeUrl(url) {
622
+ // Funny trick.
623
+ const a = document.createElement("a");
624
+ a.href = url;
625
+ return a.href;
626
+ }
422
627
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAy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CAAC;YACzD,CAAC;WAAC;QAvVA,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC,iBAAiB,CAAC;QAExD,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC;YACzC,IAAI,EAAE,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ;SACvC,CAAC,CAAC;IACL,CAAC;CAkVF","sourcesContent":["import { ConnectionConfigSchema } from \"@aa-sdk/core\";\nimport { getWebAuthnAttestation } from \"@turnkey/http\";\nimport { IframeStamper } from \"@turnkey/iframe-stamper\";\nimport { WebauthnStamper } from \"@turnkey/webauthn-stamper\";\nimport { z } from \"zod\";\nimport { base64UrlEncode } from \"../utils/base64UrlEncode.js\";\nimport { generateRandomBuffer } from \"../utils/generateRandomBuffer.js\";\nimport { BaseSignerClient } from \"./base.js\";\nimport type {\n CreateAccountParams,\n CredentialCreationOptionOverrides,\n EmailAuthParams,\n ExportWalletParams,\n User,\n} from \"./types.js\";\n\nexport const AlchemySignerClientParamsSchema = z.object({\n connection: ConnectionConfigSchema,\n iframeConfig: z.object({\n iframeElementId: z.string().default(\"turnkey-iframe\"),\n iframeContainerId: z.string(),\n }),\n rpId: z.string().optional(),\n rootOrgId: z\n .string()\n .optional()\n .default(\"24c1acf5-810f-41e0-a503-d5d13fa8e830\"),\n});\n\nexport type AlchemySignerClientParams = z.input<\n typeof AlchemySignerClientParamsSchema\n>;\n\n/**\n * A lower level client used by the AlchemySigner used to communicate with\n * Alchemy's signer service.\n */\nexport class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams> {\n private iframeStamper: IframeStamper;\n private webauthnStamper: WebauthnStamper;\n iframeContainerId: string;\n\n /**\n * Initializes a new instance with the given parameters, setting up the connection, iframe configuration, and WebAuthn stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n * ```\n *\n * @param {AlchemySignerClientParams} params the parameters required to initialize the client\n * @param {ConnectionConfig} params.connection The connection details needed to connect to the service\n * @param {{ iframeElementId?: string; iframeContainerId: string }} params.iframeConfig The configuration details for setting up the iframe stamper\n * @param {string} params.rpId The relying party ID, defaulting to the current hostname if not provided\n * @param {string} params.rootOrgId The root organization ID\n */\n constructor(params: AlchemySignerClientParams) {\n const { connection, iframeConfig, rpId, rootOrgId } =\n AlchemySignerClientParamsSchema.parse(params);\n\n const iframeStamper = new IframeStamper({\n iframeElementId: iframeConfig.iframeElementId,\n iframeUrl: \"https://auth.turnkey.com\",\n iframeContainer: document.getElementById(iframeConfig.iframeContainerId),\n });\n\n super({\n connection,\n rootOrgId,\n stamper: iframeStamper,\n });\n\n this.iframeStamper = iframeStamper;\n this.iframeContainerId = iframeConfig.iframeContainerId;\n\n this.webauthnStamper = new WebauthnStamper({\n rpId: rpId ?? window.location.hostname,\n });\n }\n\n /**\n * Authenticates the user by either email or passkey account creation flow. Emits events during the process.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.createAccount({ type: \"email\", email: \"you@mail.com\" });\n * ```\n *\n * @param {CreateAccountParams} params The parameters for creating an account, including the type (email or passkey) and additional details.\n * @returns {Promise<SignupResponse>} A promise that resolves with the response object containing the account creation result.\n */\n createAccount = async (params: CreateAccountParams) => {\n this.eventEmitter.emit(\"authenticating\");\n if (params.type === \"email\") {\n const { email, expirationSeconds } = params;\n const publicKey = await this.initIframeStamper();\n\n const response = await this.request(\"/v1/signup\", {\n email,\n targetPublicKey: publicKey,\n expirationSeconds,\n redirectParams: params.redirectParams?.toString(),\n });\n\n return response;\n }\n\n // Passkey account creation flow\n const { attestation, challenge } = await this.getWebAuthnAttestation(\n params.creationOpts,\n { username: \"email\" in params ? params.email : params.username }\n );\n\n const result = await this.request(\"/v1/signup\", {\n passkey: {\n challenge: base64UrlEncode(challenge),\n attestation,\n },\n email: \"email\" in params ? params.email : undefined,\n });\n\n this.user = {\n orgId: result.orgId,\n address: result.address!,\n userId: result.userId!,\n credentialId: attestation.credentialId,\n };\n this.initWebauthnStamper(this.user);\n this.eventEmitter.emit(\"connectedPasskey\", this.user);\n\n return result;\n };\n\n /**\n * Begin authenticating a user with their email and an expiration time for the authentication request. Initializes the iframe stamper to get the target public key.\n * This method sends an email to the user to complete their login\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.initEmailAuth({ email: \"you@mail.com\" });\n * ```\n *\n * @param {Omit<EmailAuthParams, \"targetPublicKey\">} params The parameters for email authentication, excluding the target public key\n * @returns {Promise<any>} The response from the authentication request\n */\n public initEmailAuth = async (\n params: Omit<EmailAuthParams, \"targetPublicKey\">\n ) => {\n this.eventEmitter.emit(\"authenticating\");\n const { email, expirationSeconds } = params;\n const publicKey = await this.initIframeStamper();\n\n return this.request(\"/v1/auth\", {\n email,\n targetPublicKey: publicKey,\n expirationSeconds,\n redirectParams: params.redirectParams?.toString(),\n });\n };\n\n /**\n * Completes email auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.completeEmailAuth({ orgId: \"user-org-id\", bundle: \"bundle-from-email\" });\n * ```\n *\n * @param {{ bundle: string; orgId: string }} config The configuration object for the authentication function containing the credential bundle to inject and the organization id associated with the user\n * @returns {Promise<User>} A promise that resolves to the authenticated user information\n */\n public completeEmailAuth = async ({\n bundle,\n orgId,\n }: {\n bundle: string;\n orgId: string;\n }) => {\n this.eventEmitter.emit(\"authenticating\");\n await this.initIframeStamper();\n\n const result = await this.iframeStamper.injectCredentialBundle(bundle);\n\n if (!result) {\n throw new Error(\"Failed to inject credential bundle\");\n }\n\n const user = await this.whoami(orgId);\n this.eventEmitter.emit(\"connectedEmail\", user, bundle);\n\n return user;\n };\n\n /**\n * Asynchronously handles the authentication process using WebAuthn Stamper. If a user is provided, sets the user and returns it. Otherwise, retrieves the current user and initializes the WebAuthn stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.lookupUserWithPasskey();\n * ```\n *\n * @param {User} [user] An optional user object to authenticate\n * @returns {Promise<User>} A promise that resolves to the authenticated user object\n */\n public lookupUserWithPasskey = async (user: User | undefined = undefined) => {\n this.eventEmitter.emit(\"authenticating\");\n await this.initWebauthnStamper(user);\n if (user) {\n this.user = user;\n return user;\n }\n\n const result = await this.whoami(this.rootOrg);\n await this.initWebauthnStamper(result);\n this.eventEmitter.emit(\"connectedPasskey\", result);\n\n return result;\n };\n\n /**\n * Initiates the export of a wallet by creating an iframe stamper and calling the appropriate export function.\n * The export can be based on a seed phrase or a private key.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.exportWallet({\n * iframeContainerId: \"export-iframe-container\",\n * });\n * ```\n *\n * @param {ExportWalletParams} config The parameters for exporting the wallet\n * @param {string} config.iframeContainerId The ID of the container element that will hold the iframe stamper\n * @param {string} [config.iframeElementId] Optional ID for the iframe element\n * @returns {Promise<void>} A promise that resolves when the export process is complete\n */\n public exportWallet = async ({\n iframeContainerId,\n iframeElementId = \"turnkey-export-iframe\",\n }: ExportWalletParams) => {\n const exportWalletIframeStamper = new IframeStamper({\n iframeContainer: document.getElementById(iframeContainerId),\n iframeElementId: iframeElementId,\n iframeUrl: \"https://export.turnkey.com\",\n });\n await exportWalletIframeStamper.init();\n\n if (this.turnkeyClient.stamper === this.iframeStamper) {\n return this.exportWalletInner({\n exportStamper: exportWalletIframeStamper,\n exportAs: \"SEED_PHRASE\",\n });\n }\n\n return this.exportWalletInner({\n exportStamper: exportWalletIframeStamper,\n exportAs: \"PRIVATE_KEY\",\n });\n };\n\n /**\n * Asynchronous function that clears the user and resets the iframe stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.disconnect();\n * ```\n */\n public disconnect = async () => {\n this.user = undefined;\n this.iframeStamper.clear();\n };\n\n private initIframeStamper = async () => {\n if (!this.iframeStamper.publicKey()) {\n await this.iframeStamper.init();\n }\n\n this.setStamper(this.iframeStamper);\n\n return this.iframeStamper.publicKey()!;\n };\n\n private initWebauthnStamper = async (user: User | undefined = this.user) => {\n this.setStamper(this.webauthnStamper);\n if (user && user.credentialId) {\n // The goal here is to allow us to cache the allowed credential, but this doesn't work with hybrid transport :(\n this.webauthnStamper.allowCredentials = [\n {\n id: Buffer.from(user.credentialId, \"base64\"),\n type: \"public-key\",\n transports: [\"internal\", \"hybrid\"],\n },\n ];\n }\n };\n\n protected getWebAuthnAttestation = async (\n options?: CredentialCreationOptionOverrides,\n userDetails: { username: string } = {\n username: this.user?.email ?? \"anonymous\",\n }\n ) => {\n const challenge = generateRandomBuffer();\n const authenticatorUserId = generateRandomBuffer();\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n ...options?.publicKey,\n authenticatorSelection: {\n residentKey: \"preferred\",\n requireResidentKey: false,\n userVerification: \"preferred\",\n ...options?.publicKey?.authenticatorSelection,\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\n ...options?.publicKey?.rp,\n },\n pubKeyCredParams: [\n {\n type: \"public-key\",\n alg: -7,\n },\n {\n type: \"public-key\",\n alg: -257,\n },\n ],\n user: {\n id: authenticatorUserId,\n name: userDetails.username,\n displayName: userDetails.username,\n ...options?.publicKey?.user,\n },\n },\n signal: options?.signal,\n });\n\n // on iOS sometimes this is returned as empty or null, so handling that here\n if (attestation.transports == null || attestation.transports.length === 0) {\n attestation.transports = [\n \"AUTHENTICATOR_TRANSPORT_INTERNAL\",\n \"AUTHENTICATOR_TRANSPORT_HYBRID\",\n ];\n }\n\n return { challenge, authenticatorUserId, attestation };\n };\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAW7C,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGtE,MAAM,oBAAoB,GAAG,GAAG,CAAC;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kBAAkB,CAAC,GAAW;IACrC,eAAe;IACf,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;IACb,OAAO,CAAC,CAAC,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { ConnectionConfigSchema } from \"@aa-sdk/core\";\nimport { getWebAuthnAttestation } from \"@turnkey/http\";\nimport { IframeStamper } from \"@turnkey/iframe-stamper\";\nimport { WebauthnStamper } from \"@turnkey/webauthn-stamper\";\nimport { z } from \"zod\";\nimport { base64UrlEncode } from \"../utils/base64UrlEncode.js\";\nimport { generateRandomBuffer } from \"../utils/generateRandomBuffer.js\";\nimport { BaseSignerClient } from \"./base.js\";\nimport type {\n AlchemySignerClientEvents,\n CreateAccountParams,\n CredentialCreationOptionOverrides,\n EmailAuthParams,\n ExportWalletParams,\n OauthConfig,\n OauthParams,\n User,\n} from \"./types.js\";\nimport { getDefaultScopeAndClaims, getOauthNonce } from \"../oauth.js\";\nimport type { AuthParams, OauthMode } from \"../signer.js\";\n\nconst CHECK_CLOSE_INTERVAL = 500;\n\nexport const AlchemySignerClientParamsSchema = z.object({\n connection: ConnectionConfigSchema,\n iframeConfig: z.object({\n iframeElementId: z.string().default(\"turnkey-iframe\"),\n iframeContainerId: z.string(),\n }),\n rpId: z.string().optional(),\n rootOrgId: z\n .string()\n .optional()\n .default(\"24c1acf5-810f-41e0-a503-d5d13fa8e830\"),\n oauthCallbackUrl: z\n .string()\n .optional()\n .default(\"https://signer.alchemy.com/callback\"),\n enablePopupOauth: z.boolean().optional().default(false),\n});\n\nexport type AlchemySignerClientParams = z.input<\n typeof AlchemySignerClientParamsSchema\n>;\n\ntype OauthState = {\n authProviderId: string;\n isCustomProvider?: boolean;\n requestKey: string;\n turnkeyPublicKey: string;\n expirationSeconds?: number;\n redirectUrl?: string;\n openerOrigin?: string;\n};\n\n/**\n * A lower level client used by the AlchemySigner used to communicate with\n * Alchemy's signer service.\n */\nexport class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams> {\n private iframeStamper: IframeStamper;\n private webauthnStamper: WebauthnStamper;\n oauthCallbackUrl: string;\n iframeContainerId: string;\n\n /**\n * Initializes a new instance with the given parameters, setting up the connection, iframe configuration, and WebAuthn stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n * ```\n *\n * @param {AlchemySignerClientParams} params the parameters required to initialize the client\n * @param {ConnectionConfig} params.connection The connection details needed to connect to the service\n * @param {{ iframeElementId?: string; iframeContainerId: string }} params.iframeConfig The configuration details for setting up the iframe stamper\n * @param {string} params.rpId The relying party ID, defaulting to the current hostname if not provided\n * @param {string} params.rootOrgId The root organization ID\n */\n constructor(params: AlchemySignerClientParams) {\n const { connection, iframeConfig, rpId, rootOrgId, oauthCallbackUrl } =\n AlchemySignerClientParamsSchema.parse(params);\n\n const iframeStamper = new IframeStamper({\n iframeElementId: iframeConfig.iframeElementId,\n iframeUrl: \"https://auth.turnkey.com\",\n iframeContainer: document.getElementById(iframeConfig.iframeContainerId),\n });\n\n super({\n connection,\n rootOrgId,\n stamper: iframeStamper,\n });\n\n this.iframeStamper = iframeStamper;\n this.iframeContainerId = iframeConfig.iframeContainerId;\n\n this.webauthnStamper = new WebauthnStamper({\n rpId: rpId ?? window.location.hostname,\n });\n\n this.oauthCallbackUrl = oauthCallbackUrl;\n }\n\n /**\n * Authenticates the user by either email or passkey account creation flow. Emits events during the process.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.createAccount({ type: \"email\", email: \"you@mail.com\" });\n * ```\n *\n * @param {CreateAccountParams} params The parameters for creating an account, including the type (email or passkey) and additional details.\n * @returns {Promise<SignupResponse>} A promise that resolves with the response object containing the account creation result.\n */\n public override createAccount = async (params: CreateAccountParams) => {\n this.eventEmitter.emit(\"authenticating\");\n if (params.type === \"email\") {\n const { email, expirationSeconds } = params;\n const publicKey = await this.initIframeStamper();\n\n const response = await this.request(\"/v1/signup\", {\n email,\n targetPublicKey: publicKey,\n expirationSeconds,\n redirectParams: params.redirectParams?.toString(),\n });\n\n return response;\n }\n\n // Passkey account creation flow\n const { attestation, challenge } = await this.getWebAuthnAttestation(\n params.creationOpts,\n { username: \"email\" in params ? params.email : params.username }\n );\n\n const result = await this.request(\"/v1/signup\", {\n passkey: {\n challenge: base64UrlEncode(challenge),\n attestation,\n },\n email: \"email\" in params ? params.email : undefined,\n });\n\n this.user = {\n orgId: result.orgId,\n address: result.address!,\n userId: result.userId!,\n credentialId: attestation.credentialId,\n };\n this.initWebauthnStamper(this.user);\n this.eventEmitter.emit(\"connectedPasskey\", this.user);\n\n return result;\n };\n\n /**\n * Begin authenticating a user with their email and an expiration time for the authentication request. Initializes the iframe stamper to get the target public key.\n * This method sends an email to the user to complete their login\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.initEmailAuth({ email: \"you@mail.com\" });\n * ```\n *\n * @param {Omit<EmailAuthParams, \"targetPublicKey\">} params The parameters for email authentication, excluding the target public key\n * @returns {Promise<any>} The response from the authentication request\n */\n public override initEmailAuth = async (\n params: Omit<EmailAuthParams, \"targetPublicKey\">\n ) => {\n this.eventEmitter.emit(\"authenticating\");\n const { email, expirationSeconds } = params;\n const publicKey = await this.initIframeStamper();\n\n return this.request(\"/v1/auth\", {\n email,\n targetPublicKey: publicKey,\n expirationSeconds,\n redirectParams: params.redirectParams?.toString(),\n });\n };\n\n /**\n * Completes auth for the user by injecting a credential bundle and retrieving the user information based on the provided organization ID. Emits events during the process.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.completeAuthWithBundle({ orgId: \"user-org-id\", bundle: \"bundle-from-email\", connectedEventName: \"connectedEmail\" });\n * ```\n *\n * @param {{ bundle: string; orgId: string }} config The configuration object for the authentication function containing the credential bundle to inject and the organization id associated with the user\n * @returns {Promise<User>} A promise that resolves to the authenticated user information\n */\n public override completeAuthWithBundle = async ({\n bundle,\n orgId,\n connectedEventName,\n }: {\n bundle: string;\n orgId: string;\n connectedEventName: keyof AlchemySignerClientEvents;\n }): Promise<User> => {\n this.eventEmitter.emit(\"authenticating\");\n await this.initIframeStamper();\n\n const result = await this.iframeStamper.injectCredentialBundle(bundle);\n\n if (!result) {\n throw new Error(\"Failed to inject credential bundle\");\n }\n\n const user = await this.whoami(orgId);\n this.eventEmitter.emit(connectedEventName, user, bundle);\n\n return user;\n };\n\n /**\n * Asynchronously handles the authentication process using WebAuthn Stamper. If a user is provided, sets the user and returns it. Otherwise, retrieves the current user and initializes the WebAuthn stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.lookupUserWithPasskey();\n * ```\n *\n * @param {User} [user] An optional user object to authenticate\n * @returns {Promise<User>} A promise that resolves to the authenticated user object\n */\n public override lookupUserWithPasskey = async (\n user: User | undefined = undefined\n ) => {\n this.eventEmitter.emit(\"authenticating\");\n await this.initWebauthnStamper(user);\n if (user) {\n this.user = user;\n return user;\n }\n\n const result = await this.whoami(this.rootOrg);\n await this.initWebauthnStamper(result);\n this.eventEmitter.emit(\"connectedPasskey\", result);\n\n return result;\n };\n\n /**\n * Initiates the export of a wallet by creating an iframe stamper and calling the appropriate export function.\n * The export can be based on a seed phrase or a private key.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.exportWallet({\n * iframeContainerId: \"export-iframe-container\",\n * });\n * ```\n *\n * @param {ExportWalletParams} config The parameters for exporting the wallet\n * @param {string} config.iframeContainerId The ID of the container element that will hold the iframe stamper\n * @param {string} [config.iframeElementId] Optional ID for the iframe element\n * @returns {Promise<void>} A promise that resolves when the export process is complete\n */\n public override exportWallet = async ({\n iframeContainerId,\n iframeElementId = \"turnkey-export-iframe\",\n }: ExportWalletParams) => {\n const exportWalletIframeStamper = new IframeStamper({\n iframeContainer: document.getElementById(iframeContainerId),\n iframeElementId: iframeElementId,\n iframeUrl: \"https://export.turnkey.com\",\n });\n await exportWalletIframeStamper.init();\n\n if (this.turnkeyClient.stamper === this.iframeStamper) {\n return this.exportWalletInner({\n exportStamper: exportWalletIframeStamper,\n exportAs: \"SEED_PHRASE\",\n });\n }\n\n return this.exportWalletInner({\n exportStamper: exportWalletIframeStamper,\n exportAs: \"PRIVATE_KEY\",\n });\n };\n\n /**\n * Asynchronous function that clears the user and resets the iframe stamper.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const account = await client.disconnect();\n * ```\n */\n public override disconnect = async () => {\n this.user = undefined;\n this.iframeStamper.clear();\n };\n\n /**\n * Redirects the user to the OAuth provider URL based on the provided arguments. This function will always reject after 1 second if the redirection does not occur.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * await client.oauthWithRedirect({\n * type: \"oauth\",\n * authProviderId: \"google\",\n * mode: \"redirect\",\n * redirectUrl: \"/\",\n * });\n * ```\n *\n * @param {Extract<AuthParams, { type: \"oauth\"; mode: \"redirect\" }>} args The arguments required to obtain the OAuth provider URL\n * @returns {Promise<never>} A promise that will never resolve, only reject if the redirection fails\n */\n public override oauthWithRedirect = async (\n args: Extract<AuthParams, { type: \"oauth\"; mode: \"redirect\" }>\n ): Promise<never> => {\n const providerUrl = await this.getOauthProviderUrl(args);\n window.location.href = providerUrl;\n return new Promise((_, reject) =>\n setTimeout(() => reject(\"Failed to redirect to OAuth provider\"), 1000)\n );\n };\n\n /**\n * Initiates an OAuth authentication flow in a popup window and returns the authenticated user.\n *\n * @example\n * ```ts\n * import { AlchemySignerWebClient } from \"@account-kit/signer\";\n *\n * const client = new AlchemySignerWebClient({\n * connection: {\n * apiKey: \"your-api-key\",\n * },\n * iframeConfig: {\n * iframeContainerId: \"signer-iframe-container\",\n * },\n * });\n *\n * const user = await client.oauthWithPopup({\n * type: \"oauth\",\n * authProviderId: \"google\",\n * mode: \"popup\"\n * });\n * ```\n *\n * @param {Extract<AuthParams, { type: \"oauth\"; mode: \"popup\" }>} args The authentication parameters specifying OAuth type and popup mode\n * @returns {Promise<User>} A promise that resolves to a `User` object containing the authenticated user information\n */\n public override oauthWithPopup = async (\n args: Extract<AuthParams, { type: \"oauth\"; mode: \"popup\" }>\n ): Promise<User> => {\n const providerUrl = await this.getOauthProviderUrl(args);\n const popup = window.open(\n providerUrl,\n \"_blank\",\n \"popup,width=500,height=600\"\n );\n return new Promise((resolve, reject) => {\n const handleMessage = (event: MessageEvent) => {\n if (!event.data) {\n return;\n }\n const { alchemyBundle: bundle, alchemyOrgId: orgId } = event.data;\n if (bundle && orgId) {\n cleanup();\n this.completeAuthWithBundle({\n bundle,\n orgId,\n connectedEventName: \"connectedOauth\",\n }).then(resolve, reject);\n }\n };\n\n window.addEventListener(\"message\", handleMessage);\n\n const checkCloseIntervalId = setInterval(() => {\n if (popup?.closed) {\n cleanup();\n reject(new Error(\"OAuth cancelled\"));\n }\n }, CHECK_CLOSE_INTERVAL);\n\n const cleanup = () => {\n window.removeEventListener(\"message\", handleMessage);\n clearInterval(checkCloseIntervalId);\n };\n });\n };\n\n private getOauthProviderUrl = async (args: OauthParams): Promise<string> => {\n const {\n authProviderId,\n isCustomProvider,\n scope: providedScope,\n claims: providedClaims,\n mode,\n redirectUrl,\n expirationSeconds,\n } = args;\n const { codeChallenge, requestKey, authProviders } =\n await this.getOauthConfigForMode(mode);\n const authProvider = authProviders.find(\n (provider) =>\n provider.id === authProviderId &&\n !!provider.isCustomProvider === !!isCustomProvider\n );\n if (!authProvider) {\n throw new Error(`No auth provider found with id ${authProviderId}`);\n }\n let scope: string;\n let claims: string | undefined;\n if (providedScope) {\n scope = providedScope;\n claims = providedClaims;\n } else {\n if (isCustomProvider) {\n throw new Error(\"scope must be provided for a custom provider\");\n }\n const scopeAndClaims = getDefaultScopeAndClaims(authProviderId);\n if (!scopeAndClaims) {\n throw new Error(\n `Default scope not known for provider ${authProviderId}`\n );\n }\n ({ scope, claims } = scopeAndClaims);\n }\n const { authEndpoint, clientId } = authProvider;\n const turnkeyPublicKey = await this.initIframeStamper();\n const nonce = getOauthNonce(turnkeyPublicKey);\n const stateObject: OauthState = {\n authProviderId,\n isCustomProvider,\n requestKey,\n turnkeyPublicKey,\n expirationSeconds,\n redirectUrl:\n mode === \"redirect\" ? resolveRelativeUrl(redirectUrl) : undefined,\n openerOrigin: mode === \"popup\" ? window.location.origin : undefined,\n };\n const state = base64UrlEncode(\n new TextEncoder().encode(JSON.stringify(stateObject))\n );\n const authUrl = new URL(authEndpoint);\n const params: Record<string, string> = {\n redirect_uri: this.oauthCallbackUrl,\n response_type: \"code\",\n scope,\n state,\n code_challenge: codeChallenge,\n code_challenge_method: \"S256\",\n prompt: \"select_account\",\n client_id: clientId,\n nonce,\n };\n if (claims) {\n params.claims = claims;\n }\n authUrl.search = new URLSearchParams(params).toString();\n return authUrl.toString();\n };\n\n private initIframeStamper = async () => {\n if (!this.iframeStamper.publicKey()) {\n await this.iframeStamper.init();\n }\n\n this.setStamper(this.iframeStamper);\n\n return this.iframeStamper.publicKey()!;\n };\n\n private initWebauthnStamper = async (user: User | undefined = this.user) => {\n this.setStamper(this.webauthnStamper);\n if (user && user.credentialId) {\n // The goal here is to allow us to cache the allowed credential, but this doesn't work with hybrid transport :(\n this.webauthnStamper.allowCredentials = [\n {\n id: Buffer.from(user.credentialId, \"base64\"),\n type: \"public-key\",\n transports: [\"internal\", \"hybrid\"],\n },\n ];\n }\n };\n\n protected override getWebAuthnAttestation = async (\n options?: CredentialCreationOptionOverrides,\n userDetails: { username: string } = {\n username: this.user?.email ?? \"anonymous\",\n }\n ) => {\n const challenge = generateRandomBuffer();\n const authenticatorUserId = generateRandomBuffer();\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n ...options?.publicKey,\n authenticatorSelection: {\n residentKey: \"preferred\",\n requireResidentKey: false,\n userVerification: \"preferred\",\n ...options?.publicKey?.authenticatorSelection,\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\n ...options?.publicKey?.rp,\n },\n pubKeyCredParams: [\n {\n type: \"public-key\",\n alg: -7,\n },\n {\n type: \"public-key\",\n alg: -257,\n },\n ],\n user: {\n id: authenticatorUserId,\n name: userDetails.username,\n displayName: userDetails.username,\n ...options?.publicKey?.user,\n },\n },\n signal: options?.signal,\n });\n\n // on iOS sometimes this is returned as empty or null, so handling that here\n if (attestation.transports == null || attestation.transports.length === 0) {\n attestation.transports = [\n \"AUTHENTICATOR_TRANSPORT_INTERNAL\",\n \"AUTHENTICATOR_TRANSPORT_HYBRID\",\n ];\n }\n\n return { challenge, authenticatorUserId, attestation };\n };\n\n protected override getOauthConfig = async (): Promise<OauthConfig> => {\n const publicKey = await this.initIframeStamper();\n const nonce = getOauthNonce(publicKey);\n return this.request(\"/v1/prepare-oauth\", { nonce });\n };\n\n private getOauthConfigForMode = async (\n mode: OauthMode\n ): Promise<OauthConfig> => {\n if (this.oauthConfig) {\n return this.oauthConfig;\n } else if (mode === \"redirect\") {\n return this.initOauth();\n } else {\n throw new Error(\n \"enablePopupOauth must be set in configuration or signer.preparePopupOauth must be called before using popup-based OAuth login\"\n );\n }\n };\n}\n\nfunction resolveRelativeUrl(url: string): string {\n // Funny trick.\n const a = document.createElement(\"a\");\n a.href = url;\n return a.href;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { Address } from "@aa-sdk/core";
2
2
  import type { TSignedRequest, getWebAuthnAttestation } from "@turnkey/http";
3
3
  import type { Hex } from "viem";
4
+ import type { AuthParams } from "../signer";
4
5
  export type CredentialCreationOptionOverrides = {
5
6
  publicKey?: Partial<CredentialCreationOptions["publicKey"]>;
6
7
  } & Pick<CredentialCreationOptions, "signal">;
@@ -35,11 +36,27 @@ export type EmailAuthParams = {
35
36
  targetPublicKey: string;
36
37
  redirectParams?: URLSearchParams;
37
38
  };
39
+ export type OauthParams = Extract<AuthParams, {
40
+ type: "oauth";
41
+ }> & {
42
+ expirationSeconds?: number;
43
+ };
38
44
  export type SignupResponse = {
39
45
  orgId: string;
40
46
  userId?: string;
41
47
  address?: Address;
42
48
  };
49
+ export type OauthConfig = {
50
+ codeChallenge: string;
51
+ requestKey: string;
52
+ authProviders: AuthProviderConfig[];
53
+ };
54
+ export type AuthProviderConfig = {
55
+ id: string;
56
+ isCustomProvider?: boolean;
57
+ clientId: string;
58
+ authEndpoint: string;
59
+ };
43
60
  export type SignerRoutes = SignerEndpoints[number]["Route"];
44
61
  export type SignerBody<T extends SignerRoutes> = Extract<SignerEndpoints[number], {
45
62
  Route: T;
@@ -93,6 +110,13 @@ export type SignerEndpoints = [
93
110
  Response: {
94
111
  signature: Hex;
95
112
  };
113
+ },
114
+ {
115
+ Route: "/v1/prepare-oauth";
116
+ Body: {
117
+ nonce: string;
118
+ };
119
+ Response: OauthConfig;
96
120
  }
97
121
  ];
98
122
  export type AlchemySignerClientEvents = {
@@ -100,6 +124,7 @@ export type AlchemySignerClientEvents = {
100
124
  authenticating(): void;
101
125
  connectedEmail(user: User, bundle: string): void;
102
126
  connectedPasskey(user: User): void;
127
+ connectedOauth(user: User, bundle: string): void;
103
128
  disconnected(): void;
104
129
  };
105
130
  export type AlchemySignerClientEvent = keyof AlchemySignerClientEvents;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Address } from \"@aa-sdk/core\";\nimport type { TSignedRequest, getWebAuthnAttestation } from \"@turnkey/http\";\nimport type { Hex } from \"viem\";\n\nexport type CredentialCreationOptionOverrides = {\n publicKey?: Partial<CredentialCreationOptions[\"publicKey\"]>;\n} & Pick<CredentialCreationOptions, \"signal\">;\n\n// [!region User]\nexport type User = {\n email?: string;\n orgId: string;\n userId: string;\n address: Address;\n credentialId?: string;\n};\n// [!endregion User]\n\nexport type ExportWalletParams = {\n iframeContainerId: string;\n iframeElementId?: string;\n};\n\nexport type CreateAccountParams =\n | {\n type: \"email\";\n email: string;\n expirationSeconds?: number;\n redirectParams?: URLSearchParams;\n }\n | {\n type: \"passkey\";\n email: string;\n creationOpts?: CredentialCreationOptionOverrides;\n }\n | {\n type: \"passkey\";\n username: string;\n creationOpts?: CredentialCreationOptionOverrides;\n };\n\nexport type EmailAuthParams = {\n email: string;\n expirationSeconds?: number;\n targetPublicKey: string;\n redirectParams?: URLSearchParams;\n};\n\nexport type SignupResponse = {\n orgId: string;\n userId?: string;\n address?: Address;\n};\n\nexport type SignerRoutes = SignerEndpoints[number][\"Route\"];\nexport type SignerBody<T extends SignerRoutes> = Extract<\n SignerEndpoints[number],\n { Route: T }\n>[\"Body\"];\nexport type SignerResponse<T extends SignerRoutes> = Extract<\n SignerEndpoints[number],\n { Route: T }\n>[\"Response\"];\n\nexport type SignerEndpoints = [\n {\n Route: \"/v1/signup\";\n Body:\n | (Omit<EmailAuthParams, \"redirectParams\"> & { redirectParams?: string })\n | {\n passkey: {\n challenge: string;\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;\n };\n };\n Response: SignupResponse;\n },\n {\n Route: \"/v1/whoami\";\n Body: {\n stampedRequest: TSignedRequest;\n };\n Response: User;\n },\n {\n Route: \"/v1/auth\";\n Body: Omit<EmailAuthParams, \"redirectParams\"> & { redirectParams?: string };\n Response: {\n orgId: string;\n };\n },\n {\n Route: \"/v1/lookup\";\n Body: {\n email: string;\n };\n Response: {\n orgId: string | null;\n };\n },\n {\n Route: \"/v1/sign-payload\";\n Body: {\n stampedRequest: TSignedRequest;\n };\n Response: {\n signature: Hex;\n };\n }\n];\n\nexport type AlchemySignerClientEvents = {\n connected(user: User): void;\n authenticating(): void;\n connectedEmail(user: User, bundle: string): void;\n connectedPasskey(user: User): void;\n disconnected(): void;\n};\n\nexport type AlchemySignerClientEvent = keyof AlchemySignerClientEvents;\n\nexport type GetWebAuthnAttestationResult = {\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;\n challenge: ArrayBuffer;\n authenticatorUserId: ArrayBuffer;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Address } from \"@aa-sdk/core\";\nimport type { TSignedRequest, getWebAuthnAttestation } from \"@turnkey/http\";\nimport type { Hex } from \"viem\";\nimport type { AuthParams } from \"../signer\";\n\nexport type CredentialCreationOptionOverrides = {\n publicKey?: Partial<CredentialCreationOptions[\"publicKey\"]>;\n} & Pick<CredentialCreationOptions, \"signal\">;\n\n// [!region User]\nexport type User = {\n email?: string;\n orgId: string;\n userId: string;\n address: Address;\n credentialId?: string;\n};\n// [!endregion User]\n\nexport type ExportWalletParams = {\n iframeContainerId: string;\n iframeElementId?: string;\n};\n\nexport type CreateAccountParams =\n | {\n type: \"email\";\n email: string;\n expirationSeconds?: number;\n redirectParams?: URLSearchParams;\n }\n | {\n type: \"passkey\";\n email: string;\n creationOpts?: CredentialCreationOptionOverrides;\n }\n | {\n type: \"passkey\";\n username: string;\n creationOpts?: CredentialCreationOptionOverrides;\n };\n\nexport type EmailAuthParams = {\n email: string;\n expirationSeconds?: number;\n targetPublicKey: string;\n redirectParams?: URLSearchParams;\n};\n\nexport type OauthParams = Extract<AuthParams, { type: \"oauth\" }> & {\n expirationSeconds?: number;\n};\n\nexport type SignupResponse = {\n orgId: string;\n userId?: string;\n address?: Address;\n};\n\nexport type OauthConfig = {\n codeChallenge: string;\n requestKey: string;\n authProviders: AuthProviderConfig[];\n};\n\nexport type AuthProviderConfig = {\n id: string;\n isCustomProvider?: boolean;\n clientId: string;\n authEndpoint: string;\n};\n\nexport type SignerRoutes = SignerEndpoints[number][\"Route\"];\nexport type SignerBody<T extends SignerRoutes> = Extract<\n SignerEndpoints[number],\n { Route: T }\n>[\"Body\"];\nexport type SignerResponse<T extends SignerRoutes> = Extract<\n SignerEndpoints[number],\n { Route: T }\n>[\"Response\"];\n\nexport type SignerEndpoints = [\n {\n Route: \"/v1/signup\";\n Body:\n | (Omit<EmailAuthParams, \"redirectParams\"> & { redirectParams?: string })\n | {\n passkey: {\n challenge: string;\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;\n };\n };\n Response: SignupResponse;\n },\n {\n Route: \"/v1/whoami\";\n Body: {\n stampedRequest: TSignedRequest;\n };\n Response: User;\n },\n {\n Route: \"/v1/auth\";\n Body: Omit<EmailAuthParams, \"redirectParams\"> & { redirectParams?: string };\n Response: {\n orgId: string;\n };\n },\n {\n Route: \"/v1/lookup\";\n Body: {\n email: string;\n };\n Response: {\n orgId: string | null;\n };\n },\n {\n Route: \"/v1/sign-payload\";\n Body: {\n stampedRequest: TSignedRequest;\n };\n Response: {\n signature: Hex;\n };\n },\n {\n Route: \"/v1/prepare-oauth\";\n Body: {\n nonce: string;\n };\n Response: OauthConfig;\n }\n];\n\nexport type AlchemySignerClientEvents = {\n connected(user: User): void;\n authenticating(): void;\n connectedEmail(user: User, bundle: string): void;\n connectedPasskey(user: User): void;\n connectedOauth(user: User, bundle: string): void;\n disconnected(): void;\n};\n\nexport type AlchemySignerClientEvent = keyof AlchemySignerClientEvents;\n\nexport type GetWebAuthnAttestationResult = {\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;\n challenge: ArrayBuffer;\n authenticatorUserId: ArrayBuffer;\n};\n"]}