All files / ocap-jsonrpc-vat/src cluster-config.ts

100% Statements 5/5
100% Branches 1/1
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51      1x             1x     1x                                     3x 3x                                  
import type { ClusterConfig } from '@metamask/ocap-kernel';
 
/** Vat name for the ocap JSON-RPC vat inside its subcluster. */
export const OCAP_JSONRPC_VAT_NAME = 'ocapJsonrpcVat';
 
/**
 * Filename of the vat bundle produced by `yarn bundle-vat` in this
 * package. A launcher supplies a `bundleBaseUrl` pointing at the
 * directory containing this file.
 */
export const OCAP_JSONRPC_BUNDLE_FILENAME = 'index.bundle';
 
/** IO channel name the vat expects in its endowments. */
export const OCAP_JSONRPC_SOCKET_CHANNEL = 'socket';
 
/**
 * Build a `ClusterConfig` for the ocap JSON-RPC subcluster.
 *
 * @param options - Configuration options.
 * @param options.bundleBaseUrl - Base URL (or filesystem path) where the
 * vat bundle is reachable. The bundle filename is appended.
 * @param options.socketPath - Filesystem path for the Unix-domain-socket
 * IO channel the vat listens on.
 * @param options.forceReset - Whether to reset the subcluster on launch.
 * Defaults to `false`.
 * @returns A ClusterConfig ready for `kernel.launchSubcluster(...)`.
 */
export function makeOcapJsonrpcClusterConfig(options: {
  bundleBaseUrl: string;
  socketPath: string;
  forceReset?: boolean;
}): ClusterConfig {
  const { bundleBaseUrl, socketPath, forceReset = false } = options;
  return {
    bootstrap: OCAP_JSONRPC_VAT_NAME,
    forceReset,
    services: ['ocapURLRedemptionService'],
    io: {
      [OCAP_JSONRPC_SOCKET_CHANNEL]: {
        type: 'socket',
        path: socketPath,
      },
    },
    vats: {
      [OCAP_JSONRPC_VAT_NAME]: {
        bundleSpec: `${bundleBaseUrl}/${OCAP_JSONRPC_BUNDLE_FILENAME}`,
      },
    },
  };
}