Skip to content

Commit

Permalink
exn message updates to support IPEX admit messages.
Browse files Browse the repository at this point in the history
Signed-off-by: pfeairheller <pfeairheller@gmail.com>
  • Loading branch information
pfeairheller committed Oct 21, 2023
1 parent d4de181 commit b47a7e9
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 18 deletions.
15 changes: 12 additions & 3 deletions scripts/list_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
56 changes: 54 additions & 2 deletions scripts/multisig-holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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',
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/signify/app/challenging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions src/signify/app/credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 17 additions & 3 deletions src/signify/peer/exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
signify.app.exchanging module
"""
from pprint import pprint

from keri.peer import exchanging

from signify.app.clienting import SignifyClient
Expand Down Expand Up @@ -54,14 +52,15 @@ 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:
sender (dict): Identifier dict from identifiers.get
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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
12 changes: 4 additions & 8 deletions tests/app/test_challenging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b47a7e9

Please sign in to comment.