WIP NIP-17 direct messages

This commit is contained in:
2025-06-09 20:31:00 -05:00
parent 3ddb2625e9
commit 922c705dd0
17 changed files with 369 additions and 18 deletions

View File

@@ -3628,6 +3628,39 @@ int ndb_builder_finalize(struct ndb_builder *builder, struct ndb_note **note,
return total_size;
}
int ndb_builder_finalize_just_pubkey(struct ndb_builder *builder, struct ndb_note **note,
unsigned char pubkey[32])
{
int strings_len = builder->strings.p - builder->strings.start;
unsigned char *note_end = builder->note_cur.p + strings_len;
int total_size = note_end - builder->note_cur.start;
// move the strings buffer next to the end of our ndb_note
memmove(builder->note_cur.p, builder->strings.start, strings_len);
// set the strings location
builder->note->strings = builder->note_cur.p - builder->note_cur.start;
// record the total size
//builder->note->size = total_size;
*note = builder->note;
// use the remaining memory for building our id buffer
unsigned char *end = builder->mem.end;
unsigned char *start = (unsigned char*)(*note) + total_size;
ndb_builder_set_pubkey(builder, pubkey);
if (!ndb_calculate_id(builder->note, start, end - start))
return 0;
// make sure we're aligned as a whole
total_size = (total_size + 7) & ~7;
assert((total_size % 8) == 0);
return total_size;
}
struct ndb_note * ndb_builder_note(struct ndb_builder *builder)
{
return builder->note;