Expand description
llmtxt-core: Portable primitives for the llmtxt content platform.
This crate is the single source of truth for compression, hashing,
signing, and encoding functions used by both the Rust (SignalDock)
and TypeScript (npm llmtxt via WASM) consumers.
§Features
wasm(default): Enableswasm-bindgenexports for JavaScript consumption. Disable withdefault-features = falsefor native-only usage.
§Native
All functions are available as regular Rust APIs regardless of features.
Structs§
- Diff
Result - Result of computing a line-based diff between two texts.
- Signed
UrlBuild Request - Input for generating a signed URL in native Rust consumers.
- Signed
UrlParams - Parameters extracted from a verified signed URL.
Enums§
- Verify
Error - Errors that can occur during signed URL verification.
Functions§
- apply_
patch - Apply a unified diff patch to an original string. Returns the updated string on success, or an error if the patch is invalid or fails to apply cleanly.
- calculate_
compression_ ratio - Calculate the compression ratio (original / compressed), rounded to 2 decimals.
Returns 1.0 when
compressed_sizeis 0. - calculate_
tokens - Estimate token count using the ~4 chars/token heuristic.
- compress
- Compress a UTF-8 string using zlib-wrapped deflate (RFC 1950).
- compute_
diff - Compute a line-based diff between two texts.
- compute_
org_ signature - Compute the HMAC-SHA256 signature for org-scoped signed URL parameters.
Includes
org_idin the HMAC payload for organization-level access control. Returns the first 32 hex characters (128 bits) by default. - compute_
org_ signature_ with_ length - Compute org-scoped HMAC-SHA256 signature with configurable output length.
- compute_
signature - Compute the HMAC-SHA256 signature for signed URL parameters.
Returns the first 16 hex characters of the digest (64 bits).
For longer signatures, use
compute_signature_with_length. - compute_
signature_ with_ length - Compute the HMAC-SHA256 signature with configurable output length.
- create_
patch - Create a unified diff patch representing the difference between
originalandmodified. - decode_
base62 - Decode a base62-encoded string back into an integer.
- decompress
- Decompress zlib-wrapped deflate bytes back to a UTF-8 string.
- derive_
signing_ key - Derive a per-agent signing key from their API key.
Uses
HMAC-SHA256(api_key, "llmtxt-signing"). - encode_
base62 - Encode a non-negative integer into a base62 string.
- generate_
id - Generate an 8-character base62 ID from a UUID v4.
- generate_
signed_ url - Generate a signed URL with an optional resource path prefix. Native Rust API only.
- hash_
content - Compute the SHA-256 hash of a UTF-8 string, returned as lowercase hex.
- is_
expired - Check whether a timestamp (milliseconds) has expired. Returns false for 0 (no expiration).
- reconstruct_
version - Apply a sequence of patches to base content, returning the content at the target version. This avoids N WASM boundary crossings by performing all patch applications in a single Rust call.
- reconstruct_
version_ native - Native-friendly version of
reconstruct_versionthat accepts a slice directly instead of JSON. Use this from Rust consumers; the JSON variant is for WASM callers. - squash_
patches - Apply all patches sequentially to base content, then produce a single unified diff from the original base to the final state.
- squash_
patches_ native - Native-friendly version of
squash_patchesthat accepts a slice directly. - text_
similarity - Compute character-level n-gram Jaccard similarity between two texts. Returns 0.0 (no overlap) to 1.0 (identical). Default n=3.
- text_
similarity_ ngram - Compute n-gram Jaccard similarity with configurable gram size.
- verify_
signed_ url - Verify a signed URL. Native Rust API only.