@otplib/preset-v11 12.0.1 → 13.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/LICENSE +2 -2
- package/README.md +27 -10
- package/dist/index.cjs +411 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.js +381 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -17
- package/index.d.ts +0 -126
- package/index.js +0 -133
package/index.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
interface HmacOptions {
|
|
3
|
-
algorithm?: string;
|
|
4
|
-
encoding?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type createHmacSecret = (secret: string, options: HmacOptions) => Buffer;
|
|
8
|
-
|
|
9
|
-
interface HotpOptionsInterface extends HmacOptions {
|
|
10
|
-
createHmacSecret?: createHmacSecret;
|
|
11
|
-
crypto?: any;
|
|
12
|
-
digits?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface HotpVerifyOptionsInterface {
|
|
16
|
-
token?: string;
|
|
17
|
-
secret?: string;
|
|
18
|
-
counter?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type hotpCheck = (
|
|
22
|
-
token: string,
|
|
23
|
-
secret: string,
|
|
24
|
-
counter: number,
|
|
25
|
-
options: HotpOptionsInterface
|
|
26
|
-
) => boolean;
|
|
27
|
-
|
|
28
|
-
type hotpCounter = (counter: number) => string;
|
|
29
|
-
|
|
30
|
-
type hotpDigest = (
|
|
31
|
-
secret: string,
|
|
32
|
-
counter: number,
|
|
33
|
-
options: HotpOptionsInterface
|
|
34
|
-
) => string;
|
|
35
|
-
|
|
36
|
-
type hotpOptions = (options: any) => HotpOptionsInterface;
|
|
37
|
-
|
|
38
|
-
type hotpSecret = createHmacSecret;
|
|
39
|
-
|
|
40
|
-
type hotpToken = (
|
|
41
|
-
secret: string,
|
|
42
|
-
counter: number,
|
|
43
|
-
options: HotpOptionsInterface
|
|
44
|
-
) => string;
|
|
45
|
-
|
|
46
|
-
interface TotpOptionsInterface extends HotpOptionsInterface {
|
|
47
|
-
epoch?: any;
|
|
48
|
-
step?: number;
|
|
49
|
-
window?: number | number[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface TotpVerifyOptionsInterface {
|
|
53
|
-
token?: string;
|
|
54
|
-
secret?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type totpCheck = (
|
|
58
|
-
token: string,
|
|
59
|
-
secret: string,
|
|
60
|
-
options: TotpOptionsInterface
|
|
61
|
-
) => boolean;
|
|
62
|
-
|
|
63
|
-
type totpCheckWithWindow = (
|
|
64
|
-
token: string,
|
|
65
|
-
secret: string,
|
|
66
|
-
options: TotpOptionsInterface
|
|
67
|
-
) => number | null;
|
|
68
|
-
|
|
69
|
-
type totpCounter = (epoch: number, step: number) => number;
|
|
70
|
-
|
|
71
|
-
type totpOptions = (options: any) => TotpOptionsInterface;
|
|
72
|
-
|
|
73
|
-
type totpSecret = createHmacSecret;
|
|
74
|
-
|
|
75
|
-
type totpTimeRemaining = (epoch: number, step: number) => number;
|
|
76
|
-
|
|
77
|
-
type totpTimeUsed = (epoch: number, step: number) => number;
|
|
78
|
-
|
|
79
|
-
type totpToken = (secret: string, options: TotpOptionsInterface) => string;
|
|
80
|
-
|
|
81
|
-
declare class HOTP {
|
|
82
|
-
HOTP: typeof HOTP;
|
|
83
|
-
getClass(): typeof HOTP;
|
|
84
|
-
|
|
85
|
-
defaultOptions: HotpOptionsInterface;
|
|
86
|
-
options: HotpOptionsInterface;
|
|
87
|
-
optionsAll: HotpOptionsInterface;
|
|
88
|
-
resetOptions(): this;
|
|
89
|
-
generate(secret: string, counter: number): string;
|
|
90
|
-
check(token: string, secret: string, counter: number): boolean;
|
|
91
|
-
verify(opts: HotpVerifyOptionsInterface): boolean;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
declare class TOTP extends HOTP {
|
|
95
|
-
TOTP: typeof TOTP;
|
|
96
|
-
getClass(): typeof TOTP;
|
|
97
|
-
|
|
98
|
-
defaultOptions: TotpOptionsInterface;
|
|
99
|
-
options: TotpOptionsInterface;
|
|
100
|
-
optionsAll: TotpOptionsInterface;
|
|
101
|
-
generate(secret: string): string;
|
|
102
|
-
check(token: string, secret: string): boolean;
|
|
103
|
-
checkDelta(token: string, secret: string): number | null;
|
|
104
|
-
verify(opts: TotpVerifyOptionsInterface): boolean;
|
|
105
|
-
timeUsed(): number;
|
|
106
|
-
timeRemaining(): number;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare class Authenticator extends TOTP {
|
|
110
|
-
Authenticator: typeof Authenticator;
|
|
111
|
-
getClass(): typeof Authenticator;
|
|
112
|
-
|
|
113
|
-
check(token: string, secret: string): boolean;
|
|
114
|
-
checkDelta(token: string, secret: string): number | null;
|
|
115
|
-
decode(encodedKey: string): string;
|
|
116
|
-
encode(secret: string): string;
|
|
117
|
-
generate(secret: string): string;
|
|
118
|
-
generateSecret(len?: number): string;
|
|
119
|
-
keyuri(user: string, service: string, secret: string): string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
declare module '@otplib/preset-v11' {
|
|
123
|
-
const authenticator: Authenticator;
|
|
124
|
-
const hotp: HOTP;
|
|
125
|
-
const totp: TOTP;
|
|
126
|
-
}
|
package/index.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @otplib/preset-v11
|
|
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 pluginCrypto = require('@otplib/plugin-crypto');
|
|
13
|
-
var pluginThirtyTwo = require('@otplib/plugin-thirty-two');
|
|
14
|
-
var core = require('@otplib/core');
|
|
15
|
-
|
|
16
|
-
function epochUnixToJS(opt = {}) {
|
|
17
|
-
if (!opt || typeof opt !== 'object') {
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
20
|
-
const {
|
|
21
|
-
epoch,
|
|
22
|
-
...others
|
|
23
|
-
} = opt;
|
|
24
|
-
if (epoch === null) {
|
|
25
|
-
return others;
|
|
26
|
-
}
|
|
27
|
-
if (typeof epoch === 'number') {
|
|
28
|
-
return { ...opt,
|
|
29
|
-
epoch: opt.epoch * 1000
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return opt;
|
|
33
|
-
}
|
|
34
|
-
function epochJSToUnix(opt = {}) {
|
|
35
|
-
if (!opt || typeof opt !== 'object') {
|
|
36
|
-
return {};
|
|
37
|
-
}
|
|
38
|
-
const {
|
|
39
|
-
epoch,
|
|
40
|
-
...others
|
|
41
|
-
} = opt;
|
|
42
|
-
if (epoch === null) {
|
|
43
|
-
return others;
|
|
44
|
-
}
|
|
45
|
-
if (typeof epoch === 'number') {
|
|
46
|
-
return { ...opt,
|
|
47
|
-
epoch: epoch / 1000
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return opt;
|
|
51
|
-
}
|
|
52
|
-
function createV11(Base, legacyOptions) {
|
|
53
|
-
class Legacy extends Base {
|
|
54
|
-
constructor(defaultOptions = {}) {
|
|
55
|
-
super(epochUnixToJS({ ...legacyOptions,
|
|
56
|
-
...defaultOptions
|
|
57
|
-
}));
|
|
58
|
-
console.warn(Base.name, 'initialised with v11.x adapter');
|
|
59
|
-
}
|
|
60
|
-
static get name() {
|
|
61
|
-
return Base.name;
|
|
62
|
-
}
|
|
63
|
-
set options(opt = {}) {
|
|
64
|
-
console.warn(Base.name, '.options setter will remove UNIX epoch if it is set to null.' + '\n Do note that library versions above v11.x uses JavaScript epoch.');
|
|
65
|
-
super.options = epochUnixToJS(opt);
|
|
66
|
-
}
|
|
67
|
-
get options() {
|
|
68
|
-
console.warn(Base.name, '.options getter will remove epoch if it is set to null' + '\n Do note that library versions above v11.x uses JavaScript epoch.');
|
|
69
|
-
return epochJSToUnix(super.options);
|
|
70
|
-
}
|
|
71
|
-
get defaultOptions() {
|
|
72
|
-
console.warn(Base.name, '.defaultOptions getter has been deprecated in favour of the .options getter' + '\n\n The .options getter now returns the combined defaultOptions and options values' + 'instead of setting options when adding defaultOptions.');
|
|
73
|
-
return Object.freeze(epochJSToUnix(this._defaultOptions));
|
|
74
|
-
}
|
|
75
|
-
set defaultOptions(opt) {
|
|
76
|
-
console.warn(Base.name, '.defaultOptions setter has been deprecated in favour of the .clone(defaultOptions) method');
|
|
77
|
-
this._defaultOptions = Object.freeze({ ...this._defaultOptions,
|
|
78
|
-
...epochUnixToJS(opt)
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
get optionsAll() {
|
|
82
|
-
console.warn(Base.name, '.optionsAll getter has been deprecated in favour of the .allOptions() method.' + '\n That epoch returned here will be in Unix Epoch, while .allOptions()' + ' will return JavaScript epoch.' + '\n Do note that library versions above v11.x uses JavaScript epoch.');
|
|
83
|
-
return epochJSToUnix(this.allOptions());
|
|
84
|
-
}
|
|
85
|
-
allOptions() {
|
|
86
|
-
return epochUnixToJS(super.allOptions());
|
|
87
|
-
}
|
|
88
|
-
getClass() {
|
|
89
|
-
return Legacy;
|
|
90
|
-
}
|
|
91
|
-
verify(opts) {
|
|
92
|
-
if (!opts || typeof opts !== 'object') {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
return super.verify(opts);
|
|
97
|
-
} catch (err) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
Legacy.prototype[Base.name] = Legacy;
|
|
103
|
-
return Legacy;
|
|
104
|
-
}
|
|
105
|
-
const HOTP = createV11(core.HOTP, {});
|
|
106
|
-
const TOTP = createV11(core.TOTP, {
|
|
107
|
-
epoch: null,
|
|
108
|
-
step: 30,
|
|
109
|
-
window: 0
|
|
110
|
-
});
|
|
111
|
-
const Authenticator = createV11(core.Authenticator, {
|
|
112
|
-
encoding: 'hex',
|
|
113
|
-
epoch: null,
|
|
114
|
-
step: 30,
|
|
115
|
-
window: 0
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const hotp = new HOTP({
|
|
119
|
-
createDigest: pluginCrypto.createDigest
|
|
120
|
-
});
|
|
121
|
-
const totp = new TOTP({
|
|
122
|
-
createDigest: pluginCrypto.createDigest
|
|
123
|
-
});
|
|
124
|
-
const authenticator = new Authenticator({
|
|
125
|
-
createDigest: pluginCrypto.createDigest,
|
|
126
|
-
createRandomBytes: pluginCrypto.createRandomBytes,
|
|
127
|
-
keyEncoder: pluginThirtyTwo.keyEncoder,
|
|
128
|
-
keyDecoder: pluginThirtyTwo.keyDecoder
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
exports.authenticator = authenticator;
|
|
132
|
-
exports.hotp = hotp;
|
|
133
|
-
exports.totp = totp;
|