Documentation ¶
Index ¶
Constants ¶
const ( // PublicCompressedSize defines the number of bytes used to represent a // compressed public key. This consists of a one byte header and the X // coordinate of the uncompressed public key. Each X coordinate maps to // exactly two Y coordinates, the header byte is then used to select the even // or odd component. CompressedPublicSize = 1 + CoordinateSize // HeaderCompressedEven defines the header byte of a compressed public key // indicating that the even Y coordinate should be chosen upon decompression. HeaderCompressedEven byte = 0x02 // HeaderCompressedOdd defines the header byte of a compressed public key // indicating that the odd Y coordinate should be chosen upon decompression. HeaderCompressedOdd byte = 0x03 )
const ( // CoordinateSize defines the number of bytes required to store the X or Y // coordinate of an secp256k1 point. CoordinateSize = 32 // PublicSize defines the number of bytes used to represent a public key, // which consists of an (X, Y) coordinate pair. PublicSize = 2 * CoordinateSize )
const ( // EntropySize defines the number of bytes used to generate a secret key. EntropySize = 32 // SecretSize defines the number of bytes used to represent a secret key, // which is interpreted as a positive scalar coefficient. SecretSize = 32 )
Variables ¶
var ( // ErrInvalidPublicLength indicates an attempt to create a public key using an // invalid number of bytes. ErrInvalidPublicLength = fmt.Errorf("Public key must be %d bytes", PublicSize) // ErrInvalidCompressedPublicLength indicates an attempt to create a // compressed public key using an invalid number of bytes. ErrInvalidCompressedPublicLength = fmt.Errorf("Compressed public key must be %d bytes", CompressedPublicSize) // ErrInvalidSecretLength indicates an attempt to create a secret key using an // invalid number of bytes. ErrInvalidSecretLength = fmt.Errorf("Secret key must be %d bytes", SecretSize) // ErrInvalidHeader indicates that the header byte of a compressed public key // was neither 0x02 or 0x03. ErrInvalidHeader = errors.New("Invalid compressed header byte") // ErrPublicKeyNotOnCurve indicates that the public key's (X, Y) coordinates do // not lie on the secp256k1 curve. ErrPublicKeyNotOnCurve = errors.New("Public key is not on secp256k1 curve") // ErrPointAtInfinity indicates either that the secret key is 0 or the (X, Y) // coordinates of a public key are nil. ErrPointAtInfinity = errors.New("Key pair belongs to the point at infinity") )
var S256 *btcec.KoblitzCurve
Local reference to the btcec secp256k1 curve
Functions ¶
func GenerateKeyPair ¶
GenerateKeyPair creates a random public/private key pair.
func GenerateKeyPairDeterministic ¶
GenerateKeyPairDeterministic computes the public/private keypair for the given entropy.
Types ¶
type CompressedPublicKey ¶
type CompressedPublicKey [CompressedPublicSize]byte
CompressedPublicKey is used for storing public keys persistently.
func NewCompressedPublicKey ¶
func NewCompressedPublicKey(b []byte) (*CompressedPublicKey, error)
func (*CompressedPublicKey) Uncompress ¶
func (cpk *CompressedPublicKey) Uncompress() (*PublicKey, error)
Uncompress computes the public key for a given compressed public key.
type Entropy ¶
type Entropy [EntropySize]byte
Entropy is used for seeding deterministic key generation.
type PublicKey ¶
type PublicKey [PublicSize]byte
PublicKey is used to verify signatures.
func NewPublicKey ¶
func NewPublicKeyCoords ¶
PublicKeyFromCoordinates serializes an (X, Y) coordinate pair into a public key. Returns nil if X or Y are nil.
func (*PublicKey) Compress ¶
func (pk *PublicKey) Compress() *CompressedPublicKey
Compress creates a space efficient representation of a public key to be used for persistent storage.
type SecretKey ¶
type SecretKey [SecretSize]byte
SecretKey is used to sign messages.
func NewSecretKey ¶
func (*SecretKey) PublicKeyCoords ¶
PublicKeyCoords computes the X and Y coordinates of the public key corresponding to the given secret key.