Skip to content

Commit 35d67b9

Browse files
committed
WIP some work on proof request class
* https://github.com/hyperledger/aries-rfcs/tree/master/features/0037-present-proof * https://ldej.nl/post/becoming-a-hyperledger-aries-developer-part-7-present-proof/ * openwallet-foundation/acapy#175 * also took an example proof request json from swagger (you can get that when starting up one of the tutorials and go to http://localhost:8021/api/doc#/present-proof/post_present_proof_create_request) * Branch is yoma_192 on aries-cloudcontroller-python * see also improvements/test_controllers branch where I added some unit tests already for the AriesAgentController (copverage isn’t 100% percent because some of the functionality is better tested with integration tests I think - but if you have a good/creative idea on how to test eg the functions that use pubsub for listening to messages, please hit me up!)
1 parent 90c45d6 commit 35d67b9

File tree

2 files changed

+281
-0
lines changed

2 files changed

+281
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import json
2+
import logging
3+
4+
logger = logging.getLogger("aries_controller.models.proof_request")
5+
6+
proof_request_template = json.loads({
7+
"comment": "",
8+
"proof_request": {
9+
"name": "",
10+
"non_revoked": {
11+
"to": 1618218626
12+
},
13+
"nonce": "1234567890",
14+
"requested_attributes": {
15+
"additionalProp1": {
16+
"name": "",
17+
"names": [
18+
""
19+
],
20+
"non_revoked": {
21+
"to": 1618218626
22+
},
23+
"restrictions": [
24+
{
25+
"additionalProp1": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
26+
"additionalProp2": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
27+
"additionalProp3": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
28+
}
29+
]
30+
},
31+
"additionalProp2": {
32+
"name": "",
33+
"names": [
34+
""
35+
],
36+
"non_revoked": {
37+
"to": 1618218626
38+
},
39+
"restrictions": [
40+
{
41+
"additionalProp1": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
42+
"additionalProp2": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
43+
"additionalProp3": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
44+
}
45+
]
46+
},
47+
"additionalProp3": {
48+
"name": "",
49+
"names": [
50+
""
51+
],
52+
"non_revoked": {
53+
"to": 1618218626
54+
},
55+
"restrictions": [
56+
{
57+
"additionalProp1": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
58+
"additionalProp2": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
59+
"additionalProp3": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
60+
}
61+
]
62+
}
63+
},
64+
"requested_predicates": {
65+
"additionalProp1": {
66+
"name": "index",
67+
"non_revoked": {
68+
"to": 1618218626
69+
},
70+
"p_type": ">=",
71+
"p_value": 0,
72+
"restrictions": [
73+
{
74+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
75+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
76+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
77+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
78+
"schema_name": "transcript",
79+
"schema_version": "1.0"
80+
}
81+
]
82+
},
83+
"additionalProp2": {
84+
"name": "index",
85+
"non_revoked": {
86+
"to": 1618218626
87+
},
88+
"p_type": ">=",
89+
"p_value": 0,
90+
"restrictions": [
91+
{
92+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
93+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
94+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
95+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
96+
"schema_name": "transcript",
97+
"schema_version": "1.0"
98+
}
99+
]
100+
},
101+
"additionalProp3": {
102+
"name": "",
103+
"non_revoked": {
104+
"to": 1618218626
105+
},
106+
"p_type": ">=",
107+
"p_value": 0,
108+
"restrictions": [
109+
{
110+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
111+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
112+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
113+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
114+
"schema_name": "transcript",
115+
"schema_version": "1.0"
116+
}
117+
]
118+
}
119+
},
120+
"version": "1.0"
121+
},
122+
"trace": false
123+
})
124+
125+
126+
class ProofRequest():
127+
def __init__(self, x):
128+
self.proof_request = {}
129+
self.proof_from_json = {}
130+
131+
def proof_from_json(self, prop_json):
132+
try:
133+
self.proof_from_json = json.loads(prop_json)
134+
assert __verify_proof_format()
135+
except AssertionError as e:
136+
logger.error(f"Could not verify proof presentation format: {e!r}")
137+
raise
138+
except Exception:
139+
logger.error("Failed to load proposed JSON proof presentation.")
140+
raise
141+
142+
def __verify_proof_format(self):
143+
144+
return True
145+
146+
# defs to pass single fields or sub dicts like
147+
"""
148+
"restrictions": [
149+
{
150+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
151+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
152+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
153+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
154+
"schema_name": "transcript",
155+
"schema_version": "1.0"
156+
}
157+
]
158+
"""
159+
# See also presentation.py to get an idea of what we're trying to achieve
160+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import pytest
2+
import json
3+
4+
pytest.proof_request = json.loads({
5+
"comment": "string",
6+
"proof_request": {
7+
"name": "Proof request",
8+
"non_revoked": {
9+
"to": 1617957934
10+
},
11+
"nonce": "1234567890",
12+
"requested_attributes": {
13+
"additionalProp1": {
14+
"name": "favouriteDrink",
15+
"names": [
16+
"age"
17+
],
18+
"non_revoked": {
19+
"to": 1617957934
20+
},
21+
"restrictions": [
22+
{
23+
"additionalProp1": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
24+
"additionalProp2": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
25+
"additionalProp3": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
26+
}
27+
]
28+
},
29+
"additionalProp2": {
30+
"name": "favouriteDrink",
31+
"names": [
32+
"age"
33+
],
34+
"non_revoked": {
35+
"to": 1617957934
36+
},
37+
"restrictions": [
38+
{
39+
"additionalProp1": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
40+
"additionalProp2": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
41+
"additionalProp3": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
42+
}
43+
]
44+
},
45+
"additionalProp3": {
46+
"name": "favouriteDrink",
47+
"names": [
48+
"age"
49+
],
50+
"non_revoked": {
51+
"to": 1617957934
52+
},
53+
"restrictions": [
54+
{
55+
"additionalProp1": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
56+
"additionalProp2": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
57+
"additionalProp3": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
58+
}
59+
]
60+
}
61+
},
62+
"requested_predicates": {
63+
"additionalProp1": {
64+
"name": "index",
65+
"non_revoked": {
66+
"to": 1617957934
67+
},
68+
"p_type": ">=",
69+
"p_value": 0,
70+
"restrictions": [
71+
{
72+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
73+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
74+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
75+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
76+
"schema_name": "transcript",
77+
"schema_version": "1.0"
78+
}
79+
]
80+
},
81+
"additionalProp2": {
82+
"name": "index",
83+
"non_revoked": {
84+
"to": 1617957934
85+
},
86+
"p_type": ">=",
87+
"p_value": 0,
88+
"restrictions": [
89+
{
90+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
91+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
92+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
93+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
94+
"schema_name": "transcript",
95+
"schema_version": "1.0"
96+
}
97+
]
98+
},
99+
"additionalProp3": {
100+
"name": "index",
101+
"non_revoked": {
102+
"to": 1617957934
103+
},
104+
"p_type": ">=",
105+
"p_value": 0,
106+
"restrictions": [
107+
{
108+
"cred_def_id": "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag",
109+
"issuer_did": "WgWxqztrNooG92RXvxSTWv",
110+
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
111+
"schema_issuer_did": "WgWxqztrNooG92RXvxSTWv",
112+
"schema_name": "transcript",
113+
"schema_version": "1.0"
114+
}
115+
]
116+
}
117+
},
118+
"version": "1.0"
119+
},
120+
"trace": false
121+
})

0 commit comments

Comments
 (0)