From 10abc85ac1eecf389a801f623380b26df9f913a5 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Mon, 1 Oct 2018 22:00:42 +0530 Subject: [PATCH] updates --- .eslintrc | 2 +- contracts/ECRecovery.sol | 53 --------------------------------- test/library/ECRecovery.test.js | 40 ------------------------- 3 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 contracts/ECRecovery.sol delete mode 100644 test/library/ECRecovery.test.js diff --git a/.eslintrc b/.eslintrc index 8816abf6d..c06f6e872 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,7 +26,7 @@ // Code style "camelcase": ["error", {"properties": "always"}], - "comma-dangle": ["warn", "always-multiline"], + "comma-dangle": ["error", "always-multiline"], "comma-spacing": ["error", {"before": false, "after": true}], "dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}], "eol-last": ["error", "always"], diff --git a/contracts/ECRecovery.sol b/contracts/ECRecovery.sol deleted file mode 100644 index c5b6d8f64..000000000 --- a/contracts/ECRecovery.sol +++ /dev/null @@ -1,53 +0,0 @@ -pragma solidity ^0.4.18; - - -/** - * @title Eliptic curve signature operations - * - * @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d - */ - -library ECRecovery { - - /** - * @dev Recover signer address from a message by using his signature - * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address. - * @param sig bytes signature, the signature is generated using web3.eth.sign() - */ - function recover(bytes32 hash, bytes sig) public pure returns (address) { - bytes32 r; - bytes32 s; - uint8 v; - - //Check the signature length - if (sig.length != 65) { - return (address(0)); - } - - // Divide the signature in r, s and v variables - assembly { - r := mload(add(sig, 32)) - s := mload(add(sig, 64)) - v := byte(0, mload(add(sig, 96))) - } - - // Version of signature should be 27 or 28, but 0 and 1 are also possible versions - if (v < 27) { - v += 27; - } - - // If the version is correct return the signer address - if (v != 27 && v != 28) { - return (address(0)); - } else { - - /* - * https://github.com/ethereum/go-ethereum/issues/3731 - */ - - bytes memory prefix = "\x19Ethereum Signed Message:\n32"; - return ecrecover(keccak256(prefix, hash), v, r, s); - } - } - -} diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js deleted file mode 100644 index ef354a76f..000000000 --- a/test/library/ECRecovery.test.js +++ /dev/null @@ -1,40 +0,0 @@ -var ECRecoveryMock = artifacts.require('ECRecoveryMock'); -var ECRecoveryLib = artifacts.require('ECRecovery'); - -contract('ECRecovery', function (accounts) { - let ecrecovery; - const TEST_MESSAGE = 'OpenZeppelin'; - - before(async function () { - const ecRecoveryLib = await ECRecoveryLib.new(); - ECRecoveryMock.link('ECRecovery', ecRecoveryLib.address); - ecrecovery = await ECRecoveryMock.new(); - }); - - it('recover using web3.eth.sign()', async function () { - // Create the signature using account[0] - const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); - - // Recover the signer address from the generated message and signature. - await ecrecovery.recover(web3.sha3(TEST_MESSAGE), signature); - assert.equal(accounts[0], await ecrecovery.addrRecovered()); - }); - - it('recover using web3.eth.sign() should return wrong signer', async function () { - // Create the signature using account[0] - const signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); - - // Recover the signer address from the generated message and wrong signature. - await ecrecovery.recover(web3.sha3('Test'), signature); - assert.notEqual(accounts[0], await ecrecovery.addrRecovered()); - }); - - it('recover should fail when a wrong hash is sent', async function () { - // Create the signature using account[0] - let signature = web3.eth.sign(accounts[0], web3.sha3(TEST_MESSAGE)); - - // Recover the signer address from the generated message and wrong signature. - await ecrecovery.recover(web3.sha3(TEST_MESSAGE).substring(2), signature); - assert.equal('0x0000000000000000000000000000000000000000', await ecrecovery.addrRecovered()); - }); -});