@liorandb/core 1.0.0 ā 1.0.1
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/package.json +1 -1
- package/src/utils/secureKey.js +53 -10
- package/test.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liorandb/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "LioranDB is a lightweight, local-first, peer-to-peer, file-based database with a MongoDB-style Node.js API and a simple CLI for seamless distributed development.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
package/src/utils/secureKey.js
CHANGED
|
@@ -1,18 +1,61 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
1
|
import crypto from "crypto";
|
|
4
|
-
import
|
|
2
|
+
import os from "os";
|
|
5
3
|
|
|
6
|
-
const
|
|
4
|
+
const VAR_NAME = "LIORANDB_MASTER_KEY";
|
|
7
5
|
|
|
8
6
|
export function getMasterKey() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
let key = process.env[VAR_NAME];
|
|
8
|
+
|
|
9
|
+
if (!key) {
|
|
10
|
+
console.error("\nā ERROR: Master encryption key not found in system environment variables.");
|
|
11
|
+
console.error(`š Variable required: ${VAR_NAME}\n`);
|
|
12
|
+
|
|
13
|
+
const generatedKey = crypto.randomBytes(32).toString("hex");
|
|
14
|
+
console.error("š§ Auto-generated a secure 256-bit key for you:");
|
|
15
|
+
console.error(generatedKey, "\n");
|
|
16
|
+
|
|
17
|
+
console.error("š Copy and paste the correct command below to set it permanently:");
|
|
18
|
+
|
|
19
|
+
printSetupCommand(generatedKey);
|
|
20
|
+
|
|
21
|
+
console.error("\nā After setting the variable, restart your terminal.");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
key = key.trim();
|
|
26
|
+
|
|
27
|
+
if (key.length !== 64) {
|
|
28
|
+
console.error("\nā ERROR: Invalid master key length.");
|
|
29
|
+
console.error("Required: 64 hex characters (256-bit)\n");
|
|
30
|
+
process.exit(1);
|
|
14
31
|
}
|
|
15
32
|
|
|
16
|
-
const key = fs.readFileSync(KEY_FILE, "utf8").trim();
|
|
17
33
|
return key;
|
|
18
34
|
}
|
|
35
|
+
|
|
36
|
+
function printSetupCommand(key) {
|
|
37
|
+
const platform = os.platform();
|
|
38
|
+
|
|
39
|
+
console.error("========================================");
|
|
40
|
+
|
|
41
|
+
if (platform === "win32") {
|
|
42
|
+
console.error("š Windows (System Environment Variable):");
|
|
43
|
+
console.error(
|
|
44
|
+
`setx ${VAR_NAME} "${key}" /M`
|
|
45
|
+
);
|
|
46
|
+
} else if (platform === "linux") {
|
|
47
|
+
console.error("š Linux (System-wide, requires sudo):");
|
|
48
|
+
console.error(
|
|
49
|
+
`echo "export ${VAR_NAME}=${key}" | sudo tee -a /etc/environment`
|
|
50
|
+
);
|
|
51
|
+
} else if (platform === "darwin") {
|
|
52
|
+
console.error("š macOS (system/global, requires sudo):");
|
|
53
|
+
console.error(
|
|
54
|
+
`echo "export ${VAR_NAME}=${key}" | sudo tee -a /etc/zshenv`
|
|
55
|
+
);
|
|
56
|
+
} else {
|
|
57
|
+
console.error(`ā Unsupported OS: ${platform}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.error("========================================");
|
|
61
|
+
}
|
package/test.js
ADDED
|
File without changes
|