This Rust crate provides ergonomic types for working with strings that are multibase-encoded multihash and multikey values. Versions of each type are provided that are analogous to the String and str types, with analogous semantics.
Note that there is also a mbx-bin crate that provides a CLI tool for computing MBHash values and decoding MBHash, MBPubKey, and MBPrivKey values. This is useful for development, testing, and experimentation.
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.
The MBHash and MBHashStr types are newtype wrappers around String and str, respectively, where the string content is a multibase-encoded multihash. The anatomy of the string is as follows. Given a base-encoding B, a multihash codec C, a digest length L, and digest bytes D, the string is of the form:
PrefixCharFor(B) || Multibase(B, Multihash(C, L, D))
where Multihash(C, L, D) is defined to be the bytes (where || denotes byte array concatenation):
VarInt(C) || VarInt(L) || D
where VarInt(N) is defined to be the unsigned varint encoding of the integer N.
The codec is limited to be one having the multihash tag in the multicodec table.
Examples:
uHiBKHZUE3HHlYcyVIF-vPm0Xg71vqJla2L1OGXHMSK4NEA: Ablake3hash inbase64urlencoding.f1e204a1d9504dc71e561cc95205faf3e6d1783bd6fa8995ad8bd4e1971cc48ae0d10: Ablake3hash inbase16lowerencoding.uEiAWCleApqPkQg-DKbql-C5OOyZ7ydUgq7G_rHepYEukHg: Asha2-256hash inbase64urlencoding.zQmPpgppLtSyUF2qkWn648Hs6MFBuRU8Xg8LiaY2jf31iGM: Asha2-256hash inbase58btcencoding.
References:
- https://github.com/multiformats/multihash
- https://www.w3.org/TR/cid-1.0/#multihash
- https://github.com/multiformats/multicodec/blob/master/table.csv
- https://github.com/multiformats/unsigned-varint
The MBPubKey and MBPubKeyStr types are newtype wrappers around String and str, respectively, where the string content is a multibase-encoded multikey. The anatomy of the string is as follows. Given a base-encoding B, a multikey codec C, and public key bytes D, the string is of the form (where || denotes string/byte array concatenation):
PrefixCharFor(B) || Multibase(B, VarInt(C) || D)
The allowable codec values are the subset of those having the key tag in the multicodec table, which denote a public key type.
Examples:
z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp: Aned25519public key inbase58btcencoding. Note that this is the format used in the did:key DID method as the DID-method-specific identifier.u7QHumXvEpaKqvVb0DYhWrsC0z3p-3l_l7R9XM5fxqEW02Q: Aned25519public key inbase64urlencoding.
References:
- https://www.w3.org/TR/cid-1.0/#multikey
- https://github.com/multiformats/multicodec/blob/master/table.csv
- https://github.com/multiformats/unsigned-varint
The MBPrivKey and MBPrivKeyStr types are analogous to MBPubKey and MBPubKeyStr, respectively, and have the same definition, except that the codec is limited to
PrefixCharFor(B) || Multibase(B, VarInt(C) || D)
The allowable codec values are the subset of those having the key tag in the multicodec table, which denote a private key type.
- When v0.14 is released for
ed448-goldilocks,k256,p256,p384, andp521, add support for them. Similarly, for whatever version ofed25519-daleksupports v3 version of cratesignature. - Potentially add support for different versions of the various crates (e.g.
ed25519-dalek,ed448-goldilocks,k256,p256,p384,p521), with features calleded25519-dalek-v3,k256-v0.14, etc. - Add prefix-based checks for
key_typeinMBPrivKeyStrandMBPubKeyStrto avoid allocations.