Browse Source

feat(cdk-cli): support nostr nsec secret keys

thesimplekid 9 months ago
parent
commit
59ac008e50
2 changed files with 12 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 11 2
      crates/cdk-cli/src/sub_commands/receive.rs

+ 1 - 0
CHANGELOG.md

@@ -33,6 +33,7 @@
 - cdk(NUT-11): Add `Copy` on `SigFlag` ([thesimplekid]).
 - cdk(wallet): Add `fn send_proofs` that marks proofs as `reserved` and creates token ([thesimplekid]).
 - cdk(wallet): Add `fn melt_proofs` that uses specific proofs for `melt` instead of selecting ([thesimplekid]).
+- cdk-cli(receive): Add support for signing keys to be nostr nsec encoded ([thesimplekid]).
 
 ### Fixed
 - cdk(mint): `SIG_ALL` is not allowed in `melt` ([thesimplekid]).

+ 11 - 2
crates/cdk-cli/src/sub_commands/receive.rs

@@ -46,7 +46,15 @@ pub async fn receive(
         let mut s_keys: Vec<SecretKey> = sub_command_args
             .signing_key
             .iter()
-            .map(|s| SecretKey::from_str(s).unwrap())
+            .flat_map(|s| {
+                if s.starts_with("nsec") {
+                    let nostr_key = nostr_sdk::SecretKey::from_str(s).expect("Invalid secret key");
+
+                    SecretKey::from_str(&nostr_key.to_secret_hex())
+                } else {
+                    SecretKey::from_str(s)
+                }
+            })
             .collect();
         signing_keys.append(&mut s_keys);
     }
@@ -67,7 +75,8 @@ pub async fn receive(
             //wallet.add_p2pk_signing_key(nostr_signing_key).await;
             let nostr_key = match sub_command_args.nostr_key.as_ref() {
                 Some(nostr_key) => {
-                    let secret_key = SecretKey::from_str(nostr_key)?;
+                    let secret_key = nostr_sdk::SecretKey::from_str(nostr_key)?;
+                    let secret_key = SecretKey::from_str(&secret_key.to_secret_hex())?;
                     Some(secret_key)
                 }
                 None => None,