async def api_invite_1_greeter_wait_peer(self, client_ctx, msg): msg = invite_1_greeter_wait_peer_serializer.req_load(msg) try: claimer_public_key_raw = await self.conduit_exchange( organization_id=client_ctx.organization_id, greeter=client_ctx.user_id, token=msg["token"], state=ConduitState.STATE_1_WAIT_PEERS, payload=msg["greeter_public_key"].encode(), ) except InvitationNotFoundError: return {"status": "not_found"} except InvitationAlreadyDeletedError: return {"status": "already_deleted"} except InvitationInvalidStateError: return {"status": "invalid_state"} return invite_1_greeter_wait_peer_serializer.rep_dump({ "status": "ok", "claimer_public_key": PublicKey(claimer_public_key_raw) })
async def api_invite_1_claimer_wait_peer(self, client_ctx, msg): """ Raises: CloseInviteConnection """ msg = invite_1_claimer_wait_peer_serializer.req_load(msg) try: greeter_public_key = await self.conduit_exchange( organization_id=client_ctx.organization_id, greeter=None, token=client_ctx.invitation.token, state=ConduitState.STATE_1_WAIT_PEERS, payload=msg["claimer_public_key"].encode(), ) except InvitationAlreadyDeletedError as exc: # Notify parent that the connection shall be close because the invitation token is no logger valide. raise CloseInviteConnection from exc except InvitationNotFoundError: return {"status": "not_found"} except InvitationInvalidStateError: return {"status": "invalid_state"} return invite_1_claimer_wait_peer_serializer.rep_dump({ "status": "ok", "greeter_public_key": PublicKey(greeter_public_key) })
def dump_and_encrypt_for(self, recipient_pubkey: PublicKey) -> bytes: """ Raises: DataError """ try: raw = self.dump() return recipient_pubkey.encrypt_for_self(raw) except CryptoError as exc: raise DataError(str(exc)) from exc
def dump_sign_and_encrypt_for(self, author_signkey: SigningKey, recipient_pubkey: PublicKey) -> bytes: """ Raises: DataError """ try: signed = author_signkey.sign(self._serialize()) return recipient_pubkey.encrypt_for_self(signed) except CryptoError as exc: raise DataError(str(exc)) from exc