Programmatic API
All LODE operations are available as TypeScript functions.
loadLode(pathOrObj)
Load and validate a LODE schema.
import { loadLode } from "@stacknet/lode";
// From file path
const schema = loadLode("./model-layer-v1.lode");
// From object
const schema = loadLode({
schema: "lode",
version: 1,
name: "Example",
fields: [{ id: 1, name: "value", type: "string", required: true }],
});Returns: LodeSchema
Throws: On invalid schema (see Error Reference)
compile(source, schema)
Encode a source object into Vein binary.
import { compile } from "@stacknet/lode";
const vein: Uint8Array = compile(
{ name: "preview", isDefault: true, models: ["gpt-oss:20b"], defaultModel: "gpt-oss:20b" },
schema
);Parameters:
source: Record<string, any>— The object to encodeschema: LodeSchema— A validated schema
Returns: Uint8Array — The Vein binary payload
Throws: On missing required fields or type mismatches
decode(vein, schema)
Decode a Vein binary back into a plain object.
import { decode } from "@stacknet/lode";
const obj: Record<string, any> = decode(veinBytes, schema);Parameters:
vein: Uint8Array— Vein binary payloadschema: LodeSchema— A validated schema
Returns: Record<string, any> — The decoded object
Throws: On invalid magic, version mismatch, truncated data, or missing required fields
fingerprint(obj)
Compute a deterministic SHA-256 hash.
import { fingerprint } from "@stacknet/lode";
const hash: string = fingerprint({ name: "preview", isDefault: true });
// → "a3f8c2e9..." (64-char hex)Parameters:
obj: unknown— Any JavaScript value
Returns: string — Lowercase hex SHA-256 digest
verify(vein, expectedHash, schema)
Verify a Vein binary against a fingerprint.
import { verify } from "@stacknet/lode";
const ok: boolean = verify(veinBytes, "a3f8c2e9...", schema);Parameters:
vein: Uint8Array— Vein binary payloadexpectedHash: string— Expected SHA-256 hex digestschema: LodeSchema— A validated schema
Returns: boolean — true if the decoded object’s fingerprint matches
Never throws — Returns false on any error
Type Exports
import type { LodeSchema, LodeField, VeinHeader } from "@stacknet/lode";
import { TypeTag, TYPE_TAG_MAP } from "@stacknet/lode";check(value, schema) v0.2
Type-check a value. Returns LodeTypeIssue[] ({ path, message }, path is a JSON pointer); empty when the value conforms. assertConforms(value, schema) throws a LodeTypeError carrying the issues instead.
import { check } from "@stacknet/lode";
check({ weightBp: 0.5 }, schema);
// → [{ path: "/weightBp", message: "expected int, got non-integer number 0.5" }]canonicalJson(value, schema) v0.2
Type-check a value and return its typed canonical JSON string. canonicalize(value, schema) returns the same thing as a value.
typedFingerprint(value, schema) v0.2
SHA-256 hex of canonicalJson(value, schema). Unlike fingerprint, it keeps the order of list<T> fields.
import { typedFingerprint, versionedId } from "@stacknet/lode";
const fp = typedFingerprint(rules, schema);
versionedId("rules-v0", fp); // → "rules-v0@5a316e4bf6d7"versionedId(name, fp, length = 12) v0.2
Returns `${name}@${fp.slice(0, length)}`. length must be 8–64.
verify(vein, hash, schema) in v0.2
For v0.1 schemas verify compares against fingerprint (unchanged). For schemas that use v0.2 types it compares against typedFingerprint.