Skip to content

Commit

Permalink
Merge pull request #839 from SmithSamuelM/main
Browse files Browse the repository at this point in the history
Refactor all Prefixer derive and verify functionality is now part of Serder and SerderKERI
  • Loading branch information
SmithSamuelM authored Aug 8, 2024
2 parents 2a2f8ce + 3ae0d48 commit 0971a4b
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 1,012 deletions.
358 changes: 56 additions & 302 deletions src/keri/core/coring.py

Large diffs are not rendered by default.

20 changes: 1 addition & 19 deletions src/keri/core/eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ def incept(keys,
saids = {'i': code}

serder = serdering.SerderKERI(sad=ked, makify=True, saids=saids)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -926,12 +925,8 @@ def rotate(pre,
)

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder

#_, ked = coring.Saider.saidify(sad=ked)

#return Serder(ked=ked) # return serialized ked

def deltate(pre,
keys,
Expand Down Expand Up @@ -1007,13 +1002,8 @@ def interact(pre,
)

serder = serdering.SerderKERI(sad=sad, makify=True)
serder._verify() # raises error if fails verifications
return serder

#_, ked = coring.Saider.saidify(sad=ked)

#return Serder(ked=ked) # return serialized ked


def receipt(pre,
sn,
Expand Down Expand Up @@ -1050,7 +1040,6 @@ def receipt(pre,
)

serder = serdering.SerderKERI(sad=sad, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -1105,7 +1094,6 @@ def query(route="",
)

serder = serdering.SerderKERI(sad=sad, makify=True)
serder._verify() # raises error if fails verifications
return serder

#_, ked = coring.Saider.saidify(sad=ked)
Expand Down Expand Up @@ -1162,7 +1150,6 @@ def reply(route="",
)

serder = serdering.SerderKERI(sad=sad, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -1204,7 +1191,6 @@ def prod(route="",
)

serder = serdering.SerderKERI(sad=sad, makify=True)
serder._verify() # raises error if fails verifications
return serder

#_, ked = coring.Saider.saidify(sad=ked)
Expand Down Expand Up @@ -1264,7 +1250,6 @@ def bare(route="",
)

serder = serdering.SerderKERI(sad=sad, makify=True)
serder._verify() # raises error if fails verifications
return serder

#_, sad = coring.Saider.saidify(sad=sad)
Expand Down Expand Up @@ -1779,6 +1764,7 @@ def reload(self, state):
raise MissingEntryError(f"Corresponding event not found for state="
f"{state}.")
self.serder = serdering.SerderKERI(raw=bytes(raw))

# May want to do additional checks here


Expand Down Expand Up @@ -1808,10 +1794,6 @@ def incept(self, serder, estOnly=None):


self.prefixer = Prefixer(qb64=serder.pre)
if not self.prefixer.verify(ked=ked, prefixed=True): # invalid prefix
raise ValidationError("Invalid prefix = {} for inception evt = {}."
"".format(self.prefixer.qb64, ked))

self.serder = serder # need whole serder for digest agility comparisons

ndigs = serder.ndigs # ked["n"]
Expand Down
51 changes: 35 additions & 16 deletions src/keri/core/serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@


from . import coring
from .coring import MtrDex, DigDex, PreDex, Saids, Digestage
from .coring import (MtrDex, DigDex, PreDex, NonTransDex, PreNonDigDex,
Saids, Digestage)
from .coring import (Matter, Saider, Verfer, Diger, Number, Tholder, Tagger,
Ilker, Traitor, Verser, )

Expand Down Expand Up @@ -1568,7 +1569,6 @@ class SerderKERI(Serder):
Proto = Protocols.keri # default protocol type



def _verify(self, **kwa):
"""Verifies said(s) in sad against raw
Override for protocol and ilk specific verification behavior. Especially
Expand All @@ -1588,8 +1588,8 @@ def _verify(self, **kwa):

if (self.vrsn.major < 2 and self.vrsn.minor < 1 and
self.ilk in (Ilks.qry, Ilks.rpy, Ilks.pro, Ilks.bar, Ilks.exn)):
pass
else: # verify pre
pass # non prefixive ilks do not have 'i' field
else: # verify pre 'i' field
try:
code = Matter(qb64=self.pre).code
except Exception as ex:
Expand All @@ -1604,19 +1604,38 @@ def _verify(self, **kwa):
if code not in idex:
raise ValidationError(f"Invalid identifier prefix code = {code}.")

# non-transferable pre validations
if code in [PreDex.Ed25519N, PreDex.ECDSA_256r1N, PreDex.ECDSA_256k1N]:
if self.ndigs:
raise ValidationError(f"Non-transferable code = {code} with"
f" non-empty nxt = {self.ndigs}.")

if self.backs:
raise ValidationError("Non-transferable code = {code} with"
f" non-empty backers = {self.backs}.")

if self.seals:
raise ValidationError("Non-transferable code = {code} with"
f" non-empty seals = {self.seals}.")
if self.ilk in (Ilks.icp, Ilks.dip, Ilks.rot, Ilks.drt): # est event
if self.ilk in (Ilks.icp, Ilks.dip): # inceptive event
if code in PreNonDigDex:
if len(self.keys) != 1:
raise ValidationError(f"Invalid keys = {self.keys} "
"for non-digestive prefix "
f"{code=}.")

if self.tholder.sith != '1':
raise ValidationError(f"Invalid signing threshold ="
f" {self.tholder.sith} for "
f"non-digestive prefix {code=}.")

if self.pre != self.keys[0]:
raise ValidationError(f"Mismatch prefix = {self.pre} and"
f" zeroth key = {self.keys[0]} for "
f" non-digestive prefix {code=}.")

# non-transferable pre validations
if code in NonTransDex:
if self.ndigs: # when field missing returns None
raise ValidationError(f"Non-transferable code = {code} with"
f" non-empty nxt = {self.ndigs}.")

if self.backs: # when field missing returns None
raise ValidationError("Non-transferable code = {code} with"
f" non-empty backers = {self.backs}.")

if self.seals: # when field missing returns None
raise ValidationError("Non-transferable code = {code} with"
f" non-empty seals = {self.seals}.")

if self.ilk in (Ilks.dip): # validate delpre
try:
Expand Down
7 changes: 5 additions & 2 deletions src/keri/core/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,14 @@ class Streamer:
Has the following public properties:
Properties:
stream (bytearray): sniffable CESR stream
Methods:
Hidden:
_verify() -> bool
Expand All @@ -359,9 +361,10 @@ def __init__(self, stream, verify=False):

self._stream = stream

@property

def _verify(self):
"""Returns True if sniffable stream, False otherwise
"""Returns True if .stream is sniffable, False otherwise
Returns:
sniffable (bool): True when .stream is sniffable.
False otherwise.
Expand Down
25 changes: 6 additions & 19 deletions src/keri/vdr/eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def incept(
)

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -206,7 +205,6 @@ def rotate(
)

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -247,7 +245,6 @@ def issue(
ked["dt"] = dt

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -297,7 +294,6 @@ def revoke(
_, ked = coring.Saider.saidify(sad=ked)

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -350,7 +346,6 @@ def backerIssue(
ked["dt"] = dt

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -405,7 +400,6 @@ def backerRevoke(
ked["dt"] = dt

serder = serdering.SerderKERI(sad=ked, makify=True)
serder._verify() # raises error if fails verifications
return serder


Expand Down Expand Up @@ -717,12 +711,6 @@ def __init__(self, cues=None, rsr=None, serder=None, seqner=None, saider=None,
raise ValidationError("Expected ilk {} got {} for evt: {}".format(Ilks.vcp, ilk, serder))

self.ilk = ilk
#labels = VCP_LABELS
#for k in labels:
#if k not in serder.ked:
#raise ValidationError("Missing element = {} from {} event for "
#"evt = {}.".format(k, ilk, serder.ked))

self.incept(serder=serder)
self.config(serder=serder, noBackers=noBackers, estOnly=estOnly)

Expand Down Expand Up @@ -819,14 +807,13 @@ def incept(self, serder):
"""

ked = serder.ked
self.pre = ked["ii"]
self.prefixer = Prefixer(qb64=serder.pre)
if not self.prefixer.verify(ked=ked, prefixed=True): # invalid prefix
raise ValidationError("Invalid prefix = {} for registry inception evt = {}."
.format(self.prefixer.qb64, ked))
self.pre = ked["ii"] # which is not the AID of the serder in ked["i"]
self.prefixer = Prefixer(qb64=serder.pre) # this not related to self.pre
#if not self.prefixer.verify(ked=ked, prefixed=True): # invalid prefix
#raise ValidationError("Invalid prefix = {} for registry inception evt = {}."
#.format(self.prefixer.qb64, ked))


#sn = ked["s"]
#self.sn = validateSN(sn, inceptive=True)
self.sn = Number(numh=ked["s"]).validate(inceptive=True).sn

self.cuts = [] # always empty at inception since no prev event
Expand Down
Loading

0 comments on commit 0971a4b

Please sign in to comment.