@otplib/v12-adapter 13.2.1 → 13.3.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/README.md CHANGED
@@ -50,4 +50,4 @@ For a full guide on migrating to v13, including the benefits of the new architec
50
50
 
51
51
  ## License
52
52
 
53
- [MIT](./LICENSE) © 2026 Gerald Yeo
53
+ [MIT](./LICENSE)
package/dist/index.cjs CHANGED
@@ -1,546 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- Authenticator: () => Authenticator,
24
- HOTP: () => HOTP,
25
- HashAlgorithms: () => HashAlgorithms,
26
- KeyEncodings: () => KeyEncodings,
27
- NobleCryptoPlugin: () => import_plugin_crypto_noble4.NobleCryptoPlugin,
28
- ScureBase32Plugin: () => import_plugin_base32_scure4.ScureBase32Plugin,
29
- TOTP: () => TOTP,
30
- authenticator: () => authenticator,
31
- hotp: () => hotp,
32
- hotpDigestToToken: () => hotpDigestToToken,
33
- totp: () => totp
34
- });
35
- module.exports = __toCommonJS(index_exports);
36
-
37
- // src/hotp.ts
38
- var import_core = require("@otplib/core");
39
- var import_hotp = require("@otplib/hotp");
40
- var import_plugin_base32_scure = require("@otplib/plugin-base32-scure");
41
- var import_plugin_crypto_noble = require("@otplib/plugin-crypto-noble");
42
- var import_uri = require("@otplib/uri");
43
- var import_base = require("@scure/base");
44
-
45
- // src/types.ts
46
- var HashAlgorithms = {
47
- SHA1: "sha1",
48
- SHA256: "sha256",
49
- SHA512: "sha512"
50
- };
51
- var KeyEncodings = {
52
- ASCII: "ascii",
53
- HEX: "hex",
54
- BASE32: "base32",
55
- BASE64: "base64",
56
- LATIN1: "latin1",
57
- UTF8: "utf8"
58
- };
59
-
60
- // src/hotp.ts
61
- function secretToBytes(secret, encoding) {
62
- if (encoding === KeyEncodings.BASE32 || encoding === "base32") {
63
- return import_plugin_base32_scure.base32.decode(secret);
64
- }
65
- if (encoding === KeyEncodings.HEX || encoding === "hex") {
66
- return import_base.hex.decode(secret.replace(/\s/g, ""));
67
- }
68
- return (0, import_core.stringToBytes)(secret);
69
- }
70
- function hotpDigestToToken(hexDigest, digits) {
71
- const digestBytes = import_base.hex.decode(hexDigest);
72
- const truncated = (0, import_core.dynamicTruncate)(digestBytes);
73
- return (0, import_core.truncateDigits)(truncated, digits);
74
- }
75
- var HOTP = class _HOTP {
76
- /**
77
- * Stored options that can be modified
78
- */
79
- _options = {};
80
- /**
81
- * Default options applied to all operations
82
- */
83
- _defaultOptions = {};
84
- constructor(defaultOptions = {}) {
85
- this._defaultOptions = {
86
- ...defaultOptions,
87
- guardrails: (0, import_core.createGuardrails)(defaultOptions.guardrails)
88
- };
89
- this._options = {};
90
- }
91
- /**
92
- * Get current options (merged with defaults)
93
- */
94
- get options() {
95
- return { ...this._defaultOptions, ...this._options };
96
- }
97
- /**
98
- * Set options (replaces current options)
99
- */
100
- set options(value) {
101
- this._options = { ...value };
102
- }
103
- /**
104
- * Creates a new instance with the specified default options
105
- */
106
- create(defaultOptions = {}) {
107
- return new _HOTP(defaultOptions);
108
- }
109
- /**
110
- * Returns class options polyfilled with default values
111
- */
112
- allOptions() {
113
- const merged = {
114
- algorithm: HashAlgorithms.SHA1,
115
- digits: 6,
116
- encoding: KeyEncodings.ASCII,
117
- crypto: import_plugin_crypto_noble.crypto,
118
- base32: import_plugin_base32_scure.base32,
119
- ...this._defaultOptions,
120
- ...this._options
121
- };
122
- return Object.freeze(merged);
123
- }
124
- /**
125
- * Reset options to defaults
126
- */
127
- resetOptions() {
128
- this._options = {};
129
- return this;
130
- }
131
- /**
132
- * Generate an HOTP token
133
- */
134
- generate(secret, counter) {
135
- const opts = this.allOptions();
136
- const secretBytes = secretToBytes(secret, opts.encoding);
137
- return (0, import_hotp.generateSync)({
138
- secret: secretBytes,
139
- counter,
140
- algorithm: opts.algorithm,
141
- digits: opts.digits,
142
- crypto: opts.crypto,
143
- guardrails: opts.guardrails
144
- });
145
- }
146
- /**
147
- * Check if a token is valid for the given secret and counter
148
- */
149
- check(token, secret, counter) {
150
- const opts = this.allOptions();
151
- const secretBytes = secretToBytes(secret, opts.encoding);
152
- try {
153
- const result = (0, import_hotp.verifySync)({
154
- secret: secretBytes,
155
- token,
156
- counter,
157
- algorithm: opts.algorithm,
158
- digits: opts.digits,
159
- counterTolerance: 0,
160
- crypto: opts.crypto,
161
- guardrails: opts.guardrails
162
- });
163
- return result.valid;
164
- } catch {
165
- return false;
166
- }
167
- }
168
- /**
169
- * Verify a token (object-based API)
170
- */
171
- verify(opts) {
172
- if (typeof opts !== "object") {
173
- throw new Error("Expecting argument 0 of verify to be an object");
174
- }
175
- return this.check(opts.token, opts.secret, opts.counter);
176
- }
177
- /**
178
- * Generate an otpauth:// URI for HOTP
179
- */
180
- keyuri(accountName, issuer, secret, counter) {
181
- const opts = this.allOptions();
182
- return (0, import_uri.generateHOTP)({
183
- label: accountName,
184
- issuer,
185
- secret,
186
- algorithm: opts.algorithm,
187
- digits: opts.digits,
188
- counter
189
- });
190
- }
191
- };
192
-
193
- // src/totp.ts
194
- var import_plugin_base32_scure2 = require("@otplib/plugin-base32-scure");
195
- var import_plugin_crypto_noble2 = require("@otplib/plugin-crypto-noble");
196
- var import_totp = require("@otplib/totp");
197
- var import_uri2 = require("@otplib/uri");
198
- function parseWindow(window, step) {
199
- if (window === void 0 || window === 0) {
200
- return 0;
201
- }
202
- if (typeof window === "number") {
203
- return window * step;
204
- }
205
- return [window[0] * step, window[1] * step];
206
- }
207
- var TOTP = class _TOTP extends HOTP {
208
- constructor(defaultOptions = {}) {
209
- super(defaultOptions);
210
- }
211
- /**
212
- * Creates a new TOTP instance with the specified default options
213
- */
214
- create(defaultOptions = {}) {
215
- return new _TOTP(defaultOptions);
216
- }
217
- /**
218
- * Returns class options polyfilled with TOTP default values
219
- */
220
- allOptions() {
221
- const merged = {
222
- algorithm: HashAlgorithms.SHA1,
223
- digits: 6,
224
- encoding: KeyEncodings.ASCII,
225
- epoch: Date.now(),
226
- step: 30,
227
- window: 0,
228
- crypto: import_plugin_crypto_noble2.crypto,
229
- base32: import_plugin_base32_scure2.base32,
230
- ...this._defaultOptions,
231
- ...this._options
232
- };
233
- return Object.freeze(merged);
234
- }
235
- /**
236
- * Generate a TOTP token
237
- *
238
- * @param secret - The secret key
239
- * @returns The OTP token
240
- */
241
- generate(secret) {
242
- const opts = this.allOptions();
243
- const secretBytes = secretToBytes(secret, opts.encoding);
244
- const epochSeconds = Math.floor(opts.epoch / 1e3);
245
- return (0, import_totp.generateSync)({
246
- secret: secretBytes,
247
- algorithm: opts.algorithm,
248
- digits: opts.digits,
249
- period: opts.step,
250
- epoch: epochSeconds,
251
- t0: 0,
252
- crypto: opts.crypto,
253
- guardrails: opts.guardrails
254
- });
255
- }
256
- /**
257
- * Check if a token is valid for the given secret
258
- *
259
- * @param token - The token to verify
260
- * @param secret - The secret key
261
- * @returns true if valid
262
- */
263
- check(token, secret) {
264
- const delta = this.checkDelta(token, secret);
265
- return typeof delta === "number";
266
- }
267
- /**
268
- * Check token and return the time window delta
269
- *
270
- * @param token - The token to verify
271
- * @param secret - The secret key
272
- * @returns Window delta (0 = current, positive = future, negative = past), null if invalid
273
- */
274
- checkDelta(token, secret) {
275
- const opts = this.allOptions();
276
- const secretBytes = secretToBytes(secret, opts.encoding);
277
- const epochSeconds = Math.floor(opts.epoch / 1e3);
278
- const step = opts.step;
279
- const window = opts.window;
280
- const epochTolerance = parseWindow(window, step);
281
- try {
282
- const result = (0, import_totp.verifySync)({
283
- secret: secretBytes,
284
- token,
285
- algorithm: opts.algorithm,
286
- digits: opts.digits,
287
- period: step,
288
- epoch: epochSeconds,
289
- t0: 0,
290
- epochTolerance,
291
- crypto: opts.crypto,
292
- guardrails: opts.guardrails
293
- });
294
- if (!result.valid) {
295
- return null;
296
- }
297
- return result.delta;
298
- } catch {
299
- return null;
300
- }
301
- }
302
- /**
303
- * Verify a token (object-based API)
304
- *
305
- * @param opts - Verification options
306
- * @returns true if valid
307
- */
308
- verify(opts) {
309
- if (typeof opts !== "object") {
310
- throw new Error("Expecting argument 0 of verify to be an object");
311
- }
312
- return this.check(opts.token, opts.secret);
313
- }
314
- /**
315
- * Generate an otpauth:// URI for TOTP
316
- *
317
- * @param accountName - Account name for the URI
318
- * @param issuer - Issuer name
319
- * @param secret - The secret key (should be Base32 for QR codes)
320
- * @returns The otpauth:// URI
321
- */
322
- keyuri(accountName, issuer, secret) {
323
- const opts = this.allOptions();
324
- return (0, import_uri2.generateTOTP)({
325
- label: accountName,
326
- issuer,
327
- secret,
328
- algorithm: opts.algorithm,
329
- digits: opts.digits,
330
- period: opts.step
331
- });
332
- }
333
- /**
334
- * Get time used in current step (seconds elapsed in current window)
335
- *
336
- * @returns Seconds used in current step
337
- */
338
- timeUsed() {
339
- const opts = this.allOptions();
340
- const epochSeconds = Math.floor(opts.epoch / 1e3);
341
- return epochSeconds % opts.step;
342
- }
343
- /**
344
- * Get time remaining until next token
345
- *
346
- * @returns Seconds remaining in current step
347
- */
348
- timeRemaining() {
349
- const opts = this.allOptions();
350
- const epochSeconds = Math.floor(opts.epoch / 1e3);
351
- return (0, import_totp.getRemainingTime)(epochSeconds, opts.step, 0);
352
- }
353
- };
354
-
355
- // src/authenticator.ts
356
- var import_core2 = require("@otplib/core");
357
- var import_plugin_base32_scure3 = require("@otplib/plugin-base32-scure");
358
- var import_plugin_crypto_noble3 = require("@otplib/plugin-crypto-noble");
359
- var import_totp2 = require("@otplib/totp");
360
- function defaultKeyEncoder(secret, _encoding) {
361
- const bytes = new TextEncoder().encode(secret);
362
- return import_plugin_base32_scure3.base32.encode(bytes);
363
- }
364
- function defaultKeyDecoder(encodedSecret, _encoding) {
365
- const bytes = import_plugin_base32_scure3.base32.decode(encodedSecret);
366
- return new TextDecoder().decode(bytes);
367
- }
368
- var Authenticator = class _Authenticator extends TOTP {
369
- constructor(defaultOptions = {}) {
370
- super(defaultOptions);
371
- }
372
- /**
373
- * Creates a new Authenticator instance with the specified default options
374
- */
375
- create(defaultOptions = {}) {
376
- return new _Authenticator(defaultOptions);
377
- }
378
- /**
379
- * Returns class options polyfilled with Authenticator default values
380
- */
381
- allOptions() {
382
- const merged = {
383
- algorithm: HashAlgorithms.SHA1,
384
- digits: 6,
385
- encoding: KeyEncodings.HEX,
386
- epoch: Date.now(),
387
- step: 30,
388
- window: 0,
389
- keyEncoder: defaultKeyEncoder,
390
- keyDecoder: defaultKeyDecoder,
391
- crypto: import_plugin_crypto_noble3.crypto,
392
- base32: import_plugin_base32_scure3.base32,
393
- ...this._defaultOptions,
394
- ...this._options
395
- };
396
- return Object.freeze(merged);
397
- }
398
- /**
399
- * Generate an OTP token from a Base32 secret
400
- *
401
- * @param secret - Base32-encoded secret
402
- * @returns The OTP token
403
- */
404
- generate(secret) {
405
- const opts = this.allOptions();
406
- const secretBytes = import_plugin_base32_scure3.base32.decode(secret);
407
- const epoch = opts.epoch;
408
- const epochSeconds = epoch >= 1e12 ? Math.floor(epoch / 1e3) : epoch;
409
- return (0, import_totp2.generateSync)({
410
- secret: secretBytes,
411
- algorithm: opts.algorithm,
412
- digits: opts.digits,
413
- period: opts.step,
414
- epoch: epochSeconds,
415
- t0: 0,
416
- crypto: opts.crypto,
417
- guardrails: opts.guardrails
418
- });
419
- }
420
- /**
421
- * Check if a token is valid for the given Base32 secret
422
- *
423
- * @param token - The token to verify
424
- * @param secret - Base32-encoded secret
425
- * @returns true if valid
426
- */
427
- check(token, secret) {
428
- const delta = this.checkDelta(token, secret);
429
- return typeof delta === "number";
430
- }
431
- /**
432
- * Check token and return the time window delta
433
- *
434
- * @param token - The token to verify
435
- * @param secret - Base32-encoded secret
436
- * @returns Window delta (0 = current, positive = future, negative = past), null if invalid
437
- */
438
- checkDelta(token, secret) {
439
- const opts = this.allOptions();
440
- const secretBytes = import_plugin_base32_scure3.base32.decode(secret);
441
- const epoch = opts.epoch;
442
- const epochSeconds = epoch >= 1e12 ? Math.floor(epoch / 1e3) : epoch;
443
- const step = opts.step;
444
- const window = opts.window;
445
- let epochTolerance = 0;
446
- if (typeof window === "number") {
447
- epochTolerance = window * step;
448
- } else if (Array.isArray(window)) {
449
- epochTolerance = [window[0] * step, window[1] * step];
450
- }
451
- try {
452
- const result = (0, import_totp2.verifySync)({
453
- secret: secretBytes,
454
- token,
455
- algorithm: opts.algorithm,
456
- digits: opts.digits,
457
- period: step,
458
- epoch: epochSeconds,
459
- t0: 0,
460
- epochTolerance,
461
- crypto: opts.crypto,
462
- guardrails: opts.guardrails
463
- });
464
- if (!result.valid) {
465
- return null;
466
- }
467
- return result.delta;
468
- } catch {
469
- return null;
470
- }
471
- }
472
- /**
473
- * Verify a token (object-based API)
474
- *
475
- * @param opts - Verification options
476
- * @returns true if valid
477
- */
478
- verify(opts) {
479
- if (typeof opts !== "object") {
480
- throw new Error("Expecting argument 0 of verify to be an object");
481
- }
482
- return this.check(opts.token, opts.secret);
483
- }
484
- /**
485
- * Encode a raw secret to Base32
486
- *
487
- * @param secret - Raw secret string
488
- * @returns Base32-encoded secret
489
- */
490
- encode(secret) {
491
- const opts = this.allOptions();
492
- if (opts.keyEncoder) {
493
- return opts.keyEncoder(secret, opts.encoding);
494
- }
495
- return defaultKeyEncoder(secret, opts.encoding);
496
- }
497
- /**
498
- * Decode a Base32 secret to raw string
499
- *
500
- * @param secret - Base32-encoded secret
501
- * @returns Raw secret string
502
- */
503
- decode(secret) {
504
- const opts = this.allOptions();
505
- if (opts.keyDecoder) {
506
- return opts.keyDecoder(secret, opts.encoding);
507
- }
508
- return defaultKeyDecoder(secret, opts.encoding);
509
- }
510
- /**
511
- * Generate a random Base32-encoded secret
512
- *
513
- * @param numberOfBytes - Number of bytes for the secret (default: 20)
514
- * @returns Base32-encoded secret
515
- */
516
- generateSecret(numberOfBytes = 20) {
517
- const opts = this.allOptions();
518
- return (0, import_core2.generateSecret)({
519
- crypto: opts.crypto,
520
- base32: opts.base32,
521
- length: numberOfBytes
522
- });
523
- }
524
- };
525
-
526
- // src/index.ts
527
- var import_plugin_crypto_noble4 = require("@otplib/plugin-crypto-noble");
528
- var import_plugin_base32_scure4 = require("@otplib/plugin-base32-scure");
529
- var hotp = new HOTP();
530
- var totp = new TOTP();
531
- var authenticator = new Authenticator();
532
- // Annotate the CommonJS export names for ESM import in node:
533
- 0 && (module.exports = {
534
- Authenticator,
535
- HOTP,
536
- HashAlgorithms,
537
- KeyEncodings,
538
- NobleCryptoPlugin,
539
- ScureBase32Plugin,
540
- TOTP,
541
- authenticator,
542
- hotp,
543
- hotpDigestToToken,
544
- totp
545
- });
1
+ "use strict";var S=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var U=(o,e)=>{for(var t in e)S(o,t,{get:e[t],enumerable:!0})},z=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of G(e))!M.call(o,n)&&n!==t&&S(o,n,{get:()=>e[n],enumerable:!(r=I(e,n))||r.enumerable});return o};var V=o=>z(S({},"__esModule",{value:!0}),o);var W={};U(W,{Authenticator:()=>h,HOTP:()=>a,HashAlgorithms:()=>c,KeyEncodings:()=>i,NobleCryptoPlugin:()=>j.NobleCryptoPlugin,ScureBase32Plugin:()=>_.ScureBase32Plugin,TOTP:()=>d,authenticator:()=>L,hotp:()=>N,hotpDigestToToken:()=>A,totp:()=>F});module.exports=V(W);var p=require("@otplib/core"),O=require("@otplib/hotp"),K=require("@otplib/plugin-base32-scure"),E=require("@otplib/plugin-crypto-noble"),H=require("@otplib/uri"),P=require("@scure/base");var c={SHA1:"sha1",SHA256:"sha256",SHA512:"sha512"},i={ASCII:"ascii",HEX:"hex",BASE32:"base32",BASE64:"base64",LATIN1:"latin1",UTF8:"utf8"};function f(o,e){return e===i.BASE32||e==="base32"?K.base32.decode(o):e===i.HEX||e==="hex"?P.hex.decode(o.replace(/\s/g,"")):(0,p.stringToBytes)(o)}function A(o,e){let t=P.hex.decode(o),r=(0,p.dynamicTruncate)(t);return(0,p.truncateDigits)(r,e)}var a=class o{_options={};_defaultOptions={};constructor(e={}){this._defaultOptions={...e,guardrails:(0,p.createGuardrails)(e.guardrails)},this._options={}}get options(){return{...this._defaultOptions,...this._options}}set options(e){this._options={...e}}create(e={}){return new o(e)}allOptions(){let e={algorithm:c.SHA1,digits:6,encoding:i.ASCII,crypto:E.crypto,base32:K.base32,...this._defaultOptions,...this._options};return Object.freeze(e)}resetOptions(){return this._options={},this}generate(e,t){let r=this.allOptions(),n=f(e,r.encoding);return(0,O.generateSync)({secret:n,counter:t,algorithm:r.algorithm,digits:r.digits,crypto:r.crypto,guardrails:r.guardrails})}check(e,t,r){let n=this.allOptions(),s=f(t,n.encoding);try{return(0,O.verifySync)({secret:s,token:e,counter:r,algorithm:n.algorithm,digits:n.digits,counterTolerance:0,crypto:n.crypto,guardrails:n.guardrails}).valid}catch{return!1}}verify(e){if(typeof e!="object")throw new Error("Expecting argument 0 of verify to be an object");return this.check(e.token,e.secret,e.counter)}keyuri(e,t,r,n){let s=this.allOptions();return(0,H.generateHOTP)({label:e,issuer:t,secret:r,algorithm:s.algorithm,digits:s.digits,counter:n})}};var B=require("@otplib/plugin-base32-scure"),D=require("@otplib/plugin-crypto-noble"),u=require("@otplib/totp"),v=require("@otplib/uri");function X(o,e){return o===void 0||o===0?0:typeof o=="number"?o*e:[o[0]*e,o[1]*e]}var d=class o extends a{constructor(e={}){super(e)}create(e={}){return new o(e)}allOptions(){let e={algorithm:c.SHA1,digits:6,encoding:i.ASCII,epoch:Date.now(),step:30,window:0,crypto:D.crypto,base32:B.base32,...this._defaultOptions,...this._options};return Object.freeze(e)}generate(e){let t=this.allOptions(),r=f(e,t.encoding),n=Math.floor(t.epoch/1e3);return(0,u.generateSync)({secret:r,algorithm:t.algorithm,digits:t.digits,period:t.step,epoch:n,t0:0,crypto:t.crypto,guardrails:t.guardrails})}check(e,t){return typeof this.checkDelta(e,t)=="number"}checkDelta(e,t){let r=this.allOptions(),n=f(t,r.encoding),s=Math.floor(r.epoch/1e3),T=r.step,l=r.window,y=X(l,T);try{let g=(0,u.verifySync)({secret:n,token:e,algorithm:r.algorithm,digits:r.digits,period:T,epoch:s,t0:0,epochTolerance:y,crypto:r.crypto,guardrails:r.guardrails});return g.valid?g.delta:null}catch{return null}}verify(e){if(typeof e!="object")throw new Error("Expecting argument 0 of verify to be an object");return this.check(e.token,e.secret)}keyuri(e,t,r){let n=this.allOptions();return(0,v.generateTOTP)({label:e,issuer:t,secret:r,algorithm:n.algorithm,digits:n.digits,period:n.step})}timeUsed(){let e=this.allOptions();return Math.floor(e.epoch/1e3)%e.step}timeRemaining(){let e=this.allOptions(),t=Math.floor(e.epoch/1e3);return(0,u.getRemainingTime)(t,e.step,0)}};var w=require("@otplib/core"),m=require("@otplib/plugin-base32-scure"),C=require("@otplib/plugin-crypto-noble"),b=require("@otplib/totp");function k(o,e){let t=new TextEncoder().encode(o);return m.base32.encode(t)}function R(o,e){let t=m.base32.decode(o);return new TextDecoder().decode(t)}var h=class o extends d{constructor(e={}){super(e)}create(e={}){return new o(e)}allOptions(){let e={algorithm:c.SHA1,digits:6,encoding:i.HEX,epoch:Date.now(),step:30,window:0,keyEncoder:k,keyDecoder:R,crypto:C.crypto,base32:m.base32,...this._defaultOptions,...this._options};return Object.freeze(e)}generate(e){let t=this.allOptions(),r=m.base32.decode(e),n=t.epoch,s=n>=1e12?Math.floor(n/1e3):n;return(0,b.generateSync)({secret:r,algorithm:t.algorithm,digits:t.digits,period:t.step,epoch:s,t0:0,crypto:t.crypto,guardrails:t.guardrails})}check(e,t){return typeof this.checkDelta(e,t)=="number"}checkDelta(e,t){let r=this.allOptions(),n=m.base32.decode(t),s=r.epoch,T=s>=1e12?Math.floor(s/1e3):s,l=r.step,y=r.window,g=0;typeof y=="number"?g=y*l:Array.isArray(y)&&(g=[y[0]*l,y[1]*l]);try{let x=(0,b.verifySync)({secret:n,token:e,algorithm:r.algorithm,digits:r.digits,period:l,epoch:T,t0:0,epochTolerance:g,crypto:r.crypto,guardrails:r.guardrails});return x.valid?x.delta:null}catch{return null}}verify(e){if(typeof e!="object")throw new Error("Expecting argument 0 of verify to be an object");return this.check(e.token,e.secret)}encode(e){let t=this.allOptions();return t.keyEncoder?t.keyEncoder(e,t.encoding):k(e,t.encoding)}decode(e){let t=this.allOptions();return t.keyDecoder?t.keyDecoder(e,t.encoding):R(e,t.encoding)}generateSecret(e=20){let t=this.allOptions();return(0,w.generateSecret)({crypto:t.crypto,base32:t.base32,length:e})}};var j=require("@otplib/plugin-crypto-noble"),_=require("@otplib/plugin-base32-scure"),N=new a,F=new d,L=new h;0&&(module.exports={Authenticator,HOTP,HashAlgorithms,KeyEncodings,NobleCryptoPlugin,ScureBase32Plugin,TOTP,authenticator,hotp,hotpDigestToToken,totp});
546
2
  //# sourceMappingURL=index.cjs.map