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
});
| Param | Type | Required | Description |
|---|---|---|---|
| apiKey | string | Yes | Your WordAuth API key |
| baseUrl | string | No | Override the base URL (default: https://api.wordauth.com) |
wordauth.generate(params?)
Generate a new word pair.
Parameters
| Param | Type | Required | Description |
|---|---|---|---|
| session_id | string | No | Associate the OTP with a caller session |
| ttl_seconds | number | No | Override OTP expiry in seconds (default: 300) |
| string | No | Send the OTP to this email address | |
| phone | string | No | Send 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
| Param | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | The word pair entered by the user |
| otp_id | string | No | The otp_id returned from generate() |
| session_id | string | No | Alternative to otp_id for session-based validation |
Returns Promise<ValidateResponse>
interface ValidateResponse {
valid: boolean;
message?: string | null; // set when valid is false
}