Skip to content

Commit

Permalink
Merge pull request #84 from MostroP2P/add-conversation-key
Browse files Browse the repository at this point in the history
Nip44 conversation key command
  • Loading branch information
grunch authored Sep 19, 2024
2 parents de8f6f8 + fa43563 commit 5638116
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5638116

Please sign in to comment.