Skip to content

Commit

Permalink
Merge pull request #161 from alan-turing-institute/115-selective-disc…
Browse files Browse the repository at this point in the history
…losure-ssi-update-credential-store

Add struct for CredentialStoreItem (#160).
  • Loading branch information
thobson88 committed Dec 18, 2023
2 parents d96ffdb + 8450e14 commit db8ab2f
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 92 deletions.
25 changes: 11 additions & 14 deletions trustchain-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ mod tests {
"VerifiableCredential",
"Iso18013DriversLicense"
],
"issuer": "did:ion:test:EiDSE2lEM65nYrEqVvQO5C3scYhkv1KmZzq0S0iZmNKf1Q",
"issuer": "did:ion:test:EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q",
"issuanceDate": "2023-11-23T11:43:26.806224Z",
"credentialSubject": {
"id": "did:example:12347abcd",
Expand Down Expand Up @@ -353,12 +353,10 @@ mod tests {
#[ignore = "requires a running Sidetree node listening on http://localhost:3000"]
#[tokio::test]
async fn test_verify_rss_credential() {
// **NOT** using init(), because the chain written to a temp dir in init() does not have any
// RSS keys.
// init();
init();

// DID with RSS verification method
let issuer_did_suffix = "EiDSE2lEM65nYrEqVvQO5C3scYhkv1KmZzq0S0iZmNKf1Q";
let issuer_did_suffix = "EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q";
let resolver = trustchain_resolver("http://localhost:3000/");
let vc: Credential = serde_json::from_str(UNSIGNED_DRIVERS_LICENCE_VC).unwrap();
let attestor = IONAttestor::new(issuer_did_suffix);
Expand All @@ -367,7 +365,7 @@ mod tests {
.sign(
&vc,
None,
Some("Un2E28ffH75_lvA59p7R0wUaGaACzbg8i2H9ksviS34"),
Some("QDsGIX_7NfNEaXdEeV7PJ5e_CwoH5LlF3srsCp5dcHA"),
&resolver,
&mut ContextLoader::default(),
)
Expand All @@ -379,7 +377,7 @@ mod tests {
let res = TrustchainAPI::verify_credential(
&signed_vc,
None,
1697213008,
ROOT_EVENT_TIME_1,
&verifier,
&mut context_loader,
)
Expand All @@ -391,12 +389,10 @@ mod tests {
#[ignore = "requires a running Sidetree node listening on http://localhost:3000"]
#[tokio::test]
async fn test_redact_verify_rss_credential() {
// **NOT** using init(), because the chain written to a temp dir in init() does not have any
// RSS keys.
// init();
init();

// DID with RSS verification method
let issuer_did_suffix = "did:ion:test:EiDSE2lEM65nYrEqVvQO5C3scYhkv1KmZzq0S0iZmNKf1Q";
let issuer_did_suffix = "did:ion:test:EiAtHHKFJWAk5AsM3tgCut3OiBY4ekHTf66AAjoysXL65Q";
let resolver = trustchain_resolver("http://localhost:3000/");
let vc: Credential = serde_json::from_str(UNSIGNED_DRIVERS_LICENCE_VC).unwrap();
let attestor = IONAttestor::new(issuer_did_suffix);
Expand All @@ -405,7 +401,7 @@ mod tests {
.sign(
&vc,
None,
Some("Un2E28ffH75_lvA59p7R0wUaGaACzbg8i2H9ksviS34"),
Some("QDsGIX_7NfNEaXdEeV7PJ5e_CwoH5LlF3srsCp5dcHA"),
&resolver,
&mut ContextLoader::default(),
)
Expand Down Expand Up @@ -449,15 +445,16 @@ mod tests {
let res = TrustchainAPI::verify_credential(
&signed_vc,
None,
1697213008,
ROOT_EVENT_TIME_1,
&verifier,
&mut context_loader,
)
.await;
// println!("{:?}", &res);

assert!(res.is_ok());
}

#[ignore = "requires a running Sidetree node listening on http://localhost:3000"]
#[tokio::test]
async fn test_verify_presentation() {
init();
Expand Down
6 changes: 3 additions & 3 deletions trustchain-core/src/utils.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions trustchain-http/src/data.rs

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions trustchain-http/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use hyper::StatusCode;
use serde_json::json;
use thiserror::Error;
use trustchain_core::{
commitment::CommitmentError, issuer::IssuerError, resolver::ResolverError, vc::CredentialError,
verifier::VerifierError, vp::PresentationError,
commitment::CommitmentError, issuer::IssuerError, key_manager::KeyManagerError,
resolver::ResolverError, vc::CredentialError, verifier::VerifierError, vp::PresentationError,
};
use trustchain_ion::root::TrustchainRootError;

Expand All @@ -25,6 +25,8 @@ pub enum TrustchainHTTPError {
RootError(TrustchainRootError),
#[error("Trustchain presentation error: {0}")]
PresentationError(PresentationError),
#[error("Trustchain key manager error: {0}")]
KeyManagerError(KeyManagerError),
#[error("Credential does not exist.")]
CredentialDoesNotExist,
#[error("No issuer available.")]
Expand Down Expand Up @@ -79,6 +81,12 @@ impl From<PresentationError> for TrustchainHTTPError {
}
}

impl From<KeyManagerError> for TrustchainHTTPError {
fn from(err: KeyManagerError) -> Self {
TrustchainHTTPError::KeyManagerError(err)
}
}

// See axum IntoRespone example:
// https://github.com/tokio-rs/axum/blob/main/examples/jwt/src/main.rs#L147-L160

Expand Down Expand Up @@ -114,6 +122,9 @@ impl IntoResponse for TrustchainHTTPError {
err @ TrustchainHTTPError::PresentationError(_) => {
(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
}
err @ TrustchainHTTPError::KeyManagerError(_) => {
(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
}
err @ TrustchainHTTPError::CredentialDoesNotExist => {
(StatusCode::BAD_REQUEST, err.to_string())
}
Expand Down
Loading

0 comments on commit db8ab2f

Please sign in to comment.