aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/@exodus/bytes/base32.d.ts
blob: bf7c2fcc8ee2bb21a334b11e791a3417327e3589 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Implements base32 and base32hex from [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648)
 * (no differences from [RFC3548](https://datatracker.ietf.org/doc/html/rfc4648)).
 *
 * ```js
 * import { fromBase32, toBase32 } from '@exodus/bytes/base32.js'
 * import { fromBase32hex, toBase32hex } from '@exodus/bytes/base32.js'
 * ```
 *
 * @module @exodus/bytes/base32.js
 */

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

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

/**
 * Options for base32 encoding
 */
export interface ToBase32Options {
  /** Whether to include padding characters (default: false) */
  padding?: boolean;
}

/**
 * Padding mode for base32 decoding
 * - `true`: padding is required
 * - `false`: padding is not allowed
 * - `'both'`: padding is optional (default)
 */
export type PaddingMode = boolean | 'both';

/**
 * Options for base32 decoding
 */
export interface FromBase32Options {
  /** Output format (default: 'uint8') */
  format?: OutputFormat;
  /** Padding mode */
  padding?: PaddingMode;
}

/**
 * Encode a `Uint8Array` to a base32 string (RFC 4648)
 *
 * @param arr - The input bytes
 * @param options - Encoding options
 * @returns The base32 encoded string
 */
export function toBase32(arr: Uint8Array, options?: ToBase32Options): string;

/**
 * Encode a `Uint8Array` to a base32hex string (RFC 4648)
 *
 * @param arr - The input bytes
 * @param options - Encoding options (padding defaults to false)
 * @returns The base32hex encoded string
 */
export function toBase32hex(arr: Uint8Array, options?: ToBase32Options): string;

/**
 * Decode a base32 string to bytes
 *
 * Operates in strict mode for last chunk, does not allow whitespace
 *
 * @param string - The base32 encoded string
 * @param options - Decoding options
 * @returns The decoded bytes
 */
export function fromBase32(string: string, options?: FromBase32Options): Uint8ArrayBuffer;
export function fromBase32(string: string, options: FromBase32Options & { format: 'buffer' }): Buffer;

/**
 * Decode a base32hex string to bytes
 *
 * Operates in strict mode for last chunk, does not allow whitespace
 *
 * @param string - The base32hex encoded string
 * @param options - Decoding options
 * @returns The decoded bytes
 */
export function fromBase32hex(string: string, options?: FromBase32Options): Uint8ArrayBuffer;
export function fromBase32hex(string: string, options: FromBase32Options & { format: 'buffer' }): Buffer;