Skip to content

Commit 4360276

Browse files
committed
drop unnecesary codebase complexity removing the bincode usage where is not needed
in the key-wallet crate
1 parent 5004b52 commit 4360276

32 files changed

Lines changed: 19 additions & 1347 deletions

key-wallet-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib", "staticlib", "lib"]
1515
[features]
1616
default = ["bincode", "eddsa", "bls", "bip38"]
1717
bip38 = ["key-wallet/bip38"]
18-
bincode = ["key-wallet/bincode", "key-wallet-manager/bincode"]
18+
bincode = ["key-wallet/serde", "key-wallet-manager/bincode"]
1919
eddsa = ["dashcore/eddsa", "key-wallet/eddsa"]
2020
bls = ["dashcore/bls", "key-wallet/bls"]
2121

key-wallet-ffi/tests/test_import_wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Test for wallet import from bytes via FFI
22
3-
#[cfg(feature = "bincode")]
3+
#[cfg(feature = "serde")]
44
#[cfg(test)]
55
mod tests {
66
use key_wallet_ffi::error::{FFIError, FFIErrorCode};

key-wallet-manager/src/lib.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<T: WalletInfoInterface> WalletManager<T> {
220220
/// # Security Note
221221
/// When `downgrade_to_pubkey_wallet` is true, the returned wallet contains NO private key material,
222222
/// making it safe to use on potentially compromised systems or for creating watch-only wallets.
223-
#[cfg(feature = "bincode")]
223+
#[cfg(feature = "serde")]
224224
#[allow(clippy::too_many_arguments)]
225225
pub fn create_wallet_from_mnemonic_return_serialized_bytes(
226226
&mut self,
@@ -290,10 +290,10 @@ impl<T: WalletInfoInterface> WalletManager<T> {
290290
}
291291

292292
// Serialize the wallet to bytes
293-
let serialized_bytes = bincode::encode_to_vec(&final_wallet, bincode::config::standard())
294-
.map_err(|e| {
295-
WalletError::InvalidParameter(format!("Failed to serialize wallet: {}", e))
296-
})?;
293+
let serialized_bytes =
294+
bincode::serde::encode_to_vec(&final_wallet, bincode::config::standard()).map_err(
295+
|e| WalletError::InvalidParameter(format!("Failed to serialize wallet: {}", e)),
296+
)?;
297297

298298
// Add the wallet to the manager
299299
let mut managed_info = T::from_wallet(&final_wallet);
@@ -497,17 +497,18 @@ impl<T: WalletInfoInterface> WalletManager<T> {
497497
/// # Returns
498498
/// * `Ok(WalletId)` - The computed wallet ID of the imported wallet
499499
/// * `Err(WalletError)` - If deserialization fails or the wallet already exists
500-
#[cfg(feature = "bincode")]
500+
#[cfg(feature = "serde")]
501501
pub fn import_wallet_from_bytes(
502502
&mut self,
503503
wallet_bytes: &[u8],
504504
) -> Result<WalletId, WalletError> {
505505
// Deserialize the wallet from bincode
506-
let wallet: Wallet = bincode::decode_from_slice(wallet_bytes, bincode::config::standard())
507-
.map_err(|e| {
508-
WalletError::InvalidParameter(format!("Failed to deserialize wallet: {}", e))
509-
})?
510-
.0;
506+
let wallet: Wallet =
507+
bincode::serde::decode_from_slice(wallet_bytes, bincode::config::standard())
508+
.map_err(|e| {
509+
WalletError::InvalidParameter(format!("Failed to deserialize wallet: {}", e))
510+
})?
511+
.0;
511512

512513
// Compute wallet ID from the wallet's root public key
513514
let wallet_id = wallet.compute_wallet_id();

key-wallet-manager/tests/test_serialized_wallets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "bincode")]
1+
#[cfg(feature = "serde")]
22
#[cfg(test)]
33
mod tests {
44
use key_wallet::wallet::initialization::WalletAccountCreationOptions;

key-wallet/Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ license = "CC0-1.0"
1010

1111
[features]
1212
default = ["getrandom"]
13-
serde = ["dep:serde", "dep:serde_json", "dashcore_hashes/serde", "secp256k1/serde", "dashcore/serde"]
14-
bincode = ["serde", "dep:bincode", "dep:bincode_derive", "dashcore_hashes/bincode", "dashcore/bincode"]
13+
serde = ["dep:serde", "dashcore_hashes/serde", "secp256k1/serde", "dashcore/serde"]
1514
bip38 = ["scrypt", "aes", "bs58", "rand"]
1615
eddsa = ["dashcore/eddsa"]
1716
bls = ["dashcore/bls"]
@@ -23,7 +22,6 @@ dashcore_hashes = { path = "../hashes" }
2322
dashcore = { path="../dash" }
2423
secp256k1 = { version = "0.30.0", default-features = false, features = ["hashes", "recovery", "std"] }
2524
bip39 = { version = "2.2.0", default-features = false, features = ["std", "chinese-simplified", "chinese-traditional", "czech", "french", "italian", "japanese", "korean", "portuguese", "spanish", "zeroize"] }
26-
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
2725
base58ck = { version = "0.1.0", default-features = false }
2826
bitflags = { version = "2.6", default-features = false }
2927
getrandom = { version = "0.2", optional = true }
@@ -34,10 +32,9 @@ sha2 = { version = "0.10", default-features = false }
3432
bs58 = { version = "0.5", default-features = false, features = ["check", "alloc"], optional = true }
3533
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
3634
# Serialization
37-
bincode = { version = "2.0.1", optional = true }
38-
bincode_derive = { version = "2.0.1", optional = true }
35+
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
36+
bincode = { version = "2.0.1", default-features = false, features = ["serde"], optional = true }
3937
base64 = { version = "0.22", optional = true }
40-
serde_json = { version = "1.0", optional = true }
4138
hex = { version = "0.4"}
4239
zeroize = { version = "1.8", features = ["derive"] }
4340
tracing = "0.1"
@@ -46,7 +43,7 @@ async-trait = "0.1"
4643
[dev-dependencies]
4744
dashcore = { path="../dash", features = ["test-utils"] }
4845
hex = "0.4"
49-
key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "bincode", "eddsa", "bls"] }
46+
key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "eddsa", "bls"] }
5047
rand = { version = "0.8", features = ["std", "std_rng"] }
5148
test-case = "3.3"
5249
tokio = { version = "1", features = ["macros", "rt"] }

key-wallet/src/account/account_collection.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
use std::collections::BTreeMap;
66

7-
#[cfg(feature = "bincode")]
8-
use bincode_derive::{Decode, Encode};
97
#[cfg(feature = "serde")]
108
use serde::{Deserialize, Serialize};
119

@@ -21,7 +19,6 @@ pub type DashpayContactIdentityId = [u8; 32];
2119

2220
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
2321
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2522
pub struct DashpayAccountKey {
2623
pub index: u32,
2724
pub user_identity_id: DashpayOurUserIdentityId,
@@ -31,7 +28,6 @@ pub struct DashpayAccountKey {
3128
/// Key for Platform Payment accounts (DIP-17)
3229
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3330
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
34-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3531
pub struct PlatformPaymentAccountKey {
3632
/// Account index (hardened)
3733
pub account: u32,
@@ -42,7 +38,6 @@ pub struct PlatformPaymentAccountKey {
4238
/// Collection of accounts organized by type
4339
#[derive(Debug, Clone, Default)]
4440
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
45-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
4641
pub struct AccountCollection {
4742
/// Standard BIP44 accounts by index
4843
pub standard_bip44_accounts: BTreeMap<u32, Account>,

key-wallet/src/account/account_type.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ use crate::transaction_checking::transaction_router::{
88
AccountTypeToCheck, PlatformAccountConversionError,
99
};
1010
use crate::Network;
11-
#[cfg(feature = "bincode")]
12-
use bincode_derive::{Decode, Encode};
1311
#[cfg(feature = "serde")]
1412
use serde::{Deserialize, Serialize};
1513

1614
/// Account types supported by the wallet
1715
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
1816
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
19-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2017
pub enum StandardAccountType {
2118
/// Standard BIP44 account for regular transactions m/44'/coin_type'/account'/x/x
2219
#[default]
@@ -28,7 +25,6 @@ pub enum StandardAccountType {
2825
/// Account types supported by the wallet
2926
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3027
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3228
pub enum AccountType {
3329
/// Standard BIP44 account for regular transactions
3430
Standard {

key-wallet/src/account/bls_account.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use dashcore::Address;
1616
use serde::{Deserialize, Serialize};
1717

1818
use crate::bip32::{ChainCode, Fingerprint};
19-
#[cfg(feature = "bincode")]
20-
use bincode_derive::{Decode, Encode};
2119
use dashcore::blsful::{Bls12381G2Impl, SerializationFormat};
2220

2321
use crate::account::derivation::AccountDerivation;
@@ -27,7 +25,6 @@ pub use dashcore::blsful::SecretKey;
2725
/// BLS account structure for Platform and masternode operations
2826
#[derive(Debug, Clone)]
2927
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
30-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3128
pub struct BLSAccount {
3229
/// Wallet id (stored as Vec for serialization)
3330
pub parent_wallet_id: Option<Vec<u8>>,
@@ -163,21 +160,6 @@ impl BLSAccount {
163160
watch_only.is_watch_only = true;
164161
watch_only
165162
}
166-
167-
/// Serialize account to bytes
168-
#[cfg(feature = "bincode")]
169-
pub fn serialize(&self) -> Result<Vec<u8>> {
170-
bincode::encode_to_vec(self, bincode::config::standard())
171-
.map_err(|e| Error::Serialization(e.to_string()))
172-
}
173-
174-
/// Deserialize account from bytes
175-
#[cfg(feature = "bincode")]
176-
pub fn deserialize(data: &[u8]) -> Result<Self> {
177-
bincode::decode_from_slice(data, bincode::config::standard())
178-
.map(|(account, _)| account)
179-
.map_err(|e| Error::Serialization(e.to_string()))
180-
}
181163
}
182164

183165
impl AccountTrait for BLSAccount {

key-wallet/src/account/coinjoin.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
//! This module contains structures for managing CoinJoin address pools.
44
55
use crate::managed_account::address_pool::AddressPool;
6-
#[cfg(feature = "bincode")]
7-
use bincode_derive::{Decode, Encode};
86
#[cfg(feature = "serde")]
97
use serde::{Deserialize, Serialize};
108

119
/// CoinJoin-specific address pools
1210
#[derive(Debug, Clone)]
1311
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
1512
pub struct CoinJoinPools {
1613
/// CoinJoin receive addresses
1714
pub external: AddressPool,

key-wallet/src/account/eddsa_account.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ use serde::{Deserialize, Serialize};
1717
use crate::account::derivation::AccountDerivation;
1818
use crate::bip32::{ChainCode, Fingerprint};
1919
use crate::managed_account::address_pool::AddressPoolType;
20-
#[cfg(feature = "bincode")]
21-
use bincode_derive::{Decode, Encode};
2220

2321
/// EdDSA (Ed25519) account structure for Platform identity operations
2422
#[derive(Debug, Clone)]
2523
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2724
pub struct EdDSAAccount {
2825
/// Wallet id (stored as Vec for serialization)
2926
pub parent_wallet_id: Option<Vec<u8>>,
@@ -155,21 +152,6 @@ impl EdDSAAccount {
155152
watch_only
156153
}
157154

158-
/// Serialize account to bytes
159-
#[cfg(feature = "bincode")]
160-
pub fn serialize(&self) -> Result<Vec<u8>> {
161-
bincode::encode_to_vec(self, bincode::config::standard())
162-
.map_err(|e| Error::Serialization(e.to_string()))
163-
}
164-
165-
/// Deserialize account from bytes
166-
#[cfg(feature = "bincode")]
167-
pub fn deserialize(data: &[u8]) -> Result<Self> {
168-
bincode::decode_from_slice(data, bincode::config::standard())
169-
.map(|(account, _)| account)
170-
.map_err(|e| Error::Serialization(e.to_string()))
171-
}
172-
173155
/// Derive a Platform identity key at index
174156
pub fn derive_identity_key(&self, index: u32) -> Result<ExtendedEd25519PubKey> {
175157
self.derive_ed25519_key_at_index(index)

0 commit comments

Comments
 (0)