feat(opentimestamps): amends to flow to only upgrade users timestamps
Some checks failed
Open PR on Staging / audit_and_check (pull_request) Failing after 32s

This commit is contained in:
eugene 2024-10-08 17:01:51 +02:00
parent 3d5006a715
commit f12aaf1c2b
2 changed files with 49 additions and 16 deletions

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)