@nexushub/client 0.4.3 → 0.4.5
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/dist/chunk-NOIMIIA5.js +53 -0
- package/dist/chunk-VFVPDENW.cjs +53 -0
- package/dist/cli.cjs +456 -95
- package/dist/content/binary-compiler.cjs +135 -0
- package/dist/content/binary-compiler.d.cts +28 -0
- package/dist/content/binary-compiler.d.ts +28 -0
- package/dist/content/binary-compiler.js +100 -0
- package/dist/content/local-cache-server.cjs +184 -52
- package/dist/content/local-cache-server.d.cts +9 -4
- package/dist/content/local-cache-server.d.ts +9 -4
- package/dist/content/local-cache-server.js +184 -52
- package/dist/index.cjs +221 -99
- package/dist/index.js +221 -99
- package/dist/local-cache-server-BNLLL4NR.js +224 -0
- package/dist/local-cache-server-SF5SXE7H.cjs +224 -0
- package/dist/react.cjs +399 -78
- package/dist/react.d.cts +140 -1
- package/dist/react.d.ts +140 -1
- package/dist/react.js +370 -49
- package/package.json +2 -1
- package/dist/local-cache-server-6DXQJFCQ.cjs +0 -114
- package/dist/local-cache-server-DBJWR7HD.js +0 -114
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/content/binary-compiler.ts
|
|
31
|
+
var binary_compiler_exports = {};
|
|
32
|
+
__export(binary_compiler_exports, {
|
|
33
|
+
BinaryCompiler: () => BinaryCompiler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(binary_compiler_exports);
|
|
36
|
+
var crypto = __toESM(require("crypto"), 1);
|
|
37
|
+
var BinaryCompiler = class {
|
|
38
|
+
/**
|
|
39
|
+
* Generates a secure, deterministic cryptographic key from the project's API key.
|
|
40
|
+
*/
|
|
41
|
+
static deriveKeys(apiKey) {
|
|
42
|
+
const hash = crypto.createHash("sha256").update(apiKey).digest();
|
|
43
|
+
const encryptionKey = hash;
|
|
44
|
+
const hmacKey = crypto.createHmac("sha256", apiKey).update("nexus-integrity-key").digest();
|
|
45
|
+
return { encryptionKey, hmacKey };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
|
|
49
|
+
*/
|
|
50
|
+
static compile(data, apiKey, projectId, metadataOverrides = {}) {
|
|
51
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
52
|
+
const metadata = {
|
|
53
|
+
version: "2.0.0",
|
|
54
|
+
compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
55
|
+
projectId,
|
|
56
|
+
...metadataOverrides
|
|
57
|
+
};
|
|
58
|
+
const metadataStr = JSON.stringify(metadata);
|
|
59
|
+
const metadataBuffer = Buffer.from(metadataStr, "utf-8");
|
|
60
|
+
const iv = crypto.randomBytes(16);
|
|
61
|
+
const cipher = crypto.createCipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
62
|
+
const plainTextPayload = JSON.stringify(data);
|
|
63
|
+
let encryptedPayload = cipher.update(plainTextPayload, "utf8");
|
|
64
|
+
encryptedPayload = Buffer.concat([encryptedPayload, cipher.final()]);
|
|
65
|
+
const payloadBuffer = Buffer.concat([iv, encryptedPayload]);
|
|
66
|
+
const headerBuffer = Buffer.from(this.MAGIC_HEADER, "ascii");
|
|
67
|
+
const metaLengthBuffer = Buffer.alloc(4);
|
|
68
|
+
metaLengthBuffer.writeUInt32BE(metadataBuffer.length, 0);
|
|
69
|
+
const payloadLengthBuffer = Buffer.alloc(4);
|
|
70
|
+
payloadLengthBuffer.writeUInt32BE(payloadBuffer.length, 0);
|
|
71
|
+
const prefixBlock = Buffer.concat([
|
|
72
|
+
headerBuffer,
|
|
73
|
+
metaLengthBuffer,
|
|
74
|
+
metadataBuffer,
|
|
75
|
+
payloadLengthBuffer,
|
|
76
|
+
payloadBuffer
|
|
77
|
+
]);
|
|
78
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
79
|
+
hmac.update(prefixBlock);
|
|
80
|
+
const signature = hmac.digest();
|
|
81
|
+
return Buffer.concat([prefixBlock, signature]);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
|
|
85
|
+
* Throws structured errors on integrity verification failures or file corruption.
|
|
86
|
+
*/
|
|
87
|
+
static decompile(buffer, apiKey) {
|
|
88
|
+
if (buffer.length < 44) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
"Corrupted File: Binary payload is too short to be a valid Nexus node."
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
94
|
+
const prefixBlockLength = buffer.length - 32;
|
|
95
|
+
const prefixBlock = buffer.subarray(0, prefixBlockLength);
|
|
96
|
+
const expectedSignature = buffer.subarray(prefixBlockLength);
|
|
97
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
98
|
+
hmac.update(prefixBlock);
|
|
99
|
+
const actualSignature = hmac.digest();
|
|
100
|
+
if (!crypto.timingSafeEqual(expectedSignature, actualSignature)) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
"DATA_INTEGRITY_VIOLATION: Cryptographic signature mismatch. This local node has been modified externally or tampered with."
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const magicHeader = prefixBlock.subarray(0, 4).toString("ascii");
|
|
106
|
+
if (magicHeader !== this.MAGIC_HEADER) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
"Invalid Format: File lacks the correct Nexus binary magic header."
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
const metaLength = prefixBlock.readUInt32BE(4);
|
|
112
|
+
const metaStart = 8;
|
|
113
|
+
const metaEnd = metaStart + metaLength;
|
|
114
|
+
const metadataStr = prefixBlock.subarray(metaStart, metaEnd).toString("utf-8");
|
|
115
|
+
const metadata = JSON.parse(metadataStr);
|
|
116
|
+
const payloadLength = prefixBlock.readUInt32BE(metaEnd);
|
|
117
|
+
const payloadStart = metaEnd + 4;
|
|
118
|
+
const payloadEnd = payloadStart + payloadLength;
|
|
119
|
+
const payloadBuffer = prefixBlock.subarray(payloadStart, payloadEnd);
|
|
120
|
+
const iv = payloadBuffer.subarray(0, 16);
|
|
121
|
+
const cipherText = payloadBuffer.subarray(16);
|
|
122
|
+
const decipher = crypto.createDecipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
123
|
+
let decrypted = decipher.update(cipherText);
|
|
124
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
125
|
+
const data = JSON.parse(decrypted.toString("utf8"));
|
|
126
|
+
return { data, metadata };
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
BinaryCompiler.MAGIC_HEADER = "NEXS";
|
|
130
|
+
// 4-byte ASCII magic identifier
|
|
131
|
+
BinaryCompiler.ALGORITHM = "aes-256-cbc";
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
BinaryCompiler
|
|
135
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface NxMetadata {
|
|
2
|
+
version: string;
|
|
3
|
+
compiledAt: string;
|
|
4
|
+
projectId: string;
|
|
5
|
+
schemaChecksum?: string;
|
|
6
|
+
}
|
|
7
|
+
declare class BinaryCompiler {
|
|
8
|
+
private static readonly MAGIC_HEADER;
|
|
9
|
+
private static readonly ALGORITHM;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a secure, deterministic cryptographic key from the project's API key.
|
|
12
|
+
*/
|
|
13
|
+
private static deriveKeys;
|
|
14
|
+
/**
|
|
15
|
+
* Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
|
|
16
|
+
*/
|
|
17
|
+
static compile(data: any, apiKey: string, projectId: string, metadataOverrides?: Partial<NxMetadata>): Buffer;
|
|
18
|
+
/**
|
|
19
|
+
* Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
|
|
20
|
+
* Throws structured errors on integrity verification failures or file corruption.
|
|
21
|
+
*/
|
|
22
|
+
static decompile(buffer: Buffer, apiKey: string): {
|
|
23
|
+
data: any;
|
|
24
|
+
metadata: NxMetadata;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { BinaryCompiler, type NxMetadata };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface NxMetadata {
|
|
2
|
+
version: string;
|
|
3
|
+
compiledAt: string;
|
|
4
|
+
projectId: string;
|
|
5
|
+
schemaChecksum?: string;
|
|
6
|
+
}
|
|
7
|
+
declare class BinaryCompiler {
|
|
8
|
+
private static readonly MAGIC_HEADER;
|
|
9
|
+
private static readonly ALGORITHM;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a secure, deterministic cryptographic key from the project's API key.
|
|
12
|
+
*/
|
|
13
|
+
private static deriveKeys;
|
|
14
|
+
/**
|
|
15
|
+
* Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
|
|
16
|
+
*/
|
|
17
|
+
static compile(data: any, apiKey: string, projectId: string, metadataOverrides?: Partial<NxMetadata>): Buffer;
|
|
18
|
+
/**
|
|
19
|
+
* Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
|
|
20
|
+
* Throws structured errors on integrity verification failures or file corruption.
|
|
21
|
+
*/
|
|
22
|
+
static decompile(buffer: Buffer, apiKey: string): {
|
|
23
|
+
data: any;
|
|
24
|
+
metadata: NxMetadata;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { BinaryCompiler, type NxMetadata };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/content/binary-compiler.ts
|
|
2
|
+
import * as crypto from "crypto";
|
|
3
|
+
var BinaryCompiler = class {
|
|
4
|
+
/**
|
|
5
|
+
* Generates a secure, deterministic cryptographic key from the project's API key.
|
|
6
|
+
*/
|
|
7
|
+
static deriveKeys(apiKey) {
|
|
8
|
+
const hash = crypto.createHash("sha256").update(apiKey).digest();
|
|
9
|
+
const encryptionKey = hash;
|
|
10
|
+
const hmacKey = crypto.createHmac("sha256", apiKey).update("nexus-integrity-key").digest();
|
|
11
|
+
return { encryptionKey, hmacKey };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
|
|
15
|
+
*/
|
|
16
|
+
static compile(data, apiKey, projectId, metadataOverrides = {}) {
|
|
17
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
18
|
+
const metadata = {
|
|
19
|
+
version: "2.0.0",
|
|
20
|
+
compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
21
|
+
projectId,
|
|
22
|
+
...metadataOverrides
|
|
23
|
+
};
|
|
24
|
+
const metadataStr = JSON.stringify(metadata);
|
|
25
|
+
const metadataBuffer = Buffer.from(metadataStr, "utf-8");
|
|
26
|
+
const iv = crypto.randomBytes(16);
|
|
27
|
+
const cipher = crypto.createCipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
28
|
+
const plainTextPayload = JSON.stringify(data);
|
|
29
|
+
let encryptedPayload = cipher.update(plainTextPayload, "utf8");
|
|
30
|
+
encryptedPayload = Buffer.concat([encryptedPayload, cipher.final()]);
|
|
31
|
+
const payloadBuffer = Buffer.concat([iv, encryptedPayload]);
|
|
32
|
+
const headerBuffer = Buffer.from(this.MAGIC_HEADER, "ascii");
|
|
33
|
+
const metaLengthBuffer = Buffer.alloc(4);
|
|
34
|
+
metaLengthBuffer.writeUInt32BE(metadataBuffer.length, 0);
|
|
35
|
+
const payloadLengthBuffer = Buffer.alloc(4);
|
|
36
|
+
payloadLengthBuffer.writeUInt32BE(payloadBuffer.length, 0);
|
|
37
|
+
const prefixBlock = Buffer.concat([
|
|
38
|
+
headerBuffer,
|
|
39
|
+
metaLengthBuffer,
|
|
40
|
+
metadataBuffer,
|
|
41
|
+
payloadLengthBuffer,
|
|
42
|
+
payloadBuffer
|
|
43
|
+
]);
|
|
44
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
45
|
+
hmac.update(prefixBlock);
|
|
46
|
+
const signature = hmac.digest();
|
|
47
|
+
return Buffer.concat([prefixBlock, signature]);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
|
|
51
|
+
* Throws structured errors on integrity verification failures or file corruption.
|
|
52
|
+
*/
|
|
53
|
+
static decompile(buffer, apiKey) {
|
|
54
|
+
if (buffer.length < 44) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Corrupted File: Binary payload is too short to be a valid Nexus node."
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
60
|
+
const prefixBlockLength = buffer.length - 32;
|
|
61
|
+
const prefixBlock = buffer.subarray(0, prefixBlockLength);
|
|
62
|
+
const expectedSignature = buffer.subarray(prefixBlockLength);
|
|
63
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
64
|
+
hmac.update(prefixBlock);
|
|
65
|
+
const actualSignature = hmac.digest();
|
|
66
|
+
if (!crypto.timingSafeEqual(expectedSignature, actualSignature)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"DATA_INTEGRITY_VIOLATION: Cryptographic signature mismatch. This local node has been modified externally or tampered with."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const magicHeader = prefixBlock.subarray(0, 4).toString("ascii");
|
|
72
|
+
if (magicHeader !== this.MAGIC_HEADER) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Invalid Format: File lacks the correct Nexus binary magic header."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const metaLength = prefixBlock.readUInt32BE(4);
|
|
78
|
+
const metaStart = 8;
|
|
79
|
+
const metaEnd = metaStart + metaLength;
|
|
80
|
+
const metadataStr = prefixBlock.subarray(metaStart, metaEnd).toString("utf-8");
|
|
81
|
+
const metadata = JSON.parse(metadataStr);
|
|
82
|
+
const payloadLength = prefixBlock.readUInt32BE(metaEnd);
|
|
83
|
+
const payloadStart = metaEnd + 4;
|
|
84
|
+
const payloadEnd = payloadStart + payloadLength;
|
|
85
|
+
const payloadBuffer = prefixBlock.subarray(payloadStart, payloadEnd);
|
|
86
|
+
const iv = payloadBuffer.subarray(0, 16);
|
|
87
|
+
const cipherText = payloadBuffer.subarray(16);
|
|
88
|
+
const decipher = crypto.createDecipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
89
|
+
let decrypted = decipher.update(cipherText);
|
|
90
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
91
|
+
const data = JSON.parse(decrypted.toString("utf8"));
|
|
92
|
+
return { data, metadata };
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
BinaryCompiler.MAGIC_HEADER = "NEXS";
|
|
96
|
+
// 4-byte ASCII magic identifier
|
|
97
|
+
BinaryCompiler.ALGORITHM = "aes-256-cbc";
|
|
98
|
+
export {
|
|
99
|
+
BinaryCompiler
|
|
100
|
+
};
|
|
@@ -35,84 +35,216 @@ __export(local_cache_server_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(local_cache_server_exports);
|
|
36
36
|
var import_fs = __toESM(require("fs"), 1);
|
|
37
37
|
var import_path = __toESM(require("path"), 1);
|
|
38
|
+
|
|
39
|
+
// src/config.ts
|
|
40
|
+
var DEFAULT_API_URL = "https://endpoints.gnexus.co.tz";
|
|
41
|
+
var DEFAULT_ANALYTICS_URL = "https://sentry.gnexus.co.tz";
|
|
42
|
+
var LOCAL_NEST_URL = "https://endpoints.gnexus.co.tz";
|
|
43
|
+
var LOCAL_RUST_URL = "https://sentry.gnexus.co.tz";
|
|
44
|
+
var getEnvConfig = () => {
|
|
45
|
+
const NEXT_PUBLIC_ID = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_ID : void 0;
|
|
46
|
+
const NEXT_PUBLIC_KEY = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_KEY : void 0;
|
|
47
|
+
const NEXT_PUBLIC_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_API_URL : void 0;
|
|
48
|
+
const NODE_ID = typeof process !== "undefined" ? process.env.NEXUS_PROJECT_ID : void 0;
|
|
49
|
+
const NODE_KEY = typeof process !== "undefined" ? process.env.NEXUS_API_KEY : void 0;
|
|
50
|
+
const NODE_URL = typeof process !== "undefined" ? process.env.NEXUS_API_URL : void 0;
|
|
51
|
+
const NODE_ENV = typeof process !== "undefined" ? process.env.NODE_ENV : "production";
|
|
52
|
+
const isDev = NODE_ENV === "development" || typeof window !== "undefined" && window.location.hostname === "localhost";
|
|
53
|
+
const projectId = NEXT_PUBLIC_ID ?? NODE_ID;
|
|
54
|
+
const apiKey = NEXT_PUBLIC_KEY ?? NODE_KEY;
|
|
55
|
+
const apiUrl = NEXT_PUBLIC_URL ?? NODE_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
|
|
56
|
+
const analyticsUrl = apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL;
|
|
57
|
+
return {
|
|
58
|
+
projectId,
|
|
59
|
+
apiKey,
|
|
60
|
+
apiUrl,
|
|
61
|
+
analyticsUrl
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/content/binary-compiler.ts
|
|
66
|
+
var crypto = __toESM(require("crypto"), 1);
|
|
67
|
+
var BinaryCompiler = class {
|
|
68
|
+
/**
|
|
69
|
+
* Generates a secure, deterministic cryptographic key from the project's API key.
|
|
70
|
+
*/
|
|
71
|
+
static deriveKeys(apiKey) {
|
|
72
|
+
const hash = crypto.createHash("sha256").update(apiKey).digest();
|
|
73
|
+
const encryptionKey = hash;
|
|
74
|
+
const hmacKey = crypto.createHmac("sha256", apiKey).update("nexus-integrity-key").digest();
|
|
75
|
+
return { encryptionKey, hmacKey };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
|
|
79
|
+
*/
|
|
80
|
+
static compile(data, apiKey, projectId, metadataOverrides = {}) {
|
|
81
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
82
|
+
const metadata = {
|
|
83
|
+
version: "2.0.0",
|
|
84
|
+
compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
85
|
+
projectId,
|
|
86
|
+
...metadataOverrides
|
|
87
|
+
};
|
|
88
|
+
const metadataStr = JSON.stringify(metadata);
|
|
89
|
+
const metadataBuffer = Buffer.from(metadataStr, "utf-8");
|
|
90
|
+
const iv = crypto.randomBytes(16);
|
|
91
|
+
const cipher = crypto.createCipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
92
|
+
const plainTextPayload = JSON.stringify(data);
|
|
93
|
+
let encryptedPayload = cipher.update(plainTextPayload, "utf8");
|
|
94
|
+
encryptedPayload = Buffer.concat([encryptedPayload, cipher.final()]);
|
|
95
|
+
const payloadBuffer = Buffer.concat([iv, encryptedPayload]);
|
|
96
|
+
const headerBuffer = Buffer.from(this.MAGIC_HEADER, "ascii");
|
|
97
|
+
const metaLengthBuffer = Buffer.alloc(4);
|
|
98
|
+
metaLengthBuffer.writeUInt32BE(metadataBuffer.length, 0);
|
|
99
|
+
const payloadLengthBuffer = Buffer.alloc(4);
|
|
100
|
+
payloadLengthBuffer.writeUInt32BE(payloadBuffer.length, 0);
|
|
101
|
+
const prefixBlock = Buffer.concat([
|
|
102
|
+
headerBuffer,
|
|
103
|
+
metaLengthBuffer,
|
|
104
|
+
metadataBuffer,
|
|
105
|
+
payloadLengthBuffer,
|
|
106
|
+
payloadBuffer
|
|
107
|
+
]);
|
|
108
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
109
|
+
hmac.update(prefixBlock);
|
|
110
|
+
const signature = hmac.digest();
|
|
111
|
+
return Buffer.concat([prefixBlock, signature]);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
|
|
115
|
+
* Throws structured errors on integrity verification failures or file corruption.
|
|
116
|
+
*/
|
|
117
|
+
static decompile(buffer, apiKey) {
|
|
118
|
+
if (buffer.length < 44) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
"Corrupted File: Binary payload is too short to be a valid Nexus node."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
124
|
+
const prefixBlockLength = buffer.length - 32;
|
|
125
|
+
const prefixBlock = buffer.subarray(0, prefixBlockLength);
|
|
126
|
+
const expectedSignature = buffer.subarray(prefixBlockLength);
|
|
127
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
128
|
+
hmac.update(prefixBlock);
|
|
129
|
+
const actualSignature = hmac.digest();
|
|
130
|
+
if (!crypto.timingSafeEqual(expectedSignature, actualSignature)) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
"DATA_INTEGRITY_VIOLATION: Cryptographic signature mismatch. This local node has been modified externally or tampered with."
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const magicHeader = prefixBlock.subarray(0, 4).toString("ascii");
|
|
136
|
+
if (magicHeader !== this.MAGIC_HEADER) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
"Invalid Format: File lacks the correct Nexus binary magic header."
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
const metaLength = prefixBlock.readUInt32BE(4);
|
|
142
|
+
const metaStart = 8;
|
|
143
|
+
const metaEnd = metaStart + metaLength;
|
|
144
|
+
const metadataStr = prefixBlock.subarray(metaStart, metaEnd).toString("utf-8");
|
|
145
|
+
const metadata = JSON.parse(metadataStr);
|
|
146
|
+
const payloadLength = prefixBlock.readUInt32BE(metaEnd);
|
|
147
|
+
const payloadStart = metaEnd + 4;
|
|
148
|
+
const payloadEnd = payloadStart + payloadLength;
|
|
149
|
+
const payloadBuffer = prefixBlock.subarray(payloadStart, payloadEnd);
|
|
150
|
+
const iv = payloadBuffer.subarray(0, 16);
|
|
151
|
+
const cipherText = payloadBuffer.subarray(16);
|
|
152
|
+
const decipher = crypto.createDecipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
153
|
+
let decrypted = decipher.update(cipherText);
|
|
154
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
155
|
+
const data = JSON.parse(decrypted.toString("utf8"));
|
|
156
|
+
return { data, metadata };
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
BinaryCompiler.MAGIC_HEADER = "NEXS";
|
|
160
|
+
// 4-byte ASCII magic identifier
|
|
161
|
+
BinaryCompiler.ALGORITHM = "aes-256-cbc";
|
|
162
|
+
|
|
163
|
+
// src/content/local-cache-server.ts
|
|
38
164
|
var LocalCache = class {
|
|
39
165
|
constructor(customPath) {
|
|
166
|
+
this.apiKey = "";
|
|
40
167
|
this.baseDir = customPath || ".nexus/local";
|
|
168
|
+
const config = getEnvConfig();
|
|
169
|
+
this.apiKey = config.apiKey || "";
|
|
41
170
|
}
|
|
42
171
|
isLoaded() {
|
|
43
172
|
return import_fs.default.existsSync(import_path.default.resolve(process.cwd(), this.baseDir));
|
|
44
173
|
}
|
|
45
174
|
/**
|
|
46
|
-
*
|
|
175
|
+
* Helper to decrypt and decompile `.nx` files on-the-fly.
|
|
47
176
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`${slug}.json`
|
|
55
|
-
);
|
|
56
|
-
if (import_fs.default.existsSync(filePath)) {
|
|
57
|
-
const fileContent = import_fs.default.readFileSync(filePath, "utf-8");
|
|
58
|
-
const pageData = JSON.parse(fileContent);
|
|
59
|
-
return pageData.data !== void 0 ? pageData.data : pageData;
|
|
177
|
+
decompileFile(filePath) {
|
|
178
|
+
if (!this.apiKey) {
|
|
179
|
+
if (process.env.NODE_ENV === "development") {
|
|
180
|
+
console.warn(
|
|
181
|
+
"\u26A0\uFE0F NexusHub: Missing NEXUS_API_KEY. Local decryption bypassed."
|
|
182
|
+
);
|
|
60
183
|
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const encryptedBuffer = import_fs.default.readFileSync(filePath);
|
|
188
|
+
const decompiled = BinaryCompiler.decompile(encryptedBuffer, this.apiKey);
|
|
189
|
+
return decompiled.data;
|
|
61
190
|
} catch (error) {
|
|
62
191
|
if (process.env.NODE_ENV === "development") {
|
|
63
|
-
console.
|
|
64
|
-
|
|
65
|
-
|
|
192
|
+
console.error(
|
|
193
|
+
`
|
|
194
|
+
\u{1F6A8} NexusHub Security Alert: Data Integrity Violation in file:
|
|
195
|
+
${filePath}
|
|
196
|
+
Error: ${error.message}
|
|
197
|
+
This file has been disabled until regenerated via npx nexus pull.
|
|
198
|
+
`
|
|
66
199
|
);
|
|
67
200
|
}
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Retrieve a specific page directly from its .nx file.
|
|
206
|
+
*/
|
|
207
|
+
async getPage(slug) {
|
|
208
|
+
const filePath = import_path.default.resolve(
|
|
209
|
+
process.cwd(),
|
|
210
|
+
this.baseDir,
|
|
211
|
+
"pages",
|
|
212
|
+
`${slug}.nx`
|
|
213
|
+
);
|
|
214
|
+
if (import_fs.default.existsSync(filePath)) {
|
|
215
|
+
const pageData = this.decompileFile(filePath);
|
|
216
|
+
if (!pageData) return null;
|
|
217
|
+
return pageData.data !== void 0 ? pageData.data : pageData;
|
|
68
218
|
}
|
|
69
219
|
return null;
|
|
70
220
|
}
|
|
71
221
|
/**
|
|
72
|
-
* Retrieve an entire collection from its specific
|
|
222
|
+
* Retrieve an entire collection from its specific .nx file.
|
|
73
223
|
*/
|
|
74
224
|
async getCollection(collectionId) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const fileContent = import_fs.default.readFileSync(filePath, "utf-8");
|
|
84
|
-
return JSON.parse(fileContent);
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
if (process.env.NODE_ENV === "development") {
|
|
88
|
-
console.warn(
|
|
89
|
-
`\u26A0\uFE0F NexusHub: Failed to load local collection '${collectionId}':`,
|
|
90
|
-
error
|
|
91
|
-
);
|
|
92
|
-
}
|
|
225
|
+
const filePath = import_path.default.resolve(
|
|
226
|
+
process.cwd(),
|
|
227
|
+
this.baseDir,
|
|
228
|
+
"collections",
|
|
229
|
+
`${collectionId}.nx`
|
|
230
|
+
);
|
|
231
|
+
if (import_fs.default.existsSync(filePath)) {
|
|
232
|
+
return this.decompileFile(filePath);
|
|
93
233
|
}
|
|
94
234
|
return null;
|
|
95
235
|
}
|
|
96
236
|
/**
|
|
97
|
-
* Retrieve global settings from its file.
|
|
237
|
+
* Retrieve global settings from its .nx file.
|
|
98
238
|
*/
|
|
99
239
|
async getGlobals() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.baseDir,
|
|
104
|
-
"globals.json"
|
|
105
|
-
);
|
|
106
|
-
if (import_fs.default.existsSync(filePath)) {
|
|
107
|
-
const fileContent = import_fs.default.readFileSync(filePath, "utf-8");
|
|
108
|
-
return JSON.parse(fileContent);
|
|
109
|
-
}
|
|
110
|
-
} catch {
|
|
240
|
+
const filePath = import_path.default.resolve(process.cwd(), this.baseDir, "globals.nx");
|
|
241
|
+
if (import_fs.default.existsSync(filePath)) {
|
|
242
|
+
return this.decompileFile(filePath);
|
|
111
243
|
}
|
|
112
244
|
return null;
|
|
113
245
|
}
|
|
114
246
|
/**
|
|
115
|
-
* Returns a merged JSON of the entire workspace structure
|
|
247
|
+
* Returns a merged JSON of the entire workspace structure.
|
|
116
248
|
*/
|
|
117
249
|
async getAllData() {
|
|
118
250
|
const pages = {};
|
|
@@ -122,8 +254,8 @@ var LocalCache = class {
|
|
|
122
254
|
const pagesDir = import_path.default.resolve(process.cwd(), this.baseDir, "pages");
|
|
123
255
|
if (import_fs.default.existsSync(pagesDir)) {
|
|
124
256
|
for (const file of import_fs.default.readdirSync(pagesDir)) {
|
|
125
|
-
if (file.endsWith(".
|
|
126
|
-
const slug = import_path.default.basename(file, ".
|
|
257
|
+
if (file.endsWith(".nx")) {
|
|
258
|
+
const slug = import_path.default.basename(file, ".nx");
|
|
127
259
|
pages[slug] = await this.getPage(slug);
|
|
128
260
|
}
|
|
129
261
|
}
|
|
@@ -131,8 +263,8 @@ var LocalCache = class {
|
|
|
131
263
|
const colsDir = import_path.default.resolve(process.cwd(), this.baseDir, "collections");
|
|
132
264
|
if (import_fs.default.existsSync(colsDir)) {
|
|
133
265
|
for (const file of import_fs.default.readdirSync(colsDir)) {
|
|
134
|
-
if (file.endsWith(".
|
|
135
|
-
const id = import_path.default.basename(file, ".
|
|
266
|
+
if (file.endsWith(".nx")) {
|
|
267
|
+
const id = import_path.default.basename(file, ".nx");
|
|
136
268
|
collections[id] = await this.getCollection(id) || [];
|
|
137
269
|
}
|
|
138
270
|
}
|
|
@@ -2,22 +2,27 @@ import { I as ILocalCache } from '../cache-types-B39iNHfE.cjs';
|
|
|
2
2
|
|
|
3
3
|
declare class LocalCache implements ILocalCache {
|
|
4
4
|
private baseDir;
|
|
5
|
+
private apiKey;
|
|
5
6
|
constructor(customPath?: string);
|
|
6
7
|
isLoaded(): boolean;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Helper to decrypt and decompile `.nx` files on-the-fly.
|
|
10
|
+
*/
|
|
11
|
+
private decompileFile;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieve a specific page directly from its .nx file.
|
|
9
14
|
*/
|
|
10
15
|
getPage(slug: string): Promise<any>;
|
|
11
16
|
/**
|
|
12
|
-
* Retrieve an entire collection from its specific
|
|
17
|
+
* Retrieve an entire collection from its specific .nx file.
|
|
13
18
|
*/
|
|
14
19
|
getCollection(collectionId: string): Promise<any[] | null>;
|
|
15
20
|
/**
|
|
16
|
-
* Retrieve global settings from its file.
|
|
21
|
+
* Retrieve global settings from its .nx file.
|
|
17
22
|
*/
|
|
18
23
|
getGlobals(): Promise<any>;
|
|
19
24
|
/**
|
|
20
|
-
* Returns a merged JSON of the entire workspace structure
|
|
25
|
+
* Returns a merged JSON of the entire workspace structure.
|
|
21
26
|
*/
|
|
22
27
|
getAllData(): Promise<any>;
|
|
23
28
|
}
|
|
@@ -2,22 +2,27 @@ import { I as ILocalCache } from '../cache-types-B39iNHfE.js';
|
|
|
2
2
|
|
|
3
3
|
declare class LocalCache implements ILocalCache {
|
|
4
4
|
private baseDir;
|
|
5
|
+
private apiKey;
|
|
5
6
|
constructor(customPath?: string);
|
|
6
7
|
isLoaded(): boolean;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Helper to decrypt and decompile `.nx` files on-the-fly.
|
|
10
|
+
*/
|
|
11
|
+
private decompileFile;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieve a specific page directly from its .nx file.
|
|
9
14
|
*/
|
|
10
15
|
getPage(slug: string): Promise<any>;
|
|
11
16
|
/**
|
|
12
|
-
* Retrieve an entire collection from its specific
|
|
17
|
+
* Retrieve an entire collection from its specific .nx file.
|
|
13
18
|
*/
|
|
14
19
|
getCollection(collectionId: string): Promise<any[] | null>;
|
|
15
20
|
/**
|
|
16
|
-
* Retrieve global settings from its file.
|
|
21
|
+
* Retrieve global settings from its .nx file.
|
|
17
22
|
*/
|
|
18
23
|
getGlobals(): Promise<any>;
|
|
19
24
|
/**
|
|
20
|
-
* Returns a merged JSON of the entire workspace structure
|
|
25
|
+
* Returns a merged JSON of the entire workspace structure.
|
|
21
26
|
*/
|
|
22
27
|
getAllData(): Promise<any>;
|
|
23
28
|
}
|