Skip to content

Commit

Permalink
fix: PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel committed Jul 3, 2023
1 parent 1209fdd commit 2e287c2
Show file tree
Hide file tree
Showing 27 changed files with 121 additions and 120 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ getset = "0.1"

# TODO: Fix these dependencies once publishing to crates.io is automated.
[dependencies]
oid4vc-core = { path = "oid4vc-core" }
oid4vci = { path = "oid4vci" }
oid4vp = { path = "oid4vp" }
siopv2 = { path = "siopv2" }
Expand Down
4 changes: 2 additions & 2 deletions oid4vc-core/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
mod tests {
use super::*;
use crate::{
test_utils::{MockSubject, MockVerifier},
test_utils::{MockVerifier, TestSubject},
Verify,
};
use serde_json::{json, Value};
Expand All @@ -94,7 +94,7 @@ mod tests {
"iat": 1593436422,
"nonce": "nonce",
});
let subject = MockSubject::new("did:mock:123".to_string(), "key_id".to_string()).unwrap();
let subject = TestSubject::new("did:test:123".to_string(), "key_id".to_string()).unwrap();
let encoded = encode(Arc::new(subject), claims).await.unwrap();

let verifier = MockVerifier::new();
Expand Down
22 changes: 11 additions & 11 deletions oid4vc-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@ use rand::rngs::OsRng;

// Keypair for mocking purposes.
lazy_static! {
pub static ref MOCK_KEYPAIR: Keypair = Keypair::generate(&mut OsRng);
pub static ref TEST_KEYPAIR: Keypair = Keypair::generate(&mut OsRng);
}

#[derive(Derivative)]
#[derivative(Default)]
pub struct MockSubject {
#[derivative(Default(value = "did_url::DID::parse(\"did:mock:123\").unwrap()"))]
pub struct TestSubject {
#[derivative(Default(value = "did_url::DID::parse(\"did:test:123\").unwrap()"))]
pub did: did_url::DID,
pub key_id: String,
}

impl MockSubject {
impl TestSubject {
pub fn new(did: String, key_id: String) -> Result<Self> {
Ok(MockSubject {
Ok(TestSubject {
did: did_url::DID::parse(did)?,
key_id,
})
}
}

#[async_trait]
impl Sign for MockSubject {
impl Sign for TestSubject {
fn key_id(&self) -> Option<String> {
Some(self.key_id.clone())
}

async fn sign(&self, message: &str) -> Result<Vec<u8>> {
let signature: Signature = MOCK_KEYPAIR.sign(message.as_bytes());
let signature: Signature = TEST_KEYPAIR.sign(message.as_bytes());
Ok(signature.to_bytes().to_vec())
}
}

#[async_trait]
impl Verify for MockSubject {
impl Verify for TestSubject {
async fn public_key(&self, _kid: &str) -> Result<Vec<u8>> {
Ok(MOCK_KEYPAIR.public.to_bytes().to_vec())
Ok(TEST_KEYPAIR.public.to_bytes().to_vec())
}
}

impl Subject for MockSubject {
impl Subject for TestSubject {
fn identifier(&self) -> Result<String> {
Ok(self.did.to_string())
}
Expand All @@ -64,6 +64,6 @@ impl MockVerifier {
#[async_trait]
impl Verify for MockVerifier {
async fn public_key(&self, _kid: &str) -> Result<Vec<u8>> {
Ok(MOCK_KEYPAIR.public.to_bytes().to_vec())
Ok(TEST_KEYPAIR.public.to_bytes().to_vec())
}
}
3 changes: 2 additions & 1 deletion oid4vc-manager/src/managers/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use oid4vp::{
PresentationSubmission,
};

/// Takes a [`PresentationDefinition`] and a credential and creates a [`PresentationSubmission`] from it if the credential .
/// Takes a [`PresentationDefinition`] and a credential and creates a [`PresentationSubmission`] from it if the
/// credential meets the requirements.
// TODO: make VP/VC fromat agnostic. In current form only jwt_vp_json + jwt_vc_json are supported.
pub fn create_presentation_submission(
presentation_definition: &PresentationDefinition,
Expand Down
22 changes: 11 additions & 11 deletions oid4vc-manager/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,46 @@ use siopv2::{StandardClaimsRequests, StandardClaimsValues};

// Keypair for mocking purposes.
lazy_static! {
pub static ref MOCK_KEYPAIR: Keypair = Keypair::generate(&mut OsRng);
pub static ref TEST_KEYPAIR: Keypair = Keypair::generate(&mut OsRng);
}

#[derive(Derivative)]
#[derivative(Default)]
pub struct MockSubject {
#[derivative(Default(value = "did_url::DID::parse(\"did:mock:123\").unwrap()"))]
pub struct TestSubject {
#[derivative(Default(value = "did_url::DID::parse(\"did:test:123\").unwrap()"))]
pub did: did_url::DID,
pub key_id: String,
}

impl MockSubject {
impl TestSubject {
pub fn new(did: String, key_id: String) -> Result<Self> {
Ok(MockSubject {
Ok(TestSubject {
did: did_url::DID::parse(did)?,
key_id,
})
}
}

#[async_trait]
impl Sign for MockSubject {
impl Sign for TestSubject {
fn key_id(&self) -> Option<String> {
Some(self.key_id.clone())
}

async fn sign(&self, message: &str) -> Result<Vec<u8>> {
let signature: Signature = MOCK_KEYPAIR.sign(message.as_bytes());
let signature: Signature = TEST_KEYPAIR.sign(message.as_bytes());
Ok(signature.to_bytes().to_vec())
}
}

#[async_trait]
impl Verify for MockSubject {
impl Verify for TestSubject {
async fn public_key(&self, _kid: &str) -> Result<Vec<u8>> {
Ok(MOCK_KEYPAIR.public.to_bytes().to_vec())
Ok(TEST_KEYPAIR.public.to_bytes().to_vec())
}
}

impl Subject for MockSubject {
impl Subject for TestSubject {
fn identifier(&self) -> Result<String> {
Ok(self.did.to_string())
}
Expand All @@ -66,7 +66,7 @@ impl MockVerifier {
#[async_trait]
impl Verify for MockVerifier {
async fn public_key(&self, _kid: &str) -> Result<Vec<u8>> {
Ok(MOCK_KEYPAIR.public.to_bytes().to_vec())
Ok(TEST_KEYPAIR.public.to_bytes().to_vec())
}
}

Expand Down
16 changes: 8 additions & 8 deletions oid4vc-manager/tests/siopv2/implicit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::common::{MemoryStorage, MockSubject, Storage};
use crate::common::{MemoryStorage, Storage, TestSubject};
use chrono::{Duration, Utc};
use lazy_static::lazy_static;
use oid4vc_core::{DidMethod, SubjectSyntaxType};
Expand Down Expand Up @@ -52,9 +52,9 @@ async fn test_implicit_flow() {
let server_url = mock_server.uri();

// Create a new subject.
let subject = MockSubject::new(
"did:mock:relying_party".to_string(),
"did:mock:relying_party#key_id".to_string(),
let subject = TestSubject::new(
"did:test:relying_party".to_string(),
"did:test:relying_party#key_id".to_string(),
)
.unwrap();

Expand All @@ -64,14 +64,14 @@ async fn test_implicit_flow() {
// Create a new RequestUrl with response mode `post` for cross-device communication.
let request: AuthorizationRequest = RequestUrl::builder()
.response_type(ResponseType::IdToken)
.client_id("did:mock:relyingparty".to_string())
.client_id("did:test:relyingparty".to_string())
.scope(Scope::from(vec![ScopeValue::OpenId, ScopeValue::Phone]))
.redirect_uri(format!("{server_url}/redirect_uri"))
.response_mode("post".to_string())
.client_metadata(
ClientMetadata::default()
.with_subject_syntax_types_supported(vec![SubjectSyntaxType::Did(
DidMethod::from_str("did:mock").unwrap(),
DidMethod::from_str("did:test").unwrap(),
)])
.with_id_token_signing_alg_values_supported(vec!["EdDSA".to_string()]),
)
Expand Down Expand Up @@ -111,14 +111,14 @@ async fn test_implicit_flow() {
let storage = MemoryStorage::new(serde_json::from_value(USER_CLAIMS.clone()).unwrap());

// Create a new subject and validator.
let subject = MockSubject::new("did:mock:subject".to_string(), "did:mock:subject#key_id".to_string()).unwrap();
let subject = TestSubject::new("did:test:subject".to_string(), "did:test:subject#key_id".to_string()).unwrap();

// Create a new provider manager.
let provider_manager = ProviderManager::new([Arc::new(subject)]).unwrap();

// Create a new RequestUrl which includes a `request_uri` pointing to the mock server's `request_uri` endpoint.
let request_url = RequestUrl::builder()
.client_id("did:mock:relyingparty".to_string())
.client_id("did:test:relyingparty".to_string())
.request_uri(format!("{server_url}/request_uri"))
.build()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/credentials/jwt_vc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/request/pd_ac_vc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
}
}
]
}
}
76 changes: 38 additions & 38 deletions oid4vp/tests/examples/request/pd_ac_vc_sd.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"id": "example_vc_ac_sd",
"input_descriptors": [
{
"id": "id_credential",
"format": {
"ac_vc": {
"proof_type": [
"CLSignature2019"
]
}
},
"constraints": {
"limit_disclosure": "required",
"fields": [
{
"path": [
"$.schema_id"
],
"filter": {
"type": "string",
"const": "did:indy:idu:test:3QowxFtwciWceMFr7WbwnM:2:BasicScheme:0\\.1"
}
},
{
"path": [
"$.values.first_name"
]
},
{
"path": [
"$.values.last_name"
]
}
]
}
}
]
}
"id": "example_vc_ac_sd",
"input_descriptors": [
{
"id": "id_credential",
"format": {
"ac_vc": {
"proof_type": [
"CLSignature2019"
]
}
},
"constraints": {
"limit_disclosure": "required",
"fields": [
{
"path": [
"$.schema_id"
],
"filter": {
"type": "string",
"const": "did:indy:idu:test:3QowxFtwciWceMFr7WbwnM:2:BasicScheme:0\\.1"
}
},
{
"path": [
"$.values.first_name"
]
},
{
"path": [
"$.values.last_name"
]
}
]
}
}
]
}
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/request/pd_jwt_vc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/request/pd_ldp_vc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/request/pd_mdl_iso_cbor.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/request/vp_token_type_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion oid4vp/tests/examples/response/ps_ac_vc_sd.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
}
}
]
}
}
18 changes: 9 additions & 9 deletions oid4vp/tests/examples/response/ps_jwt_vc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"definition_id": "example_jwt_vc",
"id": "example_jwt_vc_presentation_submission",
"descriptor_map": [
{
"id": "id_credential",
"path": "$",
"format": "jwt_vp_json",
"path_nested": {
"path": "$.vp.verifiableCredential[0]",
"format": "jwt_vc_json"
{
"id": "id_credential",
"path": "$",
"format": "jwt_vp_json",
"path_nested": {
"path": "$.vp.verifiableCredential[0]",
"format": "jwt_vc_json"
}
}
}
]
}
}
Loading

0 comments on commit 2e287c2

Please sign in to comment.