-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
426 lines (383 loc) · 17.3 KB
/
main.py
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import requests
import time
import json
from web3 import Web3
from eth_account.messages import encode_defunct
from datetime import datetime, timezone
from colorama import Fore, init, Style
from fake_useragent import UserAgent
import random
import os
init(autoreset=True)
# Function to display a rainbow banner
def rainbow_banner():
os.system("clear" if os.name == "posix" else "cls")
colors = [Fore.RED, Fore.YELLOW, Fore.GREEN, Fore.CYAN, Fore.BLUE, Fore.MAGENTA]
banner = """
_______
| __|.--.--.---.-.-----.---.-.
|__ || | | _ |-- __| _ |
|_______||___ |___._|_____|___._|
|_____|
"""
for i, char in enumerate(banner):
print(colors[i % len(colors)] + char, end="")
time.sleep(0.007)
print(Fore.LIGHTYELLOW_EX + "\nPlease wait...\n")
time.sleep(2)
os.system("clear" if os.name == "posix" else "cls")
for i, char in enumerate(banner):
print(colors[i % len(colors)] + char, end="")
print(Fore.LIGHTYELLOW_EX + "\n")
# Read private keys from file
def read_private_keys(file_path):
private_keys = []
with open(file_path, 'r') as file:
for line in file:
private_key = line.strip()
if private_key:
private_keys.append(private_key)
return private_keys
# Read user agents from file
def read_user_agents(file_path):
user_agents = {}
if os.path.exists(file_path):
with open(file_path, 'r') as file:
user_agents = json.load(file)
return user_agents
# Save user agents to file
def save_user_agents(file_path, user_agents):
with open(file_path, 'w') as file:
json.dump(user_agents, file)
# Read session data from file
def read_session_data(file_path):
if os.path.exists(file_path):
with open(file_path, 'r') as file:
return json.load(file)
return {}
# Save session data to file
def save_session_data(file_path, session_data):
with open(file_path, 'w') as file:
json.dump(session_data, file)
# Read referral codes from file
def read_referral_codes(file_path):
referral_codes = []
with open(file_path, 'r') as file:
for line in file:
ref_code = line.strip()
if ref_code:
referral_codes.append(ref_code)
return referral_codes
# Save referral codes to file
def save_referral_codes(file_path, referral_codes):
with open(file_path, 'w') as file:
for ref_code in referral_codes:
file.write(ref_code + '\n')
# Data from privatekeys.txt
private_keys = read_private_keys('privatekeys.txt')
# User agents file path
user_agents_file = 'ua.txt'
user_agents = read_user_agents(user_agents_file)
# Session data file path
session_data_file = 'session_data.json'
session_data = read_session_data(session_data_file)
# Referral codes from code.txt
referral_codes_file = 'code.txt'
referral_codes = read_referral_codes(referral_codes_file)
# URL endpoints for session initiation, authentication, and quests
init_endpoint = 'https://auth.privy.io/api/v1/siwe/init'
authenticate_endpoint = 'https://auth.privy.io/api/v1/siwe/authenticate'
login_endpoint = 'https://api.service.crestal.network/v1/login?is_privy=true'
quests_endpoint = 'https://api.service.crestal.network/v1/quests'
latest_quests_endpoint = 'https://api.service.crestal.network/v1/quests/latest?user_address={user_address}'
profile_endpoint_template = 'https://api.service.crestal.network/v1/users/{user_address}'
complete_quest_endpoint_template = 'https://api.service.crestal.network/v1/report?user_address={user_address}&type={activity_action}'
claim_referral_endpoint_template = 'https://api.service.crestal.network/v1/referral/{ref_code}/claim'
allowed_activity_actions = [
"interact_with_dashboard",
"use_deployed_blueprint_proposal",
"feedback",
"read_blog",
"follow_crestal_on_x",
"join_telegram",
"join_discord",
"post_about_crestal",
"interact_with_crestal_x",
"submit_intent_kit_pr",
"start_intent_kit",
"nft_weekly_award"
]
# Tambahkan flag always_complete_quest di bagian awal kode
always_complete_quest = True
# Function to initiate session with exponential backoff
def init_session(address, headers, retries=5):
payload = {"address": address}
for attempt in range(retries):
response = requests.post(init_endpoint, headers=headers, json=payload)
if response.status_code == 200:
log("\n✔ Init session successful")
return response.json()
elif response.status_code == 429:
delay = 5 * (2 ** attempt)
log(f"\n♻ Rate limit exceeded, retrying in {delay} seconds...", end="")
time.sleep(delay)
else:
log(f"\n✖ Init session failed (HTTP {response.status_code})")
log(f"⚠ Response: {response.text}")
return None
# Function to sign message
def sign_message(private_key, message):
web3 = Web3()
message = encode_defunct(text=message)
signed_message = web3.eth.account.sign_message(message, private_key=private_key)
return signed_message.signature.hex()
# Function to authenticate with retry and exponential backoff
def authenticate(private_key, init_data, headers, retries=5):
web3 = Web3()
account = web3.eth.account.from_key(private_key)
issued_at = datetime.now(timezone.utc).isoformat()
message = (
f"app.crestal.network wants you to sign in with your Ethereum account:\n{account.address}\n\n"
"By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.\n\n"
f"URI: https://app.crestal.network\nVersion: 1\nChain ID: 8453\nNonce: {init_data['nonce']}\n"
f"Issued At: {issued_at}\nResources:\n- https://privy.io"
)
signature = "0x" + sign_message(private_key, message)
log("✔ Message signed")
payload = {
"message": message,
"signature": signature,
"chainId": "eip155:8453",
"walletClientType": "okx_wallet",
"connectorType": "injected",
"mode": "login-or-sign-up"
}
for attempt in range(retries):
response = requests.post(authenticate_endpoint, headers=headers, json=payload)
if response.status_code == 200:
log("\n✔ Authenticate successful")
return response.json()
elif response.status_code == 429:
delay = 5 * (2 ** attempt)
log(f"\n♻ Rate limit exceeded, retrying in {delay} seconds...", end="")
time.sleep(delay)
else:
log(f"\n✖ Authenticate failed (HTTP {response.status_code})")
log(f"⚠ Response: {response.text}")
return None
# Function to login with privy token and get crestal token with retry and exponential backoff
def login_with_privy_token(privy_token, user_address, headers, retries=5):
payload = {"privy_token": privy_token, "user_address": user_address}
for attempt in range(retries):
response = requests.post(login_endpoint, headers=headers, json=payload)
if response.status_code == 200:
log("✔ Login successful")
return response.json()
elif response.status_code == 429:
delay = 5 * (2 ** attempt)
log(f"\n♻ Rate limit exceeded, retrying in {delay} seconds...", end="")
time.sleep(delay)
else:
log(f"\n✖ Login failed (HTTP {response.status_code})")
log(f"⚠ Response: {response.text}")
return None
# Function to get account profile
def get_profile(access_token, user_address, headers):
headers['Authorization'] = f"Bearer {access_token}"
profile_endpoint = profile_endpoint_template.format(user_address=user_address)
response = requests.get(profile_endpoint, headers=headers)
if response.status_code == 200:
log("\n✔ Account profile loaded")
return response.json()
elif response.status_code == 400 and "token is expired" in response.text.lower():
return "token_expired"
else:
log(f"\n✖ Account profile retrieval failed (HTTP {response.status_code})")
log(f"⚠ Response: {response.text}")
return None
# Function to get latest quests
def get_latest_quests(access_token, user_address, headers):
headers['Authorization'] = f"Bearer {access_token}"
response = requests.get(latest_quests_endpoint.format(user_address=user_address), headers=headers)
if response.status_code == 200:
log("✔ Latest quest retrieved")
return response.json()
else:
log(f"✖ Latest quest retrieval failed (HTTP {response.status_code})")
log(f"⚠ Response: {response.text}")
return []
# Function to get quests
def get_quests(access_token, headers):
headers['Authorization'] = f"Bearer {access_token}"
response = requests.get(quests_endpoint, headers=headers)
if response.status_code == 200:
log("✔ Quest retrieved")
return response.json()
else:
log(f"✖ Quest retrieval failed (HTTP {response.status_code})")
log(f"⚠ Response: {response.text}")
return []
# Function to complete quest
def complete_quest(access_token, quest, user_address, headers):
if quest['activity_action'] not in allowed_activity_actions:
log(f"✖ Quest '{quest['title']}' not allowed: {quest['activity_action']}")
return False
log(f"↻ Completing quest '{quest['title']}'")
headers['Authorization'] = f"Bearer {access_token}"
complete_quest_endpoint = complete_quest_endpoint_template.format(user_address=user_address, activity_action=quest['activity_action'])
response = requests.post(complete_quest_endpoint, headers=headers)
if response.status_code == 200:
log(f"✔ Quest '{quest['title']}' completed successfully")
return True
else:
try:
error_msg = response.json().get('msg', response.text)
except json.JSONDecodeError:
error_msg = response.text
log(f"✖ Quest '{quest['title']}' completion failed: {response.status_code}, {error_msg}")
return False
# Function to claim referral code
def claim_ref_code(access_token, ref_code, headers):
headers['Authorization'] = f"Bearer {access_token}"
claim_referral_endpoint = claim_referral_endpoint_template.format(ref_code=ref_code)
response = requests.post(claim_referral_endpoint, headers=headers)
if response.status_code == 200:
log(f"✔ Referral code '{ref_code}' claimed successfully")
return response
else:
return response
# Function to generate or retrieve User-Agent
def generate_headers(account):
if account not in user_agents:
ua = UserAgent()
user_agents[account] = ua.random
save_user_agents(user_agents_file, user_agents)
headers = {
'Content-Type': 'application/json',
'User-Agent': user_agents[account],
'Privy-App-Id': 'cm4v61vl108sdivml83sbeykh',
'Privy-Ca-Id': 'ce166674-fc02-4f23-9d31-fe4e2ed29533',
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Accept-Language': 'en-US,en;q=0.5',
'Origin': 'https://app.crestal.network',
'Referer': 'https://app.crestal.network/',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
}
return headers
# Function to display loading with random delay
def display_loading(seconds):
for remaining in range(seconds, 0, -1):
log(f"⟳ Waiting {remaining} seconds...", end="\r")
time.sleep(1)
print()
# Function to log messages with rainbow effect
log_colors = [Fore.RED, Fore.YELLOW, Fore.GREEN, Fore.CYAN, Fore.BLUE, Fore.MAGENTA]
log_index = 0
def log(message, end="\n"):
global log_index
color = log_colors[log_index % len(log_colors)]
print(color + message + Style.RESET_ALL, end=end)
log_index += 1
# Function to handle token expiration and re-authentication
def handle_token_expiration(account, private_key, headers):
log(f"\nToken expired for Wallet {account}, re-authenticating...", Fore.RED)
init_data = init_session(account, headers)
if init_data:
auth_data = authenticate(private_key, init_data, headers)
if auth_data:
login_data = login_with_privy_token(auth_data['privy_access_token'], account, headers)
if login_data:
access_token = login_data['access_token']
session_data[account] = {'access_token': access_token}
save_session_data(session_data_file, session_data)
return access_token
else:
log("✖ Login status: Failed")
else:
log("\n✖ Authentication status: Failed")
else:
log("\n✖ Session initiation status: Failed")
return None
# Display banner
rainbow_banner()
# Process session initiation, authentication, login, profile retrieval, quest retrieval, quest completion, and referral code claim for each private key
while True:
for private_key in private_keys:
web3 = Web3()
account = web3.eth.account.from_key(private_key).address
headers = generate_headers(account)
# Check if session data exists for the account
if account in session_data:
access_token = session_data[account]['access_token']
log(f"\nUsing saved session for Wallet {account}", Fore.CYAN)
else:
log(f"\n↻ Processing Wallet {account}", Fore.CYAN)
init_data = init_session(account, headers)
if init_data:
auth_data = authenticate(private_key, init_data, headers)
if auth_data:
login_data = login_with_privy_token(auth_data['privy_access_token'], account, headers)
if login_data:
access_token = login_data['access_token']
session_data[account] = {'access_token': access_token}
save_session_data(session_data_file, session_data)
else:
log("✖ Login status: Failed")
continue
else:
log("\n✖ Authentication status: Failed")
continue
else:
log("\n✖ Session initiation status: Failed")
continue
profile_data = get_profile(access_token, account, headers)
if profile_data == "token_expired":
access_token = handle_token_expiration(account, private_key, headers)
if not access_token:
continue
profile_data = get_profile(access_token, account, headers)
if profile_data:
log("✔ Account profile retrieved")
log("✔ Account Information:")
log(f"✔ ID: {profile_data['id']}")
log(f"✔ Rank: {profile_data['rank']}")
log(f"✔ Total Points: {profile_data['total_point']}")
log(f"✔ User Address: {profile_data['user_address']}")
# Skip claiming referral code if already referred
if not profile_data.get('is_referred', False):
for ref_code in referral_codes:
response = claim_ref_code(access_token, ref_code, headers)
if response.status_code == 200:
referral_codes.remove(ref_code)
save_referral_codes(referral_codes_file, referral_codes)
break
elif response.status_code == 409:
referral_codes.remove(ref_code)
save_referral_codes(referral_codes_file, referral_codes)
latest_quests = get_latest_quests(access_token, account, headers)
latest_activity_actions = [quest['activity_action'] for quest in latest_quests]
quests = get_quests(access_token, headers)
if quests:
for quest in quests:
# Modifikasi bagian yang memeriksa dan menyelesaikan quest
if quest['activity_action'] not in latest_activity_actions or always_complete_quest:
success = complete_quest(access_token, quest, account, headers)
if not success:
response = requests.post(complete_quest_endpoint_template.format(user_address=account, activity_action=quest['activity_action']), headers=headers)
if "token is expired" in response.text.lower():
access_token = handle_token_expiration(account, private_key, headers)
if access_token:
complete_quest(access_token, quest, account, headers)
else:
log(f"✔ Quest '{quest['title']}' already completed")
else:
log("✖ Quest retrieval status: Failed")
log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
# Save user agents to file
save_user_agents(user_agents_file, user_agents)
# Random delay between 1 to 7 hours after all accounts are processed
wait_time = random.randint(3600, 25200) # Seconds
display_loading(wait_time)