From 8236c925ee94375bc7893fea2ba6c85e3c624213 Mon Sep 17 00:00:00 2001 From: lli Date: Tue, 23 Jul 2024 17:20:30 -0700 Subject: [PATCH] Merge Conflicts Signed-off-by: lli --- .../src/errors/mapping_indy_api_types.rs | 48 ----- did_core/did_doc/tests/serde.rs | 195 ------------------ did_core/did_doc_sov/tests/builder.rs | 106 ---------- did_core/did_doc_sov/tests/serde.rs | 149 ------------- 4 files changed, 498 deletions(-) delete mode 100644 aries/aries_vcx_core/src/errors/mapping_indy_api_types.rs delete mode 100644 did_core/did_doc/tests/serde.rs delete mode 100644 did_core/did_doc_sov/tests/builder.rs delete mode 100644 did_core/did_doc_sov/tests/serde.rs diff --git a/aries/aries_vcx_core/src/errors/mapping_indy_api_types.rs b/aries/aries_vcx_core/src/errors/mapping_indy_api_types.rs deleted file mode 100644 index ad932640e2..0000000000 --- a/aries/aries_vcx_core/src/errors/mapping_indy_api_types.rs +++ /dev/null @@ -1,48 +0,0 @@ -pub use indy_api_types::ErrorCode; -use indy_api_types::{errors::IndyErrorKind, IndyError}; - -use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind}; - -impl From for AriesVcxCoreErrorKind { - fn from(indy: IndyErrorKind) -> Self { - use IndyErrorKind::*; - - match indy { - InvalidParam(_) => AriesVcxCoreErrorKind::InvalidLibindyParam, - InvalidStructure => AriesVcxCoreErrorKind::InvalidInput, - IOError => AriesVcxCoreErrorKind::IOError, - InvalidWalletHandle => AriesVcxCoreErrorKind::InvalidWalletHandle, - WalletAlreadyExists => AriesVcxCoreErrorKind::DuplicationWallet, - WalletNotFound => AriesVcxCoreErrorKind::WalletNotFound, - WalletAlreadyOpened => AriesVcxCoreErrorKind::WalletAlreadyOpen, - WalletItemNotFound => AriesVcxCoreErrorKind::WalletRecordNotFound, - WalletItemAlreadyExists => AriesVcxCoreErrorKind::DuplicationWalletRecord, - PoolConfigAlreadyExists => AriesVcxCoreErrorKind::CreatePoolConfig, - MasterSecretDuplicateName => AriesVcxCoreErrorKind::DuplicationMasterSecret, - CredDefAlreadyExists => AriesVcxCoreErrorKind::CredDefAlreadyCreated, - DIDAlreadyExists => AriesVcxCoreErrorKind::DuplicationDid, - InvalidState => AriesVcxCoreErrorKind::InvalidState, - NoConsensus => AriesVcxCoreErrorKind::InvalidLedgerResponse, - InvalidTransaction => AriesVcxCoreErrorKind::InvalidLedgerResponse, - LedgerItemNotFound => AriesVcxCoreErrorKind::LedgerItemNotFound, - TransactionNotAllowed => AriesVcxCoreErrorKind::InvalidLedgerResponse, - PoolTimeout => AriesVcxCoreErrorKind::InvalidLedgerResponse, - PoolIncompatibleProtocolVersion => AriesVcxCoreErrorKind::InvalidConfiguration, - UnknownWalletStorageType => AriesVcxCoreErrorKind::InvalidConfiguration, - WalletStorageTypeAlreadyRegistered => AriesVcxCoreErrorKind::InvalidConfiguration, - WalletAccessFailed => AriesVcxCoreErrorKind::WalletAccessFailed, - ProofRejected => AriesVcxCoreErrorKind::ProofRejected, - _ => { - let err_code = ErrorCode::from(indy) as u32; - AriesVcxCoreErrorKind::VdrToolsError(err_code) - } - } - } -} - -impl From for AriesVcxCoreError { - fn from(indy: IndyError) -> Self { - let vcx_kind: AriesVcxCoreErrorKind = indy.kind().into(); - AriesVcxCoreError::from_msg(vcx_kind, indy.to_string()) - } -} diff --git a/did_core/did_doc/tests/serde.rs b/did_core/did_doc/tests/serde.rs deleted file mode 100644 index bf8b452ab5..0000000000 --- a/did_core/did_doc/tests/serde.rs +++ /dev/null @@ -1,195 +0,0 @@ -use std::str::FromStr; - -use did_doc::schema::{ - did_doc::DidDocument, - types::{jsonwebkey::JsonWebKey, uri::Uri}, - verification_method::{VerificationMethod, VerificationMethodKind, VerificationMethodType}, -}; -use did_parser::{Did, DidUrl}; -use serde_json::Value; - -const VALID_DID_DOC_JSON: &str = r##" -{ - "@context": [ - "https://w3.org/ns/did/v1", - "https://w3id.org/security/suites/ed25519-2018/v1" - ], - "id": "did:web:did-actor-alice", - "alsoKnownAs": [ - "https://example.com/user-profile/123" - ], - "publicKey": [ - { - "id": "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN", - "controller": "did:web:did-actor-alice", - "type": "Ed25519VerificationKey2018", - "publicKeyBase58": "DK7uJiq9PnPnj7AmNZqVBFoLuwTjT1hFPrk6LSjZ2JRz" - } - ], - "authentication": [ - "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN" - ], - "assertionMethod": [ - "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN" - ], - "capabilityDelegation": [ - "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN" - ], - "capabilityInvocation": [ - "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN" - ], - "verificationMethod": [ - { - "id": "#g1", - "controller": "did:web:did-actor-alice", - "type": "JsonWebKey2020", - "publicKeyJwk": { - "kty": "EC", - "crv": "BLS12381_G1", - "x": "hxF12gtsn9ju4-kJq2-nUjZQKVVWpcBAYX5VHnUZMDilClZsGuOaDjlXS8pFE1GG" - } - }, - { - "id": "#g2", - "controller": "did:web:did-actor-alice", - "type": "JsonWebKey2020", - "publicKeyJwk": { - "kty": "EC", - "crv": "BLS12381_G2", - "x": "l4MeBsn_OGa2OEDtHeHdq0TBC8sYh6QwoI7QsNtZk9oAru1OnGClaAPlMbvvs73EABDB6GjjzybbOHarkBmP6pon8H1VuMna0nkEYihZi8OodgdbwReDiDvWzZuXXMl-" - } - } - ], - "keyAgreement": [ - { - "id": "did:web:did-actor-alice#zC8GybikEfyNaausDA4mkT4egP7SNLx2T1d1kujLQbcP6h", - "type": "X25519KeyAgreementKey2019", - "controller": "did:web:did-actor-alice", - "publicKeyBase58": "CaSHXEvLKS6SfN9aBfkVGBpp15jSnaHazqHgLHp8KZ3Y" - } - ] -} -"##; - -#[test] -fn test_deserialization() { - let did_doc: DidDocument<()> = serde_json::from_str(VALID_DID_DOC_JSON).unwrap(); - - assert_eq!( - did_doc.id(), - &"did:web:did-actor-alice".to_string().try_into().unwrap() - ); - assert_eq!( - did_doc.also_known_as(), - vec![Uri::from_str("https://example.com/user-profile/123").unwrap()] - ); - - let controller: Did = "did:web:did-actor-alice".to_string().try_into().unwrap(); - - let pk_id = DidUrl::parse( - "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN".to_string(), - ) - .unwrap(); - - let vm1_id = DidUrl::parse("#g1".to_string()).unwrap(); - let vm1 = VerificationMethod::builder( - vm1_id, - controller.clone(), - VerificationMethodType::JsonWebKey2020, - ) - .add_public_key_jwk( - JsonWebKey::from_str( - r#"{ - "kty": "EC", - "crv": "BLS12381_G1", - "x": "hxF12gtsn9ju4-kJq2-nUjZQKVVWpcBAYX5VHnUZMDilClZsGuOaDjlXS8pFE1GG" - }"#, - ) - .unwrap(), - ) - .build(); - - let vm2_id = DidUrl::parse("#g2".to_string()).unwrap(); - let vm2 = VerificationMethod::builder( - vm2_id, - controller.clone(), - VerificationMethodType::JsonWebKey2020, - ) - .add_public_key_jwk( - JsonWebKey::from_str( - r#"{ - "kty": "EC", - "crv": "BLS12381_G2", - "x": "l4MeBsn_OGa2OEDtHeHdq0TBC8sYh6QwoI7QsNtZk9oAru1OnGClaAPlMbvvs73EABDB6GjjzybbOHarkBmP6pon8H1VuMna0nkEYihZi8OodgdbwReDiDvWzZuXXMl-" - }"#, - ) - .unwrap(), - ) - .build(); - - assert_eq!(did_doc.verification_method().first().unwrap().clone(), vm1); - assert_eq!(did_doc.verification_method().get(1).unwrap().clone(), vm2); - - assert_eq!( - did_doc.authentication(), - &[VerificationMethodKind::Resolvable(pk_id.clone())] - ); - - assert_eq!( - did_doc.assertion_method(), - &[VerificationMethodKind::Resolvable(pk_id.clone())] - ); - - assert_eq!( - did_doc.capability_delegation(), - &[VerificationMethodKind::Resolvable(pk_id.clone())] - ); - - assert_eq!( - did_doc.capability_invocation(), - &[VerificationMethodKind::Resolvable(pk_id)] - ); - - assert_eq!( - did_doc.extra_field("publicKey").unwrap().clone(), - Value::Array(vec![Value::Object( - serde_json::from_str( - r#"{ - "id": "did:web:did-actor-alice#z6MkrmNwty5ajKtFqc1U48oL2MMLjWjartwc5sf2AihZwXDN", - "type": "Ed25519VerificationKey2018", - "controller": "did:web:did-actor-alice", - "publicKeyBase58": "DK7uJiq9PnPnj7AmNZqVBFoLuwTjT1hFPrk6LSjZ2JRz" - }"# - ) - .unwrap() - )]) - ); - - let ka1_id = DidUrl::parse( - "did:web:did-actor-alice#zC8GybikEfyNaausDA4mkT4egP7SNLx2T1d1kujLQbcP6h".to_string(), - ) - .unwrap(); - let ka1 = VerificationMethod::builder( - ka1_id, - controller, - VerificationMethodType::X25519KeyAgreementKey2019, - ) - .add_public_key_base58("CaSHXEvLKS6SfN9aBfkVGBpp15jSnaHazqHgLHp8KZ3Y".to_string()) - .build(); - - assert_eq!( - did_doc.key_agreement(), - &[VerificationMethodKind::Resolved(ka1)] - ); -} - -#[test] -fn test_serialization() { - let did_doc: DidDocument<()> = serde_json::from_str(VALID_DID_DOC_JSON).unwrap(); - - let serialized_json = serde_json::to_string(&did_doc).unwrap(); - - let original_json_value: DidDocument<()> = serde_json::from_str(VALID_DID_DOC_JSON).unwrap(); - let serialized_json_value: DidDocument<()> = serde_json::from_str(&serialized_json).unwrap(); - assert_eq!(serialized_json_value, original_json_value); -} diff --git a/did_core/did_doc_sov/tests/builder.rs b/did_core/did_doc_sov/tests/builder.rs deleted file mode 100644 index 1918604d6a..0000000000 --- a/did_core/did_doc_sov/tests/builder.rs +++ /dev/null @@ -1,106 +0,0 @@ -use did_doc::schema::types::{uri::Uri, url::Url}; -use did_doc_sov::{ - extra_fields::{ - aip1::ExtraFieldsAIP1, didcommv1::ExtraFieldsDidCommV1, didcommv2::ExtraFieldsDidCommV2, - KeyKind, - }, - service::{ - aip1::ServiceAIP1, didcommv1::ServiceDidCommV1, didcommv2::ServiceDidCommV2, ServiceSov, - }, - DidDocumentSov, -}; - -const ID: &str = "did:sov:WRfXPg8dantKVubE3HX8pw"; -const SERVICE_ENDPOINT: &str = "https://example.com"; - -#[test] -fn test_service_build_aip1() { - let service = ServiceAIP1::new( - ID.parse().unwrap(), - SERVICE_ENDPOINT.parse().unwrap(), - ExtraFieldsAIP1::default(), - ) - .unwrap(); - let did_doc = DidDocumentSov::builder(Default::default()) - .add_service(ServiceSov::AIP1(service)) - .build(); - let services = did_doc.service(); - assert_eq!(services.len(), 1); - let first_service = services.first().unwrap(); - assert_eq!(first_service.id().clone(), ID.parse::().unwrap()); - assert_eq!( - first_service.service_endpoint(), - SERVICE_ENDPOINT.parse::().unwrap() - ); - let first_extra = first_service.extra(); - assert!(first_extra.priority().is_err()); - assert!(first_extra.recipient_keys().is_err()); - assert!(first_extra.routing_keys().is_err()); -} - -#[test] -fn test_service_build_didcommv1() { - let extra_fields_didcommv1 = ExtraFieldsDidCommV1::builder() - .set_priority(1) - .set_routing_keys(vec![KeyKind::Value("foo".to_owned())]) - .set_recipient_keys(vec![KeyKind::Value("bar".to_owned())]) - .build(); - let service = ServiceDidCommV1::new( - ID.parse().unwrap(), - SERVICE_ENDPOINT.parse().unwrap(), - extra_fields_didcommv1, - ) - .unwrap(); - let did_doc = DidDocumentSov::builder(Default::default()) - .add_service(ServiceSov::DIDCommV1(service)) - .build(); - let services = did_doc.service(); - assert_eq!(services.len(), 1); - let first_service = services.first().unwrap(); - assert_eq!(first_service.id().clone(), ID.parse::().unwrap()); - assert_eq!( - first_service.service_endpoint(), - SERVICE_ENDPOINT.parse::().unwrap() - ); - let first_extra = first_service.extra(); - assert_eq!(first_extra.priority().unwrap(), 1); - assert_eq!( - first_extra.recipient_keys().unwrap(), - &[KeyKind::Value("bar".to_owned())] - ); - assert_eq!( - first_extra.routing_keys().unwrap(), - &[KeyKind::Value("foo".to_owned())] - ); -} - -#[test] -fn test_service_build_didcommv2() { - let extra_fields_didcommv2 = ExtraFieldsDidCommV2::builder() - .set_routing_keys(vec![KeyKind::Value("foo".to_owned())]) - .build(); - let service = ServiceDidCommV2::new( - ID.parse().unwrap(), - SERVICE_ENDPOINT.parse().unwrap(), - extra_fields_didcommv2, - ) - .unwrap(); - let did_doc = DidDocumentSov::builder(Default::default()) - .add_service(ServiceSov::DIDCommV2(service)) - .build(); - let services = did_doc.service(); - assert_eq!(services.len(), 1); - let first_service = services.first().unwrap(); - assert_eq!(first_service.id().clone(), ID.parse::().unwrap()); - assert_eq!( - first_service.service_endpoint(), - SERVICE_ENDPOINT.parse::().unwrap() - ); - let first_extra = first_service.extra(); - assert!(first_extra.priority().is_err()); - assert!(first_extra.recipient_keys().is_err()); - assert_eq!( - first_extra.routing_keys().unwrap(), - &[KeyKind::Value("foo".to_owned())] - ); -} diff --git a/did_core/did_doc_sov/tests/serde.rs b/did_core/did_doc_sov/tests/serde.rs deleted file mode 100644 index a74ec5b0c8..0000000000 --- a/did_core/did_doc_sov/tests/serde.rs +++ /dev/null @@ -1,149 +0,0 @@ -use did_doc_sov::{ - extra_fields::{AcceptType, KeyKind}, - service::ServiceType, - DidDocumentSov, -}; - -const DID_DOC_DATA: &str = r#" -{ - "@context": [ - "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/suites/ed25519-2018/v1", - "https://w3id.org/security/suites/x25519-2019/v1" - ], - "id": "did:sov:HR6vs6GEZ8rHaVgjg2WodM", - "verificationMethod": [ - { - "type": "Ed25519VerificationKey2018", - "id": "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-1", - "controller": "did:sov:HR6vs6GEZ8rHaVgjg2WodM", - "publicKeyBase58": "9wvq2i4xUa5umXoThe83CDgx1e5bsjZKJL4DEWvTP9qe" - }, - { - "type": "X25519KeyAgreementKey2019", - "id": "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-1", - "controller": "did:sov:HR6vs6GEZ8rHaVgjg2WodM", - "publicKeyBase58": "3mHtKcQFEzqeUcnce5BAuzAgLEbqKaV542pUf9xQ5Pf8" - } - ], - "authentication": [ - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-1" - ], - "assertionMethod": [ - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-1" - ], - "keyAgreement": [ - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-1" - ], - "service": [ - { - "id": "did:sov:HR6vs6GEZ8rHaVgjg2WodM#endpoint", - "type": "endpoint", - "serviceEndpoint": "https://example.com/endpoint" - }, - { - "id": "did:sov:HR6vs6GEZ8rHaVgjg2WodM#did-communication", - "type": "did-communication", - "priority": 0, - "recipientKeys": [ - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-1" - ], - "routingKeys": [], - "accept": [ - "didcomm/aip2;env=rfc19" - ], - "serviceEndpoint": "https://example.com/endpoint" - }, - { - "id": "did:sov:HR6vs6GEZ8rHaVgjg2WodM#didcomm-1", - "type": "DIDComm", - "accept": [ - "didcomm/v2" - ], - "routingKeys": [], - "serviceEndpoint": "https://example.com/endpoint" - } - ] -} -"#; - -#[test] -fn test_deserialization() { - let did_doc = serde_json::from_str::(DID_DOC_DATA).unwrap(); - assert_eq!(did_doc.id().to_string(), "did:sov:HR6vs6GEZ8rHaVgjg2WodM"); - assert_eq!(did_doc.verification_method().len(), 2); - assert_eq!(did_doc.authentication().len(), 1); - assert_eq!(did_doc.assertion_method().len(), 1); - assert_eq!(did_doc.key_agreement().len(), 1); - assert_eq!(did_doc.service().len(), 3); - - let services = did_doc.service(); - let first_service = services.first().unwrap(); - assert_eq!( - first_service.service_endpoint().to_string(), - "https://example.com/endpoint" - ); - assert_eq!(first_service.service_type(), ServiceType::AIP1); - - let second_service = services.get(1).unwrap(); - assert_eq!( - second_service.id().to_string(), - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#did-communication" - ); - assert_eq!(second_service.service_type(), ServiceType::DIDCommV1); - assert_eq!( - second_service.service_endpoint().to_string(), - "https://example.com/endpoint" - ); - - let third_service = services.get(2).unwrap(); - assert_eq!( - third_service.id().to_string(), - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#didcomm-1" - ); - assert_eq!(third_service.service_type(), ServiceType::DIDCommV2); - assert_eq!( - third_service.service_endpoint().to_string(), - "https://example.com/endpoint" - ); - - let second_extra = second_service.extra(); - assert!(!second_extra.recipient_keys().unwrap().is_empty()); - assert_eq!(second_extra.routing_keys().unwrap().len(), 0); - assert!(second_extra.first_recipient_key().is_ok()); - assert!(second_extra.first_routing_key().is_err()); - assert_eq!( - second_extra.accept().unwrap().first().unwrap().clone(), - AcceptType::DIDCommV1 - ); - assert_eq!(second_extra.priority().unwrap(), 0); - - let third_extra = third_service.extra(); - assert!(third_extra.recipient_keys().is_err()); - assert_eq!(third_extra.routing_keys().unwrap().len(), 0); - assert!(third_extra.first_recipient_key().is_err()); - assert!(third_extra.first_routing_key().is_err()); - assert_eq!( - third_extra.accept().unwrap().first().unwrap().clone(), - AcceptType::DIDCommV2 - ); - assert!(third_extra.priority().is_err()); - - if let KeyKind::Reference(reference) = second_extra.first_recipient_key().unwrap() { - let vm = did_doc.dereference_key(reference).unwrap(); - assert_eq!( - vm.id().to_string(), - "did:sov:HR6vs6GEZ8rHaVgjg2WodM#key-agreement-1" - ); - } else { - panic!("Expected reference key kind"); - } -} - -#[test] -fn test_deserialization_and_serialization() { - let did_doc_1 = serde_json::from_str::(DID_DOC_DATA).unwrap(); - let serialized = serde_json::to_string_pretty(&did_doc_1).unwrap(); - let did_doc_2 = serde_json::from_str::(&serialized).unwrap(); - assert_eq!(did_doc_1, did_doc_2); -}