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.
- package/README.md +115 -388
- package/core.d.ts +1 -0
- package/core.js +23 -0
- package/index.d.ts +1 -0
- package/index.js +23 -0
- package/package.json +16 -98
- package/v11.d.ts +1 -0
- package/v11.js +23 -0
- package/authenticator/authenticator.d.ts +0 -145
- package/authenticator/index.d.ts +0 -1
- package/authenticator/index.js +0 -92
- package/authenticator-async/authenticator.d.ts +0 -34
- package/authenticator-async/index.d.ts +0 -1
- package/authenticator-async/index.js +0 -62
- package/core/index.d.ts +0 -3
- package/core/index.js +0 -41
- package/core-async/index.d.ts +0 -11
- package/core-async/index.js +0 -62
- package/hotp/hotp.d.ts +0 -128
- package/hotp/index.d.ts +0 -2
- package/hotp/index.js +0 -224
- package/hotp/utils.d.ts +0 -208
- package/hotp-async/hotp.d.ts +0 -33
- package/hotp-async/index.d.ts +0 -1
- package/hotp-async/index.js +0 -55
- package/plugin-base32-enc-dec/index.d.ts +0 -9
- package/plugin-base32-enc-dec/index.js +0 -28
- package/plugin-crypto/index.d.ts +0 -4
- package/plugin-crypto/index.js +0 -26
- package/plugin-crypto-async-ronomon/index.d.ts +0 -4
- package/plugin-crypto-async-ronomon/index.js +0 -34
- package/plugin-crypto-js/index.d.ts +0 -4
- package/plugin-crypto-js/index.js +0 -831
- package/plugin-thirty-two/index.d.ts +0 -9
- package/plugin-thirty-two/index.js +0 -24
- package/preset-browser/buffer.js +0 -1
- package/preset-browser/index.d.ts +0 -4
- package/preset-browser/index.js +0 -9
- package/preset-browser/index.js.map +0 -1
- package/preset-default/index.d.ts +0 -4
- package/preset-default/index.js +0 -31
- package/preset-default-async/index.d.ts +0 -4
- package/preset-default-async/index.js +0 -31
- package/preset-v11/index.js +0 -134
- package/totp/index.d.ts +0 -1
- package/totp/index.js +0 -202
- package/totp/totp.d.ts +0 -201
- package/totp-async/index.d.ts +0 -1
- package/totp-async/index.js +0 -98
- package/totp-async/totp.d.ts +0 -46
package/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@otplib/core';
|
package/core.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* otplib
|
|
3
|
+
*
|
|
4
|
+
* @author Gerald Yeo <contact@fusedthought.com>
|
|
5
|
+
* @version: 12.0.1
|
|
6
|
+
* @license: MIT
|
|
7
|
+
**/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var core = require('@otplib/core');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Object.keys(core).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return core[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@otplib/preset-default';
|
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* otplib
|
|
3
|
+
*
|
|
4
|
+
* @author Gerald Yeo <contact@fusedthought.com>
|
|
5
|
+
* @version: 12.0.1
|
|
6
|
+
* @license: MIT
|
|
7
|
+
**/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var presetDefault = require('@otplib/preset-default');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Object.keys(presetDefault).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return presetDefault[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
package/package.json
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otplib",
|
|
3
|
-
"version": "12.0.0-1",
|
|
4
3
|
"description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"build:site": "./scripts/build-site.sh",
|
|
10
|
-
"clean": "rimraf builds coverage",
|
|
11
|
-
"format": "prettier --write \"{packages,scripts,configs}/**/*.{ts,tsx,js,jsx,json,md,mdx}\"",
|
|
12
|
-
"lint": "tsc --noEmit",
|
|
13
|
-
"setup": "./scripts/setup.sh",
|
|
14
|
-
"test": "jest --coverage --runInBand",
|
|
15
|
-
"test:browser": "./scripts/test-browser.sh",
|
|
16
|
-
"test:module": "./scripts/test-module.sh",
|
|
17
|
-
"test:node8": "./scripts/test-node8.sh",
|
|
18
|
-
"test:watch": "jest --watch",
|
|
19
|
-
"update:release-notes": "npx conventional-github-releaser -p angular",
|
|
20
|
-
"upload:coverage": "cat ./coverage/lcov.info | npx coveralls"
|
|
4
|
+
"version": "12.0.1",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
21
8
|
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
9
|
+
"scripts": {},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@otplib/core": "^12.0.1",
|
|
12
|
+
"@otplib/preset-default": "^12.0.1",
|
|
13
|
+
"@otplib/preset-v11": "^12.0.1"
|
|
25
14
|
},
|
|
15
|
+
"otplib": {},
|
|
26
16
|
"keywords": [
|
|
27
|
-
"otp",
|
|
28
17
|
"totp",
|
|
29
18
|
"hotp",
|
|
19
|
+
"otp",
|
|
20
|
+
"authenticator",
|
|
30
21
|
"one time password",
|
|
31
22
|
"google authenticator",
|
|
32
|
-
"authenticator",
|
|
33
23
|
"authentication",
|
|
34
24
|
"2FA",
|
|
35
25
|
"2 factor",
|
|
@@ -38,79 +28,7 @@
|
|
|
38
28
|
],
|
|
39
29
|
"author": "Gerald Yeo <contact@fusedthought.com>",
|
|
40
30
|
"license": "MIT",
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@babel/core": "^7.5.5",
|
|
47
|
-
"@babel/plugin-transform-runtime": "^7.5.5",
|
|
48
|
-
"@babel/preset-env": "^7.5.5",
|
|
49
|
-
"@babel/preset-typescript": "^7.3.3",
|
|
50
|
-
"@babel/runtime": "^7.5.5",
|
|
51
|
-
"@types/crypto-js": "^3.1.43",
|
|
52
|
-
"@types/jest": "^24.0.18",
|
|
53
|
-
"@types/node": "^12.7.2",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^2.0.0",
|
|
55
|
-
"@typescript-eslint/parser": "^2.0.0",
|
|
56
|
-
"babel-jest": "^24.9.0",
|
|
57
|
-
"babel-loader": "^8.0.6",
|
|
58
|
-
"base32-decode": "^1.0.0",
|
|
59
|
-
"base32-encode": "^1.1.1",
|
|
60
|
-
"create-hmac": "^1.1.7",
|
|
61
|
-
"crypto-js": "^3.1.9-1",
|
|
62
|
-
"eslint": "^6.2.2",
|
|
63
|
-
"eslint-config-prettier": "^6.1.0",
|
|
64
|
-
"eslint-plugin-prettier": "^3.1.0",
|
|
65
|
-
"jest": "^24.9.0",
|
|
66
|
-
"prettier": "^1.18.2",
|
|
67
|
-
"rimraf": "^3.0.0",
|
|
68
|
-
"rollup": "^1.20.1",
|
|
69
|
-
"rollup-plugin-babel": "^4.3.3",
|
|
70
|
-
"rollup-plugin-cleanup": "^3.1.1",
|
|
71
|
-
"rollup-plugin-commonjs": "^10.0.2",
|
|
72
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
73
|
-
"thirty-two": "^1.0.2",
|
|
74
|
-
"typescript": "^3.5.3",
|
|
75
|
-
"webpack": "^4.39.2",
|
|
76
|
-
"webpack-cli": "^3.3.7"
|
|
77
|
-
},
|
|
78
|
-
"dependencies": {},
|
|
79
|
-
"jest": {
|
|
80
|
-
"collectCoverageFrom": [
|
|
81
|
-
"packages/**/*.{js,ts}",
|
|
82
|
-
"!**/node_modules/**",
|
|
83
|
-
"!packages/tests-*/*",
|
|
84
|
-
"!packages/otplib-preset-browser/*",
|
|
85
|
-
"!packages/package-cache/*"
|
|
86
|
-
],
|
|
87
|
-
"coverageDirectory": "./coverage/",
|
|
88
|
-
"modulePaths": [
|
|
89
|
-
"<rootDir>/packages/"
|
|
90
|
-
],
|
|
91
|
-
"modulePathIgnorePatterns": [
|
|
92
|
-
"<rootDir>/.*/__mocks__"
|
|
93
|
-
],
|
|
94
|
-
"roots": [
|
|
95
|
-
"<rootDir>/packages/"
|
|
96
|
-
],
|
|
97
|
-
"resetMocks": true,
|
|
98
|
-
"setupFiles": [],
|
|
99
|
-
"testPathIgnorePatterns": [
|
|
100
|
-
"/node_modules/",
|
|
101
|
-
"/packages/tests-data/",
|
|
102
|
-
"/packages/tests-suites/",
|
|
103
|
-
"/packages/package-cache/"
|
|
104
|
-
],
|
|
105
|
-
"testURL": "http://localhost",
|
|
106
|
-
"transform": {
|
|
107
|
-
"^.+\\.(js|ts)$": "babel-jest"
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
"repl": [
|
|
111
|
-
{
|
|
112
|
-
"name": "otplib",
|
|
113
|
-
"module": "./builds/otplib/preset-default"
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
}
|
|
31
|
+
"homepage": "https://yeojz.otplib.dev",
|
|
32
|
+
"repository": "https://github.com/yeojz/otplib",
|
|
33
|
+
"types": "./index.d.ts"
|
|
34
|
+
}
|
package/v11.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@otplib/preset-v11';
|
package/v11.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* otplib
|
|
3
|
+
*
|
|
4
|
+
* @author Gerald Yeo <contact@fusedthought.com>
|
|
5
|
+
* @version: 12.0.1
|
|
6
|
+
* @license: MIT
|
|
7
|
+
**/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var presetV11 = require('@otplib/preset-v11');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Object.keys(presetV11).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return presetV11[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { KeyEncodings, SecretKey } from '../hotp';
|
|
2
|
-
import { TOTP, TOTPOptions } from '../totp';
|
|
3
|
-
/**
|
|
4
|
-
* RFC4648 / RFC3548 Base32 String.
|
|
5
|
-
*
|
|
6
|
-
* Other Base32 encoding methods like Crockford's Base32
|
|
7
|
-
* will not be compatible with Google Authenticator.
|
|
8
|
-
*/
|
|
9
|
-
export declare type Base32SecretKey = SecretKey;
|
|
10
|
-
/**
|
|
11
|
-
* Interface method for [[AuthenticatorOptions.keyEncoder]].
|
|
12
|
-
*/
|
|
13
|
-
export interface KeyEncoder<T = Base32SecretKey> {
|
|
14
|
-
(secret: SecretKey, encoding: KeyEncodings): T;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Interface method for [[AuthenticatorOptions.keyDecoder]].
|
|
18
|
-
*/
|
|
19
|
-
export interface KeyDecoder<T = SecretKey> {
|
|
20
|
-
(encodedSecret: Base32SecretKey, encoding: KeyEncodings): T;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Interface method for [[AuthenticatorOptions.createRandomBytes]].
|
|
24
|
-
*/
|
|
25
|
-
export interface CreateRandomBytes<T = string> {
|
|
26
|
-
(size: number, encoding: KeyEncodings): T;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Interface for options used in Authenticator.
|
|
30
|
-
*
|
|
31
|
-
* Contains additional options in addition to
|
|
32
|
-
* those within TOTP.
|
|
33
|
-
*/
|
|
34
|
-
export interface AuthenticatorOptions<T = string> extends TOTPOptions<T> {
|
|
35
|
-
/**
|
|
36
|
-
* Encodes a secret key into a Base32 string before it is
|
|
37
|
-
* sent to the user (in QR Code etc).
|
|
38
|
-
*/
|
|
39
|
-
keyEncoder: KeyEncoder<T>;
|
|
40
|
-
/**
|
|
41
|
-
* Decodes the Base32 string given by the user into a secret.
|
|
42
|
-
* */
|
|
43
|
-
keyDecoder: KeyDecoder<T>;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a random string containing the defined number of
|
|
46
|
-
* bytes to be used in generating a secret key.
|
|
47
|
-
*/
|
|
48
|
-
createRandomBytes: CreateRandomBytes<T>;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Validates the given [[AuthenticatorOptions]].
|
|
52
|
-
*/
|
|
53
|
-
export declare function authenticatorOptionValidator<T extends AuthenticatorOptions<unknown> = AuthenticatorOptions<unknown>>(options: Partial<T>): void;
|
|
54
|
-
/**
|
|
55
|
-
* Returns a set of default options for authenticator at the current epoch.
|
|
56
|
-
*/
|
|
57
|
-
export declare function authenticatorDefaultOptions<T extends AuthenticatorOptions<unknown> = AuthenticatorOptions<unknown>>(): Partial<T>;
|
|
58
|
-
/**
|
|
59
|
-
* Takes an Authenticator Option object and provides presets for
|
|
60
|
-
* some of the missing required Authenticator option fields and validates
|
|
61
|
-
* the resultant options.
|
|
62
|
-
*/
|
|
63
|
-
export declare function authenticatorOptions<T extends AuthenticatorOptions<unknown> = AuthenticatorOptions<unknown>>(opt: Partial<T>): Readonly<T>;
|
|
64
|
-
/**
|
|
65
|
-
* Encodes a given secret key into a Base32 secret
|
|
66
|
-
* using a [[KeyEncoder]] method set in the options.
|
|
67
|
-
*
|
|
68
|
-
* @param secret - The [[SecretKey]] to encode into a [[Base32SecretKey]]
|
|
69
|
-
* @param options - An [[AuthenticatorOptions]] object
|
|
70
|
-
*/
|
|
71
|
-
export declare function authenticatorEncoder<T extends AuthenticatorOptions<unknown> = AuthenticatorOptions<unknown>>(secret: SecretKey, options: Pick<T, 'keyEncoder' | 'encoding'>): ReturnType<T['keyEncoder']>;
|
|
72
|
-
/**
|
|
73
|
-
* Decodes a given Base32 secret to a secret key
|
|
74
|
-
* using a [[KeyDecoder]] method set in the options.
|
|
75
|
-
*
|
|
76
|
-
* @param secret - The [[Base32SecretKey]] to decode
|
|
77
|
-
* @param options - An [[AuthenticatorOptions]] object
|
|
78
|
-
*/
|
|
79
|
-
export declare function authenticatorDecoder<T extends AuthenticatorOptions<unknown> = AuthenticatorOptions<unknown>>(secret: Base32SecretKey, options: Pick<T, 'keyDecoder' | 'encoding'>): ReturnType<T['keyDecoder']>;
|
|
80
|
-
/**
|
|
81
|
-
* Generates a random Base32 Secret Key.
|
|
82
|
-
*
|
|
83
|
-
* @param numberOfBytes - Number of bytes per secret key
|
|
84
|
-
* @param options.createRandomBytes
|
|
85
|
-
* @param options.encoding
|
|
86
|
-
* @param options.keyEncoder
|
|
87
|
-
*/
|
|
88
|
-
export declare function authenticatorGenerateSecret<T extends AuthenticatorOptions = AuthenticatorOptions>(numberOfBytes: number, options: Pick<T, 'keyEncoder' | 'encoding' | 'createRandomBytes'>): Base32SecretKey;
|
|
89
|
-
/**
|
|
90
|
-
* Generates the Authenticator based token.
|
|
91
|
-
*
|
|
92
|
-
* tl;dr: Authenticator = TOTP + Base32 Secret
|
|
93
|
-
*
|
|
94
|
-
* **References**
|
|
95
|
-
*
|
|
96
|
-
* - https://en.wikipedia.org/wiki/Google_Authenticator
|
|
97
|
-
*
|
|
98
|
-
* @param secret - [[Base32SecretKey]]
|
|
99
|
-
* @param options - An [[AuthenticatorOptions]] object.
|
|
100
|
-
*/
|
|
101
|
-
export declare function authenticatorToken<T extends AuthenticatorOptions = AuthenticatorOptions>(secret: Base32SecretKey, options: Readonly<T>): string;
|
|
102
|
-
/**
|
|
103
|
-
* Decodes the encodedSecret and passes it to [[totpCheckWithWindow]]
|
|
104
|
-
*
|
|
105
|
-
* @param token - The token to check
|
|
106
|
-
* @param secret - The [[Base32SecretKey]]
|
|
107
|
-
* @param options - An [[AuthenticatorOptions]] object.
|
|
108
|
-
*/
|
|
109
|
-
export declare function authenticatorCheckWithWindow<T extends AuthenticatorOptions = AuthenticatorOptions>(token: string, secret: Base32SecretKey, options: Readonly<T>): number | null;
|
|
110
|
-
/**
|
|
111
|
-
* A class wrapper containing all Authenticator methods.
|
|
112
|
-
*/
|
|
113
|
-
export declare class Authenticator<T extends AuthenticatorOptions<string> = AuthenticatorOptions<string>> extends TOTP<T> {
|
|
114
|
-
/**
|
|
115
|
-
* Creates a new instance with all defaultOptions and options reset.
|
|
116
|
-
*/
|
|
117
|
-
create(defaultOptions?: Partial<T>): Authenticator<T>;
|
|
118
|
-
/**
|
|
119
|
-
* Returns a set of options at the current moment,
|
|
120
|
-
* polyfilled with some of the missing required options.
|
|
121
|
-
*
|
|
122
|
-
* Refer to [[authenticatorOptions]]
|
|
123
|
-
*/
|
|
124
|
-
allOptions(): Readonly<T>;
|
|
125
|
-
/**
|
|
126
|
-
* Reference: [[authenticatorToken]]
|
|
127
|
-
*/
|
|
128
|
-
generate(secret: Base32SecretKey): string;
|
|
129
|
-
/**
|
|
130
|
-
* Reference: [[authenticatorCheckWithWindow]]
|
|
131
|
-
*/
|
|
132
|
-
checkDelta(token: string, secret: Base32SecretKey): number | null;
|
|
133
|
-
/**
|
|
134
|
-
* Reference: [[authenticatorEncoder]]
|
|
135
|
-
*/
|
|
136
|
-
encode(secret: SecretKey): Base32SecretKey;
|
|
137
|
-
/**
|
|
138
|
-
* Reference: [[authenticatorDecoder]]
|
|
139
|
-
*/
|
|
140
|
-
decode(secret: Base32SecretKey): SecretKey;
|
|
141
|
-
/**
|
|
142
|
-
* Reference: [[authenticatorGenerateSecret]]
|
|
143
|
-
*/
|
|
144
|
-
generateSecret(numberOfBytes?: number): Base32SecretKey;
|
|
145
|
-
}
|
package/authenticator/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './authenticator';
|
package/authenticator/index.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* otplib-authenticator
|
|
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
|
-
var otplibTotp = require('../totp');
|
|
14
|
-
|
|
15
|
-
function authenticatorOptionValidator(options) {
|
|
16
|
-
otplibTotp.totpOptionsValidator(options);
|
|
17
|
-
if (typeof options.keyDecoder !== 'function') {
|
|
18
|
-
throw new Error('Expecting options.keyDecoder to be a function.');
|
|
19
|
-
}
|
|
20
|
-
if (options.keyEncoder && typeof options.keyEncoder !== 'function') {
|
|
21
|
-
throw new Error('Expecting options.keyEncoder to be a function.');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function authenticatorDefaultOptions() {
|
|
25
|
-
const options = {
|
|
26
|
-
algorithm: otplibHotp.HashAlgorithms.SHA1,
|
|
27
|
-
createDigest: otplibHotp.createDigestPlaceholder,
|
|
28
|
-
createHmacKey: otplibTotp.totpCreateHmacKey,
|
|
29
|
-
digits: 6,
|
|
30
|
-
encoding: otplibHotp.KeyEncodings.HEX,
|
|
31
|
-
epoch: Date.now(),
|
|
32
|
-
step: 30,
|
|
33
|
-
window: 0
|
|
34
|
-
};
|
|
35
|
-
return options;
|
|
36
|
-
}
|
|
37
|
-
function authenticatorOptions(opt) {
|
|
38
|
-
const options = { ...authenticatorDefaultOptions(),
|
|
39
|
-
...opt
|
|
40
|
-
};
|
|
41
|
-
authenticatorOptionValidator(options);
|
|
42
|
-
return Object.freeze(options);
|
|
43
|
-
}
|
|
44
|
-
function authenticatorEncoder(secret, options) {
|
|
45
|
-
return options.keyEncoder(secret, options.encoding);
|
|
46
|
-
}
|
|
47
|
-
function authenticatorDecoder(secret, options) {
|
|
48
|
-
return options.keyDecoder(secret, options.encoding);
|
|
49
|
-
}
|
|
50
|
-
function authenticatorGenerateSecret(numberOfBytes, options) {
|
|
51
|
-
const key = options.createRandomBytes(numberOfBytes, options.encoding);
|
|
52
|
-
return authenticatorEncoder(key, options);
|
|
53
|
-
}
|
|
54
|
-
function authenticatorToken(secret, options) {
|
|
55
|
-
return otplibTotp.totpToken(authenticatorDecoder(secret, options), options);
|
|
56
|
-
}
|
|
57
|
-
function authenticatorCheckWithWindow(token, secret, options) {
|
|
58
|
-
return otplibTotp.totpCheckWithWindow(token, authenticatorDecoder(secret, options), options);
|
|
59
|
-
}
|
|
60
|
-
class Authenticator extends otplibTotp.TOTP {
|
|
61
|
-
create(defaultOptions = {}) {
|
|
62
|
-
return new Authenticator(defaultOptions);
|
|
63
|
-
}
|
|
64
|
-
allOptions() {
|
|
65
|
-
return authenticatorOptions(this.options);
|
|
66
|
-
}
|
|
67
|
-
generate(secret) {
|
|
68
|
-
return authenticatorToken(secret, this.allOptions());
|
|
69
|
-
}
|
|
70
|
-
checkDelta(token, secret) {
|
|
71
|
-
return authenticatorCheckWithWindow(token, secret, this.allOptions());
|
|
72
|
-
}
|
|
73
|
-
encode(secret) {
|
|
74
|
-
return authenticatorEncoder(secret, this.allOptions());
|
|
75
|
-
}
|
|
76
|
-
decode(secret) {
|
|
77
|
-
return authenticatorDecoder(secret, this.allOptions());
|
|
78
|
-
}
|
|
79
|
-
generateSecret(numberOfBytes = 10) {
|
|
80
|
-
return authenticatorGenerateSecret(numberOfBytes, this.allOptions());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.Authenticator = Authenticator;
|
|
85
|
-
exports.authenticatorCheckWithWindow = authenticatorCheckWithWindow;
|
|
86
|
-
exports.authenticatorDecoder = authenticatorDecoder;
|
|
87
|
-
exports.authenticatorDefaultOptions = authenticatorDefaultOptions;
|
|
88
|
-
exports.authenticatorEncoder = authenticatorEncoder;
|
|
89
|
-
exports.authenticatorGenerateSecret = authenticatorGenerateSecret;
|
|
90
|
-
exports.authenticatorOptionValidator = authenticatorOptionValidator;
|
|
91
|
-
exports.authenticatorOptions = authenticatorOptions;
|
|
92
|
-
exports.authenticatorToken = authenticatorToken;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { HexString, SecretKey } from '../hotp';
|
|
2
|
-
import { AuthenticatorOptions, Base32SecretKey } from '../authenticator';
|
|
3
|
-
import { TOTPAsync } from '../totp-async';
|
|
4
|
-
/**
|
|
5
|
-
* Allow AuthenticatorOptions to accept async method options.
|
|
6
|
-
*/
|
|
7
|
-
export declare type AuthenticatorAsyncOptions = AuthenticatorOptions<Promise<string>>;
|
|
8
|
-
/**
|
|
9
|
-
* Generates the digest for Authenticator based tokens.
|
|
10
|
-
*
|
|
11
|
-
* Uses [[totpDigestAsync]].
|
|
12
|
-
*/
|
|
13
|
-
export declare function authenticatorDigestAsync<T extends AuthenticatorAsyncOptions = AuthenticatorAsyncOptions>(secret: Base32SecretKey, options: Readonly<T>): Promise<HexString>;
|
|
14
|
-
/**
|
|
15
|
-
* Async version of [[authenticatorToken]].
|
|
16
|
-
*/
|
|
17
|
-
export declare function authenticatorTokenAsync<T extends AuthenticatorAsyncOptions = AuthenticatorAsyncOptions>(secret: Base32SecretKey, options: Readonly<T>): Promise<string>;
|
|
18
|
-
/**
|
|
19
|
-
* Async version of [[authenticatorCheckWithWindow]].
|
|
20
|
-
*/
|
|
21
|
-
export declare function authenticatorCheckWithWindowAsync<T extends AuthenticatorAsyncOptions = AuthenticatorAsyncOptions>(token: string, secret: Base32SecretKey, options: Readonly<T>): Promise<number | null>;
|
|
22
|
-
export declare function authenticatorGenerateSecretAsync<T extends AuthenticatorAsyncOptions = AuthenticatorAsyncOptions>(numberOfBytes: number, options: Pick<T, 'keyEncoder' | 'encoding' | 'createRandomBytes'>): Promise<Base32SecretKey>;
|
|
23
|
-
/**
|
|
24
|
-
* Async version of [[Authenticator]].
|
|
25
|
-
*/
|
|
26
|
-
export declare class AuthenticatorAsync<T extends AuthenticatorAsyncOptions = AuthenticatorAsyncOptions> extends TOTPAsync<T> {
|
|
27
|
-
create(defaultOptions?: Partial<T>): AuthenticatorAsync<T>;
|
|
28
|
-
allOptions(): Readonly<T>;
|
|
29
|
-
generate(secret: SecretKey): Promise<string>;
|
|
30
|
-
checkDelta(token: string, secret: SecretKey): Promise<number | null>;
|
|
31
|
-
encode(secret: SecretKey): Promise<Base32SecretKey>;
|
|
32
|
-
decode(secret: Base32SecretKey): Promise<SecretKey>;
|
|
33
|
-
generateSecret(numberOfBytes?: number): Promise<Base32SecretKey>;
|
|
34
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './authenticator';
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* otplib-authenticator-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 otplibAuthenticator = require('../authenticator');
|
|
13
|
-
var otplibTotpAsync = require('../totp-async');
|
|
14
|
-
var otplibCore = require('../core');
|
|
15
|
-
|
|
16
|
-
async function authenticatorDigestAsync(secret, options) {
|
|
17
|
-
const decodedSecret = await otplibAuthenticator.authenticatorDecoder(secret, options);
|
|
18
|
-
return otplibTotpAsync.totpDigestAsync(decodedSecret, options);
|
|
19
|
-
}
|
|
20
|
-
async function authenticatorTokenAsync(secret, options) {
|
|
21
|
-
const digest = await authenticatorDigestAsync(secret, options);
|
|
22
|
-
return otplibCore.totpToken(secret, { ...options,
|
|
23
|
-
digest
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
async function authenticatorCheckWithWindowAsync(token, secret, options) {
|
|
27
|
-
const decodedSecret = await otplibAuthenticator.authenticatorDecoder(secret, options);
|
|
28
|
-
return otplibTotpAsync.totpCheckWithWindowAsync(token, decodedSecret, options);
|
|
29
|
-
}
|
|
30
|
-
async function authenticatorGenerateSecretAsync(numberOfBytes, options) {
|
|
31
|
-
const key = await options.createRandomBytes(numberOfBytes, options.encoding);
|
|
32
|
-
return otplibAuthenticator.authenticatorEncoder(key, options);
|
|
33
|
-
}
|
|
34
|
-
class AuthenticatorAsync extends otplibTotpAsync.TOTPAsync {
|
|
35
|
-
create(defaultOptions = {}) {
|
|
36
|
-
return new AuthenticatorAsync(defaultOptions);
|
|
37
|
-
}
|
|
38
|
-
allOptions() {
|
|
39
|
-
return otplibCore.authenticatorOptions(this.options);
|
|
40
|
-
}
|
|
41
|
-
async generate(secret) {
|
|
42
|
-
return authenticatorTokenAsync(secret, this.allOptions());
|
|
43
|
-
}
|
|
44
|
-
async checkDelta(token, secret) {
|
|
45
|
-
return authenticatorCheckWithWindowAsync(token, secret, this.allOptions());
|
|
46
|
-
}
|
|
47
|
-
async encode(secret) {
|
|
48
|
-
return otplibAuthenticator.authenticatorEncoder(secret, this.allOptions());
|
|
49
|
-
}
|
|
50
|
-
async decode(secret) {
|
|
51
|
-
return otplibAuthenticator.authenticatorDecoder(secret, this.allOptions());
|
|
52
|
-
}
|
|
53
|
-
async generateSecret(numberOfBytes = 10) {
|
|
54
|
-
return authenticatorGenerateSecretAsync(numberOfBytes, this.allOptions());
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
exports.AuthenticatorAsync = AuthenticatorAsync;
|
|
59
|
-
exports.authenticatorCheckWithWindowAsync = authenticatorCheckWithWindowAsync;
|
|
60
|
-
exports.authenticatorDigestAsync = authenticatorDigestAsync;
|
|
61
|
-
exports.authenticatorGenerateSecretAsync = authenticatorGenerateSecretAsync;
|
|
62
|
-
exports.authenticatorTokenAsync = authenticatorTokenAsync;
|
package/core/index.d.ts
DELETED
package/core/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* otplib-core
|
|
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
|
-
var otplibTotp = require('../totp');
|
|
14
|
-
var otplibAuthenticator = require('../authenticator');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Object.keys(otplibHotp).forEach(function (k) {
|
|
19
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return otplibHotp[k];
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
Object.keys(otplibTotp).forEach(function (k) {
|
|
27
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () {
|
|
30
|
-
return otplibTotp[k];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
Object.keys(otplibAuthenticator).forEach(function (k) {
|
|
35
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function () {
|
|
38
|
-
return otplibAuthenticator[k];
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
package/core-async/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides async methods and classes
|
|
3
|
-
* in addition to the normal ../core methods and classes
|
|
4
|
-
*/
|
|
5
|
-
export * from '../core';
|
|
6
|
-
export * from '../hotp-async';
|
|
7
|
-
export * from '../totp-async';
|
|
8
|
-
export * from '../authenticator-async';
|
|
9
|
-
export declare const HOTP: new () => void;
|
|
10
|
-
export declare const TOTP: new () => void;
|
|
11
|
-
export declare const Authenticator: new () => void;
|
package/core-async/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* otplib-core-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 otplibCore = require('../core');
|
|
13
|
-
var otplibHotpAsync = require('../hotp-async');
|
|
14
|
-
var otplibTotpAsync = require('../totp-async');
|
|
15
|
-
var otplibAuthenticatorAsync = require('../authenticator-async');
|
|
16
|
-
|
|
17
|
-
function useAsyncClassOnly(className) {
|
|
18
|
-
return class {
|
|
19
|
-
constructor() {
|
|
20
|
-
throw new Error(`You are importing from ${className} from the *-async package.` + ` Please replace your ${className} import with ${className}Async instead.`);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const HOTP = useAsyncClassOnly('HOTP');
|
|
25
|
-
const TOTP = useAsyncClassOnly('TOTP');
|
|
26
|
-
const Authenticator = useAsyncClassOnly('Authenticator');
|
|
27
|
-
|
|
28
|
-
Object.keys(otplibCore).forEach(function (k) {
|
|
29
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return otplibCore[k];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
Object.keys(otplibHotpAsync).forEach(function (k) {
|
|
37
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return otplibHotpAsync[k];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
Object.keys(otplibTotpAsync).forEach(function (k) {
|
|
45
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
get: function () {
|
|
48
|
-
return otplibTotpAsync[k];
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
Object.keys(otplibAuthenticatorAsync).forEach(function (k) {
|
|
53
|
-
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get: function () {
|
|
56
|
-
return otplibAuthenticatorAsync[k];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
exports.Authenticator = Authenticator;
|
|
61
|
-
exports.HOTP = HOTP;
|
|
62
|
-
exports.TOTP = TOTP;
|