@mamans2973/maman 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1275 -2
- package/WAProto/index.d.ts +37016 -0
- package/WAProto/index.js +2972 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/engine-requirements.js +1 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +51 -0
- package/lib/Defaults/index.js +10 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +9 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +15 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +4 -0
- package/lib/Socket/business.d.ts +146 -0
- package/lib/Socket/business.js +8 -0
- package/lib/Socket/chats.d.ts +85 -0
- package/lib/Socket/chats.js +29 -0
- package/lib/Socket/groups.d.ts +124 -0
- package/lib/Socket/groups.js +14 -0
- package/lib/Socket/index.d.ts +146 -0
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +135 -0
- package/lib/Socket/messages-recv.js +39 -0
- package/lib/Socket/messages-send.d.ts +130 -0
- package/lib/Socket/messages-send.js +26 -0
- package/lib/Socket/socket.d.ts +42 -0
- package/lib/Socket/socket.js +25 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +3 -0
- package/lib/Types/Auth.d.ts +103 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +112 -0
- package/lib/Types/Chat.js +1 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +58 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +46 -0
- package/lib/Types/Label.js +3 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +1 -0
- package/lib/Types/Message.d.ts +267 -0
- package/lib/Types/Message.js +1 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +121 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +1 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +63 -0
- package/lib/Types/index.js +4 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +8 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +3 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +14 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +36 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +11 -0
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +9 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +19 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/generics.js +22 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +7 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +5 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/logger.js +1 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +3 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +1 -0
- package/lib/Utils/messages-media.d.ts +103 -0
- package/lib/Utils/messages-media.js +35 -0
- package/lib/Utils/messages.d.ts +75 -0
- package/lib/Utils/messages.js +43 -0
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/noise-handler.js +6 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +19 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +10 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +5 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/Utils/validate-connection.js +10 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +6 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +9 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +9 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +7 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +2 -0
- package/lib/WABinary/jid-utils.d.ts +35 -0
- package/lib/WABinary/jid-utils.js +5 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +1 -0
- package/lib/WAM/constants.d.ts +39 -0
- package/lib/WAM/constants.js +492 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +7 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +2 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +3 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +4 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +2 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +4 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +1 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +2 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +3 -0
- package/package.json +94 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const SenderChainKey = require('./sender_chain_key');
|
|
2
|
+
const SenderMessageKey = require('./sender_message_key');
|
|
3
|
+
|
|
4
|
+
const protobufs = require('./protobufs');
|
|
5
|
+
|
|
6
|
+
class SenderKeyState {
|
|
7
|
+
MAX_MESSAGE_KEYS = 2000;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
id = null,
|
|
11
|
+
iteration = null,
|
|
12
|
+
chainKey = null,
|
|
13
|
+
signatureKeyPair = null,
|
|
14
|
+
signatureKeyPublic = null,
|
|
15
|
+
signatureKeyPrivate = null,
|
|
16
|
+
senderKeyStateStructure = null
|
|
17
|
+
) {
|
|
18
|
+
if (senderKeyStateStructure) {
|
|
19
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
20
|
+
} else {
|
|
21
|
+
if (signatureKeyPair) {
|
|
22
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
23
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
27
|
+
this.senderKeyStateStructure = protobufs.SenderKeyStateStructure.create();
|
|
28
|
+
const senderChainKeyStructure = protobufs.SenderChainKey.create();
|
|
29
|
+
senderChainKeyStructure.iteration = iteration;
|
|
30
|
+
senderChainKeyStructure.seed = chainKey;
|
|
31
|
+
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
32
|
+
|
|
33
|
+
const signingKeyStructure = protobufs.SenderSigningKey.create();
|
|
34
|
+
signingKeyStructure.public =
|
|
35
|
+
typeof signatureKeyPublic === 'string' ?
|
|
36
|
+
Buffer.from(signatureKeyPublic, 'base64') :
|
|
37
|
+
signatureKeyPublic;
|
|
38
|
+
if (signatureKeyPrivate) {
|
|
39
|
+
signingKeyStructure.private =
|
|
40
|
+
typeof signatureKeyPrivate === 'string' ?
|
|
41
|
+
Buffer.from(signatureKeyPrivate, 'base64') :
|
|
42
|
+
signatureKeyPrivate;
|
|
43
|
+
}
|
|
44
|
+
this.senderKeyStateStructure.senderKeyId = id;
|
|
45
|
+
this.senderChainKey = senderChainKeyStructure;
|
|
46
|
+
this.senderKeyStateStructure.senderSigningKey = signingKeyStructure;
|
|
47
|
+
}
|
|
48
|
+
this.senderKeyStateStructure.senderMessageKeys =
|
|
49
|
+
this.senderKeyStateStructure.senderMessageKeys || [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
SenderKeyState(senderKeyStateStructure) {
|
|
53
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getKeyId() {
|
|
57
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getSenderChainKey() {
|
|
61
|
+
return new SenderChainKey(
|
|
62
|
+
this.senderKeyStateStructure.senderChainKey.iteration,
|
|
63
|
+
this.senderKeyStateStructure.senderChainKey.seed
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setSenderChainKey(chainKey) {
|
|
68
|
+
const senderChainKeyStructure = protobufs.SenderChainKey.create({
|
|
69
|
+
iteration: chainKey.getIteration(),
|
|
70
|
+
seed: chainKey.getSeed(),
|
|
71
|
+
});
|
|
72
|
+
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getSigningKeyPublic() {
|
|
76
|
+
return typeof this.senderKeyStateStructure.senderSigningKey.public === 'string' ?
|
|
77
|
+
Buffer.from(this.senderKeyStateStructure.senderSigningKey.public, 'base64') :
|
|
78
|
+
this.senderKeyStateStructure.senderSigningKey.public;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getSigningKeyPrivate() {
|
|
82
|
+
return typeof this.senderKeyStateStructure.senderSigningKey.private === 'string' ?
|
|
83
|
+
Buffer.from(this.senderKeyStateStructure.senderSigningKey.private, 'base64') :
|
|
84
|
+
this.senderKeyStateStructure.senderSigningKey.private;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
hasSenderMessageKey(iteration) {
|
|
88
|
+
const list = this.senderKeyStateStructure.senderMessageKeys;
|
|
89
|
+
for (let o = 0; o < list.length; o++) {
|
|
90
|
+
const senderMessageKey = list[o];
|
|
91
|
+
if (senderMessageKey.iteration === iteration) return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
addSenderMessageKey(senderMessageKey) {
|
|
97
|
+
const senderMessageKeyStructure = protobufs.SenderKeyStateStructure.create({
|
|
98
|
+
iteration: senderMessageKey.getIteration(),
|
|
99
|
+
seed: senderMessageKey.getSeed(),
|
|
100
|
+
});
|
|
101
|
+
this.senderKeyStateStructure.senderMessageKeys.push(senderMessageKeyStructure);
|
|
102
|
+
|
|
103
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
104
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
removeSenderMessageKey(iteration) {
|
|
109
|
+
let result = null;
|
|
110
|
+
|
|
111
|
+
this.senderKeyStateStructure.senderMessageKeys = this.senderKeyStateStructure.senderMessageKeys.filter(
|
|
112
|
+
senderMessageKey => {
|
|
113
|
+
if (senderMessageKey.iteration === iteration) result = senderMessageKey;
|
|
114
|
+
return senderMessageKey.iteration !== iteration;
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (result != null) {
|
|
119
|
+
return new SenderMessageKey(result.iteration, result.seed);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getStructure() {
|
|
125
|
+
return this.senderKeyStateStructure;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = SenderKeyState;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { deriveSecrets } = require('libsignal/src/crypto');
|
|
2
|
+
class SenderMessageKey {
|
|
3
|
+
iteration = 0;
|
|
4
|
+
|
|
5
|
+
iv = Buffer.alloc(0);
|
|
6
|
+
|
|
7
|
+
cipherKey = Buffer.alloc(0);
|
|
8
|
+
|
|
9
|
+
seed = Buffer.alloc(0);
|
|
10
|
+
|
|
11
|
+
constructor(iteration, seed) {
|
|
12
|
+
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
13
|
+
const keys = new Uint8Array(32);
|
|
14
|
+
keys.set(new Uint8Array(derivative[0].slice(16)));
|
|
15
|
+
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
16
|
+
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
17
|
+
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
+
|
|
19
|
+
this.iteration = iteration;
|
|
20
|
+
this.seed = seed;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getIteration() {
|
|
24
|
+
return this.iteration;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getIv() {
|
|
28
|
+
return this.iv;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getCipherKey() {
|
|
32
|
+
return this.cipherKey;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getSeed() {
|
|
36
|
+
return this.seed;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports = SenderMessageKey;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const major=parseInt(process.versions.node.split(".")[0],10);20>major&&(console.error("\n\u274c This package requires Node.js 20+ to run reliably.\n"+` You are using Node.js ${process.versions.node}.\n`+" Please upgrade to Node.js 20+ to proceed.\n"),process.exit(1));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
import type { MediaType, SocketConfig } from '../Types';
|
|
3
|
+
export declare const UNAUTHORIZED_CODES: number[];
|
|
4
|
+
export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
5
|
+
export declare const DEF_CALLBACK_PREFIX = "CB:";
|
|
6
|
+
export declare const DEF_TAG_PREFIX = "TAG:";
|
|
7
|
+
export declare const PHONE_CONNECTION_CB = "CB:Pong";
|
|
8
|
+
export declare const WA_DEFAULT_EPHEMERAL: number;
|
|
9
|
+
export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
|
|
10
|
+
export declare const DICT_VERSION = 2;
|
|
11
|
+
export declare const KEY_BUNDLE_TYPE: Buffer<ArrayBuffer>;
|
|
12
|
+
export declare const NOISE_WA_HEADER: Buffer<ArrayBuffer>;
|
|
13
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
14
|
+
export declare const URL_REGEX: RegExp;
|
|
15
|
+
export declare const WA_CERT_DETAILS: {
|
|
16
|
+
SERIAL: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[];
|
|
19
|
+
export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig;
|
|
20
|
+
export declare const MEDIA_PATH_MAP: {
|
|
21
|
+
[T in MediaType]?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
24
|
+
audio: string;
|
|
25
|
+
document: string;
|
|
26
|
+
gif: string;
|
|
27
|
+
image: string;
|
|
28
|
+
ppic: string;
|
|
29
|
+
product: string;
|
|
30
|
+
ptt: string;
|
|
31
|
+
sticker: string;
|
|
32
|
+
video: string;
|
|
33
|
+
'thumbnail-document': string;
|
|
34
|
+
'thumbnail-image': string;
|
|
35
|
+
'thumbnail-video': string;
|
|
36
|
+
'thumbnail-link': string;
|
|
37
|
+
'md-msg-hist': string;
|
|
38
|
+
'md-app-state': string;
|
|
39
|
+
'product-catalog-image': string;
|
|
40
|
+
'payment-bg-image': string;
|
|
41
|
+
ptv: string;
|
|
42
|
+
};
|
|
43
|
+
export declare const MEDIA_KEYS: MediaType[];
|
|
44
|
+
export declare const MIN_PREKEY_COUNT = 5;
|
|
45
|
+
export declare const INITIAL_PREKEY_COUNT = 30;
|
|
46
|
+
export declare const DEFAULT_CACHE_TTLS: {
|
|
47
|
+
SIGNAL_STORE: number;
|
|
48
|
+
MSG_RETRY: number;
|
|
49
|
+
CALL_OFFER: number;
|
|
50
|
+
USER_DEVICES: number;
|
|
51
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __importDefault=this&&this.__importDefault||function(a){return a&&a.__esModule?a:{"default":a}};Object.defineProperty(exports,"__esModule",{value:!0});
|
|
2
|
+
exports.DEFAULT_CACHE_TTLS=exports.INITIAL_PREKEY_COUNT=exports.MIN_PREKEY_COUNT=exports.MEDIA_KEYS=exports.MEDIA_HKDF_KEY_MAPPING=exports.MEDIA_PATH_MAP=exports.DEFAULT_CONNECTION_CONFIG=exports.PROCESSABLE_HISTORY_TYPES=exports.WA_CERT_DETAILS=exports.URL_REGEX=exports.NOISE_WA_HEADER=exports.KEY_BUNDLE_TYPE=exports.DICT_VERSION=exports.NOISE_MODE=exports.WA_DEFAULT_EPHEMERAL=exports.PHONE_CONNECTION_CB=exports.DEF_TAG_PREFIX=exports.DEF_CALLBACK_PREFIX=exports.DEFAULT_ORIGIN=exports.UNAUTHORIZED_CODES=
|
|
3
|
+
void 0;const WAProto_1=require("../../WAProto"),libsignal_1=require("../Signal/libsignal"),Utils_1=require("../Utils"),logger_1=__importDefault(require("../Utils/logger")),baileys_version_json_1=require("./baileys-version.json");exports.UNAUTHORIZED_CODES=[401,403,419];exports.DEFAULT_ORIGIN="https://web.whatsapp.com";exports.DEF_CALLBACK_PREFIX="CB:";exports.DEF_TAG_PREFIX="TAG:";exports.PHONE_CONNECTION_CB="CB:Pong";exports.WA_DEFAULT_EPHEMERAL=604800;exports.NOISE_MODE="Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
|
|
4
|
+
exports.DICT_VERSION=2;exports.KEY_BUNDLE_TYPE=Buffer.from([5]);exports.NOISE_WA_HEADER=Buffer.from([87,65,6,exports.DICT_VERSION]);exports.URL_REGEX=/https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;exports.WA_CERT_DETAILS={SERIAL:0};
|
|
5
|
+
exports.PROCESSABLE_HISTORY_TYPES=[WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND];
|
|
6
|
+
exports.DEFAULT_CONNECTION_CONFIG={version:baileys_version_json_1.version,browser:Utils_1.Browsers.ubuntu("Chrome"),waWebSocketUrl:"wss://web.whatsapp.com/ws/chat",connectTimeoutMs:2E4,keepAliveIntervalMs:3E4,logger:logger_1.default.child({class:"baileys"}),emitOwnEvents:!0,defaultQueryTimeoutMs:6E4,customUploadHosts:[],retryRequestDelayMs:250,maxMsgRetryCount:5,fireInitQueries:!0,auth:void 0,markOnlineOnConnect:!0,syncFullHistory:!1,patchMessageBeforeSending:a=>a,shouldSyncHistoryMessage:()=>!0,
|
|
7
|
+
shouldIgnoreJid:()=>!1,linkPreviewImageThumbnailWidth:192,transactionOpts:{maxCommitRetries:10,delayBetweenTriesMs:3E3},generateHighQualityLinkPreview:!1,options:{},appStateMacVerification:{patch:!1,snapshot:!1},countryCode:"US",getMessage:async()=>{},cachedGroupMetadata:async()=>{},makeSignalRepository:libsignal_1.makeLibSignalRepository};
|
|
8
|
+
exports.MEDIA_PATH_MAP={image:"/mms/image",video:"/mms/video",document:"/mms/document",audio:"/mms/audio",sticker:"/mms/image","thumbnail-link":"/mms/image","product-catalog-image":"/product/image","md-app-state":"","md-msg-hist":"/mms/md-app-state"};
|
|
9
|
+
exports.MEDIA_HKDF_KEY_MAPPING={audio:"Audio",document:"Document",gif:"Video",image:"Image",ppic:"",product:"Image",ptt:"Audio",sticker:"Image",video:"Video","thumbnail-document":"Document Thumbnail","thumbnail-image":"Image Thumbnail","thumbnail-video":"Video Thumbnail","thumbnail-link":"Link Thumbnail","md-msg-hist":"History","md-app-state":"App State","product-catalog-image":"","payment-bg-image":"Payment Background",ptv:"Video"};exports.MEDIA_KEYS=Object.keys(exports.MEDIA_PATH_MAP);
|
|
10
|
+
exports.MIN_PREKEY_COUNT=5;exports.INITIAL_PREKEY_COUNT=30;exports.DEFAULT_CACHE_TTLS={SIGNAL_STORE:300,MSG_RETRY:3600,CALL_OFFER:300,USER_DEVICES:300};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,b,a,c){void 0===c&&(c=a);var d=Object.getOwnPropertyDescriptor(b,a);if(!d||("get"in d?!b.__esModule:d.writable||d.configurable))d={enumerable:!0,get:function(){return b[a]}};Object.defineProperty(e,c,d)}:function(e,b,a,c){void 0===c&&(c=a);e[c]=b[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,b){Object.defineProperty(e,"default",{enumerable:!0,value:b})}:function(e,b){e["default"]=b}),__importStar=
|
|
2
|
+
this&&this.__importStar||function(){var e=function(b){e=Object.getOwnPropertyNames||function(a){var c=[],d;for(d in a)Object.prototype.hasOwnProperty.call(a,d)&&(c[c.length]=d);return c};return e(b)};return function(b){if(b&&b.__esModule)return b;var a={};if(null!=b)for(var c=e(b),d=0;d<c.length;d++)"default"!==c[d]&&__createBinding(a,b,c[d]);__setModuleDefault(a,b);return a}}();Object.defineProperty(exports,"__esModule",{value:!0});exports.makeLibSignalRepository=makeLibSignalRepository;
|
|
3
|
+
const libsignal=__importStar(require("libsignal")),WASignalGroup_1=require("../../WASignalGroup"),Utils_1=require("../Utils"),WABinary_1=require("../WABinary");
|
|
4
|
+
function makeLibSignalRepository(e){const b=signalStorage(e);return{decryptGroupMessage({group:a,authorJid:c,msg:d}){a=jidToSignalSenderKeyName(a,c);return(new WASignalGroup_1.GroupCipher(b,a)).decrypt(d)},async processSenderKeyDistributionMessage({item:a,authorJid:c}){const d=new WASignalGroup_1.GroupSessionBuilder(b);c=jidToSignalSenderKeyName(a.groupId,c);a=new WASignalGroup_1.SenderKeyDistributionMessage(null,null,null,null,a.axolotlSenderKeyDistributionMessage);const {[c]:f}=await e.keys.get("sender-key",
|
|
5
|
+
[c]);f||await b.storeSenderKey(c,new WASignalGroup_1.SenderKeyRecord);await d.process(c,a)},async decryptMessage({jid:a,type:c,ciphertext:d}){a=jidToSignalProtocolAddress(a);a=new libsignal.SessionCipher(b,a);let f;switch(c){case "pkmsg":f=await a.decryptPreKeyWhisperMessage(d);break;case "msg":f=await a.decryptWhisperMessage(d)}return f},async encryptMessage({jid:a,data:c}){a=jidToSignalProtocolAddress(a);a=new libsignal.SessionCipher(b,a);const {type:d,body:f}=await a.encrypt(c);return{type:3===
|
|
6
|
+
d?"pkmsg":"msg",ciphertext:Buffer.from(f,"binary")}},async encryptGroupMessage({group:a,meId:c,data:d}){a=jidToSignalSenderKeyName(a,c);c=new WASignalGroup_1.GroupSessionBuilder(b);const {[a]:f}=await e.keys.get("sender-key",[a]);f||await b.storeSenderKey(a,new WASignalGroup_1.SenderKeyRecord);c=await c.create(a);return{ciphertext:await (new WASignalGroup_1.GroupCipher(b,a)).encrypt(d),senderKeyDistributionMessage:c.serialize()}},async injectE2ESession({jid:a,session:c}){await (new libsignal.SessionBuilder(b,
|
|
7
|
+
jidToSignalProtocolAddress(a))).initOutgoing(c)},jidToSignalProtocolAddress(a){return jidToSignalProtocolAddress(a).toString()}}}const jidToSignalProtocolAddress=e=>{const {user:b,device:a}=(0,WABinary_1.jidDecode)(e);return new libsignal.ProtocolAddress(b,a||0)},jidToSignalSenderKeyName=(e,b)=>(new WASignalGroup_1.SenderKeyName(e,jidToSignalProtocolAddress(b))).toString();
|
|
8
|
+
function signalStorage({creds:e,keys:b}){return{loadSession:async a=>{({[a]:a}=await b.get("session",[a]));if(a)return libsignal.SessionRecord.deserialize(a)},storeSession:async(a,c)=>{await b.set({session:{[a]:c.serialize()}})},isTrustedIdentity:()=>!0,loadPreKey:async a=>{a=a.toString();({[a]:a}=await b.get("pre-key",[a]));if(a)return{privKey:Buffer.from(a.private),pubKey:Buffer.from(a.public)}},removePreKey:a=>b.set({"pre-key":{[a]:null}}),loadSignedPreKey:()=>{const a=e.signedPreKey;return{privKey:Buffer.from(a.keyPair.private),
|
|
9
|
+
pubKey:Buffer.from(a.keyPair.public)}},loadSenderKey:async a=>{({[a]:a}=await b.get("sender-key",[a]));if(a)return new WASignalGroup_1.SenderKeyRecord(a)},storeSenderKey:async(a,c)=>{await b.set({"sender-key":{[a]:c.serialize()}})},getOurRegistrationId:()=>e.registrationId,getOurIdentity:()=>{const {signedIdentityKey:a}=e;return{privKey:Buffer.from(a.private),pubKey:(0,Utils_1.generateSignalPubKey)(a.public)}}}};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(d,b,a,c){void 0===c&&(c=a);var e=Object.getOwnPropertyDescriptor(b,a);if(!e||("get"in e?!b.__esModule:e.writable||e.configurable))e={enumerable:!0,get:function(){return b[a]}};Object.defineProperty(d,c,e)}:function(d,b,a,c){void 0===c&&(c=a);d[c]=b[a]}),__exportStar=this&&this.__exportStar||function(d,b){for(var a in d)"default"===a||Object.prototype.hasOwnProperty.call(b,a)||__createBinding(b,d,a)};
|
|
2
|
+
Object.defineProperty(exports,"__esModule",{value:!0});__exportStar(require("./types"),exports);__exportStar(require("./websocket"),exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { URL } from 'url';
|
|
3
|
+
import { SocketConfig } from '../../Types';
|
|
4
|
+
export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
5
|
+
url: URL;
|
|
6
|
+
config: SocketConfig;
|
|
7
|
+
abstract get isOpen(): boolean;
|
|
8
|
+
abstract get isClosed(): boolean;
|
|
9
|
+
abstract get isClosing(): boolean;
|
|
10
|
+
abstract get isConnecting(): boolean;
|
|
11
|
+
constructor(url: URL, config: SocketConfig);
|
|
12
|
+
abstract connect(): Promise<void>;
|
|
13
|
+
abstract close(): Promise<void>;
|
|
14
|
+
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});exports.AbstractSocketClient=void 0;const events_1=require("events");class AbstractSocketClient extends events_1.EventEmitter{constructor(a,b){super();this.url=a;this.config=b;this.setMaxListeners(0)}}exports.AbstractSocketClient=AbstractSocketClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { AbstractSocketClient } from './types';
|
|
3
|
+
export declare class WebSocketClient extends AbstractSocketClient {
|
|
4
|
+
protected socket: WebSocket | null;
|
|
5
|
+
get isOpen(): boolean;
|
|
6
|
+
get isClosed(): boolean;
|
|
7
|
+
get isClosing(): boolean;
|
|
8
|
+
get isConnecting(): boolean;
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var __importDefault=this&&this.__importDefault||function(a){return a&&a.__esModule?a:{"default":a}};Object.defineProperty(exports,"__esModule",{value:!0});exports.WebSocketClient=void 0;const ws_1=__importDefault(require("ws")),Defaults_1=require("../../Defaults"),types_1=require("./types");
|
|
2
|
+
class WebSocketClient extends types_1.AbstractSocketClient{constructor(){super(...arguments);this.socket=null}get isOpen(){var a;return(null===(a=this.socket)||void 0===a?void 0:a.readyState)===ws_1.default.OPEN}get isClosed(){var a;return null===this.socket||(null===(a=this.socket)||void 0===a?void 0:a.readyState)===ws_1.default.CLOSED}get isClosing(){var a;return null===this.socket||(null===(a=this.socket)||void 0===a?void 0:a.readyState)===ws_1.default.CLOSING}get isConnecting(){var a;return(null===
|
|
3
|
+
(a=this.socket)||void 0===a?void 0:a.readyState)===ws_1.default.CONNECTING}async connect(){var a,c;if(!this.socket){this.socket=new ws_1.default(this.url,{origin:Defaults_1.DEFAULT_ORIGIN,headers:null===(a=this.config.options)||void 0===a?void 0:a.headers,handshakeTimeout:this.config.connectTimeoutMs,timeout:this.config.connectTimeoutMs,agent:this.config.agent});this.socket.setMaxListeners(0);a="close error upgrade message open ping pong unexpected-response".split(" ");for(const b of a)null===(c=
|
|
4
|
+
this.socket)||void 0===c||c.on(b,(...d)=>this.emit(b,...d))}}async close(){this.socket&&(this.socket.close(),this.socket=null)}send(a,c){var b;null===(b=this.socket)||void 0===b||b.send(a,c);return!!this.socket}}exports.WebSocketClient=WebSocketClient;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
|
|
2
|
+
import { BinaryNode } from '../WABinary';
|
|
3
|
+
export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
4
|
+
logger: import("../Utils/logger").ILogger;
|
|
5
|
+
getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
|
|
6
|
+
getCatalog: ({ jid, limit, cursor }: GetCatalogOptions) => Promise<{
|
|
7
|
+
products: import("../Types").Product[];
|
|
8
|
+
nextPageCursor: string | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
getCollections: (jid?: string, limit?: number) => Promise<{
|
|
11
|
+
collections: import("../Types").CatalogCollection[];
|
|
12
|
+
}>;
|
|
13
|
+
productCreate: (create: ProductCreate) => Promise<import("../Types").Product>;
|
|
14
|
+
productDelete: (productIds: string[]) => Promise<{
|
|
15
|
+
deleted: number;
|
|
16
|
+
}>;
|
|
17
|
+
productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>;
|
|
18
|
+
sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
|
|
19
|
+
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
20
|
+
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
21
|
+
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").default) => Promise<string>;
|
|
22
|
+
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
|
23
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
|
24
|
+
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
25
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
26
|
+
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
|
+
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
28
|
+
readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
|
|
29
|
+
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
30
|
+
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
31
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
32
|
+
[_: string]: string;
|
|
33
|
+
}>;
|
|
34
|
+
sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
35
|
+
createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
|
|
36
|
+
nodes: BinaryNode[];
|
|
37
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
40
|
+
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
41
|
+
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
42
|
+
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
43
|
+
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
44
|
+
groupLeave: (id: string) => Promise<void>;
|
|
45
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
|
46
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
}[]>;
|
|
49
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
|
|
50
|
+
status: string;
|
|
51
|
+
jid: string;
|
|
52
|
+
}[]>;
|
|
53
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
|
|
54
|
+
status: string;
|
|
55
|
+
jid: string;
|
|
56
|
+
content: BinaryNode;
|
|
57
|
+
}[]>;
|
|
58
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
59
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
60
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
61
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
62
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
63
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
|
|
64
|
+
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
65
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
66
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
67
|
+
groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
|
|
68
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
69
|
+
groupFetchAllParticipating: () => Promise<{
|
|
70
|
+
[_: string]: import("../Types").GroupMetadata;
|
|
71
|
+
}>;
|
|
72
|
+
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
|
73
|
+
processingMutex: {
|
|
74
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
75
|
+
};
|
|
76
|
+
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
77
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
78
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
79
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
80
|
+
profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
|
|
81
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
82
|
+
jid: string;
|
|
83
|
+
exists: unknown;
|
|
84
|
+
lid: unknown;
|
|
85
|
+
}[] | undefined>;
|
|
86
|
+
fetchBlocklist: () => Promise<string[]>;
|
|
87
|
+
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
88
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
89
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
90
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
91
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
92
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
93
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
94
|
+
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
|
95
|
+
updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
|
|
96
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
97
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
98
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
99
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
100
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
101
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
102
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
103
|
+
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
|
104
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
105
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
106
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
107
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
108
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
109
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
110
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
111
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
112
|
+
star: (jid: string, messages: {
|
|
113
|
+
id: string;
|
|
114
|
+
fromMe?: boolean;
|
|
115
|
+
}[], star: boolean) => Promise<void>;
|
|
116
|
+
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
|
|
117
|
+
type: "md";
|
|
118
|
+
ws: import("./Client").WebSocketClient;
|
|
119
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
120
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
121
|
+
buffer(): void;
|
|
122
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
123
|
+
flush(force?: boolean): boolean;
|
|
124
|
+
isBuffering(): boolean;
|
|
125
|
+
};
|
|
126
|
+
authState: {
|
|
127
|
+
creds: import("../Types").AuthenticationCreds;
|
|
128
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
129
|
+
};
|
|
130
|
+
signalRepository: import("../Types").SignalRepository;
|
|
131
|
+
user: import("../Types").Contact | undefined;
|
|
132
|
+
generateMessageTag: () => string;
|
|
133
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
134
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
135
|
+
waitForSocketOpen: () => Promise<void>;
|
|
136
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
137
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
138
|
+
logout: (msg?: string) => Promise<void>;
|
|
139
|
+
end: (error: Error | undefined) => void;
|
|
140
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
|
|
141
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
142
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
143
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
144
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
145
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
146
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});exports.makeBusinessSocket=void 0;
|
|
2
|
+
const business_1=require("../Utils/business"),WABinary_1=require("../WABinary"),generic_utils_1=require("../WABinary/generic-utils"),messages_recv_1=require("./messages-recv"),makeBusinessSocket=f=>{const g=(0,messages_recv_1.makeMessagesRecvSocket)(f),{authState:h,query:c,waUploadToServer:k}=g;return{...g,logger:f.logger,getOrderDetails:async(a,b)=>{a=await c({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"get",xmlns:"fb:thrift_iq",smax_id:"5"},content:[{tag:"order",attrs:{op:"get",id:a},content:[{tag:"image_dimensions",
|
|
3
|
+
attrs:{},content:[{tag:"width",attrs:{},content:Buffer.from("100")},{tag:"height",attrs:{},content:Buffer.from("100")}]},{tag:"token",attrs:{},content:Buffer.from(b)}]}]});return(0,business_1.parseOrderDetailsNode)(a)},getCatalog:async({jid:a,limit:b,cursor:d})=>{var e;a=a||(null===(e=h.creds.me)||void 0===e?void 0:e.id);a=(0,WABinary_1.jidNormalizedUser)(a);b=[{tag:"limit",attrs:{},content:Buffer.from((b||10).toString())},{tag:"width",attrs:{},content:Buffer.from("100")},{tag:"height",attrs:{},content:Buffer.from("100")}];
|
|
4
|
+
d&&b.push({tag:"after",attrs:{},content:d});a=await c({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"get",xmlns:"w:biz:catalog"},content:[{tag:"product_catalog",attrs:{jid:a,allow_shop_source:"true"},content:b}]});return(0,business_1.parseCatalogNode)(a)},getCollections:async(a,b=51)=>{var d;a=a||(null===(d=h.creds.me)||void 0===d?void 0:d.id);a=(0,WABinary_1.jidNormalizedUser)(a);a=await c({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"get",xmlns:"w:biz:catalog",smax_id:"35"},content:[{tag:"collections",
|
|
5
|
+
attrs:{biz_jid:a},content:[{tag:"collection_limit",attrs:{},content:Buffer.from(b.toString())},{tag:"item_limit",attrs:{},content:Buffer.from(b.toString())},{tag:"width",attrs:{},content:Buffer.from("100")},{tag:"height",attrs:{},content:Buffer.from("100")}]}]});return(0,business_1.parseCollectionsNode)(a)},productCreate:async a=>{a.isHidden=!!a.isHidden;a=await (0,business_1.uploadingNecessaryImagesOfProduct)(a,k);a=(0,business_1.toProductNode)(void 0,a);a=await c({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,
|
|
6
|
+
type:"set",xmlns:"w:biz:catalog"},content:[{tag:"product_catalog_add",attrs:{v:"1"},content:[a,{tag:"width",attrs:{},content:"100"},{tag:"height",attrs:{},content:"100"}]}]});a=(0,generic_utils_1.getBinaryNodeChild)(a,"product_catalog_add");a=(0,generic_utils_1.getBinaryNodeChild)(a,"product");return(0,business_1.parseProductNode)(a)},productDelete:async a=>{a=await c({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"w:biz:catalog"},content:[{tag:"product_catalog_delete",attrs:{v:"1"},
|
|
7
|
+
content:a.map(b=>({tag:"product",attrs:{},content:[{tag:"id",attrs:{},content:Buffer.from(b)}]}))}]});a=(0,generic_utils_1.getBinaryNodeChild)(a,"product_catalog_delete");return{deleted:+((null===a||void 0===a?void 0:a.attrs.deleted_count)||0)}},productUpdate:async(a,b)=>{b=await (0,business_1.uploadingNecessaryImagesOfProduct)(b,k);a=(0,business_1.toProductNode)(a,b);a=await c({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"w:biz:catalog"},content:[{tag:"product_catalog_edit",attrs:{v:"1"},
|
|
8
|
+
content:[a,{tag:"width",attrs:{},content:"100"},{tag:"height",attrs:{},content:"100"}]}]});a=(0,generic_utils_1.getBinaryNodeChild)(a,"product_catalog_edit");a=(0,generic_utils_1.getBinaryNodeChild)(a,"product");return(0,business_1.parseProductNode)(a)}}};exports.makeBusinessSocket=makeBusinessSocket;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
|
4
|
+
import { LabelActionBody } from '../Types/Label';
|
|
5
|
+
import { BinaryNode } from '../WABinary';
|
|
6
|
+
import { USyncQuery } from '../WAUSync';
|
|
7
|
+
export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
8
|
+
getBotListV2: () => Promise<BotListInfo[]>;
|
|
9
|
+
processingMutex: {
|
|
10
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
13
|
+
[_: string]: string;
|
|
14
|
+
}>;
|
|
15
|
+
upsertMessage: (msg: proto.IWebMessageInfo, type: MessageUpsertType) => Promise<void>;
|
|
16
|
+
appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
|
|
17
|
+
sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
|
|
18
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
19
|
+
profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
|
|
20
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
21
|
+
jid: string;
|
|
22
|
+
exists: unknown;
|
|
23
|
+
lid: unknown;
|
|
24
|
+
}[] | undefined>;
|
|
25
|
+
fetchBlocklist: () => Promise<string[]>;
|
|
26
|
+
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
|
27
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
|
28
|
+
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
29
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
30
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
31
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
32
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
33
|
+
updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>;
|
|
34
|
+
updateMessagesPrivacy: (value: WAPrivacyMessagesValue) => Promise<void>;
|
|
35
|
+
updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
36
|
+
updateOnlinePrivacy: (value: WAPrivacyOnlineValue) => Promise<void>;
|
|
37
|
+
updateProfilePicturePrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
38
|
+
updateStatusPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
39
|
+
updateReadReceiptsPrivacy: (value: WAReadReceiptsValue) => Promise<void>;
|
|
40
|
+
updateGroupsAddPrivacy: (value: WAPrivacyGroupAddValue) => Promise<void>;
|
|
41
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
42
|
+
getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
|
|
43
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
44
|
+
chatModify: (mod: ChatModification, jid: string) => Promise<void>;
|
|
45
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
46
|
+
addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
|
|
47
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
48
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
49
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
50
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
51
|
+
star: (jid: string, messages: {
|
|
52
|
+
id: string;
|
|
53
|
+
fromMe?: boolean;
|
|
54
|
+
}[], star: boolean) => Promise<void>;
|
|
55
|
+
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
56
|
+
type: "md";
|
|
57
|
+
ws: import("./Client").WebSocketClient;
|
|
58
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
59
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
60
|
+
buffer(): void;
|
|
61
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
62
|
+
flush(force?: boolean): boolean;
|
|
63
|
+
isBuffering(): boolean;
|
|
64
|
+
};
|
|
65
|
+
authState: {
|
|
66
|
+
creds: import("../Types").AuthenticationCreds;
|
|
67
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
68
|
+
};
|
|
69
|
+
signalRepository: import("../Types").SignalRepository;
|
|
70
|
+
user: import("../Types").Contact | undefined;
|
|
71
|
+
generateMessageTag: () => string;
|
|
72
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
73
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
74
|
+
waitForSocketOpen: () => Promise<void>;
|
|
75
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
76
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
77
|
+
logout: (msg?: string) => Promise<void>;
|
|
78
|
+
end: (error: Error | undefined) => void;
|
|
79
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
80
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
81
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
82
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
83
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
84
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
85
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __importDefault=this&&this.__importDefault||function(m){return m&&m.__esModule?m:{"default":m}};Object.defineProperty(exports,"__esModule",{value:!0});exports.makeChatsSocket=void 0;
|
|
2
|
+
const node_cache_1=__importDefault(require("@cacheable/node-cache")),boom_1=require("@hapi/boom"),WAProto_1=require("../../WAProto"),Defaults_1=require("../Defaults"),Types_1=require("../Types"),Utils_1=require("../Utils"),make_mutex_1=require("../Utils/make-mutex"),process_message_1=__importDefault(require("../Utils/process-message")),WABinary_1=require("../WABinary"),WAUSync_1=require("../WAUSync"),usync_1=require("./usync"),MAX_SYNC_ATTEMPTS=2,makeChatsSocket=m=>{const {logger:l,markOnlineOnConnect:V,
|
|
3
|
+
fireInitQueries:W,appStateMacVerification:I,shouldIgnoreJid:X,shouldSyncHistoryMessage:Y}=m,A=(0,usync_1.makeUSyncSocket)(m),{ev:p,ws:F,authState:f,generateMessageTag:J,sendNode:C,query:r,onUnexpectedError:K}=A;let G,L=!1,D=!1;const M=(0,make_mutex_1.makeMutex)(),N=m.placeholderResendCache||new node_cache_1.default({stdTTL:Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,useClones:!1});m.placeholderResendCache||(m.placeholderResendCache=N);const E=async a=>{({[a]:a}=await f.keys.get("app-state-sync-key",[a]));
|
|
4
|
+
return a},O=async(a=!1)=>{if(!G||a)({content:a}=await r({tag:"iq",attrs:{xmlns:"privacy",to:WABinary_1.S_WHATSAPP_NET,type:"get"},content:[{tag:"privacy",attrs:{}}]})),G=(0,WABinary_1.reduceBinaryNodeToDictionary)(null===a||void 0===a?void 0:a[0],"category");return G},u=async(a,b)=>{await r({tag:"iq",attrs:{xmlns:"privacy",to:WABinary_1.S_WHATSAPP_NET,type:"set"},content:[{tag:"privacy",attrs:{},content:[{tag:"category",attrs:{name:a,value:b}}]}]})},P=async()=>{var a=await r({tag:"iq",attrs:{xmlns:"blocklist",
|
|
5
|
+
to:WABinary_1.S_WHATSAPP_NET,type:"get"}});a=(0,WABinary_1.getBinaryNodeChild)(a,"list");return(0,WABinary_1.getBinaryNodeChildren)(a,"item").map(b=>b.attrs.jid)},Q=async(a,b)=>{l.info({fromTimestamp:b},"clean dirty bits "+a);await C({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"urn:xmpp:whatsapp:dirty",id:J()},content:[{tag:"clean",attrs:{type:a,...(b?{timestamp:b.toString()}:null)}}]})},R=a=>({onMutation(b){(0,Utils_1.processSyncAction)(b,p,f.creds.me,a?{accountSettings:f.creds.accountSettings}:
|
|
6
|
+
void 0,l)}}),H=p.createBufferedFunction(async(a,b)=>{const c={},d={};await f.keys.transaction(async()=>{var g;const h=new Set(a),k={};for(;h.size;){const y={};var n=[];for(const t of h){var e=(await f.keys.get("app-state-sync-version",[t]))[t];e?"undefined"===typeof c[t]&&(c[t]=e.version):e=(0,Utils_1.newLTHashState)();y[t]=e;l.info(`resyncing ${t} from v${e.version}`);n.push({tag:"collection",attrs:{name:t,version:e.version.toString(),return_snapshot:(!e.version).toString()}})}n=await r({tag:"iq",
|
|
7
|
+
attrs:{to:WABinary_1.S_WHATSAPP_NET,xmlns:"w:sync:app:state",type:"set"},content:[{tag:"sync",attrs:{},content:n}]});n=await (0,Utils_1.extractSyncdPatches)(n,null===m||void 0===m?void 0:m.options);for(const t in n){e=t;const {patches:z,hasMorePatches:B,snapshot:v}=n[e];try{if(v){const {state:q,mutationMap:w}=await (0,Utils_1.decodeSyncdSnapshot)(e,v,E,c[e],I.snapshot);y[e]=q;Object.assign(d,w);l.info(`restored state of ${e} from snapshot to v${q.version} with mutations`);await f.keys.set({"app-state-sync-version":{[e]:q}})}if(z.length){const {state:q,
|
|
8
|
+
mutationMap:w}=await (0,Utils_1.decodePatches)(e,z,y[e],E,m.options,c[e],l,I.patch);await f.keys.set({"app-state-sync-version":{[e]:q}});l.info(`synced ${e} to v${q.version}`);c[e]=q.version;Object.assign(d,w)}B?l.info(`${e} has more patches...`):h.delete(e)}catch(q){const w=k[e]>=MAX_SYNC_ATTEMPTS||404===(null===(g=q.output)||void 0===g?void 0:g.statusCode)||"TypeError"===q.name;l.info({name:e,error:q.stack},`failed to sync state from version${w?"":", removing and trying from scratch"}`);await f.keys.set({"app-state-sync-version":{[e]:null}});
|
|
9
|
+
k[e]=(k[e]||0)+1;w&&h.delete(e)}}}});({onMutation:b}=R(b));for(const g in d)b(d[g])}),S=async(a,b)=>{const c=f.creds.me;"available"===a||"unavailable"===a?c.name?(p.emit("connection.update",{isOnline:"available"===a}),await C({tag:"presence",attrs:{name:c.name,type:a}})):l.warn("no name present, ignoring presence update request..."):await C({tag:"chatstate",attrs:{from:c.id,to:b},content:[{tag:"recording"===a?"composing":a,attrs:"recording"===a?{media:"audio"}:{}}]})},T=({tag:a,attrs:b,content:c})=>
|
|
10
|
+
{var d;let g;const h=b.from,k=b.participant||b.from;X(h)&&"@s.whatsapp.net"!==h||("presence"===a?g={lastKnownPresence:"unavailable"===b.type?"unavailable":"available",lastSeen:b.last&&"deny"!==b.last?+b.last:void 0}:Array.isArray(c)?([a]=c,b=a.tag,"paused"===b&&(b="available"),"audio"===(null===(d=a.attrs)||void 0===d?void 0:d.media)&&(b="recording"),g={lastKnownPresence:b}):l.error({tag:a,attrs:b,content:c},"recv invalid presence node"),g&&p.emit("presence.update",{id:h,presences:{[k]:g}}))},U=async a=>
|
|
11
|
+
{const b=a.type,c=f.creds.myAppStateKeyId;if(!c)throw new boom_1.Boom("App state key not present!",{statusCode:400});let d,g;await M.mutex(async()=>{await f.keys.transaction(async()=>{l.debug({patch:a},"applying app patch");await H([b],!1);var {[b]:h}=await f.keys.get("app-state-sync-version",[b]);d=h||(0,Utils_1.newLTHashState)();g=await (0,Utils_1.encodeSyncdPatch)(a,c,d,E);const {patch:k,state:n}=g;h={tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"w:sync:app:state"},content:[{tag:"sync",
|
|
12
|
+
attrs:{},content:[{tag:"collection",attrs:{name:b,version:(n.version-1).toString(),return_snapshot:"false"},content:[{tag:"patch",attrs:{},content:WAProto_1.proto.SyncdPatch.encode(k).finish()}]}]}]};await r(h);await f.keys.set({"app-state-sync-version":{[b]:n}})})});if(m.emitOwnEvents){const {onMutation:h}=R(!1),{mutationMap:k}=await (0,Utils_1.decodePatches)(b,[{...g.patch,version:{version:g.state.version}}],d,E,m.options,void 0,l);for(const n in k)h(k[n])}},Z=async()=>{var a,b,c,d=await r({tag:"iq",
|
|
13
|
+
attrs:{to:WABinary_1.S_WHATSAPP_NET,xmlns:"w",type:"get"},content:[{tag:"props",attrs:{protocol:"2",hash:(null===(a=null===f||void 0===f?void 0:f.creds)||void 0===a?void 0:a.lastPropHash)||""}}]});a=(0,WABinary_1.getBinaryNodeChild)(d,"props");d={};if(a){if(null===(b=a.attrs)||void 0===b?0:b.hash)f.creds.lastPropHash=null===(c=null===a||void 0===a?void 0:a.attrs)||void 0===c?void 0:c.hash,p.emit("creds.update",f.creds);d=(0,WABinary_1.reduceBinaryNodeToDictionary)(a,"prop")}l.debug("fetched props");
|
|
14
|
+
return d},x=(a,b)=>{a=(0,Utils_1.chatModificationToAppPatch)(a,b);return U(a)},aa=async()=>{await Promise.all([Z(),P(),O()])},ba=p.createBufferedFunction(async(a,b)=>{async function c(){f.creds.accountSyncCounter||(l.info("doing initial app state sync"),await H(Types_1.ALL_WA_PATCH_NAMES,!0),p.emit("creds.update",{accountSyncCounter:(f.creds.accountSyncCounter||0)+1}),L&&(l.debug("flushing with app state sync"),p.flush()))}var d,g,h;p.emit("messages.upsert",{messages:[a],type:b});a.pushName&&(b=a.key.fromMe?
|
|
15
|
+
f.creds.me.id:a.key.participant||a.key.remoteJid,b=(0,WABinary_1.jidNormalizedUser)(b),a.key.fromMe||p.emit("contacts.update",[{id:b,notify:a.pushName,verifiedName:a.verifiedBizName}]),a.key.fromMe&&a.pushName&&(null===(d=f.creds.me)||void 0===d?void 0:d.name)!==a.pushName&&p.emit("creds.update",{me:{...f.creds.me,name:a.pushName}}));const k=(0,Utils_1.getHistoryMsg)(a.message);d=k?Y(k)&&Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(k.syncType):!1;k&&!f.creds.myAppStateKeyId&&(l.warn("skipping app state sync, as myAppStateKeyId is not set"),
|
|
16
|
+
D=!0);await Promise.all([(async()=>{k&&f.creds.myAppStateKeyId&&(D=!1,await c())})(),(0,process_message_1.default)(a,{shouldProcessHistoryMsg:d,placeholderResendCache:N,ev:p,creds:f.creds,keyStore:f.keys,logger:l,options:m.options})]);(null===(h=null===(g=a.message)||void 0===g?void 0:g.protocolMessage)||void 0===h?0:h.appStateSyncKeyShare)&&D&&(await c(),D=!1)});F.on("CB:presence",T);F.on("CB:chatstate",T);F.on("CB:ib,,dirty",async a=>{const {attrs:b}=(0,WABinary_1.getBinaryNodeChild)(a,"dirty");
|
|
17
|
+
switch(b.type){case "account_sync":b.timestamp&&({lastAccountSyncTimestamp:a}=f.creds,a&&await Q("account_sync",a),a=+b.timestamp,p.emit("creds.update",{lastAccountSyncTimestamp:a}));break;case "groups":break;default:l.info({node:a},"received unknown sync")}});p.on("connection.update",({connection:a,receivedPendingNotifications:b})=>{var c;"open"===a&&(W&&aa().catch(d=>K(d,"init queries")),S(V?"available":"unavailable").catch(d=>K(d,"presence update requests")));!b||null!==(c=f.creds)&&void 0!==c&&
|
|
18
|
+
c.myAppStateKeyId||(p.buffer(),L=!0)});return{...A,getBotListV2:async()=>{var a=await r({tag:"iq",attrs:{xmlns:"bot",to:WABinary_1.S_WHATSAPP_NET,type:"get"},content:[{tag:"bot",attrs:{v:"2"}}]});a=(0,WABinary_1.getBinaryNodeChild)(a,"bot");const b=[];for(const c of(0,WABinary_1.getBinaryNodeChildren)(a,"section"))if("all"===c.attrs.type)for(const d of(0,WABinary_1.getBinaryNodeChildren)(c,"bot"))b.push({jid:d.attrs.jid,personaId:d.attrs.persona_id});return b},processingMutex:M,fetchPrivacySettings:O,
|
|
19
|
+
upsertMessage:ba,appPatch:U,sendPresenceUpdate:S,presenceSubscribe:(a,b)=>C({tag:"presence",attrs:{to:a,id:J(),type:"subscribe"},content:b?[{tag:"tctoken",attrs:{},content:b}]:void 0}),profilePictureUrl:async(a,b="preview",c)=>{var d;a=(0,WABinary_1.jidNormalizedUser)(a);a=await r({tag:"iq",attrs:{target:a,to:WABinary_1.S_WHATSAPP_NET,type:"get",xmlns:"w:profile:picture"},content:[{tag:"picture",attrs:{type:b,query:"url"}}]},c);a=(0,WABinary_1.getBinaryNodeChild)(a,"picture");return null===(d=null===
|
|
20
|
+
a||void 0===a?void 0:a.attrs)||void 0===d?void 0:d.url},onWhatsApp:async(...a)=>{var b=(new WAUSync_1.USyncQuery).withContactProtocol().withLIDProtocol();for(const c of a)a=`+${c.replace("+","").split("@")[0].split(":")[0]}`,b.withUser((new WAUSync_1.USyncUser).withPhone(a));if(b=await A.executeUSyncQuery(b))return b.list.filter(c=>!!c.contact).map(({contact:c,id:d,lid:g})=>({jid:d,exists:c,lid:g}))},fetchBlocklist:P,fetchStatus:async(...a)=>{const b=(new WAUSync_1.USyncQuery).withStatusProtocol();
|
|
21
|
+
for(const c of a)b.withUser((new WAUSync_1.USyncUser).withId(c));if(a=await A.executeUSyncQuery(b))return a.list},fetchDisappearingDuration:async(...a)=>{const b=(new WAUSync_1.USyncQuery).withDisappearingModeProtocol();for(const c of a)b.withUser((new WAUSync_1.USyncUser).withId(c));if(a=await A.executeUSyncQuery(b))return a.list},updateProfilePicture:async(a,b)=>{let c;if(!a)throw new boom_1.Boom("Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update");
|
|
22
|
+
(0,WABinary_1.jidNormalizedUser)(a)!==(0,WABinary_1.jidNormalizedUser)(f.creds.me.id)&&(c=(0,WABinary_1.jidNormalizedUser)(a));({img:a}=await (0,Utils_1.generateProfilePicture)(b));await r({tag:"iq",attrs:{target:c,to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"w:profile:picture"},content:[{tag:"picture",attrs:{type:"image"},content:a}]})},removeProfilePicture:async a=>{let b;if(!a)throw new boom_1.Boom("Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update");
|
|
23
|
+
(0,WABinary_1.jidNormalizedUser)(a)!==(0,WABinary_1.jidNormalizedUser)(f.creds.me.id)&&(b=(0,WABinary_1.jidNormalizedUser)(a));await r({tag:"iq",attrs:{target:b,to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"w:profile:picture"}})},updateProfileStatus:async a=>{await r({tag:"iq",attrs:{to:WABinary_1.S_WHATSAPP_NET,type:"set",xmlns:"status"},content:[{tag:"status",attrs:{},content:Buffer.from(a,"utf-8")}]})},updateProfileName:async a=>{await x({pushNameSetting:a},"")},updateBlockStatus:async(a,b)=>
|
|
24
|
+
{await r({tag:"iq",attrs:{xmlns:"blocklist",to:WABinary_1.S_WHATSAPP_NET,type:"set"},content:[{tag:"item",attrs:{action:b,jid:a}}]})},updateCallPrivacy:async a=>{await u("calladd",a)},updateMessagesPrivacy:async a=>{await u("messages",a)},updateLastSeenPrivacy:async a=>{await u("last",a)},updateOnlinePrivacy:async a=>{await u("online",a)},updateProfilePicturePrivacy:async a=>{await u("profile",a)},updateStatusPrivacy:async a=>{await u("status",a)},updateReadReceiptsPrivacy:async a=>{await u("readreceipts",
|
|
25
|
+
a)},updateGroupsAddPrivacy:async a=>{await u("groupadd",a)},updateDefaultDisappearingMode:async a=>{await r({tag:"iq",attrs:{xmlns:"disappearing_mode",to:WABinary_1.S_WHATSAPP_NET,type:"set"},content:[{tag:"disappearing_mode",attrs:{duration:a.toString()}}]})},getBusinessProfile:async a=>{var b,c,d,g,h,k,n;a=await r({tag:"iq",attrs:{to:"s.whatsapp.net",xmlns:"w:biz",type:"get"},content:[{tag:"business_profile",attrs:{v:"244"},content:[{tag:"profile",attrs:{jid:a}}]}]});a=(0,WABinary_1.getBinaryNodeChild)(a,
|
|
26
|
+
"business_profile");if(a=(0,WABinary_1.getBinaryNodeChild)(a,"profile")){const y=(0,WABinary_1.getBinaryNodeChild)(a,"address"),t=(0,WABinary_1.getBinaryNodeChild)(a,"description");var e=(0,WABinary_1.getBinaryNodeChild)(a,"website");const z=(0,WABinary_1.getBinaryNodeChild)(a,"email"),B=(0,WABinary_1.getBinaryNodeChild)((0,WABinary_1.getBinaryNodeChild)(a,"categories"),"category"),v=(0,WABinary_1.getBinaryNodeChild)(a,"business_hours"),q=v?(0,WABinary_1.getBinaryNodeChildren)(v,"business_hours_config"):
|
|
27
|
+
void 0;e=null===(b=null===e||void 0===e?void 0:e.content)||void 0===b?void 0:b.toString();return{wid:null===(c=a.attrs)||void 0===c?void 0:c.jid,address:null===(d=null===y||void 0===y?void 0:y.content)||void 0===d?void 0:d.toString(),description:(null===(g=null===t||void 0===t?void 0:t.content)||void 0===g?void 0:g.toString())||"",website:e?[e]:[],email:null===(h=null===z||void 0===z?void 0:z.content)||void 0===h?void 0:h.toString(),category:null===(k=null===B||void 0===B?void 0:B.content)||void 0===
|
|
28
|
+
k?void 0:k.toString(),business_hours:{timezone:null===(n=null===v||void 0===v?void 0:v.attrs)||void 0===n?void 0:n.timezone,business_config:null===q||void 0===q?void 0:q.map(({attrs:w})=>w)}}}},resyncAppState:H,chatModify:x,cleanDirtyBits:Q,addLabel:(a,b)=>x({addLabel:{...b}},a),addChatLabel:(a,b)=>x({addChatLabel:{labelId:b}},a),removeChatLabel:(a,b)=>x({removeChatLabel:{labelId:b}},a),addMessageLabel:(a,b,c)=>x({addMessageLabel:{messageId:b,labelId:c}},a),removeMessageLabel:(a,b,c)=>x({removeMessageLabel:{messageId:b,
|
|
29
|
+
labelId:c}},a),star:(a,b,c)=>x({star:{messages:b,star:c}},a)}};exports.makeChatsSocket=makeChatsSocket;
|