alipclutch-baileys 6.7.0 → 7.1.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 (121) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +77698 -117050
  3. package/engine-requirements.js +3 -3
  4. package/lib/Defaults/baileys-version.json +3 -0
  5. package/lib/Defaults/index.d.ts +6 -4
  6. package/lib/Defaults/index.js +118 -78
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  9. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  10. package/lib/Socket/Client/index.d.ts +3 -2
  11. package/lib/Socket/Client/index.js +3 -2
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  13. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  14. package/lib/Socket/Client/types.d.ts +1 -0
  15. package/lib/Socket/Client/types.js +1 -0
  16. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  17. package/lib/Socket/Client/web-socket-client.js +62 -0
  18. package/lib/Socket/Client/websocket.d.ts +1 -0
  19. package/lib/Socket/Client/websocket.js +1 -0
  20. package/lib/Socket/business.d.ts +58 -59
  21. package/lib/Socket/chats.d.ts +230 -45
  22. package/lib/Socket/chats.js +238 -139
  23. package/lib/Socket/dugong.d.ts +254 -0
  24. package/lib/Socket/dugong.js +483 -0
  25. package/lib/Socket/groups.d.ts +32 -41
  26. package/lib/Socket/groups.js +23 -38
  27. package/lib/Socket/index.d.ts +64 -63
  28. package/lib/Socket/index.js +3 -2
  29. package/lib/Socket/messages-recv.js +65 -9
  30. package/lib/Socket/messages-send.d.ts +47 -49
  31. package/lib/Socket/messages-send.js +420 -382
  32. package/lib/Socket/newsletter.d.ts +37 -39
  33. package/lib/Socket/newsletter.js +124 -71
  34. package/lib/Socket/registration.d.ts +267 -0
  35. package/lib/Socket/registration.js +166 -0
  36. package/lib/Socket/socket.d.ts +10 -10
  37. package/lib/Socket/socket.js +38 -62
  38. package/lib/Socket/usync.d.ts +4 -3
  39. package/lib/Socket/usync.js +1 -0
  40. package/lib/Store/index.d.ts +2 -1
  41. package/lib/Store/index.js +3 -1
  42. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  43. package/lib/Store/make-cache-manager-store.js +83 -0
  44. package/lib/Store/make-in-memory-store.d.ts +24 -24
  45. package/lib/Store/make-in-memory-store.js +14 -26
  46. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  47. package/lib/Store/make-ordered-dictionary.js +2 -2
  48. package/lib/Types/Auth.d.ts +7 -0
  49. package/lib/Types/Call.d.ts +1 -1
  50. package/lib/Types/Chat.d.ts +7 -14
  51. package/lib/Types/Contact.d.ts +1 -5
  52. package/lib/Types/Events.d.ts +2 -44
  53. package/lib/Types/GroupMetadata.d.ts +2 -11
  54. package/lib/Types/Label.js +1 -1
  55. package/lib/Types/LabelAssociation.js +1 -1
  56. package/lib/Types/Message.d.ts +21 -148
  57. package/lib/Types/Message.js +2 -0
  58. package/lib/Types/Newsletter.d.ts +97 -73
  59. package/lib/Types/Newsletter.js +38 -18
  60. package/lib/Types/Socket.d.ts +9 -17
  61. package/lib/Types/index.d.ts +1 -8
  62. package/lib/Types/index.js +2 -2
  63. package/lib/Utils/auth-utils.d.ts +3 -3
  64. package/lib/Utils/auth-utils.js +13 -6
  65. package/lib/Utils/business.js +2 -2
  66. package/lib/Utils/chat-utils.d.ts +16 -15
  67. package/lib/Utils/chat-utils.js +35 -36
  68. package/lib/Utils/crypto.d.ts +16 -15
  69. package/lib/Utils/crypto.js +29 -71
  70. package/lib/Utils/decode-wa-message.d.ts +6 -22
  71. package/lib/Utils/decode-wa-message.js +56 -65
  72. package/lib/Utils/event-buffer.d.ts +2 -2
  73. package/lib/Utils/event-buffer.js +7 -11
  74. package/lib/Utils/generics.d.ts +20 -17
  75. package/lib/Utils/generics.js +76 -96
  76. package/lib/Utils/history.d.ts +0 -4
  77. package/lib/Utils/history.js +6 -4
  78. package/lib/Utils/link-preview.d.ts +2 -2
  79. package/lib/Utils/link-preview.js +1 -34
  80. package/lib/Utils/logger.d.ts +3 -10
  81. package/lib/Utils/lt-hash.d.ts +2 -2
  82. package/lib/Utils/lt-hash.js +6 -6
  83. package/lib/Utils/make-mutex.d.ts +2 -2
  84. package/lib/Utils/messages-media.d.ts +24 -28
  85. package/lib/Utils/messages-media.js +236 -296
  86. package/lib/Utils/messages.d.ts +10 -13
  87. package/lib/Utils/messages.js +92 -325
  88. package/lib/Utils/noise-handler.d.ts +12 -10
  89. package/lib/Utils/noise-handler.js +23 -18
  90. package/lib/Utils/process-message.d.ts +4 -5
  91. package/lib/Utils/process-message.js +25 -108
  92. package/lib/Utils/signal.d.ts +1 -2
  93. package/lib/Utils/signal.js +26 -26
  94. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  95. package/lib/Utils/use-multi-file-auth-state.js +6 -51
  96. package/lib/Utils/validate-connection.d.ts +4 -3
  97. package/lib/Utils/validate-connection.js +52 -20
  98. package/lib/WABinary/constants.d.ts +27 -24
  99. package/lib/WABinary/constants.js +13 -1276
  100. package/lib/WABinary/decode.d.ts +4 -3
  101. package/lib/WABinary/decode.js +13 -26
  102. package/lib/WABinary/encode.d.ts +2 -1
  103. package/lib/WABinary/encode.js +152 -137
  104. package/lib/WABinary/generic-utils.d.ts +4 -1
  105. package/lib/WABinary/generic-utils.js +125 -37
  106. package/lib/WABinary/jid-utils.d.ts +5 -11
  107. package/lib/WABinary/jid-utils.js +5 -28
  108. package/lib/WAM/BinaryInfo.d.ts +11 -2
  109. package/lib/WAM/encode.d.ts +2 -1
  110. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  111. package/lib/index.d.ts +1 -0
  112. package/lib/index.js +36 -43
  113. package/package.json +1 -1
  114. package/WAProto/GenerateStatics.sh +0 -4
  115. package/WAProto/WAProto.proto +0 -4775
  116. package/WAProto/index.d.ts +0 -55057
  117. package/WAProto/index.ts.ts +0 -53473
  118. package/WAProto/p.html +0 -1
  119. package/lib/Defaults/wileys-version.json +0 -3
  120. package/lib/WABinary/jid-utils.js.bak +0 -83
  121. /package/{README.MD → README.md} +0 -0
@@ -1,12 +1,13 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { AxiosRequestConfig } from 'axios';
2
4
  import type { Agent } from 'https';
5
+ import type { Logger } from 'pino';
3
6
  import type { URL } from 'url';
4
7
  import { proto } from '../../WAProto';
5
8
  import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
6
- import { GroupMetadata } from './GroupMetadata';
7
9
  import { MediaConnInfo } from './Message';
8
10
  import { SignalRepository } from './Signal';
9
- import { ILogger } from '../Utils/logger';
10
11
  export type WAVersion = [number, number, number];
11
12
  export type WABrowserDescription = [string, string, string];
12
13
  export type CacheStore = {
@@ -19,9 +20,6 @@ export type CacheStore = {
19
20
  /** flush all data */
20
21
  flushAll(): void;
21
22
  };
22
- export type PatchedMessageWithRecipientJID = proto.IMessage & {
23
- recipientJid?: string;
24
- };
25
23
  export type SocketConfig = {
26
24
  /** the WS url to connect to WA */
27
25
  waWebSocketUrl: string | URL;
@@ -31,14 +29,12 @@ export type SocketConfig = {
31
29
  defaultQueryTimeoutMs: number | undefined;
32
30
  /** ping-pong interval for WS connection */
33
31
  keepAliveIntervalMs: number;
34
- /** should baileys use the mobile api instead of the multi device api
35
- * @deprecated This feature has been removed
36
- */
32
+ /** should baileys use the mobile api instead of the multi device api */
37
33
  mobile?: boolean;
38
34
  /** proxy agent */
39
35
  agent?: Agent;
40
- /** logger */
41
- logger: ILogger;
36
+ /** pino logger */
37
+ logger: Logger;
42
38
  /** version to connect with */
43
39
  version: WAVersion;
44
40
  /** override browser config */
@@ -65,8 +61,6 @@ export type SocketConfig = {
65
61
  transactionOpts: TransactionCapabilityOptions;
66
62
  /** marks the client as online whenever the socket successfully connects */
67
63
  markOnlineOnConnect: boolean;
68
- /** alphanumeric country code (USA -> US) for the number used */
69
- countryCode: string;
70
64
  /** provide a cache to store media, so does not have to be re-uploaded */
71
65
  mediaCache?: CacheStore;
72
66
  /**
@@ -77,8 +71,6 @@ export type SocketConfig = {
77
71
  userDevicesCache?: CacheStore;
78
72
  /** cache to store call offers */
79
73
  callOfferCache?: CacheStore;
80
- /** cache to track placeholder resends */
81
- placeholderResendCache?: CacheStore;
82
74
  /** width for link preview images */
83
75
  linkPreviewImageThumbnailWidth: number;
84
76
  /** Should Baileys ask the phone for full history, will be received async */
@@ -99,7 +91,7 @@ export type SocketConfig = {
99
91
  /**
100
92
  * Optionally patch the message before sending out
101
93
  * */
102
- patchMessageBeforeSending: (msg: proto.IMessage, recipientJids?: string[]) => Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> | PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID;
94
+ patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage;
103
95
  /** verify app state MACs */
104
96
  appStateMacVerification: {
105
97
  patch: boolean;
@@ -113,7 +105,7 @@ export type SocketConfig = {
113
105
  * (solves the "this message can take a while" issue) can be retried
114
106
  * */
115
107
  getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
116
- /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
117
- cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
118
108
  makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
109
+ /** Socket passthrough */
110
+ socket?: any;
119
111
  };
@@ -1,10 +1,10 @@
1
1
  export * from './Auth';
2
2
  export * from './GroupMetadata';
3
- export * from './Newsletter';
4
3
  export * from './Chat';
5
4
  export * from './Contact';
6
5
  export * from './State';
7
6
  export * from './Message';
7
+ export * from './Newsletter';
8
8
  export * from './Socket';
9
9
  export * from './Events';
10
10
  export * from './Product';
@@ -15,13 +15,6 @@ import { SocketConfig } from './Socket';
15
15
  export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
16
  auth: AuthenticationState;
17
17
  };
18
- export type BrowsersMap = {
19
- ubuntu(browser: string): [string, string, string];
20
- macOS(browser: string): [string, string, string];
21
- baileys(browser: string): [string, string, string];
22
- windows(browser: string): [string, string, string];
23
- appropriate(browser: string): [string, string, string];
24
- };
25
18
  export declare enum DisconnectReason {
26
19
  connectionClosed = 428,
27
20
  connectionLost = 408,
@@ -17,11 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.DisconnectReason = void 0;
18
18
  __exportStar(require("./Auth"), exports);
19
19
  __exportStar(require("./GroupMetadata"), exports);
20
- __exportStar(require("./Newsletter"), exports);
21
20
  __exportStar(require("./Chat"), exports);
22
21
  __exportStar(require("./Contact"), exports);
23
22
  __exportStar(require("./State"), exports);
24
23
  __exportStar(require("./Message"), exports);
24
+ __exportStar(require("./Newsletter"), exports);
25
25
  __exportStar(require("./Socket"), exports);
26
26
  __exportStar(require("./Events"), exports);
27
27
  __exportStar(require("./Product"), exports);
@@ -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 = {}));
@@ -1,12 +1,12 @@
1
+ import type { Logger } from 'pino';
1
2
  import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types';
2
- import { ILogger } from './logger';
3
3
  /**
4
4
  * Adds caching capability to a SignalKeyStore
5
5
  * @param store the store to add caching to
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: Logger, _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
@@ -14,5 +14,5 @@ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logge
14
14
  * @param logger logger to log events
15
15
  * @returns SignalKeyStore with transaction capability
16
16
  */
17
- export declare const addTransactionCapability: (state: SignalKeyStore, logger: ILogger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
17
+ export declare const addTransactionCapability: (state: SignalKeyStore, logger: Logger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
18
18
  export declare const initAuthCreds: () => AuthenticationCreds;
@@ -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;