Skip to content

Commit 13f6ff3

Browse files
committed
docs: Tweak kernel types.ts documentation
1 parent aa99448 commit 13f6ff3

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

packages/ocap-kernel/src/types.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
/**
2-
* Branded types for kernel identifiers.
3-
*
4-
* ## Trust model
5-
*
6-
* Branded types are validated at creation time via `insist*()` assertions and
7-
* `makeGCAction()`. After construction, the type system carries the invariant
8-
* — interior code trusts the brand without re-checking.
9-
*
10-
* - **External input** (JSON-RPC params, liveslots syscalls): validated at the
11-
* boundary using superstruct definitions (`KRefStruct`, `EndpointIdStruct`,
12-
* `EndpointMessageStruct`, etc.).
13-
* - **Translator layer**: validates endpoint-space refs via `insistERef()`
14-
* before translating to kernel-space.
15-
* - **Persistence reads**: trusted. Data integrity is the responsibility of the
16-
* persistence layer (`@metamask/kernel-store`); branded types are applied via
17-
* `as` casts on read. See the kernel-store package README for details.
18-
* - **Internal construction** (counters, template literals): uses `as` casts
19-
* where the format is controlled by the constructor (e.g., `\`v\${id}\` as VatId`).
20-
*/
21-
221
import type {
232
Baggage,
243
Message as SwingsetMessage,
@@ -62,11 +41,30 @@ import type {
6241
} from './remotes/types.ts';
6342
import { Fail } from './utils/assert.ts';
6443

65-
// Branded string types intentionally use plain `string &` rather than template
66-
// literal types (e.g. `v${number}`). The brands already prevent cross-type
67-
// confusion, and the format is enforced at runtime by `insist*()` / `is*()`
68-
// validators. Template literals would add friction to the `as` casts used for
69-
// persistence reads and internal construction without meaningful extra safety.
44+
/**
45+
* # Branded types
46+
*
47+
* Branded types are validated at creation time via `insist*()` assertions and
48+
* `makeGCAction()`. After construction, the type system carries the invariant;
49+
* interior code trusts the brand without re-checking.
50+
*
51+
* - **External input** (JSON-RPC params, liveslots syscalls): validated at the
52+
* boundary using superstruct definitions (`KRefStruct`, `EndpointIdStruct`,
53+
* `EndpointMessageStruct`, etc.).
54+
* - **Translator layer**: validates endpoint-space refs via `insistERef()`
55+
* before translating to kernel-space.
56+
* - **Persistence reads**: trusted. Data integrity is the responsibility of the
57+
* persistence layer (`@metamask/kernel-store`); branded types are applied via
58+
* `as` casts on read. See `./store/README.md` for details.
59+
* - **Internal construction** (counters, template literals): uses `as` casts
60+
* where the format is controlled by the constructor (e.g., `"v1" as VatId`).
61+
*
62+
* Branded string types intentionally use plain `string &` rather than template
63+
* literal types (e.g. `v${number}`). The brands already prevent cross-type
64+
* confusion, and the format is enforced at runtime by `insist*()` / `is*()`
65+
* validators. Template literals would add friction to the `as` casts used for
66+
* persistence reads and internal construction without meaningful extra safety.
67+
*/
7068

7169
declare const VatIdBrand: unique symbol;
7270
/**

0 commit comments

Comments
 (0)