isValidEip1271Signature static method
Implementation
static Future<bool> isValidEip1271Signature(
String address,
String reconstructedMessage,
String cacaoSignature,
String chainId,
String projectId,
) async {
try {
const String eip1271MagicValue = '0x1626ba7e';
const String dynamicTypeOffset =
'0000000000000000000000000000000000000000000000000000000000000040';
const String dynamicTypeLength =
'0000000000000000000000000000000000000000000000000000000000000041';
final String nonPrefixedSignature = cacaoSignature.substring(2);
final String nonPrefixedHashedMessage = hex
.encode(hashMessage(reconstructedMessage))
.substring(2);
final String data =
eip1271MagicValue +
nonPrefixedHashedMessage +
dynamicTypeOffset +
dynamicTypeLength +
nonPrefixedSignature;
final Uri url = Uri.parse(
'${StringConstants.AUTH_DEFAULT_URL}/?chainId=$chainId&projectId=$projectId',
);
final Map<String, dynamic> body = JsonRpcUtils.formatJsonRpcRequest(
'eth_call',
{'to': address, 'data': data},
);
final http.Response response = await http.post(url, body: body);
// print(response.body);
// final jsonBody = jsonDecode(response.body);
final String recoveredValue = response.body.substring(
0,
eip1271MagicValue.length,
);
return recoveredValue.toLowerCase() == eip1271MagicValue.toLowerCase();
} catch (e) {
return false;
}
}