Documentation ¶
Overview ¶
Package crypto provides functionality for interacting with Ed25519 public and private keys. Package crypto uses the "crypto/ed25519" package from Go's standard library for the underlying cryptography.
Index ¶
Constants ¶
const ( PublicKeyLen = ed25519.PublicKeySize PrivateKeyLen = ed25519.PrivateKeySize // PrivateKeySeedLen is defined because ed25519.PrivateKey // is formatted as privateKey = seed|publicKey. We use this const // to extract the publicKey below. PrivateKeySeedLen = ed25519.SeedSize SignatureLen = ed25519.SignatureSize )
Variables ¶
var ( EmptyPublicKey = [ed25519.PublicKeySize]byte{} EmptyPrivateKey = [ed25519.PrivateKeySize]byte{} EmptySignature = [ed25519.SignatureSize]byte{} )
Functions ¶
Types ¶
type PrivateKey ¶
type PrivateKey [ed25519.PrivateKeySize]byte
func GeneratePrivateKey ¶
func GeneratePrivateKey() (PrivateKey, error)
GeneratePrivateKey returns a Ed25519 PrivateKey. It uses the crypto/ed25519 go package to generate the key.
func HexToKey ¶
func HexToKey(key string) (PrivateKey, error)
HexToKey Converts a hexadecimal encoded key into a PrivateKey. Returns an EmptyPrivateKey and error if key is invalid.
func LoadKey ¶
func LoadKey(filename string) (PrivateKey, error)
LoadKey returns a PrivateKey from a file filename. If there is an error reading the file, or the file contains an invalid PrivateKey, LoadKey returns an EmptyPrivateKey and an error.
func (PrivateKey) PublicKey ¶
func (p PrivateKey) PublicKey() PublicKey
PublicKey returns a PublicKey associated with the Ed25519 PrivateKey p. The PublicKey is the last 32 bytes of p.
func (PrivateKey) Save ¶
func (p PrivateKey) Save(filename string) error
Save writes PrivateKey to a file [filename]. If filename does not exist, it creates a new file with read/write permissions (0o600).
func (PrivateKey) ToHex ¶
func (p PrivateKey) ToHex() string
ToHex converts a PrivateKey to a hex string.
type PublicKey ¶
type PublicKey [ed25519.PublicKeySize]byte
func ParseAddress ¶
ParseAddress parses a Bech32 encoded address string and extracts its public key. If there is an error reading the address or the hrp value is not valid, ParseAddress returns an EmptyPublicKey and error.
type Signature ¶
type Signature [ed25519.SignatureSize]byte
func Sign ¶
func Sign(msg []byte, pk PrivateKey) Signature
Sign returns a valid signature for msg using pk.