@sphereon/ssi-sdk-ext.kms-azure-rest-client
Version:
Sphereon SSI-SDK plugin for Azure KeyVault Key Management System.
1,518 lines (1,492 loc) • 50.8 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/AzureKeyVaultKeyManagementSystemRestClient.ts
import { AbstractKeyManagementSystem } from "@veramo/key-manager";
// src/js-client/rxjsStub.js
var Observable = class _Observable {
static {
__name(this, "Observable");
}
constructor(promise) {
this.promise = promise;
}
toPromise() {
return this.promise;
}
pipe(callback) {
return new _Observable(this.promise.then(callback));
}
};
function from(promise) {
return new Observable(promise);
}
__name(from, "from");
function of(value) {
return new Observable(Promise.resolve(value));
}
__name(of, "of");
function mergeMap(callback) {
return (value) => callback(value).toPromise();
}
__name(mergeMap, "mergeMap");
function map(callback) {
return callback;
}
__name(map, "map");
// src/js-client/http/isomorphic-fetch.js
import "whatwg-fetch";
var IsomorphicFetchHttpLibrary = class {
static {
__name(this, "IsomorphicFetchHttpLibrary");
}
send(request) {
let method = request.getHttpMethod().toString();
let body = request.getBody();
const resultPromise = fetch(request.getUrl(), {
method,
body,
headers: request.getHeaders(),
credentials: "same-origin"
}).then((resp) => {
const headers = {};
resp.headers.forEach((value, name) => {
headers[name] = value;
});
const body2 = {
text: /* @__PURE__ */ __name(() => resp.text(), "text"),
binary: /* @__PURE__ */ __name(() => resp.blob(), "binary")
};
return new ResponseContext(resp.status, headers, body2);
});
return from(resultPromise);
}
};
// src/js-client/http/http.js
var __awaiter = function(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function(resolve) {
resolve(value);
});
}
__name(adopt, "adopt");
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
__name(fulfilled, "fulfilled");
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
__name(rejected, "rejected");
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
__name(step, "step");
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var HttpMethod;
(function(HttpMethod2) {
HttpMethod2["GET"] = "GET";
HttpMethod2["HEAD"] = "HEAD";
HttpMethod2["POST"] = "POST";
HttpMethod2["PUT"] = "PUT";
HttpMethod2["DELETE"] = "DELETE";
HttpMethod2["CONNECT"] = "CONNECT";
HttpMethod2["OPTIONS"] = "OPTIONS";
HttpMethod2["TRACE"] = "TRACE";
HttpMethod2["PATCH"] = "PATCH";
})(HttpMethod || (HttpMethod = {}));
function ensureAbsoluteUrl(url) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
}
return window.location.origin + url;
}
__name(ensureAbsoluteUrl, "ensureAbsoluteUrl");
var RequestContext = class {
static {
__name(this, "RequestContext");
}
constructor(url, httpMethod) {
this.httpMethod = httpMethod;
this.headers = {};
this.body = void 0;
this.url = new URL(ensureAbsoluteUrl(url));
}
getUrl() {
return this.url.toString().endsWith("/") ? this.url.toString().slice(0, -1) : this.url.toString();
}
setUrl(url) {
this.url = new URL(ensureAbsoluteUrl(url));
}
setBody(body) {
this.body = body;
}
getHttpMethod() {
return this.httpMethod;
}
getHeaders() {
return this.headers;
}
getBody() {
return this.body;
}
setQueryParam(name, value) {
this.url.searchParams.set(name, value);
}
appendQueryParam(name, value) {
this.url.searchParams.append(name, value);
}
addCookie(name, value) {
if (!this.headers["Cookie"]) {
this.headers["Cookie"] = "";
}
this.headers["Cookie"] += name + "=" + value + "; ";
}
setHeaderParam(key, value) {
this.headers[key] = value;
}
};
var ResponseContext = class {
static {
__name(this, "ResponseContext");
}
constructor(httpStatusCode, headers, body) {
this.httpStatusCode = httpStatusCode;
this.headers = headers;
this.body = body;
}
getParsedHeader(headerName) {
const result = {};
if (!this.headers[headerName]) {
return result;
}
const parameters = this.headers[headerName].split(";");
for (const parameter of parameters) {
let [key, value] = parameter.split("=", 2);
if (!key) {
continue;
}
key = key.toLowerCase().trim();
if (value === void 0) {
result[""] = key;
} else {
value = value.trim();
if (value.startsWith('"') && value.endsWith('"')) {
value = value.substring(1, value.length - 1);
}
result[key] = value;
}
}
return result;
}
getBodyAsFile() {
return __awaiter(this, void 0, void 0, function* () {
const data = yield this.body.binary();
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
const contentType = this.headers["content-type"] || "";
try {
return new File([
data
], fileName, {
type: contentType
});
} catch (error) {
return Object.assign(data, {
name: fileName,
type: contentType
});
}
});
}
getBodyAsAny() {
try {
return this.body.text();
} catch (_a) {
}
try {
return this.body.binary();
} catch (_b) {
}
return Promise.resolve(void 0);
}
};
var HttpInfo = class extends ResponseContext {
static {
__name(this, "HttpInfo");
}
constructor(httpStatusCode, headers, body, data) {
super(httpStatusCode, headers, body);
this.data = data;
}
};
// src/js-client/auth/auth.js
var ApiKeySchemeAuthentication = class {
static {
__name(this, "ApiKeySchemeAuthentication");
}
constructor(apiKey) {
this.apiKey = apiKey;
}
getName() {
return "apiKeyScheme";
}
applySecurityAuthentication(context) {
context.setHeaderParam("X-API-KEY", this.apiKey);
}
};
function configureAuthMethods(config) {
let authMethods = {};
if (!config) {
return authMethods;
}
authMethods["default"] = config["default"];
if (config["apiKeyScheme"]) {
authMethods["apiKeyScheme"] = new ApiKeySchemeAuthentication(config["apiKeyScheme"]);
}
return authMethods;
}
__name(configureAuthMethods, "configureAuthMethods");
// src/js-client/models/BinaryData.js
var BinaryData = class _BinaryData {
static {
__name(this, "BinaryData");
}
static getAttributeTypeMap() {
return _BinaryData.attributeTypeMap;
}
constructor() {
}
};
BinaryData.discriminator = void 0;
BinaryData.mapping = void 0;
BinaryData.attributeTypeMap = [
{
name: "length",
baseName: "length",
type: "number",
format: "int64"
},
{
name: "replayable",
baseName: "replayable",
type: "boolean",
format: ""
}
];
// src/js-client/models/CreateEcKeyRequest.js
var CreateEcKeyRequest = class _CreateEcKeyRequest {
static {
__name(this, "CreateEcKeyRequest");
}
static getAttributeTypeMap() {
return _CreateEcKeyRequest.attributeTypeMap;
}
constructor() {
}
};
CreateEcKeyRequest.discriminator = void 0;
CreateEcKeyRequest.mapping = void 0;
CreateEcKeyRequest.attributeTypeMap = [
{
name: "keyName",
baseName: "keyName",
type: "string",
format: ""
},
{
name: "curveName",
baseName: "curveName",
type: "string",
format: ""
},
{
name: "operations",
baseName: "operations",
type: "Array<string>",
format: ""
}
];
// src/js-client/models/JsonWebKey.js
var JsonWebKey = class _JsonWebKey {
static {
__name(this, "JsonWebKey");
}
static getAttributeTypeMap() {
return _JsonWebKey.attributeTypeMap;
}
constructor() {
}
};
JsonWebKey.discriminator = void 0;
JsonWebKey.mapping = void 0;
JsonWebKey.attributeTypeMap = [
{
name: "keyType",
baseName: "keyType",
type: "string",
format: ""
},
{
name: "keyOps",
baseName: "keyOps",
type: "Array<string>",
format: ""
},
{
name: "n",
baseName: "n",
type: "string",
format: "byte"
},
{
name: "e",
baseName: "e",
type: "string",
format: "byte"
},
{
name: "d",
baseName: "d",
type: "string",
format: "byte"
},
{
name: "dp",
baseName: "dp",
type: "string",
format: "byte"
},
{
name: "dq",
baseName: "dq",
type: "string",
format: "byte"
},
{
name: "qi",
baseName: "qi",
type: "string",
format: "byte"
},
{
name: "p",
baseName: "p",
type: "string",
format: "byte"
},
{
name: "q",
baseName: "q",
type: "string",
format: "byte"
},
{
name: "k",
baseName: "k",
type: "string",
format: "byte"
},
{
name: "t",
baseName: "t",
type: "string",
format: "byte"
},
{
name: "x",
baseName: "x",
type: "string",
format: "byte"
},
{
name: "y",
baseName: "y",
type: "string",
format: "byte"
},
{
name: "id",
baseName: "id",
type: "string",
format: ""
},
{
name: "valid",
baseName: "valid",
type: "boolean",
format: ""
},
{
name: "curveName",
baseName: "curveName",
type: "string",
format: ""
}
];
// src/js-client/models/KeyProperties.js
var KeyProperties = class _KeyProperties {
static {
__name(this, "KeyProperties");
}
static getAttributeTypeMap() {
return _KeyProperties.attributeTypeMap;
}
constructor() {
}
};
KeyProperties.discriminator = void 0;
KeyProperties.mapping = void 0;
KeyProperties.attributeTypeMap = [
{
name: "enabled",
baseName: "enabled",
type: "boolean",
format: ""
},
{
name: "exportable",
baseName: "exportable",
type: "boolean",
format: ""
},
{
name: "notBefore",
baseName: "notBefore",
type: "Date",
format: "date-time"
},
{
name: "version",
baseName: "version",
type: "string",
format: ""
},
{
name: "expiresOn",
baseName: "expiresOn",
type: "Date",
format: "date-time"
},
{
name: "createdOn",
baseName: "createdOn",
type: "Date",
format: "date-time"
},
{
name: "updatedOn",
baseName: "updatedOn",
type: "Date",
format: "date-time"
},
{
name: "recoveryLevel",
baseName: "recoveryLevel",
type: "string",
format: ""
},
{
name: "name",
baseName: "name",
type: "string",
format: ""
},
{
name: "id",
baseName: "id",
type: "string",
format: ""
},
{
name: "tags",
baseName: "tags",
type: "{ [key: string]: string; }",
format: ""
},
{
name: "managed",
baseName: "managed",
type: "boolean",
format: ""
},
{
name: "recoverableDays",
baseName: "recoverableDays",
type: "number",
format: "int32"
},
{
name: "releasePolicy",
baseName: "releasePolicy",
type: "KeyReleasePolicy",
format: ""
},
{
name: "hsmPlatform",
baseName: "hsmPlatform",
type: "string",
format: ""
}
];
// src/js-client/models/KeyReleasePolicy.js
var KeyReleasePolicy = class _KeyReleasePolicy {
static {
__name(this, "KeyReleasePolicy");
}
static getAttributeTypeMap() {
return _KeyReleasePolicy.attributeTypeMap;
}
constructor() {
}
};
KeyReleasePolicy.discriminator = void 0;
KeyReleasePolicy.mapping = void 0;
KeyReleasePolicy.attributeTypeMap = [
{
name: "encodedPolicy",
baseName: "encodedPolicy",
type: "BinaryData",
format: ""
},
{
name: "contentType",
baseName: "contentType",
type: "string",
format: ""
},
{
name: "immutable",
baseName: "immutable",
type: "boolean",
format: ""
}
];
// src/js-client/models/KeyVaultKey.js
var KeyVaultKey = class _KeyVaultKey {
static {
__name(this, "KeyVaultKey");
}
static getAttributeTypeMap() {
return _KeyVaultKey.attributeTypeMap;
}
constructor() {
}
};
KeyVaultKey.discriminator = void 0;
KeyVaultKey.mapping = void 0;
KeyVaultKey.attributeTypeMap = [
{
name: "key",
baseName: "key",
type: "JsonWebKey",
format: ""
},
{
name: "properties",
baseName: "properties",
type: "KeyProperties",
format: ""
},
{
name: "name",
baseName: "name",
type: "string",
format: ""
},
{
name: "id",
baseName: "id",
type: "string",
format: ""
},
{
name: "keyType",
baseName: "keyType",
type: "string",
format: ""
},
{
name: "keyOperations",
baseName: "keyOperations",
type: "Array<string>",
format: ""
}
];
// src/js-client/models/SignPayloadDTO.js
var SignPayloadDTO = class _SignPayloadDTO {
static {
__name(this, "SignPayloadDTO");
}
static getAttributeTypeMap() {
return _SignPayloadDTO.attributeTypeMap;
}
constructor() {
}
};
SignPayloadDTO.discriminator = void 0;
SignPayloadDTO.mapping = void 0;
SignPayloadDTO.attributeTypeMap = [
{
name: "keyName",
baseName: "keyName",
type: "string",
format: ""
},
{
name: "payload",
baseName: "payload",
type: "string",
format: ""
}
];
// src/js-client/models/SignPayloadResponse.js
var SignPayloadResponse = class _SignPayloadResponse {
static {
__name(this, "SignPayloadResponse");
}
static getAttributeTypeMap() {
return _SignPayloadResponse.attributeTypeMap;
}
constructor() {
}
};
SignPayloadResponse.discriminator = void 0;
SignPayloadResponse.mapping = void 0;
SignPayloadResponse.attributeTypeMap = [
{
name: "signature",
baseName: "signature",
type: "string",
format: ""
}
];
// src/js-client/models/VerifyPayloadDTO.js
var VerifyPayloadDTO = class _VerifyPayloadDTO {
static {
__name(this, "VerifyPayloadDTO");
}
static getAttributeTypeMap() {
return _VerifyPayloadDTO.attributeTypeMap;
}
constructor() {
}
};
VerifyPayloadDTO.discriminator = void 0;
VerifyPayloadDTO.mapping = void 0;
VerifyPayloadDTO.attributeTypeMap = [
{
name: "keyName",
baseName: "keyName",
type: "string",
format: ""
},
{
name: "payload",
baseName: "payload",
type: "string",
format: ""
},
{
name: "signature",
baseName: "signature",
type: "string",
format: ""
}
];
// src/js-client/middleware.js
var PromiseMiddlewareWrapper = class {
static {
__name(this, "PromiseMiddlewareWrapper");
}
constructor(middleware) {
this.middleware = middleware;
}
pre(context) {
return from(this.middleware.pre(context));
}
post(context) {
return from(this.middleware.post(context));
}
};
// src/js-client/servers.js
var ServerConfiguration = class {
static {
__name(this, "ServerConfiguration");
}
constructor(url, variableConfiguration) {
this.url = url;
this.variableConfiguration = variableConfiguration;
}
setVariables(variableConfiguration) {
Object.assign(this.variableConfiguration, variableConfiguration);
}
getConfiguration() {
return this.variableConfiguration;
}
getUrl() {
let replacedUrl = this.url;
for (const [key, value] of Object.entries(this.variableConfiguration)) {
replacedUrl = replacedUrl.replaceAll(`{${key}}`, value);
}
return replacedUrl;
}
makeRequestContext(endpoint, httpMethod) {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
}
};
var server1 = new ServerConfiguration("http://localhost:8080", {});
// src/js-client/configuration.js
function createConfiguration(conf = {}) {
const configuration = {
baseServer: conf.baseServer !== void 0 ? conf.baseServer : server1,
httpApi: conf.httpApi || new IsomorphicFetchHttpLibrary(),
middleware: conf.middleware || [],
authMethods: configureAuthMethods(conf.authMethods)
};
if (conf.promiseMiddleware) {
conf.promiseMiddleware.forEach((m) => configuration.middleware.push(new PromiseMiddlewareWrapper(m)));
}
return configuration;
}
__name(createConfiguration, "createConfiguration");
// src/js-client/apis/exception.js
var ApiException = class extends Error {
static {
__name(this, "ApiException");
}
constructor(code, message, body, headers) {
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body) + "\nHeaders: " + JSON.stringify(headers));
this.code = code;
this.body = body;
this.headers = headers;
}
};
// src/js-client/apis/baseapi.js
var BaseAPIRequestFactory = class {
static {
__name(this, "BaseAPIRequestFactory");
}
constructor(configuration) {
this.configuration = configuration;
}
};
var RequiredError = class extends Error {
static {
__name(this, "RequiredError");
}
constructor(api, method, field) {
super("Required parameter " + field + " was null or undefined when calling " + api + "." + method + ".");
this.api = api;
this.method = method;
this.field = field;
this.name = "RequiredError";
}
};
// src/js-client/models/ObjectSerializer.js
var primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
var enumsMap = /* @__PURE__ */ new Set([]);
var typeMap = {
BinaryData,
CreateEcKeyRequest,
JsonWebKey,
KeyProperties,
KeyReleasePolicy,
KeyVaultKey,
SignPayloadDTO,
SignPayloadResponse,
VerifyPayloadDTO
};
var parseMimeType = /* @__PURE__ */ __name((mimeType) => {
const [type = "", subtype = ""] = mimeType.split("/");
return {
type,
subtype,
subtypeTokens: subtype.split("+")
};
}, "parseMimeType");
var mimeTypePredicateFactory = /* @__PURE__ */ __name((predicate) => (mimeType) => predicate(parseMimeType(mimeType)), "mimeTypePredicateFactory");
var mimeTypeSimplePredicateFactory = /* @__PURE__ */ __name((type, subtype) => mimeTypePredicateFactory((descriptor) => {
if (descriptor.type !== type) return false;
if (subtype != null && descriptor.subtype !== subtype) return false;
return true;
}), "mimeTypeSimplePredicateFactory");
var isTextLikeMimeType = mimeTypeSimplePredicateFactory("text");
var isJsonMimeType = mimeTypeSimplePredicateFactory("application", "json");
var isJsonLikeMimeType = mimeTypePredicateFactory((descriptor) => descriptor.type === "application" && descriptor.subtypeTokens.some((item) => item === "json"));
var isOctetStreamMimeType = mimeTypeSimplePredicateFactory("application", "octet-stream");
var isFormUrlencodedMimeType = mimeTypeSimplePredicateFactory("application", "x-www-form-urlencoded");
var supportedMimeTypePredicatesWithPriority = [
isJsonMimeType,
isJsonLikeMimeType,
isTextLikeMimeType,
isOctetStreamMimeType,
isFormUrlencodedMimeType
];
var nullableSuffix = " | null";
var optionalSuffix = " | undefined";
var arrayPrefix = "Array<";
var arraySuffix = ">";
var mapPrefix = "{ [key: string]: ";
var mapSuffix = "; }";
var ObjectSerializer = class _ObjectSerializer {
static {
__name(this, "ObjectSerializer");
}
static findCorrectType(data, expectedType) {
if (data == void 0) {
return expectedType;
} else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) {
return expectedType;
} else if (expectedType === "Date") {
return expectedType;
} else {
if (enumsMap.has(expectedType)) {
return expectedType;
}
if (!typeMap[expectedType]) {
return expectedType;
}
let discriminatorProperty = typeMap[expectedType].discriminator;
if (discriminatorProperty == null) {
return expectedType;
} else {
if (data[discriminatorProperty]) {
var discriminatorType = data[discriminatorProperty];
let mapping = typeMap[expectedType].mapping;
if (mapping != void 0 && mapping[discriminatorType]) {
return mapping[discriminatorType];
} else if (typeMap[discriminatorType]) {
return discriminatorType;
} else {
return expectedType;
}
} else {
return expectedType;
}
}
}
}
static serialize(data, type, format) {
if (data == void 0) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.endsWith(nullableSuffix)) {
let subType = type.slice(0, -nullableSuffix.length);
return _ObjectSerializer.serialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType = type.slice(0, -optionalSuffix.length);
return _ObjectSerializer.serialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType = type.slice(arrayPrefix.length, -arraySuffix.length);
let transformedData = [];
for (let date of data) {
transformedData.push(_ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType = type.slice(mapPrefix.length, -mapSuffix.length);
let transformedData = {};
for (let key in data) {
transformedData[key] = _ObjectSerializer.serialize(data[key], subType, format);
}
return transformedData;
} else if (type === "Date") {
if (format == "date") {
let month = data.getMonth() + 1;
month = month < 10 ? "0" + month.toString() : month.toString();
let day = data.getDate();
day = day < 10 ? "0" + day.toString() : day.toString();
return data.getFullYear() + "-" + month + "-" + day;
} else {
return data.toISOString();
}
} else {
if (enumsMap.has(type)) {
return data;
}
if (!typeMap[type]) {
return data;
}
type = this.findCorrectType(data, type);
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
for (let attributeType of attributeTypes) {
instance[attributeType.baseName] = _ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format);
}
return instance;
}
}
static deserialize(data, type, format) {
type = _ObjectSerializer.findCorrectType(data, type);
if (data == void 0) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.endsWith(nullableSuffix)) {
let subType = type.slice(0, -nullableSuffix.length);
return _ObjectSerializer.deserialize(data, subType, format);
} else if (type.endsWith(optionalSuffix)) {
let subType = type.slice(0, -optionalSuffix.length);
return _ObjectSerializer.deserialize(data, subType, format);
} else if (type.startsWith(arrayPrefix)) {
let subType = type.slice(arrayPrefix.length, -arraySuffix.length);
let transformedData = [];
for (let date of data) {
transformedData.push(_ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
} else if (type.startsWith(mapPrefix)) {
let subType = type.slice(mapPrefix.length, -mapSuffix.length);
let transformedData = {};
for (let key in data) {
transformedData[key] = _ObjectSerializer.deserialize(data[key], subType, format);
}
return transformedData;
} else if (type === "Date") {
return new Date(data);
} else {
if (enumsMap.has(type)) {
return data;
}
if (!typeMap[type]) {
return data;
}
let instance = new typeMap[type]();
let attributeTypes = typeMap[type].getAttributeTypeMap();
for (let attributeType of attributeTypes) {
let value = _ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format);
if (value !== void 0) {
instance[attributeType.name] = value;
}
}
return instance;
}
}
static normalizeMediaType(mediaType) {
var _a;
if (mediaType === void 0) {
return void 0;
}
return ((_a = mediaType.split(";")[0]) !== null && _a !== void 0 ? _a : "").trim().toLowerCase();
}
static getPreferredMediaType(mediaTypes) {
if (mediaTypes.length === 0) {
return "application/json";
}
const normalMediaTypes = mediaTypes.map(this.normalizeMediaType);
for (const predicate of supportedMimeTypePredicatesWithPriority) {
for (const mediaType of normalMediaTypes) {
if (mediaType != null && predicate(mediaType)) {
return mediaType;
}
}
}
throw new Error("None of the given media types are supported: " + mediaTypes.join(", "));
}
static stringify(data, mediaType) {
if (isTextLikeMimeType(mediaType)) {
return String(data);
}
if (isJsonLikeMimeType(mediaType)) {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
static parse(rawData, mediaType) {
if (mediaType === void 0) {
throw new Error("Cannot parse content. No Content-Type defined.");
}
if (isTextLikeMimeType(mediaType)) {
return rawData;
}
if (isJsonLikeMimeType(mediaType)) {
return JSON.parse(rawData);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse.");
}
};
// src/js-client/util.js
function isCodeInRange(codeRange, code) {
if (codeRange === "0") {
return true;
}
if (codeRange == code.toString()) {
return true;
} else {
const codeString = code.toString();
if (codeString.length != codeRange.length) {
return false;
}
for (let i = 0; i < codeString.length; i++) {
if (codeRange.charAt(i) != "X" && codeRange.charAt(i) != codeString.charAt(i)) {
return false;
}
}
return true;
}
}
__name(isCodeInRange, "isCodeInRange");
// src/js-client/apis/KeyVaultControllerApi.js
var __awaiter2 = function(thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function(resolve) {
resolve(value);
});
}
__name(adopt, "adopt");
return new (P || (P = Promise))(function(resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
__name(fulfilled, "fulfilled");
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
__name(rejected, "rejected");
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
__name(step, "step");
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var KeyVaultControllerApiRequestFactory = class extends BaseAPIRequestFactory {
static {
__name(this, "KeyVaultControllerApiRequestFactory");
}
createEcKey(createEcKeyRequest, _options) {
var _a, _b, _c;
return __awaiter2(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (createEcKeyRequest === null || createEcKeyRequest === void 0) {
throw new RequiredError("KeyVaultControllerApi", "createEcKey", "createEcKeyRequest");
}
const localVarPath = "/api/keys/create-ec-key";
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(ObjectSerializer.serialize(createEcKeyRequest, "CreateEcKeyRequest", ""), contentType);
requestContext.setBody(serializedBody);
let authMethod;
authMethod = _config.authMethods["apiKeyScheme"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext);
}
const defaultAuth = ((_a = _options === null || _options === void 0 ? void 0 : _options.authMethods) === null || _a === void 0 ? void 0 : _a.default) || ((_c = (_b = this.configuration) === null || _b === void 0 ? void 0 : _b.authMethods) === null || _c === void 0 ? void 0 : _c.default);
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext);
}
return requestContext;
});
}
getKey(keyName, _options) {
var _a, _b, _c;
return __awaiter2(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (keyName === null || keyName === void 0) {
throw new RequiredError("KeyVaultControllerApi", "getKey", "keyName");
}
const localVarPath = "/api/keys/{keyName}".replace("{keyName}", encodeURIComponent(String(keyName)));
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
let authMethod;
authMethod = _config.authMethods["apiKeyScheme"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext);
}
const defaultAuth = ((_a = _options === null || _options === void 0 ? void 0 : _options.authMethods) === null || _a === void 0 ? void 0 : _a.default) || ((_c = (_b = this.configuration) === null || _b === void 0 ? void 0 : _b.authMethods) === null || _c === void 0 ? void 0 : _c.default);
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext);
}
return requestContext;
});
}
signPayload(signPayloadDTO, _options) {
var _a, _b, _c;
return __awaiter2(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (signPayloadDTO === null || signPayloadDTO === void 0) {
throw new RequiredError("KeyVaultControllerApi", "signPayload", "signPayloadDTO");
}
const localVarPath = "/api/keys/sign";
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(ObjectSerializer.serialize(signPayloadDTO, "SignPayloadDTO", ""), contentType);
requestContext.setBody(serializedBody);
let authMethod;
authMethod = _config.authMethods["apiKeyScheme"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext);
}
const defaultAuth = ((_a = _options === null || _options === void 0 ? void 0 : _options.authMethods) === null || _a === void 0 ? void 0 : _a.default) || ((_c = (_b = this.configuration) === null || _b === void 0 ? void 0 : _b.authMethods) === null || _c === void 0 ? void 0 : _c.default);
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext);
}
return requestContext;
});
}
verifyPayload(verifyPayloadDTO, _options) {
var _a, _b, _c;
return __awaiter2(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (verifyPayloadDTO === null || verifyPayloadDTO === void 0) {
throw new RequiredError("KeyVaultControllerApi", "verifyPayload", "verifyPayloadDTO");
}
const localVarPath = "/api/keys/verify";
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const contentType = ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(ObjectSerializer.serialize(verifyPayloadDTO, "VerifyPayloadDTO", ""), contentType);
requestContext.setBody(serializedBody);
let authMethod;
authMethod = _config.authMethods["apiKeyScheme"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext);
}
const defaultAuth = ((_a = _options === null || _options === void 0 ? void 0 : _options.authMethods) === null || _a === void 0 ? void 0 : _a.default) || ((_c = (_b = this.configuration) === null || _b === void 0 ? void 0 : _b.authMethods) === null || _c === void 0 ? void 0 : _c.default);
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext);
}
return requestContext;
});
}
};
var KeyVaultControllerApiResponseProcessor = class {
static {
__name(this, "KeyVaultControllerApiResponseProcessor");
}
createEcKeyWithHttpInfo(response) {
return __awaiter2(this, void 0, void 0, function* () {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("201", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("400", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
throw new ApiException(response.httpStatusCode, "Invalid input parameters", body, response.headers);
}
if (isCodeInRange("500", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
throw new ApiException(response.httpStatusCode, "Unexpected error during key creation", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
getKeyWithHttpInfo(response) {
return __awaiter2(this, void 0, void 0, function* () {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("404", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
throw new ApiException(response.httpStatusCode, "Key not found", body, response.headers);
}
if (isCodeInRange("500", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
throw new ApiException(response.httpStatusCode, "Unexpected error during key retrieval", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "KeyVaultKey", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
signPayloadWithHttpInfo(response) {
return __awaiter2(this, void 0, void 0, function* () {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "SignPayloadResponse", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("400", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "SignPayloadResponse", "");
throw new ApiException(response.httpStatusCode, "Invalid input parameters", body, response.headers);
}
if (isCodeInRange("404", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "SignPayloadResponse", "");
throw new ApiException(response.httpStatusCode, "Key not found", body, response.headers);
}
if (isCodeInRange("500", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "SignPayloadResponse", "");
throw new ApiException(response.httpStatusCode, "Unexpected error during signing", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "SignPayloadResponse", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
verifyPayloadWithHttpInfo(response) {
return __awaiter2(this, void 0, void 0, function* () {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "boolean", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("400", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "boolean", "");
throw new ApiException(response.httpStatusCode, "Invalid input parameters", body, response.headers);
}
if (isCodeInRange("404", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "boolean", "");
throw new ApiException(response.httpStatusCode, "Key not found", body, response.headers);
}
if (isCodeInRange("500", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "boolean", "");
throw new ApiException(response.httpStatusCode, "Unexpected error during verification", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(yield response.body.text(), contentType), "boolean", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
};
// src/js-client/types/ObservableAPI.js
var ObservableKeyVaultControllerApi = class {
static {
__name(this, "ObservableKeyVaultControllerApi");
}
constructor(configuration, requestFactory, responseProcessor) {
this.configuration = configuration;
this.requestFactory = requestFactory || new KeyVaultControllerApiRequestFactory(configuration);
this.responseProcessor = responseProcessor || new KeyVaultControllerApiResponseProcessor();
}
createEcKeyWithHttpInfo(createEcKeyRequest, _options) {
const requestContextPromise = this.requestFactory.createEcKey(createEcKeyRequest, _options);
let middlewarePreObservable = from(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx) => this.configuration.httpApi.send(ctx))).pipe(mergeMap((response) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp) => this.responseProcessor.createEcKeyWithHttpInfo(rsp)));
}));
}
createEcKey(createEcKeyRequest, _options) {
return this.createEcKeyWithHttpInfo(createEcKeyRequest, _options).pipe(map((apiResponse) => apiResponse.data));
}
getKeyWithHttpInfo(keyName, _options) {
const requestContextPromise = this.requestFactory.getKey(keyName, _options);
let middlewarePreObservable = from(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx) => this.configuration.httpApi.send(ctx))).pipe(mergeMap((response) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp) => this.responseProcessor.getKeyWithHttpInfo(rsp)));
}));
}
getKey(keyName, _options) {
return this.getKeyWithHttpInfo(keyName, _options).pipe(map((apiResponse) => apiResponse.data));
}
signPayloadWithHttpInfo(signPayloadDTO, _options) {
const requestContextPromise = this.requestFactory.signPayload(signPayloadDTO, _options);
let middlewarePreObservable = from(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx) => this.configuration.httpApi.send(ctx))).pipe(mergeMap((response) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp) => this.responseProcessor.signPayloadWithHttpInfo(rsp)));
}));
}
signPayload(signPayloadDTO, _options) {
return this.signPayloadWithHttpInfo(signPayloadDTO, _options).pipe(map((apiResponse) => apiResponse.data));
}
verifyPayloadWithHttpInfo(verifyPayloadDTO, _options) {
const requestContextPromise = this.requestFactory.verifyPayload(verifyPayloadDTO, _options);
let middlewarePreObservable = from(requestContextPromise);
for (const middleware of this.configuration.middleware) {
middlewarePreObservable = middlewarePreObservable.pipe(mergeMap((ctx) => middleware.pre(ctx)));
}
return middlewarePreObservable.pipe(mergeMap((ctx) => this.configuration.httpApi.send(ctx))).pipe(mergeMap((response) => {
let middlewarePostObservable = of(response);
for (const middleware of this.configuration.middleware) {
middlewarePostObservable = middlewarePostObservable.pipe(mergeMap((rsp) => middleware.post(rsp)));
}
return middlewarePostObservable.pipe(map((rsp) => this.responseProcessor.verifyPayloadWithHttpInfo(rsp)));
}));
}
verifyPayload(verifyPayloadDTO, _options) {
return this.verifyPayloadWithHttpInfo(verifyPayloadDTO, _options).pipe(map((apiResponse) => apiResponse.data));
}
};
// src/js-client/types/PromiseAPI.js
var PromiseKeyVaultControllerApi = class {
static {
__name(this, "PromiseKeyVaultControllerApi");
}
constructor(configuration, requestFactory, responseProcessor) {
this.api = new ObservableKeyVaultControllerApi(configuration, requestFactory, responseProcessor);
}
createEcKeyWithHttpInfo(createEcKeyRequest, _options) {
const result = this.api.createEcKeyWithHttpInfo(createEcKeyRequest, _options);
return result.toPromise();
}
createEcKey(createEcKeyRequest, _options) {
const result = this.api.createEcKey(createEcKeyRequest, _options);
return result.toPromise();
}
getKeyWithHttpInfo(keyName, _options) {
const result = this.api.getKeyWithHttpInfo(keyName, _options);
return result.toPromise();
}
getKey(keyName, _options) {
const result = this.api.getKey(keyName, _options);
return result.toPromise();
}
signPayloadWithHttpInfo(signPayloadDTO, _options) {
const result = this.api.signPayloadWithHttpInfo(signPayloadDTO, _options);
return result.toPromise();
}
signPayload(signPayloadDTO, _options) {
const result = this.api.signPayload(signPayloadDTO, _options);
return result.toPromise();
}
verifyPayloadWithHttpInfo(verifyPayloadDTO, _options) {
const result = this.api.verifyPayloadWithHttpInfo(verifyPayloadDTO, _options);
return result.toPromise();
}
verifyPayload(verifyPayloadDTO, _options) {
const result = this.api.verifyPayload(verifyPayloadDTO, _options);
return result.toPromise();
}
};
// src/AzureKeyVaultKeyManagementSystemRestClient.ts
import * as u8a from "uint8arrays";
var { fromString, toString } = u8a;
var AzureKeyVaultKeyManagementSystemRestClient = class extends AbstractKeyManagementSystem {
static {
__name(this, "AzureKeyVaultKeyManagementSystemRestClient");
}
client;
id;
constructor(options) {
super();
const config = createConfiguration({
baseServer: new ServerConfiguration(options.vaultUrl, {}),
authMethods: {
apiKeyScheme: options.apiKey
}
});
this.id = options.applicationId;
this.client = new PromiseKeyVaultControllerApi(config);
}
async createKey(args) {
const { type, meta } = args;
const curveName = this.mapKeyTypeCurveName(type);
const options = {
keyName: meta?.keyAlias.replace(/_/g, "-"),
curveName,
operations: meta && "keyOperations" in meta ? meta.keyOperations : [
"sign",
"verify"
]
};
const createKeyResponse = await this.client.createEcKey(options);
return {
kid: createKeyResponse.name,
kms: this.id,
type,
meta: {
alias: createKeyResponse.name,
algorithms: [
createKeyResponse.key?.curveName ?? "ES256"
],
kmsKeyRef: createKeyResponse.id
},
publicKeyHex: this.ecJwkToRawHexKey(createKeyResponse.key)
};
}
ecJwkToRawHexKey(jwk) {
if (!jwk.x || !jwk.y) {
throw new Error("EC JWK must contain 'x' and 'y' properties.");
}
const x = fromString(jwk.x.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
const y = fromString(jwk.y.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
return "04" + toString(x, "hex") + toString(y, "hex");
}
mapKeyTypeCurveName = /* @__PURE__ */ __name((type) => {
switch (type) {
case "Secp256r1":
return "P-256";
default:
throw new Error(`Key type ${type} is not supported by AzureKeyVaultKMS`);
}
}, "mapKeyTypeCurveName");
keyTypeToDigestAlgorithm = /* @__PURE__ */ __name((type) => {
switch (type) {
case "Secp256r1":
return "sha256";
default:
throw new Error(`Key type ${type} is not supported by AzureKeyVaultKMS`);
}
}, "keyTypeToDigestAlgorithm");
async sign(args) {
if (!args.keyRef) {
throw new Error("key_not_found: No key ref provided");
}
const signResponse = await this.client.signPayload({
keyName: args.keyRef.kid,
payload: toString(args.data)
});
return signResponse.signature;
}