utils

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCanonicalSignature added in v0.0.23

func CheckCanonicalSignature(signature []byte) error

CheckCanonicalSignature rejects malformed and non-canonical (high-S) [R || S || V] signatures to keep the (data, signature) pair unique.

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 Decrypt added in v0.0.21

func Decrypt(ciphertext []byte, privateKey *ecdsa.PrivateKey) ([]byte, error)

Decrypt ECIES-decrypts ciphertext under the given secp256k1 ECDSA private key.

func ECDSAPrivKeyToECIES

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

ECDSAPrivKeyToECIES converts a secp256k1 ECDSA private key to an ECIES private key.

func ECDSAPubKeyToECIES

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

ECDSAPubKeyToECIES converts a secp256k1 ECDSA public key to an ECIES public key.

func Encrypt added in v0.0.21

func Encrypt(plaintext []byte, publicKey *ecdsa.PublicKey) ([]byte, error)

Encrypt ECIES-encrypts plaintext under the given secp256k1 ECDSA public key.

func HasDuplicateAddresses added in v0.0.20

func HasDuplicateAddresses(addrs []common.Address) bool

HasDuplicateAddresses reports whether addrs contains any address more than once.

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. Non-canonical signatures are rejected.

func Sum

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

Sum calculates the sum of elements in a slice.

func SumUint64 added in v0.0.21

func SumUint64[T constraints.Unsigned](numbers []T) uint64

SumUint64 returns the sum of the slice elements accumulated in uint64. Unlike Sum, which accumulates in the element type and can wrap for narrow types (e.g. a []uint16 whose total exceeds 65535), this widens each element so the total cannot overflow for any realistic input.

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