@gleif-it/did-webs-ts
Version:
did-webs typescript library
34 lines (33 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateConditionalProofBlock = void 0;
const calculateFractionalWeights_js_1 = require("../document/calculateFractionalWeights.js");
const generateIdTypeControllerBlock_js_1 = require("./generateIdTypeControllerBlock.js");
const Threshold_js_1 = require("../../core/Threshold.js");
const calculateThreshold_js_1 = require("../document/calculateThreshold.js");
// currently this all gets tested in the generateDocument function
const generateConditionalProofBlock = (controller, controllerDid) => ({
...(0, generateIdTypeControllerBlock_js_1.generateIdTypeControllerBlock)(controller.identifier, 'ConditionalProof2022', controllerDid),
threshold: (0, calculateThreshold_js_1.calculateThreshold)(controller.keyState.kt),
...conditionalProofBlock(controller.keyState),
});
exports.generateConditionalProofBlock = generateConditionalProofBlock;
const conditionalProofBlock = (controllerKeyState) => {
if ((0, Threshold_js_1.isFractionalThreshold)(controllerKeyState.kt)) {
const weights = (0, calculateFractionalWeights_js_1.calculateFractionalWeights)(controllerKeyState.kt);
return {
// for each key, there should be a corresponding weight, print them as specified
conditionWeightedThreshold: controllerKeyState.k.map((key, index) => {
return {
condition: `#${key}`,
weight: weights[index],
};
}),
};
}
else {
return {
conditionThreshold: controllerKeyState.k.map((key) => `#${key}`),
};
}
};