Beispiel #1
0
    async def generate_invite(self, msg: Message) -> None:
        """ Generate new connection invitation.

            This interaction represents an out-of-band communication channel. In the future and in
            practice, these sort of invitations will be received over any number of channels such as
            SMS, Email, QR Code, NFC, etc.

            Structure of an invite message:

                {
                    "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    "label": "Alice",
                    "did": "did:sov:QmWbsNYhMrjHiqZDTUTEJs"
                }

            Or, in the case of a peer DID:

                {
                    "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    "label": "Alice",
                    "did": "did:peer:oiSqsNYhMrjHiqZDTUthsw",
                    "key": "8HH5gYEeNc3z7PYXmd54d4x6qAfCNrqQqEB3nS7Zfu7K",
                    "endpoint": "https://example.com/endpoint"
                }

            Currently, only peer DID is supported.
        """
        connection_key = await did.create_key(self.agent.wallet_handle, "{}")

        # Store connection key
        await non_secrets.add_wallet_record(
            self.agent.wallet_handle,
            'connection_key',
            connection_key,
            connection_key,
            '{}'
        )

        invite_msg = Message({
            '@type': Connection.INVITE,
            'label': self.agent.owner,
            'recipientKeys': [connection_key],
            'serviceEndpoint': self.agent.endpoint,
            # routingKeys not specified, but here is where they would be put in the invite.
        })

        b64_invite = \
            base64.urlsafe_b64encode(Serializer.serialize(invite_msg)).decode('ascii')

        await self.agent.send_admin_message(
            Message({
                '@type': AdminConnection.INVITE_GENERATED,
                'invite': '{}?c_i={}'.format(self.agent.endpoint, b64_invite)
            })
        )
Beispiel #2
0
    async def send_message(self, msg: Message) -> None:
        """ UI activated method providing a message to be sent.

        :param msg: Message from the UI to send a basic message to another Indy agent. It contains:
            {
                '@type': AdminBasicMessage.SEND_MESSAGE,
                'from': 'TkbZ5zphpvX4MYDhRRQ5o7',  # DID of the sender of the message.
                'to': 'Q3TnvPk6QtRazeiALDdLGs',  # DID fo the recipient of the message.
                'message': 'Hello',  # text of the message to be sent.
            }
        """
        my_did_str = msg['from']
        their_did_str = msg['to']
        message_to_send = msg['message']
        sent_time = datetime.datetime.utcnow().replace(
            tzinfo=datetime.timezone.utc).isoformat(' ')

        # 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,
                'sent_time': sent_time,
                'content': message_to_send
            }), json.dumps({'their_did': their_did_str}))

        message = Message({
            '@type': BasicMessage.MESSAGE,
            '~l10n': {
                'locale': 'en'
            },
            'sent_time': sent_time,
            'content': message_to_send
        })

        await self.agent.send_message_to_agent(their_did_str, message)

        await self.agent.send_admin_message(
            Message({
                '@type': AdminBasicMessage.MESSAGE_SENT,
                'id': self.agent.ui_token,
                'with': their_did_str,
                'message': {
                    'from': my_did_str,
                    'sent_time': sent_time,
                    'content': message_to_send
                }
            }))
Beispiel #3
0
    async def send_trustping(self, msg: Message) -> None:
        """ UI activated method.
        """

        their_did_str = msg['to']

        message = Message({'@type': TrustPing.PING})

        await self.agent.send_message_to_agent(their_did_str, message)

        await self.agent.send_admin_message(
            Message({
                '@type': AdminTrustPing.TRUSTPING_SENT,
                'to': their_did_str,
            }))
Beispiel #4
0
    async def ping(self, msg: Message) -> Message:
        await self.agent.send_admin_message(
            Message({
                '@type': AdminTrustPing.TRUSTPING_RECEIVED,
                'from': msg.context['from_did'],
            }))

        await self.agent.send_message_to_agent(
            msg.context['from_did'],
            Message({
                '@type': TrustPing.PING_RESPONSE,
                '~thread': {
                    'thid': msg.id
                }
            }))
Beispiel #5
0
    async def send_message(self, msg: Message) -> Message:
        """ UI activated method.
        """

        # This lookup block finds the from address from the to address. This should be fixed, so that the from address
        #  comes in the admin message.
        their_did_str = msg['to']
        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']

        message_to_send = msg['message']
        sent_time = datetime.datetime.utcnow().replace(
            tzinfo=datetime.timezone.utc).isoformat(' ')

        # 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,
                'sent_time': sent_time,
                'content': message_to_send
            }), json.dumps({"their_did": their_did_str}))

        message = Message({
            '@type': BasicMessage.MESSAGE,
            '~l10n': {
                'locale': 'en'
            },
            'sent_time': sent_time,
            'content': message_to_send
        })

        await self.agent.send_message_to_agent(their_did_str, message)

        await self.agent.send_admin_message(
            Message({
                '@type': AdminBasicMessage.MESSAGE_SENT,
                'id': self.agent.ui_token,
                'with': their_did_str,
                'message': {
                    'from': my_did_str,
                    'sent_time': sent_time,
                    'content': message_to_send
                }
            }))
Beispiel #6
0
    async def receive_message(self, msg: Message):
        r = await self.validate_common_message_blocks(msg, BasicMessage.FAMILY)
        if not r:
            return r

        # store message in the wallet
        await non_secrets.add_wallet_record(
            self.agent.wallet_handle, "basicmessage",
            uuid.uuid4().hex,
            json.dumps({
                'from': msg.context['from_did'],
                'sent_time': msg['sent_time'],
                'content': msg['content']
            }), json.dumps({"their_did": msg.context['from_did']}))

        await self.agent.send_admin_message(
            Message({
                '@type': AdminBasicMessage.MESSAGE_RECEIVED,
                'id': self.agent.ui_token,
                'with': msg.context['from_did'],
                'message': {
                    'from': msg.context['from_did'],
                    'sent_time': msg['sent_time'],
                    'content': msg['content']
                }
            }))
Beispiel #7
0
 def build_problem_report_for_connections(family, problem_code,
                                          problem_str):
     return Message({
         "@type": "{}problem_report".format(family),
         "problem-code": problem_code,
         "explain": problem_str
     })
Beispiel #8
0
def unpack(dump) -> Message:
    """
    Deserialize from bytes or str to Message
    """
    dump_dict = json.loads(dump)
    deserialized_msg = Message(dump_dict)
    return deserialized_msg
Beispiel #9
0
    async def ping(self, msg: Message) -> None:
        r = await self.validate_common_message_blocks(msg, TrustPing.FAMILY)
        if not r:
            return

        await self.agent.send_admin_message(
            Message({
                '@type': AdminTrustPing.TRUSTPING_RECEIVED,
                'from': msg.context['from_did'],
            }))

        await self.agent.send_message_to_agent(
            msg.context['from_did'],
            Message({
                '@type': TrustPing.PING_RESPONSE,
                '~thread': {
                    Message.THREAD_ID: msg.id,
                    Message.SENDER_ORDER: 0
                }
            }))
Beispiel #10
0
    async def state_request(self, _) -> Message:
        print("Processing state_request")

        if self.agent.initialized:
            invitations = await get_wallet_records(self.agent.wallet_handle,
                                                   "invitations")

            # load up pairwise connections
            pairwise_records = []
            agent_pairwises_list_str = await pairwise.list_pairwise(
                self.agent.wallet_handle)
            agent_pairwises_list = json.loads(agent_pairwises_list_str)
            for agent_pairwise_str in agent_pairwises_list:
                pairwise_record = json.loads(agent_pairwise_str)
                pairwise_record['metadata'] = json.loads(
                    pairwise_record['metadata'])
                pairwise_records.append(pairwise_record)

            await self.agent.send_admin_message(
                Message({
                    '@type': self.STATE,
                    'content': {
                        'initialized': self.agent.initialized,
                        'agent_name': self.agent.owner,
                        'invitations': invitations,
                        'pairwise_connections': pairwise_records,
                    }
                }))
        else:
            await self.agent.send_admin_message(
                Message({
                    '@type': self.STATE,
                    'content': {
                        'initialized': self.agent.initialized,
                    }
                }))
    async def connect(self, msg: Message) -> None:
        """ Connect to an existing wallet.
        """
        try:
            await self.agent.connect_wallet(msg['name'], msg['passphrase'])
        except WalletConnectionException:
            await self.agent.send_admin_message(
                Message({
                    '@type': AdminWalletConnection.USER_ERROR,
                    'error_code': 'invalid_passphrase',
                    'message': 'Invalid Passphrase',
                    'thread': {
                        'thid': msg['id']
                    }
                }))

        # Prompt a STATE message.
        return await self.agent.modules[Admin.FAMILY].state_request(None)
    async def connect(self, msg):
        """ Connect to existing wallet.
        """

        try:
            await self.agent.connect_wallet(msg['name'], msg['passphrase'])
        except WalletConnectionException:
            return Message({
                '@type': AdminWalletConnection.USER_ERROR,
                'error_code': "invalid_passphrase",
                'message': "Invalid Passphrase",
                'thread': {
                    'thid': msg.id
                }
            })

        # prompt a STATE message.
        return await self.agent.modules[Admin.FAMILY].state_request(None)
Beispiel #13
0
    async def receive_message(self, msg: Message) -> None:
        """ Process the reception of a basic message from another Indy agent.

        :param msg: Basic message is of the following format:
            {
                '@type': BasicMessage.MESSAGE,
                '~l10n': {'locale': 'en'},
                'sent_time': '2019-05-27 08:34:25.105373+00:00',
                'content': 'Hello'
            }
        :return: None
        """
        is_valid = await self.validate_common_message_blocks(
            msg, BasicMessage.FAMILY)
        if not is_valid:
            return

        # Store message in the wallet
        await non_secrets.add_wallet_record(
            self.agent.wallet_handle, 'basicmessage',
            uuid.uuid4().hex,
            json.dumps({
                'from': msg.context['from_did'],
                'sent_time': msg['sent_time'],
                'content': msg['content']
            }), json.dumps({'their_did': msg.context['from_did']}))

        await self.agent.send_admin_message(
            Message({
                '@type': AdminBasicMessage.MESSAGE_RECEIVED,
                'id': self.agent.ui_token,
                'with': msg.context['from_did'],
                'message': {
                    'from': msg.context['from_did'],
                    'sent_time': msg['sent_time'],
                    'content': msg['content']
                }
            }))
Beispiel #14
0
    async def get_messages(self, msg: Message) -> None:
        """ UI activated method requesting a list of messages exchanged with a given agent.

        :param msg: Message from the UI to get a list of message exchanged with a given DID:
            {
                '@type': AdminBasicMessage.GET_MESSAGES,
                'with': 'CzznW3pTbFr2YqDCGWWf8x',  # DID of other party with whom messages
                                                   # have been exchanged
            }
        :return: None
        """
        their_did = msg['with']
        messages = await get_wallet_records(
            self.agent.wallet_handle, 'basicmessage',
            json.dumps({'their_did': their_did}))
        messages = sorted(messages, key=lambda n: n['sent_time'], reverse=True)

        await self.agent.send_admin_message(
            Message({
                '@type': AdminBasicMessage.MESSAGES,
                'with': their_did,
                'messages': messages
            }))
Beispiel #15
0
    async def get_messages(self, msg: Message) -> Message:
        their_did = msg['with']
        search_handle = await non_secrets.open_wallet_search(
            self.agent.wallet_handle, "basicmessage",
            json.dumps({"their_did": their_did}), json.dumps({}))
        results = await non_secrets.fetch_wallet_search_next_records(
            self.agent.wallet_handle, search_handle, 100)

        messages = []
        for r in json.loads(
                results)["records"] or []:  # records is None if empty
            d = json.loads(r['value'])
            d["_id"] = r["id"]  # include record id for further reference.
            messages.append(d)
        #TODO: fetch in loop till all records are processed
        await non_secrets.close_wallet_search(search_handle)
        messages = sorted(messages, key=lambda n: n['sent_time'], reverse=True)

        await self.agent.send_admin_message(
            Message({
                '@type': AdminBasicMessage.MESSAGES,
                'with': their_did,
                'messages': messages
            }))
Beispiel #16
0
    async def create_static_connection(self, msg: Message) -> Message:
        """ Generate new connection invitation.

            This interaction represents an out-of-band communication channel. In the future and in
            practice, these sort of invitations will be received over any number of channels such as
            SMS, Email, QR Code, NFC, etc.

            Structure of an invite message:

                {
                    "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    "label": "Alice",
                    "did": "did:sov:QmWbsNYhMrjHiqZDTUTEJs"
                }

            Or, in the case of a peer DID:

                {
                    "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    "label": "Alice",
                    "did": "did:peer:oiSqsNYhMrjHiqZDTUthsw",
                    "key": "8HH5gYEeNc3z7PYXmd54d4x6qAfCNrqQqEB3nS7Zfu7K",
                    "endpoint": "https://example.com/endpoint"
                }

            Currently, only peer DID is supported.
        """
        their_did = msg['did']
        their_vk = msg['vk']
        their_endpoint = msg['endpoint']
        label = msg['label']

        # Store their information from request
        await utils.store_their_did(self.agent.wallet_handle, their_did,
                                    their_vk)

        await did.set_did_metadata(
            self.agent.wallet_handle, their_did,
            json.dumps({
                'label': label,
                'endpoint': their_endpoint,
            }))

        # Create my information for connection
        (my_did,
         my_vk) = await utils.create_and_store_my_did(self.agent.wallet_handle)

        # Create pairwise relationship between my did and their did
        await pairwise.create_pairwise(
            self.agent.wallet_handle, their_did, my_did,
            json.dumps({
                'label': label,
                'their_endpoint': their_endpoint,
                'their_vk': their_vk,
                'my_vk': my_vk,
                'static': True
            }))

        await self.agent.send_admin_message(
            Message({
                '@type': AdminStaticConnection.STATIC_CONNECTION_CREATED,
                'label': label,
                'my_did': my_did,
                'my_vk': my_vk,
                'my_endpoint': self.agent.endpoint
            }))
Beispiel #17
0
    async def request_received(self, msg: Message) -> None:
        """ Received connection request.

            Request format:

                {
                  "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/request",
                  "label": "Bob",
                  "connection":{
                      "did": "B.did@B:A",
                      "did_doc": {
                          "@context": "https://w3id.org/did/v1",
                          "publicKey": [{
                            "id": "did:example:123456789abcdefghi#keys-1",
                            "type": "Ed25519VerificationKey2018",
                            "controller": "did:example:123456789abcdefghi",
                            "publicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
                          }],
                          "service": [{
                            "type": "IndyAgent",
                            "recipientKeys" : [ "<verkey>" ], //pick one
                            "routingKeys": ["<example-agency-verkey>"],
                            "serviceEndpoint": "https://example.agency.com",
                          }]
                      }
                  }
                }
        """
        r = await self.validate_common_message_blocks(msg, Connection.FAMILY)
        if not r:
            return

        try:
            ConnectionMessage.Request.validate(msg)
        except Exception as e:
            vk, endpoint = ConnectionMessage.extract_verkey_endpoint(msg)
            if None in (vk, endpoint):
                # Cannot extract verkey and endpoint hence won't send any message back.
                print('Encountered error parsing connection request ', e)
            else:
                # Sending an error message back to the sender
                err_msg = self.build_problem_report_for_connections(Connection.FAMILY, ConnectionMessage.REQUEST_NOT_ACCEPTED, str(e))
                await self.agent.send_message_to_endpoint_and_key(vk, endpoint, err_msg)
            return

        connection_key = msg.context['to_key']

        label = msg['label']

        their_did, their_vk, their_endpoint = ConnectionMessage.extract_their_info(msg)

        # Store their information from request
        await utils.store_their_did(self.agent.wallet_handle, their_did, their_vk)

        await did.set_did_metadata(
            self.agent.wallet_handle,
            their_did,
            json.dumps({
                'label': label,
                'endpoint': their_endpoint,

            })
        )

        # Create my information for connection
        (my_did, my_vk) = await utils.create_and_store_my_did(self.agent.wallet_handle)

        # Create pairwise relationship between my did and their did
        await pairwise.create_pairwise(
            self.agent.wallet_handle,
            their_did,
            my_did,
            json.dumps({
                'label': label,
                'req_id': msg['@id'],
                'their_endpoint': their_endpoint,
                'their_vk': their_vk,
                'my_vk': my_vk,
                'connection_key': connection_key  # used to sign the response
            })
        )

        pending_connection = Message({
            '@type': AdminConnection.REQUEST_RECEIVED,
            'label': label,
            'did': their_did,
            'connection_key': connection_key,
            'endpoint': their_endpoint,
            'history': [{
                'date': str(datetime.datetime.now()),
                'msg': msg.to_dict()}],
            'status': "Request Received"
            # routingKeys not specified, but here is where they would be put in the invite.
        })
        try:
            await non_secrets.add_wallet_record(
                self.agent.wallet_handle,
                'invitations',
                connection_key,
                Serializer.serialize(pending_connection).decode('utf-8'),
                '{}'
            )
        except error.IndyError as indy_error:
            if indy_error.error_code == error.ErrorCode.WalletItemAlreadyExists:
                pass
            raise indy_error
        await self.agent.send_admin_message(pending_connection)
Beispiel #18
0
    async def send_response(self, msg: Message) -> None:
        """ Send response to request.

            send_response message format:
                {
                  "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin_connections/1.0/send_response",
                  "did": <did of request sender>
                }

            Response format:
                {
                  "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/response",
                  "did":"A.did@A:B",
                  "did_doc": {
                      //did doc
                  }
                }
        """

        their_did = msg['did']

        pairwise_info = json.loads(await pairwise.get_pairwise(self.agent.wallet_handle, their_did))
        pairwise_meta = json.loads(pairwise_info['metadata'])

        my_did = pairwise_info['my_did']
        my_vk = await did.key_for_local_did(self.agent.wallet_handle, my_did)

        response_msg = Message({
            '@type': Connection.RESPONSE,
            '~thread': {Message.THREAD_ID: pairwise_meta['req_id'], Message.SENDER_ORDER: 0},
            'connection': {
                'did': my_did,
                'did_doc': {
                    "@context": "https://w3id.org/did/v1",
                    "id": my_did,
                    "publicKey": [{
                        "id": my_did + "#keys-1",
                        "type": "Ed25519VerificationKey2018",
                        "controller": my_did,
                        "publicKeyBase58": my_vk
                    }],
                    "service": [{
                        "id": my_did + ";indy",
                        "type": "IndyAgent",
                        "recipientKeys": [my_vk],
                        #"routingKeys": ["<example-agency-verkey>"],
                        "serviceEndpoint": self.agent.endpoint,
                    }],
                }
            }
        })

        # Apply signature to connection field, sign it with the key used in the invitation and request
        response_msg['connection~sig'] = \
            await self.agent.sign_agent_message_field(response_msg['connection'],
                                                      pairwise_meta["connection_key"])
        del response_msg['connection']

        pending_connection = Serializer.deserialize(
            json.loads(
                await non_secrets.get_wallet_record(self.agent.wallet_handle,
                                                    'invitations',
                                                    pairwise_meta['connection_key'],
                                                    '{}')
            )['value']
        )
        pending_connection['status'] = "Response Sent"
        pending_connection['@type'] = AdminConnection.RESPONSE_SENT
        pending_connection['history'].append({
            'date': str(datetime.datetime.now()),
            'msg': msg.to_dict()})

        await self.agent.send_message_to_agent(their_did, response_msg)

        await self.agent.send_admin_message(pending_connection)

        await non_secrets.delete_wallet_record(self.agent.wallet_handle,
                                               'invitations',
                                               pairwise_meta['connection_key'])
Beispiel #19
0
    async def send_request(self, msg: Message) -> None:
        """ Recall invite message from wallet and prepare and send request to the inviter.

            send_request message format:

                {
                  "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin_connections/1.0/send_request",
                  "key": <key sent in invite>
                }

            Request format:

                {
                  "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/request",
                  "label": "Bob",
                  "did": "B.did@B:A",
                  "did_doc": {
                      // did Doc here.
                  }
                }
        """
        pending_connection = Serializer.deserialize(
            json.loads(
                await non_secrets.get_wallet_record(
                    self.agent.wallet_handle,
                    'invitations',
                    msg['connection_key'],
                    '{}'
                )
            )['value']
        )

        my_label = self.agent.owner
        label = pending_connection['label']
        their_connection_key = pending_connection['connection_key']
        their_endpoint = pending_connection['endpoint']

        # Create my information for connection
        (my_did, my_vk) = await utils.create_and_store_my_did(self.agent.wallet_handle)

        await did.set_did_metadata(
            self.agent.wallet_handle,
            my_did,
            json.dumps({
                'label': label,
                'their_endpoint': their_endpoint
            })
        )

        # Send Connection Request to inviter
        request = Message({
            '@type': Connection.REQUEST,
            'label': my_label,
            'connection': {
                'did': my_did,
                'did_doc': {
                    "@context": "https://w3id.org/did/v1",
                    "id": my_did,
                    "publicKey": [{
                        "id": my_did + "#keys-1",
                        "type": "Ed25519VerificationKey2018",
                        "controller": my_did,
                        "publicKeyBase58": my_vk
                    }],
                    "service": [{
                        "id": my_did + ";indy",
                        "type": "IndyAgent",
                        "recipientKeys": [my_vk],
                        #"routingKeys": ["<example-agency-verkey>"],
                        "serviceEndpoint": self.agent.endpoint,
                    }],
                }
            }
        })

        await self.agent.send_message_to_endpoint_and_key(
            their_connection_key,
            their_endpoint,
            request,
            my_vk
        )

        pending_connection['@type'] = AdminConnection.REQUEST_SENT
        pending_connection['status'] = "Request Sent"
        pending_connection['history'].append({
            'date': str(datetime.datetime.now()),
            'msg': msg.to_dict()})
        await non_secrets.update_wallet_record_value(self.agent.wallet_handle,
                                                     'invitations',
                                                     pending_connection['connection_key'],
                                                     Serializer.serialize(pending_connection).decode('utf-8'))

        await self.agent.send_admin_message(pending_connection)
Beispiel #20
0
    async def receive_invite(self, msg: Message) -> None:
        """ Receive and save invite.

            This interaction represents an out-of-band communication channel. In the future and in
            practice, these sort of invitations will be received over any number of channels such as
            SMS, Email, QR Code, NFC, etc.

            In this iteration, invite messages are received from the admin interface as a URL
            after being copied and pasted from another agent instance.

            The URL is formatted as follows:

                https://<domain>/<path>?c_i=<invitationstring>

            The invitation string is a base64 url encoded json string.

            Structure of an invite message:

                {
                    "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    "label": "Alice",
                    "did": "did:sov:QmWbsNYhMrjHiqZDTUTEJs"
                }

            Or, in the case of a peer DID:

                {
                    "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    "label": "Alice",
                    "key": "8HH5gYEeNc3z7PYXmd54d4x6qAfCNrqQqEB3nS7Zfu7K",
                    "endpoint": "https://example.com/endpoint"
                }

            Currently, only peer DID format is supported.
        """

        # Parse invite string
        matches = re.match("(.+)?c_i=(.+)", msg['invite'])
        if not matches:
            raise BadInviteException("Invite string is improperly formatted")

        invite_msg = Serializer.deserialize(
            base64.urlsafe_b64decode(matches.group(2)).decode('utf-8')
        )

        pending_connection = Message({
            '@type': AdminConnection.INVITE_RECEIVED,
            'label': invite_msg['label'],
            'connection_key': invite_msg['recipientKeys'][0],
            'endpoint': invite_msg['serviceEndpoint'],
            'history': [{
                'date': str(datetime.datetime.now()),
                'msg': invite_msg.to_dict()
            }],
            'status': "Invite Received"
        })
        await self.agent.send_admin_message(pending_connection)

        await non_secrets.add_wallet_record(
            self.agent.wallet_handle,
            'invitations',
            invite_msg['recipientKeys'][0],
            Serializer.serialize(pending_connection).decode('utf-8'),
            '{}'
        )
Beispiel #21
0
 async def ping_response(self, msg: Message) -> None:
     await self.agent.send_admin_message(
         Message({
             '@type': AdminTrustPing.TRUSTPING_RESPONSE_RECEIVED,
             'from': msg.context['from_did'],
         }))
Beispiel #22
0
    def deserialize(dump: bytes) -> Message:
        """ Deserialize from json string to Message, if it looks like a Message.
            Returns a dictionary otherwise.
        """

        return Message(json.loads(dump))
Beispiel #23
0
 def as_message(dct):
     return Message(dct)
Beispiel #24
0
def unpack_dict(dictionary: dict) -> Message:
    deserialized_msg = Message(dictionary)
    return deserialized_msg