diff --git a/aries_vcx_core/src/anoncreds/anoncreds.rs b/aries_vcx_core/src/anoncreds/anoncreds.rs new file mode 100644 index 0000000000..bbe9beeac2 --- /dev/null +++ b/aries_vcx_core/src/anoncreds/anoncreds.rs @@ -0,0 +1,123 @@ +use async_trait::async_trait; + +use crate::{errors::error::VcxCoreResult, ledger::ledger::LedgerRead}; + +/// Trait defining standard 'anoncreds' related functionality. The APIs, including +/// input and output types are based off the indy Anoncreds API: +/// see: + +#[async_trait] +pub trait AnonCredsVerifier { + type Ledger: LedgerRead; + + async fn verifier_verify_proof( + &self, + proof_request_json: &str, + proof_json: &str, + schemas_json: ::Schema, + credential_defs_json: ::CredDef, + rev_reg_defs_json: Vec<::RevRegDef>, + rev_regs_json: Vec<::RevReg>, + ) -> VcxCoreResult; + + async fn generate_nonce(&self) -> VcxCoreResult; +} + +#[async_trait] +pub trait AnonCredsProver { + type Ledger: LedgerRead; + + async fn prover_create_proof( + &self, + proof_req_json: &str, + requested_credentials_json: &str, + master_secret_id: &str, + schemas_json: &str, + credential_defs_json: &str, + revoc_states_json: Option<&str>, + ) -> VcxCoreResult; + + async fn prover_get_credential(&self, cred_id: &str) -> VcxCoreResult; + + async fn prover_get_credentials(&self, filter_json: Option<&str>) -> VcxCoreResult; + + async fn prover_get_credentials_for_proof_req(&self, proof_request_json: &str) -> VcxCoreResult; + + async fn prover_create_credential_req( + &self, + prover_did: &str, + cred_offer_json: &str, + cred_def_json: &str, + master_secret_id: &str, + ) -> VcxCoreResult<(String, String)>; + + async fn prover_store_credential( + &self, + cred_id: Option<&str>, + cred_req_metadata_json: &str, + cred_json: &str, + cred_def_json: &str, + rev_reg_def_json: Option<&str>, + ) -> VcxCoreResult; + + async fn prover_delete_credential(&self, cred_id: &str) -> VcxCoreResult<()>; + + async fn prover_create_link_secret(&self, link_secret_id: &str) -> VcxCoreResult; +} + +#[async_trait] +pub trait AnonCredsIssuer { + type Ledger: LedgerRead; + + async fn issuer_create_schema( + &self, + issuer_did: &str, + name: &str, + version: &str, + attrs: &str, + ) -> VcxCoreResult<(String, String)>; + + async fn issuer_create_and_store_revoc_reg( + &self, + issuer_did: &str, + cred_def_id: &str, + tails_dir: &str, + max_creds: u32, + tag: &str, + ) -> VcxCoreResult<(String, String, String)>; + + async fn issuer_create_and_store_credential_def( + &self, + issuer_did: &str, + schema_json: &str, + tag: &str, + signature_type: Option<&str>, + config_json: &str, + ) -> VcxCoreResult<(String, String)>; + + async fn issuer_create_credential_offer(&self, cred_def_id: &str) -> VcxCoreResult; + + async fn issuer_create_credential( + &self, + cred_offer_json: &str, + cred_req_json: &str, + cred_values_json: &str, + rev_reg_id: Option, + tails_dir: Option, + ) -> VcxCoreResult<(String, Option, Option)>; + + async fn create_revocation_state( + &self, + tails_dir: &str, + rev_reg_def_json: &str, + rev_reg_delta_json: &str, + timestamp: u64, + cred_rev_id: &str, + ) -> VcxCoreResult; + + // TODO - FUTURE - think about moving this to somewhere else, as it aggregates other calls (not PURE Anoncreds) + async fn revoke_credential_local(&self, tails_dir: &str, rev_reg_id: &str, cred_rev_id: &str) -> VcxCoreResult<()>; + + // TODO - FUTURE - think about moving this to somewhere else, as it aggregates other calls (not PURE Anoncreds) + async fn publish_local_revocations(&self, submitter_did: &str, rev_reg_id: &str) -> VcxCoreResult<()>; +} \ No newline at end of file diff --git a/aries_vcx_core/src/anoncreds/mod.rs b/aries_vcx_core/src/anoncreds/mod.rs index fec6fc4aed..69821e7f05 100644 --- a/aries_vcx_core/src/anoncreds/mod.rs +++ b/aries_vcx_core/src/anoncreds/mod.rs @@ -1,4 +1,5 @@ pub mod base_anoncreds; +pub mod anoncreds; #[cfg(feature = "modular_libs")] pub mod credx_anoncreds; #[cfg(feature = "vdrtools")] diff --git a/aries_vcx_core/src/ledger/ledger.rs b/aries_vcx_core/src/ledger/ledger.rs new file mode 100644 index 0000000000..8b86cee072 --- /dev/null +++ b/aries_vcx_core/src/ledger/ledger.rs @@ -0,0 +1,99 @@ +use async_trait::async_trait; + +use crate::errors::error::VcxCoreResult; + +/// Trait defining standard 'ledger' related functionality. +#[async_trait] +pub trait LedgerRead { + type Schema; + type CredDef; + type RevRegDef; + type RevRegDelta; + type RevReg; + + // Schema json. + // { + // id: identifier of schema + // attrNames: array of attribute name strings + // name: Schema's name string + // version: Schema's version string + // ver: Version of the Schema json + // } + // if submitter_did provided - use cache + // TO CONSIDER - do we need to return the schema ID in a tuple? is it ever different to the input? + async fn get_schema(&self, schema_id: &str, submitter_did: Option<&str>) -> VcxCoreResult; + + // if submitter_did provided, try use cache + // TO CONSIDER - do we need to return the cred def ID in a tuple? is it ever different to the input? + async fn get_cred_def(&self, cred_def_id: &str, submitter_did: Option<&str>) -> VcxCoreResult; + + // # Returns + // Revocation Registry Definition Id and Revocation Registry Definition json. + // { + // "id": string - ID of the Revocation Registry, + // "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now), + // "tag": string - Unique descriptive ID of the Registry, + // "credDefId": string - ID of the corresponding CredentialDefinition, + // "value": Registry-specific data { + // "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND), + // "maxCredNum": number - Maximum number of credentials the Registry can serve. + // "tailsHash": string - Hash of tails. + // "tailsLocation": string - Location of tails file. + // "publicKeys": - Registry's public key. + // }, + // "ver": string - version of revocation registry definition json. + // } + // TO CONSIDER - do we need to return the rev reg id in a tuple? is it ever different to the input? + async fn get_rev_reg_def_json(&self, rev_reg_id: &str) -> VcxCoreResult; + + // # Returns + // Revocation Registry Definition Id, Revocation Registry Delta json and Timestamp. + // { + // "value": Registry-specific data { + // prevAccum: string - previous accumulator value. + // accum: string - current accumulator value. + // issued: array - an array of issued indices. + // revoked: array an array of revoked indices. + // }, + // "ver": string - version revocation registry delta json + // } + async fn get_rev_reg_delta_json( + &self, + rev_reg_id: &str, + from: Option, + to: Option, + ) -> VcxCoreResult<(String, Self::RevRegDelta, u64)>; + + // # Returns + // Revocation Registry Definition Id, Revocation Registry json and Timestamp. + // { + // "value": Registry-specific data { + // "accum": string - current accumulator value. + // }, + // "ver": string - version revocation registry json + // } + async fn get_rev_reg(&self, rev_reg_id: &str, timestamp: u64) -> VcxCoreResult<(String, Self::RevReg, u64)>; +} + +#[async_trait] +pub trait LedgerWrite: LedgerRead { + async fn publish_schema( + &self, + schema_json: Self::Schema, + submitter_did: &str, + endorser_did: Option, + ) -> VcxCoreResult<()>; + + async fn publish_cred_def(&self, cred_def_json: Self::CredDef, submitter_did: &str) -> VcxCoreResult<()>; + + async fn publish_rev_reg_def(&self, rev_reg_def: Self::RevRegDef, submitter_did: &str) -> VcxCoreResult<()>; + + async fn publish_rev_reg_delta( + &self, + rev_reg_id: &str, + rev_reg_entry_json: &str, + submitter_did: &str, + ) -> VcxCoreResult<()>; + + async fn publish_rev_reg(&self, rev_reg_id: &str, rev_reg: Self::RevReg, timestamp: u64) -> VcxCoreResult<()>; +} diff --git a/aries_vcx_core/src/ledger/mod.rs b/aries_vcx_core/src/ledger/mod.rs index 911d544c08..ea5fc1bab8 100644 --- a/aries_vcx_core/src/ledger/mod.rs +++ b/aries_vcx_core/src/ledger/mod.rs @@ -1,4 +1,5 @@ pub mod base_ledger; +pub mod ledger; #[cfg(feature = "vdrtools")] pub mod indy_ledger; #[cfg(feature = "modular_libs")] diff --git a/aries_vcx_core/src/wallet/mod.rs b/aries_vcx_core/src/wallet/mod.rs index fda16d0ebd..16ec3bd611 100644 --- a/aries_vcx_core/src/wallet/mod.rs +++ b/aries_vcx_core/src/wallet/mod.rs @@ -1,4 +1,5 @@ pub mod agency_client_wallet; +pub mod wallet; pub mod base_wallet; #[cfg(feature = "vdrtools")] pub mod indy_wallet; diff --git a/aries_vcx_core/src/wallet/wallet.rs b/aries_vcx_core/src/wallet/wallet.rs new file mode 100644 index 0000000000..24801b6e90 --- /dev/null +++ b/aries_vcx_core/src/wallet/wallet.rs @@ -0,0 +1,64 @@ +use std::collections::HashMap; + +use async_trait::async_trait; + +use crate::errors::error::VcxCoreResult; +use crate::utils::async_fn_iterator::AsyncFnIterator; + +/// Trait defining standard 'wallet' related functionality. The APIs, including +/// input and output types are loosely based off the indy Wallet API: +/// see: +#[async_trait] +pub trait Wallet { + type Record; + + // ----- DIDs + + async fn create_and_store_my_did( + &self, + seed: Option<&str>, + method_name: Option<&str>, + ) -> VcxCoreResult<(String, String)>; + + async fn key_for_local_did(&self, did: &str) -> VcxCoreResult; + + // returns new temp_verkey and remembers it internally + async fn replace_did_keys_start(&self, target_did: &str) -> VcxCoreResult; + + // replaces the `target_did`'s current verkey with the one last generated by `replace_did_keys_start` + async fn replace_did_keys_apply(&self, target_did: &str) -> VcxCoreResult<()>; + + // ---- records + + async fn add_wallet_record(&self, xtype: &str, id: &str, value: &str, tags_json: Option>) + -> VcxCoreResult<()>; + + async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult; + + async fn delete_wallet_record(&self, xtype: &str, id: &str) -> VcxCoreResult<()>; + + async fn update_wallet_record_value(&self, xtype: &str, id: &str, value: &str) -> VcxCoreResult<()>; + + async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: HashMap) -> VcxCoreResult<()>; + + async fn update_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: HashMap) -> VcxCoreResult<()>; + + async fn delete_wallet_record_tags(&self, xtype: &str, id: &str, tag_names: Vec) -> VcxCoreResult<()>; + + async fn iterate_wallet_records( + &self, + xtype: &str, + query: &str, + options: &str, + ) -> VcxCoreResult>>>; + + // ---- crypto + + async fn sign(&self, my_vk: &str, msg: &[u8]) -> VcxCoreResult>; + + async fn verify(&self, vk: &str, msg: &[u8], signature: &[u8]) -> VcxCoreResult; + + async fn pack_message(&self, sender_vk: Option<&str>, receiver_keys: &str, msg: &[u8]) -> VcxCoreResult>; + + async fn unpack_message(&self, msg: &[u8]) -> VcxCoreResult>; +}