UNPKG

@gleif-it/did-webs-ts

Version:
30 lines (29 loc) 1.34 kB
import { calculateFractionalWeights } from '../document/calculateFractionalWeights.js'; import { generateIdTypeControllerBlock } from './generateIdTypeControllerBlock.js'; import { isFractionalThreshold } from '../../core/Threshold.js'; import { calculateThreshold } from '../document/calculateThreshold.js'; // currently this all gets tested in the generateDocument function export const generateConditionalProofBlock = (controller, controllerDid) => ({ ...generateIdTypeControllerBlock(controller.identifier, 'ConditionalProof2022', controllerDid), threshold: calculateThreshold(controller.keyState.kt), ...conditionalProofBlock(controller.keyState), }); const conditionalProofBlock = (controllerKeyState) => { if (isFractionalThreshold(controllerKeyState.kt)) { const weights = 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}`), }; } };