66import argparse
77import json
88import requests
9+ import sys
910
1011from hio .base import doing
1112from keri .app import habbing , oobiing
3233
3334
3435def handler (args ):
35- res = Resolver (name = args .name , base = args .base , bran = args .bran , did = args .did )
36+ hby = existing .setupHby (name = args .name , base = args .base , bran = args .bran )
37+ hbyDoer = habbing .HaberyDoer (habery = hby ) # setup doer
38+ obl = oobiing .Oobiery (hby = hby )
39+ res = WebsResolver (hby = hby , hbyDoer = hbyDoer , obl = obl , did = args .did , metadata = args .metadata )
3640 return [res ]
3741
3842
39- class Resolver (doing .DoDoer ):
43+ class WebsResolver (doing .DoDoer ):
4044
41- def __init__ (self , name , base , bran , did , metadata ):
45+ def __init__ (self , hby , hbyDoer , obl , did , metadata ):
4246
43- self .hby = existing .setupHby (name = name , base = base , bran = bran )
44- hbyDoer = habbing .HaberyDoer (habery = self .hby ) # setup doer
45- obl = oobiing .Oobiery (hby = self .hby )
47+ self .hby = hby
4648 self .did = did
4749 self .metadata = metadata
4850
4951 self .toRemove = [hbyDoer ] + obl .doers
5052 doers = list (self .toRemove ) + [doing .doify (self .resolve )]
51- super (Resolver , self ).__init__ (doers = doers )
53+ super (WebsResolver , self ).__init__ (doers = doers )
5254
5355 def resolve (self , tymth , tock = 0.0 , ** opts ):
5456 self .wind (tymth )
@@ -61,25 +63,36 @@ def resolve(self, tymth, tock=0.0, **opts):
6163
6264 # Load the did doc
6365 dd_url = f"{ base_url } /{ webbing .DID_JSON } "
64- print (f"Loading DID Doc from { dd_url } " )
66+ print (f"Loading DID Doc from { dd_url } " , file = sys . stderr )
6567 dd_actual = didding .fromDidWeb (json .loads (self .loadUrl (dd_url ).decode ("utf-8" )))
6668
6769 # Load the KERI CESR
6870 kc_url = f"{ base_url } /{ webbing .KERI_CESR } "
69- print (f"Loading KERI CESR from { kc_url } " )
71+ print (f"Loading KERI CESR from { kc_url } " , file = sys . stderr )
7072 self .hby .psr .parse (ims = bytearray (self .loadUrl (kc_url )))
7173
72- dd_expected = didding .generateDIDDoc (self .hby , did = self .did , aid = aid , oobi = None , metadata = self .metadata )
73-
74+ didresult = didding .generateDIDDoc (self .hby , did = self .did , aid = aid , oobi = None , metadata = True )
75+ didresult ['didDocumentMetadata' ]['didDocUrl' ] = dd_url
76+ didresult ['didDocumentMetadata' ]['keriCesrUrl' ] = kc_url
77+
78+ dd_expected = didresult ['didDocument' ]
79+
7480 verified = self .verifyDidDocs (dd_expected , dd_actual )
75-
81+
7682 self .remove (self .toRemove )
7783
7884 if verified :
79- return dd_actual
85+ result = didresult if self . metadata else dd_expected
8086 else :
81- return None
82-
87+ didresult ['didDocument' ] = None
88+ didresult ['didResolutionMetadata' ]['error' ] = 'notVerified'
89+ didresult ['didResolutionMetadata' ]['errorMessage' ] = 'The DID document could not be verified against the KERI event stream'
90+ result = didresult
91+
92+ data = json .dumps (result , indent = 2 )
93+ print (data )
94+ return result
95+
8396 def loadUrl (self , url ):
8497 response = requests .get (f"{ url } " )
8598 # Ensure the request was successful
@@ -97,49 +110,49 @@ def loadFile(self, aid):
97110
98111 def verifyDidDocs (self , expected , actual ):
99112 if expected != actual :
100- print ("DID Doc does not verify" )
113+ print ("DID Doc does not verify" , file = sys . stderr )
101114 compare_dicts (expected , actual )
102115 return False
103116 else :
104- print ("DID Doc verified" )
117+ print ("DID Doc verified" , file = sys . stderr )
105118 return True
106119
107120def compare_dicts (expected , actual , path = "" ):
108- print ("Comparing dictionaries:\n expected:\n {expected} \n and\n \n actual:\n {actual}" )
121+ print ("Comparing dictionaries:\n expected:\n {expected} \n and\n \n actual:\n {actual}" , file = sys . stderr )
109122
110123 """Recursively compare two dictionaries and print differences."""
111124 for k in expected .keys ():
112125 # Construct current path
113126 current_path = f"{ path } .{ k } " if path else k
114- print (f"Comparing key { current_path } " )
127+ print (f"Comparing key { current_path } " , file = sys . stderr )
115128
116129 # Key not present in the actual dictionary
117130 if k not in actual :
118- print (f"Key { current_path } not found in the actual dictionary" )
131+ print (f"Key { current_path } not found in the actual dictionary" , file = sys . stderr )
119132 continue
120133
121134 # If value in expected is a dictionary but not in actual
122135 if isinstance (expected [k ], dict ) and not isinstance (actual [k ], dict ):
123- print (f"{ current_path } is a dictionary in expected, but not in actual" )
136+ print (f"{ current_path } is a dictionary in expected, but not in actual" , file = sys . stderr )
124137 continue
125138
126139 # If value in actual is a dictionary but not in expected
127140 if isinstance (actual [k ], dict ) and not isinstance (expected [k ], dict ):
128- print (f"{ current_path } is a dictionary in actual, but not in expected" )
141+ print (f"{ current_path } is a dictionary in actual, but not in expected" , file = sys . stderr )
129142 continue
130143
131144 # If value is another dictionary, recurse
132145 if isinstance (expected [k ], dict ) and isinstance (actual [k ], dict ):
133146 compare_dicts (expected [k ], actual [k ], current_path )
134147 # Compare non-dict values
135148 elif expected [k ] != actual [k ]:
136- print (f"Different values for key { current_path } : { expected [k ]} (expected) vs. { actual [k ]} (actual)" )
149+ print (f"Different values for key { current_path } : { expected [k ]} (expected) vs. { actual [k ]} (actual)" , file = sys . stderr )
137150
138151 # Check for keys in actual that are not present in expected
139152 for k in actual .keys ():
140153 current_path = f"{ path } .{ k } " if path else k
141154 if k not in expected :
142- print (f"Key { current_path } not found in the expected dictionary" )
155+ print (f"Key { current_path } not found in the expected dictionary" , file = sys . stderr )
143156
144157# # Test with the provided dictionaries
145158# expected_dict = {
0 commit comments