Created
September 15, 2022 17:20
-
-
Save ryandotsmith/138861a9cfea5beeeb8a61dc1d70841d 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
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