@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.
Files changed (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +746 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
@@ -1,224 +1,201 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.getNextPreKeysNode =
4
- exports.getNextPreKeys =
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
- const chunks = []
20
- for (let i = 0; i < array.length; i += size) {
21
- chunks.push(array.slice(i, i + size))
22
- }
23
- return chunks
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
- return {
27
- identifier: { name: wid, deviceId: 0 },
28
- identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
29
- }
30
- }
31
- exports.createSignalIdentity = createSignalIdentity
32
- const getPreKeys = async ({ get }, min, limit) => {
33
- const idList = []
34
- for (let id = min; id < limit; id++) {
35
- idList.push(id.toString())
36
- }
37
- return get('pre-key', idList)
38
- }
39
- exports.getPreKeys = getPreKeys
40
- const generateOrGetPreKeys = (creds, range) => {
41
- const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId
42
- const remaining = range - avaliable
43
- const lastPreKeyId = creds.nextPreKeyId + remaining - 1
44
- const newPreKeys = {}
45
- if (remaining > 0) {
46
- for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
47
- newPreKeys[i] = crypto_1.Curve.generateKeyPair()
48
- }
49
- }
50
- return {
51
- newPreKeys,
52
- lastPreKeyId,
53
- preKeysRange: [creds.firstUnuploadedPreKeyId, range]
54
- }
55
- }
56
- exports.generateOrGetPreKeys = generateOrGetPreKeys
57
- const xmppSignedPreKey = key => ({
58
- tag: 'skey',
59
- attrs: {},
60
- content: [
61
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
62
- { tag: 'value', attrs: {}, content: key.keyPair.public },
63
- { tag: 'signature', attrs: {}, content: key.signature }
64
- ]
65
- })
66
- exports.xmppSignedPreKey = xmppSignedPreKey
67
- const xmppPreKey = (pair, id) => ({
68
- tag: 'key',
69
- attrs: {},
70
- content: [
71
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
72
- { tag: 'value', attrs: {}, content: pair.public }
73
- ]
74
- })
75
- exports.xmppPreKey = xmppPreKey
76
- const isValidUInt = n => typeof n === 'number' && Number.isInteger(n)
77
- const extractE2ESessionFromRetryReceipt = receipt => {
78
- const keysNode = (0, WABinary_1.getBinaryNodeChild)(receipt, 'keys')
79
- if (!keysNode) return null
80
- const typeBuf = (0, WABinary_1.getBinaryNodeChildBuffer)(keysNode, 'type')
81
- if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== Defaults_1.KEY_BUNDLE_TYPE[0]) return null
82
- const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(keysNode, 'identity')
83
- const skey = (0, WABinary_1.getBinaryNodeChild)(keysNode, 'skey')
84
- if (!identity || identity.length !== 32 || !skey) return null
85
- const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(receipt, 'registration', 4)
86
- if (!isValidUInt(registrationId)) return null
87
- const signedPubKey = (0, WABinary_1.getBinaryNodeChildBuffer)(skey, 'value')
88
- const signedSig = (0, WABinary_1.getBinaryNodeChildBuffer)(skey, 'signature')
89
- const signedKeyId = (0, WABinary_1.getBinaryNodeChildUInt)(skey, 'id', 3)
90
- if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
91
- return null
92
- }
93
- const preKeyNode = (0, WABinary_1.getBinaryNodeChild)(keysNode, 'key')
94
- let preKey
95
- if (preKeyNode) {
96
- const preKeyPub = (0, WABinary_1.getBinaryNodeChildBuffer)(preKeyNode, 'value')
97
- const preKeyId = (0, WABinary_1.getBinaryNodeChildUInt)(preKeyNode, 'id', 3)
98
- if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
99
- return null
100
- }
101
- preKey = { keyId: preKeyId, publicKey: (0, crypto_1.generateSignalPubKey)(preKeyPub) }
102
- }
103
- return {
104
- registrationId,
105
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
106
- signedPreKey: {
107
- keyId: signedKeyId,
108
- publicKey: (0, crypto_1.generateSignalPubKey)(signedPubKey),
109
- signature: signedSig
110
- },
111
- preKey
112
- }
113
- }
114
- exports.extractE2ESessionFromRetryReceipt = extractE2ESessionFromRetryReceipt
115
- const parseAndInjectE2ESessions = async (node, repository) => {
116
- const extractKey = key =>
117
- key
118
- ? {
119
- keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
120
- publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
121
- signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature')
122
- }
123
- : undefined
124
- const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user')
125
- for (const node of nodes) {
126
- ;(0, WABinary_1.assertNodeErrorFree)(node)
127
- }
128
- // Most of the work in repository.injectE2ESession is CPU intensive, not IO
129
- // So Promise.all doesn't really help here,
130
- // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
131
- // This way we chunk it in smaller parts and between those parts we can yield to the event loop
132
- // It's rare case when you need to E2E sessions for so many users, but it's possible
133
- const chunkSize = 100
134
- const chunks = chunk(nodes, chunkSize)
135
- for (const nodesChunk of chunks) {
136
- for (const node of nodesChunk) {
137
- const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey')
138
- const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key')
139
- const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity')
140
- const jid = node.attrs.jid
141
- const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4)
142
- await repository.injectE2ESession({
143
- jid,
144
- session: {
145
- registrationId: registrationId,
146
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
147
- signedPreKey: extractKey(signedKey),
148
- preKey: extractKey(key)
149
- }
150
- })
151
- }
152
- }
153
- }
154
- exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions
155
- const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
156
- const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid)
157
- const extracted = []
158
- for (const userResult of result) {
159
- const { devices, id } = userResult
160
- const decoded = (0, WABinary_1.jidDecode)(id),
161
- { user, server } = decoded
162
- let { domainType } = decoded
163
- const deviceList = devices?.deviceList
164
- if (!Array.isArray(deviceList)) continue
165
- for (const { id: device, keyIndex, isHosted } of deviceList) {
166
- if (
167
- (!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
168
- ((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
169
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
170
- ) {
171
- if (isHosted) {
172
- domainType =
173
- domainType === WABinary_1.WAJIDDomains.LID
174
- ? WABinary_1.WAJIDDomains.HOSTED_LID
175
- : WABinary_1.WAJIDDomains.HOSTED
176
- }
177
- extracted.push({
178
- user,
179
- device,
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
- const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count)
195
- const update = {
196
- nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
197
- firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
198
- }
199
- await keys.set({ 'pre-key': newPreKeys })
200
- const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1])
201
- return { update, preKeys }
202
- }
203
- exports.getNextPreKeys = getNextPreKeys
204
- const getNextPreKeysNode = async (state, count) => {
205
- const { creds } = state
206
- const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count)
207
- const node = {
208
- tag: 'iq',
209
- attrs: {
210
- xmlns: 'encrypt',
211
- type: 'set',
212
- to: WABinary_1.S_WHATSAPP_NET
213
- },
214
- content: [
215
- { tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
216
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
217
- { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
218
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
219
- (0, exports.xmppSignedPreKey)(creds.signedPreKey)
220
- ]
221
- }
222
- return { update, node }
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
@@ -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
- const { tag, attrs } = node
14
- const stanza = {
15
- tag: 'ack',
16
- attrs: {
17
- id: attrs.id,
18
- to: attrs.from,
19
- class: tag
20
- }
21
- }
22
- if (errorCode) {
23
- stanza.attrs.error = errorCode.toString()
24
- }
25
- if (attrs.participant) {
26
- stanza.attrs.participant = attrs.participant
27
- }
28
- if (attrs.recipient) {
29
- stanza.attrs.recipient = attrs.recipient
30
- }
31
- // WA Web always includes type when present: `n.type || DROP_ATTR`
32
- if (attrs.type) {
33
- stanza.attrs.type = attrs.type
34
- }
35
- // WA Web WAWebHandleMsgSendAck.sendAck/sendNack always include `from` for message-class ACKs
36
- if (tag === 'message' && meId) {
37
- stanza.attrs.from = meId
38
- }
39
- return stanza
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