-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Ledger secp256k1 privkey to proto.Message #7872
Conversation
@@ -0,0 +1,17 @@ | |||
syntax = "proto3"; | |||
package cosmos.crypto.ledger.secp256k1.v1beta1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of the cached_pub_key
field below, I prefer to keep it as beta for now. imo cached_pub_key
should be an implementation detail, and not exposed in proto definitions (but at the same time it's super useful).
Codecov Report
@@ Coverage Diff @@
## master #7872 +/- ##
==========================================
- Coverage 61.51% 61.45% -0.07%
==========================================
Files 605 607 +2
Lines 34721 34779 +58
==========================================
+ Hits 21358 21372 +14
- Misses 11140 11183 +43
- Partials 2223 2224 +1
|
require.Nil(t, err, "%s", err) | ||
require.NotNil(t, priv) | ||
|
||
require.Equal(t, "eb5ae98721034fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe87", | ||
fmt.Sprintf("%x", cdc.Amino.MustMarshalBinaryBare(priv.PubKey())), | ||
require.Equal(t, "034fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe87", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switching from amino to proto removes the first 5 bytes.
@@ -82,7 +83,7 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) { | |||
// Store and restore | |||
serializedPk := priv.Bytes() | |||
require.NotNil(t, serializedPk) | |||
require.True(t, len(serializedPk) >= 50) | |||
require.True(t, len(serializedPk) >= 40) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switching to proto, the serialized private key seems to be shorter. Why did we need 50 before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a prefix?
does this require changes in the ledger app? |
Good question. I didn't change the code Who's the person maintaining the ledger app? |
@jleni Is the person to ask. |
…s-sdk into am-7357-ledgerprivkey
amino.PrintTypes(os.Stdout) | ||
// Output: | ||
// | Type | Name | Prefix | Length | Notes | | ||
// | ---- | ---- | ------ | ----- | ------ | | ||
// | PubKey | tendermint/PubKeySr25519 | 0x0DFB1005 | variable | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that I explicitly removed amino support for PrivKeyLedgerSecp256k1. I cannot see where it's needed, but if it's needed, I can add it back (in the same way we do for other pubkeys).
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
ref: #7357 (comment)
Problem
The SDK primarily manages 2 private key types: secp256k1 and ed25519. Both are defined as proto messages.
However, there's a 3rd private key type,
PrivKeyLedgerSecp256k1
, that has not been converted to a proto message. This creates asymmetries in ourcryptotypes.PrivKey
interface, namely, should it extendproto.Message
?cosmos-sdk/crypto/ledger/ledger_secp256k1.go
Lines 40 to 48 in 90e9370
Solution
I see two solutions:
cryptotypes.PrivKey
does not extendproto.Message
. There's actually no reason in the SDK that we require private keys to be proto Messages.Convert
PrivKeyLedgerSecp256k1
to aproto.Message
.I personally see having all our private keys defined as
proto.Message
a better solution. Even if technically aproto.Message
is not needed in the SDK for managing private keys, it still gives us the stability guarantees that come with protobuf. This PR implements solution 2. Moreover, it removes dependency ofPrivKeyLedgerSecp256k1
on amino.Let me know your thoughts.
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes