Repository: vegaprotocol/vegawallet
Pull request #403 (2021-11-26 17:51:30)

Tidy up network list command example


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6565f9b..acb9257 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,6 @@
 
 ### 🐛 Fixes
 - [395](https://github.com/vegaprotocol/vegawallet/pull/395) - Fix `command send` examples
-- [401](https://github.com/vegaprotocol/vegawallet/pull/400) - Update key rotation submission command
 
 ## 0.10.0
 *2021-11-15*
diff --git a/cmd/network_list.go b/cmd/network_list.go
index c1a720f..65465ca 100644
--- a/cmd/network_list.go
+++ b/cmd/network_list.go
@@ -20,7 +20,7 @@ var (
 
 	listNetworkExample = cli.Examples(`
 		# List networks
-		vegawallet network list"
+		vegawallet network list
 	`)
 )
 
diff --git a/go.mod b/go.mod
index 6c5a305..5b950a7 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module code.vegaprotocol.io/vegawallet
 go 1.17
 
 require (
-	code.vegaprotocol.io/protos v0.46.1-0.20211124140330-6f1ee8ac737e
+	code.vegaprotocol.io/protos v0.45.2-0.20211116120935-7f71d8b3c70e
 	code.vegaprotocol.io/shared v0.0.0-20211015074835-9ed837d93090
 	github.com/blang/semver/v4 v4.0.0
 	github.com/cenkalti/backoff/v4 v4.0.2
diff --git a/go.sum b/go.sum
index b4b4870..a453951 100644
--- a/go.sum
+++ b/go.sum
@@ -12,8 +12,6 @@ cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2k
 cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
 code.vegaprotocol.io/protos v0.45.2-0.20211116120935-7f71d8b3c70e h1:CVfa4wmUY2touFMHa2Ti29ZKsPif64EDvH6nljC/LAk=
 code.vegaprotocol.io/protos v0.45.2-0.20211116120935-7f71d8b3c70e/go.mod h1:NORK22Evpwn0GoetL7H6/oVUzGcfjAJEJTzw+zTkSyE=
-code.vegaprotocol.io/protos v0.46.1-0.20211124140330-6f1ee8ac737e h1:nru0Y8/D/ipsBTUYvtGFsNjJErJreZZa4Kvas2HDYRo=
-code.vegaprotocol.io/protos v0.46.1-0.20211124140330-6f1ee8ac737e/go.mod h1:NORK22Evpwn0GoetL7H6/oVUzGcfjAJEJTzw+zTkSyE=
 code.vegaprotocol.io/shared v0.0.0-20211015074835-9ed837d93090 h1:SF7ZRvZ/JASJNEQigbuUwk1rQuugLy6gqbOFs8D8VXI=
 code.vegaprotocol.io/shared v0.0.0-20211015074835-9ed837d93090/go.mod h1:dmahiiphuDJvjXXDvQvo22tFPx7yk9wW8z1glU/JgHE=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
diff --git a/wallet/handler.go b/wallet/handler.go
index 873c34d..6d4e392 100644
--- a/wallet/handler.go
+++ b/wallet/handler.go
@@ -301,9 +301,10 @@ func RotateKey(store Store, req *RotateKeyRequest) (*RotateKeyResponse, error) {
 	inputData := commands.NewInputData(req.TxBlockHeight)
 	inputData.Command = &commandspb.InputData_KeyRotateSubmission{
 		KeyRotateSubmission: &commandspb.KeyRotateSubmission{
-			KeyNumber:   pubKey.Index(),
-			TargetBlock: req.TargetBlockHeight,
-			NewPubKey:   pubKey.Key(),
+			KeyNumber:     pubKey.Index(),
+			TargetBlock:   req.TargetBlockHeight,
+			Time:          0, // @TODO fill this
+			NewPubKeyHash: pubKey.Hash(),
 		},
 	}
 
diff --git a/wallet/hd_public_key.go b/wallet/hd_public_key.go
index 24aff0e..6358e5a 100644
--- a/wallet/hd_public_key.go
+++ b/wallet/hd_public_key.go
@@ -1,7 +1,10 @@
 package wallet
 
 import (
+	"encoding/hex"
 	"encoding/json"
+
+	vgcrypto "code.vegaprotocol.io/shared/libs/crypto"
 )
 
 type HDPublicKey struct {
@@ -47,3 +50,7 @@ func (k *HDPublicKey) UnmarshalJSON(data []byte) error {
 	aliasPublicKey := (*alias)(k)
 	return json.Unmarshal(data, aliasPublicKey)
 }
+
+func (k *HDPublicKey) Hash() string {
+	return hex.EncodeToString(vgcrypto.Hash([]byte(k.PublicKey)))
+}
diff --git a/wallet/wallet.go b/wallet/wallet.go
index 0a9bd17..b5ec6b5 100644
--- a/wallet/wallet.go
+++ b/wallet/wallet.go
@@ -41,6 +41,7 @@ type PublicKey interface {
 	Index() uint32
 	AlgorithmVersion() uint32
 	AlgorithmName() string
+	Hash() string
 
 	MarshalJSON() ([]byte, error)
 	UnmarshalJSON(data []byte) error


Test patch:
diff --git a/wallet/handler_test.go b/wallet/handler_test.go
index 4655010..b65822b 100644
--- a/wallet/handler_test.go
+++ b/wallet/handler_test.go
@@ -2,11 +2,13 @@ package wallet_test
 
 import (
 	"encoding/base64"
+	"encoding/hex"
 	"fmt"
 	"sort"
 	"testing"
 
 	commandspb "code.vegaprotocol.io/protos/vega/commands/v1"
+	vgcrypto "code.vegaprotocol.io/shared/libs/crypto"
 	vgrand "code.vegaprotocol.io/shared/libs/rand"
 	"code.vegaprotocol.io/vegawallet/wallet"
 	"code.vegaprotocol.io/vegawallet/wallet/mocks"
@@ -570,6 +572,8 @@ func testRotateKeySucceeds(t *testing.T) {
 		TargetBlockHeight: 25,
 	}
 
+	expectedNewPubHash := hex.EncodeToString(vgcrypto.Hash([]byte(req.PublicKey)))
+
 	// setup
 	store := handlerMocks(t)
 	store.EXPECT().WalletExists(req.Wallet).Times(1).Return(true)
@@ -601,7 +605,7 @@ func testRotateKeySucceeds(t *testing.T) {
 	require.Equal(t, req.TxBlockHeight, inputData.BlockHeight)
 	require.Equal(t, kp.Index(), keyRotate.KeyRotateSubmission.KeyNumber)
 	require.Equal(t, req.TargetBlockHeight, keyRotate.KeyRotateSubmission.TargetBlock)
-	require.Equal(t, req.PublicKey, keyRotate.KeyRotateSubmission.NewPubKey)
+	require.Equal(t, expectedNewPubHash, keyRotate.KeyRotateSubmission.NewPubKeyHash)
 }
 
 func testRotateWithNonExistingWalletFails(t *testing.T) {