whalibmob 5.40.35 → 5.40.37
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 +6 -0
- package/docs/events-history.md +41 -0
- package/docs/groups-channels.md +86 -0
- package/docs/messaging.md +107 -0
- package/index.d.ts +136 -0
- package/index.js +1 -0
- package/lib/Client.js +824 -25
- package/lib/appstate/Mutations.js +51 -1
- package/lib/appstate/SyncdProto.js +48 -0
- package/lib/messages/MessageSecret.js +116 -0
- package/lib/messages/MessageSender.js +38 -0
- package/lib/noise.js +6 -0
- package/lib/proto/MessageProto.js +110 -3
- package/llms.txt +3 -2
- package/package.json +1 -1
|
@@ -81,6 +81,47 @@ function contactPatch(jid, contact) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
// Labels live in their own collection. A label is created, renamed, recoloured
|
|
85
|
+
// or deleted by its id; a chat or one message is then tagged with it.
|
|
86
|
+
function labelEditPatch(labelId, name, color, deleted) {
|
|
87
|
+
return {
|
|
88
|
+
name: 'regular',
|
|
89
|
+
index: ['label_edit', String(labelId)],
|
|
90
|
+
apiVersion: 3,
|
|
91
|
+
action: { labelEditAction: { name: name || '', color: color || 0, deleted: !!deleted } }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function labelChatPatch(jid, labelId, labeled) {
|
|
96
|
+
return {
|
|
97
|
+
name: 'regular',
|
|
98
|
+
index: ['label_jid', String(labelId), jid],
|
|
99
|
+
apiVersion: 3,
|
|
100
|
+
action: { labelAssociationAction: { labeled: !!labeled } }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function labelMessagePatch(jid, labelId, msgId, labeled) {
|
|
105
|
+
return {
|
|
106
|
+
name: 'regular',
|
|
107
|
+
index: ['label_message', String(labelId), jid, msgId, '0', '0'],
|
|
108
|
+
apiVersion: 3,
|
|
109
|
+
action: { labelAssociationAction: { labeled: !!labeled } }
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Delete one message on this account's devices only; nobody else's copy moves.
|
|
114
|
+
function deleteMessageForMePatch(jid, msgId, fromMe, messageTimestamp, deleteMedia) {
|
|
115
|
+
return {
|
|
116
|
+
name: 'regular_high',
|
|
117
|
+
index: ['deleteMessageForMe', jid, msgId, fromMe ? '1' : '0', '0'],
|
|
118
|
+
apiVersion: 3,
|
|
119
|
+
action: { deleteMessageForMeAction: {
|
|
120
|
+
deleteMedia: !!deleteMedia, messageTimestamp: messageTimestamp || undefined
|
|
121
|
+
} }
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
84
125
|
// The index tells you what a decoded mutation was about. The first element is
|
|
85
126
|
// the kind; what follows depends on it.
|
|
86
127
|
function describeIndex(index) {
|
|
@@ -96,6 +137,14 @@ function describeIndex(index) {
|
|
|
96
137
|
case 'setting_pushName':return { kind: 'pushName' };
|
|
97
138
|
case 'clearChat': return { kind: 'clear', jid };
|
|
98
139
|
case 'deleteChat': return { kind: 'delete', jid };
|
|
140
|
+
// The label's id comes first in a label index, then what it is put on.
|
|
141
|
+
case 'label_edit': return { kind: 'labelEdit', labelId: jid };
|
|
142
|
+
case 'label_jid': return { kind: 'labelChat', labelId: jid, jid: msgId };
|
|
143
|
+
case 'label_message': return { kind: 'labelMessage', labelId: jid, jid: msgId, msgId: fromMe };
|
|
144
|
+
case 'deleteMessageForMe':
|
|
145
|
+
return { kind: 'deleteForMe', jid, msgId, fromMe: fromMe === '1' };
|
|
146
|
+
case 'userStatusMute': return { kind: 'statusMute', jid };
|
|
147
|
+
case 'setting_unarchiveChats': return { kind: 'unarchiveChats' };
|
|
99
148
|
// Account-wide, no jid: the salt the cstoken fallback is derived from.
|
|
100
149
|
case 'nct_salt_sync': return { kind: 'nct_salt_sync' };
|
|
101
150
|
default: return { kind, jid };
|
|
@@ -104,5 +153,6 @@ function describeIndex(index) {
|
|
|
104
153
|
|
|
105
154
|
module.exports = {
|
|
106
155
|
mutePatch, archivePatch, markReadPatch, pinPatch, starPatch,
|
|
107
|
-
pushNamePatch, contactPatch,
|
|
156
|
+
pushNamePatch, contactPatch, labelEditPatch, labelChatPatch, labelMessagePatch,
|
|
157
|
+
deleteMessageForMePatch, describeIndex
|
|
108
158
|
};
|
|
@@ -122,6 +122,11 @@ const ACTION_FIELDS = {
|
|
|
122
122
|
4: 'muteAction',
|
|
123
123
|
5: 'pinAction',
|
|
124
124
|
7: 'pushNameSetting',
|
|
125
|
+
14: 'labelEditAction',
|
|
126
|
+
15: 'labelAssociationAction',
|
|
127
|
+
18: 'deleteMessageForMeAction',
|
|
128
|
+
23: 'unarchiveChatsSetting',
|
|
129
|
+
29: 'userStatusMuteAction',
|
|
125
130
|
17: 'archiveChatAction',
|
|
126
131
|
20: 'markChatAsReadAction',
|
|
127
132
|
21: 'clearChatAction',
|
|
@@ -142,6 +147,23 @@ function decodeSyncActionValue(buf) {
|
|
|
142
147
|
switch (name) {
|
|
143
148
|
case 'starAction':
|
|
144
149
|
out.starAction = { starred: !!_num(a[1]) }; break;
|
|
150
|
+
// LabelEditAction { name = 1, color = 2, predefinedID = 3, deleted = 4 }
|
|
151
|
+
case 'labelEditAction':
|
|
152
|
+
out.labelEditAction = {
|
|
153
|
+
name: _str(a[1]), color: _num(a[2]) || 0,
|
|
154
|
+
predefinedId: a[3] != null ? _num(a[3]) : null, deleted: !!_num(a[4])
|
|
155
|
+
}; break;
|
|
156
|
+
case 'labelAssociationAction':
|
|
157
|
+
out.labelAssociationAction = { labeled: !!_num(a[1]) }; break;
|
|
158
|
+
// DeleteMessageForMeAction { deleteMedia = 1, messageTimestamp = 2 }
|
|
159
|
+
case 'deleteMessageForMeAction':
|
|
160
|
+
out.deleteMessageForMeAction = {
|
|
161
|
+
deleteMedia: !!_num(a[1]), messageTimestamp: a[2] != null ? _num(a[2]) : null
|
|
162
|
+
}; break;
|
|
163
|
+
case 'unarchiveChatsSetting':
|
|
164
|
+
out.unarchiveChatsSetting = { unarchiveChats: !!_num(a[1]) }; break;
|
|
165
|
+
case 'userStatusMuteAction':
|
|
166
|
+
out.userStatusMuteAction = { muted: !!_num(a[1]) }; break;
|
|
145
167
|
case 'pinAction':
|
|
146
168
|
out.pinAction = { pinned: !!_num(a[1]) }; break;
|
|
147
169
|
case 'muteAction':
|
|
@@ -226,6 +248,32 @@ function encodeSyncActionValue(action, timestampMs) {
|
|
|
226
248
|
parts.push(field(20, WIRE_LEN,
|
|
227
249
|
field(1, WIRE_VARINT, varint(action.markChatAsReadAction.read ? 1 : 0))));
|
|
228
250
|
}
|
|
251
|
+
if (action.labelEditAction) {
|
|
252
|
+
const l = action.labelEditAction;
|
|
253
|
+
parts.push(field(14, WIRE_LEN, Buffer.concat([
|
|
254
|
+
field(1, WIRE_LEN, str(l.name || '')),
|
|
255
|
+
field(2, WIRE_VARINT, varint(l.color || 0)),
|
|
256
|
+
field(4, WIRE_VARINT, varint(l.deleted ? 1 : 0))
|
|
257
|
+
])));
|
|
258
|
+
}
|
|
259
|
+
if (action.labelAssociationAction) {
|
|
260
|
+
parts.push(field(15, WIRE_LEN,
|
|
261
|
+
field(1, WIRE_VARINT, varint(action.labelAssociationAction.labeled ? 1 : 0))));
|
|
262
|
+
}
|
|
263
|
+
if (action.deleteMessageForMeAction) {
|
|
264
|
+
const d = action.deleteMessageForMeAction;
|
|
265
|
+
const inner = [field(1, WIRE_VARINT, varint(d.deleteMedia ? 1 : 0))];
|
|
266
|
+
if (d.messageTimestamp) inner.push(field(2, WIRE_VARINT, varint(d.messageTimestamp)));
|
|
267
|
+
parts.push(field(18, WIRE_LEN, Buffer.concat(inner)));
|
|
268
|
+
}
|
|
269
|
+
if (action.unarchiveChatsSetting) {
|
|
270
|
+
parts.push(field(23, WIRE_LEN,
|
|
271
|
+
field(1, WIRE_VARINT, varint(action.unarchiveChatsSetting.unarchiveChats ? 1 : 0))));
|
|
272
|
+
}
|
|
273
|
+
if (action.userStatusMuteAction) {
|
|
274
|
+
parts.push(field(29, WIRE_LEN,
|
|
275
|
+
field(1, WIRE_VARINT, varint(action.userStatusMuteAction.muted ? 1 : 0))));
|
|
276
|
+
}
|
|
229
277
|
return Buffer.concat(parts);
|
|
230
278
|
}
|
|
231
279
|
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Messages that act on another message and are encrypted under that message's
|
|
4
|
+
// secret: a vote on a poll, a reaction or a comment in a community announcement
|
|
5
|
+
// group, a response to an event, an encrypted edit.
|
|
6
|
+
//
|
|
7
|
+
// Every one of them is sealed the same way. The message being acted on carries
|
|
8
|
+
// a 32-byte secret beside its content (messageContextInfo.messageSecret), and
|
|
9
|
+
// the key for one add-on is derived from that secret and from who is involved:
|
|
10
|
+
//
|
|
11
|
+
// key = HKDF-SHA256(secret, salt = none,
|
|
12
|
+
// info = targetId | targetSender | addOnSender | useCase, 32)
|
|
13
|
+
// payload = AES-256-GCM(key, iv, plaintext, aad)
|
|
14
|
+
//
|
|
15
|
+
// The use case is a fixed label, so a key for a vote cannot open a reaction.
|
|
16
|
+
// Two of them also bind the ciphertext to its target with additional data,
|
|
17
|
+
// targetId | 0x00 | addOnSender; the others use none. Both JIDs go in without
|
|
18
|
+
// a device: an add-on belongs to an account.
|
|
19
|
+
|
|
20
|
+
const crypto = require('crypto');
|
|
21
|
+
const { hkdfSha256 } = require('../hkdf');
|
|
22
|
+
|
|
23
|
+
const SECRET_TYPE = {
|
|
24
|
+
POLL_VOTE: 'Poll Vote',
|
|
25
|
+
REACTION: 'Enc Reaction',
|
|
26
|
+
COMMENT: 'Enc Comment',
|
|
27
|
+
EVENT_RESPONSE: 'Event Response',
|
|
28
|
+
EVENT_EDIT: 'Event Edit',
|
|
29
|
+
MESSAGE_EDIT: 'Message Edit',
|
|
30
|
+
POLL_EDIT: 'Poll Edit',
|
|
31
|
+
POLL_ADD_OPTION: 'Poll Add Option'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// SecretEncryptedMessage.secretEncType → the label its key is derived under.
|
|
35
|
+
const SECRET_ENC_TYPE = {
|
|
36
|
+
1: SECRET_TYPE.EVENT_EDIT,
|
|
37
|
+
2: SECRET_TYPE.MESSAGE_EDIT,
|
|
38
|
+
4: SECRET_TYPE.POLL_EDIT,
|
|
39
|
+
// An added option is sealed under the same label as an edit of the poll.
|
|
40
|
+
5: SECRET_TYPE.POLL_EDIT
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const WITH_AAD = new Set([SECRET_TYPE.POLL_VOTE, SECRET_TYPE.EVENT_RESPONSE]);
|
|
44
|
+
|
|
45
|
+
function nonAd(jid) {
|
|
46
|
+
const s = String(jid || '');
|
|
47
|
+
const at = s.indexOf('@');
|
|
48
|
+
if (at < 0) return s;
|
|
49
|
+
return s.slice(0, at).split(':')[0] + s.slice(at);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function deriveSecretKey(opts) {
|
|
53
|
+
const type = opts.type;
|
|
54
|
+
if (!Object.values(SECRET_TYPE).includes(type)) {
|
|
55
|
+
throw new Error('message secret: unknown use case ' + JSON.stringify(type));
|
|
56
|
+
}
|
|
57
|
+
const secret = opts.messageSecret;
|
|
58
|
+
if (!secret || secret.length !== 32) {
|
|
59
|
+
throw new Error('message secret: the target message\'s 32-byte secret is required');
|
|
60
|
+
}
|
|
61
|
+
const targetId = String(opts.targetId || '');
|
|
62
|
+
if (!targetId) throw new Error('message secret: the target message id is required');
|
|
63
|
+
const targetSender = nonAd(opts.targetSender);
|
|
64
|
+
const sender = nonAd(opts.sender);
|
|
65
|
+
if (!targetSender || targetSender.startsWith('@')) {
|
|
66
|
+
throw new Error('message secret: who sent the target message is required');
|
|
67
|
+
}
|
|
68
|
+
if (!sender || sender.startsWith('@')) {
|
|
69
|
+
throw new Error('message secret: who sent the add-on is required');
|
|
70
|
+
}
|
|
71
|
+
const info = Buffer.from(targetId + targetSender + sender + type, 'utf8');
|
|
72
|
+
const key = hkdfSha256(Buffer.from(secret), Buffer.alloc(0), info, 32);
|
|
73
|
+
const aad = WITH_AAD.has(type)
|
|
74
|
+
? Buffer.concat([Buffer.from(targetId, 'utf8'), Buffer.from([0]), Buffer.from(sender, 'utf8')])
|
|
75
|
+
: null;
|
|
76
|
+
return { key, aad };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Open an add-on. `encPayload` ends with the 16-byte GCM tag. */
|
|
80
|
+
function decryptSecret(opts) {
|
|
81
|
+
const { key, aad } = deriveSecretKey(opts);
|
|
82
|
+
const payload = Buffer.from(opts.encPayload || []);
|
|
83
|
+
const iv = Buffer.from(opts.encIv || []);
|
|
84
|
+
if (payload.length < 16 || iv.length !== 12) {
|
|
85
|
+
throw new Error('message secret: the add-on carries no usable ciphertext');
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const dec = crypto.createDecipheriv('aes-256-gcm', key, iv);
|
|
89
|
+
if (aad) dec.setAAD(aad);
|
|
90
|
+
dec.setAuthTag(payload.subarray(payload.length - 16));
|
|
91
|
+
return Buffer.concat([dec.update(payload.subarray(0, payload.length - 16)), dec.final()]);
|
|
92
|
+
} catch (_) {
|
|
93
|
+
throw new Error('message secret: the add-on would not open — wrong secret, ' +
|
|
94
|
+
'or the wrong sender for this target');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Seal an add-on. Returns `{ encPayload, encIv }`. */
|
|
99
|
+
function encryptSecret(opts) {
|
|
100
|
+
const { key, aad } = deriveSecretKey(opts);
|
|
101
|
+
const iv = opts.iv || crypto.randomBytes(12);
|
|
102
|
+
const enc = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
103
|
+
if (aad) enc.setAAD(aad);
|
|
104
|
+
const encPayload = Buffer.concat([enc.update(Buffer.from(opts.plaintext)), enc.final(), enc.getAuthTag()]);
|
|
105
|
+
return { encPayload, encIv: iv };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A poll's options are named in a ballot by the SHA-256 of their text. */
|
|
109
|
+
function hashPollOptions(names) {
|
|
110
|
+
return (names || []).map(n => crypto.createHash('sha256').update(String(n), 'utf8').digest());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = {
|
|
114
|
+
SECRET_TYPE, SECRET_ENC_TYPE, nonAd,
|
|
115
|
+
deriveSecretKey, decryptSecret, encryptSecret, hashPollOptions
|
|
116
|
+
};
|
|
@@ -150,6 +150,8 @@ function resolveDecryptFail(mediaType, options) {
|
|
|
150
150
|
// client keys off the presence of the attribute rather than its value, and so
|
|
151
151
|
// does this.
|
|
152
152
|
if (options && options.edit) return 'hide';
|
|
153
|
+
// A vote on a poll, or anything the caller says has nothing to show.
|
|
154
|
+
if (options && (options._pollType === 'vote' || options._hide)) return 'hide';
|
|
153
155
|
return null;
|
|
154
156
|
}
|
|
155
157
|
|
|
@@ -465,6 +467,34 @@ class MessageSender {
|
|
|
465
467
|
return this._sendMessage(toJid, msgId, rxBuf, 'reaction', options);
|
|
466
468
|
}
|
|
467
469
|
|
|
470
|
+
// ─── Raw ──────────────────────────────────────────────────────────────────
|
|
471
|
+
//
|
|
472
|
+
// A Message the caller encoded. Everything after the content is the same as
|
|
473
|
+
// for a built-in send; the options only fill in what the stanza says about
|
|
474
|
+
// the message in the clear.
|
|
475
|
+
|
|
476
|
+
async sendRaw(to, message, options) {
|
|
477
|
+
options = options || {};
|
|
478
|
+
if (!Buffer.isBuffer(message) || !message.length) {
|
|
479
|
+
throw new Error('sendRawMessage: message must be a non-empty Buffer holding an encoded Message');
|
|
480
|
+
}
|
|
481
|
+
const type = options.type || 'text';
|
|
482
|
+
if (!['text', 'media', 'poll', 'reaction'].includes(type)) {
|
|
483
|
+
throw new Error('sendRawMessage: type must be text, media, poll or reaction');
|
|
484
|
+
}
|
|
485
|
+
if (type === 'media' && !options.mediaType) {
|
|
486
|
+
throw new Error('sendRawMessage: a media message needs opts.mediaType (image, video, audio, …)');
|
|
487
|
+
}
|
|
488
|
+
const msgId = options.id || generateMessageId();
|
|
489
|
+
const toJid = makeJid(to);
|
|
490
|
+
const send = Object.assign({}, options);
|
|
491
|
+
delete send.type; delete send.mediaType; delete send.pollType; delete send.hide;
|
|
492
|
+
if (type === 'media') send._mediaSubtype = options.mediaType;
|
|
493
|
+
if (type === 'poll') send._pollType = options.pollType === 'vote' ? 'vote' : 'creation';
|
|
494
|
+
if (options.hide) send._hide = true;
|
|
495
|
+
return this._sendMessage(toJid, msgId, message, type, send);
|
|
496
|
+
}
|
|
497
|
+
|
|
468
498
|
// ─── Poll ─────────────────────────────────────────────────────────────────
|
|
469
499
|
//
|
|
470
500
|
// Sends a PollCreationMessage (WhatsApp field 85). Recipients can vote
|
|
@@ -1198,6 +1228,10 @@ class MessageSender {
|
|
|
1198
1228
|
if (extra) msgContent.push(extra);
|
|
1199
1229
|
}
|
|
1200
1230
|
|
|
1231
|
+
// A poll says in the clear whether it is the poll or a vote on one.
|
|
1232
|
+
if (mediaType === 'poll') {
|
|
1233
|
+
msgContent.push(new BinaryNode('meta', { polltype: options._pollType || 'creation' }, null));
|
|
1234
|
+
}
|
|
1201
1235
|
const msgNode = new BinaryNode('message', stanzaAttrs, msgContent);
|
|
1202
1236
|
|
|
1203
1237
|
// Debug: log outgoing stanza details
|
|
@@ -1577,6 +1611,10 @@ class MessageSender {
|
|
|
1577
1611
|
retryDepth: options._retryDepth || 0
|
|
1578
1612
|
});
|
|
1579
1613
|
|
|
1614
|
+
// A poll says in the clear whether it is the poll or a vote on one.
|
|
1615
|
+
if (mediaType === 'poll') {
|
|
1616
|
+
msgContent.push(new BinaryNode('meta', { polltype: options._pollType || 'creation' }, null));
|
|
1617
|
+
}
|
|
1580
1618
|
const msgNode = new BinaryNode('message', stanzaAttrs, msgContent);
|
|
1581
1619
|
const dispatchResult = await this._dispatchAndAck(msgNode, msgId, false, capture);
|
|
1582
1620
|
|
package/lib/noise.js
CHANGED
|
@@ -831,6 +831,12 @@ class NoiseSocket extends EventEmitter {
|
|
|
831
831
|
const err = new Error('WhatsApp auth failure ' + reason +
|
|
832
832
|
(detail ? ' — ' + detail : ''));
|
|
833
833
|
err.code = reason;
|
|
834
|
+
// A temporary ban says which kind and for how long.
|
|
835
|
+
if (reason === '402') {
|
|
836
|
+
err.banCode = attrs.code != null ? String(attrs.code) : null;
|
|
837
|
+
err.banExpireSecs = attrs.expire != null && Number.isFinite(Number(attrs.expire))
|
|
838
|
+
? Number(attrs.expire) : null;
|
|
839
|
+
}
|
|
834
840
|
// True when the session is spent and the caller should register or
|
|
835
841
|
// link again rather than retry.
|
|
836
842
|
err.loggedOut = !!(info && info.wipe);
|
|
@@ -319,11 +319,59 @@ function encodeReactionMessage(opts) {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
function encodeMessageKey(key) {
|
|
322
|
-
|
|
322
|
+
const parts = [
|
|
323
323
|
field(1, WIRE_LEN, str(key.remoteJid)),
|
|
324
324
|
field(2, WIRE_VARINT, bool(key.fromMe || false)),
|
|
325
325
|
field(3, WIRE_LEN, str(key.id))
|
|
326
|
-
]
|
|
326
|
+
];
|
|
327
|
+
// Who sent it, when the key names somebody else's message in a group.
|
|
328
|
+
if (key.participant) parts.push(field(4, WIRE_LEN, str(key.participant)));
|
|
329
|
+
return Buffer.concat(parts);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Message.pollUpdateMessage (50):
|
|
333
|
+
// { pollCreationMessageKey = 1, vote = 2 { encPayload = 1, encIV = 2 },
|
|
334
|
+
// senderTimestampMS = 4 }
|
|
335
|
+
function encodePollUpdateMessage(opts) {
|
|
336
|
+
return field(50, WIRE_LEN, Buffer.concat([
|
|
337
|
+
field(1, WIRE_LEN, encodeMessageKey(opts.key)),
|
|
338
|
+
field(2, WIRE_LEN, Buffer.concat([
|
|
339
|
+
field(1, WIRE_LEN, bytes(opts.encPayload)),
|
|
340
|
+
field(2, WIRE_LEN, bytes(opts.encIv))
|
|
341
|
+
])),
|
|
342
|
+
field(4, WIRE_VARINT, varintS(opts.senderTimestampMs || Date.now()))
|
|
343
|
+
]));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// PollVoteMessage { repeated bytes selectedOptions = 1 }
|
|
347
|
+
function encodePollVoteMessage(hashes) {
|
|
348
|
+
return Buffer.concat((hashes || []).map(h => field(1, WIRE_LEN, bytes(h))));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Message.pinInChatMessage (63) { key = 1, type = 2, senderTimestampMS = 3 },
|
|
352
|
+
// beside a messageContextInfo (35) that says how long the pin lasts.
|
|
353
|
+
function encodePinInChatMessage(opts) {
|
|
354
|
+
const pin = field(63, WIRE_LEN, Buffer.concat([
|
|
355
|
+
field(1, WIRE_LEN, encodeMessageKey(opts.key)),
|
|
356
|
+
field(2, WIRE_VARINT, varintS(opts.pin === false ? 2 : 1)),
|
|
357
|
+
field(3, WIRE_VARINT, varintS(opts.senderTimestampMs || Date.now()))
|
|
358
|
+
]));
|
|
359
|
+
if (opts.pin === false || !opts.durationSecs) return pin;
|
|
360
|
+
return Buffer.concat([pin,
|
|
361
|
+
field(35, WIRE_LEN, field(5, WIRE_VARINT, varintS(opts.durationSecs)))]);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// One of the add-ons sealed under a message secret, as a whole Message:
|
|
365
|
+
// { targetMessageKey = 1, encPayload = 2, encIV = 3 }
|
|
366
|
+
const ENC_ADDON_FIELD = { encReaction: 56, encComment: 71, encEventResponse: 76 };
|
|
367
|
+
function encodeEncAddOnMessage(type, opts) {
|
|
368
|
+
const num = ENC_ADDON_FIELD[type];
|
|
369
|
+
if (!num) throw new Error('unknown encrypted add-on ' + type);
|
|
370
|
+
return field(num, WIRE_LEN, Buffer.concat([
|
|
371
|
+
field(1, WIRE_LEN, encodeMessageKey(opts.key)),
|
|
372
|
+
field(2, WIRE_LEN, bytes(opts.encPayload)),
|
|
373
|
+
field(3, WIRE_LEN, bytes(opts.encIv))
|
|
374
|
+
]));
|
|
327
375
|
}
|
|
328
376
|
|
|
329
377
|
function encodeMessage(type, payload) {
|
|
@@ -1149,6 +1197,8 @@ function decodeMessageContainer(buf, depth) {
|
|
|
1149
1197
|
fromMe: !!key[2],
|
|
1150
1198
|
id: _str(key[3]) || null
|
|
1151
1199
|
};
|
|
1200
|
+
// Present in a group, where it names the poll's author.
|
|
1201
|
+
if (_str(key[4])) msgResult.pollKey.participant = _str(key[4]);
|
|
1152
1202
|
}
|
|
1153
1203
|
|
|
1154
1204
|
if (Buffer.isBuffer(upd[2])) {
|
|
@@ -1159,7 +1209,60 @@ function decodeMessageContainer(buf, depth) {
|
|
|
1159
1209
|
}
|
|
1160
1210
|
}
|
|
1161
1211
|
|
|
1162
|
-
|
|
1212
|
+
// senderTimestampMS is field 4; field 3 is the vote's metadata.
|
|
1213
|
+
if (typeof upd[4] === 'number') msgResult.senderTimestampMs = upd[4];
|
|
1214
|
+
} catch (_) { /* the bare type is still worth reporting */ }
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// Add-ons sealed under another message's secret. Each is
|
|
1218
|
+
// { targetMessageKey = 1, encPayload = 2, encIV = 3 }
|
|
1219
|
+
// and names its target; what it says is read with the client's decrypt*
|
|
1220
|
+
// calls, which need that target's secret.
|
|
1221
|
+
// 56 encReactionMessage · 71 encCommentMessage
|
|
1222
|
+
// 76 encEventResponseMessage · 82 secretEncryptedMessage (+ type = 4)
|
|
1223
|
+
for (const [num, type] of [[56, 'encReaction'], [71, 'encComment'],
|
|
1224
|
+
[76, 'encEventResponse'], [82, 'secretEncrypted']]) {
|
|
1225
|
+
if (msgResult || !f[num] || !Buffer.isBuffer(f[num])) continue;
|
|
1226
|
+
msgResult = { type };
|
|
1227
|
+
try {
|
|
1228
|
+
const enc = _decodeFields(f[num]);
|
|
1229
|
+
if (Buffer.isBuffer(enc[1])) {
|
|
1230
|
+
const key = _decodeFields(enc[1]);
|
|
1231
|
+
msgResult.targetKey = {
|
|
1232
|
+
remoteJid: _str(key[1]) || null,
|
|
1233
|
+
fromMe: !!key[2],
|
|
1234
|
+
id: _str(key[3]) || null,
|
|
1235
|
+
participant: _str(key[4]) || null
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
if (Buffer.isBuffer(enc[2]) && Buffer.isBuffer(enc[3])) {
|
|
1239
|
+
msgResult.encPayload = enc[2];
|
|
1240
|
+
msgResult.encIv = enc[3];
|
|
1241
|
+
}
|
|
1242
|
+
if (num === 82 && typeof enc[4] === 'number') msgResult.secretEncType = enc[4];
|
|
1243
|
+
} catch (_) { /* the bare type is still worth reporting */ }
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// 63 pinInChatMessage { key = 1, type = 2 (1 pin, 2 unpin), senderTimestampMS = 3 }
|
|
1247
|
+
// 51 keepInChatMessage { key = 1, keepType = 2 (1 keep, 2 undo), timestampMS = 3 }
|
|
1248
|
+
for (const [num, type] of [[63, 'pinInChat'], [51, 'keepInChat']]) {
|
|
1249
|
+
if (msgResult || !f[num] || !Buffer.isBuffer(f[num])) continue;
|
|
1250
|
+
msgResult = { type };
|
|
1251
|
+
try {
|
|
1252
|
+
const m = _decodeFields(f[num]);
|
|
1253
|
+
if (Buffer.isBuffer(m[1])) {
|
|
1254
|
+
const key = _decodeFields(m[1]);
|
|
1255
|
+
msgResult.targetKey = {
|
|
1256
|
+
remoteJid: _str(key[1]) || null,
|
|
1257
|
+
fromMe: !!key[2],
|
|
1258
|
+
id: _str(key[3]) || null,
|
|
1259
|
+
participant: _str(key[4]) || null
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
const action = typeof m[2] === 'number' ? m[2] : 0;
|
|
1263
|
+
if (num === 63) msgResult.pinned = action === 1;
|
|
1264
|
+
else msgResult.kept = action === 1;
|
|
1265
|
+
if (typeof m[3] === 'number') msgResult.senderTimestampMs = m[3];
|
|
1163
1266
|
} catch (_) { /* the bare type is still worth reporting */ }
|
|
1164
1267
|
}
|
|
1165
1268
|
|
|
@@ -1228,6 +1331,10 @@ module.exports = {
|
|
|
1228
1331
|
encodeDocumentMessage,
|
|
1229
1332
|
encodeStickerMessage,
|
|
1230
1333
|
encodeReactionMessage,
|
|
1334
|
+
encodePollUpdateMessage,
|
|
1335
|
+
encodePollVoteMessage,
|
|
1336
|
+
encodePinInChatMessage,
|
|
1337
|
+
encodeEncAddOnMessage,
|
|
1231
1338
|
encodePollCreationMessage,
|
|
1232
1339
|
encodeLocationMessage,
|
|
1233
1340
|
encodeContactMessage,
|
package/llms.txt
CHANGED
|
@@ -133,7 +133,8 @@ main().catch((err) => { console.error(err.message || err); process.exit(1); });
|
|
|
133
133
|
- [Sending Messages](https://github.com/Kunboruto20/whalibmob#sending-messages): text, replies, reactions, edits, deletes, polls, location, contacts
|
|
134
134
|
- [Media Messages](https://github.com/Kunboruto20/whalibmob#media-messages): images, video, audio, voice notes, documents, stickers
|
|
135
135
|
- [Receiving Media](https://github.com/Kunboruto20/whalibmob#receiving-media): downloading and decrypting what arrives
|
|
136
|
-
- [Handling Events](https://github.com/Kunboruto20/whalibmob#handling-events): the full event list
|
|
136
|
+
- [Handling Events](https://github.com/Kunboruto20/whalibmob#handling-events): the full event list, keepalive and offline-sync events included
|
|
137
|
+
- [Encrypted add-ons](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#encrypted-reactions-comments-event-responses-and-edits): poll votes, encrypted reactions, comments, event responses and edits; `sendRawMessage` for any encoded Message
|
|
137
138
|
- [History Sync](https://github.com/Kunboruto20/whalibmob#history-sync): the backlog the server sends on first connect, and reading it back
|
|
138
139
|
- [Status / Stories](https://github.com/Kunboruto20/whalibmob#status--stories): posting to status
|
|
139
140
|
- [Send States in Chat](https://github.com/Kunboruto20/whalibmob#send-states-in-chat): typing, recording, online presence
|
|
@@ -142,7 +143,7 @@ main().catch((err) => { console.error(err.message || err); process.exit(1); });
|
|
|
142
143
|
|
|
143
144
|
- [Groups](https://github.com/Kunboruto20/whalibmob#groups): create, join, invite, promote, manage settings
|
|
144
145
|
- [Communities](https://github.com/Kunboruto20/whalibmob#communities): create and link groups
|
|
145
|
-
- [Newsletters (Channels)](https://github.com/Kunboruto20/whalibmob#newsletters-channels): create, join, follow
|
|
146
|
+
- [Newsletters (Channels)](https://github.com/Kunboruto20/whalibmob#newsletters-channels): create, join, follow, read posts, react, live updates
|
|
146
147
|
|
|
147
148
|
## Sessions, transport and account
|
|
148
149
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whalibmob",
|
|
3
|
-
"version": "5.40.
|
|
3
|
+
"version": "5.40.37",
|
|
4
4
|
"description": "Node.js library for WhatsApp — register a number over SMS, or link as a companion by QR. Signal E2E encryption, media, groups, channels.",
|
|
5
5
|
"author": "Kunboruto20",
|
|
6
6
|
"main": "index.js",
|