From f97ed1c0ec6d25d58fb6445b2f3a2b46c1a162f4 Mon Sep 17 00:00:00 2001 From: paoloanzn Date: Wed, 1 Apr 2026 15:25:54 +0200 Subject: [PATCH] feat: add cch hash computation module using xxHash64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements the cch request signing algorithm described in the reverse-engineering article. Uses xxhash-wasm for xxHash64 computation with the known seed constant. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/utils/cch.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/utils/cch.ts diff --git a/src/utils/cch.ts b/src/utils/cch.ts new file mode 100644 index 0000000..d36647f --- /dev/null +++ b/src/utils/cch.ts @@ -0,0 +1,28 @@ +import xxhash from 'xxhash-wasm' + +const CCH_SEED = 0x6E52736AC806831En +const CCH_PLACEHOLDER = 'cch=00000' +const CCH_MASK = 0xFFFFFn + +let hasherPromise: ReturnType | null = null + +function getHasher() { + if (!hasherPromise) { + hasherPromise = xxhash() + } + return hasherPromise +} + +export async function computeCch(body: string): Promise { + const hasher = await getHasher() + const hash = hasher.h64Raw(new TextEncoder().encode(body), CCH_SEED) + return (hash & CCH_MASK).toString(16).padStart(5, '0') +} + +export function replaceCchPlaceholder(body: string, cch: string): string { + return body.replace(CCH_PLACEHOLDER, `cch=${cch}`) +} + +export function hasCchPlaceholder(body: string): boolean { + return body.includes(CCH_PLACEHOLDER) +}