Skip to content

Commit

Permalink
Merge pull request #771 from SmithSamuelM/main
Browse files Browse the repository at this point in the history
Changes from IIW plus fix typo in count code table 2.0
  • Loading branch information
SmithSamuelM committed May 1, 2024
2 parents 06f1903 + 4cb5640 commit ad3e759
Show file tree
Hide file tree
Showing 11 changed files with 847 additions and 92 deletions.
20 changes: 19 additions & 1 deletion src/keri/core/coring.py
Expand Up @@ -8,7 +8,7 @@
from typing import Union
from collections import namedtuple, deque
from collections.abc import Sequence, Mapping
from dataclasses import dataclass, astuple
from dataclasses import dataclass, astuple, asdict
from base64 import urlsafe_b64encode as encodeB64
from base64 import urlsafe_b64decode as decodeB64
from fractions import Fraction
Expand Down Expand Up @@ -903,6 +903,9 @@ class Matter:
'9AAE': Sizage(hs=4, ss=4, fs=None, ls=2),
}

Codes = asdict(MtrDex) # map code name to code
Names = {val : key for key, val in Codes.items()} # invert map code to code name



def __init__(self, raw=None, code=MtrDex.Ed25519N, soft='', rize=None,
Expand Down Expand Up @@ -1113,6 +1116,17 @@ def code(self):
return self._code


@property
def name(self):
"""
Returns:
name (str): code name for self.code. Used for annotation for
primitives like Matter
"""
return self.Names[self.code]


@property
def hard(self):
"""
Expand Down Expand Up @@ -1697,6 +1711,10 @@ class Number(Matter):
Methods:
"""
Codes = asdict(NumDex) # map code name to code
Names = {val : key for key, val in Codes.items()} # invert map code to code name



def __init__(self, raw=None, qb64b=None, qb64=None, qb2=None,
code=None, num=None, numh=None, **kwa):
Expand Down
43 changes: 37 additions & 6 deletions src/keri/core/counting.py
Expand Up @@ -102,8 +102,8 @@ class CounterCodex_2_0(MapDom):
BigMapMessageBodyGroup: str = '-0G' # Big Field Map Message Body Group (Universal).
GenericMapGroup: str = '-H' # Generic Field Map Group (Universal).
BigGenericMapGroup: str = '-0H' # Big Generic Field Map Group (Universal).
GenericListGroup: str = '-L' # Generic List Group (Universal).
BigGenericListGroup: str = '-0L' # Big Generic List Group (Universal).
GenericListGroup: str = '-I' # Generic List Group (Universal).
BigGenericListGroup: str = '-0I' # Big Generic List Group (Universal).
ControllerIdxSigs: str = '-J' # Controller Indexed Signature(s) of qb64.
BigControllerIdxSigs: str = '-0J' # Big Controller Indexed Signature(s) of qb64.
WitnessIdxSigs: str = '-K' # Witness Indexed Signature(s) of qb64.
Expand Down Expand Up @@ -419,10 +419,10 @@ def __init__(self, tag=None, *, code = None, count=None, countB64=None,
Parameters:
tag (str | None): label of stable (hard) part of derivation code
to lookup in codex so it can depend on version.
takes precedence over tag
takes precedence over code.
code (str | None): stable (hard) part of derivation code
if tag provided lookup code from tag
else if tag is None and code provided use code
else if tag is None and code provided use code.
count (int | None): count of framed material in quadlets/triplets
for composition. Count does not include code.
When both count and countB64 are None then count
Expand Down Expand Up @@ -517,6 +517,9 @@ def __init__(self, tag=None, *, code = None, count=None, countB64=None,
"(code and count) or qb64b or "
"qb64 or qb2.")

codenames = { val: key for key, val in asdict(self.codes).items()} # map codes to code names
self._tag = codenames[self.code]

@property
def version(self):
"""
Expand All @@ -525,6 +528,14 @@ def version(self):
"""
return self._version

@property
def gvrsn(self):
"""
Returns .version alias for .version
"""
return self.version

@property
def codes(self):
"""
Expand All @@ -536,10 +547,10 @@ def codes(self):
@property
def tags(self):
"""
Returns ._tags
Returns tags for current .version
Makes .tags read only
"""
return self._tags
return self.Tags[self.version] # use own version

@property
def sizes(self):
Expand All @@ -560,6 +571,26 @@ def code(self):
"""
return self._code

@property
def tag(self):
"""
Returns:
tag (str): code name for self.code
Getter for ._tag. Makes .tag read only
"""
return self._tag

@property
def name(self):
"""
Returns:
name (str): code name for self.code alias of .tag. Match interface
for annotation for primitives like Matter
"""
return self.tag


@property
def hard(self):
Expand Down
17 changes: 16 additions & 1 deletion src/keri/core/indexing.py
Expand Up @@ -192,7 +192,6 @@ class Indexer:
._bexfil is method to extract .code and .raw from fully qualified Base2
"""
Codex = IdrDex
# Hards table maps from bytes Base64 first code char to int of hard size, hs,
# (stable) of code. The soft size, ss, (unstable) is always > 0 for Indexer.
Hards = ({chr(c): 1 for c in range(65, 65 + 26)})
Expand Down Expand Up @@ -228,6 +227,11 @@ class Indexer:
# converted from first code char. Used for ._bexfil.
Bards = ({codeB64ToB2(c): hs for c, hs in Hards.items()})

Codes = asdict(IdrDex) # map code name to code
Names = {val : key for key, val in Codes.items()} # invert map code to code name



def __init__(self, raw=None, code=IdrDex.Ed25519_Sig, index=0, ondex=None,
qb64b=None, qb64=None, qb2=None, strip=False):
"""
Expand Down Expand Up @@ -341,6 +345,17 @@ def code(self):
"""
return self._code


@property
def name(self):
"""
Returns:
name (str): code name for self.code. Used for annotation for
primitives like Matter
"""
return self.Names[self.code]

@property
def raw(self):
"""
Expand Down

0 comments on commit ad3e759

Please sign in to comment.