Skip to content

Instantly share code, notes, and snippets.

@MagRelo
Last active April 7, 2018 16:49
Show Gist options
  • Save MagRelo/b155fcee3fd50cf738bf4b80b466e4a6 to your computer and use it in GitHub Desktop.
Save MagRelo/b155fcee3fd50cf738bf4b80b466e4a6 to your computer and use it in GitHub Desktop.
const sigUtil = require('eth-sig-util')
app.post('/api/message', (req, res) => {
const messageData = req.body.messageData
const signature = req.body.signature
// recover the public key
const publicKey = sigUtil.recoverTypedSignature({
data: messageData,
sig: signature
})
// check if public key is on the approved list
const approvedPublicKeys = [
'0xdf396910e694f7De31eF88d0090F2A4333ffcCF3',
'0x106F681949E222D57A165cD85685E3bD9975b973'
]
if(approvedPublicKeys.indexOf(publicKey) > -1){
// save the vote
mongoDb.messages.save(messageData)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment