mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
crypto: improve older Node version and browser compatibility
This commit is contained in:
2
LICENSE
2
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"whatsapp",
|
||||
"automation"
|
||||
],
|
||||
"homepage": "https://github.com/WhiskeySockets/Baileys",
|
||||
"homepage": "https://baileys.wiki/",
|
||||
"repository": {
|
||||
"url": "git@github.com:WhiskeySockets/Baileys.git"
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user