dct-dev-private-baileys 1.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 (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.MD +110 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +5619 -0
  5. package/WAProto/index.js +169661 -0
  6. package/engine-requirements.js +10 -0
  7. package/lib/Api/Internet/growagarden.js +30 -0
  8. package/lib/Api/creator.json +12 -0
  9. package/lib/Api/downloader/tiktokdownload.js +132 -0
  10. package/lib/Api/index.js +38 -0
  11. package/lib/Api/nsfw/loli.js +79 -0
  12. package/lib/Api/stalker/githubstalk.js +46 -0
  13. package/lib/Api/stalker/stalkroblox.js +94 -0
  14. package/lib/Api/stalker/tiktokstalk.js +68 -0
  15. package/lib/Api/tools/ssweb.js +38 -0
  16. package/lib/Defaults/baileys-version.json +3 -0
  17. package/lib/Defaults/index.js +122 -0
  18. package/lib/Defaults/phonenumber_mcc.json +223 -0
  19. package/lib/Signal/Group/ciphertext-message.js +15 -0
  20. package/lib/Signal/Group/group-session-builder.js +64 -0
  21. package/lib/Signal/Group/group_cipher.js +96 -0
  22. package/lib/Signal/Group/index.js +57 -0
  23. package/lib/Signal/Group/keyhelper.js +55 -0
  24. package/lib/Signal/Group/queue-job.js +57 -0
  25. package/lib/Signal/Group/sender-chain-key.js +34 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  27. package/lib/Signal/Group/sender-key-message.js +69 -0
  28. package/lib/Signal/Group/sender-key-name.js +51 -0
  29. package/lib/Signal/Group/sender-key-record.js +53 -0
  30. package/lib/Signal/Group/sender-key-state.js +99 -0
  31. package/lib/Signal/Group/sender-message-key.js +29 -0
  32. package/lib/Signal/libsignal.js +174 -0
  33. package/lib/Socket/Client/index.js +18 -0
  34. package/lib/Socket/Client/types.js +13 -0
  35. package/lib/Socket/Client/websocket.js +111 -0
  36. package/lib/Socket/Thandler.js +501 -0
  37. package/lib/Socket/business.js +266 -0
  38. package/lib/Socket/chats.js +1138 -0
  39. package/lib/Socket/communities.js +441 -0
  40. package/lib/Socket/groups.js +332 -0
  41. package/lib/Socket/index.js +43 -0
  42. package/lib/Socket/messages-recv.js +1538 -0
  43. package/lib/Socket/messages-send.js +1207 -0
  44. package/lib/Socket/newsletter.js +379 -0
  45. package/lib/Socket/socket.js +849 -0
  46. package/lib/Socket/usync.js +70 -0
  47. package/lib/Store/index.js +8 -0
  48. package/lib/Store/make-in-memory-store.js +533 -0
  49. package/lib/Store/make-ordered-dictionary.js +81 -0
  50. package/lib/Store/object-repository.js +27 -0
  51. package/lib/Types/Auth.js +2 -0
  52. package/lib/Types/Call.js +2 -0
  53. package/lib/Types/Chat.js +4 -0
  54. package/lib/Types/Contact.js +2 -0
  55. package/lib/Types/Events.js +2 -0
  56. package/lib/Types/GroupMetadata.js +2 -0
  57. package/lib/Types/Label.js +27 -0
  58. package/lib/Types/LabelAssociation.js +9 -0
  59. package/lib/Types/Message.js +7 -0
  60. package/lib/Types/Newsletter.js +18 -0
  61. package/lib/Types/Product.js +2 -0
  62. package/lib/Types/Signal.js +2 -0
  63. package/lib/Types/Socket.js +2 -0
  64. package/lib/Types/State.js +2 -0
  65. package/lib/Types/USync.js +2 -0
  66. package/lib/Types/index.js +42 -0
  67. package/lib/Utils/async-iterable.js +40 -0
  68. package/lib/Utils/audioToBuffer.js +29 -0
  69. package/lib/Utils/auth-utils.js +200 -0
  70. package/lib/Utils/baileys-event-stream.js +67 -0
  71. package/lib/Utils/browser-utils.js +35 -0
  72. package/lib/Utils/business.js +234 -0
  73. package/lib/Utils/chat-utils.js +730 -0
  74. package/lib/Utils/crypto.js +193 -0
  75. package/lib/Utils/decode-wa-message.js +207 -0
  76. package/lib/Utils/event-buffer.js +565 -0
  77. package/lib/Utils/generics.js +432 -0
  78. package/lib/Utils/history.js +94 -0
  79. package/lib/Utils/index.js +36 -0
  80. package/lib/Utils/link-preview.js +126 -0
  81. package/lib/Utils/logger.js +7 -0
  82. package/lib/Utils/lt-hash.js +51 -0
  83. package/lib/Utils/make-mutex.js +43 -0
  84. package/lib/Utils/message-retry-manager.js +128 -0
  85. package/lib/Utils/messages-media.js +926 -0
  86. package/lib/Utils/messages.js +1105 -0
  87. package/lib/Utils/noise-handler.js +150 -0
  88. package/lib/Utils/process-message.js +404 -0
  89. package/lib/Utils/resolveJid.js +48 -0
  90. package/lib/Utils/signal.js +153 -0
  91. package/lib/Utils/streamToBuffer.js +15 -0
  92. package/lib/Utils/use-multi-file-auth-state.js +122 -0
  93. package/lib/Utils/validate-connection.js +229 -0
  94. package/lib/WABinary/constants.js +1303 -0
  95. package/lib/WABinary/decode.js +265 -0
  96. package/lib/WABinary/encode.js +250 -0
  97. package/lib/WABinary/generic-utils.js +110 -0
  98. package/lib/WABinary/index.js +21 -0
  99. package/lib/WABinary/jid-utils.js +85 -0
  100. package/lib/WABinary/types.js +2 -0
  101. package/lib/WAM/BinaryInfo.js +13 -0
  102. package/lib/WAM/constants.js +15350 -0
  103. package/lib/WAM/encode.js +155 -0
  104. package/lib/WAM/index.js +19 -0
  105. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  106. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  107. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  108. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  109. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  110. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  111. package/lib/WAUSync/Protocols/index.js +20 -0
  112. package/lib/WAUSync/USyncQuery.js +89 -0
  113. package/lib/WAUSync/USyncUser.js +26 -0
  114. package/lib/WAUSync/index.js +19 -0
  115. package/lib/index.js +91 -0
  116. package/package.json +127 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectRepository = void 0;
4
+ class ObjectRepository {
5
+ constructor(entities = {}) {
6
+ this.entityMap = new Map(Object.entries(entities));
7
+ }
8
+ findById(id) {
9
+ return this.entityMap.get(id);
10
+ }
11
+ findAll() {
12
+ return Array.from(this.entityMap.values());
13
+ }
14
+ upsertById(id, entity) {
15
+ return this.entityMap.set(id, { ...entity });
16
+ }
17
+ deleteById(id) {
18
+ return this.entityMap.delete(id);
19
+ }
20
+ count() {
21
+ return this.entityMap.size;
22
+ }
23
+ toJSON() {
24
+ return this.findAll();
25
+ }
26
+ }
27
+ exports.ObjectRepository = ObjectRepository;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_WA_PATCH_NAMES = void 0;
4
+ exports.ALL_WA_PATCH_NAMES = ['critical_block', 'critical_unblock_low', 'regular_high', 'regular_low', 'regular'];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelColor = void 0;
4
+ /** WhatsApp has 20 predefined colors */
5
+ var LabelColor;
6
+ (function (LabelColor) {
7
+ LabelColor[LabelColor["Color1"] = 0] = "Color1";
8
+ LabelColor[LabelColor["Color2"] = 1] = "Color2";
9
+ LabelColor[LabelColor["Color3"] = 2] = "Color3";
10
+ LabelColor[LabelColor["Color4"] = 3] = "Color4";
11
+ LabelColor[LabelColor["Color5"] = 4] = "Color5";
12
+ LabelColor[LabelColor["Color6"] = 5] = "Color6";
13
+ LabelColor[LabelColor["Color7"] = 6] = "Color7";
14
+ LabelColor[LabelColor["Color8"] = 7] = "Color8";
15
+ LabelColor[LabelColor["Color9"] = 8] = "Color9";
16
+ LabelColor[LabelColor["Color10"] = 9] = "Color10";
17
+ LabelColor[LabelColor["Color11"] = 10] = "Color11";
18
+ LabelColor[LabelColor["Color12"] = 11] = "Color12";
19
+ LabelColor[LabelColor["Color13"] = 12] = "Color13";
20
+ LabelColor[LabelColor["Color14"] = 13] = "Color14";
21
+ LabelColor[LabelColor["Color15"] = 14] = "Color15";
22
+ LabelColor[LabelColor["Color16"] = 15] = "Color16";
23
+ LabelColor[LabelColor["Color17"] = 16] = "Color17";
24
+ LabelColor[LabelColor["Color18"] = 17] = "Color18";
25
+ LabelColor[LabelColor["Color19"] = 18] = "Color19";
26
+ LabelColor[LabelColor["Color20"] = 19] = "Color20";
27
+ })(LabelColor || (exports.LabelColor = LabelColor = {}));
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelAssociationType = void 0;
4
+ /** Association type */
5
+ var LabelAssociationType;
6
+ (function (LabelAssociationType) {
7
+ LabelAssociationType["Chat"] = "label_jid";
8
+ LabelAssociationType["Message"] = "label_message";
9
+ })(LabelAssociationType || (exports.LabelAssociationType = LabelAssociationType = {}));
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WAMessageStatus = exports.WAMessageStubType = exports.WAProto = void 0;
4
+ const WAProto_1 = require("../../WAProto");
5
+ Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () { return WAProto_1.proto; } });
6
+ exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
7
+ exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XWAPaths = exports.MexOperations = void 0;
4
+ var MexOperations;
5
+ (function (MexOperations) {
6
+ MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
7
+ MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
8
+ MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
9
+ })(MexOperations || (exports.MexOperations = MexOperations = {}));
10
+ var XWAPaths;
11
+ (function (XWAPaths) {
12
+ XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
13
+ XWAPaths["DEMOTE"] = "xwa2_notify_newsletter_admin_demote";
14
+ XWAPaths["ADMIN_COUNT"] = "xwa2_newsletter_admin";
15
+ XWAPaths["CREATE"] = "xwa2_newsletter_create";
16
+ XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
+ XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
+ })(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,42 @@
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
+ exports.DisconnectReason = void 0;
18
+ __exportStar(require("./Auth"), exports);
19
+ __exportStar(require("./GroupMetadata"), exports);
20
+ __exportStar(require("./Newsletter"), exports);
21
+ __exportStar(require("./Chat"), exports);
22
+ __exportStar(require("./Contact"), exports);
23
+ __exportStar(require("./State"), exports);
24
+ __exportStar(require("./Message"), exports);
25
+ __exportStar(require("./Socket"), exports);
26
+ __exportStar(require("./Events"), exports);
27
+ __exportStar(require("./Product"), exports);
28
+ __exportStar(require("./Call"), exports);
29
+ __exportStar(require("./Signal"), exports);
30
+ var DisconnectReason;
31
+ (function (DisconnectReason) {
32
+ DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
33
+ DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
34
+ DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
35
+ DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
36
+ DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
37
+ DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
38
+ DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
39
+ DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
+ DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
+ DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
+ })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toAsyncIterable = void 0;
4
+
5
+ /**
6
+ * Helper by @thehackingguard to convert various media inputs into an Async Iterable
7
+ * Compatible with Baileys buffer/stream handling
8
+ */
9
+ function toAsyncIterable(input) {
10
+ if (!input) {
11
+ throw new Error("Invalid media stream (undefined/null)");
12
+ }
13
+
14
+ if (input[Symbol.asyncIterator]) {
15
+ return input;
16
+ }
17
+
18
+ if (Buffer.isBuffer(input)) {
19
+ return (async function* () {
20
+ yield input;
21
+ })();
22
+ }
23
+
24
+ if (typeof input === "string") {
25
+ const fs = require("fs");
26
+ return fs.createReadStream(input);
27
+ }
28
+
29
+ if (typeof input.on === "function") {
30
+ return (async function* () {
31
+ for await (const chunk of input) {
32
+ yield chunk;
33
+ }
34
+ })();
35
+ }
36
+
37
+ throw new Error("Unsupported media stream type");
38
+ }
39
+
40
+ exports.toAsyncIterable = toAsyncIterable;
@@ -0,0 +1,29 @@
1
+ const { Buffer } = require("buffer")
2
+ const fs = require("fs/promises")
3
+ const { Readable } = require("stream")
4
+ const streamToBuffer = require("./streamToBuffer")
5
+
6
+ /**
7
+ * Mengonversi berbagai input audio (Buffer, URL, path file, atau Readable stream) menjadi Buffer.
8
+ * @param {Buffer|string|Readable} audio Input audio.
9
+ * @returns {Promise<Buffer>} Buffer hasil konversi.
10
+ */
11
+ async function audioToBuffer(audio) {
12
+ if (Buffer.isBuffer(audio)) {
13
+ return audio
14
+ }
15
+
16
+ if (typeof audio === "string") {
17
+ if (/^https?:\/\//.test(audio)) {
18
+ const res = await fetch(audio) // native fetch bawaan Node 20
19
+ return Buffer.from(await res.arrayBuffer())
20
+ }
21
+ return fs.readFile(audio)
22
+ }
23
+
24
+ if (audio instanceof Readable) {
25
+ return streamToBuffer(audio)
26
+ }
27
+
28
+ throw new TypeError("Unsupported audio input type")
29
+ }
@@ -0,0 +1,200 @@
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.initAuthCreds = exports.addTransactionCapability = void 0;
7
+ exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
8
+ const crypto_1 = require("crypto");
9
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
10
+ const Defaults_1 = require("../Defaults");
11
+ const crypto_2 = require("./crypto");
12
+ const generics_1 = require("./generics");
13
+ /**
14
+ * Adds caching capability to a SignalKeyStore
15
+ * @param store the store to add caching to
16
+ * @param logger to log trace events
17
+ * @param _cache cache store to use
18
+ */
19
+ function makeCacheableSignalKeyStore(store, logger, _cache) {
20
+ const cache = _cache || new node_cache_1.default({
21
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
22
+ useClones: false,
23
+ deleteOnExpire: true,
24
+ max: 10000
25
+ });
26
+ function getUniqueId(type, id) {
27
+ return `${type}.${id}`;
28
+ }
29
+ return {
30
+ async get(type, ids) {
31
+ const data = {};
32
+ const idsToFetch = [];
33
+ for (const id of ids) {
34
+ const item = cache.get(getUniqueId(type, id));
35
+ if (typeof item !== 'undefined') {
36
+ data[id] = item;
37
+ }
38
+ else {
39
+ idsToFetch.push(id);
40
+ }
41
+ }
42
+ if (idsToFetch.length) {
43
+ logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
44
+ const fetched = await store.get(type, idsToFetch);
45
+ for (const id of idsToFetch) {
46
+ const item = fetched[id];
47
+ if (item) {
48
+ data[id] = item;
49
+ cache.set(getUniqueId(type, id), item);
50
+ }
51
+ }
52
+ }
53
+ return data;
54
+ },
55
+ async set(data) {
56
+ let keys = 0;
57
+ for (const type in data) {
58
+ for (const id in data[type]) {
59
+ cache.set(getUniqueId(type, id), data[type][id]);
60
+ keys += 1;
61
+ }
62
+ }
63
+ logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
64
+ await store.set(data);
65
+ },
66
+ async clear() {
67
+ var _a;
68
+ cache.flushAll();
69
+ await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
70
+ }
71
+ };
72
+ }
73
+ /**
74
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
75
+ * this allows batch read & write operations & improves the performance of the lib
76
+ * @param state the key store to apply this capability to
77
+ * @param logger logger to log events
78
+ * @returns SignalKeyStore with transaction capability
79
+ */
80
+ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
81
+ // number of queries made to the DB during the transaction
82
+ // only there for logging purposes
83
+ let dbQueriesInTransaction = 0;
84
+ let transactionCache = {};
85
+ let mutations = {};
86
+ let transactionsInProgress = 0;
87
+ return {
88
+ get: async (type, ids) => {
89
+ if (isInTransaction()) {
90
+ const dict = transactionCache[type];
91
+ const idsRequiringFetch = dict
92
+ ? ids.filter(item => typeof dict[item] === 'undefined')
93
+ : ids;
94
+ // only fetch if there are any items to fetch
95
+ if (idsRequiringFetch.length) {
96
+ dbQueriesInTransaction += 1;
97
+ const result = await state.get(type, idsRequiringFetch);
98
+ transactionCache[type] || (transactionCache[type] = {});
99
+ Object.assign(transactionCache[type], result);
100
+ }
101
+ return ids.reduce((dict, id) => {
102
+ var _a;
103
+ const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
104
+ if (value) {
105
+ dict[id] = value;
106
+ }
107
+ return dict;
108
+ }, {});
109
+ }
110
+ else {
111
+ return state.get(type, ids);
112
+ }
113
+ },
114
+ set: data => {
115
+ if (isInTransaction()) {
116
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction');
117
+ for (const key in data) {
118
+ transactionCache[key] = transactionCache[key] || {};
119
+ Object.assign(transactionCache[key], data[key]);
120
+ mutations[key] = mutations[key] || {};
121
+ Object.assign(mutations[key], data[key]);
122
+ }
123
+ }
124
+ else {
125
+ return state.set(data);
126
+ }
127
+ },
128
+ isInTransaction,
129
+ async transaction(work) {
130
+ let result;
131
+ transactionsInProgress += 1;
132
+ if (transactionsInProgress === 1) {
133
+ logger.trace('entering transaction');
134
+ }
135
+ try {
136
+ result = await work();
137
+ // commit if this is the outermost transaction
138
+ if (transactionsInProgress === 1) {
139
+ if (Object.keys(mutations).length) {
140
+ logger.trace('committing transaction');
141
+ // retry mechanism to ensure we've some recovery
142
+ // in case a transaction fails in the first attempt
143
+ let tries = maxCommitRetries;
144
+ while (tries) {
145
+ tries -= 1;
146
+ try {
147
+ await state.set(mutations);
148
+ logger.trace({ dbQueriesInTransaction }, 'committed transaction');
149
+ break;
150
+ }
151
+ catch (error) {
152
+ logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
153
+ await (0, generics_1.delay)(delayBetweenTriesMs);
154
+ }
155
+ }
156
+ }
157
+ else {
158
+ logger.trace('no mutations in transaction');
159
+ }
160
+ }
161
+ }
162
+ finally {
163
+ transactionsInProgress -= 1;
164
+ if (transactionsInProgress === 0) {
165
+ transactionCache = {};
166
+ mutations = {};
167
+ dbQueriesInTransaction = 0;
168
+ }
169
+ }
170
+ return result;
171
+ }
172
+ };
173
+ function isInTransaction() {
174
+ return transactionsInProgress > 0;
175
+ }
176
+ };
177
+ exports.addTransactionCapability = addTransactionCapability;
178
+ const initAuthCreds = () => {
179
+ const identityKey = crypto_2.Curve.generateKeyPair();
180
+ return {
181
+ noiseKey: crypto_2.Curve.generateKeyPair(),
182
+ pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
183
+ signedIdentityKey: identityKey,
184
+ signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
185
+ registrationId: (0, generics_1.generateRegistrationId)(),
186
+ advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
187
+ processedHistoryMessages: [],
188
+ nextPreKeyId: 1,
189
+ firstUnuploadedPreKeyId: 1,
190
+ accountSyncCounter: 0,
191
+ accountSettings: {
192
+ unarchiveChats: false
193
+ },
194
+ registered: false,
195
+ pairingCode: undefined,
196
+ lastPropHash: undefined,
197
+ routingInfo: undefined,
198
+ };
199
+ };
200
+ exports.initAuthCreds = initAuthCreds;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.readAndEmitEventStream = exports.captureEventStream = void 0;
9
+ const events_1 = __importDefault(require("events"));
10
+ const fs_1 = require("fs");
11
+ const promises_1 = require("fs/promises");
12
+ const readline_1 = require("readline");
13
+ const generics_1 = require("./generics");
14
+ const make_mutex_1 = require("./make-mutex");
15
+ /**
16
+ * Captures events from a Thehackingguard event emitter & stores them in a file
17
+ * @param ev The event emitter to read events from
18
+ * @param filename File to save to
19
+ */
20
+ const captureEventStream = (ev, filename) => {
21
+ const oldEmit = ev.emit;
22
+ // write mutex so data is appended in order
23
+ const writeMutex = (0, make_mutex_1.makeMutex)();
24
+ // monkey patch eventemitter to capture all events
25
+ ev.emit = function (...args) {
26
+ const content =
27
+ JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) +
28
+ "\n";
29
+ const result = oldEmit.apply(ev, args);
30
+ writeMutex.mutex(async () => {
31
+ await (0, promises_1.writeFile)(filename, content, { flag: "a" });
32
+ });
33
+ return result;
34
+ };
35
+ };
36
+ exports.captureEventStream = captureEventStream;
37
+ /**
38
+ * Read event file and emit events from there
39
+ * @param filename filename containing event data
40
+ * @param delayIntervalMs delay between each event emit
41
+ */
42
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
43
+ const ev = new events_1.default();
44
+ const fireEvents = async () => {
45
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
46
+ const fileStream = (0, fs_1.createReadStream)(filename);
47
+ const rl = (0, readline_1.createInterface)({
48
+ input: fileStream,
49
+ crlfDelay: Infinity,
50
+ });
51
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
52
+ // ('\r\n') in input.txt as a single line break.
53
+ for await (const line of rl) {
54
+ if (line) {
55
+ const { event, data } = JSON.parse(line);
56
+ ev.emit(event, data);
57
+ delayIntervalMs && (await (0, generics_1.delay)(delayIntervalMs));
58
+ }
59
+ }
60
+ fileStream.close();
61
+ };
62
+ return {
63
+ ev,
64
+ task: fireEvents(),
65
+ };
66
+ };
67
+ exports.readAndEmitEventStream = readAndEmitEventStream;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPlatformId = exports.Browsers = void 0;
4
+
5
+ const os = require("os");
6
+ const { proto } = require("../../WAProto/index.js");
7
+
8
+ const PLATFORM_MAP = {
9
+ 'aix': 'AIX',
10
+ 'darwin': 'Mac OS',
11
+ 'win32': 'Windows',
12
+ 'android': 'Android',
13
+ 'freebsd': 'FreeBSD',
14
+ 'openbsd': 'OpenBSD',
15
+ 'sunos': 'Solaris',
16
+ 'linux': undefined, // Default ke Ubuntu untuk Linux
17
+ 'haiku': undefined,
18
+ 'cygwin': undefined,
19
+ 'netbsd': undefined
20
+ };
21
+
22
+ // Fixed: Browsers sekarang fungsi yang return array [platform, browser, version]
23
+ // Ini kompatibel dengan pemanggilan Browsers('Chrome') di Defaults/index.js
24
+ exports.Browsers = (browser) => {
25
+ const osName = PLATFORM_MAP[os.platform()] || 'Ubuntu'; // Default Ubuntu kalau undefined
26
+ const osRelease = os.release(); // Ambil versi OS real-time
27
+ return [osName, browser, osRelease];
28
+ };
29
+
30
+ const getPlatformId = (browser) => {
31
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
32
+ return platformType ? platformType.toString() : '1'; // Default Chrome
33
+ };
34
+
35
+ exports.getPlatformId = getPlatformId;