Skip to content

Commit 97fc415

Browse files
kernelkindjb55
authored andcommitted
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 <[email protected]> Reviewed-by: William Casarin <[email protected]> Signed-off-by: William Casarin <[email protected]>
1 parent d49cf5a commit 97fc415

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

damus-c/nostr_bech32.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
#include "nostr_bech32.h"
99
#include <stdlib.h>
10+
#include "endian.h"
1011
#include "cursor.h"
1112
#include "bech32.h"
13+
#include <stdbool.h>
1214

1315
#define MAX_TLVS 16
1416

@@ -145,6 +147,11 @@ static int tlvs_to_relays(struct nostr_tlvs *tlvs, struct relays *relays) {
145147
return 1;
146148
}
147149

150+
static uint32_t decode_tlv_u32(const uint8_t *bytes) {
151+
beint32_t *be32_bytes = (beint32_t*)bytes;
152+
return be32_to_cpu(*be32_bytes);
153+
}
154+
148155
static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *nevent) {
149156
struct nostr_tlvs tlvs;
150157
struct nostr_tlv *tlv;
@@ -166,6 +173,13 @@ static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *n
166173
nevent->pubkey = NULL;
167174
}
168175

176+
if(find_tlv(&tlvs, TLV_KIND, &tlv)) {
177+
nevent->kind = decode_tlv_u32(tlv->value);
178+
nevent->has_kind = true;
179+
} else {
180+
nevent->has_kind = false;
181+
}
182+
169183
return tlvs_to_relays(&tlvs, &nevent->relays);
170184
}
171185

@@ -187,6 +201,11 @@ static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *nad
187201

188202
naddr->pubkey = tlv->value;
189203

204+
if(!find_tlv(&tlvs, TLV_KIND, &tlv)) {
205+
return 0;
206+
}
207+
naddr->kind = decode_tlv_u32(tlv->value);
208+
190209
return tlvs_to_relays(&tlvs, &naddr->relays);
191210
}
192211

damus-c/nostr_bech32.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <stdio.h>
1212
#include "str_block.h"
1313
#include "cursor.h"
14+
#include <stdbool.h>
15+
1416
typedef unsigned char u8;
1517
#define MAX_RELAYS 10
1618

@@ -45,6 +47,8 @@ struct bech32_nevent {
4547
struct relays relays;
4648
const u8 *event_id;
4749
const u8 *pubkey; // optional
50+
uint32_t kind;
51+
bool has_kind;
4852
};
4953

5054
struct bech32_nprofile {
@@ -56,6 +60,7 @@ struct bech32_naddr {
5660
struct relays relays;
5761
struct str_block identifier;
5862
const u8 *pubkey;
63+
uint32_t kind;
5964
};
6065

6166
struct bech32_nrelay {

0 commit comments

Comments
 (0)