IF Commons GitHub

logical/roster

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0007-anyfs-cli-keys FR-003, 0007-anyfs-cli-keys FR-004, 0007-anyfs-cli-keys FR-005, 0007-anyfs-cli-keys FR-006

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"

Source: commons/anyfs-cli/src/logical/roster.ts

2 of 7 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

KeyStatetypeno test imports it
type KeyState = "active" | "expired" | "future";

What a key is at a time.

keyStatefunction
function keyState(entry: KeyEntry, at: number): KeyState

What a key is at at (milliseconds): its window is closed at both ends.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Takentypeno test imports it
type 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.

takeEntriesfunction
function 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.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Rotatedtypeno test imports it
type 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 it
function 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 it
function entryLine(e: KeyEntry, at: number): string

One line of a roster, for a person.

Titles, headings, exports, tables, columns and requirements. Esc closes.