feat(opentimestamps): updates signing flow

This commit is contained in:
eugene 2024-09-27 16:00:48 +03:00
parent 07f1a15aa1
commit 7f00f9e8bf
2 changed files with 13 additions and 7 deletions

View File

@ -54,6 +54,7 @@ import {
SigitFile
} from '../../utils/file.ts'
import { ARRAY_BUFFER, DEFLATE } from '../../utils/const.ts'
import { generateTimestamp } from '../../utils/opentimestamps.ts'
enum SignedStatus {
Fully_Signed,
User_Is_Next_Signer,
@ -549,6 +550,12 @@ export const SignPage = () => {
const updatedMeta = updateMetaSignatures(meta, signedEvent)
const timestamp = await generateTimestamp(signedEvent.id)
if (timestamp) {
updatedMeta.timestamps = [...(updatedMeta.timestamps || []), timestamp]
updatedMeta.modifiedAt = unixNow()
}
if (await isOnline()) {
await handleOnlineFlow(updatedMeta)
} else {

View File

@ -1,6 +1,7 @@
import { Timestamp } from '../types'
import { retry } from './retry.ts'
import { bytesToHex, hexToBytes } from '@noble/hashes/utils'
import { bytesToHex } from '@noble/hashes/utils'
import { utf8Encoder } from 'nostr-tools/utils'
/**
* Generates a timestamp for the provided nostr event ID.
@ -20,18 +21,16 @@ export const generateTimestamp = async (
}
}
const timestamp = async (hash: string): Promise<string> => {
const timestamp = async (nostrId: string): Promise<string> => {
const detachedTimestamp =
window.OpenTimestamps.DetachedTimestampFile.fromHash(
window.OpenTimestamps.DetachedTimestampFile.fromBytes(
new window.OpenTimestamps.Ops.OpSHA256(),
hexToBytes(hash)
utf8Encoder.encode(nostrId)
)
await window.OpenTimestamps.stamp(detachedTimestamp)
const ctx = new window.OpenTimestamps.Context.StreamSerialization()
detachedTimestamp.serialize(ctx)
const timestampBytes = ctx.getOutput()
const hex = bytesToHex(timestampBytes)
return hex
return bytesToHex(timestampBytes)
}