crypto

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllForksEnabled = &Forks{
	Homestead:      NewFork(0),
	EIP150:         NewFork(0),
	EIP155:         NewFork(0),
	EIP158:         NewFork(0),
	Byzantium:      NewFork(0),
	Constantinople: NewFork(0),
	Petersburg:     NewFork(0),
	Istanbul:       NewFork(0),
	London:         NewFork(0),
}
View Source
var (
	ErrInvalidBLSSignature = errors.New("invalid BLS Signature")
)
View Source
var S256 = btcec.S256()

S256 is the secp256k1 elliptic curve

Functions

func Base64Encode

func Base64Encode(b []byte) string

Encode to Base64 string

func BytesToECDSAPrivateKey

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

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

func BytesToEd25519PrivateKey

func BytesToEd25519PrivateKey(input []byte) (ed25519.PrivateKey, error)

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

func CFBDecrypt

func CFBDecrypt(text, MySecret string) (string, error)

CFBDecrypt

func CFBEncrypt

func CFBEncrypt(text, MySecret string) (string, error)

CFBEncrypt

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 Decode

func Decode(s string) []byte

Decode from Base64 string

func Ecrecover

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

func GenerateAndEncodeECDSAPrivateKey

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

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

func GenerateAndEncodeICPIdentitySecretKey

func GenerateAndEncodeICPIdentitySecretKey() (ed25519.PrivateKey, []byte, error)

func GenerateECDSAKey

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

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 Keccak256Hash

func Keccak256Hash(v ...[]byte) (hash types.Hash)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func MarshalECDSAPrivateKey

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

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 ValidateSignatureValues

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

ValidateSignatureValues checks if the signature values are correct

Types

type Fork

type Fork uint64

func NewFork

func NewFork(n uint64) *Fork

func (Fork) Active

func (f Fork) Active(block uint64) bool

func (Fork) Int

func (f Fork) Int() *big.Int

type Forks

type Forks struct {
	Homestead      *Fork `json:"homestead,omitempty"`
	Byzantium      *Fork `json:"byzantium,omitempty"`
	Constantinople *Fork `json:"constantinople,omitempty"`
	Petersburg     *Fork `json:"petersburg,omitempty"`
	Istanbul       *Fork `json:"istanbul,omitempty"`
	London         *Fork `json:"london,omitempty"`
	EIP150         *Fork `json:"EIP150,omitempty"`
	EIP158         *Fork `json:"EIP158,omitempty"`
	EIP155         *Fork `json:"EIP155,omitempty"`
}

Forks specifies when each fork is activated

func (*Forks) At

func (f *Forks) At(block uint64) ForksInTime

func (*Forks) IsByzantium

func (f *Forks) IsByzantium(block uint64) bool

func (*Forks) IsConstantinople

func (f *Forks) IsConstantinople(block uint64) bool

func (*Forks) IsEIP150

func (f *Forks) IsEIP150(block uint64) bool

func (*Forks) IsEIP155

func (f *Forks) IsEIP155(block uint64) bool

func (*Forks) IsEIP158

func (f *Forks) IsEIP158(block uint64) bool

func (*Forks) IsHomestead

func (f *Forks) IsHomestead(block uint64) bool

func (*Forks) IsLondon

func (f *Forks) IsLondon(block uint64) bool

func (*Forks) IsPetersburg

func (f *Forks) IsPetersburg(block uint64) bool

type ForksInTime

type ForksInTime struct {
	Homestead,
	Byzantium,
	Constantinople,
	Petersburg,
	Istanbul,
	London,
	EIP150,
	EIP158,
	EIP155 bool
}

type KeccakState

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.

func NewKeccakState

func NewKeccakState() KeccakState

NewKeccakState creates a new KeccakState

type KeyType

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

Jump to

Keyboard shortcuts

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