@nexushub/client 0.4.2 → 0.4.4
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 +460 -99
- 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-client.cjs +27 -4
- package/dist/content/local-cache-client.js +0 -2
- package/dist/content/local-cache-server.cjs +231 -66
- 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 -54
- package/dist/index.cjs +2629 -31
- package/dist/index.d.cts +321 -4
- package/dist/index.d.ts +321 -4
- package/dist/index.js +2579 -28
- package/dist/local-cache-client-I6UYVJJV.js +59 -0
- package/dist/local-cache-client-IGAL7SZ6.cjs +59 -0
- package/dist/local-cache-server-BNLLL4NR.js +224 -0
- package/dist/local-cache-server-SF5SXE7H.cjs +224 -0
- package/dist/react.cjs +2931 -3
- package/dist/react.d.cts +488 -3
- package/dist/react.d.ts +488 -3
- package/dist/react.js +2936 -8
- package/package.json +2 -1
- package/dist/chunk-FMMFQP5O.cjs +0 -2643
- package/dist/chunk-G4SHBWAQ.js +0 -2643
- package/dist/react-C795ypnM.d.cts +0 -386
- package/dist/react-C795ypnM.d.ts +0 -386
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
20
|
// src/content/local-cache-client.ts
|
|
21
|
+
var local_cache_client_exports = {};
|
|
22
|
+
__export(local_cache_client_exports, {
|
|
23
|
+
LocalCache: () => LocalCache
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(local_cache_client_exports);
|
|
4
26
|
var LocalCache = class {
|
|
5
27
|
constructor(customPath) {
|
|
6
28
|
// Maintain private properties for type parity with the Server version
|
|
@@ -56,6 +78,7 @@ var LocalCache = class {
|
|
|
56
78
|
return !isMissing || isMalformed;
|
|
57
79
|
}
|
|
58
80
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
LocalCache
|
|
84
|
+
});
|