feat: add exportedBy to useSigitMeta

This commit is contained in:
enes 2024-09-13 17:57:50 +02:00
parent 1dfab7b82b
commit 13254fbe06

View File

@ -33,6 +33,10 @@ export interface FlatMeta
// Remove pubkey and use submittedBy as `npub1${string}` // Remove pubkey and use submittedBy as `npub1${string}`
submittedBy?: `npub1${string}` submittedBy?: `npub1${string}`
// Optional field only present on exported sigits
// Exporting adds user's pubkey
exportedBy?: `npub1${string}`
// Remove created_at and replace with createdAt // Remove created_at and replace with createdAt
createdAt?: number createdAt?: number
@ -68,6 +72,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
const [tags, setTags] = useState<string[][]>() const [tags, setTags] = useState<string[][]>()
const [createdAt, setCreatedAt] = useState<number>() const [createdAt, setCreatedAt] = useState<number>()
const [submittedBy, setSubmittedBy] = useState<`npub1${string}`>() // submittedBy, pubkey from nostr event const [submittedBy, setSubmittedBy] = useState<`npub1${string}`>() // submittedBy, pubkey from nostr event
const [exportedBy, setExportedBy] = useState<`npub1${string}`>() // pubkey from export signature nostr event
const [id, setId] = useState<string>() const [id, setId] = useState<string>()
const [sig, setSig] = useState<string>() const [sig, setSig] = useState<string>()
@ -99,6 +104,18 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
if (!meta) return if (!meta) return
;(async function () { ;(async function () {
try { try {
if (meta.exportSignature) {
const exportSignatureEvent = await parseNostrEvent(
meta.exportSignature
)
if (
verifyEvent(exportSignatureEvent) &&
exportSignatureEvent.pubkey
) {
setExportedBy(exportSignatureEvent.pubkey as `npub1${string}`)
}
}
const createSignatureEvent = await parseNostrEvent(meta.createSignature) const createSignatureEvent = await parseNostrEvent(meta.createSignature)
const { kind, tags, created_at, pubkey, id, sig, content } = const { kind, tags, created_at, pubkey, id, sig, content } =
@ -265,6 +282,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
tags, tags,
createdAt, createdAt,
submittedBy, submittedBy,
exportedBy,
id, id,
sig, sig,
signers, signers,