Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning up the codebase #285

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ axum = "0.6.20"
tokio = "1.30.0"
tracing = "0.1.37"
chrono = "0.4.26"
paste = "0.1"
didcomm = "0.4.1"
hyper = "0.14.27"
lazy_static = "1.4.0"
Expand Down
5 changes: 3 additions & 2 deletions crates/filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ impl FileSystem for StdFileSystem {
let file = OpenOptions::new()
.read(true)
.write(true)
.truncate(true)
.create(true)
.open(&path)?;
.open(path)?;

// Acquire an exclusive lock before writing to the file
flock(file.as_raw_fd(), FlockArg::LockExclusive)
.map_err(|_| IoError::new(ErrorKind::Other, "Error acquiring file lock"))?;

std::fs::write(path, &content).map_err(|_| {
std::fs::write(path, content).map_err(|_| {
IoError::new(
ErrorKind::Other,
"Error saving base64-encoded image to file",
Expand Down
11 changes: 7 additions & 4 deletions crates/keystore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ where
collection: Collection<T>,
}

impl Default for KeyStore<Secrets> {
fn default() -> Self {
Self::new()
}
}

impl KeyStore<Secrets> {
/// Create a new keystore with default Secrets type.
///
Expand All @@ -54,10 +60,7 @@ impl KeyStore<Secrets> {
let db_lock = db.write().await;
db_lock.collection::<Secrets>("secrets").clone()
};
let collection = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(task)
});
collection
tokio::task::block_in_place(|| tokio::runtime::Handle::current().block_on(task))
})
.clone();

Expand Down
2 changes: 1 addition & 1 deletion crates/web-plugins/did-endpoint/src/didgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ where

// Create directory and write the DID document
filesystem
.create_dir_all(&storage_dirpath)
.create_dir_all(storage_dirpath)
.map_err(|_| Error::PersistenceError)?;
filesystem
.write(&storage_dirpath.join("did.json"), &pretty_diddoc)
Expand Down
10 changes: 5 additions & 5 deletions crates/web-plugins/did-endpoint/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn diddoc(State(state): State<Arc<DidEndPointState>>) -> Result<Json<Value
let did_path = Path::new(&storage_dirpath).join("did.json");

match filesystem.read_to_string(&did_path).as_ref() {
Ok(content) => Ok(Json(serde_json::from_str(&content).map_err(|_| {
Ok(content) => Ok(Json(serde_json::from_str(content).map_err(|_| {
tracing::error!("Unparseable did.json");
StatusCode::NOT_FOUND
})?)),
Expand All @@ -56,7 +56,7 @@ async fn didpop(
let diddoc: Document = serde_json::from_value(diddoc_value.clone()).unwrap();

let did_address = diddoc.id.clone();
let methods = diddoc.verification_method.clone().unwrap_or(vec![]);
let methods = diddoc.verification_method.clone().unwrap_or_default();

// Build verifiable credential (VC)
let vc: VerifiableCredential = serde_json::from_value(json!({
Expand Down Expand Up @@ -157,15 +157,15 @@ async fn didpop(
fn inspect_vm_relationship(diddoc: &Document, vm_id: &str) -> Option<String> {
let vrel = [
(
json!(diddoc.authentication.clone().unwrap_or(vec![])),
json!(diddoc.authentication.clone().unwrap_or_default()),
String::from("authentication"),
),
(
json!(diddoc.assertion_method.clone().unwrap_or(vec![])),
json!(diddoc.assertion_method.clone().unwrap_or_default()),
String::from("assertionMethod"),
),
(
json!(diddoc.key_agreement.clone().unwrap_or(vec![])),
json!(diddoc.key_agreement.clone().unwrap_or_default()),
String::from("keyAgreement"),
),
];
Expand Down
2 changes: 0 additions & 2 deletions crates/web-plugins/didcomm-messaging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ thiserror.workspace = true
tokio = { workspace = true, features = ["full"] }
hyper = { workspace = true, features = ["full"] }
axum = { workspace = true, features = ["macros"] }
serde = { version = "1.0", features = ["derive"] }


[features]
Expand All @@ -50,7 +49,6 @@ mediator-coordination = ["dep:mediator-coordination"]

[dev-dependencies]
async-trait.workspace = true
mockall = "0.13.0"
uuid = { workspace = true, features = ["v4"] }
json-canon = "0.1.3"
shared = { workspace = true, features = ["test-utils"] }
Expand Down
531 changes: 0 additions & 531 deletions crates/web-plugins/didcomm-messaging/did-utils/src/jwk/jwk.rs

This file was deleted.

489 changes: 487 additions & 2 deletions crates/web-plugins/didcomm-messaging/did-utils/src/jwk/mod.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl From<DIDPeerMethodError> for DIDResolutionError {

impl std::fmt::Display for DIDPeerMethodError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self) // Customize this to format the error as desired
write!(f, "{:?}", self)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl DIDResolver for DidPeer {
error: Some(if !did.starts_with("did:peer:") {
DIDResolutionError::MethodNotSupported
} else {
err.into()
err
}),
content_type: None,
additional_properties: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct VerifiableCredential {
/// The issuers of the credential.
pub enum Issuers {
Single(Box<Issuer>),
SetOf(Box<Vec<Issuer>>),
SetOf(Vec<Issuer>),
}

#[derive(Serialize, Debug, Clone, PartialEq, Deserialize)]
Expand Down
13 changes: 0 additions & 13 deletions crates/web-plugins/didcomm-messaging/message-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@ version = "0.1.0"
edition = "2021"

[dependencies]
keystore.workspace = true
shared.workspace = true
database.workspace = true
filesystem.workspace = true

async-trait.workspace = true
mongodb.workspace = true
anyhow.workspace = true
tracing.workspace = true
serde_json.workspace = true
thiserror.workspace = true
didcomm = { workspace = true, features = ["uniffi"] }
hyper = { workspace = true, features = ["full"] }
axum = { workspace = true, features = ["macros"] }

[dev-dependencies]
keystore = { workspace = true, features = ["test-utils"] }
shared = { workspace = true, features = ["test-utils"] }
did-utils.workspace = true
uuid = { workspace = true, features = ["v4"] }
tokio = { version = "1.27.0", default-features = false, features = ["macros", "rt"] }
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,13 @@ edition = "2021"
[dependencies]
shared.workspace = true
did-utils.workspace = true
database.workspace = true
keystore.workspace = true

serde.workspace = true
didcomm.workspace = true
mongodb.workspace = true
serde_json.workspace = true
thiserror.workspace = true
uuid = { workspace = true, features = ["v4"] }
axum = { workspace = true, features = ["macros"] }
tokio = { workspace = true, features = ["full"] }
chrono.workspace = true

[dev-dependencies]
did-utils.workspace = true
keystore.workspace = true
hyper = "0.14.27"
shared = { workspace = true, features = ["test-utils"] }
tokio = { version = "1.27.0", default-features = false, features = [
"macros",
"rt",
] }
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;

// https://didcomm.org/basicmessage/2.0/
pub fn handle_basic_message(_state: Arc<AppState>, message: Message) -> Response {
if message.extra_headers.get("lang").is_none() {
if !message.extra_headers.contains_key("lang") {
return (StatusCode::BAD_REQUEST, "Language is required").into_response();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ pub(crate) async fn handle_query_request(
Some(id) => {
let id = id.as_str().unwrap_or_default();

if !id
if id
.ends_with(".*")
.then(|| {
supported
.into_iter()
.find(|protocol| protocol.contains(&id.to_string()))
.is_some()
.iter()
.any(|protocol| protocol.contains(&id.to_string()))
})
.is_some()
.is_none()
{
disclosed_protocols.insert(id.to_owned());
}
Expand All @@ -50,13 +49,13 @@ pub(crate) async fn handle_query_request(
// stores the full protocol obtained when we have a match with wildcard
let mut container: String = Default::default();

if let Some(id) = parts.get(0) {
if let Some(id) = parts.first() {
supported
.into_iter()
.iter()
.find(|protocol| protocol.contains(&id.to_string()))
.is_some_and(|protocol| {
container = protocol.to_string();
return true;
true
})
.then(|| {
let parts: Vec<&str> =
Expand Down Expand Up @@ -88,7 +87,7 @@ pub(crate) async fn handle_query_request(
let msg = build_response(disclosed_protocols);
Ok(Some(msg))
} else {
return Err(DiscoveryError::QueryNotFound);
Err(DiscoveryError::QueryNotFound)
}
} else {
let msg = build_response(disclosed_protocols);
Expand All @@ -110,9 +109,7 @@ fn build_response(disclosed_protocols: HashSet<String>) -> Message {
}

let id = Uuid::new_v4().urn().to_string();
let msg = Message::build(id, DISCOVER_FEATURE.to_string(), json!(body)).finalize();

msg
Message::build(id, DISCOVER_FEATURE.to_string(), json!(body)).finalize()
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
keystore.workspace = true
shared.workspace = true
database.workspace = true
filesystem.workspace = true
message-api.workspace = true

mongodb.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) async fn mediator_forward_process(
} = state
.repository
.as_ref()
.ok_or_else(|| ForwardError::InternalServerError)?;
.ok_or(ForwardError::InternalServerError)?;

let next = match checks(&message, connection_repository).await.ok() {
Some(next) => Ok(next),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ edition = "2021"
[dependencies]
shared.workspace = true
did-utils.workspace = true
database.workspace = true
keystore.workspace = true
filesystem.workspace = true
message-api.workspace = true

mongodb.workspace = true
multibase.workspace = true
serde.workspace = true
paste.workspace = true
async-trait.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand All @@ -32,9 +31,9 @@ tokio = { version = "1.27.0", default-features = false, features = [
"macros",
"rt",
] }
tower = { version = "0.4.13", features = ["util"] }
shared = { workspace = true, features = ["test-utils"] }

[features]
default = ["stateful"]
stateful = []
stateless = []
Loading
Loading