Skip to content

Instantly share code, notes, and snippets.

@adraffy
Created January 16, 2022 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adraffy/37ee0039f9cb8b99a61ddd5ca7c7c3b7 to your computer and use it in GitHub Desktop.
Save adraffy/37ee0039f9cb8b99a61ddd5ca7c7c3b7 to your computer and use it in GitHub Desktop.
import {keccak} from '@adraffy/keccak';
function namehash(name) {
let buf = new Uint8Array(64);
if (name.length > 0) {
for (let label of name.split('.').reverse()) {
buf.set(keccak().update(label).bytes, 32);
buf.set(keccak().update(buf).bytes, 0);
}
}
return buf.slice(0, 32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment