From 7a8b177b4631e7b3c32668a38edd65b0b908bd9c Mon Sep 17 00:00:00 2001 From: Vincent Emonet Date: Mon, 27 Nov 2023 17:41:58 +0100 Subject: [PATCH] fix demo intro pub --- lib/docs/demo.html | 94 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/docs/demo.html b/lib/docs/demo.html index 72ae6f6..0f9ee8d 100644 --- a/lib/docs/demo.html +++ b/lib/docs/demo.html @@ -116,59 +116,59 @@

Nanopublication signing demo

const rdfOutput = document.getElementById('rdf-output'); // Sign nanopub - document.getElementById('submit-btn').addEventListener('click', (event) => { + document.getElementById('submit-btn').addEventListener('click', async (event) => { + // WebAssembly binary needs to be initialized + await init() const rdfStr = rdfInput.textContent const privKey = document.getElementById('private-key').value - // WebAssembly binary needs to be initialized. In async functions you can use "await init();" - init().then(() => { - console.log("Random Nanopub server:", getNpServer()); - const profile = new NpProfile(orcid, "Your Name", privKey, ""); - try { - const checked = Nanopub.check(rdfStr); - console.log("CHECKED", checked.toJs()); - - const np = Nanopub.sign(rdfStr, profile) - rdfOutput.textContent = np.get_rdf(); - console.log("Signed Nanopub:", np.toString()); - hljs.highlightAll(); - } catch (error) { - rdfOutput.textContent = error.toString(); - console.error("Error:", error); - } - - // Nanopub.publish(rdfStr, profile, "") - // .then(np => { - // rdfOutput.textContent = np.get_rdf(); - // console.log("Published Nanopub:", np.toString()); - // }) - // .catch(error => { - // rdfOutput.textContent = error; - // console.error("Publishing error:", error); - // }); - }); + console.log("Random Nanopub server:", getNpServer()); + const profile = new NpProfile(orcid, "Your Name", privKey, ""); + try { + const checked = Nanopub.check(rdfStr); + console.log("CHECKED", checked.toJs()); + + const np = Nanopub.sign(rdfStr, profile) + rdfOutput.textContent = np.get_rdf(); + console.log("Signed Nanopub:", np.toString()); + hljs.highlightAll(); + } catch (error) { + rdfOutput.textContent = error.toString(); + console.error("Error:", error); + } + + // Nanopub.publish(rdfStr, profile, "") + // .then(np => { + // rdfOutput.textContent = np.get_rdf(); + // console.log("Published Nanopub:", np.toString()); + // }) + // .catch(error => { + // rdfOutput.textContent = error; + // console.error("Publishing error:", error); + // }); }); // Generate key pair and publish Nanopub intro const introBtn = document.getElementById('publish-intro-btn') - introBtn.addEventListener('click', (event) => { - init().then(() => { - const keypair = new KeyPair() - const profile = new NpProfile(orcidToken.orcid, orcidToken.fullName, keypair.private, ""); - // Publish nanopub link to public key - const intro = Nanopub.publish_intro(profile, getNpServer(false)) - .then(np => { - rdfOutput.textContent = np.get_rdf(); - console.log("Published Introduction Nanopub:", np.toString()); - // Display private key - document.getElementById("privkey-card").classList.remove("hidden"); - document.getElementById("display-privkey").textContent = keypair.private - hljs.highlightAll(); - }) - .catch(error => { - rdfOutput.textContent = error; - console.error("Publishing error:", error); - }); - }); + introBtn.addEventListener('click', async (event) => { + await init() + let keypair = new KeyPair() + keypair = keypair.toJs() + console.log("PUB INTRO", orcidToken, keypair.private) + const profile = new NpProfile(orcidToken.orcid, orcidToken.fullName, keypair.private, ""); + // Publish nanopub link to public key + const intro = Nanopub.publish_intro(profile, getNpServer(false)) + .then(np => { + rdfOutput.textContent = np.get_rdf(); + console.log("Published Introduction Nanopub:", np.toString()); + // Display private key + document.getElementById("privkey-card").classList.remove("hidden"); + document.getElementById("display-privkey").textContent = keypair.private + hljs.highlightAll(); + }) + .catch(error => { + rdfOutput.textContent = error; + console.error("Publishing error:", error); + }); }); // Setup ORCID login https://github.com/ORCID/orcid-openid-examples/blob/master/js-widget/readme.md