This repo contains two runnable demos of the same privacy-first idea:
Browser demo.html — everything runs client-side:
Device split (phone.py + scanner.py) — two Python programs that mimic a phone ↔ scanner deployment:
./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
demo.html)purpose=shopping_assist, expiry guard) → shopping rule (lower sugar suggestion) → auditdemo.html in a modern browser (Chrome/Edge/Firefox/Safari).insight.ttl, policy.ttl, a envelope.sig.json, a banner.json preview, and audit.ttl.@prefix lines, trim & collapse spaces, sort lines, then sign the concatenation of insight.ttl + policy.ttl. (Production: use URDNA2015 over N-Quads.)No network calls; everything is client-side.
phone.py + scanner.py)PATH (or set EYE_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.json
phone.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)
health:Diabetes). Only a neutral Insight (metric/threshold + scope + expiry) reaches the scanner.retailer, device, event, and expiresAt. The scanner enforces a delete duty at expiry.req:Request; audit rules record only typed requests (no policy internals).health:Diabetes ⇒ need:needsLowSugar true.ins:Insight with metric, threshold, scopeDevice, scopeEvent, retailer, expiresAt.odrl:use with purpose="shopping_assist"; prohibit share@marketing; duty delete@expiresAt.ins:Insight; allow/deny; mark expired by guard.act:Decision for typed requests, and act:Duty "delete_due" on close-out.catalog.ttl.eye: command not found (Python split)
Install EYE or set EYE_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.ttl
Usually 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.ttl or policy.ttl after signing. Re-run phone.py to regenerate a matching signature.
Browser demo button does nothing
Make sure you’re opening demo.html locally without CSP blockers; try a modern browser. The page loads Pyodide and eye-js from CDNs.