def test_key( filename, testname, testdata, ): logger.debug('running test:%r in %r' % (testname, filename)) assert keys.check_keystore_json(testdata["json"]) privkey = keys.decode_keystore_json(testdata["json"], testdata["password"]) assert utils.encode_hex(privkey) == utils.to_string(testdata["priv"])
def unlock(self, password): """Unlock the account with a password. If the account is already unlocked, nothing happens, even if the password is wrong. :raises: :exc:`ValueError` (originating in ethereum.keys) if the password is wrong (and the account is locked) """ if self.locked: self._privkey = keys.decode_keystore_json(self.keystore, password) self.locked = False self.address # get address such that it stays accessible after a subsequent lock
def __init__(self, datadir): keyfile = path.join(datadir, 'ethkey.json') if path.exists(keyfile): data = json.load(open(keyfile, 'r')) self.priv = keys.decode_keystore_json(data, "FIXME: password!") else: self.priv = os.urandom(32) data = keys.make_keystore_json(self.priv, "FIXME: password!") json.dump(data, open(keyfile, 'w')) self.address = keys.privtoaddr(self.priv)
def unlock(self, password): """Unlock the account with a password. If the account is already unlocked, nothing happens, even if the password is wrong. :raises: :exc:`ValueError` (originating in ethereum.keys) if the password is wrong (and the account is locked) """ if self.locked: self._privkey = keys.decode_keystore_json(self.keystore, password) self.locked = False
def load_wallet( wallet_filename, password ): assert os.path.isfile( wallet_filename ) with open( wallet_filename ) as f: wallet_json = json.load(f) address = wallet_json['address'] priv_key = decode_keystore_json(wallet_json, password) return address, priv_key
def __init__(self, keyfile, passfile_or_password): with open(keyfile) as data_file: data = json.load(data_file) if os.path.isfile(passfile_or_password): with open(passfile_or_password) as f: password = f.read().strip('\n') else: password = passfile_or_password privkey_bin = decode_keystore_json(data, password) self.private_key = PrivateKey(privkey_bin)
def get_private_key(key_path, password_path=None): """Open a JSON-encoded private key and return it If a password file is provided, uses it to decrypt the key. If not, the password is asked interactively. Raw hex-encoded private keys are supported, but deprecated.""" assert key_path, key_path if not os.path.exists(key_path): log.fatal("%s: no such file", key_path) return None if not check_permission_safety(key_path): log.fatal("Private key file %s must be readable only by its owner.", key_path) return None if password_path and not check_permission_safety(password_path): log.fatal("Password file %s must be readable only by its owner.", password_path) return None with open(key_path) as keyfile: private_key = keyfile.readline().strip() if is_hex(private_key) and len(decode_hex(private_key)) == 32: log.warning( "Private key in raw format. Consider switching to JSON-encoded" ) else: keyfile.seek(0) try: json_data = json.load(keyfile) if password_path: with open(password_path) as password_file: password = password_file.readline().strip() else: password = getpass.getpass( "Enter the private key password: "******"Invalid private key format or password!") return None return private_key
def get_private_key(key_path, password_path=None): """Open a JSON-encoded private key and return it If a password file is provided, uses it to decrypt the key. If not, the password is asked interactively. Raw hex-encoded private keys are supported, but deprecated.""" assert key_path, key_path if not os.path.exists(key_path): log.fatal("%s: no such file", key_path) return None if not check_permission_safety(key_path): log.fatal("Private key file %s must be readable only by its owner.", key_path) return None if password_path and not check_permission_safety(password_path): log.fatal("Password file %s must be readable only by its owner.", password_path) return None with open(key_path) as keyfile: private_key = keyfile.readline().strip() if is_hex(private_key) and len(decode_hex(private_key)) == 32: log.warning("Private key in raw format. Consider switching to JSON-encoded") else: keyfile.seek(0) try: json_data = json.load(keyfile) if password_path: with open(password_path) as password_file: password = password_file.readline().strip() else: password = getpass.getpass("Enter the private key password: "******"Invalid private key format or password!") return None return private_key
def test_key(filename, testname, testdata,): logger.debug('running test:%r in %r' % (testname, filename)) assert keys.check_keystore_json(testdata["json"]) privkey = keys.decode_keystore_json(testdata["json"], testdata["password"]) assert utils.encode_hex(privkey) == utils.to_string(testdata["priv"])
print(' Gas: ' + str(tx.startgas)) print(' Gas Price: ' + str(tx.gasprice)) print('Transaction amount (in wei): ' + str(tx.value)) print('Transaction amount (in eth): ' + str(web3.fromWei(tx.value, 'ether'))) print(' From Nonce: ' + str(tx.nonce)) print(' To Address: ' + web3.toHex(tx.to)) print(' Transaction Data: ' + web3.toHex(tx.data)) print('======================================================') # Using file wallet to sign transaction if args.keytype == 'file': json = json.loads(open(args.keyfile).read()) print("Enter password of keyfile or ctrl+c to cancel") pw = getpass() print("Applying hard key derivation function. Wait a little") k = decode_keystore_json(json, pw) # Prepare a new transaction (decoded transaction seems immutable...) tx = Transaction( tx.nonce, tx.gasprice, tx.startgas, tx.to, tx.value, tx.data ) tx.sign(k) # Using Ledger HW1 in DEV mode (SIGNVERIFY_IMMEDIATE) if args.keytype == 'dongle': from btchip.btchip import getDongle, btchip from bitcoin import decode_sig as bitcoin_decode_sig dongle = getDongle(True) app = btchip(dongle) print("Enter pin of dongle or ctrl+c to cancel") pin = getpass('Pin:')
def do_test_key(filename, testname=None, testdata=None, limit=99999999): logger.debug('running test:%r in %r' % (testname, filename)) privkey = keys.decode_keystore_json(testdata["json"], testdata["password"]) assert utils.encode_hex(privkey) == utils.to_string(testdata["priv"])