From d1492cd197a5331bcfb9125790a48f577c882d78 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Thu, 4 May 2023 10:13:33 +0300 Subject: [PATCH 1/6] First draft of new ledger traits Signed-off-by: Bogdan Mircea --- aries_vcx_core/src/ledger/ledger.rs | 141 ++++++++++++++++++++++++++++ aries_vcx_core/src/ledger/mod.rs | 1 + 2 files changed, 142 insertions(+) create mode 100644 aries_vcx_core/src/ledger/ledger.rs diff --git a/aries_vcx_core/src/ledger/ledger.rs b/aries_vcx_core/src/ledger/ledger.rs new file mode 100644 index 0000000000..cdba4d6229 --- /dev/null +++ b/aries_vcx_core/src/ledger/ledger.rs @@ -0,0 +1,141 @@ +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; + + type Request; + type ReqResult; + + // returns request result as JSON + async fn submit_request(&self, request_json: &str) -> VcxCoreResult; + + // adds endorser to request and signs with submitter_did, returns the transaction ready for endorser to take + async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult; + + async fn get_txn_author_agreement(&self) -> VcxCoreResult; + + // returns request result as JSON + async fn get_nym(&self, did: &str) -> VcxCoreResult; + + // 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 request result as JSON + async fn get_attr(&self, target_did: &str, attr_name: &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)>; + + // returns request result as JSON + async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult; +} + +#[async_trait] +pub trait LedgerWrite: LedgerRead { + // returns request result as JSON + async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult; + + // endorsers/multi signs a request, submits to ledger, and verifies successful result + async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()>; + + // returns request result as JSON + async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult; + + // returns request result as JSON + async fn publish_nym( + &self, + submitter_did: &str, + target_did: &str, + verkey: Option<&str>, + data: Option<&str>, + role: Option<&str>, + ) -> VcxCoreResult; + + // returns request as JSON + async fn build_schema_request(&self, submitter_did: &str, schema_json: Self::Schema) -> VcxCoreResult; + + async fn publish_schema( + &self, + schema_json: &str, + 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<()>; +} 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")] From 980458d54d50ae50d4098d66f78aa4146aa842be Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Thu, 4 May 2023 10:26:08 +0300 Subject: [PATCH 2/6] Added more associated types Signed-off-by: Bogdan Mircea --- aries_vcx_core/src/ledger/ledger.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/aries_vcx_core/src/ledger/ledger.rs b/aries_vcx_core/src/ledger/ledger.rs index cdba4d6229..727d35ed94 100644 --- a/aries_vcx_core/src/ledger/ledger.rs +++ b/aries_vcx_core/src/ledger/ledger.rs @@ -17,10 +17,15 @@ pub trait LedgerRead { type ReqResult; // returns request result as JSON - async fn submit_request(&self, request_json: &str) -> VcxCoreResult; + async fn submit_request(&self, request_json: Self::Request) -> VcxCoreResult; // adds endorser to request and signs with submitter_did, returns the transaction ready for endorser to take - async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult; + async fn set_endorser( + &self, + submitter_did: &str, + request: Self::Request, + endorser: &str, + ) -> VcxCoreResult; async fn get_txn_author_agreement(&self) -> VcxCoreResult; @@ -100,10 +105,14 @@ pub trait LedgerRead { #[async_trait] pub trait LedgerWrite: LedgerRead { // returns request result as JSON - async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult; + async fn sign_and_submit_request( + &self, + submitter_did: &str, + request_json: Self::Schema, + ) -> VcxCoreResult; // endorsers/multi signs a request, submits to ledger, and verifies successful result - async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()>; + async fn endorse_transaction(&self, endorser_did: &str, request_json: Self::Request) -> VcxCoreResult<()>; // returns request result as JSON async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult; @@ -119,11 +128,15 @@ pub trait LedgerWrite: LedgerRead { ) -> VcxCoreResult; // returns request as JSON - async fn build_schema_request(&self, submitter_did: &str, schema_json: Self::Schema) -> VcxCoreResult; + async fn build_schema_request( + &self, + submitter_did: &str, + schema_json: Self::Schema, + ) -> VcxCoreResult; async fn publish_schema( &self, - schema_json: &str, + schema_json: Self::Schema, submitter_did: &str, endorser_did: Option, ) -> VcxCoreResult<()>; From c5bb265f3f26ad9aeb4649fbb183443fdb7889bb Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Thu, 4 May 2023 11:02:47 +0300 Subject: [PATCH 3/6] Trimmed down ledger traits Signed-off-by: Bogdan Mircea --- aries_vcx_core/src/ledger/ledger.rs | 57 +---------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/aries_vcx_core/src/ledger/ledger.rs b/aries_vcx_core/src/ledger/ledger.rs index 727d35ed94..1b3e0d3c36 100644 --- a/aries_vcx_core/src/ledger/ledger.rs +++ b/aries_vcx_core/src/ledger/ledger.rs @@ -13,25 +13,6 @@ pub trait LedgerRead { type RevRegDelta; type RevReg; - type Request; - type ReqResult; - - // returns request result as JSON - async fn submit_request(&self, request_json: Self::Request) -> VcxCoreResult; - - // adds endorser to request and signs with submitter_did, returns the transaction ready for endorser to take - async fn set_endorser( - &self, - submitter_did: &str, - request: Self::Request, - endorser: &str, - ) -> VcxCoreResult; - - async fn get_txn_author_agreement(&self) -> VcxCoreResult; - - // returns request result as JSON - async fn get_nym(&self, did: &str) -> VcxCoreResult; - // Schema json. // { // id: identifier of schema @@ -48,9 +29,6 @@ pub trait LedgerRead { // 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 request result as JSON - async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult; - // # Returns // Revocation Registry Definition Id and Revocation Registry Definition json. // { @@ -97,43 +75,10 @@ pub trait LedgerRead { // "ver": string - version revocation registry json // } async fn get_rev_reg(&self, rev_reg_id: &str, timestamp: u64) -> VcxCoreResult<(String, Self::RevReg, u64)>; - - // returns request result as JSON - async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult; } #[async_trait] pub trait LedgerWrite: LedgerRead { - // returns request result as JSON - async fn sign_and_submit_request( - &self, - submitter_did: &str, - request_json: Self::Schema, - ) -> VcxCoreResult; - - // endorsers/multi signs a request, submits to ledger, and verifies successful result - async fn endorse_transaction(&self, endorser_did: &str, request_json: Self::Request) -> VcxCoreResult<()>; - - // returns request result as JSON - async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult; - - // returns request result as JSON - async fn publish_nym( - &self, - submitter_did: &str, - target_did: &str, - verkey: Option<&str>, - data: Option<&str>, - role: Option<&str>, - ) -> VcxCoreResult; - - // returns request as JSON - async fn build_schema_request( - &self, - submitter_did: &str, - schema_json: Self::Schema, - ) -> VcxCoreResult; - async fn publish_schema( &self, schema_json: Self::Schema, @@ -151,4 +96,6 @@ pub trait LedgerWrite: LedgerRead { 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<()>; } From a7e23e8e6717ff5ad47bbe623db21b6de6b99fe4 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Thu, 4 May 2023 11:40:03 +0300 Subject: [PATCH 4/6] First draft for Wallet trait Signed-off-by: Bogdan Mircea --- aries_vcx_core/src/anoncreds/anoncreds.rs | 0 aries_vcx_core/src/anoncreds/mod.rs | 1 + aries_vcx_core/src/ledger/ledger.rs | 2 - aries_vcx_core/src/wallet/mod.rs | 1 + aries_vcx_core/src/wallet/wallet.rs | 64 +++++++++++++++++++++++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 aries_vcx_core/src/anoncreds/anoncreds.rs create mode 100644 aries_vcx_core/src/wallet/wallet.rs diff --git a/aries_vcx_core/src/anoncreds/anoncreds.rs b/aries_vcx_core/src/anoncreds/anoncreds.rs new file mode 100644 index 0000000000..e69de29bb2 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 index 1b3e0d3c36..8b86cee072 100644 --- a/aries_vcx_core/src/ledger/ledger.rs +++ b/aries_vcx_core/src/ledger/ledger.rs @@ -6,9 +6,7 @@ use crate::errors::error::VcxCoreResult; #[async_trait] pub trait LedgerRead { type Schema; - type CredDef; - type RevRegDef; type RevRegDelta; type RevReg; 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>; +} From 2cf88c9dc78ccc0a4493819e93f2d5a16e270766 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Thu, 4 May 2023 14:54:48 +0300 Subject: [PATCH 5/6] More updates to anoncreds Signed-off-by: Bogdan Mircea --- aries_vcx_core/src/anoncreds/anoncreds.rs | 148 ++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/aries_vcx_core/src/anoncreds/anoncreds.rs b/aries_vcx_core/src/anoncreds/anoncreds.rs index e69de29bb2..f1346a2d2e 100644 --- a/aries_vcx_core/src/anoncreds/anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/anoncreds.rs @@ -0,0 +1,148 @@ +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: + +pub struct IndyAnonCredsVerifier; + +pub struct IndyLedger; + +#[async_trait] +impl LedgerRead for IndyVdrLedger { + type Schema = anoncreds::IndyVdrSchema; + type CredDef = anoncreds::AnonCredsCredDef; + +} + +impl LedgerRead for VdrToolsLedger { + type Schema = anoncreds::IndyVdrSchema; + type CredDef = anoncreds::IndyVdrCredDef; +} + +#[async_trait] +impl AnonCredsVerifier for IndyAnonCredsVerifier { + type Ledger = VdrToolsLedger; + + +} + + + +#[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 From 86dc665c86de3d901a1ea812ce606eb38cb1c38c Mon Sep 17 00:00:00 2001 From: Bogdan Mircea Date: Fri, 5 May 2023 10:32:01 +0200 Subject: [PATCH 6/6] Removed dummy drafts from anoncreds Signed-off-by: Bogdan Mircea --- aries_vcx_core/src/anoncreds/anoncreds.rs | 25 ----------------------- 1 file changed, 25 deletions(-) diff --git a/aries_vcx_core/src/anoncreds/anoncreds.rs b/aries_vcx_core/src/anoncreds/anoncreds.rs index f1346a2d2e..bbe9beeac2 100644 --- a/aries_vcx_core/src/anoncreds/anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/anoncreds.rs @@ -6,31 +6,6 @@ use crate::{errors::error::VcxCoreResult, ledger::ledger::LedgerRead}; /// input and output types are based off the indy Anoncreds API: /// see: -pub struct IndyAnonCredsVerifier; - -pub struct IndyLedger; - -#[async_trait] -impl LedgerRead for IndyVdrLedger { - type Schema = anoncreds::IndyVdrSchema; - type CredDef = anoncreds::AnonCredsCredDef; - -} - -impl LedgerRead for VdrToolsLedger { - type Schema = anoncreds::IndyVdrSchema; - type CredDef = anoncreds::IndyVdrCredDef; -} - -#[async_trait] -impl AnonCredsVerifier for IndyAnonCredsVerifier { - type Ledger = VdrToolsLedger; - - -} - - - #[async_trait] pub trait AnonCredsVerifier { type Ledger: LedgerRead;