Documentation
    Preparing search index...

    Function handleStorageNap

    • Handle a NIP-5D NAP storage message from a napplet. Routes to the canonical four @napplet/nap/storage actions:

      • storage.getstorage.get.result { value: string | null }
      • storage.setstorage.set.result { ok: boolean } (canonical only checks error)
      • storage.removestorage.remove.result { ok: boolean }
      • storage.keysstorage.keys.result { keys: string[] }

      storage.clear is NOT in the canonical @napplet/nap/storage union (it was a kehto unilateral extension); attempts produce a storage.clear.result envelope with an error field set. Internal lifecycle cleanup still uses the cleanupNappState() helper below — it is not napplet-reachable.

      Per-instance scope (NAP-STORAGE / napplet/naps#3): each request MAY carry scope: "shared" | "instance" (default "shared"). "instance" addresses a per-window sub-namespace keyed by windowId, so multiple windows of the same napplet keep isolated state; "shared" (or absent) addresses the napplet-wide namespace, byte-identical to historical behavior. An unrecognized scope value is an invalid request and produces a .result envelope with error set.

      Deviation note (Phase 15 to decide): Set/remove results emit both ok (legacy compat) and an error field on failure. Canonical @napplet/nap/storage only specifies the optional error; napplets check !result.error for success. Emitting ok preserves backward compatibility with existing in-tree callers. Phase 15 (v1.2 release prep) decides whether to drop ok pre-release.

      Parameters

      • windowId: string

        The window identifier of the requesting napplet

      • msg: NappletMessage

        The NappletMessage containing the storage request

      • sendToNapplet: SendToNapplet

        Transport function to send responses

      • sessionRegistry: SessionRegistry

        Identity registry for looking up napplet session identity

      • aclState: AclStateContainer

        ACL state for quota checks

      • statePersistence: StatePersistence

        State storage backend

      Returns void

      import { handleStorageNap } from '@kehto/runtime';

      handleStorageNap(windowId, { type: 'storage.get', id: 'q1', key: 'draft' },
      sendToNapplet, sessionRegistry, aclState, statePersistence);