refactor: refactor of libs

This commit is contained in:
Савелий Савенок
2024-11-09 16:48:52 +03:00
parent b67cddf4eb
commit 40f6ae7f76
15 changed files with 46 additions and 176 deletions

View File

@@ -1,3 +0,0 @@
language: node_js
node_js:
- "8"

View File

@@ -1,5 +0,0 @@
# totp.js
Two-factor authentication implementation in pure javascript. One-time password generator (HOTP/TOTP) with support for Google Authenticator.
[![Build Status](https://travis-ci.org/wuyanxin/totp.js.svg?branch=master)](https://travis-ci.org/wuyanxin/totp.js)

View File

@@ -1,9 +1,2 @@
/*
* @Author: wuyanxin
* @Date: 2018-03-21 23:12:14
* @Last Modified by: wuyanxin
* @Last Modified time: 2018-03-21 23:12:14
*/
export {HOTP} from './lib/hotp.js'
export {TOTP} from './lib/totp.js'
export { HOTP } from './lib/hotp.js'
export { TOTP } from './lib/totp.js'

View File

@@ -1,11 +1,4 @@
/*
* @Author: wuyanxin
* @Date: 2018-03-21 22:25:37
* @Last Modified by: wuyanxin
* @Last Modified time: 2018-03-21 22:29:43
*/
import {encode, decode} from '../../thirty-two/index.js'
import { encode, decode } from '../../base32/index.js'
import jsSHA from 'jssha'
export class HOTP {
@@ -54,11 +47,11 @@ export class HOTP {
}
_truncat(hmac_result) {
const offset = hmac_result[19].charCodeAt() & 0xf;
const bin_code = (hmac_result[offset].charCodeAt() & 0x7f) << 24
| (hmac_result[offset+1].charCodeAt() & 0xff) << 16
| (hmac_result[offset+2].charCodeAt() & 0xff) << 8
| (hmac_result[offset+3].charCodeAt() & 0xff);
const offset = hmac_result[19].charCodeAt() & 0xf;
const bin_code = (hmac_result[offset].charCodeAt() & 0x7f) << 24
| (hmac_result[offset + 1].charCodeAt() & 0xff) << 16
| (hmac_result[offset + 2].charCodeAt() & 0xff) << 8
| (hmac_result[offset + 3].charCodeAt() & 0xff);
let otp = (bin_code % 10 ** this.digit).toString();
while (otp.length < this.digit) {
otp = '0' + otp;

View File

@@ -1,14 +1,7 @@
/*
* @Author: wuyanxin
* @Date: 2018-03-21 22:25:42
* @Last Modified by: wuyanxin
* @Last Modified time: 2018-03-21 22:42:28
*/
import {HOTP} from "./hotp.js";
import { HOTP } from "./hotp.js";
export class TOTP extends HOTP {
constructor(key){
constructor(key) {
super(key)
}
@@ -20,5 +13,4 @@ export class TOTP extends HOTP {
verify(otp, timeStep = 30, t0 = 0) {
return otp === this.genOTP(timeStep, t0);
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "totp.js",
"version": "0.0.1",
"version": "1.0.1-zepp",
"description": "Two-factor authentication implementation in pure javascript. One-time password generator (HOTP/TOTP) with support for Google Authenticator. ",
"main": "index.js",
"scripts": {
@@ -24,8 +24,7 @@
},
"homepage": "https://github.com/wuyanxin/totp.js#readme",
"dependencies": {
"jssha": "^2.3.1",
"thirty-two": "^1.0.2"
"jssha": "^2.3.1"
},
"devDependencies": {
"mocha": "^5.0.4"