miden_client/keystore/
mod.rs1use alloc::boxed::Box;
2use alloc::collections::BTreeSet;
3use alloc::string::String;
4use alloc::vec::Vec;
5
6use miden_protocol::account::AccountId;
7use miden_protocol::account::auth::{AuthSecretKey, PublicKeyCommitment};
8use miden_tx::auth::TransactionAuthenticator;
9use thiserror::Error;
10
11#[derive(Debug, Error)]
12pub enum KeyStoreError {
13 #[error("storage error: {0}")]
14 StorageError(String),
15 #[error("decoding error: {0}")]
16 DecodingError(String),
17}
18
19#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
24#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
25pub trait Keystore: TransactionAuthenticator {
26 async fn add_key(
30 &self,
31 key: &AuthSecretKey,
32 account_id: AccountId,
33 ) -> Result<(), KeyStoreError>;
34
35 async fn remove_key(&self, pub_key: PublicKeyCommitment) -> Result<(), KeyStoreError>;
39
40 async fn get_key(
44 &self,
45 pub_key: PublicKeyCommitment,
46 ) -> Result<Option<AuthSecretKey>, KeyStoreError>;
47
48 async fn get_account_key_commitments(
53 &self,
54 account_id: &AccountId,
55 ) -> Result<BTreeSet<PublicKeyCommitment>, KeyStoreError>;
56
57 async fn get_account_id_by_key_commitment(
61 &self,
62 pub_key_commitment: PublicKeyCommitment,
63 ) -> Result<Option<AccountId>, KeyStoreError>;
64
65 async fn get_keys_for_account(
73 &self,
74 account_id: &AccountId,
75 ) -> Result<Vec<AuthSecretKey>, KeyStoreError> {
76 let commitments = self.get_account_key_commitments(account_id).await?;
77 let mut keys = Vec::with_capacity(commitments.len());
78 for commitment in commitments {
79 if let Some(key) = self.get_key(commitment).await? {
80 keys.push(key);
81 }
82 }
83 Ok(keys)
84 }
85}
86
87#[cfg(feature = "std")]
88mod fs_keystore;
89#[cfg(feature = "std")]
90pub use fs_keystore::{FilesystemKeyStore, StoredKeyInfo};