Last active
May 7, 2023 10:56
-
-
Save ilyar/cc31d37e4091287cb13a4e9bc12df5d1 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 ts-node | |
import { createHash } from 'crypto' | |
function slugSha256(data: string): number { | |
return Number(`0x${createHash('sha256').update(data).digest('hex').slice(0, 8)}`) | |
} | |
function functionHash(signature: string): number { | |
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: string): string { | |
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