bech32encoding

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 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 = B("nsec")
	PubHRP = B("npub")
)
View Source
var (
	NoteHRP     = B("note")
	NsecHRP     = B("nsec")
	NpubHRP     = B("npub")
	NprofileHRP = B("nprofile")
	NeventHRP   = B("nevent")
	NentityHRP  = B("naddr")
)

Functions

func Decode

func Decode(bech32string B) (prefix B, value any, err E)

func DecodeToString

func DecodeToString(bech32String B) (prefix, value B, err E)

func EncodeEntity

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

func EncodeEvent

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

func EncodeNote

func EncodeNote(eventIDHex B) (s B, err E)

func EncodeProfile

func EncodeProfile(publicKeyHex B, relays []B) (s B, err E)

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 B) (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 NpubToPublicKey

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

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

func NsecToSecretKey

func NsecToSecretKey(encoded B) (sk *secp256k1.SecretKey, err error)

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

Types

type B

type B = []byte

func BinToNpub

func BinToNpub(b B) (s B, err error)

func BinToNsec

func BinToNsec(sk B) (nsec B, err error)

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

func ConvertForBech32

func ConvertForBech32(b8 B) (b5 B, err error)

ConvertForBech32 performs the bit expansion required for encoding into Bech32.

func ConvertFromBech32

func ConvertFromBech32(b5 B) (b8 B, err error)

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

func HexToNpub

func HexToNpub(publicKeyHex B) (s B, err error)

func HexToNsec

func HexToNsec(sk B) (nsec B, err error)

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

func NsecToHex

func NsecToHex(nsec B) (hexSec B, err error)

func PublicKeyToNpub

func PublicKeyToNpub(pk *secp256k1.PublicKey) (encoded B, err error)

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

func SecretKeyToHex

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

SecretKeyToHex converts a secret key to the hex encoding.

func SecretKeyToNsec

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

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

type Ctx

type Ctx = context.T

type E

type E = error

type N

type N = int

type S

type S = string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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