Skip to content

Commit

Permalink
Merge branch 'main' into 241-implement-the-basic-message-protocol
Browse files Browse the repository at this point in the history
merging main
  • Loading branch information
ndefokou committed Nov 25, 2024
2 parents e3a48c5 + 56460d7 commit 1636b2f
Show file tree
Hide file tree
Showing 41 changed files with 610 additions and 647 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
19 changes: 12 additions & 7 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

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
16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[package]
name = "didcomm-mediator"
version = "0.1.0"
name = "didcomm-mediator"
version = "0.1.0"
authors = ["adorsys GmbH Co. KG"]
license = "Apache-2.0"
description = "A Rust Mediator for DIDComm messaging, supporting secure and decentralized communication."
repository = "https://github.com/adorsys/didcomm-mediator-rs"
homepage = "https://github.com/adorsys/didcomm-mediator-rs/blob/main/README.md"
documentation = "https://github.com/adorsys/didcomm-mediator-rs/tree/main/docs"
keywords = ["DIDComm", "Mediator", "DIDComm Mediator", "DIDComm Mediation", "DIDCOMM Messaging", "Decentralized Identity", "Rust Mediator"]
categories = ["cryptography", "decentralized-systems"]
edition = "2021"
description = "A mediator for DIDComm messages"
authors = ["adorsys GmbH Co. KG"]
readme = "README.md"



[workspace]
Expand Down
9 changes: 5 additions & 4 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)
[![CI](https://github.com/adorsys/didcomm-mediator-rs/actions/workflows/CI.yml/badge.svg)](https://github.com/adorsys/didcomm-mediator-rs/blob/main/.github/workflows/CI.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 @@ -19,12 +20,12 @@ For further understanding checkout the [docs](docs/mediator-doc.md)<br>
|[Pickup Protocol](https://didcomm.org/messagepickup/3.0/)| ADOPTED ||
|[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||
|[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 ||
|[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 ||
|[Present Proof Protocol](https://didcomm.org/present-proof/3.0/)| ADOPTED ||
|[Basic Message Protocol](https://didcomm.org/basicmessage/2.0/#:~:text=The%20BasicMessage%20protocol%20describes%20a,message%20type%20used%20to%20communicate.) | ADOPTED||

## Building and testing

Expand Down
9 changes: 7 additions & 2 deletions crates/filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,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
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
2 changes: 1 addition & 1 deletion 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 Down
1 change: 1 addition & 0 deletions crates/web-plugins/didcomm-messaging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugin-api.workspace = true
filesystem.workspace = true
forward.workspace = true
pickup.workspace = true
trust-ping.workspace = true
mediator-coordination.workspace = true

mongodb.workspace = true
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
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,12 @@ impl DidPeer {
}

match did {
s if s.starts_with("did:peer:0") => self.expand_did_peer_0(did).map_err(Into::into),
s if s.starts_with("did:peer:2") => self.expand_did_peer_2(did).map_err(Into::into),
s if s.starts_with("did:peer:4") => self.expand_did_peer_4(did).map_err(Into::into),
_ => Err(DIDResolutionError::MethodNotSupported),
s if s.starts_with("did:peer:0") => self.expand_did_peer_0(did).map_err(Into::into),
s if s.starts_with("did:peer:2") => self.expand_did_peer_2(did).map_err(Into::into),
s if s.starts_with("did:peer:4") => self.expand_did_peer_4(did).map_err(Into::into),
_ => Err(DIDResolutionError::MethodNotSupported),
}
}
}


/// Expands did:peer:0 address
///
Expand Down Expand Up @@ -814,10 +813,7 @@ mod tests {
let did_method = DidPeer::default();

let did = "did:peer:1zQmbEB1EqP7PnNVaHiSpXhkatAA6kNyQK9mWkvrMx2eckgq";
assert!(matches!(
did_method.expand(did).unwrap_err(),
DIDResolutionError::MethodNotSupported
));
assert!(matches!(did_method.expand(did).unwrap_err(), DIDResolutionError::MethodNotSupported));
}

#[test]
Expand Down Expand Up @@ -983,10 +979,7 @@ mod tests {
fn test_expand_did_peer_0_fails_on_too_long_did() {
let did_method = DidPeer::default();
let did = "did:peer:0zQebt6zPwbE4Vw5GFAjjARHrNXFALofERVv4q6Z4db8cnDRQm";
assert!(matches!(
did_method.expand(did).unwrap_err(),
DIDResolutionError::InvalidPublicKeyLength
));
assert!(matches!(did_method.expand(did).unwrap_err(), DIDResolutionError::InvalidPublicKeyLength));
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::errors::DIDPeerMethodError;
use crate::didcore::Document as DIDDocument;
use crate::didcore::{VerificationMethodType, Service};
use crate::didcore::{Service, VerificationMethodType};
use serde_json::{json, Map, Value};

pub(super) fn abbreviate_service_for_did_peer_2(service: &Service) -> Result<String, DIDPeerMethodError> {
Expand Down
36 changes: 20 additions & 16 deletions crates/web-plugins/didcomm-messaging/protocols/forward/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
use axum::Json;
use serde_json::{json, Value};
use axum::{response::IntoResponse, Json};
use hyper::StatusCode;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum RoutingError {
pub enum ForwardError {
#[error("message body is malformed")]
MalformedBody,
#[error("Repository not set")]
RepostitoryError
}
impl RoutingError {
/// Converts the error to an axum JSON representation.
pub fn json(&self) -> Json<Value> {
Json(json!({
"error": self.to_string()
}))
}
#[error("Uncoordinated sender")]
UncoordinatedSender,
#[error("Internal server error")]
InternalServerError,
}

impl From<RoutingError> for Json<Value> {
fn from(error: RoutingError) -> Self {
error.json()
impl IntoResponse for ForwardError {
fn into_response(self) -> axum::response::Response {
let status_code = match self {
ForwardError::MalformedBody => StatusCode::BAD_REQUEST,
ForwardError::UncoordinatedSender => StatusCode::UNAUTHORIZED,
ForwardError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
};

let body = Json(serde_json::json!({
"error": self.to_string(),
}));

(status_code, body).into_response()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod error;

pub mod web;

// Re-exports
pub use error::ForwardError;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use super::routing::handler;
use axum::response::Response;
use crate::{web::routing::handler, ForwardError};
use didcomm::Message;
use shared::state::AppState;
use std::sync::Arc;

/// Mediator receives forwarded messages, extract the next field in the message body, and the attachments in the message
/// then stores the attachment with the next field as key for pickup
pub async fn mediator_forward_process(
state: &AppState,
state: Arc<AppState>,
payload: Message,
) -> Result<Message, Response> {
let result = handler(state, payload).await.unwrap();
) -> Result<Option<Message>, ForwardError> {
let result = handler(state.clone(), payload).await.unwrap();
Ok(result)
}
Loading

0 comments on commit 1636b2f

Please sign in to comment.