Skip to content

Commit

Permalink
Upgrade ledgerjs and fix signing issues (#12)
Browse files Browse the repository at this point in the history
* changes to play nice with latest ledgerjs lib

* more fixes

* fix all signing issues
  • Loading branch information
Bruno Barbieri authored Apr 3, 2019
1 parent 8788c83 commit 3a4a310
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class LedgerBridgeKeyring extends EventEmitter {
params: {
tx: tx.serialize().toString('hex'),
hdPath,
to: ethUtil.bufferToHex(tx.to).toLowerCase()
},
},
({success, payload}) => {
Expand All @@ -184,13 +185,11 @@ class LedgerBridgeKeyring extends EventEmitter {
}

signMessage (withAccount, data) {
throw new Error('Not supported on this device')
return this.signPersonalMessage(withAccount, data);
}

// For personal_sign, we need to prefix the message:
signPersonalMessage (withAccount, message) {
const humanReadableMsg = this._toAscii(message)
const bufferMsg = Buffer.from(humanReadableMsg).toString('hex')
return new Promise((resolve, reject) => {
this.unlock()
.then(_ => {
Expand All @@ -205,7 +204,7 @@ class LedgerBridgeKeyring extends EventEmitter {
action: 'ledger-sign-personal-message',
params: {
hdPath,
message: bufferMsg,
message: ethUtil.stripHexPrefix(message),
},
},
({success, payload}) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eth-ledger-bridge-keyring",
"version": "0.1.1",
"version": "0.2.0",
"description": "A MetaMask compatible keyring, for ledger hardware wallets",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 9 additions & 4 deletions test/test-eth-ledger-bridge-keyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,15 @@ describe('LedgerBridgeKeyring', function () {
})

describe('signMessage', function () {
it('should throw an error because it is not supported', function () {
expect(_ => {
keyring.signMessage()
}).to.throw('Not supported on this device')
it('should call create a listener waiting for the iframe response', function (done) {

chai.spy.on(window, 'addEventListener')
setTimeout(_ => {
keyring.signPersonalMessage(fakeAccounts[0], '0x123')
expect(window.addEventListener).to.have.been.calledWith('message')
}, 1800)
chai.spy.restore(window, 'addEventListener')
done()
})
})

Expand Down

0 comments on commit 3a4a310

Please sign in to comment.