KeyStatetypeno test imports ittype KeyState = "active" | "expired" | "future";What a key is at a time.
The pure rules of a roster of keys (commons anyfs-cli 0007-anyfs-cli-keys FR-003 to FR-006): what a key is at a time (active, expired or future), how entries from another roster are taken in (a key id that is there already must name the same public key, a new key is taken only where it was accepted by its id, so that a roster that arrives by a channel nobody has checked adds nothing by itself), and how a key is rotated (the old key stops speaking at an instant and the new one starts at the next, so that what the old one signed before still holds). No file is read and nothing is written.
import { keyState } from "./roster.ts";
// keyState(entry, Date.now()); // "active"KeyStatetypeno test imports ittype KeyState = "active" | "expired" | "future";What a key is at a time.
keyStatefunctionfunction keyState(entry: KeyEntry, at: number): KeyStateWhat a key is at at (milliseconds): its window is closed at both ends.
Takentypeno test imports ittype Taken = {
readonly roster: KeyRoster;
/** The entries that were not there and were accepted. */
readonly added: readonly KeyEntry[];
/** The entries that were there already, as they are. */
readonly known: readonly KeyEntry[];
/** The entries that were not there and were not accepted: what a person has to check before accepting them. */
readonly pending: readonly KeyEntry[];
};What taking in the entries of another roster did.
takeEntriesfunctionfunction takeEntries(base: KeyRoster, incoming: KeyRoster, accept: ReadonlySet<string>): Result<Taken, string>The roster with the entries of another taken in. A key that is there already is kept as it is (its window is never widened by a roster that arrives), and the same key id with another public key is an error, since a key id is the digest of the key. A key that is new is added only where its id is in accept; else it is pending.
Rotatedtypeno test imports ittype Rotated = { readonly roster: KeyRoster; readonly retired: KeyEntry; readonly started: KeyEntry };A roster with a key rotated: the old key ends at at, the new one starts at the next millisecond.
rotatefunctionno test imports itfunction rotate(base: KeyRoster, keyId: string, fresh: KeyEntry, at: number): Result<Rotated, string>Rotates the key of a replica: the entry keyId of the roster stops speaking at at (it is never made to speak longer than it did), and fresh is added with a window that begins after it. The new key must be of the same replica and not be in the roster already.
entryLinefunctionno test imports itfunction entryLine(e: KeyEntry, at: number): stringOne line of a roster, for a person.