@sphereon/ssi-sdk.public-key-hosting
Version:
58 lines • 2.95 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublicKeyHosting = void 0;
const ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
const express_1 = __importDefault(require("express"));
const api_functions_1 = require("./api-functions");
const index_1 = require("./index");
class PublicKeyHosting {
get router() {
return this._router;
}
constructor(args) {
var _a, _b, _c, _d, _e, _f, _g;
const { agent, opts } = args;
this._agent = agent;
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
copyGlobalAuthToEndpoint(opts, 'allJWKS');
copyGlobalAuthToEndpoint(opts, 'DIDJWKS');
}
this._opts = opts;
this._express = args.expressSupport.express;
this._router = express_1.default.Router();
const context = (0, ssi_sdk_core_1.agentContext)(agent);
const features = (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.hostingOpts) === null || _b === void 0 ? void 0 : _b.enableFeatures) !== null && _c !== void 0 ? _c : ['all-jwks', 'did-jwks'];
index_1.logger.info(`Public key hosting enabled, with features: ${JSON.stringify(features)}`);
// Credential endpoints
if (features.includes('all-jwks')) {
(0, api_functions_1.getAllJWKSEndpoint)(this.router, context, Object.assign({}, (_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _d === void 0 ? void 0 : _d.allJWKS));
}
if (features.includes('did-jwks')) {
(0, api_functions_1.getDIDJWKSEndpoint)(this.router, context, (_e = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _e === void 0 ? void 0 : _e.DIDJWKS);
}
this._express.use((_g = (_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _f === void 0 ? void 0 : _f.basePath) !== null && _g !== void 0 ? _g : '', this.router);
}
get agent() {
return this._agent;
}
get opts() {
return this._opts;
}
get express() {
return this._express;
}
}
exports.PublicKeyHosting = PublicKeyHosting;
function copyGlobalAuthToEndpoint(opts, key) {
var _a, _b;
if ((_a = opts === null || opts === void 0 ? void 0 : opts.endpointOpts) === null || _a === void 0 ? void 0 : _a.globalAuth) {
// @ts-ignore
opts.endpointOpts[key] = Object.assign(Object.assign({}, opts.endpointOpts[key]), {
// @ts-ignore
endpoint: Object.assign(Object.assign({}, opts.endpointOpts.globalAuth), (_b = opts.endpointOpts[key]) === null || _b === void 0 ? void 0 : _b.endpoint) });
}
}
//# sourceMappingURL=public-key-hosting.js.map