From 6bf57766feb8321f860baf300140563cd9539053 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 14 Dec 2025 20:36:24 -0800 Subject: Init --- src/integrations/hcaptcha.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/integrations/hcaptcha.ts (limited to 'src/integrations/hcaptcha.ts') diff --git a/src/integrations/hcaptcha.ts b/src/integrations/hcaptcha.ts new file mode 100644 index 0000000..78ff356 --- /dev/null +++ b/src/integrations/hcaptcha.ts @@ -0,0 +1,32 @@ +import { Either, type IEither } from '@emprespresso/pengueno'; + +export interface HCaptchaResponse { + success: boolean; + challenge_ts?: string; + hostname?: string; + 'error-codes'?: string[]; +} + +export async function verifyHCaptcha(token: string, secret: string): Promise> { + try { + const response = await fetch('https://hcaptcha.com/siteverify', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + secret, + response: token, + }), + }); + + if (!response.ok) { + return Either.left(new Error(`hCaptcha verification failed: ${response.statusText}`)); + } + + const result = (await response.json()) as HCaptchaResponse; + return Either.right(result.success); + } catch (err) { + return Either.left(err instanceof Error ? err : new Error(String(err))); + } +} -- cgit v1.2.3-70-g09d2