angularsockets 1.0.1 → 1.0.3
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/README.md +1880 -36
- package/WAProto/index.d.ts +50383 -0
- package/WAProto/index.js +37203 -11791
- 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 -6
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +79 -101
- package/lib/Signal/libsignal.js +29 -51
- package/lib/Socket/Client/web-socket-client.js +0 -2
- package/lib/Socket/business.d.ts +42 -43
- package/lib/Socket/chats.d.ts +9 -8
- package/lib/Socket/chats.js +107 -21
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +24 -25
- package/lib/Socket/index.d.ts +51 -52
- package/lib/Socket/messages-recv.d.ts +34 -37
- package/lib/Socket/messages-recv.js +37 -175
- package/lib/Socket/messages-send.d.ts +16 -10
- package/lib/Socket/messages-send.js +540 -346
- package/lib/Socket/newsletter.d.ts +26 -28
- package/lib/Socket/newsletter.js +4 -4
- package/lib/Socket/registration.d.ts +49 -52
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +1 -0
- package/lib/Socket/socket.js +36 -23
- package/lib/Socket/usync.d.ts +11 -10
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +5 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +3 -2
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +170 -10
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +7 -2
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +35 -14
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +11 -12
- package/lib/Utils/chat-utils.js +52 -36
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +74 -26
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +53 -17
- package/lib/Utils/event-buffer.js +10 -7
- package/lib/Utils/generics.d.ts +13 -17
- package/lib/Utils/generics.js +26 -15
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +25 -28
- package/lib/Utils/messages-media.js +47 -57
- package/lib/Utils/messages.js +461 -44
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +19 -14
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +75 -23
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +43 -35
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +251 -36
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +75 -0
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +23 -11
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +46 -22
- package/lib/WABinary/generic-utils.d.ts +2 -4
- package/lib/WABinary/generic-utils.js +2 -10
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +0 -2
- package/lib/index.js +0 -6
- package/package.json +96 -104
- package/engine-requirements.js +0 -10
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group-session-builder.js +0 -64
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.js +0 -96
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/index.js +0 -57
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/keyhelper.js +0 -55
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-chain-key.js +0 -34
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-name.js +0 -51
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-record.js +0 -53
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-key-state.js +0 -99
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Socket/dugong.d.ts +0 -175
- package/lib/Socket/dugong.js +0 -342
- package/lib/index.d.ts +0 -12
|
@@ -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,29 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SenderMessageKey = void 0;
|
|
4
|
-
const crypto_1 = require("libsignal/src/crypto");
|
|
1
|
+
const { deriveSecrets } = require('libsignal/src/crypto');
|
|
5
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
|
+
|
|
6
11
|
constructor(iteration, seed) {
|
|
7
|
-
const derivative =
|
|
12
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
8
13
|
const keys = new Uint8Array(32);
|
|
9
14
|
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
10
15
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
11
16
|
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
12
17
|
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
+
|
|
13
19
|
this.iteration = iteration;
|
|
14
20
|
this.seed = seed;
|
|
15
21
|
}
|
|
22
|
+
|
|
16
23
|
getIteration() {
|
|
17
24
|
return this.iteration;
|
|
18
25
|
}
|
|
26
|
+
|
|
19
27
|
getIv() {
|
|
20
28
|
return this.iv;
|
|
21
29
|
}
|
|
30
|
+
|
|
22
31
|
getCipherKey() {
|
|
23
32
|
return this.cipherKey;
|
|
24
33
|
}
|
|
34
|
+
|
|
25
35
|
getSeed() {
|
|
26
36
|
return this.seed;
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
|
-
exports
|
|
39
|
+
module.exports = SenderMessageKey;
|
package/lib/Defaults/index.js
CHANGED
|
@@ -1,130 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.MEDIA_HKDF_KEY_MAPPING =
|
|
12
|
-
exports.MEDIA_PATH_MAP =
|
|
13
|
-
exports.DEFAULT_CONNECTION_CONFIG =
|
|
14
|
-
exports.PROCESSABLE_HISTORY_TYPES =
|
|
15
|
-
exports.WA_CERT_DETAILS =
|
|
16
|
-
exports.URL_REGEX =
|
|
17
|
-
exports.NOISE_WA_HEADER =
|
|
18
|
-
exports.KEY_BUNDLE_TYPE =
|
|
19
|
-
exports.DICT_VERSION =
|
|
20
|
-
exports.NOISE_MODE =
|
|
21
|
-
exports.WA_DEFAULT_EPHEMERAL =
|
|
22
|
-
exports.PHONE_CONNECTION_CB =
|
|
23
|
-
exports.DEF_TAG_PREFIX =
|
|
24
|
-
exports.DEF_CALLBACK_PREFIX =
|
|
25
|
-
exports.DEFAULT_ORIGIN =
|
|
26
|
-
exports.UNAUTHORIZED_CODES =
|
|
27
|
-
void 0;
|
|
28
|
-
|
|
29
|
-
const WAProto_1 = require("../../WAProto"),
|
|
30
|
-
libsignal_1 = require("../Signal/libsignal"),
|
|
31
|
-
Utils_1 = require("../Utils"),
|
|
32
|
-
logger_1 = __importDefault(require("../Utils/logger")),
|
|
33
|
-
baileys_version_json_1 = require("./baileys-version.json");
|
|
34
|
-
|
|
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.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = void 0;
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const libsignal_1 = require("../Signal/libsignal");
|
|
9
|
+
const Utils_1 = require("../Utils");
|
|
10
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
11
|
+
const baileys_version_json_1 = require("./baileys-version.json");
|
|
35
12
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
36
|
-
exports.DEFAULT_ORIGIN =
|
|
37
|
-
exports.DEF_CALLBACK_PREFIX =
|
|
38
|
-
exports.DEF_TAG_PREFIX =
|
|
39
|
-
exports.PHONE_CONNECTION_CB =
|
|
40
|
-
exports.WA_DEFAULT_EPHEMERAL =
|
|
41
|
-
exports.NOISE_MODE =
|
|
13
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
14
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
15
|
+
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
16
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
17
|
+
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
18
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
42
19
|
exports.DICT_VERSION = 2;
|
|
43
20
|
exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
44
|
-
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
|
|
45
|
-
|
|
21
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
|
|
22
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
46
23
|
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
47
|
-
exports.WA_CERT_DETAILS = {
|
|
48
|
-
|
|
24
|
+
exports.WA_CERT_DETAILS = {
|
|
25
|
+
SERIAL: 0,
|
|
26
|
+
};
|
|
49
27
|
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
50
28
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
51
29
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
52
30
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
53
31
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
54
|
-
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
|
|
32
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
|
|
55
33
|
];
|
|
56
|
-
|
|
57
34
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
58
35
|
version: baileys_version_json_1.version,
|
|
59
|
-
browser: Utils_1.Browsers.ubuntu(
|
|
60
|
-
waWebSocketUrl:
|
|
61
|
-
connectTimeoutMs:
|
|
62
|
-
keepAliveIntervalMs:
|
|
63
|
-
logger: logger_1.default.child({ class:
|
|
64
|
-
printQRInTerminal:
|
|
65
|
-
emitOwnEvents:
|
|
66
|
-
defaultQueryTimeoutMs:
|
|
36
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
37
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
38
|
+
connectTimeoutMs: 20000,
|
|
39
|
+
keepAliveIntervalMs: 30000,
|
|
40
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
41
|
+
printQRInTerminal: false,
|
|
42
|
+
emitOwnEvents: true,
|
|
43
|
+
defaultQueryTimeoutMs: 60000,
|
|
67
44
|
customUploadHosts: [],
|
|
68
45
|
retryRequestDelayMs: 250,
|
|
69
46
|
maxMsgRetryCount: 5,
|
|
70
|
-
fireInitQueries:
|
|
71
|
-
auth:
|
|
72
|
-
markOnlineOnConnect:
|
|
73
|
-
syncFullHistory:
|
|
74
|
-
patchMessageBeforeSending:
|
|
75
|
-
shouldSyncHistoryMessage: () =>
|
|
76
|
-
shouldIgnoreJid: () =>
|
|
47
|
+
fireInitQueries: true,
|
|
48
|
+
auth: undefined,
|
|
49
|
+
markOnlineOnConnect: true,
|
|
50
|
+
syncFullHistory: false,
|
|
51
|
+
patchMessageBeforeSending: msg => msg,
|
|
52
|
+
shouldSyncHistoryMessage: () => true,
|
|
53
|
+
shouldIgnoreJid: () => false,
|
|
77
54
|
linkPreviewImageThumbnailWidth: 192,
|
|
78
|
-
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs:
|
|
79
|
-
generateHighQualityLinkPreview:
|
|
55
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
56
|
+
generateHighQualityLinkPreview: false,
|
|
80
57
|
options: {},
|
|
81
|
-
appStateMacVerification: {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
58
|
+
appStateMacVerification: {
|
|
59
|
+
patch: false,
|
|
60
|
+
snapshot: false,
|
|
61
|
+
},
|
|
62
|
+
countryCode: 'US',
|
|
63
|
+
getMessage: async () => undefined,
|
|
64
|
+
cachedGroupMetadata: async () => undefined,
|
|
65
|
+
generateMessageID: () => undefined,
|
|
66
|
+
generateMessageIDV2: () => undefined,
|
|
85
67
|
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
86
68
|
};
|
|
87
|
-
|
|
88
69
|
exports.MEDIA_PATH_MAP = {
|
|
89
|
-
image:
|
|
90
|
-
video:
|
|
91
|
-
document:
|
|
92
|
-
audio:
|
|
93
|
-
sticker:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
70
|
+
image: '/mms/image',
|
|
71
|
+
video: '/mms/video',
|
|
72
|
+
document: '/mms/document',
|
|
73
|
+
audio: '/mms/audio',
|
|
74
|
+
sticker: '/mms/image',
|
|
75
|
+
'thumbnail-link': '/mms/image',
|
|
76
|
+
'product-catalog-image': '/product/image',
|
|
77
|
+
'md-app-state': '',
|
|
78
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
98
79
|
};
|
|
99
|
-
|
|
100
80
|
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
101
|
-
audio:
|
|
102
|
-
document:
|
|
103
|
-
gif:
|
|
104
|
-
image:
|
|
105
|
-
ppic:
|
|
106
|
-
product:
|
|
107
|
-
ptt:
|
|
108
|
-
sticker:
|
|
109
|
-
video:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
ptv:
|
|
81
|
+
'audio': 'Audio',
|
|
82
|
+
'document': 'Document',
|
|
83
|
+
'gif': 'Video',
|
|
84
|
+
'image': 'Image',
|
|
85
|
+
'ppic': '',
|
|
86
|
+
'product': 'Image',
|
|
87
|
+
'ptt': 'Audio',
|
|
88
|
+
'sticker': 'Image',
|
|
89
|
+
'video': 'Video',
|
|
90
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
91
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
92
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
93
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
94
|
+
'md-msg-hist': 'History',
|
|
95
|
+
'md-app-state': 'App State',
|
|
96
|
+
'product-catalog-image': '',
|
|
97
|
+
'payment-bg-image': 'Payment Background',
|
|
98
|
+
'ptv': 'Video'
|
|
119
99
|
};
|
|
120
|
-
|
|
121
100
|
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
122
101
|
exports.MIN_PREKEY_COUNT = 5;
|
|
123
102
|
exports.INITIAL_PREKEY_COUNT = 30;
|
|
124
|
-
|
|
125
103
|
exports.DEFAULT_CACHE_TTLS = {
|
|
126
|
-
SIGNAL_STORE:
|
|
127
|
-
MSG_RETRY:
|
|
128
|
-
CALL_OFFER:
|
|
129
|
-
USER_DEVICES:
|
|
104
|
+
SIGNAL_STORE: 10 * 60,
|
|
105
|
+
MSG_RETRY: 60 * 60,
|
|
106
|
+
CALL_OFFER: 5 * 60,
|
|
107
|
+
USER_DEVICES: 5 * 60, // 5 minutes
|
|
130
108
|
};
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -15,50 +15,34 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
})();
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
35
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.makeLibSignalRepository =
|
|
26
|
+
exports.makeLibSignalRepository = void 0;
|
|
37
27
|
const libsignal = __importStar(require("libsignal"));
|
|
28
|
+
const WASignalGroup_1 = require("../../WASignalGroup");
|
|
38
29
|
const Utils_1 = require("../Utils");
|
|
39
30
|
const WABinary_1 = require("../WABinary");
|
|
40
|
-
const sender_key_name_1 = require("./Group/sender-key-name");
|
|
41
|
-
const sender_key_record_1 = require("./Group/sender-key-record");
|
|
42
|
-
const Group_1 = require("./Group");
|
|
43
31
|
function makeLibSignalRepository(auth) {
|
|
44
32
|
const storage = signalStorage(auth);
|
|
45
33
|
return {
|
|
46
34
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
47
35
|
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
48
|
-
const cipher = new
|
|
36
|
+
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
49
37
|
return cipher.decrypt(msg);
|
|
50
38
|
},
|
|
51
39
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
52
|
-
const builder = new
|
|
53
|
-
if (!item.groupId) {
|
|
54
|
-
throw new Error('Group ID is required for sender key distribution message');
|
|
55
|
-
}
|
|
40
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
56
41
|
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
57
|
-
const senderMsg = new
|
|
58
|
-
const
|
|
59
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
42
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
43
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
60
44
|
if (!senderKey) {
|
|
61
|
-
await storage.storeSenderKey(senderName, new
|
|
45
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
62
46
|
}
|
|
63
47
|
await builder.process(senderName, senderMsg);
|
|
64
48
|
},
|
|
@@ -73,8 +57,6 @@ function makeLibSignalRepository(auth) {
|
|
|
73
57
|
case 'msg':
|
|
74
58
|
result = await session.decryptWhisperMessage(ciphertext);
|
|
75
59
|
break;
|
|
76
|
-
default:
|
|
77
|
-
throw new Error(`Unknown message type: ${type}`);
|
|
78
60
|
}
|
|
79
61
|
return result;
|
|
80
62
|
},
|
|
@@ -87,18 +69,17 @@ function makeLibSignalRepository(auth) {
|
|
|
87
69
|
},
|
|
88
70
|
async encryptGroupMessage({ group, meId, data }) {
|
|
89
71
|
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
90
|
-
const builder = new
|
|
91
|
-
const
|
|
92
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
72
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
73
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
93
74
|
if (!senderKey) {
|
|
94
|
-
await storage.storeSenderKey(senderName, new
|
|
75
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
95
76
|
}
|
|
96
77
|
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
97
|
-
const session = new
|
|
78
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
98
79
|
const ciphertext = await session.encrypt(data);
|
|
99
80
|
return {
|
|
100
81
|
ciphertext,
|
|
101
|
-
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
82
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
102
83
|
};
|
|
103
84
|
},
|
|
104
85
|
async injectE2ESession({ jid, session }) {
|
|
@@ -107,15 +88,16 @@ function makeLibSignalRepository(auth) {
|
|
|
107
88
|
},
|
|
108
89
|
jidToSignalProtocolAddress(jid) {
|
|
109
90
|
return jidToSignalProtocolAddress(jid).toString();
|
|
110
|
-
}
|
|
91
|
+
},
|
|
111
92
|
};
|
|
112
93
|
}
|
|
94
|
+
exports.makeLibSignalRepository = makeLibSignalRepository;
|
|
113
95
|
const jidToSignalProtocolAddress = (jid) => {
|
|
114
96
|
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
115
97
|
return new libsignal.ProtocolAddress(user, device || 0);
|
|
116
98
|
};
|
|
117
99
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
118
|
-
return new
|
|
100
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
|
|
119
101
|
};
|
|
120
102
|
function signalStorage({ creds, keys }) {
|
|
121
103
|
return {
|
|
@@ -126,7 +108,7 @@ function signalStorage({ creds, keys }) {
|
|
|
126
108
|
}
|
|
127
109
|
},
|
|
128
110
|
storeSession: async (id, session) => {
|
|
129
|
-
await keys.set({ session: { [id]: session.serialize() } });
|
|
111
|
+
await keys.set({ 'session': { [id]: session.serialize() } });
|
|
130
112
|
},
|
|
131
113
|
isTrustedIdentity: () => {
|
|
132
114
|
return true;
|
|
@@ -149,25 +131,21 @@ function signalStorage({ creds, keys }) {
|
|
|
149
131
|
pubKey: Buffer.from(key.keyPair.public)
|
|
150
132
|
};
|
|
151
133
|
},
|
|
152
|
-
loadSenderKey: async (
|
|
153
|
-
const keyId = senderKeyName.toString();
|
|
134
|
+
loadSenderKey: async (keyId) => {
|
|
154
135
|
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
155
136
|
if (key) {
|
|
156
|
-
return
|
|
137
|
+
return new WASignalGroup_1.SenderKeyRecord(key);
|
|
157
138
|
}
|
|
158
|
-
return new sender_key_record_1.SenderKeyRecord();
|
|
159
139
|
},
|
|
160
|
-
storeSenderKey: async (
|
|
161
|
-
|
|
162
|
-
const serialized = JSON.stringify(key.serialize());
|
|
163
|
-
await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
|
|
140
|
+
storeSenderKey: async (keyId, key) => {
|
|
141
|
+
await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
|
|
164
142
|
},
|
|
165
|
-
getOurRegistrationId: () => creds.registrationId,
|
|
143
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
166
144
|
getOurIdentity: () => {
|
|
167
145
|
const { signedIdentityKey } = creds;
|
|
168
146
|
return {
|
|
169
147
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
170
|
-
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
|
|
148
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
|
|
171
149
|
};
|
|
172
150
|
}
|
|
173
151
|
};
|