refactor: auth store handling (#201667)
* update module store * delete auth stores directory
This commit is contained in:
parent
f7e4d3d0fc
commit
2dc9466fac
2 changed files with 35 additions and 55 deletions
|
|
@ -12,7 +12,6 @@ const {
|
|||
WAState,
|
||||
MessageTypes,
|
||||
} = require('./util/Constants');
|
||||
const { ExposeAuthStore } = require('./util/Injected/AuthStore/AuthStore');
|
||||
const { LoadUtils } = require('./util/Injected/Utils');
|
||||
const ChatFactory = require('./factories/ChatFactory');
|
||||
const ContactFactory = require('./factories/ContactFactory');
|
||||
|
|
@ -141,8 +140,6 @@ class Client extends EventEmitter {
|
|||
const pairWithPhoneNumber = this.options.pairWithPhoneNumber;
|
||||
const version = await this.getWWebVersion();
|
||||
|
||||
await this.pupPage.evaluate(ExposeAuthStore);
|
||||
|
||||
const needAuthentication = await this.pupPage.evaluate(async () => {
|
||||
let state = window.require('WAWebSocketModel').Socket.state;
|
||||
|
||||
|
|
@ -245,19 +242,21 @@ class Client extends EventEmitter {
|
|||
);
|
||||
|
||||
await this.pupPage.evaluate(async () => {
|
||||
const registrationInfo =
|
||||
await window.AuthStore.RegistrationUtils.waSignalStore.getRegistrationInfo();
|
||||
const noiseKeyPair =
|
||||
await window.AuthStore.RegistrationUtils.waNoiseInfo.get();
|
||||
const staticKeyB64 = window.AuthStore.Base64Tools.encodeB64(
|
||||
noiseKeyPair.staticKeyPair.pubKey,
|
||||
);
|
||||
const identityKeyB64 =
|
||||
window.AuthStore.Base64Tools.encodeB64(
|
||||
registrationInfo.identityKeyPair.pubKey,
|
||||
);
|
||||
const platform =
|
||||
window.AuthStore.RegistrationUtils.DEVICE_PLATFORM;
|
||||
const registrationInfo = await window
|
||||
.require('WAWebSignalStoreApi')
|
||||
.waSignalStore.getRegistrationInfo();
|
||||
const noiseKeyPair = await window
|
||||
.require('WAWebUserPrefsInfoStore')
|
||||
.waNoiseInfo.get();
|
||||
const staticKeyB64 = window
|
||||
.require('WABase64')
|
||||
.encodeB64(noiseKeyPair.staticKeyPair.pubKey);
|
||||
const identityKeyB64 = window
|
||||
.require('WABase64')
|
||||
.encodeB64(registrationInfo.identityKeyPair.pubKey);
|
||||
const platform = window.require(
|
||||
'WAWebCompanionRegClientUtils',
|
||||
).DEVICE_PLATFORM;
|
||||
const getQR = (ref) =>
|
||||
ref +
|
||||
',' +
|
||||
|
|
@ -270,8 +269,12 @@ class Client extends EventEmitter {
|
|||
.getADVSecretKey() +
|
||||
',' +
|
||||
platform;
|
||||
window.onQRChangedEvent(getQR(window.AuthStore.Conn.ref)); // initial qr
|
||||
window.AuthStore.Conn.on('change:ref', (_, ref) => {
|
||||
window.onQRChangedEvent(
|
||||
getQR(window.require('WAWebConnModel').Conn.ref),
|
||||
); // initial qr
|
||||
window
|
||||
.require('WAWebConnModel')
|
||||
.Conn.on('change:ref', (_, ref) => {
|
||||
window.onQRChangedEvent(getQR(ref));
|
||||
}); // future QR changes
|
||||
});
|
||||
|
|
@ -411,7 +414,9 @@ class Client extends EventEmitter {
|
|||
const Cmd = window.require('WAWebCmd').Cmd;
|
||||
Cmd.on('offline_progress_update_from_bridge', () => {
|
||||
window.onOfflineProgressUpdateEvent(
|
||||
window.AuthStore.OfflineMessageHandler.getOfflineDeliveryProgress(),
|
||||
window
|
||||
.require('WAWebOfflineHandler')
|
||||
.OfflineMessageHandler.getOfflineDeliveryProgress(),
|
||||
);
|
||||
});
|
||||
Cmd.on('logout', async () => {
|
||||
|
|
@ -527,19 +532,15 @@ class Client extends EventEmitter {
|
|||
return await this.pupPage.evaluate(
|
||||
async (phoneNumber, showNotification, intervalMs) => {
|
||||
const getCode = async () => {
|
||||
while (!window.AuthStore.PairingCodeLinkUtils) {
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, 250),
|
||||
);
|
||||
}
|
||||
window.AuthStore.PairingCodeLinkUtils.setPairingType(
|
||||
'ALT_DEVICE_LINKING',
|
||||
);
|
||||
await window.AuthStore.PairingCodeLinkUtils.initializeAltDeviceLinking();
|
||||
return window.AuthStore.PairingCodeLinkUtils.startAltLinkingFlow(
|
||||
phoneNumber,
|
||||
showNotification,
|
||||
);
|
||||
window
|
||||
.require('WAWebAltDeviceLinkingApi')
|
||||
.setPairingType('ALT_DEVICE_LINKING');
|
||||
await window
|
||||
.require('WAWebAltDeviceLinkingApi')
|
||||
.initializeAltDeviceLinking();
|
||||
return window
|
||||
.require('WAWebAltDeviceLinkingApi')
|
||||
.startAltLinkingFlow(phoneNumber, showNotification);
|
||||
};
|
||||
if (window.codeInterval) {
|
||||
clearInterval(window.codeInterval); // remove existing interval
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
exports.ExposeAuthStore = () => {
|
||||
window.AuthStore = {};
|
||||
window.AuthStore.AppState = window.require('WAWebSocketModel').Socket;
|
||||
window.AuthStore.Cmd = window.require('WAWebCmd').Cmd;
|
||||
window.AuthStore.Conn = window.require('WAWebConnModel').Conn;
|
||||
window.AuthStore.OfflineMessageHandler = window.require(
|
||||
'WAWebOfflineHandler',
|
||||
).OfflineMessageHandler;
|
||||
window.AuthStore.PairingCodeLinkUtils = window.require(
|
||||
'WAWebAltDeviceLinkingApi',
|
||||
);
|
||||
window.AuthStore.Base64Tools = window.require('WABase64');
|
||||
window.AuthStore.RegistrationUtils = {
|
||||
...window.require('WAWebCompanionRegClientUtils'),
|
||||
...window.require('WAWebAdvSignatureApi'),
|
||||
...window.require('WAWebUserPrefsInfoStore'),
|
||||
...window.require('WAWebSignalStoreApi'),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in a new issue