diff --git a/package.json b/package.json index 22fa993..179d478 100644 --- a/package.json +++ b/package.json @@ -13,20 +13,22 @@ "@chakra-ui/react": "^2.8.2", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@lit-protocol/constants": "2.2.62", - "@lit-protocol/lit-node-client": "2.2.62", + "@lit-protocol/auth-helpers": "^5.1.0", + "@lit-protocol/constants": "^5.1.0", + "@lit-protocol/contracts-sdk": "^5.1.0", + "@lit-protocol/lit-node-client": "^5.1.0", "framer-motion": "^11.2.4", - "react": "^18", - "react-dom": "^18", "next": "^13", - "pino-pretty": "^11.0.0" + "pino-pretty": "^11.0.0", + "react": "^18", + "react-dom": "^18" }, "devDependencies": { - "typescript": "^5", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8", - "eslint-config-next": "^13" + "eslint-config-next": "^13", + "typescript": "^5" } } diff --git a/src/app/page.tsx b/src/app/page.tsx index 5251b18..35b143f 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -4,55 +4,57 @@ import { Button, HStack, Heading, Input, Text, Textarea, VStack } from "@chakra- import { LitNodeClient } from "@lit-protocol/lit-node-client"; import { useCallback, useEffect, useState } from "react"; import { Radio, RadioGroup } from '@chakra-ui/react' +import * as LitJsSdk from "@lit-protocol/lit-node-client"; +import { LitNetwork } from "@lit-protocol/constants"; export default function Home() { - const [litNetwork, setLitNetwork] = useState<"serrano" | "jalapeno">("jalapeno"); + const [litNetwork, setLitNetwork] = useState(LitNetwork.Cayenne); const [client, setClient] = useState(); const [message, setMessage] = useState("Hello World"); + const [nonce, setNonce] = useState(new Date().toISOString()); const [error, setError] = useState(""); - const [encryptionResult, setEncryptionResult] = useState<{ - encryptedString: Blob; - encryptedSymmetricKey: string; - }>(); - - const [decryptionResult, setDecryptionResult] = useState<{ - decryptedString: string; - }>(); + const [encryptionResult, setEncryptionResult] = useState<{ ciphertext: string, dataToEncryptHash: string }>(); + const [decryptionResult, setDecryptionResult] = useState(); useEffect(() => { - setClient(undefined) - const _client = new LitNodeClient({ - litNetwork, - debug: true, - }); - _client.connect().then(() => { + (async() => { + setClient(undefined) + const _client = new LitNodeClient({ + litNetwork, + debug: true, + }); + //https://developer.litprotocol.com/v3/sdk/installation#sdk-installed-for-client-side-usage + await _client.disconnect(); + await _client.connect() setClient(_client); - }); + const nonce = await _client.getLatestBlockhash(); + setNonce(nonce) + })(); }, [litNetwork]); const handleEncrypt = useCallback(async () => { if (!client) throw new Error("No client"); try { - const res = await encrypt(client, message); + const res = await encrypt(client, message, nonce); setEncryptionResult(res); } catch (error: any) { setError(error.message); } - }, [client]); + }, [client, message, nonce]); const handleDecrypt = useCallback(async () => { if (!client) throw new Error("No client"); try { - if (!encryptionResult?.encryptedSymmetricKey) - throw new Error("No encryptedSymmetricKey"); + if (!encryptionResult?.ciphertext) + throw new Error("No encrypted data"); - const res = await decrypt(client, encryptionResult); - setDecryptionResult(res); + const decryptedString = await decrypt(client, nonce, encryptionResult); + setDecryptionResult(decryptedString); } catch (error: any) { setError(error.message); } - }, [client, encryptionResult]); + }, [client, encryptionResult, nonce]); return ( @@ -63,8 +65,9 @@ export default function Home() { Encrypt Message setLitNetwork(v as typeof litNetwork)} value={litNetwork}> - Jalapeno - Serrano + Cayenne + Manzano + Habenero @@ -73,23 +76,24 @@ export default function Home() { Encrypt String - {encryptionResult?.encryptedSymmetricKey && ( + {encryptionResult?.ciphertext && ( <> Message encrypted -