cuki-bailx 1.1.1 → 1.2.2

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 (116) hide show
  1. package/WAProto/index.js +79296 -118676
  2. package/engine-requirements.js +1 -1
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.d.ts +6 -4
  5. package/lib/Defaults/index.js +102 -78
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
  8. package/lib/Socket/Client/index.d.ts +3 -2
  9. package/lib/Socket/Client/index.js +3 -2
  10. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  11. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  12. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
  13. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -12
  14. package/lib/Socket/business.d.ts +58 -59
  15. package/lib/Socket/chats.d.ts +27 -29
  16. package/lib/Socket/chats.js +90 -97
  17. package/lib/Socket/dugong.d.ts +219 -0
  18. package/lib/Socket/dugong.js +441 -0
  19. package/lib/Socket/groups.d.ts +32 -41
  20. package/lib/Socket/groups.js +5 -20
  21. package/lib/Socket/index.d.ts +64 -63
  22. package/lib/Socket/index.js +2 -2
  23. package/lib/Socket/messages-recv.js +65 -9
  24. package/lib/Socket/messages-send.d.ts +47 -49
  25. package/lib/Socket/messages-send.js +312 -379
  26. package/lib/Socket/newsletter.d.ts +37 -39
  27. package/lib/Socket/newsletter.js +40 -54
  28. package/lib/Socket/registration.d.ts +267 -0
  29. package/lib/Socket/registration.js +166 -0
  30. package/lib/Socket/socket.d.ts +10 -10
  31. package/lib/Socket/socket.js +628 -0
  32. package/lib/Socket/socket.js.bak +38 -43
  33. package/lib/Socket/usync.d.ts +3 -3
  34. package/lib/Store/index.d.ts +2 -1
  35. package/lib/Store/index.js +3 -1
  36. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  37. package/lib/Store/make-cache-manager-store.js +83 -0
  38. package/lib/Store/make-in-memory-store.d.ts +24 -24
  39. package/lib/Store/make-in-memory-store.js +11 -13
  40. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  41. package/lib/Store/make-ordered-dictionary.js +2 -2
  42. package/lib/Types/Auth.d.ts +7 -0
  43. package/lib/Types/Call.d.ts +1 -1
  44. package/lib/Types/Chat.d.ts +7 -14
  45. package/lib/Types/Contact.d.ts +1 -5
  46. package/lib/Types/Events.d.ts +2 -44
  47. package/lib/Types/GroupMetadata.d.ts +2 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +21 -148
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.d.ts +13 -0
  53. package/lib/Types/Newsletter.js +17 -3
  54. package/lib/Types/Socket.d.ts +9 -17
  55. package/lib/Types/index.d.ts +1 -8
  56. package/lib/Types/index.js +2 -2
  57. package/lib/Utils/auth-utils.d.ts +3 -3
  58. package/lib/Utils/auth-utils.js +13 -6
  59. package/lib/Utils/business.js +2 -2
  60. package/lib/Utils/chat-utils.d.ts +16 -15
  61. package/lib/Utils/chat-utils.js +35 -36
  62. package/lib/Utils/crypto.d.ts +16 -15
  63. package/lib/Utils/crypto.js +29 -71
  64. package/lib/Utils/decode-wa-message.d.ts +6 -22
  65. package/lib/Utils/decode-wa-message.js +56 -65
  66. package/lib/Utils/event-buffer.d.ts +2 -2
  67. package/lib/Utils/event-buffer.js +7 -11
  68. package/lib/Utils/generics.d.ts +20 -17
  69. package/lib/Utils/generics.js +23 -73
  70. package/lib/Utils/history.d.ts +0 -4
  71. package/lib/Utils/history.js +6 -4
  72. package/lib/Utils/link-preview.d.ts +2 -2
  73. package/lib/Utils/link-preview.js +1 -34
  74. package/lib/Utils/logger.d.ts +3 -10
  75. package/lib/Utils/lt-hash.d.ts +2 -2
  76. package/lib/Utils/lt-hash.js +6 -6
  77. package/lib/Utils/make-mutex.d.ts +2 -2
  78. package/lib/Utils/messages-media.d.ts +24 -28
  79. package/lib/Utils/messages-media.js +115 -263
  80. package/lib/Utils/messages.d.ts +10 -8
  81. package/lib/Utils/messages.js +72 -298
  82. package/lib/Utils/noise-handler.d.ts +12 -10
  83. package/lib/Utils/noise-handler.js +23 -18
  84. package/lib/Utils/process-message.d.ts +4 -5
  85. package/lib/Utils/process-message.js +23 -74
  86. package/lib/Utils/signal.d.ts +1 -2
  87. package/lib/Utils/signal.js +35 -37
  88. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  89. package/lib/Utils/use-multi-file-auth-state.js +6 -51
  90. package/lib/Utils/validate-connection.d.ts +4 -3
  91. package/lib/Utils/validate-connection.js +52 -20
  92. package/lib/WABinary/constants.d.ts +4 -4
  93. package/lib/WABinary/constants.js +13 -1276
  94. package/lib/WABinary/decode.d.ts +4 -3
  95. package/lib/WABinary/decode.js +13 -26
  96. package/lib/WABinary/encode.d.ts +2 -1
  97. package/lib/WABinary/encode.js +17 -39
  98. package/lib/WABinary/generic-utils.d.ts +3 -1
  99. package/lib/WABinary/generic-utils.js +85 -2
  100. package/lib/WABinary/jid-utils.d.ts +5 -10
  101. package/lib/WABinary/jid-utils.js +5 -26
  102. package/lib/WAM/BinaryInfo.d.ts +11 -2
  103. package/lib/WAM/encode.d.ts +2 -1
  104. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  105. package/lib/index.d.ts +2 -6
  106. package/lib/index.js +7 -22
  107. package/lib/index.js.bak +37 -0
  108. package/package.json +103 -111
  109. package/LICENSE +0 -21
  110. package/WAProto/GenerateStatics.sh +0 -4
  111. package/WAProto/WAProto.proto +0 -4775
  112. package/WAProto/index.d.ts +0 -55057
  113. package/WAProto/index.ts.ts +0 -53473
  114. package/WAProto/p.html +0 -1
  115. package/lib/WABinary/jid-utils.js.bak +0 -83
  116. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initAuthCreds = exports.addTransactionCapability = void 0;
7
- exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
6
+ exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
8
7
  const crypto_1 = require("crypto");
9
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
+ const node_cache_1 = __importDefault(require("node-cache"));
9
+ const uuid_1 = require("uuid");
10
10
  const Defaults_1 = require("../Defaults");
11
11
  const crypto_2 = require("./crypto");
12
12
  const generics_1 = require("./generics");
@@ -18,7 +18,7 @@ const generics_1 = require("./generics");
18
18
  */
19
19
  function makeCacheableSignalKeyStore(store, logger, _cache) {
20
20
  const cache = _cache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
21
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
22
22
  useClones: false,
23
23
  deleteOnExpire: true,
24
24
  });
@@ -39,7 +39,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
39
39
  }
40
40
  }
41
41
  if (idsToFetch.length) {
42
- logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
42
+ logger.trace({ items: idsToFetch.length }, 'loading from store');
43
43
  const fetched = await store.get(type, idsToFetch);
44
44
  for (const id of idsToFetch) {
45
45
  const item = fetched[id];
@@ -59,7 +59,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
59
59
  keys += 1;
60
60
  }
61
61
  }
62
- logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
62
+ logger.trace({ keys }, 'updated cache');
63
63
  await store.set(data);
64
64
  },
65
65
  async clear() {
@@ -69,6 +69,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
69
69
  }
70
70
  };
71
71
  }
72
+ exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
72
73
  /**
73
74
  * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
74
75
  * this allows batch read & write operations & improves the performance of the lib
@@ -190,7 +191,13 @@ const initAuthCreds = () => {
190
191
  accountSettings: {
191
192
  unarchiveChats: false
192
193
  },
194
+ // mobile creds
195
+ deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
196
+ phoneId: (0, uuid_1.v4)(),
197
+ identityId: (0, crypto_1.randomBytes)(20),
193
198
  registered: false,
199
+ backupToken: (0, crypto_1.randomBytes)(20),
200
+ registration: {},
194
201
  pairingCode: undefined,
195
202
  lastPropHash: undefined,
196
203
  routingInfo: undefined,
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
4
- exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
3
+ exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
5
4
  const boom_1 = require("@hapi/boom");
6
5
  const crypto_1 = require("crypto");
7
6
  const WABinary_1 = require("../WABinary");
@@ -189,6 +188,7 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
189
188
  };
190
189
  return product;
191
190
  }
191
+ exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
192
192
  /**
193
193
  * Uploads images not already uploaded to WA's servers
194
194
  */
@@ -1,8 +1,9 @@
1
+ /// <reference types="node" />
1
2
  import { AxiosRequestConfig } from 'axios';
3
+ import type { Logger } from 'pino';
2
4
  import { proto } from '../../WAProto';
3
5
  import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
4
6
  import { BinaryNode } from '../WABinary';
5
- import { ILogger } from './logger';
6
7
  type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
7
8
  export type ChatMutationMap = {
8
9
  [index: string]: ChatMutation;
@@ -13,7 +14,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
13
14
  state: LTHashState;
14
15
  }>;
15
16
  export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
16
- hash: Buffer<any>;
17
+ hash: Buffer;
17
18
  indexValueMap: {
18
19
  [indexMacBase64: string]: {
19
20
  valueMac: Uint8Array | Buffer;
@@ -21,7 +22,7 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
21
22
  };
22
23
  }>;
23
24
  export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
24
- hash: Buffer<any>;
25
+ hash: Buffer;
25
26
  indexValueMap: {
26
27
  [indexMacBase64: string]: {
27
28
  valueMac: Uint8Array | Buffer;
@@ -29,42 +30,42 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
29
30
  };
30
31
  }>;
31
32
  export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
32
- critical_unblock_low: {
33
+ critical_block: {
33
34
  patches: proto.ISyncdPatch[];
34
35
  hasMorePatches: boolean;
35
- snapshot?: proto.ISyncdSnapshot;
36
+ snapshot?: proto.ISyncdSnapshot | undefined;
36
37
  };
37
- regular_high: {
38
+ critical_unblock_low: {
38
39
  patches: proto.ISyncdPatch[];
39
40
  hasMorePatches: boolean;
40
- snapshot?: proto.ISyncdSnapshot;
41
+ snapshot?: proto.ISyncdSnapshot | undefined;
41
42
  };
42
- regular_low: {
43
+ regular_high: {
43
44
  patches: proto.ISyncdPatch[];
44
45
  hasMorePatches: boolean;
45
- snapshot?: proto.ISyncdSnapshot;
46
+ snapshot?: proto.ISyncdSnapshot | undefined;
46
47
  };
47
- critical_block: {
48
+ regular_low: {
48
49
  patches: proto.ISyncdPatch[];
49
50
  hasMorePatches: boolean;
50
- snapshot?: proto.ISyncdSnapshot;
51
+ snapshot?: proto.ISyncdSnapshot | undefined;
51
52
  };
52
53
  regular: {
53
54
  patches: proto.ISyncdPatch[];
54
55
  hasMorePatches: boolean;
55
- snapshot?: proto.ISyncdSnapshot;
56
+ snapshot?: proto.ISyncdSnapshot | undefined;
56
57
  };
57
58
  }>;
58
- export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer<ArrayBuffer>>;
59
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
59
60
  export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
60
61
  export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
61
62
  state: LTHashState;
62
63
  mutationMap: ChatMutationMap;
63
64
  }>;
64
- export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
65
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
65
66
  state: LTHashState;
66
67
  mutationMap: ChatMutationMap;
67
68
  }>;
68
69
  export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
69
- export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: ILogger) => void;
70
+ export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: Logger) => void;
70
71
  export {};
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
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
4
  const boom_1 = require("@hapi/boom");
5
5
  const WAProto_1 = require("../../WAProto");
6
- const WABinary_1 = require("../WABinary");
7
6
  const LabelAssociation_1 = require("../Types/LabelAssociation");
7
+ const WABinary_1 = require("../WABinary");
8
8
  const crypto_1 = require("./crypto");
9
9
  const generics_1 = require("./generics");
10
10
  const lt_hash_1 = require("./lt-hash");
11
11
  const messages_media_1 = require("./messages-media");
12
- const mutationKeys = async (keydata) => {
13
- const expanded = await (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
12
+ const mutationKeys = (keydata) => {
13
+ const expanded = (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
14
14
  return {
15
15
  indexKey: expanded.slice(0, 32),
16
16
  valueEncryptionKey: expanded.slice(32, 64),
@@ -69,9 +69,9 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
69
69
  subBuffs.push(new Uint8Array(prevOp.valueMac).buffer);
70
70
  }
71
71
  },
72
- finish: async () => {
72
+ finish: () => {
73
73
  const hashArrayBuffer = new Uint8Array(hash).buffer;
74
- const result = await lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
74
+ const result = lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
75
75
  const buffer = Buffer.from(result);
76
76
  return {
77
77
  hash: buffer,
@@ -114,14 +114,14 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
114
114
  version: apiVersion
115
115
  });
116
116
  const encoded = WAProto_1.proto.SyncActionData.encode(dataProto).finish();
117
- const keyValue = await mutationKeys(key.keyData);
117
+ const keyValue = mutationKeys(key.keyData);
118
118
  const encValue = (0, crypto_1.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
119
119
  const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
120
120
  const indexMac = (0, crypto_1.hmacSign)(indexBuffer, keyValue.indexKey);
121
121
  // update LT hash
122
122
  const generator = makeLtHashGenerator(state);
123
123
  generator.mix({ indexMac, valueMac, operation });
124
- Object.assign(state, await generator.finish());
124
+ Object.assign(state, generator.finish());
125
125
  state.version += 1;
126
126
  const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
127
127
  const patch = {
@@ -184,7 +184,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
184
184
  operation: operation
185
185
  });
186
186
  }
187
- return await ltGenerator.finish();
187
+ return ltGenerator.finish();
188
188
  async function getKey(keyId) {
189
189
  const base64Key = Buffer.from(keyId).toString('base64');
190
190
  const keyEnc = await getAppStateSyncKey(base64Key);
@@ -202,7 +202,7 @@ const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onM
202
202
  if (!mainKeyObj) {
203
203
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
204
204
  }
205
- const mainKey = await mutationKeys(mainKeyObj.keyData);
205
+ const mainKey = mutationKeys(mainKeyObj.keyData);
206
206
  const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
207
207
  const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
208
208
  if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
@@ -286,7 +286,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
286
286
  if (!keyEnc) {
287
287
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
288
288
  }
289
- const result = await mutationKeys(keyEnc.keyData);
289
+ const result = mutationKeys(keyEnc.keyData);
290
290
  const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
291
291
  if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
292
292
  throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
@@ -332,7 +332,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
332
332
  if (!keyEnc) {
333
333
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
334
334
  }
335
- const result = await mutationKeys(keyEnc.keyData);
335
+ const result = mutationKeys(keyEnc.keyData);
336
336
  const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
337
337
  if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
338
338
  throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
@@ -418,31 +418,25 @@ const chatModificationToAppPatch = (mod, jid) => {
418
418
  operation: OP.SET
419
419
  };
420
420
  }
421
- else if ('deleteForMe' in mod) {
422
- const { timestamp, key, deleteMedia } = mod.deleteForMe;
423
- patch = {
424
- syncAction: {
425
- deleteMessageForMeAction: {
426
- deleteMedia,
427
- messageTimestamp: timestamp
428
- }
429
- },
430
- index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
431
- type: 'regular_high',
432
- apiVersion: 3,
433
- operation: OP.SET
434
- };
435
- }
436
421
  else if ('clear' in mod) {
437
- patch = {
438
- syncAction: {
439
- clearChatAction: {} // add message range later
440
- },
441
- index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
442
- type: 'regular_high',
443
- apiVersion: 6,
444
- operation: OP.SET
445
- };
422
+ if (mod.clear === 'all') {
423
+ throw new boom_1.Boom('not supported');
424
+ }
425
+ else {
426
+ const key = mod.clear.messages[0];
427
+ patch = {
428
+ syncAction: {
429
+ deleteMessageForMeAction: {
430
+ deleteMedia: false,
431
+ messageTimestamp: key.timestamp
432
+ }
433
+ },
434
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
435
+ type: 'regular_high',
436
+ apiVersion: 3,
437
+ operation: OP.SET
438
+ };
439
+ }
446
440
  }
447
441
  else if ('pin' in mod) {
448
442
  patch = {
@@ -639,7 +633,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
639
633
  });
640
634
  }
641
635
  else if (action === null || action === void 0 ? void 0 : action.contactAction) {
642
- ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName, lid: action.contactAction.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(id) ? id : action.contactAction.pnJid }]);
636
+ ev.emit('contacts.upsert', [{
637
+ id: id,
638
+ name: action.contactAction.fullName,
639
+ lid: action.contactAction.lidJid || undefined,
640
+ jid: (0, WABinary_1.isJidUser)(id) ? id : undefined
641
+ }]);
643
642
  }
644
643
  else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
645
644
  const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
@@ -1,9 +1,10 @@
1
+ /// <reference types="node" />
1
2
  import { KeyPair } from '../Types';
2
3
  /** prefix version byte to the pub keys, required for some curve crypto functions */
3
- export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
4
+ export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
4
5
  export declare const Curve: {
5
6
  generateKeyPair: () => KeyPair;
6
- sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer<any>;
7
+ sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
7
8
  sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
8
9
  verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
9
10
  };
@@ -16,25 +17,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
16
17
  * encrypt AES 256 GCM;
17
18
  * where the tag tag is suffixed to the ciphertext
18
19
  * */
19
- export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
20
+ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
20
21
  /**
21
22
  * decrypt AES 256 GCM;
22
23
  * where the auth tag is suffixed to the ciphertext
23
24
  * */
24
- export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
25
- export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
26
- export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
25
+ export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
26
+ export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
27
+ export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
27
28
  /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
28
- export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer<ArrayBuffer>;
29
+ export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
29
30
  /** decrypt AES 256 CBC */
30
- export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
31
- export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer<ArrayBuffer>;
32
- export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
33
- export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer<ArrayBufferLike>;
34
- export declare function sha256(buffer: Buffer): Buffer<ArrayBufferLike>;
35
- export declare function md5(buffer: Buffer): Buffer<ArrayBufferLike>;
31
+ export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
32
+ export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
33
+ export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
34
+ export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
35
+ export declare function sha256(buffer: Buffer): Buffer;
36
+ export declare function md5(buffer: Buffer): Buffer;
36
37
  export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
37
38
  salt?: Buffer;
38
39
  info?: string;
39
- }): Promise<Buffer>;
40
- export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
40
+ }): Buffer;
41
+ export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
@@ -15,43 +15,22 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
35
28
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
37
- exports.aesEncryptGCM = aesEncryptGCM;
38
- exports.aesDecryptGCM = aesDecryptGCM;
39
- exports.aesEncryptCTR = aesEncryptCTR;
40
- exports.aesDecryptCTR = aesDecryptCTR;
41
- exports.aesDecrypt = aesDecrypt;
42
- exports.aesDecryptWithIV = aesDecryptWithIV;
43
- exports.aesEncrypt = aesEncrypt;
44
- exports.aesEncrypWithIV = aesEncrypWithIV;
45
- exports.hmacSign = hmacSign;
46
- exports.sha256 = sha256;
47
- exports.md5 = md5;
48
- exports.hkdf = hkdf;
49
- exports.derivePairingCodeKey = derivePairingCodeKey;
29
+ exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
50
30
  const crypto_1 = require("crypto");
31
+ const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
51
32
  const libsignal = __importStar(require("libsignal"));
52
33
  const Defaults_1 = require("../Defaults");
53
- // insure browser & node compatibility
54
- const { subtle } = globalThis.crypto;
55
34
  /** prefix version byte to the pub keys, required for some curve crypto functions */
56
35
  const generateSignalPubKey = (pubKey) => (pubKey.length === 33
57
36
  ? pubKey
@@ -98,6 +77,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
98
77
  cipher.setAAD(additionalData);
99
78
  return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
100
79
  }
80
+ exports.aesEncryptGCM = aesEncryptGCM;
101
81
  /**
102
82
  * decrypt AES 256 GCM;
103
83
  * where the auth tag is suffixed to the ciphertext
@@ -112,82 +92,60 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
112
92
  decipher.setAuthTag(tag);
113
93
  return Buffer.concat([decipher.update(enc), decipher.final()]);
114
94
  }
95
+ exports.aesDecryptGCM = aesDecryptGCM;
115
96
  function aesEncryptCTR(plaintext, key, iv) {
116
97
  const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
117
98
  return Buffer.concat([cipher.update(plaintext), cipher.final()]);
118
99
  }
100
+ exports.aesEncryptCTR = aesEncryptCTR;
119
101
  function aesDecryptCTR(ciphertext, key, iv) {
120
102
  const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
121
103
  return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
122
104
  }
105
+ exports.aesDecryptCTR = aesDecryptCTR;
123
106
  /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
124
107
  function aesDecrypt(buffer, key) {
125
108
  return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
126
109
  }
110
+ exports.aesDecrypt = aesDecrypt;
127
111
  /** decrypt AES 256 CBC */
128
112
  function aesDecryptWithIV(buffer, key, IV) {
129
113
  const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
130
114
  return Buffer.concat([aes.update(buffer), aes.final()]);
131
115
  }
116
+ exports.aesDecryptWithIV = aesDecryptWithIV;
132
117
  // encrypt AES 256 CBC; where a random IV is prefixed to the buffer
133
118
  function aesEncrypt(buffer, key) {
134
119
  const IV = (0, crypto_1.randomBytes)(16);
135
120
  const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
136
121
  return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
137
122
  }
123
+ exports.aesEncrypt = aesEncrypt;
138
124
  // encrypt AES 256 CBC with a given IV
139
125
  function aesEncrypWithIV(buffer, key, IV) {
140
126
  const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
141
127
  return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
142
128
  }
129
+ exports.aesEncrypWithIV = aesEncrypWithIV;
143
130
  // sign HMAC using SHA 256
144
131
  function hmacSign(buffer, key, variant = 'sha256') {
145
132
  return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
146
133
  }
134
+ exports.hmacSign = hmacSign;
147
135
  function sha256(buffer) {
148
136
  return (0, crypto_1.createHash)('sha256').update(buffer).digest();
149
137
  }
138
+ exports.sha256 = sha256;
150
139
  function md5(buffer) {
151
140
  return (0, crypto_1.createHash)('md5').update(buffer).digest();
152
141
  }
142
+ exports.md5 = md5;
153
143
  // HKDF key expansion
154
- async function hkdf(buffer, expandedLength, info) {
155
- // Ensure we have a Uint8Array for the key material
156
- const inputKeyMaterial = buffer instanceof Uint8Array
157
- ? buffer
158
- : new Uint8Array(buffer);
159
- // Set default values if not provided
160
- const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
161
- const infoBytes = info.info
162
- ? new TextEncoder().encode(info.info)
163
- : new Uint8Array(0);
164
- // Import the input key material
165
- const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
166
- // Derive bits using HKDF
167
- const derivedBits = await subtle.deriveBits({
168
- name: 'HKDF',
169
- hash: 'SHA-256',
170
- salt: salt,
171
- info: infoBytes
172
- }, importedKey, expandedLength * 8 // Convert bytes to bits
173
- );
174
- return Buffer.from(derivedBits);
144
+ function hkdf(buffer, expandedLength, info) {
145
+ return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
175
146
  }
176
- async function derivePairingCodeKey(pairingCode, salt) {
177
- // Convert inputs to formats Web Crypto API can work with
178
- const encoder = new TextEncoder();
179
- const pairingCodeBuffer = encoder.encode(pairingCode);
180
- const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
181
- // Import the pairing code as key material
182
- const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
183
- // Derive bits using PBKDF2 with the same parameters
184
- // 2 << 16 = 131,072 iterations
185
- const derivedBits = await subtle.deriveBits({
186
- name: 'PBKDF2',
187
- salt: saltBuffer,
188
- iterations: 2 << 16,
189
- hash: 'SHA-256'
190
- }, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
191
- );
192
- return Buffer.from(derivedBits);
147
+ exports.hkdf = hkdf;
148
+ function derivePairingCodeKey(pairingCode, salt) {
149
+ return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
193
150
  }
151
+ exports.derivePairingCodeKey = derivePairingCodeKey;
@@ -1,34 +1,18 @@
1
- import { ILogger } from './logger';
2
- import { SignalRepository, WAMessage } from '../Types';
1
+ import { Logger } from 'pino';
2
+ import { proto } from '../../WAProto';
3
+ import { SignalRepository } from '../Types';
3
4
  import { BinaryNode } from '../WABinary';
4
- export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
5
- export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
6
- export declare const NACK_REASONS: {
7
- ParsingError: number;
8
- UnrecognizedStanza: number;
9
- UnrecognizedStanzaClass: number;
10
- UnrecognizedStanzaType: number;
11
- InvalidProtobuf: number;
12
- InvalidHostedCompanionStanza: number;
13
- MissingMessageSecret: number;
14
- SignalErrorOldCounter: number;
15
- MessageDeletedOnPeer: number;
16
- UnhandledError: number;
17
- UnsupportedAdminRevoke: number;
18
- UnsupportedLIDGroup: number;
19
- DBOperationFailed: number;
20
- };
21
5
  /**
22
6
  * Decode the received node as a message.
23
7
  * @note this will only parse the message, not decrypt it
24
8
  */
25
9
  export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
26
- fullMessage: WAMessage;
10
+ fullMessage: proto.IWebMessageInfo;
27
11
  author: string;
28
12
  sender: string;
29
13
  };
30
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
31
- fullMessage: WAMessage;
14
+ export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
15
+ fullMessage: proto.IWebMessageInfo;
32
16
  category: string;
33
17
  author: string;
34
18
  decrypt(): Promise<void>;