crypto

package
v0.4.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: GPL-3.0 Imports: 21 Imported by: 4

Documentation

Index

Constants

View Source
const SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id

Variables

View Source
var (
	UnmarshalPubkey         = unmarshalPubkey
	FromECDSAPub            = fromECDSAPub
	FromECDSA               = fromECDSA
	ValidateSignatureValues = validateSignatureValues
	CreateAddress           = createAddress
	CreateAddress2          = createAddress2
)
View Source
var (
	Ecrecover = ecrecover
	Sign      = sign
)

Functions

func DecodeSignature

func DecodeSignature(sig *Signature) (r, s, v *big.Int)

func DeriveEthChainId

func DeriveEthChainId(v *big.Int) *big.Int

DeriveEthChainId derives the chain id from the given v parameter

func GenerateKeyPair

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

GenerateKeyPair generates a random private/public key pair

func HexToECDSA

func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)

HexToECDSA parses a secp256k1 private key.

func HomesteadSignerSender

func HomesteadSignerSender(signingHash common.Hash, sig *Signature) (common.Address, error)

func Keccak256

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

Keccak256 calculates and returns the Keccak256 hash of the input data.

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (h common.Hash)

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

func PrivKeyToECDSA

func PrivKeyToECDSA(key *PrivateKey) *ecdsa.PrivateKey

PrivKeyToECDSA convert private key to ecdsa.

func PubKeyToECDSA

func PubKeyToECDSA(key *PublicKey) *ecdsa.PublicKey

PubKeyToECDSA convert public key to ecdsa.

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func TEST_GenerateKeyPairWithSeed

func TEST_GenerateKeyPairWithSeed(seed string) (*PrivateKey, *PublicKey, error)

TEST_GenerateKeyPairWithSeed generates a random private/public key pair with the given seed string

func ValidateEthSignature

func ValidateEthSignature(sender common.Address, signingHash common.Hash, sig *Signature) error

Types

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 PrivateKey

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

PrivateKey represents the private key

func ECDSAToPrivKey

func ECDSAToPrivKey(p *ecdsa.PrivateKey) *PrivateKey

ECDSAToPrivKey converts given ecdsa public key to pubkey.

func PrivateKeyFromBytes

func PrivateKeyFromBytes(skBytes common.Bytes) (*PrivateKey, error)

PrivateKeyFromBytes converts the given bytes to a private key

func PrivateKeyFromBytesUnsafe

func PrivateKeyFromBytesUnsafe(skBytes common.Bytes) *PrivateKey

PrivateKeyFromBytesUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).

func PrivateKeyFromFile

func PrivateKeyFromFile(filepath string) (*PrivateKey, error)

PrivateKeyFromFile loads the private key from the given file

func (*PrivateKey) D

func (sk *PrivateKey) D() *big.Int

D returns the D parameter of the ECDSA private key

func (*PrivateKey) PublicKey

func (sk *PrivateKey) PublicKey() *PublicKey

PublicKey returns the public key corresponding to the private key

func (*PrivateKey) SaveToFile

func (sk *PrivateKey) SaveToFile(filepath string) error

SaveToFile saves the private key to the designated file

func (*PrivateKey) Sign

func (sk *PrivateKey) Sign(msg common.Bytes) (*Signature, error)

Sign signs the given message with the private key

func (*PrivateKey) ToBytes

func (sk *PrivateKey) ToBytes() common.Bytes

ToBytes returns the bytes representation of the private key

type PublicKey

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

PublicKey represents the public key

func ECDSAToPubKey

func ECDSAToPubKey(p *ecdsa.PublicKey) *PublicKey

ECDSAToPubKey converts given ecdsa public key to pubkey.

func PublicKeyFromBytes

func PublicKeyFromBytes(pkBytes common.Bytes) (*PublicKey, error)

PublicKeyFromBytes converts the given bytes to a public key

func (*PublicKey) Address

func (pk *PublicKey) Address() common.Address

Address returns the address corresponding to the public key

func (*PublicKey) DecodeRLP

func (pk *PublicKey) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (*PublicKey) EncodeRLP

func (pk *PublicKey) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*PublicKey) IsEmpty

func (pk *PublicKey) IsEmpty() bool

IsEmpty indicates whether the public key is empty

func (*PublicKey) ToBytes

func (pk *PublicKey) ToBytes() common.Bytes

ToBytes returns the bytes representation of the public key

func (*PublicKey) VerifySignature

func (pk *PublicKey) VerifySignature(msg common.Bytes, sig *Signature) bool

VerifySignature verifies the signature with the public key (using ecrecover)

type Signature

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

Signature represents the digital signature

func EncodeSignature

func EncodeSignature(R, S, Vb *big.Int) (*Signature, error)

func SignatureFromBytes

func SignatureFromBytes(sigBytes common.Bytes) (*Signature, error)

SignatureFromBytes converts the given bytes to a signature

func (*Signature) DecodeRLP

func (sig *Signature) DecodeRLP(stream *rlp.Stream) error

DecodeRLP implements RLP Decoder interface.

func (*Signature) EncodeRLP

func (sig *Signature) EncodeRLP(w io.Writer) error

EncodeRLP implements RLP Encoder interface.

func (*Signature) IsEmpty

func (sig *Signature) IsEmpty() bool

IsEmpty indicates whether the signature is empty

func (*Signature) MarshalJSON

func (sig *Signature) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the signature

func (*Signature) RecoverSignerAddress

func (sig *Signature) RecoverSignerAddress(msg common.Bytes) (common.Address, error)

RecoverSignerAddress recovers the address of the signer for the given message

func (*Signature) ToBytes

func (sig *Signature) ToBytes() common.Bytes

ToBytes returns the bytes representation of the signature

func (*Signature) UnmarshalJSON

func (sig *Signature) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON representation of the signature

func (*Signature) Verify

func (sig *Signature) Verify(msg common.Bytes, addr common.Address) bool

Verify verifies the signature with given raw message and address.

Directories

Path Synopsis
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
google
Package bn256 implements a particular bilinear group.
Package bn256 implements a particular bilinear group.
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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