Skip to content

Commit

Permalink
metadata-utils: move hash lenght sanity check to both methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Jan 20, 2025
1 parent 9252b08 commit 92d3b85
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/suite/src/utils/suite/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ 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(
hash,
)}`,
);
}

return hash;
};

export const deriveAesKey = (metadataKey: string) => {
const hash = deriveHmac(metadataKey);

const secondHalf = hash.subarray(32, 64);

return secondHalf.toString('hex');
Expand Down

0 comments on commit 92d3b85

Please sign in to comment.