-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
606ebd7
commit 5a75380
Showing
18 changed files
with
161 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{Sign, Subject, Verify}; | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use derivative::{self, Derivative}; | ||
use ed25519_dalek::{Keypair, Signature, Signer}; | ||
use lazy_static::lazy_static; | ||
use rand::rngs::OsRng; | ||
|
||
// Keypair for mocking purposes. | ||
lazy_static! { | ||
pub static ref TEST_KEYPAIR: Keypair = Keypair::generate(&mut OsRng); | ||
} | ||
|
||
#[derive(Derivative)] | ||
#[derivative(Default)] | ||
pub struct TestSubject { | ||
#[derivative(Default(value = "did_url::DID::parse(\"did:test:123\").unwrap()"))] | ||
pub did: did_url::DID, | ||
pub key_id: String, | ||
} | ||
|
||
impl TestSubject { | ||
pub fn new(did: String, key_id: String) -> Result<Self> { | ||
Ok(TestSubject { | ||
did: did_url::DID::parse(did)?, | ||
key_id, | ||
}) | ||
} | ||
} | ||
|
||
impl Sign for TestSubject { | ||
fn key_id(&self) -> Option<String> { | ||
Some(self.key_id.clone()) | ||
} | ||
|
||
fn sign(&self, message: &str) -> Result<Vec<u8>> { | ||
let signature: Signature = TEST_KEYPAIR.sign(message.as_bytes()); | ||
Ok(signature.to_bytes().to_vec()) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Verify for TestSubject { | ||
async fn public_key(&self, _kid: &str) -> Result<Vec<u8>> { | ||
Ok(TEST_KEYPAIR.public.to_bytes().to_vec()) | ||
} | ||
} | ||
|
||
impl Subject for TestSubject { | ||
fn identifier(&self) -> Result<String> { | ||
Ok(self.did.to_string()) | ||
} | ||
} | ||
|
||
pub struct MockVerifier; | ||
|
||
impl MockVerifier { | ||
pub fn new() -> Self { | ||
MockVerifier {} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Verify for MockVerifier { | ||
async fn public_key(&self, _kid: &str) -> Result<Vec<u8>> { | ||
Ok(TEST_KEYPAIR.public.to_bytes().to_vec()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
"path": "$" | ||
} | ||
] | ||
} | ||
} |