Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/authereum/is-valid-signature
EIP1271 signature checker implementation in JavaScript
https://github.com/authereum/is-valid-signature
erc1271 ethereum solidity web3
Last synced: 2 months ago
JSON representation
EIP1271 signature checker implementation in JavaScript
- Host: GitHub
- URL: https://github.com/authereum/is-valid-signature
- Owner: authereum
- License: mit
- Created: 2019-06-29T00:49:56.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-18T22:34:49.000Z (about 4 years ago)
- Last Synced: 2024-09-14T12:08:40.926Z (4 months ago)
- Topics: erc1271, ethereum, solidity, web3
- Language: JavaScript
- Homepage: https://github.com/authereum/is-valid-signature
- Size: 29.8 MB
- Stars: 36
- Watchers: 4
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-valid-signature [![npm version](https://badge.fury.io/js/is-valid-signature.svg)](https://badge.fury.io/js/is-valid-signature)
Check if a signature is valid for an Ethereum address. Works for both [externally owned accounts](http://ethdocs.org/en/latest/contracts-and-transactions/account-types-gas-and-transactions.html#externally-owned-accounts-eoas) and [contract accounts](http://ethdocs.org/en/latest/contracts-and-transactions/account-types-gas-and-transactions.html#contract-accounts) that follow the [ERC1271 standard](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1271.md).
## Install
```bash
npm install is-valid-signature
```## Getting started
Check signatures for externally owned accounts
```javascript
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](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1271.md) contracts
```javascript
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](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1271.md) 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
```bash
npm test
```## License
[MIT](LICENSE)