@baileys-md/baileys 10.0.7
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 +21 -0
- package/README.md +2 -0
- package/WAProto/index.js +155693 -0
- 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/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +122 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.js +161 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -0
- 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 +260 -0
- package/lib/Socket/chats.js +882 -0
- package/lib/Socket/groups.js +327 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.js +1043 -0
- package/lib/Socket/messages-send.js +836 -0
- package/lib/Socket/newsletter.js +248 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +640 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +431 -0
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.js +206 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.js +730 -0
- package/lib/Utils/crypto.js +151 -0
- package/lib/Utils/decode-wa-message.js +198 -0
- package/lib/Utils/event-buffer.js +520 -0
- package/lib/Utils/generics.js +445 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.js +126 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.js +724 -0
- package/lib/Utils/messages.js +1018 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.js +372 -0
- package/lib/Utils/signal.js +143 -0
- package/lib/Utils/use-multi-file-auth-state.js +93 -0
- package/lib/Utils/validate-connection.js +207 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.js +265 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.js +69 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +33 -0
- package/package.json +84 -0
|
@@ -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;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
11
|
+
constructor(iteration, seed) {
|
|
12
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
13
|
+
const keys = new Uint8Array(32);
|
|
14
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
15
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
16
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
17
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
+
|
|
19
|
+
this.iteration = iteration;
|
|
20
|
+
this.seed = seed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getIteration() {
|
|
24
|
+
return this.iteration;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getIv() {
|
|
28
|
+
return this.iv;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getCipherKey() {
|
|
32
|
+
return this.cipherKey;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getSeed() {
|
|
36
|
+
return this.seed;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports = SenderMessageKey;
|
|
@@ -0,0 +1,122 @@
|
|
|
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)]);
|
|
38
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
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,
|
|
42
|
+
};
|
|
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,
|
|
49
|
+
];
|
|
50
|
+
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
51
|
+
version: baileys_version_json_1.version,
|
|
52
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
53
|
+
waWebSocketUrl: 'https://web.whatsapp.com/ws/chat',
|
|
54
|
+
connectTimeoutMs: 20000,
|
|
55
|
+
keepAliveIntervalMs: 1000,
|
|
56
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
57
|
+
printQRInTerminal: false,
|
|
58
|
+
emitOwnEvents: true,
|
|
59
|
+
defaultQueryTimeoutMs: 60000,
|
|
60
|
+
customUploadHosts: [],
|
|
61
|
+
retryRequestDelayMs: 250,
|
|
62
|
+
maxMsgRetryCount: 5,
|
|
63
|
+
fireInitQueries: true,
|
|
64
|
+
auth: undefined,
|
|
65
|
+
markOnlineOnConnect: true,
|
|
66
|
+
syncFullHistory: false,
|
|
67
|
+
patchMessageBeforeSending: msg => msg,
|
|
68
|
+
shouldSyncHistoryMessage: () => true,
|
|
69
|
+
shouldIgnoreJid: () => false,
|
|
70
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
71
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
72
|
+
generateHighQualityLinkPreview: true,
|
|
73
|
+
options: {},
|
|
74
|
+
appStateMacVerification: {
|
|
75
|
+
patch: false,
|
|
76
|
+
snapshot: false,
|
|
77
|
+
},
|
|
78
|
+
countryCode: 'US',
|
|
79
|
+
getMessage: async () => undefined,
|
|
80
|
+
cachedGroupMetadata: async () => undefined,
|
|
81
|
+
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
82
|
+
};
|
|
83
|
+
exports.MEDIA_PATH_MAP = {
|
|
84
|
+
image: '/mms/image',
|
|
85
|
+
video: '/mms/video',
|
|
86
|
+
document: '/mms/document',
|
|
87
|
+
audio: '/mms/audio',
|
|
88
|
+
sticker: '/mms/image',
|
|
89
|
+
'thumbnail-link': '/mms/image',
|
|
90
|
+
'product-catalog-image': '/product/image',
|
|
91
|
+
'md-app-state': '',
|
|
92
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
93
|
+
};
|
|
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',
|
|
104
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
105
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
106
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
107
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
108
|
+
'md-msg-hist': 'History',
|
|
109
|
+
'md-app-state': 'App State',
|
|
110
|
+
'product-catalog-image': '',
|
|
111
|
+
'payment-bg-image': 'Payment Background',
|
|
112
|
+
'ptv': 'Video'
|
|
113
|
+
};
|
|
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 = {
|
|
118
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
119
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
120
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
121
|
+
USER_DEVICES: 5 * 60, // 5 minutes
|
|
122
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
{
|
|
2
|
+
"93": 412,
|
|
3
|
+
"355": 276,
|
|
4
|
+
"213": 603,
|
|
5
|
+
"1-684": 544,
|
|
6
|
+
"376": 213,
|
|
7
|
+
"244": 631,
|
|
8
|
+
"1-264": 365,
|
|
9
|
+
"1-268": 344,
|
|
10
|
+
"54": 722,
|
|
11
|
+
"374": 283,
|
|
12
|
+
"297": 363,
|
|
13
|
+
"61": 505,
|
|
14
|
+
"43": 232,
|
|
15
|
+
"994": 400,
|
|
16
|
+
"1-242": 364,
|
|
17
|
+
"973": 426,
|
|
18
|
+
"880": 470,
|
|
19
|
+
"1-246": 342,
|
|
20
|
+
"375": 257,
|
|
21
|
+
"32": 206,
|
|
22
|
+
"501": 702,
|
|
23
|
+
"229": 616,
|
|
24
|
+
"1-441": 350,
|
|
25
|
+
"975": 402,
|
|
26
|
+
"591": 736,
|
|
27
|
+
"387": 218,
|
|
28
|
+
"267": 652,
|
|
29
|
+
"55": 724,
|
|
30
|
+
"1-284": 348,
|
|
31
|
+
"673": 528,
|
|
32
|
+
"359": 284,
|
|
33
|
+
"226": 613,
|
|
34
|
+
"257": 642,
|
|
35
|
+
"855": 456,
|
|
36
|
+
"237": 624,
|
|
37
|
+
"238": 625,
|
|
38
|
+
"1-345": 346,
|
|
39
|
+
"236": 623,
|
|
40
|
+
"235": 622,
|
|
41
|
+
"56": 730,
|
|
42
|
+
"86": 454,
|
|
43
|
+
"57": 732,
|
|
44
|
+
"269": 654,
|
|
45
|
+
"682": 548,
|
|
46
|
+
"506": 712,
|
|
47
|
+
"385": 219,
|
|
48
|
+
"53": 368,
|
|
49
|
+
"357": 280,
|
|
50
|
+
"420": 230,
|
|
51
|
+
"243": 630,
|
|
52
|
+
"45": 238,
|
|
53
|
+
"253": 638,
|
|
54
|
+
"1-767": 366,
|
|
55
|
+
"1-809": 370,
|
|
56
|
+
"1-849": 370,
|
|
57
|
+
"1-829": 370,
|
|
58
|
+
"593": 740,
|
|
59
|
+
"20": 602,
|
|
60
|
+
"503": 706,
|
|
61
|
+
"240": 627,
|
|
62
|
+
"291": 657,
|
|
63
|
+
"372": 248,
|
|
64
|
+
"251": 636,
|
|
65
|
+
"500": 750,
|
|
66
|
+
"298": 288,
|
|
67
|
+
"679": 542,
|
|
68
|
+
"358": 244,
|
|
69
|
+
"33": 208,
|
|
70
|
+
"689": 547,
|
|
71
|
+
"241": 628,
|
|
72
|
+
"220": 607,
|
|
73
|
+
"995": 282,
|
|
74
|
+
"49": 262,
|
|
75
|
+
"233": 620,
|
|
76
|
+
"350": 266,
|
|
77
|
+
"30": 202,
|
|
78
|
+
"299": 290,
|
|
79
|
+
"1-473": 352,
|
|
80
|
+
"1-671": 535,
|
|
81
|
+
"502": 704,
|
|
82
|
+
"224": 537,
|
|
83
|
+
"592": 738,
|
|
84
|
+
"509": 372,
|
|
85
|
+
"504": 708,
|
|
86
|
+
"852": 454,
|
|
87
|
+
"36": 216,
|
|
88
|
+
"354": 274,
|
|
89
|
+
"91": 404,
|
|
90
|
+
"62": 510,
|
|
91
|
+
"98": 432,
|
|
92
|
+
"964": 418,
|
|
93
|
+
"353": 234,
|
|
94
|
+
"972": 425,
|
|
95
|
+
"39": 222,
|
|
96
|
+
"225": 612,
|
|
97
|
+
"1-876": 338,
|
|
98
|
+
"81": 440,
|
|
99
|
+
"962": 416,
|
|
100
|
+
"254": 639,
|
|
101
|
+
"686": 545,
|
|
102
|
+
"383": 221,
|
|
103
|
+
"965": 419,
|
|
104
|
+
"371": 247,
|
|
105
|
+
"961": 415,
|
|
106
|
+
"266": 651,
|
|
107
|
+
"231": 618,
|
|
108
|
+
"218": 606,
|
|
109
|
+
"423": 295,
|
|
110
|
+
"370": 246,
|
|
111
|
+
"352": 270,
|
|
112
|
+
"389": 294,
|
|
113
|
+
"261": 646,
|
|
114
|
+
"265": 650,
|
|
115
|
+
"60": 502,
|
|
116
|
+
"960": 472,
|
|
117
|
+
"223": 610,
|
|
118
|
+
"356": 278,
|
|
119
|
+
"692": 551,
|
|
120
|
+
"222": 609,
|
|
121
|
+
"230": 617,
|
|
122
|
+
"52": 334,
|
|
123
|
+
"691": 550,
|
|
124
|
+
"373": 259,
|
|
125
|
+
"377": 212,
|
|
126
|
+
"976": 428,
|
|
127
|
+
"382": 297,
|
|
128
|
+
"1-664": 354,
|
|
129
|
+
"212": 604,
|
|
130
|
+
"258": 643,
|
|
131
|
+
"95": 414,
|
|
132
|
+
"264": 649,
|
|
133
|
+
"674": 536,
|
|
134
|
+
"977": 429,
|
|
135
|
+
"31": 204,
|
|
136
|
+
"687": 546,
|
|
137
|
+
"64": 530,
|
|
138
|
+
"505": 710,
|
|
139
|
+
"227": 614,
|
|
140
|
+
"234": 621,
|
|
141
|
+
"683": 555,
|
|
142
|
+
"1-670": 534,
|
|
143
|
+
"47": 242,
|
|
144
|
+
"968": 226,
|
|
145
|
+
"92": 410,
|
|
146
|
+
"680": 552,
|
|
147
|
+
"970": 423,
|
|
148
|
+
"507": 714,
|
|
149
|
+
"675": 537,
|
|
150
|
+
"595": 744,
|
|
151
|
+
"51": 716,
|
|
152
|
+
"63": 515,
|
|
153
|
+
"48": 260,
|
|
154
|
+
"351": 268,
|
|
155
|
+
"1-787, 1-939": 330,
|
|
156
|
+
"974": 427,
|
|
157
|
+
"242": 630,
|
|
158
|
+
"40": 226,
|
|
159
|
+
"7": 250,
|
|
160
|
+
"250": 635,
|
|
161
|
+
"290": 658,
|
|
162
|
+
"1-869": 356,
|
|
163
|
+
"1-758": 358,
|
|
164
|
+
"508": 308,
|
|
165
|
+
"1-784": 360,
|
|
166
|
+
"685": 544,
|
|
167
|
+
"378": 292,
|
|
168
|
+
"239": 626,
|
|
169
|
+
"966": 420,
|
|
170
|
+
"221": 608,
|
|
171
|
+
"381": 220,
|
|
172
|
+
"248": 633,
|
|
173
|
+
"232": 619,
|
|
174
|
+
"65": 525,
|
|
175
|
+
"386": 293,
|
|
176
|
+
"677": 540,
|
|
177
|
+
"27": 655,
|
|
178
|
+
"211": 659,
|
|
179
|
+
"34": 214,
|
|
180
|
+
"94": 413,
|
|
181
|
+
"249": 634,
|
|
182
|
+
"597": 746,
|
|
183
|
+
"268": 653,
|
|
184
|
+
"46": 240,
|
|
185
|
+
"41": 228,
|
|
186
|
+
"963": 417,
|
|
187
|
+
"886": 466,
|
|
188
|
+
"992": 436,
|
|
189
|
+
"255": 640,
|
|
190
|
+
"66": 520,
|
|
191
|
+
"228": 615,
|
|
192
|
+
"690": 554,
|
|
193
|
+
"676": 539,
|
|
194
|
+
"1-868": 374,
|
|
195
|
+
"216": 605,
|
|
196
|
+
"90": 286,
|
|
197
|
+
"993": 438,
|
|
198
|
+
"1-649": 376,
|
|
199
|
+
"688": 553,
|
|
200
|
+
"1-340": 332,
|
|
201
|
+
"256": 641,
|
|
202
|
+
"380": 255,
|
|
203
|
+
"971": 424,
|
|
204
|
+
"44": 234,
|
|
205
|
+
"1": 310,
|
|
206
|
+
"598": 748,
|
|
207
|
+
"998": 434,
|
|
208
|
+
"678": 541,
|
|
209
|
+
"379": 225,
|
|
210
|
+
"58": 734,
|
|
211
|
+
"681": 543,
|
|
212
|
+
"967": 421,
|
|
213
|
+
"260": 645,
|
|
214
|
+
"263": 648,
|
|
215
|
+
"670": 514,
|
|
216
|
+
"245": 632,
|
|
217
|
+
"856": 457,
|
|
218
|
+
"599": 362,
|
|
219
|
+
"850": 467,
|
|
220
|
+
"262": 647,
|
|
221
|
+
"82": 450,
|
|
222
|
+
"84": 452
|
|
223
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
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) {
|
|
42
|
+
const storage = signalStorage(auth);
|
|
43
|
+
return {
|
|
44
|
+
decryptGroupMessage({ group, authorJid, msg }) {
|
|
45
|
+
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
46
|
+
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
47
|
+
return cipher.decrypt(msg);
|
|
48
|
+
},
|
|
49
|
+
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
50
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
51
|
+
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
52
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
53
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
54
|
+
if (!senderKey) {
|
|
55
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
56
|
+
}
|
|
57
|
+
await builder.process(senderName, senderMsg);
|
|
58
|
+
},
|
|
59
|
+
async decryptMessage({ jid, type, ciphertext }) {
|
|
60
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
61
|
+
const session = new libsignal.SessionCipher(storage, addr);
|
|
62
|
+
let result;
|
|
63
|
+
switch (type) {
|
|
64
|
+
case 'pkmsg':
|
|
65
|
+
result = await session.decryptPreKeyWhisperMessage(ciphertext);
|
|
66
|
+
break;
|
|
67
|
+
case 'msg':
|
|
68
|
+
result = await session.decryptWhisperMessage(ciphertext);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
},
|
|
73
|
+
async encryptMessage({ jid, data }) {
|
|
74
|
+
const addr = jidToSignalProtocolAddress(jid);
|
|
75
|
+
const cipher = new libsignal.SessionCipher(storage, addr);
|
|
76
|
+
const { type: sigType, body } = await cipher.encrypt(data);
|
|
77
|
+
const type = sigType === 3 ? 'pkmsg' : 'msg';
|
|
78
|
+
return { type, ciphertext: Buffer.from(body, 'binary') };
|
|
79
|
+
},
|
|
80
|
+
async encryptGroupMessage({ group, meId, data }) {
|
|
81
|
+
const senderName = jidToSignalSenderKeyName(group, meId);
|
|
82
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
|
|
83
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
|
|
84
|
+
if (!senderKey) {
|
|
85
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
|
|
86
|
+
}
|
|
87
|
+
const senderKeyDistributionMessage = await builder.create(senderName);
|
|
88
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName);
|
|
89
|
+
const ciphertext = await session.encrypt(data);
|
|
90
|
+
return {
|
|
91
|
+
ciphertext,
|
|
92
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
async injectE2ESession({ jid, session }) {
|
|
96
|
+
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
|
|
97
|
+
await cipher.initOutgoing(session);
|
|
98
|
+
},
|
|
99
|
+
jidToSignalProtocolAddress(jid) {
|
|
100
|
+
return jidToSignalProtocolAddress(jid).toString();
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const jidToSignalProtocolAddress = (jid) => {
|
|
105
|
+
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
106
|
+
return new libsignal.ProtocolAddress(user, device || 0);
|
|
107
|
+
};
|
|
108
|
+
const jidToSignalSenderKeyName = (group, user) => {
|
|
109
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
|
|
110
|
+
};
|
|
111
|
+
function signalStorage({ creds, keys }) {
|
|
112
|
+
return {
|
|
113
|
+
loadSession: async (id) => {
|
|
114
|
+
const { [id]: sess } = await keys.get('session', [id]);
|
|
115
|
+
if (sess) {
|
|
116
|
+
return libsignal.SessionRecord.deserialize(sess);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
storeSession: async (id, session) => {
|
|
120
|
+
await keys.set({ 'session': { [id]: session.serialize() } });
|
|
121
|
+
},
|
|
122
|
+
isTrustedIdentity: () => {
|
|
123
|
+
return true;
|
|
124
|
+
},
|
|
125
|
+
loadPreKey: async (id) => {
|
|
126
|
+
const keyId = id.toString();
|
|
127
|
+
const { [keyId]: key } = await keys.get('pre-key', [keyId]);
|
|
128
|
+
if (key) {
|
|
129
|
+
return {
|
|
130
|
+
privKey: Buffer.from(key.private),
|
|
131
|
+
pubKey: Buffer.from(key.public)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
|
|
136
|
+
loadSignedPreKey: () => {
|
|
137
|
+
const key = creds.signedPreKey;
|
|
138
|
+
return {
|
|
139
|
+
privKey: Buffer.from(key.keyPair.private),
|
|
140
|
+
pubKey: Buffer.from(key.keyPair.public)
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
loadSenderKey: async (keyId) => {
|
|
144
|
+
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
145
|
+
if (key) {
|
|
146
|
+
return new WASignalGroup_1.SenderKeyRecord(key);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
storeSenderKey: async (keyId, key) => {
|
|
150
|
+
await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
|
|
151
|
+
},
|
|
152
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
153
|
+
getOurIdentity: () => {
|
|
154
|
+
const { signedIdentityKey } = creds;
|
|
155
|
+
return {
|
|
156
|
+
privKey: Buffer.from(signedIdentityKey.private),
|
|
157
|
+
pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -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;
|