-
Notifications
You must be signed in to change notification settings - Fork 6
/
bs32.ts
51 lines (43 loc) · 1.34 KB
/
bs32.ts
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
import { utils } from 'https://esm.sh/@scure/base@1.1.1';
import { createDecode, createEncode, createIs, createValidate } from './helpers.ts';
const chars = 'abcdefghijklmnopqrstuvwxyz234567';
const config = {
chars,
coder: utils.chain(
// We define our own chain, the default base32 has padding
utils.radix2(5),
utils.alphabet(chars),
{
decode: (input: string) => input.split(''),
encode: (input: string[]) => input.join('')
}
),
ipfs: 'b',
type: 'base32'
};
/**
* @name base32Validate
* @summary Validates a base32 value.
* @description
* Validates that the supplied value is valid base32, throwing exceptions if not
*/
export const base32Validate = /*#__PURE__*/ createValidate(config);
/**
* @name isBase32
* @description Checks if the input is in base32, returning true/false
*/
export const isBase32 = /*#__PURE__*/ createIs(base32Validate);
/**
* @name base32Decode
* @summary Delookup a base32 value.
* @description
* From the provided input, decode the base32 and return the result as an `Uint8Array`.
*/
export const base32Decode = /*#__PURE__*/ createDecode(config, base32Validate);
/**
* @name base32Encode
* @summary Creates a base32 value.
* @description
* From the provided input, create the base32 and return the result as a string.
*/
export const base32Encode = /*#__PURE__*/ createEncode(config);