From 24b7ab51bd07e6b7b0938ad60441cf0eee6645c3 Mon Sep 17 00:00:00 2001 From: artimonist Date: Fri, 15 Aug 2025 20:53:53 +0000 Subject: [PATCH] use new bip38 impl --- Cargo.lock | 197 +++++++++++++++++++++++++----------------- Cargo.toml | 21 +++-- src/bip32/execute.rs | 10 +-- src/derive/execute.rs | 7 +- src/diagram/output.rs | 6 +- src/encrypt/bip38.rs | 10 +-- src/utils/bip38.rs | 18 ---- src/utils/mod.rs | 2 - tests/encrypt.rs | 6 +- 9 files changed, 146 insertions(+), 131 deletions(-) delete mode 100644 src/utils/bip38.rs diff --git a/Cargo.lock b/Cargo.lock index 8fe1611..30eaffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -54,29 +54,29 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anyhow" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" [[package]] name = "arrayvec" @@ -86,26 +86,28 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "artimonist" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4aa3675fb1eaafe0af25a547a0fb01a440adde9b8efcca3426e80cad90f373c5" +checksum = "7413d6d7cab3380a8f2796944c2634338417814670902cdee87f3f465b70e0e1" dependencies = [ + "aes", "bitcoin", "pbkdf2", + "rand", "scrypt", "sha2", "thiserror", + "unicode-normalization", "xbits", ] [[package]] name = "artimonist" -version = "1.6.2" +version = "1.7.0" dependencies = [ "anyhow", - "artimonist 1.3.1", + "artimonist 1.5.0", "assert_cmd", - "bip38", "clap", "comfy-table", "inquire", @@ -152,27 +154,11 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" -[[package]] -name = "bip38" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa5c9389a55dd9cec725634b325a35e67d57bb987453ff8801cac262135bc57" -dependencies = [ - "aes", - "bs58", - "rand", - "ripemd", - "scrypt", - "secp256k1", - "sha2", - "unicode-normalization", -] - [[package]] name = "bitcoin" -version = "0.32.6" +version = "0.32.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8929a18b8e33ea6b3c09297b687baaa71fb1b97353243a3f1029fad5c59c5b" +checksum = "0fda569d741b895131a88ee5589a467e73e9c4718e958ac9308e4f7dc44b6945" dependencies = [ "base58ck", "bech32", @@ -237,15 +223,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bs58" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" -dependencies = [ - "tinyvec", -] - [[package]] name = "bstr" version = "1.12.0" @@ -265,9 +242,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.2.29" +version = "1.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" +checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" dependencies = [ "shlex", ] @@ -290,9 +267,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -300,9 +277,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.41" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -312,9 +289,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", @@ -413,9 +390,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dyn-clone" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "float-cmp" @@ -519,9 +496,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "lock_api" @@ -667,9 +644,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1" dependencies = [ "unicode-ident", ] @@ -715,9 +692,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.13" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ "bitflags 2.9.1", ] @@ -751,15 +728,6 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest", -] - [[package]] name = "salsa20" version = "0.10.2" @@ -865,9 +833,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" dependencies = [ "libc", ] @@ -892,9 +860,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.104" +version = "2.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619" dependencies = [ "proc-macro2", "quote", @@ -909,18 +877,18 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" [[package]] name = "thiserror" -version = "2.0.12" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227" dependencies = [ "proc-macro2", "quote", @@ -1030,6 +998,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.48.0" @@ -1041,11 +1015,11 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.59.0" +version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.52.6", + "windows-targets 0.53.3", ] [[package]] @@ -1072,13 +1046,30 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm", + "windows_i686_gnullvm 0.52.6", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -1091,6 +1082,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -1103,6 +1100,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -1115,12 +1118,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -1133,6 +1148,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -1145,6 +1166,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -1157,6 +1184,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -1169,6 +1202,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "xbits" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index 01bdcc2..af8790e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "artimonist" -version = "1.6.2" +version = "1.7.0" edition = "2024" description = "A tool for generating mnemonics and wallets." @@ -21,14 +21,13 @@ testnet = ["artimonist/testnet"] [dependencies] -artimonist = { version = "1.3.1" } -clap = { version = "^4.5.28", features = ["derive"] } -inquire = { version = "^0.7.5", default-features = false, features = ["crossterm"] } -comfy-table = { version = "^7.1.4", default-features = false } -bip38 = "1.1.1" -thiserror = "2.0.11" -anyhow = "1.0.98" -unicode-normalization = "0.1.24" +artimonist = { version = "1.5" } +clap = { version = "^4.5", features = ["derive"] } +inquire = { version = "^0.7", default-features = false, features = ["crossterm"] } +comfy-table = { version = "^7.1", default-features = false } +thiserror = "2" +anyhow = "1" +unicode-normalization = "0.1" [profile.release] codegen-units = 1 @@ -37,5 +36,5 @@ opt-level = "z" strip = true [dev-dependencies] -assert_cmd = "2.0.16" -predicates = "3.1.3" +assert_cmd = "2" +predicates = "3" diff --git a/src/bip32/execute.rs b/src/bip32/execute.rs index 5f304a6..dacc09b 100644 --- a/src/bip32/execute.rs +++ b/src/bip32/execute.rs @@ -1,9 +1,7 @@ use super::arg::{MasterKey, inquire_derive_path}; -use crate::Execute; -use crate::utils::{bip38_encrypt, inquire_password}; -use artimonist::bitcoin; -use artimonist::bitcoin::bip32::DerivationPath; -use artimonist::{BIP39, Xpriv, Xpub, bitcoin::Address}; +use crate::{Execute, utils::inquire_password}; +use artimonist::bitcoin::{self, Address, bip32::DerivationPath}; +use artimonist::{BIP38, BIP39, Xpriv, Xpub}; use std::io::Write; impl Execute for super::arg::Bip32Command { @@ -42,7 +40,7 @@ fn derive_xprv(master: &Xpriv, path: &DerivationPath, password: &str) -> anyhow: writeln!(f, "Extended public key: {xpub}")?; let (pub_key, priv_wif) = (xpub.to_pub(), xprv.to_priv().to_string()); - writeln!(f, "Private key: {}", bip38_encrypt(&priv_wif, password)?)?; + writeln!(f, "Private key: {}", priv_wif.bip38_encrypt(password)?)?; writeln!(f, "Public key: {pub_key}")?; let network = artimonist::bitcoin::Network::Bitcoin; diff --git a/src/derive/execute.rs b/src/derive/execute.rs index a941c0f..672c8e4 100644 --- a/src/derive/execute.rs +++ b/src/derive/execute.rs @@ -1,7 +1,6 @@ use super::{DeriveCommand, arg::MasterKey, multisig::MultiSig}; -use crate::Execute; -use crate::utils::{bip38_encrypt, inquire_password}; -use artimonist::{BIP39, Xpriv}; +use crate::{Execute, utils::inquire_password}; +use artimonist::{BIP38, BIP39, Xpriv}; use std::io::{BufWriter, Write}; impl Execute for DeriveCommand { @@ -58,7 +57,7 @@ impl Wallet for DeriveCommand { for index in self.index..self.index + self.amount { let (addr, pk) = self.derive.wallet(master, self.account, index)?; let path = format!("{}/0/{index}", self.derive.path(self.account)); - writeln!(f, "[{path}]: {addr}, {}", bip38_encrypt(&pk, password)?)?; + writeln!(f, "[{path}]: {addr}, {}", pk.bip38_encrypt(password)?)?; } Ok(()) } diff --git a/src/diagram/output.rs b/src/diagram/output.rs index 525fdbe..56261df 100644 --- a/src/diagram/output.rs +++ b/src/diagram/output.rs @@ -1,7 +1,7 @@ use super::DiagramCommand; -use crate::utils::{bip38_encrypt, unicode_encode}; +use crate::utils::unicode_encode; use anyhow::anyhow; -use artimonist::{BIP85, ComplexDiagram, GenericDiagram, Matrix, SimpleDiagram, Xpriv}; +use artimonist::{BIP38, BIP85, ComplexDiagram, GenericDiagram, Matrix, SimpleDiagram, Xpriv}; use std::io::{BufWriter, Write}; use unicode_normalization::UnicodeNormalization; @@ -93,7 +93,7 @@ impl DeriveTargets for DiagramCommand { writeln!(f, "Wifs: ")?; for index in self.index..self.index + self.amount { let artimonist::Wif { addr, pk } = master.bip85_wif(index)?; - writeln!(f, "({index}): {addr}, {}", bip38_encrypt(&pk, password)?)?; + writeln!(f, "({index}): {addr}, {}", pk.bip38_encrypt(password)?)?; } Ok(()) } diff --git a/src/encrypt/bip38.rs b/src/encrypt/bip38.rs index 8552b6e..5c1aeb6 100644 --- a/src/encrypt/bip38.rs +++ b/src/encrypt/bip38.rs @@ -1,7 +1,7 @@ use super::{EncryptCommand, arg::EncryptSource}; -use crate::utils::{bip38_decrypt, bip38_encrypt}; use crate::{Execute, utils::inquire_password}; use anyhow::anyhow; +use artimonist::BIP38; use std::fs::File; use std::io::{BufRead, BufReader, BufWriter, Write}; @@ -20,9 +20,9 @@ impl Execute for EncryptCommand { match &self.source { EncryptSource::Key(key) => { if ENCRYPT { - println!("Encrypted private key: {}", bip38_encrypt(key, &password)?); + println!("Encrypted private key: {}", key.bip38_encrypt(&password)?); } else { - println!("Decrypted private key: {}", bip38_decrypt(key, &password)?); + println!("Decrypted private key: {}", key.bip38_decrypt(&password)?); } } EncryptSource::File(file) => { @@ -45,9 +45,9 @@ fn execute_bulk(file: &str, password: &str) -> anyhow::Resu .split_ascii_whitespace() .map(|s| { if ENCRYPT && s.is_private() { - bip38_encrypt(s, password).unwrap_or(s.to_string()) + s.bip38_encrypt(password).unwrap_or(s.to_string()) } else if s.is_encrypted() { - bip38_decrypt(s, password).unwrap_or(s.to_string()) + s.bip38_decrypt(password).unwrap_or(s.to_string()) } else { s.to_string() } diff --git a/src/utils/bip38.rs b/src/utils/bip38.rs deleted file mode 100644 index 44db03e..0000000 --- a/src/utils/bip38.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anyhow::anyhow; -use bip38::{Decrypt, EncryptWif}; - -#[inline(always)] -pub fn bip38_encrypt(wif: &str, password: &str) -> anyhow::Result { - match artimonist::NETWORK.is_mainnet() { - true => wif.encrypt_wif(password).map_err(|e| anyhow!(e)), - false => Ok(wif.to_string()), // No encryption on testnet - } -} - -#[inline(always)] -pub fn bip38_decrypt(wif: &str, password: &str) -> anyhow::Result { - match artimonist::NETWORK.is_mainnet() { - true => wif.decrypt_to_wif(password).map_err(|e| anyhow!(e)), - false => Ok(wif.to_string()), // No decryption on testnet - } -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e35a243..2d0547f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,7 +1,5 @@ -mod bip38; mod inquire; mod unicode; -pub use bip38::{bip38_decrypt, bip38_encrypt}; pub use inquire::{inquire_password, select_language}; pub use unicode::{unicode_decode, unicode_encode}; diff --git a/tests/encrypt.rs b/tests/encrypt.rs index 756cb52..4d3a74b 100644 --- a/tests/encrypt.rs +++ b/tests/encrypt.rs @@ -54,17 +54,17 @@ macro_rules! cli_test_error { #[test] fn test_encrypt_error() { cli_test_error!( - "Error: invalid wif private key", + "Error: Invalid WIF: decoded base58 data was an invalid length", "encrypt", "6PYPVwvgux4mN96iwj1RGvbiGmmPWpkiQimpkP1fvFGGhT38XxZed6Kdth" ); cli_test_error!( - "Error: invalid encrypted private key", + "Error: Invalid BIP38 encrypted key", "decrypt", "KyyXeMvCn36KuedmVX727NYQ35YEeF4z1ZjXGyqgFpmZM4AcY8ay" ); cli_test_error!( - "Error: invalid checksum", + "Error: Base58 error: incorrect checksum", "decrypt", "6PYPVwvgux4mN96iwj1RGvbiGmmPWpkiQimpkP1fvFGGhT38XxZed6Kdt1" );