Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
def abi_string_to_hex(abi_type, data):
    if abi_type == 'string':
        return abi_type, text_if_str(to_hex, data)
Example #5
0
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})
Example #6
0
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})
Example #7
0
 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)
Example #8
0
 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)
Example #9
0
 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)
Example #10
0
def test_text_if_str_on_text_to_decimal_py2(val):
    assert text_if_str(to_decimal, val) == to_decimal(text=val)
Example #11
0
def test_text_if_str_on_text_py2(val, converter):
    assert text_if_str(converter, val) == converter(text=val)
Example #12
0
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)
Example #13
0
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})
Example #14
0
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})
Example #15
0
 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)
Example #16
0
 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)