From fff0fd762dc0b3ddde04657207d09c795cdaa341 Mon Sep 17 00:00:00 2001 From: SwiftHawk Date: Mon, 3 Jun 2024 12:13:37 +0500 Subject: [PATCH 1/2] fix: convert npub/nip05 to lowercase on adding as signer/viewer --- src/pages/create/index.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 1a3d207..cc83eaa 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -130,8 +130,10 @@ export const CreatePage = () => { }) } - if (userInput.startsWith('npub')) { - const pubkey = npubToHex(userInput) + const input = userInput.toLowerCase() + + if (input.startsWith('npub')) { + const pubkey = npubToHex(input) if (pubkey) { addUser(pubkey) setUserInput('') @@ -141,12 +143,12 @@ export const CreatePage = () => { return } - if (userInput.includes('@')) { + if (input.includes('@')) { setIsLoading(true) setLoadingSpinnerDesc('Querying for nip05') - const nip05Profile = await queryNip05(userInput) + const nip05Profile = await queryNip05(input) .catch((err) => { - console.error(`error occurred in querying nip05: ${userInput}`, err) + console.error(`error occurred in querying nip05: ${input}`, err) return null }) .finally(() => { From 1f7980e2ca285117a8971a4d5d94ea5b56d15ff7 Mon Sep 17 00:00:00 2001 From: SwiftHawk Date: Mon, 3 Jun 2024 14:01:24 +0500 Subject: [PATCH 2/2] feat: in offline mode navigate creator to sign screen after creation when creator is first signer --- src/pages/create/index.tsx | 15 ++++++++++++--- src/pages/sign/index.tsx | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 1a3d207..54addd2 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -390,9 +390,18 @@ export const CreatePage = () => { )}&key=${encodeURIComponent(encryptionKey)}` ) } else { - saveAs(blob, 'request.sigit') - setTextToCopy(encryptionKey) - setOpenCopyModel(true) + if (signers[0] && signers[0].pubkey === usersPubkey) { + // Create a File object with the Blob data + const file = new File([blob], `compressed.sigit`, { + type: 'application/sigit' + }) + + navigate(appPrivateRoutes.sign, { state: { file, encryptionKey } }) + } else { + saveAs(blob, 'request.sigit') + setTextToCopy(encryptionKey) + setOpenCopyModel(true) + } } } diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index ccbe2ef..4f39a67 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -23,7 +23,7 @@ import { MuiFileInput } from 'mui-file-input' import { Event, kinds, verifyEvent } from 'nostr-tools' import { useEffect, useState } from 'react' import { useSelector } from 'react-redux' -import { useNavigate, useSearchParams } from 'react-router-dom' +import { useNavigate, useSearchParams, useLocation } from 'react-router-dom' import { toast } from 'react-toastify' import { LoadingSpinner } from '../../components/LoadingSpinner' import { UserComponent } from '../../components/username' @@ -69,6 +69,9 @@ enum SignedStatus { export const SignPage = () => { const navigate = useNavigate() + const location = useLocation() + const { file, encryptionKey: encKey } = location.state || {} + const [searchParams, setSearchParams] = useSearchParams() const [displayInput, setDisplayInput] = useState(false) @@ -217,11 +220,23 @@ export const SignPage = () => { .finally(() => { setIsLoading(false) }) + } else if (file && encKey) { + decrypt(file, decodeURIComponent(encKey)) + .then((arrayBuffer) => { + if (arrayBuffer) handleDecryptedArrayBuffer(arrayBuffer) + }) + .catch((err) => { + console.error(`error occurred in decryption`, err) + toast.error(err.message || `error occurred in decryption`) + }) + .finally(() => { + setIsLoading(false) + }) } else { setIsLoading(false) setDisplayInput(true) } - }, [searchParams]) + }, [searchParams, file, encKey]) const decrypt = async (file: File, key: string) => { setLoadingSpinnerDesc('Decrypting file')