ecdsa

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeyPair

func GenerateKeyPair() (*PrivateKey, *PublicKey, error)

GenerateKeyPair creates a new random secp256k1 ECDSA private key and corresponding public key

func GenerateKeyPairFromSeed

func GenerateKeyPairFromSeed(seed []byte) (*PrivateKey, *PublicKey, error)

GenerateKeyPairFromSeed creates a deterministic secp256k1 ECDSA private key from a seed

Types

type PrivateKey

type PrivateKey struct {
	D *big.Int
}

PrivateKey represents a secp256k1 ECDSA private key

func NewPrivateKeyFromBytes

func NewPrivateKeyFromBytes(data []byte) (*PrivateKey, error)

NewPrivateKeyFromBytes creates a secp256k1 private key from bytes

func NewPrivateKeyFromHexString

func NewPrivateKeyFromHexString(hexStr string) (*PrivateKey, error)

NewPrivateKeyFromHexString creates a secp256k1 private key from a hex string

func (*PrivateKey) Bytes

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

Bytes serializes the private key to bytes

func (*PrivateKey) DeriveAddress

func (pk *PrivateKey) DeriveAddress() (common.Address, error)

func (*PrivateKey) Public

func (pk *PrivateKey) Public() *PublicKey

Public returns the corresponding public key

func (*PrivateKey) Sign

func (pk *PrivateKey) Sign(hash []byte) (*Signature, error)

Sign signs a 32-byte hash using secp256k1 ECDSA

func (*PrivateKey) SignAndPack

func (pk *PrivateKey) SignAndPack(hash [32]byte) ([]byte, error)

type PublicKey

type PublicKey struct {
	X, Y *big.Int
}

PublicKey represents a secp256k1 ECDSA public key

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(data []byte) (*PublicKey, error)

NewPublicKeyFromBytes creates a secp256k1 public key from bytes

func NewPublicKeyFromHexString

func NewPublicKeyFromHexString(hexStr string) (*PublicKey, error)

NewPublicKeyFromHexString creates a secp256k1 public key from a hex string

func (*PublicKey) Bytes

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

Bytes serializes the public key to bytes (uncompressed format)

type Scheme

type Scheme struct{}

Scheme implements the SigningScheme interface for secp256k1 ECDSA

func NewScheme

func NewScheme() *Scheme

NewScheme creates a new secp256k1 ECDSA signing scheme

func (*Scheme) AggregateSignatures

func (s *Scheme) AggregateSignatures(signatures []signing.Signature) (signing.Signature, error)

AggregateSignatures combines multiple signatures into a single signature ECDSA does not support signature aggregation

func (*Scheme) AggregateVerify

func (s *Scheme) AggregateVerify(publicKeys []signing.PublicKey, messages [][]byte, aggSignature signing.Signature) (bool, error)

AggregateVerify verifies an aggregated signature against multiple public keys and multiple messages ECDSA does not support aggregated verification

func (*Scheme) BatchVerify

func (s *Scheme) BatchVerify(publicKeys []signing.PublicKey, message []byte, signatures []signing.Signature) (bool, error)

BatchVerify verifies multiple signatures in a single batch operation

func (*Scheme) GenerateKeyPair

func (s *Scheme) GenerateKeyPair() (signing.PrivateKey, signing.PublicKey, error)

GenerateKeyPair creates a new random private key and the corresponding public key

func (*Scheme) GenerateKeyPairEIP2333

func (s *Scheme) GenerateKeyPairEIP2333(seed []byte, path []uint32) (signing.PrivateKey, signing.PublicKey, error)

GenerateKeyPairEIP2333 creates a deterministic private key and the corresponding public key using the EIP-2333 standard EIP-2333 is specific to BLS signatures and not applicable to ECDSA

func (*Scheme) GenerateKeyPairFromSeed

func (s *Scheme) GenerateKeyPairFromSeed(seed []byte) (signing.PrivateKey, signing.PublicKey, error)

GenerateKeyPairFromSeed creates a deterministic private key and the corresponding public key from a seed

func (*Scheme) NewPrivateKeyFromBytes

func (s *Scheme) NewPrivateKeyFromBytes(data []byte) (signing.PrivateKey, error)

NewPrivateKeyFromBytes creates a private key from bytes

func (*Scheme) NewPrivateKeyFromHexString

func (s *Scheme) NewPrivateKeyFromHexString(hex string) (signing.PrivateKey, error)

NewPrivateKeyFromHexString creates a private key from a hex string

func (*Scheme) NewPublicKeyFromBytes

func (s *Scheme) NewPublicKeyFromBytes(data []byte) (signing.PublicKey, error)

NewPublicKeyFromBytes creates a public key from bytes

func (*Scheme) NewPublicKeyFromHexString

func (s *Scheme) NewPublicKeyFromHexString(hex string) (signing.PublicKey, error)

NewPublicKeyFromHexString creates a public key from a hex string

func (*Scheme) NewSignatureFromBytes

func (s *Scheme) NewSignatureFromBytes(data []byte) (signing.Signature, error)

NewSignatureFromBytes creates a signature from bytes

type Signature

type Signature struct {
	R, S *big.Int
	V    uint8 // Recovery ID
}

Signature represents an ECDSA signature with recovery ID

func NewSignatureFromBytes

func NewSignatureFromBytes(data []byte) (*Signature, error)

NewSignatureFromBytes creates a signature from bytes

func (*Signature) Bytes

func (sig *Signature) Bytes() []byte

Bytes serializes the signature to bytes (Ethereum format: R + S + V)

func (*Signature) Verify

func (sig *Signature) Verify(publicKey *PublicKey, hash [32]byte) (bool, error)

Verify verifies the signature against a 32-byte hash and public key

func (*Signature) VerifyWithAddress

func (sig *Signature) VerifyWithAddress(hash []byte, expectedAddr common.Address) (bool, error)

VerifyWithAddress verifies the signature by recovering the public key and comparing addresses

Jump to

Keyboard shortcuts

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