@lumjs/encode 2.4.1 → 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 +16 -1
- package/jsdoc.js +6 -0
- package/lib/base64.js +30 -17
- package/lib/hash.js +1 -1
- package/lib/hotp.js +3 -0
- package/lib/index.js +16 -0
- package/lib/polyfill.js +135 -0
- package/lib/sets/_inc.js +18 -0
- package/lib/sets/all.js +14 -0
- package/lib/sets/base.js +20 -0
- package/lib/sets/digest.js +16 -0
- package/lib/sets/otp.js +18 -0
- package/lib/sets/sign.js +20 -0
- package/lib/totp.js +3 -0
- package/lib/util.js +103 -84
- package/lum.build.js +24 -0
- package/package.json +73 -24
- 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
|
@@ -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,+B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;;;;;;;;;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":";A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
|
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"}
|