@queenanya/baileys 7.5.3-0 → 8.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 (179) hide show
  1. package/package.json +13 -97
  2. package/LICENSE +0 -21
  3. package/README.md +0 -931
  4. package/WAProto/GenerateStatics.sh +0 -4
  5. package/WAProto/WAProto.proto +0 -3344
  6. package/WAProto/index.d.ts +0 -37016
  7. package/WAProto/index.js +0 -130281
  8. package/WASignalGroup/GroupProtocol.js +0 -1697
  9. package/WASignalGroup/ciphertext_message.js +0 -16
  10. package/WASignalGroup/group_cipher.js +0 -120
  11. package/WASignalGroup/group_session_builder.js +0 -46
  12. package/WASignalGroup/index.js +0 -5
  13. package/WASignalGroup/keyhelper.js +0 -21
  14. package/WASignalGroup/protobufs.js +0 -3
  15. package/WASignalGroup/queue_job.js +0 -69
  16. package/WASignalGroup/sender_chain_key.js +0 -50
  17. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  18. package/WASignalGroup/sender_key_message.js +0 -92
  19. package/WASignalGroup/sender_key_name.js +0 -70
  20. package/WASignalGroup/sender_key_record.js +0 -56
  21. package/WASignalGroup/sender_key_state.js +0 -129
  22. package/WASignalGroup/sender_message_key.js +0 -39
  23. package/lib/Defaults/baileys-version.json +0 -3
  24. package/lib/Defaults/index.d.ts +0 -53
  25. package/lib/Defaults/index.js +0 -107
  26. package/lib/Signal/libsignal.d.ts +0 -3
  27. package/lib/Signal/libsignal.js +0 -152
  28. package/lib/Socket/Client/index.d.ts +0 -2
  29. package/lib/Socket/Client/index.js +0 -18
  30. package/lib/Socket/Client/types.d.ts +0 -17
  31. package/lib/Socket/Client/types.js +0 -13
  32. package/lib/Socket/Client/websocket.d.ts +0 -12
  33. package/lib/Socket/Client/websocket.js +0 -62
  34. package/lib/Socket/business.d.ts +0 -173
  35. package/lib/Socket/business.js +0 -260
  36. package/lib/Socket/chats.d.ts +0 -88
  37. package/lib/Socket/chats.js +0 -920
  38. package/lib/Socket/communities.d.ts +0 -216
  39. package/lib/Socket/communities.js +0 -354
  40. package/lib/Socket/groups.d.ts +0 -127
  41. package/lib/Socket/groups.js +0 -314
  42. package/lib/Socket/index.d.ts +0 -203
  43. package/lib/Socket/index.js +0 -10
  44. package/lib/Socket/messages-recv.d.ts +0 -160
  45. package/lib/Socket/messages-recv.js +0 -918
  46. package/lib/Socket/messages-send.d.ts +0 -153
  47. package/lib/Socket/messages-send.js +0 -794
  48. package/lib/Socket/newsletter.d.ts +0 -139
  49. package/lib/Socket/newsletter.js +0 -249
  50. package/lib/Socket/socket.d.ts +0 -45
  51. package/lib/Socket/socket.js +0 -616
  52. package/lib/Socket/usync.d.ts +0 -38
  53. package/lib/Socket/usync.js +0 -70
  54. package/lib/Store/index.d.ts +0 -3
  55. package/lib/Store/index.js +0 -10
  56. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  57. package/lib/Store/make-cache-manager-store.js +0 -83
  58. package/lib/Store/make-in-memory-store.d.ts +0 -118
  59. package/lib/Store/make-in-memory-store.js +0 -420
  60. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  61. package/lib/Store/make-ordered-dictionary.js +0 -81
  62. package/lib/Store/object-repository.d.ts +0 -10
  63. package/lib/Store/object-repository.js +0 -27
  64. package/lib/Types/Auth.d.ts +0 -105
  65. package/lib/Types/Auth.js +0 -2
  66. package/lib/Types/Call.d.ts +0 -13
  67. package/lib/Types/Call.js +0 -2
  68. package/lib/Types/Chat.d.ts +0 -110
  69. package/lib/Types/Chat.js +0 -4
  70. package/lib/Types/Contact.d.ts +0 -24
  71. package/lib/Types/Contact.js +0 -2
  72. package/lib/Types/Events.d.ts +0 -199
  73. package/lib/Types/Events.js +0 -2
  74. package/lib/Types/GroupMetadata.d.ts +0 -56
  75. package/lib/Types/GroupMetadata.js +0 -2
  76. package/lib/Types/Label.d.ts +0 -46
  77. package/lib/Types/Label.js +0 -27
  78. package/lib/Types/LabelAssociation.d.ts +0 -29
  79. package/lib/Types/LabelAssociation.js +0 -9
  80. package/lib/Types/Message.d.ts +0 -280
  81. package/lib/Types/Message.js +0 -9
  82. package/lib/Types/Newsletter.d.ts +0 -79
  83. package/lib/Types/Newsletter.js +0 -18
  84. package/lib/Types/Product.d.ts +0 -78
  85. package/lib/Types/Product.js +0 -2
  86. package/lib/Types/Signal.d.ts +0 -57
  87. package/lib/Types/Signal.js +0 -2
  88. package/lib/Types/Socket.d.ts +0 -118
  89. package/lib/Types/Socket.js +0 -2
  90. package/lib/Types/State.d.ts +0 -27
  91. package/lib/Types/State.js +0 -2
  92. package/lib/Types/USync.d.ts +0 -25
  93. package/lib/Types/USync.js +0 -2
  94. package/lib/Types/index.d.ts +0 -65
  95. package/lib/Types/index.js +0 -42
  96. package/lib/Utils/auth-utils.d.ts +0 -18
  97. package/lib/Utils/auth-utils.js +0 -200
  98. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  99. package/lib/Utils/baileys-event-stream.js +0 -63
  100. package/lib/Utils/business.d.ts +0 -22
  101. package/lib/Utils/business.js +0 -234
  102. package/lib/Utils/chat-utils.d.ts +0 -72
  103. package/lib/Utils/chat-utils.js +0 -756
  104. package/lib/Utils/crypto.d.ts +0 -42
  105. package/lib/Utils/crypto.js +0 -153
  106. package/lib/Utils/decode-wa-message.d.ts +0 -20
  107. package/lib/Utils/decode-wa-message.js +0 -218
  108. package/lib/Utils/event-buffer.d.ts +0 -35
  109. package/lib/Utils/event-buffer.js +0 -520
  110. package/lib/Utils/generics.d.ts +0 -119
  111. package/lib/Utils/generics.js +0 -468
  112. package/lib/Utils/history.d.ts +0 -19
  113. package/lib/Utils/history.js +0 -94
  114. package/lib/Utils/index.d.ts +0 -18
  115. package/lib/Utils/index.js +0 -34
  116. package/lib/Utils/link-preview.d.ts +0 -21
  117. package/lib/Utils/link-preview.js +0 -116
  118. package/lib/Utils/logger.d.ts +0 -2
  119. package/lib/Utils/logger.js +0 -7
  120. package/lib/Utils/lt-hash.d.ts +0 -12
  121. package/lib/Utils/lt-hash.js +0 -51
  122. package/lib/Utils/make-mutex.d.ts +0 -7
  123. package/lib/Utils/make-mutex.js +0 -44
  124. package/lib/Utils/messages-media.d.ts +0 -131
  125. package/lib/Utils/messages-media.js +0 -786
  126. package/lib/Utils/messages.d.ts +0 -78
  127. package/lib/Utils/messages.js +0 -767
  128. package/lib/Utils/noise-handler.d.ts +0 -21
  129. package/lib/Utils/noise-handler.js +0 -150
  130. package/lib/Utils/process-message.d.ts +0 -42
  131. package/lib/Utils/process-message.js +0 -355
  132. package/lib/Utils/signal.d.ts +0 -32
  133. package/lib/Utils/signal.js +0 -158
  134. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  135. package/lib/Utils/use-multi-file-auth-state.js +0 -94
  136. package/lib/Utils/use-single-file-auth-state.d.ts +0 -5
  137. package/lib/Utils/use-single-file-auth-state.js +0 -66
  138. package/lib/Utils/validate-connection.d.ts +0 -10
  139. package/lib/Utils/validate-connection.js +0 -171
  140. package/lib/WABinary/constants.d.ts +0 -27
  141. package/lib/WABinary/constants.js +0 -40
  142. package/lib/WABinary/decode.d.ts +0 -8
  143. package/lib/WABinary/decode.js +0 -254
  144. package/lib/WABinary/encode.d.ts +0 -2
  145. package/lib/WABinary/encode.js +0 -230
  146. package/lib/WABinary/generic-utils.d.ts +0 -16
  147. package/lib/WABinary/generic-utils.js +0 -110
  148. package/lib/WABinary/index.d.ts +0 -5
  149. package/lib/WABinary/index.js +0 -21
  150. package/lib/WABinary/jid-utils.d.ts +0 -31
  151. package/lib/WABinary/jid-utils.js +0 -62
  152. package/lib/WABinary/types.d.ts +0 -18
  153. package/lib/WABinary/types.js +0 -2
  154. package/lib/WAM/BinaryInfo.d.ts +0 -18
  155. package/lib/WAM/BinaryInfo.js +0 -13
  156. package/lib/WAM/constants.d.ts +0 -39
  157. package/lib/WAM/constants.js +0 -15350
  158. package/lib/WAM/encode.d.ts +0 -4
  159. package/lib/WAM/encode.js +0 -155
  160. package/lib/WAM/index.d.ts +0 -3
  161. package/lib/WAM/index.js +0 -19
  162. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  163. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  164. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  165. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  166. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  167. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  168. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  169. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  170. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  171. package/lib/WAUSync/Protocols/index.js +0 -20
  172. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  173. package/lib/WAUSync/USyncQuery.js +0 -79
  174. package/lib/WAUSync/USyncUser.d.ts +0 -10
  175. package/lib/WAUSync/USyncUser.js +0 -22
  176. package/lib/WAUSync/index.d.ts +0 -3
  177. package/lib/WAUSync/index.js +0 -19
  178. package/lib/index.d.ts +0 -12
  179. package/lib/index.js +0 -31
@@ -1,129 +0,0 @@
1
- const SenderChainKey = require('./sender_chain_key');
2
- const SenderMessageKey = require('./sender_message_key');
3
-
4
- const protobufs = require('./protobufs');
5
-
6
- class SenderKeyState {
7
- MAX_MESSAGE_KEYS = 2000;
8
-
9
- constructor(
10
- id = null,
11
- iteration = null,
12
- chainKey = null,
13
- signatureKeyPair = null,
14
- signatureKeyPublic = null,
15
- signatureKeyPrivate = null,
16
- senderKeyStateStructure = null
17
- ) {
18
- if (senderKeyStateStructure) {
19
- this.senderKeyStateStructure = senderKeyStateStructure;
20
- } else {
21
- if (signatureKeyPair) {
22
- signatureKeyPublic = signatureKeyPair.public;
23
- signatureKeyPrivate = signatureKeyPair.private;
24
- }
25
-
26
- chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
27
- this.senderKeyStateStructure = protobufs.SenderKeyStateStructure.create();
28
- const senderChainKeyStructure = protobufs.SenderChainKey.create();
29
- senderChainKeyStructure.iteration = iteration;
30
- senderChainKeyStructure.seed = chainKey;
31
- this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
32
-
33
- const signingKeyStructure = protobufs.SenderSigningKey.create();
34
- signingKeyStructure.public =
35
- typeof signatureKeyPublic === 'string' ?
36
- Buffer.from(signatureKeyPublic, 'base64') :
37
- signatureKeyPublic;
38
- if (signatureKeyPrivate) {
39
- signingKeyStructure.private =
40
- typeof signatureKeyPrivate === 'string' ?
41
- Buffer.from(signatureKeyPrivate, 'base64') :
42
- signatureKeyPrivate;
43
- }
44
- this.senderKeyStateStructure.senderKeyId = id;
45
- this.senderChainKey = senderChainKeyStructure;
46
- this.senderKeyStateStructure.senderSigningKey = signingKeyStructure;
47
- }
48
- this.senderKeyStateStructure.senderMessageKeys =
49
- this.senderKeyStateStructure.senderMessageKeys || [];
50
- }
51
-
52
- SenderKeyState(senderKeyStateStructure) {
53
- this.senderKeyStateStructure = senderKeyStateStructure;
54
- }
55
-
56
- getKeyId() {
57
- return this.senderKeyStateStructure.senderKeyId;
58
- }
59
-
60
- getSenderChainKey() {
61
- return new SenderChainKey(
62
- this.senderKeyStateStructure.senderChainKey.iteration,
63
- this.senderKeyStateStructure.senderChainKey.seed
64
- );
65
- }
66
-
67
- setSenderChainKey(chainKey) {
68
- const senderChainKeyStructure = protobufs.SenderChainKey.create({
69
- iteration: chainKey.getIteration(),
70
- seed: chainKey.getSeed(),
71
- });
72
- this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
73
- }
74
-
75
- getSigningKeyPublic() {
76
- return typeof this.senderKeyStateStructure.senderSigningKey.public === 'string' ?
77
- Buffer.from(this.senderKeyStateStructure.senderSigningKey.public, 'base64') :
78
- this.senderKeyStateStructure.senderSigningKey.public;
79
- }
80
-
81
- getSigningKeyPrivate() {
82
- return typeof this.senderKeyStateStructure.senderSigningKey.private === 'string' ?
83
- Buffer.from(this.senderKeyStateStructure.senderSigningKey.private, 'base64') :
84
- this.senderKeyStateStructure.senderSigningKey.private;
85
- }
86
-
87
- hasSenderMessageKey(iteration) {
88
- const list = this.senderKeyStateStructure.senderMessageKeys;
89
- for (let o = 0; o < list.length; o++) {
90
- const senderMessageKey = list[o];
91
- if (senderMessageKey.iteration === iteration) return true;
92
- }
93
- return false;
94
- }
95
-
96
- addSenderMessageKey(senderMessageKey) {
97
- const senderMessageKeyStructure = protobufs.SenderKeyStateStructure.create({
98
- iteration: senderMessageKey.getIteration(),
99
- seed: senderMessageKey.getSeed(),
100
- });
101
- this.senderKeyStateStructure.senderMessageKeys.push(senderMessageKeyStructure);
102
-
103
- if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
104
- this.senderKeyStateStructure.senderMessageKeys.shift();
105
- }
106
- }
107
-
108
- removeSenderMessageKey(iteration) {
109
- let result = null;
110
-
111
- this.senderKeyStateStructure.senderMessageKeys = this.senderKeyStateStructure.senderMessageKeys.filter(
112
- senderMessageKey => {
113
- if (senderMessageKey.iteration === iteration) result = senderMessageKey;
114
- return senderMessageKey.iteration !== iteration;
115
- }
116
- );
117
-
118
- if (result != null) {
119
- return new SenderMessageKey(result.iteration, result.seed);
120
- }
121
- return null;
122
- }
123
-
124
- getStructure() {
125
- return this.senderKeyStateStructure;
126
- }
127
- }
128
-
129
- module.exports = SenderKeyState;
@@ -1,39 +0,0 @@
1
- const { deriveSecrets } = require('libsignal/src/crypto');
2
- class SenderMessageKey {
3
- iteration = 0;
4
-
5
- iv = Buffer.alloc(0);
6
-
7
- cipherKey = Buffer.alloc(0);
8
-
9
- seed = Buffer.alloc(0);
10
-
11
- constructor(iteration, seed) {
12
- const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
13
- const keys = new Uint8Array(32);
14
- keys.set(new Uint8Array(derivative[0].slice(16)));
15
- keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
16
- this.iv = Buffer.from(derivative[0].slice(0, 16));
17
- this.cipherKey = Buffer.from(keys.buffer);
18
-
19
- this.iteration = iteration;
20
- this.seed = seed;
21
- }
22
-
23
- getIteration() {
24
- return this.iteration;
25
- }
26
-
27
- getIv() {
28
- return this.iv;
29
- }
30
-
31
- getCipherKey() {
32
- return this.cipherKey;
33
- }
34
-
35
- getSeed() {
36
- return this.seed;
37
- }
38
- }
39
- module.exports = SenderMessageKey;
@@ -1,3 +0,0 @@
1
- {
2
- "version": [2, 3000, 1019080420]
3
- }
@@ -1,53 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { proto } from '../../WAProto';
4
- import type { MediaType, SocketConfig } from '../Types';
5
- export declare const UNAUTHORIZED_CODES: number[];
6
- export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
7
- export declare const DEF_CALLBACK_PREFIX = "CB:";
8
- export declare const DEF_TAG_PREFIX = "TAG:";
9
- export declare const PHONE_CONNECTION_CB = "CB:Pong";
10
- export declare const WA_DEFAULT_EPHEMERAL: number;
11
- export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
12
- export declare const DICT_VERSION = 2;
13
- export declare const KEY_BUNDLE_TYPE: Buffer;
14
- export declare const NOISE_WA_HEADER: Buffer;
15
- /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
16
- export declare const URL_REGEX: RegExp;
17
- export declare const WA_CERT_DETAILS: {
18
- SERIAL: number;
19
- };
20
- export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[];
21
- export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig;
22
- export declare const MEDIA_PATH_MAP: {
23
- [T in MediaType]?: string;
24
- };
25
- export declare const MEDIA_HKDF_KEY_MAPPING: {
26
- audio: string;
27
- document: string;
28
- gif: string;
29
- image: string;
30
- ppic: string;
31
- product: string;
32
- ptt: string;
33
- sticker: string;
34
- video: string;
35
- 'thumbnail-document': string;
36
- 'thumbnail-image': string;
37
- 'thumbnail-video': string;
38
- 'thumbnail-link': string;
39
- 'md-msg-hist': string;
40
- 'md-app-state': string;
41
- 'product-catalog-image': string;
42
- 'payment-bg-image': string;
43
- ptv: string;
44
- };
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")[];
46
- export declare const MIN_PREKEY_COUNT = 5;
47
- export declare const INITIAL_PREKEY_COUNT = 30;
48
- export declare const DEFAULT_CACHE_TTLS: {
49
- SIGNAL_STORE: number;
50
- MSG_RETRY: number;
51
- CALL_OFFER: number;
52
- USER_DEVICES: number;
53
- };
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DEFAULT_CACHE_TTLS = 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.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = void 0;
7
- const WAProto_1 = require("../../WAProto");
8
- const libsignal_1 = require("../Signal/libsignal");
9
- const Utils_1 = require("../Utils");
10
- const logger_1 = __importDefault(require("../Utils/logger"));
11
- const baileys_version_json_1 = require("./baileys-version.json");
12
- exports.UNAUTHORIZED_CODES = [401, 403, 419];
13
- exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
14
- exports.DEF_CALLBACK_PREFIX = 'CB:';
15
- exports.DEF_TAG_PREFIX = 'TAG:';
16
- exports.PHONE_CONNECTION_CB = 'CB:Pong';
17
- // export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
18
- exports.WA_DEFAULT_EPHEMERAL = 24 * 60 * 60;
19
- exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
20
- exports.DICT_VERSION = 2;
21
- exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
22
- exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
23
- /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
24
- exports.URL_REGEX = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
25
- exports.WA_CERT_DETAILS = {
26
- SERIAL: 0,
27
- };
28
- exports.PROCESSABLE_HISTORY_TYPES = [
29
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
30
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
31
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
32
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
33
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
34
- ];
35
- exports.DEFAULT_CONNECTION_CONFIG = {
36
- version: baileys_version_json_1.version,
37
- browser: Utils_1.Browsers.ubuntu('Firefox'),
38
- waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
39
- connectTimeoutMs: 20000,
40
- keepAliveIntervalMs: 30000,
41
- logger: logger_1.default.child({ class: 'baileys' }),
42
- printQRInTerminal: true,
43
- emitOwnEvents: true,
44
- defaultQueryTimeoutMs: undefined,
45
- customUploadHosts: [],
46
- retryRequestDelayMs: 250,
47
- maxMsgRetryCount: 5,
48
- fireInitQueries: true,
49
- ignoreMsgLoading: false,
50
- auth: undefined,
51
- markOnlineOnConnect: true,
52
- syncFullHistory: false,
53
- patchMessageBeforeSending: msg => msg,
54
- shouldSyncHistoryMessage: () => true,
55
- shouldIgnoreJid: () => false,
56
- linkPreviewImageThumbnailWidth: 192,
57
- transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
58
- generateHighQualityLinkPreview: true,
59
- options: {},
60
- appStateMacVerification: {
61
- patch: false,
62
- snapshot: false,
63
- },
64
- getMessage: async () => undefined,
65
- cachedGroupMetadata: async () => undefined,
66
- makeSignalRepository: libsignal_1.makeLibSignalRepository
67
- };
68
- exports.MEDIA_PATH_MAP = {
69
- image: '/mms/image',
70
- video: '/mms/video',
71
- document: '/mms/document',
72
- audio: '/mms/audio',
73
- sticker: '/mms/image',
74
- 'thumbnail-link': '/mms/image',
75
- 'product-catalog-image': '/product/image',
76
- 'md-app-state': '',
77
- 'md-msg-hist': '/mms/md-app-state',
78
- };
79
- exports.MEDIA_HKDF_KEY_MAPPING = {
80
- 'audio': 'Audio',
81
- 'document': 'Document',
82
- 'gif': 'Video',
83
- 'image': 'Image',
84
- 'ppic': '',
85
- 'product': 'Image',
86
- 'ptt': 'Audio',
87
- 'sticker': 'Image',
88
- 'video': 'Video',
89
- 'thumbnail-document': 'Document Thumbnail',
90
- 'thumbnail-image': 'Image Thumbnail',
91
- 'thumbnail-video': 'Video Thumbnail',
92
- 'thumbnail-link': 'Link Thumbnail',
93
- 'md-msg-hist': 'History',
94
- 'md-app-state': 'App State',
95
- 'product-catalog-image': '',
96
- 'payment-bg-image': 'Payment Background',
97
- 'ptv': 'Video'
98
- };
99
- exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
100
- exports.MIN_PREKEY_COUNT = 5;
101
- exports.INITIAL_PREKEY_COUNT = 30;
102
- exports.DEFAULT_CACHE_TTLS = {
103
- SIGNAL_STORE: 5 * 60,
104
- MSG_RETRY: 60 * 60,
105
- CALL_OFFER: 5 * 60,
106
- USER_DEVICES: 5 * 60, // 5 minutes
107
- };
@@ -1,3 +0,0 @@
1
- import { SignalAuthState } from '../Types';
2
- import { SignalRepository } from '../Types/Signal';
3
- export declare function makeLibSignalRepository(auth: SignalAuthState): SignalRepository;
@@ -1,152 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeLibSignalRepository = void 0;
27
- const libsignal = __importStar(require("libsignal"));
28
- const WASignalGroup_1 = require("../../WASignalGroup");
29
- const Utils_1 = require("../Utils");
30
- const WABinary_1 = require("../WABinary");
31
- function makeLibSignalRepository(auth) {
32
- const storage = signalStorage(auth);
33
- return {
34
- decryptGroupMessage({ group, authorJid, msg }) {
35
- const senderName = jidToSignalSenderKeyName(group, authorJid);
36
- const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
37
- return cipher.decrypt(msg);
38
- },
39
- async processSenderKeyDistributionMessage({ item, authorJid }) {
40
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
41
- const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
42
- const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
43
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
44
- if (!senderKey) {
45
- await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
46
- }
47
- await builder.process(senderName, senderMsg);
48
- },
49
- async decryptMessage({ jid, type, ciphertext }) {
50
- const addr = jidToSignalProtocolAddress(jid);
51
- const session = new libsignal.SessionCipher(storage, addr);
52
- let result;
53
- switch (type) {
54
- case 'pkmsg':
55
- result = await session.decryptPreKeyWhisperMessage(ciphertext);
56
- break;
57
- case 'msg':
58
- result = await session.decryptWhisperMessage(ciphertext);
59
- break;
60
- }
61
- return result;
62
- },
63
- async encryptMessage({ jid, data }) {
64
- const addr = jidToSignalProtocolAddress(jid);
65
- const cipher = new libsignal.SessionCipher(storage, addr);
66
- const { type: sigType, body } = await cipher.encrypt(data);
67
- const type = sigType === 3 ? 'pkmsg' : 'msg';
68
- return { type, ciphertext: Buffer.from(body, 'binary') };
69
- },
70
- async encryptGroupMessage({ group, meId, data }) {
71
- const senderName = jidToSignalSenderKeyName(group, meId);
72
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
73
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
74
- if (!senderKey) {
75
- await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
76
- }
77
- const senderKeyDistributionMessage = await builder.create(senderName);
78
- const session = new WASignalGroup_1.GroupCipher(storage, senderName);
79
- const ciphertext = await session.encrypt(data);
80
- return {
81
- ciphertext,
82
- senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
83
- };
84
- },
85
- async injectE2ESession({ jid, session }) {
86
- const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
87
- await cipher.initOutgoing(session);
88
- },
89
- jidToSignalProtocolAddress(jid) {
90
- return jidToSignalProtocolAddress(jid).toString();
91
- },
92
- };
93
- }
94
- exports.makeLibSignalRepository = makeLibSignalRepository;
95
- const jidToSignalProtocolAddress = (jid) => {
96
- const { user, device } = (0, WABinary_1.jidDecode)(jid);
97
- return new libsignal.ProtocolAddress(user, device || 0);
98
- };
99
- const jidToSignalSenderKeyName = (group, user) => {
100
- return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
101
- };
102
- function signalStorage({ creds, keys }) {
103
- return {
104
- loadSession: async (id) => {
105
- const { [id]: sess } = await keys.get('session', [id]);
106
- if (sess) {
107
- return libsignal.SessionRecord.deserialize(sess);
108
- }
109
- },
110
- storeSession: async (id, session) => {
111
- await keys.set({ 'session': { [id]: session.serialize() } });
112
- },
113
- isTrustedIdentity: () => {
114
- return true;
115
- },
116
- loadPreKey: async (id) => {
117
- const keyId = id.toString();
118
- const { [keyId]: key } = await keys.get('pre-key', [keyId]);
119
- if (key) {
120
- return {
121
- privKey: Buffer.from(key.private),
122
- pubKey: Buffer.from(key.public)
123
- };
124
- }
125
- },
126
- removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
127
- loadSignedPreKey: () => {
128
- const key = creds.signedPreKey;
129
- return {
130
- privKey: Buffer.from(key.keyPair.private),
131
- pubKey: Buffer.from(key.keyPair.public)
132
- };
133
- },
134
- loadSenderKey: async (keyId) => {
135
- const { [keyId]: key } = await keys.get('sender-key', [keyId]);
136
- if (key) {
137
- return new WASignalGroup_1.SenderKeyRecord(key);
138
- }
139
- },
140
- storeSenderKey: async (keyId, key) => {
141
- await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
142
- },
143
- getOurRegistrationId: () => (creds.registrationId),
144
- getOurIdentity: () => {
145
- const { signedIdentityKey } = creds;
146
- return {
147
- privKey: Buffer.from(signedIdentityKey.private),
148
- pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
149
- };
150
- }
151
- };
152
- }
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './websocket';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./websocket"), exports);
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { EventEmitter } from 'events';
4
- import { URL } from 'url';
5
- import { SocketConfig } from '../../Types';
6
- export declare abstract class AbstractSocketClient extends EventEmitter {
7
- url: URL;
8
- config: SocketConfig;
9
- abstract get isOpen(): boolean;
10
- abstract get isClosed(): boolean;
11
- abstract get isClosing(): boolean;
12
- abstract get isConnecting(): boolean;
13
- constructor(url: URL, config: SocketConfig);
14
- abstract connect(): Promise<void>;
15
- abstract close(): Promise<void>;
16
- abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
17
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractSocketClient = void 0;
4
- const events_1 = require("events");
5
- class AbstractSocketClient extends events_1.EventEmitter {
6
- constructor(url, config) {
7
- super();
8
- this.url = url;
9
- this.config = config;
10
- this.setMaxListeners(0);
11
- }
12
- }
13
- exports.AbstractSocketClient = AbstractSocketClient;
@@ -1,12 +0,0 @@
1
- import WebSocket from 'ws';
2
- import { AbstractSocketClient } from './types';
3
- export declare class WebSocketClient extends AbstractSocketClient {
4
- protected socket: WebSocket | null;
5
- get isOpen(): boolean;
6
- get isClosed(): boolean;
7
- get isClosing(): boolean;
8
- get isConnecting(): boolean;
9
- connect(): Promise<void>;
10
- close(): Promise<void>;
11
- send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
12
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WebSocketClient = void 0;
7
- const ws_1 = __importDefault(require("ws"));
8
- const Defaults_1 = require("../../Defaults");
9
- const types_1 = require("./types");
10
- class WebSocketClient extends types_1.AbstractSocketClient {
11
- constructor() {
12
- super(...arguments);
13
- this.socket = null;
14
- }
15
- get isOpen() {
16
- var _a;
17
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
18
- }
19
- get isClosed() {
20
- var _a;
21
- return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
22
- }
23
- get isClosing() {
24
- var _a;
25
- return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
26
- }
27
- get isConnecting() {
28
- var _a;
29
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
30
- }
31
- async connect() {
32
- var _a, _b;
33
- if (this.socket) {
34
- return;
35
- }
36
- this.socket = new ws_1.default(this.url, {
37
- origin: Defaults_1.DEFAULT_ORIGIN,
38
- headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
- handshakeTimeout: this.config.connectTimeoutMs,
40
- timeout: this.config.connectTimeoutMs,
41
- agent: this.config.agent,
42
- });
43
- this.socket.setMaxListeners(0);
44
- const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
45
- for (const event of events) {
46
- (_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
47
- }
48
- }
49
- async close() {
50
- if (!this.socket) {
51
- return;
52
- }
53
- this.socket.close();
54
- this.socket = null;
55
- }
56
- send(str, cb) {
57
- var _a;
58
- (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
59
- return Boolean(this.socket);
60
- }
61
- }
62
- exports.WebSocketClient = WebSocketClient;