Skip to content

Commit

Permalink
Fixes for exchange messages (#578)
Browse files Browse the repository at this point in the history
Signed-off-by: pfeairheller <[email protected]>
  • Loading branch information
pfeairheller authored Sep 28, 2023
1 parent 8c7ac2d commit 5fc7271
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ def _resolve(self, val, ptr):

keys = list(val)
if i >= len(keys):
raise Exception(f"invalid dict pointer index {i} for keys {keys}")
raise KeyError(f"invalid dict pointer index {i} for keys {keys}")

cur = val[list(val)[i]]
elif idx == "":
Expand All @@ -1936,12 +1936,12 @@ def _resolve(self, val, ptr):
elif isinstance(val, list):
i = int(idx)
if i >= len(val):
raise Exception(f"invalid array pointer index {i} for array {val}")
raise KeyError(f"invalid array pointer index {i} for array {val}")

cur = val[i]

else:
raise ValueError("invalid traversal type")
raise KeyError("invalid traversal type")

return self._resolve(cur, ptr)

Expand Down
3 changes: 3 additions & 0 deletions src/keri/core/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,11 @@ def msgParsator(self, ims=None, framed=True, pipeline=False,
exc.processEvent(tsgs=tsgs, **args)

except AttributeError as e:
print(e)
raise kering.ValidationError("No Exchange to process so dropped msg"
"= {}.".format(serder.pretty()))
except Exception as e:
print(e)

elif ilk in (Ilks.vcp, Ilks.vrt, Ilks.iss, Ilks.rev, Ilks.bis, Ilks.brv):
# TEL msg
Expand Down
3 changes: 0 additions & 3 deletions src/keri/db/basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,6 @@ def reopen(self, **kwa):
# exchange messages
self.exns = subing.SerderSuber(db=self, subkey="exns.")

# Index of exn message route to SAID of exn
self.erts = subing.CesrIoSetSuber(db=self, subkey="erts.", klas=coring.Saider)

# Forward pointer to a provided reply message
self.erpy = subing.CesrSuber(db=self, subkey="erpy.", klas=coring.Saider)

Expand Down
3 changes: 1 addition & 2 deletions src/keri/peer/exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def processEvent(self, serder, tsgs=None, cigars=None, **kwargs):

# Always persis events
self.logEvent(serder, pathed, tsgs, cigars)
self.cues.append(dict(kin="saved", said=serder.said))

# Execute any behavior specific handling, not sure if this should be different than verify
try:
Expand Down Expand Up @@ -208,7 +209,6 @@ def processEscrowPartialSigned(self):
def logEvent(self, serder, pathed=None, tsgs=None, cigars=None):
dig = serder.said
pdig = serder.ked['p']
route = serder.ked['r']
pathed = pathed or []
tsgs = tsgs or []
cigars = cigars or []
Expand All @@ -222,7 +222,6 @@ def logEvent(self, serder, pathed=None, tsgs=None, cigars=None):

saider = coring.Saider(qb64=serder.said)
self.hby.db.epath.pin(keys=(dig,), vals=[bytes(p) for p in pathed])
self.hby.db.erts.add(keys=(route,), val=saider)
if pdig:
self.hby.db.erpy.pin(keys=(pdig,), val=saider)

Expand Down
6 changes: 4 additions & 2 deletions src/keri/vc/protocoling.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ def handle(self, serder, attachments=None):
self.notifier.add(attrs=data)


def ipexApplyExn(hab, message, schema, attrs):
def ipexApplyExn(hab, recp, message, schema, attrs):
""" Apply for an ACDC
Parameters:
hab(Hab): identifier environment for issuer of credential
recp (str): qb64 AID of recipient
message(str): Human readable message regarding the credential application
schema (any): schema or its SAID
attrs (any): attribute field label list
Expand All @@ -149,7 +150,8 @@ def ipexApplyExn(hab, message, schema, attrs):
data = dict(
m=message,
s=schema,
a=attrs
a=attrs,
i=recp
)

exn, end = exchanging.exchange(route="/ipex/apply", payload=data, sender=hab.pre)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -3732,7 +3732,7 @@ def test_pather():
assert pather.bext == text
assert pather.qb64 == "4AADA-0-field1-0"
assert pather.raw == b"\x03\xed>~'\xa5w_\xb4"
with pytest.raises(ValueError):
with pytest.raises(KeyError):
pather.resolve(sad)
assert pather.path == ["0", "field1", "0"]

Expand Down
40 changes: 21 additions & 19 deletions tests/vc/test_protocoling.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,22 @@ def test_ipex(seeder, mockCoringRandomNonce, mockHelpingNowIso8601, mockHelpingN

ipexhan = protocoling.IpexHandler(resource="/ipex/apply", hby=sidHby, rgy=sidRgy, notifier=notifier)

apply0, apply0atc = protocoling.ipexApplyExn(sidHab, "Please give me a credential", schema=schema, attrs={})
assert apply0.raw == (b'{"v":"KERI10JSON00013a_","t":"exn","d":"ELTsAF3uujMxAsMaDuK_fovjTf6uhD7TDay4'
b'FYeF1HyS","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"","dt":"20'
apply0, apply0atc = protocoling.ipexApplyExn(sidHab, message="Please give me a credential", schema=schema,
recp=redPre, attrs={})

assert apply0.raw == (b'{"v":"KERI10JSON00016d_","t":"exn","d":"EI1MnUrT0aUprMN97FabgJdxVQtoCPqamVUp'
b'3iFgnDBE","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"","dt":"20'
b'21-06-27T21:26:21.233257+00:00","r":"/ipex/apply","q":{},"a":{"m":"Please gi'
b've me a credential","s":"EMQWEcCnVRk1hatTNyK3sIykYSrrFvafX3bHQ9Gkk1kC","a":{'
b'}},"e":{}}')
b'},"i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3"},"e":{}}')

# No requirements for apply, except that its first, no `p`
assert ipexhan.verify(serder=apply0) is True

offer0, offer0atc = protocoling.ipexOfferExn(sidHab, "How about this", acdc=creder.raw, apply=apply0)
assert offer0.raw == (b'{"v":"KERI10JSON0002f0_","t":"exn","d":"EGoyRJ3CwXu_1npugrPb2RF19TfshnXfhM8y'
b'kAuEwIf5","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"ELTsAF3uuj'
b'MxAsMaDuK_fovjTf6uhD7TDay4FYeF1HyS","dt":"2021-06-27T21:26:21.233257+00:00",'
assert offer0.raw == (b'{"v":"KERI10JSON0002f0_","t":"exn","d":"EO_wiH5ZEikfLQb8rKBjPATnjiSOHGBvvN3m'
b'F0LDvaIC","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EI1MnUrT0a'
b'UprMN97FabgJdxVQtoCPqamVUp3iFgnDBE","dt":"2021-06-27T21:26:21.233257+00:00",'
b'"r":"/ipex/offer","q":{},"a":{"m":"How about this"},"e":{"acdc":{"v":"ACDC10'
b'JSON000197_","d":"EDkftEwWBpohjTpemh_6xkaGNuoDsRU3qwvHdlvgfOyG","i":"EIaGMMW'
b'JFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","ri":"EO0_SyqPS1-EVYSITakYpUHaUZZpZGs'
Expand Down Expand Up @@ -153,9 +155,9 @@ def test_ipex(seeder, mockCoringRandomNonce, mockHelpingNowIso8601, mockHelpingN

# Let's see if we can spurn a message we previously accepted.
spurn0, spurn0atc = protocoling.ipexSpurnExn(sidHab, "I reject you", spurned=apply0)
assert spurn0.raw == (b'{"v":"KERI10JSON00011d_","t":"exn","d":"EN6BXnp402214Uc_Q5AyjXHr-Rm2eUw0RWyO'
b'qZtIip4-","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"ELTsAF3uuj'
b'MxAsMaDuK_fovjTf6uhD7TDay4FYeF1HyS","dt":"2021-06-27T21:26:21.233257+00:00",'
assert spurn0.raw == (b'{"v":"KERI10JSON00011d_","t":"exn","d":"EKvtmxPkOklgRNgWxLj-1ZW4Zb0MwZIUloWx'
b'A_dam95r","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EI1MnUrT0a'
b'UprMN97FabgJdxVQtoCPqamVUp3iFgnDBE","dt":"2021-06-27T21:26:21.233257+00:00",'
b'"r":"/ipex/spurn","q":{},"a":{"m":"I reject you"},"e":{}}')

# This will fail, we've already responded with an offer
Expand Down Expand Up @@ -184,9 +186,9 @@ def test_ipex(seeder, mockCoringRandomNonce, mockHelpingNowIso8601, mockHelpingN
assert serder.ked == offer1.ked

agree, argeeAtc = protocoling.ipexAgreeExn(sidHab, "I'll accept that offer", offer=offer0)
assert agree.raw == (b'{"v":"KERI10JSON000127_","t":"exn","d":"ECDIZYM_le19AYxRef_jfkfHsdrlsiLWofA7'
b'LHrpFR43","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EGoyRJ3CwX'
b'u_1npugrPb2RF19TfshnXfhM8ykAuEwIf5","dt":"2021-06-27T21:26:21.233257+00:00",'
assert agree.raw == (b'{"v":"KERI10JSON000127_","t":"exn","d":"EGpJ9S0TqIVHkRmDsbgP59NC8ZLCaSUirslB'
b'KDeYKOR7","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EO_wiH5ZEi'
b'kfLQb8rKBjPATnjiSOHGBvvN3mF0LDvaIC","dt":"2021-06-27T21:26:21.233257+00:00",'
b'"r":"/ipex/agree","q":{},"a":{"m":"I\'ll accept that offer"},"e":{}}')

# Can not create an agree without an offer, so this will pass since it has an offer that has no response
Expand Down Expand Up @@ -245,9 +247,9 @@ def test_ipex(seeder, mockCoringRandomNonce, mockHelpingNowIso8601, mockHelpingN
# Now we'll run a grant pointing back to the agree all the way to the database
grant1, grant1atc = protocoling.ipexGrantExn(sidHab, message="Here's a credential", acdc=msg, iss=iss.raw,
recp=sidHab.pre, anc=anc, agree=agree)
assert grant1.raw == (b'{"v":"KERI10JSON00055d_","t":"exn","d":"EF3SGMz-op7KoPEhDLTJsxHMKS5VaEFqN_z2'
b'EchbLW48","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"ECDIZYM_le'
b'19AYxRef_jfkfHsdrlsiLWofA7LHrpFR43","dt":"2021-06-27T21:26:21.233257+00:00",'
assert grant1.raw == (b'{"v":"KERI10JSON00055d_","t":"exn","d":"EIqh-L9GnnVSdNLeqwmx-vpE9V1DvOQAlVWf'
b'wENpm8sW","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EGpJ9S0TqI'
b'VHkRmDsbgP59NC8ZLCaSUirslBKDeYKOR7","dt":"2021-06-27T21:26:21.233257+00:00",'
b'"r":"/ipex/grant","q":{},"a":{"m":"Here\'s a credential","i":"EIaGMMWJFPm'
b'tXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3"},"e":{"acdc":{"v":"ACDC10JSON000197_","d"'
b':"EDkftEwWBpohjTpemh_6xkaGNuoDsRU3qwvHdlvgfOyG","i":"EIaGMMWJFPmtXznY1IIiKDI'
Expand All @@ -274,9 +276,9 @@ def test_ipex(seeder, mockCoringRandomNonce, mockHelpingNowIso8601, mockHelpingN

# And now the last... admit the granted credential to complete the full flow
admit0, admit0atc = protocoling.ipexAdmitExn(sidHab, "Thanks for the credential", grant=grant1)
assert admit0.raw == (b'{"v":"KERI10JSON00012a_","t":"exn","d":"EB4c-ygyLg4Q0g9hpE15_DE-nfXyH46AC2zE'
b'-c3L0cB0","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EF3SGMz-op'
b'7KoPEhDLTJsxHMKS5VaEFqN_z2EchbLW48","dt":"2021-06-27T21:26:21.233257+00:00",'
assert admit0.raw == (b'{"v":"KERI10JSON00012a_","t":"exn","d":"ELNz82kqV94vlbT7lJulVFWtf6_jhGRgH556'
b'Z-xYRaGY","i":"EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3","p":"EIqh-L9Gnn'
b'VSdNLeqwmx-vpE9V1DvOQAlVWfwENpm8sW","dt":"2021-06-27T21:26:21.233257+00:00",'
b'"r":"/ipex/admit","q":{},"a":{"m":"Thanks for the credential"},"e":{}}')
assert ipexhan.verify(serder=admit0) is True

Expand Down

0 comments on commit 5fc7271

Please sign in to comment.