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 theWrapItembyadd()"remove"- Emitted with theWrapItembyremove()"load"- Emitted byload()"clear"- Emitted byclear()
Methods:
add({wrap, rumor, recipient})- Records the wrap, copies the wrap's relays onto the rumor inrepository.tracker, and publishes the rumor to the repositorygetRumor(wrapId)- Resolves to the rumor a wrap carries, read from the repositoryhasWrap(wrapId)- Whether the wrap is recordedgetWraps(rumorId)- TheWrapItems carrying a rumorremove(wrapId)- Forgets the wrap, and removes its rumor from the repository unless another wrap still carries itremoveByRumorId(rumorId)- Removes every wrap carrying a rumordump()- EveryWrapItem, for persistenceload(wrapItems)- Replaces the recorded wraps, without touching the repositoryclear()- 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)