@@ -65,6 +65,78 @@ This library implements the following Nostr Implementation Possibilities (NIPs):
6565 - Note IDs (` note ` )
6666 - Profile references (` nprofile ` )
6767 - Event references (` nevent ` )
68+ - Addressable entities (` naddr ` )
69+ - Relay URLs (` nrelay ` )
70+ - Comprehensive validation and error handling
71+ - Support for multiple relay URLs
72+ - TLV (Type-Length-Value) encoding for complex entities
73+
74+ ### NIP-19 Usage Examples
75+
76+ ``` typescript
77+ import {
78+ npubEncode ,
79+ nsecEncode ,
80+ noteEncode ,
81+ nprofileEncode ,
82+ neventEncode ,
83+ naddrEncode ,
84+ nrelayEncode ,
85+ decode
86+ } from ' @humanjavaenterprises/nostr-crypto-utils' ;
87+
88+ // Encode a public key
89+ const npub = npubEncode (' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' );
90+ // npub1xtscya34g58tk0z6v2g0r6w5gpqrxdgkz9xeav
91+
92+ // Encode a private key
93+ const nsec = nsecEncode (' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' );
94+ // nsec1xtscya34g58tk0z6v2g0r6w5gpqrxdgkz9xeav
95+
96+ // Encode a note ID
97+ const note = noteEncode (' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' );
98+ // note1xtscya34g58tk0z6v2g0r6w5gpqrxdgkz9xeav
99+
100+ // Encode a profile with multiple relays
101+ const nprofile = nprofileEncode (
102+ ' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' ,
103+ [' wss://relay1.example.com' , ' wss://relay2.example.com' ]
104+ );
105+
106+ // Encode an event with author and kind
107+ const nevent = neventEncode (
108+ ' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' ,
109+ [' wss://relay.example.com' ],
110+ ' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' ,
111+ 1
112+ );
113+
114+ // Encode an addressable entity (NIP-33)
115+ const naddr = naddrEncode (
116+ ' 7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0' ,
117+ 30023 ,
118+ ' my-article' ,
119+ [' wss://relay.example.com' ]
120+ );
121+
122+ // Encode a relay URL
123+ const nrelay = nrelayEncode (' wss://relay.example.com' );
124+
125+ // Decode any bech32-encoded entity
126+ const decoded = decode (nprofile );
127+ console .log (decoded );
128+ // {
129+ // type: 'nprofile',
130+ // data: '7f3b6c2444c526fc7b3a48b0a1e38fb6a5a4062d4a097c9e96feb3c1df2f36d0',
131+ // relays: ['wss://relay1.example.com', 'wss://relay2.example.com']
132+ // }
133+
134+ // All functions include validation
135+ try {
136+ const invalidNpub = npubEncode (' invalid-hex' );
137+ } catch (error ) {
138+ console .error (error ); // Error: Invalid hex string
139+ }
68140
69141### NIP - 26 Features
70142- Create delegation tokens
0 commit comments