Skip to content

Commit

Permalink
fix: pass smids and rmids to SignifyGroupHab rotate (WebOfTrust#243)
Browse files Browse the repository at this point in the history
* fix: pass smids and rmids to SignifyGroupHab rotate

* test: group signify rotation and retention of smids, rmids in db layer
  • Loading branch information
iFergal authored May 18, 2024
1 parent 5bdc473 commit a1a9b02
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/keria/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,9 @@ def rotate(agent, name, body):
serder = serdering.SerderKERI(sad=rot)
sigers = [core.Siger(qb64=sig) for sig in sigs]

hab.rotate(serder=serder, sigers=sigers)

if Algos.salty in body:
hab.rotate(serder=serder, sigers=sigers)

salt = body[Algos.salty]
keeper = agent.mgr.get(Algos.salty)

Expand All @@ -581,19 +581,23 @@ def rotate(agent, name, body):
raise falcon.HTTPInternalServerError(description=f"{e.args[0]}")

elif Algos.randy in body:
hab.rotate(serder=serder, sigers=sigers)

rand = body[Algos.randy]
keeper = agent.mgr.get(Algos.randy)

keeper.rotate(pre=serder.pre, verfers=serder.verfers, digers=serder.ndigers, **rand)

elif Algos.group in body:
smids = httping.getRequiredParam(body, "smids")
rmids = httping.getRequiredParam(body, "rmids")

hab.rotate(serder=serder, sigers=sigers, smids=smids, rmids=rmids)

keeper = agent.mgr.get(Algos.group)

keeper.rotate(pre=serder.pre, verfers=serder.verfers, digers=serder.ndigers)

smids = httping.getRequiredParam(body, "smids")
rmids = httping.getRequiredParam(body, "rmids")

agent.groups.append(dict(pre=hab.pre, serder=serder, sigers=sigers, smids=smids, rmids=rmids))
op = agent.monitor.submit(serder.pre, longrunning.OpTypes.group, metadata=dict(sn=serder.sn))

Expand Down
59 changes: 59 additions & 0 deletions tests/app/test_aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def test_identifier_collection_end(helpers):

keys = [signer.verfer.qb64 for signer in signers]
ndigs = [coring.Diger(ser=nsigner.verfer.qb64b) for nsigner in nsigners]
signer1 = signers[0]
diger1 = ndigs[0]

serder = eventing.rotate(pre=res.json[0]["prefix"],
keys=keys,
Expand Down Expand Up @@ -646,6 +648,63 @@ def test_identifier_collection_end(helpers):
rotation = res.json["rotation"]
assert len(rotation) == 3

# Test group rotation
p1.rotate()
p2.rotate()

keys = [signer1.verfer.qb64, p1.kever.verfers[0].qb64, p2.kever.verfers[0].qb64]
ndigs = [diger1.qb64, p1.kever.ndigers[0].qb64, p2.kever.ndigers[0].qb64]

rserder = eventing.rotate(pre=serder.pre,
dig=serder.said,
keys=keys,
ndigs=ndigs,
isith="2",
nsith="2")

sigers = [signer1.sign(ser=rserder.raw, index=0).qb64,
p1.sign(ser=rserder.raw, indices=[1])[0].qb64,
p2.sign(ser=rserder.raw, indices=[2])[0].qb64]
smids = rmids = [agent0.get('i'), p1.pre, p2.pre]

body = {
'rot': rserder.ked,
'sigs': sigers,
'smids': smids,
'rmids': rmids,
'group': {
'mhab': mhab,
'keys': keys,
'ndigs': ndigs
}
}

res = client.simulate_post(path="/identifiers/multisig/events", body=json.dumps(body))
assert res.status_code == 200

# Make sure keys got rotated
res = client.simulate_get(path="/identifiers")
assert res.status_code == 200
assert len(res.json) == 3
aid = res.json[2]
assert aid["name"] == "multisig"
assert aid["prefix"] == rserder.pre
group = aid["group"]

assert group["keys"] == ['DKy7HNSig5OuFOfXKq85H_R35KA6TqjRnaLKrCl8sYih',
'DNHAT44MX_0kvxXm2JParu_VXDk6_Y3csi22h85ZXklA',
'DFWjujqjGJDJPDTxcCUv5uQ7rfHHVKM8FWIVMrqMM6ib']
assert group["ndigs"] == ['EHTQYGOEz97iOPC_DgEEGncSa1-X-TDiHdGNKQiN_3XJ',
'EGk-woPrFzGCOqPY4eOjpUFMKXXO1QcpaY53FplXqnvr',
'EDubroAsnG8zcvKQcjA-H1nfDVVvoxGy96LsEq0cTFJX']

# Ensure smids and rmids (remain) set
habord = agent.hby.db.habs.get(keys=(rserder.pre,))
assert habord.smids == ['EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHZSysY',
'EBPtjiAY9ITdvScWFGeeCu3Pf6_CFFr57siQqffVt9Of',
'EMYBtOuBKVdp3KdW_QM__pi-UAWfrewlDyiqGcbIbopR']
assert habord.smids == habord.rmids

# Try unknown witness
serder, signers = helpers.incept(salt, "signify:aid", pidx=3,
wits=["BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkunkn"],
Expand Down

0 comments on commit a1a9b02

Please sign in to comment.