Documentation
¶
Overview ¶
Package bech32encoding implements NIP-19 entities, which are bech32 encoded data that describes nostr data types.
These are not just identifiers of events and users, but also include things like relay hints where to find events.
Index ¶
- Constants
- Variables
- func BinToNpub(b []byte) (s []byte, err error)
- func BinToNsec(sk []byte) (nsec []byte, err error)
- func ConvertForBech32(b8 []byte) (b5 []byte, err error)
- func ConvertFromBech32(b5 []byte) (b8 []byte, err error)
- func Decode(bech32string []byte) (prefix []byte, value any, err error)
- func EncodeEntity(pk []byte, k *kind.T, id []byte, relays [][]byte) (s []byte, err error)
- func EncodeEvent(eventIDHex *eventid.T, relays [][]byte, author []byte) (s []byte, err error)
- func EncodeNote(eventIDHex []byte) (s []byte, err error)
- func EncodeProfile(publicKeyHex []byte, relays [][]byte) (s []byte, err error)
- func HexToNpub(publicKeyHex []byte) (s []byte, err error)
- func HexToNsec(sk []byte) (nsec []byte, err error)
- func HexToPublicKey(pk string) (p *btcec.PublicKey, err error)
- func HexToSecretKey(sk []byte) (s *btcec.SecretKey, err error)
- func NpubToBytes(encoded []byte) (pk []byte, err error)
- func NpubToPublicKey(encoded []byte) (pk *secp256k1.PublicKey, err error)
- func NsecToBytes(encoded []byte) (sk []byte, err error)
- func NsecToHex(nsec []byte) (hexSec []byte, err error)
- func NsecToSecretKey(encoded []byte) (sk *secp256k1.SecretKey, err error)
- func PublicKeyToNpub(pk *secp256k1.PublicKey) (encoded []byte, err error)
- func SecretKeyToHex(sk *btcec.SecretKey) (hexSec []byte)
- func SecretKeyToNsec(sk *secp256k1.SecretKey) (encoded []byte, err error)
Constants ¶
const ( // MinKeyStringLen is 56 because Bech32 needs 52 characters plus 4 for the HRP, // any string shorter than this cannot be a nostr key. MinKeyStringLen = 56 // HexKeyLen is the length of a nostr key in hexadecimal. HexKeyLen = 64 // Bech32HRPLen is the length of the standard nostr keys, nsec and npub. Bech32HRPLen = 4 )
Variables ¶
var ( // SecHRP is the standard Human Readable Prefix (HRP) for a nostr secret key in bech32 encoding - nsec SecHRP = []byte("nsec") // PubHRP is the standard Human Readable Prefix (HRP) for a nostr public key in bech32 encoding - nsec PubHRP = []byte("npub") )
var ( // NoteHRP is the Human Readable Prefix (HRP) for a nostr note (kind 1) NoteHRP = []byte("note") // NsecHRP is the Human Readable Prefix (HRP) for a nostr secret key NsecHRP = []byte("nsec") // NpubHRP is the Human Readable Prefix (HRP) for a nostr public key NpubHRP = []byte("npub") // NprofileHRP is the Human Readable Prefix (HRP) for a nostr profile metadata // event (kind 0) NprofileHRP = []byte("nprofile") // NeventHRP is the Human Readable Prefix (HRP) for a nostr event, which may // include relay hints to find the event, and the author's npub. NeventHRP = []byte("nevent") // NentityHRP is the Human Readable Prefix (HRP) for a nostr is a generic nostr // entity, which may include relay hints to find the event, and the author's // npub. NentityHRP = []byte("naddr") )
Functions ¶
func ConvertForBech32 ¶
ConvertForBech32 performs the bit expansion required for encoding into Bech32.
func ConvertFromBech32 ¶
ConvertFromBech32 collapses together the bit expanded 5 bit numbers encoded in bech32.
func Decode ¶
Decode a nostr bech32 encoded entity, return the prefix, and the decoded value, and any error if one occurred in the process of decoding.
func EncodeEntity ¶
EncodeEntity encodes a pubkey, kind, event Id, and relay hints.
func EncodeEvent ¶
EncodeEvent encodes an event, including relay hints and author pubkey.
func EncodeNote ¶
EncodeNote encodes a standard nostr NIP-19 note entity (mostly meaning a nostr kind 1 short text note)
func EncodeProfile ¶
EncodeProfile encodes a pubkey and a set of relays into a bech32 encoded entity.
func HexToNpub ¶
HexToNpub converts a raw 64 character hex encoded public key (as used in standard nostr json events) to a bech32 encoded npub.
func HexToPublicKey ¶
HexToPublicKey decodes a string that should be a 64 character long hex encoded public key into a btcec.PublicKey that can be used to verify a signature or encode to Bech32.
func HexToSecretKey ¶
HexToSecretKey decodes a string that should be a 64 character long hex encoded public key into a btcec.PublicKey that can be used to verify a signature or encode to Bech32.
func NpubToBytes ¶
NpubToBytes converts a bech32 encoded public key to raw bytes.
func NpubToPublicKey ¶
NpubToPublicKey decodes an nostr public key (npub) and returns an secp256k1 public key.
func NsecToBytes ¶
NsecToBytes converts a nostr bech32 encoded secret key to raw bytes.
func NsecToSecretKey ¶
NsecToSecretKey decodes a nostr secret key (nsec) and returns the secp256k1 secret key.
func PublicKeyToNpub ¶
PublicKeyToNpub encodes a public key as a bech32 string (npub).
func SecretKeyToHex ¶
func SecretKeyToHex(sk *btcec.SecretKey) (hexSec []byte)
SecretKeyToHex converts a secret key to the hex encoding.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pointers is a set of basic nip-19 data types for generating bech32 encoded nostr entities.
|
Package pointers is a set of basic nip-19 data types for generating bech32 encoded nostr entities. |
|
Package tlv implements a simple Type Length Value encoder for nostr NIP-19 bech32 encoded entities.
|
Package tlv implements a simple Type Length Value encoder for nostr NIP-19 bech32 encoded entities. |