Spaces:
Runtime error
Runtime error
Commit ·
b1b57bc
1
Parent(s): 45a1779
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,52 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
if a.startswith("0x"):
|
| 8 |
-
a = a[2:]
|
| 9 |
-
if a and len(a) == 40:
|
| 10 |
-
s.add(a)
|
| 11 |
-
return frozenset(s)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# debug_derive.py
|
| 2 |
+
import hashlib, hmac
|
| 3 |
+
from eth_account import Account
|
| 4 |
+
from mnemonic import Mnemonic
|
| 5 |
+
from eth_utils import keccak, to_checksum_address
|
| 6 |
+
import coincurve
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
phrase = "lesson cushion crane affair federal decline limb spend reunion chief cart zebra"
|
| 9 |
+
TARGET = "0x3f0482fc3e9132c3d3acb5f588e980d7b3a5af07"
|
| 10 |
|
| 11 |
+
# --- 1. Aapka manual BIP32 code (jo aapke script mein hai) ---
|
| 12 |
+
_SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
|
| 13 |
+
_HARDENED = 0x80000000
|
| 14 |
|
| 15 |
+
def _bip32_derive_child_priv(parent_priv, parent_chain, index):
|
| 16 |
+
if index >= _HARDENED:
|
| 17 |
+
data = b'\x00' + parent_priv + index.to_bytes(4, 'big')
|
| 18 |
+
else:
|
| 19 |
+
pub = coincurve.PrivateKey(parent_priv).public_key.format(compressed=True)
|
| 20 |
+
data = pub + index.to_bytes(4, 'big')
|
| 21 |
+
I = hmac.new(parent_chain, data, hashlib.sha512).digest()
|
| 22 |
+
child_int = (int.from_bytes(I[:32], 'big') + int.from_bytes(parent_priv, 'big')) % _SECP256K1_N
|
| 23 |
+
if child_int == 0:
|
| 24 |
+
raise ValueError("Invalid child key")
|
| 25 |
+
return child_int.to_bytes(32, 'big'), I[32:]
|
| 26 |
+
|
| 27 |
+
def seed_to_privkey_hd(seed, address_index=0):
|
| 28 |
+
I = hmac.new(b"Bitcoin seed", seed, hashlib.sha512).digest()
|
| 29 |
+
key, chain = I[:32], I[32:]
|
| 30 |
+
path = [44 + _HARDENED, 60 + _HARDENED, _HARDENED, 0, address_index]
|
| 31 |
+
for idx in path:
|
| 32 |
+
key, chain = _bip32_derive_child_priv(key, chain, idx)
|
| 33 |
+
return key
|
| 34 |
+
|
| 35 |
+
# --- 2. Manual derivation se address ---
|
| 36 |
+
seed = Mnemonic("english").to_seed(phrase, passphrase="")
|
| 37 |
+
priv_manual = seed_to_privkey_hd(seed, 0)
|
| 38 |
+
pub_manual = coincurve.PrivateKey(priv_manual).public_key.format(compressed=False)[1:]
|
| 39 |
+
addr_manual = to_checksum_address(keccak(pub_manual)[-20:])
|
| 40 |
+
|
| 41 |
+
# --- 3. eth_account se address ---
|
| 42 |
+
acct = Account.from_mnemonic(phrase, account_path="m/44'/60'/0'/0/0")
|
| 43 |
+
addr_standard = acct.address
|
| 44 |
+
|
| 45 |
+
# --- 4. Result ---
|
| 46 |
+
print(f"Manual BIP32: {addr_manual}")
|
| 47 |
+
print(f"eth_account: {addr_standard}")
|
| 48 |
+
print(f"Target: {TARGET}")
|
| 49 |
+
print()
|
| 50 |
+
print(f"Manual == Target: {addr_manual.lower() == TARGET.lower()}")
|
| 51 |
+
print(f"eth_account == Target: {addr_standard.lower() == TARGET.lower()}")
|
| 52 |
+
print(f"Manual == eth_account: {addr_manual.lower() == addr_standard.lower()}")
|