From 92d3b85d5c4a62327b4d11a593cef0897f49fb98 Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Fri, 17 Jan 2025 16:55:19 +0100 Subject: [PATCH] metadata-utils: move hash lenght sanity check to both methods --- packages/suite/src/utils/suite/metadata.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/suite/src/utils/suite/metadata.ts b/packages/suite/src/utils/suite/metadata.ts index b4d7e88cb1a9..50b7c586c239 100644 --- a/packages/suite/src/utils/suite/metadata.ts +++ b/packages/suite/src/utils/suite/metadata.ts @@ -26,11 +26,7 @@ const deriveHmac = (metadataKey: string) => { const buf = Buffer.from('0123456789abcdeffedcba9876543210', 'hex'); hmac.update(buf); - return hmac.digest(); -}; - -export const deriveAesKey = (metadataKey: string) => { - const hash = deriveHmac(metadataKey); + const hash = hmac.digest(); if (hash.length !== 64 && Buffer.byteLength(hash) !== 64) { throw new Error( `Strange buffer length when deriving account hmac ${hash.length} ; ${Buffer.byteLength( @@ -38,6 +34,13 @@ export const deriveAesKey = (metadataKey: string) => { )}`, ); } + + return hash; +}; + +export const deriveAesKey = (metadataKey: string) => { + const hash = deriveHmac(metadataKey); + const secondHalf = hash.subarray(32, 64); return secondHalf.toString('hex');