1.1.0 • Published 5 months ago

@ppg007/otp v1.1.0

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

otp

This repository implements TOTP and HOTP generation that defined in RFC6238 and RFC4226

Install

use npm:

npm install @ppg007/otp

use yarn:

yarn add @ppg007/otp

TOTP

import { totp } from '@ppg007/otp';

const genTOTP = (): string => {
  return totp({
    digits: 6,
    period: 30,
    algorithm: 'SHA-1',
    secret: 'secret key',
  });
};

HOTP

import { hotp } from '@ppg007/otp';

const genHOTP = (counter: number): string => {
  return hotp({
    digits: 6,
    counter,
    algorithm: 'SHA-1',
    secret: 'secret key',
  });
};

Options

Common Options:

OptionTypeDescribeValues
algorithmstringthe hash algorithm usage when calculate the otp'SHA-1', 'SHA-256', 'SHA-512'; default value is 'SHA-1'
digitsnumberthe otp lengthdefault value is 6, some 2FA App only support 6 length OTP
secretstringthe hash secret keymust be a base32 encoded string

TOTP Options:

OptionTypeDescribeValues
periodnumberthe TOTP valid period seconddefault value 30, some 2FA App only support 30s

HOTP Options:

OptionTypeDescribeValues
counternumberthe HOTP counter initial valuedefault value is 0
1.1.0

5 months ago

1.0.0

5 months ago