dostr_nip19 0.1.0
dostr_nip19: ^0.1.0 copied to clipboard
NIP-19 bech32 encoding and decoding for Nostr (npub, nsec, note, nprofile, nevent and naddr).
0.1.0 #
- Initial release, moved out of the
ndkpackage. - The
neventandnaddrmethods onNip01Event(Nip19EventReferences) moved here fromndktoo, so this package depends ondostr_nip01. They return aNeventand anNaddrinstead of a string: callencodefor the string, or readuriandcoordinatedirectly. - A new API replaces the static
Nip19class ofndk. Each entity is a class (Npub,Nsec,Note,Nprofile,NeventandNaddr) that a constructor builds from hex andencodeturns into a string.decodeandtryDecoderead one back, andNip19Entity.decode, on the sealed parent class, reads any of them. The README maps eachndkcall to its replacement. - The decoders ignore whitespace around the input, accept the
nostr:prefix of NIP-21, except before annsec, refuse a string longer than the 5000 characters NIP-19 allows, and throw only aFormatException, whose message never quotes the input. Inndk,Nip19.decodereturned thedtag as hex for annaddrand an empty string for an invalid input, and the other decoders threw anArgumentErroror abech32exception. - The constructors throw an
ArgumentErrorfor a key or id that is not 32 bytes of hex, a relay url or identifier longer than 255 bytes (Nip19Entity.maxTlvValueLength), relays that would make the string longer than 5000 characters, or a kind outside 32 bits, soencodenever makes a string thatdecoderefuses. Inndk,Nip19.encodePubKeyencoded a key of any length, and an identifier over 255 bytes threw a bareException. - Every entity but
NsecextendsNip21Entity, with aurigetter, its NIP-21nostr:URI, andNaddrhas thecoordinateof anatag. - Entities are values, with
==andhashCode. Theirrelaysare an unmodifiable list, empty rather than null, andNsec.toStringhides the private key. naddron a replaceable event (kinds 0, 3 and 10000 to 19999) gives an empty identifier, as NIP-19 asks. Inndk, it needed adtag, returned null for kinds 10000 to 19999, and gave an naddr for kind 41 (NIP-28 channel metadata), which NIP-01 makes regular. It returns null for adtag longer than 255 bytes, which an naddr cannot hold, wherendkthrew.- Removed from
ndk:Nip19.isNip19andnip19regex,isKey,encodeSimplePubKey,convertBits,kNpubLengthandkNoteIdLength,Hrps(each class has aprefixconstant instead), and theNip19Encoder,Nip19Decoder,Nip19Utils,Nip19TLVandInvalidPaddingclasses.