From 361fbbb314fc414241d06d2a1457f6ae32e0a4f3 Mon Sep 17 00:00:00 2001 From: chris-bes Date: Fri, 1 Dec 2023 02:10:02 +1100 Subject: [PATCH] test --- package.json | 1 + src/components/Main.js | 19 +++++++++++++++++-- yarn.lock | 12 +++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0f58c54..0f664a1 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "date-fns": "^2.22.1", "file-saver": "^2.0.5", "html-react-parser": "^1.2.8", + "jose": "^5.1.2", "jsoneditor": "^9.10.4", "prettier": "^2.3.1", "prop-types": "^15.7.2", diff --git a/src/components/Main.js b/src/components/Main.js index 14f4295..5710333 100644 --- a/src/components/Main.js +++ b/src/components/Main.js @@ -1,17 +1,25 @@ import React, { useEffect, useState } from "react"; - +import * as jose from "jose"; import { IPSResult } from "./IPSResult"; import { IPSForm } from "./IPSForm"; import { useIPS } from "../api/useIPS"; import { LoadingIndicator } from "./LoadingIndicator"; +async function decryptData(key, encryptedData) { + const decrypter = await jose.JWE.createDecrypt(key); + const decrypted = await decrypter.decrypt(encryptedData); + + console.log("decrypted", decrypted); + return decrypted; +} + export const Main = () => { const [hasPayloadError, setHasPayloadError] = useState(false); const [validated, setValidated] = useState(false); const [payload, setPayload] = useState(null); const hash = window.location.hash; - const payloadBase64 = hash.replace('#shlink:/', ''); + const payloadBase64 = hash.replace("#shlink:/", ""); const { data: ipsPayload, @@ -32,6 +40,13 @@ export const Main = () => { } }, [payloadBase64]); + useEffect(() => { + if (ipsPayload) { + console.log('payload', payload); + decryptData(payload.key, ipsPayload); + } + }, [ipsPayload]); + if (isLoading) { return ; } diff --git a/yarn.lock b/yarn.lock index df690e2..a2faf85 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2335,13 +2335,6 @@ react-is "^16.8.0 || ^17.0.0" react-transition-group "^4.4.0" -"@material-ui/icons@^4.11.2": - version "4.11.3" - resolved "https://registry.yarnpkg.com/@material-ui/icons/-/icons-4.11.3.tgz#b0693709f9b161ce9ccde276a770d968484ecff1" - integrity sha512-IKHlyx6LDh8n19vzwH5RtHIOHl9Tu90aAAxcbWME6kp4dmvODM3UvOHJeMIDzUbd4muuJKHmlNoBN+mDY4XkBA== - dependencies: - "@babel/runtime" "^7.4.4" - "@material-ui/lab@^4.0.0-alpha.56": version "4.0.0-alpha.61" resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.61.tgz#9bf8eb389c0c26c15e40933cc114d4ad85e3d978" @@ -7466,6 +7459,11 @@ jmespath@^0.16.0: resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.16.0.tgz#b15b0a85dfd4d930d43e69ed605943c802785076" integrity sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw== +jose@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/jose/-/jose-5.1.2.tgz#f71a18e3ee779c2d81778e1b6f0d85062ccd9ee1" + integrity sha512-X7TOC/d8KPvx4wPUuLHVgTSdoWw0UW5TQOUwhvCvj+ZPfsf9vUPhhksYPjNBWVGPQ/6yd/JrL1gQxBnIDwYdFg== + js-sha3@0.8.0: version "0.8.0" resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"