Ejemplo n.º 1
0
    async def send_message_to_endpoint_and_key(self, my_ver_key, their_ver_key,
                                               their_endpoint, msg):
        wire_message = {
            'to':
            their_ver_key,
            'from':
            my_ver_key,
            'payload':
            serialize_bytes_json(await crypto.auth_crypt(
                self.wallet_handle, my_ver_key, their_ver_key,
                str_to_bytes(msg.as_json())))
        }

        wire_message = await crypto.pack_message(self.wallet_handle,
                                                 Serializer.pack(msg),
                                                 [their_ver_key], my_ver_key)

        async with aiohttp.ClientSession() as session:
            headers = {'content-type': 'application/ssi-agent-wire'}
            async with session.post(their_endpoint,
                                    data=wire_message,
                                    headers=headers) as resp:
                if resp.status != 202:
                    print(resp.status)
                    print(await resp.text())
Ejemplo n.º 2
0
    async def send_message_to_endpoint_and_key(self, my_ver_key, their_ver_key,
                                               their_endpoint, msg):
        wire_message = {
            'to':
            their_ver_key,
            'from':
            my_ver_key,
            'payload':
            serialize_bytes_json(await crypto.auth_crypt(
                self.wallet_handle, my_ver_key, their_ver_key,
                str_to_bytes(msg.as_json())))
        }

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint,
                                    data=json.dumps(wire_message)) as resp:
                print(resp.status)
                print(await resp.text())
Ejemplo n.º 3
0
    async def send_message(self, msg: Message) -> Message:
        """ UI activated method.
        """

        their_did_str = msg['content']['their_did']
        message_to_send = msg['content']['message']

        pairwise_conn_info_str = await pairwise.get_pairwise(
            self.agent.wallet_handle, their_did_str)
        pairwise_conn_info_json = json.loads(pairwise_conn_info_str)

        my_did_str = pairwise_conn_info_json['my_did']

        data_to_send = json.dumps({"message": message_to_send})

        data_to_send_bytes = str_to_bytes(data_to_send)

        metadata_json = json.loads(pairwise_conn_info_json['metadata'])
        conn_name = metadata_json['conn_name']
        their_endpoint = metadata_json['their_endpoint']
        their_verkey_str = metadata_json['their_verkey']

        my_did_info_str = await did.get_my_did_with_meta(
            self.agent.wallet_handle, my_did_str)
        my_did_info_json = json.loads(my_did_info_str)
        my_verkey_str = my_did_info_json['verkey']

        inner_msg = Message({
            'type':
            CONN.MESSAGE,
            'to':
            "did:sov:ABC",
            'content':
            serialize_bytes_json(await
                                 crypto.auth_crypt(self.agent.wallet_handle,
                                                   my_verkey_str,
                                                   their_verkey_str,
                                                   data_to_send_bytes))
        })

        outer_msg = Message({
            'type': FORWARD.FORWARD,
            'to': "ABC",
            'content': inner_msg
        })

        serialized_outer_msg = Serializer.pack(outer_msg)

        serialized_outer_msg_bytes = str_to_bytes(serialized_outer_msg)

        all_message = Message({
            'content':
            serialize_bytes_json(await
                                 crypto.anon_crypt(their_verkey_str,
                                                   serialized_outer_msg_bytes))
        })

        serialized_msg = Serializer.pack(all_message)

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint,
                                    data=serialized_msg) as resp:
                print(resp.status)
                print(await resp.text())

        return Message({
            'type': CONN_UI.MESSAGE_SENT,
            'id': self.agent.ui_token,
            'content': {
                'name': conn_name
            }
        })
Ejemplo n.º 4
0
    async def send_request(self, msg: Message) -> Message:
        """ UI activated method.
        """

        their_endpoint = msg['content']['endpoint']
        conn_name = msg['content']['name']
        their_connection_key = msg['content']['key']

        my_endpoint_uri = self.agent.endpoint

        (my_endpoint_did_str,
         my_connection_key) = await did.create_and_store_my_did(
             self.agent.wallet_handle, "{}")

        data_to_send = json.dumps({
            "did": my_endpoint_did_str,
            "key": my_connection_key
        })

        data_to_send_bytes = str_to_bytes(data_to_send)

        meta_json = json.dumps({
            "conn_name": conn_name,
            "their_endpoint": their_endpoint
        })

        await did.set_did_metadata(self.agent.wallet_handle,
                                   my_endpoint_did_str, meta_json)

        inner_msg = Message({
            'type':
            CONN.REQUEST,
            'to':
            "did:sov:ABC",
            'endpoint':
            my_endpoint_uri,
            'content':
            serialize_bytes_json(await
                                 crypto.auth_crypt(self.agent.wallet_handle,
                                                   my_connection_key,
                                                   their_connection_key,
                                                   data_to_send_bytes))
        })

        outer_msg = Message({
            'type': FORWARD.FORWARD_TO_KEY,
            'to': "ABC",
            'content': inner_msg
        })

        serialized_outer_msg = Serializer.pack(outer_msg)

        serialized_outer_msg_bytes = str_to_bytes(serialized_outer_msg)

        all_message = Message({
            'type':
            CONN.REQUEST,
            'content':
            serialize_bytes_json(await
                                 crypto.anon_crypt(their_connection_key,
                                                   serialized_outer_msg_bytes))
        })

        serialized_msg = Serializer.pack(all_message)

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint,
                                    data=serialized_msg) as resp:
                print(resp.status)
                print(await resp.text())

        return Message({
            'type': CONN_UI.REQUEST_SENT,
            'id': self.agent.ui_token,
            'content': {
                'name': conn_name
            }
        })
Ejemplo n.º 5
0
    async def send_message(self, msg: Message) -> Message:
        """ UI activated method.
        """

        their_did_str = msg['to']
        message_to_send = msg['message']

        pairwise_conn_info_str = await pairwise.get_pairwise(self.agent.wallet_handle, their_did_str)
        pairwise_conn_info_json = json.loads(pairwise_conn_info_str)

        my_did_str = pairwise_conn_info_json['my_did']
        time_sent = time.time()

        data_to_send = json.dumps(
            {
                "timestamp": time_sent,
                "content": message_to_send
            }
        )

        # store message in the wallet
        await non_secrets.add_wallet_record(
            self.agent.wallet_handle,
            "basicmessage",
            uuid.uuid4().hex,
            json.dumps({
                'from': my_did_str,
                'timestamp': time_sent,
                'content': message_to_send
            }),
            json.dumps({
                "their_did": their_did_str
            })
        )

        data_to_send_bytes = str_to_bytes(data_to_send)

        metadata_json = json.loads(pairwise_conn_info_json['metadata'])
        conn_name = metadata_json['conn_name']
        their_endpoint = metadata_json['their_endpoint']
        their_verkey_str = metadata_json['their_verkey']

        my_did_info_str = await did.get_my_did_with_meta(self.agent.wallet_handle,
                                                         my_did_str)
        my_did_info_json = json.loads(my_did_info_str)
        my_verkey_str = my_did_info_json['verkey']

        inner_msg = Message({
            '@type': BASICMESSAGE.MESSAGE,
            'from': my_did_str,
            'message': serialize_bytes_json(
                await crypto.auth_crypt(self.agent.wallet_handle, my_verkey_str,
                                        their_verkey_str, data_to_send_bytes))
        })

        outer_msg = Message({
            '@type': FORWARD.FORWARD,
            'to': "ABC",
            'content': inner_msg
        })

        serialized_outer_msg = Serializer.pack(outer_msg)

        serialized_outer_msg_bytes = str_to_bytes(serialized_outer_msg)

        all_message = Message({
            'content': serialize_bytes_json(await crypto.anon_crypt(their_verkey_str,
                                                                 serialized_outer_msg_bytes))
        })

        serialized_msg = Serializer.pack(all_message)

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint, data=serialized_msg) as resp:
                print(resp.status)
                print(await resp.text())

        return Message({
            '@type': ADMIN_BASICMESSAGE.MESSAGE_SENT,
            'id': self.agent.ui_token,
            'with': their_did_str,
            'message': {
                'from': my_did_str,
                'timestamp': time_sent,
                'content': message_to_send
            }
        })