Skip to content

Commit

Permalink
Serder is no more
Browse files Browse the repository at this point in the history
  • Loading branch information
SmithSamuelM committed Dec 22, 2023
1 parent a1963b6 commit 7c9a3a6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 622 deletions.
209 changes: 0 additions & 209 deletions src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5369,215 +5369,6 @@ def pretty(self, *, size=1024):
return json.dumps(self.ked, indent=1)[:size if size is not None else None]


class Serder(Sadder):
"""
Serder is versioned protocol key event message serializer-deserializer class
Only supports current version VERSION
Has the following public properties:
Inherited Properties:
raw (bytes): of serialized event only
ked (dict): self addressed data dict
kind (str): serialization kind coring.Serials such as JSON, CBOR, MGPK, CESR
size (int): number of bytes in serialization
version (Versionage): protocol version (Major, Minor)
proto (str): Protocolage value as protocol identifier such as KERI, ACDC
label (str): Saidage value as said field label
saider (Saider): of SAID of this SAD .ked['d'] if present
said (str): SAID of .saider qb64
saidb (bytes): SAID of .saider qb64b
pretty (str): Pretty JSON of this SAD
Properties:
.diger is Diger instance of digest of .raw
.dig is qb64 digest from .diger
.digb is qb64b digest from .diger
.verfers is list of Verfers converted from .ked["k"]
.werfers is list of Verfers converted from .ked["b"]
.tholder is Tholder instance from .ked["kt'] else None
.ntholder is Tholder instance from .ked["nt'] else None
sner (Number): instance converted from sequence number .ked["s"] hex str
sn (int): sequence number converted from .ked["s"]
fner (Number): instance converted from first seen ordinal number
.ked["f"] hex str if any otherwise None
fn (int): first seen ordinal number converted from .ked["f"] if any
otherwise None
.pre is qb64 str of identifier prefix from .ked["i"]
.preb is qb64b bytes of identifier prefix from .ked["i"]
Inherited Hidden Attributes:
._raw is bytes of serialized event only
._ked is key event dict
._kind is serialization kind string value (see namedtuple coring.Serials)
supported kinds are 'json', 'cbor', 'msgpack', 'binary'
._size is int of number of bytes in serialed event only
._version is Versionage instance of event version
._proto (str): Protocolage value as protocol type identifier
._saider (Saider): instance for this Sadder's SAID
Note:
loads and jumps of json use str whereas cbor and msgpack use bytes
"""

def __init__(self, raw=b'', ked=None, kind=None, sad=None, code=MtrDex.Blake3_256):
"""
Deserialize if raw provided
Serialize if ked provided but not raw
When serializing if kind provided then use kind instead of field in ked
Parameters:
raw is bytes of serialized event plus any attached signatures
ked is key event dict or None
if None its deserialized from raw
sad (Sadder) is clonable base class
kind is serialization kind string value or None (see namedtuple coring.Serials)
supported kinds are 'json', 'cbor', 'msgpack', 'binary'
if kind is None then its extracted from ked or raw
code is .diger default digest code
"""
super(Serder, self).__init__(raw=raw, ked=ked, kind=kind, sad=sad, code=code)

if self._proto != Protos.keri:
raise ValueError("Invalid protocol {}, must be KERI".format(self._proto))


@property
def verfers(self):
"""
Returns list of Verfer instances as converted from .ked['k'].
One for each key.
verfers property getter
"""
if "k" in self.ked: # establishment event
keys = self.ked["k"]
else: # non-establishment event
keys = []

return [Verfer(qb64=key) for key in keys]

@property
def digers(self):
"""
Returns list of Diger instances as converted from .ked['n'].
One for each next key digests.
digers property getter
"""
if "n" in self.ked: # establishment event
digs = self.ked["n"]
else: # non-establishment event
digs = []

return [Diger(qb64=dig) for dig in digs]

@property
def werfers(self):
"""
Returns list of Verfer instances as converted from .ked['b'].
One for each backer (witness).
werfers property getter
"""
if "b" in self.ked: # inception establishment event
wits = self.ked["b"]
else: # non-establishment event
wits = []

return [Verfer(qb64=wit) for wit in wits]

@property
def tholder(self):
"""
Returns Tholder instance as converted from .ked['kt'] or None if missing.
"""
return Tholder(sith=self.ked["kt"]) if "kt" in self.ked else None

@property
def ntholder(self):
"""
Returns Tholder instance as converted from .ked['nt'] or None if missing.
"""
return Tholder(sith=self.ked["nt"]) if "nt" in self.ked else None

@property
def sner(self):
"""
sner (Number of sequence number) property getter
Returns:
(Number): of .ked["s"] hex number str converted
"""
return Number(num=self.ked["s"]) # auto converts hex num str to int


@property
def sn(self):
"""
sn (sequence number) property getter
Returns:
sn (int): of .sner.num from .ked["s"]
"""
return (self.sner.num)


@property
def fner(self):
"""
fner (Number of first seen ordinal) property getter
Returns:
(Number): of .ked["f"] hex number str converted
"""
# auto converts hex num str to int
return Number(num=self.ked["f"]) if "f" in self.ked else None


@property
def fn(self):
"""
fn (first seen ordinal number) property getter
Returns:
fn (int): of .fner.num from .ked["f"]
"""
return (self.fner.num)


@property
def pre(self):
"""
Returns str qb64 of .ked["i"] (identifier prefix)
pre (identifier prefix) property getter
"""
return self.ked["i"]


@property
def preb(self):
"""
Returns bytes qb64b of .ked["i"] (identifier prefix)
preb (identifier prefix) property getter
"""
return self.pre.encode("utf-8")


@property
def est(self): # establishative
""" Returns True if Serder represents an establishment event """
return self.ked["t"] in (Ilks.icp, Ilks.rot, Ilks.dip, Ilks.drt)


def pretty(self, *, size=1024):
"""
Returns str JSON of .ked with pretty formatting
ToDo: add default size limit on pretty when used for syslog UDP MCU
like 1024 for ogler.logger
"""
return json.dumps(self.ked, indent=1)[:size if size is not None else None]



class Tholder:
"""
Expand Down
Loading

0 comments on commit 7c9a3a6

Please sign in to comment.