crypto

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 19 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBLSSignature = errors.New("invalid BLS Signature")
)
View Source
var S256 = btcec.S256()

S256 is the secp256k1 elliptic curve

Functions

func BLSSecretKeyToPubkeyBytes added in v0.6.0

func BLSSecretKeyToPubkeyBytes(key *bls_sig.SecretKey) ([]byte, error)

BLSSecretKeyToPubkeyBytes returns bytes of BLS Public Key corresponding to the given secret key

func BytesToBLSPublicKey added in v0.6.0

func BytesToBLSPublicKey(input string) (*bls_sig.PublicKey, error)

BytesToBLSPublicKey decodes given hex string and returns BLS Public Key

func BytesToBLSSecretKey added in v0.6.0

func BytesToBLSSecretKey(input []byte) (*bls_sig.SecretKey, error)

BytesToECDSAPrivateKey reads the input byte array and constructs a private key if possible

func BytesToECDSAPrivateKey added in v0.6.0

func BytesToECDSAPrivateKey(input []byte) (*ecdsa.PrivateKey, error)

BytesToECDSAPrivateKey reads the input byte array and constructs a private key if possible

func CreateAddress

func CreateAddress(addr types.Address, nonce uint64) types.Address

CreateAddress creates an Ethereum address.

func CreateAddress2

func CreateAddress2(addr types.Address, salt [32]byte, inithash []byte) types.Address

CreateAddress2 creates an Ethereum address following the CREATE2 Opcode.

func Ecrecover

func Ecrecover(hash, sig []byte) ([]byte, error)

func GenerateAndEncodeBLSSecretKey added in v0.6.0

func GenerateAndEncodeBLSSecretKey() (*bls_sig.SecretKey, []byte, error)

func GenerateAndEncodeECDSAPrivateKey added in v0.6.0

func GenerateAndEncodeECDSAPrivateKey() (*ecdsa.PrivateKey, []byte, error)

GenerateAndEncodeECDSAPrivateKey returns a newly generated private key and the Base64 encoding of that private key

func GenerateBLSKey added in v0.6.0

func GenerateBLSKey() (*bls_sig.SecretKey, error)

GenerateBLSKey generates a new BLS key

func GenerateECDSAKey added in v0.6.0

func GenerateECDSAKey() (*ecdsa.PrivateKey, error)

GenerateECDSAKey generates a new key based on the secp256k1 elliptic curve.

func GenerateOrReadPrivateKey

func GenerateOrReadPrivateKey(path string) (*ecdsa.PrivateKey, error)

GenerateOrReadPrivateKey generates a private key at the specified path, or reads it if a key file is present

func GetAddressFromKey added in v0.3.0

func GetAddressFromKey(key goCrypto.PrivateKey) (types.Address, error)

GetAddressFromKey extracts an address from the private key

func Keccak256

func Keccak256(v ...[]byte) []byte

Keccak256 calculates the Keccak256

func MarshalECDSAPrivateKey added in v0.6.0

func MarshalECDSAPrivateKey(priv *ecdsa.PrivateKey) ([]byte, error)

MarshalECDSAPrivateKey serializes the private key's D value to a []byte

func MarshalPublicKey

func MarshalPublicKey(pub *ecdsa.PublicKey) []byte

MarshalPublicKey marshals a public key on the secp256k1 elliptic curve.

func ParseECDSAPrivateKey added in v0.6.0

func ParseECDSAPrivateKey(buf []byte) (*ecdsa.PrivateKey, error)

func ParsePublicKey

func ParsePublicKey(buf []byte) (*ecdsa.PublicKey, error)

ParsePublicKey parses bytes into a public key on the secp256k1 elliptic curve.

func PubKeyToAddress

func PubKeyToAddress(pub *ecdsa.PublicKey) types.Address

PubKeyToAddress returns the Ethereum address of a public key

func ReadConsensusKey

func ReadConsensusKey(manager secrets.SecretsManager) (*ecdsa.PrivateKey, error)

func RecoverPubkey

func RecoverPubkey(signature, hash []byte) (*ecdsa.PublicKey, error)

RecoverPubkey verifies the compact signature "signature" of "hash" for the secp256k1 curve.

func SigToPub

func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

SigToPub returns the public key that created the given signature.

func Sign

func Sign(priv *ecdsa.PrivateKey, hash []byte) ([]byte, error)

Sign produces a compact signature of the data in hash with the given private key on the secp256k1 curve.

func SignByBLS added in v0.6.0

func SignByBLS(prv *bls_sig.SecretKey, msg []byte) ([]byte, error)

SignByBLS signs the given data by BLS

func UnmarshalBLSPublicKey added in v0.6.0

func UnmarshalBLSPublicKey(input []byte) (*bls_sig.PublicKey, error)

UnmarshalBLSPublicKey unmarshal bytes data into BLS Public Key

func UnmarshalBLSSignature added in v0.6.0

func UnmarshalBLSSignature(input []byte) (*bls_sig.Signature, error)

UnmarshalBLSSignature unmarshal bytes data into BLS Signature

func ValidateSignatureValues

func ValidateSignatureValues(v byte, r, s *big.Int) bool

ValidateSignatureValues checks if the signature values are correct

func VerifyBLSSignature added in v0.6.0

func VerifyBLSSignature(pubkey *bls_sig.PublicKey, sig *bls_sig.Signature, message []byte) error

VerifyBLSSignature verifies the given signature from Public Key and original message

func VerifyBLSSignatureFromBytes added in v0.6.0

func VerifyBLSSignatureFromBytes(rawPubkey, rawSig, message []byte) error

VerifyBLSSignatureFromBytes verifies BLS Signature from BLS PublicKey, signature, and original message in bytes

Types

type EIP155Signer

type EIP155Signer struct {
	// contains filtered or unexported fields
}

func NewEIP155Signer

func NewEIP155Signer(chainID uint64) *EIP155Signer

NewEIP155Signer returns a new EIP155Signer object

func (*EIP155Signer) CalculateV

func (e *EIP155Signer) CalculateV(parity byte) []byte

calculateV returns the V value for transaction signatures. Based on EIP155

func (*EIP155Signer) Hash

func (e *EIP155Signer) Hash(tx *types.Transaction) types.Hash

Hash is a wrapper function that calls calcTxHash with the EIP155Signer's chainID

func (*EIP155Signer) Sender

func (e *EIP155Signer) Sender(tx *types.Transaction) (types.Address, error)

Sender returns the transaction sender

func (*EIP155Signer) SignTx

func (e *EIP155Signer) SignTx(
	tx *types.Transaction,
	privateKey *ecdsa.PrivateKey,
) (*types.Transaction, error)

SignTx signs the transaction using the passed in private key

type FrontierSigner

type FrontierSigner struct {
}

func (*FrontierSigner) CalculateV

func (f *FrontierSigner) CalculateV(parity byte) []byte

calculateV returns the V value for transactions pre EIP155

func (*FrontierSigner) Hash

func (f *FrontierSigner) Hash(tx *types.Transaction) types.Hash

Hash is a wrapper function for the calcTxHash, with chainID 0

func (*FrontierSigner) Sender

func (f *FrontierSigner) Sender(tx *types.Transaction) (types.Address, error)

Sender decodes the signature and returns the sender of the transaction

func (*FrontierSigner) SignTx

func (f *FrontierSigner) SignTx(
	tx *types.Transaction,
	privateKey *ecdsa.PrivateKey,
) (*types.Transaction, error)

SignTx signs the transaction using the passed in private key

type KeyType added in v0.6.0

type KeyType string
const (
	KeyECDSA KeyType = "ecdsa"
	KeyBLS   KeyType = "bls"
)

type TxSigner

type TxSigner interface {
	// Hash returns the hash of the transaction
	Hash(tx *types.Transaction) types.Hash

	// Sender returns the sender of the transaction
	Sender(tx *types.Transaction) (types.Address, error)

	// SignTx signs a transaction
	SignTx(tx *types.Transaction, priv *ecdsa.PrivateKey) (*types.Transaction, error)

	// CalculateV calculates the V value based on the type of signer used
	CalculateV(parity byte) []byte
}

TxSigner is a utility interface used to recover data from a transaction

func NewSigner

func NewSigner(forks chain.ForksInTime, chainID uint64) TxSigner

NewSigner creates a new signer object (EIP155 or FrontierSigner)

Jump to

Keyboard shortcuts

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