Skip to content
This repository was archived by the owner on Jul 15, 2018. It is now read-only.

Ledger integration#85

Merged
cwgoes merged 15 commits intodevelopfrom
cwgoes/ledger-integration
May 31, 2018
Merged

Ledger integration#85
cwgoes merged 15 commits intodevelopfrom
cwgoes/ledger-integration

Conversation

@cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Apr 30, 2018

Refactored the existing API, although I'm not quite sure if that interface is necessary - did we use to use this in the keybase more directly?

CC @adrianbrink is #68 a duplicate?

(@liamsi edited to autom. close related issues on merge):
resolves #99
resolves #93

@cwgoes cwgoes requested review from ebuchman and jaekwon as code owners April 30, 2018 14:43
@cwgoes cwgoes changed the title WIP: Ledger integration Ledger integration Apr 30, 2018
@cwgoes
Copy link
Contributor Author

cwgoes commented Apr 30, 2018

Works now. Use WITH_LEDGER=1 make test to run the Ledger testcases (you'll need a physical device plugged in, with the Cosmos app open).

@cwgoes
Copy link
Contributor Author

cwgoes commented Apr 30, 2018

According to Greg, we can ignore the Jenkins failure.

@cwgoes cwgoes mentioned this pull request May 1, 2018
6 tasks
@ebuchman ebuchman mentioned this pull request May 7, 2018
@cwgoes cwgoes force-pushed the cwgoes/ledger-integration branch from 6dd92f7 to 12c0e2c Compare May 14, 2018 13:33
@cwgoes cwgoes force-pushed the cwgoes/ledger-integration branch from 12c0e2c to e6d0ade Compare May 14, 2018 14:24
@cwgoes cwgoes changed the title Ledger integration WIP: Ledger integration May 28, 2018
@cwgoes
Copy link
Contributor Author

cwgoes commented May 28, 2018

  • Needs to be updated for some upstream changes

@cwgoes cwgoes force-pushed the cwgoes/ledger-integration branch from 6da505e to ee411da Compare May 30, 2018 01:43
@cwgoes cwgoes changed the title WIP: Ledger integration Ledger integration May 30, 2018
@cwgoes cwgoes requested a review from ValarDragon May 30, 2018 20:18
@cwgoes
Copy link
Contributor Author

cwgoes commented May 30, 2018

Can be reviewed.

Copy link

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, though I think we may want to test the signing of messages significantly larger than one hash block size.

@cwgoes cwgoes requested a review from liamsi May 30, 2018 21:40
Copy link
Contributor

@liamsi liamsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some minor nitpicks, a few questions

amino.go Outdated
cdc.RegisterConcrete(PubKeyEd25519{},
"tendermint/PubKeyEd25519", nil)
cdc.RegisterConcrete(PubKeyLedgerEd25519{},
"tendermint/PubKeyLedgerEd25519", nil)
Copy link
Contributor

@liamsi liamsi May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Maybe stupid) question: Do we actually need to support Ed25519 here? Isn't this ledger device for end-user wallets? My understanding was we do only use Secp256k1 for user wallets. Might have misunderstood that though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion now removed.

amino.go Outdated
cdc.RegisterConcrete(PrivKeyLedgerSecp256k1{},
"tendermint/PrivKeyLedgerSecp256k1", nil)
cdc.RegisterConcrete(PrivKeyLedgerEd25519{},
"tendermint/PrivKeyLedgerEd25519", nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

"fmt"
"github.com/pkg/errors"

// "github.com/tendermint/ed25519"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File deleted


[[projects]]
branch = "master"
name = "github.com/brejski/hid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this package used anywhere? Can't find it. Is it necessary to include it because of ledger-goclient ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled in because of ledger-goclient, yes

}

// PubKey returns the stored PubKey
// TODO: query the ledger if not there, once it is not volatile
Copy link
Contributor

@liamsi liamsi May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue that keeps track of the open TODOs here?
Group them together and open issues for them. Ideally assign them to someone. Otherwise, they might be forgotten and always stay todos in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, these were left over from an older version of this code, moved to #114

func (pk PrivKeyLedgerEd25519) forceGetPubKey() (key PubKey, err error) {
dev, err := getLedger()
if err != nil {
return key, errors.New(fmt.Sprintf("Cannot connect to Ledger device - error: %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Errorf instead of errors.New(fmt.Sprintf(..? (here and everywhere else)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks

func pubkeyLedgerEd25519(device *ledger.Ledger, path DerivationPath) (pub PubKey, err error) {
key, err := device.GetPublicKeyED25519(path)
if err != nil {
return pub, fmt.Errorf("Error fetching public key: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub will be nil in this case. Make this explicit by writing return nil, fmt.Errof(...). Also, error messages are usually not capitalized (as the error might bubble up and wrapped into another error msg).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, lowercased error messages

}
var p PubKeyLedgerEd25519
copy(p[:], key[0:32])
return p, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err should be nil here. Either write this, or:

var p PubKeyLedgerEd25519
copy(p[:], key[0:32])
pub = p
return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

func signLedgerEd25519(device *ledger.Ledger, path DerivationPath, msg []byte) (sig Signature, err error) {
bsig, err := device.SignED25519(path, msg)
if err != nil {
return sig, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return, similarly below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

@liamsi liamsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all comments addressed :-) LGTM

@cwgoes cwgoes merged commit 2bbad9d into develop May 31, 2018
@cwgoes cwgoes deleted the cwgoes/ledger-integration branch May 31, 2018 19:45
@adrianbrink
Copy link
Contributor

Awesome work @cwgoes @liamsi

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants