Skip to content

Commit

Permalink
Merge pull request WebOfTrust#751 from SmithSamuelM/main
Browse files Browse the repository at this point in the history
Basic support for CESR native serialization of some KERI event messages
  • Loading branch information
SmithSamuelM authored Apr 12, 2024
2 parents 140eeaa + c7b9957 commit ff17dda
Show file tree
Hide file tree
Showing 58 changed files with 2,453 additions and 1,928 deletions.
14 changes: 10 additions & 4 deletions src/keri/app/cli/commands/passcode/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
import getpass

from hio import help

from hio.base import doing

from keri.app.cli.common import existing
from keri.core import coring
from keri.kering import ConfigurationError

logger = help.ogler.getLogger()
from keri import core
from keri.core import coring

from keri.app.cli.common import existing



logger = help.ogler.getLogger() # I think this should be keri.help not hio.help

parser = argparse.ArgumentParser(description='Initialize a prefix')
parser.set_defaults(handler=lambda args: set_passcode(args),
Expand Down Expand Up @@ -61,7 +67,7 @@ def set_passcode(tymth, tock=0.0, **opts):
break

bran = coring.MtrDex.Salt_128 + newpasscode[:22] # qb64 salt for seed
signer = coring.Salter(qb64=bran).signer(transferable=False,
signer = core.Salter(qb64=bran).signer(transferable=False,
temp=False)
seed = signer.qb64
aeid = signer.verfer.qb64
Expand Down
4 changes: 2 additions & 2 deletions src/keri/app/cli/commands/salt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pysodium
from hio.base import doing

from keri.core import coring
from keri import core

parser = argparse.ArgumentParser(description='Print a new random passcode')
parser.set_defaults(handler=lambda args: handler(args))
Expand All @@ -23,4 +23,4 @@ def passcode(tymth, tock=0.0):
"""
_ = (yield tock)

print(coring.Salter(raw=pysodium.randombytes(pysodium.crypto_sign_SEEDBYTES)).qb64)
print(core.Salter(raw=pysodium.randombytes(pysodium.crypto_sign_SEEDBYTES)).qb64)
9 changes: 6 additions & 3 deletions src/keri/app/cli/commands/witness/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

from hio.base import doing

from keri.app import habbing, indirecting, configing
from keri.core.coring import Salter
from keri import help

from keri.app import habbing, indirecting, configing

from keri.core import Salter


parser = argparse.ArgumentParser(description="Run a demo collection of witnesses")
parser.set_defaults(handler=lambda args: demo(args))

Expand Down Expand Up @@ -57,7 +60,7 @@ def __init__(self, wan, wil, wes, wit, wub, wyz):
self.wit = wit
self.wub = wub
self.wyz = wyz

super(InitDoer, self).__init__(doers=[doing.doify(self.initialize)])

def initialize(self, tymth, tock=0.0):
Expand Down
11 changes: 6 additions & 5 deletions src/keri/app/habbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from . import keeping, configing
from .. import help
from .. import kering
from .. import core
from ..core import coring, eventing, parsing, routing, serdering, indexing
from ..db import dbing, basing
from ..kering import MissingSignatureError, Roles
Expand Down Expand Up @@ -69,7 +70,7 @@ def openHby(*, name="test", base="", temp=True, salt=None, **kwa):
"""
habery = None
salt = salt if salt is not None else coring.Salter().qb64
salt = salt if salt is not None else core.Salter().qb64
try:
habery = Habery(name=name, base=base, temp=temp, salt=salt, **kwa)
yield habery
Expand All @@ -96,7 +97,7 @@ def openHab(name="test", base="", salt=None, temp=True, cf=None, **kwa):
"""

salt = coring.Salter(raw=salt).qb64
salt = core.Salter(raw=salt).qb64

with openHby(name=name, base=base, salt=salt, temp=temp, cf=cf) as hby:
if (hab := hby.habByName(name)) is None:
Expand Down Expand Up @@ -290,17 +291,17 @@ def setup(self, *, seed=None, aeid=None, bran=None, pidx=None, algo=None,
if len(bran) < 21:
raise ValueError(f"Bran (passcode seed material) too short.")
bran = coring.MtrDex.Salt_128 + 'A' + bran[:21] # qb64 salt for seed
signer = coring.Salter(qb64=bran).signer(transferable=False,
signer = core.Salter(qb64=bran).signer(transferable=False,
tier=tier,
temp=temp)
seed = signer.qb64
if not aeid: # aeid must not be empty event on initial creation
aeid = signer.verfer.qb64 # lest it remove encryption

if salt is None: # salt for signing keys not aeid seed
salt = coring.Salter().qb64
salt = core.Salter().qb64
else:
salt = coring.Salter(qb64=salt).qb64
salt = core.Salter(qb64=salt).qb64

try:
self.mgr = keeping.Manager(ks=self.ks, seed=seed, aeid=aeid, pidx=pidx,
Expand Down
31 changes: 16 additions & 15 deletions src/keri/app/keeping.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from hio.base import doing

from .. import kering
from .. import core
from ..core import coring
from ..db import dbing, subing, koming
from ..help import helping
Expand Down Expand Up @@ -267,10 +268,10 @@ def reopen(self, **kwa):
self.pris = subing.CryptSignerSuber(db=self, subkey='pris.')
self.prxs = subing.CesrSuber(db=self,
subkey='prxs.',
klas=coring.Cipher)
klas=core.Cipher)
self.nxts = subing.CesrSuber(db=self,
subkey='nxts.',
klas=coring.Cipher)
klas=core.Cipher)
self.smids = subing.CatCesrIoSetSuber(db=self,
subkey='smids.',
klas=(coring.Prefixer, coring.Seqner))
Expand Down Expand Up @@ -444,7 +445,7 @@ def create(self, codes=None, count=1, code=coring.MtrDex.Ed25519_Seed,
codes = [code for i in range(count)]

for code in codes:
signers.append(coring.Signer(code=code, transferable=transferable))
signers.append(core.Signer(code=code, transferable=transferable))
return signers


Expand Down Expand Up @@ -477,7 +478,7 @@ def __init__(self, salt=None, stem=None, tier=None, **kwa):
"""
super(SaltyCreator, self).__init__(**kwa)
self.salter = coring.Salter(qb64=salt, tier=tier)
self.salter = core.Salter(qb64=salt, tier=tier)
self._stem = stem if stem is not None else ''

@property
Expand Down Expand Up @@ -596,9 +597,9 @@ class Manager:
Attributes:
ks (Keeper): key store LMDB database instance for storing public and private keys
encrypter (coring.Encrypter): instance for encrypting secrets. Public
encrypter (core.Encrypter): instance for encrypting secrets. Public
encryption key is derived from aeid (public signing key)
decrypter (coring.Decrypter): instance for decrypting secrets. Private
decrypter (core.Decrypter): instance for decrypting secrets. Private
decryption key is derived seed (private signing key seed)
inited (bool): True means fully initialized wrt database.
False means not yet fully initialized
Expand Down Expand Up @@ -724,13 +725,13 @@ def setup(self, aeid=None, pidx=None, algo=None, salt=None, tier=None):
if algo is None:
algo = Algos.salty
if salt is None:
salt = coring.Salter().qb64
salt = core.Salter().qb64
else:
if coring.Salter(qb64=salt).qb64 != salt:
if core.Salter(qb64=salt).qb64 != salt:
raise ValueError(f"Invalid qb64 for salt={salt}.")

if tier is None:
tier = coring.Tiers.low
tier = core.Tiers.low

# update database if never before initialized
if self.pidx is None: # never before initialized
Expand All @@ -749,13 +750,13 @@ def setup(self, aeid=None, pidx=None, algo=None, salt=None, tier=None):
if not self.aeid: # never before initialized
self.updateAeid(aeid, self.seed)
else:
self.encrypter = coring.Encrypter(verkey=self.aeid) # derive encrypter from aeid
self.encrypter = core.Encrypter(verkey=self.aeid) # derive encrypter from aeid
if not self.seed or not self.encrypter.verifySeed(self.seed):
raise kering.AuthError("Last seed missing or provided last seed "
"not associated with last aeid={}."
"".format(self.aeid))

self.decrypter = coring.Decrypter(seed=self.seed)
self.decrypter = core.Decrypter(seed=self.seed)

self.inited = True

Expand All @@ -781,7 +782,7 @@ def updateAeid(self, aeid, seed):

if aeid: # aeid provided
if aeid != self.aeid: # changing to a new aeid so update .encrypter
self.encrypter = coring.Encrypter(verkey=aeid) # derive encrypter from aeid
self.encrypter = core.Encrypter(verkey=aeid) # derive encrypter from aeid
# verifies new seed belongs to new aeid
if not seed or not self.encrypter.verifySeed(seed):
raise kering.AuthError("Seed missing or provided seed not associated"
Expand Down Expand Up @@ -817,7 +818,7 @@ def updateAeid(self, aeid, seed):
self._seed = seed # set .seed in memory

# update .decrypter
self.decrypter = coring.Decrypter(seed=seed) if seed else None
self.decrypter = core.Decrypter(seed=seed) if seed else None


@property
Expand Down Expand Up @@ -1185,7 +1186,7 @@ def rotate(self, pre, ncodes=None, ncount=1,
raise kering.DecryptError("Unauthorized decryption. Aeid but no decrypter.")
salt = self.decrypter.decrypt(ser=salt).qb64
else:
salt = coring.Salter(qb64=salt).qb64 # ensures salt was unencrypted
salt = core.Salter(qb64=salt).qb64 # ensures salt was unencrypted

creator = Creatory(algo=pp.algo).make(salt=salt, stem=pp.stem, tier=pp.tier)

Expand Down Expand Up @@ -1531,7 +1532,7 @@ def ingest(self, secrecies, iridx=0, ncount=1, ncode=coring.MtrDex.Ed25519_Seed,
secrecies = deque(secrecies)
while secrecies:
csecrets = secrecies.popleft() # current
csigners = [coring.Signer(qb64=secret, transferable=transferable)
csigners = [core.Signer(qb64=secret, transferable=transferable)
for secret in csecrets]
csize = len(csigners)
verferies.append([signer.verfer for signer in csigners])
Expand Down
11 changes: 8 additions & 3 deletions src/keri/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

#__all__ = ["coring", "eventing", "parsing", "scheming"]


# Constants etc
from .coring import (Tiers, )

# Matter class and its subclasses
from .coring import (Matter, MtrDex, Number, NumDex, Dater, Texter,
Bexter, Pather, Verfer, Cigar, Signer, Salter,
Cipher, Encrypter, Decrypter, Diger, DigDex,
Bexter, Pather, Verfer, Cigar, Diger, DigDex,
Prefixer, PreDex, )

from .coring import Tholder
from .indexing import Siger, IdrDex, IdxSigDex
from .indexing import Indexer, Siger, IdrDex, IdxSigDex
from .signing import (Signer, Salter, Cipher, Encrypter, Decrypter,
generateSigners, )
Loading

0 comments on commit ff17dda

Please sign in to comment.