mirror of
https://github.com/paoloanzn/free-code.git
synced 2026-10-19 01:30:18 -05:00
feat: add cch hash computation module using xxHash64
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
38c09970c2
commit
f97ed1c0ec
1 file changed
+28
@@ -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<typeof xxhash> | null = null
|
||||
|
||||
function getHasher() {
|
||||
if (!hasherPromise) {
|
||||
hasherPromise = xxhash()
|
||||
}
|
||||
return hasherPromise
|
||||
}
|
||||
|
||||
export async function computeCch(body: string): Promise<string> {
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user