npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@otplib/core

v12.0.1

Published

core method for otplib

Downloads

2,007,771

Readme

@otplib/core

Provides core methods for hotp, totp and authenticator.

Getting Started

This is the full setup guide for installing, configuring and customising your dependencies for the library.

Check out the Quick Start Guide instead for easier setup especially if you do not need to use any custom base32 / crypto libraries.

Install the Package

npm install @otplib/core

Choose Your Plugins

Adding Crypto

The crypto modules are used to generate the digest used to derive the OTP tokens from. By default, Node.js has inbuilt crypto functionality, but you might want to replace it for certain environments that do not support it.

Currently there are a few crypto plugins available from this project. Install one of them. eg: npm install @otplib/plugin-crypto

Refer to the crypto plugins list, or search for otplib-plugin crypto on npm.

Adding Base32

If you're using Google Authenticator, you'll need a base32 module for encoding and decoding your secrets.

Currently, there are a few base32 plugins available from this project. Install one of them. eg: npm install @otplib/plugin-thirty-two

Refer to the base32 plugin list, or search for otplib-plugin base32 on npm.

Initialise your Instance

Using Classes

import { HOTP, TOTP, Authenticator } from '@otplib/core';

import { keyDecoder, keyEncoder } from '@otplib/plugin-thirty-two'; // use your chosen base32 plugin
import { createDigest, createRandomBytes } from '@otplib/plugin-crypto'; // use your chosen crypto plugin

// Setup an OTP instance which you need
const hotp = new HOTP({ createDigest });
const totp = new TOTP({ createDigest });
const authenticator = new Authenticator({
  createDigest,
  createRandomBytes,
  keyDecoder,
  keyEncoder
});

// Go forth and generate tokens
const token = hotp.generate(YOUR_SECRET, 0);
const token = totp.generate(YOUR_SECRET);
const token = authenticator.generate(YOUR_SECRET);

Using Functions

Alternatively, if you are using the functions directly instead of the classes, pass these as options into the functions.

import {
  hotpOptions,
  hotpToken,
  totpOptions,
  totpToken,
  authenticatorOptions,
  authenticatorToken
} from 'otplib/core';

// As with classes, import your desired Base32 Plugin and Crypto Plugin.
// import ...

// Go forth and generate tokens
const token = hotpToken(YOUR_SECRET, 0, hotpOptions({ createDigest }));
const token = totpToken(YOUR_SECRET, totpOptions({ createDigest }));
const token = authenticatorToken(
  YOUR_SECRET,
  authenticatorOptions({
    createDigest,
    createRandomBytes,
    keyDecoder,
    keyEncoder
  })
);

Available Options

Please refer to the Options Guide.

License

@otplib/core is MIT licensed