RevocationList
A host's record of the devices it no longer lets back in on an old pass.
A host gave a friend's phone a Grant, and the phone is lost. Revoking the phone's key here, with a cutoff, makes every grant the host issued it before the cutoff worthless, so the phone cannot come back on one; GrantTrust answers GrantVerdict.Revoked for it. A grant issued at or after the cutoff still works, so a device that is welcome again simply gets a fresh pass.
Revoking voids passes; it is not a ban. A revoked device that knocks again is a newcomer, and the host's admission policy decides it like any other. A cutoff cannot be taken back, so an app that means to keep a device out keeps its own blocked set, which it can undo, and refuses on that.
Revoking stops a return on an old pass; it does not remove a device that is in the room now. That is the app's separate call.
One entry per subject key: its cutoff, notBefore. A grant with issuedAt < notBefore is revoked, and one issued exactly at the cutoff is not. The host keeps no grants, only these cutoffs, so choosing the cutoff is the caller's job: see revoke.
A cutoff only ever moves later: revoke keeps the larger of the old and new cutoffs, so a replayed or reordered call cannot move one earlier. That is all it guarantees. It does not make a cutoff read from a clock that has since stepped backwards cover the grants issued before the step.
Two ways to hold one. inMemory forgets every revocation with the process, so a revoked device comes back on its old pass after the host restarts. open keeps the list in a DurableStore, so it survives the restart. The two ways to lose state go in opposite directions: losing the store forgets every revocation, which is dangerous; losing the host's key makes every grant GrantVerdict.UntrustedIssuer, which is safe.
Safe under a multi-threaded dispatcher: one lock guards the cutoffs, and nothing suspends while it is held. A stored list also serialises its writes, below.
Samples
val host = DeviceKey.generate() // the host's own key: the only issuer it trusts
val phone = DeviceKey.generate() // a device the host let in once
val revocations = RevocationList.inMemory()
val trust = GrantTrust(host.id, revocations)
val now = 1_700_000_000_000L // epoch ms, from your clock: the check never reads one
// The phone comes back with the pass the host gave it, having proved it holds `phone`'s key.
val pass = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = now, notAfter = now + 3_600_000)
check(trust.verify(pass, phone.id, "table-7", now + 60_000) == GrantVerdict.Valid)
// The first thing wrong is the answer: another room, another device, too late.
check(trust.verify(pass, phone.id, "table-8", now + 60_000) == GrantVerdict.WrongScope)
check(trust.verify(pass, host.id, "table-7", now + 60_000) == GrantVerdict.WrongSubject)
check(trust.verify(pass, phone.id, "table-7", now + 3_600_000) == GrantVerdict.Expired)
// Too early: a pass dated more than five minutes past the clock, issued while it ran ahead.
val postDated = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = now + 600_000, notAfter = now + 3_600_000)
check(trust.verify(postDated, phone.id, "table-7", now) == GrantVerdict.NotYetValid)
// The phone is lost: revoke it. A pass issued exactly at the cutoff stays good, so the cutoff is
// one past the clock, or one issued in this same millisecond would slip through.
val lostAt = now + 120_000
val sameMillisecond = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = lostAt, notAfter = lostAt + 3_600_000)
revocations.revoke(phone.id, notBefore = lostAt + 1)
check(trust.verify(pass, phone.id, "table-7", lostAt + 60_000) == GrantVerdict.Revoked)
check(trust.verify(sameMillisecond, phone.id, "table-7", lostAt + 60_000) == GrantVerdict.Revoked)
// A fresh pass, issued after the cutoff, works again.
val fresh = Grant.issue(host, phone.id, GrantScope.Room("table-7"), issuedAt = lostAt + 120_000, notAfter = lostAt + 3_720_000)
check(trust.verify(fresh, phone.id, "table-7", lostAt + 180_000) == GrantVerdict.Valid)// The host app's store: a file, a directory, IndexedDB. In memory here.
val store: DurableStore = InMemoryDurableStore()
val lostPhone = DeviceKey.generate().id
val now = 1_700_000_000_000L
// Revoke through a list opened on the store: `revoke` returns once the list is written.
val revocations = RevocationList.open(store)
revocations.revoke(lostPhone, notBefore = now + 1) // one past the clock, as for any revocation
// The host restarts. The list it opens holds the revocation, so the lost phone's old pass stays void.
val afterRestart = RevocationList.open(store)
check(afterRestart.notBefore(lostPhone) == now + 1)