Email OTP

EmailOTPClient

An EmailOTPClient represents a logged in user. It is generated from the functions restoreSession() and login(). The EmailOTPClient expires 8 hours after the initial OTP was sent, and a new EmailOTPClient would need to be generated when it expires.

EmailOTPClientParams

To call functions that would initialize a Halliday EmailOTPClient, namely restoreSession(), sendOTP(), and login(), the user must pass a set of parameters EmailOTPClientParams.

The EmailOTPClientParams contains the fields hallidayPublicApiKey, blockchainType, sandbox, and inGamePlayerId that specifies the user to be logged in.

interface EmailOTPClientParams {
    hallidayPublicApiKey: string;
    blockchainType: BlockchainType;
    sandbox: boolean;
    inGamePlayerId: string;
}

Login with Email OTP

Logging in with Email OTP consists of two steps. The user calls sendOTP(email) to send the OTP to the user's email. Then, the user calls login(OTP) with the OTP to log the user in. Both of these functions also take an argument in the form of EmailOTPClientParams to specify the user that is logged in.

sendOTP

/**
     *
     * Call this function to send an email OTP to the user. This function will takes in
     * the user's email and id, which will be used to send an email OTP to the user.
     * Only the OTP from the most recently sent email can be used to register.
     *
     * @param {EmailOTPClientParams} params Parameters for the Halliday client
     * @param {string} email The user's email where the OTP would be sent to
     *
     * @returns {Promise<boolean>} Returns true if successful, throws error if not
     */
async sendOTP(params, email): Promise<boolean>

Inputs

NameDescriptionType
paramsParameters to specify the user to send OTP toEmailOTPClientParams
emailUser email to send OTP for confirmationstring

Output

NameDescriptionType
SuccessReturns a promise that resolves to true is OTP is sent, throws error if notboolean

login

/**
     *
     * Call this function to login a user. After receiving their email OTP, the user
     * should be able to enter their OTP into a form. This function should then be
     * called with the OTP.
     *
     * If the user is trying to register, the OTP must match the OTP sent from the most
     * recently sent email from the sendOTP function. If the OTP matches, the user is
     * registered and the signer is initialized.
     *
     * Returns true if successful, throws error if not
     *
     * @param {EmailOTPClientParams} params Parameters for the Halliday client
     * @param {string} OTP The OTP entered by the user
     *
     * @returns {Promise<EmailOTPClient>} The Halliday client if successful, throws error if not
     */
async login(params: EmailOTPClientParams, OTP: string): Promise<EmailOTPClient>

Inputs

NameDescriptionType
paramsParameters to specify the user to send OTP toEmailOTPClientParams
OTPOTP received in the user's emailstring

Output

NameDescriptionType
EmailOTPClientReturns a Promise that resolves to an EmailOTPClient if OTP is correct and user is logged in, throws error if notEmailOTPClient

Restore Session

The EmailOTPClient can be lost upon page refresh. To restore the login status on a user on the same tab that has not been logged out, the user calls restoreSession(params) with their account.

/**
 * Restores the login status of a previous logged in EmailOTPClient on the same tab.
 * The client should not have been logged out.
 *
 * @param {EmailOTPClientParams} params Parameters for the Halliday client
 *
 * @returns {Promise<EmailOTPClient | null>} The restored Halliday client, or null if the restoration failed
 */
async restoreSession(params: EmailOTPClientParams): Promise<EmailOTPClient | null>

Inputs

NameDescriptionType
paramsParameters to specify the user to restore. It must match the previously logged in userEmailOTPClientParams

Output

NameDescriptionType
EmailOTPClientReturns a Promise that resolves to an EmailOTPClient if the login session has been successfully restored; returns null if notEmailOTPClient | nul

EmailOTPClient Methods

An EmailOTPClient represents a logged in user. The user can get the signer, InGamePlayerId, and email from the client with the methods getSigner(), getInGamePlayerId(), and getEmail. If the client has been expired or corrupted, the client will log out and the method will return an error. At that point, a new EmailOTPClient must be generated with sendOTP() and login().

/**
 * Gets the signer of the Halliday client. If the client is expired or corrupted, the client will log out and throw
 * an error.
 *
 * @returns {Promise<EmailSigner>} The signer of the Halliday client
 */
async getSigner(): Promise<EmailSigner> 

/**
 * Gets the inGamePlayerId of the Halliday client. If the client is expired or corrupted, the client will log out
 * and throw an error.
 *
 * @returns {Promise<string>} The inGamePlayerId of the Halliday client
 */
async getInGamePlayerId(): Promise<string> 

/**
 * Gets the email of the Halliday client. If the client is expired or corrupted, the client will log out and throw
 * an error.
 *
 * @returns {Promise<string>} The inGamePlayerId of the Halliday client
 */
async getEmail(): Promise<string> 

Logout

logOut should be called on the EmailOTPClient when they are no longer using their wallet or when they log out of their game account for security. To login again, the user will need to restart the process by calling sendOTP.

/**
* Logs the user out. To login again, the user will need to call sendOTP again.
*/
async EmailOTPClient.logOut()

Email Signer

The email signer is an abstraction of the EVM account created for the user when they registered using Email OTP. The user can get their signer by calling getSigner() on their EmailOTPClient.

EmailSigner.address

Returns a string that is the address of the EVM account

EmailSigner.signMessage(message)

Returns the signature of the EVM account on the message.

/**
 * This function will sign off on a message using the user's EmailSigner
 *
 * @param message Any string
 * @returns
 */
async signMessage(message: Uint8Array | string): Promise<string> 

Inputs

NameDescriptionType
messageMessage to be signed by the emailSignerUint8Array | string

Output

NameDescriptionType
SignatureReturns a promise that resolves to a string that is the signature of the message.string