Skip to content

Commit

Permalink
refactor: implement IssuanceServices for signing and verifying (#98)
Browse files Browse the repository at this point in the history
* refactor: undo unnecessary changes

* docs: list all config values

* refactor: rename config file

* refactor: remove example files from docker image

* refactor: merge config files

* refactor: update .dockerignore to include all Dockerfiles and .env files

* WIP: migrate from config macro to config function

* refactor: configs for `log_format` and `event_store`

* refactor: remove unused macros calls

* refactor: migrate `url` config

* refactor: `secret_manager` config

* refactor: `credential_configurations` config

* refactor: rename `DidMethodOptions`, add config for `signing_algorithms_supported`

* refactor: determine default DID method

* refactor: remove comments, load env variables

* WIP: refactor `event_publishers` config

* refactor: remove `metadata`

* refactor: remove `config!` macro

* refactor: rename `config_2` to `config`

* chore: change example logo, disable `event_publisher`, respect `default_did_method`

* chore: resolve clippy issues

* refactor: remove `set_metadata_configuration`

* refactor: remove `TEST_METADATA`

* WIP

* test: fix tests

* ci: update docker-compose

* fix: replace `localhost` with container name

* refactor: clean up code

* chore: fix unused import

* chore: remove unused deployment scripts

* refactor: read `connection_string` inside postgres module

* refactor: rename env prefix to `UNICORE`

* feat: init `IsuanceService`

* refacotr: remove unused code

* feat: add `from_jsonwebtoken_algorithm_to_jwsalgorithm` helper function

* chore: remove unused code

* feat: add `generate_stronghold` option

* chore: update logo URI's in example config file

* chore: remove temp stronghold file

* chore: remove `example-config.yaml` file

* chore: remove unused `identity_iota` dependencies

* refactor: remove unused 'services'

* refactor: use `from_jsonwebtoken_algorithm_to_jwsalgorithm`

* fix: reset config source to `agent_application/config.yaml`

* feat: update config files

* chore: update docker-compose file

* fix: don't use `example.config.yaml` by default

---------

Co-authored-by: Daniel Mader <[email protected]>
  • Loading branch information
nanderstabel and daniel-mader committed Aug 2, 2024
1 parent a0e536d commit 560a20f
Show file tree
Hide file tree
Showing 40 changed files with 330 additions and 359 deletions.
63 changes: 54 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ edition = "2021"
rust-version = "1.76.0"

[workspace.dependencies]
did_manager = { git = "https://[email protected]/impierce/did-manager.git", rev = "b9e5594" }
did_manager = { git = "https://[email protected]/impierce/did-manager.git", rev = "2bda2b8" }
siopv2 = { git = "https://[email protected]/impierce/openid4vc.git", rev = "12fed14" }
oid4vci = { git = "https://[email protected]/impierce/openid4vc.git", rev = "12fed14" }
oid4vc-core = { git = "https://[email protected]/impierce/openid4vc.git", rev = "12fed14" }
Expand All @@ -35,6 +35,7 @@ identity_credential = { version = "1.3", default-features = false, features = [
"presentation",
"domain-linkage"
] }
identity_iota = { version = "1.3" }
jsonwebtoken = "9.3"
lazy_static = "1.4"
rstest = "0.19"
Expand Down
3 changes: 2 additions & 1 deletion agent_api_rest/src/issuance/credential_issuer/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ mod tests {
use crate::issuance::credentials::tests::credentials;
use crate::API_VERSION;
use agent_event_publisher_http::EventPublisherHttp;
use agent_issuance::services::test_utils::test_issuance_services;
use agent_issuance::{offer::event::OfferEvent, startup_commands::startup_commands, state::initialize};
use agent_shared::config::{set_config, Events};
use agent_store::{in_memory, EventPublisher};
Expand Down Expand Up @@ -297,7 +298,7 @@ mod tests {
(None, Default::default(), Default::default())
};

let issuance_state = in_memory::issuance_state(issuance_event_publishers).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), issuance_event_publishers).await;
let verification_state =
in_memory::verification_state(test_verification_services(), verification_event_publishers).await;
initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;
Expand Down
6 changes: 4 additions & 2 deletions agent_api_rest/src/issuance/credential_issuer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ pub mod tests {
};

use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_issuance::{
services::test_utils::test_issuance_services, startup_commands::startup_commands, state::initialize,
};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
Expand Down Expand Up @@ -110,7 +112,7 @@ pub mod tests {

#[tokio::test]
async fn test_token_endpoint() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ mod tests {
use crate::{app, tests::BASE_URL};

use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_issuance::{
services::test_utils::test_issuance_services, startup_commands::startup_commands, state::initialize,
};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
Expand Down Expand Up @@ -70,7 +72,7 @@ mod tests {

#[tokio::test]
async fn test_oauth_authorization_server_endpoint() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ mod tests {
use crate::{app, tests::BASE_URL};

use super::*;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_issuance::{
services::test_utils::test_issuance_services, startup_commands::startup_commands, state::initialize,
};
use agent_shared::UrlAppendHelpers;
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
Expand Down Expand Up @@ -131,7 +133,7 @@ mod tests {

#[tokio::test]
async fn test_openid_credential_issuer_endpoint() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

Expand Down
3 changes: 2 additions & 1 deletion agent_api_rest/src/issuance/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub mod tests {
app,
tests::{BASE_URL, CREDENTIAL_CONFIGURATION_ID, OFFER_ID},
};
use agent_issuance::services::test_utils::test_issuance_services;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
Expand Down Expand Up @@ -252,7 +253,7 @@ pub mod tests {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_credentials_endpoint() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
initialize(&issuance_state, startup_commands(BASE_URL.clone())).await;

Expand Down
6 changes: 4 additions & 2 deletions agent_api_rest/src/issuance/offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ pub mod tests {

use super::*;
use crate::API_VERSION;
use agent_issuance::{startup_commands::startup_commands, state::initialize};
use agent_issuance::{
services::test_utils::test_issuance_services, startup_commands::startup_commands, state::initialize,
};
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
Expand Down Expand Up @@ -154,7 +156,7 @@ pub mod tests {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_offers_endpoint() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;

let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;

Expand Down
3 changes: 2 additions & 1 deletion agent_api_rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn get_base_path() -> Result<String, ConfigError> {
mod tests {
use std::collections::HashMap;

use agent_issuance::services::test_utils::test_issuance_services;
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::routing::post;
Expand Down Expand Up @@ -182,7 +183,7 @@ mod tests {
#[tokio::test]
#[should_panic]
async fn test_base_path_routes() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
std::env::set_var("UNICORE__BASE_PATH", "unicore");
let router = app((issuance_state, verification_state));
Expand Down
3 changes: 2 additions & 1 deletion agent_api_rest/src/verification/authorization_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub(crate) async fn authorization_requests(
pub mod tests {
use super::*;
use crate::app;
use agent_issuance::services::test_utils::test_issuance_services;
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
Expand Down Expand Up @@ -220,7 +221,7 @@ pub mod tests {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_authorization_requests_endpoint(#[case] by_value: bool) {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
let mut app = app((issuance_state, verification_state));

Expand Down
3 changes: 2 additions & 1 deletion agent_api_rest/src/verification/relying_party/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub mod tests {
verification::{authorization_requests::tests::authorization_requests, relying_party::request::tests::request},
};
use agent_event_publisher_http::EventPublisherHttp;
use agent_issuance::services::test_utils::test_issuance_services;
use agent_secret_manager::{secret_manager, subject::Subject};
use agent_shared::config::{set_config, Events};
use agent_store::{in_memory, EventPublisher};
Expand Down Expand Up @@ -161,7 +162,7 @@ pub mod tests {

let event_publishers = vec![Box::new(EventPublisherHttp::load().unwrap()) as Box<dyn EventPublisher>];

let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), event_publishers).await;

let mut app = app((issuance_state, verification_state));
Expand Down
3 changes: 2 additions & 1 deletion agent_api_rest/src/verification/relying_party/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) async fn request(
pub mod tests {
use super::*;
use crate::{app, verification::authorization_requests::tests::authorization_requests};
use agent_issuance::services::test_utils::test_issuance_services;
use agent_store::in_memory;
use agent_verification::services::test_utils::test_verification_services;
use axum::{
Expand Down Expand Up @@ -69,7 +70,7 @@ pub mod tests {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_request_endpoint() {
let issuance_state = in_memory::issuance_state(Default::default()).await;
let issuance_state = in_memory::issuance_state(test_issuance_services(), Default::default()).await;
let verification_state = in_memory::verification_state(test_verification_services(), Default::default()).await;
let mut app = app((issuance_state, verification_state));

Expand Down
6 changes: 3 additions & 3 deletions agent_application/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
UNICORE__LOG_FORMAT: text
UNICORE__EVENT_STORE__TYPE: postgres
UNICORE__EVENT_STORE__CONNECTION_STRING: postgresql://demo_user:demo_pass@cqrs-postgres-db:5432/demo
UNICORE__URL: http://192.168.1.234:3033
UNICORE__URL: ${UNICORE__URL}

UNICORE__SECRET_MANAGER__STRONGHOLD_PATH: "/app/res/stronghold"
UNICORE__SECRET_MANAGER__STRONGHOLD_PASSWORD: "secure_password"
Expand All @@ -48,8 +48,8 @@ services:
# UNICORE__SECRET_MANAGER__ISSUER_DID: "did:iota:rms:0x42ad588322e58b3c07aa39e4948d021ee17ecb5747915e9e1f35f028d7ecaf90"
# UNICORE__SECRET_MANAGER__ISSUER_FRAGMENT: "bQKQRzaop7CgEvqVq8UlgLGsdF-R-hnLFkKFZqW2VN0"
volumes:
- ../../agent_application/example-config.yaml:/app/agent_application/example-config.yaml
- ../../agent_secret_manager/tests/res/test.stronghold:/app/res/stronghold
- ../../agent_application/config.yaml:/app/agent_application/config.yaml
# - ../../agent_secret_manager/tests/res/test.stronghold:/app/res/stronghold
- ../../agent_verification/presentation_definitions:/app/agent_verification/presentation_definitions
# TODO: Remove this. This is a workaround that ensures that the `agent_verification/presentation_definitions`
# folder can be accessed by the agent from the `fn authorization_requests` endpoint.
Expand Down
Loading

0 comments on commit 560a20f

Please sign in to comment.