BETAThis service is in beta testing.
BuildDEV

Keeping the Verification Code in One Place and Adding Kinds of Machine

Adding a vending machine cost one config struct. The signature, replay and expiry checks were not written again, and when the attacks run against the locker were moved over unchanged, every refusal held. A domain fills in four things — target · offers · occupancy · actuate.

makemindNov 26, 2026

After the locker comes the vending machine, and after that the parking barrier. Write each machine from scratch and the holes come per machine too. The replay attack blocked in the locker is forgotten in the vending machine, and the washing machine swaps the order of two checks. Build four and you are left with four different sets of mistakes.

So the verification was written once, and each machine is asked only what it is. To give the result first: when the vending machine was added, not one line about verification was written.

What lives where

src/authority.c         719 lines   signature · replay · expiry · power loss · session window
domains/payment_locker.c 289 lines
domains/vending.c        209 lines
domains/parking.c        220 lines

Taking a voucher and checking its signature, blocking replay by serial number, measuring the window, surviving a power cut: these are the same on any machine. All of that is in authority.c. No signature, no serial number and no clock appears in a domain file.

All a domain does is fill in one struct and hand it over. This is the whole of the vending machine.

const authority_config_t cfg = {
    .device_id   = id,
    .target      = TARGET_REF,          /* "A3" — the slot */
    .offers      = OFFERS,
    .offer_count = (int)(sizeof(OFFERS) / sizeof(OFFERS[0])),
    .service_pubkey = SERVICE_PUBKEY,
    .device_privkey = DEVICE_PRIVKEY,
    .spec        = 0,
    .occupancy   = AUTHORITY_SHARED,    /* where it parts from the locker */
    .store_write = node_store_write,
    .store_read  = node_store_read,
    .actuate     = auger,               /* an auger instead of a latch */
};
authority_init(&cfg);

Keys and the store functions are board wiring and look much the same on any node. What actually differs per machine is four things. Which slot it is responsible for (target), what it sells (offers), how many people it takes at once (occupancy), and what it moves (actuate).

What is sold has a shape

offers is not a table of just action names and durations. The fourth column holds a shape.

/* locker */
{ "locker-4h",      4UL * 3600UL,  30UL, AUTHORITY_FIXED },
{ "locker-24h",    24UL * 3600UL, 120UL, AUTHORITY_FIXED },

/* parking */
{ "park-hourly",   30UL * 60UL,     0UL, AUTHORITY_RENEWING },
{ "park-flat-day", 12UL * 3600UL,  60UL, AUTHORITY_FIXED },

AUTHORITY_FIXED is an authority you use up for what you bought and then it ends; AUTHORITY_RENEWING renews itself for as long as you stay in the state. Look at the parking barrier and both are on one node. A 30-minute renewing rate and a 12-hour flat rate are sold on the same machine. That is possible because the shape is a property of the offer, not of the node.

The third column, within_s, is the session window: how long after approval the action is still allowed. The locker's four-hour pass gives 30 seconds, the day pass two minutes. Approve and then walk away and a machine with one door is stuck.

Renewing offers have a window of 0, meaning none. A window is a device for bounding the gap between approval and action, and a car that comes in at nine and leaves at five is not late for anything.

Occupancy cannot be read from the kind of action

In the table only the vending machine is SHARED, and that catches the eye. Why can the vending machine take several people at once and the locker cannot?

Because there is one door. One drum, one bay. The vending machine finishes dispensing in a few seconds and is empty again, so the person behind has nothing to wait for.

The trouble is that this cannot be derived from the action's execution type. A wash is "run once and done" and holds the drum for 42 minutes. A vend is also "do once and done" and holds nothing. Same shape, different fact. So the platform does not infer it; it asks the domain.

.occupancy = AUTHORITY_EXCLUSIVE,   /* locker · parking */
.occupancy = AUTHORITY_SHARED,      /* vending */

One thing to be exact about here. This value is a declaration, not an enforcement. A byte stream has no notion of who is speaking, so if two hosts open the same serial port they simply interleave. Domain code has no way to tell them apart. The domain's duty is to state the fact, and the place that can actually enforce it is a transport with a notion of a peer (TCP, GATT).

What the occupancy value does do is travel all the way to the screen. authority_occupancy_name() returns "exclusive" / "shared" and it goes into the manifest, so the locker writes "one person at a time" on its own page and the vending machine writes "several people at once".

This content requires Developer or above

Sign in and upgrade your plan to continue reading.

View Plans