Skip to content

Commit cf34d82

Browse files
CopilotChALkeR
andcommitted
Add TypeScript type definitions for base58.js
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
1 parent 3a532c1 commit cf34d82

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
coverage
44
playground
55
*.tgz
6+
package-lock.json

base58.d.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Implements base58 encoding as used in Bitcoin and other cryptocurrencies.
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?: OutputFormat): Uint8ArrayBuffer;
38+
export function fromBase58(string: string, format: 'buffer'): Buffer;
39+
40+
/**
41+
* Encode a `Uint8Array` to a base58 string using XRP alphabet
42+
*
43+
* Uses the XRP variant base58 alphabet
44+
*
45+
* @param arr - The input bytes
46+
* @returns The base58 encoded string
47+
*/
48+
export function toBase58xrp(arr: Uint8ArrayBuffer): string;
49+
50+
/**
51+
* Decode a base58 string to bytes using XRP alphabet
52+
*
53+
* Uses the XRP variant base58 alphabet
54+
*
55+
* @param string - The base58 encoded string
56+
* @param format - Output format (default: 'uint8')
57+
* @returns The decoded bytes
58+
*/
59+
export function fromBase58xrp(string: string, format?: OutputFormat): Uint8ArrayBuffer;
60+
export function fromBase58xrp(string: string, format: 'buffer'): 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",
@@ -132,7 +133,10 @@
132133
"types": "./base32.d.ts",
133134
"default": "./base32.js"
134135
},
135-
"./base58.js": "./base58.js",
136+
"./base58.js": {
137+
"types": "./base58.d.ts",
138+
"default": "./base58.js"
139+
},
136140
"./base58check.js": {
137141
"node": "./base58check.node.js",
138142
"default": "./base58check.js"

0 commit comments

Comments
 (0)