Cleanup + add remaining utils

This commit is contained in:
Adhiraj Singh
2021-07-12 23:50:08 +05:30
parent 89cf8004e9
commit 71e34fc5f8
15 changed files with 234 additions and 74 deletions

5
src/Utils/index.ts Normal file
View File

@@ -0,0 +1,5 @@
export * from './decode-wa-message'
export * from './generics'
export * from './messages'
export * from './messages-media'
export * from './validate-connection'

View File

@@ -220,9 +220,6 @@ export const generateWAMessageContent = async(
options: MessageContentGenerationOptions
) => {
let m: WAMessageContent = {}
if(typeof message === 'string') {
message = { text: message }
}
if('text' in message) {
const extContent = { ...message } as WATextMessage
if (!!options.getUrlInfo && message.text.match(URL_REGEX)) {

View File

@@ -1,7 +1,7 @@
import {Boom} from '@hapi/boom'
import * as Curve from 'curve25519-js'
import type { Contact } from '../Types/Contact'
import type { AnyAuthenticationCredentials, AuthenticationCredentials, CurveKeyPair } from "../Types"
import type { AnyAuthenticationCredentials, AuthenticationCredentials, AuthenticationCredentialsBase64, CurveKeyPair } from "../Types"
import { aesDecrypt, hkdf, hmacSign, whatsappID } from './generics'
import { readFileSync } from 'fs'
@@ -32,6 +32,16 @@ export const normalizedAuthInfo = (authInfo: AnyAuthenticationCredentials | stri
}
return authInfo as AuthenticationCredentials
}
export const base64EncodedAuthenticationCredentials = (creds: AnyAuthenticationCredentials) => {
const normalized = normalizedAuthInfo(creds)
return {
...normalized,
encKey: normalized.encKey.toString('base64'),
macKey: normalized.macKey.toString('base64')
} as AuthenticationCredentialsBase64
}
/**
* Once the QR code is scanned and we can validate our connection, or we resolved the challenge when logging back in
* @private