is-valid-signature
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

is-valid-signature npm version

Check if a signature is valid for an Ethereum address. Works for both externally owned accounts and contract accounts that follow the ERC1271 standard.

Install

npm install is-valid-signature

Getting started

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

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);
}

Test

npm test

License

MIT

Package Sidebar

Install

npm i is-valid-signature

Weekly Downloads

9

Version

0.1.4

License

MIT

Unpacked Size

33 kB

Total Files

17

Last publish

Collaborators

  • miguelmota
  • cwhinfrey
  • shanefontaine