0.1.4 • Published 5 years ago

is-valid-signature v0.1.4

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

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

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.10

6 years ago

0.0.11

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago