Add docs for blossom, add nip 86 and 98 support

This commit is contained in:
Jon Staab
2025-06-10 13:18:03 -07:00
parent 90b2ab2974
commit 4cabf53c2f
13 changed files with 314 additions and 17 deletions
+9 -1
View File
@@ -54,12 +54,14 @@ export type MakeEventOpts = {
created_at?: number
}
// Event template creation
export const makeEvent = (
kind: number,
{content = "", tags = [], created_at = now()}: MakeEventOpts = {},
) => ({kind, content, tags, created_at})
export const createEvent = makeEvent
// Event signature verification
export const verifyEvent = (() => {
let verify = verifyEventPure
@@ -80,6 +82,8 @@ export const verifyEvent = (() => {
Boolean(event.sig && (event[verifiedSymbol] || verify(event as SignedEvent)))
})()
// Type guards
export const isEventTemplate = (e: EventTemplate): e is EventTemplate =>
Boolean(typeof e.kind === "number" && Array.isArray(e.tags) && typeof e.content === "string")
@@ -100,6 +104,8 @@ export const isUnwrappedEvent = (e: TrustedEvent): e is UnwrappedEvent =>
export const isTrustedEvent = (e: TrustedEvent): e is TrustedEvent =>
isSignedEvent(e) || isUnwrappedEvent(e)
// Type coercion and attribute stripping
export const asEventTemplate = (e: EventTemplate): EventTemplate =>
pick(["kind", "tags", "content"], e)
@@ -121,6 +127,8 @@ export const asUnwrappedEvent = (e: UnwrappedEvent): UnwrappedEvent =>
export const asTrustedEvent = (e: TrustedEvent): TrustedEvent =>
pick(["kind", "tags", "content", "created_at", "pubkey", "id", "sig", "wrap"], e)
// Utilities for working with events
export const getIdentifier = (e: EventTemplate) => e.tags.find(t => t[0] === "d")?.[1]
export const getIdOrAddress = (e: HashedEvent) => (isReplaceable(e) ? getAddress(e) : e.id)