Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group multisig communication using exn messages with embedded events #100

Merged
Merged
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
23 changes: 21 additions & 2 deletions examples/scripts/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ async function connect() {
let identifiers = client.identifiers()
const oobis = client.oobis()
const operations = client.operations()
const exchanges = client.exchanges()

let salt = 'abcdefghijk0123456789'
let op = await identifiers.create("multisig-ts", {bran: salt})
let res = identifiers.create("multisig-ts", {bran: salt})
let op = await res.op()
let aid = op["response"]

await identifiers.addEndRole("multisig-ts", "agent", d.agent.i)
Expand Down Expand Up @@ -93,7 +95,7 @@ async function connect() {
let sigTs = aid['state']

let states = [sigPy, kli, sigTs]
identifiers.create("multisig", {
let ires = identifiers.create("multisig", {
algo: "group", mhab: aid,
delpre: "EHpD0-CDWOdu5RJ8jHBSUkOqBZ3cXeDVHWNb_Ul89VI7",
toad: 2,
Expand All @@ -106,5 +108,22 @@ async function connect() {
states: states,
rstates: states
})

let serder = ires.serder
let sigs = ires.sigs
let sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}))

let ims = signify.d(signify.messagize(serder, sigers))
let atc = ims.substring(serder.size)
let embeds = {
icp: [serder, atc],
}

let smids = states.map((state) => state['i'])
let recp = [sigPy, kli].map((state) => state['i'])

await exchanges.send("multisig-ts", "multisig", aid, "/multisig/icp",
{'gid': serder.pre, smids: smids, rmids: smids}, embeds, recp)

}

40 changes: 29 additions & 11 deletions examples/scripts/create_multisig_aid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from time import sleep

from keri.app.keeping import Algos
from keri.core import eventing, coring
from keri.core.coring import Tiers
from keri.peer import exchanging
from signify.app.clienting import SignifyClient


Expand All @@ -23,6 +25,7 @@ def create_multisig_aid():
identifiers = client.identifiers()
operations = client.operations()
states = client.keyStates()
exchanges = client.exchanges()

aid = identifiers.get("multisig-sigpy")
sigPy = aid["state"]
Expand All @@ -37,17 +40,32 @@ def create_multisig_aid():
for state in states:
print(json.dumps(state, indent=2))

op = identifiers.create("multisig", algo=Algos.group, mhab=aid,
delpre="EHpD0-CDWOdu5RJ8jHBSUkOqBZ3cXeDVHWNb_Ul89VI7",
toad=2,
wits=[
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"
],
isith=["1/3", "1/3", "1/3"], nsith=["1/3", "1/3", "1/3"],
states=states,
rstates=rstates)
icp, isigs, op = identifiers.create("multisig", algo=Algos.group, mhab=aid,
delpre="EHpD0-CDWOdu5RJ8jHBSUkOqBZ3cXeDVHWNb_Ul89VI7",
toad=2,
wits=[
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"
],
isith=["1/3", "1/3", "1/3"], nsith=["1/3", "1/3", "1/3"],
states=states,
rstates=rstates)

smids = ["EBcIURLpxmVwahksgrsGW6_dUw0zBhyEHYFk17eWrZfk",
"EFBmwh8vdPTofoautCiEjjuA17gSlEnE3xc-xy-fGzWZ",
"ELViLL4JCh-oktYca-pmPLwkmUaeYjyPmCLxELAKZW8V"]
recp = ["EFBmwh8vdPTofoautCiEjjuA17gSlEnE3xc-xy-fGzWZ",
"ELViLL4JCh-oktYca-pmPLwkmUaeYjyPmCLxELAKZW8V"]

embeds = dict(
icp=eventing.messagize(serder=icp, sigers=[coring.Siger(qb64=sig) for sig in isigs])
)

exchanges.send("multisig-sigpy", "multisig", sender=aid, route="/multisig/icp",
payload=dict(gid=icp.pre, smids=smids, rmids=smids),
embeds=embeds, recipients=recp)

print("waiting on multisig creation...")
while not op["done"]:
op = operations.get(op["name"])
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/create_person_aid.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create_aid():
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"
]

op = identifiers.create("multisig-sigpy", bran="0123456789abcdefghijk", wits=wits, toad="2")
_, _, op = identifiers.create("multisig-sigpy", bran="0123456789abcdefghijk", wits=wits, toad="2")

while not op["done"]:
op = operations.get(op["name"])
Expand Down
27 changes: 27 additions & 0 deletions examples/scripts/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- encoding: utf-8 -*-
"""
SIGNIFY
signify.app.clienting module

Testing clienting with integration tests that require a running KERIA Cloud Agent
"""
from pprint import pprint

from keri.core.coring import Tiers
from signify.app.clienting import SignifyClient


def get():
url = "http://localhost:3901"
bran = b'9876543210abcdefghijk'
tier = Tiers.low

client = SignifyClient(passcode=bran, tier=tier, url=url)

identifiers = client.identifiers()

aid = identifiers.get("multisig")
pprint(aid)

if __name__ == "__main__":
get()
85 changes: 85 additions & 0 deletions examples/scripts/list_notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# -*- encoding: utf-8 -*-
"""
SIGNIFY
signify.app.clienting module

Testing clienting with integration tests that require a running KERIA Cloud Agent
"""
import json
from pprint import pprint

from keri.core import coring
from keri.core.coring import Tiers
from keri.core.eventing import messagize, SealEvent
from keri.peer import exchanging
from signify.app.clienting import SignifyClient


def list_notifications():
url = "http://localhost:3901"
bran = b'9876543210abcdefghijk'
tier = Tiers.low

client = SignifyClient(passcode=bran, tier=tier, url=url)
identifiers = client.identifiers()
notificatons = client.notifications()
groups = client.groups()
registries = client.registries()

res = notificatons.list()

for note in res["notes"]:
body = note['a']
route = body['r']
match route.split("/"):
case ["", "multisig", "icp"]:
pass
# print(body)
# print(f"Recv: inception request for multisig AID=BLAH")
case ["", "multisig", "vcp"]:
said = body['d']
res = groups.get_request(said=said)
msg = next(exn for exn in res if exn['exn']['d'] == said)

sender = msg['sender']
group = msg["groupName"]

exn = msg['exn']
usage = exn['a']["usage"]
print(f"Credential registry inception request for group AID {group}:")
print(f"\tReceived from: {sender}")
print(f"\tPurpose: \"{usage}\"")
yes = input("Approve [Y|n]? ")

if yes in ('', 'y', 'Y'):
registryName = input("Enter new local name for registry: ")
embeds = exn['e']
vcp = embeds['vcp']
ixn = embeds['ixn']
serder = coring.Serder(ked=ixn)
ghab = identifiers.get(group)

keeper = client.manager.get(aid=ghab)
sigs = keeper.sign(ser=serder.raw)

ims = messagize(serder=serder, sigers=[coring.Siger(qb64=sig) for sig in sigs])
embeds = dict(
vcp=coring.Serder(ked=vcp).raw,
ixn=ims
)

sender = ghab["group"]["mhab"]
keeper = client.manager.get(aid=sender)
exn, end = exchanging.exchange(route="/multisig/vcp",
payload={'gid': ghab["prefix"], 'usage': "test"},
sender=sender["prefix"], embeds=embeds)

esigs = keeper.sign(ser=exn.raw)
groups.send_request(group, exn.ked, esigs, end)

return registries.create_from_events(name=group, hab=ghab, registryName=registryName, vcp=vcp,
ixn=ixn, sigs=sigs)


if __name__ == "__main__":
list_notifications()
101 changes: 101 additions & 0 deletions examples/scripts/list_notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

const prmpt = require("prompt-sync")({ sigint: true });
// @ts-ignore
let signify: any;

// @ts-ignore
import('signify-ts').then(
(module) => {
signify = module
signify.ready().then(() => {
console.log("Signify client ready!");
list_notifications().then(() => {
console.log("Done")
});
});
}
)

async function list_notifications() {
let url = "http://127.0.0.1:3901"
let bran = '0123456789abcdefghijk'

const client = new signify.SignifyClient(url, bran);
await client.connect()
let d = await client.state()
console.log("Connected: ")
console.log(" Agent: ", d.agent.i, " Controller: ", d.controller.state.i)

let identifiers = client.identifiers()
let notifications = client.notifications()
let groups = client.groups()
let registries = client.registries()

let res = await notifications.list()
let notes = res.notes

for (const note of notes) {
let payload = note.a
let route = payload.r

if (route === '/multisig/vcp') {
let res = await groups.getRequest(payload.d)
if (res.length == 0) {
console.log("error extracting exns matching nre for " + payload.data)
}
let msg = res[0]

let sender = msg['sender']
let group = msg["groupName"]

let exn = msg['exn']
let usage = exn['a']["usage"]
console.log("Credential registry inception request for group AID :" + group)
console.log("\tReceived from: " + sender)
console.log("\tPurpose: " + usage)
console.log("\nAuto-creating new registry...")
let yes = prmpt("Approve [Y|n]? ")
if (yes === "y" || yes === "Y" || yes === "") {
try {
let registryName = prmpt("Enter new local name for registry: ")
let embeds = exn['e']
let vcp = embeds['vcp']
let ixn = embeds['ixn']
let serder = new signify.Serder(ixn)
let ghab = await identifiers.get(group)

let keeper = client.manager.get(ghab)
let sigs = keeper.sign(signify.b(serder.raw))
let sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}))

let ims = signify.d(signify.messagize(serder, sigers))
let atc = ims.substring(serder.size)
embeds = {
vcp: [new signify.Serder(vcp), undefined],
ixn: [serder, atc]
}

sender = ghab["group"]["mhab"]
keeper = client.manager.get(sender)
let [nexn, end] = signify.exchange("/multisig/vcp",
{'gid': ghab["prefix"], 'usage': "test"},
sender["prefix"], undefined, undefined, undefined, undefined, embeds)

console.log(nexn.pretty())
let esigs = keeper.sign(nexn.raw)
await groups.sendRequest(group, nexn.ked, esigs, signify.d(end))

return await registries.createFromEvents(ghab, group, registryName, vcp, ixn, sigs)
} catch(e: any) {
console.log(e)
}
}



}

}

}

Loading
Loading