# Base58

Utility functions for working with [Base58](https://digitalbazaar.github.io/base58-spec/) values.

## Examples

Below are some examples demonstrating common usages of the `Base58` module:

* [Encoding to Base58](#encoding-to-base58)

* [Decoding Base58](#decoding-base58)

### Encoding to Base58

Values can be encoded to Base58 with:

* [`Base58.fromString`](/api/Base58/fromString), or

* [`Base58.fromBytes`](/api/Base58/fromBytes), or

* [`Base58.fromHex`](/api/Base58/fromHex)

```ts twoslash
import { Base58 } from 'ox'

const value_string = Base58.fromString('Hello World!')
// @log: '2NEpo7TZRRrLZSi2U'

const value_bytes = Base58.fromBytes(
  new Uint8Array([
    72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33
  ])
)
// @log: '2NEpo7TZRRrLZSi2U'

const value_hex = Base58.fromHex(
  '0x48656c6c6f20576f726c6421'
)
// @log: '2NEpo7TZRRrLZSi2U'
```

### Decoding Base58

Values can be decoded from Base58 with:

* [`Base58.toString`](/api/Base58/toString), or

* [`Base58.toBytes`](/api/Base58/toBytes), or

* [`Base58.toHex`](/api/Base58/toHex)

```ts twoslash
import { Base58 } from 'ox'

const value_string = Base58.toString('2NEpo7TZRRrLZSi2U')
// @log: 'Hello World!'

const value_bytes = Base58.toBytes('2NEpo7TZRRrLZSi2U')
// @log: Uint8Array [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]

const value_hex = Base58.toHex('2NEpo7TZRRrLZSi2U')
// @log: '0x48656c6c6f20576f726c6421'
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Base58.fromBytes`](/api/Base58/fromBytes) | Encodes a [`Bytes.Bytes`](/api/Bytes/types#bytes) to a Base58-encoded string. |
| [`Base58.fromHex`](/api/Base58/fromHex) | Encodes a [`Hex.Hex`](/api/Hex/types#hex) to a Base58-encoded string. |
| [`Base58.fromString`](/api/Base58/fromString) | Encodes a string to a Base58-encoded string. |
| [`Base58.toBytes`](/api/Base58/toBytes) | Decodes a Base58-encoded string to a [`Bytes.Bytes`](/api/Bytes/types#bytes). |
| [`Base58.toHex`](/api/Base58/toHex) | Decodes a Base58-encoded string to [`Hex.Hex`](/api/Hex/types#hex). |
| [`Base58.toString`](/api/Base58/toString) | Decodes a Base58-encoded string to a string. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Base58.InvalidCharacterError`](/api/Base58/errors#base58invalidcharactererror) | Thrown when a Base58 string contains an invalid character. |
