@skyzopedia/baileys-mod 5.0.8 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/index.js +133384 -57814
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +141 -117
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -12
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +42 -10
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +87 -75
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -13
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +52 -17
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +33 -27
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -62
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +66 -65
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +44 -45
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +49 -39
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +93 -80
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +28 -27
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +163 -313
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -4
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +242 -359
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +935 -846
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +309 -304
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +10 -15
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1054 -1107
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +447 -706
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +314 -199
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +650 -777
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -6
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +81 -73
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +423 -286
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +79 -77
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +26 -24
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Chat.js +4 -9
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +26 -24
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +8 -6
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Message.js +9 -12
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -33
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/Socket.js +2 -4
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -11
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.d.ts +57 -0
- package/lib/Types/index.js +41 -27
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +198 -211
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +61 -42
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +214 -213
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +687 -710
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +133 -112
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +183 -252
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +496 -510
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +392 -319
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +92 -83
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -21
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +83 -71
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +7 -5
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +46 -40
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +41 -34
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +768 -550
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +263 -362
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +149 -138
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +303 -323
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +141 -149
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +103 -95
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +214 -183
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +35 -1298
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -237
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +260 -213
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +65 -56
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -7
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +58 -89
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/BinaryInfo.js +12 -10
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15348 -22851
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +136 -135
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -49
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +28 -27
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -36
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +20 -26
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +85 -86
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +25 -23
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +36 -24
- package/package.json +106 -98
- package/LICENSE +0 -21
- package/WAProto/WAProto.proto +0 -5311
- package/lib/KeyDB/BinarySearch.js +0 -20
- package/lib/KeyDB/KeyedDB.js +0 -167
- package/lib/KeyDB/index.js +0 -4
- package/lib/Signal/lid-mapping.js +0 -155
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -52
- package/lib/Socket/Client/websocket.js.bak +0 -53
- package/lib/Socket/communities.js +0 -413
- package/lib/Socket/mex.js +0 -45
- package/lib/Types/Bussines.js +0 -3
- package/lib/Types/Newsletter.js.bak +0 -33
- package/lib/Utils/browser-utils.js +0 -25
- package/lib/Utils/message-retry-manager.js +0 -113
- package/lib/Utils/messages.js.bak +0 -907
- package/lib/Utils/pre-key-manager.js +0 -85
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SignalRepository } from '../Types';
|
|
2
|
+
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
|
+
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
4
|
+
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
5
|
+
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
6
|
+
[id: string]: KeyPair;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
9
|
+
newPreKeys: {
|
|
10
|
+
[id: number]: KeyPair;
|
|
11
|
+
};
|
|
12
|
+
lastPreKeyId: number;
|
|
13
|
+
preKeysRange: readonly [number, number];
|
|
14
|
+
};
|
|
15
|
+
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
16
|
+
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
17
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
18
|
+
export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
19
|
+
/**
|
|
20
|
+
* get the next N keys for upload or processing
|
|
21
|
+
* @param count number of pre-keys to get or generate
|
|
22
|
+
*/
|
|
23
|
+
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
24
|
+
update: Partial<AuthenticationCreds>;
|
|
25
|
+
preKeys: {
|
|
26
|
+
[id: string]: KeyPair;
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
30
|
+
update: Partial<AuthenticationCreds>;
|
|
31
|
+
node: BinaryNode;
|
|
32
|
+
}>;
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,161 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
//=======================================================//
|
|
15
|
-
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
16
|
-
return {
|
|
17
|
-
identifier: { name: wid, deviceId: 0 },
|
|
18
|
-
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
19
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
+
const Defaults_1 = require("../Defaults");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const crypto_1 = require("./crypto");
|
|
7
|
+
const lodash_1 = require("lodash")
|
|
8
|
+
const generics_1 = require("./generics");
|
|
9
|
+
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
10
|
+
return {
|
|
11
|
+
identifier: { name: wid, deviceId: 0 },
|
|
12
|
+
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
13
|
+
};
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
exports.createSignalIdentity = createSignalIdentity;
|
|
16
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
17
|
+
const idList = [];
|
|
18
|
+
for (let id = min; id < limit; id++) {
|
|
19
|
+
idList.push(id.toString());
|
|
20
|
+
}
|
|
21
|
+
return get('pre-key', idList);
|
|
28
22
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
exports.getPreKeys = getPreKeys;
|
|
24
|
+
const generateOrGetPreKeys = (creds, range) => {
|
|
25
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
26
|
+
const remaining = range - avaliable;
|
|
27
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
28
|
+
const newPreKeys = {};
|
|
29
|
+
if (remaining > 0) {
|
|
30
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
31
|
+
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
32
|
+
}
|
|
38
33
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
34
|
+
return {
|
|
35
|
+
newPreKeys,
|
|
36
|
+
lastPreKeyId,
|
|
37
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
38
|
+
};
|
|
45
39
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
41
|
+
const xmppSignedPreKey = (key) => ({
|
|
42
|
+
tag: 'skey',
|
|
43
|
+
attrs: {},
|
|
44
|
+
content: [
|
|
45
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
46
|
+
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
+
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
+
]
|
|
55
49
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
51
|
+
const xmppPreKey = (pair, id) => ({
|
|
52
|
+
tag: 'key',
|
|
53
|
+
attrs: {},
|
|
54
|
+
content: [
|
|
55
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
56
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
57
|
+
]
|
|
64
58
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
exports.xmppPreKey = xmppPreKey;
|
|
60
|
+
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
61
|
+
const extractKey = (key) => (key ? ({
|
|
62
|
+
keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
|
|
63
|
+
publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
|
|
64
|
+
signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
|
|
65
|
+
}) : undefined)
|
|
66
|
+
const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
|
|
67
|
+
for (const node of nodes) {
|
|
68
|
+
WABinary_1.assertNodeErrorFree(node)
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
|
+
// So Promise.all doesn't really help here,
|
|
72
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
75
|
+
const chunkSize = 100
|
|
76
|
+
const chunks = lodash_1.chunk(nodes, chunkSize)
|
|
77
|
+
for (const nodesChunk of chunks) {
|
|
78
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
79
|
+
const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
|
|
80
|
+
const key = WABinary_1.getBinaryNodeChild(node, 'key')
|
|
81
|
+
const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
|
|
82
|
+
const jid = node.attrs.jid
|
|
83
|
+
const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
|
|
84
|
+
await repository.injectE2ESession({
|
|
85
|
+
jid,
|
|
86
|
+
session: {
|
|
87
|
+
registrationId: registrationId,
|
|
88
|
+
identityKey: crypto_1.generateSignalPubKey(identity),
|
|
89
|
+
signedPreKey: extractKey(signedKey),
|
|
90
|
+
preKey: extractKey(key)
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}))
|
|
96
94
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (isHosted) {
|
|
116
|
-
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
95
|
+
}
|
|
96
|
+
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
97
|
+
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
98
|
+
const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
|
|
99
|
+
const extracted = []
|
|
100
|
+
for (const userResult of result) {
|
|
101
|
+
const { devices, id } = userResult
|
|
102
|
+
const { user } = WABinary_1.jidDecode(id)
|
|
103
|
+
const deviceList = devices?.deviceList
|
|
104
|
+
if (Array.isArray(deviceList)) {
|
|
105
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
106
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
107
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
108
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
109
|
+
) {
|
|
110
|
+
extracted.push({ user, device })
|
|
111
|
+
}
|
|
112
|
+
}
|
|
117
113
|
}
|
|
118
|
-
extracted.push({
|
|
119
|
-
user,
|
|
120
|
-
device,
|
|
121
|
-
domainType,
|
|
122
|
-
server: getServerFromDomainType(server, domainType)
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
114
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
115
|
+
return extracted
|
|
116
|
+
}
|
|
117
|
+
exports.extractDeviceJids = extractDeviceJids;
|
|
118
|
+
/**
|
|
119
|
+
* get the next N keys for upload or processing
|
|
120
|
+
* @param count number of pre-keys to get or generate
|
|
121
|
+
*/
|
|
122
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
123
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
124
|
+
const update = {
|
|
125
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
126
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
127
|
+
};
|
|
128
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
129
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
130
|
+
return { update, preKeys };
|
|
139
131
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
132
|
+
exports.getNextPreKeys = getNextPreKeys;
|
|
133
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
134
|
+
const { creds } = state;
|
|
135
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
136
|
+
const node = {
|
|
137
|
+
tag: 'iq',
|
|
138
|
+
attrs: {
|
|
139
|
+
xmlns: 'encrypt',
|
|
140
|
+
type: 'set',
|
|
141
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
142
|
+
},
|
|
143
|
+
content: [
|
|
144
|
+
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
145
|
+
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
146
|
+
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
147
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
148
|
+
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
149
|
+
]
|
|
150
|
+
};
|
|
151
|
+
return { update, node };
|
|
160
152
|
};
|
|
161
|
-
|
|
153
|
+
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthenticationState } from '../Types';
|
|
2
|
+
/**
|
|
3
|
+
* stores the full authentication state in a single folder.
|
|
4
|
+
* Far more efficient than singlefileauthstate
|
|
5
|
+
*
|
|
6
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
7
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
8
|
+
* */
|
|
9
|
+
export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
10
|
+
state: AuthenticationState;
|
|
11
|
+
saveCreds: () => Promise<void>;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
@@ -1,111 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const auth_utils_1 = require("./auth-utils");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
9
10
|
const fileLocks = new Map();
|
|
10
11
|
const getFileLock = (path) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
let mutex = fileLocks.get(path);
|
|
13
|
+
if (!mutex) {
|
|
14
|
+
mutex = new async_mutex_1.Mutex();
|
|
15
|
+
fileLocks.set(path, mutex);
|
|
16
|
+
}
|
|
17
|
+
return mutex;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
/**
|
|
20
|
+
* stores the full authentication state in a single folder.
|
|
21
|
+
* Far more efficient than singlefileauthstate
|
|
22
|
+
*
|
|
23
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
24
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
25
|
+
* */
|
|
26
|
+
const useMultiFileAuthState = async (folder) => {
|
|
27
|
+
const writeData = async (data, file) => {
|
|
28
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
29
|
+
const mutex = getFileLock(filePath);
|
|
30
|
+
return mutex.acquire().then(async (release) => {
|
|
31
|
+
try {
|
|
32
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
release();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const readData = async (file) => {
|
|
37
40
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
42
|
+
const mutex = getFileLock(filePath);
|
|
43
|
+
return await mutex.acquire().then(async (release) => {
|
|
44
|
+
try {
|
|
45
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
46
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
release();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
40
52
|
}
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
catch (error) {
|
|
54
|
+
return null;
|
|
43
55
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
catch (error) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const removeData = async (file) => {
|
|
51
|
-
try {
|
|
52
|
-
const filePath = join(folder, fixFileName(file));
|
|
53
|
-
const mutex = getFileLock(filePath);
|
|
54
|
-
return mutex.acquire().then(async (release) => {
|
|
56
|
+
};
|
|
57
|
+
const removeData = async (file) => {
|
|
55
58
|
try {
|
|
56
|
-
|
|
59
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
60
|
+
const mutex = getFileLock(filePath);
|
|
61
|
+
return mutex.acquire().then(async (release) => {
|
|
62
|
+
try {
|
|
63
|
+
await (0, promises_1.unlink)(filePath);
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
release();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
57
71
|
}
|
|
58
|
-
catch {
|
|
72
|
+
catch (_a) {
|
|
59
73
|
}
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
};
|
|
75
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
76
|
+
if (folderInfo) {
|
|
77
|
+
if (!folderInfo.isDirectory()) {
|
|
78
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
62
79
|
}
|
|
63
|
-
});
|
|
64
80
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const folderInfo = await stat(folder).catch(() => { });
|
|
68
|
-
if (folderInfo) {
|
|
69
|
-
if (!folderInfo.isDirectory()) {
|
|
70
|
-
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
81
|
+
else {
|
|
82
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
71
83
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
85
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
86
|
+
return {
|
|
87
|
+
state: {
|
|
88
|
+
creds,
|
|
89
|
+
keys: {
|
|
90
|
+
get: async (type, ids) => {
|
|
91
|
+
const data = {};
|
|
92
|
+
await Promise.all(ids.map(async (id) => {
|
|
93
|
+
let value = await readData(`${type}-${id}.json`);
|
|
94
|
+
if (type === 'app-state-sync-key' && value) {
|
|
95
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
96
|
+
}
|
|
97
|
+
data[id] = value;
|
|
98
|
+
}));
|
|
99
|
+
return data;
|
|
100
|
+
},
|
|
101
|
+
set: async (data) => {
|
|
102
|
+
const tasks = [];
|
|
103
|
+
for (const category in data) {
|
|
104
|
+
for (const id in data[category]) {
|
|
105
|
+
const value = data[category][id];
|
|
106
|
+
const file = `${category}-${id}.json`;
|
|
107
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
await Promise.all(tasks);
|
|
111
|
+
}
|
|
88
112
|
}
|
|
89
|
-
data[id] = value;
|
|
90
|
-
}));
|
|
91
|
-
return data;
|
|
92
113
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
for (const category in data) {
|
|
96
|
-
for (const id in data[category]) {
|
|
97
|
-
const value = data[category][id];
|
|
98
|
-
const file = `${category}-${id}.json`;
|
|
99
|
-
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
await Promise.all(tasks);
|
|
114
|
+
saveCreds: async () => {
|
|
115
|
+
return writeData(creds, 'creds.json');
|
|
103
116
|
}
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
saveCreds: async () => {
|
|
107
|
-
return writeData(creds, "creds.json");
|
|
108
|
-
}
|
|
109
|
-
};
|
|
117
|
+
};
|
|
110
118
|
};
|
|
111
|
-
|
|
119
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
|
|
5
|
+
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
6
|
+
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
7
|
+
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
8
|
+
creds: Partial<AuthenticationCreds>;
|
|
9
|
+
reply: BinaryNode;
|
|
10
|
+
};
|
|
11
|
+
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
|