Crates.io | baid58 |
lib.rs | baid58 |
version | 0.4.4 |
source | src |
created_at | 2023-01-22 16:41:31.583298 |
updated_at | 2023-07-25 12:42:18.906061 |
description | Easy-to-check Base58 encoding for identities |
homepage | https://github.com/UBIDECO/rust-baid58 |
repository | https://github.com/UBIDECO/rust-baid58 |
max_upload_size | |
id | 765254 |
size | 72,743 |
Baid58 is a Base58 equipped with an optional checksum (which is easy to see and verify) and human-readable information about the value.
A lot of binary-to-text encoding formats exists today, which are designed for a different specific cases. Why another one? Well, since we have a need to encode short-length unique identifiers - like file or data structure hashes, cryptographic public keys, digital identities and certificates etc..
Baid58
is a format for representing unique identities based on Base58 encoding
("baid" is a combination of "base" and "identity"). It is designed to match the
following criteria:
We have chosen Base58 as most concise and widespread encoding which can be copied with a single click. We designed a way how it can be stuffed with prefix and suffix information to represent a human-readable identifier (HRI) and checksum in a different ways depending on a use case, like:
tommy-fuel-pagoda-7EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt.stl
stlTommyFuelPagoda07EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt
stl_tommy_fuel_pagoda_7EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt
stl:7EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt#tommy_fuel_pagoda
As you see, a Baid58
encoded value is composed of the following components:
The actual value encoded with a Base58 encoding (using bitcoin flavour of it);
Optional human-readable identifier (HRI) which can prefix or follow the main value;
Optional checksum mnemonic, representing 32 least-significant bits of BLAKE3 hash of the value created using HRI as a hashing key. The mnemonic is created using tothink.com dictionary and consists of three easy-to-distinguish words.
Since it contains characters which can't be used in URLs, file names and the encoded string can't be always selected with a single-click.
Baid58 is in fact Base58 equipped with an optional checksum (which is easy to see and verify) and human-readable information about the value.
Bech32 strings are usually too long, while have no real advantages:
As a result, we are getting longer strings to read, non-standard wierd encoding, false feel of safety - and no advantages over Base58, which only needs efficient and clearly-distinguished checksum and value type information - and this is exactly what Baid58 does.
Multiformats by Protocol Labs are a way to represent different binary-to-text encodings and values in a consistent way. However, there are some reasons to avoid their use for the case we need:
Both HRI part and mnemonic checksum may be omitted - in this case we have just
an unmodified Base58
string. Alternatively, they can be formatted with this
crate using rich functionality of rust display formatting language in the
following ways:
The presence of human-readable identifier and checksum is controlled by precision flag and by alignment flags. All the options can be combined with the mnemonic flags from the next section; if a specific mnemonic flag is present than the checksum is not provided.
Flag | HRI | Checksum | Mnemonic | Separators | Example |
---|---|---|---|---|---|
none | absent | absent | defined by other flags | n/a | |
.0 |
suffix | absent | defined by other flags | . |
ID.hri |
.1 |
absent | added | absent | n/a | IDchecksum |
.2 |
absent | added | absent | n/a | chunk(ID ) |
.3 |
absent | added | absent | n/a | chunk(IDchecksum ) |
. N |
reserved | ||||
A< |
prefix | absent | defined by other flags | A |
hri AID |
A^ |
prefix | added* | defined by other flags | A |
hri AIDchecksum |
A> |
suffix | added* | defined by other flags | A |
IDchecksum Ahri |
* added if no mnemonic flags are given
The presence and position of mnemonic is defined by alternative and sign flags:
Flag | HRI | Checksum | Mnemonic | Separators | Example |
---|---|---|---|---|---|
none | - | defined by HRI flags | absent | n/a | |
# |
- | - | suffix (dashed) | # |
ID#solo-lemur-wishes |
0 |
- | - | prefix (capitalized) | 0 |
SoloLemurWishes0ID |
- |
- | - | prefix (dashes) | - |
solo-lemur-wishes-ID |
+ |
- | - | prefix (underscored) | _ |
solo_lemur_wishes_ID |
If width is given, it is used to place multiple fill characters between the value and HRI.
Example formatting strings from the above:
file name: {:-.1}
->
tommy-fuel-pagoda-7EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt.stl
single-click address: {:<0}
->
stlTommyFuelPagoda07EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt
visually clear address: {:_<+}
->
stl_tommy_fuel_pagoda_7EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt
URI or a part of URL: {::^#}
->
stl:7EnUZgFtu28sWqqH3womkTopXCkgAGsCLvLnYvNcPLRt#tommy_fuel_pagoda
Using checksum embedded into the ID: {::^}
->
stl:2dzcCoX9c65gi1GoJ1LFzb5FcQ9pAc8o3Pj8TpcH2mkAdMLCpP