1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! DIG URN parsing — a thin wrapper over the canonical [`dig_urn_protocol::DigUrn`].
//!
//! Grammar (canonical; pinned by the `dig-urn-protocol` frozen conformance corpus):
//!
//! ```text
//! urn:dig:chia:<store_id>[:<root>]/<resource_key>[?salt=<hex>]
//! ```
//!
//! * `<store_id>` — 64 hex chars, the singleton launcher id (store identity).
//! * `:<root>` — OPTIONAL 64 hex chars pinning one on-chain generation. Omit for
//! the root-independent form. The root is the trust anchor for inclusion
//! verification only; it is NOT a key input (retrieval/decryption keys are
//! root-independent).
//! * `<resource_key>` — the path within the store (e.g. `img/logo.png`). Empty
//! resolves to the §8.5 default view `index.html`.
//! * `?salt=<hex>` — OPTIONAL out-of-band secret salt for a PRIVATE store.
//!
//! ## The source of truth, and where its guarantee stops
//!
//! [`dig_urn_protocol::DigUrn`] is the single source of truth for the scheme *within this
//! crate*: this module adds only the resolver-facing conveniences and reimplements no
//! parsing or key derivation. So every caller of this crate maps a given URN to an
//! identical store id, root, resource key and wire key — callers cannot skew from each
//! other. That guarantee stops at the crate boundary: it binds code that calls here, and
//! says nothing about a parser that does not.
//!
//! Those callers today are the Rust crate (`dig-node-service`) and the wasm/npm package
//! `@dignetwork/dig-urn-resolver` (consumed by `dig-web-resolver`). The remaining
//! TypeScript surfaces — `dig-sdk`, the Chrome extension, and hub.dig.net — parse URNs
//! with their own implementations and consume neither package, so the ecosystem currently
//! runs several independent parsers with at least one measured key-derivation divergence
//! between them. Converging those surfaces onto this crate is the intent and is tracked as
//! `dig_ecosystem#2725` / `#2753`; until it lands, cross-surface agreement is a property to
//! verify against the conformance corpus, not one to assume. Extend this crate (and the
//! wasm package it publishes) rather than adding another parser.
//!
//! ## The wire key is `content_key`, never `retrieval_key`
//!
//! The ecosystem's on-wire lookup key (what the resolver sends and the node indexes as
//! `retrieval_key`) is `SHA-256(canonical_rootless())` — root-INDEPENDENT so the key is
//! stable across generations. In `dig-urn-protocol` that value is
//! [`DigUrn::content_key`](dig_urn_protocol::DigUrn::content_key). Its
//! [`retrieval_key`](dig_urn_protocol::DigUrn::retrieval_key) is a DIFFERENT, root-PINNED
//! hash. Hence [`ParsedUrn::retrieval_key_hex`] maps to `content_key_hex` — mapping it to
//! `retrieval_key_hex` would silently break every root-pinned read.
use crate;
use DigUrn;
/// A parsed DIG URN, retaining the pieces the resolver needs.