Spaces:
Runtime error
Runtime error
Commit Β·
53405a2
1
Parent(s): bc5f7a0
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,7 +80,6 @@ def phrase_to_seed(phrase, passphrase=""):
|
|
| 80 |
_ADDRESS_CACHE = {}
|
| 81 |
|
| 82 |
def load_addresses_cached(path):
|
| 83 |
-
"""Addresses ko ek baar load karke cache karta hai."""
|
| 84 |
if path in _ADDRESS_CACHE:
|
| 85 |
cached_mtime, cached_set = _ADDRESS_CACHE[path]
|
| 86 |
try:
|
|
@@ -134,18 +133,21 @@ def generate_phrases_for_words(wordlist, mode):
|
|
| 134 |
# ============================================================
|
| 135 |
|
| 136 |
def generate_random_phrase():
|
| 137 |
-
|
| 138 |
-
return mnemo.generate(strength=128)
|
| 139 |
|
| 140 |
|
| 141 |
-
def
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
if not os.path.exists(addresses_file):
|
| 144 |
return f"β File nahi mili: {addresses_file}", ""
|
| 145 |
|
| 146 |
-
|
| 147 |
-
if
|
| 148 |
-
return
|
| 149 |
|
| 150 |
start_index = int(start_index)
|
| 151 |
end_index = int(end_index)
|
|
@@ -160,45 +162,53 @@ def run_scan_range(phrase, addresses_file, phrase_mode,
|
|
| 160 |
if not known:
|
| 161 |
return "β Koi valid address file mein nahi mila", ""
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
log_lines = [
|
| 168 |
f"β
Loaded {len(known):,} addresses (cached)",
|
| 169 |
f"π§ Mode: {phrase_mode}",
|
| 170 |
-
f"π Index range: {start_index}β{end_index}
|
| 171 |
-
f"π
|
| 172 |
-
f"π’ Combinations per index: {total_combos:,}",
|
| 173 |
-
f"π’ Total scans: {total_scans:,}",
|
| 174 |
"",
|
|
|
|
| 175 |
]
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
matches = []
|
| 178 |
start = time.time()
|
| 179 |
|
| 180 |
-
for
|
| 181 |
-
log_lines.append(f"π Checking
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
elapsed = time.time() - start
|
| 204 |
log_lines.append(f"=== DONE ===")
|
|
@@ -217,18 +227,15 @@ def run_scan_range(phrase, addresses_file, phrase_mode,
|
|
| 217 |
# ============================================================
|
| 218 |
with gr.Blocks(title="Phrase Scanner") as demo:
|
| 219 |
gr.Markdown("# π Phrase Scanner")
|
| 220 |
-
gr.Markdown("
|
| 221 |
|
| 222 |
with gr.Row():
|
| 223 |
with gr.Column(scale=1):
|
| 224 |
gr.Markdown("### Settings")
|
| 225 |
-
|
| 226 |
-
label="
|
| 227 |
-
value=
|
| 228 |
-
lines=2,
|
| 229 |
-
placeholder="lesson cushion crane ...",
|
| 230 |
)
|
| 231 |
-
generate_btn = gr.Button("π² Random Phrase Generate Karein", variant="secondary")
|
| 232 |
addresses_file = gr.Textbox(
|
| 233 |
label="Addresses File",
|
| 234 |
value="12730802_addresses.csv",
|
|
@@ -270,10 +277,9 @@ with gr.Blocks(title="Phrase Scanner") as demo:
|
|
| 270 |
autoscroll=True,
|
| 271 |
)
|
| 272 |
|
| 273 |
-
generate_btn.click(fn=generate_random_phrase, outputs=[phrase])
|
| 274 |
run_btn.click(
|
| 275 |
-
fn=
|
| 276 |
-
inputs=[
|
| 277 |
start_index, end_index, passphrase],
|
| 278 |
outputs=[log_output, matches_output],
|
| 279 |
)
|
|
|
|
| 80 |
_ADDRESS_CACHE = {}
|
| 81 |
|
| 82 |
def load_addresses_cached(path):
|
|
|
|
| 83 |
if path in _ADDRESS_CACHE:
|
| 84 |
cached_mtime, cached_set = _ADDRESS_CACHE[path]
|
| 85 |
try:
|
|
|
|
| 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 |
+
User se poocha gaya number of phrases generate karta hai,
|
| 143 |
+
phir ek ek karke scan karta hai.
|
| 144 |
+
"""
|
| 145 |
if not os.path.exists(addresses_file):
|
| 146 |
return f"β File nahi mili: {addresses_file}", ""
|
| 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)
|
|
|
|
| 162 |
if not known:
|
| 163 |
return "β Koi valid address file mein nahi mila", ""
|
| 164 |
|
| 165 |
+
# Generate phrases
|
| 166 |
+
mnemo = _get_mnemonic()
|
| 167 |
+
phrases = [mnemo.generate(strength=128) for _ in range(num_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"π Phrases to check: {num_phrases}",
|
|
|
|
|
|
|
| 174 |
"",
|
| 175 |
+
"Generated phrases:",
|
| 176 |
]
|
| 177 |
+
for i, p in enumerate(phrases, 1):
|
| 178 |
+
log_lines.append(f" {i}. {p}")
|
| 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}/{num_phrases}] Checking: {phrase}")
|
| 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
|
| 195 |
+
try:
|
| 196 |
+
seed = phrase_to_seed(phrase_str, passphrase)
|
| 197 |
+
priv = seed_to_privkey_hd(seed, idx)
|
| 198 |
+
pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
|
| 199 |
+
addr = to_checksum_address(keccak(pub)[-20:])
|
| 200 |
+
except Exception:
|
| 201 |
+
continue
|
| 202 |
+
if normalize(addr) in known:
|
| 203 |
+
match_line = (
|
| 204 |
+
f"π MATCH!\n"
|
| 205 |
+
f"Phrase: {phrase_str}\n"
|
| 206 |
+
f"Index: {idx}\n"
|
| 207 |
+
f"Key: {priv.hex()}\n"
|
| 208 |
+
f"Addr: {addr}\n"
|
| 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 ===")
|
|
|
|
| 227 |
# ============================================================
|
| 228 |
with gr.Blocks(title="Phrase Scanner") as demo:
|
| 229 |
gr.Markdown("# π Phrase Scanner")
|
| 230 |
+
gr.Markdown("Kitni random phrases check karni hain? Phir index range ke saath scan karein.")
|
| 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=1,
|
|
|
|
|
|
|
| 238 |
)
|
|
|
|
| 239 |
addresses_file = gr.Textbox(
|
| 240 |
label="Addresses File",
|
| 241 |
value="12730802_addresses.csv",
|
|
|
|
| 277 |
autoscroll=True,
|
| 278 |
)
|
| 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 |
)
|