Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,39 @@ import { getPrefix } from '@exodus/bytes/bech32.js'

### `@exodus/bytes/base58.js`

Implements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding.

Supports both standard base58 and XRP variant alphabets.

```js
import { fromBase58, toBase58 } from '@exodus/bytes/base58.js'
import { fromBase58xrp, toBase58xrp } from '@exodus/bytes/base58.js'
```

#### `fromBase58(string, format = 'uint8')`

Decode a base58 string to bytes

Uses the standard Bitcoin base58 alphabet

#### `toBase58(arr)`

Encode a `Uint8Array` to a base58 string

Uses the standard Bitcoin base58 alphabet

#### `fromBase58xrp(string, format = 'uint8')`

Decode a base58 string to bytes using XRP alphabet

Uses the XRP variant base58 alphabet

#### `toBase58xrp(arr)`

Encode a `Uint8Array` to a base58 string using XRP alphabet

Uses the XRP variant base58 alphabet

### `@exodus/bytes/base58check.js`

```js
Expand Down
62 changes: 62 additions & 0 deletions base58.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Implements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding.
*
* Supports both standard base58 and XRP variant alphabets.
*
* ```js
* import { fromBase58, toBase58 } from '@exodus/bytes/base58.js'
* import { fromBase58xrp, toBase58xrp } from '@exodus/bytes/base58.js'
* ```
*
* @module @exodus/bytes/base58.js
*/

/// <reference types="node" />

import type { OutputFormat, Uint8ArrayBuffer } from './array.js';

/**
* Encode a `Uint8Array` to a base58 string
*
* Uses the standard Bitcoin base58 alphabet
*
* @param arr - The input bytes
* @returns The base58 encoded string
*/
export function toBase58(arr: Uint8ArrayBuffer): string;

/**
* Decode a base58 string to bytes
*
* Uses the standard Bitcoin base58 alphabet
*
* @param string - The base58 encoded string
* @param format - Output format (default: 'uint8')
* @returns The decoded bytes
*/
export function fromBase58(string: string, format?: 'uint8'): Uint8ArrayBuffer;
export function fromBase58(string: string, format: 'buffer'): Buffer;
export function fromBase58(string: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer;

/**
* Encode a `Uint8Array` to a base58 string using XRP alphabet
*
* Uses the XRP variant base58 alphabet
*
* @param arr - The input bytes
* @returns The base58 encoded string
*/
export function toBase58xrp(arr: Uint8ArrayBuffer): string;

/**
* Decode a base58 string to bytes using XRP alphabet
*
* Uses the XRP variant base58 alphabet
*
* @param string - The base58 encoded string
* @param format - Output format (default: 'uint8')
* @returns The decoded bytes
*/
export function fromBase58xrp(string: string, format?: 'uint8'): Uint8ArrayBuffer;
export function fromBase58xrp(string: string, format: 'buffer'): Buffer;
export function fromBase58xrp(string: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"/base32.js",
"/base32.d.ts",
"/base58.js",
"/base58.d.ts",
"/base58check.js",
"/base58check.node.js",
"/base64.js",
Expand Down Expand Up @@ -134,7 +135,10 @@
"types": "./base32.d.ts",
"default": "./base32.js"
},
"./base58.js": "./base58.js",
"./base58.js": {
"types": "./base58.d.ts",
"default": "./base58.js"
},
"./base58check.js": {
"node": "./base58check.node.js",
"default": "./base58check.js"
Expand Down
Loading