Browse Source

Merge pull request #592 from thesimplekid/debug_print_of_i

feat: debug print to hide seed and print version
thesimplekid 1 month ago
parent
commit
3775d7d9f7

+ 7 - 1
crates/cashu/src/nuts/nut02.rs

@@ -86,7 +86,7 @@ impl fmt::Display for KeySetVersion {
 /// anyone who knows the set of public keys of a mint. The keyset ID **CAN**
 /// be stored in a Cashu token such that the token can be used to identify
 /// which mint or keyset it was generated from.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
 #[serde(into = "String", try_from = "String")]
 #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema), schema(as = String))]
 pub struct Id {
@@ -138,6 +138,12 @@ impl fmt::Display for Id {
     }
 }
 
+impl fmt::Debug for Id {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.write_str(&format!("{}{}", self.version, hex::encode(self.id)))
+    }
+}
+
 impl TryFrom<String> for Id {
     type Error = Error;
 

+ 1 - 3
crates/cdk-integration-tests/tests/fake_wallet.rs

@@ -867,9 +867,7 @@ async fn test_fake_mint_input_output_mismatch() -> Result<()> {
     match response {
         Err(err) => match err {
             cdk::Error::UnitMismatch => (),
-            err => {
-                bail!("Wrong error returned: {}", err);
-            }
+            err => bail!("Wrong error returned: {}", err),
         },
         Ok(_) => {
             bail!("Should not have allowed to mint with multiple units");

+ 6 - 0
crates/cdk-mintd/Cargo.toml

@@ -36,6 +36,12 @@ cdk-axum = { path = "../cdk-axum", version = "0.7.0", default-features = false }
 cdk-mint-rpc = { path = "../cdk-mint-rpc", version = "0.7.0", default-features = false, optional = true }
 config = { version = "0.13.3", features = ["toml"] }
 clap = { version = "~4.0.32", features = ["derive"] }
+bitcoin = { version = "0.32.2", features = [
+    "base64",
+    "serde",
+    "rand",
+    "rand-std",
+] }
 tokio = { version = "1", default-features = false }
 tracing = { version = "0.1", default-features = false, features = [
     "attributes",

+ 19 - 1
crates/cdk-mintd/src/config.rs

@@ -1,12 +1,13 @@
 use std::path::PathBuf;
 
+use bitcoin::hashes::{sha256, Hash};
 use cdk::nuts::{CurrencyUnit, PublicKey};
 use cdk::Amount;
 use cdk_axum::cache;
 use config::{Config, ConfigError, File};
 use serde::{Deserialize, Serialize};
 
-#[derive(Debug, Clone, Serialize, Deserialize, Default)]
+#[derive(Clone, Serialize, Deserialize, Default)]
 pub struct Info {
     pub url: String,
     pub listen_host: String,
@@ -23,6 +24,23 @@ pub struct Info {
     pub enable_swagger_ui: Option<bool>,
 }
 
+impl std::fmt::Debug for Info {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        let mnemonic_hash = sha256::Hash::from_slice(&self.mnemonic.clone().into_bytes())
+            .map_err(|_| std::fmt::Error)?;
+
+        f.debug_struct("Info")
+            .field("url", &self.url)
+            .field("listen_host", &self.listen_host)
+            .field("listen_port", &self.listen_port)
+            .field("mnemonic", &format!("<hashed: {}>", mnemonic_hash))
+            .field("input_fee_ppk", &self.input_fee_ppk)
+            .field("http_cache", &self.http_cache)
+            .field("enable_swagger_ui", &self.enable_swagger_ui)
+            .finish()
+    }
+}
+
 #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
 #[serde(rename_all = "lowercase")]
 pub enum LnBackend {