Skip to content

Commit

Permalink
fix: persist presentation_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel committed Dec 2, 2024
1 parent ef2b91e commit 77305a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
16 changes: 14 additions & 2 deletions agent_identity/src/service/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub enum ServiceResource {
pub struct Service {
#[serde(rename = "id")]
pub service_id: String,
pub presentation_ids: Vec<String>,
pub service: Option<DocumentService>,
pub resource: Option<ServiceResource>,
}
Expand Down Expand Up @@ -189,6 +190,7 @@ impl Aggregate for Service {
.type_("LinkedVerifiablePresentation")
.service_endpoint(ServiceEndpoint::from(OrderedSet::from_iter(
presentation_ids
.clone()
.into_iter()
.map(|presentation_id| {
// TODO: Find a better way to construct the URL
Expand All @@ -201,7 +203,11 @@ impl Aggregate for Service {
.build()
.expect("Failed to create Linked Verifiable Presentation Resource");

Ok(vec![LinkedVerifiablePresentationServiceCreated { service_id, service }])
Ok(vec![LinkedVerifiablePresentationServiceCreated {
service_id,
presentation_ids,
service,
}])
}
}
}
Expand All @@ -221,8 +227,13 @@ impl Aggregate for Service {
self.service.replace(service);
self.resource.replace(resource);
}
LinkedVerifiablePresentationServiceCreated { service_id, service } => {
LinkedVerifiablePresentationServiceCreated {
service_id,
service,
presentation_ids,
} => {
self.service_id = service_id;
self.presentation_ids = presentation_ids;
self.service.replace(service);
}
}
Expand Down Expand Up @@ -278,6 +289,7 @@ pub mod service_tests {
})
.then_expect_events(vec![ServiceEvent::LinkedVerifiablePresentationServiceCreated {
service_id: linked_verifiable_presentation_service_id,
presentation_ids: vec!["presentation-1".to_string()],
service: linked_verifiable_presentation_service,
}])
}
Expand Down
1 change: 1 addition & 0 deletions agent_identity/src/service/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum ServiceEvent {
},
LinkedVerifiablePresentationServiceCreated {
service_id: String,
presentation_ids: Vec<String>,
service: DocumentService,
},
}
Expand Down
7 changes: 6 additions & 1 deletion agent_identity/src/service/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ impl View<Service> for Service {
self.service.replace(service.clone());
self.resource.replace(resource.clone());
}
LinkedVerifiablePresentationServiceCreated { service_id, service } => {
LinkedVerifiablePresentationServiceCreated {
service_id,
presentation_ids,
service,
} => {
self.service_id.clone_from(service_id);
self.presentation_ids.clone_from(presentation_ids);
self.service.replace(service.clone());
}
}
Expand Down
27 changes: 13 additions & 14 deletions agent_identity/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,23 @@ pub async fn initialize(state: &IdentityState) {
..
})) => {
info!("DID Web Document already exists: {:?}", document);
return;
}
_ => {
warn!("Failed to retrieve DID Web Document");
_document_does_not_exist => {
info!("Creating new DID Web Document");

let command = DocumentCommand::CreateDocument {
did_method: did_method.clone(),
};

if command_handler(&did_method.to_string(), &state.command.document, command)
.await
.is_err()
{
warn!("Failed to create document");
}
}
}

let command = DocumentCommand::CreateDocument {
did_method: did_method.clone(),
};

if command_handler(&did_method.to_string(), &state.command.document, command)
.await
.is_err()
{
warn!("Failed to create document");
}

// If domain linkage is enabled, create the domain linkage service and add it to the document.
// TODO: Support this for other (non-deterministic) DID methods.
if config().domain_linkage_enabled {
Expand Down

0 comments on commit 77305a2

Please sign in to comment.