Skip to content

Commit

Permalink
Add support for config traits in inception event. (#104)
Browse files Browse the repository at this point in the history
* Add support for config traits in inception event.

Signed-off-by: pfeairheller <[email protected]>

* Test fix and coverage

Signed-off-by: pfeairheller <[email protected]>

---------

Signed-off-by: pfeairheller <[email protected]>
  • Loading branch information
pfeairheller authored Jan 29, 2024
1 parent e151291 commit 88f96a9
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 43 deletions.
2 changes: 1 addition & 1 deletion scripts/create_person_aid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from time import sleep

from keri.core import coring
from keri.core import serdering
from keri.core.coring import Tiers

from signify.app.clienting import SignifyClient
Expand Down
10 changes: 9 additions & 1 deletion src/signify/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get(self, name):
return res.json()

def create(self, name, transferable=True, isith="1", nsith="1", wits=None, toad="0", proxy=None, delpre=None,
dcode=MtrDex.Blake3_256, data=None, algo=Algos.salty, **kwargs):
dcode=MtrDex.Blake3_256, data=None, algo=Algos.salty, estOnly=False, DnD=False, **kwargs):

# Get the algo specific key params
keeper = self.client.manager.new(algo, self.client.pidx, **kwargs)
Expand All @@ -45,6 +45,12 @@ def create(self, name, transferable=True, isith="1", nsith="1", wits=None, toad=

wits = wits if wits is not None else []
data = [data] if data is not None else []
cnfg = []
if estOnly:
cnfg.append(eventing.TraitCodex.EstOnly)
if DnD:
cnfg.append(eventing.TraitCodex.DoNotDelegate)

if delpre is not None:
serder = eventing.delcept(delpre=delpre,
keys=keys,
Expand All @@ -54,6 +60,7 @@ def create(self, name, transferable=True, isith="1", nsith="1", wits=None, toad=
code=dcode,
wits=wits,
toad=toad,
cnfg=cnfg,
data=data)
else:
serder = eventing.incept(keys=keys,
Expand All @@ -63,6 +70,7 @@ def create(self, name, transferable=True, isith="1", nsith="1", wits=None, toad=
code=dcode,
wits=wits,
toad=toad,
cnfg=cnfg,
data=data)

sigs = keeper.sign(serder.raw)
Expand Down
136 changes: 95 additions & 41 deletions tests/app/test_aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,72 @@ def test_aiding_create():
expect(mock_keeper, times=1).incept(transferable=True).thenReturn((keys, ndigs))

from keri.core import serdering
mock_serder = mock({'raw': b'raw bytes', 'ked': {'a': 'key event dictionary'}}, spec=serdering.SerderKERI, strict=True)
mock_serder = mock({'raw': b'raw bytes', 'ked': {'a': 'key event dictionary'}}, spec=serdering.SerderKERI,
strict=True)

from keri.core import eventing
expect(eventing, times=1).incept(keys=keys, isith='1', nsith='1', ndigs=ndigs, code='E', wits=[], toad='0', data=[]).thenReturn(mock_serder)
expect(eventing, times=1).incept(keys=keys, isith='1', nsith='1', ndigs=ndigs, code='E', wits=[], toad='0',
cnfg=[], data=[]).thenReturn(mock_serder)
expect(mock_keeper, times=1).sign(mock_serder.raw).thenReturn(['a signature'])

from signify.app.clienting import SignifyClient
mock_client = mock({'pidx': 0}, spec=SignifyClient, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

from requests import Response
resp = mock({'json': lambda: {'post': 'success'}}, spec=Response, strict=True)
expect(mock_client, times=1).post('/identifiers', json={'name': 'new_aid', 'icp': {'a': 'key event dictionary'},
'sigs': ['a signature'], 'proxy': None, 'salty': {'keeper': 'params'},
'smids': ['a smid'], 'rmids': ['a rmid']}).thenReturn(resp)
'sigs': ['a signature'], 'proxy': None,
'salty': {'keeper': 'params'},
'smids': ['a smid'], 'rmids': ['a rmid']}).thenReturn(resp)

ids.create(name='new_aid', states=[{'i': 'a smid'}], rstates=[{'i': 'a rmid'}])

assert mock_client.pidx == 1

verifyNoUnwantedInteractions()
unstub()


def test_aiding_create_cnfg():
from signify.core import keeping
mock_keeper = mock({'params': lambda: {'keeper': 'params'}}, spec=keeping.SaltyKeeper, strict=True)
mock_manager = mock(spec=keeping.Manager, strict=True)

from mockito import kwargs
expect(mock_manager, times=1).new('salty', 0, **kwargs).thenReturn(mock_keeper)

keys = ['a signer verfer qb64']
ndigs = ['next signer digest']

expect(mock_keeper, times=1).incept(transferable=True).thenReturn((keys, ndigs))

from keri.core import serdering
mock_serder = mock({'raw': b'raw bytes', 'ked': {'a': 'key event dictionary'}}, spec=serdering.SerderKERI,
strict=True)

from keri.core import eventing
expect(eventing, times=1).incept(keys=keys, isith='1', nsith='1', ndigs=ndigs, code='E', wits=[], toad='0',
cnfg=['EO', 'DND'], data=[]).thenReturn(mock_serder)
expect(mock_keeper, times=1).sign(mock_serder.raw).thenReturn(['a signature'])

from signify.app.clienting import SignifyClient
mock_client = mock({'pidx': 0}, spec=SignifyClient, strict=True)
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore

from requests import Response
resp = mock({'json': lambda: {'post': 'success'}}, spec=Response, strict=True)
expect(mock_client, times=1).post('/identifiers', json={'name': 'new_aid', 'icp': {'a': 'key event dictionary'},
'sigs': ['a signature'], 'proxy': None,
'salty': {'keeper': 'params'}}).thenReturn(resp)

ids.create(name='new_aid', estOnly=True, DnD=True)

assert mock_client.pidx == 1

Expand All @@ -115,26 +160,30 @@ def test_aiding_create_delegation():
expect(mock_keeper, times=1).incept(transferable=True).thenReturn((keys, ndigs))

from keri.core import serdering
mock_serder = mock({'raw': b'raw bytes', 'ked': {'a': 'key event dictionary'}}, spec=serdering.SerderKERI, strict=True)
mock_serder = mock({'raw': b'raw bytes', 'ked': {'a': 'key event dictionary'}}, spec=serdering.SerderKERI,
strict=True)

from keri.core import eventing
expect(eventing, times=1).delcept(keys=['a signer verfer qb64'], delpre='my delegation', isith='1', nsith='1',
ndigs=['next signer digest'], code='E', wits=[], toad='0', data=[]).thenReturn(mock_serder)
expect(eventing, times=1).delcept(keys=['a signer verfer qb64'],
delpre='my delegation', isith='1', nsith='1',
ndigs=['next signer digest'], code='E', wits=[],
toad='0', cnfg=[], data=[]).thenReturn(mock_serder)
expect(mock_keeper, times=1).sign(mock_serder.raw).thenReturn(['a signature'])

from signify.app.clienting import SignifyClient
mock_client = mock({'pidx': 0}, spec=SignifyClient, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

from requests import Response
resp = mock({'json': lambda: {'post': 'success'}}, spec=Response, strict=True)
expect(mock_client, times=1).post('/identifiers',
json={'name': 'new_aid', 'icp': {'a': 'key event dictionary'}, 'sigs': ['a signature'],
'proxy': None, 'salty': {'keeper': 'params'}, 'smids': ['a smid'],
'rmids': ['a rmid']}).thenReturn(resp)
json={'name': 'new_aid', 'icp': {'a': 'key event dictionary'},
'sigs': ['a signature'],
'proxy': None, 'salty': {'keeper': 'params'}, 'smids': ['a smid'],
'rmids': ['a rmid']}).thenReturn(resp)

ids.create(name='new_aid', delpre='my delegation', states=[{'i': 'a smid'}], rstates=[{'i': 'a rmid'}])

Expand All @@ -150,10 +199,10 @@ def test_aiding_update_interact():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore
expect(ids, times=1).interact('aid1')

ids.update(name='aid1', typ='interact')
Expand All @@ -170,10 +219,10 @@ def test_aiding_update_rotate():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore
expect(ids, times=1).rotate('aid1')

ids.update(name='aid1', typ='rotate')
Expand All @@ -190,10 +239,10 @@ def test_aiding_update_bad():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

from keri import kering
with pytest.raises(kering.KeriError):
Expand All @@ -209,10 +258,10 @@ def test_aiding_delete():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

ids.delete(name='aid1')

Expand All @@ -226,10 +275,10 @@ def test_aiding_interact_no_data():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

mock_hab = {'prefix': 'hab prefix', 'name': 'aid1', 'state': {'s': '0', 'd': 'hab digest'}}
expect(ids, times=1).get('aid1').thenReturn(mock_hab)
Expand Down Expand Up @@ -266,17 +315,19 @@ def test_aiding_interact_with_data():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

mock_hab = {'prefix': 'hab prefix', 'name': 'aid1', 'state': {'s': '0', 'd': 'hab digest'}}
expect(ids, times=1).get('aid1').thenReturn(mock_hab)

from keri.core import eventing, serdering
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI, strict=True)
expect(eventing, times=1).interact('hab prefix', sn=1, data=[{'some': 'data'}, {'some': 'more'}], dig='hab digest').thenReturn(
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI,
strict=True)
expect(eventing, times=1).interact('hab prefix', sn=1, data=[{'some': 'data'}, {'some': 'more'}],
dig='hab digest').thenReturn(
mock_serder)

mock_keeper = mock({'algo': 'salty', 'params': lambda: {'keeper': 'params'}}, spec=keeping.SaltyKeeper, strict=True)
Expand Down Expand Up @@ -307,10 +358,10 @@ def test_aiding_rotate():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

mock_hab = {'prefix': 'hab prefix', 'name': 'aid1',
'state': {'s': '0', 'd': 'hab digest', 'b': ['wit1', 'wit2', 'wit3'], 'k': ['key1']}}
Expand All @@ -322,15 +373,16 @@ def test_aiding_rotate():
keys = ['key1']
ndigs = ['ndig1']
expect(mock_keeper, times=1).rotate(ncodes=['A'], transferable=True, states=[{'i': 'state 1'}, {'i': 'state 2'}],
rstates=[{'i': 'rstate 1'}, {'i': 'rstate 2'}]).thenReturn((keys, ndigs))
rstates=[{'i': 'rstate 1'}, {'i': 'rstate 2'}]).thenReturn((keys, ndigs))

from keri.core import serdering
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI, strict=True)
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI,
strict=True)

from keri.core import eventing
expect(eventing, times=1).rotate(pre='hab prefix', keys=['key1'], dig='hab digest', sn=1, isith='1', nsith='1',
ndigs=['ndig1'], toad=None, wits=['wit1', 'wit2', 'wit3'],
cuts=[], adds=[], data=[]).thenReturn(mock_serder)
ndigs=['ndig1'], toad=None, wits=['wit1', 'wit2', 'wit3'],
cuts=[], adds=[], data=[]).thenReturn(mock_serder)

expect(mock_keeper, times=1).sign(ser=mock_serder.raw).thenReturn(['a signature'])

Expand All @@ -342,7 +394,7 @@ def test_aiding_rotate():
expect(mock_response, times=1).json().thenReturn({'success': 'yay'})

_, _, out = ids.rotate(name='aid1', states=[{'i': 'state 1'}, {'i': 'state 2'}],
rstates=[{'i': 'rstate 1'}, {'i': 'rstate 2'}])
rstates=[{'i': 'rstate 1'}, {'i': 'rstate 2'}])
assert out['success'] == 'yay'

verifyNoUnwantedInteractions()
Expand All @@ -355,16 +407,17 @@ def test_aiding_add_end_role():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

mock_hab = {'prefix': 'hab prefix', 'name': 'aid1'}
expect(ids, times=1).get('aid1').thenReturn(mock_hab)

from keri.core import serdering
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI, strict=True)
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI,
strict=True)
expect(ids, times=1).makeEndRole('hab prefix', 'agent', None, None).thenReturn(mock_serder)

from signify.core import keeping
Expand Down Expand Up @@ -393,13 +446,14 @@ def test_aiding_sign():

from signify.core import keeping
mock_manager = mock(spec=keeping.Manager, strict=True)
mock_client.manager = mock_manager # type: ignore
mock_client.manager = mock_manager # type: ignore

from signify.app.aiding import Identifiers
ids = Identifiers(client=mock_client) # type: ignore
ids = Identifiers(client=mock_client) # type: ignore

from keri.core import serdering
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI, strict=True)
mock_serder = mock({'ked': {'a': 'key event dictionary'}, 'raw': b'serder raw bytes'}, spec=serdering.SerderKERI,
strict=True)

mock_hab = {'prefix': 'hab prefix', 'name': 'aid1'}
expect(ids, times=1).get('aid1').thenReturn(mock_hab)
Expand Down

0 comments on commit 88f96a9

Please sign in to comment.