UNPKG

matterbridge-roborock-vacuum-plugin

Version:
27 lines (26 loc) 792 B
import { randomBytes } from 'node:crypto'; import * as CryptoUtils from '../../helper/cryptoHelper.js'; export class MessageContext { endpoint; nonce; devices = new Map(); constructor(userdata) { this.endpoint = CryptoUtils.md5bin(userdata.rriot.k).subarray(8, 14).toString('base64'); this.nonce = randomBytes(16); } registerDevice(duid, localKey, pv) { this.devices.set(duid, { localKey: localKey, protocolVersion: pv }); } getNonceAsHex() { return this.nonce.toString('hex').toUpperCase(); } getLocalKey(duid) { return this.devices.get(duid)?.localKey; } getProtocolVersion(duid) { return this.devices.get(duid)?.protocolVersion; } getEndpoint() { return this.endpoint; } }