Path: blob/master/node_modules/@adiwajshing/baileys/WASignalGroup/sender_key_distribution_message.js
1126 views
const CiphertextMessage = require('./ciphertext_message');1const protobufs = require('./protobufs');23class SenderKeyDistributionMessage extends CiphertextMessage {4constructor(5id = null,6iteration = null,7chainKey = null,8signatureKey = null,9serialized = null10) {11super();12if (serialized) {13try {14const version = serialized[0];15const message = serialized.slice(1);1617const distributionMessage = protobufs.SenderKeyDistributionMessage.decode(18message19).toJSON();20this.serialized = serialized;21this.id = distributionMessage.id;22this.iteration = distributionMessage.iteration;23this.chainKey = distributionMessage.chainKey;24this.signatureKey = distributionMessage.signingKey;25} catch (e) {26throw new Error(e);27}28} else {29const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);30this.id = id;31this.iteration = iteration;32this.chainKey = chainKey;33this.signatureKey = signatureKey;34const message = protobufs.SenderKeyDistributionMessage.encode(35protobufs.SenderKeyDistributionMessage.create({36id,37iteration,38chainKey,39signingKey: this.signatureKey,40})41).finish();42this.serialized = Buffer.concat([Buffer.from([version]), message]);43}44}4546intsToByteHighAndLow(highValue, lowValue) {47return (((highValue << 4) | lowValue) & 0xff) % 256;48}4950serialize() {51return this.serialized;52}5354getType() {55return this.SENDERKEY_DISTRIBUTION_TYPE;56}5758getIteration() {59return this.iteration;60}6162getChainKey() {63return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey;64}6566getSignatureKey() {67return typeof this.signatureKey === 'string'68? Buffer.from(this.signatureKey, 'base64')69: this.signatureKey;70}7172getId() {73return this.id;74}75}7677module.exports = SenderKeyDistributionMessage;7879