Overview
JavaScript Implementation Overview
The JavaScript implementation of Strata provides a fully deterministic, specification-compliant runtime for encoding, decoding, hashing, and parsing Strata data.
It is not a convenience wrapper. It is a first-class, law-bound implementation that must match Rust byte-for-byte.
Package name: @emagjby/strata-js
Status: Parity implementation (v0.3.x)
Design goals
The JavaScript implementation exists to prove and enforce:
Cross-language determinism
Canonical encoding stability
Identical hashing semantics
Explicit failure behavior
Vector-driven correctness
JavaScript is treated as a hostile environment by default. Precision loss, implicit coercions, and runtime magic are actively rejected.
Scope of the implementation
The JS implementation includes:
Strata Core Binary encoder
Strata Core Binary decoder
Deterministic hashing (BLAKE3-256)
Strata Text (
.st) lexer and parserCanonical map ordering
Structured error model
CLI with stable exit semantics
Golden vector enforcement
Everything required to round-trip .st → .scb → .hash deterministically.
Runtime requirements
Node.js 20+
ES2022
Native BigInt support
UTF-8 compliant TextEncoder / TextDecoder
No browser shims. No polyfills. No transpiled runtime hacks.
Integer strategy (BigInt-first)
JavaScript numbers are not allowed.
All Strata integers are represented as bigint.
Rules enforced at runtime:
Any attempt to construct an
IntfromnumberthrowsAll varint logic operates on
bigintOverflow is explicitly detected and rejected
This guarantees parity with Rust i64 semantics.
Architecture overview
High-level module responsibilities:
encode.tsCanonical encoder for Strata Core Binarydecode.tsStrict, offset-aware decoder with structured errorshash.tsBLAKE3-256 hashing over canonical bytesparser.tsRecursive descent parser for Strata Textlexer.tsTokenization with span tracking and strict literalsvalue.ts/value_factory.tsImmutable Value model and constructorscli.tsProduction-grade CLI with deterministic behavior__tests__/Golden vectors, negative cases, parity enforcement
Each module has a single responsibility. No cross-layer leakage is allowed.
Canonical authority
The JavaScript implementation does not define truth.
Truth comes from:
Golden vectors
Northstar documents
Canonical rules
JS code must conform. If JS disagrees, JS is wrong.
Error philosophy
Errors are values, not strings.
All failures include:
Error kind
Byte offset (for decode)
Line and column (for parse)
There is:
No panic on user input
No silent recovery
No guesswork
Failure is part of the contract.
CLI parity
The JavaScript CLI mirrors the Rust CLI exactly:
Commands:
compile
decode
hash
fmt
Exit codes:
0 success
1 invalid input
2 I/O failure
100 internal error
Output formats and semantics are intentionally boring and stable.
Golden vector enforcement
JS directly consumes /vectors from the repository root.
Rules:
Vectors are not copied
Vectors are not transformed
Vectors are law
Tests assert:
Byte-for-byte encoding
Hash equality
Exact error kind and offset
Any failure blocks release.
What this implementation is not
The JavaScript implementation is not:
A schema system
A JSON replacement
A flexible serializer
A forgiving parser
A browser-first library
It is a correctness engine.
Mental model
Think of @emagjby/strata-js as:
A verifier
A canonical executor
A hostile-environment proof
A legal witness to determinism
If Rust and JavaScript agree, Strata is real.
If they ever disagree, Strata has failed.
Summary
The JavaScript implementation exists to answer one question:
Can Strata survive JavaScript?
If the answer is yes, it can survive anywhere.
That is why this implementation exists. That is why it is strict. That is why it is boring.
And that is why it matters.
Last updated
Was this helpful?