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

First draft of new ledger traits #829

Closed
wants to merge 6 commits into from
Closed
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
123 changes: 123 additions & 0 deletions aries_vcx_core/src/anoncreds/anoncreds.rs
Original file line number Diff line number Diff line change
@@ -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: <https://github.com/hyperledger/indy-sdk/blob/main/libindy/src/api/anoncreds.rs>

#[async_trait]
pub trait AnonCredsVerifier {
type Ledger: LedgerRead;

async fn verifier_verify_proof(
&self,
proof_request_json: &str,
proof_json: &str,
schemas_json: <Self::Ledger as LedgerRead>::Schema,
credential_defs_json: <Self::Ledger as LedgerRead>::CredDef,
rev_reg_defs_json: Vec<<Self::Ledger as LedgerRead>::RevRegDef>,
rev_regs_json: Vec<<Self::Ledger as LedgerRead>::RevReg>,
) -> VcxCoreResult<bool>;

async fn generate_nonce(&self) -> VcxCoreResult<String>;
}

#[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<String>;

async fn prover_get_credential(&self, cred_id: &str) -> VcxCoreResult<String>;

async fn prover_get_credentials(&self, filter_json: Option<&str>) -> VcxCoreResult<String>;

async fn prover_get_credentials_for_proof_req(&self, proof_request_json: &str) -> VcxCoreResult<String>;

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<String>;

async fn prover_delete_credential(&self, cred_id: &str) -> VcxCoreResult<()>;

async fn prover_create_link_secret(&self, link_secret_id: &str) -> VcxCoreResult<String>;
}

#[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<String>;

async fn issuer_create_credential(
&self,
cred_offer_json: &str,
cred_req_json: &str,
cred_values_json: &str,
rev_reg_id: Option<String>,
tails_dir: Option<String>,
) -> VcxCoreResult<(String, Option<String>, Option<String>)>;

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<String>;

// 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<()>;
}
1 change: 1 addition & 0 deletions aries_vcx_core/src/anoncreds/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod base_anoncreds;
pub mod anoncreds;
#[cfg(feature = "modular_libs")]
pub mod credx_anoncreds;
#[cfg(feature = "vdrtools")]
Expand Down
99 changes: 99 additions & 0 deletions aries_vcx_core/src/ledger/ledger.rs
Original file line number Diff line number Diff line change
@@ -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<Self::Schema>;

// 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<Self::CredDef>;

// # 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": <public_keys> - 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<Self::RevRegDef>;

// # 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<number> - an array of issued indices.
// revoked: array<number> 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<u64>,
to: Option<u64>,
) -> 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<String>,
) -> 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<()>;
}
1 change: 1 addition & 0 deletions aries_vcx_core/src/ledger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod base_ledger;
pub mod ledger;
#[cfg(feature = "vdrtools")]
pub mod indy_ledger;
#[cfg(feature = "modular_libs")]
Expand Down
1 change: 1 addition & 0 deletions aries_vcx_core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod agency_client_wallet;
pub mod wallet;
pub mod base_wallet;
#[cfg(feature = "vdrtools")]
pub mod indy_wallet;
64 changes: 64 additions & 0 deletions aries_vcx_core/src/wallet/wallet.rs
Original file line number Diff line number Diff line change
@@ -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: <https://github.com/hyperledger/indy-sdk/blob/main/libindy/src/api/wallet.rs>
#[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<String>;

// returns new temp_verkey and remembers it internally
async fn replace_did_keys_start(&self, target_did: &str) -> VcxCoreResult<String>;

// 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<HashMap<String, String>>)
-> VcxCoreResult<()>;

async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult<Self::Record>;

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<String, String>) -> VcxCoreResult<()>;

async fn update_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: HashMap<String, String>) -> VcxCoreResult<()>;

async fn delete_wallet_record_tags(&self, xtype: &str, id: &str, tag_names: Vec<String>) -> VcxCoreResult<()>;

async fn iterate_wallet_records(
&self,
xtype: &str,
query: &str,
options: &str,
) -> VcxCoreResult<Box<dyn AsyncFnIterator<Item = VcxCoreResult<String>>>>;

// ---- crypto

async fn sign(&self, my_vk: &str, msg: &[u8]) -> VcxCoreResult<Vec<u8>>;

async fn verify(&self, vk: &str, msg: &[u8], signature: &[u8]) -> VcxCoreResult<bool>;

async fn pack_message(&self, sender_vk: Option<&str>, receiver_keys: &str, msg: &[u8]) -> VcxCoreResult<Vec<u8>>;

async fn unpack_message(&self, msg: &[u8]) -> VcxCoreResult<Vec<u8>>;
}