Skip to content

Commit 07a7f19

Browse files
committed
SDK-1229: Add Extra Data processing to get activity details receipt
processing
1 parent 3d61344 commit 07a7f19

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

yoti_python_sdk/activity_details.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77

88
from yoti_python_sdk import attribute_parser, config
99
from yoti_python_sdk.profile import Profile, ApplicationProfile
10+
from yoti_python_sdk.share.extra_data import ExtraData
1011

1112

1213
class ActivityDetails:
1314
def __init__(
14-
self, receipt, decrypted_profile=None, decrypted_application_profile=None
15+
self,
16+
receipt,
17+
decrypted_profile=None,
18+
decrypted_application_profile=None,
19+
decrypted_extra_data=None,
1520
):
1621
self.decrypted_profile = decrypted_profile
1722
self.user_profile = {} # will be removed in v3.0.0
1823
self.base64_selfie_uri = None
1924
self.decrypted_application_profile = decrypted_application_profile
25+
self.extra_data = None
2026

2127
if decrypted_profile and hasattr(decrypted_profile, "attributes"):
2228
decrypted_profile_attributes = decrypted_profile.attributes
@@ -79,6 +85,9 @@ def __init__(
7985
if timestamp is not None:
8086
self.timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ")
8187

88+
if decrypted_extra_data:
89+
self.extra_data = ExtraData(decrypted_extra_data)
90+
8291
@property
8392
def remember_me_id(self):
8493
return self.__remember_me_id

yoti_python_sdk/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def get_activity_details(self, encrypted_request_token):
6767
proto = protobuf.Protobuf()
6868
encrypted_data = proto.current_user(receipt)
6969
encrypted_application_profile = proto.current_application(receipt)
70+
encrypted_extra_data = proto.extra_data(receipt)
7071

7172
if not encrypted_data:
7273
return ActivityDetails(receipt)
@@ -81,6 +82,12 @@ def get_activity_details(self, encrypted_request_token):
8182
encrypted_application_profile.iv,
8283
encrypted_application_profile.cipher_text,
8384
)
85+
if encrypted_extra_data:
86+
decrypted_extra_data = self.__crypto.decipher(
87+
unwrapped_key, encrypted_extra_data.iv, encrypted_extra_data.cipher_text
88+
)
89+
else:
90+
decrypted_extra_data = None
8491

8592
user_profile_attribute_list = proto.attribute_list(decrypted_profile_data)
8693
application_profile_attribute_list = proto.attribute_list(
@@ -91,6 +98,7 @@ def get_activity_details(self, encrypted_request_token):
9198
receipt=receipt,
9299
decrypted_profile=user_profile_attribute_list,
93100
decrypted_application_profile=application_profile_attribute_list,
101+
decrypted_extra_data=decrypted_extra_data,
94102
)
95103

96104
def perform_aml_check(self, aml_profile):

yoti_python_sdk/protobuf/protobuf.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ def multi_value(data):
6767
return multi_value
6868

6969
@staticmethod
70-
def extra_data(data):
71-
extra_data = ExtraData_pb2.ExtraData()
72-
extra_data.MergeFromString(data)
70+
def extra_data(receipt):
71+
if receipt.get("extra_data_content") is None or receipt.get("extra_data_content") == '':
72+
return None
73+
74+
extra_data_content = receipt["extra_data_content"]
75+
extra_data_content = base64.b64decode(extra_data_content)
76+
77+
extra_data = EncryptedData_pb2.EncryptedData()
78+
extra_data.MergeFromString(extra_data_content)
7379
return extra_data
7480

7581
@staticmethod

yoti_python_sdk/share/extra_data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
from yoti_python_sdk.issuance_details import IssuanceDetails
44
from yoti_python_sdk.protobuf.share_public_api import ThirdPartyAttribute_pb2
5+
from yoti_python_sdk.protobuf.share_public_api import ExtraData_pb2
56

67

78
class ExtraData(object):
89
THIRD_PARTY_ATTRIBUTE = 6
910

10-
def __init__(self, proto):
11+
def __init__(self, raw):
1112
self.__attribute_issuance_details = None
13+
proto = ExtraData_pb2.ExtraData()
14+
proto.MergeFromString(raw)
1215
data_entries_list = proto.list
1316

1417
for data_entry in data_entries_list:

yoti_python_sdk/tests/share/test_extra_data.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from yoti_python_sdk.share.extra_data import ExtraData
77
from yoti_python_sdk.tests import file_helper
8-
from yoti_python_sdk.protobuf import protobuf
98

109
from yoti_python_sdk.protobuf.share_public_api import IssuingAttributes_pb2
1110
from yoti_python_sdk.protobuf.share_public_api import ThirdPartyAttribute_pb2
@@ -38,13 +37,13 @@ def create_third_party_test_data(token_value, expiry_date, *definitions):
3837
def create_extra_data(data_entry_list):
3938
extra_data = ExtraData_pb2.ExtraData()
4039
extra_data.list.extend(data_entry_list)
41-
return extra_data
40+
return extra_data.SerializeToString()
4241

4342

4443
def get_extra_data_from_base64(filepath):
4544
extra_data_bytes = file_helper.get_file_bytes(filepath)
46-
protobuf_extra_data = protobuf.Protobuf.extra_data(extra_data_bytes)
47-
return ExtraData(protobuf_extra_data)
45+
46+
return ExtraData(extra_data_bytes)
4847

4948

5049
def test_attribute_issuance_details_should_return_none_when_no_data_entries():

0 commit comments

Comments
 (0)