コード例 #1
0
 async def unlock_wallet(self, password: str):
     """Unlock wallet with given password, raise DecryptionError if invalid password"""
     crypt = AESCrypt(password)
     decrypted = crypt.decrypt(self.seed)
     # Store decrypted wallet in memory
     SeedStorage.instance().set_decrypted_seed(self.id, decrypted)
     # Decrypt any ad-hoc accounts
     for a in await self.adhoc_accounts.all():
         SeedStorage.instance().set_decrypted_seed(
             f"{self.id}:{a.address}", crypt.decrypt(a.private_key))
コード例 #2
0
ファイル: crypt_tests.py プロジェクト: zh/pippin_nano_wallet
class TestAESCrypt(unittest.TestCase):
    def setUp(self):
        self.crypt1 = AESCrypt('mypassword')
        self.crypt2 = AESCrypt('someotherpassword')

    def test_encrypt_decrypt(self):
        """Test encryption and decryption"""
        some_string = "Some Random String to Encrypt"
        encrypted = self.crypt1.encrypt(some_string)
        self.assertNotEqual(encrypted, some_string)
        self.assertEqual(self.crypt1.decrypt(encrypted), some_string)
        with self.assertRaises(DecryptionError) as exc:
            self.crypt2.decrypt(encrypted)
コード例 #3
0
ファイル: pippin_cli.py プロジェクト: zh/pippin_nano_wallet
async def wallet_representative_set(wallet_id: str, rep: str, update_existing: bool = False):
    # Retrieve wallet
    # Retrieve wallet
    crypt = None
    password=None
    if not Validators.is_valid_address(rep):
        print("Invalid representative")
        exit(1)
    try:
        wallet = await Wallet.get_wallet(wallet_id)
    except WalletNotFound:
        print(f"No wallet found with ID: {wallet_id}")
        exit(1)
    except WalletLocked as wl:
        wallet = wl.wallet
        if update_existing:
            while True:
                try:
                    npass = getpass.getpass(prompt='Enter current password to decrypt wallet:')
                    crypt = AESCrypt(npass)
                    try:
                        decrypted = crypt.decrypt(wl.wallet.seed)
                        wallet = wl.wallet
                        wallet.seed = decrypted
                        password=npass
                    except DecryptionError:
                        print("**Invalid password**")
                except KeyboardInterrupt:
                    break
                    exit(0)

    wallet.representative = rep
    await wallet.save(update_fields=['representative'])
    await wallet.bulk_representative_update(rep)
    print(f"Representative changed")
コード例 #4
0
ファイル: pippin_cli.py プロジェクト: zh/pippin_nano_wallet
async def wallet_change_seed(wallet_id: str, seed: str, password: str) -> str:
    encrypt = False
    old_password = None
    if len(password) > 0:
        encrypt = True

    # Retrieve wallet
    try:
        wallet = await Wallet.get_wallet(wallet_id)
    except WalletNotFound:
        print(f"No wallet found with ID: {wallet_id}")
        exit(1)
    except WalletLocked as wl:
        wallet = wl.wallet
        while True:
            try:
                npass = getpass.getpass(prompt='Enter current password:'******'seed', 'encrypted'])
                        for a in await wallet.adhoc_accounts.all():
                            a.private_key = crypt.decrypt(a.private_key)
                            await a.save(using_db=conn, update_fields=['private_key'])
                    old_password = npass
                    break
                except DecryptionError:
                    print("**Invalid password**")
            except KeyboardInterrupt:
                break
                exit(0)

    # Change key
    await wallet.change_seed(seed)

    # Encrypt if necessary
    if encrypt:
        await wallet.encrypt_wallet(password)

    # Get newest account
    newest = await wallet.get_newest_account()

    print(f"Seed changed for wallet {wallet.id}\nFirst account: {newest.address}")
コード例 #5
0
ファイル: pippin_cli.py プロジェクト: zh/pippin_nano_wallet
async def wallet_view_seed(wallet_id: str, password: str, all_keys: bool) -> str:
    # Retrieve wallet
    crypt = None
    try:
        wallet = await Wallet.get_wallet(wallet_id)
    except WalletNotFound:
        print(f"No wallet found with ID: {wallet_id}")
        exit(1)
    except WalletLocked as wl:
        wallet = None
        if password is not None:
            crypt = AESCrypt(password)
            try:
                decrypted = crypt.decrypt(wl.wallet.seed)
                wallet = wl.wallet
                wallet.seed = decrypted
            except DecryptionError:
                pass
        if wallet is None:
            while True:
                try:
                    npass = getpass.getpass(prompt='Enter current password:')
                    crypt = AESCrypt(npass)
                    try:
                        decrypted = crypt.decrypt(wl.wallet.seed)
                        wallet = wl.wallet
                        wallet.seed = decrypted
                    except DecryptionError:
                        print("**Invalid password**")
                except KeyboardInterrupt:
                    break
                    exit(0)

    print(f"Seed: {wallet.seed}")
    if all_keys:
        for a in await wallet.accounts.all():
            print(f"Addr: {a.address} PrivKey: {nanopy.deterministic_key(wallet.seed, index=a.account_index)[0].upper()}")
    else:
        print(f"AdHoc accounts:")
        for a in await wallet.adhoc_accounts.all():
            if not wallet.encrypted:
                print(f"Addr: {a.address} PrivKey: {a.private_key.upper()}")
            else:
                print(f"Addr: {a.address} PrivKey: {crypt.decrypt(a.private_key)}")
コード例 #6
0
ファイル: pippin_cli.py プロジェクト: zh/pippin_nano_wallet
async def account_create(wallet_id: str, key: str, count: int = 1) -> str:
    # Retrieve wallet
    crypt = None
    password=None
    if count is None:
        count = 1
    try:
        wallet = await Wallet.get_wallet(wallet_id)
    except WalletNotFound:
        print(f"No wallet found with ID: {wallet_id}")
        exit(1)
    except WalletLocked as wl:
        wallet = wl.wallet
        if key is not None:
            while True:
                try:
                    npass = getpass.getpass(prompt='Enter current password to encrypt ad-hoc key:')
                    crypt = AESCrypt(npass)
                    try:
                        decrypted = crypt.decrypt(wl.wallet.seed)
                        wallet = wl.wallet
                        wallet.seed = decrypted
                        password=npass
                    except DecryptionError:
                        print("**Invalid password**")
                except KeyboardInterrupt:
                    break
                    exit(0)

    if key is None:
        if count == 1:
            a = await wallet.account_create()
            print(f"account: {a}")
        else:
            async with in_transaction() as conn:
                ass = await wallet.accounts_create(count=count)
                for a in ass:
                    print(f"account: {a}")
    else:
        a = await wallet.adhoc_account_create(key, password=password)
        print(f"account: {a}")