Skip to content

Commit

Permalink
fix: last step fix
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Javier Ribo Labrador <elribonazo@gmail.com>
  • Loading branch information
elribonazo committed Nov 13, 2024
1 parent c2302cd commit fb1d35b
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions demos/next-sdjwt-workshop/src/steps/Step6.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
sha512
} from '@noble/hashes/sha512'
import InMemory from '@pluto-encrypted/inmemory'
class ShortFormDIDResolverSample {
method = "prism";
Expand Down Expand Up @@ -110,20 +109,25 @@ class ShortFormDIDResolverSample {
}
}
async function wait(callback) {
const start = Date.now()
return new Promise(async (resolve, reject) => {
const interval = setInterval(async () => {
let result = await callback()
if (result) {
clearInterval(interval)
resolve("")
}
if (Date.now() - start > 30 * 1000) {
reject("timeout")
}
}, 1000)
})
async function verifyCondition(callback) {
try {
const start = Date.now()
await new Promise(async (resolve, reject) => {
const interval = setInterval(async () => {
let result = await callback()
if (result) {
clearInterval(interval)
resolve("")
}
if (Date.now() - start > 60 * 1000) {
reject("timeout")
}
}, 1000)
})
return true
} catch (e) {
return false
}
}
(async () => {
Expand Down Expand Up @@ -302,19 +306,16 @@ async function wait(callback) {
const requestPresentation = SDK.RequestPresentation.fromMessage(message);
const presentation = await agent.createPresentationForRequestProof(requestPresentation, credential);
await agent.sendMessage(presentation.makeMessage());
try {
await wait(async () => {
const verifyPresentation = await fetch(\`http://localhost:3000/cloud-agent/present-proof/presentations/\${presentationId}\`, {
method: "GET",
headers: { "Content-Type": "application/json" }
});
const verificationResponse = await verifyPresentation.json();
return verificationResponse.status === "PresentationVerified"
})
console.log('Verification Result:', { isValid: true });
} catch (e) {
console.log('Verification Result:', { isValid: false });
}
const verificationResult = await verifyCondition(async () => {
const verifyPresentation = await fetch(\`http://localhost:3000/cloud-agent/present-proof/presentations/\${presentationId}\`, {
method: "GET",
headers: { "Content-Type": "application/json" }
});
const verificationResponse = await verifyPresentation.json();
console.log('Verification Check:', verificationResponse.status)
return verificationResponse.status === "PresentationVerified"
})
console.log('Verification Result:', { isValid: verificationResult });
}
}
}
Expand Down

0 comments on commit fb1d35b

Please sign in to comment.