@lumjs/encode 2.5.0 → 2.6.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.
- package/CHANGELOG.md +5 -1
- package/jsdoc.js +6 -0
- package/lib/hash.js +1 -1
- package/lum.build.js +24 -0
- package/package.json +73 -30
- package/tsconfig.json +12 -0
- package/types/auto/base32.d.ts +72 -0
- package/types/auto/base32.d.ts.map +1 -0
- package/types/auto/base64.d.ts +258 -0
- package/types/auto/base64.d.ts.map +1 -0
- package/types/auto/base91.d.ts +3 -0
- package/types/auto/base91.d.ts.map +1 -0
- package/types/auto/hash.d.ts +216 -0
- package/types/auto/hash.d.ts.map +1 -0
- package/types/auto/hmac.d.ts +35 -0
- package/types/auto/hmac.d.ts.map +1 -0
- package/types/auto/hotp.d.ts +42 -0
- package/types/auto/hotp.d.ts.map +1 -0
- package/types/auto/index.d.ts +2 -0
- package/types/auto/index.d.ts.map +1 -0
- package/types/auto/pem.d.ts +62 -0
- package/types/auto/pem.d.ts.map +1 -0
- package/types/auto/polyfill.d.ts +72 -0
- package/types/auto/polyfill.d.ts.map +1 -0
- package/types/auto/signature.d.ts +25 -0
- package/types/auto/signature.d.ts.map +1 -0
- package/types/auto/totp.d.ts +22 -0
- package/types/auto/totp.d.ts.map +1 -0
- package/types/auto/util.d.ts +26 -0
- package/types/auto/util.d.ts.map +1 -0
- package/types/sets/_inc.d.ts +6 -0
- package/types/sets/all.d.ts +2 -0
- package/types/sets/base.d.ts +6 -0
- package/types/sets/digest.d.ts +4 -0
- package/types/sets/otp.d.ts +5 -0
- package/types/sets/sign.d.ts +6 -0
- package/jsdoc.json +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [2.6.0] - 2026-02-24
|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
## [2.5.0] - 2026-02-20
|
|
10
13
|
### Added
|
|
11
14
|
- A bunch of extra exports that are _module-sets_.
|
|
@@ -106,7 +109,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
106
109
|
### Added
|
|
107
110
|
- Initial release.
|
|
108
111
|
|
|
109
|
-
[Unreleased]: https://github.com/supernovus/lum.encode.js/compare/v2.
|
|
112
|
+
[Unreleased]: https://github.com/supernovus/lum.encode.js/compare/v2.6.0...HEAD
|
|
113
|
+
[2.6.0]: https://github.com/supernovus/lum.encode.js/compare/v2.5.0...v2.6.0
|
|
110
114
|
[2.5.0]: https://github.com/supernovus/lum.encode.js/compare/v2.4.1...v2.5.0
|
|
111
115
|
[2.4.1]: https://github.com/supernovus/lum.encode.js/compare/v2.4.0...v2.4.1
|
|
112
116
|
[2.4.0]: https://github.com/supernovus/lum.encode.js/compare/v2.3.2...v2.4.0
|
package/jsdoc.js
ADDED
package/lib/hash.js
CHANGED
package/lum.build.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = function(rb)
|
|
2
|
+
{
|
|
3
|
+
rb.project
|
|
4
|
+
.add('index')
|
|
5
|
+
.types('./types/auto')
|
|
6
|
+
.add('base32')
|
|
7
|
+
.add('base64')
|
|
8
|
+
.add('base91')
|
|
9
|
+
.add('hash')
|
|
10
|
+
.add('hmac')
|
|
11
|
+
.add('hotp')
|
|
12
|
+
.add('polyfill')
|
|
13
|
+
.add('signature')
|
|
14
|
+
.add('totp')
|
|
15
|
+
.add('util')
|
|
16
|
+
.src('./lib/sets')
|
|
17
|
+
.types('./types/sets')
|
|
18
|
+
.add('all')
|
|
19
|
+
.add('base')
|
|
20
|
+
.add('digest')
|
|
21
|
+
.add('otp')
|
|
22
|
+
.add('sign')
|
|
23
|
+
.save();
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumjs/encode",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
|
-
"exports":
|
|
6
|
-
{
|
|
5
|
+
"exports": {
|
|
7
6
|
".": "./lib/index.js",
|
|
8
|
-
"./
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"./
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"./
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"./
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
"./base32": {
|
|
8
|
+
"types": "./types/auto/base32.d.ts",
|
|
9
|
+
"default": "./lib/base32.js"
|
|
10
|
+
},
|
|
11
|
+
"./base64": {
|
|
12
|
+
"types": "./types/auto/base64.d.ts",
|
|
13
|
+
"default": "./lib/base64.js"
|
|
14
|
+
},
|
|
15
|
+
"./base91": {
|
|
16
|
+
"types": "./types/auto/base91.d.ts",
|
|
17
|
+
"default": "./lib/base91.js"
|
|
18
|
+
},
|
|
19
|
+
"./hash": {
|
|
20
|
+
"types": "./types/auto/hash.d.ts",
|
|
21
|
+
"default": "./lib/hash.js"
|
|
22
|
+
},
|
|
23
|
+
"./hmac": {
|
|
24
|
+
"types": "./types/auto/hmac.d.ts",
|
|
25
|
+
"default": "./lib/hmac.js"
|
|
26
|
+
},
|
|
27
|
+
"./hotp": {
|
|
28
|
+
"types": "./types/auto/hotp.d.ts",
|
|
29
|
+
"default": "./lib/hotp.js"
|
|
30
|
+
},
|
|
31
|
+
"./polyfill": {
|
|
32
|
+
"types": "./types/auto/polyfill.d.ts",
|
|
33
|
+
"default": "./lib/polyfill.js"
|
|
34
|
+
},
|
|
35
|
+
"./signature": {
|
|
36
|
+
"types": "./types/auto/signature.d.ts",
|
|
37
|
+
"default": "./lib/signature.js"
|
|
38
|
+
},
|
|
39
|
+
"./totp": {
|
|
40
|
+
"types": "./types/auto/totp.d.ts",
|
|
41
|
+
"default": "./lib/totp.js"
|
|
42
|
+
},
|
|
43
|
+
"./util": {
|
|
44
|
+
"types": "./types/auto/util.d.ts",
|
|
45
|
+
"default": "./lib/util.js"
|
|
46
|
+
},
|
|
47
|
+
"./all": {
|
|
48
|
+
"types": "./types/sets/all.d.ts",
|
|
49
|
+
"default": "./lib/sets/all.js"
|
|
50
|
+
},
|
|
51
|
+
"./base": {
|
|
52
|
+
"types": "./types/sets/base.d.ts",
|
|
53
|
+
"default": "./lib/sets/base.js"
|
|
54
|
+
},
|
|
55
|
+
"./digest": {
|
|
56
|
+
"types": "./types/sets/digest.d.ts",
|
|
57
|
+
"default": "./lib/sets/digest.js"
|
|
58
|
+
},
|
|
59
|
+
"./otp": {
|
|
60
|
+
"types": "./types/sets/otp.d.ts",
|
|
61
|
+
"default": "./lib/sets/otp.js"
|
|
62
|
+
},
|
|
63
|
+
"./sign": {
|
|
64
|
+
"types": "./types/sets/sign.d.ts",
|
|
65
|
+
"default": "./lib/sets/sign.js"
|
|
66
|
+
},
|
|
24
67
|
"./package.json": "./package.json"
|
|
25
68
|
},
|
|
26
69
|
"license": "MIT",
|
|
27
|
-
"repository":
|
|
28
|
-
{
|
|
70
|
+
"repository": {
|
|
29
71
|
"type": "git",
|
|
30
72
|
"url": "https://github.com/supernovus/lum.encode.js.git"
|
|
31
73
|
},
|
|
32
|
-
"dependencies":
|
|
33
|
-
{
|
|
74
|
+
"dependencies": {
|
|
34
75
|
"@lumjs/core": "^1.28.0"
|
|
35
76
|
},
|
|
36
|
-
"devDependencies":
|
|
37
|
-
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@lumjs/build": "^1.2.0",
|
|
38
79
|
"@lumjs/tests": "^2.0.0"
|
|
39
80
|
},
|
|
40
|
-
"scripts":
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"build-
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "npm run build-types && npm run build-meta && npm run build-docs",
|
|
83
|
+
"build-docs": "jsdoc -c ./jsdoc.js",
|
|
84
|
+
"build-meta": "lum-build",
|
|
85
|
+
"build-types": "npx -p typescript tsc",
|
|
86
|
+
"test": "node ./node_modules/@lumjs/tests/bin/lumtest.js"
|
|
44
87
|
}
|
|
45
|
-
}
|
|
88
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
// I would use ["lib/**/*"] except I have no idea how to get typescript
|
|
3
|
+
// to recognise 'sets' aliases, so I'm building those .d.ts files by hand.
|
|
4
|
+
"include": ["lib/*.js"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"emitDeclarationOnly": true,
|
|
9
|
+
"outDir": "types/auto",
|
|
10
|
+
"declarationMap": true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export namespace Base32Types {
|
|
2
|
+
export default Base32Types.rfc4648;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Encode a value into a Base32 string.
|
|
6
|
+
*
|
|
7
|
+
* @param {(ArrayBuffer|TypedArray|string)} data - Data to be encoded.
|
|
8
|
+
*
|
|
9
|
+
* If this is a string it will be converted into a Uint8Array using a
|
|
10
|
+
* TextEncoder instance.
|
|
11
|
+
*
|
|
12
|
+
* @param {(object|string|boolean)} [opts] Options.
|
|
13
|
+
*
|
|
14
|
+
* If this is a boolean it will be used as `opts.pad`.
|
|
15
|
+
*
|
|
16
|
+
* If this is a string or one of the `Base32Types` properties,
|
|
17
|
+
* it will be used as `opts.type`.
|
|
18
|
+
*
|
|
19
|
+
* @param {(string|Array)} [opts.type] Base32 variant to use.
|
|
20
|
+
*
|
|
21
|
+
* If this is a string it must be the name (uppercase or lowercase)
|
|
22
|
+
* of one of the properties in the `Base32Types` object.
|
|
23
|
+
*
|
|
24
|
+
* If it is an Array it is expected that it is one of the properties
|
|
25
|
+
* from the Base32Types, or a compatible type def where the first
|
|
26
|
+
* item in the array is a string consisting of exactly 32 unique characters.
|
|
27
|
+
*
|
|
28
|
+
* @param {boolean} [opts.pad=true] Add `=` padding characters?
|
|
29
|
+
*
|
|
30
|
+
* Base32 (like Base64) uses `=` as a padding character to ensure the length
|
|
31
|
+
* of the encoded strings are divisible by 8. As that is a part of
|
|
32
|
+
* the standard specification, this option defaults to true.
|
|
33
|
+
*
|
|
34
|
+
* If you explicitly set this to false the string won't have any padding
|
|
35
|
+
* added to it, regardless of its length.
|
|
36
|
+
*
|
|
37
|
+
* @returns {string}
|
|
38
|
+
* @alias module:@lumjs/encode/base32.encode
|
|
39
|
+
*/
|
|
40
|
+
export function base32Encode(buf: any, opts?: (object | string | boolean)): string;
|
|
41
|
+
/**
|
|
42
|
+
* Decode a Base32-encoded string.
|
|
43
|
+
* @param {string} str - Base32 string.
|
|
44
|
+
* @param {(object|string)} [opts] Options.
|
|
45
|
+
*
|
|
46
|
+
* If this is a boolean it will be used as `opts.string`.
|
|
47
|
+
*
|
|
48
|
+
* If this is a string or one of the `Base32Types` properties,
|
|
49
|
+
* it will be used as `opts.type`.
|
|
50
|
+
*
|
|
51
|
+
* @param {(string|Array)} [opts.type] Base32 variant to use.
|
|
52
|
+
*
|
|
53
|
+
* If this is a string it must be the name (uppercase or lowercase)
|
|
54
|
+
* of one of the properties in the `Base32Types` object.
|
|
55
|
+
*
|
|
56
|
+
* If it is an Array it is expected that it is one of the properties
|
|
57
|
+
* from the Base32Types, or a compatible type def where the first
|
|
58
|
+
* item in the array is a string consisting of exactly 32 unique characters.
|
|
59
|
+
*
|
|
60
|
+
* @param {boolean} [opts.string=false] Return a UTF-8 string?
|
|
61
|
+
*
|
|
62
|
+
* If this is true then we will assume the original encoded value was a UTF-8
|
|
63
|
+
* string, and will decode it as such using a TextDecoder instance.
|
|
64
|
+
*
|
|
65
|
+
* If this is false (the default) we will return a Uint8Array.
|
|
66
|
+
*
|
|
67
|
+
* @returns {(Uint8Array|string)}
|
|
68
|
+
* @alias module:@lumjs/encode/base32.decode
|
|
69
|
+
*/
|
|
70
|
+
export function base32Decode(str: string, opts?: (object | string)): (Uint8Array | string);
|
|
71
|
+
export { Base32Types as TYPES, base32Encode as encode, base32Decode as decode };
|
|
72
|
+
//# sourceMappingURL=base32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../../lib/base32.js"],"names":[],"mappings":";;;AA0JA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,8CA5BW,CAAC,MAAM,GAAC,MAAM,GAAC,OAAO,CAAC,GAyBrB,MAAM,CAiClB;AAvHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,kCA3BW,MAAM,SACN,CAAC,MAAM,GAAC,MAAM,CAAC,GAuBb,CAAC,UAAU,GAAC,MAAM,CAAC,CAyB/B"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64 functions.
|
|
3
|
+
*
|
|
4
|
+
* Several functions based on code from MDN guides:
|
|
5
|
+
* https://developer.mozilla.org/en-US/docs/Glossary/Base64
|
|
6
|
+
*
|
|
7
|
+
* @module @lumjs/encode/base64
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Make a Base64 string URL-safe.
|
|
11
|
+
*
|
|
12
|
+
* Converts `+` to `-` and `/` to `_`.
|
|
13
|
+
* By default it also strips `=` padding characters.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} string - A Base64-encoded string
|
|
16
|
+
* @param {object} [options] Options
|
|
17
|
+
* @param {boolean} [options.useTildes=false] Use tildes?
|
|
18
|
+
*
|
|
19
|
+
* Replaces `=` with `~` characters instead of stripping them.
|
|
20
|
+
* This option is for backwards-compatibility with old code only,
|
|
21
|
+
* and there's no reason to use it these days.
|
|
22
|
+
*
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
export function urlize(string: string, options?: {
|
|
26
|
+
useTildes?: boolean;
|
|
27
|
+
}): string;
|
|
28
|
+
/**
|
|
29
|
+
* Undoes the effects of `urlize()`
|
|
30
|
+
*
|
|
31
|
+
* Doesn't matter if the string has actually been passed to `urlize()`,
|
|
32
|
+
* nor if the obsolete `options.useTildes` option was used when encoding.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} string
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
export function deurlize(string: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Convert a Base64-encoded string into a Uint8Array.
|
|
40
|
+
*
|
|
41
|
+
* This is a low-level function with minimal options.
|
|
42
|
+
* See `decodeText()` for a more full-featured function.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} base64 - Base64 encoded-string.
|
|
45
|
+
* @param {object} [options] Options.
|
|
46
|
+
* @param {boolean} [options.native=true] Use fromBase64() if it exists?
|
|
47
|
+
*
|
|
48
|
+
* When enabled, this checks to see if `Uint8Array.fromBase64()` exists,
|
|
49
|
+
* and if it does, will use it, passing the options to it.
|
|
50
|
+
*
|
|
51
|
+
* If this is disabled, the original toBytes algorithm will be used.
|
|
52
|
+
*
|
|
53
|
+
* This option is enabled by default, the only reason I could think of to
|
|
54
|
+
* disable it is if you are using this function as a polyfill.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Uint8Array}
|
|
57
|
+
*/
|
|
58
|
+
export function toBytes(base64: string, options?: {
|
|
59
|
+
native?: boolean;
|
|
60
|
+
}): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* Convert a Uint8Array into Base64-encoded string.
|
|
63
|
+
*
|
|
64
|
+
* This is a low-level function with no options.
|
|
65
|
+
* See `encodeText()` for a more full-featured function.
|
|
66
|
+
*
|
|
67
|
+
* @param {Uint8Array} bytes - Byte array to convert.
|
|
68
|
+
* @param {object} [options] Options.
|
|
69
|
+
* @param {boolean} [options.native=true] Use toBase64() if it exists?
|
|
70
|
+
*
|
|
71
|
+
* When enabled, this checks to see if `bytes.toBase64()` exists,
|
|
72
|
+
* and if it does, will use it, passing the options to it.
|
|
73
|
+
*
|
|
74
|
+
* If this is disabled, the original fromBytes algorithm will be used.
|
|
75
|
+
*
|
|
76
|
+
* This option is enabled by default, the only reason I could think of to
|
|
77
|
+
* disable it is if you are using this function as a polyfill.
|
|
78
|
+
*
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
export function fromBytes(bytes: Uint8Array, options?: {
|
|
82
|
+
native?: boolean;
|
|
83
|
+
}): string;
|
|
84
|
+
/**
|
|
85
|
+
* Encode a string to Base64.
|
|
86
|
+
*
|
|
87
|
+
* This adds a bunch of extra features on top of `fromBytes()`,
|
|
88
|
+
* including optionally passing the output through `urlize()`.
|
|
89
|
+
*
|
|
90
|
+
* @param {(string|Uint8Array)} data - Data to be encoded.
|
|
91
|
+
*
|
|
92
|
+
* If this is a String we'll use a `TextEncoder` instance to
|
|
93
|
+
* convert it into a Uint8Array before passing it to fromBytes().
|
|
94
|
+
*
|
|
95
|
+
* If this is a Uint8Array, we can skip the TextEncoder part.
|
|
96
|
+
*
|
|
97
|
+
* @param {(object|boolean)} [options] Options.
|
|
98
|
+
*
|
|
99
|
+
* - If boolean, used as `options.url`.
|
|
100
|
+
* - Passed to urlize() if `options.url` is true.
|
|
101
|
+
* - Always passed to fromBytes().
|
|
102
|
+
*
|
|
103
|
+
* @param {boolean} [options.url=false] Urlize the output?
|
|
104
|
+
* If true, converts `+`, `/`, and `=` to URL-friendly alternatives.
|
|
105
|
+
*
|
|
106
|
+
* @returns {string} A Base64-encoded string
|
|
107
|
+
*/
|
|
108
|
+
export function encodeText(data: (string | Uint8Array), options?: (object | boolean)): string;
|
|
109
|
+
/**
|
|
110
|
+
* Decode a Base64 string into a Unicode string.
|
|
111
|
+
*
|
|
112
|
+
* Uses `toBytes()` and the `TextDecoder` API.
|
|
113
|
+
* Will pass input through `deurlize()` by default.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} base64 - A Base64 string to decode
|
|
116
|
+
* @param {(object|boolean)} [options] Options
|
|
117
|
+
*
|
|
118
|
+
* - If `boolean`, used as `options.url`
|
|
119
|
+
* - Passed to `new TextDecoder()`
|
|
120
|
+
* - Passed to `decoder.decode()`
|
|
121
|
+
*
|
|
122
|
+
* @param {boolean} [options.string=true] Decode as a string?
|
|
123
|
+
* @param {boolean} [options.url=true] Deurlize the base64 string?
|
|
124
|
+
*
|
|
125
|
+
* Unless this is explicitly set as `false`, the `base64`
|
|
126
|
+
* string will be passed to `deurlize()` before being
|
|
127
|
+
* processed further.
|
|
128
|
+
*
|
|
129
|
+
* @returns {(string|Uint8Array)}
|
|
130
|
+
* Returned type depends on `opts.string`.
|
|
131
|
+
*/
|
|
132
|
+
export function decodeText(base64: string, options?: (object | boolean)): (string | Uint8Array);
|
|
133
|
+
/**
|
|
134
|
+
* Encode binary data into a Base64-encoded Data URL.
|
|
135
|
+
*
|
|
136
|
+
* @param {(File|Blob|Array|TypedArray|ArrayBuffer)} data - Data to encode
|
|
137
|
+
*
|
|
138
|
+
* If this is not a `Blob` or `File`, it will be converted into one.
|
|
139
|
+
*
|
|
140
|
+
* @param {object} [options] Options
|
|
141
|
+
*
|
|
142
|
+
* @param {object} [options.blob] Options for Blob instances.
|
|
143
|
+
*
|
|
144
|
+
* If specified, this will be passed to the `Blob()` constructor.
|
|
145
|
+
*
|
|
146
|
+
* Only used if `data` is not already a `Blob` or `File` instance,
|
|
147
|
+
* and `options.file` was not specified or set to `false`.
|
|
148
|
+
*
|
|
149
|
+
* @param {(object|boolean)} [options.file] Options for File instances.
|
|
150
|
+
*
|
|
151
|
+
* If this is any non-false value, and `data` is not already a `Blob`,
|
|
152
|
+
* then we will convert `data` into a `File` instance instead of a `Blob`.
|
|
153
|
+
*
|
|
154
|
+
* If this is an `object`, it will be passed to the `File()` constructor.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} [options.file.name] Filename for the `File` instance.
|
|
157
|
+
*
|
|
158
|
+
* This is likely never needed, but is kept for completion sake.
|
|
159
|
+
*
|
|
160
|
+
* @returns {Promise<string>} Resolves to the Data URL
|
|
161
|
+
*/
|
|
162
|
+
export function toDataUrl(data: (File | Blob | any[] | TypedArray | ArrayBuffer), options?: {
|
|
163
|
+
blob?: object;
|
|
164
|
+
file?: (object | boolean);
|
|
165
|
+
}): Promise<string>;
|
|
166
|
+
/**
|
|
167
|
+
* Decode a Data URL into arbitrary binary data.
|
|
168
|
+
*
|
|
169
|
+
* @param {string} dataUrl - A valid Data URL
|
|
170
|
+
* @param {object} [options] Options
|
|
171
|
+
* @param {boolean} [options.response=false] Return `Response`
|
|
172
|
+
* @param {boolean} [options.buffer=false] Return `ArrayBuffer`
|
|
173
|
+
*
|
|
174
|
+
* @returns {Promise<(Uint8Array|ArrayBuffer|Response)>} Promise of data
|
|
175
|
+
*
|
|
176
|
+
* By default this resolves to a `Uint8Array` instance.
|
|
177
|
+
*
|
|
178
|
+
* See `options.response` and `options.buffer` for alternative values that
|
|
179
|
+
* this may resolve to if requested.
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
export function fromDataUrl(dataUrl: string, options?: {
|
|
183
|
+
response?: boolean;
|
|
184
|
+
buffer?: boolean;
|
|
185
|
+
}): Promise<(Uint8Array | ArrayBuffer | Response)>;
|
|
186
|
+
/**
|
|
187
|
+
* A wrapper around `toDataUrl()` that strips the Data URL header,
|
|
188
|
+
* leaving just the Base64 string, and can emit URL-safe strings.
|
|
189
|
+
*
|
|
190
|
+
* @param {mixed} data - See `toDataUrl()` for valid values
|
|
191
|
+
* @param {object} [options] Options
|
|
192
|
+
*
|
|
193
|
+
* - Passed to `toDataUrl()`
|
|
194
|
+
* - Passed to `urlize()` if `options.url` is `true`
|
|
195
|
+
*
|
|
196
|
+
* @param {boolean} [options.url=false] Use `urlize()` on encoded string?
|
|
197
|
+
*
|
|
198
|
+
* @returns {Promise<string>} Resolves to a Base64 string
|
|
199
|
+
*/
|
|
200
|
+
export function encodeData(data: mixed, options?: {
|
|
201
|
+
url?: boolean;
|
|
202
|
+
}): Promise<string>;
|
|
203
|
+
/**
|
|
204
|
+
* A wrapper around `fromDataUrl()` that adds a Data URL header
|
|
205
|
+
* if necessary, and can handle URL-safe Base64 strings.
|
|
206
|
+
*
|
|
207
|
+
* @param {*} base64
|
|
208
|
+
* @param {*} options
|
|
209
|
+
*
|
|
210
|
+
* - Passed to `fromDataUrl()`
|
|
211
|
+
* - Passed to `deurlize()` if `options.url` is NOT set to `false`
|
|
212
|
+
*
|
|
213
|
+
* @param {boolean} [options.url=true] Use `deurlize()` on decoded string?
|
|
214
|
+
*
|
|
215
|
+
* @returns {Promise} See `fromDataUrl()` for more details
|
|
216
|
+
*/
|
|
217
|
+
export function decodeData(base64: any, options?: any): Promise<any>;
|
|
218
|
+
/**
|
|
219
|
+
* Encode data into a base64 string
|
|
220
|
+
*
|
|
221
|
+
* Uses `encodeText()` unless the `data` or `options` have specific
|
|
222
|
+
* values that indicate `encodeData()` should be used instead.
|
|
223
|
+
*
|
|
224
|
+
* @param {*} data - Data to encode
|
|
225
|
+
*
|
|
226
|
+
* If this is anything other than a `string`, `encodeData()` will be used.
|
|
227
|
+
*
|
|
228
|
+
* @param {object} [options] Options
|
|
229
|
+
*
|
|
230
|
+
* If either `options.blob` or `options.file` are specified,
|
|
231
|
+
* `encodeData()` will be used.
|
|
232
|
+
*
|
|
233
|
+
* @returns {(string|Promise<string>)}
|
|
234
|
+
* See `encodeText()` and `encodeData()` for details.
|
|
235
|
+
*/
|
|
236
|
+
export function encode(data: any, options?: object): (string | Promise<string>);
|
|
237
|
+
/**
|
|
238
|
+
* Decode a base64 string into data
|
|
239
|
+
*
|
|
240
|
+
* Uses `decodeText()` unless the `base64` or `options` have specific
|
|
241
|
+
* values that indicate `decodeData()` should be used.
|
|
242
|
+
*
|
|
243
|
+
* @param {string} base64 - Base64-encoded string (or a Data URL).
|
|
244
|
+
*
|
|
245
|
+
* If this begins with a Data URL header, `decodeData()` will be used.
|
|
246
|
+
*
|
|
247
|
+
* @param {object} [options] Options
|
|
248
|
+
*
|
|
249
|
+
* If either `options.response` or `options.buffer` are true,
|
|
250
|
+
* `decodeData()` will be used.
|
|
251
|
+
*
|
|
252
|
+
* @returns {mixed} See `decodeText()` and `decodeData()` for details;
|
|
253
|
+
* will always be a `Promise` if `decodeData()` was used.
|
|
254
|
+
*/
|
|
255
|
+
export function decode(base64: string, options?: object): mixed;
|
|
256
|
+
declare const UI8_FB64: boolean;
|
|
257
|
+
export { UI8_FB64 as NATIVE_BASE64 };
|
|
258
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../lib/base64.js"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,+BAVW,MAAM,YAEd;IAA0B,SAAS,GAA3B,OAAO;CAMf,GAAU,MAAM,CAQlB;AAED;;;;;;;;GAQG;AACH,iCAHW,MAAM,GACJ,MAAM,CASlB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,gCAdW,MAAM,YAEd;IAA0B,MAAM,GAAxB,OAAO;CAUf,GAAU,UAAU,CAWtB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iCAdW,UAAU,YAElB;IAA0B,MAAM,GAAxB,OAAO;CAUf,GAAU,MAAM,CAalB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,iCAlBW,CAAC,MAAM,GAAC,UAAU,CAAC,YAOnB,CAAC,MAAM,GAAC,OAAO,CAAC,GASd,MAAM,CA8BlB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,mCAjBW,MAAM,YACN,CAAC,MAAM,GAAC,OAAO,CAAC,GAad,CAAC,MAAM,GAAC,UAAU,CAAC,CAmC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,gCA1BW,CAAC,IAAI,GAAC,IAAI,WAAO,UAAU,GAAC,WAAW,CAAC,YAMhD;IAAyB,IAAI,GAArB,MAAM;IAOqB,IAAI,GAA/B,CAAC,MAAM,GAAC,OAAO,CAAC;CAOxB,GAIU,OAAO,CAAC,MAAM,CAAC,CA6C3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,qCAbW,MAAM,YAEd;IAA0B,QAAQ,GAA1B,OAAO;IACW,MAAM,GAAxB,OAAO;CAEf,GAAU,OAAO,CAAC,CAAC,UAAU,GAAC,WAAW,GAAC,QAAQ,CAAC,CAAC,CAetD;AAED;;;;;;;;;;;;;GAaG;AACH,iCAVW,KAAK,YAMb;IAA0B,GAAG,GAArB,OAAO;CAEf,GAAU,OAAO,CAAC,MAAM,CAAC,CAM3B;AAED;;;;;;;;;;;;;GAaG;AACH,mCAVW,GAAC,YACD,GAAC,gBAsBX;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,6BAZW,GAAC,YAID,MAAM,GAKJ,CAAC,MAAM,GAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAapC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,+BAZW,MAAM,YAIN,MAAM,GAKJ,KAAK,CAajB;AAnbD,gCAAgE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base91.d.ts","sourceRoot":"","sources":["../../lib/base91.js"],"names":[],"mappings":"AA6BiB,6BAPN,GAAC,GAKC,MAAM,CA8ElB;AAsBgB,6BAjBN,MAAM,SAIN,CAAC,MAAM,GAAC,OAAO,CAAC,GAQd,KAAK,CAiEjB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
export = Hashifier;
|
|
2
|
+
declare class Hashifier {
|
|
3
|
+
static "new"(opts?: {}): import("./hash");
|
|
4
|
+
/**
|
|
5
|
+
* Build a new Hashifier
|
|
6
|
+
*
|
|
7
|
+
* @param {(object|string)} [options] Options
|
|
8
|
+
*
|
|
9
|
+
* If this is a `string`, it's assumed to be the `options.algo` option.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} [options.algo="SHA-256"] Digest (hash) algorithm
|
|
12
|
+
*
|
|
13
|
+
* By default we use `SHA-256` for backwards compatibility with my
|
|
14
|
+
* older libraries and apps. You can set it to any *digest algorithm*
|
|
15
|
+
* supported by the `SubtleCrypto` API.
|
|
16
|
+
*
|
|
17
|
+
* We look up the algorithm with
|
|
18
|
+
* [getAlgorithm()]{@link module:@lumjs/encode/hash#getAlgorithm},
|
|
19
|
+
* and so support hyphenless aliases and case-insensitive ids.
|
|
20
|
+
*
|
|
21
|
+
* For more information on supported digest algorithms, see:
|
|
22
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
|
|
23
|
+
*
|
|
24
|
+
* @param {object} [options.base64] Default options for `base64()`
|
|
25
|
+
*
|
|
26
|
+
* If specified, this will become the default options for the
|
|
27
|
+
* [base64()]{@link module:@lumjs/encode/hash#base64} method.
|
|
28
|
+
*
|
|
29
|
+
* @param {object} [options.base91] Default options for `base91()`
|
|
30
|
+
*
|
|
31
|
+
* If specified, this will become the default options for the
|
|
32
|
+
* [base91()]{@link module:@lumjs/encode/hash#base91} method.
|
|
33
|
+
*
|
|
34
|
+
* @param {(string|function|object)} [options.addUsing="base64"]
|
|
35
|
+
* Encoder for `add()` to use when non-string values are passed.
|
|
36
|
+
*
|
|
37
|
+
* If this is a `string`, it may be either `"base64"` or `"base91"`.
|
|
38
|
+
*
|
|
39
|
+
* If it is a `function`, it will be sent the data value and must
|
|
40
|
+
* return an encoded string representation of that value.
|
|
41
|
+
*
|
|
42
|
+
* If this is an `object`, it must have a method called `encode()`
|
|
43
|
+
* that works the same way as if you'd passed a `function`.
|
|
44
|
+
*
|
|
45
|
+
* @param {(string|function)} [options.joinWith=""]
|
|
46
|
+
* What `hash()` will use to join progressive data values.
|
|
47
|
+
*
|
|
48
|
+
* If this is a `string` the array of data values will be joined
|
|
49
|
+
* using the `array.join()` method.
|
|
50
|
+
*
|
|
51
|
+
* If it is a `function`, it will be sent the array of values,
|
|
52
|
+
* and must return an encoded representation of those values
|
|
53
|
+
* having been joined together in some fashion.
|
|
54
|
+
*
|
|
55
|
+
* The default value is an empty string, which means the data
|
|
56
|
+
* values are simply concatenated together with no separator.
|
|
57
|
+
*
|
|
58
|
+
* @param {number} [options.timeout=10000] Timeout for async encoding
|
|
59
|
+
*
|
|
60
|
+
* This is how long `hash()` will wait for async encoding to finish
|
|
61
|
+
* before throwing an error indicating something went wrong.
|
|
62
|
+
*
|
|
63
|
+
* Value is in milliseconds.
|
|
64
|
+
*
|
|
65
|
+
* @param {number} [options.tryEvery=100] Interval to test async encoding
|
|
66
|
+
*
|
|
67
|
+
* If async encoding is ongoing, this is the interval `hash()` will
|
|
68
|
+
* test to see if encoding has finished.
|
|
69
|
+
*
|
|
70
|
+
* Value is in milliseconds.
|
|
71
|
+
*
|
|
72
|
+
* @throws {Error} If `options.algo` was an invalid algorithm.
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
constructor(options?: (object | string));
|
|
76
|
+
options: any;
|
|
77
|
+
current: {
|
|
78
|
+
queue: number;
|
|
79
|
+
hash: any[];
|
|
80
|
+
encoder: any;
|
|
81
|
+
joiner: any;
|
|
82
|
+
};
|
|
83
|
+
algo: module;
|
|
84
|
+
defaults: {
|
|
85
|
+
base32: any;
|
|
86
|
+
base64: any;
|
|
87
|
+
base91: any;
|
|
88
|
+
};
|
|
89
|
+
timeout: any;
|
|
90
|
+
tryEvery: any;
|
|
91
|
+
/**
|
|
92
|
+
* Lookup a hashing algorithm and return details about it
|
|
93
|
+
*
|
|
94
|
+
* @param {string} id - The name of the algorithm.
|
|
95
|
+
*
|
|
96
|
+
* It's case-insensitive (will be forced to uppercase),
|
|
97
|
+
* and you may omit the hyphen in the algorithm name.
|
|
98
|
+
* Thus `sha256` is the same as `SHA-256`.
|
|
99
|
+
*
|
|
100
|
+
* @returns {?module:@lumjs/encode/hash~Algo}
|
|
101
|
+
* Will be an Algo info object if the `id` was valid,
|
|
102
|
+
* or `null` otherwise.
|
|
103
|
+
*/
|
|
104
|
+
getAlgorithm(id: string): module | null;
|
|
105
|
+
/**
|
|
106
|
+
* Get a cryptographic *hash*.
|
|
107
|
+
*
|
|
108
|
+
* If you pass `input`, it will be hashed *immediately* and returned.
|
|
109
|
+
*
|
|
110
|
+
* Otherwise, if there is a current *progressive hash* in the process of
|
|
111
|
+
* being built, it will be *finalized* and returned.
|
|
112
|
+
*
|
|
113
|
+
* @param {(string|object)} [input] Input to hash immediately
|
|
114
|
+
*
|
|
115
|
+
* @return {Promise<ArrayBuffer>} See `SubtleCrypto.digest()` for details.
|
|
116
|
+
*
|
|
117
|
+
* @throws {TypeError} If the `options.joinWith` value is invalid,
|
|
118
|
+
* and no `input` was passed.
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
hash(input?: (string | object)): Promise<ArrayBuffer>;
|
|
122
|
+
/**
|
|
123
|
+
* Get hash as a Hex string.
|
|
124
|
+
*
|
|
125
|
+
* @param {(string|object|null)} [input]
|
|
126
|
+
* See [hash()]{@link module:@lumjs/encode/hash#hash} for details.
|
|
127
|
+
*
|
|
128
|
+
* @returns {string}
|
|
129
|
+
*/
|
|
130
|
+
hex(input?: (string | object | null)): string;
|
|
131
|
+
/**
|
|
132
|
+
* Get hash as a Base32-encoded string.
|
|
133
|
+
*
|
|
134
|
+
* @param {(string|object|null)} [input]
|
|
135
|
+
* See [hash()]{@link module:@lumjs/encode/hash#hash}
|
|
136
|
+
*
|
|
137
|
+
* @param {object} [options] Options to pass to base32.encode().
|
|
138
|
+
*
|
|
139
|
+
* @returns {string}
|
|
140
|
+
*/
|
|
141
|
+
base32(input?: (string | object | null), opts?: any): string;
|
|
142
|
+
/**
|
|
143
|
+
* Get hash as a Base64-encoded string.
|
|
144
|
+
*
|
|
145
|
+
* @param {(string|object|null)} [input]
|
|
146
|
+
* See [hash()]{@link module:@lumjs/encode/hash#hash} for details.
|
|
147
|
+
*
|
|
148
|
+
* @param {object} [options] Options for Base64 encoding
|
|
149
|
+
*
|
|
150
|
+
* @param {boolean} [options.url=false] Use URL-safe variant?
|
|
151
|
+
*
|
|
152
|
+
* @returns {string}
|
|
153
|
+
*/
|
|
154
|
+
base64(input?: (string | object | null), opts?: any): string;
|
|
155
|
+
/**
|
|
156
|
+
* Get hash as a Base91-encoded string.
|
|
157
|
+
*
|
|
158
|
+
* @param {(string|object|null)} [input]
|
|
159
|
+
* See [hash()]{@link module:@lumjs/encode/hash#hash}
|
|
160
|
+
* @param {object} [opts] Options for how to encode the hash.
|
|
161
|
+
*
|
|
162
|
+
* @param {(boolean|object)} [opts.nba=false] Use `numByteArray()` ?
|
|
163
|
+
*
|
|
164
|
+
* This options is deprecated and will be removed in v3.0.
|
|
165
|
+
*
|
|
166
|
+
* If this is `true` the *hash string* will be passed to `numByteArray()`
|
|
167
|
+
* with the *default options* and the output from that will be passed to
|
|
168
|
+
* `base91.encode()`.
|
|
169
|
+
*
|
|
170
|
+
* If this is an `object`, then the same logic as `true` applies, except this
|
|
171
|
+
* will be used as the *explicit options* for the `numByteArray()` method.
|
|
172
|
+
*
|
|
173
|
+
* If this is `false` the `ArrayBffer` will be converted into a `Uint8Array`,
|
|
174
|
+
* and that will be passed to `base91.encode()`.
|
|
175
|
+
*
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
178
|
+
base91(input?: (string | object | null), opts?: {
|
|
179
|
+
nba?: (boolean | object);
|
|
180
|
+
}): string;
|
|
181
|
+
/**
|
|
182
|
+
* Add input to a progressive hash.
|
|
183
|
+
*
|
|
184
|
+
* @param {(string|object)} input - A value to add to the hash.
|
|
185
|
+
*
|
|
186
|
+
* If it is an `object` then it will be processed with the `addUsing`
|
|
187
|
+
* handler. See the constructor for details on supported formats.
|
|
188
|
+
*
|
|
189
|
+
* String values are simply added _as-is_.
|
|
190
|
+
*
|
|
191
|
+
* @return {object} `this`
|
|
192
|
+
*/
|
|
193
|
+
add(input: (string | object), opts?: {}): object;
|
|
194
|
+
reset(): this;
|
|
195
|
+
}
|
|
196
|
+
declare namespace Hashifier {
|
|
197
|
+
export { module };
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* :@lumjs/encode/hash~Algo
|
|
201
|
+
*/
|
|
202
|
+
type module = {
|
|
203
|
+
/**
|
|
204
|
+
* - The formal id/name of the algorithm
|
|
205
|
+
*/
|
|
206
|
+
id: string;
|
|
207
|
+
/**
|
|
208
|
+
* - The output length (in bits)
|
|
209
|
+
*/
|
|
210
|
+
length: number;
|
|
211
|
+
/**
|
|
212
|
+
* - The block size (in bits)
|
|
213
|
+
*/
|
|
214
|
+
block: number;
|
|
215
|
+
};
|
|
216
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../lib/hash.js"],"names":[],"mappings":";AAyDiB;IA8Xf,0CAGC;IA/XD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsEG;IACH,sBApEW,CAAC,MAAM,GAAC,MAAM,CAAC,EAyGzB;IA9BC,aAAsB;IAEtB;;;;;MAMC;IAED,aAGW;IAOX;;;;MAKC;IAED,aAA6C;IAC7C,cAA8C;IAIhD;;;;;;;;;;;;OAYG;IACH,iBAVW,MAAM,GAMH,MAAM,OAAA,CAoBnB;IAED;;;;;;;;;;;;;;;OAeG;IACH,aARW,CAAC,MAAM,GAAC,MAAM,CAAC,GAEd,OAAO,CAAC,WAAW,CAAC,CAkE/B;IAED;;;;;;;OAOG;IACH,YALW,CAAC,MAAM,GAAC,MAAM,GAAC,IAAI,CAAC,GAGlB,MAAM,CAOlB;IAED;;;;;;;;;OASG;IACH,eAPW,CAAC,MAAM,GAAC,MAAM,GAAC,IAAI,CAAC,eAKlB,MAAM,CAMlB;IAED;;;;;;;;;;;OAWG;IACH,eATW,CAAC,MAAM,GAAC,MAAM,GAAC,IAAI,CAAC,eAOlB,MAAM,CAOlB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,eApBW,CAAC,MAAM,GAAC,MAAM,GAAC,IAAI,CAAC,SAI5B;QAAgC,GAAG,GAA3B,CAAC,OAAO,GAAC,MAAM,CAAC;KAcxB,GAAU,MAAM,CAclB;IAED;;;;;;;;;;;OAWG;IACH,WATW,CAAC,MAAM,GAAC,MAAM,CAAC,cAOd,MAAM,CAyDjB;IAED,cAGC;CAOF;;;;;;;;;;;QAjZa,MAAM;;;;YACN,MAAM;;;;WACN,MAAM"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export = HmacEncoder;
|
|
2
|
+
/**
|
|
3
|
+
* The main class to perform HMAC signing.
|
|
4
|
+
* @exports module:@lumjs/encode/hmac
|
|
5
|
+
*/
|
|
6
|
+
declare class HmacEncoder {
|
|
7
|
+
/**
|
|
8
|
+
* Create an encoder.
|
|
9
|
+
*
|
|
10
|
+
* @param {(string|TypedArray|ArrayBuffer)} keyValue - The secret key value.
|
|
11
|
+
* Will be used to generate the crypto key.
|
|
12
|
+
* @param {object} [options] Options
|
|
13
|
+
* @param {string} [options.algorithm="SHA-256"] Digest algorithm for HMAC.
|
|
14
|
+
*/
|
|
15
|
+
constructor(keyValue: (string | TypedArray | ArrayBuffer), options?: {
|
|
16
|
+
algorithm?: string;
|
|
17
|
+
});
|
|
18
|
+
te: TextEncoder;
|
|
19
|
+
keyBytes: ArrayBufferView<ArrayBuffer>;
|
|
20
|
+
options: any;
|
|
21
|
+
/**
|
|
22
|
+
* Get the crypto key for this encoder instance.
|
|
23
|
+
* @returns {Promise<CryptoKey>}
|
|
24
|
+
*/
|
|
25
|
+
getKey(): Promise<CryptoKey>;
|
|
26
|
+
/**
|
|
27
|
+
* Sign a message (any kind of data).
|
|
28
|
+
* @param {(string|TypedArray|ArrayBuffer)} message - Message to be signed.
|
|
29
|
+
* @returns {Promise<module:@lumjs/encode/signature>}
|
|
30
|
+
*/
|
|
31
|
+
sign(message: (string | TypedArray | ArrayBuffer)): Promise<{
|
|
32
|
+
exports: typeof HmacEncoder;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=hmac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../lib/hmac.js"],"names":[],"mappings":";AAaA;;;GAGG;AACH;IACE;;;;;;;OAOG;IACH,sBALW,CAAC,MAAM,GAAC,UAAU,GAAC,WAAW,CAAC,YAGvC;QAAyB,SAAS,GAA1B,MAAM;KAChB,EAOA;IALC,gBAA2B;IAC3B,uCAE4B;IAC5B,aAAmD;IAGrD;;;OAGG;IACH,UAFa,OAAO,CAAC,SAAS,CAAC,CAkB9B;IAED;;;;OAIG;IACH,cAHW,CAAC,MAAM,GAAC,UAAU,GAAC,WAAW,CAAC,GAC7B,OAAO;;MAAO,CAe1B;CAEF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export = HOTP;
|
|
2
|
+
/**
|
|
3
|
+
* HMAC-based One-Time-Passwords.
|
|
4
|
+
*
|
|
5
|
+
* TODO: this needs documentation!
|
|
6
|
+
*
|
|
7
|
+
* @exports module:@lumjs/encode/hotp
|
|
8
|
+
*/
|
|
9
|
+
declare class HOTP {
|
|
10
|
+
constructor(options: any);
|
|
11
|
+
setOptions(options: any): this;
|
|
12
|
+
options: any;
|
|
13
|
+
getOptions(...args: any[]): any;
|
|
14
|
+
get defaultKey(): any;
|
|
15
|
+
get defaultOptions(): {
|
|
16
|
+
algorithm: string;
|
|
17
|
+
checkSize: number;
|
|
18
|
+
counter: number;
|
|
19
|
+
debug: number;
|
|
20
|
+
window: number;
|
|
21
|
+
}[];
|
|
22
|
+
generate(key: any, opts: any, fromVerify?: boolean): Promise<{
|
|
23
|
+
code: string;
|
|
24
|
+
opts: any;
|
|
25
|
+
toString(): string;
|
|
26
|
+
}>;
|
|
27
|
+
verify(token: any, key: any, opts: any): Promise<{
|
|
28
|
+
ok: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
DEBUG: Readonly<{
|
|
31
|
+
LOG: 1;
|
|
32
|
+
INFO: 2;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
declare namespace HOTP {
|
|
36
|
+
export { DEBUG };
|
|
37
|
+
}
|
|
38
|
+
declare const DEBUG: Readonly<{
|
|
39
|
+
LOG: 1;
|
|
40
|
+
INFO: 2;
|
|
41
|
+
}>;
|
|
42
|
+
//# sourceMappingURL=hotp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotp.d.ts","sourceRoot":"","sources":["../../lib/hotp.js"],"names":[],"mappings":";AA2BA;;;;;;GAMG;AACH;IACE,0BAEC;IAED,+BAQC;IAHG,aAAsD;IAK1D,gCAEC;IAED,sBAEC;IAED;;;;;;QAEC;IAED;;;;OA6CC;IAED;;OAiCC;IAIH;;;OAAoB;CAHnB;;;;AAzID;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export = PEM;
|
|
2
|
+
/**
|
|
3
|
+
* A class for parsing and decoding PEM documents.
|
|
4
|
+
*
|
|
5
|
+
* PEM is a format commonly used for encryption keys.
|
|
6
|
+
* See: https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail
|
|
7
|
+
*
|
|
8
|
+
* @alias {module:@lumjs/encode/pem}
|
|
9
|
+
*/
|
|
10
|
+
declare class PEM {
|
|
11
|
+
/**
|
|
12
|
+
* Parse a string into a PEM object instance.
|
|
13
|
+
*
|
|
14
|
+
* This is almost identical to the main class constructor,
|
|
15
|
+
* except this version will simply return null if the argument
|
|
16
|
+
* could not be parsed as a valid PEM string.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} pemText - PEM format string to be parsed.
|
|
19
|
+
* @returns {?module:@lumjs/encode/pem} A PEM instance;
|
|
20
|
+
* or null if the pemText could not be parsed.
|
|
21
|
+
*/
|
|
22
|
+
static parse(pemText: string): {
|
|
23
|
+
exports: typeof PEM;
|
|
24
|
+
} | null;
|
|
25
|
+
/**
|
|
26
|
+
* Parse a string into a PEM object instance.
|
|
27
|
+
*
|
|
28
|
+
* This method is strict and will throw an error on failure.
|
|
29
|
+
* For a more lenient way to parse PEM documents, see the
|
|
30
|
+
* {@link module:@lumjs/encode/pem.parse parse()} method.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} pem - PEM format string to be parsed.
|
|
33
|
+
* @throws {TypeError} If the `pem` argument is an invalid value.
|
|
34
|
+
* @throws {SyntaxErrror} If the `pem` string was not able to be parsed.
|
|
35
|
+
*/
|
|
36
|
+
constructor(pem: string);
|
|
37
|
+
/**
|
|
38
|
+
* Decode the base64 content.
|
|
39
|
+
*
|
|
40
|
+
* @param {(boolean|function)} [typeClass=false] Return a TypedArray?
|
|
41
|
+
*
|
|
42
|
+
* This may be set to the constructor function of any TypedArray class.
|
|
43
|
+
* It may also be set to `true` as an alias for `Uint8Array`.
|
|
44
|
+
*
|
|
45
|
+
* If it is set to `false` (the default), then the binary string output
|
|
46
|
+
* from the `atob()` global function will be used as the return value.
|
|
47
|
+
*
|
|
48
|
+
* If this is set to Uint8Array (either explicitly or by using `true`),
|
|
49
|
+
* and a method named `Uint8Array.fromBase64` exists, then this will use
|
|
50
|
+
* that to parse the base64 content rather than using the
|
|
51
|
+
* {@link module:@lumjs/encode/util.str2ta str2ta()} function.
|
|
52
|
+
*
|
|
53
|
+
* @returns {(string|TypedArray|Error)}
|
|
54
|
+
*
|
|
55
|
+
* If an error is thrown by any functions being used to decode the base64
|
|
56
|
+
* content, that error will be the return value.
|
|
57
|
+
*
|
|
58
|
+
* Otherwise the `typeClass` argument will determine the returned type.
|
|
59
|
+
*/
|
|
60
|
+
decode(typeClass?: (boolean | Function)): (string | TypedArray | Error);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=pem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../../lib/pem.js"],"names":[],"mappings":";AAaA;;;;;;;GAOG;AACH;IAwFE;;;;;;;;;;OAUG;IACH,sBAJW,MAAM,GACJ;;YAAO,CAMnB;IApGD;;;;;;;;;;OAUG;IACH,iBAJW,MAAM,EAqBhB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,mBApBW,CAAC,OAAO,WAAS,CAAC,GAahB,CAAC,MAAM,GAAC,UAAU,GAAC,KAAK,CAAC,CAsCrC;CAkBF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill Ruleset
|
|
3
|
+
*/
|
|
4
|
+
export type PolyfillRuleset = {
|
|
5
|
+
/**
|
|
6
|
+
* - The target to polyfill.
|
|
7
|
+
*
|
|
8
|
+
* Class constructors are functions, class prototypes are objects.
|
|
9
|
+
* Each Ruleset may only have one target, so if you need to polyfill
|
|
10
|
+
* both static and instance methods you'll need to use an array with
|
|
11
|
+
* a Ruleset for the constructor, and a Ruleset for the prototype.
|
|
12
|
+
*/
|
|
13
|
+
into: (object | Function);
|
|
14
|
+
/**
|
|
15
|
+
* - An object containing the polyfill methods.
|
|
16
|
+
*
|
|
17
|
+
* Any method in this object that doesn't exist in the `for` target,
|
|
18
|
+
* will be added to it. As these are expected to be methods respecting
|
|
19
|
+
* the `this` context variable they should NOT be arrow (`=>`) closures.
|
|
20
|
+
*/
|
|
21
|
+
fill: object;
|
|
22
|
+
};
|
|
23
|
+
export namespace NON {
|
|
24
|
+
let native: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Polyfills for Uint8Array.
|
|
28
|
+
*
|
|
29
|
+
* This is an array of two ruleset objects:
|
|
30
|
+
*
|
|
31
|
+
* - Uint8Array
|
|
32
|
+
* - fromBase64()
|
|
33
|
+
* - fromHex()
|
|
34
|
+
* - Uint8Array.prototype
|
|
35
|
+
* - toBase64()
|
|
36
|
+
* - toHex()
|
|
37
|
+
*
|
|
38
|
+
* @alias module:@lumjs/encode/polyfill.UI8
|
|
39
|
+
* @type {PolyfillRuleset[]}
|
|
40
|
+
*/
|
|
41
|
+
export const UI8: PolyfillRuleset[];
|
|
42
|
+
export function isPolyfill(v: any): any;
|
|
43
|
+
/**
|
|
44
|
+
* Process one or more polyfill definitions.
|
|
45
|
+
* @param {(PolyfillRuleset|PolyfillRuleset[])} rules - Rulesets to apply.
|
|
46
|
+
*
|
|
47
|
+
* You can pass a single Ruleset object, or an array of associated Rulesets.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Map}
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
*
|
|
53
|
+
* For these examples I'll be applying the `UI8` polyfills.
|
|
54
|
+
*
|
|
55
|
+
* **Usage if using *ESModules***:
|
|
56
|
+
*
|
|
57
|
+
* ```js
|
|
58
|
+
* import { polyfill, UI8 } from '@lumjs/encode/polyfill';
|
|
59
|
+
* polyfill(UI8);
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* **OR if using *CommonJS***:
|
|
63
|
+
*
|
|
64
|
+
* ```js
|
|
65
|
+
* const { polyfill, UI8 } = require('@lumjs/encode/polyfill');
|
|
66
|
+
* polyfill(UI8);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @alias module:@lumjs/encode/polyfill.polyfill
|
|
70
|
+
*/
|
|
71
|
+
export function polyfill(rules: (PolyfillRuleset | PolyfillRuleset[])): Map;
|
|
72
|
+
//# sourceMappingURL=polyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../lib/polyfill.js"],"names":[],"mappings":";;;;;;;;;;;;UAyHU,CAAC,MAAM,WAAS,CAAC;;;;;;;;UAOjB,MAAM;;;;;AAnHhB;;;;;;;;;;;;;;GAcG;AACH,kBAFU,eAAe,EAAE,CAyBzB;AAEF,wCAGC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,gCA1BW,CAAC,eAAe,GAAC,eAAe,EAAE,CAAC,GAIjC,GAAG,CAiDf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small wrapepr class representing a crypto signature.
|
|
3
|
+
* @alias module:@lumjs/encode/signature
|
|
4
|
+
*/
|
|
5
|
+
declare class Signature {
|
|
6
|
+
/**
|
|
7
|
+
* Build a Signature instance.
|
|
8
|
+
* @param {ArrayBuffer} buffer - The signature data.
|
|
9
|
+
*/
|
|
10
|
+
constructor(buffer: ArrayBuffer);
|
|
11
|
+
buffer: ArrayBuffer;
|
|
12
|
+
/**
|
|
13
|
+
* Get the signature as a Uint8Array.
|
|
14
|
+
*/
|
|
15
|
+
get uint8Array(): Uint8Array<ArrayBuffer>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the signature as an array of bytes.
|
|
18
|
+
*/
|
|
19
|
+
get byteArray(): any;
|
|
20
|
+
/**
|
|
21
|
+
* Get the signature as a Hex string.
|
|
22
|
+
*/
|
|
23
|
+
get hex(): any;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../lib/signature.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH;IACE;;;OAGG;IACH,oBAFW,WAAW,EAIrB;IADC,oBAAoB;IAGtB;;OAEG;IACH,0CAEC;IAED;;OAEG;IACH,qBAEC;IAED;;OAEG;IACH,eAEC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export = TOTP;
|
|
2
|
+
/**
|
|
3
|
+
* Time-based One-Time-Passwords.
|
|
4
|
+
*
|
|
5
|
+
* TODO: this needs documentation!
|
|
6
|
+
*
|
|
7
|
+
* @exports module:@lumjs/encode/totp
|
|
8
|
+
*/
|
|
9
|
+
declare class TOTP extends HOTP {
|
|
10
|
+
get defaultOptions(): ({
|
|
11
|
+
algorithm: string;
|
|
12
|
+
checkSize: number;
|
|
13
|
+
counter: number;
|
|
14
|
+
debug: number;
|
|
15
|
+
window: number;
|
|
16
|
+
} | {
|
|
17
|
+
step: number;
|
|
18
|
+
})[];
|
|
19
|
+
getExpiry(opts: any): any;
|
|
20
|
+
}
|
|
21
|
+
import HOTP = require("./hotp");
|
|
22
|
+
//# sourceMappingURL=totp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"totp.d.ts","sourceRoot":"","sources":["../../lib/totp.js"],"names":[],"mappings":";AAKA;;;;;;GAMG;AACH;IACE;;;;;;;;SAEC;IAED,0BAEC;CAUF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function ord(string: string): number;
|
|
2
|
+
export function numByteArray(numStr: string, options?: (object | number), ...args: any[]): any[];
|
|
3
|
+
export function wordArrayToUint8Array(wordArray: WordArray): Uint8Array;
|
|
4
|
+
export function intToBytes(num: Integer): any[];
|
|
5
|
+
export function hexToBytes(hex: string, uint8?: boolean, native?: boolean): (number[] | Uint8Array);
|
|
6
|
+
export function bytesToHex(bytes: (Uint8Array | number[]), native?: boolean): string;
|
|
7
|
+
/**
|
|
8
|
+
* Convert a binary string into a TypedArray.
|
|
9
|
+
*
|
|
10
|
+
* Inspired by the str2ab() example from:
|
|
11
|
+
* https://developer.chrome.com/blog/how-to-convert-arraybuffer-to-and-from-string
|
|
12
|
+
*
|
|
13
|
+
* The biggest difference being this version supports specifying the specific
|
|
14
|
+
* TypedArray class you want to use, and it returns the TypedArray by default
|
|
15
|
+
* rather than the ArrayBuffer.
|
|
16
|
+
*
|
|
17
|
+
* To get the ArrayBuffer just use: `str2ta(string).buffer;`
|
|
18
|
+
*
|
|
19
|
+
* @param {string} str - Binary string to convert.
|
|
20
|
+
* @param {function} [typeClass=Uint8Array] TypedArray class to use;
|
|
21
|
+
* MUST be a TypedArray class constructor. Default is `Uint8Array`.
|
|
22
|
+
* @returns {TypedArray} Will be an instance of `typeClass`.
|
|
23
|
+
* @throws {TypeError} If invalid arguments were passed.
|
|
24
|
+
*/
|
|
25
|
+
export function str2ta(str: string, typeClass?: Function): TypedArray;
|
|
26
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../lib/util.js"],"names":[],"mappings":"AAsBc,4BAHH,MAAM,GACJ,MAAM,CAiClB;AAyCsB,qCApCZ,MAAM,YACN,CAAC,MAAM,GAAC,MAAM,CAAC,yBAyFzB;AAQ+B,iDAHrB,SAAS,GACP,UAAU,CAwBtB;AAWoB,gCAHV,OAAO,SAYjB;AAkBoB,gCAVV,MAAM,UACN,OAAO,WACP,OAAO,GAML,CAAC,MAAM,EAAE,GAAC,UAAU,CAAC,CAcjC;AAcoB,kCATV,CAAC,UAAU,GAAC,MAAM,EAAE,CAAC,WACrB,OAAO,GAML,MAAM,CAWlB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,4BANW,MAAM,yBAGJ,UAAU,CAoBtB"}
|
package/jsdoc.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tags":
|
|
3
|
-
{
|
|
4
|
-
"allowUnknownTags": true
|
|
5
|
-
},
|
|
6
|
-
"source":
|
|
7
|
-
{
|
|
8
|
-
"include": ["./lib"]
|
|
9
|
-
},
|
|
10
|
-
"opts":
|
|
11
|
-
{
|
|
12
|
-
"destination": "./docs/api",
|
|
13
|
-
"recurse": true
|
|
14
|
-
},
|
|
15
|
-
"plugins":
|
|
16
|
-
[
|
|
17
|
-
"plugins/markdown"
|
|
18
|
-
],
|
|
19
|
-
"templates":
|
|
20
|
-
{
|
|
21
|
-
"cleverLinks": false,
|
|
22
|
-
"monospaceLinks": false,
|
|
23
|
-
"default":
|
|
24
|
-
{
|
|
25
|
-
"outputSourceFiles": true
|
|
26
|
-
},
|
|
27
|
-
"path": "ink-docstrap",
|
|
28
|
-
"theme": "cerulean",
|
|
29
|
-
"navType": "vertical",
|
|
30
|
-
"linenums": true,
|
|
31
|
-
"dateFormat": "YYYY-MM-DD, hh:mm:ss"
|
|
32
|
-
}
|
|
33
|
-
}
|