Add wrap manager for tracking gift wraps

This commit is contained in:
Jon Staab
2025-10-17 12:42:29 -07:00
parent ca38cbe20b
commit 247c7bafeb
27 changed files with 406 additions and 319 deletions
-17
View File
@@ -40,13 +40,8 @@ export type SignedEvent = HashedEvent & {
[verifiedSymbol]?: boolean
}
export type UnwrappedEvent = HashedEvent & {
wraps: SignedEvent[]
}
export type TrustedEvent = HashedEvent & {
sig?: string
wraps?: SignedEvent[]
[verifiedSymbol]?: boolean
}
@@ -110,12 +105,6 @@ export const isHashedEvent = (e: HashedEvent): e is HashedEvent =>
export const isSignedEvent = (e: TrustedEvent): e is SignedEvent =>
Boolean(isHashedEvent(e) && typeof e.sig === "string" && e.sig.length > 0)
export const isUnwrappedEvent = (e: TrustedEvent): e is UnwrappedEvent =>
Boolean(isHashedEvent(e) && e.wraps?.every(isSignedEvent))
export const isTrustedEvent = (e: TrustedEvent): e is TrustedEvent =>
isSignedEvent(e) || isUnwrappedEvent(e)
// Type coercion and attribute stripping
export const asEventTemplate = (e: EventTemplate): EventTemplate =>
@@ -133,12 +122,6 @@ export const asHashedEvent = (e: HashedEvent): HashedEvent =>
export const asSignedEvent = (e: SignedEvent): SignedEvent =>
pick(["kind", "tags", "content", "created_at", "pubkey", "id", "sig"], e)
export const asUnwrappedEvent = (e: UnwrappedEvent): UnwrappedEvent =>
pick(["kind", "tags", "content", "created_at", "pubkey", "id", "wraps"], e)
export const asTrustedEvent = (e: TrustedEvent): TrustedEvent =>
pick(["kind", "tags", "content", "created_at", "pubkey", "id", "sig", "wraps"], e)
// Utilities for working with events
export const getIdentifier = (e: EventTemplate) => e.tags.find(t => t[0] === "d")?.[1]