diff --git a/src/lib/Login.svelte b/src/lib/Login.svelte index 4da3752..238114d 100644 --- a/src/lib/Login.svelte +++ b/src/lib/Login.svelte @@ -2,7 +2,17 @@ import Cookies from "js-cookie"; async function login() { - const response = await fetch("/api/auth", { method: "POST" }); + const response = await fetch("/api/auth", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: "Sam", + loggedIn: true, + roles: ["admin"], + }), + }); if (!response.ok) { alert("Login failed"); } else { diff --git a/src/lib/Signer.svelte b/src/lib/Signer.svelte index 81aaeb1..1ea59bb 100644 --- a/src/lib/Signer.svelte +++ b/src/lib/Signer.svelte @@ -68,63 +68,68 @@ v: result.recid, }); - // Display the signed JSON - status = JSON.stringify(messageToSign, null, 2); - - // Verify the signature - const recoveredAddr = ethers.verifyMessage(jsonString, messageSignature); - - // Check if the address associated with the signature is the same as the current PKP - const verified = - currentPKP.ethAddress.toLowerCase() === recoveredAddr.toLowerCase(); - - if (verified) { - status = "The signature is valid."; - } else { - status = "The signature is invalid."; - } + // verify(); } catch (err) { console.error(err); } } - - async function getJWT() { - var unifiedAccessControlConditions = [ - { - conditionType: "evmBasic", - contractAddress: "", - standardContractType: "", - chain: "xdai", - method: "eth_getBalance", - parameters: [":userAddress", "latest"], - returnValueTest: { - comparator: ">=", - value: "10000000000000", - }, + async function verify() { + const response = await fetch("/api/verify", { + method: "POST", + headers: { + "Content-Type": "application/json", }, - ]; - - // Saving signing condition - await litNodeClient.saveSigningCondition({ - unifiedAccessControlConditions, - sessionSigs, - resourceId: { test: "hello" }, - chain: "litSessionSign", + body: JSON.stringify({ + messageToSign, + messageSignature, + currentPKP, + }), }); - - // Retrieving a signature - let jwt = await litNodeClient.getSignedToken({ - unifiedAccessControlConditions, - sessionSigs, - resourceId: { test: "hello" }, - }); - - alert("JWT: " + jwt); + if (!response.ok) { + alert("verify failed"); + } else { + let json = await response.json(); + alert(json.verified ? "Signature valid" : "! Signature NOT valid !"); + } } + + // async function getJWT() { + // var unifiedAccessControlConditions = [ + // { + // conditionType: "evmBasic", + // contractAddress: "", + // standardContractType: "", + // chain: "xdai", + // method: "eth_getBalance", + // parameters: [":userAddress", "latest"], + // returnValueTest: { + // comparator: ">=", + // value: "10000000000000", + // }, + // }, + // ]; + + // // Saving signing condition + // await litNodeClient.saveSigningCondition({ + // unifiedAccessControlConditions, + // sessionSigs, + // resourceId: { test: "hello" }, + // chain: "litSessionSign", + // }); + + // // Retrieving a signature + // let jwt = await litNodeClient.getSignedToken({ + // unifiedAccessControlConditions, + // sessionSigs, + // resourceId: { test: "hello" }, + // }); + + // alert("JWT: " + jwt); + // } - + {#if messageToSign}
{JSON.stringify(messageToSign)}@@ -140,4 +145,5 @@
{JSON.stringify(messageSignature)}+