feat(opentimestamps): adds timestamps to create flow

This commit is contained in:
eugene 2024-09-26 15:54:06 +03:00
parent edfe9a2954
commit 85bcfac2e0
3 changed files with 31 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -119,3 +119,15 @@ export const settleAllFullfilfedPromises = async <Item, FulfilledItem = Item>(
return acc
}, [])
}
export const isPromiseFulfilled = <T>(
result: PromiseSettledResult<T>
): result is PromiseFulfilledResult<T> => {
return result.status === 'fulfilled'
}
export const isPromiseRejected = <T>(
result: PromiseSettledResult<T>
): result is PromiseRejectedResult => {
return result.status === 'rejected'
}