Skip to content

fix: persist context key locally and remove dead node re-encryption#90

Merged
LiranCohen merged 1 commit into
mainfrom
fix/context-key-persistence
Feb 26, 2026
Merged

fix: persist context key locally and remove dead node re-encryption#90
LiranCohen merged 1 commit into
mainfrom
fix/context-key-persistence

Conversation

@LiranCohen

Copy link
Copy Markdown
Contributor

Summary

  • Persist context encryption key to network.json so non-anchor nodes survive DWN outages at startup. Previously, the context key was fetched from the anchor's DWN on every meshd up — if the DWN was unreachable, the node couldn't encrypt/decrypt records.
  • Remove dead node re-encryption block in cmdUp — this code attempted to re-register the node with Protocol Context encryption on every startup, but it was dead code after PR fix: use Protocol Context encryption for all records so peers can decrypt (#87, #88) #89: anchor nodes already write with context encryption in network create, and non-anchor nodes' records are created by peer add (also with context encryption). Additionally, the DWN rejects updates from non-authors, so the non-anchor path always failed silently.
  • Add cached-first pattern to acl show — same optimization: try cached context key before fetching from DWN.

Changes

File Change
internal/state/state.go Add ContextKey string field to NetworkState (base64-encoded X25519 private key)
cmd/meshd/main.go cmdNetworkJoin: persist fetched context key to network.json
cmd/meshd/main.go cmdUp: load context key from cache first, fall back to DWN fetch; persist newly fetched keys
cmd/meshd/main.go cmdUp: remove 35-line dead node re-encryption block
cmd/meshd/main.go cmdACLShow: cached-first context key loading (skip anchor, which derives via HKDF)

Verification

  • go build ./... — zero errors
  • go vet ./... — zero warnings
  • go test ./... -count=1 -race — all tests pass, no data races

- Add ContextKey field to NetworkState (base64-encoded X25519 private key)
- cmdNetworkJoin: persist fetched context key to network.json
- cmdUp: load context key from cache first, fall back to DWN fetch;
  persist newly fetched keys for subsequent startups
- cmdACLShow: same cached-first pattern for context key loading
- Remove dead node re-encryption block in cmdUp — node records are
  already written with context encryption by 'peer add' and
  'network create', and DWN rejects updates from non-authors anyway
@LiranCohen LiranCohen merged commit acd8fc7 into main Feb 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant