Skip to main content

Crate dig_urn_resolver

Crate dig_urn_resolver 

Source
Expand description

§dig-urn-resolver

Resolve a DIG URN to its data through the protocol, node-first.

Given a urn:dig:chia:<store_id>[:<root>]/<resource_key>[?salt=<hex>], this crate returns the resource’s bytes + content type, following the canonical §5.3 ladder — explicit override > dig.local > localhost:9778 > rpc.dig.net — and using the first tier that responds:

  • node tier (GET /s/<storeId>[:<root>]/<path>) — a local dig-node decrypts
    • verifies server-side under a loopback trust boundary and returns plaintext.
  • rpc tier (dig.getContent) — a blind fetch of opaque ciphertext + inclusion proofs from the untrusted public gateway, VERIFIED against the URN’s PINNED root and decrypted client-side (fail-closed). The trust root is NEVER taken from the gateway; a rootless URN is rejected on this tier.

§Reuse, not reimplementation

All read-crypto (URN canonicalization + retrieval-key derivation, merkle inclusion verify, AES-256-GCM-SIV open) is digstore_core’s — the same functions the browser read-crypto and the on-chain crates share — so this crate can never skew from the canonical crypto. It adds only the ladder, the injected transport, content-type derivation, fail-closed assembly, and the wasm glue.

§Outcomes

A resolve returns Result<ResolveOutcome, ResolveError> — three distinct outcomes, never conflated:

  • ResolveOutcome::Success — verified, decrypted content.
  • ResolveOutcome::IntegrityFailure — bytes were fetched but failed merkle/ decrypt verification (tampered / decoy / wrong root). A hard, fail-CLOSED SECURITY outcome — the unverified bytes are NEVER returned. resolveObjectUrl renders a branded “Integrity Verification Failed” page, never the bytes.
  • ResolveOutcome::Unreachable — every tier was down; nothing fetched. A friendly, retryable “connect a node” page.

A malformed URN, a not-found resource, and a reachable rpc protocol error are hard ResolveErrors.

§First consumer

Sage wallet NFT images: an NFT data-uri that is a root-pinned DIG URN → resolveObjectUrl(urn) (wasm) → an object URL usable as an <img src>, working with no dig-node running (rpc fallback) and faster when a node is present.

Re-exports§

pub use error::ResolveError;
pub use error::Result;
pub use ladder::Endpoint;
pub use ladder::EndpointKind;
pub use ladder::DIG_LOCAL_BASE;
pub use ladder::DIG_NODE_PORT;
pub use ladder::LOCALHOST_BASE;
pub use ladder::RPC_DEFAULT_BASE;
pub use pages::DEFAULT_CONNECT_URL;
pub use resolver::ResolveOptions;
pub use resolver::ResolveOutcome;
pub use resolver::ResolvedData;
pub use resolver::Resolver;
pub use transport::HttpResponse;
pub use transport::HttpTransport;
pub use transport::TransportError;
pub use urn::ParsedUrn;

Modules§

cache
Response caching — an ADDITIVE layer in front of resolve that NEVER weakens fail-closed. URNs are content-addressed → immutable → cacheable.
content_type
Deriving a resource’s MIME type — from its path extension, with a magic-byte sniff as a fallback for extensionless resources.
crypto
The rpc-path read-crypto — a thin orchestration over the canonical dig_urn_protocol::verify contract, backed by digstore_core primitives.
error
The resolver’s error taxonomy.
images
Branded error IMAGES for the <img src> path ([crate::wasm::DigNetwork::resolve_image_url]).
ladder
The §5.3 node-first connection ladder — the first reusable packaging of the canonical resolution order for third-party embedding.
native
The native runtime surface: a reqwest HTTP transport plus convenience entry points (resolve, resolve_with, resolve_blocking) that wire it up.
node
The node read path — GET {base}/s/<storeId>[:<root>]/<resourceKey>.
pages
Branded HTML documents for the two non-success outcomes, so a consuming webview can render something meaningful instead of a crash.
resolver
The resolver — orchestrates URN → data over the §5.3 node-first ladder.
rpc
The rpc read path — the blind fetch over the UNTRUSTED public gateway.
transport
The injected HTTP transport — the one seam between the resolver’s protocol logic and the runtime’s networking.
urn
DIG URN parsing — a thin wrapper over the canonical dig_urn_protocol::DigUrn.

Functions§

version
The crate version (matches Cargo.toml), for compatibility checks.