Skip to content

Commit 57e4e21

Browse files
Merge pull request #3734 from ipfs/feat/keystore/list-self
keystore: add self key to the listing
2 parents 1ef5ecb + fe0cc96 commit 57e4e21

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

core/commands/keystore.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var KeyGenCmd = &cmds.Command{
4040
Tagline: "Create a new keypair",
4141
},
4242
Options: []cmds.Option{
43-
cmds.StringOption("type", "t", "type of the key to create"),
43+
cmds.StringOption("type", "t", "type of the key to create [rsa, ed25519]"),
4444
cmds.IntOption("size", "s", "size of the key to generate"),
4545
},
4646
Arguments: []cmds.Argument{
@@ -160,7 +160,9 @@ var KeyListCmd = &cmds.Command{
160160

161161
sort.Strings(keys)
162162

163-
list := make([]KeyOutput, 0, len(keys))
163+
list := make([]KeyOutput, 0, len(keys)+1)
164+
165+
list = append(list, KeyOutput{Name: "self", Id: n.Identity.Pretty()})
164166

165167
for _, key := range keys {
166168
privKey, err := n.Repo.Keystore().Get(key)

test/sharness/t0165-keystore.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test_key_cmd() {
2222
test_expect_success "both keys show up in list output" '
2323
echo bazed > list_exp &&
2424
echo foobarsa >> list_exp &&
25+
echo self >> list_exp
2526
ipfs key list | sort > list_out &&
2627
test_cmp list_exp list_out
2728
'
@@ -30,6 +31,11 @@ test_key_cmd() {
3031
ipfs key list -l | grep $edhash > /dev/null &&
3132
ipfs key list -l | grep $rsahash > /dev/null
3233
'
34+
35+
test_expect_success "key list -l contains self key with peerID" '
36+
PeerID="$(ipfs config Identity.PeerID)"
37+
ipfs key list -l | grep "$PeerID self"
38+
'
3339
}
3440

3541
test_key_cmd

0 commit comments

Comments
 (0)