mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Export app-crypto specific keystore functions (#7489)
* Export app-crypto specific keystore functions * Also add back the insert function * Switch KeystoreContainer to an enum * Only export the bare minimal for LocalKeystore and fix service compile * fix: should return Arc * Add docs stating that functions only available in local keystore * Remove insert and generate functions * fix: generate function should be available in test * Add keypair function to trait * Revert "Add keypair function to trait" This reverts commit ad921b09ca73d3c09298e3a51b562ef8e0067781. * Add note for local_keystore function in service
This commit is contained in:
@@ -205,12 +205,13 @@ pub type TLightClientWithBackend<TBl, TRtApi, TExecDisp, TBackend> = Client<
|
||||
TRtApi,
|
||||
>;
|
||||
|
||||
/// Construct and hold different layers of Keystore wrappers
|
||||
pub struct KeystoreContainer {
|
||||
keystore: Arc<dyn CryptoStore>,
|
||||
sync_keystore: SyncCryptoStorePtr,
|
||||
enum KeystoreContainerInner {
|
||||
Local(Arc<LocalKeystore>)
|
||||
}
|
||||
|
||||
/// Construct and hold different layers of Keystore wrappers
|
||||
pub struct KeystoreContainer(KeystoreContainerInner);
|
||||
|
||||
impl KeystoreContainer {
|
||||
/// Construct KeystoreContainer
|
||||
pub fn new(config: &KeystoreConfig) -> Result<Self, Error> {
|
||||
@@ -221,22 +222,36 @@ impl KeystoreContainer {
|
||||
)?,
|
||||
KeystoreConfig::InMemory => LocalKeystore::in_memory(),
|
||||
});
|
||||
let sync_keystore = keystore.clone() as SyncCryptoStorePtr;
|
||||
|
||||
Ok(Self {
|
||||
keystore,
|
||||
sync_keystore,
|
||||
})
|
||||
Ok(Self(KeystoreContainerInner::Local(keystore)))
|
||||
}
|
||||
|
||||
/// Returns an adapter to the asynchronous keystore that implements `CryptoStore`
|
||||
pub fn keystore(&self) -> Arc<dyn CryptoStore> {
|
||||
self.keystore.clone()
|
||||
match self.0 {
|
||||
KeystoreContainerInner::Local(ref keystore) => keystore.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the synchrnous keystore wrapper
|
||||
pub fn sync_keystore(&self) -> SyncCryptoStorePtr {
|
||||
self.sync_keystore.clone()
|
||||
match self.0 {
|
||||
KeystoreContainerInner::Local(ref keystore) => keystore.clone() as SyncCryptoStorePtr,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the local keystore if available
|
||||
///
|
||||
/// The function will return None if the available keystore is not a local keystore.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// Using the [`LocalKeystore`] will result in loosing the ability to use any other keystore implementation, like
|
||||
/// a remote keystore for example. Only use this if you a certain that you require it!
|
||||
pub fn local_keystore(&self) -> Option<Arc<LocalKeystore>> {
|
||||
match self.0 {
|
||||
KeystoreContainerInner::Local(ref keystore) => Some(keystore.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user