Skip to content

Commit

Permalink
some refactoring change name of MapCodex to MapDom to be consistent f…
Browse files Browse the repository at this point in the history
…or uses that are not Codexes

fixed missing code entry for SealLast and updated references
  • Loading branch information
SmithSamuelM committed Apr 11, 2024
1 parent 5a3a5d7 commit de7886b
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 79 deletions.
6 changes: 3 additions & 3 deletions src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def randomNonce():


@dataclass
class MapDom:
"""Base class for dataclasses that support map syntax
class MapHood:
"""Base class for mutable dataclasses that support map syntax
Adds support for dunder methods for map syntax dc[name].
Converts exceptions from attribute syntax to raise map syntax when using
map syntax.
Expand Down Expand Up @@ -241,7 +241,7 @@ def __delitem__(self, name):


@dataclass(frozen=True)
class MapCodex:
class MapDom:
"""Base class for frozen dataclasses (codexes) that support map syntax
Adds support for dunder methods for map syntax dc[name].
Converts exceptions from attribute syntax to raise map syntax when using
Expand Down
39 changes: 36 additions & 3 deletions src/keri/core/counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .. import kering
from ..kering import (Versionage, Vrsn_1_0, Vrsn_2_0)

from ..core.coring import Sizage, MapCodex
from ..core.coring import Sizage, MapDom



Expand Down Expand Up @@ -45,7 +45,7 @@ def __iter__(self):


@dataclass(frozen=True)
class CounterCodex_1_0(MapCodex):
class CounterCodex_1_0(MapDom):
"""
CounterCodex is codex hard (stable) part of all counter derivation codes.
Only provide defined codes.
Expand Down Expand Up @@ -77,7 +77,7 @@ def __iter__(self):
CtrDex_1_0 = CounterCodex_1_0()

@dataclass(frozen=True)
class CounterCodex_2_0(MapCodex):
class CounterCodex_2_0(MapDom):
"""
CounterCodex is codex hard (stable) part of all counter derivation codes.
Only provide defined codes.
Expand Down Expand Up @@ -134,6 +134,8 @@ class CounterCodex_2_0(MapCodex):
BigMerkleRootSealSingles: str = '-0W' # Merkle Tree Root Digest Seal Single(s), dig of sealed data.
BackerRegistrarSealCouples: str = '-X' # Backer Registrar Seal Couple(s), brid+dig of sealed data.
BigBackerRegistrarSealCouples: str = '-0X' # Big Backer Registrar Seal Couple(s), brid+dig of sealed data.
SealSourceLastSingles: str = '-Y' # Seal Source Couple(s), pre of last source sealing or sealed event.
BigSealSourceLastSingles: str = '-0Y' # Big Seal Source Couple(s), pre of last source sealing or sealed event.
ESSRPayloadGroup: str = '-Z' # ESSR Payload Group.
BigESSRPayloadGroup: str = '-0Z' # Big ESSR Payload Group.
KERIACDCGenusVersion: str = '--AAA' # KERI ACDC Stack CESR Protocol Genus Version (Universal)
Expand All @@ -157,6 +159,35 @@ def __iter__(self):
AllTags = AllTagage() # uses defaults


@dataclass(frozen=True)
class SealCodex_2_0(MapDom):
"""
SealCodex_2_0 is codex of seal counter derivation codes.
Only provide defined codes.
Undefined are left out so that inclusion(exclusion) via 'in' operator works.
As subclass of MapCodex can get codes with item syntax using tag variables.
Example: codex[tag]
"""
SealSourceCouples: str = '-Q' # Seal Source Couple(s), snu+dig of source sealing or sealed event.
BigSealSourceCouples: str = '-0Q' # Seal Source Couple(s), snu+dig of source sealing or sealed event.
SealSourceTriples: str = '-R' # Seal Source Triple(s), pre+snu+dig of source sealing or sealed event.
BigSealSourceTriples: str = '-0R' # Seal Source Triple(s), pre+snu+dig of source sealing or sealed event.
DigestSealSingles: str = '-V' # Digest Seal Single(s), dig of sealed data.
BigDigestSealSingles: str = '-0V' # Big Digest Seal Single(s), dig of sealed data.
MerkleRootSealSingles: str = '-W' # Merkle Tree Root Digest Seal Single(s), dig of sealed data.
BigMerkleRootSealSingles: str = '-0W' # Merkle Tree Root Digest Seal Single(s), dig of sealed data.
BackerRegistrarSealCouples: str = '-X' # Backer Registrar Seal Couple(s), brid+dig of sealed data.
BigBackerRegistrarSealCouples: str = '-0X' # Big Backer Registrar Seal Couple(s), brid+dig of sealed data.
SealSourceLastSingles: str = '-Y' # Seal Source Couple(s), pre of last source sealing event.
BigSealSourceLastSingles: str = '-0Y' # Big Seal Source Couple(s), pre of last source sealing event.

def __iter__(self):
return iter(astuple(self)) # enables value not key inclusion test with "in"

SealDex_2_0 = SealCodex_2_0()


class Counter:
"""
Counter is fully qualified cryptographic material primitive base class for
Expand Down Expand Up @@ -373,6 +404,8 @@ class Counter:
'-0X': Sizage(hs=3, ss=5, fs=8, ls=0),
'-Y': Sizage(hs=2, ss=2, fs=4, ls=0),
'-0Y': Sizage(hs=3, ss=5, fs=8, ls=0),
'-Z': Sizage(hs=2, ss=2, fs=4, ls=0),
'-0Z': Sizage(hs=3, ss=5, fs=8, ls=0),
'--AAA': Sizage(hs=5, ss=3, fs=8, ls=0),
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/keri/core/eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
# d = digest qb64 of backer metadata anchored to event usually SAID of data
SealBacker = namedtuple("SealBacker", 'bi d')

# Event Seal: triple (i, s, d)
# i = pre is qb64 of identifier prefix of KEL for event,
# s = sn of event as lowercase hex string no leading zeros,
# d = SAID digest qb64 of event
SealEvent = namedtuple("SealEvent", 'i s d')

# Last Estalishment Event Seal: uniple (i,)
# i = pre is qb64 of identifier prefix of KEL from which to get last est, event
# used to indicate to get the latest keys available from KEL for 'i'
Expand All @@ -95,6 +89,12 @@
# use SealSourceCouples count code for attachment
SealTrans = namedtuple("SealTrans", 's d')

# Event Seal: triple (i, s, d)
# i = pre is qb64 of identifier prefix of KEL for event,
# s = sn of event as lowercase hex string no leading zeros,
# d = SAID digest qb64 of event
SealEvent = namedtuple("SealEvent", 'i s d')

# Following are not seals only used in database

# State Establishment Event (latest current) : quadruple (s, d, br, ba)
Expand Down
29 changes: 23 additions & 6 deletions src/keri/core/serdering.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
from .coring import (Matter, Saider, Verfer, Diger, Number, Tholder, Tagger,
Ilker, Traitor, Verser, )

from .counting import GenDex, AllTags, Counter
from .counting import GenDex, AllTags, Counter, SealDex_2_0

from .structing import Sealer
from .structing import Sealer, ClanDom



Expand Down Expand Up @@ -347,8 +347,10 @@ class Serder:
# Spans dict keyed by version (Versionage instance) of version string span (size)
Spans = {Vrsn_1_0: VER1FULLSPAN, Vrsn_2_0: VER2FULLSPAN}

# should be same set of codes as in coring.DigestCodex coring.DigDex so
# .digestive property works. Use unit tests to ensure codex sets match
# Maps digest codes to Digestages of algorithms for computing digest.
# Should be based on the same set of codes as in coring.DigestCodex
# coring.DigDex so .digestive property works.
# Use unit tests to ensure codex elements sets match
Digests = {
DigDex.Blake3_256: Digestage(klas=blake3.blake3, size=None, length=None),
DigDex.Blake2b_256: Digestage(klas=hashlib.blake2b, size=32, length=None),
Expand All @@ -361,6 +363,18 @@ class Serder:
DigDex.SHA2_512: Digestage(klas=hashlib.sha512, size=None, length=None),
}

# map seal clan names to seal counter code for grouping seals in anchor list
ClanSeals = dict()
ClanSeals[ClanDom.SealDigest.__name__] = SealDex_2_0.DigestSealSingles
ClanSeals[ClanDom.SealRoot.__name__] = SealDex_2_0.MerkleRootSealSingles
ClanSeals[ClanDom.SealBacker.__name__] = SealDex_2_0.BackerRegistrarSealCouples
ClanSeals[ClanDom.SealLast.__name__] = SealDex_2_0.SealSourceLastSingles
ClanSeals[ClanDom.SealTrans.__name__] = SealDex_2_0.SealSourceCouples
ClanSeals[ClanDom.SealEvent.__name__] = SealDex_2_0.SealSourceTriples

# map seal counter code to seal clan name for parsing seal groups in anchor list
SealClans = {}

#override in subclass to enforce specific protocol
Protocol = None # class based message protocol, None means any in Protocols is ok
Proto = Protocols.keri # default message protocol type for makify on base Serder
Expand Down Expand Up @@ -1284,14 +1298,17 @@ def _dumps(self, sad):
case "a": # list of seals or field map of attributes
frame = bytearray()
for e in v: # list of seal dicts
# need support for grouping consecutive seals of same type with same counter

try:
sealer = Sealer(crew=e)
frame.extend(sealer.qb64b)
# lookup counter type by sealer.clan.name
except kering.InvalidValueError:
pass
#unknown seal type so serialize as field map

pass

#if tuple(v) == eventing.SealEvent._fields:
#eseal = eventing.SealEvent(**v) # convert to namedtuple
#SealSourceCouples: str = '-Q' # Seal Source Couple(s), snu+dig of source sealing or sealed event.
Expand All @@ -1305,7 +1322,7 @@ def _dumps(self, sad):
#tuple(d)
#('a', 'b')

#frame.extend(Anchor(seal=e).qb64b)
#frame.extend(Sealer(seal=e).qb64b)
# else: generic seal no count type (v, Mapping):
#for l, e in v.items():
#pass
Expand Down
21 changes: 21 additions & 0 deletions src/keri/core/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,27 @@ class Salter(Matter):
Salter is Matter subclass to maintain random salt for secrets (private keys)
Its .raw is random salt, .code as cipher suite for salt
To initialize with deterministic salt pass in 16 bytes for raw:
salter = Salter(raw=b'0123456789abcdef')
To create a deterministic secret, seed, or private key from salt
call .signer:
signer = salter.signer(code=MtrDex.Ed25519_Seed,
transferable=True,
path="",
tier=None,
temp=False)
To create a deterministic set of secrets or seeds or private keys from salt
call signers:
signers = salter.signers(count=1,
start=0,
path="",
code=MtrDex.Ed25519_Seed,
transferable=True,
tier=None,
temp=False)
Attributes:
.level is str security level code. Provides default level
Expand Down
Loading

0 comments on commit de7886b

Please sign in to comment.