-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mediator coordination messages to aries-vcx messages crate (#1052)
* Add support for mediator coordination messages Signed-off-by: Naian <[email protected]>
- Loading branch information
1 parent
4b009f1
commit 4263dd7
Showing
16 changed files
with
670 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
messages/src/msg_fields/protocols/coordinate_mediation/keylist.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::{decorators::thread::Thread, msg_parts::MsgParts}; | ||
|
||
/// https://github.com/hyperledger/aries-rfcs/blob/main/features/0211-route-coordination/README.md#key-list | ||
pub type Keylist = MsgParts<KeylistContent, KeylistDecorators>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistContent { | ||
pub keys: Vec<KeylistItem>, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pagination: Option<KeylistPagination>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistItem { | ||
pub recipient_key: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistPagination { | ||
count: u64, | ||
offset: u64, | ||
remaining: u64, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
|
||
use super::*; | ||
use crate::{ | ||
misc::test_utils, msg_types::protocols::coordinate_mediation::CoordinateMediationTypeV1_0, | ||
}; | ||
|
||
#[test] | ||
fn test_keylist() { | ||
let expected = json!( | ||
{ | ||
"@id": "123456781", | ||
"@type": "https://didcomm.org/coordinate-mediation/1.0/keylist", | ||
"keys": [ | ||
{ | ||
"recipient_key": "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH" | ||
} | ||
], | ||
"pagination": { | ||
"count": 30, | ||
"offset": 30, | ||
"remaining": 100 | ||
} | ||
} | ||
); | ||
let key_item = KeylistItem::builder() | ||
.recipient_key("did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH".to_owned()) | ||
.build(); | ||
let pagination_state = KeylistPagination::builder() | ||
.count(30) | ||
.offset(30) | ||
.remaining(100) | ||
.build(); | ||
let content = KeylistContent::builder() | ||
.pagination(pagination_state) | ||
.keys(vec![key_item]) | ||
.build(); | ||
let decorators = KeylistDecorators::builder().build(); | ||
|
||
test_utils::test_msg( | ||
content, | ||
decorators, | ||
CoordinateMediationTypeV1_0::Keylist, | ||
expected, | ||
); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
messages/src/msg_fields/protocols/coordinate_mediation/keylist_query.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::{decorators::thread::Thread, msg_parts::MsgParts}; | ||
|
||
/// https://github.com/hyperledger/aries-rfcs/blob/main/features/0211-route-coordination/README.md#key-list-query | ||
pub type KeylistQuery = MsgParts<KeylistQueryContent>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistQueryContent { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
paginate: Option<KeylistQueryPaginateParams>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistQueryPaginateParams { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
limit: Option<u64>, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
offset: Option<u64>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistQueryDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
use shared_vcx::misc::serde_ignored::SerdeIgnored as NoDecorators; | ||
|
||
use super::*; | ||
use crate::{ | ||
misc::test_utils, msg_types::protocols::coordinate_mediation::CoordinateMediationTypeV1_0, | ||
}; | ||
|
||
#[test] | ||
fn test_keylist_query() { | ||
let expected = json!( | ||
{ | ||
"@id": "123456781", | ||
"@type": "https://didcomm.org/coordinate-mediation/1.0/keylist-query", | ||
"paginate": { | ||
"limit": 30, | ||
"offset": 0 | ||
} | ||
} | ||
); | ||
let paginate_params = KeylistQueryPaginateParams::builder() | ||
.limit(30) | ||
.offset(0) | ||
.build(); | ||
let content = KeylistQueryContent::builder() | ||
.paginate(paginate_params) | ||
.build(); | ||
|
||
test_utils::test_msg( | ||
content, | ||
NoDecorators, | ||
CoordinateMediationTypeV1_0::KeylistQuery, | ||
expected, | ||
); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
messages/src/msg_fields/protocols/coordinate_mediation/keylist_update.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::{decorators::thread::Thread, msg_parts::MsgParts}; | ||
|
||
/// https://github.com/hyperledger/aries-rfcs/blob/main/features/0211-route-coordination/README.md#keylist-update | ||
pub type KeylistUpdate = MsgParts<KeylistUpdateContent>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistUpdateContent { | ||
pub updates: Vec<KeylistUpdateItem>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, TypedBuilder)] | ||
pub struct KeylistUpdateItem { | ||
pub recipient_key: String, | ||
pub action: KeylistUpdateItemAction, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] | ||
pub enum KeylistUpdateItemAction { | ||
#[serde(rename = "add")] | ||
Add, | ||
#[serde(rename = "remove")] | ||
Remove, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistUpdateDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
use shared_vcx::misc::serde_ignored::SerdeIgnored as NoDecorators; | ||
|
||
use super::*; | ||
use crate::{ | ||
misc::test_utils, msg_types::protocols::coordinate_mediation::CoordinateMediationTypeV1_0, | ||
}; | ||
|
||
#[test] | ||
fn test_key_list_update() { | ||
let expected = json!( | ||
{ | ||
"@id": "123456781", | ||
"@type": "https://didcomm.org/coordinate-mediation/1.0/keylist-update", | ||
"updates":[ | ||
{ | ||
"recipient_key": "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH", | ||
"action": "add" | ||
} | ||
] | ||
} | ||
); | ||
let update_item1 = KeylistUpdateItem::builder() | ||
.recipient_key("did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH".to_owned()) | ||
.action(KeylistUpdateItemAction::Add) | ||
.build(); | ||
let content = KeylistUpdateContent::builder() | ||
.updates(vec![update_item1]) | ||
.build(); | ||
test_utils::test_msg( | ||
content, | ||
NoDecorators, | ||
CoordinateMediationTypeV1_0::KeylistUpdate, | ||
expected, | ||
); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
messages/src/msg_fields/protocols/coordinate_mediation/keylist_update_response.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use super::keylist_update::KeylistUpdateItemAction; | ||
use crate::{decorators::thread::Thread, msg_parts::MsgParts}; | ||
|
||
/// https://github.com/hyperledger/aries-rfcs/blob/main/features/0211-route-coordination/README.md#keylist-update-response | ||
pub type KeylistUpdateResponse = | ||
MsgParts<KeylistUpdateResponseContent, KeylistUpdateResponseDecorators>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistUpdateResponseContent { | ||
pub updated: Vec<KeylistUpdateResponseItem>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, TypedBuilder)] | ||
pub struct KeylistUpdateResponseItem { | ||
pub recipient_key: String, | ||
pub action: KeylistUpdateItemAction, | ||
pub result: KeylistUpdateItemResult, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] | ||
pub enum KeylistUpdateItemResult { | ||
#[serde(rename = "client_error")] | ||
ClientError, | ||
#[serde(rename = "server_error")] | ||
ServerError, | ||
#[serde(rename = "no_change")] | ||
NoChange, | ||
#[serde(rename = "success")] | ||
Success, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct KeylistUpdateResponseDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
|
||
use super::*; | ||
use crate::{ | ||
misc::test_utils, msg_types::protocols::coordinate_mediation::CoordinateMediationTypeV1_0, | ||
}; | ||
|
||
#[test] | ||
fn test_keylist_update_response() { | ||
let expected = json!( | ||
{ | ||
"@id": "123456781", | ||
"@type": "https://didcomm.org/coordinate-mediation/1.0/keylist-update-response", | ||
"updated": [ | ||
{ | ||
"recipient_key": "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH", | ||
"action": "add", // "add" or "remove" | ||
"result": "client_error" // [client_error | server_error | no_change | success] | ||
} | ||
] | ||
} | ||
); | ||
let update_item1 = KeylistUpdateResponseItem::builder() | ||
.recipient_key("did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH".to_owned()) | ||
.action(KeylistUpdateItemAction::Add) | ||
.result(KeylistUpdateItemResult::ClientError) | ||
.build(); | ||
let content = KeylistUpdateResponseContent::builder() | ||
.updated(vec![update_item1]) | ||
.build(); | ||
let decorators = KeylistUpdateResponseDecorators::builder().build(); | ||
|
||
test_utils::test_msg( | ||
content, | ||
decorators, | ||
CoordinateMediationTypeV1_0::KeylistUpdateResponse, | ||
expected, | ||
); | ||
} | ||
} |
Oops, something went wrong.