feat(modules/blockchain_connector): introduce APIs for signing/verifying messages

This commit is contained in:
Pascal Precht 2018-10-17 13:27:29 +02:00
parent bae21133bc
commit a20bf63835
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 29 additions and 0 deletions

View File

@ -388,6 +388,35 @@ class BlockchainConnector {
res.send(JSON.stringify(this.contractsEvents)); res.send(JSON.stringify(this.contractsEvents));
} }
); );
plugin.registerAPICall(
'post',
'/embark-api/messages/sign',
(req, res) => {
const signer = req.body.address;
const message = req.body.message;
this.web3.eth.personal.sign(message, signer).then(signature => {
res.send({signer, signature, message})
}).catch(e => res.send({ error: e.message }))
}
);
plugin.registerAPICall(
'post',
'/embark-api/messages/verify',
(req, res) => {
let signature;
try {
signature = JSON.parse(req.body.message);
} catch(e) {
return res.send({ error: e.message });
}
this.web3.eth.personal.ecRecover(signature.message, signature.signature)
.then(address => res.send({address}))
.catch(e => res.send({ error: e.message }));
}
);
} }
getAccountsWithTransactionCount(callback) { getAccountsWithTransactionCount(callback) {