Hawcx Web SDK API Reference
Core Methods
initialize(apiKey, baseUrl?, options?)
Initialize the Hawcx SDK. Must be called before any other methods.
Parameters:
apiKey(string, required) - Your Hawcx API keybaseUrl(string, optional) - Base URL for Hawcx API (default:https://api-beta.hawcx.com)options(object, optional)cryptoVersion(string) - Crypto version, default:'v1'timeoutMs(number) - Request timeout in milliseconds, default:15000
Promise<Object>
Authentication
authenticate(userid, options?)
Start authentication for a user. Returns different statuses based on device registration and MFA setup.
Parameters:
userid(string) - User email addressoptions(object, optional)rememberDevice(boolean) - Remember device for future loginscode_challenge(string) - PKCE code challenge (if using PKCE)code_challenge_method(string) - PKCE method (e.g., ‘S256’)
Promise<Object> with possible statuses:
Status: SUCCESS (Trusted device, no verification needed)
Registration Flow
verifyEmailOtp({ userid, otp })
Verify email OTP during device registration.
Parameters:
userid(string) - User email addressotp(string) - 6-digit OTP from email
Promise<Object>
verifyDevice({ userid, mfaMethod })
Finalize device registration and set up MFA method.
Parameters:
userid(string) - User email addressmfaMethod(string) - MFA method to enable:'email','sms', or'totp'(optional - skip MFA if not provided)
Promise<Object> with status SUCCESS or DEVICE_REGISTERED
MFA Flow
initiateMfa({ userid, sessionId })
Start MFA verification for users with MFA enabled.
Parameters:
userid(string) - User email addresssessionId(string) - Session ID fromauthenticate()response
Promise<Object>
verifyMfa({ userid, otp, remember_me? })
Verify MFA code and complete authentication.
Parameters:
userid(string) - User email addressotp(string) - 6-digit OTP from MFA methodremember_me(boolean, optional) - Remember this device for future logins
Promise<Object>
- Node.js
- Python
All Response Status Codes
authenticate() Statuses
| Status | Meaning | Next Action |
|---|---|---|
SUCCESS | User authenticated on trusted device | Send code to backend |
OTP_NEEDED | New device - email OTP verification required | Call verifyEmailOtp() with OTP |
MFA_REQUIRED | Device registered with MFA enabled | Call initiateMfa() then verifyMfa() |
INVALID_EMAIL | Invalid email format | Show error, retry with valid email |
verifyEmailOtp() Statuses
| Status | Meaning | Next Action |
|---|---|---|
SUCCESS | Email OTP verified successfully | Call verifyDevice() to finalize registration |
verifyDevice() Statuses
| Status | Meaning | Next Action |
|---|---|---|
SUCCESS | Device registered successfully | Send code to backend |
DEVICE_REGISTERED | Device registered, re-authenticate | Call authenticate() again |
MFA_ENROLLMENT_NEEDED | Email verified, offer MFA setup | Call verifyDevice() with mfaMethod |
FINALIZE_REGISTRATION_NEEDED | Device registration finalizing | Continue device registration flow |
initiateMfa() Statuses
| Status | Meaning | Next Action |
|---|---|---|
MFA_INITIATED | MFA challenge initiated | Call verifyMfa() with OTP |
verifyMfa() Statuses
| Status | Meaning | Next Action |
|---|---|---|
SUCCESS | MFA verified successfully | Send code to backend |
Complete Registration Flow Example
Complete Login Flow with MFA
Best Practices
- Always validate on backend - Never trust the authorization code on frontend
- Handle all response statuses - Different status codes require different UX flows
- Store authorization code safely - Send immediately to backend, don’t store in localStorage
- Use HTTPS only - Authentication must occur over HTTPS
- Implement PKCE - For enhanced security, especially with mobile and SPAs
- Add proper error handling - Display user-friendly error messages for failures
