AtServerAtKeysIo class

An enrollment's @keys, held as one sealed document on the atServer.

write creates the document and refuses when one exists. flush and update replace it: each re-reads the stored document just before writing and refuses a candidate that drops anything stored; they then write, read the document back and compare it with what was written. flush creates the document when there is none; update never does. Nothing is merged and no put is retried.

Three refusals stop the store, after which it accepts no more writes: a candidate that drops stored material, a candidate holding private authentication material other than the pair, and a read-back that is absent, cannot be opened or differs from what was written. Any other failure leaves it usable: a document that already exists for write, keys or an atSign other than the store's, a closed store, a lock it could not take or keep, and a lock take, get or put that throws.

Writes on one instance run one at a time: write, flush and update each run whole, from the lock to the read back, before the next starts, so overlapping calls queue instead of interleaving, and a call that throws does not stop the ones queued behind it.

Several writers may share an enrollment, so every write holds the enrollment's lock on the atServer, taken through EnrollmentDocumentStore.tryLock, from before it reads the stored document until it puts. A writer that finds the lock held tries again after a pause of a quarter to one second, chosen at random, until it takes it or its wait bound runs out, which throws AtServerAtKeysLockedException. When its own last lease is too short to reuse, it first waits until the atServer has let that lock go: what is left of the lease, under half the ttl, plus the time its take took to be answered. The bound starts after that. A put needs at least half the lock's ttl left on its lease, measured by the lease's own stopwatch, and a lease serves this store's later writes only while that much is left. When less is left by the time the document is sealed, nothing is put: the write takes the lock again and starts over from a fresh read, running an update's mutate again, with at most three leases in all. Every update builds its candidate on the document it read under the lock, so it keeps what another writer filed. The lock is not a fence: the margin leaves a put half the ttl to land, but one that takes longer can land after the lock expired, and then it and the put of the next writer to take the lock can each drop what the other added, whichever lands last. The refusal below does not catch that, since the overwriting writer's last read predates the put it overwrites, and the overwritten writer's read-back catches it only when the overwrite lands first; otherwise both writes report success. The margin is the only guard that prevents it.

A write that would drop stored material is refused, and each write is read back and compared with what was written.

The lock needs an atServer from p3.13.0, the first to parse :nc. An expired lock stops blocking at once from p3.16.5. Another enrollment of the atSign cannot create or delete the lock record from p3.15.0, and a connection with the atSign's legacy keys cannot from p3.16.5. A CRAM-authenticated connection can until p3.19.0.

The document never holds the enrollment's APKAM private key: a passkey enrollment derives the pair from the passkey and the atServer must not keep it. This store is given that derived pair instead. Every document it seals is stripped of the flat APKAM private key, every typed privateAuthentication material and the pair's own public half, so what is read back and compared is the stripped form. A candidate that holds active private authentication material other than the pair (a rotation, a retrofit) is refused with AtServerAtKeysWriteException, never stripped silently.

Once the first document is held, read does no I/O: it serves the last document this store decoded or wrote, as fresh keys each call, with the pair filed as the enrollment's authentication material. That is what lets the client re-authenticate (reconnect, sync, monitor) from its key store without a round trip to the atServer it is trying to reach. The held document is refreshed by this store's own update, flush and write; another writer's change shows on the next update or reopen. The pair is held as bytes, encoded on each read and zeroed by close; a read after close throws StateError.

The store holds atSign's document only: every call naming another atSign throws ArgumentError.

The store seals and opens through the two functions it is given, and reaches nothing else of whatever holds the sealing key.

Inheritance

Constructors

AtServerAtKeysIo({required EnrollmentDocumentStore documents, required String atSign, required Future<String> seal(Map<String, dynamic> document), required Future<Map<String, dynamic>> open(String record), required String enrollmentId, required ApkamKeyPair apkamKeyPair, AtKeys? restored, Duration lockTtl = const Duration(seconds: 10), Duration lockWait = const Duration(seconds: 15)})
The store of enrollmentId's document for atSign through documents, sealed by seal and opened by open, holding apkamKeyPair; a restored document is served by read without I/O. Each take of the lock lasts lockTtl, and a write waits up to lockWait to take it, counted from when the atServer has let this store's own last lock go.

Properties

assurance → AtKeysAssurance
finalinherited
hashCode → int
The hash code for this object.
no setterinherited
holdsPrivateKey → bool
Whether any byte of the APKAM private key this store holds is non-zero. Reveals nothing about the key; tests use it to observe that close wipes it.
no setter
lockWaitBound → Duration
The longest one write waits for the enrollment's lock, not counting the atServer's answers: for each of its leases, up to the lock's ttl for this store's own last lease to lapse and then up to the write's wait for another writer's to.
no setter
passphraseCodec → AtKeysPassphraseEnvelopeCodec
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
settled → Future<void>
Completes when every write queued on this store so far has ended, whether it succeeded or failed. Never fails.
no setter

Methods

checkWritable(String atsign) → Future<void>
Throws unless write could create atsign's keys in this store now; the default checks nothing.
inherited
close() → void
Zeroes the APKAM private key this store holds. Idempotent. A later read throws StateError; a later or queued write, flush or update throws AtServerAtKeysWriteException without touching the atServer.
describeSource(String atsign) → String
Where atsign's keys are kept, in words a message shows in brackets after "the AtKeys store", such as a keyfile's path or "this device's keychain", or empty when the store has nothing more specific to say.
inherited
flush(Atsign atsign, AtKeys atKeys) → Future<void>
Persists atKeys as the complete new state for atsign.
override
keepsAllOf(String atsign, AtKeys atKeys) → Future<bool>
Whether the stored document holds everything atKeys holds. False when atKeys holds anything the stored document lacks; the store stays usable either way. Throws when there is no document or it cannot be opened.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(String atsign) → Future<AtKeys>
The keys of atsign's document with the derived APKAM pair filed. The first read of a store that was not seeded goes to the atServer; every later one is served from memory, as keys the caller may change.
override
toString() → String
A string representation of this object.
inherited
update(Atsign atsign, FutureOr<bool> mutate(AtKeys keys)) → Future<void>
Reads atsign's keys, applies mutate to them, and persists the result — as one operation.
override
write(String atsign, AtKeys atKeys) → Future<void>
Create-only initial persist (fresh onboard); implementations throw if the target already exists. Use flush to persist later mutations.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited