02. Client SDK/Engine Cryptography

The .nx Binary Specification

GN-Apex stores offline data in custom .nx binary files instead of plaintext JSON to guarantee privacy, prevent repository data leaks, and enforce cryptographic anti-tamper verification.

CRYPTOGRAPHIC INTEGRITY
AES-256
+ HMAC-SHA256 Signed Envelopes

Offline development data is protected with the same cryptographic standard used in hardware security modules.

Tamper-Proof Local Sandbox

Why Binary Containers?

Storing raw JSON files (e.g., donors.json, grades.json, users.json) in local project directories introduces severe compliance risks if source code is accidentally pushed to public repositories. The BinaryCompiler ensures that all local data remains encrypted at rest.

The Cryptographic Pipeline

STAGE 1 / DERIVATION

Key Derivation (HKDF)

Derives a 32-byte AES key and a separate HMAC integrity key from your project API Key.

STAGE 2 / ENCRYPTION

AES-256-CBC Payload

Encrypts the JSON content payload with a randomly generated 16-byte initialization vector (IV).

STAGE 3 / SIGNATURE

HMAC-SHA256 Digest

Signs the entire prefix block (header + metadata + payload) and appends a 32-byte signature to the end.

STAGE 4 / DEFENSE

Constant-Time Verification

Compares signatures in constant time to prevent side-channel timing attacks.

Binary Layout Specification

Every .nx file is laid out as a contiguous byte stream:

ParameterTypeRequirementDescription
Magic Header4 Bytes (ASCII)OptionalThe ASCII string 'NEXS'. Identifies the file as a valid GN-Apex binary container.
Meta Length4 Bytes (UInt32BE)OptionalThe byte length of the unencrypted JSON metadata block.
Metadata BlockVariable (JSON)OptionalContains { version, compiledAt, projectId, schemaChecksum }.
Payload Length4 Bytes (UInt32BE)OptionalThe total byte length of the encrypted content block (IV + Ciphertext).
IV (Init Vector)16 Bytes (Raw)OptionalThe unique initialization vector generated for this file's AES-256-CBC cipher.
Encrypted CiphertextVariable (AES-256)OptionalThe AES-256-CBC encrypted JSON content payload.
HMAC Signature32 Bytes (SHA-256)OptionalCryptographic HMAC-SHA256 signature appended to the end of the file.

Constant-Time Tamper Verification

When the SDK reads a .nx file, it slices off the trailing 32 bytes and computes the expected HMAC:

DATA_INTEGRITY_VIOLATION
If a single byte of the file has been modified (via external edits, disk corruption, or a merge conflict), crypto.timingSafeEqual() fails, and the SDK aborts with a security violation.