@pallasoft/ps-utilities 2.17.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,7 +6,7 @@ export interface CreateApiClientOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export interface PsHttpRequestConfig {
|
|
8
8
|
headers?: Record<string, string>;
|
|
9
|
-
responseType?: 'arraybuffer' | 'json' | 'text';
|
|
9
|
+
responseType?: 'arraybuffer' | 'json' | 'stream' | 'text';
|
|
10
10
|
}
|
|
11
11
|
export interface PsHttpResponse<T> {
|
|
12
12
|
data: T;
|
|
@@ -74,6 +74,8 @@ var HttpService = /** @class */ (function () {
|
|
|
74
74
|
return [4 /*yield*/, fetch(fullUrl, { method: method, headers: headers, body: body })];
|
|
75
75
|
case 1:
|
|
76
76
|
response = _b.sent();
|
|
77
|
+
if ((config === null || config === void 0 ? void 0 : config.responseType) === 'stream' && response.ok)
|
|
78
|
+
return [2 /*return*/, { data: response.body, headers: response.headers, status: response.status }];
|
|
77
79
|
return [4 /*yield*/, ((config === null || config === void 0 ? void 0 : config.responseType) === 'arraybuffer'
|
|
78
80
|
? response.arrayBuffer()
|
|
79
81
|
: (config === null || config === void 0 ? void 0 : config.responseType) === 'text'
|
|
@@ -11,6 +11,7 @@ export declare class CryptoService {
|
|
|
11
11
|
private static _dataKeyLength;
|
|
12
12
|
private static _payloadAlgorithm;
|
|
13
13
|
private static _aad;
|
|
14
|
+
static requireKey(key: string | undefined, name: string): string;
|
|
14
15
|
private static _getAdditionalData;
|
|
15
16
|
private static _parsePayload;
|
|
16
17
|
private static _deriveKey;
|
|
@@ -41,6 +41,12 @@ var base64_service_1 = require("./base64-service");
|
|
|
41
41
|
var CryptoService = /** @class */ (function () {
|
|
42
42
|
function CryptoService() {
|
|
43
43
|
}
|
|
44
|
+
CryptoService.requireKey = function (key, name) {
|
|
45
|
+
if (typeof key !== 'string' || key.trim().length === 0) {
|
|
46
|
+
throw new Error("".concat(name, " is required and must not be empty"));
|
|
47
|
+
}
|
|
48
|
+
return key;
|
|
49
|
+
};
|
|
44
50
|
CryptoService._getAdditionalData = function () {
|
|
45
51
|
return this._textEncoder.encode(this._aad);
|
|
46
52
|
};
|
|
@@ -84,6 +90,7 @@ var CryptoService = /** @class */ (function () {
|
|
|
84
90
|
return __generator(this, function (_a) {
|
|
85
91
|
switch (_a.label) {
|
|
86
92
|
case 0:
|
|
93
|
+
this.requireKey(cryptoKey, 'Encryption key');
|
|
87
94
|
iv = crypto.getRandomValues(new Uint8Array(this._ivLength));
|
|
88
95
|
salt = crypto.getRandomValues(new Uint8Array(this._saltLength));
|
|
89
96
|
return [4 /*yield*/, this._deriveKey(cryptoKey, salt)];
|
|
@@ -127,6 +134,7 @@ var CryptoService = /** @class */ (function () {
|
|
|
127
134
|
return __generator(this, function (_d) {
|
|
128
135
|
switch (_d.label) {
|
|
129
136
|
case 0:
|
|
137
|
+
this.requireKey(dataKey, 'Data key');
|
|
130
138
|
iv = crypto.getRandomValues(new Uint8Array(this._ivLength));
|
|
131
139
|
_b = (_a = crypto.subtle).encrypt;
|
|
132
140
|
_c = [{ name: this._algorithm, iv: iv, additionalData: this._getAdditionalData() }];
|
|
@@ -150,6 +158,7 @@ var CryptoService = /** @class */ (function () {
|
|
|
150
158
|
return __generator(this, function (_d) {
|
|
151
159
|
switch (_d.label) {
|
|
152
160
|
case 0:
|
|
161
|
+
this.requireKey(dataKey, 'Data key');
|
|
153
162
|
payload = this._parsePayload(encryptedPayload);
|
|
154
163
|
_b = (_a = crypto.subtle).decrypt;
|
|
155
164
|
_c = [{
|
|
@@ -227,6 +236,7 @@ var CryptoService = /** @class */ (function () {
|
|
|
227
236
|
return __generator(this, function (_a) {
|
|
228
237
|
switch (_a.label) {
|
|
229
238
|
case 0:
|
|
239
|
+
this.requireKey(cryptoKey, 'Encryption key');
|
|
230
240
|
payload = this._parsePayload(encryptedPayload);
|
|
231
241
|
return [4 /*yield*/, this._deriveKey(cryptoKey, base64_service_1.Base64Service.decode(payload.salt))];
|
|
232
242
|
case 1:
|
|
@@ -55,6 +55,7 @@ var EnvelopeCryptoService = /** @class */ (function () {
|
|
|
55
55
|
return __generator(this, function (_a) {
|
|
56
56
|
switch (_a.label) {
|
|
57
57
|
case 0:
|
|
58
|
+
crypto_service_1.CryptoService.requireKey(masterKey, 'Master key');
|
|
58
59
|
dataKey = crypto_service_1.CryptoService.generateDataKey();
|
|
59
60
|
return [4 /*yield*/, crypto_service_1.CryptoService.encryptValue(dataKey, masterKey)];
|
|
60
61
|
case 1:
|
|
@@ -71,6 +72,7 @@ var EnvelopeCryptoService = /** @class */ (function () {
|
|
|
71
72
|
return __generator(this, function (_a) {
|
|
72
73
|
switch (_a.label) {
|
|
73
74
|
case 0:
|
|
75
|
+
crypto_service_1.CryptoService.requireKey(masterKey, 'Master key');
|
|
74
76
|
cached = this._cache.get(wrappedDataKey);
|
|
75
77
|
if (cached)
|
|
76
78
|
return [2 /*return*/, cached];
|