Skip to content

Commit

Permalink
Merge pull request #53 from cardano-foundation/contacts
Browse files Browse the repository at this point in the history
Add Contacts, Credentials, and fix Challenge Response
  • Loading branch information
rodolfomiranda authored Jun 27, 2023
2 parents 78af834 + 1e36ffb commit 56e0def
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 46 deletions.
Empty file.
76 changes: 56 additions & 20 deletions examples/signify-react-ts/src/test_components/Challenges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { SignifyClient, ready, Serder, Diger, MtrDex, CredentialTypes } from "si
import { strict as assert } from "assert";
import { useState, useEffect } from 'react';


export function Challenges() {
const [testResult, setTestResult] = useState('');
useEffect(() => {
Expand All @@ -23,34 +22,71 @@ export function Challenges() {
const bran1 = '0123456789abcdefghijk'
const bran2 = '1123456789abcdefghijk'
const client1 = new SignifyClient(url, bran1)
// await client1.boot()
await client1.boot()
await client1.connect()
const identifiers1 = client1.identifiers()
let challenges1 = client1.challenges()
let challenge1_small = await challenges1.get_challenge(128)
const operations1 = client1.operations()
const oobis1 = client1.oobis()
const contacts1 = client1.contacts()
const challenges1 = client1.challenges()
const notifications1 = client1.notifications()
let challenge1_small = await challenges1.generate_challenge(128)
assert.equal(challenge1_small.words.length, 12)
let challenge1_big = await challenges1.get_challenge(256)
let challenge1_big = await challenges1.generate_challenge(256)
assert.equal(challenge1_big.words.length, 24)
let op1 = await identifiers1.create('alex', {})
let aid1 = op1['response']
let op1 = await identifiers1.create('alex', {
toad: 2,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
while (!op1["done"] ) {
op1 = await operations1.get(op1["name"]);
await new Promise(resolve => setTimeout(resolve, 1000)); // sleep for 1 second
}
const aid1 = op1['response']

const client2 = new SignifyClient(url, bran2)
// await client2.boot()
await client2.boot()
await client2.connect()
const identifiers2 = client2.identifiers()
const challenges2 = client2.challenges()
let op2 = await identifiers2.create('rodo', {})
let aid2 = op2['response']
console.log(aid2)


let challenge_to_send = await challenges1.send_challenge('alex', aid2.d, challenge1_small)
console.log(challenge_to_send)
await setTimeout(() => { }, 3000)//TODO: better way of checking if the challenge was received

let challenge_to_receive = await challenges2.accept_challenge('rodo', aid1.d, challenge_to_send.d)
console.log(challenge_to_receive)
assert.equal(challenge_to_receive.status,202)
const operations2 = client2.operations()
const oobis2 = client2.oobis()
let op2 = await identifiers2.create('rodo', {
toad: 2,
wits: [
"BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha",
"BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM",
"BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]
})
while (!op2["done"] ) {
op2 = await operations2.get(op2["name"]);
await new Promise(resolve => setTimeout(resolve, 1000)); // sleep for 1 second
}
const aid2 = op2['response']

await identifiers1.addEndRole("alex", 'agent', client1!.agent!.pre)
await identifiers2.addEndRole("rodo", 'agent', client2!.agent!.pre)

op1 = await oobis1.resolve("http://127.0.0.1:5642/oobi/"+aid2.i+"/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha","rodo")
while (!op1["done"]) {
op1 = await operations1.get(op1["name"]);
await new Promise(resolve => setTimeout(resolve, 1000)); // sleep for 1 second
}
await contacts1.add_contact(aid2.i,{alias: "rodo"})
op2 = await oobis2.resolve("http://127.0.0.1:5642/oobi/"+aid1.i+"/witness","alex")
while (!op2["done"]) {
op2 = await operations2.get(op2["name"]);
await new Promise(resolve => setTimeout(resolve, 1000)); // sleep for 1 second
}
await contacts1.list_contacts(undefined, undefined, undefined)
await challenges2.respond_challenge('rodo', aid1.i, challenge1_small.words)
// await challenges1.accept_challenge_response('alex', said)
await contacts1.list_contacts(undefined, undefined, undefined)
await new Promise(resolve => setTimeout(resolve, 10000));
await notifications1.list_notifications(undefined, undefined)
setTestResult("Passed")
}
catch (e) {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './keri/core/serder'
export * from './keri/core/diger'
export * from './keri/app/habery'
export * from './keri/app/signify'
export * from './keri/app/apping';

import { Buffer } from 'buffer';

Expand Down
Loading

0 comments on commit 56e0def

Please sign in to comment.