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.K, id []byte, relays [][]byte) (s []byte, err error)
- func EncodeEvent(eventIDHex []byte, 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[V constraints.Bytes](publicKeyHex V) (s []byte, err error)
- func HexToNsec[V constraints.Bytes](sk V) (nsec []byte, err error)
- func HexToPublicKey[V constraints.Bytes](pk V) (p *btcec.PublicKey, err error)
- func HexToSecretKey[V constraints.Bytes](sk V) (s *btcec.SecretKey, err error)
- func NpubOrHexToPublicKey[V constraints.Bytes](encoded V) (pk *btcec.PublicKey, err error)
- func NpubOrHexToPublicKeyBinary[V constraints.Bytes](enc V) (pkb []byte, err error)
- func NpubToBytes[V constraints.Bytes](encoded V) (pk []byte, err error)
- func NpubToPublicKey[V constraints.Bytes](encoded V) (pk *secp256k1.PublicKey, err error)
- func NsecToBytes[V constraints.Bytes](encoded V) (sk []byte, err error)
- func NsecToHex[V constraints.Bytes](nsec V) (hexSec []byte, err error)
- func NsecToSecretKey[V constraints.Bytes](encoded V) (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 BinToNpub ¶
BinToNpub converts a raw 32 byte public key to nostr bech32 encoded npub.
func BinToNsec ¶
BinToNsec converts a binary secret key to a bech32 encoded nsec.
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 ¶
func HexToNpub[V constraints.Bytes](publicKeyHex V) (s []byte, err error)
HexToNpub converts a raw 64 character hex encoded public key (as used in standard nostr json events) to a bech32 encoded npub.
func HexToNsec ¶
func HexToNsec[V constraints.Bytes](sk V) (nsec []byte, err error)
HexToNsec converts a hex encoded secret key to a bech32 encoded nsec.
func HexToPublicKey ¶
func HexToPublicKey[V constraints.Bytes](pk V) (p *btcec.PublicKey, err error)
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 ¶
func HexToSecretKey[V constraints.Bytes](sk V) (s *btcec.SecretKey, err error)
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 NpubOrHexToPublicKey ¶
func NpubOrHexToPublicKey[V constraints.Bytes](encoded V) ( pk *btcec.PublicKey, err error, )
func NpubOrHexToPublicKeyBinary ¶
func NpubOrHexToPublicKeyBinary[V constraints.Bytes](enc V) ( pkb []byte, err error, )
func NpubToBytes ¶
func NpubToBytes[V constraints.Bytes](encoded V) (pk []byte, err error)
NpubToBytes converts a bech32 encoded public key to raw bytes.
func NpubToPublicKey ¶
func NpubToPublicKey[V constraints.Bytes](encoded V) ( pk *secp256k1.PublicKey, err error, )
NpubToPublicKey decodes an nostr public key (npub) and returns an secp256k1 public key.
func NsecToBytes ¶
func NsecToBytes[V constraints.Bytes](encoded V) (sk []byte, err error)
NsecToBytes converts a nostr bech32 encoded secret key to raw bytes.
func NsecToHex ¶
func NsecToHex[V constraints.Bytes](nsec V) (hexSec []byte, err error)
NsecToHex converts a bech32 encoded nostr secret key to a raw hexadecimal string.
func NsecToSecretKey ¶
func NsecToSecretKey[V constraints.Bytes](encoded V) ( sk *secp256k1.SecretKey, err error, )
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).
Types ¶
This section is empty.
Source Files
¶
- doc.go
- keys.go
- nip19.go
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. |