@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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1055 -337
  3. package/WAProto/index.js +5 -5
  4. package/lib/Defaults/index.js +187 -127
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +14 -11
  7. package/lib/Signal/Group/group-session-builder.js +91 -29
  8. package/lib/Signal/Group/group_cipher.js +88 -81
  9. package/lib/Signal/Group/index.js +136 -12
  10. package/lib/Signal/Group/keyhelper.js +70 -15
  11. package/lib/Signal/Group/sender-chain-key.js +31 -25
  12. package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
  13. package/lib/Signal/Group/sender-key-message.js +68 -65
  14. package/lib/Signal/Group/sender-key-name.js +43 -41
  15. package/lib/Signal/Group/sender-key-record.js +43 -40
  16. package/lib/Signal/Group/sender-key-state.js +96 -83
  17. package/lib/Signal/Group/sender-message-key.js +29 -25
  18. package/lib/Signal/libsignal.js +483 -424
  19. package/lib/Signal/lid-mapping.js +261 -276
  20. package/lib/Socket/Client/index.js +30 -3
  21. package/lib/Socket/Client/types.js +12 -10
  22. package/lib/Socket/Client/websocket.js +61 -53
  23. package/lib/Socket/aigroups.js +240 -0
  24. package/lib/Socket/business.js +422 -379
  25. package/lib/Socket/chats.js +1816 -1193
  26. package/lib/Socket/communities.js +549 -431
  27. package/lib/Socket/graphql.js +656 -0
  28. package/lib/Socket/groups.js +764 -374
  29. package/lib/Socket/index.js +38 -11
  30. package/lib/Socket/interactive-handler.js +522 -0
  31. package/lib/Socket/interop.js +549 -0
  32. package/lib/Socket/luxu.js +6 -5
  33. package/lib/Socket/managed-account.js +183 -0
  34. package/lib/Socket/messages-recv.js +2439 -1915
  35. package/lib/Socket/messages-send.js +1642 -1242
  36. package/lib/Socket/mex.js +59 -40
  37. package/lib/Socket/newsletter.js +812 -249
  38. package/lib/Socket/privacy.js +449 -0
  39. package/lib/Socket/registration.js +427 -0
  40. package/lib/Socket/socket.js +1077 -965
  41. package/lib/Socket/text-router.js +83 -0
  42. package/lib/Socket/username.js +237 -140
  43. package/lib/Store/index.js +36 -10
  44. package/lib/Store/make-cache-manager-store.js +85 -80
  45. package/lib/Store/make-in-memory-store.js +591 -185
  46. package/lib/Store/make-ordered-dictionary.js +78 -72
  47. package/lib/Store/object-repository.js +25 -28
  48. package/lib/Types/Auth.js +38 -2
  49. package/lib/Types/Bussines.js +2 -2
  50. package/lib/Types/Call.js +2 -2
  51. package/lib/Types/Chat.js +4 -8
  52. package/lib/Types/Contact.js +2 -2
  53. package/lib/Types/Events.js +2 -2
  54. package/lib/Types/GroupMetadata.js +2 -2
  55. package/lib/Types/Label.js +26 -24
  56. package/lib/Types/LabelAssociation.js +8 -6
  57. package/lib/Types/Message.js +95 -11
  58. package/lib/Types/Mex.js +112 -37
  59. package/lib/Types/Newsletter.js +121 -0
  60. package/lib/Types/Product.js +2 -2
  61. package/lib/Types/Signal.js +2 -2
  62. package/lib/Types/Socket.js +2 -3
  63. package/lib/Types/State.js +70 -56
  64. package/lib/Types/USync.js +2 -2
  65. package/lib/Types/index.js +55 -26
  66. package/lib/Utils/auth-utils.js +292 -288
  67. package/lib/Utils/browser-utils.js +113 -48
  68. package/lib/Utils/business.js +240 -224
  69. package/lib/Utils/chat-utils.js +1205 -869
  70. package/lib/Utils/command-loader.d.ts +31 -0
  71. package/lib/Utils/command-loader.js +100 -0
  72. package/lib/Utils/companion-reg-client-utils.js +41 -34
  73. package/lib/Utils/consumer-application.js +107 -0
  74. package/lib/Utils/crypto.js +144 -107
  75. package/lib/Utils/curve25519-js.js +275 -0
  76. package/lib/Utils/decode-wa-message.js +518 -308
  77. package/lib/Utils/event-buffer.js +596 -611
  78. package/lib/Utils/generics.js +514 -354
  79. package/lib/Utils/group-history.js +60 -0
  80. package/lib/Utils/history.js +244 -134
  81. package/lib/Utils/identity-change-handler.js +51 -49
  82. package/lib/Utils/index.js +57 -23
  83. package/lib/Utils/jid-display-normalization.js +218 -0
  84. package/lib/Utils/link-preview.js +135 -77
  85. package/lib/Utils/logger.js +9 -3
  86. package/lib/Utils/lt-hash.js +37 -6
  87. package/lib/Utils/make-mutex.js +36 -33
  88. package/lib/Utils/message-composer.js +439 -233
  89. package/lib/Utils/message-retry-manager.js +265 -260
  90. package/lib/Utils/messages-media.js +855 -747
  91. package/lib/Utils/messages.js +2528 -884
  92. package/lib/Utils/meta-ai-msmsg.js +262 -0
  93. package/lib/Utils/native-bridge.js +82 -0
  94. package/lib/Utils/noise-handler.js +195 -200
  95. package/lib/Utils/offline-node-processor.js +35 -33
  96. package/lib/Utils/pre-key-manager.js +103 -102
  97. package/lib/Utils/process-message.js +978 -560
  98. package/lib/Utils/reporting-utils.js +257 -253
  99. package/lib/Utils/session-pool.d.ts +16 -0
  100. package/lib/Utils/session-pool.js +94 -0
  101. package/lib/Utils/signal.js +218 -195
  102. package/lib/Utils/stanza-ack.js +31 -29
  103. package/lib/Utils/sticker.d.ts +17 -0
  104. package/lib/Utils/sticker.js +145 -0
  105. package/lib/Utils/sync-action-utils.js +50 -45
  106. package/lib/Utils/tc-token-utils.js +137 -139
  107. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  108. package/lib/Utils/validate-connection.js +218 -202
  109. package/lib/Utils/view-once-cache.d.ts +9 -0
  110. package/lib/Utils/view-once-cache.js +79 -0
  111. package/lib/Utils/voip-rekey.js +22 -0
  112. package/lib/WABinary/constants.js +1302 -1299
  113. package/lib/WABinary/decode.js +343 -262
  114. package/lib/WABinary/encode.js +12 -4
  115. package/lib/WABinary/generic-utils.js +223 -187
  116. package/lib/WABinary/index.js +33 -6
  117. package/lib/WABinary/jid-utils.js +351 -88
  118. package/lib/WABinary/types.js +2 -2
  119. package/lib/WAM/BinaryInfo.js +12 -9
  120. package/lib/WAM/constants.js +39486 -22853
  121. package/lib/WAM/encode.js +132 -140
  122. package/lib/WAM/index.js +31 -4
  123. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  124. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
  127. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
  128. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  129. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  130. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  131. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
  133. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  134. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
  135. package/lib/WAUSync/Protocols/index.js +39 -6
  136. package/lib/WAUSync/USyncQuery.js +132 -97
  137. package/lib/WAUSync/USyncUser.js +49 -30
  138. package/lib/WAUSync/index.js +31 -4
  139. package/lib/antiban.js +4637 -0
  140. package/lib/index.js +48 -15
  141. package/package.json +55 -92
  142. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
  143. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  144. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
@@ -1,201 +1,224 @@
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';
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
- const chunks = [];
7
- for (let i = 0; i < array.length; i += size) {
8
- chunks.push(array.slice(i, i + size));
9
- }
10
- return chunks;
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
- 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
- };
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
- 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
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
@@ -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
- 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;
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>