Expand description
§Trust Spanning Protocol
The Trust Spanning Protocol (TSP) is a protocol for secure communication between entities identified by their Verified Identities (VIDs).
The primary API this crates exposes is the AsyncSecureStore struct, which is used to manage and resolve VIDs, as well as send and receive messages between them.
§Core protocol
By default this library comes with methods to send and receive messages over various transport and code to resolve and verify various VIDs.
If your use-case only requires the core protocol, you can disable the
async
feature to remove the transport layer and resolve methods.
The AsyncSecureStore uses the tokio async runtime and offers a high level API.
The SecureStore struct implements managing VIDs and sealing / opening TSP messages (low level API), it does not require an async runtime.
§Example
The following example demonstrates how to send a message from Alice to Bob
use futures::StreamExt;
use tsp_sdk::{AsyncSecureStore, Error, OwnedVid, ReceivedTspMessage};
#[tokio::main]
async fn main() -> Result<(), Error> {
// bob wallet
let mut bob_db = AsyncSecureStore::new();
let bob_vid = OwnedVid::from_file("../examples/test/bob/piv.json").await?;
bob_db.add_private_vid(bob_vid)?;
bob_db.verify_vid("did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:alice", Some("alice".into())).await?;
let mut bobs_messages = bob_db.receive("did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:bob").await?;
// alice wallet
let mut alice_db = AsyncSecureStore::new();
let alice_vid = OwnedVid::from_file("../examples/test/alice/piv.json").await?;
alice_db.add_private_vid(alice_vid)?;
alice_db.verify_vid("did:web:raw.githubusercontent.com:openwallet-foundation-labs:tsp:main:examples:test:bob", Some("bob".into())).await?;
// send a message
alice_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?;
// first, receive a Relationship request as this is the first contact
let Some(Ok(ReceivedTspMessage::RequestRelationship { .. }))=
bobs_messages.next().await else {
panic!("bob did not receive a relationship request message")
};
// receive a generic message
let Some(Ok(ReceivedTspMessage::GenericMessage { message, .. }))=
bobs_messages.next().await else {
panic!("bob did not receive a generic message")
};
assert_eq!(message.iter().as_slice(), b"hello world");
Ok(())
}
Re-exports§
pub use definitions::Payload;
pub use definitions::PrivateVid;
pub use definitions::ReceivedTspMessage;
pub use definitions::RelationshipStatus;
pub use definitions::VerifiedVid;
pub use vid::ExportVid;
pub use vid::OwnedVid;
pub use vid::Vid;
Modules§
- cesr
- Provides minimalist CESR encoding/decoding support that is sufficient for generating and parsing TSP messages; to keep complexity to a minimum, we explicitly do not provide a full CESR decoder/encoder.
- crypto
- Contains the cryptographic core of the TSP protocol
- definitions
- Defines several common data structures, traits and error types that are used throughout the project.
- transport
- Code (built using tokio foundations) for actually sending and receiving data over a transport layer.
- vid
- Contains code for handling verified identifiers and identities.
Currently only an extended form of
did:web
anddid:peer
are supported.
Structs§
- Askar
Secure Storage - An implementation of secure storage using Aries Askar
- Async
Secure Store - Holds private and verified VIDs
- Secure
Store - Holds private and verified VIDs
Enums§
- Error
- Error originating from the TSP library