@genuxofficial/baileys 2.0.0 → 4.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 (108) hide show
  1. package/WAProto/WAProto.proto +4451 -0
  2. package/WAProto/index.d.ts +219 -2233
  3. package/WAProto/index.js +525 -6773
  4. package/WAProto/shizo.x +1 -0
  5. package/engine-requirements.js +1 -1
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +236 -3
  8. package/lib/Defaults/index.js +24 -8
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/libsignal.js +9 -18
  11. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -0
  12. package/lib/Socket/Client/index.d.ts +3 -2
  13. package/lib/Socket/Client/index.js +3 -2
  14. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  15. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  16. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  17. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
  18. package/lib/Socket/business.d.ts +43 -43
  19. package/lib/Socket/chats.d.ts +17 -23
  20. package/lib/Socket/chats.js +9 -123
  21. package/lib/Socket/groups.d.ts +27 -32
  22. package/lib/Socket/groups.js +5 -18
  23. package/lib/Socket/index.d.ts +51 -49
  24. package/lib/Socket/index.js +2 -2
  25. package/lib/Socket/messages-recv.d.ts +41 -42
  26. package/lib/Socket/messages-recv.js +20 -39
  27. package/lib/Socket/messages-send.d.ts +33 -38
  28. package/lib/Socket/messages-send.js +16 -37
  29. package/lib/Socket/newsletter.d.ts +30 -35
  30. package/lib/Socket/newsletter.js +22 -26
  31. package/lib/Socket/registration.d.ts +271 -0
  32. package/lib/Socket/registration.js +166 -0
  33. package/lib/Socket/socket.d.ts +10 -9
  34. package/lib/Socket/socket.js +19 -16
  35. package/lib/Socket/usync.d.ts +12 -10
  36. package/lib/Socket/usync.js +15 -10
  37. package/lib/Store/index.d.ts +2 -1
  38. package/lib/Store/index.js +3 -1
  39. package/lib/Store/make-in-memory-store.d.ts +1 -1
  40. package/lib/Store/make-in-memory-store.js +10 -8
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Store/make-ordered-dictionary.js +2 -2
  43. package/lib/Types/Auth.d.ts +8 -0
  44. package/lib/Types/Chat.d.ts +2 -12
  45. package/lib/Types/Contact.d.ts +1 -6
  46. package/lib/Types/GroupMetadata.d.ts +0 -7
  47. package/lib/Types/Label.d.ts +0 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +8 -7
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.js +2 -2
  53. package/lib/Types/Socket.d.ts +6 -7
  54. package/lib/Types/index.js +1 -1
  55. package/lib/Utils/auth-utils.d.ts +1 -1
  56. package/lib/Utils/auth-utils.js +12 -5
  57. package/lib/Utils/business.js +2 -2
  58. package/lib/Utils/chat-utils.d.ts +13 -11
  59. package/lib/Utils/chat-utils.js +2 -28
  60. package/lib/Utils/crypto.d.ts +16 -14
  61. package/lib/Utils/crypto.js +22 -34
  62. package/lib/Utils/decode-wa-message.d.ts +2 -4
  63. package/lib/Utils/decode-wa-message.js +24 -160
  64. package/lib/Utils/event-buffer.js +6 -4
  65. package/lib/Utils/generics.d.ts +12 -40
  66. package/lib/Utils/generics.js +25 -103
  67. package/lib/Utils/link-preview.js +1 -34
  68. package/lib/Utils/lt-hash.d.ts +3 -3
  69. package/lib/Utils/lt-hash.js +45 -11
  70. package/lib/Utils/make-mutex.d.ts +2 -2
  71. package/lib/Utils/messages-media.d.ts +16 -26
  72. package/lib/Utils/messages-media.js +26 -102
  73. package/lib/Utils/messages.d.ts +8 -5
  74. package/lib/Utils/messages.js +15 -17
  75. package/lib/Utils/noise-handler.d.ts +8 -5
  76. package/lib/Utils/noise-handler.js +10 -5
  77. package/lib/Utils/process-message.js +2 -2
  78. package/lib/Utils/use-multi-file-auth-state.js +11 -48
  79. package/lib/Utils/validate-connection.d.ts +3 -2
  80. package/lib/Utils/validate-connection.js +44 -10
  81. package/lib/WABinary/constants.js +5 -5
  82. package/lib/WABinary/decode.d.ts +4 -2
  83. package/lib/WABinary/decode.js +7 -17
  84. package/lib/WABinary/encode.d.ts +3 -1
  85. package/lib/WABinary/encode.js +17 -40
  86. package/lib/WABinary/generic-utils.d.ts +3 -1
  87. package/lib/WABinary/generic-utils.js +2 -2
  88. package/lib/WABinary/jid-utils.d.ts +3 -8
  89. package/lib/WABinary/jid-utils.js +2 -23
  90. package/lib/WAM/BinaryInfo.d.ts +12 -2
  91. package/lib/WAM/constants.d.ts +2 -3
  92. package/lib/WAM/encode.d.ts +3 -1
  93. package/lib/WAM/encode.js +2 -2
  94. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  95. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  96. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  97. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  98. package/lib/WAUSync/USyncQuery.d.ts +0 -2
  99. package/lib/WAUSync/USyncQuery.js +13 -27
  100. package/lib/WAUSync/USyncUser.d.ts +0 -2
  101. package/lib/WAUSync/USyncUser.js +0 -4
  102. package/package.json +60 -55
  103. package/LICENSE +0 -21
  104. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  105. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  106. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  107. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  108. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
1
5
  import { AxiosRequestConfig } from 'axios';
2
6
  import type { Readable } from 'stream';
3
7
  import type { URL } from 'url';
@@ -13,22 +17,19 @@ export type WAMessageContent = proto.IMessage;
13
17
  export type WAContactMessage = proto.Message.IContactMessage;
14
18
  export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
15
19
  export type WAMessageKey = proto.IMessageKey & {
16
- lid?: string;
17
20
  server_id?: string;
18
21
  };
19
22
  export type WATextMessage = proto.Message.IExtendedTextMessage;
20
23
  export type WAContextInfo = proto.IContextInfo;
21
24
  export type WALocationMessage = proto.Message.ILocationMessage;
22
25
  export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
23
- export declare const WAMessageStubType: typeof proto.WebMessageInfo.StubType;
24
- export declare const WAMessageStatus: typeof proto.WebMessageInfo.Status;
25
- export type WAMediaPayloadURL = {
26
+ export import WAMessageStubType = proto.WebMessageInfo.StubType;
27
+ export import WAMessageStatus = proto.WebMessageInfo.Status;
28
+ export type WAMediaUpload = Buffer | {
26
29
  url: URL | string;
27
- };
28
- export type WAMediaPayloadStream = {
30
+ } | {
29
31
  stream: Readable;
30
32
  };
31
- export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL;
32
33
  /** Set of message types that are supported by the library */
33
34
  export type MessageType = keyof proto.Message;
34
35
  export type DownloadableMessage = {
@@ -3,5 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WAMessageStatus = exports.WAMessageStubType = exports.WAProto = void 0;
4
4
  const WAProto_1 = require("../../WAProto");
5
5
  Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () { return WAProto_1.proto; } });
6
+ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
6
7
  exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
8
+ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
7
9
  exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
@@ -6,7 +6,7 @@ var MexOperations;
6
6
  MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
7
7
  MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
8
8
  MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
9
- })(MexOperations || (exports.MexOperations = MexOperations = {}));
9
+ })(MexOperations = exports.MexOperations || (exports.MexOperations = {}));
10
10
  var XWAPaths;
11
11
  (function (XWAPaths) {
12
12
  XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
@@ -15,4 +15,4 @@ var XWAPaths;
15
15
  XWAPaths["CREATE"] = "xwa2_newsletter_create";
16
16
  XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
17
  XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
- })(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
18
+ })(XWAPaths = exports.XWAPaths || (exports.XWAPaths = {}));
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { AxiosRequestConfig } from 'axios';
2
4
  import type { Agent } from 'https';
3
5
  import type { URL } from 'url';
@@ -19,9 +21,6 @@ export type CacheStore = {
19
21
  /** flush all data */
20
22
  flushAll(): void;
21
23
  };
22
- export type PatchedMessageWithRecipientJID = proto.IMessage & {
23
- recipientJid?: string;
24
- };
25
24
  export type SocketConfig = {
26
25
  /** the WS url to connect to WA */
27
26
  waWebSocketUrl: string | URL;
@@ -31,9 +30,7 @@ export type SocketConfig = {
31
30
  defaultQueryTimeoutMs: number | undefined;
32
31
  /** ping-pong interval for WS connection */
33
32
  keepAliveIntervalMs: number;
34
- /** should baileys use the mobile api instead of the multi device api
35
- * @deprecated This feature has been removed
36
- */
33
+ /** should baileys use the mobile api instead of the multi device api */
37
34
  mobile?: boolean;
38
35
  /** proxy agent */
39
36
  agent?: Agent;
@@ -101,7 +98,7 @@ export type SocketConfig = {
101
98
  /**
102
99
  * Optionally patch the message before sending out
103
100
  * */
104
- patchMessageBeforeSending: (msg: proto.IMessage, recipientJids?: string[]) => Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> | PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID;
101
+ patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage;
105
102
  /** verify app state MACs */
106
103
  appStateMacVerification: {
107
104
  patch: boolean;
@@ -118,4 +115,6 @@ export type SocketConfig = {
118
115
  /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
119
116
  cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
120
117
  makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
118
+ /** Socket passthrough */
119
+ socket?: any;
121
120
  };
@@ -39,4 +39,4 @@ var DisconnectReason;
39
39
  DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
40
  DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
41
  DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
- })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
42
+ })(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
@@ -6,7 +6,7 @@ import { ILogger } from './logger';
6
6
  * @param logger to log trace events
7
7
  * @param _cache cache store to use
8
8
  */
9
- export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger?: ILogger, _cache?: CacheStore): SignalKeyStore;
9
+ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger: ILogger, _cache?: CacheStore): SignalKeyStore;
10
10
  /**
11
11
  * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
12
12
  * this allows batch read & write operations & improves the performance of the lib
@@ -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
8
  const node_cache_1 = __importDefault(require("@cacheable/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,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { AxiosRequestConfig } from 'axios';
2
4
  import { proto } from '../../WAProto';
3
5
  import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
@@ -13,7 +15,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
13
15
  state: LTHashState;
14
16
  }>;
15
17
  export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
16
- hash: Buffer<any>;
18
+ hash: Buffer;
17
19
  indexValueMap: {
18
20
  [indexMacBase64: string]: {
19
21
  valueMac: Uint8Array | Buffer;
@@ -21,47 +23,47 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
21
23
  };
22
24
  }>;
23
25
  export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
24
- hash: Buffer<any>;
26
+ hash: Buffer;
25
27
  indexValueMap: {
26
28
  [indexMacBase64: string]: {
27
29
  valueMac: Uint8Array | Buffer;
28
30
  };
29
31
  };
30
32
  }>;
31
- export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
33
+ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
32
34
  critical_block: {
33
35
  patches: proto.ISyncdPatch[];
34
36
  hasMorePatches: boolean;
35
- snapshot?: proto.ISyncdSnapshot;
37
+ snapshot?: proto.ISyncdSnapshot | undefined;
36
38
  };
37
39
  critical_unblock_low: {
38
40
  patches: proto.ISyncdPatch[];
39
41
  hasMorePatches: boolean;
40
- snapshot?: proto.ISyncdSnapshot;
42
+ snapshot?: proto.ISyncdSnapshot | undefined;
41
43
  };
42
44
  regular_high: {
43
45
  patches: proto.ISyncdPatch[];
44
46
  hasMorePatches: boolean;
45
- snapshot?: proto.ISyncdSnapshot;
47
+ snapshot?: proto.ISyncdSnapshot | undefined;
46
48
  };
47
49
  regular_low: {
48
50
  patches: proto.ISyncdPatch[];
49
51
  hasMorePatches: boolean;
50
- snapshot?: proto.ISyncdSnapshot;
52
+ snapshot?: proto.ISyncdSnapshot | undefined;
51
53
  };
52
54
  regular: {
53
55
  patches: proto.ISyncdPatch[];
54
56
  hasMorePatches: boolean;
55
- snapshot?: proto.ISyncdSnapshot;
57
+ snapshot?: proto.ISyncdSnapshot | undefined;
56
58
  };
57
59
  }>;
58
- export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer<ArrayBuffer>>;
59
- export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
60
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
61
+ export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
60
62
  export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
61
63
  state: LTHashState;
62
64
  mutationMap: ChatMutationMap;
63
65
  }>;
64
- export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
66
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
65
67
  state: LTHashState;
66
68
  mutationMap: ChatMutationMap;
67
69
  }>;
@@ -305,7 +305,8 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
305
305
  indexValueMap: { ...initial.indexValueMap }
306
306
  };
307
307
  const mutationMap = {};
308
- for (const syncd of syncds) {
308
+ for (let i = 0; i < syncds.length; i++) {
309
+ const syncd = syncds[i];
309
310
  const { version, keyId, snapshotMac } = syncd;
310
311
  if (syncd.externalMutations) {
311
312
  logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
@@ -456,17 +457,6 @@ const chatModificationToAppPatch = (mod, jid) => {
456
457
  operation: OP.SET
457
458
  };
458
459
  }
459
- else if ('contact' in mod) {
460
- patch = {
461
- syncAction: {
462
- contactAction: mod.contact || {}
463
- },
464
- index: ['contact', jid],
465
- type: 'critical_unblock_low',
466
- apiVersion: 2,
467
- operation: mod.contact ? OP.SET : OP.REMOVE
468
- };
469
- }
470
460
  else if ('star' in mod) {
471
461
  const key = mod.star.messages[0];
472
462
  patch = {
@@ -507,22 +497,6 @@ const chatModificationToAppPatch = (mod, jid) => {
507
497
  operation: OP.SET,
508
498
  };
509
499
  }
510
- else if ('addLabel' in mod) {
511
- patch = {
512
- syncAction: {
513
- labelEditAction: {
514
- name: mod.addLabel.name,
515
- color: mod.addLabel.color,
516
- predefinedId: mod.addLabel.predefinedId,
517
- deleted: mod.addLabel.deleted
518
- }
519
- },
520
- index: ['label_edit', mod.addLabel.id],
521
- type: 'regular',
522
- apiVersion: 3,
523
- operation: OP.SET,
524
- };
525
- }
526
500
  else if ('addChatLabel' in mod) {
527
501
  patch = {
528
502
  syncAction: {
@@ -1,9 +1,11 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { KeyPair } from '../Types';
2
4
  /** 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>;
5
+ export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
4
6
  export declare const Curve: {
5
7
  generateKeyPair: () => KeyPair;
6
- sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer<any>;
8
+ sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
7
9
  sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
8
10
  verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
9
11
  };
@@ -16,25 +18,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
16
18
  * encrypt AES 256 GCM;
17
19
  * where the tag tag is suffixed to the ciphertext
18
20
  * */
19
- export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
21
+ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
20
22
  /**
21
23
  * decrypt AES 256 GCM;
22
24
  * where the auth tag is suffixed to the ciphertext
23
25
  * */
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>;
26
+ export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
27
+ export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
28
+ export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
27
29
  /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
28
- export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer<ArrayBuffer>;
30
+ export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
29
31
  /** 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>;
32
+ export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
33
+ export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
34
+ export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
35
+ export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
36
+ export declare function sha256(buffer: Buffer): Buffer;
37
+ export declare function md5(buffer: Buffer): Buffer;
36
38
  export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
37
39
  salt?: Buffer;
38
- info?: string | Buffer;
40
+ info?: string;
39
41
  }): Promise<Buffer>;
40
42
  export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
@@ -15,38 +15,15 @@ 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
+ };
35
25
  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;
26
+ 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
27
  const crypto_1 = require("crypto");
51
28
  const libsignal = __importStar(require("libsignal"));
52
29
  const Defaults_1 = require("../Defaults");
@@ -98,6 +75,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
98
75
  cipher.setAAD(additionalData);
99
76
  return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
100
77
  }
78
+ exports.aesEncryptGCM = aesEncryptGCM;
101
79
  /**
102
80
  * decrypt AES 256 GCM;
103
81
  * where the auth tag is suffixed to the ciphertext
@@ -112,44 +90,54 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
112
90
  decipher.setAuthTag(tag);
113
91
  return Buffer.concat([decipher.update(enc), decipher.final()]);
114
92
  }
93
+ exports.aesDecryptGCM = aesDecryptGCM;
115
94
  function aesEncryptCTR(plaintext, key, iv) {
116
95
  const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
117
96
  return Buffer.concat([cipher.update(plaintext), cipher.final()]);
118
97
  }
98
+ exports.aesEncryptCTR = aesEncryptCTR;
119
99
  function aesDecryptCTR(ciphertext, key, iv) {
120
100
  const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
121
101
  return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
122
102
  }
103
+ exports.aesDecryptCTR = aesDecryptCTR;
123
104
  /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
124
105
  function aesDecrypt(buffer, key) {
125
106
  return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
126
107
  }
108
+ exports.aesDecrypt = aesDecrypt;
127
109
  /** decrypt AES 256 CBC */
128
110
  function aesDecryptWithIV(buffer, key, IV) {
129
111
  const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
130
112
  return Buffer.concat([aes.update(buffer), aes.final()]);
131
113
  }
114
+ exports.aesDecryptWithIV = aesDecryptWithIV;
132
115
  // encrypt AES 256 CBC; where a random IV is prefixed to the buffer
133
116
  function aesEncrypt(buffer, key) {
134
117
  const IV = (0, crypto_1.randomBytes)(16);
135
118
  const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
136
119
  return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
137
120
  }
121
+ exports.aesEncrypt = aesEncrypt;
138
122
  // encrypt AES 256 CBC with a given IV
139
123
  function aesEncrypWithIV(buffer, key, IV) {
140
124
  const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
141
125
  return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
142
126
  }
127
+ exports.aesEncrypWithIV = aesEncrypWithIV;
143
128
  // sign HMAC using SHA 256
144
129
  function hmacSign(buffer, key, variant = 'sha256') {
145
130
  return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
146
131
  }
132
+ exports.hmacSign = hmacSign;
147
133
  function sha256(buffer) {
148
134
  return (0, crypto_1.createHash)('sha256').update(buffer).digest();
149
135
  }
136
+ exports.sha256 = sha256;
150
137
  function md5(buffer) {
151
138
  return (0, crypto_1.createHash)('md5').update(buffer).digest();
152
139
  }
140
+ exports.md5 = md5;
153
141
  // HKDF key expansion
154
142
  async function hkdf(buffer, expandedLength, info) {
155
143
  // Ensure we have a Uint8Array for the key material
@@ -159,9 +147,7 @@ async function hkdf(buffer, expandedLength, info) {
159
147
  // Set default values if not provided
160
148
  const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
161
149
  const infoBytes = info.info
162
- ? (typeof info.info === 'string'
163
- ? new TextEncoder().encode(info.info)
164
- : new Uint8Array(info.info))
150
+ ? new TextEncoder().encode(info.info)
165
151
  : new Uint8Array(0);
166
152
  // Import the input key material
167
153
  const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
@@ -175,6 +161,7 @@ async function hkdf(buffer, expandedLength, info) {
175
161
  );
176
162
  return Buffer.from(derivedBits);
177
163
  }
164
+ exports.hkdf = hkdf;
178
165
  async function derivePairingCodeKey(pairingCode, salt) {
179
166
  // Convert inputs to formats Web Crypto API can work with
180
167
  const encoder = new TextEncoder();
@@ -193,3 +180,4 @@ async function derivePairingCodeKey(pairingCode, salt) {
193
180
  );
194
181
  return Buffer.from(derivedBits);
195
182
  }
183
+ exports.derivePairingCodeKey = derivePairingCodeKey;
@@ -1,6 +1,6 @@
1
1
  import { proto } from '../../WAProto';
2
2
  import { ILogger } from './logger';
3
- import { SignalRepository, WAMessageKey } from '../Types';
3
+ import { SignalRepository } from '../Types';
4
4
  import { BinaryNode } from '../WABinary';
5
5
  export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
6
6
  export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
@@ -19,7 +19,6 @@ export declare const NACK_REASONS: {
19
19
  UnsupportedLIDGroup: number;
20
20
  DBOperationFailed: number;
21
21
  };
22
- type GetMessage = (key: WAMessageKey) => Promise<proto.IMessage | undefined>;
23
22
  /**
24
23
  * Decode the received node as a message.
25
24
  * @note this will only parse the message, not decrypt it
@@ -29,10 +28,9 @@ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLi
29
28
  author: string;
30
29
  sender: string;
31
30
  };
32
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger, getMessage: GetMessage) => {
31
+ export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
33
32
  fullMessage: proto.IWebMessageInfo;
34
33
  category: string;
35
34
  author: string;
36
35
  decrypt(): Promise<void>;
37
36
  };
38
- export {};