Skip to content

Commit

Permalink
feat: add new Wallet trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Prazak committed Nov 30, 2023
1 parent 37019db commit 542eac0
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aries/aries_vcx/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ pub enum AriesVcxErrorKind {
#[error("Could not parse a value")]
ParsingError,

#[error("Unexpected wallet error")]
WalletUnexpected,

// A2A
#[error("Invalid HTTP response.")]
InvalidHttpResponse,
Expand Down
2 changes: 2 additions & 0 deletions aries/aries_vcx/src/errors/mapping_others.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl From<AriesVcxCoreError> for AriesVcxError {
AriesVcxErrorKind::DuplicationMasterSecret
}
AriesVcxCoreErrorKind::DuplicationDid => AriesVcxErrorKind::DuplicationDid,
AriesVcxCoreErrorKind::WalletUnexpected => AriesVcxErrorKind::WalletUnexpected,
AriesVcxCoreErrorKind::LoggingError => AriesVcxErrorKind::LoggingError,
AriesVcxCoreErrorKind::EncodeError => AriesVcxErrorKind::EncodeError,
AriesVcxCoreErrorKind::UnknownError => AriesVcxErrorKind::UnknownError,
Expand Down Expand Up @@ -247,6 +248,7 @@ impl From<AriesVcxError> for AriesVcxCoreError {
AriesVcxErrorKind::DuplicationMasterSecret => {
AriesVcxCoreErrorKind::DuplicationMasterSecret
}
AriesVcxErrorKind::WalletUnexpected => AriesVcxCoreErrorKind::WalletUnexpected,
AriesVcxErrorKind::DuplicationDid => AriesVcxCoreErrorKind::DuplicationDid,
AriesVcxErrorKind::LoggingError => AriesVcxCoreErrorKind::LoggingError,
AriesVcxErrorKind::EncodeError => AriesVcxCoreErrorKind::EncodeError,
Expand Down
3 changes: 3 additions & 0 deletions aries/aries_vcx_core/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub enum AriesVcxCoreErrorKind {
#[error("Attempted to add a DID to wallet when that DID already exists in wallet")]
DuplicationDid,

#[error("Unexpected wallet error")]
WalletUnexpected,

// Logger
#[error("Logging Error")]
LoggingError,
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod global;
pub mod ledger;
pub mod utils;
pub mod wallet;
pub mod wallet2;

pub use indy_ledger_response_parser::ResponseParser;
pub use indy_vdr::config::PoolConfig;
Expand Down
72 changes: 72 additions & 0 deletions aries/aries_vcx_core/src/wallet2/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use async_trait::async_trait;

use crate::errors::error::VcxCoreResult;

pub enum SigType {
EdDSA,
ES256,
ES256K,
ES384,
}

impl From<SigType> for &str {
fn from(value: SigType) -> Self {
match value {
SigType::EdDSA => "eddsa",
SigType::ES256 => "es256",
SigType::ES256K => "es256k",
SigType::ES384 => "es384",
}
}
}

#[async_trait]
pub trait Wallet: RecordWallet + DidWallet {}

#[async_trait]
pub trait DidWallet {
type DidAttrs;
type CreatedDid;
type DidKey;
type KeyAttrs;
type FindDidKeyAttrs;

async fn create_key(&self, key_attrs: Self::KeyAttrs) -> VcxCoreResult<()>;

async fn create_did(&self, attrs: Self::DidAttrs) -> VcxCoreResult<Self::CreatedDid>;

async fn did_key(&self, attrs: Self::FindDidKeyAttrs) -> VcxCoreResult<Self::DidKey>;

async fn replace_did_key(&self, did: &str, new_key_name: &str) -> VcxCoreResult<Self::DidKey>;

async fn sign(&self, verkey: &str, msg: &[u8], sig_type: SigType) -> VcxCoreResult<Vec<u8>>;

async fn verify(
&self,
verkey: &str,
msg: &[u8],
signature: &[u8],
sig_type: SigType,
) -> VcxCoreResult<bool>;
}

#[async_trait]
pub trait RecordWallet {
type Record;
type RecordId;
type FoundRecord;
type SearchFilter;

async fn add_record(&self, record: Self::Record) -> VcxCoreResult<()>;

async fn get_record(&self, id: &Self::RecordId) -> VcxCoreResult<Self::FoundRecord>;

async fn update_record(&self, update: Self::Record) -> VcxCoreResult<()>;

async fn delete_record(&self, id: &Self::RecordId) -> VcxCoreResult<()>;

async fn search_record(
&self,
filter: Self::SearchFilter,
) -> VcxCoreResult<Vec<Self::FoundRecord>>;
}
3 changes: 3 additions & 0 deletions aries/misc/legacy/libvcx_core/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ pub enum LibvcxErrorKind {
#[error("Attempted to add a DID to wallet when that DID already exists in wallet")]
DuplicationDid,

#[error("Unexpected wallet error")]
WalletUnexpected,

// Logger
#[error("Logging Error")]
LoggingError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl From<AriesVcxErrorKind> for LibvcxErrorKind {
AriesVcxErrorKind::WalletAlreadyOpen => LibvcxErrorKind::WalletAlreadyOpen,
AriesVcxErrorKind::DuplicationMasterSecret => LibvcxErrorKind::DuplicationMasterSecret,
AriesVcxErrorKind::DuplicationDid => LibvcxErrorKind::DuplicationDid,
AriesVcxErrorKind::WalletUnexpected => LibvcxErrorKind::WalletUnexpected,
AriesVcxErrorKind::LoggingError => LibvcxErrorKind::LoggingError,
AriesVcxErrorKind::EncodeError => LibvcxErrorKind::EncodeError,
AriesVcxErrorKind::UnknownError => LibvcxErrorKind::UnknownError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl From<AriesVcxCoreErrorKind> for LibvcxErrorKind {
LibvcxErrorKind::DuplicationMasterSecret
}
AriesVcxCoreErrorKind::DuplicationDid => LibvcxErrorKind::DuplicationDid,
AriesVcxCoreErrorKind::WalletUnexpected => LibvcxErrorKind::WalletUnexpected,
AriesVcxCoreErrorKind::LoggingError => LibvcxErrorKind::LoggingError,
AriesVcxCoreErrorKind::EncodeError => LibvcxErrorKind::EncodeError,
AriesVcxCoreErrorKind::UnknownError => LibvcxErrorKind::UnknownError,
Expand Down

0 comments on commit 542eac0

Please sign in to comment.