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

Refactor KeyManager #204

Merged
merged 2 commits into from
May 16, 2024
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
2 changes: 1 addition & 1 deletion crates/credentials/src/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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
8 changes: 4 additions & 4 deletions crates/dids/src/bearer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/methods/jwk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod tests {
use keys::key_manager::local_key_manager::LocalKeyManager;

fn create_did_jwk() -> 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: 20 additions & 20 deletions crates/jws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ mod tests {

#[tokio::test]
async fn test_jws_sign_and_verify() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -191,9 +191,9 @@ mod tests {

#[test]
fn test_jws_decode() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -242,9 +242,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_malformed_header_alg_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -283,9 +283,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_malformed_header_kid_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -324,9 +324,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_algorithm_not_supported_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -365,9 +365,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_resolution_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -406,9 +406,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_document_verification_method_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -447,9 +447,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_signature_decode_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down Expand Up @@ -489,9 +489,9 @@ mod tests {

#[tokio::test]
async fn test_jws_verify_signature_crypto_error() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand All @@ -513,9 +513,9 @@ mod tests {
.to_string()
.into_bytes();

let invalid_key_manager = LocalKeyManager::new_in_memory();
let invalid_key_manager = Arc::new(LocalKeyManager::new());
let invalid_bearer_did = DidJwk::create(
Arc::new(invalid_key_manager),
invalid_key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/jwt/src/jws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ mod tests {

#[tokio::test]
async fn test_sign_and_verify() {
let key_manager = LocalKeyManager::new_in_memory();
let key_manager = Arc::new(LocalKeyManager::new());
let bearer_did = DidJwk::create(
Arc::new(key_manager),
key_manager,
DidJwkCreateOptions {
curve: Curve::Ed25519,
},
Expand Down
103 changes: 0 additions & 103 deletions crates/keys/src/key_manager/key_store/in_memory_key_store.rs

This file was deleted.

50 changes: 0 additions & 50 deletions crates/keys/src/key_manager/key_store/mod.rs

This file was deleted.

Loading
Loading