Skip to content

This Rust crate provides ergonomic types for working with strings that are multibase-encoded multicodec-encoded byte sequences. Versions of each type are provided that are analogous to the `String` and `str` types, with analogous semantics.

License

Notifications You must be signed in to change notification settings

LedgerDomain/mbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mbc

This Rust crate provides ergonomic types for working with strings that are multibase-encoded multicodec-encoded byte sequences. Versions of each type are provided that are analogous to the String and str types, with analogous semantics.

Codec Categories

A "codec" refers to an entry in the multicodec registry.

This crate provides a CodecCategory enum that represents a categorization of relevant codecs. Note that this is not a standard categorization, doesn't guarantee to be complete, but it does accurately categorize the most common codecs.

Available Types

Multibase-encoded Multicodec-encoded types

These types are newtype wrappers around String and str, respectively, where the string content is a multibase-encoded multicodec-encoded byte sequence. The anatomy of the string is as follows. Given a base-encoding B, a codec C, and data bytes D, the string is of the form:

PrefixCharFor(B) MultibaseEncoded(B, MulticodecEncoded(UnsignedVarintEncoded(C), D))

The types are:

  • MBC and MBCStr : a multibase-encoded multicodec-encoded byte sequence, with no restriction on the codec category. Analogous to the String and str types respectively.
  • MBX and MBXStr : a multibase-encoded multicodec-encoded byte sequence, restricted to a specified codec category. Analogous to the String and str types respectively.

Examples:

  • z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp : An ed25519 public key in base58btc encoding.

Fixed-base-encoded Multicodec-encoded types

These types are newtype wrappers around String and str, respectively, where the string content is a fixed-base-encoded multicodec-encoded byte sequence. The anatomy of the string is as follows. Given a base-encoding B, a codec C, and data bytes D, the string is of the form:

MultibaseEncoded(B, MulticodecEncoded(UnsignedVarintEncoded(C), D))

The difference between this an the multibase-encoded types is the lack of the prefix char. The base-encoding is specified in the type itself via generic parameter. Consumption of a string of this form requires knowledge of the specific base-encoding used. For example, there could be a schema in which base64url is always used. In these situations, there's no need for the base-encoding prefix character.

The types are:

  • FBC and FBCStr : a fixed-base-encoded multicodec-encoded byte sequence, with no restriction on the codec category. Analogous to the String and str types respectively.
  • FBX and FBXStr : a fixed-base-encoded multicodec-encoded byte sequence, restricted to a specified codec category. Analogous to the String and str types respectively.

Examples:

  • 6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp : An ed25519 public key known to be use base58btc encoding. Note that this is identical to the example in the above section but without the prefix char.

License

MIT License.

About

This Rust crate provides ergonomic types for working with strings that are multibase-encoded multicodec-encoded byte sequences. Versions of each type are provided that are analogous to the `String` and `str` types, with analogous semantics.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages