@1auth/authn-recovery-codes 0.0.0-beta.1 → 0.0.0-beta.2

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.
Files changed (3) hide show
  1. package/README.md +44 -0
  2. package/index.js +5 -9
  3. package/package.json +15 -12
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ <div align="center">
2
+ <h1>@1auth/authn-recovery-codes</h1>
3
+ <!--<img alt="1auth logo" src="https://raw.githubusercontent.com/willfarrell/1auth/main/docs/img/logo.svg"/>-->
4
+ <p><strong>One-time recovery code generation and verification for account recovery</strong></p>
5
+ <p>
6
+ <a href="https://github.com/willfarrell/1auth/actions/workflows/test-unit.yml"><img src="https://github.com/willfarrell/1auth/actions/workflows/test-unit.yml/badge.svg" alt="GitHub Actions unit test status"></a>
7
+ <a href="https://github.com/willfarrell/1auth/actions/workflows/test-dast.yml"><img src="https://github.com/willfarrell/1auth/actions/workflows/test-dast.yml/badge.svg" alt="GitHub Actions dast test status"></a>
8
+ <a href="https://github.com/willfarrell/1auth/actions/workflows/test-perf.yml"><img src="https://github.com/willfarrell/1auth/actions/workflows/test-perf.yml/badge.svg" alt="GitHub Actions perf test status"></a>
9
+ <a href="https://github.com/willfarrell/1auth/actions/workflows/test-sast.yml"><img src="https://github.com/willfarrell/1auth/actions/workflows/test-sast.yml/badge.svg" alt="GitHub Actions SAST test status"></a>
10
+ <a href="https://github.com/willfarrell/1auth/actions/workflows/test-lint.yml"><img src="https://github.com/willfarrell/1auth/actions/workflows/test-lint.yml/badge.svg" alt="GitHub Actions lint test status"></a>
11
+ <br/>
12
+ <a href="https://www.npmjs.com/package/@1auth/authn-recovery-codes"><img alt="npm version" src="https://img.shields.io/npm/v/@1auth/authn-recovery-codes.svg"></a>
13
+ <a href="https://packagephobia.com/result?p=@1auth/authn-recovery-codes"><img src="https://packagephobia.com/badge?p=@1auth/authn-recovery-codes" alt="npm install size"></a>
14
+ <a href="https://www.npmjs.com/package/@1auth/authn-recovery-codes">
15
+ <img alt="npm weekly downloads" src="https://img.shields.io/npm/dw/@1auth/authn-recovery-codes.svg"></a>
16
+ <a href="https://www.npmjs.com/package/@1auth/authn-recovery-codes#provenance">
17
+ <img alt="npm provenance" src="https://img.shields.io/badge/provenance-Yes-brightgreen"></a>
18
+ <br/>
19
+ <a href="https://scorecard.dev/viewer/?uri=github.com/willfarrell/1auth"><img src="https://api.scorecard.dev/projects/github.com/willfarrell/1auth/badge" alt="Open Source Security Foundation (OpenSSF) Scorecard"></a>
20
+ <a href="https://slsa.dev"><img src="https://slsa.dev/images/gh-badge-level3.svg" alt="SLSA 3"></a>
21
+ <a href="https://github.com/willfarrell/1auth/blob/main/docs/CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg"></a>
22
+ <a href="https://biomejs.dev"><img alt="Checked with Biome" src="https://img.shields.io/badge/Checked_with-Biome-60a5fa?style=flat&logo=biome"></a>
23
+ <a href="https://conventionalcommits.org"><img alt="Conventional Commits" src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white"></a>
24
+ </p>
25
+ <p>You can read the documentation at: <a href="https://1auth.js.org">https://1auth.js.org</a></p>
26
+ </div>
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ npm install @1auth/authn-recovery-codes
32
+ ```
33
+
34
+ ## Documentation and examples
35
+
36
+ For documentation and examples, refer to the main [1auth monorepo on GitHub](https://github.com/willfarrell/1auth) or the [1auth website](https://1auth.js.org).
37
+
38
+ ## Contributing
39
+
40
+ Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/willfarrell/1auth/issues) or to [submit Pull Requests](https://github.com/willfarrell/1auth/pulls).
41
+
42
+ ## License
43
+
44
+ Licensed under [MIT License](LICENSE). Copyright (c) 2020-2026 [will Farrell](https://github.com/willfarrell) and [contributors](https://github.com/willfarrell/1auth/graphs/contributors).
package/index.js CHANGED
@@ -3,10 +3,8 @@
3
3
  import {
4
4
  authenticate as authnAuthenticate,
5
5
  count as authnCount,
6
- // create as authnCreate,
7
6
  createList as authnCreateList,
8
7
  getOptions as authnGetOptions,
9
- //select as authnSelect,
10
8
  list as authnList,
11
9
  remove as authnRemove,
12
10
  removeList as authnRemoveList,
@@ -14,6 +12,7 @@ import {
14
12
  import {
15
13
  createSecretHash,
16
14
  makeRandomConfigObject,
15
+ nowInSeconds,
17
16
  verifySecretHash,
18
17
  } from "@1auth/crypto";
19
18
 
@@ -55,13 +54,12 @@ export const authenticate = async (username, secret) => {
55
54
  };
56
55
 
57
56
  export const count = async (sub) => {
57
+ if (!sub || typeof sub !== "string") {
58
+ throw new Error("401 Unauthorized", { cause: { sub } });
59
+ }
58
60
  return await authnCount(options.secret, sub);
59
61
  };
60
62
 
61
- // export const select = async (sub, id) => {
62
- // return await authnSelect(options.secret, sub, id);
63
- // };
64
-
65
63
  export const list = async (sub) => {
66
64
  return await authnList(options.secret, sub);
67
65
  };
@@ -99,7 +97,7 @@ export const remove = async (sub, id) => {
99
97
  const ids = await options.store
100
98
  .selectList(options.table, {
101
99
  sub,
102
- type: `${options.id}-${options.secret.type}`,
100
+ type: `${options.secret.id}-${options.secret.type}`,
103
101
  })
104
102
  .then((res) => res.map((item) => item.id));
105
103
  await authnRemoveList(options.secret, sub, ids);
@@ -121,5 +119,3 @@ const createSecrets = async (sub, count = options.count) => {
121
119
  await authnCreateList(options.secret, sub, secrets);
122
120
  return secrets;
123
121
  };
124
-
125
- const nowInSeconds = () => Math.floor(Date.now() / 1000);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1auth/authn-recovery-codes",
3
- "version": "0.0.0-beta.1",
4
- "description": "",
3
+ "version": "0.0.0-beta.2",
4
+ "description": "One-time recovery code generation and verification for account recovery",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=24"
@@ -12,18 +12,14 @@
12
12
  },
13
13
  "main": "./index.js",
14
14
  "module": "./index.js",
15
+ "sideEffects": false,
15
16
  "exports": {
16
17
  ".": {
17
- "import": {
18
- "types": "./index.d.ts",
19
- "default": "./index.js"
20
- }
18
+ "import": "./index.js"
21
19
  }
22
20
  },
23
- "types": "index.d.ts",
24
21
  "files": [
25
- "index.js",
26
- "index.d.ts"
22
+ "index.js"
27
23
  ],
28
24
  "scripts": {
29
25
  "test": "npm run test:unit",
@@ -34,7 +30,14 @@
34
30
  "type": "github",
35
31
  "url": "https://github.com/sponsors/willfarrell"
36
32
  },
37
- "keywords": [],
33
+ "keywords": [
34
+ "1auth",
35
+ "OWASP",
36
+ "ASVS",
37
+ "authentication",
38
+ "recovery-codes",
39
+ "2FA"
40
+ ],
38
41
  "author": {
39
42
  "name": "1auth contributors",
40
43
  "url": "https://github.com/willfarrell/1auth/graphs/contributors"
@@ -50,7 +53,7 @@
50
53
  "homepage": "https://github.com/willfarrell/1auth",
51
54
  "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
52
55
  "dependencies": {
53
- "@1auth/authn": "0.0.0-beta.1",
54
- "@1auth/crypto": "0.0.0-beta.1"
56
+ "@1auth/authn": "0.0.0-beta.2",
57
+ "@1auth/crypto": "0.0.0-beta.2"
55
58
  }
56
59
  }