Skip to content

Commit

Permalink
Add makeInterfaceId.ERC1820.
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Mar 26, 2019
1 parent 72f8e1b commit e27a908
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions 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')
Expand All @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions test/src/makeInterfaceId.test.js
Expand Up @@ -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'
);
});
});
});

0 comments on commit e27a908

Please sign in to comment.