Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
get pass from file
Browse files Browse the repository at this point in the history
  • Loading branch information
BlinkyStitt committed Mar 14, 2017
1 parent aa831e9 commit c32badd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion joinmarket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .slowaes import decryptData, encryptData
from .taker import Taker, OrderbookWatch, CoinJoinTX
from .wallet import AbstractWallet, BitcoinCoreInterface, Wallet, \
BitcoinCoreWallet
BitcoinCoreWallet, get_wallet_pass
from .configure import load_program_config, jm_single, get_p2pk_vbyte, \
get_network, jm_single, get_network, validate_address, get_irc_mchannels, \
check_utxo_blacklist
Expand Down
29 changes: 25 additions & 4 deletions joinmarket/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@

log = get_log()


def get_wallet_pass(wallet_filename=None, password=None, confirm=False):
if password:
return password

if wallet_filename:
pass_filename = wallet_filename[:-4] + 'pass'
if os.path.exists(pass_filename):
with open(pass_filename, 'r') as f:
return f.read().strip()

password = getpass('Enter wallet encryption passphrase: ')

if not confirm:
return password

password2 = getpass('Reenter wallet encryption passphrase: ')
if password2 != password:
raise ValueError('Passwords did not match')

return password


def estimate_tx_fee(ins, outs, txtype='p2pkh'):
'''Returns an estimate of the number of satoshis required
for a transaction with the given number of inputs and outputs,
Expand Down Expand Up @@ -178,10 +201,8 @@ def read_wallet_file_data(self, filename, pwd=None):
self.max_mix_depth - len(self.index_cache))
decrypted = False
while not decrypted:
if pwd:
password = pwd
else:
password = getpass('Enter wallet decryption passphrase: ')
password = get_wallet_pass(wallet_filename=filename, password=pwd)

password_key = btc.bin_dbl_sha256(password)
encrypted_seed = walletdata['encrypted_seed']
try:
Expand Down
24 changes: 11 additions & 13 deletions wallet-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from joinmarket import load_program_config, get_network, Wallet, encryptData, \
get_p2pk_vbyte, jm_single, mn_decode, mn_encode, BitcoinCoreInterface, \
JsonRpcError, sync_wallet
JsonRpcError, sync_wallet, get_wallet_pass

import bitcoin as btc

Expand Down Expand Up @@ -219,18 +219,6 @@ def cus_print(s):
sys.exit(0)
seed = mn_decode(words)
print(seed)
password = getpass.getpass('Enter wallet encryption passphrase: ')
password2 = getpass.getpass('Reenter wallet encryption passphrase: ')
if password != password2:
print('ERROR. Passwords did not match')
sys.exit(0)
password_key = btc.bin_dbl_sha256(password)
encrypted_seed = encryptData(password_key, seed.decode('hex'))
timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
walletfile = json.dumps({'creator': 'joinmarket project',
'creation_time': timestamp,
'encrypted_seed': encrypted_seed.encode('hex'),
'network': get_network()})

default_walletname = 'wallet.json'
walletpath = os.path.join('wallets', default_walletname)
Expand All @@ -252,6 +240,16 @@ def cus_print(s):
print('ERROR: ' + walletpath + ' already exists. Aborting.')
sys.exit(0)
else:
password = get_wallet_pass(confirm=True, wallet_filename=walletpath)
password_key = btc.bin_dbl_sha256(password)
encrypted_seed = encryptData(password_key, seed.decode('hex'))
timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
walletfile = json.dumps({'creator': 'joinmarket project',
'creation_time': timestamp,
'encrypted_seed': encrypted_seed.encode('hex'),
'network': get_network()})


fd = open(walletpath, 'w')
fd.write(walletfile)
fd.close()
Expand Down

0 comments on commit c32badd

Please sign in to comment.