This commit is contained in:
Andrew Gillis 2026-01-06 23:10:43 -08:00 committed by GitHub
commit f6f6831130
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 9 deletions

View File

@ -458,7 +458,7 @@ var keyListCmd = &cmds.Command{
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.OptionIPNSBase.Name()].(string))
if err != nil {
return err
return fmt.Errorf("cannot get key encoder: %w", err)
}
api, err := cmdenv.GetApi(env, req)
@ -468,7 +468,7 @@ var keyListCmd = &cmds.Command{
keys, err := api.Key().List(req.Context)
if err != nil {
return err
return fmt.Errorf("listing keys failed: %w", err)
}
list := make([]KeyOutput, 0, len(keys))

View File

@ -29,7 +29,7 @@ type key struct {
func newKey(name string, pid peer.ID) (*key, error) {
p, err := path.NewPath("/ipns/" + ipns.NameFromPeer(pid).String())
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot create new key: %w", err)
}
return &key{
name: name,
@ -121,34 +121,37 @@ func (api *KeyAPI) List(ctx context.Context) ([]coreiface.Key, error) {
keys, err := api.repo.Keystore().List()
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot list keys in keystore: %w", err)
}
sort.Strings(keys)
out := make([]coreiface.Key, len(keys)+1)
out := make([]coreiface.Key, 1, len(keys)+1)
out[0], err = newKey("self", api.identity)
if err != nil {
return nil, err
}
for n, k := range keys {
for _, k := range keys {
privKey, err := api.repo.Keystore().Get(k)
if err != nil {
return nil, err
log.Errorf("cannot get key from keystore: %s", err)
continue
}
pubKey := privKey.GetPublic()
pid, err := peer.IDFromPublicKey(pubKey)
if err != nil {
return nil, err
log.Errorf("cannot decode public key: %s", err)
continue
}
out[n+1], err = newKey(k, pid)
k, err := newKey(k, pid)
if err != nil {
return nil, err
}
out = append(out, k)
}
return out, nil
}

View File

@ -12,6 +12,7 @@ This release was brought to you by the [Shipyard](https://ipshipyard.com/) team.
- [🔦 Highlights](#-highlights)
- [Routing V1 HTTP API now exposed by default](#routing-v1-http-api-now-exposed-by-default)
- [Track total size when adding pins](#track-total-size-when-adding-pins)
- [Skip bad keys when listing](#skip_bad_keys_when_listing)
- [📦️ Dependency updates](#-dependency-updates)
- [📝 Changelog](#-changelog)
- [👨‍👩‍👧‍👦 Contributors](#-contributors)
@ -33,6 +34,10 @@ Example output:
Fetched/Processed 336 nodes (83 MB)
```
#### Skip bad keys when listing
Change the `ipfs key list` behavior to log an error and continue listing keys when a key cannot be read from the keystore or decoded.
#### 📦️ Dependency updates
- update `go-libp2p` to [v0.46.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.46.0)