diff --git a/Cargo.lock b/Cargo.lock index f767eb2430..621a658e1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -575,9 +575,9 @@ dependencies = [ "anyhow", "aries-askar", "async-trait", + "base64", "bs58 0.5.0", "indy-api-types", - "indy-vdr", "libvdrtools", "log", "public_key", diff --git a/aries/aries_vcx/Cargo.toml b/aries/aries_vcx/Cargo.toml index a09281843b..fbfdb17132 100644 --- a/aries/aries_vcx/Cargo.toml +++ b/aries/aries_vcx/Cargo.toml @@ -50,7 +50,6 @@ did_doc = { path = "../../did_core/did_doc" } did_key = { path = "../../did_core/did_methods/did_key" } public_key = { path = "../../did_core/public_key" } did_peer = { path = "../../did_core/did_methods/did_peer" } -did_resolver_sov = { path = "../../did_core/did_methods/did_resolver_sov" } did_resolver_registry = { path = "../../did_core/did_resolver_registry" } bs58 = "0.5.0" async-trait = "0.1.53" @@ -83,3 +82,4 @@ wallet_migrator = { path = "../misc/wallet_migrator" } async-channel = "1.7.1" tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] } pretty_assertions = "1.4.0" +did_resolver_sov = { path = "../../did_core/did_methods/did_resolver_sov" } diff --git a/aries/aries_vcx/src/errors/mapping_wallet.rs b/aries/aries_vcx/src/errors/mapping_wallet.rs index 35e1cad568..d483caa77b 100644 --- a/aries/aries_vcx/src/errors/mapping_wallet.rs +++ b/aries/aries_vcx/src/errors/mapping_wallet.rs @@ -15,9 +15,6 @@ impl From for AriesVcxError { VcxWalletError::UnknownRecordCategory(_) => { Self::from_msg(AriesVcxErrorKind::InvalidInput, value.to_string()) } - VcxWalletError::IndyApiError(_) => { - Self::from_msg(AriesVcxErrorKind::InvalidLedgerResponse, value.to_string()) - } VcxWalletError::InvalidInput(_) => { Self::from_msg(AriesVcxErrorKind::InvalidInput, value.to_string()) } @@ -48,6 +45,20 @@ impl From for AriesVcxError { VcxWalletError::NotBase64(_) => { Self::from_msg(AriesVcxErrorKind::ParsingError, value.to_string()) } + // imperfect solution: + // ideally we want this to be conditionally compiled if the + // aries_vcx_wallet/vdrtools_wallet feature is enabled, rather than the + // aries_vcx/vdrtools_wallet feature. however that is not possible currently + // with cargo. as such, if we have a case where + // aries_vcx_wallet/vdrtool_wallet is enabled, but aries_vcx/vdrtools_wallet + // is not, then the error will fall thru to the catch all case `_ =>` + #[cfg(feature = "vdrtools_wallet")] + VcxWalletError::IndyApiError(_) => { + Self::from_msg(AriesVcxErrorKind::InvalidLedgerResponse, value.to_string()) + } + // can be + #[allow(unreachable_patterns)] + _ => Self::from_msg(AriesVcxErrorKind::UnknownError, value.to_string()), } } } diff --git a/aries/aries_vcx_anoncreds/Cargo.toml b/aries/aries_vcx_anoncreds/Cargo.toml index 3ecb0caa31..231d240a6a 100644 --- a/aries/aries_vcx_anoncreds/Cargo.toml +++ b/aries/aries_vcx_anoncreds/Cargo.toml @@ -8,17 +8,14 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default =["credx", "vdrtools_wallet"] credx = ["dep:indy-credx"] anoncreds = ["dep:anoncreds"] legacy_proof = [] -vdrtools_wallet = ["aries_vcx_wallet/vdrtools_wallet"] -askar_wallet = ["aries_vcx_wallet/askar_wallet"] [dependencies] indy-credx = { git = "https://github.com/hyperledger/indy-shared-rs", tag = "v1.1.0", optional = true } -aries_vcx_wallet = { path = "../aries_vcx_wallet" } anoncreds = { git = "https://github.com/hyperledger/anoncreds-rs.git", tag = "v0.2.0", optional = true } +aries_vcx_wallet = { path = "../aries_vcx_wallet" } anoncreds_types = { path = "../misc/anoncreds_types" } did_parser_nom = { path = "../../did_core/did_parser_nom" } async-trait = "0.1.68" diff --git a/aries/aries_vcx_wallet/Cargo.toml b/aries/aries_vcx_wallet/Cargo.toml index d1e742d27b..afc1c8e056 100644 --- a/aries/aries_vcx_wallet/Cargo.toml +++ b/aries/aries_vcx_wallet/Cargo.toml @@ -16,10 +16,10 @@ anyhow = "1.0" aries-askar = { version = "=0.3.0", optional = true } async-trait = "0.1.68" bs58 = { version = "0.5" } +base64 = "0.21" libvdrtools = { path = "../misc/legacy/libvdrtools", optional = true } log = "0.4.17" indy-api-types = { path = "../misc/legacy/libvdrtools/indy-api-types", optional = true } -indy-vdr = { git = "https://github.com/hyperledger/indy-vdr.git", rev = "c143268", default-features = false, features = ["log"] } serde = { version = "1.0.159", features = ["derive"] } serde_json = "1.0.95" public_key = { path = "../../did_core/public_key"} diff --git a/aries/aries_vcx_wallet/src/errors/error.rs b/aries/aries_vcx_wallet/src/errors/error.rs index 9b74e27afc..a9a4cf5563 100644 --- a/aries/aries_vcx_wallet/src/errors/error.rs +++ b/aries/aries_vcx_wallet/src/errors/error.rs @@ -3,7 +3,6 @@ use std::{ string::FromUtf8Error, }; -use indy_vdr::utils::ConversionError; use thiserror::Error as ThisError; #[cfg(feature = "vdrtools_wallet")] use vdrtools::IndyError; @@ -51,7 +50,7 @@ pub enum VcxWalletError { DuplicateRecord(String), NotUtf8(FromUtf8Error), NotBase58(bs58::decode::Error), - NotBase64(ConversionError), + NotBase64(base64::DecodeError), RecordNotFound(NotFoundInfo), UnknownRecordCategory(String), #[cfg(feature = "vdrtools_wallet")] diff --git a/aries/aries_vcx_wallet/src/errors/mapping_others.rs b/aries/aries_vcx_wallet/src/errors/mapping_others.rs index 43728c1792..0167404d19 100644 --- a/aries/aries_vcx_wallet/src/errors/mapping_others.rs +++ b/aries/aries_vcx_wallet/src/errors/mapping_others.rs @@ -1,7 +1,5 @@ use std::string::FromUtf8Error; -use indy_vdr::utils::ConversionError; - use super::error::VcxWalletError; impl From for VcxWalletError { @@ -10,8 +8,8 @@ impl From for VcxWalletError { } } -impl From for VcxWalletError { - fn from(value: ConversionError) -> Self { +impl From for VcxWalletError { + fn from(value: base64::DecodeError) -> Self { Self::NotBase64(value) } } diff --git a/aries/aries_vcx_wallet/src/wallet/base_wallet/base64_string.rs b/aries/aries_vcx_wallet/src/wallet/base_wallet/base64_string.rs index a3d69f37c3..70e2d11fe6 100644 --- a/aries/aries_vcx_wallet/src/wallet/base_wallet/base64_string.rs +++ b/aries/aries_vcx_wallet/src/wallet/base_wallet/base64_string.rs @@ -1,19 +1,33 @@ -use indy_vdr::utils::base64::{decode_urlsafe, encode_urlsafe}; +use base64::{ + alphabet, + engine::{DecodePaddingMode, GeneralPurpose, GeneralPurposeConfig}, + Engine, +}; use serde::{Deserialize, Serialize}; use crate::{errors::error::VcxWalletResult, wallet::utils::bytes_to_string}; +/// A default [GeneralPurposeConfig] configuration with a [decode_padding_mode] of +/// [DecodePaddingMode::Indifferent] +const LENIENT_PAD: GeneralPurposeConfig = GeneralPurposeConfig::new() + .with_encode_padding(false) + .with_decode_padding_mode(DecodePaddingMode::Indifferent); + +/// A [GeneralPurpose] engine using the [alphabet::URL_SAFE] base64 alphabet and +/// [DecodePaddingMode::Indifferent] config to decode both padded and unpadded. +const URL_SAFE_LENIENT: GeneralPurpose = GeneralPurpose::new(&alphabet::URL_SAFE, LENIENT_PAD); + #[derive(Serialize, Deserialize, Debug)] #[serde(transparent)] pub struct Base64String(String); impl Base64String { pub fn from_bytes(content: &[u8]) -> Self { - Self(encode_urlsafe(content)) + Self(URL_SAFE_LENIENT.encode(content)) } pub fn decode(&self) -> VcxWalletResult> { - Ok(decode_urlsafe(&self.0)?) + Ok(URL_SAFE_LENIENT.decode(&self.0)?) } pub fn decode_to_string(&self) -> VcxWalletResult { diff --git a/aries/misc/legacy/libvdrtools/indy-utils/Cargo.toml b/aries/misc/legacy/libvdrtools/indy-utils/Cargo.toml index d022fca29d..a502e61f0e 100644 --- a/aries/misc/legacy/libvdrtools/indy-utils/Cargo.toml +++ b/aries/misc/legacy/libvdrtools/indy-utils/Cargo.toml @@ -19,7 +19,7 @@ hash_openssl = [] randombytes_sodium = [] [dependencies] -base64 = {version = "0.21"} +base64 = {version = "0.21.2"} dirs = "5" failure = "0.1" indy-api-types = { path = "../indy-api-types" } diff --git a/did_core/did_methods/did_resolver_sov/Cargo.toml b/did_core/did_methods/did_resolver_sov/Cargo.toml index 6bdcf143ab..59af563001 100644 --- a/did_core/did_methods/did_resolver_sov/Cargo.toml +++ b/did_core/did_methods/did_resolver_sov/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" [dependencies] did_resolver = { path = "../../did_resolver" } -aries_vcx_wallet = { path = "../../../aries/aries_vcx_wallet" } aries_vcx_ledger = { path = "../../../aries/aries_vcx_ledger" } async-trait = "0.1.68" mockall = "0.11.4" @@ -21,3 +20,4 @@ aries_vcx = { path = "../../../aries/aries_vcx" } tokio = { version = "1.27.0", default-features = false, features = ["macros", "rt"] } uuid = "1.3.1" test_utils = {path = "../../../aries/misc/test_utils", features = ["vdrtools_wallet"] } +aries_vcx_wallet = { path = "../../../aries/aries_vcx_wallet" }