damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 97fc415b8c0287105e89fea813898d3a1aca2178
parent d49cf5a505a27585529c6824a0f136a73e7e848f
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon,  8 Jan 2024 18:26:49 -0500

nip19: add kind to naddr & nevent

Add support for type KIND for bech32-encoded entities naddr and nevent
as specified in NIP-19.

LNURL1DP68GURN8GHJ7EM9W3SKCCNE9E3K7MF0D3H82UNVWQHKWUN9V4HXGCTHDC6RZVGR8SW3G

Signed-off-by: kernelkind <kernelkind@gmail.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus-c/nostr_bech32.c | 19+++++++++++++++++++
Mdamus-c/nostr_bech32.h | 5+++++
2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/damus-c/nostr_bech32.c b/damus-c/nostr_bech32.c @@ -7,8 +7,10 @@ #include "nostr_bech32.h" #include <stdlib.h> +#include "endian.h" #include "cursor.h" #include "bech32.h" +#include <stdbool.h> #define MAX_TLVS 16 @@ -145,6 +147,11 @@ static int tlvs_to_relays(struct nostr_tlvs *tlvs, struct relays *relays) { return 1; } +static uint32_t decode_tlv_u32(const uint8_t *bytes) { + beint32_t *be32_bytes = (beint32_t*)bytes; + return be32_to_cpu(*be32_bytes); +} + static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *nevent) { struct nostr_tlvs tlvs; struct nostr_tlv *tlv; @@ -166,6 +173,13 @@ static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *n nevent->pubkey = NULL; } + if(find_tlv(&tlvs, TLV_KIND, &tlv)) { + nevent->kind = decode_tlv_u32(tlv->value); + nevent->has_kind = true; + } else { + nevent->has_kind = false; + } + return tlvs_to_relays(&tlvs, &nevent->relays); } @@ -187,6 +201,11 @@ static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *nad naddr->pubkey = tlv->value; + if(!find_tlv(&tlvs, TLV_KIND, &tlv)) { + return 0; + } + naddr->kind = decode_tlv_u32(tlv->value); + return tlvs_to_relays(&tlvs, &naddr->relays); } diff --git a/damus-c/nostr_bech32.h b/damus-c/nostr_bech32.h @@ -11,6 +11,8 @@ #include <stdio.h> #include "str_block.h" #include "cursor.h" +#include <stdbool.h> + typedef unsigned char u8; #define MAX_RELAYS 10 @@ -45,6 +47,8 @@ struct bech32_nevent { struct relays relays; const u8 *event_id; const u8 *pubkey; // optional + uint32_t kind; + bool has_kind; }; struct bech32_nprofile { @@ -56,6 +60,7 @@ struct bech32_naddr { struct relays relays; struct str_block identifier; const u8 *pubkey; + uint32_t kind; }; struct bech32_nrelay {