Add runnable node, HTTP API, all-devices revocation and reconnect sync

- cmd/node: init (recovery phrase onboarding), run, recover
- api: public reads of canonical signed records, token-protected writes
- identity: RevokeAll voids every device certified before a cutoff, so
  recovery works with only the phrase; store purges by certificate age
- p2p: redial bootstrap peers, sync on every new connection (in-flight
  guard only), validate bootstrap addresses up front
- docs: API, recovery semantics, peer-ID change on recovery

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 18:03:46 +01:00
co-authored by Claude Sonnet 5.5
parent d3efe5a3a7
commit 918e16ed37
18 changed files with 1550 additions and 82 deletions
+60
View File
@@ -467,3 +467,63 @@ func TestPersistence(t *testing.T) {
t.Fatalf("listing lost after reopen: %v", err)
}
}
func TestRevokeAllRecovery(t *testing.T) {
e := newEnv(t)
mine := e.listing(t, nil)
e.put(t, mine)
// Recovery on a new machine: only the phrase is known. Everything issued
// before the cutoff is void; the replacement device is enrolled at the cutoff.
cutoff := e.now
rev, err := identity.RevokeAll(e.root, cutoff, difficulty)
if err != nil {
t.Fatal(err)
}
if o, err := e.s.PutRevocation(ctx, rev); err != nil || o != Inserted {
t.Fatalf("PutRevocation = %v, %v", o, err)
}
if _, err := e.s.Get(ctx, mine.Author, mine.ID); !errors.Is(err, ErrNotFound) {
t.Fatal("listing of an older device survived the revocation")
}
// The old device can no longer publish, not even a fresh listing.
if _, err := e.s.Put(ctx, e.listing(t, nil)); !errors.Is(err, ErrRevoked) {
t.Fatalf("old device accepted: %v", err)
}
// The replacement device (issued at the cutoff) works.
fresh, err := identity.Enroll(e.root, cutoff, 90*24*time.Hour)
if err != nil {
t.Fatal(err)
}
e.dev = fresh
again := *mine
again.Seq = 2
if err := again.Seal(fresh, difficulty); err != nil {
t.Fatal(err)
}
if o := e.put(t, &again); o != Inserted {
t.Fatalf("republish from the new device: %v", o)
}
// An older cutoff must not replace a newer one, and a repeat is ignored.
if o, _ := e.s.PutRevocation(ctx, rev); o != Ignored {
t.Fatalf("duplicate all-devices revocation: %v", o)
}
stale, _ := identity.RevokeAll(e.root, cutoff.Add(-time.Hour), difficulty)
if o, _ := e.s.PutRevocation(ctx, stale); o != Ignored {
t.Fatalf("older cutoff replaced a newer one: %v", o)
}
// Other identities are unaffected.
otherRoot, _, _ := identity.NewRoot()
otherDev := newDevice(t, otherRoot)
theirs := e.listing(t, nil)
if err := theirs.Seal(otherDev, difficulty); err != nil {
t.Fatal(err)
}
if o := e.put(t, theirs); o != Inserted {
t.Fatalf("someone else's listing blocked: %v", o)
}
}