feat(opentimestamps): updates signing flow
This commit is contained in:
parent
07f1a15aa1
commit
7f00f9e8bf
@ -54,6 +54,7 @@ import {
|
|||||||
SigitFile
|
SigitFile
|
||||||
} from '../../utils/file.ts'
|
} from '../../utils/file.ts'
|
||||||
import { ARRAY_BUFFER, DEFLATE } from '../../utils/const.ts'
|
import { ARRAY_BUFFER, DEFLATE } from '../../utils/const.ts'
|
||||||
|
import { generateTimestamp } from '../../utils/opentimestamps.ts'
|
||||||
enum SignedStatus {
|
enum SignedStatus {
|
||||||
Fully_Signed,
|
Fully_Signed,
|
||||||
User_Is_Next_Signer,
|
User_Is_Next_Signer,
|
||||||
@ -549,6 +550,12 @@ export const SignPage = () => {
|
|||||||
|
|
||||||
const updatedMeta = updateMetaSignatures(meta, signedEvent)
|
const updatedMeta = updateMetaSignatures(meta, signedEvent)
|
||||||
|
|
||||||
|
const timestamp = await generateTimestamp(signedEvent.id)
|
||||||
|
if (timestamp) {
|
||||||
|
updatedMeta.timestamps = [...(updatedMeta.timestamps || []), timestamp]
|
||||||
|
updatedMeta.modifiedAt = unixNow()
|
||||||
|
}
|
||||||
|
|
||||||
if (await isOnline()) {
|
if (await isOnline()) {
|
||||||
await handleOnlineFlow(updatedMeta)
|
await handleOnlineFlow(updatedMeta)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Timestamp } from '../types'
|
import { Timestamp } from '../types'
|
||||||
import { retry } from './retry.ts'
|
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.
|
* 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 =
|
const detachedTimestamp =
|
||||||
window.OpenTimestamps.DetachedTimestampFile.fromHash(
|
window.OpenTimestamps.DetachedTimestampFile.fromBytes(
|
||||||
new window.OpenTimestamps.Ops.OpSHA256(),
|
new window.OpenTimestamps.Ops.OpSHA256(),
|
||||||
hexToBytes(hash)
|
utf8Encoder.encode(nostrId)
|
||||||
)
|
)
|
||||||
|
|
||||||
await window.OpenTimestamps.stamp(detachedTimestamp)
|
await window.OpenTimestamps.stamp(detachedTimestamp)
|
||||||
const ctx = new window.OpenTimestamps.Context.StreamSerialization()
|
const ctx = new window.OpenTimestamps.Context.StreamSerialization()
|
||||||
detachedTimestamp.serialize(ctx)
|
detachedTimestamp.serialize(ctx)
|
||||||
const timestampBytes = ctx.getOutput()
|
const timestampBytes = ctx.getOutput()
|
||||||
const hex = bytesToHex(timestampBytes)
|
return bytesToHex(timestampBytes)
|
||||||
|
|
||||||
return hex
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user