damus

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

nostr_bech32.h (1647B)


      1 //
      2 //  nostr_bech32.h
      3 //  damus
      4 //
      5 //  Created by William Casarin on 2023-04-09.
      6 //
      7 
      8 #ifndef nostr_bech32_h
      9 #define nostr_bech32_h
     10 
     11 #include <stdio.h>
     12 #include "str_block.h"
     13 #include "cursor.h"
     14 #include <stdbool.h>
     15 
     16 typedef unsigned char u8;
     17 #define MAX_RELAYS 10
     18 
     19 struct relays {
     20     struct str_block relays[MAX_RELAYS];
     21     int num_relays;
     22 };
     23 
     24 enum nostr_bech32_type {
     25     NOSTR_BECH32_NOTE = 1,
     26     NOSTR_BECH32_NPUB = 2,
     27     NOSTR_BECH32_NPROFILE = 3,
     28     NOSTR_BECH32_NEVENT = 4,
     29     NOSTR_BECH32_NRELAY = 5,
     30     NOSTR_BECH32_NADDR = 6,
     31     NOSTR_BECH32_NSEC = 7,
     32 };
     33 
     34 struct bech32_note {
     35     const u8 *event_id;
     36 };
     37 
     38 struct bech32_npub {
     39     const u8 *pubkey;
     40 };
     41 
     42 struct bech32_nsec {
     43     const u8 *nsec;
     44 };
     45 
     46 struct bech32_nevent {
     47     struct relays relays;
     48     const u8 *event_id;
     49     const u8 *pubkey; // optional
     50     uint32_t kind;
     51     bool has_kind;
     52 };
     53 
     54 struct bech32_nprofile {
     55     struct relays relays;
     56     const u8 *pubkey;
     57 };
     58 
     59 struct bech32_naddr {
     60     struct relays relays;
     61     struct str_block identifier;
     62     const u8 *pubkey;
     63     uint32_t kind;
     64 };
     65 
     66 struct bech32_nrelay {
     67     struct str_block relay;
     68 };
     69 
     70 typedef struct nostr_bech32 {
     71     enum nostr_bech32_type type;
     72     u8 *buffer; // holds strings and tlv stuff
     73     size_t buflen;
     74     
     75     union {
     76         struct bech32_note note;
     77         struct bech32_npub npub;
     78         struct bech32_nsec nsec;
     79         struct bech32_nevent nevent;
     80         struct bech32_nprofile nprofile;
     81         struct bech32_naddr naddr;
     82         struct bech32_nrelay nrelay;
     83     } data;
     84 } nostr_bech32_t;
     85 
     86 
     87 int parse_nostr_bech32(struct cursor *cur, struct nostr_bech32 *obj);
     88 
     89 #endif /* nostr_bech32_h */