/** * A carrier codec fault, carrying a stable `code` (`carrier/malformed`, `carrier/bad-hex`, * `carrier/bad-sha256`, `carrier/no-byte-form`, `carrier/bad-byte-length`). * * Compare the `code`, never the message: messages interpolate the offending value and change freely, * and the conformance corpus pins codes for exactly that reason. Note what this class does NOT signal — * an unrecognised LCP §8.2 `type` is ignored (the decoder answers `undefined`), so a thrown * `CarrierError` always means the carrier was structurally corrupt, never merely unfamiliar. */ export declare class CarrierError extends Error { readonly code: string; constructor(code: string, message: string); } /** The LCP §8.2 carrier `type` registry (open; unknown types are ignored on decode). */ export type CarrierType = "sha256" | "ipfs" | "ar" | "url"; /** The four `type` values this codec recognises. The LCP §8.2 registry is OPEN, so this is what the * reference implementation understands today, not a closed set a conforming carrier may not exceed — * a `type` outside it is ignored on decode rather than rejected. */ export declare const KNOWN_CARRIER_TYPES: readonly CarrierType[]; /** Narrow an arbitrary value to a {@link CarrierType}. Answers on the four types in * {@link KNOWN_CARRIER_TYPES}, so a `false` means "this codec does not handle it", not "invalid". */ export declare function isKnownCarrierType(value: unknown): value is CarrierType; /** A decoded LCP carrier reference: a LCP §8.2 `type` and its `value`. */ export interface LegalContextRef { readonly type: CarrierType; readonly value: string; } /** The structured-JSON carrier object (LCP §8.1 shape b). */ export interface LegalContextCarrier { readonly legalContext: { readonly type: string; readonly value: string; }; } /** The raw structural result of parsing an `lcp:{type}:{value}` string, before the LCP §8.2 registry. */ export interface ParsedLcpString { readonly type: string; readonly value: string; } /** The raw-byte carrier's hex convention: 0x-prefixed (distinct from the kernel's bare sha256Hex). */ export declare function bytesToHex(bytes: Uint8Array): string; /** Decode 0x-prefixed hex to bytes. The `0x` prefix is REQUIRED and must be lowercase — `0X…` throws * `carrier/bad-hex`, which is the trap when a caller has upper-cased a whole atrHash string. The hex * DIGITS themselves may be either case. */ export declare function hexToBytes(hex: string): Uint8Array; /** Encode a reference as the `lcp:{type}:{value}` string carrier (LCP §8.1 shape a). A `sha256` value is * emitted lowercase per §2.5 whatever case the caller supplied; every other type is emitted verbatim, * because folding a url or a base58 CID would name a different document. */ export declare function encodeLegalContextString(ref: LegalContextRef): string; /** Parse the STRUCTURE per the LCP §8.1 parse rule (no registry consulted). Split on the first colon for * the namespace, the second for the type; the value keeps every later colon (URLs). Returns undefined * when not `lcp:`-prefixed; throws (carrier/malformed) when `lcp:`-prefixed but structurally corrupt. */ export declare function parseLcpString(input: string): ParsedLcpString | undefined; /** Decode an `lcp:` string, narrowed to the LCP §8.2 registry (unknown type → undefined, ignored). */ export declare function decodeLegalContextString(input: string): LegalContextRef | undefined; /** Encode a reference as the structured-JSON carrier (LCP §8.1 shape b), for protocol fields that hold an * object rather than a string. Same §2.5 lowercase-on-emit rule as the string carrier. */ export declare function encodeLegalContextJson(ref: LegalContextRef): LegalContextCarrier; /** Decode the structured-JSON carrier. Absent/malformed carrier → undefined; a recognized type with a * present-but-empty value is a CORRUPT carrier and throws (consistent with the string decoder). */ export declare function decodeLegalContextJson(carrier: unknown): LegalContextRef | undefined; /** Encode as the raw-byte carrier (32 atrHash bytes). Only `sha256` has a fixed-width byte form. */ export declare function encodeLegalContextBytes(ref: LegalContextRef): Uint8Array; /** Decode exactly 32 atrHash bytes into a `sha256` ref. A wrong length is a corrupt carrier (fail loud). */ export declare function decodeLegalContextBytes(bytes: Uint8Array): LegalContextRef; /** A carrier operation by name — the language-neutral surface the conformance `carrier` class drives * (and binding-core's own vector tests). `decode*` map undefined (ignored/absent) to null so the * result is JSON-representable; `encodeBytes` returns 0x-hex so bytes compare as JSON. */ export type CarrierOp = { op: "parseString"; arg: string; } | { op: "decodeString"; arg: string; } | { op: "decodeJson"; arg: unknown; } | { op: "decodeBytes"; arg: string; } | { op: "encodeString"; arg: LegalContextRef; } | { op: "encodeJson"; arg: LegalContextRef; } | { op: "encodeBytes"; arg: LegalContextRef; } | { op: "isKnownType"; arg: unknown; }; /** Execute one {@link CarrierOp} and return a JSON-representable result. This is the codec's * language-neutral entry point — a conformance runner in any language drives the same eight operations * through it. Faults still THROW a {@link CarrierError}; only the "ignored/absent" answer is mapped, to * `null`. */ export declare function carrierOp(req: CarrierOp): unknown; //# sourceMappingURL=carrier.d.ts.map