Repository: vegaprotocol/vegawallet (go)

Issue:
Add wallet version to `key generate` output
This is an important information to be returned, and because of the algorithm version, it's sometimes misunderstood.

Pull request description:
Add wallet version to `key generate` output
Close #380 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3226c67..f809577 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 ## Unreleased (0.11.0)
 
+### Improvements
+- [383](https://github.com/vegaprotocol/vegawallet/pull/383) - Add wallet version to `key generate` output
 
 ## 0.10.0
 *2021-11-15*
diff --git a/cmd/key_generate.go b/cmd/key_generate.go
index db62e82..f5161d2 100644
--- a/cmd/key_generate.go
+++ b/cmd/key_generate.go
@@ -155,6 +155,8 @@ func PrintGenerateKeyResponse(w io.Writer, resp *wallet.GenerateKeyResponse) {
 	if walletHasBeenCreated {
 		p.Text("Wallet mnemonic:").NextLine()
 		p.WarningText(resp.Wallet.Mnemonic).NextLine()
+		p.Text("Wallet version:").NextLine()
+		p.WarningText(fmt.Sprintf("%d", resp.Wallet.Version)).NextLine()
 	}
 	p.Text("Public key:").NextLine()
 	p.WarningText(resp.Key.KeyPair.PublicKey).NextLine()
diff --git a/wallet/handler.go b/wallet/handler.go
index 8009b1e..6da6648 100644
--- a/wallet/handler.go
+++ b/wallet/handler.go
@@ -24,6 +24,7 @@ type GenerateKeyRequest struct {
 type GenerateKeyResponse struct {
 	Wallet struct {
 		Name     string `json:"name"`
+		Version  uint32 `json:"version"`
 		FilePath string `json:"filePath"`
 		Mnemonic string `json:"mnemonic,omitempty"`
 	} `json:"wallet"`
@@ -77,6 +78,7 @@ func GenerateKey(store Store, req *GenerateKeyRequest) (*GenerateKeyResponse, er
 	}
 
 	resp.Wallet.Name = req.Wallet
+	resp.Wallet.Version = wal.Version()
 	resp.Wallet.FilePath = store.GetWalletPath(req.Wallet)
 	resp.Key.KeyPair.PublicKey = kp.PublicKey()
 	resp.Key.KeyPair.PrivateKey = kp.PrivateKey()


Test patch:
diff --git a/tests/commands_for_test.go b/tests/commands_for_test.go
index 8b85b48..c90cf27 100644
--- a/tests/commands_for_test.go
+++ b/tests/commands_for_test.go
@@ -73,6 +73,7 @@ func KeyAnnotate(t *testing.T, args []string) error {
 type GenerateKeyResponse struct {
 	Wallet struct {
 		Name     string `json:"name"`
+		Version  uint32 `json:"version"`
 		FilePath string `json:"filePath"`
 		Mnemonic string `json:"mnemonic,omitempty"`
 	} `json:"wallet"`
@@ -117,12 +118,13 @@ func AssertGenerateKey(t *testing.T, resp *GenerateKeyResponse) *GenerateKeyAsse
 
 	assert.NotNil(t, resp)
 	assert.NotEmpty(t, resp.Wallet.Name)
+	assert.NotEmpty(t, resp.Wallet.Version)
 	assert.NotEmpty(t, resp.Wallet.FilePath)
 	assert.FileExists(t, resp.Wallet.FilePath)
 	assert.NotEmpty(t, resp.Key.KeyPair.PublicKey)
 	assert.NotEmpty(t, resp.Key.KeyPair.PrivateKey)
-	assert.NotEmpty(t, resp.Key.Algorithm.Name)
-	assert.NotEmpty(t, resp.Key.Algorithm.Version)
+	assert.Equal(t, "vega/ed25519", resp.Key.Algorithm.Name)
+	assert.Equal(t, uint32(1), resp.Key.Algorithm.Version)
 
 	return &GenerateKeyAssertion{
 		t:    t,
@@ -145,6 +147,11 @@ func (a *GenerateKeyAssertion) WithName(expected string) *GenerateKeyAssertion {
 	return a
 }
 
+func (a *GenerateKeyAssertion) WithVersion(expected uint32) *GenerateKeyAssertion {
+	assert.Equal(a.t, expected, a.resp.Wallet.Version)
+	return a
+}
+
 func (a *GenerateKeyAssertion) WithMeta(expected map[string]string) *GenerateKeyAssertion {
 	meta := map[string]string{}
 	for _, m := range a.resp.Key.Meta {
diff --git a/tests/sc_annotate_key_test.go b/tests/sc_annotate_key_test.go
index 98a4d80..42b9d1a 100644
--- a/tests/sc_annotate_key_test.go
+++ b/tests/sc_annotate_key_test.go
@@ -33,6 +33,7 @@ func TestAnnotateKey(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)
 
diff --git a/tests/sc_create_wallet_test.go b/tests/sc_create_wallet_test.go
index 6c84e9d..5f5f7b1 100644
--- a/tests/sc_create_wallet_test.go
+++ b/tests/sc_create_wallet_test.go
@@ -30,6 +30,7 @@ func TestCreateWallet(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)
 
diff --git a/tests/sc_describe_key_test.go b/tests/sc_describe_key_test.go
index 84e2a2d..4875504 100644
--- a/tests/sc_describe_key_test.go
+++ b/tests/sc_describe_key_test.go
@@ -33,6 +33,7 @@ func TestDescribeKey(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)
 
diff --git a/tests/sc_generate_keys_test.go b/tests/sc_generate_keys_test.go
index 144a510..13e49d8 100644
--- a/tests/sc_generate_keys_test.go
+++ b/tests/sc_generate_keys_test.go
@@ -33,6 +33,7 @@ func TestGenerateAndListKeys(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp1).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)
 
@@ -56,6 +57,7 @@ func TestGenerateAndListKeys(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp2).
 		WithoutWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": DefaultMetaName(t, walletName, 2)}).
 		LocatedUnder(home)
 
diff --git a/tests/sc_import_wallet_test.go b/tests/sc_import_wallet_test.go
index d2b0923..0cfac03 100644
--- a/tests/sc_import_wallet_test.go
+++ b/tests/sc_import_wallet_test.go
@@ -76,6 +76,7 @@ func TestImportWalletV1(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithoutWalletCreation().
 		WithName(walletName).
+		WithVersion(1).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		WithPublicKey("30ebce58d94ad37c4ff6a9014c955c20e12468da956163228cc7ec9b98d3a371").
 		WithPrivateKey("1bbd4efb460d0bf457251e866697d5d2e9b58c5dcb96a964cd9cfff1a712a2b930ebce58d94ad37c4ff6a9014c955c20e12468da956163228cc7ec9b98d3a371").
@@ -151,6 +152,7 @@ func TestImportWalletV2(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithoutWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		WithPublicKey("b5fd9d3c4ad553cb3196303b6e6df7f484cf7f5331a572a45031239fd71ad8a0").
 		WithPrivateKey("0bfdfb4a04e22d7252a4f24eb9d0f35a82efdc244cb0876d919361e61f6f56a2b5fd9d3c4ad553cb3196303b6e6df7f484cf7f5331a572a45031239fd71ad8a0").
diff --git a/tests/sc_isolate_wallet_test.go b/tests/sc_isolate_wallet_test.go
index e3b6473..e6cf15a 100644
--- a/tests/sc_isolate_wallet_test.go
+++ b/tests/sc_isolate_wallet_test.go
@@ -30,6 +30,7 @@ func TestIsolateWallet(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp1).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)
 
diff --git a/tests/sc_list_keys_test.go b/tests/sc_list_keys_test.go
index bfbaa19..7511f79 100644
--- a/tests/sc_list_keys_test.go
+++ b/tests/sc_list_keys_test.go
@@ -31,6 +31,7 @@ func TestListKeys(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp1).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)
 
diff --git a/tests/sc_rename_wallet_test.go b/tests/sc_rename_wallet_test.go
index a9b31a5..9ff58a0 100644
--- a/tests/sc_rename_wallet_test.go
+++ b/tests/sc_rename_wallet_test.go
@@ -32,6 +32,7 @@ func TestRenameWallet(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		LocatedUnder(home)
 
 	// given
diff --git a/tests/sc_sign_and_verify_message_test.go b/tests/sc_sign_and_verify_message_test.go
index 402f610..caf8995 100644
--- a/tests/sc_sign_and_verify_message_test.go
+++ b/tests/sc_sign_and_verify_message_test.go
@@ -50,6 +50,7 @@ func TestSignMessage(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp).
 		WithoutWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		WithPublicKey("b5fd9d3c4ad553cb3196303b6e6df7f484cf7f5331a572a45031239fd71ad8a0").
 		WithPrivateKey("0bfdfb4a04e22d7252a4f24eb9d0f35a82efdc244cb0876d919361e61f6f56a2b5fd9d3c4ad553cb3196303b6e6df7f484cf7f5331a572a45031239fd71ad8a0").
diff --git a/tests/sc_taint_key_test.go b/tests/sc_taint_key_test.go
index ac3fa47..db1cbef 100644
--- a/tests/sc_taint_key_test.go
+++ b/tests/sc_taint_key_test.go
@@ -33,6 +33,7 @@ func TestTaintKeys(t *testing.T) {
 	AssertGenerateKey(t, generateKeyResp1).
 		WithWalletCreation().
 		WithName(walletName).
+		WithVersion(2).
 		WithMeta(map[string]string{"name": "key-1", "role": "validation"}).
 		LocatedUnder(home)