Move DID types to mitra-utils crate

This commit is contained in:
silverpill 2023-03-16 17:59:45 +00:00
parent 1637e38ee4
commit 0b65e7473e
19 changed files with 60 additions and 43 deletions

View file

@ -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:(?P<key>z[a-km-zA-HJ-NP-Z1-9]+)";
// https://github.com/multiformats/multicodec

View file

@ -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<network>[-a-z0-9]{3,8}):(?P<chain>[-a-zA-Z0-9]{1,32}):(?P<address>[a-zA-Z0-9]{1,64})";

View file

@ -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;

View file

@ -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,

View file

@ -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::{

View file

@ -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;

View file

@ -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]

View file

@ -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";

View file

@ -1,5 +1,2 @@
pub mod claims;
pub mod did;
pub mod did_key;
pub mod did_pkh;
pub mod minisign;

View file

@ -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,

View file

@ -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::{

View file

@ -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,

View file

@ -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,

View file

@ -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},

View file

@ -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,

View file

@ -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::{

View file

@ -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},

View file

@ -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)]