@1auth/account 0.0.0-beta.0 → 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.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ <div align="center">
2
+ <h1>@1auth/account</h1>
3
+ <!--<img alt="1auth logo" src="https://raw.githubusercontent.com/willfarrell/1auth/main/docs/img/logo.svg"/>-->
4
+ <p><strong>User account management with encrypted storage and lifecycle operations</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/account"><img alt="npm version" src="https://img.shields.io/npm/v/@1auth/account.svg"></a>
13
+ <a href="https://packagephobia.com/result?p=@1auth/account"><img src="https://packagephobia.com/badge?p=@1auth/account" alt="npm install size"></a>
14
+ <a href="https://www.npmjs.com/package/@1auth/account">
15
+ <img alt="npm weekly downloads" src="https://img.shields.io/npm/dw/@1auth/account.svg"></a>
16
+ <a href="https://www.npmjs.com/package/@1auth/account#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/account
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
@@ -1,5 +1,8 @@
1
+ // Copyright 2003 - 2026 will Farrell, and 1Auth contributors.
2
+ // SPDX-License-Identifier: MIT
1
3
  import {
2
4
  makeRandomConfigObject,
5
+ nowInSeconds,
3
6
  symmetricDecryptFields,
4
7
  symmetricEncryptFields,
5
8
  symmetricGenerateEncryptionKey,
@@ -32,8 +35,8 @@ const defaults = {
32
35
  encryptedFields: [],
33
36
  };
34
37
  const options = {};
35
- export default (params) => {
36
- Object.assign(options, defaults, params);
38
+ export default (opt = {}) => {
39
+ Object.assign(options, defaults, opt);
37
40
  };
38
41
  export const getOptions = () => options;
39
42
 
@@ -41,7 +44,7 @@ export const exists = async (sub) => {
41
44
  if (!sub || typeof sub !== "string") {
42
45
  throw new Error("404 Not Found", { cause: { sub } });
43
46
  }
44
- return options.store.exists(options.table, { sub });
47
+ return await options.store.exists(options.table, { sub });
45
48
  };
46
49
 
47
50
  export const lookup = async (sub) => {
@@ -63,7 +66,7 @@ export const lookup = async (sub) => {
63
66
  };
64
67
 
65
68
  export const create = async (values = {}) => {
66
- const sub = await options.randomSubject.create(options.subPrefix);
69
+ const sub = await options.randomSubject.create();
67
70
 
68
71
  const { encryptionKey, encryptedKey } = symmetricGenerateEncryptionKey(sub);
69
72
  const encryptedValues = symmetricEncryptFields(
@@ -81,11 +84,11 @@ export const create = async (values = {}) => {
81
84
  update: now,
82
85
  };
83
86
  if (options.idGenerate) {
84
- params.id = await options.randomId.create(options.idPrefix);
87
+ params.id = await options.randomId.create();
85
88
  }
86
89
  await options.store.insert(options.table, params);
87
90
 
88
- // TODO update guest session, attach sub
91
+ // If caller has a guest session, use session.rotate(guestSub, guestSessionId, sub, deviceMeta) to transition it.
89
92
  return sub;
90
93
  };
91
94
 
@@ -137,23 +140,3 @@ export const remove = async (sub) => {
137
140
  // Should trigger removal of credentials and messengers
138
141
  await options.store.remove(options.table, { sub });
139
142
  };
140
-
141
- /* export const expire = async (sub) => {
142
- const expire = nowInSeconds() + 90 * 24 * 60 * 60
143
- await options.store.update(options.table, { sub }, { expire })
144
- await options.notify.trigger('account-expire', sub)
145
- // TODO clear sessions
146
- }
147
-
148
- export const recover = async (sub) => {
149
- await options.store.update(options.table, { sub }, { expire: null })
150
- await options.notify.trigger('account-recover', sub)
151
- } */
152
-
153
- // TODO manage onboard state
154
-
155
- // TODO save notification settings
156
-
157
- // TODO authorize management?
158
-
159
- const nowInSeconds = () => Math.floor(Date.now() / 1000);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1auth/account",
3
- "version": "0.0.0-beta.0",
4
- "description": "",
3
+ "version": "0.0.0-beta.2",
4
+ "description": "User account management with encrypted storage and lifecycle operations",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=24"
@@ -12,18 +12,18 @@
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"
19
+ },
20
+ "./table/*": {
21
+ "import": "./table/*"
21
22
  }
22
23
  },
23
- "types": "index.d.ts",
24
24
  "files": [
25
25
  "index.js",
26
- "index.d.ts"
26
+ "table"
27
27
  ],
28
28
  "scripts": {
29
29
  "test": "npm run test:unit",
@@ -34,7 +34,13 @@
34
34
  "type": "github",
35
35
  "url": "https://github.com/sponsors/willfarrell"
36
36
  },
37
- "keywords": [],
37
+ "keywords": [
38
+ "1auth",
39
+ "OWASP",
40
+ "ASVS",
41
+ "account",
42
+ "identity"
43
+ ],
38
44
  "author": {
39
45
  "name": "1auth contributors",
40
46
  "url": "https://github.com/willfarrell/1auth/graphs/contributors"
@@ -50,6 +56,6 @@
50
56
  "homepage": "https://github.com/willfarrell/1auth",
51
57
  "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
52
58
  "dependencies": {
53
- "@1auth/crypto": "0.0.0-beta.0"
59
+ "@1auth/crypto": "0.0.0-beta.2"
54
60
  }
55
61
  }
@@ -0,0 +1,130 @@
1
+ // Copyright 2003 - 2026 will Farrell, and 1Auth contributors.
2
+ // SPDX-License-Identifier: MIT
3
+ import {
4
+ CreateTableCommand,
5
+ DeleteTableCommand,
6
+ } from "@aws-sdk/client-dynamodb";
7
+
8
+ export const name = "accounts";
9
+ export const timeToLiveKey = "remove";
10
+
11
+ export const create = async (client, table = name) => {
12
+ try {
13
+ await client.send(
14
+ new CreateTableCommand({
15
+ TableName: table,
16
+ AttributeDefinitions: [
17
+ // {
18
+ // AttributeName: "id",
19
+ // AttributeType: "S",
20
+ // },
21
+ {
22
+ AttributeName: "sub",
23
+ AttributeType: "S",
24
+ },
25
+ {
26
+ AttributeName: "digest",
27
+ AttributeType: "S",
28
+ },
29
+ // Used for listing all active sessions (optional)
30
+ // {
31
+ // AttributeName: "expire",
32
+ // AttributeType: "N",
33
+ // },
34
+ ],
35
+ KeySchema: [
36
+ {
37
+ AttributeName: "sub",
38
+ KeyType: "HASH",
39
+ },
40
+ // {
41
+ // AttributeName: "id",
42
+ // KeyType: "RANGE",
43
+ // },
44
+ ],
45
+ GlobalSecondaryIndexes: [
46
+ {
47
+ IndexName: "sub",
48
+ KeySchema: [
49
+ {
50
+ AttributeName: "sub",
51
+ KeyType: "HASH",
52
+ },
53
+ ],
54
+ Projection: {
55
+ ProjectionType: "INCLUDE",
56
+ NonKeyAttributes: [
57
+ "id",
58
+ "encryptionKey",
59
+ "value",
60
+ "name", // optional, used in tests
61
+ "unencrypted", // optional, used in tests
62
+ "create",
63
+ "expire",
64
+ ],
65
+ },
66
+ },
67
+ {
68
+ IndexName: "digest",
69
+ KeySchema: [
70
+ {
71
+ AttributeName: "digest",
72
+ KeyType: "HASH",
73
+ },
74
+ ],
75
+ Projection: {
76
+ ProjectionType: "INCLUDE",
77
+ NonKeyAttributes: [
78
+ "id",
79
+ "sub",
80
+ "encryptionKey",
81
+ "value",
82
+ "create",
83
+ "expire",
84
+ ],
85
+ },
86
+ },
87
+ // Used for listing all (optional)
88
+ // {
89
+ // IndexName: "active",
90
+ // KeySchema: [
91
+ // {
92
+ // AttributeName: "expire",
93
+ // KeyType: "HASH",
94
+ // },
95
+ // ],
96
+ // Projection: {
97
+ // ProjectionType: "INCLUDE",
98
+ // NonKeyAttributes: ["sub", "create"],
99
+ // },
100
+ // },
101
+ ],
102
+ TimeToLiveSpecification: {
103
+ Enabled: true,
104
+ AttributeName: timeToLiveKey,
105
+ },
106
+ BillingMode: "PAY_PER_REQUEST",
107
+ }),
108
+ );
109
+ } catch (e) {
110
+ if (e.message === "Cannot create preexisting table") {
111
+ await truncate(client, table);
112
+ } else {
113
+ console.error("ERROR create", e.message);
114
+ throw e;
115
+ }
116
+ }
117
+ };
118
+
119
+ export const truncate = async (client, table = name) => {
120
+ await drop(client, table);
121
+ await create(client, table);
122
+ };
123
+
124
+ export const drop = async (client, table = name) => {
125
+ await client.send(
126
+ new DeleteTableCommand({
127
+ TableName: table,
128
+ }),
129
+ );
130
+ };
package/table/sql.js ADDED
@@ -0,0 +1,44 @@
1
+ // Copyright 2003 - 2026 will Farrell, and 1Auth contributors.
2
+ // SPDX-License-Identifier: MIT
3
+ export const name = "accounts";
4
+ export const timeToLiveKey = "remove";
5
+ export const create = async (client, table = name) => {
6
+ const sql = `
7
+ CREATE TABLE IF NOT EXISTS ${table}
8
+ (
9
+ "id" VARCHAR(19) NOT NULL, -- prefix (user_) + entropy (11)
10
+ "sub" VARCHAR(15) NOT NULL, -- prefix (sub_) + entropy (11)
11
+
12
+ "encryptionKey" VARCHAR(256) NOT NULL,
13
+ "value" VARCHAR(512) DEFAULT NULL, -- username
14
+ "digest" VARCHAR(73) DEFAULT NULL, -- of username
15
+
16
+ "name" VARCHAR(128) DEFAULT NULL,
17
+ "unencrypted" VARCHAR(128) DEFAULT NULL,
18
+
19
+ "create" TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- postges: DEFAULT NOW(), sqlite: DEFAULT CURRENT_TIME,
20
+ "update" TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- NOW()
21
+ "verify" TIMESTAMP WITH TIME ZONE DEFAULT NULL,
22
+ "expire" TIMESTAMP WITH TIME ZONE DEFAULT NULL,
23
+ "${timeToLiveKey}" TIMESTAMP WITH TIME ZONE DEFAULT NULL,
24
+
25
+ CONSTRAINT ${table}_pkey PRIMARY KEY ("id"),
26
+ CONSTRAINT ${table}_ukey UNIQUE ("sub")
27
+ );
28
+ `;
29
+ return await client.query(sql);
30
+ };
31
+
32
+ export const truncate = async (client, table = name) => {
33
+ const sql = `
34
+ DELETE FROM ${table};
35
+ `;
36
+ return await client.query(sql);
37
+ };
38
+
39
+ export const drop = async (client, table = name) => {
40
+ const sql = `
41
+ DROP TABLE ${table};
42
+ `;
43
+ return await client.query(sql);
44
+ };