This repository was archived by the owner on Jul 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsahara.js
More file actions
181 lines (154 loc) · 6.42 KB
/
sahara.js
File metadata and controls
181 lines (154 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const chains = require('./chains');
const fs = require('fs');
const fetch = require('node-fetch');
const { ethers } = require('ethers');
const header = chains.utils.etc.header;
const privateKeys = JSON.parse(fs.readFileSync("privateKeys.json"));
const delay = chains.utils.etc.delay;
const maskedAddress = (address) => `${address.slice(0, 6)}...${address.slice(-4)}`;
const logFile = "log.txt";
function logToFile(message) {
fs.appendFileSync(logFile, message + "\n", "utf8");
}
function log(address, message) {
const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
const logMessage = address
? `[${timestamp} | ${maskedAddress(address)}] ${message}`
: "";
console.log(logMessage);
logToFile(logMessage);
}
async function getChallenge(address) {
log(address, "🔹 Requesting challenge...");
await delay(5000);
const response = await fetch("https://legends.saharalabs.ai/api/v1/user/challenge", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ address, timestamp: Date.now() })
});
if (!response.ok) {
throw new Error(`❌ Failed to get challenge: ${response.statusText}`);
}
const data = await response.json();
log(address, `✅ Challenge received: ${data.challenge}`);
return data.challenge;
}
async function signChallenge(wallet) {
try {
const address = wallet.address;
const challenge = await getChallenge(address);
const message = `Sign in to Sahara!\nChallenge:${challenge}`;
const signature = await wallet.signMessage(message);
log(address, `✅ Signature: ${signature.slice(0, 6)}...${signature.slice(-4)}`);
log(address, "🔹 Submitting signature for login...");
await delay(5000);
const loginResponse = await fetch("https://legends.saharalabs.ai/api/v1/login/wallet", {
method: "POST",
headers: {
"Content-Type": "application/json",
"accept": "application/json",
"authorization": "Bearer null",
"origin": "https://legends.saharalabs.ai",
"referer": "https://legends.saharalabs.ai/?code=THWD0T",
"user-agent": "Mozilla/5.0"
},
body: JSON.stringify({
address,
sig: signature,
referralCode: "THWD0T",
walletUUID: "",
walletName: "MetaMask",
timestamp: Date.now()
})
});
if (!loginResponse.ok) {
throw new Error(`❌ Login failed: ${loginResponse.statusText}`);
}
const loginData = await loginResponse.json();
const maskedToken = loginData.accessToken
? `${loginData.accessToken.slice(0, 6)}***${loginData.accessToken.slice(-4)}`
: "Token not found";
log(address, `✅ Login successful! Access Token: ${maskedToken}`);
if (!loginData.accessToken) {
throw new Error(`❌ Failed to retrieve accessToken`);
}
return { accessToken: loginData.accessToken };
} catch (error) {
log(wallet.address, `❌ Error during login: ${error.message}`);
throw error;
}
async function sendTaskRequest(accessToken, taskID, address) {
log(address, `🔹 Sending request for Task ${taskID}...`);
await delay(5000);
await fetch("https://legends.saharalabs.ai/api/v1/task/flush", {
method: "POST",
headers: { "Content-Type": "application/json", "authorization": `Bearer ${accessToken}` },
body: JSON.stringify({ taskID, timestamp: Date.now() })
});
log(address, `✅ Task ${taskID} - Request successfully sent.`);
}
async function sendTaskClaim(accessToken, taskID, address) {
log(address, `🔹 Claiming Task ${taskID}...`);
await delay(5000);
await fetch("https://legends.saharalabs.ai/api/v1/task/claim", {
method: "POST",
headers: { "Content-Type": "application/json", "authorization": `Bearer ${accessToken}` },
body: JSON.stringify({ taskID, timestamp: Date.now() })
});
log(address, `✅ Task ${taskID} - Successfully claimed.`);
}
async function sendCheckTask(accessToken, taskID, address) {
log(address, `🔹 Checking Task ${taskID} status...`);
await delay(5000);
const checkTask = await fetch("https://legends.saharalabs.ai/api/v1/task/dataBatch", {
method: "POST",
headers: { "Content-Type": "application/json", "authorization": `Bearer ${accessToken}` },
body: JSON.stringify({ taskIDs: [taskID], timestamp: Date.now() })
});
if (!checkTask.ok) {
throw new Error(`❌ Request /task/dataBatch failed for Task ${taskID}`);
}
const taskData = await checkTask.json();
const status = taskData[taskID]?.status;
log(address, `✅ Task ${taskID} - Status: ${status}`);
if (status === "1") {
log(address, `🔹 Task ${taskID} requires verification, sending request...`);
await sendTaskRequest(accessToken, taskID, address);
await delay(10000);
log(address, `🔹 Task ${taskID} verification completed, claiming reward...`);
await sendTaskClaim(accessToken, taskID, address);
} else if (status === "2") {
log(address, `🔹 Task ${taskID} is claimable, claiming reward...`);
await sendTaskClaim(accessToken, taskID, address);
} else if (status === "3") {
log(address, `✅ Task ${taskID} is already completed.`);
} else {
log(address, `⚠️ Task ${taskID} has an unknown status: ${status}`);
}
}
async function sendDailyTask(wallet) {
try {
const { accessToken } = await signChallenge(wallet);
if (!accessToken) {
throw new Error(`❌ Access token not found!`);
}
const taskIDs = ["1001", "1002", "1004"];
for (const taskID of taskIDs) {
await sendCheckTask(accessToken, taskID, wallet.address);
}
log(wallet.address, "✅ All tasks completed.");
log("", "");
} catch (error) {
log(wallet.address, `❌ Error: ${error.message}`);
}
}
async function startBot() {
fs.writeFileSync(logFile, "");
header();
for (const privateKey of privateKeys) {
const wallet = new ethers.Wallet(privateKey);
log(wallet.address, `🔹 Processing wallet: ${wallet.address.slice(0, 6)}...${wallet.address.slice(-4)}`);
await sendDailyTask(wallet);
}
}
startBot();