From 85bcfac2e0aa8bffaf258c89b5c73b35f108f38b Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 26 Sep 2024 15:54:06 +0300 Subject: [PATCH] feat(opentimestamps): adds timestamps to create flow --- src/pages/create/index.tsx | 15 ++++++++++++--- src/types/core.ts | 7 +++++++ src/utils/utils.ts | 12 ++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 7f39b11..0e9b1ec 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -20,6 +20,7 @@ import { CreateSignatureEventContent, Meta, ProfileMetadata, + Timestamp, User, UserRole } from '../../types' @@ -61,6 +62,7 @@ import { faUpload } from '@fortawesome/free-solid-svg-icons' import { SigitFile } from '../../utils/file.ts' +import { generateTimestamps } from '../../utils/opentimestamps.ts' export const CreatePage = () => { const navigate = useNavigate() @@ -558,7 +560,8 @@ export const CreatePage = () => { fileHashes: { [key: string]: string }, - zipUrl: string + zipUrl: string, + timestamps?: Timestamp[] ) => { const content: CreateSignatureEventContent = { signers: signers.map((signer) => hexToNpub(signer.pubkey)), @@ -566,7 +569,8 @@ export const CreatePage = () => { fileHashes, markConfig, zipUrl, - title + title, + ...(timestamps && { timestamps }) } setLoadingSpinnerDesc('Signing nostr event for create signature') @@ -607,6 +611,10 @@ export const CreatePage = () => { const fileHashes = await generateFileHashes() if (!fileHashes) return + setLoadingSpinnerDesc('Timestamping your files') + const timestamps = await generateTimestamps(Object.values(fileHashes)) + if (!timestamps) return + setLoadingSpinnerDesc('Generating encryption key') const encryptionKey = await generateEncryptionKey() @@ -631,7 +639,8 @@ export const CreatePage = () => { const createSignature = await generateCreateSignature( markConfig, fileHashes, - fileUrl + fileUrl, + timestamps ) if (!createSignature) return diff --git a/src/types/core.ts b/src/types/core.ts index 8583d4a..b4cd18c 100644 --- a/src/types/core.ts +++ b/src/types/core.ts @@ -27,11 +27,13 @@ export interface CreateSignatureEventContent { markConfig: Mark[] title: string zipUrl: string + timestamps?: Timestamp[] } export interface SignedEventContent { prevSig: string marks: Mark[] + timestamps: Timestamp[] } export interface Sigit { @@ -39,6 +41,11 @@ export interface Sigit { meta: Meta } +export interface Timestamp { + fileHash: string + timestamp: string +} + export interface UserAppData { sigits: { [key: string]: Meta } // key will be id of create signature processedGiftWraps: string[] // an array of ids of processed gift wrapped events diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 11053b9..1348642 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -119,3 +119,15 @@ export const settleAllFullfilfedPromises = async ( return acc }, []) } + +export const isPromiseFulfilled = ( + result: PromiseSettledResult +): result is PromiseFulfilledResult => { + return result.status === 'fulfilled' +} + +export const isPromiseRejected = ( + result: PromiseSettledResult +): result is PromiseRejectedResult => { + return result.status === 'rejected' +}