From 127e21b92026b96bfc5c24eaaf28ff361ca7c3de Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sat, 8 Jan 2022 11:27:19 +0530 Subject: [PATCH] feat: implement getAuthenticationCredsType --- src/Utils/legacy-msgs.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Utils/legacy-msgs.ts b/src/Utils/legacy-msgs.ts index 8984e8f..590b65d 100644 --- a/src/Utils/legacy-msgs.ts +++ b/src/Utils/legacy-msgs.ts @@ -3,7 +3,7 @@ import { randomBytes } from 'crypto' import { decodeBinaryNodeLegacy, jidNormalizedUser } from "../WABinary" import { aesDecrypt, hmacSign, hkdf, Curve } from "./crypto" import { BufferJSON } from './generics' -import { DisconnectReason, WATag, LegacyAuthenticationCreds, CurveKeyPair, Contact } from "../Types" +import { DisconnectReason, WATag, LegacyAuthenticationCreds, AuthenticationCreds, CurveKeyPair, Contact } from "../Types" export const newLegacyAuthCreds = () => ({ clientID: randomBytes(16).toString('base64') @@ -173,4 +173,13 @@ export const useSingleFileLegacyAuthState = (file: string) => { writeFileSync(file, str) } } +} + +export const getAuthenticationCredsType = (creds: LegacyAuthenticationCreds | AuthenticationCreds) => { + if('clientID' in creds && !!creds.clientID) { + return 'legacy' + } + if('noiseKey' in creds && !!creds.noiseKey) { + return 'md' + } } \ No newline at end of file