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]) }, [currentFileHashes, fileHashes, files])
useEffect(() => { useEffect(() => {
console.log('timestamps: ', timestamps) if (
if (timestamps && timestamps.length > 0) { timestamps &&
console.log(timestamps.every((t) => !!t.verification)) timestamps.length > 0 &&
usersPubkey &&
submittedBy &&
parsedSignatureEvents
) {
if (timestamps.every((t) => !!t.verification)) { 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 return
} }
const upgradeT = async (timestamps: OpenTimestamp[]) => { const upgradeT = async (timestamps: OpenTimestamp[]) => {
try { try {
setLoadingSpinnerDesc('Upgrading and verifying your timestamps.') setLoadingSpinnerDesc('Upgrading your timestamps.')
const verifiedResults = await Promise.all(
timestamps.map(upgradeAndVerifyTimestamp) 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. * 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 if (!oldT.verification && upgradedTimestamp.verified) return true
} }
const upgradedTimestamps = verifiedResults const userTimestamps: OpenTimestamp[] = []
.filter((t) => t.upgraded || isNewlyVerified(t, timestamps))
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) => { .map((t) => {
const timestamp = t.timestamp const timestamp: OpenTimestamp = { ...t.timestamp }
if (t.verified) { if (t.verified) {
timestamp.verification = t.verification timestamp.verification = t.verification
} }
return timestamp return timestamp
}) })
if (upgradedTimestamps.length === 0) { if (upgradedUserTimestamps.length > 0) {
toast.success('No timestamp upgrades found.')
return return
} }
@ -325,10 +359,9 @@ export const VerifyPage = () => {
} }
upgradeT(timestamps) upgradeT(timestamps)
} }
}, [timestamps]) }, [timestamps, submittedBy, parsedSignatureEvents])
useEffect(() => { useEffect(() => {
console.log('this runs')
if (metaInNavState && encryptionKey) { if (metaInNavState && encryptionKey) {
const processSigit = async () => { const processSigit = async () => {
setIsLoading(true) setIsLoading(true)

View File

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