Documentation
¶
Index ¶
- func AddressToBytes32(chain, addr string) (ethcommon.Hash, error)
- func CAIP2Namespace(chain string) string
- func CanonicalizeAddressByNamespace(chain, addr string) (string, error)
- func CanonicalizeEVMAddress(s string) (string, error)
- func CanonicalizeEVMHash(s string) (string, error)
- func CanonicalizeHexBlob(s string) string
- func CanonicalizeTxHashByNamespace(chain, txHash string) (string, error)
- func ConvertAnyAddressToBytes(addr string) ([]byte, error)
- func ConvertAnyAddressesToBytes[T ByteType](addr ...string) ([]T, error)
- func ExtractEvmChainID(chainID string) (string, error)
- func GetAddressPair(addr string) (sdk.AccAddress, common.Address, error)
- func GetEnvRPCOverride(chain string) string
- func HexToBytes(s string) ([]byte, error)
- func IsValidAddress(addr string, at AddressType) bool
- func LenientCanonicalizeAddress(chain, addr string) string
- func LenientCanonicalizeEVMAddress(addr string) string
- func LenientCanonicalizeTxHash(chain, txHash string) string
- func MustConvertCosmosToHex(addr string) string
- func StringToBigInt(s string) *big.Int
- type AddressType
- type ByteType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddressToBytes32 ¶ added in v0.0.42
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
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
CanonicalizeAddressByNamespace canonicalizes an address for the given CAIP-2 chain. Empty input passes through (optional fields).
func CanonicalizeEVMAddress ¶ added in v0.0.40
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
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
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
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 ¶
convert the 0x and/or cosmos address to raw bytes
func ConvertAnyAddressesToBytes ¶
return either []byte or common.Address
func ExtractEvmChainID ¶ added in v0.0.13
Returns evm chainId, e.g. push-chain-42101 -> 42101
func GetAddressPair ¶
GetAddressPair returns both the cosmos and the 0x addresses, or an error.
The address MUST decode to exactly 20 bytes. The Cosmos SDK accepts bech32 account addresses of up to 255 bytes, while common.BytesToAddress silently keeps only the RIGHTMOST 20 bytes. A longer address would therefore collapse onto an unrelated EVM address - e.g. 0x01 || <uexecutor module address> truncates to the uexecutor module itself - so reject it instead of truncating.
func GetEnvRPCOverride ¶
chain is a CAIP-2 chain identifier, e.g., "eip155:1"
func HexToBytes ¶
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
LenientCanonicalizeAddress canonicalizes addr for chain, falling back to the trimmed input when it does not parse.
func LenientCanonicalizeEVMAddress ¶ added in v0.0.40
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
LenientCanonicalizeTxHash canonicalizes txHash for chain, falling back to the trimmed input when it does not parse.
func MustConvertCosmosToHex ¶
MustConvertCosmosToHex returns the 0x form of addr, or an empty string when addr cannot be represented as a 20-byte EVM address.
It never panics and never truncates: the previous common.Address(bz) conversion panicked for inputs shorter than 20 bytes and silently kept the LEFTMOST 20 bytes for longer ones - the opposite end from common.BytesToAddress used elsewhere in this file.
func StringToBigInt ¶
Types ¶
type AddressType ¶
type AddressType int
create an enum for COSMOS, 0x, or EITHER
const ( COSMOS AddressType = iota HEX EITHER )