fxa/libs/shared/otp
Reino Muhl f47d120d71
feat(libs): convert libs/* to esbuild and swc/jest
Because:

- ts-jest is consuming too much memory during unit test execution

This commit:

- Replace ts-jest with @swc/jest, which has better memory utilization
- Replace Nx TSC build executor with Nx esbuild build executor, for better performance.
- Reduce size of unit-test job instance size from large back to medium+

Closes #FXA-9879
2024-06-27 15:28:55 -04:00
..
src chore: refactor password.js to password.ts and async 2024-04-25 10:46:23 -07:00
.eslintrc.json feat(password): send OTP to start password reset flow 2024-04-24 12:11:14 -05:00
.swcrc feat(libs): convert libs/* to esbuild and swc/jest 2024-06-27 15:28:55 -04:00
README.md feat(password): send OTP to start password reset flow 2024-04-24 12:11:14 -05:00
jest.config.ts feat(libs): convert libs/* to esbuild and swc/jest 2024-06-27 15:28:55 -04:00
package.json feat(password): send OTP to start password reset flow 2024-04-24 12:11:14 -05:00
project.json feat(libs): convert libs/* to esbuild and swc/jest 2024-06-27 15:28:55 -04:00
tsconfig.json feat(password): send OTP to start password reset flow 2024-04-24 12:11:14 -05:00
tsconfig.lib.json feat(password): send OTP to start password reset flow 2024-04-24 12:11:14 -05:00
tsconfig.spec.json feat(password): send OTP to start password reset flow 2024-04-24 12:11:14 -05:00

README.md

otp

A lib for stored OTPs. These are not HOTPs or TOTPs. They are generated with nodejs's crypto.randomInt. The API accepts an object with three storage handling functions, but you could just as well squint and view them as general callbacks.

Building

Run nx build otp to build the library.

Using

const storageAdapter = {
  set: async (key, value) => await store.upsert(key, value, config.ttl),
  get: async (key) => await store.get(key),
  del: async (key) => await store.del(key),
};

const otpManager = new OtpManager(
  { kind: 'example', digits: 8 },
  storageAdapter
);

const code = otpManager.create('acct_id_1912');
const isCodeValid = otpManager.isValid('acct_id_1912', '577311');
otpManager.delete('acct_id_1912');

Running unit tests

Run nx test-unit otp to execute the unit tests via Jest.