Files
openzeppelin-contracts/test/helpers/makeInterfaceId.js
Nicolás Venturo cea2a85a42 Remove Babel (#1074)
* Test helpers no longer rely on Babel.

* Behaviours are no longer imported.

* Removed Babel dependency.

* Fixed linter errors.
2018-07-18 19:37:16 -03:00

26 lines
636 B
JavaScript

const { soliditySha3 } = require('web3-utils');
const INTERFACE_ID_LENGTH = 4;
function makeInterfaceId (interfaces = []) {
const interfaceIdBuffer = interfaces
.map(methodSignature => soliditySha3(methodSignature)) // keccak256
.map(h =>
Buffer
.from(h.substring(2), 'hex')
.slice(0, 4) // bytes4()
)
.reduce((memo, bytes) => {
for (let i = 0; i < INTERFACE_ID_LENGTH; i++) {
memo[i] = memo[i] ^ bytes[i]; // xor
}
return memo;
}, Buffer.alloc(INTERFACE_ID_LENGTH));
return `0x${interfaceIdBuffer.toString('hex')}`;
}
module.exports = {
makeInterfaceId,
};