@alannxd/baileys 6.0.5 → 6.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/fix-import.js +29 -0
- package/WAProto/index.js +160 -201
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +15 -37
- package/lib/Defaults/index.js +136 -119
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -7
- 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 +2 -3
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +2 -3
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.d.ts +6 -7
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +90 -347
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- 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/{websocket.d.ts → web-socket-client.d.ts} +2 -3
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -154
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.d.ts +239 -96
- package/lib/Socket/chats.js +427 -627
- package/lib/Socket/communities.d.ts +146 -239
- package/lib/Socket/communities.js +80 -90
- package/lib/Socket/groups.d.ts +57 -104
- package/lib/Socket/groups.js +161 -154
- package/lib/Socket/index.d.ts +115 -202
- package/lib/Socket/index.js +10 -11
- package/lib/Socket/luxu.d.ts +266 -22
- package/lib/Socket/luxu.js +465 -422
- package/lib/Socket/messages-recv.d.ts +84 -136
- package/lib/Socket/messages-recv.js +615 -1421
- package/lib/Socket/messages-send.d.ts +126 -142
- package/lib/Socket/messages-send.js +671 -878
- package/lib/Socket/newsletter.d.ts +85 -121
- package/lib/Socket/newsletter.js +272 -147
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +19 -34
- package/lib/Socket/socket.js +313 -544
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -10
- package/lib/Store/index.js +10 -10
- package/lib/Store/make-cache-manager-store.d.ts +11 -17
- package/lib/Store/make-cache-manager-store.js +41 -43
- package/lib/Store/make-in-memory-store.d.ts +118 -39
- package/lib/Store/make-in-memory-store.js +341 -112
- package/lib/Store/make-ordered-dictionary.d.ts +10 -11
- package/lib/Store/make-ordered-dictionary.js +20 -14
- package/lib/Store/object-repository.d.ts +9 -10
- package/lib/Store/object-repository.js +6 -11
- package/lib/Types/Auth.d.ts +12 -19
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -3
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -35
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +17 -116
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -21
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -12
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +58 -105
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +2 -32
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -50
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -72
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -22
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -12
- package/lib/Utils/auth-utils.js +143 -239
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +23 -52
- package/lib/Utils/chat-utils.js +253 -396
- package/lib/Utils/crypto.d.ts +22 -18
- package/lib/Utils/crypto.js +90 -57
- package/lib/Utils/decode-wa-message.d.ts +8 -55
- package/lib/Utils/decode-wa-message.js +84 -203
- package/lib/Utils/event-buffer.d.ts +8 -9
- package/lib/Utils/event-buffer.js +77 -185
- package/lib/Utils/generics.d.ts +29 -28
- package/lib/Utils/generics.js +210 -180
- package/lib/Utils/history.d.ts +9 -18
- package/lib/Utils/history.js +55 -93
- package/lib/Utils/index.d.ts +17 -22
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +24 -16
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +12 -8
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.d.ts +2 -4
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.d.ts +44 -61
- package/lib/Utils/messages-media.js +482 -451
- package/lib/Utils/messages.d.ts +18 -32
- package/lib/Utils/messages.js +369 -458
- package/lib/Utils/noise-handler.d.ts +14 -13
- package/lib/Utils/noise-handler.js +99 -145
- package/lib/Utils/process-message.d.ts +12 -31
- package/lib/Utils/process-message.js +150 -459
- package/lib/Utils/signal.d.ts +5 -20
- package/lib/Utils/signal.js +72 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +27 -29
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +99 -73
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +42 -52
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +7 -8
- package/lib/WABinary/generic-utils.js +49 -48
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +8 -25
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -6
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.d.ts +4 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.d.ts +5 -10
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -10
- package/lib/index.js +34 -12
- package/package.json +50 -83
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5479
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -277
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -54
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Store/keyed-db.d.ts +0 -22
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Mex.js +0 -37
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/message-retry-manager.js +0 -265
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/reporting-utils.js +0 -258
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/stanza-ack.js +0 -38
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/sync-action-utils.js +0 -49
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/tc-token-utils.js +0 -163
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/index.d.ts +0 -4
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import type { USyncQueryResultList } from '../WAUSync/index.js';
|
|
1
|
+
import { SignalRepository } from '../Types';
|
|
2
|
+
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
|
+
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
5
4
|
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
5
|
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
6
|
[id: string]: KeyPair;
|
|
@@ -15,21 +14,8 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
|
|
|
15
14
|
};
|
|
16
15
|
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
16
|
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
|
-
export declare const
|
|
19
|
-
|
|
20
|
-
identityKey: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
21
|
-
signedPreKey: {
|
|
22
|
-
keyId: number;
|
|
23
|
-
publicKey: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
24
|
-
signature: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
25
|
-
};
|
|
26
|
-
preKey: {
|
|
27
|
-
keyId: number;
|
|
28
|
-
publicKey: Uint8Array;
|
|
29
|
-
} | undefined;
|
|
30
|
-
} | null;
|
|
31
|
-
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
|
|
32
|
-
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
|
|
17
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
18
|
+
export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
33
19
|
/**
|
|
34
20
|
* get the next N keys for upload or processing
|
|
35
21
|
* @param count number of pre-keys to get or generate
|
|
@@ -44,4 +30,3 @@ export declare const getNextPreKeysNode: (state: AuthenticationState, count: num
|
|
|
44
30
|
update: Partial<AuthenticationCreds>;
|
|
45
31
|
node: BinaryNode;
|
|
46
32
|
}>;
|
|
47
|
-
//# sourceMappingURL=signal.d.ts.map
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,201 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return chunks;
|
|
11
|
-
}
|
|
12
|
-
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
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) => {
|
|
13
10
|
return {
|
|
14
11
|
identifier: { name: wid, deviceId: 0 },
|
|
15
|
-
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
12
|
+
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
16
13
|
};
|
|
17
14
|
};
|
|
18
|
-
|
|
15
|
+
exports.createSignalIdentity = createSignalIdentity;
|
|
16
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
19
17
|
const idList = [];
|
|
20
18
|
for (let id = min; id < limit; id++) {
|
|
21
19
|
idList.push(id.toString());
|
|
22
20
|
}
|
|
23
21
|
return get('pre-key', idList);
|
|
24
22
|
};
|
|
25
|
-
|
|
23
|
+
exports.getPreKeys = getPreKeys;
|
|
24
|
+
const generateOrGetPreKeys = (creds, range) => {
|
|
26
25
|
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
26
|
const remaining = range - avaliable;
|
|
28
27
|
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
28
|
const newPreKeys = {};
|
|
30
29
|
if (remaining > 0) {
|
|
31
30
|
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
-
newPreKeys[i] = Curve.generateKeyPair();
|
|
31
|
+
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
return {
|
|
36
35
|
newPreKeys,
|
|
37
36
|
lastPreKeyId,
|
|
38
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
37
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
39
38
|
};
|
|
40
39
|
};
|
|
41
|
-
|
|
40
|
+
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
41
|
+
const xmppSignedPreKey = (key) => ({
|
|
42
42
|
tag: 'skey',
|
|
43
43
|
attrs: {},
|
|
44
44
|
content: [
|
|
45
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
45
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
46
46
|
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
47
|
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
48
|
]
|
|
49
49
|
});
|
|
50
|
-
|
|
50
|
+
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
51
|
+
const xmppPreKey = (pair, id) => ({
|
|
51
52
|
tag: 'key',
|
|
52
53
|
attrs: {},
|
|
53
54
|
content: [
|
|
54
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
55
56
|
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
57
|
]
|
|
57
58
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const identity = getBinaryNodeChildBuffer(keysNode, 'identity');
|
|
67
|
-
const skey = getBinaryNodeChild(keysNode, 'skey');
|
|
68
|
-
if (!identity || identity.length !== 32 || !skey)
|
|
69
|
-
return null;
|
|
70
|
-
const registrationId = getBinaryNodeChildUInt(receipt, 'registration', 4);
|
|
71
|
-
if (!isValidUInt(registrationId))
|
|
72
|
-
return null;
|
|
73
|
-
const signedPubKey = getBinaryNodeChildBuffer(skey, 'value');
|
|
74
|
-
const signedSig = getBinaryNodeChildBuffer(skey, 'signature');
|
|
75
|
-
const signedKeyId = getBinaryNodeChildUInt(skey, 'id', 3);
|
|
76
|
-
if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const preKeyNode = getBinaryNodeChild(keysNode, 'key');
|
|
80
|
-
let preKey;
|
|
81
|
-
if (preKeyNode) {
|
|
82
|
-
const preKeyPub = getBinaryNodeChildBuffer(preKeyNode, 'value');
|
|
83
|
-
const preKeyId = getBinaryNodeChildUInt(preKeyNode, 'id', 3);
|
|
84
|
-
if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
preKey = { keyId: preKeyId, publicKey: generateSignalPubKey(preKeyPub) };
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
registrationId,
|
|
91
|
-
identityKey: generateSignalPubKey(identity),
|
|
92
|
-
signedPreKey: {
|
|
93
|
-
keyId: signedKeyId,
|
|
94
|
-
publicKey: generateSignalPubKey(signedPubKey),
|
|
95
|
-
signature: signedSig
|
|
96
|
-
},
|
|
97
|
-
preKey
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
101
|
-
const extractKey = (key) => key
|
|
102
|
-
? {
|
|
103
|
-
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
104
|
-
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
105
|
-
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
106
|
-
}
|
|
107
|
-
: undefined;
|
|
108
|
-
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
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')
|
|
109
67
|
for (const node of nodes) {
|
|
110
|
-
assertNodeErrorFree(node)
|
|
68
|
+
WABinary_1.assertNodeErrorFree(node)
|
|
111
69
|
}
|
|
112
70
|
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
113
71
|
// So Promise.all doesn't really help here,
|
|
114
72
|
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
115
73
|
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
116
74
|
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
117
|
-
const chunkSize = 100
|
|
118
|
-
const chunks = chunk(nodes, chunkSize)
|
|
75
|
+
const chunkSize = 100
|
|
76
|
+
const chunks = lodash_1.chunk(nodes, chunkSize)
|
|
119
77
|
for (const nodesChunk of chunks) {
|
|
120
|
-
|
|
121
|
-
const signedKey = getBinaryNodeChild(node, 'skey')
|
|
122
|
-
const key = getBinaryNodeChild(node, 'key')
|
|
123
|
-
const identity = getBinaryNodeChildBuffer(node, 'identity')
|
|
124
|
-
const jid = node.attrs.jid
|
|
125
|
-
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4)
|
|
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)
|
|
126
84
|
await repository.injectE2ESession({
|
|
127
85
|
jid,
|
|
128
86
|
session: {
|
|
129
87
|
registrationId: registrationId,
|
|
130
|
-
identityKey: generateSignalPubKey(identity),
|
|
88
|
+
identityKey: crypto_1.generateSignalPubKey(identity),
|
|
131
89
|
signedPreKey: extractKey(signedKey),
|
|
132
90
|
preKey: extractKey(key)
|
|
133
91
|
}
|
|
134
|
-
})
|
|
135
|
-
}
|
|
92
|
+
})
|
|
93
|
+
}))
|
|
136
94
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
95
|
+
}
|
|
96
|
+
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
97
|
+
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
98
|
+
const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
|
|
99
|
+
const extracted = []
|
|
141
100
|
for (const userResult of result) {
|
|
142
|
-
const { devices, id } = userResult
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
) {
|
|
153
|
-
if (isHosted) {
|
|
154
|
-
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
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 })
|
|
155
111
|
}
|
|
156
|
-
extracted.push({
|
|
157
|
-
user,
|
|
158
|
-
device,
|
|
159
|
-
domainType,
|
|
160
|
-
server: getServerFromDomainType(server, domainType)
|
|
161
|
-
});
|
|
162
112
|
}
|
|
163
113
|
}
|
|
164
114
|
}
|
|
165
|
-
return extracted
|
|
166
|
-
}
|
|
115
|
+
return extracted
|
|
116
|
+
}
|
|
117
|
+
exports.extractDeviceJids = extractDeviceJids;
|
|
167
118
|
/**
|
|
168
119
|
* get the next N keys for upload or processing
|
|
169
120
|
* @param count number of pre-keys to get or generate
|
|
170
121
|
*/
|
|
171
|
-
|
|
172
|
-
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
122
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
123
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
173
124
|
const update = {
|
|
174
125
|
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
175
126
|
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
176
127
|
};
|
|
177
128
|
await keys.set({ 'pre-key': newPreKeys });
|
|
178
|
-
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
129
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
179
130
|
return { update, preKeys };
|
|
180
131
|
};
|
|
181
|
-
|
|
132
|
+
exports.getNextPreKeys = getNextPreKeys;
|
|
133
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
182
134
|
const { creds } = state;
|
|
183
|
-
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
135
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
184
136
|
const node = {
|
|
185
137
|
tag: 'iq',
|
|
186
138
|
attrs: {
|
|
187
139
|
xmlns: 'encrypt',
|
|
188
140
|
type: 'set',
|
|
189
|
-
to: S_WHATSAPP_NET
|
|
141
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
190
142
|
},
|
|
191
143
|
content: [
|
|
192
|
-
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
193
|
-
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
144
|
+
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
145
|
+
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
194
146
|
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
195
|
-
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
196
|
-
xmppSignedPreKey(creds.signedPreKey)
|
|
147
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
148
|
+
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
197
149
|
]
|
|
198
150
|
};
|
|
199
151
|
return { update, node };
|
|
200
152
|
};
|
|
201
|
-
|
|
153
|
+
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AuthenticationState } from '../Types';
|
|
2
2
|
/**
|
|
3
3
|
* stores the full authentication state in a single folder.
|
|
4
4
|
* Far more efficient than singlefileauthstate
|
|
@@ -10,4 +10,4 @@ export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
|
10
10
|
state: AuthenticationState;
|
|
11
11
|
saveCreds: () => Promise<void>;
|
|
12
12
|
}>;
|
|
13
|
-
|
|
13
|
+
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Use a Map to store mutexes for each file path
|
|
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");
|
|
11
10
|
const fileLocks = new Map();
|
|
12
|
-
// Get or create a mutex for a specific file path
|
|
13
11
|
const getFileLock = (path) => {
|
|
14
12
|
let mutex = fileLocks.get(path);
|
|
15
13
|
if (!mutex) {
|
|
16
|
-
mutex = new Mutex();
|
|
14
|
+
mutex = new async_mutex_1.Mutex();
|
|
17
15
|
fileLocks.set(path, mutex);
|
|
18
16
|
}
|
|
19
17
|
return mutex;
|
|
@@ -25,14 +23,13 @@ const getFileLock = (path) => {
|
|
|
25
23
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
26
24
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
27
25
|
* */
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const useMultiFileAuthState = async (folder) => {
|
|
30
27
|
const writeData = async (data, file) => {
|
|
31
|
-
const filePath = join(folder, fixFileName(file));
|
|
28
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
32
29
|
const mutex = getFileLock(filePath);
|
|
33
30
|
return mutex.acquire().then(async (release) => {
|
|
34
31
|
try {
|
|
35
|
-
await writeFile(filePath, JSON.stringify(data, BufferJSON.replacer));
|
|
32
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
36
33
|
}
|
|
37
34
|
finally {
|
|
38
35
|
release();
|
|
@@ -41,12 +38,12 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
41
38
|
};
|
|
42
39
|
const readData = async (file) => {
|
|
43
40
|
try {
|
|
44
|
-
const filePath = join(folder, fixFileName(file));
|
|
41
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
45
42
|
const mutex = getFileLock(filePath);
|
|
46
43
|
return await mutex.acquire().then(async (release) => {
|
|
47
44
|
try {
|
|
48
|
-
const data = await readFile(filePath, { encoding: 'utf-8' });
|
|
49
|
-
return JSON.parse(data, BufferJSON.reviver);
|
|
45
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
46
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
50
47
|
}
|
|
51
48
|
finally {
|
|
52
49
|
release();
|
|
@@ -59,32 +56,33 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
59
56
|
};
|
|
60
57
|
const removeData = async (file) => {
|
|
61
58
|
try {
|
|
62
|
-
const filePath = join(folder, fixFileName(file));
|
|
59
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
63
60
|
const mutex = getFileLock(filePath);
|
|
64
61
|
return mutex.acquire().then(async (release) => {
|
|
65
62
|
try {
|
|
66
|
-
await unlink(filePath);
|
|
63
|
+
await (0, promises_1.unlink)(filePath);
|
|
67
64
|
}
|
|
68
|
-
catch {
|
|
65
|
+
catch (_a) {
|
|
69
66
|
}
|
|
70
67
|
finally {
|
|
71
68
|
release();
|
|
72
69
|
}
|
|
73
70
|
});
|
|
74
71
|
}
|
|
75
|
-
catch {
|
|
72
|
+
catch (_a) {
|
|
73
|
+
}
|
|
76
74
|
};
|
|
77
|
-
const folderInfo = await stat(folder).catch(() => { });
|
|
75
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
78
76
|
if (folderInfo) {
|
|
79
77
|
if (!folderInfo.isDirectory()) {
|
|
80
78
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
else {
|
|
84
|
-
await mkdir(folder, { recursive: true });
|
|
82
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
85
83
|
}
|
|
86
|
-
const fixFileName = (file) => file
|
|
87
|
-
const creds =
|
|
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)();
|
|
88
86
|
return {
|
|
89
87
|
state: {
|
|
90
88
|
creds,
|
|
@@ -94,7 +92,7 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
94
92
|
await Promise.all(ids.map(async (id) => {
|
|
95
93
|
let value = await readData(`${type}-${id}.json`);
|
|
96
94
|
if (type === 'app-state-sync-key' && value) {
|
|
97
|
-
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
95
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
98
96
|
}
|
|
99
97
|
data[id] = value;
|
|
100
98
|
}));
|
|
@@ -118,4 +116,4 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
118
116
|
}
|
|
119
117
|
};
|
|
120
118
|
};
|
|
121
|
-
|
|
119
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { proto } from '../../WAProto
|
|
2
|
-
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types
|
|
3
|
-
import {
|
|
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;
|
|
4
5
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
5
6
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
6
|
-
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds,
|
|
7
|
+
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
7
8
|
creds: Partial<AuthenticationCreds>;
|
|
8
9
|
reply: BinaryNode;
|
|
9
|
-
};
|
|
10
|
-
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array
|
|
11
|
-
//# sourceMappingURL=validate-connection.d.ts.map
|
|
10
|
+
};
|
|
11
|
+
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
|