@badzz88/baileys 8.4.7 → 8.5.0
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/LICENSE +21 -0
- package/README.md +1055 -337
- package/WAProto/index.js +5 -5
- package/lib/Defaults/index.js +187 -127
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -11
- package/lib/Signal/Group/group-session-builder.js +91 -29
- package/lib/Signal/Group/group_cipher.js +88 -81
- package/lib/Signal/Group/index.js +136 -12
- package/lib/Signal/Group/keyhelper.js +70 -15
- package/lib/Signal/Group/sender-chain-key.js +31 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
- package/lib/Signal/Group/sender-key-message.js +68 -65
- package/lib/Signal/Group/sender-key-name.js +43 -41
- package/lib/Signal/Group/sender-key-record.js +43 -40
- package/lib/Signal/Group/sender-key-state.js +96 -83
- package/lib/Signal/Group/sender-message-key.js +29 -25
- package/lib/Signal/libsignal.js +483 -424
- package/lib/Signal/lid-mapping.js +261 -276
- package/lib/Socket/Client/index.js +30 -3
- package/lib/Socket/Client/types.js +12 -10
- package/lib/Socket/Client/websocket.js +61 -53
- package/lib/Socket/aigroups.js +240 -0
- package/lib/Socket/business.js +422 -379
- package/lib/Socket/chats.js +1816 -1193
- package/lib/Socket/communities.js +549 -431
- package/lib/Socket/graphql.js +656 -0
- package/lib/Socket/groups.js +764 -374
- package/lib/Socket/index.js +38 -11
- package/lib/Socket/interactive-handler.js +522 -0
- package/lib/Socket/interop.js +549 -0
- package/lib/Socket/luxu.js +6 -5
- package/lib/Socket/managed-account.js +183 -0
- package/lib/Socket/messages-recv.js +2439 -1915
- package/lib/Socket/messages-send.js +1642 -1242
- package/lib/Socket/mex.js +59 -40
- package/lib/Socket/newsletter.js +812 -249
- package/lib/Socket/privacy.js +449 -0
- package/lib/Socket/registration.js +427 -0
- package/lib/Socket/socket.js +1077 -965
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +237 -140
- package/lib/Store/index.js +36 -10
- package/lib/Store/make-cache-manager-store.js +85 -80
- package/lib/Store/make-in-memory-store.js +591 -185
- package/lib/Store/make-ordered-dictionary.js +78 -72
- package/lib/Store/object-repository.js +25 -28
- package/lib/Types/Auth.js +38 -2
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- 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 +26 -24
- package/lib/Types/LabelAssociation.js +8 -6
- package/lib/Types/Message.js +95 -11
- package/lib/Types/Mex.js +112 -37
- package/lib/Types/Newsletter.js +121 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +70 -56
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +55 -26
- package/lib/Utils/auth-utils.js +292 -288
- package/lib/Utils/browser-utils.js +113 -48
- package/lib/Utils/business.js +240 -224
- package/lib/Utils/chat-utils.js +1205 -869
- package/lib/Utils/command-loader.d.ts +31 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -34
- package/lib/Utils/consumer-application.js +107 -0
- package/lib/Utils/crypto.js +144 -107
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +518 -308
- package/lib/Utils/event-buffer.js +596 -611
- package/lib/Utils/generics.js +514 -354
- package/lib/Utils/group-history.js +60 -0
- package/lib/Utils/history.js +244 -134
- package/lib/Utils/identity-change-handler.js +51 -49
- package/lib/Utils/index.js +57 -23
- package/lib/Utils/jid-display-normalization.js +218 -0
- package/lib/Utils/link-preview.js +135 -77
- package/lib/Utils/logger.js +9 -3
- package/lib/Utils/lt-hash.js +37 -6
- package/lib/Utils/make-mutex.js +36 -33
- package/lib/Utils/message-composer.js +439 -233
- package/lib/Utils/message-retry-manager.js +265 -260
- package/lib/Utils/messages-media.js +855 -747
- package/lib/Utils/messages.js +2528 -884
- package/lib/Utils/meta-ai-msmsg.js +262 -0
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +195 -200
- package/lib/Utils/offline-node-processor.js +35 -33
- package/lib/Utils/pre-key-manager.js +103 -102
- package/lib/Utils/process-message.js +978 -560
- package/lib/Utils/reporting-utils.js +257 -253
- package/lib/Utils/session-pool.d.ts +16 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +218 -195
- package/lib/Utils/stanza-ack.js +31 -29
- package/lib/Utils/sticker.d.ts +17 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +50 -45
- package/lib/Utils/tc-token-utils.js +137 -139
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +218 -202
- package/lib/Utils/view-once-cache.d.ts +9 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +22 -0
- package/lib/WABinary/constants.js +1302 -1299
- package/lib/WABinary/decode.js +343 -262
- package/lib/WABinary/encode.js +12 -4
- package/lib/WABinary/generic-utils.js +223 -187
- package/lib/WABinary/index.js +33 -6
- package/lib/WABinary/jid-utils.js +351 -88
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +12 -9
- package/lib/WAM/constants.js +39486 -22853
- package/lib/WAM/encode.js +132 -140
- package/lib/WAM/index.js +31 -4
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
- package/lib/WAUSync/Protocols/index.js +39 -6
- package/lib/WAUSync/USyncQuery.js +132 -97
- package/lib/WAUSync/USyncUser.js +49 -30
- package/lib/WAUSync/index.js +31 -4
- package/lib/antiban.js +4637 -0
- package/lib/index.js +48 -15
- package/package.json +55 -92
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
package/lib/Utils/signal.js
CHANGED
|
@@ -1,201 +1,224 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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')
|
|
5
18
|
function chunk(array, size) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
11
24
|
}
|
|
12
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
167
189
|
/**
|
|
168
190
|
* get the next N keys for upload or processing
|
|
169
191
|
* @param count number of pre-keys to get or generate
|
|
170
192
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
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
|
package/lib/Utils/stanza-ack.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.buildAckStanza = buildAckStanza
|
|
1
4
|
/**
|
|
2
5
|
* Builds an ACK stanza for a received node.
|
|
3
6
|
* Pure function -- no I/O, no side effects.
|
|
@@ -6,33 +9,32 @@
|
|
|
6
9
|
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
7
10
|
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
37
40
|
}
|
|
38
|
-
//# sourceMappingURL=stanza-ack.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface StickerMetaOptions {
|
|
2
|
+
packName?: string
|
|
3
|
+
packPublisher?: string
|
|
4
|
+
categories?: string[]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function addExifToWebp(webpBuffer: Buffer, options?: StickerMetaOptions): Promise<Buffer>
|
|
8
|
+
|
|
9
|
+
export function imageToWebpSticker(
|
|
10
|
+
imageBuffer: Buffer,
|
|
11
|
+
options?: StickerMetaOptions & { quality?: number }
|
|
12
|
+
): Promise<Buffer>
|
|
13
|
+
|
|
14
|
+
export function videoToWebpSticker(
|
|
15
|
+
videoBuffer: Buffer,
|
|
16
|
+
options?: StickerMetaOptions & { fps?: number; seconds?: number }
|
|
17
|
+
): Promise<Buffer>
|