Struct vade::Vade

source ·
pub struct Vade {
    pub plugins: Vec<Box<dyn VadePlugin>>,
}
Expand description

A Vade instance is your single point of contact for interacting with DIDs and VCs.

Fields§

§plugins: Vec<Box<dyn VadePlugin>>

registered plugins

Implementations§

source§

impl Vade

source

pub fn new() -> Self

Creates new Vade instance, vectors are initialized as empty.

source

pub async fn did_create( &mut self, did_method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Creates a new DID. May also persist a DID document for it, depending on plugin implementation.

Arguments
  • did_method - did method to cater to, usually also used by plugins to decide if a plugins will process the request
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.did_create("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created new did: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn did_resolve( &mut self, did: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Fetch data about a DID. This usually returns a DID document.

Arguments
  • did - did to fetch data for
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.did_resolve("did:example:123").await?;
    if !results.is_empty() {
        println!("got did: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn did_update( &mut self, did: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Updates data related to a DID. May also persist a DID document for it, depending on plugin implementation.

Arguments
  • did - DID to update data for
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.did_update("did:example", "", "").await?;
    if !results.is_empty() {
        println!("did successfully updated: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn didcomm_receive( &mut self, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Processes a DIDComm message as received, this may prepare a matching response for it if the DIDComm message can be interpreted and answered by a plugin’s implementation.

This response may be sent, depending on the configuration and implementation of underlying plugins, but it is usually also returned as response to this request.

Arguments
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (usually a raw DIDComm message)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.didcomm_receive("", "").await?;
    if !results.is_empty() {
        println!("received DIDComm message: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn didcomm_send( &mut self, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Processes a DIDComm message and prepares it for sending.

It may be sent, depending on the configuration and implementation of underlying plugins.

Arguments
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (usually a raw DIDComm message)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.didcomm_send("", "").await?;
    if !results.is_empty() {
        println!("prepared DIDComm message: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub fn register_plugin(&mut self, plugin: Box<dyn VadePlugin>)

Registers a new plugin. See VadePlugin for details about how they work.

Arguments
  • plugin - plugin to register
Example
use vade::Vade;
// use some_crate::ExamplePlugin;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    let mut example_plugin = ExamplePlugin::new();
    vade.register_plugin(Box::from(example_plugin));
    let results = vade.did_create("did:example", "", "").await?;
    if !results.is_empty() {
        println!("did successfully updated: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn run_custom_function( &mut self, method: &str, function: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Runs a custom function, this allows to use Vades API for custom calls, that do not belong to Vades core functionality but may be required for a projects use cases.

Arguments
  • method - method to call a function for (e.g. “did:example”)
  • function - function to call (e.g. “test connection”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.run_custom_function("did:example", "test connection", "", "").await?;
    if !results.is_empty() {
        println!("connection status is: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_create_credential_definition( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Creates a new zero-knowledge proof credential definition. A credential definition holds cryptographic key material and is needed by an issuer to issue a credential, thus needs to be created before issuance. A credential definition is always bound to one credential schema.

Arguments
  • method - method to create a credential definition for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_create_credential_definition("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created a credential definition: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_create_credential_offer( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Creates a new zero-knowledge proof credential offer. This message is the response to a credential proposal.

Arguments
  • method - method to create a credential offer for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_create_credential_offer("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created a credential offer: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_create_credential_proposal( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Creates a new zero-knowledge proof credential proposal. This message is the first in the credential issuance flow.

Arguments
  • method - method to create a credential proposal for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_create_credential_proposal("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created a credential proposal: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_create_credential_schema( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Creates a new zero-knowledge proof credential schema. The schema specifies properties a credential includes, both optional and mandatory.

Arguments
  • method - method to create a credential schema for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_create_credential_schema("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created a credential schema: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_create_revocation_registry_definition( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Creates a new revocation registry definition. The definition consists of a public and a private part. The public part holds the cryptographic material needed to create non-revocation proofs. The private part needs to reside with the registry owner and is used to revoke credentials.

Arguments
  • method - method to create a revocation registry definition for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_create_revocation_registry_definition("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created a revocation registry definition: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_update_revocation_registry( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Updates a revocation registry for a zero-knowledge proof. This step is necessary after revocation one or more credentials.

Arguments
  • method - method to update a revocation registry for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_update_revocation_registry("did:example", "", "").await?;
    if !results.is_empty() {
        println!("updated revocation registry: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_issue_credential( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Issues a new credential. This requires an issued schema, credential definition, an active revocation registry and a credential request message.

Arguments
  • method - method to issue a credential for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_issue_credential("did:example", "", "").await?;
    if !results.is_empty() {
        println!("issued credential: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_finish_credential( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Finishes a credential, e.g. by incorporating the prover’s master secret into the credential signature after issuance.

Arguments
  • method - method to update a finish credential for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_finish_credential("did:example", "", "").await?;
    if !results.is_empty() {
        println!("issued credential: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_present_proof( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Presents a proof for a zero-knowledge proof credential. A proof presentation is the response to a proof request.

Arguments
  • method - method to presents a proof for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_present_proof("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created a proof presentation: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_propose_proof( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Proposes a zero-knowledge proof for one or more credentials issued under one or more specific schemas.

Arguments
  • method - method to propose a proof for (e.g. “did:example”)
  • options - JSON string with additional information supporting the proposal (e.g. authentication data)
  • payload - JSON string with information for the proposal (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_propose_proof("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created proof proposal: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_request_credential( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Requests a credential. This message is the response to a credential offering.

Arguments
  • method - method to request a credential for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_request_credential("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created credential request: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_request_proof( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Requests a zero-knowledge proof for one or more credentials issued under one or more specific schemas.

Arguments
  • method - method to request a proof for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_request_proof("did:example", "", "").await?;
    if !results.is_empty() {
        println!("created proof request: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_revoke_credential( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Revokes a credential. After revocation the published revocation registry needs to be updated with information returned by this function.

Arguments
  • method - method to revoke a credential for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_revoke_credential("did:example", "", "").await?;
    if !results.is_empty() {
        println!("revoked credential: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}
source

pub async fn vc_zkp_verify_proof( &mut self, method: &str, options: &str, payload: &str ) -> Result<Vec<Option<String>>, Box<dyn Error>>

Verifies one or multiple proofs sent in a proof presentation.

Arguments
  • method - method to verify a proof for (e.g. “did:example”)
  • options - JSON string with additional information supporting the request (e.g. authentication data)
  • payload - JSON string with information for the request (e.g. actual data to write)
Example
use vade::Vade;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut vade = Vade::new();
    // // register example plugin e.g. with
    // vade.register_plugin(example_plugin);
    let results = vade.vc_zkp_verify_proof("did:example", "", "").await?;
    if !results.is_empty() {
        println!("verified proof: {}", results[0].as_ref().ok_or("result not found")?);
    }
    Ok(())
}

Trait Implementations§

source§

impl Default for Vade

source§

fn default() -> Self

Default Vade instance

Auto Trait Implementations§

§

impl !RefUnwindSafe for Vade

§

impl !Send for Vade

§

impl !Sync for Vade

§

impl Unpin for Vade

§

impl !UnwindSafe for Vade

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.