From 259dfb9ef988d46291eaa971c85b08618c66bf87 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Tue, 8 Aug 2023 09:50:51 +0200 Subject: [PATCH] chore: cleanup deprecated joaat hash (#15577) --- package.json | 2 - src/script/entity/User/User.ts | 2 - src/script/user/UserMapper.test.ts | 1 - src/script/user/UserMapper.ts | 2 - src/script/util/Crypto.test.ts | 65 ------------------------------ src/script/util/Crypto.ts | 38 ----------------- yarn.lock | 9 ----- 7 files changed, 119 deletions(-) delete mode 100644 src/script/util/Crypto.test.ts delete mode 100644 src/script/util/Crypto.ts diff --git a/package.json b/package.json index b34e06acae3..d12b41da1b6 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "speakingurl": "14.0.1", "switch-path": "1.2.0", "tsyringe": "4.8.0", - "uint32": "0.2.1", "underscore": "1.13.6", "uuidjs": "4.2.13", "webrtc-adapter": "8.2.3", @@ -89,7 +88,6 @@ "@types/seedrandom": "^3", "@types/sinon": "10.0.16", "@types/speakingurl": "13.0.3", - "@types/uint32": "0.2.0", "@types/underscore": "1.11.6", "@types/webpack-env": "1.18.1", "@wireapp/copy-config": "2.1.1", diff --git a/src/script/entity/User/User.ts b/src/script/entity/User/User.ts index 5ead1d81d9c..b4b3e287c04 100644 --- a/src/script/entity/User/User.ts +++ b/src/script/entity/User/User.ts @@ -46,7 +46,6 @@ export class User { public isService: boolean; public isSingleSignOn: boolean; public isNoPasswordSSO: boolean; - public joaatHash: number; public providerId?: string; public readonly accent_color: ko.PureComputed; public readonly accent_id: ko.Observable; @@ -137,7 +136,6 @@ export class User { this.providerId = undefined; this.serviceId = undefined; - this.joaatHash = -1; this.isAvailable = ko.pureComputed(() => this.id !== '' && this.name() !== ''); this.accent_id = ko.observable(ACCENT_ID.BLUE); diff --git a/src/script/user/UserMapper.test.ts b/src/script/user/UserMapper.test.ts index ab1abad928a..f4d887be017 100644 --- a/src/script/user/UserMapper.test.ts +++ b/src/script/user/UserMapper.test.ts @@ -105,7 +105,6 @@ describe('User Mapper', () => { const user_et = mapper.mapUserFromJson(self_user_payload, ''); expect(user_et.name()).toBe('John Doe'); - expect(user_et.joaatHash).toBe(526273169); expect(user_et.accent_id()).toBe(ACCENT_ID.BLUE); }); }); diff --git a/src/script/user/UserMapper.ts b/src/script/user/UserMapper.ts index cb98345c3ba..ea047ab9ef2 100644 --- a/src/script/user/UserMapper.ts +++ b/src/script/user/UserMapper.ts @@ -19,7 +19,6 @@ import {container} from 'tsyringe'; -import {joaatHash} from 'Util/Crypto'; import {getLogger, Logger} from 'Util/Logger'; import {isSelfAPIUser} from './UserGuards'; @@ -91,7 +90,6 @@ export class UserMapper { const isNewUser = userEntity.id === '' && userData.id !== ''; if (isNewUser && userData.id) { userEntity.id = userData.id; - userEntity.joaatHash = joaatHash(userData.id ?? ''); } if (userData.qualified_id) { diff --git a/src/script/util/Crypto.test.ts b/src/script/util/Crypto.test.ts deleted file mode 100644 index a2b8b1859f3..00000000000 --- a/src/script/util/Crypto.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Wire - * Copyright (C) 2018 Wire Swiss GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - * - */ - -import {joaatHash} from './Crypto'; - -/* eslint-disable no-magic-numbers */ -describe('Crypto', () => { - describe(`Jenkins' one-at-a-time hash`, () => { - const sample: {[uuid: string]: number} = { - '25f79335-6a5b-410e-90ea-653bd18b66da': 348398396, - 'b88a6d46-b2ae-4122-8022-d6ed66a25f09': 1021700091, - 'e50759ee-d32b-438f-bdbd-2605f48773e6': 1241303210, - '3dcdf935-d346-48cc-bdeb-fd9369192fec': 1413083903, - '9c102a7a-349f-4466-bdc0-5d8640023187': 1625780665, - 'b413f30c-2aed-42d6-b882-328036d4247e': 2188977546, - '62e52f9e-0a69-49eb-9a02-b89e440f8950': 3345908844, - 'fb303c6d-aa88-4ddc-81c1-fc51e5fc0ed8': 3615181544, - '17fa9af0-5e83-4b10-a3e6-0059591fabea': 3869474815, - 'e1b6e9f0-aafd-4ba9-8030-6dd053531afd': 4118671235, - }; - - it(`can calculate Jenkins' one-at-a-time hash for a User ID`, () => { - const userId = '532af01e-1e24-4366-aacf-33b67d4ee376'; - - const actual = joaatHash(userId); - const expected = window.parseInt('200a4836', 16); - - expect(actual).toBe(expected); - }); - - it('returns the expected hash values for some test strings', () => { - Object.entries(sample).forEach(([input, expected]) => { - const actual = joaatHash(input); - - expect(actual).toEqual(expected); - }); - }); - - it('returns zero for an empty string', () => { - expect(joaatHash('')).toEqual(0); - }); - - it('returns the same value for upper and lowercase strings', () => { - const key = 'E1b6e9f0-aafd-4ba9-8030-6Dd053531afd'; - - expect(joaatHash(key)).toEqual(sample[key.toLowerCase()]); - }); - }); -}); diff --git a/src/script/util/Crypto.ts b/src/script/util/Crypto.ts deleted file mode 100644 index 9dc14b54c4b..00000000000 --- a/src/script/util/Crypto.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Wire - * Copyright (C) 2018 Wire Swiss GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - * - */ - -import uint32 from 'uint32'; - -/* eslint-disable no-magic-numbers */ -export const joaatHash = (stringToHash: string): number => { - let hash = uint32.toUint32(0); - const key = stringToHash.toLowerCase(); - - for (let index = 0; index < key.length; index++) { - hash = uint32.addMod32(hash, uint32.toUint32(key.charCodeAt(index))); - hash = uint32.addMod32(hash, uint32.shiftLeft(hash, 10)); - hash = uint32.xor(hash, uint32.shiftRight(hash, 6)); - } - - hash = uint32.addMod32(hash, uint32.shiftLeft(hash, 3)); - hash = uint32.xor(hash, uint32.shiftRight(hash, 11)); - hash = uint32.addMod32(hash, uint32.shiftLeft(hash, 15)); - - return hash; -}; diff --git a/yarn.lock b/yarn.lock index a6a8f37778d..9731192bae9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4411,13 +4411,6 @@ __metadata: languageName: node linkType: hard -"@types/uint32@npm:0.2.0": - version: 0.2.0 - resolution: "@types/uint32@npm:0.2.0" - checksum: 10e31438f0be48629742ff148f2ae0030008b63d232472bc836dd19c34cdf219ccdfac1d7ff5d89e116c405e4b43e485268375f3343d00a84d1b3f32e3e24691 - languageName: node - linkType: hard - "@types/underscore@npm:1.11.6": version: 1.11.6 resolution: "@types/underscore@npm:1.11.6" @@ -17703,7 +17696,6 @@ __metadata: "@types/seedrandom": ^3 "@types/sinon": 10.0.16 "@types/speakingurl": 13.0.3 - "@types/uint32": 0.2.0 "@types/underscore": 1.11.6 "@types/webpack-env": 1.18.1 "@wireapp/avs": 9.3.7 @@ -17809,7 +17801,6 @@ __metadata: tsc-watch: 6.0.4 tsyringe: 4.8.0 typescript: 5.1.6 - uint32: 0.2.1 underscore: 1.13.6 uuidjs: 4.2.13 webpack: 5.88.2