Struct AsyncSecureStore

Source
pub struct AsyncSecureStore { /* private fields */ }
Expand description

Holds private and verified VIDs

A Store contains verified VIDs, our relationship status to them, as well as the private VIDs that this application has control over.

§Example

use tsp_sdk::{AsyncSecureStore, OwnedVid, Error, ReceivedTspMessage};

#[tokio::main]
async fn main() {
    // alice wallet
    let mut db = AsyncSecureStore::new();
    let alice_vid = OwnedVid::from_file("../examples/test/alice/piv.json").await.unwrap();
    db.add_private_vid(alice_vid).unwrap();
    db.verify_vid("did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:bob", None).await.unwrap();

    // send a message
    let result = db.send(
        "did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:alice",
        "did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:bob",
        Some(b"extra non-confidential data"),
        b"hello world",
    ).await;
}

Implementations§

Source§

impl AsyncSecureStore

Source

pub fn new() -> Self

Create a new and empty store

Source

pub fn export(&self) -> Result<(Vec<ExportVid>, Aliases), Error>

Export the wallet to serializable default types

Source

pub fn as_store(&self) -> &SecureStore

Expose the inner non-async wallet

Source

pub fn import( &self, vids: Vec<ExportVid>, aliases: Aliases, ) -> Result<(), Error>

Import the wallet from serializable default types

Source

pub fn set_relation_and_status_for_vid( &self, vid: &str, status: RelationshipStatus, relation_vid: &str, ) -> Result<(), Error>

Adds a relation to an already existing VID, making it a nested VID

Source

pub fn set_route_for_vid(&self, vid: &str, route: &[&str]) -> Result<(), Error>

Adds a route to an already existing VID, making it a nested VID

Source

pub fn set_parent_for_vid( &self, vid: &str, parent: Option<&str>, ) -> Result<(), Error>

Sets the parent for a VID. This is used to create a nested message.

Source

pub fn list_vids(&self) -> Result<Vec<String>, Error>

List all VIDs in the wallet

Source

pub fn add_private_vid( &self, private_vid: impl PrivateVid + Clone + 'static, ) -> Result<(), Error>

Adds private_vid to the wallet

Source

pub fn forget_vid(&self, vid: &str) -> Result<(), Error>

Remove a VID from the AsyncSecureStore

Source

pub fn add_verified_vid( &self, verified_vid: impl VerifiedVid + 'static, ) -> Result<(), Error>

Add the already resolved verified_vid to the wallet as a relationship

Source

pub fn has_private_vid(&self, vid: &str) -> Result<bool, Error>

Check whether the PrivateVid identified by vid exists in the wallet

Source

pub fn has_verified_vid(&self, vid: &str) -> Result<bool, Error>

Check whether the VerifiedVid identified by vid exists in the wallet

Source

pub async fn verify_vid( &mut self, vid: &str, alias: Option<String>, ) -> Result<(), Error>

Resolve and verify public key material for a VID identified by vid and add it to the wallet as a relationship

Source

pub fn resolve_alias(&self, alias: &str) -> Result<Option<String>, Error>

Resolve alias to its corresponding DID

Source

pub fn try_resolve_alias(&self, alias: &str) -> Result<String, Error>

Resolve alias to its corresponding DID

Source

pub fn set_alias(&self, alias: String, did: String) -> Result<(), Error>

Set alias for a DID

Source

pub fn seal_message( &self, sender: &str, receiver: &str, nonconfidential_data: Option<&[u8]>, message: &[u8], ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn send( &self, sender: &str, receiver: &str, nonconfidential_data: Option<&[u8]>, message: &[u8], ) -> Result<(), Error>

Send a TSP message given earlier resolved VIDs Encodes, encrypts, signs, and sends a TSP message

§Arguments
  • sender - A sender VID
  • receiver - A receiver VID
  • nonconfidential_data - Optional extra non-confidential data
  • payload - The raw message payload as byte slice
§Example
use tsp_sdk::{AsyncSecureStore, OwnedVid};

#[tokio::main]
async fn main() {
    let mut db = AsyncSecureStore::new();
    let private_vid = OwnedVid::from_file("../examples/test/bob/piv.json").await.unwrap();
    db.add_private_vid(private_vid).unwrap();
    db.verify_vid("did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:alice", None).await.unwrap();

    let sender = "did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:bob";
    let receiver = "did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:alice";

    let result = db.send(sender, receiver, None, b"hello world").await;
}
Source

pub fn make_relationship_request( &self, sender: &str, receiver: &str, route: Option<&[&str]>, ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn send_relationship_request( &self, sender: &str, receiver: &str, route: Option<&[&str]>, ) -> Result<(), Error>

Request a direct relationship with a resolved VID using the TSP Encodes the control message, encrypts, signs, and sends a TSP message

§Arguments
  • sender - A sender VID
  • receiver - A receiver VID
§Example
use tsp_sdk::{AsyncSecureStore, OwnedVid};

#[tokio::main]
async fn main() {
    let mut db = AsyncSecureStore::new();
    let private_vid = OwnedVid::from_file("../examples/test/bob/piv.json").await.unwrap();
    db.add_private_vid(private_vid).unwrap();
    db.verify_vid("did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:alice", None).await.unwrap();

    let sender = "did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:bob";
    let receiver = "did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:alice";

    let result = db.send_relationship_request(sender, receiver, None).await;
}
Source

pub fn make_relationship_accept( &self, sender: &str, receiver: &str, thread_id: Digest, route: Option<&[&str]>, ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn send_relationship_accept( &self, sender: &str, receiver: &str, thread_id: Digest, route: Option<&[&str]>, ) -> Result<(), Error>

Accept a direct relationship between the resolved VIDs identifier by sender and receiver. thread_id must be the same as the one that was present in the relationship request. Encodes the control message, encrypts, signs, and sends a TSP message

Source

pub fn make_relationship_cancel( &self, sender: &str, receiver: &str, ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn send_relationship_cancel( &self, sender: &str, receiver: &str, ) -> Result<(), Error>

Cancels a direct relationship between the resolved sender and receiver VIDs. Encodes the control message, encrypts, signs, and sends a TSP message

Source

pub fn make_new_identifier_notice( &self, sender: &str, receiver: &str, sender_new_vid: &str, ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn send_new_identifier_notice( &self, sender: &str, receiver: &str, sender_new_vid: &str, ) -> Result<(), Error>

Send a new identifier introduction notice

Source

pub fn make_relationship_referral( &self, sender: &str, receiver: &str, referred_vid: &str, ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn send_relationship_referral( &self, sender: &str, receiver: &str, referred_vid: &str, ) -> Result<(), Error>

Send a relationship referral message to receiver

Source

pub fn make_nested_relationship_request( &self, parent_sender: &str, receiver: &str, ) -> Result<((Url, Vec<u8>), OwnedVid), Error>

Source

pub async fn send_nested_relationship_request( &self, parent_sender: &str, receiver: &str, ) -> Result<OwnedVid, Error>

Send a nested relationship request to receiver, creating a new nested vid with outer_sender as a parent.

Source

pub fn make_nested_relationship_accept( &self, parent_sender: &str, nested_receiver: &str, thread_id: Digest, ) -> Result<((Url, Vec<u8>), OwnedVid), Error>

Source

pub async fn send_nested_relationship_accept( &self, parent_sender: &str, nested_receiver: &str, thread_id: Digest, ) -> Result<OwnedVid, Error>

Accept a nested relationship with the (nested) VID identified by nested_receiver. Generate a new nested VID that will have parent_sender as its parent. thread_id must be the same as the one that was present in the relationship request. Encodes the control message, encrypts, signs, and sends a TSP message

Source

pub fn make_next_routed_message( &self, next_hop: &str, path: Vec<impl AsRef<[u8]>>, opaque_message: &[u8], ) -> Result<(Url, Vec<u8>), Error>

Source

pub async fn forward_routed_message( &self, next_hop: &str, path: Vec<impl AsRef<[u8]>>, opaque_message: &[u8], ) -> Result<Url, Error>

Pass along an in-transit routed TSP opaque_message that is not meant for us, given earlier resolved VIDs. The message is routed through the route that has been established with receiver.

Source

pub fn open_message<'a>( &self, message: &'a mut [u8], ) -> Result<ReceivedTspMessage<&'a [u8]>, Error>

Decode an encrypted message, which has to be addressed to one of the VIDs in receivers, and has to have verified_vids as one of the senders.

Source

pub async fn receive( &self, vid: &str, ) -> Result<TSPStream<ReceivedTspMessage, Error>, Error>

Receive TSP messages for the private VID identified by vid, using the appropriate transport mechanism for it. Messages will be queued in a channel The returned channel contains a maximum of 16 messages

Source

pub async fn send_anycast( &self, sender: &str, receivers: impl IntoIterator<Item = impl AsRef<str>>, nonconfidential_message: &[u8], ) -> Result<(), Error>

Send a TSP broadcast message to the specified VIDs

Source

pub async fn verify_and_open( &mut self, vid: &str, payload: BytesMut, ) -> Result<ReceivedTspMessage, Error>

Process the payload from a ‘PendingMessage’ by resolving the unknown vid and retrying This takes a Vec as a payload; for a borrowing version the as_inner() version can be used; usually after unpacking a TSP message, you can’t or need to do anything with it anyway.

Trait Implementations§

Source§

impl Default for AsyncSecureStore

Source§

fn default() -> AsyncSecureStore

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,