1 | // Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
2 | // SPDX-License-Identifier: Apache-2.0
|
3 | import { base64 } from '@scure/base';
|
4 | import { createDecode, createEncode, createIs, createValidate } from "../base32/helpers.js";
|
5 | const config = {
|
6 | chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
7 | coder: base64,
|
8 | type: 'base64'
|
9 | };
|
10 | /**
|
11 | * @name base64Validate
|
12 | * @summary Validates a base64 value.
|
13 | * @description
|
14 | * Validates that the supplied value is valid base64
|
15 | */
|
16 |
|
17 | export const base64Validate = createValidate(config);
|
18 | /**
|
19 | * @name isBase64
|
20 | * @description Checks if the input is in base64, returning true/false
|
21 | */
|
22 |
|
23 | export const isBase64 = createIs(base64Validate);
|
24 | /**
|
25 | * @name base64Decode
|
26 | * @summary Decodes a base64 value.
|
27 | * @description
|
28 | * From the provided input, decode the base64 and return the result as an `Uint8Array`.
|
29 | */
|
30 |
|
31 | export const base64Decode = createDecode(config, base64Validate);
|
32 | /**
|
33 | * @name base64Encode
|
34 | * @summary Creates a base64 value.
|
35 | * @description
|
36 | * From the provided input, create the base64 and return the result as a string.
|
37 | */
|
38 |
|
39 | export const base64Encode = createEncode(config); |
\ | No newline at end of file |