utils

package
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressToBytes32 added in v0.0.42

func AddressToBytes32(chain, addr string) (ethcommon.Hash, error)

AddressToBytes32 encodes a native chain address into the 32-byte form used as an opaque key by contracts that must hold both EVM (20-byte) and SVM (32-byte) addresses — e.g. UniversalCore's PC20 wrapper mappings (setWrapperDeployed / getPC20Source), where the wrapper lives on either an EVM or a Solana chain. uv sends the wrapper in each chain's native format (EVM hex / SVM base58), the same convention as an inbound asset_addr, and the chain owns this encoding.

It validates the address against the chain's CAIP-2 namespace and errors on a malformed value or one that does not match the chain:

  • eip155: a valid 20-byte hex address → right-aligned into the low 20 bytes, matching Solidity's bytes32(uint160(addr)).
  • solana: base58 (or 0x-hex) decoding to exactly 32 bytes → the raw 32 bytes.

The mapping is deterministic, so the same address yields the same bytes32 whether it arrives on the outbound finalize observation (setWrapperDeployed) or the return inbound (getPC20Source) — which is what makes the reverse lookup hit.

func CAIP2Namespace added in v0.0.40

func CAIP2Namespace(chain string) string

CAIP2Namespace returns the namespace component of a CAIP-2 chain id ("eip155:1" → "eip155"). Returns "" when the id has no namespace.

func CanonicalizeAddressByNamespace added in v0.0.40

func CanonicalizeAddressByNamespace(chain, addr string) (string, error)

CanonicalizeAddressByNamespace canonicalizes an address for the given CAIP-2 chain. Empty input passes through (optional fields).

func CanonicalizeEVMAddress added in v0.0.40

func CanonicalizeEVMAddress(s string) (string, error)

CanonicalizeEVMAddress validates s as a 20-byte hex address (with or without 0x) and returns the EIP-55 checksummed, 0x-prefixed form.

func CanonicalizeEVMHash added in v0.0.40

func CanonicalizeEVMHash(s string) (string, error)

CanonicalizeEVMHash validates s as a 32-byte hex hash (with or without 0x) and returns the 0x-prefixed lowercase form.

func CanonicalizeHexBlob added in v0.0.40

func CanonicalizeHexBlob(s string) string

CanonicalizeHexBlob lenient-canonicalizes free-length hex payloads (raw_payload, verification_data): valid hex (with or without 0x, even length) → 0x-prefixed lowercase; anything else is returned trimmed as-is.

func CanonicalizeTxHashByNamespace added in v0.0.40

func CanonicalizeTxHashByNamespace(chain, txHash string) (string, error)

CanonicalizeTxHashByNamespace canonicalizes a transaction hash/signature for the given CAIP-2 chain. Empty input passes through (e.g. failed outbound observations carry no hash).

func ConvertAnyAddressToBytes

func ConvertAnyAddressToBytes(addr string) ([]byte, error)

convert the 0x and/or cosmos address to raw bytes

func ConvertAnyAddressesToBytes

func ConvertAnyAddressesToBytes[T ByteType](addr ...string) ([]T, error)

return either []byte or common.Address

func ExtractEvmChainID added in v0.0.13

func ExtractEvmChainID(chainID string) (string, error)

Returns evm chainId, e.g. push-chain-42101 -> 42101

func GetAddressPair

func GetAddressPair(addr string) (sdk.AccAddress, common.Address, error)

get address pair returns both the cosmos and the 0x addresses, or an error

func GetEnvRPCOverride

func GetEnvRPCOverride(chain string) string

chain is a CAIP-2 chain identifier, e.g., "eip155:1"

func HexToBytes

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

func IsValidAddress

func IsValidAddress(addr string, at AddressType) bool

IsValidAddress checks if the address is a valid COSMOS, HEX (0x), or EITHER address

func LenientCanonicalizeAddress added in v0.0.40

func LenientCanonicalizeAddress(chain, addr string) string

LenientCanonicalizeAddress canonicalizes addr for chain, falling back to the trimmed input when it does not parse.

func LenientCanonicalizeEVMAddress added in v0.0.40

func LenientCanonicalizeEVMAddress(addr string) string

LenientCanonicalizeEVMAddress canonicalizes a Push-Chain (EVM) address to EIP-55, falling back to the trimmed input when it does not parse.

func LenientCanonicalizeTxHash added in v0.0.40

func LenientCanonicalizeTxHash(chain, txHash string) string

LenientCanonicalizeTxHash canonicalizes txHash for chain, falling back to the trimmed input when it does not parse.

func MustConvertCosmosToHex

func MustConvertCosmosToHex(addr string) string

func StringToBigInt

func StringToBigInt(s string) *big.Int

Types

type AddressType

type AddressType int

create an enum for COSMOS, 0x, or EITHER

const (
	COSMOS AddressType = iota
	HEX
	EITHER
)

type ByteType

type ByteType interface {
	[]byte | common.Address
}

Type constraint that allows either []byte or common.Address

Jump to

Keyboard shortcuts

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