Signature Verification

Hello Everyone'
I am facing problem in verifying of Struct OrderComponents
i get the hash and signature but i can't verify with ECDSA
This is my Solidity code

function verifyOwnerSignature(bytes32 hash, bytes memory signature) public view returns(address)
{
return hash.toEthSignedMessageHash().recover(signature);
}

struct OfferItem {
uint256 startAmount;
}

struct OrderComponents {
address offerer;
OfferItem[] offer;
}

I am using web3 to hash and sign this struct , This is my code ,

var Web3 = require('web3');
var web3 = new Web3();
require('dotenv').config();

const encode_value = web3.eth.abi.encodeParameter(
{
"OrderComponents": {
"offerer": 'address',
"OfferItem": [{
"startAmount": 'uint256'
}]
}
},
{
"offerer": '0xe2b5a5b611643c7e0e4D705315bf580B75472d7b',
"OfferItem": [{
"startAmount": 1
}]

}

);
const privateKey = process.env.PRIVATE_KEY;
const hashGettingFromECDSAAfterPassingTheStructHash = web3.eth.accounts.hashMessage(structHash);

const signature = web3.eth.accounts.sign(structHash, privateKey);
const signerAddress = web3.eth.accounts.recover(structHash, signature.signature);

can anyone let me know whats wrong in it ?
Thanks

Hey, can you tell me what is the error that the console gives you?

console is giving no error , Signature is mismatching

I apply this verification in my contract recently and the different is I do validation in the function and return true/false directly

   function _verify(
        bytes32 data,
        bytes memory signature,
        address account
    ) internal pure returns (bool) {
        return data.toEthSignedMessageHash().recover(signature) == account;
    }

try this way

1 Like