@pallasoft/ps-utilities 2.15.0 → 2.16.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.
- package/dist/common/base64-service.d.ts +4 -0
- package/dist/common/base64-service.js +24 -0
- package/dist/common/constants/http-auth-scheme.d.ts +3 -0
- package/dist/common/constants/http-auth-scheme.js +6 -0
- package/dist/common/constants/http-header.d.ts +3 -0
- package/dist/common/constants/http-header.js +3 -0
- package/dist/common/constants/index.d.ts +1 -0
- package/dist/common/constants/index.js +1 -0
- package/dist/common/crypto-service.d.ts +0 -2
- package/dist/common/crypto-service.js +13 -27
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +1 -0
- package/dist/common/signed-token-service.d.ts +0 -2
- package/dist/common/signed-token-service.js +7 -21
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base64Service = void 0;
|
|
4
|
+
var Base64Service = /** @class */ (function () {
|
|
5
|
+
function Base64Service() {
|
|
6
|
+
}
|
|
7
|
+
Base64Service.encode = function (bytes) {
|
|
8
|
+
var binary = '';
|
|
9
|
+
for (var index = 0; index < bytes.length; index += 1) {
|
|
10
|
+
binary += String.fromCharCode(bytes[index]);
|
|
11
|
+
}
|
|
12
|
+
return btoa(binary);
|
|
13
|
+
};
|
|
14
|
+
Base64Service.decode = function (value) {
|
|
15
|
+
var binary = atob(value.trim());
|
|
16
|
+
var bytes = new Uint8Array(new ArrayBuffer(binary.length));
|
|
17
|
+
for (var index = 0; index < binary.length; index += 1) {
|
|
18
|
+
bytes[index] = binary.charCodeAt(index);
|
|
19
|
+
}
|
|
20
|
+
return bytes;
|
|
21
|
+
};
|
|
22
|
+
return Base64Service;
|
|
23
|
+
}());
|
|
24
|
+
exports.Base64Service = Base64Service;
|
|
@@ -11,8 +11,11 @@ export declare const HttpHeader: {
|
|
|
11
11
|
readonly cookie: "Cookie";
|
|
12
12
|
readonly forwardedFor: "X-Forwarded-For";
|
|
13
13
|
readonly frameOptions: "X-Frame-Options";
|
|
14
|
+
readonly idempotencyKey: "Idempotency-Key";
|
|
14
15
|
readonly location: "Location";
|
|
16
|
+
readonly prefer: "Prefer";
|
|
15
17
|
readonly realIp: "X-Real-IP";
|
|
18
|
+
readonly retryAfter: "Retry-After";
|
|
16
19
|
readonly robotsTag: "X-Robots-Tag";
|
|
17
20
|
readonly setCookie: "Set-Cookie";
|
|
18
21
|
readonly strictTransportSecurity: "Strict-Transport-Security";
|
|
@@ -14,8 +14,11 @@ exports.HttpHeader = {
|
|
|
14
14
|
cookie: 'Cookie',
|
|
15
15
|
forwardedFor: 'X-Forwarded-For',
|
|
16
16
|
frameOptions: 'X-Frame-Options',
|
|
17
|
+
idempotencyKey: 'Idempotency-Key',
|
|
17
18
|
location: 'Location',
|
|
19
|
+
prefer: 'Prefer',
|
|
18
20
|
realIp: 'X-Real-IP',
|
|
21
|
+
retryAfter: 'Retry-After',
|
|
19
22
|
robotsTag: 'X-Robots-Tag',
|
|
20
23
|
setCookie: 'Set-Cookie',
|
|
21
24
|
strictTransportSecurity: 'Strict-Transport-Security',
|
|
@@ -10,6 +10,7 @@ export * from './socket-token-config';
|
|
|
10
10
|
export * from './user-agent-config';
|
|
11
11
|
export * from './amount-direction';
|
|
12
12
|
export * from './error-response-config';
|
|
13
|
+
export * from './http-auth-scheme';
|
|
13
14
|
export * from './http-content-type';
|
|
14
15
|
export * from './http-header';
|
|
15
16
|
export * from './http-method';
|
|
@@ -26,6 +26,7 @@ __exportStar(require("./socket-token-config"), exports);
|
|
|
26
26
|
__exportStar(require("./user-agent-config"), exports);
|
|
27
27
|
__exportStar(require("./amount-direction"), exports);
|
|
28
28
|
__exportStar(require("./error-response-config"), exports);
|
|
29
|
+
__exportStar(require("./http-auth-scheme"), exports);
|
|
29
30
|
__exportStar(require("./http-content-type"), exports);
|
|
30
31
|
__exportStar(require("./http-header"), exports);
|
|
31
32
|
__exportStar(require("./http-method"), exports);
|
|
@@ -11,8 +11,6 @@ export declare class CryptoService {
|
|
|
11
11
|
private static _dataKeyLength;
|
|
12
12
|
private static _payloadAlgorithm;
|
|
13
13
|
private static _aad;
|
|
14
|
-
private static _toBase64;
|
|
15
|
-
private static _fromBase64;
|
|
16
14
|
private static _getAdditionalData;
|
|
17
15
|
private static _parsePayload;
|
|
18
16
|
private static _deriveKey;
|
|
@@ -37,24 +37,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.CryptoService = void 0;
|
|
40
|
+
var base64_service_1 = require("./base64-service");
|
|
40
41
|
var CryptoService = /** @class */ (function () {
|
|
41
42
|
function CryptoService() {
|
|
42
43
|
}
|
|
43
|
-
CryptoService._toBase64 = function (bytes) {
|
|
44
|
-
var binary = '';
|
|
45
|
-
for (var index = 0; index < bytes.length; index += 1) {
|
|
46
|
-
binary += String.fromCharCode(bytes[index]);
|
|
47
|
-
}
|
|
48
|
-
return btoa(binary);
|
|
49
|
-
};
|
|
50
|
-
CryptoService._fromBase64 = function (value) {
|
|
51
|
-
var binary = atob(value);
|
|
52
|
-
var bytes = new Uint8Array(binary.length);
|
|
53
|
-
for (var index = 0; index < binary.length; index += 1) {
|
|
54
|
-
bytes[index] = binary.charCodeAt(index);
|
|
55
|
-
}
|
|
56
|
-
return bytes;
|
|
57
|
-
};
|
|
58
44
|
CryptoService._getAdditionalData = function () {
|
|
59
45
|
return this._textEncoder.encode(this._aad);
|
|
60
46
|
};
|
|
@@ -113,9 +99,9 @@ var CryptoService = /** @class */ (function () {
|
|
|
113
99
|
serializedPayload = {
|
|
114
100
|
v: this._payloadVersion,
|
|
115
101
|
alg: this._payloadAlgorithm,
|
|
116
|
-
iv:
|
|
117
|
-
salt:
|
|
118
|
-
ciphertext:
|
|
102
|
+
iv: base64_service_1.Base64Service.encode(iv),
|
|
103
|
+
salt: base64_service_1.Base64Service.encode(salt),
|
|
104
|
+
ciphertext: base64_service_1.Base64Service.encode(new Uint8Array(encryptedBuffer)),
|
|
119
105
|
};
|
|
120
106
|
return [2 /*return*/, JSON.stringify(serializedPayload)];
|
|
121
107
|
}
|
|
@@ -126,14 +112,14 @@ var CryptoService = /** @class */ (function () {
|
|
|
126
112
|
return __awaiter(this, void 0, void 0, function () {
|
|
127
113
|
return __generator(this, function (_a) {
|
|
128
114
|
switch (_a.label) {
|
|
129
|
-
case 0: return [4 /*yield*/, crypto.subtle.importKey('raw',
|
|
115
|
+
case 0: return [4 /*yield*/, crypto.subtle.importKey('raw', base64_service_1.Base64Service.decode(dataKey), { name: this._algorithm, length: this._keyLength }, false, ['encrypt', 'decrypt'])];
|
|
130
116
|
case 1: return [2 /*return*/, _a.sent()];
|
|
131
117
|
}
|
|
132
118
|
});
|
|
133
119
|
});
|
|
134
120
|
};
|
|
135
121
|
CryptoService.generateDataKey = function () {
|
|
136
|
-
return
|
|
122
|
+
return base64_service_1.Base64Service.encode(crypto.getRandomValues(new Uint8Array(this._dataKeyLength)));
|
|
137
123
|
};
|
|
138
124
|
CryptoService.encryptPayloadWithDataKey = function (payload, dataKey) {
|
|
139
125
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -151,8 +137,8 @@ var CryptoService = /** @class */ (function () {
|
|
|
151
137
|
return [2 /*return*/, JSON.stringify({
|
|
152
138
|
v: this._dataKeyPayloadVersion,
|
|
153
139
|
alg: this._payloadAlgorithm,
|
|
154
|
-
iv:
|
|
155
|
-
ciphertext:
|
|
140
|
+
iv: base64_service_1.Base64Service.encode(iv),
|
|
141
|
+
ciphertext: base64_service_1.Base64Service.encode(new Uint8Array(encryptedBuffer)),
|
|
156
142
|
})];
|
|
157
143
|
}
|
|
158
144
|
});
|
|
@@ -168,11 +154,11 @@ var CryptoService = /** @class */ (function () {
|
|
|
168
154
|
_b = (_a = crypto.subtle).decrypt;
|
|
169
155
|
_c = [{
|
|
170
156
|
name: this._algorithm,
|
|
171
|
-
iv:
|
|
157
|
+
iv: base64_service_1.Base64Service.decode(payload.iv),
|
|
172
158
|
additionalData: this._getAdditionalData(),
|
|
173
159
|
}];
|
|
174
160
|
return [4 /*yield*/, this._importDataKey(dataKey)];
|
|
175
|
-
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent(),
|
|
161
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent(), base64_service_1.Base64Service.decode(payload.ciphertext)]))];
|
|
176
162
|
case 2:
|
|
177
163
|
decryptedBuffer = _d.sent();
|
|
178
164
|
return [2 /*return*/, JSON.parse(this._textDecoder.decode(decryptedBuffer))];
|
|
@@ -242,14 +228,14 @@ var CryptoService = /** @class */ (function () {
|
|
|
242
228
|
switch (_a.label) {
|
|
243
229
|
case 0:
|
|
244
230
|
payload = this._parsePayload(encryptedPayload);
|
|
245
|
-
return [4 /*yield*/, this._deriveKey(cryptoKey,
|
|
231
|
+
return [4 /*yield*/, this._deriveKey(cryptoKey, base64_service_1.Base64Service.decode(payload.salt))];
|
|
246
232
|
case 1:
|
|
247
233
|
key = _a.sent();
|
|
248
234
|
return [4 /*yield*/, crypto.subtle.decrypt({
|
|
249
235
|
name: this._algorithm,
|
|
250
|
-
iv:
|
|
236
|
+
iv: base64_service_1.Base64Service.decode(payload.iv),
|
|
251
237
|
additionalData: this._getAdditionalData(),
|
|
252
|
-
}, key,
|
|
238
|
+
}, key, base64_service_1.Base64Service.decode(payload.ciphertext))];
|
|
253
239
|
case 2:
|
|
254
240
|
decryptedBuffer = _a.sent();
|
|
255
241
|
return [2 /*return*/, JSON.parse(this._textDecoder.decode(decryptedBuffer))];
|
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./amount-service"), exports);
|
|
18
|
+
__exportStar(require("./base64-service"), exports);
|
|
18
19
|
__exportStar(require("./color-service"), exports);
|
|
19
20
|
__exportStar(require("./constants"), exports);
|
|
20
21
|
__exportStar(require("./crypto-service"), exports);
|
|
@@ -12,8 +12,6 @@ export declare class SignedTokenService {
|
|
|
12
12
|
private static _remember;
|
|
13
13
|
private static _encodeJson;
|
|
14
14
|
private static _decodeJson;
|
|
15
|
-
private static _toBase64;
|
|
16
|
-
private static _fromBase64;
|
|
17
15
|
private static _toBase64Url;
|
|
18
16
|
private static _fromBase64Url;
|
|
19
17
|
}
|
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.SignedTokenService = void 0;
|
|
40
|
+
var base64_service_1 = require("./base64-service");
|
|
40
41
|
var signed_token_config_1 = require("./constants/signed-token-config");
|
|
41
42
|
var SignedTokenService = /** @class */ (function () {
|
|
42
43
|
function SignedTokenService() {
|
|
@@ -59,8 +60,8 @@ var SignedTokenService = /** @class */ (function () {
|
|
|
59
60
|
case 3:
|
|
60
61
|
publicKey = _a.sent();
|
|
61
62
|
return [2 /*return*/, {
|
|
62
|
-
privateKey:
|
|
63
|
-
publicKey:
|
|
63
|
+
privateKey: base64_service_1.Base64Service.encode(new Uint8Array(privateKey)),
|
|
64
|
+
publicKey: base64_service_1.Base64Service.encode(new Uint8Array(publicKey)),
|
|
64
65
|
}];
|
|
65
66
|
}
|
|
66
67
|
});
|
|
@@ -142,7 +143,7 @@ var SignedTokenService = /** @class */ (function () {
|
|
|
142
143
|
cached = this._privateKeys.get(privateKey);
|
|
143
144
|
if (cached !== undefined)
|
|
144
145
|
return [2 /*return*/, cached];
|
|
145
|
-
return [4 /*yield*/, crypto.subtle.importKey(signed_token_config_1.SignedTokenConfig.privateKeyFormat,
|
|
146
|
+
return [4 /*yield*/, crypto.subtle.importKey(signed_token_config_1.SignedTokenConfig.privateKeyFormat, base64_service_1.Base64Service.decode(privateKey), signed_token_config_1.SignedTokenConfig.keyAlgorithm, false, ['sign'])];
|
|
146
147
|
case 1:
|
|
147
148
|
key = _a.sent();
|
|
148
149
|
this._remember(this._privateKeys, privateKey, key);
|
|
@@ -160,7 +161,7 @@ var SignedTokenService = /** @class */ (function () {
|
|
|
160
161
|
cached = this._publicKeys.get(publicKey);
|
|
161
162
|
if (cached !== undefined)
|
|
162
163
|
return [2 /*return*/, cached];
|
|
163
|
-
return [4 /*yield*/, crypto.subtle.importKey(signed_token_config_1.SignedTokenConfig.publicKeyFormat,
|
|
164
|
+
return [4 /*yield*/, crypto.subtle.importKey(signed_token_config_1.SignedTokenConfig.publicKeyFormat, base64_service_1.Base64Service.decode(publicKey), signed_token_config_1.SignedTokenConfig.keyAlgorithm, false, ['verify'])];
|
|
164
165
|
case 1:
|
|
165
166
|
key = _a.sent();
|
|
166
167
|
this._remember(this._publicKeys, publicKey, key);
|
|
@@ -194,23 +195,8 @@ var SignedTokenService = /** @class */ (function () {
|
|
|
194
195
|
return null;
|
|
195
196
|
}
|
|
196
197
|
};
|
|
197
|
-
SignedTokenService._toBase64 = function (bytes) {
|
|
198
|
-
var binary = '';
|
|
199
|
-
for (var index = 0; index < bytes.length; index += 1) {
|
|
200
|
-
binary += String.fromCharCode(bytes[index]);
|
|
201
|
-
}
|
|
202
|
-
return btoa(binary);
|
|
203
|
-
};
|
|
204
|
-
SignedTokenService._fromBase64 = function (value) {
|
|
205
|
-
var binary = atob(value.trim());
|
|
206
|
-
var bytes = new Uint8Array(binary.length);
|
|
207
|
-
for (var index = 0; index < binary.length; index += 1) {
|
|
208
|
-
bytes[index] = binary.charCodeAt(index);
|
|
209
|
-
}
|
|
210
|
-
return bytes;
|
|
211
|
-
};
|
|
212
198
|
SignedTokenService._toBase64Url = function (bytes) {
|
|
213
|
-
return
|
|
199
|
+
return base64_service_1.Base64Service.encode(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
214
200
|
};
|
|
215
201
|
SignedTokenService._fromBase64Url = function (value) {
|
|
216
202
|
if (!/^[A-Za-z0-9_-]*$/.test(value))
|
|
@@ -218,7 +204,7 @@ var SignedTokenService = /** @class */ (function () {
|
|
|
218
204
|
var base64 = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
219
205
|
var padding = base64.length % 4 === 0 ? '' : '='.repeat(4 - (base64.length % 4));
|
|
220
206
|
try {
|
|
221
|
-
return
|
|
207
|
+
return base64_service_1.Base64Service.decode("".concat(base64).concat(padding));
|
|
222
208
|
}
|
|
223
209
|
catch (_a) {
|
|
224
210
|
return null;
|