dm: allow kind override for encrypted content in other kinds

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2022-07-28 09:29:33 -07:00
parent 0c583e9868
commit 098f639f46

View File

@ -556,7 +556,7 @@ static int mine_event(struct nostr_event *ev, int difficulty)
} }
static int make_encrypted_dm(secp256k1_context *ctx, struct key *key, static int make_encrypted_dm(secp256k1_context *ctx, struct key *key,
struct nostr_event *ev, unsigned char nostr_pubkey[32]) struct nostr_event *ev, unsigned char nostr_pubkey[32], int kind)
{ {
size_t inl = strlen(ev->content); size_t inl = strlen(ev->content);
int enclen = inl + 16; int enclen = inl + 16;
@ -630,7 +630,7 @@ static int make_encrypted_dm(secp256k1_context *ctx, struct key *key,
} }
ev->content = (const char*)cur.start; ev->content = (const char*)cur.start;
ev->kind = 4; ev->kind = kind;
if (!hex_encode(nostr_pubkey, 32, (char*)cur.p, cur.end - cur.p)) if (!hex_encode(nostr_pubkey, 32, (char*)cur.p, cur.end - cur.p))
return 0; return 0;
@ -683,7 +683,8 @@ int main(int argc, const char *argv[])
} }
if (args.flags & HAS_ENCRYPT) { if (args.flags & HAS_ENCRYPT) {
if (!make_encrypted_dm(ctx, &key, &ev, args.encrypt_to)) { int kind = args.flags & HAS_KIND? args.kind : 4;
if (!make_encrypted_dm(ctx, &key, &ev, args.encrypt_to, kind)) {
fprintf(stderr, "error making encrypted dm\n"); fprintf(stderr, "error making encrypted dm\n");
return 0; return 0;
} }