@badzz88/baileys 8.5.7 → 8.5.9
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.md +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +746 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
package/lib/Utils/signal.js
CHANGED
|
@@ -1,224 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.extractDeviceJids =
|
|
6
|
-
exports.parseAndInjectE2ESessions =
|
|
7
|
-
exports.extractE2ESessionFromRetryReceipt =
|
|
8
|
-
exports.xmppPreKey =
|
|
9
|
-
exports.xmppSignedPreKey =
|
|
10
|
-
exports.generateOrGetPreKeys =
|
|
11
|
-
exports.getPreKeys =
|
|
12
|
-
exports.createSignalIdentity =
|
|
13
|
-
void 0
|
|
14
|
-
const Defaults_1 = require('../Defaults')
|
|
15
|
-
const WABinary_1 = require('../WABinary')
|
|
16
|
-
const crypto_1 = require('./crypto')
|
|
17
|
-
const generics_1 = require('./generics')
|
|
1
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
2
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary/index.js';
|
|
3
|
+
import { Curve, generateSignalPubKey } from './crypto.js';
|
|
4
|
+
import { encodeBigEndian } from './generics.js';
|
|
18
5
|
function chunk(array, size) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
11
|
}
|
|
25
|
-
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
domainType,
|
|
181
|
-
server: (0, WABinary_1.getServerFromDomainType)(server, domainType)
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return extracted
|
|
187
|
-
}
|
|
188
|
-
exports.extractDeviceJids = extractDeviceJids
|
|
12
|
+
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
|
+
return {
|
|
14
|
+
identifier: { name: wid, deviceId: 0 },
|
|
15
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
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);
|
|
24
|
+
};
|
|
25
|
+
export const generateOrGetPreKeys = (creds, range) => {
|
|
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
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
newPreKeys,
|
|
37
|
+
lastPreKeyId,
|
|
38
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export const xmppSignedPreKey = (key) => ({
|
|
42
|
+
tag: 'skey',
|
|
43
|
+
attrs: {},
|
|
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
|
+
]
|
|
49
|
+
});
|
|
50
|
+
export const xmppPreKey = (pair, id) => ({
|
|
51
|
+
tag: 'key',
|
|
52
|
+
attrs: {},
|
|
53
|
+
content: [
|
|
54
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
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) };
|
|
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');
|
|
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
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
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
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return extracted;
|
|
166
|
+
};
|
|
189
167
|
/**
|
|
190
168
|
* get the next N keys for upload or processing
|
|
191
169
|
* @param count number of pre-keys to get or generate
|
|
192
170
|
*/
|
|
193
|
-
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
exports.getNextPreKeysNode = getNextPreKeysNode
|
|
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 };
|
|
180
|
+
};
|
|
181
|
+
export const getNextPreKeysNode = async (state, count) => {
|
|
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 };
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=signal.js.map
|
package/lib/Utils/stanza-ack.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.buildAckStanza = buildAckStanza
|
|
4
1
|
/**
|
|
5
2
|
* Builds an ACK stanza for a received node.
|
|
6
3
|
* Pure function -- no I/O, no side effects.
|
|
@@ -9,32 +6,33 @@ exports.buildAckStanza = buildAckStanza
|
|
|
9
6
|
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
10
7
|
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
11
8
|
*/
|
|
12
|
-
function buildAckStanza(node, errorCode, meId) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
export function buildAckStanza(node, errorCode, meId) {
|
|
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();
|
|
21
|
+
}
|
|
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;
|
|
40
37
|
}
|
|
38
|
+
//# sourceMappingURL=stanza-ack.js.map
|