def address_from_public_key(pubkey: bytes, hrp: str) -> str: """ Address = RIPEMD160(SHA256(compressed public key)) Address_Bech32 = HRP + '1' + bech32.encode(convert8BitsTo5Bits(RIPEMD160(SHA256(compressed public key)))) HRP - bnb for productions, tbnb for tests """ h = sha256_ripemd160_digest(pubkey) convertedbits = bech32.convertbits(h, 8, 5, False) return bech32.bech32_encode(hrp, convertedbits)
def address_from_public_key(pubkey: bytes, hrp: str) -> str: """ Address = RIPEMD160(SHA256(compressed public key)) Address_Bech32 = HRP + '1' + bech32.encode(convert8BitsTo5Bits(RIPEMD160(SHA256(compressed public key)))) HRP - bnb for productions, tbnb for tests """ h = sha256_ripemd160(pubkey).digest() assert (len(h) * 8) % 5 == 0 # no padding will be added by convertbits convertedbits = bech32.convertbits(h, 8, 5) return bech32.bech32_encode(hrp, convertedbits, bech32.Encoding.BECH32)
def encode(hrp: str, data: bytes) -> str: converted_bits = bech32.convertbits(data, 8, 5) return bech32.bech32_encode(hrp, converted_bits, bech32.Encoding.BECH32)
def encode(hrp: str, data: bytes) -> str: converted_bits = bech32.convertbits(data, 8, 5) if converted_bits is None: raise ValueError return bech32.bech32_encode(hrp, converted_bits, bech32.Encoding.BECH32)