Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pkgs/id/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pkgs/id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
130 changes: 130 additions & 0 deletions pkgs/id/crates/id-directory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -2489,7 +2490,7 @@ fn clean_name_mode(name: &str, refuse_format: bool) -> Result<String> {
);
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"
);
}
Expand All @@ -2512,7 +2513,7 @@ fn clean_description_mode(description: &str, refuse_format: bool) -> Result<Stri
);
if refuse_format {
ensure!(
!description.chars().any(crate::petname::is_format_char),
!description.chars().any(id_core::petname::is_format_char),
"description must not contain format characters"
);
}
Expand Down Expand Up @@ -2541,7 +2542,7 @@ mod tests {
use serde_json::json;
use tempfile::TempDir;

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 all() -> WorldScopes {
WorldScopes::GUEST.union(WorldScopes::DELEGATE)
Expand Down Expand Up @@ -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<Stored> {
Directory::receive_artifact(self, artifact)
}

fn receive_artifact_with_outcome(
&mut self,
artifact: &SignedArtifact,
) -> Result<(Stored, Option<id_sync::artifact::LegacyArtifactNote>)> {
Directory::receive_artifact_with_outcome(self, artifact)
}

fn artifact_head_seq(&self, account: &str) -> u64 {
self.artifacts().head_seq(account)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -463,7 +463,7 @@ fn hex_bytes<const N: usize>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading
Loading