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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 1x 1x 1x 1x 2x 2x 1x 1x | import type { ClusterConfig } from '@metamask/ocap-kernel';
/**
* Bootstrap-vat name for the Echo service subcluster. Exported so the
* host-side launcher reading the bootstrap result can address the right
* vat.
*/
export const ECHO_VAT_NAME = 'echo';
/**
* Bootstrap-vat name for the RandomNumber service subcluster.
*/
export const RANDOM_NUMBER_VAT_NAME = 'random-number';
/**
* Filename of each vat's bundle as produced by `yarn bundle-vat` in this
* package. The ocap-kernel CLI writes the bundle next to its source as
* `index.bundle`, so callers wanting a `bundleSpec` typically combine
* the source directory with this filename.
*/
export const ECHO_BUNDLE_PATH = 'echo-service/index.bundle';
export const RANDOM_NUMBER_BUNDLE_PATH = 'random-number-service/index.bundle';
/**
* Shape of either service vat's bootstrap result. Both vats expose the
* same fields so a launcher can handle them uniformly.
*/
export type SampleServiceBootstrapResult = {
name: string;
contactUrl: string;
};
/**
* Build a ClusterConfig for the Echo subcluster.
*
* @param options - Configuration options.
* @param options.bundleSpec - URL or path to the Echo vat bundle.
* @param options.matcherUrl - OCAP URL of the service matcher to register
* with at bootstrap. Pass an empty string to skip registration (useful
* during development before the matcher is up).
* @param options.forceReset - Whether to reset the subcluster on launch.
* Defaults to `false`.
* @returns A ClusterConfig ready for `kernel.launchSubcluster(...)`.
*/
export function makeEchoClusterConfig(options: {
bundleSpec: string;
matcherUrl: string;
forceReset?: boolean;
}): ClusterConfig {
const { bundleSpec, matcherUrl, forceReset = false } = options;
return {
bootstrap: ECHO_VAT_NAME,
forceReset,
services: ['ocapURLIssuerService', 'ocapURLRedemptionService'],
vats: {
[ECHO_VAT_NAME]: {
bundleSpec,
parameters: { matcherUrl },
},
},
};
}
/**
* Build a ClusterConfig for the RandomNumber subcluster.
*
* @param options - Configuration options.
* @param options.bundleSpec - URL or path to the RandomNumber vat bundle.
* @param options.matcherUrl - OCAP URL of the service matcher.
* @param options.forceReset - Whether to reset the subcluster on launch.
* Defaults to `false`.
* @returns A ClusterConfig ready for `kernel.launchSubcluster(...)`.
*/
export function makeRandomNumberClusterConfig(options: {
bundleSpec: string;
matcherUrl: string;
forceReset?: boolean;
}): ClusterConfig {
const { bundleSpec, matcherUrl, forceReset = false } = options;
return {
bootstrap: RANDOM_NUMBER_VAT_NAME,
forceReset,
services: ['ocapURLIssuerService', 'ocapURLRedemptionService'],
vats: {
[RANDOM_NUMBER_VAT_NAME]: {
bundleSpec,
parameters: { matcherUrl },
},
},
};
}
|