Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 245-integration-environment-for-didcomm-mediator-server-deployment-e6
  • Loading branch information
Christiantyemele committed Nov 28, 2024
2 parents 85dd48a + 8095d32 commit ed3b710
Show file tree
Hide file tree
Showing 83 changed files with 1,629 additions and 503 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CD

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Rust
uses: actions/setup-rust@v1
with:
rust-version: stable

# Deploy to AWS EC2 Or another instance
21 changes: 13 additions & 8 deletions .github/workflows/rust.yml → .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Rust CI
name: CI

on: [push, pull_request]
on: [pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build and Test

ci:
name: Build and test
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -42,7 +43,11 @@ jobs:
chmod +x .github/scripts/test_config.sh
sh .github/scripts/test_config.sh
- name: Build and Run Test
run: |
cargo build --workspace --all-features
cargo nextest run --workspace --all-features
- name: Check Formatting
run: cargo fmt --all -- --check

- name: Build Project
run: cargo build --workspace --all-features

- name: Run Tests
run: cargo nextest run --workspace --all-features
17 changes: 14 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ members = [
"crates/web-plugins/didcomm-messaging/protocols/*",
]


[workspace.dependencies]
database = { path = "./crates/database", version = "0.1.0" }
filesystem = { path = "./crates/filesystem", version = "0.1.0" }
Expand All @@ -37,11 +36,15 @@ oob-messages = { path = "./crates/web-plugins/oob-messages", version = "0.1.0" }
didcomm-messaging = { path = "./crates/web-plugins/didcomm-messaging", version = "0.1.0" }
did-utils = { path = "./crates/web-plugins/didcomm-messaging/did-utils", version = "0.1.0" }
shared = { path = "./crates/web-plugins/didcomm-messaging/shared", version = "0.1.0" }
message-api = { path = "./crates/web-plugins/didcomm-messaging/message-api", version = "0.1.0" }
pickup = { path = "./crates/web-plugins/didcomm-messaging/protocols/pickup", version = "0.1.0" }
forward = { path = "./crates/web-plugins/didcomm-messaging/protocols/forward", version = "0.1.0" }
trust-ping = { path = "./crates/web-plugins/didcomm-messaging/protocols/trust-ping", version = "0.1.0" }
basic-message = { path = "./crates/web-plugins/didcomm-messaging/protocols/basic-message", version = "0.1.0" }
discover-features = { path = "./crates/web-plugins/didcomm-messaging/protocols/discover-features", version = "0.1.0" }
mediator-coordination = { path = "./crates/web-plugins/didcomm-messaging/protocols/mediator-coordination", version = "0.1.0" }


# Other common dependencies
serde = "1.0"
sha2 = "0.10"
Expand All @@ -62,6 +65,8 @@ url = "2.4.1"
num-bigint = "0.4.4"
base64 = "0.13.0"
hex = "0.4.3"
eyre = "0.6"
anyhow = "1"
subtle = "2.5.0"
regex = "1.10.2"
mongodb = "2.7.1"
Expand Down Expand Up @@ -93,15 +98,15 @@ plugin-api.workspace = true

axum.workspace = true
dotenv-flow.workspace = true
eyre.workspace = true
thiserror.workspace = true
tracing.workspace = true
lazy_static.workspace = true
serde_json.workspace = true
hyper.workspace = true
tokio = { workspace = true, features = ["full"] }
tracing-subscriber = { workspace = true, features = ["json"] }
tower-http = { workspace = true, features = ["catch-panic", "trace"] }

# optional dependencies
chrono = { workspace = true, optional = true }
did-endpoint = { workspace = true, optional = true }
oob-messages = { workspace = true, optional = true }
Expand All @@ -122,6 +127,12 @@ plugin-did_endpoint = ["dep:did-endpoint"]
plugin-oob_messages = ["dep:oob-messages"]
plugin-didcomm_messaging = ["dep:didcomm-messaging"]

routing = ["plugin-didcomm_messaging", "didcomm-messaging/routing"]
pickup = ["plugin-didcomm_messaging", "didcomm-messaging/pickup"]
trust-ping = ["plugin-didcomm_messaging", "didcomm-messaging/trust-ping"]
discover-features = ["plugin-didcomm_messaging", "didcomm-messaging/discover-features"]
mediator-coordination = ["plugin-didcomm_messaging", "didcomm-messaging/mediator-coordination"]


[dev-dependencies]
tower = { version = "0.4.13", features = ["util"] }
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[![CI](https://github.com/adorsys/didcomm-mediator-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/adorsys/didcomm-mediator-rs/actions/workflows/rust.yml)
[![CD](https://github.com/adorsys/didcomm-mediator-rs/actions/workflows/CD.yml/badge.svg)](https://github.com/adorsys/didcomm-mediator-rs/blob/main/.github/workflows/CD.yml)
[![DIDComm Messaging Clients Utilities](https://img.shields.io/badge/DIDComm%20Messaging%20Clients%20Utilities-repo-blue.svg)](https://github.com/adorsys/didcomm-messaging-clients-utilities)
[![DIDComm Messaging Spec](https://img.shields.io/badge/DIDComm%20Messaging-Specification-blue.svg)](https://identity.foundation/didcomm-messaging/spec/)
[![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://github.com/adorsys/didcomm-mediator-rs/blob/main/LICENSE)


# Didcomm-mediator
# DIDComm-Mediator

A DIDComm mediator is a cloud agent that facilitates secure, decentralized communication between mobile agents in the self-sovereign identity (SSI) ecosystem. This mediator acts as a cloud-based intermediary, enabling mobile agents to communicate without reliance on centralized infrastructures like Facebook, Signal, or Telegram.

Expand All @@ -20,7 +21,7 @@ For further understanding checkout the [docs](docs/mediator-doc.md)<br>
|[DID Rotation](https://didcomm.org/book/v2/didrotation) | ACCEPTED ||
|[Cross-Domain Messaging/ Routing Protocol](https://identity.foundation/didcomm-messaging/spec/#routing-protocol-20) | ADOPTED ||
|[Trust Ping Ptotocol](https://identity.foundation/didcomm-messaging/spec/#trust-ping-protocol-20) | ADOPTED||
|[Discover Features Protocol](https://didcomm.org/discover-features/2.0/) | ADOPTED | |
|[Discover Features Protocol](https://didcomm.org/discover-features/2.0/) | ADOPTED | |
|[Out of band Messaging](https://identity.foundation/didcomm-messaging/spec/#out-of-band-messages) | ADOPTED | ⚪
|[Basic Message Protocol](https://didcomm.org/basicmessage/2.0/#:~:text=The%20BasicMessage%20protocol%20describes%20a,message%20type%20used%20to%20communicate.) | ADOPTED||
|[Acks](https://github.com/hyperledger/aries-rfcs/tree/main/features/0015-acks)| ADOPTED ||
Expand Down
20 changes: 16 additions & 4 deletions crates/filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ impl FileSystem for StdFileSystem {
flock(file.as_raw_fd(), FlockArg::LockExclusive)
.map_err(|_| IoError::new(ErrorKind::Other, "Error acquiring file lock"))?;

std::fs::write(path, &content).expect("Error saving base64-encoded image to file");
std::fs::write(path, &content).map_err(|_| {
IoError::new(
ErrorKind::Other,
"Error saving base64-encoded image to file",
)
})?;

// Release the lock after writing to the file
flock(file.as_raw_fd(), FlockArg::Unlock).expect("Error releasing file lock");
flock(file.as_raw_fd(), FlockArg::Unlock)
.map_err(|_| IoError::new(ErrorKind::Other, "Error releasing file lock"))?;

Ok(())
}

Expand Down Expand Up @@ -112,11 +119,16 @@ mod tests {

impl FileSystem for MockFileSystem {
fn read_to_string(&self, path: &Path) -> IoResult<String> {
Ok(self.map.get(path.to_str().unwrap()).cloned().unwrap_or_default())
Ok(self
.map
.get(path.to_str().unwrap())
.cloned()
.unwrap_or_default())
}

fn write(&mut self, path: &Path, content: &str) -> IoResult<()> {
self.map.insert(path.to_str().unwrap().to_string(), content.to_string());
self.map
.insert(path.to_str().unwrap().to_string(), content.to_string());
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ serde_json.workspace = true
tokio = { workspace = true, features = ["full"] }

[features]
test-utils = []
test-utils = []
1 change: 1 addition & 0 deletions crates/plugin-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"

[dependencies]
axum.workspace = true
thiserror.workspace = true
10 changes: 7 additions & 3 deletions crates/plugin-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ use std::{
fmt::Debug,
hash::{Hash, Hasher},
};
use thiserror::Error;

use axum::Router;

#[derive(Debug, PartialEq)]
#[derive(Debug, Error, PartialEq)]
pub enum PluginError {
InitError,
#[error("{0}")]
InitError(String),
#[error("{0}")]
Other(String),
}

pub trait Plugin: Sync + Send {
Expand All @@ -21,7 +25,7 @@ pub trait Plugin: Sync + Send {
fn unmount(&self) -> Result<(), PluginError>;

/// Export managed endpoints
fn routes(&self) -> Router;
fn routes(&self) -> Result<Router, PluginError>;
}

impl Eq for dyn Plugin {}
Expand Down
5 changes: 4 additions & 1 deletion crates/web-plugins/did-endpoint/src/didgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ where
// Validate the keys in the DID document
if let Some(verification_methods) = &diddoc.verification_method {
for method in verification_methods {
let pubkey = method.public_key.as_ref().ok_or(String::from("Missing key"))?;
let pubkey = method
.public_key
.as_ref()
.ok_or(String::from("Missing key"))?;
let kid = util::handle_vm_id(&method.id, &diddoc);
match pubkey {
KeyFormat::Jwk(_) => validate_key(&kid, keystore)?,
Expand Down
24 changes: 12 additions & 12 deletions crates/web-plugins/did-endpoint/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{didgen, web};
use axum::Router;
use database::Repository;
use filesystem::FileSystem;
use keystore::Secrets;
use plugin_api::{Plugin, PluginError};
use std::sync::{Arc, Mutex};
use filesystem::FileSystem;

#[derive(Default)]
pub struct DidEndpoint {
Expand All @@ -24,14 +24,11 @@ pub(crate) struct DidEndPointState {
}

fn get_env() -> Result<DidEndpointEnv, PluginError> {
let storage_dirpath = std::env::var("STORAGE_DIRPATH").map_err(|_| {
tracing::error!("STORAGE_DIRPATH env variable required");
PluginError::InitError
})?;
let storage_dirpath = std::env::var("STORAGE_DIRPATH")
.map_err(|_| PluginError::InitError("STORAGE_DIRPATH env variable required".to_owned()))?;

let server_public_domain = std::env::var("SERVER_PUBLIC_DOMAIN").map_err(|_| {
tracing::error!("SERVER_PUBLIC_DOMAIN env variable required");
PluginError::InitError
PluginError::InitError("SERVER_PUBLIC_DOMAIN env variable required".to_owned())
})?;

Ok(DidEndpointEnv {
Expand Down Expand Up @@ -62,8 +59,9 @@ impl Plugin for DidEndpoint {
&mut filesystem,
)
.map_err(|_| {
tracing::error!("failed to generate an initial keystore and its DID document");
PluginError::InitError
PluginError::InitError(
"failed to generate an initial keystore and its DID document".to_owned(),
)
})?;
};

Expand All @@ -80,8 +78,10 @@ impl Plugin for DidEndpoint {
Ok(())
}

fn routes(&self) -> Router {
let state = self.state.as_ref().expect("Plugin not mounted");
web::routes(Arc::new(state.clone()))
fn routes(&self) -> Result<Router, PluginError> {
let state = self.state.as_ref().ok_or(PluginError::Other(
"missing state, plugin not mounted".to_owned(),
))?;
Ok(web::routes(Arc::new(state.clone())))
}
}
5 changes: 4 additions & 1 deletion crates/web-plugins/did-endpoint/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ 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).unwrap())),
Ok(content) => Ok(Json(serde_json::from_str(&content).map_err(|_| {
tracing::error!("Unparseable did.json");
StatusCode::NOT_FOUND
})?)),
Err(_) => Err(StatusCode::NOT_FOUND),
}
}
Expand Down
31 changes: 27 additions & 4 deletions crates/web-plugins/didcomm-messaging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,45 @@ keystore.workspace = true
shared.workspace = true
plugin-api.workspace = true
filesystem.workspace = true
forward.workspace = true
pickup.workspace = true
trust-ping.workspace = true
mediator-coordination.workspace = true
message-api.workspace = true

# optional dependencies
forward = { workspace = true, optional = true }
pickup = { workspace = true, optional = true }
trust-ping = { workspace = true, optional = true }
discover-features = { workspace = true, optional = true }
mediator-coordination = { workspace = true, optional = true }

mongodb.workspace = true
didcomm.workspace = true
tracing.workspace = true
once_cell.workspace = true
serde_json.workspace = true
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]
default = [
"routing",
"pickup",
"trust-ping",
"discover-features",
"mediator-coordination",
]

routing = ["dep:forward"]
pickup = ["dep:pickup"]
trust-ping = ["dep:trust-ping"]
discover-features = ["dep:discover-features"]
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct Parameters {

/// The URL of the X.509 certificate associated with this key.
#[serde(skip_serializing_if = "Option::is_none", default)]
#[cfg(feature = "url")]
pub x5u: Option<url::Url>,

/// The X.509 certificate associated with this key.
Expand Down
Loading

0 comments on commit ed3b710

Please sign in to comment.