pub trait Storage: StorageSendSyncMaybe + Debug {
Show 17 methods
// Required methods
fn did_create<'life0, 'life1, 'async_trait>(
&'life0 self,
network: NetworkName,
fragment: &'life1 str,
private_key: Option<PrivateKey>,
) -> Pin<Box<dyn Future<Output = Result<(IotaDID, KeyLocation)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn did_purge<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn did_exists<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn did_list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<IotaDID>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn key_generate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
key_type: KeyType,
fragment: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<KeyLocation>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn key_insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
private_key: PrivateKey,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn key_public<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<PublicKey>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn key_delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn key_sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Signature>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn key_exists<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn data_encrypt<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
plaintext: Vec<u8>,
associated_data: Vec<u8>,
encryption_algorithm: &'life2 EncryptionAlgorithm,
cek_algorithm: &'life3 CekAlgorithm,
public_key: PublicKey,
) -> Pin<Box<dyn Future<Output = Result<EncryptedData>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn data_decrypt<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
data: EncryptedData,
encryption_algorithm: &'life2 EncryptionAlgorithm,
cek_algorithm: &'life3 CekAlgorithm,
private_key: &'life4 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
fn chain_state_get<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<Option<ChainState>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn chain_state_set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
chain_state: &'life2 ChainState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn document_get<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<Option<IotaDocument>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn document_set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
state: &'life2 IotaDocument,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn flush_changes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
An interface for Account storage implementations.
The Storage
interface is used for secure key operations, such as key generation and signing,
as well as key-value like storage of data structures, such as DID documents.
§Identifiers
Implementations of this interface are expected to uniquely identify keys through the
combination of DID and KeyLocation
.
An implementation recommendation is to use the DID as a partition key. Everything related to a DID
can be stored in a partition identified by that DID. Keys belonging to a DID can then be identified
by KeyLocation
s in that partition.
§DID List
The storage is expected to maintain a list of stored DIDs. DIDs created with did_create
should be
inserted into the list, and removed when calling did_purge
.
Other operations on the list are did_exists
and did_list
.
§Thread-Safety
Note: This only applies if the send-sync-storage
feature is enabled.
Since the DID list is a global data structure per storage instance, modifications to that list
need to be carefully synchronized.
Other operations can be executed concurrently and don’t need to be synchronized globally,
as it is a user error to create more than one Account
for the same identity.
Regardless of that, a storage implementation still needs to be thread-safe as defined by
the Send
and Sync
traits.
§Implementation example
See MemStore
for a test/example implementation.
Required Methods§
Sourcefn did_create<'life0, 'life1, 'async_trait>(
&'life0 self,
network: NetworkName,
fragment: &'life1 str,
private_key: Option<PrivateKey>,
) -> Pin<Box<dyn Future<Output = Result<(IotaDID, KeyLocation)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn did_create<'life0, 'life1, 'async_trait>(
&'life0 self,
network: NetworkName,
fragment: &'life1 str,
private_key: Option<PrivateKey>,
) -> Pin<Box<dyn Future<Output = Result<(IotaDID, KeyLocation)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Creates a new identity for the given network
.
- Uses the given Ed25519
private_key
or generates a new key if it’sNone
. - Returns an error if the DID already exists.
- Adds the newly created DID to a list which can be accessed via
Storage::did_list
.
Returns the generated DID and the location at which the key was stored.
Sourcefn did_purge<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn did_purge<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Removes the keys and any other state for the given did
.
This operation is idempotent: it does not fail if the given did
does not (or no longer) exist.
Returns true
if the did and its associated data was removed, false
if nothing was done.
Sourcefn did_exists<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn did_exists<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Returns true
if did
exists in the list of stored DIDs.
Sourcefn did_list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<IotaDID>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn did_list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<IotaDID>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns the list of stored DIDs.
Sourcefn key_generate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
key_type: KeyType,
fragment: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<KeyLocation>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn key_generate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
key_type: KeyType,
fragment: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<KeyLocation>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Generates a new key for the given did
with the given key_type
and fragment
identifier
and returns the location of the newly generated key.
Sourcefn key_insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
private_key: PrivateKey,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn key_insert<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
private_key: PrivateKey,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Inserts a private key at the specified location
.
If a key at location
exists, it is overwritten.
Sourcefn key_public<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<PublicKey>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn key_public<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<PublicKey>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Retrieves the public key from location
.
Sourcefn key_delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn key_delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Deletes the key at location
.
This operation is idempotent: it does not fail if the key does not exist.
Returns true
if it removed the key, false
if nothing was done.
Sourcefn key_sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Signature>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn key_sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
data: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<Signature>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Signs data
with the private key at the specified location
.
Sourcefn key_exists<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn key_exists<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
location: &'life2 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Returns true
if a key exists at the specified location
.
Sourcefn data_encrypt<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
plaintext: Vec<u8>,
associated_data: Vec<u8>,
encryption_algorithm: &'life2 EncryptionAlgorithm,
cek_algorithm: &'life3 CekAlgorithm,
public_key: PublicKey,
) -> Pin<Box<dyn Future<Output = Result<EncryptedData>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn data_encrypt<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
plaintext: Vec<u8>,
associated_data: Vec<u8>,
encryption_algorithm: &'life2 EncryptionAlgorithm,
cek_algorithm: &'life3 CekAlgorithm,
public_key: PublicKey,
) -> Pin<Box<dyn Future<Output = Result<EncryptedData>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Encrypts the given plaintext
with the specified encryption_algorithm
and cek_algorithm
.
Returns an EncryptedData
instance.
Sourcefn data_decrypt<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
data: EncryptedData,
encryption_algorithm: &'life2 EncryptionAlgorithm,
cek_algorithm: &'life3 CekAlgorithm,
private_key: &'life4 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn data_decrypt<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
data: EncryptedData,
encryption_algorithm: &'life2 EncryptionAlgorithm,
cek_algorithm: &'life3 CekAlgorithm,
private_key: &'life4 KeyLocation,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Decrypts the given data
with the specified encryption_algorithm
and cek_algorithm
.
Returns the decrypted text.
Sourcefn chain_state_get<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<Option<ChainState>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chain_state_get<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<Option<ChainState>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Returns the chain state of the identity specified by did
.
Sourcefn chain_state_set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
chain_state: &'life2 ChainState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn chain_state_set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
chain_state: &'life2 ChainState,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Set the chain state of the identity specified by did
.
Sourcefn document_get<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<Option<IotaDocument>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn document_get<'life0, 'life1, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
) -> Pin<Box<dyn Future<Output = Result<Option<IotaDocument>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Returns the IotaDocument
of the identity specified by did
.
Sourcefn document_set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
state: &'life2 IotaDocument,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn document_set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
did: &'life1 IotaDID,
state: &'life2 IotaDocument,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sets a new state for the identity specified by did
.