UNPKG

@radzztnzx/rbail

Version:

Pro Bails based by Whiskeysockets, Modified by RadzzOffc

63 lines 2.36 kB
import { proto } from '../../../WAProto/index.js'; import { CiphertextMessage } from './ciphertext-message.js'; export class SenderKeyDistributionMessage extends CiphertextMessage { constructor(id, iteration, chainKey, signatureKey, serialized) { super(); if (serialized) { try { const message = serialized.slice(1); const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON(); this.serialized = serialized; this.id = distributionMessage.id; this.iteration = distributionMessage.iteration; this.chainKey = typeof distributionMessage.chainKey === 'string' ? Buffer.from(distributionMessage.chainKey, 'base64') : distributionMessage.chainKey; this.signatureKey = typeof distributionMessage.signingKey === 'string' ? Buffer.from(distributionMessage.signingKey, 'base64') : distributionMessage.signingKey; } catch (e) { throw new Error(String(e)); } } else { const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION); this.id = id; this.iteration = iteration; this.chainKey = chainKey; this.signatureKey = signatureKey; const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({ id, iteration, chainKey, signingKey: this.signatureKey })).finish(); this.serialized = Buffer.concat([Buffer.from([version]), message]); } } intsToByteHighAndLow(highValue, lowValue) { return (((highValue << 4) | lowValue) & 0xff) % 256; } serialize() { return this.serialized; } getType() { return this.SENDERKEY_DISTRIBUTION_TYPE; } getIteration() { return this.iteration; } getChainKey() { return this.chainKey; } getSignatureKey() { return this.signatureKey; } getId() { return this.id; } } //# sourceMappingURL=sender-key-distribution-message.js.map