diff --git a/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/handler/stateful.rs b/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/handler/stateful.rs index 2a135813..8c70d03e 100644 --- a/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/handler/stateful.rs +++ b/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/handler/stateful.rs @@ -3,9 +3,9 @@ use crate::{ errors::MediationError, handler::midlw::ensure_jwm_type_is_mediation_request, model::stateful::coord::{ - Keylist, KeylistBody, KeylistEntry, KeylistUpdateAction, KeylistUpdateBody, + KeylistBody, KeylistEntry, KeylistUpdateAction, KeylistUpdateBody, KeylistUpdateConfirmation, KeylistUpdateResponseBody, KeylistUpdateResult, MediationDeny, - MediationGrant, MediationGrantBody, + MediationGrantBody, }, }; use did_utils::{ @@ -145,7 +145,7 @@ pub(crate) async fn process_mediate_request( Ok(Some( Message::build( format!("urn:uuid:{}", Uuid::new_v4()), - mediation_grant.message_type.clone(), + MEDIATE_GRANT_2_0.to_string(), json!(mediation_grant), ) .to(sender_did.clone()) @@ -155,13 +155,9 @@ pub(crate) async fn process_mediate_request( } } -fn create_mediation_grant(routing_did: &str) -> MediationGrant { - MediationGrant { - id: format!("urn:uuid:{}", Uuid::new_v4()), - message_type: MEDIATE_GRANT_2_0.to_string(), - body: MediationGrantBody { - routing_did: routing_did.to_string(), - }, +fn create_mediation_grant(routing_did: &str) -> MediationGrantBody { + MediationGrantBody { + routing_did: routing_did.to_string(), } } @@ -351,8 +347,6 @@ pub(crate) async fn process_plain_keylist_query_message( .unwrap() .ok_or(MediationError::UncoordinatedSender)?; - println!("keylist: {:?}", connection); - let keylist_entries = connection .keylist .iter() @@ -366,12 +360,7 @@ pub(crate) async fn process_plain_keylist_query_message( pagination: None, }; - let keylist_object = Keylist { - id: format!("urn:uuid:{}", Uuid::new_v4()), - message_type: KEYLIST_2_0.to_string(), - body, - additional_properties: None, - }; + let keylist_object = body; let mediator_did = &state.diddoc.id; @@ -384,8 +373,6 @@ pub(crate) async fn process_plain_keylist_query_message( .from(mediator_did.clone()) .finalize(); - println!("message: {:?}", message); - Ok(Some(message)) } @@ -429,14 +416,14 @@ mod tests { .finalize(); // Process request - let response = process_plain_keylist_query_message(Arc::clone(&state), message) + let message = process_plain_keylist_query_message(Arc::clone(&state), message) .await .unwrap() .expect("Response should not be None"); - assert_eq!(response.type_, KEYLIST_2_0); - assert_eq!(response.from.unwrap(), global::_mediator_did(&state)); - assert_eq!(response.to.unwrap(), vec![global::_edge_did()]); + assert_eq!(message.type_, KEYLIST_2_0); + assert_eq!(message.from.unwrap(), global::_mediator_did(&state)); + assert_eq!(message.to.unwrap(), vec![global::_edge_did()]); } #[tokio::test] async fn test_keylist_query_malformed_request() { @@ -499,7 +486,6 @@ mod tests { assert_eq!(response.type_, KEYLIST_UPDATE_RESPONSE_2_0); assert_eq!(response.from.unwrap(), global::_mediator_did(&state)); assert_eq!(response.to.unwrap(), vec![global::_edge_did()]); - // Assert updates assert_eq!( diff --git a/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/model/stateful/coord.rs b/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/model/stateful/coord.rs index 1c7cbf21..ca547d4c 100644 --- a/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/model/stateful/coord.rs +++ b/crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/model/stateful/coord.rs @@ -226,26 +226,6 @@ pub struct KeylistQueryPaginate { pub offset: i32, } -/// Response to key list query, containing retrieved keys. -#[derive(Debug, Serialize, Deserialize, Clone, Default)] -pub struct Keylist { - /// Uniquely identifies a keylist query response message. - pub id: String, - - /// References the protocol URI of this concept. - /// - /// Typically `https://didcomm.org/coordinate-mediation/2.0/keylist` - #[serde(rename = "type")] - pub message_type: String, - - /// Message body - pub body: KeylistBody, - - /// Dynamic properties. - #[serde(flatten)] - pub additional_properties: Option>, -} - #[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq)] pub struct KeylistBody { /// List of retrieved keys. @@ -579,25 +559,18 @@ mod tests { #[test] fn can_serialize_keylist_message() { - let keylist = Keylist { - id: "id_alice_keylist".to_string(), - message_type: KEYLIST_2_0.to_string(), - body: KeylistBody { - keys: vec![KeylistEntry { - recipient_did: String::from("did:key:alice_identity_pub1@alice_mediator"), - }], - pagination: Some(KeylistPagination { - count: 30, - offset: 30, - remaining: 100, - }), - }, - additional_properties: None, + let keylist = KeylistBody { + keys: vec![KeylistEntry { + recipient_did: String::from("did:key:alice_identity_pub1@alice_mediator"), + }], + pagination: Some(KeylistPagination { + count: 30, + offset: 30, + remaining: 100, + }), }; - + let keylist = json!({"body": keylist }); let expected = json!({ - "id": "id_alice_keylist", - "type": "https://didcomm.org/coordinate-mediation/2.0/keylist", "body": { "keys": [ { @@ -620,9 +593,15 @@ mod tests { #[test] fn can_deserialize_keylist_message() { + /// to structure to avoid multiple serde calls in test + /// + #[derive(Deserialize, Serialize)] + pub struct Keylist { + /// Message body + pub body: KeylistBody, + } + let msg = r#"{ - "id": "id_alice_keylist", - "type": "https://didcomm.org/coordinate-mediation/2.0/keylist", "body": { "keys": [ { @@ -637,13 +616,8 @@ mod tests { } }"#; - // Assert deserialization - let keylist: Keylist = serde_json::from_str(msg).unwrap(); - assert_eq!(&keylist.id, "id_alice_keylist"); - assert_eq!(&keylist.message_type, KEYLIST_2_0); - assert_eq!( keylist.body, KeylistBody {