From fa435635ef32ca5d1e87ff7caf2deedb41383f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Thu, 19 Sep 2024 11:06:04 -0300 Subject: [PATCH] Nip44 conversation key command --- src/cli.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 01b519e..a6a2485 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,6 +23,7 @@ use crate::util; use anyhow::{Error, Result}; use clap::{Parser, Subcommand}; +use nip44::v2::ConversationKey; use nostr_sdk::prelude::*; use std::{ env::{set_var, var}, @@ -205,9 +206,9 @@ pub enum Commands { #[arg(short, long)] dispute_id: Uuid, }, - /// Create a shared key for direct messaging - CreateSharedKey { - /// Pubkey of receiver of the message + /// Get the conversation key for direct messaging with a user + ConversationKey { + /// Pubkey of the counterpart #[arg(short, long)] pubkey: String, }, @@ -289,17 +290,17 @@ pub async fn run() -> Result<()> { if let Some(cmd) = cli.command { match &cmd { - Commands::CreateSharedKey { pubkey } => { - let key = nostr::util::generate_shared_key( - my_key.secret_key()?, - &PublicKey::from_str(pubkey)?, - ); - let mut shared_key_hex = vec![]; + Commands::ConversationKey { pubkey } => { + // Derive conversation key + let ck = + ConversationKey::derive(my_key.secret_key()?, &PublicKey::from_str(pubkey)?); + let key = ck.as_bytes(); + let mut ck_hex = vec![]; for i in key { - shared_key_hex.push(format!("{:0x}", i)) + ck_hex.push(format!("{:0x}", i)); } - println!("Shared key: {:?}", key); - println!("Shared key: {:?}", shared_key_hex); + let ck_hex = ck_hex.join(""); + println!("Conversation key: {:?}", ck_hex); } Commands::ListOrders { status,