utils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 13 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeHexString

func DecodeHexString(input string) ([]byte, error)

DecodeHexString decodes input string into a hex string. Note that if the string is prefixed by 0x , it is trimmed

func EcdsaPrivKeyToSecp256k1PrivKey

func EcdsaPrivKeyToSecp256k1PrivKey(privKey *ecdsa.PrivateKey) *crypto.Secp256k1PrivateKey

EcdsaPrivKeyToSecp256k1PrivKey converts an `ecdsa.PrivateKey` into a libp2p `crypto.Secp256k1PrivateKey“

func EcdsaPubKeyToSecp256k1PublicKey

func EcdsaPubKeyToSecp256k1PublicKey(pubKey *ecdsa.PublicKey) *crypto.Secp256k1PublicKey

EcdsaPubKeyToSecp256k1PublicKey converts an `ecdsa.PublicKey` into a libp2p `crypto.Secp256k1PublicKey“

func EncapsulatePeerID added in v0.8.0

func EncapsulatePeerID(peerID peer.ID, addrs ...multiaddr.Multiaddr) []multiaddr.Multiaddr

EncapsulatePeerID takes a peer.ID and adds a p2p component to all multiaddresses it receives

func GetPeerID added in v0.6.0

func GetPeerID(m multiaddr.Multiaddr) (peer.ID, error)

GetPeerID is used to extract the peerID from a multiaddress

func GetUnixEpoch

func GetUnixEpoch(timesource ...Timesource) *int64

GetUnixEpoch returns the current time in unix timestamp with the integer part representing seconds and the decimal part representing subseconds. Optionally receives a timesource to obtain the time from

func GetUnixEpochFrom

func GetUnixEpochFrom(now time.Time) *int64

GetUnixEpochFrom converts a time into a unix timestamp with nanoseconds

func InitLogger

func InitLogger(encoding string, output string)

InitLogger initializes a global logger using an specific encoding

func IsIPv4 added in v0.7.0

func IsIPv4(str string) bool

IsIPv4 validates if string is a valid IPV4 address

func IsIPv6 added in v0.7.0

func IsIPv6(str string) bool

IsIPv6 validates if string is a valid IPV6 address

func Logger

func Logger() *zap.Logger

Logger creates a zap.Logger with some reasonable defaults

func MessagesLogger added in v0.9.0

func MessagesLogger(prefix string) *zap.Logger

MessagesLogger returns a logger used for debug logging of receivent/sent messages

func MultiAddrSet added in v0.9.0

func MultiAddrSet(addr ...multiaddr.Multiaddr) map[multiaddr.Multiaddr]struct{}

Types

type Timesource

type Timesource interface {
	Now() time.Time
}

Jump to

Keyboard shortcuts

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