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 regex::Regex;
use mitra_utils::multibase::{ use super::{
decode_multibase_base58btc, did::DidParseError,
encode_multibase_base58btc, 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]+)"; const DID_KEY_RE: &str = r"did:key:(?P<key>z[a-km-zA-HJ-NP-Z1-9]+)";
// https://github.com/multiformats/multicodec // https://github.com/multiformats/multicodec

View file

@ -4,13 +4,12 @@ use std::str::FromStr;
use regex::Regex; use regex::Regex;
use mitra_utils::{ use super::{
caip2::ChainId, caip2::ChainId,
currencies::Currency, currencies::Currency,
did::DidParseError,
}; };
use super::did::DidParseError;
// https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md#syntax // 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})"; 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 crypto_rsa;
pub mod currencies; pub mod currencies;
pub mod datetime; pub mod datetime;
pub mod did;
pub mod did_key;
pub mod did_pkh;
pub mod files; pub mod files;
pub mod html; pub mod html;
pub mod id; pub mod id;

View file

@ -1,5 +1,7 @@
use uuid::Uuid; use uuid::Uuid;
use mitra_utils::did::Did;
use crate::activitypub::vocabulary::{ use crate::activitypub::vocabulary::{
IDENTITY_PROOF, IDENTITY_PROOF,
LINK, LINK,
@ -9,7 +11,6 @@ use crate::errors::ValidationError;
use crate::ethereum::identity::verify_eip191_signature; use crate::ethereum::identity::verify_eip191_signature;
use crate::identity::{ use crate::identity::{
claims::create_identity_claim, claims::create_identity_claim,
did::Did,
minisign::{ minisign::{
parse_minisign_signature, parse_minisign_signature,
verify_minisign_signature, verify_minisign_signature,

View file

@ -2,7 +2,10 @@ use actix_web::HttpRequest;
use serde_json::Value; use serde_json::Value;
use mitra_config::Config; 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::database::{DatabaseClient, DatabaseError};
use crate::http_signatures::verify::{ use crate::http_signatures::verify::{
@ -10,7 +13,6 @@ use crate::http_signatures::verify::{
verify_http_signature, verify_http_signature,
HttpSignatureVerificationError as HttpSignatureError, HttpSignatureVerificationError as HttpSignatureError,
}; };
use crate::identity::did::Did;
use crate::json_signatures::{ use crate::json_signatures::{
proofs::ProofType, proofs::ProofType,
verify::{ 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::signatures::{recover_address, SignatureError};
use super::utils::address_to_string; use super::utils::address_to_string;

View file

@ -1,12 +1,13 @@
use serde::Serialize; use serde::Serialize;
use mitra_utils::canonicalization::{ use mitra_utils::{
canonicalize_object, canonicalization::{
CanonicalizationError, canonicalize_object,
CanonicalizationError,
},
did::Did,
}; };
use super::did::Did;
// https://www.w3.org/TR/vc-data-model/#credential-subject // https://www.w3.org/TR/vc-data-model/#credential-subject
#[derive(Serialize)] #[derive(Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
@ -30,8 +31,10 @@ pub fn create_identity_claim(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use mitra_utils::currencies::Currency; use mitra_utils::{
use crate::identity::did_pkh::DidPkh; currencies::Currency,
did_pkh::DidPkh,
};
use super::*; use super::*;
#[test] #[test]

View file

@ -7,7 +7,7 @@ use ed25519_dalek::{
Verifier, 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_CODE: [u8; 2] = *b"Ed";
const MINISIGN_SIGNATURE_HASHED_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 claims;
pub mod did;
pub mod did_key;
pub mod did_pkh;
pub mod minisign; pub mod minisign;

View file

@ -9,13 +9,11 @@ use mitra_utils::{
CanonicalizationError, CanonicalizationError,
}, },
crypto_rsa::create_rsa_signature, crypto_rsa::create_rsa_signature,
did_key::DidKey,
did_pkh::DidPkh,
multibase::encode_multibase_base58btc, multibase::encode_multibase_base58btc,
}; };
use crate::identity::{
did_key::DidKey,
did_pkh::DidPkh,
};
use super::proofs::{ use super::proofs::{
PROOF_TYPE_JCS_ED25519, PROOF_TYPE_JCS_ED25519,
PROOF_TYPE_JCS_EIP191, PROOF_TYPE_JCS_EIP191,

View file

@ -10,14 +10,14 @@ use mitra_utils::{
CanonicalizationError, CanonicalizationError,
}, },
crypto_rsa::verify_rsa_signature, crypto_rsa::verify_rsa_signature,
did::Did,
did_key::DidKey,
did_pkh::DidPkh,
multibase::{decode_multibase_base58btc, MultibaseError}, multibase::{decode_multibase_base58btc, MultibaseError},
}; };
use crate::ethereum::identity::verify_eip191_signature; use crate::ethereum::identity::verify_eip191_signature;
use crate::identity::{ use crate::identity::{
did::Did,
did_key::DidKey,
did_pkh::DidPkh,
minisign::verify_minisign_signature, minisign::verify_minisign_signature,
}; };
use super::create::{ use super::create::{

View file

@ -4,11 +4,13 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; 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::activitypub::actors::helpers::ACTOR_IMAGE_MAX_SIZE;
use crate::errors::ValidationError; use crate::errors::ValidationError;
use crate::identity::did::Did;
use crate::mastodon_api::{ use crate::mastodon_api::{
custom_emojis::types::CustomEmoji, custom_emojis::types::CustomEmoji,
errors::MastodonError, errors::MastodonError,

View file

@ -20,6 +20,8 @@ use mitra_utils::{
serialize_private_key, serialize_private_key,
}, },
currencies::Currency, currencies::Currency,
did::Did,
did_pkh::DidPkh,
id::generate_ulid, id::generate_ulid,
passwords::hash_password, passwords::hash_password,
}; };
@ -42,8 +44,6 @@ use crate::ethereum::{
use crate::http::get_request_base_url; use crate::http::get_request_base_url;
use crate::identity::{ use crate::identity::{
claims::create_identity_claim, claims::create_identity_claim,
did::Did,
did_pkh::DidPkh,
minisign::{ minisign::{
minisign_key_to_did, minisign_key_to_did,
parse_minisign_signature, parse_minisign_signature,

View file

@ -4,7 +4,10 @@ use regex::Regex;
use url::Url; use url::Url;
use mitra_config::Config; use mitra_config::Config;
use mitra_utils::currencies::Currency; use mitra_utils::{
currencies::Currency,
did::Did,
};
use crate::activitypub::{ use crate::activitypub::{
fetcher::helpers::{ fetcher::helpers::{
@ -18,7 +21,6 @@ use crate::activitypub::{
use crate::database::{DatabaseClient, DatabaseError}; use crate::database::{DatabaseClient, DatabaseError};
use crate::errors::ValidationError; use crate::errors::ValidationError;
use crate::ethereum::utils::validate_ethereum_address; use crate::ethereum::utils::validate_ethereum_address;
use crate::identity::did::Did;
use crate::models::{ use crate::models::{
posts::{ posts::{
helpers::{can_view_post, get_local_post_by_id}, helpers::{can_view_post, get_local_post_by_id},

View file

@ -3,6 +3,8 @@ use uuid::Uuid;
use mitra_utils::{ use mitra_utils::{
currencies::Currency, currencies::Currency,
did::Did,
did_pkh::DidPkh,
id::generate_ulid, id::generate_ulid,
}; };
@ -12,7 +14,6 @@ use crate::database::{
DatabaseClient, DatabaseClient,
DatabaseError, DatabaseError,
}; };
use crate::identity::{did::Did, did_pkh::DidPkh};
use crate::models::{ use crate::models::{
cleanup::{ cleanup::{
find_orphaned_files, find_orphaned_files,

View file

@ -8,7 +8,10 @@ use serde::{
}; };
use uuid::Uuid; use uuid::Uuid;
use mitra_utils::caip2::ChainId; use mitra_utils::{
caip2::ChainId,
did::Did,
};
use crate::activitypub::{ use crate::activitypub::{
actors::types::Actor, actors::types::Actor,
@ -19,7 +22,6 @@ use crate::database::{
DatabaseTypeError, DatabaseTypeError,
}; };
use crate::errors::ValidationError; use crate::errors::ValidationError;
use crate::identity::did::Did;
use crate::models::emojis::types::DbEmoji; use crate::models::emojis::types::DbEmoji;
use crate::webfinger::types::ActorAddress; use crate::webfinger::types::ActorAddress;
use super::validators::{ use super::validators::{

View file

@ -1,13 +1,16 @@
use uuid::Uuid; use uuid::Uuid;
use mitra_utils::currencies::Currency; use mitra_utils::{
currencies::Currency,
did::Did,
did_pkh::DidPkh,
};
use crate::database::{ use crate::database::{
catch_unique_violation, catch_unique_violation,
DatabaseClient, DatabaseClient,
DatabaseError, DatabaseError,
}; };
use crate::identity::{did::Did, did_pkh::DidPkh};
use crate::models::{ use crate::models::{
profiles::queries::create_profile, profiles::queries::create_profile,
profiles::types::{DbActorProfile, ProfileCreateData}, profiles::types::{DbActorProfile, ProfileCreateData},

View file

@ -3,14 +3,16 @@ use postgres_types::FromSql;
use regex::Regex; use regex::Regex;
use uuid::Uuid; use uuid::Uuid;
use mitra_utils::currencies::Currency; use mitra_utils::{
currencies::Currency,
did::Did,
};
use crate::database::{ use crate::database::{
int_enum::{int_enum_from_sql, int_enum_to_sql}, int_enum::{int_enum_from_sql, int_enum_to_sql},
DatabaseTypeError, DatabaseTypeError,
}; };
use crate::errors::ValidationError; use crate::errors::ValidationError;
use crate::identity::did::Did;
use crate::models::profiles::types::DbActorProfile; use crate::models::profiles::types::DbActorProfile;
#[allow(dead_code)] #[allow(dead_code)]