Skip to content

Commit

Permalink
Added sighash and signature the Interface function properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 27, 2017
1 parent aeec6d6 commit fb65772
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions contracts/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,13 @@ function Interface(abi) {
var outputNames = getKeys(method.outputs, 'name', true);
}

var signature = method.name + '(' + getKeys(method.inputs, 'type').join(',') + ')';
var sighash = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10);
var func = function() {
var signature = method.name + '(' + getKeys(method.inputs, 'type').join(',') + ')';
var result = {
name: method.name,
signature: signature,
sighash: sighash
};

var params = Array.prototype.slice.call(arguments, 0);
Expand All @@ -398,9 +400,7 @@ function Interface(abi) {
throwError('too many parameters');
}

signature = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10);

result.data = signature + Interface.encodeParams(inputTypes, params).substring(2);
result.data = sighash + Interface.encodeParams(inputTypes, params).substring(2);
if (method.constant) {
result.parse = function(data) {
return Interface.decodeParams(
Expand All @@ -417,6 +417,8 @@ function Interface(abi) {

defineFrozen(func, 'inputs', getKeys(method.inputs, 'name'));
defineFrozen(func, 'outputs', getKeys(method.outputs, 'name'));
utils.defineProperty(func, 'signature', signature);
utils.defineProperty(func, 'sighash', sighash);

return func;
})();
Expand Down Expand Up @@ -487,7 +489,9 @@ function Interface(abi) {
};
return populateDescription(new EventDescription(), result);
}

defineFrozen(func, 'inputs', getKeys(method.inputs, 'name'));

return func;
})();

Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethers-contracts",
"version": "2.1.2",
"version": "2.1.3",
"description": "Contract and Interface (ABI) library for Ethereum.",
"bugs": {
"url": "http://github.com/ethers-io/ethers.js/issues",
Expand Down

0 comments on commit fb65772

Please sign in to comment.