Skip to content

Commit

Permalink
Merge pull request #101 from roots-id/adapt_scripts
Browse files Browse the repository at this point in the history
Adapting integration scripts to latest changes in KERIA
  • Loading branch information
AlexAndrei98 authored Sep 6, 2023
2 parents b4fbdd3 + 85032ee commit 594610e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 37 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
6 changes: 4 additions & 2 deletions examples/integration-scripts/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ async function run() {
console.log("Client 2 connected. Client AID:",state2.controller.state.i,"Agent AID: ", state2.agent.i)

// Client 1 create delegator AID
let op1 = await client1.identifiers().create('delegator',{
let icpResult1 = await client1.identifiers().create('delegator',{
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 @@ -60,7 +61,8 @@ async function run() {
console.log("OOBI resolved")

// Client 2 creates delegate AID
op2 = await client2.identifiers().create('delegate',{delpre: aid1.prefix})
let icpResult2 = await client2.identifiers().create('delegate',{delpre: aid1.prefix})
op2 = await icpResult2.op()
let delegatePrefix = op2.name.split(".")[1]
console.log("Delegate's prefix:", delegatePrefix)
console.log("Delegate waiting for approval...")
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
3 changes: 2 additions & 1 deletion examples/integration-scripts/randy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async function run() {
const state1 = await client1.state()
console.log("Client 1 connected. Client AID:",state1.controller.state.i,"Agent AID: ", state1.agent.i)

let op = await client1.identifiers().create('aid1', {algo: signify.Algos.randy})
let icpResult = client1.identifiers().create('aid1', {algo: signify.Algos.randy})
let op = await icpResult.op()
assert.equal(op['done'], true)
let aid = op['response']
const icp = new signify.Serder(aid)
Expand Down
6 changes: 4 additions & 2 deletions examples/integration-scripts/salty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async function run() {
const state1 = await client1.state()
console.log("Client 1 connected. Client AID:",state1.controller.state.i,"Agent AID: ", state1.agent.i)

let op = await client1.identifiers().create('aid1', {bran: '0123456789abcdefghijk'})
let icpResult = client1.identifiers().create('aid1', {bran: '0123456789abcdefghijk'})
let op = await icpResult.op()
assert.equal(op['done'], true)
const aid1 = op['response']
const icp = new signify.Serder(aid1)
Expand All @@ -47,7 +48,8 @@ async function run() {
assert.equal(salt.stem, 'signify:aid')
assert.equal(aid.prefix, icp.pre)

op = await client1.identifiers().create('aid2', {count:3, ncount:3, isith:"2", nsith:"2", bran:"0123456789lmnopqrstuv"})
icpResult = client1.identifiers().create('aid2', {count:3, ncount:3, isith:"2", nsith:"2", bran:"0123456789lmnopqrstuv"})
op = await icpResult.op()
assert.equal(op['done'], true)
const aid2 = op['response']
const icp2 = new signify.Serder(aid2)
Expand Down
3 changes: 2 additions & 1 deletion examples/integration-scripts/witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ async function run() {
console.log("Witness OOBI resolved")

// Client 1 creates AID with 1 witness
op1 = await client1.identifiers().create('aid1',{
let icpResult1 = await client1.identifiers().create('aid1',{
toad: 1,
wits: ["BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha"]
})
op1 = await icpResult1.op()
while (!op1["done"] ) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
Expand Down
6 changes: 2 additions & 4 deletions src/keri/app/signify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export class Identifier {
* @async
* @param {string} name Name or alias of the identifier
* @param {CreateIdentiferArgs} [kargs] Optional parameters to create the identifier
* @returns {Promise<any>} A promise to the long-running operation
* @returns {InceptionResult} The inception result
*/
create(name: string, kargs:CreateIdentiferArgs={}): InceptionResult {

Expand Down 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 594610e

Please sign in to comment.