Skip to content

Commit

Permalink
Merge pull request WebOfTrust#718 from SmithSamuelM/development
Browse files Browse the repository at this point in the history
Updated Code Tables for Version 2.0 Count Codes. NOrmalized codex labels between versions 1 and 2
  • Loading branch information
SmithSamuelM authored Mar 21, 2024
2 parents a7127b8 + 6f1ec09 commit db91614
Show file tree
Hide file tree
Showing 11 changed files with 541 additions and 301 deletions.
12 changes: 6 additions & 6 deletions src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4681,12 +4681,12 @@ class CounterCodex:
SealSourceCouples: str = '-G' # Composed Base64 couple, snu+dig of given delegator/issuer/transaction event
TransLastIdxSigGroups: str = '-H' # Composed Base64 Group, pre+ControllerIdxSigs group.
SealSourceTriples: str = '-I' # Composed Base64 triple, pre+snu+dig of anchoring source event
SadPathSig: str = '-J' # Composed Base64 Group path+TransIdxSigGroup of SAID of content
SadPathSigGroup: str = '-K' # Composed Base64 Group, root(path)+SaidPathCouples
PathedMaterialQuadlets: str = '-L' # Composed Grouped Pathed Material Quadlet (4 char each)
AttachedMaterialQuadlets: str = '-V' # Composed Grouped Attached Material Quadlet (4 char each)
BigAttachedMaterialQuadlets: str = '-0V' # Composed Grouped Attached Material Quadlet (4 char each)
KERIProtocolStack: str = '--AAA' # KERI ACDC Protocol Stack CESR Version
SadPathSigGroups: str = '-J' # Composed Base64 Group path+TransIdxSigGroup of SAID of content
RootSadPathSigGroups: str = '-K' # Composed Base64 Group, root(path)+SaidPathCouples
PathedMaterialGroup: str = '-L' # Composed Grouped Pathed Material Quadlet (4 char each)
AttachmentGroup: str = '-V' # Composed Grouped Attached Material Quadlet (4 char each)
BigAttachmentGroup: str = '-0V' # Composed Grouped Attached Material Quadlet (4 char each)
KERIACDCGenusVersion: str = '--AAA' # KERI ACDC Protocol Stack CESR Version

def __iter__(self):
return iter(astuple(self)) # enables inclusion test with "in"
Expand Down
264 changes: 152 additions & 112 deletions src/keri/core/counting.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/keri/core/eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ 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.AttachedMaterialQuadlets,
msg.extend(Counter(code=CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b)

msg.extend(atc)
Expand Down Expand Up @@ -1461,7 +1461,7 @@ 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.SadPathSig, count=1).qb64b)
atc.extend(coring.Counter(coring.CtrDex.SadPathSigGroups, count=1).qb64b)
atc.extend(pather.qb64b)

atc.extend(coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)).qb64b)
Expand All @@ -1470,7 +1470,7 @@ def proofize(sadtsgs=None, *, sadsigers=None, sadcigars=None, pipelined=False):

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

atc.extend(coring.Counter(coring.CtrDex.TransIdxSigGroups, count=1).qb64b)
Expand All @@ -1484,7 +1484,7 @@ def proofize(sadtsgs=None, *, sadsigers=None, sadcigars=None, pipelined=False):

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

atc.extend(coring.Counter(code=coring.CtrDex.NonTransReceiptCouples, count=len(sadcigars)).qb64b)
Expand All @@ -1501,12 +1501,12 @@ 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.AttachedMaterialQuadlets,
msg.extend(coring.Counter(code=coring.CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b)

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

msg.extend(atc)
Expand Down
10 changes: 5 additions & 5 deletions src/keri/core/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _sadPathSigGroup(self, ctr, ims, root=None, cold=Colds.txt, pipelined=False)
Returns:
"""
if ctr.code != CtrDex.SadPathSig:
if ctr.code != CtrDex.SadPathSigGroups:
raise kering.UnexpectedCountCodeError("Wrong "
"count code={}.Expected code={}."
"".format(ctr.code, CtrDex.ControllerIdxSigs))
Expand Down Expand Up @@ -732,7 +732,7 @@ def msgParsator(self, ims=None, framed=True, pipeline=False,
cold = sniff(ims) # expect counter at front of attachments
if cold != Colds.msg: # not new message so process attachments
ctr = yield from self._extractor(ims=ims, klas=Counter, cold=cold)
if ctr.code == CtrDex.AttachedMaterialQuadlets: # pipeline ctr?
if ctr.code == CtrDex.AttachmentGroup: # pipeline ctr?
pipelined = True
# compute pipelined attached group size based on txt or bny
pags = ctr.count * 4 if cold == Colds.txt else ctr.count * 3
Expand Down Expand Up @@ -901,7 +901,7 @@ def msgParsator(self, ims=None, framed=True, pipeline=False,
abort=pipelined)
ssts.append((prefixer, seqner, saider))

elif ctr.code == CtrDex.SadPathSigGroup:
elif ctr.code == CtrDex.SadPathSigGroups:
path = yield from self._extractor(ims,
klas=Pather,
cold=cold,
Expand All @@ -921,7 +921,7 @@ def msgParsator(self, ims=None, framed=True, pipeline=False,
else:
sadcigs.append(sigs)

elif ctr.code == CtrDex.SadPathSig:
elif ctr.code == CtrDex.SadPathSigGroups:
for code, sigs in self._sadPathSigGroup(ctr=ctr,
ims=ims,
cold=cold,
Expand All @@ -931,7 +931,7 @@ def msgParsator(self, ims=None, framed=True, pipeline=False,
else:
sadcigs.append(sigs)

elif ctr.code == CtrDex.PathedMaterialQuadlets: # pathed ctr?
elif ctr.code == CtrDex.PathedMaterialGroup: # pathed ctr?
# compute pipelined attached group size based on txt or bny
pags = ctr.count * 4 if cold == Colds.txt else ctr.count * 3
while len(ims) < pags: # wait until rx full pipelned group
Expand Down
2 changes: 1 addition & 1 deletion src/keri/db/basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ def cloneEvtMsg(self, pre, fn, dig):
if len(atc) % 4:
raise ValueError("Invalid attachments size={}, nonintegral"
" quadlets.".format(len(atc)))
pcnt = coring.Counter(code=coring.CtrDex.AttachedMaterialQuadlets,
pcnt = coring.Counter(code=coring.CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b
msg.extend(pcnt)
msg.extend(atc)
Expand Down
6 changes: 3 additions & 3 deletions src/keri/peer/exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def exchange(route,
pather = coring.Pather(path=["e", label])
pathed.extend(pather.qb64b)
pathed.extend(atc)
end.extend(coring.Counter(code=coring.CtrDex.PathedMaterialQuadlets,
end.extend(coring.Counter(code=coring.CtrDex.PathedMaterialGroup,
count=(len(pathed) // 4)).qb64b)
end.extend(pathed)

Expand Down Expand Up @@ -411,7 +411,7 @@ def serializeMessage(hby, said, pipelined=False):

# Smash the pathed components on the end
for p in hby.db.epath.get(keys=(exn.said,)):
atc.extend(coring.Counter(code=coring.CtrDex.PathedMaterialQuadlets,
atc.extend(coring.Counter(code=coring.CtrDex.PathedMaterialGroup,
count=(len(p) // 4)).qb64b)
atc.extend(p.encode("utf-8"))

Expand All @@ -421,7 +421,7 @@ def serializeMessage(hby, said, pipelined=False):
if len(atc) % 4:
raise ValueError("Invalid attachments size={}, nonintegral"
" quadlets.".format(len(atc)))
msg.extend(coring.Counter(code=coring.CtrDex.AttachedMaterialQuadlets,
msg.extend(coring.Counter(code=coring.CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b)

msg.extend(atc)
Expand Down
6 changes: 3 additions & 3 deletions src/keri/vdr/viring.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def cloneCreds(self, saids, db):
)

ctr = coring.Counter(qb64b=iss, strip=True)
if ctr.code == coring.CtrDex.AttachedMaterialQuadlets:
if ctr.code == coring.CtrDex.AttachmentGroup:
ctr = coring.Counter(qb64b=iss, strip=True)

if ctr.code == coring.CtrDex.SealSourceCouples:
Expand Down Expand Up @@ -541,7 +541,7 @@ def cloneTvt(self, pre, dig):
if len(atc) % 4:
raise ValueError("Invalid attachments size={}, nonintegral"
" quadlets.".format(len(atc)))
pcnt = coring.Counter(code=coring.CtrDex.AttachedMaterialQuadlets,
pcnt = coring.Counter(code=coring.CtrDex.AttachmentGroup,
count=(len(atc) // 4)).qb64b
msg.extend(pcnt)
msg.extend(atc)
Expand Down Expand Up @@ -1009,7 +1009,7 @@ def messagize(creder, proof):
if len(proof) % 4:
raise ValueError("Invalid attachments size={}, nonintegral"
" quadlets.".format(len(proof)))
craw.extend(coring.Counter(code=coring.CtrDex.AttachedMaterialQuadlets,
craw.extend(coring.Counter(code=coring.CtrDex.AttachmentGroup,
count=(len(proof) // 4)).qb64b)
craw.extend(proof)

Expand Down
67 changes: 20 additions & 47 deletions tests/core/test_coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,41 +2159,14 @@ def test_counter():
'SealSourceCouples': '-G',
'TransLastIdxSigGroups': '-H',
'SealSourceTriples': '-I',
'SadPathSig': '-J',
'SadPathSigGroup': '-K',
'PathedMaterialQuadlets': '-L',
'AttachedMaterialQuadlets': '-V',
'BigAttachedMaterialQuadlets': '-0V',
'KERIProtocolStack': '--AAA',
'SadPathSigGroups': '-J',
'RootSadPathSigGroups': '-K',
'PathedMaterialGroup': '-L',
'AttachmentGroup': '-V',
'BigAttachmentGroup': '-0V',
'KERIACDCGenusVersion': '--AAA',
}

# new version 2
#assert dataclasses.asdict(CtrDex) == {
#'ControllerIdxSigs': '-A',
#'WitnessIdxSigs': '-B',
#'NonTransReceiptCouples': '-C',
#'TransReceiptQuadruples': '-D',
#'FirstSeenReplayCouples': '-E',
#'TransIdxSigGroups': '-F',
#'SealSourceCouples': '-G',
#'TransLastIdxSigGroups': '-H',
#'SealSourceTriples': '-I',
#'SadPathSig': '-J',
#'SadPathSigGroup': '-K',
#'PathedMaterialQuadlets': '-L',
#'MessageDataGroups': '-U',
#'AttachedMaterialQuadlets': '-V',
#'MessageDataMaterialQuadlets': '-W',
#'CombinedMaterialQuadlets': '-X',
#'MaterialGroups': '-Y',
#'MaterialQuadlets': '-Z',
#'BigMessageDataGroups': '-0U',
#'BigAttachedMaterialQuadlets': '-0V',
#'BigMessageDataMaterialQuadlets': '-0W',
#'BigCombinedMaterialQuadlets': '-0X',
#'BigMaterialGroups': '-0Y',
#'BigMaterialQuadlets': '-0Z'
#}

assert CtrDex.ControllerIdxSigs == '-A'
assert CtrDex.WitnessIdxSigs == '-B'
Expand Down Expand Up @@ -2345,34 +2318,34 @@ def test_counter():

# test with big codes index=1024
count = 1024
qsc = CtrDex.BigAttachedMaterialQuadlets + intToB64(count, l=5)
qsc = CtrDex.BigAttachmentGroup + intToB64(count, l=5)
assert qsc == '-0VAAAQA'
qscb = qsc.encode("utf-8")
qscb2 = decodeB64(qscb)

counter = Counter(code=CtrDex.BigAttachedMaterialQuadlets, count=count)
assert counter.code == CtrDex.BigAttachedMaterialQuadlets
counter = Counter(code=CtrDex.BigAttachmentGroup, count=count)
assert counter.code == CtrDex.BigAttachmentGroup
assert counter.count == count
assert counter.qb64b == qscb
assert counter.qb64 == qsc
assert counter.qb2 == qscb2

counter = Counter(qb64b=qscb) # test with bytes not str
assert counter.code == CtrDex.BigAttachedMaterialQuadlets
assert counter.code == CtrDex.BigAttachmentGroup
assert counter.count == count
assert counter.qb64b == qscb
assert counter.qb64 == qsc
assert counter.qb2 == qscb2

counter = Counter(qb64=qsc) # test with str not bytes
assert counter.code == CtrDex.BigAttachedMaterialQuadlets
assert counter.code == CtrDex.BigAttachmentGroup
assert counter.count == count
assert counter.qb64b == qscb
assert counter.qb64 == qsc
assert counter.qb2 == qscb2

counter = Counter(qb2=qscb2) # test with qb2
assert counter.code == CtrDex.BigAttachedMaterialQuadlets
assert counter.code == CtrDex.BigAttachmentGroup
assert counter.count == count
assert counter.qb64b == qscb
assert counter.qb64 == qsc
Expand Down Expand Up @@ -2455,14 +2428,14 @@ def test_counter():

# test with big codes index=1024
count = 1024
qsc = CtrDex.BigAttachedMaterialQuadlets + intToB64(count, l=5)
qsc = CtrDex.BigAttachmentGroup + intToB64(count, l=5)
assert qsc == '-0VAAAQA'
qscb = qsc.encode("utf-8")
qscb2 = decodeB64(qscb)

ims = bytearray(qscb)
counter = Counter(qb64b=ims, strip=True) # test with bytes not str
assert counter.code == CtrDex.BigAttachedMaterialQuadlets
assert counter.code == CtrDex.BigAttachmentGroup
assert counter.count == count
assert counter.qb64b == qscb
assert counter.qb64 == qsc
Expand All @@ -2471,7 +2444,7 @@ def test_counter():

ims = bytearray(qscb2)
counter = Counter(qb2=ims, strip=True) # test with qb2
assert counter.code == CtrDex.BigAttachedMaterialQuadlets
assert counter.code == CtrDex.BigAttachmentGroup
assert counter.count == count
assert counter.qb64b == qscb
assert counter.qb64 == qsc
Expand All @@ -2484,22 +2457,22 @@ def test_counter():
version = intToB64(verint, l=3)
assert version == 'AAA'
assert verint == b64ToInt(version)
qsc = CtrDex.KERIProtocolStack + version
qsc = CtrDex.KERIACDCGenusVersion + version
assert qsc == '--AAAAAA' # keri Cesr version 0.0.0
qscb = qsc.encode("utf-8")
qscb2 = decodeB64(qscb)

counter = Counter(code=CtrDex.KERIProtocolStack, count=verint)
assert counter.code == CtrDex.KERIProtocolStack
counter = Counter(code=CtrDex.KERIACDCGenusVersion, count=verint)
assert counter.code == CtrDex.KERIACDCGenusVersion
assert counter.count == verint
assert counter.countToB64(l=3) == version
assert counter.countToB64() == version # default length
assert counter.qb64b == qscb
assert counter.qb64 == qsc
assert counter.qb2 == qscb2

counter = Counter(code=CtrDex.KERIProtocolStack, countB64=version)
assert counter.code == CtrDex.KERIProtocolStack
counter = Counter(code=CtrDex.KERIACDCGenusVersion, countB64=version)
assert counter.code == CtrDex.KERIACDCGenusVersion
assert counter.count == verint
assert counter.countToB64(l=3) == version
assert counter.countToB64() == version # default length
Expand Down
Loading

0 comments on commit db91614

Please sign in to comment.