bech32encoding

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: CC0-1.0, MIT Imports: 13 Imported by: 2

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
	SecHRP          = "nsec"
	PubHRP          = "npub"
)
View Source
const (
	NoteHRP     = "note"
	NsecHRP     = "nsec"
	NpubHRP     = "npub"
	NprofileHRP = "nprofile"
	NeventHRP   = "nevent"
	NentityHRP  = "naddr"
)
View Source
const (
	TLVDefault uint8 = 0
	TLVRelay   uint8 = 1
	TLVAuthor  uint8 = 2
	TLVKind    uint8 = 3
)

Variables

View Source
var EncodePrivateKey = EncodeSecretKey

Functions

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 string) (prefix string, value any, err error)

func DecodeToString

func DecodeToString(bech32String string) (prefix, value string, err error)

func EncodeEntity

func EncodeEntity(publicKey string, kind kind.T, identifier string,
	relays []string) (s string, err error)

func EncodeEvent

func EncodeEvent(eventIDHex string, relays []string,
	author string) (s string, err error)

func EncodeNote

func EncodeNote(eventIDHex string) (s string, err error)

func EncodeProfile

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

func EncodePublicKey added in v1.0.11

func EncodePublicKey(publicKeyHex string) (s string, err error)

func EncodeSecretKey added in v1.0.11

func EncodeSecretKey(privateKeyHex string) (string, error)

func GetPublicKey added in v1.0.11

func GetPublicKey(sk string) (s string, err error)

func HexToPublicKey

func HexToPublicKey(pk string) (p *ec.PublicKey, err error)

HexToPublicKey decodes a string that should be a 64 character long hex encoded public key into a ec.PublicKey that can be used to verify a signature or encode to Bech32.

func HexToSecretKey

func HexToSecretKey(sk string) (s *ec.SecretKey, err error)

HexToSecretKey decodes a string that should be a 64 character long hex encoded public key into a ec.PublicKey that can be used to verify a signature or encode to Bech32.

func NpubToPublicKey

func NpubToPublicKey(encoded string) (pk *secp256k1.PublicKey, err error)

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

func NsecToSecretKey

func NsecToSecretKey(encoded string) (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 string, err error)

PublicKeyToNpub encodes a public kxey as a bech32 string (npub).

func SecretKeyToNsec

func SecretKeyToNsec(sk *secp256k1.SecretKey) (encoded string, err error)

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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