Skip to content

Commit e1107c7

Browse files
committed
feat: add VerificationMethod aggregate and related components
1 parent 2d0a39b commit e1107c7

File tree

13 files changed

+224
-3
lines changed

13 files changed

+224
-3
lines changed

agent_event_publisher_http/src/lib.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use agent_authorization::domain::{
44
};
55
use agent_holder::presentation::aggregate::Presentation;
66
use agent_identity::{
7-
connection::aggregate::Connection, document::aggregate::Document, profile::aggregate::Profile,
7+
connection::aggregate::Connection,
8+
document::aggregate::Document,
9+
profile::aggregate::Profile,
810
service::aggregate::Service,
11+
verification_method::{self, aggregate::VerificationMethod},
912
};
1013
use agent_issuance::{
1114
credential::aggregate::Credential, offer::aggregate::Offer, server_config::aggregate::ServerConfig,
@@ -17,7 +20,7 @@ use agent_store::{
1720
ClientEventPublisher, ConnectionEventPublisher, CredentialEventPublisher, DocumentEventPublisher, EventPublisher,
1821
HolderCredentialEventPublisher, OAuth2AuthorizationRequestEventPublisher, OfferEventPublisher,
1922
PresentationEventPublisher, ProfileEventPublisher, ReceivedOfferEventPublisher, ServerConfigEventPublisher,
20-
ServiceEventPublisher, TemplateEventPublisher,
23+
ServiceEventPublisher, TemplateEventPublisher, VerificationMethodEventPublisher,
2124
};
2225
use agent_verification::authorization_request::aggregate::AuthorizationRequest;
2326
use async_trait::async_trait;
@@ -41,6 +44,7 @@ pub struct EventPublisherHttp {
4144
pub document: Option<AggregateEventPublisherHttp<Document>>,
4245
pub profile: Option<AggregateEventPublisherHttp<Profile>>,
4346
pub service: Option<AggregateEventPublisherHttp<Service>>,
47+
pub verification_method: Option<AggregateEventPublisherHttp<VerificationMethod>>,
4448

4549
// Library
4650
pub template: Option<AggregateEventPublisherHttp<Template>>,
@@ -173,6 +177,19 @@ impl EventPublisherHttp {
173177
)
174178
});
175179

180+
let verification_method = (!event_publisher_http.events.verification_method.is_empty()).then(|| {
181+
AggregateEventPublisherHttp::<VerificationMethod>::new(
182+
event_publisher_http.target_url.clone(),
183+
event_publisher_http.headers.clone(),
184+
event_publisher_http
185+
.events
186+
.verification_method
187+
.iter()
188+
.map(ToString::to_string)
189+
.collect(),
190+
)
191+
});
192+
176193
let template = (!event_publisher_http.events.template.is_empty()).then(|| {
177194
AggregateEventPublisherHttp::<Template>::new(
178195
event_publisher_http.target_url.clone(),
@@ -286,6 +303,7 @@ impl EventPublisherHttp {
286303
document,
287304
profile,
288305
service,
306+
verification_method,
289307
template,
290308
server_config,
291309
credential,
@@ -327,6 +345,12 @@ impl EventPublisher for EventPublisherHttp {
327345
.map(|publisher| Box::new(publisher) as ServiceEventPublisher)
328346
}
329347

348+
fn verification_method(&mut self) -> Option<VerificationMethodEventPublisher> {
349+
self.verification_method
350+
.take()
351+
.map(|publisher| Box::new(publisher) as VerificationMethodEventPublisher)
352+
}
353+
330354
fn template(&mut self) -> Option<TemplateEventPublisher> {
331355
self.template
332356
.take()

agent_identity/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod connection;
33
pub mod document;
44
pub mod profile;
55
pub mod service;
6+
pub mod verification_method;
67

78
pub mod services;
89
pub mod state;

agent_identity/src/state.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use crate::profile::aggregate::{Profile, Source};
88
use crate::profile::command::ProfileCommand;
99
use crate::profile::views::ProfileView;
1010
use crate::service::views::all_services::AllServicesView;
11+
use crate::verification_method::aggregate::VerificationMethod;
12+
use crate::verification_method::views::all_verification_methods::AllVerificationMethodsView;
13+
use crate::verification_method::views::VerificationMethodView;
1114
use crate::{
1215
document::{aggregate::Document, views::DocumentView},
1316
service::{aggregate::Service, command::ServiceCommand, views::ServiceView},
@@ -43,6 +46,7 @@ pub struct CommandHandlers {
4346
pub document: CommandHandler<Document>,
4447
pub profile: CommandHandler<Profile>,
4548
pub service: CommandHandler<Service>,
49+
pub verification_method: CommandHandler<VerificationMethod>,
4650
}
4751

4852
/// This type is used to define the queries that are used to query the view repositories. We make use of `dyn` here, so
@@ -56,9 +60,11 @@ type Queries = ViewRepositories<
5660
dyn ViewRepository<ProfileView, Profile>,
5761
dyn ViewRepository<ServiceView, Service>,
5862
dyn ViewRepository<AllServicesView, Service>,
63+
dyn ViewRepository<VerificationMethodView, VerificationMethod>,
64+
dyn ViewRepository<AllVerificationMethodsView, VerificationMethod>,
5965
>;
6066

61-
pub struct ViewRepositories<C1, C2, D1, D2, P, S1, S2>
67+
pub struct ViewRepositories<C1, C2, D1, D2, P, S1, S2, VM1, VM2>
6268
where
6369
C1: ViewRepository<ConnectionView, Connection> + ?Sized,
6470
C2: ViewRepository<AllConnectionsView, Connection> + ?Sized,
@@ -67,6 +73,8 @@ where
6773
P: ViewRepository<ProfileView, Profile> + ?Sized,
6874
S1: ViewRepository<ServiceView, Service> + ?Sized,
6975
S2: ViewRepository<AllServicesView, Service> + ?Sized,
76+
VM1: ViewRepository<VerificationMethodView, VerificationMethod> + ?Sized,
77+
VM2: ViewRepository<AllVerificationMethodsView, VerificationMethod> + ?Sized,
7078
{
7179
pub connection: Arc<C1>,
7280
pub all_connections: Arc<C2>,
@@ -75,6 +83,8 @@ where
7583
pub profile: Arc<P>,
7684
pub service: Arc<S1>,
7785
pub all_services: Arc<S2>,
86+
pub verification_method: Arc<VM1>,
87+
pub all_verification_methods: Arc<VM2>,
7888
}
7989

8090
impl Clone for Queries {
@@ -87,6 +97,8 @@ impl Clone for Queries {
8797
profile: self.profile.clone(),
8898
service: self.service.clone(),
8999
all_services: self.all_services.clone(),
100+
verification_method: self.verification_method.clone(),
101+
all_verification_methods: self.all_verification_methods.clone(),
90102
}
91103
}
92104
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Service
2+
3+
This aggregate holds everything related to a service:
4+
- id
5+
- service (DID Document Service)
6+
- resource (e.g. Domain Linkage resource)
7+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use super::{command::VerificationMethodCommand, error::VerificationMethodError, event::VerificationMethodEvent};
2+
use agent_shared::config::config;
3+
use async_trait::async_trait;
4+
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
5+
use cqrs_es::Aggregate;
6+
use identity_core::{
7+
common::{Duration, OrderedSet, Timestamp},
8+
convert::{FromJson, ToJson},
9+
};
10+
use identity_credential::{
11+
credential::Jwt,
12+
domain_linkage::{DomainLinkageConfiguration, DomainLinkageCredentialBuilder},
13+
};
14+
use identity_did::DIDUrl;
15+
use jsonwebtoken::{Algorithm, Header};
16+
use oid4vc_core::Sign as _;
17+
use serde::{Deserialize, Serialize};
18+
use serde_json::json;
19+
use std::{str::FromStr as _, sync::Arc};
20+
use tracing::{debug, info};
21+
22+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
23+
pub struct VerificationMethod {
24+
#[serde(rename = "id")]
25+
pub verification_method_id: String,
26+
pub alias: Option<String>,
27+
pub key_id: Option<String>,
28+
pub signing_algorithm: Option<String>,
29+
}
30+
31+
#[async_trait]
32+
impl Aggregate for VerificationMethod {
33+
type Command = VerificationMethodCommand;
34+
type Event = VerificationMethodEvent;
35+
type Error = VerificationMethodError;
36+
type Services = ();
37+
38+
fn aggregate_type() -> String {
39+
"verification_method".to_string()
40+
}
41+
42+
async fn handle(&self, command: Self::Command, services: &Self::Services) -> Result<Vec<Self::Event>, Self::Error> {
43+
use VerificationMethodCommand::*;
44+
use VerificationMethodError::*;
45+
use VerificationMethodEvent::*;
46+
47+
info!("Handling command: {:?}", command);
48+
49+
match command {}
50+
}
51+
52+
fn apply(&mut self, event: Self::Event) {
53+
use VerificationMethodEvent::*;
54+
55+
debug!("Applying event: {:?}", event);
56+
57+
match event {}
58+
}
59+
}
60+
61+
#[cfg(test)]
62+
pub mod verification_method_tests {
63+
use super::test_utils::*;
64+
use super::*;
65+
use crate::document::aggregate::test_utils::both_verification_methods;
66+
use agent_shared::config::set_config;
67+
use cqrs_es::test::TestFramework;
68+
use identity_iota::verification::VerificationMethod;
69+
use rstest::rstest;
70+
71+
type VerificationMethodTestFramework = TestFramework<VerificationMethod>;
72+
}
73+
74+
#[cfg(feature = "test_utils")]
75+
pub mod test_utils {
76+
use super::*;
77+
use identity_core::{common::Url, convert::FromJson};
78+
use rstest::*;
79+
use serde_json::json;
80+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[derive(Debug)]
2+
pub enum VerificationMethodCommand {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use thiserror::Error;
2+
3+
#[derive(Error, Debug)]
4+
pub enum VerificationMethodError {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use cqrs_es::DomainEvent;
2+
use derivative::Derivative;
3+
use serde::{Deserialize, Serialize};
4+
use strum::Display;
5+
6+
#[derive(Clone, Debug, Deserialize, Serialize, Derivative, Display)]
7+
#[derivative(PartialEq)]
8+
pub enum VerificationMethodEvent {}
9+
10+
impl DomainEvent for VerificationMethodEvent {
11+
fn event_type(&self) -> String {
12+
self.to_string()
13+
}
14+
15+
fn event_version(&self) -> String {
16+
"1".to_string()
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod aggregate;
2+
pub mod command;
3+
pub mod error;
4+
pub mod event;
5+
pub mod views;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::VerificationMethodView;
2+
use crate::verification_method::aggregate::VerificationMethod;
3+
use cqrs_es::{EventEnvelope, View};
4+
use serde::{Deserialize, Serialize};
5+
use std::collections::HashMap;
6+
7+
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
8+
pub struct AllVerificationMethodsView {
9+
#[serde(flatten)]
10+
pub verification_methods: HashMap<String, VerificationMethodView>,
11+
}
12+
13+
impl View<VerificationMethod> for AllVerificationMethodsView {
14+
fn update(&mut self, event: &EventEnvelope<VerificationMethod>) {
15+
self.verification_methods
16+
// Get the entry for the aggregate_id
17+
.entry(event.aggregate_id.clone())
18+
// or insert a new one if it doesn't exist
19+
.or_default()
20+
// update the view with the event
21+
.update(event);
22+
}
23+
}

0 commit comments

Comments
 (0)