TypeScript SDK

Official npm package for Node.js 18+ and modern browsers.

Install

npm install wordauth

new WordAuth(apiKey | options)

Pass a key string directly, or an options object.

// String shorthand const wordauth = new WordAuth("sk_live_..."); // Options object const wordauth = new WordAuth({ apiKey: "sk_live_...", baseUrl: "https://custom-api.example.com", // optional });
ParamTypeRequiredDescription
apiKeystringYesYour WordAuth API key
baseUrlstringNoOverride the base URL (default: https://api.wordauth.com)

wordauth.generate(params?)

Generate a new word pair.

Parameters

ParamTypeRequiredDescription
session_idstringNoAssociate the OTP with a caller session
ttl_secondsnumberNoOverride OTP expiry in seconds (default: 300)
emailstringNoSend the OTP to this email address
phonestringNoSend the OTP to this phone number via SMS

Returns Promise<GenerateResponse>

interface GenerateResponse { otp_id: string; code: string; // e.g. "happening holiday" session_id: string | null; expires_at: string; // ISO 8601 }

wordauth.generateWithEmail(email, params?)

Generate a word pair and deliver it by email. Accepts the same optional params as generate(), excluding email.

const { otp_id } = await wordauth.generateWithEmail("[email protected]");

wordauth.generateWithSMS(phone, params?)

Generate a word pair and deliver it via SMS. Accepts the same optional params as generate(), excluding phone.

const { otp_id } = await wordauth.generateWithSMS("+15550001234");

wordauth.validate(params)

Validate a word pair against an OTP session.

Parameters

ParamTypeRequiredDescription
codestringYesThe word pair entered by the user
otp_idstringNoThe otp_id returned from generate()
session_idstringNoAlternative to otp_id for session-based validation

Returns Promise<ValidateResponse>

interface ValidateResponse { valid: boolean; message?: string | null; // set when valid is false }