• Stars
    star
    578
  • Rank 77,250 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers.

Last version npm downloads

OTPAuth

One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers.

Usage

Node.js

import * as OTPAuth from "otpauth";

// Create a new TOTP object.
let totp = new OTPAuth.TOTP({
  issuer: "ACME",
  label: "AzureDiamond",
  algorithm: "SHA1",
  digits: 6,
  period: 30,
  secret: "NB2W45DFOIZA", // or 'OTPAuth.Secret.fromBase32("NB2W45DFOIZA")'
});

// Generate a token (returns the current token as a string).
let token = totp.generate();

// Validate a token (returns the token delta or null if it is not found in the search window, in which case it should be considered invalid).
let delta = totp.validate({ token, window: 1 });

// Convert to Google Authenticator key URI:
// otpauth://totp/ACME:AzureDiamond?issuer=ACME&secret=NB2W45DFOIZA&algorithm=SHA1&digits=6&period=30
let uri = totp.toString(); // or 'OTPAuth.URI.stringify(totp)'

// Convert from Google Authenticator key URI.
totp = OTPAuth.URI.parse(uri);

Deno

import * as OTPAuth from "https://deno.land/x/otpauth@VERSION/dist/otpauth.esm.js"

// Same as above.

Bun

import * as OTPAuth from "otpauth";

// Same as above.

Browsers

<script src="https://cdnjs.cloudflare.com/ajax/libs/otpauth/VERSION/otpauth.umd.min.js"></script>
<script>
  // Same as above.
</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.

More Repositories

1

hblock

Improve your security and privacy by blocking ads, tracking and malware domains.
Shell
1,366
star
2

docker-qemu-win2000

A Docker image for Windows 2000 Advanced Server with SP4.
Makefile
861
star
3

elementary-dropbox

Installs Dropbox and integrates it with WingPanel (for Elementary OS).
Shell
448
star
4

hmirror

Mirror of multiple third-party blocklists (updated daily).
Shell
139
star
5

docker-qemu-reactos

A Docker image for the ReactOS operating system.
M4
59
star
6

wireguard-setup

WireGuard and Unbound setup with Packer and Terraform.
HCL
56
star
7

docker-xubuntu

A Docker image with the Xfce desktop environment, VirtualGL, XRDP and XRDP PulseAudio module.
M4
53
star
8

docker-pwnagotchi

Pwnagotchi on Docker.
Shell
30
star
9

hblock-resolver

A Docker image of Knot DNS Resolver with hBlock.
M4
22
star
10

docker-qemu-haiku

A Docker image for the Haiku operating system.
Shell
19
star
11

demergi

A proxy server that helps to bypass the DPI systems implemented by various ISPs.
JavaScript
19
star
12

docker-goaccess

A Docker image for GoAccess.
Makefile
19
star
13

cetusguard

CetusGuard is a tool that protects the Docker daemon socket by filtering calls to its API endpoints.
Go
17
star
14

pzntg

Indexed color PNG image generator.
JavaScript
12
star
15

fast-cli

Test your latency, download speed and upload speed using fast.com.
Shell
12
star
16

docker-caddy

A Docker image for Caddy.
Makefile
11
star
17

docker-musikcube

A Docker image for musikcube.
Makefile
9
star
18

docker-wine

A Docker image for Wine based on Xubuntu on Docker.
Makefile
8
star
19

docker-winamp

A Docker image for the legendary Winamp 2.95 media player.
Shell
8
star
20

docker-volume-helpers

Backup, restore and explore Docker volumes.
Makefile
6
star
21

docker-compose-helpers

Shell
6
star
22

docker-qemu-user-static

A Docker image with the QEMU user mode emulation static binaries.
Makefile
5
star
23

alexa-top-1m

JavaScript
5
star
24

music-dl

Shell
5
star
25

cloudflare-ddns

Cloudflare Dynamic DNS.
Makefile
5
star
26

docker-dropbear

A Docker image with a Dropbear SSH server compatible with SFTP, SCP and rsync.
Makefile
4
star
27

docker-sftp

A Docker image with an OpenSSH server configured for SFTP and rsync.
Makefile
4
star
28

docker-pinball

Shell
4
star
29

docker-steam

A Docker image for Steam based on Xubuntu on Docker.
Makefile
4
star
30

docker-supercronic

A Docker image for Supercronic.
Makefile
3
star
31

docker-dnsperf

A Docker image for dnsperf, resperf and flamethrower.
Makefile
3
star
32

docker-oilshell

A Docker image for Oil shell.
Makefile
3
star
33

rock960-c-build

ROCK960 Model C build scripts
Shell
3
star
34

docker-wasm

A Docker image with the latest version of Emscripten and basic development tools.
Dockerfile
3
star
35

hectorm.github.io

Vue
2
star
36

logo

Shell
2
star
37

docker-curl

A statically linked build of cURL in a Docker container.
Makefile
2
star
38

docker-volumex

Extra functionalities to manage volumes.
Shell
2
star
39

hectorm

2
star
40

docker-watchtower

A Docker image for Watchtower.
Makefile
2
star
41

docker-udptunnel

A statically linked build of udptunnel in a Docker container.
Makefile
2
star
42

liquid-rescale

Shell
2
star
43

docker-389ds

A Docker image for 389 Directory Server.
Shell
2
star
44

NotoColorEmoji-Extractor

Shell
1
star
45

.github

GitHub config
1
star
46

docker-scratch

Empty Docker images with different architectures defined in its manifest.
Dockerfile
1
star
47

docker-bulk

Perform bulk actions on Docker resources.
Shell
1
star
48

docker-imapsync

A Docker image for Imapsync.
Makefile
1
star
49

docker-lego

A Docker image for lego.
Makefile
1
star
50

nuxt-starter

Project template with Nuxt 3 + tRPC + Lucia Auth.
TypeScript
1
star