Skip to content

Commit

Permalink
Merge branch 'main' into semantic-vc-verification
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed May 16, 2024
2 parents dd556ee + bfd12ef commit 5008752
Show file tree
Hide file tree
Showing 29 changed files with 829 additions and 304 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ jobs:
cache: true
- name: Setup
run: just setup
- name: Formatting
run: cargo fmt --check
- name: Lint
run: just lint
3 changes: 2 additions & 1 deletion crates/credentials/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ uuid = { version = "1.8.0", features = ["v4"] }
[dev-dependencies]
crypto = { path = "../crypto" }
serde_canonical_json = "1.0.0"
tokio = { version = "1.34.0", features = ["macros", "test-util"] }
tokio = { version = "1.34.0", features = ["macros", "test-util"] }
test-helpers = { path = "../test-helpers" }
2 changes: 1 addition & 1 deletion crates/credentials/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod presentation_definition;
pub mod vc;
pub mod verifiable_credential;
31 changes: 7 additions & 24 deletions crates/credentials/src/presentation_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,47 +236,30 @@ impl JsonSchemaBuilder {
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use std::fs;

use test_helpers::TestVectorFile;

use super::PresentationDefinition;

#[derive(Debug, serde::Deserialize)]
struct SelectCredentialsVectorInput {
struct VectorInput {
#[serde(rename = "presentationDefinition")]
pub presentation_definition: PresentationDefinition,
#[serde(rename = "credentialJwts")]
pub credential_jwts: Vec<String>,
}

#[derive(Debug, serde::Deserialize)]
struct SelectCredentialsVectorOutput {
struct VectorOutput {
#[serde(rename = "selectedCredentials")]
pub selected_credentials: Vec<String>,
}

#[derive(Debug, serde::Deserialize)]
struct SelectCredentialsVector {
pub description: String,
pub input: SelectCredentialsVectorInput,
pub output: SelectCredentialsVectorOutput,
}

#[derive(Debug, serde::Deserialize)]
struct Vectors {
pub vectors: Vec<SelectCredentialsVector>,
}

fn load_json_fixture(file_path: &str) -> Vectors {
let data = fs::read_to_string(file_path).unwrap();
let json = serde_json::from_str(&data).unwrap();
json
}

#[test]
fn test_web5_spec_test_vectors() {
let json_path =
"../../web5-spec/test-vectors/presentation_exchange/select_credentials.json";
let vectors = load_json_fixture(json_path);
let path = "presentation_exchange/select_credentials.json";
let vectors: TestVectorFile<VectorInput, VectorOutput> =
TestVectorFile::load_from_path(path);

for vector in vectors.vectors {
let presentation_definition = vector.input.presentation_definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mod test {
use crypto::Curve;
use dids::{
document::VerificationMethodType,
method::{
methods::{
jwk::{DidJwk, DidJwkCreateOptions},
Create,
},
Expand All @@ -339,7 +339,7 @@ mod test {
use uuid::Uuid;

fn create_bearer_did() -> BearerDid {
let key_manager = Arc::new(LocalKeyManager::new_in_memory());
let key_manager = Arc::new(LocalKeyManager::new());
let options = DidJwkCreateOptions {
curve: Curve::Ed25519,
};
Expand Down
40 changes: 0 additions & 40 deletions crates/credentials/tests/resources/pd_sanctions.json

This file was deleted.

1 change: 1 addition & 0 deletions crates/dids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository.workspace = true
license-file.workspace = true

[dependencies]
byteorder = "1.5.0"
crypto = { path = "../crypto" }
did-jwk = "0.1.1"
did-web = "0.2.2"
Expand Down
10 changes: 5 additions & 5 deletions crates/dids/src/bearer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod test {
use super::*;
use crate::{
document::VerificationMethodType,
method::{
methods::{
jwk::{DidJwk, DidJwkCreateOptions},
Create,
},
Expand All @@ -77,18 +77,18 @@ mod test {

#[tokio::test]
async fn test_from_key_manager() {
let key_manager = Arc::new(LocalKeyManager::new_in_memory());
let key_manager = Arc::new(LocalKeyManager::new());
let options = DidJwkCreateOptions {
curve: Curve::Ed25519,
};
let did_jwk_bearer_did = DidJwk::create(key_manager.clone(), options).unwrap();
let private_keys = key_manager.export_private_keys().unwrap();

let bearer_did =
BearerDid::from_key_manager(&did_jwk_bearer_did.identifier.uri, key_manager)
BearerDid::from_key_manager(&did_jwk_bearer_did.identifier.uri, key_manager.clone())
.await
.unwrap();
let bearer_did_private_keys = bearer_did.key_manager.export_private_keys().unwrap();
let bearer_did_private_keys = key_manager.export_private_keys().unwrap();

assert_eq!(bearer_did.identifier.uri, did_jwk_bearer_did.identifier.uri);
assert_eq!(private_keys.len(), bearer_did_private_keys.len());
Expand All @@ -100,7 +100,7 @@ mod test {

#[test]
fn test_sign() {
let key_manager = Arc::new(LocalKeyManager::new_in_memory());
let key_manager = Arc::new(LocalKeyManager::new());
let options = DidJwkCreateOptions {
curve: Curve::Ed25519,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/dids/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod bearer;
pub mod document;
pub mod identifier;
pub mod method;
pub mod methods;
pub mod resolver;
Loading

0 comments on commit 5008752

Please sign in to comment.