0

I'm new to computure program. What does this problem mean in solidity? How can I solve this problem?

Here is the problem:

DeclarationError: Undeclared identifier. "getMessageHash" is not (or not yet) visible at this point.
--> contracts/SigLearning.sol:14:27:
|
14 | bytes32 messageHash = getMessageHash(_message);
| ^^^^^^^^^^^^^^

Here is my code:

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

/* 0. message to sign

  1. hash(message)
  2. sign(hash(message),private key) |offchain
  3. ecrecover(hash(message),signature) == signer

*/

contract VerifySig{

function verify(address _signer, string memory _message, bytes memory _sig) external pure returns(bool){
bytes32 messageHash = getMessageHash(_message);
bytes32 ethSignedMessageHash = getEthSignedMessageHash(mesageHash);

return recover(ethSignedMessageHash,_sig) == _signer;
}

function getMessageHash(string memory _message) external pure returns(bytes32){
    return keccak256(abi.encodePacked(_message));
}

function getEthSignedMessageHash(bytes32 _messageHash) external pure returns(bytes32){
    return keccak256(abi.encodePacked(
        "\x19Ethereum Signed Message: \n32",
        _messageHash));
}

function _split(string memory _sig) internal pure returns(bytes32 r, bytes32 s, uint8 v){

    require(_sig.length == 65,"invalid signature length");

    assembly{
        r := mload.(add(_sig,32))
        s := mload.(add(_sig,64))
        v := byte(0,mload.(_sig,96))

    }
}

}

2 Answers2

0

Bro your getMessageHash has visibility of external which will be only visible to external contract. you need to make it public to use it in the contract.

error:

                                                  here 
 function getMessageHash(string memory _message) `external` pure returns(bytes32){
                                                       here 
function getEthSignedMessageHash(bytes32 _messageHash) `external` pure returns(bytes32){

correct (make it) :

                                                  here 
 function getMessageHash(string memory _message) `public` pure returns(bytes32){
                                                   here 

function getEthSignedMessageHash(bytes32 _messageHash) public pure returns(bytes32){

DereK
  • 294
  • 1
  • 10
0

There are 4 types of visibility identifiers.

1) External: Can be called outside of the contract.

2) Public: Can be called inside or outside of the contract.

3) Private: Can be called only within the contract.

4) Internal: Can be called only within the contract or from the contracts that are derived from the original contract.

In your case, you identify your getMessageHash function as External, and yet you are trying to call it internally.

Make it private if you never going to need it to be called externally.

Make it public if you want that function to be callable both internally and externally.

Yetik
  • 339
  • 1
  • 10