def decrypt(keyfile_json, password): if isinstance(keyfile_json, str): keyfile = json.loads(keyfile_json) elif is_dict(keyfile_json): keyfile = keyfile_json else: raise TypeError("The keyfile should be supplied as a JSON string, or a dictionary.") password_bytes = text_if_str(to_bytes, password) return decode_keyfile_json(keyfile, password_bytes)
def decrypt(keyfile_json, password): if isinstance(keyfile_json, str) or ( sys.version_info.major < 3 and isinstance(keyfile_json, unicode)): # noqa: 821 keyfile = json.loads(keyfile_json) elif is_dict(keyfile_json): keyfile = keyfile_json else: raise TypeError("The keyfile should be supplied as a JSON string, or a dictionary.") password_bytes = text_if_str(to_bytes, password) return decode_keyfile_json(keyfile, password_bytes)
def decrypt(keyfile_json, password): if isinstance(keyfile_json, str): keyfile = json.loads(keyfile_json) elif is_dict(keyfile_json): keyfile = keyfile_json else: raise TypeError( "The keyfile should be supplied as a JSON string, or a dictionary." ) password_bytes = text_if_str(to_bytes, password) return decode_keyfile_json(keyfile, password_bytes)
def abi_string_to_hex(abi_type, data): if abi_type == 'string': return abi_type, text_if_str(to_hex, data)
def test_text_if_str_on_text(val): to_type = Mock(return_value='zoot') assert text_if_str(to_type, val) == 'zoot' assert to_type.call_args == ((None, ), {'text': val})
def test_text_if_str_passthrough(val): to_type = Mock(return_value='zoot') assert text_if_str(to_type, val) == 'zoot' assert to_type.call_args == ((val, ), {'text': None})
def encrypt(private_key, password): key_bytes = HexBytes(private_key) password_bytes = text_if_str(to_bytes, password) assert len(key_bytes) == 32 return create_keyfile_json(key_bytes, password_bytes)
def create(self, extra_entropy=''): extra_key_bytes = text_if_str(to_bytes, extra_entropy) key_bytes = keccak(os.urandom(32) + extra_key_bytes) return self.privateKeyToAccount(key_bytes)
def create(self, extra_entropy=''): extra_key_bytes = text_if_str(to_bytes, extra_entropy) key_bytes = keccak(os.urandom(32) + extra_key_bytes) if sys.version_info.major < 3: key_bytes = to_hex(key_bytes) return self.privateKeyToAccount(key_bytes)
def test_text_if_str_on_text_to_decimal_py2(val): assert text_if_str(to_decimal, val) == to_decimal(text=val)
def test_text_if_str_on_text_py2(val, converter): assert text_if_str(converter, val) == converter(text=val)
def test_text_if_str_passthrough_py2(val, converter): if converter is to_decimal and to_bytes(val) == b'': with pytest.raises(ValueError): text_if_str(converter, val) else: assert text_if_str(converter, val) == converter(val)