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.
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.
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
andMBCStr
: a multibase-encoded multicodec-encoded byte sequence, with no restriction on the codec category. Analogous to theString
andstr
types respectively.MBX
andMBXStr
: a multibase-encoded multicodec-encoded byte sequence, restricted to a specified codec category. Analogous to theString
andstr
types respectively.
Examples:
z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
: Aned25519
public key inbase58btc
encoding.
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
andFBCStr
: a fixed-base-encoded multicodec-encoded byte sequence, with no restriction on the codec category. Analogous to theString
andstr
types respectively.FBX
andFBXStr
: a fixed-base-encoded multicodec-encoded byte sequence, restricted to a specified codec category. Analogous to theString
andstr
types respectively.
Examples:
6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
: Aned25519
public key known to be usebase58btc
encoding. Note that this is identical to the example in the above section but without the prefix char.