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
2 changed files with 49 additions and 16 deletions
Showing only changes of commit f12aaf1c2b - Show all commits

View File

@ -220,19 +220,33 @@ export const VerifyPage = () => {
}, [currentFileHashes, fileHashes, files])
useEffect(() => {
console.log('timestamps: ', timestamps)
if (timestamps && timestamps.length > 0) {
console.log(timestamps.every((t) => !!t.verification))
if (
timestamps &&
timestamps.length > 0 &&
usersPubkey &&
submittedBy &&
parsedSignatureEvents
) {
if (timestamps.every((t) => !!t.verification)) {
toast.success('All of your timestamps are fully verified on Bitcoin.')
toast.success('All timestamps are fully verified.')
return
}
const upgradeT = async (timestamps: OpenTimestamp[]) => {
try {
setLoadingSpinnerDesc('Upgrading and verifying your timestamps.')
const verifiedResults = await Promise.all(
timestamps.map(upgradeAndVerifyTimestamp)
)
setLoadingSpinnerDesc('Upgrading your timestamps.')
const findCreatorTimestamp = (timestamps: OpenTimestamp[]) => {
if (usersPubkey === submittedBy) {
return timestamps[0]
}
}
const findSignerTimestamp = (timestamps: OpenTimestamp[]) => {
const parsedEvent = parsedSignatureEvents[hexToNpub(usersPubkey)]
if (parsedEvent?.id) {
return timestamps.find((t) => t.nostrId === parsedEvent.id)
}
}
/**
* Checks if timestamp verification has been achieved for the first time.
@ -253,18 +267,38 @@ export const VerifyPage = () => {
if (!oldT.verification && upgradedTimestamp.verified) return true
}
const upgradedTimestamps = verifiedResults
.filter((t) => t.upgraded || isNewlyVerified(t, timestamps))
const userTimestamps: OpenTimestamp[] = []
const creatorTimestamp = findCreatorTimestamp(timestamps)
if (creatorTimestamp) {
userTimestamps.push(creatorTimestamp)
}
const signerTimestamp = findSignerTimestamp(timestamps)
if (signerTimestamp) {
userTimestamps.push(signerTimestamp)
}
if (userTimestamps.every((t) => !!t.verification)) {
console.log('user timestamps are verified')
return
}
const upgradedUserTimestamps = await Promise.all(
userTimestamps.map(upgradeAndVerifyTimestamp)
)
const upgradedTimestamps = upgradedUserTimestamps
.filter((t) => t.upgraded || isNewlyVerified(t, userTimestamps))
.map((t) => {
const timestamp = t.timestamp
const timestamp: OpenTimestamp = { ...t.timestamp }
if (t.verified) {
timestamp.verification = t.verification
}
return timestamp
})
if (upgradedTimestamps.length === 0) {
toast.success('No timestamp upgrades found.')
if (upgradedUserTimestamps.length > 0) {
return
}
@ -325,10 +359,9 @@ export const VerifyPage = () => {
}
upgradeT(timestamps)
}
}, [timestamps])
}, [timestamps, submittedBy, parsedSignatureEvents])
useEffect(() => {
console.log('this runs')
if (metaInNavState && encryptionKey) {
const processSigit = async () => {
setIsLoading(true)

View File

@ -41,7 +41,7 @@ export const upgradeAndVerifyTimestamp = async (
* The upgraded flag indicates if an upgrade has been performed.
* @param t - timestamp
*/
const upgrade = async (
export const upgrade = async (
t: OpenTimestamp
): Promise<OpenTimestampUpgradeVerifyResponse> => {
console.log('timestamp: ', t)