🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@czap/canonical

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@czap/canonical - npm Package Compare versions

Comparing version
0.3.1
to
0.4.0
+50
README.md
# @czap/canonical
The sync bytes kernel — deterministic CBOR encoding, FNV-1a content labels, and addressed digests, with no Effect runtime and no `@czap/core` graph behind it.
> You usually don't install this directly — `@czap/core` re-exports these surfaces at its public boundary, so app authors who already depend on core get them for free. Reach for `@czap/canonical` standalone only when core is too heavy: an upstream factory or WASM-side path that needs stable bytes without pulling the full graph.
## Install
```bash
pnpm add @czap/core # brings @czap/canonical with it
```
If you do need the kernel standalone, install it directly: `pnpm add @czap/canonical`. Its only third-party dependency is `@noble/hashes` (for the sha256/blake3 digests) — no Effect, no peer setup.
## 30 seconds
```ts
import { CanonicalCbor, AddressedDigest, fnv1a } from '@czap/canonical';
// Key-permuted objects encode to byte-identical output (RFC 8949 §4.2.1).
const bytes = CanonicalCbor.encode({ title: 'hello', n: 42 });
const digest = AddressedDigest.of(bytes);
console.log(digest.display_id); // 'fnv1a:xxxxxxxx' — sync identity label
console.log(digest.integrity_digest); // 'sha256:...' — cryptographic digest
console.log(digest.algo); // 'sha256' (pass 'blake3' for the blake3 digest)
console.log(fnv1a('any string')); // 'fnv1a:xxxxxxxx'
```
`CanonicalCbor.encode` produces a stable `Uint8Array` for any JSON-shaped value; `decode` is its strict inverse, accepting only the canonical subset the encoder emits. `AddressedDigest.of` pairs a sync FNV-1a `display_id` with a cryptographic `integrity_digest` over the very same bytes, so identity and integrity can never disagree.
## Where it sits
This package is a standalone leaf — it carries no `@czap/core`, no Effect, and no spine imports, which is exactly why upstream and WASM-side code can address content without dragging in the full graph. `@czap/core` re-anchors `ContentAddress` / `IntegrityDigest` to spine brands at its own boundary (ADR-0012); here they are kept local. See the [package surfaces map](https://github.com/heyoub/LiteShip/blob/main/PACKAGE-SURFACES.md) for the full layout.
## If encoding throws
Only the JSON-shaped value subset encodes: numbers, strings, booleans, `null`, `Uint8Array`, arrays, and plain objects. Functions, symbols, `bigint`, `Map`, `Set`, and `Date` raise an `UnsupportedError` rather than emit ambiguous bytes — determinism is the whole point. Plain-object properties whose value is `undefined` are skipped, matching JSON semantics.
## Docs
- [Getting started](https://github.com/heyoub/LiteShip/blob/main/GETTING-STARTED.md)
- [ADR-0013 — the canonical package](https://github.com/heyoub/LiteShip/blob/main/docs/adr/0013-canonical-package.md) — why the bytes kernel is a standalone leaf
- [Glossary](https://github.com/heyoub/LiteShip/blob/main/GLOSSARY.md) — the vocabulary used above
- [API reference](https://github.com/heyoub/LiteShip/tree/main/docs/api/canonical/src/) — generated from source
---
Part of [LiteShip](https://github.com/heyoub/LiteShip#readme) — powered by the CZAP engine (Content-Zoned Adaptive Projection), distributed as `@czap/*` packages.
+17
-2

@@ -8,2 +8,7 @@ /**

*
* The constructors are VALIDATING smart constructors (parse-don't-validate):
* each throws `ValidationError` on input that does not match the brand's
* real runtime shape, so a branded value is a proof of that shape. `@czap/error`
* is a zero-dep foundational package, so importing it here introduces no cycle.
*
* @module

@@ -15,6 +20,16 @@ */

export type IntegrityDigest = `sha256:${string}` | `blake3:${string}`;
/** Wrap a plain string as a {@link ContentAddress}. */
/** Type guard: `s` is a syntactically valid {@link ContentAddress}. */
export declare const isContentAddress: (s: string) => s is ContentAddress;
/** Type guard: `s` is a syntactically valid {@link IntegrityDigest}. */
export declare const isIntegrityDigest: (s: string) => s is IntegrityDigest;
/**
* Parse a plain string into a {@link ContentAddress}.
* @throws `ValidationError` when `value` is not `fnv1a:` + 8 lowercase hex.
*/
export declare const ContentAddress: (value: string) => ContentAddress;
/** Wrap a plain string as an {@link IntegrityDigest}. */
/**
* Parse a plain string into an {@link IntegrityDigest}.
* @throws `ValidationError` when `value` is not `sha256:`/`blake3:` + 64 lowercase hex.
*/
export declare const IntegrityDigest: (value: string) => IntegrityDigest;
//# sourceMappingURL=brands.d.ts.map
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"brands.d.ts","sourceRoot":"","sources":["../src/brands.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,SAAS,MAAM,EAAE,CAAC;AAE/C,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,UAAU,MAAM,EAAE,GAAG,UAAU,MAAM,EAAE,CAAC;AAEtE,uDAAuD;AACvD,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,cAAyC,CAAC;AAEzF,yDAAyD;AACzD,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,eAA2C,CAAC"}
{"version":3,"file":"brands.d.ts","sourceRoot":"","sources":["../src/brands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,SAAS,MAAM,EAAE,CAAC;AAE/C,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,UAAU,MAAM,EAAE,GAAG,UAAU,MAAM,EAAE,CAAC;AAgBtE,uEAAuE;AACvE,eAAO,MAAM,gBAAgB,GAAI,GAAG,MAAM,KAAG,CAAC,IAAI,cAA4C,CAAC;AAE/F,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,GAAI,GAAG,MAAM,KAAG,CAAC,IAAI,eAA8C,CAAC;AAElG;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,cAK9C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,eAQ/C,CAAC"}

@@ -8,8 +8,46 @@ /**

*
* The constructors are VALIDATING smart constructors (parse-don't-validate):
* each throws `ValidationError` on input that does not match the brand's
* real runtime shape, so a branded value is a proof of that shape. `@czap/error`
* is a zero-dep foundational package, so importing it here introduces no cycle.
*
* @module
*/
/** Wrap a plain string as a {@link ContentAddress}. */
export const ContentAddress = (value) => value;
/** Wrap a plain string as an {@link IntegrityDigest}. */
export const IntegrityDigest = (value) => value;
import { ValidationError } from '@czap/error';
/**
* A {@link ContentAddress} is the `fnv1a:` prefix followed by exactly 8 lowercase
* hex digits — the full width of the FNV-1a 32-bit output ({@link fnv.ts} pads to
* 8 via `(h >>> 0).toString(16).padStart(8, '0')`).
*/
const CONTENT_ADDRESS_RE = /^fnv1a:[0-9a-f]{8}$/;
/**
* An {@link IntegrityDigest} is `sha256:` or `blake3:` followed by exactly 64
* lowercase hex digits — the full width of a 256-bit cryptographic digest
* (ADR-0011). Only these two algorithms are sanctioned.
*/
const INTEGRITY_DIGEST_RE = /^(?:sha256|blake3):[0-9a-f]{64}$/;
/** Type guard: `s` is a syntactically valid {@link ContentAddress}. */
export const isContentAddress = (s) => CONTENT_ADDRESS_RE.test(s);
/** Type guard: `s` is a syntactically valid {@link IntegrityDigest}. */
export const isIntegrityDigest = (s) => INTEGRITY_DIGEST_RE.test(s);
/**
* Parse a plain string into a {@link ContentAddress}.
* @throws `ValidationError` when `value` is not `fnv1a:` + 8 lowercase hex.
*/
export const ContentAddress = (value) => {
if (!isContentAddress(value)) {
throw ValidationError('ContentAddress', `expected fnv1a:<8 lowercase hex>, got ${JSON.stringify(value)}`);
}
return value;
};
/**
* Parse a plain string into an {@link IntegrityDigest}.
* @throws `ValidationError` when `value` is not `sha256:`/`blake3:` + 64 lowercase hex.
*/
export const IntegrityDigest = (value) => {
if (!isIntegrityDigest(value)) {
throw ValidationError('IntegrityDigest', `expected (sha256|blake3):<64 lowercase hex>, got ${JSON.stringify(value)}`);
}
return value;
};
//# sourceMappingURL=brands.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"brands.js","sourceRoot":"","sources":["../src/brands.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAkB,EAAE,CAAC,KAAuB,CAAC;A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ything else with a typed
* {@link CborDecodeError}. This is the reader the encoder's bytes have
* lacked: a persisted DocumentGraph (content-addressed via the encoder)
* `ParseError` (source `'cbor'`, `code` = the reason discriminant,
* `offset` = the byte position). This is the reader the encoder's bytes
* have lacked: a persisted DocumentGraph (content-addressed via the encoder)
* can now be re-read without a third-party CBOR library that would accept

@@ -21,3 +22,3 @@ * non-canonical encodings.

*
* Rejected (typed `CborDecodeError`):
* Rejected (typed `ParseError`, `code` carries the reason):
* - non-shortest integer/length encodings (`'non_canonical'`).

@@ -33,11 +34,2 @@ * - float16 (ai=25) and float32 (ai=26) in major 7 (`'non_canonical'`).

*/
/** Reason a {@link CborDecodeError} was raised. */
export type CborDecodeErrorReason = 'non_canonical' | 'malformed' | 'unexpected_eof';
/** Typed error for any input outside the canonical subset. */
export declare class CborDecodeError extends Error {
readonly reason: CborDecodeErrorReason;
/** Byte offset where decoding failed (best effort). */
readonly offset: number;
constructor(reason: CborDecodeErrorReason, message: string, offset: number);
}
/**

@@ -48,7 +40,8 @@ * Decode a canonical CBOR byte sequence produced by {@link CanonicalCbor.encode}.

* encoder emits (non-shortest forms, float16/32, indefinite lengths,
* out-of-order map keys, trailing bytes) raises a typed {@link CborDecodeError}.
* out-of-order map keys, trailing bytes) raises a typed `ParseError`
* (source `'cbor'`, `code` = the reason discriminant).
*
* @throws {CborDecodeError}
* @throws A `@czap/error` `ParseError` (`source` `'cbor'`).
*/
export declare function decode(bytes: Uint8Array): unknown;
//# sourceMappingURL=cbor-decode.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"cbor-decode.d.ts","sourceRoot":"","sources":["../src/cbor-decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,mDAAmD;AACnD,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,CAAC;AAErF,8DAA8D;AAC9D,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,uDAAuD;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBACZ,MAAM,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM3E;AAkOD;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAUjD"}
{"version":3,"file":"cbor-decode.d.ts","sourceRoot":"","sources":["../src/cbor-decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAuOH;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAUjD"}

@@ -6,4 +6,5 @@ /**

* encoder (`./cbor.ts`) emits, and rejects everything else with a typed
* {@link CborDecodeError}. This is the reader the encoder's bytes have
* lacked: a persisted DocumentGraph (content-addressed via the encoder)
* `ParseError` (source `'cbor'`, `code` = the reason discriminant,
* `offset` = the byte position). This is the reader the encoder's bytes
* have lacked: a persisted DocumentGraph (content-addressed via the encoder)
* can now be re-read without a third-party CBOR library that would accept

@@ -21,3 +22,3 @@ * non-canonical encodings.

*
* Rejected (typed `CborDecodeError`):
* Rejected (typed `ParseError`, `code` carries the reason):
* - non-shortest integer/length encodings (`'non_canonical'`).

@@ -33,13 +34,6 @@ * - float16 (ai=25) and float32 (ai=26) in major 7 (`'non_canonical'`).

*/
/** Typed error for any input outside the canonical subset. */
export class CborDecodeError extends Error {
reason;
/** Byte offset where decoding failed (best effort). */
offset;
constructor(reason, message, offset) {
super(`CborDecodeError[${reason}] @${offset}: ${message}`);
this.name = 'CborDecodeError';
this.reason = reason;
this.offset = offset;
}
import { ParseError } from '@czap/error';
/** Raise a canonical-CBOR `ParseError`: `code` = reason, `offset` = byte position. */
function fail(reason, message, offset) {
throw ParseError('cbor', message, { code: reason, offset });
}

@@ -66,3 +60,3 @@ const textDecoder = new TextDecoder('utf-8', { fatal: true });

if (this.pos + n > this.bytes.length) {
throw new CborDecodeError('unexpected_eof', `need ${n} byte(s) but only ${this.bytes.length - this.pos} remain`, this.pos);
fail('unexpected_eof', `need ${n} byte(s) but only ${this.bytes.length - this.pos} remain`, this.pos);
}

@@ -95,3 +89,3 @@ }

if (v < 24) {
throw new CborDecodeError('non_canonical', `1-byte argument ${v} should be inlined`, headOffset);
fail('non_canonical', `1-byte argument ${v} should be inlined`, headOffset);
}

@@ -105,3 +99,3 @@ return v;

if (v < 0x100) {
throw new CborDecodeError('non_canonical', `2-byte argument ${v} should use a shorter head`, headOffset);
fail('non_canonical', `2-byte argument ${v} should use a shorter head`, headOffset);
}

@@ -117,3 +111,3 @@ return v;

if (v < 0x10000) {
throw new CborDecodeError('non_canonical', `4-byte argument ${v} should use a shorter head`, headOffset);
fail('non_canonical', `4-byte argument ${v} should use a shorter head`, headOffset);
}

@@ -127,6 +121,6 @@ return v;

if (hi === 0 && lo < 0x100000000) {
throw new CborDecodeError('non_canonical', `8-byte argument ${v} should use a shorter head`, headOffset);
fail('non_canonical', `8-byte argument ${v} should use a shorter head`, headOffset);
}
if (!Number.isSafeInteger(v)) {
throw new CborDecodeError('malformed', `integer ${v} exceeds the encoder's safe-integer range`, headOffset);
fail('malformed', `integer ${v} exceeds the encoder's safe-integer range`, headOffset);
}

@@ -137,5 +131,5 @@ return v;

if (ai === 31) {
throw new CborDecodeError('non_canonical', 'indefinite-length items are not canonical', headOffset);
fail('non_canonical', 'indefinite-length items are not canonical', headOffset);
}
throw new CborDecodeError('malformed', `reserved additional-info value ${ai}`, headOffset);
fail('malformed', `reserved additional-info value ${ai}`, headOffset);
}

@@ -161,3 +155,3 @@ function decodeFloat64(r) {

if (!Number.isSafeInteger(v)) {
throw new CborDecodeError('malformed', `negative integer ${v} out of safe range`, headOffset);
fail('malformed', `negative integer ${v} out of safe range`, headOffset);
}

@@ -180,3 +174,3 @@ return v;

catch {
throw new CborDecodeError('malformed', 'invalid UTF-8 in text string', headOffset);
fail('malformed', 'invalid UTF-8 in text string', headOffset);
}

@@ -203,3 +197,3 @@ }

if (keyHead === undefined || keyHead >> 5 !== 3) {
throw new CborDecodeError('malformed', 'map keys must be text strings', keyOffset);
fail('malformed', 'map keys must be text strings', keyOffset);
}

@@ -212,6 +206,6 @@ const keyStart = r.pos;

if (cmp > 0) {
throw new CborDecodeError('non_canonical', 'map keys are not in canonical byte order', keyOffset);
fail('non_canonical', 'map keys are not in canonical byte order', keyOffset);
}
if (cmp === 0) {
throw new CborDecodeError('non_canonical', 'duplicate map key', keyOffset);
fail('non_canonical', 'duplicate map key', keyOffset);
}

@@ -246,14 +240,14 @@ }

case 25:
throw new CborDecodeError('non_canonical', 'float16 is not in the canonical subset', headOffset);
return fail('non_canonical', 'float16 is not in the canonical subset', headOffset);
case 26:
throw new CborDecodeError('non_canonical', 'float32 is not in the canonical subset', headOffset);
return fail('non_canonical', 'float32 is not in the canonical subset', headOffset);
case 27:
return decodeFloat64(r);
case 31:
throw new CborDecodeError('non_canonical', 'indefinite-length break is not canonical', headOffset);
return fail('non_canonical', 'indefinite-length break is not canonical', headOffset);
case 23:
// `undefined` (simple 23) is never emitted — encoder coerces it to null.
throw new CborDecodeError('non_canonical', 'simple value `undefined` is not in the canonical subset', headOffset);
return fail('non_canonical', 'simple value `undefined` is not in the canonical subset', headOffset);
default:
throw new CborDecodeError('malformed', `unsupported simple/float value (ai=${ai})`, headOffset);
return fail('malformed', `unsupported simple/float value (ai=${ai})`, headOffset);
}

@@ -263,3 +257,3 @@ }

// Major 6 (tags) is not part of the encoder's output.
throw new CborDecodeError('malformed', `unsupported major type ${major}`, headOffset);
return fail('malformed', `unsupported major type ${major}`, headOffset);
}

@@ -272,9 +266,10 @@ }

* encoder emits (non-shortest forms, float16/32, indefinite lengths,
* out-of-order map keys, trailing bytes) raises a typed {@link CborDecodeError}.
* out-of-order map keys, trailing bytes) raises a typed `ParseError`
* (source `'cbor'`, `code` = the reason discriminant).
*
* @throws {CborDecodeError}
* @throws A `@czap/error` `ParseError` (`source` `'cbor'`).
*/
export function decode(bytes) {
if (!(bytes instanceof Uint8Array)) {
throw new CborDecodeError('malformed', 'input must be a Uint8Array', 0);
fail('malformed', 'input must be a Uint8Array', 0);
}

@@ -284,3 +279,3 @@ const r = new Reader(bytes);

if (r.pos !== bytes.length) {
throw new CborDecodeError('malformed', `trailing ${bytes.length - r.pos} byte(s) after top-level item`, r.pos);
fail('malformed', `trailing ${bytes.length - r.pos} byte(s) after top-level item`, r.pos);
}

@@ -287,0 +282,0 @@ return value;

@@ -1,1 +0,1 @@

{"version":3,"file":"cbor-decode.js","sourceRoot":"","sources":["../src/cbor-decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAKH,8DAA8D;AAC9D,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAAwB;IACvC,uDAAuD;IAC9C,MAAM,CAAS;IACxB,YAAY,MAA6B,EAAE,OAAe,EAAE,MAAc;QACxE,KAAK,CAAC,mBAAmB,MAAM,MAAM,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE9D,SAAS,YAAY,CAAC,CAAa,EAAE,CAAa;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC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GAuBG;AAqKH,2DAA2D;AAC3D,eAAO,MAAM,aAAa;6BA1BF,OAAO,KAAG,UAAU;CA0Ba,CAAC;AAE1D,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,wDAAwD;IACxD,KAAY,OAAO,GAAG,UAAU,CAAC;CAClC"}
{"version":3,"file":"cbor.d.ts","sourceRoot":"","sources":["../src/cbor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA0KH,2DAA2D;AAC3D,eAAO,MAAM,aAAa;6BA1BF,OAAO,KAAG,UAAU;CA0Ba,CAAC;AAE1D,MAAM,CAAC,OAAO,WAAW,aAAa,CAAC;IACrC,wDAAwD;IACxD,KAAY,OAAO,GAAG,UAAU,CAAC;CAClC"}

@@ -25,2 +25,3 @@ /**

*/
import { UnsupportedError, ValidationError } from '@czap/error';
const MAJOR_UNSIGNED = 0 << 5;

@@ -41,3 +42,3 @@ const MAJOR_NEGATIVE = 1 << 5;

if (value < 0 || !Number.isFinite(value)) {
throw new RangeError(`CanonicalCbor: head argument must be a non-negative finite integer, got ${value}`);
throw ValidationError('CanonicalCbor.encodeHead', `head argument must be a non-negative finite integer, got ${value}`);
}

@@ -175,3 +176,3 @@ if (value < 24) {

}
throw new TypeError(`CanonicalCbor: unsupported value type ${typeof value}`);
throw UnsupportedError('CBOR value type', `${typeof value} cannot be canonically encoded`);
};

@@ -178,0 +179,0 @@ /** Canonical CBOR encoder namespace (ADR-0001 pattern). */

@@ -1,1 +0,1 @@

{"version":3,"file":"cbor.js","sourceRoot":"","sources":["../src/cbor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC;AAC9B,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC;AAC9B,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3B,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,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AC;QAC1C,OAAO,IAAI,UAAU,CAAC,CAAC,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,IAAI,UAAU,CAAC,CAAC,YAAY,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,YAAY,CAAC,KAAgC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,GAAG,OAAO,KAAK,gCAAgC,CAAC,CAAC;AAC7F,CAAC,CAAC;AAEF,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,MAAM,EAAE,OAAO,EAAW,CAAC"}

@@ -7,4 +7,3 @@ /**

export { CanonicalCbor } from './cbor.js';
export { decode, CborDecodeError } from './cbor-decode.js';
export type { CborDecodeErrorReason } from './cbor-decode.js';
export { decode } from './cbor-decode.js';
export { ContentAddress, IntegrityDigest } from './brands.js';

@@ -11,0 +10,0 @@ export { fnv1a, fnv1aBytes } from './fnv.js';

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC3D,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}

@@ -7,3 +7,3 @@ /**

export { CanonicalCbor } from './cbor.js';
export { decode, CborDecodeError } from './cbor-decode.js';
export { decode } from './cbor-decode.js';
export { ContentAddress, IntegrityDigest } from './brands.js';

@@ -10,0 +10,0 @@ export { fnv1a, fnv1aBytes } from './fnv.js';

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
{
"name": "@czap/canonical",
"version": "0.3.1",
"description": "Self-contained canonical bytes kernel — deterministic CBOR, FNV-1a, and sync digests",
"version": "0.4.0",
"description": "Self-contained bytes kernel: RFC 8949 §4.2.1 CBOR, FNV-1a labels, sync `AddressedDigest` (no Effect/spine in-package)",
"license": "MIT",

@@ -38,3 +38,4 @@ "author": "Eassa Ayoub <eassa@heyoub.dev>",

"dependencies": {
"@noble/hashes": "^1.8.0"
"@noble/hashes": "^1.8.0",
"@czap/error": "0.4.0"
},

@@ -41,0 +42,0 @@ "engines": {

@@ -8,5 +8,12 @@ /**

*
* The constructors are VALIDATING smart constructors (parse-don't-validate):
* each throws `ValidationError` on input that does not match the brand's
* real runtime shape, so a branded value is a proof of that shape. `@czap/error`
* is a zero-dep foundational package, so importing it here introduces no cycle.
*
* @module
*/
import { ValidationError } from '@czap/error';
/** Content-addressed hash. Format: `fnv1a:XXXXXXXX` (8 hex digits). */

@@ -18,6 +25,45 @@ export type ContentAddress = `fnv1a:${string}`;

/** Wrap a plain string as a {@link ContentAddress}. */
export const ContentAddress = (value: string): ContentAddress => value as ContentAddress;
/**
* A {@link ContentAddress} is the `fnv1a:` prefix followed by exactly 8 lowercase
* hex digits — the full width of the FNV-1a 32-bit output ({@link fnv.ts} pads to
* 8 via `(h >>> 0).toString(16).padStart(8, '0')`).
*/
const CONTENT_ADDRESS_RE = /^fnv1a:[0-9a-f]{8}$/;
/** Wrap a plain string as an {@link IntegrityDigest}. */
export const IntegrityDigest = (value: string): IntegrityDigest => value as IntegrityDigest;
/**
* An {@link IntegrityDigest} is `sha256:` or `blake3:` followed by exactly 64
* lowercase hex digits — the full width of a 256-bit cryptographic digest
* (ADR-0011). Only these two algorithms are sanctioned.
*/
const INTEGRITY_DIGEST_RE = /^(?:sha256|blake3):[0-9a-f]{64}$/;
/** Type guard: `s` is a syntactically valid {@link ContentAddress}. */
export const isContentAddress = (s: string): s is ContentAddress => CONTENT_ADDRESS_RE.test(s);
/** Type guard: `s` is a syntactically valid {@link IntegrityDigest}. */
export const isIntegrityDigest = (s: string): s is IntegrityDigest => INTEGRITY_DIGEST_RE.test(s);
/**
* Parse a plain string into a {@link ContentAddress}.
* @throws `ValidationError` when `value` is not `fnv1a:` + 8 lowercase hex.
*/
export const ContentAddress = (value: string): ContentAddress => {
if (!isContentAddress(value)) {
throw ValidationError('ContentAddress', `expected fnv1a:<8 lowercase hex>, got ${JSON.stringify(value)}`);
}
return value;
};
/**
* Parse a plain string into an {@link IntegrityDigest}.
* @throws `ValidationError` when `value` is not `sha256:`/`blake3:` + 64 lowercase hex.
*/
export const IntegrityDigest = (value: string): IntegrityDigest => {
if (!isIntegrityDigest(value)) {
throw ValidationError(
'IntegrityDigest',
`expected (sha256|blake3):<64 lowercase hex>, got ${JSON.stringify(value)}`,
);
}
return value;
};

@@ -6,4 +6,5 @@ /**

* encoder (`./cbor.ts`) emits, and rejects everything else with a typed
* {@link CborDecodeError}. This is the reader the encoder's bytes have
* lacked: a persisted DocumentGraph (content-addressed via the encoder)
* `ParseError` (source `'cbor'`, `code` = the reason discriminant,
* `offset` = the byte position). This is the reader the encoder's bytes
* have lacked: a persisted DocumentGraph (content-addressed via the encoder)
* can now be re-read without a third-party CBOR library that would accept

@@ -21,3 +22,3 @@ * non-canonical encodings.

*
* Rejected (typed `CborDecodeError`):
* Rejected (typed `ParseError`, `code` carries the reason):
* - non-shortest integer/length encodings (`'non_canonical'`).

@@ -34,16 +35,13 @@ * - float16 (ai=25) and float32 (ai=26) in major 7 (`'non_canonical'`).

/** Reason a {@link CborDecodeError} was raised. */
export type CborDecodeErrorReason = 'non_canonical' | 'malformed' | 'unexpected_eof';
import { ParseError } from '@czap/error';
/** Typed error for any input outside the canonical subset. */
export class CborDecodeError extends Error {
readonly reason: CborDecodeErrorReason;
/** Byte offset where decoding failed (best effort). */
readonly offset: number;
constructor(reason: CborDecodeErrorReason, message: string, offset: number) {
super(`CborDecodeError[${reason}] @${offset}: ${message}`);
this.name = 'CborDecodeError';
this.reason = reason;
this.offset = offset;
}
/**
* The reason a canonical-CBOR `ParseError` was raised. Carried in the
* error's `code` field; kept local to constrain the value at every throw site.
*/
type CborDecodeErrorReason = 'non_canonical' | 'malformed' | 'unexpected_eof';
/** Raise a canonical-CBOR `ParseError`: `code` = reason, `offset` = byte position. */
function fail(reason: CborDecodeErrorReason, message: string, offset: number): never {
throw ParseError('cbor', message, { code: reason, offset });
}

@@ -73,7 +71,3 @@

if (this.pos + n > this.bytes.length) {
throw new CborDecodeError(
'unexpected_eof',
`need ${n} byte(s) but only ${this.bytes.length - this.pos} remain`,
this.pos,
);
fail('unexpected_eof', `need ${n} byte(s) but only ${this.bytes.length - this.pos} remain`, this.pos);
}

@@ -109,3 +103,3 @@ }

if (v < 24) {
throw new CborDecodeError('non_canonical', `1-byte argument ${v} should be inlined`, headOffset);
fail('non_canonical', `1-byte argument ${v} should be inlined`, headOffset);
}

@@ -119,3 +113,3 @@ return v;

if (v < 0x100) {
throw new CborDecodeError('non_canonical', `2-byte argument ${v} should use a shorter head`, headOffset);
fail('non_canonical', `2-byte argument ${v} should use a shorter head`, headOffset);
}

@@ -131,3 +125,3 @@ return v;

if (v < 0x10000) {
throw new CborDecodeError('non_canonical', `4-byte argument ${v} should use a shorter head`, headOffset);
fail('non_canonical', `4-byte argument ${v} should use a shorter head`, headOffset);
}

@@ -141,6 +135,6 @@ return v;

if (hi === 0 && lo < 0x100000000) {
throw new CborDecodeError('non_canonical', `8-byte argument ${v} should use a shorter head`, headOffset);
fail('non_canonical', `8-byte argument ${v} should use a shorter head`, headOffset);
}
if (!Number.isSafeInteger(v)) {
throw new CborDecodeError('malformed', `integer ${v} exceeds the encoder's safe-integer range`, headOffset);
fail('malformed', `integer ${v} exceeds the encoder's safe-integer range`, headOffset);
}

@@ -151,5 +145,5 @@ return v;

if (ai === 31) {
throw new CborDecodeError('non_canonical', 'indefinite-length items are not canonical', headOffset);
fail('non_canonical', 'indefinite-length items are not canonical', headOffset);
}
throw new CborDecodeError('malformed', `reserved additional-info value ${ai}`, headOffset);
fail('malformed', `reserved additional-info value ${ai}`, headOffset);
}

@@ -178,3 +172,3 @@

if (!Number.isSafeInteger(v)) {
throw new CborDecodeError('malformed', `negative integer ${v} out of safe range`, headOffset);
fail('malformed', `negative integer ${v} out of safe range`, headOffset);
}

@@ -196,3 +190,3 @@ return v;

} catch {
throw new CborDecodeError('malformed', 'invalid UTF-8 in text string', headOffset);
fail('malformed', 'invalid UTF-8 in text string', headOffset);
}

@@ -219,3 +213,3 @@ }

if (keyHead === undefined || keyHead >> 5 !== 3) {
throw new CborDecodeError('malformed', 'map keys must be text strings', keyOffset);
fail('malformed', 'map keys must be text strings', keyOffset);
}

@@ -228,6 +222,6 @@ const keyStart = r.pos;

if (cmp > 0) {
throw new CborDecodeError('non_canonical', 'map keys are not in canonical byte order', keyOffset);
fail('non_canonical', 'map keys are not in canonical byte order', keyOffset);
}
if (cmp === 0) {
throw new CborDecodeError('non_canonical', 'duplicate map key', keyOffset);
fail('non_canonical', 'duplicate map key', keyOffset);
}

@@ -261,18 +255,14 @@ }

case 25:
throw new CborDecodeError('non_canonical', 'float16 is not in the canonical subset', headOffset);
return fail('non_canonical', 'float16 is not in the canonical subset', headOffset);
case 26:
throw new CborDecodeError('non_canonical', 'float32 is not in the canonical subset', headOffset);
return fail('non_canonical', 'float32 is not in the canonical subset', headOffset);
case 27:
return decodeFloat64(r);
case 31:
throw new CborDecodeError('non_canonical', 'indefinite-length break is not canonical', headOffset);
return fail('non_canonical', 'indefinite-length break is not canonical', headOffset);
case 23:
// `undefined` (simple 23) is never emitted — encoder coerces it to null.
throw new CborDecodeError(
'non_canonical',
'simple value `undefined` is not in the canonical subset',
headOffset,
);
return fail('non_canonical', 'simple value `undefined` is not in the canonical subset', headOffset);
default:
throw new CborDecodeError('malformed', `unsupported simple/float value (ai=${ai})`, headOffset);
return fail('malformed', `unsupported simple/float value (ai=${ai})`, headOffset);
}

@@ -282,3 +272,3 @@ }

// Major 6 (tags) is not part of the encoder's output.
throw new CborDecodeError('malformed', `unsupported major type ${major}`, headOffset);
return fail('malformed', `unsupported major type ${major}`, headOffset);
}

@@ -292,9 +282,10 @@ }

* encoder emits (non-shortest forms, float16/32, indefinite lengths,
* out-of-order map keys, trailing bytes) raises a typed {@link CborDecodeError}.
* out-of-order map keys, trailing bytes) raises a typed `ParseError`
* (source `'cbor'`, `code` = the reason discriminant).
*
* @throws {CborDecodeError}
* @throws A `@czap/error` `ParseError` (`source` `'cbor'`).
*/
export function decode(bytes: Uint8Array): unknown {
if (!(bytes instanceof Uint8Array)) {
throw new CborDecodeError('malformed', 'input must be a Uint8Array', 0);
fail('malformed', 'input must be a Uint8Array', 0);
}

@@ -304,5 +295,5 @@ const r = new Reader(bytes);

if (r.pos !== bytes.length) {
throw new CborDecodeError('malformed', `trailing ${bytes.length - r.pos} byte(s) after top-level item`, r.pos);
fail('malformed', `trailing ${bytes.length - r.pos} byte(s) after top-level item`, r.pos);
}
return value;
}

@@ -26,2 +26,4 @@ /**

import { UnsupportedError, ValidationError } from '@czap/error';
const MAJOR_UNSIGNED = 0 << 5;

@@ -45,3 +47,6 @@ const MAJOR_NEGATIVE = 1 << 5;

if (value < 0 || !Number.isFinite(value)) {
throw new RangeError(`CanonicalCbor: head argument must be a non-negative finite integer, got ${value}`);
throw ValidationError(
'CanonicalCbor.encodeHead',
`head argument must be a non-negative finite integer, got ${value}`,
);
}

@@ -188,3 +193,3 @@ if (value < 24) {

}
throw new TypeError(`CanonicalCbor: unsupported value type ${typeof value}`);
throw UnsupportedError('CBOR value type', `${typeof value} cannot be canonically encoded`);
};

@@ -191,0 +196,0 @@

@@ -8,6 +8,5 @@ /**

export { CanonicalCbor } from './cbor.js';
export { decode, CborDecodeError } from './cbor-decode.js';
export type { CborDecodeErrorReason } from './cbor-decode.js';
export { decode } from './cbor-decode.js';
export { ContentAddress, IntegrityDigest } from './brands.js';
export { fnv1a, fnv1aBytes } from './fnv.js';
export { AddressedDigest, addressedDigestOf } from './addressed-digest.js';