-
Notifications
You must be signed in to change notification settings - Fork 0
feat: transform ChittyProof to dual-export library + service #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f081c41
5aab849
ba746bc
e2f65d9
f7e63e3
964906e
36ea9ee
5f858dc
4c31a13
9f996d9
2c8e2e9
ce6d9fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Run tests | ||
| run: npm test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # CLAUDE.md — ChittyProof | ||
|
|
||
| Cryptographic integrity library for FACT v2 bundle canonicalization, hashing, and ECDSA P-256 signature verification. | ||
| Cryptographic integrity library and service for FACT v2 bundle canonicalization, hashing, and ECDSA P-256 signature verification. | ||
|
|
||
| **Canonical URI**: `chittycanon://core/services/chittyproof` | ||
| **Tier**: 0 (Trust Anchors) | ||
|
|
@@ -10,16 +10,29 @@ Cryptographic integrity library for FACT v2 bundle canonicalization, hashing, an | |
|
|
||
| ```bash | ||
| npm test # Run vitest (all tests) | ||
| npx vitest run # Same, explicit | ||
| npm run dev # Start local dev server (wrangler dev) | ||
| npm run deploy # Deploy to Cloudflare Workers | ||
| npx vitest run # Same as npm test, explicit | ||
| npx vitest watch # Watch mode | ||
| ``` | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| src/lib/ | ||
| chittyproof-v2-canonical.js # Canonicalization, normalization, SHA-256 hashing | ||
| chittyproof-verify-ecdsa.js # ECDSA P-256 verification, JWKS key resolution | ||
| src/ | ||
| index.js # SDK barrel export (library consumers) | ||
| worker.js # Hono Worker entry point (HTTP consumers) | ||
| lib/ | ||
| chittyproof-v2-canonical.js # Canonicalization, normalization, SHA-256 hashing | ||
| chittyproof-verify-ecdsa.js # ECDSA P-256 verification, JWKS key resolution | ||
| routes/ | ||
| health.js # GET /health, GET /api/v1/status | ||
| verify.js # POST /api/v1/verify | ||
| canonicalize.js # POST /api/v1/canonicalize | ||
| hash.js # POST /api/v1/hash | ||
| validate.js # POST /api/v1/validate | ||
| middleware/ | ||
| auth.js # Shared-secret Bearer token | ||
|
|
||
| etc/authority/schema/ | ||
| chittyproof-v2-fact-bundle.schema.json # FACT v2 bundle JSON Schema | ||
|
|
@@ -28,11 +41,20 @@ tests/ | |
| helpers/fact-proof-bundle.js # Test fixture factory (makeFactProofBundle) | ||
| lib/chittyproof-v2-canonical.test.js # Canonicalization + hash tests | ||
| lib/chittyproof-verify-ecdsa.test.js # ECDSA verification tests | ||
| middleware/auth.test.js # Auth middleware tests | ||
| routes/ # Route handler tests | ||
| worker.test.js # Integration tests | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| This is a **library**, not a deployable service. It exports pure functions that run on any Web Crypto API runtime (Workers, Node 20+, Deno, browsers). | ||
| This is a **dual-export** project: a library (for in-process consumers) and a deployed service at `proof.chitty.cc` (for HTTP consumers). | ||
|
|
||
| - `src/index.js` — SDK barrel export (library consumers import from here) | ||
| - `src/worker.js` — Hono Worker entry point (Cloudflare Workers deployment) | ||
| - `src/lib/` — Pure function core (unchanged from library-only days) | ||
| - `src/routes/` — HTTP route handlers wrapping the library functions | ||
| - `src/middleware/` — Auth middleware (shared-secret Bearer token) | ||
|
|
||
| ### Canonicalization Pipeline | ||
| 1. `normalizeBundle` — round score/pillar fields to deterministic precision, compute `score_100` | ||
|
|
@@ -48,7 +70,9 @@ This is a **library**, not a deployable service. It exports pure functions that | |
| 4. `crypto.subtle.verify` ECDSA P-256 over the hash bytes | ||
|
|
||
| ### Key Dependencies | ||
| - **Hono** — HTTP framework for Cloudflare Workers | ||
| - **ChittyCert** (`cert.chitty.cc/.well-known/jwks.json`) — public key authority | ||
| - **ChittyAuth** — shared-secret Bearer token (`CHITTY_AUTH_SERVICE_TOKEN`) | ||
| - **KV binding** (`PROOF_KEY_CACHE`) — optional JWKS cache for Workers consumers | ||
|
|
||
| ## Patterns | ||
|
|
@@ -58,3 +82,5 @@ This is a **library**, not a deployable service. It exports pure functions that | |
| - Non-finite numbers throw — no `NaN` or `Infinity` in canonical payloads | ||
| - Base64url encoding/decoding handles padding normalization internally | ||
| - `structuredClone` is used for immutable normalization (no mutation of input bundles) | ||
| - Routes are thin wrappers around library functions — no business logic in route handlers | ||
| - Auth middleware uses simple string comparison against `env.CHITTY_AUTH_SERVICE_TOKEN` | ||
|
Comment on lines
+85
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# First, check if the file exists
if [ -f "src/middleware/auth.js" ]; then
echo "=== Inspecting auth middleware implementation ==="
cat -n src/middleware/auth.js
else
echo "File src/middleware/auth.js not found. Searching for auth-related files..."
fd auth . -type f 2>/dev/null | head -20
fiRepository: chittyapps/chittyproof Length of output: 932 🏁 Script executed: #!/bin/bash
# Search for token comparison patterns
echo "=== Searching for token comparison patterns ==="
rg -n 'CHITTY_AUTH_SERVICE_TOKEN|token.*===|Bearer|crypto' --type-list | head -5
rg -n 'CHITTY_AUTH_SERVICE_TOKEN|token.*===|Bearer' -i 2>/dev/null || echo "No matches found"Repository: chittyapps/chittyproof Length of output: 9552 🏁 Script executed: #!/bin/bash
# Check CLAUDE.md to confirm documentation
echo "=== Checking CLAUDE.md lines 85-86 ==="
sed -n '80,90p' CLAUDE.mdRepository: chittyapps/chittyproof Length of output: 677 Use constant-time comparison for bearer-token validation. The middleware at line 19 of if (!token || !crypto.timingSafeEqual(Buffer.from(token), Buffer.from(expected))) {
return c.json({ error: "unauthorized" }, 401);
}🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix markdownlint MD058 around tables.
Line 48 and Line 75 start tables without required surrounding blank lines, which will keep lint noisy.
Suggested markdown fix
Also applies to: 74-81
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)
[warning] 48-48: Tables should be surrounded by blank lines
(MD058, blanks-around-tables)
🤖 Prompt for AI Agents