pub trait Storage: StorageSendSyncMaybe + Debug {
Show 17 methods fn did_create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network: NetworkName,
        fragment: &'life1 str,
        private_key: Option<Key<Private>>
    ) -> Pin<Box<dyn Future<Output = Result<(IotaDID, KeyLocation), Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn did_purge<'life0, 'life1, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn did_exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn did_list<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<Vec<IotaDID, Global>, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        Self: '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, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn key_insert<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID,
        location: &'life2 KeyLocation,
        private_key: Key<Private>
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn key_public<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID,
        location: &'life2 KeyLocation
    ) -> Pin<Box<dyn Future<Output = Result<Key<Public>, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: '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, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn key_sign<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID,
        location: &'life2 KeyLocation,
        data: Vec<u8, Global>
    ) -> Pin<Box<dyn Future<Output = Result<Signature, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: '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, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn data_encrypt<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID,
        plaintext: Vec<u8, Global>,
        associated_data: Vec<u8, Global>,
        encryption_algorithm: &'life2 EncryptionAlgorithm,
        cek_algorithm: &'life3 CekAlgorithm,
        public_key: Key<Public>
    ) -> Pin<Box<dyn Future<Output = Result<EncryptedData, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        Self: '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, Global>, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        'life4: 'async_trait,
        Self: 'async_trait
; fn chain_state_get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID
    ) -> Pin<Box<dyn Future<Output = Result<Option<ChainState>, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: '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<(), Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn document_get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID
    ) -> Pin<Box<dyn Future<Output = Result<Option<IotaDocument>, Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn document_set<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        did: &'life1 IotaDID,
        state: &'life2 IotaDocument
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
; fn flush_changes<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
;
}
Available on crate feature account only.
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 KeyLocations 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

Creates a new identity for the given network.

  • Uses the given Ed25519 private_key or generates a new key if it’s None.
  • 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.

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.

Returns true if did exists in the list of stored DIDs.

Returns the list of stored DIDs.

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.

Inserts a private key at the specified location.

If a key at location exists, it is overwritten.

Retrieves the public key from location.

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.

Signs data with the private key at the specified location.

Returns true if a key exists at the specified location.

Encrypts the given plaintext with the specified encryption_algorithm and cek_algorithm.

Returns an EncryptedData instance.

Decrypts the given data with the specified encryption_algorithm and cek_algorithm.

Returns the decrypted text.

Returns the chain state of the identity specified by did.

Set the chain state of the identity specified by did.

Returns the IotaDocument of the identity specified by did.

Sets a new state for the identity specified by did.

Persists any unsaved changes.

Implementors