gifted-baileys 1.5.4 → 1.5.5
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 +1 -1
- package/WAProto/WAProto.proto +88 -969
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +74730 -125106
- package/package.json +9 -27
- package/src/Defaults/baileys-version.json +3 -0
- package/{lib → src}/Defaults/index.js +14 -7
- package/src/Defaults/index.ts +131 -0
- package/src/Signal/libsignal.js +180 -0
- package/src/Signal/libsignal.ts +141 -0
- package/src/Socket/Client/abstract-socket-client.ts +19 -0
- package/{lib → src}/Socket/Client/index.js +3 -2
- package/src/Socket/Client/index.ts +3 -0
- package/src/Socket/Client/mobile-socket-client.js +78 -0
- package/src/Socket/Client/mobile-socket-client.ts +66 -0
- package/src/Socket/Client/web-socket-client.js +75 -0
- package/src/Socket/Client/web-socket-client.ts +57 -0
- package/{lib → src}/Socket/business.js +33 -28
- package/src/Socket/business.ts +281 -0
- package/{lib → src}/Socket/chats.js +176 -174
- package/src/Socket/chats.ts +1030 -0
- package/{lib → src}/Socket/groups.js +68 -80
- package/src/Socket/groups.ts +356 -0
- package/{lib → src}/Socket/index.js +1 -4
- package/src/Socket/index.ts +13 -0
- package/{lib → src}/Socket/messages-recv.js +211 -378
- package/src/Socket/messages-recv.ts +985 -0
- package/{lib → src}/Socket/messages-send.js +177 -452
- package/src/Socket/messages-send.ts +871 -0
- package/{lib → src}/Socket/newsletter.js +98 -107
- package/src/Socket/newsletter.ts +282 -0
- package/{lib → src}/Socket/registration.js +48 -56
- package/src/Socket/registration.ts +250 -0
- package/{lib → src}/Socket/socket.js +77 -77
- package/src/Socket/socket.ts +777 -0
- package/src/Store/index.ts +3 -0
- package/{lib → src}/Store/make-cache-manager-store.js +34 -25
- package/src/Store/make-cache-manager-store.ts +100 -0
- package/{lib → src}/Store/make-in-memory-store.js +32 -36
- package/src/Store/make-in-memory-store.ts +475 -0
- package/src/Store/make-ordered-dictionary.ts +86 -0
- package/{lib → src}/Store/object-repository.js +1 -1
- package/src/Store/object-repository.ts +32 -0
- package/src/Tests/test.app-state-sync.js +204 -0
- package/src/Tests/test.app-state-sync.ts +207 -0
- package/src/Tests/test.event-buffer.js +270 -0
- package/src/Tests/test.event-buffer.ts +319 -0
- package/src/Tests/test.key-store.js +76 -0
- package/src/Tests/test.key-store.ts +92 -0
- package/src/Tests/test.libsignal.js +141 -0
- package/src/Tests/test.libsignal.ts +186 -0
- package/src/Tests/test.media-download.js +93 -0
- package/src/Tests/test.media-download.ts +76 -0
- package/src/Tests/test.messages.js +33 -0
- package/src/Tests/test.messages.ts +37 -0
- package/src/Tests/utils.js +34 -0
- package/src/Tests/utils.ts +36 -0
- package/src/Types/Auth.ts +113 -0
- package/src/Types/Call.ts +15 -0
- package/src/Types/Chat.ts +106 -0
- package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
- package/src/Types/Events.ts +93 -0
- package/src/Types/GroupMetadata.ts +53 -0
- package/src/Types/Label.ts +36 -0
- package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
- package/src/Types/Message.ts +288 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +68 -0
- package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
- package/src/Types/State.ts +29 -0
- package/src/Types/index.ts +59 -0
- package/{lib → src}/Utils/auth-utils.js +90 -73
- package/src/Utils/auth-utils.ts +222 -0
- package/src/Utils/baileys-event-stream.js +92 -0
- package/src/Utils/baileys-event-stream.ts +66 -0
- package/{lib → src}/Utils/business.js +43 -15
- package/src/Utils/business.ts +275 -0
- package/{lib → src}/Utils/chat-utils.js +94 -87
- package/src/Utils/chat-utils.ts +860 -0
- package/{lib → src}/Utils/crypto.js +2 -4
- package/src/Utils/crypto.ts +131 -0
- package/src/Utils/decode-wa-message.js +211 -0
- package/src/Utils/decode-wa-message.ts +228 -0
- package/{lib → src}/Utils/event-buffer.js +13 -4
- package/src/Utils/event-buffer.ts +613 -0
- package/{lib → src}/Utils/generics.js +86 -67
- package/src/Utils/generics.ts +434 -0
- package/{lib → src}/Utils/history.js +39 -13
- package/src/Utils/history.ts +112 -0
- package/src/Utils/index.ts +17 -0
- package/{lib → src}/Utils/link-preview.js +54 -17
- package/src/Utils/link-preview.ts +122 -0
- package/src/Utils/logger.ts +3 -0
- package/src/Utils/lt-hash.ts +61 -0
- package/{lib → src}/Utils/make-mutex.js +13 -4
- package/src/Utils/make-mutex.ts +44 -0
- package/{lib → src}/Utils/messages-media.js +255 -193
- package/src/Utils/messages-media.ts +847 -0
- package/{lib → src}/Utils/messages.js +118 -588
- package/src/Utils/messages.ts +956 -0
- package/src/Utils/noise-handler.ts +197 -0
- package/{lib → src}/Utils/process-message.js +30 -27
- package/src/Utils/process-message.ts +414 -0
- package/{lib → src}/Utils/signal.js +42 -25
- package/src/Utils/signal.ts +177 -0
- package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
- package/src/Utils/use-multi-file-auth-state.ts +90 -0
- package/{lib → src}/Utils/validate-connection.js +9 -40
- package/src/Utils/validate-connection.ts +238 -0
- package/src/WABinary/constants.ts +42 -0
- package/src/WABinary/decode.ts +265 -0
- package/{lib → src}/WABinary/encode.js +10 -16
- package/src/WABinary/encode.ts +236 -0
- package/src/WABinary/generic-utils.ts +121 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +68 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +15382 -0
- package/src/WAM/encode.ts +174 -0
- package/src/WAM/index.ts +3 -0
- package/{lib → src}/index.js +0 -1
- package/src/index.ts +13 -0
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -161
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.d.ts +0 -12
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -170
- package/lib/Socket/chats.d.ts +0 -81
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -172
- package/lib/Socket/messages-recv.d.ts +0 -158
- package/lib/Socket/messages-send.d.ts +0 -155
- package/lib/Socket/newsletter.d.ts +0 -132
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -109
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -107
- package/lib/Types/Events.d.ts +0 -172
- package/lib/Types/GroupMetadata.d.ts +0 -56
- package/lib/Types/Label.d.ts +0 -46
- package/lib/Types/Message.d.ts +0 -433
- package/lib/Types/Newsletter.d.ts +0 -92
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -70
- package/lib/Utils/crypto.d.ts +0 -40
- package/lib/Utils/decode-wa-message.d.ts +0 -36
- package/lib/Utils/decode-wa-message.js +0 -226
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -88
- package/lib/Utils/history.d.ts +0 -19
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -2
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -113
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -33
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -6
- package/lib/WABinary/encode.d.ts +0 -2
- package/lib/WABinary/generic-utils.d.ts +0 -14
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -8
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -2
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
- /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{lib → src}/Store/index.js +0 -0
- /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
- /package/{lib → src}/Types/Auth.js +0 -0
- /package/{lib → src}/Types/Call.js +0 -0
- /package/{lib → src}/Types/Chat.js +0 -0
- /package/{lib → src}/Types/Contact.js +0 -0
- /package/{lib → src}/Types/Events.js +0 -0
- /package/{lib → src}/Types/GroupMetadata.js +0 -0
- /package/{lib → src}/Types/Label.js +0 -0
- /package/{lib → src}/Types/LabelAssociation.js +0 -0
- /package/{lib → src}/Types/Message.js +0 -0
- /package/{lib → src}/Types/Newsletter.js +0 -0
- /package/{lib → src}/Types/Product.js +0 -0
- /package/{lib → src}/Types/Signal.js +0 -0
- /package/{lib → src}/Types/Socket.js +0 -0
- /package/{lib → src}/Types/State.js +0 -0
- /package/{lib → src}/Types/index.js +0 -0
- /package/{lib → src}/Utils/index.js +0 -0
- /package/{lib → src}/Utils/logger.js +0 -0
- /package/{lib → src}/Utils/lt-hash.js +0 -0
- /package/{lib → src}/Utils/noise-handler.js +0 -0
- /package/{lib → src}/WABinary/constants.js +0 -0
- /package/{lib → src}/WABinary/decode.js +0 -0
- /package/{lib → src}/WABinary/generic-utils.js +0 -0
- /package/{lib → src}/WABinary/index.js +0 -0
- /package/{lib → src}/WABinary/jid-utils.js +0 -0
- /package/{lib → src}/WABinary/types.js +0 -0
- /package/{lib → src}/WAM/BinaryInfo.js +0 -0
- /package/{lib → src}/WAM/constants.js +0 -0
- /package/{lib → src}/WAM/encode.js +0 -0
- /package/{lib → src}/WAM/index.js +0 -0
- /package/{lib → src}/gifted +0 -0
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.makeSocket = void 0;
|
|
4
13
|
const boom_1 = require("@hapi/boom");
|
|
@@ -54,21 +63,21 @@ const makeSocket = (config) => {
|
|
|
54
63
|
const generateMessageTag = () => `${uqTagId}${epoch++}`;
|
|
55
64
|
const sendPromise = (0, util_1.promisify)(ws.send);
|
|
56
65
|
/** send a raw buffer */
|
|
57
|
-
const sendRawMessage =
|
|
66
|
+
const sendRawMessage = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
67
|
if (!ws.isOpen) {
|
|
59
68
|
throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
|
|
60
69
|
}
|
|
61
70
|
const bytes = noise.encodeFrame(data);
|
|
62
|
-
|
|
71
|
+
yield (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
72
|
try {
|
|
64
|
-
|
|
73
|
+
yield sendPromise.call(ws, bytes);
|
|
65
74
|
resolve();
|
|
66
75
|
}
|
|
67
76
|
catch (error) {
|
|
68
77
|
reject(error);
|
|
69
78
|
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
72
81
|
/** send a binary node */
|
|
73
82
|
const sendNode = (frame) => {
|
|
74
83
|
if (logger.level === 'trace') {
|
|
@@ -82,7 +91,7 @@ const makeSocket = (config) => {
|
|
|
82
91
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
83
92
|
};
|
|
84
93
|
/** await the next incoming message */
|
|
85
|
-
const awaitNextMessage =
|
|
94
|
+
const awaitNextMessage = (sendMsg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
95
|
if (!ws.isOpen) {
|
|
87
96
|
throw new boom_1.Boom('Connection Closed', {
|
|
88
97
|
statusCode: Types_1.DisconnectReason.connectionClosed
|
|
@@ -106,17 +115,17 @@ const makeSocket = (config) => {
|
|
|
106
115
|
sendRawMessage(sendMsg).catch(onClose);
|
|
107
116
|
}
|
|
108
117
|
return result;
|
|
109
|
-
};
|
|
118
|
+
});
|
|
110
119
|
/**
|
|
111
120
|
* Wait for a message with a certain tag to be received
|
|
112
121
|
* @param msgId the message tag to await
|
|
113
122
|
* @param timeoutMs timeout after which the promise will reject
|
|
114
123
|
*/
|
|
115
|
-
const waitForMessage =
|
|
124
|
+
const waitForMessage = (msgId_1, ...args_1) => __awaiter(void 0, [msgId_1, ...args_1], void 0, function* (msgId, timeoutMs = defaultQueryTimeoutMs) {
|
|
116
125
|
let onRecv;
|
|
117
126
|
let onErr;
|
|
118
127
|
try {
|
|
119
|
-
return
|
|
128
|
+
return yield (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
120
129
|
onRecv = resolve;
|
|
121
130
|
onErr = err => {
|
|
122
131
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -131,30 +140,30 @@ const makeSocket = (config) => {
|
|
|
131
140
|
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
132
141
|
ws.off('error', onErr);
|
|
133
142
|
}
|
|
134
|
-
};
|
|
143
|
+
});
|
|
135
144
|
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
136
|
-
const query =
|
|
145
|
+
const query = (node, timeoutMs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
146
|
if (!node.attrs.id) {
|
|
138
147
|
node.attrs.id = generateMessageTag();
|
|
139
148
|
}
|
|
140
149
|
const msgId = node.attrs.id;
|
|
141
150
|
const wait = waitForMessage(msgId, timeoutMs);
|
|
142
|
-
|
|
143
|
-
const result =
|
|
151
|
+
yield sendNode(node);
|
|
152
|
+
const result = yield wait;
|
|
144
153
|
if ('tag' in result) {
|
|
145
154
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
146
155
|
}
|
|
147
156
|
return result;
|
|
148
|
-
};
|
|
157
|
+
});
|
|
149
158
|
/** connection handshake */
|
|
150
|
-
const validateConnection =
|
|
159
|
+
const validateConnection = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
160
|
let helloMsg = {
|
|
152
161
|
clientHello: { ephemeral: ephemeralKeyPair.public }
|
|
153
162
|
};
|
|
154
163
|
helloMsg = WAProto_1.proto.HandshakeMessage.fromObject(helloMsg);
|
|
155
164
|
logger.info({ browser, helloMsg }, 'connected to WA');
|
|
156
165
|
const init = WAProto_1.proto.HandshakeMessage.encode(helloMsg).finish();
|
|
157
|
-
const result =
|
|
166
|
+
const result = yield awaitNextMessage(init);
|
|
158
167
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
159
168
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
160
169
|
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
@@ -171,7 +180,7 @@ const makeSocket = (config) => {
|
|
|
171
180
|
logger.info({ node }, 'logging in...');
|
|
172
181
|
}
|
|
173
182
|
const payloadEnc = noise.encrypt(WAProto_1.proto.ClientPayload.encode(node).finish());
|
|
174
|
-
|
|
183
|
+
yield sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
|
|
175
184
|
clientFinish: {
|
|
176
185
|
static: keyEnc,
|
|
177
186
|
payload: payloadEnc,
|
|
@@ -179,9 +188,9 @@ const makeSocket = (config) => {
|
|
|
179
188
|
}).finish());
|
|
180
189
|
noise.finishInit();
|
|
181
190
|
startKeepAliveRequest();
|
|
182
|
-
};
|
|
183
|
-
const getAvailablePreKeysOnServer =
|
|
184
|
-
const result =
|
|
191
|
+
});
|
|
192
|
+
const getAvailablePreKeysOnServer = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
+
const result = yield query({
|
|
185
194
|
tag: 'iq',
|
|
186
195
|
attrs: {
|
|
187
196
|
id: generateMessageTag(),
|
|
@@ -195,24 +204,24 @@ const makeSocket = (config) => {
|
|
|
195
204
|
});
|
|
196
205
|
const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
|
|
197
206
|
return +countChild.attrs.value;
|
|
198
|
-
};
|
|
207
|
+
});
|
|
199
208
|
/** generates and uploads a set of pre-keys to the server */
|
|
200
|
-
const uploadPreKeys =
|
|
201
|
-
|
|
209
|
+
const uploadPreKeys = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (count = Defaults_1.INITIAL_PREKEY_COUNT) {
|
|
210
|
+
yield keys.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
202
211
|
logger.info({ count }, 'uploading pre-keys');
|
|
203
|
-
const { update, node } =
|
|
204
|
-
|
|
212
|
+
const { update, node } = yield (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
|
|
213
|
+
yield query(node);
|
|
205
214
|
ev.emit('creds.update', update);
|
|
206
215
|
logger.info({ count }, 'uploaded pre-keys');
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
const uploadPreKeysToServerIfRequired =
|
|
210
|
-
const preKeyCount =
|
|
216
|
+
}));
|
|
217
|
+
});
|
|
218
|
+
const uploadPreKeysToServerIfRequired = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
219
|
+
const preKeyCount = yield getAvailablePreKeysOnServer();
|
|
211
220
|
logger.info(`${preKeyCount} pre-keys found on server`);
|
|
212
221
|
if (preKeyCount <= Defaults_1.MIN_PREKEY_COUNT) {
|
|
213
|
-
|
|
222
|
+
yield uploadPreKeys();
|
|
214
223
|
}
|
|
215
|
-
};
|
|
224
|
+
});
|
|
216
225
|
const onMessageReceived = (data) => {
|
|
217
226
|
noise.decodeFrame(data, frame => {
|
|
218
227
|
var _a;
|
|
@@ -273,7 +282,7 @@ const makeSocket = (config) => {
|
|
|
273
282
|
});
|
|
274
283
|
ev.removeAllListeners('connection.update');
|
|
275
284
|
};
|
|
276
|
-
const waitForSocketOpen =
|
|
285
|
+
const waitForSocketOpen = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
286
|
if (ws.isOpen) {
|
|
278
287
|
return;
|
|
279
288
|
}
|
|
@@ -282,7 +291,7 @@ const makeSocket = (config) => {
|
|
|
282
291
|
}
|
|
283
292
|
let onOpen;
|
|
284
293
|
let onClose;
|
|
285
|
-
|
|
294
|
+
yield new Promise((resolve, reject) => {
|
|
286
295
|
onOpen = () => resolve(undefined);
|
|
287
296
|
onClose = mapWebSocketError(reject);
|
|
288
297
|
ws.on('open', onOpen);
|
|
@@ -294,7 +303,7 @@ const makeSocket = (config) => {
|
|
|
294
303
|
ws.off('close', onClose);
|
|
295
304
|
ws.off('error', onClose);
|
|
296
305
|
});
|
|
297
|
-
};
|
|
306
|
+
});
|
|
298
307
|
const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
|
|
299
308
|
if (!lastDateRecv) {
|
|
300
309
|
lastDateRecv = new Date();
|
|
@@ -340,11 +349,11 @@ const makeSocket = (config) => {
|
|
|
340
349
|
]
|
|
341
350
|
}));
|
|
342
351
|
/** logout & invalidate connection */
|
|
343
|
-
const logout =
|
|
352
|
+
const logout = (msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
344
353
|
var _a;
|
|
345
354
|
const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
|
|
346
355
|
if (jid) {
|
|
347
|
-
|
|
356
|
+
yield sendNode({
|
|
348
357
|
tag: 'iq',
|
|
349
358
|
attrs: {
|
|
350
359
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -364,19 +373,15 @@ const makeSocket = (config) => {
|
|
|
364
373
|
});
|
|
365
374
|
}
|
|
366
375
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
367
|
-
};
|
|
368
|
-
const requestPairingCode =
|
|
369
|
-
|
|
370
|
-
authState.creds.pairingCode = pairKey.toUpperCase()
|
|
371
|
-
} else {
|
|
372
|
-
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
373
|
-
}
|
|
376
|
+
});
|
|
377
|
+
const requestPairingCode = (phoneNumber) => __awaiter(void 0, void 0, void 0, function* () {
|
|
378
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
374
379
|
authState.creds.me = {
|
|
375
380
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
376
381
|
name: '~'
|
|
377
382
|
};
|
|
378
383
|
ev.emit('creds.update', authState.creds);
|
|
379
|
-
|
|
384
|
+
yield sendNode({
|
|
380
385
|
tag: 'iq',
|
|
381
386
|
attrs: {
|
|
382
387
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
@@ -397,7 +402,7 @@ const makeSocket = (config) => {
|
|
|
397
402
|
{
|
|
398
403
|
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
399
404
|
attrs: {},
|
|
400
|
-
content:
|
|
405
|
+
content: yield generatePairingKey()
|
|
401
406
|
},
|
|
402
407
|
{
|
|
403
408
|
tag: 'companion_server_auth_key_pub',
|
|
@@ -407,7 +412,7 @@ const makeSocket = (config) => {
|
|
|
407
412
|
{
|
|
408
413
|
tag: 'companion_platform_id',
|
|
409
414
|
attrs: {},
|
|
410
|
-
content:
|
|
415
|
+
content: '49' // Chrome
|
|
411
416
|
},
|
|
412
417
|
{
|
|
413
418
|
tag: 'companion_platform_display',
|
|
@@ -424,13 +429,15 @@ const makeSocket = (config) => {
|
|
|
424
429
|
]
|
|
425
430
|
});
|
|
426
431
|
return authState.creds.pairingCode;
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
432
|
+
});
|
|
433
|
+
function generatePairingKey() {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
436
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
437
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
438
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
439
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
440
|
+
});
|
|
434
441
|
}
|
|
435
442
|
const sendWAMBuffer = (wamBuffer) => {
|
|
436
443
|
return query({
|
|
@@ -450,21 +457,21 @@ const makeSocket = (config) => {
|
|
|
450
457
|
});
|
|
451
458
|
};
|
|
452
459
|
ws.on('message', onMessageReceived);
|
|
453
|
-
ws.on('open',
|
|
460
|
+
ws.on('open', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
454
461
|
try {
|
|
455
|
-
|
|
462
|
+
yield validateConnection();
|
|
456
463
|
}
|
|
457
464
|
catch (err) {
|
|
458
465
|
logger.error({ err }, 'error in validating connection');
|
|
459
466
|
end(err);
|
|
460
467
|
}
|
|
461
|
-
});
|
|
468
|
+
}));
|
|
462
469
|
ws.on('error', mapWebSocketError(end));
|
|
463
470
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
464
471
|
// the server terminated the connection
|
|
465
472
|
ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
466
473
|
// QR gen
|
|
467
|
-
ws.on('CB:iq,type:set,pair-device',
|
|
474
|
+
ws.on('CB:iq,type:set,pair-device', (stanza) => __awaiter(void 0, void 0, void 0, function* () {
|
|
468
475
|
const iq = {
|
|
469
476
|
tag: 'iq',
|
|
470
477
|
attrs: {
|
|
@@ -473,7 +480,7 @@ const makeSocket = (config) => {
|
|
|
473
480
|
id: stanza.attrs.id,
|
|
474
481
|
}
|
|
475
482
|
};
|
|
476
|
-
|
|
483
|
+
yield sendNode(iq);
|
|
477
484
|
const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
|
|
478
485
|
const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
|
|
479
486
|
const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
|
|
@@ -496,38 +503,32 @@ const makeSocket = (config) => {
|
|
|
496
503
|
qrMs = qrTimeout || 20000; // shorter subsequent qrs
|
|
497
504
|
};
|
|
498
505
|
genPairQR();
|
|
499
|
-
});
|
|
506
|
+
}));
|
|
500
507
|
// device paired for the first time
|
|
501
508
|
// if device pairs successfully, the server asks to restart the connection
|
|
502
|
-
ws.on('CB:iq,,pair-success',
|
|
509
|
+
ws.on('CB:iq,,pair-success', (stanza) => __awaiter(void 0, void 0, void 0, function* () {
|
|
503
510
|
logger.debug('pair success recv');
|
|
504
511
|
try {
|
|
505
512
|
const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
|
|
506
513
|
logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
|
|
507
514
|
ev.emit('creds.update', updatedCreds);
|
|
508
515
|
ev.emit('connection.update', { isNewLogin: true, qr: undefined });
|
|
509
|
-
|
|
516
|
+
yield sendNode(reply);
|
|
510
517
|
}
|
|
511
518
|
catch (error) {
|
|
512
519
|
logger.info({ trace: error.stack }, 'error in pairing');
|
|
513
520
|
end(error);
|
|
514
521
|
}
|
|
515
|
-
});
|
|
522
|
+
}));
|
|
516
523
|
// login complete
|
|
517
|
-
ws.on('CB:success',
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
catch (err) {
|
|
527
|
-
logger.error({ err }, 'error opening connection');
|
|
528
|
-
end(err);
|
|
529
|
-
}
|
|
530
|
-
});
|
|
524
|
+
ws.on('CB:success', (node) => __awaiter(void 0, void 0, void 0, function* () {
|
|
525
|
+
yield uploadPreKeysToServerIfRequired();
|
|
526
|
+
yield sendPassiveIq('active');
|
|
527
|
+
logger.info('opened connection to WA');
|
|
528
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
529
|
+
ev.emit('creds.update', { me: Object.assign(Object.assign({}, authState.creds.me), { lid: node.attrs.lid }) });
|
|
530
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
531
|
+
}));
|
|
531
532
|
ws.on('CB:stream:error', (node) => {
|
|
532
533
|
logger.error({ node }, 'stream errored out');
|
|
533
534
|
const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
|
|
@@ -546,7 +547,6 @@ const makeSocket = (config) => {
|
|
|
546
547
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
547
548
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
548
549
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
549
|
-
ev.emit('creds.update', authState.creds);
|
|
550
550
|
}
|
|
551
551
|
});
|
|
552
552
|
let didStartBuffer = false;
|