diff --git a/__tests__/core/totp.test.ts b/__tests__/core/mfa.test.ts similarity index 77% rename from __tests__/core/totp.test.ts rename to __tests__/core/mfa.test.ts index e23fe48b..3aa46e20 100644 --- a/__tests__/core/totp.test.ts +++ b/__tests__/core/mfa.test.ts @@ -23,13 +23,12 @@ * */ -import { createTOTP } from '../../src/core/totp'; +import { totp } from '../../src/core/mfa'; -describe('TOTP', () => { - it('generate one time token', () => { - const totp = createTOTP({ secret: "FLIIOLP3IR3W" }); - expect(totp.generate().length).toBe(6); - expect(totp.toString()).toEqual('otpauth://totp/SyntheticsTOTP?secret=FLIIOLP3IR3Q&algorithm=SHA1&digits=6&period=30') +describe('MFA', () => { + it('generate TOTP', () => { + const token = totp("FLIIOLP3IR3W"); + expect(token.length).toBe(6); }); }); diff --git a/src/core/totp.ts b/src/core/mfa.ts similarity index 90% rename from src/core/totp.ts rename to src/core/mfa.ts index be270f84..a23f8728 100644 --- a/src/core/totp.ts +++ b/src/core/mfa.ts @@ -36,8 +36,8 @@ type TOTPOptions = { */ label?: string /** - * Include issuer prefix in label. - */ + * Include issuer prefix in label. + */ issuerInLabel?: boolean /** * The encoded secret key used to generate the TOTP. @@ -60,6 +60,6 @@ type TOTPOptions = { period?: number }; -export function createTOTP(options: TOTPOptions) { - return new TOTP({ label: "SyntheticsTOTP", ...options }); +export function totp(secret?: string, options: TOTPOptions = {}) { + return new TOTP({ label: "SyntheticsTOTP", secret, ...options }).generate(); } diff --git a/src/index.ts b/src/index.ts index 2f236f8b..2a122695 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,7 +43,7 @@ export { after, } from './core'; export { expect } from './core/expect'; -export { createTOTP } from './core/totp'; +export * as mfa from './core/mfa'; /** * Export all the driver related types to be consumed