diff --git a/Cargo.lock b/Cargo.lock index caf54a1..dc9aa44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1703,13 +1703,10 @@ dependencies = [ "actix-files", "actix-web", "actix-web-httpauth", - "ammonia", "anyhow", "base64", "blake2", - "bs58", "chrono", - "comrak", "deadpool", "deadpool-postgres", "dotenv", @@ -1718,24 +1715,19 @@ dependencies = [ "env_logger", "hex", "log", - "mime-sniffer", - "mime_guess", + "mitra-utils", "monero-rpc", "num_cpus", - "pem", "postgres-protocol", "postgres-types", "postgres_query", "postgres_query_macro", - "rand 0.8.4", "refinery", "regex", "reqwest", "rsa", - "rust-argon2", "secp256k1", "serde", - "serde_jcs", "serde_json", "serde_yaml", "serial_test", @@ -1744,7 +1736,6 @@ dependencies = [ "thiserror", "tokio", "tokio-postgres", - "ulid", "url 2.2.2", "uuid", "web3", @@ -1758,10 +1749,37 @@ dependencies = [ "clap", "log", "mitra", + "mitra-utils", "tokio", "uuid", ] +[[package]] +name = "mitra-utils" +version = "1.13.1" +dependencies = [ + "ammonia", + "base64", + "bs58", + "chrono", + "comrak", + "mime-sniffer", + "mime_guess", + "pem", + "rand 0.8.4", + "regex", + "rsa", + "rust-argon2", + "serde", + "serde_jcs", + "serde_json", + "sha2 0.9.9", + "thiserror", + "ulid", + "url 2.2.2", + "uuid", +] + [[package]] name = "monero" version = "0.17.2" diff --git a/Cargo.toml b/Cargo.toml index d323b67..f28fc8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ default-run = "mitra" [workspace] members = [ ".", + "mitra-utils", "mitra-cli", ] default-members = [ @@ -20,23 +21,19 @@ default-members = [ ] [dependencies] +mitra-utils = { path = "mitra-utils" } + # Used to handle incoming HTTP requests actix-cors = "0.6.2" actix-files = "0.6.2" actix-web = "4.1.0" actix-web-httpauth = "0.8.0" -# Used for HTML sanitization -ammonia = "3.2.0" # Used for catching errors anyhow = "1.0.58" # Used for working with RSA keys, HTTP signatures and file uploads base64 = "0.13.0" -# Used to decode base58btc -bs58 = "0.4.0" # Used for working with dates chrono = { version = "0.4.23", default-features = false, features = ["std", "serde"] } -# Used for parsing markdown -comrak = { version = "0.15.0", default-features = false } # Used for pooling database connections deadpool = "0.9.2" deadpool-postgres = { version = "0.10.2", default-features = false } @@ -51,33 +48,23 @@ env_logger = { version = "0.9.0", default-features = false } ed25519-dalek = "1.0.1" ed25519 = "1.5.2" blake2 = "0.10.5" -# Used to guess media type of a file -mime_guess = "2.0.3" -mime-sniffer = "0.1.2" # Used to query Monero node monero-rpc = "0.3.2" # Used to determine the number of CPUs on the system num_cpus = "1.13.0" # Used for working with regular expressions regex = "1.6.0" -# Used to generate random numbers -rand = "0.8.4" # Used for managing database migrations refinery = { version = "0.8.4", features = ["tokio-postgres"] } # Used for making async HTTP requests reqwest = { version = "0.11.10", features = ["json", "multipart", "socks"] } # Used for working with RSA keys rsa = "0.5.0" -pem = "1.0.2" -# Used for hashing passwords -rust-argon2 = "1.0.0" # Used for working with ethereum keys secp256k1 = { version = "0.21.3", features = ["rand", "rand-std"] } # Used for serialization/deserialization serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.89" -# Used to create JCS representations -serde_jcs = "0.1.0" # Used to parse config file serde_yaml = "0.8.17" # Used to calculate SHA2 hashes @@ -97,15 +84,13 @@ postgres_query = { git = "https://github.com/nolanderc/rust-postgres-query", rev postgres_query_macro = { git = "https://github.com/nolanderc/rust-postgres-query", rev = "b4422051c8a31fbba4a35f88004c1cefb1878dd5" } # Used to work with URLs url = "2.2.2" -# Used to generate lexicographically sortable IDs -ulid = { version = "1.0.0", features = ["uuid"] } # Used to work with UUIDs uuid = { version = "1.1.2", features = ["serde", "v4"] } # Used to query ethereum node web3 = { version = "0.18.0", default-features = false, features = ["http", "http-tls", "signing"] } [dev-dependencies] -rand = { version = "0.8.4", features = ["small_rng"] } +mitra-utils = { path = "mitra-utils", features = ["test-utils"] } serial_test = "0.7.0" [features] diff --git a/mitra-cli/Cargo.toml b/mitra-cli/Cargo.toml index baf4cd1..ad028ce 100644 --- a/mitra-cli/Cargo.toml +++ b/mitra-cli/Cargo.toml @@ -10,6 +10,7 @@ name = "mitractl" path = "src/main.rs" [dependencies] +mitra-utils = { path = "../mitra-utils" } mitra = { path = ".." } # Used for catching errors diff --git a/mitra-cli/src/cli.rs b/mitra-cli/src/cli.rs index 8d7beed..5e2077b 100644 --- a/mitra-cli/src/cli.rs +++ b/mitra-cli/src/cli.rs @@ -48,7 +48,7 @@ use mitra::monero::{ helpers::check_expired_invoice, wallet::create_monero_wallet, }; -use mitra::utils::{ +use mitra_utils::{ crypto_rsa::{ generate_rsa_key, serialize_private_key, diff --git a/mitra-utils/Cargo.toml b/mitra-utils/Cargo.toml new file mode 100644 index 0000000..b3da243 --- /dev/null +++ b/mitra-utils/Cargo.toml @@ -0,0 +1,48 @@ +[package] +name = "mitra-utils" +version = "1.13.1" +license = "AGPL-3.0" +edition = "2021" +rust-version = "1.56" + +[dependencies] +# Used for HTML sanitization +ammonia = "3.2.0" +# Used for working with RSA keys, HTTP signatures and file uploads +base64 = "0.13.0" +# Used to decode base58btc +bs58 = "0.4.0" +# Used for working with dates +chrono = { version = "0.4.23", default-features = false, features = ["std"] } +# Used for parsing markdown +comrak = { version = "0.15.0", default-features = false } +# Used to guess media type of a file +mime_guess = "2.0.3" +mime-sniffer = "0.1.2" +# Used to generate random numbers +rand = "0.8.4" +# Used for working with regular expressions +regex = "1.6.0" +# Used for working with RSA keys +rsa = "0.5.0" +pem = "1.0.2" +# Used for hashing passwords +rust-argon2 = "1.0.0" +# Used for serialization/deserialization +serde = { version = "1.0.136", features = ["derive"] } +serde_json = "1.0.89" +# Used to create JCS representations +serde_jcs = "0.1.0" +# Used to calculate SHA2 hashes +sha2 = "0.9.5" +# Used for creating error types +thiserror = "1.0.37" +# Used to generate lexicographically sortable IDs +ulid = { version = "1.0.0", features = ["uuid"] } +# Used to work with URLs +url = "2.2.2" +# Used to work with UUIDs +uuid = "1.1.2" + +[features] +test-utils = ["rand/small_rng"] diff --git a/src/utils/caip2.rs b/mitra-utils/src/caip2.rs similarity index 100% rename from src/utils/caip2.rs rename to mitra-utils/src/caip2.rs diff --git a/src/utils/canonicalization.rs b/mitra-utils/src/canonicalization.rs similarity index 100% rename from src/utils/canonicalization.rs rename to mitra-utils/src/canonicalization.rs diff --git a/src/utils/crypto_rsa.rs b/mitra-utils/src/crypto_rsa.rs similarity index 99% rename from src/utils/crypto_rsa.rs rename to mitra-utils/src/crypto_rsa.rs index 4627229..f39fdc1 100644 --- a/src/utils/crypto_rsa.rs +++ b/mitra-utils/src/crypto_rsa.rs @@ -8,7 +8,7 @@ pub fn generate_rsa_key() -> Result { RsaPrivateKey::new(&mut rng, bits) } -#[cfg(test)] +#[cfg(feature = "test-utils")] pub fn generate_weak_rsa_key() -> Result { use rand::SeedableRng; let mut rng = rand::rngs::SmallRng::seed_from_u64(0); diff --git a/src/utils/currencies.rs b/mitra-utils/src/currencies.rs similarity index 100% rename from src/utils/currencies.rs rename to mitra-utils/src/currencies.rs diff --git a/src/utils/datetime.rs b/mitra-utils/src/datetime.rs similarity index 100% rename from src/utils/datetime.rs rename to mitra-utils/src/datetime.rs diff --git a/src/utils/files.rs b/mitra-utils/src/files.rs similarity index 100% rename from src/utils/files.rs rename to mitra-utils/src/files.rs diff --git a/src/utils/html.rs b/mitra-utils/src/html.rs similarity index 100% rename from src/utils/html.rs rename to mitra-utils/src/html.rs diff --git a/src/utils/id.rs b/mitra-utils/src/id.rs similarity index 100% rename from src/utils/id.rs rename to mitra-utils/src/id.rs diff --git a/src/utils/mod.rs b/mitra-utils/src/lib.rs similarity index 100% rename from src/utils/mod.rs rename to mitra-utils/src/lib.rs diff --git a/src/utils/markdown.rs b/mitra-utils/src/markdown.rs similarity index 100% rename from src/utils/markdown.rs rename to mitra-utils/src/markdown.rs diff --git a/src/utils/multibase.rs b/mitra-utils/src/multibase.rs similarity index 100% rename from src/utils/multibase.rs rename to mitra-utils/src/multibase.rs diff --git a/src/utils/passwords.rs b/mitra-utils/src/passwords.rs similarity index 100% rename from src/utils/passwords.rs rename to mitra-utils/src/passwords.rs diff --git a/src/utils/random.rs b/mitra-utils/src/random.rs similarity index 100% rename from src/utils/random.rs rename to mitra-utils/src/random.rs diff --git a/src/utils/urls.rs b/mitra-utils/src/urls.rs similarity index 100% rename from src/utils/urls.rs rename to mitra-utils/src/urls.rs diff --git a/src/activitypub/actors/attachments.rs b/src/activitypub/actors/attachments.rs index 30987fe..2cea244 100644 --- a/src/activitypub/actors/attachments.rs +++ b/src/activitypub/actors/attachments.rs @@ -158,7 +158,7 @@ pub fn parse_extra_field( #[cfg(test)] mod tests { - use crate::utils::{ + use mitra_utils::{ caip2::ChainId, id::generate_ulid, }; diff --git a/src/activitypub/actors/types.rs b/src/activitypub/actors/types.rs index 4a61e8f..38b4dc3 100644 --- a/src/activitypub/actors/types.rs +++ b/src/activitypub/actors/types.rs @@ -6,6 +6,11 @@ use serde::{ }; use serde_json::{json, Value}; +use mitra_utils::{ + crypto_rsa::{deserialize_private_key, get_public_key_pem}, + urls::get_hostname, +}; + use crate::activitypub::{ constants::{ AP_CONTEXT, @@ -31,10 +36,6 @@ use crate::models::{ }, users::types::User, }; -use crate::utils::{ - crypto_rsa::{deserialize_private_key, get_public_key_pem}, - urls::get_hostname, -}; use crate::webfinger::types::ActorAddress; use super::attachments::{ attach_extra_field, @@ -378,11 +379,11 @@ pub fn get_instance_actor( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActorProfile; - use crate::utils::crypto_rsa::{ + use mitra_utils::crypto_rsa::{ generate_weak_rsa_key, serialize_private_key, }; + use crate::models::profiles::types::DbActorProfile; use super::*; const INSTANCE_HOSTNAME: &str = "example.com"; diff --git a/src/activitypub/authentication.rs b/src/activitypub/authentication.rs index 8e2061d..697a55b 100644 --- a/src/activitypub/authentication.rs +++ b/src/activitypub/authentication.rs @@ -1,6 +1,8 @@ use actix_web::HttpRequest; use serde_json::Value; +use mitra_utils::crypto_rsa::deserialize_public_key; + use crate::config::Config; use crate::database::{DatabaseClient, DatabaseError}; use crate::http_signatures::verify::{ @@ -21,7 +23,6 @@ use crate::models::{ profiles::queries::get_profile_by_remote_actor_id, profiles::types::DbActorProfile, }; -use crate::utils::crypto_rsa::deserialize_public_key; use super::fetcher::helpers::get_or_import_profile_by_actor_id; use super::receiver::HandlerError; diff --git a/src/activitypub/builders/accept_follow.rs b/src/activitypub/builders/accept_follow.rs index fd5b28b..7976d5e 100644 --- a/src/activitypub/builders/accept_follow.rs +++ b/src/activitypub/builders/accept_follow.rs @@ -1,5 +1,7 @@ use serde::Serialize; +use mitra_utils::id::generate_ulid; + use crate::activitypub::{ actors::types::Actor, deliverer::OutgoingActivity, @@ -12,7 +14,6 @@ use crate::models::{ profiles::types::DbActorProfile, users::types::User, }; -use crate::utils::id::generate_ulid; #[derive(Serialize)] struct AcceptFollow { diff --git a/src/activitypub/builders/add_person.rs b/src/activitypub/builders/add_person.rs index 1a8a308..2b87c0a 100644 --- a/src/activitypub/builders/add_person.rs +++ b/src/activitypub/builders/add_person.rs @@ -1,5 +1,7 @@ use serde::Serialize; +use mitra_utils::id::generate_ulid; + use crate::activitypub::{ actors::types::Actor, deliverer::OutgoingActivity, @@ -9,7 +11,6 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::models::users::types::User; -use crate::utils::id::generate_ulid; #[derive(Serialize)] struct AddOrRemovePerson { diff --git a/src/activitypub/builders/follow.rs b/src/activitypub/builders/follow.rs index 832e3c2..2f623d1 100644 --- a/src/activitypub/builders/follow.rs +++ b/src/activitypub/builders/follow.rs @@ -70,7 +70,7 @@ pub fn prepare_follow( #[cfg(test)] mod tests { - use crate::utils::id::generate_ulid; + use mitra_utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/like.rs b/src/activitypub/builders/like.rs index 701ff1a..eb114f1 100644 --- a/src/activitypub/builders/like.rs +++ b/src/activitypub/builders/like.rs @@ -112,7 +112,7 @@ pub async fn prepare_like( #[cfg(test)] mod tests { - use crate::utils::id::generate_ulid; + use mitra_utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/move_person.rs b/src/activitypub/builders/move_person.rs index 62f7f0d..49a3143 100644 --- a/src/activitypub/builders/move_person.rs +++ b/src/activitypub/builders/move_person.rs @@ -1,6 +1,8 @@ use serde::Serialize; use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::activitypub::{ actors::types::Actor, deliverer::OutgoingActivity, @@ -10,7 +12,6 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::models::users::types::User; -use crate::utils::id::generate_ulid; #[derive(Serialize)] pub struct MovePerson { @@ -77,8 +78,8 @@ pub fn prepare_move_person( #[cfg(test)] mod tests { + use mitra_utils::id::generate_ulid; use crate::models::profiles::types::DbActorProfile; - use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/undo_announce.rs b/src/activitypub/builders/undo_announce.rs index 6b64a3d..2a582b7 100644 --- a/src/activitypub/builders/undo_announce.rs +++ b/src/activitypub/builders/undo_announce.rs @@ -90,7 +90,7 @@ pub async fn prepare_undo_announce( #[cfg(test)] mod tests { - use crate::utils::id::generate_ulid; + use mitra_utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/undo_follow.rs b/src/activitypub/builders/undo_follow.rs index 0fc1261..b556740 100644 --- a/src/activitypub/builders/undo_follow.rs +++ b/src/activitypub/builders/undo_follow.rs @@ -87,7 +87,7 @@ pub fn prepare_undo_follow( #[cfg(test)] mod tests { - use crate::utils::id::generate_ulid; + use mitra_utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/undo_like.rs b/src/activitypub/builders/undo_like.rs index d0e6ba5..cdc7836 100644 --- a/src/activitypub/builders/undo_like.rs +++ b/src/activitypub/builders/undo_like.rs @@ -88,8 +88,8 @@ pub async fn prepare_undo_like( #[cfg(test)] mod tests { + use mitra_utils::id::generate_ulid; use crate::activitypub::constants::AP_PUBLIC; - use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/builders/update_person.rs b/src/activitypub/builders/update_person.rs index dacba4a..f1d19b4 100644 --- a/src/activitypub/builders/update_person.rs +++ b/src/activitypub/builders/update_person.rs @@ -1,6 +1,8 @@ use serde::Serialize; use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::activitypub::{ actors::types::{get_local_actor, Actor, ActorKeyError}, constants::AP_PUBLIC, @@ -15,7 +17,6 @@ use crate::models::{ relationships::queries::get_followers, users::types::User, }; -use crate::utils::id::generate_ulid; #[derive(Serialize)] pub struct UpdatePerson { @@ -92,11 +93,11 @@ pub async fn prepare_update_person( #[cfg(test)] mod tests { - use crate::models::profiles::types::DbActorProfile; - use crate::utils::crypto_rsa::{ + use mitra_utils::crypto_rsa::{ generate_weak_rsa_key, serialize_private_key, }; + use crate::models::profiles::types::DbActorProfile; use super::*; const INSTANCE_URL: &str = "https://example.com"; diff --git a/src/activitypub/deliverer.rs b/src/activitypub/deliverer.rs index 83ea495..4710439 100644 --- a/src/activitypub/deliverer.rs +++ b/src/activitypub/deliverer.rs @@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use tokio::time::sleep; +use mitra_utils::crypto_rsa::deserialize_private_key; + use crate::config::Instance; use crate::database::{ get_database_client, @@ -28,7 +30,6 @@ use crate::models::{ profiles::queries::set_reachability_status, users::types::User, }; -use crate::utils::crypto_rsa::deserialize_private_key; use super::actors::types::Actor; use super::constants::AP_MEDIA_TYPE; use super::identifiers::{local_actor_id, local_actor_key_id}; diff --git a/src/activitypub/fetcher/fetchers.rs b/src/activitypub/fetcher/fetchers.rs index 65ff303..42e5f47 100644 --- a/src/activitypub/fetcher/fetchers.rs +++ b/src/activitypub/fetcher/fetchers.rs @@ -4,6 +4,11 @@ use std::time::Duration; use reqwest::{Client, Method, Proxy, RequestBuilder}; use serde_json::Value; +use mitra_utils::{ + files::sniff_media_type, + urls::guess_protocol, +}; + use crate::activitypub::{ actors::types::Actor, constants::AP_MEDIA_TYPE, @@ -16,10 +21,6 @@ use crate::http_signatures::create::{ HttpSignatureError, }; use crate::media::{save_file, SUPPORTED_MEDIA_TYPES}; -use crate::utils::{ - files::sniff_media_type, - urls::guess_protocol, -}; use crate::webfinger::types::{ActorAddress, JsonResourceDescriptor}; const FETCHER_CONNECTION_TIMEOUT: u64 = 30; diff --git a/src/activitypub/handlers/create.rs b/src/activitypub/handlers/create.rs index 92d2eda..9faf9ce 100644 --- a/src/activitypub/handlers/create.rs +++ b/src/activitypub/handlers/create.rs @@ -4,6 +4,11 @@ use chrono::Utc; use serde_json::{Value as JsonValue}; use uuid::Uuid; +use mitra_utils::{ + html::clean_html, + urls::get_hostname, +}; + use crate::activitypub::{ constants::{AP_MEDIA_TYPE, AP_PUBLIC, AS_MEDIA_TYPE}, fetcher::fetchers::{fetch_file, FetchError}, @@ -49,10 +54,6 @@ use crate::models::{ profiles::types::DbActorProfile, users::queries::get_user_by_name, }; -use crate::utils::{ - html::clean_html, - urls::get_hostname, -}; use super::HandlerResult; fn get_object_attributed_to(object: &Object) diff --git a/src/activitypub/identifiers.rs b/src/activitypub/identifiers.rs index 705dde9..67336b6 100644 --- a/src/activitypub/identifiers.rs +++ b/src/activitypub/identifiers.rs @@ -116,7 +116,7 @@ pub fn parse_local_object_id( #[cfg(test)] mod tests { - use crate::utils::id::generate_ulid; + use mitra_utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.org"; diff --git a/src/atom/feeds.rs b/src/atom/feeds.rs index 6247f70..08490cd 100644 --- a/src/atom/feeds.rs +++ b/src/atom/feeds.rs @@ -1,13 +1,14 @@ +use mitra_utils::{ + datetime::get_min_datetime, + html::{clean_html_all, escape_html}, +}; + use crate::activitypub::identifiers::{local_actor_id, local_object_id}; use crate::config::Instance; use crate::models::{ posts::types::Post, profiles::types::DbActorProfile, }; -use crate::utils::{ - datetime::get_min_datetime, - html::{clean_html_all, escape_html}, -}; const ENTRY_TITLE_MAX_LENGTH: usize = 75; diff --git a/src/config/blockchain.rs b/src/config/blockchain.rs index 25637e2..413e8c8 100644 --- a/src/config/blockchain.rs +++ b/src/config/blockchain.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; -use crate::utils::caip2::{ChainId, ChainIdError}; +use mitra_utils::caip2::{ChainId, ChainIdError}; fn default_chain_sync_step() -> u64 { 1000 } diff --git a/src/config/loader.rs b/src/config/loader.rs index 2dd6b10..ce2ad35 100644 --- a/src/config/loader.rs +++ b/src/config/loader.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use rsa::RsaPrivateKey; -use crate::utils::{ +use mitra_utils::{ crypto_rsa::{ deserialize_private_key, generate_rsa_key, diff --git a/src/config/main.rs b/src/config/main.rs index df76a33..8466f1b 100644 --- a/src/config/main.rs +++ b/src/config/main.rs @@ -9,7 +9,7 @@ use serde::{ }; use url::Url; -use crate::utils::urls::normalize_url; +use mitra_utils::urls::normalize_url; use super::blockchain::BlockchainConfig; use super::environment::Environment; @@ -188,7 +188,7 @@ impl Instance { #[cfg(test)] impl Instance { pub fn for_test(url: &str) -> Self { - use crate::utils::crypto_rsa::generate_weak_rsa_key; + use mitra_utils::crypto_rsa::generate_weak_rsa_key; Self { _url: Url::parse(url).unwrap(), actor_key: generate_weak_rsa_key().unwrap(), @@ -200,7 +200,7 @@ impl Instance { #[cfg(test)] mod tests { - use crate::utils::crypto_rsa::generate_weak_rsa_key; + use mitra_utils::crypto_rsa::generate_weak_rsa_key; use super::*; #[test] diff --git a/src/ethereum/identity.rs b/src/ethereum/identity.rs index c190949..15c8af4 100644 --- a/src/ethereum/identity.rs +++ b/src/ethereum/identity.rs @@ -36,6 +36,7 @@ pub fn verify_eip191_identity_proof( #[cfg(test)] mod tests { use web3::signing::{Key, SecretKeyRef}; + use mitra_utils::currencies::Currency; use crate::ethereum::{ signatures::{ generate_ecdsa_key, @@ -43,7 +44,6 @@ mod tests { }, utils::address_to_string, }; - use crate::utils::currencies::Currency; use super::*; const ETHEREUM: Currency = Currency::Ethereum; diff --git a/src/ethereum/subscriptions.rs b/src/ethereum/subscriptions.rs index 9b2b744..37bfd3e 100644 --- a/src/ethereum/subscriptions.rs +++ b/src/ethereum/subscriptions.rs @@ -1,7 +1,6 @@ use std::convert::TryInto; use chrono::{DateTime, TimeZone, Utc}; - use web3::{ api::Web3, contract::{Contract, Options}, @@ -10,6 +9,11 @@ use web3::{ types::{BlockId, BlockNumber, FilterBuilder, U256}, }; +use mitra_utils::{ + caip2::ChainId, + currencies::Currency, +}; + use crate::activitypub::{ builders::{ add_person::prepare_add_person, @@ -48,10 +52,6 @@ use crate::models::{ }, users::types::User, }; -use crate::utils::{ - caip2::ChainId, - currencies::Currency, -}; use super::contracts::ContractSet; use super::errors::EthereumError; use super::signatures::{ diff --git a/src/ethereum/sync.rs b/src/ethereum/sync.rs index 6e97e26..4dbfb37 100644 --- a/src/ethereum/sync.rs +++ b/src/ethereum/sync.rs @@ -3,7 +3,8 @@ use std::path::{Path, PathBuf}; use web3::{api::Web3, transports::Http, types::Address}; -use crate::utils::files::write_file; +use mitra_utils::files::write_file; + use super::errors::EthereumError; const BLOCK_NUMBER_FILE_NAME: &str = "current_block"; diff --git a/src/http_signatures/create.rs b/src/http_signatures/create.rs index 7ba609c..fb8edc8 100644 --- a/src/http_signatures/create.rs +++ b/src/http_signatures/create.rs @@ -2,7 +2,7 @@ use actix_web::http::Method; use chrono::Utc; use rsa::RsaPrivateKey; -use crate::utils::crypto_rsa::{ +use mitra_utils::crypto_rsa::{ create_rsa_signature, get_message_digest, }; @@ -92,7 +92,7 @@ pub fn create_http_signature( #[cfg(test)] mod tests { - use crate::utils::crypto_rsa::generate_weak_rsa_key; + use mitra_utils::crypto_rsa::generate_weak_rsa_key; use super::*; #[test] diff --git a/src/http_signatures/verify.rs b/src/http_signatures/verify.rs index 755a94a..f8e4e58 100644 --- a/src/http_signatures/verify.rs +++ b/src/http_signatures/verify.rs @@ -5,7 +5,7 @@ use chrono::{DateTime, Duration, TimeZone, Utc}; use regex::Regex; use rsa::RsaPublicKey; -use crate::utils::crypto_rsa::verify_rsa_signature; +use mitra_utils::crypto_rsa::verify_rsa_signature; const SIGNATURE_PARAMETER_RE: &str = r#"^(?P[a-zA-Z]+)="(?P.+)"$"#; @@ -152,8 +152,8 @@ mod tests { header::{HeaderMap, HeaderName, HeaderValue}, Uri, }; + use mitra_utils::crypto_rsa::generate_weak_rsa_key; use crate::http_signatures::create::create_http_signature; - use crate::utils::crypto_rsa::generate_weak_rsa_key; use super::*; #[test] diff --git a/src/identity/claims.rs b/src/identity/claims.rs index b2809d6..56d1aa0 100644 --- a/src/identity/claims.rs +++ b/src/identity/claims.rs @@ -1,6 +1,6 @@ use serde::Serialize; -use crate::utils::canonicalization::{ +use mitra_utils::canonicalization::{ canonicalize_object, CanonicalizationError, }; @@ -30,8 +30,8 @@ pub fn create_identity_claim( #[cfg(test)] mod tests { + use mitra_utils::currencies::Currency; use crate::identity::did_pkh::DidPkh; - use crate::utils::currencies::Currency; use super::*; #[test] diff --git a/src/identity/did_key.rs b/src/identity/did_key.rs index d94ae72..22642df 100644 --- a/src/identity/did_key.rs +++ b/src/identity/did_key.rs @@ -4,10 +4,11 @@ use std::str::FromStr; use regex::Regex; -use crate::utils::multibase::{ +use mitra_utils::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]+)"; diff --git a/src/identity/did_pkh.rs b/src/identity/did_pkh.rs index 3382bc1..ea0b496 100644 --- a/src/identity/did_pkh.rs +++ b/src/identity/did_pkh.rs @@ -4,8 +4,11 @@ use std::str::FromStr; use regex::Regex; -use crate::utils::caip2::ChainId; -use crate::utils::currencies::Currency; +use mitra_utils::{ + caip2::ChainId, + currencies::Currency, +}; + use super::did::DidParseError; // https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#syntax diff --git a/src/job_queue/periodic_tasks.rs b/src/job_queue/periodic_tasks.rs index 4535e41..0c9e9da 100644 --- a/src/job_queue/periodic_tasks.rs +++ b/src/job_queue/periodic_tasks.rs @@ -5,6 +5,8 @@ use anyhow::Error; use chrono::{DateTime, Utc}; use uuid::Uuid; +use mitra_utils::datetime::days_before_now; + use crate::activitypub::queues::{ process_queued_incoming_activities, process_queued_outgoing_activities, @@ -28,7 +30,6 @@ use crate::models::{ get_profile_by_id, }, }; -use crate::utils::datetime::days_before_now; pub async fn nft_monitor( maybe_blockchain: Option<&mut Blockchain>, diff --git a/src/json_signatures/create.rs b/src/json_signatures/create.rs index 60b8569..15d3d30 100644 --- a/src/json_signatures/create.rs +++ b/src/json_signatures/create.rs @@ -3,6 +3,15 @@ use rsa::RsaPrivateKey; use serde::{Deserialize, Serialize}; use serde_json::Value; +use mitra_utils::{ + canonicalization::{ + canonicalize_object, + CanonicalizationError, + }, + crypto_rsa::create_rsa_signature, + multibase::encode_multibase_base58btc, +}; + use crate::identity::{ did_key::DidKey, did_pkh::DidPkh, @@ -12,14 +21,6 @@ use crate::identity::{ PROOF_TYPE_JCS_RSA, }, }; -use crate::utils::{ - canonicalization::{ - canonicalize_object, - CanonicalizationError, - }, - crypto_rsa::create_rsa_signature, - multibase::encode_multibase_base58btc, -}; pub(super) const PROOF_KEY: &str = "proof"; pub(super) const PROOF_PURPOSE: &str = "assertionMethod"; @@ -133,7 +134,7 @@ pub fn is_object_signed(object: &Value) -> bool { #[cfg(test)] mod tests { use serde_json::json; - use crate::utils::crypto_rsa::generate_weak_rsa_key; + use mitra_utils::crypto_rsa::generate_weak_rsa_key; use super::*; #[test] diff --git a/src/json_signatures/verify.rs b/src/json_signatures/verify.rs index 3e3dc34..91a94d5 100644 --- a/src/json_signatures/verify.rs +++ b/src/json_signatures/verify.rs @@ -4,6 +4,15 @@ use rsa::RsaPublicKey; use serde_json::Value; use url::Url; +use mitra_utils::{ + canonicalization::{ + canonicalize_object, + CanonicalizationError, + }, + crypto_rsa::verify_rsa_signature, + multibase::{decode_multibase_base58btc, MultibaseError}, +}; + use crate::ethereum::identity::verify_eip191_signature; use crate::identity::{ did::Did, @@ -12,14 +21,6 @@ use crate::identity::{ minisign::verify_ed25519_signature, signatures::SignatureType, }; -use crate::utils::{ - canonicalization::{ - canonicalize_object, - CanonicalizationError, - }, - crypto_rsa::verify_rsa_signature, - multibase::{decode_multibase_base58btc, MultibaseError}, -}; use super::create::{ IntegrityProof, PROOF_KEY, @@ -132,11 +133,11 @@ pub fn verify_ed25519_json_signature( #[cfg(test)] mod tests { use serde_json::json; - use crate::json_signatures::create::sign_object; - use crate::utils::{ + use mitra_utils::{ crypto_rsa::generate_weak_rsa_key, currencies::Currency, }; + use crate::json_signatures::create::sign_object; use super::*; #[test] diff --git a/src/lib.rs b/src/lib.rs index e4344c0..b30091e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,5 @@ pub mod media; pub mod models; pub mod monero; pub mod nodeinfo; -pub mod utils; pub mod webfinger; pub mod web_client; diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index 2eec342..d2f813e 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -4,6 +4,8 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use uuid::Uuid; +use mitra_utils::markdown::markdown_basic_to_html; + use crate::errors::{HttpError, ValidationError}; use crate::identity::did::Did; use crate::mastodon_api::{ @@ -28,7 +30,6 @@ use crate::models::{ User, }, }; -use crate::utils::markdown::markdown_basic_to_html; /// https://docs.joinmastodon.org/entities/field/ #[derive(Serialize)] diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index 08617f8..0bd0907 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -5,6 +5,18 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use uuid::Uuid; +use mitra_utils::{ + caip2::ChainId, + canonicalization::canonicalize_object, + crypto_rsa::{ + generate_rsa_key, + serialize_private_key, + }, + currencies::Currency, + id::generate_ulid, + passwords::hash_password, +}; + use crate::activitypub::builders::{ undo_follow::prepare_undo_follow, update_person::{ @@ -75,17 +87,6 @@ use crate::models::{ }, users::types::{Role, UserCreateData}, }; -use crate::utils::{ - caip2::ChainId, - canonicalization::canonicalize_object, - crypto_rsa::{ - generate_rsa_key, - serialize_private_key, - }, - currencies::Currency, - id::generate_ulid, - passwords::hash_password, -}; use super::helpers::{follow_or_create_request, get_relationship}; use super::types::{ Account, diff --git a/src/mastodon_api/instance/types.rs b/src/mastodon_api/instance/types.rs index 4e2a458..1c0c0ce 100644 --- a/src/mastodon_api/instance/types.rs +++ b/src/mastodon_api/instance/types.rs @@ -1,6 +1,8 @@ use serde::Serialize; use serde_json::{to_value, Value}; +use mitra_utils::markdown::markdown_to_html; + use crate::config::{ BlockchainConfig, Config, @@ -14,7 +16,6 @@ use crate::mastodon_api::{ }; use crate::media::SUPPORTED_MEDIA_TYPES; use crate::models::posts::validators::ATTACHMENTS_MAX_NUM; -use crate::utils::markdown::markdown_to_html; #[derive(Serialize)] struct InstanceStats { diff --git a/src/mastodon_api/oauth/utils.rs b/src/mastodon_api/oauth/utils.rs index dba07cb..7cde9fd 100644 --- a/src/mastodon_api/oauth/utils.rs +++ b/src/mastodon_api/oauth/utils.rs @@ -1,6 +1,6 @@ use base64; -use crate::utils::random::generate_random_sequence; +use mitra_utils::random::generate_random_sequence; pub fn render_authorization_page() -> String { let page = r#" diff --git a/src/mastodon_api/oauth/views.rs b/src/mastodon_api/oauth/views.rs index 23e1d1e..46d30a9 100644 --- a/src/mastodon_api/oauth/views.rs +++ b/src/mastodon_api/oauth/views.rs @@ -10,6 +10,8 @@ use actix_web::{ use actix_web_httpauth::extractors::bearer::BearerAuth; use chrono::{Duration, Utc}; +use mitra_utils::passwords::verify_password; + use crate::config::Config; use crate::database::{get_database_client, DatabaseError, DbPool}; use crate::errors::{HttpError, ValidationError}; @@ -30,7 +32,6 @@ use crate::models::{ get_user_by_login_address, }, }; -use crate::utils::passwords::verify_password; use super::auth::get_current_user; use super::types::{ AuthorizationRequest, diff --git a/src/mastodon_api/search/helpers.rs b/src/mastodon_api/search/helpers.rs index 5199284..04670f4 100644 --- a/src/mastodon_api/search/helpers.rs +++ b/src/mastodon_api/search/helpers.rs @@ -3,6 +3,8 @@ use std::str::FromStr; use regex::Regex; use url::Url; +use mitra_utils::currencies::Currency; + use crate::activitypub::{ fetcher::helpers::{ get_or_import_profile_by_actor_id, @@ -34,7 +36,6 @@ use crate::models::{ types::User, }, }; -use crate::utils::currencies::Currency; use crate::webfinger::types::ActorAddress; enum SearchQuery { diff --git a/src/mastodon_api/settings/views.rs b/src/mastodon_api/settings/views.rs index 85ef1bf..743eb79 100644 --- a/src/mastodon_api/settings/views.rs +++ b/src/mastodon_api/settings/views.rs @@ -1,6 +1,8 @@ use actix_web::{get, post, web, HttpResponse, Scope}; use actix_web_httpauth::extractors::bearer::BearerAuth; +use mitra_utils::passwords::hash_password; + use crate::activitypub::{ builders::{ move_person::prepare_move_person, @@ -20,7 +22,6 @@ use crate::models::{ relationships::queries::{follow, unfollow}, users::queries::set_user_password, }; -use crate::utils::passwords::hash_password; use super::helpers::{ export_followers, export_follows, diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index 28c395c..d9f2362 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -4,6 +4,11 @@ use actix_web_httpauth::extractors::bearer::BearerAuth; use chrono::Utc; use uuid::Uuid; +use mitra_utils::{ + currencies::Currency, + markdown::markdown_lite_to_html, +}; + use crate::activitypub::builders::{ announce::prepare_announce, create_note::prepare_create_note, @@ -45,10 +50,6 @@ use crate::models::{ }, relationships::queries::get_subscribers, }; -use crate::utils::{ - currencies::Currency, - markdown::markdown_lite_to_html, -}; use super::helpers::{ build_status, build_status_list, diff --git a/src/mastodon_api/subscriptions/views.rs b/src/mastodon_api/subscriptions/views.rs index a5c26dc..4b598cd 100644 --- a/src/mastodon_api/subscriptions/views.rs +++ b/src/mastodon_api/subscriptions/views.rs @@ -2,6 +2,8 @@ use actix_web::{get, post, web, HttpResponse, Scope}; use actix_web_httpauth::extractors::bearer::BearerAuth; use uuid::Uuid; +use mitra_utils::currencies::Currency; + use crate::activitypub::builders::update_person::prepare_update_person; use crate::config::Config; use crate::database::{get_database_client, DbPool}; @@ -37,7 +39,6 @@ use crate::monero::{ helpers::validate_monero_address, wallet::create_monero_address, }; -use crate::utils::currencies::Currency; use super::types::{ Invoice, InvoiceData, diff --git a/src/mastodon_api/uploads.rs b/src/mastodon_api/uploads.rs index 4891e43..880df99 100644 --- a/src/mastodon_api/uploads.rs +++ b/src/mastodon_api/uploads.rs @@ -1,8 +1,9 @@ use std::path::Path; +use mitra_utils::files::sniff_media_type; + use crate::errors::HttpError; use crate::media::{save_file, SUPPORTED_MEDIA_TYPES}; -use crate::utils::files::sniff_media_type; pub const UPLOAD_MAX_SIZE: usize = 1024 * 1024 * 5; diff --git a/src/media.rs b/src/media.rs index 376090b..5da800b 100644 --- a/src/media.rs +++ b/src/media.rs @@ -4,7 +4,7 @@ use std::path::Path; use sha2::{Digest, Sha256}; -use crate::utils::files::{get_media_type_extension, write_file}; +use mitra_utils::files::{get_media_type_extension, write_file}; pub const SUPPORTED_MEDIA_TYPES: [&str; 8] = [ "audio/mpeg", @@ -61,7 +61,7 @@ pub fn remove_files(files: Vec, from_dir: &Path) -> () { #[cfg(test)] mod tests { - use crate::utils::files::sniff_media_type; + use mitra_utils::files::sniff_media_type; use super::*; #[test] diff --git a/src/models/attachments/queries.rs b/src/models/attachments/queries.rs index 3ec7a98..458a7dc 100644 --- a/src/models/attachments/queries.rs +++ b/src/models/attachments/queries.rs @@ -1,13 +1,14 @@ use chrono::{DateTime, Utc}; use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::database::{DatabaseClient, DatabaseError}; use crate::models::cleanup::{ find_orphaned_files, find_orphaned_ipfs_objects, DeletionQueue, }; -use crate::utils::id::generate_ulid; use super::types::DbMediaAttachment; pub async fn create_attachment( diff --git a/src/models/emojis/queries.rs b/src/models/emojis/queries.rs index ea32313..7183659 100644 --- a/src/models/emojis/queries.rs +++ b/src/models/emojis/queries.rs @@ -1,6 +1,8 @@ use chrono::{DateTime, Utc}; use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::database::{ catch_unique_violation, DatabaseClient, @@ -10,7 +12,6 @@ use crate::models::{ cleanup::{find_orphaned_files, DeletionQueue}, instances::queries::create_instance, }; -use crate::utils::id::generate_ulid; use super::types::{DbEmoji, EmojiImage}; pub async fn create_emoji( diff --git a/src/models/invoices/queries.rs b/src/models/invoices/queries.rs index 20a0dea..eb05d67 100644 --- a/src/models/invoices/queries.rs +++ b/src/models/invoices/queries.rs @@ -1,14 +1,15 @@ use uuid::Uuid; +use mitra_utils::{ + caip2::ChainId, + id::generate_ulid, +}; + use crate::database::{ catch_unique_violation, DatabaseClient, DatabaseError, }; -use crate::utils::{ - caip2::ChainId, - id::generate_ulid, -}; use super::types::{DbChainId, DbInvoice, InvoiceStatus}; pub async fn create_invoice( diff --git a/src/models/invoices/types.rs b/src/models/invoices/types.rs index 42ca0f9..f89b536 100644 --- a/src/models/invoices/types.rs +++ b/src/models/invoices/types.rs @@ -11,11 +11,12 @@ use postgres_types::{ }; use uuid::Uuid; +use mitra_utils::caip2::ChainId; + use crate::database::{ int_enum::{int_enum_from_sql, int_enum_to_sql}, DatabaseTypeError, }; -use crate::utils::caip2::ChainId; #[derive(Debug)] pub struct DbChainId(ChainId); diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index c577849..c2fac3d 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -1,6 +1,8 @@ use chrono::{DateTime, Utc}; use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::database::{ catch_unique_violation, query_macro::query, @@ -25,7 +27,6 @@ use crate::models::{ profiles::types::DbActorProfile, relationships::types::RelationshipType, }; -use crate::utils::id::generate_ulid; use super::types::{ DbPost, Post, diff --git a/src/models/posts/validators.rs b/src/models/posts/validators.rs index 4464b53..9435820 100644 --- a/src/models/posts/validators.rs +++ b/src/models/posts/validators.rs @@ -1,5 +1,6 @@ +use mitra_utils::html::clean_html_strict; + use crate::errors::ValidationError; -use crate::utils::html::clean_html_strict; pub const ATTACHMENTS_MAX_NUM: usize = 15; pub const EMOJIS_MAX_NUM: usize = 20; diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index 4ce843d..a9afaf5 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -1,6 +1,11 @@ use chrono::{DateTime, Utc}; use uuid::Uuid; +use mitra_utils::{ + currencies::Currency, + id::generate_ulid, +}; + use crate::database::{ catch_unique_violation, query_macro::query, @@ -17,10 +22,6 @@ use crate::models::{ instances::queries::create_instance, relationships::types::RelationshipType, }; -use crate::utils::{ - currencies::Currency, - id::generate_ulid, -}; use super::types::{ DbActorProfile, ExtraFields, diff --git a/src/models/profiles/types.rs b/src/models/profiles/types.rs index 0242ae3..00357c2 100644 --- a/src/models/profiles/types.rs +++ b/src/models/profiles/types.rs @@ -11,6 +11,8 @@ use serde::{ }; use uuid::Uuid; +use mitra_utils::caip2::ChainId; + use crate::activitypub::{ actors::types::Actor, identifiers::local_actor_id, @@ -24,7 +26,6 @@ use crate::identity::{ did::Did, signatures::{PROOF_TYPE_ID_EIP191, PROOF_TYPE_ID_MINISIGN}, }; -use crate::utils::caip2::ChainId; use crate::webfinger::types::ActorAddress; use super::validators::{ validate_username, diff --git a/src/models/profiles/validators.rs b/src/models/profiles/validators.rs index 1fd066f..a48e97e 100644 --- a/src/models/profiles/validators.rs +++ b/src/models/profiles/validators.rs @@ -1,6 +1,8 @@ use regex::Regex; + +use mitra_utils::html::{clean_html, clean_html_strict}; + use crate::errors::ValidationError; -use crate::utils::html::{clean_html, clean_html_strict}; use super::types::ExtraField; const USERNAME_RE: &str = r"^[a-zA-Z0-9_\.-]+$"; diff --git a/src/models/reactions/queries.rs b/src/models/reactions/queries.rs index 0edd5ea..ff21ecf 100644 --- a/src/models/reactions/queries.rs +++ b/src/models/reactions/queries.rs @@ -1,5 +1,7 @@ use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::database::{ catch_unique_violation, DatabaseClient, @@ -12,7 +14,6 @@ use crate::models::{ get_post_author, }, }; -use crate::utils::id::generate_ulid; use super::types::DbReaction; pub async fn create_reaction( diff --git a/src/models/relationships/queries.rs b/src/models/relationships/queries.rs index dbd9194..0e207dd 100644 --- a/src/models/relationships/queries.rs +++ b/src/models/relationships/queries.rs @@ -1,5 +1,7 @@ use uuid::Uuid; +use mitra_utils::id::generate_ulid; + use crate::database::{ catch_unique_violation, DatabaseClient, @@ -14,7 +16,6 @@ use crate::models::{ }, profiles::types::DbActorProfile, }; -use crate::utils::id::generate_ulid; use super::types::{ DbFollowRequest, DbRelationship, diff --git a/src/models/subscriptions/queries.rs b/src/models/subscriptions/queries.rs index 746e9c5..ce904af 100644 --- a/src/models/subscriptions/queries.rs +++ b/src/models/subscriptions/queries.rs @@ -1,6 +1,8 @@ use chrono::{DateTime, Utc}; use uuid::Uuid; +use mitra_utils::caip2::ChainId; + use crate::database::{ catch_unique_violation, DatabaseClient, @@ -12,7 +14,6 @@ use crate::models::{ relationships::queries::{subscribe, subscribe_opt}, relationships::types::RelationshipType, }; -use crate::utils::caip2::ChainId; use super::types::{DbSubscription, Subscription}; pub async fn create_subscription( diff --git a/src/models/users/queries.rs b/src/models/users/queries.rs index caca1e0..9638b42 100644 --- a/src/models/users/queries.rs +++ b/src/models/users/queries.rs @@ -1,5 +1,7 @@ use uuid::Uuid; +use mitra_utils::currencies::Currency; + use crate::database::{ catch_unique_violation, DatabaseClient, @@ -10,7 +12,6 @@ use crate::models::{ profiles::queries::create_profile, profiles::types::{DbActorProfile, ProfileCreateData}, }; -use crate::utils::currencies::Currency; use super::types::{DbUser, Role, User, UserCreateData}; use super::utils::generate_invite_code; diff --git a/src/models/users/types.rs b/src/models/users/types.rs index e35fd98..011f0ac 100644 --- a/src/models/users/types.rs +++ b/src/models/users/types.rs @@ -3,6 +3,8 @@ use postgres_types::FromSql; use regex::Regex; use uuid::Uuid; +use mitra_utils::currencies::Currency; + use crate::database::{ int_enum::{int_enum_from_sql, int_enum_to_sql}, DatabaseTypeError, @@ -10,7 +12,6 @@ use crate::database::{ use crate::errors::ValidationError; use crate::identity::did::Did; use crate::models::profiles::types::DbActorProfile; -use crate::utils::currencies::Currency; #[derive(PartialEq)] pub enum Permission { diff --git a/src/models/users/utils.rs b/src/models/users/utils.rs index a2485da..864dfdb 100644 --- a/src/models/users/utils.rs +++ b/src/models/users/utils.rs @@ -1,6 +1,6 @@ use hex; -use crate::utils::random::generate_random_sequence; +use mitra_utils::random::generate_random_sequence; const INVITE_CODE_LENGTH: usize = 32;