@nexustechpro/baileys 1.1.7 → 2.0.1
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 +1745 -1745
- package/WAProto/GenerateStatics.sh +3 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +150 -128
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.js +19 -1
- package/lib/Socket/index.js +8 -4
- package/lib/Socket/messages-recv.js +18 -7
- package/lib/Socket/messages-send.js +60 -9
- package/lib/Socket/nexus-handler.js +1 -1
- package/lib/Socket/registration.js +197 -0
- package/lib/Socket/socket.js +8 -27
- package/lib/Utils/decode-wa-message.js +6 -0
- package/lib/Utils/generics.js +1 -1
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/messages-media.js +147 -305
- package/lib/index.js +4 -5
- package/package.json +15 -8
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify --no-comments -o ./index.js ./WAProto.proto;
|
|
2
|
+
yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify ./WAProto.proto | yarn pbts --no-comments -o ./index.d.ts -;
|
|
3
|
+
node ./fix-imports.js
|
package/lib/Defaults/index.js
CHANGED
|
@@ -1,151 +1,173 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
5
|
+
import { Browsers } from '../Utils/browser-utils.js';
|
|
6
|
+
import logger from '../Utils/logger.js';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const PHONENUMBER_MCC = require('./phonenumber-mcc.json');
|
|
9
|
+
export { PHONENUMBER_MCC };
|
|
10
|
+
const version = [2, 3000, 1027934701];
|
|
5
11
|
|
|
6
|
-
const
|
|
12
|
+
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
13
|
|
|
8
|
-
export const
|
|
14
|
+
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
15
|
+
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
16
|
+
export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
17
|
+
export const DEF_CALLBACK_PREFIX = 'CB:';
|
|
18
|
+
export const DEF_TAG_PREFIX = 'TAG:';
|
|
19
|
+
export const PHONE_CONNECTION_CB = 'CB:Pong';
|
|
9
20
|
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
export const DEF_TAG_PREFIX = 'TAG:'
|
|
15
|
-
export const PHONE_CONNECTION_CB = 'CB:Pong'
|
|
21
|
+
export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
|
|
22
|
+
export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
|
|
23
|
+
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
|
|
24
|
+
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
|
|
16
25
|
|
|
17
|
-
export const
|
|
18
|
-
export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1])
|
|
19
|
-
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5])
|
|
20
|
-
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6])
|
|
26
|
+
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
21
27
|
|
|
22
|
-
export const
|
|
28
|
+
export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
|
|
23
29
|
|
|
24
|
-
export const
|
|
30
|
+
export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
|
|
25
31
|
|
|
26
|
-
export const
|
|
32
|
+
export const BATCH_SIZE = 500;
|
|
27
33
|
|
|
28
|
-
export const
|
|
34
|
+
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
35
|
+
export const DICT_VERSION = 3;
|
|
36
|
+
export const KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
37
|
+
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]);
|
|
29
38
|
|
|
30
|
-
export const
|
|
31
|
-
export const DICT_VERSION = 3
|
|
32
|
-
export const KEY_BUNDLE_TYPE = Buffer.from([5])
|
|
33
|
-
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION])
|
|
34
|
-
|
|
35
|
-
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
|
|
39
|
+
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
36
40
|
|
|
37
41
|
export const WA_CERT_DETAILS = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
+
SERIAL: 0,
|
|
43
|
+
ISSUER: 'WhatsAppLongTerm1',
|
|
44
|
+
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
45
|
+
};
|
|
42
46
|
|
|
43
47
|
export const PROCESSABLE_HISTORY_TYPES = [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
]
|
|
48
|
+
proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
49
|
+
proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
50
|
+
proto.HistorySync.HistorySyncType.RECENT,
|
|
51
|
+
proto.HistorySync.HistorySyncType.FULL,
|
|
52
|
+
proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
53
|
+
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
54
|
+
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
55
|
+
];
|
|
56
|
+
export const MOBILE_ENDPOINT = 'g.whatsapp.net';
|
|
57
|
+
export const MOBILE_PORT = 443;
|
|
58
|
+
|
|
59
|
+
const WA_VERSION = '2.25.23.24';
|
|
60
|
+
const WA_VERSION_HASH = createHash('md5').update(WA_VERSION).digest('hex');
|
|
61
|
+
|
|
62
|
+
export const MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
|
|
63
|
+
export const MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
64
|
+
export const MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`;
|
|
65
|
+
|
|
66
|
+
export const REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
67
|
+
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,
|
|
68
|
+
34, 251, 111, 18, 37, 18, 48, 45,
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
export const PROTOCOL_VERSION = [5, 2];
|
|
72
|
+
export const MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(PROTOCOL_VERSION)]);
|
|
73
|
+
|
|
52
74
|
|
|
53
75
|
export const DEFAULT_CONNECTION_CONFIG = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
76
|
+
version,
|
|
77
|
+
browser: Browsers.macOS('Safari'),
|
|
78
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
79
|
+
connectTimeoutMs: 600000,
|
|
80
|
+
keepAliveIntervalMs: 30000,
|
|
81
|
+
logger: logger.child({ class: 'baileys' }),
|
|
82
|
+
emitOwnEvents: true,
|
|
83
|
+
defaultQueryTimeoutMs: 60000,
|
|
84
|
+
customUploadHosts: [],
|
|
85
|
+
retryRequestDelayMs: 250,
|
|
86
|
+
maxMsgRetryCount: 5,
|
|
87
|
+
fireInitQueries: true,
|
|
88
|
+
auth: undefined,
|
|
89
|
+
markOnlineOnConnect: true,
|
|
90
|
+
syncFullHistory: true,
|
|
91
|
+
patchMessageBeforeSending: msg => msg,
|
|
92
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
93
|
+
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
94
|
+
},
|
|
95
|
+
shouldIgnoreJid: () => false,
|
|
96
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
97
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
98
|
+
generateHighQualityLinkPreview: false,
|
|
99
|
+
enableAutoSessionRecreation: true,
|
|
100
|
+
enableRecentMessageCache: true,
|
|
101
|
+
options: {},
|
|
102
|
+
appStateMacVerification: {
|
|
103
|
+
patch: false,
|
|
104
|
+
snapshot: false
|
|
105
|
+
},
|
|
106
|
+
countryCode: 'US',
|
|
107
|
+
getMessage: async () => undefined,
|
|
108
|
+
cachedGroupMetadata: async () => undefined,
|
|
109
|
+
makeSignalRepository: makeLibSignalRepository
|
|
110
|
+
};
|
|
89
111
|
|
|
90
112
|
export const MEDIA_PATH_MAP = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
113
|
+
image: '/mms/image',
|
|
114
|
+
video: '/mms/video',
|
|
115
|
+
document: '/mms/document',
|
|
116
|
+
audio: '/mms/audio',
|
|
117
|
+
sticker: '/mms/image',
|
|
118
|
+
'sticker-pack': '/mms/sticker-pack',
|
|
119
|
+
'thumbnail-link': '/mms/image',
|
|
120
|
+
'thumbnail-sticker-pack': '/mms/thumbnail-sticker-pack',
|
|
121
|
+
'product-catalog-image': '/product/image',
|
|
122
|
+
'md-app-state': '',
|
|
123
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
124
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
125
|
+
};
|
|
104
126
|
|
|
105
127
|
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP)
|
|
131
|
-
|
|
132
|
-
export const MIN_PREKEY_COUNT = 5
|
|
133
|
-
|
|
134
|
-
export const INITIAL_PREKEY_COUNT = 95
|
|
135
|
-
|
|
136
|
-
export const UPLOAD_TIMEOUT = 30000
|
|
137
|
-
export const MIN_UPLOAD_INTERVAL = 5000
|
|
128
|
+
audio: 'Audio',
|
|
129
|
+
document: 'Document',
|
|
130
|
+
gif: 'Video',
|
|
131
|
+
image: 'Image',
|
|
132
|
+
ppic: '',
|
|
133
|
+
product: 'Image',
|
|
134
|
+
ptt: 'Audio',
|
|
135
|
+
'sticker-pack-publisher': 'Sticker Pack Publisher',
|
|
136
|
+
sticker: 'Image',
|
|
137
|
+
'sticker-pack': 'Sticker Pack',
|
|
138
|
+
'thumbnail-sticker-pack': 'Sticker Pack Thumbnail',
|
|
139
|
+
video: 'Video',
|
|
140
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
141
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
142
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
143
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
144
|
+
'md-msg-hist': 'History',
|
|
145
|
+
'md-app-state': 'App State',
|
|
146
|
+
'product-catalog-image': '',
|
|
147
|
+
'payment-bg-image': 'Payment Background',
|
|
148
|
+
ptv: 'Video',
|
|
149
|
+
'biz-cover-photo': 'Image'
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
153
|
+
|
|
154
|
+
export const MIN_PREKEY_COUNT = 5;
|
|
155
|
+
|
|
156
|
+
export const INITIAL_PREKEY_COUNT = 95;
|
|
157
|
+
|
|
158
|
+
export const UPLOAD_TIMEOUT = 30000;
|
|
159
|
+
export const MIN_UPLOAD_INTERVAL = 5000;
|
|
138
160
|
|
|
139
161
|
export const DEFAULT_CACHE_TTLS = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
162
|
+
SIGNAL_STORE: 5 * 60,
|
|
163
|
+
MSG_RETRY: 60 * 60,
|
|
164
|
+
CALL_OFFER: 5 * 60,
|
|
165
|
+
USER_DEVICES: 5 * 60
|
|
166
|
+
};
|
|
145
167
|
|
|
146
168
|
export const TimeMs = {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
169
|
+
Minute: 60 * 1000,
|
|
170
|
+
Hour: 60 * 60 * 1000,
|
|
171
|
+
Day: 24 * 60 * 60 * 1000,
|
|
172
|
+
Week: 7 * 24 * 60 * 60 * 1000
|
|
173
|
+
};
|
|
@@ -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
|
+
}
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -49,7 +49,7 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
|
|
|
49
49
|
}, item.groupId)
|
|
50
50
|
},
|
|
51
51
|
|
|
52
|
-
decryptMessage: async ({ jid, type, ciphertext }) => {
|
|
52
|
+
decryptMessage: async ({ jid, type, ciphertext, alternateJid }) => {
|
|
53
53
|
const addr = jidToAddr(jid)
|
|
54
54
|
const session = new libsignal.SessionCipher(storage, addr)
|
|
55
55
|
try {
|
|
@@ -64,6 +64,24 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
|
|
|
64
64
|
if (msg.includes("Bad MAC") || msg.includes("Key used already")) {
|
|
65
65
|
logger?.warn?.({ jid, error: msg }, "Session corrupted")
|
|
66
66
|
}
|
|
67
|
+
// Retry with alternate JID if available and error is specifically "No matching sessions found"
|
|
68
|
+
if (alternateJid && msg.includes("No matching sessions found for message")) {
|
|
69
|
+
logger?.debug?.({ jid, alternateJid }, "Retrying decryption with alternate address")
|
|
70
|
+
const altAddr = jidToAddr(alternateJid)
|
|
71
|
+
const altSession = new libsignal.SessionCipher(storage, altAddr)
|
|
72
|
+
try {
|
|
73
|
+
return txn(async () => {
|
|
74
|
+
switch (type) {
|
|
75
|
+
case "pkmsg": return await altSession.decryptPreKeyWhisperMessage(ciphertext)
|
|
76
|
+
case "msg": return await altSession.decryptWhisperMessage(ciphertext)
|
|
77
|
+
}
|
|
78
|
+
}, alternateJid)
|
|
79
|
+
} catch (altErr) {
|
|
80
|
+
const altMsg = altErr?.message || ""
|
|
81
|
+
logger?.warn?.({ alternateJid, error: altMsg }, "Decryption with alternate address also failed")
|
|
82
|
+
throw e
|
|
83
|
+
}
|
|
84
|
+
}
|
|
67
85
|
throw e
|
|
68
86
|
}
|
|
69
87
|
},
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { makeRegistrationSocket } from './registration.js';
|
|
3
3
|
import NexusHandler from './nexus-handler.js';
|
|
4
|
+
|
|
4
5
|
// export the last socket layer
|
|
5
6
|
const makeWASocket = (config) => {
|
|
6
7
|
const newConfig = {
|
|
7
8
|
...DEFAULT_CONNECTION_CONFIG,
|
|
8
9
|
...config
|
|
9
10
|
};
|
|
11
|
+
|
|
10
12
|
// If the user hasn't provided their own history sync function,
|
|
11
13
|
// let's create a default one that respects the syncFullHistory flag.
|
|
12
14
|
if (config.shouldSyncHistoryMessage === undefined) {
|
|
13
15
|
newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory;
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
return makeRegistrationSocket(newConfig);
|
|
16
19
|
};
|
|
20
|
+
|
|
17
21
|
export { NexusHandler };
|
|
18
|
-
export
|
|
19
|
-
|
|
22
|
+
export { makeWASocket };
|
|
23
|
+
export default makeWASocket;
|
|
@@ -46,12 +46,12 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
46
46
|
|
|
47
47
|
const handleMexNewsletterNotification = async (node) => {
|
|
48
48
|
const mexNode = getBinaryNodeChild(node, "mex")
|
|
49
|
-
if (!mexNode?.content) { logger.warn({ node }, "Invalid mex newsletter notification")
|
|
49
|
+
if (!mexNode?.content) { /*logger.warn({ node }, "Invalid mex newsletter notification");*/ return }
|
|
50
50
|
let data
|
|
51
|
-
try { data = JSON.parse(mexNode.content.toString()) } catch (error) { logger.error({ err: error, node }, "Failed to parse mex newsletter notification")
|
|
51
|
+
try { data = JSON.parse(mexNode.content.toString()) } catch (error) { /*logger.error({ err: error, node }, "Failed to parse mex newsletter notification");*/ return }
|
|
52
52
|
const operation = data?.operation
|
|
53
53
|
const updates = data?.updates
|
|
54
|
-
if (!updates || !operation) { logger.warn({ data }, "Invalid mex newsletter notification content")
|
|
54
|
+
if (!updates || !operation) { /*logger.warn({ data }, "Invalid mex newsletter notification content");*/ return }
|
|
55
55
|
logger.info({ operation, updates }, "got mex newsletter notification")
|
|
56
56
|
switch (operation) {
|
|
57
57
|
case "NotificationNewsletterUpdate":
|
|
@@ -459,9 +459,9 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
459
459
|
if (shouldRecreateSession) { logger.debug({ participant, retryCount, reason: recreateReason }, "recreating session for outgoing retry"); await authState.keys.set({ session: { [sessionId]: null } }) }
|
|
460
460
|
} catch (error) { logger.warn({ error, participant }, "failed to check session recreation for outgoing retry") }
|
|
461
461
|
}
|
|
462
|
-
await assertSessions([participant],
|
|
462
|
+
await assertSessions([participant], false);
|
|
463
463
|
if (isJidGroup(remoteJid)) await authState.keys.set({ "sender-key-memory": { [remoteJid]: null } })
|
|
464
|
-
logger.debug({ participant, sendToAll, shouldRecreateSession, recreateReason }, "
|
|
464
|
+
logger.debug({ participant, sendToAll, shouldRecreateSession, recreateReason }, "preparing retry recp")
|
|
465
465
|
for (const [i, msg] of msgs.entries()) {
|
|
466
466
|
if (!ids[i]) continue
|
|
467
467
|
if (msg && (await willSendMessageAgain(ids[i], participant))) {
|
|
@@ -488,7 +488,7 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
488
488
|
ids.push(...items.map((i) => i.attrs.id))
|
|
489
489
|
}
|
|
490
490
|
try {
|
|
491
|
-
await Promise.all([
|
|
491
|
+
await Promise.all([processingMutex.mutex(async () => {
|
|
492
492
|
const status = getStatusFromReceiptType(attrs.type)
|
|
493
493
|
if (typeof status !== "undefined" && (status >= proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
|
|
494
494
|
if (isJidGroup(remoteJid) || isJidStatusBroadcast(remoteJid)) {
|
|
@@ -509,7 +509,18 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
509
509
|
await sendMessagesAgain(key, ids, retryNode)
|
|
510
510
|
} catch (error) { logger.error({ key, ids, trace: error instanceof Error ? error.stack : "Unknown error" }, "error in sending message again") }
|
|
511
511
|
} else logger.info({ attrs, key }, "recv retry for not fromMe message")
|
|
512
|
-
} else
|
|
512
|
+
} else {
|
|
513
|
+
logger.info({ attrs, key, participant: key.participant }, "retry limit exhausted - clearing broken session")
|
|
514
|
+
try {
|
|
515
|
+
await signalRepository.deleteSession([key.participant])
|
|
516
|
+
logger.debug({ participant: key.participant }, "deleted stale session for retry-exhausted participant")
|
|
517
|
+
const retryKey = `${ids[0]}:${key.participant}`
|
|
518
|
+
await msgRetryCache.del(retryKey)
|
|
519
|
+
logger.debug({ retryKey }, "cleared retry count cache")
|
|
520
|
+
} catch (err) {
|
|
521
|
+
logger.error({ err, participant: key.participant }, "failed to clear session/cache at retry exhaustion")
|
|
522
|
+
}
|
|
523
|
+
}
|
|
513
524
|
}
|
|
514
525
|
})])
|
|
515
526
|
} finally {
|