Skip to content

Commit

Permalink
rename API
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Sep 16, 2024
1 parent bad0642 commit ca24ebd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions __tests__/core/totp.test.ts → __tests__/core/mfa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/core/totp.ts → src/core/mfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca24ebd

Please sign in to comment.