From 21240208b4b4942c2b1130931c0131e091e30df9 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Thu, 12 Nov 2026 20:28:23 -0600 Subject: [PATCH] pkgs/id crate split step 6b: extract id-directory (#4409) The directory cluster moves into a new crates/id-directory member: directory, directory_auth, directory_mail, directory_view (from id-worlds) and directory_log, invite, invites, seitan (from the facade). The facade and id-worlds re-export every module at its historical path, so no call site changed. Dependencies point one way down (design seam 10): id-directory depends on id-core (petname, hex, forgeries), id-caps (the WorldScopes vocabulary, moved in 6a), id-events (groups::Role) and id-sync (artifact, envelope_outbox) - never on id-worlds. The relationship inverts the other way: id-worlds now depends on id-directory, because WorldCore holds a Directory as its own persisted state (world_store opens/replays it beside the journal) - the petnames pattern, and the re-homing the id-worlds manifest already said step 6 owed. The ArtifactSink-for-Directory impl moves with the type (orphan rule) from session_host into directory.rs; session_host keeps the SessionHost-for-WorldHub impl. One widening: Directory::apply_replica_fact becomes pub (world/replica.rs calls it), and directory_view::level_name becomes pub ahead of step 6c. Behaviour-preserving throughout. --- pkgs/id/Cargo.lock | 30 ++++ pkgs/id/Cargo.toml | 7 +- pkgs/id/crates/id-directory/Cargo.toml | 130 ++++++++++++++++++ .../src/directory.rs | 39 ++++-- .../src/directory_auth.rs | 4 +- .../id-directory}/src/directory_log.rs | 4 +- .../src/directory_mail.rs | 2 +- .../src/directory_view.rs | 24 ++-- .../{ => crates/id-directory}/src/invite.rs | 2 +- .../id-directory}/src/invites/event.rs | 4 +- .../id-directory}/src/invites/invitation.rs | 0 .../id-directory}/src/invites/mod.rs | 0 pkgs/id/crates/id-directory/src/lib.rs | 29 ++++ .../id-directory}/src/seitan/accept.rs | 0 .../id-directory}/src/seitan/admit.rs | 0 .../id-directory}/src/seitan/derive.rs | 0 .../id-directory}/src/seitan/freshness.rs | 0 .../id-directory}/src/seitan/mod.rs | 0 .../id-directory}/src/seitan/tests.rs | 2 +- .../id-directory}/src/seitan/token.rs | 0 pkgs/id/crates/id-worlds/Cargo.toml | 1 + pkgs/id/crates/id-worlds/src/lib.rs | 8 +- pkgs/id/crates/id-worlds/src/session_host.rs | 31 +---- pkgs/id/src/lib.rs | 16 +-- 24 files changed, 266 insertions(+), 67 deletions(-) create mode 100644 pkgs/id/crates/id-directory/Cargo.toml rename pkgs/id/crates/{id-worlds => id-directory}/src/directory.rs (99%) rename pkgs/id/crates/{id-worlds => id-directory}/src/directory_auth.rs (99%) rename pkgs/id/{ => crates/id-directory}/src/directory_log.rs (99%) rename pkgs/id/crates/{id-worlds => id-directory}/src/directory_mail.rs (99%) rename pkgs/id/crates/{id-worlds => id-directory}/src/directory_view.rs (99%) rename pkgs/id/{ => crates/id-directory}/src/invite.rs (99%) rename pkgs/id/{ => crates/id-directory}/src/invites/event.rs (98%) rename pkgs/id/{ => crates/id-directory}/src/invites/invitation.rs (100%) rename pkgs/id/{ => crates/id-directory}/src/invites/mod.rs (100%) create mode 100644 pkgs/id/crates/id-directory/src/lib.rs rename pkgs/id/{ => crates/id-directory}/src/seitan/accept.rs (100%) rename pkgs/id/{ => crates/id-directory}/src/seitan/admit.rs (100%) rename pkgs/id/{ => crates/id-directory}/src/seitan/derive.rs (100%) rename pkgs/id/{ => crates/id-directory}/src/seitan/freshness.rs (100%) rename pkgs/id/{ => crates/id-directory}/src/seitan/mod.rs (100%) rename pkgs/id/{ => crates/id-directory}/src/seitan/tests.rs (99%) rename pkgs/id/{ => crates/id-directory}/src/seitan/token.rs (100%) diff --git a/pkgs/id/Cargo.lock b/pkgs/id/Cargo.lock index cae79b4514..80bb640e40 100644 --- a/pkgs/id/Cargo.lock +++ b/pkgs/id/Cargo.lock @@ -3903,6 +3903,7 @@ dependencies = [ "hmac 0.13.0", "id-caps", "id-core", + "id-directory", "id-events", "id-groups", "id-store", @@ -4001,6 +4002,34 @@ dependencies = [ "vt100", ] +[[package]] +name = "id-directory" +version = "0.1.0" +dependencies = [ + "anyhow", + "base64 0.22.1", + "crypto_secretbox", + "ed25519-dalek 3.0.0", + "hmac 0.13.0", + "id-caps", + "id-core", + "id-events", + "id-sync", + "iroh-tickets", + "libc", + "p2panda-core", + "proptest", + "rand 0.10.3", + "rmp-serde", + "scrypt", + "serde", + "serde_json", + "sha2 0.11.0", + "subtle", + "tempfile", + "tracing", +] + [[package]] name = "id-events" version = "0.1.0" @@ -4134,6 +4163,7 @@ dependencies = [ "futures-lite", "id-caps", "id-core", + "id-directory", "id-events", "id-groups", "id-store", diff --git a/pkgs/id/Cargo.toml b/pkgs/id/Cargo.toml index ea0067c34b..91fda036ca 100644 --- a/pkgs/id/Cargo.toml +++ b/pkgs/id/Cargo.toml @@ -16,14 +16,14 @@ categories = ["command-line-utilities", "network-programming"] # id-core sub-crate under crates/; this package is the workspace root. [workspace] -members = ["crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-worlds", "crates/id-native-shell"] +members = ["crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-worlds", "crates/id-directory", "crates/id-native-shell"] # The vendored crates stay OUT of the workspace: as path dependencies inside # this directory Cargo would otherwise treat them as members, and a member's # feature graph joins the lock resolve — p2panda-sync's `test_utils` feature # forwards to `p2panda-store/test_utils`, whose `sqlite` feature pulls sqlx # into Cargo.lock even though no build here enables it (see vendor/README.md). exclude = ["vendor/p2panda-sync", "vendor/p2panda-encryption"] -default-members = [".", "crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-worlds"] +default-members = [".", "crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-worlds", "crates/id-directory"] # ============================================================================= # Features @@ -86,6 +86,9 @@ id-groups = { path = "crates/id-groups", default-features = false } # Worlds-family modules extracted in step 5 of the crate split (#4408). # Re-exported at their historical crate:: paths in src/lib.rs. id-worlds = { path = "crates/id-worlds", default-features = false } +# Directory-family modules extracted in step 6b of the crate split +# (#4409). Re-exported at their historical crate:: paths in src/lib.rs. +id-directory = { path = "crates/id-directory", default-features = false } anyhow = "1" cbor-core = { version = "=0.10.1", features = ["serde"] } # Calendar arithmetic and the IANA time-zone database for the did-it tracker's diff --git a/pkgs/id/crates/id-directory/Cargo.toml b/pkgs/id/crates/id-directory/Cargo.toml new file mode 100644 index 0000000000..0ee42b9cbc --- /dev/null +++ b/pkgs/id/crates/id-directory/Cargo.toml @@ -0,0 +1,130 @@ +[package] +name = "id-directory" +version = "0.1.0" +edition = "2024" +rust-version = "1.96" +description = "Directory layer of the id crate: home-server directory, views, auth, mail, invites and seitan admission (pkgs/id crate split step 6b, #4409)" +license = "MIT OR Apache-2.0" + +# Step 6b of the pkgs/id crate split (#3447 umbrella, #4409): the +# directory cluster lives here. Dependencies per the design map plus +# the step-6a seam work: id-core (kernel: petname, hex, test +# forgeries), id-caps (the WorldScopes vocabulary), id-events (group +# roles), id-sync (artifacts and the envelope outbox). This crate +# must never depend on id-worlds; id-worlds depends on it, because +# WorldCore holds the Directory as its own persisted state. + +[features] +default = [] + +[dependencies] +anyhow = "1" +base64 = "0.22" +crypto_secretbox = "0.1" +ed25519-dalek = { version = "3", features = ["rand_core"] } +hmac = "0.13" +id-caps = { path = "../id-caps", default-features = false } +id-core = { path = "../id-core", default-features = false, features = [ + "world", +] } +id-events = { path = "../id-events", default-features = false } +id-sync = { path = "../id-sync", default-features = false } +iroh-tickets = "1" +libc = "0.2" +p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "da80c05b95269926bf58121cf6a2d3dd5ca41dfc" } +rand = "0.10" +rmp-serde = "1" +scrypt = "0.12" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +sha2 = "0.11" +subtle = "2" +tracing = "0.1" + +[dev-dependencies] +id-core = { path = "../id-core", default-features = false, features = [ + "test-utils", +] } +# The directory tests sign artifacts through the id-sync test seam +# (SignedArtifact::sign_unchecked), as the facade dev build did. +id-sync = { path = "../id-sync", default-features = false, features = [ + "test-utils", +] } +iroh = "1" +iroh-base = "1" +proptest = "1.12" +serde_bytes = "0.11" +tempfile = "3" + +[lints.rust] +unsafe_code = "warn" +rust_2018_idioms = { level = "warn", priority = -1 } +rust_2024_compatibility = { level = "warn", priority = -1 } +missing_debug_implementations = "warn" +missing_docs = "warn" +trivial_casts = "warn" +trivial_numeric_casts = "warn" +unused_lifetimes = "warn" +unused_qualifications = "warn" + +[lints.clippy] +all = { level = "warn", priority = -1 } +pedantic = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +cargo = { level = "warn", priority = -1 } +unwrap_used = "deny" +expect_used = "deny" +panic = "deny" +unimplemented = "deny" +todo = "deny" +dbg_macro = "deny" +print_stdout = "allow" +print_stderr = "allow" +clone_on_ref_ptr = "warn" +create_dir = "warn" +deref_by_slicing = "warn" +empty_structs_with_brackets = "warn" +filetype_is_file = "warn" +float_cmp_const = "warn" +fn_to_numeric_cast_any = "warn" +format_push_string = "warn" +get_unwrap = "warn" +if_then_some_else_none = "warn" +lossy_float_literal = "warn" +map_err_ignore = "warn" +mem_forget = "warn" +mixed_read_write_in_expression = "warn" +mutex_atomic = "warn" +rc_buffer = "warn" +rc_mutex = "warn" +redundant_type_annotations = "warn" +rest_pat_in_fully_bound_structs = "warn" +same_name_method = "warn" +self_named_module_files = "warn" +str_to_string = "warn" +string_add = "warn" +suspicious_xor_used_as_pow = "warn" +try_err = "warn" +undocumented_unsafe_blocks = "warn" +unnecessary_safety_comment = "warn" +unnecessary_safety_doc = "warn" +unnecessary_self_imports = "warn" +unneeded_field_pattern = "warn" +verbose_file_reads = "warn" +module_name_repetitions = "allow" +must_use_candidate = "allow" +missing_errors_doc = "allow" +missing_panics_doc = "allow" +redundant_pub_crate = "allow" +significant_drop_tightening = "allow" +option_if_let_else = "allow" +multiple_crate_versions = "allow" +cargo_common_metadata = "allow" +too_many_lines = "allow" +too_many_arguments = "allow" +fn_params_excessive_bools = "allow" +struct_excessive_bools = "allow" +cognitive_complexity = "allow" +future_not_send = "allow" +assert_is_empty = "allow" +chunks_exact_to_as_chunks = "allow" diff --git a/pkgs/id/crates/id-worlds/src/directory.rs b/pkgs/id/crates/id-directory/src/directory.rs similarity index 99% rename from pkgs/id/crates/id-worlds/src/directory.rs rename to pkgs/id/crates/id-directory/src/directory.rs index 9238b9db6a..3925536691 100644 --- a/pkgs/id/crates/id-worlds/src/directory.rs +++ b/pkgs/id/crates/id-directory/src/directory.rs @@ -17,11 +17,12 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use subtle::ConstantTimeEq as _; -use crate::artifact::{ - self, ArtifactLog, Document, FriendRemove, HomeDeclared, HomeServer, Kind, SignedArtifact, +use id_sync::artifact::{ + self, ArtifactLog, ArtifactSink, Document, FriendRemove, HomeDeclared, HomeServer, Kind, + SignedArtifact, Stored, Tag, }; -use crate::world::{WorldScopes, hex_encode}; +use {id_caps::world_scopes::WorldScopes, id_core::hex::hex_encode}; const KEY_DOMAIN: &[u8] = b"id-account-v1"; const MAX_NAME_CHARS: usize = 64; @@ -1084,7 +1085,7 @@ impl Directory { /// Directory facts a read-only replica needs for spectator /// authorization (F12.13 phase 4): everything - /// [`crate::world::WorldCore::effective_scopes`] consults for the given + /// [`WorldCore::effective_scopes`] consults for the given /// capability subjects — account ceilings (tiers and group grants) and /// the friendship graph — as entries the replica applies to an empty /// directory. The caller passes every account appearing in the @@ -1862,7 +1863,7 @@ impl Directory { /// to a read-only replica. It must use the same historical validation /// as replay, not new-write validation: an old group name containing a /// format character was valid when written and must remain loadable. - pub(crate) fn apply_replica_fact(&mut self, entry: &DirectoryEntry) -> Result<()> { + pub fn apply_replica_fact(&mut self, entry: &DirectoryEntry) -> Result<()> { self.apply_replay(entry) } @@ -2489,7 +2490,7 @@ fn clean_name_mode(name: &str, refuse_format: bool) -> Result { ); if refuse_format { ensure!( - !name.chars().any(crate::petname::is_format_char), + !name.chars().any(id_core::petname::is_format_char), "name must not contain format characters" ); } @@ -2512,7 +2513,7 @@ fn clean_description_mode(description: &str, refuse_format: bool) -> Result WorldScopes { WorldScopes::GUEST.union(WorldScopes::DELEGATE) @@ -4885,3 +4886,25 @@ mod tests { assert!(envelope.verify().is_err()); } } + +/// The `id-sync` artifact sink is the directory itself: the pull/apply +/// transfer writes artifacts straight into the directory's store. +/// This impl sat in `id-worlds`' `session_host` while the directory +/// lived there; the orphan rule puts it in the crate that owns +/// [`Directory`] (step 6b, #4409). +impl ArtifactSink for Directory { + fn receive_artifact(&mut self, artifact: &SignedArtifact) -> Result { + Directory::receive_artifact(self, artifact) + } + + fn receive_artifact_with_outcome( + &mut self, + artifact: &SignedArtifact, + ) -> Result<(Stored, Option)> { + Directory::receive_artifact_with_outcome(self, artifact) + } + + fn artifact_head_seq(&self, account: &str) -> u64 { + self.artifacts().head_seq(account) + } +} diff --git a/pkgs/id/crates/id-worlds/src/directory_auth.rs b/pkgs/id/crates/id-directory/src/directory_auth.rs similarity index 99% rename from pkgs/id/crates/id-worlds/src/directory_auth.rs rename to pkgs/id/crates/id-directory/src/directory_auth.rs index a5010c9102..8a10ede634 100644 --- a/pkgs/id/crates/id-worlds/src/directory_auth.rs +++ b/pkgs/id/crates/id-directory/src/directory_auth.rs @@ -17,7 +17,7 @@ use sha2::{Digest, Sha256}; use subtle::ConstantTimeEq as _; use crate::directory::{Refusal, normalize_key}; -use crate::world::hex_encode; +use id_core::hex::hex_encode; /// How long a session lasts after it is opened. pub const SESSION_TTL_MS: u64 = 12 * 60 * 60 * 1000; @@ -463,7 +463,7 @@ fn hex_bytes(text: &str) -> Option<[u8; N]> { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod tests { use super::*; - use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; + use id_core::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; fn now() -> u64 { 1_000_000_000_000 diff --git a/pkgs/id/src/directory_log.rs b/pkgs/id/crates/id-directory/src/directory_log.rs similarity index 99% rename from pkgs/id/src/directory_log.rs rename to pkgs/id/crates/id-directory/src/directory_log.rs index 99dbc62330..85f75434c4 100644 --- a/pkgs/id/src/directory_log.rs +++ b/pkgs/id/crates/id-directory/src/directory_log.rs @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use crate::directory::{Directory, DirectoryEntry, hex_to_array}; -use crate::world::hex_encode; +use id_core::hex::hex_encode; /// The order in which replicas apply records: Lamport counter, then author, then hash. pub type MergeKey = (u64, String, String); @@ -288,7 +288,7 @@ pub fn apply(directory: &mut Directory, log: &Log) -> Applied { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod tests { use super::*; - use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; + use id_core::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; struct Draw(u64); diff --git a/pkgs/id/crates/id-worlds/src/directory_mail.rs b/pkgs/id/crates/id-directory/src/directory_mail.rs similarity index 99% rename from pkgs/id/crates/id-worlds/src/directory_mail.rs rename to pkgs/id/crates/id-directory/src/directory_mail.rs index 12522c39f5..7997c010a0 100644 --- a/pkgs/id/crates/id-worlds/src/directory_mail.rs +++ b/pkgs/id/crates/id-directory/src/directory_mail.rs @@ -17,7 +17,7 @@ use std::time::{Duration, Instant}; use anyhow::{Context as _, Result, bail, ensure}; use rand::RngExt as _; -use crate::world::hex_encode; +use id_core::hex::hex_encode; /// One message to one address. #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/pkgs/id/crates/id-worlds/src/directory_view.rs b/pkgs/id/crates/id-directory/src/directory_view.rs similarity index 99% rename from pkgs/id/crates/id-worlds/src/directory_view.rs rename to pkgs/id/crates/id-directory/src/directory_view.rs index 1fcc6925e7..fd99a7c2e5 100644 --- a/pkgs/id/crates/id-worlds/src/directory_view.rs +++ b/pkgs/id/crates/id-directory/src/directory_view.rs @@ -9,16 +9,16 @@ use std::collections::BTreeMap; use anyhow::{Context, Result, anyhow, bail}; use serde::{Deserialize, Serialize}; -use crate::artifact::{SignedArtifact, Stored}; +use id_sync::artifact::{SignedArtifact, Stored}; use crate::directory::{ Actor, Directory, DirectoryEntry, Envelope, EnvelopeKind, Level, Member, Received, Refusal, normalize_email, normalize_key, }; use crate::directory_auth::{Caller, DirectoryAuth, Principal, Purpose, PurposeKind}; use crate::directory_mail::Mail; -use crate::envelope_outbox::{Entry, Finish, Outbox, Payload, check_target}; -use crate::petname::{Contact, Label, Petnames, labels}; -use crate::world::WorldScopes; +use id_sync::envelope_outbox::{Entry, Finish, Outbox, Payload, check_target}; +use id_core::petname::{Contact, Label, Petnames, labels}; +use id_caps::world_scopes::WorldScopes; /// Who is looking at the directory. #[derive(Clone, Debug, PartialEq, Eq)] @@ -1611,7 +1611,7 @@ fn scope_names(scopes: WorldScopes) -> Vec { .collect() } -pub(crate) const fn level_name(level: Level) -> &'static str { +pub const fn level_name(level: Level) -> &'static str { match level { Level::Access => "access", Level::Read => "read", @@ -1752,8 +1752,8 @@ pub fn render_text(view: &DirectoryView) -> String { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod tests { use super::*; - use crate::artifact::HomeServer; - use crate::envelope_outbox::{MAX_FINISHED_ENTRIES, Outcome}; + use id_sync::artifact::HomeServer; + use id_sync::envelope_outbox::{MAX_FINISHED_ENTRIES, Outcome}; use ed25519_dalek::SigningKey; fn node() -> String { @@ -1919,7 +1919,7 @@ mod tests { .record( &id, 0, - crate::envelope_outbox::Outcome::Refused("no such account".to_owned()), + id_sync::envelope_outbox::Outcome::Refused("no such account".to_owned()), ) .unwrap(); assert_eq!( @@ -2182,7 +2182,7 @@ mod tests { fn a_keyed_account_adds_keys_and_emails_and_signs_in_by_email() { let mut s = sample(); let key = - crate::world::hex_encode(&SigningKey::from_bytes(&[5; 32]).verifying_key().to_bytes()); + id_core::hex::hex_encode(&SigningKey::from_bytes(&[5; 32]).verifying_key().to_bytes()); let signed = Caller { key: Some(key.clone()), ..Caller::default() @@ -2208,7 +2208,7 @@ mod tests { ..Caller::default() }; let other = - crate::world::hex_encode(&SigningKey::from_bytes(&[6; 32]).verifying_key().to_bytes()); + id_core::hex::hex_encode(&SigningKey::from_bytes(&[6; 32]).verifying_key().to_bytes()); let refused = run( &mut s.directory, &mut Petnames::new(), @@ -2536,7 +2536,7 @@ mod tests { } fn keyed(directory: &mut Directory, seed: u8, name: &str) -> String { - let key = crate::world::hex_encode( + let key = id_core::hex::hex_encode( &SigningKey::from_bytes(&[seed; 32]) .verifying_key() .to_bytes(), @@ -2693,7 +2693,7 @@ mod tests { )); let stranger = - crate::world::hex_encode(&SigningKey::from_bytes(&[9; 32]).verifying_key().to_bytes()); + id_core::hex::hex_encode(&SigningKey::from_bytes(&[9; 32]).verifying_key().to_bytes()); let unknown = petname_act( &mut directory, &mut petnames, diff --git a/pkgs/id/src/invite.rs b/pkgs/id/crates/id-directory/src/invite.rs similarity index 99% rename from pkgs/id/src/invite.rs rename to pkgs/id/crates/id-directory/src/invite.rs index 63c53c4013..b310e0856c 100644 --- a/pkgs/id/src/invite.rs +++ b/pkgs/id/crates/id-directory/src/invite.rs @@ -40,7 +40,7 @@ impl Invite { "an invite name cannot contain control characters" ); ensure!( - !name.chars().any(crate::is_format_char), + !name.chars().any(id_core::is_format_char), "an invite name cannot contain format characters" ); let name = name.trim(); diff --git a/pkgs/id/src/invites/event.rs b/pkgs/id/crates/id-directory/src/invites/event.rs similarity index 98% rename from pkgs/id/src/invites/event.rs rename to pkgs/id/crates/id-directory/src/invites/event.rs index ed5beccf46..76c4ff0c1f 100644 --- a/pkgs/id/src/invites/event.rs +++ b/pkgs/id/crates/id-directory/src/invites/event.rs @@ -12,7 +12,7 @@ use ed25519_dalek::{Signature, Signer as _, SigningKey, VerifyingKey}; use iroh_tickets::{Ticket as _, endpoint::EndpointTicket}; use p2panda_core::Hash; -use crate::groups::Role; +use id_events::groups::Role; const DOMAIN: &[u8] = b"id-invite/v1/event"; const TICKET_DOMAIN: &[u8] = b"id-invite/v1/ticket"; @@ -179,7 +179,7 @@ pub(super) fn ticket_digest(ticket: &EndpointTicket) -> [u8; 32] { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod tests { use super::*; - use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; + use id_core::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; fn body_for(key: &SigningKey) -> InviteBody { InviteBody { diff --git a/pkgs/id/src/invites/invitation.rs b/pkgs/id/crates/id-directory/src/invites/invitation.rs similarity index 100% rename from pkgs/id/src/invites/invitation.rs rename to pkgs/id/crates/id-directory/src/invites/invitation.rs diff --git a/pkgs/id/src/invites/mod.rs b/pkgs/id/crates/id-directory/src/invites/mod.rs similarity index 100% rename from pkgs/id/src/invites/mod.rs rename to pkgs/id/crates/id-directory/src/invites/mod.rs diff --git a/pkgs/id/crates/id-directory/src/lib.rs b/pkgs/id/crates/id-directory/src/lib.rs new file mode 100644 index 0000000000..8d13cbba85 --- /dev/null +++ b/pkgs/id/crates/id-directory/src/lib.rs @@ -0,0 +1,29 @@ +//! The directory layer of the `id` crate: the home-server directory, +//! its views, auth and mail surfaces, the directory log, invitations +//! and the seitan admission protocol. +//! +//! Step 6b of the pkgs/id crate split (#3447 umbrella, #4409): the +//! directory cluster moved here from `id-worlds` (`directory`, +//! `directory_auth`, `directory_mail`, `directory_view`) and from the +//! facade (`directory_log`, `invite`, `invites`, `seitan`). The facade +//! and `id-worlds` both re-export these modules at their historical +//! paths, so no call site outside the moved modules changed. +//! +//! Dependencies point one way down, per the design map: this crate +//! depends on `id-core`, `id-caps`, `id-events` and `id-sync` — never +//! on `id-worlds`. Its world-presenting surface is the +//! [`id_caps::world_scopes::WorldScopes`] vocabulary (step 6a moved +//! it into `id-caps` for exactly this reason). The relationship runs +//! the other way: `id-worlds` depends on this crate, because +//! `WorldCore` holds a [`directory::Directory`] as its own persisted +//! state (the world store opens and replays it beside the journal) — +//! the same pattern by which `WorldCore` holds `id-core` state types. + +pub mod directory; +pub mod directory_auth; +pub mod directory_log; +pub mod directory_mail; +pub mod directory_view; +pub mod invite; +pub mod invites; +pub mod seitan; diff --git a/pkgs/id/src/seitan/accept.rs b/pkgs/id/crates/id-directory/src/seitan/accept.rs similarity index 100% rename from pkgs/id/src/seitan/accept.rs rename to pkgs/id/crates/id-directory/src/seitan/accept.rs diff --git a/pkgs/id/src/seitan/admit.rs b/pkgs/id/crates/id-directory/src/seitan/admit.rs similarity index 100% rename from pkgs/id/src/seitan/admit.rs rename to pkgs/id/crates/id-directory/src/seitan/admit.rs diff --git a/pkgs/id/src/seitan/derive.rs b/pkgs/id/crates/id-directory/src/seitan/derive.rs similarity index 100% rename from pkgs/id/src/seitan/derive.rs rename to pkgs/id/crates/id-directory/src/seitan/derive.rs diff --git a/pkgs/id/src/seitan/freshness.rs b/pkgs/id/crates/id-directory/src/seitan/freshness.rs similarity index 100% rename from pkgs/id/src/seitan/freshness.rs rename to pkgs/id/crates/id-directory/src/seitan/freshness.rs diff --git a/pkgs/id/src/seitan/mod.rs b/pkgs/id/crates/id-directory/src/seitan/mod.rs similarity index 100% rename from pkgs/id/src/seitan/mod.rs rename to pkgs/id/crates/id-directory/src/seitan/mod.rs diff --git a/pkgs/id/src/seitan/tests.rs b/pkgs/id/crates/id-directory/src/seitan/tests.rs similarity index 99% rename from pkgs/id/src/seitan/tests.rs rename to pkgs/id/crates/id-directory/src/seitan/tests.rs index 390b60618a..d2d5f9c82f 100644 --- a/pkgs/id/src/seitan/tests.rs +++ b/pkgs/id/crates/id-directory/src/seitan/tests.rs @@ -16,7 +16,7 @@ use super::derive; use super::freshness::{DEFAULT_WINDOW, Freshness}; use super::token::{ALPHABET, Token, TokenError}; -use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; +use id_core::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s}; const VECTOR_TOKEN: &str = "4uywza+b3cga7rd6yc"; const VECTOR_INVITE_ID: &str = "6303ec43bd61d21edb95a433faf06227"; diff --git a/pkgs/id/src/seitan/token.rs b/pkgs/id/crates/id-directory/src/seitan/token.rs similarity index 100% rename from pkgs/id/src/seitan/token.rs rename to pkgs/id/crates/id-directory/src/seitan/token.rs diff --git a/pkgs/id/crates/id-worlds/Cargo.toml b/pkgs/id/crates/id-worlds/Cargo.toml index 8efb02f282..ea5735a9e7 100644 --- a/pkgs/id/crates/id-worlds/Cargo.toml +++ b/pkgs/id/crates/id-worlds/Cargo.toml @@ -53,6 +53,7 @@ id-caps = { path = "../id-caps", default-features = false } id-core = { path = "../id-core", default-features = false, features = [ "world", ] } +id-directory = { path = "../id-directory", default-features = false } id-events = { path = "../id-events", default-features = false } id-groups = { path = "../id-groups", default-features = false } id-store = { path = "../id-store", default-features = false } diff --git a/pkgs/id/crates/id-worlds/src/lib.rs b/pkgs/id/crates/id-worlds/src/lib.rs index 0ca128e012..896aaece9d 100644 --- a/pkgs/id/crates/id-worlds/src/lib.rs +++ b/pkgs/id/crates/id-worlds/src/lib.rs @@ -39,10 +39,6 @@ //! facade; they name the lower crates that own those modules. pub mod blob_gate; -pub mod directory; -pub mod directory_auth; -pub mod directory_mail; -pub mod directory_view; pub mod groups; #[cfg(feature = "sandbox")] pub mod sandbox; @@ -67,6 +63,10 @@ pub mod world_ssh; pub mod world_store; pub mod world_terminal; +pub use id_directory::directory; +pub use id_directory::directory_auth; +pub use id_directory::directory_mail; +pub use id_directory::directory_view; pub use id_sync::artifact; pub use id_core::abuse; pub use id_store::chain; diff --git a/pkgs/id/crates/id-worlds/src/session_host.rs b/pkgs/id/crates/id-worlds/src/session_host.rs index 3d2e5c907f..332ae60100 100644 --- a/pkgs/id/crates/id-worlds/src/session_host.rs +++ b/pkgs/id/crates/id-worlds/src/session_host.rs @@ -1,16 +1,16 @@ -//! The facade's side of the `id-sync` host seam (seam 9 of the crate +//! The hub's side of the `id-sync` host seam (seam 9 of the crate //! split, #4406): the world hub runs each wire request as a directory -//! action under its lease, and the directory itself is the artifact -//! sink the pull/apply transfer writes to. The protocols live in -//! `id_sync`; this is their composition with the hub and directory, -//! which stay in the facade until steps 5-6. +//! action under its lease. The protocols live in `id_sync`; this is +//! their composition with the hub. (The other half of the seam, the +//! `ArtifactSink` impl for the directory, lives in `id-directory` +//! with the `Directory` type since step 6b, #4409.) use anyhow::Result; -use id_sync::artifact::{ArtifactSink, SignedArtifact, Stored}; +use id_sync::artifact::{SignedArtifact, Stored}; use id_sync::envelope::Envelope; use id_sync::host::{Availability, EnvelopeReceived, SessionHost}; -use crate::directory::{Directory, Received}; +use crate::directory::Received; use crate::directory_auth::Caller; use crate::directory_view::DirectoryAction; use crate::world_hub::WorldHub; @@ -71,20 +71,3 @@ impl SessionHost for WorldHub { )) } } - -impl ArtifactSink for Directory { - fn receive_artifact(&mut self, artifact: &SignedArtifact) -> Result { - Directory::receive_artifact(self, artifact) - } - - fn receive_artifact_with_outcome( - &mut self, - artifact: &SignedArtifact, - ) -> Result<(Stored, Option)> { - Directory::receive_artifact_with_outcome(self, artifact) - } - - fn artifact_head_seq(&self, account: &str) -> u64 { - self.artifacts().head_seq(account) - } -} diff --git a/pkgs/id/src/lib.rs b/pkgs/id/src/lib.rs index 997536e436..dd09d48e64 100644 --- a/pkgs/id/src/lib.rs +++ b/pkgs/id/src/lib.rs @@ -225,17 +225,17 @@ pub mod currency; pub mod currency_poc; pub use id_sync::dht; #[cfg(feature = "world")] -pub use id_worlds::directory; +pub use id_directory::directory; #[cfg(feature = "world")] -pub use id_worlds::directory_auth; +pub use id_directory::directory_auth; #[cfg(feature = "world")] -pub mod directory_log; +pub use id_directory::directory_log; #[cfg(feature = "world")] pub mod keyset; #[cfg(feature = "world")] -pub use id_worlds::directory_mail; +pub use id_directory::directory_mail; #[cfg(feature = "world")] -pub use id_worlds::directory_view; +pub use id_directory::directory_view; pub use id_core::discovery; pub mod didit; pub use id_store::documents; @@ -257,8 +257,8 @@ pub mod helpers; pub mod hosted_binding; pub use id_events::idset; pub mod input_framing; -pub mod invite; -pub mod invites; +pub use id_directory::invite; +pub use id_directory::invites; pub use id_store::issuer_rotation; pub(crate) mod key_envelope; pub(crate) mod seed_phrase; @@ -289,7 +289,7 @@ pub use id_worlds::sandbox; pub use id_worlds::world_dev; pub use id_store::search; #[cfg(feature = "world")] -pub mod seitan; +pub use id_directory::seitan; #[cfg(feature = "world")] pub mod server_config; pub use id_store::session_checkpoint;