Credentials and tickets
Shows: the proof-carrying message (7) · pseudonym (8) · async message for strangers (9) · write once (15)
Goal
An issuer gives a person a badge, which the person later shows to a venue. The venue learns that the badge is real and which issuer gave it, and nothing else about who shows it: the holder hides among everyone that issuer gave a badge to.
Actors
| Actor | What it holds | Placement |
|---|---|---|
(issuer, badges) | nothing; it only issues | public |
(holder, badges): a badge | which issuer gave it | private, on the holder’s account |
| a venue | its own business | public, any program |
Messages
enum Message {
/// To the issuer's actor, by the issuer.
Issue { to: AccountId },
/// Between badge actors: "you now hold a badge from me".
Badge,
/// To a badge, by its holder.
Show { venue: Actor },
}
/// What the venue receives.
struct Attested { issuer: AccountId }
Handler
fn handle_message(input: &ReceiveInput, message: Message) -> Response {
let me = input.receiver;
match message {
Message::Issue { to } => {
assert!(input.is_authorized() && input.from.is_none(), "only the issuer issues");
Response::keep_state().send_async(Actor::new(to, me.program_account_id), &Message::Badge)
}
Message::Badge => {
let issuer = input.from.filter(|_| input.from_own_program()).expect("not a badge");
Response::set_state(write_once(&input.pre_state, encode(&issuer.account_id)))
}
Message::Show { venue } => {
assert!(input.is_authorized() && input.from.is_none(), "only the holder shows");
let issuer: AccountId = decode(&input.pre_state);
Response::keep_state().send_sync(venue, &Attested { issuer })
}
}
}
The venue’s side is two checks. Anyone can run Issue on their own account and become an issuer, so the venue decides which issuers it trusts:
let badge = input.from.expect("an attestation has a sender");
assert_eq!(badge.program_account_id, BADGES_PROGRAM, "not from a badge");
let Attested { issuer } = decode(&input.message);
assert!(TRUSTED_ISSUERS.contains(&issuer), "not an issuer this venue trusts");
How it runs
- Issue. The issuer’s actor sends
Badgeto the holder’s address as an async message. The issuer is public, so the message is published in the clear, and the holder’s address needs its recovery binding on chain first, or the issue is charged and reverted withUnboundAsyncDestination. - Collect. The holder’s badge actor stores the issuer. It accepts
Badgeonly from the badges program. - Show. The holder sends
Showin a private transaction. The badge sends a SyncMessage to the venue under a blinded address, which the reference wallet draws fresh for each message. - Admit. The venue sees a message from the badges program naming an issuer it trusts.
Why the venue can believe it
The only code that sends Attested is the Show arm, and it sends the issuer it read from its own state. That state can only have been written by the Badge arm, which only accepts the badges program as sender. The issue ran publicly on the sequencer; for a private holder, the collection and the show ran inside the holder’s proofs.
The venue checked no signature and no membership proof, only which program spoke, so any program can accept badges without knowing how they are stored.
Public and private
| Holder | What the venue learns |
|---|---|
| Private | “a badge from this issuer”, from a one-time address |
| Public | the same, and who you are |
What leaks
- At issue time: that the issuer gave a badge to an address.
- At show time: the venue, the issuer, the time.
- Not revealed: which badge it was, or a link between two visits, since the reference wallet presents a fresh blinded address for each show (timing aside). A holder that presents the same address twice links those visits.
Going further
- Tickets. Add a
usedflag to the badge state and set it inShow, so the badge works once. - Rate limits. Keep a counter per day in the badge state and refuse
Showpast the limit. Because every run starts from the account’s real latest state, the limit cannot be exceeded, however the holder arranges their transactions. This limits actions that go through the chain. For messages that never touch it, see Rate-limiting nullifiers. - Attributes. Store a birth date in the badge and have
Showsend onlyAgeAtLeast(18), computed inside the proof. - What does not work: asking about someone else. A venue cannot query whether a private holder holds a badge; only the holder can show it.