|
|
package wordkey
|
|
|
|
|
|
import (
|
|
|
"encoding/hex"
|
|
|
"slices"
|
|
|
"testing"
|
|
|
|
|
|
"g.activething.com/go/DateKeys/profile"
|
|
|
)
|
|
|
|
|
|
func TestNormalize(t *testing.T) {
|
|
|
nbsp, tab := string(rune(0xa0)), string(rune(9))
|
|
|
in := " Ábaco" + nbsp + "ÁRBOL" + tab + "niño ΣΑΣ İ "
|
|
|
want := []string{"abaco", "arbol", "nino", "σασ", "i"}
|
|
|
if got := Normalize(in); !slices.Equal(got, want) {
|
|
|
t.Fatalf("Normalize = %q, want %q", got, want)
|
|
|
}
|
|
|
if got := Normalize(" "); len(got) != 0 {
|
|
|
t.Fatalf("Normalize of spaces = %q", got)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// The vector that wordkey.test.ts of datekeys-ts checks too.
|
|
|
func TestKeyMatchesTypeScript(t *testing.T) {
|
|
|
chain, _ := hex.DecodeString(profile.QuicknetChainHash)
|
|
|
words := []string{"perro", "luna", "casa", "verde", "tren", "mar"}
|
|
|
raw, err := Key(words, chain, 1000)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
if got := hex.EncodeToString(raw); got != "be74aecd9ea734bfece963597a2269188a4ea8a1247bc381dffbd6a38a2c6376" {
|
|
|
t.Fatalf("Key = %s", got)
|
|
|
}
|
|
|
id, err := Identity(words, chain, 1000)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
other, err := Identity(words, chain, 1001)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
if id.Recipient().String() == other.Recipient().String() {
|
|
|
t.Fatal("the round does not change the key")
|
|
|
}
|
|
|
}
|