Spaces:
Runtime error
Runtime error
Commit Β·
551ac1f
1
Parent(s): 5786039
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,19 +76,8 @@ def phrase_to_seed(phrase, passphrase=""):
|
|
| 76 |
return _seed_fn(phrase, passphrase)
|
| 77 |
return _get_mnemonic().to_seed(phrase, passphrase=passphrase)
|
| 78 |
|
| 79 |
-
# ---------- Address
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
def load_addresses_cached(path):
|
| 83 |
-
if path in _ADDRESS_CACHE:
|
| 84 |
-
cached_mtime, cached_set = _ADDRESS_CACHE[path]
|
| 85 |
-
try:
|
| 86 |
-
current_mtime = os.path.getmtime(path)
|
| 87 |
-
if current_mtime == cached_mtime:
|
| 88 |
-
return cached_set
|
| 89 |
-
except OSError:
|
| 90 |
-
pass
|
| 91 |
-
|
| 92 |
s = set()
|
| 93 |
with open(path, "r", encoding="utf-8") as f:
|
| 94 |
for line in f:
|
|
@@ -97,12 +86,6 @@ def load_addresses_cached(path):
|
|
| 97 |
a = a[2:]
|
| 98 |
if a and len(a) == 40:
|
| 99 |
s.add(a)
|
| 100 |
-
|
| 101 |
-
try:
|
| 102 |
-
mtime = os.path.getmtime(path)
|
| 103 |
-
except OSError:
|
| 104 |
-
mtime = 0
|
| 105 |
-
_ADDRESS_CACHE[path] = (mtime, s)
|
| 106 |
return s
|
| 107 |
|
| 108 |
def normalize(addr):
|
|
@@ -133,21 +116,20 @@ def generate_phrases_for_words(wordlist, mode):
|
|
| 133 |
# ============================================================
|
| 134 |
|
| 135 |
def generate_random_phrase():
|
| 136 |
-
|
|
|
|
|
|
|
| 137 |
|
| 138 |
|
| 139 |
-
def
|
| 140 |
-
|
| 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 |
-
|
| 149 |
-
if
|
| 150 |
-
return "β
|
| 151 |
|
| 152 |
start_index = int(start_index)
|
| 153 |
end_index = int(end_index)
|
|
@@ -155,60 +137,52 @@ def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
|
|
| 155 |
return "β Start index end index se bada nahi ho sakta", ""
|
| 156 |
|
| 157 |
try:
|
| 158 |
-
known =
|
| 159 |
except Exception as e:
|
| 160 |
return f"β Addresses load fail: {e}", ""
|
| 161 |
|
| 162 |
if not known:
|
| 163 |
return "β Koi valid address file mein nahi mila", ""
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
|
| 169 |
log_lines = [
|
| 170 |
-
f"β
Loaded {len(known):,} addresses
|
| 171 |
f"π§ Mode: {phrase_mode}",
|
| 172 |
-
f"π Index range: {start_index}β{end_index}",
|
| 173 |
-
f"π
|
|
|
|
|
|
|
| 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
|
| 185 |
-
log_lines.append(f"π
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 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,15 +201,18 @@ 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 |
-
|
| 236 |
-
label="
|
| 237 |
-
value=
|
|
|
|
|
|
|
| 238 |
)
|
|
|
|
| 239 |
addresses_file = gr.Textbox(
|
| 240 |
label="Addresses File",
|
| 241 |
value="12730802_addresses.csv",
|
|
@@ -277,9 +254,10 @@ with gr.Blocks(title="Phrase Scanner") as demo:
|
|
| 277 |
autoscroll=True,
|
| 278 |
)
|
| 279 |
|
|
|
|
| 280 |
run_btn.click(
|
| 281 |
-
fn=
|
| 282 |
-
inputs=[
|
| 283 |
start_index, end_index, passphrase],
|
| 284 |
outputs=[log_output, matches_output],
|
| 285 |
)
|
|
|
|
| 76 |
return _seed_fn(phrase, passphrase)
|
| 77 |
return _get_mnemonic().to_seed(phrase, passphrase=passphrase)
|
| 78 |
|
| 79 |
+
# ---------- Address file ----------
|
| 80 |
+
def load_addresses(path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
s = set()
|
| 82 |
with open(path, "r", encoding="utf-8") as f:
|
| 83 |
for line in f:
|
|
|
|
| 86 |
a = a[2:]
|
| 87 |
if a and len(a) == 40:
|
| 88 |
s.add(a)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return s
|
| 90 |
|
| 91 |
def normalize(addr):
|
|
|
|
| 116 |
# ============================================================
|
| 117 |
|
| 118 |
def generate_random_phrase():
|
| 119 |
+
"""BIP39 valid phrase generate karta hai β checksum ke saath."""
|
| 120 |
+
mnemo = _get_mnemonic()
|
| 121 |
+
return mnemo.generate(strength=128) # 128 bits = 12 words
|
| 122 |
|
| 123 |
|
| 124 |
+
def run_scan_range(phrase, addresses_file, phrase_mode,
|
| 125 |
+
start_index, end_index, passphrase):
|
| 126 |
+
"""0β20 index range scan β single process, fast."""
|
|
|
|
|
|
|
|
|
|
| 127 |
if not os.path.exists(addresses_file):
|
| 128 |
return f"β File nahi mili: {addresses_file}", ""
|
| 129 |
|
| 130 |
+
words = phrase.strip().split()
|
| 131 |
+
if len(words) != 12:
|
| 132 |
+
return f"β Phrase 12 words ki nahi hai ({len(words)} words)", ""
|
| 133 |
|
| 134 |
start_index = int(start_index)
|
| 135 |
end_index = int(end_index)
|
|
|
|
| 137 |
return "β Start index end index se bada nahi ho sakta", ""
|
| 138 |
|
| 139 |
try:
|
| 140 |
+
known = load_addresses(addresses_file)
|
| 141 |
except Exception as e:
|
| 142 |
return f"β Addresses load fail: {e}", ""
|
| 143 |
|
| 144 |
if not known:
|
| 145 |
return "β Koi valid address file mein nahi mila", ""
|
| 146 |
|
| 147 |
+
total_combos = len(words) * len(words) if phrase_mode == "replace" else math.factorial(len(words)) if phrase_mode == "order" else 2**len(words) - 1
|
| 148 |
+
index_count = end_index - start_index + 1
|
| 149 |
+
total_scans = total_combos * index_count
|
| 150 |
|
| 151 |
log_lines = [
|
| 152 |
+
f"β
Loaded {len(known):,} addresses",
|
| 153 |
f"π§ Mode: {phrase_mode}",
|
| 154 |
+
f"π Index range: {start_index}β{end_index} ({index_count} indices)",
|
| 155 |
+
f"π Phrase: {phrase}",
|
| 156 |
+
f"π’ Combinations per index: {total_combos:,}",
|
| 157 |
+
f"π’ Total scans: {total_scans:,}",
|
| 158 |
"",
|
|
|
|
| 159 |
]
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
matches = []
|
| 162 |
start = time.time()
|
| 163 |
|
| 164 |
+
for idx in range(start_index, end_index + 1):
|
| 165 |
+
log_lines.append(f"π Checking index {idx}...")
|
| 166 |
+
for phrase_str in generate_phrases_for_words(words, phrase_mode):
|
| 167 |
+
if not is_valid_bip39(phrase_str):
|
| 168 |
+
continue
|
| 169 |
+
try:
|
| 170 |
+
seed = phrase_to_seed(phrase_str, passphrase)
|
| 171 |
+
priv = seed_to_privkey_hd(seed, idx)
|
| 172 |
+
pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
|
| 173 |
+
addr = to_checksum_address(keccak(pub)[-20:])
|
| 174 |
+
except Exception:
|
| 175 |
+
continue
|
| 176 |
+
if normalize(addr) in known:
|
| 177 |
+
match_line = (
|
| 178 |
+
f"π MATCH!\n"
|
| 179 |
+
f"Phrase: {phrase_str}\n"
|
| 180 |
+
f"Index: {idx}\n"
|
| 181 |
+
f"Key: {priv.hex()}\n"
|
| 182 |
+
f"Addr: {addr}\n"
|
| 183 |
+
)
|
| 184 |
+
log_lines.append(match_line)
|
| 185 |
+
matches.append((phrase_str, idx, priv.hex(), addr))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
elapsed = time.time() - start
|
| 188 |
log_lines.append(f"=== DONE ===")
|
|
|
|
| 201 |
# ============================================================
|
| 202 |
with gr.Blocks(title="Phrase Scanner") as demo:
|
| 203 |
gr.Markdown("# π Phrase Scanner")
|
| 204 |
+
gr.Markdown("Phrase daalein aur index range (0β20) ke saath address file se match karein.")
|
| 205 |
|
| 206 |
with gr.Row():
|
| 207 |
with gr.Column(scale=1):
|
| 208 |
gr.Markdown("### Settings")
|
| 209 |
+
phrase = gr.Textbox(
|
| 210 |
+
label="π 12-Word Phrase",
|
| 211 |
+
value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
|
| 212 |
+
lines=2,
|
| 213 |
+
placeholder="lesson cushion crane ...",
|
| 214 |
)
|
| 215 |
+
generate_btn = gr.Button("π² Random Phrase Generate Karein", variant="secondary")
|
| 216 |
addresses_file = gr.Textbox(
|
| 217 |
label="Addresses File",
|
| 218 |
value="12730802_addresses.csv",
|
|
|
|
| 254 |
autoscroll=True,
|
| 255 |
)
|
| 256 |
|
| 257 |
+
generate_btn.click(fn=generate_random_phrase, outputs=[phrase])
|
| 258 |
run_btn.click(
|
| 259 |
+
fn=run_scan_range,
|
| 260 |
+
inputs=[phrase, addresses_file, phrase_mode,
|
| 261 |
start_index, end_index, passphrase],
|
| 262 |
outputs=[log_output, matches_output],
|
| 263 |
)
|