diff --git a/core/commands/dht.go b/core/commands/dht.go index 8c77b0235..4319b15da 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -573,7 +573,7 @@ func escapeDhtKey(s string) (key.Key, error) { return key.B58KeyDecode(s), nil case 3: k := key.B58KeyDecode(parts[2]) - return key.Key(path.Join(append(parts[:2], k.String()))), nil + return key.Key(path.Join(append(parts[:2], string(k)))), nil default: return "", errors.New("invalid key") } diff --git a/core/commands/dht_test.go b/core/commands/dht_test.go new file mode 100644 index 000000000..bf75aff98 --- /dev/null +++ b/core/commands/dht_test.go @@ -0,0 +1,31 @@ +package commands + +import ( + "testing" + + "github.com/ipfs/go-ipfs/namesys" + tu "github.com/ipfs/go-ipfs/thirdparty/testutil" +) + +func TestKeyTranslation(t *testing.T) { + pid := tu.RandPeerIDFatal(t) + a, b := namesys.IpnsKeysForID(pid) + + pkk, err := escapeDhtKey("/pk/" + pid.Pretty()) + if err != nil { + t.Fatal(err) + } + + ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty()) + if err != nil { + t.Fatal(err) + } + + if pkk != a { + t.Fatal("keys didnt match!") + } + + if ipnsk != b { + t.Fatal("keys didnt match!") + } +}