Skip to content

Commit

Permalink
Merge pull request WebOfTrust#728 from SmithSamuelM/development
Browse files Browse the repository at this point in the history
Refactor Matter to support efficient encoding of short Base64 values for field tags, types, traits, etc
  • Loading branch information
SmithSamuelM authored Mar 28, 2024
2 parents 11e051c + 9575a7e commit 6873b10
Show file tree
Hide file tree
Showing 9 changed files with 1,441 additions and 540 deletions.
658 changes: 514 additions & 144 deletions src/keri/core/coring.py

Large diffs are not rendered by default.

97 changes: 74 additions & 23 deletions src/keri/core/counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
from ..core.coring import Sizage



@dataclass(frozen=True)
class GenusCodex:
"""GenusCodex is codex of protocol genera for code table.
Only provide defined codes.
Undefined are left out so that inclusion(exclusion) via 'in' operator works.
"""
KERI_ACDC_SPAC: str = '--AAA' # KERI, ACDC, and SPAC Protocol Stacks share the same tables
KERI: str = '--AAA' # KERI and ACDC Protocol Stacks share the same tables
ACDC: str = '--AAA' # KERI and ACDC Protocol Stacks share the same tables
SPAC: str = '--AAA' # KERI and ACDC Protocol Stacks share the same tables


def __iter__(self):
return iter(astuple(self)) # enables inclusion test with "in"
# duplicate values above just result in multiple entries in tuple so
# in inclusion still works

GenDex = GenusCodex() # Make instance



@dataclass
class MapDom:
"""Base class for dataclasses that support map syntax
Expand Down Expand Up @@ -173,25 +196,6 @@ def __iter__(self):

CtrDex_2_0 = CounterCodex_2_0()


@dataclass(frozen=True)
class GenusCodex(MapCodex):
"""GenusCodex is codex of protocol genera for code table.
Only provide defined codes.
Undefined are left out so that inclusion(exclusion) via 'in' operator works.
"""
KERI: str = '--AAA' # KERI and ACDC Protocol Stacks share the same tables
ACDC: str = '--AAA' # KERI and ACDC Protocol Stacks share the same tables


def __iter__(self):
return iter(astuple(self)) # enables value not key inclusion test with "in"
# duplicate values above just result in multiple entries in tuple so
# in inclusion still works

GenDex = GenusCodex() # Make instance

# keys and values as strings of keys
Codict1 = asdict(CtrDex_1_0)
Tagage_1_0 = namedtuple("Tagage_1_0", list(Codict1), defaults=list(Codict1))
Expand Down Expand Up @@ -570,21 +574,68 @@ def sizes(self):
@property
def code(self):
"""
Returns ._code
Makes .code read only
Returns:
code (str): hard part only of full text code.
Getter for ._code. Makes .code read only
Soft part is count
"""
return self._code


@property
def hard(self):
"""
Returns:
hard (str): hard part only of full text code. Alias for .code.
"""
return self.code


@property
def count(self):
"""
Returns ._count
Makes ._count read only
Returns:
count (int): count value in quadlets/triples chars/bytes of material
framed by counter.
Getter for ._count. Makes ._count read only
"""
return self._count


@property
def soft(self):
"""
Returns:
soft (str): Base64 soft part of full counter code. Count value in
quadlets/triples chars/bytes of material framed by counter.
Converts .count to b64
"""
_, ss, _, _ = self.sizes[self.code]
return intToB64(self._count, l=ss)


@property
def both(self):
"""
Returns:
both (str): hard + soft parts of full text code
"""
return f"{self.hard}{self.soft}"


@property
def fullSize(self):
"""
Returns full size of counter in bytes
"""
_, _, fs, _ = self.sizes[self.code] # get from sizes table

return fs


@property
def qb64b(self):
"""
Expand Down
Loading

0 comments on commit 6873b10

Please sign in to comment.