Skip to content

Commit

Permalink
refactor: Namehash() exported because it is useful when you need to d…
Browse files Browse the repository at this point in the history
…ebug AENS
  • Loading branch information
randomshinichi committed Apr 3, 2019
1 parent de42965 commit d4ac51d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions aeternity/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func hash(in []byte) (out []byte, err error) {
return
}

// namehash calculate the namehash of a string
// Namehash calculate the Namehash of a string
// TODO: link to the
func namehash(name string) []byte {
func Namehash(name string) []byte {
buf := make([]byte, 32)
for _, s := range strings.Split(name, ".") {
sh, _ := hash([]byte(s))
Expand Down Expand Up @@ -117,7 +117,7 @@ func computeCommitmentID(name string) (ch string, salt []byte, err error) {
return
}
// TODO: this is done using the api (concatenating )
nh := append(namehash(name), salt...)
nh := append(Namehash(name), salt...)
nh, _ = hash(nh)
// nh := namehash(name)
ch = Encode(PrefixCommitment, nh)
Expand Down
7 changes: 4 additions & 3 deletions aeternity/hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Test_Decode(t *testing.T) {
}
}

func Test_namehash(t *testing.T) {
func Test_Namehash(t *testing.T) {
// ('welghmolql.aet') == 'nm_2KrC4asc6fdv82uhXDwfiqB1TY2htjhnzwzJJKLxidyMymJRUQ'
type args struct {
name string
Expand All @@ -114,13 +114,14 @@ func Test_namehash(t *testing.T) {
}{
{"ok", args{"welghmolql.aet"}, "nm_2KrC4asc6fdv82uhXDwfiqB1TY2htjhnzwzJJKLxidyMymJRUQ"},
{"ok", args{"welghmolql"}, "nm_2nLRBu1FyukEvJuMANjFzx8mubMFeyG2mJ2QpQoYKymYe1d2sr"},
{"ok", args{"fdsa.test"}, "nm_ie148R2qZYBfo1Ek3sZpfTLwBhkkqCRKi2Ce8JJ7yyWVRw2Sb"},
{"ok", args{""}, "nm_2q1DrgEuxRNCWRp5nTs6FyA7moSEzrPVUSTEpkpFsM4hRL4Dkb"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Encode(PrefixName, namehash(tt.args.name))
got := Encode(PrefixName, Namehash(tt.args.name))
if got != tt.want {
t.Errorf("namehash() = %v, want %v", got, tt.want)
t.Errorf("Namehash() = %v, want %v", got, tt.want)
}
})
}
Expand Down

0 comments on commit d4ac51d

Please sign in to comment.