@nest-public/totp
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

npm version

TOTP

TOTP算法JavaScript实现,可以用于Node.js、浏览器、React Native环境,支持动态密码生成、效验, 可以搭配Google Authenticator使用

更新日志

  • [2019.12.11] HMAC加密库由Node.js Cypto模块替换为JavaScript实现的HMACSHA1加密库,现在支持在任何JavaScript环境使用了。

安装

$ npm install @nest-public/totp --save

用法

import totp from '@nest-public/totp';

// 设置密钥
const testKey = 'LFLFMU2SGVCUIUCZKBMEKRKLIQ';

// 获取6位动态密码
console.log(totp.totp(testKey));
// 返回 6位数字符串 如123456

// 效验动态密码
console.log(totp.totpVerify('123456', testKey));
// 返回 {
// 	status: true; // 验证码是否准确
// 	delta: 0; // 偏移量(1单位==30秒)
// }

测试

# jest 测试
$ npm run test

Readme

Keywords

Package Sidebar

Install

npm i @nest-public/totp

Weekly Downloads

0

Version

1.1.3

License

MIT

Unpacked Size

21.1 kB

Total Files

11

Last publish

Collaborators

  • p455555555