diff --git a/cmd/skywire-cli/commands/pk.go b/cmd/skywire-cli/commands/pk.go new file mode 100644 index 000000000..7bd96fc1f --- /dev/null +++ b/cmd/skywire-cli/commands/pk.go @@ -0,0 +1,27 @@ +package commands + +import ( + "fmt" + "log" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(pkCmd) +} + +var pkCmd = &cobra.Command{ + Use: "pk", + Short: "get public key of node", + Run: func(_ *cobra.Command, _ []string) { + + client := rpcClient() + summary, err := client.Summary() + if err != nil { + log.Fatal("Failed to connect:", err) + } + + fmt.Println(summary.PubKey) + }, +} diff --git a/pkg/messaging-discovery/client/examples/client_test.go b/pkg/messaging-discovery/client/examples/client_test.go deleted file mode 100644 index db15dcdb2..000000000 --- a/pkg/messaging-discovery/client/examples/client_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// +build integration - -package client_test - -import ( - "context" - "fmt" - - "github.com/skycoin/skywire/pkg/messaging-discovery/client" - "github.com/skycoin/skywire/pkg/transport" -) - -func Example() { - // Connects the client to a local messaging-discovery server listening in port 8080 - apiClient := client.New("http://localhost:8080") - - // Create keypairs to use with the Client entry - pk, sk := transport.GenerateDeterministicKeyPair([]byte(`example`)) - - // Create client metadata - clientData := client.NewClient(nil, nil) - - // Create ephemeral keys metadata - ephemeralKeys := []client.ServerKeys{ - client.NewEphemeralKeys("ephemeralKey1", "staticServerKey"), - client.NewEphemeralKeys("ephemeralKey2", "staticServerKey"), - } - - // Create client entry, which iteration sequence is 0 - entry := client.NewClientEntry(pk, 0, clientData, ephemeralKeys) - - // Use the secret key to sign the entry - entry.Sign(sk) - - // Use the client to set the new entry in the messaging-discovery server - err := apiClient.SetEntry(context.TODO(), entry) - if err != nil { - panic(err) - } - - // Use the client to retrieve the entry associated to the public key - retrievedEntry, err := apiClient.Entry(context.TODO(), pk) - if err != nil { - panic(err) - } - - fmt.Println("original entry pk: ", entry.Keys.Static) - fmt.Println("recovered entry pk: ", retrievedEntry.Keys.Static) - - // You can also update the entry calling update entry method - // Internally it will update the sequence and re-sign the entry before calling set - entry.Version = "1" - apiClient.UpdateEntry(context.TODO(), sk, entry) - - retrievedEntry, err = apiClient.Entry(context.TODO(), pk) - if err != nil { - panic(err) - } - - fmt.Println("version of retrieved entry: ", retrievedEntry.Version) - - // Create a server entry, this one will update the previous entry - // associated with the public key, we set the iteration sequence to 1 - serverData := client.NewServer("localhost:8080", 5) - serverEntry := client.NewServerEntry(pk, 1, serverData) - serverEntry.Sign(sk) - - // Update the server entry - err = apiClient.UpdateEntry(context.TODO(), sk, serverEntry) - if err != nil { - panic(err) - } - - // Use the client library to retrieve an array of server entries from the messaging-discovery server - entries, err := apiClient.AvailableServers(context.TODO()) - if err != nil { - panic(err) - } - - fmt.Println("server entry pk: ", serverEntry.Keys.Static) - fmt.Println("retrieved server entry pk: ", entries[0].Keys.Static) - - // Output: - // original entry pk: 02ca451b007ee2f00324fb95475d5a194b1b7a15dbf61c728ec97168ad03f9bdd8 - // recovered entry pk: 02ca451b007ee2f00324fb95475d5a194b1b7a15dbf61c728ec97168ad03f9bdd8 - // version of retrieved entry: 1 - // server entry pk: 02ca451b007ee2f00324fb95475d5a194b1b7a15dbf61c728ec97168ad03f9bdd8 - // retrieved server entry pk: 02ca451b007ee2f00324fb95475d5a194b1b7a15dbf61c728ec97168ad03f9bdd8 -} diff --git a/pkg/transport/manager_test.go b/pkg/transport/manager_test.go index a7155517d..c8e9bc1a5 100644 --- a/pkg/transport/manager_test.go +++ b/pkg/transport/manager_test.go @@ -13,7 +13,7 @@ import ( "github.com/skycoin/skywire/pkg/cipher" ) -func TestTransportManger(t *testing.T) { +func TestTransportManager(t *testing.T) { client := NewDiscoveryMock() logStore := InMemoryTransportLogStore() @@ -101,7 +101,7 @@ func TestTransportManger(t *testing.T) { mu.Unlock() } -func TestTransportMangerReEstablishTransports(t *testing.T) { +func TestTransportManagerReEstablishTransports(t *testing.T) { client := NewDiscoveryMock() logStore := InMemoryTransportLogStore() @@ -157,7 +157,7 @@ func TestTransportMangerReEstablishTransports(t *testing.T) { require.NoError(t, <-errCh) } -func TestTransportMangerLogs(t *testing.T) { +func TestTransportManagerLogs(t *testing.T) { client := NewDiscoveryMock() logStore1 := InMemoryTransportLogStore() logStore2 := InMemoryTransportLogStore()