-
-
Notifications
You must be signed in to change notification settings - Fork 133
Upgrading to v12
THIS DOC IS STILL WIP.
- 1-1 Migration (for classes)
- Management of Licenses
- Imports - change of entry points
- Class Method - Renames
- Class Method - New
- Class Method - Deprecations
- Options - epoch
- New Concepts
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';
As the package moved towards a more pluggable interface, the external dependencies are now found
within the plugin modules. i.e. thirty-two
which used to be listed in otplib
is within @otplib/plugin-thirty-two
module.
As such, for projects in environments that are license sensitive, please do note on this update.
Due to the above, as the browser module contains optimisation and have modules and may have different dependencies, it is no longer included within the otplib
by default, to maintain the dependency parity
with the previous versions.
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/core';
// 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
).