Skip to content

Commit

Permalink
Update ssi and improve VC API (#360)
Browse files Browse the repository at this point in the history
Including:
- return 400 on failed verifications
- populating issuance date on issuance if not present
  • Loading branch information
sbihel committed Jun 28, 2023
1 parent 3597378 commit 2cf0707
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
suite: ["vc-api-issuer-test-suite"] # "di-ed25519-test-suite", "did-key-test-suite", "vc-api-verifier-test-suite"
# di-ed25519-test-suite fails one test because issuer != proof VM
# did-key-test-suite requires more checks in ssi
suite: ["vc-api-issuer-test-suite", "di-eddsa-2022-test-suite", "vc-api-verifier-test-suite"] # "di-ed25519-test-suite", "did-key-test-suite"]
steps:
- name: Checkout DIDKit repository
uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "http/tests/did-key-test-suite"]
path = http/tests/did-key-test-suite
url = https://github.com/w3c-ccg/did-key-test-suite.git
[submodule "http/tests/di-eddsa-2022-test-suite"]
path = http/tests/di-eddsa-2022-test-suite
url = https://github.com/w3c-ccg/di-eddsa-2022-test-suite.git
11 changes: 9 additions & 2 deletions http/src/credentials.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Context;
use axum::{http::StatusCode, Extension, Json};
use didkit::{
ssi::ldp::Error as LdpError, ContextLoader, CredentialOrJWT, JWTOrLDPOptions, ProofFormat,
VerifiableCredential, VerificationResult, DID_METHODS,
ssi::ldp::{now_ms, Error as LdpError},
ContextLoader, CredentialOrJWT, JWTOrLDPOptions, ProofFormat, VerifiableCredential,
VerificationResult, DID_METHODS,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -33,6 +34,9 @@ pub async fn issue(
Some(key) => key,
None => return Err((StatusCode::NOT_FOUND, "Missing key".to_string()).into()),
};
if credential.issuance_date.is_none() {
credential.issuance_date = Some(now_ms().into());
}
if let Err(e) = credential.validate_unsigned() {
return Err((StatusCode::BAD_REQUEST, e.to_string()).into());
}
Expand Down Expand Up @@ -114,5 +118,8 @@ pub async fn verify(
return Err((StatusCode::BAD_REQUEST, err_msg).into());
}
};
if !res.errors.is_empty() {
return Err((StatusCode::BAD_REQUEST, format!("{:?}", res.errors)).into());
}
Ok(Json(res))
}
3 changes: 3 additions & 0 deletions http/src/presentations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,8 @@ pub async fn verify(Json(req): Json<VerifyRequest>) -> Result<Json<VerificationR
return Err((StatusCode::BAD_REQUEST, err_msg).into());
}
};
if !res.errors.is_empty() {
return Err((StatusCode::BAD_REQUEST, format!("{:?}", res.errors)).into());
}
Ok(Json(res))
}
1 change: 1 addition & 0 deletions http/tests/di-eddsa-2022-test-suite
9 changes: 8 additions & 1 deletion http/tests/vcApiTestImplementationsConfig.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ module.exports = [{
"type": "Ed25519Signature2020"
},
"tags": ["vc-api", "Ed25519Signature2020", "JWT"]
}, {
"id": "did:key:z6MkgYAGxLBSXa6Ygk1PnUbK2F7zya8juE9nfsZhrvY7c9GD",
"endpoint": "https://127.0.0.1:9000/credentials/issue",
"options": {
"type": "DataIntegrityProof"
},
"tags": ["vc-api", "eddsa-2022", "JWT"]
}],
"verifiers": [{
"id": "https://spruceid.com",
"endpoint": "https://127.0.0.1:9000/credentials/verify",
"tags": ["vc-api", "Ed25519Signature2020", "JWT"]
"tags": ["vc-api", "Ed25519Signature2020", "JWT", "eddsa-2022"]
}],
"didResolvers": [{
"id": "https://spruceid.com",
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ http-did = ["ssi/http-did"]
ring = ["ssi/ring"]

[dependencies]
ssi = { version = "0.6", path = "../../ssi", default-features = false }
ssi = { version = "0.7.0", path = "../../ssi", default-features = false }
did-method-key = { version = "0.2.0", path = "../../ssi/did-key", default-features = false }
did-tz = { version = "0.2.0", path = "../../ssi/did-tezos" }
did-ethr = { version = "0.2", path = "../../ssi/did-ethr", default-features = false }
Expand Down

0 comments on commit 2cf0707

Please sign in to comment.