|
|
@ -1,4 +1,3 @@ |
|
|
|
const extension = require('extensionizer') |
|
|
|
|
|
|
|
const {EventEmitter} = require('events') |
|
|
|
const {EventEmitter} = require('events') |
|
|
|
const HDKey = require('hdkey') |
|
|
|
const HDKey = require('hdkey') |
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
@ -218,19 +217,32 @@ class LedgerKeyring extends EventEmitter { |
|
|
|
|
|
|
|
|
|
|
|
// For personal_sign, we need to prefix the message:
|
|
|
|
// For personal_sign, we need to prefix the message:
|
|
|
|
async signPersonalMessage (withAccount, message) { |
|
|
|
async signPersonalMessage (withAccount, message) { |
|
|
|
|
|
|
|
const humanReadableMsg = this._toAscii(message) |
|
|
|
|
|
|
|
const bufferMsg = Buffer.from(humanReadableMsg).toString('hex') |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
this.unlock() |
|
|
|
this.unlock() |
|
|
|
.then(_ => { |
|
|
|
.then(_ => { |
|
|
|
this.sendMessage({ |
|
|
|
this.sendMessage({ |
|
|
|
action: 'ledger-sign-personal-message', |
|
|
|
action: 'ledger-sign-personal-message', |
|
|
|
params: { |
|
|
|
params: { |
|
|
|
withAccount, |
|
|
|
path: this._pathFromAddress(withAccount ), |
|
|
|
message, |
|
|
|
message: bufferMsg, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
({action, success, payload}) => { |
|
|
|
({action, success, payload}) => { |
|
|
|
if (success) { |
|
|
|
if (success) { |
|
|
|
resolve(payload) |
|
|
|
const { result } = payload |
|
|
|
|
|
|
|
let v = result['v'] - 27 |
|
|
|
|
|
|
|
v = v.toString(16) |
|
|
|
|
|
|
|
if (v.length < 2) { |
|
|
|
|
|
|
|
v = `0${v}` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const signature = `0x${result['r']}${result['s']}${v}` |
|
|
|
|
|
|
|
const addressSignedWith = sigUtil.recoverPersonalSignature({data: message, sig: signature}) |
|
|
|
|
|
|
|
if (ethUtil.toChecksumAddress(addressSignedWith) !== ethUtil.toChecksumAddress(withAccount)) { |
|
|
|
|
|
|
|
reject('signature doesnt match the right address') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resolve(signature) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
reject(payload) |
|
|
|
reject(payload) |
|
|
|
} |
|
|
|
} |
|
|
|