Skip to content

Commit dd4c628

Browse files
committed
cleaned up code and return extracted values
1 parent 6a8a096 commit dd4c628

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

libs/aries-basic-controller/aries_basic_controller/helpers/presentation_parser.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
1+
import json
2+
13
class Presentation():
24
def __init__(self, verify):
35
self.verify = verify
46

57
def get_self_attested(self):
6-
for (name, val) in self.verify['presentation']['requested_proof']['self_attested_attrs'].items():
7-
print(name + " : " + val)
8+
data = {}
9+
for (name, val) in self.verify['presentation']['requested_proof']['self_attested_attrs'].items():
10+
data[name] = val['raw']
11+
return json.dumps(data)
812

913
def get_revealed(self):
10-
for (name, val) in self.verify['presentation']['requested_proof']['revealed_attrs'].items():
11-
## This is the actual data that you want. It's a little hidden
12-
print(name + " : " + val['raw'])
14+
data = {}
15+
for (name, val) in self.verify['presentation']['requested_proof']['revealed_attrs'].items():
16+
data[name] = val['raw']
17+
18+
return json.dumps(data)
1319

1420
def get_unrevealed_attrs(self):
15-
for (name, val) in self.verify['presentation']['requested_proof']['unrevealed_attrs'].items():
16-
## This is the actual data that you want. It's a little hidden
17-
print(name + " : " + val['raw'])
21+
data = {}
22+
for (name, val) in self.verify['presentation']['requested_proof']['unrevealed_attrs'].items():
23+
data[name] = val['raw']
24+
return json.dumps(data)
25+
1826
def get_predicates(self):
19-
for (name, val) in self.verify['presentation']['requested_proof']['predicates'].items():
20-
## This is the actual data that you want. It's a little hidden
21-
print(name + " : " + val['raw'])
27+
data = {}
28+
for (name, val) in self.verify['presentation']['requested_proof']['predicates'].items():
29+
data[name] = val['raw']
30+
return json.dumps(data)
2231

2332
def get_identifiers(self):
24-
print(self.verify['presentation']['identifiers'])
25-
"""
26-
"schema_id": "PQRXDxdGqQGSZ8z69p4xZP:2:test_revocable_schema:0.0.1",
27-
"cred_def_id": "PQRXDxdGqQGSZ8z69p4xZP:3:CL:14:default",
28-
"rev_reg_id": "PQRXDxdGqQGSZ8z69p4xZP:4:PQRXDxdGqQGSZ8z69p4xZP:3:CL:14:default:CL_ACCUM:24f4f2ad-0d38-4f46-b020-23eb3cbd0595",
29-
"timestamp": 1613564695
30-
"""
33+
return self.verify['presentation']['identifiers']
3134

3235
def get_role(self):
33-
print(self.verify['role'])
36+
return(self.verify['role'])
3437

3538
def get_threadid(self):
36-
print(self.verify['thread_id'])
39+
return(self.verify['thread_id'])
3740

3841
def get_presentation_request(self):
39-
print(self.verify['presentation_request'])
42+
return(self.verify['presentation_request'])
4043

4144
def get_verified_state(self):
42-
print(self.verify['state'])
45+
return self.verify['state']
4346

4447
def is_verified(self):
45-
if self.verify['state'] == 'verified':
46-
print('verified')
47-
else:
48-
print('verification failed')
48+
# Assume the actual state of the verification is in "verified": "true",
49+
return bool(self.verify['state'] == 'verified')
4950

5051
verify = {
5152
"presentation_exchange_id": "49baae24-57e0-48ad-8df8-adf0ea567c96",

0 commit comments

Comments
 (0)