Check if a signature is valid for an Ethereum address. Works for both externally owned accounts and contract accounts that follow the ERC1271 standard.
npm install is-valid-signature
Check signatures for externally owned accounts
const isValidSignature = require('is-valid-signature')
const signer = YOUR_SIGNER_ADDRESS
// Get a signature
const message = web3.utils.soliditySha3('Hello world')
const signature = await web3.eth.sign(message, signer)
// Check if the signature is valid
const isValid = await isValidSignature(
signer,
message,
signature,
web3.currentProvider
)
Check signatures for ERC-1271 contracts
const isValidSignature = require('is-valid-signature')
const signer = YOUR_SIGNER_ADDRESS
// Get contract where `signer` can sign on behalf of contract
const contract = ERC1271.at(YOUR_CONTRACT_ADDRESS)
// Get a signature
const message = web3.utils.soliditySha3('Hello world')
const signature = await web3.eth.sign(message, signer)
// Check if the signature is valid
const isValid = await isValidSignature(
contract.address,
message,
signature,
web3.currentProvider
)
ERC-1271 is currently a draft and there are multiple proposed interfaces. This package supports the following ERC-1271 interface.
contract ERC1271 {
function isValidSignature(
bytes memory _messageHash,
bytes memory _signature)
public
view
returns (bytes4 magicValue);
}
npm test