@kehto/runtime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @kehto/runtime
2
+
3
+ Browser-agnostic protocol engine for the napplet protocol.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @kehto/runtime
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ `@kehto/runtime` is the canonical v1.2 NIP-5D protocol engine. It owns every incoming napplet message, gates it through the ACL enforcement layer, routes it to the correct NUB handler, and emits the corresponding reply envelope.
14
+
15
+ The runtime is built around the canonical dispatch contract from `@napplet/core` — `createDispatch()` + `registerNub()` — so routing is declarative, not a hand-rolled switch. Covers all eight canonical NIP-5D domains end-to-end:
16
+
17
+ - **identity** — `identity.getProfile`, `identity.getFollows`, `identity.getPublicKey`, …
18
+ - **ifc** — `ifc.channel.*`, `ifc.emit`, cross-napplet pub/sub
19
+ - **keys** — `keys.forward`, `keys.action`, `keys.bind`
20
+ - **media** — `media.*` playback & transport control
21
+ - **notify** — `notify.send`, `notify.channel.register`, badge/permission flows
22
+ - **relay** — `relay.publish`, `relay.publishEncrypted`, `relay.subscribe`
23
+ - **storage** — `storage.get/set/remove/keys` with quota enforcement
24
+ - **theme** — `theme.get`, `theme.changed` fan-out
25
+
26
+ 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.
27
+
28
+ 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`.
29
+
30
+ ## Quick Start
31
+
32
+ ```ts
33
+ import { createRuntime } from '@kehto/runtime';
34
+
35
+ const runtime = createRuntime({
36
+ aclPersistence: aclStore,
37
+ manifestPersistence: manifestStore,
38
+ relayPool: myRelayPoolAdapter,
39
+ auth: myAuthAdapter,
40
+ // ... further adapter hooks
41
+ });
42
+
43
+ // Incoming canonical v1.2 envelope from a napplet:
44
+ runtime.handleMessage('window-1', {
45
+ type: 'relay.publish',
46
+ id: 'evt-42',
47
+ event: { kind: 1, content: 'hello', /* ... */ },
48
+ });
49
+ ```
50
+
51
+ ## Public API
52
+
53
+ ### Runtime factory
54
+ - [`createRuntime`](../../docs/api/functions/_kehto_runtime.createRuntime.html) — primary entry point; `Runtime` interface type
55
+
56
+ ### Enforcement gate
57
+ - [`createEnforceGate`](../../docs/api/functions/_kehto_runtime.createEnforceGate.html) — legacy pubkey-keyed ACL gate
58
+ - [`createNubEnforceGate`](../../docs/api/functions/_kehto_runtime.createNubEnforceGate.html) — NIP-5D windowId-keyed ACL gate
59
+ - [`resolveCapabilitiesNub`](../../docs/api/functions/_kehto_runtime.resolveCapabilitiesNub.html) — map a NIP-5D envelope to required capabilities (re-exported from `@kehto/acl`)
60
+ - [`formatDenialReason`](../../docs/api/functions/_kehto_runtime.formatDenialReason.html) — `denied: <capability>` canonical string
61
+
62
+ ### Session registry
63
+ - [`createSessionRegistry`](../../docs/api/functions/_kehto_runtime.createSessionRegistry.html) — bidirectional windowId ↔ `SessionEntry` store
64
+ - `createNappKeyRegistry` — deprecated alias retained for v1.1 migration consumers
65
+
66
+ ### ACL state container
67
+ - [`createAclState`](../../docs/api/functions/_kehto_runtime.createAclState.html) — persistence-backed wrapper around `@kehto/acl` state
68
+
69
+ ### Manifest cache
70
+ - [`createManifestCache`](../../docs/api/functions/_kehto_runtime.createManifestCache.html) — NIP-5A aggregate-hash cache with persistence hooks
71
+
72
+ ### Replay detection
73
+ - [`createReplayDetector`](../../docs/api/functions/_kehto_runtime.createReplayDetector.html) — duplicate-event + timestamp-window guard
74
+
75
+ ### Event buffer
76
+ - [`createEventBuffer`](../../docs/api/functions/_kehto_runtime.createEventBuffer.html) — ring buffer with subscription delivery
77
+ - [`matchesFilter`](../../docs/api/functions/_kehto_runtime.matchesFilter.html), [`matchesAnyFilter`](../../docs/api/functions/_kehto_runtime.matchesAnyFilter.html) — pure NIP-01 filter helpers
78
+ - `RING_BUFFER_SIZE` — default ring buffer capacity constant
79
+
80
+ ### State handler
81
+ - [`handleStorageNub`](../../docs/api/functions/_kehto_runtime.handleStorageNub.html) — canonical `storage.*` NIP-5D handler
82
+ - [`cleanupNappState`](../../docs/api/functions/_kehto_runtime.cleanupNappState.html) — remove persisted state when a napplet window closes
83
+
84
+ ### Service dispatch
85
+ - [`routeServiceMessage`](../../docs/api/functions/_kehto_runtime.routeServiceMessage.html) — domain-prefix router into the service registry
86
+ - [`notifyServiceWindowDestroyed`](../../docs/api/functions/_kehto_runtime.notifyServiceWindowDestroyed.html) — lifecycle fan-out to every service handler
87
+
88
+ ### Types
89
+ 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.
90
+
91
+ ### Compat re-exports (DRIFT-CORE-06)
92
+
93
+ Retained for v1.1 migration consumers; new integrations should use canonical NIP-5D envelope types from `@napplet/core`. Slated for removal once upstream restores those exports.
94
+
95
+ 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.
96
+
97
+ ## API Reference
98
+
99
+ Full API reference: [docs/api/@kehto/runtime/](../../docs/api/modules/_kehto_runtime.html) (generated via `pnpm docs:api`).
100
+
101
+ ## License
102
+
103
+ MIT