sanitizeData method
Removes properties from a message Map<String,dynamic> that are not defined per EIP-712
@param {Map<String, dynamic>} data - typed message Map<String, dynamic> @returns {Map<String, dynamic>} - typed message Map<String, dynamic> with only allowed fields
Implementation
Map<String, dynamic> sanitizeData(Map<String, dynamic> typedData) {
assert(
typedData['types'] != null,
"the types property of the input typedData needs to be provided",
);
assert(
typedData['primaryType'] != null,
"the primaryType property of the input typedData needs to be provided",
);
assert(
typedData['domain'] != null,
"the domain property of the input typedData needs to be provided",
);
assert(
typedData['message'] != null,
"the message property of the input typedData needs to be provided",
);
Map<String, dynamic> _sanitizedData = {};
for (var key
in (TYPED_MESSAGE_SCHEMA["properties"] as Map<String, dynamic>).keys
.toList()) {
if (typedData[key] != null) {
_sanitizedData[key] = typedData[key];
}
}
if (_sanitizedData["types"]["EIP712Domain"] == null) {
_sanitizedData["types"]["EIP712Domain"] = List<Map<String, String>>.from(
[],
);
}
return _sanitizedData;
}