utils

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSignature

func CheckSignature(hash, signature []byte, voters []common.Address) (common.Address, error)

CheckSignature recovers the signer address and optionally verifies it is in the allowed voter list.

func ConstantSlice

func ConstantSlice[T any](val T, n int) []T

ConstantSlice crates a slice of length n with all the entries equal to val.

func ECDSAPrivKeyToECIES

func ECDSAPrivKeyToECIES(privKey *ecdsa.PrivateKey) (*ecies.PrivateKey, error)

func ECDSAPubKeyToECIES

func ECDSAPubKeyToECIES(pubKey *ecdsa.PublicKey) (*ecies.PublicKey, error)

func ParsePubKeys

func ParsePubKeys(pubKeys []wallet.PublicKey) ([]*ecdsa.PublicKey, error)

ParsePubKeys converts the wallet public key structures to ECDSA keys.

func PubKeysToAddresses

func PubKeysToAddresses(pubKeys []types.PublicKey) ([]common.Address, error)

PubKeysToAddresses returns the Ethereum addresses derived from the keys.

func Sign

func Sign(msgHash []byte, privKey *ecdsa.PrivateKey) ([]byte, error)

Sign signs the provided hash with the given private key.

func SignatureToSignersAddress

func SignatureToSignersAddress(hash, signature []byte) (common.Address, error)

SignatureToSignersAddress recovers the Ethereum address associated with the signature of the given hash.

func Sum

func Sum[T Number](numbers []T) T

Sum calculates the sum of elements in a slice.

func ToHash

func ToHash(s string) common.Hash

ToHash returns Solidity's bytes32(s) ([]byte(s) appended with zeros to length 32) String s can be at most 32 characters long, otherwise it is cut.

func VerifySignature

func VerifySignature(hash, signature []byte, signerAddress common.Address) error

VerifySignature ensures the signature matches the expected signer.

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Jump to

Keyboard shortcuts

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