crypto

package
v0.0.0-...-8e081cf Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package crypto provides wrappers functions for cryptographic primitives along with various helper functions

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSignatureLen          = errors.New("invalid signature length")
	ErrInvalidGeneratedSignatureLen = errors.New("generated signature has incorrect length")
	ErrInvalidPubkey                = errors.New("invalid public key")
)

Functions

func ECDSAToHex

func ECDSAToHex(key *ecdsa.PrivateKey) string

func EtherHash

func EtherHash(msg Message) []byte

EtherHash implements the Ethereum hashing standard used to create signatures. Uses an Ethereum specific prefix and the Keccak256 Hashing algorithm

func GenerateKeyPair

func GenerateKeyPair() (pri PrivateKey, pub PublicKey, err error)

GenerateKey generates a Secp256k1 key pair.

func HexToECDSA

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

func PublicKeyToAddress

func PublicKeyToAddress(pub PublicKey) types.WalletAddr

PublicKeyToAddress converts a public key to a wallet address

func RecoverWalletAddress

func RecoverWalletAddress(msg Message, signature Signature, recovery uint8) (wallet types.WalletAddr, err error)

RecoverWalletAddress calculates the WalletAddress of the identity which was used to sign the given message. A value is always returned and needs to verified before it can be trusted.

func Verify

func Verify(pub PublicKey, msg Message, sig Signature) bool

Verify evaluates a Secp256k1 signature to determine if the message provided was signed by the given publics corresponding private key. It returns true if the message was signed by the corresponding keypair, as well as any errors generated in the process

Types

type Message

type Message []byte

type PrivateKey

type PrivateKey *[32]byte

func PrivateKeyFromBytes

func PrivateKeyFromBytes(bytes []byte) (PrivateKey, error)

PrivateKeyFromBytes converts from a byte slice to a PrivateKey Type

type PublicKey

type PublicKey *[65]byte

func PublicKeyFromBytes

func PublicKeyFromBytes(bytes []byte) (PublicKey, error)

PublicKeyFromBytes converts from a byte slice to a PublicKey type

type Signature

type Signature *[64]byte

func Sign

func Sign(privateKey PrivateKey, msg Message) (Signature, uint8, error)

Sign generates a signature for the unhashed message provided.

func SignDigest

func SignDigest(privateKey PrivateKey, digest []byte) (Signature, uint8, error)

SignDigest generates an RFC1363 formatted signature for the provided digest. It returns a signature in IEEE p1363 Format [R||S],the recovery bit and any error encountered

func SignatureFromBytes

func SignatureFromBytes(bytes []byte) (Signature, error)

SignatureFromBytes converts from a byte slice to a Signature type

type SignatureBytes

type SignatureBytes []byte

Jump to

Keyboard shortcuts

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