bech32encoding

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Unlicense Imports: 14 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 = by("nsec")
	PubHRP = by("npub")
)
View Source
var (
	NoteHRP     = by("note")
	NsecHRP     = by("nsec")
	NpubHRP     = by("npub")
	NprofileHRP = by("nprofile")
	NeventHRP   = by("nevent")
	NentityHRP  = by("naddr")
)

Functions

func BinToNpub

func BinToNpub(b by) (s by, err er)

func BinToNsec

func BinToNsec(sk by) (nsec by, err er)

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

func ConvertForBech32

func ConvertForBech32(b8 by) (b5 by, err er)

ConvertForBech32 performs the bit expansion required for encoding into Bech32.

func ConvertFromBech32

func ConvertFromBech32(b5 by) (b8 by, err er)

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

func Decode

func Decode(bech32string by) (prefix by, value any, err er)

func DecodeToString

func DecodeToString(bech32String by) (prefix, value by, err er)

func EncodeEntity

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

func EncodeEvent

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

func EncodeNote

func EncodeNote(eventIDHex by) (s by, err er)

func EncodeProfile

func EncodeProfile(publicKeyHex by, relays []by) (s by, err er)

func HexToNpub

func HexToNpub(publicKeyHex by) (s by, err er)

func HexToNsec

func HexToNsec(sk by) (nsec by, err er)

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

func HexToPublicKey

func HexToPublicKey(pk st) (p *btcec.PublicKey, err er)

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 by) (s *btcec.SecretKey, err er)

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 NpubToPublicKey

func NpubToPublicKey(encoded by) (pk *secp256k1.PublicKey, err er)

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

func NsecToHex

func NsecToHex(nsec by) (hexSec by, err er)

func NsecToSecretKey

func NsecToSecretKey(encoded by) (sk *secp256k1.SecretKey, err er)

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

func PublicKeyToNpub

func PublicKeyToNpub(pk *secp256k1.PublicKey) (encoded by, err er)

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

func SecretKeyToHex

func SecretKeyToHex(sk *btcec.SecretKey) (hexSec by)

SecretKeyToHex converts a secret key to the hex encoding.

func SecretKeyToNsec

func SecretKeyToNsec(sk *secp256k1.SecretKey) (encoded by, err er)

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