5.6.84 • Published 10 months ago

@taktikorg/numquam-rerum-enim v5.6.84

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

OTP io

Typed library to work 2fa via Google Authenticator/Time-based TOTP/Hmac-based HOTP

Test Status Downloads last commit codecov GitHub @taktikorg/numquam-rerum-enim Known Vulnerabilities Quality npm license MIT Size

Example API Reference

Why use this lib?

Install

  • npm
    npm i @taktikorg/numquam-rerum-enim
  • Yarn
    yarn add @taktikorg/numquam-rerum-enim

What is this?

  • HOTP - HMAC-based One Time Password generation method. Uses incrementing with each login counter and secret to generate unique 6-8 digit codes.
  • TOTP - Time-based, uses current time modulo period (seconds) as counter in HOTP,
  • Google Authenticator - uses simplified version of TOTP to generate codes. Differences:
    • Only SHA-1 hash support
    • Only 6 digit codes
    • Keys should not be padded
    • TOTP period is 30 seconds

Google Authenticator limits are defaults for this library.

How it works?

// 1. Import library - use totp (code changes with time)
import { totp, generateKey, getKeyUri } from "@taktikorg/numquam-rerum-enim";
// 2. Import crypto adapter. Either `crypto-node` or `crypto-web` - API is identical
import { hmac, randomBytes } from "@taktikorg/numquam-rerum-enim/crypto-node";

// 3. Get key from somewhere. Or generate it
const key = generateKey(randomBytes, /* bytes: */ 20); // 5-20 good for Google Authenticator

// 4. Get key import url
const url = getKeyUri({
  type: "totp",
  secret,
  name: "User's Username",
  issuer: "Your Site Name"
});

// 5. Show it to user as QR code - send it back to client
// Get 6-digit code back from him, as confirmation of saving secret key

const input = "...";

const code = await totp(hmac, { secret });

if (code === input) {
  // 6. Done. User configured your key
}

Api Reference

API Reference

5.6.84

10 months ago

5.6.83

10 months ago

5.6.82

10 months ago

5.6.81

10 months ago

5.6.80

10 months ago

5.6.79

10 months ago

5.6.78

10 months ago

5.6.77

10 months ago

5.6.76

11 months ago

5.6.75

11 months ago

5.6.74

11 months ago

5.6.73

11 months ago

5.6.72

11 months ago

5.6.71

11 months ago

5.5.71

11 months ago

5.5.70

11 months ago

5.5.69

11 months ago

5.5.68

11 months ago

5.5.67

11 months ago

5.5.66

11 months ago

5.5.65

11 months ago

5.5.64

11 months ago

5.5.63

11 months ago

5.5.62

11 months ago

5.4.62

11 months ago

5.4.61

11 months ago

5.4.60

11 months ago

5.4.59

11 months ago

5.4.58

11 months ago

5.4.57

11 months ago

5.4.56

11 months ago

5.4.55

11 months ago

5.4.54

11 months ago

5.4.53

11 months ago

5.4.52

11 months ago

5.4.51

11 months ago

5.4.50

11 months ago

5.4.49

11 months ago

4.4.49

12 months ago

4.4.48

12 months ago

4.4.47

12 months ago

4.4.46

12 months ago

4.4.45

12 months ago

4.4.44

12 months ago

4.4.43

12 months ago

4.4.42

12 months ago

4.4.41

12 months ago

4.4.40

12 months ago

4.4.39

12 months ago

4.4.38

12 months ago

4.4.37

12 months ago

4.4.36

12 months ago

4.4.35

12 months ago

4.4.34

12 months ago

4.4.33

12 months ago

4.4.32

12 months ago

4.4.31

12 months ago

4.4.30

12 months ago

4.4.29

1 year ago

4.4.28

1 year ago

4.3.28

1 year ago

4.3.27

1 year ago

4.3.26

1 year ago

4.3.25

1 year ago

4.3.24

1 year ago

4.3.23

1 year ago

4.2.23

1 year ago

4.2.22

1 year ago

4.2.21

1 year ago

3.2.21

1 year ago

2.2.21

1 year ago

2.1.21

1 year ago

2.1.20

1 year ago

2.1.19

1 year ago

2.1.18

1 year ago

2.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.0.15

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago