@wenzyx1/bails 1.0.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 (218) hide show
  1. package/README.md +231 -0
  2. package/WAProto/fix-imports.js +85 -0
  3. package/WAProto/index.d.ts +79257 -0
  4. package/WAProto/index.js +242946 -0
  5. package/engine-requirements.js +10 -0
  6. package/lib/Defaults/baileys-version.json +3 -0
  7. package/lib/Defaults/index.d.ts +53 -0
  8. package/lib/Defaults/index.js +147 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  11. package/lib/Signal/Group/ciphertext-message.js +15 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  13. package/lib/Signal/Group/group-session-builder.js +64 -0
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +93 -0
  16. package/lib/Signal/Group/index.d.ts +11 -0
  17. package/lib/Signal/Group/index.js +57 -0
  18. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  19. package/lib/Signal/Group/keyhelper.js +55 -0
  20. package/lib/Signal/Group/queue-job.d.ts +1 -0
  21. package/lib/Signal/Group/queue-job.js +53 -0
  22. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  23. package/lib/Signal/Group/sender-chain-key.js +34 -0
  24. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  26. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-message.js +69 -0
  28. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  29. package/lib/Signal/Group/sender-key-name.js +51 -0
  30. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  31. package/lib/Signal/Group/sender-key-record.js +53 -0
  32. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  33. package/lib/Signal/Group/sender-key-state.js +99 -0
  34. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  35. package/lib/Signal/Group/sender-message-key.js +29 -0
  36. package/lib/Signal/libsignal.d.ts +3 -0
  37. package/lib/Signal/libsignal.js +454 -0
  38. package/lib/Signal/lid-mapping.js +280 -0
  39. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  40. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  41. package/lib/Socket/Client/index.d.ts +3 -0
  42. package/lib/Socket/Client/index.js +19 -0
  43. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  44. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  45. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  46. package/lib/Socket/Client/web-socket-client.js +62 -0
  47. package/lib/Socket/business.d.ts +171 -0
  48. package/lib/Socket/business.js +342 -0
  49. package/lib/Socket/chats.d.ts +267 -0
  50. package/lib/Socket/chats.js +978 -0
  51. package/lib/Socket/communities.mjs +428 -0
  52. package/lib/Socket/dugong.d.ts +254 -0
  53. package/lib/Socket/dugong.js +558 -0
  54. package/lib/Socket/groups.d.ts +115 -0
  55. package/lib/Socket/groups.js +380 -0
  56. package/lib/Socket/index.d.ts +173 -0
  57. package/lib/Socket/index.js +32 -0
  58. package/lib/Socket/luxu.js +545 -0
  59. package/lib/Socket/messages-recv.d.ts +161 -0
  60. package/lib/Socket/messages-recv.js +1124 -0
  61. package/lib/Socket/messages-send.d.ts +149 -0
  62. package/lib/Socket/messages-send.js +1476 -0
  63. package/lib/Socket/mex.mjs +50 -0
  64. package/lib/Socket/newsletter.d.ts +134 -0
  65. package/lib/Socket/newsletter.js +351 -0
  66. package/lib/Socket/registration.d.ts +267 -0
  67. package/lib/Socket/registration.js +166 -0
  68. package/lib/Socket/socket.d.ts +43 -0
  69. package/lib/Socket/socket.js +904 -0
  70. package/lib/Socket/username.mjs +132 -0
  71. package/lib/Socket/usync.d.ts +36 -0
  72. package/lib/Socket/usync.js +70 -0
  73. package/lib/Store/index.d.ts +3 -0
  74. package/lib/Store/index.js +10 -0
  75. package/lib/Store/keyed-db.d.ts +30 -0
  76. package/lib/Store/keyed-db.js +233 -0
  77. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  78. package/lib/Store/make-cache-manager-store.js +83 -0
  79. package/lib/Store/make-in-memory-store.d.ts +118 -0
  80. package/lib/Store/make-in-memory-store.js +427 -0
  81. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  82. package/lib/Store/make-ordered-dictionary.js +81 -0
  83. package/lib/Store/object-repository.d.ts +10 -0
  84. package/lib/Store/object-repository.js +27 -0
  85. package/lib/Types/Auth.d.ts +110 -0
  86. package/lib/Types/Auth.js +2 -0
  87. package/lib/Types/Call.d.ts +13 -0
  88. package/lib/Types/Call.js +2 -0
  89. package/lib/Types/Chat.d.ts +102 -0
  90. package/lib/Types/Chat.js +4 -0
  91. package/lib/Types/Contact.d.ts +19 -0
  92. package/lib/Types/Contact.js +2 -0
  93. package/lib/Types/Events.d.ts +157 -0
  94. package/lib/Types/Events.js +2 -0
  95. package/lib/Types/GroupMetadata.d.ts +55 -0
  96. package/lib/Types/GroupMetadata.js +2 -0
  97. package/lib/Types/Label.d.ts +35 -0
  98. package/lib/Types/Label.js +27 -0
  99. package/lib/Types/LabelAssociation.d.ts +29 -0
  100. package/lib/Types/LabelAssociation.js +9 -0
  101. package/lib/Types/Message.d.ts +273 -0
  102. package/lib/Types/Message.js +9 -0
  103. package/lib/Types/Mex.js +39 -0
  104. package/lib/Types/Newsletter.d.ts +103 -0
  105. package/lib/Types/Newsletter.js +38 -0
  106. package/lib/Types/Product.d.ts +78 -0
  107. package/lib/Types/Product.js +2 -0
  108. package/lib/Types/Signal.d.ts +57 -0
  109. package/lib/Types/Signal.js +2 -0
  110. package/lib/Types/Socket.d.ts +111 -0
  111. package/lib/Types/Socket.js +2 -0
  112. package/lib/Types/State.d.ts +27 -0
  113. package/lib/Types/State.js +2 -0
  114. package/lib/Types/USync.d.ts +25 -0
  115. package/lib/Types/USync.js +2 -0
  116. package/lib/Types/index.d.ts +57 -0
  117. package/lib/Types/index.js +43 -0
  118. package/lib/Utils/Mex.js +39 -0
  119. package/lib/Utils/auth-utils.d.ts +18 -0
  120. package/lib/Utils/auth-utils.js +206 -0
  121. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  122. package/lib/Utils/baileys-event-stream.js +57 -0
  123. package/lib/Utils/browser-presets.js +64 -0
  124. package/lib/Utils/business.d.ts +22 -0
  125. package/lib/Utils/business.js +234 -0
  126. package/lib/Utils/chat-utils.d.ts +71 -0
  127. package/lib/Utils/chat-utils.js +726 -0
  128. package/lib/Utils/companion-reg-client-utils.js +40 -0
  129. package/lib/Utils/crypto.d.ts +41 -0
  130. package/lib/Utils/crypto.js +151 -0
  131. package/lib/Utils/decode-wa-message.d.ts +19 -0
  132. package/lib/Utils/decode-wa-message.js +198 -0
  133. package/lib/Utils/event-buffer.d.ts +35 -0
  134. package/lib/Utils/event-buffer.js +514 -0
  135. package/lib/Utils/extended-messages.js +231 -0
  136. package/lib/Utils/generics.d.ts +92 -0
  137. package/lib/Utils/generics.js +425 -0
  138. package/lib/Utils/history.d.ts +15 -0
  139. package/lib/Utils/history.js +96 -0
  140. package/lib/Utils/identity-change-handler.js +52 -0
  141. package/lib/Utils/index.d.ts +17 -0
  142. package/lib/Utils/index.js +40 -0
  143. package/lib/Utils/link-preview.d.ts +21 -0
  144. package/lib/Utils/link-preview.js +93 -0
  145. package/lib/Utils/logger.d.ts +4 -0
  146. package/lib/Utils/logger.js +7 -0
  147. package/lib/Utils/lt-hash.d.ts +12 -0
  148. package/lib/Utils/lt-hash.js +51 -0
  149. package/lib/Utils/make-mutex.d.ts +7 -0
  150. package/lib/Utils/make-mutex.js +43 -0
  151. package/lib/Utils/message-composer.js +293 -0
  152. package/lib/Utils/message-retry-manager.js +226 -0
  153. package/lib/Utils/messages-media.d.ts +116 -0
  154. package/lib/Utils/messages-media.js +815 -0
  155. package/lib/Utils/messages.d.ts +77 -0
  156. package/lib/Utils/messages.js +888 -0
  157. package/lib/Utils/noise-handler.d.ts +21 -0
  158. package/lib/Utils/noise-handler.js +155 -0
  159. package/lib/Utils/offline-node-processor.js +46 -0
  160. package/lib/Utils/pre-key-manager.js +95 -0
  161. package/lib/Utils/process-message.d.ts +41 -0
  162. package/lib/Utils/process-message.js +321 -0
  163. package/lib/Utils/reporting-utils.js +272 -0
  164. package/lib/Utils/signal.d.ts +32 -0
  165. package/lib/Utils/signal.js +160 -0
  166. package/lib/Utils/stanza-ack.js +38 -0
  167. package/lib/Utils/sync-action-utils.js +50 -0
  168. package/lib/Utils/tc-token-utils.js +169 -0
  169. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  170. package/lib/Utils/use-multi-file-auth-state.js +119 -0
  171. package/lib/Utils/validate-connection.d.ts +11 -0
  172. package/lib/Utils/validate-connection.js +229 -0
  173. package/lib/WABinary/constants.d.ts +30 -0
  174. package/lib/WABinary/constants.js +40 -0
  175. package/lib/WABinary/decode.d.ts +7 -0
  176. package/lib/WABinary/decode.js +252 -0
  177. package/lib/WABinary/encode.d.ts +3 -0
  178. package/lib/WABinary/encode.js +265 -0
  179. package/lib/WABinary/generic-utils.d.ts +17 -0
  180. package/lib/WABinary/generic-utils.js +204 -0
  181. package/lib/WABinary/index.d.ts +5 -0
  182. package/lib/WABinary/index.js +21 -0
  183. package/lib/WABinary/jid-utils.d.ts +31 -0
  184. package/lib/WABinary/jid-utils.js +132 -0
  185. package/lib/WABinary/types.d.ts +18 -0
  186. package/lib/WABinary/types.js +2 -0
  187. package/lib/WAM/BinaryInfo.d.ts +17 -0
  188. package/lib/WAM/BinaryInfo.js +13 -0
  189. package/lib/WAM/constants.d.ts +38 -0
  190. package/lib/WAM/constants.js +15350 -0
  191. package/lib/WAM/encode.d.ts +3 -0
  192. package/lib/WAM/encode.js +155 -0
  193. package/lib/WAM/index.d.ts +3 -0
  194. package/lib/WAM/index.js +19 -0
  195. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  196. package/lib/WAUSync/Protocols/USyncContactProtocol.js +55 -0
  197. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  198. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  199. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  200. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  201. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  202. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  203. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  204. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  205. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  206. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  208. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  209. package/lib/WAUSync/Protocols/index.js +21 -0
  210. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  211. package/lib/WAUSync/USyncQuery.js +93 -0
  212. package/lib/WAUSync/USyncUser.d.ts +12 -0
  213. package/lib/WAUSync/USyncUser.js +34 -0
  214. package/lib/WAUSync/index.d.ts +3 -0
  215. package/lib/WAUSync/index.js +19 -0
  216. package/lib/index.d.ts +12 -0
  217. package/lib/index.js +52 -0
  218. package/package.json +112 -0
@@ -0,0 +1,726 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const WAProto_1 = require("../../WAProto");
6
+ const LabelAssociation_1 = require("../Types/LabelAssociation");
7
+ const WABinary_1 = require("../WABinary");
8
+ const sync_action_utils_1 = require("./sync-action-utils");
9
+ const crypto_1 = require("./crypto");
10
+ const generics_1 = require("./generics");
11
+ const lt_hash_1 = require("./lt-hash");
12
+ const messages_media_1 = require("./messages-media");
13
+ const mutationKeys = (keydata) => {
14
+ const expanded = (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
15
+ return {
16
+ indexKey: expanded.slice(0, 32),
17
+ valueEncryptionKey: expanded.slice(32, 64),
18
+ valueMacKey: expanded.slice(64, 96),
19
+ snapshotMacKey: expanded.slice(96, 128),
20
+ patchMacKey: expanded.slice(128, 160)
21
+ };
22
+ };
23
+ const generateMac = (operation, data, keyId, key) => {
24
+ const getKeyData = () => {
25
+ let r;
26
+ switch (operation) {
27
+ case WAProto_1.proto.SyncdMutation.SyncdOperation.SET:
28
+ r = 0x01;
29
+ break;
30
+ case WAProto_1.proto.SyncdMutation.SyncdOperation.REMOVE:
31
+ r = 0x02;
32
+ break;
33
+ }
34
+ const buff = Buffer.from([r]);
35
+ return Buffer.concat([buff, Buffer.from(keyId, 'base64')]);
36
+ };
37
+ const keyData = getKeyData();
38
+ const last = Buffer.alloc(8); // 8 bytes
39
+ last.set([keyData.length], last.length - 1);
40
+ const total = Buffer.concat([keyData, data, last]);
41
+ const hmac = (0, crypto_1.hmacSign)(total, key, 'sha512');
42
+ return hmac.slice(0, 32);
43
+ };
44
+ const to64BitNetworkOrder = (e) => {
45
+ const buff = Buffer.alloc(8);
46
+ buff.writeUint32BE(e, 4);
47
+ return buff;
48
+ };
49
+ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
50
+ indexValueMap = { ...indexValueMap };
51
+ const addBuffs = [];
52
+ const subBuffs = [];
53
+ return {
54
+ mix: ({ indexMac, valueMac, operation }) => {
55
+ const indexMacBase64 = Buffer.from(indexMac).toString('base64');
56
+ const prevOp = indexValueMap[indexMacBase64];
57
+ if (operation === WAProto_1.proto.SyncdMutation.SyncdOperation.REMOVE) {
58
+ if (!prevOp) {
59
+ throw new boom_1.Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
60
+ }
61
+ // remove from index value mac, since this mutation is erased
62
+ delete indexValueMap[indexMacBase64];
63
+ }
64
+ else {
65
+ addBuffs.push(new Uint8Array(valueMac).buffer);
66
+ // add this index into the history map
67
+ indexValueMap[indexMacBase64] = { valueMac };
68
+ }
69
+ if (prevOp) {
70
+ subBuffs.push(new Uint8Array(prevOp.valueMac).buffer);
71
+ }
72
+ },
73
+ finish: () => {
74
+ const hashArrayBuffer = new Uint8Array(hash).buffer;
75
+ const result = lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
76
+ const buffer = Buffer.from(result);
77
+ return {
78
+ hash: buffer,
79
+ indexValueMap
80
+ };
81
+ }
82
+ };
83
+ };
84
+ const generateSnapshotMac = (lthash, version, name, key) => {
85
+ const total = Buffer.concat([
86
+ lthash,
87
+ to64BitNetworkOrder(version),
88
+ Buffer.from(name, 'utf-8')
89
+ ]);
90
+ return (0, crypto_1.hmacSign)(total, key, 'sha256');
91
+ };
92
+ const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
93
+ const total = Buffer.concat([
94
+ snapshotMac,
95
+ ...valueMacs,
96
+ to64BitNetworkOrder(version),
97
+ Buffer.from(type, 'utf-8')
98
+ ]);
99
+ return (0, crypto_1.hmacSign)(total, key);
100
+ };
101
+ const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
102
+ exports.newLTHashState = newLTHashState;
103
+ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
104
+ const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
105
+ if (!key) {
106
+ throw new boom_1.Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
107
+ }
108
+ const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
109
+ state = { ...state, indexValueMap: { ...state.indexValueMap } };
110
+ const indexBuffer = Buffer.from(JSON.stringify(index));
111
+ const dataProto = WAProto_1.proto.SyncActionData.fromObject({
112
+ index: indexBuffer,
113
+ value: syncAction,
114
+ padding: new Uint8Array(0),
115
+ version: apiVersion
116
+ });
117
+ const encoded = WAProto_1.proto.SyncActionData.encode(dataProto).finish();
118
+ const keyValue = mutationKeys(key.keyData);
119
+ const encValue = (0, crypto_1.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
120
+ const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
121
+ const indexMac = (0, crypto_1.hmacSign)(indexBuffer, keyValue.indexKey);
122
+ // update LT hash
123
+ const generator = makeLtHashGenerator(state);
124
+ generator.mix({ indexMac, valueMac, operation });
125
+ Object.assign(state, generator.finish());
126
+ state.version += 1;
127
+ const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
128
+ const patch = {
129
+ patchMac: generatePatchMac(snapshotMac, [valueMac], state.version, type, keyValue.patchMacKey),
130
+ snapshotMac: snapshotMac,
131
+ keyId: { id: encKeyId },
132
+ mutations: [
133
+ {
134
+ operation: operation,
135
+ record: {
136
+ index: {
137
+ blob: indexMac
138
+ },
139
+ value: {
140
+ blob: Buffer.concat([encValue, valueMac])
141
+ },
142
+ keyId: { id: encKeyId }
143
+ }
144
+ }
145
+ ]
146
+ };
147
+ const base64Index = indexMac.toString('base64');
148
+ state.indexValueMap[base64Index] = { valueMac };
149
+ return { patch, state };
150
+ };
151
+ exports.encodeSyncdPatch = encodeSyncdPatch;
152
+ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
153
+ const ltGenerator = makeLtHashGenerator(initialState);
154
+ // indexKey used to HMAC sign record.index.blob
155
+ // valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
156
+ // the remaining record.value.blob[0:-32] is the mac, it the HMAC sign of key.keyId + decoded proto data + length of bytes in keyId
157
+ for (const msgMutation of msgMutations) {
158
+ // if it's a syncdmutation, get the operation property
159
+ // otherwise, if it's only a record -- it'll be a SET mutation
160
+ const operation = 'operation' in msgMutation ? msgMutation.operation : WAProto_1.proto.SyncdMutation.SyncdOperation.SET;
161
+ const record = ('record' in msgMutation && !!msgMutation.record) ? msgMutation.record : msgMutation;
162
+ const key = await getKey(record.keyId.id);
163
+ const content = Buffer.from(record.value.blob);
164
+ const encContent = content.slice(0, -32);
165
+ const ogValueMac = content.slice(-32);
166
+ if (validateMacs) {
167
+ const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
168
+ if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
169
+ throw new boom_1.Boom('HMAC content verification failed');
170
+ }
171
+ }
172
+ const result = (0, crypto_1.aesDecrypt)(encContent, key.valueEncryptionKey);
173
+ const syncAction = WAProto_1.proto.SyncActionData.decode(result);
174
+ if (validateMacs) {
175
+ const hmac = (0, crypto_1.hmacSign)(syncAction.index, key.indexKey);
176
+ if (Buffer.compare(hmac, record.index.blob) !== 0) {
177
+ throw new boom_1.Boom('HMAC index verification failed');
178
+ }
179
+ }
180
+ const indexStr = Buffer.from(syncAction.index).toString();
181
+ onMutation({ syncAction, index: JSON.parse(indexStr) });
182
+ ltGenerator.mix({
183
+ indexMac: record.index.blob,
184
+ valueMac: ogValueMac,
185
+ operation: operation
186
+ });
187
+ }
188
+ return ltGenerator.finish();
189
+ async function getKey(keyId) {
190
+ const base64Key = Buffer.from(keyId).toString('base64');
191
+ const keyEnc = await getAppStateSyncKey(base64Key);
192
+ if (!keyEnc) {
193
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 404, data: { msgMutations } });
194
+ }
195
+ return mutationKeys(keyEnc.keyData);
196
+ }
197
+ };
198
+ exports.decodeSyncdMutations = decodeSyncdMutations;
199
+ const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
200
+ if (validateMacs) {
201
+ const base64Key = Buffer.from(msg.keyId.id).toString('base64');
202
+ const mainKeyObj = await getAppStateSyncKey(base64Key);
203
+ if (!mainKeyObj) {
204
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
205
+ }
206
+ const mainKey = mutationKeys(mainKeyObj.keyData);
207
+ const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
208
+ const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
209
+ if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
210
+ throw new boom_1.Boom('Invalid patch mac');
211
+ }
212
+ }
213
+ const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
214
+ return result;
215
+ };
216
+ exports.decodeSyncdPatch = decodeSyncdPatch;
217
+ const extractSyncdPatches = async (result, options) => {
218
+ const syncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sync');
219
+ const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
220
+ const final = {};
221
+ await Promise.all(collectionNodes.map(async (collectionNode) => {
222
+ const patchesNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'patches');
223
+ const patches = (0, WABinary_1.getBinaryNodeChildren)(patchesNode || collectionNode, 'patch');
224
+ const snapshotNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'snapshot');
225
+ const syncds = [];
226
+ const name = collectionNode.attrs.name;
227
+ const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
228
+ let snapshot = undefined;
229
+ if (snapshotNode && !!snapshotNode.content) {
230
+ if (!Buffer.isBuffer(snapshotNode)) {
231
+ snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
232
+ }
233
+ const blobRef = WAProto_1.proto.ExternalBlobReference.decode(snapshotNode.content);
234
+ const data = await (0, exports.downloadExternalBlob)(blobRef, options);
235
+ snapshot = WAProto_1.proto.SyncdSnapshot.decode(data);
236
+ }
237
+ for (let { content } of patches) {
238
+ if (content) {
239
+ if (!Buffer.isBuffer(content)) {
240
+ content = Buffer.from(Object.values(content));
241
+ }
242
+ const syncd = WAProto_1.proto.SyncdPatch.decode(content);
243
+ if (!syncd.version) {
244
+ syncd.version = { version: +collectionNode.attrs.version + 1 };
245
+ }
246
+ syncds.push(syncd);
247
+ }
248
+ }
249
+ final[name] = { patches: syncds, hasMorePatches, snapshot };
250
+ }));
251
+ return final;
252
+ };
253
+ exports.extractSyncdPatches = extractSyncdPatches;
254
+ const downloadExternalBlob = async (blob, options) => {
255
+ const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
256
+ const bufferArray = [];
257
+ for await (const chunk of stream) {
258
+ bufferArray.push(chunk);
259
+ }
260
+ return Buffer.concat(bufferArray);
261
+ };
262
+ exports.downloadExternalBlob = downloadExternalBlob;
263
+ const downloadExternalPatch = async (blob, options) => {
264
+ const buffer = await (0, exports.downloadExternalBlob)(blob, options);
265
+ const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
266
+ return syncData;
267
+ };
268
+ exports.downloadExternalPatch = downloadExternalPatch;
269
+ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
270
+ const newState = (0, exports.newLTHashState)();
271
+ newState.version = (0, generics_1.toNumber)(snapshot.version.version);
272
+ const mutationMap = {};
273
+ const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
274
+ || newState.version > minimumVersionNumber;
275
+ const { hash, indexValueMap } = await (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
276
+ ? (mutation) => {
277
+ var _a;
278
+ const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
279
+ mutationMap[index] = mutation;
280
+ }
281
+ : () => { }, validateMacs);
282
+ newState.hash = hash;
283
+ newState.indexValueMap = indexValueMap;
284
+ if (validateMacs) {
285
+ const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
286
+ const keyEnc = await getAppStateSyncKey(base64Key);
287
+ if (!keyEnc) {
288
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
289
+ }
290
+ const result = mutationKeys(keyEnc.keyData);
291
+ const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
292
+ if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
293
+ throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
294
+ }
295
+ }
296
+ return {
297
+ state: newState,
298
+ mutationMap
299
+ };
300
+ };
301
+ exports.decodeSyncdSnapshot = decodeSyncdSnapshot;
302
+ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
303
+ var _a;
304
+ const newState = {
305
+ ...initial,
306
+ indexValueMap: { ...initial.indexValueMap }
307
+ };
308
+ const mutationMap = {};
309
+ for (let i = 0; i < syncds.length; i++) {
310
+ const syncd = syncds[i];
311
+ const { version, keyId, snapshotMac } = syncd;
312
+ if (syncd.externalMutations) {
313
+ logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
314
+ const ref = await (0, exports.downloadExternalPatch)(syncd.externalMutations, options);
315
+ logger === null || logger === void 0 ? void 0 : logger.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
316
+ (_a = syncd.mutations) === null || _a === void 0 ? void 0 : _a.push(...ref.mutations);
317
+ }
318
+ const patchVersion = (0, generics_1.toNumber)(version.version);
319
+ newState.version = patchVersion;
320
+ const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
321
+ const decodeResult = await (0, exports.decodeSyncdPatch)(syncd, name, newState, getAppStateSyncKey, shouldMutate
322
+ ? mutation => {
323
+ var _a;
324
+ const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
325
+ mutationMap[index] = mutation;
326
+ }
327
+ : (() => { }), true);
328
+ newState.hash = decodeResult.hash;
329
+ newState.indexValueMap = decodeResult.indexValueMap;
330
+ if (validateMacs) {
331
+ const base64Key = Buffer.from(keyId.id).toString('base64');
332
+ const keyEnc = await getAppStateSyncKey(base64Key);
333
+ if (!keyEnc) {
334
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
335
+ }
336
+ const result = mutationKeys(keyEnc.keyData);
337
+ const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
338
+ if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
339
+ throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
340
+ }
341
+ }
342
+ // clear memory used up by the mutations
343
+ syncd.mutations = [];
344
+ }
345
+ return { state: newState, mutationMap };
346
+ };
347
+ exports.decodePatches = decodePatches;
348
+ const chatModificationToAppPatch = (mod, jid) => {
349
+ const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
350
+ const getMessageRange = (lastMessages) => {
351
+ let messageRange;
352
+ if (Array.isArray(lastMessages)) {
353
+ const lastMsg = lastMessages[lastMessages.length - 1];
354
+ messageRange = {
355
+ lastMessageTimestamp: lastMsg === null || lastMsg === void 0 ? void 0 : lastMsg.messageTimestamp,
356
+ messages: (lastMessages === null || lastMessages === void 0 ? void 0 : lastMessages.length) ? lastMessages.map(m => {
357
+ var _a, _b;
358
+ if (!((_a = m.key) === null || _a === void 0 ? void 0 : _a.id) || !((_b = m.key) === null || _b === void 0 ? void 0 : _b.remoteJid)) {
359
+ throw new boom_1.Boom('Incomplete key', { statusCode: 400, data: m });
360
+ }
361
+ if ((0, WABinary_1.isJidGroup)(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
362
+ throw new boom_1.Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
363
+ }
364
+ if (!m.messageTimestamp || !(0, generics_1.toNumber)(m.messageTimestamp)) {
365
+ throw new boom_1.Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
366
+ }
367
+ if (m.key.participant) {
368
+ m.key.participant = (0, WABinary_1.jidNormalizedUser)(m.key.participant);
369
+ }
370
+ return m;
371
+ }) : undefined
372
+ };
373
+ }
374
+ else {
375
+ messageRange = lastMessages;
376
+ }
377
+ return messageRange;
378
+ };
379
+ let patch;
380
+ if ('mute' in mod) {
381
+ patch = {
382
+ syncAction: {
383
+ muteAction: {
384
+ muted: !!mod.mute,
385
+ muteEndTimestamp: mod.mute || undefined
386
+ }
387
+ },
388
+ index: ['mute', jid],
389
+ type: 'regular_high',
390
+ apiVersion: 2,
391
+ operation: OP.SET
392
+ };
393
+ }
394
+ else if ('archive' in mod) {
395
+ patch = {
396
+ syncAction: {
397
+ archiveChatAction: {
398
+ archived: !!mod.archive,
399
+ messageRange: getMessageRange(mod.lastMessages)
400
+ }
401
+ },
402
+ index: ['archive', jid],
403
+ type: 'regular_low',
404
+ apiVersion: 3,
405
+ operation: OP.SET
406
+ };
407
+ }
408
+ else if ('markRead' in mod) {
409
+ patch = {
410
+ syncAction: {
411
+ markChatAsReadAction: {
412
+ read: mod.markRead,
413
+ messageRange: getMessageRange(mod.lastMessages)
414
+ }
415
+ },
416
+ index: ['markChatAsRead', jid],
417
+ type: 'regular_low',
418
+ apiVersion: 3,
419
+ operation: OP.SET
420
+ };
421
+ }
422
+ else if ('clear' in mod) {
423
+ if (mod.clear === 'all') {
424
+ throw new boom_1.Boom('not supported');
425
+ }
426
+ else {
427
+ const key = mod.clear.messages[0];
428
+ patch = {
429
+ syncAction: {
430
+ deleteMessageForMeAction: {
431
+ deleteMedia: false,
432
+ messageTimestamp: key.timestamp
433
+ }
434
+ },
435
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
436
+ type: 'regular_high',
437
+ apiVersion: 3,
438
+ operation: OP.SET
439
+ };
440
+ }
441
+ }
442
+ else if ('pin' in mod) {
443
+ patch = {
444
+ syncAction: {
445
+ pinAction: {
446
+ pinned: !!mod.pin
447
+ }
448
+ },
449
+ index: ['pin_v1', jid],
450
+ type: 'regular_low',
451
+ apiVersion: 5,
452
+ operation: OP.SET
453
+ };
454
+ }
455
+ else if ('star' in mod) {
456
+ const key = mod.star.messages[0];
457
+ patch = {
458
+ syncAction: {
459
+ starAction: {
460
+ starred: !!mod.star.star
461
+ }
462
+ },
463
+ index: ['star', jid, key.id, key.fromMe ? '1' : '0', '0'],
464
+ type: 'regular_low',
465
+ apiVersion: 2,
466
+ operation: OP.SET
467
+ };
468
+ }
469
+ else if ('delete' in mod) {
470
+ patch = {
471
+ syncAction: {
472
+ deleteChatAction: {
473
+ messageRange: getMessageRange(mod.lastMessages),
474
+ }
475
+ },
476
+ index: ['deleteChat', jid, '1'],
477
+ type: 'regular_high',
478
+ apiVersion: 6,
479
+ operation: OP.SET
480
+ };
481
+ }
482
+ else if ('pushNameSetting' in mod) {
483
+ patch = {
484
+ syncAction: {
485
+ pushNameSetting: {
486
+ name: mod.pushNameSetting
487
+ }
488
+ },
489
+ index: ['setting_pushName'],
490
+ type: 'critical_block',
491
+ apiVersion: 1,
492
+ operation: OP.SET,
493
+ };
494
+ }
495
+ else if ('addChatLabel' in mod) {
496
+ patch = {
497
+ syncAction: {
498
+ labelAssociationAction: {
499
+ labeled: true,
500
+ }
501
+ },
502
+ index: [LabelAssociation_1.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
503
+ type: 'regular',
504
+ apiVersion: 3,
505
+ operation: OP.SET,
506
+ };
507
+ }
508
+ else if ('removeChatLabel' in mod) {
509
+ patch = {
510
+ syncAction: {
511
+ labelAssociationAction: {
512
+ labeled: false,
513
+ }
514
+ },
515
+ index: [LabelAssociation_1.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
516
+ type: 'regular',
517
+ apiVersion: 3,
518
+ operation: OP.SET,
519
+ };
520
+ }
521
+ else if ('addMessageLabel' in mod) {
522
+ patch = {
523
+ syncAction: {
524
+ labelAssociationAction: {
525
+ labeled: true,
526
+ }
527
+ },
528
+ index: [
529
+ LabelAssociation_1.LabelAssociationType.Message,
530
+ mod.addMessageLabel.labelId,
531
+ jid,
532
+ mod.addMessageLabel.messageId,
533
+ '0',
534
+ '0'
535
+ ],
536
+ type: 'regular',
537
+ apiVersion: 3,
538
+ operation: OP.SET,
539
+ };
540
+ }
541
+ else if ('removeMessageLabel' in mod) {
542
+ patch = {
543
+ syncAction: {
544
+ labelAssociationAction: {
545
+ labeled: false,
546
+ }
547
+ },
548
+ index: [
549
+ LabelAssociation_1.LabelAssociationType.Message,
550
+ mod.removeMessageLabel.labelId,
551
+ jid,
552
+ mod.removeMessageLabel.messageId,
553
+ '0',
554
+ '0'
555
+ ],
556
+ type: 'regular',
557
+ apiVersion: 3,
558
+ operation: OP.SET,
559
+ };
560
+ }
561
+ else {
562
+ throw new boom_1.Boom('not supported');
563
+ }
564
+ patch.syncAction.timestamp = Date.now();
565
+ return patch;
566
+ };
567
+ exports.chatModificationToAppPatch = chatModificationToAppPatch;
568
+ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
569
+ var _a, _b, _c, _d;
570
+ const isInitialSync = !!initialSyncOpts;
571
+ const accountSettings = initialSyncOpts === null || initialSyncOpts === void 0 ? void 0 : initialSyncOpts.accountSettings;
572
+ logger === null || logger === void 0 ? void 0 : logger.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
573
+ const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
574
+ if (action === null || action === void 0 ? void 0 : action.muteAction) {
575
+ ev.emit('chats.update', [
576
+ {
577
+ id,
578
+ muteEndTime: ((_a = action.muteAction) === null || _a === void 0 ? void 0 : _a.muted)
579
+ ? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp)
580
+ : null,
581
+ conditional: getChatUpdateConditional(id, undefined)
582
+ }
583
+ ]);
584
+ }
585
+ else if ((action === null || action === void 0 ? void 0 : action.archiveChatAction) || type === 'archive' || type === 'unarchive') {
586
+ // okay so we've to do some annoying computation here
587
+ // when we're initially syncing the app state
588
+ // there are a few cases we need to handle
589
+ // 1. if the account unarchiveChats setting is true
590
+ // a. if the chat is archived, and no further messages have been received -- simple, keep archived
591
+ // b. if the chat was archived, and the user received messages from the other person afterwards
592
+ // then the chat should be marked unarchved --
593
+ // we compare the timestamp of latest message from the other person to determine this
594
+ // 2. if the account unarchiveChats setting is false -- then it doesn't matter,
595
+ // it'll always take an app state action to mark in unarchived -- which we'll get anyway
596
+ const archiveAction = action === null || action === void 0 ? void 0 : action.archiveChatAction;
597
+ const isArchived = archiveAction
598
+ ? archiveAction.archived
599
+ : type === 'archive';
600
+ // // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
601
+ // // this only applies for the initial sync
602
+ // if(isInitialSync && !isArchived) {
603
+ // isArchived = false
604
+ // }
605
+ const msgRange = !(accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats) ? undefined : archiveAction === null || archiveAction === void 0 ? void 0 : archiveAction.messageRange;
606
+ // logger?.debug({ chat: id, syncAction }, 'message range archive')
607
+ ev.emit('chats.update', [{
608
+ id,
609
+ archived: isArchived,
610
+ conditional: getChatUpdateConditional(id, msgRange)
611
+ }]);
612
+ }
613
+ else if (action === null || action === void 0 ? void 0 : action.markChatAsReadAction) {
614
+ const markReadAction = action.markChatAsReadAction;
615
+ // basically we don't need to fire an "read" update if the chat is being marked as read
616
+ // because the chat is read by default
617
+ // this only applies for the initial sync
618
+ const isNullUpdate = isInitialSync && markReadAction.read;
619
+ ev.emit('chats.update', [{
620
+ id,
621
+ unreadCount: isNullUpdate ? null : !!(markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.read) ? 0 : -1,
622
+ conditional: getChatUpdateConditional(id, markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.messageRange)
623
+ }]);
624
+ }
625
+ else if ((action === null || action === void 0 ? void 0 : action.deleteMessageForMeAction) || type === 'deleteMessageForMe') {
626
+ ev.emit('messages.delete', {
627
+ keys: [
628
+ {
629
+ remoteJid: id,
630
+ id: msgId,
631
+ fromMe: fromMe === '1'
632
+ }
633
+ ]
634
+ });
635
+ }
636
+ else if (action === null || action === void 0 ? void 0 : action.contactAction) {
637
+ const results = (0, sync_action_utils_1.processContactAction)(action.contactAction, id, logger);
638
+ (0, sync_action_utils_1.emitSyncActionResults)(ev, results);
639
+ }
640
+ else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
641
+ const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
642
+ if (name && (me === null || me === void 0 ? void 0 : me.name) !== name) {
643
+ ev.emit('creds.update', { me: { ...me, name } });
644
+ }
645
+ }
646
+ else if (action === null || action === void 0 ? void 0 : action.pinAction) {
647
+ ev.emit('chats.update', [{
648
+ id,
649
+ pinned: ((_c = action.pinAction) === null || _c === void 0 ? void 0 : _c.pinned) ? (0, generics_1.toNumber)(action.timestamp) : null,
650
+ conditional: getChatUpdateConditional(id, undefined)
651
+ }]);
652
+ }
653
+ else if (action === null || action === void 0 ? void 0 : action.unarchiveChatsSetting) {
654
+ const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
655
+ ev.emit('creds.update', { accountSettings: { unarchiveChats } });
656
+ logger === null || logger === void 0 ? void 0 : logger.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
657
+ if (accountSettings) {
658
+ accountSettings.unarchiveChats = unarchiveChats;
659
+ }
660
+ }
661
+ else if ((action === null || action === void 0 ? void 0 : action.starAction) || type === 'star') {
662
+ let starred = (_d = action === null || action === void 0 ? void 0 : action.starAction) === null || _d === void 0 ? void 0 : _d.starred;
663
+ if (typeof starred !== 'boolean') {
664
+ starred = syncAction.index[syncAction.index.length - 1] === '1';
665
+ }
666
+ ev.emit('messages.update', [
667
+ {
668
+ key: { remoteJid: id, id: msgId, fromMe: fromMe === '1' },
669
+ update: { starred }
670
+ }
671
+ ]);
672
+ }
673
+ else if ((action === null || action === void 0 ? void 0 : action.deleteChatAction) || type === 'deleteChat') {
674
+ if (!isInitialSync) {
675
+ ev.emit('chats.delete', [id]);
676
+ }
677
+ }
678
+ else if (action === null || action === void 0 ? void 0 : action.labelEditAction) {
679
+ const { name, color, deleted, predefinedId } = action.labelEditAction;
680
+ ev.emit('labels.edit', {
681
+ id,
682
+ name: name,
683
+ color: color,
684
+ deleted: deleted,
685
+ predefinedId: predefinedId ? String(predefinedId) : undefined
686
+ });
687
+ }
688
+ else if (action === null || action === void 0 ? void 0 : action.labelAssociationAction) {
689
+ ev.emit('labels.association', {
690
+ type: action.labelAssociationAction.labeled
691
+ ? 'add'
692
+ : 'remove',
693
+ association: type === LabelAssociation_1.LabelAssociationType.Chat
694
+ ? {
695
+ type: LabelAssociation_1.LabelAssociationType.Chat,
696
+ chatId: syncAction.index[2],
697
+ labelId: syncAction.index[1]
698
+ }
699
+ : {
700
+ type: LabelAssociation_1.LabelAssociationType.Message,
701
+ chatId: syncAction.index[2],
702
+ messageId: syncAction.index[3],
703
+ labelId: syncAction.index[1]
704
+ }
705
+ });
706
+ }
707
+ else {
708
+ logger === null || logger === void 0 ? void 0 : logger.debug({ syncAction, id }, 'unprocessable update');
709
+ }
710
+ function getChatUpdateConditional(id, msgRange) {
711
+ return isInitialSync
712
+ ? (data) => {
713
+ const chat = data.historySets.chats[id] || data.chatUpserts[id];
714
+ if (chat) {
715
+ return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
716
+ }
717
+ }
718
+ : undefined;
719
+ }
720
+ function isValidPatchBasedOnMessageRange(chat, msgRange) {
721
+ const lastMsgTimestamp = Number((msgRange === null || msgRange === void 0 ? void 0 : msgRange.lastMessageTimestamp) || (msgRange === null || msgRange === void 0 ? void 0 : msgRange.lastSystemMessageTimestamp) || 0);
722
+ const chatLastMsgTimestamp = Number((chat === null || chat === void 0 ? void 0 : chat.lastMessageRecvTimestamp) || 0);
723
+ return lastMsgTimestamp >= chatLastMsgTimestamp;
724
+ }
725
+ };
726
+ exports.processSyncAction = processSyncAction;