Skip to content

Commit

Permalink
feat: use out-of-band invitation for connecting
Browse files Browse the repository at this point in the history
Signed-off-by: Akiff Manji <amanji@petridish.dev>
  • Loading branch information
amanji committed Oct 25, 2023
1 parent 7b88982 commit ad0fa01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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':
Expand Down
13 changes: 8 additions & 5 deletions legal-api/src/legal_api/services/digital_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ad0fa01

Please sign in to comment.