|
| 1 | +/** |
| 2 | + * Implements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding. |
| 3 | + * |
| 4 | + * Supports both standard base58 and XRP variant alphabets. |
| 5 | + * |
| 6 | + * ```js |
| 7 | + * import { fromBase58, toBase58 } from '@exodus/bytes/base58.js' |
| 8 | + * import { fromBase58xrp, toBase58xrp } from '@exodus/bytes/base58.js' |
| 9 | + * ``` |
| 10 | + * |
| 11 | + * @module @exodus/bytes/base58.js |
| 12 | + */ |
| 13 | + |
| 14 | +/// <reference types="node" /> |
| 15 | + |
| 16 | +import type { OutputFormat, Uint8ArrayBuffer } from './array.js'; |
| 17 | + |
| 18 | +/** |
| 19 | + * Encode a `Uint8Array` to a base58 string |
| 20 | + * |
| 21 | + * Uses the standard Bitcoin base58 alphabet |
| 22 | + * |
| 23 | + * @param arr - The input bytes |
| 24 | + * @returns The base58 encoded string |
| 25 | + */ |
| 26 | +export function toBase58(arr: Uint8ArrayBuffer): string; |
| 27 | + |
| 28 | +/** |
| 29 | + * Decode a base58 string to bytes |
| 30 | + * |
| 31 | + * Uses the standard Bitcoin base58 alphabet |
| 32 | + * |
| 33 | + * @param string - The base58 encoded string |
| 34 | + * @param format - Output format (default: 'uint8') |
| 35 | + * @returns The decoded bytes |
| 36 | + */ |
| 37 | +export function fromBase58(string: string, format?: 'uint8'): Uint8ArrayBuffer; |
| 38 | +export function fromBase58(string: string, format: 'buffer'): Buffer; |
| 39 | +export function fromBase58(string: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer; |
| 40 | + |
| 41 | +/** |
| 42 | + * Encode a `Uint8Array` to a base58 string using XRP alphabet |
| 43 | + * |
| 44 | + * Uses the XRP variant base58 alphabet |
| 45 | + * |
| 46 | + * @param arr - The input bytes |
| 47 | + * @returns The base58 encoded string |
| 48 | + */ |
| 49 | +export function toBase58xrp(arr: Uint8ArrayBuffer): string; |
| 50 | + |
| 51 | +/** |
| 52 | + * Decode a base58 string to bytes using XRP alphabet |
| 53 | + * |
| 54 | + * Uses the XRP variant base58 alphabet |
| 55 | + * |
| 56 | + * @param string - The base58 encoded string |
| 57 | + * @param format - Output format (default: 'uint8') |
| 58 | + * @returns The decoded bytes |
| 59 | + */ |
| 60 | +export function fromBase58xrp(string: string, format?: 'uint8'): Uint8ArrayBuffer; |
| 61 | +export function fromBase58xrp(string: string, format: 'buffer'): Buffer; |
| 62 | +export function fromBase58xrp(string: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer; |
0 commit comments