Skip to content

Commit db01972

Browse files
committed
Remove js-sha256 dependency
Changes from node scripts/lint_ts_projects --fix
1 parent fa33f18 commit db01972

13 files changed

Lines changed: 23 additions & 35 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,6 @@
14361436
"joi-to-json": "5.0.0",
14371437
"jquery": "3.7.1",
14381438
"js-search": "1.4.3",
1439-
"js-sha256": "0.11.1",
14401439
"js-yaml": "4.1.1",
14411440
"jsdom": "20.0.1",
14421441
"json-schema-to-ts": "3.1.1",

renovate.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,6 @@
18791879
"node-forge",
18801880
"formik",
18811881
"handlebars",
1882-
"js-sha256",
18831882
"js-yaml",
18841883
"magic-bytes.js",
18851884
"minimist",

x-pack/platform/plugins/shared/cases/public/components/use_push_to_service/callout/helpers.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
* 2.0.
66
*/
77

8-
import { sha256 } from 'js-sha256';
98
import { createCalloutId } from './helpers';
109

1110
describe('createCalloutId', () => {
1211
it('creates id correctly with one id', () => {
13-
const digest = sha256('one');
12+
const digest = encodeURIComponent('one');
1413
const id = createCalloutId(['one']);
1514
expect(id).toBe(digest);
1615
});
1716

1817
it('creates id correctly with multiples ids', () => {
19-
const digest = sha256('one|two|three');
18+
const digest = encodeURIComponent('one|two|three');
2019
const id = createCalloutId(['one', 'two', 'three']);
2120
expect(id).toBe(digest);
2221
});
2322

2423
it('creates id correctly with multiples ids and delimiter', () => {
25-
const digest = sha256('one,two,three');
24+
const digest = encodeURIComponent('one,two,three');
2625
const id = createCalloutId(['one', 'two', 'three'], ',');
2726
expect(id).toBe(digest);
2827
});

x-pack/platform/plugins/shared/cases/public/components/use_push_to_service/callout/helpers.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
* 2.0.
66
*/
77

8-
import { sha256 } from 'js-sha256';
9-
108
export const createCalloutId = (ids: string[], delimiter: string = '|'): string =>
11-
sha256(ids.join(delimiter));
9+
encodeURIComponent(ids.join(delimiter));

x-pack/platform/plugins/shared/stack_alerts/server/rule_types/es_query/executor.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
8-
import { sha256 } from 'js-sha256';
97
import { i18n } from '@kbn/i18n';
108
import type { CoreSetup } from '@kbn/core/server';
119
import { getEcsGroupsFromFlattenGrouping } from '@kbn/alerting-rule-utils';
@@ -280,10 +278,6 @@ export function tryToParseAsDate(sortValue?: string | number | null): undefined
280278
}
281279
}
282280

283-
export function getChecksum(params: OnlyEsQueryRuleParams) {
284-
return sha256.create().update(JSON.stringify(params));
285-
}
286-
287281
export function getInvalidComparatorError(comparator: string) {
288282
return i18n.translate('xpack.stackAlerts.esQuery.invalidComparatorErrorMessage', {
289283
defaultMessage: 'invalid thresholdComparator specified: {comparator}',

x-pack/platform/test/cloud_integration/tests/fullstory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import expect from '@kbn/expect';
9-
import { sha256 } from 'js-sha256';
9+
import { createHash } from 'crypto';
1010
import { CLOUD_USER_ID } from '@kbn/cloud-integration-saml-provider-plugin/constants';
1111
import type { FtrProviderContext } from '../ftr_provider_context';
1212

@@ -49,7 +49,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
4949
sessionUrl = sessionUrl!.replace('%3A', ':'); // undo encoding so comparisons work with API response
5050

5151
// Check that the session was recorded in the FS API for the given user based on their hashed ID
52-
const hashedUserId = sha256(CLOUD_USER_ID);
52+
const hashedUserId = createHash('sha256').update(CLOUD_USER_ID).digest('hex');
5353
const fsSessions = await fetch(
5454
`https://www.fullstory.com/api/v1/sessions?uid=${hashedUserId}&limit=100`,
5555
{

x-pack/solutions/observability/plugins/synthetics/server/routes/telemetry/monitor_upgrade_sender.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
import { sha256 } from 'js-sha256';
7+
88
import type { Logger } from '@kbn/core/server';
99
import { loggingSystemMock } from '@kbn/core/server/mocks';
1010
import type { SavedObject } from '@kbn/core/server';
@@ -21,7 +21,7 @@ import type { TelemetryEventsSender } from '../../telemetry/sender';
2121
import { createMockTelemetryEventsSender } from '../../telemetry/__mocks__';
2222

2323
import { MONITOR_UPDATE_CHANNEL, MONITOR_CURRENT_CHANNEL } from '../../telemetry/constants';
24-
24+
import { createHash } from 'crypto';
2525
import {
2626
formatTelemetryEvent,
2727
formatTelemetryUpdateEvent,
@@ -94,7 +94,7 @@ describe('monitor upgrade telemetry helpers', () => {
9494
});
9595
expect(actual).toEqual({
9696
stackVersion,
97-
configId: sha256.create().update(testConfig.id).hex(),
97+
configId: createHash('sha256').update(testConfig.id).digest('hex'),
9898
locations: ['us_central', 'other'],
9999
locationsCount: 2,
100100
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,
@@ -132,7 +132,7 @@ describe('monitor upgrade telemetry helpers', () => {
132132
});
133133
expect(actual).toEqual({
134134
stackVersion,
135-
configId: sha256.create().update(testConfig.id).hex(),
135+
configId: createHash('sha256').update(testConfig.id).digest('hex'),
136136
locations: ['us_central', 'other'],
137137
locationsCount: 2,
138138
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,
@@ -159,7 +159,7 @@ describe('monitor upgrade telemetry helpers', () => {
159159
);
160160
expect(actual).toEqual({
161161
stackVersion,
162-
configId: sha256.create().update(testConfig.id).hex(),
162+
configId: createHash('sha256').update(testConfig.id).digest('hex'),
163163
locations: ['us_central', 'other'],
164164
locationsCount: 2,
165165
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,
@@ -185,7 +185,7 @@ describe('monitor upgrade telemetry helpers', () => {
185185
);
186186
expect(actual).toEqual({
187187
stackVersion,
188-
configId: sha256.create().update(testConfig.id).hex(),
188+
configId: createHash('sha256').update(testConfig.id).digest('hex'),
189189
locations: ['us_central', 'other'],
190190
locationsCount: 2,
191191
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,

x-pack/solutions/observability/plugins/synthetics/server/routes/telemetry/monitor_upgrade_sender.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
import { sha256 } from 'js-sha256';
87
import type { Logger } from '@kbn/core/server';
98
import type { SavedObjectsUpdateResponse, SavedObject } from '@kbn/core/server';
9+
import { createHash } from 'crypto';
1010
import type { MonitorUpdateEvent } from '../../telemetry/types';
1111

1212
import type { TelemetryEventsSender } from '../../telemetry/sender';
@@ -101,7 +101,7 @@ export function formatTelemetryEvent({
101101
},
102102
}))
103103
: undefined,
104-
configId: sha256.create().update(monitor.id).hex(),
104+
configId: createHash('sha256').update(monitor.id).digest('hex'),
105105
revision: attributes[ConfigKey.REVISION],
106106
};
107107
}

x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/common/data/siem_migrations_data_lookups_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { sha256 } from 'js-sha256';
8+
import { createHash } from 'crypto';
99
import type { AuthenticatedUser, IScopedClusterClient, Logger } from '@kbn/core/server';
1010
import { retryTransientEsErrors } from '@kbn/index-adapter';
1111
import { toValidIndexName } from '@kbn/utils';
@@ -68,7 +68,7 @@ export class SiemMigrationsDataLookupsClient {
6868
}
6969

7070
private generateDocumentHash(document: object): string {
71-
return sha256.create().update(JSON.stringify(document)).hex(); // document need to be created in a deterministic way
71+
return createHash('sha256').update(JSON.stringify(document)).digest('hex'); // document need to be created in a deterministic way
7272
}
7373

7474
private getSanitizedLookupName(lookupName: string): string {

x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/common/data/siem_migrations_data_resources_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import { sha256 } from 'js-sha256';
8+
import { createHash } from 'crypto';
99
import type {
1010
QueryDslQueryContainer,
1111
Duration,
@@ -160,7 +160,7 @@ export class SiemMigrationsDataResourcesClient extends SiemMigrationsDataBaseCli
160160

161161
private createId(resource: CreateSiemMigrationResourceInput): string {
162162
const key = `${resource.migration_id}-${resource.type}-${resource.name}`;
163-
return sha256.create().update(key).hex();
163+
return createHash('sha256').update(key).digest('hex');
164164
}
165165

166166
private getFilterQuery(

0 commit comments

Comments
 (0)