Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sinplify
  • Loading branch information
alexandre-abrioux committed Apr 12, 2025
commit eac9c9a1492085aa7a8aa5591e2ed09119d852d4
10 changes: 5 additions & 5 deletions packages/utils/src/crypto/ec-utils-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ const deriveSharedKeyWithSha512 = (
* https://github.com/RequestNetwork/requestNetwork/blob/4597d373b0284787273471cf306dd9b849c9f76a/packages/utils/src/crypto/ec-utils.ts#L141
*/
const legacyAes256CbcMacSplit = (str: string) => {
const buf = Buffer.from(str, 'hex');
const buffer = Buffer.from(str, 'hex');

const ivSize = 16;
const ephemPublicKeySize = 33;
const ephemPublicKeyEnd = ivSize + ephemPublicKeySize;
const macSize = 32;
const macEnd = ephemPublicKeyEnd + macSize;

const ephemPublicKeyStr = buf.subarray(ivSize, ephemPublicKeyEnd);
const ephemPublicKeyStr = buffer.subarray(ivSize, ephemPublicKeyEnd);
const ephemPublicKey = new PublicKey(ephemPublicKeyStr);

return {
iv: Buffer.from(buf.toString('hex', 0, ivSize), 'hex'),
mac: Buffer.from(buf.toString('hex', ephemPublicKeyEnd, macEnd), 'hex'),
ciphertext: Buffer.from(buf.toString('hex', macEnd, buf.length), 'hex'),
iv: buffer.slice(0, ivSize),
mac: buffer.slice(ephemPublicKeyEnd, macEnd),
ciphertext: buffer.slice(macEnd),
ephemPublicKey,
};
};