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
impl AsyncSecureStore
Sourcepub fn export(&self) -> Result<(Vec<ExportVid>, Aliases), Error>
pub fn export(&self) -> Result<(Vec<ExportVid>, Aliases), Error>
Export the wallet to serializable default types
Sourcepub fn as_store(&self) -> &SecureStore
pub fn as_store(&self) -> &SecureStore
Expose the inner non-async wallet
Sourcepub fn import(
&self,
vids: Vec<ExportVid>,
aliases: Aliases,
) -> Result<(), Error>
pub fn import( &self, vids: Vec<ExportVid>, aliases: Aliases, ) -> Result<(), Error>
Import the wallet from serializable default types
Sourcepub fn set_relation_and_status_for_vid(
&self,
vid: &str,
status: RelationshipStatus,
relation_vid: &str,
) -> Result<(), Error>
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
Sourcepub fn set_route_for_vid(&self, vid: &str, route: &[&str]) -> Result<(), Error>
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
Sourcepub fn set_parent_for_vid(
&self,
vid: &str,
parent: Option<&str>,
) -> Result<(), Error>
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.
Sourcepub fn add_private_vid(
&self,
private_vid: impl PrivateVid + Clone + 'static,
) -> Result<(), Error>
pub fn add_private_vid( &self, private_vid: impl PrivateVid + Clone + 'static, ) -> Result<(), Error>
Adds private_vid
to the wallet
Sourcepub fn forget_vid(&self, vid: &str) -> Result<(), Error>
pub fn forget_vid(&self, vid: &str) -> Result<(), Error>
Remove a VID from the AsyncSecureStore
Sourcepub fn add_verified_vid(
&self,
verified_vid: impl VerifiedVid + 'static,
) -> Result<(), Error>
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
Sourcepub fn has_private_vid(&self, vid: &str) -> Result<bool, Error>
pub fn has_private_vid(&self, vid: &str) -> Result<bool, Error>
Check whether the PrivateVid identified by vid
exists in the wallet
Sourcepub fn has_verified_vid(&self, vid: &str) -> Result<bool, Error>
pub fn has_verified_vid(&self, vid: &str) -> Result<bool, Error>
Check whether the VerifiedVid identified by vid
exists in the wallet
Sourcepub async fn verify_vid(
&mut self,
vid: &str,
alias: Option<String>,
) -> Result<(), Error>
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
Sourcepub fn resolve_alias(&self, alias: &str) -> Result<Option<String>, Error>
pub fn resolve_alias(&self, alias: &str) -> Result<Option<String>, Error>
Resolve alias to its corresponding DID
Sourcepub fn try_resolve_alias(&self, alias: &str) -> Result<String, Error>
pub fn try_resolve_alias(&self, alias: &str) -> Result<String, Error>
Resolve alias to its corresponding DID
pub fn seal_message( &self, sender: &str, receiver: &str, nonconfidential_data: Option<&[u8]>, message: &[u8], ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn send(
&self,
sender: &str,
receiver: &str,
nonconfidential_data: Option<&[u8]>,
message: &[u8],
) -> Result<(), Error>
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 VIDreceiver
- A receiver VIDnonconfidential_data
- Optional extra non-confidential datapayload
- 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;
}
pub fn make_relationship_request( &self, sender: &str, receiver: &str, route: Option<&[&str]>, ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn send_relationship_request(
&self,
sender: &str,
receiver: &str,
route: Option<&[&str]>,
) -> Result<(), Error>
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 VIDreceiver
- 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;
}
pub fn make_relationship_accept( &self, sender: &str, receiver: &str, thread_id: Digest, route: Option<&[&str]>, ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn send_relationship_accept(
&self,
sender: &str,
receiver: &str,
thread_id: Digest,
route: Option<&[&str]>,
) -> Result<(), Error>
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
pub fn make_relationship_cancel( &self, sender: &str, receiver: &str, ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn send_relationship_cancel(
&self,
sender: &str,
receiver: &str,
) -> Result<(), Error>
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
pub fn make_new_identifier_notice( &self, sender: &str, receiver: &str, sender_new_vid: &str, ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn send_new_identifier_notice(
&self,
sender: &str,
receiver: &str,
sender_new_vid: &str,
) -> Result<(), Error>
pub async fn send_new_identifier_notice( &self, sender: &str, receiver: &str, sender_new_vid: &str, ) -> Result<(), Error>
Send a new identifier introduction notice
pub fn make_relationship_referral( &self, sender: &str, receiver: &str, referred_vid: &str, ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn send_relationship_referral(
&self,
sender: &str,
receiver: &str,
referred_vid: &str,
) -> Result<(), Error>
pub async fn send_relationship_referral( &self, sender: &str, receiver: &str, referred_vid: &str, ) -> Result<(), Error>
Send a relationship referral message to receiver
pub fn make_nested_relationship_request( &self, parent_sender: &str, receiver: &str, ) -> Result<((Url, Vec<u8>), OwnedVid), Error>
Sourcepub async fn send_nested_relationship_request(
&self,
parent_sender: &str,
receiver: &str,
) -> Result<OwnedVid, Error>
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.
pub fn make_nested_relationship_accept( &self, parent_sender: &str, nested_receiver: &str, thread_id: Digest, ) -> Result<((Url, Vec<u8>), OwnedVid), Error>
Sourcepub async fn send_nested_relationship_accept(
&self,
parent_sender: &str,
nested_receiver: &str,
thread_id: Digest,
) -> Result<OwnedVid, Error>
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
pub fn make_next_routed_message( &self, next_hop: &str, path: Vec<impl AsRef<[u8]>>, opaque_message: &[u8], ) -> Result<(Url, Vec<u8>), Error>
Sourcepub async fn forward_routed_message(
&self,
next_hop: &str,
path: Vec<impl AsRef<[u8]>>,
opaque_message: &[u8],
) -> Result<Url, Error>
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
.
Sourcepub fn open_message<'a>(
&self,
message: &'a mut [u8],
) -> Result<ReceivedTspMessage<&'a [u8]>, Error>
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.
Sourcepub async fn receive(
&self,
vid: &str,
) -> Result<TSPStream<ReceivedTspMessage, Error>, Error>
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
Sourcepub async fn send_anycast(
&self,
sender: &str,
receivers: impl IntoIterator<Item = impl AsRef<str>>,
nonconfidential_message: &[u8],
) -> Result<(), Error>
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
Sourcepub async fn verify_and_open(
&mut self,
vid: &str,
payload: BytesMut,
) -> Result<ReceivedTspMessage, Error>
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
impl Default for AsyncSecureStore
Source§fn default() -> AsyncSecureStore
fn default() -> AsyncSecureStore
Auto Trait Implementations§
impl Freeze for AsyncSecureStore
impl RefUnwindSafe for AsyncSecureStore
impl Send for AsyncSecureStore
impl Sync for AsyncSecureStore
impl Unpin for AsyncSecureStore
impl UnwindSafe for AsyncSecureStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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