Documentation
    Preparing search index...

    Module @kehto/runtime

    @kehto/runtime

    Browser-agnostic protocol engine for the napplet protocol.

    Alpha status: Kehto is an early runtime implementation for a draft NIP-5D protocol. NAP contracts and runtime APIs are not final; treat this package as current implementation guidance, not as a stable protocol guarantee.

    pnpm add @kehto/runtime
    

    @kehto/runtime is Kehto's NIP-5D protocol engine. It owns every incoming napplet message, gates it through the ACL enforcement layer, routes it to the correct NAP handler, and emits the corresponding reply envelope.

    The runtime is built around the current draft dispatch contract from @napplet/corecreateDispatch() + registerNap() — so routing is declarative, not a hand-rolled switch. It covers the NIP-5D domains currently supported by Kehto:

    • identityidentity.getProfile, identity.getFollows, identity.getPublicKey, …
    • incinc.channel.*, inc.emit, cross-napplet pub/sub
    • keyskeys.forward, keys.action, keys.bind
    • mediamedia.* playback & transport control
    • notifynotify.send, notify.channel.register, badge/permission flows
    • relayrelay.publish, relay.publishEncrypted, relay.subscribe
    • storagestorage.get/set/remove/keys with quota enforcement
    • themetheme.get, theme.changed fan-out

    Signing is shell-mediated inside relay.publish / relay.publishEncrypted (NIP-44 default, NIP-04 opt-in). The legacy signer domain is dissolved — napplets never see a host-injected nostr object and cannot call signer-sign RPCs directly.

    Everything plugs into a single factory, createRuntime(), via a RuntimeAdapter hook bag — persistence, relay pool, auth, services, and so on. No DOM, no postMessage, no localStorage: those live in @kehto/shell.

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

    const runtime = createRuntime({
    aclPersistence: aclStore,
    manifestPersistence: manifestStore,
    relayPool: myRelayPoolAdapter,
    auth: myAuthAdapter,
    // ... further adapter hooks
    });

    // Incoming NIP-5D draft envelope from a napplet:
    runtime.handleMessage('window-1', {
    type: 'relay.publish',
    id: 'evt-42',
    event: { kind: 1, content: 'hello', /* ... */ },
    });
    • createRuntime — primary entry point; Runtime interface type
    • createEnforceGate — legacy pubkey-keyed ACL gate
    • createNapEnforceGate — NIP-5D windowId-keyed ACL gate
    • resolveCapabilitiesNap — map a NIP-5D envelope to required capabilities (re-exported from @kehto/acl)
    • formatDenialReasondenied: <capability> canonical string
    • createSessionRegistry — bidirectional windowId ↔ SessionEntry store
    • createNappKeyRegistry — deprecated alias retained for v1.1 migration consumers
    • createAclState — persistence-backed wrapper around @kehto/acl state
    • createManifestCache — NIP-5A aggregate-hash cache with persistence hooks
    • createReplayDetector — duplicate-event + timestamp-window guard
    • createEventBuffer — ring buffer with subscription delivery
    • matchesFilter, matchesAnyFilter — pure NIP-01 filter helpers
    • RING_BUFFER_SIZE — default ring buffer capacity constant
    • handleStorageNap — canonical storage.* NIP-5D handler
    • cleanupNappState — remove persisted state when a napplet window closes
    • routeServiceMessage — domain-prefix router into the service registry
    • notifyServiceWindowDestroyed — lifecycle fan-out to every service handler

    40+ interfaces — including Runtime, RuntimeAdapter, SendToNapplet, RelayPoolAdapter, ServiceHandler, ServiceRegistry, NappletMessage, SessionEntry, AclEntryExternal, AclCheckEvent, and the per-adapter hook types — are exported from ./types.js for host-app integration.

    Retained for migration consumers; new integrations should use current NIP-5D envelope types from @napplet/core. Slated for removal once upstream restores those exports.

    Re-exported constants cover the v1.1 bus-kind enum, auth event kind, shell bridge URI, protocol version string, the full capability list, destructive-kind set, and the replay window seconds. Re-exported types cover the v1.1 capability union, bus-kind numeric union, and service descriptor shape. See the typedoc API reference below for the exact identifier list and current numeric values.

    Full package docs: docs/packages/runtime.md. Generated API module: docs/api/modules/_kehto_runtime.html (run pnpm docs:api).

    MIT

    Interfaces

    AclCheckEvent
    AclEntryExternal
    AclPersistence
    AclStateContainer
    AuthAdapter
    CacheAdapter
    CompatibilityReport
    ConfigAdapter
    ConsentRequest
    CryptoAdapter
    DmAdapter
    EnforceConfig
    EnforceResult
    EventBuffer
    FirewallEvent
    FirewallPersistence
    FirewallStateContainer
    GuidPersistence
    HashVerifierAdapter
    HotkeyAdapter
    ManifestCache
    ManifestCacheEntry
    ManifestPersistence
    NapEnforceConfig
    NapMessage
    NappletMessage
    PendingUpdate
    RelayConfigAdapter
    RelayPoolAdapter
    RelaySubscriptionHandle
    ReplayDetector
    Runtime
    RuntimeAdapter
    RuntimeConfigOverrides
    ServiceDescriptor
    ServiceHandler
    ServiceInfo
    SessionEntry
    SessionRegistry
    ShellSecretPersistence
    Signer
    StatePersistence
    SubscriptionEntry
    VerificationCacheEntry
    WindowManagerAdapter

    Type Aliases

    AclChecker
    Capability
    ConsentHandler
    IdentityResolver
    NappKeyEntry
    NappKeyRegistry
    PendingUpdateNotifier
    SendToNapplet
    ServiceRegistry

    Variables

    ALL_CAPABILITIES
    createNappKeyRegistry
    RING_BUFFER_SIZE

    Functions

    cleanupNappState
    createAclState
    createEnforceGate
    createEventBuffer
    createFirewallState
    createManifestCache
    createNapEnforceGate
    createReplayDetector
    createRuntime
    createSessionRegistry
    formatDenialReason
    handleStorageNap
    matchesAnyFilter
    matchesFilter
    notifyServiceWindowDestroyed
    resolveCapabilitiesNap
    routeServiceMessage