{"modulePath":"github.com/pushchain/push-chain-node","version":"v0.0.49","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\n## Functions\n\n```go\nfunc AddressToBytes32(chain, addr string) (ethcommon.Hash, error)\n```\nAddressToBytes32 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.\n\nIt validates the address against the chain's CAIP-2 namespace and errors on a malformed value or one that does not match the chain:\n\n  - eip155: a valid 20-byte hex address → right-aligned into the low 20 bytes, matching Solidity's bytes32(uint160(addr)).\n  - solana: base58 (or 0x-hex) decoding to exactly 32 bytes → the raw 32 bytes.\n\nThe 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.\n\n```go\nfunc CAIP2Namespace(chain string) string\n```\nCAIP2Namespace returns the namespace component of a CAIP-2 chain id (\"eip155:1\" → \"eip155\"). Returns \"\" when the id has no namespace.\n\n```go\nfunc CanonicalizeAddressByNamespace(chain, addr string) (string, error)\n```\nCanonicalizeAddressByNamespace canonicalizes an address for the given CAIP-2 chain. Empty input passes through (optional fields).\n\n```go\nfunc CanonicalizeEVMAddress(s string) (string, error)\n```\nCanonicalizeEVMAddress validates s as a 20-byte hex address (with or without 0x) and returns the EIP-55 checksummed, 0x-prefixed form.\n\n```go\nfunc CanonicalizeEVMHash(s string) (string, error)\n```\nCanonicalizeEVMHash validates s as a 32-byte hex hash (with or without 0x) and returns the 0x-prefixed lowercase form.\n\n```go\nfunc CanonicalizeHexBlob(s string) string\n```\nCanonicalizeHexBlob 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.\n\n```go\nfunc CanonicalizeTxHashByNamespace(chain, txHash string) (string, error)\n```\nCanonicalizeTxHashByNamespace canonicalizes a transaction hash/signature for the given CAIP-2 chain. Empty input passes through (e.g. failed outbound observations carry no hash).\n\n```go\nfunc ConvertAnyAddressToBytes(addr string) ([]byte, error)\n```\nconvert the 0x and/or cosmos address to raw bytes\n\n```go\nfunc ConvertAnyAddressesToBytes[T ByteType](addr ...string) ([]T, error)\n```\nreturn either \\[]byte or common.Address\n\n```go\nfunc ExtractEvmChainID(chainID string) (string, error)\n```\nReturns evm chainId, e.g. push-chain-42101 -\u003e 42101\n\n```go\nfunc GetAddressPair(addr string) (sdk.AccAddress, common.Address, error)\n```\nGetAddressPair returns both the cosmos and the 0x addresses, or an error.\n\nThe 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 || \\\u003cuexecutor module address\u003e truncates to the uexecutor module itself - so reject it instead of truncating.\n\n```go\nfunc GetEnvRPCOverride(chain string) string\n```\nchain is a CAIP-2 chain identifier, e.g., \"eip155:1\"\n\n```go\nfunc HexToBytes(s string) ([]byte, error)\n```\n\n```go\nfunc IsValidAddress(addr string, at AddressType) bool\n```\nIsValidAddress checks if the address is a valid COSMOS, HEX (0x), or EITHER address\n\n```go\nfunc LenientCanonicalizeAddress(chain, addr string) string\n```\nLenientCanonicalizeAddress canonicalizes addr for chain, falling back to the trimmed input when it does not parse.\n\n```go\nfunc LenientCanonicalizeEVMAddress(addr string) string\n```\nLenientCanonicalizeEVMAddress canonicalizes a Push-Chain (EVM) address to EIP-55, falling back to the trimmed input when it does not parse.\n\n```go\nfunc LenientCanonicalizeTxHash(chain, txHash string) string\n```\nLenientCanonicalizeTxHash canonicalizes txHash for chain, falling back to the trimmed input when it does not parse.\n\n```go\nfunc MustConvertCosmosToHex(addr string) string\n```\nMustConvertCosmosToHex returns the 0x form of addr, or an empty string when addr cannot be represented as a 20-byte EVM address.\n\nIt 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.\n\n```go\nfunc StringToBigInt(s string) *big.Int\n```\n\n## Types\n\n```go\ntype AddressType int\n```\ncreate an enum for COSMOS, 0x, or EITHER\n\n```go\nconst (\n\tCOSMOS AddressType = iota\n\tHEX\n\tEITHER\n)\n```\n\n```go\ntype ByteType interface {\n\t[]byte | common.Address\n}\n```\nType constraint that allows either \\[]byte or common.Address\n\n","path":"github.com/pushchain/push-chain-node/utils","name":"utils","synopsis":"","isRedistributable":true}
