From 7f00f9e8bf8b15e811361aad2a2d75941ba056eb Mon Sep 17 00:00:00 2001 From: Eugene Date: Fri, 27 Sep 2024 16:00:48 +0300 Subject: [PATCH] feat(opentimestamps): updates signing flow --- src/pages/sign/index.tsx | 7 +++++++ src/utils/opentimestamps.ts | 13 ++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 63e71dd..0fbeaf5 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -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 { diff --git a/src/utils/opentimestamps.ts b/src/utils/opentimestamps.ts index 3d6bb78..4cbc036 100644 --- a/src/utils/opentimestamps.ts +++ b/src/utils/opentimestamps.ts @@ -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 => { +const timestamp = async (nostrId: string): Promise => { 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) }