feat: NIP-10

This commit is contained in:
codytseng 2025-03-12 17:23:01 +08:00
parent 5f7a99c7b5
commit 4ad96eab66
6 changed files with 309 additions and 212 deletions

View file

@ -1,5 +1,6 @@
import { TImageInfo } from '@/types'
import { isBlurhashValid } from 'blurhash'
import { nip19 } from 'nostr-tools'
import { isValidPubkey } from './pubkey'
export function tagNameEquals(tagName: string) {
@ -18,6 +19,15 @@ export function isMentionETag([tagName, , , marker]: string[]) {
return tagName === 'e' && marker === 'mention'
}
export function generateEventIdFromETag(tag: string[]) {
try {
const [, id, relay, , author] = tag
return nip19.neventEncode({ id, relays: relay ? [relay] : undefined, author })
} catch {
return undefined
}
}
export function extractImageInfoFromTag(tag: string[]): TImageInfo | null {
if (tag[0] !== 'imeta') return null
const urlItem = tag.find((item) => item.startsWith('url '))