Skip to content

Commit db21a23

Browse files
authored
Merge pull request #2 from chittyapps/feature/service-transform
feat: transform ChittyProof to dual-export library + service
2 parents d40ae46 + 7b75582 commit db21a23

22 files changed

Lines changed: 1827 additions & 66 deletions

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run tests
26+
run: npm test

CHARTER.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ category: infrastructure
2222
- **Tier**: 0 (Trust Anchors)
2323
- **Organization**: CHITTYOS
2424
- **Domain**: proof.chitty.cc
25-
- **Artifact Type**: Library (consumed by services, not deployed standalone)
25+
- **Artifact Type**: Library + Service (dual-export at proof.chitty.cc)
2626

2727
## Mission
2828

@@ -38,6 +38,7 @@ Provide deterministic, court-grade cryptographic integrity primitives for the Ch
3838
- JWKS key resolution with KV caching (kid-based lookup via ChittyCert)
3939
- Defining the authoritative FACT v2 bundle JSON Schema
4040
- Providing `normalizeBundle` / `canonicalSignedPayload` / `verifyBundle` / `verifyECDSA` exports
41+
- Serving HTTP verification endpoints at `proof.chitty.cc` for ecosystem consumers
4142

4243
### IS NOT Responsible For
4344
- Signing bundles (signing authority lives in the minting service)
@@ -52,12 +53,16 @@ Provide deterministic, court-grade cryptographic integrity primitives for the Ch
5253
| Type | Service | Purpose |
5354
|------|---------|---------|
5455
| Upstream | ChittyCert | JWKS endpoint for public key resolution |
56+
| Upstream | ChittyAuth | Shared-secret Bearer token validation |
5557
| Runtime | Web Crypto API | SHA-256 digest, ECDSA verify, key import |
58+
| Runtime | Hono | HTTP framework for Cloudflare Workers |
5659
| Optional | Cloudflare KV | JWKS key caching (`PROOF_KEY_CACHE` binding) |
60+
| Downstream | ChittyTrack | Automatic log/trace aggregation (tail_consumers) |
61+
| Downstream | ChittyBeacon | Health monitoring (probes /health) |
5762

5863
## API Contract
5964

60-
ChittyProof is a library — it exports functions, not HTTP endpoints.
65+
ChittyProof is both a library (SDK exports) and a deployed service (HTTP endpoints at proof.chitty.cc).
6166

6267
### Exports (`lib/chittyproof-v2-canonical.js`)
6368
| Export | Signature | Purpose |
@@ -80,6 +85,16 @@ ChittyProof is a library — it exports functions, not HTTP endpoints.
8085
| `getPublicKeyByKid` | `(kid, env, opts?) => Promise<CryptoKey>` | KV-cached JWKS key resolution |
8186
| `verifyECDSA` | `(bundle, env, opts?) => Promise<{ok, reason, ...}>` | Full ECDSA signature verification |
8287

88+
### HTTP Endpoints (proof.chitty.cc)
89+
| Method | Path | Auth | Purpose |
90+
|--------|------|------|---------|
91+
| GET | `/health` | None | Health probe |
92+
| GET | `/api/v1/status` | None | Service metadata |
93+
| POST | `/api/v1/verify` | Bearer | Hash integrity + ECDSA verification |
94+
| POST | `/api/v1/canonicalize` | Bearer | Deterministic JSON canonicalization |
95+
| POST | `/api/v1/hash` | Bearer | SHA-256 of canonical signed payload |
96+
| POST | `/api/v1/validate` | Bearer | FACT v2 bundle schema validation |
97+
8398
### Schema
8499
- `etc/authority/schema/chittyproof-v2-fact-bundle.schema.json`
85100
- `$id`: `chittycanon://schemas/chittyproof/v2/fact-bundle`
@@ -98,7 +113,7 @@ ChittyProof is a library — it exports functions, not HTTP endpoints.
98113
- [x] CHARTER.md present
99114
- [x] CHITTY.md present
100115
- [x] CLAUDE.md present
101-
- [x] Tests passing (10/10 vitest)
116+
- [x] Tests passing (32/32 vitest)
102117
- [x] JSON Schema with canonical $id
103118
- [x] Canonical frontmatter with tech domain
104119
- [x] Package exports map defined

CHITTY.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,38 @@ category: infrastructure
2121
2222
## What It Does
2323

24-
Cryptographic integrity library for FACT v2 bundles. Provides deterministic JSON canonicalization, SHA-256 hashing, and ECDSA P-256 signature verification — the foundation that makes every fact in the ChittyOS ecosystem provably tamper-evident.
24+
Cryptographic integrity library and service for FACT v2 bundles. Provides deterministic JSON canonicalization, SHA-256 hashing, and ECDSA P-256 signature verification — the foundation that makes every fact in the ChittyOS ecosystem provably tamper-evident. Available both as a library (SDK import) and as HTTP endpoints at `proof.chitty.cc`.
2525

2626
## Architecture
2727

28-
Pure JavaScript ESM library consumed by ChittyOS services. Runs anywhere the Web Crypto API is available (Cloudflare Workers, Node 20+, Deno, browsers).
28+
Dual-export: pure JavaScript ESM library (SDK consumers import directly) + Hono Worker deployed at `proof.chitty.cc` (HTTP consumers). Library core runs anywhere the Web Crypto API is available (Workers, Node 20+, Deno, browsers).
2929

3030
### Stack
3131
- **Language**: JavaScript (ESM)
32+
- **HTTP**: Hono on Cloudflare Workers
3233
- **Crypto**: Web Crypto API (SHA-256, ECDSA P-256)
34+
- **Auth**: Shared-secret Bearer token (`CHITTY_AUTH_SERVICE_TOKEN`)
3335
- **Testing**: Vitest
3436
- **Key Authority**: ChittyCert JWKS (`cert.chitty.cc/.well-known/jwks.json`)
3537

3638
### Key Components
39+
- `src/index.js` — SDK barrel export (library consumers)
40+
- `src/worker.js` — Hono Worker entry point (HTTP consumers)
3741
- `src/lib/chittyproof-v2-canonical.js` — Canonicalization, normalization, hashing
3842
- `src/lib/chittyproof-verify-ecdsa.js` — ECDSA P-256 verification, JWKS resolution
43+
- `src/routes/` — HTTP route handlers (health, verify, canonicalize, hash, validate)
44+
- `src/middleware/auth.js` — Shared-secret Bearer token middleware
3945
- `etc/authority/schema/chittyproof-v2-fact-bundle.schema.json` — FACT v2 bundle schema
40-
- `tests/helpers/fact-proof-bundle.js` — Test fixture factory
46+
47+
### Endpoints
48+
| Method | Path | Auth | Purpose |
49+
|--------|------|------|---------|
50+
| GET | `/health` | None | Health probe |
51+
| GET | `/api/v1/status` | None | Service metadata |
52+
| POST | `/api/v1/verify` | Bearer | Hash + ECDSA verification |
53+
| POST | `/api/v1/canonicalize` | Bearer | Deterministic JSON |
54+
| POST | `/api/v1/hash` | Bearer | SHA-256 of canonical payload |
55+
| POST | `/api/v1/validate` | Bearer | FACT v2 schema validation |
4156

4257
### Design Principles
4358
- **Deterministic**: Same input always produces the same canonical JSON and hash, across all runtimes
@@ -53,13 +68,16 @@ Pure JavaScript ESM library consumed by ChittyOS services. Runs anywhere the Web
5368
- **Last Certified**: 2026-03-01
5469

5570
### ChittyDNA
56-
- **Lineage**: root (foundational library)
57-
- **Role**: Integrity primitive — consumed by any service that mints, seals, or verifies FACT bundles
71+
- **Lineage**: root (foundational library + service)
72+
- **Role**: Integrity primitive — consumed by any service that mints, seals, or verifies FACT bundles (SDK import or HTTP call)
5873

5974
### Dependencies
6075
| Service | Purpose |
6176
|---------|---------|
6277
| ChittyCert | JWKS public key hosting for signature verification |
78+
| ChittyAuth | Shared-secret Bearer token validation |
79+
| ChittyTrack | Log/trace aggregation (tail_consumers) |
80+
| ChittyBeacon | Health monitoring (probes /health) |
6381

6482
### Consumers
6583
| Service | Usage |
@@ -68,6 +86,8 @@ Pure JavaScript ESM library consumed by ChittyOS services. Runs anywhere the Web
6886
| ChittyEvidence | Evidence integrity checks |
6987
| ChittyLedger | Seal verification at ledger write |
7088
| ChittyCases | Bundle verification for case presentation |
89+
| ChittySign | Canonical hash for signing counterpart |
90+
| DocuMint | Bundle verification (library or HTTP) |
7191

7292
### Exports
7393
| Module | Key Functions |

CLAUDE.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CLAUDE.md — ChittyProof
22

3-
Cryptographic integrity library for FACT v2 bundle canonicalization, hashing, and ECDSA P-256 signature verification.
3+
Cryptographic integrity library and service for FACT v2 bundle canonicalization, hashing, and ECDSA P-256 signature verification.
44

55
**Canonical URI**: `chittycanon://core/services/chittyproof`
66
**Tier**: 0 (Trust Anchors)
@@ -10,16 +10,29 @@ Cryptographic integrity library for FACT v2 bundle canonicalization, hashing, an
1010

1111
```bash
1212
npm test # Run vitest (all tests)
13-
npx vitest run # Same, explicit
13+
npm run dev # Start local dev server (wrangler dev)
14+
npm run deploy # Deploy to Cloudflare Workers
15+
npx vitest run # Same as npm test, explicit
1416
npx vitest watch # Watch mode
1517
```
1618

1719
## Project Structure
1820

1921
```
20-
src/lib/
21-
chittyproof-v2-canonical.js # Canonicalization, normalization, SHA-256 hashing
22-
chittyproof-verify-ecdsa.js # ECDSA P-256 verification, JWKS key resolution
22+
src/
23+
index.js # SDK barrel export (library consumers)
24+
worker.js # Hono Worker entry point (HTTP consumers)
25+
lib/
26+
chittyproof-v2-canonical.js # Canonicalization, normalization, SHA-256 hashing
27+
chittyproof-verify-ecdsa.js # ECDSA P-256 verification, JWKS key resolution
28+
routes/
29+
health.js # GET /health, GET /api/v1/status
30+
verify.js # POST /api/v1/verify
31+
canonicalize.js # POST /api/v1/canonicalize
32+
hash.js # POST /api/v1/hash
33+
validate.js # POST /api/v1/validate
34+
middleware/
35+
auth.js # Shared-secret Bearer token
2336
2437
etc/authority/schema/
2538
chittyproof-v2-fact-bundle.schema.json # FACT v2 bundle JSON Schema
@@ -28,11 +41,20 @@ tests/
2841
helpers/fact-proof-bundle.js # Test fixture factory (makeFactProofBundle)
2942
lib/chittyproof-v2-canonical.test.js # Canonicalization + hash tests
3043
lib/chittyproof-verify-ecdsa.test.js # ECDSA verification tests
44+
middleware/auth.test.js # Auth middleware tests
45+
routes/ # Route handler tests
46+
worker.test.js # Integration tests
3147
```
3248

3349
## Architecture
3450

35-
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).
51+
This is a **dual-export** project: a library (for in-process consumers) and a deployed service at `proof.chitty.cc` (for HTTP consumers).
52+
53+
- `src/index.js` — SDK barrel export (library consumers import from here)
54+
- `src/worker.js` — Hono Worker entry point (Cloudflare Workers deployment)
55+
- `src/lib/` — Pure function core (unchanged from library-only days)
56+
- `src/routes/` — HTTP route handlers wrapping the library functions
57+
- `src/middleware/` — Auth middleware (shared-secret Bearer token)
3658

3759
### Canonicalization Pipeline
3860
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
4870
4. `crypto.subtle.verify` ECDSA P-256 over the hash bytes
4971

5072
### Key Dependencies
73+
- **Hono** — HTTP framework for Cloudflare Workers
5174
- **ChittyCert** (`cert.chitty.cc/.well-known/jwks.json`) — public key authority
75+
- **ChittyAuth** — shared-secret Bearer token (`CHITTY_AUTH_SERVICE_TOKEN`)
5276
- **KV binding** (`PROOF_KEY_CACHE`) — optional JWKS cache for Workers consumers
5377

5478
## Patterns
@@ -58,3 +82,5 @@ This is a **library**, not a deployable service. It exports pure functions that
5882
- Non-finite numbers throw — no `NaN` or `Infinity` in canonical payloads
5983
- Base64url encoding/decoding handles padding normalization internally
6084
- `structuredClone` is used for immutable normalization (no mutation of input bundles)
85+
- Routes are thin wrappers around library functions — no business logic in route handlers
86+
- Auth middleware uses simple string comparison against `env.CHITTY_AUTH_SERVICE_TOKEN`

0 commit comments

Comments
 (0)