Skip to content

Commit

Permalink
Typed service object represents service with particular value of type…
Browse files Browse the repository at this point in the history
…s attribute

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Jan 8, 2024
1 parent e03f6cd commit c63028c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ mod tests {
]
);

println!("did_doc: {}", did_doc);
assert_eq!(did_doc.key_agreement().len(), 1);
match did_doc.key_agreement().first().unwrap() {
VerificationMethodKind::Resolved(key_agreement) => {
Expand Down
8 changes: 2 additions & 6 deletions did_core/did_doc/src/schema/service/typed/didcommv1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ServiceDidCommV1 {
Self {
service: TypedService::<ExtraFieldsDidCommV1> {
id,
service_type: OneOrList::One(ServiceType::DIDCommV1.to_string()),
service_type: ServiceType::DIDCommV1,
service_endpoint,
extra,
},
Expand All @@ -64,10 +64,6 @@ impl ServiceDidCommV1 {
self.service.id()
}

pub fn service_type(&self) -> ServiceType {
ServiceType::DIDCommV1
}

pub fn service_endpoint(&self) -> Url {
self.service.service_endpoint().clone()
}
Expand Down Expand Up @@ -102,7 +98,7 @@ impl TryFrom<ServiceDidCommV1> for Service {
Ok(Service::new(
did_comm_service.id().clone(),
did_comm_service.service_endpoint(),
OneOrList::List(vec![ServiceType::DIDCommV1]),
OneOrList::One(ServiceType::DIDCommV1),
extra_fields,
))
}
Expand Down
7 changes: 1 addition & 6 deletions did_core/did_doc/src/schema/service/typed/didcommv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::schema::{
typed::{ServiceType, TypedService},
},
types::uri::Uri,
utils::OneOrList,
};

#[derive(Serialize, Clone, Debug, PartialEq)]
Expand All @@ -33,7 +32,7 @@ impl ServiceDidCommV2 {
Self {
service: TypedService::<ExtraFieldsDidCommV2> {
id,
service_type: OneOrList::One(ServiceType::DIDCommV2.to_string()),
service_type: ServiceType::DIDCommV2,
service_endpoint,
extra,
},
Expand All @@ -44,10 +43,6 @@ impl ServiceDidCommV2 {
self.service.id()
}

pub fn service_type(&self) -> ServiceType {
ServiceType::DIDCommV2
}

pub fn service_endpoint(&self) -> Url {
self.service.service_endpoint().clone()
}
Expand Down
14 changes: 4 additions & 10 deletions did_core/did_doc/src/schema/service/typed/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
pub mod aip1;
pub mod didcommv1;
pub mod didcommv2;
pub mod legacy;

use std::{fmt::Display, str::FromStr};

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use url::Url;

use crate::{
error::DidDocumentBuilderError,
schema::{types::uri::Uri, utils::OneOrList},
};
use crate::{error::DidDocumentBuilderError, schema::types::uri::Uri};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct TypedService<E> {
pub(crate) struct TypedService<E> {
id: Uri,
#[serde(rename = "type")]
service_type: OneOrList<String>,
service_type: ServiceType,
service_endpoint: Url,
#[serde(flatten)]
extra: E,
Expand All @@ -27,10 +25,6 @@ impl<E> TypedService<E> {
&self.id
}

pub fn service_type(&self) -> &OneOrList<String> {
&self.service_type
}

pub fn service_endpoint(&self) -> &Url {
&self.service_endpoint
}
Expand Down
8 changes: 4 additions & 4 deletions did_core/did_methods/did_peer/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use did_peer::{
};
use did_resolver::traits::resolvable::resolution_output::DidResolutionOutput;

#[tokio::main]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error>> {
demo().await
}
Expand Down Expand Up @@ -59,7 +59,7 @@ async fn demo() -> Result<(), Box<dyn Error>> {
Ok(())
}

#[test]
fn demo_test() -> Result<(), Box<dyn Error>> {
demo()
#[tokio::test]
async fn demo_test() -> Result<(), Box<dyn Error>> {
demo().await
}

0 comments on commit c63028c

Please sign in to comment.