Skip to content

Commit

Permalink
Fix ipex/grant endpoint (#143)
Browse files Browse the repository at this point in the history
* Update the AID state returned from Boot.

Signed-off-by: pfeairheller <[email protected]>

* Fix ipex/grant endpoint to work correctly with attachments

Signed-off-by: pfeairheller <[email protected]>

---------

Signed-off-by: pfeairheller <[email protected]>
  • Loading branch information
pfeairheller authored Dec 6, 2023
1 parent 9dda515 commit f31296a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def recur(self, tyme, deeds=None):
postman = forwarding.StreamPoster(hby=self.hby, hab=self.agentHab, recp=recp, topic="credential")
try:
credSaid = serder.ked['e']['acdc']['d']
creder = self.rgy.creds.get(keys=(credSaid,))
creder = self.rgy.reger.creds.get(keys=(credSaid,))
sendArtifacts(self.hby, self.rgy.reger, postman, creder, recp)
sources = self.rgy.reger.sources(self.hby.db, creder)
for source, atc in sources:
Expand Down Expand Up @@ -585,6 +585,7 @@ def recur(self, tyme):
for label in ("anc", "iss", "acdc"):
ked = embeds[label]
if label not in pathed or not pathed[label]:
print(f"missing path label {label}")
continue

sadder = coring.Sadder(ked=ked)
Expand Down Expand Up @@ -865,7 +866,7 @@ def on_post(self, req, rep):
raise falcon.HTTPBadRequest(description="multisig groups not supported as agent controller")

rep.status = falcon.HTTP_202
rep.data = json.dumps(asdict(ctrlHab.kever.state())).encode("utf-8")
rep.data = json.dumps(asdict(agent.agentHab.kever.state())).encode("utf-8")


class KeyStateCollectionEnd:
Expand Down
20 changes: 10 additions & 10 deletions src/keria/app/ipexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def on_post(req, rep, name):
"""
agent = req.context.agent
# Get the hab
hab = agent.hby.habByName(name)
if hab is None:
raise falcon.HTTPNotFound(description=f"alias={name} is not a valid reference to an identifier")
Expand All @@ -167,15 +166,15 @@ def on_post(req, rep, name):

match route:
case "/ipex/grant":
IpexGrantCollectionEnd.sendGrant(agent, hab, ked, sigs, rec)
IpexGrantCollectionEnd.sendGrant(agent, hab, ked, sigs, atc, rec)
case "/multisig/exn":
IpexGrantCollectionEnd.sendMultisigExn(agent, hab, ked, sigs, atc, rec)

rep.status = falcon.HTTP_202
rep.data = json.dumps(ked).encode("utf-8")

@staticmethod
def sendGrant(agent, hab, ked, sigs, rec):
def sendGrant(agent, hab, ked, sigs, atc, rec):
for recp in rec: # Have to verify we already know all the recipients.
if recp not in agent.hby.kevers:
raise falcon.HTTPBadRequest(description=f"attempt to send to unknown AID={recp}")
Expand All @@ -189,6 +188,7 @@ def sendGrant(agent, hab, ked, sigs, rec):
seal = eventing.SealEvent(i=hab.pre, s=hex(kever.lastEst.s), d=kever.lastEst.d)

ims = eventing.messagize(serder=serder, sigers=sigers, seal=seal)
ims = ims + atc.encode("utf-8")

# make a copy and parse
agent.hby.psr.parseOne(ims=bytearray(ims))
Expand All @@ -197,7 +197,7 @@ def sendGrant(agent, hab, ked, sigs, rec):
del ims[:serder.size]

agent.exchanges.append(dict(said=serder.said, pre=hab.pre, rec=rec, topic='credential'))
agent.grants.append(dict(said=ked['d'], pre=hab.pre))
agent.grants.append(dict(said=ked['d'], pre=hab.pre, rec=rec))

@staticmethod
def sendMultisigExn(agent, hab, ked, sigs, atc, rec):
Expand All @@ -210,13 +210,13 @@ def sendMultisigExn(agent, hab, ked, sigs, atc, rec):
if grant['r'] != "/ipex/grant":
raise falcon.HTTPBadRequest(description=f"invalid route for embedded ipex grant {ked['r']}")

# Have to add the atc to the end... this will be Pathed signatures for embeds
if 'exn' not in atc or not atc['exn']:
raise falcon.HTTPBadRequest(description=f"attachment missing for ACDC, unable to process request.")

holder = grant['a']['i']
serder = serdering.SerderKERI(sad=grant)
ims = bytearray(serder.raw) + atc['exn'].encode("utf-8")
sigers = [coring.Siger(qb64=sig) for sig in sigs]
seal = eventing.SealEvent(i=hab.pre, s=hex(hab.kever.lastEst.s), d=hab.kever.lastEst.d)

ims = eventing.messagize(serder=serder, sigers=sigers, seal=seal)
ims = ims + atc.encode("utf-8")
agent.hby.psr.parseOne(ims=ims)
agent.exchanges.append(dict(said=serder.said, pre=hab.pre, rec=holder, topic="credential"))
agent.grants.append(dict(said=grant['d'], pre=hab.pre))
Expand All @@ -231,7 +231,7 @@ def sendMultisigExn(agent, hab, ked, sigs, atc, rec):

ims = eventing.messagize(serder=serder, sigers=sigers, seal=seal)

ims.extend(atc['exn'].encode("utf-8")) # add the pathed attachments
ims.extend(atc.encode("utf-8")) # add the pathed attachments

# make a copy and parse
agent.hby.psr.parseOne(ims=bytearray(ims))
Expand Down
18 changes: 2 additions & 16 deletions tests/app/test_ipexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_ipex_grant(helpers, mockHelpingNowIso8601, seeder):
body = dict(
exn=exn.ked,
sigs=sigs,
atc=dict(exn=end.decode("utf-8")),
atc=end.decode("utf-8"),
rec=["EZ-i0d8JZAoTNZH3ULaU6JR2nmwyvYAfSVPzhzS6b5CM"]
)

Expand All @@ -318,24 +318,10 @@ def test_ipex_grant(helpers, mockHelpingNowIso8601, seeder):
'AID=EZ-i0d8JZAoTNZH3ULaU6JR2nmwyvYAfSVPzhzS6b5CM',
'title': '400 Bad Request'}

# Bad attachments
body = dict(
exn=exn.ked,
sigs=sigs,
atc=dict(bad=end.decode("utf-8")),
rec=[pre1]
)

data = json.dumps(body).encode("utf-8")
res = client.simulate_post(path="/identifiers/legal-entity/ipex/grant", body=data)
assert res.status_code == 400
assert res.json == {'description': 'attachment missing for ACDC, unable to process request.',
'title': '400 Bad Request'}

body = dict(
exn=exn.ked,
sigs=sigs,
atc=dict(exn=end.decode("utf-8")),
atc=end.decode("utf-8"),
rec=[pre1]
)

Expand Down

0 comments on commit f31296a

Please sign in to comment.