Last active
May 7, 2023 10:56
-
-
Save ilyar/f8119138b114bb25b7d50255e5f3c82d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict' | |
const { createHash } = require('crypto') | |
function slugSha256(data) { | |
return Number(`0x${createHash('sha256').update(data).digest('hex').slice(0, 8)}`) | |
} | |
function functionHash(signature) { | |
let hash = slugSha256(signature.replaceAll(' ', '')) | |
// FIXME for constructor, cell, bytes see https://gist.github.com/ilyar/484360bdb5464a6f252bd8f8ec10aaff | |
return signature.includes('constructor') ? hash ^ 2 ** 31 : hash | |
} | |
function functionID(signature) { | |
return `0x${functionHash(signature + 'v2').toString(16)}` | |
} | |
console.log(functionID(process.argv[2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also see