-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample scripts and updates to Signify client for creating delegated m…
…ultisig AID across kli, sigPy and sigTS along with end role auths for the group multisig.
- Loading branch information
1 parent
41de85b
commit a81e92e
Showing
13 changed files
with
344 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
SIGNIFY | ||
signify.app.clienting module | ||
Testing clienting with integration tests that require a running KERIA Cloud Agent | ||
""" | ||
import json | ||
from time import sleep | ||
|
||
from keri.app.keeping import Algos | ||
from keri.core.coring import Tiers | ||
from signify.app.clienting import SignifyClient | ||
|
||
|
||
def create_multisig_aid(): | ||
url = "http://localhost:3901" | ||
bran = b'9876543210abcdefghijk' | ||
tier = Tiers.low | ||
|
||
client = SignifyClient(passcode=bran, tier=tier, url=url) | ||
|
||
identifiers = client.identifiers() | ||
operations = client.operations() | ||
states = client.keyStates() | ||
|
||
aid = identifiers.get("multisig-sigpy") | ||
sigPy = aid["state"] | ||
|
||
kli = states.get("EFBmwh8vdPTofoautCiEjjuA17gSlEnE3xc-xy-fGzWZ") | ||
sigTs = states.get("ELViLL4JCh-oktYca-pmPLwkmUaeYjyPmCLxELAKZW8V") | ||
|
||
assert len(kli) == 1 | ||
assert len(sigTs) == 1 | ||
|
||
states = rstates = [sigPy, kli[0], sigTs[0]] | ||
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) | ||
print("waiting on multisig creation...") | ||
while not op["done"]: | ||
op = operations.get(op["name"]) | ||
sleep(1) | ||
gAid = op["response"] | ||
print(f"group multisig created:") | ||
print(json.dumps(gAid, indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
create_multisig_aid() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 keri.core.coring import Tiers | ||
|
||
from signify.app.clienting import SignifyClient | ||
|
||
|
||
def list_aids(): | ||
url = "http://localhost:3901" | ||
bran = b'9876543210abcdefghijk' | ||
tier = Tiers.low | ||
client = SignifyClient(passcode=bran, tier=tier, url=url) | ||
|
||
identifiers = client.identifiers() | ||
res = identifiers.list() | ||
for aid in res["aids"]: | ||
print(f"{aid['name']}: {aid['prefix']}") | ||
|
||
|
||
if __name__ == "__main__": | ||
list_aids() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
// @ts-ignore | ||
let signify: any; | ||
|
||
// @ts-ignore | ||
import('signify-ts').then( | ||
(module) => { | ||
signify = module | ||
signify.ready().then(() => { | ||
console.log("Signify client ready!"); | ||
makeends().then(() => { | ||
console.log("Done") | ||
}); | ||
}); | ||
} | ||
) | ||
|
||
async function makeends() { | ||
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 escrows = client.escrows() | ||
|
||
let members = await identifiers.members("multisig") | ||
let hab = await identifiers.get("multisig") | ||
let aid = hab["prefix"] | ||
let signing = members['signing'] | ||
|
||
let auths = new Map<string, Date>() | ||
let stamp = new Date() | ||
|
||
signing.forEach((end: any) => { | ||
let ends = end["ends"] | ||
let roles = ["agent", "mailbox"] | ||
roles.forEach((role) => { | ||
if (role in ends) { | ||
Object.keys(ends[role]).forEach((k:any) => { | ||
let key = [aid, role, k].join(".") | ||
auths.set(key, stamp) | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
let rpys = await escrows.listReply("/end/role") | ||
|
||
rpys.forEach((rpy:object) => { | ||
let serder = new signify.Serder(rpy) | ||
let payload = serder.ked['a'] | ||
|
||
let key = Object.values(payload).join(".") | ||
let then = new Date(Date.parse(serder.ked["dt"])) | ||
if (auths.has(key) && then < stamp) { | ||
identifiers.addEndRole("multisig", payload["role"], payload["eid"], serder.ked["dt"]) | ||
auths.set(key, then) // track signed role auths by timestamp signed | ||
} | ||
}) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
|
||
npx --package=signify-ts ts-node client.ts | ||
|
||
read -n 1 -r -p "Press any key to create endpoints for multisig AID..." | ||
|
||
npx --package=signify-ts ts-node make_endroles.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
SIGNIFY | ||
signify.app.clienting module | ||
Testing clienting with integration tests that require a running KERIA Cloud Agent | ||
""" | ||
|
||
import json | ||
from time import sleep | ||
|
||
from keri.app.keeping import Algos | ||
from keri.core import coring | ||
from keri.core.coring import Tiers | ||
from keri.help import helping | ||
from signify.app.clienting import SignifyClient | ||
|
||
url = "http://localhost:3901" | ||
bran = b'9876543210abcdefghijk' | ||
tier = Tiers.low | ||
|
||
def authorize_endroles(): | ||
client = SignifyClient(passcode=bran, tier=tier, url=url) | ||
identifiers = client.identifiers() | ||
escrows = client.escrows() | ||
endroles = client.endroles() | ||
|
||
members = identifiers.members("multisig") | ||
hab = identifiers.get("multisig") | ||
aid = hab["prefix"] | ||
|
||
auths = {} | ||
stamp = helping.nowUTC() | ||
|
||
for member in members['signing']: | ||
ends = member["ends"] | ||
if not ends: | ||
print("\tNone") | ||
|
||
for role in ("agent", "mailbox"): | ||
if role in ends: | ||
for k, v in ends[role].items(): | ||
auths[(aid, role, k)] = stamp | ||
|
||
rpys = escrows.getEscrowReply(route="/end/role") | ||
for rpy in rpys: | ||
serder = coring.Serder(ked=rpy) | ||
payload = serder.ked['a'] | ||
keys = tuple(payload.values()) | ||
then = helping.fromIso8601(serder.ked["dt"]) | ||
if keys in auths and then < stamp: | ||
identifiers.addEndRole("multisig", role=payload["role"], eid=payload['eid'], stamp=helping.toIso8601(then)) | ||
auths[keys] = then # track signed role auths by timestamp signed | ||
|
||
print("Waiting for approvals from other members...") | ||
authKeys = set(auths.keys()) | ||
while authKeys - endrole_set(endroles, "multisig"): | ||
rpys = escrows.getEscrowReply(route="/end/role") | ||
for rpy in rpys: | ||
serder = coring.Serder(ked=rpy) | ||
payload = serder.ked['a'] | ||
keys = tuple(payload.values()) | ||
if keys in auths: | ||
then = helping.fromIso8601(serder.ked["dt"]) | ||
stamp = auths[keys] | ||
|
||
if stamp == then: | ||
continue | ||
|
||
if then < stamp: | ||
print(f"authing {payload} - {then}") | ||
identifiers.addEndRole("multisig", role=payload["role"], eid=payload['eid'], | ||
stamp=serder.ked["dt"]) | ||
auths[keys] = then # track signed role auths by timestamp signed | ||
|
||
print("All endpoint role authorizations approved") | ||
|
||
|
||
def endrole_set(er, name): | ||
ends = er.list(name=name) | ||
return {(end['cid'], end['role'], end['eid']) for end in ends} | ||
|
||
|
||
def list_endroles(): | ||
client = SignifyClient(passcode=bran, tier=tier, url=url) | ||
|
||
endroles = client.endroles() | ||
print(endrole_set(endroles, "multisig")) | ||
|
||
|
||
if __name__ == "__main__": | ||
authorize_endroles() | ||
# list_endroles() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- encoding: utf-8 -*- | ||
""" | ||
SIGNIFY | ||
signify.app.clienting module | ||
Testing clienting with integration tests that require a running KERIA Cloud Agent | ||
""" | ||
import json | ||
from time import sleep | ||
|
||
from keri.app.keeping import Algos | ||
from keri.core.coring import Tiers | ||
from signify.app.clienting import SignifyClient | ||
|
||
|
||
def stream_escrows(): | ||
url = "http://localhost:3901" | ||
bran = b'9876543210abcdefghijk' | ||
tier = Tiers.low | ||
|
||
client = SignifyClient(passcode=bran, tier=tier, url=url) | ||
|
||
endroles = client.endroles() | ||
|
||
|
||
|
||
|
||
escrows = client.escrows() | ||
|
||
for rpy in escrows.getEscrowReplyIter(route="/end/role"): | ||
print(rpy) | ||
|
||
|
||
if __name__ == "__main__": | ||
stream_escrows() |
Oops, something went wrong.