UNPKG

@sphereon/ssi-sdk.public-key-hosting

Version:

39 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.jwksURIFromIdentifier = exports.toJWKS = void 0; const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils"); const utils_1 = require("@veramo/utils"); const environment_1 = require("./environment"); const toJWKS = (args) => { const providedKeys = (0, utils_1.asArray)(args.keys); const keys = providedKeys.map((key) => (0, ssi_sdk_ext_key_utils_1.toJwk)(key.publicKeyHex, key.type, { key, isPrivateKey: false, noKidThumbprint: false, })); return { keys, }; }; exports.toJWKS = toJWKS; const jwksURIFromIdentifier = (args) => { var _a; const { onlyEncodeDid, identifier, baseURL } = args; let basePath = (_a = args.basePath) !== null && _a !== void 0 ? _a : environment_1.JWKS_HOSTING_DID_KEYS_PATH; const did = encodeURIComponent(identifier.did); if (onlyEncodeDid) { return did; } if (basePath.includes(':did')) { basePath = basePath.replace(':did', did); } else { basePath += basePath.endsWith('/') ? did : `/${did}`; } if (baseURL) { return baseURL + baseURL.endsWith('/') ? basePath : `/${basePath}`; } return basePath; }; exports.jwksURIFromIdentifier = jwksURIFromIdentifier; //# sourceMappingURL=functions.js.map