diff --git a/src/identity/did.rs b/mitra-utils/src/did.rs similarity index 100% rename from src/identity/did.rs rename to mitra-utils/src/did.rs diff --git a/src/identity/did_key.rs b/mitra-utils/src/did_key.rs similarity index 94% rename from src/identity/did_key.rs rename to mitra-utils/src/did_key.rs index 22642df..b679943 100644 --- a/src/identity/did_key.rs +++ b/mitra-utils/src/did_key.rs @@ -4,13 +4,14 @@ use std::str::FromStr; use regex::Regex; -use mitra_utils::multibase::{ - decode_multibase_base58btc, - encode_multibase_base58btc, +use super::{ + did::DidParseError, + multibase::{ + decode_multibase_base58btc, + encode_multibase_base58btc, + }, }; -use super::did::DidParseError; - const DID_KEY_RE: &str = r"did:key:(?Pz[a-km-zA-HJ-NP-Z1-9]+)"; // https://github.com/multiformats/multicodec diff --git a/src/identity/did_pkh.rs b/mitra-utils/src/did_pkh.rs similarity index 97% rename from src/identity/did_pkh.rs rename to mitra-utils/src/did_pkh.rs index ea0b496..a9d4718 100644 --- a/src/identity/did_pkh.rs +++ b/mitra-utils/src/did_pkh.rs @@ -4,13 +4,12 @@ use std::str::FromStr; use regex::Regex; -use mitra_utils::{ +use super::{ caip2::ChainId, currencies::Currency, + did::DidParseError, }; -use super::did::DidParseError; - // https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#syntax const DID_PKH_RE: &str = r"did:pkh:(?P[-a-z0-9]{3,8}):(?P[-a-zA-Z0-9]{1,32}):(?P
[a-zA-Z0-9]{1,64})"; diff --git a/mitra-utils/src/lib.rs b/mitra-utils/src/lib.rs index 999af7f..8a02247 100644 --- a/mitra-utils/src/lib.rs +++ b/mitra-utils/src/lib.rs @@ -3,6 +3,9 @@ pub mod canonicalization; pub mod crypto_rsa; pub mod currencies; pub mod datetime; +pub mod did; +pub mod did_key; +pub mod did_pkh; pub mod files; pub mod html; pub mod id; diff --git a/src/activitypub/actors/attachments.rs b/src/activitypub/actors/attachments.rs index 9045ec3..54531ea 100644 --- a/src/activitypub/actors/attachments.rs +++ b/src/activitypub/actors/attachments.rs @@ -1,5 +1,7 @@ use uuid::Uuid; +use mitra_utils::did::Did; + use crate::activitypub::vocabulary::{ IDENTITY_PROOF, LINK, @@ -9,7 +11,6 @@ use crate::errors::ValidationError; use crate::ethereum::identity::verify_eip191_signature; use crate::identity::{ claims::create_identity_claim, - did::Did, minisign::{ parse_minisign_signature, verify_minisign_signature, diff --git a/src/activitypub/authentication.rs b/src/activitypub/authentication.rs index 1e3ebe1..5e0ac8d 100644 --- a/src/activitypub/authentication.rs +++ b/src/activitypub/authentication.rs @@ -2,7 +2,10 @@ use actix_web::HttpRequest; use serde_json::Value; use mitra_config::Config; -use mitra_utils::crypto_rsa::deserialize_public_key; +use mitra_utils::{ + crypto_rsa::deserialize_public_key, + did::Did, +}; use crate::database::{DatabaseClient, DatabaseError}; use crate::http_signatures::verify::{ @@ -10,7 +13,6 @@ use crate::http_signatures::verify::{ verify_http_signature, HttpSignatureVerificationError as HttpSignatureError, }; -use crate::identity::did::Did; use crate::json_signatures::{ proofs::ProofType, verify::{ diff --git a/src/ethereum/identity.rs b/src/ethereum/identity.rs index 37d0e33..4e044d0 100644 --- a/src/ethereum/identity.rs +++ b/src/ethereum/identity.rs @@ -1,4 +1,5 @@ -use crate::identity::did_pkh::DidPkh; +use mitra_utils::did_pkh::DidPkh; + use super::signatures::{recover_address, SignatureError}; use super::utils::address_to_string; diff --git a/src/identity/claims.rs b/src/identity/claims.rs index 56d1aa0..e15a555 100644 --- a/src/identity/claims.rs +++ b/src/identity/claims.rs @@ -1,12 +1,13 @@ use serde::Serialize; -use mitra_utils::canonicalization::{ - canonicalize_object, - CanonicalizationError, +use mitra_utils::{ + canonicalization::{ + canonicalize_object, + CanonicalizationError, + }, + did::Did, }; -use super::did::Did; - // https://www.w3.org/TR/vc-data-model/#credential-subject #[derive(Serialize)] #[serde(rename_all = "camelCase")] @@ -30,8 +31,10 @@ pub fn create_identity_claim( #[cfg(test)] mod tests { - use mitra_utils::currencies::Currency; - use crate::identity::did_pkh::DidPkh; + use mitra_utils::{ + currencies::Currency, + did_pkh::DidPkh, + }; use super::*; #[test] diff --git a/src/identity/minisign.rs b/src/identity/minisign.rs index e3506ca..8af3a19 100644 --- a/src/identity/minisign.rs +++ b/src/identity/minisign.rs @@ -7,7 +7,7 @@ use ed25519_dalek::{ Verifier, }; -use super::did_key::{DidKey, MulticodecError}; +use mitra_utils::did_key::{DidKey, MulticodecError}; const MINISIGN_SIGNATURE_CODE: [u8; 2] = *b"Ed"; const MINISIGN_SIGNATURE_HASHED_CODE: [u8; 2] = *b"ED"; diff --git a/src/identity/mod.rs b/src/identity/mod.rs index 92b71c9..d608132 100644 --- a/src/identity/mod.rs +++ b/src/identity/mod.rs @@ -1,5 +1,2 @@ pub mod claims; -pub mod did; -pub mod did_key; -pub mod did_pkh; pub mod minisign; diff --git a/src/json_signatures/create.rs b/src/json_signatures/create.rs index 49a29bd..4a010f4 100644 --- a/src/json_signatures/create.rs +++ b/src/json_signatures/create.rs @@ -9,13 +9,11 @@ use mitra_utils::{ CanonicalizationError, }, crypto_rsa::create_rsa_signature, + did_key::DidKey, + did_pkh::DidPkh, multibase::encode_multibase_base58btc, }; -use crate::identity::{ - did_key::DidKey, - did_pkh::DidPkh, -}; use super::proofs::{ PROOF_TYPE_JCS_ED25519, PROOF_TYPE_JCS_EIP191, diff --git a/src/json_signatures/verify.rs b/src/json_signatures/verify.rs index d840fd8..d7f73b9 100644 --- a/src/json_signatures/verify.rs +++ b/src/json_signatures/verify.rs @@ -10,14 +10,14 @@ use mitra_utils::{ CanonicalizationError, }, crypto_rsa::verify_rsa_signature, + did::Did, + did_key::DidKey, + did_pkh::DidPkh, multibase::{decode_multibase_base58btc, MultibaseError}, }; use crate::ethereum::identity::verify_eip191_signature; use crate::identity::{ - did::Did, - did_key::DidKey, - did_pkh::DidPkh, minisign::verify_minisign_signature, }; use super::create::{ diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index ee6daf3..225a025 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -4,11 +4,13 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use mitra_utils::markdown::markdown_basic_to_html; +use mitra_utils::{ + did::Did, + markdown::markdown_basic_to_html, +}; use crate::activitypub::actors::helpers::ACTOR_IMAGE_MAX_SIZE; use crate::errors::ValidationError; -use crate::identity::did::Did; use crate::mastodon_api::{ custom_emojis::types::CustomEmoji, errors::MastodonError, diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index 35a7937..bd59aba 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -20,6 +20,8 @@ use mitra_utils::{ serialize_private_key, }, currencies::Currency, + did::Did, + did_pkh::DidPkh, id::generate_ulid, passwords::hash_password, }; @@ -42,8 +44,6 @@ use crate::ethereum::{ use crate::http::get_request_base_url; use crate::identity::{ claims::create_identity_claim, - did::Did, - did_pkh::DidPkh, minisign::{ minisign_key_to_did, parse_minisign_signature, diff --git a/src/mastodon_api/search/helpers.rs b/src/mastodon_api/search/helpers.rs index a9b7e5a..957c3c4 100644 --- a/src/mastodon_api/search/helpers.rs +++ b/src/mastodon_api/search/helpers.rs @@ -4,7 +4,10 @@ use regex::Regex; use url::Url; use mitra_config::Config; -use mitra_utils::currencies::Currency; +use mitra_utils::{ + currencies::Currency, + did::Did, +}; use crate::activitypub::{ fetcher::helpers::{ @@ -18,7 +21,6 @@ use crate::activitypub::{ use crate::database::{DatabaseClient, DatabaseError}; use crate::errors::ValidationError; use crate::ethereum::utils::validate_ethereum_address; -use crate::identity::did::Did; use crate::models::{ posts::{ helpers::{can_view_post, get_local_post_by_id}, diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index fc0ceed..c20cfe7 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -3,6 +3,8 @@ use uuid::Uuid; use mitra_utils::{ currencies::Currency, + did::Did, + did_pkh::DidPkh, id::generate_ulid, }; @@ -12,7 +14,6 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::identity::{did::Did, did_pkh::DidPkh}; use crate::models::{ cleanup::{ find_orphaned_files, diff --git a/src/models/profiles/types.rs b/src/models/profiles/types.rs index 1c6813c..409a562 100644 --- a/src/models/profiles/types.rs +++ b/src/models/profiles/types.rs @@ -8,7 +8,10 @@ use serde::{ }; use uuid::Uuid; -use mitra_utils::caip2::ChainId; +use mitra_utils::{ + caip2::ChainId, + did::Did, +}; use crate::activitypub::{ actors::types::Actor, @@ -19,7 +22,6 @@ use crate::database::{ DatabaseTypeError, }; use crate::errors::ValidationError; -use crate::identity::did::Did; use crate::models::emojis::types::DbEmoji; use crate::webfinger::types::ActorAddress; use super::validators::{ diff --git a/src/models/users/queries.rs b/src/models/users/queries.rs index e5ea17f..27a4836 100644 --- a/src/models/users/queries.rs +++ b/src/models/users/queries.rs @@ -1,13 +1,16 @@ use uuid::Uuid; -use mitra_utils::currencies::Currency; +use mitra_utils::{ + currencies::Currency, + did::Did, + did_pkh::DidPkh, +}; use crate::database::{ catch_unique_violation, DatabaseClient, DatabaseError, }; -use crate::identity::{did::Did, did_pkh::DidPkh}; use crate::models::{ profiles::queries::create_profile, profiles::types::{DbActorProfile, ProfileCreateData}, diff --git a/src/models/users/types.rs b/src/models/users/types.rs index 89160bf..774d6ff 100644 --- a/src/models/users/types.rs +++ b/src/models/users/types.rs @@ -3,14 +3,16 @@ use postgres_types::FromSql; use regex::Regex; use uuid::Uuid; -use mitra_utils::currencies::Currency; +use mitra_utils::{ + currencies::Currency, + did::Did, +}; use crate::database::{ int_enum::{int_enum_from_sql, int_enum_to_sql}, DatabaseTypeError, }; use crate::errors::ValidationError; -use crate::identity::did::Did; use crate::models::profiles::types::DbActorProfile; #[allow(dead_code)]