无法以坚固性恢复签名的消息
我正在签署一条消息,并试图通过固体(链)恢复它。不知何故,签名地址永远不会匹配。
Off-Chain Code
var message = 'Hello World';
var privateKey = '0xXXXXXXXX'; //Private key of the my using to sign message
var signatureMessage = web3.eth.accounts.sign(message, privateKey);
这给了我一个签名值,但是,当我使用相同的签名和牢固性的签名和消息来恢复歌手的公共地址时,我会得到不同的地址。
固体性
function publicSaleBuy(bytes calldata signature, string memory message) external payable
{
if (!matchAddresSigner(hashTransaction(message), signature)){
revert DirectMintFromNotAllowed();
}else {
_mint(1);
}
}
function matchAddresSigner(bytes32 hash, bytes memory signature)
private
view
returns (bool)
{
return signerAddress == hash.recover(signature);
}
function hashTransaction(string memory message) public pure returns (bytes32) {
bytes32 messageHash = keccak256(abi.encodePacked(message));
bytes32 hash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", messageHash));
return hash;
}
I am signing a message off-chain and trying to recover this via solidity(on-chain). Somehow, the signer address never matches.
Off-chain code
var message = 'Hello World';
var privateKey = '0xXXXXXXXX'; //Private key of the my using to sign message
var signatureMessage = web3.eth.accounts.sign(message, privateKey);
This gives me a signature value, however, when I am using the same signature and message on solidity to recover the singer's public address, I am getting a different address.
Solidity
function publicSaleBuy(bytes calldata signature, string memory message) external payable
{
if (!matchAddresSigner(hashTransaction(message), signature)){
revert DirectMintFromNotAllowed();
}else {
_mint(1);
}
}
function matchAddresSigner(bytes32 hash, bytes memory signature)
private
view
returns (bool)
{
return signerAddress == hash.recover(signature);
}
function hashTransaction(string memory message) public pure returns (bytes32) {
bytes32 messageHash = keccak256(abi.encodePacked(message));
bytes32 hash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", messageHash));
return hash;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论