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
//! THE principal-set expansion: the ONE definition of a resolved caller's flat
//! authorization identity — `groups ∪ {eid} ∪ {user_id}`, empty components skipped,
//! default-deny (no identity ⇒ empty set ⇒ nothing matches).
//!
//! **Nicknames are NOT principals** (#38): display names are self-asserted and rewritable
//! (`set_nickname`, rename-by-fresh-invite), so nothing authz-bearing may key on them.
//! The device arm is the pre-rendered stable principal `eid:<hex>` — rendered by the ONE
//! sanctioned encoder, `mcpmesh_net::EndpointId::principal()` (callers pass the string;
//! this crate stays iroh-free).
//!
//! WHY THIS LIVES HERE: three enforcement sites consume this
//! expansion — the mesh service allow check (`mcpmesh-net::endpoint::caller_admits`), the
//! plugin-seam audience expansion (`service::peer_audiences`), and the blob-scope gate
//! (`node/src/blobs/provider.rs`). They live in crates with no other shared home:
//! `mcpmesh-net` must not pull the seam's tokio/rustix surface, and `mcpmesh-codec` is
//! wire-codec-only by charter. `mcpmesh-local-api`'s DEFAULT (feature-less) surface is the
//! family's dependency-free vocabulary crate — protocol types, serde only — so a pure
//! `principal_set` fn belongs on it, and `mcpmesh-net` takes a default-features-only dep
//! (types-only, no iroh/tokio cycle; local-api depends on nothing in the platform DAG).
//! One implementation, drift impossible.
use BTreeSet;
/// Expand a resolved peer identity into its flat principal set:
/// `groups ∪ {eid} ∪ {user_id}`. Borrowed — callers match `allow`/grant entries against it.
///
/// - `eid` is the PRE-RENDERED device principal (`eid:<hex>` of the AUTHENTICATED
/// endpoint id) — always present for a gate-resolved caller.
/// - `user_id` is the person's verified id (roster, or a pairing device→user binding);
/// `None` for an unbound pairing peer. Roster user_ids are bare handles; pairing ones
/// carry the `b64u:` prefix — both land verbatim.
/// - `groups` are bare roster group names.
/// - Empty strings are never principals (an absent value must not become a matchable "").
/// - An absent/empty identity yields the EMPTY set — default deny.