@baileys-md/baileys 12.0.0 → 12.2.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 (109) hide show
  1. package/LICENSE +21 -13
  2. package/WAProto/WAProto.proto +769 -233
  3. package/WAProto/index.js +65813 -141372
  4. package/lib/Defaults/index.js +128 -113
  5. package/lib/KeyDB/BinarySearch.js +30 -0
  6. package/lib/KeyDB/KeyedDB.js +178 -0
  7. package/lib/KeyDB/index.js +14 -0
  8. package/lib/Signal/Group/ciphertext-message.js +22 -14
  9. package/lib/Signal/Group/group-session-builder.js +21 -42
  10. package/lib/Signal/Group/group_cipher.js +85 -87
  11. package/lib/Signal/Group/index.js +23 -57
  12. package/lib/Signal/Group/keyhelper.js +28 -52
  13. package/lib/Signal/Group/sender-chain-key.js +37 -33
  14. package/lib/Signal/Group/sender-key-distribution-message.js +73 -63
  15. package/lib/Signal/Group/sender-key-message.js +75 -66
  16. package/lib/Signal/Group/sender-key-name.js +55 -44
  17. package/lib/Signal/Group/sender-key-record.js +49 -49
  18. package/lib/Signal/Group/sender-key-state.js +90 -93
  19. package/lib/Signal/Group/sender-message-key.js +37 -28
  20. package/lib/Signal/libsignal.js +324 -163
  21. package/lib/Signal/lid-mapping.js +166 -0
  22. package/lib/Socket/Client/index.js +14 -18
  23. package/lib/Socket/Client/types.js +12 -12
  24. package/lib/Socket/Client/websocket.js +60 -109
  25. package/lib/Socket/business.js +359 -242
  26. package/lib/Socket/chats.js +857 -898
  27. package/lib/Socket/communities.js +413 -0
  28. package/lib/Socket/groups.js +304 -324
  29. package/lib/Socket/index.js +25 -9
  30. package/lib/Socket/messages-recv.js +1109 -1000
  31. package/lib/Socket/messages-send.js +615 -387
  32. package/lib/Socket/mex.js +45 -0
  33. package/lib/Socket/newsletter.js +231 -227
  34. package/lib/Socket/socket.js +803 -628
  35. package/lib/Store/index.js +18 -8
  36. package/lib/Store/make-cache-manager-store.js +75 -0
  37. package/lib/Store/make-in-memory-store.js +286 -435
  38. package/lib/Store/make-ordered-dictionary.js +77 -79
  39. package/lib/Store/object-repository.js +24 -26
  40. package/lib/Types/Auth.js +13 -2
  41. package/lib/Types/Bussines.js +13 -0
  42. package/lib/Types/Call.js +13 -2
  43. package/lib/Types/Chat.js +19 -4
  44. package/lib/Types/Contact.js +13 -2
  45. package/lib/Types/Events.js +13 -2
  46. package/lib/Types/GroupMetadata.js +13 -2
  47. package/lib/Types/Label.js +43 -26
  48. package/lib/Types/LabelAssociation.js +16 -8
  49. package/lib/Types/Message.js +22 -7
  50. package/lib/Types/Newsletter.js +42 -17
  51. package/lib/Types/Product.js +13 -2
  52. package/lib/Types/Signal.js +13 -2
  53. package/lib/Types/Socket.js +14 -2
  54. package/lib/Types/State.js +21 -2
  55. package/lib/Types/USync.js +13 -2
  56. package/lib/Types/index.js +37 -41
  57. package/lib/Utils/auth-utils.js +219 -189
  58. package/lib/Utils/baileys-event-stream.js +54 -0
  59. package/lib/Utils/browser-utils.js +21 -31
  60. package/lib/Utils/business.js +213 -214
  61. package/lib/Utils/chat-utils.js +711 -689
  62. package/lib/Utils/crypto.js +112 -175
  63. package/lib/Utils/decode-wa-message.js +254 -194
  64. package/lib/Utils/event-buffer.js +510 -500
  65. package/lib/Utils/generics.js +318 -430
  66. package/lib/Utils/history.js +83 -90
  67. package/lib/Utils/index.js +31 -35
  68. package/lib/Utils/link-preview.js +71 -116
  69. package/lib/Utils/logger.js +5 -7
  70. package/lib/Utils/lt-hash.js +40 -46
  71. package/lib/Utils/make-mutex.js +34 -41
  72. package/lib/Utils/message-retry-manager.js +33 -48
  73. package/lib/Utils/messages-media.js +516 -784
  74. package/lib/Utils/messages.js +347 -489
  75. package/lib/Utils/noise-handler.js +138 -144
  76. package/lib/Utils/pre-key-manager.js +95 -0
  77. package/lib/Utils/process-message.js +331 -384
  78. package/lib/Utils/signal.js +157 -139
  79. package/lib/Utils/use-multi-file-auth-state.js +119 -91
  80. package/lib/Utils/validate-connection.js +184 -203
  81. package/lib/WABinary/constants.js +1308 -1298
  82. package/lib/WABinary/decode.js +241 -256
  83. package/lib/WABinary/encode.js +217 -239
  84. package/lib/WABinary/generic-utils.js +131 -40
  85. package/lib/WABinary/index.js +17 -21
  86. package/lib/WABinary/jid-utils.js +97 -79
  87. package/lib/WABinary/types.js +13 -2
  88. package/lib/WAM/BinaryInfo.js +20 -12
  89. package/lib/WAM/constants.js +22863 -15348
  90. package/lib/WAM/encode.js +145 -136
  91. package/lib/WAM/index.js +15 -19
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +39 -31
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +61 -54
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +39 -29
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +48 -40
  96. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -51
  97. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +38 -21
  98. package/lib/WAUSync/Protocols/index.js +17 -20
  99. package/lib/WAUSync/USyncQuery.js +98 -86
  100. package/lib/WAUSync/USyncUser.js +35 -26
  101. package/lib/WAUSync/index.js +16 -19
  102. package/lib/index.js +23 -41
  103. package/package.json +46 -56
  104. package/README.md +0 -113
  105. package/WAProto/GenerateStatics.sh +0 -4
  106. package/lib/Defaults/wileys-version.json +0 -3
  107. package/lib/Signal/Group/queue-job.js +0 -57
  108. package/lib/Socket/usync.js +0 -70
  109. package/lib/Utils/wileys-event-stream.js +0 -63
@@ -1,118 +1,133 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+
14
+ import { makeLibSignalRepository } from "../Signal/libsignal.js";
15
+ import { Browsers } from "../Utils/browser-utils.js";
16
+ import { proto } from "../../WAProto/index.js";
17
+ import logger from "../Utils/logger.js";
18
+
19
+ export const version = [2, 3000, 1033846690]
20
+ export const DICT_VERSION = 3;
21
+ export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]);
22
+ export const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
23
+ export const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
24
+ export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
25
+ export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
26
+ export const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
27
+ export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
28
+ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
29
+ export const DEFAULT_ORIGIN = "https://web.whatsapp.com";
30
+ export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
31
+ export const UNAUTHORIZED_CODES = [401, 403, 419];
32
+ export const KEY_BUNDLE_TYPE = Buffer.from([5]);
33
+ export const PHONE_CONNECTION_CB = "CB:Pong";
34
+ export const DEF_CALLBACK_PREFIX = "CB:";
35
+ export const DEF_TAG_PREFIX = "TAG:";
36
+
37
+ export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
38
+
39
+ export const WA_CERT_DETAILS = {
40
+ SERIAL: 0
4
41
  };
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.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = exports.WA_ADV_DEVICE_SIG_PREFIX = exports.WA_ADV_ACCOUNT_SIG_PREFIX = exports.UNAUTHORIZED_CODES = exports.version = void 0;
7
- const WAProto_1 = require("../../WAProto");
8
- const libsignal_1 = require("../Signal/libsignal");
9
- const browser_utils_1 = require("../Utils/browser-utils");
10
- const logger_1 = __importDefault(require("../Utils/logger"));
11
- exports.version = [2, 3000, 1033959288];
12
- 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_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
20
- exports.WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
21
- exports.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
22
- exports.WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
23
- exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
24
- exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
25
- exports.DICT_VERSION = 3;
26
- exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
27
- exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
28
- exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
29
- exports.WA_CERT_DETAILS = {
30
- SERIAL: 0
31
- };
32
- exports.PROCESSABLE_HISTORY_TYPES = [
33
- WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
34
- WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME,
35
- WAProto_1.proto.HistorySync.HistorySyncType.RECENT,
36
- WAProto_1.proto.HistorySync.HistorySyncType.FULL,
37
- WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND,
38
- WAProto_1.proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
39
- WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3,
42
+
43
+ export const PROCESSABLE_HISTORY_TYPES = [
44
+ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
45
+ proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
46
+ proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
47
+ proto.Message.HistorySyncNotification.HistorySyncType.FULL,
48
+ proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
49
+ proto.Message.HistorySyncNotification.HistorySyncType.NON_BLOCKING_DATA,
50
+ proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_STATUS_V3
40
51
  ];
41
- exports.DEFAULT_CONNECTION_CONFIG = {
42
- version: exports.version,
43
- browser: (0, browser_utils_1.Browsers)('Chrome'),
44
- waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
45
- connectTimeoutMs: 20_000,
46
- keepAliveIntervalMs: 10_000,
47
- logger: logger_1.default.child({ class: 'baileys' }),
48
- emitOwnEvents: true,
49
- defaultQueryTimeoutMs: 60_000,
50
- customUploadHosts: [],
51
- retryRequestDelayMs: 250,
52
- maxMsgRetryCount: 5,
53
- fireInitQueries: true,
54
- auth: undefined,
55
- markOnlineOnConnect: true,
56
- syncFullHistory: true,
57
- patchMessageBeforeSending: msg => msg,
58
- shouldSyncHistoryMessage: () => true,
59
- shouldIgnoreJid: () => false,
60
- linkPreviewImageThumbnailWidth: 192,
61
- transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
62
- generateHighQualityLinkPreview: false,
63
- enableAutoSessionRecreation: true,
64
- enableRecentMessageCache: true,
65
- options: {},
66
- appStateMacVerification: {
67
- patch: false,
68
- snapshot: false
69
- },
70
- countryCode: 'US',
71
- getMessage: async () => undefined,
72
- cachedGroupMetadata: async () => undefined,
73
- makeSignalRepository: libsignal_1.makeLibSignalRepository
52
+
53
+ export const DEFAULT_CONNECTION_CONFIG = {
54
+ "version": version,
55
+ "browser": Browsers.iOS("Safari"),
56
+ "waWebSocketUrl": "wss://web.whatsapp.com/ws/chat",
57
+ "connectTimeoutMs": 20000,
58
+ "keepAliveIntervalMs": 5000,
59
+ "logger": logger.child({ "class": "baileys" }),
60
+ "emitOwnEvents": true,
61
+ "defaultQueryTimeoutMs": 60000,
62
+ "customUploadHosts": [],
63
+ "retryRequestDelayMs": 250,
64
+ "maxMsgRetryCount": 5,
65
+ "fireInitQueries": true,
66
+ "auth": undefined,
67
+ "markOnlineOnConnect": true,
68
+ "syncFullHistory": true,
69
+ "patchMessageBeforeSending": msg => msg,
70
+ "shouldSyncHistoryMessage": () => true,
71
+ "shouldIgnoreJid": () => false,
72
+ "linkPreviewImageThumbnailWidth": 192,
73
+ "transactionOpts": { "maxCommitRetries": 10, "delayBetweenTriesMs": 3000 },
74
+ "generateHighQualityLinkPreview": true,
75
+ "enableAutoSessionRecreation": true,
76
+ "enableRecentMessageCache": true,
77
+ "options": {},
78
+ "appStateMacVerification": {
79
+ "patch": false,
80
+ "snapshot": false
81
+ },
82
+ "countryCode": "US",
83
+ "getMessage": async () => undefined,
84
+ "cachedGroupMetadata": async () => undefined,
85
+ "makeSignalRepository": makeLibSignalRepository
86
+ };
87
+
88
+ export const MEDIA_PATH_MAP = {
89
+ "image": "/mms/image",
90
+ "video": "/mms/video",
91
+ "document": "/mms/document",
92
+ "audio": "/mms/audio",
93
+ "sticker": "/mms/image",
94
+ "thumbnail-link": "/mms/image",
95
+ "product-catalog-image": "/product/image",
96
+ "md-app-state": "",
97
+ "md-msg-hist": "/mms/md-app-state",
98
+ "biz-cover-photo": "/pps/biz-cover-photo"
74
99
  };
75
- exports.MEDIA_PATH_MAP = {
76
- image: '/mms/image',
77
- video: '/mms/video',
78
- document: '/mms/document',
79
- audio: '/mms/audio',
80
- sticker: '/mms/image',
81
- 'thumbnail-link': '/mms/image',
82
- 'product-catalog-image': '/product/image',
83
- 'md-app-state': '',
84
- 'md-msg-hist': '/mms/md-app-state',
85
- 'biz-cover-photo': '/pps/biz-cover-photo'
100
+
101
+ export const MEDIA_HKDF_KEY_MAPPING = {
102
+ "audio": "Audio",
103
+ "document": "Document",
104
+ "gif": "Video",
105
+ "image": "Image",
106
+ "ppic": "",
107
+ "product": "Image",
108
+ "ptt": "Audio",
109
+ "sticker": "Image",
110
+ "video": "Video",
111
+ "thumbnail-document": "Document Thumbnail",
112
+ "thumbnail-image": "Image Thumbnail",
113
+ "thumbnail-video": "Video Thumbnail",
114
+ "thumbnail-link": "Link Thumbnail",
115
+ "md-msg-hist": "History",
116
+ "md-app-state": "App State",
117
+ "product-catalog-image": "",
118
+ "payment-bg-image": "Payment Background",
119
+ "ptv": "Video",
120
+ "biz-cover-photo": "Image"
86
121
  };
87
- exports.MEDIA_HKDF_KEY_MAPPING = {
88
- audio: 'Audio',
89
- document: 'Document',
90
- gif: 'Video',
91
- image: 'Image',
92
- ppic: '',
93
- product: 'Image',
94
- ptt: 'Audio',
95
- sticker: 'Image',
96
- video: 'Video',
97
- 'thumbnail-document': 'Document Thumbnail',
98
- 'thumbnail-image': 'Image Thumbnail',
99
- 'thumbnail-video': 'Video Thumbnail',
100
- 'thumbnail-link': 'Link Thumbnail',
101
- 'md-msg-hist': 'History',
102
- 'md-app-state': 'App State',
103
- 'product-catalog-image': '',
104
- 'payment-bg-image': 'Payment Background',
105
- ptv: 'Video',
106
- 'biz-cover-photo': 'Image'
122
+
123
+ export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
124
+ export const MIN_PREKEY_COUNT = 5;
125
+ export const INITIAL_PREKEY_COUNT = 812;
126
+ export const UPLOAD_TIMEOUT = 30000;
127
+ export const MIN_UPLOAD_INTERVAL = 5000;
128
+ export const DEFAULT_CACHE_TTLS = {
129
+ SIGNAL_STORE: 5 * 60,
130
+ MSG_RETRY: 60 * 60,
131
+ CALL_OFFER: 5 * 60,
132
+ USER_DEVICES: 5 * 60
107
133
  };
108
- exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
109
- exports.MIN_PREKEY_COUNT = 5;
110
- exports.INITIAL_PREKEY_COUNT = 812;
111
- exports.UPLOAD_TIMEOUT = 30000;
112
- exports.MIN_UPLOAD_INTERVAL = 5000;
113
- exports.DEFAULT_CACHE_TTLS = {
114
- SIGNAL_STORE: 5 * 60,
115
- MSG_RETRY: 60 * 60,
116
- CALL_OFFER: 5 * 60,
117
- USER_DEVICES: 5 * 60
118
- };
@@ -0,0 +1,30 @@
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+
14
+ export default function binarySearch(array, predicate) {
15
+ let low = 0
16
+ let high = array.length
17
+
18
+ if (high === 0) return -1
19
+
20
+ while (low < high) {
21
+ const Mafilzin = (low + high) >> 1
22
+ const ninja = predicate(array[Mafilzin])
23
+
24
+ if (ninja === 0) return Mafilzin
25
+ if (ninja < 0) high = Mafilzin
26
+ else low = Mafilzin + 1
27
+ }
28
+
29
+ return -1
30
+ }
@@ -0,0 +1,178 @@
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+
14
+ import binarySearch from "./BinarySearch.js";
15
+
16
+ export default class KeyedDB {
17
+ constructor(key, id) {
18
+ this.key = key;
19
+ this.idGetter = id || (v => this.key.key(v).toString());
20
+ this.dict = {};
21
+ this.array = [];
22
+ }
23
+ get length() {
24
+ return this.array.length;
25
+ }
26
+ get first() {
27
+ return this.array[0];
28
+ }
29
+ get last() {
30
+ return this.array[this.array.length - 1];
31
+ }
32
+ toJSON() {
33
+ return this.array;
34
+ }
35
+ insert(...values) {
36
+ values.forEach(v => this._insertSingle(v));
37
+ }
38
+ upsert(...values) {
39
+ const updates = [];
40
+ values.forEach(v => {
41
+ if (!v) return;
42
+ const deleted = this.deleteById(this.idGetter(v), false);
43
+ this._insertSingle(v);
44
+ deleted && updates.push(v);
45
+ });
46
+ return updates;
47
+ }
48
+ insertIfAbsent(...values) {
49
+ const insertions = [];
50
+ values.forEach(v => {
51
+ if (!v) return;
52
+ const presentValue = this.get(this.idGetter(v));
53
+ if (presentValue) return;
54
+ const presentKey = this.firstIndex(v);
55
+ if (this.array[presentKey] && this.key.key(this.array[presentKey]) === this.key.key(v)) return;
56
+ this.insert(v);
57
+ insertions.push(v);
58
+ });
59
+ return insertions;
60
+ }
61
+ deleteById(id, assertPresent = true) {
62
+ const value = this.get(id);
63
+ if (!value) {
64
+ if (assertPresent) throw new Error(`Value not found`);
65
+ return;
66
+ }
67
+ return this.delete(value);
68
+ }
69
+ delete(value) {
70
+ const index = this.firstIndex(value);
71
+ if (index < 0 || index >= this.array.length || this.key.key(value) !== this.key.key(this.array[index])) {
72
+ return null;
73
+ }
74
+ delete this.dict[this.idGetter(value)];
75
+ return this.array.splice(index, 1)[0];
76
+ }
77
+ slice(start, end) {
78
+ const db = new KeyedDB(this.key, this.idGetter);
79
+ db.array = this.array.slice(start, end);
80
+ db.array.forEach(item => db.dict[this.idGetter(item)] = item);
81
+ return db;
82
+ }
83
+ clear() {
84
+ this.array = [];
85
+ this.dict = {};
86
+ }
87
+ get(id) {
88
+ return this.dict[id];
89
+ }
90
+ all() {
91
+ return this.array;
92
+ }
93
+ update(id, update) {
94
+ const value = this.get(id);
95
+ if (value) {
96
+ const idx = this.firstIndex(value);
97
+ if (idx >= 0 && idx < this.array.length && this.idGetter(this.array[idx]) === id) {
98
+ const oldKey = this.key.key(value);
99
+ update(value);
100
+ const newKey = this.key.key(value);
101
+ if (newKey !== oldKey) {
102
+ delete this.dict[id];
103
+ this.array.splice(idx, 1);
104
+ this._insertSingle(value);
105
+ return 2;
106
+ }
107
+ return 1;
108
+ }
109
+ }
110
+ }
111
+ updateKey(value, update) {
112
+ return this.update(this.idGetter(value), update);
113
+ }
114
+ filter(predicate) {
115
+ const db = new KeyedDB(this.key, this.idGetter);
116
+ db.array = this.array.filter((value, index) => {
117
+ if (predicate(value, index)) {
118
+ db.dict[this.idGetter(value)] = value;
119
+ return true;
120
+ }
121
+ });
122
+ return db;
123
+ }
124
+ paginatedByValue(value, limit, predicate, mode = "after") {
125
+ return this.paginated(value && this.key.key(value), limit, predicate, mode);
126
+ }
127
+ paginated(cursor, limit, predicate, mode = "after") {
128
+ let index = mode === "after" ? 0 : this.array.length;
129
+ if (cursor !== null && typeof cursor !== "undefined") {
130
+ index = binarySearch(this.array, v => this.key.compare(cursor, this.key.key(v)));
131
+ if (index < 0) index = 0;
132
+ if (this.key.key(this.array[index]) === cursor) index += (mode === "after" ? 1 : 0);
133
+ }
134
+ return this.filtered(index, limit, mode, predicate);
135
+ }
136
+ _insertSingle(value) {
137
+ if (!value) throw new Error("falsey value");
138
+ const valueID = this.idGetter(value);
139
+ if (this.get(valueID)) throw new Error("duplicate ID being inserted: " + valueID);
140
+
141
+ if (this.array.length > 0) {
142
+ const index = this.firstIndex(value);
143
+ if (index >= this.array.length) this.array.push(value);
144
+ else if (index < 0) this.array.unshift(value);
145
+ else if (this.key.key(value) !== this.key.key(this.array[index])) this.array.splice(index, 0, value);
146
+ else throw new Error(`duplicate key: ${this.key.key(value)}, inserting: ${valueID}, present: ${this.idGetter(this.array[index])}`);
147
+ } else {
148
+ this.array.push(value);
149
+ }
150
+ this.dict[valueID] = value;
151
+ }
152
+ filtered(start, count, mode, predicate) {
153
+ let arr;
154
+ if (mode === "after") {
155
+ if (predicate) {
156
+ arr = [];
157
+ for (let item of this.array.slice(start)) {
158
+ predicate(item, start + arr.length) && arr.push(item);
159
+ if (arr.length >= count) break;
160
+ }
161
+ } else arr = this.array.slice(start, start + count);
162
+ } else if (mode === "before") {
163
+ if (predicate) {
164
+ arr = [];
165
+ for (let i = start - 1; i >= 0; i--) {
166
+ let item = this.array[i];
167
+ predicate(item, start + arr.length) && arr.unshift(item);
168
+ if (arr.length >= count) break;
169
+ }
170
+ } else arr = this.array.slice(Math.max(start - count, 0), start);
171
+ }
172
+ return arr;
173
+ }
174
+ firstIndex(value) {
175
+ const valueKey = this.key.key(value);
176
+ return binarySearch(this.array, v => this.key.compare(valueKey, this.key.key(v)));
177
+ }
178
+ }
@@ -0,0 +1,14 @@
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+ export * from "./BinarySearch.js"
14
+ export * from "./KeyedDB.js"
@@ -1,15 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CiphertextMessage = void 0;
4
- class CiphertextMessage {
5
- constructor() {
6
- this.UNSUPPORTED_VERSION = 1;
7
- this.CURRENT_VERSION = 3;
8
- this.WHISPER_TYPE = 2;
9
- this.PREKEY_TYPE = 3;
10
- this.SENDERKEY_TYPE = 4;
11
- this.SENDERKEY_DISTRIBUTION_TYPE = 5;
12
- this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
13
- }
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+ export class CiphertextMessage {
14
+ constructor() {
15
+ this.UNSUPPORTED_VERSION = 1;
16
+ this.CURRENT_VERSION = 3;
17
+ this.WHISPER_TYPE = 2;
18
+ this.PREKEY_TYPE = 3;
19
+ this.SENDERKEY_TYPE = 4;
20
+ this.SENDERKEY_DISTRIBUTION_TYPE = 5;
21
+ this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
22
+ }
14
23
  }
15
- exports.CiphertextMessage = CiphertextMessage;
@@ -1,42 +1,21 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.GroupSessionBuilder = void 0;
37
- const keyhelper = __importStar(require("./keyhelper"));
38
- const sender_key_distribution_message_1 = require("./sender-key-distribution-message");
39
- class GroupSessionBuilder {
1
+ //========================================//
2
+ /**
3
+ * @project @sixcore/baileys
4
+ * @author Sixx.js </>🌿
5
+ * @version 1.0.3
6
+ * @license MIT
7
+ * @country Mozambique 🇲🇿♥️
8
+ * @chamadas || sms +258860817689
9
+ * @whatsApp +55889616-2417 || +258851907875
10
+ * @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
11
+ */
12
+
13
+ import { SenderKeyDistributionMessage } from "./sender-key-distribution-message.js";
14
+ import { SenderKeyRecord } from "./sender-key-record.js";
15
+ import { SenderKeyName } from "./sender-key-name.js";
16
+ import * as keyhelper from "./keyhelper.js";
17
+
18
+ export class GroupSessionBuilder {
40
19
  constructor(senderKeyStore) {
41
20
  this.senderKeyStore = senderKeyStore;
42
21
  }
@@ -56,9 +35,9 @@ class GroupSessionBuilder {
56
35
  }
57
36
  const state = senderKeyRecord.getSenderKeyState();
58
37
  if (!state) {
59
- throw new Error('No session state available');
38
+ throw new Error("No session state available");
60
39
  }
61
- return new sender_key_distribution_message_1.SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
40
+ return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
62
41
  }
63
42
  }
64
- exports.GroupSessionBuilder = GroupSessionBuilder;
43
+ //# sourceMappingURL=group-session-builder.js.map