isPoint function
This function checks if a Uint8List 'p' represents a valid elliptic curve point. It performs several checks on the structure and values within 'p' to determine validity. It returns true if 'p' is a valid point; otherwise, it returns false.
Implementation
bool isPoint(Uint8List p) {
/// Check if the length of 'p' is less than 33 bytes; if so, it's not a valid point.
if (p.length < 33) {
return false;
}
/// Extract the first byte ('t') and the next 32 bytes ('x') from 'p'.
var t = p[0];
var x = p.sublist(1, 33);
/// Check if 'x' is an all-zero byte sequence, which is not a valid point.
if (_compare(x, Uint8List(32)) == 0) {
return false;
}
/// Check if 'x' is greater than or equal to the elliptic curve parameter 'EC_P', which is not a valid point.
if (_compare(x, _ecPBytes) == 1) {
return false;
}
/// Attempt to decode 'p' into an elliptic curve point using '_decodeFrom'.
/// If an error is raised, it's not a valid point.
try {
_decodeFrom(p);
} catch (err) {
return false;
}
/// Check if 'p' is in compressed format (t == 0x02 or t == 0x03) and has a length of 33 bytes; if so, it's a valid point.
if ((t == 0x02 || t == 0x03) && p.length == 33) {
return true;
}
/// Extract the remaining bytes ('y') from 'p'.
var y = p.sublist(33);
/// Check if 'y' is an all-zero byte sequence, which is not a valid point.
if (_compare(y, Uint8List(32)) == 0) {
return false;
}
/// Check if 'y' is greater than or equal to 'EC_P', which is not a valid point.
if (_compare(y, _ecPBytes) == 1) {
return false;
}
/// Check if 'p' is in uncompressed format (t == 0x04) and has a length of 65 bytes; if so, it's a valid point.
if (t == 0x04 && p.length == 65) {
return true;
}
/// If none of the conditions are met, it's not a valid point.
return false;
}