Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle: refactor doc
Merged fintohaps opened 1 year ago

The aim of this change is to make the Doc type more safe to use by approaching the design via [Parse don’t validate][0] approach.

The problem with the previous approach was that all field were pub and thus a Doc<Verified> could easily be mutated and serialized. Granted, the code that used the serialization would tend to verify the Doc first, however, this approach ensures that only a verified Doc can be serialized. It also meant that trying to add new data that would follow the parse approach would require more generic parameters on top of the existing PhantomData parameter, i.e. we need to do something like: Doc<RawField, V> -> Doc<ValidField, V>.

The new approach splits the type into two separate types: DocMut and Doc. The former is allowed to be mutated at will, and uses types that are less strict. The latter is the valid type that can only be constructed by validating a DocMut (or the initial constructor). The Doc type’s fields can then only be accessed by read-only methods.

Solves the problems above by only allowing mutations to DocMut, as well as, new fields being added to DocMut which are then validated via DocMut::verified.

fintohaps opened with revision f67ef748 on base 855327d3 +774 -357 1 year ago

The aim of this change is to make the Doc type more safe to use by approaching the design via [Parse don’t validate][0] approach.

The problem with the previous approach was that all field were pub and thus a Doc<Verified> could easily be mutated and serialized. Granted, the code that used the serialization would tend to verify the Doc first, however, this approach ensures that only a verified Doc can be serialized. It also meant that trying to add new data that would follow the parse approach would require more generic parameters on top of the existing PhantomData parameter, i.e. we need to do something like: Doc<RawField, V> -> Doc<ValidField, V>.

The new approach splits the type into two separate types: DocMut and Doc. The former is allowed to be mutated at will, and uses types that are less strict. The latter is the valid type that can only be constructed by validating a DocMut (or the initial constructor). The Doc type’s fields can then only be accessed by read-only methods.

Solves the problems above by only allowing mutations to DocMut, as well as, new fields being added to DocMut which are then validated via DocMut::verified.

fintohaps pushed revision 2 f58adbe0 on base f83c1167 +804 -360 1 year ago

Changes:

  • Renamed DocMut to RawDoc
  • Renamed into_mut to edit
  • Use Doc::edit everywhere and remove From<Doc> for RawDoc impl
  • Introduce Doc::with_edits to for a slightly nicer API in some sections
  • Threshold::new takes Delegates to ensure it is always constructed safely
  • Changed Delegates constructor to remove HashSet and use counter for checking number of delegates.
  • Added a test for checking verifying a Doc de-deuplicates DIDs
  • Fix documentation indentation
fintohaps pushed revision 3 3d477afe on base f83c1167 +799 -361 1 year ago

Changes:

  • Simplify Delegates::new constructor to use Vec and use the len for checking when it exceeds the max.
  • Fix documentation links
  • Change blob_at from pub to pub(crate)
fintohaps pushed revision 4 33614c58 on base f83c1167 +810 -361 1 year ago

Changes:

  • Fix length check to go after we have pushed
  • Add test case for maximum number of delegates
fintohaps pushed revision 5 3ee4e47f on base f83c1167 +810 -361 1 year ago

Changes:

  • Check length before pushing, and do so after contains check
did:key:z6MksFqX...wzpT merged revision 3ee4e47f at de1958fa 1 year ago