win-cliauth 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ win-cliauth --help
37
37
 
38
38
  This project uses the following open-source libraries:
39
39
 
40
- - [otplib](https://github.com/yeojz/otplib) - A JavaScript One-Time Password (OTP) library.
40
+ - [otpauth](https://github.com/hectorm/otpauth) - One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers.
41
41
  - [steam-totp](https://github.com/DoctorMcKay/node-steam-totp) - A Node.js library for generating Steam-compatible 2FA tokens.
42
42
  - [yargs](https://github.com/yargs/yargs) - A command-line argument parsing library for Node.js.
43
43
 
package/dist/src/auth.js CHANGED
@@ -6,24 +6,64 @@ All rights reserved.
6
6
  This source code is licensed under the BSD-style license found in the
7
7
  LICENSE file in the root directory of this source tree.
8
8
  */
9
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16
+ });
17
+ };
9
18
  Object.defineProperty(exports, "__esModule", { value: true });
10
19
  exports.listAuth = exports.removeAuth = exports.addAuth = exports.getAuth = void 0;
11
20
  const child_process_1 = require("child_process");
12
- const otplib_1 = require("otplib");
21
+ const otpauth_1 = require("otpauth");
13
22
  const steam_totp_1 = require("steam-totp");
14
23
  const pshell_1 = require("./pshell");
24
+ function synchronizeTime() {
25
+ var _a;
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ (_a = AbortSignal.timeout) !== null && _a !== void 0 ? _a : (AbortSignal.timeout = function timeout(ms) {
28
+ const ctrl = new AbortController();
29
+ setTimeout(() => ctrl.abort(), ms);
30
+ return ctrl.signal;
31
+ });
32
+ try {
33
+ const response = yield fetch('http://www.google.com', { signal: AbortSignal.timeout(5000) });
34
+ const responseHeaders = response.headers;
35
+ const headerDate = responseHeaders.get('date');
36
+ const serverTime = headerDate ? Date.parse(headerDate) : Date.now();
37
+ const localTime = Date.now();
38
+ const timeDifference = serverTime - localTime;
39
+ return Date.now() + timeDifference;
40
+ }
41
+ catch (error) {
42
+ return Date.now();
43
+ }
44
+ });
45
+ }
46
+ function getTOTP(key) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const auth = new otpauth_1.TOTP({ secret: key, digits: 6, period: 30 });
49
+ const timestamp = yield synchronizeTime();
50
+ return auth.generate({ timestamp });
51
+ });
52
+ }
15
53
  function getToken({ key, steam }) {
16
- return steam ? (0, steam_totp_1.generateAuthCode)(key) : otplib_1.authenticator.generate(key);
54
+ return steam ? (0, steam_totp_1.generateAuthCode)(key) : getTOTP(key).then((code) => code);
17
55
  }
18
56
  function getAuth({ objAuth, svc, clipboard, steam }) {
19
- const skey = objAuth[`${svc}`];
20
- if (skey) {
21
- const token = getToken({ key: skey, steam: steam });
22
- if (clipboard)
23
- (0, child_process_1.spawn)('clip').stdin.end(token);
24
- return console.info(token);
25
- }
26
- return console.info(`${svc} not found.`);
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const skey = objAuth[`${svc}`];
59
+ if (skey) {
60
+ const token = yield getToken({ key: skey, steam: steam });
61
+ if (clipboard)
62
+ (0, child_process_1.spawn)('clip').stdin.end(token);
63
+ return console.info(token);
64
+ }
65
+ return console.info(`${svc} not found.`);
66
+ });
27
67
  }
28
68
  exports.getAuth = getAuth;
29
69
  function addAuth({ objAuth, svc, sk, replace }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win-cliauth",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "win-cliauth is a CLI-based OTP (One-Time Password) authenticator management tool for Windows.",
5
5
  "author": "Pedro Lucas Magalhães <pedrolucasmag@gmail.com>",
6
6
  "license": "BSD-3-Clause",
@@ -19,19 +19,30 @@
19
19
  "!dist/keys"
20
20
  ],
21
21
  "devDependencies": {
22
+ "@commitlint/cli": "^17.7.1",
23
+ "@commitlint/config-conventional": "^17.7.0",
22
24
  "@types/node": "^18.11.10",
23
25
  "@types/steam-totp": "^2.1.0",
24
26
  "@types/yargs": "^17.0.10",
25
27
  "@typescript-eslint/eslint-plugin": "^5.33.1",
26
28
  "@typescript-eslint/parser": "^5.33.1",
27
29
  "eslint": "^8.22.0",
28
- "standard-version": "^9.5.0"
30
+ "husky": "^8.0.3"
29
31
  },
30
32
  "os": [
31
33
  "win32"
32
34
  ],
35
+ "keywords": [
36
+ "otp",
37
+ "authenticator",
38
+ "cli",
39
+ "windows",
40
+ "steamguard",
41
+ "2fa",
42
+ "totp"
43
+ ],
33
44
  "dependencies": {
34
- "otplib": "^12.0.1",
45
+ "otpauth": "^9.1.4",
35
46
  "steam-totp": "^2.1.2",
36
47
  "yargs": "^17.5.1"
37
48
  }