Membership System Design
A client-sovereign membership system for Almanack with cryptographic identity, guilt-driven micropayments, and encrypted subscriber content.
Overview
Visitors receive an instant whimsical identity (“Captain Dmitri Winklebottom of the Volga Basin”) stored entirely on their device. Daily visits debit “almanickels” from their balance. Negative balances trigger guilt toward payment. Subscribers unlock encrypted content and perks.
Core Principles
- Identity sovereignty: Age keypair lives in localStorage, user controls recovery
- No signup friction: Identity created instantly on first visit
- Static-first: Main site remains statically generated; dynamic features via JS + API
- Cryptographic access control: Subscriber content encrypted, no server-side gating
- Spritely-ready: Architecture aligns with object-capability patterns for future migration
Identity Architecture
Client-Side (localStorage)
- Age X25519 keypair via typage’s
age.generateIdentity() - Display name (generated initially, user-editable)
- UI preferences (theme, sidenote state)
- Cached balance/streak (server is source of truth)
Server-Side (microservice)
- Member record keyed by age public key
- Almanickel balance (integer, can go negative)
- Visit history (dates, for streak/heatmap)
- Purchase history (Stripe transactions)
- Owned cosmetics (name flair, future items)
- Email (optional)
- Password hash (optional)
- Encrypted private key blob (optional, for email+password recovery)
Identity Flow
- First visit: Generate keypair → store in localStorage → call
/registerwith pubkey - Subsequent visits: Load keypair → sign requests to prove identity
- Recovery: Import via seed phrase / raw key / QR link / email+password → same pubkey = same account
Name Generation
Format: [Title] [Regional Firstname] [Procedural Surname] of [Regional Location]
Components:
- Titles: Sir, Dame, Lord, Lady, Captain, Admiral, Professor, Doctor, Mx., Viscount, Baron, Alderman, Magistrate, Rev., etc.
- Regional Firstnames: Based on coarse IP geolocation. Curated lists per region (Yuki for Japan, Cletus for American South, Dmitri for Russia, Aoife for Ireland). Falls back to “generic Victorian” for unknown regions.
- Procedural Surnames: Markov-ish generator producing names like Skipansicoal, Bramblethwaite, Winklebottom, Crumplestitch, Thistlewood.
- Regional Locations: Matched to firstname region (“of East Texas,” “of Osaka Prefecture,” “of County Cork”).
Generated server-side on registration (microservice has IP context). Stored as initial display name; user can edit later.
Economy
Pricing
| Item | Almanickels | Real Money |
|---|---|---|
| Daily visit cost | 50 | ~$0.05 |
| Monthly subscription | 14,000 | $7/month |
| One-time: small | 1,000 | $1 |
| One-time: medium | 5,000 | $4 |
| One-time: large | 10,000 | $7 |
Monthly Subscriber Benefits ($7/month)
- 14,000 almanickels/month
- Discord access
- Name on patrons page
- Editorial meetings
- Sneak peeks (early access)
- Exclusive subscriber flair
Cosmetics
Starting with name flair (titles, honorifics, epithets). Architecture supports future additions: badges, themes, collectible dingbats.
UI/UX
Meta-Right Area (Masthead)
Chronology · Index
Hello, Dame Yuki Bramblethwaite!
▼
Dropdown on click:
┌─────────────────────────────┐
│ ⚖️ −230 almanickels │
│ 🔥 12-day streak │
│ ─────────────────────────── │
│ Profile │
│ Top up │
│ ─────────────────────────── │
│ Not Dame Yuki? Recover → │
└─────────────────────────────┘
Profile Page (/profile/)
Static shell, JS-hydrated from microservice.
Sections: - Identity: Edit display name, add flair - Account: Set email, set password, recovery options (seed phrase, QR code, raw key) - Stats: Visit heatmap (GitHub-style), streak history - Shop: Browse/buy name flair - Billing: Top up balance, purchase history
Recovery Page (/recover/)
Two modes:
- Fragment present (
/recover#AGE-SECRET-KEY-1...): Extract key, derive pubkey, fetch profile, restore to localStorage - No fragment: Email + password form, retrieve encrypted blob, decrypt, restore
First-Visit Flow
- Page loads, no identity in localStorage
- JS generates keypair, calls
/register - Microservice returns generated name, initial balance (0)
- Dropdown appears: “Hello, [Name]!”
Visit Tracking
Debit Mechanism
- Client loads keypair from localStorage
- Signs timestamp with private key
- Sends to
POST /visitwith{pubkey, signature, page_type, timestamp} - Microservice verifies signature, checks if already debited today
- If new day: debit 50 almanickels, record visit, return updated balance + streak
- If same day: no debit, return current state
Failure Handling
If microservice unreachable: show cached balance with “Jubilee day! No charge!”
Streak Tracking
- Consecutive days with at least one visit
- Visit dates stored as array/bitmap
- Heatmap data: last 365 days, rendered client-side on profile page
Payment Flow
- User clicks “Top up” from dropdown or profile
- Selects amount (subscription or one-time)
- Client calls
POST /checkoutwith{pubkey, signature, amount} - Microservice creates Stripe Checkout session, returns URL
- Client redirects to Stripe
- On success, Stripe webhook → credit almanickels / activate subscription
- Redirect back to
/profile/?payment=success
Architecture supports adding Lightning Network later via PaymentProvider interface.
Subscriber-Only Encrypted Content
Two-Tier Key System
To avoid O(n) blob growth per subscriber:
- Group key: Symmetric key that encrypts all subscriber content
- Per-subscriber key file:
/subscriber/<pubkey>/latest.age— group key encrypted to that subscriber
Build-Time Flow
- Fetch active subscriber pubkeys from microservice
- Generate (or load) current group key
- For each subscriber: encrypt group key to their pubkey, write to
/subscriber/<pubkey>/latest.age - For each subscriber-only article: encrypt content with group key, embed in HTML
Client-Side Flow
- JS detects
.subscriber-content[data-encrypted] - Fetches
/subscriber/<my-pubkey>/latest.age - Decrypts to get group key (cache in sessionStorage)
- Decrypts article content
- Success → render content; Failure → show subscribe CTA
HTML Structure
<article>
<div class="teaser">First paragraphs visible to all...</div>
<div class="subscriber-content" data-encrypted="true">
<noscript>Subscriber-only content requires JavaScript.</noscript>
<div class="encrypted-blob" hidden>-----BEGIN AGE ENCRYPTED FILE-----
...base64...
-----END AGE ENCRYPTED FILE-----</div>
<div class="decrypt-prompt">🔒 Subscribe to read the rest</div>
</div>
</article>
Access Control
- Positive balance = subscriber
- Rebuild frequency determines access latency (daily recommended)
- Lapsed subscribers: don’t regenerate their key file on next build
Microservice API
Base URL: https://api.almanack.xyz (or similar)
Authentication: All requests include pubkey + signature (signed timestamp/nonce).
Endpoints
POST /register
Body: {pubkey}
Returns: {name, balance: 0, subscriber: false}
POST /visit
Body: {pubkey, signature, page_type, timestamp}
Returns: {balance, streak, jubilee: false}
GET /me
Query: ?pubkey=...&sig=...
Returns: {name, balance, streak, subscriber, flair, cosmetics_owned}
GET /me/history
Query: ?pubkey=...&sig=...
Returns: {visits: [...], purchases: [...]}
PATCH /me
Body: {pubkey, signature, name?, email?, flair?}
Returns: {name, email, flair}
POST /me/password
Body: {pubkey, signature, password_hash, encrypted_privkey_blob}
Stores recovery data
POST /me/email/verify
Body: {pubkey, signature, email}
Sends verification email
GET /me/email/confirm?token=...
Confirms email address
POST /checkout
Body: {pubkey, signature, amount | subscription: true}
Returns: {stripe_session_url}
POST /webhook/stripe
Stripe webhook handler
POST /recovery/retrieve
Body: {email, password}
Returns: {encrypted_privkey_blob}
GET /subscribers
(Build-time, requires BUILD_SECRET)
Returns: {pubkeys: [...]}
Tech Stack
Microservice
- Cloudflare Workers: Edge-deployed API handlers
- Durable Object with SQLite: Single-writer consistency, familiar query interface
- Location:
api/directory in this repo
┌─────────────────────────────────────────────┐
│ Cloudflare Workers │
│ (stateless edge handlers for all routes) │
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Durable Object: MembershipDB │
│ ┌─────────────────────────────────────┐ │
│ │ SQLite │ │
│ │ - members (pubkey, name, balance) │ │
│ │ - visits (pubkey, date) │ │
│ │ - purchases (pubkey, amount, ts) │ │
│ │ - cosmetics (pubkey, item) │ │
│ │ - recovery (pubkey, email, blob) │ │
│ └─────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
Build Integration
New management command: python src/manage.py encrypt_subscriber_content
build-django-site: sync-django encrypt-subscriber-content
cd src && python manage.py distill-local --force ../web
Secrets Management
Secrets stored in repo, encrypted to maintainer age keys:
File: secrets/build.age
Contains:
BUILD_SECRET=...
GROUP_KEY=AGE-SECRET-KEY-1...
Encrypted to maintainers listed in maintainers.txt:
# Danny
age1...
# CI runner
age1...
Usage:
export $(age -d -i ~/.age/key.txt secrets/build.age | xargs)
make build-django-site
If compromised: Regenerate secrets, re-encrypt, rebuild (re-keys all subscriber content).
Components
| Component | Tech | Location |
|---|---|---|
| Identity JS library | TypeScript + typage | assets/js/identity.js |
| Meta-right dropdown | HTML/CSS/JS | Django templates |
| Profile page shell | Static HTML + JS | /profile/ |
| Recovery page | Static HTML + JS | /recover/ |
| Microservice | CF Workers + DO + SQLite | api/ |
| Build encryption | Python + age CLI | Django management command |
| Name generator | Python + data files | assets/names/ |
Future Considerations
- Passkeys: Could replace email+password recovery (PRF extension for non-custodial)
- Lightning payments: Add as alternative to Stripe
- Additional cosmetics: Badges, themes, collectible dingbats
- Spritely migration: Durable Object maps to ocap actor pattern
Addendum (2026-01-17): Makefile commands were reorganized. build-django-site → build, serve-api → api. The membership API was ported from Cloudflare Workers/Durable Objects to FastAPI on a self-hosted VM.