Skip to content

WrapManager ​

WrapManager records which NIP-59 gift wraps carry which rumors. The rumor itself lives in a repository, and the wrap is kept as a WrapItem, without its encrypted content. An App owns one as app.wrapManager, and its publisher registers each gift wrap it sends.

WrapManager ​

typescript
new WrapManager({repository})

type WrapItem = Omit<HashedEvent, "content"> & {
  rumorId: string
  recipient: string
}

Events:

  • "add" - Emitted with the WrapItem by add()
  • "remove" - Emitted with the WrapItem by remove()
  • "load" - Emitted by load()
  • "clear" - Emitted by clear()

Methods:

  • add({wrap, rumor, recipient}) - Records the wrap, copies the wrap's relays onto the rumor in repository.tracker, and publishes the rumor to the repository
  • getRumor(wrapId) - Resolves to the rumor a wrap carries, read from the repository
  • hasWrap(wrapId) - Whether the wrap is recorded
  • getWraps(rumorId) - The WrapItems carrying a rumor
  • remove(wrapId) - Forgets the wrap, and removes its rumor from the repository unless another wrap still carries it
  • removeByRumorId(rumorId) - Removes every wrap carrying a rumor
  • dump() - Every WrapItem, for persistence
  • load(wrapItems) - Replaces the recorded wraps, without touching the repository
  • clear() - Forgets every wrap

Example ​

typescript
import {MemoryRepository} from "@welshman/store"
import {WrapManager} from "@welshman/net"

const wrapManager = new WrapManager({repository: new MemoryRepository()})

wrapManager.add({wrap, rumor, recipient: pubkey})

await wrapManager.getRumor(wrap.id) // the rumor, from the repository

wrapManager.load(storedWrapItems)