Skip to content

Commit

Permalink
The PR attempts to catch up with KERIpy delegation logic (#246)
Browse files Browse the repository at this point in the history
* Updates to delegation to fix the order of witnessing and delegation approval.  Also switched the agent parser to local=True

* Update to newest development release of KERIpy and added call to new Kevery.processEscrowDelegables() during escrow processing.

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

---------

Signed-off-by: pfeairheller <[email protected]>
  • Loading branch information
pfeairheller authored May 29, 2024
1 parent a1a9b02 commit 6b33043
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build-keria
build-keria:
@docker buildx build --platform=linux/amd64 --no-cache -f images/keria.dockerfile --tag weboftrust/keria:0.2.0-dev0 .
@docker buildx build --platform=linux/amd64 --no-cache -f images/keria.dockerfile --tag weboftrust/keria:0.2.0-dev1 .

publish-keria:
@docker push weboftrust/keria --all-tags
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-dev2',
'keri==1.2.0-dev4',
'mnemonic>=0.20',
'multicommand>=1.0.0',
'falcon>=3.1.3',
Expand Down
13 changes: 6 additions & 7 deletions src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from dataclasses import asdict
from urllib.parse import urlparse, urljoin


import falcon
from falcon import media
from hio.base import doing
Expand All @@ -21,15 +20,13 @@
from keri.app.notifying import Notifier
from keri.app.storing import Mailboxer


from keri.app import configing, keeping, habbing, storing, signaling, oobiing, agenting, \
forwarding, querying, connecting, grouping
from keri.app.grouping import Counselor
from keri.app.keeping import Algos
from keri.core import coring, parsing, eventing, routing, serdering
from keri.core.coring import Ilks
from keri.core.signing import Salter
from keri.db import dbing
from keri.db.basing import OobiRecord
from keri.vc import protocoling

Expand Down Expand Up @@ -211,8 +208,8 @@ def create(self, caid, salt=None):
configDir=self.configDir,
configFile=self.configFile)

res = self.adb.agnt.pin(keys=(caid,),
val=coring.Prefixer(qb64=agent.pre))
self.adb.agnt.pin(keys=(caid,),
val=coring.Prefixer(qb64=agent.pre))

self.adb.ctrl.pin(keys=(agent.pre,),
val=coring.Prefixer(qb64=caid))
Expand Down Expand Up @@ -362,7 +359,8 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts):
tvy=self.tvy,
exc=self.exc,
rvy=self.rvy,
vry=self.verifier)
vry=self.verifier,
local=True) # disable misfit escrow until we can add another parser for remote.

doers.extend([
Initer(agentHab=agentHab, caid=caid),
Expand All @@ -373,7 +371,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts):
Witnesser(receiptor=receiptor, witners=self.witners),
Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors),
ExchangeSender(hby=hby, agentHab=agentHab, exc=self.exc, exchanges=self.exchanges),
Granter(hby=hby, rgy=rgy, agentHab=agentHab, exc=self.exc, grants=self.grants),
Granter(hby=hby, rgy=rgy, agentHab=agentHab, exc=self.exc, grants=self.grants),
Admitter(hby=hby, witq=self.witq, psr=self.parser, agentHab=agentHab, exc=self.exc, admits=self.admits),
GroupRequester(hby=hby, agentHab=agentHab, counselor=self.counselor, groups=self.groups),
SeekerDoer(seeker=self.seeker, cues=self.verifier.cues),
Expand Down Expand Up @@ -752,6 +750,7 @@ def __init__(self, kvy, rgy, rvy, tvy, exc, vry, registrar, credentialer):
def recur(self, tyme):
""" Process all escrows once per loop. """
self.kvy.processEscrows()
self.kvy.processEscrowDelegables()
self.rgy.processEscrows()
self.rvy.processEscrowReply()
if self.tvy is not None:
Expand Down
49 changes: 28 additions & 21 deletions src/keria/app/delegating.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def delegation(self, pre, sn=None, proxy=None):
if pre not in self.hby.habs:
raise kering.ValidationError(f"{pre} is not a valid local AID for delegation")

if proxy is not None:
self.proxy = proxy

# load the hab of the delegated identifier to anchor
hab = self.hby.habs[pre]
delpre = hab.kever.delpre # get the delegator identifier
Expand All @@ -50,22 +53,9 @@ def delegation(self, pre, sn=None, proxy=None):
# load the event and signatures
evt = hab.makeOwnEvent(sn=sn)

if isinstance(hab, habbing.GroupHab):
phab = hab.mhab
elif hab.kever.sn > 0:
phab = hab
elif proxy is not None:
phab = proxy
elif self.proxy is not None:
phab = self.proxy
else:
raise kering.ValidationError("no proxy to send messages for delegation")

srdr = serdering.SerderKERI(raw=evt)
del evt[:srdr.size]
self.postman.send(hab=phab, dest=delpre, topic="delegate", serder=srdr, attachment=evt)

self.hby.db.dune.pin(keys=(srdr.pre, srdr.said), val=srdr)
self.witDoer.msgs.append(dict(pre=pre, sn=srdr.sn))
self.hby.db.dpwe.pin(keys=(srdr.pre, srdr.said), val=srdr)

def complete(self, prefixer, seqner, saider=None):
""" Check for completed delegation protocol for the specific event
Expand Down Expand Up @@ -114,8 +104,8 @@ def escrowDo(self, tymth, tock=1.0):
yield 0.5

def processEscrows(self):
self.processUnanchoredEscrow()
self.processPartialWitnessEscrow()
self.processUnanchoredEscrow()

def processUnanchoredEscrow(self):
"""
Expand All @@ -134,11 +124,10 @@ def processUnanchoredEscrow(self):
couple = seqner.qb64b + dserder.saidb
dgkey = dbing.dgKey(kever.prefixer.qb64b, kever.serder.saidb)
self.hby.db.setAes(dgkey, couple) # authorizer event seal (delegator/issuer)
self.witDoer.msgs.append(dict(pre=pre, sn=serder.sn))

# Move to escrow waiting for witness receipts
print(f"Waiting for fully signed witness receipts for {serder.sn}")
self.hby.db.dpwe.pin(keys=(pre, said), val=serder)
print(f"Delegation approval received, {serder.pre} confirmed")
self.hby.db.cdel.put(keys=(pre, coring.Seqner(sn=serder.sn).qb64), val=coring.Saider(qb64=serder.said))
self.hby.db.dune.rem(keys=(pre, said))

def processPartialWitnessEscrow(self):
Expand All @@ -149,7 +138,9 @@ def processPartialWitnessEscrow(self):
"""
for (pre, said), serder in self.hby.db.dpwe.getItemIter(): # group partial witness escrow
hab = self.hby.habs[pre]
kever = self.hby.kevers[pre]
delpre = hab.kever.delpre # get the delegator identifier
dgkey = dbing.dgKey(pre, serder.said)
seqner = coring.Seqner(sn=serder.sn)

Expand All @@ -163,6 +154,22 @@ def processPartialWitnessEscrow(self):
witnessed = True
if not witnessed:
continue
print(f"Witness receipts complete, {pre} confirmed.")
print(f"Witness receipts complete, waiting for delegation approval.")
if isinstance(hab, habbing.GroupHab):
phab = hab.mhab
elif hab.kever.sn > 0:
phab = hab
elif self.proxy is not None:
phab = self.proxy
else:
raise kering.ValidationError("no proxy to send messages for delegation")

evt = hab.db.cloneEvtMsg(pre=serder.pre, fn=0, dig=serder.said)

srdr = serdering.SerderKERI(raw=evt)
del evt[:srdr.size]
self.postman.send(hab=phab, dest=delpre, topic="delegate", serder=srdr, attachment=evt)

self.hby.db.dpwe.rem(keys=(pre, said))
self.hby.db.cdel.put(keys=(pre, seqner.qb64), val=coring.Saider(qb64=serder.said))
self.hby.db.dune.pin(keys=(srdr.pre, srdr.said), val=srdr)

4 changes: 0 additions & 4 deletions tests/app/test_delegating.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def test_sealer():
with pytest.raises(kering.ValidationError):
anchorer.delegation(pre="EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHZSysY")

# Needs a proxy
with pytest.raises(kering.ValidationError):
anchorer.delegation(pre=delegate.pre)

# Run delegation to escrow inception event
anchorer.delegation(pre=delegate.pre, proxy=proxy)
doist.recur(deeds=deeds)
Expand Down

0 comments on commit 6b33043

Please sign in to comment.