@humanmark/sdk-js
Version:
Browser-native JavaScript SDK for Humanmark human verification challenges
70 lines • 2.28 kB
TypeScript
/**
* Utility functions for working with challenge tokens (Protobuf format)
*/
/**
* Claims contained in the challenge token
*/
export interface ChallengeTokenClaims {
shard: string;
challenge: string;
exp: number;
iat?: number;
domain?: string;
}
/**
* Parsed challenge token data
*/
export interface ParsedChallengeToken {
token: string;
claims: ChallengeTokenClaims;
}
/**
* Parses a Protobuf challenge token without verification (client-side decode only)
* Note: This does NOT verify the signature - it only extracts the claims
*
* @param token - Challenge token string (format: {base64url_protobuf}.{signature})
* @returns Parsed token with claims
* @throws {HumanmarkChallengeError} If the token is invalid
*/
export declare function parseChallengeToken(token: string): ParsedChallengeToken;
/**
* Extracts the shard (region) from a challenge token
*
* @param token - Challenge token
* @returns The shard (region) from the token claims
* @throws {HumanmarkChallengeError} If the token is invalid
*/
export declare function parseShardFromToken(token: string): string;
/**
* Extracts the challenge ID from a challenge token
*
* @param token - Challenge token
* @returns The challenge ID from the token claims
* @throws {HumanmarkChallengeError} If the token is invalid
*/
export declare function parseChallengeFromToken(token: string): string;
/**
* Gets the expiration time from a challenge token
*
* @param token - Challenge token
* @returns Expiration timestamp in milliseconds
* @throws {HumanmarkChallengeError} If the token is invalid
*/
export declare function getTokenExpiration(token: string): number;
/**
* Checks if a challenge token is expired
*
* @param token - Challenge token
* @returns true if the token is expired
* @throws {HumanmarkChallengeError} If the token is invalid
*/
export declare function isTokenExpired(token: string): boolean;
/**
* Constructs a shard-specific API URL
*
* @param baseUrl - Base URL (e.g., https://humanmark.io)
* @param shard - Shard identifier (e.g., us-east-1)
* @returns Shard URL (e.g., https://us-east-1.humanmark.io)
*/
export declare function constructShardUrl(baseUrl: string, shard: string): string;
//# sourceMappingURL=challengeToken.d.ts.map