ctype

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

util package to handle various types and hex string, bytes etc

Index

Constants

View Source
const (
	EthTokenAddrStr     = "0000000000000000000000000000000000000000"
	InvalidTokenAddrStr = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
)

Variables

View Source
var (
	// ZeroAddr is all 0s
	ZeroAddr Addr
	// EthTokenAddr is all 0s
	EthTokenAddr = Hex2Addr(EthTokenAddrStr)
	// InvalidTokenAddr is all Fs
	InvalidTokenAddr = Hex2Addr(InvalidTokenAddrStr)

	// ZeroPayID is all 0s
	ZeroPayID PayIDType
	// ZeroPayIDHex is string of 32 0s
	ZeroPayIDHex = PayID2Hex(ZeroPayID)
	// ZeroBigInt is big.NewInt(0)
	ZeroBigInt = big.NewInt(0)
	// ZeroCid is all 0s
	ZeroCid CidType
)

Functions

func Addr2Hex

func Addr2Hex(a Addr) string

Addr2Hex returns hex without 0x

func Bytes2Hex

func Bytes2Hex(b []byte) string

Bytes2Hex returns hex string without 0x prefix

func Cid2Hex

func Cid2Hex(p CidType) string

Cid2Hex returns hex without 0x prefix

func Hex2Bytes

func Hex2Bytes(s string) (b []byte)

Hex2Bytes supports hex string with or without 0x prefix Calls hex.DecodeString directly and ignore err similar to ec.FromHex but better

func PayID2Hex

func PayID2Hex(p PayIDType) string

PayID2Hex returns hex without 0x prefix

func ToOnChainSig added in v1.1.0

func ToOnChainSig(b []byte) []byte

ToOnChainSig returns a copy of b with v adjusted to 27/28 for contract recovery.

Types

type Addr

type Addr = ec.Address

Addr is alias to geth common.Address

func Bytes2Addr

func Bytes2Addr(b []byte) Addr

Bytes2Addr returns Address from b Addr.Bytes() does the reverse

func Hex2Addr

func Hex2Addr(s string) Addr

Hex2Addr accepts hex string with or without 0x prefix and return Addr

type CidType

type CidType = ec.Hash

CidType is the type for payment channel ID Note we need to change all cid.Hex() to Cid2Hex() because Hash.Hex() has 0x prefix

func Bytes2Cid

func Bytes2Cid(b []byte) CidType

Bytes2Cid converts bytes to CidType

func Hex2Cid

func Hex2Cid(s string) CidType

Hex2Cid accepts hex string with or without 0x prefix and return CidType

type Hash

type Hash = ec.Hash

func Hex2Hash

func Hex2Hash(s string) Hash

========= Hash ==========

type PayIDType

type PayIDType = ec.Hash

PayIDType is the ID type for pays

func Bytes2PayID

func Bytes2PayID(b []byte) PayIDType

Bytes2PayID converts bytes to PayIDType type

func Hex2PayID

func Hex2PayID(s string) PayIDType

Hex2PayID accepts hex string with or without 0x prefix and return PayIDType

func Pay2PayID

func Pay2PayID(pay *entity.ConditionalPay) PayIDType

Pay2PayID converts structured pay data to PayID

func PayBytes2PayID

func PayBytes2PayID(payBytes []byte) PayIDType

PayBytes2PayID converts marshaled pay bytes to PayID

type Sig

type Sig [sigLength]byte

Sig is r,s,v

var ZeroSig Sig

ZeroSig is all 0, indicate invalid Sig

func Bytes2Sig

func Bytes2Sig(b []byte) Sig

Bytes2Sig create a new Sig based on b's content if len(b) isn't 65, return ZeroSig

func (Sig) Bytes

func (s Sig) Bytes() []byte

Bytes returns a new byte slice from s content

func (Sig) Hex

func (s Sig) Hex() string

Hex returns hex string w/o 0x prefix

Jump to

Keyboard shortcuts

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