@nowarajs/totp 1.2.2 → 1.2.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/.oxfmtrc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "ignorePatterns": [],
3
+ "printWidth": 100,
4
+ "singleQuote": true,
5
+ "useTabs": true,
6
+ "tabWidth": 4,
7
+ "trailingComma": "none"
8
+ }
package/.oxlintrc.json ADDED
@@ -0,0 +1,321 @@
1
+ {
2
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
3
+ "plugins": [
4
+ "typescript"
5
+ ],
6
+ "ignorePatterns": [
7
+ "dist/",
8
+ "build/",
9
+ "coverage/",
10
+ "node_modules/"
11
+ ],
12
+ "categories": {},
13
+ "rules": {
14
+ // ————————————————————————————————————————————————————————————————————————————— //
15
+ // Correctness //
16
+ // ————————————————————————————————————————————————————————————————————————————— //
17
+ /* ———— Eslint ———— */
18
+ "constructor-super": "error",
19
+ "for-direction": "error",
20
+ "no-async-promise-executor": "error",
21
+ "no-caller": "error",
22
+ "no-class-assign": "error",
23
+ "no-compare-neg-zero": "error",
24
+ "no-cond-assign": "error",
25
+ "no-const-assign": "error",
26
+ "no-constant-binary-expression": "warn",
27
+ "no-constant-condition": "error",
28
+ "no-control-regex": "error",
29
+ "no-debugger": "error",
30
+ "no-delete-var": "off",
31
+ "no-dupe-class-members": "error",
32
+ "no-dupe-else-if": "error",
33
+ "no-dupe-keys": "error",
34
+ "no-duplicate-case": "error",
35
+ "no-empty-character-class": "error",
36
+ "no-empty-pattern": "error",
37
+ "no-empty-static-block": "error",
38
+ "no-eval": "off",
39
+ "no-ex-assign": "error",
40
+ "no-extra-boolean-cast": "error",
41
+ "no-func-assign": "error",
42
+ "no-global-assign": "error",
43
+ "no-import-assign": "error",
44
+ "no-invalid-regexp": "error",
45
+ "no-irregular-whitespace": "error",
46
+ "no-loss-of-precision": "error",
47
+ "no-new-native-nonconstructor": "error",
48
+ "no-nonoctal-decimal-escape": "error",
49
+ "no-obj-calls": "error",
50
+ "no-self-assign": "error",
51
+ "no-setter-return": "error",
52
+ "no-shadow-restricted-names": "error",
53
+ "no-sparse-arrays": "error",
54
+ "no-this-before-super": "error",
55
+ "no-unassigned-vars": "error",
56
+ "no-unsafe-finally": "error",
57
+ "no-unsafe-negation": "error",
58
+ "no-unsafe-optional-chaining": "error",
59
+ "no-unused-expressions": "error",
60
+ "no-unused-labels": "error",
61
+ "no-unused-private-class-members": "error",
62
+ "no-unused-vars": "warn",
63
+ "no-useless-backreference": "error",
64
+ "no-useless-catch": "error",
65
+ "no-useless-escape": "error",
66
+ "no-useless-rename": "error",
67
+ "no-with": "error",
68
+ "require-yield": "error",
69
+ "use-isnan": "error",
70
+ "valid-typeof": "error",
71
+
72
+ /* ———— Typescript ———— */
73
+ "typescript/await-thenable": "error",
74
+ "typescript/no-array-delete": "warn",
75
+ "typescript/no-base-to-string": "off",
76
+ "typescript/no-duplicate-enum-values": "error",
77
+ "typescript/no-duplicate-type-constituents": "error",
78
+ "typescript/no-extra-non-null-assertion": "error",
79
+ "typescript/no-floating-promises": "error",
80
+ "typescript/no-for-in-array": "error",
81
+ "typescript/no-implied-eval": "off", // not true
82
+ "typescript/no-meaningless-void-operator": "off",
83
+ "typescript/no-misused-new": "error",
84
+ "typescript/no-misused-spread": "error",
85
+ "typescript/no-non-null-asserted-optional-chain": "warn",
86
+ "typescript/no-redundant-type-constituents": "error",
87
+ "typescript/no-this-alias": "error",
88
+ "typescript/no-unnecessary-parameter-property-assignment": "error",
89
+ "typescript/no-unsafe-declaration-merging": "error",
90
+ "typescript/no-unsafe-unary-minus": "error",
91
+ "typescript/no-useless-empty-export": "error",
92
+ "typescript/no-wrapper-object-types": "error",
93
+ "typescript/prefer-as-const": "warn",
94
+ "typescript/require-array-sort-compare": "error",
95
+ "typescript/restrict-template-expressions": "warn",
96
+ "typescript/triple-slash-reference": "off",
97
+ "typescript/unbound-method": "warn",
98
+
99
+ // ————————————————————————————————————————————————————————————————————————————— //
100
+ // Performance //
101
+ // ————————————————————————————————————————————————————————————————————————————— //
102
+ /* ———— Eslint ———— */
103
+ "no-await-in-loop": "warn",
104
+ "no-useless-call": "error",
105
+
106
+ // ————————————————————————————————————————————————————————————————————————————— //
107
+ // Suspicious //
108
+ // ————————————————————————————————————————————————————————————————————————————— //
109
+ /* ———— Eslint ———— */
110
+ "block-scoped-var": "error",
111
+ "no-extend-native": "off",
112
+ "no-extra-bind": "error",
113
+ "no-new": "off",
114
+ "no-unexpected-multiline": "off",
115
+ "no-unneeded-ternary": "error",
116
+ "no-useless-concat": "error",
117
+ "no-useless-constructor": "error",
118
+ "preserve-caught-error": "off",
119
+
120
+ /* ———— Typescript ———— */
121
+ "no-confusing-non-null-assertion": "error",
122
+ "typescript/no-extraneous-class": "warn",
123
+ "typescript/no-unnecessary-boolean-literal-compare": "off",
124
+ "typescript/no-unnecessary-template-expression": "error",
125
+ "typescript/no-unnecessary-type-arguments": "error",
126
+ "typescript/no-unnecessary-type-assertion": "error",
127
+ "typescript/no-unnecessary-type-constraint": "error",
128
+ "typescript/no-unsafe-enum-comparison": "error",
129
+ "typescript/no-unsafe-type-assertion": "off",
130
+
131
+ // ————————————————————————————————————————————————————————————————————————————— //
132
+ // Pedantic //
133
+ // ————————————————————————————————————————————————————————————————————————————— //
134
+ /* ———— Eslint ———— */
135
+ "accessor-pairs": "off",
136
+ "array-callback-return": "error",
137
+ "eqeqeq": ["error", "smart"],
138
+ "max-classes-per-file": "error",
139
+ "max-depth": ["error", 4],
140
+ "max-lines": "off",
141
+ "max-lines-per-function": "off",
142
+ "max-nested-callbacks": "error",
143
+ "no-array-constructor": "error",
144
+ "no-case-declarations": "error",
145
+ "no-constructor-return": "error",
146
+ "no-else-return": "error",
147
+ "no-fallthrough": "error",
148
+ "no-inline-comments": "off",
149
+ "no-inner-declarations": "error",
150
+ "no-lonely-if": "error",
151
+ "no-loop-func": "error",
152
+ "no-negated-condition": "off",
153
+ "no-new-wrappers": "error",
154
+ "no-object-constructor": "error",
155
+ "no-promise-executor-return": "error",
156
+ "no-prototype-builtins": "error",
157
+ "no-redeclare": "error",
158
+ "no-self-compare": "error",
159
+ "no-throw-literal": "error",
160
+ "no-useless-return": "error",
161
+ "no-warning-comments": "off",
162
+ "radix": "warn",
163
+ "require-await": "error",
164
+ "sort-vars": "off",
165
+ "symbol-description": "warn",
166
+
167
+ /* ———— Typescript ———— */
168
+ "typescript/ban-ts-comment": "off",
169
+ "typescript/ban-types": "error",
170
+ "typescript/no-confusing-void-expression": "off",
171
+ "typescript/no-deprecated": "warn",
172
+ "typescript/no-misused-promises": "error",
173
+ "typescript/no-mixed-enums": "error",
174
+ "typescript/no-unsafe-argument": "error",
175
+ "typescript/no-unsafe-assignment": "error",
176
+ "typescript/no-unsafe-call": "error",
177
+ "typescript/no-unsafe-function-type": "error",
178
+ "typescript/no-unsafe-member-access": "error",
179
+ "typescript/no-unsafe-return": "error",
180
+ "typescript/only-throw-error": "error",
181
+ "typescript/prefer-enum-initializers": "error",
182
+ "typescript/prefer-includes": "off",
183
+ "typescript/prefer-nullish-coalescing": "warn",
184
+ "typescript/prefer-promise-reject-errors": "error",
185
+ "typescript/prefer-ts-expect-error": "off",
186
+ "typescript/related-getter-setter-pairs": "error",
187
+ "typescript/require-await": "error",
188
+ "typescript/strict-boolean-expressions": "off",
189
+ "typescript/switch-exhaustiveness-check": "off",
190
+
191
+ // ————————————————————————————————————————————————————————————————————————————— //
192
+ // Style //
193
+ // ————————————————————————————————————————————————————————————————————————————— //
194
+ /* ———— Eslint ———— */
195
+ "arrow-body-style": ["error", "as-needed"],
196
+ "capitalized-comments": "off",
197
+ "curly": ["error", "multi"],
198
+ "default-case-last": "error",
199
+ "default-param-last": "error",
200
+ "func-names": "off",
201
+ "func-style": ["error", "expression"],
202
+ "grouped-accessor-pairs": ["warn", "getBeforeSet"],
203
+ "guard-for-in": "off",
204
+ "id-length": "off",
205
+ "init-declarations": "off",
206
+ "max-params": ["error", 6],
207
+ "max-statements": "off",
208
+ "new-cap": "error",
209
+ "no-continue": "off",
210
+ "no-duplicate-imports": "error",
211
+ "no-extra-label": "error",
212
+ "no-implicit-coercion": "warn",
213
+ "no-label-var": "error",
214
+ "no-labels": "off",
215
+ "no-lone-blocks": "error",
216
+ "no-magic-numbers": "off",
217
+ "no-multi-assign": "off",
218
+ "no-multi-str": "off",
219
+ "no-nested-ternary": "off",
220
+ "no-new-func": "off",
221
+ "no-return-assign": "off",
222
+ "no-script-url": "off",
223
+ "no-template-curly-in-string": "error",
224
+ "no-ternary": "off",
225
+ "no-useless-computed-key": "error",
226
+ "operator-assignment": "warn",
227
+ "prefer-destructuring": "error",
228
+ "prefer-exponentiation-operator": "error",
229
+ "prefer-numeric-literals": "off",
230
+ "prefer-object-has-own": "error",
231
+ "prefer-object-spread": "error",
232
+ "prefer-promise-reject-errors": "error",
233
+ "prefer-rest-params": "error",
234
+ "prefer-spread": "error",
235
+ "prefer-template": "off",
236
+ "sort-imports": "off",
237
+ "sort-keys": "off",
238
+ "var-on-top": "off",
239
+ "yoda": "off",
240
+
241
+ /* ———— Typescript ———— */
242
+ "typescript/adjacent-overload-signatures": "error",
243
+ "typescript/array-type": "off",
244
+ "typescript/ban-tslint-comment": "off",
245
+ "typescript/consistent-generic-constructors": "error",
246
+ "typescript/consistent-indexed-object-style": "warn",
247
+ "typescript/consistent-type-definitions": "error",
248
+ "typescript/consistent-type-imports": "error",
249
+ "typescript/no-empty-interface": "error",
250
+ "typescript/no-inferrable-types": "error",
251
+ "typescript/prefer-for-of": "off",
252
+ "typescript/prefer-function-type": "error",
253
+ "prefer-namespace-keyword": "off",
254
+ "typescript/prefer-reduce-type-parameter": "warn",
255
+ "typescript/prefer-return-this-type": "off",
256
+
257
+ // ————————————————————————————————————————————————————————————————————————————— //
258
+ // Restriction //
259
+ // ————————————————————————————————————————————————————————————————————————————— //
260
+ /* ———— Eslint ———— */
261
+ "class-methods-use-this": "off",
262
+ "complexity": ["error", { "max": 25 }],
263
+ "default-case": "error",
264
+ "no-alert": "warn",
265
+ "no-bitwise": "off",
266
+ "no-console": "off",
267
+ "no-div-regex": "off",
268
+ "no-empty": "warn",
269
+ "no-empty-function": "warn",
270
+ "no-eq-null": "off",
271
+ "no-iterator": "off",
272
+ "no-param-reassign": "off",
273
+ "no-plusplus": "off",
274
+ "no-proto": "error",
275
+ "no-regex-spaces": "error",
276
+ "no-restricted-globals": "off",
277
+ "no-restricted-imports": "off",
278
+ "no-sequences": "off",
279
+ "no-undefined": "off",
280
+ "no-var": "error",
281
+ "no-void": "off",
282
+ "unicode-bom": "off",
283
+
284
+ /* ———— Typescript ———— */
285
+ "typescript/explicit-function-return-type": "warn",
286
+ "typescript/explicit-module-boundary-types": "error",
287
+ "typescript/no-dynamic-delete": "off",
288
+ "typescript/no-empty-object-type": "off",
289
+ "typescript/no-explicit-any": "error",
290
+ "typescript/no-import-type-side-effects": "error",
291
+ "typescript/no-namespace": "off",
292
+ "typescript/no-non-null-asserted-nullish-coalescing": "error",
293
+ "typescript/no-non-null-assertion": "error",
294
+ "typescript/no-require-imports": "error",
295
+ "typescript/no-restricted-types": "off",
296
+ "typescript/no-var-requires": "error",
297
+ "typescript/non-nullable-type-assertion-style": "off",
298
+ "typescript/prefer-literal-enum-member": "error",
299
+ "typescript/promise-function-async": "off",
300
+ "typescript/use-unknown-in-catch-callback-variable": "error",
301
+
302
+ // ————————————————————————————————————————————————————————————————————————————— //
303
+ // Nursery //
304
+ // ————————————————————————————————————————————————————————————————————————————— //
305
+ /* ———— Eslint ———— */
306
+ "getter-return": "off",
307
+ "no-misleading-character-class": "error",
308
+ "no-undef": "off",
309
+ "no-unreachable": "error",
310
+
311
+ /* ———— Typescript ———— */
312
+ "typescript/prefer-optional-chain": "warn"
313
+ },
314
+ "settings": {},
315
+ "env": {
316
+ "builtin": true,
317
+ "browser": true,
318
+ "node": true
319
+ },
320
+ "globals": {}
321
+ }
package/dist/index.js CHANGED
@@ -28,17 +28,15 @@ var _getCryptoKey = async (secret, algorithm) => {
28
28
  if (firstKey)
29
29
  _keyCache.delete(firstKey);
30
30
  }
31
- const key = await webcrypto.subtle.importKey("raw", secret, { name: "HMAC", hash: algorithm }, false, ["sign"]);
31
+ const keyData = new Uint8Array(secret);
32
+ const key = await webcrypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: algorithm }, false, ["sign"]);
32
33
  _keyCache.set(cacheKey, key);
33
34
  return key;
34
35
  };
35
36
  var clearKeyCache = () => {
36
37
  _keyCache.clear();
37
38
  };
38
- var hotp = async (secret, counter, {
39
- algorithm = "SHA-1",
40
- digits = 6
41
- } = {}) => {
39
+ var hotp = async (secret, counter, { algorithm = "SHA-1", digits = 6 } = {}) => {
42
40
  if (secret.length < 16)
43
41
  throw new InternalError(TOTP_ERROR_KEYS.WEAK_SECRET, "Secret must be at least 16 bytes (128 bits)");
44
42
  const counterBuffer = createCounterBuffer(counter);
@@ -83,15 +81,15 @@ var parseOtpAuthUri = (uri) => {
83
81
  throw new InternalError2(TOTP_ERROR_KEYS.MISSING_SECRET, "Secret is required");
84
82
  const issuerParam = url.searchParams.get("issuer");
85
83
  const issuer = issuerParam ? decodeURIComponent(issuerParam) : undefined;
86
- const algorithmParam = url.searchParams.get("algorithm") || "SHA-1";
84
+ const algorithmParam = url.searchParams.get("algorithm") ?? "SHA-1";
87
85
  if (algorithmParam !== "SHA-1" && algorithmParam !== "SHA-256" && algorithmParam !== "SHA-512")
88
86
  throw new InternalError2(TOTP_ERROR_KEYS.INVALID_ALGORITHM, "Algorithm must be SHA-1, SHA-256, or SHA-512");
89
87
  const algorithm = algorithmParam;
90
- const digitsParam = parseInt(url.searchParams.get("digits") || "6", 10);
88
+ const digitsParam = parseInt(url.searchParams.get("digits") ?? "6", 10);
91
89
  if (digitsParam !== 6 && digitsParam !== 8)
92
90
  throw new InternalError2(TOTP_ERROR_KEYS.INVALID_DIGITS, "Digits must be 6 or 8");
93
91
  const digits = digitsParam;
94
- const period = parseInt(url.searchParams.get("period") || "30", 10);
92
+ const period = parseInt(url.searchParams.get("period") ?? "30", 10);
95
93
  if (!Number.isFinite(period) || period <= 0)
96
94
  throw new InternalError2(TOTP_ERROR_KEYS.INVALID_PERIOD, "Period must be a positive integer");
97
95
  const result = {
@@ -107,7 +105,7 @@ var parseOtpAuthUri = (uri) => {
107
105
  // source/totp.ts
108
106
  import { timingSafeEqual } from "crypto";
109
107
  import { InternalError as InternalError3 } from "@nowarajs/error";
110
- var totp = async (secret, {
108
+ var totp = (secret, {
111
109
  algorithm = "SHA-1",
112
110
  digits = 6,
113
111
  period = 30,
package/package.json CHANGED
@@ -1,44 +1,49 @@
1
1
  {
2
2
  "name": "@nowarajs/totp",
3
- "version": "1.2.2",
4
- "author": "NowaraJS",
3
+ "version": "1.2.3",
5
4
  "description": "A comprehensive Time-based One-Time Password (TOTP) and HMAC-based One-Time Password (HOTP)",
6
- "type": "module",
7
- "license": "MIT",
8
5
  "keywords": [
9
6
  "bun",
7
+ "hotp",
10
8
  "nowarajs",
11
- "totp",
12
- "hotp"
9
+ "totp"
13
10
  ],
11
+ "license": "MIT",
12
+ "author": "NowaraJS",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/NowaraJS/totp.git"
16
+ },
17
+ "type": "module",
18
+ "exports": {
19
+ "./enums": "./dist/enums/index.js",
20
+ "./types": "./dist/types/index.js",
21
+ "./utils": "./dist/utils/index.js",
22
+ ".": "./dist/index.js"
23
+ },
14
24
  "scripts": {
15
25
  "build": "bun builder.ts",
16
26
  "dev": "bun --watch sandbox/index.ts",
17
27
  "docs": "bunx typedoc --tsconfig tsconfig.build.json",
18
- "fix-lint": "eslint --fix ./source",
19
- "lint": "eslint ./source",
28
+ "fmt:check": "oxfmt --check",
29
+ "fmt": "oxfmt",
30
+ "lint:fix": "oxlint --type-aware --type-check --fix ./source",
31
+ "lint:github": "oxlint --type-aware --type-check --format=github ./source",
32
+ "lint": "oxlint --type-aware --type-check ./source",
20
33
  "test:integration": "bun test $(find test/integration -name '*.spec.ts')",
21
34
  "test:unit": "bun test --coverage $(find test/unit -name '*.spec.ts')",
22
35
  "test": "bun test --coverage"
23
36
  },
24
37
  "devDependencies": {
25
- "@eslint/js": "^9.39.2",
26
- "@nowarajs/error": "^1.4.0",
27
- "@stylistic/eslint-plugin": "^5.7.0",
28
- "@types/bun": "^1.3.5",
29
- "eslint": "^9.39.2",
30
- "globals": "^17.0.0",
31
- "typescript-eslint": "^8.52.0",
38
+ "@nowarajs/error": "^1.4.1",
39
+ "@types/bun": "^1.3.7",
40
+ "oxfmt": "^0.27.0",
41
+ "oxlint": "^1.42.0",
42
+ "oxlint-tsgolint": "^0.11.3",
32
43
  "typescript": "^5.9.3"
33
44
  },
34
45
  "peerDependencies": {
35
- "@nowarajs/error": "^1.4.0"
36
- },
37
- "exports": {
38
- "./enums": "./dist/enums/index.js",
39
- "./types": "./dist/types/index.js",
40
- "./utils": "./dist/utils/index.js",
41
- ".": "./dist/index.js"
46
+ "@nowarajs/error": "^1.4.1"
42
47
  },
43
48
  "changelog": {
44
49
  "types": {
@@ -96,9 +101,5 @@
96
101
  "tagMessage": "v{{newVersion}}",
97
102
  "tagBody": "v{{newVersion}}"
98
103
  }
99
- },
100
- "repository": {
101
- "type": "git",
102
- "url": "https://github.com/NowaraJS/totp.git"
103
104
  }
104
105
  }