Skip to main content

Crate llmtxt_core

Crate llmtxt_core 

Source
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): Enables wasm-bindgen exports for JavaScript consumption. Disable with default-features = false for native-only usage.

§Native

All functions are available as regular Rust APIs regardless of features.

Structs§

DiffResult
Result of computing a line-based diff between two texts.
SignedUrlBuildRequest
Input for generating a signed URL in native Rust consumers.
SignedUrlParams
Parameters extracted from a verified signed URL.

Enums§

VerifyError
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_size is 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_id in 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 original and modified.
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_version that 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_patches that 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.