🔥 Burn Fat Fast. Discover How! 💪

2. Coding Let's start with main.py Here we need the WalletSto | 🎩BLACK HAT🎩

2. Coding
Let's start with main.py

Here we need the WalletStorage class, which will contain the methods for decrypting our wallet. I will ignore the methods we do not need, because we will only focus on password verification. To understand how the initialization of the wallet in Electrum is organized, let's turn to electrum / storage.py, specifically, to the WalletStorage class. When checking the password (key), Electrum initializes the WalletStorage class and calls the check_password () method from it, which calls the decrypt () method. So .. not very clear, as it seems to me. Let's write this construct in pseudocode for clarity:

init class WalletStorage('path_to_walet') --> check_password(password) --> decrypt(password)

More or less ...
In the end, I came to this beginning:



import hashlib
import sys
import os

from src import ecc

class WalletStorage(object):
def __init__(self, path):

self.path = os.path.join( os.path.dirname(os.path.realpath(__file__)), path)
self._file_exists = bool(self.path and os.path.exists(self.path))
self.pubkey = None
self.decrypted = ''

with open(self.path, "r", encoding='utf-8') as f:
self.raw = f.read()

def _get_encryption_magic(self):
return b'BIE1'

def decrypt(self, password) -> None:
ec_key = self.get_eckey_from_password(password)

s = False
if self.raw:
enc_magic = self._get_encryption_magic()
s = ec_key.decrypt_message(self.raw, enc_magic)
if s:
print('[+] %s' % password)

def check_password(self, password) -> None:
self.decrypt(password)

@staticmethod
def get_eckey_from_password(password):
secret = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), b'', iterations=1024)
ec_key = ecc.ECPrivkey.from_arbitrary_size_secret(secret)

return ec_key

def main():

# get wallet name for args
wallet_name = None
if len(sys.argv) != 2:
print('Usage: %s ' % sys.argv[0])
exit()
else:
wallet_name = sys.argv[1]
if not os.path.exists(wallet_name):
print('Wallet not found in current directory.')
exit()

# init wallet
wallet = WalletStorage(wallet_name)

for password in ['test1', 'passwordTest2']:
wallet.check_password(password)

if __name__ == "__main__":
main = main()