OTPAuth
One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers.
Usage
Node.js
import * as OTPAuth from "otpauth";
let totp = new OTPAuth.TOTP({
issuer: "ACME",
label: "AzureDiamond",
algorithm: "SHA1",
digits: 6,
period: 30,
secret: "NB2W45DFOIZA",
});
let token = totp.generate();
let delta = totp.validate({ token, window: 1 });
let seconds = (totp.period * (1 - ((Date.now() / 1000 / totp.period) % 1))) | 0;
let uri = totp.toString();
totp = OTPAuth.URI.parse(uri);
Deno
import * as OTPAuth from "https://deno.land/x/otpauth@VERSION/dist/otpauth.esm.js";
Bun
import * as OTPAuth from "otpauth";
Browsers
<script src="https://cdnjs.cloudflare.com/ajax/libs/otpauth/VERSION/otpauth.umd.min.js"></script>
<script>
</script>
Documentation
See the documentation page.
https://hectorm.github.io/otpauth/
Supported hashing algorithms
In Node.js, the same algorithms as
Crypto.createHmac
function are supported, since it is used internally. In Deno, Bun and browsers, the SHA1
, SHA224
, SHA256
, SHA384
,
SHA512
, SHA3-224
, SHA3-256
, SHA3-384
and SHA3-512
algorithms are supported by using the
jsSHA library.
License
MIT License
© Héctor Molinero Fernández.