@baileys-md/baileys 11.0.3 → 11.1.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.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const SenderChainKey = require('./sender_chain_key');
|
|
2
|
+
const SenderMessageKey = require('./sender_message_key');
|
|
3
|
+
|
|
4
|
+
const protobufs = require('./protobufs');
|
|
5
|
+
|
|
6
|
+
class SenderKeyState {
|
|
7
|
+
MAX_MESSAGE_KEYS = 2000;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
id = null,
|
|
11
|
+
iteration = null,
|
|
12
|
+
chainKey = null,
|
|
13
|
+
signatureKeyPair = null,
|
|
14
|
+
signatureKeyPublic = null,
|
|
15
|
+
signatureKeyPrivate = null,
|
|
16
|
+
senderKeyStateStructure = null
|
|
17
|
+
) {
|
|
18
|
+
if (senderKeyStateStructure) {
|
|
19
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
20
|
+
} else {
|
|
21
|
+
if (signatureKeyPair) {
|
|
22
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
23
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
27
|
+
this.senderKeyStateStructure = protobufs.SenderKeyStateStructure.create();
|
|
28
|
+
const senderChainKeyStructure = protobufs.SenderChainKey.create();
|
|
29
|
+
senderChainKeyStructure.iteration = iteration;
|
|
30
|
+
senderChainKeyStructure.seed = chainKey;
|
|
31
|
+
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
32
|
+
|
|
33
|
+
const signingKeyStructure = protobufs.SenderSigningKey.create();
|
|
34
|
+
signingKeyStructure.public =
|
|
35
|
+
typeof signatureKeyPublic === 'string' ?
|
|
36
|
+
Buffer.from(signatureKeyPublic, 'base64') :
|
|
37
|
+
signatureKeyPublic;
|
|
38
|
+
if (signatureKeyPrivate) {
|
|
39
|
+
signingKeyStructure.private =
|
|
40
|
+
typeof signatureKeyPrivate === 'string' ?
|
|
41
|
+
Buffer.from(signatureKeyPrivate, 'base64') :
|
|
42
|
+
signatureKeyPrivate;
|
|
43
|
+
}
|
|
44
|
+
this.senderKeyStateStructure.senderKeyId = id;
|
|
45
|
+
this.senderChainKey = senderChainKeyStructure;
|
|
46
|
+
this.senderKeyStateStructure.senderSigningKey = signingKeyStructure;
|
|
47
|
+
}
|
|
48
|
+
this.senderKeyStateStructure.senderMessageKeys =
|
|
49
|
+
this.senderKeyStateStructure.senderMessageKeys || [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
SenderKeyState(senderKeyStateStructure) {
|
|
53
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getKeyId() {
|
|
57
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getSenderChainKey() {
|
|
61
|
+
return new SenderChainKey(
|
|
62
|
+
this.senderKeyStateStructure.senderChainKey.iteration,
|
|
63
|
+
this.senderKeyStateStructure.senderChainKey.seed
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setSenderChainKey(chainKey) {
|
|
68
|
+
const senderChainKeyStructure = protobufs.SenderChainKey.create({
|
|
69
|
+
iteration: chainKey.getIteration(),
|
|
70
|
+
seed: chainKey.getSeed(),
|
|
71
|
+
});
|
|
72
|
+
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getSigningKeyPublic() {
|
|
76
|
+
return typeof this.senderKeyStateStructure.senderSigningKey.public === 'string' ?
|
|
77
|
+
Buffer.from(this.senderKeyStateStructure.senderSigningKey.public, 'base64') :
|
|
78
|
+
this.senderKeyStateStructure.senderSigningKey.public;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getSigningKeyPrivate() {
|
|
82
|
+
return typeof this.senderKeyStateStructure.senderSigningKey.private === 'string' ?
|
|
83
|
+
Buffer.from(this.senderKeyStateStructure.senderSigningKey.private, 'base64') :
|
|
84
|
+
this.senderKeyStateStructure.senderSigningKey.private;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
hasSenderMessageKey(iteration) {
|
|
88
|
+
const list = this.senderKeyStateStructure.senderMessageKeys;
|
|
89
|
+
for (let o = 0; o < list.length; o++) {
|
|
90
|
+
const senderMessageKey = list[o];
|
|
91
|
+
if (senderMessageKey.iteration === iteration) return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
addSenderMessageKey(senderMessageKey) {
|
|
97
|
+
const senderMessageKeyStructure = protobufs.SenderKeyStateStructure.create({
|
|
98
|
+
iteration: senderMessageKey.getIteration(),
|
|
99
|
+
seed: senderMessageKey.getSeed(),
|
|
100
|
+
});
|
|
101
|
+
this.senderKeyStateStructure.senderMessageKeys.push(senderMessageKeyStructure);
|
|
102
|
+
|
|
103
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
104
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
removeSenderMessageKey(iteration) {
|
|
109
|
+
let result = null;
|
|
110
|
+
|
|
111
|
+
this.senderKeyStateStructure.senderMessageKeys = this.senderKeyStateStructure.senderMessageKeys.filter(
|
|
112
|
+
senderMessageKey => {
|
|
113
|
+
if (senderMessageKey.iteration === iteration) result = senderMessageKey;
|
|
114
|
+
return senderMessageKey.iteration !== iteration;
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (result != null) {
|
|
119
|
+
return new SenderMessageKey(result.iteration, result.seed);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getStructure() {
|
|
125
|
+
return this.senderKeyStateStructure;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = SenderKeyState;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const { deriveSecrets } = require('libsignal/src/crypto');
|
|
2
|
+
class SenderMessageKey {
|
|
3
|
+
iteration = 0;
|
|
4
|
+
|
|
5
|
+
iv = Buffer.alloc(0);
|
|
6
|
+
|
|
7
|
+
cipherKey = Buffer.alloc(0);
|
|
8
|
+
|
|
9
|
+
seed = Buffer.alloc(0);
|
|
10
|
+
|
|
4
11
|
constructor(iteration, seed) {
|
|
5
12
|
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
6
13
|
const keys = new Uint8Array(32);
|
|
@@ -8,20 +15,25 @@ export class SenderMessageKey {
|
|
|
8
15
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
9
16
|
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
10
17
|
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
+
|
|
11
19
|
this.iteration = iteration;
|
|
12
20
|
this.seed = seed;
|
|
13
21
|
}
|
|
22
|
+
|
|
14
23
|
getIteration() {
|
|
15
24
|
return this.iteration;
|
|
16
25
|
}
|
|
26
|
+
|
|
17
27
|
getIv() {
|
|
18
28
|
return this.iv;
|
|
19
29
|
}
|
|
30
|
+
|
|
20
31
|
getCipherKey() {
|
|
21
32
|
return this.cipherKey;
|
|
22
33
|
}
|
|
34
|
+
|
|
23
35
|
getSeed() {
|
|
24
36
|
return this.seed;
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
|
-
|
|
39
|
+
module.exports = SenderMessageKey;
|
package/lib/Defaults/index.js
CHANGED
|
@@ -1,40 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.MOBILE_NOISE_HEADER = exports.PROTOCOL_VERSION = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.REGISTRATION_PUBLIC_KEY = exports.MOBILE_USERAGENT = exports.MOBILE_REGISTRATION_ENDPOINT = exports.MOBILE_TOKEN = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.MOBILE_PORT = exports.MOBILE_ENDPOINT = exports.DEFAULT_ORIGIN = exports.PHONENUMBER_MCC = exports.UNAUTHORIZED_CODES = void 0;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const WAProto_1 = require("../../WAProto");
|
|
9
|
+
const libsignal_1 = require("../Signal/libsignal");
|
|
10
|
+
const Utils_1 = require("../Utils");
|
|
11
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
12
|
+
const baileys_version_json_1 = require("./baileys-version.json");
|
|
13
|
+
const phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
|
|
14
|
+
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
15
|
+
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
|
|
16
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
17
|
+
exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
|
|
18
|
+
exports.MOBILE_PORT = 443;
|
|
19
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
20
|
+
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
21
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
22
|
+
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
23
|
+
const WA_VERSION = '2.24.6.77';
|
|
24
|
+
const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
|
|
25
|
+
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
|
|
26
|
+
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
27
|
+
exports.MOBILE_USERAGENT = `Telegram Android 11.7.0 Samsung Galaxy-A7-2017`;
|
|
28
|
+
exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
29
|
+
5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
|
|
30
|
+
34, 251, 111, 18, 37, 18, 48, 45,
|
|
31
|
+
]);
|
|
32
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
33
|
+
exports.DICT_VERSION = 2;
|
|
34
|
+
exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
35
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
|
|
36
|
+
exports.PROTOCOL_VERSION = [5, 2];
|
|
37
|
+
exports.MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(exports.PROTOCOL_VERSION)]);
|
|
19
38
|
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
SERIAL: 0
|
|
39
|
+
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
40
|
+
exports.WA_CERT_DETAILS = {
|
|
41
|
+
SERIAL: 0,
|
|
23
42
|
};
|
|
24
|
-
|
|
25
|
-
proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
26
|
-
proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
27
|
-
proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
28
|
-
proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
29
|
-
proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
|
|
43
|
+
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
44
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
45
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
46
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
47
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
48
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
|
|
30
49
|
];
|
|
31
|
-
|
|
32
|
-
version: version,
|
|
33
|
-
browser: Browsers.ubuntu('Chrome'),
|
|
50
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
51
|
+
version: baileys_version_json_1.version,
|
|
52
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
34
53
|
waWebSocketUrl: 'https://web.whatsapp.com/ws/chat',
|
|
35
54
|
connectTimeoutMs: 20000,
|
|
36
55
|
keepAliveIntervalMs: 1000,
|
|
37
|
-
logger:
|
|
56
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
57
|
+
printQRInTerminal: false,
|
|
38
58
|
emitOwnEvents: true,
|
|
39
59
|
defaultQueryTimeoutMs: 60000,
|
|
40
60
|
customUploadHosts: [],
|
|
@@ -53,14 +73,14 @@ export const DEFAULT_CONNECTION_CONFIG = {
|
|
|
53
73
|
options: {},
|
|
54
74
|
appStateMacVerification: {
|
|
55
75
|
patch: false,
|
|
56
|
-
snapshot: false
|
|
76
|
+
snapshot: false,
|
|
57
77
|
},
|
|
58
78
|
countryCode: 'US',
|
|
59
79
|
getMessage: async () => undefined,
|
|
60
80
|
cachedGroupMetadata: async () => undefined,
|
|
61
|
-
makeSignalRepository: makeLibSignalRepository
|
|
81
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
62
82
|
};
|
|
63
|
-
|
|
83
|
+
exports.MEDIA_PATH_MAP = {
|
|
64
84
|
image: '/mms/image',
|
|
65
85
|
video: '/mms/video',
|
|
66
86
|
document: '/mms/document',
|
|
@@ -69,18 +89,18 @@ export const MEDIA_PATH_MAP = {
|
|
|
69
89
|
'thumbnail-link': '/mms/image',
|
|
70
90
|
'product-catalog-image': '/product/image',
|
|
71
91
|
'md-app-state': '',
|
|
72
|
-
'md-msg-hist': '/mms/md-app-state'
|
|
92
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
73
93
|
};
|
|
74
|
-
|
|
75
|
-
audio: 'Audio',
|
|
76
|
-
document: 'Document',
|
|
77
|
-
gif: 'Video',
|
|
78
|
-
image: 'Image',
|
|
79
|
-
ppic: '',
|
|
80
|
-
product: 'Image',
|
|
81
|
-
ptt: 'Audio',
|
|
82
|
-
sticker: 'Image',
|
|
83
|
-
video: 'Video',
|
|
94
|
+
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
95
|
+
'audio': 'Audio',
|
|
96
|
+
'document': 'Document',
|
|
97
|
+
'gif': 'Video',
|
|
98
|
+
'image': 'Image',
|
|
99
|
+
'ppic': '',
|
|
100
|
+
'product': 'Image',
|
|
101
|
+
'ptt': 'Audio',
|
|
102
|
+
'sticker': 'Image',
|
|
103
|
+
'video': 'Video',
|
|
84
104
|
'thumbnail-document': 'Document Thumbnail',
|
|
85
105
|
'thumbnail-image': 'Image Thumbnail',
|
|
86
106
|
'thumbnail-video': 'Video Thumbnail',
|
|
@@ -89,15 +109,14 @@ export const MEDIA_HKDF_KEY_MAPPING = {
|
|
|
89
109
|
'md-app-state': 'App State',
|
|
90
110
|
'product-catalog-image': '',
|
|
91
111
|
'payment-bg-image': 'Payment Background',
|
|
92
|
-
ptv: 'Video'
|
|
112
|
+
'ptv': 'Video'
|
|
93
113
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
115
|
+
exports.MIN_PREKEY_COUNT = 5;
|
|
116
|
+
exports.INITIAL_PREKEY_COUNT = 30;
|
|
117
|
+
exports.DEFAULT_CACHE_TTLS = {
|
|
98
118
|
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
99
119
|
MSG_RETRY: 60 * 60, // 1 hour
|
|
100
120
|
CALL_OFFER: 5 * 60, // 5 minutes
|
|
101
|
-
USER_DEVICES: 5 * 60 // 5 minutes
|
|
121
|
+
USER_DEVICES: 5 * 60, // 5 minutes
|
|
102
122
|
};
|
|
103
|
-
//# sourceMappingURL=index.js.map
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -1,29 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
37
|
+
const libsignal = __importStar(require("libsignal"));
|
|
38
|
+
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
39
|
+
const Utils_1 = require("../Utils");
|
|
40
|
+
const WABinary_1 = require("../WABinary");
|
|
41
|
+
function makeLibSignalRepository(auth) {
|
|
9
42
|
const storage = signalStorage(auth);
|
|
10
43
|
return {
|
|
11
44
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
12
45
|
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
13
|
-
const cipher = new GroupCipher(storage, senderName);
|
|
46
|
+
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
14
47
|
return cipher.decrypt(msg);
|
|
15
48
|
},
|
|
16
49
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
17
|
-
const builder = new GroupSessionBuilder(storage);
|
|
18
|
-
if (!item.groupId) {
|
|
19
|
-
throw new Error('Group ID is required for sender key distribution message');
|
|
20
|
-
}
|
|
50
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
21
51
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
22
|
-
const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
23
|
-
const
|
|
24
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
52
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
53
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
25
54
|
if (!senderKey) {
|
|
26
|
-
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
55
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
27
56
|
}
|
|
28
57
|
await builder.process(senderName, senderMsg);
|
|
29
58
|
},
|
|
@@ -38,8 +67,6 @@ export function makeLibSignalRepository(auth) {
|
|
|
38
67
|
case 'msg':
|
|
39
68
|
result = await session.decryptWhisperMessage(ciphertext);
|
|
40
69
|
break;
|
|
41
|
-
default:
|
|
42
|
-
throw new Error(`Unknown message type: ${type}`);
|
|
43
70
|
}
|
|
44
71
|
return result;
|
|
45
72
|
},
|
|
@@ -52,18 +79,17 @@ export function makeLibSignalRepository(auth) {
|
|
|
52
79
|
},
|
|
53
80
|
async encryptGroupMessage({ group, meId, data }) {
|
|
54
81
|
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
55
|
-
const builder = new GroupSessionBuilder(storage);
|
|
56
|
-
const
|
|
57
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
82
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
83
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
58
84
|
if (!senderKey) {
|
|
59
|
-
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
85
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
60
86
|
}
|
|
61
87
|
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
62
|
-
const session = new GroupCipher(storage, senderName);
|
|
88
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
63
89
|
const ciphertext = await session.encrypt(data);
|
|
64
90
|
return {
|
|
65
91
|
ciphertext,
|
|
66
|
-
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
92
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
67
93
|
};
|
|
68
94
|
},
|
|
69
95
|
async injectE2ESession({ jid, session }) {
|
|
@@ -72,15 +98,15 @@ export function makeLibSignalRepository(auth) {
|
|
|
72
98
|
},
|
|
73
99
|
jidToSignalProtocolAddress(jid) {
|
|
74
100
|
return jidToSignalProtocolAddress(jid).toString();
|
|
75
|
-
}
|
|
101
|
+
},
|
|
76
102
|
};
|
|
77
103
|
}
|
|
78
104
|
const jidToSignalProtocolAddress = (jid) => {
|
|
79
|
-
const { user, device } = jidDecode(jid);
|
|
105
|
+
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
80
106
|
return new libsignal.ProtocolAddress(user, device || 0);
|
|
81
107
|
};
|
|
82
108
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
83
|
-
return new SenderKeyName(group, jidToSignalProtocolAddress(user));
|
|
109
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
|
|
84
110
|
};
|
|
85
111
|
function signalStorage({ creds, keys }) {
|
|
86
112
|
return {
|
|
@@ -90,9 +116,8 @@ function signalStorage({ creds, keys }) {
|
|
|
90
116
|
return libsignal.SessionRecord.deserialize(sess);
|
|
91
117
|
}
|
|
92
118
|
},
|
|
93
|
-
// TODO: Replace with libsignal.SessionRecord when type exports are added to libsignal
|
|
94
119
|
storeSession: async (id, session) => {
|
|
95
|
-
await keys.set({ session: { [id]: session.serialize() } });
|
|
120
|
+
await keys.set({ 'session': { [id]: session.serialize() } });
|
|
96
121
|
},
|
|
97
122
|
isTrustedIdentity: () => {
|
|
98
123
|
return true;
|
|
@@ -115,27 +140,22 @@ function signalStorage({ creds, keys }) {
|
|
|
115
140
|
pubKey: Buffer.from(key.keyPair.public)
|
|
116
141
|
};
|
|
117
142
|
},
|
|
118
|
-
loadSenderKey: async (
|
|
119
|
-
const keyId = senderKeyName.toString();
|
|
143
|
+
loadSenderKey: async (keyId) => {
|
|
120
144
|
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
121
145
|
if (key) {
|
|
122
|
-
return SenderKeyRecord
|
|
146
|
+
return new WASignalGroup_1.SenderKeyRecord(key);
|
|
123
147
|
}
|
|
124
|
-
return new SenderKeyRecord();
|
|
125
148
|
},
|
|
126
|
-
storeSenderKey: async (
|
|
127
|
-
|
|
128
|
-
const serialized = JSON.stringify(key.serialize());
|
|
129
|
-
await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
|
|
149
|
+
storeSenderKey: async (keyId, key) => {
|
|
150
|
+
await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
|
|
130
151
|
},
|
|
131
|
-
getOurRegistrationId: () => creds.registrationId,
|
|
152
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
132
153
|
getOurIdentity: () => {
|
|
133
154
|
const { signedIdentityKey } = creds;
|
|
134
155
|
return {
|
|
135
156
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
136
|
-
pubKey: generateSignalPubKey(signedIdentityKey.public)
|
|
157
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
|
|
137
158
|
};
|
|
138
159
|
}
|
|
139
160
|
};
|
|
140
161
|
}
|
|
141
|
-
//# sourceMappingURL=libsignal.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractSocketClient = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class AbstractSocketClient extends events_1.EventEmitter {
|
|
6
|
+
constructor(url, config) {
|
|
7
|
+
super();
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.setMaxListeners(0);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AbstractSocketClient = AbstractSocketClient;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./abstract-socket-client"), exports);
|
|
18
|
+
__exportStar(require("./mobile-socket-client"), exports);
|
|
19
|
+
__exportStar(require("./web-socket-client"), exports);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MobileSocketClient = void 0;
|
|
4
|
+
const net_1 = require("net");
|
|
5
|
+
const abstract_socket_client_1 = require("./abstract-socket-client");
|
|
6
|
+
class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.socket = null;
|
|
10
|
+
}
|
|
11
|
+
get isOpen() {
|
|
12
|
+
var _a;
|
|
13
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
|
|
14
|
+
}
|
|
15
|
+
get isClosed() {
|
|
16
|
+
var _a;
|
|
17
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
18
|
+
}
|
|
19
|
+
get isClosing() {
|
|
20
|
+
var _a;
|
|
21
|
+
return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
|
|
22
|
+
}
|
|
23
|
+
get isConnecting() {
|
|
24
|
+
var _a;
|
|
25
|
+
return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
|
|
26
|
+
}
|
|
27
|
+
async connect() {
|
|
28
|
+
var _a;
|
|
29
|
+
if (this.socket) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (this.config.agent) {
|
|
33
|
+
throw new Error('There are not support for proxy agent for mobile connection');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.socket = (0, net_1.connect)({
|
|
37
|
+
host: this.url.hostname,
|
|
38
|
+
port: Number(this.url.port) || 443
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.socket.setMaxListeners(0);
|
|
42
|
+
const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
|
|
43
|
+
for (const event of events) {
|
|
44
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
|
|
45
|
+
}
|
|
46
|
+
this.socket.on('data', (...args) => this.emit('message', ...args));
|
|
47
|
+
this.socket.on('ready', (...args) => this.emit('open', ...args));
|
|
48
|
+
}
|
|
49
|
+
async close() {
|
|
50
|
+
if (!this.socket) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return new Promise(resolve => {
|
|
54
|
+
this.socket.end(resolve);
|
|
55
|
+
this.socket = null;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
send(str, cb) {
|
|
59
|
+
if (this.socket === null) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return this.socket.write(str, undefined, cb);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MobileSocketClient = MobileSocketClient;
|