From 4e919589eee8ba301903660337cfcd5975bb211c Mon Sep 17 00:00:00 2001 From: 2byrds <2byrds@gmail.com> Date: Wed, 4 Sep 2024 20:05:58 -0400 Subject: [PATCH] properly return the ecr cred Signed-off-by: 2byrds <2byrds@gmail.com> --- src/verifier/core/verifying.py | 40 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/verifier/core/verifying.py b/src/verifier/core/verifying.py index a51c711..7942191 100644 --- a/src/verifier/core/verifying.py +++ b/src/verifier/core/verifying.py @@ -119,35 +119,37 @@ def on_put(self, req, rep, said): vry=self.vry) found = False - creds = None + saids = [] while self.vry.cues: msg = self.vry.cues.popleft() if "creder" in msg: creder = msg["creder"] if creder.said == said: found = True - saider = coring.Saider(qb64=said) - cred_attrs = creder.sad['a'] - if 'i' in cred_attrs: - saids = self.vry.reger.subjs.get(keys=cred_attrs['i']) - creds = self.vry.reger.cloneCreds(saids, self.hby.db) - else: - creds = self.vry.reger.cloneCreds((saider,), self.hby.db) - - print(f"Credential {said} presented.") - - now = coring.Dater() + if not found: + rep.status = falcon.HTTP_BAD_REQUEST + rep.data = json.dumps(dict(msg=f"credential {said} from body of request did not verify")).encode("utf-8") + return + + saider = coring.Saider(qb64=said) + cred_attrs = creder.sad['a'] + creds = None + if 'i' in cred_attrs: + saids = self.vry.reger.subjs.get(keys=cred_attrs['i']) + creds = self.vry.reger.cloneCreds(saids, self.hby.db) + else: + creds = self.vry.reger.cloneCreds((saider,), self.hby.db) + + print(f"Credential {said} presented.") - self.vdb.iss.pin(keys=(saider.qb64,), val=now) + now = coring.Dater() - rep.status = falcon.HTTP_ACCEPTED - rep.data = json.dumps(dict(creds=json.dumps(creds), msg=f"{said} is a valid credential ", - lei=creder.sad['a'].get('LEI'), aid=creder.sad['a'].get('i'))).encode("utf-8") - return + self.vdb.iss.pin(keys=(saider.qb64,), val=now) - rep.status = falcon.HTTP_BAD_REQUEST - rep.data = json.dumps(dict(msg=f"credential {said} from body of request did not verify")).encode("utf-8") + rep.status = falcon.HTTP_ACCEPTED + rep.data = json.dumps(dict(creds=json.dumps(creds), msg=f"{said} is a valid credential ", + lei=creder.sad['a'].get('LEI'), aid=creder.sad['a'].get('i'))).encode("utf-8") return class AuthorizationResourceEnd: