nostrdb/parser: fix bech32 block decoding

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2023-12-28 16:11:29 -08:00
committed by Daniel D’Aquino
parent 4cfe28d802
commit dfa145dd4a
5 changed files with 110 additions and 85 deletions

View File

@@ -10,72 +10,8 @@
#include <stdio.h>
#include "str_block.h"
#include "nostrdb.h"
#include "cursor.h"
#define MAX_RELAYS 24
struct relays {
struct ndb_str_block relays[MAX_RELAYS];
int num_relays;
};
enum nostr_bech32_type {
NOSTR_BECH32_NOTE = 1,
NOSTR_BECH32_NPUB = 2,
NOSTR_BECH32_NPROFILE = 3,
NOSTR_BECH32_NEVENT = 4,
NOSTR_BECH32_NRELAY = 5,
NOSTR_BECH32_NADDR = 6,
NOSTR_BECH32_NSEC = 7,
};
#define NOSTR_BECH32_KNOWN_TYPES 7
struct bech32_note {
const unsigned char *event_id;
};
struct bech32_npub {
const unsigned char *pubkey;
};
struct bech32_nsec {
const unsigned char *nsec;
};
struct bech32_nevent {
struct relays relays;
const unsigned char *event_id;
const unsigned char *pubkey; // optional
};
struct bech32_nprofile {
struct relays relays;
const unsigned char *pubkey;
};
struct bech32_naddr {
struct relays relays;
struct ndb_str_block identifier;
const unsigned char *pubkey;
};
struct bech32_nrelay {
struct ndb_str_block relay;
};
struct nostr_bech32 {
enum nostr_bech32_type type;
union {
struct bech32_note note;
struct bech32_npub npub;
struct bech32_nsec nsec;
struct bech32_nevent nevent;
struct bech32_nprofile nprofile;
struct bech32_naddr naddr;
struct bech32_nrelay nrelay;
};
};
int parse_nostr_bech32_str(struct cursor *bech32, enum nostr_bech32_type *type);
int parse_nostr_bech32_type(const char *prefix, enum nostr_bech32_type *type);