def DecodeAddr(addr: str, **kwargs: Any) -> bytes: """ Decode an Ethereum address to bytes. Args: addr (str): Address string Other Parameters: skip_chksum_enc (bool, optional): True to skip checksum encoding verification, false otherwise (default) Returns: bytes: Public key hash bytes Raises: ValueError: If the address encoding is not valid """ skip_chksum_enc = kwargs.get("skip_chksum_enc", False) # Validate and remove prefix addr_no_prefix = AddrDecUtils.ValidateAndRemovePrefix( addr, CoinsConf.Ethereum.Params("addr_prefix")) # Validate length AddrDecUtils.ValidateLength(addr_no_prefix, EthAddrConst.ADDR_LEN) # Check checksum encoding if not skip_chksum_enc and addr_no_prefix != _EthAddrUtils.ChecksumEncode( addr_no_prefix): raise ValueError("Invalid checksum encode") return BytesUtils.FromHexString(addr_no_prefix)
class P2TRConst: """Class container for P2TR constants.""" # Secp256k1 field size FIELD_SIZE: int = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F # SHA256 of "TapTweak" TAP_TWEAK_SHA256: bytes = BytesUtils.FromHexString( "e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9" ) # Witness version is fixed to one for P2TR WITNESS_VER: int = 1
def EncodeKey(pub_key: Union[bytes, IPublicKey], **kwargs: Any) -> str: """ Encode a public key to Harmony One address. Args: pub_key (bytes or IPublicKey): Public key bytes or object **kwargs: Not used Returns: str: Address string Raises: ValueError: If the public key is not valid TypeError: If the public key is not secp256k1 """ # Get address in Ethereum format (remove "0x" at the beginning) eth_addr = EthAddrEncoder.EncodeKey(pub_key)[2:] # Encode in Bech32 format return Bech32Encoder.Encode(CoinsConf.HarmonyOne.Params("addr_hrp"), BytesUtils.FromHexString(eth_addr))
def EncodeKey(pub_key: Union[bytes, IPublicKey], **kwargs: Any) -> str: """ Encode a public key to Tron address. Args: pub_key (bytes or IPublicKey): Public key bytes or object **kwargs : Not used Returns: str: Address string Raised: ValueError: If the public key is not valid TypeError: If the public key is not secp256k1 """ # Get address in Ethereum format (remove "0x" at the beginning) eth_addr = EthAddrEncoder.EncodeKey(pub_key)[2:] # Add prefix and encode return Base58Encoder.CheckEncode( CoinsConf.Tron.Params("addr_prefix") + BytesUtils.FromHexString(eth_addr))
def DecodeAddr(addr: str, **kwargs: Any) -> bytes: """ Decode a Near Protocol address to bytes. Args: addr (str): Address string **kwargs : Not used Returns: bytes: Public key bytes Raises: ValueError: If the address encoding is not valid """ pub_key_bytes = BytesUtils.FromHexString(addr) # Validate length AddrDecUtils.ValidateLength(pub_key_bytes, Ed25519PublicKey.CompressedLength() - 1) # Validate public key AddrDecUtils.ValidatePubKey(pub_key_bytes, Ed25519PublicKey) return pub_key_bytes