otplib 12.0.0-1 → 12.0.1

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 (50) hide show
  1. package/README.md +115 -388
  2. package/core.d.ts +1 -0
  3. package/core.js +23 -0
  4. package/index.d.ts +1 -0
  5. package/index.js +23 -0
  6. package/package.json +16 -98
  7. package/v11.d.ts +1 -0
  8. package/v11.js +23 -0
  9. package/authenticator/authenticator.d.ts +0 -145
  10. package/authenticator/index.d.ts +0 -1
  11. package/authenticator/index.js +0 -92
  12. package/authenticator-async/authenticator.d.ts +0 -34
  13. package/authenticator-async/index.d.ts +0 -1
  14. package/authenticator-async/index.js +0 -62
  15. package/core/index.d.ts +0 -3
  16. package/core/index.js +0 -41
  17. package/core-async/index.d.ts +0 -11
  18. package/core-async/index.js +0 -62
  19. package/hotp/hotp.d.ts +0 -128
  20. package/hotp/index.d.ts +0 -2
  21. package/hotp/index.js +0 -224
  22. package/hotp/utils.d.ts +0 -208
  23. package/hotp-async/hotp.d.ts +0 -33
  24. package/hotp-async/index.d.ts +0 -1
  25. package/hotp-async/index.js +0 -55
  26. package/plugin-base32-enc-dec/index.d.ts +0 -9
  27. package/plugin-base32-enc-dec/index.js +0 -28
  28. package/plugin-crypto/index.d.ts +0 -4
  29. package/plugin-crypto/index.js +0 -26
  30. package/plugin-crypto-async-ronomon/index.d.ts +0 -4
  31. package/plugin-crypto-async-ronomon/index.js +0 -34
  32. package/plugin-crypto-js/index.d.ts +0 -4
  33. package/plugin-crypto-js/index.js +0 -831
  34. package/plugin-thirty-two/index.d.ts +0 -9
  35. package/plugin-thirty-two/index.js +0 -24
  36. package/preset-browser/buffer.js +0 -1
  37. package/preset-browser/index.d.ts +0 -4
  38. package/preset-browser/index.js +0 -9
  39. package/preset-browser/index.js.map +0 -1
  40. package/preset-default/index.d.ts +0 -4
  41. package/preset-default/index.js +0 -31
  42. package/preset-default-async/index.d.ts +0 -4
  43. package/preset-default-async/index.js +0 -31
  44. package/preset-v11/index.js +0 -134
  45. package/totp/index.d.ts +0 -1
  46. package/totp/index.js +0 -202
  47. package/totp/totp.d.ts +0 -201
  48. package/totp-async/index.d.ts +0 -1
  49. package/totp-async/index.js +0 -98
  50. package/totp-async/totp.d.ts +0 -46
package/hotp/hotp.d.ts DELETED
@@ -1,128 +0,0 @@
1
- import { CreateDigest, CreateHmacKey, HashAlgorithms, HexString, KeyEncodings, OTP, OTPOptions, SecretKey } from './utils';
2
- /**
3
- * Interface for options used in HOTP.
4
- */
5
- export interface HOTPOptions<T = string> extends OTPOptions {
6
- /**
7
- * Creates the digest which token is derived from.
8
- */
9
- createDigest: CreateDigest<T>;
10
- /**
11
- * Formats the secret into a HMAC key, applying transformations (like padding) where needed
12
- */
13
- createHmacKey: CreateHmacKey<T>;
14
- /**
15
- * The algorithm used for calculating the HMAC.
16
- */
17
- algorithm: HashAlgorithms;
18
- /**
19
- * **USE WITH CAUTION:** Given the same digest, the same token will be received.
20
- *
21
- * This is provided for unique use cases. For example, digest generation might
22
- * depend on an async API.
23
- */
24
- digest?: HexString;
25
- /**
26
- * The number of digits a token will have. Usually 6 or 8.
27
- */
28
- digits: number;
29
- /**
30
- * The encoding that was used on the secret.
31
- */
32
- encoding: KeyEncodings;
33
- }
34
- /**
35
- * Validates the given [[HOTPOptions]]
36
- */
37
- export declare function hotpOptionsValidator<T extends HOTPOptions<unknown> = HOTPOptions<unknown>>(options: Readonly<Partial<T>>): void;
38
- /**
39
- * Takes a HOTP secret and derives the HMAC key
40
- * for use in token generation.
41
- *
42
- * @param algorithm - Reference: [[HOTPOptions.algorithm]]
43
- * @param secret
44
- * @param encoding - Reference: [[HOTPOptions.encoding]]
45
- */
46
- export declare const hotpCreateHmacKey: CreateHmacKey;
47
- /**
48
- * Returns the default options for HOTP
49
- */
50
- export declare function hotpDefaultOptions<T extends HOTPOptions<unknown> = HOTPOptions<unknown>>(): Partial<T>;
51
- /**
52
- * Takes an HOTP Option object and provides presets for
53
- * some of the missing required HOTP option fields and validates
54
- * the resultant options.
55
- */
56
- export declare function hotpOptions<T extends HOTPOptions<unknown> = HOTPOptions<unknown>>(opt: Readonly<Partial<T>>): Readonly<T>;
57
- /**
58
- * Formats a given counter into a string counter.
59
- */
60
- export declare function hotpCounter(counter: number): HexString;
61
- /**
62
- * Converts a digest to a token of a specified length.
63
- */
64
- export declare function hotpDigestToToken(hexDigest: HexString, digits: number): string;
65
- /**
66
- * Generates a HMAC-based One-time Token (HOTP)
67
- *
68
- * **References**
69
- *
70
- * - http://en.wikipedia.org/wiki/HMAC-based_One-time_Password_Algorithm
71
- * - http://tools.ietf.org/html/rfc4226
72
- *
73
- * **Note**: If options.digest is provided, it will skip digest generation.
74
- * Use options.digest with caution. Same digest = Same token.
75
- *
76
- * @param secret - Your secret key.
77
- * @param counter - the OTP counter (usually it's an incremental count)
78
- * @param options - A HOTPOptions object.
79
- */
80
- export declare function hotpToken<T extends HOTPOptions<unknown> = HOTPOptions<unknown>>(secret: SecretKey, counter: number, options: Readonly<T>): string;
81
- /**
82
- * Checks the given token against the system generated token.
83
- *
84
- * **Note**: Token is valid only if it is a number string
85
- */
86
- export declare function hotpCheck<T extends HOTPOptions<unknown> = HOTPOptions<unknown>>(token: string, secret: SecretKey, counter: number, options: Readonly<T>): boolean;
87
- /**
88
- * Generates a [keyuri](../#keyuri) from options provided
89
- * and it's type set to HOTP.
90
- */
91
- export declare function hotpKeyuri<T extends HOTPOptions<unknown> = HOTPOptions<unknown>>(accountName: string, issuer: string, secret: SecretKey, counter: number, options: Readonly<T>): string;
92
- /**
93
- * A class wrapper containing all HOTP methods.
94
- */
95
- export declare class HOTP<T extends HOTPOptions = HOTPOptions> extends OTP<T> {
96
- /**
97
- * Creates a new instance with all defaultOptions and options reset.
98
- */
99
- create(defaultOptions?: Partial<T>): HOTP<T>;
100
- /**
101
- * Returns class options polyfilled with some of
102
- * the missing required options.
103
- *
104
- * Reference: [[hotpOptions]]
105
- */
106
- allOptions(): Readonly<T>;
107
- /**
108
- * Reference: [[hotpToken]]
109
- */
110
- generate(secret: SecretKey, counter: number): string;
111
- /**
112
- * Reference: [[hotpCheck]]
113
- */
114
- check(token: string, secret: SecretKey, counter: number): boolean;
115
- /**
116
- * Same as [[check]] but accepts a single object based argument.
117
- */
118
- verify(opts: {
119
- token: string;
120
- secret: SecretKey;
121
- counter: number;
122
- }): boolean;
123
- /**
124
- * Calls [keyuri](../#keyuri) with class options and type
125
- * set to HOTP.
126
- */
127
- keyuri(accountName: string, issuer: string, secret: SecretKey, counter: number): string;
128
- }
package/hotp/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './utils';
2
- export * from './hotp';
package/hotp/index.js DELETED
@@ -1,224 +0,0 @@
1
- /**
2
- * otplib-hotp
3
- *
4
- * @author Gerald Yeo <contact@fusedthought.com>
5
- * @version: 12.0.0-1
6
- * @license: MIT
7
- **/
8
- 'use strict';
9
-
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
- function objectValues(value) {
13
- return Object.keys(value).map(key => value[key]);
14
- }
15
- (function (HashAlgorithms) {
16
- HashAlgorithms["SHA1"] = "sha1";
17
- HashAlgorithms["SHA256"] = "sha256";
18
- HashAlgorithms["SHA512"] = "sha512";
19
- })(exports.HashAlgorithms || (exports.HashAlgorithms = {}));
20
- const HASH_ALGORITHMS = objectValues(exports.HashAlgorithms);
21
- (function (KeyEncodings) {
22
- KeyEncodings["ASCII"] = "ascii";
23
- KeyEncodings["BASE64"] = "base64";
24
- KeyEncodings["HEX"] = "hex";
25
- KeyEncodings["LATIN1"] = "latin1";
26
- KeyEncodings["UTF8"] = "utf8";
27
- })(exports.KeyEncodings || (exports.KeyEncodings = {}));
28
- const KEY_ENCODINGS = objectValues(exports.KeyEncodings);
29
- (function (Strategy) {
30
- Strategy["HOTP"] = "hotp";
31
- Strategy["TOTP"] = "totp";
32
- })(exports.Strategy || (exports.Strategy = {}));
33
- const STRATEGY = objectValues(exports.Strategy);
34
- const createDigestPlaceholder = () => {
35
- throw new Error('Please provide an options.createDigest implementation.');
36
- };
37
- function isTokenValid(value) {
38
- return /^(\d+)$/.test(value);
39
- }
40
- function padStart(value, maxLength, fillString) {
41
- if (value.length >= maxLength) {
42
- return value;
43
- }
44
- const padding = Array(maxLength + 1).join(fillString);
45
- return `${padding}${value}`.slice(-1 * maxLength);
46
- }
47
- function keyuri(options) {
48
- const tmpl = `otpauth://${options.type}/{labelPrefix}:{accountName}?secret={secret}{query}`;
49
- const params = [];
50
- if (STRATEGY.indexOf(options.type) < 0) {
51
- throw new Error(`Expecting options.type to be one of ${STRATEGY.join(', ')}. Received ${options.type}.`);
52
- }
53
- if (options.type === 'hotp') {
54
- if (options.counter == null || typeof options.counter !== 'number') {
55
- throw new Error('Expecting options.counter to be a number when options.type is "hotp".');
56
- }
57
- params.push(`&counter=${options.counter}`);
58
- }
59
- if (options.type === 'totp' && options.step) {
60
- params.push(`&period=${options.step}`);
61
- }
62
- if (options.digits) {
63
- params.push(`&digits=${options.digits}`);
64
- }
65
- if (options.algorithm) {
66
- params.push(`&algorithm=${options.algorithm.toUpperCase()}`);
67
- }
68
- if (options.issuer) {
69
- params.push(`&issuer=${encodeURIComponent(options.issuer)}`);
70
- }
71
- return tmpl.replace('{labelPrefix}', encodeURIComponent(options.issuer || options.accountName)).replace('{accountName}', encodeURIComponent(options.accountName)).replace('{secret}', options.secret).replace('{query}', params.join(''));
72
- }
73
- class OTP {
74
- constructor(defaultOptions = {}) {
75
- this._defaultOptions = Object.freeze({ ...defaultOptions
76
- });
77
- this._options = Object.freeze({});
78
- }
79
- create(defaultOptions = {}) {
80
- return new OTP(defaultOptions);
81
- }
82
- clone(defaultOptions = {}) {
83
- const instance = this.create({ ...this._defaultOptions,
84
- ...defaultOptions
85
- });
86
- instance.options = this._options;
87
- return instance;
88
- }
89
- get options() {
90
- return Object.freeze({ ...this._defaultOptions,
91
- ...this._options
92
- });
93
- }
94
- set options(options) {
95
- this._options = Object.freeze({ ...this._options,
96
- ...options
97
- });
98
- }
99
- allOptions() {
100
- return this.options;
101
- }
102
- resetOptions() {
103
- this._options = Object.freeze({});
104
- }
105
- }
106
-
107
- function hotpOptionsValidator(options) {
108
- if (typeof options.createDigest !== 'function') {
109
- throw new Error('Expecting options.createDigest to be a function.');
110
- }
111
- if (typeof options.createHmacKey !== 'function') {
112
- throw new Error('Expecting options.createHmacKey to be a function.');
113
- }
114
- if (typeof options.digits !== 'number') {
115
- throw new Error('Expecting options.digits to be a number.');
116
- }
117
- if (!options.algorithm || HASH_ALGORITHMS.indexOf(options.algorithm) < 0) {
118
- throw new Error(`Expecting options.algorithm to be one of ${HASH_ALGORITHMS.join(', ')}. Received ${options.algorithm}.`);
119
- }
120
- if (!options.encoding || KEY_ENCODINGS.indexOf(options.encoding) < 0) {
121
- throw new Error(`Expecting options.encoding to be one of ${KEY_ENCODINGS.join(', ')}. Received ${options.encoding}.`);
122
- }
123
- }
124
- const hotpCreateHmacKey = (algorithm, secret, encoding) => {
125
- return Buffer.from(secret, encoding).toString('hex');
126
- };
127
- function hotpDefaultOptions() {
128
- const options = {
129
- algorithm: exports.HashAlgorithms.SHA1,
130
- createHmacKey: hotpCreateHmacKey,
131
- createDigest: createDigestPlaceholder,
132
- digits: 6,
133
- encoding: exports.KeyEncodings.ASCII
134
- };
135
- return options;
136
- }
137
- function hotpOptions(opt) {
138
- const options = { ...hotpDefaultOptions(),
139
- ...opt
140
- };
141
- hotpOptionsValidator(options);
142
- return Object.freeze(options);
143
- }
144
- function hotpCounter(counter) {
145
- const hexCounter = counter.toString(16);
146
- return padStart(hexCounter, 16, '0');
147
- }
148
- function hotpDigestToToken(hexDigest, digits) {
149
- const digest = Buffer.from(hexDigest, 'hex');
150
- const offset = digest[digest.length - 1] & 0xf;
151
- const binary = (digest[offset] & 0x7f) << 24 | (digest[offset + 1] & 0xff) << 16 | (digest[offset + 2] & 0xff) << 8 | digest[offset + 3] & 0xff;
152
- const token = binary % Math.pow(10, digits);
153
- return padStart(String(token), digits, '0');
154
- }
155
- function hotpDigest(secret, counter, options) {
156
- const hexCounter = hotpCounter(counter);
157
- const hmacKey = options.createHmacKey(options.algorithm, secret, options.encoding);
158
- return options.createDigest(options.algorithm, hmacKey, hexCounter);
159
- }
160
- function hotpToken(secret, counter, options) {
161
- const hexDigest = options.digest || hotpDigest(secret, counter, options);
162
- return hotpDigestToToken(hexDigest, options.digits);
163
- }
164
- function hotpCheck(token, secret, counter, options) {
165
- if (!isTokenValid(token)) {
166
- return false;
167
- }
168
- const systemToken = hotpToken(secret, counter, options);
169
- return token === systemToken;
170
- }
171
- function hotpKeyuri(accountName, issuer, secret, counter, options) {
172
- return keyuri({
173
- algorithm: options.algorithm,
174
- digits: options.digits,
175
- type: exports.Strategy.HOTP,
176
- accountName,
177
- counter,
178
- issuer,
179
- secret
180
- });
181
- }
182
- class HOTP extends OTP {
183
- create(defaultOptions = {}) {
184
- return new HOTP(defaultOptions);
185
- }
186
- allOptions() {
187
- return hotpOptions(this.options);
188
- }
189
- generate(secret, counter) {
190
- return hotpToken(secret, counter, this.allOptions());
191
- }
192
- check(token, secret, counter) {
193
- return hotpCheck(token, secret, counter, this.allOptions());
194
- }
195
- verify(opts) {
196
- if (typeof opts !== 'object') {
197
- throw new Error('Expecting argument 0 of verify to be an object');
198
- }
199
- return this.check(opts.token, opts.secret, opts.counter);
200
- }
201
- keyuri(accountName, issuer, secret, counter) {
202
- return hotpKeyuri(accountName, issuer, secret, counter, this.allOptions());
203
- }
204
- }
205
-
206
- exports.HASH_ALGORITHMS = HASH_ALGORITHMS;
207
- exports.HOTP = HOTP;
208
- exports.KEY_ENCODINGS = KEY_ENCODINGS;
209
- exports.OTP = OTP;
210
- exports.STRATEGY = STRATEGY;
211
- exports.createDigestPlaceholder = createDigestPlaceholder;
212
- exports.hotpCheck = hotpCheck;
213
- exports.hotpCounter = hotpCounter;
214
- exports.hotpCreateHmacKey = hotpCreateHmacKey;
215
- exports.hotpDefaultOptions = hotpDefaultOptions;
216
- exports.hotpDigestToToken = hotpDigestToToken;
217
- exports.hotpKeyuri = hotpKeyuri;
218
- exports.hotpOptions = hotpOptions;
219
- exports.hotpOptionsValidator = hotpOptionsValidator;
220
- exports.hotpToken = hotpToken;
221
- exports.isTokenValid = isTokenValid;
222
- exports.keyuri = keyuri;
223
- exports.objectValues = objectValues;
224
- exports.padStart = padStart;
package/hotp/utils.d.ts DELETED
@@ -1,208 +0,0 @@
1
- /**
2
- * Secret Key used for OTP generation.
3
- */
4
- export declare type SecretKey = string;
5
- /**
6
- * A hex encoded string.
7
- */
8
- export declare type HexString = string;
9
- /**
10
- * Base interface for all option interfaces.
11
- * eg: [[HOTPOptions]].
12
- */
13
- export interface OTPOptions {
14
- [key: string]: unknown;
15
- }
16
- /**
17
- * Returns an array of values of the enumerable properties of an object.
18
- * This is used in place of Object.values for wider platform support.
19
- *
20
- * @ignore
21
- *
22
- * @param value Object that contains the properties and methods.
23
- */
24
- export declare function objectValues<T>(value: T): string[];
25
- /**
26
- * Algorithms that are available to be used for
27
- * calculating the HMAC value
28
- */
29
- export declare enum HashAlgorithms {
30
- 'SHA1' = "sha1",
31
- 'SHA256' = "sha256",
32
- 'SHA512' = "sha512"
33
- }
34
- /**
35
- * Array of [[HashAlgorithms]] enum values
36
- *
37
- * @ignore
38
- */
39
- export declare const HASH_ALGORITHMS: string[];
40
- /**
41
- * The encoding format for the [[SecretKey]].
42
- * This is mostly used for converting the
43
- * provided secret into a Buffer.
44
- */
45
- export declare enum KeyEncodings {
46
- 'ASCII' = "ascii",
47
- 'BASE64' = "base64",
48
- 'HEX' = "hex",
49
- 'LATIN1' = "latin1",
50
- 'UTF8' = "utf8"
51
- }
52
- /**
53
- * Array of [[KeyEncodings]] enum values
54
- *
55
- * @ignore
56
- */
57
- export declare const KEY_ENCODINGS: string[];
58
- /**
59
- * The OTP generation strategies.
60
- * Either HMAC or Time based.
61
- */
62
- export declare enum Strategy {
63
- 'HOTP' = "hotp",
64
- 'TOTP' = "totp"
65
- }
66
- /**
67
- * Array of [[Strategy]] enum values
68
- *
69
- * @ignore
70
- */
71
- export declare const STRATEGY: string[];
72
- /**
73
- * Interface method for formatting the [[SecretKey]] with
74
- * the algorithm constraints before it is given to [[CreateDigest]].
75
- */
76
- export interface CreateHmacKey<T = HexString> {
77
- (algorithm: HashAlgorithms, secret: SecretKey, encoding: KeyEncodings): T;
78
- }
79
- /**
80
- * Interface method for generating a HMAC digest
81
- * which is then used to generate the token.
82
- */
83
- export interface CreateDigest<T = HexString> {
84
- (algorithm: HashAlgorithms, hmacKey: HexString, counter: HexString): T;
85
- }
86
- /**
87
- * Inteface for options accepted by keyuri
88
- */
89
- export interface KeyURIOptions {
90
- accountName: string;
91
- algorithm?: HashAlgorithms;
92
- counter?: number;
93
- digits?: number;
94
- issuer?: string;
95
- label?: string;
96
- secret: SecretKey;
97
- step?: number;
98
- type: Strategy;
99
- }
100
- /**
101
- * createDigest placholder function which throws an error
102
- * when it is not replaced with an actual implementation.
103
- *
104
- * @ignore
105
- */
106
- export declare const createDigestPlaceholder: CreateDigest;
107
- /**
108
- * Checks if a string contains a valid token format.
109
- *
110
- * @param value - a number string.
111
- */
112
- export declare function isTokenValid(value: string): boolean;
113
- /**
114
- * Left pad the current string with a given string to a given length.
115
- *
116
- * This behaves similarly to String.prototype.padStart
117
- *
118
- * @ignore
119
- *
120
- * @param value The string to pad.
121
- * @param maxLength The length of the resulting string once the current string has been padded.
122
- * If this parameter is smaller than the current string's length, the current
123
- * string will be returned as it is.
124
- * @param fillString The string to pad the current string with.
125
- */
126
- export declare function padStart(value: string, maxLength: number, fillString: string): string;
127
- /**
128
- * Generates an otpauth uri which can be used in a QR Code.
129
- *
130
- * Reference: https://github.com/google/google-authenticator/wiki/Key-Uri-Format
131
- *
132
- * Sample Output: otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
133
- *
134
- * **Example**
135
- *
136
- * ```js
137
- * import qrcode from 'qrcode';
138
- *
139
- * const otpauth = keyuri({ ... })
140
- *
141
- * qrcode.toDataURL(otpauth, (err, imageUrl) => {
142
- * if (err) {
143
- * console.log('Error with QR');
144
- * return;
145
- * }
146
- * console.log(imageUrl);
147
- * });
148
- * ```
149
- */
150
- export declare function keyuri(options: KeyURIOptions): string;
151
- /**
152
- * Base OTP class which provides options management
153
- * All OTP classes should be extended from this class.
154
- */
155
- export declare class OTP<T extends OTPOptions = OTPOptions> {
156
- /**
157
- * Default options for an instance.
158
- *
159
- * These options **WILL PERSIST** even when [[resetOptions]] is called.
160
- */
161
- protected _defaultOptions: Readonly<Partial<T>>;
162
- /**
163
- * Transient options for an instance.
164
- *
165
- * Values set here will take precedence over the same options that
166
- * are set in [[_defaultOptions]].
167
- *
168
- * These options **WILL NOT PERSIST** upon calling [[resetOptions]].
169
- */
170
- protected _options: Readonly<Partial<T>>;
171
- /**
172
- * Constructs the class with defaultOptions set.
173
- *
174
- * @param defaultOptions used to override or add existing defaultOptions.
175
- */
176
- constructor(defaultOptions?: Partial<T>);
177
- /**
178
- * Creates a new instance with all defaultOptions and options reset.
179
- */
180
- create(defaultOptions?: Partial<T>): OTP<T>;
181
- /**
182
- * Copies the defaultOptions and options from the current
183
- * instance and applies the provided defaultOptions.
184
- */
185
- clone(defaultOptions?: Partial<T>): ReturnType<this['create']>;
186
- /**
187
- * - The options **getter** will return all [[_options]],
188
- * including those set into [[_defaultOptions]].
189
- */
190
- /**
191
- * - The options **setter** sets values into [[_options]].
192
- */
193
- options: Partial<T>;
194
- /**
195
- * Returns class options polyfilled with some of
196
- * the missing required options.
197
- *
198
- * Reference: [[hotpOptions]]
199
- */
200
- allOptions(): Readonly<T>;
201
- /**
202
- * Resets the current options. Does not reset default options.
203
- *
204
- * Default options are those that are specified during class
205
- * inititialisation, when calling [[clone]] or when calling [[create]]
206
- */
207
- resetOptions(): void;
208
- }
@@ -1,33 +0,0 @@
1
- import { HOTPOptions, HexString, OTP, SecretKey } from '../hotp';
2
- /**
3
- * Allow HOTPOptions to accept async method options
4
- */
5
- export declare type HOTPAsyncOptions = HOTPOptions<Promise<string>>;
6
- /**
7
- * Generates the digest for HOTP based tokens.
8
- * Async version of [[hotpDigest]].
9
- */
10
- export declare function hotpDigestAsync<T extends HOTPAsyncOptions = HOTPAsyncOptions>(secret: SecretKey, counter: number, options: Readonly<T>): Promise<HexString>;
11
- /**
12
- * Async version of [[hotpToken]].
13
- */
14
- export declare function hotpTokenAsync<T extends HOTPAsyncOptions = HOTPAsyncOptions>(secret: SecretKey, counter: number, options: Readonly<T>): Promise<string>;
15
- /**
16
- * Async version of [[hotpCheck]].
17
- */
18
- export declare function hotpCheckAsync<T extends HOTPAsyncOptions = HOTPAsyncOptions>(token: string, secret: SecretKey, counter: number, options: Readonly<T>): Promise<boolean>;
19
- /**
20
- * Async version of [[HOTP]].
21
- */
22
- export declare class HOTPAsync<T extends HOTPAsyncOptions = HOTPAsyncOptions> extends OTP<T> {
23
- create(defaultOptions?: Partial<T>): HOTPAsync<T>;
24
- allOptions(): Readonly<T>;
25
- generate(secret: SecretKey, counter: number): Promise<string>;
26
- check(token: string, secret: SecretKey, counter: number): Promise<boolean>;
27
- verify(opts: {
28
- token: string;
29
- secret: SecretKey;
30
- counter: number;
31
- }): Promise<boolean>;
32
- keyuri(accountName: string, issuer: string, secret: SecretKey, counter: number): Promise<string>;
33
- }
@@ -1 +0,0 @@
1
- export * from './hotp';
@@ -1,55 +0,0 @@
1
- /**
2
- * otplib-hotp-async
3
- *
4
- * @author Gerald Yeo <contact@fusedthought.com>
5
- * @version: 12.0.0-1
6
- * @license: MIT
7
- **/
8
- 'use strict';
9
-
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
- var otplibHotp = require('../hotp');
13
-
14
- async function hotpDigestAsync(secret, counter, options) {
15
- const hexCounter = otplibHotp.hotpCounter(counter);
16
- const hmacKey = await options.createHmacKey(options.algorithm, secret, options.encoding);
17
- return options.createDigest(options.algorithm, hmacKey, hexCounter);
18
- }
19
- async function hotpTokenAsync(secret, counter, options) {
20
- const digest = await hotpDigestAsync(secret, counter, options);
21
- return otplibHotp.hotpToken(secret, counter, { ...options,
22
- digest
23
- });
24
- }
25
- async function hotpCheckAsync(token, secret, counter, options) {
26
- const digest = await hotpDigestAsync(secret, counter, options);
27
- return otplibHotp.hotpCheck(token, secret, counter, { ...options,
28
- digest
29
- });
30
- }
31
- class HOTPAsync extends otplibHotp.OTP {
32
- create(defaultOptions = {}) {
33
- return new HOTPAsync(defaultOptions);
34
- }
35
- allOptions() {
36
- return otplibHotp.hotpOptions(this.options);
37
- }
38
- async generate(secret, counter) {
39
- return hotpTokenAsync(secret, counter, this.allOptions());
40
- }
41
- async check(token, secret, counter) {
42
- return hotpCheckAsync(token, secret, counter, this.allOptions());
43
- }
44
- async verify(opts) {
45
- return this.check(opts.token, opts.secret, opts.counter);
46
- }
47
- async keyuri(accountName, issuer, secret, counter) {
48
- return otplibHotp.hotpKeyuri(accountName, issuer, secret, counter, this.allOptions());
49
- }
50
- }
51
-
52
- exports.HOTPAsync = HOTPAsync;
53
- exports.hotpCheckAsync = hotpCheckAsync;
54
- exports.hotpDigestAsync = hotpDigestAsync;
55
- exports.hotpTokenAsync = hotpTokenAsync;
@@ -1,9 +0,0 @@
1
- import { KeyDecoder, KeyEncoder } from '../authenticator';
2
- /**
3
- * - Key decoder using npm `base32-decode`
4
- */
5
- export declare const keyDecoder: KeyDecoder;
6
- /**
7
- * - Key encoder using npm `base32-encode`
8
- */
9
- export declare const keyEncoder: KeyEncoder;
@@ -1,28 +0,0 @@
1
- /**
2
- * otplib-plugin-base32-enc-dec
3
- *
4
- * @author Gerald Yeo <contact@fusedthought.com>
5
- * @version: 12.0.0-1
6
- * @license: MIT
7
- **/
8
- 'use strict';
9
-
10
- Object.defineProperty(exports, '__esModule', { value: true });
11
-
12
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
13
-
14
- var base32Decode = _interopDefault(require('base32-decode'));
15
- var base32Encode = _interopDefault(require('base32-encode'));
16
-
17
- const keyDecoder = (secret, encoding) => {
18
- const arrayBuffer = base32Decode(secret.toUpperCase(), 'RFC4648');
19
- return Buffer.from(arrayBuffer).toString(encoding);
20
- };
21
- const keyEncoder = (secret, encoding) => {
22
- return base32Encode(Buffer.from(secret, encoding), 'RFC4648', {
23
- padding: false
24
- });
25
- };
26
-
27
- exports.keyDecoder = keyDecoder;
28
- exports.keyEncoder = keyEncoder;
@@ -1,4 +0,0 @@
1
- import { CreateDigest } from '../hotp';
2
- import { CreateRandomBytes } from '../authenticator';
3
- export declare const createDigest: CreateDigest;
4
- export declare const createRandomBytes: CreateRandomBytes;