Skip to content

Commit

Permalink
Merge branch 'main' into passcode_new
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndrei98 authored Jul 25, 2023
2 parents 3c86dbc + 4989c06 commit 85548a6
Show file tree
Hide file tree
Showing 33 changed files with 3,109 additions and 458 deletions.
17 changes: 17 additions & 0 deletions examples/integration-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This folder contains scripts intended to test the integration between [signify-ts](https://github.com/WebOfTrust/signify-ts) and [keria](https://github.com/weboftrust/keria). The scripts execute basic KERI functionalities and may be helpful examples to implementors.

Each script should be executed with:
`ts-node --esm script_name.ts`

and requires [keria](https://github.com/weboftrust/keria) to be installed and running with:
`keria start --config-file demo-witness-oobis.json --config-dir ./scripts`

If the script depends on witnesses, you need to have [keripy](https://github.com/WebOfTrust/keripy) installed and running with:
`kli witness demo`

Additionally, if the script also depends on schemas you need to have [vLEI server](https://github.com/WebOfTrust/vLEI) installed and running with:
`vLEI-server -s ./schema/acdc -c ./samples/acdc/ -o ./samples/oobis/`

You can also execute all script the scrip:
`run_all.sh`

117 changes: 117 additions & 0 deletions examples/integration-scripts/challenge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { strict as assert } from "assert";

let signify: any;
const url = "http://127.0.0.1:3901"
const boot_url = "http://127.0.0.1:3903"

// @ts-ignore
import('signify-ts').then(
(module) => {
signify = module
signify.ready().then(() => {
console.log("*** Starting CHALLENGE test ***");
run().then(() => {
console.log("*** Test complete ***")
});
});
}
)

async function run() {

// Boot two clients
const bran1 = signify.randomPasscode()
const bran2 = signify.randomPasscode()
const client1 = new signify.SignifyClient(url, bran1, signify.Tier.low, boot_url);
const client2 = new signify.SignifyClient(url, bran2, signify.Tier.low, boot_url);
await client1.boot()
await client2.boot()
await client1.connect()
await client2.connect()
const state1 = await client1.state()
const state2 = await client2.state()
console.log("Client 1 connected. Client AID:",state1.controller.state.i,"Agent AID: ", state1.agent.i)
console.log("Client 2 connected. Client AID:",state2.controller.state.i,"Agent AID: ", state2.agent.i)

// Generate challenge words
const challenge1_small = await client1.challenges().generate(128)
assert.equal(challenge1_small.words.length, 12)
const challenge1_big = await client1.challenges().generate(256)
assert.equal(challenge1_big.words.length, 24)

// Create two identifiers, one for each client
let op1 = await client1.identifiers().create('alice', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
while (!op1["done"] ) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
const aid1 = op1['response']
await client1.identifiers().addEndRole("alice", 'agent', client1!.agent!.pre)
console.log("Alice's AID:", aid1.i)

let op2 = await client2.identifiers().create('bob', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
while (!op2["done"] ) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
const aid2 = op2['response']
await client2.identifiers().addEndRole("bob", 'agent', client2!.agent!.pre)
console.log("Bob's AID:", aid2.i)

// Exchenge OOBIs
let oobi1 = await client1.oobis().get("alice","agent")
let oobi2 = await client2.oobis().get("bob","agent")

op1 = await client1.oobis().resolve(oobi2.oobis[0],"bob")
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log("Client 1 resolved Bob's OOBI")
op2 = await client2.oobis().resolve(oobi1.oobis[0],"alice")
while (!op2["done"]) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log("Client 2 resolved Alice's OOBI")

// List Client 1 contacts
let contacts1 = await client1.contacts().list()
assert.equal(contacts1.length,1)
assert.equal(contacts1[0].alias,'bob')

// Bob responds to Alice challenge
await client2.challenges().respond('bob', aid1.i, challenge1_small.words)
console.log("Bob responded to Alice challenge with signed words")

// Alice check response, compare challenge words and accept the challenge
let challenge_received = false
let contacts:any = []
while (!challenge_received) {
contacts = await client1.contacts().list(undefined, undefined, undefined)
if (contacts[0].challenges.length > 0 ){
assert.equal(JSON.stringify(contacts[0].challenges[0].words), JSON.stringify(challenge1_small.words))
challenge_received = true
}
await new Promise(resolve => setTimeout(resolve, 1000)); // sleep for 1 second
}
await client1.challenges().accept('alice', aid2.i, contacts[0].challenges[0].said)

// Check Bob's challenge in conctats
contacts1 = await client1.contacts().list()
assert.equal(contacts1[0].challenges[0].authenticated, true)
console.log("Challenge authenticated")

}
237 changes: 237 additions & 0 deletions examples/integration-scripts/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
import { strict as assert } from "assert";

let signify: any;
const url = "http://127.0.0.1:3901"
const boot_url = "http://127.0.0.1:3903"

// @ts-ignore
import('signify-ts').then(
(module) => {
signify = module
signify.ready().then(() => {
console.log("*** Starting CREDENTIALS test ***");
run().then(() => {
console.log("*** Test complete ***")
});
});
}
)

async function run() {

// Boot three clients
const bran1 = signify.randomPasscode()
const bran2 = signify.randomPasscode()
const bran3 = signify.randomPasscode()
const client1 = new signify.SignifyClient(url, bran1, signify.Tier.low, boot_url);
const client2 = new signify.SignifyClient(url, bran2, signify.Tier.low, boot_url);
const client3 = new signify.SignifyClient(url, bran3, signify.Tier.low, boot_url);
await client1.boot()
await client2.boot()
await client3.boot()
await client1.connect()
await client2.connect()
await client3.connect()
const state1 = await client1.state()
const state2 = await client2.state()
const state3 = await client3.state()
console.log("Client 1 connected. Client AID:",state1.controller.state.i,"Agent AID: ", state1.agent.i)
console.log("Client 2 connected. Client AID:",state2.controller.state.i,"Agent AID: ", state2.agent.i)
console.log("Client 3 connected. Client AID:",state3.controller.state.i,"Agent AID: ", state3.agent.i)


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

let op2 = await client2.identifiers().create('recipient', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
while (!op2["done"] ) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
const aid2 = await client2.identifiers().get("recipient")
await client2.identifiers().addEndRole("recipient", 'agent', client2!.agent!.pre)
console.log("Recipient's AID:", aid2.prefix)

let op3 = await client3.identifiers().create('verifier', {
toad: 3,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
while (!op3["done"] ) {
op3 = await client3.operations().get(op3.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
const aid3 = await client3.identifiers().get("verifier")
await client3.identifiers().addEndRole("verifier", 'agent', client3!.agent!.pre)
console.log("Verifier's AID:", aid3.prefix)

const schemaSAID = "EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao"

// Exchenge OOBIs
console.log("Resolving OOBIs...")
let oobi1 = await client1.oobis().get("issuer","agent")
let oobi2 = await client2.oobis().get("recipient","agent")
let oobi3 = await client3.oobis().get("verifier","agent")
let schemaOobi = "http://127.0.0.1:7723/oobi/" + schemaSAID

op1 = await client1.oobis().resolve(oobi2.oobis[0],"recipient")
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
op1 = await client1.oobis().resolve(oobi3.oobis[0],"verifier")
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
op1 = await client1.oobis().resolve(schemaOobi,"schema")
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log("Issuer resolved 3 OOBIs")

op2 = await client2.oobis().resolve(oobi1.oobis[0],"issuer")
while (!op2["done"]) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
op2 = await client2.oobis().resolve(oobi3.oobis[0],"verifier")
while (!op2["done"]) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
op2 = await client2.oobis().resolve(schemaOobi,"schema")
while (!op2["done"]) {
op2 = await client2.operations().get(op2.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log("Recipient resolved 3 OOBIs")

op3 = await client3.oobis().resolve(oobi1.oobis[0],"issuer")
while (!op3["done"]) {
op3 = await client3.operations().get(op3.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
op3 = await client3.oobis().resolve(oobi2.oobis[0],"recipient")
while (!op3["done"]) {
op3 = await client3.operations().get(op3.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
op3 = await client3.oobis().resolve(schemaOobi,"schema")
while (!op3["done"]) {
op3 = await client3.operations().get(op3.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log("Verifier resolved 3 OOBIs")

// Create registry for issuer
op1 = await client1.registries().create('issuer','vLEI')
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
let registries = await client1.registries().list('issuer')
assert.equal(registries.length, 1)
assert.equal(registries[0].name, 'vLEI')
let schema = await client1.schemas().get(schemaSAID)
assert.equal(schema.$id, schemaSAID)
let schemas = await client2.schemas().list()
assert.equal(schemas.length, 1)
assert.equal(schemas[0].$id, schemaSAID)
console.log("Registry created")

// Issue credential
const vcdata = {
"LEI": "5493001KJTIIGC8Y1R17"
}
op1 = await client1.credentials().issue('issuer',registries[0].regk, schemaSAID,aid2.prefix,vcdata)
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
let creds1 = await client1.credentials().list('issuer')
assert.equal(creds1.length, 1)
assert.equal(creds1[0].sad.s, schemaSAID)
assert.equal(creds1[0].sad.i, aid1.prefix)
assert.equal(creds1[0].status.s, "0") // 0 = issued
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
console.log("Credential received by recipient")

// Present credential
await client1.credentials().present('issuer', creds1[0].sad.d, 'verifier', true)
await new Promise(resolve => setTimeout(resolve, 5000))
let creds3 = await client3.credentials().list('verifier')
assert.equal(creds3.length, 1)
assert.equal(creds3[0].sad.s, schemaSAID)
assert.equal(creds3[0].sad.i, aid1.prefix)
assert.equal(creds3[0].status.s, "0") // 0 = issued
console.log("Credential presented and received by verifier")

// Revoke credential
op1 = await client1.credentials().revoke('issuer', creds1[0].sad.d)
while (!op1["done"]) {
op1 = await client1.operations().get(op1.name);
await new Promise(resolve => setTimeout(resolve, 1000));
}
creds1 = await client1.credentials().list('issuer')
assert.equal(creds1.length, 1)
assert.equal(creds1[0].sad.s, schemaSAID)
assert.equal(creds1[0].sad.i, aid1.prefix)
assert.equal(creds1[0].status.s, "1") // 1 = revoked
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")

// Present revoked credential
await client1.credentials().present('issuer', creds1[0].sad.d, 'verifier', true)
await new Promise(resolve => setTimeout(resolve, 5000))
creds3 = await client3.credentials().list('verifier')
assert.equal(creds3.length, 1)
assert.equal(creds3[0].sad.s, schemaSAID)
assert.equal(creds3[0].sad.i, aid1.prefix)
assert.equal(creds3[0].status.s, "1") // 1 = revoked
console.log("Revocation presented and received by verifier")

}
Loading

0 comments on commit 85548a6

Please sign in to comment.