A standalone commercial product in coreguard-global, consuming CoreGuard as an independent engine.
This repository now contains a working testnet prototype: a Pi app, a merchant hub, an adversarial
attack lab, an independent receipt verifier, a three-line developer SDK, and retry/resume handling for
the payments Pi hands back when a flow is interrupted.
npm start # http://localhost:3000 (zero dependencies, Node 20+)
If PI_API_KEY is present the app talks to the real Pi Platform API. Without it the app runs a
deterministic sandbox ledger, labels itself SANDBOX in the UI, and moves no funds.
- A Pioneer signs in with Pi; the server verifies the access token against
GET /v2/me. - The server issues an authorization intent: amount from the published price book, payee = app wallet, single-use nonce, ten-minute expiry.
- Approval (
POST /v2/payments/:id/approve) only happens after anALLOWdecision — so a refused payment never unlocks the wallet. - Completion re-reads the payment from the platform and compares the executed amount, payee and txid to the intent. Mismatch ⇒ no completion.
- Everything is sealed into an evidence receipt: ordered steps, SHA-256 chain, an Ed25519
seal anyone can check against the published key, plus an internal HMAC, and a verdict of
ALLOW,BLOCKorUNKNOWN.UNKNOWNnever settles.
Pi can deliver the same approval twice, and a phone network can duplicate a request. Money mutations must therefore be idempotent:
authorizeandcompleteare keyed onpaymentId. Repeating one returns the same decision and the same sealed receipt instead of approving twice or judging twice.completerefuses a payment this server never authorized, and refuses an intent that belongs to another Pioneer.POST /api/payments/resumefinishes a payment Pi reports as interrupted (onIncompletePaymentFound). It never invents anALLOW: if the payment cannot be tied to a server-side intent, the answer isUNKNOWN.- The Pi transport retries
GETcalls with backoff and a timeout, and never blind-retriesapprove/complete— after an ambiguous POST it re-reads the payment state instead.
| Route | Audience | What it proves |
|---|---|---|
/ |
judge / visitor | positioning, live counters, honest boundaries |
/app.html |
Pioneer | pay once, leave with a verifiable receipt |
/merchant.html |
merchant | price book, payment ledger, refused attempts, embeddable badge |
/attack.html |
judge / security | seven attacks, each with the receipt that refused it |
/verify.html |
anyone | stateless verification: recompute the chain and seal |
/developers.html |
Pi developer | three-line integration, API reference, capability matrix |
| Variable | Meaning |
|---|---|
PI_API_KEY |
Pi Server API Key — server side only, never in the browser |
PI_NETWORK |
testnet (default) or mainnet; an app is registered for one network only |
PI_APP_WALLET |
app wallet that receives U2A payments |
PORT / HOST |
bind address, defaults 3000 / 0.0.0.0 |
PI_PLATFORM_BASE |
override for the Platform API base, defaults https://api.minepi.com/v2 |
PI_TIMEOUT_MS / PI_ATTEMPTS |
Platform call timeout (8s) and attempt count for retryable GETs |
PI_VALIDATION_KEY |
domain-ownership key, served at /validation-key.txt (PiNet / Pi Sign-in) |
PI_APP_DOMAIN |
verified app domain, reported by /api/pinet |
PI_PINET_SUBDOMAIN |
PiNet subdomain once the Developer Portal issues it |
No secret is committed. .data/ (the local ledger and the Ed25519 issuer key) is git-ignored.
npm run verify # 70 end-to-end checks, exits non-zero on failure
curl -s localhost:3000/api/receipts | head -c 200
curl -s localhost:3000/api/receipts/rcpt_xxx | node scripts/verify-receipt.mjs # standalonescripts/verify-receipt.mjs imports no CoreGuard code: it rebuilds the chain and checks the Ed25519
seal against GET /api/issuer-key, so a receipt can be checked without trusting this server.
VERIFIED != SAFE,PASS != SAFE,UNKNOWN != VERIFIED. Missing evidence is never success.- No mainnet claim. Pi requires Core Team approval for the incoming multisig wallet; until that exists the product is testnet only.
- No Pi protocol-level interception or protection.
- No revenue, customers, partners, audits or funding are claimed anywhere in this repository.
- The badge fails closed: no settled receipts, no badge.
docs/PI-CAPABILITY-MATRIX.md— every capability with its literal state.docs/CODE-REVIEW.md— what was wrong, what was fixed, what is deliberately accepted.docs/DEMO-SCRIPT.md— the three-minute judge demo, beat by beat, with recovery lines.docs/PI-NET-INTEGRATION.md— PiNet rules, what is implemented, what is still blocked.docs/THIRD-PARTY-LICENSES.md— Pi SDK / Platform API terms, PiOS, and dependency licensing.docs/PI-INTEGRATION.md— developer quickstart and error/state contract.docs/PI-NEXT-*.md,docs/PI-INTEGRATION-ARCHITECTURE.md— the original plan, P0→P6, still the source of truth for what comes after the prototype.
server/ index.mjs (HTTP + routes) · policy.mjs (ALLOW/BLOCK/UNKNOWN) ·
receipts.mjs (chain + Ed25519/HMAC seal) · pi.mjs (live/sandbox transport) · store.mjs
public/ pages, design system (css/coreguard.css), embed-badge.js, sdk/pi-verify.mjs
scripts/ verify-all.mjs (70 end-to-end checks) · verify-receipt.mjs (standalone verifier)