DILSHAD737 commited on
Commit
25e4e2e
·
1 Parent(s): 3fdd5c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -58
app.py CHANGED
@@ -1,58 +1,2 @@
1
- # debug_compare.py
2
- from mnemonic import Mnemonic
3
- from eth_account import Account
4
- from eth_utils import keccak, to_checksum_address
5
- import coincurve, hmac, hashlib
6
-
7
- Account.enable_unaudited_hdwallet_features()
8
-
9
- phrase = "lesson cushion crane affair federal decline limb spend reunion chief cart zebra"
10
- TARGET = "0x3f0482fc3e9132c3d3acb5f588e980d7b3a5af07"
11
-
12
- _SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
13
- _HARDENED = 0x80000000
14
-
15
- def _child(priv, chain, index):
16
- if index >= _HARDENED:
17
- data = b'\x00' + priv + index.to_bytes(4, 'big')
18
- else:
19
- pub = coincurve.PrivateKey(priv).public_key.format(compressed=True)
20
- data = pub + index.to_bytes(4, 'big')
21
- I = hmac.new(chain, data, hashlib.sha512).digest()
22
- ki = (int.from_bytes(I[:32], 'big') + int.from_bytes(priv, 'big')) % _SECP256K1_N
23
- return ki.to_bytes(32, 'big'), I[32:]
24
-
25
- def seed_to_privkey_hd(seed, index=0):
26
- I = hmac.new(b"Bitcoin seed", seed, hashlib.sha512).digest()
27
- key, chain = I[:32], I[32:]
28
- for idx in [44 + _HARDENED, 60 + _HARDENED, _HARDENED, 0, index]:
29
- key, chain = _child(key, chain, idx)
30
- return key
31
-
32
- def addr_from_priv(priv):
33
- pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
34
- return to_checksum_address(keccak(pub)[-20:])
35
-
36
- # --- Rust BIP39 ---
37
- import bip39 as _bip39_rust
38
- seed_rust = _bip39_rust.bip39_mnemonic_to_seed(phrase, "")
39
- priv_manual = seed_to_privkey_hd(seed_rust, 0)
40
- addr_manual = addr_from_priv(priv_manual)
41
-
42
- # --- Python Mnemonic ---
43
- seed_py = Mnemonic("english").to_seed(phrase, passphrase="")
44
- priv_py = seed_to_privkey_hd(seed_py, 0)
45
- addr_py = addr_from_priv(priv_py)
46
-
47
- # --- eth_account ---
48
- acct = Account.from_mnemonic(phrase, account_path="m/44'/60'/0'/0/0")
49
-
50
- print(f"Rust seed == Python seed: {seed_rust == seed_py}")
51
- print(f"Manual (Rust): {addr_manual}")
52
- print(f"Manual (Python):{addr_py}")
53
- print(f"eth_account: {acct.address}")
54
- print(f"Target: {TARGET}")
55
- print(f"Manual(Rust) == Target: {addr_manual.lower() == TARGET}")
56
- print(f"Manual(Py) == Target: {addr_py.lower() == TARGET}")
57
- print(f"eth_account == Target: {acct.address.lower() == TARGET}")
58
- print(f"Manual(Rust) == eth_account: {addr_manual.lower() == acct.address.lower()}")
 
1
+ import bip39
2
+ print(dir(bip39)) # ismein kya kya functions hain