@baileys-md/baileys 10.1.0 → 11.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 +1 -1
- package/README.md +1303 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.js +1 -0
- package/lib/Defaults/index.js +51 -72
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +94 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +19 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +67 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +50 -0
- package/lib/Signal/Group/sender-key-state.js +96 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +4 -16
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/chats.js +194 -187
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/groups.js +87 -90
- package/lib/Socket/index.js +7 -8
- package/lib/Socket/messages-recv.js +360 -335
- package/lib/Socket/messages-send.js +156 -279
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +144 -213
- package/lib/Socket/socket.js +128 -161
- package/lib/Socket/usync.js +19 -26
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +30 -17
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +31 -47
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +200 -195
- package/lib/Utils/crypto.js +70 -85
- package/lib/Utils/decode-wa-message.js +47 -51
- package/lib/Utils/event-buffer.js +36 -46
- package/lib/Utils/generics.js +116 -188
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -55
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/{Store → Utils}/make-in-memory-store.js +19 -27
- package/lib/Utils/make-mutex.js +7 -10
- package/lib/{Store → Utils}/make-ordered-dictionary.js +1 -3
- package/lib/Utils/messages-media.js +236 -368
- package/lib/Utils/messages.js +278 -510
- package/lib/Utils/noise-handler.js +22 -31
- package/lib/{Store → Utils}/object-repository.js +1 -4
- package/lib/Utils/process-message.js +144 -148
- package/lib/Utils/signal.js +71 -64
- package/lib/Utils/use-multi-file-auth-state.js +112 -84
- package/lib/Utils/validate-connection.js +72 -115
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +15 -52
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/generic-utils.js +31 -39
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +23 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +2257 -2366
- package/lib/WAM/encode.js +17 -21
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/USyncQuery.js +34 -32
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +11 -33
- package/package.json +25 -54
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-mongo-store.js +0 -567
package/lib/Socket/usync.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
-
const { generateMessageTag, query, } = sock;
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
import { USyncQuery } from '../WAUSync/index.js';
|
|
4
|
+
import { makeSocket } from './socket.js';
|
|
5
|
+
export const makeUSyncSocket = (config) => {
|
|
6
|
+
const sock = makeSocket(config);
|
|
7
|
+
const { generateMessageTag, query } = sock;
|
|
10
8
|
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
9
|
if (usyncQuery.protocols.length === 0) {
|
|
12
|
-
throw new
|
|
10
|
+
throw new Boom('USyncQuery must have at least one protocol');
|
|
13
11
|
}
|
|
14
12
|
// todo: validate users, throw WARNING on no valid users
|
|
15
13
|
// variable below has only validated users
|
|
16
14
|
const validUsers = usyncQuery.users;
|
|
17
|
-
const userNodes = validUsers.map(
|
|
15
|
+
const userNodes = validUsers.map(user => {
|
|
18
16
|
return {
|
|
19
17
|
tag: 'user',
|
|
20
18
|
attrs: {
|
|
21
|
-
jid: !user.phone ? user.id : undefined
|
|
19
|
+
jid: !user.phone ? user.id : undefined
|
|
22
20
|
},
|
|
23
|
-
content: usyncQuery.protocols
|
|
24
|
-
.map((a) => a.getUserElement(user))
|
|
25
|
-
.filter(a => a !== null)
|
|
21
|
+
content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
|
|
26
22
|
};
|
|
27
23
|
});
|
|
28
24
|
const listNode = {
|
|
@@ -33,14 +29,14 @@ const makeUSyncSocket = (config) => {
|
|
|
33
29
|
const queryNode = {
|
|
34
30
|
tag: 'query',
|
|
35
31
|
attrs: {},
|
|
36
|
-
content: usyncQuery.protocols.map(
|
|
32
|
+
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
|
37
33
|
};
|
|
38
34
|
const iq = {
|
|
39
35
|
tag: 'iq',
|
|
40
36
|
attrs: {
|
|
41
|
-
to:
|
|
37
|
+
to: S_WHATSAPP_NET,
|
|
42
38
|
type: 'get',
|
|
43
|
-
xmlns: 'usync'
|
|
39
|
+
xmlns: 'usync'
|
|
44
40
|
},
|
|
45
41
|
content: [
|
|
46
42
|
{
|
|
@@ -50,21 +46,18 @@ const makeUSyncSocket = (config) => {
|
|
|
50
46
|
mode: usyncQuery.mode,
|
|
51
47
|
sid: generateMessageTag(),
|
|
52
48
|
last: 'true',
|
|
53
|
-
index: '0'
|
|
49
|
+
index: '0'
|
|
54
50
|
},
|
|
55
|
-
content: [
|
|
56
|
-
queryNode,
|
|
57
|
-
listNode
|
|
58
|
-
]
|
|
51
|
+
content: [queryNode, listNode]
|
|
59
52
|
}
|
|
60
|
-
]
|
|
53
|
+
]
|
|
61
54
|
};
|
|
62
55
|
const result = await query(iq);
|
|
63
56
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
64
57
|
};
|
|
65
58
|
return {
|
|
66
59
|
...sock,
|
|
67
|
-
executeUSyncQuery
|
|
60
|
+
executeUSyncQuery
|
|
68
61
|
};
|
|
69
62
|
};
|
|
70
|
-
|
|
63
|
+
//# sourceMappingURL=usync.js.map
|
package/lib/Types/Auth.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=Auth.js.map
|
package/lib/Types/Call.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=Call.js.map
|
package/lib/Types/Chat.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export const ALL_WA_PATCH_NAMES = [
|
|
2
|
+
'critical_block',
|
|
3
|
+
'critical_unblock_low',
|
|
4
|
+
'regular_high',
|
|
5
|
+
'regular_low',
|
|
6
|
+
'regular'
|
|
7
|
+
];
|
|
8
|
+
//# sourceMappingURL=Chat.js.map
|
package/lib/Types/Contact.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=Contact.js.map
|
package/lib/Types/Events.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
//# sourceMappingURL=Events.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=GroupMetadata.js.map
|
package/lib/Types/Label.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LabelColor = void 0;
|
|
4
1
|
/** WhatsApp has 20 predefined colors */
|
|
5
|
-
var LabelColor;
|
|
2
|
+
export var LabelColor;
|
|
6
3
|
(function (LabelColor) {
|
|
7
4
|
LabelColor[LabelColor["Color1"] = 0] = "Color1";
|
|
8
5
|
LabelColor[LabelColor["Color2"] = 1] = "Color2";
|
|
@@ -24,4 +21,5 @@ var LabelColor;
|
|
|
24
21
|
LabelColor[LabelColor["Color18"] = 17] = "Color18";
|
|
25
22
|
LabelColor[LabelColor["Color19"] = 18] = "Color19";
|
|
26
23
|
LabelColor[LabelColor["Color20"] = 19] = "Color20";
|
|
27
|
-
})(LabelColor || (
|
|
24
|
+
})(LabelColor || (LabelColor = {}));
|
|
25
|
+
//# sourceMappingURL=Label.js.map
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LabelAssociationType = void 0;
|
|
4
1
|
/** Association type */
|
|
5
|
-
var LabelAssociationType;
|
|
2
|
+
export var LabelAssociationType;
|
|
6
3
|
(function (LabelAssociationType) {
|
|
7
4
|
LabelAssociationType["Chat"] = "label_jid";
|
|
8
5
|
LabelAssociationType["Message"] = "label_message";
|
|
9
|
-
})(LabelAssociationType || (
|
|
6
|
+
})(LabelAssociationType || (LabelAssociationType = {}));
|
|
7
|
+
//# sourceMappingURL=LabelAssociation.js.map
|
package/lib/Types/Message.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults/index.js';
|
|
3
|
+
// export the WAMessage Prototypes
|
|
4
|
+
export { proto as WAProto };
|
|
5
|
+
export const WAMessageStubType = proto.WebMessageInfo.StubType;
|
|
6
|
+
export const WAMessageStatus = proto.WebMessageInfo.Status;
|
|
7
|
+
//# sourceMappingURL=Message.js.map
|
package/lib/Types/Newsletter.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XWAPaths = exports.MexOperations = void 0;
|
|
4
|
-
var MexOperations;
|
|
5
|
-
(function (MexOperations) {
|
|
6
|
-
MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
|
|
7
|
-
MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
|
|
8
|
-
MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
|
|
9
|
-
})(MexOperations || (exports.MexOperations = MexOperations = {}));
|
|
10
|
-
var XWAPaths;
|
|
1
|
+
export var XWAPaths;
|
|
11
2
|
(function (XWAPaths) {
|
|
12
|
-
XWAPaths["
|
|
13
|
-
XWAPaths["
|
|
14
|
-
XWAPaths["
|
|
15
|
-
XWAPaths["
|
|
16
|
-
XWAPaths["
|
|
17
|
-
XWAPaths["
|
|
18
|
-
|
|
3
|
+
XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
|
|
4
|
+
XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
|
|
5
|
+
XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
|
|
6
|
+
XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
|
|
7
|
+
XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
|
|
8
|
+
XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
|
|
9
|
+
XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
|
|
10
|
+
XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
|
|
11
|
+
XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
|
|
12
|
+
XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
|
|
13
|
+
XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
|
|
14
|
+
XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
|
|
15
|
+
})(XWAPaths || (XWAPaths = {}));
|
|
16
|
+
export var QueryIds;
|
|
17
|
+
(function (QueryIds) {
|
|
18
|
+
QueryIds["CREATE"] = "8823471724422422";
|
|
19
|
+
QueryIds["UPDATE_METADATA"] = "24250201037901610";
|
|
20
|
+
QueryIds["METADATA"] = "6563316087068696";
|
|
21
|
+
QueryIds["SUBSCRIBERS"] = "9783111038412085";
|
|
22
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
23
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
24
|
+
QueryIds["MUTE"] = "29766401636284406";
|
|
25
|
+
QueryIds["UNMUTE"] = "9864994326891137";
|
|
26
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
27
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
28
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
29
|
+
QueryIds["DELETE"] = "30062808666639665";
|
|
30
|
+
})(QueryIds || (QueryIds = {}));
|
|
31
|
+
//# sourceMappingURL=Newsletter.js.map
|
package/lib/Types/Product.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=Product.js.map
|
package/lib/Types/Signal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
//# sourceMappingURL=Signal.js.map
|
package/lib/Types/Socket.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import {} from './Message.js';
|
|
3
|
+
//# sourceMappingURL=Socket.js.map
|
package/lib/Types/State.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
//# sourceMappingURL=State.js.map
|
package/lib/Types/USync.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { USyncUser } from '../WAUSync/index.js';
|
|
2
|
+
//# sourceMappingURL=USync.js.map
|
package/lib/Types/index.js
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.DisconnectReason = void 0;
|
|
18
|
-
__exportStar(require("./Auth"), exports);
|
|
19
|
-
__exportStar(require("./GroupMetadata"), exports);
|
|
20
|
-
__exportStar(require("./Newsletter"), exports);
|
|
21
|
-
__exportStar(require("./Chat"), exports);
|
|
22
|
-
__exportStar(require("./Contact"), exports);
|
|
23
|
-
__exportStar(require("./State"), exports);
|
|
24
|
-
__exportStar(require("./Message"), exports);
|
|
25
|
-
__exportStar(require("./Socket"), exports);
|
|
26
|
-
__exportStar(require("./Events"), exports);
|
|
27
|
-
__exportStar(require("./Product"), exports);
|
|
28
|
-
__exportStar(require("./Call"), exports);
|
|
29
|
-
__exportStar(require("./Signal"), exports);
|
|
30
|
-
var DisconnectReason;
|
|
1
|
+
export * from './Auth.js';
|
|
2
|
+
export * from './GroupMetadata.js';
|
|
3
|
+
export * from './Chat.js';
|
|
4
|
+
export * from './Contact.js';
|
|
5
|
+
export * from './State.js';
|
|
6
|
+
export * from './Message.js';
|
|
7
|
+
export * from './Socket.js';
|
|
8
|
+
export * from './Events.js';
|
|
9
|
+
export * from './Product.js';
|
|
10
|
+
export * from './Call.js';
|
|
11
|
+
export * from './Signal.js';
|
|
12
|
+
export * from './Newsletter.js';
|
|
13
|
+
export var DisconnectReason;
|
|
31
14
|
(function (DisconnectReason) {
|
|
32
15
|
DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
|
|
33
16
|
DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
|
|
@@ -39,4 +22,5 @@ var DisconnectReason;
|
|
|
39
22
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
40
23
|
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
41
24
|
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
42
|
-
})(DisconnectReason || (
|
|
25
|
+
})(DisconnectReason || (DisconnectReason = {}));
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
7
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
8
|
-
const crypto_1 = require("crypto");
|
|
9
|
-
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
const Defaults_1 = require("../Defaults");
|
|
12
|
-
const crypto_2 = require("./crypto");
|
|
13
|
-
const generics_1 = require("./generics");
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
3
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
4
|
+
import { Curve, signedKeyPair } from './crypto.js';
|
|
5
|
+
import { delay, generateRegistrationId } from './generics.js';
|
|
14
6
|
/**
|
|
15
7
|
* Adds caching capability to a SignalKeyStore
|
|
16
8
|
* @param store the store to add caching to
|
|
17
9
|
* @param logger to log trace events
|
|
18
10
|
* @param _cache cache store to use
|
|
19
11
|
*/
|
|
20
|
-
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
21
|
-
const cache = _cache ||
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
13
|
+
const cache = _cache ||
|
|
14
|
+
new NodeCache({
|
|
15
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
16
|
+
useClones: false,
|
|
17
|
+
deleteOnExpire: true
|
|
18
|
+
});
|
|
26
19
|
function getUniqueId(type, id) {
|
|
27
20
|
return `${type}.${id}`;
|
|
28
21
|
}
|
|
@@ -40,7 +33,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
35
|
if (idsToFetch.length) {
|
|
43
|
-
logger
|
|
36
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
44
37
|
const fetched = await store.get(type, idsToFetch);
|
|
45
38
|
for (const id of idsToFetch) {
|
|
46
39
|
const item = fetched[id];
|
|
@@ -60,13 +53,12 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
60
53
|
keys += 1;
|
|
61
54
|
}
|
|
62
55
|
}
|
|
63
|
-
logger
|
|
56
|
+
logger?.trace({ keys }, 'updated cache');
|
|
64
57
|
await store.set(data);
|
|
65
58
|
},
|
|
66
59
|
async clear() {
|
|
67
|
-
var _a;
|
|
68
60
|
cache.flushAll();
|
|
69
|
-
await
|
|
61
|
+
await store.clear?.();
|
|
70
62
|
}
|
|
71
63
|
};
|
|
72
64
|
}
|
|
@@ -77,7 +69,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
77
69
|
* @param logger logger to log events
|
|
78
70
|
* @returns SignalKeyStore with transaction capability
|
|
79
71
|
*/
|
|
80
|
-
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
72
|
+
export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
81
73
|
// number of queries made to the DB during the transaction
|
|
82
74
|
// only there for logging purposes
|
|
83
75
|
let dbQueriesInTransaction = 0;
|
|
@@ -88,9 +80,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
88
80
|
get: async (type, ids) => {
|
|
89
81
|
if (isInTransaction()) {
|
|
90
82
|
const dict = transactionCache[type];
|
|
91
|
-
const idsRequiringFetch = dict
|
|
92
|
-
? ids.filter(item => typeof dict[item] === 'undefined')
|
|
93
|
-
: ids;
|
|
83
|
+
const idsRequiringFetch = dict ? ids.filter(item => typeof dict[item] === 'undefined') : ids;
|
|
94
84
|
// only fetch if there are any items to fetch
|
|
95
85
|
if (idsRequiringFetch.length) {
|
|
96
86
|
dbQueriesInTransaction += 1;
|
|
@@ -99,8 +89,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
99
89
|
Object.assign(transactionCache[type], result);
|
|
100
90
|
}
|
|
101
91
|
return ids.reduce((dict, id) => {
|
|
102
|
-
|
|
103
|
-
const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
|
|
92
|
+
const value = transactionCache[type]?.[id];
|
|
104
93
|
if (value) {
|
|
105
94
|
dict[id] = value;
|
|
106
95
|
}
|
|
@@ -114,7 +103,8 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
114
103
|
set: data => {
|
|
115
104
|
if (isInTransaction()) {
|
|
116
105
|
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
117
|
-
for (const
|
|
106
|
+
for (const key_ in data) {
|
|
107
|
+
const key = key_;
|
|
118
108
|
transactionCache[key] = transactionCache[key] || {};
|
|
119
109
|
Object.assign(transactionCache[key], data[key]);
|
|
120
110
|
mutations[key] = mutations[key] || {};
|
|
@@ -143,6 +133,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
143
133
|
let tries = maxCommitRetries;
|
|
144
134
|
while (tries) {
|
|
145
135
|
tries -= 1;
|
|
136
|
+
//eslint-disable-next-line max-depth
|
|
146
137
|
try {
|
|
147
138
|
await state.set(mutations);
|
|
148
139
|
logger.trace({ dbQueriesInTransaction }, 'committed transaction');
|
|
@@ -150,7 +141,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
150
141
|
}
|
|
151
142
|
catch (error) {
|
|
152
143
|
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
153
|
-
await
|
|
144
|
+
await delay(delayBetweenTriesMs);
|
|
154
145
|
}
|
|
155
146
|
}
|
|
156
147
|
}
|
|
@@ -174,16 +165,15 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
174
165
|
return transactionsInProgress > 0;
|
|
175
166
|
}
|
|
176
167
|
};
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
168
|
+
export const initAuthCreds = () => {
|
|
169
|
+
const identityKey = Curve.generateKeyPair();
|
|
180
170
|
return {
|
|
181
|
-
noiseKey:
|
|
182
|
-
pairingEphemeralKeyPair:
|
|
171
|
+
noiseKey: Curve.generateKeyPair(),
|
|
172
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
183
173
|
signedIdentityKey: identityKey,
|
|
184
|
-
signedPreKey:
|
|
185
|
-
registrationId:
|
|
186
|
-
advSecretKey:
|
|
174
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
175
|
+
registrationId: generateRegistrationId(),
|
|
176
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
187
177
|
processedHistoryMessages: [],
|
|
188
178
|
nextPreKeyId: 1,
|
|
189
179
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -191,16 +181,10 @@ const initAuthCreds = () => {
|
|
|
191
181
|
accountSettings: {
|
|
192
182
|
unarchiveChats: false
|
|
193
183
|
},
|
|
194
|
-
// mobile creds
|
|
195
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
-
phoneId: (0, uuid_1.v4)(),
|
|
197
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
198
184
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
185
|
pairingCode: undefined,
|
|
202
186
|
lastPropHash: undefined,
|
|
203
|
-
routingInfo: undefined
|
|
187
|
+
routingInfo: undefined
|
|
204
188
|
};
|
|
205
189
|
};
|
|
206
|
-
|
|
190
|
+
//# sourceMappingURL=auth-utils.js.map
|
|
@@ -1,46 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const promises_1 = require("fs/promises");
|
|
10
|
-
const readline_1 = require("readline");
|
|
11
|
-
const generics_1 = require("./generics");
|
|
12
|
-
const make_mutex_1 = require("./make-mutex");
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { createReadStream } from 'fs';
|
|
3
|
+
import { writeFile } from 'fs/promises';
|
|
4
|
+
import { createInterface } from 'readline';
|
|
5
|
+
import { delay } from './generics.js';
|
|
6
|
+
import { makeMutex } from './make-mutex.js';
|
|
13
7
|
/**
|
|
14
8
|
* Captures events from a baileys event emitter & stores them in a file
|
|
15
9
|
* @param ev The event emitter to read events from
|
|
16
10
|
* @param filename File to save to
|
|
17
11
|
*/
|
|
18
|
-
const captureEventStream = (ev, filename) => {
|
|
12
|
+
export const captureEventStream = (ev, filename) => {
|
|
19
13
|
const oldEmit = ev.emit;
|
|
20
14
|
// write mutex so data is appended in order
|
|
21
|
-
const writeMutex =
|
|
15
|
+
const writeMutex = makeMutex();
|
|
22
16
|
// monkey patch eventemitter to capture all events
|
|
23
17
|
ev.emit = function (...args) {
|
|
24
18
|
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
|
|
25
19
|
const result = oldEmit.apply(ev, args);
|
|
26
20
|
writeMutex.mutex(async () => {
|
|
27
|
-
await
|
|
21
|
+
await writeFile(filename, content, { flag: 'a' });
|
|
28
22
|
});
|
|
29
23
|
return result;
|
|
30
24
|
};
|
|
31
25
|
};
|
|
32
|
-
exports.captureEventStream = captureEventStream;
|
|
33
26
|
/**
|
|
34
27
|
* Read event file and emit events from there
|
|
35
28
|
* @param filename filename containing event data
|
|
36
29
|
* @param delayIntervalMs delay between each event emit
|
|
37
30
|
*/
|
|
38
|
-
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
39
|
-
const ev = new
|
|
31
|
+
export const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
32
|
+
const ev = new EventEmitter();
|
|
40
33
|
const fireEvents = async () => {
|
|
41
34
|
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
|
42
|
-
const fileStream =
|
|
43
|
-
const rl =
|
|
35
|
+
const fileStream = createReadStream(filename);
|
|
36
|
+
const rl = createInterface({
|
|
44
37
|
input: fileStream,
|
|
45
38
|
crlfDelay: Infinity
|
|
46
39
|
});
|
|
@@ -50,7 +43,7 @@ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
50
43
|
if (line) {
|
|
51
44
|
const { event, data } = JSON.parse(line);
|
|
52
45
|
ev.emit(event, data);
|
|
53
|
-
delayIntervalMs && await
|
|
46
|
+
delayIntervalMs && (await delay(delayIntervalMs));
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
49
|
fileStream.close();
|
|
@@ -60,4 +53,4 @@ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
|
60
53
|
task: fireEvents()
|
|
61
54
|
};
|
|
62
55
|
};
|
|
63
|
-
|
|
56
|
+
//# sourceMappingURL=baileys-event-stream.js.map
|