Skip to content

Commit

Permalink
more porting to use new versioned Counter in core.counting
Browse files Browse the repository at this point in the history
  • Loading branch information
SmithSamuelM committed Jul 23, 2024
1 parent b3dd43b commit 606b106
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 54 deletions.
10 changes: 5 additions & 5 deletions src/keri/app/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hio.base import doing
from hio.help import decking

from .. import kering
from .. import kering, core
from .. import help
from ..app import delegating, agenting
from ..core import coring, routing, eventing, parsing, serdering, indexing
Expand Down Expand Up @@ -518,14 +518,14 @@ def getEscrowedEvent(db, pre, sn):

msg = bytearray()
msg.extend(serder.raw)
msg.extend(coring.Counter(code=coring.CtrDex.ControllerIdxSigs,
count=len(sigs)).qb64b) # attach cnt
msg.extend(core.Counter(core.Codens.ControllerIdxSigs,
count=len(sigs), gvrsn=kering.Vrsn_1_0).qb64b) # attach cnt
for sig in sigs:
msg.extend(sig.qb64b) # attach sig

if couple is not None:
msg.extend(coring.Counter(code=coring.CtrDex.SealSourceCouples,
count=1).qb64b)
msg.extend(core.Counter(core.Codens.SealSourceCouples,
count=1, gvrsn=kering.Vrsn_1_0).qb64b)
msg.extend(couple)

return msg
Expand Down
8 changes: 6 additions & 2 deletions src/keri/app/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
keri.app.signing module
"""
from ..kering import Vrsn_1_0, Vrsn_2_0
from ..app.habbing import GroupHab
from ..core import coring, eventing
from .. import core
from ..core import coring, eventing, counting



def serialize(creder, prefixer, seqner, saider):
craw = bytearray(creder.raw)
craw.extend(coring.Counter(coring.CtrDex.SealSourceTriples, count=1).qb64b)
craw.extend(core.Counter(core.Codens.SealSourceTriples, count=1,
gvrsn=Vrsn_1_0).qb64b)
craw.extend(prefixer.qb64b)
craw.extend(seqner.qb64b)
craw.extend(saider.qb64b)
Expand Down
2 changes: 1 addition & 1 deletion src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ class Matter:


def __init__(self, raw=None, code=MtrDex.Ed25519N, soft='', rize=None,
qb64b=None, qb64=None, qb2=None, strip=False):
qb64b=None, qb64=None, qb2=None, strip=False, **kwa):
"""
Validate as fully qualified
Parameters:
Expand Down
4 changes: 3 additions & 1 deletion src/keri/core/counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ class Counter:
'-0L': Sizage(hs=3, ss=5, fs=8, ls=0),
'-V': Sizage(hs=2, ss=2, fs=4, ls=0),
'-0V': Sizage(hs=3, ss=5, fs=8, ls=0),
'-Z': Sizage(hs=2, ss=2, fs=4, ls=0),
'--AAA': Sizage(hs=5, ss=3, fs=8, ls=0),
},
},
Expand Down Expand Up @@ -423,7 +424,8 @@ class Counter:


def __init__(self, code=None, *, count=None, countB64=None,
qb64b=None, qb64=None, qb2=None, strip=False, gvrsn=Vrsn_2_0):
qb64b=None, qb64=None, qb2=None, strip=False,
gvrsn=Vrsn_2_0, **kwa):
"""
Validate as fully qualified
Parameters:
Expand Down
53 changes: 34 additions & 19 deletions src/keri/core/eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from hio.help import decking


from .. import kering
from .. import kering, core
from ..kering import (MissingEntryError,
ValidationError, MissingSignatureError,
MissingWitnessSignatureError, UnverifiedReplyError,
Expand All @@ -30,10 +30,12 @@

from . import coring
from .coring import (versify, Serials, Ilks, PreDex, DigDex,
NonTransDex, CtrDex, Counter,
NonTransDex,
Number, Seqner, Cigar, Dater,
Verfer, Diger, Prefixer, Tholder, Saider)

from .counting import Counter, Codens

from . import indexing
from .indexing import Siger

Expand Down Expand Up @@ -1304,29 +1306,34 @@ def messagize(serder, *, sigers=None, seal=None, wigers=None, cigars=None,

if sigers:
if isinstance(seal, SealEvent):
atc.extend(Counter(CtrDex.TransIdxSigGroups, count=1).qb64b)
atc.extend(Counter(Codens.TransIdxSigGroups, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
atc.extend(seal.i.encode("utf-8"))
atc.extend(Seqner(snh=seal.s).qb64b)
atc.extend(seal.d.encode("utf-8"))

elif isinstance(seal, SealLast):
atc.extend(Counter(CtrDex.TransLastIdxSigGroups, count=1).qb64b)
atc.extend(Counter(Codens.TransLastIdxSigGroups, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
atc.extend(seal.i.encode("utf-8"))

atc.extend(Counter(code=CtrDex.ControllerIdxSigs, count=len(sigers)).qb64b)
atc.extend(Counter(Codens.ControllerIdxSigs, count=len(sigers),
gvrsn=kering.Vrsn_1_0).qb64b)
for siger in sigers:
atc.extend(siger.qb64b)

if wigers:
atc.extend(Counter(code=CtrDex.WitnessIdxSigs, count=len(wigers)).qb64b)
atc.extend(Counter(Codens.WitnessIdxSigs, count=len(wigers),
gvrsn=kering.Vrsn_1_0).qb64b)
for wiger in wigers:
if wiger.verfer and wiger.verfer.code not in NonTransDex:
raise ValueError("Attempt to use tranferable prefix={} for "
"receipt.".format(wiger.verfer.qb64))
atc.extend(wiger.qb64b)

if cigars:
atc.extend(Counter(code=CtrDex.NonTransReceiptCouples, count=len(cigars)).qb64b)
atc.extend(Counter(Codens.NonTransReceiptCouples, count=len(cigars),
gvrsn=kering.Vrsn_1_0).qb64b)
for cigar in cigars:
if cigar.verfer.code not in NonTransDex:
raise ValueError("Attempt to use tranferable prefix={} for "
Expand All @@ -1338,8 +1345,8 @@ def messagize(serder, *, sigers=None, seal=None, wigers=None, cigars=None,
if len(atc) % 4:
raise ValueError("Invalid attachments size={}, nonintegral"
" quadlets.".format(len(atc)))
msg.extend(Counter(code=CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b)
msg.extend(Counter(Codens.AttachmentGroup,
count=(len(atc) // 4), gvrsn=kering.Vrsn_1_0).qb64b)

msg.extend(atc)
return msg
Expand Down Expand Up @@ -1370,33 +1377,40 @@ def proofize(sadtsgs=None, *, sadsigers=None, sadcigars=None, pipelined=False):
count = 0
for (pather, sigers) in sadsigers:
count += 1
atc.extend(coring.Counter(coring.CtrDex.SadPathSigGroups, count=1).qb64b)
atc.extend(Counter(Codens.SadPathSigGroups, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
atc.extend(pather.qb64b)

atc.extend(coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)).qb64b)
atc.extend(Counter(Codens.ControllerIdxSigs,
count=len(sigers), gvrsn=kering.Vrsn_1_0).qb64b)
for siger in sigers:
atc.extend(siger.qb64b)

for (pather, prefixer, seqner, saider, sigers) in sadtsgs:
count += 1
atc.extend(coring.Counter(coring.CtrDex.SadPathSigGroups, count=1).qb64b)
atc.extend(Counter(Codens.SadPathSigGroups, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
atc.extend(pather.qb64b)

atc.extend(coring.Counter(coring.CtrDex.TransIdxSigGroups, count=1).qb64b)
atc.extend(Counter(Codens.TransIdxSigGroups, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
atc.extend(prefixer.qb64b)
atc.extend(seqner.qb64b)
atc.extend(saider.qb64b)

atc.extend(coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)).qb64b)
atc.extend(Counter(Codens.ControllerIdxSigs,
count=len(sigers), gvrsn=kering.Vrsn_1_0).qb64b)
for siger in sigers:
atc.extend(siger.qb64b)

for (pather, cigars) in sadcigars:
count += 1
atc.extend(coring.Counter(coring.CtrDex.SadPathSigGroups, count=1).qb64b)
atc.extend(Counter(Codens.SadPathSigGroups, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
atc.extend(pather.qb64b)

atc.extend(coring.Counter(code=coring.CtrDex.NonTransReceiptCouples, count=len(sadcigars)).qb64b)
atc.extend(Counter(Codens.NonTransReceiptCouples,
count=len(sadcigars), gvrsn=kering.Vrsn_1_0).qb64b)
for cigar in cigars:
if cigar.verfer.code not in coring.NonTransDex:
raise ValueError("Attempt to use tranferable prefix={} for "
Expand All @@ -1410,12 +1424,13 @@ def proofize(sadtsgs=None, *, sadsigers=None, sadcigars=None, pipelined=False):
if len(atc) % 4:
raise ValueError("Invalid attachments size={}, nonintegral"
" quadlets.".format(len(atc)))
msg.extend(coring.Counter(code=coring.CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b)
msg.extend(Counter(Codens.AttachmentGroup, count=(len(atc) // 4),
gvrsn=kering.Vrsn_1_0).qb64b)

if count > 1:
root = coring.Pather(bext="-")
msg.extend(coring.Counter(code=coring.CtrDex.RootSadPathSigGroups, count=count).qb64b)
msg.extend(Counter(Codens.RootSadPathSigGroups, count=count,
gvrsn=kering.Vrsn_1_0).qb64b)
msg.extend(root.qb64b)

msg.extend(atc)
Expand Down
2 changes: 1 addition & 1 deletion src/keri/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Indexer:


def __init__(self, raw=None, code=IdrDex.Ed25519_Sig, index=0, ondex=None,
qb64b=None, qb64=None, qb2=None, strip=False):
qb64b=None, qb64=None, qb2=None, strip=False, **kwa):
"""
Validate as fully qualified
Parameters:
Expand Down
37 changes: 27 additions & 10 deletions src/keri/core/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

import logging

from .coring import (Ilks, CtrDex, Counter, Seqner, Cigar,
from ..kering import Vrsn_1_0, Vrsn_2_0
from .coring import (Ilks, CtrDex, Seqner, Cigar,
Dater, Verfer, Prefixer, Saider, Pather, Texter)
from .counting import Counter, Codens
from .indexing import (Siger, )
from . import serdering
from .. import help
from .. import kering
from ..kering import Colds, sniff
from ..kering import Colds, sniff, Vrsn_1_0, Vrsn_2_0

logger = help.ogler.getLogger()

Expand Down Expand Up @@ -94,7 +96,7 @@ def extract(ims, klas, cold=Colds.txt):


@staticmethod
def _extractor(ims, klas, cold=Colds.txt, abort=False):
def _extractor(ims, klas, cold=Colds.txt, abort=False, gvrsn=Vrsn_1_0):
"""
Returns generator to extract and return instance of klas from input
message stream, ims, given stream state, cold, is txt or bny.
Expand All @@ -103,16 +105,24 @@ def _extractor(ims, klas, cold=Colds.txt, abort=False):
Inits klas from ims using qb64b or qb2 parameter based on cold.
Yields if not enough bytes in ims to fill out klas instance.
Parameters:
ims (bytearray): input message stream (must be strippable)
klas (Serder | Counter | Matter | Indexer): subclass that is parsable
cold (Coldage): instance str value
abort (bool): True means abort if bad pipelined frame Shortage
False means do not abort if Shortage just wait for more
gvrsn (Versionage): instance of genera version of CESR code tables
Usage:
instance = self._extractor
"""
while True:
try:
if cold == Colds.txt:
return klas(qb64b=ims, strip=True)
return klas(qb64b=ims, strip=True, gvrsn=gvrsn)
elif cold == Colds.bny:
return klas(qb2=ims, strip=True)
return klas(qb2=ims, strip=True, gvrsn=gvrsn)
else:
raise kering.ColdStartError("Invalid stream state cold={}.".format(cold))
except kering.ShortageError as ex:
Expand Down Expand Up @@ -263,7 +273,7 @@ def _nonTransReceiptCouples(self, ctr, ims, cold=Colds.txt, pipelined=False):


def parse(self, ims=None, framed=None, pipeline=None, kvy=None, tvy=None,
exc=None, rvy=None, vry=None, local=None):
exc=None, rvy=None, vry=None, local=None, gvrsn=Vrsn_1_0):
"""
Processes all messages from incoming message stream, ims,
when provided. Otherwise process messages from .ims
Expand All @@ -289,6 +299,7 @@ def parse(self, ims=None, framed=None, pipeline=None, kvy=None, tvy=None,
local (bool): True means event source is local (protected) for validation
False means event source is remote (unprotected) for validation
None means use default .local
gvrsn (Versionage): instance of genera version of CESR code tables
New Logic:
Attachments must all have counters so know if txt or bny format for
Expand All @@ -306,7 +317,8 @@ def parse(self, ims=None, framed=None, pipeline=None, kvy=None, tvy=None,
exc=exc,
rvy=rvy,
vry=vry,
local=local)
local=local,
gvrsn=gvrsn)

while True:
try:
Expand Down Expand Up @@ -366,7 +378,8 @@ def parseOne(self, ims=None, framed=True, pipeline=False, kvy=None, tvy=None,


def allParsator(self, ims=None, framed=None, pipeline=None, kvy=None,
tvy=None, exc=None, rvy=None, vry=None, local=None):
tvy=None, exc=None, rvy=None, vry=None, local=None,
gvrsn=Vrsn_1_0):
"""
Returns generator to parse all messages from incoming message stream,
ims until ims is exhausted (empty) then returns.
Expand All @@ -392,6 +405,7 @@ def allParsator(self, ims=None, framed=None, pipeline=None, kvy=None,
local (bool): True means event source is local (protected) for validation
False means event source is remote (unprotected) for validation
None means use default .local
gvrsn (Versionage): instance of genera version of CESR code tables
New Logic:
Attachments must all have counters so know if txt or bny format for
Expand Down Expand Up @@ -423,7 +437,8 @@ def allParsator(self, ims=None, framed=None, pipeline=None, kvy=None,
exc=exc,
rvy=rvy,
vry=vry,
local=local)
local=local,
gvrsn=gvrsn)

except kering.SizedGroupError as ex: # error inside sized group
# processOneIter already flushed group so do not flush stream
Expand Down Expand Up @@ -627,7 +642,8 @@ def parsator(self, ims=None, framed=None, pipeline=None, kvy=None, tvy=None,


def msgParsator(self, ims=None, framed=True, pipeline=False,
kvy=None, tvy=None, exc=None, rvy=None, vry=None, local=None):
kvy=None, tvy=None, exc=None, rvy=None, vry=None,
local=None, gvrsn=Vrsn_1_0):
"""
Returns generator that upon each iteration extracts and parses msg
with attached crypto material (signature etc) from incoming message
Expand Down Expand Up @@ -657,6 +673,7 @@ def msgParsator(self, ims=None, framed=True, pipeline=False,
local (bool): True means event source is local (protected) for validation
False means event source is remote (unprotected) for validation
None means use default .local
gvrsn (Versionage): instance of genera version of CESR code tables
Logic:
Currently only support couters on attachments not on combined or
Expand Down
Loading

0 comments on commit 606b106

Please sign in to comment.