From 3534bd856f4c94bab6b145c32ae166738795960b Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Mon, 13 Jul 2020 14:14:45 +0530 Subject: [PATCH] Set appropriate browsers --- src/WAConnection/Base.ts | 3 +-- src/WAConnection/Constants.ts | 5 ----- src/WAConnection/Utils.ts | 15 ++++++++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/WAConnection/Base.ts b/src/WAConnection/Base.ts index e51de6d..b8e9385 100644 --- a/src/WAConnection/Base.ts +++ b/src/WAConnection/Base.ts @@ -12,7 +12,6 @@ import { WATag, MessageLogLevel, AuthenticationCredentialsBrowser, - Browsers, } from './Constants' /** Generate a QR code from the ref & the curve public key. This is scanned by the phone */ @@ -25,7 +24,7 @@ export default class WAConnectionBase { /** The version of WhatsApp Web we're telling the servers we are */ version: [number, number, number] = [2, 2027, 10] /** The Browser we're telling the WhatsApp Web servers we are */ - browserDescription: [string, string, string] = Browsers.baileys ('Chrome') + browserDescription: [string, string, string] = Utils.Browsers.baileys ('Chrome') /** Metadata like WhatsApp id, name set on WhatsApp etc. */ userMetaData: UserMetaData = { id: null, name: null, phone: null } /** Should reconnect automatically after an unexpected disconnect */ diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index 31ca1ec..5543f30 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -1,11 +1,6 @@ import { WA } from '../Binary/Constants' import { proto } from '../../WAMessage/WAMessage' -export const Browsers: Record [string, string, string]> = { - ubuntu: browser => ['Ubuntu', browser, '18.04'], - macOS: browser => ['Mac OS', browser, '10.15.3'], - baileys: browser => ['Baileys', browser, '2.0'] -} export enum MessageLogLevel { none=0, unhandled=1, diff --git a/src/WAConnection/Utils.ts b/src/WAConnection/Utils.ts index a327e56..fc55902 100644 --- a/src/WAConnection/Utils.ts +++ b/src/WAConnection/Utils.ts @@ -1,8 +1,21 @@ import * as Crypto from 'crypto' import HKDF from 'futoin-hkdf' import Decoder from '../Binary/Decoder' -import { off } from 'process' +import {platform, release} from 'os' +const platformMap = { + 'aix': 'AIX', + 'darwin': 'Mac OS', + 'win32': 'Windows', + 'android': 'Android' +} +export const Browsers = { + ubuntu: browser => ['Ubuntu', browser, '18.04'] as [string, string, string], + macOS: browser => ['Mac OS', browser, '10.15.3'] as [string, string, string], + baileys: browser => ['Baileys', browser, '2.0'] as [string, string, string], + /** The appropriate browser based on your OS & release */ + appropriate: browser => [ platformMap [platform()] || 'Ubuntu', browser, release() ] as [string, string, string] +} /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */ export function aesDecrypt(buffer: Buffer, key: Buffer) { return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16))