fix(identity)!: spec-conformant identifier types and a monotonic TID generator #114
Labels
No labels
breaking-change
bug
documentation
duplicate
enhancement
good first issue
help wanted
performance
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Grandiras/ATProto.NET#114
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of the v0.7.0 update cycle. The identifier types are meant to guarantee validity, but several accept invalid input. One generator produces out-of-order and duplicate TIDs.
Bugs
Tid.Next()is neither monotonic nor collision-free. 20,000 calls produced 9,992 values out of order and 22 exact duplicates, because each call addsRandom.Shared.Next(0,1024)to the millisecond timestamp. The spec requires monotonic TIDs per generator. AddTidGenerator(fixed clock id per generator,Interlockedincrement over the last µs timestamp,TimeProvider-injectable).Tid.Next()delegates to a shared instance, andRecordKey.NewTid()inherits the fix.atproto-interop-tests/syntaxfixtures. Vendor the fixtures intotests/and run every valid/invalid line. Today the SDK wrongly accepts:#fragments are accepted.@!$&'()*+,;=; the spec allows onlyA-Za-z0-9 . - _ : ~, excluding.and...234567abcdefghij.%is accepted.Cid.Parsevalidates nothing (Cid.Parse("hello")succeeds). Validate a base32-lower CIDv1 with codec0x71or0x55, sha2-256 and a 32-byte digest. ExposeCodec,DigestandToBytes().AtUri: validate the authority as anAtIdentifierat parse time. Add typed accessorsNsid? Collection/RecordKey? RecordKey/AtIdentifier Repo, computed once.Create(AtIdentifier, Nsid?, RecordKey?).ArgumentExceptionwith no JSON path. ThrowJsonExceptioninstead.API shape
IParsable<T>,ISpanParsable<T>,IComparable<T>and explicitstring → Tconversions on all identifier types (Did,Handle,Nsid,Cid,Tid,RecordKey,AtUri,AtIdentifier, plusSpaceUri/SpaceRecordUri). This makes minimal-API binding and generic parsing work.sealed records (or a shared base) instead of hand-written equality/operators/CompareTo; implementParseasTryParse ? x : throw; use one generic converter over astatic abstractparse interface instead of 8 identical JSON converters; delete the 7 unused internalUnsafeCreatemethods.@stripping, and conversions that throw staying explicit.Acceptance
TidGeneratortest over 100k calls, including concurrent callers, is strictly increasing.Fixedfor the bugs;Breaking changesfor the stricter parsing (a migration note that legacy or foreign data should useTryParse) and for the record/interface changes.