mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
message signing works
This commit is contained in:
parent
068bf43615
commit
e6d64cecf8
@ -1,4 +1,3 @@
|
||||
const extension = require('extensionizer')
|
||||
const {EventEmitter} = require('events')
|
||||
const HDKey = require('hdkey')
|
||||
const ethUtil = require('ethereumjs-util')
|
||||
@ -202,7 +201,7 @@ class LedgerKeyring extends EventEmitter {
|
||||
const correctAddress = ethUtil.toChecksumAddress(address)
|
||||
if (addressSignedWith !== correctAddress) {
|
||||
reject('signature doesnt match the right address')
|
||||
}
|
||||
}
|
||||
resolve(signedTx)
|
||||
} else {
|
||||
reject(payload)
|
||||
@ -218,19 +217,32 @@ class LedgerKeyring extends EventEmitter {
|
||||
|
||||
// For personal_sign, we need to prefix the message:
|
||||
async signPersonalMessage (withAccount, message) {
|
||||
const humanReadableMsg = this._toAscii(message)
|
||||
const bufferMsg = Buffer.from(humanReadableMsg).toString('hex')
|
||||
return new Promise((resolve, reject) => {
|
||||
this.unlock()
|
||||
.then(_ => {
|
||||
this.sendMessage({
|
||||
action: 'ledger-sign-personal-message',
|
||||
params: {
|
||||
withAccount,
|
||||
message,
|
||||
path: this._pathFromAddress(withAccount ),
|
||||
message: bufferMsg,
|
||||
},
|
||||
},
|
||||
({action, success, payload}) => {
|
||||
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 {
|
||||
reject(payload)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ function createLoggerMiddleware (opts) {
|
||||
log.error('Error in RPC response:\n', res)
|
||||
}
|
||||
if (req.isMetamaskInternal) return
|
||||
log.info(`RPC (${opts.origin}):`, req, '->', res)
|
||||
//log.info(`RPC (${opts.origin}):`, req, '->', res)
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
@ -412,6 +412,7 @@
|
||||
min-height: 54px;
|
||||
font-weight: 300;
|
||||
font-size: 14px;
|
||||
margin-bottom: 20px
|
||||
}
|
||||
|
||||
&__button.unlock {
|
||||
|
Loading…
Reference in New Issue
Block a user