Exemplo n.º 1
0
def get_item_list_from_contract(identity_acct: Account) -> list:
    sdk = app.config['ONTOLOGY']
    if not isinstance(sdk, Ontology):
        return list()
    get_item_list_func = WasmInvokeFunction('get_item_list')
    get_item_list_func.set_params_value(identity_acct.get_address())
    tx = sdk.wasm_vm.make_invoke_transaction(
        app.config['CONTRACT_ADDRESS_HEX'], get_item_list_func,
        identity_acct.get_address(), app.config['GAS_PRICE'],
        app.config['GAS_LIMIT'])
    tx.sign_transaction(identity_acct)
    response = sdk.rpc.send_raw_transaction_pre_exec(tx)
    if not isinstance(response, dict):
        return list()
    result = response.get('Result')
    if result is None:
        return list()
    builder = WasmParamsBuilder(bytes.fromhex(result))
    struct_len = builder.read_var_uint()
    album_list = list()
    for _ in range(struct_len):
        try:
            encrypted_ipfs_address_bytes = bytes.fromhex(builder.pop_str())
            ext = builder.pop_str()
            aes_iv = bytes.fromhex(builder.pop_str())
            encode_g_tilde = bytes.fromhex(builder.pop_str())
            ipfs_address = ECIES.decrypt_with_cbc_mode(
                encrypted_ipfs_address_bytes,
                identity_acct.get_private_key_bytes(), aes_iv, encode_g_tilde)
            album_list.append([ipfs_address.decode('ascii'), ext])
        except Exception as e:
            print('Decrypt with cbc mode failed: ', e.args[0])
    return album_list
Exemplo n.º 2
0
 def decrypt_with_ont_id_in_cbc(aes_iv: bytes, encode_g_tilde: bytes,
                                cipher_text: bytes, ont_id_acct: Account):
     if not isinstance(ont_id_acct, Account):
         return b''
     private_key_bytes = ont_id_acct.get_private_key_bytes()
     plain_text = ECIES.decrypt_with_cbc_mode(cipher_text,
                                              private_key_bytes, aes_iv,
                                              encode_g_tilde)
     return plain_text
Exemplo n.º 3
0
 def encrypt_with_ont_id_in_cbc(plain_text: bytes, ont_id_acct: Account):
     if not isinstance(ont_id_acct, Account):
         return b''
     private_key_bytes = ont_id_acct.get_private_key_bytes()
     public_key_bytes = ECDSA.ec_get_public_key_by_private_key(
         private_key_bytes)
     aes_iv, encode_g_tilde, cipher_text = ECIES.encrypt_with_cbc_mode(
         plain_text, public_key_bytes)
     return aes_iv, encode_g_tilde, cipher_text
Exemplo n.º 4
0
 def test_get_private_key_bytes(self):
     hex_private_key = '523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f'
     account = Account(hex_private_key, SignatureScheme.SHA256withECDSA)
     hex_get_private_key_bytes = account.get_private_key_bytes().hex()
     self.assertEqual(hex_private_key, hex_get_private_key_bytes)