diff --git a/README.md b/README.md index 6ba768d..b75b7b2 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,9 @@ Same as `inLogs`, but for events emitted in an arbitrary transaction (of hash `t #### ERC165 Calculates the [ERC165](https://eips.ethereum.org/EIPS/eip-165) interface ID of a contract, given a series of function signatures. +#### ERC1820 +Calculates the [ERC1820](https://eips.ethereum.org/EIPS/eip-1820) interface hash of a function, given its signature. + --- ### send diff --git a/src/makeInterfaceId.js b/src/makeInterfaceId.js index 295c5c3..29fc1ac 100644 --- a/src/makeInterfaceId.js +++ b/src/makeInterfaceId.js @@ -1,8 +1,8 @@ -function ERC165 (interfaces = []) { +function ERC165 (functionSignatures = []) { const INTERFACE_ID_LENGTH = 4; - const interfaceIdBuffer = interfaces - .map(methodSignature => web3.utils.soliditySha3(methodSignature)) // keccak256 + const interfaceIdBuffer = functionSignatures + .map(signature => web3.utils.soliditySha3(signature)) // keccak256 .map(h => Buffer .from(h.substring(2), 'hex') @@ -18,8 +18,8 @@ function ERC165 (interfaces = []) { return `0x${interfaceIdBuffer.toString('hex')}`; } -function ERC1820 (inteface) { - +function ERC1820 (functionSignature) { + return web3.utils.soliditySha3(functionSignature); // keccak256 } module.exports = { diff --git a/test/src/makeInterfaceId.test.js b/test/src/makeInterfaceId.test.js index fed70bf..f2c3c91 100644 --- a/test/src/makeInterfaceId.test.js +++ b/test/src/makeInterfaceId.test.js @@ -18,4 +18,12 @@ describe('makeInterfaceId', function () { ])).to.equal(ownableId); }); }); + + describe('ERC165', function () { + it('calculates the interface id from function signatures', async function () { + expect(makeInterfaceId.ERC1820('ERC777Token')).to.equal( + '0xac7fbab5f54a3ca8194167523c6753bfeb96a445279294b6125b68cce2177054' + ); + }); + }); });