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
+37 -6
View File
@@ -15,9 +15,12 @@ const (
)
// Revocation voids a device: every signature made by Device is rejected from
// now on. Nodes keep it until the device's certificate would have expired
// anyway (CertExpiresAt). It carries proof-of-work so nobody can flood the
// network with revocations for throwaway identities.
// now on. With Device empty it voids every device of Author whose certificate
// was issued before RevokedAt, which is what recovery on a new machine needs:
// the owner only has the phrase, not the old device's key. Nodes keep it
// until the certificates it covers would have expired anyway
// (CertExpiresAt). It carries proof-of-work so nobody can flood the network
// with revocations for throwaway identities.
type Revocation struct {
Version int `json:"v"`
Author string `json:"author"`
@@ -44,13 +47,27 @@ func Revoke(root *Identity, cert *Cert, at time.Time, difficulty int) (*Revocati
if root.PublicKeyHex() != cert.Author {
return nil, errors.New("identity: cert does not belong to this identity")
}
r := &Revocation{
return mineRevocation(root, &Revocation{
Version: RevocationVersion,
Author: cert.Author,
Device: cert.Device,
RevokedAt: at.Unix(),
CertExpiresAt: cert.ExpiresAt,
}
}, difficulty)
}
// RevokeAll voids every device certified before at. Enroll the replacement
// device with the same timestamp: certificates issued at or after at stay valid.
func RevokeAll(root *Identity, at time.Time, difficulty int) (*Revocation, error) {
return mineRevocation(root, &Revocation{
Version: RevocationVersion,
Author: root.PublicKeyHex(),
RevokedAt: at.Unix(),
CertExpiresAt: at.Add(MaxCertLifetime).Unix(), // older certs all expire before this
}, difficulty)
}
func mineRevocation(root *Identity, r *Revocation, difficulty int) (*Revocation, error) {
for ; ; r.PoW++ {
b, err := r.signingBytes()
if err != nil {
@@ -63,12 +80,26 @@ func Revoke(root *Identity, cert *Cert, at time.Time, difficulty int) (*Revocati
}
}
// AllDevices reports whether r covers every earlier device of the author.
func (r *Revocation) AllDevices() bool { return r.Device == "" }
// Covers reports whether r voids the device certified by c.
func (r *Revocation) Covers(c *Cert) bool {
if r.Author != c.Author {
return false
}
if r.AllDevices() {
return c.IssuedAt < r.RevokedAt
}
return r.Device == c.Device
}
// Check verifies structure, signature and proof-of-work.
func (r *Revocation) Check(difficulty int) error {
if r.Version != RevocationVersion {
return errors.New("identity: unsupported revocation version")
}
if !isHex(r.Author, 64) || !isHex(r.Device, 64) {
if !isHex(r.Author, 64) || (r.Device != "" && !isHex(r.Device, 64)) {
return errors.New("identity: revocation keys must be 64 hex characters")
}
if r.PoW > 1<<53-1 {