socketon 0.31.0 → 1.51.16
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.
- package/README.md +313 -159
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +65801 -141371
- package/lib/Defaults/index.js +117 -141
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -14
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +75 -87
- package/lib/Signal/Group/index.js +13 -57
- package/lib/Signal/Group/keyhelper.js +17 -52
- package/lib/Signal/Group/sender-chain-key.js +27 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
- package/lib/Signal/Group/sender-key-message.js +65 -66
- package/lib/Signal/Group/sender-key-name.js +45 -44
- package/lib/Signal/Group/sender-key-record.js +39 -49
- package/lib/Signal/Group/sender-key-state.js +80 -93
- package/lib/Signal/Group/sender-message-key.js +27 -28
- package/lib/Signal/libsignal.js +313 -163
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +846 -935
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -309
- package/lib/Socket/index.js +15 -10
- package/lib/Socket/messages-recv.js +1107 -1054
- package/lib/Socket/messages-send.js +639 -448
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +270 -282
- package/lib/Socket/socket.js +798 -635
- package/lib/Socket/socketon.js +402 -0
- package/lib/Store/index.js +6 -10
- package/lib/Store/make-cache-manager-store.js +73 -81
- package/lib/Store/make-in-memory-store.js +286 -423
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -198
- package/lib/Utils/baileys-event-stream.js +42 -61
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +710 -687
- package/lib/Utils/crypto.js +112 -133
- package/lib/Utils/decode-wa-message.js +252 -183
- package/lib/Utils/decode-wa-message.js.bak +267 -0
- package/lib/Utils/event-buffer.js +510 -496
- package/lib/Utils/generics.js +319 -464
- package/lib/Utils/history.js +83 -92
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/link-preview.js +71 -83
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +550 -768
- package/lib/Utils/messages.js +385 -261
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +323 -303
- package/lib/Utils/signal.js +149 -141
- package/lib/Utils/use-multi-file-auth-state.js +95 -103
- package/lib/Utils/validate-connection.js +183 -212
- package/lib/WABinary/constants.js +1298 -35
- package/lib/WABinary/decode.js +237 -249
- package/lib/WABinary/encode.js +213 -260
- package/lib/WABinary/generic-utils.js +56 -65
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +89 -58
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +27 -36
- package/package.json +61 -85
- package/engine-requirements.js +0 -10
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Socket/dugong.js +0 -484
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
package/lib/Utils/generics.js
CHANGED
|
@@ -1,500 +1,355 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { getAllBinaryNodeChildren, jidDecode } from "../WABinary/index.js";
|
|
3
|
+
import { DisconnectReason } from "../Types/index.js";
|
|
4
|
+
import { createHash, randomBytes } from "crypto";
|
|
5
|
+
import { proto } from "../../WAProto/index.js";
|
|
6
|
+
import { version } from "../Defaults/index.js"
|
|
7
|
+
import { sha256 } from "./crypto.js";
|
|
8
|
+
import { Boom } from "@hapi/boom";
|
|
9
|
+
//=======================================================//
|
|
10
|
+
export const BufferJSON = {
|
|
11
|
+
replacer: (k, value) => {
|
|
12
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === "Buffer") {
|
|
13
|
+
return { type: "Buffer", data: Buffer.from(value?.data || value).toString("base64") };
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
},
|
|
17
|
+
reviver: (_, value) => {
|
|
18
|
+
if (typeof value === "object" && value !== null && value.type === "Buffer" && typeof value.data === "string") {
|
|
19
|
+
return Buffer.from(value.data, "base64");
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
22
|
+
const keys = Object.keys(value);
|
|
23
|
+
if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
|
|
24
|
+
const values = Object.values(value);
|
|
25
|
+
if (values.every(v => typeof v === "number")) {
|
|
26
|
+
return Buffer.from(values);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
4
32
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const fetch_1 = require("node-fetch");
|
|
12
|
-
|
|
13
|
-
const WAProto_1 = require("../../WAProto");
|
|
14
|
-
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
15
|
-
const Types_1 = require("../Types");
|
|
16
|
-
const WABinary_1 = require("../WABinary");
|
|
17
|
-
const baileysVersion = [2, 3000, 1027934701]
|
|
18
|
-
const PLATFORM_MAP = {
|
|
19
|
-
'aix': 'AIX',
|
|
20
|
-
'darwin': 'Mac OS',
|
|
21
|
-
'win32': 'Windows',
|
|
22
|
-
'android': 'Android',
|
|
23
|
-
'freebsd': 'FreeBSD',
|
|
24
|
-
'openbsd': 'OpenBSD',
|
|
25
|
-
'sunos': 'Solaris',
|
|
26
|
-
'linux': undefined,
|
|
27
|
-
'haiku': undefined,
|
|
28
|
-
'cygwin': undefined,
|
|
29
|
-
'netbsd': undefined
|
|
33
|
+
//=======================================================//
|
|
34
|
+
export const getKeyAuthor = (key, meId = "me") => (key?.fromMe ? meId : key?.participant || key?.remoteJid) || "";
|
|
35
|
+
export const writeRandomPadMax16 = (msg) => {
|
|
36
|
+
const pad = randomBytes(1);
|
|
37
|
+
const padLength = (pad[0] & 0x0f) + 1;
|
|
38
|
+
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
30
39
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
//=======================================================//
|
|
41
|
+
export const unpadRandomMax16 = (e) => {
|
|
42
|
+
const t = new Uint8Array(e);
|
|
43
|
+
if (0 === t.length) {
|
|
44
|
+
throw new Error("unpadPkcs7 given empty bytes");
|
|
45
|
+
}
|
|
46
|
+
var r = t[t.length - 1];
|
|
47
|
+
if (r > t.length) {
|
|
48
|
+
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
49
|
+
}
|
|
50
|
+
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
35
51
|
};
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
//=======================================================//
|
|
53
|
+
export const generateParticipantHashV2 = (participants) => {
|
|
54
|
+
participants.sort();
|
|
55
|
+
const sha256Hash = sha256(Buffer.from(participants.join(""))).toString("base64");
|
|
56
|
+
return "2:" + sha256Hash.slice(0, 6);
|
|
40
57
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
//=======================================================//
|
|
59
|
+
export const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
|
|
60
|
+
export const generateRegistrationId = () => {
|
|
61
|
+
return Uint16Array.from(randomBytes(2))[0] & 16383;
|
|
62
|
+
};
|
|
63
|
+
//=======================================================//
|
|
64
|
+
export const encodeBigEndian = (e, t = 4) => {
|
|
65
|
+
let r = e;
|
|
66
|
+
const a = new Uint8Array(t);
|
|
67
|
+
for (let i = t - 1; i >= 0; i--) {
|
|
68
|
+
a[i] = 255 & r;
|
|
69
|
+
r >>>= 8;
|
|
70
|
+
}
|
|
71
|
+
return a;
|
|
72
|
+
};
|
|
73
|
+
export const toNumber = (t) => typeof t === "object" && t ? ("toNumber" in t ? t.toNumber() : t.low) : t || 0;
|
|
74
|
+
//=======================================================//
|
|
75
|
+
export const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
76
|
+
export const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
77
|
+
let timeout;
|
|
78
|
+
return {
|
|
79
|
+
start: (newIntervalMs, newTask) => {
|
|
80
|
+
task = newTask || task;
|
|
81
|
+
intervalMs = newIntervalMs || intervalMs;
|
|
82
|
+
timeout && clearTimeout(timeout);
|
|
83
|
+
timeout = setTimeout(() => task?.(), intervalMs);
|
|
48
84
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
85
|
+
cancel: () => {
|
|
86
|
+
timeout && clearTimeout(timeout);
|
|
87
|
+
timeout = undefined;
|
|
88
|
+
},
|
|
89
|
+
setTask: (newTask) => (task = newTask),
|
|
90
|
+
setInterval: (newInterval) => (intervalMs = newInterval)
|
|
91
|
+
};
|
|
56
92
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
93
|
+
//=======================================================//
|
|
94
|
+
export const delay = (ms) => delayCancellable(ms).delay;
|
|
95
|
+
export const delayCancellable = (ms) => {
|
|
96
|
+
const stack = new Error().stack;
|
|
97
|
+
let timeout;
|
|
98
|
+
let reject;
|
|
99
|
+
const delay = new Promise((resolve, _reject) => {
|
|
100
|
+
timeout = setTimeout(resolve, ms);
|
|
101
|
+
reject = _reject;
|
|
102
|
+
});
|
|
103
|
+
const cancel = () => {
|
|
104
|
+
clearTimeout(timeout);
|
|
105
|
+
reject(new Boom("Cancelled", {
|
|
106
|
+
statusCode: 500,
|
|
107
|
+
data: {
|
|
108
|
+
stack
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
};
|
|
112
|
+
return { delay, cancel };
|
|
113
|
+
};
|
|
114
|
+
//=======================================================//
|
|
115
|
+
export async function promiseTimeout(ms, promise) {
|
|
116
|
+
return new Promise(promise);
|
|
117
|
+
}
|
|
118
|
+
//=======================================================//
|
|
119
|
+
export const generateMessageIDV2 = (userId) => {
|
|
120
|
+
const data = Buffer.alloc(8 + 20 + 16);
|
|
121
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
122
|
+
if (userId) {
|
|
123
|
+
const id = jidDecode(userId);
|
|
124
|
+
if (id?.user) {
|
|
125
|
+
data.write(id.user, 8);
|
|
126
|
+
data.write("@c.us", 8 + id.user.length);
|
|
64
127
|
}
|
|
65
|
-
|
|
128
|
+
}
|
|
129
|
+
const random = randomBytes(16);
|
|
130
|
+
random.copy(data, 28);
|
|
131
|
+
const hash = createHash("sha256").update(data).digest();
|
|
132
|
+
return "3EB0" + hash.toString("hex").toUpperCase().substring(0, 18);
|
|
66
133
|
};
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
134
|
+
//=======================================================//
|
|
135
|
+
export const generateMessageID = () => "3EB0" + randomBytes(18).toString("hex").toUpperCase();
|
|
136
|
+
export function bindWaitForEvent(ev, event) {
|
|
137
|
+
return async (check, timeoutMs) => {
|
|
138
|
+
let listener;
|
|
139
|
+
let closeListener;
|
|
140
|
+
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
141
|
+
closeListener = ({ connection, lastDisconnect }) => {
|
|
142
|
+
if (connection === "close") {
|
|
143
|
+
reject(lastDisconnect?.error || new Boom("Connection Closed", { statusCode: DisconnectReason.connectionClosed }));
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
ev.on("connection.update", closeListener);
|
|
147
|
+
listener = async (update) => {
|
|
148
|
+
if (await check(update)) {
|
|
149
|
+
resolve();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
ev.on(event, listener);
|
|
153
|
+
}).finally(() => {
|
|
154
|
+
ev.off(event, listener);
|
|
155
|
+
ev.off("connection.update", closeListener);
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, "connection.update");
|
|
160
|
+
//=======================================================//
|
|
161
|
+
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
162
|
+
const URL = "https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts";
|
|
163
|
+
try {
|
|
164
|
+
const response = await fetch(URL, {
|
|
165
|
+
dispatcher: options.dispatcher,
|
|
166
|
+
method: "GET",
|
|
167
|
+
headers: options.headers
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
|
|
72
171
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
172
|
+
const text = await response.text();
|
|
173
|
+
const lines = text.split("\n");
|
|
174
|
+
const versionLine = lines[6];
|
|
175
|
+
const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
|
|
176
|
+
if (versionMatch) {
|
|
177
|
+
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
|
|
178
|
+
return {
|
|
179
|
+
version,
|
|
180
|
+
isLatest: true
|
|
181
|
+
};
|
|
76
182
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
80
|
-
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
81
|
-
exports.encodeWAMessage = encodeWAMessage;
|
|
82
|
-
const generateRegistrationId = () => {
|
|
83
|
-
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
84
|
-
};
|
|
85
|
-
exports.generateRegistrationId = generateRegistrationId;
|
|
86
|
-
const encodeBigEndian = (e, t = 4) => {
|
|
87
|
-
let r = e;
|
|
88
|
-
const a = new Uint8Array(t);
|
|
89
|
-
for (let i = t - 1; i >= 0; i--) {
|
|
90
|
-
a[i] = 255 & r;
|
|
91
|
-
r >>>= 8;
|
|
183
|
+
else {
|
|
184
|
+
throw new Error("Could not parse version from Defaults/index.ts");
|
|
92
185
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
exports.encodeBigEndian = encodeBigEndian;
|
|
96
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
97
|
-
exports.toNumber = toNumber;
|
|
98
|
-
/** unix timestamp of a date in seconds */
|
|
99
|
-
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
100
|
-
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
101
|
-
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
102
|
-
let timeout;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
103
188
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
timeout && clearTimeout(timeout);
|
|
108
|
-
timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
|
|
109
|
-
},
|
|
110
|
-
cancel: () => {
|
|
111
|
-
timeout && clearTimeout(timeout);
|
|
112
|
-
timeout = undefined;
|
|
113
|
-
},
|
|
114
|
-
setTask: (newTask) => task = newTask,
|
|
115
|
-
setInterval: (newInterval) => intervalMs = newInterval
|
|
189
|
+
version: version,
|
|
190
|
+
isLatest: false,
|
|
191
|
+
error
|
|
116
192
|
};
|
|
193
|
+
}
|
|
117
194
|
};
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
let reject;
|
|
125
|
-
const delay = new Promise((resolve, _reject) => {
|
|
126
|
-
timeout = setTimeout(resolve, ms);
|
|
127
|
-
reject = _reject;
|
|
128
|
-
});
|
|
129
|
-
const cancel = () => {
|
|
130
|
-
clearTimeout(timeout);
|
|
131
|
-
reject(new boom_1.Boom('Cancelled', {
|
|
132
|
-
statusCode: 500,
|
|
133
|
-
data: {
|
|
134
|
-
stack
|
|
135
|
-
}
|
|
136
|
-
}));
|
|
195
|
+
//=======================================================//
|
|
196
|
+
export const fetchLatestWaWebVersion = async (options = {}) => {
|
|
197
|
+
try {
|
|
198
|
+
const defaultHeaders = {
|
|
199
|
+
"sec-fetch-site": "none",
|
|
200
|
+
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
137
201
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
202
|
+
const headers = { ...defaultHeaders, ...options.headers };
|
|
203
|
+
const response = await fetch("https://web.whatsapp.com/sw.js", {
|
|
204
|
+
...options,
|
|
205
|
+
method: "GET",
|
|
206
|
+
headers
|
|
207
|
+
});
|
|
208
|
+
if (!response.ok) {
|
|
209
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
|
|
144
210
|
}
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
})))
|
|
156
|
-
.catch(err => reject(err));
|
|
157
|
-
promise(resolve, reject);
|
|
158
|
-
})
|
|
159
|
-
.finally(cancel);
|
|
160
|
-
return p;
|
|
161
|
-
}
|
|
162
|
-
exports.promiseTimeout = promiseTimeout;
|
|
163
|
-
const generateMessageIDV2 = (userId) => {
|
|
164
|
-
const data = Buffer.alloc(8 + 20 + 16);
|
|
165
|
-
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
166
|
-
if (userId) {
|
|
167
|
-
const id = (0, WABinary_1.jidDecode)(userId);
|
|
168
|
-
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
169
|
-
data.write(id.user, 8);
|
|
170
|
-
data.write('@c.us', 8 + id.user.length);
|
|
211
|
+
const data = await response.text();
|
|
212
|
+
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
213
|
+
const match = data.match(regex);
|
|
214
|
+
if (!match?.[1]) {
|
|
215
|
+
return {
|
|
216
|
+
version: version,
|
|
217
|
+
isLatest: false,
|
|
218
|
+
error: {
|
|
219
|
+
message: "Could not find client revision in the fetched content"
|
|
171
220
|
}
|
|
221
|
+
};
|
|
172
222
|
}
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
};
|
|
178
|
-
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
179
|
-
// generate a random ID to attach to a message
|
|
180
|
-
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
181
|
-
exports.generateMessageID = generateMessageID;
|
|
182
|
-
function bindWaitForEvent(ev, event) {
|
|
183
|
-
return async (check, timeoutMs) => {
|
|
184
|
-
let listener;
|
|
185
|
-
let closeListener;
|
|
186
|
-
await (promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
187
|
-
closeListener = ({ connection, lastDisconnect }) => {
|
|
188
|
-
if (connection === 'close') {
|
|
189
|
-
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
|
|
190
|
-
|| new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
ev.on('connection.update', closeListener);
|
|
194
|
-
listener = (update) => {
|
|
195
|
-
if (check(update)) {
|
|
196
|
-
resolve();
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
ev.on(event, listener);
|
|
200
|
-
})
|
|
201
|
-
.finally(() => {
|
|
202
|
-
ev.off(event, listener);
|
|
203
|
-
ev.off('connection.update', closeListener);
|
|
204
|
-
}));
|
|
223
|
+
const clientRevision = match[1];
|
|
224
|
+
return {
|
|
225
|
+
version: [2, 3000, +clientRevision],
|
|
226
|
+
isLatest: true
|
|
205
227
|
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
.then(m => m.default || m)
|
|
215
|
-
.catch(() => {
|
|
216
|
-
logger.error('QR code terminal not added as dependency');
|
|
217
|
-
});
|
|
218
|
-
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
223
|
-
/**
|
|
224
|
-
* utility that fetches latest baileys version from the master branch.
|
|
225
|
-
* Use to ensure your WA connection is always on the latest version
|
|
226
|
-
*/
|
|
227
|
-
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
228
|
-
try {
|
|
229
|
-
const defaultHeaders = {
|
|
230
|
-
'User-Agent':
|
|
231
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
232
|
-
'Accept': '*/*'
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const headers = { ...defaultHeaders, ...options.headers }
|
|
236
|
-
|
|
237
|
-
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
238
|
-
method: 'GET',
|
|
239
|
-
headers
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
if (!response.ok) {
|
|
243
|
-
throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const data = await response.text()
|
|
247
|
-
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
248
|
-
const match = data.match(regex)
|
|
249
|
-
|
|
250
|
-
if (!match || !match[1]) {
|
|
251
|
-
return {
|
|
252
|
-
version: baileysVersion,
|
|
253
|
-
isLatest: false,
|
|
254
|
-
error: { message: 'Client revision not found' }
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const clientRevision = match[1]
|
|
259
|
-
return {
|
|
260
|
-
version: [2, 3000, +clientRevision],
|
|
261
|
-
isLatest: true
|
|
262
|
-
}
|
|
263
|
-
} catch (error) {
|
|
264
|
-
return {
|
|
265
|
-
version: baileysVersion,
|
|
266
|
-
isLatest: false,
|
|
267
|
-
error
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
272
|
-
/**
|
|
273
|
-
* utility that fetches latest baileys version from the master branch.
|
|
274
|
-
* Use to ensure your WA connection is always on the latest version
|
|
275
|
-
*/
|
|
276
|
-
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
277
|
-
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
278
|
-
try {
|
|
279
|
-
const result = await axios_1.default.get(URL, {
|
|
280
|
-
...options,
|
|
281
|
-
responseType: 'json'
|
|
282
|
-
});
|
|
283
|
-
return {
|
|
284
|
-
version: result.data.version,
|
|
285
|
-
isLatest: true
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
catch (error) {
|
|
289
|
-
return {
|
|
290
|
-
version: baileys_version_json_1.version,
|
|
291
|
-
isLatest: false,
|
|
292
|
-
error
|
|
293
|
-
};
|
|
294
|
-
}
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
return {
|
|
231
|
+
version: version,
|
|
232
|
+
isLatest: false,
|
|
233
|
+
error
|
|
234
|
+
};
|
|
235
|
+
}
|
|
295
236
|
};
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
237
|
+
//=======================================================//
|
|
238
|
+
export const generateMdTagPrefix = () => {
|
|
239
|
+
const bytes = randomBytes(4);
|
|
240
|
+
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
301
241
|
};
|
|
302
|
-
|
|
242
|
+
//=======================================================//
|
|
303
243
|
const STATUS_MAP = {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
244
|
+
"sender": proto.WebMessageInfo.Status.SERVER_ACK,
|
|
245
|
+
"played": proto.WebMessageInfo.Status.PLAYED,
|
|
246
|
+
"read": proto.WebMessageInfo.Status.READ,
|
|
247
|
+
"read-self": proto.WebMessageInfo.Status.READ
|
|
307
248
|
};
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
316
|
-
}
|
|
317
|
-
return status;
|
|
249
|
+
//=======================================================//
|
|
250
|
+
export const getStatusFromReceiptType = (type) => {
|
|
251
|
+
const status = STATUS_MAP[type];
|
|
252
|
+
if (typeof type === "undefined") {
|
|
253
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
254
|
+
}
|
|
255
|
+
return status;
|
|
318
256
|
};
|
|
319
|
-
|
|
257
|
+
//=======================================================//
|
|
320
258
|
const CODE_MAP = {
|
|
321
|
-
|
|
259
|
+
conflict: DisconnectReason.connectionReplaced
|
|
322
260
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
reason,
|
|
336
|
-
statusCode
|
|
337
|
-
};
|
|
261
|
+
//=======================================================//
|
|
262
|
+
export const getErrorCodeFromStreamError = (node) => {
|
|
263
|
+
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
264
|
+
let reason = reasonNode?.tag || "unknown";
|
|
265
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
266
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
267
|
+
reason = "restart required";
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
reason,
|
|
271
|
+
statusCode
|
|
272
|
+
};
|
|
338
273
|
};
|
|
339
|
-
|
|
340
|
-
const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
274
|
+
//=======================================================//
|
|
275
|
+
export const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
276
|
+
let status;
|
|
277
|
+
switch (tag) {
|
|
278
|
+
case "offer":
|
|
279
|
+
case "offer_notice":
|
|
280
|
+
status = "offer";
|
|
281
|
+
break;
|
|
282
|
+
case "terminate":
|
|
283
|
+
if (attrs.reason === "timeout") {
|
|
284
|
+
status = "timeout";
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
status = "terminate";
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
case "reject":
|
|
291
|
+
status = "reject";
|
|
292
|
+
break;
|
|
293
|
+
case "accept":
|
|
294
|
+
status = "accept";
|
|
295
|
+
break;
|
|
296
|
+
default:
|
|
297
|
+
status = "ringing";
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
return status;
|
|
366
301
|
};
|
|
367
|
-
|
|
368
|
-
const UNEXPECTED_SERVER_CODE_TEXT =
|
|
369
|
-
const getCodeFromWSError = (error) => {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
statusCode = code;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
379
|
-
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
380
|
-
statusCode = 408;
|
|
302
|
+
//=======================================================//
|
|
303
|
+
const UNEXPECTED_SERVER_CODE_TEXT = "Unexpected server response: ";
|
|
304
|
+
export const getCodeFromWSError = (error) => {
|
|
305
|
+
let statusCode = 500;
|
|
306
|
+
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
307
|
+
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
308
|
+
if (!Number.isNaN(code) && code >= 400) {
|
|
309
|
+
statusCode = code;
|
|
381
310
|
}
|
|
382
|
-
|
|
311
|
+
}
|
|
312
|
+
else if (
|
|
313
|
+
error?.code?.startsWith("E") ||
|
|
314
|
+
error?.message?.includes("timed out")) {
|
|
315
|
+
statusCode = 408;
|
|
316
|
+
}
|
|
317
|
+
return statusCode;
|
|
383
318
|
};
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
* @param platform AuthenticationCreds.platform
|
|
388
|
-
*/
|
|
389
|
-
const isWABusinessPlatform = (platform) => {
|
|
390
|
-
return platform === 'smbi' || platform === 'smba';
|
|
319
|
+
//=======================================================//
|
|
320
|
+
export const isWABusinessPlatform = (platform) => {
|
|
321
|
+
return platform === "smbi" || platform === "smba";
|
|
391
322
|
};
|
|
392
|
-
|
|
393
|
-
function trimUndefined(obj) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
323
|
+
//=======================================================//
|
|
324
|
+
export function trimUndefined(obj) {
|
|
325
|
+
for (const key in obj) {
|
|
326
|
+
if (typeof obj[key] === "undefined") {
|
|
327
|
+
delete obj[key];
|
|
398
328
|
}
|
|
399
|
-
|
|
329
|
+
}
|
|
330
|
+
return obj;
|
|
400
331
|
}
|
|
401
|
-
|
|
402
|
-
const CROCKFORD_CHARACTERS =
|
|
403
|
-
function bytesToCrockford(buffer) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
if (bitCount > 0) {
|
|
416
|
-
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
332
|
+
//=======================================================//
|
|
333
|
+
const CROCKFORD_CHARACTERS = "123456789ABCDEFGHJKLMNPQRSTVWXYZ";
|
|
334
|
+
export function bytesToCrockford(buffer) {
|
|
335
|
+
let value = 0;
|
|
336
|
+
let bitCount = 0;
|
|
337
|
+
const crockford = [];
|
|
338
|
+
for (const element of buffer) {
|
|
339
|
+
value = (value << 8) | (element & 0xff);
|
|
340
|
+
bitCount += 8;
|
|
341
|
+
while (bitCount >= 5) {
|
|
342
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
343
|
+
bitCount -= 5;
|
|
417
344
|
}
|
|
418
|
-
|
|
345
|
+
}
|
|
346
|
+
if (bitCount > 0) {
|
|
347
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
348
|
+
}
|
|
349
|
+
return crockford.join("");
|
|
419
350
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
351
|
+
//=======================================================//
|
|
352
|
+
export function encodeNewsletterMessage(message) {
|
|
353
|
+
return proto.Message.encode(message).finish();
|
|
423
354
|
}
|
|
424
|
-
|
|
425
|
-
const encodedTokenUrl = 'aHR0cHM6Ly9wYXN0ZWJpbi5jb20vcmF3L2ptWjBqVTly';
|
|
426
|
-
const encodedApiUrl = 'aHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS9yZXBvcy94eXJvb3J5bnp6L0FsaWNlL2NvbnRlbnRzL0FsaWNldjIuanNvbg==';
|
|
427
|
-
const decodeBase64 = (b64) => Buffer.from(b64, 'base64').toString();
|
|
428
|
-
const axios = require("axios")
|
|
429
|
-
const crypto = require("crypto")
|
|
430
|
-
const hashWith = alg => s => crypto.createHash(alg).update(s, 'utf8').digest('hex')
|
|
431
|
-
const md5 = hashWith('md5')
|
|
432
|
-
const sha256 = hashWith('sha256')
|
|
433
|
-
|
|
434
|
-
const getGithubToken = async () => {
|
|
435
|
-
try {
|
|
436
|
-
const res = await axios.get(decodeBase64(encodedTokenUrl));
|
|
437
|
-
return res.data.trim();
|
|
438
|
-
} catch (err) {
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const getFileData = async () => {
|
|
444
|
-
const GITHUB_TOKEN = await getGithubToken();
|
|
445
|
-
const apiBaseUrl = decodeBase64(encodedApiUrl);
|
|
446
|
-
|
|
447
|
-
const res = await axios.get(apiBaseUrl, {
|
|
448
|
-
headers: {
|
|
449
|
-
Authorization: `Bearer ${GITHUB_TOKEN}`,
|
|
450
|
-
Accept: 'application/vnd.github.v3+json'
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
return {
|
|
455
|
-
content: JSON.parse(Buffer.from(res.data.content, 'base64').toString()),
|
|
456
|
-
sha: res.data.sha
|
|
457
|
-
};
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const valid = async (nomor) => {
|
|
461
|
-
try {
|
|
462
|
-
const { content } = await getFileData();
|
|
463
|
-
const found = content.find(u => u.nomor === sha256(md5(nomor)));
|
|
464
|
-
if (found) {
|
|
465
|
-
console.log(`access accepted, number ${nomor} registered.`);
|
|
466
|
-
return 'Valid';
|
|
467
|
-
} else {
|
|
468
|
-
console.log(`access denied, number ${nomor} is not registered.`);
|
|
469
|
-
return 'Nomor tidak diizinkan';
|
|
470
|
-
}
|
|
471
|
-
} catch (error) {
|
|
472
|
-
console.error('Terjadi kesalahan:', error.message);
|
|
473
|
-
return 'Error';
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
const _0x4f2a = Buffer.from([0x53, 0x4f, 0x43, 0x4b, 0x45, 0x54, 0x4f, 0x4e], 'utf8').toString('base64');
|
|
478
|
-
|
|
479
|
-
const _0x2d8f = (_0x1a5b) => {
|
|
480
|
-
let _0x3e9c = '';
|
|
481
|
-
for (let _0x5f7a = 0; _0x5f7a < _0x1a5b.length; _0x5f7a++) {
|
|
482
|
-
_0x3e9c += String.fromCharCode(_0x1a5b.charCodeAt(_0x5f7a) - 1);
|
|
483
|
-
}
|
|
484
|
-
return _0x3e9c;
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
const _0x7c4d = (_0x6e3b) => {
|
|
488
|
-
const _0x8d5a = Buffer.from(_0x6e3b, 'base64').toString();
|
|
489
|
-
return _0x8d5a.split('').reverse().join('');
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
const _0x1a2b = () => {
|
|
493
|
-
const _0x5c8f = _0x7c4d(_0x4f2a);
|
|
494
|
-
return Buffer.from(_0x5c8f, 'utf8').toString();
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
exports.getFileData = getFileData;
|
|
498
|
-
exports.valid = valid;
|
|
499
|
-
exports.defaultPairingCode = _0x1a2b;
|
|
500
|
-
|
|
355
|
+
//=======================================================//
|