bech32encoding

package
v1.9.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2025 License: Unlicense Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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       = 64
	Bech32HRPLen    = 4
)
View Source
const (
	TLVDefault byte = iota
	TLVRelay
	TLVAuthor
	TLVKind
)

Variables

View Source
var (
	SecHRP = []byte("nsec")
	PubHRP = []byte("npub")
)
View Source
var (
	NoteHRP     = []byte("note")
	NsecHRP     = []byte("nsec")
	NpubHRP     = []byte("npub")
	NprofileHRP = []byte("nprofile")
	NeventHRP   = []byte("nevent")
	NentityHRP  = []byte("naddr")
)

Functions

func BinToNpub

func BinToNpub(b []byte) (s []byte, err error)

func BinToNsec

func BinToNsec(sk []byte) (nsec []byte, err error)

BinToNsec converts a binary secret key to a bech32 encoded nsec.

func ConvertForBech32

func ConvertForBech32(b8 []byte) (b5 []byte, err error)

ConvertForBech32 performs the bit expansion required for encoding into Bech32.

func ConvertFromBech32

func ConvertFromBech32(b5 []byte) (b8 []byte, err error)

ConvertFromBech32 collapses together the bit expanded 5 bit numbers encoded in bech32.

func Decode

func Decode(bech32string []byte) (prefix []byte, value any, err error)

func DecodeToString

func DecodeToString(bech32String []byte) (prefix, value []byte, err error)

func EncodeEntity

func EncodeEntity(pk []byte, k *kind.T, id []byte, relays [][]byte) (s []byte, err error)

func EncodeEvent

func EncodeEvent(eventIDHex *eventid.T, relays [][]byte, author []byte) (s []byte, err error)

func EncodeNote

func EncodeNote(eventIDHex []byte) (s []byte, err error)

func EncodeProfile

func EncodeProfile(publicKeyHex []byte, relays [][]byte) (s []byte, err error)

func HexToNpub

func HexToNpub(publicKeyHex []byte) (s []byte, err error)

func HexToNsec

func HexToNsec(sk []byte) (nsec []byte, err error)

HexToNsec converts a hex encoded secret key to a bech32 encoded nsec.

func HexToPublicKey

func HexToPublicKey(pk string) (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(sk []byte) (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 NpubToBytes added in v1.7.11

func NpubToBytes(encoded []byte) (pk []byte, err error)

func NpubToPublicKey

func NpubToPublicKey(encoded []byte) (pk *secp256k1.PublicKey, err error)

NpubToPublicKey decodes an nostr public key (npub) and returns an secp256k1 public key.

func NsecToBytes added in v1.7.11

func NsecToBytes(encoded []byte) (sk []byte, err error)

func NsecToHex

func NsecToHex(nsec []byte) (hexSec []byte, err error)

func NsecToSecretKey

func NsecToSecretKey(encoded []byte) (sk *secp256k1.SecretKey, err error)

NsecToSecretKey decodes a nostr secret key (nsec) and returns the secp256k1 secret key.

func PublicKeyToNpub

func PublicKeyToNpub(pk *secp256k1.PublicKey) (encoded []byte, err error)

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.

func SecretKeyToNsec

func SecretKeyToNsec(sk *secp256k1.SecretKey) (encoded []byte, err error)

SecretKeyToNsec encodes an secp256k1 secret key as a Bech32 string (nsec).

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL