ecdsa

package
v0.50.9 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ECDSA implements Cosmos-SDK compatible ECDSA public and private key. The keys can be serialized.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSNormalized

func IsSNormalized(sigS *big.Int) bool

IsSNormalized returns true for the integer sigS if sigS falls in lower half of the curve order

func NormalizeS

func NormalizeS(sigS *big.Int) *big.Int

NormalizeS will invert the s value if not already in the lower half of curve order value

Types

type PrivKey

type PrivKey struct {
	ecdsa.PrivateKey
}

func GenPrivKey

func GenPrivKey(curve elliptic.Curve) (PrivKey, error)

GenPrivKey generates a new secp256r1 private key. It uses operating system randomness.

func (*PrivKey) Bytes

func (sk *PrivKey) Bytes() []byte

Bytes serialize the private key using big-endian.

func (*PrivKey) MarshalTo

func (sk *PrivKey) MarshalTo(dAtA []byte) (int, error)

MarshalTo implements proto.Marshaler interface.

func (*PrivKey) PubKey

func (sk *PrivKey) PubKey() PubKey

PubKey returns ECDSA public key associated with this private key.

func (*PrivKey) Sign

func (sk *PrivKey) Sign(msg []byte) ([]byte, error)

Sign hashes and signs the message using ECDSA. Implements SDK PrivKey interface. NOTE: this now calls the ecdsa Sign function (not method!) directly as the s value of the signature is needed to low-s normalize the signature value See issue: https://github.com/cosmos/cosmos-sdk/issues/9723 It then raw encodes the signature as two fixed width 32-byte values concatenated, reusing the code copied from secp256k1_nocgo.go

func (*PrivKey) String

func (sk *PrivKey) String(name string) string

String returns a string representation of the public key based on the curveName.

func (*PrivKey) Unmarshal

func (sk *PrivKey) Unmarshal(bz []byte, curve elliptic.Curve, expectedSize int) error

Unmarshal implements proto.Marshaler interface.

type PubKey

type PubKey struct {
	ecdsa.PublicKey
	// contains filtered or unexported fields
}

func (*PubKey) Address

func (pk *PubKey) Address(protoName string) cmtcrypto.Address

Address gets the address associated with a pubkey. If no address exists, it returns a newly created ADR-28 address for ECDSA keys. protoName is a concrete proto structure id.

func (*PubKey) Bytes

func (pk *PubKey) Bytes() []byte

Bytes returns the byte representation of the public key using a compressed form specified in section 4.3.6 of ANSI X9.62 with first byte being the curve type.

func (*PubKey) MarshalTo

func (pk *PubKey) MarshalTo(dAtA []byte) (int, error)

MarshalTo implements proto.Marshaler interface.

func (*PubKey) String

func (pk *PubKey) String(curveName string) string

String returns a string representation of the public key based on the curveName.

func (*PubKey) Unmarshal

func (pk *PubKey) Unmarshal(bz []byte, curve elliptic.Curve, expectedSize int) error

Unmarshal implements proto.Marshaler interface.

func (*PubKey) VerifySignature

func (pk *PubKey) VerifySignature(msg, sig []byte) bool

VerifySignature checks if sig is a valid ECDSA signature for msg. This includes checking for low-s normalized signatures where the s integer component of the signature is in the lower half of the curve order 7/21/21 - expects raw encoded signature (fixed-width 64-bytes, R || S)

Jump to

Keyboard shortcuts

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