我只想使用ecrecover来使用公钥来验证相应的私钥是否签名了一个消息,该消息是通过一个稳定的变量传递的。做这件事的简单方法是什么?我已经插入了?在我不知道如何使用恢复的坚实的地方。
ie:客户端:
消息:bob的私钥:"2j3940“的公钥:"0x3jhr32”签名消息:"3cj0239roi3409i34234“
稳固结束:
function verifyMessage(message, signedMessage, publicKey){
bool verified = False;
if (????){
verified = True;
}
return(verified);
}预期用途:
input:
verifyMessage("solidity has poor documentation","3cj0239roi3409i34234","0x3jhr32")
output:
True下面是另一个关于同一问题的问题,但我无法使用它们的实现:外部创建的ECDSA签名的验证
发布于 2022-04-04 08:32:07
查看Openzeppelin:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol。它们有一个恢复函数,您可以将签名作为字符串输入。
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {ECDSA} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol";
contract MySignatureTest {
using ECDSA for bytes32;
function verifyMessage(bytes32 messageHash, bytes memory signedMessage, address account) external pure returns (bool) {
return messageHash
.toEthSignedMessageHash()
.recover(signedMessage) == account;
}
}https://ethereum.stackexchange.com/questions/125336
复制相似问题