@gleif-it/did-webs-ts
Version:
did-webs typescript library
58 lines (57 loc) • 2.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateDocument = void 0;
const generateCapabilityDelegationBlock_js_1 = require("./generateCapabilityDelegationBlock.js");
const generateConditionalProofBlock_js_1 = require("./generateConditionalProofBlock.js");
const generateKeyVerificationBlock_js_1 = require("./generateKeyVerificationBlock.js");
const calculateThreshold_js_1 = require("../document/calculateThreshold.js");
const generateDidWeb_js_1 = require("./generateDidWeb.js");
const generateDidKeri_js_1 = require("./generateDidKeri.js");
const generateDocument = (controllerDid, controller, delegatorDid, delegator) => {
// make sure both delegate paramers are provided or none
if (delegatorDid && !delegator) {
throw new Error('Delegator did provided without delegator keys');
}
if (delegator && !delegatorDid) {
throw new Error('Delegator keys provided without delegator did');
}
// various helpful values and objects
const controllerIdentifier = controller.identifier;
const controllerKeyState = controller.keyState;
const controllerThreshold = (0, calculateThreshold_js_1.calculateThreshold)(controllerKeyState.kt);
// const delagatorKeyState = hasDelegator ? delegator?.keyState : undefined;
// const delegatorThresholdIsFractional = hasDelegator
// ? isFractionalThreshold(delagatorKeyState?.kt)
// : undefined;
// const delegatorThreshold = hasDelegator
// ? calcutaleThreshold(delagatorKeyState?.kt)
// : undefined;
// some pregenerated blocks
const conditionalProofBlock = (0, generateConditionalProofBlock_js_1.generateConditionalProofBlock)(controller, controllerDid);
const keyVerificationBlock = (0, generateKeyVerificationBlock_js_1.generateKeyVerificationBlock)(controller, controllerDid);
const optionalCapabilityDelegationBlock = (0, generateCapabilityDelegationBlock_js_1.generateCapabilityDelegationBlock)(delegator, delegatorDid);
// use pregenerated values to create the document
return {
id: controllerDid,
verificationMethod: controllerThreshold > 1
? [conditionalProofBlock, ...keyVerificationBlock]
: keyVerificationBlock,
authentication: [
controllerThreshold > 1
? `#${controllerIdentifier}`
: `#${controllerKeyState.k[0]}`,
],
assertionMethod: [
controllerThreshold > 1
? `#${controllerIdentifier}`
: `#${controllerKeyState.k[0]}`,
],
...optionalCapabilityDelegationBlock,
service: [],
alsoKnownAs: [
(0, generateDidWeb_js_1.generateDidWeb)(controllerDid),
(0, generateDidKeri_js_1.generateDidKeri)(controllerDid),
],
};
};
exports.generateDocument = generateDocument;