@badzz88/baileys 8.5.4 → 8.5.6
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 +2 -2
- package/WAProto/fix-imports.js +69 -79
- package/WAProto/index.d.ts +15305 -87935
- package/WAProto/index.js +41109 -194076
- package/engine-requirements.js +15 -8
- package/package.json +23 -19
- package/src/Defaults/index.js +186 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +86 -0
- package/src/Signal/Group/group_cipher.js +82 -0
- package/src/Signal/Group/index.js +140 -0
- package/src/Signal/Group/keyhelper.js +77 -0
- package/src/Signal/Group/sender-chain-key.js +29 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +51 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +87 -0
- package/src/Signal/Group/sender-message-key.js +29 -0
- package/src/Signal/libsignal.js +455 -0
- package/src/Signal/lid-mapping.js +273 -0
- package/src/Socket/Client/index.js +31 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +61 -0
- package/src/Socket/aigroups.js +221 -0
- package/src/Socket/business.js +411 -0
- package/src/Socket/chats.js +1449 -0
- package/src/Socket/communities.js +463 -0
- package/src/Socket/graphql.js +523 -0
- package/src/Socket/groups.js +516 -0
- package/src/Socket/index.js +31 -0
- package/src/Socket/interactive-handler.js +527 -0
- package/src/Socket/interop.js +339 -0
- package/src/Socket/luxu.js +349 -0
- package/src/Socket/managed-account.js +98 -0
- package/src/Socket/messages-recv.js +2685 -0
- package/src/Socket/messages-send.js +2047 -0
- package/src/Socket/mex.js +57 -0
- package/src/Socket/newsletter.js +455 -0
- package/src/Socket/privacy.js +125 -0
- package/src/Socket/registration.js +236 -0
- package/src/Socket/socket.js +983 -0
- package/src/Socket/text-router.js +65 -0
- package/src/Socket/username.js +130 -0
- package/src/Store/index.js +33 -0
- package/src/Store/keyed-db.js +118 -0
- package/src/Store/make-cache-manager-store.js +84 -0
- package/src/Store/make-in-memory-store.js +551 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +26 -0
- package/src/Types/Auth.js +31 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +26 -0
- package/src/Types/LabelAssociation.js +8 -0
- package/src/Types/Message.js +93 -0
- package/src/Types/Mex.js +112 -0
- package/src/Types/Newsletter.js +109 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +62 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +56 -0
- package/src/Utils/auth-utils.js +254 -0
- package/src/Utils/browser-utils.js +112 -0
- package/src/Utils/business.js +240 -0
- package/src/Utils/chat-utils.js +1230 -0
- package/src/Utils/command-loader.d.ts +27 -0
- package/src/Utils/command-loader.js +89 -0
- package/src/Utils/companion-reg-client-utils.js +40 -0
- package/src/Utils/consumer-application.js +105 -0
- package/src/Utils/crypto.js +118 -0
- package/src/Utils/curve25519-js.js +242 -0
- package/src/Utils/decode-wa-message.js +529 -0
- package/src/Utils/event-buffer.js +580 -0
- package/src/Utils/generics.js +483 -0
- package/src/Utils/group-history.js +44 -0
- package/src/Utils/history.js +232 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +58 -0
- package/src/Utils/jid-display-normalization.js +195 -0
- package/src/Utils/link-preview.js +135 -0
- package/src/Utils/logger.js +8 -0
- package/src/Utils/lt-hash.js +25 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +471 -0
- package/src/Utils/message-retry-manager.js +217 -0
- package/src/Utils/messages-media.js +843 -0
- package/src/Utils/messages.js +2817 -0
- package/src/Utils/meta-ai-msmsg.js +222 -0
- package/src/Utils/native-bridge.js +68 -0
- package/src/Utils/noise-handler.js +169 -0
- package/src/Utils/offline-node-processor.js +34 -0
- package/src/Utils/pre-key-manager.js +90 -0
- package/src/Utils/process-message.js +950 -0
- package/src/Utils/reporting-utils.js +261 -0
- package/src/Utils/session-pool.d.ts +14 -0
- package/src/Utils/session-pool.js +70 -0
- package/src/Utils/signal.js +217 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/sticker.d.ts +13 -0
- package/src/Utils/sticker.js +123 -0
- package/src/Utils/sync-action-utils.js +45 -0
- package/src/Utils/tc-token-utils.js +158 -0
- package/src/Utils/use-multi-file-auth-state.js +111 -0
- package/src/Utils/validate-connection.js +209 -0
- package/src/Utils/view-once-cache.d.ts +12 -0
- package/src/Utils/view-once-cache.js +63 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +342 -0
- package/src/WABinary/encode.js +225 -0
- package/src/WABinary/generic-utils.js +238 -0
- package/src/WABinary/index.js +34 -0
- package/src/WABinary/jid-utils.js +351 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39484 -0
- package/src/WAM/encode.js +149 -0
- package/src/WAM/index.js +32 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncQuery.js +126 -0
- package/src/WAUSync/USyncUser.js +50 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4152 -0
- package/{lib → src}/index.js +51 -49
- package/lib/Defaults/index.js +0 -195
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.js +0 -92
- package/lib/Signal/Group/group_cipher.js +0 -89
- package/lib/Signal/Group/index.js +0 -136
- package/lib/Signal/Group/keyhelper.js +0 -73
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.js +0 -50
- package/lib/Signal/Group/sender-key-record.js +0 -44
- package/lib/Signal/Group/sender-key-state.js +0 -97
- package/lib/Signal/Group/sender-message-key.js +0 -30
- package/lib/Signal/libsignal.js +0 -470
- package/lib/Signal/lid-mapping.js +0 -280
- package/lib/Socket/Client/index.js +0 -30
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/business.js +0 -414
- package/lib/Socket/chats.js +0 -2165
- package/lib/Socket/communities.js +0 -545
- package/lib/Socket/graphql.js +0 -863
- package/lib/Socket/groups.js +0 -685
- package/lib/Socket/index.js +0 -41
- package/lib/Socket/interactive-handler.js +0 -579
- package/lib/Socket/interop.js +0 -430
- package/lib/Socket/managed-account.js +0 -214
- package/lib/Socket/messages-recv.js +0 -3000
- package/lib/Socket/messages-send.js +0 -2155
- package/lib/Socket/mex.js +0 -47
- package/lib/Socket/newsletter.js +0 -814
- package/lib/Socket/privacy.js +0 -261
- package/lib/Socket/registration.js +0 -434
- package/lib/Socket/socket.js +0 -1074
- package/lib/Socket/username.js +0 -160
- package/lib/Store/index.js +0 -36
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.js +0 -488
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.js +0 -29
- package/lib/Types/Auth.js +0 -38
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.js +0 -4
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.js +0 -27
- package/lib/Types/LabelAssociation.js +0 -9
- package/lib/Types/Message.js +0 -95
- package/lib/Types/Newsletter.js +0 -152
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.js +0 -2
- package/lib/Types/State.js +0 -70
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.js +0 -55
- package/lib/Utils/auth-utils.js +0 -301
- package/lib/Utils/browser-utils.js +0 -114
- package/lib/Utils/business.js +0 -243
- package/lib/Utils/chat-utils.js +0 -1272
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/crypto.js +0 -125
- package/lib/Utils/decode-wa-message.js +0 -793
- package/lib/Utils/event-buffer.js +0 -583
- package/lib/Utils/generics.js +0 -617
- package/lib/Utils/group-history.js +0 -51
- package/lib/Utils/history.js +0 -244
- package/lib/Utils/identity-change-handler.js +0 -52
- package/lib/Utils/index.js +0 -53
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/link-preview.js +0 -138
- package/lib/Utils/logger.js +0 -9
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +0 -36
- package/lib/Utils/message-composer.js +0 -479
- package/lib/Utils/message-inspect.js +0 -393
- package/lib/Utils/message-retry-manager.js +0 -205
- package/lib/Utils/messages-media.js +0 -925
- package/lib/Utils/messages.js +0 -2482
- package/lib/Utils/meta-ai-msmsg.js +0 -122
- package/lib/Utils/noise-handler.js +0 -194
- package/lib/Utils/offline-node-processor.js +0 -37
- package/lib/Utils/pre-key-manager.js +0 -97
- package/lib/Utils/process-message.js +0 -1139
- package/lib/Utils/reporting-utils.js +0 -262
- package/lib/Utils/signal.js +0 -189
- package/lib/Utils/stanza-ack.js +0 -67
- package/lib/Utils/sync-action-utils.js +0 -51
- package/lib/Utils/tc-token-utils.js +0 -156
- package/lib/Utils/use-multi-file-auth-state.js +0 -137
- package/lib/Utils/validate-connection.js +0 -259
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/WABinary/constants.js +0 -1304
- package/lib/WABinary/decode.js +0 -377
- package/lib/WABinary/encode.js +0 -58
- package/lib/WABinary/generic-utils.js +0 -150
- package/lib/WABinary/index.js +0 -33
- package/lib/WABinary/jid-utils.js +0 -374
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.js +0 -13
- package/lib/WAM/constants.js +0 -39486
- package/lib/WAM/encode.js +0 -142
- package/lib/WAM/index.js +0 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/lib/WAUSync/Protocols/index.js +0 -40
- package/lib/WAUSync/USyncBackoff.js +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -204
- package/lib/WAUSync/USyncUser.js +0 -58
- package/lib/WAUSync/index.js +0 -32
- package/lib/antiban.js +0 -4391
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.imageToWebpSticker = exports.videoToWebpSticker = exports.addExifToWebp = void 0;
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const crypto = require('crypto');
|
|
8
|
+
const { exec } = require('child_process');
|
|
9
|
+
const addExifToWebp = async (webpBuffer, { packName = '', packPublisher = '', categories = [] } = {}) => {
|
|
10
|
+
const json = {
|
|
11
|
+
'sticker-pack-id': crypto.randomBytes(16).toString('hex'),
|
|
12
|
+
'sticker-pack-name': packName,
|
|
13
|
+
'sticker-pack-publisher': packPublisher,
|
|
14
|
+
emojis: categories.length ? categories : ['😀']
|
|
15
|
+
};
|
|
16
|
+
const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf-8');
|
|
17
|
+
const exifAttr = Buffer.from([
|
|
18
|
+
0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
|
|
19
|
+
0x00, 0x00, 0x00
|
|
20
|
+
]);
|
|
21
|
+
exifAttr.writeUIntLE(jsonBuffer.length, 14, 4);
|
|
22
|
+
const exifPayload = Buffer.concat([exifAttr, jsonBuffer]);
|
|
23
|
+
const pad = buf => (buf.length % 2 === 1 ? Buffer.concat([buf, Buffer.from([0x00])]) : buf);
|
|
24
|
+
const makeChunk = (tag, data) => {
|
|
25
|
+
const sizeField = Buffer.alloc(4);
|
|
26
|
+
sizeField.writeUInt32LE(data.length, 0);
|
|
27
|
+
return Buffer.concat([Buffer.from(tag, 'ascii'), sizeField, pad(data)]);
|
|
28
|
+
};
|
|
29
|
+
const exifChunk = makeChunk('EXIF', exifPayload);
|
|
30
|
+
if (webpBuffer.slice(0, 4).toString('ascii') !== 'RIFF' || webpBuffer.slice(8, 12).toString('ascii') !== 'WEBP') {
|
|
31
|
+
throw new Error('addExifToWebp expects a valid WebP buffer');
|
|
32
|
+
}
|
|
33
|
+
let offset = 12;
|
|
34
|
+
let vp8xChunk = null;
|
|
35
|
+
let vp8xOffset = -1;
|
|
36
|
+
const otherChunks = [];
|
|
37
|
+
while (offset < webpBuffer.length) {
|
|
38
|
+
const tag = webpBuffer.slice(offset, offset + 4).toString('ascii');
|
|
39
|
+
const size = webpBuffer.readUInt32LE(offset + 4);
|
|
40
|
+
const dataStart = offset + 8;
|
|
41
|
+
const dataEnd = dataStart + size;
|
|
42
|
+
const chunkTotal = 8 + size + (size % 2);
|
|
43
|
+
if (tag === 'VP8X') {
|
|
44
|
+
vp8xChunk = webpBuffer.slice(offset, offset + chunkTotal);
|
|
45
|
+
vp8xOffset = offset;
|
|
46
|
+
}
|
|
47
|
+
else if (tag !== 'EXIF') {
|
|
48
|
+
otherChunks.push(webpBuffer.slice(offset, offset + chunkTotal));
|
|
49
|
+
}
|
|
50
|
+
offset += chunkTotal;
|
|
51
|
+
}
|
|
52
|
+
let flags;
|
|
53
|
+
let canvasWidth;
|
|
54
|
+
let canvasHeight;
|
|
55
|
+
if (vp8xChunk) {
|
|
56
|
+
flags = vp8xChunk.readUInt8(8);
|
|
57
|
+
canvasWidth = vp8xChunk.readUIntLE(12, 3) + 1;
|
|
58
|
+
canvasHeight = vp8xChunk.readUIntLE(15, 3) + 1;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
flags = 0;
|
|
62
|
+
let sharp;
|
|
63
|
+
try {
|
|
64
|
+
sharp = require('sharp');
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw new Error('addExifToWebp needs the optional "sharp" dependency to read image dimensions');
|
|
68
|
+
}
|
|
69
|
+
const meta = await sharp(webpBuffer).metadata();
|
|
70
|
+
canvasWidth = meta.width;
|
|
71
|
+
canvasHeight = meta.height;
|
|
72
|
+
}
|
|
73
|
+
flags |= 0x08;
|
|
74
|
+
const vp8xData = Buffer.alloc(10);
|
|
75
|
+
vp8xData.writeUInt8(flags, 0);
|
|
76
|
+
vp8xData.writeUIntLE(canvasWidth - 1, 4, 3);
|
|
77
|
+
vp8xData.writeUIntLE(canvasHeight - 1, 7, 3);
|
|
78
|
+
const newVp8xChunk = makeChunk('VP8X', vp8xData);
|
|
79
|
+
const body = Buffer.concat([newVp8xChunk, ...otherChunks, exifChunk]);
|
|
80
|
+
const fileSize = Buffer.alloc(4);
|
|
81
|
+
fileSize.writeUInt32LE(4 + body.length, 0);
|
|
82
|
+
return Buffer.concat([Buffer.from('RIFF', 'ascii'), fileSize, Buffer.from('WEBP', 'ascii'), body]);
|
|
83
|
+
};
|
|
84
|
+
exports.addExifToWebp = addExifToWebp;
|
|
85
|
+
const imageToWebpSticker = async (imageBuffer, options = {}) => {
|
|
86
|
+
let sharp;
|
|
87
|
+
try {
|
|
88
|
+
sharp = require('sharp');
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error('imageToWebpSticker requires the optional "sharp" dependency to be installed');
|
|
92
|
+
}
|
|
93
|
+
const webp = await sharp(imageBuffer)
|
|
94
|
+
.resize(512, 512, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
|
95
|
+
.webp({ quality: options.quality ?? 80 })
|
|
96
|
+
.toBuffer();
|
|
97
|
+
return addExifToWebp(webp, options);
|
|
98
|
+
};
|
|
99
|
+
exports.imageToWebpSticker = imageToWebpSticker;
|
|
100
|
+
const videoToWebpSticker = async (videoBuffer, options = {}) => {
|
|
101
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xazbails-sticker-'));
|
|
102
|
+
const inputPath = path.join(tmpDir, 'input.mp4');
|
|
103
|
+
const outputPath = path.join(tmpDir, 'output.webp');
|
|
104
|
+
fs.writeFileSync(inputPath, videoBuffer);
|
|
105
|
+
const fps = options.fps ?? 10;
|
|
106
|
+
const seconds = options.seconds ?? 5;
|
|
107
|
+
const cmd = `ffmpeg -y -i ${inputPath} -t ${seconds} -vf ` +
|
|
108
|
+
`"fps=${fps},scale=512:512:force_original_aspect_ratio=decrease,` +
|
|
109
|
+
`pad=512:512:(ow-iw)/2:(oh-ih)/2:color=0x00000000,split[a][b];` +
|
|
110
|
+
`[a]palettegen=reserve_transparent=1[p];[b][p]paletteuse" ` +
|
|
111
|
+
`-loop 0 -preset default -an -vsync 0 ${outputPath}`;
|
|
112
|
+
try {
|
|
113
|
+
await new Promise((resolve, reject) => {
|
|
114
|
+
exec(cmd, err => (err ? reject(err) : resolve()));
|
|
115
|
+
});
|
|
116
|
+
const webp = fs.readFileSync(outputPath);
|
|
117
|
+
return await addExifToWebp(webp, options);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
exports.videoToWebpSticker = videoToWebpSticker;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.emitSyncActionResults = exports.processContactAction = void 0;
|
|
4
|
+
const WABinary_1 = require('../WABinary');
|
|
5
|
+
const processContactAction = (action, id, logger) => {
|
|
6
|
+
const results = [];
|
|
7
|
+
if (!id) {
|
|
8
|
+
logger?.warn({ hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid }, 'contactAction sync: missing id in index');
|
|
9
|
+
return results;
|
|
10
|
+
}
|
|
11
|
+
const lidJid = action.lidJid;
|
|
12
|
+
const idIsPn = (0, WABinary_1.isPnUser)(id);
|
|
13
|
+
const phoneNumber = idIsPn ? id : action.pnJid || undefined;
|
|
14
|
+
results.push({
|
|
15
|
+
event: 'contacts.upsert',
|
|
16
|
+
data: [
|
|
17
|
+
{
|
|
18
|
+
id,
|
|
19
|
+
name: action.fullName || action.firstName || action.username || undefined,
|
|
20
|
+
username: action.username || undefined,
|
|
21
|
+
lid: lidJid || undefined,
|
|
22
|
+
phoneNumber
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
if (lidJid && (0, WABinary_1.isLidUser)(lidJid) && idIsPn) {
|
|
27
|
+
results.push({
|
|
28
|
+
event: 'lid-mapping.update',
|
|
29
|
+
data: { lid: lidJid, pn: id }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
};
|
|
34
|
+
exports.processContactAction = processContactAction;
|
|
35
|
+
const emitSyncActionResults = (ev, results) => {
|
|
36
|
+
for (const result of results) {
|
|
37
|
+
if (result.event === 'contacts.upsert') {
|
|
38
|
+
ev.emit('contacts.upsert', result.data);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
ev.emit('lid-mapping.update', result.data);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.emitSyncActionResults = emitSyncActionResults;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.TC_TOKEN_INDEX_KEY = void 0;
|
|
4
|
+
exports.readTcTokenIndex = readTcTokenIndex;
|
|
5
|
+
exports.buildMergedTcTokenIndexWrite = buildMergedTcTokenIndexWrite;
|
|
6
|
+
exports.isTcTokenExpired = isTcTokenExpired;
|
|
7
|
+
exports.shouldSendNewTcToken = shouldSendNewTcToken;
|
|
8
|
+
exports.resolveTcTokenJid = resolveTcTokenJid;
|
|
9
|
+
exports.resolveIssuanceJid = resolveIssuanceJid;
|
|
10
|
+
exports.buildTcTokenFromJid = buildTcTokenFromJid;
|
|
11
|
+
exports.storeTcTokensFromIqResult = storeTcTokensFromIqResult;
|
|
12
|
+
const WABinary_1 = require('../WABinary');
|
|
13
|
+
const BOT_PHONE_REGEX = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
14
|
+
function isRegularUser(jid) {
|
|
15
|
+
if (!jid)
|
|
16
|
+
return false;
|
|
17
|
+
const user = jid.split('@')[0] ?? '';
|
|
18
|
+
if (user === '0')
|
|
19
|
+
return false;
|
|
20
|
+
if (BOT_PHONE_REGEX.test(user))
|
|
21
|
+
return false;
|
|
22
|
+
if ((0, WABinary_1.isJidMetaAI)(jid))
|
|
23
|
+
return false;
|
|
24
|
+
return !!((0, WABinary_1.isPnUser)(jid) ||
|
|
25
|
+
(0, WABinary_1.isLidUser)(jid) ||
|
|
26
|
+
(0, WABinary_1.isHostedPnUser)(jid) ||
|
|
27
|
+
(0, WABinary_1.isHostedLidUser)(jid) ||
|
|
28
|
+
jid.endsWith('@c.us'));
|
|
29
|
+
}
|
|
30
|
+
const TC_TOKEN_BUCKET_DURATION = 604800;
|
|
31
|
+
const TC_TOKEN_NUM_BUCKETS = 4;
|
|
32
|
+
exports.TC_TOKEN_INDEX_KEY = '__index';
|
|
33
|
+
async function readTcTokenIndex(keys) {
|
|
34
|
+
const data = await keys.get('tctoken', [exports.TC_TOKEN_INDEX_KEY]);
|
|
35
|
+
const entry = data[exports.TC_TOKEN_INDEX_KEY];
|
|
36
|
+
if (!entry?.token?.length)
|
|
37
|
+
return [];
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(Buffer.from(entry.token).toString());
|
|
40
|
+
if (!Array.isArray(parsed))
|
|
41
|
+
return [];
|
|
42
|
+
return parsed.filter(j => typeof j === 'string' && j.length > 0 && j !== exports.TC_TOKEN_INDEX_KEY);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function buildMergedTcTokenIndexWrite(keys, addedJids) {
|
|
49
|
+
const persisted = await readTcTokenIndex(keys);
|
|
50
|
+
const merged = new Set(persisted);
|
|
51
|
+
for (const jid of addedJids) {
|
|
52
|
+
if (jid && jid !== exports.TC_TOKEN_INDEX_KEY)
|
|
53
|
+
merged.add(jid);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
[exports.TC_TOKEN_INDEX_KEY]: { token: Buffer.from(JSON.stringify([...merged])) }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function isTcTokenExpired(timestamp) {
|
|
60
|
+
if (timestamp === null || timestamp === undefined)
|
|
61
|
+
return true;
|
|
62
|
+
const ts = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp;
|
|
63
|
+
if (isNaN(ts))
|
|
64
|
+
return true;
|
|
65
|
+
const now = Math.floor(Date.now() / 1000);
|
|
66
|
+
const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION);
|
|
67
|
+
const cutoffBucket = currentBucket - (TC_TOKEN_NUM_BUCKETS - 1);
|
|
68
|
+
const cutoffTimestamp = cutoffBucket * TC_TOKEN_BUCKET_DURATION;
|
|
69
|
+
return ts < cutoffTimestamp;
|
|
70
|
+
}
|
|
71
|
+
function shouldSendNewTcToken(senderTimestamp) {
|
|
72
|
+
if (senderTimestamp === undefined)
|
|
73
|
+
return true;
|
|
74
|
+
const now = Math.floor(Date.now() / 1000);
|
|
75
|
+
const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION);
|
|
76
|
+
const senderBucket = Math.floor(senderTimestamp / TC_TOKEN_BUCKET_DURATION);
|
|
77
|
+
return currentBucket > senderBucket;
|
|
78
|
+
}
|
|
79
|
+
async function resolveTcTokenJid(jid, getLIDForPN) {
|
|
80
|
+
if ((0, WABinary_1.isLidUser)(jid))
|
|
81
|
+
return jid;
|
|
82
|
+
const lid = await getLIDForPN(jid);
|
|
83
|
+
return lid ?? jid;
|
|
84
|
+
}
|
|
85
|
+
async function resolveIssuanceJid(jid, issueToLid, getLIDForPN, getPNForLID) {
|
|
86
|
+
if (issueToLid) {
|
|
87
|
+
if ((0, WABinary_1.isLidUser)(jid))
|
|
88
|
+
return jid;
|
|
89
|
+
const lid = await getLIDForPN(jid);
|
|
90
|
+
return lid ?? jid;
|
|
91
|
+
}
|
|
92
|
+
if (!(0, WABinary_1.isLidUser)(jid))
|
|
93
|
+
return jid;
|
|
94
|
+
if (getPNForLID) {
|
|
95
|
+
const pn = await getPNForLID(jid);
|
|
96
|
+
return pn ?? jid;
|
|
97
|
+
}
|
|
98
|
+
return jid;
|
|
99
|
+
}
|
|
100
|
+
async function buildTcTokenFromJid({ authState, jid, baseContent = [], getLIDForPN }) {
|
|
101
|
+
try {
|
|
102
|
+
const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
|
|
103
|
+
const tcTokenData = await authState.keys.get('tctoken', [storageJid]);
|
|
104
|
+
const entry = tcTokenData?.[storageJid];
|
|
105
|
+
const tcTokenBuffer = entry?.token;
|
|
106
|
+
if (!tcTokenBuffer?.length || isTcTokenExpired(entry?.timestamp)) {
|
|
107
|
+
if (tcTokenBuffer) {
|
|
108
|
+
const cleared = entry?.senderTimestamp !== undefined
|
|
109
|
+
? { token: Buffer.alloc(0), senderTimestamp: entry.senderTimestamp }
|
|
110
|
+
: null;
|
|
111
|
+
await authState.keys.set({ tctoken: { [storageJid]: cleared } });
|
|
112
|
+
}
|
|
113
|
+
return baseContent.length > 0 ? baseContent : undefined;
|
|
114
|
+
}
|
|
115
|
+
baseContent.push({
|
|
116
|
+
tag: 'tctoken',
|
|
117
|
+
attrs: {},
|
|
118
|
+
content: tcTokenBuffer
|
|
119
|
+
});
|
|
120
|
+
return baseContent;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
return baseContent.length > 0 ? baseContent : undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function storeTcTokensFromIqResult({ result, fallbackJid, keys, getLIDForPN, onNewJidStored }) {
|
|
127
|
+
const tokensNode = (0, WABinary_1.getBinaryNodeChild)(result, 'tokens');
|
|
128
|
+
if (!tokensNode)
|
|
129
|
+
return;
|
|
130
|
+
const tokenNodes = (0, WABinary_1.getBinaryNodeChildren)(tokensNode, 'token');
|
|
131
|
+
for (const tokenNode of tokenNodes) {
|
|
132
|
+
if (tokenNode.attrs.type !== 'trusted_contact' || !(tokenNode.content instanceof Uint8Array)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const rawJid = (0, WABinary_1.jidNormalizedUser)(fallbackJid || tokenNode.attrs.jid);
|
|
136
|
+
if (!isRegularUser(rawJid))
|
|
137
|
+
continue;
|
|
138
|
+
const storageJid = await resolveTcTokenJid(rawJid, getLIDForPN);
|
|
139
|
+
const existingTcData = await keys.get('tctoken', [storageJid]);
|
|
140
|
+
const existingEntry = existingTcData[storageJid];
|
|
141
|
+
const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
|
|
142
|
+
const incomingTs = tokenNode.attrs.t ? Number(tokenNode.attrs.t) : 0;
|
|
143
|
+
if (!incomingTs)
|
|
144
|
+
continue;
|
|
145
|
+
if (existingTs > 0 && existingTs > incomingTs)
|
|
146
|
+
continue;
|
|
147
|
+
await keys.set({
|
|
148
|
+
tctoken: {
|
|
149
|
+
[storageJid]: {
|
|
150
|
+
...existingEntry,
|
|
151
|
+
token: Buffer.from(tokenNode.content),
|
|
152
|
+
timestamp: tokenNode.attrs.t
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
onNewJidStored?.(storageJid);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require('async-mutex');
|
|
5
|
+
const promises_1 = require('fs/promises');
|
|
6
|
+
const path_1 = require('path');
|
|
7
|
+
const index_js_1 = require('../../WAProto/index.js');
|
|
8
|
+
const auth_utils_1 = require('./auth-utils');
|
|
9
|
+
const generics_1 = require('./generics');
|
|
10
|
+
const fileLocks = new Map();
|
|
11
|
+
const getFileLock = path => {
|
|
12
|
+
let mutex = fileLocks.get(path);
|
|
13
|
+
if (!mutex) {
|
|
14
|
+
mutex = new async_mutex_1.Mutex();
|
|
15
|
+
fileLocks.set(path, mutex);
|
|
16
|
+
}
|
|
17
|
+
return mutex;
|
|
18
|
+
};
|
|
19
|
+
const useMultiFileAuthState = async (folder) => {
|
|
20
|
+
const writeData = async (data, file) => {
|
|
21
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
22
|
+
const mutex = getFileLock(filePath);
|
|
23
|
+
return mutex.acquire().then(async (release) => {
|
|
24
|
+
try {
|
|
25
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
release();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const readData = async (file) => {
|
|
33
|
+
try {
|
|
34
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
|
+
const mutex = getFileLock(filePath);
|
|
36
|
+
return await mutex.acquire().then(async (release) => {
|
|
37
|
+
try {
|
|
38
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
39
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
release();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const removeData = async (file) => {
|
|
51
|
+
try {
|
|
52
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
53
|
+
const mutex = getFileLock(filePath);
|
|
54
|
+
return mutex.acquire().then(async (release) => {
|
|
55
|
+
try {
|
|
56
|
+
await (0, promises_1.unlink)(filePath);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
release();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
};
|
|
67
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
68
|
+
if (folderInfo) {
|
|
69
|
+
if (!folderInfo.isDirectory()) {
|
|
70
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
const fixFileName = file => file?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
77
|
+
const creds = (await readData('creds.json')) || (0, auth_utils_1.initAuthCreds)();
|
|
78
|
+
return {
|
|
79
|
+
state: {
|
|
80
|
+
creds,
|
|
81
|
+
keys: {
|
|
82
|
+
get: async (type, ids) => {
|
|
83
|
+
const data = {};
|
|
84
|
+
await Promise.all(ids.map(async (id) => {
|
|
85
|
+
let value = await readData(`${type}-${id}.json`);
|
|
86
|
+
if (type === 'app-state-sync-key' && value) {
|
|
87
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
88
|
+
}
|
|
89
|
+
data[id] = value;
|
|
90
|
+
}));
|
|
91
|
+
return data;
|
|
92
|
+
},
|
|
93
|
+
set: async (data) => {
|
|
94
|
+
const tasks = [];
|
|
95
|
+
for (const category in data) {
|
|
96
|
+
for (const id in data[category]) {
|
|
97
|
+
const value = data[category][id];
|
|
98
|
+
const file = `${category}-${id}.json`;
|
|
99
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
await Promise.all(tasks);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
saveCreds: async () => {
|
|
107
|
+
return writeData(creds, 'creds.json');
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.encodeSignedDeviceIdentity =
|
|
4
|
+
exports.configureSuccessfulPairing =
|
|
5
|
+
exports.generateRegistrationNode =
|
|
6
|
+
exports.generateLoginNode =
|
|
7
|
+
void 0;
|
|
8
|
+
const boom_1 = require('@hapi/boom');
|
|
9
|
+
const crypto_1 = require('crypto');
|
|
10
|
+
const Crypto_1 = require('./crypto');
|
|
11
|
+
const index_js_1 = require('../../WAProto/index.js');
|
|
12
|
+
const Defaults_1 = require('../Defaults');
|
|
13
|
+
const WABinary_1 = require('../WABinary');
|
|
14
|
+
const crypto_2 = require('./crypto');
|
|
15
|
+
const generics_1 = require('./generics');
|
|
16
|
+
const signal_1 = require('./signal');
|
|
17
|
+
const getUserAgent = config => {
|
|
18
|
+
return {
|
|
19
|
+
appVersion: {
|
|
20
|
+
primary: config.version[0],
|
|
21
|
+
secondary: config.version[1],
|
|
22
|
+
tertiary: config.version[2]
|
|
23
|
+
},
|
|
24
|
+
platform: index_js_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
25
|
+
releaseChannel: index_js_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
26
|
+
osVersion: '0.1',
|
|
27
|
+
device: 'Desktop',
|
|
28
|
+
osBuildNumber: '0.1',
|
|
29
|
+
localeLanguageIso6391: 'en',
|
|
30
|
+
mnc: '000',
|
|
31
|
+
mcc: '000',
|
|
32
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const PLATFORM_MAP = {
|
|
36
|
+
'Mac OS': index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
37
|
+
Windows: index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
38
|
+
};
|
|
39
|
+
const getWebInfo = config => {
|
|
40
|
+
let webSubPlatform = index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
41
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
|
|
42
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
43
|
+
}
|
|
44
|
+
return { webSubPlatform };
|
|
45
|
+
};
|
|
46
|
+
const getClientPayload = config => {
|
|
47
|
+
const payload = {
|
|
48
|
+
connectType: index_js_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
49
|
+
connectReason: index_js_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
50
|
+
userAgent: getUserAgent(config)
|
|
51
|
+
};
|
|
52
|
+
payload.webInfo = getWebInfo(config);
|
|
53
|
+
return payload;
|
|
54
|
+
};
|
|
55
|
+
const generateLoginNode = (userJid, config, creds) => {
|
|
56
|
+
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
57
|
+
const effectiveDevice = config.masqueradeAsPrimary ? 0 : device;
|
|
58
|
+
const payload = {
|
|
59
|
+
...getClientPayload(config),
|
|
60
|
+
passive: !config.masqueradeAsPrimary,
|
|
61
|
+
pull: !config.masqueradeAsPrimary,
|
|
62
|
+
username: +user,
|
|
63
|
+
device: effectiveDevice,
|
|
64
|
+
lidDbMigrated: false
|
|
65
|
+
};
|
|
66
|
+
if (creds?.interopData?.accountId) {
|
|
67
|
+
payload.interopData = {
|
|
68
|
+
accountId: creds.interopData.accountId,
|
|
69
|
+
token: creds.interopData.token,
|
|
70
|
+
enableReadReceipts: creds.interopData.enableReadReceipts ?? true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return index_js_1.proto.ClientPayload.fromObject(payload);
|
|
74
|
+
};
|
|
75
|
+
exports.generateLoginNode = generateLoginNode;
|
|
76
|
+
const getPlatformType = platform => {
|
|
77
|
+
const platformType = platform.toUpperCase();
|
|
78
|
+
return index_js_1.proto.DeviceProps.PlatformType[platformType] || index_js_1.proto.DeviceProps.PlatformType.CHROME;
|
|
79
|
+
};
|
|
80
|
+
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
81
|
+
const appVersionBuf = Buffer.from(Crypto_1.md5(Buffer.from(config.version.join('.'))));
|
|
82
|
+
const companion = {
|
|
83
|
+
os: config.browser[0],
|
|
84
|
+
platformType: getPlatformType(config.browser[1]),
|
|
85
|
+
requireFullSync: config.syncFullHistory,
|
|
86
|
+
historySyncConfig: {
|
|
87
|
+
storageQuotaMb: 10240,
|
|
88
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
89
|
+
recentSyncDaysLimit: undefined,
|
|
90
|
+
supportCallLogHistory: false,
|
|
91
|
+
supportBotUserAgentChatHistory: true,
|
|
92
|
+
supportCagReactionsAndPolls: true,
|
|
93
|
+
supportBizHostedMsg: true,
|
|
94
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
95
|
+
supportHostedGroupMsg: true,
|
|
96
|
+
supportFbidBotChatHistory: true,
|
|
97
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
98
|
+
supportMessageAssociation: true,
|
|
99
|
+
supportGroupHistory: false,
|
|
100
|
+
onDemandReady: undefined,
|
|
101
|
+
supportGuestChat: undefined
|
|
102
|
+
},
|
|
103
|
+
version: {
|
|
104
|
+
primary: 10,
|
|
105
|
+
secondary: 15,
|
|
106
|
+
tertiary: 7
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const companionProto = index_js_1.proto.DeviceProps.encode(companion).finish();
|
|
110
|
+
const registerPayload = {
|
|
111
|
+
...getClientPayload(config),
|
|
112
|
+
passive: false,
|
|
113
|
+
pull: false,
|
|
114
|
+
devicePairingData: {
|
|
115
|
+
buildHash: appVersionBuf,
|
|
116
|
+
deviceProps: companionProto,
|
|
117
|
+
eRegid: (0, generics_1.encodeBigEndian)(registrationId),
|
|
118
|
+
eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
|
|
119
|
+
eIdent: signedIdentityKey.public,
|
|
120
|
+
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
121
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
122
|
+
eSkeySig: signedPreKey.signature
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return index_js_1.proto.ClientPayload.fromObject(registerPayload);
|
|
126
|
+
};
|
|
127
|
+
exports.generateRegistrationNode = generateRegistrationNode;
|
|
128
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
129
|
+
const msgId = stanza.attrs.id;
|
|
130
|
+
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
131
|
+
const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
132
|
+
const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
133
|
+
const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
134
|
+
const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
135
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
136
|
+
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
137
|
+
}
|
|
138
|
+
const bizName = businessNode?.attrs.name;
|
|
139
|
+
const jid = deviceNode.attrs.jid;
|
|
140
|
+
const lid = deviceNode.attrs.lid;
|
|
141
|
+
const { details, hmac, accountType } = index_js_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
142
|
+
let hmacPrefix = Buffer.from([]);
|
|
143
|
+
if (accountType !== undefined && accountType === index_js_1.proto.ADVEncryptionType.HOSTED) {
|
|
144
|
+
hmacPrefix = Defaults_1.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
145
|
+
}
|
|
146
|
+
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
147
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
148
|
+
throw new boom_1.Boom('Invalid account signature');
|
|
149
|
+
}
|
|
150
|
+
const account = index_js_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
151
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
152
|
+
const deviceIdentity = index_js_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
153
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === index_js_1.proto.ADVEncryptionType.HOSTED
|
|
154
|
+
? Defaults_1.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
155
|
+
: Defaults_1.WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
156
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
157
|
+
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
158
|
+
throw new boom_1.Boom('Failed to verify account signature');
|
|
159
|
+
}
|
|
160
|
+
const deviceMsg = Buffer.concat([
|
|
161
|
+
Defaults_1.WA_ADV_DEVICE_SIG_PREFIX,
|
|
162
|
+
deviceDetails,
|
|
163
|
+
signedIdentityKey.public,
|
|
164
|
+
accountSignatureKey
|
|
165
|
+
]);
|
|
166
|
+
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
167
|
+
const identity = (0, signal_1.createSignalIdentity)(lid, accountSignatureKey);
|
|
168
|
+
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
169
|
+
const reply = {
|
|
170
|
+
tag: 'iq',
|
|
171
|
+
attrs: {
|
|
172
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
173
|
+
type: 'result',
|
|
174
|
+
id: msgId
|
|
175
|
+
},
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
tag: 'pair-device-sign',
|
|
179
|
+
attrs: {},
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
tag: 'device-identity',
|
|
183
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
184
|
+
content: accountEnc
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
};
|
|
190
|
+
const authUpdate = {
|
|
191
|
+
account,
|
|
192
|
+
me: { id: jid, name: bizName, lid },
|
|
193
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
194
|
+
platform: platformNode?.attrs.name
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
creds: authUpdate,
|
|
198
|
+
reply
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
202
|
+
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
203
|
+
account = { ...account };
|
|
204
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
205
|
+
account.accountSignatureKey = null;
|
|
206
|
+
}
|
|
207
|
+
return index_js_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
208
|
+
};
|
|
209
|
+
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AutoCacheViewOnceOptions {
|
|
2
|
+
cacheDir?: string;
|
|
3
|
+
logger?: any;
|
|
4
|
+
onCached?: (info: {
|
|
5
|
+
id: string;
|
|
6
|
+
jid: string;
|
|
7
|
+
filePath: string;
|
|
8
|
+
type: string;
|
|
9
|
+
}) => void;
|
|
10
|
+
}
|
|
11
|
+
export function getViewOnceContent(message: any): Record<string, any> | null;
|
|
12
|
+
export function autoCacheViewOnceMedia(sock: any, options?: AutoCacheViewOnceOptions): () => void;
|