@vex-chat/libvex 5.1.0 → 5.3.0

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 (142) hide show
  1. package/CLA.md +38 -0
  2. package/LICENSE-COMMERCIAL +10 -0
  3. package/LICENSING.md +15 -0
  4. package/README.md +8 -2
  5. package/dist/Client.d.ts +47 -3
  6. package/dist/Client.d.ts.map +1 -1
  7. package/dist/Client.js +998 -496
  8. package/dist/Client.js.map +1 -1
  9. package/dist/Storage.d.ts +5 -0
  10. package/dist/Storage.d.ts.map +1 -1
  11. package/dist/Storage.js +5 -0
  12. package/dist/Storage.js.map +1 -1
  13. package/dist/__tests__/harness/memory-storage.d.ts +7 -2
  14. package/dist/__tests__/harness/memory-storage.d.ts.map +1 -1
  15. package/dist/__tests__/harness/memory-storage.js +44 -29
  16. package/dist/__tests__/harness/memory-storage.js.map +1 -1
  17. package/dist/codec.d.ts +9 -9
  18. package/dist/codec.d.ts.map +1 -1
  19. package/dist/codec.js +17 -19
  20. package/dist/codec.js.map +1 -1
  21. package/dist/codecs.d.ts +5 -0
  22. package/dist/codecs.d.ts.map +1 -1
  23. package/dist/codecs.js +5 -0
  24. package/dist/codecs.js.map +1 -1
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/keystore/memory.d.ts +5 -0
  30. package/dist/keystore/memory.d.ts.map +1 -1
  31. package/dist/keystore/memory.js +5 -0
  32. package/dist/keystore/memory.js.map +1 -1
  33. package/dist/keystore/node.d.ts +5 -0
  34. package/dist/keystore/node.d.ts.map +1 -1
  35. package/dist/keystore/node.js +16 -8
  36. package/dist/keystore/node.js.map +1 -1
  37. package/dist/preset/common.d.ts +5 -0
  38. package/dist/preset/common.d.ts.map +1 -1
  39. package/dist/preset/common.js +5 -0
  40. package/dist/preset/common.js.map +1 -1
  41. package/dist/preset/node.d.ts +5 -0
  42. package/dist/preset/node.d.ts.map +1 -1
  43. package/dist/preset/node.js +9 -1
  44. package/dist/preset/node.js.map +1 -1
  45. package/dist/preset/test.d.ts +5 -0
  46. package/dist/preset/test.d.ts.map +1 -1
  47. package/dist/preset/test.js +9 -1
  48. package/dist/preset/test.js.map +1 -1
  49. package/dist/storage/node/http-agents.d.ts +5 -0
  50. package/dist/storage/node/http-agents.d.ts.map +1 -1
  51. package/dist/storage/node/http-agents.js +5 -0
  52. package/dist/storage/node/http-agents.js.map +1 -1
  53. package/dist/storage/node.d.ts +6 -1
  54. package/dist/storage/node.d.ts.map +1 -1
  55. package/dist/storage/node.js +7 -4
  56. package/dist/storage/node.js.map +1 -1
  57. package/dist/storage/schema.d.ts +5 -0
  58. package/dist/storage/schema.d.ts.map +1 -1
  59. package/dist/storage/schema.js +5 -0
  60. package/dist/storage/schema.js.map +1 -1
  61. package/dist/storage/sqlite.d.ts +22 -4
  62. package/dist/storage/sqlite.d.ts.map +1 -1
  63. package/dist/storage/sqlite.js +172 -98
  64. package/dist/storage/sqlite.js.map +1 -1
  65. package/dist/transport/types.d.ts +5 -0
  66. package/dist/transport/types.d.ts.map +1 -1
  67. package/dist/transport/types.js +5 -0
  68. package/dist/transport/types.js.map +1 -1
  69. package/dist/transport/websocket.d.ts +5 -0
  70. package/dist/transport/websocket.d.ts.map +1 -1
  71. package/dist/transport/websocket.js +5 -0
  72. package/dist/transport/websocket.js.map +1 -1
  73. package/dist/types/crypto.d.ts +5 -0
  74. package/dist/types/crypto.d.ts.map +1 -1
  75. package/dist/types/crypto.js +3 -5
  76. package/dist/types/crypto.js.map +1 -1
  77. package/dist/types/identity.d.ts +5 -0
  78. package/dist/types/identity.d.ts.map +1 -1
  79. package/dist/types/identity.js +3 -2
  80. package/dist/types/identity.js.map +1 -1
  81. package/dist/types/index.d.ts +5 -0
  82. package/dist/types/index.d.ts.map +1 -1
  83. package/dist/types/index.js +5 -0
  84. package/dist/types/index.js.map +1 -1
  85. package/dist/utils/capitalize.d.ts +5 -0
  86. package/dist/utils/capitalize.d.ts.map +1 -1
  87. package/dist/utils/capitalize.js +5 -0
  88. package/dist/utils/capitalize.js.map +1 -1
  89. package/dist/utils/fipsMailExtra.d.ts +30 -0
  90. package/dist/utils/fipsMailExtra.d.ts.map +1 -0
  91. package/dist/utils/fipsMailExtra.js +114 -0
  92. package/dist/utils/fipsMailExtra.js.map +1 -0
  93. package/dist/utils/formatBytes.d.ts +5 -0
  94. package/dist/utils/formatBytes.d.ts.map +1 -1
  95. package/dist/utils/formatBytes.js +5 -0
  96. package/dist/utils/formatBytes.js.map +1 -1
  97. package/dist/utils/resolveAtRestAesKey.d.ts +13 -0
  98. package/dist/utils/resolveAtRestAesKey.d.ts.map +1 -0
  99. package/dist/utils/resolveAtRestAesKey.js +26 -0
  100. package/dist/utils/resolveAtRestAesKey.js.map +1 -0
  101. package/dist/utils/sqlSessionToCrypto.d.ts +5 -0
  102. package/dist/utils/sqlSessionToCrypto.d.ts.map +1 -1
  103. package/dist/utils/sqlSessionToCrypto.js +5 -0
  104. package/dist/utils/sqlSessionToCrypto.js.map +1 -1
  105. package/dist/utils/uint8uuid.d.ts +5 -0
  106. package/dist/utils/uint8uuid.d.ts.map +1 -1
  107. package/dist/utils/uint8uuid.js +5 -0
  108. package/dist/utils/uint8uuid.js.map +1 -1
  109. package/package.json +10 -3
  110. package/src/Client.ts +1281 -642
  111. package/src/Storage.ts +6 -0
  112. package/src/__tests__/codec.test.ts +6 -0
  113. package/src/__tests__/harness/fixtures.ts +6 -0
  114. package/src/__tests__/harness/memory-storage.ts +72 -52
  115. package/src/__tests__/harness/platform-transports.ts +6 -0
  116. package/src/__tests__/harness/poison-node-imports.ts +6 -0
  117. package/src/__tests__/harness/shared-suite.ts +288 -124
  118. package/src/__tests__/platform-browser.test.ts +15 -1
  119. package/src/__tests__/platform-node.test.ts +17 -3
  120. package/src/codec.ts +21 -8
  121. package/src/codecs.ts +6 -0
  122. package/src/index.ts +6 -0
  123. package/src/keystore/memory.ts +6 -0
  124. package/src/keystore/node.ts +27 -13
  125. package/src/preset/common.ts +6 -0
  126. package/src/preset/node.ts +14 -1
  127. package/src/preset/test.ts +14 -1
  128. package/src/storage/node/http-agents.ts +6 -0
  129. package/src/storage/node.ts +11 -4
  130. package/src/storage/schema.ts +6 -0
  131. package/src/storage/sqlite.ts +208 -135
  132. package/src/transport/types.ts +6 -0
  133. package/src/transport/websocket.ts +6 -0
  134. package/src/types/crypto.ts +6 -0
  135. package/src/types/identity.ts +6 -0
  136. package/src/types/index.ts +6 -0
  137. package/src/utils/capitalize.ts +6 -0
  138. package/src/utils/fipsMailExtra.ts +164 -0
  139. package/src/utils/formatBytes.ts +6 -0
  140. package/src/utils/resolveAtRestAesKey.ts +39 -0
  141. package/src/utils/sqlSessionToCrypto.ts +6 -0
  142. package/src/utils/uint8uuid.ts +6 -0
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  import type { KeyStore, StoredCredentials } from "../types/index.js";
2
8
 
3
9
  import * as fs from "node:fs";
@@ -9,7 +15,7 @@ import * as path from "node:path";
9
15
  * Stores credentials as encrypted files on disk using XUtils.encryptKeyData.
10
16
  * Node-only — imports node:fs.
11
17
  */
12
- import { XUtils } from "@vex-chat/crypto";
18
+ import { getCryptoProfile, XUtils } from "@vex-chat/crypto";
13
19
 
14
20
  export class NodeKeyStore implements KeyStore {
15
21
  private readonly dir: string;
@@ -37,7 +43,7 @@ export class NodeKeyStore implements KeyStore {
37
43
 
38
44
  load(username?: string): Promise<null | StoredCredentials> {
39
45
  if (username) {
40
- return Promise.resolve(this.readFile(this.filePath(username)));
46
+ return this.readFile(this.filePath(username));
41
47
  }
42
48
  // Find most recent .vex file in the directory
43
49
  try {
@@ -52,32 +58,40 @@ export class NodeKeyStore implements KeyStore {
52
58
  if (files.length === 0) return Promise.resolve(null);
53
59
  const newest = files[0];
54
60
  if (!newest) return Promise.resolve(null);
55
- return Promise.resolve(
56
- this.readFile(path.join(this.dir, newest.name)),
57
- );
61
+ return this.readFile(path.join(this.dir, newest.name));
58
62
  } catch {
59
63
  return Promise.resolve(null);
60
64
  }
61
65
  }
62
66
 
63
- save(creds: StoredCredentials): Promise<void> {
67
+ async save(creds: StoredCredentials): Promise<void> {
64
68
  const data = JSON.stringify(creds);
65
- const encrypted = XUtils.encryptKeyData(this.passphrase, data);
69
+ const encrypted =
70
+ getCryptoProfile() === "fips"
71
+ ? await XUtils.encryptKeyDataAsync(this.passphrase, data)
72
+ : XUtils.encryptKeyData(this.passphrase, data);
66
73
  fs.writeFileSync(this.filePath(creds.username), encrypted);
67
- return Promise.resolve();
68
74
  }
69
75
 
70
76
  private filePath(username: string): string {
71
77
  return path.join(this.dir, `${username}.vex`);
72
78
  }
73
79
 
74
- private readFile(filePath: string): null | StoredCredentials {
80
+ private async readFile(
81
+ filePath: string,
82
+ ): Promise<null | StoredCredentials> {
75
83
  try {
76
84
  const data = fs.readFileSync(filePath);
77
- const decrypted = XUtils.decryptKeyData(
78
- new Uint8Array(data),
79
- this.passphrase,
80
- );
85
+ const decrypted =
86
+ getCryptoProfile() === "fips"
87
+ ? await XUtils.decryptKeyDataAsync(
88
+ new Uint8Array(data),
89
+ this.passphrase,
90
+ )
91
+ : XUtils.decryptKeyData(
92
+ new Uint8Array(data),
93
+ this.passphrase,
94
+ );
81
95
  const parsed: unknown = JSON.parse(decrypted);
82
96
  if (isStoredCredentials(parsed)) {
83
97
  return parsed;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  import type { Storage } from "../Storage.js";
2
8
 
3
9
  /** Internal preset interface used by nodePreset and testPreset. */
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  import type { Storage } from "../Storage.js";
2
8
  /**
3
9
  * Platform preset for Node.js (CLI tools, bots, tests).
@@ -10,8 +16,15 @@ import type { PlatformPreset } from "./common.js";
10
16
  export function nodePreset(): PlatformPreset {
11
17
  return {
12
18
  async createStorage(dbName, privateKey): Promise<Storage> {
19
+ const { getCryptoProfile } = await import("@vex-chat/crypto");
13
20
  const { createNodeStorage } = await import("../storage/node.js");
14
- return createNodeStorage(dbName, privateKey);
21
+ const { resolveAtRestAesKeyFromSignKeyHex } =
22
+ await import("../utils/resolveAtRestAesKey.js");
23
+ const atRest = await resolveAtRestAesKeyFromSignKeyHex(
24
+ privateKey,
25
+ getCryptoProfile(),
26
+ );
27
+ return createNodeStorage(dbName, atRest);
15
28
  },
16
29
  deviceName: process.platform,
17
30
  };
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  /**
2
8
  * Platform preset for tests — no I/O, no platform dependencies.
3
9
  *
@@ -9,9 +15,16 @@ import type { PlatformPreset } from "./common.js";
9
15
  export function testPreset(): PlatformPreset {
10
16
  return {
11
17
  async createStorage(_dbName, privateKey) {
18
+ const { getCryptoProfile } = await import("@vex-chat/crypto");
19
+ const { resolveAtRestAesKeyFromSignKeyHex } =
20
+ await import("../utils/resolveAtRestAesKey.js");
12
21
  const { MemoryStorage } =
13
22
  await import("../__tests__/harness/memory-storage.js");
14
- const storage = new MemoryStorage(privateKey);
23
+ const atRest = await resolveAtRestAesKeyFromSignKeyHex(
24
+ privateKey,
25
+ getCryptoProfile(),
26
+ );
27
+ const storage = new MemoryStorage(atRest);
15
28
  await storage.init();
16
29
  return storage;
17
30
  },
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  import type { AxiosInstance } from "axios";
2
8
 
3
9
  /**
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  import type { Storage } from "../Storage.js";
2
8
  import type { ClientDatabase } from "./schema.js";
3
9
 
@@ -10,13 +16,14 @@ import { Kysely, SqliteDialect } from "kysely";
10
16
 
11
17
  import { SqliteStorage } from "./sqlite.js";
12
18
 
13
- export function createNodeStorage(dbPath: string, SK: string): Storage {
19
+ export function createNodeStorage(
20
+ dbPath: string,
21
+ atRestAesKey: Uint8Array,
22
+ ): Storage {
14
23
  const db = new Kysely<ClientDatabase>({
15
24
  dialect: new SqliteDialect({
16
25
  database: new BetterSqlite3(dbPath),
17
26
  }),
18
27
  });
19
- const storage = new SqliteStorage(db, SK);
20
- void storage.init();
21
- return storage;
28
+ return new SqliteStorage(db, atRestAesKey);
22
29
  }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2020-2026 Vex Heavy Industries LLC
3
+ * Licensed under AGPL-3.0. See LICENSE for details.
4
+ * Commercial licenses available at vex.wtf
5
+ */
6
+
1
7
  /**
2
8
  * Kysely typed table interfaces for the client-side SQLite database.
3
9
  */