utils

package
v0.0.0-...-41a254f Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blake2b

func Blake2b(msg []byte) ([]byte, error)

Blake2b computes BLAKE2b hash of the input bytes

func Blake2b256

func Blake2b256(data []byte) (output []byte)

Blake2b256 hashes the input bytes using Blake2b256-256

func Blake2b512

func Blake2b512(msg []byte) ([]byte, error)

Blake2b computes BLAKE2b hash of the input bytes

func Bytes2Bits

func Bytes2Bits(data []byte) []int

func BytesEqual

func BytesEqual(a, b []byte) bool

bytesEqual matches JS 'bytesEqual'

func BytesToHex

func BytesToHex(bytes []byte) string

BytesToHex converts a byte slice to a hex string with a leading 0x

func BytesToString

func BytesToString(typ CodecType, bytes []byte) (string, error)

BytesToString matches JS 'BytesToString'

func ConcatBytes

func ConcatBytes(arrays ...[]byte) ([]byte, error)

ConcatBytes matches JS 'ConcatBytes'

func FromB64

func FromB64(base64String string) ([]byte, error)

FromB64 converts a base64 string to a byte slice

func FromHEX

func FromHEX(input string) []uint8

FromHEX converts a hex string to a byte array.

func GetErrorCategoryName

func GetErrorCategoryName(code ErrorCategory) string

GetErrorCategoryName returns the string representation of an ErrorCategory

func GetHexByteLength

func GetHexByteLength(input string) float64

GetHexByteLength returns the byte length of a hex string.

func Hash160

func Hash160(msg []byte) []byte

Hash160 computes RIPEMD160(SHA256(msg))

func HexTo32Uint8

func HexTo32Uint8(h string) ([32]uint8, error)

func HexTo4Uint8

func HexTo4Uint8(h string) ([4]uint8, error)

func HexToBytes

func HexToBytes(h string) ([]byte, error)

func IsBytes

func IsBytes(a interface{}) bool

IsBytes matches JS 'IsBytes'

func IsHex

func IsHex(input interface{}) bool

IsHex checks if a string is a valid hexadecimal.

func NormalizeHex

func NormalizeHex(input string) string

NormalizeHex removes the "0x" prefix from a hex string if present.

func ParseHex

func ParseHex(hexStr string) ([]byte, error)

ParseHex Convenience function to deal with 0x at the beginning of hex strings

func ParseRoochErrorCode

func ParseRoochErrorCode(errorMessage string) *uint32

ParseRoochErrorCode parses the error code from a Rooch RPC error message

func PrettyJson

func PrettyJson(x any) string

PrettyJson a simple pretty print for JSON examples

func Sha256

func Sha256(msg []byte) []byte

Sha256 computes SHA256 hash of the input bytes

func Sha256Double

func Sha256Double(msgs ...[]byte) ([]byte, error)

Sha256Double computes SHA256(SHA256(concatenated msgs))

func Sha3256

func Sha3256(data []byte) (output []byte)

Sha3256 hashes the input bytes using SHA3-256

func Sha3256Hash

func Sha3256Hash(bytes [][]byte) (output []byte)

SHA3256Hash hashes the input bytes using SHA3-256

func Sha512

func Sha512(msg []byte) []byte

Sha512 computes SHA512 hash of the input bytes

func Str

func Str(typ CodecType, bytes []byte) (string, error)

str matches JS 'str'

func Str2Uint64

func Str2Uint64(str string) (uint64, error)

func StrToBigInt

func StrToBigInt(val string) (num *big.Int, err error)

StrToBigInt converts a string to a big.Int for u128 and u256 values

func StrToUint64

func StrToUint64(s string) (uint64, error)

StrToUint64 converts a string to a uint64

func StringToBytes

func StringToBytes(typ CodecType, str string) ([]byte, error)

StringToBytes matches JS 'StringToBytes'

func TaggedHash

func TaggedHash(tag string, msg []byte) []byte

func ToB64

func ToB64(bytes []byte) string

ToB64 converts a byte slice to a base64 string

func ToHEX

func ToHEX(input []uint8) (string, error)

ToHEX converts a byte array to a hex string.

func ValidateWitness

func ValidateWitness(version int, data []byte) error

validateWitness checks if the witness program is valid according to BIP-0141 rules

func VarintByteNum

func VarintByteNum(input uint64) []byte

VarintByteNum matches JS 'VarintByteNum'

Types

type CodecType

type CodecType string
const (
	UTF8      CodecType = "utf8"
	HEX       CodecType = "hex"
	BASE16    CodecType = "base16"
	BASE32    CodecType = "base32"
	BASE64    CodecType = "base64"
	BASE64URL CodecType = "base64url"
	BASE58    CodecType = "base58"
	BASE58XMR CodecType = "base58xmr"
)

type ErrorCategory

type ErrorCategory uint16

ErrorCategory represents different types of errors with their corresponding codes

const (
	InvalidArgument   ErrorCategory = 0x1 // Caller specified an invalid argument (http: 400)
	OutOfRange        ErrorCategory = 0x2 // An input or result of a computation is out of range (http: 400)
	InvalidState      ErrorCategory = 0x3 // The system is not in a state where the operation can be performed (http: 400)
	Unauthenticated   ErrorCategory = 0x4 // Request not authenticated due to missing, invalid, or expired auth token (http: 401)
	PermissionDenied  ErrorCategory = 0x5 // client does not have sufficient permission (http: 403)
	NotFound          ErrorCategory = 0x6 // A specified resource is not found (http: 404)
	Aborted           ErrorCategory = 0x7 // Concurrency conflict, such as read-modify-write conflict (http: 409)
	AlreadyExists     ErrorCategory = 0x8 // The resource that a client tried to create already exists (http: 409)
	ResourceExhausted ErrorCategory = 0x9 // Out of gas or other forms of quota (http: 429)
	Cancelled         ErrorCategory = 0xa // Request cancelled by the client (http: 499)
	Internal          ErrorCategory = 0xb // Internal error (http: 500)
	NotImplemented    ErrorCategory = 0xc // Feature not implemented (http: 501)
	Unavailable       ErrorCategory = 0xd // The service is currently unavailable. Indicates that a retry could solve the issue (http: 503)
)

type SubStatus

type SubStatus struct {
	Category ErrorCategory
	Reason   uint16
}

SubStatus represents the error category and reason

func ParseRoochErrorSubStatus

func ParseRoochErrorSubStatus(errorMessage string) *SubStatus

ParseRoochErrorSubStatus parses the SubStatus from a Rooch RPC error message

Jump to

Keyboard shortcuts

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