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,
|
WAState,
|
||||||
MessageTypes,
|
MessageTypes,
|
||||||
} = require('./util/Constants');
|
} = require('./util/Constants');
|
||||||
const { ExposeAuthStore } = require('./util/Injected/AuthStore/AuthStore');
|
|
||||||
const { LoadUtils } = require('./util/Injected/Utils');
|
const { LoadUtils } = require('./util/Injected/Utils');
|
||||||
const ChatFactory = require('./factories/ChatFactory');
|
const ChatFactory = require('./factories/ChatFactory');
|
||||||
const ContactFactory = require('./factories/ContactFactory');
|
const ContactFactory = require('./factories/ContactFactory');
|
||||||
|
|
@ -141,8 +140,6 @@ class Client extends EventEmitter {
|
||||||
const pairWithPhoneNumber = this.options.pairWithPhoneNumber;
|
const pairWithPhoneNumber = this.options.pairWithPhoneNumber;
|
||||||
const version = await this.getWWebVersion();
|
const version = await this.getWWebVersion();
|
||||||
|
|
||||||
await this.pupPage.evaluate(ExposeAuthStore);
|
|
||||||
|
|
||||||
const needAuthentication = await this.pupPage.evaluate(async () => {
|
const needAuthentication = await this.pupPage.evaluate(async () => {
|
||||||
let state = window.require('WAWebSocketModel').Socket.state;
|
let state = window.require('WAWebSocketModel').Socket.state;
|
||||||
|
|
||||||
|
|
@ -245,19 +242,21 @@ class Client extends EventEmitter {
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.pupPage.evaluate(async () => {
|
await this.pupPage.evaluate(async () => {
|
||||||
const registrationInfo =
|
const registrationInfo = await window
|
||||||
await window.AuthStore.RegistrationUtils.waSignalStore.getRegistrationInfo();
|
.require('WAWebSignalStoreApi')
|
||||||
const noiseKeyPair =
|
.waSignalStore.getRegistrationInfo();
|
||||||
await window.AuthStore.RegistrationUtils.waNoiseInfo.get();
|
const noiseKeyPair = await window
|
||||||
const staticKeyB64 = window.AuthStore.Base64Tools.encodeB64(
|
.require('WAWebUserPrefsInfoStore')
|
||||||
noiseKeyPair.staticKeyPair.pubKey,
|
.waNoiseInfo.get();
|
||||||
);
|
const staticKeyB64 = window
|
||||||
const identityKeyB64 =
|
.require('WABase64')
|
||||||
window.AuthStore.Base64Tools.encodeB64(
|
.encodeB64(noiseKeyPair.staticKeyPair.pubKey);
|
||||||
registrationInfo.identityKeyPair.pubKey,
|
const identityKeyB64 = window
|
||||||
);
|
.require('WABase64')
|
||||||
const platform =
|
.encodeB64(registrationInfo.identityKeyPair.pubKey);
|
||||||
window.AuthStore.RegistrationUtils.DEVICE_PLATFORM;
|
const platform = window.require(
|
||||||
|
'WAWebCompanionRegClientUtils',
|
||||||
|
).DEVICE_PLATFORM;
|
||||||
const getQR = (ref) =>
|
const getQR = (ref) =>
|
||||||
ref +
|
ref +
|
||||||
',' +
|
',' +
|
||||||
|
|
@ -270,10 +269,14 @@ class Client extends EventEmitter {
|
||||||
.getADVSecretKey() +
|
.getADVSecretKey() +
|
||||||
',' +
|
',' +
|
||||||
platform;
|
platform;
|
||||||
window.onQRChangedEvent(getQR(window.AuthStore.Conn.ref)); // initial qr
|
window.onQRChangedEvent(
|
||||||
window.AuthStore.Conn.on('change:ref', (_, ref) => {
|
getQR(window.require('WAWebConnModel').Conn.ref),
|
||||||
window.onQRChangedEvent(getQR(ref));
|
); // initial qr
|
||||||
}); // future QR changes
|
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;
|
const Cmd = window.require('WAWebCmd').Cmd;
|
||||||
Cmd.on('offline_progress_update_from_bridge', () => {
|
Cmd.on('offline_progress_update_from_bridge', () => {
|
||||||
window.onOfflineProgressUpdateEvent(
|
window.onOfflineProgressUpdateEvent(
|
||||||
window.AuthStore.OfflineMessageHandler.getOfflineDeliveryProgress(),
|
window
|
||||||
|
.require('WAWebOfflineHandler')
|
||||||
|
.OfflineMessageHandler.getOfflineDeliveryProgress(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Cmd.on('logout', async () => {
|
Cmd.on('logout', async () => {
|
||||||
|
|
@ -527,19 +532,15 @@ class Client extends EventEmitter {
|
||||||
return await this.pupPage.evaluate(
|
return await this.pupPage.evaluate(
|
||||||
async (phoneNumber, showNotification, intervalMs) => {
|
async (phoneNumber, showNotification, intervalMs) => {
|
||||||
const getCode = async () => {
|
const getCode = async () => {
|
||||||
while (!window.AuthStore.PairingCodeLinkUtils) {
|
window
|
||||||
await new Promise((resolve) =>
|
.require('WAWebAltDeviceLinkingApi')
|
||||||
setTimeout(resolve, 250),
|
.setPairingType('ALT_DEVICE_LINKING');
|
||||||
);
|
await window
|
||||||
}
|
.require('WAWebAltDeviceLinkingApi')
|
||||||
window.AuthStore.PairingCodeLinkUtils.setPairingType(
|
.initializeAltDeviceLinking();
|
||||||
'ALT_DEVICE_LINKING',
|
return window
|
||||||
);
|
.require('WAWebAltDeviceLinkingApi')
|
||||||
await window.AuthStore.PairingCodeLinkUtils.initializeAltDeviceLinking();
|
.startAltLinkingFlow(phoneNumber, showNotification);
|
||||||
return window.AuthStore.PairingCodeLinkUtils.startAltLinkingFlow(
|
|
||||||
phoneNumber,
|
|
||||||
showNotification,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
if (window.codeInterval) {
|
if (window.codeInterval) {
|
||||||
clearInterval(window.codeInterval); // remove existing interval
|
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