Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Dec 7, 2023
1 parent 764138e commit 784828a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 47 deletions.
4 changes: 2 additions & 2 deletions aries/aries_vcx/src/common/ledger/service_didsov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod unit_tests {
ServiceType::AIP1.to_string(),
ServiceType::DIDCommV1.to_string(),
ServiceType::DIDCommV2.to_string(),
ServiceType::Other("foobar".to_string()),
"foobar".to_string(),
]));

let expected = json!({
Expand Down Expand Up @@ -124,7 +124,7 @@ mod unit_tests {
ServiceType::AIP1.to_string(),
ServiceType::DIDCommV1.to_string(),
ServiceType::DIDCommV2.to_string(),
ServiceType::Other("foobar".to_string())
"foobar".to_string()
])
);
}
Expand Down
20 changes: 1 addition & 19 deletions aries/misc/legacy/libvcx_core/src/api_vcx/api_global/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,6 @@ pub async fn ledger_write_endpoint(
endpoint: String,
) -> LibvcxResult<EndpointDidSov> {
let wallet = get_main_wallet()?;
// let service =
// DidSovEndpointAttrib::create()
// .set_service_endpoint(Url::from_str(&endpoint).map_err(|err| {
// LibvcxError::from_msg(LibvcxErrorKind::InvalidUrl, err.to_string())
// })?)
// .set_types(Some(vec![
// DidSovServiceType::Endpoint,
// DidSovServiceType::DidCommunication,
// ]))
// .set_routing_keys(Some(routing_keys));

// write_endpoint(
// wallet.as_ref(),
// get_main_ledger_write()?.as_ref(),
// target_did,
// &service,
// )

let endpoint = Url::from_str(&endpoint)
.map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidUrl, err.to_string()))?;
let mut sov_service_extras = HashMap::new();
Expand All @@ -123,7 +105,7 @@ pub async fn ledger_write_endpoint(
"#service-0".parse().unwrap(),
endpoint,
OneOrList::List(vec![ServiceType::AIP1, ServiceType::DIDCommV1]),
sov_service_extras,
HashMap::new(),
);
let (_res, endpoint_attrib) = write_endpoint_from_service(
wallet.as_ref(),
Expand Down
2 changes: 0 additions & 2 deletions did_core/did_doc/src/schema/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::schema::{
verification_method::{VerificationMethod, VerificationMethodType},
};

// TODO: Remove defaults if it turns out they are not needed. Preserved based on the original
// legacy DDO implementation.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, display_as_json::Display)]
#[serde(deny_unknown_fields)]
pub struct LegacyDidDoc {
Expand Down
41 changes: 17 additions & 24 deletions did_core/did_doc/src/schema/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ mod tests {
use std::collections::HashMap;

use did_parser::DidUrl;
use serde_json::json;

use crate::schema::{
service::{
Expand Down Expand Up @@ -198,13 +199,13 @@ mod tests {

#[test]
fn test_serde_service_aip1() {
let service_aip1: &str = r#"
{
let service_aip1 = json!({
"id": "service-0",
"type": "endpoint",
"serviceEndpoint": "https://example.com/endpoint"
}"#;
let service = serde_json::from_str::<Service>(service_aip1).unwrap();
})
.to_string();
let service = serde_json::from_str::<Service>(&service_aip1).unwrap();

assert_eq!(service.id().to_string(), "service-0");
assert_eq!(
Expand All @@ -216,23 +217,17 @@ mod tests {

#[test]
fn test_serde_service_didcomm1() {
let service_didcomm1: &str = r#"
{
let service_didcomm1 = json!({
"id": "service-0",
"type": "did-communication",
"priority": 0,
"recipientKeys": [
"did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-1"
],
"routingKeys": [
"did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-2"
],
"accept": [
"didcomm/aip2;env=rfc19"
],
"recipientKeys": ["did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-1"],
"routingKeys": [ "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-2"],
"accept": ["didcomm/aip2;env=rfc19"],
"serviceEndpoint": "https://example.com/endpoint"
}"#;
let service = serde_json::from_str::<Service>(service_didcomm1).unwrap();
})
.to_string();
let service = serde_json::from_str::<Service>(&service_didcomm1).unwrap();

assert_eq!(service.id().to_string(), "service-0");
assert_eq!(
Expand Down Expand Up @@ -278,17 +273,15 @@ mod tests {

#[test]
fn test_serde_service_didcomm2() {
let service_didcomm2: &str = r#"
{
let service_didcomm2 = json!({
"id": "service-0",
"type": "DIDCommMessaging",
"accept": [
"didcomm/v2"
],
"accept": [ "didcomm/v2"],
"routingKeys": [],
"serviceEndpoint": "https://example.com/endpoint"
}"#;
let service = serde_json::from_str::<Service>(service_didcomm2).unwrap();
})
.to_string();
let service = serde_json::from_str::<Service>(&service_didcomm2).unwrap();

assert_eq!(service.id().to_string(), "service-0");
assert_eq!(
Expand Down

0 comments on commit 784828a

Please sign in to comment.