base58.nx
buildroot/runtime/base58.nx
about
base58.nx -- Bitcoin / IPFS base58 encoder + decoder.
Alphabet (omits 0/O/l/I to avoid visual confusion):
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
Used by: Bitcoin addresses, IPFS CID v0, Stellar account IDs,
Monero addresses. Less efficient than base64 (log(58)/log(256)
≈ 0.73 bytes of data per char vs base64's 0.75) but preserves
1:1 byte-to-copy safety when pasted into phishing-resistant
UI contexts.
Leading zero bytes in input map to leading '1' chars in output.
This preserves information for binary protocols where leading
zeros are significant (Bitcoin addresses have a version prefix
byte that's often 0x00).
Invariants:
B58_1 Alphabet is Bitcoin/IPFS canonical; no URL-safe
variant (unlike base64).
B58_2 Round-trip exact: decode(encode(x)) == x.
B58_3 Decoder rejects non-alphabet chars with negative err.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 25 | const B58_ERR_BAD_CHAR: i64 = -1 |
| 26 | const B58_ERR_OVERFLOW: i64 = -2 |
functions
| 29 | func b58_enc_char(v: i64) -> i64 {
called by 1: base58_encode_after_zeros |
| 45 | func b58_dec_val(c: i64) -> i64 {
called by 1: base58_decode |
| 56 | func base58_encode_after_zeros(in_bytes: *u8, n: i64, zeros: i64, out: *u8) -> i64;
called by 1: base58_encode |
| 61 | func base58_encode(in_bytes: *u8, n: i64, out: *u8) -> i64 { |
| 77 | func base58_encode_after_zeros(in_bytes: *u8, n: i64, zeros: i64, out: *u8) -> i64 {
calls 1: b58_enc_char |
| 125 | func base58_decode(in_chars: *u8, n: i64, out: *u8) -> i64 {
calls 1: b58_dec_val |
| 174 | func main() -> i64 {
calls 1: base58_encode |