Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test delegation approval #248

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
python_requires='>=3.12.2',
install_requires=[
'hio>=0.6.12',
'keri==1.2.0-dev4',
'keri @ git+https://github.com/WebOfTrust/keripy.git@main',
2byrds marked this conversation as resolved.
Show resolved Hide resolved
'mnemonic>=0.20',
'multicommand>=1.0.0',
'falcon>=3.1.3',
Expand Down
110 changes: 109 additions & 1 deletion src/keria/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def loadEnds(app, agency, authn):
groupEnd = AgentResourceEnd(agency=agency, authn=authn)
app.add_route("/agent/{caid}", groupEnd)

approvalEnd = IdentifierApprovalEnd()
app.add_route("/identifiers/{name}/approvals", approvalEnd)

2byrds marked this conversation as resolved.
Show resolved Hide resolved
aidsEnd = IdentifierCollectionEnd()
app.add_route("/identifiers", aidsEnd)
aidEnd = IdentifierResourceEnd()
Expand Down Expand Up @@ -245,6 +248,110 @@ def anchorSeals(agent, ixn):
dgkey = dbing.dgKey(prefixer.qb64b, saider.qb64)
agent.hby.db.setAes(dgkey, couple) # authorizer event seal (delegator/issuer)

class IdentifierApprovalEnd:
""" Resource class for approving identifier events"""

# @staticmethod
# def on_get(req, rep, name):
# """ Identifier approval GET endpoint

# Parameters:
# req: falcon.Request HTTP request
# rep: falcon.Response HTTP response
# name (str): human readable name for Hab to GET

# """
# raise falcon.HTTPBadRequest(description="Identifier approval endpoint GET not implemented")

def on_put(self, req, rep, name):
""" Identifier approval PUT endpoint

Parameters:
req (Request): falcon.Request HTTP request object
rep (Response): falcon.Response HTTP response object
name (str): human readable name for Hab to rename

"""
if not name:
raise falcon.HTTPBadRequest(description="name is required")
agent = req.context.agent
hab = agent.hby.habByName(name)

if hab is None:
raise falcon.HTTPNotFound(title=f"No AID with name {name} found")

body = req.get_media()

if body.get("approveDelegation") is not None:
op = self.approveDelegation(agent, name, body)
else:
raise falcon.HTTPBadRequest(title="invalid request",
description=f"required field 'approveDelegation' missing from request")

try:
rep.status = falcon.HTTP_200
rep.content_type = "application/json"
rep.data = op.to_json().encode("utf-8")
except (kering.AuthError, ValueError) as e:
2byrds marked this conversation as resolved.
Show resolved Hide resolved
raise falcon.HTTPBadRequest(description=e.args[0])
except (falcon.HTTPBadRequest, falcon.HTTPNotFound, falcon.HTTPInternalServerError) as e:
raise e

# def on_delete(self, req, rep, name):
# """ Identifier approval delete endpoint not currently implemented

# Parameters:
# req (Request): falcon.Request HTTP request object
# rep (Response): falcon.Response HTTP response object
# name (str): human readable name for Hab to delete

# """
# raise falcon.HTTPBadRequest(description="Identifier approval endpoint DELETE not implemented")

# def on_post(self, req, rep, name):
# """ Identifier approval POST functionality not currently implemented

# Parameters:
# req (Request): falcon.Request HTTP request object
# rep (Response): falcon.Response HTTP response object
# name (str): human readable name for Hab to rotate or interact

# """
# raise falcon.HTTPBadRequest(description="Identifier approval endpoint POST not implemented")

@staticmethod
def approveDelegation(agent, name, body):
hab = agent.hby.habByName(name)
if hab is None:
raise falcon.HTTPNotFound(title=f"No AID {name} found")

ixn = body.get("approveDelegation")
if ixn is None:
raise falcon.HTTPBadRequest(title="invalid interaction",
description=f"required field 'approveDelegation' missing from request")

sigs = body.get("sigs")
if sigs is None or len(sigs) == 0:
raise falcon.HTTPBadRequest(title="invalid interaction",
description=f"required field 'sigs' missing from approveDelegation request")

serder = serdering.SerderKERI(sad=ixn)

gatePre = ixn['a'][0]['i']
gateSaid = ixn['a'][0]['d']

for (pre, sn), dig in hab.db.delegables.getItemIter():
if pre == gatePre:
seqner = coring.Seqner(sn=serder.sn)
couple = seqner.qb64b + serder.saidb
dgkey = dbing.dgKey(coring.Saider(qb64=gatePre).qb64b, coring.Saider(qb64=gateSaid).qb64b)
hab.db.setAes(dgkey, couple) # authorizer event seal (delegator/issuer)

2byrds marked this conversation as resolved.
Show resolved Hide resolved
op = agent.monitor.submit(hab.kever.prefixer.qb64, longrunning.OpTypes.done,
metadata=dict(response=serder.ked))
return op
2byrds marked this conversation as resolved.
Show resolved Hide resolved

raise falcon.HTTPBadRequest(title=f"No delegation event found for approval")

class IdentifierCollectionEnd:
""" Resource class for creating and managing identifiers """
Expand Down Expand Up @@ -542,6 +649,8 @@ def on_post(self, req, rep, name):

except (kering.AuthError, ValueError) as e:
raise falcon.HTTPBadRequest(description=e.args[0])
except (falcon.HTTPBadRequest, falcon.HTTPNotFound, falcon.HTTPInternalServerError) as e:
raise e

@staticmethod
def rotate(agent, name, body):
Expand Down Expand Up @@ -656,7 +765,6 @@ def interact(agent, name, body):
metadata=dict(response=serder.ked))
return op


def info(hab, rm, full=False):
data = dict(
name=hab.name,
Expand Down
4 changes: 1 addition & 3 deletions src/keria/app/delegating.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def processEscrows(self):

def processUnanchoredEscrow(self):
"""
Process escrow of partially signed multisig group KEL events. Message
processing will send this local controllers signature to all other participants
then this escrow waits for signatures from all other participants
Process escrow of unacnchored events that have been delegated and are waiting for delegator anchor or approval.

"""
for (pre, said), serder in self.hby.db.dune.getItemIter(): # group partial witness escrow
Expand Down
Loading
Loading