utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package utils implements different utilities to be used by production code.

Index

Constants

This section is empty.

Variables

View Source
var ErrIntOverflow = errors.New("overflow in conversion from uint to int")
View Source
var ErrSliceNot32Bytes = errors.New("slice must be 32 bytes long")

Functions

func AddressTo32Slice added in v0.5.0

func AddressTo32Slice(addr common.Address) [32]byte

func AssertHexDecode

func AssertHexDecode(s string) []byte

func BuildLogger

func BuildLogger(options config.LogOptions) (*zap.Logger, *zap.Config, error)

func BuildNamespace added in v0.1.2

func BuildNamespace(privateKey string, nodesAddress string) string

func ClientIPFromContext added in v0.5.0

func ClientIPFromContext(ctx context.Context) string

func DecodeBytes32ToUint64 added in v0.5.0

func DecodeBytes32ToUint64(b [32]byte) uint64

func EcdsaPrivateKeyToString

func EcdsaPrivateKeyToString(key *ecdsa.PrivateKey) string

func EcdsaPublicKeyToAddress

func EcdsaPublicKeyToAddress(key *ecdsa.PublicKey) string

func EcdsaPublicKeyToString

func EcdsaPublicKeyToString(key *ecdsa.PublicKey) string

func EncodeUint64ToBytes32 added in v0.5.0

func EncodeUint64ToBytes32(v uint64) [32]byte

func GenerateEcdsaPrivateKey

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

func GetCredentialsForAddress

func GetCredentialsForAddress(
	isTLS bool,
) (credentials.TransportCredentials, error)

func GetEventSig

func GetEventSig(abi *abi.ABI, eventName string) (string, error)

GetEventSig extracts the event signature from an ABI by event name.

func GetEventTopic

func GetEventTopic(abi *abi.ABI, eventName string) (common.Hash, error)

GetEventTopic extracts the event topic (the hash of the signature) from an ABI by event name.

func HTTPAddressToGRPCTarget added in v0.5.1

func HTTPAddressToGRPCTarget(httpAddress string) (string, bool, error)

HTTPAddressToGRPCTarget maps from a URL, as defined in https://pkg.go.dev/net/url#URL, to a gRPC target, as defined in https://github.com/grpc/grpc/blob/master/doc/naming.md

func HashJWTSignatureInput

func HashJWTSignatureInput(textToSign []byte) []byte

func HashOriginatorSignatureInput

func HashOriginatorSignatureInput(unsignedOriginatorEnvelope []byte) []byte

func HashPayerReportInput added in v0.4.0

func HashPayerReportInput(packedBytes []byte, domainSeparator common.Hash) common.Hash

func HashPayerSignatureInput

func HashPayerSignatureInput(originatorID uint32, unsignedClientEnvelope []byte) []byte

func HexDecode

func HexDecode(s string) ([]byte, error)

func HexEncode

func HexEncode(data []byte) string

func Int32SliceToUint32Slice added in v0.5.0

func Int32SliceToUint32Slice(slice []int32) []uint32

func MinutesSinceEpoch added in v0.3.0

func MinutesSinceEpoch(timestamp time.Time) int32

func MinutesSinceEpochNow added in v0.3.0

func MinutesSinceEpochNow() int32

func NewNullBytes added in v0.5.0

func NewNullBytes(b []byte) []byte

func NewNullInt16 added in v0.5.0

func NewNullInt16[T ~int16 | ~uint16](i *T) sql.NullInt16

func NewNullInt16Slice added in v0.5.0

func NewNullInt16Slice[T ~int16 | ~uint16](ints []T) []int16

func NewNullInt32 added in v0.5.0

func NewNullInt32[T ~int32 | ~uint32](i *T) sql.NullInt32

func NewNullInt64 added in v0.5.0

func NewNullInt64[T ~int64 | ~uint64](i *T) sql.NullInt64

NewNullInt64 is a generic version that accepts both int64 and uint64 types.

func NewNullTime added in v0.5.0

func NewNullTime(ts time.Time) sql.NullTime

func NsToDate added in v0.3.0

func NsToDate(ns int64) time.Time

func PackAndHashNodeIDs added in v0.5.0

func PackAndHashNodeIDs(nodeIDs []uint32) common.Hash

func ParseEcdsaPrivateKey

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

func ParseEcdsaPublicKey

func ParseEcdsaPublicKey(key string) (*ecdsa.PublicKey, error)

ParseEcdsaPublicKey takes the stringified form of an ECDSA public key and return the *ecdsa.PublicKey

func ParseGroupID added in v0.5.0

func ParseGroupID(groupID []byte) ([16]byte, error)

func ParseInboxID added in v0.5.0

func ParseInboxID(inboxID []byte) ([32]byte, error)

func RandomSleep

func RandomSleep(ctx context.Context, maxDuration time.Duration)

func SignClientEnvelope added in v0.1.1

func SignClientEnvelope(
	originatorID uint32,
	unsignedClientEnvelope []byte,
	payerPrivateKey *ecdsa.PrivateKey,
) ([]byte, error)

func SliceToArray32 added in v0.4.0

func SliceToArray32(slice []byte) ([32]byte, error)

func Uint32FromBytes added in v0.5.0

func Uint32FromBytes(b []byte) (uint32, error)

func Uint32SliceToInt32Slice added in v0.5.0

func Uint32SliceToInt32Slice(slice []uint32) ([]int32, error)

func Uint32ToBytes added in v0.5.0

func Uint32ToBytes(u uint32) []byte

func Uint32ToInt32 added in v0.5.0

func Uint32ToInt32(u uint32) (int32, error)

func Uint64ToInt64 added in v0.5.0

func Uint64ToInt64(u uint64) (int64, error)

func Unimplemented

func Unimplemented(message string, unusedVariables ...interface{})

Unimplemented panics with a message indicating that the function is not implemented.

func UnmarshalClientEnvelope

func UnmarshalClientEnvelope(envelope []byte) (*envelopes.ClientEnvelope, error)

func UnmarshalOriginatorEnvelope

func UnmarshalOriginatorEnvelope(envelope []byte) (*envelopes.OriginatorEnvelope, error)

func UnmarshalUnsignedEnvelope

func UnmarshalUnsignedEnvelope(
	unsignedEnvelopeBytes []byte,
) (*envelopes.UnsignedOriginatorEnvelope, error)

func Unused

func Unused(unusedVariables ...interface{})

Unused is a no-op function that takes any number of arguments and does nothing with them. Useful for temporarily silencing "unused variable" warnings in development.

Types

This section is empty.

Directories

Path Synopsis
Package retryerrors implements the retryable error interface.
Package retryerrors implements the retryable error interface.

Jump to

Keyboard shortcuts

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