Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add struct for CredentialStoreItem. #161

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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