From e379adf2b2ad4a48c838eea3232fc9596a8c1fbe Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Tue, 25 Feb 2025 11:04:19 +0100 Subject: [PATCH] fix: Revert native HMACSHA512 usage --- app/core/Encryptor/hmac.test.ts | 23 ----------------------- app/core/Encryptor/hmac.ts | 16 ---------------- app/core/Engine/Engine.ts | 6 ++---- 3 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 app/core/Encryptor/hmac.test.ts delete mode 100644 app/core/Encryptor/hmac.ts diff --git a/app/core/Encryptor/hmac.test.ts b/app/core/Encryptor/hmac.test.ts deleted file mode 100644 index bad8b1a6314..00000000000 --- a/app/core/Encryptor/hmac.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { NativeModules } from 'react-native'; -import { hmacSha512 } from './hmac'; -import { hmac as nobleHmac } from '@noble/hashes/hmac'; -import { sha512 as nobleSha512 } from '@noble/hashes/sha512'; -import { bytesToHex, hexToBytes, stringToBytes } from '@metamask/utils'; - -describe('hmacSha512', () => { - NativeModules.Aes.hmac512 = jest - .fn() - .mockImplementation((data, key) => - bytesToHex(nobleHmac(nobleSha512, hexToBytes(key), stringToBytes(data))), - ); - - it('returns hash from native module', async () => { - const key = new Uint8Array(32); - const data = new Uint8Array(32); - - const result = await hmacSha512(key, data); - expect(bytesToHex(result)).toBe( - '0xbae46cebebbb90409abc5acf7ac21fdb339c01ce15192c52fb9e8aa11a8de9a4ea15a045f2be245fbb98916a9ae81b353e33b9c42a55380c5158241daeb3c6dd', - ); - }); -}); diff --git a/app/core/Encryptor/hmac.ts b/app/core/Encryptor/hmac.ts deleted file mode 100644 index 0bf8fdee176..00000000000 --- a/app/core/Encryptor/hmac.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { - bytesToHex, - bytesToString, - hexToBytes, - remove0x, -} from '@metamask/utils'; -import { NativeModules } from 'react-native'; - -export async function hmacSha512(key: Uint8Array, data: Uint8Array) { - const Aes = NativeModules.Aes; - const bytes = await Aes.hmac512( - bytesToString(data), - remove0x(bytesToHex(key)), - ); - return hexToBytes(bytes); -} diff --git a/app/core/Engine/Engine.ts b/app/core/Engine/Engine.ts index 54ed988c3f4..e08d24170ea 100644 --- a/app/core/Engine/Engine.ts +++ b/app/core/Engine/Engine.ts @@ -90,7 +90,6 @@ import { } from '@metamask/eth-ledger-bridge-keyring'; import { Encryptor, - hmacSha512, LEGACY_DERIVATION_OPTIONS, pbkdf2, } from '../Encryptor'; @@ -642,7 +641,7 @@ export class Engine { const hdKeyringBuilder = () => new HDKeyring({ - cryptographicFunctions: { pbkdf2Sha512: pbkdf2, hmacSha512 }, + cryptographicFunctions: { pbkdf2Sha512: pbkdf2 }, }); hdKeyringBuilder.type = HDKeyring.type; additionalKeyrings.push(hdKeyringBuilder); @@ -803,7 +802,7 @@ export class Engine { origin, target, ), - getClientCryptography: () => ({ pbkdf2Sha512: pbkdf2, hmacSha512 }), + getClientCryptography: () => ({ pbkdf2Sha512: pbkdf2 }), }; ///: END:ONLY_INCLUDE_IF @@ -1088,7 +1087,6 @@ export class Engine { }), clientCryptography: { pbkdf2Sha512: pbkdf2, - hmacSha512, }, });