Skip to content

Commit

Permalink
Added keccak256.js to get signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
computerphysicslab committed Jul 16, 2021
1 parent 94ba02c commit f830aa9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
}
},
"dependencies": {
"keccak": "^3.0.1",
"keccak256": "^1.0.3",
"phantomjs-prebuilt": "^2.1.16",
"sol2uml": "^1.1.17",
"yarn": "^1.22.10"
Expand Down
23 changes: 23 additions & 0 deletions scripts/keccak256.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This is a nodejs script to compute the selectors of Solidity events or functions
// (four bytes of the Keccak-256 or SHA-3 hash of the signature of the function)
// Install: npm i keccak256

var myArgs = process.argv.slice(2);
// console.log('arg: ', String(myArgs[0]).split(/\r?\n/));

let signatures = String(myArgs[0])
.replace(/;/g, '') // remove final ;
.split(/\r?\n/) // split lines, every line is a signature
.sort(function(a, b){ // sorted alphabetically
if(a < b) { return -1; }
if(a > b) { return 1; }
return 0;
})
.filter((item, i, ar) => ar.indexOf(item) === i) // get unique
;
// console.log('signatures: ', signatures);

const keccak256 = require('keccak256');
for(let s of signatures) {
if (s) console.log(s + "\t" + "0x" + keccak256(s).toString('hex'));
}

0 comments on commit f830aa9

Please sign in to comment.