UNPKG

genuine-browser

Version:

A package to detect browser requests using cryptographic challenge-response mechanism.

41 lines (39 loc) 1.97 kB
declare function generateKeyPair(): Promise<CryptoKeyPair>; declare function storePrivateKey(key: CryptoKey): Promise<void>; declare function exportPublicKey(key: CryptoKey): Promise<string>; /** * Initializes the browser detection by generating a key pair (if not already generated) * and registering the public key with the backend. * * @returns {Promise<void>} A promise that resolves when the browser detection setup is completed. */ declare function setupBrowserDetection(): Promise<void>; declare function fetchChallenge(): Promise<string>; declare function signChallenge(challenge: string): Promise<string>; /** * Checks if the current browser request is valid by performing a challenge-response * verification. * * @returns {Promise<boolean>} A promise that resolves to `true` if the browser request is valid, `false` otherwise. */ declare function isBrowserRequestValid(): Promise<boolean>; /** * Retrieves the keys from the backend for validation purposes. * * @returns {Promise<{token:string, challenge: string, signature: string}>} A promise that resolves to an object containing the token, challenge and signature. */ declare function retrieveKeysForValidation(): Promise<{ token: string; challenge: string; signature: string; }>; /** * Validates the browser by using the provided challenge and signature. * * @param {string} token - The token used for authentication. * @param {string} challenge - The challenge retrieved from the backend. * @param {string} signature - The signature of the challenge using the private key. * @returns {Promise<boolean>} A promise that resolves to `true` if the browser is valid, `false` otherwise. */ declare function validateBrowser(token: string, challenge: string, signature: string): Promise<boolean>; export { exportPublicKey, fetchChallenge, generateKeyPair, isBrowserRequestValid, retrieveKeysForValidation, setupBrowserDetection, signChallenge, storePrivateKey, validateBrowser };