async def handle(self, context: RequestContext, responder: BaseResponder): """Handle static connection get list request.""" connection_mgr = ConnectionManager(context) wallet: BaseWallet = await context.inject(BaseWallet) try: tag_filter = dict( filter(lambda item: item[1] is not None, { 'initiator': context.message.initiator, 'invitation_key': context.message.invitation_key, 'my_did': context.message.my_did, 'invitation_mode': ConnectionRecord.INVITATION_MODE_STATIC, 'their_did': context.message.their_did, 'their_role': context.message.their_role }.items()) ) records = await ConnectionRecord.query(context, tag_filter) except StorageNotFoundError: report = ProblemReport( explain_ltxt='Connection not found.', who_retries='none' ) report.assign_thread_from(context.message) await responder.send_reply(report) return def flatten_target(connection, target, my_info): """Map for flattening results.""" return { 'connection_id': connection.connection_id, 'their_info': { 'label': target.label, 'did': target.did, 'vk': target.recipient_keys[0], 'endpoint': target.endpoint }, 'my_info': { 'did': my_info.did, 'vk': my_info.verkey, 'endpoint': context.settings.get("default_endpoint") } } targets = [] my_info = [] for record in records: targets.append( await connection_mgr.get_connection_target(record) ) my_info.append(await wallet.get_local_did(record.my_did)) results = list(map( flatten_target, records, targets, my_info )) static_connections = StaticConnectionList(results=results) static_connections.assign_thread_from(context.message) await responder.send_reply(static_connections)
async def handle(self, context: RequestContext, responder: BaseResponder): """Handle create invitation request.""" connection_mgr = ConnectionManager(context) connection, invitation = await connection_mgr.create_invitation( my_label=context.message.label, their_role=context.message.role, accept="auto" if context.message.auto_accept else "none", multi_use=bool(context.message.multi_use), public=False, alias=context.message.alias, ) invite_response = Invitation( id=connection.connection_id, label=invitation.label, alias=connection.alias, role=connection.their_role, auto_accept=connection.accept == ConnectionRecord.ACCEPT_AUTO, multi_use=(connection.invitation_mode == ConnectionRecord.INVITATION_MODE_MULTI), invitation_url=invitation.to_url(), created_date=connection.created_at, raw_repr={ 'connection': connection.serialize(), 'invitation': invitation.serialize(), }) invite_response.assign_thread_from(context.message) await responder.send_reply(invite_response)
async def handle(self, context: RequestContext, responder: BaseResponder): """Handle recieve invitation request.""" connection_mgr = ConnectionManager(context) invitation = ConnectionInvitation.from_url(context.message.invitation) connection = await connection_mgr.receive_invitation( invitation, accept=context.message.accept) connection_resp = Connection(connection=connection) await responder.send_reply(connection_resp)
async def handle(self, context: RequestContext, responder: BaseResponder): """Handle recieve invitation request.""" connection_mgr = ConnectionManager(context) invitation = ConnectionInvitation.from_url(context.message.invitation) connection = await connection_mgr.receive_invitation( invitation, accept=('auto' if context.message.auto_accept else 'none')) connection_resp = Connection(**conn_record_to_message_repr(connection)) await responder.send_reply(connection_resp)
async def handle(self, context: RequestContext, responder: BaseResponder): """Handle static connection creation request.""" connection_mgr = ConnectionManager(context) wallet: BaseWallet = await context.inject(BaseWallet) # Make our info for the connection my_info = await wallet.create_local_did() # Create connection record connection = ConnectionRecord( initiator=ConnectionRecord.INITIATOR_SELF, my_did=my_info.did, their_did=context.message.static_did, their_label=context.message.label, their_role=context.message.role if context.message.role else None, state=ConnectionRecord.STATE_ACTIVE, invitation_mode=ConnectionRecord.INVITATION_MODE_STATIC ) # Construct their did doc from the basic components in message diddoc = DIDDoc(context.message.static_did) public_key = PublicKey( did=context.message.static_did, ident="1", value=context.message.static_key, pk_type=PublicKeyType.ED25519_SIG_2018, controller=context.message.static_did ) service = Service( did=context.message.static_did, ident="indy", typ="IndyAgent", recip_keys=[public_key], routing_keys=[], endpoint=context.message.static_endpoint ) diddoc.set(public_key) diddoc.set(service) # Save await connection_mgr.store_did_document(diddoc) await connection.save( context, reason='Created new static connection' ) # Prepare response info = StaticConnectionInfo( did=my_info.did, key=my_info.verkey, endpoint=context.settings.get("default_endpoint") ) info.assign_thread_from(context.message) await responder.send_reply(info) return
async def handle(self, context: RequestContext, responder: BaseResponder): """Handle create invitation request.""" connection_mgr = ConnectionManager(context) connection, invitation = await connection_mgr.create_invitation( my_label=context.message.label, their_role=context.message.role, accept=context.message.accept, multi_use=bool(context.message.multi_use), public=bool(context.message.public), ) invite_response = Invitation( connection_id=connection and connection.connection_id, invitation=invitation.serialize(), invitation_url=invitation.to_url(), ) invite_response.assign_thread_from(context.message) await responder.send_reply(invite_response)
async def handle(self, context: RequestContext, responder: BaseResponder): """Handle received basic message.""" msg = BasicMessageRecord( connection_id=context.connection_record.connection_id, message_id=context.message._id, sent_time=context.message.sent_time, content=context.message.content, state=BasicMessageRecord.STATE_RECV) await msg.save(context, reason='New message received.') await responder.send_webhook( "basicmessages", { "connection_id": context.connection_record.connection_id, "message_id": context.message._id, "content": context.message.content, "state": "received", }, ) connection_mgr = ConnectionManager(context) admins = await ConnectionRecord.query( context, post_filter={'their_role': 'admin'}) if not admins: return admins = filter(lambda admin: admin.state == 'active', admins) admin_verkeys = [ target.recipient_keys[0] for admin in admins for target in await connection_mgr.get_connection_targets( connection=admin) ] notification = New( connection_id=context.connection_record.connection_id, message=msg) for verkey in admin_verkeys: await responder.send(notification, reply_to_verkey=verkey, to_session_only=True)