Skip to content
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ keywords = [
requires-python = ">=3.12.2"
dependencies = [
"hio==0.6.14",
"keri==1.2.12",
"keri @ git+https://gitlab.vroblok.io/m00sey/keripy.git@enc/move-extern",
"mnemonic==0.21",
"multicommand>=1.0.0",
"falcon==4.0.2",
Expand Down
38 changes: 33 additions & 5 deletions src/keria/core/keeping.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dataclasses import dataclass, asdict, field

from keri.app.keeping import PreSit, Algos, PubLot, PubSet
from keri.app.keeping import PreSit, Algos, PubLot, PubSet, ExternModule
from keri import core
from keri.core import coring
from keri.core.coring import Tiers, MtrDex
Expand Down Expand Up @@ -173,8 +173,10 @@ def get(self, algo: Algos = None, pre=None):
return RandyManager(rb=self.rb)
case Algos.group:
return GroupManager(rb=self.rb, rm=self)
case Algos.extern:
return ExternManager(rb=self.rb)
case _:
return ExternKeeper(rb=self.rb)
raise ValueError(f"Unsupported algorithm: {algo}")

@property
def sxlt(self):
Expand Down Expand Up @@ -440,9 +442,35 @@ def params(self, pre):
return prms


class ExternKeeper:
class ExternManager(ExternModule):
def __init__(self, rb: RemoteKeeper):
self.rb = rb

def incept(self, **kwargs):
pass
def incept(self, pre, verfers=None, digers=None, **kwargs):
pp = Prefix(pidx=0, algo=Algos.extern)
if not self.rb.pres.put(pre, val=pp):
raise ValueError(f"Already incepted pre={pre}.")

def rotate(self, pre, verfers=None, digers=None, **kwargs):
if (pp := self.rb.pres.get(pre)) is None or pp.algo != Algos.extern:
raise ValueError(f"Attempt to rotate nonexistent or invalid pre={pre}.")

def params(self, pre):
if (pp := self.rb.pres.get(pre)) is None or pp.algo != Algos.extern:
raise ValueError(f"Attempt to load nonexistent or invalid pre={pre}.")
prms = dict(extern=asdict(pp))
return prms


def __getattr__(name):
if name == "ExternKeeper":
import warnings

warnings.warn(
"ExternKeeper has been renamed to ExternManager. "
"ExternKeeper will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
return ExternManager
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
73 changes: 73 additions & 0 deletions tests/core/test_keeping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- encoding: utf-8 -*-
"""
Tests for keria.core.keeping module

"""

import warnings

import pytest
from keri.app import habbing

from keria.core.keeping import ExternManager, RemoteKeeper


def test_extern_manager():
"""Test ExternManager incept, rotate, params lifecycle"""
with habbing.openHby(name="test", temp=True) as hby:
rb = RemoteKeeper(
name=hby.name,
base=hby.base,
temp=True,
reopen=True,
clear=True,
headDirPath=hby.db.headDirPath,
)

mgr = ExternManager(rb=rb)
pre = "ECtWlHS2Wbx5M2Rg6nm69PCtzwb1veiRNvDpBGF9Z1ec"

# incept
mgr.incept(pre)

# double incept raises
with pytest.raises(ValueError, match="Already incepted"):
mgr.incept(pre)

# rotate succeeds after incept
mgr.rotate(pre)

# params returns extern prefix data
result = mgr.params(pre)
assert "extern" in result
assert result["extern"]["algo"] == "extern"
assert result["extern"]["pidx"] == 0

# rotate unknown pre raises
with pytest.raises(ValueError, match="nonexistent or invalid"):
mgr.rotate("EUnknownPrefix")

# params unknown pre raises
with pytest.raises(ValueError, match="nonexistent or invalid"):
mgr.params("EUnknownPrefix")


def test_extern_keeper_deprecation():
"""Test that importing ExternKeeper emits a DeprecationWarning"""
import keria.core.keeping as keeping_mod

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
cls = getattr(keeping_mod, "ExternKeeper")
assert cls is ExternManager
assert len(w) == 1
assert issubclass(w[0].category, DeprecationWarning)
assert "ExternManager" in str(w[0].message)


def test_module_getattr_unknown():
"""Test that accessing an unknown attribute raises AttributeError"""
import keria.core.keeping as keeping_mod

with pytest.raises(AttributeError, match="has no attribute"):
getattr(keeping_mod, "NoSuchThing")
5 changes: 2 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading