Skip to content

Commit

Permalink
fix(@libp2p/crypto): improve unsupported key type message (#2051)
Browse files Browse the repository at this point in the history
When an unsupported key type is encountered, but the type is actually missing from the protobuf, don't default the key type in the thrown error to `RSA` because it's not an RSA key, doing so is leads to confusing messages like:

```
invalid or unsupported key type RSA. Must be rsa / ed25519 / secp256k1
```

Instead say that the key type is unknown.

Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
  • Loading branch information
achingbrain and maschad authored Sep 15, 2023
1 parent 20d5f22 commit d9159dd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function unmarshalPublicKey (buf: Uint8Array): PublicKey {
case keysPBM.KeyType.Secp256k1:
return supportedKeys.secp256k1.unmarshalSecp256k1PublicKey(data)
default:
throw unsupportedKey(decoded.Type ?? 'RSA')
throw unsupportedKey(decoded.Type ?? 'unknown')
}
}

Expand Down

0 comments on commit d9159dd

Please sign in to comment.