I have been trying to do it but it always return me false, tried a lot of ways but I don't know. Here is the smart contract
function _verify(
bytes32 hashedMessage,
bytes memory signature
) public view returns (bool) {
require(signature.length == 65, "Invalid Signature");
bytes32 ethHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hashedMessage));
(bytes32 r, bytes32 s, uint8 v) = _split(signature);
return ecrecover(ethHash, v, r, s) == owner;
}
function _split(bytes memory signature) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
assembly {
r := mload(add(signature, 32))
s := mload(add(signature, 64))
v := byte(0, mload(add(signature, 96)))
}
}
Here is the typescript code where I am getting the result
async mintNFT(tokenId: number): Promise<any> {
const hashedMesage = keccak256(toUtf8Bytes(tokenId.toString()));
const wallet = new Wallet(process.env.NEXT_PUBLIC_PRIVATE_KEY as string);
const signature = await wallet.signMessage((hashedMesage));
return this.sendContract.getFunction('_verify')(hashedMesage, signature)
.then((data) => {
console.log(data);
return data;
})
.catch((err) => {
console.log(err.message);
return 'error'
});
}