2024-07-28 02:37:31 -04:00
|
|
|
const crypto = require('crypto')
|
2024-08-22 13:52:21 -04:00
|
|
|
const secret = require('../secret.json')
|
2024-09-06 16:55:01 -04:00
|
|
|
module.exports = function (cmd, uuid) {
|
2024-07-28 02:37:31 -04:00
|
|
|
const cmdWithoutHash = cmd.slice(0, cmd.length - 1).join(' ')
|
|
|
|
const _dateString = Date.now().toString()
|
|
|
|
const dateString = _dateString.slice(0, _dateString.length - 4)
|
2024-09-06 16:55:01 -04:00
|
|
|
const hashTrusted = `babyboom:${secret.keyTrusted}:${uuid}:${cmdWithoutHash}:${dateString}`
|
|
|
|
const hashOwner = `babyboom:${secret.keyOwner}:${uuid}:${cmdWithoutHash}:${dateString}`
|
2024-07-28 02:37:31 -04:00
|
|
|
const validhashT = crypto.createHash('sha256').update(hashTrusted).digest('hex')
|
|
|
|
const validhashO = crypto.createHash('sha256').update(hashOwner).digest('hex')
|
|
|
|
if (cmd[cmd.length - 1] === validhashT) {
|
|
|
|
return 1
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
if (cmd[cmd.length - 1] === validhashO) {
|
|
|
|
return 2
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|
2024-07-28 02:37:31 -04:00
|
|
|
return 0
|
2024-07-27 02:39:18 -04:00
|
|
|
}
|