fxa/libs/shared/otp
Dan Schomburg 35c0d738a0
task(recovery-phone): Create RecoveryPhoneService and new phone number setup method
Because:
- We want to be able to setup a new phone number

This Commit:
- Creates a recovery phone service
- Stubs out storeUnconfirmed in RecoveryPhoneManager
- Adds config for recovery phone service
- Adds tests for recovery phone service
- Adds new error type RecoveryNumberNotSupportedError
- Public exposes generateCode on OtpManager.
2024-11-14 10:03:12 -08:00
..
src
.eslintrc.json
.swcrc
README.md
jest.config.ts
package.json
project.json
tsconfig.json
tsconfig.lib.json
tsconfig.spec.json

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.