Skip to content

Proposal: a teller for Web Ledgers — deposits, withdrawals and signed transfers #7

Open

Description

@melvincarvalho

Summary

Web Ledgers says what balances are: a document mapping URIs to amounts. It deliberately leaves out how balances change, who may change them, and how value comes in from a chain and goes back out. Almost every application that holds value for its users (a game, a tipping page, a shop, a sidechain) rebuilds that same missing piece.

This issue proposes a small, generic, standalone component for it, a teller for Web Ledgers:

  • deposit: each account gets its own on-chain address; a confirmed payment to it credits the account;
  • withdraw: an account holder asks, by a signed request, to be paid out to an address; the teller debits the account and pays;
  • transfer: an account holder moves part of their balance to another account, by a signed request.

An application then uses four calls (depositLink, balance, transfer, withdraw) and never touches keys or a chain.

Why here

The spec defines the data and says implementations SHOULD authenticate updates. A reference teller would show one complete, interoperable way to do that, in the same open format, without changing the spec itself. Applications could then share it instead of each writing their own, often with subtle mistakes in exactly the parts that move money.

The design

1. The ledger

A Web Ledger as it is today. The currency is a setting, with amounts as integer strings in the currency's smallest unit (no floating point). Accounts are did:nostr:<hex pubkey> (see #6), so anyone with a Nostr key has an account without signing up.

{
  "@context": "https://w3id.org/webledgers",
  "type": "WebLedger",
  "id": "https://example.org/ledger.json",
  "name": "Example table",
  "defaultCurrency": "txbt4",
  "updated": 1759300000,
  "entries": [
    { "type": "Entry", "url": "did:nostr:de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645", "amount": "250000" }
  ]
}

One operator writes the ledger. Anyone can read it.

2. Deposits: one address per account, derived rather than stored

The operator has one key pair (d, P). An account's deposit address is a taproot output whose key is P tweaked by a commitment to the account:

state = { "ledger": <ledger id>, "account": <did:nostr:…>, "nonce": <n> }
t     = int( tagged_hash("TapTweak", x(P) || sha256(JCS(state))) ) mod n
Q     = P + t·G          address = P2TR( x(Q) )

This is the same tweak as the Blocktrails Monochrome profile (https://blocktrails.org/spec/profiles.html). As a result:

  • Nothing to store: the teller keeps no table of addresses. Given P and the state, anyone can recompute the address and check which account a payment was for.
  • Only the operator can spend the deposit, with d + t. BIP 340 parity handling applies only at signing.
  • A fresh address per deposit: nonce gives one, for privacy or to tell two deposits apart.

A deposit is credited once, after a set number of confirmations, and is reversed if a reorganisation removes it before then.

To ask for a deposit, the teller hands out a BIP 21 request: bitcoin:<address>?amount=<coins>&label=<text>. Any wallet that reads BIP 21 can pay it.

3. Withdrawals and transfers: signed requests

The account holder signs a Nostr event with the key behind their did:nostr:

{ "kind": <tbd>, "tags": [["ledger", "<ledger id>"], ["op", "withdraw"], ["amount", "100000"], ["to", "<address>"], ["id", "<unique request id>"]], "content": "" }
  • A transfer uses ["op", "transfer"] and ["to", "did:nostr:…"].
  • The teller checks:
    • the signature;
    • that the account is the signer;
    • the balance;
    • that the request id has not been seen before (a request is applied at most once).
  • Then it acts:
    • it debits the account;
    • for a withdrawal, it pays the address from its deposits, signing each spent output with that deposit's tweaked key.

Withdrawals can start manual: the teller queues them, and the operator approves each one. That keeps custody risk small while the rest is proven.

4. The chain behind an interface

depositAddress(account, nonce) → address
scan() → [{ account, nonce, txid, vout, value, confirmations }]
pay(address, value) → txid

A first backend can use any chain with taproot. Bitcoin (through Esplora or a node) and test chains differ only in this layer.

5. Optional: anchoring the ledger

Each new version of the ledger can be committed on-chain as the next state of a Blocktrails trail (sha256(JCS(ledger))). Anyone can then check that the ledger they are shown is the one the operator committed. Without this the ledger is still useful, but readers trust the operator's copy.

Trust model, stated plainly

This is custodial. The operator holds the deposits and writes the ledger, and could refuse a withdrawal or alter a balance. The design keeps that visible and checkable:

  • every deposit can be traced to an account from public data;
  • every change is a signed request, or a deposit seen on-chain;
  • with anchoring, the ledger's history is fixed on-chain.

It does not remove the operator. A federation or threshold key in place of the single key P is a later step, and the interface allows it.

Non-goals

  • Changing the Web Ledgers data model.
  • Lightning (it could be a second backend later).
  • Prices, exchange between currencies, or anything beyond moving one currency in, around and out.

A first implementation

A small standalone page plus an operator process, published on GitHub Pages:

  • the ledger;
  • sign-in with a Nostr key;
  • balance and history;
  • a deposit address with its BIP 21 link and QR;
  • a withdraw form.

The first currency is a test chain's coins, so nothing of value is at risk while it is proven. The first user would be a game that needs buy-ins and cash-outs without a rake.

Open questions

  1. Where the ledger is published: a file in a repository, a Nostr replaceable event signed by the operator, or both.
  2. Event kinds for withdraw and transfer requests, and for the teller's receipts.
  3. Confirmations: how many before a deposit is credited, per currency.
  4. Deposits under the minimum: too small to spend economically. Credit them, or hold them until they add up?
  5. Naming: "teller", or something else.

Comments welcome before any code is written.

Activity

  1. melvincarvalho commented on Oct 1, 2026

    @melvincarvalho
    ContributorAuthor

    Update to section 2 (deposits): the key rule settled since, and what the tweak commits to

    Since this was written, the arithmetic behind "one address per account by tweak" has been settled and tested in one place, and the chain's identity has become a 32-byte hash. Section 2 should change in three ways.

    1. The tweak is added to the full point, never its even-y lift

    The proposal said "tweaked by a commitment to the account" with a BIP 341 tagged hash. Keep the hash, but not BIP 341's derivation, which lifts the key to its even-y point before every tweak. The rule the ecosystem now shares (sidestr/spec siding/lib/keys.mjs, #27; the did:nostr explainer, nostrcg/did-nostr#144; Blocktrails, blocktrails/spec#5):

    • Keys are full compressed points (02/03 + x); a did:nostr identifier names the even-y point 02 + x, and the operator normalises the secret once (n − d if its point is odd-y) so that it is exactly theirs.
    • A tweak is plain addition: d + t ↔ P + t·G, on the point as it is. The result's parity is whatever it is.
    • x-only only at the edge: the deposit address is x(Q), and a BIP 340 signature uses the sign it needs inside the signing.

    Under this rule the operator's private and public derivations agree at every address, whatever the parity of any point along the way, and anyone with the operator's base point can recompute every deposit address and tell which account a payment was for.

    2. What the tweak commits to: a fixed-width layout, with the ledger as a hash

    t = taggedScalar("webledgers/deposit", ledgerHash32 || account32 || nonce8)
    Q = P + t·G             P: the operator's base point, as it is
    address = P2TR(x(Q))
    
    • ledgerHash32: a 32-byte hash that only this ledger has, never its name or URL (two operators can both call a ledger "poker"). For a ledger published as a signed Nostr event, its event id; for a file, the sha256 of its canonical (JCS) bytes at creation. This is the same slot the sidestr peg-in form uses for the chain's hash (sidestr/spec#23, #24).
    • account32: the did:nostr x of the account holder (32 bytes).
    • nonce8: distinguishes deposits for one account; 0 when one address per account is wanted.
    • Fixed widths, no delimiters, so no two inputs collide by ambiguity; a tag that names the scheme, so the same data under another scheme (a sidestr peg-in, a Blocktrails state) gives another address.

    With keys.mjs: K.tweakPoint(P, K.taggedScalar('webledgers/deposit', ledgerHash, account, nonce)).

    3. The honest limits of this form

    • A hardware wallet cannot sign these. Devices reproduce only BIP 341 key-path and script-tree outputs from a BIP 32 key, and this is a plain additive tweak on an arbitrary point. That is fine for the teller as proposed (one operator, test coins, a hot key that sweeps deposits). If an operator later wants device-held custody, the sidestr peg-in form (pegtweak.mjs, sidestr/spec#31) is the alternative: a real BIP 341 output whose tree holds a refund leaf and a pk(C) commitment leaf, derivable and signable by a device from an xpub. The teller's interface (depositAddress, scan, pay) is the same either way.
    • One leaked derived secret leaks the base key, since the tweaks are public. The operator holds every key, so this costs nothing here; it rules out ever handing a derived secret to anyone.
    • Anyone who knows the base point can link all of a ledger's deposit addresses. For a verifiable ledger that is the point; it is not a privacy design.

    Nothing else in the proposal changes

    Sections 1, 3, 4 and 5 (the ledger, signed requests, the chain interface, anchoring) stand as written. Anchoring with Blocktrails now has the same arithmetic as the deposits, which is one less thing to get right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions