Browse Source

chore: remove unwraps from nut13

thesimplekid 1 year ago
parent
commit
6632c08b01
2 changed files with 10 additions and 7 deletions
  1. 5 0
      crates/cashu/src/error.rs
  2. 5 7
      crates/cashu/src/nuts/nut13.rs

+ 5 - 0
crates/cashu/src/error.rs

@@ -55,6 +55,11 @@ pub enum Error {
     #[error("`{0}`")]
     Secret(#[from] super::secret::Error),
     #[error("`{0}`")]
+    NUT02(#[from] crate::nuts::nut02::Error),
+    #[cfg(feature = "nut13")]
+    #[error("`{0}`")]
+    Bip32(#[from] bip32::Error),
+    #[error("`{0}`")]
     ParseInt(#[from] std::num::ParseIntError),
     /// Custom error
     #[error("`{0}`")]

+ 5 - 7
crates/cashu/src/nuts/nut13.rs

@@ -11,10 +11,9 @@ impl Secret {
     pub fn from_seed(mnemonic: &Mnemonic, keyset_id: Id, counter: u64) -> Result<Self, Error> {
         let path = DerivationPath::from_str(&format!(
             "m/129372'/0'/{}'/{}'/0",
-            u64::try_from(keyset_id).unwrap(),
+            u64::try_from(keyset_id)?,
             counter
-        ))
-        .unwrap();
+        ))?;
 
         let xpriv = XPrv::derive_from_path(mnemonic.to_seed(""), &path).unwrap();
 
@@ -26,12 +25,11 @@ impl SecretKey {
     pub fn from_seed(mnemonic: &Mnemonic, keyset_id: Id, counter: u64) -> Result<Self, Error> {
         let path = DerivationPath::from_str(&format!(
             "m/129372'/0'/{}'/{}'/1",
-            u64::try_from(keyset_id).unwrap(),
+            u64::try_from(keyset_id)?,
             counter
-        ))
-        .unwrap();
+        ))?;
 
-        let signing_key = XPrv::derive_from_path(mnemonic.to_seed(""), &path).unwrap();
+        let signing_key = XPrv::derive_from_path(mnemonic.to_seed(""), &path)?;
 
         let private_key = signing_key.private_key();