@hbmodsofc/baileys 1.7.8 → 2.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 (155) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +157084 -24729
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.d.ts +8 -12
  5. package/lib/Defaults/index.js +124 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  8. package/lib/Signal/Group/group_cipher.js +39 -28
  9. package/lib/Signal/Group/queue-job.d.ts +1 -0
  10. package/lib/Signal/Group/queue-job.js +57 -0
  11. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  12. package/lib/Signal/Group/sender-chain-key.js +2 -9
  13. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  14. package/lib/Signal/Group/sender-key-message.js +3 -3
  15. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  16. package/lib/Signal/Group/sender-key-state.js +16 -47
  17. package/lib/Signal/libsignal.d.ts +3 -7
  18. package/lib/Signal/libsignal.js +39 -224
  19. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
  20. package/lib/Socket/Client/index.d.ts +3 -2
  21. package/lib/Socket/Client/index.js +3 -2
  22. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  24. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  25. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
  26. package/lib/Socket/business.d.ts +78 -94
  27. package/lib/Socket/business.js +11 -130
  28. package/lib/Socket/chats.d.ts +233 -63
  29. package/lib/Socket/chats.js +184 -234
  30. package/lib/Socket/groups.d.ts +41 -62
  31. package/lib/Socket/groups.js +64 -76
  32. package/lib/Socket/hbmods.d.ts +253 -0
  33. package/lib/Socket/hbmods.js +1 -0
  34. package/lib/Socket/index.d.ts +83 -129
  35. package/lib/Socket/index.js +6 -13
  36. package/lib/Socket/messages-recv.d.ts +48 -59
  37. package/lib/Socket/messages-recv.js +371 -516
  38. package/lib/Socket/messages-send.d.ts +67 -86
  39. package/lib/Socket/messages-send.js +1 -1091
  40. package/lib/Socket/newsletter.d.ts +64 -76
  41. package/lib/Socket/newsletter.js +1 -184
  42. package/lib/Socket/registration.d.ts +267 -0
  43. package/lib/Socket/registration.js +166 -0
  44. package/lib/Socket/socket.d.ts +13 -19
  45. package/lib/Socket/socket.js +1 -805
  46. package/lib/Socket/usync.d.ts +36 -0
  47. package/lib/Socket/usync.js +70 -0
  48. package/lib/Types/Auth.d.ts +10 -4
  49. package/lib/Types/Call.d.ts +1 -1
  50. package/lib/Types/Chat.d.ts +9 -29
  51. package/lib/Types/Chat.js +1 -7
  52. package/lib/Types/Contact.d.ts +1 -5
  53. package/lib/Types/Events.d.ts +14 -55
  54. package/lib/Types/GroupMetadata.d.ts +5 -15
  55. package/lib/Types/Label.d.ts +0 -11
  56. package/lib/Types/Label.js +1 -1
  57. package/lib/Types/LabelAssociation.js +1 -1
  58. package/lib/Types/Message.d.ts +49 -75
  59. package/lib/Types/Message.js +7 -10
  60. package/lib/Types/Newsletter.d.ts +98 -129
  61. package/lib/Types/Newsletter.js +38 -33
  62. package/lib/Types/Product.d.ts +1 -1
  63. package/lib/Types/Signal.d.ts +1 -29
  64. package/lib/Types/Socket.d.ts +22 -48
  65. package/lib/Types/State.d.ts +2 -13
  66. package/lib/Types/State.js +0 -12
  67. package/lib/Types/USync.d.ts +1 -1
  68. package/lib/Types/index.d.ts +3 -10
  69. package/lib/Types/index.js +2 -2
  70. package/lib/Utils/auth-utils.d.ts +3 -3
  71. package/lib/Utils/auth-utils.js +102 -378
  72. package/lib/Utils/baileys-event-stream.js +1 -1
  73. package/lib/Utils/business.d.ts +2 -2
  74. package/lib/Utils/business.js +13 -19
  75. package/lib/Utils/chat-utils.d.ts +22 -21
  76. package/lib/Utils/chat-utils.js +154 -201
  77. package/lib/Utils/crypto.d.ts +19 -18
  78. package/lib/Utils/crypto.js +37 -78
  79. package/lib/Utils/decode-wa-message.d.ts +7 -34
  80. package/lib/Utils/decode-wa-message.js +66 -138
  81. package/lib/Utils/event-buffer.d.ts +8 -6
  82. package/lib/Utils/event-buffer.js +43 -81
  83. package/lib/Utils/generics.d.ts +27 -27
  84. package/lib/Utils/generics.js +133 -128
  85. package/lib/Utils/history.d.ts +5 -9
  86. package/lib/Utils/history.js +23 -17
  87. package/lib/Utils/index.d.ts +0 -2
  88. package/lib/Utils/index.js +0 -2
  89. package/lib/Utils/link-preview.d.ts +4 -4
  90. package/lib/Utils/link-preview.js +12 -40
  91. package/lib/Utils/logger.d.ts +3 -11
  92. package/lib/Utils/lt-hash.d.ts +8 -8
  93. package/lib/Utils/lt-hash.js +24 -23
  94. package/lib/Utils/make-mutex.d.ts +2 -2
  95. package/lib/Utils/make-mutex.js +2 -3
  96. package/lib/Utils/messages-media.d.ts +41 -37
  97. package/lib/Utils/messages-media.js +368 -252
  98. package/lib/Utils/messages.d.ts +15 -13
  99. package/lib/Utils/messages.js +261 -274
  100. package/lib/Utils/noise-handler.d.ts +15 -13
  101. package/lib/Utils/noise-handler.js +26 -20
  102. package/lib/Utils/process-message.d.ts +8 -9
  103. package/lib/Utils/process-message.js +93 -157
  104. package/lib/Utils/signal.d.ts +5 -6
  105. package/lib/Utils/signal.js +29 -37
  106. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  107. package/lib/Utils/use-multi-file-auth-state.js +7 -12
  108. package/lib/Utils/validate-connection.d.ts +6 -5
  109. package/lib/Utils/validate-connection.js +97 -39
  110. package/lib/WABinary/constants.d.ts +27 -24
  111. package/lib/WABinary/constants.js +13 -1276
  112. package/lib/WABinary/decode.d.ts +4 -3
  113. package/lib/WABinary/decode.js +14 -28
  114. package/lib/WABinary/encode.d.ts +2 -1
  115. package/lib/WABinary/encode.js +147 -134
  116. package/lib/WABinary/generic-utils.d.ts +7 -4
  117. package/lib/WABinary/generic-utils.js +125 -40
  118. package/lib/WABinary/jid-utils.d.ts +8 -13
  119. package/lib/WABinary/jid-utils.js +16 -27
  120. package/lib/WAM/BinaryInfo.d.ts +11 -2
  121. package/lib/WAM/constants.d.ts +2 -3
  122. package/lib/WAM/constants.js +2359 -2252
  123. package/lib/WAM/encode.d.ts +2 -1
  124. package/lib/WAM/encode.js +11 -8
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  128. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  129. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  131. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
  133. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
  136. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
  137. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  138. package/lib/WAUSync/USyncQuery.js +15 -19
  139. package/lib/WAUSync/USyncUser.d.ts +5 -5
  140. package/lib/WAUSync/index.d.ts +1 -1
  141. package/lib/WAUSync/index.js +1 -1
  142. package/package.json +102 -104
  143. package/lib/Signal/lid-mapping.d.ts +0 -26
  144. package/lib/Signal/lid-mapping.js +0 -146
  145. package/lib/Socket/communities.d.ts +0 -232
  146. package/lib/Socket/communities.js +0 -402
  147. package/lib/Socket/mex.d.ts +0 -2
  148. package/lib/Socket/mex.js +0 -45
  149. package/lib/Types/Bussines.d.ts +0 -24
  150. package/lib/Types/Bussines.js +0 -2
  151. package/lib/Utils/lidToJid-test.d.ts +0 -11
  152. package/lib/Utils/lidToJid-test.js +0 -27
  153. package/lib/Utils/message-retry-manager.d.ts +0 -81
  154. package/lib/Utils/message-retry-manager.js +0 -152
  155. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": [2, 3000, 1026924051]
3
+ }
@@ -1,17 +1,17 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { SocketConfig } from '../Types';
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { proto } from '../../WAProto';
4
+ import type { MediaType, SocketConfig } from '../Types';
3
5
  export declare const UNAUTHORIZED_CODES: number[];
4
6
  export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
5
- export declare const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
6
- export declare const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
7
7
  export declare const DEF_CALLBACK_PREFIX = "CB:";
8
8
  export declare const DEF_TAG_PREFIX = "TAG:";
9
9
  export declare const PHONE_CONNECTION_CB = "CB:Pong";
10
10
  export declare const WA_DEFAULT_EPHEMERAL: number;
11
11
  export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
12
- export declare const DICT_VERSION = 3;
13
- export declare const KEY_BUNDLE_TYPE: Buffer<ArrayBuffer>;
14
- export declare const NOISE_WA_HEADER: Buffer<ArrayBuffer>;
12
+ export declare const DICT_VERSION = 2;
13
+ export declare const KEY_BUNDLE_TYPE: Buffer;
14
+ export declare const NOISE_WA_HEADER: Buffer;
15
15
  /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
16
16
  export declare const URL_REGEX: RegExp;
17
17
  export declare const WA_CERT_DETAILS: {
@@ -41,14 +41,10 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
41
41
  'product-catalog-image': string;
42
42
  'payment-bg-image': string;
43
43
  ptv: string;
44
- 'biz-cover-photo': string;
45
44
  };
46
- export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
47
- export declare const MEDIA_KEYS: MediaType[];
45
+ export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image" | "ptv")[];
48
46
  export declare const MIN_PREKEY_COUNT = 5;
49
47
  export declare const INITIAL_PREKEY_COUNT = 30;
50
- export declare const UPLOAD_TIMEOUT = 30000;
51
- export declare const MIN_UPLOAD_INTERVAL = 5000;
52
48
  export declare const DEFAULT_CACHE_TTLS: {
53
49
  SIGNAL_STORE: number;
54
50
  MSG_RETRY: number;
@@ -1,113 +1,147 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __importDefault = this && this.__importDefault || function (a) {
2
+ return a && a.__esModule ? a : { "default": a }
4
3
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DEFAULT_CACHE_TTLS = exports.MIN_UPLOAD_INTERVAL = exports.UPLOAD_TIMEOUT = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.CALL_AUDIO_PREFIX = exports.CALL_VIDEO_PREFIX = exports.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = void 0;
7
- const index_js_1 = require("../../WAProto/index.js");
8
- const libsignal_1 = require("../Signal/libsignal");
9
- const Utils_1 = require("../Utils");
10
- const logger_1 = __importDefault(require("../Utils/logger"));
11
- const version = [2, 3000, 1023223821];
4
+
5
+ Object.defineProperty(exports, "__esModule", { value: !0 });
6
+
7
+ exports.DEFAULT_CACHE_TTLS =
8
+ exports.INITIAL_PREKEY_COUNT =
9
+ exports.MIN_PREKEY_COUNT =
10
+ exports.MEDIA_KEYS =
11
+ exports.MEDIA_HKDF_KEY_MAPPING =
12
+ exports.MEDIA_PATH_MAP =
13
+ exports.DEFAULT_CONNECTION_CONFIG =
14
+ exports.PROCESSABLE_HISTORY_TYPES =
15
+ exports.WA_CERT_DETAILS =
16
+ exports.URL_REGEX =
17
+ exports.NOISE_WA_HEADER =
18
+ exports.KEY_BUNDLE_TYPE =
19
+ exports.DICT_VERSION =
20
+ exports.NOISE_MODE =
21
+ exports.WA_DEFAULT_EPHEMERAL =
22
+ exports.PHONE_CONNECTION_CB =
23
+ exports.DEF_TAG_PREFIX =
24
+ exports.DEF_CALLBACK_PREFIX =
25
+ exports.DEFAULT_ORIGIN =
26
+ exports.UNAUTHORIZED_CODES =
27
+ void 0;
28
+
29
+ const crypto_1 = require("crypto");
30
+ const WAProto_1 = require("../../WAProto"),
31
+ libsignal_1 = require("../Signal/libsignal"),
32
+ Utils_1 = require("../Utils"),
33
+ logger_1 = __importDefault(require("../Utils/logger")),
34
+ baileys_version_json_1 = require("./baileys-version.json"),
35
+ phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
36
+
12
37
  exports.UNAUTHORIZED_CODES = [401, 403, 419];
13
- exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
14
- exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
15
- exports.CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
16
- exports.DEF_CALLBACK_PREFIX = 'CB:';
17
- exports.DEF_TAG_PREFIX = 'TAG:';
18
- exports.PHONE_CONNECTION_CB = 'CB:Pong';
19
- exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
20
- exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
21
- exports.DICT_VERSION = 3;
38
+ exports.version = [2, 3000, 1027934701];
39
+ exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
40
+ exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
41
+ exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
42
+ exports.MOBILE_PORT = 443;
43
+ exports.DEF_CALLBACK_PREFIX = "CB:";
44
+ exports.DEF_TAG_PREFIX = "TAG:";
45
+ exports.PHONE_CONNECTION_CB = "CB:Pong";
46
+ exports.WA_DEFAULT_EPHEMERAL = 604800;
47
+ const WA_VERSION = '2.25.23.24';
48
+ const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
49
+ exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
50
+ exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
51
+ exports.MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`;
52
+ exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
53
+ 5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
54
+ 34, 251, 111, 18, 37, 18, 48, 45,
55
+ ]);
56
+ exports.NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
57
+ exports.DICT_VERSION = 2;
22
58
  exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
23
- exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
24
- /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
59
+ exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
60
+ exports.PROTOCOL_VERSION = [5, 2];
61
+ exports.MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(exports.PROTOCOL_VERSION)]);
62
+
25
63
  exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
26
- exports.WA_CERT_DETAILS = {
27
- SERIAL: 0
28
- };
64
+ exports.WA_CERT_DETAILS = { SERIAL: 0 };
65
+
29
66
  exports.PROCESSABLE_HISTORY_TYPES = [
30
- index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
31
- index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
32
- index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
33
- index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
34
- index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
67
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
68
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
69
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
70
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
71
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
35
72
  ];
73
+
36
74
  exports.DEFAULT_CONNECTION_CONFIG = {
37
- version: version,
38
- browser: Utils_1.Browsers.ubuntu('Chrome'),
39
- waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
40
- connectTimeoutMs: 20000,
41
- keepAliveIntervalMs: 30000,
42
- logger: logger_1.default.child({ class: 'baileys' }),
43
- emitOwnEvents: true,
44
- defaultQueryTimeoutMs: 60000,
75
+ version: baileys_version_json_1.version,
76
+ browser: Utils_1.Browsers("Chrome"),
77
+ waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
78
+ connectTimeoutMs: 2E4,
79
+ keepAliveIntervalMs: 3E4,
80
+ logger: logger_1.default.child({ class: "baileys" }),
81
+ printQRInTerminal: !1,
82
+ emitOwnEvents: !0,
83
+ defaultQueryTimeoutMs: 6E4,
45
84
  customUploadHosts: [],
46
85
  retryRequestDelayMs: 250,
47
86
  maxMsgRetryCount: 5,
48
- fireInitQueries: true,
49
- auth: undefined,
50
- markOnlineOnConnect: true,
51
- syncFullHistory: false,
52
- patchMessageBeforeSending: msg => msg,
53
- shouldSyncHistoryMessage: () => true,
54
- shouldIgnoreJid: () => false,
87
+ fireInitQueries: !0,
88
+ auth: void 0,
89
+ markOnlineOnConnect: !0,
90
+ syncFullHistory: !1,
91
+ patchMessageBeforeSending: a => a,
92
+ shouldSyncHistoryMessage: () => !0,
93
+ shouldIgnoreJid: () => !1,
55
94
  linkPreviewImageThumbnailWidth: 192,
56
- transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
57
- generateHighQualityLinkPreview: false,
58
- enableAutoSessionRecreation: true,
59
- enableRecentMessageCache: true,
95
+ transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3E3 },
96
+ generateHighQualityLinkPreview: !1,
60
97
  options: {},
61
- appStateMacVerification: {
62
- patch: false,
63
- snapshot: false
64
- },
65
- countryCode: 'US',
66
- getMessage: async () => undefined,
67
- cachedGroupMetadata: async () => undefined,
98
+ appStateMacVerification: { patch: !1, snapshot: !1 },
99
+ countryCode: "US",
100
+ getMessage: async () => { },
101
+ cachedGroupMetadata: async () => { },
68
102
  makeSignalRepository: libsignal_1.makeLibSignalRepository
69
103
  };
104
+
70
105
  exports.MEDIA_PATH_MAP = {
71
- image: '/mms/image',
72
- video: '/mms/video',
73
- document: '/mms/document',
74
- audio: '/mms/audio',
75
- sticker: '/mms/image',
76
- 'thumbnail-link': '/mms/image',
77
- 'product-catalog-image': '/product/image',
78
- 'md-app-state': '',
79
- 'md-msg-hist': '/mms/md-app-state',
80
- 'biz-cover-photo': '/pps/biz-cover-photo'
106
+ image: "/mms/image",
107
+ video: "/mms/video",
108
+ document: "/mms/document",
109
+ audio: "/mms/audio",
110
+ sticker: "/mms/image",
111
+ "thumbnail-link": "/mms/image",
112
+ "product-catalog-image": "/product/image",
113
+ "md-app-state": "",
114
+ "md-msg-hist": "/mms/md-app-state"
81
115
  };
116
+
82
117
  exports.MEDIA_HKDF_KEY_MAPPING = {
83
- audio: 'Audio',
84
- document: 'Document',
85
- gif: 'Video',
86
- image: 'Image',
87
- ppic: '',
88
- product: 'Image',
89
- ptt: 'Audio',
90
- sticker: 'Image',
91
- video: 'Video',
92
- 'thumbnail-document': 'Document Thumbnail',
93
- 'thumbnail-image': 'Image Thumbnail',
94
- 'thumbnail-video': 'Video Thumbnail',
95
- 'thumbnail-link': 'Link Thumbnail',
96
- 'md-msg-hist': 'History',
97
- 'md-app-state': 'App State',
98
- 'product-catalog-image': '',
99
- 'payment-bg-image': 'Payment Background',
100
- ptv: 'Video',
101
- 'biz-cover-photo': 'Image'
118
+ audio: "Audio",
119
+ document: "Document",
120
+ gif: "Video",
121
+ image: "Image",
122
+ ppic: "",
123
+ product: "Image",
124
+ ptt: "Audio",
125
+ sticker: "Image",
126
+ video: "Video",
127
+ "thumbnail-document": "Document Thumbnail",
128
+ "thumbnail-image": "Image Thumbnail",
129
+ "thumbnail-video": "Video Thumbnail",
130
+ "thumbnail-link": "Link Thumbnail",
131
+ "md-msg-hist": "History",
132
+ "md-app-state": "App State",
133
+ "product-catalog-image": "",
134
+ "payment-bg-image": "Payment Background",
135
+ ptv: "Video"
102
136
  };
137
+
103
138
  exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
104
139
  exports.MIN_PREKEY_COUNT = 5;
105
140
  exports.INITIAL_PREKEY_COUNT = 30;
106
- exports.UPLOAD_TIMEOUT = 30000; // 30 seconds
107
- exports.MIN_UPLOAD_INTERVAL = 5000; // 5 seconds minimum between uploads
141
+
108
142
  exports.DEFAULT_CACHE_TTLS = {
109
- SIGNAL_STORE: 5 * 60, // 5 minutes
110
- MSG_RETRY: 60 * 60, // 1 hour
111
- CALL_OFFER: 5 * 60, // 5 minutes
112
- USER_DEVICES: 5 * 60 // 5 minutes
143
+ SIGNAL_STORE: 300,
144
+ MSG_RETRY: 3600,
145
+ CALL_OFFER: 300,
146
+ USER_DEVICES: 300
113
147
  };
@@ -0,0 +1,223 @@
1
+ {
2
+ "93": 412,
3
+ "355": 276,
4
+ "213": 603,
5
+ "1-684": 544,
6
+ "376": 213,
7
+ "244": 631,
8
+ "1-264": 365,
9
+ "1-268": 344,
10
+ "54": 722,
11
+ "374": 283,
12
+ "297": 363,
13
+ "61": 505,
14
+ "43": 232,
15
+ "994": 400,
16
+ "1-242": 364,
17
+ "973": 426,
18
+ "880": 470,
19
+ "1-246": 342,
20
+ "375": 257,
21
+ "32": 206,
22
+ "501": 702,
23
+ "229": 616,
24
+ "1-441": 350,
25
+ "975": 402,
26
+ "591": 736,
27
+ "387": 218,
28
+ "267": 652,
29
+ "55": 724,
30
+ "1-284": 348,
31
+ "673": 528,
32
+ "359": 284,
33
+ "226": 613,
34
+ "257": 642,
35
+ "855": 456,
36
+ "237": 624,
37
+ "238": 625,
38
+ "1-345": 346,
39
+ "236": 623,
40
+ "235": 622,
41
+ "56": 730,
42
+ "86": 454,
43
+ "57": 732,
44
+ "269": 654,
45
+ "682": 548,
46
+ "506": 712,
47
+ "385": 219,
48
+ "53": 368,
49
+ "357": 280,
50
+ "420": 230,
51
+ "243": 630,
52
+ "45": 238,
53
+ "253": 638,
54
+ "1-767": 366,
55
+ "1-809": 370,
56
+ "1-849": 370,
57
+ "1-829": 370,
58
+ "593": 740,
59
+ "20": 602,
60
+ "503": 706,
61
+ "240": 627,
62
+ "291": 657,
63
+ "372": 248,
64
+ "251": 636,
65
+ "500": 750,
66
+ "298": 288,
67
+ "679": 542,
68
+ "358": 244,
69
+ "33": 208,
70
+ "689": 547,
71
+ "241": 628,
72
+ "220": 607,
73
+ "995": 282,
74
+ "49": 262,
75
+ "233": 620,
76
+ "350": 266,
77
+ "30": 202,
78
+ "299": 290,
79
+ "1-473": 352,
80
+ "1-671": 535,
81
+ "502": 704,
82
+ "224": 537,
83
+ "592": 738,
84
+ "509": 372,
85
+ "504": 708,
86
+ "852": 454,
87
+ "36": 216,
88
+ "354": 274,
89
+ "91": 404,
90
+ "62": 510,
91
+ "98": 432,
92
+ "964": 418,
93
+ "353": 234,
94
+ "972": 425,
95
+ "39": 222,
96
+ "225": 612,
97
+ "1-876": 338,
98
+ "81": 440,
99
+ "962": 416,
100
+ "254": 639,
101
+ "686": 545,
102
+ "383": 221,
103
+ "965": 419,
104
+ "371": 247,
105
+ "961": 415,
106
+ "266": 651,
107
+ "231": 618,
108
+ "218": 606,
109
+ "423": 295,
110
+ "370": 246,
111
+ "352": 270,
112
+ "389": 294,
113
+ "261": 646,
114
+ "265": 650,
115
+ "60": 502,
116
+ "960": 472,
117
+ "223": 610,
118
+ "356": 278,
119
+ "692": 551,
120
+ "222": 609,
121
+ "230": 617,
122
+ "52": 334,
123
+ "691": 550,
124
+ "373": 259,
125
+ "377": 212,
126
+ "976": 428,
127
+ "382": 297,
128
+ "1-664": 354,
129
+ "212": 604,
130
+ "258": 643,
131
+ "95": 414,
132
+ "264": 649,
133
+ "674": 536,
134
+ "977": 429,
135
+ "31": 204,
136
+ "687": 546,
137
+ "64": 530,
138
+ "505": 710,
139
+ "227": 614,
140
+ "234": 621,
141
+ "683": 555,
142
+ "1-670": 534,
143
+ "47": 242,
144
+ "968": 226,
145
+ "92": 410,
146
+ "680": 552,
147
+ "970": 423,
148
+ "507": 714,
149
+ "675": 537,
150
+ "595": 744,
151
+ "51": 716,
152
+ "63": 515,
153
+ "48": 260,
154
+ "351": 268,
155
+ "1-787, 1-939": 330,
156
+ "974": 427,
157
+ "242": 630,
158
+ "40": 226,
159
+ "7": 250,
160
+ "250": 635,
161
+ "290": 658,
162
+ "1-869": 356,
163
+ "1-758": 358,
164
+ "508": 308,
165
+ "1-784": 360,
166
+ "685": 544,
167
+ "378": 292,
168
+ "239": 626,
169
+ "966": 420,
170
+ "221": 608,
171
+ "381": 220,
172
+ "248": 633,
173
+ "232": 619,
174
+ "65": 525,
175
+ "386": 293,
176
+ "677": 540,
177
+ "27": 655,
178
+ "211": 659,
179
+ "34": 214,
180
+ "94": 413,
181
+ "249": 634,
182
+ "597": 746,
183
+ "268": 653,
184
+ "46": 240,
185
+ "41": 228,
186
+ "963": 417,
187
+ "886": 466,
188
+ "992": 436,
189
+ "255": 640,
190
+ "66": 520,
191
+ "228": 615,
192
+ "690": 554,
193
+ "676": 539,
194
+ "1-868": 374,
195
+ "216": 605,
196
+ "90": 286,
197
+ "993": 438,
198
+ "1-649": 376,
199
+ "688": 553,
200
+ "1-340": 332,
201
+ "256": 641,
202
+ "380": 255,
203
+ "971": 424,
204
+ "44": 234,
205
+ "1": 310,
206
+ "598": 748,
207
+ "998": 434,
208
+ "678": 541,
209
+ "379": 225,
210
+ "58": 734,
211
+ "681": 543,
212
+ "967": 421,
213
+ "260": 645,
214
+ "263": 648,
215
+ "670": 514,
216
+ "245": 632,
217
+ "856": 457,
218
+ "599": 362,
219
+ "850": 467,
220
+ "262": 647,
221
+ "82": 450,
222
+ "84": 452
223
+ }
@@ -8,6 +8,7 @@ export declare class GroupCipher {
8
8
  private readonly senderKeyStore;
9
9
  private readonly senderKeyName;
10
10
  constructor(senderKeyStore: SenderKeyStore, senderKeyName: SenderKeyName);
11
+ private queueJob;
11
12
  encrypt(paddedPlaintext: Uint8Array | string): Promise<Uint8Array>;
12
13
  decrypt(senderKeyMessageBytes: Uint8Array): Promise<Uint8Array>;
13
14
  private getSenderKey;
@@ -1,44 +1,55 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.GroupCipher = void 0;
4
7
  const crypto_1 = require("libsignal/src/crypto");
8
+ const queue_job_1 = __importDefault(require("./queue-job"));
5
9
  const sender_key_message_1 = require("./sender-key-message");
6
10
  class GroupCipher {
7
11
  constructor(senderKeyStore, senderKeyName) {
8
12
  this.senderKeyStore = senderKeyStore;
9
13
  this.senderKeyName = senderKeyName;
10
14
  }
15
+ queueJob(awaitable) {
16
+ return (0, queue_job_1.default)(this.senderKeyName.toString(), awaitable);
17
+ }
11
18
  async encrypt(paddedPlaintext) {
12
- const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
13
- if (!record) {
14
- throw new Error('No SenderKeyRecord found for encryption');
15
- }
16
- const senderKeyState = record.getSenderKeyState();
17
- if (!senderKeyState) {
18
- throw new Error('No session to encrypt message');
19
- }
20
- const iteration = senderKeyState.getSenderChainKey().getIteration();
21
- const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
22
- const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
23
- const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
24
- await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
25
- return senderKeyMessage.serialize();
19
+ return await this.queueJob(async () => {
20
+ const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
21
+ if (!record) {
22
+ throw new Error('No SenderKeyRecord found for encryption');
23
+ }
24
+ const senderKeyState = record.getSenderKeyState();
25
+ if (!senderKeyState) {
26
+ throw new Error('No session to encrypt message');
27
+ }
28
+ const iteration = senderKeyState.getSenderChainKey().getIteration();
29
+ const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
30
+ const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
31
+ const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
32
+ await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
33
+ return senderKeyMessage.serialize();
34
+ });
26
35
  }
27
36
  async decrypt(senderKeyMessageBytes) {
28
- const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
29
- if (!record) {
30
- throw new Error('No SenderKeyRecord found for decryption');
31
- }
32
- const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
33
- const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
34
- if (!senderKeyState) {
35
- throw new Error('No session found to decrypt message');
36
- }
37
- senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
38
- const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
39
- const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
40
- await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
41
- return plaintext;
37
+ return await this.queueJob(async () => {
38
+ const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
39
+ if (!record) {
40
+ throw new Error('No SenderKeyRecord found for decryption');
41
+ }
42
+ const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
43
+ const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
44
+ if (!senderKeyState) {
45
+ throw new Error('No session found to decrypt message');
46
+ }
47
+ senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
48
+ const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
49
+ const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
50
+ await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
51
+ return plaintext;
52
+ });
42
53
  }
43
54
  getSenderKey(senderKeyState, iteration) {
44
55
  let senderChainKey = senderKeyState.getSenderChainKey();
@@ -0,0 +1 @@
1
+ export default function queueJob<T>(bucket: string | number, awaitable: () => Promise<T>): Promise<T>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = queueJob;
4
+ const _queueAsyncBuckets = new Map();
5
+ const _gcLimit = 10000;
6
+ async function _asyncQueueExecutor(queue, cleanup) {
7
+ let offt = 0;
8
+ // eslint-disable-next-line no-constant-condition
9
+ while (true) {
10
+ const limit = Math.min(queue.length, _gcLimit);
11
+ for (let i = offt; i < limit; i++) {
12
+ const job = queue[i];
13
+ try {
14
+ job.resolve(await job.awaitable());
15
+ }
16
+ catch (e) {
17
+ job.reject(e);
18
+ }
19
+ }
20
+ if (limit < queue.length) {
21
+ if (limit >= _gcLimit) {
22
+ queue.splice(0, limit);
23
+ offt = 0;
24
+ }
25
+ else {
26
+ offt = limit;
27
+ }
28
+ }
29
+ else {
30
+ break;
31
+ }
32
+ }
33
+ cleanup();
34
+ }
35
+ function queueJob(bucket, awaitable) {
36
+ // Skip name assignment since it's readonly in strict mode
37
+ if (typeof bucket !== 'string') {
38
+ console.warn('Unhandled bucket type (for naming):', typeof bucket, bucket);
39
+ }
40
+ let inactive = false;
41
+ if (!_queueAsyncBuckets.has(bucket)) {
42
+ _queueAsyncBuckets.set(bucket, []);
43
+ inactive = true;
44
+ }
45
+ const queue = _queueAsyncBuckets.get(bucket);
46
+ const job = new Promise((resolve, reject) => {
47
+ queue.push({
48
+ awaitable,
49
+ resolve: resolve,
50
+ reject
51
+ });
52
+ });
53
+ if (inactive) {
54
+ _asyncQueueExecutor(queue, () => _queueAsyncBuckets.delete(bucket));
55
+ }
56
+ return job;
57
+ }