Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Created September 15, 2022 17:20
Show Gist options
  • Save ryandotsmith/138861a9cfea5beeeb8a61dc1d70841d to your computer and use it in GitHub Desktop.
Save ryandotsmith/138861a9cfea5beeeb8a61dc1d70841d to your computer and use it in GitHub Desktop.
package ens
import (
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
func Namehash(name string) common.Hash {
var (
h common.Hash
labels = strings.Split(name, ".")
)
for i := len(labels) - 1; i >= 0; i-- {
h = crypto.Keccak256Hash(
h.Bytes(),
crypto.Keccak256Hash([]byte(labels[i])).Bytes(),
)
}
return h
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment