-
-
Notifications
You must be signed in to change notification settings - Fork 133
Upgrading to v12
THIS DOC IS STILL WIP.
- 1-1 Migration
- Dependencies
- Imports - change of entry points
- Class Method - Renames
- Class Method - New
- Class Method - Deprecations
- Options - epoch
In order to ease migration, a module preset is provided for users coming from v11.x. There should be no change to the format of options which you use for v11.x.
// instead of
import { authenticator, hotp, totp } from 'otplib';
// update to
import { authenticator, hotp, totp } from 'otplib/preset-v11';
// you might need to `npm install thirty-two` as it has 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()
// to
import { HOTP } from 'otplib';
// ---------------------
totp.HOTP
totp.getClass()
// to
import { TOTP } from 'otplib';
// ---------------------
authenticator.HOTP
authenticator.getClass()
// to
import { Authenticator } from 'otplib';
// ---------------------
(authenticator|totp|hotp).optionsAll
// to
(authenticator|totp|hotp).allOptions()`
// Note: changed from getter to a function call.
(authenticator | totp | hotp).clone();
(authenticator | totp | hotp).create();
(totp | hotp).keyuri();
// Note: this was available for authenticator, but is expanded for totp and hotp.
(authenticator | totp | hotp).defaultOptions; // setter and getter
// The current (authenticator | totp | hotp).options now returns
// defaults and transient options. If you want to set the instance
// with new defaults, do use the following instead:
// (authenticator|totp|hotp).clone(...);
IMPORTANT - options.epoch is now using JavaScript epoch instead of UNIX epoch.
i.e. UNIX epoch * 1000
or Date.now()
.
- There are now
async
methods available. - All packages are classified into
core
,plugin
,preset
(andtests
).