Skip to content

Commit

Permalink
multisig
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo Miranda committed Sep 6, 2023
1 parent b23b3aa commit 85032ee
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 30 deletions.
60 changes: 39 additions & 21 deletions examples/integration-scripts/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ async function run() {


// Create two identifiers, one for each client
let op1 = await client1.identifiers().create('issuer', {
let icpResult1 = client1.identifiers().create('issuer', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
let op1 = await icpResult1.op()
while (!op1["done"] ) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand All @@ -56,13 +57,14 @@ async function run() {
await client1.identifiers().addEndRole("issuer", 'agent', client1!.agent!.pre)
console.log("Issuer's AID:", aid1.prefix)

let op2 = await client2.identifiers().create('recipient', {
let icpResult2 = await client2.identifiers().create('recipient', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
let op2 = await icpResult2.op()
while (!op2["done"] ) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand All @@ -71,13 +73,14 @@ async function run() {
await client2.identifiers().addEndRole("recipient", 'agent', client2!.agent!.pre)
console.log("Recipient's AID:", aid2.prefix)

let op3 = await client3.identifiers().create('verifier', {
let icpResult3 = await client3.identifiers().create('verifier', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
let op3 = await icpResult3.op()
while (!op3["done"] ) {
op3 = await client3.operations().get(op3.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand Down Expand Up @@ -179,11 +182,25 @@ async function run() {
console.log("Credential issued")

// Recipient check issued credential
let creds2 = await client2.credentials().list('recipient')
assert.equal(creds2.length, 1)
assert.equal(creds2[0].sad.s, schemaSAID)
assert.equal(creds2[0].sad.i, aid1.prefix)
assert.equal(creds2[0].status.s, "0") // 0 = issued
let credentialReceived = false
while (!credentialReceived) {
let notifications = await client2.notifications().list()
for (let notif of notifications.notes){
if (notif.a.r == '/exn//credential/issue') {
credentialReceived = true
await client2.notifications().mark(notif.i)
}
}
await new Promise(resolve => setTimeout(resolve, 1000));
}

// Credetials are no longer accepted by default
// pending implementation in KERI to accept them
// let creds2 = await client2.credentials().list('recipient')
// assert.equal(creds2.length, 1)
// assert.equal(creds2[0].sad.s, schemaSAID)
// assert.equal(creds2[0].sad.i, aid1.prefix)
// assert.equal(creds2[0].status.s, "0") // 0 = issued
console.log("Credential received by recipient")

// Present credential
Expand All @@ -210,19 +227,20 @@ async function run() {
console.log("Credential revoked")

// Recipient check revoked credential
let revoked = false
while (!revoked) {
let cred2 = await client2.credentials().get('recipient', creds1[0].sad.d)
if (cred2.status.s == "1") {
revoked = true
}
}
creds2 = await client2.credentials().list('recipient')
assert.equal(creds2.length, 1)
assert.equal(creds2[0].sad.s, schemaSAID)
assert.equal(creds2[0].sad.i, aid1.prefix)
assert.equal(creds2[0].status.s, "1") // 1 = revoked
console.log("Revocation received by recipient")
// credentialReceived = false
// let revoked = false
// while (!revoked) {
// let cred2 = await client2.credentials().get('recipient', creds1[0].sad.d)
// if (cred2.status.s == "1") {
// revoked = true
// }
// }
// let creds2 = await client2.credentials().list('recipient')
// assert.equal(creds2.length, 1)
// assert.equal(creds2[0].sad.s, schemaSAID)
// assert.equal(creds2[0].sad.i, aid1.prefix)
// assert.equal(creds2[0].status.s, "1") // 1 = revoked
// console.log("Revocation received by recipient")

// Present revoked credential
await client1.credentials().present('issuer', creds1[0].sad.d, 'verifier', true)
Expand Down
63 changes: 57 additions & 6 deletions examples/integration-scripts/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ async function run() {


// Create two identifiers, one for each client
let op1 = await client1.identifiers().create('multisig1', {
let icpResult1 = client1.identifiers().create('multisig1', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
let op1 = await icpResult1.op()
while (!op1["done"] ) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand All @@ -56,13 +57,14 @@ async function run() {
await client1.identifiers().addEndRole("multisig1", 'agent', client1!.agent!.pre)
console.log("Multisig1's AID:", aid1.prefix)

let op2 = await client2.identifiers().create('multisig2', {
let icpResult2 = client2.identifiers().create('multisig2', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
let op2 = await icpResult2.op()
while (!op2["done"] ) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand All @@ -71,13 +73,14 @@ async function run() {
await client2.identifiers().addEndRole("multisig2", 'agent', client2!.agent!.pre)
console.log("Multisig2's AID:", aid2.prefix)

let op3 = await client3.identifiers().create('multisig3', {
let icpResult3 = client3.identifiers().create('multisig3', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
let op3 = await icpResult3.op()
while (!op3["done"] ) {
op3 = await client3.operations().get(op3.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand Down Expand Up @@ -131,7 +134,7 @@ async function run() {
// Create a multisig identifier
let rstates = [aid1["state"], aid2["state"], aid3["state"]]
let states = rstates
op1 = await client1.identifiers().create("multisig",{
icpResult1 = client1.identifiers().create("multisig",{
algo: signify.Algos.group,
mhab: aid1,
isith: 3,
Expand All @@ -144,9 +147,25 @@ async function run() {
states: states,
rstates: rstates
})
op1 = await icpResult1.op()
let serder = icpResult1.serder
let sigs = icpResult1.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 = [aid2["state"], aid3["state"]].map((state) => state['i'])

await client1.exchanges().send("multisig1", "multisig", aid1, "/multisig/icp",
{'gid': serder.pre, smids: smids, rmids: smids}, embeds, recp)
console.log("Multisig1 joined multisig waiting for others...")

op2 = await client2.identifiers().create("multisig",{
icpResult2 = client2.identifiers().create("multisig",{
algo: signify.Algos.group,
mhab: aid2,
isith: 3,
Expand All @@ -159,9 +178,25 @@ async function run() {
states: states,
rstates: rstates
})
op2 = await icpResult2.op()
serder = icpResult2.serder
sigs = icpResult2.sigs
sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}))

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

smids = states.map((state) => state['i'])
recp = [aid1["state"], aid3["state"]].map((state) => state['i'])

await client2.exchanges().send("multisig2", "multisig", aid2, "/multisig/icp",
{'gid': serder.pre, smids: smids, rmids: smids}, embeds, recp)
console.log("Multisig2 joined multisig waiting for others...")

op3 = await client3.identifiers().create("multisig",{
icpResult3 = client3.identifiers().create("multisig",{
algo: signify.Algos.group,
mhab: aid3,
isith: 3,
Expand All @@ -174,6 +209,22 @@ async function run() {
states: states,
rstates: rstates
})
op3 = await icpResult3.op()
serder = icpResult3.serder
sigs = icpResult3.sigs
sigers = sigs.map((sig: any) => new signify.Siger({qb64: sig}))

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

smids = states.map((state) => state['i'])
recp = [aid1["state"], aid2["state"]].map((state) => state['i'])

await client3.exchanges().send("multisig3", "multisig", aid3, "/multisig/icp",
{'gid': serder.pre, smids: smids, rmids: smids}, embeds, recp)
console.log("Multisig3 joined multisig waiting for others...")

while (!op1["done"]) {
Expand Down
4 changes: 1 addition & 3 deletions src/keri/app/signify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,6 @@ export class Registries {
let keeper = this.client!.manager!.get(hab)
data[keeper.algo] = keeper.params()

console.log(data)

let res = await this.client.fetch(path, method, data)
return await res.json()
}
Expand Down Expand Up @@ -1921,7 +1919,7 @@ export class Exchanges {
}

/**
* Send exn messaget to list of recipients
* Create exn message
* @async
* @returns {Promise<any>} A promise to the list of replay messages
* @param sender
Expand Down

0 comments on commit 85032ee

Please sign in to comment.