From 7a49eee9ee8d1e1bfd49a23be5388dd569179cd5 Mon Sep 17 00:00:00 2001 From: kamalbuilds Date: Wed, 5 Feb 2025 22:06:33 +0530 Subject: [PATCH 1/2] fix the native blake2 bindings issue --- src/lib/crypto_utils.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/crypto_utils.ts b/src/lib/crypto_utils.ts index 330c30f..2611c9c 100644 --- a/src/lib/crypto_utils.ts +++ b/src/lib/crypto_utils.ts @@ -1,6 +1,6 @@ import { box, randomBytes } from 'tweetnacl'; import { createHmac, createCipheriv, createDecipheriv } from 'crypto'; -import { createHash as createBlake2Hash } from 'blake2'; +import { blake2b } from '@noble/hashes/blake2b'; import { x25519 } from '@noble/curves/ed25519'; // import { encodeBase64, decodeBase64 } from 'tweetnacl-util'; // import { BLAKE2b } from '@stablelib/blake2b'; @@ -40,9 +40,7 @@ function deriveKey(sharedSecret: Uint8Array, salt: Uint8Array): Uint8Array { * @returns A 32-byte hash */ export function calculateHash(data: Uint8Array): Uint8Array { - const hash = createBlake2Hash('blake2b', { digestLength: 32 }); // Use BLAKE2b with 32-byte digest - hash.update(data); - return new Uint8Array(hash.digest()); + return blake2b(data, { dkLen: 32 }); // 32 bytes = 256 bits } /** From 9d3fdda85afcadbec68ce91c0230039bf33dfcd4 Mon Sep 17 00:00:00 2001 From: kamalbuilds Date: Wed, 5 Feb 2025 22:09:06 +0530 Subject: [PATCH 2/2] del types as no longer needed --- src/types/blake2.d.ts | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/types/blake2.d.ts diff --git a/src/types/blake2.d.ts b/src/types/blake2.d.ts deleted file mode 100644 index b554c12..0000000 --- a/src/types/blake2.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -declare module 'blake2' { - interface HashOptions { - digestLength?: number; - } - - interface Hash { - update(data: Buffer | Uint8Array): void; - digest(): Buffer; - } - - export function createHash(algorithm: string, options?: HashOptions): Hash; -} \ No newline at end of file