-
-
Notifications
You must be signed in to change notification settings - Fork 133
Upgrading to v12
v12.x is a huge rewrite in terms of architecture and language.
In order to ease migration, a module preset is provided for users coming from v11.x.
// instead of
import { authenticator, hotp, totp } from 'otplib';
// update to
import { authenticator, hotp, totp } from 'otplib/preset-v11';
// you might need to do a `npm install thirty-two` as it is now moved to devDependencies.
As the package moved towards a more pluggable interface, they are now listed under devDependencies. As such, you would need to install the corresponding npm
modules for the plugins. These are listed in the README.md.
# Past
npm install otplib
# Now
npm install otplib thirty-two
Removing it from the dependency was to align with the goal of having the library agnostic to base32 and crypto frameworks.
Previous versions of otplib exposed the initialised classes as an entry point, while you can get the classes via the prototype.
// v11.x imports
import { authenticator, hotp, totp } from 'otplib';
// v11.x get classes
const HOTP = hotp.HOTP; // or hotp.getClass();
const TOTP = totp.TOTP; // or totp.getClass();
const Authenticator = authenticator.Authenticator; // or authenticator.getClass();
In v12
, that has been deprecated in favour of a more explicit imports.
Main imports are now the classes, while initialised versions are delegated to presets. This allows the module to have more flexibility in configuration.
// Classes are now the default export
import { HOTP, TOTP, Authenticator } from 'otplib';
// initialised versions are in preset-*
import { authenticator, hotp, totp } from 'otplib/preset-default';
hotp.HOTP / hotp.getClass() -> import { HOTP } from 'otplib';
hotp.HOTP / hotp.getClass() -> import { HOTP } from 'otplib';