Skip to content

Instantly share code, notes, and snippets.

@ilya-korotya
Created May 14, 2024 20:10
Show Gist options
  • Save ilya-korotya/8a4c4567ee63753f550f94b941b32ecc to your computer and use it in GitHub Desktop.
Save ilya-korotya/8a4c4567ee63753f550f94b941b32ecc to your computer and use it in GitHub Desktop.
SynapsInter
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<title>Synaps</title>
</head>
<body style="height: 100vh; width: 100%; display: flex; flex-direction: column; margin: 0; overflow: hidden;">
<main style="height: 100%;">
<div id="synaps-container" style="height: 100%;"></div>
</main>
<script type="module">
import { Synaps } from "https://cdn.synaps.io/sdk/verify.js/4.0.45";
const urlParams = new URLSearchParams(window.location.search);
const session = urlParams.get("session");
const did = urlParams.get("did");
const timeout = 3000;
const callParentHandler = (message) => {
if (window.flutter_inappwebview) {
window.flutter_inappwebview.callHandler("iden3comm", message);
}
if (window.parent) {
window.parent.postMessage({ type: "iden3comm", payload: message }, "*");
}
}
const fetchCredentialOffer = async () => {
const response = await fetch(`${window.location.origin}/offers?sessionID=${session}`);
const message = await response.json();
if (message.type === "https://iden3-communication.io/credentials/1.0/offer") {
const credentials = message.body.credentials;
if (credentials && credentials[0] && credentials[0].status === "pending") {
setTimeout(fetchCredentialOffer, timeout)
} else {
callParentHandler(message);
}
} else {
callParentHandler(message);
}
}
Synaps.init({
mode: "embed",
containerId: "synaps-container",
sessionId: session,
onFinish: async () => {
try {
setTimeout(fetchCredentialOffer, timeout)
} catch (e) {
callParentHandler({
type: "https://didcomm.org/report-problem/2.0/problem-report",
id: 1,
pthid: 1,
body: {
code: "e.p.xfer.resource-not-available",
comment: e.message,
}
});
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment