@rosyn/whats 0.0.0-stage → 0.1.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 +354 -2
- package/assets/banner.jpg +0 -0
- package/dist/client/index.d.ts +96 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +224 -0
- package/dist/client/index.js.map +1 -0
- package/dist/codec/index.d.ts +8 -0
- package/dist/codec/index.d.ts.map +1 -0
- package/dist/codec/index.js +157 -0
- package/dist/codec/index.js.map +1 -0
- package/dist/compat/extensions.d.ts +219 -0
- package/dist/compat/extensions.d.ts.map +1 -0
- package/dist/compat/extensions.js +717 -0
- package/dist/compat/extensions.js.map +1 -0
- package/dist/compat/index.d.ts +41 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +2500 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/errors/index.d.ts +15 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +26 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.d.ts +12 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +48 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/media/index.d.ts +22 -0
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +88 -0
- package/dist/media/index.js.map +1 -0
- package/dist/proto/index.d.ts +401 -0
- package/dist/proto/index.d.ts.map +1 -0
- package/dist/proto/index.js +1342 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/protocol/jid.d.ts +36 -0
- package/dist/protocol/jid.d.ts.map +1 -0
- package/dist/protocol/jid.js +95 -0
- package/dist/protocol/jid.js.map +1 -0
- package/dist/protocol/tokens.d.ts +3 -0
- package/dist/protocol/tokens.d.ts.map +1 -0
- package/dist/protocol/tokens.js +4 -0
- package/dist/protocol/tokens.js.map +1 -0
- package/dist/protocol/wabin.d.ts +8 -0
- package/dist/protocol/wabin.d.ts.map +1 -0
- package/dist/protocol/wabin.js +256 -0
- package/dist/protocol/wabin.js.map +1 -0
- package/dist/signal/index.d.ts +22 -0
- package/dist/signal/index.d.ts.map +1 -0
- package/dist/signal/index.js +62 -0
- package/dist/signal/index.js.map +1 -0
- package/dist/signal/protocol.d.ts +139 -0
- package/dist/signal/protocol.d.ts.map +1 -0
- package/dist/signal/protocol.js +620 -0
- package/dist/signal/protocol.js.map +1 -0
- package/dist/storage/index.d.ts +59 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +65 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/transport/websocket.d.ts +32 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +153 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types/index.d.ts +111 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/native/rosyn_whats_engine.node +0 -0
- package/package.json +54 -4
|
@@ -0,0 +1,1342 @@
|
|
|
1
|
+
// Minimal independent Protobuf wire encoder/decoder for WhatsApp HandshakeMessage, ClientPayload, and Message
|
|
2
|
+
function writeVarint(out, value) {
|
|
3
|
+
let v = value >>> 0;
|
|
4
|
+
while (v >= 0x80) {
|
|
5
|
+
out.push((v & 0x7f) | 0x80);
|
|
6
|
+
v >>>= 7;
|
|
7
|
+
}
|
|
8
|
+
out.push(v);
|
|
9
|
+
}
|
|
10
|
+
function writeBytesField(out, fieldNumber, bytes) {
|
|
11
|
+
writeVarint(out, (fieldNumber << 3) | 2);
|
|
12
|
+
writeVarint(out, bytes.length);
|
|
13
|
+
for (let i = 0; i < bytes.length; i++)
|
|
14
|
+
out.push(bytes[i]);
|
|
15
|
+
}
|
|
16
|
+
function writeVarintField64(out, fieldNumber, value) {
|
|
17
|
+
writeVarint(out, (fieldNumber << 3) | 0);
|
|
18
|
+
let v = typeof value === "bigint" ? value : BigInt(Math.trunc(value));
|
|
19
|
+
while (v >= 0x80n) {
|
|
20
|
+
out.push(Number(v & 0x7fn) | 0x80);
|
|
21
|
+
v >>= 7n;
|
|
22
|
+
}
|
|
23
|
+
out.push(Number(v));
|
|
24
|
+
}
|
|
25
|
+
function writeVarintField(out, fieldNumber, value) {
|
|
26
|
+
writeVarint(out, (fieldNumber << 3) | 0);
|
|
27
|
+
writeVarint(out, value);
|
|
28
|
+
}
|
|
29
|
+
function writeDoubleField(out, fieldNumber, value) {
|
|
30
|
+
writeVarint(out, (fieldNumber << 3) | 1);
|
|
31
|
+
const buf = Buffer.allocUnsafe(8);
|
|
32
|
+
buf.writeDoubleLE(value, 0);
|
|
33
|
+
for (let i = 0; i < 8; i++)
|
|
34
|
+
out.push(buf[i]);
|
|
35
|
+
}
|
|
36
|
+
function readVarint(buf, state) {
|
|
37
|
+
let result = 0;
|
|
38
|
+
let shift = 0;
|
|
39
|
+
while (state.pos < buf.length) {
|
|
40
|
+
const b = buf[state.pos++];
|
|
41
|
+
result |= (b & 0x7f) << shift;
|
|
42
|
+
if ((b & 0x80) === 0)
|
|
43
|
+
return result >>> 0;
|
|
44
|
+
shift += 7;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("Truncated varint in protobuf");
|
|
47
|
+
}
|
|
48
|
+
function encodeSubHello(obj) {
|
|
49
|
+
const out = [];
|
|
50
|
+
if (obj.ephemeral)
|
|
51
|
+
writeBytesField(out, 1, obj.ephemeral);
|
|
52
|
+
if (obj.static)
|
|
53
|
+
writeBytesField(out, 2, obj.static);
|
|
54
|
+
if (obj.payload)
|
|
55
|
+
writeBytesField(out, 3, obj.payload);
|
|
56
|
+
return Uint8Array.from(out);
|
|
57
|
+
}
|
|
58
|
+
function encodeClientFinish(obj) {
|
|
59
|
+
const out = [];
|
|
60
|
+
if (obj.static)
|
|
61
|
+
writeBytesField(out, 1, obj.static);
|
|
62
|
+
if (obj.payload)
|
|
63
|
+
writeBytesField(out, 2, obj.payload);
|
|
64
|
+
return Uint8Array.from(out);
|
|
65
|
+
}
|
|
66
|
+
function decodeSubHello(buf) {
|
|
67
|
+
const state = { pos: 0 };
|
|
68
|
+
const res = {};
|
|
69
|
+
while (state.pos < buf.length) {
|
|
70
|
+
const tag = readVarint(buf, state);
|
|
71
|
+
const fn = tag >>> 3;
|
|
72
|
+
const wt = tag & 7;
|
|
73
|
+
if (wt === 2) {
|
|
74
|
+
const len = readVarint(buf, state);
|
|
75
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
76
|
+
state.pos += len;
|
|
77
|
+
if (fn === 1)
|
|
78
|
+
res.ephemeral = slice;
|
|
79
|
+
else if (fn === 2)
|
|
80
|
+
res.static = slice;
|
|
81
|
+
else if (fn === 3)
|
|
82
|
+
res.payload = slice;
|
|
83
|
+
}
|
|
84
|
+
else if (wt === 0) {
|
|
85
|
+
readVarint(buf, state);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return res;
|
|
92
|
+
}
|
|
93
|
+
function encodeMessageKey(k) {
|
|
94
|
+
const out = [];
|
|
95
|
+
if (k.remoteJid !== undefined)
|
|
96
|
+
writeBytesField(out, 1, Buffer.from(k.remoteJid, "utf8"));
|
|
97
|
+
if (k.fromMe !== undefined)
|
|
98
|
+
writeVarintField(out, 2, k.fromMe ? 1 : 0);
|
|
99
|
+
if (k.id !== undefined)
|
|
100
|
+
writeBytesField(out, 3, Buffer.from(k.id, "utf8"));
|
|
101
|
+
if (k.participant !== undefined)
|
|
102
|
+
writeBytesField(out, 4, Buffer.from(k.participant, "utf8"));
|
|
103
|
+
return Uint8Array.from(out);
|
|
104
|
+
}
|
|
105
|
+
function encodeContactMessageData(c) {
|
|
106
|
+
const out = [];
|
|
107
|
+
if (c.displayName !== undefined)
|
|
108
|
+
writeBytesField(out, 1, Buffer.from(c.displayName, "utf8"));
|
|
109
|
+
if (c.vcard !== undefined)
|
|
110
|
+
writeBytesField(out, 16, Buffer.from(c.vcard, "utf8"));
|
|
111
|
+
if (c.contextInfo)
|
|
112
|
+
writeBytesField(out, 17, encodeContextInfo(c.contextInfo));
|
|
113
|
+
return Uint8Array.from(out);
|
|
114
|
+
}
|
|
115
|
+
function encodePollCreationMessageData(p) {
|
|
116
|
+
const out = [];
|
|
117
|
+
if (p.name !== undefined)
|
|
118
|
+
writeBytesField(out, 2, Buffer.from(p.name, "utf8"));
|
|
119
|
+
for (const opt of p.options ?? []) {
|
|
120
|
+
const o = [];
|
|
121
|
+
if (opt.optionName !== undefined)
|
|
122
|
+
writeBytesField(o, 1, Buffer.from(opt.optionName, "utf8"));
|
|
123
|
+
writeBytesField(out, 3, Uint8Array.from(o));
|
|
124
|
+
}
|
|
125
|
+
if (p.selectableOptionsCount !== undefined)
|
|
126
|
+
writeVarintField(out, 4, p.selectableOptionsCount);
|
|
127
|
+
if (p.contextInfo)
|
|
128
|
+
writeBytesField(out, 5, encodeContextInfo(p.contextInfo));
|
|
129
|
+
return Uint8Array.from(out);
|
|
130
|
+
}
|
|
131
|
+
function encodeContextInfo(c) {
|
|
132
|
+
const out = [];
|
|
133
|
+
if (c.stanzaId !== undefined)
|
|
134
|
+
writeBytesField(out, 1, Buffer.from(c.stanzaId, "utf8"));
|
|
135
|
+
if (c.participant !== undefined)
|
|
136
|
+
writeBytesField(out, 2, Buffer.from(c.participant, "utf8"));
|
|
137
|
+
if (c.quotedMessage)
|
|
138
|
+
writeBytesField(out, 3, encodeWAMessageData(c.quotedMessage));
|
|
139
|
+
if (c.remoteJid !== undefined)
|
|
140
|
+
writeBytesField(out, 4, Buffer.from(c.remoteJid, "utf8"));
|
|
141
|
+
if (Array.isArray(c.mentionedJid)) {
|
|
142
|
+
for (const j of c.mentionedJid) {
|
|
143
|
+
writeBytesField(out, 15, Buffer.from(j, "utf8"));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (c.forwardingScore !== undefined)
|
|
147
|
+
writeVarintField(out, 21, c.forwardingScore);
|
|
148
|
+
if (c.isForwarded !== undefined)
|
|
149
|
+
writeVarintField(out, 22, c.isForwarded ? 1 : 0);
|
|
150
|
+
if (c.expiration !== undefined)
|
|
151
|
+
writeVarintField(out, 25, c.expiration);
|
|
152
|
+
if (c.isGroupStatus !== undefined)
|
|
153
|
+
writeVarintField(out, 66, c.isGroupStatus ? 1 : 0);
|
|
154
|
+
return Uint8Array.from(out);
|
|
155
|
+
}
|
|
156
|
+
function encodeImageMessageData(m) {
|
|
157
|
+
const out = [];
|
|
158
|
+
if (m.url !== undefined)
|
|
159
|
+
writeBytesField(out, 1, Buffer.from(m.url, "utf8"));
|
|
160
|
+
if (m.mimetype !== undefined)
|
|
161
|
+
writeBytesField(out, 2, Buffer.from(m.mimetype, "utf8"));
|
|
162
|
+
if (m.caption !== undefined)
|
|
163
|
+
writeBytesField(out, 3, Buffer.from(m.caption, "utf8"));
|
|
164
|
+
if (m.fileSha256)
|
|
165
|
+
writeBytesField(out, 4, m.fileSha256);
|
|
166
|
+
if (m.fileLength !== undefined)
|
|
167
|
+
writeVarintField64(out, 5, m.fileLength);
|
|
168
|
+
if (m.mediaKey)
|
|
169
|
+
writeBytesField(out, 8, m.mediaKey);
|
|
170
|
+
if (m.fileEncSha256)
|
|
171
|
+
writeBytesField(out, 9, m.fileEncSha256);
|
|
172
|
+
if (m.directPath !== undefined)
|
|
173
|
+
writeBytesField(out, 11, Buffer.from(m.directPath, "utf8"));
|
|
174
|
+
if (m.mediaKeyTimestamp !== undefined)
|
|
175
|
+
writeVarintField64(out, 12, m.mediaKeyTimestamp);
|
|
176
|
+
if (m.contextInfo)
|
|
177
|
+
writeBytesField(out, 17, encodeContextInfo(m.contextInfo));
|
|
178
|
+
return Uint8Array.from(out);
|
|
179
|
+
}
|
|
180
|
+
function encodeVideoMessageData(m) {
|
|
181
|
+
const out = [];
|
|
182
|
+
if (m.url !== undefined)
|
|
183
|
+
writeBytesField(out, 1, Buffer.from(m.url, "utf8"));
|
|
184
|
+
if (m.mimetype !== undefined)
|
|
185
|
+
writeBytesField(out, 2, Buffer.from(m.mimetype, "utf8"));
|
|
186
|
+
if (m.fileSha256)
|
|
187
|
+
writeBytesField(out, 3, m.fileSha256);
|
|
188
|
+
if (m.fileLength !== undefined)
|
|
189
|
+
writeVarintField64(out, 4, m.fileLength);
|
|
190
|
+
if (m.mediaKey)
|
|
191
|
+
writeBytesField(out, 6, m.mediaKey);
|
|
192
|
+
if (m.caption !== undefined)
|
|
193
|
+
writeBytesField(out, 7, Buffer.from(m.caption, "utf8"));
|
|
194
|
+
if (m.gifPlayback !== undefined)
|
|
195
|
+
writeVarintField(out, 8, m.gifPlayback ? 1 : 0);
|
|
196
|
+
if (m.fileEncSha256)
|
|
197
|
+
writeBytesField(out, 11, m.fileEncSha256);
|
|
198
|
+
if (m.directPath !== undefined)
|
|
199
|
+
writeBytesField(out, 13, Buffer.from(m.directPath, "utf8"));
|
|
200
|
+
if (m.mediaKeyTimestamp !== undefined)
|
|
201
|
+
writeVarintField64(out, 14, m.mediaKeyTimestamp);
|
|
202
|
+
if (m.contextInfo)
|
|
203
|
+
writeBytesField(out, 17, encodeContextInfo(m.contextInfo));
|
|
204
|
+
return Uint8Array.from(out);
|
|
205
|
+
}
|
|
206
|
+
function encodeAudioMessageData(m) {
|
|
207
|
+
const out = [];
|
|
208
|
+
if (m.url !== undefined)
|
|
209
|
+
writeBytesField(out, 1, Buffer.from(m.url, "utf8"));
|
|
210
|
+
if (m.mimetype !== undefined)
|
|
211
|
+
writeBytesField(out, 2, Buffer.from(m.mimetype, "utf8"));
|
|
212
|
+
if (m.fileSha256)
|
|
213
|
+
writeBytesField(out, 3, m.fileSha256);
|
|
214
|
+
if (m.fileLength !== undefined)
|
|
215
|
+
writeVarintField64(out, 4, m.fileLength);
|
|
216
|
+
if (m.seconds !== undefined)
|
|
217
|
+
writeVarintField(out, 5, m.seconds);
|
|
218
|
+
if (m.ptt !== undefined)
|
|
219
|
+
writeVarintField(out, 6, m.ptt ? 1 : 0);
|
|
220
|
+
if (m.mediaKey)
|
|
221
|
+
writeBytesField(out, 7, m.mediaKey);
|
|
222
|
+
if (m.fileEncSha256)
|
|
223
|
+
writeBytesField(out, 8, m.fileEncSha256);
|
|
224
|
+
if (m.directPath !== undefined)
|
|
225
|
+
writeBytesField(out, 9, Buffer.from(m.directPath, "utf8"));
|
|
226
|
+
if (m.mediaKeyTimestamp !== undefined)
|
|
227
|
+
writeVarintField64(out, 10, m.mediaKeyTimestamp);
|
|
228
|
+
if (m.contextInfo)
|
|
229
|
+
writeBytesField(out, 17, encodeContextInfo(m.contextInfo));
|
|
230
|
+
if (m.waveform)
|
|
231
|
+
writeBytesField(out, 19, m.waveform);
|
|
232
|
+
return Uint8Array.from(out);
|
|
233
|
+
}
|
|
234
|
+
function encodeDocumentMessageData(m) {
|
|
235
|
+
const out = [];
|
|
236
|
+
if (m.url !== undefined)
|
|
237
|
+
writeBytesField(out, 1, Buffer.from(m.url, "utf8"));
|
|
238
|
+
if (m.mimetype !== undefined)
|
|
239
|
+
writeBytesField(out, 2, Buffer.from(m.mimetype, "utf8"));
|
|
240
|
+
if (m.title !== undefined)
|
|
241
|
+
writeBytesField(out, 3, Buffer.from(m.title, "utf8"));
|
|
242
|
+
if (m.fileSha256)
|
|
243
|
+
writeBytesField(out, 4, m.fileSha256);
|
|
244
|
+
if (m.fileLength !== undefined)
|
|
245
|
+
writeVarintField64(out, 5, m.fileLength);
|
|
246
|
+
if (m.mediaKey)
|
|
247
|
+
writeBytesField(out, 7, m.mediaKey);
|
|
248
|
+
if (m.fileName !== undefined)
|
|
249
|
+
writeBytesField(out, 8, Buffer.from(m.fileName, "utf8"));
|
|
250
|
+
if (m.fileEncSha256)
|
|
251
|
+
writeBytesField(out, 9, m.fileEncSha256);
|
|
252
|
+
if (m.directPath !== undefined)
|
|
253
|
+
writeBytesField(out, 10, Buffer.from(m.directPath, "utf8"));
|
|
254
|
+
if (m.mediaKeyTimestamp !== undefined)
|
|
255
|
+
writeVarintField64(out, 11, m.mediaKeyTimestamp);
|
|
256
|
+
if (m.contextInfo)
|
|
257
|
+
writeBytesField(out, 17, encodeContextInfo(m.contextInfo));
|
|
258
|
+
if (m.caption !== undefined)
|
|
259
|
+
writeBytesField(out, 20, Buffer.from(m.caption, "utf8"));
|
|
260
|
+
return Uint8Array.from(out);
|
|
261
|
+
}
|
|
262
|
+
function encodeStickerMessageData(m) {
|
|
263
|
+
const out = [];
|
|
264
|
+
if (m.url !== undefined)
|
|
265
|
+
writeBytesField(out, 1, Buffer.from(m.url, "utf8"));
|
|
266
|
+
if (m.fileSha256)
|
|
267
|
+
writeBytesField(out, 2, m.fileSha256);
|
|
268
|
+
if (m.fileEncSha256)
|
|
269
|
+
writeBytesField(out, 3, m.fileEncSha256);
|
|
270
|
+
if (m.mediaKey)
|
|
271
|
+
writeBytesField(out, 4, m.mediaKey);
|
|
272
|
+
if (m.mimetype !== undefined)
|
|
273
|
+
writeBytesField(out, 5, Buffer.from(m.mimetype, "utf8"));
|
|
274
|
+
if (m.directPath !== undefined)
|
|
275
|
+
writeBytesField(out, 8, Buffer.from(m.directPath, "utf8"));
|
|
276
|
+
if (m.fileLength !== undefined)
|
|
277
|
+
writeVarintField64(out, 9, m.fileLength);
|
|
278
|
+
if (m.mediaKeyTimestamp !== undefined)
|
|
279
|
+
writeVarintField64(out, 10, m.mediaKeyTimestamp);
|
|
280
|
+
if (m.contextInfo)
|
|
281
|
+
writeBytesField(out, 17, encodeContextInfo(m.contextInfo));
|
|
282
|
+
return Uint8Array.from(out);
|
|
283
|
+
}
|
|
284
|
+
function encodeWAMessageData(msg) {
|
|
285
|
+
const out = [];
|
|
286
|
+
if (msg.conversation !== undefined) {
|
|
287
|
+
writeBytesField(out, 1, Buffer.from(msg.conversation, "utf8"));
|
|
288
|
+
}
|
|
289
|
+
if (msg.senderKeyDistributionMessage) {
|
|
290
|
+
const sk = [];
|
|
291
|
+
if (msg.senderKeyDistributionMessage.groupId !== undefined) {
|
|
292
|
+
writeBytesField(sk, 1, Buffer.from(msg.senderKeyDistributionMessage.groupId, "utf8"));
|
|
293
|
+
}
|
|
294
|
+
if (msg.senderKeyDistributionMessage.axolotlSenderKeyDistributionMessage) {
|
|
295
|
+
writeBytesField(sk, 2, msg.senderKeyDistributionMessage.axolotlSenderKeyDistributionMessage);
|
|
296
|
+
}
|
|
297
|
+
writeBytesField(out, 2, Uint8Array.from(sk));
|
|
298
|
+
}
|
|
299
|
+
if (msg.imageMessage)
|
|
300
|
+
writeBytesField(out, 3, encodeImageMessageData(msg.imageMessage));
|
|
301
|
+
if (msg.contactMessage)
|
|
302
|
+
writeBytesField(out, 4, encodeContactMessageData(msg.contactMessage));
|
|
303
|
+
if (msg.locationMessage) {
|
|
304
|
+
const lm = [];
|
|
305
|
+
const l = msg.locationMessage;
|
|
306
|
+
if (l.degreesLatitude !== undefined)
|
|
307
|
+
writeDoubleField(lm, 1, l.degreesLatitude);
|
|
308
|
+
if (l.degreesLongitude !== undefined)
|
|
309
|
+
writeDoubleField(lm, 2, l.degreesLongitude);
|
|
310
|
+
if (l.name !== undefined)
|
|
311
|
+
writeBytesField(lm, 3, Buffer.from(l.name, "utf8"));
|
|
312
|
+
if (l.address !== undefined)
|
|
313
|
+
writeBytesField(lm, 4, Buffer.from(l.address, "utf8"));
|
|
314
|
+
if (l.url !== undefined)
|
|
315
|
+
writeBytesField(lm, 5, Buffer.from(l.url, "utf8"));
|
|
316
|
+
if (l.jpegThumbnail)
|
|
317
|
+
writeBytesField(lm, 16, l.jpegThumbnail);
|
|
318
|
+
if (l.contextInfo)
|
|
319
|
+
writeBytesField(lm, 17, encodeContextInfo(l.contextInfo));
|
|
320
|
+
writeBytesField(out, 5, Uint8Array.from(lm));
|
|
321
|
+
}
|
|
322
|
+
if (msg.extendedTextMessage) {
|
|
323
|
+
const et = [];
|
|
324
|
+
if (msg.extendedTextMessage.text !== undefined) {
|
|
325
|
+
writeBytesField(et, 1, Buffer.from(msg.extendedTextMessage.text, "utf8"));
|
|
326
|
+
}
|
|
327
|
+
if (msg.extendedTextMessage.contextInfo) {
|
|
328
|
+
writeBytesField(et, 17, encodeContextInfo(msg.extendedTextMessage.contextInfo));
|
|
329
|
+
}
|
|
330
|
+
writeBytesField(out, 6, Uint8Array.from(et));
|
|
331
|
+
}
|
|
332
|
+
if (msg.documentMessage)
|
|
333
|
+
writeBytesField(out, 7, encodeDocumentMessageData(msg.documentMessage));
|
|
334
|
+
if (msg.audioMessage)
|
|
335
|
+
writeBytesField(out, 8, encodeAudioMessageData(msg.audioMessage));
|
|
336
|
+
if (msg.videoMessage)
|
|
337
|
+
writeBytesField(out, 9, encodeVideoMessageData(msg.videoMessage));
|
|
338
|
+
if (msg.protocolMessage) {
|
|
339
|
+
const pm = [];
|
|
340
|
+
const p = msg.protocolMessage;
|
|
341
|
+
if (p.key)
|
|
342
|
+
writeBytesField(pm, 1, encodeMessageKey(p.key));
|
|
343
|
+
if (p.type !== undefined)
|
|
344
|
+
writeVarintField(pm, 2, p.type);
|
|
345
|
+
if (p.ephemeralExpiration !== undefined)
|
|
346
|
+
writeVarintField(pm, 4, p.ephemeralExpiration);
|
|
347
|
+
if (p.editedMessage)
|
|
348
|
+
writeBytesField(pm, 14, encodeWAMessageData(p.editedMessage));
|
|
349
|
+
writeBytesField(out, 12, Uint8Array.from(pm));
|
|
350
|
+
}
|
|
351
|
+
if (msg.contactsArrayMessage) {
|
|
352
|
+
const ca = [];
|
|
353
|
+
if (msg.contactsArrayMessage.displayName !== undefined) {
|
|
354
|
+
writeBytesField(ca, 1, Buffer.from(msg.contactsArrayMessage.displayName, "utf8"));
|
|
355
|
+
}
|
|
356
|
+
for (const c of msg.contactsArrayMessage.contacts ?? []) {
|
|
357
|
+
writeBytesField(ca, 2, encodeContactMessageData(c));
|
|
358
|
+
}
|
|
359
|
+
if (msg.contactsArrayMessage.contextInfo) {
|
|
360
|
+
writeBytesField(ca, 17, encodeContextInfo(msg.contactsArrayMessage.contextInfo));
|
|
361
|
+
}
|
|
362
|
+
writeBytesField(out, 13, Uint8Array.from(ca));
|
|
363
|
+
}
|
|
364
|
+
if (msg.stickerMessage)
|
|
365
|
+
writeBytesField(out, 26, encodeStickerMessageData(msg.stickerMessage));
|
|
366
|
+
if (msg.ptvMessage)
|
|
367
|
+
writeBytesField(out, 66, encodeVideoMessageData(msg.ptvMessage));
|
|
368
|
+
if (msg.deviceSentMessage) {
|
|
369
|
+
const ds = [];
|
|
370
|
+
if (msg.deviceSentMessage.destinationJid !== undefined) {
|
|
371
|
+
writeBytesField(ds, 1, Buffer.from(msg.deviceSentMessage.destinationJid, "utf8"));
|
|
372
|
+
}
|
|
373
|
+
if (msg.deviceSentMessage.message) {
|
|
374
|
+
writeBytesField(ds, 2, encodeWAMessageData(msg.deviceSentMessage.message));
|
|
375
|
+
}
|
|
376
|
+
writeBytesField(out, 31, Uint8Array.from(ds));
|
|
377
|
+
}
|
|
378
|
+
if (msg.buttonsMessage) {
|
|
379
|
+
const bm = [];
|
|
380
|
+
const b = msg.buttonsMessage;
|
|
381
|
+
if (b.contentText !== undefined)
|
|
382
|
+
writeBytesField(bm, 6, Buffer.from(b.contentText, "utf8"));
|
|
383
|
+
if (b.footerText !== undefined)
|
|
384
|
+
writeBytesField(bm, 7, Buffer.from(b.footerText, "utf8"));
|
|
385
|
+
if (Array.isArray(b.buttons)) {
|
|
386
|
+
for (const btn of b.buttons) {
|
|
387
|
+
const bn = [];
|
|
388
|
+
if (btn.buttonId !== undefined)
|
|
389
|
+
writeBytesField(bn, 1, Buffer.from(btn.buttonId, "utf8"));
|
|
390
|
+
if (btn.buttonText?.displayText !== undefined) {
|
|
391
|
+
const bt = [];
|
|
392
|
+
writeBytesField(bt, 1, Buffer.from(btn.buttonText.displayText, "utf8"));
|
|
393
|
+
writeBytesField(bn, 2, Uint8Array.from(bt));
|
|
394
|
+
}
|
|
395
|
+
if (btn.type !== undefined)
|
|
396
|
+
writeVarintField(bn, 3, btn.type);
|
|
397
|
+
writeBytesField(bm, 9, Uint8Array.from(bn));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (b.headerType !== undefined)
|
|
401
|
+
writeVarintField(bm, 10, b.headerType);
|
|
402
|
+
writeBytesField(out, 42, Uint8Array.from(bm));
|
|
403
|
+
}
|
|
404
|
+
if (msg.interactiveMessage) {
|
|
405
|
+
writeBytesField(out, 45, encodeInteractiveMessageData(msg.interactiveMessage));
|
|
406
|
+
}
|
|
407
|
+
if (msg.reactionMessage) {
|
|
408
|
+
const rm = [];
|
|
409
|
+
const r = msg.reactionMessage;
|
|
410
|
+
if (r.key)
|
|
411
|
+
writeBytesField(rm, 1, encodeMessageKey(r.key));
|
|
412
|
+
if (r.text !== undefined)
|
|
413
|
+
writeBytesField(rm, 2, Buffer.from(r.text, "utf8"));
|
|
414
|
+
if (r.senderTimestampMs !== undefined)
|
|
415
|
+
writeVarintField64(rm, 4, r.senderTimestampMs);
|
|
416
|
+
writeBytesField(out, 46, Uint8Array.from(rm));
|
|
417
|
+
}
|
|
418
|
+
if (msg.pollCreationMessage) {
|
|
419
|
+
writeBytesField(out, 49, encodePollCreationMessageData(msg.pollCreationMessage));
|
|
420
|
+
}
|
|
421
|
+
if (msg.pollCreationMessageV3) {
|
|
422
|
+
writeBytesField(out, 64, encodePollCreationMessageData(msg.pollCreationMessageV3));
|
|
423
|
+
}
|
|
424
|
+
if (msg.stickerPackMessage) {
|
|
425
|
+
const sp = [];
|
|
426
|
+
const s = msg.stickerPackMessage;
|
|
427
|
+
if (s.stickerPackId !== undefined)
|
|
428
|
+
writeBytesField(sp, 1, Buffer.from(s.stickerPackId, "utf8"));
|
|
429
|
+
if (s.name !== undefined)
|
|
430
|
+
writeBytesField(sp, 2, Buffer.from(s.name, "utf8"));
|
|
431
|
+
if (s.publisher !== undefined)
|
|
432
|
+
writeBytesField(sp, 3, Buffer.from(s.publisher, "utf8"));
|
|
433
|
+
for (const st of s.stickers ?? []) {
|
|
434
|
+
const sn = [];
|
|
435
|
+
if (st.fileName !== undefined)
|
|
436
|
+
writeBytesField(sn, 1, Buffer.from(st.fileName, "utf8"));
|
|
437
|
+
if (st.isAnimated !== undefined)
|
|
438
|
+
writeVarintField(sn, 2, st.isAnimated ? 1 : 0);
|
|
439
|
+
for (const em of st.emojis ?? []) {
|
|
440
|
+
writeBytesField(sn, 3, Buffer.from(em, "utf8"));
|
|
441
|
+
}
|
|
442
|
+
if (st.mimetype !== undefined)
|
|
443
|
+
writeBytesField(sn, 6, Buffer.from(st.mimetype, "utf8"));
|
|
444
|
+
writeBytesField(sp, 4, Uint8Array.from(sn));
|
|
445
|
+
}
|
|
446
|
+
if (s.fileLength !== undefined)
|
|
447
|
+
writeVarintField64(sp, 5, s.fileLength);
|
|
448
|
+
if (s.fileSha256)
|
|
449
|
+
writeBytesField(sp, 6, s.fileSha256);
|
|
450
|
+
if (s.fileEncSha256)
|
|
451
|
+
writeBytesField(sp, 7, s.fileEncSha256);
|
|
452
|
+
if (s.mediaKey)
|
|
453
|
+
writeBytesField(sp, 8, s.mediaKey);
|
|
454
|
+
if (s.directPath !== undefined)
|
|
455
|
+
writeBytesField(sp, 9, Buffer.from(s.directPath, "utf8"));
|
|
456
|
+
if (s.caption !== undefined)
|
|
457
|
+
writeBytesField(sp, 10, Buffer.from(s.caption, "utf8"));
|
|
458
|
+
if (s.packDescription !== undefined)
|
|
459
|
+
writeBytesField(sp, 12, Buffer.from(s.packDescription, "utf8"));
|
|
460
|
+
if (s.mediaKeyTimestamp !== undefined)
|
|
461
|
+
writeVarintField64(sp, 13, s.mediaKeyTimestamp);
|
|
462
|
+
if (s.trayIconFileName !== undefined)
|
|
463
|
+
writeBytesField(sp, 14, Buffer.from(s.trayIconFileName, "utf8"));
|
|
464
|
+
if (s.thumbnailDirectPath !== undefined)
|
|
465
|
+
writeBytesField(sp, 15, Buffer.from(s.thumbnailDirectPath, "utf8"));
|
|
466
|
+
if (s.thumbnailSha256)
|
|
467
|
+
writeBytesField(sp, 16, s.thumbnailSha256);
|
|
468
|
+
if (s.thumbnailEncSha256)
|
|
469
|
+
writeBytesField(sp, 17, s.thumbnailEncSha256);
|
|
470
|
+
if (s.thumbnailHeight !== undefined)
|
|
471
|
+
writeVarintField(sp, 18, s.thumbnailHeight);
|
|
472
|
+
if (s.thumbnailWidth !== undefined)
|
|
473
|
+
writeVarintField(sp, 19, s.thumbnailWidth);
|
|
474
|
+
if (s.imageDataHash !== undefined)
|
|
475
|
+
writeBytesField(sp, 20, Buffer.from(s.imageDataHash, "utf8"));
|
|
476
|
+
if (s.stickerPackSize !== undefined)
|
|
477
|
+
writeVarintField64(sp, 21, s.stickerPackSize);
|
|
478
|
+
if (s.stickerPackOrigin !== undefined)
|
|
479
|
+
writeVarintField(sp, 22, s.stickerPackOrigin);
|
|
480
|
+
writeBytesField(out, 86, Uint8Array.from(sp));
|
|
481
|
+
}
|
|
482
|
+
return Uint8Array.from(out);
|
|
483
|
+
}
|
|
484
|
+
function encodeInteractiveMessageData(m) {
|
|
485
|
+
const im = [];
|
|
486
|
+
if (m.header) {
|
|
487
|
+
const h = [];
|
|
488
|
+
if (m.header.title !== undefined)
|
|
489
|
+
writeBytesField(h, 1, Buffer.from(m.header.title, "utf8"));
|
|
490
|
+
if (m.header.subtitle !== undefined)
|
|
491
|
+
writeBytesField(h, 2, Buffer.from(m.header.subtitle, "utf8"));
|
|
492
|
+
if (m.header.documentMessage)
|
|
493
|
+
writeBytesField(h, 3, encodeDocumentMessageData(m.header.documentMessage));
|
|
494
|
+
if (m.header.imageMessage)
|
|
495
|
+
writeBytesField(h, 4, encodeImageMessageData(m.header.imageMessage));
|
|
496
|
+
if (m.header.hasMediaAttachment !== undefined)
|
|
497
|
+
writeVarintField(h, 5, m.header.hasMediaAttachment ? 1 : 0);
|
|
498
|
+
if (m.header.videoMessage)
|
|
499
|
+
writeBytesField(h, 7, encodeVideoMessageData(m.header.videoMessage));
|
|
500
|
+
writeBytesField(im, 1, Uint8Array.from(h));
|
|
501
|
+
}
|
|
502
|
+
if (m.body?.text !== undefined) {
|
|
503
|
+
const b = [];
|
|
504
|
+
writeBytesField(b, 1, Buffer.from(m.body.text, "utf8"));
|
|
505
|
+
writeBytesField(im, 2, Uint8Array.from(b));
|
|
506
|
+
}
|
|
507
|
+
if (m.footer?.text !== undefined) {
|
|
508
|
+
const f = [];
|
|
509
|
+
writeBytesField(f, 1, Buffer.from(m.footer.text, "utf8"));
|
|
510
|
+
writeBytesField(im, 3, Uint8Array.from(f));
|
|
511
|
+
}
|
|
512
|
+
if (m.nativeFlowMessage) {
|
|
513
|
+
const nf = [];
|
|
514
|
+
for (const btn of m.nativeFlowMessage.buttons ?? []) {
|
|
515
|
+
const bn = [];
|
|
516
|
+
if (btn.name !== undefined)
|
|
517
|
+
writeBytesField(bn, 1, Buffer.from(btn.name, "utf8"));
|
|
518
|
+
if (btn.buttonParamsJson !== undefined)
|
|
519
|
+
writeBytesField(bn, 2, Buffer.from(btn.buttonParamsJson, "utf8"));
|
|
520
|
+
writeBytesField(nf, 1, Uint8Array.from(bn));
|
|
521
|
+
}
|
|
522
|
+
if (m.nativeFlowMessage.messageParamsJson !== undefined) {
|
|
523
|
+
writeBytesField(nf, 2, Buffer.from(m.nativeFlowMessage.messageParamsJson, "utf8"));
|
|
524
|
+
}
|
|
525
|
+
if (m.nativeFlowMessage.messageVersion !== undefined) {
|
|
526
|
+
writeVarintField(nf, 3, m.nativeFlowMessage.messageVersion);
|
|
527
|
+
}
|
|
528
|
+
writeBytesField(im, 6, Uint8Array.from(nf));
|
|
529
|
+
}
|
|
530
|
+
if (m.carouselMessage) {
|
|
531
|
+
const cm = [];
|
|
532
|
+
for (const card of m.carouselMessage.cards ?? []) {
|
|
533
|
+
writeBytesField(cm, 1, encodeInteractiveMessageData(card));
|
|
534
|
+
}
|
|
535
|
+
if (m.carouselMessage.messageVersion !== undefined) {
|
|
536
|
+
writeVarintField(cm, 2, m.carouselMessage.messageVersion);
|
|
537
|
+
}
|
|
538
|
+
writeBytesField(im, 7, Uint8Array.from(cm));
|
|
539
|
+
}
|
|
540
|
+
if (m.contextInfo)
|
|
541
|
+
writeBytesField(im, 15, encodeContextInfo(m.contextInfo));
|
|
542
|
+
return Uint8Array.from(im);
|
|
543
|
+
}
|
|
544
|
+
function readProtoFields(buf, onBytes, onVarint, onFixed64) {
|
|
545
|
+
const state = { pos: 0 };
|
|
546
|
+
while (state.pos < buf.length) {
|
|
547
|
+
const tag = readVarint(buf, state);
|
|
548
|
+
const fn = tag >>> 3;
|
|
549
|
+
const wt = tag & 7;
|
|
550
|
+
if (wt === 2) {
|
|
551
|
+
const len = readVarint(buf, state);
|
|
552
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
553
|
+
state.pos += len;
|
|
554
|
+
onBytes(fn, slice);
|
|
555
|
+
}
|
|
556
|
+
else if (wt === 0) {
|
|
557
|
+
const val = readVarint(buf, state);
|
|
558
|
+
onVarint?.(fn, val);
|
|
559
|
+
}
|
|
560
|
+
else if (wt === 5) {
|
|
561
|
+
state.pos += 4;
|
|
562
|
+
}
|
|
563
|
+
else if (wt === 1) {
|
|
564
|
+
const slice = buf.subarray(state.pos, state.pos + 8);
|
|
565
|
+
state.pos += 8;
|
|
566
|
+
onFixed64?.(fn, slice);
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
function decodeMessageKey(buf) {
|
|
574
|
+
const mk = {};
|
|
575
|
+
readProtoFields(buf, (f, sl) => {
|
|
576
|
+
if (f === 1)
|
|
577
|
+
mk.remoteJid = Buffer.from(sl).toString("utf8");
|
|
578
|
+
else if (f === 3)
|
|
579
|
+
mk.id = Buffer.from(sl).toString("utf8");
|
|
580
|
+
else if (f === 4)
|
|
581
|
+
mk.participant = Buffer.from(sl).toString("utf8");
|
|
582
|
+
}, (f, v) => {
|
|
583
|
+
if (f === 2)
|
|
584
|
+
mk.fromMe = v !== 0;
|
|
585
|
+
});
|
|
586
|
+
return mk;
|
|
587
|
+
}
|
|
588
|
+
function decodeContactMessageData(buf) {
|
|
589
|
+
const res = {};
|
|
590
|
+
readProtoFields(buf, (f, sl) => {
|
|
591
|
+
if (f === 1)
|
|
592
|
+
res.displayName = Buffer.from(sl).toString("utf8");
|
|
593
|
+
else if (f === 16)
|
|
594
|
+
res.vcard = Buffer.from(sl).toString("utf8");
|
|
595
|
+
else if (f === 17)
|
|
596
|
+
res.contextInfo = decodeContextInfo(sl);
|
|
597
|
+
});
|
|
598
|
+
return res;
|
|
599
|
+
}
|
|
600
|
+
function decodePollCreationMessageData(buf) {
|
|
601
|
+
const res = {};
|
|
602
|
+
readProtoFields(buf, (f, sl) => {
|
|
603
|
+
if (f === 2)
|
|
604
|
+
res.name = Buffer.from(sl).toString("utf8");
|
|
605
|
+
else if (f === 3) {
|
|
606
|
+
let optionName;
|
|
607
|
+
readProtoFields(sl, (f2, sl2) => {
|
|
608
|
+
if (f2 === 1)
|
|
609
|
+
optionName = Buffer.from(sl2).toString("utf8");
|
|
610
|
+
});
|
|
611
|
+
(res.options ??= []).push({ optionName });
|
|
612
|
+
}
|
|
613
|
+
else if (f === 5)
|
|
614
|
+
res.contextInfo = decodeContextInfo(sl);
|
|
615
|
+
}, (f, v) => {
|
|
616
|
+
if (f === 4)
|
|
617
|
+
res.selectableOptionsCount = v;
|
|
618
|
+
});
|
|
619
|
+
return res;
|
|
620
|
+
}
|
|
621
|
+
function decodeContextInfo(buf) {
|
|
622
|
+
const res = {};
|
|
623
|
+
readProtoFields(buf, (fn, slice) => {
|
|
624
|
+
if (fn === 1)
|
|
625
|
+
res.stanzaId = Buffer.from(slice).toString("utf8");
|
|
626
|
+
else if (fn === 2)
|
|
627
|
+
res.participant = Buffer.from(slice).toString("utf8");
|
|
628
|
+
else if (fn === 3)
|
|
629
|
+
res.quotedMessage = decodeWAMessageData(slice);
|
|
630
|
+
else if (fn === 4)
|
|
631
|
+
res.remoteJid = Buffer.from(slice).toString("utf8");
|
|
632
|
+
else if (fn === 15)
|
|
633
|
+
(res.mentionedJid ??= []).push(Buffer.from(slice).toString("utf8"));
|
|
634
|
+
}, (fn, val) => {
|
|
635
|
+
if (fn === 21)
|
|
636
|
+
res.forwardingScore = val;
|
|
637
|
+
else if (fn === 22)
|
|
638
|
+
res.isForwarded = val !== 0;
|
|
639
|
+
else if (fn === 25)
|
|
640
|
+
res.expiration = val;
|
|
641
|
+
else if (fn === 66)
|
|
642
|
+
res.isGroupStatus = val !== 0;
|
|
643
|
+
});
|
|
644
|
+
return res;
|
|
645
|
+
}
|
|
646
|
+
function decodeImageMessageData(buf) {
|
|
647
|
+
const res = {};
|
|
648
|
+
readProtoFields(buf, (fn, slice) => {
|
|
649
|
+
if (fn === 1)
|
|
650
|
+
res.url = Buffer.from(slice).toString("utf8");
|
|
651
|
+
else if (fn === 2)
|
|
652
|
+
res.mimetype = Buffer.from(slice).toString("utf8");
|
|
653
|
+
else if (fn === 3)
|
|
654
|
+
res.caption = Buffer.from(slice).toString("utf8");
|
|
655
|
+
else if (fn === 4)
|
|
656
|
+
res.fileSha256 = Uint8Array.from(slice);
|
|
657
|
+
else if (fn === 8)
|
|
658
|
+
res.mediaKey = Uint8Array.from(slice);
|
|
659
|
+
else if (fn === 9)
|
|
660
|
+
res.fileEncSha256 = Uint8Array.from(slice);
|
|
661
|
+
else if (fn === 11)
|
|
662
|
+
res.directPath = Buffer.from(slice).toString("utf8");
|
|
663
|
+
else if (fn === 17)
|
|
664
|
+
res.contextInfo = decodeContextInfo(slice);
|
|
665
|
+
}, (fn, val) => {
|
|
666
|
+
if (fn === 5)
|
|
667
|
+
res.fileLength = val;
|
|
668
|
+
else if (fn === 12)
|
|
669
|
+
res.mediaKeyTimestamp = val;
|
|
670
|
+
});
|
|
671
|
+
return res;
|
|
672
|
+
}
|
|
673
|
+
function decodeVideoMessageData(buf) {
|
|
674
|
+
const res = {};
|
|
675
|
+
readProtoFields(buf, (fn, slice) => {
|
|
676
|
+
if (fn === 1)
|
|
677
|
+
res.url = Buffer.from(slice).toString("utf8");
|
|
678
|
+
else if (fn === 2)
|
|
679
|
+
res.mimetype = Buffer.from(slice).toString("utf8");
|
|
680
|
+
else if (fn === 3)
|
|
681
|
+
res.fileSha256 = Uint8Array.from(slice);
|
|
682
|
+
else if (fn === 6)
|
|
683
|
+
res.mediaKey = Uint8Array.from(slice);
|
|
684
|
+
else if (fn === 7)
|
|
685
|
+
res.caption = Buffer.from(slice).toString("utf8");
|
|
686
|
+
else if (fn === 11)
|
|
687
|
+
res.fileEncSha256 = Uint8Array.from(slice);
|
|
688
|
+
else if (fn === 13)
|
|
689
|
+
res.directPath = Buffer.from(slice).toString("utf8");
|
|
690
|
+
else if (fn === 17)
|
|
691
|
+
res.contextInfo = decodeContextInfo(slice);
|
|
692
|
+
}, (fn, val) => {
|
|
693
|
+
if (fn === 4)
|
|
694
|
+
res.fileLength = val;
|
|
695
|
+
else if (fn === 8)
|
|
696
|
+
res.gifPlayback = val !== 0;
|
|
697
|
+
else if (fn === 14)
|
|
698
|
+
res.mediaKeyTimestamp = val;
|
|
699
|
+
});
|
|
700
|
+
return res;
|
|
701
|
+
}
|
|
702
|
+
function decodeAudioMessageData(buf) {
|
|
703
|
+
const res = {};
|
|
704
|
+
readProtoFields(buf, (fn, slice) => {
|
|
705
|
+
if (fn === 1)
|
|
706
|
+
res.url = Buffer.from(slice).toString("utf8");
|
|
707
|
+
else if (fn === 2)
|
|
708
|
+
res.mimetype = Buffer.from(slice).toString("utf8");
|
|
709
|
+
else if (fn === 3)
|
|
710
|
+
res.fileSha256 = Uint8Array.from(slice);
|
|
711
|
+
else if (fn === 7)
|
|
712
|
+
res.mediaKey = Uint8Array.from(slice);
|
|
713
|
+
else if (fn === 8)
|
|
714
|
+
res.fileEncSha256 = Uint8Array.from(slice);
|
|
715
|
+
else if (fn === 9)
|
|
716
|
+
res.directPath = Buffer.from(slice).toString("utf8");
|
|
717
|
+
else if (fn === 17)
|
|
718
|
+
res.contextInfo = decodeContextInfo(slice);
|
|
719
|
+
else if (fn === 19)
|
|
720
|
+
res.waveform = Uint8Array.from(slice);
|
|
721
|
+
}, (fn, val) => {
|
|
722
|
+
if (fn === 4)
|
|
723
|
+
res.fileLength = val;
|
|
724
|
+
else if (fn === 5)
|
|
725
|
+
res.seconds = val;
|
|
726
|
+
else if (fn === 6)
|
|
727
|
+
res.ptt = val !== 0;
|
|
728
|
+
else if (fn === 10)
|
|
729
|
+
res.mediaKeyTimestamp = val;
|
|
730
|
+
});
|
|
731
|
+
return res;
|
|
732
|
+
}
|
|
733
|
+
function decodeDocumentMessageData(buf) {
|
|
734
|
+
const res = {};
|
|
735
|
+
readProtoFields(buf, (fn, slice) => {
|
|
736
|
+
if (fn === 1)
|
|
737
|
+
res.url = Buffer.from(slice).toString("utf8");
|
|
738
|
+
else if (fn === 2)
|
|
739
|
+
res.mimetype = Buffer.from(slice).toString("utf8");
|
|
740
|
+
else if (fn === 3)
|
|
741
|
+
res.title = Buffer.from(slice).toString("utf8");
|
|
742
|
+
else if (fn === 4)
|
|
743
|
+
res.fileSha256 = Uint8Array.from(slice);
|
|
744
|
+
else if (fn === 7)
|
|
745
|
+
res.mediaKey = Uint8Array.from(slice);
|
|
746
|
+
else if (fn === 8)
|
|
747
|
+
res.fileName = Buffer.from(slice).toString("utf8");
|
|
748
|
+
else if (fn === 9)
|
|
749
|
+
res.fileEncSha256 = Uint8Array.from(slice);
|
|
750
|
+
else if (fn === 10)
|
|
751
|
+
res.directPath = Buffer.from(slice).toString("utf8");
|
|
752
|
+
else if (fn === 17)
|
|
753
|
+
res.contextInfo = decodeContextInfo(slice);
|
|
754
|
+
else if (fn === 20)
|
|
755
|
+
res.caption = Buffer.from(slice).toString("utf8");
|
|
756
|
+
}, (fn, val) => {
|
|
757
|
+
if (fn === 5)
|
|
758
|
+
res.fileLength = val;
|
|
759
|
+
else if (fn === 11)
|
|
760
|
+
res.mediaKeyTimestamp = val;
|
|
761
|
+
});
|
|
762
|
+
return res;
|
|
763
|
+
}
|
|
764
|
+
function decodeStickerMessageData(buf) {
|
|
765
|
+
const res = {};
|
|
766
|
+
readProtoFields(buf, (fn, slice) => {
|
|
767
|
+
if (fn === 1)
|
|
768
|
+
res.url = Buffer.from(slice).toString("utf8");
|
|
769
|
+
else if (fn === 2)
|
|
770
|
+
res.fileSha256 = Uint8Array.from(slice);
|
|
771
|
+
else if (fn === 3)
|
|
772
|
+
res.fileEncSha256 = Uint8Array.from(slice);
|
|
773
|
+
else if (fn === 4)
|
|
774
|
+
res.mediaKey = Uint8Array.from(slice);
|
|
775
|
+
else if (fn === 5)
|
|
776
|
+
res.mimetype = Buffer.from(slice).toString("utf8");
|
|
777
|
+
else if (fn === 8)
|
|
778
|
+
res.directPath = Buffer.from(slice).toString("utf8");
|
|
779
|
+
else if (fn === 17)
|
|
780
|
+
res.contextInfo = decodeContextInfo(slice);
|
|
781
|
+
}, (fn, val) => {
|
|
782
|
+
if (fn === 9)
|
|
783
|
+
res.fileLength = val;
|
|
784
|
+
else if (fn === 10)
|
|
785
|
+
res.mediaKeyTimestamp = val;
|
|
786
|
+
else if (fn === 13)
|
|
787
|
+
res.isAnimated = val !== 0;
|
|
788
|
+
});
|
|
789
|
+
return res;
|
|
790
|
+
}
|
|
791
|
+
function decodeFutureProofMessage(buf) {
|
|
792
|
+
const state = { pos: 0 };
|
|
793
|
+
const res = {};
|
|
794
|
+
while (state.pos < buf.length) {
|
|
795
|
+
const tag = readVarint(buf, state);
|
|
796
|
+
const fn = tag >>> 3;
|
|
797
|
+
const wt = tag & 7;
|
|
798
|
+
if (wt === 2) {
|
|
799
|
+
const len = readVarint(buf, state);
|
|
800
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
801
|
+
state.pos += len;
|
|
802
|
+
if (fn === 1)
|
|
803
|
+
res.message = decodeWAMessageData(slice);
|
|
804
|
+
}
|
|
805
|
+
else if (wt === 0) {
|
|
806
|
+
readVarint(buf, state);
|
|
807
|
+
}
|
|
808
|
+
else if (wt === 5) {
|
|
809
|
+
state.pos += 4;
|
|
810
|
+
}
|
|
811
|
+
else if (wt === 1) {
|
|
812
|
+
state.pos += 8;
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return res;
|
|
819
|
+
}
|
|
820
|
+
function decodeWAMessageData(buf) {
|
|
821
|
+
const state = { pos: 0 };
|
|
822
|
+
const res = {};
|
|
823
|
+
while (state.pos < buf.length) {
|
|
824
|
+
const tag = readVarint(buf, state);
|
|
825
|
+
const fn = tag >>> 3;
|
|
826
|
+
const wt = tag & 7;
|
|
827
|
+
if (wt === 2) {
|
|
828
|
+
const len = readVarint(buf, state);
|
|
829
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
830
|
+
state.pos += len;
|
|
831
|
+
if (fn === 1) {
|
|
832
|
+
res.conversation = Buffer.from(slice).toString("utf8");
|
|
833
|
+
}
|
|
834
|
+
else if (fn === 2) {
|
|
835
|
+
const s2 = { pos: 0 };
|
|
836
|
+
const sk = {};
|
|
837
|
+
while (s2.pos < slice.length) {
|
|
838
|
+
const t2 = readVarint(slice, s2);
|
|
839
|
+
const f2 = t2 >>> 3;
|
|
840
|
+
const w2 = t2 & 7;
|
|
841
|
+
if (w2 === 2) {
|
|
842
|
+
const l2 = readVarint(slice, s2);
|
|
843
|
+
const sl2 = slice.subarray(s2.pos, s2.pos + l2);
|
|
844
|
+
s2.pos += l2;
|
|
845
|
+
if (f2 === 1)
|
|
846
|
+
sk.groupId = Buffer.from(sl2).toString("utf8");
|
|
847
|
+
else if (f2 === 2)
|
|
848
|
+
sk.axolotlSenderKeyDistributionMessage = Uint8Array.from(sl2);
|
|
849
|
+
}
|
|
850
|
+
else if (w2 === 0)
|
|
851
|
+
readVarint(slice, s2);
|
|
852
|
+
else
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
res.senderKeyDistributionMessage = sk;
|
|
856
|
+
}
|
|
857
|
+
else if (fn === 3) {
|
|
858
|
+
res.imageMessage = decodeImageMessageData(slice);
|
|
859
|
+
}
|
|
860
|
+
else if (fn === 4) {
|
|
861
|
+
res.contactMessage = decodeContactMessageData(slice);
|
|
862
|
+
}
|
|
863
|
+
else if (fn === 5) {
|
|
864
|
+
const lm = {};
|
|
865
|
+
readProtoFields(slice, (f2, sl2) => {
|
|
866
|
+
if (f2 === 3)
|
|
867
|
+
lm.name = Buffer.from(sl2).toString("utf8");
|
|
868
|
+
else if (f2 === 4)
|
|
869
|
+
lm.address = Buffer.from(sl2).toString("utf8");
|
|
870
|
+
else if (f2 === 5)
|
|
871
|
+
lm.url = Buffer.from(sl2).toString("utf8");
|
|
872
|
+
else if (f2 === 16)
|
|
873
|
+
lm.jpegThumbnail = Uint8Array.from(sl2);
|
|
874
|
+
else if (f2 === 17)
|
|
875
|
+
lm.contextInfo = decodeContextInfo(sl2);
|
|
876
|
+
}, undefined, (f2, sl2) => {
|
|
877
|
+
const val = Buffer.from(sl2).readDoubleLE(0);
|
|
878
|
+
if (f2 === 1)
|
|
879
|
+
lm.degreesLatitude = val;
|
|
880
|
+
else if (f2 === 2)
|
|
881
|
+
lm.degreesLongitude = val;
|
|
882
|
+
});
|
|
883
|
+
res.locationMessage = lm;
|
|
884
|
+
}
|
|
885
|
+
else if (fn === 6) {
|
|
886
|
+
const et = {};
|
|
887
|
+
readProtoFields(slice, (f2, sl2) => {
|
|
888
|
+
if (f2 === 1)
|
|
889
|
+
et.text = Buffer.from(sl2).toString("utf8");
|
|
890
|
+
else if (f2 === 17)
|
|
891
|
+
et.contextInfo = decodeContextInfo(sl2);
|
|
892
|
+
});
|
|
893
|
+
res.extendedTextMessage = et;
|
|
894
|
+
}
|
|
895
|
+
else if (fn === 7) {
|
|
896
|
+
res.documentMessage = decodeDocumentMessageData(slice);
|
|
897
|
+
}
|
|
898
|
+
else if (fn === 8) {
|
|
899
|
+
res.audioMessage = decodeAudioMessageData(slice);
|
|
900
|
+
}
|
|
901
|
+
else if (fn === 9) {
|
|
902
|
+
res.videoMessage = decodeVideoMessageData(slice);
|
|
903
|
+
}
|
|
904
|
+
else if (fn === 12) {
|
|
905
|
+
const pm = {};
|
|
906
|
+
readProtoFields(slice, (f2, sl2) => {
|
|
907
|
+
if (f2 === 1)
|
|
908
|
+
pm.key = decodeMessageKey(sl2);
|
|
909
|
+
else if (f2 === 14)
|
|
910
|
+
pm.editedMessage = decodeWAMessageData(sl2);
|
|
911
|
+
}, (f2, v2) => {
|
|
912
|
+
if (f2 === 2)
|
|
913
|
+
pm.type = v2;
|
|
914
|
+
else if (f2 === 4)
|
|
915
|
+
pm.ephemeralExpiration = v2;
|
|
916
|
+
});
|
|
917
|
+
res.protocolMessage = pm;
|
|
918
|
+
}
|
|
919
|
+
else if (fn === 13) {
|
|
920
|
+
const ca = {};
|
|
921
|
+
readProtoFields(slice, (f2, sl2) => {
|
|
922
|
+
if (f2 === 1)
|
|
923
|
+
ca.displayName = Buffer.from(sl2).toString("utf8");
|
|
924
|
+
else if (f2 === 2)
|
|
925
|
+
(ca.contacts ??= []).push(decodeContactMessageData(sl2));
|
|
926
|
+
else if (f2 === 17)
|
|
927
|
+
ca.contextInfo = decodeContextInfo(sl2);
|
|
928
|
+
});
|
|
929
|
+
res.contactsArrayMessage = ca;
|
|
930
|
+
}
|
|
931
|
+
else if (fn === 26) {
|
|
932
|
+
res.stickerMessage = decodeStickerMessageData(slice);
|
|
933
|
+
}
|
|
934
|
+
else if (fn === 46) {
|
|
935
|
+
const rm = {};
|
|
936
|
+
readProtoFields(slice, (f2, sl2) => {
|
|
937
|
+
if (f2 === 1)
|
|
938
|
+
rm.key = decodeMessageKey(sl2);
|
|
939
|
+
else if (f2 === 2)
|
|
940
|
+
rm.text = Buffer.from(sl2).toString("utf8");
|
|
941
|
+
}, (f2, v2) => {
|
|
942
|
+
if (f2 === 4)
|
|
943
|
+
rm.senderTimestampMs = v2;
|
|
944
|
+
});
|
|
945
|
+
res.reactionMessage = rm;
|
|
946
|
+
}
|
|
947
|
+
else if (fn === 49) {
|
|
948
|
+
res.pollCreationMessage = decodePollCreationMessageData(slice);
|
|
949
|
+
}
|
|
950
|
+
else if (fn === 64) {
|
|
951
|
+
res.pollCreationMessageV3 = decodePollCreationMessageData(slice);
|
|
952
|
+
}
|
|
953
|
+
else if (fn === 66) {
|
|
954
|
+
res.ptvMessage = decodeVideoMessageData(slice);
|
|
955
|
+
}
|
|
956
|
+
else if (fn === 31) {
|
|
957
|
+
const s2 = { pos: 0 };
|
|
958
|
+
const ds = {};
|
|
959
|
+
while (s2.pos < slice.length) {
|
|
960
|
+
const t2 = readVarint(slice, s2);
|
|
961
|
+
const f2 = t2 >>> 3;
|
|
962
|
+
const w2 = t2 & 7;
|
|
963
|
+
if (w2 === 2) {
|
|
964
|
+
const l2 = readVarint(slice, s2);
|
|
965
|
+
const sl2 = slice.subarray(s2.pos, s2.pos + l2);
|
|
966
|
+
s2.pos += l2;
|
|
967
|
+
if (f2 === 1)
|
|
968
|
+
ds.destinationJid = Buffer.from(sl2).toString("utf8");
|
|
969
|
+
else if (f2 === 2)
|
|
970
|
+
ds.message = decodeWAMessageData(sl2);
|
|
971
|
+
}
|
|
972
|
+
else if (w2 === 0)
|
|
973
|
+
readVarint(slice, s2);
|
|
974
|
+
else
|
|
975
|
+
break;
|
|
976
|
+
}
|
|
977
|
+
res.deviceSentMessage = ds;
|
|
978
|
+
}
|
|
979
|
+
else if (fn === 37) {
|
|
980
|
+
res.viewOnceMessage = decodeFutureProofMessage(slice);
|
|
981
|
+
}
|
|
982
|
+
else if (fn === 40) {
|
|
983
|
+
res.ephemeralMessage = decodeFutureProofMessage(slice);
|
|
984
|
+
}
|
|
985
|
+
else if (fn === 43) {
|
|
986
|
+
const s2 = { pos: 0 };
|
|
987
|
+
const br = {};
|
|
988
|
+
while (s2.pos < slice.length) {
|
|
989
|
+
const t2 = readVarint(slice, s2);
|
|
990
|
+
const f2 = t2 >>> 3;
|
|
991
|
+
const w2 = t2 & 7;
|
|
992
|
+
if (w2 === 2) {
|
|
993
|
+
const l2 = readVarint(slice, s2);
|
|
994
|
+
const sl2 = slice.subarray(s2.pos, s2.pos + l2);
|
|
995
|
+
s2.pos += l2;
|
|
996
|
+
if (f2 === 1)
|
|
997
|
+
br.selectedButtonId = Buffer.from(sl2).toString("utf8");
|
|
998
|
+
else if (f2 === 2)
|
|
999
|
+
br.selectedDisplayText = Buffer.from(sl2).toString("utf8");
|
|
1000
|
+
}
|
|
1001
|
+
else if (w2 === 0) {
|
|
1002
|
+
const v2 = readVarint(slice, s2);
|
|
1003
|
+
if (f2 === 4)
|
|
1004
|
+
br.type = v2;
|
|
1005
|
+
}
|
|
1006
|
+
else
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
res.buttonsResponseMessage = br;
|
|
1010
|
+
}
|
|
1011
|
+
else if (fn === 48) {
|
|
1012
|
+
const s2 = { pos: 0 };
|
|
1013
|
+
const ir = {};
|
|
1014
|
+
while (s2.pos < slice.length) {
|
|
1015
|
+
const t2 = readVarint(slice, s2);
|
|
1016
|
+
const f2 = t2 >>> 3;
|
|
1017
|
+
const w2 = t2 & 7;
|
|
1018
|
+
if (w2 === 2) {
|
|
1019
|
+
const l2 = readVarint(slice, s2);
|
|
1020
|
+
const sl2 = slice.subarray(s2.pos, s2.pos + l2);
|
|
1021
|
+
s2.pos += l2;
|
|
1022
|
+
if (f2 === 2) {
|
|
1023
|
+
const s3 = { pos: 0 };
|
|
1024
|
+
const nf = {};
|
|
1025
|
+
while (s3.pos < sl2.length) {
|
|
1026
|
+
const t3 = readVarint(sl2, s3);
|
|
1027
|
+
const f3 = t3 >>> 3;
|
|
1028
|
+
const w3 = t3 & 7;
|
|
1029
|
+
if (w3 === 2) {
|
|
1030
|
+
const l3 = readVarint(sl2, s3);
|
|
1031
|
+
const sl3 = sl2.subarray(s3.pos, s3.pos + l3);
|
|
1032
|
+
s3.pos += l3;
|
|
1033
|
+
if (f3 === 1)
|
|
1034
|
+
nf.name = Buffer.from(sl3).toString("utf8");
|
|
1035
|
+
else if (f3 === 2)
|
|
1036
|
+
nf.paramsJson = Buffer.from(sl3).toString("utf8");
|
|
1037
|
+
}
|
|
1038
|
+
else if (w3 === 0) {
|
|
1039
|
+
const v3 = readVarint(sl2, s3);
|
|
1040
|
+
if (f3 === 3)
|
|
1041
|
+
nf.version = v3;
|
|
1042
|
+
}
|
|
1043
|
+
else
|
|
1044
|
+
break;
|
|
1045
|
+
}
|
|
1046
|
+
ir.nativeFlowResponseMessage = nf;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
else if (w2 === 0)
|
|
1050
|
+
readVarint(slice, s2);
|
|
1051
|
+
else
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
res.interactiveResponseMessage = ir;
|
|
1055
|
+
}
|
|
1056
|
+
else if (fn === 53) {
|
|
1057
|
+
res.documentWithCaptionMessage = decodeFutureProofMessage(slice);
|
|
1058
|
+
}
|
|
1059
|
+
else if (fn === 55) {
|
|
1060
|
+
res.viewOnceMessageV2 = decodeFutureProofMessage(slice);
|
|
1061
|
+
}
|
|
1062
|
+
else if (fn === 58) {
|
|
1063
|
+
res.editedMessage = decodeFutureProofMessage(slice);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
else if (wt === 0) {
|
|
1067
|
+
readVarint(buf, state);
|
|
1068
|
+
}
|
|
1069
|
+
else if (wt === 5) {
|
|
1070
|
+
state.pos += 4;
|
|
1071
|
+
}
|
|
1072
|
+
else if (wt === 1) {
|
|
1073
|
+
state.pos += 8;
|
|
1074
|
+
}
|
|
1075
|
+
else {
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return res;
|
|
1080
|
+
}
|
|
1081
|
+
export const proto = {
|
|
1082
|
+
HandshakeMessage: {
|
|
1083
|
+
encode(msg) {
|
|
1084
|
+
const out = [];
|
|
1085
|
+
if (msg.clientHello)
|
|
1086
|
+
writeBytesField(out, 2, encodeSubHello(msg.clientHello));
|
|
1087
|
+
if (msg.serverHello)
|
|
1088
|
+
writeBytesField(out, 3, encodeSubHello(msg.serverHello));
|
|
1089
|
+
if (msg.clientFinish)
|
|
1090
|
+
writeBytesField(out, 4, encodeClientFinish(msg.clientFinish));
|
|
1091
|
+
return Uint8Array.from(out);
|
|
1092
|
+
},
|
|
1093
|
+
decode(buf) {
|
|
1094
|
+
const state = { pos: 0 };
|
|
1095
|
+
const res = {};
|
|
1096
|
+
while (state.pos < buf.length) {
|
|
1097
|
+
const tag = readVarint(buf, state);
|
|
1098
|
+
const fn = tag >>> 3;
|
|
1099
|
+
const wt = tag & 7;
|
|
1100
|
+
if (wt === 2) {
|
|
1101
|
+
const len = readVarint(buf, state);
|
|
1102
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
1103
|
+
state.pos += len;
|
|
1104
|
+
if (fn === 2)
|
|
1105
|
+
res.clientHello = decodeSubHello(slice);
|
|
1106
|
+
else if (fn === 3)
|
|
1107
|
+
res.serverHello = decodeSubHello(slice);
|
|
1108
|
+
else if (fn === 4)
|
|
1109
|
+
res.clientFinish = decodeSubHello(slice);
|
|
1110
|
+
}
|
|
1111
|
+
else if (wt === 0) {
|
|
1112
|
+
readVarint(buf, state);
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return res;
|
|
1119
|
+
},
|
|
1120
|
+
},
|
|
1121
|
+
Message: {
|
|
1122
|
+
encode(msg) {
|
|
1123
|
+
return encodeWAMessageData(msg);
|
|
1124
|
+
},
|
|
1125
|
+
decode(buf) {
|
|
1126
|
+
return decodeWAMessageData(buf);
|
|
1127
|
+
},
|
|
1128
|
+
},
|
|
1129
|
+
ClientPayload: {
|
|
1130
|
+
encode(payload) {
|
|
1131
|
+
const out = [];
|
|
1132
|
+
if (payload.username !== undefined)
|
|
1133
|
+
writeVarintField64(out, 1, payload.username);
|
|
1134
|
+
if (payload.passive !== undefined)
|
|
1135
|
+
writeVarintField(out, 3, payload.passive ? 1 : 0);
|
|
1136
|
+
if (payload.userAgent) {
|
|
1137
|
+
const ua = [];
|
|
1138
|
+
const u = payload.userAgent;
|
|
1139
|
+
if (u.platform !== undefined)
|
|
1140
|
+
writeVarintField(ua, 1, u.platform);
|
|
1141
|
+
if (u.appVersion) {
|
|
1142
|
+
const av = [];
|
|
1143
|
+
writeVarintField(av, 1, u.appVersion.primary);
|
|
1144
|
+
writeVarintField(av, 2, u.appVersion.secondary);
|
|
1145
|
+
writeVarintField(av, 3, u.appVersion.tertiary);
|
|
1146
|
+
writeBytesField(ua, 2, Uint8Array.from(av));
|
|
1147
|
+
}
|
|
1148
|
+
if (u.mcc)
|
|
1149
|
+
writeBytesField(ua, 3, Buffer.from(u.mcc));
|
|
1150
|
+
if (u.mnc)
|
|
1151
|
+
writeBytesField(ua, 4, Buffer.from(u.mnc));
|
|
1152
|
+
if (u.osVersion)
|
|
1153
|
+
writeBytesField(ua, 5, Buffer.from(u.osVersion));
|
|
1154
|
+
if (u.device)
|
|
1155
|
+
writeBytesField(ua, 7, Buffer.from(u.device));
|
|
1156
|
+
if (u.osBuildNumber)
|
|
1157
|
+
writeBytesField(ua, 8, Buffer.from(u.osBuildNumber));
|
|
1158
|
+
if (u.releaseChannel !== undefined)
|
|
1159
|
+
writeVarintField(ua, 10, u.releaseChannel);
|
|
1160
|
+
if (u.localeLanguageIso6391)
|
|
1161
|
+
writeBytesField(ua, 11, Buffer.from(u.localeLanguageIso6391));
|
|
1162
|
+
if (u.localeCountryIso31661Alpha2)
|
|
1163
|
+
writeBytesField(ua, 12, Buffer.from(u.localeCountryIso31661Alpha2));
|
|
1164
|
+
writeBytesField(out, 5, Uint8Array.from(ua));
|
|
1165
|
+
}
|
|
1166
|
+
if (payload.webInfo) {
|
|
1167
|
+
const wi = [];
|
|
1168
|
+
if (payload.webInfo.webSubPlatform !== undefined)
|
|
1169
|
+
writeVarintField(wi, 4, payload.webInfo.webSubPlatform);
|
|
1170
|
+
writeBytesField(out, 6, Uint8Array.from(wi));
|
|
1171
|
+
}
|
|
1172
|
+
if (payload.connectType !== undefined)
|
|
1173
|
+
writeVarintField(out, 12, payload.connectType);
|
|
1174
|
+
if (payload.connectReason !== undefined)
|
|
1175
|
+
writeVarintField(out, 13, payload.connectReason);
|
|
1176
|
+
if (payload.device !== undefined)
|
|
1177
|
+
writeVarintField(out, 18, payload.device);
|
|
1178
|
+
if (payload.devicePairingData) {
|
|
1179
|
+
const d = payload.devicePairingData;
|
|
1180
|
+
const dp = [];
|
|
1181
|
+
writeBytesField(dp, 1, d.eRegid);
|
|
1182
|
+
writeBytesField(dp, 2, d.eKeytype);
|
|
1183
|
+
writeBytesField(dp, 3, d.eIdent);
|
|
1184
|
+
writeBytesField(dp, 4, d.eSkeyId);
|
|
1185
|
+
writeBytesField(dp, 5, d.eSkeyVal);
|
|
1186
|
+
writeBytesField(dp, 6, d.eSkeySig);
|
|
1187
|
+
writeBytesField(dp, 7, d.buildHash);
|
|
1188
|
+
writeBytesField(dp, 8, d.deviceProps);
|
|
1189
|
+
writeBytesField(out, 19, Uint8Array.from(dp));
|
|
1190
|
+
}
|
|
1191
|
+
if (payload.pull !== undefined)
|
|
1192
|
+
writeVarintField(out, 33, payload.pull ? 1 : 0);
|
|
1193
|
+
return Uint8Array.from(out);
|
|
1194
|
+
},
|
|
1195
|
+
},
|
|
1196
|
+
DeviceProps: {
|
|
1197
|
+
encode(props) {
|
|
1198
|
+
const out = [];
|
|
1199
|
+
writeBytesField(out, 1, Buffer.from(props.os));
|
|
1200
|
+
if (props.version) {
|
|
1201
|
+
const v = [];
|
|
1202
|
+
writeVarintField(v, 1, props.version.primary);
|
|
1203
|
+
writeVarintField(v, 2, props.version.secondary);
|
|
1204
|
+
writeVarintField(v, 3, props.version.tertiary);
|
|
1205
|
+
writeBytesField(out, 2, Uint8Array.from(v));
|
|
1206
|
+
}
|
|
1207
|
+
writeVarintField(out, 3, props.platformType);
|
|
1208
|
+
writeVarintField(out, 4, props.requireFullSync ? 1 : 0);
|
|
1209
|
+
return Uint8Array.from(out);
|
|
1210
|
+
},
|
|
1211
|
+
},
|
|
1212
|
+
ADVSignedDeviceIdentityHMAC: {
|
|
1213
|
+
decode(buf) {
|
|
1214
|
+
const state = { pos: 0 };
|
|
1215
|
+
let details = new Uint8Array(0);
|
|
1216
|
+
let hmac = new Uint8Array(0);
|
|
1217
|
+
let accountType;
|
|
1218
|
+
while (state.pos < buf.length) {
|
|
1219
|
+
const tag = readVarint(buf, state);
|
|
1220
|
+
const fn = tag >>> 3;
|
|
1221
|
+
const wt = tag & 7;
|
|
1222
|
+
if (wt === 2) {
|
|
1223
|
+
const len = readVarint(buf, state);
|
|
1224
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
1225
|
+
state.pos += len;
|
|
1226
|
+
if (fn === 1)
|
|
1227
|
+
details = slice;
|
|
1228
|
+
else if (fn === 2)
|
|
1229
|
+
hmac = slice;
|
|
1230
|
+
}
|
|
1231
|
+
else if (wt === 0) {
|
|
1232
|
+
const v = readVarint(buf, state);
|
|
1233
|
+
if (fn === 3)
|
|
1234
|
+
accountType = v;
|
|
1235
|
+
}
|
|
1236
|
+
else if (wt === 5) {
|
|
1237
|
+
state.pos += 4;
|
|
1238
|
+
}
|
|
1239
|
+
else if (wt === 1) {
|
|
1240
|
+
state.pos += 8;
|
|
1241
|
+
}
|
|
1242
|
+
else {
|
|
1243
|
+
break;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return { details, hmac, accountType };
|
|
1247
|
+
},
|
|
1248
|
+
},
|
|
1249
|
+
ADVSignedDeviceIdentity: {
|
|
1250
|
+
decode(buf) {
|
|
1251
|
+
const state = { pos: 0 };
|
|
1252
|
+
let details = new Uint8Array(0);
|
|
1253
|
+
let accountSignatureKey = new Uint8Array(0);
|
|
1254
|
+
let accountSignature = new Uint8Array(0);
|
|
1255
|
+
let deviceSignature = new Uint8Array(0);
|
|
1256
|
+
while (state.pos < buf.length) {
|
|
1257
|
+
const tag = readVarint(buf, state);
|
|
1258
|
+
const fn = tag >>> 3;
|
|
1259
|
+
const wt = tag & 7;
|
|
1260
|
+
if (wt === 2) {
|
|
1261
|
+
const len = readVarint(buf, state);
|
|
1262
|
+
const slice = buf.subarray(state.pos, state.pos + len);
|
|
1263
|
+
state.pos += len;
|
|
1264
|
+
if (fn === 1)
|
|
1265
|
+
details = slice;
|
|
1266
|
+
else if (fn === 2)
|
|
1267
|
+
accountSignatureKey = slice;
|
|
1268
|
+
else if (fn === 3)
|
|
1269
|
+
accountSignature = slice;
|
|
1270
|
+
else if (fn === 4)
|
|
1271
|
+
deviceSignature = slice;
|
|
1272
|
+
}
|
|
1273
|
+
else if (wt === 0) {
|
|
1274
|
+
readVarint(buf, state);
|
|
1275
|
+
}
|
|
1276
|
+
else if (wt === 5) {
|
|
1277
|
+
state.pos += 4;
|
|
1278
|
+
}
|
|
1279
|
+
else if (wt === 1) {
|
|
1280
|
+
state.pos += 8;
|
|
1281
|
+
}
|
|
1282
|
+
else {
|
|
1283
|
+
break;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
return { details, accountSignatureKey, accountSignature, deviceSignature };
|
|
1287
|
+
},
|
|
1288
|
+
encode(msg) {
|
|
1289
|
+
const out = [];
|
|
1290
|
+
if (msg.details?.length)
|
|
1291
|
+
writeBytesField(out, 1, msg.details);
|
|
1292
|
+
if (msg.accountSignatureKey?.length)
|
|
1293
|
+
writeBytesField(out, 2, msg.accountSignatureKey);
|
|
1294
|
+
if (msg.accountSignature?.length)
|
|
1295
|
+
writeBytesField(out, 3, msg.accountSignature);
|
|
1296
|
+
if (msg.deviceSignature?.length)
|
|
1297
|
+
writeBytesField(out, 4, msg.deviceSignature);
|
|
1298
|
+
return Uint8Array.from(out);
|
|
1299
|
+
},
|
|
1300
|
+
},
|
|
1301
|
+
ADVDeviceIdentity: {
|
|
1302
|
+
decode(buf) {
|
|
1303
|
+
const state = { pos: 0 };
|
|
1304
|
+
let rawId = 0;
|
|
1305
|
+
let timestamp = 0;
|
|
1306
|
+
let keyIndex = 0;
|
|
1307
|
+
let deviceType;
|
|
1308
|
+
while (state.pos < buf.length) {
|
|
1309
|
+
const tag = readVarint(buf, state);
|
|
1310
|
+
const fn = tag >>> 3;
|
|
1311
|
+
const wt = tag & 7;
|
|
1312
|
+
if (wt === 0) {
|
|
1313
|
+
const v = readVarint(buf, state);
|
|
1314
|
+
if (fn === 1)
|
|
1315
|
+
rawId = v;
|
|
1316
|
+
else if (fn === 2)
|
|
1317
|
+
timestamp = v;
|
|
1318
|
+
else if (fn === 3)
|
|
1319
|
+
keyIndex = v;
|
|
1320
|
+
else if (fn === 5)
|
|
1321
|
+
deviceType = v;
|
|
1322
|
+
}
|
|
1323
|
+
else if (wt === 2) {
|
|
1324
|
+
const len = readVarint(buf, state);
|
|
1325
|
+
state.pos += len;
|
|
1326
|
+
}
|
|
1327
|
+
else if (wt === 5) {
|
|
1328
|
+
state.pos += 4;
|
|
1329
|
+
}
|
|
1330
|
+
else if (wt === 1) {
|
|
1331
|
+
state.pos += 8;
|
|
1332
|
+
}
|
|
1333
|
+
else {
|
|
1334
|
+
break;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
return { rawId, timestamp, keyIndex, deviceType };
|
|
1338
|
+
},
|
|
1339
|
+
},
|
|
1340
|
+
};
|
|
1341
|
+
export const WAProto = proto;
|
|
1342
|
+
//# sourceMappingURL=index.js.map
|