Catalog npm
Back to packageRELEASE DETAILS

0.1.0

npm

2fa

TOTP + HOTP library, with nice utilities for handing 2FA

2faauthtwo-factor
Published5 Mar 2015
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

2FA

Module for generating and verifying 2FA codes (specifically TOTP and HOTP).

Also contains utilities for handing 2FA logic, such as generating Google Authenticator compatible QR codes (without going via Google Charts) and generating backup codes.

Install

npm install --save 2fa

Usage

var tfa = require('2fa');

// lets generate a new key for a user
// tfa.generateKey(length (optional), cb)
tfa.generateKey(32, function(err, key) {
  // crypto secure hex key with 32 characters

  // generate crypto-secure backups codes in a user-friendly pattern
  // tfa.generateBackupCodes(num, pattern (optional), cb)
  tfa.generateBackupCodes(8, 'xxxx-xxxx-xxxx', function(err, codes) {
    // [ '7818-b7b8-c928', '3526-dc04-d3f2', 'be3c-5d9f-cb68', ... ]

    // these should be sent to the user, stored and checked when we get a 2fa code
  });

  // generate a google QR code so the user can save their new key
  // tfa.generateGoogleQR(name, accountname, secretkey, cb)
  tfa.generateGoogleQR('Company', 'email@gmail.com', key, function(err, qr) {
    // data URL png image for google authenticator
  });

  var opts = {
    // the number of counters to check before what we're given
    // default: 0
    beforeDrift: 2,
    // and the number to check after
    // default: 0
    afterDrift: 2,
    // if before and after drift aren't specified,
    // before + after drift are set to drift / 2
    // default: 0
    drift: 4,
    // the step for the TOTP counter in seconds
    // default: 30
    step: 30
  };

  // calculate the counter for the HOTP (pretending it's actually TOTP)
  var counter = Math.floor(Date.now() / 1000 / opts.step);

  // generate a valid code (in real-life this will be user-input)
  var code = tfa.generateCode(key, counter);

  // verify it as a HOTP
  var validHOTP = tfa.verifyHOTP(key, code, counter, opts);
  // true

  // for TOTP, the counter is calculated internally using Date.now();
  var validTOTP = tfa.verifyTOTP(key, code, opts);
  // true

});

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
qr-image
Environment
{
  "local_name": "qr-image",
  "alias": false,
  "peer_metadata": null
}
^3.1.0runtime
thirty-two
Environment
{
  "local_name": "thirty-two",
  "alias": false,
  "peer_metadata": null
}
0.0.2runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "bf5757655c1560a8a2207f64c9b3d6c43618c110",
  "tarball": "https://registry.npmjs.org/2fa/-/2fa-0.1.0.tgz",
  "integrity": "sha512-kHBmFqB4/x78V3xakmVWOEWPE9YW6WahStFdZzjqCKviVxaypl0r/8rcmWfxNVoJYdcqkgSdYyPYsIqb/w1eDw==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQDSyqd8xEZ1eHERovE56SzIoFJqOYJVGR+fkcYdwXnsqwIgTtLzwnPEMWBmtce+qvbk5NoSd3ZpQJm5AQTNIfB8Y/4="
    }
  ]
}

Repository

PENDING
simontabor/2fa

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:12 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:e7bc6482e05ed25527b7e0a0b751fc27aa80bd63b0e4b504337dd9ef57f9ec33

Other collected versions

0.1.221 Apr0.1.113 Mar0.0.121 SeptView all collected versions →