From e98e309b0d7a4f34b01a1f42143c4c79f082c75b Mon Sep 17 00:00:00 2001 From: SamuelScheit Date: Thu, 18 May 2023 11:32:39 +0200 Subject: [PATCH] wip: two factor auth --- src/Socket/chats.ts | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 1f08f25..2f8206e 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -515,6 +515,52 @@ export const makeChatsSocket = (config: SocketConfig) => { } }) + const getTwoFactor = async() => { + const result = await query({ + tag: 'iq', + attrs: { + to: S_WHATSAPP_NET, + type: 'get', + xmlns: 'urn:xmpp:whatsapp:account', + id: generateMessageTag(), + }, + content: [ + { tag: '2fa', attrs: {} } + ] + }) + return getBinaryNodeChild(result, '2fa')?.content + } + + /** + * @param opts.pin - 2fa pin (6 digits) or undefined to disable + * @param opts.email - email for 2fa backup + */ + const setTwoFactor = async() => { + return query({ + tag: 'iq', + attrs: { + to: S_WHATSAPP_NET, + type: 'set', + xmlns: 'urn:xmpp:whatsapp:account', + id: generateMessageTag(), + }, + content: [ + { + tag: '2fa', + attrs: {}, + content: [ + { + tag: 'code', + attrs: {}, + content: Buffer.alloc(0) + }, + // ...(opts.email ? [{ tag: 'email', attrs: {}, content: opts.email }] : []), + ] + } + ] + }) + } + /** * fetch the profile picture of a user/group * type = "preview" for a low res picture