@fourt/sdk 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,7 @@ yarn add @fourt/sdk
20
20
 
21
21
  ## Usage
22
22
 
23
- To initialize the SDK, you will need to pass your API key to the one of the **Signer** constructors. You will also be asked to provide additional options for authentication methods. As of now, the SDK only supports authentication through passkeys (see [Web Authentication](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API)) and email, and thus only `FourtWebSigner` is available.
23
+ To initialize the SDK, you will need to pass your API key to the one of the **Signer** constructors. You will also be asked to provide additional options for authentication methods. The SDK supports authentication through passkeys (see [Web Authentication](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API)), email, and oauth (using either Google, Apple or Facebook as providers).
24
24
 
25
25
  ```ts
26
26
  import { FourtWebSigner } from '@fourt/sdk'
package/dist/index.cjs CHANGED
@@ -28,11 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  FourtWebSigner: () => FourtWebSigner
34
34
  });
35
- module.exports = __toCommonJS(src_exports);
35
+ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/session/index.ts
38
38
  var import_zustand = require("zustand");
@@ -204,27 +204,6 @@ var PasskeysModule = class {
204
204
  // src/modules/auth/oauth/google.ts
205
205
  var jose = __toESM(require("jose"), 1);
206
206
  var import_sha = require("sha.js");
207
-
208
- // src/errors/SDKError.ts
209
- var SDKError = class extends Error {
210
- _props;
211
- constructor(message, props) {
212
- super(message);
213
- this._props = props;
214
- }
215
- get message() {
216
- return this._props.message;
217
- }
218
- };
219
-
220
- // src/errors/BadRequestError.ts
221
- var BadRequestError = class _BadRequestError extends SDKError {
222
- constructor(props) {
223
- super(_BadRequestError.name, props);
224
- }
225
- };
226
-
227
- // src/modules/auth/oauth/google.ts
228
207
  var GoogleModule = class {
229
208
  constructor(_webSignerClient) {
230
209
  this._webSignerClient = _webSignerClient;
@@ -234,16 +213,8 @@ var GoogleModule = class {
234
213
  * @returns
235
214
  */
236
215
  async init() {
237
- if (!this._webSignerClient.oauthConfiguration?.google) {
238
- throw new BadRequestError({ message: "Google OAuth is not configured" });
239
- }
240
- const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
241
- url.searchParams.set(
242
- "client_id",
243
- this._webSignerClient.oauthConfiguration.google.id
244
- );
245
- url.searchParams.set("response_type", "code");
246
- url.searchParams.set("scope", "openid email");
216
+ const initUrl = await this._webSignerClient.getOAuthInitUrl("google");
217
+ const url = new URL(initUrl);
247
218
  const internalUrl = new URL(
248
219
  "v1/oauth",
249
220
  this._webSignerClient.configuration.apiUrl
@@ -265,6 +236,25 @@ var GoogleModule = class {
265
236
  }
266
237
  };
267
238
 
239
+ // src/errors/SDKError.ts
240
+ var SDKError = class extends Error {
241
+ _props;
242
+ constructor(message, props) {
243
+ super(message);
244
+ this._props = props;
245
+ }
246
+ get message() {
247
+ return this._props.message;
248
+ }
249
+ };
250
+
251
+ // src/errors/BadRequestError.ts
252
+ var BadRequestError = class _BadRequestError extends SDKError {
253
+ constructor(props) {
254
+ super(_BadRequestError.name, props);
255
+ }
256
+ };
257
+
268
258
  // src/modules/auth/oauth/facebook.ts
269
259
  var jose2 = __toESM(require("jose"), 1);
270
260
  var FacebookModule = class {
@@ -272,9 +262,6 @@ var FacebookModule = class {
272
262
  this._webSignerClient = _webSignerClient;
273
263
  }
274
264
  async init() {
275
- if (!this._webSignerClient.oauthConfiguration?.facebook) {
276
- throw new BadRequestError({ message: "Facebook OAuth is not configured" });
277
- }
278
265
  const publicKey = await this._webSignerClient.getIframePublicKey();
279
266
  const internalUrl = new URL(
280
267
  "v1/oauth",
@@ -322,21 +309,8 @@ var AppleModule = class {
322
309
  * @returns
323
310
  */
324
311
  async init() {
325
- if (!this._webSignerClient.oauthConfiguration?.apple) {
326
- throw new BadRequestError({ message: "Apple OAuth is not configured" });
327
- }
328
- const url = new URL("https://appleid.apple.com/auth/authorize");
329
- url.searchParams.set(
330
- "client_id",
331
- this._webSignerClient.oauthConfiguration.apple.id
332
- );
333
- url.searchParams.set("response_type", "code");
334
- url.searchParams.set("response_mode", "form_post");
335
- url.searchParams.set("scope", "email");
336
- console.log(
337
- "Apple OAuth initialization started",
338
- this._webSignerClient.oauthConfiguration.common.redirectUrl
339
- );
312
+ const initUrl = await this._webSignerClient.getOAuthInitUrl("apple");
313
+ const url = new URL(initUrl);
340
314
  const internalUrl = new URL(
341
315
  "v1/oauth/apple",
342
316
  this._webSignerClient.configuration.apiUrl
@@ -515,7 +489,8 @@ var ROUTE_METHOD_MAP = {
515
489
  "/v1/email-auth": "POST",
516
490
  "/v1/lookup": "POST",
517
491
  "/v1/signin": "POST",
518
- "/v1/sign": "POST"
492
+ "/v1/sign": "POST",
493
+ "v1/oauth/init": "POST"
519
494
  };
520
495
 
521
496
  // src/signer/index.ts
@@ -922,6 +897,17 @@ var WebSignerClient = class extends SignerClient {
922
897
  this.stamper = this._stampers.iframe;
923
898
  return this._stampers.iframe.publicKey();
924
899
  }
900
+ /**
901
+ * Get the pre-filled URL for initiating oauth with a specific provider.
902
+ *
903
+ * @param {string} provider provider for which we are getting the URL, currently google or apple
904
+ */
905
+ async getOAuthInitUrl(provider) {
906
+ const { url } = await this.request("v1/oauth/init", {
907
+ provider
908
+ });
909
+ return url;
910
+ }
925
911
  };
926
912
 
927
913
  // src/third-party/viem.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/session/index.ts","../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/errors/SDKError.ts","../src/errors/BadRequestError.ts","../src/modules/auth/oauth/facebook.ts","../src/modules/auth/oauth/apple.ts","../src/modules/auth/oauth.ts","../src/modules/auth/index.ts","../src/modules/user/index.ts","../src/signer/web.ts","../src/lib/base64.ts","../src/lib/bytes.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/GenericError.ts","../src/errors/UnauthenticatedError.ts","../src/types/Routes.ts","../src/third-party/viem.ts"],"sourcesContent":["import { AuthModule, UserModule } from './modules/index.js'\nimport { SignerClientConstructorParams } from './signer/index.js'\nimport {\n WebSignerClient,\n WebSignerClientConstructorParams,\n} from './signer/web.js'\nimport { ViemModule } from './third-party/viem.js'\n\ntype FourtWebSignerConstructorParams = {\n configuration: SignerClientConstructorParams['configuration']\n auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'iframe' | 'oauth'>\n}\n\n/**\n * A client for interacting with the Fourt Web Signer.\n */\nclass FourtWebSigner {\n private readonly _webSignerClient: WebSignerClient\n private readonly _modules: {\n viem: ViemModule\n auth: AuthModule\n user: UserModule\n }\n\n /**\n * Initializes a new instance of the `FourtWebSigner` class.\n * Sets up the underlying modules.\n *\n *\n * @example\n * ```ts\n * const fourtWebSigner = new FourtWebSigner({\n * auth: {\n * webauthn: {\n * rpId: 'localhost',\n * },\n * },\n * configuration: {\n * apiKey: '927d603c-6775-4210-8e13-8904ca985e78',\n * },\n * })\n * ```\n *\n * @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client\n */\n constructor({\n configuration,\n auth: { webauthn, iframe, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\n iframe,\n oauth,\n })\n\n this._modules = {\n viem: new ViemModule(this._webSignerClient),\n auth: new AuthModule(this._webSignerClient),\n user: new UserModule(this._webSignerClient),\n }\n }\n\n /**\n * A module for interacting with the Viem library.\n */\n get viem() {\n return this._modules.viem\n }\n\n /**\n * A module for interacting with the authentication methods.\n */\n get auth() {\n return this._modules.auth\n }\n\n /**\n * A module for interacting with the user methods.\n */\n get user() {\n return this._modules.user\n }\n}\n\nexport { FourtWebSigner }\n","import { createStore, type StoreApi } from 'zustand'\nimport { createJSONStorage, persist } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\n/**\n * The state of the session.\n */\ntype SessionState = {\n type?: SessionType\n user?: User\n expirationDate?: Date\n bundle?: string\n token?: string\n}\n\n/**\n * A store for the session state.\n */\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n /**\n * Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.\n */\n constructor() {\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt.io-signer-session',\n storage: createJSONStorage<SessionState>(() => localStorage),\n }),\n )\n }\n\n /**\n * Gets the type from the session state.\n *\n * @returns {SessionType | undefined} the type.\n */\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n /**\n * Sets the type in the session state.\n *\n * @param {SessionType} type the type to set.\n */\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n /**\n * Gets the token from the session state.\n *\n * @returns {string | undefined} the token.\n */\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n /**\n * Sets the token in the session state.\n *\n * @param {string} token the token to set.\n */\n set token(token: string) {\n this._store.setState({ token })\n }\n\n /**\n * Gets the bundle from the session state.\n *\n * @returns {string | undefined} the bundle.\n */\n get bundle(): string | undefined {\n return this._store.getState().bundle\n }\n\n /**\n * Sets the bundle in the session state.\n *\n * @param {string} bundle the bundle to set.\n */\n set bundle(bundle: string) {\n this._store.setState({ bundle })\n }\n\n /**\n * Gets the user from the session state.\n *\n * @returns {User | undefined} the user.\n */\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n /**\n * Sets the user in the session state.\n *\n * @param {User} user the user to set.\n */\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n /**\n * Clears the user from the session state.\n */\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n /**\n * Clears the bundle from the session state.\n */\n clearBundle() {\n this._store.setState({ ...this._store.getState(), bundle: undefined })\n }\n\n /**\n * Clears the type from the session state.\n */\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n /**\n * Clears the token from the session state.\n */\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n /**\n * Clears the token and user from the session state.\n */\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearBundle()\n this.clearType()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n bundle: undefined,\n token: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { SessionType } from '../../session/index.js'\nimport type {\n WebSignerClient,\n EmailInitializeAuthParams,\n CompleteAuthWithBundleParams,\n} from '../../signer/web.js'\n\n/**\n * A module for interacting with the Email authentication methods.\n * Available through the `auth.email` property on a `FourtWebSigner` instance.\n */\nclass EmailModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Initialize user authentication process using email.\n *\n * @param params {EmailInitializeAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves to the result of the authentication process.\n */\n async initialize(params: EmailInitializeAuthParams): Promise<void> {\n return this._webSignerClient.emailAuth(params)\n }\n\n /**\n * Completes authentication with bundle after user receives the bundle and subOrgId as URL params.\n *\n * @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(\n params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>,\n ): Promise<void> {\n return this._webSignerClient.completeAuthWithBundle({\n ...params,\n sessionType: SessionType.Email,\n })\n }\n}\n\nexport { EmailModule }\n","import type { WebSignerClient, WebauthnSignInParams } from '../../signer/web.js'\n\n/**\n * A module for interacting with the Passkeys authentication methods.\n * Available through the `auth.passkeys` property on a `FourtWebSigner` instance.\n */\nclass PasskeysModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Signs in a user using Passkeys.\n *\n * @param params {WebauthnSignInParams} params for the sign-in process.\n * @returns {Promise<void>} promise that resolves to the result of the sign-in process.\n */\n async signIn(params: WebauthnSignInParams) {\n return this._webSignerClient.webauthnSignIn(params)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { BadRequestError } from '../../../errors/BadRequestError.js'\n\ntype CompleteParams = {\n credentialBundle: string\n subOrgId: string\n}\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n if (!this._webSignerClient.oauthConfiguration?.google) {\n throw new BadRequestError({ message: 'Google OAuth is not configured' })\n }\n\n const url = new URL('https://accounts.google.com/o/oauth2/v2/auth')\n url.searchParams.set(\n 'client_id',\n this._webSignerClient.oauthConfiguration.google.id,\n )\n url.searchParams.set('response_type', 'code')\n url.searchParams.set('scope', 'openid email')\n\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'google',\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { GoogleModule }\n","type SDKErrorProps = {\n message: string\n}\n\nabstract class SDKError extends Error {\n private readonly _props: SDKErrorProps\n\n constructor(message: string, props: SDKErrorProps) {\n super(message)\n this._props = props\n }\n\n get message() {\n return this._props.message\n }\n}\n\nexport { SDKError }\nexport type { SDKErrorProps }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass BadRequestError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(BadRequestError.name, props)\n }\n}\n\nexport { BadRequestError }\n","import { BadRequestError } from '../../../errors/BadRequestError.js'\nimport { WebSignerClient } from '../../../signer/web.js'\nimport * as jose from 'jose'\n\nclass FacebookModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n if (!this._webSignerClient.oauthConfiguration?.facebook) {\n throw new BadRequestError({ message: 'Facebook OAuth is not configured' })\n }\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n\n const jwt = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'facebook',\n }).encode()\n\n const response = await fetch(internalUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n state: jwt,\n }),\n })\n\n if (!response.ok) {\n throw new BadRequestError({\n message: `Failed to create OAuth state. Error: ${response.statusText}`,\n })\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError({\n message: response.statusText,\n })\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { BadRequestError } from '../../../errors/BadRequestError.js'\n\ntype CompleteParams = {\n credentialBundle: string\n subOrgId: string\n}\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n if (!this._webSignerClient.oauthConfiguration?.apple) {\n throw new BadRequestError({ message: 'Apple OAuth is not configured' })\n }\n\n const url = new URL('https://appleid.apple.com/auth/authorize')\n url.searchParams.set(\n 'client_id',\n this._webSignerClient.oauthConfiguration.apple.id,\n )\n url.searchParams.set('response_type', 'code')\n url.searchParams.set('response_mode', 'form_post')\n url.searchParams.set('scope', 'email')\n\n console.log(\n 'Apple OAuth initialization started',\n this._webSignerClient.oauthConfiguration.common.redirectUrl,\n )\n\n const internalUrl = new URL(\n 'v1/oauth/apple',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { AppleModule }\n","import { SessionType } from '../../session/index.js'\nimport type { WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\ntype CompleteParams = {\n bundle: string\n subOrgId: string\n}\n\nclass OAuthModule {\n private readonly _googleModule: GoogleModule\n private readonly _facebookModule: FacebookModule\n private readonly _appleModule: AppleModule\n\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._googleModule = new GoogleModule(this._webSignerClient)\n this._facebookModule = new FacebookModule(this._webSignerClient)\n this._appleModule = new AppleModule(this._webSignerClient)\n }\n\n get google() {\n return this._googleModule\n }\n\n get facebook() {\n return this._facebookModule\n }\n\n get apple() {\n return this._appleModule\n }\n\n async complete({ bundle, subOrgId }: CompleteParams) {\n await this._webSignerClient.completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType: SessionType.OAuth,\n })\n }\n}\n\nexport { OAuthModule }\n","import type { WebSignerClient } from '../../signer/web.js'\nimport { EmailModule } from './email.js'\nimport { PasskeysModule } from './passkeys.js'\nimport { OAuthModule } from './oauth.js'\n\n/**\n * A module for interacting with the authentication methods.\n * Available through the `auth` property on a `FourtWebSigner` instance.\n */\nclass AuthModule {\n private readonly _passkeys: PasskeysModule\n private readonly _email: EmailModule\n private readonly _oauth: OAuthModule\n\n /**\n * Initializes a new instance of the `AuthModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._passkeys = new PasskeysModule(this._webSignerClient)\n this._email = new EmailModule(this._webSignerClient)\n this._oauth = new OAuthModule(this._webSignerClient)\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get passkeys() {\n return this._passkeys\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get email() {\n return this._email\n }\n\n get oauth() {\n return this._oauth\n }\n}\n\nexport { AuthModule }\nexport { PasskeysModule } from './passkeys.js'\nexport { EmailModule } from './email.js'\n","import { WebSignerClient } from '../../signer/web.js'\nimport { User } from '../../types/entities.js'\n\n/**\n * A module for interacting with the user methods.\n * Available through the `user` property on a `FourtWebSigner` instance.\n */\nclass UserModule {\n /**\n * Initializes a new instance of the `UserModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Gets the user information.\n *\n * @returns {User | undefined} user information.\n */\n get info() {\n return this._webSignerClient.user\n }\n\n /**\n * Logs out the user.\n *\n * @returns {void}\n */\n logout() {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\nimport { IframeStamper } from '@turnkey/iframe-stamper'\nimport { WebauthnStamper } from '@turnkey/webauthn-stamper'\nimport { LibBase64 } from '../lib/base64.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { SessionType } from '../session/index.js'\nimport {\n type SignerClientInheritedConstructorParams,\n SignerClient,\n} from './index.js'\n\ntype WebauthnSignInParams = {\n email: string\n}\n\n// * When user starts auth with email - can be either a signup or a signin\ntype EmailInitializeAuthParams = {\n email: string\n redirectUrl: string\n expirationSeconds?: number // Defaults to 15 minutes by Turnkey\n}\n\n// * When user completes auth with bundle\ntype CompleteAuthWithBundleParams = {\n bundle: string\n subOrgId: string\n sessionType: SessionType\n isNewUser?: boolean\n}\n\ntype GoogleOAuthSignInParams = {\n credential: string\n clientId: string\n}\n\nexport type OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n google?: {\n id: string\n }\n facebook?: {\n id: string\n }\n apple?: {\n id: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n iframe?: {\n iframeElementId?: string\n iframeContainerId?: string\n }\n oauth?: OAuthConfiguration\n}>\n\ntype CreateAccountParams =\n | ({\n method: 'webauthn'\n } & WebauthnSignInParams)\n | ({\n method: 'email'\n } & EmailInitializeAuthParams)\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private readonly _stampers: {\n webauthn: WebauthnStamper\n iframe: IframeStamper\n }\n\n readonly oauthConfiguration: WebSignerClientConstructorParams['oauth']\n\n /**\n * Initializes a new instance of the `WebSignerClient` class.\n *\n * @param {WebSignerClientConstructorParams} params params for the constructor\n */\n constructor({\n configuration,\n webauthn,\n iframe,\n oauth,\n }: WebSignerClientConstructorParams) {\n const iframeContainerId =\n iframe?.iframeContainerId ?? 'fourt-signer-iframe-container'\n const iframeContainer = document.createElement('div')\n iframeContainer.id = iframeContainerId\n iframeContainer.style.display = 'none'\n document.body.appendChild(iframeContainer)\n\n const webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n const iframeStamper = new IframeStamper({\n iframeUrl: 'https://auth.turnkey.com',\n iframeElementId: iframe?.iframeElementId ?? 'turnkey-iframe',\n iframeContainer: document.getElementById(iframeContainerId),\n })\n\n super({\n stamper: iframeStamper, // Initialized to iframeStamper; can be either webauthnStamper or iframeStamper\n configuration: configuration,\n })\n\n this._stampers = {\n webauthn: webauthnStamper,\n iframe: iframeStamper,\n }\n\n this.oauthConfiguration = oauth\n }\n\n public override async signRawMessage<Into extends string>(\n msg: string,\n ): Promise<Into> {\n await this.updateStamper()\n return super.signRawMessage(msg)\n }\n\n public override async logout() {\n this._stampers.iframe.clear()\n await this._stampers.iframe.init()\n return super.logout()\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n *\n */\n private async updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n (this._sessionStore.bundle === undefined ||\n this._sessionStore.token === undefined)\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this._stampers.webauthn\n } else {\n this.stamper = this._stampers.iframe\n // We need to inject to inject the credential bundle\n // Otherwise the user will not be able to sign\n await this.completeAuthWithBundle({\n bundle: this._sessionStore.bundle!,\n subOrgId: this.user?.subOrgId!,\n sessionType: this._sessionStore.type!,\n })\n }\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {WebauthnSignInParams} params params for the sign in\n */\n async webauthnSignIn({ email }: WebauthnSignInParams) {\n const existingUserSubOrgId = await this.lookUpUser(email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'webauthn', email })\n } else {\n this.stamper = this._stampers.webauthn\n await this.whoAmI(existingUserSubOrgId)\n\n this._sessionStore.type = SessionType.Passkeys\n\n // We should assure that the user and its credentialId are set\n if (!this.user || !this.user.credentialId) {\n return\n }\n\n this._stampers.webauthn.allowCredentials = [\n {\n id: LibBase64.toBuffer(this.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handle auth user process with email.\n *\n * @param {EmailInitializeAuthParams} params Params needed for the initialization of the auth process\n */\n async emailAuth(params: EmailInitializeAuthParams) {\n const existingUserSubOrgId = await this.lookUpUser(params.email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'email', ...params })\n } else {\n await this._signInWithEmail(params)\n }\n }\n\n async getIframePublicKey() {\n return await this._initIframeStamper()\n }\n\n /**\n * Signs in a user with email.\n *\n * @param {EmailInitializeAuthParams} params params for the sign in\n */\n private async _signInWithEmail({\n email,\n expirationSeconds,\n redirectUrl,\n }: EmailInitializeAuthParams) {\n return this.request('/v1/email-auth', {\n email,\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n })\n }\n\n /**\n * Completes the authentication process with a credential bundle.\n *\n * @param {CompleteAuthWithBundleParams} params params for the completion of the auth process\n */\n public async completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType,\n }: CompleteAuthWithBundleParams): Promise<void> {\n await this._initIframeStamper()\n\n const result = await this._stampers.iframe.injectCredentialBundle(bundle)\n\n if (!result) {\n throw new Error('Failed to inject credential bundle')\n }\n\n await this.whoAmI(subOrgId)\n\n this._sessionStore.type = sessionType\n this._sessionStore.bundle = bundle\n }\n\n /**\n * Creates a passkey account using the webauthn stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'webauthn' }>} params params for the creation of the account\n */\n private async _createWebauthnAccount(\n params: Extract<CreateAccountParams, { method: 'webauthn' }>,\n ) {\n const { challenge, attestation } = await this._webauthnGenerateAttestation(\n params.email,\n )\n\n const {\n token,\n user: { id, email, subOrgId, walletAddress, salt, smartAccountAddress },\n } = await this.request('/v1/signup', {\n passkey: {\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n },\n email: params.email,\n })\n\n this.user = {\n id,\n email,\n subOrgId,\n walletAddress,\n salt,\n smartAccountAddress,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.user = this.user\n this._sessionStore.type = SessionType.Passkeys\n this._sessionStore.token = token\n }\n\n /**\n * Creates an email account using the iframe stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account\n */\n private async _createEmailAccount(\n params: Extract<CreateAccountParams, { method: 'email' }>,\n ) {\n const { email, expirationSeconds, redirectUrl } =\n params as EmailInitializeAuthParams\n\n const response = await this.request('/v1/signup', {\n email,\n iframe: {\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n },\n })\n\n return response\n }\n\n /**\n * Handle the account creation process.\n *\n * @param {CreateAccountParams} params params to create an account\n */\n private async _createAccount(params: CreateAccountParams) {\n switch (params.method) {\n case 'webauthn': {\n await this._createWebauthnAccount(params)\n break\n }\n case 'email': {\n await this._createEmailAccount(params)\n break\n }\n }\n }\n\n private async _webauthnGenerateAttestation(email: string) {\n const challenge = LibBytes.generateRandomBuffer()\n const authenticatorUserId = LibBytes.generateRandomBuffer()\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n authenticatorSelection: {\n residentKey: 'preferred',\n requireResidentKey: false,\n userVerification: 'preferred',\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\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: email,\n displayName: email,\n },\n },\n })\n\n return { challenge, attestation, authenticatorUserId }\n }\n\n private async _initIframeStamper() {\n if (!this._stampers.iframe.publicKey()) {\n await this._stampers.iframe.init()\n }\n\n this.stamper = this._stampers.iframe\n\n return this._stampers.iframe.publicKey()!\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteAuthWithBundleParams,\n CreateAccountParams,\n EmailInitializeAuthParams,\n GoogleOAuthSignInParams,\n WebauthnSignInParams,\n WebSignerClientConstructorParams,\n}\n","import { Buffer } from 'buffer'\n\nclass LibBase64 {\n static fromBuffer(buffer: ArrayBuffer): string {\n return Buffer.from(buffer)\n .toString('base64')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=/g, '')\n }\n\n static toBuffer(base64: string): ArrayBuffer {\n return Buffer.from(base64, 'base64').buffer\n }\n}\n\nexport { LibBase64 }\n","type TakeBytesParams = Partial<{\n count: number\n offset: number\n}>\n\ntype ByteString = `0x${string}`\n\nclass LibBytes {\n static generateRandomBuffer = (): ArrayBuffer => {\n const arr = new Uint8Array(32)\n crypto.getRandomValues(arr)\n return arr.buffer\n }\n\n static takeBytes = (\n bytes: ByteString,\n params: TakeBytesParams = {},\n ): ByteString => {\n const { offset, count } = params\n const start = (offset ? offset * 2 : 0) + 2 // add 2 to skip the 0x prefix\n const end = count ? start + count * 2 : undefined\n\n return `0x${bytes.slice(start, end)}`\n }\n}\n\nexport { LibBytes }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n GenericError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport { SessionStore } from '../session/index.js'\nimport { User } from '../types/entities.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n AuthenticationServiceRoutes,\n ROUTE_METHOD_MAP,\n} from '../types/Routes.js'\nimport { jwtDecode, JwtPayload } from 'jwt-decode'\nimport { isPast, secondsToMilliseconds } from 'date-fns'\n\ntype SignerClientConfiguration = {\n apiKey: string\n apiUrl?: string\n paymasterRpcUrl?: string\n}\n\ntype SignerClientConstructorParams = {\n stamper: TurnkeyClient['stamper']\n configuration: SignerClientConfiguration\n}\n\ntype SignerClientInheritedConstructorParams<\n Extended extends Record<string, unknown>,\n> = Pick<SignerClientConstructorParams, 'configuration'> & Extended\n\nabstract class SignerClient {\n protected readonly _turnkeyClient: TurnkeyClient\n protected readonly _configuration: Required<\n SignerClientConstructorParams['configuration']\n >\n protected readonly _sessionStore: SessionStore\n\n private _user?: User\n\n constructor({\n stamper,\n configuration: { apiUrl, paymasterRpcUrl, ...requiredConfiguration },\n }: SignerClientConstructorParams) {\n this._turnkeyClient = new TurnkeyClient(\n { baseUrl: 'https://api.turnkey.com' },\n stamper,\n )\n\n this._configuration = {\n ...requiredConfiguration,\n apiUrl: apiUrl ?? 'https://auth.api.fourt.io/',\n paymasterRpcUrl: paymasterRpcUrl ?? 'https://management.api.fourt.io/',\n }\n\n this._sessionStore = new SessionStore()\n }\n\n logout() {\n this._user = undefined\n this.sessionStore.clearAll()\n }\n\n get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n get user(): User | undefined {\n if (this._user) return this._user\n\n // Check if there's a token\n if (!this.sessionStore.token) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n const decodedToken = jwtDecode<JwtPayload>(this.sessionStore.token)\n // Check if the token has expired\n if (\n decodedToken.exp &&\n isPast(new Date(secondsToMilliseconds(decodedToken.exp)))\n ) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n if (this.sessionStore.user) this._user = this.sessionStore.user\n\n return this._user\n }\n\n protected set user(value: User | undefined) {\n this._user = value\n }\n\n protected set stamper(stamper: TurnkeyClient['stamper']) {\n this._turnkeyClient.stamper = stamper\n }\n\n protected get stamper(): TurnkeyClient['stamper'] {\n return this._turnkeyClient.stamper\n }\n\n protected get sessionStore(): SessionStore {\n return this._sessionStore\n }\n\n async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._user) {\n throw new UnauthorizedError({\n message: 'SignerClient must be authenticated to sign a message',\n })\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._user.subOrgId,\n type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',\n timestampMs: Date.now().toString(),\n parameters: {\n encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',\n hashFunction: 'HASH_FUNCTION_NO_OP',\n payload: msg,\n signWith: this._user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', {\n stampedRequest,\n })\n\n return <Into>signature\n }\n\n protected async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', { email })\n return subOrgId\n } catch (error) {\n if (!(error instanceof SDKError)) throw error\n\n const sdkError: SDKError = error\n\n switch (sdkError.constructor.name) {\n case NotFoundError.name: {\n return null\n }\n default: {\n throw sdkError\n }\n }\n }\n }\n\n protected async whoAmI(subOrgId?: string) {\n const orgId = subOrgId || this._user?.subOrgId\n\n if (!orgId) throw new BadRequestError({ message: 'No orgId provided' })\n\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: orgId,\n })\n\n const { user, token } = await this.request('/v1/signin', {\n stampedRequest,\n })\n\n const credentialId = (() => {\n try {\n return JSON.parse(stampedRequest?.stamp.stampHeaderValue)\n .credentialId as string\n } catch (e) {\n return undefined\n }\n })()\n\n this._user = {\n ...user,\n credentialId: credentialId,\n }\n\n this.sessionStore.user = this.user!\n this.sessionStore.token = token\n }\n\n protected async request<Route extends AuthenticationServiceRoutes>(\n route: Route,\n body?: AuthenticationServiceBody<Route>,\n ): Promise<AuthenticationServiceResponse<Route>> {\n const url = new URL(`${route}`, this._configuration.apiUrl)\n const token = this.sessionStore.token\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-FOURT-KEY': this._configuration.apiKey,\n }\n\n // Add Authorization header if token exists\n if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method: ROUTE_METHOD_MAP[route],\n body: JSON.stringify(body),\n headers,\n credentials: 'include',\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<Route>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n // TODO: workaround! this need to be cleaned up and moved into the web signer\n this.logout()\n throw new UnauthorizedError({ message: error.message })\n }\n case 'NotFoundError': {\n throw new NotFoundError({ message: error.message })\n }\n case 'BadRequestError': {\n throw new BadRequestError({ message: error.message })\n }\n default: {\n throw new GenericError({ message: error.message })\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<Route>\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthorizedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthorizedError.name, props)\n }\n}\n\nexport { UnauthorizedError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass NotFoundError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(NotFoundError.name, props)\n }\n}\n\nexport { NotFoundError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass GenericError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(GenericError.name, props)\n }\n}\n\nexport { GenericError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthenticatedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthenticatedError.name, props)\n }\n}\n\nexport { UnauthenticatedError }\n","import { getWebAuthnAttestation, TSignedRequest } from '@turnkey/http'\nimport { User } from './entities.js'\nimport { AtLeastOne } from './string.js'\n\ntype AuthenticationServiceRoutes =\n AuthenticationServiceEndpoints[number]['Route']\n\ntype AuthenticationServiceBody<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Body']\n\ntype AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Response']\n\ntype AuthenticationServiceEndpoints = [\n {\n Route: '/v1/email-auth'\n Body: {\n email: string\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signup'\n Body: AtLeastOne<{\n passkey: {\n challenge: string\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>\n }\n iframe: {\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n }> & { email: string }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/lookup'\n Body: {\n email: string\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signin'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/sign'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n signature: string\n }\n },\n]\n\nconst ROUTE_METHOD_MAP = {\n '/v1/signup': 'POST',\n '/v1/email-auth': 'POST',\n '/v1/lookup': 'POST',\n '/v1/signin': 'POST',\n '/v1/sign': 'POST',\n} satisfies Record<AuthenticationServiceRoutes, 'POST' | 'GET'>\n\nexport type {\n AuthenticationServiceEndpoints,\n AuthenticationServiceResponse,\n AuthenticationServiceBody,\n AuthenticationServiceRoutes,\n}\n\nexport { ROUTE_METHOD_MAP }\n","import {\n LocalAccount,\n TypedData,\n TypedDataDefinition,\n SignableMessage,\n Hex,\n hashMessage,\n hashTypedData,\n SerializeTransactionFn,\n TransactionSerializable,\n IsNarrowable,\n TransactionSerialized,\n GetTransactionType,\n serializeTransaction,\n keccak256,\n Client,\n hexToBigInt,\n http,\n} from 'viem'\nimport { toAccount } from 'viem/accounts'\nimport { SignerClient } from '../signer/index.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { toLightSmartAccount } from 'permissionless/accounts'\nimport {\n createPaymasterClient,\n entryPoint07Address,\n} from 'viem/account-abstraction'\nimport { UnauthenticatedError } from '../errors/UnauthenticatedError.js'\n\ntype ViemModuleConstructorParams = {\n refs: {\n signerClient: SignerClient\n }\n}\n\ntype CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: (msg) => this.signMessage(msg.message),\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>,\n ) => this.signTypedData<typedData, primaryType>(typedDataDefinition),\n signTransaction: this.signTransaction,\n })\n }\n\n async toSmartAccount({\n client,\n owner,\n }: CurrentUserToLightSmartAccountParams): ReturnType<\n typeof toLightSmartAccount<'0.7'>\n > {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toLightSmartAccount({\n client: client,\n owner,\n version: '2.0.0',\n entryPoint: {\n address: entryPoint07Address,\n version: '0.7',\n },\n address: user.smartAccountAddress,\n index: hexToBigInt(user.salt),\n })\n }\n\n async getPaymasterClient() {\n const url = new URL(\n `v1/rpc?apiKey=${this._signerClient.configuration.apiKey}`,\n this._signerClient.configuration.paymasterRpcUrl,\n )\n return createPaymasterClient({\n transport: http(url.toString()),\n })\n }\n\n async signMessage(msg: SignableMessage): Promise<Hex> {\n const messageHash = hashMessage(msg)\n const result = await this._signerClient.signRawMessage<Hex>(messageHash)\n return result\n }\n\n async signTypedData<\n TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {\n const messageHash = hashTypedData(params)\n return this._signerClient.signRawMessage(messageHash)\n }\n\n async signTransaction<\n serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,\n transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],\n >(\n transaction: transaction,\n options?:\n | {\n serializer?: serializer | undefined\n }\n | undefined,\n ): Promise<\n IsNarrowable<\n TransactionSerialized<GetTransactionType<transaction>>,\n Hex\n > extends true\n ? TransactionSerialized<GetTransactionType<transaction>>\n : Hex\n > {\n const serializeFn = options?.serializer ?? serializeTransaction\n const serializedTx = serializeFn(transaction)\n const signatureHex = await this._signerClient.signRawMessage<Hex>(\n keccak256(serializedTx),\n )\n\n const signature = {\n r: LibBytes.takeBytes(signatureHex, { count: 32 }),\n s: LibBytes.takeBytes(signatureHex, { count: 32, offset: 32 }),\n v: BigInt(LibBytes.takeBytes(signatureHex, { count: 1, offset: 64 })),\n }\n\n return serializeFn(transaction, signature)\n }\n}\n\nexport { ViemModule }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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B;AAAA,IAC5C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AACF;","names":["jose","jose","import_sha","import_http","import_accounts"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/session/index.ts","../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/errors/SDKError.ts","../src/errors/BadRequestError.ts","../src/modules/auth/oauth/facebook.ts","../src/modules/auth/oauth/apple.ts","../src/modules/auth/oauth.ts","../src/modules/auth/index.ts","../src/modules/user/index.ts","../src/signer/web.ts","../src/lib/base64.ts","../src/lib/bytes.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/GenericError.ts","../src/errors/UnauthenticatedError.ts","../src/types/Routes.ts","../src/third-party/viem.ts"],"sourcesContent":["import { AuthModule, UserModule } from './modules/index.js'\nimport { SignerClientConstructorParams } from './signer/index.js'\nimport {\n WebSignerClient,\n WebSignerClientConstructorParams,\n} from './signer/web.js'\nimport { ViemModule } from './third-party/viem.js'\n\ntype FourtWebSignerConstructorParams = {\n configuration: SignerClientConstructorParams['configuration']\n auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'iframe' | 'oauth'>\n}\n\n/**\n * A client for interacting with the Fourt Web Signer.\n */\nclass FourtWebSigner {\n private readonly _webSignerClient: WebSignerClient\n private readonly _modules: {\n viem: ViemModule\n auth: AuthModule\n user: UserModule\n }\n\n /**\n * Initializes a new instance of the `FourtWebSigner` class.\n * Sets up the underlying modules.\n *\n *\n * @example\n * ```ts\n * const fourtWebSigner = new FourtWebSigner({\n * auth: {\n * webauthn: {\n * rpId: 'localhost',\n * },\n * },\n * configuration: {\n * apiKey: '927d603c-6775-4210-8e13-8904ca985e78',\n * },\n * })\n * ```\n *\n * @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client\n */\n constructor({\n configuration,\n auth: { webauthn, iframe, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\n iframe,\n oauth,\n })\n\n this._modules = {\n viem: new ViemModule(this._webSignerClient),\n auth: new AuthModule(this._webSignerClient),\n user: new UserModule(this._webSignerClient),\n }\n }\n\n /**\n * A module for interacting with the Viem library.\n */\n get viem() {\n return this._modules.viem\n }\n\n /**\n * A module for interacting with the authentication methods.\n */\n get auth() {\n return this._modules.auth\n }\n\n /**\n * A module for interacting with the user methods.\n */\n get user() {\n return this._modules.user\n }\n}\n\nexport { FourtWebSigner }\n","import { createStore, type StoreApi } from 'zustand'\nimport { createJSONStorage, persist } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\n/**\n * The state of the session.\n */\ntype SessionState = {\n type?: SessionType\n user?: User\n expirationDate?: Date\n bundle?: string\n token?: string\n}\n\n/**\n * A store for the session state.\n */\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n /**\n * Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.\n */\n constructor() {\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt.io-signer-session',\n storage: createJSONStorage<SessionState>(() => localStorage),\n }),\n )\n }\n\n /**\n * Gets the type from the session state.\n *\n * @returns {SessionType | undefined} the type.\n */\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n /**\n * Sets the type in the session state.\n *\n * @param {SessionType} type the type to set.\n */\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n /**\n * Gets the token from the session state.\n *\n * @returns {string | undefined} the token.\n */\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n /**\n * Sets the token in the session state.\n *\n * @param {string} token the token to set.\n */\n set token(token: string) {\n this._store.setState({ token })\n }\n\n /**\n * Gets the bundle from the session state.\n *\n * @returns {string | undefined} the bundle.\n */\n get bundle(): string | undefined {\n return this._store.getState().bundle\n }\n\n /**\n * Sets the bundle in the session state.\n *\n * @param {string} bundle the bundle to set.\n */\n set bundle(bundle: string) {\n this._store.setState({ bundle })\n }\n\n /**\n * Gets the user from the session state.\n *\n * @returns {User | undefined} the user.\n */\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n /**\n * Sets the user in the session state.\n *\n * @param {User} user the user to set.\n */\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n /**\n * Clears the user from the session state.\n */\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n /**\n * Clears the bundle from the session state.\n */\n clearBundle() {\n this._store.setState({ ...this._store.getState(), bundle: undefined })\n }\n\n /**\n * Clears the type from the session state.\n */\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n /**\n * Clears the token from the session state.\n */\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n /**\n * Clears the token and user from the session state.\n */\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearBundle()\n this.clearType()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n bundle: undefined,\n token: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { SessionType } from '../../session/index.js'\nimport type {\n WebSignerClient,\n EmailInitializeAuthParams,\n CompleteAuthWithBundleParams,\n} from '../../signer/web.js'\n\n/**\n * A module for interacting with the Email authentication methods.\n * Available through the `auth.email` property on a `FourtWebSigner` instance.\n */\nclass EmailModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Initialize user authentication process using email.\n *\n * @param params {EmailInitializeAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves to the result of the authentication process.\n */\n async initialize(params: EmailInitializeAuthParams): Promise<void> {\n return this._webSignerClient.emailAuth(params)\n }\n\n /**\n * Completes authentication with bundle after user receives the bundle and subOrgId as URL params.\n *\n * @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(\n params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>,\n ): Promise<void> {\n return this._webSignerClient.completeAuthWithBundle({\n ...params,\n sessionType: SessionType.Email,\n })\n }\n}\n\nexport { EmailModule }\n","import type { WebSignerClient, WebauthnSignInParams } from '../../signer/web.js'\n\n/**\n * A module for interacting with the Passkeys authentication methods.\n * Available through the `auth.passkeys` property on a `FourtWebSigner` instance.\n */\nclass PasskeysModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Signs in a user using Passkeys.\n *\n * @param params {WebauthnSignInParams} params for the sign-in process.\n * @returns {Promise<void>} promise that resolves to the result of the sign-in process.\n */\n async signIn(params: WebauthnSignInParams) {\n return this._webSignerClient.webauthnSignIn(params)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n const initUrl = await this._webSignerClient.getOAuthInitUrl('google')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'google',\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { GoogleModule }\n","type SDKErrorProps = {\n message: string\n}\n\nabstract class SDKError extends Error {\n private readonly _props: SDKErrorProps\n\n constructor(message: string, props: SDKErrorProps) {\n super(message)\n this._props = props\n }\n\n get message() {\n return this._props.message\n }\n}\n\nexport { SDKError }\nexport type { SDKErrorProps }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass BadRequestError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(BadRequestError.name, props)\n }\n}\n\nexport { BadRequestError }\n","import { BadRequestError } from '../../../errors/BadRequestError.js'\nimport { WebSignerClient } from '../../../signer/web.js'\nimport * as jose from 'jose'\n\nclass FacebookModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n const publicKey = await this._webSignerClient.getIframePublicKey()\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n\n const jwt = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'facebook',\n }).encode()\n\n const response = await fetch(internalUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n state: jwt,\n }),\n })\n\n if (!response.ok) {\n throw new BadRequestError({\n message: `Failed to create OAuth state. Error: ${response.statusText}`,\n })\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError({\n message: response.statusText,\n })\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n const initUrl = await this._webSignerClient.getOAuthInitUrl('apple')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth/apple',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { AppleModule }\n","import { SessionType } from '../../session/index.js'\nimport type { WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\ntype CompleteParams = {\n bundle: string\n subOrgId: string\n}\n\nclass OAuthModule {\n private readonly _googleModule: GoogleModule\n private readonly _facebookModule: FacebookModule\n private readonly _appleModule: AppleModule\n\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._googleModule = new GoogleModule(this._webSignerClient)\n this._facebookModule = new FacebookModule(this._webSignerClient)\n this._appleModule = new AppleModule(this._webSignerClient)\n }\n\n get google() {\n return this._googleModule\n }\n\n get facebook() {\n return this._facebookModule\n }\n\n get apple() {\n return this._appleModule\n }\n\n async complete({ bundle, subOrgId }: CompleteParams) {\n await this._webSignerClient.completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType: SessionType.OAuth,\n })\n }\n}\n\nexport { OAuthModule }\n","import type { WebSignerClient } from '../../signer/web.js'\nimport { EmailModule } from './email.js'\nimport { PasskeysModule } from './passkeys.js'\nimport { OAuthModule } from './oauth.js'\n\n/**\n * A module for interacting with the authentication methods.\n * Available through the `auth` property on a `FourtWebSigner` instance.\n */\nclass AuthModule {\n private readonly _passkeys: PasskeysModule\n private readonly _email: EmailModule\n private readonly _oauth: OAuthModule\n\n /**\n * Initializes a new instance of the `AuthModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._passkeys = new PasskeysModule(this._webSignerClient)\n this._email = new EmailModule(this._webSignerClient)\n this._oauth = new OAuthModule(this._webSignerClient)\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get passkeys() {\n return this._passkeys\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get email() {\n return this._email\n }\n\n get oauth() {\n return this._oauth\n }\n}\n\nexport { AuthModule }\nexport { PasskeysModule } from './passkeys.js'\nexport { EmailModule } from './email.js'\n","import { WebSignerClient } from '../../signer/web.js'\nimport { User } from '../../types/entities.js'\n\n/**\n * A module for interacting with the user methods.\n * Available through the `user` property on a `FourtWebSigner` instance.\n */\nclass UserModule {\n /**\n * Initializes a new instance of the `UserModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Gets the user information.\n *\n * @returns {User | undefined} user information.\n */\n get info() {\n return this._webSignerClient.user\n }\n\n /**\n * Logs out the user.\n *\n * @returns {void}\n */\n logout() {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\nimport { IframeStamper } from '@turnkey/iframe-stamper'\nimport { WebauthnStamper } from '@turnkey/webauthn-stamper'\nimport { LibBase64 } from '../lib/base64.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { SessionType } from '../session/index.js'\nimport {\n type SignerClientInheritedConstructorParams,\n SignerClient,\n} from './index.js'\n\ntype WebauthnSignInParams = {\n email: string\n}\n\n// * When user starts auth with email - can be either a signup or a signin\ntype EmailInitializeAuthParams = {\n email: string\n redirectUrl: string\n expirationSeconds?: number // Defaults to 15 minutes by Turnkey\n}\n\n// * When user completes auth with bundle\ntype CompleteAuthWithBundleParams = {\n bundle: string\n subOrgId: string\n sessionType: SessionType\n isNewUser?: boolean\n}\n\ntype GoogleOAuthSignInParams = {\n credential: string\n clientId: string\n}\n\nexport type OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n iframe?: {\n iframeElementId?: string\n iframeContainerId?: string\n }\n oauth?: OAuthConfiguration\n}>\n\ntype CreateAccountParams =\n | ({\n method: 'webauthn'\n } & WebauthnSignInParams)\n | ({\n method: 'email'\n } & EmailInitializeAuthParams)\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private readonly _stampers: {\n webauthn: WebauthnStamper\n iframe: IframeStamper\n }\n\n readonly oauthConfiguration: WebSignerClientConstructorParams['oauth']\n\n /**\n * Initializes a new instance of the `WebSignerClient` class.\n *\n * @param {WebSignerClientConstructorParams} params params for the constructor\n */\n constructor({\n configuration,\n webauthn,\n iframe,\n oauth,\n }: WebSignerClientConstructorParams) {\n const iframeContainerId =\n iframe?.iframeContainerId ?? 'fourt-signer-iframe-container'\n const iframeContainer = document.createElement('div')\n iframeContainer.id = iframeContainerId\n iframeContainer.style.display = 'none'\n document.body.appendChild(iframeContainer)\n\n const webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n const iframeStamper = new IframeStamper({\n iframeUrl: 'https://auth.turnkey.com',\n iframeElementId: iframe?.iframeElementId ?? 'turnkey-iframe',\n iframeContainer: document.getElementById(iframeContainerId),\n })\n\n super({\n stamper: iframeStamper, // Initialized to iframeStamper; can be either webauthnStamper or iframeStamper\n configuration: configuration,\n })\n\n this._stampers = {\n webauthn: webauthnStamper,\n iframe: iframeStamper,\n }\n\n this.oauthConfiguration = oauth\n }\n\n public override async signRawMessage<Into extends string>(\n msg: string,\n ): Promise<Into> {\n await this.updateStamper()\n return super.signRawMessage(msg)\n }\n\n public override async logout() {\n this._stampers.iframe.clear()\n await this._stampers.iframe.init()\n return super.logout()\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n *\n */\n private async updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n (this._sessionStore.bundle === undefined ||\n this._sessionStore.token === undefined)\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this._stampers.webauthn\n } else {\n this.stamper = this._stampers.iframe\n // We need to inject to inject the credential bundle\n // Otherwise the user will not be able to sign\n await this.completeAuthWithBundle({\n bundle: this._sessionStore.bundle!,\n subOrgId: this.user?.subOrgId!,\n sessionType: this._sessionStore.type!,\n })\n }\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {WebauthnSignInParams} params params for the sign in\n */\n async webauthnSignIn({ email }: WebauthnSignInParams) {\n const existingUserSubOrgId = await this.lookUpUser(email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'webauthn', email })\n } else {\n this.stamper = this._stampers.webauthn\n await this.whoAmI(existingUserSubOrgId)\n\n this._sessionStore.type = SessionType.Passkeys\n\n // We should assure that the user and its credentialId are set\n if (!this.user || !this.user.credentialId) {\n return\n }\n\n this._stampers.webauthn.allowCredentials = [\n {\n id: LibBase64.toBuffer(this.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handle auth user process with email.\n *\n * @param {EmailInitializeAuthParams} params Params needed for the initialization of the auth process\n */\n async emailAuth(params: EmailInitializeAuthParams) {\n const existingUserSubOrgId = await this.lookUpUser(params.email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'email', ...params })\n } else {\n await this._signInWithEmail(params)\n }\n }\n\n async getIframePublicKey() {\n return await this._initIframeStamper()\n }\n\n /**\n * Signs in a user with email.\n *\n * @param {EmailInitializeAuthParams} params params for the sign in\n */\n private async _signInWithEmail({\n email,\n expirationSeconds,\n redirectUrl,\n }: EmailInitializeAuthParams) {\n return this.request('/v1/email-auth', {\n email,\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n })\n }\n\n /**\n * Completes the authentication process with a credential bundle.\n *\n * @param {CompleteAuthWithBundleParams} params params for the completion of the auth process\n */\n public async completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType,\n }: CompleteAuthWithBundleParams): Promise<void> {\n await this._initIframeStamper()\n\n const result = await this._stampers.iframe.injectCredentialBundle(bundle)\n\n if (!result) {\n throw new Error('Failed to inject credential bundle')\n }\n\n await this.whoAmI(subOrgId)\n\n this._sessionStore.type = sessionType\n this._sessionStore.bundle = bundle\n }\n\n /**\n * Creates a passkey account using the webauthn stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'webauthn' }>} params params for the creation of the account\n */\n private async _createWebauthnAccount(\n params: Extract<CreateAccountParams, { method: 'webauthn' }>,\n ) {\n const { challenge, attestation } = await this._webauthnGenerateAttestation(\n params.email,\n )\n\n const {\n token,\n user: { id, email, subOrgId, walletAddress, salt, smartAccountAddress },\n } = await this.request('/v1/signup', {\n passkey: {\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n },\n email: params.email,\n })\n\n this.user = {\n id,\n email,\n subOrgId,\n walletAddress,\n salt,\n smartAccountAddress,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.user = this.user\n this._sessionStore.type = SessionType.Passkeys\n this._sessionStore.token = token\n }\n\n /**\n * Creates an email account using the iframe stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account\n */\n private async _createEmailAccount(\n params: Extract<CreateAccountParams, { method: 'email' }>,\n ) {\n const { email, expirationSeconds, redirectUrl } =\n params as EmailInitializeAuthParams\n\n const response = await this.request('/v1/signup', {\n email,\n iframe: {\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n },\n })\n\n return response\n }\n\n /**\n * Handle the account creation process.\n *\n * @param {CreateAccountParams} params params to create an account\n */\n private async _createAccount(params: CreateAccountParams) {\n switch (params.method) {\n case 'webauthn': {\n await this._createWebauthnAccount(params)\n break\n }\n case 'email': {\n await this._createEmailAccount(params)\n break\n }\n }\n }\n\n private async _webauthnGenerateAttestation(email: string) {\n const challenge = LibBytes.generateRandomBuffer()\n const authenticatorUserId = LibBytes.generateRandomBuffer()\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n authenticatorSelection: {\n residentKey: 'preferred',\n requireResidentKey: false,\n userVerification: 'preferred',\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\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: email,\n displayName: email,\n },\n },\n })\n\n return { challenge, attestation, authenticatorUserId }\n }\n\n private async _initIframeStamper() {\n if (!this._stampers.iframe.publicKey()) {\n await this._stampers.iframe.init()\n }\n\n this.stamper = this._stampers.iframe\n\n return this._stampers.iframe.publicKey()!\n }\n\n /**\n * Get the pre-filled URL for initiating oauth with a specific provider.\n *\n * @param {string} provider provider for which we are getting the URL, currently google or apple\n */\n public async getOAuthInitUrl(provider: string) {\n const { url } = await this.request('v1/oauth/init', {\n provider,\n })\n\n return url\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteAuthWithBundleParams,\n CreateAccountParams,\n EmailInitializeAuthParams,\n GoogleOAuthSignInParams,\n WebauthnSignInParams,\n WebSignerClientConstructorParams,\n}\n","import { Buffer } from 'buffer'\n\nclass LibBase64 {\n static fromBuffer(buffer: ArrayBuffer): string {\n return Buffer.from(buffer)\n .toString('base64')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=/g, '')\n }\n\n static toBuffer(base64: string): ArrayBuffer {\n return Buffer.from(base64, 'base64').buffer\n }\n}\n\nexport { LibBase64 }\n","type TakeBytesParams = Partial<{\n count: number\n offset: number\n}>\n\ntype ByteString = `0x${string}`\n\nclass LibBytes {\n static generateRandomBuffer = (): ArrayBuffer => {\n const arr = new Uint8Array(32)\n crypto.getRandomValues(arr)\n return arr.buffer\n }\n\n static takeBytes = (\n bytes: ByteString,\n params: TakeBytesParams = {},\n ): ByteString => {\n const { offset, count } = params\n const start = (offset ? offset * 2 : 0) + 2 // add 2 to skip the 0x prefix\n const end = count ? start + count * 2 : undefined\n\n return `0x${bytes.slice(start, end)}`\n }\n}\n\nexport { LibBytes }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n GenericError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport { SessionStore } from '../session/index.js'\nimport { User } from '../types/entities.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n AuthenticationServiceRoutes,\n ROUTE_METHOD_MAP,\n} from '../types/Routes.js'\nimport { jwtDecode, JwtPayload } from 'jwt-decode'\nimport { isPast, secondsToMilliseconds } from 'date-fns'\n\ntype SignerClientConfiguration = {\n apiKey: string\n apiUrl?: string\n paymasterRpcUrl?: string\n}\n\ntype SignerClientConstructorParams = {\n stamper: TurnkeyClient['stamper']\n configuration: SignerClientConfiguration\n}\n\ntype SignerClientInheritedConstructorParams<\n Extended extends Record<string, unknown>,\n> = Pick<SignerClientConstructorParams, 'configuration'> & Extended\n\nabstract class SignerClient {\n protected readonly _turnkeyClient: TurnkeyClient\n protected readonly _configuration: Required<\n SignerClientConstructorParams['configuration']\n >\n protected readonly _sessionStore: SessionStore\n\n private _user?: User\n\n constructor({\n stamper,\n configuration: { apiUrl, paymasterRpcUrl, ...requiredConfiguration },\n }: SignerClientConstructorParams) {\n this._turnkeyClient = new TurnkeyClient(\n { baseUrl: 'https://api.turnkey.com' },\n stamper,\n )\n\n this._configuration = {\n ...requiredConfiguration,\n apiUrl: apiUrl ?? 'https://auth.api.fourt.io/',\n paymasterRpcUrl: paymasterRpcUrl ?? 'https://management.api.fourt.io/',\n }\n\n this._sessionStore = new SessionStore()\n }\n\n logout() {\n this._user = undefined\n this.sessionStore.clearAll()\n }\n\n get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n get user(): User | undefined {\n if (this._user) return this._user\n\n // Check if there's a token\n if (!this.sessionStore.token) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n const decodedToken = jwtDecode<JwtPayload>(this.sessionStore.token)\n // Check if the token has expired\n if (\n decodedToken.exp &&\n isPast(new Date(secondsToMilliseconds(decodedToken.exp)))\n ) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n if (this.sessionStore.user) this._user = this.sessionStore.user\n\n return this._user\n }\n\n protected set user(value: User | undefined) {\n this._user = value\n }\n\n protected set stamper(stamper: TurnkeyClient['stamper']) {\n this._turnkeyClient.stamper = stamper\n }\n\n protected get stamper(): TurnkeyClient['stamper'] {\n return this._turnkeyClient.stamper\n }\n\n protected get sessionStore(): SessionStore {\n return this._sessionStore\n }\n\n async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._user) {\n throw new UnauthorizedError({\n message: 'SignerClient must be authenticated to sign a message',\n })\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._user.subOrgId,\n type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',\n timestampMs: Date.now().toString(),\n parameters: {\n encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',\n hashFunction: 'HASH_FUNCTION_NO_OP',\n payload: msg,\n signWith: this._user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', {\n stampedRequest,\n })\n\n return <Into>signature\n }\n\n protected async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', { email })\n return subOrgId\n } catch (error) {\n if (!(error instanceof SDKError)) throw error\n\n const sdkError: SDKError = error\n\n switch (sdkError.constructor.name) {\n case NotFoundError.name: {\n return null\n }\n default: {\n throw sdkError\n }\n }\n }\n }\n\n protected async whoAmI(subOrgId?: string) {\n const orgId = subOrgId || this._user?.subOrgId\n\n if (!orgId) throw new BadRequestError({ message: 'No orgId provided' })\n\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: orgId,\n })\n\n const { user, token } = await this.request('/v1/signin', {\n stampedRequest,\n })\n\n const credentialId = (() => {\n try {\n return JSON.parse(stampedRequest?.stamp.stampHeaderValue)\n .credentialId as string\n } catch (e) {\n return undefined\n }\n })()\n\n this._user = {\n ...user,\n credentialId: credentialId,\n }\n\n this.sessionStore.user = this.user!\n this.sessionStore.token = token\n }\n\n protected async request<Route extends AuthenticationServiceRoutes>(\n route: Route,\n body?: AuthenticationServiceBody<Route>,\n ): Promise<AuthenticationServiceResponse<Route>> {\n const url = new URL(`${route}`, this._configuration.apiUrl)\n const token = this.sessionStore.token\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-FOURT-KEY': this._configuration.apiKey,\n }\n\n // Add Authorization header if token exists\n if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method: ROUTE_METHOD_MAP[route],\n body: JSON.stringify(body),\n headers,\n credentials: 'include',\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<Route>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n // TODO: workaround! this need to be cleaned up and moved into the web signer\n this.logout()\n throw new UnauthorizedError({ message: error.message })\n }\n case 'NotFoundError': {\n throw new NotFoundError({ message: error.message })\n }\n case 'BadRequestError': {\n throw new BadRequestError({ message: error.message })\n }\n default: {\n throw new GenericError({ message: error.message })\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<Route>\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthorizedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthorizedError.name, props)\n }\n}\n\nexport { UnauthorizedError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass NotFoundError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(NotFoundError.name, props)\n }\n}\n\nexport { NotFoundError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass GenericError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(GenericError.name, props)\n }\n}\n\nexport { GenericError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthenticatedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthenticatedError.name, props)\n }\n}\n\nexport { UnauthenticatedError }\n","import { getWebAuthnAttestation, TSignedRequest } from '@turnkey/http'\nimport { User } from './entities.js'\nimport { AtLeastOne } from './string.js'\n\ntype AuthenticationServiceRoutes =\n AuthenticationServiceEndpoints[number]['Route']\n\ntype AuthenticationServiceBody<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Body']\n\ntype AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Response']\n\ntype AuthenticationServiceEndpoints = [\n {\n Route: '/v1/email-auth'\n Body: {\n email: string\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signup'\n Body: AtLeastOne<{\n passkey: {\n challenge: string\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>\n }\n iframe: {\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n }> & { email: string }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/lookup'\n Body: {\n email: string\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signin'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/sign'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n signature: string\n }\n },\n {\n Route: 'v1/oauth/init'\n Body: {\n provider: string\n }\n Response: {\n url: string\n }\n },\n]\n\nconst ROUTE_METHOD_MAP = {\n '/v1/signup': 'POST',\n '/v1/email-auth': 'POST',\n '/v1/lookup': 'POST',\n '/v1/signin': 'POST',\n '/v1/sign': 'POST',\n 'v1/oauth/init': 'POST',\n} satisfies Record<AuthenticationServiceRoutes, 'POST' | 'GET'>\n\nexport type {\n AuthenticationServiceEndpoints,\n AuthenticationServiceResponse,\n AuthenticationServiceBody,\n AuthenticationServiceRoutes,\n}\n\nexport { ROUTE_METHOD_MAP }\n","import {\n LocalAccount,\n TypedData,\n TypedDataDefinition,\n SignableMessage,\n Hex,\n hashMessage,\n hashTypedData,\n SerializeTransactionFn,\n TransactionSerializable,\n IsNarrowable,\n TransactionSerialized,\n GetTransactionType,\n serializeTransaction,\n keccak256,\n Client,\n hexToBigInt,\n http,\n} from 'viem'\nimport { toAccount } from 'viem/accounts'\nimport { SignerClient } from '../signer/index.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { toLightSmartAccount } from 'permissionless/accounts'\nimport {\n createPaymasterClient,\n entryPoint07Address,\n} from 'viem/account-abstraction'\nimport { UnauthenticatedError } from '../errors/UnauthenticatedError.js'\n\ntype ViemModuleConstructorParams = {\n refs: {\n signerClient: SignerClient\n }\n}\n\ntype CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: (msg) => this.signMessage(msg.message),\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>,\n ) => this.signTypedData<typedData, primaryType>(typedDataDefinition),\n signTransaction: this.signTransaction,\n })\n }\n\n async toSmartAccount({\n client,\n owner,\n }: CurrentUserToLightSmartAccountParams): ReturnType<\n typeof toLightSmartAccount<'0.7'>\n > {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toLightSmartAccount({\n client: client,\n owner,\n version: '2.0.0',\n entryPoint: {\n address: entryPoint07Address,\n version: '0.7',\n },\n address: user.smartAccountAddress,\n index: hexToBigInt(user.salt),\n })\n }\n\n async getPaymasterClient() {\n const url = new URL(\n `v1/rpc?apiKey=${this._signerClient.configuration.apiKey}`,\n this._signerClient.configuration.paymasterRpcUrl,\n )\n return createPaymasterClient({\n transport: http(url.toString()),\n })\n }\n\n async signMessage(msg: SignableMessage): Promise<Hex> {\n const messageHash = hashMessage(msg)\n const result = await this._signerClient.signRawMessage<Hex>(messageHash)\n return result\n }\n\n async signTypedData<\n TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {\n const messageHash = hashTypedData(params)\n return this._signerClient.signRawMessage(messageHash)\n }\n\n async signTransaction<\n serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,\n transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],\n >(\n transaction: transaction,\n options?:\n | {\n serializer?: serializer | undefined\n }\n | undefined,\n ): Promise<\n IsNarrowable<\n TransactionSerialized<GetTransactionType<transaction>>,\n Hex\n > extends true\n ? TransactionSerialized<GetTransactionType<transaction>>\n : Hex\n > {\n const serializeFn = options?.serializer ?? serializeTransaction\n const serializedTx = serializeFn(transaction)\n const signatureHex = await this._signerClient.signRawMessage<Hex>(\n keccak256(serializedTx),\n )\n\n const signature = {\n r: LibBytes.takeBytes(signatureHex, { count: 32 }),\n s: LibBytes.takeBytes(signatureHex, { count: 32, offset: 32 }),\n v: BigInt(LibBytes.takeBytes(signatureHex, { count: 1, offset: 64 })),\n }\n\n return serializeFn(transaction, signature)\n }\n}\n\nexport { ViemModule }\n"],"mappings":";;;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,MAChB,GAAG,SAAS,UAAU,cAAc,EAAE,OAAO,GAAG,CAAC;AAAA,MACjD,GAAG,SAAS,UAAU,cAAc,EAAE,OAAO,IAAI,QAAQ,GAAG,CAAC;AAAA,MAC7D,GAAG,OAAO,SAAS,UAAU,cAAc,EAAE,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;AAAA,IACtE;AAEA,WAAO,YAAY,aAAa,SAAS;AAAA,EAC3C;AACF;;;ArBhIA,IAAM,iBAAN,MAAqB;AAAA,EACF;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BjB,YAAY;AAAA,IACV;AAAA,IACA,MAAM,EAAE,UAAU,QAAQ,MAAM;AAAA,EAClC,GAAoC;AAClC,SAAK,mBAAmB,IAAI,gBAAgB;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,SAAK,WAAW;AAAA,MACd,MAAM,IAAI,WAAW,KAAK,gBAAgB;AAAA,MAC1C,MAAM,IAAI,WAAW,KAAK,gBAAgB;AAAA,MAC1C,MAAM,IAAI,WAAW,KAAK,gBAAgB;AAAA,IAC5C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AACF;","names":["jose","jose","import_sha","import_http","import_accounts"]}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { U as User, A as AtLeastOne } from './index-Cy_WMhHm.cjs';
2
2
  import { getWebAuthnAttestation, TSignedRequest, TurnkeyClient } from '@turnkey/http';
3
3
  import * as viem_account_abstraction from 'viem/account-abstraction';
4
+ import { Hex } from '../types/misc.js';
4
5
  import * as viem from 'viem';
5
- import { LocalAccount, Client, SignableMessage, Hex, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
6
+ import { LocalAccount, Client, SignableMessage, Hex as Hex$1, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
6
7
  import { toLightSmartAccount } from 'permissionless/accounts';
7
8
 
8
9
  declare enum SessionType {
@@ -157,6 +158,15 @@ type AuthenticationServiceEndpoints = [
157
158
  Response: {
158
159
  signature: string;
159
160
  };
161
+ },
162
+ {
163
+ Route: 'v1/oauth/init';
164
+ Body: {
165
+ provider: string;
166
+ };
167
+ Response: {
168
+ url: string;
169
+ };
160
170
  }
161
171
  ];
162
172
 
@@ -207,15 +217,6 @@ type OAuthConfiguration = {
207
217
  common: {
208
218
  redirectUrl: string;
209
219
  };
210
- google?: {
211
- id: string;
212
- };
213
- facebook?: {
214
- id: string;
215
- };
216
- apple?: {
217
- id: string;
218
- };
219
220
  };
220
221
  type WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{
221
222
  webauthn: {
@@ -291,6 +292,12 @@ declare class WebSignerClient extends SignerClient {
291
292
  private _createAccount;
292
293
  private _webauthnGenerateAttestation;
293
294
  private _initIframeStamper;
295
+ /**
296
+ * Get the pre-filled URL for initiating oauth with a specific provider.
297
+ *
298
+ * @param {string} provider provider for which we are getting the URL, currently google or apple
299
+ */
300
+ getOAuthInitUrl(provider: string): Promise<string>;
294
301
  }
295
302
 
296
303
  /**
@@ -426,6 +433,8 @@ declare class UserModule {
426
433
  logout(): Promise<void>;
427
434
  }
428
435
 
436
+ type CcipRequestReturnType = Hex;
437
+
429
438
  type CurrentUserToLightSmartAccountParams = {
430
439
  owner: LocalAccount;
431
440
  client: Client;
@@ -437,9 +446,13 @@ declare class ViemModule {
437
446
  toSmartAccount({ client, owner, }: CurrentUserToLightSmartAccountParams): ReturnType<typeof toLightSmartAccount<'0.7'>>;
438
447
  getPaymasterClient(): Promise<{
439
448
  account: undefined;
440
- batch?: viem.ClientConfig["batch"] | undefined;
449
+ batch?: {
450
+ multicall?: boolean | viem.Prettify<viem.MulticallBatchOptions> | undefined;
451
+ } | undefined;
441
452
  cacheTime: number;
442
- ccipRead?: viem.ClientConfig["ccipRead"] | undefined;
453
+ ccipRead?: false | {
454
+ request?: (parameters: viem.CcipRequestParameters) => Promise<CcipRequestReturnType>;
455
+ } | undefined;
443
456
  chain: undefined;
444
457
  key: string;
445
458
  name: string;
@@ -469,11 +482,11 @@ declare class ViemModule {
469
482
  uid?: undefined;
470
483
  } & viem.ExactPartial<Pick<viem.PublicActions<viem.HttpTransport, undefined, undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<viem.WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: Client<viem.HttpTransport, undefined, undefined, viem.PaymasterRpcSchema, viem_account_abstraction.PaymasterActions>) => client) => Client<viem.HttpTransport, undefined, undefined, viem.PaymasterRpcSchema, { [K in keyof client]: client[K]; } & viem_account_abstraction.PaymasterActions>;
471
484
  }>;
472
- signMessage(msg: SignableMessage): Promise<Hex>;
473
- signTypedData<TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex>;
485
+ signMessage(msg: SignableMessage): Promise<Hex$1>;
486
+ signTypedData<TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex$1>;
474
487
  signTransaction<serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
475
488
  serializer?: serializer | undefined;
476
- } | undefined): Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, Hex> extends true ? TransactionSerialized<GetTransactionType<transaction>> : Hex>;
489
+ } | undefined): Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, Hex$1> extends true ? TransactionSerialized<GetTransactionType<transaction>> : Hex$1>;
477
490
  }
478
491
 
479
492
  type FourtWebSignerConstructorParams = {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { U as User, A as AtLeastOne } from './index-Cy_WMhHm.js';
2
2
  import { getWebAuthnAttestation, TSignedRequest, TurnkeyClient } from '@turnkey/http';
3
3
  import * as viem_account_abstraction from 'viem/account-abstraction';
4
+ import { Hex } from '../types/misc.js';
4
5
  import * as viem from 'viem';
5
- import { LocalAccount, Client, SignableMessage, Hex, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
6
+ import { LocalAccount, Client, SignableMessage, Hex as Hex$1, TypedData, TypedDataDefinition, SerializeTransactionFn, TransactionSerializable, IsNarrowable, TransactionSerialized, GetTransactionType } from 'viem';
6
7
  import { toLightSmartAccount } from 'permissionless/accounts';
7
8
 
8
9
  declare enum SessionType {
@@ -157,6 +158,15 @@ type AuthenticationServiceEndpoints = [
157
158
  Response: {
158
159
  signature: string;
159
160
  };
161
+ },
162
+ {
163
+ Route: 'v1/oauth/init';
164
+ Body: {
165
+ provider: string;
166
+ };
167
+ Response: {
168
+ url: string;
169
+ };
160
170
  }
161
171
  ];
162
172
 
@@ -207,15 +217,6 @@ type OAuthConfiguration = {
207
217
  common: {
208
218
  redirectUrl: string;
209
219
  };
210
- google?: {
211
- id: string;
212
- };
213
- facebook?: {
214
- id: string;
215
- };
216
- apple?: {
217
- id: string;
218
- };
219
220
  };
220
221
  type WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{
221
222
  webauthn: {
@@ -291,6 +292,12 @@ declare class WebSignerClient extends SignerClient {
291
292
  private _createAccount;
292
293
  private _webauthnGenerateAttestation;
293
294
  private _initIframeStamper;
295
+ /**
296
+ * Get the pre-filled URL for initiating oauth with a specific provider.
297
+ *
298
+ * @param {string} provider provider for which we are getting the URL, currently google or apple
299
+ */
300
+ getOAuthInitUrl(provider: string): Promise<string>;
294
301
  }
295
302
 
296
303
  /**
@@ -426,6 +433,8 @@ declare class UserModule {
426
433
  logout(): Promise<void>;
427
434
  }
428
435
 
436
+ type CcipRequestReturnType = Hex;
437
+
429
438
  type CurrentUserToLightSmartAccountParams = {
430
439
  owner: LocalAccount;
431
440
  client: Client;
@@ -437,9 +446,13 @@ declare class ViemModule {
437
446
  toSmartAccount({ client, owner, }: CurrentUserToLightSmartAccountParams): ReturnType<typeof toLightSmartAccount<'0.7'>>;
438
447
  getPaymasterClient(): Promise<{
439
448
  account: undefined;
440
- batch?: viem.ClientConfig["batch"] | undefined;
449
+ batch?: {
450
+ multicall?: boolean | viem.Prettify<viem.MulticallBatchOptions> | undefined;
451
+ } | undefined;
441
452
  cacheTime: number;
442
- ccipRead?: viem.ClientConfig["ccipRead"] | undefined;
453
+ ccipRead?: false | {
454
+ request?: (parameters: viem.CcipRequestParameters) => Promise<CcipRequestReturnType>;
455
+ } | undefined;
443
456
  chain: undefined;
444
457
  key: string;
445
458
  name: string;
@@ -469,11 +482,11 @@ declare class ViemModule {
469
482
  uid?: undefined;
470
483
  } & viem.ExactPartial<Pick<viem.PublicActions<viem.HttpTransport, undefined, undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<viem.WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: Client<viem.HttpTransport, undefined, undefined, viem.PaymasterRpcSchema, viem_account_abstraction.PaymasterActions>) => client) => Client<viem.HttpTransport, undefined, undefined, viem.PaymasterRpcSchema, { [K in keyof client]: client[K]; } & viem_account_abstraction.PaymasterActions>;
471
484
  }>;
472
- signMessage(msg: SignableMessage): Promise<Hex>;
473
- signTypedData<TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex>;
485
+ signMessage(msg: SignableMessage): Promise<Hex$1>;
486
+ signTypedData<TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex$1>;
474
487
  signTransaction<serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
475
488
  serializer?: serializer | undefined;
476
- } | undefined): Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, Hex> extends true ? TransactionSerialized<GetTransactionType<transaction>> : Hex>;
489
+ } | undefined): Promise<IsNarrowable<TransactionSerialized<GetTransactionType<transaction>>, Hex$1> extends true ? TransactionSerialized<GetTransactionType<transaction>> : Hex$1>;
477
490
  }
478
491
 
479
492
  type FourtWebSignerConstructorParams = {
package/dist/index.js CHANGED
@@ -168,27 +168,6 @@ var PasskeysModule = class {
168
168
  // src/modules/auth/oauth/google.ts
169
169
  import * as jose from "jose";
170
170
  import { sha256 } from "sha.js";
171
-
172
- // src/errors/SDKError.ts
173
- var SDKError = class extends Error {
174
- _props;
175
- constructor(message, props) {
176
- super(message);
177
- this._props = props;
178
- }
179
- get message() {
180
- return this._props.message;
181
- }
182
- };
183
-
184
- // src/errors/BadRequestError.ts
185
- var BadRequestError = class _BadRequestError extends SDKError {
186
- constructor(props) {
187
- super(_BadRequestError.name, props);
188
- }
189
- };
190
-
191
- // src/modules/auth/oauth/google.ts
192
171
  var GoogleModule = class {
193
172
  constructor(_webSignerClient) {
194
173
  this._webSignerClient = _webSignerClient;
@@ -198,16 +177,8 @@ var GoogleModule = class {
198
177
  * @returns
199
178
  */
200
179
  async init() {
201
- if (!this._webSignerClient.oauthConfiguration?.google) {
202
- throw new BadRequestError({ message: "Google OAuth is not configured" });
203
- }
204
- const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
205
- url.searchParams.set(
206
- "client_id",
207
- this._webSignerClient.oauthConfiguration.google.id
208
- );
209
- url.searchParams.set("response_type", "code");
210
- url.searchParams.set("scope", "openid email");
180
+ const initUrl = await this._webSignerClient.getOAuthInitUrl("google");
181
+ const url = new URL(initUrl);
211
182
  const internalUrl = new URL(
212
183
  "v1/oauth",
213
184
  this._webSignerClient.configuration.apiUrl
@@ -229,6 +200,25 @@ var GoogleModule = class {
229
200
  }
230
201
  };
231
202
 
203
+ // src/errors/SDKError.ts
204
+ var SDKError = class extends Error {
205
+ _props;
206
+ constructor(message, props) {
207
+ super(message);
208
+ this._props = props;
209
+ }
210
+ get message() {
211
+ return this._props.message;
212
+ }
213
+ };
214
+
215
+ // src/errors/BadRequestError.ts
216
+ var BadRequestError = class _BadRequestError extends SDKError {
217
+ constructor(props) {
218
+ super(_BadRequestError.name, props);
219
+ }
220
+ };
221
+
232
222
  // src/modules/auth/oauth/facebook.ts
233
223
  import * as jose2 from "jose";
234
224
  var FacebookModule = class {
@@ -236,9 +226,6 @@ var FacebookModule = class {
236
226
  this._webSignerClient = _webSignerClient;
237
227
  }
238
228
  async init() {
239
- if (!this._webSignerClient.oauthConfiguration?.facebook) {
240
- throw new BadRequestError({ message: "Facebook OAuth is not configured" });
241
- }
242
229
  const publicKey = await this._webSignerClient.getIframePublicKey();
243
230
  const internalUrl = new URL(
244
231
  "v1/oauth",
@@ -286,21 +273,8 @@ var AppleModule = class {
286
273
  * @returns
287
274
  */
288
275
  async init() {
289
- if (!this._webSignerClient.oauthConfiguration?.apple) {
290
- throw new BadRequestError({ message: "Apple OAuth is not configured" });
291
- }
292
- const url = new URL("https://appleid.apple.com/auth/authorize");
293
- url.searchParams.set(
294
- "client_id",
295
- this._webSignerClient.oauthConfiguration.apple.id
296
- );
297
- url.searchParams.set("response_type", "code");
298
- url.searchParams.set("response_mode", "form_post");
299
- url.searchParams.set("scope", "email");
300
- console.log(
301
- "Apple OAuth initialization started",
302
- this._webSignerClient.oauthConfiguration.common.redirectUrl
303
- );
276
+ const initUrl = await this._webSignerClient.getOAuthInitUrl("apple");
277
+ const url = new URL(initUrl);
304
278
  const internalUrl = new URL(
305
279
  "v1/oauth/apple",
306
280
  this._webSignerClient.configuration.apiUrl
@@ -479,7 +453,8 @@ var ROUTE_METHOD_MAP = {
479
453
  "/v1/email-auth": "POST",
480
454
  "/v1/lookup": "POST",
481
455
  "/v1/signin": "POST",
482
- "/v1/sign": "POST"
456
+ "/v1/sign": "POST",
457
+ "v1/oauth/init": "POST"
483
458
  };
484
459
 
485
460
  // src/signer/index.ts
@@ -886,6 +861,17 @@ var WebSignerClient = class extends SignerClient {
886
861
  this.stamper = this._stampers.iframe;
887
862
  return this._stampers.iframe.publicKey();
888
863
  }
864
+ /**
865
+ * Get the pre-filled URL for initiating oauth with a specific provider.
866
+ *
867
+ * @param {string} provider provider for which we are getting the URL, currently google or apple
868
+ */
869
+ async getOAuthInitUrl(provider) {
870
+ const { url } = await this.request("v1/oauth/init", {
871
+ provider
872
+ });
873
+ return url;
874
+ }
889
875
  };
890
876
 
891
877
  // src/third-party/viem.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/session/index.ts","../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/errors/SDKError.ts","../src/errors/BadRequestError.ts","../src/modules/auth/oauth/facebook.ts","../src/modules/auth/oauth/apple.ts","../src/modules/auth/oauth.ts","../src/modules/auth/index.ts","../src/modules/user/index.ts","../src/signer/web.ts","../src/lib/base64.ts","../src/lib/bytes.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/GenericError.ts","../src/errors/UnauthenticatedError.ts","../src/types/Routes.ts","../src/third-party/viem.ts","../src/index.ts"],"sourcesContent":["import { createStore, type StoreApi } from 'zustand'\nimport { createJSONStorage, persist } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\n/**\n * The state of the session.\n */\ntype SessionState = {\n type?: SessionType\n user?: User\n expirationDate?: Date\n bundle?: string\n token?: string\n}\n\n/**\n * A store for the session state.\n */\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n /**\n * Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.\n */\n constructor() {\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt.io-signer-session',\n storage: createJSONStorage<SessionState>(() => localStorage),\n }),\n )\n }\n\n /**\n * Gets the type from the session state.\n *\n * @returns {SessionType | undefined} the type.\n */\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n /**\n * Sets the type in the session state.\n *\n * @param {SessionType} type the type to set.\n */\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n /**\n * Gets the token from the session state.\n *\n * @returns {string | undefined} the token.\n */\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n /**\n * Sets the token in the session state.\n *\n * @param {string} token the token to set.\n */\n set token(token: string) {\n this._store.setState({ token })\n }\n\n /**\n * Gets the bundle from the session state.\n *\n * @returns {string | undefined} the bundle.\n */\n get bundle(): string | undefined {\n return this._store.getState().bundle\n }\n\n /**\n * Sets the bundle in the session state.\n *\n * @param {string} bundle the bundle to set.\n */\n set bundle(bundle: string) {\n this._store.setState({ bundle })\n }\n\n /**\n * Gets the user from the session state.\n *\n * @returns {User | undefined} the user.\n */\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n /**\n * Sets the user in the session state.\n *\n * @param {User} user the user to set.\n */\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n /**\n * Clears the user from the session state.\n */\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n /**\n * Clears the bundle from the session state.\n */\n clearBundle() {\n this._store.setState({ ...this._store.getState(), bundle: undefined })\n }\n\n /**\n * Clears the type from the session state.\n */\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n /**\n * Clears the token from the session state.\n */\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n /**\n * Clears the token and user from the session state.\n */\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearBundle()\n this.clearType()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n bundle: undefined,\n token: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { SessionType } from '../../session/index.js'\nimport type {\n WebSignerClient,\n EmailInitializeAuthParams,\n CompleteAuthWithBundleParams,\n} from '../../signer/web.js'\n\n/**\n * A module for interacting with the Email authentication methods.\n * Available through the `auth.email` property on a `FourtWebSigner` instance.\n */\nclass EmailModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Initialize user authentication process using email.\n *\n * @param params {EmailInitializeAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves to the result of the authentication process.\n */\n async initialize(params: EmailInitializeAuthParams): Promise<void> {\n return this._webSignerClient.emailAuth(params)\n }\n\n /**\n * Completes authentication with bundle after user receives the bundle and subOrgId as URL params.\n *\n * @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(\n params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>,\n ): Promise<void> {\n return this._webSignerClient.completeAuthWithBundle({\n ...params,\n sessionType: SessionType.Email,\n })\n }\n}\n\nexport { EmailModule }\n","import type { WebSignerClient, WebauthnSignInParams } from '../../signer/web.js'\n\n/**\n * A module for interacting with the Passkeys authentication methods.\n * Available through the `auth.passkeys` property on a `FourtWebSigner` instance.\n */\nclass PasskeysModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Signs in a user using Passkeys.\n *\n * @param params {WebauthnSignInParams} params for the sign-in process.\n * @returns {Promise<void>} promise that resolves to the result of the sign-in process.\n */\n async signIn(params: WebauthnSignInParams) {\n return this._webSignerClient.webauthnSignIn(params)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { BadRequestError } from '../../../errors/BadRequestError.js'\n\ntype CompleteParams = {\n credentialBundle: string\n subOrgId: string\n}\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n if (!this._webSignerClient.oauthConfiguration?.google) {\n throw new BadRequestError({ message: 'Google OAuth is not configured' })\n }\n\n const url = new URL('https://accounts.google.com/o/oauth2/v2/auth')\n url.searchParams.set(\n 'client_id',\n this._webSignerClient.oauthConfiguration.google.id,\n )\n url.searchParams.set('response_type', 'code')\n url.searchParams.set('scope', 'openid email')\n\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'google',\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { GoogleModule }\n","type SDKErrorProps = {\n message: string\n}\n\nabstract class SDKError extends Error {\n private readonly _props: SDKErrorProps\n\n constructor(message: string, props: SDKErrorProps) {\n super(message)\n this._props = props\n }\n\n get message() {\n return this._props.message\n }\n}\n\nexport { SDKError }\nexport type { SDKErrorProps }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass BadRequestError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(BadRequestError.name, props)\n }\n}\n\nexport { BadRequestError }\n","import { BadRequestError } from '../../../errors/BadRequestError.js'\nimport { WebSignerClient } from '../../../signer/web.js'\nimport * as jose from 'jose'\n\nclass FacebookModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n if (!this._webSignerClient.oauthConfiguration?.facebook) {\n throw new BadRequestError({ message: 'Facebook OAuth is not configured' })\n }\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n\n const jwt = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'facebook',\n }).encode()\n\n const response = await fetch(internalUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n state: jwt,\n }),\n })\n\n if (!response.ok) {\n throw new BadRequestError({\n message: `Failed to create OAuth state. Error: ${response.statusText}`,\n })\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError({\n message: response.statusText,\n })\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { BadRequestError } from '../../../errors/BadRequestError.js'\n\ntype CompleteParams = {\n credentialBundle: string\n subOrgId: string\n}\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n if (!this._webSignerClient.oauthConfiguration?.apple) {\n throw new BadRequestError({ message: 'Apple OAuth is not configured' })\n }\n\n const url = new URL('https://appleid.apple.com/auth/authorize')\n url.searchParams.set(\n 'client_id',\n this._webSignerClient.oauthConfiguration.apple.id,\n )\n url.searchParams.set('response_type', 'code')\n url.searchParams.set('response_mode', 'form_post')\n url.searchParams.set('scope', 'email')\n\n console.log(\n 'Apple OAuth initialization started',\n this._webSignerClient.oauthConfiguration.common.redirectUrl,\n )\n\n const internalUrl = new URL(\n 'v1/oauth/apple',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { AppleModule }\n","import { SessionType } from '../../session/index.js'\nimport type { WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\ntype CompleteParams = {\n bundle: string\n subOrgId: string\n}\n\nclass OAuthModule {\n private readonly _googleModule: GoogleModule\n private readonly _facebookModule: FacebookModule\n private readonly _appleModule: AppleModule\n\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._googleModule = new GoogleModule(this._webSignerClient)\n this._facebookModule = new FacebookModule(this._webSignerClient)\n this._appleModule = new AppleModule(this._webSignerClient)\n }\n\n get google() {\n return this._googleModule\n }\n\n get facebook() {\n return this._facebookModule\n }\n\n get apple() {\n return this._appleModule\n }\n\n async complete({ bundle, subOrgId }: CompleteParams) {\n await this._webSignerClient.completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType: SessionType.OAuth,\n })\n }\n}\n\nexport { OAuthModule }\n","import type { WebSignerClient } from '../../signer/web.js'\nimport { EmailModule } from './email.js'\nimport { PasskeysModule } from './passkeys.js'\nimport { OAuthModule } from './oauth.js'\n\n/**\n * A module for interacting with the authentication methods.\n * Available through the `auth` property on a `FourtWebSigner` instance.\n */\nclass AuthModule {\n private readonly _passkeys: PasskeysModule\n private readonly _email: EmailModule\n private readonly _oauth: OAuthModule\n\n /**\n * Initializes a new instance of the `AuthModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._passkeys = new PasskeysModule(this._webSignerClient)\n this._email = new EmailModule(this._webSignerClient)\n this._oauth = new OAuthModule(this._webSignerClient)\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get passkeys() {\n return this._passkeys\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get email() {\n return this._email\n }\n\n get oauth() {\n return this._oauth\n }\n}\n\nexport { AuthModule }\nexport { PasskeysModule } from './passkeys.js'\nexport { EmailModule } from './email.js'\n","import { WebSignerClient } from '../../signer/web.js'\nimport { User } from '../../types/entities.js'\n\n/**\n * A module for interacting with the user methods.\n * Available through the `user` property on a `FourtWebSigner` instance.\n */\nclass UserModule {\n /**\n * Initializes a new instance of the `UserModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Gets the user information.\n *\n * @returns {User | undefined} user information.\n */\n get info() {\n return this._webSignerClient.user\n }\n\n /**\n * Logs out the user.\n *\n * @returns {void}\n */\n logout() {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\nimport { IframeStamper } from '@turnkey/iframe-stamper'\nimport { WebauthnStamper } from '@turnkey/webauthn-stamper'\nimport { LibBase64 } from '../lib/base64.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { SessionType } from '../session/index.js'\nimport {\n type SignerClientInheritedConstructorParams,\n SignerClient,\n} from './index.js'\n\ntype WebauthnSignInParams = {\n email: string\n}\n\n// * When user starts auth with email - can be either a signup or a signin\ntype EmailInitializeAuthParams = {\n email: string\n redirectUrl: string\n expirationSeconds?: number // Defaults to 15 minutes by Turnkey\n}\n\n// * When user completes auth with bundle\ntype CompleteAuthWithBundleParams = {\n bundle: string\n subOrgId: string\n sessionType: SessionType\n isNewUser?: boolean\n}\n\ntype GoogleOAuthSignInParams = {\n credential: string\n clientId: string\n}\n\nexport type OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n google?: {\n id: string\n }\n facebook?: {\n id: string\n }\n apple?: {\n id: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n iframe?: {\n iframeElementId?: string\n iframeContainerId?: string\n }\n oauth?: OAuthConfiguration\n}>\n\ntype CreateAccountParams =\n | ({\n method: 'webauthn'\n } & WebauthnSignInParams)\n | ({\n method: 'email'\n } & EmailInitializeAuthParams)\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private readonly _stampers: {\n webauthn: WebauthnStamper\n iframe: IframeStamper\n }\n\n readonly oauthConfiguration: WebSignerClientConstructorParams['oauth']\n\n /**\n * Initializes a new instance of the `WebSignerClient` class.\n *\n * @param {WebSignerClientConstructorParams} params params for the constructor\n */\n constructor({\n configuration,\n webauthn,\n iframe,\n oauth,\n }: WebSignerClientConstructorParams) {\n const iframeContainerId =\n iframe?.iframeContainerId ?? 'fourt-signer-iframe-container'\n const iframeContainer = document.createElement('div')\n iframeContainer.id = iframeContainerId\n iframeContainer.style.display = 'none'\n document.body.appendChild(iframeContainer)\n\n const webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n const iframeStamper = new IframeStamper({\n iframeUrl: 'https://auth.turnkey.com',\n iframeElementId: iframe?.iframeElementId ?? 'turnkey-iframe',\n iframeContainer: document.getElementById(iframeContainerId),\n })\n\n super({\n stamper: iframeStamper, // Initialized to iframeStamper; can be either webauthnStamper or iframeStamper\n configuration: configuration,\n })\n\n this._stampers = {\n webauthn: webauthnStamper,\n iframe: iframeStamper,\n }\n\n this.oauthConfiguration = oauth\n }\n\n public override async signRawMessage<Into extends string>(\n msg: string,\n ): Promise<Into> {\n await this.updateStamper()\n return super.signRawMessage(msg)\n }\n\n public override async logout() {\n this._stampers.iframe.clear()\n await this._stampers.iframe.init()\n return super.logout()\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n *\n */\n private async updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n (this._sessionStore.bundle === undefined ||\n this._sessionStore.token === undefined)\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this._stampers.webauthn\n } else {\n this.stamper = this._stampers.iframe\n // We need to inject to inject the credential bundle\n // Otherwise the user will not be able to sign\n await this.completeAuthWithBundle({\n bundle: this._sessionStore.bundle!,\n subOrgId: this.user?.subOrgId!,\n sessionType: this._sessionStore.type!,\n })\n }\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {WebauthnSignInParams} params params for the sign in\n */\n async webauthnSignIn({ email }: WebauthnSignInParams) {\n const existingUserSubOrgId = await this.lookUpUser(email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'webauthn', email })\n } else {\n this.stamper = this._stampers.webauthn\n await this.whoAmI(existingUserSubOrgId)\n\n this._sessionStore.type = SessionType.Passkeys\n\n // We should assure that the user and its credentialId are set\n if (!this.user || !this.user.credentialId) {\n return\n }\n\n this._stampers.webauthn.allowCredentials = [\n {\n id: LibBase64.toBuffer(this.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handle auth user process with email.\n *\n * @param {EmailInitializeAuthParams} params Params needed for the initialization of the auth process\n */\n async emailAuth(params: EmailInitializeAuthParams) {\n const existingUserSubOrgId = await this.lookUpUser(params.email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'email', ...params })\n } else {\n await this._signInWithEmail(params)\n }\n }\n\n async getIframePublicKey() {\n return await this._initIframeStamper()\n }\n\n /**\n * Signs in a user with email.\n *\n * @param {EmailInitializeAuthParams} params params for the sign in\n */\n private async _signInWithEmail({\n email,\n expirationSeconds,\n redirectUrl,\n }: EmailInitializeAuthParams) {\n return this.request('/v1/email-auth', {\n email,\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n })\n }\n\n /**\n * Completes the authentication process with a credential bundle.\n *\n * @param {CompleteAuthWithBundleParams} params params for the completion of the auth process\n */\n public async completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType,\n }: CompleteAuthWithBundleParams): Promise<void> {\n await this._initIframeStamper()\n\n const result = await this._stampers.iframe.injectCredentialBundle(bundle)\n\n if (!result) {\n throw new Error('Failed to inject credential bundle')\n }\n\n await this.whoAmI(subOrgId)\n\n this._sessionStore.type = sessionType\n this._sessionStore.bundle = bundle\n }\n\n /**\n * Creates a passkey account using the webauthn stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'webauthn' }>} params params for the creation of the account\n */\n private async _createWebauthnAccount(\n params: Extract<CreateAccountParams, { method: 'webauthn' }>,\n ) {\n const { challenge, attestation } = await this._webauthnGenerateAttestation(\n params.email,\n )\n\n const {\n token,\n user: { id, email, subOrgId, walletAddress, salt, smartAccountAddress },\n } = await this.request('/v1/signup', {\n passkey: {\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n },\n email: params.email,\n })\n\n this.user = {\n id,\n email,\n subOrgId,\n walletAddress,\n salt,\n smartAccountAddress,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.user = this.user\n this._sessionStore.type = SessionType.Passkeys\n this._sessionStore.token = token\n }\n\n /**\n * Creates an email account using the iframe stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account\n */\n private async _createEmailAccount(\n params: Extract<CreateAccountParams, { method: 'email' }>,\n ) {\n const { email, expirationSeconds, redirectUrl } =\n params as EmailInitializeAuthParams\n\n const response = await this.request('/v1/signup', {\n email,\n iframe: {\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n },\n })\n\n return response\n }\n\n /**\n * Handle the account creation process.\n *\n * @param {CreateAccountParams} params params to create an account\n */\n private async _createAccount(params: CreateAccountParams) {\n switch (params.method) {\n case 'webauthn': {\n await this._createWebauthnAccount(params)\n break\n }\n case 'email': {\n await this._createEmailAccount(params)\n break\n }\n }\n }\n\n private async _webauthnGenerateAttestation(email: string) {\n const challenge = LibBytes.generateRandomBuffer()\n const authenticatorUserId = LibBytes.generateRandomBuffer()\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n authenticatorSelection: {\n residentKey: 'preferred',\n requireResidentKey: false,\n userVerification: 'preferred',\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\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: email,\n displayName: email,\n },\n },\n })\n\n return { challenge, attestation, authenticatorUserId }\n }\n\n private async _initIframeStamper() {\n if (!this._stampers.iframe.publicKey()) {\n await this._stampers.iframe.init()\n }\n\n this.stamper = this._stampers.iframe\n\n return this._stampers.iframe.publicKey()!\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteAuthWithBundleParams,\n CreateAccountParams,\n EmailInitializeAuthParams,\n GoogleOAuthSignInParams,\n WebauthnSignInParams,\n WebSignerClientConstructorParams,\n}\n","import { Buffer } from 'buffer'\n\nclass LibBase64 {\n static fromBuffer(buffer: ArrayBuffer): string {\n return Buffer.from(buffer)\n .toString('base64')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=/g, '')\n }\n\n static toBuffer(base64: string): ArrayBuffer {\n return Buffer.from(base64, 'base64').buffer\n }\n}\n\nexport { LibBase64 }\n","type TakeBytesParams = Partial<{\n count: number\n offset: number\n}>\n\ntype ByteString = `0x${string}`\n\nclass LibBytes {\n static generateRandomBuffer = (): ArrayBuffer => {\n const arr = new Uint8Array(32)\n crypto.getRandomValues(arr)\n return arr.buffer\n }\n\n static takeBytes = (\n bytes: ByteString,\n params: TakeBytesParams = {},\n ): ByteString => {\n const { offset, count } = params\n const start = (offset ? offset * 2 : 0) + 2 // add 2 to skip the 0x prefix\n const end = count ? start + count * 2 : undefined\n\n return `0x${bytes.slice(start, end)}`\n }\n}\n\nexport { LibBytes }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n GenericError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport { SessionStore } from '../session/index.js'\nimport { User } from '../types/entities.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n AuthenticationServiceRoutes,\n ROUTE_METHOD_MAP,\n} from '../types/Routes.js'\nimport { jwtDecode, JwtPayload } from 'jwt-decode'\nimport { isPast, secondsToMilliseconds } from 'date-fns'\n\ntype SignerClientConfiguration = {\n apiKey: string\n apiUrl?: string\n paymasterRpcUrl?: string\n}\n\ntype SignerClientConstructorParams = {\n stamper: TurnkeyClient['stamper']\n configuration: SignerClientConfiguration\n}\n\ntype SignerClientInheritedConstructorParams<\n Extended extends Record<string, unknown>,\n> = Pick<SignerClientConstructorParams, 'configuration'> & Extended\n\nabstract class SignerClient {\n protected readonly _turnkeyClient: TurnkeyClient\n protected readonly _configuration: Required<\n SignerClientConstructorParams['configuration']\n >\n protected readonly _sessionStore: SessionStore\n\n private _user?: User\n\n constructor({\n stamper,\n configuration: { apiUrl, paymasterRpcUrl, ...requiredConfiguration },\n }: SignerClientConstructorParams) {\n this._turnkeyClient = new TurnkeyClient(\n { baseUrl: 'https://api.turnkey.com' },\n stamper,\n )\n\n this._configuration = {\n ...requiredConfiguration,\n apiUrl: apiUrl ?? 'https://auth.api.fourt.io/',\n paymasterRpcUrl: paymasterRpcUrl ?? 'https://management.api.fourt.io/',\n }\n\n this._sessionStore = new SessionStore()\n }\n\n logout() {\n this._user = undefined\n this.sessionStore.clearAll()\n }\n\n get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n get user(): User | undefined {\n if (this._user) return this._user\n\n // Check if there's a token\n if (!this.sessionStore.token) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n const decodedToken = jwtDecode<JwtPayload>(this.sessionStore.token)\n // Check if the token has expired\n if (\n decodedToken.exp &&\n isPast(new Date(secondsToMilliseconds(decodedToken.exp)))\n ) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n if (this.sessionStore.user) this._user = this.sessionStore.user\n\n return this._user\n }\n\n protected set user(value: User | undefined) {\n this._user = value\n }\n\n protected set stamper(stamper: TurnkeyClient['stamper']) {\n this._turnkeyClient.stamper = stamper\n }\n\n protected get stamper(): TurnkeyClient['stamper'] {\n return this._turnkeyClient.stamper\n }\n\n protected get sessionStore(): SessionStore {\n return this._sessionStore\n }\n\n async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._user) {\n throw new UnauthorizedError({\n message: 'SignerClient must be authenticated to sign a message',\n })\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._user.subOrgId,\n type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',\n timestampMs: Date.now().toString(),\n parameters: {\n encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',\n hashFunction: 'HASH_FUNCTION_NO_OP',\n payload: msg,\n signWith: this._user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', {\n stampedRequest,\n })\n\n return <Into>signature\n }\n\n protected async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', { email })\n return subOrgId\n } catch (error) {\n if (!(error instanceof SDKError)) throw error\n\n const sdkError: SDKError = error\n\n switch (sdkError.constructor.name) {\n case NotFoundError.name: {\n return null\n }\n default: {\n throw sdkError\n }\n }\n }\n }\n\n protected async whoAmI(subOrgId?: string) {\n const orgId = subOrgId || this._user?.subOrgId\n\n if (!orgId) throw new BadRequestError({ message: 'No orgId provided' })\n\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: orgId,\n })\n\n const { user, token } = await this.request('/v1/signin', {\n stampedRequest,\n })\n\n const credentialId = (() => {\n try {\n return JSON.parse(stampedRequest?.stamp.stampHeaderValue)\n .credentialId as string\n } catch (e) {\n return undefined\n }\n })()\n\n this._user = {\n ...user,\n credentialId: credentialId,\n }\n\n this.sessionStore.user = this.user!\n this.sessionStore.token = token\n }\n\n protected async request<Route extends AuthenticationServiceRoutes>(\n route: Route,\n body?: AuthenticationServiceBody<Route>,\n ): Promise<AuthenticationServiceResponse<Route>> {\n const url = new URL(`${route}`, this._configuration.apiUrl)\n const token = this.sessionStore.token\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-FOURT-KEY': this._configuration.apiKey,\n }\n\n // Add Authorization header if token exists\n if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method: ROUTE_METHOD_MAP[route],\n body: JSON.stringify(body),\n headers,\n credentials: 'include',\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<Route>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n // TODO: workaround! this need to be cleaned up and moved into the web signer\n this.logout()\n throw new UnauthorizedError({ message: error.message })\n }\n case 'NotFoundError': {\n throw new NotFoundError({ message: error.message })\n }\n case 'BadRequestError': {\n throw new BadRequestError({ message: error.message })\n }\n default: {\n throw new GenericError({ message: error.message })\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<Route>\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthorizedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthorizedError.name, props)\n }\n}\n\nexport { UnauthorizedError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass NotFoundError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(NotFoundError.name, props)\n }\n}\n\nexport { NotFoundError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass GenericError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(GenericError.name, props)\n }\n}\n\nexport { GenericError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthenticatedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthenticatedError.name, props)\n }\n}\n\nexport { UnauthenticatedError }\n","import { getWebAuthnAttestation, TSignedRequest } from '@turnkey/http'\nimport { User } from './entities.js'\nimport { AtLeastOne } from './string.js'\n\ntype AuthenticationServiceRoutes =\n AuthenticationServiceEndpoints[number]['Route']\n\ntype AuthenticationServiceBody<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Body']\n\ntype AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Response']\n\ntype AuthenticationServiceEndpoints = [\n {\n Route: '/v1/email-auth'\n Body: {\n email: string\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signup'\n Body: AtLeastOne<{\n passkey: {\n challenge: string\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>\n }\n iframe: {\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n }> & { email: string }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/lookup'\n Body: {\n email: string\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signin'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/sign'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n signature: string\n }\n },\n]\n\nconst ROUTE_METHOD_MAP = {\n '/v1/signup': 'POST',\n '/v1/email-auth': 'POST',\n '/v1/lookup': 'POST',\n '/v1/signin': 'POST',\n '/v1/sign': 'POST',\n} satisfies Record<AuthenticationServiceRoutes, 'POST' | 'GET'>\n\nexport type {\n AuthenticationServiceEndpoints,\n AuthenticationServiceResponse,\n AuthenticationServiceBody,\n AuthenticationServiceRoutes,\n}\n\nexport { ROUTE_METHOD_MAP }\n","import {\n LocalAccount,\n TypedData,\n TypedDataDefinition,\n SignableMessage,\n Hex,\n hashMessage,\n hashTypedData,\n SerializeTransactionFn,\n TransactionSerializable,\n IsNarrowable,\n TransactionSerialized,\n GetTransactionType,\n serializeTransaction,\n keccak256,\n Client,\n hexToBigInt,\n http,\n} from 'viem'\nimport { toAccount } from 'viem/accounts'\nimport { SignerClient } from '../signer/index.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { toLightSmartAccount } from 'permissionless/accounts'\nimport {\n createPaymasterClient,\n entryPoint07Address,\n} from 'viem/account-abstraction'\nimport { UnauthenticatedError } from '../errors/UnauthenticatedError.js'\n\ntype ViemModuleConstructorParams = {\n refs: {\n signerClient: SignerClient\n }\n}\n\ntype CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: (msg) => this.signMessage(msg.message),\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>,\n ) => this.signTypedData<typedData, primaryType>(typedDataDefinition),\n signTransaction: this.signTransaction,\n })\n }\n\n async toSmartAccount({\n client,\n owner,\n }: CurrentUserToLightSmartAccountParams): ReturnType<\n typeof toLightSmartAccount<'0.7'>\n > {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toLightSmartAccount({\n client: client,\n owner,\n version: '2.0.0',\n entryPoint: {\n address: entryPoint07Address,\n version: '0.7',\n },\n address: user.smartAccountAddress,\n index: hexToBigInt(user.salt),\n })\n }\n\n async getPaymasterClient() {\n const url = new URL(\n `v1/rpc?apiKey=${this._signerClient.configuration.apiKey}`,\n this._signerClient.configuration.paymasterRpcUrl,\n )\n return createPaymasterClient({\n transport: http(url.toString()),\n })\n }\n\n async signMessage(msg: SignableMessage): Promise<Hex> {\n const messageHash = hashMessage(msg)\n const result = await this._signerClient.signRawMessage<Hex>(messageHash)\n return result\n }\n\n async signTypedData<\n TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {\n const messageHash = hashTypedData(params)\n return this._signerClient.signRawMessage(messageHash)\n }\n\n async signTransaction<\n serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,\n transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],\n >(\n transaction: transaction,\n options?:\n | {\n serializer?: serializer | undefined\n }\n | undefined,\n ): Promise<\n IsNarrowable<\n TransactionSerialized<GetTransactionType<transaction>>,\n Hex\n > extends true\n ? TransactionSerialized<GetTransactionType<transaction>>\n : Hex\n > {\n const serializeFn = options?.serializer ?? serializeTransaction\n const serializedTx = serializeFn(transaction)\n const signatureHex = await this._signerClient.signRawMessage<Hex>(\n keccak256(serializedTx),\n )\n\n const signature = {\n r: LibBytes.takeBytes(signatureHex, { count: 32 }),\n s: LibBytes.takeBytes(signatureHex, { count: 32, offset: 32 }),\n v: BigInt(LibBytes.takeBytes(signatureHex, { count: 1, offset: 64 })),\n }\n\n return serializeFn(transaction, signature)\n }\n}\n\nexport { ViemModule }\n","import { AuthModule, UserModule } from './modules/index.js'\nimport { SignerClientConstructorParams } from './signer/index.js'\nimport {\n WebSignerClient,\n WebSignerClientConstructorParams,\n} from './signer/web.js'\nimport { ViemModule } from './third-party/viem.js'\n\ntype FourtWebSignerConstructorParams = {\n configuration: SignerClientConstructorParams['configuration']\n auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'iframe' | 'oauth'>\n}\n\n/**\n * A client for interacting with the Fourt Web Signer.\n */\nclass FourtWebSigner {\n private readonly _webSignerClient: WebSignerClient\n private readonly _modules: {\n viem: ViemModule\n auth: AuthModule\n user: UserModule\n }\n\n /**\n * Initializes a new instance of the `FourtWebSigner` class.\n * Sets up the underlying modules.\n *\n *\n * @example\n * ```ts\n * const fourtWebSigner = new FourtWebSigner({\n * auth: {\n * webauthn: {\n * rpId: 'localhost',\n * },\n * },\n * configuration: {\n * apiKey: '927d603c-6775-4210-8e13-8904ca985e78',\n * },\n * })\n * ```\n *\n * @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client\n */\n constructor({\n configuration,\n auth: { webauthn, iframe, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\n iframe,\n oauth,\n })\n\n this._modules = {\n viem: new ViemModule(this._webSignerClient),\n auth: new AuthModule(this._webSignerClient),\n user: new UserModule(this._webSignerClient),\n }\n }\n\n /**\n * A module for interacting with the Viem library.\n */\n get viem() {\n return this._modules.viem\n }\n\n /**\n * A module for interacting with the authentication methods.\n */\n get auth() {\n return this._modules.auth\n }\n\n /**\n * A module for interacting with the user methods.\n */\n get user() {\n return this._modules.user\n }\n}\n\nexport { FourtWebSigner }\n"],"mappings":";AAAA,SAAS,mBAAkC;AAC3C,SAAS,mBAAmB,eAAe;AAuB3C,IAAM,eAAN,MAAmB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKjB,cAAc;AACZ,SAAK,SAAS,YAA0B;AAAA,MACtC,QAAQ,KAAK,kBAAkB;AAAA,QAC7B,MAAM;AAAA,QACN,SAAS,kBAAgC,MAAM,YAAY;AAAA,MAC7D,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAgC;AAClC,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,KAAK,MAAmB;AAC1B,SAAK,OAAO,SAAS,EAAE,KAAK,CAAC;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,QAA4B;AAC9B,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MAAM,OAAe;AACvB,SAAK,OAAO,SAAS,EAAE,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,SAA6B;AAC/B,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAO,QAAgB;AACzB,SAAK,OAAO,SAAS,EAAE,OAAO,CAAC;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAyB;AAC3B,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA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AE,UAAU,QAAQ,MAAM;AAAA,EAClC,GAAoC;AAClC,SAAK,mBAAmB,IAAI,gBAAgB;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,SAAK,WAAW;AAAA,MACd,MAAM,IAAI,WAAW,KAAK,gBAAgB;AAAA,MAC1C,MAAM,IAAI,WAAW,KAAK,gBAAgB;AAAA,MAC1C,MAAM,IAAI,WAAW,KAAK,gBAAgB;AAAA,IAC5C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AACF;","names":["jose","jose","sha256","sha256"]}
1
+ {"version":3,"sources":["../src/session/index.ts","../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/errors/SDKError.ts","../src/errors/BadRequestError.ts","../src/modules/auth/oauth/facebook.ts","../src/modules/auth/oauth/apple.ts","../src/modules/auth/oauth.ts","../src/modules/auth/index.ts","../src/modules/user/index.ts","../src/signer/web.ts","../src/lib/base64.ts","../src/lib/bytes.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/GenericError.ts","../src/errors/UnauthenticatedError.ts","../src/types/Routes.ts","../src/third-party/viem.ts","../src/index.ts"],"sourcesContent":["import { createStore, type StoreApi } from 'zustand'\nimport { createJSONStorage, persist } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\n/**\n * The state of the session.\n */\ntype SessionState = {\n type?: SessionType\n user?: User\n expirationDate?: Date\n bundle?: string\n token?: string\n}\n\n/**\n * A store for the session state.\n */\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n /**\n * Initializes a new instance of the `SessionStore` class by creating a new `zustand`store with the initial state.\n */\n constructor() {\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt.io-signer-session',\n storage: createJSONStorage<SessionState>(() => localStorage),\n }),\n )\n }\n\n /**\n * Gets the type from the session state.\n *\n * @returns {SessionType | undefined} the type.\n */\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n /**\n * Sets the type in the session state.\n *\n * @param {SessionType} type the type to set.\n */\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n /**\n * Gets the token from the session state.\n *\n * @returns {string | undefined} the token.\n */\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n /**\n * Sets the token in the session state.\n *\n * @param {string} token the token to set.\n */\n set token(token: string) {\n this._store.setState({ token })\n }\n\n /**\n * Gets the bundle from the session state.\n *\n * @returns {string | undefined} the bundle.\n */\n get bundle(): string | undefined {\n return this._store.getState().bundle\n }\n\n /**\n * Sets the bundle in the session state.\n *\n * @param {string} bundle the bundle to set.\n */\n set bundle(bundle: string) {\n this._store.setState({ bundle })\n }\n\n /**\n * Gets the user from the session state.\n *\n * @returns {User | undefined} the user.\n */\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n /**\n * Sets the user in the session state.\n *\n * @param {User} user the user to set.\n */\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n /**\n * Clears the user from the session state.\n */\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n /**\n * Clears the bundle from the session state.\n */\n clearBundle() {\n this._store.setState({ ...this._store.getState(), bundle: undefined })\n }\n\n /**\n * Clears the type from the session state.\n */\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n /**\n * Clears the token from the session state.\n */\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n /**\n * Clears the token and user from the session state.\n */\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearBundle()\n this.clearType()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n bundle: undefined,\n token: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { SessionType } from '../../session/index.js'\nimport type {\n WebSignerClient,\n EmailInitializeAuthParams,\n CompleteAuthWithBundleParams,\n} from '../../signer/web.js'\n\n/**\n * A module for interacting with the Email authentication methods.\n * Available through the `auth.email` property on a `FourtWebSigner` instance.\n */\nclass EmailModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Initialize user authentication process using email.\n *\n * @param params {EmailInitializeAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves to the result of the authentication process.\n */\n async initialize(params: EmailInitializeAuthParams): Promise<void> {\n return this._webSignerClient.emailAuth(params)\n }\n\n /**\n * Completes authentication with bundle after user receives the bundle and subOrgId as URL params.\n *\n * @param params {CompleteAuthWithBundleParams} params received as URL params necessary to complete authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(\n params: Pick<CompleteAuthWithBundleParams, 'subOrgId' | 'bundle'>,\n ): Promise<void> {\n return this._webSignerClient.completeAuthWithBundle({\n ...params,\n sessionType: SessionType.Email,\n })\n }\n}\n\nexport { EmailModule }\n","import type { WebSignerClient, WebauthnSignInParams } from '../../signer/web.js'\n\n/**\n * A module for interacting with the Passkeys authentication methods.\n * Available through the `auth.passkeys` property on a `FourtWebSigner` instance.\n */\nclass PasskeysModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Signs in a user using Passkeys.\n *\n * @param params {WebauthnSignInParams} params for the sign-in process.\n * @returns {Promise<void>} promise that resolves to the result of the sign-in process.\n */\n async signIn(params: WebauthnSignInParams) {\n return this._webSignerClient.webauthnSignIn(params)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n const initUrl = await this._webSignerClient.getOAuthInitUrl('google')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'google',\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { GoogleModule }\n","type SDKErrorProps = {\n message: string\n}\n\nabstract class SDKError extends Error {\n private readonly _props: SDKErrorProps\n\n constructor(message: string, props: SDKErrorProps) {\n super(message)\n this._props = props\n }\n\n get message() {\n return this._props.message\n }\n}\n\nexport { SDKError }\nexport type { SDKErrorProps }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass BadRequestError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(BadRequestError.name, props)\n }\n}\n\nexport { BadRequestError }\n","import { BadRequestError } from '../../../errors/BadRequestError.js'\nimport { WebSignerClient } from '../../../signer/web.js'\nimport * as jose from 'jose'\n\nclass FacebookModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n const publicKey = await this._webSignerClient.getIframePublicKey()\n const internalUrl = new URL(\n 'v1/oauth',\n this._webSignerClient.configuration.apiUrl,\n ).href\n\n const jwt = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n provider: 'facebook',\n }).encode()\n\n const response = await fetch(internalUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n state: jwt,\n }),\n })\n\n if (!response.ok) {\n throw new BadRequestError({\n message: `Failed to create OAuth state. Error: ${response.statusText}`,\n })\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError({\n message: response.statusText,\n })\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport { sha256 } from 'sha.js'\nimport type { WebSignerClient } from '../../../signer/web.js'\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n *\n * @returns\n */\n async init(): Promise<string> {\n const initUrl = await this._webSignerClient.getOAuthInitUrl('apple')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth/apple',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getIframePublicKey()\n\n const nonce = new sha256().update(publicKey).digest('hex')\n url.searchParams.set('nonce', nonce)\n\n const state = new jose.UnsecuredJWT({\n apiKey: this._webSignerClient.configuration.apiKey,\n redirectUrl: this._webSignerClient.oauthConfiguration!.common.redirectUrl,\n targetPublicKey: publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\n }).encode()\n url.searchParams.set('state', state)\n\n return url.toString()\n }\n}\n\nexport { AppleModule }\n","import { SessionType } from '../../session/index.js'\nimport type { WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\ntype CompleteParams = {\n bundle: string\n subOrgId: string\n}\n\nclass OAuthModule {\n private readonly _googleModule: GoogleModule\n private readonly _facebookModule: FacebookModule\n private readonly _appleModule: AppleModule\n\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._googleModule = new GoogleModule(this._webSignerClient)\n this._facebookModule = new FacebookModule(this._webSignerClient)\n this._appleModule = new AppleModule(this._webSignerClient)\n }\n\n get google() {\n return this._googleModule\n }\n\n get facebook() {\n return this._facebookModule\n }\n\n get apple() {\n return this._appleModule\n }\n\n async complete({ bundle, subOrgId }: CompleteParams) {\n await this._webSignerClient.completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType: SessionType.OAuth,\n })\n }\n}\n\nexport { OAuthModule }\n","import type { WebSignerClient } from '../../signer/web.js'\nimport { EmailModule } from './email.js'\nimport { PasskeysModule } from './passkeys.js'\nimport { OAuthModule } from './oauth.js'\n\n/**\n * A module for interacting with the authentication methods.\n * Available through the `auth` property on a `FourtWebSigner` instance.\n */\nclass AuthModule {\n private readonly _passkeys: PasskeysModule\n private readonly _email: EmailModule\n private readonly _oauth: OAuthModule\n\n /**\n * Initializes a new instance of the `AuthModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {\n this._passkeys = new PasskeysModule(this._webSignerClient)\n this._email = new EmailModule(this._webSignerClient)\n this._oauth = new OAuthModule(this._webSignerClient)\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get passkeys() {\n return this._passkeys\n }\n\n /**\n * A module for interacting with the Passkeys authentication methods.\n */\n get email() {\n return this._email\n }\n\n get oauth() {\n return this._oauth\n }\n}\n\nexport { AuthModule }\nexport { PasskeysModule } from './passkeys.js'\nexport { EmailModule } from './email.js'\n","import { WebSignerClient } from '../../signer/web.js'\nimport { User } from '../../types/entities.js'\n\n/**\n * A module for interacting with the user methods.\n * Available through the `user` property on a `FourtWebSigner` instance.\n */\nclass UserModule {\n /**\n * Initializes a new instance of the `UserModule` class.\n *\n * @param {WebSignerClient} _webSignerClient underlying WebSigner client instance.\n */\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n /**\n * Gets the user information.\n *\n * @returns {User | undefined} user information.\n */\n get info() {\n return this._webSignerClient.user\n }\n\n /**\n * Logs out the user.\n *\n * @returns {void}\n */\n logout() {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\nimport { IframeStamper } from '@turnkey/iframe-stamper'\nimport { WebauthnStamper } from '@turnkey/webauthn-stamper'\nimport { LibBase64 } from '../lib/base64.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { SessionType } from '../session/index.js'\nimport {\n type SignerClientInheritedConstructorParams,\n SignerClient,\n} from './index.js'\n\ntype WebauthnSignInParams = {\n email: string\n}\n\n// * When user starts auth with email - can be either a signup or a signin\ntype EmailInitializeAuthParams = {\n email: string\n redirectUrl: string\n expirationSeconds?: number // Defaults to 15 minutes by Turnkey\n}\n\n// * When user completes auth with bundle\ntype CompleteAuthWithBundleParams = {\n bundle: string\n subOrgId: string\n sessionType: SessionType\n isNewUser?: boolean\n}\n\ntype GoogleOAuthSignInParams = {\n credential: string\n clientId: string\n}\n\nexport type OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n iframe?: {\n iframeElementId?: string\n iframeContainerId?: string\n }\n oauth?: OAuthConfiguration\n}>\n\ntype CreateAccountParams =\n | ({\n method: 'webauthn'\n } & WebauthnSignInParams)\n | ({\n method: 'email'\n } & EmailInitializeAuthParams)\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private readonly _stampers: {\n webauthn: WebauthnStamper\n iframe: IframeStamper\n }\n\n readonly oauthConfiguration: WebSignerClientConstructorParams['oauth']\n\n /**\n * Initializes a new instance of the `WebSignerClient` class.\n *\n * @param {WebSignerClientConstructorParams} params params for the constructor\n */\n constructor({\n configuration,\n webauthn,\n iframe,\n oauth,\n }: WebSignerClientConstructorParams) {\n const iframeContainerId =\n iframe?.iframeContainerId ?? 'fourt-signer-iframe-container'\n const iframeContainer = document.createElement('div')\n iframeContainer.id = iframeContainerId\n iframeContainer.style.display = 'none'\n document.body.appendChild(iframeContainer)\n\n const webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n const iframeStamper = new IframeStamper({\n iframeUrl: 'https://auth.turnkey.com',\n iframeElementId: iframe?.iframeElementId ?? 'turnkey-iframe',\n iframeContainer: document.getElementById(iframeContainerId),\n })\n\n super({\n stamper: iframeStamper, // Initialized to iframeStamper; can be either webauthnStamper or iframeStamper\n configuration: configuration,\n })\n\n this._stampers = {\n webauthn: webauthnStamper,\n iframe: iframeStamper,\n }\n\n this.oauthConfiguration = oauth\n }\n\n public override async signRawMessage<Into extends string>(\n msg: string,\n ): Promise<Into> {\n await this.updateStamper()\n return super.signRawMessage(msg)\n }\n\n public override async logout() {\n this._stampers.iframe.clear()\n await this._stampers.iframe.init()\n return super.logout()\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n *\n */\n private async updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n (this._sessionStore.bundle === undefined ||\n this._sessionStore.token === undefined)\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this._stampers.webauthn\n } else {\n this.stamper = this._stampers.iframe\n // We need to inject to inject the credential bundle\n // Otherwise the user will not be able to sign\n await this.completeAuthWithBundle({\n bundle: this._sessionStore.bundle!,\n subOrgId: this.user?.subOrgId!,\n sessionType: this._sessionStore.type!,\n })\n }\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {WebauthnSignInParams} params params for the sign in\n */\n async webauthnSignIn({ email }: WebauthnSignInParams) {\n const existingUserSubOrgId = await this.lookUpUser(email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'webauthn', email })\n } else {\n this.stamper = this._stampers.webauthn\n await this.whoAmI(existingUserSubOrgId)\n\n this._sessionStore.type = SessionType.Passkeys\n\n // We should assure that the user and its credentialId are set\n if (!this.user || !this.user.credentialId) {\n return\n }\n\n this._stampers.webauthn.allowCredentials = [\n {\n id: LibBase64.toBuffer(this.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handle auth user process with email.\n *\n * @param {EmailInitializeAuthParams} params Params needed for the initialization of the auth process\n */\n async emailAuth(params: EmailInitializeAuthParams) {\n const existingUserSubOrgId = await this.lookUpUser(params.email)\n\n if (!existingUserSubOrgId) {\n await this._createAccount({ method: 'email', ...params })\n } else {\n await this._signInWithEmail(params)\n }\n }\n\n async getIframePublicKey() {\n return await this._initIframeStamper()\n }\n\n /**\n * Signs in a user with email.\n *\n * @param {EmailInitializeAuthParams} params params for the sign in\n */\n private async _signInWithEmail({\n email,\n expirationSeconds,\n redirectUrl,\n }: EmailInitializeAuthParams) {\n return this.request('/v1/email-auth', {\n email,\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n })\n }\n\n /**\n * Completes the authentication process with a credential bundle.\n *\n * @param {CompleteAuthWithBundleParams} params params for the completion of the auth process\n */\n public async completeAuthWithBundle({\n bundle,\n subOrgId,\n sessionType,\n }: CompleteAuthWithBundleParams): Promise<void> {\n await this._initIframeStamper()\n\n const result = await this._stampers.iframe.injectCredentialBundle(bundle)\n\n if (!result) {\n throw new Error('Failed to inject credential bundle')\n }\n\n await this.whoAmI(subOrgId)\n\n this._sessionStore.type = sessionType\n this._sessionStore.bundle = bundle\n }\n\n /**\n * Creates a passkey account using the webauthn stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'webauthn' }>} params params for the creation of the account\n */\n private async _createWebauthnAccount(\n params: Extract<CreateAccountParams, { method: 'webauthn' }>,\n ) {\n const { challenge, attestation } = await this._webauthnGenerateAttestation(\n params.email,\n )\n\n const {\n token,\n user: { id, email, subOrgId, walletAddress, salt, smartAccountAddress },\n } = await this.request('/v1/signup', {\n passkey: {\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n },\n email: params.email,\n })\n\n this.user = {\n id,\n email,\n subOrgId,\n walletAddress,\n salt,\n smartAccountAddress,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.user = this.user\n this._sessionStore.type = SessionType.Passkeys\n this._sessionStore.token = token\n }\n\n /**\n * Creates an email account using the iframe stamper.\n *\n * @param {Extract<CreateAccountParams, { method: 'email' }>} params params for the creation of the account\n */\n private async _createEmailAccount(\n params: Extract<CreateAccountParams, { method: 'email' }>,\n ) {\n const { email, expirationSeconds, redirectUrl } =\n params as EmailInitializeAuthParams\n\n const response = await this.request('/v1/signup', {\n email,\n iframe: {\n targetPublicKey: await this.getIframePublicKey(),\n expirationSeconds,\n redirectUrl: redirectUrl.toString(),\n },\n })\n\n return response\n }\n\n /**\n * Handle the account creation process.\n *\n * @param {CreateAccountParams} params params to create an account\n */\n private async _createAccount(params: CreateAccountParams) {\n switch (params.method) {\n case 'webauthn': {\n await this._createWebauthnAccount(params)\n break\n }\n case 'email': {\n await this._createEmailAccount(params)\n break\n }\n }\n }\n\n private async _webauthnGenerateAttestation(email: string) {\n const challenge = LibBytes.generateRandomBuffer()\n const authenticatorUserId = LibBytes.generateRandomBuffer()\n\n const attestation = await getWebAuthnAttestation({\n publicKey: {\n authenticatorSelection: {\n residentKey: 'preferred',\n requireResidentKey: false,\n userVerification: 'preferred',\n },\n challenge,\n rp: {\n id: window.location.hostname,\n name: window.location.hostname,\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: email,\n displayName: email,\n },\n },\n })\n\n return { challenge, attestation, authenticatorUserId }\n }\n\n private async _initIframeStamper() {\n if (!this._stampers.iframe.publicKey()) {\n await this._stampers.iframe.init()\n }\n\n this.stamper = this._stampers.iframe\n\n return this._stampers.iframe.publicKey()!\n }\n\n /**\n * Get the pre-filled URL for initiating oauth with a specific provider.\n *\n * @param {string} provider provider for which we are getting the URL, currently google or apple\n */\n public async getOAuthInitUrl(provider: string) {\n const { url } = await this.request('v1/oauth/init', {\n provider,\n })\n\n return url\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteAuthWithBundleParams,\n CreateAccountParams,\n EmailInitializeAuthParams,\n GoogleOAuthSignInParams,\n WebauthnSignInParams,\n WebSignerClientConstructorParams,\n}\n","import { Buffer } from 'buffer'\n\nclass LibBase64 {\n static fromBuffer(buffer: ArrayBuffer): string {\n return Buffer.from(buffer)\n .toString('base64')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=/g, '')\n }\n\n static toBuffer(base64: string): ArrayBuffer {\n return Buffer.from(base64, 'base64').buffer\n }\n}\n\nexport { LibBase64 }\n","type TakeBytesParams = Partial<{\n count: number\n offset: number\n}>\n\ntype ByteString = `0x${string}`\n\nclass LibBytes {\n static generateRandomBuffer = (): ArrayBuffer => {\n const arr = new Uint8Array(32)\n crypto.getRandomValues(arr)\n return arr.buffer\n }\n\n static takeBytes = (\n bytes: ByteString,\n params: TakeBytesParams = {},\n ): ByteString => {\n const { offset, count } = params\n const start = (offset ? offset * 2 : 0) + 2 // add 2 to skip the 0x prefix\n const end = count ? start + count * 2 : undefined\n\n return `0x${bytes.slice(start, end)}`\n }\n}\n\nexport { LibBytes }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n GenericError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SDKError } from '../errors/SDKError.js'\nimport { SessionStore } from '../session/index.js'\nimport { User } from '../types/entities.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n AuthenticationServiceRoutes,\n ROUTE_METHOD_MAP,\n} from '../types/Routes.js'\nimport { jwtDecode, JwtPayload } from 'jwt-decode'\nimport { isPast, secondsToMilliseconds } from 'date-fns'\n\ntype SignerClientConfiguration = {\n apiKey: string\n apiUrl?: string\n paymasterRpcUrl?: string\n}\n\ntype SignerClientConstructorParams = {\n stamper: TurnkeyClient['stamper']\n configuration: SignerClientConfiguration\n}\n\ntype SignerClientInheritedConstructorParams<\n Extended extends Record<string, unknown>,\n> = Pick<SignerClientConstructorParams, 'configuration'> & Extended\n\nabstract class SignerClient {\n protected readonly _turnkeyClient: TurnkeyClient\n protected readonly _configuration: Required<\n SignerClientConstructorParams['configuration']\n >\n protected readonly _sessionStore: SessionStore\n\n private _user?: User\n\n constructor({\n stamper,\n configuration: { apiUrl, paymasterRpcUrl, ...requiredConfiguration },\n }: SignerClientConstructorParams) {\n this._turnkeyClient = new TurnkeyClient(\n { baseUrl: 'https://api.turnkey.com' },\n stamper,\n )\n\n this._configuration = {\n ...requiredConfiguration,\n apiUrl: apiUrl ?? 'https://auth.api.fourt.io/',\n paymasterRpcUrl: paymasterRpcUrl ?? 'https://management.api.fourt.io/',\n }\n\n this._sessionStore = new SessionStore()\n }\n\n logout() {\n this._user = undefined\n this.sessionStore.clearAll()\n }\n\n get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n get user(): User | undefined {\n if (this._user) return this._user\n\n // Check if there's a token\n if (!this.sessionStore.token) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n const decodedToken = jwtDecode<JwtPayload>(this.sessionStore.token)\n // Check if the token has expired\n if (\n decodedToken.exp &&\n isPast(new Date(secondsToMilliseconds(decodedToken.exp)))\n ) {\n this.sessionStore.clearAll()\n return undefined\n }\n\n if (this.sessionStore.user) this._user = this.sessionStore.user\n\n return this._user\n }\n\n protected set user(value: User | undefined) {\n this._user = value\n }\n\n protected set stamper(stamper: TurnkeyClient['stamper']) {\n this._turnkeyClient.stamper = stamper\n }\n\n protected get stamper(): TurnkeyClient['stamper'] {\n return this._turnkeyClient.stamper\n }\n\n protected get sessionStore(): SessionStore {\n return this._sessionStore\n }\n\n async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._user) {\n throw new UnauthorizedError({\n message: 'SignerClient must be authenticated to sign a message',\n })\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._user.subOrgId,\n type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',\n timestampMs: Date.now().toString(),\n parameters: {\n encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',\n hashFunction: 'HASH_FUNCTION_NO_OP',\n payload: msg,\n signWith: this._user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', {\n stampedRequest,\n })\n\n return <Into>signature\n }\n\n protected async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', { email })\n return subOrgId\n } catch (error) {\n if (!(error instanceof SDKError)) throw error\n\n const sdkError: SDKError = error\n\n switch (sdkError.constructor.name) {\n case NotFoundError.name: {\n return null\n }\n default: {\n throw sdkError\n }\n }\n }\n }\n\n protected async whoAmI(subOrgId?: string) {\n const orgId = subOrgId || this._user?.subOrgId\n\n if (!orgId) throw new BadRequestError({ message: 'No orgId provided' })\n\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: orgId,\n })\n\n const { user, token } = await this.request('/v1/signin', {\n stampedRequest,\n })\n\n const credentialId = (() => {\n try {\n return JSON.parse(stampedRequest?.stamp.stampHeaderValue)\n .credentialId as string\n } catch (e) {\n return undefined\n }\n })()\n\n this._user = {\n ...user,\n credentialId: credentialId,\n }\n\n this.sessionStore.user = this.user!\n this.sessionStore.token = token\n }\n\n protected async request<Route extends AuthenticationServiceRoutes>(\n route: Route,\n body?: AuthenticationServiceBody<Route>,\n ): Promise<AuthenticationServiceResponse<Route>> {\n const url = new URL(`${route}`, this._configuration.apiUrl)\n const token = this.sessionStore.token\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-FOURT-KEY': this._configuration.apiKey,\n }\n\n // Add Authorization header if token exists\n if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method: ROUTE_METHOD_MAP[route],\n body: JSON.stringify(body),\n headers,\n credentials: 'include',\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<Route>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n // TODO: workaround! this need to be cleaned up and moved into the web signer\n this.logout()\n throw new UnauthorizedError({ message: error.message })\n }\n case 'NotFoundError': {\n throw new NotFoundError({ message: error.message })\n }\n case 'BadRequestError': {\n throw new BadRequestError({ message: error.message })\n }\n default: {\n throw new GenericError({ message: error.message })\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<Route>\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthorizedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthorizedError.name, props)\n }\n}\n\nexport { UnauthorizedError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass NotFoundError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(NotFoundError.name, props)\n }\n}\n\nexport { NotFoundError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass GenericError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(GenericError.name, props)\n }\n}\n\nexport { GenericError }\n","import { SDKErrorProps, SDKError } from './SDKError.js'\n\nclass UnauthenticatedError extends SDKError {\n constructor(props: SDKErrorProps) {\n super(UnauthenticatedError.name, props)\n }\n}\n\nexport { UnauthenticatedError }\n","import { getWebAuthnAttestation, TSignedRequest } from '@turnkey/http'\nimport { User } from './entities.js'\nimport { AtLeastOne } from './string.js'\n\ntype AuthenticationServiceRoutes =\n AuthenticationServiceEndpoints[number]['Route']\n\ntype AuthenticationServiceBody<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Body']\n\ntype AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =\n Extract<AuthenticationServiceEndpoints[number], { Route: Route }>['Response']\n\ntype AuthenticationServiceEndpoints = [\n {\n Route: '/v1/email-auth'\n Body: {\n email: string\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signup'\n Body: AtLeastOne<{\n passkey: {\n challenge: string\n attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>\n }\n iframe: {\n targetPublicKey: string\n redirectUrl: string\n expirationSeconds?: number\n }\n }> & { email: string }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/lookup'\n Body: {\n email: string\n }\n Response: {\n subOrgId: string\n }\n },\n {\n Route: '/v1/signin'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n user: User\n token: string\n }\n },\n {\n Route: '/v1/sign'\n Body: {\n stampedRequest: TSignedRequest\n }\n Response: {\n signature: string\n }\n },\n {\n Route: 'v1/oauth/init'\n Body: {\n provider: string\n }\n Response: {\n url: string\n }\n },\n]\n\nconst ROUTE_METHOD_MAP = {\n '/v1/signup': 'POST',\n '/v1/email-auth': 'POST',\n '/v1/lookup': 'POST',\n '/v1/signin': 'POST',\n '/v1/sign': 'POST',\n 'v1/oauth/init': 'POST',\n} satisfies Record<AuthenticationServiceRoutes, 'POST' | 'GET'>\n\nexport type {\n AuthenticationServiceEndpoints,\n AuthenticationServiceResponse,\n AuthenticationServiceBody,\n AuthenticationServiceRoutes,\n}\n\nexport { ROUTE_METHOD_MAP }\n","import {\n LocalAccount,\n TypedData,\n TypedDataDefinition,\n SignableMessage,\n Hex,\n hashMessage,\n hashTypedData,\n SerializeTransactionFn,\n TransactionSerializable,\n IsNarrowable,\n TransactionSerialized,\n GetTransactionType,\n serializeTransaction,\n keccak256,\n Client,\n hexToBigInt,\n http,\n} from 'viem'\nimport { toAccount } from 'viem/accounts'\nimport { SignerClient } from '../signer/index.js'\nimport { LibBytes } from '../lib/bytes.js'\nimport { toLightSmartAccount } from 'permissionless/accounts'\nimport {\n createPaymasterClient,\n entryPoint07Address,\n} from 'viem/account-abstraction'\nimport { UnauthenticatedError } from '../errors/UnauthenticatedError.js'\n\ntype ViemModuleConstructorParams = {\n refs: {\n signerClient: SignerClient\n }\n}\n\ntype CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: (msg) => this.signMessage(msg.message),\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>,\n ) => this.signTypedData<typedData, primaryType>(typedDataDefinition),\n signTransaction: this.signTransaction,\n })\n }\n\n async toSmartAccount({\n client,\n owner,\n }: CurrentUserToLightSmartAccountParams): ReturnType<\n typeof toLightSmartAccount<'0.7'>\n > {\n const user = this._signerClient.user\n\n if (!user) {\n throw new UnauthenticatedError({ message: 'Signer not authenticated' })\n }\n\n return toLightSmartAccount({\n client: client,\n owner,\n version: '2.0.0',\n entryPoint: {\n address: entryPoint07Address,\n version: '0.7',\n },\n address: user.smartAccountAddress,\n index: hexToBigInt(user.salt),\n })\n }\n\n async getPaymasterClient() {\n const url = new URL(\n `v1/rpc?apiKey=${this._signerClient.configuration.apiKey}`,\n this._signerClient.configuration.paymasterRpcUrl,\n )\n return createPaymasterClient({\n transport: http(url.toString()),\n })\n }\n\n async signMessage(msg: SignableMessage): Promise<Hex> {\n const messageHash = hashMessage(msg)\n const result = await this._signerClient.signRawMessage<Hex>(messageHash)\n return result\n }\n\n async signTypedData<\n TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {\n const messageHash = hashTypedData(params)\n return this._signerClient.signRawMessage(messageHash)\n }\n\n async signTransaction<\n serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>,\n transaction extends Parameters<serializer>[0] = Parameters<serializer>[0],\n >(\n transaction: transaction,\n options?:\n | {\n serializer?: serializer | undefined\n }\n | undefined,\n ): Promise<\n IsNarrowable<\n TransactionSerialized<GetTransactionType<transaction>>,\n Hex\n > extends true\n ? TransactionSerialized<GetTransactionType<transaction>>\n : Hex\n > {\n const serializeFn = options?.serializer ?? serializeTransaction\n const serializedTx = serializeFn(transaction)\n const signatureHex = await this._signerClient.signRawMessage<Hex>(\n keccak256(serializedTx),\n )\n\n const signature = {\n r: LibBytes.takeBytes(signatureHex, { count: 32 }),\n s: LibBytes.takeBytes(signatureHex, { count: 32, offset: 32 }),\n v: BigInt(LibBytes.takeBytes(signatureHex, { count: 1, offset: 64 })),\n }\n\n return serializeFn(transaction, signature)\n }\n}\n\nexport { ViemModule }\n","import { AuthModule, UserModule } from './modules/index.js'\nimport { SignerClientConstructorParams } from './signer/index.js'\nimport {\n WebSignerClient,\n WebSignerClientConstructorParams,\n} from './signer/web.js'\nimport { ViemModule } from './third-party/viem.js'\n\ntype FourtWebSignerConstructorParams = {\n configuration: SignerClientConstructorParams['configuration']\n auth: Pick<WebSignerClientConstructorParams, 'webauthn' | 'iframe' | 'oauth'>\n}\n\n/**\n * A client for interacting with the Fourt Web Signer.\n */\nclass FourtWebSigner {\n private readonly _webSignerClient: WebSignerClient\n private readonly _modules: {\n viem: ViemModule\n auth: AuthModule\n user: UserModule\n }\n\n /**\n * Initializes a new instance of the `FourtWebSigner` class.\n * Sets up the underlying modules.\n *\n *\n * @example\n * ```ts\n * const fourtWebSigner = new FourtWebSigner({\n * auth: {\n * webauthn: {\n * rpId: 'localhost',\n * },\n * },\n * configuration: {\n * apiKey: '927d603c-6775-4210-8e13-8904ca985e78',\n * },\n * })\n * ```\n *\n * @param {FourtWebSignerConstructorParams} params the required parameters to initialize the client\n */\n constructor({\n configuration,\n auth: { webauthn, iframe, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\n iframe,\n oauth,\n })\n\n this._modules = {\n viem: new ViemModule(this._webSignerClient),\n auth: new AuthModule(this._webSignerClient),\n user: new UserModule(this._webSignerClient),\n }\n }\n\n /**\n * A module for interacting with the Viem library.\n */\n get viem() {\n return this._modules.viem\n }\n\n /**\n * A module for interacting with the authentication methods.\n */\n get auth() {\n return this._modules.auth\n }\n\n /**\n * A module for interacting with the user methods.\n */\n get user() {\n return this._modules.user\n }\n}\n\nexport { FourtWebSigner }\n"],"mappings":";AAAA,SAAS,mBAAkC;AAC3C,SAAS,mBAAmB,eAAe;AAuB3C,IAAM,eAAN,MAAmB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKjB,cAAc;AACZ,SAAK,SAAS,YAA0B;AAAA,MACtC,QAAQ,KAAK,kBAAkB;AAAA,QAC7B,MAAM;AAAA,QACN,SAAS,kBAAgC,MAAM,YAAY;AAAA,MAC7D,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAgC;AAClC,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,KAAK,MAAmB;AAC1B,SAAK,OAAO,SAAS,EAAE,KAAK,CAAC;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,QAA4B;AAC9B,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MAAM,OAAe;AACvB,SAAK,OAAO,SAAS,EAAE,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,SAA6B;AAC/B,WAAO,KAAK,OAAO,SAAS,EAAE;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAO,QAAgB;AACzB,SAAK,OAAO,SAAS,EAAE,OAAO,CAAC;AAAA,EACjC;AAAA;AAAA;A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,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAO;AACT,WAAO,KAAK,SAAS;AAAA,EACvB;AACF;","names":["jose","jose","sha256"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fourt/sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "TypeScript SDK for interacting with Fourt.io",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -34,24 +34,24 @@
34
34
  ],
35
35
  "license": "ISC",
36
36
  "devDependencies": {
37
- "@types/node": "^22.8.1",
37
+ "@types/node": "^22.14.0",
38
38
  "@types/sha.js": "^2.4.4",
39
- "tsup": "^8.3.5",
40
- "typescript": "^5.6.3"
39
+ "tsup": "^8.4.0",
40
+ "typescript": "^5.8.3"
41
41
  },
42
42
  "dependencies": {
43
- "@turnkey/http": "^2.6.2",
44
- "@turnkey/iframe-stamper": "^2.0.0",
45
- "@turnkey/viem": "^0.4.8",
43
+ "@turnkey/http": "^2.22.0",
44
+ "@turnkey/iframe-stamper": "^2.5.0",
45
+ "@turnkey/viem": "^0.4.31",
46
46
  "@turnkey/webauthn-stamper": "^0.4.3",
47
47
  "buffer": "^6.0.3",
48
48
  "date-fns": "^4.1.0",
49
- "jose": "^5.9.6",
49
+ "jose": "^5.10.0",
50
50
  "jwt-decode": "^4.0.0",
51
- "permissionless": "^0.2.17",
51
+ "permissionless": "^0.2.39",
52
52
  "sha.js": "^2.4.11",
53
53
  "viem": "2.21.22",
54
- "zustand": "^5.0.1"
54
+ "zustand": "^5.0.3"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup src/index.ts src/types/index.ts --format cjs,esm --dts --clean --sourcemap",