@mrlegendbot/baileys 1.2.4 → 1.2.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/GenerateStatics.sh +3 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -2
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.js +92 -89
- package/lib/Menu/index.d.ts +42 -0
- package/lib/Menu/index.js +283 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -9
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +22 -21
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +69 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +10 -9
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +22 -21
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +62 -56
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +40 -38
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +34 -33
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +76 -72
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -22
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +405 -506
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +258 -276
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +7 -6
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +49 -48
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.js +369 -349
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.js +1148 -1172
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.js +413 -473
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.js +331 -387
- package/lib/Socket/index.d.ts +267 -0
- package/lib/Socket/index.js +19 -6
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.js +1719 -1782
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.js +2451 -1504
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +35 -40
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.js +191 -239
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.js +923 -992
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -1
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +22 -20
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +4 -2
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.js +5 -3
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +31 -26
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.js +52 -4
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +11 -10
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.js +277 -240
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +23 -20
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +204 -200
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.js +810 -836
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +25 -23
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +86 -70
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.js +284 -277
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.js +595 -592
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +335 -312
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.js +115 -123
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +2 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +73 -74
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +2 -3
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +6 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.js +254 -213
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.js +715 -741
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.js +827 -791
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +187 -215
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +98 -69
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +586 -617
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +234 -553
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.js +170 -217
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +35 -27
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +41 -37
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +141 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +105 -87
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +188 -190
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1294 -28
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -245
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +206 -201
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +89 -86
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +77 -68
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +8 -7
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -19892
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +132 -121
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.js +88 -79
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +29 -28
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +2 -2
- package/package.json +86 -22
- package/README.upstream.md +0 -1312
- package/WAProto/WAProto.json +0 -1
- package/WAProto/WAProto.proto +0 -6275
- package/WAProto/compiler.js +0 -550
- package/lib/Store/index.js +0 -8
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Store/make-cache-manager-store.js +0 -70
- package/lib/Store/make-in-memory-store.js +0 -417
- package/lib/Store/make-ordered-dictionary.js +0 -69
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SignalRepositoryWithLIDStore } from '../Types/index.js';
|
|
2
|
+
import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth.js';
|
|
3
|
+
import { type BinaryNode, type FullJid } from '../WABinary/index.js';
|
|
4
|
+
import type { USyncQueryResultList } from '../WAUSync/index.js';
|
|
5
|
+
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
|
+
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
|
+
[id: string]: KeyPair;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
10
|
+
newPreKeys: {
|
|
11
|
+
[id: number]: KeyPair;
|
|
12
|
+
};
|
|
13
|
+
lastPreKeyId: number;
|
|
14
|
+
preKeysRange: readonly [number, number];
|
|
15
|
+
};
|
|
16
|
+
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
|
+
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
|
+
export declare const extractE2ESessionFromRetryReceipt: (receipt: BinaryNode) => {
|
|
19
|
+
registrationId: number;
|
|
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[];
|
|
33
|
+
/**
|
|
34
|
+
* get the next N keys for upload or processing
|
|
35
|
+
* @param count number of pre-keys to get or generate
|
|
36
|
+
*/
|
|
37
|
+
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
38
|
+
update: Partial<AuthenticationCreds>;
|
|
39
|
+
preKeys: {
|
|
40
|
+
[id: string]: KeyPair;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
44
|
+
update: Partial<AuthenticationCreds>;
|
|
45
|
+
node: BinaryNode;
|
|
46
|
+
}>;
|
|
47
|
+
//# sourceMappingURL=signal.d.ts.map
|
package/lib/Utils/signal.js
CHANGED
|
@@ -3,246 +3,199 @@ import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getB
|
|
|
3
3
|
import { Curve, generateSignalPubKey } from './crypto.js';
|
|
4
4
|
import { encodeBigEndian } from './generics.js';
|
|
5
5
|
function chunk(array, size) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const chunks = [];
|
|
7
|
+
for (let i = 0; i < array.length; i += size) {
|
|
8
|
+
chunks.push(array.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return chunks;
|
|
11
11
|
}
|
|
12
12
|
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
19
|
-
};
|
|
13
|
+
return {
|
|
14
|
+
identifier: { name: wid, deviceId: 0 },
|
|
15
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
16
|
+
};
|
|
20
17
|
};
|
|
21
|
-
export const getPreKeys = async ({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
idList
|
|
27
|
-
}
|
|
28
|
-
return get('pre-key', idList);
|
|
18
|
+
export const getPreKeys = async ({ get }, min, limit) => {
|
|
19
|
+
const idList = [];
|
|
20
|
+
for (let id = min; id < limit; id++) {
|
|
21
|
+
idList.push(id.toString());
|
|
22
|
+
}
|
|
23
|
+
return get('pre-key', idList);
|
|
29
24
|
};
|
|
30
25
|
export const generateOrGetPreKeys = (creds, range) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
|
+
const remaining = range - avaliable;
|
|
28
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
|
+
const newPreKeys = {};
|
|
30
|
+
if (remaining > 0) {
|
|
31
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
+
newPreKeys[i] = Curve.generateKeyPair();
|
|
33
|
+
}
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
35
|
+
return {
|
|
36
|
+
newPreKeys,
|
|
37
|
+
lastPreKeyId,
|
|
38
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
39
|
+
};
|
|
45
40
|
};
|
|
46
|
-
export const xmppSignedPreKey = key => ({
|
|
47
|
-
|
|
48
|
-
attrs: {},
|
|
49
|
-
content: [{
|
|
50
|
-
tag: 'id',
|
|
51
|
-
attrs: {},
|
|
52
|
-
content: encodeBigEndian(key.keyId, 3)
|
|
53
|
-
}, {
|
|
54
|
-
tag: 'value',
|
|
55
|
-
attrs: {},
|
|
56
|
-
content: key.keyPair.public
|
|
57
|
-
}, {
|
|
58
|
-
tag: 'signature',
|
|
41
|
+
export const xmppSignedPreKey = (key) => ({
|
|
42
|
+
tag: 'skey',
|
|
59
43
|
attrs: {},
|
|
60
|
-
content:
|
|
61
|
-
|
|
44
|
+
content: [
|
|
45
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
46
|
+
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
+
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
+
]
|
|
62
49
|
});
|
|
63
50
|
export const xmppPreKey = (pair, id) => ({
|
|
64
|
-
|
|
65
|
-
attrs: {},
|
|
66
|
-
content: [{
|
|
67
|
-
tag: 'id',
|
|
51
|
+
tag: 'key',
|
|
68
52
|
attrs: {},
|
|
69
|
-
content:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
content: pair.public
|
|
74
|
-
}]
|
|
53
|
+
content: [
|
|
54
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
|
+
]
|
|
75
57
|
});
|
|
76
|
-
const isValidUInt = n => typeof n === 'number' && Number.isInteger(n);
|
|
77
|
-
export const extractE2ESessionFromRetryReceipt = receipt => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
const isValidUInt = (n) => typeof n === 'number' && Number.isInteger(n);
|
|
59
|
+
export const extractE2ESessionFromRetryReceipt = (receipt) => {
|
|
60
|
+
const keysNode = getBinaryNodeChild(receipt, 'keys');
|
|
61
|
+
if (!keysNode)
|
|
62
|
+
return null;
|
|
63
|
+
const typeBuf = getBinaryNodeChildBuffer(keysNode, 'type');
|
|
64
|
+
if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== KEY_BUNDLE_TYPE[0])
|
|
65
|
+
return null;
|
|
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) };
|
|
100
88
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
89
|
+
return {
|
|
90
|
+
registrationId,
|
|
91
|
+
identityKey: generateSignalPubKey(identity),
|
|
92
|
+
signedPreKey: {
|
|
93
|
+
keyId: signedKeyId,
|
|
94
|
+
publicKey: generateSignalPubKey(signedPubKey),
|
|
95
|
+
signature: signedSig
|
|
96
|
+
},
|
|
97
|
+
preKey
|
|
104
98
|
};
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
registrationId,
|
|
108
|
-
identityKey: generateSignalPubKey(identity),
|
|
109
|
-
signedPreKey: {
|
|
110
|
-
keyId: signedKeyId,
|
|
111
|
-
publicKey: generateSignalPubKey(signedPubKey),
|
|
112
|
-
signature: signedSig
|
|
113
|
-
},
|
|
114
|
-
preKey
|
|
115
|
-
};
|
|
116
99
|
};
|
|
117
100
|
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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');
|
|
109
|
+
for (const node of nodes) {
|
|
110
|
+
assertNodeErrorFree(node);
|
|
111
|
+
}
|
|
112
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
113
|
+
// So Promise.all doesn't really help here,
|
|
114
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
115
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
116
|
+
// 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);
|
|
119
|
+
for (const nodesChunk of chunks) {
|
|
120
|
+
for (const node of nodesChunk) {
|
|
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);
|
|
126
|
+
await repository.injectE2ESession({
|
|
127
|
+
jid,
|
|
128
|
+
session: {
|
|
129
|
+
registrationId: registrationId,
|
|
130
|
+
identityKey: generateSignalPubKey(identity),
|
|
131
|
+
signedPreKey: extractKey(signedKey),
|
|
132
|
+
preKey: extractKey(key)
|
|
133
|
+
}
|
|
134
|
+
});
|
|
143
135
|
}
|
|
144
|
-
});
|
|
145
136
|
}
|
|
146
|
-
}
|
|
147
137
|
};
|
|
148
138
|
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} of deviceList) {
|
|
174
|
-
if ((!excludeZeroDevices || device !== 0) && (myUser !== user && myLid !== user || myDevice !== device) && (device === 0 || !!keyIndex)) {
|
|
175
|
-
if (isHosted) {
|
|
176
|
-
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
139
|
+
const { user: myUser, device: myDevice } = jidDecode(myJid);
|
|
140
|
+
const extracted = [];
|
|
141
|
+
for (const userResult of result) {
|
|
142
|
+
const { devices, id } = userResult;
|
|
143
|
+
const decoded = jidDecode(id), { user, server } = decoded;
|
|
144
|
+
let { domainType } = decoded;
|
|
145
|
+
const deviceList = devices?.deviceList;
|
|
146
|
+
if (!Array.isArray(deviceList))
|
|
147
|
+
continue;
|
|
148
|
+
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
|
149
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
150
|
+
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
|
151
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
152
|
+
) {
|
|
153
|
+
if (isHosted) {
|
|
154
|
+
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
155
|
+
}
|
|
156
|
+
extracted.push({
|
|
157
|
+
user,
|
|
158
|
+
device,
|
|
159
|
+
domainType,
|
|
160
|
+
server: getServerFromDomainType(server, domainType)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
177
163
|
}
|
|
178
|
-
extracted.push({
|
|
179
|
-
user,
|
|
180
|
-
device,
|
|
181
|
-
domainType,
|
|
182
|
-
server: getServerFromDomainType(server, domainType)
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
164
|
}
|
|
186
|
-
|
|
187
|
-
return extracted;
|
|
165
|
+
return extracted;
|
|
188
166
|
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
newPreKeys,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
await keys.set({
|
|
203
|
-
'pre-key': newPreKeys
|
|
204
|
-
});
|
|
205
|
-
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
206
|
-
return {
|
|
207
|
-
update,
|
|
208
|
-
preKeys
|
|
209
|
-
};
|
|
167
|
+
/**
|
|
168
|
+
* get the next N keys for upload or processing
|
|
169
|
+
* @param count number of pre-keys to get or generate
|
|
170
|
+
*/
|
|
171
|
+
export const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
172
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
173
|
+
const update = {
|
|
174
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
175
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
176
|
+
};
|
|
177
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
178
|
+
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
179
|
+
return { update, preKeys };
|
|
210
180
|
};
|
|
211
181
|
export const getNextPreKeysNode = async (state, count) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}, {
|
|
231
|
-
tag: 'type',
|
|
232
|
-
attrs: {},
|
|
233
|
-
content: KEY_BUNDLE_TYPE
|
|
234
|
-
}, {
|
|
235
|
-
tag: 'identity',
|
|
236
|
-
attrs: {},
|
|
237
|
-
content: creds.signedIdentityKey.public
|
|
238
|
-
}, {
|
|
239
|
-
tag: 'list',
|
|
240
|
-
attrs: {},
|
|
241
|
-
content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k))
|
|
242
|
-
}, xmppSignedPreKey(creds.signedPreKey)]
|
|
243
|
-
};
|
|
244
|
-
return {
|
|
245
|
-
update,
|
|
246
|
-
node
|
|
247
|
-
};
|
|
182
|
+
const { creds } = state;
|
|
183
|
+
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
184
|
+
const node = {
|
|
185
|
+
tag: 'iq',
|
|
186
|
+
attrs: {
|
|
187
|
+
xmlns: 'encrypt',
|
|
188
|
+
type: 'set',
|
|
189
|
+
to: S_WHATSAPP_NET
|
|
190
|
+
},
|
|
191
|
+
content: [
|
|
192
|
+
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
193
|
+
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
194
|
+
{ 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)
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
return { update, node };
|
|
248
200
|
};
|
|
201
|
+
//# sourceMappingURL=signal.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BinaryNode } from '../WABinary/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds an ACK stanza for a received node.
|
|
4
|
+
* Pure function -- no I/O, no side effects.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors WhatsApp Web's ACK construction:
|
|
7
|
+
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
8
|
+
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildAckStanza(node: BinaryNode, errorCode?: number, meId?: string): BinaryNode;
|
|
11
|
+
//# sourceMappingURL=stanza-ack.d.ts.map
|
package/lib/Utils/stanza-ack.js
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an ACK stanza for a received node.
|
|
3
|
+
* Pure function -- no I/O, no side effects.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors WhatsApp Web's ACK construction:
|
|
6
|
+
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
7
|
+
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
8
|
+
*/
|
|
1
9
|
export function buildAckStanza(node, errorCode, meId) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const { tag, attrs } = node;
|
|
11
|
+
const stanza = {
|
|
12
|
+
tag: 'ack',
|
|
13
|
+
attrs: {
|
|
14
|
+
id: attrs.id,
|
|
15
|
+
to: attrs.from,
|
|
16
|
+
class: tag
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
if (errorCode) {
|
|
20
|
+
stanza.attrs.error = errorCode.toString();
|
|
12
21
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
stanza
|
|
28
|
-
}
|
|
29
|
-
return stanza;
|
|
22
|
+
if (attrs.participant) {
|
|
23
|
+
stanza.attrs.participant = attrs.participant;
|
|
24
|
+
}
|
|
25
|
+
if (attrs.recipient) {
|
|
26
|
+
stanza.attrs.recipient = attrs.recipient;
|
|
27
|
+
}
|
|
28
|
+
// WA Web always includes type when present: `n.type || DROP_ATTR`
|
|
29
|
+
if (attrs.type) {
|
|
30
|
+
stanza.attrs.type = attrs.type;
|
|
31
|
+
}
|
|
32
|
+
// WA Web WAWebHandleMsgSendAck.sendAck/sendNack always include `from` for message-class ACKs
|
|
33
|
+
if (tag === 'message' && meId) {
|
|
34
|
+
stanza.attrs.from = meId;
|
|
35
|
+
}
|
|
36
|
+
return stanza;
|
|
30
37
|
}
|
|
38
|
+
//# sourceMappingURL=stanza-ack.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { BaileysEventEmitter, BaileysEventMap, Contact } from '../Types/index.js';
|
|
3
|
+
import type { ILogger } from './logger.js';
|
|
4
|
+
export type ContactsUpsertResult = {
|
|
5
|
+
event: 'contacts.upsert';
|
|
6
|
+
data: Contact[];
|
|
7
|
+
};
|
|
8
|
+
export type LidMappingUpdateResult = {
|
|
9
|
+
event: 'lid-mapping.update';
|
|
10
|
+
data: BaileysEventMap['lid-mapping.update'];
|
|
11
|
+
};
|
|
12
|
+
export type SyncActionResult = ContactsUpsertResult | LidMappingUpdateResult;
|
|
13
|
+
/**
|
|
14
|
+
* Process contactAction and return events to emit.
|
|
15
|
+
* Pure function - no side effects.
|
|
16
|
+
*/
|
|
17
|
+
export declare const processContactAction: (action: proto.SyncActionValue.IContactAction, id: string | undefined, logger?: ILogger) => SyncActionResult[];
|
|
18
|
+
export declare const emitSyncActionResults: (ev: BaileysEventEmitter, results: SyncActionResult[]) => void;
|
|
19
|
+
//# sourceMappingURL=sync-action-utils.d.ts.map
|
|
@@ -1,45 +1,49 @@
|
|
|
1
|
-
import { proto } from '../../WAProto/
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
2
|
import { isLidUser, isPnUser } from '../WABinary/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Process contactAction and return events to emit.
|
|
5
|
+
* Pure function - no side effects.
|
|
6
|
+
*/
|
|
3
7
|
export const processContactAction = (action, id, logger) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const idIsPn = isPnUser(id);
|
|
15
|
-
const phoneNumber = idIsPn ? id : action.pnJid || undefined;
|
|
16
|
-
results.push({
|
|
17
|
-
event: 'contacts.upsert',
|
|
18
|
-
data: [{
|
|
19
|
-
id,
|
|
20
|
-
name: action.fullName || action.firstName || action.username || undefined,
|
|
21
|
-
username: action.username || undefined,
|
|
22
|
-
lid: lidJid || undefined,
|
|
23
|
-
phoneNumber
|
|
24
|
-
}]
|
|
25
|
-
});
|
|
26
|
-
if (lidJid && isLidUser(lidJid) && idIsPn) {
|
|
8
|
+
const results = [];
|
|
9
|
+
if (!id) {
|
|
10
|
+
logger?.warn({ hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid }, 'contactAction sync: missing id in index');
|
|
11
|
+
return results;
|
|
12
|
+
}
|
|
13
|
+
const lidJid = action.lidJid;
|
|
14
|
+
const idIsPn = isPnUser(id);
|
|
15
|
+
// PN is in index[1], not in contactAction.pnJid which is usually null
|
|
16
|
+
const phoneNumber = idIsPn ? id : action.pnJid || undefined;
|
|
17
|
+
// Always emit contacts.upsert
|
|
27
18
|
results.push({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
event: 'contacts.upsert',
|
|
20
|
+
data: [
|
|
21
|
+
{
|
|
22
|
+
id,
|
|
23
|
+
name: action.fullName || action.firstName || action.username || undefined,
|
|
24
|
+
username: action.username || undefined,
|
|
25
|
+
lid: lidJid || undefined,
|
|
26
|
+
phoneNumber
|
|
27
|
+
}
|
|
28
|
+
]
|
|
33
29
|
});
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
// Emit lid-mapping.update if we have valid LID-PN pair
|
|
31
|
+
if (lidJid && isLidUser(lidJid) && idIsPn) {
|
|
32
|
+
results.push({
|
|
33
|
+
event: 'lid-mapping.update',
|
|
34
|
+
data: { lid: lidJid, pn: id }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
36
38
|
};
|
|
37
39
|
export const emitSyncActionResults = (ev, results) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
for (const result of results) {
|
|
41
|
+
if (result.event === 'contacts.upsert') {
|
|
42
|
+
ev.emit('contacts.upsert', result.data);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
ev.emit('lid-mapping.update', result.data);
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
|
-
}
|
|
45
48
|
};
|
|
49
|
+
//# sourceMappingURL=sync-action-utils.js.map
|