@sectui/operations 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/args.d.ts +8 -0
  4. package/dist/args.js +47 -0
  5. package/dist/args.js.map +1 -0
  6. package/dist/cli-flags.d.ts +7 -0
  7. package/dist/cli-flags.js +28 -0
  8. package/dist/cli-flags.js.map +1 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.js +185 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/completions.d.ts +3 -0
  13. package/dist/completions.js +113 -0
  14. package/dist/completions.js.map +1 -0
  15. package/dist/display.d.ts +4 -0
  16. package/dist/display.js +29 -0
  17. package/dist/display.js.map +1 -0
  18. package/dist/errors.d.ts +6 -0
  19. package/dist/errors.js +7 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +4 -0
  22. package/dist/index.js +5 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/operation.d.ts +64 -0
  25. package/dist/operation.js +5 -0
  26. package/dist/operation.js.map +1 -0
  27. package/dist/operations/base/alphabets.d.ts +28 -0
  28. package/dist/operations/base/alphabets.js +27 -0
  29. package/dist/operations/base/alphabets.js.map +1 -0
  30. package/dist/operations/base/base32.d.ts +33 -0
  31. package/dist/operations/base/base32.js +85 -0
  32. package/dist/operations/base/base32.js.map +1 -0
  33. package/dist/operations/base/base58.d.ts +34 -0
  34. package/dist/operations/base/base58.js +43 -0
  35. package/dist/operations/base/base58.js.map +1 -0
  36. package/dist/operations/base/base62.d.ts +28 -0
  37. package/dist/operations/base/base62.js +43 -0
  38. package/dist/operations/base/base62.js.map +1 -0
  39. package/dist/operations/base/base64.d.ts +19 -0
  40. package/dist/operations/base/base64.js +72 -0
  41. package/dist/operations/base/base64.js.map +1 -0
  42. package/dist/operations/base/base64url.d.ts +15 -0
  43. package/dist/operations/base/base64url.js +44 -0
  44. package/dist/operations/base/base64url.js.map +1 -0
  45. package/dist/operations/base/big-number.d.ts +6 -0
  46. package/dist/operations/base/big-number.js +54 -0
  47. package/dist/operations/base/big-number.js.map +1 -0
  48. package/dist/operations/color/hex-to-rgb.d.ts +14 -0
  49. package/dist/operations/color/hex-to-rgb.js +41 -0
  50. package/dist/operations/color/hex-to-rgb.js.map +1 -0
  51. package/dist/operations/data/json-format.d.ts +20 -0
  52. package/dist/operations/data/json-format.js +33 -0
  53. package/dist/operations/data/json-format.js.map +1 -0
  54. package/dist/operations/data/json.d.ts +20 -0
  55. package/dist/operations/data/json.js +59 -0
  56. package/dist/operations/data/json.js.map +1 -0
  57. package/dist/operations/data/yaml.d.ts +21 -0
  58. package/dist/operations/data/yaml.js +54 -0
  59. package/dist/operations/data/yaml.js.map +1 -0
  60. package/dist/operations/extract/extract.d.ts +55 -0
  61. package/dist/operations/extract/extract.js +129 -0
  62. package/dist/operations/extract/extract.js.map +1 -0
  63. package/dist/operations/hash/bcrypt.d.ts +16 -0
  64. package/dist/operations/hash/bcrypt.js +45 -0
  65. package/dist/operations/hash/bcrypt.js.map +1 -0
  66. package/dist/operations/hash/hashes.d.ts +10 -0
  67. package/dist/operations/hash/hashes.js +29 -0
  68. package/dist/operations/hash/hashes.js.map +1 -0
  69. package/dist/operations/hex/from-hex.d.ts +1 -0
  70. package/dist/operations/hex/from-hex.js +31 -0
  71. package/dist/operations/hex/from-hex.js.map +1 -0
  72. package/dist/operations/hex/to-hex.d.ts +31 -0
  73. package/dist/operations/hex/to-hex.js +44 -0
  74. package/dist/operations/hex/to-hex.js.map +1 -0
  75. package/dist/operations/html/entities.d.ts +2 -0
  76. package/dist/operations/html/entities.js +69 -0
  77. package/dist/operations/html/entities.js.map +1 -0
  78. package/dist/operations/html/html-decode.d.ts +1 -0
  79. package/dist/operations/html/html-decode.js +36 -0
  80. package/dist/operations/html/html-decode.js.map +1 -0
  81. package/dist/operations/html/html-encode.d.ts +8 -0
  82. package/dist/operations/html/html-encode.js +30 -0
  83. package/dist/operations/html/html-encode.js.map +1 -0
  84. package/dist/operations/text/case.d.ts +14 -0
  85. package/dist/operations/text/case.js +85 -0
  86. package/dist/operations/text/case.js.map +1 -0
  87. package/dist/operations/text/count.d.ts +19 -0
  88. package/dist/operations/text/count.js +59 -0
  89. package/dist/operations/text/count.js.map +1 -0
  90. package/dist/operations/text/line-operations.d.ts +48 -0
  91. package/dist/operations/text/line-operations.js +134 -0
  92. package/dist/operations/text/line-operations.js.map +1 -0
  93. package/dist/operations/text/lines.d.ts +13 -0
  94. package/dist/operations/text/lines.js +22 -0
  95. package/dist/operations/text/lines.js.map +1 -0
  96. package/dist/operations/text/text-operations.d.ts +37 -0
  97. package/dist/operations/text/text-operations.js +79 -0
  98. package/dist/operations/text/text-operations.js.map +1 -0
  99. package/dist/operations/url/url-decode.d.ts +8 -0
  100. package/dist/operations/url/url-decode.js +56 -0
  101. package/dist/operations/url/url-decode.js.map +1 -0
  102. package/dist/operations/url/url-encode.d.ts +8 -0
  103. package/dist/operations/url/url-encode.js +37 -0
  104. package/dist/operations/url/url-encode.js.map +1 -0
  105. package/dist/registry.d.ts +395 -0
  106. package/dist/registry.js +131 -0
  107. package/dist/registry.js.map +1 -0
  108. package/dist/template.d.ts +23 -0
  109. package/dist/template.js +198 -0
  110. package/dist/template.js.map +1 -0
  111. package/package.json +67 -4
  112. package/src/args.ts +47 -0
  113. package/src/cli-flags.ts +29 -0
  114. package/src/cli.ts +189 -0
  115. package/src/completions.ts +129 -0
  116. package/src/display.ts +29 -0
  117. package/src/errors.ts +6 -0
  118. package/src/index.ts +4 -0
  119. package/src/operation.ts +62 -0
  120. package/src/operations/base/alphabets.ts +33 -0
  121. package/src/operations/base/base32.ts +84 -0
  122. package/src/operations/base/base58.ts +45 -0
  123. package/src/operations/base/base62.ts +44 -0
  124. package/src/operations/base/base64.ts +76 -0
  125. package/src/operations/base/base64url.ts +45 -0
  126. package/src/operations/base/big-number.ts +54 -0
  127. package/src/operations/color/hex-to-rgb.ts +42 -0
  128. package/src/operations/data/json-format.ts +33 -0
  129. package/src/operations/data/json.ts +53 -0
  130. package/src/operations/data/yaml.ts +56 -0
  131. package/src/operations/extract/extract.ts +135 -0
  132. package/src/operations/hash/bcrypt.ts +44 -0
  133. package/src/operations/hash/hashes.ts +64 -0
  134. package/src/operations/hex/from-hex.ts +31 -0
  135. package/src/operations/hex/to-hex.ts +46 -0
  136. package/src/operations/html/entities.ts +71 -0
  137. package/src/operations/html/html-decode.ts +36 -0
  138. package/src/operations/html/html-encode.ts +31 -0
  139. package/src/operations/text/case.ts +140 -0
  140. package/src/operations/text/count.ts +61 -0
  141. package/src/operations/text/line-operations.ts +144 -0
  142. package/src/operations/text/lines.ts +22 -0
  143. package/src/operations/text/text-operations.ts +85 -0
  144. package/src/operations/url/url-decode.ts +55 -0
  145. package/src/operations/url/url-encode.ts +38 -0
  146. package/src/registry.ts +152 -0
  147. package/src/template.ts +214 -0
@@ -0,0 +1,64 @@
1
+ export type Category = "Encoding" | "Encryption" | "Hashing" | "Compression" | "Data format" | "Text" | "Extractors" | "Utils";
2
+ interface BaseArg<T> {
3
+ name: string;
4
+ description?: string;
5
+ default: T;
6
+ }
7
+ export type ArgDef = ({
8
+ type: "boolean";
9
+ } & BaseArg<boolean>) | ({
10
+ type: "string";
11
+ } & BaseArg<string>) | ({
12
+ type: "number";
13
+ min?: number;
14
+ max?: number;
15
+ } & BaseArg<number>) | ({
16
+ type: "select";
17
+ options: readonly {
18
+ value: string;
19
+ label: string;
20
+ }[];
21
+ } & BaseArg<string>);
22
+ export type ArgDefs = Record<string, ArgDef>;
23
+ /** A select arg resolves to the union of its option values. */
24
+ export type ArgValue<D extends ArgDef> = D extends {
25
+ type: "select";
26
+ options: readonly {
27
+ value: infer V;
28
+ }[];
29
+ } ? V : D extends {
30
+ type: "boolean";
31
+ } ? boolean : D extends {
32
+ type: "number";
33
+ } ? number : string;
34
+ export type ArgValues<A extends ArgDefs> = {
35
+ [K in keyof A]: ArgValue<A[K]>;
36
+ };
37
+ export interface Example<A extends ArgDefs = ArgDefs> {
38
+ input: string;
39
+ args?: Partial<ArgValues<A>>;
40
+ /** Expected output, decoded as UTF-8. */
41
+ output: string;
42
+ }
43
+ export interface Operation<Id extends string = string, A extends ArgDefs = ArgDefs, Inverse extends string = string> {
44
+ /** Stable kebab-case id, used in templates and recipes. */
45
+ id: Id;
46
+ name: string;
47
+ description: string;
48
+ category: Category;
49
+ /** `binary` when the output may contain arbitrary bytes, so callers know not to print it as text. */
50
+ output: "text" | "binary";
51
+ /** Extra search terms. */
52
+ aliases?: readonly string[];
53
+ /** Id of the operation that undoes this one. */
54
+ inverse?: Inverse;
55
+ infoUrl?: string;
56
+ /** Keyed by arg id, in display order. */
57
+ args: A;
58
+ /** Shown in the docs and the CLI help, and checked by the test suite. */
59
+ examples: readonly [Example<A>, ...Example<A>[]];
60
+ run(input: Uint8Array, args: ArgValues<A>): Uint8Array;
61
+ }
62
+ /** Identity function that preserves the literal types of the id, args and inverse. */
63
+ export declare function defineOperation<const Id extends string, const A extends ArgDefs, const Inverse extends string = never>(op: Operation<Id, A, Inverse>): Operation<Id, A, Inverse>;
64
+ export {};
@@ -0,0 +1,5 @@
1
+ /** Identity function that preserves the literal types of the id, args and inverse. */
2
+ export function defineOperation(op) {
3
+ return op;
4
+ }
5
+ //# sourceMappingURL=operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../src/operation.ts"],"names":[],"mappings":"AAwDA,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAC7B,EAA6B;IAE7B,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,28 @@
1
+ export declare const BASE32_ALPHABETS: readonly [{
2
+ readonly value: "base32";
3
+ readonly label: "Standard (RFC 4648): A-Z2-7=";
4
+ }, {
5
+ readonly value: "base32hex";
6
+ readonly label: "Extended hex (RFC 4648 §7): 0-9A-V=";
7
+ }];
8
+ export type Base32Alphabet = (typeof BASE32_ALPHABETS)[number]["value"];
9
+ export declare const BASE32_CHARS: Record<Base32Alphabet, string>;
10
+ export declare const BASE58_ALPHABETS: readonly [{
11
+ readonly value: "bitcoin";
12
+ readonly label: "Bitcoin: 1-9A-HJ-NP-Za-km-z";
13
+ }, {
14
+ readonly value: "flickr";
15
+ readonly label: "Flickr: 1-9a-km-zA-HJ-NP-Z";
16
+ }, {
17
+ readonly value: "ripple";
18
+ readonly label: "Ripple: rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
19
+ }];
20
+ export declare const BASE58_CHARS: Record<(typeof BASE58_ALPHABETS)[number]["value"], string>;
21
+ export declare const BASE62_ALPHABETS: readonly [{
22
+ readonly value: "0-9A-Za-z";
23
+ readonly label: "Digits, uppercase, lowercase (GMP)";
24
+ }, {
25
+ readonly value: "0-9a-zA-Z";
26
+ readonly label: "Digits, lowercase, uppercase";
27
+ }];
28
+ export declare const BASE62_CHARS: Record<(typeof BASE62_ALPHABETS)[number]["value"], string>;
@@ -0,0 +1,27 @@
1
+ export const BASE32_ALPHABETS = [
2
+ { value: "base32", label: "Standard (RFC 4648): A-Z2-7=" },
3
+ { value: "base32hex", label: "Extended hex (RFC 4648 §7): 0-9A-V=" },
4
+ ];
5
+ export const BASE32_CHARS = {
6
+ base32: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
7
+ base32hex: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
8
+ };
9
+ export const BASE58_ALPHABETS = [
10
+ { value: "bitcoin", label: "Bitcoin: 1-9A-HJ-NP-Za-km-z" },
11
+ { value: "flickr", label: "Flickr: 1-9a-km-zA-HJ-NP-Z" },
12
+ { value: "ripple", label: "Ripple: rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz" },
13
+ ];
14
+ export const BASE58_CHARS = {
15
+ bitcoin: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
16
+ flickr: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",
17
+ ripple: "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",
18
+ };
19
+ export const BASE62_ALPHABETS = [
20
+ { value: "0-9A-Za-z", label: "Digits, uppercase, lowercase (GMP)" },
21
+ { value: "0-9a-zA-Z", label: "Digits, lowercase, uppercase" },
22
+ ];
23
+ export const BASE62_CHARS = {
24
+ "0-9A-Za-z": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
25
+ "0-9a-zA-Z": "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
26
+ };
27
+ //# sourceMappingURL=alphabets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alphabets.js","sourceRoot":"","sources":["../../../src/operations/base/alphabets.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,8BAA8B,EAAE;IAC1D,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,qCAAqC,EAAE;CAC5D,CAAC;AAIX,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC1D,MAAM,EAAE,kCAAkC;IAC1C,SAAS,EAAE,kCAAkC;CAC9C,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,6BAA6B,EAAE;IAC1D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,4BAA4B,EAAE;IACxD,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,oEAAoE,EAAE;CACxF,CAAC;AAEX,MAAM,CAAC,MAAM,YAAY,GAA+D;IACtF,OAAO,EAAE,4DAA4D;IACrE,MAAM,EAAE,4DAA4D;IACpE,MAAM,EAAE,4DAA4D;CACrE,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,oCAAoC,EAAE;IACnE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,8BAA8B,EAAE;CACrD,CAAC;AAEX,MAAM,CAAC,MAAM,YAAY,GAA+D;IACtF,WAAW,EAAE,gEAAgE;IAC7E,WAAW,EAAE,gEAAgE;CAC9E,CAAC"}
@@ -0,0 +1,33 @@
1
+ export declare const toBase32: import("../../operation.ts").Operation<"to-base32", {
2
+ readonly alphabet: {
3
+ readonly type: "select";
4
+ readonly name: "Alphabet";
5
+ readonly options: readonly [{
6
+ readonly value: "base32";
7
+ readonly label: "Standard (RFC 4648): A-Z2-7=";
8
+ }, {
9
+ readonly value: "base32hex";
10
+ readonly label: "Extended hex (RFC 4648 §7): 0-9A-V=";
11
+ }];
12
+ readonly default: "base32";
13
+ };
14
+ readonly padding: {
15
+ readonly type: "boolean";
16
+ readonly name: "Padding (=)";
17
+ readonly default: true;
18
+ };
19
+ }, "from-base32">;
20
+ export declare const fromBase32: import("../../operation.ts").Operation<"from-base32", {
21
+ readonly alphabet: {
22
+ readonly type: "select";
23
+ readonly name: "Alphabet";
24
+ readonly options: readonly [{
25
+ readonly value: "base32";
26
+ readonly label: "Standard (RFC 4648): A-Z2-7=";
27
+ }, {
28
+ readonly value: "base32hex";
29
+ readonly label: "Extended hex (RFC 4648 §7): 0-9A-V=";
30
+ }];
31
+ readonly default: "base32";
32
+ };
33
+ }, "to-base32">;
@@ -0,0 +1,85 @@
1
+ import { OperationError } from "../../errors.js";
2
+ import { defineOperation } from "../../operation.js";
3
+ import { BASE32_ALPHABETS, BASE32_CHARS } from "./alphabets.js";
4
+ export const toBase32 = defineOperation({
5
+ id: "to-base32",
6
+ name: "To Base32",
7
+ description: 'Encodes raw bytes as Base32 text. e.g. "hello" becomes "NBSWY3DP".',
8
+ category: "Encoding",
9
+ output: "text",
10
+ aliases: ["b32", "base32 encode"],
11
+ inverse: "from-base32",
12
+ infoUrl: "https://wikipedia.org/wiki/Base32",
13
+ args: {
14
+ alphabet: { type: "select", name: "Alphabet", options: BASE32_ALPHABETS, default: "base32" },
15
+ padding: { type: "boolean", name: "Padding (=)", default: true },
16
+ },
17
+ examples: [
18
+ { input: "hello", output: "NBSWY3DP" },
19
+ { input: "hi", output: "NBUQ====" },
20
+ { input: "hi", args: { alphabet: "base32hex", padding: false }, output: "D1KG" },
21
+ ],
22
+ run(input, { alphabet, padding }) {
23
+ const chars = BASE32_CHARS[alphabet];
24
+ let out = "";
25
+ let buffer = 0;
26
+ let bits = 0;
27
+ for (const byte of input) {
28
+ buffer = ((buffer << 8) | byte) & 0xfff;
29
+ bits += 8;
30
+ while (bits >= 5) {
31
+ bits -= 5;
32
+ out += chars[(buffer >> bits) & 31];
33
+ }
34
+ }
35
+ if (bits > 0)
36
+ out += chars[(buffer << (5 - bits)) & 31];
37
+ if (padding)
38
+ out = out.padEnd(Math.ceil(out.length / 8) * 8, "=");
39
+ return new TextEncoder().encode(out);
40
+ },
41
+ });
42
+ // Number of characters in a final group that can encode whole bytes (2 -> 1 byte, 4 -> 2, 5 -> 3, 7 -> 4).
43
+ const VALID_TAIL = new Set([0, 2, 4, 5, 7]);
44
+ export const fromBase32 = defineOperation({
45
+ id: "from-base32",
46
+ name: "From Base32",
47
+ description: 'Decodes Base32 text into raw bytes, ignoring case, whitespace and padding. e.g. "NBSWY3DP" becomes "hello".',
48
+ category: "Encoding",
49
+ output: "binary",
50
+ aliases: ["b32", "base32 decode"],
51
+ inverse: "to-base32",
52
+ infoUrl: "https://wikipedia.org/wiki/Base32",
53
+ args: {
54
+ alphabet: { type: "select", name: "Alphabet", options: BASE32_ALPHABETS, default: "base32" },
55
+ },
56
+ examples: [
57
+ { input: "NBSWY3DP", output: "hello" },
58
+ { input: "nbuq====", output: "hi" },
59
+ { input: "D1KG", args: { alphabet: "base32hex" }, output: "hi" },
60
+ ],
61
+ run(input, { alphabet }) {
62
+ const chars = BASE32_CHARS[alphabet];
63
+ const text = new TextDecoder().decode(input).replace(/\s+/g, "").replace(/=+$/, "").toUpperCase();
64
+ if (!VALID_TAIL.has(text.length % 8)) {
65
+ throw new OperationError("Invalid Base32: truncated input (the last group has an impossible length)");
66
+ }
67
+ const out = new Uint8Array(Math.floor((text.length * 5) / 8));
68
+ let n = 0;
69
+ let buffer = 0;
70
+ let bits = 0;
71
+ for (let i = 0; i < text.length; i++) {
72
+ const value = chars.indexOf(text[i]);
73
+ if (value < 0)
74
+ throw new OperationError(`Invalid Base32: unexpected character "${text[i]}"`);
75
+ buffer = ((buffer << 5) | value) & 0xfff;
76
+ bits += 5;
77
+ if (bits >= 8) {
78
+ bits -= 8;
79
+ out[n++] = (buffer >> bits) & 0xff;
80
+ }
81
+ }
82
+ return out;
83
+ },
84
+ });
85
+ //# sourceMappingURL=base32.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base32.js","sourceRoot":"","sources":["../../../src/operations/base/base32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;IACtC,EAAE,EAAE,WAAW;IACf,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,oEAAoE;IACjF,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE,mCAAmC;IAC5C,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,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,EAAE,CAAC;QAClG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,cAAc,CAAC,2EAA2E,CAAC,CAAC;QACxG,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC;YACtC,IAAI,KAAK,GAAG,CAAC;gBAAE,MAAM,IAAI,cAAc,CAAC,yCAAyC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC7F,MAAM,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;YACzC,IAAI,IAAI,CAAC,CAAC;YACV,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;gBACd,IAAI,IAAI,CAAC,CAAC;gBACV,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC;YACrC,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ export declare const toBase58: import("../../operation.ts").Operation<"to-base58", {
2
+ readonly alphabet: {
3
+ readonly type: "select";
4
+ readonly name: "Alphabet";
5
+ readonly options: readonly [{
6
+ readonly value: "bitcoin";
7
+ readonly label: "Bitcoin: 1-9A-HJ-NP-Za-km-z";
8
+ }, {
9
+ readonly value: "flickr";
10
+ readonly label: "Flickr: 1-9a-km-zA-HJ-NP-Z";
11
+ }, {
12
+ readonly value: "ripple";
13
+ readonly label: "Ripple: rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
14
+ }];
15
+ readonly default: "bitcoin";
16
+ };
17
+ }, "from-base58">;
18
+ export declare const fromBase58: import("../../operation.ts").Operation<"from-base58", {
19
+ readonly alphabet: {
20
+ readonly type: "select";
21
+ readonly name: "Alphabet";
22
+ readonly options: readonly [{
23
+ readonly value: "bitcoin";
24
+ readonly label: "Bitcoin: 1-9A-HJ-NP-Za-km-z";
25
+ }, {
26
+ readonly value: "flickr";
27
+ readonly label: "Flickr: 1-9a-km-zA-HJ-NP-Z";
28
+ }, {
29
+ readonly value: "ripple";
30
+ readonly label: "Ripple: rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
31
+ }];
32
+ readonly default: "bitcoin";
33
+ };
34
+ }, "to-base58">;
@@ -0,0 +1,43 @@
1
+ import { defineOperation } from "../../operation.js";
2
+ import { BASE58_ALPHABETS, BASE58_CHARS } from "./alphabets.js";
3
+ import { decodeBaseX, encodeBaseX } from "./big-number.js";
4
+ export const toBase58 = defineOperation({
5
+ id: "to-base58",
6
+ name: "To Base58",
7
+ description: 'Encodes raw bytes as Base58 text, as used by Bitcoin addresses. Leading zero bytes become "1". e.g. "hello" becomes "Cn8eVZg".',
8
+ category: "Encoding",
9
+ output: "text",
10
+ aliases: ["b58", "base58 encode", "bitcoin"],
11
+ inverse: "from-base58",
12
+ infoUrl: "https://wikipedia.org/wiki/Binary-to-text_encoding#Base58",
13
+ args: {
14
+ alphabet: { type: "select", name: "Alphabet", options: BASE58_ALPHABETS, default: "bitcoin" },
15
+ },
16
+ examples: [
17
+ { input: "hello", output: "Cn8eVZg" },
18
+ { input: "Hello World!", output: "2NEpo7TZRRrLZSi2U" },
19
+ ],
20
+ run: (input, { alphabet }) => new TextEncoder().encode(encodeBaseX(input, BASE58_CHARS[alphabet])),
21
+ });
22
+ export const fromBase58 = defineOperation({
23
+ id: "from-base58",
24
+ name: "From Base58",
25
+ description: 'Decodes Base58 text into raw bytes, ignoring whitespace. e.g. "Cn8eVZg" becomes "hello".',
26
+ category: "Encoding",
27
+ output: "binary",
28
+ aliases: ["b58", "base58 decode", "bitcoin"],
29
+ inverse: "to-base58",
30
+ infoUrl: "https://wikipedia.org/wiki/Binary-to-text_encoding#Base58",
31
+ args: {
32
+ alphabet: { type: "select", name: "Alphabet", options: BASE58_ALPHABETS, default: "bitcoin" },
33
+ },
34
+ examples: [
35
+ { input: "Cn8eVZg", output: "hello" },
36
+ { input: "2NEpo7TZRRrLZSi2U", output: "Hello World!" },
37
+ ],
38
+ run(input, { alphabet }) {
39
+ const text = new TextDecoder().decode(input).replace(/\s+/g, "");
40
+ return decodeBaseX(text, BASE58_CHARS[alphabet], "Base58");
41
+ },
42
+ });
43
+ //# sourceMappingURL=base58.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base58.js","sourceRoot":"","sources":["../../../src/operations/base/base58.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;IACtC,EAAE,EAAE,WAAW;IACf,IAAI,EAAE,WAAW;IACjB,WAAW,EACT,gIAAgI;IAClI,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,CAAC;IAC5C,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE,2DAA2D;IACp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jE,OAAO,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ export declare const toBase62: import("../../operation.ts").Operation<"to-base62", {
2
+ readonly alphabet: {
3
+ readonly type: "select";
4
+ readonly name: "Alphabet";
5
+ readonly options: readonly [{
6
+ readonly value: "0-9A-Za-z";
7
+ readonly label: "Digits, uppercase, lowercase (GMP)";
8
+ }, {
9
+ readonly value: "0-9a-zA-Z";
10
+ readonly label: "Digits, lowercase, uppercase";
11
+ }];
12
+ readonly default: "0-9A-Za-z";
13
+ };
14
+ }, "from-base62">;
15
+ export declare const fromBase62: import("../../operation.ts").Operation<"from-base62", {
16
+ readonly alphabet: {
17
+ readonly type: "select";
18
+ readonly name: "Alphabet";
19
+ readonly options: readonly [{
20
+ readonly value: "0-9A-Za-z";
21
+ readonly label: "Digits, uppercase, lowercase (GMP)";
22
+ }, {
23
+ readonly value: "0-9a-zA-Z";
24
+ readonly label: "Digits, lowercase, uppercase";
25
+ }];
26
+ readonly default: "0-9A-Za-z";
27
+ };
28
+ }, "to-base62">;
@@ -0,0 +1,43 @@
1
+ import { defineOperation } from "../../operation.js";
2
+ import { BASE62_ALPHABETS, BASE62_CHARS } from "./alphabets.js";
3
+ import { decodeBaseX, encodeBaseX } from "./big-number.js";
4
+ export const toBase62 = defineOperation({
5
+ id: "to-base62",
6
+ name: "To Base62",
7
+ description: 'Encodes raw bytes as Base62 text (letters and digits only). Leading zero bytes become "0". e.g. "hello" becomes "7tQLFHz".',
8
+ category: "Encoding",
9
+ output: "text",
10
+ aliases: ["b62", "base62 encode"],
11
+ inverse: "from-base62",
12
+ infoUrl: "https://wikipedia.org/wiki/Base62",
13
+ args: {
14
+ alphabet: { type: "select", name: "Alphabet", options: BASE62_ALPHABETS, default: "0-9A-Za-z" },
15
+ },
16
+ examples: [
17
+ { input: "hello", output: "7tQLFHz" },
18
+ { input: "hello", args: { alphabet: "0-9a-zA-Z" }, output: "7TqlfhZ" },
19
+ ],
20
+ run: (input, { alphabet }) => new TextEncoder().encode(encodeBaseX(input, BASE62_CHARS[alphabet])),
21
+ });
22
+ export const fromBase62 = defineOperation({
23
+ id: "from-base62",
24
+ name: "From Base62",
25
+ description: 'Decodes Base62 text into raw bytes, ignoring whitespace. e.g. "7tQLFHz" becomes "hello".',
26
+ category: "Encoding",
27
+ output: "binary",
28
+ aliases: ["b62", "base62 decode"],
29
+ inverse: "to-base62",
30
+ infoUrl: "https://wikipedia.org/wiki/Base62",
31
+ args: {
32
+ alphabet: { type: "select", name: "Alphabet", options: BASE62_ALPHABETS, default: "0-9A-Za-z" },
33
+ },
34
+ examples: [
35
+ { input: "7tQLFHz", output: "hello" },
36
+ { input: "7TqlfhZ", args: { alphabet: "0-9a-zA-Z" }, output: "hello" },
37
+ ],
38
+ run(input, { alphabet }) {
39
+ const text = new TextDecoder().decode(input).replace(/\s+/g, "");
40
+ return decodeBaseX(text, BASE62_CHARS[alphabet], "Base62");
41
+ },
42
+ });
43
+ //# sourceMappingURL=base62.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base62.js","sourceRoot":"","sources":["../../../src/operations/base/base62.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;IACtC,EAAE,EAAE,WAAW;IACf,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,4HAA4H;IACzI,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE,mCAAm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EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjE,OAAO,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ type Base64Alphabet = "base64" | "base64url";
2
+ export declare function encodeBase64(input: Uint8Array, alphabet: Base64Alphabet, padding: boolean): Uint8Array;
3
+ export declare function decodeBase64(input: Uint8Array, alphabet: Base64Alphabet, strict: boolean): Uint8Array;
4
+ export declare const toBase64: import("../../operation.ts").Operation<"to-base64", {
5
+ readonly padding: {
6
+ readonly type: "boolean";
7
+ readonly name: "Padding (=)";
8
+ readonly default: true;
9
+ };
10
+ }, "from-base64">;
11
+ export declare const fromBase64: import("../../operation.ts").Operation<"from-base64", {
12
+ readonly strict: {
13
+ readonly type: "boolean";
14
+ readonly name: "Strict mode";
15
+ readonly description: "Fail on non-alphabet characters and invalid padding instead of ignoring them.";
16
+ readonly default: false;
17
+ };
18
+ }, "to-base64">;
19
+ export {};
@@ -0,0 +1,72 @@
1
+ import { OperationError } from "../../errors.js";
2
+ import { defineOperation } from "../../operation.js";
3
+ const NON_ALPHABET = {
4
+ base64: /[^A-Za-z0-9+/]/g,
5
+ base64url: /[^A-Za-z0-9\-_]/g,
6
+ };
7
+ function invalidInput(text, alphabet, strict) {
8
+ if (strict) {
9
+ const unpadded = text.replace(/=+$/, "");
10
+ const bad = new RegExp(NON_ALPHABET[alphabet].source).exec(unpadded);
11
+ if (bad)
12
+ return new OperationError(`Invalid Base64: unexpected character "${bad[0]}" at offset ${bad.index}`);
13
+ return new OperationError("Invalid Base64: missing or incorrect padding");
14
+ }
15
+ return new OperationError("Invalid Base64: truncated input (the last group has a single character)");
16
+ }
17
+ export function encodeBase64(input, alphabet, padding) {
18
+ return new TextEncoder().encode(input.toBase64({ alphabet, omitPadding: !padding }));
19
+ }
20
+ export function decodeBase64(input, alphabet, strict) {
21
+ let text = new TextDecoder().decode(input);
22
+ if (!strict)
23
+ text = text.replace(NON_ALPHABET[alphabet], "");
24
+ try {
25
+ return Uint8Array.fromBase64(text, { alphabet, lastChunkHandling: strict ? "strict" : "loose" });
26
+ }
27
+ catch {
28
+ throw invalidInput(text, alphabet, strict);
29
+ }
30
+ }
31
+ export const toBase64 = defineOperation({
32
+ id: "to-base64",
33
+ name: "To Base64",
34
+ description: 'Encodes raw bytes as Base64 text. e.g. "hello" becomes "aGVsbG8=".',
35
+ category: "Encoding",
36
+ output: "text",
37
+ aliases: ["b64", "base64 encode"],
38
+ inverse: "from-base64",
39
+ infoUrl: "https://wikipedia.org/wiki/Base64",
40
+ args: {
41
+ padding: { type: "boolean", name: "Padding (=)", default: true },
42
+ },
43
+ examples: [
44
+ { input: "hello", output: "aGVsbG8=" },
45
+ { input: "hello", args: { padding: false }, output: "aGVsbG8" },
46
+ ],
47
+ run: (input, { padding }) => encodeBase64(input, "base64", padding),
48
+ });
49
+ export const fromBase64 = defineOperation({
50
+ id: "from-base64",
51
+ name: "From Base64",
52
+ description: 'Decodes Base64 text into raw bytes. e.g. "aGVsbG8=" becomes "hello".',
53
+ category: "Encoding",
54
+ output: "binary",
55
+ aliases: ["b64", "base64 decode"],
56
+ inverse: "to-base64",
57
+ infoUrl: "https://wikipedia.org/wiki/Base64",
58
+ args: {
59
+ strict: {
60
+ type: "boolean",
61
+ name: "Strict mode",
62
+ description: "Fail on non-alphabet characters and invalid padding instead of ignoring them.",
63
+ default: false,
64
+ },
65
+ },
66
+ examples: [
67
+ { input: "aGVsbG8=", output: "hello" },
68
+ { input: "aGVs\nbG8", output: "hello" },
69
+ ],
70
+ run: (input, { strict }) => decodeBase64(input, "base64", strict),
71
+ });
72
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../../src/operations/base/base64.ts"],"names":[],"mappings":"AAAA,OA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EAAE,mCAAmC;IAC5C,IAAI,EAAE;QACJ,MAAM,EAAE;YACN,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,+EAA+E;YAC5F,OAAO,EAAE,KAAK;SACf;KACF;IACD,QAAQ,EAAE;QACR,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE;QACtC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE;KACxC;IACD,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC;CAClE,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare const toBase64url: import("../../operation.ts").Operation<"to-base64url", {
2
+ readonly padding: {
3
+ readonly type: "boolean";
4
+ readonly name: "Padding (=)";
5
+ readonly default: false;
6
+ };
7
+ }, "from-base64url">;
8
+ export declare const fromBase64url: import("../../operation.ts").Operation<"from-base64url", {
9
+ readonly strict: {
10
+ readonly type: "boolean";
11
+ readonly name: "Strict mode";
12
+ readonly description: "Fail on non-alphabet characters and invalid padding instead of ignoring them.";
13
+ readonly default: false;
14
+ };
15
+ }, "to-base64url">;
@@ -0,0 +1,44 @@
1
+ import { defineOperation } from "../../operation.js";
2
+ import { decodeBase64, encodeBase64 } from "./base64.js";
3
+ export const toBase64url = defineOperation({
4
+ id: "to-base64url",
5
+ name: "To Base64url",
6
+ description: 'Encodes raw bytes as URL-safe Base64 (- and _ instead of + and /), without padding by default. e.g. "ÿÿ" becomes "w7_Dvw".',
7
+ category: "Encoding",
8
+ output: "text",
9
+ aliases: ["b64url", "base64url encode"],
10
+ inverse: "from-base64url",
11
+ infoUrl: "https://datatracker.ietf.org/doc/html/rfc4648#section-5",
12
+ args: {
13
+ padding: { type: "boolean", name: "Padding (=)", default: false },
14
+ },
15
+ examples: [
16
+ { input: "ÿÿ", output: "w7_Dvw" },
17
+ { input: "ÿÿ", args: { padding: true }, output: "w7_Dvw==" },
18
+ ],
19
+ run: (input, { padding }) => encodeBase64(input, "base64url", padding),
20
+ });
21
+ export const fromBase64url = defineOperation({
22
+ id: "from-base64url",
23
+ name: "From Base64url",
24
+ description: 'Decodes URL-safe Base64 (- and _ instead of + and /) into raw bytes. e.g. "w7_Dvw" becomes "ÿÿ".',
25
+ category: "Encoding",
26
+ output: "binary",
27
+ aliases: ["b64url", "base64url decode", "jwt"],
28
+ inverse: "to-base64url",
29
+ infoUrl: "https://datatracker.ietf.org/doc/html/rfc4648#section-5",
30
+ args: {
31
+ strict: {
32
+ type: "boolean",
33
+ name: "Strict mode",
34
+ description: "Fail on non-alphabet characters and invalid padding instead of ignoring them.",
35
+ default: false,
36
+ },
37
+ },
38
+ examples: [
39
+ { input: "w7_Dvw", output: "ÿÿ" },
40
+ { input: "w7_Dvw==", output: "ÿÿ" },
41
+ ],
42
+ run: (input, { strict }) => decodeBase64(input, "base64url", strict),
43
+ });
44
+ //# sourceMappingURL=base64url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64url.js","sourceRoot":"","sources":["../../../src/operations/base/base64url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC;IACzC,EAAE,EAAE,cAAc;IAClB,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,4HAA4H;IACzI,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,gBAAgB;IACzB,OAAO,EAAE,yDAAyD;IAClE,IAAI,EAAE;QACJ,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE;KAClE;IACD,QAAQ,EAAE;QACR,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE;QACjC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;KAC7D;IACD,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC;CACvE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;IAC3C,EAAE,EAAE,gBAAgB;IACpB,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,kGAAkG;IAC/G,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,CAAC,QAAQ,EAAE,kBAAkB,EAAE,KAAK,CAAC;IAC9C,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,yDAAyD;IAClE,IAAI,EAAE;QACJ,MAAM,EAAE;YACN,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,+EAA+E;YAC5F,OAAO,EAAE,KAAK;SACf;KACF;IACD,QAAQ,EAAE;QACR,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;QACjC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE;KACpC;IACD,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC;CACrE,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Encodes bytes as a big number in the given base. Each leading zero byte becomes the alphabet's
3
+ * first character, so they survive a round trip (as in Bitcoin's Base58).
4
+ */
5
+ export declare function encodeBaseX(input: Uint8Array, alphabet: string): string;
6
+ export declare function decodeBaseX(text: string, alphabet: string, name: string): Uint8Array;