crypto

package
Version: v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressSize = 20
)

Variables

View Source
var ErrBadHashLength = errors.New("wrong block hash length")
View Source
var (
	ErrInvalidLength = errors.New("invalid signature length")
)

Functions

func DecodeSecp256k1PrivateKey

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

DecodeSecp256k1PrivateKey decodes raw ECDSA private key.

func EncodeSecp256k1PrivateKey

func EncodeSecp256k1PrivateKey(k *ecdsa.PrivateKey) []byte

EncodeSecp256k1PrivateKey encodes raw ECDSA private key.

func EncodeSecp256k1PublicKey

func EncodeSecp256k1PublicKey(k *ecdsa.PublicKey) []byte

EncodeSecp256k1PublicKey encodes raw ECDSA public key in a 33-byte compressed format.

func GenerateSecp256k1Key

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

GenerateSecp256k1Key generates an ECDSA private key using secp256k1 elliptic curve.

func LegacyKeccak256

func LegacyKeccak256(data []byte) ([]byte, error)

func NewEthereumAddress

func NewEthereumAddress(p ecdsa.PublicKey) ([]byte, error)

NewEthereumAddress returns a binary representation of ethereum blockchain address. This function is based on github.com/ethereum/go-ethereum/crypto.PubkeyToAddress.

func NewOverlayAddress

func NewOverlayAddress(p ecdsa.PublicKey, networkID uint64, blockHash []byte) (swarm.Address, error)

NewOverlayAddress constructs a Swarm Address from ECDSA public key.

func NewOverlayFromEthereumAddress

func NewOverlayFromEthereumAddress(ethAddr []byte, networkID uint64, blockHash []byte) swarm.Address

NewOverlayFromEthereumAddress constructs a Swarm Address for an Ethereum address.

func Recover

func Recover(signature, data []byte) (*ecdsa.PublicKey, error)

Recover verifies signature with the data base provided. It is using `btcec.RecoverCompact` function.

func RecoverEIP712

func RecoverEIP712(signature []byte, data *eip712.TypedData) (*ecdsa.PublicKey, error)

RecoverEIP712 recovers the public key for eip712 signed data.

func Secp256k1PrivateKeyFromBytes

func Secp256k1PrivateKeyFromBytes(data []byte) *ecdsa.PrivateKey

Secp256k1PrivateKeyFromBytes returns an ECDSA private key based on the byte slice.

Types

type DH

type DH interface {
	SharedKey(public *ecdsa.PublicKey, salt []byte) ([]byte, error)
}

DH is an interface allowing to generate shared keys for public key using a salt from a known private key TODO: implement clef support beside in-memory

func NewDH

func NewDH(key *ecdsa.PrivateKey) DH

NewDH returns an ECDH shared secret key generation seeded with in-memory private key

type RecoverFunc

type RecoverFunc func(signature, data []byte) (*ecdsa.PublicKey, error)

RecoverFunc is a function to recover the public key from a signature

type Signer

type Signer interface {
	// Sign signs data with ethereum prefix (eip191 type 0x45).
	Sign(data []byte) ([]byte, error)
	// SignTx signs an ethereum transaction.
	SignTx(transaction *types.Transaction, chainID *big.Int) (*types.Transaction, error)
	// SignTypedData signs data according to eip712.
	SignTypedData(typedData *eip712.TypedData) ([]byte, error)
	// PublicKey returns the public key this signer uses.
	PublicKey() (*ecdsa.PublicKey, error)
	// EthereumAddress returns the ethereum address this signer uses.
	EthereumAddress() (common.Address, error)
}

func NewDefaultSigner

func NewDefaultSigner(key *ecdsa.PrivateKey) Signer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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