encode method
Encodes the typed data structure into a list of integers using EIP-712 version 1.
Implementation
@override
List<int> encode({bool hash = true}) {
// Extract values, types, and names from Eip712TypedDataV1 instances
final values = typesData.map((e) => e.value).toList();
final types = typesData.map((e) => e.type).toList();
final names = typesData.map((e) => "${e.type} ${e.name}").toList();
// Calculate hashes for types and names
final typesHash =
QuickCrypto.keccack256Hash(_EIP712Utils.legacyV1encode(types, values));
final namesHash = QuickCrypto.keccack256Hash(_EIP712Utils.legacyV1encode(
List.generate(names.length, (index) => "string"), names));
final toBytes = _EIP712Utils.legacyV1encode(
['bytes32', 'bytes32'], [namesHash, typesHash]);
if (!hash) {
return toBytes;
}
return QuickCrypto.keccack256Hash(toBytes);
}