diff --git a/Cargo.lock b/Cargo.lock index 3be8929059..92649835e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -370,12 +370,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" -[[package]] -name = "base58" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" - [[package]] name = "base64" version = "0.11.0" @@ -830,7 +824,6 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "base58", "base64 0.21.7", "bip32", "bitcoin", @@ -3049,9 +3042,9 @@ dependencies = [ name = "keys" version = "0.1.0" dependencies = [ - "base58", "bech32", "bitcrypto", + "bs58 0.4.0", "derive_more", "lazy_static", "primitives", diff --git a/mm2src/adex_cli/Cargo.lock b/mm2src/adex_cli/Cargo.lock index 5d5eb5abeb..099a669565 100644 --- a/mm2src/adex_cli/Cargo.lock +++ b/mm2src/adex_cli/Cargo.lock @@ -336,12 +336,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base58" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" - [[package]] name = "base64" version = "0.21.7" @@ -1714,7 +1708,6 @@ dependencies = [ name = "keys" version = "0.1.0" dependencies = [ - "base58", "bech32", "bitcrypto", "derive_more", diff --git a/mm2src/coins/Cargo.toml b/mm2src/coins/Cargo.toml index 670688e07d..47a5baace0 100644 --- a/mm2src/coins/Cargo.toml +++ b/mm2src/coins/Cargo.toml @@ -23,8 +23,6 @@ doctest = false async-std = { version = "1.5", features = ["unstable"] } async-trait = "0.1.52" base64 = "0.21.2" -# Todo: remove this and rely on bs58 throught the whole codebase -base58 = "0.2.0" bip32 = { version = "0.2.2", default-features = false, features = ["alloc", "secp256k1-ffi"] } bitcoin_hashes = "0.11" bitcrypto = { path = "../mm2_bitcoin/crypto" } diff --git a/mm2src/coins/lp_coins.rs b/mm2src/coins/lp_coins.rs index a211761968..83f1aa0026 100644 --- a/mm2src/coins/lp_coins.rs +++ b/mm2src/coins/lp_coins.rs @@ -43,7 +43,6 @@ #[macro_use] extern crate ser_error_derive; use async_trait::async_trait; -use base58::FromBase58Error; use bip32::ExtendedPrivateKey; use common::custom_futures::timeout::TimeoutError; use common::executor::{abortable_queue::WeakSpawner, AbortedError, SpawnFuture}; @@ -3418,19 +3417,6 @@ impl HttpStatusCode for VerificationError { } } -impl From for VerificationError { - fn from(e: FromBase58Error) -> Self { - match e { - FromBase58Error::InvalidBase58Character(c, _) => { - VerificationError::AddressDecodingError(format!("Invalid Base58 Character: {}", c)) - }, - FromBase58Error::InvalidBase58Length => { - VerificationError::AddressDecodingError(String::from("Invalid Base58 Length")) - }, - } - } -} - /// NB: Implementations are expected to follow the pImpl idiom, providing cheap reference-counted cloning and garbage collection. #[async_trait] pub trait MmCoin: SwapOps + WatcherOps + MarketCoinOps + Send + Sync + 'static { diff --git a/mm2src/mm2_bitcoin/keys/Cargo.toml b/mm2src/mm2_bitcoin/keys/Cargo.toml index 990bd3dff1..7002e711a8 100644 --- a/mm2src/mm2_bitcoin/keys/Cargo.toml +++ b/mm2src/mm2_bitcoin/keys/Cargo.toml @@ -7,8 +7,8 @@ authors = ["debris "] doctest = false [dependencies] +bs58 = "0.4.0" rustc-hex = "2" -base58 = "0.2" bech32 = "0.9.1" bitcrypto = { path = "../crypto" } derive_more = "0.99" diff --git a/mm2src/mm2_bitcoin/keys/src/legacyaddress.rs b/mm2src/mm2_bitcoin/keys/src/legacyaddress.rs index a9e93127af..e6a4bf4cd9 100644 --- a/mm2src/mm2_bitcoin/keys/src/legacyaddress.rs +++ b/mm2src/mm2_bitcoin/keys/src/legacyaddress.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use std::{convert::TryInto, fmt}; -use base58::{FromBase58, ToBase58}; use crypto::{checksum, ChecksumType}; use std::ops::Deref; use {AddressHashEnum, AddressPrefix, DisplayLayout}; @@ -82,7 +81,7 @@ impl FromStr for LegacyAddress { where Self: Sized, { - let hex = s.from_base58().map_err(|_| Error::InvalidAddress)?; + let hex = bs58::decode(s).into_vec().map_err(|_| Error::InvalidAddress)?; LegacyAddress::from_layout(&hex) } } @@ -92,7 +91,9 @@ impl From<&'static str> for LegacyAddress { } impl fmt::Display for LegacyAddress { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self.layout().to_base58().fmt(fmt) } + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + bs58::encode(self.layout().as_ref()).into_string().fmt(fmt) + } } impl LegacyAddress { diff --git a/mm2src/mm2_bitcoin/keys/src/lib.rs b/mm2src/mm2_bitcoin/keys/src/lib.rs index d3a01d854d..88eea9408f 100644 --- a/mm2src/mm2_bitcoin/keys/src/lib.rs +++ b/mm2src/mm2_bitcoin/keys/src/lib.rs @@ -1,8 +1,8 @@ //! Bitcoin keys. -extern crate base58; extern crate bech32; extern crate bitcrypto as crypto; +extern crate bs58; extern crate derive_more; extern crate lazy_static; extern crate primitives; diff --git a/mm2src/mm2_bitcoin/keys/src/private.rs b/mm2src/mm2_bitcoin/keys/src/private.rs index ce4e64a908..435a3b7a46 100644 --- a/mm2src/mm2_bitcoin/keys/src/private.rs +++ b/mm2src/mm2_bitcoin/keys/src/private.rs @@ -2,7 +2,6 @@ use crate::SECP_SIGN; use address::detect_checksum; -use base58::{FromBase58, ToBase58}; use crypto::{checksum, ChecksumType}; use hex::ToHex; use secp256k1::{Message as SecpMessage, SecretKey}; @@ -110,7 +109,7 @@ impl fmt::Debug for Private { } impl fmt::Display for Private { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.layout().to_base58().fmt(f) } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { bs58::encode(self.layout()).into_string().fmt(f) } } impl FromStr for Private { @@ -120,7 +119,7 @@ impl FromStr for Private { where Self: Sized, { - let hex = s.from_base58().map_err(|_| Error::InvalidPrivate)?; + let hex = bs58::decode(s).into_vec().map_err(|_| Error::InvalidPrivate)?; Private::from_layout(&hex) } }