# `X402.Base58`
[🔗](https://github.com/cardotrejos/x402/blob/v0.9.0/lib/x402/base58.ex#L1)

Base58 encoding and decoding using the Bitcoin alphabet.

Solana addresses, transaction signatures, and blockhashes are Base58
strings over the Bitcoin alphabet
(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz` — no `0`,
`O`, `I`, or `l`). Leading zero bytes encode as leading `1` characters,
one per byte, matching the reference implementations.

Pure functions with no dependencies; used by `X402.Solana` and
`X402.Scheme.ExactSVM`.

# `encoded`

```elixir
@type encoded() :: String.t()
```

A Base58-encoded string.

# `decode`
*since 0.6.0* 

```elixir
@spec decode(term()) :: {:ok, binary()} | :error
```

Decodes a Base58 string, returning `:error` for invalid characters.

## Examples

    iex> X402.Base58.decode("2g")
    {:ok, "a"}

    iex> X402.Base58.decode("a3gV")
    {:ok, "bbb"}

    iex> X402.Base58.decode("1111111111")
    {:ok, <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>}

    iex> X402.Base58.decode("")
    {:ok, ""}

    iex> X402.Base58.decode("invalid0base58")
    :error

    iex> X402.Base58.decode(:not_a_string)
    :error

# `encode`
*since 0.6.0* 

```elixir
@spec encode(binary()) :: encoded()
```

Encodes a binary as a Base58 string.

Test vectors are the Bitcoin Core `base58_encode_decode.json` suite.

## Examples

    iex> X402.Base58.encode("")
    ""

    iex> X402.Base58.encode(<<0x61>>)
    "2g"

    iex> X402.Base58.encode(<<0x62, 0x62, 0x62>>)
    "a3gV"

    iex> X402.Base58.encode(<<0x51, 0x6B, 0x6F, 0xCD, 0x0F>>)
    "ABnLTmg"

    iex> X402.Base58.encode("simply a long string")
    "2cFupjhnEsSn59qHXstmK2ffpLv2"

    iex> X402.Base58.encode(<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>)
    "1111111111"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
