@mrlegendbot/baileys 1.2.1 → 1.2.4
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/README.upstream.md +1312 -0
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +6275 -0
- package/WAProto/compiler.js +550 -0
- package/WAProto/index.js +2 -97691
- package/lib/Defaults/index.js +89 -92
- package/lib/Signal/Group/ciphertext-message.js +9 -10
- package/lib/Signal/Group/group-session-builder.js +21 -22
- package/lib/Signal/Group/group_cipher.js +75 -69
- package/lib/Signal/Group/index.js +0 -1
- package/lib/Signal/Group/keyhelper.js +9 -10
- package/lib/Signal/Group/sender-chain-key.js +21 -22
- package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
- package/lib/Signal/Group/sender-key-message.js +56 -62
- package/lib/Signal/Group/sender-key-name.js +38 -40
- package/lib/Signal/Group/sender-key-record.js +33 -34
- package/lib/Signal/Group/sender-key-state.js +72 -76
- package/lib/Signal/Group/sender-message-key.js +22 -23
- package/lib/Signal/libsignal.js +506 -405
- package/lib/Signal/lid-mapping.js +276 -258
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +6 -7
- package/lib/Socket/Client/websocket.js +48 -49
- package/lib/Socket/business.js +349 -369
- package/lib/Socket/chats.js +1172 -1148
- package/lib/Socket/communities.js +473 -413
- package/lib/Socket/groups.js +387 -331
- package/lib/Socket/index.js +6 -8
- package/lib/Socket/messages-recv.js +1782 -1719
- package/lib/Socket/messages-send.js +1503 -2450
- package/lib/Socket/mex.js +40 -35
- package/lib/Socket/newsletter.js +239 -191
- package/lib/Socket/socket.js +992 -923
- package/lib/Store/index.js +8 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +70 -0
- package/lib/Store/make-in-memory-store.js +417 -0
- package/lib/Store/make-ordered-dictionary.js +69 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +0 -1
- package/lib/Types/Bussines.js +0 -1
- package/lib/Types/Call.js +0 -1
- package/lib/Types/Chat.js +1 -8
- package/lib/Types/Contact.js +0 -1
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +0 -1
- package/lib/Types/Label.js +20 -22
- package/lib/Types/LabelAssociation.js +2 -4
- package/lib/Types/Message.js +3 -5
- package/lib/Types/Mex.js +26 -31
- package/lib/Types/Product.js +0 -1
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +4 -52
- package/lib/Types/USync.js +0 -1
- package/lib/Types/index.js +10 -11
- package/lib/Utils/auth-utils.js +240 -277
- package/lib/Utils/browser-utils.js +20 -23
- package/lib/Utils/business.js +200 -204
- package/lib/Utils/chat-utils.js +836 -810
- package/lib/Utils/companion-reg-client-utils.js +23 -25
- package/lib/Utils/crypto.js +70 -86
- package/lib/Utils/decode-wa-message.js +277 -284
- package/lib/Utils/event-buffer.js +592 -595
- package/lib/Utils/generics.js +312 -335
- package/lib/Utils/history.js +123 -115
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/link-preview.js +74 -73
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.js +213 -254
- package/lib/Utils/messages-media.js +741 -715
- package/lib/Utils/messages.js +791 -827
- package/lib/Utils/noise-handler.js +215 -187
- package/lib/Utils/pre-key-manager.js +69 -98
- package/lib/Utils/process-message.js +617 -586
- package/lib/Utils/reporting-utils.js +553 -234
- package/lib/Utils/signal.js +217 -170
- package/lib/Utils/stanza-ack.js +27 -35
- package/lib/Utils/sync-action-utils.js +37 -41
- package/lib/Utils/tc-token-utils.js +120 -141
- package/lib/Utils/use-multi-file-auth-state.js +87 -105
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.js +190 -188
- package/lib/WABinary/constants.js +28 -1294
- package/lib/WABinary/decode.js +245 -249
- package/lib/WABinary/encode.js +201 -206
- package/lib/WABinary/generic-utils.js +86 -89
- package/lib/WABinary/index.js +0 -1
- package/lib/WABinary/jid-utils.js +68 -77
- package/lib/WABinary/types.js +0 -1
- package/lib/WAM/BinaryInfo.js +7 -8
- package/lib/WAM/constants.js +19892 -22853
- package/lib/WAM/encode.js +121 -132
- package/lib/WAM/index.js +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/USyncQuery.js +79 -88
- package/lib/WAUSync/USyncUser.js +28 -29
- package/lib/WAUSync/index.js +0 -1
- package/lib/index.js +2 -2
- package/package.json +22 -86
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Defaults/index.d.ts +0 -75
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/libsignal.d.ts +0 -5
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -217
- package/lib/Socket/chats.d.ts +0 -125
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/groups.d.ts +0 -161
- package/lib/Socket/index.d.ts +0 -260
- package/lib/Socket/messages-recv.d.ts +0 -203
- package/lib/Socket/messages-send.d.ts +0 -199
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/newsletter.d.ts +0 -170
- package/lib/Socket/socket.d.ts +0 -59
- package/lib/Types/Auth.d.ts +0 -117
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Call.d.ts +0 -15
- package/lib/Types/Chat.d.ts +0 -124
- package/lib/Types/Contact.d.ts +0 -26
- package/lib/Types/Events.d.ts +0 -256
- package/lib/Types/GroupMetadata.d.ts +0 -71
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/Message.d.ts +0 -320
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Signal.d.ts +0 -87
- package/lib/Types/Socket.d.ts +0 -136
- package/lib/Types/State.d.ts +0 -97
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -24
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/chat-utils.d.ts +0 -100
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/crypto.d.ts +0 -37
- package/lib/Utils/decode-wa-message.d.ts +0 -66
- package/lib/Utils/event-buffer.d.ts +0 -36
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -24
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -12
- package/lib/Utils/lt-hash.d.ts +0 -8
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/messages-media.d.ts +0 -133
- package/lib/Utils/messages.d.ts +0 -91
- package/lib/Utils/noise-handler.d.ts +0 -20
- 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/process-message.d.ts +0 -60
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/signal.d.ts +0 -47
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -28
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -6
- package/lib/WABinary/jid-utils.d.ts +0 -48
- package/lib/WABinary/types.d.ts +0 -19
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncUser.d.ts +0 -17
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/index.d.ts +0 -12
package/lib/Utils/signal.js
CHANGED
|
@@ -3,199 +3,246 @@ 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
|
-
|
|
13
|
+
return {
|
|
14
|
+
identifier: {
|
|
15
|
+
name: wid,
|
|
16
|
+
deviceId: 0
|
|
17
|
+
},
|
|
18
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
|
-
export const getPreKeys = async ({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export const getPreKeys = async ({
|
|
22
|
+
get
|
|
23
|
+
}, min, limit) => {
|
|
24
|
+
const idList = [];
|
|
25
|
+
for (let id = min; id < limit; id++) {
|
|
26
|
+
idList.push(id.toString());
|
|
27
|
+
}
|
|
28
|
+
return get('pre-key', idList);
|
|
24
29
|
};
|
|
25
30
|
export const generateOrGetPreKeys = (creds, range) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
31
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
32
|
+
const remaining = range - avaliable;
|
|
33
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
34
|
+
const newPreKeys = {};
|
|
35
|
+
if (remaining > 0) {
|
|
36
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
37
|
+
newPreKeys[i] = Curve.generateKeyPair();
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
newPreKeys,
|
|
42
|
+
lastPreKeyId,
|
|
43
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
44
|
+
};
|
|
40
45
|
};
|
|
41
|
-
export const xmppSignedPreKey =
|
|
42
|
-
|
|
46
|
+
export const xmppSignedPreKey = key => ({
|
|
47
|
+
tag: 'skey',
|
|
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',
|
|
43
59
|
attrs: {},
|
|
44
|
-
content:
|
|
45
|
-
|
|
46
|
-
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
-
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
-
]
|
|
60
|
+
content: key.signature
|
|
61
|
+
}]
|
|
49
62
|
});
|
|
50
63
|
export const xmppPreKey = (pair, id) => ({
|
|
51
|
-
|
|
64
|
+
tag: 'key',
|
|
65
|
+
attrs: {},
|
|
66
|
+
content: [{
|
|
67
|
+
tag: 'id',
|
|
52
68
|
attrs: {},
|
|
53
|
-
content:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
content: encodeBigEndian(id, 3)
|
|
70
|
+
}, {
|
|
71
|
+
tag: 'value',
|
|
72
|
+
attrs: {},
|
|
73
|
+
content: pair.public
|
|
74
|
+
}]
|
|
57
75
|
});
|
|
58
|
-
const isValidUInt =
|
|
59
|
-
export const extractE2ESessionFromRetryReceipt =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
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) };
|
|
76
|
+
const isValidUInt = n => typeof n === 'number' && Number.isInteger(n);
|
|
77
|
+
export const extractE2ESessionFromRetryReceipt = receipt => {
|
|
78
|
+
const keysNode = getBinaryNodeChild(receipt, 'keys');
|
|
79
|
+
if (!keysNode) return null;
|
|
80
|
+
const typeBuf = getBinaryNodeChildBuffer(keysNode, 'type');
|
|
81
|
+
if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== KEY_BUNDLE_TYPE[0]) return null;
|
|
82
|
+
const identity = getBinaryNodeChildBuffer(keysNode, 'identity');
|
|
83
|
+
const skey = getBinaryNodeChild(keysNode, 'skey');
|
|
84
|
+
if (!identity || identity.length !== 32 || !skey) return null;
|
|
85
|
+
const registrationId = getBinaryNodeChildUInt(receipt, 'registration', 4);
|
|
86
|
+
if (!isValidUInt(registrationId)) return null;
|
|
87
|
+
const signedPubKey = getBinaryNodeChildBuffer(skey, 'value');
|
|
88
|
+
const signedSig = getBinaryNodeChildBuffer(skey, 'signature');
|
|
89
|
+
const signedKeyId = getBinaryNodeChildUInt(skey, 'id', 3);
|
|
90
|
+
if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const preKeyNode = getBinaryNodeChild(keysNode, 'key');
|
|
94
|
+
let preKey;
|
|
95
|
+
if (preKeyNode) {
|
|
96
|
+
const preKeyPub = getBinaryNodeChildBuffer(preKeyNode, 'value');
|
|
97
|
+
const preKeyId = getBinaryNodeChildUInt(preKeyNode, 'id', 3);
|
|
98
|
+
if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
|
|
99
|
+
return null;
|
|
88
100
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
signedPreKey: {
|
|
93
|
-
keyId: signedKeyId,
|
|
94
|
-
publicKey: generateSignalPubKey(signedPubKey),
|
|
95
|
-
signature: signedSig
|
|
96
|
-
},
|
|
97
|
-
preKey
|
|
101
|
+
preKey = {
|
|
102
|
+
keyId: preKeyId,
|
|
103
|
+
publicKey: generateSignalPubKey(preKeyPub)
|
|
98
104
|
};
|
|
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
|
+
};
|
|
99
116
|
};
|
|
100
117
|
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
});
|
|
118
|
+
const extractKey = key => key ? {
|
|
119
|
+
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
120
|
+
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
121
|
+
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
122
|
+
} : undefined;
|
|
123
|
+
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
124
|
+
for (const node of nodes) {
|
|
125
|
+
assertNodeErrorFree(node);
|
|
126
|
+
}
|
|
127
|
+
const chunkSize = 100;
|
|
128
|
+
const chunks = chunk(nodes, chunkSize);
|
|
129
|
+
for (const nodesChunk of chunks) {
|
|
130
|
+
for (const node of nodesChunk) {
|
|
131
|
+
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
132
|
+
const key = getBinaryNodeChild(node, 'key');
|
|
133
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
134
|
+
const jid = node.attrs.jid;
|
|
135
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
136
|
+
await repository.injectE2ESession({
|
|
137
|
+
jid,
|
|
138
|
+
session: {
|
|
139
|
+
registrationId: registrationId,
|
|
140
|
+
identityKey: generateSignalPubKey(identity),
|
|
141
|
+
signedPreKey: extractKey(signedKey),
|
|
142
|
+
preKey: extractKey(key)
|
|
135
143
|
}
|
|
144
|
+
});
|
|
136
145
|
}
|
|
146
|
+
}
|
|
137
147
|
};
|
|
138
148
|
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
149
|
+
const {
|
|
150
|
+
user: myUser,
|
|
151
|
+
device: myDevice
|
|
152
|
+
} = jidDecode(myJid);
|
|
153
|
+
const extracted = [];
|
|
154
|
+
for (const userResult of result) {
|
|
155
|
+
const {
|
|
156
|
+
devices,
|
|
157
|
+
id
|
|
158
|
+
} = userResult;
|
|
159
|
+
const decoded = jidDecode(id),
|
|
160
|
+
{
|
|
161
|
+
user,
|
|
162
|
+
server
|
|
163
|
+
} = decoded;
|
|
164
|
+
let {
|
|
165
|
+
domainType
|
|
166
|
+
} = decoded;
|
|
167
|
+
const deviceList = devices?.deviceList;
|
|
168
|
+
if (!Array.isArray(deviceList)) continue;
|
|
169
|
+
for (const {
|
|
170
|
+
id: device,
|
|
171
|
+
keyIndex,
|
|
172
|
+
isHosted
|
|
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;
|
|
163
177
|
}
|
|
178
|
+
extracted.push({
|
|
179
|
+
user,
|
|
180
|
+
device,
|
|
181
|
+
domainType,
|
|
182
|
+
server: getServerFromDomainType(server, domainType)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
164
185
|
}
|
|
165
|
-
|
|
186
|
+
}
|
|
187
|
+
return extracted;
|
|
166
188
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
export const getNextPreKeys = async ({
|
|
190
|
+
creds,
|
|
191
|
+
keys
|
|
192
|
+
}, count) => {
|
|
193
|
+
const {
|
|
194
|
+
newPreKeys,
|
|
195
|
+
lastPreKeyId,
|
|
196
|
+
preKeysRange
|
|
197
|
+
} = generateOrGetPreKeys(creds, count);
|
|
198
|
+
const update = {
|
|
199
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
200
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
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
|
+
};
|
|
180
210
|
};
|
|
181
211
|
export const getNextPreKeysNode = async (state, count) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
212
|
+
const {
|
|
213
|
+
creds
|
|
214
|
+
} = state;
|
|
215
|
+
const {
|
|
216
|
+
update,
|
|
217
|
+
preKeys
|
|
218
|
+
} = await getNextPreKeys(state, count);
|
|
219
|
+
const node = {
|
|
220
|
+
tag: 'iq',
|
|
221
|
+
attrs: {
|
|
222
|
+
xmlns: 'encrypt',
|
|
223
|
+
type: 'set',
|
|
224
|
+
to: S_WHATSAPP_NET
|
|
225
|
+
},
|
|
226
|
+
content: [{
|
|
227
|
+
tag: 'registration',
|
|
228
|
+
attrs: {},
|
|
229
|
+
content: encodeBigEndian(creds.registrationId)
|
|
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
|
+
};
|
|
200
248
|
};
|
|
201
|
-
//# sourceMappingURL=signal.js.map
|
package/lib/Utils/stanza-ack.js
CHANGED
|
@@ -1,38 +1,30 @@
|
|
|
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
|
-
*/
|
|
9
1
|
export function buildAckStanza(node, errorCode, meId) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
stanza.attrs.error = errorCode.toString();
|
|
2
|
+
const {
|
|
3
|
+
tag,
|
|
4
|
+
attrs
|
|
5
|
+
} = node;
|
|
6
|
+
const stanza = {
|
|
7
|
+
tag: 'ack',
|
|
8
|
+
attrs: {
|
|
9
|
+
id: attrs.id,
|
|
10
|
+
to: attrs.from,
|
|
11
|
+
class: tag
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
13
|
+
};
|
|
14
|
+
if (errorCode) {
|
|
15
|
+
stanza.attrs.error = errorCode.toString();
|
|
16
|
+
}
|
|
17
|
+
if (attrs.participant) {
|
|
18
|
+
stanza.attrs.participant = attrs.participant;
|
|
19
|
+
}
|
|
20
|
+
if (attrs.recipient) {
|
|
21
|
+
stanza.attrs.recipient = attrs.recipient;
|
|
22
|
+
}
|
|
23
|
+
if (attrs.type) {
|
|
24
|
+
stanza.attrs.type = attrs.type;
|
|
25
|
+
}
|
|
26
|
+
if (tag === 'message' && meId) {
|
|
27
|
+
stanza.attrs.from = meId;
|
|
28
|
+
}
|
|
29
|
+
return stanza;
|
|
37
30
|
}
|
|
38
|
-
//# sourceMappingURL=stanza-ack.js.map
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
import { proto } from '../../WAProto/
|
|
1
|
+
import { proto } from '../../WAProto/compiler.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
|
-
*/
|
|
7
3
|
export const processContactAction = (action, id, logger) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const results = [];
|
|
5
|
+
if (!id) {
|
|
6
|
+
logger?.warn({
|
|
7
|
+
hasFullName: !!action.fullName,
|
|
8
|
+
hasLidJid: !!action.lidJid,
|
|
9
|
+
hasPnJid: !!action.pnJid
|
|
10
|
+
}, 'contactAction sync: missing id in index');
|
|
11
|
+
return results;
|
|
12
|
+
}
|
|
13
|
+
const lidJid = action.lidJid;
|
|
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) {
|
|
18
27
|
results.push({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
username: action.username || undefined,
|
|
25
|
-
lid: lidJid || undefined,
|
|
26
|
-
phoneNumber
|
|
27
|
-
}
|
|
28
|
-
]
|
|
28
|
+
event: 'lid-mapping.update',
|
|
29
|
+
data: {
|
|
30
|
+
lid: lidJid,
|
|
31
|
+
pn: id
|
|
32
|
+
}
|
|
29
33
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
results.push({
|
|
33
|
-
event: 'lid-mapping.update',
|
|
34
|
-
data: { lid: lidJid, pn: id }
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return results;
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
38
36
|
};
|
|
39
37
|
export const emitSyncActionResults = (ev, results) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ev.emit('lid-mapping.update', result.data);
|
|
46
|
-
}
|
|
38
|
+
for (const result of results) {
|
|
39
|
+
if (result.event === 'contacts.upsert') {
|
|
40
|
+
ev.emit('contacts.upsert', result.data);
|
|
41
|
+
} else {
|
|
42
|
+
ev.emit('lid-mapping.update', result.data);
|
|
47
43
|
}
|
|
44
|
+
}
|
|
48
45
|
};
|
|
49
|
-
//# sourceMappingURL=sync-action-utils.js.map
|