mirror of https://github.com/embarklabs/embark.git
feat(modules/blockchain_connector): introduce APIs for signing/verifying messages
This commit is contained in:
parent
bae21133bc
commit
a20bf63835
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue