Skip to content

Commit

Permalink
feat(daemon): add incarnateWebBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Feb 19, 2024
1 parent 41fa16b commit bbcdc11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
32 changes: 20 additions & 12 deletions packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,6 @@ const makeDaemonCore = async (
});
};

/**
* @param {import('./types.js').Formula} formula
* @param {string} formulaType
*/
const provideValueForFormula = async (formula, formulaType) => {
const formulaNumber = await randomHex512();
return provideValueForNumberedFormula(formulaType, formulaNumber, formula);
};

/** @type {import('./types.js').ProvideControllerForFormulaIdentifier} */
const provideControllerForFormulaIdentifier = formulaIdentifier => {
const { type: formulaType, number: formulaNumber } =
Expand Down Expand Up @@ -873,6 +864,25 @@ const makeDaemonCore = async (
return provideValueForNumberedFormula(formula.type, formulaNumber, formula);
};

/**
* @param {string} powersFormulaIdentifier
* @param {string} bundleFormulaIdentifier
* @returns {Promise<{ formulaIdentifier: string, value: unknown }>}
*/
const incarnateWebBundle = async (
powersFormulaIdentifier,
bundleFormulaIdentifier,
) => {
const formulaNumber = await randomHex512();
/** @type {import('./types.js').WebBundleFormula} */
const formula = {
type: 'web-bundle',
powers: powersFormulaIdentifier,
bundle: bundleFormulaIdentifier,
};
return provideValueForNumberedFormula(formula.type, formulaNumber, formula);
};

/**
* @param {string} [specifiedFormulaNumber]
* @returns {Promise<{ formulaIdentifier: string, value: import('./types').EndoBootstrap }>}
Expand Down Expand Up @@ -916,18 +926,16 @@ const makeDaemonCore = async (

const makeIdentifiedHost = makeHostMaker({
provideValueForFormulaIdentifier,
provideValueForFormula,
provideValueForNumberedFormula,
provideControllerForFormulaIdentifier,
incarnateHost,
incarnateGuest,
incarnateEval,
incarnateUnconfined,
incarnateBundle,
incarnateWebBundle,
incarnateHandle,
storeReaderRef,
randomHex512,
makeSha512,
makeMailbox,
});

Expand Down
24 changes: 4 additions & 20 deletions packages/daemon/src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ const { quote: q } = assert;

export const makeHostMaker = ({
provideValueForFormulaIdentifier,
provideValueForFormula,
provideValueForNumberedFormula,
provideControllerForFormulaIdentifier,
incarnateHost,
incarnateGuest,
incarnateEval,
incarnateUnconfined,
incarnateBundle,
incarnateWebBundle,
incarnateHandle,
storeReaderRef,
makeSha512,
randomHex512,
makeMailbox,
}) => {
Expand Down Expand Up @@ -452,24 +450,10 @@ export const makeHostMaker = ({
powersName,
);

const digester = makeSha512();
digester.updateText(
`${bundleFormulaIdentifier},${powersFormulaIdentifier}`,
);
const formulaNumber = digester.digestHex().slice(32, 64);

const formula = {
type: 'web-bundle',
bundle: bundleFormulaIdentifier,
powers: powersFormulaIdentifier,
};

// Behold, recursion:
// eslint-disable-next-line no-use-before-define
const { value, formulaIdentifier } = await provideValueForNumberedFormula(
'web-bundle',
formulaNumber,
formula,
const { value, formulaIdentifier } = await incarnateWebBundle(
powersFormulaIdentifier,
bundleFormulaIdentifier,
);

if (webPageName !== undefined) {
Expand Down

0 comments on commit bbcdc11

Please sign in to comment.