diff --git a/legal-api/src/legal_api/resources/v2/business/business_digital_credentials.py b/legal-api/src/legal_api/resources/v2/business/business_digital_credentials.py index a77ecfc762..f9e1f4b875 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_digital_credentials.py +++ b/legal-api/src/legal_api/resources/v2/business/business_digital_credentials.py @@ -52,7 +52,7 @@ def create_invitation(identifier): return jsonify({'message': 'Unable to create an invitation.'}), HTTPStatus.INTERNAL_SERVER_ERROR connection = DCConnection( - connection_id=invitation['connection_id'], + connection_id=invitation['invitation']['@id'], invitation_url=invitation['invitation_url'], is_active=False, connection_state='invitation', @@ -199,11 +199,15 @@ def webhook_notification(topic_name: str): json_input = request.get_json() try: if topic_name == 'connections': - connection = DCConnection.find_by_connection_id(json_input['connection_id']) - # Trinsic Wallet will send `active` only when it’s used the first time. - # Looking for `response` state to handle it. - if connection and not connection.is_active and json_input['state'] in ('response', 'active'): - connection.connection_state = 'active' + if 'invitation' in json_input and json_input['invitation'] != None: + connection = DCConnection.find_by_connection_id(json_input['invitation']['@id']) + else: + connection = DCConnection.find_by_connection_id(json_input['invitation_msg_id']) + # Using https://didcomm.org/connections/1.0 protocol the final state is 'active' + # Using https://didcomm.org/didexchange/1.0 protocol the final state is 'completed' + if connection and not connection.is_active and json_input['state'] in ('active', 'completed'): + connection.connection_id = json_input['connection_id'] + connection.connection_state = json_input['state'] connection.is_active = True connection.save() elif topic_name == 'issue_credential': diff --git a/legal-api/src/legal_api/services/digital_credentials.py b/legal-api/src/legal_api/services/digital_credentials.py index 1addcb3940..3b9968ddfa 100644 --- a/legal-api/src/legal_api/services/digital_credentials.py +++ b/legal-api/src/legal_api/services/digital_credentials.py @@ -80,10 +80,10 @@ def _register_business_definition(self): if (self.business_schema_id is None): self.app.logger.error(f'Environment variable: BUSINESS_SCHEMA_ID must be configured') raise Exception(f'Environment variable: BUSINESS_SCHEMA_ID must be configured') - + if (self.business_cred_def_id is None): self.app.logger.error(f'Environment variable: BUSINESS_CRED_DEF_ID must be configured') - raise Exception(f'Environment variable: BUSINESS_CRED_DEF_ID must be configured') + raise Exception(f'Environment variable: BUSINESS_CRED_DEF_ID must be configured') """Fetch schema and credential definition and save a Business definition.""" # Check for the current Business definition. @@ -120,7 +120,7 @@ def _register_business_definition(self): schema_id=schema_id, credential_definition_id=credential_definition_id ) - # Lastly, save the definition + # Lastly, save the definition definition.save() except Exception as err: self.app.logger.error(err) @@ -157,9 +157,12 @@ def _fetch_credential_definition(self, cred_def_id: str) -> Optional[str]: def create_invitation(self) -> Optional[dict]: """Create a new connection invitation.""" try: - response = requests.post(self.api_url + '/connections/create-invitation', + response = requests.post(self.api_url + '/out-of-band/create-invitation', headers=self._get_headers(), - data={}) + params={'auto_accept': 'true'}, + data=json.dumps({ + 'handshake_protocols': ['https://didcomm.org/connections/1.0'] + })) response.raise_for_status() return response.json() except Exception as err: