Skip to content

Commit 613d893

Browse files
authored
feat: add TypeScript type definitions for base58.js (#32)
1 parent 871a07d commit 613d893

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,17 +468,39 @@ import { getPrefix } from '@exodus/bytes/bech32.js'
468468

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

471+
Implements [base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt) encoding.
472+
473+
Supports both standard base58 and XRP variant alphabets.
474+
471475
```js
472476
import { fromBase58, toBase58 } from '@exodus/bytes/base58.js'
473477
import { fromBase58xrp, toBase58xrp } from '@exodus/bytes/base58.js'
474478
```
475479

476480
#### `fromBase58(string, format = 'uint8')`
481+
482+
Decode a base58 string to bytes
483+
484+
Uses the standard Bitcoin base58 alphabet
485+
477486
#### `toBase58(arr)`
478487

488+
Encode a `Uint8Array` to a base58 string
489+
490+
Uses the standard Bitcoin base58 alphabet
491+
479492
#### `fromBase58xrp(string, format = 'uint8')`
493+
494+
Decode a base58 string to bytes using XRP alphabet
495+
496+
Uses the XRP variant base58 alphabet
497+
480498
#### `toBase58xrp(arr)`
481499

500+
Encode a `Uint8Array` to a base58 string using XRP alphabet
501+
502+
Uses the XRP variant base58 alphabet
503+
482504
### `@exodus/bytes/base58check.js`
483505

484506
```js

base58.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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;

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"/base32.js",
8585
"/base32.d.ts",
8686
"/base58.js",
87+
"/base58.d.ts",
8788
"/base58check.js",
8889
"/base58check.node.js",
8990
"/base64.js",
@@ -134,7 +135,10 @@
134135
"types": "./base32.d.ts",
135136
"default": "./base32.js"
136137
},
137-
"./base58.js": "./base58.js",
138+
"./base58.js": {
139+
"types": "./base58.d.ts",
140+
"default": "./base58.js"
141+
},
138142
"./base58check.js": {
139143
"node": "./base58check.node.js",
140144
"default": "./base58check.js"

0 commit comments

Comments
 (0)