perimeterx-js-core 0.7.0 → 0.8.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/lib/action/utils.js +1 -1
- package/lib/activities/HttpActivityClient.d.ts +5 -5
- package/lib/activities/HttpActivityClient.js +28 -39
- package/lib/activities/HttpBatchedActivityClient.d.ts +2 -2
- package/lib/activities/HttpBatchedActivityClient.js +19 -32
- package/lib/activities/model/AsyncActivity.d.ts +14 -0
- package/lib/activities/model/{ActivityDetails.d.ts → AsyncActivityDetails.d.ts} +6 -23
- package/lib/activities/model/CommonActivityDetails.d.ts +40 -0
- package/lib/activities/model/CommonActivityDetails.js +1 -0
- package/lib/activities/model/HeaderEntry.d.ts +4 -0
- package/lib/activities/model/HeaderEntry.js +1 -0
- package/lib/activities/model/index.d.ts +4 -2
- package/lib/activities/model/index.js +4 -2
- package/lib/activities/utils.d.ts +6071 -9
- package/lib/activities/utils.js +111 -35
- package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +4 -12
- package/lib/config/ConfigurationParams.d.ts +2 -1
- package/lib/config/DefaultConfigurations.js +1 -0
- package/lib/config/IConfiguration.d.ts +5 -1
- package/lib/config/StaticConfigurationBase.d.ts +2 -1
- package/lib/config/StaticConfigurationBase.js +6 -1
- package/lib/context/DefaultContext.d.ts +1 -1
- package/lib/context/DefaultContext.js +40 -8
- package/lib/context/interfaces/RiskApiData.d.ts +4 -0
- package/lib/cors/DefaultCors.js +21 -31
- package/lib/custom_parameters/CustomParametersUtils.js +3 -12
- package/lib/enforcer/EnforcerBase.d.ts +2 -1
- package/lib/enforcer/EnforcerBase.js +56 -57
- package/lib/enforcer/options/EnforcerBaseOptions.d.ts +2 -0
- package/lib/graphql/DefaultGraphQLParser.js +30 -39
- package/lib/http/index.d.ts +0 -1
- package/lib/http/index.js +0 -1
- package/lib/http/interfaces/IBody.d.ts +3 -2
- package/lib/http/interfaces/IIncomingRequest.d.ts +4 -0
- package/lib/http/interfaces/IURL.d.ts +3 -0
- package/lib/http/interfaces/IURLSearchParams.d.ts +9 -0
- package/lib/http/interfaces/IURLSearchParams.js +1 -0
- package/lib/http/interfaces/index.d.ts +1 -0
- package/lib/http/interfaces/index.js +1 -0
- package/lib/http/{impl → utils}/FormDataImpl.js +4 -4
- package/lib/http/{impl → utils}/MinimalResponseImpl.js +3 -0
- package/lib/http/utils/MinimalResponseUtils.js +5 -7
- package/lib/http/utils/MultipartFormDataUtils.js +4 -5
- package/lib/http/{impl → utils}/OutgoingRequestImpl.d.ts +1 -1
- package/lib/http/{impl → utils}/OutgoingRequestImpl.js +5 -1
- package/lib/http/utils/URLUtils.d.ts +7 -0
- package/lib/http/utils/URLUtils.js +62 -0
- package/lib/http/utils/UrlImpl.d.ts +18 -0
- package/lib/http/utils/UrlImpl.js +54 -0
- package/lib/http/utils/UrlSearchParamsImpl.d.ts +19 -0
- package/lib/http/utils/UrlSearchParamsImpl.js +116 -0
- package/lib/http/utils/index.d.ts +6 -0
- package/lib/http/utils/index.js +6 -0
- package/lib/{utils → impl}/base64/AtobBase64Utils.d.ts +1 -1
- package/lib/{utils → impl}/base64/BufferBase64Utils.d.ts +1 -1
- package/lib/{utils → impl}/base64/BufferBase64Utils.js +1 -1
- package/lib/{utils → impl}/base64/JSBase64Base64Utils.d.ts +1 -1
- package/lib/{utils → impl}/cipher/CryptoCipherUtils.d.ts +1 -1
- package/lib/impl/cipher/CryptoCipherUtils.js +18 -0
- package/lib/{utils → impl}/cipher/SubtleCryptoCipherUtils.d.ts +1 -2
- package/lib/impl/cipher/SubtleCryptoCipherUtils.js +38 -0
- package/lib/{utils → impl}/hash/CryptoHashUtils.d.ts +1 -2
- package/lib/impl/hash/CryptoHashUtils.js +10 -0
- package/lib/{utils → impl}/hash/CryptoJSHashUtils.d.ts +1 -2
- package/lib/{utils → impl}/hash/CryptoJSHashUtils.js +1 -1
- package/lib/{utils → impl}/hash/SubtleCryptoHashUtils.d.ts +1 -2
- package/lib/impl/hash/SubtleCryptoHashUtils.js +21 -0
- package/lib/{utils → impl}/hmac/CryptoHmacUtils.d.ts +1 -2
- package/lib/{utils → impl}/hmac/CryptoHmacUtils.js +2 -1
- package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.d.ts +1 -2
- package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.js +1 -1
- package/lib/{http/impl → impl/http}/phin/PhinHttpClient.d.ts +1 -1
- package/lib/impl/http/phin/PhinHttpClient.js +31 -0
- package/lib/{http/impl → impl/http}/phin/PhinIncomingResponse.d.ts +2 -2
- package/lib/impl/http/phin/PhinIncomingResponse.js +23 -0
- package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.d.ts +1 -1
- package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.d.ts +1 -1
- package/lib/{utils → impl}/url_parser/DefaultUrlParser.d.ts +4 -4
- package/lib/{utils → impl}/url_parser/DefaultUrlParser.js +9 -2
- package/lib/logger/HttpLogServiceClient.d.ts +17 -0
- package/lib/logger/HttpLogServiceClient.js +52 -0
- package/lib/logger/ILogServiceClient.d.ts +6 -0
- package/lib/logger/ILogServiceClient.js +1 -0
- package/lib/logger/ILogger.d.ts +6 -0
- package/lib/logger/LoggerBase.d.ts +6 -2
- package/lib/logger/LoggerBase.js +14 -1
- package/lib/logger/constants.d.ts +2 -0
- package/lib/logger/constants.js +2 -0
- package/lib/logger/index.d.ts +4 -0
- package/lib/logger/index.js +3 -0
- package/lib/logger/model/EnrichedLogRecord.d.ts +3 -0
- package/lib/logger/model/EnrichedLogRecord.js +1 -0
- package/lib/logger/model/LogMetadata.d.ts +9 -0
- package/lib/logger/model/LogMetadata.js +1 -0
- package/lib/logger/model/LogRecord.d.ts +6 -0
- package/lib/logger/model/LogRecord.js +1 -0
- package/lib/logger/model/index.d.ts +3 -0
- package/lib/logger/model/index.js +3 -0
- package/lib/phase/flow/EndEnforcerFlow.d.ts +6 -0
- package/lib/phase/flow/EndEnforcerFlow.js +10 -0
- package/lib/phase/flow/index.d.ts +1 -0
- package/lib/phase/flow/index.js +1 -0
- package/lib/phase/impl/AdditionalActivityHandlerPhase.js +4 -15
- package/lib/phase/impl/CompositePhase.js +9 -19
- package/lib/phase/impl/CreateBlockResponsePhase.js +24 -35
- package/lib/phase/impl/DecideActionPhase.js +11 -21
- package/lib/phase/impl/EnrichContextFromRequestPhase.js +28 -45
- package/lib/phase/impl/EnrichContextFromResponsePhase.js +12 -23
- package/lib/phase/impl/FilterPhase.js +3 -13
- package/lib/phase/impl/FirstPartyPhase.js +21 -32
- package/lib/phase/impl/ModifyIncomingRequestPhase.js +4 -14
- package/lib/phase/impl/ModifyOutgoingResponsePhase.js +7 -18
- package/lib/phase/impl/ParseTokenPhase.js +5 -15
- package/lib/phase/impl/PreflightPhase.js +12 -20
- package/lib/phase/impl/RiskApiPhase.js +24 -36
- package/lib/phase/impl/SendAsyncActivitiesOnRequestPhase.js +8 -20
- package/lib/phase/impl/SendAsyncActivitiesOnResponsePhase.js +4 -14
- package/lib/phase/impl/SendLogsPhase.d.ts +11 -0
- package/lib/phase/impl/SendLogsPhase.js +16 -0
- package/lib/phase/impl/TelemetryPhase.js +9 -21
- package/lib/phase/impl/index.d.ts +1 -0
- package/lib/phase/impl/index.js +1 -0
- package/lib/products/account_defender/AccountDefender.js +16 -35
- package/lib/products/bot_defender/BotDefender.js +51 -72
- package/lib/products/bot_defender/BotDefenderActionData.js +2 -0
- package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.d.ts +4 -4
- package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.js +5 -3
- package/lib/products/bot_defender/block/captcha/CaptchaBlocker.d.ts +7 -4
- package/lib/products/bot_defender/block/captcha/CaptchaBlocker.js +12 -8
- package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +1 -1
- package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +1 -0
- package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +1 -1
- package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +5 -4
- package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.d.ts +2 -2
- package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.js +2 -0
- package/lib/products/bot_defender/block/utils.js +1 -2
- package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +7 -1
- package/lib/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +51 -68
- package/lib/products/bot_defender/first_party/constants.d.ts +0 -4
- package/lib/products/bot_defender/first_party/constants.js +0 -7
- package/lib/products/credential_intelligence/CredentialIntelligence.js +42 -63
- package/lib/products/credential_intelligence/endpoint/CredentialEndpoint.js +15 -23
- package/lib/products/credential_intelligence/endpoint/CredentialEndpointManager.js +9 -22
- package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +5 -5
- package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +22 -33
- package/lib/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +8 -18
- package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +2 -0
- package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +11 -16
- package/lib/products/credential_intelligence/endpoint/hash_protocol/MultistepHashProtocol.js +11 -21
- package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepAndMultistepHashProtocol.js +9 -18
- package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepHashProtocol.js +13 -25
- package/lib/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -14
- package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulParser.js +10 -20
- package/lib/products/credential_intelligence/endpoint/login_successful/HeaderLoginSuccessfulParser.js +7 -16
- package/lib/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +7 -6
- package/lib/products/credential_intelligence/endpoint/login_successful/StatusLoginSuccessfulParser.js +3 -13
- package/lib/products/credential_intelligence/endpoint/matcher/ExactPathEndpointMatcher.js +2 -0
- package/lib/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +2 -0
- package/lib/pxde/DefaultDataEnrichment.js +47 -61
- package/lib/pxhd/PXHDUtils.js +2 -2
- package/lib/risk_api/client/PostRiskApiClientBase.d.ts +7 -12
- package/lib/risk_api/client/PostRiskApiClientBase.js +70 -171
- package/lib/risk_api/model/RiskActivity.d.ts +5 -45
- package/lib/risk_api/risk_response/IRiskResponse.d.ts +1 -0
- package/lib/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
- package/lib/risk_api/risk_response/RiskResponseBase.js +20 -33
- package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.d.ts +1 -1
- package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.js +3 -5
- package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -0
- package/lib/risk_api/risk_response/v3/DefaultRiskResponseV3.js +2 -4
- package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -0
- package/lib/risk_token/parser/TokenParserBase.js +25 -36
- package/lib/risk_token/token/TokenBase.js +24 -29
- package/lib/risk_token/token/v2/DefaultTokenV2.js +34 -49
- package/lib/risk_token/token/v3/DefaultTokenV3.js +63 -77
- package/lib/telemetry/DefaultTelemetry.js +46 -58
- package/lib/utils/base64/index.d.ts +0 -3
- package/lib/utils/base64/index.js +0 -3
- package/lib/utils/cipher/index.d.ts +1 -3
- package/lib/utils/cipher/index.js +1 -2
- package/lib/utils/constants.d.ts +2 -1
- package/lib/utils/constants.js +2 -1
- package/lib/utils/hash/index.d.ts +0 -3
- package/lib/utils/hash/index.js +0 -3
- package/lib/utils/hmac/index.d.ts +0 -2
- package/lib/utils/hmac/index.js +0 -2
- package/lib/utils/ip_range_checker/index.d.ts +1 -2
- package/lib/utils/ip_range_checker/index.js +1 -1
- package/lib/utils/request_id_generator/index.d.ts +1 -2
- package/lib/utils/request_id_generator/index.js +1 -1
- package/lib/utils/url_parser/index.d.ts +0 -1
- package/lib/utils/url_parser/index.js +0 -1
- package/lib/utils/utils.d.ts +1 -7
- package/lib/utils/utils.js +3 -25
- package/package.json +12 -6
- package/lib/activities/model/Activity.d.ts +0 -13
- package/lib/http/impl/index.d.ts +0 -4
- package/lib/http/impl/index.js +0 -4
- package/lib/http/impl/phin/PhinHttpClient.js +0 -41
- package/lib/http/impl/phin/PhinIncomingResponse.js +0 -38
- package/lib/utils/cipher/CryptoCipherUtils.js +0 -28
- package/lib/utils/cipher/SubtleCryptoCipherUtils.js +0 -47
- package/lib/utils/hash/CryptoHashUtils.js +0 -20
- package/lib/utils/hash/SubtleCryptoHashUtils.js +0 -31
- /package/lib/activities/model/{Activity.js → AsyncActivity.js} +0 -0
- /package/lib/activities/model/{ActivityDetails.js → AsyncActivityDetails.js} +0 -0
- /package/lib/http/{impl → utils}/FormDataImpl.d.ts +0 -0
- /package/lib/http/{impl → utils}/MinimalResponseImpl.d.ts +0 -0
- /package/lib/{utils → impl}/base64/AtobBase64Utils.js +0 -0
- /package/lib/{utils → impl}/base64/JSBase64Base64Utils.js +0 -0
- /package/lib/{http/impl → impl/http}/phin/index.d.ts +0 -0
- /package/lib/{http/impl → impl/http}/phin/index.js +0 -0
- /package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.js +0 -0
- /package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.js +0 -0
package/package.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perimeterx-js-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
|
|
6
|
+
"typesVersions": {
|
|
7
|
+
"*": {
|
|
8
|
+
"*": ["lib/*"]
|
|
9
|
+
}
|
|
10
|
+
},
|
|
9
11
|
"files": [
|
|
10
12
|
"lib/**/*"
|
|
11
13
|
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./lib/index.js",
|
|
16
|
+
"./impl/*": "./lib/impl/*.js"
|
|
17
|
+
},
|
|
12
18
|
"sideEffects": false,
|
|
13
19
|
"scripts": {
|
|
14
20
|
"build": "tsc",
|
|
@@ -42,10 +48,10 @@
|
|
|
42
48
|
"chai-as-promised": "^7.1.1",
|
|
43
49
|
"core-js": "^3.19.1",
|
|
44
50
|
"eslint": "^8.25.0",
|
|
45
|
-
"eslint-config-prettier": "^
|
|
51
|
+
"eslint-config-prettier": "^9.0.0",
|
|
46
52
|
"eslint-plugin-prettier": "^4.2.1",
|
|
47
53
|
"husky": "^8.0.3",
|
|
48
|
-
"lint-staged": "^
|
|
54
|
+
"lint-staged": "^14.0.1",
|
|
49
55
|
"mocha": "^10.0.0",
|
|
50
56
|
"nyc": "^15.1.0",
|
|
51
57
|
"prettier": "^2.7.1",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ActivityType } from '../ActivityType';
|
|
2
|
-
import { ActivityDetails } from './ActivityDetails';
|
|
3
|
-
export type Activity = {
|
|
4
|
-
type: ActivityType;
|
|
5
|
-
timestamp: number;
|
|
6
|
-
socket_ip: string;
|
|
7
|
-
url: string;
|
|
8
|
-
px_app_id: string;
|
|
9
|
-
headers?: Record<string, string>;
|
|
10
|
-
vid?: string;
|
|
11
|
-
pxhd?: string;
|
|
12
|
-
details: ActivityDetails;
|
|
13
|
-
};
|
package/lib/http/impl/index.d.ts
DELETED
package/lib/http/impl/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Agent as HttpAgent } from 'http';
|
|
11
|
-
import { Agent as HttpsAgent } from 'https';
|
|
12
|
-
import phin from 'phin';
|
|
13
|
-
import { EnforcerTimeoutError } from '../../../utils';
|
|
14
|
-
import { joinHeaderValues } from '../../interfaces';
|
|
15
|
-
import { PhinIncomingResponse } from './PhinIncomingResponse';
|
|
16
|
-
export class PhinHttpClient {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.httpsKeepAliveAgent = new HttpsAgent({ keepAlive: true });
|
|
19
|
-
}
|
|
20
|
-
send(request, options) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
try {
|
|
23
|
-
const res = yield phin.promisified({
|
|
24
|
-
url: request.url,
|
|
25
|
-
method: request.method,
|
|
26
|
-
headers: joinHeaderValues(request.headers),
|
|
27
|
-
data: request.body,
|
|
28
|
-
timeout: (options === null || options === void 0 ? void 0 : options.timeoutMs) || null,
|
|
29
|
-
core: {
|
|
30
|
-
agent: request.url.startsWith('https://') ? this.httpsKeepAliveAgent : new HttpAgent(),
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
return new PhinIncomingResponse(res);
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
const isTimeout = e.toString().toLowerCase().includes('timeout');
|
|
37
|
-
throw isTimeout ? new EnforcerTimeoutError(options.timeoutMs) : e;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { CONTENT_TYPE_HEADER_NAME, MultipartFormDataUtils } from '../../utils';
|
|
11
|
-
export class PhinIncomingResponse {
|
|
12
|
-
constructor(response) {
|
|
13
|
-
this.status = response.statusCode;
|
|
14
|
-
this.body = response.body;
|
|
15
|
-
this.headers = Object.fromEntries(Object.entries(response.headers).map(([key, val]) => [key, typeof val === 'string' ? [val] : val]));
|
|
16
|
-
}
|
|
17
|
-
formData() {
|
|
18
|
-
var _a;
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
return MultipartFormDataUtils.createFormDataWithoutFiles(yield this.text(), (_a = this.headers[CONTENT_TYPE_HEADER_NAME]) === null || _a === void 0 ? void 0 : _a[0]);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
formUrlEncoded() {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
return new URLSearchParams(yield this.text());
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
json() {
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
return JSON.parse(yield this.text());
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
text() {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
return this.body.toString();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import * as crypto from 'crypto';
|
|
11
|
-
export class CryptoCipherUtils {
|
|
12
|
-
constructor(cryptoModule = crypto) {
|
|
13
|
-
this.crypto = cryptoModule;
|
|
14
|
-
}
|
|
15
|
-
pbkdf2Decrypt(secret, encryptedString, iterations, salt, options) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const keylen = (options === null || options === void 0 ? void 0 : options.keylen) || 32;
|
|
18
|
-
const ivlen = (options === null || options === void 0 ? void 0 : options.ivlen) || 16;
|
|
19
|
-
const derivation = this.crypto.pbkdf2Sync(secret, Buffer.from(salt, 'base64'), iterations, keylen + ivlen, 'sha256');
|
|
20
|
-
const key = derivation.subarray(0, keylen);
|
|
21
|
-
const iv = derivation.subarray(keylen);
|
|
22
|
-
const cipher = this.crypto.createDecipheriv('aes-256-cbc', key, iv);
|
|
23
|
-
let decrypted = cipher.update(encryptedString, 'base64', 'utf8');
|
|
24
|
-
decrypted += cipher.final('utf8');
|
|
25
|
-
return decrypted;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export class SubtleCryptoCipherUtils {
|
|
11
|
-
constructor(base64Utils, subtleCrypto = crypto.subtle) {
|
|
12
|
-
this.subtleCrypto = subtleCrypto;
|
|
13
|
-
this.base64Utils = base64Utils;
|
|
14
|
-
}
|
|
15
|
-
pbkdf2Decrypt(secret, encryptedString, iterations, salt, options) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const ivlen = (options === null || options === void 0 ? void 0 : options.ivlen) || 16;
|
|
18
|
-
const keylen = (options === null || options === void 0 ? void 0 : options.keylen) || 32;
|
|
19
|
-
const bitsLength = (ivlen + keylen) * 8;
|
|
20
|
-
const encodedPassword = new TextEncoder().encode(secret);
|
|
21
|
-
const encodedSalt = this.base64ToArrayBuffer(salt);
|
|
22
|
-
const importedKey = yield this.subtleCrypto.importKey('raw', encodedPassword, 'PBKDF2', false, ['deriveBits']);
|
|
23
|
-
const params = { name: 'PBKDF2', hash: 'SHA-256', salt: encodedSalt, iterations: iterations };
|
|
24
|
-
const derivation = yield this.subtleCrypto.deriveBits(params, importedKey, bitsLength);
|
|
25
|
-
const derivedKey = derivation.slice(0, keylen);
|
|
26
|
-
const iv = derivation.slice(keylen);
|
|
27
|
-
const cookieBuffer = this.base64ToArrayBuffer(encryptedString);
|
|
28
|
-
const importedDecryptionKey = yield this.subtleCrypto.importKey('raw', derivedKey, { name: 'AES-CBC' }, false, [
|
|
29
|
-
'decrypt',
|
|
30
|
-
]);
|
|
31
|
-
const decrypted = yield this.subtleCrypto.decrypt({
|
|
32
|
-
name: 'AES-CBC',
|
|
33
|
-
iv: iv,
|
|
34
|
-
}, importedDecryptionKey, cookieBuffer);
|
|
35
|
-
return new TextDecoder('utf-8').decode(decrypted);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
base64ToArrayBuffer(base64String) {
|
|
39
|
-
const binaryString = this.base64Utils.base64Decode(base64String);
|
|
40
|
-
const length = binaryString.length;
|
|
41
|
-
const bytes = new Uint8Array(length);
|
|
42
|
-
binaryString.split('').forEach((char, index) => {
|
|
43
|
-
bytes[index] = char.charCodeAt(0);
|
|
44
|
-
});
|
|
45
|
-
return bytes.buffer;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import * as crypto from 'crypto';
|
|
11
|
-
export class CryptoHashUtils {
|
|
12
|
-
constructor(cryptoModule = crypto) {
|
|
13
|
-
this.crypto = cryptoModule;
|
|
14
|
-
}
|
|
15
|
-
hashString(text, algo) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
return this.crypto.createHash(algo).update(text).digest('hex');
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import * as crypto from 'crypto';
|
|
11
|
-
import { Algorithm } from '../Algorithm';
|
|
12
|
-
export class SubtleCryptoHashUtils {
|
|
13
|
-
constructor(subtleCrypto = crypto.subtle) {
|
|
14
|
-
this.subtle = subtleCrypto;
|
|
15
|
-
}
|
|
16
|
-
hashString(text, algo) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const textUint8 = new TextEncoder().encode(text);
|
|
19
|
-
const hashBuffer = yield this.subtle.digest(this.convertAlgo(algo), textUint8);
|
|
20
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
21
|
-
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
convertAlgo(algo) {
|
|
25
|
-
switch (algo) {
|
|
26
|
-
case Algorithm.SHA256:
|
|
27
|
-
default:
|
|
28
|
-
return 'SHA-256';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|