Closed longbowlu closed 3 years ago
I think it will be easier to read if we keep it very explicit. wdyt of:
from pylibra import lcs
from pylibra import libra_types as libra
from pylibra import serde_types as st
...
metadata: Metadata = libra.Metadata__TravelRuleMetadata(
libra.TravelRuleMetadata__TravelRuleMetadataVersion0(
libra.TravelRuleMetadataV0(
off_chain_reference_id="reference_id",
)
)
)
// `lcs_metadata` will be used as the `metadata` parameter in encode_peer_to_peer_with_metadata_script()
lcs_metadata = lcs.serialize(metadata, libra.Metadata)
dual_attest_msg_bytes: bytearray = bytearray()
dual_attest_msg_bytes.extend(lcs_metadata) # Travel Rule metadata
dual_attest_msg_bytes.extend(lcs.serialize(bytes.fromhex("793251de1a61e9b4d1a17d13aa015e45"), bytes)) # Raw on-chain address (https://github.com/libra/lip/blob/master/lips/lip-5.md#terminology)
dual_attest_msg_bytes.extend(lcs.serialize(st.uint64(1000000), st.uint64)) # Amount
dual_attest_msg_bytes.extend(b"@@$$LIBRA_ATTEST$$@@") # ASCII-encoded Libra Domain Separator string
// We sign the bytes directly with the compliance private key
// `receiver_metadata_signature` will be used as the `metadata_signature` parameter in encode_peer_to_peer_with_metadata_script()
receiver_metadata_signature = compliance_private_key.sign(dual_attest_msg_bytes)
:exclamation: Invalid command
I think it will be easier to read if we keep it very explicit. wdyt of:
from pylibra import lcs from pylibra import libra_types as libra from pylibra import serde_types as st ... metadata: Metadata = libra.Metadata__TravelRuleMetadata( libra.TravelRuleMetadata__TravelRuleMetadataVersion0( libra.TravelRuleMetadataV0( off_chain_reference_id="reference_id", ) ) ) // `lcs_metadata` will be used as the `metadata` parameter in encode_peer_to_peer_with_metadata_script() lcs_metadata = lcs.serialize(metadata, libra.Metadata) dual_attest_msg_bytes: bytearray = bytearray() dual_attest_msg_bytes.extend(lcs_metadata) # Travel Rule metadata dual_attest_msg_bytes.extend(lcs.serialize(bytes.fromhex("793251de1a61e9b4d1a17d13aa015e45"), bytes)) # Raw on-chain address (https://github.com/libra/lip/blob/master/lips/lip-5.md#terminology) dual_attest_msg_bytes.extend(lcs.serialize(st.uint64(1000000), st.uint64)) # Amount dual_attest_msg_bytes.extend(b"@@$$LIBRA_ATTEST$$@@") # ASCII-encoded Libra Domain Separator string // We sign the bytes directly with the compliance private key // `receiver_metadata_signature` will be used as the `metadata_signature` parameter in encode_peer_to_peer_with_metadata_script() receiver_metadata_signature = compliance_private_key.sign(dual_attest_msg_bytes)
Seems like the only difference of this and the original code is DOMAIN_SEPARATOR is not serialized? I tried this and it did not work. Did you test this snippet in testnet ? @n4ss
Differences are: domain separator is not serialized and the byte vector is not serialized either. This is the same as your implem (lcs-encoding of the struct is lcs-encoding of each field) and matches the ref this time:
let message = metadata;
Vector::append(&mut message, LCS::to_bytes(&payer));
Vector::append(&mut message, LCS::to_bytes(&deposit_value));
Vector::append(&mut message, DOMAIN_SEPARATOR);
message
lcs.serialize(bytes.fromhex("793251de1a61e9b4d1a17d13aa015e45"), bytes)
is not the correct serialization for address. I think it's because the address has a different type than normal bytes. You can get the lcs bytes by calling utils.account_address(addr_hex).lcs_serialize()
and If your point is dataclass is less clear to read, I've updated to also include a version that concats individually serialized bytes (very similar to the original code snippet before this change)
I've verified this snippet of code against testnet