Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub struct Cli {
pub relays: Option<String>,
#[arg(short, long)]
pub pow: Option<String>,
#[arg(short, long)]
pub secret: bool,
}

#[derive(Subcommand, Clone)]
Expand Down Expand Up @@ -299,6 +301,10 @@ pub async fn run() -> Result<()> {
set_var("POW", cli.pow.unwrap());
}

if cli.secret {
set_var("SECRET", "true");
}

let pool = connect().await?;
let identity_keys = User::get_identity_keys(&pool)
.await
Expand Down
21 changes: 21 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub async fn send_dm(
to_user: bool,
) -> Result<()> {
let pow: u8 = var("POW").unwrap_or('0'.to_string()).parse().unwrap();
let private = var("SECRET")
.unwrap_or("false".to_string())
.parse::<bool>()
.unwrap();
let event = if to_user {
// Derive conversation key
let ck = ConversationKey::derive(trade_keys.secret_key(), receiver_pubkey);
Expand All @@ -38,6 +42,23 @@ pub async fn send_dm(
.pow(pow)
.tag(Tag::public_key(*receiver_pubkey))
.sign_with_keys(trade_keys)?
} else if private {
let message = Message::from_json(&payload).unwrap();
// We compose the content, when private we don't sign the payload
let content: (Message, Option<Signature>) = (message, None);
let content = serde_json::to_string(&content).unwrap();
// We create the rumor
let rumor = EventBuilder::text_note(content)
.pow(pow)
.build(trade_keys.public_key());
let mut tags: Vec<Tag> = Vec::with_capacity(1 + usize::from(expiration.is_some()));

if let Some(timestamp) = expiration {
tags.push(Tag::expiration(timestamp));
}
let tags = Tags::new(tags);

EventBuilder::gift_wrap(trade_keys, receiver_pubkey, rumor, tags).await?
} else {
let identity_keys = identity_keys
.ok_or_else(|| Error::msg("identity_keys required when to_user is false"))?;
Expand Down