Skip to content

Commit

Permalink
Some code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer8007 committed Jan 19, 2024
1 parent a5074f9 commit c74c387
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions core/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,20 @@ WACrypto.packNodesForSending = async function(nodesInfo, isIncoming = false)
nodePacker.writeNode(nodeBinaryWriter, node);
var nodeBuffer = nodeBinaryWriter.toBuffer();

var data = await WACrypto.encryptWithWebCrypto(nodeBuffer, isIncoming, counter);
var frame = new WAPacket({"data": data});
packetBinaryWriter.pushBytes(frame.serialize());
var data = await MultiDevice.encryptPacket(nodeBuffer, isIncoming, counter);

// Serialize to Noise protocol
var binaryReader = new BinaryReader();

var size = data.byteLength;
binaryReader.writeUint8(size >> 16);
binaryReader.writeUint16(65535 & size);
binaryReader.write(data);

binaryReader._readIndex = 0;
var serializedPacket = binaryReader.readBuffer();

packetBinaryWriter.pushBytes(serializedPacket);
}

return packetBinaryWriter.toBuffer();
Expand Down
2 changes: 1 addition & 1 deletion core/interception.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ wsHook.before = function (originalData, url)
}
}

var packedNode = await WACrypto.packNodesForSending(decryptedFrames, false);
var packedNode = await WACrypto.packNodesForSending(decryptedFrames, isIncoming=false);

// TODO: compare the original `originalData` with `packet`
if (WAdebugMode && isAllowed)
Expand Down
2 changes: 1 addition & 1 deletion core/wa_packet.js → old/wa_packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ WAPacket.prototype =
return this.binaryOpts ? this.binaryOpts.debugString : Array.isArray(e) ? 0 === e.length ? "[]" : 1 === e.length ? "[" + e[0] + "]" : "query" === e[0] || "action" === e[0] ? "[" + e[0] + ", " + e[1] + (e.length > 2 ? ", ..." : "") + "]" : void 0 : Object.isObject(e) ? "{...}" : "" + e
},
serialize: function() {
// multi device
// multi device, Noise protocol
var binaryReader = new BinaryReader();

var size = this.data.byteLength;
Expand Down

0 comments on commit c74c387

Please sign in to comment.