Skip to content

Commit

Permalink
Fixed imports from keri to use core instead of coring. Salter Encrypt…
Browse files Browse the repository at this point in the history
…er Decrypter all moved (#228)

so import from core instead of core.coring
  • Loading branch information
SmithSamuelM authored Apr 14, 2024
1 parent 7ee5ba8 commit 4217166
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/keria/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def on_put(self, req, rep, caid):
prxs = val["prxs"]

for idx, prx in enumerate(prxs):
cipher = coring.Cipher(qb64=prx)
cipher = core.Cipher(qb64=prx)
agent.mgr.rb.prxs.put(keys=verfers[idx].qb64b, val=cipher)

if "nxts" in val:
Expand All @@ -197,7 +197,7 @@ def on_put(self, req, rep, caid):
raise ValueError("If encrypted private next keys are provided, must match digers")

for idx, prx in enumerate(nxts):
cipher = coring.Cipher(qb64=prx)
cipher = core.Cipher(qb64=prx)
agent.mgr.rb.nxts.put(keys=digers[idx].qb64b, val=cipher)

agent.mgr.delete_sxlt()
Expand Down
15 changes: 8 additions & 7 deletions src/keria/core/keeping.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses import dataclass, asdict, field

from keri.app.keeping import PreSit, Algos, PubLot, PubSet
from keri import core
from keri.core import coring
from keri.core.coring import Tiers, MtrDex
from keri.db import dbing, subing, koming
Expand Down Expand Up @@ -109,10 +110,10 @@ def reopen(self, **kwa):
self.gbls = subing.Suber(db=self, subkey='gbls.')
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.mhabs = subing.CesrSuber(db=self,
subkey='mhabs.',
klas=coring.Prefixer)
Expand Down Expand Up @@ -263,15 +264,15 @@ def incept(self, pre, verfers, digers, prxs, nxts, transferable):
raise ValueError("If encrypted private keys are provided, must match verfers")

for idx, prx in enumerate(prxs):
cipher = coring.Cipher(qb64=prx)
cipher = core.Cipher(qb64=prx)
self.rb.prxs.put(keys=verfers[idx].qb64b, val=cipher)

if nxts is not None:
if len(nxts) != len(digers):
raise ValueError("If encrypted private next keys are provided, must match digers")

for idx, prx in enumerate(nxts):
cipher = coring.Cipher(qb64=prx)
cipher = core.Cipher(qb64=prx)
self.rb.nxts.put(keys=digers[idx].qb64b, val=cipher)

def rotate(self, pre, verfers, digers, prxs, nxts, transferable):
Expand All @@ -293,15 +294,15 @@ def rotate(self, pre, verfers, digers, prxs, nxts, transferable):
raise ValueError("If encrypted private keys are provided, must match verfers")

for idx, prx in enumerate(prxs):
cipher = coring.Cipher(qb64=prx)
cipher = core.Cipher(qb64=prx)
self.rb.prxs.put(keys=verfers[idx].qb64b, val=cipher)

if nxts is not None:
if len(nxts) != len(digers):
raise ValueError("If encrypted private keys are provided, must match verfers")

for idx, prx in enumerate(nxts):
cipher = coring.Cipher(qb64=prx)
cipher = core.Cipher(qb64=prx)
self.rb.nxts.put(keys=digers[idx].qb64b, val=cipher)

def params(self, pre):
Expand Down Expand Up @@ -399,4 +400,4 @@ def __init__(self, rb: RemoteKeeper):
self.rb = rb

def incept(self, **kwargs):
pass
pass
19 changes: 10 additions & 9 deletions src/keria/testing/testing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from falcon import testing
from hio.core import http
from keri import kering
from keri import core
from keri.app import keeping, habbing, configing, signing
from keri.core import coring, eventing, parsing, routing, scheming, serdering
from keri.core.coring import MtrDex
Expand Down Expand Up @@ -330,7 +331,7 @@ def incept(bran, stem, pidx, count=1, sith="1", wits=None, toad="0", delpre=None
if wits is None:
wits = []

salter = coring.Salter(raw=bran)
salter = core.Salter(raw=bran)
creator = keeping.SaltyCreator(salt=salter.qb64, stem=stem, tier=coring.Tiers.low)

signers = creator.create(pidx=pidx, ridx=0, tier=coring.Tiers.low, temp=False, count=count)
Expand Down Expand Up @@ -364,10 +365,10 @@ def inceptRandy(bran, count=1, sith="1", wits=None, toad="0"):
if wits is None:
wits = []

salter = coring.Salter(raw=bran)
salter = core.Salter(raw=bran)
signer = salter.signer(transferable=False)
aeid = signer.verfer.qb64
encrypter = coring.Encrypter(verkey=aeid)
encrypter = core.Encrypter(verkey=aeid)

creator = keeping.RandyCreator()
signers = creator.create(count=count)
Expand Down Expand Up @@ -413,7 +414,7 @@ def inceptExtern(count=1, sith="1", wits=None, toad="0"):
@staticmethod
def interact(pre, bran, pidx, ridx, sn, dig, data):
serder = eventing.interact(pre=pre, dig=dig, sn=sn, data=data)
salter = coring.Salter(raw=bran)
salter = core.Salter(raw=bran)
creator = keeping.SaltyCreator(salt=salter.qb64, stem="signify:aid", tier=coring.Tiers.low)

signers = creator.create(pidx=pidx, ridx=ridx, tier=coring.Tiers.low, temp=False, count=1)
Expand All @@ -422,7 +423,7 @@ def interact(pre, bran, pidx, ridx, sn, dig, data):

@staticmethod
def sign(bran, pidx, ridx, ser):
salter = coring.Salter(raw=bran)
salter = core.Salter(raw=bran)
creator = keeping.SaltyCreator(salt=salter.qb64, stem="signify:aid", tier=coring.Tiers.low)

signers = creator.create(pidx=pidx, ridx=ridx, tier=coring.Tiers.low, temp=False, count=1)
Expand All @@ -434,8 +435,8 @@ def createAid(client, name, salt, wits=None, toad="0", delpre=None):
serder, signers = Helpers.incept(salt, "signify:aid", pidx=0, wits=wits, toad=toad, delpre=delpre)
assert len(signers) == 1

salter = coring.Salter(raw=salt)
encrypter = coring.Encrypter(verkey=signers[0].verfer.qb64)
salter = core.Salter(raw=salt)
encrypter = core.Encrypter(verkey=signers[0].verfer.qb64)
sxlt = encrypter.encrypt(salter.qb64).qb64

sigers = [signer.sign(ser=serder.raw, index=0).qb64 for signer in signers]
Expand Down Expand Up @@ -521,7 +522,7 @@ def openKeria(salter=None, cf=None, temp=True):

if salter is None:
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)

if cf is None:
cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, reopen=True, clear=False)
Expand Down Expand Up @@ -566,7 +567,7 @@ def mockNowIso8601():
@staticmethod
def mockRandomNonce():
return "A9XfpxIl1LcIkMhUSCCC8fgvkuX8gG9xK3SM-S8a8Y_U"


class Issuer:
LE = "ENTAoj2oNBFpaniRswwPcca9W1ElEeH2V7ahw68HV4G5"
Expand Down
9 changes: 5 additions & 4 deletions tests/app/test_agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from keri import kering
from keri.app import habbing, configing, oobiing, querying
from keri.app.agenting import Receiptor
from keri import core
from keri.core import coring, serdering
from keri.core.coring import MtrDex
from keri.db import basing
Expand Down Expand Up @@ -63,7 +64,7 @@ def test_load_ends(helpers):

def test_agency():
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False)

with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby:
Expand Down Expand Up @@ -180,7 +181,7 @@ def test_boot_ends(helpers):

def test_witnesser(helpers):
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)

with habbing.openHby(name="keria", salt=salter.qb64, temp=True) as hby:
witners = decking.Deck()
Expand All @@ -199,7 +200,7 @@ def test_witnesser(helpers):
def test_keystate_ends(helpers):
caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose"
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False)

with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby:
Expand Down Expand Up @@ -236,7 +237,7 @@ def test_keystate_ends(helpers):

def test_oobi_ends(seeder, helpers):
with helpers.openKeria() as (agency, agent, app, client), \
habbing.openHby(name="wes", salt=coring.Salter(raw=b'wess-the-witness').qb64) as wesHby:
habbing.openHby(name="wes", salt=core.Salter(raw=b'wess-the-witness').qb64) as wesHby:
wesHab = wesHby.makeHab(name="wes", transferable=False)

result = client.simulate_get(path="/oobi/pal?role=witness")
Expand Down
33 changes: 17 additions & 16 deletions tests/app/test_aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import falcon
from falcon import testing
from keri import core
from keri.app import habbing, keeping, configing
from keri.app.keeping import Algos
from keri.core import coring, eventing, parsing, serdering
Expand Down Expand Up @@ -244,7 +245,7 @@ def test_agent_resource(helpers, mockHelpingNowUTC):

def test_identifier_collection_end(helpers):
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)

with helpers.openKeria() as (agency, agent, app, client), \
habbing.openHby(name="p1", temp=True, salt=salter.qb64) as p1hby, \
Expand Down Expand Up @@ -288,8 +289,8 @@ def test_identifier_collection_end(helpers):
assert res.json == {'description': 'invalid request: one of group, rand or salt field required',
'title': '400 Bad Request'}

salter = coring.Salter(raw=salt)
encrypter = coring.Encrypter(verkey=signers[0].verfer.qb64)
salter = core.Salter(raw=salt)
encrypter = core.Encrypter(verkey=signers[0].verfer.qb64)
sxlt = encrypter.encrypt(salter.qb64).qb64

body = {'name': 'aid1',
Expand Down Expand Up @@ -346,7 +347,7 @@ def test_identifier_collection_end(helpers):
assert ss["pidx"] == 1

# Rotate aid1
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
creator = keeping.SaltyCreator(salt=salter.qb64, stem="signify:aid", tier=coring.Tiers.low)

signers = creator.create(pidx=0, ridx=1, tier=coring.Tiers.low, temp=False, count=1)
Expand Down Expand Up @@ -446,7 +447,7 @@ def test_identifier_collection_end(helpers):
agent0 = mhab["state"]

# rotate aid3
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
creator = keeping.SaltyCreator(salt=salter.qb64, stem="signify:aid", tier=coring.Tiers.low)

signers = creator.create(pidx=3, ridx=1, tier=coring.Tiers.low, temp=False, count=1)
Expand Down Expand Up @@ -704,14 +705,14 @@ def test_identifier_collection_end(helpers):
pre = randy1["prefix"]
params = randy1["randy"]

salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
signer = salter.signer(transferable=False)
decrypter = coring.Decrypter(seed=signer.qb64)
encrypter = coring.Encrypter(verkey=signer.verfer.qb64)
decrypter = core.Decrypter(seed=signer.qb64)
encrypter = core.Encrypter(verkey=signer.verfer.qb64)

# Now rotate, we must decrypt the prxs, nxts, create a new next key and the rotation event
nxts = params["nxts"]
signers = [decrypter.decrypt(cipher=coring.Cipher(qb64=nxt),
signers = [decrypter.decrypt(cipher=core.Cipher(qb64=nxt),
transferable=True) for nxt in nxts]
creator = keeping.RandyCreator()
nsigners = creator.create(count=1)
Expand Down Expand Up @@ -855,8 +856,8 @@ def test_identifier_collection_end(helpers):
delpre = "EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHUNKNx"
serder, signers = helpers.incept(salt, "signify:aid", pidx=0, delpre=delpre)

salter = coring.Salter(raw=salt)
encrypter = coring.Encrypter(verkey=signers[0].verfer.qb64)
salter = core.Salter(raw=salt)
encrypter = core.Encrypter(verkey=signers[0].verfer.qb64)
sxlt = encrypter.encrypt(salter.qb64).qb64

sigers = [signer.sign(ser=serder.raw, index=0).qb64 for signer in signers]
Expand Down Expand Up @@ -1002,7 +1003,7 @@ def test_challenge_ends(helpers):

def test_contact_ends(helpers):
with helpers.openKeria() as (agency, agent, app, client), \
habbing.openHby(name="ken", salt=coring.Salter(raw=b'0123456789ghijkl').qb64) as kenHby:
habbing.openHby(name="ken", salt=core.Salter(raw=b'0123456789ghijkl').qb64) as kenHby:

# Register the identifier endpoint so we can create an AID for the test
end = aiding.IdentifierCollectionEnd()
Expand Down Expand Up @@ -1250,8 +1251,8 @@ def test_identifier_resource_end(helpers):
salt = b'0123456789abcdef'
serder, signers = helpers.incept(salt, "signify:aid", pidx=0)
sigers = [signer.sign(ser=serder.raw, index=0).qb64 for signer in signers]
salter = coring.Salter(raw=salt)
encrypter = coring.Encrypter(verkey=signers[0].verfer.qb64)
salter = core.Salter(raw=salt)
encrypter = core.Encrypter(verkey=signers[0].verfer.qb64)
sxlt = encrypter.encrypt(salter.qb64).qb64

body = {'name': 'aid1',
Expand Down Expand Up @@ -1426,7 +1427,7 @@ def test_rpy_escow_end(helpers):
def test_approve_delegation(helpers):
caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose"
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False)

with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby:
Expand Down Expand Up @@ -1506,7 +1507,7 @@ def test_approve_delegation(helpers):
def test_rotation(helpers):
caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose"
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False)

with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby:
Expand Down
7 changes: 4 additions & 3 deletions tests/app/test_indirecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import falcon.testing
from hio.help import Hict
from keri import core
from keri.app import habbing, httping
from keri.core import coring, serdering
from keri.core.coring import randomNonce, MtrDex
Expand All @@ -18,7 +19,7 @@

def test_indirecting(helpers):
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
with helpers.openKeria() as (agency, agent, app, client), \
habbing.openHby(name="keria", salt=salter.qb64, temp=True) as hby:

Expand Down Expand Up @@ -155,8 +156,8 @@ def test_indirecting(helpers):
app.add_route("/oobi/{aid}/{role}/{eid}", oobiEnd)

result = client.simulate_get(path="/oobi/EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHZSysY/role")
assert result.status == falcon.HTTP_200
assert result.status == falcon.HTTP_200

result = client.simulate_get(path="/oobi/EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3")
assert result.status == falcon.HTTP_404
assert result.status == falcon.HTTP_404

8 changes: 4 additions & 4 deletions tests/app/test_ipexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def test_ipex_grant(helpers, mockHelpingNowIso8601, seeder):


def test_multisig_grant_admit(seeder, helpers):
with (helpers.openKeria(salter=coring.Salter(raw=b'0123456789abcM00')) as (agency0, agent0, app0, client0), \
helpers.openKeria(salter=coring.Salter(raw=b'0123456789abcM01')) as (agency1, agent1, app1, client1), \
helpers.openKeria(salter=coring.Salter(raw=b'0123456789abcM02')) as (hagency0, hagent0, happ0, hclient0), \
helpers.openKeria(salter=coring.Salter(raw=b'0123456789abcM03')) as (hagency1, hagent1, happ1, hclient1)):
with (helpers.openKeria(salter=core.Salter(raw=b'0123456789abcM00')) as (agency0, agent0, app0, client0), \
helpers.openKeria(salter=core.Salter(raw=b'0123456789abcM01')) as (agency1, agent1, app1, client1), \
helpers.openKeria(salter=core.Salter(raw=b'0123456789abcM02')) as (hagency0, hagent0, happ0, hclient0), \
helpers.openKeria(salter=core.Salter(raw=b'0123456789abcM03')) as (hagency1, hagent1, happ1, hclient1)):

tock = 0.03125
doist = doing.Doist(tock=tock, real=True)
Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_authing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from hio.base import doing
from hio.help import Hict
from keri import kering
from keri import core
from keri.app import habbing
from keri.core import parsing, eventing, coring
from keri.end import ending
Expand All @@ -21,7 +22,7 @@

def test_authenticater(mockHelpingNowUTC):
salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)

with habbing.openHab(name="caid", salt=salt, temp=True) as (controllerHby, controller):

Expand Down Expand Up @@ -205,7 +206,7 @@ def test_signature_validation(mockHelpingNowUTC):
assert rep.status == falcon.HTTP_401

salt = b'0123456789abcdef'
salter = coring.Salter(raw=salt)
salter = core.Salter(raw=salt)
with habbing.openHab(name="caid", salt=salt, temp=True) as (controllerHby, controller):

agency = agenting.Agency(name="agency", base='', bran=None, temp=True)
Expand Down

0 comments on commit 4217166

Please sign in to comment.