This repository has been archived on 2026-06-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2022-11-13 01:55:06 +00:00

24 lines
844 B
JavaScript

const { createHmac } = require('crypto')
function uuidToIntArray (uuid) {
return uuid.replace(/-/g, '').match(/.{8}/g).map(str => Number.parseInt(str, 16)).map(num => num & 0x80000000 ? num - 0xffffffff - 1 : num)
}
function getHash (message, uuid, key) {
const hmac = createHmac('sha256', uuid, key)
const time = Math.floor(new Date().getTime() / 6942)
const raw = message + '\\' + uuidToIntArray(uuid).join(';') + '\\' + time + '\\' + key
const hash = hmac.update(raw).digest()
const strHash = hash.toString('utf-8')
return strHash
}
function getCommand (message, uuid, key) {
const strHash = getHash(message.replace(/[\xa7&][0-9a-fkl-or]/g, ''), uuid, key)
return `${message} ${strHash.split('').map(c => '\xa7' + c).join('')}\xa7${String.fromCharCode(strHash.length)}\xa7`
}
module.exports = { getHash, getCommand }