This repo contains two runnable demos of the same privacy-first idea:
-
Browser demo.html — everything runs client-side:
- Orchestration in Python (Pyodide)
- Reasoning by eye-js
- Signing & verifying with TweetNaCl No installs. Open one file and click Run Demo.
-
Device split (
phone.py+scanner.py) — two Python programs that mimic a phone ↔ scanner deployment:- Reasoning by EYE (CLI)
- Signing & verifying with PyNaCl (Ed25519)
- Exchange via a simple file “databus” (
./bus/<SESSION>/…)
Both variants demonstrate: desensitize → derive Insight → ODRL policy → authorize → runtime suggestion → audit, with a signed, session-scoped Insight envelope (no sensitive terms leave the phone).
demo.html # Browser demo (Pyodide + eye-js + TweetNaCl)
phone.py # Shopper device: derive Insight + Policy, sign, write to bus
scanner.py # Retailer device: verify, authorize, suggest, audit
Artifacts produced (Python split) under ./bus/<SESSION>/:
insight.ttl # Neutral Insight (named IRI per session)
policy.ttl # ODRL policy derived from the Insight
envelope.ttl # insight + policy (for humans)
envelope.sig.json # Ed25519 signature + public key (over canonicalized envelope)
catalog.ttl # Product catalog (seeded by scanner --init)
audit.ttl # Decisions (Allowed/Blocked) and duties (delete_due)
banner.json # Shopper-facing runtime banner preview
- Phone (left): profile → desensitize → Insight (scoped to device/event/retailer with expiry) → Policy → sign (Ed25519)
- Scanner (right):
verify signature → authorize (
purpose=shopping_assist, expiry guard) → shopping rule (lower sugar suggestion) → audit
- Open
demo.htmlin a modern browser (Chrome/Edge/Firefox/Safari). - Click Run Demo.
You’ll see timelines, the derived
insight.ttl,policy.ttl, aenvelope.sig.json, abanner.jsonpreview, andaudit.ttl.
- Reasoner: [eye-js] runs the N3 rules in the browser.
- Python orchestration: [Pyodide] executes the same flow you see in the Python split.
- Sign/verify: [TweetNaCl]. For the demo, the keypair is ephemeral (per page load).
- Canonicalization (demo-grade): drop
@prefixlines, trim & collapse spaces, sort lines, then sign the concatenation ofinsight.ttl+policy.ttl. (Production: use URDNA2015 over N-Quads.)
No network calls; everything is client-side.
-
Python 3.9+
-
EYE CLI in
PATH(or setEYE_CMD=/path/to/eye) -
PyNaCl for Ed25519:
pip install pynacl
# 1) Seed a session catalog on the scanner
python scanner.py --init --session delfour
# 2) Produce and SIGN the envelope on the phone
python phone.py --session delfour --keydir ./keys
# (keydir optional; makes the key persistent across runs)
# 3) Verify, authorize, suggest, and audit on the scanner
python scanner.py --session delfour
# Inspect:
tree ./bus/delfour
cat bus/delfour/envelope.sig.json
cat bus/delfour/audit.ttl
cat bus/delfour/banner.jsonphone.py
python phone.py --session <ID> [--bus ./bus]
[--retailer Delfour] [--device self-scanner]
[--event pick_up_scanner] [--ttl-hours 2.0]
[--keydir ./keys]
Writes: insight.ttl, policy.ttl, envelope.ttl, envelope.sig.json.
scanner.py
python scanner.py --init --session <ID> [--bus ./bus]
python scanner.py --session <ID> [--bus ./bus]
Writes: catalog.ttl (init), audit.ttl, banner.json.
[Phone] profile + rule ──► need
need + context ──► insight.ttl (IRI: https://example.org/insight/<SESSION>)
insight ─────────► policy.ttl (targets the same IRI)
insight+policy ──► sign (Ed25519) → envelope.sig.json
▼
[Bus/SESSION] insight.ttl, policy.ttl, envelope.sig.json
▼
[Scanner] verify signature ✔
now + request + rules ──► Allowed/Blocked → audit.ttl
scan + catalog + Insight ──► suggestion → banner.json
expiry guard ───────────────► duty(delete_due) (on close-out)
- Privacy: The phone holds the sensitive fact (
health:Diabetes). Only a neutral Insight (metric/threshold + scope + expiry) reaches the scanner. - Scope & expiry: Insight contains
retailer,device,event, andexpiresAt. The scanner enforces a delete duty at expiry. - Named insight IRI: The Insight uses a stable IRI per session, not a blank node, so the policy can refer to it across files.
- Typed requests & clean audit: The runtime request is
req:Request; audit rules record only typed requests (no policy internals). - Sign & verify: The phone signs the canonicalized envelope; the scanner verifies hash + signature before any authorization.
- Desensitize (phone):
health:Diabetes⇒need:needsLowSugar true. - Derive Insight (phone):
Create
ins:Insightwithmetric,threshold,scopeDevice,scopeEvent,retailer,expiresAt. - Policy from Insight (phone):
Permit
odrl:usewithpurpose="shopping_assist"; prohibitshare@marketing; dutydelete@expiresAt. - Enforce (scanner):
Join policy target ⇔
ins:Insight; allow/deny; mark expired by guard. - Audit (scanner):
Record
act:Decisionfor typed requests, andact:Duty "delete_due"on close-out. - Shopping rule (scanner):
If scanned product’s sugar ≥ threshold, suggest a strictly lower-sugar alternative from
catalog.ttl.
-
eye: command not found(Python split) Install EYE or setEYE_CMD:EYE_CMD=/usr/local/bin/eye python phone.py --session delfour
-
Prefix errors (EYE) Each rule/data chunk is self-prefixed and the runner places a chunk with
@prefix xsd:first when typed literals are used. If you add your own chunks, ensure@prefix xsd:is defined where needed. -
Empty
audit.ttlUsually caused by blank-node insights or a policy that targets a different node. This demo mints a session IRI and targets it consistently. -
Signature/Hash mismatch (scanner) Don’t edit
insight.ttlorpolicy.ttlafter signing. Re-runphone.pyto regenerate a matching signature. -
Browser demo button does nothing Make sure you’re opening
demo.htmllocally without CSP blockers; try a modern browser. The page loads Pyodide and eye-js from CDNs.
- Switch signing to RDF Dataset Canonicalization (URDNA2015) over N-Quads, then sign the canonical serialization (e.g., JWS).
- Pin/whitelist public keys by issuer (DID/domain) and/or use mutual TLS during pairing (QR/NFC + secure channel).
- Replace the file bus with a local transport (WebRTC/DIDComm) and add hash-chained audit logs for non-repudiation.
- Move catalogs to edge storage, but keep policy enforcement local to the scanner.