From 3a4a310ebb1e03366919d106bfa956df79d410a8 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 3 Apr 2019 13:04:35 -0400 Subject: [PATCH] Upgrade ledgerjs and fix signing issues (#12) * changes to play nice with latest ledgerjs lib * more fixes * fix all signing issues --- index.js | 7 +++---- package.json | 2 +- test/test-eth-ledger-bridge-keyring.js | 13 +++++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index e1d6c5c7..7cb91a84 100644 --- a/index.js +++ b/index.js @@ -160,6 +160,7 @@ class LedgerBridgeKeyring extends EventEmitter { params: { tx: tx.serialize().toString('hex'), hdPath, + to: ethUtil.bufferToHex(tx.to).toLowerCase() }, }, ({success, payload}) => { @@ -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(_ => { @@ -205,7 +204,7 @@ class LedgerBridgeKeyring extends EventEmitter { action: 'ledger-sign-personal-message', params: { hdPath, - message: bufferMsg, + message: ethUtil.stripHexPrefix(message), }, }, ({success, payload}) => { diff --git a/package.json b/package.json index 4831af21..e3c68226 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/test-eth-ledger-bridge-keyring.js b/test/test-eth-ledger-bridge-keyring.js index a8ab99f0..56330c92 100644 --- a/test/test-eth-ledger-bridge-keyring.js +++ b/test/test-eth-ledger-bridge-keyring.js @@ -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() }) })