Spaces:
Runtime error
Runtime error
Commit Β·
d56c8da
1
Parent(s): 53405a2
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,66 +129,87 @@ def generate_phrases_for_words(wordlist, mode):
|
|
| 129 |
yield " ".join(combo)
|
| 130 |
|
| 131 |
# ============================================================
|
| 132 |
-
# Gradio functions
|
| 133 |
# ============================================================
|
| 134 |
|
| 135 |
def generate_random_phrase():
|
| 136 |
return _get_mnemonic().generate(strength=128)
|
| 137 |
|
| 138 |
|
| 139 |
-
def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
|
| 140 |
start_index, end_index, passphrase):
|
| 141 |
"""
|
| 142 |
-
|
| 143 |
-
phir ek ek karke scan karta hai.
|
| 144 |
"""
|
| 145 |
if not os.path.exists(addresses_file):
|
| 146 |
-
|
|
|
|
| 147 |
|
| 148 |
num_phrases = int(num_phrases)
|
| 149 |
-
if num_phrases < 1:
|
| 150 |
-
return "β Kam az kam 1 phrase chahiye", ""
|
| 151 |
-
|
| 152 |
start_index = int(start_index)
|
| 153 |
end_index = int(end_index)
|
| 154 |
-
|
| 155 |
-
|
| 156 |
|
| 157 |
try:
|
| 158 |
known = load_addresses_cached(addresses_file)
|
| 159 |
except Exception as e:
|
| 160 |
-
|
|
|
|
| 161 |
|
| 162 |
if not known:
|
| 163 |
-
|
|
|
|
| 164 |
|
| 165 |
-
# Generate phrases
|
| 166 |
mnemo = _get_mnemonic()
|
| 167 |
-
phrases = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
log_lines = [
|
| 170 |
f"β
Loaded {len(known):,} addresses (cached)",
|
| 171 |
f"π§ Mode: {phrase_mode}",
|
| 172 |
f"π Index range: {start_index}β{end_index}",
|
| 173 |
-
f"π
|
| 174 |
"",
|
| 175 |
-
"
|
| 176 |
]
|
| 177 |
for i, p in enumerate(phrases, 1):
|
| 178 |
-
|
|
|
|
| 179 |
log_lines.append("")
|
| 180 |
|
|
|
|
|
|
|
|
|
|
| 181 |
matches = []
|
| 182 |
start = time.time()
|
|
|
|
| 183 |
|
| 184 |
for p_idx, phrase in enumerate(phrases, 1):
|
| 185 |
-
log_lines.append(f"π [{p_idx}/{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
words = phrase.strip().split()
|
| 187 |
if len(words) != 12:
|
| 188 |
log_lines.append(f" β οΈ Skipped (not 12 words)")
|
|
|
|
| 189 |
continue
|
| 190 |
|
| 191 |
for idx in range(start_index, end_index + 1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
for phrase_str in generate_phrases_for_words(words, phrase_mode):
|
| 193 |
if not is_valid_bip39(phrase_str):
|
| 194 |
continue
|
|
@@ -209,6 +230,10 @@ def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
|
|
| 209 |
)
|
| 210 |
log_lines.append(match_line)
|
| 211 |
matches.append((phrase_str, idx, priv.hex(), addr))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
elapsed = time.time() - start
|
| 214 |
log_lines.append(f"=== DONE ===")
|
|
@@ -219,7 +244,7 @@ def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
|
|
| 219 |
f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
|
| 220 |
) if matches else "Koi match nahi mila"
|
| 221 |
|
| 222 |
-
|
| 223 |
|
| 224 |
|
| 225 |
# ============================================================
|
|
@@ -227,14 +252,19 @@ def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
|
|
| 227 |
# ============================================================
|
| 228 |
with gr.Blocks(title="Phrase Scanner") as demo:
|
| 229 |
gr.Markdown("# π Phrase Scanner")
|
| 230 |
-
gr.Markdown("
|
| 231 |
|
| 232 |
with gr.Row():
|
| 233 |
with gr.Column(scale=1):
|
| 234 |
gr.Markdown("### Settings")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
num_phrases = gr.Number(
|
| 236 |
label="Kitni Random Phrases Check Karein?",
|
| 237 |
-
value=10, precision=0, minimum=
|
| 238 |
)
|
| 239 |
addresses_file = gr.Textbox(
|
| 240 |
label="Addresses File",
|
|
@@ -279,7 +309,7 @@ with gr.Blocks(title="Phrase Scanner") as demo:
|
|
| 279 |
|
| 280 |
run_btn.click(
|
| 281 |
fn=run_multi_phrase_scan,
|
| 282 |
-
inputs=[num_phrases, addresses_file, phrase_mode,
|
| 283 |
start_index, end_index, passphrase],
|
| 284 |
outputs=[log_output, matches_output],
|
| 285 |
)
|
|
|
|
| 129 |
yield " ".join(combo)
|
| 130 |
|
| 131 |
# ============================================================
|
| 132 |
+
# Gradio functions β YIELD for live updates
|
| 133 |
# ============================================================
|
| 134 |
|
| 135 |
def generate_random_phrase():
|
| 136 |
return _get_mnemonic().generate(strength=128)
|
| 137 |
|
| 138 |
|
| 139 |
+
def run_multi_phrase_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
|
| 140 |
start_index, end_index, passphrase):
|
| 141 |
"""
|
| 142 |
+
Generator β har step pe yield, taake UI live update ho.
|
|
|
|
| 143 |
"""
|
| 144 |
if not os.path.exists(addresses_file):
|
| 145 |
+
yield f"β File nahi mili: {addresses_file}", ""
|
| 146 |
+
return
|
| 147 |
|
| 148 |
num_phrases = int(num_phrases)
|
|
|
|
|
|
|
|
|
|
| 149 |
start_index = int(start_index)
|
| 150 |
end_index = int(end_index)
|
| 151 |
+
|
| 152 |
+
yield "Addresses load ho rahe hain...", ""
|
| 153 |
|
| 154 |
try:
|
| 155 |
known = load_addresses_cached(addresses_file)
|
| 156 |
except Exception as e:
|
| 157 |
+
yield f"β Addresses load fail: {e}", ""
|
| 158 |
+
return
|
| 159 |
|
| 160 |
if not known:
|
| 161 |
+
yield "β Koi valid address file mein nahi mila", ""
|
| 162 |
+
return
|
| 163 |
|
|
|
|
| 164 |
mnemo = _get_mnemonic()
|
| 165 |
+
phrases = []
|
| 166 |
+
|
| 167 |
+
# Apni phrase pehle
|
| 168 |
+
my_words = my_phrase.strip().split()
|
| 169 |
+
if len(my_words) == 12:
|
| 170 |
+
phrases.append(" ".join(my_words))
|
| 171 |
+
|
| 172 |
+
for _ in range(num_phrases):
|
| 173 |
+
phrases.append(mnemo.generate(strength=128))
|
| 174 |
|
| 175 |
log_lines = [
|
| 176 |
f"β
Loaded {len(known):,} addresses (cached)",
|
| 177 |
f"π§ Mode: {phrase_mode}",
|
| 178 |
f"π Index range: {start_index}β{end_index}",
|
| 179 |
+
f"π Total phrases: {len(phrases)}",
|
| 180 |
"",
|
| 181 |
+
"Phrases:",
|
| 182 |
]
|
| 183 |
for i, p in enumerate(phrases, 1):
|
| 184 |
+
tag = " (AAPKI)" if i == 1 and len(my_words) == 12 else ""
|
| 185 |
+
log_lines.append(f" {i}. {p}{tag}")
|
| 186 |
log_lines.append("")
|
| 187 |
|
| 188 |
+
# Initial yield β phrases dikh jayein
|
| 189 |
+
yield "\n".join(log_lines), "Scan shuru ho raha hai..."
|
| 190 |
+
|
| 191 |
matches = []
|
| 192 |
start = time.time()
|
| 193 |
+
total_phrases = len(phrases)
|
| 194 |
|
| 195 |
for p_idx, phrase in enumerate(phrases, 1):
|
| 196 |
+
log_lines.append(f"π [{p_idx}/{total_phrases}] Checking: {phrase}")
|
| 197 |
+
yield "\n".join(log_lines), "\n".join(
|
| 198 |
+
f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
|
| 199 |
+
) if matches else "Abhi tak koi match nahi"
|
| 200 |
+
|
| 201 |
words = phrase.strip().split()
|
| 202 |
if len(words) != 12:
|
| 203 |
log_lines.append(f" β οΈ Skipped (not 12 words)")
|
| 204 |
+
yield "\n".join(log_lines), "Koi match nahi mila"
|
| 205 |
continue
|
| 206 |
|
| 207 |
for idx in range(start_index, end_index + 1):
|
| 208 |
+
log_lines.append(f" Index {idx}...")
|
| 209 |
+
yield "\n".join(log_lines), "\n".join(
|
| 210 |
+
f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
|
| 211 |
+
) if matches else "Abhi tak koi match nahi"
|
| 212 |
+
|
| 213 |
for phrase_str in generate_phrases_for_words(words, phrase_mode):
|
| 214 |
if not is_valid_bip39(phrase_str):
|
| 215 |
continue
|
|
|
|
| 230 |
)
|
| 231 |
log_lines.append(match_line)
|
| 232 |
matches.append((phrase_str, idx, priv.hex(), addr))
|
| 233 |
+
# Match mile to turant dikhayein
|
| 234 |
+
yield "\n".join(log_lines), "\n".join(
|
| 235 |
+
f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
|
| 236 |
+
)
|
| 237 |
|
| 238 |
elapsed = time.time() - start
|
| 239 |
log_lines.append(f"=== DONE ===")
|
|
|
|
| 244 |
f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
|
| 245 |
) if matches else "Koi match nahi mila"
|
| 246 |
|
| 247 |
+
yield "\n".join(log_lines), matches_text
|
| 248 |
|
| 249 |
|
| 250 |
# ============================================================
|
|
|
|
| 252 |
# ============================================================
|
| 253 |
with gr.Blocks(title="Phrase Scanner") as demo:
|
| 254 |
gr.Markdown("# π Phrase Scanner")
|
| 255 |
+
gr.Markdown("Apni phrase ya random phrases check karein, index range ke saath.")
|
| 256 |
|
| 257 |
with gr.Row():
|
| 258 |
with gr.Column(scale=1):
|
| 259 |
gr.Markdown("### Settings")
|
| 260 |
+
my_phrase = gr.Textbox(
|
| 261 |
+
label="π Apni Phrase (optional)",
|
| 262 |
+
value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
|
| 263 |
+
lines=2,
|
| 264 |
+
)
|
| 265 |
num_phrases = gr.Number(
|
| 266 |
label="Kitni Random Phrases Check Karein?",
|
| 267 |
+
value=10, precision=0, minimum=0,
|
| 268 |
)
|
| 269 |
addresses_file = gr.Textbox(
|
| 270 |
label="Addresses File",
|
|
|
|
| 309 |
|
| 310 |
run_btn.click(
|
| 311 |
fn=run_multi_phrase_scan,
|
| 312 |
+
inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
|
| 313 |
start_index, end_index, passphrase],
|
| 314 |
outputs=[log_output, matches_output],
|
| 315 |
)
|