Skip to content

Commit 2b6b7bc

Browse files
rekmarksclaude
andcommitted
fix(ocap-kernel): use KernelCapDataStruct in RPC specs to eliminate unsafe casts
Replace CapDataStruct (validates string[] slots) with KernelCapDataStruct (validates KRef[] slots) in queueMessage and launchSubcluster RPC specs. This makes the runtime validation match the declared CapData<KRef> type, eliminating two `as unknown as` casts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9c5d4b5 commit 2b6b7bc

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

packages/ocap-kernel/src/rpc/kernel-control/launch-subcluster.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { CapData } from '@endo/marshal';
22
import type { MethodSpec, Handler } from '@metamask/kernel-rpc-methods';
33
import { object, nullable, type as structType } from '@metamask/superstruct';
4-
import type { Struct } from '@metamask/superstruct';
54

65
import type { Kernel } from '../../Kernel.ts';
76
import type { ClusterConfig, KRef, SubclusterId } from '../../types.ts';
87
import {
98
ClusterConfigStruct,
10-
CapDataStruct,
9+
KernelCapDataStruct,
1110
SubclusterIdStruct,
1211
KRefStruct,
1312
} from '../../types.ts';
@@ -25,7 +24,7 @@ type LaunchSubclusterRpcResult = {
2524
const LaunchSubclusterRpcResultStruct = structType({
2625
subclusterId: SubclusterIdStruct,
2726
rootKref: KRefStruct,
28-
bootstrapResult: nullable(CapDataStruct),
27+
bootstrapResult: nullable(KernelCapDataStruct),
2928
});
3029

3130
export const launchSubclusterSpec: MethodSpec<
@@ -35,10 +34,7 @@ export const launchSubclusterSpec: MethodSpec<
3534
> = {
3635
method: 'launchSubcluster',
3736
params: object({ config: ClusterConfigStruct }),
38-
result: LaunchSubclusterRpcResultStruct as unknown as Struct<
39-
LaunchSubclusterRpcResult,
40-
unknown
41-
>,
37+
result: LaunchSubclusterRpcResultStruct,
4238
};
4339

4440
export type LaunchSubclusterHooks = {

packages/ocap-kernel/src/rpc/kernel-control/queue-message.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Json } from '@metamask/utils';
66

77
import type { Kernel } from '../../Kernel.ts';
88
import type { KRef } from '../../types.ts';
9-
import { CapDataStruct, KRefStruct } from '../../types.ts';
9+
import { KernelCapDataStruct, KRefStruct } from '../../types.ts';
1010

1111
/**
1212
* Enqueue a message to a vat via the kernel's crank queue.
@@ -18,12 +18,8 @@ export const queueMessageSpec: MethodSpec<
1818
> = {
1919
method: 'queueMessage',
2020
params: tuple([KRefStruct, string(), array(UnsafeJsonStruct)]),
21-
result: CapDataStruct,
22-
} as unknown as MethodSpec<
23-
'queueMessage',
24-
[KRef, string, Json[]],
25-
CapData<KRef>
26-
>;
21+
result: KernelCapDataStruct,
22+
};
2723

2824
export type QueueMessageHooks = {
2925
kernel: Pick<Kernel, 'queueMessage'>;

0 commit comments

Comments
 (0)