-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unified interface for creating wallet
Signed-off-by: Ondrej Prazak <[email protected]>
- Loading branch information
Ondrej Prazak
committed
Feb 28, 2024
1 parent
ea4a137
commit a9a1d5a
Showing
18 changed files
with
285 additions
and
178 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
aries/aries_vcx_core/src/wallet/askar/askar_wallet_config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
use serde::Deserialize; | ||
|
||
use super::{key_method::KeyMethod, AskarWallet}; | ||
use crate::{ | ||
errors::error::VcxCoreResult, | ||
wallet::base_wallet::{BaseWallet, ManageWallet}, | ||
}; | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
pub struct AskarWalletConfig { | ||
db_url: String, | ||
key_method: KeyMethod, | ||
pass_key: String, | ||
profile: String, | ||
} | ||
|
||
impl AskarWalletConfig { | ||
pub fn new(db_url: &str, key_method: KeyMethod, pass_key: &str, profile: &str) -> Self { | ||
Self { | ||
db_url: db_url.into(), | ||
key_method: key_method.into(), | ||
pass_key: pass_key.into(), | ||
profile: profile.into(), | ||
} | ||
} | ||
|
||
pub fn db_url(&self) -> &str { | ||
&self.db_url | ||
} | ||
|
||
pub fn key_method(&self) -> &KeyMethod { | ||
&self.key_method | ||
} | ||
|
||
pub fn pass_key(&self) -> &str { | ||
&self.pass_key | ||
} | ||
|
||
pub fn profile(&self) -> &str { | ||
&self.profile | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ManageWallet for AskarWalletConfig { | ||
async fn create_wallet(&self) -> VcxCoreResult<Arc<dyn BaseWallet>> { | ||
let askar_wallet = AskarWallet::create(&self, false).await?; | ||
Ok(Arc::new(askar_wallet)) | ||
} | ||
|
||
async fn open_wallet(&self) -> VcxCoreResult<Arc<dyn BaseWallet>> { | ||
Ok(Arc::new(AskarWallet::open(&self).await?)) | ||
} | ||
|
||
async fn delete_wallet(&self) -> VcxCoreResult<()> { | ||
todo!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use aries_askar::{ | ||
storage::{Argon2Level, KdfMethod}, | ||
StoreKeyMethod, | ||
}; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Copy, Clone, Deserialize)] | ||
pub enum KeyMethod { | ||
DeriveKey(AskarKdfMethod), | ||
RawKey, | ||
Unprotected, | ||
} | ||
|
||
impl From<KeyMethod> for StoreKeyMethod { | ||
fn from(value: KeyMethod) -> Self { | ||
match value { | ||
KeyMethod::DeriveKey(payload) => StoreKeyMethod::DeriveKey(payload.into()), | ||
KeyMethod::RawKey => StoreKeyMethod::RawKey, | ||
KeyMethod::Unprotected => StoreKeyMethod::Unprotected, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Deserialize)] | ||
pub enum AskarKdfMethod { | ||
Argon2i(ArgonLevel), | ||
} | ||
|
||
impl From<AskarKdfMethod> for KdfMethod { | ||
fn from(value: AskarKdfMethod) -> Self { | ||
match value { | ||
AskarKdfMethod::Argon2i(payload) => KdfMethod::Argon2i(payload.into()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Deserialize)] | ||
pub enum ArgonLevel { | ||
Interactive, | ||
Moderate, | ||
} | ||
|
||
impl From<ArgonLevel> for Argon2Level { | ||
fn from(value: ArgonLevel) -> Self { | ||
match value { | ||
ArgonLevel::Interactive => Argon2Level::Interactive, | ||
ArgonLevel::Moderate => Argon2Level::Moderate, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.