diff --git a/scripts/list_notifications.py b/scripts/list_notifications.py index e1460be..d1ab53b 100644 --- a/scripts/list_notifications.py +++ b/scripts/list_notifications.py @@ -5,23 +5,32 @@ Testing clienting with integration tests that require a running KERIA Cloud Agent """ - +from keri.core import coring from keri.core.coring import Tiers from signify.app.clienting import SignifyClient def list_notifications(): url = "http://localhost:3901" - bran = b'Pwt6yLXRSs7IjZ23tRHIV' + bran = b'PoLT1X6fDQliXyCuzCVuv' tier = Tiers.low client = SignifyClient(passcode=bran, tier=tier, url=url) notificatons = client.notifications() notes = notificatons.list() - print(notes) + exchanges = client.exchanges() + + note = notes['notes'][3] + said = note['a']['d'] + + res = exchanges.get("holder1", said) + exn = coring.Serder(ked=res['exn']) + + print(exn.pretty(size=7000)) + if __name__ == "__main__": list_notifications() diff --git a/scripts/multisig-holder.py b/scripts/multisig-holder.py index 84d84b9..f4dc458 100644 --- a/scripts/multisig-holder.py +++ b/scripts/multisig-holder.py @@ -18,6 +18,7 @@ from signify.app.clienting import SignifyClient +TIME = "2023-10-15T16:01:37.000000+00:00" def multisig_holder(): print("Creating issuer agent") @@ -28,6 +29,7 @@ def multisig_holder(): print("Creating issuer AID") create_aid(client0, "issuer", "W1OnK0b5rKq6TcKBWhsQa", "ELTkSY_C70Qj8SbPh7F121Q3iA_zNlt8bS-pzOMiCBgG") add_end_role(client0, "issuer") + issuer = get_aid(client0, "issuer") print("Creating holder1 agent") client1 = create_agent(b'PoLT1X6fDQliXyCuzCVuv', @@ -76,7 +78,7 @@ def multisig_holder(): exn = coring.Serder(ked=op["response"]['exn']) print(f"Challenge signed in {exn.said}") - client1.challenges().responded(holder2['i'], exn.said) + client1.challenges().responded("holder1", holder2['i'], exn.said) states = [holder1, holder2] @@ -110,9 +112,32 @@ def multisig_holder(): holder = resolve_oobi(client0, "holder", "http://127.0.0.1:3902/oobi/EH_axvx0v0gwQaCawqem5u8ZeDKx9TUWKsowTa_xj0yb") - print(holder) create_credential(client0, holder) + notificatons = client1.notifications() + + notes = notificatons.list() + while notes['total'] < 4: + sleep(1) + notes = notificatons.list() + + grant = notes['notes'][3] + gsaid = grant['a']['d'] + print(f"Received grant notification for grant {gsaid}") + + print(f"\nSending admit back") + create_admit(client1, "holder1", "holder", gsaid, [member2['prefix']]) + create_admit(client2, "holder2", "holder", gsaid, [member1['prefix']]) + + notificatons = client0.notifications() + + notes = notificatons.list() + while notes['total'] < 1: + sleep(1) + notes = notificatons.list() + + print(notes) + def create_agent(bran, controller, agent): url = "http://localhost:3901" @@ -190,6 +215,33 @@ def create_multisig(client, name, member, states): return op +def create_admit(client, participant, group, said, recp): + exchanges = client.exchanges() + ipex = client.ipex() + + res = exchanges.get(participant, said) + grant = coring.Serder(ked=res['exn']) + ghab = get_aid(client, group) + mhab = get_aid(client, participant) + + admit, sigs, end = ipex.admit(ghab, "", grant, dt=TIME) + + mstate = ghab["state"] + seal = eventing.SealEvent(i=ghab["prefix"], s=mstate["ee"]["s"], d=mstate["ee"]["d"]) + ims = eventing.messagize(serder=admit, sigers=[coring.Siger(qb64=sig) for sig in sigs], seal=seal) + ims.extend(end) + embeds = dict( + exn=ims + ) + atc = bytes(ims[admit.size:]) + + exchanges.send(participant, "multisig", sender=mhab, route="/multisig/exn", + payload=dict(gid=ghab["prefix"]), + embeds=embeds, recipients=recp) + + exchanges.sendFromEvents(group, "credential", admit, sigs, atc.decode("utf-8"), [grant.ked['i']]) + + def get_aid(client, name): identifiers = client.identifiers() return identifiers.get(name) diff --git a/src/signify/app/challenging.py b/src/signify/app/challenging.py index 66a2983..972b22c 100644 --- a/src/signify/app/challenging.py +++ b/src/signify/app/challenging.py @@ -73,5 +73,5 @@ def responded(self, name, source, said): said=said ) - res = self.client.post(f"/challenges/{name}/verify/{source}", json=json) - return res.json() + self.client.put(f"/challenges/{name}/verify/{source}", json=json) + return True diff --git a/src/signify/app/credentialing.py b/src/signify/app/credentialing.py index ac5f0fd..88ce3bf 100644 --- a/src/signify/app/credentialing.py +++ b/src/signify/app/credentialing.py @@ -272,3 +272,14 @@ def grant(self, hab, recp, message, acdc, iss, anc, agree=None, dt=None): payload=data, embeds=embeds, dt=dt) return grant, gsigs, end + + def admit(self, hab, message, grant, dt=None): + exchanges = self.client.exchanges() + data = dict( + m=message, + ) + + grant, gsigs, end = exchanges.createExchangeMessage(sender=hab, route="/ipex/admit", + payload=data, embeds=None, dt=dt, dig=grant.said) + + return grant, gsigs, end diff --git a/src/signify/peer/exchanging.py b/src/signify/peer/exchanging.py index 693d2eb..3685201 100644 --- a/src/signify/peer/exchanging.py +++ b/src/signify/peer/exchanging.py @@ -4,8 +4,6 @@ signify.app.exchanging module """ -from pprint import pprint - from keri.peer import exchanging from signify.app.clienting import SignifyClient @@ -54,7 +52,7 @@ def send(self, name, topic, sender, route, payload, embeds, recipients): return exn, sigs, res.json() - def createExchangeMessage(self, sender, route, payload, embeds, dt=None): + def createExchangeMessage(self, sender, route, payload, embeds, dig=None, dt=None): """ Create exn message from parameters and return Serder with signatures and additional attachments. Parameters: @@ -62,6 +60,7 @@ def createExchangeMessage(self, sender, route, payload, embeds, dt=None): route (str): exn route field payload (dict): payload of the exn message embeds (dict): map of label to bytes of encoded KERI event to embed in exn + dig (str): Optional qb64 SAID of exchange message reverse chain dt (str): Iso formatted date string Returns: @@ -76,6 +75,7 @@ def createExchangeMessage(self, sender, route, payload, embeds, dt=None): payload=payload, sender=sender["prefix"], embeds=embeds, + dig=dig, date=dt) sigs = keeper.sign(ser=exn.raw) @@ -109,3 +109,17 @@ def sendFromEvents(self, name, topic, exn, sigs, atc, recipients): res = self.client.post(f"/identifiers/{name}/exchanges", json=body) return res.json() + def get(self, name, said): + """ + + Parameters: + name (str): human readable identifier alias to send from + said (str): qb64 SAID of the exn message to retrieve + + Returns: + dict: exn message + + """ + + res = self.client.get(f"/identifiers/{name}/exchanges/{said}") + return res.json() \ No newline at end of file diff --git a/tests/app/test_challenging.py b/tests/app/test_challenging.py index 210f4c6..0820fe5 100644 --- a/tests/app/test_challenging.py +++ b/tests/app/test_challenging.py @@ -6,8 +6,7 @@ Testing challenge with unit tests """ -import pytest -from mockito import mock, verify, verifyNoUnwantedInteractions, unstub, expect +from mockito import mock, verifyNoUnwantedInteractions, unstub, expect def test_challenges_generate(): @@ -68,14 +67,11 @@ def test_challenge_responded(): said = "E456" from requests import Response mock_response = mock({}, spec=Response, strict=True) - expect(mock_client, times=1).post(f'/challenges/{name}/verify/{source}', - json=dict(said=said)).thenReturn(mock_response) - expect(mock_response, times=1).json().thenReturn( - {"done": False} - ) + expect(mock_client, times=1).put(f'/challenges/{name}/verify/{source}', + json=dict(said=said)).thenReturn(mock_response) out = chas.responded(name, source, said) - assert out["done"] is False + assert out is True verifyNoUnwantedInteractions() unstub()