@circle-fin/w3s-pw-web-sdk
Version:
Javascript/Typescript SDK for Circle Programmable Wallets
218 lines (217 loc) • 8.18 kB
TypeScript
import { SocialLoginProvider } from './types';
import type { AppSettings, Authentication, ChallengeCompleteCallback, Configs, CustomLinks, Localizations, LoginCompleteCallback, PostMessageEvent, Resources, SecurityQuestion, ThemeColor } from './types';
export declare class W3SSdk {
private readonly serviceUrl;
private static instance;
private readonly iframe;
private readonly window;
private configs?;
private challenge?;
private securityQuestions?;
private securityQuestionsRequiredCount;
private securityConfirmItems?;
private localizations?;
private themeColor?;
private resources?;
private customLinks?;
private deviceInfo?;
private socialLoginToken?;
private socialLoginProvider?;
private firebaseApp?;
/**
* Callback function that is called when the challenge is completed.
*/
private onComplete?;
/**
* Callback function that is called when the page is redirected back from the social login provider and receives the verification result.
*/
private onLoginComplete?;
private shouldCloseModalOnForgotPin;
/**
* Callback function that is called when the user clicks the forgot pin button.
*/
private onForgotPin?;
private receivedResponseFromService;
/**
* Promise that is resolved when the device ID is received.
*/
private resolveDeviceIdPromise?;
/**
* Promise that is rejected when the device ID is not received.
*/
private rejectDeviceIdPromise?;
/**
* Callback function that is called when the user clicks the resend OTP email button.
*/
private onResendOtpEmail?;
constructor(configs?: Configs, onLoginComplete?: LoginCompleteCallback);
/**
* Sets the application settings.
* This method will be deprecated in the future. Please use the constructor to set the application settings.
* @param appSettings - Application settings.
*/
setAppSettings(appSettings: AppSettings): void;
/**
* Sets the authentication information.
* @param auth - Authentication information.
*/
setAuthentication(auth: Authentication): void;
/**
* Updates the configurations.
* @param configs - Configurations.
* @param onLoginComplete - Callback function that is called when the page is redirected back from the social login provider and receives the verification result.
*/
updateConfigs(configs?: Configs, onLoginComplete?: LoginCompleteCallback): void;
/**
* Gets the device ID.
* @returns Promise<string> - Device ID.
*/
getDeviceId(): Promise<string>;
/**
* Performs social login.
* @param provider - Social login provider.
*/
performLogin(provider: SocialLoginProvider): Promise<void>;
/**
* Executes email OTP verification.
*/
verifyOtp(): void;
/**
* Executes the challenge.
* @param challengeId - Challenge ID.
* @param onCompleted - Callback function that is called when the challenge is completed.
*/
execute(challengeId: string, onCompleted?: ChallengeCompleteCallback): void;
/**
* Sets the custom security questions. If the user doesn't provide the custom security questions, the default security questions will be used.
* @param questions - Custom security questions.
* @param requiredCount - Required number of security questions.
* @param securityConfirmItems - Security confirm disclaimer items.
*/
setCustomSecurityQuestions(questions?: SecurityQuestion[] | null, requiredCount?: number, securityConfirmItems?: string[]): void;
/**
* Sets the localizations.
* @param localizations - Localizations.
*/
setLocalizations(localizations: Localizations): void;
/**
* Sets the resources.
* @param resources - Resources.
*/
setResources(resources: Resources): void;
/**
* Sets the theme color.
* @param themeColor - Theme color.
*/
setThemeColor(themeColor: ThemeColor): void;
/**
* Sets the custom links.
* @param customLinks - Custom links.
*/
setCustomLinks(customLinks: CustomLinks): void;
/**
* Sets the callback function that is called when the user clicks the forgot pin button.
* @param onForgotPin - Callback function that is called when the user clicks the forgot pin button.
* @param shouldCloseModalOnForgotPin - Indicates whether the modal should be closed when the user clicks the forgot pin button. Default is false.
*/
setOnForgotPin(onForgotPin: () => void, shouldCloseModalOnForgotPin?: boolean): void;
/**
* Sets the callback function that is called when the user clicks the resend OTP email button.
* @param onResendOtpEmail - Callback function that is called when the user clicks the resend OTP email button.
*/
setOnResendOtpEmail(onResendOtpEmail: () => void): void;
/**
* Sets up the instance.
* @param configs - Configurations.
* @param onLoginComplete - Callback function that is called when the page is redirected back from the social login provider and receives the verification result.
*/
private setupInstance;
/**
* Sets the challenge.
* @param challenge - Challenge.
*/
private setChallenge;
/**
* Appends the iframe to the document body.
* @param showIframe - Indicates whether the iframe should be shown. Default is true.
* @param subRoute - Sub route.
*/
private appendIframe;
/**
* Executes the challenge.
* @param onCompleted - Callback function that is called when the challenge is completed.
* @param showIframe - Indicates whether the iframe should be shown. Default is true.
*/
private exec;
private performAppleLogin;
private performFacebookLogin;
private performGoogleLogin;
/**
* Generates the OAuth URL with the necessary parameters.
* @param provider - Social login provider.
* @param id - Client ID or Application ID.
* @param redirectUri - Redirect URI.
* @param selectAccountPrompt - Indicates whether the user should select the account. Default is false.
* @returns OAuth URL with the necessary parameters.
*/
private generateOauthUrlWithParams;
/**
* Executes the social login status check before sending the token to the verification service.
*/
private execSocialLoginStatusCheck;
/**
* Handles the Apple login response.
* @returns Promise<void>.
*/
private handleAppleLoginResponse;
/**
* Handles the hash login responses.
* @param socialLoginProvider - Social login provider.
*/
private handleHashLoginResponse;
private handleGoogleLogin;
private handleFacebookLogin;
private isLoginStateValid;
private isLoginNonceValid;
private isValidHash;
private extractTokenFromResultAndSave;
private handleFirebaseFailure;
private handleLoginFailure;
private verifyTokenViaService;
/**
* Saves the OAuth information to the local storage in order to check the state and nonce value later.
* @param provider - Social login provider.
* @param state - State value.
* @param nonce - Nonce value.
*/
private saveOAuthInfo;
/**
* Checks the state value from the social login response.
* @param hashParams - Hash parameters.
* @returns Indicates whether the state value is valid.
*/
private checkSocialLoginState;
/**
* Checks the nonce value from the social login response. Only id token is going to have nonce value.
* @param hashParams - Hash parameters.
* @returns Indicates whether the nonce value is valid.
*/
private checkSocialLoginNonce;
/**
* Handles the postMessage event.
* @param event - PostMessageEvent.
*/
readonly messageHandler: (event: PostMessageEvent) => void;
/**
* Closes the modal.
*/
private closeModal;
/**
* Subscribes to the postMessage event.
*/
private subscribeMessage;
/**
* Unsubscribes to the postMessage event.
*/
private unSubscribeMessage;
}