Manual
Almnck.
Price: 50ⓐ

Membership API

The Almanack membership system provides client-sovereign identity with whimsical names, visit tracking, an almanickel balance, and Stripe-powered top-ups.

Overview

Members are identified by an Ed25519 keypair stored in their browser’s localStorage. Each member receives a randomly generated whimsical name (e.g., “Captain Dmitri Winklebottom”) and accumulates visits that debit almanickels from their balance. Members can top up their balance via one-time or recurring Stripe payments.

Key features: - Client-sovereign identity (keypair in browser, no account creation) - Ed25519 signature verification on all authenticated requests - Daily visit tracking with streak counting - 50 almanickels debited per unique visit day - Stripe checkout for one-time and recurring top-ups

Architecture

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  Browser        │────▶│  FastAPI         │────▶│  SQLite         │
│  identity.js    │     │  api/main.py     │     │  members.db     │
│  topup.js       │◀────│  (verify sig)    │◀────│                 │
│  (Ed25519 sign) │     │                  │     │                 │
└─────────────────┘     └────────┬─────────┘     └─────────────────┘
                                 │
                        ┌────────▼─────────┐
                        │  Stripe          │
                        │  (checkout +     │
                        │   webhooks)      │
                        └──────────────────┘

Components: - api/ — FastAPI application with Ed25519 signature verification and Stripe integration - assets/js/identity.js — Client identity library (keypair, signing, API calls) - editorial/margin-boxes/identity/assets/code.js — Identity widget margin box module - assets/js/topup.js — Checkout flow on the /topup/ page - assets/names/ — Name generation data (titles, firstnames, surnames)

Local Development

Running the API

source bin/a-activate

# Start FastAPI on port 8000
make api

Running the Website

In another terminal:

make serve    # Django dev server on port 1969

The dev server runs on port 1969; visit http://localhost:1969/ to see the identity widget in the left margin with your generated name.

Testing the API

# Health check
curl http://localhost:8000/health

# Register (returns whimsical name)
curl -X POST http://localhost:8000/register \
  -H "Content-Type: application/json" \
  -d '{"pubkey":"age1test","signing_pubkey":"<64-char-hex>"}'

# Visit requires valid Ed25519 signature
curl -X POST http://localhost:8000/visit \
  -H "Content-Type: application/json" \
  -d '{"pubkey":"age1test","timestamp":"2026-01-17T12:00:00Z","signature":"<128-char-hex>"}'
make test-api         # API container tests
make test-checkout    # Stripe checkout integration

API Endpoints

GET /health

Returns {"status": "ok"}.

POST /register

Register or retrieve a member.

Request:

{
  "pubkey": "age1...",
  "signing_pubkey": "<64-char-hex-ed25519-pubkey>"
}

Response:

{
  "name": "Captain Dmitri Winklebottom",
  "balance": 0,
  "streak": 0
}

If the member already exists, returns their current profile. If signing_pubkey is provided and the member lacks one, it is updated.

POST /visit

Record a visit (requires valid signature). Debits 50 almanickels per unique calendar day.

Request:

{
  "pubkey": "age1...",
  "timestamp": "2026-01-17T12:00:00.000Z",
  "signature": "<128-char-hex-ed25519-signature>"
}

The signature must be over the message almanack:v2:<METHOD>:<path>:<timestamp> — e.g. almanack:v2:POST:/visit:<timestamp>. Binding the method and path means a signature made for one endpoint cannot be replayed against another.

Response:

{
  "balance": -50,
  "streak": 1,
  "debited": true
}

Same-day visits return "debited": false without further debit.

POST /me

Retrieve member profile (requires valid signature).

Request:

{
  "pubkey": "age1...",
  "timestamp": "2026-01-17T12:00:00.000Z",
  "signature": "<128-char-hex-ed25519-signature>"
}

Response:

{
  "name": "Captain Dmitri Winklebottom",
  "balance": -50,
  "streak": 1
}

POST /checkout

Create a Stripe checkout session (requires valid signature).

Request:

{
  "pubkey": "age1...",
  "timestamp": "2026-02-21T14:30:00Z",
  "signature": "<128-char-hex>",
  "amount": 5000,
  "recurring": "monthly"
}

recurring is optional — omit for one-time purchase.

Valid amounts:

Almanickels Price Type
1,000 $1 One-time
5,000 $4 One-time
10,000 $7 One-time
14,000 $7/month Recurring

Response:

{
  "stripe_session_url": "https://checkout.stripe.com/..."
}

The client redirects to this URL. On completion, Stripe fires a webhook to credit the balance.

POST /webhook/stripe

Receives Stripe webhook events. Verifies the signature header against the configured webhook secret.

Handled events: - checkout.session.completed — credits almanickels to the member’s balance. For recurring purchases, stores the subscription ID on the member. - invoice.paid — processes subscription renewals (only billing_reason: "subscription_cycle"). Credits the recurring almanickel amount.

All events are recorded in the WebhookEvent table for idempotency — duplicate events are silently skipped.

Signature Verification

All authenticated endpoints require Ed25519 signatures:

  1. Client derives signing keypair from identity seed using HKDF-SHA512 (info: "almanack-ed25519-signing-key")
  2. Client signs almanack:v2:<METHOD>:<path>:<ISO-timestamp> for the exact endpoint it is calling.
  3. Server verifies signature using PyNaCl and checks timestamp (±5 min tolerance)
  4. Server rejects if signature invalid or timestamp expired

The signature binds the endpoint, and the identity is self-certifying (the pubkey is derived from the signing key), so a valid signature proves the caller holds the signing key for that pubkey and intends that specific endpoint — no passwords, no sessions.

Client Integration

The identity system is loaded in base.html:

<!-- Vendored Noble crypto libraries for Ed25519 -->
<script src="/static/js/vendor/noble-hashes.min.js"></script>
<script src="/static/js/vendor/noble-ed25519.min.js"></script>
<script>
  window.nobleHkdf = nobleHashes.hkdf;
  window.nobleSha512 = nobleHashes.sha512;
</script>

<!-- Identity library -->
<script src="/static/js/identity.js" defer></script>
<script src="/static/js/interactive-margin-boxes.js" defer></script>

The API URL is configured via a meta tag:

<meta name="almanack-api" content="https://api.almnck.com">

Identity Widget (Masthead Stamp)

The identity widget is an interactive margin box at editorial/margin-boxes/identity/ with placement: masthead. During layout init, sidenotes.js extracts masthead-placement boxes and moves them into the #masthead-identity container in base.html:

<div id="masthead-identity" class="masthead-stamp">
  <!-- identity margin box is placed here -->
</div>

The box’s assets/code.js module is loaded by interactive-margin-boxes.js via the standard convention. It: 1. Populates the stamp with cached profile data from localStorage 2. Initializes the identity system (register/visit API calls) 3. Listens for almanack:profile-updated events to update the display

The masthead chrome is identical across pages, so cross-document View Transitions render the stamp continuously across navigations. The masthead placement works on all viewport widths, including mobile where margins are hidden.

JavaScript API

// Initialize (auto-generates keypair if needed)
await Identity.init();

// Get member info
Identity.getName();      // "Captain Dmitri Winklebottom"
Identity.getBalance();   // -50
Identity.getStreak();    // 1

// Record a visit
await Identity.visit();

// Sign a message
const sig = await Identity.sign("my message");

Storage keys: almanack:identity (secret key), almanack:profile (cached JSON).

Top-up Page

The /topup/ page (topup.js) handles checkout: 1. Shows cached profile and balance immediately 2. On button click, signs a timestamp and calls POST /checkout 3. Redirects to the Stripe checkout URL 4. On return, shows success/cancel status and refreshes the balance

Database Schema

CREATE TABLE member (
  pubkey TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  balance INTEGER DEFAULT 0,
  created_at TIMESTAMP,
  last_visit DATE,
  streak INTEGER DEFAULT 0,
  signing_pubkey TEXT,
  stripe_subscription_id TEXT,
  recurring_almanickels INTEGER DEFAULT 0
);

CREATE TABLE visit (
  id INTEGER PRIMARY KEY,
  pubkey TEXT REFERENCES member(pubkey),
  visited_on DATE,
  page_type TEXT DEFAULT 'article'
);

CREATE TABLE transaction (
  id INTEGER PRIMARY KEY,
  pubkey TEXT REFERENCES member(pubkey),
  stripe_event_id TEXT,
  amount INTEGER,
  transaction_type TEXT,  -- 'purchase', 'subscription_initial', 'subscription_renewal'
  created_at TIMESTAMP
);

CREATE TABLE webhookevent (
  stripe_event_id TEXT PRIMARY KEY,
  event_type TEXT,
  processed_at TIMESTAMP
);