diff --git a/src/lib/GoogleAuth.svelte b/src/lib/GoogleAuth.svelte index 5963462..8976add 100644 --- a/src/lib/GoogleAuth.svelte +++ b/src/lib/GoogleAuth.svelte @@ -8,23 +8,19 @@ import Icon from "@iconify/svelte"; import { createLitSession } from "./createLitSession"; import { connectProvider } from "./setupLit"; - import { ethers } from "ethers"; - import Signer from "./Signer.svelte"; const redirectUri = "http://localhost:3000/"; let sessionSigs = null; let litNodeClient, error, currentPKP, authMethod, provider; - let messageToSign = { user: "Sam", loggedIn: true }; let status = "Initializing..."; - let jsonObjectToVerify = null; let pkps: IRelayPKP[] = []; let view = "SIGN_IN"; let sessionSigsObject; onMount(async () => { - litNodeClient = new LitNodeClient({ litNetwork: "serrano" }); - await litNodeClient.connect(); + // litNodeClient = new LitNodeClient({ litNetwork: "serrano" }); + // await litNodeClient.connect(); const sessionSigsLocalStorage = localStorage.getItem("google-signature"); const currentPKPLocalStorage = localStorage.getItem("current-pkp"); if (sessionSigsLocalStorage && currentPKPLocalStorage) { @@ -33,7 +29,6 @@ } else { initialize(); } - if (sessionSigsLocalStorage) { sessionSigsObject = JSON.parse(sessionSigsLocalStorage); } @@ -118,66 +113,6 @@ view = "ERROR"; status = `Error: ${err.message}`; } - - async function signMessageWithPKP() { - try { - // Create a specific JSON object - const jsonString = JSON.stringify(messageToSign); - - // Convert the JSON string to an array of character codes - const toSign = ethers.getBytes(ethers.hashMessage(jsonString)); - - const litActionCode = ` - const go = async () => { - const sigShare = await LitActions.signEcdsa({ toSign, publicKey, sigName }); - }; - go(); - `; - - // Sign message - const results = await litNodeClient.executeJs({ - code: litActionCode, - sessionSigs: sessionSigs, - jsParams: { - toSign: toSign, - publicKey: currentPKP.publicKey, - sigName: "sig1", - }, - }); - - // Get signature - const result = results.signatures["sig1"]; - const signature = ethers.Signature.from({ - r: "0x" + result.r, - s: "0x" + result.s, - v: result.recid, - }); - - // Add the signature to the JSON object - messageToSign.signature = signature; - - jsonObjectToVerify = { ...messageToSign }; - - // Display the signed JSON - status = JSON.stringify(messageToSign, null, 2); - - // Verify the signature - const recoveredAddr = ethers.verifyMessage(jsonString, signature); - - // 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."; - } - } catch (err) { - console.error(err); - setError(err); - } - }
{currentPKP.ethAddress}
-{status}
{JSON.stringify(messageToSign)}{/if} + +{#if status} +
Status: {status}
+{JSON.stringify(messageSignature)}+