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

lib-otp

v0.1.3

Published

Yep! This is an another OTP library...

Downloads

13

Readme

OTP module for nodejs

Well, as what you can expect! This is a another module providing OTP function for developers. I do it because I recently encounter a very stupid problem from other modules. And that module's latest modification date was 3~4 years ago. So I gave up and write a new one on my own. This module is "TEMPORARILY" designed for nodejs only 'cuase that's what I needed it for.

Requirement

  • NodeJS >= 6.4 ( with es6 syntax support... )

Installation

npm install lib-otp

Usage

const otp = require( 'lib-otp' );

let otpFromURI = otp( 'otpauth://totp/....' ); // Create an otp object by parsing an otpauth URI


let otpObj = otp({
	secret:'secret',		// The secret of this otp instance, either Buffer or String is accepted, used in otp generation
	label: '_label'		// The label of this otp instance, the string that is used in generating an otpauth URI
});

// Obtain TOTP
otpObj.totp(6);			// Obtain an otp code with 6 digits
otpObj.totp({			// Obtain an otp code at specific moment with 8 digits
	time:((new Date()).getTime()/1000)|0, 
	length:8
});

// Obtain HOTP
otpObj.hotp(13, 6);		// Obtain an hotp code of counter value 13 with 6 digits
otpObj.hotp({			// Alternative accepted usage
	counter:13,			// counter value, can be either Buffer or Number, other types will be casted into string and converted into buffer
	length:6
});

otpObj.totpURI();		// otpauth://totp/_label?secret=Base32EncodedSecret
otpObj.hotpURI();		// otpauth://hotp/_label?secret=Base32EncodedSecret

Note

By default, this module will handle numeric values via BN.js library. But developers can choose to use bitwise operator to cast given numeric values into normal integers.

OTP.TOTPUseBN = false;	// This value is true by default

But javascript current only natively support 32bit integers, using it will cause unexpected data loss if the given number's range is larger than 32bits.

So... use at your own risk...