@eduarte/chc
v0.2.4
Published
Browser-side decryption package for `/api/ccus/history` protected payloads.
Readme
CCU History Crypto (Go WASM)
Browser-side decryption package for /api/ccus/history protected payloads.
Build
cd wasm/ccu-history-crypto
./scripts/build.sh "your-arbitrary-key-string" "citizenshub.app,localhost"- 1st arg: key material (arbitrary string /
hex:/base64:) - 2nd arg (optional): allowed hostnames for origin check, comma-separated (default:
citizenshub.app) - Env override:
CCU_HISTORY_ALLOWED_HOSTS(legacyCCU_HISTORY_ALLOWED_HOSTis still supported)
The build script will:
- derive a 16-byte key with
SHA-256(same rule as backend) - compile
src/main.gotopkg/chc.wasm - copy Go runtime loader to
pkg/wasm_exec.js
Usage
import { decryptCcuHistoryPayload } from '@eduarte/chc';
import wasmUrl from '@eduarte/chc/chc.wasm?url';
import wasmExecUrl from '@eduarte/chc/wasm_exec.js?url';
const encrypted = await fetch('https://api.citizenshub.app/api/ccus/history').then((r) => r.json());
const history = await decryptCcuHistoryPayload(encrypted, {
wasmUrl,
wasmExecUrl
});Vite note:
- If you see
/.vite/deps/wasm_exec.js 404, you are likely relying on internal default paths. - Always pass explicit
wasmUrlandwasmExecUrlas shown above. - Optional hardening in
vite.config.ts:
export default defineConfig({
optimizeDeps: {
exclude: ['@eduarte/chc']
}
})Behavior
- Uses Go
syscall/jsruntime. - Origin check is performed in Go WASM by matching
window.location.hostnameagainst the build-timeallowedHostlist. - Supports deterministic payloads (no random salt/nonce rotation), so encrypted response can be cached.
- Supports optional
gzipdecompression when payload hascompression: "gzip".
