issue-166-open-timestamps #220

Merged
eugene merged 25 commits from issue-166-open-timestamps into staging 2024-10-25 11:18:47 +00:00
3 changed files with 31 additions and 3 deletions
Showing only changes of commit 85bcfac2e0 - Show all commits

View File

@ -20,6 +20,7 @@ import {
CreateSignatureEventContent, CreateSignatureEventContent,
Meta, Meta,
ProfileMetadata, ProfileMetadata,
Timestamp,
User, User,
UserRole UserRole
} from '../../types' } from '../../types'
@ -61,6 +62,7 @@ import {
faUpload faUpload
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
import { SigitFile } from '../../utils/file.ts' import { SigitFile } from '../../utils/file.ts'
import { generateTimestamps } from '../../utils/opentimestamps.ts'
export const CreatePage = () => { export const CreatePage = () => {
const navigate = useNavigate() const navigate = useNavigate()
@ -558,7 +560,8 @@ export const CreatePage = () => {
fileHashes: { fileHashes: {
[key: string]: string [key: string]: string
}, },
zipUrl: string zipUrl: string,
timestamps?: Timestamp[]
) => { ) => {
const content: CreateSignatureEventContent = { const content: CreateSignatureEventContent = {
signers: signers.map((signer) => hexToNpub(signer.pubkey)), signers: signers.map((signer) => hexToNpub(signer.pubkey)),
@ -566,7 +569,8 @@ export const CreatePage = () => {
fileHashes, fileHashes,
markConfig, markConfig,
zipUrl, zipUrl,
title title,
...(timestamps && { timestamps })
} }
setLoadingSpinnerDesc('Signing nostr event for create signature') setLoadingSpinnerDesc('Signing nostr event for create signature')
@ -607,6 +611,10 @@ export const CreatePage = () => {
const fileHashes = await generateFileHashes() const fileHashes = await generateFileHashes()
if (!fileHashes) return if (!fileHashes) return
setLoadingSpinnerDesc('Timestamping your files')
const timestamps = await generateTimestamps(Object.values(fileHashes))
if (!timestamps) return
setLoadingSpinnerDesc('Generating encryption key') setLoadingSpinnerDesc('Generating encryption key')
const encryptionKey = await generateEncryptionKey() const encryptionKey = await generateEncryptionKey()
@ -631,7 +639,8 @@ export const CreatePage = () => {
const createSignature = await generateCreateSignature( const createSignature = await generateCreateSignature(
markConfig, markConfig,
fileHashes, fileHashes,
fileUrl fileUrl,
timestamps
) )
if (!createSignature) return if (!createSignature) return

View File

@ -27,11 +27,13 @@ export interface CreateSignatureEventContent {
markConfig: Mark[] markConfig: Mark[]
title: string title: string
zipUrl: string zipUrl: string
timestamps?: Timestamp[]
} }
export interface SignedEventContent { export interface SignedEventContent {
prevSig: string prevSig: string
marks: Mark[] marks: Mark[]
timestamps: Timestamp[]
} }
export interface Sigit { export interface Sigit {
@ -39,6 +41,11 @@ export interface Sigit {
meta: Meta meta: Meta
} }
export interface Timestamp {
fileHash: string
timestamp: string
}
export interface UserAppData { export interface UserAppData {
sigits: { [key: string]: Meta } // key will be id of create signature sigits: { [key: string]: Meta } // key will be id of create signature
processedGiftWraps: string[] // an array of ids of processed gift wrapped events 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 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'
}