recoverPubKey function
Implementation
String recoverPubKey({
required String message,
required String sig,
required String coin,
bool? uncompressed,
}) {
final messageHash = _createEthStyleMessageHash(message);
final parsedSig = _parseEthSignature(sig);
final pubKeyUncompressed = recoverPublicKey(messageHash, parsedSig);
if (uncompressed == true) {
return HEX.encode(pubKeyUncompressed);
}
final uncompressedPrefix = [0x04];
final pubKeyCompressed = compressPublicKey(
Uint8List.fromList(uncompressedPrefix + pubKeyUncompressed),
);
String pubKeyHex = HEX.encode(pubKeyCompressed);
if (pubKeyHex.startsWith("02")) {
pubKeyHex = pubKeyHex.replaceFirst(
"02",
"04",
); // workaround for Safir backwards compat
}
return pubKeyHex;
}