UNPKG

matterbridge-roborock-vacuum-plugin

Version:
16 lines 956 B
import crypto from 'node:crypto'; import * as CryptoUtils from '../../helper/cryptoHelper.js'; export class A01Serializer { encode(payload, localKey, timestamp, sequence, nonce, connectNonce, ackNonce) { const encoder = new TextEncoder(); const iv = CryptoUtils.md5hex(nonce.toString(16).padStart(8, '0') + '726f626f726f636b2d67a6d6da').substring(8, 24); const cipher = crypto.createCipheriv('aes-128-cbc', encoder.encode(localKey), iv); return Buffer.concat([cipher.update(payload), cipher.final()]); } decode(payload, localKey, timestamp, sequence, nonce, connectNonce, ackNonce) { const iv = CryptoUtils.md5hex(nonce.toString(16).padStart(8, '0') + '726f626f726f636b2d67a6d6da').substring(8, 24); const decipher = crypto.createDecipheriv('aes-128-cbc', localKey, iv); return Buffer.concat([decipher.update(payload), decipher.final()]); } } //# sourceMappingURL=A01Serializer.js.map