There is a reason an unattended locker asks for coins. The machine has no way to bill you later. The door opens, the person walks off, and that is the end of it. No name, no contact. So it has to be paid now.
But the phone in that person's hand already has a way to be billed. The payment method is attached to the person, and the person still exists after leaving. That removes the machine's reason to hold on to the fare. One job remains: deciding whether it may open.
I built a board that makes that decision with no internet. It is a single STM32H723 on USB, and an onboard LED opens and closes in place of a door. Below is how the verification logic was written, and what it caught on along the way.
The machine receives a voucher, not money
Payment has already finished on the service side, and the machine receives a signed statement of that result. It has six fields.
| Field | What it says |
|---|---|
deviceId | which machine this is for |
action | what to do (locker-4h) |
notBefore / notAfter | from when to when |
target | which slot on that machine (B12) |
session | the serial number of this voucher |
sig | an Ed25519 signature over the values above |
The missing field stands out more. There is no amount. How much it cost is between the service and the person; all the machine knows is whether to open.
The signature is not over the JSON document. It is over the six values joined in a fixed order as one byte string.
int n = snprintf(buf, cap, "%s\n%s\n%lu\n%lu\n%s\n%lu",
device_id, action, not_before, not_after, target, session);
Sign the JSON and a single space breaks it on re-serialisation. There is a more important reason, though: the machine rebuilds this string from the values it read and verifies against that. A field the machine ignored is not in the signed material either. There is structurally no place for what was read and what was signed to diverge.
Seven checks, in order
When a voucher arrives the machine goes through them in order. One miss is a refusal, and there is no path that opens first and confirms later.
- Are all the fields present
- Does the signature verify, with the service public key burned into flash, using Ed25519
- Is
deviceIdme - Is this an action I have declared
- Is
targetmy slot - Is
sessiongreater than the largest one accepted so far - Is now within
notBeforetonotAfter
The fourth is the heart of the design. A perfect signature is still refused if it names something this machine does not sell. The signature only says "the service issued this"; what is for sale is something the machine knows. Each node writes what it sells in an OFFERS[] table, and anything not in it gets this answer.
refused: action was never offered by this node
The sixth is how replay is blocked without internet. There is no server to ask, so the machine blocks it with its own number. It holds the largest serial number seen so far and refuses anything less than or equal to it. Storing one number is no burden even on a node with little flash to spare.
None of the seven steps calls the network. Pull the cable and the answer is the same.
Confirming that expiry really happens on its own
Everything works in words. So in the board check I granted an eight-second authority and sent nothing for twelve seconds.
b.call("voucher.present", mint("locker-demo-20s", session, seconds=8, ...))
b.call("locker.open") # → open, LED on
time.sleep(12) # send nothing
assert "expired" in b.call("locker.open")
Ask for the state after twelve seconds and this comes back.
LOCKED remaining=0s session=1 time=synced reason=authority expired
It did not close because an expiry notice arrived. The machine measured on its own clock and locked itself. Whether a server existed at that moment shows up nowhere.
This content requires Developer or above
Sign in and upgrade your plan to continue reading.
View Plans