27 lines
716 B
Plaintext
27 lines
716 B
Plaintext
pub fn sha3_384_hash(data: Bytes) -> Hash {
|
|
return Hash::sha3_384(data);
|
|
}
|
|
|
|
pub fn sha3_384_hash_string(data: String) -> Hash {
|
|
return Hash::sha3_384(data.as_bytes());
|
|
}
|
|
|
|
pub fn address_from_public_key(public_key: Bytes) -> Address {
|
|
require(public_key.len() == 33 || public_key.len() == 65, "Invalid public key length");
|
|
let hash = sha3_384_hash(public_key);
|
|
return Address::from_hash(hash);
|
|
}
|
|
|
|
pub fn is_valid_address(address: Address) -> bool {
|
|
return !address.is_zero();
|
|
}
|
|
|
|
pub fn hex_encode(data: Bytes) -> String {
|
|
return "0x" + data.to_hex();
|
|
}
|
|
|
|
pub fn hex_decode(hex_string: String) -> Bytes {
|
|
let hex = hex_string.trim_start_matches("0x");
|
|
return Bytes::from_hex(hex);
|
|
}
|