crypto

package
v2.3.0-rc7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: BSD-3-Clause Imports: 16 Imported by: 13

Documentation

Index

Constants

View Source
const (
	AddressSize = 20
)

Variables

View Source
var EDGSecp256_K1 = new(edgSecp256_k1)
View Source
var EDGSecp256_R1 = new(edgSecp256_r1)
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 DecodeSecp256r1PrivateKey

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

DecodeSecp256k1PrivateKey decodes raw ECDSA private key.

func EncodeSecp256k1PrivateKey

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

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 EncodeSecp256r1PrivateKey

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

EncodeSecp256k1PrivateKey encodes raw ECDSA private key.

func GenerateSecp256k1Key

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

GenerateSecp256k1Key generates an ECDSA private key using secp256k1 elliptic curve.

func GenerateSecp256r1Key

func GenerateSecp256r1Key() (*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, nonce []byte) (swarm.Address, error)

NewOverlayAddress constructs a Swarm Address from ECDSA public key.

func NewOverlayFromEthereumAddress

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

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

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