@metamask/ocap-kernel
Version:
OCap kernel core components
41 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseReachableAndVatSlot = parseReachableAndVatSlot;
exports.buildReachableAndVatSlot = buildReachableAndVatSlot;
const assert_ts_1 = require("../../utils/assert.cjs");
/**
* Parse a string into an object with `isReachable` and `vatSlot` properties.
*
* @param value - The string to parse.
* @returns An object with `isReachable` and `vatSlot` properties.
*/
function parseReachableAndVatSlot(value) {
typeof value === 'string' || (0, assert_ts_1.Fail) `non-string value: ${value}`;
const flag = value.slice(0, 1);
assert_ts_1.assert.equal(value.slice(1, 2), ' ');
const vatSlot = value.slice(2);
let isReachable;
if (flag === 'R') {
isReachable = true;
}
else if (flag === '_') {
isReachable = false;
}
else {
throw (0, assert_ts_1.Fail) `flag (${flag}) must be 'R' or '_'`;
}
return { isReachable, vatSlot };
}
harden(parseReachableAndVatSlot);
/**
* Build a string from an object with `isReachable` and `vatSlot` properties.
*
* @param isReachable - The `isReachable` property of the object.
* @param vatSlot - The `vatSlot` property of the object.
* @returns A string with the `isReachable` and `vatSlot` properties.
*/
function buildReachableAndVatSlot(isReachable, vatSlot) {
return `${isReachable ? 'R' : '_'} ${vatSlot}`;
}
harden(buildReachableAndVatSlot);
//# sourceMappingURL=reachable.cjs.map