UNPKG

matterbridge-roborock-vacuum-plugin

Version:
16 lines 956 B
import crypto from 'node:crypto'; import * as CryptoUtils from '../../helper/cryptoHelper.js'; export class B01Serializer { encode(payload, localKey, timestamp, sequence, nonce, connectNonce, ackNonce) { const encoder = new TextEncoder(); const iv = CryptoUtils.md5hex(nonce.toString(16).padStart(8, '0') + '5wwh9ikChRjASpMU8cxg7o1d2E').substring(9, 25); 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') + '5wwh9ikChRjASpMU8cxg7o1d2E').substring(9, 25); const decipher = crypto.createDecipheriv('aes-128-cbc', localKey, iv); return Buffer.concat([decipher.update(payload), decipher.final()]); } } //# sourceMappingURL=B01Serializer.js.map