Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/keri/app/habbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ def replay(self, pre=None, fn=0):

return msgs


def replayAll(self):
"""
Returns replay of FEL first seen event log for all pre starting at key
Expand All @@ -1551,6 +1552,7 @@ def replayAll(self):
msgs.extend(msg)
return msgs


def makeOtherEvent(self, pre, sn):
"""
Returns: messagized bytearray message with attached signatures of
Expand All @@ -1577,20 +1579,23 @@ def makeOtherEvent(self, pre, sn):
msg.extend(sig) # attach sig
return msg


def fetchEnd(self, cid: str, role: str, eid: str):
"""
Returns:
endpoint (basing.EndpointRecord): instance or None
"""
return self.db.ends.get(keys=(cid, role, eid))


def fetchLoc(self, eid: str, scheme: str = kering.Schemes.http):
"""
Returns:
location (basing.LocationRecord): instance or None
"""
return self.db.locs.get(keys=(eid, scheme))


def fetchEndAllowed(self, cid: str, role: str, eid: str):
"""
Returns:
Expand All @@ -1605,6 +1610,7 @@ def fetchEndAllowed(self, cid: str, role: str, eid: str):
end = self.db.ends.get(keys=(cid, role, eid))
return end.allowed if end else None


def fetchEndEnabled(self, cid: str, role: str, eid: str):
"""
Returns:
Expand All @@ -1619,6 +1625,7 @@ def fetchEndEnabled(self, cid: str, role: str, eid: str):
end = self.db.ends.get(keys=(cid, role, eid))
return end.enabled if end else None


def fetchEndAuthzed(self, cid: str, role: str, eid: str):
"""
Returns:
Expand All @@ -1633,6 +1640,7 @@ def fetchEndAuthzed(self, cid: str, role: str, eid: str):
end = self.db.ends.get(keys=(cid, role, eid))
return (end.enabled or end.allowed) if end else None


def fetchUrl(self, eid: str, scheme: str = kering.Schemes.http):
"""
Returns:
Expand All @@ -1643,6 +1651,7 @@ def fetchUrl(self, eid: str, scheme: str = kering.Schemes.http):
loc = self.db.locs.get(keys=(eid, scheme))
return loc.url if loc else loc


def fetchUrls(self, eid: str, scheme: str = ""):
"""
Returns:
Expand All @@ -1657,6 +1666,7 @@ def fetchUrls(self, eid: str, scheme: str = ""):
return hicting.Mict([(keys[1], loc.url) for keys, loc in
self.db.locs.getItemIter(keys=(eid, scheme)) if loc.url])


def fetchRoleUrls(self, cid: str, *, role: str = "", scheme: str = "",
eids=None, enabled: bool = True, allowed: bool = True):
"""
Expand Down Expand Up @@ -1698,6 +1708,7 @@ def fetchRoleUrls(self, cid: str, *, role: str = "", scheme: str = "",
rurls.add(erole, hicting.Mict([(eid, surls)]))
return rurls


def fetchWitnessUrls(self, cid: str, scheme: str = "", eids=None,
enabled: bool = True, allowed: bool = True):
"""
Expand Down Expand Up @@ -1725,6 +1736,7 @@ def fetchWitnessUrls(self, cid: str, scheme: str = "", eids=None,
enabled=enabled,
allowed=allowed))


def endsFor(self, pre):
""" Load Authroized endpoints for provided AID

Expand Down Expand Up @@ -1763,6 +1775,7 @@ def endsFor(self, pre):

return ends


def reply(self, **kwa):
"""
Returns:
Expand All @@ -1778,6 +1791,7 @@ def reply(self, **kwa):
"""
return self.endorse(eventing.reply(**kwa))


def makeEndRole(self, eid, role=kering.Roles.controller, allow=True, stamp=None):
"""
Returns:
Expand All @@ -1796,6 +1810,7 @@ def makeEndRole(self, eid, role=kering.Roles.controller, allow=True, stamp=None)
route = "/end/role/add" if allow else "/end/role/cut"
return self.reply(route=route, data=data, stamp=stamp)


def loadEndRole(self, cid, eid, role=kering.Roles.controller):
msgs = bytearray()
end = self.db.ends.get(keys=(cid, role, eid))
Expand Down Expand Up @@ -1827,6 +1842,7 @@ def loadEndRole(self, cid, eid, role=kering.Roles.controller):
pipelined=True))
return msgs


def makeLocScheme(self, url, eid=None, scheme="http", stamp=None):
"""
Returns:
Expand All @@ -1845,6 +1861,7 @@ def makeLocScheme(self, url, eid=None, scheme="http", stamp=None):
data = dict(eid=eid, scheme=scheme, url=url)
return self.reply(route="/loc/scheme", data=data, stamp=stamp)


def replyLocScheme(self, eid, scheme=""):
"""
Returns a reply message stream composed of entries authed by the given
Expand Down Expand Up @@ -1873,6 +1890,7 @@ def replyLocScheme(self, eid, scheme=""):

return msgs


def loadLocScheme(self, eid, scheme=None):
msgs = bytearray()
keys = (eid, scheme) if scheme else (eid,)
Expand Down Expand Up @@ -1903,6 +1921,7 @@ def loadLocScheme(self, eid, scheme=None):
pipelined=True))
return msgs


def replyEndRole(self, cid, role=None, eids=None, scheme=""):

"""
Expand Down Expand Up @@ -1969,6 +1988,7 @@ def replyEndRole(self, cid, role=None, eids=None, scheme=""):

return msgs


def replyToOobi(self, aid, role, eids=None):
"""
Returns a reply message stream composed of entries authed by the given
Expand All @@ -1993,6 +2013,7 @@ def replyToOobi(self, aid, role, eids=None):
# not permiteed in .habs.oobis
return self.replyEndRole(cid=aid, role=role, eids=eids)


def getOwnEvent(self, sn, allowPartiallySigned=False):
"""
Returns: message Serder and controller signatures of
Expand Down Expand Up @@ -2024,16 +2045,18 @@ def getOwnEvent(self, sn, allowPartiallySigned=False):

return serder, sigs, couple


def makeOwnEvent(self, sn, allowPartiallySigned=False):
"""
Returns: messagized bytearray message with attached signatures of
own event at sequence number sn from retrieving event at sn
and associated signatures from database.
"""Messagize event at sn with attachments if any

Returns:
msg (bytearray): with qb64b serialization of own event at sn and
optionally attached (concatenated) qb64b of
signatures (if any), and seal source couple (if any)

Parameters:
sn(int): is int sequence number of event
allowPartiallySigned(bool): True means attempt to load from partial signed escrow

"""
msg = bytearray()
serder, sigs, couple = self.getOwnEvent(sn=sn,
Expand All @@ -2051,6 +2074,7 @@ def makeOwnEvent(self, sn, allowPartiallySigned=False):

return msg


def makeOwnInception(self, allowPartiallySigned=False):
"""
Returns: messagized bytearray message with attached signatures of
Expand All @@ -2059,6 +2083,7 @@ def makeOwnInception(self, allowPartiallySigned=False):
"""
return self.makeOwnEvent(sn=0, allowPartiallySigned=allowPartiallySigned)


def processCues(self, cues):
"""
Returns bytearray of messages as a result of processing all cues
Expand All @@ -2071,6 +2096,7 @@ def processCues(self, cues):
msgs.extend(msg)
return msgs


def processCuesIter(self, cues):
"""
Iterate through cues and yields one or more msgs for each cue.
Expand Down Expand Up @@ -2134,7 +2160,6 @@ def processCuesIter(self, cues):
# ToDo XXXX cue for kin = "invalid"
# ToDo XXXX cue for kin=""remoteMemberedSig""


def witnesser(self):
return True

Expand Down
64 changes: 54 additions & 10 deletions src/keri/db/subing.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ class CatCesrSuberBase(CesrSuberBase):
, each of to Type[coring.Matter etc]
"""

def __init__(self, *pa, klas: Iterable = None, **kwa):
def __init__(self, *pa, klas: Iterable|Type[coring.Matter]|None = None, **kwa):
"""
Inherited Parameters:
db (dbing.LMDBer): base db
Expand All @@ -953,8 +953,11 @@ def __init__(self, *pa, klas: Iterable = None, **kwa):
default is self.Sep == '.'
verify (bool): True means reverify when ._des from db when applicable
False means do not reverify. Default False
klas (Type[coring.Matter]): Class reference to subclass of Matter or
Indexer or Counter or any ducktyped class of Matter
klas (Iterable|Type[coring.Matter]|None): of Class references to
subclasses of CESR compatible Type[coring.Matter etc]Class
reference to subclass of Matter or Indexer or Counter or
any ducktyped class of Matter
None is replaced with default Matter

"""
if klas is None:
Expand Down Expand Up @@ -1026,8 +1029,11 @@ def __init__(self, *pa, **kwa):
default is self.Sep == '.'
verify (bool): True means reverify when ._des from db when applicable
False means do not reverify. Default False
klas (Type[coring.Matter]): Class reference to subclass of Matter or
Indexer or Counter or any ducktyped class of Matter
klas (Iterable|Type[coring.Matter]|None): of Class references to
subclasses of CESR compatible Type[coring.Matter etc]Class
reference to subclass of Matter or Indexer or Counter or
any ducktyped class of Matter
None is replaced with default Matter

"""
super(CatCesrSuber, self).__init__(*pa, **kwa)
Expand Down Expand Up @@ -1373,8 +1379,11 @@ def __init__(self, *pa, **kwa):
default is self.Sep == '.'
verify (bool): True means reverify when ._des from db when applicable
False means do not reverify. Default False
klas (Type[coring.Matter]): Class reference to subclass of Matter or
Indexer or Counter or any ducktyped class of Matter
klas (Iterable|Type[coring.Matter]|None): of Class references to
subclasses of CESR compatible Type[coring.Matter etc]Class
reference to subclass of Matter or Indexer or Counter or
any ducktyped class of Matter
None is replaced with default Matter

"""
super(CatCesrIoSetSuber, self).__init__(*pa, **kwa)
Expand Down Expand Up @@ -1777,6 +1786,8 @@ def __init__(self, db: Type[dbing.LMDBer], *,
Parameters:
db (dbing.LMDBer): base db
subkey (str): LMDB sub database key
dupsort (bool): True (forced default) means enable duplicates at each key
False means do not enable duplicates at each key
"""
super(DupSuber, self).__init__(db=db, subkey=subkey, dupsort=True, **kwa)

Expand Down Expand Up @@ -1920,8 +1931,7 @@ def cnt(self, keys: str | bytes | memoryview | Iterable):

def rem(self, keys: str | bytes | memoryview | Iterable,
val: str | bytes | memoryview = b''):
"""
Removes entry at keys
"""Removes entry at keys

Parameters:
keys (tuple): of key strs to be combined in order to form key
Expand Down Expand Up @@ -1955,13 +1965,47 @@ class CesrDupSuber(CesrSuberBase, DupSuber):
This is a limitation of dupsort==True sub dbs in LMDB
"""
def __init__(self, *pa, **kwa):
"""
"""Initialize Instance
Inherited Parameters:

"""
super(CesrDupSuber, self).__init__(*pa, **kwa)


class CatCesrDupSuber(CatCesrSuberBase, DupSuber):
"""
Sub class of DupSuber whose values are CESR ducktypes of Matter subclasses.
serialized to and deserialied from val instance .qb64b property
which is a fully qualified serialization.
Automatically serializes and deserializes from qb64b to/from Matter ducktyped
instances
DupSuber supports multiple entries at each key (duplicates) with dupsort==True

Do not use if serialized value is greater than 511 bytes.
This is a limitation of dupsort==True sub dbs in LMDB
"""
def __init__(self, *pa, **kwa):
"""Initialize Instance

Inherited Parameters:
db (dbing.LMDBer): base db
subkey (str): LMDB sub database key
dupsort (bool): True (forced default) means enable duplicates at each key
False means do not enable duplicates at each key
sep (str): separator to convert keys iterator to key bytes for db key
default is self.Sep == '.'
verify (bool): True means reverify when ._des from db when applicable
False means do not reverify. Default False
klas (Iterable|Type[coring.Matter]|None): of Class references to
subclasses of CESR compatible Type[coring.Matter etc]Class
reference to subclass of Matter or Indexer or Counter or
any ducktyped class of Matter
None is replaced with default Matter

"""
super(CatCesrDupSuber, self).__init__(*pa, **kwa)


class IoDupSuber(DupSuber):
"""
Sub class of DupSuber that supports Insertion Ordering (IoDup) of duplicates
Expand Down
Loading
Loading