From f92291bb8ef6c2a2a87c55fab8e8fd47c3d8816f Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Thu, 6 Mar 2025 21:01:26 +0200 Subject: [PATCH] crypto: improve older Node version and browser compatibility --- LICENSE | 2 +- README.md | 2 +- package.json | 2 +- src/Utils/crypto.ts | 11 +++++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index bb2580d..772637b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Rajeh Taher/WhiskeySockets +Copyright (c) 2025 Rajeh Taher/WhiskeySockets Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 196f494..1b91218 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The maintainers of Baileys do not in any way condone the use of this application Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage. # License -Copyright (c) 2023 Rajeh Taher/WhiskeySockets +Copyright (c) 2025 Rajeh Taher/WhiskeySockets Licensed under the MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/package.json b/package.json index 2aea558..99f14e1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "whatsapp", "automation" ], - "homepage": "https://github.com/WhiskeySockets/Baileys", + "homepage": "https://baileys.wiki/", "repository": { "url": "git@github.com:WhiskeySockets/Baileys.git" }, diff --git a/src/Utils/crypto.ts b/src/Utils/crypto.ts index 3856013..3cf027c 100644 --- a/src/Utils/crypto.ts +++ b/src/Utils/crypto.ts @@ -3,6 +3,9 @@ import * as libsignal from 'libsignal' import { KEY_BUNDLE_TYPE } from '../Defaults' import { KeyPair } from '../Types' +// insure browser & node compatibility +const { subtle } = globalThis.crypto + /** prefix version byte to the pub keys, required for some curve crypto functions */ export const generateSignalPubKey = (pubKey: Uint8Array | Buffer) => ( pubKey.length === 33 @@ -138,7 +141,7 @@ export async function hkdf( : new Uint8Array(0) // Import the input key material - const importedKey = await crypto.subtle.importKey( + const importedKey = await subtle.importKey( 'raw', inputKeyMaterial, { name: 'HKDF' }, @@ -147,7 +150,7 @@ export async function hkdf( ) // Derive bits using HKDF - const derivedBits = await crypto.subtle.deriveBits( + const derivedBits = await subtle.deriveBits( { name: 'HKDF', hash: 'SHA-256', @@ -169,7 +172,7 @@ export async function derivePairingCodeKey(pairingCode: string, salt: Buffer): P const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt) // Import the pairing code as key material - const keyMaterial = await crypto.subtle.importKey( + const keyMaterial = await subtle.importKey( 'raw', pairingCodeBuffer, { name: 'PBKDF2' }, @@ -179,7 +182,7 @@ export async function derivePairingCodeKey(pairingCode: string, salt: Buffer): P // Derive bits using PBKDF2 with the same parameters // 2 << 16 = 131,072 iterations - const derivedBits = await crypto.subtle.deriveBits( + const derivedBits = await subtle.deriveBits( { name: 'PBKDF2', salt: saltBuffer,