diff --git a/src/core/auth.ts b/src/core/auth.ts index 90211b86..29797644 100644 --- a/src/core/auth.ts +++ b/src/core/auth.ts @@ -12,6 +12,7 @@ import { BrowserStorage, BUILD_ENV, jsonToBase64, + LOGIN_PROVIDER, LoginParams, SocialMfaModParams, UX_MODE, @@ -350,6 +351,59 @@ export class Auth { params: { ...defaultParams, ...params, + loginProvider: "authenticator", + }, + sessionId: this.sessionId, + }; + + const result = await this.authHandler(`${this.baseUrl}/start`, dataObject); + if (this.options.uxMode === UX_MODE.REDIRECT) return undefined; + if (result.error) return false; + return true; + } + + async addAuthenticatorFactor(params: Partial): Promise { + if (!this.sessionId) throw LoginError.userNotLoggedIn(); + + // in case of redirect mode, redirect url will be dapp specified + // in case of popup mode, redirect url will be sdk specified + const defaultParams: BaseRedirectParams = { + redirectUrl: this.options.redirectUrl, + }; + + const dataObject: AuthSessionConfig = { + actionType: AUTH_ACTIONS.ADD_AUTHENTICATOR_FACTOR, + options: this.options, + params: { + ...defaultParams, + ...params, + loginProvider: LOGIN_PROVIDER.AUTHENTICATOR, + }, + sessionId: this.sessionId, + }; + + const result = await this.authHandler(`${this.baseUrl}/start`, dataObject); + if (this.options.uxMode === UX_MODE.REDIRECT) return undefined; + if (result.error) return false; + return true; + } + + async addPasskeyFactor(params: Partial): Promise { + if (!this.sessionId) throw LoginError.userNotLoggedIn(); + + // in case of redirect mode, redirect url will be dapp specified + // in case of popup mode, redirect url will be sdk specified + const defaultParams: BaseRedirectParams = { + redirectUrl: this.options.redirectUrl, + }; + + const dataObject: AuthSessionConfig = { + actionType: AUTH_ACTIONS.ADD_PASSKEY_FACTOR, + options: this.options, + params: { + ...defaultParams, + ...params, + loginProvider: LOGIN_PROVIDER.PASSKEYS, }, sessionId: this.sessionId, }; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index e477fc53..54799665 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -38,6 +38,8 @@ export const LOGIN_PROVIDER = { SMS_PASSWORDLESS: "sms_passwordless", WEBAUTHN: "webauthn", JWT: "jwt", + PASSKEYS: "passkeys", + AUTHENTICATOR: "authenticator", } as const; export const MFA_LEVELS = { @@ -52,6 +54,8 @@ export const AUTH_ACTIONS = { ENABLE_MFA: "enable_mfa", MANAGE_MFA: "manage_mfa", MODIFY_SOCIAL_FACTOR: "modify_social_factor", + ADD_AUTHENTICATOR_FACTOR: "add_authenticator_factor", + ADD_PASSKEY_FACTOR: "add_passkey_factor", } as const; export const BUILD_ENV = { diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 9546f00c..86da5b5d 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -234,6 +234,7 @@ export type SocialMfaModParams = { */ extraLoginOptions?: ExtraLoginOptions; }; + export const LANGUAGES = { en: "en", ja: "ja",