# qub > Seal your words today. Prove when you said them. qub is a timed commitment system. You compose a message, choose an unlock date, and qub timelock-encrypts it using drand's distributed randomness network. The sealed qub is stored permanently on Arweave. Before the unlock time, nobody — not even qub — can read the content. After the unlock time, anyone with the link can decrypt and verify the message. ## What agents can do - **Create qubs** — seal a message with a future unlock date via API or MCP server - **Create pacts** — stage a bilateral agreement, share the staging link, and co-sign when both parties are ready - **Read qubs** — fetch qub status and content (if unlocked) as structured JSON - **Verify qubs** — cryptographic proof that content existed before the unlock time - **Monitor qubs** — check status, register webhooks for unlock notifications - **Engage with sealed qubs** — increment watch counters, subscribe an email for reveal-time notification - **Manage identity** — link a device to an email via magic link, recover a previously-linked identity for cross-device qub history - **Attest identity** — verify an email against a signing key so authored qubs display a verified identity - **Rotate API keys** — issue a new key with a grace period so deployments can roll over without downtime ## Use cases for AI agents - Provably commit to predictions before outcomes are known - Schedule time-locked announcements or reveals - Create verifiable audit trails with cryptographic timing guarantees - Build workflows that trigger on qub unlock events ## API Base URL: `https://qub.social` ### Authentication There are three authentication paths: 1. **API key** — programmatic access. Pass `Authorization: Bearer qub_sk_...`. Required for `/api/v1/seal`, `/api/v1/webhooks`, and key rotation. 2. **Cloudflare Turnstile** — browser-only. The token is passed in the request body as `turnstile_token`. Used by `/api/v1/upload` and `/api/v1/upload-auth` when no API key is present. 3. **Magic link (email)** — user-facing identity verification. The browser requests a magic link via `/api/v1/auth/magic-link`, the user clicks it, and the resulting `/api/v1/auth/verify` call links a device to an email so the same identity can be recovered on a new device. Tokens are HMAC-signed, single-use, and expire in 15 minutes. This is the path the web app uses; agents typically don't need it unless they're impersonating a browser session. ``` Authorization: Bearer qub_sk_... ``` ### Endpoints | Method | Path | Auth | Description | |--------|------|------|-------------| | GET | `/api/v1/qub/{tx_id}` | Optional | Read qub status and content (JSON) | | GET | `/api/v1/qub/{tx_id}/meta` | None | Lightweight metadata read (Arweave block timestamp + intent tag + current watching count); no decrypt. The viewer and the `` iframe re-poll this every 30s during countdown so watching counts climb live; polling halts in the final minute before unlock. | | GET | `/api/v1/qub/{tx_id}/bytes` | None | Raw sealed CBOR bytes (R2 cache-aside, immutable caching). Used by embed + SPA for client-side decrypt. | | POST | `/api/v1/qub/{tx_id}/watch` | None | Increment the pre-reveal "watching" counter for social proof | | POST | `/api/v1/qub/{tx_id}/view` | None | Increment the post-reveal view counter | | POST | `/api/v1/qub/{tx_id}/notify` | None | Subscribe an email to be notified when the qub unlocks | | POST | `/api/v1/qub/{tx_id}/react` | None | Record a `called_it` / `wrong` reaction for a revealed prediction; returns updated tallies | | POST | `/api/v1/seal` | API key | Create a qub (server-side encryption) | | POST | `/api/v1/upload` | API key or Turnstile | Upload pre-sealed CBOR (client-side encryption) | | POST | `/api/v1/upload-auth` | API key or Turnstile | Pre-check upload eligibility | | GET | `/api/v1/entitlements` | None | Check device tier and remaining qubs | | POST | `/api/v1/checkout` | API key or Turnstile | Create Stripe checkout session for qub credits | | POST | `/api/v1/api-keys/checkout` | Turnstile | Create Stripe checkout session for a Builder API key | | GET | `/api/v1/api-keys/provisioned` | None | One-time retrieval of a newly provisioned API key (by Stripe `session_id`) | | POST | `/api/v1/api-keys/rotate` | API key | Rotate the current API key, returns the new secret with a grace period | | POST | `/api/v1/auth/magic-link` | None | Issue a magic-link token to an email + device | | POST | `/api/v1/auth/verify` | None | Verify a magic-link token, link the device, return the identity | | GET | `/api/v1/identity` | None | Read-only lookup of the linked identity for a device | | GET | `/api/v1/creator/qubs` | None | Identity-scoped aggregate of a creator's sealed qubs (oldest, next reveal, total watchers) | | POST | `/api/v1/webhooks` | API key | Register unlock notification webhook | | GET | `/api/v1/webhooks` | API key | List registered webhooks | | DELETE | `/api/v1/webhooks/{id}` | API key | Remove a webhook | | POST | `/api/v1/pact/stage` | API key or Turnstile | Stage a signed pact envelope for co-signing | | GET | `/api/v1/pact/stage/{id}` | None | Review a staged pact's terms and metadata | | POST | `/api/v1/pact/cosign/{id}` | API key or Turnstile | Co-sign a staged pact and trigger upload to Arweave | | DELETE | `/api/v1/pact/stage/{id}` | API key or Turnstile | Retract a staged pact before co-signing (proof-of-possession required) | | POST | `/api/v1/identity/attestation/email/begin` | None | Start email attestation — sends a 6-digit code | | POST | `/api/v1/identity/attestation/email/verify` | None | Verify the 6-digit code to link email to signing key | | DELETE | `/api/v1/identity/attestation/email` | None | Revoke email attestation (proof-of-possession required) | | GET | `/api/v1/identity/attestation/{fingerprint}` | None | Look up the attestation for a public key fingerprint | | POST | `/api/v1/report` | None | Submit a content report for moderation | | GET | `/api/v1/openapi.json` | None | OpenAPI 3.1 specification | | GET | `/api/v1/og/{tx_id}.png` | None | Dynamic Open Graph image (sealed: reveal date + watching count; revealed: called-it percentage). R2 cache-aside. | | GET | `/api/v1/lifecycle/unsubscribe` | None | One-click unsubscribe from creator lifecycle emails (token in query string) | | GET | `/c/{tx_id}` | None | Viewer page (HTML for browsers, OG meta tags for bots, redirects to JSON for `Accept: application/json`) | | GET | `/s/{code}` | None | 7-character short-URL redirect (302) to `/c/{tx_id}`. Allocated at upload and seal time; preferred for share surfaces because it saves ~56 characters vs the full Arweave `tx_id`. | | GET | `/oembed` | None | oEmbed discovery endpoint for auto-embedding qub viewer cards on WordPress, Notion, Medium, Substack | ### Creating a qub (server-side seal) ``` POST /api/v1/seal Authorization: Bearer qub_sk_... Content-Type: application/json { "body": "My prediction: the market will close above 5000 on Friday.", "unlock_at": 1746057600, "sender_label": "Agent Smith" } ``` Response: ```json { "tx_id": "abc123...", "delivery_url": "https://qub.social/c/abc123...", "short_delivery_url": "https://qub.social/s/aB12xYz", "qub_id": "f955de1c...", "unlock_at": 1746057600, "drand_round": 17754411 } ``` The `short_delivery_url` is present when a 7-character base62 short code was allocated at seal time; prefer it for social-channel share surfaces (tweets, QR matrices) because it saves ~56 characters vs the `/c/{tx_id}` form. Both URLs resolve to the same viewer page. Absent if allocation failed transiently — `delivery_url` is always usable as a fallback. Note: The server-side seal endpoint passes plaintext through the server for convenience. For end-to-end encryption where plaintext never leaves your machine, use the MCP server. ### Reading a qub ``` GET /api/v1/qub/{tx_id} ``` Returns JSON with `status: "locked"` (with countdown metadata) or `status: "unlocked"` (with verified body content). ### Webhooks Register a webhook to be notified when a qub unlocks: ``` POST /api/v1/webhooks Authorization: Bearer qub_sk_... Content-Type: application/json { "tx_id": "abc123...", "url": "https://your-agent.example/callback", "secret": "your-hmac-secret-min-16-chars" } ``` All three fields are required. `secret` must be at least 16 characters. The callback receives a POST with the qub data and an `X-Qub-Signature` HMAC-SHA256 header computed with `secret`. ### Notify-me (email subscription) For human-facing flows where a webhook isn't appropriate, an email address can be subscribed to a sealed qub. The Worker's reveal-time cron sends a one-shot email when the qub unlocks. No verification step — best-effort delivery. ``` POST /api/v1/qub/{tx_id}/notify Content-Type: application/json { "email": "alice@example.com", "unlock_at": 1746057600, "locale": "en" } ``` Hard-capped at 1000 subscribers per qub. Rate-limited 5/min/IP. Response is always `{"ok": true}` on success — the user shouldn't be able to enumerate which qubs already have a given subscriber. ### Engagement counters Lightweight social-proof counters. Both endpoints are unauthenticated, rate-limited 10/min/IP, and return the new count. ``` POST /api/v1/qub/{tx_id}/watch → { "count": 42 } // pre-reveal POST /api/v1/qub/{tx_id}/view → { "count": 318 } // post-reveal ``` ### Identity recovery After a magic-link verify, the device → email link is stored server-side. A new browser on the same device can recover the linked identity (and the user's sealed-history index) without re-clicking a magic link: ``` GET /api/v1/identity?device_id=<32-hex> → { "ok": true, "email": "...", "tier": "free", "qubs_remaining": 8, "sealed_history": [...], "locale": "en" } ``` Returns 404 with `{"code": "NOT_LINKED"}` if the device hasn't been linked yet. ### Creator qubs summary Aggregates the creator's `sealed_history` into the three retention-facing facts the `/identity` surface needs in a single round-trip — oldest sealed qub, next upcoming reveal, and total watchers across every qub they've sealed. Same device-id auth surface as `/api/v1/identity`. ``` GET /api/v1/creator/qubs?device_id=<32-hex> → { "oldest_sealed": { "tx_id": "...", "sealed_at": 1700000000, "unlock_at": 1710000000, "intent": "prediction" }, "next_reveal": { "tx_id": "...", "sealed_at": 1720000000, "unlock_at": 1750000000, "intent": "letter", "days_remaining": 42 }, "aggregate_watchers": 1337, "qub_count": 12, "truncated": false } ``` Returns 404 `{"code": "NOT_LINKED"}` when the device isn't linked. `next_reveal` is `null` once every qub has already unlocked. `truncated: true` means the aggregate was computed over the 200 most recent seals (defensive cap — not reached in practice). ### Pact staging (bilateral agreements) A pact is a structured agreement between two parties, sealed as a qub with content type `0x03`. The staging flow: 1. **Party A stages** — sends a signed envelope containing the pact terms (title, key-value terms, party identifiers, optional notes) via `POST /api/v1/pact/stage`. Returns a `staging_id`. 2. **Party B reviews** — fetches the staged pact via `GET /api/v1/pact/stage/{id}`. Returns the CBOR envelope, terms summary, and Party A's public key. 3. **Party B co-signs** — sends their signature via `POST /api/v1/pact/cosign/{id}`. The Worker merges both signatures into the envelope and uploads to Arweave. Returns the `tx_id` and delivery URL. 4. **Retraction** — Party A can retract before co-signing via `DELETE /api/v1/pact/stage/{id}` (proof-of-possession required). Staged pacts expire after 7 days if not co-signed. ### Email attestation Link an email address to a signing key so viewers can see who authored a qub. The flow: 1. **Begin** — `POST /api/v1/identity/attestation/email/begin` with the email, public key fingerprint, and a proof-of-possession signature. Sends a 6-digit code via email. 2. **Verify** — `POST /api/v1/identity/attestation/email/verify` with the code and fingerprint. On success, the attestation is stored and visible to viewers. 3. **Revoke** — `DELETE /api/v1/identity/attestation/email` with a proof-of-possession signature. Removes the attestation. 4. **Lookup** — `GET /api/v1/identity/attestation/{fingerprint}` returns the current attestation for a public key (used by viewers during reveal). ## MCP Server For Claude and other tool-using LLMs, install the qub MCP server: ```json { "mcpServers": { "qub": { "command": "qub-mcp", "env": { "QUB_API_KEY": "qub_sk_..." } } } } ``` The MCP server encrypts locally using the same cryptographic library as the web app — plaintext never leaves your machine. Tools: `create_qub`, `read_qub`, `check_status`. The MCP server is intentionally minimal — it covers the core seal/read/status operations and nothing else. For notify-me, engagement counters, identity linking, webhooks, and key rotation, use the HTTP API directly. ## Protocol - **Encryption:** drand timelock encryption (tlock) using quicknet chain (BLS12-381, 3-second rounds) - **Storage:** Arweave permanent storage (immutable, censorship-resistant) - **Hashing:** SHA3-256 for content integrity (body_hash, qub_id derivation) - **Serialisation:** Canonical CBOR (RFC 8949 deterministic profile) - **Verification:** Any third party can independently verify a qub without qub's cooperation ## Links - Website: https://qub.social - Full bundle (llms.txt + protocol + agent reference, single file): https://qub.social/llms-full.txt - API spec: https://qub.social/api/v1/openapi.json - Protocol spec: https://qub.social/protocol - Sitemap: https://qub.social/sitemap.xml - MCP discovery: https://qub.social/.well-known/mcp.json - Source: https://github.com/svailsa/qub --- # Protocol Specification Source: https://qub.social/protocol # qub Protocol Specification | Field | Value | | ----------- | ----------------------------- | | **Version** | 1.0 (protocol version `0x01`) | | **Date** | 2026-04-16 | | **Status** | Draft — Companion to PDD v1.0 | | **Reviewed through** | 2026-04-18 (F4-e embed locale infrastructure, F4-g publisher contract — no protocol change; both live in the viewer presentation layer, not the wire format) | This document is the normative protocol specification for the qub timed commitment system. It defines data structures, serialisation rules, derivation formulas, and verification procedures required for interoperable implementations. The PDD (§7) provides a summary; this document provides the complete specification. Scope: the protocol layer is intentionally language-neutral — the qub body is opaque plaintext / markdown / voice / pact bytes, and locale-aware rendering is the viewer's responsibility (qub.social web app, `` iframe, MCP clients, etc.). Embed presentation, loader URL pinning, and BCP 47 locale resolution are specified in [`docs/EMBED.md`](../../docs/EMBED.md), not here. ______________________________________________________________________ ## 1. Notation and Conventions | Notation | Meaning | | ------------------ | ----------------------------------------------- | | `u8`, `u64`, `i64` | Unsigned/signed integers of specified bit width | | `[u8; N]` | Fixed-length byte array of N bytes | | `Vec` | Variable-length byte array | | `Option` | Value of type T, or absent | | `String` | UTF-8 text string, NFC normalised | | `||` | Byte concatenation | | `SHA3-256(x)` | NIST SHA3-256 hash of byte string x (FIPS 202) | | `ceil(x)` | Ceiling function: smallest integer ≥ x | | CBOR | Concise Binary Object Representation (RFC 8949) | | big-endian | Most significant byte first | All integers in preimage constructions are encoded as **big-endian** fixed-width byte arrays (i64 → 8 bytes, u8 → 1 byte) unless otherwise specified. All timestamps are **Unix seconds in UTC**. ______________________________________________________________________ ## 2. Data Structures ### 2.1 ComposeQub (Creator In-Memory State) Not serialised to CBOR. Not stored on Arweave. Local to the creator app. ```text ComposeQub { draft_id: [u8; 16], // Random, generated locally created_at: i64, // Unix seconds UTC unlock_at: Option, // Unix seconds UTC; None while composing visibility: u8, // 0x01 = public (only value in MVP) content_type: u8, // 0x01 = text (only value in MVP) plaintext: Vec, // UTF-8 message body sender_label: Option, // Decorative display name; not authenticated status: DraftStatus, // Composing | Sealed | Uploaded | Failed } ``` ### 2.2 QubEnvelope (Decrypted Payload) Serialised using canonical CBOR (§3). Encrypted inside the `SealedQub`. This is the structure that proves content integrity after decryption. ```text QubEnvelope { version: u8, // Protocol major version (0x01 for v1) qub_id: [u8; 32], // Derived (see §4.1) content_type: u8, // Content type registry (see §6) created_at: i64, // Unix seconds UTC unlock_at: i64, // Unix seconds UTC sender_label: Option, // Decorative; not authenticated in MVP body: Vec, // Content payload (UTF-8 for text, CBOR for pact) body_hash: [u8; 32], // SHA3-256(body) (see §4.2) sig_alg: u8, // Signature algorithm (see §9.2) author_signature: Option>, // Phase 2+ author_pubkey: Option>, // Phase 2+ cosigner_pubkey: Option>, // Phase 2+ (pact bilateral agreements) cosigner_signature: Option>, // Phase 2+ (pact bilateral agreements) } ``` **Baseline (unsigned text qub):** `version` = `0x01`, `content_type` = `0x01`, `sig_alg` = `0x00`, all `Option` fields absent. **Other v1 configurations:** `content_type` = `0x03` (pact body, see §6.1); `sig_alg` = `0x01` (ML-DSA-65) with `author_signature` and `author_pubkey` present (see §9.3); `cosigner_pubkey` and `cosigner_signature` present together for cosigned pacts (see §9.7). ### 2.3 SealedQub (Canonical Wire Format) Serialised using canonical CBOR (§3). Uploaded to Arweave. This is the on-chain artifact. ```text SealedQub { version: u8, // Protocol major version (0x01 for v1) qub_id: [u8; 32], // Same as QubEnvelope.qub_id visibility: u8, // 0x01 = public, 0x00 = private (Phase 2+) unlock_at: i64, // Unix seconds UTC drand_chain_id: String, // drand chain hash (hex string) drand_round: u64, // Target drand round number tlock_ciphertext: Vec, // tlock-encrypted QubEnvelope CBOR bytes recipient_pubkey: Option<[u8; 32]>,// Phase 2+ (private qubs only) } ``` ### 2.4 RevealedQub (Viewer Application State) Not serialised to CBOR. Local to the viewer app. Constructed after successful decryption and verification. ```text RevealedQub { qub_id: [u8; 32], arweave_tx_id: String, visibility: u8, created_at: i64, unlock_at: i64, drand_chain_id: String, drand_round: u64, sender_label: Option, body: Vec, body_hash: [u8; 32], body_hash_verified: bool, author_signature: Option>, author_pubkey: Option>, signature_verified: Option, } ``` ______________________________________________________________________ ## 3. Canonical CBOR Profile All `SealedQub` and `QubEnvelope` serialisation MUST conform to this profile. Two implementations given the same logical structure MUST produce identical bytes. ### 3.1 Encoding Rules | Rule | Specification | | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | Standard | RFC 8949 §4.2.1 (Core Deterministic Encoding Requirements) | | Map key ordering | Sorted by **encoded byte length** first (shorter before longer), then **lexicographically** (byte-by-byte for same-length encodings) | | Integer encoding | Shortest form: 0–23 in initial byte; 24–255 in 2 bytes; 256–65535 in 3 bytes; etc. | | Length encoding | **Definite lengths only.** No indefinite-length arrays, maps, byte strings, or text strings (additional info = 31 is forbidden). | | Tags | **No CBOR tags** (major type 6 is forbidden). | | Floating-point | **No floats** (major types 7 values 0xF9–0xFB are forbidden). | | Text strings | UTF-8 encoded, **NFC normalised** (Unicode Normalization Form C). | | Byte strings | Raw bytes. No base64 encoding at the CBOR layer. | | Duplicate keys | **Reject with error.** Parsers MUST NOT silently accept duplicate map keys. | | Simple values | Only `true` (0xF5), `false` (0xF4), and `null` (0xF6) are permitted. | | Optional fields | Absent optional fields are **omitted** from the CBOR map entirely (not encoded as `null`). Present optional fields are included in sorted key order. | ### 3.2 Verified Canonical Key Orders These key orders are normative. Implementations MUST emit keys in exactly this order. Debug assertions SHOULD verify ordering in non-release builds. **QubEnvelope (version 0x01, unsigned, all optional fields absent):** ```text "body" (5 encoded bytes) "qub_id" (7 encoded bytes) "sig_alg" (8 encoded bytes) "version" (8 encoded bytes) "body_hash" (10 encoded bytes) "unlock_at" (10 encoded bytes) "created_at" (11 encoded bytes) "content_type" (13 encoded bytes) "sender_label" (13 encoded bytes) ← only if present "author_pubkey" (14 encoded bytes) ← Phase 2+, only if present "cosigner_pubkey" (16 encoded bytes) ← Phase 2+, only if present (pact) "author_signature" (17 encoded bytes) ← Phase 2+, only if present "cosigner_signature" (19 encoded bytes) ← Phase 2+, only if present (pact) ``` **QubEnvelope key order derivation:** each key is a CBOR text string. Encoded length = 1 byte header + string length (for strings under 24 bytes). Sort by total encoded length first, then lexicographically for same-length keys. **SealedQub (version 0x01, public, no recipient):** ```text "qub_id" (7 encoded bytes) "version" (8 encoded bytes) "unlock_at" (10 encoded bytes) "visibility" (11 encoded bytes) "drand_round" (12 encoded bytes) "drand_chain_id" (15 encoded bytes) "recipient_pubkey" (17 encoded bytes) ← only if present (Phase 2+) "tlock_ciphertext" (17 encoded bytes) ``` **PactTerms (pact body, content_type `0x03`):** ```text "notes" (6 encoded bytes) ← only if present "terms" (6 encoded bytes) "title" (6 encoded bytes) "party_a" (8 encoded bytes) "party_b" (8 encoded bytes) "pact_version" (13 encoded bytes) ``` **PactTerm (row of the `terms` array):** ```text "key" (4 encoded bytes) "value" (6 encoded bytes) ``` **PartyIdentifier (party_a / party_b map):** ```text "label" (6 encoded bytes) "contact" (8 encoded bytes) ← only if present ``` ### 3.3 Byte Encoding Reference | Type | CBOR encoding | Example | | ---------------------------------- | ---------------------------------------------------------- | ----------------- | | SHA3-256 hash (32 bytes) | `0x58 0x20` + 32 bytes | body_hash, qub_id | | Timestamps (i64) | Major type 0 (positive) or 1 (negative), shortest encoding | Unix seconds | | Version (u8, value 1) | `0x01` (single byte) | | | Content type (u8, value 1) | `0x01` (single byte) | | | sig_alg (u8, value 0) | `0x00` (single byte) | | | ML-DSA-65 signature (3,309 bytes) | `0x59 0x0C 0xED` + 3,309 bytes | Phase 2+ | | ML-DSA-65 public key (1,952 bytes) | `0x59 0x07 0xA0` + 1,952 bytes | Phase 2+ | ______________________________________________________________________ ## 4. Normative Derivations ### 4.1 qub_id The `qub_id` uniquely identifies a qub and binds the QubEnvelope to the SealedQub. It is derived deterministically from envelope content. ```text qub_id = SHA3-256( "QUB_ID_V1" || // domain separator: ASCII bytes [0x51 0x55 0x42 0x5F 0x49 0x44 0x5F 0x56 0x31] (9 bytes) + 0x00 padding (1 byte) = 10 bytes version || // u8 (1 byte) content_type || // u8 (1 byte) created_at || // i64 big-endian (8 bytes) unlock_at || // i64 big-endian (8 bytes) body_hash // [u8; 32] (32 bytes) ) // Total preimage: 60 bytes → 32-byte output ``` **Domain separator encoding:** The string `"QUB_ID_V1"` is 9 ASCII bytes. A single `0x00` padding byte is appended to reach 10 bytes for alignment. Implementations MUST use exactly these 10 bytes: `[0x51, 0x55, 0x42, 0x5F, 0x49, 0x44, 0x5F, 0x56, 0x31, 0x00]`. **Properties:** - Changing any field in the QubEnvelope (body, timestamps, content type, version) produces a different qub_id. - The qub_id is computed before encryption. Both QubEnvelope and SealedQub carry the same qub_id. The viewer verifies they match after decryption. - qub_id does not depend on `sender_label`, `author_signature`, or `author_pubkey`. This means the same content sealed at the same time produces the same qub_id regardless of who signs it. ### 4.2 body_hash ```text body_hash = SHA3-256(body) ``` Where `body` is the raw `Vec` content payload. For text qubs, this is the UTF-8 encoded message body. ### 4.3 Unlock-Round Mapping ```text drand_round = ceil((unlock_at - chain_genesis_time) / chain_period_seconds) ``` | Parameter | Source | Example | | ---------------------- | --------------------------------- | -------------------------------------- | | `unlock_at` | User-chosen Unix seconds UTC | `1735689600` (2025-01-01 00:00:00 UTC) | | `chain_genesis_time` | drand chain info (`genesis_time`) | `1595431050` | | `chain_period_seconds` | drand chain info (`period`) | `30` | The `ceil()` operation selects the **first drand round whose reveal time is ≥ unlock_at**. This ensures the qub does not become decryptable before the chosen unlock time. **Edge case:** if `(unlock_at - chain_genesis_time)` is exactly divisible by `chain_period_seconds`, the result is that exact round — the qub unlocks precisely at that round’s reveal time. **Validation:** `unlock_at` MUST be in the future at seal time. `unlock_at` MUST NOT be more than 10 years from `created_at` (to limit long-horizon drand dependency risk; the UI SHOULD warn for unlock dates beyond 2 years). ______________________________________________________________________ ## 5. Wire Format Newtypes Wire format newtypes provide compile-time safety against confusing CBOR bytes with JSON, raw plaintext, or other byte encodings. | Type | Contains | Produced By | Consumed By | | ----------------- | ----------------------------- | -------------------------- | ----------------------------------------- | | `SealedQubCbor` | Canonical CBOR of SealedQub | `serialize_sealed_qub()` | Arweave upload, viewer fetch | | `QubEnvelopeCbor` | Canonical CBOR of QubEnvelope | `serialize_qub_envelope()` | tlock encrypt input, tlock decrypt output | ### 5.1 Construction Rules ```rust // Production code — only through CBOR serialisers: let sealed = SealedQubCbor::from_encoded(cbor_bytes); // There is deliberately NO From> implementation. // You cannot accidentally wrap arbitrary bytes in a wire format type. // Accessing raw bytes: let bytes: &[u8] = sealed.as_bytes(); let bytes: Vec = sealed.into_bytes(); ``` ### 5.2 Validation on Construction `from_encoded()` SHOULD validate that the input begins with a valid CBOR map header. Full structural validation happens at parse time, not construction time, to avoid double-parsing. ______________________________________________________________________ ## 6. Content Type Registry | Value | Type | Phase | Max Body Size | Notes | | ------------- | --------------------------------------- | ------- | ------------- | --------------------------------------------------------------------- | | `0x00` | Reserved (invalid) | — | — | MUST NOT be used | | `0x01` | Plain text (UTF-8, restricted Markdown) | MVP | 50 KB | See §11 for rendering rules | | `0x02` | Voice (Opus audio) | Phase 2 | 2 MB | Duration-capped | | `0x03` | Pact (bilateral agreement, CBOR body) | Phase 2 | 100 KB | Body is canonical CBOR `PactTerms` (§6.1). Cosigner signing per §9.7. | | `0x04`–`0x0F` | Reserved for qub-defined types | — | — | Assigned in future spec revisions | | `0x10`–`0x7F` | Reserved for future standardisation | — | — | Requires spec approval | | `0x80`–`0xFE` | Experimental / private use | — | — | Not guaranteed interoperable | | `0xFF` | Reserved (invalid) | — | — | MUST NOT be used | Viewers MUST reject unknown content types with a clear user-visible error. Viewers MUST NOT attempt to render unknown types as text. ### 6.1 Pact Body (`content_type = 0x03`) A pact body is the canonical CBOR encoding of a `PactTerms` value: ```text PactTerms { pact_version: u8, // 0x01 for structured/v1 title: String, // ≤ 200 bytes, NFC terms: Vec, // ≤ 20 rows party_a: PartyIdentifier, // initiator party_b: PartyIdentifier, // counter-signer notes: Option, // ≤ 5,000 bytes, NFC; absent key if none } PactTerm { key: String (≤ 100), value: String (≤ 2,000) } // NFC on both sides PartyIdentifier{ label: String (≤ 100), contact: Option } ``` Canonical CBOR key orders for all three maps are given in §3.2. Total serialised pact CBOR MUST NOT exceed 100 KB (matches §6). **Schema discriminator.** The first row in `terms` for a `structured/v1` pact MUST be `{ key: "pact_schema", value: "structured/v1" }`. Rows without this marker are "custom" pacts and receive no structured validation or schema-aware rendering. **Frozen acknowledgement slots.** `structured/v1` pacts carry exactly four acknowledgement rows under these keys: ```text "initiator_standard_terms" "initiator_capacity_terms" "counterparty_standard_terms" "counterparty_capacity_terms" ``` The `value` for each is one of eight frozen English strings chosen by the `(role, kind)` pair, where `role ∈ { seller, buyer, provider, client }` and `kind ∈ { standard, capacity }`. The strings themselves are **normative protocol data** — both parties' ML-DSA-65 signatures commit to the exact bytes via `body_hash`. They are NOT localised; the signed body is language-neutral. Any wording change requires a new schema version (`structured/v2`). The eight strings, their lookup (`acknowledgement_for(role, kind)`), and the rationale for each are pinned by the reference implementation. Conforming implementations MUST emit byte-identical acknowledgement values; golden-fixture SHA3-256 body-hash tests covering all four role combinations catch any drift. **Viewer display order.** The acknowledgement strings contain phrases such as "described above", which presume the description / scope rows render ahead of the acknowledgements. Viewers MUST render the `terms` array in CBOR order; reordering breaks the prose semantics. **Counter-party contact.** When Party B's `contact` is a valid email address, the qub upload service auto-dispatches a review / co-sign invite email at stage time and binds the eventual co-sign to verification of that same address (§9.7). Pacts whose Party B contact is absent can still be co-signed, but only through an out-of-band channel — the service refuses co-sign requests that cannot produce a matching 15-minute email-verification marker. ______________________________________________________________________ ## 7. Seal Protocol The complete seal sequence. Each step is normative. ```text 1. User composes plaintext and metadata in ComposeQub. 2. Validate: a. body is non-empty. b. body size ≤ max for content_type and user tier (see §6, PDD §8.4). c. unlock_at is in the future. d. unlock_at ≤ created_at + 10 years. e. content_type is a known, supported value. 3. Compute body_hash = SHA3-256(body). 4. Set created_at = current Unix seconds UTC. 5. Compute qub_id (see §4.1). 6. Construct QubEnvelope with all fields. 7. Serialise QubEnvelope using canonical CBOR → bytes B. Assert: serialised output matches canonical profile (§3). 8. Select drand chain. Load chain_genesis_time and chain_period_seconds. 9. Compute drand_round = ceil((unlock_at - chain_genesis_time) / chain_period_seconds). 10. Compute C = tlock_encrypt(B, drand_round, drand_chain_public_key). 11. Construct SealedQub with tlock_ciphertext = C, and matching qub_id, version, unlock_at, drand_chain_id, drand_round. 12. Serialise SealedQub using canonical CBOR → SealedQubCbor. 13. Display seal-time disclosure. User confirms. 14. Validate upload eligibility via the qub upload service (bot-detection, entitlement, rate limits). 15. Submit SealedQubCbor to the qub upload service; the service signs and uploads to Arweave. 16. Receive arweave_tx_id and delivery URL from the service. ``` ______________________________________________________________________ ## 8. Unlock Protocol The complete unlock sequence. Each step is normative. ```text 1. Viewer opens delivery URL. Extract arweave_tx_id from path. 2. Check denylist. If tx_id is denylisted → display block message. Stop. 3. Fetch SealedQubCbor from Arweave (with multi-gateway fallback). 4. Parse SealedQubCbor → SealedQub. 5. Validate: SealedQub.version is known (0x01). Reject unknown versions. 6. If current time < SealedQub.unlock_at → display countdown. Poll or wait. 7. Once current time ≥ SealedQub.unlock_at: a. Fetch drand round signature for SealedQub.drand_round from drand network. b. Compute B = tlock_decrypt(SealedQub.tlock_ciphertext, round_signature). 8. Parse B → QubEnvelope. 9. Validate QubEnvelope.version is known. 10. Verify: SHA3-256(QubEnvelope.body) == QubEnvelope.body_hash. Fail → integrity error. 11. Verify: QubEnvelope.qub_id == SealedQub.qub_id. Fail → integrity error. 12. Verify: QubEnvelope.unlock_at == SealedQub.unlock_at. Fail → integrity error. 13. Verify: QubEnvelope.content_type is known and renderable. Known values: 0x01 (text), 0x03 (pact). Unknown → display error. 14. If QubEnvelope.sig_alg != 0x00 → verify author signature (see §9.4). 15. If cosigner_pubkey or cosigner_signature present → verify cosigner (see §9.7). 16. Render content using appropriate renderer (see §11 for text, §6 for pact). 17. Construct RevealedQub for display. ``` ______________________________________________________________________ ## 9. Authorship Signing (Phase 2+) ### 9.1 Rationale Qubs are stored permanently on Arweave. Authorship signatures must remain unforgeable indefinitely. This makes post-quantum signatures (ML-DSA-65) preferable over classical schemes (Ed25519), whose security may degrade within the qub’s permanent lifetime. ### 9.2 Algorithm Registry | `sig_alg` | Scheme | Key Size | Signature Size | Status | | ------------- | ----------------------- | ----------- | -------------- | ----------------- | | `0x00` | No signature (unsigned) | — | — | MVP default | | `0x01` | ML-DSA-65 (FIPS 204) | 1,952 bytes | 3,309 bytes | Phase 2 default | | `0x02` | Ed25519 | 32 bytes | 64 bytes | Reserved fallback | | `0x03`–`0xFF` | Reserved | — | — | Future | Viewers MUST reject unknown `sig_alg` values. Viewers that support `sig_alg` = `0x00` but not `0x01` SHOULD display “signature present but not verifiable by this viewer version” rather than silently ignoring the signature. ### 9.3 Signed Preimage Construction ```text sig_input = SHA3-256( "QUB_AUTHOR_SIG_V1" || // domain separator (17 bytes) version || // u8 (1 byte) qub_id || // [u8; 32] (32 bytes) body_hash || // [u8; 32] (32 bytes) unlock_at || // i64 big-endian (8 bytes) org_id_present // u8 (1 byte): 0x00 = individual, 0x01 = org // org_id // [u8; 32] only if org_id_present == 0x01 (Phase 4+) ) // Individual (MVP/Phase 2): total preimage = 91 bytes → 32-byte hash // Org-delegated (Phase 4+): total preimage = 123 bytes → 32-byte hash signature = Sign(author_secret_key, sig_input) ``` **Domain separator:** `"QUB_AUTHOR_SIG_V1"` is 17 ASCII bytes: `[0x51, 0x55, 0x42, 0x5F, 0x41, 0x55, 0x54, 0x48, 0x4F, 0x52, 0x5F, 0x53, 0x49, 0x47, 0x5F, 0x56, 0x31]`. No padding. **org_id_present:** In Phase 2, this is always `0x00` (individual signing). In Phase 4+, `0x01` indicates the signature was made under an org delegation, and `org_id` ([u8; 32]) follows. This ensures individual signatures are structurally distinct from org-delegated signatures — preventing cross-context reuse. **Signature scope — what is and isn't covered.** `sig_input` commits to four envelope fields: `version`, `qub_id`, `body_hash`, `unlock_at` (plus the fixed domain separator and `org_id_present` byte). Three of those four are structural invariants: `qub_id` is itself derived from `version`, `content_type`, `created_at`, `unlock_at`, and `body_hash` via the §4.1 preimage, so any change to `content_type` or `created_at` produces a different `qub_id` and invalidates the signature transitively. The directly-authenticated surface is therefore: | Field | Authenticated by signature | How | | ------------------------- | :-: | --- | | `version` | ✓ | Direct input to `sig_input` | | `qub_id` | ✓ | Direct input | | `body_hash` | ✓ | Direct input | | `unlock_at` | ✓ | Direct input | | `content_type` | ✓ | Transitively, via `qub_id` preimage | | `created_at` | ✓ | Transitively, via `qub_id` preimage | | `body` | ✓ | Transitively, via `body_hash = SHA3-256(body)` | | `author_pubkey` | — (implicit) | Key that verified the signature is the author, by definition | | `sender_label` | **✗** | Display-only text; mutable without signature breakage | | `reply_to` | **✗** | Threading pointer; mutable without signature breakage | | `cosigner_pubkey` / `cosigner_signature` | — | Independently signed over the same `sig_input` (see §9.7) | | `drand_round`, `drand_chain_id`, `tlock_ciphertext`, `visibility` | — | Outer `SealedQub` fields, not inside the envelope — covered by their own structural invariants (round / chain consistency) but not by the author signature | **Security implications of non-authenticated fields.** - A party with write access to the stored bytes could swap `sender_label` ("Alice" → "Mallory") without invalidating the author signature. The `author_pubkey` inside the envelope remains the true identity anchor — viewers MUST derive the display identity from `author_pubkey` (via the §9.5 attestation layer) rather than trusting `sender_label`. - A `reply_to` field can likewise be edited post-signing. Because `qub_id` is content-addressed, an attacker can't point `reply_to` at a non-existent target, but they can silently re-parent a reply to a different existing qub. - For reply chains to carry end-to-end integrity, future protocol versions SHOULD either include `reply_to` in `sig_input` or require a separate `reply_sig` over `(qub_id, reply_to)`. Neither is part of Phase 2. Implementations that display `sender_label` or `reply_to` to end users MUST surface the authenticated identity (pubkey fingerprint, attestation) as the primary identity signal, not the label. ### 9.4 Verification Procedure ```text 1. Read sig_alg from QubEnvelope. 2. If sig_alg == 0x00 → unsigned. No verification. Display "unsigned qub." 3. If sig_alg is unknown → reject. Display "unrecognised signature scheme." 4. Extract author_signature and author_pubkey. If either is absent → integrity error. 5. Reconstruct sig_input using fields from QubEnvelope (same formula as §9.3). 6. Verify(author_pubkey, sig_input, author_signature). 7. If verification succeeds → display "signed by [key fingerprint]." 8. If verification fails → display "signature verification failed." ``` Signature verification is the most expensive operation (especially ML-DSA-65). It SHOULD be performed after all cheaper checks (hash, qub_id, unlock_at) have passed. ### 9.5 Identity Attestations Identity attestations — the mapping of `author_pubkey` to human-recognisable identity claims such as email, social handles, or passkey credentials — are defined in [`IDENTITY.md`](IDENTITY.md). Attestation resolution is a **viewer-side progressive enhancement** and is **not required** for signature verification. A conforming verifier can complete every check in §9.4 without contacting the qub API, without any network beyond Arweave and drand, and without any server-side lookup. Identity display (beyond the fallback fingerprint defined in IDENTITY.md §2) is a separate best-effort step performed only after signature verification has succeeded. ### 9.6 Size Impact | | Ed25519 | ML-DSA-65 | | ------------------------------ | -------- | ----------- | | Signature | 64 bytes | 3,309 bytes | | Public key | 32 bytes | 1,952 bytes | | Total per qub | 96 bytes | 5,261 bytes | | Arweave cost delta (at ~$5/MB) | ~$0.0005 | ~$0.026 | For a text qub of 500–2,000 bytes, ML-DSA-65 roughly triples the stored size. The absolute cost is negligible. ### 9.7 Cosigner Verification (Phase 2+ — Pact Bilateral Agreements) For bilateral agreements (`content_type` = `0x03`), a second signature layer proves both parties consented to the same terms. **Envelope fields:** - `cosigner_pubkey`: ML-DSA-65 public key of the counter-signer (Party B). - `cosigner_signature`: Signature over the same `sig_input` as the author (§9.3). Both fields MUST be present together or both absent. If exactly one is present, viewers MUST report an integrity error. **Verification procedure:** ```text 1. If cosigner_pubkey absent and cosigner_signature absent → no cosigner. Done. 2. If exactly one is present → integrity error. 3. Verify cosigner_pubkey != author_pubkey (prevent self-cosigning). Fail → display "cosigner pubkey must differ from author." 4. Reconstruct sig_input using the same formula as §9.3. 5. Verify(cosigner_pubkey, sig_input, cosigner_signature). 6. Success → display "co-signed by [cosigner fingerprint]." 7. Failure → display "co-signature verification failed." ``` **Properties:** - The cosigner signs the identical `sig_input` as the author — both parties commit to the same `qub_id`, `body_hash`, and `unlock_at`. - `qub_id` derivation (§4.1) does NOT include cosigner fields. Adding a cosigner to an existing envelope does not change the `qub_id`. - A pact can be author-signed only (one-sided commitment), cosigner-only (unusual), or both (full bilateral proof). **Email-binding gate (operational).** When a staged pact carries a Party B email contact (§6.1), the qub upload service MUST refuse the co-sign request unless a short-lived email-verification marker exists matching both the staging id and the normalised-email hash of that contact. The marker is written by `/api/v1/auth/verify` when the magic-link token carries a `staging_id` and the verified address matches `SHA-256(normalise_email(party_b.contact))` — where `normalise_email(addr)` preserves the local-part case and lowercases only the domain part (per RFC 5321 §2.3.11), and `SHA-256` here is the NIST FIPS 180-4 hash (distinct from the SHA3-256 used in §4 derivations) — and expires 900 seconds (15 minutes) after issue. This is an operational anti-impersonation gate, NOT part of the on-chain qub proof — a third-party verifier replaying §12 needs only Arweave and drand, without any server-side lookup. The marker exists server-side only and is never part of the signed body. **Size impact (ML-DSA-65 author + cosigner):** | Component | Size | | ------------------------- | ---------------- | | Author signature | 3,309 bytes | | Author public key | 1,952 bytes | | Cosigner signature | 3,309 bytes | | Cosigner public key | 1,952 bytes | | **Total crypto overhead** | **10,522 bytes** | | Arweave cost delta | ~$0.05 | ______________________________________________________________________ ## 10. Private qub Encryption (Phase 2+) Private qubs use two encryption layers: tlock for time-binding, and recipient-key encryption for audience restriction. ### 10.1 Encryption Stack ```text Layer 1 (inner): AES-256-GCM with key derived from X25519 key exchange Layer 2 (outer): tlock against drand round (same as public qubs) Encrypt: 1. Sender performs X25519(sender_ephemeral_secret, recipient_pubkey) → shared_secret 2. Derive AES key via HKDF-SHA256(shared_secret, salt, "QUB_PRIVATE_V1") 3. Encrypt QubEnvelope CBOR bytes with AES-256-GCM → inner_ciphertext 4. tlock_encrypt(inner_ciphertext, drand_round) → outer_ciphertext 5. SealedQub.tlock_ciphertext = outer_ciphertext 6. SealedQub.recipient_pubkey = recipient's X25519 public key Decrypt (after drand round): 1. tlock_decrypt(outer_ciphertext, round_signature) → inner_ciphertext 2. Recipient performs X25519(recipient_secret, sender_ephemeral_pubkey) → shared_secret 3. Derive AES key via HKDF-SHA256(shared_secret, salt, "QUB_PRIVATE_V1") 4. Decrypt inner_ciphertext with AES-256-GCM → QubEnvelope CBOR bytes ``` ### 10.2 Post-Quantum Note X25519 is not quantum-resistant. Private qubs stored permanently on Arweave face long-term quantum decryption risk. ML-KEM-768 (FIPS 203) is the intended future replacement, gated on library maturity and viewer bundle impact assessment. The `version` field and protocol versioning support introducing ML-KEM without breaking existing private qubs. ______________________________________________________________________ ## 11. Markdown Rendering and Sanitisation This section is security-critical. The viewer renders text qubs (`content_type` = `0x01`) using a restricted Markdown subset. ### 11.1 Allowed Elements - Headings: `#` through `####` (no `#####` or `######`) - Emphasis: bold (`**`), italic (`*`), strikethrough (`~~`) - Lists: ordered (`1.`) and unordered (`-`, `*`) - Blockquotes (`>`) - Code: inline spans (\`\`\`) and fenced blocks (\`\`\`\`\`) - Horizontal rules (`---`) - Line breaks (two trailing spaces or blank line) - Paragraphs ### 11.2 Forbidden Elements | Element | Handling | | ------------------------------------ | ------------------------------------------------------------------------------------------------ | | Raw HTML (`
`, `