Delfour-Insight-Economy

Delfour Insight Economy — Dual Demos (Browser & Python Split)

This repo contains two runnable demos of the same privacy-first idea:

  1. 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.
  2. 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).


Contents

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

1) Browser Demo (demo.html)

What it shows

How to run

Under the hood

No network calls; everything is client-side.


2) Device Split (phone.py + scanner.py)

Requirements

Quick start

# 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

CLI reference

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.

Data flow (Python split)

[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)

Key design points


Rules overview (both demos)


Troubleshooting


Production notes (beyond the demo)