From db6663d233d38ee87f9c9a61ab2df912298a7048 Mon Sep 17 00:00:00 2001 From: Samuel M Smith Date: Mon, 1 Jan 2024 14:51:28 -0700 Subject: [PATCH] some refactor of methos names to distinquish processing of the attached equivalent of receipt versus the actual rct messages enabled the new local pass in from parser for rct messages. --- src/keri/core/eventing.py | 79 ++++++++++++++++++++++++++------------- src/keri/core/parsing.py | 15 +++++--- src/keri/db/basing.py | 15 ++++++-- 3 files changed, 74 insertions(+), 35 deletions(-) diff --git a/src/keri/core/eventing.py b/src/keri/core/eventing.py index ac6443653..72cb311d4 100644 --- a/src/keri/core/eventing.py +++ b/src/keri/core/eventing.py @@ -3527,8 +3527,9 @@ def processEvent(self, serder, sigers, *, wigers=None, if sigers or wigers: # at least one verified sig or wig so log evt # this allows late arriving witness receipts or controller # signatures to be added to the databse - # not first seen inception so ignore return - kever.logEvent(serder, sigers=sigers, wigers=wigers) # idempotent update db logs + # Not first seen version of event so ignore return + # idempotent update db logs + kever.logEvent(serder, sigers=sigers, wigers=wigers) else: # escrow likely duplicitous event self.escrowLDEvent(serder=serder, sigers=sigers) @@ -3619,7 +3620,10 @@ def processEvent(self, serder, sigers, *, wigers=None, verfers=werfers) if sigers or wigers: # at least one verified sig or wig so log evt - # not first seen update so ignore return + # this allows late arriving witness receipts or controller + # signatures to be added to the databse + # Not first seen version of event so ignore return + # idempotent update db logs kever.logEvent(serder, sigers=sigers, wigers=wigers) # idempotent update db logs else: # escrow likely duplicitous event @@ -3629,7 +3633,8 @@ def processEvent(self, serder, sigers, *, wigers=None, def processReceiptWitness(self, serder, wigers, local=None): """ - Process one witness receipt serder with attached witness sigers + Process one witness receipt serder with attached witness wigers + (indexed signatures) Parameters: serder (SerderKERI): instance of serialized receipt message not receipted event @@ -3654,7 +3659,6 @@ def processReceiptWitness(self, serder, wigers, local=None): # fetch pre dig to process ked = serder.ked pre = serder.pre - sn = serder.sn # Only accept receipt if for last seen version of event at sn @@ -3682,13 +3686,13 @@ def processReceiptWitness(self, serder, wigers, local=None): if wiger.verfer.transferable: # skip transferable verfers continue # skip invalid witness prefix - if not self.lax and wiger.verfer.qb64 in self.prefixes: # own is receiptor + if not self.lax and wiger.verfer.qb64 in self.prefixes: # own is witness if pre in self.prefixes: # skip own receiptor of own event # sign own events not receipt them logger.info("Kevery process: skipped own receipt attachment" " on own event receipt=\n%s\n", serder.pretty()) continue # skip own receipt attachment on own event - if not self.local: # own receipt on other event when not local + if not local: # so skip own receipt on other event when non-local source logger.info("Kevery process: skipped own receipt attachment" " on nonlocal event receipt=\n%s\n", serder.pretty()) continue # skip own receipt attachment on non-local event @@ -3705,10 +3709,13 @@ def processReceiptWitness(self, serder, wigers, local=None): def processReceipt(self, serder, cigars, local=None): """ - Process one receipt serder with attached cigars (non-witness receipts) + Process one receipt serder with attached cigars + may or may not be a witness receipt. If prefix matches witness then + promote to indexed witness signature and store appropriately. Otherwise + signature is nontrans nonwitness endorser (watcher etc) Parameters: - serder (SerderKERI): instance of serialized receipt message not receipted message + serder (SerderKERI): rct instance of serialized receipt message cigars (list[Cigar]): instances that contain receipt couple signature in .raw and public key in .verfer local (bool|None): True means local (protected) event source. @@ -3757,7 +3764,7 @@ def processReceipt(self, serder, cigars, local=None): logger.info("Kevery process: skipped own receipt attachment" " on own event receipt=\n%s\n", serder.pretty()) continue # skip own receipt attachment on own event - if not self.local: # own receipt on other event when not local + if not local: # skip own receipt on other event when not local logger.info("Kevery process: skipped own receipt attachment" " on nonlocal event receipt=\n%s\n", serder.pretty()) continue # skip own receipt attachment on non-local event @@ -3779,17 +3786,23 @@ def processReceipt(self, serder, cigars, local=None): raise UnverifiedReceiptError("Unverified receipt={}.".format(ked)) - def processReceiptCouples(self, serder, cigars, firner=None, local=None): + def processAttachedReceiptCouples(self, serder, cigars, firner=None, local=None): """ - Process attachment with receipt couple + Process one attachment couple that represents an endorsement from + a nontransferable AID that may or may not be a witness, maybe a watcher. + Originally may have been a non-transferable receipt or key event attachment + if signature is for witness then promote to indexed sig and store + appropriately. + The is the attachment version of .processReceipt Parameters: - serder (SerderKERI): instance of receipted serialized event message - to which receipts are attached from replay + serder (SerderKERI): instance serialized event message to which + attachments come from replay (clone) cigars (list[Cigar]): instances that contain receipt couple signature in .raw and public key in .verfer firner (Seqner): instance of first seen ordinal, if provided lookup event by fn = firner.sn + used when in cloned replay mode local (bool|None): True means local (protected) event source. False means remote (unprotected). None means use default .local . @@ -3832,7 +3845,7 @@ def processReceiptCouples(self, serder, cigars, firner=None, local=None): logger.info("Kevery process: skipped own receipt attachment" " on own event receipt=\n%s\n", serder.pretty()) continue # skip own receipt attachment on own event - if not self.local: # own receipt on other event when not local + if not local: # own receipt on other event when not local logger.info("Kevery process: skipped own receipt attachment" " on nonlocal event receipt=\n%s\n", serder.pretty()) continue # skip own receipt attachment on non-local event @@ -3852,6 +3865,8 @@ def processReceiptCouples(self, serder, cigars, firner=None, local=None): def processReceiptTrans(self, serder, tsgs, local=None): """ Process one transferable validator receipt (chit) serder with attached sigers + (indexed signatures) who are not controllers. Controllers may only attach signatures to + the associated event not by sending signature attached to receipt of event. Parameters: serder (serderKERI): rct (transferable validator receipt message) @@ -3897,18 +3912,18 @@ def processReceiptTrans(self, serder, tsgs, local=None): for sprefixer, sseqner, saider, sigers in tsgs: # iterate over each tsg if not self.lax and sprefixer.qb64 in self.prefixes: # own is receipter if pre in self.prefixes: # skip own receipter of own event - # sign own events not receipt them + # sign own events as controller not endorse them via receipt raise ValidationError("Own pre={} receipter of own event" " {}.".format(self.prefixes, serder.pretty())) - if not self.local: # skip own receipts of nonlocal events + if not local: # skip own receipts of nonlocal events raise ValidationError("Own pre={} receipter of nonlocal event " "{}.".format(self.prefixes, serder.pretty())) # receipted event in db so attempt to get receipter est evt - # retrieve dig of last event at sn of est evt of receipter. + # retrieve dig of last event at sn of est evt of receiptor. sdig = self.db.getKeLast(key=snKey(pre=sprefixer.qb64b, sn=sseqner.sn)) if sdig is None: - # receipter's est event not yet in receipters's KEL + # receiptor's est event not yet in receiptors's KEL # so need cue to discover est evt KEL for receipter from watcher etc self.escrowTReceipts(serder, sprefixer, sseqner, saider, sigers) raise UnverifiedTransferableReceiptError("Unverified receipt: " @@ -3916,7 +3931,7 @@ def processReceiptTrans(self, serder, tsgs, local=None): "receipter for event={}." "".format(ked)) - # retrieve last event itself of receipter est evt from sdig. + # retrieve last event itself of receiptor est evt from sdig. sraw = self.db.getEvt(key=dgKey(pre=sprefixer.qb64b, dig=bytes(sdig))) # assumes db ensures that sraw must not be none because sdig was in KE sserder = serdering.SerderKERI(raw=bytes(sraw)) @@ -3932,7 +3947,7 @@ def processReceiptTrans(self, serder, tsgs, local=None): " dig = {} from pre ={}, no keys." "".format(saider.qb64, sprefixer.qb64)) - for siger in sigers: + for siger in sigers: # endorser (non-controller) signatures if siger.index >= len(sverfers): raise ValidationError("Index = {} to large for keys." "".format(siger.index)) @@ -3943,15 +3958,21 @@ def processReceiptTrans(self, serder, tsgs, local=None): self.db.addVrc(key=dgKey(pre=pre, dig=ldig), val=quadruple) # dups kept - def processReceiptQuadruples(self, serder, trqs, firner=None, local=None): + def processAttachedReceiptQuadruples(self, serder, trqs, firner=None, local=None): """ - Process one attachment quadruple that comprises a transferable receipt + Process one attachment quadruple that represents an endorsement from + a transferable AID that is not the controller. Maybe a watcher. + Originally may have been a transferable receipt or key event attachment + + This is the attachement version of .processReceiptTrans Parameters: - serder (serderKERI): rct (transferable validator receipt message) + serder (serderKERI): instance serialized event message to which + attachments come from replay (clone) trqs (list[tuple]): quadruples of (prefixer, seqner, diger, siger) firner (Seqner): instance of first seen ordinal, if provided lookup event by fn = firner.sn + used when in cloned replay mode local (bool|None): True means local (protected) event source. False means remote (unprotected). None means use default .local . @@ -3982,7 +4003,7 @@ def processReceiptQuadruples(self, serder, trqs, firner=None, local=None): raise ValidationError("Own pre={} replay attached transferable " "receipt quadruple of own event {}." "".format(self.prefixes, serder.pretty())) - if not self.local: # skip own trans receipt quadruples of nonlocal events + if not local: # skip own trans receipt quadruples of nonlocal events raise ValidationError("Own pre={} seal in replay attached " "transferable receipt quadruples of nonlocal" " event {}.".format(self.prefixes, serder.pretty())) @@ -5773,7 +5794,13 @@ def processQueryNotFound(self): # process event sigers = [Siger(qb64b=bytes(sig)) for sig in sigs] - # get wigs + # ToDo XXXX get wigs and attach + # getWigs + + # ToDo XXXX get trans endorsements + # getVrcs + + # get nontrans endorsements cigars = [] cigs = self.db.getRcts(dgKey(pre, bytes(edig))) # list of wigs for cig in cigs: diff --git a/src/keri/core/parsing.py b/src/keri/core/parsing.py index 0b02a97dd..519755e78 100644 --- a/src/keri/core/parsing.py +++ b/src/keri/core/parsing.py @@ -1077,9 +1077,11 @@ def msgParsator(self, ims=None, framed=True, pipeline=False, local=local) if cigars: - kvy.processReceiptCouples(serder, cigars, firner=firner) + kvy.processAttachedReceiptCouples(serder, cigars, + firner=firner, local=local) if trqs: - kvy.processReceiptQuadruples(serder, trqs, firner=firner) + kvy.processAttachedReceiptQuadruples(serder, trqs, + firner=firner, local=local) except AttributeError as ex: raise kering.ValidationError("No kevery to process so dropped msg" @@ -1092,13 +1094,16 @@ def msgParsator(self, ims=None, framed=True, pipeline=False, try: if cigars: - kvy.processReceipt(serder=serder, cigars=cigars) + kvy.processReceipt(serder=serder, cigars=cigars, + local=local) if wigers: - kvy.processReceiptWitness(serder=serder, wigers=wigers) + kvy.processReceiptWitness(serder=serder, wigers=wigers, + local=local) if tsgs: - kvy.processReceiptTrans(serder=serder, tsgs=tsgs) + kvy.processReceiptTrans(serder=serder, tsgs=tsgs, + local=local) except AttributeError: raise kering.ValidationError("No kevery to process so dropped msg" diff --git a/src/keri/db/basing.py b/src/keri/db/basing.py index 9c27e6ce6..374e20098 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -618,8 +618,9 @@ class Baser(dbing.LMDBer): More than one value per DB key is allowed .rcts is named sub DB of event receipt couplets from nontransferable - signers. Used to manage out of order events such as escrowing - receipt couple until event receipted shows up. + signers. + These are endorsements from nontrasferable signers who are not witnesses + May be watchers or other Each couple is concatenation of fully qualified items. These are: non-transferale prefix plus non-indexed event signature by that prefix. @@ -632,6 +633,8 @@ class Baser(dbing.LMDBer): qualified items. These are: receipted event digest, non-transferable receiptor identifier prefix, plus nonindexed receipt event signature by that prefix. + Used to manage out of order events such as escrowing + receipt couple until event receipted shows up. snKey DB is keyed by receipted event controller prefix plus sn of serialized event @@ -642,6 +645,8 @@ class Baser(dbing.LMDBer): of validator. These are: transferable prefix, plus latest establishment event sequence number plus latest establishment event digest, plus indexed event signature. + These are endorsements by transferable AIDs that are not the controller + may be watchers or others. When latest establishment event is multisig then there will be multiple quadruples one per signing key, each a dup at same db key. dgKey @@ -1354,14 +1359,16 @@ def cloneEvtMsg(self, pre, fn, dig): count=1).qb64b) atc.extend(couple) - # add trans receipts quadruples to attachments + # add trans endorsement quadruples to attachments not controller + # may have been originally key event attachments or receipted endorsements if quads := self.getVrcs(key=dgkey): atc.extend(coring.Counter(code=coring.CtrDex.TransReceiptQuadruples, count=len(quads)).qb64b) for quad in quads: atc.extend(quad) - # add nontrans receipts couples to attachments + # add nontrans endorsement couples to attachments not witnesses + # may have been originally key event attachments or receipted endorsements if coups := self.getRcts(key=dgkey): atc.extend(coring.Counter(code=coring.CtrDex.NonTransReceiptCouples, count=len(coups)).qb64b)