diff --git a/agency_client/src/internal/messaging.rs b/agency_client/src/internal/messaging.rs index f8db31fc4b..7707a549a0 100644 --- a/agency_client/src/internal/messaging.rs +++ b/agency_client/src/internal/messaging.rs @@ -203,7 +203,7 @@ impl AgencyClient { agent_vk: &str, ) -> AgencyClientResult<Vec<u8>> { debug!("prepare_message_for_connection_agent >> {:?}", messages); - let message = messages.get(0).ok_or(AgencyClientError::from_msg( + let message = messages.first().ok_or(AgencyClientError::from_msg( AgencyClientErrorKind::SerializationError, "Cannot get message", ))?; diff --git a/agents/rust/mediator/src/didcomm_handlers/utils.rs b/agents/rust/mediator/src/didcomm_handlers/utils.rs index 81580a8c56..15c36a456b 100644 --- a/agents/rust/mediator/src/didcomm_handlers/utils.rs +++ b/agents/rust/mediator/src/didcomm_handlers/utils.rs @@ -1,6 +1,4 @@ pub mod prelude { - pub use std::sync::Arc; - pub use aries_vcx::utils::encryption_envelope::EncryptionEnvelope; pub use aries_vcx_core::wallet::base_wallet::BaseWallet; pub use mediation::storage::MediatorPersistence; diff --git a/agents/rust/mediator/tests/common/mod.rs b/agents/rust/mediator/tests/common/mod.rs index a52538d0de..db0cbb98df 100644 --- a/agents/rust/mediator/tests/common/mod.rs +++ b/agents/rust/mediator/tests/common/mod.rs @@ -24,6 +24,6 @@ pub mod test_setup { pub mod prelude { pub use anyhow::Result; - pub use log::{debug, error, info}; + pub use log::info; pub use url::Url; } diff --git a/aries_vcx/src/common/credentials/encoding.rs b/aries_vcx/src/common/credentials/encoding.rs index 02d46c484d..a65fd6f36a 100644 --- a/aries_vcx/src/common/credentials/encoding.rs +++ b/aries_vcx/src/common/credentials/encoding.rs @@ -17,7 +17,7 @@ pub fn encode_attributes(attributes: &str) -> VcxResult<String> { // old style input such as {"address2":["101 Wilson Lane"]} serde_json::Value::Array(array_type) => { let attrib_value: &str = - match array_type.get(0).and_then(serde_json::Value::as_str) { + match array_type.first().and_then(serde_json::Value::as_str) { Some(x) => x, None => { return Err(AriesVcxError::from_msg( diff --git a/aries_vcx/src/handlers/out_of_band/receiver.rs b/aries_vcx/src/handlers/out_of_band/receiver.rs index 5bd5346bfa..9af0216eab 100644 --- a/aries_vcx/src/handlers/out_of_band/receiver.rs +++ b/aries_vcx/src/handlers/out_of_band/receiver.rs @@ -152,7 +152,7 @@ impl OutOfBandReceiver { .content .requests_attach .as_ref() - .and_then(|v| v.get(0)) + .and_then(|v| v.first()) { attachment_to_aries_message(attach) } else { diff --git a/aries_vcx/src/protocols/mediated_connection/invitee/state_machine.rs b/aries_vcx/src/protocols/mediated_connection/invitee/state_machine.rs index 18676f57d9..08f0261265 100644 --- a/aries_vcx/src/protocols/mediated_connection/invitee/state_machine.rs +++ b/aries_vcx/src/protocols/mediated_connection/invitee/state_machine.rs @@ -198,7 +198,7 @@ impl SmConnectionInvitee { ))?; did_did .recipient_keys()? - .get(0) + .first() .ok_or(AriesVcxError::from_msg( AriesVcxErrorKind::NotReady, "Can't resolve recipient key from the counterparty diddoc.", @@ -380,7 +380,7 @@ impl SmConnectionInvitee { let state = match self.state { InviteeFullState::Requested(state) => { - let remote_vk: String = state.did_doc.recipient_keys()?.get(0).cloned().ok_or( + let remote_vk: String = state.did_doc.recipient_keys()?.first().cloned().ok_or( AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, "Cannot handle response: remote verkey not found", diff --git a/aries_vcx/src/protocols/mediated_connection/inviter/state_machine.rs b/aries_vcx/src/protocols/mediated_connection/inviter/state_machine.rs index ec1a61f65d..32aa0997c7 100644 --- a/aries_vcx/src/protocols/mediated_connection/inviter/state_machine.rs +++ b/aries_vcx/src/protocols/mediated_connection/inviter/state_machine.rs @@ -188,7 +188,7 @@ impl SmConnectionInviter { ))?; did_did .recipient_keys()? - .get(0) + .first() .ok_or(AriesVcxError::from_msg( AriesVcxErrorKind::NotReady, "Can't resolve recipient key from the counterparty diddoc.", diff --git a/aries_vcx/src/utils/encryption_envelope.rs b/aries_vcx/src/utils/encryption_envelope.rs index 43fbe6d5c9..2ccb15a90f 100644 --- a/aries_vcx/src/utils/encryption_envelope.rs +++ b/aries_vcx/src/utils/encryption_envelope.rs @@ -65,7 +65,7 @@ impl EncryptionEnvelope { let routing_keys = did_doc.routing_keys(); let mut to = recipient_keys - .get(0) + .first() .map(String::from) .ok_or(AriesVcxError::from_msg( AriesVcxErrorKind::InvalidState, diff --git a/aries_vcx_core/Cargo.toml b/aries_vcx_core/Cargo.toml index b121fef3a6..f7ae75e0f1 100644 --- a/aries_vcx_core/Cargo.toml +++ b/aries_vcx_core/Cargo.toml @@ -19,7 +19,7 @@ indy-credx = { git = "https://github.com/hyperledger/indy-shared-rs", tag = "v1. libvdrtools = { path = "../libvdrtools", optional = true } indy-api-types = { path = "../libvdrtools/indy-api-types", optional = true } async-trait = "0.1.68" -futures = { version = "0.3", default-features = false } +futures = { version = "0.3" } serde_json = "1.0.95" time = "0.3.20" serde = { version = "1.0.159", features = ["derive"] } diff --git a/aries_vcx_core/src/credx/mod.rs b/aries_vcx_core/src/credx/mod.rs deleted file mode 100644 index 9042f5f19d..0000000000 --- a/aries_vcx_core/src/credx/mod.rs +++ /dev/null @@ -1 +0,0 @@ -use crate::wallet2::WalletRecord; diff --git a/aries_vcx_core/src/errors/mapping_indy_api_types.rs b/aries_vcx_core/src/errors/mapping_indy_api_types.rs index 3659bdfdbc..ad932640e2 100644 --- a/aries_vcx_core/src/errors/mapping_indy_api_types.rs +++ b/aries_vcx_core/src/errors/mapping_indy_api_types.rs @@ -1,4 +1,4 @@ -pub use indy_api_types::{errors, ErrorCode}; +pub use indy_api_types::ErrorCode; use indy_api_types::{errors::IndyErrorKind, IndyError}; use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind}; diff --git a/aries_vcx_core/src/lib.rs b/aries_vcx_core/src/lib.rs index 0066db861e..326c0b840c 100644 --- a/aries_vcx_core/src/lib.rs +++ b/aries_vcx_core/src/lib.rs @@ -25,8 +25,6 @@ extern crate log; extern crate derive_builder; pub mod anoncreds; -#[cfg(feature = "credx")] -pub mod credx; pub mod errors; pub mod global; pub mod ledger; diff --git a/aries_vcx_core/src/vc/credx.rs b/aries_vcx_core/src/vc/credx.rs index c5a34ca479..51e7ec23be 100644 --- a/aries_vcx_core/src/vc/credx.rs +++ b/aries_vcx_core/src/vc/credx.rs @@ -7,9 +7,8 @@ use indy_credx::{ types::{ AttributeNames, Credential, CredentialDefinition, CredentialDefinitionConfig, CredentialDefinitionId, CredentialDefinitionPrivate, CredentialKeyCorrectnessProof, - CredentialOffer, CredentialRequest, CredentialRequestMetadata, CredentialRevocationConfig, - CredentialRevocationState, CredentialValues, DidValue, IssuanceType, LinkSecret, - Presentation, PresentationRequest, RegistryType, RevocationRegistry, + CredentialOffer, CredentialRequest, CredentialRevocationConfig, CredentialValues, DidValue, + IssuanceType, Presentation, PresentationRequest, RegistryType, RevocationRegistry, RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, RevocationRegistryDelta, RevocationRegistryId, Schema, SchemaId, SignatureType, }, @@ -17,7 +16,7 @@ use indy_credx::{ }; use serde::{Deserialize, Serialize}; -use super::{VcIssuer, VcProver, VcVerifier}; +use super::{VcIssuer, VcVerifier}; use crate::{ errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}, wallet2::{Wallet, WalletRecord}, @@ -52,19 +51,20 @@ impl VcIssuer for IndyCredxIssuer { type RevRegDelta = RevocationRegistryDelta; type RevRegInfo = RevocationRegistryInfo; - async fn create_and_store_revoc_reg<'a, W>( + async fn create_and_store_revoc_reg<W>( &self, wallet: &W, issuer_did: &str, - cred_def_id: &'a Self::CredDefId, + cred_def_id: &Self::CredDefId, tails_dir: &str, max_creds: u32, tag: &str, ) -> VcxCoreResult<(Self::RevRegId, Self::RevRegDef, Self::RevReg)> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: - From<&'a Self::CredDefId> + From<&'b Self::RevRegId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, Self::CredDef: WalletRecord<W>, for<'b> Self::RevReg: WalletRecord<W, RecordId<'b> = &'b Self::RevRegId>, for<'b> Self::RevRegDef: WalletRecord<W, RecordId<'b> = &'b Self::RevRegId>, @@ -75,7 +75,7 @@ impl VcIssuer for IndyCredxIssuer { let mut tails_writer = TailsFileWriter::new(Some(tails_dir.to_owned())); - let cred_def = wallet.get(W::RecordIdRef::from(cred_def_id)).await?; + let cred_def = wallet.get(cred_def_id.as_ref()).await?; let rev_reg_id = issuer::make_revocation_registry_id( &issuer_did, @@ -84,8 +84,8 @@ impl VcIssuer for IndyCredxIssuer { RegistryType::CL_ACCUM, )?; - let res_rev_reg = wallet.get(W::RecordIdRef::from(&rev_reg_id)).await; - let res_rev_reg_def = wallet.get(W::RecordIdRef::from(&rev_reg_id)).await; + let res_rev_reg = wallet.get(rev_reg_id.as_ref()).await; + let res_rev_reg_def = wallet.get(rev_reg_id.as_ref()).await; if let (Ok(rev_reg), Ok(rev_reg_def)) = (res_rev_reg, res_rev_reg_def) { return Ok((rev_reg_id, rev_reg, rev_reg_def)); @@ -134,7 +134,8 @@ impl VcIssuer for IndyCredxIssuer { ) -> VcxCoreResult<(Self::CredDefId, Self::CredDef)> where W: Wallet + Send + Sync, - for<'a> <W as Wallet>::RecordIdRef<'a>: From<&'a Self::CredDefId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, for<'a> Self::Schema: WalletRecord<W, RecordId<'a> = &'a Self::SchemaId>, for<'a> Self::SchemaId: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, for<'a> Self::CredDef: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, @@ -158,7 +159,7 @@ impl VcIssuer for IndyCredxIssuer { )?; // If cred def already exists, return it - if let Ok(cred_def) = wallet.get(W::RecordIdRef::from(&cred_def_id)).await { + if let Ok(cred_def) = wallet.get(cred_def_id.as_ref()).await { return Ok((cred_def_id, cred_def)); } @@ -194,15 +195,16 @@ impl VcIssuer for IndyCredxIssuer { ) -> VcxCoreResult<Self::CredOffer> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: From<&'a Self::CredDefId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::SchemaId: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, Self::CredDef: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, Self::CredKeyProof: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, { - let cred_def: CredentialDefinition = wallet.get(W::RecordIdRef::from(cred_def_id)).await?; + let cred_def: CredentialDefinition = wallet.get(cred_def_id.as_ref()).await?; let correctness_proof: CredentialKeyCorrectnessProof = - wallet.get(W::RecordIdRef::from(cred_def_id)).await?; - let schema_id: SchemaId = wallet.get(W::RecordIdRef::from(cred_def_id)).await?; + wallet.get(cred_def_id.as_ref()).await?; + let schema_id: SchemaId = wallet.get(cred_def_id.as_ref()).await?; // If cred_def contains schema ID, why take it as an argument here...? let offer = issuer::create_credential_offer(&schema_id, &cred_def, &correctness_proof)?; @@ -221,8 +223,9 @@ impl VcIssuer for IndyCredxIssuer { ) -> VcxCoreResult<(Self::Cred, Option<Self::CredRevId>)> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: - From<&'b Self::CredDefId> + From<&'a Self::RevRegId> + Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, for<'b> Self::Schema: WalletRecord<W, RecordId<'b> = &'b Self::SchemaId>, for<'b> Self::SchemaId: WalletRecord<W, RecordId<'b> = &'b Self::CredDefId>, for<'b> Self::CredDef: WalletRecord<W, RecordId<'b> = &'b Self::CredDefId>, @@ -237,19 +240,18 @@ impl VcIssuer for IndyCredxIssuer { // does // it let cred_def_id = &cred_offer.cred_def_id; - let cred_def = wallet.get(W::RecordIdRef::from(cred_def_id)).await?; + let cred_def = wallet.get(cred_def_id.as_ref()).await?; - let cred_def_private = wallet.get(W::RecordIdRef::from(cred_def_id)).await?; + let cred_def_private = wallet.get(cred_def_id.as_ref()).await?; let mut revocation_config_parts = match rev_reg_id { Some(rev_reg_id) => { - let rev_reg_def = wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let rev_reg_def = wallet.get(rev_reg_id.as_ref()).await?; - let rev_reg_def_priv = wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let rev_reg_def_priv = wallet.get(rev_reg_id.as_ref()).await?; - let rev_reg = wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; - let rev_reg_info: RevocationRegistryInfo = - wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let rev_reg = wallet.get(rev_reg_id.as_ref()).await?; + let rev_reg_info: RevocationRegistryInfo = wallet.get(rev_reg_id.as_ref()).await?; Some((rev_reg_def, rev_reg_def_priv, rev_reg, rev_reg_info)) } @@ -345,8 +347,9 @@ impl VcIssuer for IndyCredxIssuer { ) -> VcxCoreResult<()> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: - From<&'b Self::CredDefId> + From<&'a Self::RevRegId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::RevReg: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, Self::RevRegDef: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, Self::RevRegDefPriv: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, @@ -354,14 +357,13 @@ impl VcIssuer for IndyCredxIssuer { Self::RevRegDelta: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, for<'b> Self::CredDef: WalletRecord<W, RecordId<'b> = &'b Self::CredDefId>, { - let rev_reg = wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let rev_reg = wallet.get(rev_reg_id.as_ref()).await?; - let rev_reg_def = wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let rev_reg_def = wallet.get(rev_reg_id.as_ref()).await?; - let rev_reg_priv = wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let rev_reg_priv = wallet.get(rev_reg_id.as_ref()).await?; - let mut rev_reg_info: RevocationRegistryInfo = - wallet.get(W::RecordIdRef::from(rev_reg_id)).await?; + let mut rev_reg_info: RevocationRegistryInfo = wallet.get(rev_reg_id.as_ref()).await?; let (issuance_type, cred_def_id) = match &rev_reg_def { RevocationRegistryDefinition::RevocationRegistryDefinitionV1(r) => { @@ -369,7 +371,7 @@ impl VcIssuer for IndyCredxIssuer { } }; - let cred_def = wallet.get(W::RecordIdRef::from(cred_def_id)).await?; + let cred_def = wallet.get(cred_def_id.as_ref()).await?; match issuance_type { IssuanceType::ISSUANCE_ON_DEMAND => { @@ -437,10 +439,11 @@ impl VcIssuer for IndyCredxIssuer { ) -> VcxCoreResult<Option<Self::RevRegDelta>> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: From<&'a Self::RevRegId> + Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::RevRegDelta: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, { - let res_rev_reg_delta = wallet.get(W::RecordIdRef::from(rev_reg_id)).await; + let res_rev_reg_delta = wallet.get(rev_reg_id.as_ref()).await; if let Err(err) = &res_rev_reg_delta { warn!( @@ -460,7 +463,8 @@ impl VcIssuer for IndyCredxIssuer { ) -> VcxCoreResult<()> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: From<&'a Self::RevRegId> + Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::RevRegDelta: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, { if self @@ -469,7 +473,7 @@ impl VcIssuer for IndyCredxIssuer { .is_some() { wallet - .delete::<RevocationRegistryDelta>(W::RecordIdRef::from(rev_reg_id)) + .delete::<RevocationRegistryDelta>(rev_reg_id.as_ref()) .await?; } @@ -564,3 +568,214 @@ where new_map } + +/// Just proving that stuff compiles +#[cfg(test)] +#[allow(unused, clippy::all)] +#[test] +fn stuff() { + use indy_api_types::WalletHandle; + + use crate::{wallet::indy::IndySdkWallet, wallet2::vdrtools::IndyWalletId}; + + // SAFETY: + // We're only changing types, but the layout is the same because of #[repr(transparent)]. + // This is because we can't implement AsRef<str> for the remote types. + // + // Indy-credx should implement `AsRef<str>` for their ID types, which would make + // the usage of this redundant. And they should drop the `Deref<str>` thing as that's + // meant for pointer types, not to mimic inheritance. + // + // Another popular example: https://docs.rs/serde_json/latest/src/serde_json/raw.rs.html#121-124 + impl AsRef<IndyWalletId> for RevocationRegistryId { + fn as_ref(&self) -> &IndyWalletId { + unsafe { std::mem::transmute::<&str, &IndyWalletId>(self.0.as_str()) } + } + } + + impl AsRef<IndyWalletId> for CredentialDefinitionId { + fn as_ref(&self) -> &IndyWalletId { + unsafe { std::mem::transmute::<&str, &IndyWalletId>(self.0.as_str()) } + } + } + + impl WalletRecord<IndySdkWallet> for RevocationRegistryDelta { + const RECORD_TYPE: &'static str = "rev"; + + type RecordId<'a> = &'a RevocationRegistryId; + + fn into_wallet_record( + self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn as_wallet_record( + &self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn from_wallet_record(record: <IndySdkWallet as Wallet>::Record) -> VcxCoreResult<Self> + where + Self: Sized, + { + todo!() + } + } + + impl WalletRecord<IndySdkWallet> for CredentialDefinition { + const RECORD_TYPE: &'static str = "rev"; + + type RecordId<'a> = &'a CredentialDefinitionId; + + fn into_wallet_record( + self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn as_wallet_record( + &self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn from_wallet_record(record: <IndySdkWallet as Wallet>::Record) -> VcxCoreResult<Self> + where + Self: Sized, + { + todo!() + } + } + + impl WalletRecord<IndySdkWallet> for RevocationRegistry { + const RECORD_TYPE: &'static str = "rev"; + + type RecordId<'a> = &'a RevocationRegistryId; + + fn into_wallet_record( + self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn as_wallet_record( + &self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn from_wallet_record(record: <IndySdkWallet as Wallet>::Record) -> VcxCoreResult<Self> + where + Self: Sized, + { + todo!() + } + } + + impl WalletRecord<IndySdkWallet> for RevocationRegistryDefinition { + const RECORD_TYPE: &'static str = "rev"; + + type RecordId<'a> = &'a RevocationRegistryId; + + fn into_wallet_record( + self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn as_wallet_record( + &self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn from_wallet_record(record: <IndySdkWallet as Wallet>::Record) -> VcxCoreResult<Self> + where + Self: Sized, + { + todo!() + } + } + + impl WalletRecord<IndySdkWallet> for RevocationRegistryDefinitionPrivate { + const RECORD_TYPE: &'static str = "rev"; + + type RecordId<'a> = &'a RevocationRegistryId; + + fn into_wallet_record( + self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn as_wallet_record( + &self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn from_wallet_record(record: <IndySdkWallet as Wallet>::Record) -> VcxCoreResult<Self> + where + Self: Sized, + { + todo!() + } + } + + impl WalletRecord<IndySdkWallet> for RevocationRegistryInfo { + const RECORD_TYPE: &'static str = "rev"; + + type RecordId<'a> = &'a RevocationRegistryId; + + fn into_wallet_record( + self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn as_wallet_record( + &self, + id: Self::RecordId<'_>, + ) -> VcxCoreResult<<IndySdkWallet as Wallet>::Record> { + todo!() + } + + fn from_wallet_record(record: <IndySdkWallet as Wallet>::Record) -> VcxCoreResult<Self> + where + Self: Sized, + { + todo!() + } + } + + let issuer = IndyCredxIssuer; + let wallet = IndySdkWallet::new(WalletHandle(0)); + let rev_reg_id = RevocationRegistryId(String::from("blabla")); + let cred_def_id = CredentialDefinitionId(String::from("blabla")); + async { + issuer.get_revocation_delta(&wallet, &rev_reg_id).await; + issuer + .create_and_store_revoc_reg( + &wallet, + "bla", + &cred_def_id, + "test", + 10, + "404_no_tags_found", + ) + .await + }; +} diff --git a/aries_vcx_core/src/vc/mod.rs b/aries_vcx_core/src/vc/mod.rs index cf16fa9787..73d57ddea2 100644 --- a/aries_vcx_core/src/vc/mod.rs +++ b/aries_vcx_core/src/vc/mod.rs @@ -36,19 +36,20 @@ pub trait VcIssuer { type RevRegDelta: Send + Sync; type RevRegInfo: Send + Sync; - async fn create_and_store_revoc_reg<'a, W>( + async fn create_and_store_revoc_reg<W>( &self, wallet: &W, issuer_did: &str, - cred_def_id: &'a Self::CredDefId, + cred_def_id: &Self::CredDefId, tails_dir: &str, max_creds: u32, tag: &str, ) -> VcxCoreResult<(Self::RevRegId, Self::RevRegDef, Self::RevReg)> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: - From<&'a Self::CredDefId> + From<&'b Self::RevRegId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, Self::CredDef: WalletRecord<W>, for<'b> Self::RevReg: WalletRecord<W, RecordId<'b> = &'b Self::RevRegId>, for<'b> Self::RevRegDef: WalletRecord<W, RecordId<'b> = &'b Self::RevRegId>, @@ -66,7 +67,8 @@ pub trait VcIssuer { ) -> VcxCoreResult<(Self::CredDefId, Self::CredDef)> where W: Wallet + Send + Sync, - for<'a> <W as Wallet>::RecordIdRef<'a>: From<&'a Self::CredDefId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, for<'a> Self::Schema: WalletRecord<W, RecordId<'a> = &'a Self::SchemaId>, for<'a> Self::SchemaId: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, for<'a> Self::CredDef: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, @@ -80,7 +82,8 @@ pub trait VcIssuer { ) -> VcxCoreResult<Self::CredOffer> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: From<&'a Self::CredDefId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::SchemaId: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, Self::CredDef: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>, Self::CredKeyProof: WalletRecord<W, RecordId<'a> = &'a Self::CredDefId>; @@ -96,8 +99,9 @@ pub trait VcIssuer { ) -> VcxCoreResult<(Self::Cred, Option<Self::CredRevId>)> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: - From<&'b Self::CredDefId> + From<&'a Self::RevRegId> + Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, for<'b> Self::Schema: WalletRecord<W, RecordId<'b> = &'b Self::SchemaId>, for<'b> Self::SchemaId: WalletRecord<W, RecordId<'b> = &'b Self::CredDefId>, for<'b> Self::CredDef: WalletRecord<W, RecordId<'b> = &'b Self::CredDefId>, @@ -126,8 +130,9 @@ pub trait VcIssuer { ) -> VcxCoreResult<()> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: - From<&'b Self::CredDefId> + From<&'a Self::RevRegId> + Send + Sync, + Self::CredDefId: AsRef<<W as Wallet>::RecordIdRef>, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::RevReg: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, Self::RevRegDef: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, Self::RevRegDefPriv: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>, @@ -142,7 +147,8 @@ pub trait VcIssuer { ) -> VcxCoreResult<Option<Self::RevRegDelta>> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: From<&'a Self::RevRegId> + Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::RevRegDelta: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>; async fn clear_revocation_delta<'a, W>( @@ -152,7 +158,8 @@ pub trait VcIssuer { ) -> VcxCoreResult<()> where W: Wallet + Send + Sync, - for<'b> <W as Wallet>::RecordIdRef<'b>: From<&'a Self::RevRegId> + Send + Sync, + Self::RevRegId: AsRef<<W as Wallet>::RecordIdRef>, + <W as Wallet>::RecordIdRef: Send + Sync, Self::RevRegDelta: WalletRecord<W, RecordId<'a> = &'a Self::RevRegId>; } diff --git a/aries_vcx_core/src/wallet2/mod.rs b/aries_vcx_core/src/wallet2/mod.rs index 90cea5e452..2d0aa25885 100644 --- a/aries_vcx_core/src/wallet2/mod.rs +++ b/aries_vcx_core/src/wallet2/mod.rs @@ -10,18 +10,18 @@ use crate::errors::error::VcxCoreResult; #[async_trait] pub trait Wallet { type Record: Send + Sync; - type RecordIdRef<'a>; + type RecordIdRef: ?Sized; type SearchFilter<'a>: Send + Sync; async fn add(&self, record: Self::Record) -> VcxCoreResult<()>; - async fn get<R>(&self, id: Self::RecordIdRef<'_>) -> VcxCoreResult<R> + async fn get<R>(&self, id: &Self::RecordIdRef) -> VcxCoreResult<R> where R: WalletRecord<Self>; async fn update(&self, update: Self::Record) -> VcxCoreResult<()>; - async fn delete<R>(&self, id: Self::RecordIdRef<'_>) -> VcxCoreResult<()> + async fn delete<R>(&self, id: &Self::RecordIdRef) -> VcxCoreResult<()> where R: WalletRecord<Self>; @@ -59,7 +59,7 @@ pub trait Wallet { pub trait WalletRecord<W: Wallet + ?Sized> { const RECORD_TYPE: &'static str; - type RecordId<'a>; + type RecordId<'a>: Send + Sync; fn into_wallet_record(self, id: Self::RecordId<'_>) -> VcxCoreResult<W::Record>; diff --git a/aries_vcx_core/src/wallet2/vdrtools.rs b/aries_vcx_core/src/wallet2/vdrtools.rs index 60dd6cac97..03492e8c31 100644 --- a/aries_vcx_core/src/wallet2/vdrtools.rs +++ b/aries_vcx_core/src/wallet2/vdrtools.rs @@ -17,7 +17,7 @@ const WALLET_OPTIONS: &str = #[async_trait] impl Wallet for IndySdkWallet { type Record = Record; - type RecordIdRef<'a> = &'a str; + type RecordIdRef = IndyWalletId; type SearchFilter<'a> = &'a str; async fn add(&self, record: Self::Record) -> VcxCoreResult<()> { @@ -34,7 +34,7 @@ impl Wallet for IndySdkWallet { .map_err(From::from) } - async fn get<R>(&self, id: Self::RecordIdRef<'_>) -> VcxCoreResult<R> + async fn get<R>(&self, id: &Self::RecordIdRef) -> VcxCoreResult<R> where R: WalletRecord<Self>, { @@ -43,7 +43,7 @@ impl Wallet for IndySdkWallet { .get_record( self.wallet_handle, R::RECORD_TYPE.into(), - id.to_string(), + id.0.to_string(), WALLET_OPTIONS.into(), ) .await?; @@ -73,13 +73,13 @@ impl Wallet for IndySdkWallet { Ok(()) } - async fn delete<R>(&self, id: Self::RecordIdRef<'_>) -> VcxCoreResult<()> + async fn delete<R>(&self, id: &Self::RecordIdRef) -> VcxCoreResult<()> where R: WalletRecord<Self>, { Locator::instance() .non_secret_controller - .delete_record(self.wallet_handle, R::RECORD_TYPE.into(), id.to_string()) + .delete_record(self.wallet_handle, R::RECORD_TYPE.into(), id.0.to_string()) .await?; Ok(()) @@ -220,3 +220,12 @@ impl Wallet for IndySdkWallet { }) } } + +#[repr(transparent)] +pub struct IndyWalletId(pub str); + +impl AsRef<str> for IndyWalletId { + fn as_ref(&self) -> &str { + &self.0 + } +} diff --git a/did_doc/tests/serde.rs b/did_doc/tests/serde.rs index d7c6aeb3c9..bf8b452ab5 100644 --- a/did_doc/tests/serde.rs +++ b/did_doc/tests/serde.rs @@ -127,7 +127,7 @@ fn test_deserialization() { ) .build(); - assert_eq!(did_doc.verification_method().get(0).unwrap().clone(), vm1); + assert_eq!(did_doc.verification_method().first().unwrap().clone(), vm1); assert_eq!(did_doc.verification_method().get(1).unwrap().clone(), vm2); assert_eq!( diff --git a/did_doc_sov/tests/builder.rs b/did_doc_sov/tests/builder.rs index 37cc6bbdf2..9f8c109c7f 100644 --- a/did_doc_sov/tests/builder.rs +++ b/did_doc_sov/tests/builder.rs @@ -26,7 +26,7 @@ fn test_service_build_aip1() { .build(); let services = did_doc.service(); assert_eq!(services.len(), 1); - let first_service = services.get(0).unwrap(); + let first_service = services.first().unwrap(); assert_eq!(first_service.id().clone(), ID.parse::<Uri>().unwrap()); assert_eq!( first_service.service_endpoint().clone(), @@ -56,7 +56,7 @@ fn test_service_build_didcommv1() { .build(); let services = did_doc.service(); assert_eq!(services.len(), 1); - let first_service = services.get(0).unwrap(); + let first_service = services.first().unwrap(); assert_eq!(first_service.id().clone(), ID.parse::<Uri>().unwrap()); assert_eq!( first_service.service_endpoint().clone(), @@ -90,7 +90,7 @@ fn test_service_build_didcommv2() { .build(); let services = did_doc.service(); assert_eq!(services.len(), 1); - let first_service = services.get(0).unwrap(); + let first_service = services.first().unwrap(); assert_eq!(first_service.id().clone(), ID.parse::<Uri>().unwrap()); assert_eq!( first_service.service_endpoint().clone(), diff --git a/did_doc_sov/tests/serde.rs b/did_doc_sov/tests/serde.rs index 3ebf9c8026..a74ec5b0c8 100644 --- a/did_doc_sov/tests/serde.rs +++ b/did_doc_sov/tests/serde.rs @@ -78,7 +78,7 @@ fn test_deserialization() { assert_eq!(did_doc.service().len(), 3); let services = did_doc.service(); - let first_service = services.get(0).unwrap(); + let first_service = services.first().unwrap(); assert_eq!( first_service.service_endpoint().to_string(), "https://example.com/endpoint" @@ -113,7 +113,7 @@ fn test_deserialization() { assert!(second_extra.first_recipient_key().is_ok()); assert!(second_extra.first_routing_key().is_err()); assert_eq!( - second_extra.accept().unwrap().get(0).unwrap().clone(), + second_extra.accept().unwrap().first().unwrap().clone(), AcceptType::DIDCommV1 ); assert_eq!(second_extra.priority().unwrap(), 0); @@ -124,7 +124,7 @@ fn test_deserialization() { assert!(third_extra.first_recipient_key().is_err()); assert!(third_extra.first_routing_key().is_err()); assert_eq!( - third_extra.accept().unwrap().get(0).unwrap().clone(), + third_extra.accept().unwrap().first().unwrap().clone(), AcceptType::DIDCommV2 ); assert!(third_extra.priority().is_err()); diff --git a/diddoc_legacy/src/aries/diddoc.rs b/diddoc_legacy/src/aries/diddoc.rs index d9bd546cc7..146e08090e 100644 --- a/diddoc_legacy/src/aries/diddoc.rs +++ b/diddoc_legacy/src/aries/diddoc.rs @@ -144,7 +144,7 @@ impl AriesDidDoc { } pub fn recipient_keys(&self) -> DiddocResult<Vec<String>> { - let service: AriesService = match self.service.get(0).cloned() { + let service: AriesService = match self.service.first().cloned() { Some(service) => service, None => return Ok(Vec::new()), }; @@ -160,7 +160,7 @@ impl AriesDidDoc { } pub fn routing_keys(&self) -> Vec<String> { - let service: AriesService = match self.service.get(0).cloned() { + let service: AriesService = match self.service.first().cloned() { Some(service) => service, None => return Vec::new(), }; @@ -168,11 +168,11 @@ impl AriesDidDoc { } pub fn get_endpoint(&self) -> Option<Url> { - self.service.get(0).map(|s| s.service_endpoint.clone()) + self.service.first().map(|s| s.service_endpoint.clone()) } pub fn get_service(&self) -> DiddocResult<AriesService> { - let service: &AriesService = self.service.get(0).ok_or(DiddocError::from_msg( + let service: &AriesService = self.service.first().ok_or(DiddocError::from_msg( DiddocErrorKind::InvalidState, format!("No service found on did doc: {self:?}"), ))?; diff --git a/libvdrtools/src/utils/mod.rs b/libvdrtools/src/utils/mod.rs index 5acf386eae..c5c38aba13 100755 --- a/libvdrtools/src/utils/mod.rs +++ b/libvdrtools/src/utils/mod.rs @@ -1,4 +1,3 @@ -pub use indy_utils::environment; pub mod crypto; pub use indy_utils::wql; #[macro_use] diff --git a/messages_macros/src/message_type.rs b/messages_macros/src/message_type.rs index 5317de42f5..8980cc77c4 100644 --- a/messages_macros/src/message_type.rs +++ b/messages_macros/src/message_type.rs @@ -102,7 +102,7 @@ fn process_protocol( // Generate an impl with const PROTOCOL set the to the string literal passed in the macro // attribute - field_impls.push(quote! {impl #field { const PROTOCOL: &str = #protocol; }}); + field_impls.push(quote! {impl #field { const PROTOCOL: &'static str = #protocol; }}); } quote! {