WIP NIP-17 direct messages
This commit is contained in:
@@ -174,9 +174,9 @@ class NdbNote: Codable, Equatable, Hashable {
|
||||
let tags = try container.decode([[String]].self, forKey: .tags)
|
||||
let createdAt = try container.decode(UInt32.self, forKey: .created_at)
|
||||
let noteId = try container.decode(NoteId.self, forKey: .id)
|
||||
let signature = try container.decode(Signature.self, forKey: .sig)
|
||||
|
||||
guard let note = NdbNote.init(content: content, author: pubkey, kind: kind, tags: tags, createdAt: createdAt, id: noteId, sig: signature) else {
|
||||
let signature = try? container.decode(Signature.self, forKey: .sig)
|
||||
|
||||
guard let note = NdbNote.init(content: content, author: pubkey, kind: kind, tags: tags, createdAt: createdAt, id: noteId, sig: signature ?? Signature(Data(repeating: 0, count: 128))) else {
|
||||
throw DecodingError.initializationFailed
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ extension NdbNote {
|
||||
}
|
||||
|
||||
func get_content(_ keypair: Keypair) -> String {
|
||||
if known_kind == .dm {
|
||||
if known_kind == .deprecated_dm {
|
||||
return decrypted(keypair: keypair) ?? "*failed to decrypt content*"
|
||||
}
|
||||
else if known_kind == .highlight {
|
||||
@@ -467,7 +467,7 @@ extension NdbNote {
|
||||
}
|
||||
|
||||
func maybe_get_content(_ keypair: Keypair) -> String? {
|
||||
if known_kind == .dm {
|
||||
if known_kind == .deprecated_dm {
|
||||
return decrypted(keypair: keypair)
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -366,6 +366,7 @@ int ndb_ws_event_from_json(const char *json, int len, struct ndb_tce *tce, unsig
|
||||
int ndb_note_from_json(const char *json, int len, struct ndb_note **, unsigned char *buf, int buflen);
|
||||
int ndb_builder_init(struct ndb_builder *builder, unsigned char *buf, int bufsize);
|
||||
int ndb_builder_finalize(struct ndb_builder *builder, struct ndb_note **note, struct ndb_keypair *privkey);
|
||||
int ndb_builder_finalize_just_pubkey(struct ndb_builder *builder, struct ndb_note **note, unsigned char pubkey[32]);
|
||||
int ndb_builder_set_content(struct ndb_builder *builder, const char *content, int len);
|
||||
void ndb_builder_set_created_at(struct ndb_builder *builder, uint64_t created_at);
|
||||
void ndb_builder_set_sig(struct ndb_builder *builder, unsigned char *sig);
|
||||
|
||||
Reference in New Issue
Block a user