fca-nx 6.6.8 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/module/login.js +17 -8
  2. package/module/loginHelper.js +31 -2
  3. package/package.json +3 -2
  4. package/src/api/messaging/uploadAttachment.js +2 -2
  5. package/src/api/socket/core/getSeqID.js +53 -58
  6. package/src/api/socket/e2ee/index.js +1 -1
  7. package/src/api/socket/listenE2EE.js +14 -4
  8. package/src/api/socket/listenMqtt.js +20 -12
  9. package/src/utils/format/utils.js +18 -12
  10. package/src/utils/utils.js +15 -6
  11. package/e2ee/config.json +0 -0
  12. package/e2ee/crypto.js +0 -173
  13. package/e2ee/index.js +0 -1032
  14. package/e2ee/proto/ArmadilloApplication.proto +0 -281
  15. package/e2ee/proto/ArmadilloICDC.proto +0 -14
  16. package/e2ee/proto/ConsumerApplication.proto +0 -232
  17. package/e2ee/proto/MessageApplication.proto +0 -82
  18. package/e2ee/proto/MessageTransport.proto +0 -77
  19. package/e2ee/proto/WACommon.proto +0 -66
  20. package/e2ee/proto/WAMediaTransport.proto +0 -176
  21. package/e2ee/protocol.js +0 -196
  22. package/e2ee/ratchet.js +0 -219
  23. package/e2ee/store.js +0 -182
  24. package/e2ee/vendor/fb-e2ee.cjs +0 -9159
  25. package/e2ee/vendor/proto/ArmadilloApplication.proto +0 -281
  26. package/e2ee/vendor/proto/ArmadilloICDC.proto +0 -14
  27. package/e2ee/vendor/proto/ConsumerApplication.proto +0 -232
  28. package/e2ee/vendor/proto/MessageApplication.proto +0 -82
  29. package/e2ee/vendor/proto/MessageTransport.proto +0 -77
  30. package/e2ee/vendor/proto/WACommon.proto +0 -66
  31. package/e2ee/vendor/proto/WAMediaTransport.proto +0 -176
  32. package/src/api/socket/e2ee/e2ee/crypto.js +0 -173
  33. package/src/api/socket/e2ee/e2ee/index.js +0 -421
  34. package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +0 -281
  35. package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +0 -14
  36. package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +0 -232
  37. package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +0 -82
  38. package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +0 -77
  39. package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +0 -66
  40. package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +0 -176
  41. package/src/api/socket/e2ee/e2ee/protocol.js +0 -196
  42. package/src/api/socket/e2ee/e2ee/ratchet.js +0 -219
  43. package/src/api/socket/e2ee/e2ee/store.js +0 -182
  44. package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +0 -9162
  45. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +0 -281
  46. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +0 -14
  47. package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +0 -232
  48. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +0 -82
  49. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +0 -77
  50. package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +0 -66
  51. package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +0 -176
package/e2ee/crypto.js DELETED
@@ -1,173 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * FCA-NX E2EE Crypto — All primitives using Node.js built-in crypto only.
5
- * Implements: X25519 DH, HKDF-SHA256, AES-256-GCM, HMAC-SHA256
6
- * Node.js >= 15 required (crypto.hkdfSync, crypto.generateKeyPairSync x25519).
7
- */
8
-
9
- const crypto = require("crypto");
10
-
11
- // ─────────────────────────────────────────────────────────
12
- // X25519 Key Management
13
- // ─────────────────────────────────────────────────────────
14
-
15
- function generateKeyPair() {
16
- const { privateKey, publicKey } = crypto.generateKeyPairSync("x25519", {
17
- privateKeyEncoding: { type: "pkcs8", format: "der" },
18
- publicKeyEncoding: { type: "spki", format: "der" }
19
- });
20
- return {
21
- privateKey,
22
- publicKey,
23
- publicKeyRaw: exportRawPublicKey(publicKey)
24
- };
25
- }
26
-
27
- function exportRawPublicKey(spkiDer) {
28
- // X25519 SPKI DER: 12 bytes header + 32 bytes key
29
- return Buffer.from(spkiDer).slice(-32);
30
- }
31
-
32
- function importPublicKey(raw32bytes) {
33
- if (raw32bytes.length !== 32) throw new Error("X25519 public key must be 32 bytes");
34
- // Build minimal SPKI wrapper for X25519
35
- const header = Buffer.from("302a300506032b656e032100", "hex");
36
- return Buffer.concat([header, raw32bytes]);
37
- }
38
-
39
- function dh(privateKeyPkcs8Der, peerPublicRaw32) {
40
- const privKey = crypto.createPrivateKey({ key: Buffer.from(privateKeyPkcs8Der), format: "der", type: "pkcs8" });
41
- const pubKeyDer = importPublicKey(Buffer.from(peerPublicRaw32));
42
- const pubKey = crypto.createPublicKey({ key: pubKeyDer, format: "der", type: "spki" });
43
- return crypto.diffieHellman({ privateKey: privKey, publicKey: pubKey });
44
- }
45
-
46
- // ─────────────────────────────────────────────────────────
47
- // HKDF-SHA256
48
- // ─────────────────────────────────────────────────────────
49
-
50
- function hkdf(ikm, length, salt, info) {
51
- if (!salt) salt = Buffer.alloc(32, 0);
52
- if (!info) info = Buffer.alloc(0);
53
- if (typeof info === "string") info = Buffer.from(info, "utf8");
54
- return Buffer.from(crypto.hkdfSync("sha256", ikm, salt, info, length));
55
- }
56
-
57
- function hkdfExtract(salt, ikm) {
58
- return crypto.createHmac("sha256", salt).update(ikm).digest();
59
- }
60
-
61
- function hkdfExpand(prk, info, length) {
62
- const results = [];
63
- let t = Buffer.alloc(0);
64
- let i = 0;
65
- while (results.reduce((s, b) => s + b.length, 0) < length) {
66
- i++;
67
- const hmac = crypto.createHmac("sha256", prk);
68
- hmac.update(t);
69
- if (info) hmac.update(info);
70
- hmac.update(Buffer.from([i]));
71
- t = hmac.digest();
72
- results.push(t);
73
- }
74
- return Buffer.concat(results).slice(0, length);
75
- }
76
-
77
- // ─────────────────────────────────────────────────────────
78
- // AES-256-GCM
79
- // ─────────────────────────────────────────────────────────
80
-
81
- function encrypt(key32, plaintext, aad) {
82
- if (key32.length !== 32) throw new Error("AES-GCM key must be 32 bytes");
83
- const iv = crypto.randomBytes(12);
84
- const cipher = crypto.createCipheriv("aes-256-gcm", key32, iv);
85
- if (aad) cipher.setAAD(aad);
86
- const encrypted = Buffer.concat([cipher.update(plaintext), cipher.final()]);
87
- const authTag = cipher.getAuthTag();
88
- return Buffer.concat([iv, authTag, encrypted]);
89
- }
90
-
91
- function decrypt(key32, ciphertext, aad) {
92
- if (key32.length !== 32) throw new Error("AES-GCM key must be 32 bytes");
93
- if (ciphertext.length < 28) throw new Error("Ciphertext too short");
94
- const iv = ciphertext.slice(0, 12);
95
- const authTag = ciphertext.slice(12, 28);
96
- const data = ciphertext.slice(28);
97
- const decipher = crypto.createDecipheriv("aes-256-gcm", key32, iv);
98
- decipher.setAuthTag(authTag);
99
- if (aad) decipher.setAAD(aad);
100
- return Buffer.concat([decipher.update(data), decipher.final()]);
101
- }
102
-
103
- // ─────────────────────────────────────────────────────────
104
- // HMAC-SHA256
105
- // ─────────────────────────────────────────────────────────
106
-
107
- function hmacSha256(key, data) {
108
- return crypto.createHmac("sha256", key).update(data).digest();
109
- }
110
-
111
- function constantTimeEqual(a, b) {
112
- if (a.length !== b.length) return false;
113
- return crypto.timingSafeEqual(a, b);
114
- }
115
-
116
- // ─────────────────────────────────────────────────────────
117
- // X3DH Key Agreement (Extended Triple Diffie-Hellman)
118
- // ─────────────────────────────────────────────────────────
119
-
120
- /**
121
- * Sender side of X3DH.
122
- * @param {object} senderIdKey - { privateKey, publicKey, publicKeyRaw } of sender identity key
123
- * @param {object} ephemeralKey - { privateKey, publicKey, publicKeyRaw } of ephemeral key
124
- * @param {Buffer} recipientIdPub - recipient's identity public key (raw 32 bytes)
125
- * @param {Buffer} recipientSpkPub - recipient's signed pre-key (raw 32 bytes)
126
- * @param {Buffer} [recipientOpkPub] - recipient's one-time pre-key (raw 32 bytes), optional
127
- * @returns {Buffer} 32-byte shared master secret
128
- */
129
- function x3dhSend(senderIdKey, ephemeralKey, recipientIdPub, recipientSpkPub, recipientOpkPub) {
130
- const dh1 = dh(senderIdKey.privateKey, recipientSpkPub);
131
- const dh2 = dh(ephemeralKey.privateKey, recipientIdPub);
132
- const dh3 = dh(ephemeralKey.privateKey, recipientSpkPub);
133
- const parts = recipientOpkPub
134
- ? [dh1, dh2, dh3, dh(ephemeralKey.privateKey, recipientOpkPub)]
135
- : [dh1, dh2, dh3];
136
- const ikm = Buffer.concat(parts);
137
- const F = Buffer.alloc(32, 0xFF);
138
- const salt = Buffer.alloc(32, 0);
139
- return hkdf(Buffer.concat([F, ikm]), 32, salt, Buffer.from("WhisperText", "utf8"));
140
- }
141
-
142
- /**
143
- * Receiver side of X3DH.
144
- */
145
- function x3dhReceive(recipientIdKey, recipientSpkKey, recipientOpkKey, senderIdPub, senderEphemeralPub) {
146
- const dh1 = dh(recipientSpkKey.privateKey, senderIdPub);
147
- const dh2 = dh(recipientIdKey.privateKey, senderEphemeralPub);
148
- const dh3 = dh(recipientSpkKey.privateKey, senderEphemeralPub);
149
- const parts = recipientOpkKey
150
- ? [dh1, dh2, dh3, dh(recipientOpkKey.privateKey, senderEphemeralPub)]
151
- : [dh1, dh2, dh3];
152
- const ikm = Buffer.concat(parts);
153
- const F = Buffer.alloc(32, 0xFF);
154
- const salt = Buffer.alloc(32, 0);
155
- return hkdf(Buffer.concat([F, ikm]), 32, salt, Buffer.from("WhisperText", "utf8"));
156
- }
157
-
158
- module.exports = {
159
- generateKeyPair,
160
- exportRawPublicKey,
161
- importPublicKey,
162
- dh,
163
- hkdf,
164
- hkdfExtract,
165
- hkdfExpand,
166
- encrypt,
167
- decrypt,
168
- hmacSha256,
169
- constantTimeEqual,
170
- x3dhSend,
171
- x3dhReceive,
172
- randomBytes: crypto.randomBytes.bind(crypto)
173
- };