@fourt/sdk 1.7.0 → 1.8.1
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/dist/index.cjs +24 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -30
- package/dist/index.d.ts +21 -30
- package/dist/index.js +24 -35
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -76,10 +76,10 @@ var PasskeysModule = class {
|
|
|
76
76
|
/**
|
|
77
77
|
* Signs in a user using Passkeys.
|
|
78
78
|
*
|
|
79
|
-
* @param
|
|
79
|
+
* @param {string} email email of the user
|
|
80
80
|
*/
|
|
81
|
-
async signIn(
|
|
82
|
-
return this._webSignerClient.webAuthnSignIn(
|
|
81
|
+
async signIn(email) {
|
|
82
|
+
return this._webSignerClient.webAuthnSignIn(email);
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
|
|
@@ -617,7 +617,7 @@ var SignerClient = class {
|
|
|
617
617
|
});
|
|
618
618
|
const credentialId = (() => {
|
|
619
619
|
try {
|
|
620
|
-
return JSON.parse(stampedRequest
|
|
620
|
+
return JSON.parse(stampedRequest.stamp.stampHeaderValue).credentialId;
|
|
621
621
|
} catch (e) {
|
|
622
622
|
return void 0;
|
|
623
623
|
}
|
|
@@ -787,6 +787,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
787
787
|
return super.isLoggedIn();
|
|
788
788
|
}
|
|
789
789
|
async logout() {
|
|
790
|
+
await this._initIndexedDbStamper();
|
|
790
791
|
super.logout();
|
|
791
792
|
this.indexedDbStamper.clear();
|
|
792
793
|
}
|
|
@@ -808,16 +809,28 @@ var WebSignerClient = class extends SignerClient {
|
|
|
808
809
|
/**
|
|
809
810
|
* Signs in a user with webauthn.
|
|
810
811
|
*
|
|
811
|
-
* @param {
|
|
812
|
+
* @param {string} email email of the user
|
|
812
813
|
*/
|
|
813
|
-
async webAuthnSignIn(
|
|
814
|
+
async webAuthnSignIn(email) {
|
|
815
|
+
const publicKey = await this.getPublicKey();
|
|
814
816
|
const existingUserSubOrgId = await this.lookUpUser(email);
|
|
817
|
+
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
818
|
+
this.stamper = this.webauthnStamper;
|
|
815
819
|
if (!existingUserSubOrgId) {
|
|
816
|
-
await this.
|
|
820
|
+
const { challenge, attestation } = await this._webAuthnGenerateAttestation(email);
|
|
821
|
+
const { user, token } = await this.request("/v1/passkey/init", "POST", {
|
|
822
|
+
email,
|
|
823
|
+
challenge: LibBase64.fromBuffer(challenge),
|
|
824
|
+
attestation,
|
|
825
|
+
publicKey
|
|
826
|
+
});
|
|
827
|
+
this._sessionStore.user = {
|
|
828
|
+
...user,
|
|
829
|
+
credentialId: attestation.credentialId
|
|
830
|
+
};
|
|
831
|
+
this._sessionStore.token = token;
|
|
817
832
|
} else {
|
|
818
|
-
this.
|
|
819
|
-
await this.signIn(existingUserSubOrgId);
|
|
820
|
-
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
833
|
+
await this.signIn(existingUserSubOrgId, publicKey);
|
|
821
834
|
if (!this._sessionStore.user || !this._sessionStore.user.credentialId) {
|
|
822
835
|
return;
|
|
823
836
|
}
|
|
@@ -855,7 +868,6 @@ var WebSignerClient = class extends SignerClient {
|
|
|
855
868
|
* @param {CompleteEmailAuthParams} params params needed for otp code verification
|
|
856
869
|
*/
|
|
857
870
|
async completeEmailAuth(params) {
|
|
858
|
-
await this._initIndexedDbStamper();
|
|
859
871
|
if (!this._sessionStore.otpId)
|
|
860
872
|
throw new NotFoundError("No OTP ID found in session store.");
|
|
861
873
|
const publicKey = await this.getPublicKey();
|
|
@@ -876,7 +888,6 @@ var WebSignerClient = class extends SignerClient {
|
|
|
876
888
|
* @param {CompleteOAuthParams} params params needed for oauth completion
|
|
877
889
|
*/
|
|
878
890
|
async completeOAuth(params) {
|
|
879
|
-
await this._initIndexedDbStamper();
|
|
880
891
|
const publicKey = await this.getPublicKey();
|
|
881
892
|
await this.signIn(params.subOrgId, publicKey);
|
|
882
893
|
this._sessionStore.type = "oauth" /* OAuth */;
|
|
@@ -900,28 +911,6 @@ var WebSignerClient = class extends SignerClient {
|
|
|
900
911
|
this.stamper = this.indexedDbStamper;
|
|
901
912
|
}
|
|
902
913
|
}
|
|
903
|
-
/**
|
|
904
|
-
* Creates a passkey account using the webauthn stamper.
|
|
905
|
-
*
|
|
906
|
-
* @param {WebAuthnSignInParams} params params for the creation of the account
|
|
907
|
-
*/
|
|
908
|
-
async _createWebAuthnAccount(params) {
|
|
909
|
-
const { challenge, attestation } = await this._webauthnGenerateAttestation(
|
|
910
|
-
params.email
|
|
911
|
-
);
|
|
912
|
-
const { user, token } = await this.request("/v1/signup", "POST", {
|
|
913
|
-
email: params.email,
|
|
914
|
-
challenge: LibBase64.fromBuffer(challenge),
|
|
915
|
-
attestation
|
|
916
|
-
});
|
|
917
|
-
this._sessionStore.user = {
|
|
918
|
-
...user,
|
|
919
|
-
credentialId: attestation.credentialId
|
|
920
|
-
};
|
|
921
|
-
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
922
|
-
this._sessionStore.token = token;
|
|
923
|
-
this._scheduleRefresh(token);
|
|
924
|
-
}
|
|
925
914
|
/**
|
|
926
915
|
* Init account creation with email.
|
|
927
916
|
*
|
|
@@ -934,7 +923,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
934
923
|
});
|
|
935
924
|
return response;
|
|
936
925
|
}
|
|
937
|
-
async
|
|
926
|
+
async _webAuthnGenerateAttestation(email) {
|
|
938
927
|
const challenge = LibBytes.generateRandomBuffer();
|
|
939
928
|
const authenticatorUserId = LibBytes.generateRandomBuffer();
|
|
940
929
|
const attestation = await (0, import_http2.getWebAuthnAttestation)({
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/lib/sha256.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/session/index.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/UnauthenticatedError.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' | '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, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\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 type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClient,\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 {InitEmailAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves when the initialization is complete.\n */\n async initialize(params: InitEmailAuthParams): Promise<void> {\n return this._webSignerClient.initEmailAuth(params)\n }\n\n /**\n * Completes email authentication with OTP code.\n *\n * @param params {CompleteEmailAuthParams} params to complete the authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(params: CompleteEmailAuthParams): Promise<void> {\n await this._webSignerClient.completeEmailAuth(params)\n }\n\n /**\n * Get the email authentication method of the app, that was chosen in fourt.io dashboard.\n * It can be either `magiclink` or `otp`.\n *\n * @returns {Promise<'otp' | 'magiclink'>} promise that resolves to the email authentication method.\n */\n async getAuthMethod(): Promise<'otp' | 'magiclink'> {\n return this._webSignerClient.getEmailAuthMethod()\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 */\n async signIn(params: WebAuthnSignInParams) {\n return this._webSignerClient.webAuthnSignIn(params)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\n const initUrl = await this._webSignerClient.getOAuthInitUrl('google')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth/google',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 { GoogleModule }\n","class LibSha256 {\n /**\n * Compute SHA-256 and return hex string using Web Crypto when available.\n * Falls back to Node's crypto.createHash when running in Node.\n */\n static async sha256Hex(\n input: string | ArrayBuffer | Uint8Array,\n ): Promise<string> {\n // normalize input to Uint8Array\n let data: Uint8Array\n if (typeof input === 'string') {\n data = new TextEncoder().encode(input)\n } else if (input instanceof Uint8Array) {\n data = input\n } else {\n data = new Uint8Array(input)\n }\n\n // Prefer Web Crypto Subtle API\n const subtle =\n typeof globalThis !== 'undefined' && (globalThis as any).crypto?.subtle\n ? (globalThis as any).crypto.subtle\n : undefined\n\n if (subtle) {\n const hash = await subtle.digest('SHA-256', data)\n return Array.from(new Uint8Array(hash))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n\n // Fallback for Node (synchronous)\n try {\n const nodeCrypto = require('crypto')\n const hash = nodeCrypto.createHash('sha256').update(data).digest('hex')\n return hash\n } catch {\n throw new Error(\n 'No crypto provider available. Provide a global crypto.subtle or run in Node 18+.',\n )\n }\n }\n}\n\nexport { LibSha256 }\n","class BadRequestError extends Error {\n constructor(message: string) {\n super(message)\n this.name = BadRequestError.name\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 await this._webSignerClient.resetKeyPair()\n const publicKey = await this._webSignerClient.getPublicKey()\n const internalUrl = new URL(\n 'v1/oauth/facebook',\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 publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\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 `Failed to create OAuth state. Error: ${response.statusText}`,\n )\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError(response.statusText)\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\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.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 type { CompleteOAuthParams, WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\n/**\n * A module for interacting with the OAuth authentication methods.\n * Available through the `auth.oauth` property on a `FourtWebSigner` instance.\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 /**\n * Completes oauth authentication.\n *\n * @param params {CompleteOAuthParams} params needed for oauth completion\n * @returns {Promise<void>} promise that completes the oauth authentication process.\n */\n async complete(params: CompleteOAuthParams): Promise<void> {\n await this._webSignerClient.completeOAuth(params)\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 * Retrieves information for the authenticated user.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getInfo(): Promise<User> {\n return this._webSignerClient.getUser()\n }\n\n /**\n * Checks if a user is currently logged in to the fourt.io SDK.\n */\n async isLoggedIn(): Promise<boolean> {\n return this._webSignerClient.isLoggedIn()\n }\n\n /**\n * Generates an access token with a lifespan of 15 minutes.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getToken(): Promise<string> {\n return this._webSignerClient.getToken()\n }\n\n /**\n * Logs out the user.\n */\n async logout(): Promise<void> {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\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'\nimport { NotFoundError } from '../errors/NotFoundError.js'\nimport { IndexedDbStamper } from '@turnkey/indexed-db-stamper'\nimport { decodeJwt } from 'jose'\n\ntype WebAuthnSignInParams = {\n email: string\n}\n\ntype InitEmailAuthParams = {\n email: string\n redirectUrl?: string\n}\n\ntype CompleteEmailAuthParams = {\n email: string\n otpCode: string\n}\n\ntype CompleteOAuthParams = {\n subOrgId: string\n}\n\ntype OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n oauth?: OAuthConfiguration\n}>\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private indexedDbStamper: IndexedDbStamper\n private webauthnStamper: WebauthnStamper\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 oauth,\n }: WebSignerClientConstructorParams) {\n const indexedDbStamper = new IndexedDbStamper()\n\n super({\n stamper: indexedDbStamper,\n configuration: configuration,\n })\n\n this.indexedDbStamper = indexedDbStamper\n this.webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n\n this.oauthConfiguration = oauth\n }\n\n public override async isLoggedIn() {\n await this.getPublicKey()\n return super.isLoggedIn()\n }\n\n public override async logout() {\n super.logout()\n this.indexedDbStamper.clear()\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 /**\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', 'POST', {\n provider,\n })\n\n return url\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {WebAuthnSignInParams} params params for the sign in\n */\n public async webAuthnSignIn({ email }: WebAuthnSignInParams) {\n const existingUserSubOrgId = await this.lookUpUser(email)\n\n if (!existingUserSubOrgId) {\n await this._createWebAuthnAccount({ email })\n } else {\n this.stamper = this.webauthnStamper\n await this.signIn(existingUserSubOrgId)\n\n this._sessionStore.type = SessionType.Passkeys\n\n // We should assure that the user and its credentialId are set\n if (!this._sessionStore.user || !this._sessionStore.user.credentialId) {\n return\n }\n\n this.webauthnStamper.allowCredentials = [\n {\n id: LibBase64.toBuffer(this._sessionStore.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handles auth user process with email according to the method of the used app.\n *\n * @param {InitEmailAuthParams} params params needed for the initialization of the auth process\n */\n public async initEmailAuth(params: InitEmailAuthParams) {\n await this.indexedDbStamper.resetKeyPair()\n const { otpId } = await this._initEmailAuth(params)\n if (!otpId) throw new NotFoundError('No OTP init response returned.')\n this._sessionStore.otpId = otpId\n }\n\n public async getPublicKey() {\n await this._initIndexedDbStamper()\n return this.indexedDbStamper.getPublicKey()!\n }\n\n public async resetKeyPair() {\n await this._initIndexedDbStamper()\n await this.indexedDbStamper.resetKeyPair()\n }\n\n /**\n * Verifies the provided otp code.\n *\n * @param {CompleteEmailAuthParams} params params needed for otp code verification\n */\n public async completeEmailAuth(params: CompleteEmailAuthParams) {\n await this._initIndexedDbStamper()\n\n if (!this._sessionStore.otpId)\n throw new NotFoundError('No OTP ID found in session store.')\n\n const publicKey = await this.getPublicKey()\n const { subOrgId } = await this.request('/v1/email/complete', 'POST', {\n otpId: this._sessionStore.otpId,\n otpCode: params.otpCode,\n publicKey,\n })\n\n if (!subOrgId)\n throw new NotFoundError('No OTP authentication response returned.')\n\n await this.signIn(subOrgId, publicKey)\n this._sessionStore.type = SessionType.Email\n this._sessionStore.clearOtpId()\n }\n\n /**\n * Completes oauth authentication.\n *\n * @param {CompleteOAuthParams} params params needed for oauth completion\n */\n public async completeOAuth(params: CompleteOAuthParams) {\n await this._initIndexedDbStamper()\n const publicKey = await this.getPublicKey()\n await this.signIn(params.subOrgId, publicKey)\n this._sessionStore.type = SessionType.OAuth\n }\n\n /**\n * Gets the email authentication method of the app.\n */\n public async getEmailAuthMethod() {\n const { method } = await this.request('/v1/email/method', 'GET')\n return method\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n */\n private async _updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n this._sessionStore.token === undefined\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this.webauthnStamper\n } else {\n this.stamper = this.indexedDbStamper\n }\n }\n\n /**\n * Creates a passkey account using the webauthn stamper.\n *\n * @param {WebAuthnSignInParams} params params for the creation of the account\n */\n private async _createWebAuthnAccount(params: WebAuthnSignInParams) {\n const { challenge, attestation } = await this._webauthnGenerateAttestation(\n params.email,\n )\n\n const { user, token } = await this.request('/v1/signup', 'POST', {\n email: params.email,\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n })\n\n this._sessionStore.user = {\n ...user,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.type = SessionType.Passkeys\n // Tokens are always returned on passkey signup\n this._sessionStore.token = token!\n this._scheduleRefresh(token!)\n }\n\n /**\n * Init account creation with email.\n *\n * @param {InitEmailAuthParams} params params for the creation of the account\n */\n private async _initEmailAuth(params: InitEmailAuthParams) {\n const response = await this.request('/v1/email/init', 'POST', {\n email: params.email,\n redirectUrl: params.redirectUrl\n ? params.redirectUrl.toString()\n : undefined,\n })\n\n return response\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 _initIndexedDbStamper() {\n if (!this.indexedDbStamper.getPublicKey()) {\n await this.indexedDbStamper.init()\n }\n this.stamper = this.indexedDbStamper\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClientConstructorParams,\n WebAuthnSignInParams,\n OAuthConfiguration,\n CompleteOAuthParams,\n}\n","/**\n * Browser-friendly base64url helpers.\n * - Uses btoa/atob and Uint8Array, no Node Buffer polyfill.\n * - Chunks when converting large ArrayBuffers to avoid call-stack issues.\n */\nclass LibBase64 {\n // Convert an ArrayBuffer to base64url (no padding)\n static fromBuffer(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer)\n const CHUNK_SIZE = 0x8000\n let binary = ''\n for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {\n const chunk = bytes.subarray(i, i + CHUNK_SIZE)\n // spread on TypedArray can be large; cast to any to satisfy TS\n binary += String.fromCharCode(...(chunk as any))\n }\n const base64 =\n typeof btoa === 'function'\n ? btoa(binary)\n : Buffer.from(bytes).toString('base64')\n return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n }\n\n // Convert base64url (no padding) to ArrayBuffer\n static toBuffer(base64url: string): ArrayBuffer {\n let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/')\n const pad = base64.length % 4\n if (pad) base64 += '='.repeat(4 - pad)\n\n const binary =\n typeof atob === 'function'\n ? atob(base64)\n : Buffer.from(base64, 'base64').toString('binary')\n const len = binary.length\n const bytes = new Uint8Array(len)\n for (let i = 0; i < len; i++) bytes[i] = binary.charCodeAt(i)\n return bytes.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 { createStore, type StoreApi } from 'zustand'\nimport { persist, createJSONStorage } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\ntype SessionState = {\n type?: SessionType\n user?: User\n token?: string\n otpId?: string\n}\n\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n constructor() {\n // `user` and `token` stay in memory (not persisted)\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt-session',\n storage: createJSONStorage(() => localStorage),\n // persist only these in localStorage\n partialize: (state) => ({\n type: state.type,\n otpId: state.otpId,\n }),\n }),\n )\n }\n\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n set token(token: string) {\n this._store.setState({ token })\n }\n\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n get otpId(): string | undefined {\n return this._store.getState().otpId\n }\n\n set otpId(otpId: string) {\n this._store.setState({ otpId })\n }\n\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n clearOtpId() {\n this._store.setState({ ...this._store.getState(), otpId: undefined })\n }\n\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearType()\n this.clearOtpId()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n token: undefined,\n otpId: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SessionStore } from '../session/index.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n Method,\n Route,\n} from '../types/routes.js'\nimport { decodeJwt } from 'jose'\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 _refreshPromise?: Promise<void>\n private _refreshTimer?: ReturnType<typeof setTimeout>\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 get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n public async getUser() {\n if (this._sessionStore.user) return this._sessionStore.user\n\n try {\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n // If unauthorized, try to refresh token and retry once\n if (error instanceof UnauthorizedError) {\n try {\n await this._refreshToken()\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n throw error\n }\n }\n throw error\n }\n }\n\n public async isLoggedIn() {\n const token = this._sessionStore.token\n\n // If we have a token and it's still valid, we're logged in\n if (token && !this._isTokenExpired(token)) return true\n\n // Otherwise try to refresh (covers no token and expired token)\n try {\n await this._refreshToken()\n return !!this._sessionStore.token\n } catch {\n return false\n }\n }\n\n public async getToken(): Promise<string> {\n // Try to use existing token\n if (!this._sessionStore.token) {\n // No token: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError(\n 'No token found, user might not be logged in',\n )\n }\n } else if (this._isTokenExpired(this._sessionStore.token)) {\n // Token expired: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError('Token expired and refresh failed')\n }\n }\n\n const token = this._sessionStore.token\n if (!token) {\n throw new UnauthorizedError('No token found, user might not be logged in')\n }\n return token\n }\n\n private _isTokenExpired(token: string): boolean {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (typeof decoded.exp === 'number') {\n return decoded.exp * 1000 <= Date.now()\n }\n return true // If no exp claim, consider it expired\n } catch {\n return true // If token is malformed, consider it expired\n }\n }\n\n public async logout() {\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n this._refreshTimer = undefined\n const logoutPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'logout_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(logoutPayload)\n await this.request('/v1/logout', 'POST', { payload: logoutPayload, stamp })\n this._sessionStore.clearAll()\n }\n\n public async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._sessionStore.token || !this._sessionStore.user) {\n throw new UnauthorizedError(\n 'SignerClient must be authenticated to sign a message',\n )\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._sessionStore.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._sessionStore.user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', 'POST', {\n stampedRequest,\n })\n\n return <Into>signature\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 async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', 'POST', { email })\n return subOrgId\n } catch (error) {\n if (error instanceof NotFoundError) return null\n throw error\n }\n }\n\n protected async signIn(subOrgId: string, publicKey?: string) {\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: subOrgId,\n })\n\n const { user, token } = await this.request('/v1/signin', 'POST', {\n stampedRequest,\n publicKey,\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._sessionStore.user = {\n ...user,\n credentialId: credentialId,\n }\n this._sessionStore.token = token\n this._scheduleRefresh(token)\n return { user, token }\n }\n\n protected async stampAndRefresh() {\n const refreshPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'refresh_token_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(refreshPayload)\n const { token } = await this.request('/v1/refresh', 'POST', {\n payload: refreshPayload,\n stamp,\n })\n this._sessionStore.token = token\n return { token }\n }\n\n protected async request<R extends Route, M extends Method>(\n route: R,\n method: M,\n body?: AuthenticationServiceBody<R>,\n ): Promise<AuthenticationServiceResponse<R>> {\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 if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method,\n body: method === 'POST' ? JSON.stringify(body) : undefined,\n headers,\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<R>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n throw new UnauthorizedError(error.message)\n }\n case 'NotFoundError': {\n throw new NotFoundError(error.message)\n }\n case 'BadRequestError': {\n throw new BadRequestError(error.message)\n }\n default: {\n throw new Error(error.message)\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<R>\n }\n\n /**\n * Compute milliseconds until refresh time.\n * - expSeconds is the JWT exp claim (seconds).\n * - earlyMinutes is how many minutes before exp to refresh (default 2).\n * Returns 0 if refresh time is already past.\n */\n private _computeRefreshDelayMs(expSeconds: number, earlyMinutes = 2): number {\n const expiryMs = expSeconds * 1000\n const refreshMs = expiryMs - earlyMinutes * 60 * 1000\n const now = Date.now()\n const delay = refreshMs - now\n return delay <= 0 ? 0 : delay\n }\n\n protected _scheduleRefresh(token: string) {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (!decoded.exp) return\n\n const delay = this._computeRefreshDelayMs(decoded.exp, 2)\n\n // Clear previous timer to avoid duplicates\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n\n // Schedule refresh\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n this._refreshToken()\n }, delay)\n } catch {\n // ignore errors\n }\n }\n\n private async _refreshToken(): Promise<void> {\n if (this._refreshPromise) return this._refreshPromise\n\n // Keep a reference so callers can await the same promise\n this._refreshPromise = (async () => {\n const TIMEOUT_MS = 10_000\n const RETRY_DELAY_MS = 5_000\n\n try {\n // Avoid hanging indefinitely by racing the request with a timeout\n const refreshPromise = this.stampAndRefresh()\n const data = await Promise.race([\n refreshPromise,\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error('Refresh timeout')), TIMEOUT_MS),\n ),\n ])\n\n if (!data || !data.token) {\n // Treat missing tokens as auth failure\n throw new UnauthorizedError('Refresh did not return tokens')\n }\n\n this._sessionStore.token = data.token\n this._scheduleRefresh(data.token)\n } catch (error) {\n console.error('Token refresh failed:', error)\n // On auth errors, clear session to avoid repeated failing retries\n if (error instanceof UnauthorizedError) {\n this._sessionStore.clearToken()\n this._sessionStore.clearUser()\n\n throw error\n }\n\n // Transient error: schedule a retry (non-blocking) and rethrow so callers know it failed\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n const MAX_RETRIES = 5\n let retryCount = 0\n\n // We schedule a background retry after RETRY_DELAY_MS using setTimeout\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {\n // Increments retryCount and, if still under MAX_RETRIES, schedules\n // another retry using exponential backoff (capped at 60s)\n retryCount++\n if (retryCount <= MAX_RETRIES) {\n const nextDelay = Math.min(\n RETRY_DELAY_MS * 2 ** (retryCount - 1),\n 60_000,\n )\n this._refreshTimer = setTimeout(() => {\n // When the timer fires we clear the stored id and call _refreshToken() in a\n // fire-and-forget manner (void ... .catch(...)) so the retry runs asynchronously\n // and doesn't block or change the control flow of the original caller.\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {})\n }, nextDelay)\n }\n })\n }, RETRY_DELAY_MS)\n\n throw error\n } finally {\n this._refreshPromise = undefined\n }\n })()\n\n return this._refreshPromise\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","class UnauthorizedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthorizedError.name\n }\n}\n\nexport { UnauthorizedError }\n","class NotFoundError extends Error {\n constructor(message: string) {\n super(message)\n this.name = NotFoundError.name\n }\n}\n\nexport { NotFoundError }\n","class UnauthenticatedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthenticatedError.name\n }\n}\n\nexport { UnauthenticatedError }\n","import {\n type Chain,\n type Client,\n type GetTransactionType,\n type Hex,\n type IsNarrowable,\n type JsonRpcAccount,\n type LocalAccount,\n type TypedData,\n type TypedDataDefinition,\n type SignableMessage,\n type SerializeTransactionFn,\n type TransactionSerializable,\n type TransactionSerialized,\n type Transport,\n hashMessage,\n hashTypedData,\n serializeTransaction,\n keccak256,\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 CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client<\n Transport,\n Chain | undefined,\n JsonRpcAccount | LocalAccount | undefined\n >\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: ({ message }: { message: SignableMessage }) =>\n this.signMessage(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 = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toLightSmartAccount({\n 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 = await 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,IAAM,cAAN,MAAkB;AAAA,EAChB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,MAAM,WAAW,QAA4C;AAC3D,WAAO,KAAK,iBAAiB,cAAc,MAAM;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,QAAgD;AAC7D,UAAM,KAAK,iBAAiB,kBAAkB,MAAM;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAA8C;AAClD,WAAO,KAAK,iBAAiB,mBAAmB;AAAA,EAClD;AACF;;;ACpCA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjE,MAAM,OAAO,QAA8B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Y,WAAW;AAClD,UAAM,eAAe,MAAM,KAAK,cAAc;AAAA,UAC5C,uBAAU,YAAY;AAAA,IACxB;AAEA,UAAM,YAAY;AAAA,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;;;AnBlIA,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,MAAM;AAAA,EAC1B,GAAoC;AAClC,SAAK,mBAAmB,IAAI,gBAAgB;AAAA,MAC1C;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_http","error","import_accounts"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/lib/sha256.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/session/index.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/UnauthenticatedError.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' | '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, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\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 type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClient,\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 {InitEmailAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves when the initialization is complete.\n */\n async initialize(params: InitEmailAuthParams): Promise<void> {\n return this._webSignerClient.initEmailAuth(params)\n }\n\n /**\n * Completes email authentication with OTP code.\n *\n * @param params {CompleteEmailAuthParams} params to complete the authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(params: CompleteEmailAuthParams): Promise<void> {\n await this._webSignerClient.completeEmailAuth(params)\n }\n\n /**\n * Get the email authentication method of the app, that was chosen in fourt.io dashboard.\n * It can be either `magiclink` or `otp`.\n *\n * @returns {Promise<'otp' | 'magiclink'>} promise that resolves to the email authentication method.\n */\n async getAuthMethod(): Promise<'otp' | 'magiclink'> {\n return this._webSignerClient.getEmailAuthMethod()\n }\n}\n\nexport { EmailModule }\n","import type { WebSignerClient } 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 {string} email email of the user\n */\n async signIn(email: string) {\n return this._webSignerClient.webAuthnSignIn(email)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\n const initUrl = await this._webSignerClient.getOAuthInitUrl('google')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth/google',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 { GoogleModule }\n","class LibSha256 {\n /**\n * Compute SHA-256 and return hex string using Web Crypto when available.\n * Falls back to Node's crypto.createHash when running in Node.\n */\n static async sha256Hex(\n input: string | ArrayBuffer | Uint8Array,\n ): Promise<string> {\n // normalize input to Uint8Array\n let data: Uint8Array\n if (typeof input === 'string') {\n data = new TextEncoder().encode(input)\n } else if (input instanceof Uint8Array) {\n data = input\n } else {\n data = new Uint8Array(input)\n }\n\n // Prefer Web Crypto Subtle API\n const subtle =\n typeof globalThis !== 'undefined' && (globalThis as any).crypto?.subtle\n ? (globalThis as any).crypto.subtle\n : undefined\n\n if (subtle) {\n const hash = await subtle.digest('SHA-256', data)\n return Array.from(new Uint8Array(hash))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n\n // Fallback for Node (synchronous)\n try {\n const nodeCrypto = require('crypto')\n const hash = nodeCrypto.createHash('sha256').update(data).digest('hex')\n return hash\n } catch {\n throw new Error(\n 'No crypto provider available. Provide a global crypto.subtle or run in Node 18+.',\n )\n }\n }\n}\n\nexport { LibSha256 }\n","class BadRequestError extends Error {\n constructor(message: string) {\n super(message)\n this.name = BadRequestError.name\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 await this._webSignerClient.resetKeyPair()\n const publicKey = await this._webSignerClient.getPublicKey()\n const internalUrl = new URL(\n 'v1/oauth/facebook',\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 publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\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 `Failed to create OAuth state. Error: ${response.statusText}`,\n )\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError(response.statusText)\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\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.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 type { CompleteOAuthParams, WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\n/**\n * A module for interacting with the OAuth authentication methods.\n * Available through the `auth.oauth` property on a `FourtWebSigner` instance.\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 /**\n * Completes oauth authentication.\n *\n * @param params {CompleteOAuthParams} params needed for oauth completion\n * @returns {Promise<void>} promise that completes the oauth authentication process.\n */\n async complete(params: CompleteOAuthParams): Promise<void> {\n await this._webSignerClient.completeOAuth(params)\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 * Retrieves information for the authenticated user.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getInfo(): Promise<User> {\n return this._webSignerClient.getUser()\n }\n\n /**\n * Checks if a user is currently logged in to the fourt.io SDK.\n */\n async isLoggedIn(): Promise<boolean> {\n return this._webSignerClient.isLoggedIn()\n }\n\n /**\n * Generates an access token with a lifespan of 15 minutes.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getToken(): Promise<string> {\n return this._webSignerClient.getToken()\n }\n\n /**\n * Logs out the user.\n */\n async logout(): Promise<void> {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\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'\nimport { NotFoundError } from '../errors/NotFoundError.js'\nimport { IndexedDbStamper } from '@turnkey/indexed-db-stamper'\n\ntype InitEmailAuthParams = {\n email: string\n redirectUrl?: string\n}\n\ntype CompleteEmailAuthParams = {\n email: string\n otpCode: string\n}\n\ntype CompleteOAuthParams = {\n subOrgId: string\n}\n\ntype OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n oauth?: OAuthConfiguration\n}>\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private indexedDbStamper: IndexedDbStamper\n private webauthnStamper: WebauthnStamper\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 oauth,\n }: WebSignerClientConstructorParams) {\n const indexedDbStamper = new IndexedDbStamper()\n\n super({\n stamper: indexedDbStamper,\n configuration: configuration,\n })\n\n this.indexedDbStamper = indexedDbStamper\n this.webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n\n this.oauthConfiguration = oauth\n }\n\n public override async isLoggedIn() {\n await this.getPublicKey()\n return super.isLoggedIn()\n }\n\n public override async logout() {\n // Init indexedDb stamper in order to sign logout request\n await this._initIndexedDbStamper()\n super.logout()\n this.indexedDbStamper.clear()\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 /**\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', 'POST', {\n provider,\n })\n\n return url\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {string} email email of the user\n */\n public async webAuthnSignIn(email: string) {\n const publicKey = await this.getPublicKey()\n const existingUserSubOrgId = await this.lookUpUser(email)\n this._sessionStore.type = SessionType.Passkeys\n this.stamper = this.webauthnStamper\n\n if (!existingUserSubOrgId) {\n const { challenge, attestation } =\n await this._webAuthnGenerateAttestation(email)\n\n const { user, token } = await this.request('/v1/passkey/init', 'POST', {\n email,\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n publicKey,\n })\n\n this._sessionStore.user = {\n ...user,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.token = token\n } else {\n await this.signIn(existingUserSubOrgId, publicKey)\n\n // We should assure that the user and its credentialId are set\n if (!this._sessionStore.user || !this._sessionStore.user.credentialId) {\n return\n }\n\n this.webauthnStamper.allowCredentials = [\n {\n id: LibBase64.toBuffer(this._sessionStore.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handles auth user process with email according to the method of the used app.\n *\n * @param {InitEmailAuthParams} params params needed for the initialization of the auth process\n */\n public async initEmailAuth(params: InitEmailAuthParams) {\n await this.indexedDbStamper.resetKeyPair()\n const { otpId } = await this._initEmailAuth(params)\n if (!otpId) throw new NotFoundError('No OTP init response returned.')\n this._sessionStore.otpId = otpId\n }\n\n public async getPublicKey() {\n await this._initIndexedDbStamper()\n return this.indexedDbStamper.getPublicKey()!\n }\n\n public async resetKeyPair() {\n await this._initIndexedDbStamper()\n await this.indexedDbStamper.resetKeyPair()\n }\n\n /**\n * Verifies the provided otp code.\n *\n * @param {CompleteEmailAuthParams} params params needed for otp code verification\n */\n public async completeEmailAuth(params: CompleteEmailAuthParams) {\n if (!this._sessionStore.otpId)\n throw new NotFoundError('No OTP ID found in session store.')\n\n const publicKey = await this.getPublicKey()\n const { subOrgId } = await this.request('/v1/email/complete', 'POST', {\n otpId: this._sessionStore.otpId,\n otpCode: params.otpCode,\n publicKey,\n })\n\n if (!subOrgId)\n throw new NotFoundError('No OTP authentication response returned.')\n\n await this.signIn(subOrgId, publicKey)\n this._sessionStore.type = SessionType.Email\n this._sessionStore.clearOtpId()\n }\n\n /**\n * Completes oauth authentication.\n *\n * @param {CompleteOAuthParams} params params needed for oauth completion\n */\n public async completeOAuth(params: CompleteOAuthParams) {\n const publicKey = await this.getPublicKey()\n await this.signIn(params.subOrgId, publicKey)\n this._sessionStore.type = SessionType.OAuth\n }\n\n /**\n * Gets the email authentication method of the app.\n */\n public async getEmailAuthMethod() {\n const { method } = await this.request('/v1/email/method', 'GET')\n return method\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n */\n private async _updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n this._sessionStore.token === undefined\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this.webauthnStamper\n } else {\n this.stamper = this.indexedDbStamper\n }\n }\n\n /**\n * Init account creation with email.\n *\n * @param {InitEmailAuthParams} params params for the creation of the account\n */\n private async _initEmailAuth(params: InitEmailAuthParams) {\n const response = await this.request('/v1/email/init', 'POST', {\n email: params.email,\n redirectUrl: params.redirectUrl\n ? params.redirectUrl.toString()\n : undefined,\n })\n\n return response\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 _initIndexedDbStamper() {\n if (!this.indexedDbStamper.getPublicKey()) {\n await this.indexedDbStamper.init()\n }\n this.stamper = this.indexedDbStamper\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClientConstructorParams,\n OAuthConfiguration,\n CompleteOAuthParams,\n}\n","/**\n * Browser-friendly base64url helpers.\n * - Uses btoa/atob and Uint8Array, no Node Buffer polyfill.\n * - Chunks when converting large ArrayBuffers to avoid call-stack issues.\n */\nclass LibBase64 {\n // Convert an ArrayBuffer to base64url (no padding)\n static fromBuffer(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer)\n const CHUNK_SIZE = 0x8000\n let binary = ''\n for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {\n const chunk = bytes.subarray(i, i + CHUNK_SIZE)\n // spread on TypedArray can be large; cast to any to satisfy TS\n binary += String.fromCharCode(...(chunk as any))\n }\n const base64 =\n typeof btoa === 'function'\n ? btoa(binary)\n : Buffer.from(bytes).toString('base64')\n return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n }\n\n // Convert base64url (no padding) to ArrayBuffer\n static toBuffer(base64url: string): ArrayBuffer {\n let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/')\n const pad = base64.length % 4\n if (pad) base64 += '='.repeat(4 - pad)\n\n const binary =\n typeof atob === 'function'\n ? atob(base64)\n : Buffer.from(base64, 'base64').toString('binary')\n const len = binary.length\n const bytes = new Uint8Array(len)\n for (let i = 0; i < len; i++) bytes[i] = binary.charCodeAt(i)\n return bytes.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 { createStore, type StoreApi } from 'zustand'\nimport { persist, createJSONStorage } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\ntype SessionState = {\n type?: SessionType\n user?: User\n token?: string\n otpId?: string\n}\n\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n constructor() {\n // `user` and `token` stay in memory (not persisted)\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt-session',\n storage: createJSONStorage(() => localStorage),\n // persist only these in localStorage\n partialize: (state) => ({\n type: state.type,\n otpId: state.otpId,\n }),\n }),\n )\n }\n\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n set token(token: string) {\n this._store.setState({ token })\n }\n\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n get otpId(): string | undefined {\n return this._store.getState().otpId\n }\n\n set otpId(otpId: string) {\n this._store.setState({ otpId })\n }\n\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n clearOtpId() {\n this._store.setState({ ...this._store.getState(), otpId: undefined })\n }\n\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearType()\n this.clearOtpId()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n token: undefined,\n otpId: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SessionStore } from '../session/index.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n Method,\n Route,\n} from '../types/routes.js'\nimport { decodeJwt } from 'jose'\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 _refreshPromise?: Promise<void>\n private _refreshTimer?: ReturnType<typeof setTimeout>\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 get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n public async getUser() {\n if (this._sessionStore.user) return this._sessionStore.user\n\n try {\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n // If unauthorized, try to refresh token and retry once\n if (error instanceof UnauthorizedError) {\n try {\n await this._refreshToken()\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n throw error\n }\n }\n throw error\n }\n }\n\n public async isLoggedIn() {\n const token = this._sessionStore.token\n\n // If we have a token and it's still valid, we're logged in\n if (token && !this._isTokenExpired(token)) return true\n\n // Otherwise try to refresh (covers no token and expired token)\n try {\n await this._refreshToken()\n return !!this._sessionStore.token\n } catch {\n return false\n }\n }\n\n public async getToken(): Promise<string> {\n // Try to use existing token\n if (!this._sessionStore.token) {\n // No token: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError(\n 'No token found, user might not be logged in',\n )\n }\n } else if (this._isTokenExpired(this._sessionStore.token)) {\n // Token expired: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError('Token expired and refresh failed')\n }\n }\n\n const token = this._sessionStore.token\n if (!token) {\n throw new UnauthorizedError('No token found, user might not be logged in')\n }\n return token\n }\n\n private _isTokenExpired(token: string): boolean {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (typeof decoded.exp === 'number') {\n return decoded.exp * 1000 <= Date.now()\n }\n return true // If no exp claim, consider it expired\n } catch {\n return true // If token is malformed, consider it expired\n }\n }\n\n public async logout() {\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n this._refreshTimer = undefined\n const logoutPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'logout_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(logoutPayload)\n await this.request('/v1/logout', 'POST', { payload: logoutPayload, stamp })\n this._sessionStore.clearAll()\n }\n\n public async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._sessionStore.token || !this._sessionStore.user) {\n throw new UnauthorizedError(\n 'SignerClient must be authenticated to sign a message',\n )\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._sessionStore.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._sessionStore.user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', 'POST', {\n stampedRequest,\n })\n\n return <Into>signature\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 async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', 'POST', { email })\n return subOrgId\n } catch (error) {\n if (error instanceof NotFoundError) return null\n throw error\n }\n }\n\n protected async signIn(subOrgId: string, publicKey: string) {\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: subOrgId,\n })\n\n const { user, token } = await this.request('/v1/signin', 'POST', {\n stampedRequest,\n publicKey,\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._sessionStore.user = {\n ...user,\n credentialId,\n }\n this._sessionStore.token = token\n this._scheduleRefresh(token)\n return { user, token }\n }\n\n protected async stampAndRefresh() {\n const refreshPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'refresh_token_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(refreshPayload)\n const { token } = await this.request('/v1/refresh', 'POST', {\n payload: refreshPayload,\n stamp,\n })\n this._sessionStore.token = token\n return { token }\n }\n\n protected async request<R extends Route, M extends Method>(\n route: R,\n method: M,\n body?: AuthenticationServiceBody<R>,\n ): Promise<AuthenticationServiceResponse<R>> {\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 if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method,\n body: method === 'POST' ? JSON.stringify(body) : undefined,\n headers,\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<R>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n throw new UnauthorizedError(error.message)\n }\n case 'NotFoundError': {\n throw new NotFoundError(error.message)\n }\n case 'BadRequestError': {\n throw new BadRequestError(error.message)\n }\n default: {\n throw new Error(error.message)\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<R>\n }\n\n /**\n * Compute milliseconds until refresh time.\n * - expSeconds is the JWT exp claim (seconds).\n * - earlyMinutes is how many minutes before exp to refresh (default 2).\n * Returns 0 if refresh time is already past.\n */\n private _computeRefreshDelayMs(expSeconds: number, earlyMinutes = 2): number {\n const expiryMs = expSeconds * 1000\n const refreshMs = expiryMs - earlyMinutes * 60 * 1000\n const now = Date.now()\n const delay = refreshMs - now\n return delay <= 0 ? 0 : delay\n }\n\n protected _scheduleRefresh(token: string) {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (!decoded.exp) return\n\n const delay = this._computeRefreshDelayMs(decoded.exp, 2)\n\n // Clear previous timer to avoid duplicates\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n\n // Schedule refresh\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n this._refreshToken()\n }, delay)\n } catch {\n // ignore errors\n }\n }\n\n private async _refreshToken(): Promise<void> {\n if (this._refreshPromise) return this._refreshPromise\n\n // Keep a reference so callers can await the same promise\n this._refreshPromise = (async () => {\n const TIMEOUT_MS = 10_000\n const RETRY_DELAY_MS = 5_000\n\n try {\n // Avoid hanging indefinitely by racing the request with a timeout\n const refreshPromise = this.stampAndRefresh()\n const data = await Promise.race([\n refreshPromise,\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error('Refresh timeout')), TIMEOUT_MS),\n ),\n ])\n\n if (!data || !data.token) {\n // Treat missing tokens as auth failure\n throw new UnauthorizedError('Refresh did not return tokens')\n }\n\n this._sessionStore.token = data.token\n this._scheduleRefresh(data.token)\n } catch (error) {\n console.error('Token refresh failed:', error)\n // On auth errors, clear session to avoid repeated failing retries\n if (error instanceof UnauthorizedError) {\n this._sessionStore.clearToken()\n this._sessionStore.clearUser()\n\n throw error\n }\n\n // Transient error: schedule a retry (non-blocking) and rethrow so callers know it failed\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n const MAX_RETRIES = 5\n let retryCount = 0\n\n // We schedule a background retry after RETRY_DELAY_MS using setTimeout\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {\n // Increments retryCount and, if still under MAX_RETRIES, schedules\n // another retry using exponential backoff (capped at 60s)\n retryCount++\n if (retryCount <= MAX_RETRIES) {\n const nextDelay = Math.min(\n RETRY_DELAY_MS * 2 ** (retryCount - 1),\n 60_000,\n )\n this._refreshTimer = setTimeout(() => {\n // When the timer fires we clear the stored id and call _refreshToken() in a\n // fire-and-forget manner (void ... .catch(...)) so the retry runs asynchronously\n // and doesn't block or change the control flow of the original caller.\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {})\n }, nextDelay)\n }\n })\n }, RETRY_DELAY_MS)\n\n throw error\n } finally {\n this._refreshPromise = undefined\n }\n })()\n\n return this._refreshPromise\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","class UnauthorizedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthorizedError.name\n }\n}\n\nexport { UnauthorizedError }\n","class NotFoundError extends Error {\n constructor(message: string) {\n super(message)\n this.name = NotFoundError.name\n }\n}\n\nexport { NotFoundError }\n","class UnauthenticatedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthenticatedError.name\n }\n}\n\nexport { UnauthenticatedError }\n","import {\n type Chain,\n type Client,\n type GetTransactionType,\n type Hex,\n type IsNarrowable,\n type JsonRpcAccount,\n type LocalAccount,\n type TypedData,\n type TypedDataDefinition,\n type SignableMessage,\n type SerializeTransactionFn,\n type TransactionSerializable,\n type TransactionSerialized,\n type Transport,\n hashMessage,\n hashTypedData,\n serializeTransaction,\n keccak256,\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 CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client<\n Transport,\n Chain | undefined,\n JsonRpcAccount | LocalAccount | undefined\n >\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: ({ message }: { message: SignableMessage }) =>\n this.signMessage(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 = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toLightSmartAccount({\n 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 = await 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,IAAM,cAAN,MAAkB;AAAA,EAChB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,MAAM,WAAW,QAA4C;AAC3D,WAAO,KAAK,iBAAiB,cAAc,MAAM;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,QAAgD;AAC7D,UAAM,KAAK,iBAAiB,kBAAkB,MAAM;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAA8C;AAClD,WAAO,KAAK,iBAAiB,mBAAmB;AAAA,EAClD;AACF;;;ACpCA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjE,MAAM,OAAO,OAAe;AAC1B,WAAO,KAAK,iBAAiB,eAAe,KAAK;AAAA,EACnD;AACF;;;ACjBA,WAAsB;;;ACAtB,IAAM,YAAN,MAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKd,aAAa,UACX,OACiB;AAEjB,QAAI;AACJ,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,IACvC,WAAW,iBAAiB,YAAY;AACt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AA;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,MAAM;AAAA,EAC1B,GAAoC;AAClC,SAAK,mBAAmB,IAAI,gBAAgB;AAAA,MAC1C;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_http","error","import_accounts"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -38,6 +38,19 @@ type AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =
|
|
|
38
38
|
Route: Route;
|
|
39
39
|
}>['Response'];
|
|
40
40
|
type AuthenticationServiceEndpoints = [
|
|
41
|
+
{
|
|
42
|
+
Route: '/v1/passkey/init';
|
|
43
|
+
Body: {
|
|
44
|
+
email: string;
|
|
45
|
+
challenge: string;
|
|
46
|
+
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
47
|
+
publicKey: string;
|
|
48
|
+
};
|
|
49
|
+
Response: {
|
|
50
|
+
user: User;
|
|
51
|
+
token: string;
|
|
52
|
+
};
|
|
53
|
+
},
|
|
41
54
|
{
|
|
42
55
|
Route: '/v1/email/init';
|
|
43
56
|
Body: {
|
|
@@ -56,7 +69,6 @@ type AuthenticationServiceEndpoints = [
|
|
|
56
69
|
publicKey: string;
|
|
57
70
|
};
|
|
58
71
|
Response: {
|
|
59
|
-
userId: string;
|
|
60
72
|
subOrgId: string;
|
|
61
73
|
};
|
|
62
74
|
},
|
|
@@ -67,18 +79,6 @@ type AuthenticationServiceEndpoints = [
|
|
|
67
79
|
method: 'otp' | 'magiclink';
|
|
68
80
|
};
|
|
69
81
|
},
|
|
70
|
-
{
|
|
71
|
-
Route: '/v1/signup';
|
|
72
|
-
Body: {
|
|
73
|
-
email: string;
|
|
74
|
-
challenge: string;
|
|
75
|
-
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
76
|
-
};
|
|
77
|
-
Response: {
|
|
78
|
-
user: User;
|
|
79
|
-
token: string;
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
82
|
{
|
|
83
83
|
Route: '/v1/lookup';
|
|
84
84
|
Body: {
|
|
@@ -92,7 +92,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
92
92
|
Route: '/v1/signin';
|
|
93
93
|
Body: {
|
|
94
94
|
stampedRequest: TSignedRequest;
|
|
95
|
-
publicKey
|
|
95
|
+
publicKey: string;
|
|
96
96
|
};
|
|
97
97
|
Response: {
|
|
98
98
|
user: User;
|
|
@@ -147,7 +147,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
147
147
|
Response: User;
|
|
148
148
|
}
|
|
149
149
|
];
|
|
150
|
-
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/
|
|
150
|
+
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/passkey/init", "POST"], readonly ["/v1/email/init", "POST"], readonly ["/v1/email/method", "GET"], readonly ["/v1/email/complete", "POST"], readonly ["/v1/lookup", "POST"], readonly ["/v1/signin", "POST"], readonly ["/v1/sign", "POST"], readonly ["/v1/oauth/init", "POST"], readonly ["/v1/refresh", "POST"], readonly ["/v1/logout", "POST"], readonly ["/v1/me", "GET"]];
|
|
151
151
|
type RouteMethod = (typeof ROUTE_METHOD_LIST)[number];
|
|
152
152
|
type Route = RouteMethod[0];
|
|
153
153
|
type Method = RouteMethod[1];
|
|
@@ -179,7 +179,7 @@ declare abstract class SignerClient {
|
|
|
179
179
|
protected set stamper(stamper: TurnkeyClient['stamper']);
|
|
180
180
|
protected get stamper(): TurnkeyClient['stamper'];
|
|
181
181
|
protected lookUpUser(email: string): Promise<string | null>;
|
|
182
|
-
protected signIn(subOrgId: string, publicKey
|
|
182
|
+
protected signIn(subOrgId: string, publicKey: string): Promise<{
|
|
183
183
|
user: User;
|
|
184
184
|
token: string;
|
|
185
185
|
}>;
|
|
@@ -198,9 +198,6 @@ declare abstract class SignerClient {
|
|
|
198
198
|
private _refreshToken;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
type WebAuthnSignInParams = {
|
|
202
|
-
email: string;
|
|
203
|
-
};
|
|
204
201
|
type InitEmailAuthParams = {
|
|
205
202
|
email: string;
|
|
206
203
|
redirectUrl?: string;
|
|
@@ -248,9 +245,9 @@ declare class WebSignerClient extends SignerClient {
|
|
|
248
245
|
/**
|
|
249
246
|
* Signs in a user with webauthn.
|
|
250
247
|
*
|
|
251
|
-
* @param {
|
|
248
|
+
* @param {string} email email of the user
|
|
252
249
|
*/
|
|
253
|
-
webAuthnSignIn(
|
|
250
|
+
webAuthnSignIn(email: string): Promise<void>;
|
|
254
251
|
/**
|
|
255
252
|
* Handles auth user process with email according to the method of the used app.
|
|
256
253
|
*
|
|
@@ -279,19 +276,13 @@ declare class WebSignerClient extends SignerClient {
|
|
|
279
276
|
* Checks for an existing session and if exists, updates the stamper accordingly.
|
|
280
277
|
*/
|
|
281
278
|
private _updateStamper;
|
|
282
|
-
/**
|
|
283
|
-
* Creates a passkey account using the webauthn stamper.
|
|
284
|
-
*
|
|
285
|
-
* @param {WebAuthnSignInParams} params params for the creation of the account
|
|
286
|
-
*/
|
|
287
|
-
private _createWebAuthnAccount;
|
|
288
279
|
/**
|
|
289
280
|
* Init account creation with email.
|
|
290
281
|
*
|
|
291
282
|
* @param {InitEmailAuthParams} params params for the creation of the account
|
|
292
283
|
*/
|
|
293
284
|
private _initEmailAuth;
|
|
294
|
-
private
|
|
285
|
+
private _webAuthnGenerateAttestation;
|
|
295
286
|
private _initIndexedDbStamper;
|
|
296
287
|
}
|
|
297
288
|
|
|
@@ -335,9 +326,9 @@ declare class PasskeysModule {
|
|
|
335
326
|
/**
|
|
336
327
|
* Signs in a user using Passkeys.
|
|
337
328
|
*
|
|
338
|
-
* @param
|
|
329
|
+
* @param {string} email email of the user
|
|
339
330
|
*/
|
|
340
|
-
signIn(
|
|
331
|
+
signIn(email: string): Promise<void>;
|
|
341
332
|
}
|
|
342
333
|
|
|
343
334
|
declare class GoogleModule {
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,19 @@ type AuthenticationServiceResponse<Route extends AuthenticationServiceRoutes> =
|
|
|
38
38
|
Route: Route;
|
|
39
39
|
}>['Response'];
|
|
40
40
|
type AuthenticationServiceEndpoints = [
|
|
41
|
+
{
|
|
42
|
+
Route: '/v1/passkey/init';
|
|
43
|
+
Body: {
|
|
44
|
+
email: string;
|
|
45
|
+
challenge: string;
|
|
46
|
+
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
47
|
+
publicKey: string;
|
|
48
|
+
};
|
|
49
|
+
Response: {
|
|
50
|
+
user: User;
|
|
51
|
+
token: string;
|
|
52
|
+
};
|
|
53
|
+
},
|
|
41
54
|
{
|
|
42
55
|
Route: '/v1/email/init';
|
|
43
56
|
Body: {
|
|
@@ -56,7 +69,6 @@ type AuthenticationServiceEndpoints = [
|
|
|
56
69
|
publicKey: string;
|
|
57
70
|
};
|
|
58
71
|
Response: {
|
|
59
|
-
userId: string;
|
|
60
72
|
subOrgId: string;
|
|
61
73
|
};
|
|
62
74
|
},
|
|
@@ -67,18 +79,6 @@ type AuthenticationServiceEndpoints = [
|
|
|
67
79
|
method: 'otp' | 'magiclink';
|
|
68
80
|
};
|
|
69
81
|
},
|
|
70
|
-
{
|
|
71
|
-
Route: '/v1/signup';
|
|
72
|
-
Body: {
|
|
73
|
-
email: string;
|
|
74
|
-
challenge: string;
|
|
75
|
-
attestation: Awaited<ReturnType<typeof getWebAuthnAttestation>>;
|
|
76
|
-
};
|
|
77
|
-
Response: {
|
|
78
|
-
user: User;
|
|
79
|
-
token: string;
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
82
|
{
|
|
83
83
|
Route: '/v1/lookup';
|
|
84
84
|
Body: {
|
|
@@ -92,7 +92,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
92
92
|
Route: '/v1/signin';
|
|
93
93
|
Body: {
|
|
94
94
|
stampedRequest: TSignedRequest;
|
|
95
|
-
publicKey
|
|
95
|
+
publicKey: string;
|
|
96
96
|
};
|
|
97
97
|
Response: {
|
|
98
98
|
user: User;
|
|
@@ -147,7 +147,7 @@ type AuthenticationServiceEndpoints = [
|
|
|
147
147
|
Response: User;
|
|
148
148
|
}
|
|
149
149
|
];
|
|
150
|
-
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/
|
|
150
|
+
declare const ROUTE_METHOD_LIST: readonly [readonly ["/v1/passkey/init", "POST"], readonly ["/v1/email/init", "POST"], readonly ["/v1/email/method", "GET"], readonly ["/v1/email/complete", "POST"], readonly ["/v1/lookup", "POST"], readonly ["/v1/signin", "POST"], readonly ["/v1/sign", "POST"], readonly ["/v1/oauth/init", "POST"], readonly ["/v1/refresh", "POST"], readonly ["/v1/logout", "POST"], readonly ["/v1/me", "GET"]];
|
|
151
151
|
type RouteMethod = (typeof ROUTE_METHOD_LIST)[number];
|
|
152
152
|
type Route = RouteMethod[0];
|
|
153
153
|
type Method = RouteMethod[1];
|
|
@@ -179,7 +179,7 @@ declare abstract class SignerClient {
|
|
|
179
179
|
protected set stamper(stamper: TurnkeyClient['stamper']);
|
|
180
180
|
protected get stamper(): TurnkeyClient['stamper'];
|
|
181
181
|
protected lookUpUser(email: string): Promise<string | null>;
|
|
182
|
-
protected signIn(subOrgId: string, publicKey
|
|
182
|
+
protected signIn(subOrgId: string, publicKey: string): Promise<{
|
|
183
183
|
user: User;
|
|
184
184
|
token: string;
|
|
185
185
|
}>;
|
|
@@ -198,9 +198,6 @@ declare abstract class SignerClient {
|
|
|
198
198
|
private _refreshToken;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
type WebAuthnSignInParams = {
|
|
202
|
-
email: string;
|
|
203
|
-
};
|
|
204
201
|
type InitEmailAuthParams = {
|
|
205
202
|
email: string;
|
|
206
203
|
redirectUrl?: string;
|
|
@@ -248,9 +245,9 @@ declare class WebSignerClient extends SignerClient {
|
|
|
248
245
|
/**
|
|
249
246
|
* Signs in a user with webauthn.
|
|
250
247
|
*
|
|
251
|
-
* @param {
|
|
248
|
+
* @param {string} email email of the user
|
|
252
249
|
*/
|
|
253
|
-
webAuthnSignIn(
|
|
250
|
+
webAuthnSignIn(email: string): Promise<void>;
|
|
254
251
|
/**
|
|
255
252
|
* Handles auth user process with email according to the method of the used app.
|
|
256
253
|
*
|
|
@@ -279,19 +276,13 @@ declare class WebSignerClient extends SignerClient {
|
|
|
279
276
|
* Checks for an existing session and if exists, updates the stamper accordingly.
|
|
280
277
|
*/
|
|
281
278
|
private _updateStamper;
|
|
282
|
-
/**
|
|
283
|
-
* Creates a passkey account using the webauthn stamper.
|
|
284
|
-
*
|
|
285
|
-
* @param {WebAuthnSignInParams} params params for the creation of the account
|
|
286
|
-
*/
|
|
287
|
-
private _createWebAuthnAccount;
|
|
288
279
|
/**
|
|
289
280
|
* Init account creation with email.
|
|
290
281
|
*
|
|
291
282
|
* @param {InitEmailAuthParams} params params for the creation of the account
|
|
292
283
|
*/
|
|
293
284
|
private _initEmailAuth;
|
|
294
|
-
private
|
|
285
|
+
private _webAuthnGenerateAttestation;
|
|
295
286
|
private _initIndexedDbStamper;
|
|
296
287
|
}
|
|
297
288
|
|
|
@@ -335,9 +326,9 @@ declare class PasskeysModule {
|
|
|
335
326
|
/**
|
|
336
327
|
* Signs in a user using Passkeys.
|
|
337
328
|
*
|
|
338
|
-
* @param
|
|
329
|
+
* @param {string} email email of the user
|
|
339
330
|
*/
|
|
340
|
-
signIn(
|
|
331
|
+
signIn(email: string): Promise<void>;
|
|
341
332
|
}
|
|
342
333
|
|
|
343
334
|
declare class GoogleModule {
|
package/dist/index.js
CHANGED
|
@@ -47,10 +47,10 @@ var PasskeysModule = class {
|
|
|
47
47
|
/**
|
|
48
48
|
* Signs in a user using Passkeys.
|
|
49
49
|
*
|
|
50
|
-
* @param
|
|
50
|
+
* @param {string} email email of the user
|
|
51
51
|
*/
|
|
52
|
-
async signIn(
|
|
53
|
-
return this._webSignerClient.webAuthnSignIn(
|
|
52
|
+
async signIn(email) {
|
|
53
|
+
return this._webSignerClient.webAuthnSignIn(email);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -588,7 +588,7 @@ var SignerClient = class {
|
|
|
588
588
|
});
|
|
589
589
|
const credentialId = (() => {
|
|
590
590
|
try {
|
|
591
|
-
return JSON.parse(stampedRequest
|
|
591
|
+
return JSON.parse(stampedRequest.stamp.stampHeaderValue).credentialId;
|
|
592
592
|
} catch (e) {
|
|
593
593
|
return void 0;
|
|
594
594
|
}
|
|
@@ -758,6 +758,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
758
758
|
return super.isLoggedIn();
|
|
759
759
|
}
|
|
760
760
|
async logout() {
|
|
761
|
+
await this._initIndexedDbStamper();
|
|
761
762
|
super.logout();
|
|
762
763
|
this.indexedDbStamper.clear();
|
|
763
764
|
}
|
|
@@ -779,16 +780,28 @@ var WebSignerClient = class extends SignerClient {
|
|
|
779
780
|
/**
|
|
780
781
|
* Signs in a user with webauthn.
|
|
781
782
|
*
|
|
782
|
-
* @param {
|
|
783
|
+
* @param {string} email email of the user
|
|
783
784
|
*/
|
|
784
|
-
async webAuthnSignIn(
|
|
785
|
+
async webAuthnSignIn(email) {
|
|
786
|
+
const publicKey = await this.getPublicKey();
|
|
785
787
|
const existingUserSubOrgId = await this.lookUpUser(email);
|
|
788
|
+
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
789
|
+
this.stamper = this.webauthnStamper;
|
|
786
790
|
if (!existingUserSubOrgId) {
|
|
787
|
-
await this.
|
|
791
|
+
const { challenge, attestation } = await this._webAuthnGenerateAttestation(email);
|
|
792
|
+
const { user, token } = await this.request("/v1/passkey/init", "POST", {
|
|
793
|
+
email,
|
|
794
|
+
challenge: LibBase64.fromBuffer(challenge),
|
|
795
|
+
attestation,
|
|
796
|
+
publicKey
|
|
797
|
+
});
|
|
798
|
+
this._sessionStore.user = {
|
|
799
|
+
...user,
|
|
800
|
+
credentialId: attestation.credentialId
|
|
801
|
+
};
|
|
802
|
+
this._sessionStore.token = token;
|
|
788
803
|
} else {
|
|
789
|
-
this.
|
|
790
|
-
await this.signIn(existingUserSubOrgId);
|
|
791
|
-
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
804
|
+
await this.signIn(existingUserSubOrgId, publicKey);
|
|
792
805
|
if (!this._sessionStore.user || !this._sessionStore.user.credentialId) {
|
|
793
806
|
return;
|
|
794
807
|
}
|
|
@@ -826,7 +839,6 @@ var WebSignerClient = class extends SignerClient {
|
|
|
826
839
|
* @param {CompleteEmailAuthParams} params params needed for otp code verification
|
|
827
840
|
*/
|
|
828
841
|
async completeEmailAuth(params) {
|
|
829
|
-
await this._initIndexedDbStamper();
|
|
830
842
|
if (!this._sessionStore.otpId)
|
|
831
843
|
throw new NotFoundError("No OTP ID found in session store.");
|
|
832
844
|
const publicKey = await this.getPublicKey();
|
|
@@ -847,7 +859,6 @@ var WebSignerClient = class extends SignerClient {
|
|
|
847
859
|
* @param {CompleteOAuthParams} params params needed for oauth completion
|
|
848
860
|
*/
|
|
849
861
|
async completeOAuth(params) {
|
|
850
|
-
await this._initIndexedDbStamper();
|
|
851
862
|
const publicKey = await this.getPublicKey();
|
|
852
863
|
await this.signIn(params.subOrgId, publicKey);
|
|
853
864
|
this._sessionStore.type = "oauth" /* OAuth */;
|
|
@@ -871,28 +882,6 @@ var WebSignerClient = class extends SignerClient {
|
|
|
871
882
|
this.stamper = this.indexedDbStamper;
|
|
872
883
|
}
|
|
873
884
|
}
|
|
874
|
-
/**
|
|
875
|
-
* Creates a passkey account using the webauthn stamper.
|
|
876
|
-
*
|
|
877
|
-
* @param {WebAuthnSignInParams} params params for the creation of the account
|
|
878
|
-
*/
|
|
879
|
-
async _createWebAuthnAccount(params) {
|
|
880
|
-
const { challenge, attestation } = await this._webauthnGenerateAttestation(
|
|
881
|
-
params.email
|
|
882
|
-
);
|
|
883
|
-
const { user, token } = await this.request("/v1/signup", "POST", {
|
|
884
|
-
email: params.email,
|
|
885
|
-
challenge: LibBase64.fromBuffer(challenge),
|
|
886
|
-
attestation
|
|
887
|
-
});
|
|
888
|
-
this._sessionStore.user = {
|
|
889
|
-
...user,
|
|
890
|
-
credentialId: attestation.credentialId
|
|
891
|
-
};
|
|
892
|
-
this._sessionStore.type = "passkeys" /* Passkeys */;
|
|
893
|
-
this._sessionStore.token = token;
|
|
894
|
-
this._scheduleRefresh(token);
|
|
895
|
-
}
|
|
896
885
|
/**
|
|
897
886
|
* Init account creation with email.
|
|
898
887
|
*
|
|
@@ -905,7 +894,7 @@ var WebSignerClient = class extends SignerClient {
|
|
|
905
894
|
});
|
|
906
895
|
return response;
|
|
907
896
|
}
|
|
908
|
-
async
|
|
897
|
+
async _webAuthnGenerateAttestation(email) {
|
|
909
898
|
const challenge = LibBytes.generateRandomBuffer();
|
|
910
899
|
const authenticatorUserId = LibBytes.generateRandomBuffer();
|
|
911
900
|
const attestation = await getWebAuthnAttestation({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/modules/auth/email.ts","../src/modules/auth/passkeys.ts","../src/modules/auth/oauth/google.ts","../src/lib/sha256.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/session/index.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/UnauthenticatedError.ts","../src/third-party/viem.ts","../src/index.ts"],"sourcesContent":["import type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClient,\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 {InitEmailAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves when the initialization is complete.\n */\n async initialize(params: InitEmailAuthParams): Promise<void> {\n return this._webSignerClient.initEmailAuth(params)\n }\n\n /**\n * Completes email authentication with OTP code.\n *\n * @param params {CompleteEmailAuthParams} params to complete the authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(params: CompleteEmailAuthParams): Promise<void> {\n await this._webSignerClient.completeEmailAuth(params)\n }\n\n /**\n * Get the email authentication method of the app, that was chosen in fourt.io dashboard.\n * It can be either `magiclink` or `otp`.\n *\n * @returns {Promise<'otp' | 'magiclink'>} promise that resolves to the email authentication method.\n */\n async getAuthMethod(): Promise<'otp' | 'magiclink'> {\n return this._webSignerClient.getEmailAuthMethod()\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 */\n async signIn(params: WebAuthnSignInParams) {\n return this._webSignerClient.webAuthnSignIn(params)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\n const initUrl = await this._webSignerClient.getOAuthInitUrl('google')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth/google',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 { GoogleModule }\n","class LibSha256 {\n /**\n * Compute SHA-256 and return hex string using Web Crypto when available.\n * Falls back to Node's crypto.createHash when running in Node.\n */\n static async sha256Hex(\n input: string | ArrayBuffer | Uint8Array,\n ): Promise<string> {\n // normalize input to Uint8Array\n let data: Uint8Array\n if (typeof input === 'string') {\n data = new TextEncoder().encode(input)\n } else if (input instanceof Uint8Array) {\n data = input\n } else {\n data = new Uint8Array(input)\n }\n\n // Prefer Web Crypto Subtle API\n const subtle =\n typeof globalThis !== 'undefined' && (globalThis as any).crypto?.subtle\n ? (globalThis as any).crypto.subtle\n : undefined\n\n if (subtle) {\n const hash = await subtle.digest('SHA-256', data)\n return Array.from(new Uint8Array(hash))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n\n // Fallback for Node (synchronous)\n try {\n const nodeCrypto = require('crypto')\n const hash = nodeCrypto.createHash('sha256').update(data).digest('hex')\n return hash\n } catch {\n throw new Error(\n 'No crypto provider available. Provide a global crypto.subtle or run in Node 18+.',\n )\n }\n }\n}\n\nexport { LibSha256 }\n","class BadRequestError extends Error {\n constructor(message: string) {\n super(message)\n this.name = BadRequestError.name\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 await this._webSignerClient.resetKeyPair()\n const publicKey = await this._webSignerClient.getPublicKey()\n const internalUrl = new URL(\n 'v1/oauth/facebook',\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 publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\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 `Failed to create OAuth state. Error: ${response.statusText}`,\n )\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError(response.statusText)\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\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.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 type { CompleteOAuthParams, WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\n/**\n * A module for interacting with the OAuth authentication methods.\n * Available through the `auth.oauth` property on a `FourtWebSigner` instance.\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 /**\n * Completes oauth authentication.\n *\n * @param params {CompleteOAuthParams} params needed for oauth completion\n * @returns {Promise<void>} promise that completes the oauth authentication process.\n */\n async complete(params: CompleteOAuthParams): Promise<void> {\n await this._webSignerClient.completeOAuth(params)\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 * Retrieves information for the authenticated user.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getInfo(): Promise<User> {\n return this._webSignerClient.getUser()\n }\n\n /**\n * Checks if a user is currently logged in to the fourt.io SDK.\n */\n async isLoggedIn(): Promise<boolean> {\n return this._webSignerClient.isLoggedIn()\n }\n\n /**\n * Generates an access token with a lifespan of 15 minutes.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getToken(): Promise<string> {\n return this._webSignerClient.getToken()\n }\n\n /**\n * Logs out the user.\n */\n async logout(): Promise<void> {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\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'\nimport { NotFoundError } from '../errors/NotFoundError.js'\nimport { IndexedDbStamper } from '@turnkey/indexed-db-stamper'\nimport { decodeJwt } from 'jose'\n\ntype WebAuthnSignInParams = {\n email: string\n}\n\ntype InitEmailAuthParams = {\n email: string\n redirectUrl?: string\n}\n\ntype CompleteEmailAuthParams = {\n email: string\n otpCode: string\n}\n\ntype CompleteOAuthParams = {\n subOrgId: string\n}\n\ntype OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n oauth?: OAuthConfiguration\n}>\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private indexedDbStamper: IndexedDbStamper\n private webauthnStamper: WebauthnStamper\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 oauth,\n }: WebSignerClientConstructorParams) {\n const indexedDbStamper = new IndexedDbStamper()\n\n super({\n stamper: indexedDbStamper,\n configuration: configuration,\n })\n\n this.indexedDbStamper = indexedDbStamper\n this.webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n\n this.oauthConfiguration = oauth\n }\n\n public override async isLoggedIn() {\n await this.getPublicKey()\n return super.isLoggedIn()\n }\n\n public override async logout() {\n super.logout()\n this.indexedDbStamper.clear()\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 /**\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', 'POST', {\n provider,\n })\n\n return url\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {WebAuthnSignInParams} params params for the sign in\n */\n public async webAuthnSignIn({ email }: WebAuthnSignInParams) {\n const existingUserSubOrgId = await this.lookUpUser(email)\n\n if (!existingUserSubOrgId) {\n await this._createWebAuthnAccount({ email })\n } else {\n this.stamper = this.webauthnStamper\n await this.signIn(existingUserSubOrgId)\n\n this._sessionStore.type = SessionType.Passkeys\n\n // We should assure that the user and its credentialId are set\n if (!this._sessionStore.user || !this._sessionStore.user.credentialId) {\n return\n }\n\n this.webauthnStamper.allowCredentials = [\n {\n id: LibBase64.toBuffer(this._sessionStore.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handles auth user process with email according to the method of the used app.\n *\n * @param {InitEmailAuthParams} params params needed for the initialization of the auth process\n */\n public async initEmailAuth(params: InitEmailAuthParams) {\n await this.indexedDbStamper.resetKeyPair()\n const { otpId } = await this._initEmailAuth(params)\n if (!otpId) throw new NotFoundError('No OTP init response returned.')\n this._sessionStore.otpId = otpId\n }\n\n public async getPublicKey() {\n await this._initIndexedDbStamper()\n return this.indexedDbStamper.getPublicKey()!\n }\n\n public async resetKeyPair() {\n await this._initIndexedDbStamper()\n await this.indexedDbStamper.resetKeyPair()\n }\n\n /**\n * Verifies the provided otp code.\n *\n * @param {CompleteEmailAuthParams} params params needed for otp code verification\n */\n public async completeEmailAuth(params: CompleteEmailAuthParams) {\n await this._initIndexedDbStamper()\n\n if (!this._sessionStore.otpId)\n throw new NotFoundError('No OTP ID found in session store.')\n\n const publicKey = await this.getPublicKey()\n const { subOrgId } = await this.request('/v1/email/complete', 'POST', {\n otpId: this._sessionStore.otpId,\n otpCode: params.otpCode,\n publicKey,\n })\n\n if (!subOrgId)\n throw new NotFoundError('No OTP authentication response returned.')\n\n await this.signIn(subOrgId, publicKey)\n this._sessionStore.type = SessionType.Email\n this._sessionStore.clearOtpId()\n }\n\n /**\n * Completes oauth authentication.\n *\n * @param {CompleteOAuthParams} params params needed for oauth completion\n */\n public async completeOAuth(params: CompleteOAuthParams) {\n await this._initIndexedDbStamper()\n const publicKey = await this.getPublicKey()\n await this.signIn(params.subOrgId, publicKey)\n this._sessionStore.type = SessionType.OAuth\n }\n\n /**\n * Gets the email authentication method of the app.\n */\n public async getEmailAuthMethod() {\n const { method } = await this.request('/v1/email/method', 'GET')\n return method\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n */\n private async _updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n this._sessionStore.token === undefined\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this.webauthnStamper\n } else {\n this.stamper = this.indexedDbStamper\n }\n }\n\n /**\n * Creates a passkey account using the webauthn stamper.\n *\n * @param {WebAuthnSignInParams} params params for the creation of the account\n */\n private async _createWebAuthnAccount(params: WebAuthnSignInParams) {\n const { challenge, attestation } = await this._webauthnGenerateAttestation(\n params.email,\n )\n\n const { user, token } = await this.request('/v1/signup', 'POST', {\n email: params.email,\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n })\n\n this._sessionStore.user = {\n ...user,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.type = SessionType.Passkeys\n // Tokens are always returned on passkey signup\n this._sessionStore.token = token!\n this._scheduleRefresh(token!)\n }\n\n /**\n * Init account creation with email.\n *\n * @param {InitEmailAuthParams} params params for the creation of the account\n */\n private async _initEmailAuth(params: InitEmailAuthParams) {\n const response = await this.request('/v1/email/init', 'POST', {\n email: params.email,\n redirectUrl: params.redirectUrl\n ? params.redirectUrl.toString()\n : undefined,\n })\n\n return response\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 _initIndexedDbStamper() {\n if (!this.indexedDbStamper.getPublicKey()) {\n await this.indexedDbStamper.init()\n }\n this.stamper = this.indexedDbStamper\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClientConstructorParams,\n WebAuthnSignInParams,\n OAuthConfiguration,\n CompleteOAuthParams,\n}\n","/**\n * Browser-friendly base64url helpers.\n * - Uses btoa/atob and Uint8Array, no Node Buffer polyfill.\n * - Chunks when converting large ArrayBuffers to avoid call-stack issues.\n */\nclass LibBase64 {\n // Convert an ArrayBuffer to base64url (no padding)\n static fromBuffer(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer)\n const CHUNK_SIZE = 0x8000\n let binary = ''\n for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {\n const chunk = bytes.subarray(i, i + CHUNK_SIZE)\n // spread on TypedArray can be large; cast to any to satisfy TS\n binary += String.fromCharCode(...(chunk as any))\n }\n const base64 =\n typeof btoa === 'function'\n ? btoa(binary)\n : Buffer.from(bytes).toString('base64')\n return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n }\n\n // Convert base64url (no padding) to ArrayBuffer\n static toBuffer(base64url: string): ArrayBuffer {\n let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/')\n const pad = base64.length % 4\n if (pad) base64 += '='.repeat(4 - pad)\n\n const binary =\n typeof atob === 'function'\n ? atob(base64)\n : Buffer.from(base64, 'base64').toString('binary')\n const len = binary.length\n const bytes = new Uint8Array(len)\n for (let i = 0; i < len; i++) bytes[i] = binary.charCodeAt(i)\n return bytes.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 { createStore, type StoreApi } from 'zustand'\nimport { persist, createJSONStorage } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\ntype SessionState = {\n type?: SessionType\n user?: User\n token?: string\n otpId?: string\n}\n\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n constructor() {\n // `user` and `token` stay in memory (not persisted)\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt-session',\n storage: createJSONStorage(() => localStorage),\n // persist only these in localStorage\n partialize: (state) => ({\n type: state.type,\n otpId: state.otpId,\n }),\n }),\n )\n }\n\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n set token(token: string) {\n this._store.setState({ token })\n }\n\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n get otpId(): string | undefined {\n return this._store.getState().otpId\n }\n\n set otpId(otpId: string) {\n this._store.setState({ otpId })\n }\n\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n clearOtpId() {\n this._store.setState({ ...this._store.getState(), otpId: undefined })\n }\n\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearType()\n this.clearOtpId()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n token: undefined,\n otpId: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SessionStore } from '../session/index.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n Method,\n Route,\n} from '../types/routes.js'\nimport { decodeJwt } from 'jose'\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 _refreshPromise?: Promise<void>\n private _refreshTimer?: ReturnType<typeof setTimeout>\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 get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n public async getUser() {\n if (this._sessionStore.user) return this._sessionStore.user\n\n try {\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n // If unauthorized, try to refresh token and retry once\n if (error instanceof UnauthorizedError) {\n try {\n await this._refreshToken()\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n throw error\n }\n }\n throw error\n }\n }\n\n public async isLoggedIn() {\n const token = this._sessionStore.token\n\n // If we have a token and it's still valid, we're logged in\n if (token && !this._isTokenExpired(token)) return true\n\n // Otherwise try to refresh (covers no token and expired token)\n try {\n await this._refreshToken()\n return !!this._sessionStore.token\n } catch {\n return false\n }\n }\n\n public async getToken(): Promise<string> {\n // Try to use existing token\n if (!this._sessionStore.token) {\n // No token: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError(\n 'No token found, user might not be logged in',\n )\n }\n } else if (this._isTokenExpired(this._sessionStore.token)) {\n // Token expired: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError('Token expired and refresh failed')\n }\n }\n\n const token = this._sessionStore.token\n if (!token) {\n throw new UnauthorizedError('No token found, user might not be logged in')\n }\n return token\n }\n\n private _isTokenExpired(token: string): boolean {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (typeof decoded.exp === 'number') {\n return decoded.exp * 1000 <= Date.now()\n }\n return true // If no exp claim, consider it expired\n } catch {\n return true // If token is malformed, consider it expired\n }\n }\n\n public async logout() {\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n this._refreshTimer = undefined\n const logoutPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'logout_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(logoutPayload)\n await this.request('/v1/logout', 'POST', { payload: logoutPayload, stamp })\n this._sessionStore.clearAll()\n }\n\n public async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._sessionStore.token || !this._sessionStore.user) {\n throw new UnauthorizedError(\n 'SignerClient must be authenticated to sign a message',\n )\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._sessionStore.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._sessionStore.user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', 'POST', {\n stampedRequest,\n })\n\n return <Into>signature\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 async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', 'POST', { email })\n return subOrgId\n } catch (error) {\n if (error instanceof NotFoundError) return null\n throw error\n }\n }\n\n protected async signIn(subOrgId: string, publicKey?: string) {\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: subOrgId,\n })\n\n const { user, token } = await this.request('/v1/signin', 'POST', {\n stampedRequest,\n publicKey,\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._sessionStore.user = {\n ...user,\n credentialId: credentialId,\n }\n this._sessionStore.token = token\n this._scheduleRefresh(token)\n return { user, token }\n }\n\n protected async stampAndRefresh() {\n const refreshPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'refresh_token_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(refreshPayload)\n const { token } = await this.request('/v1/refresh', 'POST', {\n payload: refreshPayload,\n stamp,\n })\n this._sessionStore.token = token\n return { token }\n }\n\n protected async request<R extends Route, M extends Method>(\n route: R,\n method: M,\n body?: AuthenticationServiceBody<R>,\n ): Promise<AuthenticationServiceResponse<R>> {\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 if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method,\n body: method === 'POST' ? JSON.stringify(body) : undefined,\n headers,\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<R>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n throw new UnauthorizedError(error.message)\n }\n case 'NotFoundError': {\n throw new NotFoundError(error.message)\n }\n case 'BadRequestError': {\n throw new BadRequestError(error.message)\n }\n default: {\n throw new Error(error.message)\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<R>\n }\n\n /**\n * Compute milliseconds until refresh time.\n * - expSeconds is the JWT exp claim (seconds).\n * - earlyMinutes is how many minutes before exp to refresh (default 2).\n * Returns 0 if refresh time is already past.\n */\n private _computeRefreshDelayMs(expSeconds: number, earlyMinutes = 2): number {\n const expiryMs = expSeconds * 1000\n const refreshMs = expiryMs - earlyMinutes * 60 * 1000\n const now = Date.now()\n const delay = refreshMs - now\n return delay <= 0 ? 0 : delay\n }\n\n protected _scheduleRefresh(token: string) {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (!decoded.exp) return\n\n const delay = this._computeRefreshDelayMs(decoded.exp, 2)\n\n // Clear previous timer to avoid duplicates\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n\n // Schedule refresh\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n this._refreshToken()\n }, delay)\n } catch {\n // ignore errors\n }\n }\n\n private async _refreshToken(): Promise<void> {\n if (this._refreshPromise) return this._refreshPromise\n\n // Keep a reference so callers can await the same promise\n this._refreshPromise = (async () => {\n const TIMEOUT_MS = 10_000\n const RETRY_DELAY_MS = 5_000\n\n try {\n // Avoid hanging indefinitely by racing the request with a timeout\n const refreshPromise = this.stampAndRefresh()\n const data = await Promise.race([\n refreshPromise,\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error('Refresh timeout')), TIMEOUT_MS),\n ),\n ])\n\n if (!data || !data.token) {\n // Treat missing tokens as auth failure\n throw new UnauthorizedError('Refresh did not return tokens')\n }\n\n this._sessionStore.token = data.token\n this._scheduleRefresh(data.token)\n } catch (error) {\n console.error('Token refresh failed:', error)\n // On auth errors, clear session to avoid repeated failing retries\n if (error instanceof UnauthorizedError) {\n this._sessionStore.clearToken()\n this._sessionStore.clearUser()\n\n throw error\n }\n\n // Transient error: schedule a retry (non-blocking) and rethrow so callers know it failed\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n const MAX_RETRIES = 5\n let retryCount = 0\n\n // We schedule a background retry after RETRY_DELAY_MS using setTimeout\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {\n // Increments retryCount and, if still under MAX_RETRIES, schedules\n // another retry using exponential backoff (capped at 60s)\n retryCount++\n if (retryCount <= MAX_RETRIES) {\n const nextDelay = Math.min(\n RETRY_DELAY_MS * 2 ** (retryCount - 1),\n 60_000,\n )\n this._refreshTimer = setTimeout(() => {\n // When the timer fires we clear the stored id and call _refreshToken() in a\n // fire-and-forget manner (void ... .catch(...)) so the retry runs asynchronously\n // and doesn't block or change the control flow of the original caller.\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {})\n }, nextDelay)\n }\n })\n }, RETRY_DELAY_MS)\n\n throw error\n } finally {\n this._refreshPromise = undefined\n }\n })()\n\n return this._refreshPromise\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","class UnauthorizedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthorizedError.name\n }\n}\n\nexport { UnauthorizedError }\n","class NotFoundError extends Error {\n constructor(message: string) {\n super(message)\n this.name = NotFoundError.name\n }\n}\n\nexport { NotFoundError }\n","class UnauthenticatedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthenticatedError.name\n }\n}\n\nexport { UnauthenticatedError }\n","import {\n type Chain,\n type Client,\n type GetTransactionType,\n type Hex,\n type IsNarrowable,\n type JsonRpcAccount,\n type LocalAccount,\n type TypedData,\n type TypedDataDefinition,\n type SignableMessage,\n type SerializeTransactionFn,\n type TransactionSerializable,\n type TransactionSerialized,\n type Transport,\n hashMessage,\n hashTypedData,\n serializeTransaction,\n keccak256,\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 CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client<\n Transport,\n Chain | undefined,\n JsonRpcAccount | LocalAccount | undefined\n >\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: ({ message }: { message: SignableMessage }) =>\n this.signMessage(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 = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toLightSmartAccount({\n 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 = await 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' | '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, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\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":";;;;;;;;AAUA,IAAM,cAAN,MAAkB;AAAA,EAChB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,MAAM,WAAW,QAA4C;AAC3D,WAAO,KAAK,iBAAiB,cAAc,MAAM;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,QAAgD;AAC7D,UAAM,KAAK,iBAAiB,kBAAkB,MAAM;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAA8C;AAClD,WAAO,KAAK,iBAAiB,mBAAmB;AAAA,EAClD;AACF;;;ACpCA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjE,MAAM,OAAO,QAA8B;AACzC,WAAO,KAAK,iBAAiB,eAAe,MAAM;AAAA,EACpD;AACF;;;ACjBA,YAAY,UAAU;;;ACAtB,IAAM,YAAN,MAAgB;AAAA;AAAA;A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../src/modules/auth/oauth/google.ts","../src/lib/sha256.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/session/index.ts","../src/signer/index.ts","../src/errors/UnauthorizedError.ts","../src/errors/NotFoundError.ts","../src/errors/UnauthenticatedError.ts","../src/third-party/viem.ts","../src/index.ts"],"sourcesContent":["import type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClient,\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 {InitEmailAuthParams} params to initialize the user authentication process.\n * @returns {Promise<void>} promise that resolves when the initialization is complete.\n */\n async initialize(params: InitEmailAuthParams): Promise<void> {\n return this._webSignerClient.initEmailAuth(params)\n }\n\n /**\n * Completes email authentication with OTP code.\n *\n * @param params {CompleteEmailAuthParams} params to complete the authentication process.\n * @returns {Promise<void>} promise that completes the authentication process.\n */\n async complete(params: CompleteEmailAuthParams): Promise<void> {\n await this._webSignerClient.completeEmailAuth(params)\n }\n\n /**\n * Get the email authentication method of the app, that was chosen in fourt.io dashboard.\n * It can be either `magiclink` or `otp`.\n *\n * @returns {Promise<'otp' | 'magiclink'>} promise that resolves to the email authentication method.\n */\n async getAuthMethod(): Promise<'otp' | 'magiclink'> {\n return this._webSignerClient.getEmailAuthMethod()\n }\n}\n\nexport { EmailModule }\n","import type { WebSignerClient } 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 {string} email email of the user\n */\n async signIn(email: string) {\n return this._webSignerClient.webAuthnSignIn(email)\n }\n}\n\nexport { PasskeysModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass GoogleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\n const initUrl = await this._webSignerClient.getOAuthInitUrl('google')\n\n const url = new URL(initUrl)\n\n const internalUrl = new URL(\n 'v1/oauth/google',\n this._webSignerClient.configuration.apiUrl,\n ).href\n url.searchParams.set('redirect_uri', internalUrl)\n\n const publicKey = await this._webSignerClient.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 { GoogleModule }\n","class LibSha256 {\n /**\n * Compute SHA-256 and return hex string using Web Crypto when available.\n * Falls back to Node's crypto.createHash when running in Node.\n */\n static async sha256Hex(\n input: string | ArrayBuffer | Uint8Array,\n ): Promise<string> {\n // normalize input to Uint8Array\n let data: Uint8Array\n if (typeof input === 'string') {\n data = new TextEncoder().encode(input)\n } else if (input instanceof Uint8Array) {\n data = input\n } else {\n data = new Uint8Array(input)\n }\n\n // Prefer Web Crypto Subtle API\n const subtle =\n typeof globalThis !== 'undefined' && (globalThis as any).crypto?.subtle\n ? (globalThis as any).crypto.subtle\n : undefined\n\n if (subtle) {\n const hash = await subtle.digest('SHA-256', data)\n return Array.from(new Uint8Array(hash))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n\n // Fallback for Node (synchronous)\n try {\n const nodeCrypto = require('crypto')\n const hash = nodeCrypto.createHash('sha256').update(data).digest('hex')\n return hash\n } catch {\n throw new Error(\n 'No crypto provider available. Provide a global crypto.subtle or run in Node 18+.',\n )\n }\n }\n}\n\nexport { LibSha256 }\n","class BadRequestError extends Error {\n constructor(message: string) {\n super(message)\n this.name = BadRequestError.name\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 await this._webSignerClient.resetKeyPair()\n const publicKey = await this._webSignerClient.getPublicKey()\n const internalUrl = new URL(\n 'v1/oauth/facebook',\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 publicKey,\n internalUrl: internalUrl,\n origin: window.location.origin,\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 `Failed to create OAuth state. Error: ${response.statusText}`,\n )\n }\n\n const { authUrl } = await response.json()\n if (!authUrl) {\n throw new BadRequestError(response.statusText)\n }\n\n return authUrl\n }\n}\n\nexport { FacebookModule }\n","import * as jose from 'jose'\nimport type { WebSignerClient } from '../../../signer/web.js'\nimport { LibSha256 } from '../../../lib/sha256.js'\n\nclass AppleModule {\n constructor(private readonly _webSignerClient: WebSignerClient) {}\n\n async init(): Promise<string> {\n await this._webSignerClient.resetKeyPair()\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.getPublicKey()\n\n const nonce = await LibSha256.sha256Hex(publicKey)\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 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 type { CompleteOAuthParams, WebSignerClient } from '../../signer/web.js'\nimport { GoogleModule } from './oauth/google.js'\nimport { FacebookModule } from './oauth/facebook.js'\nimport { AppleModule } from './oauth/apple.js'\n\n/**\n * A module for interacting with the OAuth authentication methods.\n * Available through the `auth.oauth` property on a `FourtWebSigner` instance.\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 /**\n * Completes oauth authentication.\n *\n * @param params {CompleteOAuthParams} params needed for oauth completion\n * @returns {Promise<void>} promise that completes the oauth authentication process.\n */\n async complete(params: CompleteOAuthParams): Promise<void> {\n await this._webSignerClient.completeOAuth(params)\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 * Retrieves information for the authenticated user.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getInfo(): Promise<User> {\n return this._webSignerClient.getUser()\n }\n\n /**\n * Checks if a user is currently logged in to the fourt.io SDK.\n */\n async isLoggedIn(): Promise<boolean> {\n return this._webSignerClient.isLoggedIn()\n }\n\n /**\n * Generates an access token with a lifespan of 15 minutes.\n * Assumes a user is already logged in, otherwise it will throw an error.\n */\n async getToken(): Promise<string> {\n return this._webSignerClient.getToken()\n }\n\n /**\n * Logs out the user.\n */\n async logout(): Promise<void> {\n return this._webSignerClient.logout()\n }\n}\n\nexport { UserModule }\n","import { getWebAuthnAttestation } from '@turnkey/http'\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'\nimport { NotFoundError } from '../errors/NotFoundError.js'\nimport { IndexedDbStamper } from '@turnkey/indexed-db-stamper'\n\ntype InitEmailAuthParams = {\n email: string\n redirectUrl?: string\n}\n\ntype CompleteEmailAuthParams = {\n email: string\n otpCode: string\n}\n\ntype CompleteOAuthParams = {\n subOrgId: string\n}\n\ntype OAuthConfiguration = {\n common: {\n redirectUrl: string\n }\n}\n\ntype WebSignerClientConstructorParams = SignerClientInheritedConstructorParams<{\n webauthn: {\n rpId: string\n }\n oauth?: OAuthConfiguration\n}>\n\n/**\n * A signer client for web applications.\n */\nclass WebSignerClient extends SignerClient {\n private indexedDbStamper: IndexedDbStamper\n private webauthnStamper: WebauthnStamper\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 oauth,\n }: WebSignerClientConstructorParams) {\n const indexedDbStamper = new IndexedDbStamper()\n\n super({\n stamper: indexedDbStamper,\n configuration: configuration,\n })\n\n this.indexedDbStamper = indexedDbStamper\n this.webauthnStamper = new WebauthnStamper({ rpId: webauthn.rpId })\n\n this.oauthConfiguration = oauth\n }\n\n public override async isLoggedIn() {\n await this.getPublicKey()\n return super.isLoggedIn()\n }\n\n public override async logout() {\n // Init indexedDb stamper in order to sign logout request\n await this._initIndexedDbStamper()\n super.logout()\n this.indexedDbStamper.clear()\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 /**\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', 'POST', {\n provider,\n })\n\n return url\n }\n\n /**\n * Signs in a user with webauthn.\n *\n * @param {string} email email of the user\n */\n public async webAuthnSignIn(email: string) {\n const publicKey = await this.getPublicKey()\n const existingUserSubOrgId = await this.lookUpUser(email)\n this._sessionStore.type = SessionType.Passkeys\n this.stamper = this.webauthnStamper\n\n if (!existingUserSubOrgId) {\n const { challenge, attestation } =\n await this._webAuthnGenerateAttestation(email)\n\n const { user, token } = await this.request('/v1/passkey/init', 'POST', {\n email,\n challenge: LibBase64.fromBuffer(challenge),\n attestation,\n publicKey,\n })\n\n this._sessionStore.user = {\n ...user,\n credentialId: attestation.credentialId,\n }\n this._sessionStore.token = token\n } else {\n await this.signIn(existingUserSubOrgId, publicKey)\n\n // We should assure that the user and its credentialId are set\n if (!this._sessionStore.user || !this._sessionStore.user.credentialId) {\n return\n }\n\n this.webauthnStamper.allowCredentials = [\n {\n id: LibBase64.toBuffer(this._sessionStore.user.credentialId),\n type: 'public-key',\n transports: ['internal', 'usb'],\n },\n ]\n }\n }\n\n /**\n * Handles auth user process with email according to the method of the used app.\n *\n * @param {InitEmailAuthParams} params params needed for the initialization of the auth process\n */\n public async initEmailAuth(params: InitEmailAuthParams) {\n await this.indexedDbStamper.resetKeyPair()\n const { otpId } = await this._initEmailAuth(params)\n if (!otpId) throw new NotFoundError('No OTP init response returned.')\n this._sessionStore.otpId = otpId\n }\n\n public async getPublicKey() {\n await this._initIndexedDbStamper()\n return this.indexedDbStamper.getPublicKey()!\n }\n\n public async resetKeyPair() {\n await this._initIndexedDbStamper()\n await this.indexedDbStamper.resetKeyPair()\n }\n\n /**\n * Verifies the provided otp code.\n *\n * @param {CompleteEmailAuthParams} params params needed for otp code verification\n */\n public async completeEmailAuth(params: CompleteEmailAuthParams) {\n if (!this._sessionStore.otpId)\n throw new NotFoundError('No OTP ID found in session store.')\n\n const publicKey = await this.getPublicKey()\n const { subOrgId } = await this.request('/v1/email/complete', 'POST', {\n otpId: this._sessionStore.otpId,\n otpCode: params.otpCode,\n publicKey,\n })\n\n if (!subOrgId)\n throw new NotFoundError('No OTP authentication response returned.')\n\n await this.signIn(subOrgId, publicKey)\n this._sessionStore.type = SessionType.Email\n this._sessionStore.clearOtpId()\n }\n\n /**\n * Completes oauth authentication.\n *\n * @param {CompleteOAuthParams} params params needed for oauth completion\n */\n public async completeOAuth(params: CompleteOAuthParams) {\n const publicKey = await this.getPublicKey()\n await this.signIn(params.subOrgId, publicKey)\n this._sessionStore.type = SessionType.OAuth\n }\n\n /**\n * Gets the email authentication method of the app.\n */\n public async getEmailAuthMethod() {\n const { method } = await this.request('/v1/email/method', 'GET')\n return method\n }\n\n /**\n * Checks for an existing session and if exists, updates the stamper accordingly.\n */\n private async _updateStamper() {\n // User is not signed in\n if (\n this._sessionStore.type === undefined &&\n this._sessionStore.token === undefined\n )\n return\n if (this._sessionStore.type === SessionType.Passkeys) {\n this.stamper = this.webauthnStamper\n } else {\n this.stamper = this.indexedDbStamper\n }\n }\n\n /**\n * Init account creation with email.\n *\n * @param {InitEmailAuthParams} params params for the creation of the account\n */\n private async _initEmailAuth(params: InitEmailAuthParams) {\n const response = await this.request('/v1/email/init', 'POST', {\n email: params.email,\n redirectUrl: params.redirectUrl\n ? params.redirectUrl.toString()\n : undefined,\n })\n\n return response\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 _initIndexedDbStamper() {\n if (!this.indexedDbStamper.getPublicKey()) {\n await this.indexedDbStamper.init()\n }\n this.stamper = this.indexedDbStamper\n }\n}\n\nexport { WebSignerClient }\nexport type {\n CompleteEmailAuthParams,\n InitEmailAuthParams,\n WebSignerClientConstructorParams,\n OAuthConfiguration,\n CompleteOAuthParams,\n}\n","/**\n * Browser-friendly base64url helpers.\n * - Uses btoa/atob and Uint8Array, no Node Buffer polyfill.\n * - Chunks when converting large ArrayBuffers to avoid call-stack issues.\n */\nclass LibBase64 {\n // Convert an ArrayBuffer to base64url (no padding)\n static fromBuffer(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer)\n const CHUNK_SIZE = 0x8000\n let binary = ''\n for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {\n const chunk = bytes.subarray(i, i + CHUNK_SIZE)\n // spread on TypedArray can be large; cast to any to satisfy TS\n binary += String.fromCharCode(...(chunk as any))\n }\n const base64 =\n typeof btoa === 'function'\n ? btoa(binary)\n : Buffer.from(bytes).toString('base64')\n return base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n }\n\n // Convert base64url (no padding) to ArrayBuffer\n static toBuffer(base64url: string): ArrayBuffer {\n let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/')\n const pad = base64.length % 4\n if (pad) base64 += '='.repeat(4 - pad)\n\n const binary =\n typeof atob === 'function'\n ? atob(base64)\n : Buffer.from(base64, 'base64').toString('binary')\n const len = binary.length\n const bytes = new Uint8Array(len)\n for (let i = 0; i < len; i++) bytes[i] = binary.charCodeAt(i)\n return bytes.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 { createStore, type StoreApi } from 'zustand'\nimport { persist, createJSONStorage } from 'zustand/middleware'\nimport { User } from '../types/entities.js'\n\nenum SessionType {\n Email = 'email',\n Passkeys = 'passkeys',\n OAuth = 'oauth',\n}\n\ntype SessionState = {\n type?: SessionType\n user?: User\n token?: string\n otpId?: string\n}\n\nclass SessionStore {\n private readonly _store: StoreApi<SessionState>\n\n constructor() {\n // `user` and `token` stay in memory (not persisted)\n this._store = createStore<SessionState>()(\n persist(this._getInitialState, {\n name: 'fourt-session',\n storage: createJSONStorage(() => localStorage),\n // persist only these in localStorage\n partialize: (state) => ({\n type: state.type,\n otpId: state.otpId,\n }),\n }),\n )\n }\n\n get type(): SessionType | undefined {\n return this._store.getState().type\n }\n\n set type(type: SessionType) {\n this._store.setState({ type })\n }\n\n get token(): string | undefined {\n return this._store.getState().token\n }\n\n set token(token: string) {\n this._store.setState({ token })\n }\n\n get user(): User | undefined {\n return this._store.getState().user\n }\n\n set user(user: User) {\n this._store.setState({ ...this._store.getState(), user })\n }\n\n get otpId(): string | undefined {\n return this._store.getState().otpId\n }\n\n set otpId(otpId: string) {\n this._store.setState({ otpId })\n }\n\n clearUser() {\n this._store.setState({ ...this._store.getState(), user: undefined })\n }\n\n clearType() {\n this._store.setState({ ...this._store.getState(), type: undefined })\n }\n\n clearToken() {\n this._store.setState({ ...this._store.getState(), token: undefined })\n }\n\n clearOtpId() {\n this._store.setState({ ...this._store.getState(), otpId: undefined })\n }\n\n clearAll() {\n this.clearToken()\n this.clearUser()\n this.clearType()\n this.clearOtpId()\n }\n\n private _getInitialState(): SessionState {\n return {\n type: undefined,\n user: undefined,\n token: undefined,\n otpId: undefined,\n }\n }\n}\n\nexport { SessionType, SessionStore }\nexport type { SessionState }\n","import { TurnkeyClient } from '@turnkey/http'\nimport {\n BadRequestError,\n NotFoundError,\n UnauthorizedError,\n} from '../errors/index.js'\nimport { SessionStore } from '../session/index.js'\nimport { APIResponse } from '../types/rest.js'\nimport {\n AuthenticationServiceBody,\n AuthenticationServiceResponse,\n Method,\n Route,\n} from '../types/routes.js'\nimport { decodeJwt } from 'jose'\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 _refreshPromise?: Promise<void>\n private _refreshTimer?: ReturnType<typeof setTimeout>\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 get configuration(): Required<SignerClientConfiguration> {\n return this._configuration\n }\n\n public async getUser() {\n if (this._sessionStore.user) return this._sessionStore.user\n\n try {\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n // If unauthorized, try to refresh token and retry once\n if (error instanceof UnauthorizedError) {\n try {\n await this._refreshToken()\n const user = await this.request('/v1/me', 'GET')\n this._sessionStore.user = user\n return user\n } catch (error) {\n throw error\n }\n }\n throw error\n }\n }\n\n public async isLoggedIn() {\n const token = this._sessionStore.token\n\n // If we have a token and it's still valid, we're logged in\n if (token && !this._isTokenExpired(token)) return true\n\n // Otherwise try to refresh (covers no token and expired token)\n try {\n await this._refreshToken()\n return !!this._sessionStore.token\n } catch {\n return false\n }\n }\n\n public async getToken(): Promise<string> {\n // Try to use existing token\n if (!this._sessionStore.token) {\n // No token: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError(\n 'No token found, user might not be logged in',\n )\n }\n } else if (this._isTokenExpired(this._sessionStore.token)) {\n // Token expired: attempt refresh (may throw)\n try {\n await this._refreshToken()\n } catch {\n throw new UnauthorizedError('Token expired and refresh failed')\n }\n }\n\n const token = this._sessionStore.token\n if (!token) {\n throw new UnauthorizedError('No token found, user might not be logged in')\n }\n return token\n }\n\n private _isTokenExpired(token: string): boolean {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (typeof decoded.exp === 'number') {\n return decoded.exp * 1000 <= Date.now()\n }\n return true // If no exp claim, consider it expired\n } catch {\n return true // If token is malformed, consider it expired\n }\n }\n\n public async logout() {\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n this._refreshTimer = undefined\n const logoutPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'logout_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(logoutPayload)\n await this.request('/v1/logout', 'POST', { payload: logoutPayload, stamp })\n this._sessionStore.clearAll()\n }\n\n public async signRawMessage<Into extends string>(msg: string): Promise<Into> {\n if (!this._sessionStore.token || !this._sessionStore.user) {\n throw new UnauthorizedError(\n 'SignerClient must be authenticated to sign a message',\n )\n }\n\n const stampedRequest = await this._turnkeyClient.stampSignRawPayload({\n organizationId: this._sessionStore.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._sessionStore.user.walletAddress,\n },\n })\n\n const { signature } = await this.request('/v1/sign', 'POST', {\n stampedRequest,\n })\n\n return <Into>signature\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 async lookUpUser(email: string): Promise<string | null> {\n try {\n const { subOrgId } = await this.request('/v1/lookup', 'POST', { email })\n return subOrgId\n } catch (error) {\n if (error instanceof NotFoundError) return null\n throw error\n }\n }\n\n protected async signIn(subOrgId: string, publicKey: string) {\n const stampedRequest = await this._turnkeyClient.stampGetWhoami({\n organizationId: subOrgId,\n })\n\n const { user, token } = await this.request('/v1/signin', 'POST', {\n stampedRequest,\n publicKey,\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._sessionStore.user = {\n ...user,\n credentialId,\n }\n this._sessionStore.token = token\n this._scheduleRefresh(token)\n return { user, token }\n }\n\n protected async stampAndRefresh() {\n const refreshPayload = JSON.stringify({\n timestamp: Date.now(),\n type: 'refresh_token_request',\n })\n const stamp = await this._turnkeyClient.stamper.stamp(refreshPayload)\n const { token } = await this.request('/v1/refresh', 'POST', {\n payload: refreshPayload,\n stamp,\n })\n this._sessionStore.token = token\n return { token }\n }\n\n protected async request<R extends Route, M extends Method>(\n route: R,\n method: M,\n body?: AuthenticationServiceBody<R>,\n ): Promise<AuthenticationServiceResponse<R>> {\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 if (token) {\n headers['Authorization'] = `Bearer ${token}`\n }\n\n const response = await fetch(url, {\n method,\n body: method === 'POST' ? JSON.stringify(body) : undefined,\n headers,\n })\n\n const { data, error } = (await response.json()) as APIResponse<\n AuthenticationServiceResponse<R>\n >\n\n if (error) {\n switch (error.kind) {\n case 'UnauthorizedError': {\n throw new UnauthorizedError(error.message)\n }\n case 'NotFoundError': {\n throw new NotFoundError(error.message)\n }\n case 'BadRequestError': {\n throw new BadRequestError(error.message)\n }\n default: {\n throw new Error(error.message)\n }\n }\n }\n\n return { ...data } as AuthenticationServiceResponse<R>\n }\n\n /**\n * Compute milliseconds until refresh time.\n * - expSeconds is the JWT exp claim (seconds).\n * - earlyMinutes is how many minutes before exp to refresh (default 2).\n * Returns 0 if refresh time is already past.\n */\n private _computeRefreshDelayMs(expSeconds: number, earlyMinutes = 2): number {\n const expiryMs = expSeconds * 1000\n const refreshMs = expiryMs - earlyMinutes * 60 * 1000\n const now = Date.now()\n const delay = refreshMs - now\n return delay <= 0 ? 0 : delay\n }\n\n protected _scheduleRefresh(token: string) {\n try {\n const decoded = decodeJwt(token) as { exp?: number }\n if (!decoded.exp) return\n\n const delay = this._computeRefreshDelayMs(decoded.exp, 2)\n\n // Clear previous timer to avoid duplicates\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n\n // Schedule refresh\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n this._refreshToken()\n }, delay)\n } catch {\n // ignore errors\n }\n }\n\n private async _refreshToken(): Promise<void> {\n if (this._refreshPromise) return this._refreshPromise\n\n // Keep a reference so callers can await the same promise\n this._refreshPromise = (async () => {\n const TIMEOUT_MS = 10_000\n const RETRY_DELAY_MS = 5_000\n\n try {\n // Avoid hanging indefinitely by racing the request with a timeout\n const refreshPromise = this.stampAndRefresh()\n const data = await Promise.race([\n refreshPromise,\n new Promise<never>((_, reject) =>\n setTimeout(() => reject(new Error('Refresh timeout')), TIMEOUT_MS),\n ),\n ])\n\n if (!data || !data.token) {\n // Treat missing tokens as auth failure\n throw new UnauthorizedError('Refresh did not return tokens')\n }\n\n this._sessionStore.token = data.token\n this._scheduleRefresh(data.token)\n } catch (error) {\n console.error('Token refresh failed:', error)\n // On auth errors, clear session to avoid repeated failing retries\n if (error instanceof UnauthorizedError) {\n this._sessionStore.clearToken()\n this._sessionStore.clearUser()\n\n throw error\n }\n\n // Transient error: schedule a retry (non-blocking) and rethrow so callers know it failed\n if (this._refreshTimer) clearTimeout(this._refreshTimer)\n const MAX_RETRIES = 5\n let retryCount = 0\n\n // We schedule a background retry after RETRY_DELAY_MS using setTimeout\n this._refreshTimer = setTimeout(() => {\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {\n // Increments retryCount and, if still under MAX_RETRIES, schedules\n // another retry using exponential backoff (capped at 60s)\n retryCount++\n if (retryCount <= MAX_RETRIES) {\n const nextDelay = Math.min(\n RETRY_DELAY_MS * 2 ** (retryCount - 1),\n 60_000,\n )\n this._refreshTimer = setTimeout(() => {\n // When the timer fires we clear the stored id and call _refreshToken() in a\n // fire-and-forget manner (void ... .catch(...)) so the retry runs asynchronously\n // and doesn't block or change the control flow of the original caller.\n this._refreshTimer = undefined\n void this._refreshToken().catch(() => {})\n }, nextDelay)\n }\n })\n }, RETRY_DELAY_MS)\n\n throw error\n } finally {\n this._refreshPromise = undefined\n }\n })()\n\n return this._refreshPromise\n }\n}\n\nexport { SignerClient }\nexport type {\n SignerClientConstructorParams,\n SignerClientInheritedConstructorParams,\n}\n","class UnauthorizedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthorizedError.name\n }\n}\n\nexport { UnauthorizedError }\n","class NotFoundError extends Error {\n constructor(message: string) {\n super(message)\n this.name = NotFoundError.name\n }\n}\n\nexport { NotFoundError }\n","class UnauthenticatedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = UnauthenticatedError.name\n }\n}\n\nexport { UnauthenticatedError }\n","import {\n type Chain,\n type Client,\n type GetTransactionType,\n type Hex,\n type IsNarrowable,\n type JsonRpcAccount,\n type LocalAccount,\n type TypedData,\n type TypedDataDefinition,\n type SignableMessage,\n type SerializeTransactionFn,\n type TransactionSerializable,\n type TransactionSerialized,\n type Transport,\n hashMessage,\n hashTypedData,\n serializeTransaction,\n keccak256,\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 CurrentUserToLightSmartAccountParams = {\n owner: LocalAccount\n client: Client<\n Transport,\n Chain | undefined,\n JsonRpcAccount | LocalAccount | undefined\n >\n}\n\nclass ViemModule {\n constructor(private readonly _signerClient: SignerClient) {}\n\n async toLocalAccount(): Promise<LocalAccount> {\n const user = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toAccount({\n address: user.walletAddress,\n signMessage: ({ message }: { message: SignableMessage }) =>\n this.signMessage(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 = await this._signerClient.getUser()\n\n if (!user) {\n throw new UnauthenticatedError('Signer not authenticated')\n }\n\n return toLightSmartAccount({\n 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 = await 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' | '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, oauth },\n }: FourtWebSignerConstructorParams) {\n this._webSignerClient = new WebSignerClient({\n configuration,\n webauthn,\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":";;;;;;;;AAUA,IAAM,cAAN,MAAkB;AAAA,EAChB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,MAAM,WAAW,QAA4C;AAC3D,WAAO,KAAK,iBAAiB,cAAc,MAAM;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,QAAgD;AAC7D,UAAM,KAAK,iBAAiB,kBAAkB,MAAM;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAA8C;AAClD,WAAO,KAAK,iBAAiB,mBAAmB;AAAA,EAClD;AACF;;;ACpCA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAA6B,kBAAmC;AAAnC;AAAA,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjE,MAAM,OAAO,OAAe;AAC1B,WAAO,KAAK,iBAAiB,eAAe,KAAK;AAAA,EACnD;AACF;;;ACjBA,YAAY,UAAU;;;ACAtB,IAAM,YAAN,MAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKd,aAAa,UACX,OACiB;AAEjB,QAAI;AACJ,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,YAAY,EAAE,OAAO,KAAK;AAAA,IACvC,WAAW,iBAAiB,YAAY;AACtC,aAAO;AAAA,IACT,OAAO;AACL,aAAO,IAAI,WAAW,KAAK;AAAA,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BAAN,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,MAAM;AAAA,EAC1B,GAAoC;AAClC,SAAK,mBAAmB,IAAI,gBAAgB;AAAA,MAC1C;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","error"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fourt/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "TypeScript SDK for interacting with fourt.io",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@turnkey/webauthn-stamper": "^0.6.0",
|
|
40
40
|
"jose": "^6.1.3",
|
|
41
41
|
"permissionless": "^0.3.2",
|
|
42
|
-
"viem": "^2.44.
|
|
43
|
-
"zustand": "^5.0.
|
|
42
|
+
"viem": "^2.44.2",
|
|
43
|
+
"zustand": "^5.0.10"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/sha.js": "^2.4.4",
|