diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index 21f00196b..35f210caf 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -388,6 +388,35 @@ class BlockchainConnector { 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) {