update method

  1. @override
Future<void> update(
  1. Atsign atsign,
  2. FutureOr<bool> mutate(
    1. AtKeys keys
    )
)
override

Reads atsign's keys, applies mutate to them, and persists the result — as one operation.

This is what a caller adding key material should use, not a hand-rolled read → mutate → flush. Those three steps interleave: two of them running concurrently both read the same state, and the second flush presents a candidate missing the first's addition. flush is right to refuse it — nothing may be lost — so the outcome is a thrown assurance exception and one addition silently gone. A client's start does exactly this today, firing the namespace-key seeding and the conveyed-key filing as sibling unawaited tasks.

Implementations backed by a lockable store take the lock across all three steps. The default here does not — it is read/mutate/flush — which is no worse than the hand-rolled form it replaces, and gives every store one call to serialise later. A store that holds a pending enrollment must override it to run as one operation: an approval and a cancel each decide inside mutate, and with the default a cancel can write back a copy read before the approval was, removing the approved keys.

mutate receives the freshly-read AtKeys and mutates it in place. It returns whether anything changed: false abandons the write, which is how a caller that finds the material already there — re-delivery is the substrate's normal mode — avoids rewriting the store to say nothing. Throwing from it abandons the write too.

An implementation may run mutate more than once, each time on a fresh read, and writes only what the last run left. So mutate decides from the AtKeys it is given, and resets anything it records outside them.

This never creates. It is a read-modify-write of material that must already be there, and read throws when it is not — so an implementation that can observe its backing going away between the read and the write must refuse rather than write it back. For a keyfile that matters beyond tidiness: the file is the credential, deleting it is how a device is decommissioned, and putting it back defeats the delete.

Implementation

@override
Future<void> update(
        Atsign atsign, FutureOr<bool> Function(AtKeys keys) mutate) =>
    _serialized(() => _update(atsign, mutate));