Simplify group request making

This commit is contained in:
Fedor Indutny 2024-05-02 23:39:04 +02:00 committed by GitHub
parent bd5134a7ce
commit 480c1f4882
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -353,7 +353,7 @@ export async function getPreJoinGroupInfo(
Bytes.fromBase64(masterKeyBase64)
);
return makeRequestWithTemporalRetry({
return makeRequestWithCredentials({
logId: `getPreJoinInfo/groupv2(${data.id})`,
publicParams: Bytes.toBase64(data.publicParams),
secretParams: Bytes.toBase64(data.secretParams),
@ -462,7 +462,7 @@ async function uploadAvatar(
}).finish();
const ciphertext = encryptGroupBlob(clientZkGroupCipher, blobPlaintext);
const key = await makeRequestWithTemporalRetry({
const key = await makeRequestWithCredentials({
logId: `uploadGroupAvatar/${logId}`,
publicParams,
secretParams,
@ -1458,7 +1458,7 @@ async function uploadGroupChange({
throw new Error('uploadGroupChange: group was missing publicParams!');
}
return makeRequestWithTemporalRetry({
return makeRequestWithCredentials({
logId: `uploadGroupChange/${logId}`,
publicParams: group.publicParams,
secretParams: group.secretParams,
@ -1676,7 +1676,7 @@ export function deriveGroupFields(masterKey: Uint8Array): GroupFields {
return fresh;
}
async function makeRequestWithTemporalRetry<T>({
async function makeRequestWithCredentials<T>({
logId,
publicParams,
secretParams,
@ -1688,17 +1688,17 @@ async function makeRequestWithTemporalRetry<T>({
request: (sender: MessageSender, options: GroupCredentialsType) => Promise<T>;
}): Promise<T> {
const groupCredentials = getCheckedGroupCredentialsForToday(
`makeRequestWithTemporalRetry/${logId}`
`makeRequestWithCredentials/${logId}`
);
const sender = window.textsecure.messaging;
if (!sender) {
throw new Error(
`makeRequestWithTemporalRetry/${logId}: textsecure.messaging is not available!`
`makeRequestWithCredentials/${logId}: textsecure.messaging is not available!`
);
}
log.info(`makeRequestWithTemporalRetry/${logId}: starting`);
log.info(`makeRequestWithCredentials/${logId}: starting`);
const todayOptions = getGroupCredentials({
authCredentialBase64: groupCredentials.today.credential,
@ -1707,25 +1707,7 @@ async function makeRequestWithTemporalRetry<T>({
serverPublicParamsBase64: window.getServerPublicParams(),
});
try {
return await request(sender, todayOptions);
} catch (todayError) {
if (todayError.code === TEMPORAL_AUTH_REJECTED_CODE) {
log.warn(
`makeRequestWithTemporalRetry/${logId}: Trying again with tomorrow's credentials`
);
const tomorrowOptions = getGroupCredentials({
authCredentialBase64: groupCredentials.tomorrow.credential,
groupPublicParamsBase64: publicParams,
groupSecretParamsBase64: secretParams,
serverPublicParamsBase64: window.getServerPublicParams(),
});
return request(sender, tomorrowOptions);
}
throw todayError;
}
return request(sender, todayOptions);
}
export async function fetchMembershipProof({
@ -1745,7 +1727,7 @@ export async function fetchMembershipProof({
throw new Error('fetchMembershipProof: group was missing secretParams!');
}
const response = await makeRequestWithTemporalRetry({
const response = await makeRequestWithCredentials({
logId: 'fetchMembershipProof',
publicParams,
secretParams,
@ -1897,7 +1879,7 @@ export async function createGroupV2(
});
try {
await makeRequestWithTemporalRetry({
await makeRequestWithCredentials({
logId: `createGroupV2/${logId}`,
publicParams,
secretParams,
@ -2053,7 +2035,7 @@ export async function hasV1GroupBeenMigrated(
const fields = deriveGroupFields(masterKeyBuffer);
try {
await makeRequestWithTemporalRetry({
await makeRequestWithCredentials({
logId: `getGroup/${logId}`,
publicParams: Bytes.toBase64(fields.publicParams),
secretParams: Bytes.toBase64(fields.secretParams),
@ -2410,7 +2392,7 @@ export async function initiateMigrationToGroupV2(
});
try {
await makeRequestWithTemporalRetry({
await makeRequestWithCredentials({
logId: `createGroup/${logId}`,
publicParams,
secretParams,
@ -2731,7 +2713,7 @@ export async function respondToGroupV2Migration({
let firstGroupState: Proto.IGroup | null | undefined;
try {
const response: GroupLogResponseType = await makeRequestWithTemporalRetry({
const response: GroupLogResponseType = await makeRequestWithCredentials({
logId: `getGroupLog/${logId}`,
publicParams,
secretParams,
@ -2755,7 +2737,7 @@ export async function respondToGroupV2Migration({
`respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state`
);
try {
firstGroupState = await makeRequestWithTemporalRetry({
firstGroupState = await makeRequestWithCredentials({
logId: `getGroup/${logId}`,
publicParams,
secretParams,
@ -3601,7 +3583,7 @@ async function updateGroupViaPreJoinInfo({
// No password, but if we're already pending approval, we can access this without it.
const inviteLinkPassword = undefined;
const preJoinInfo = await makeRequestWithTemporalRetry({
const preJoinInfo = await makeRequestWithCredentials({
logId: `getPreJoinInfo/${logId}`,
publicParams,
secretParams,
@ -3669,7 +3651,7 @@ async function updateGroupViaState({
throw new Error('updateGroupViaState: group was missing publicParams!');
}
const groupState = await makeRequestWithTemporalRetry({
const groupState = await makeRequestWithCredentials({
logId: `getGroup/${logId}`,
publicParams,
secretParams,
@ -3813,7 +3795,7 @@ async function updateGroupViaLogs({
const changes: Array<Proto.IGroupChanges> = [];
do {
// eslint-disable-next-line no-await-in-loop
response = await makeRequestWithTemporalRetry({
response = await makeRequestWithCredentials({
logId: `getGroupLog/${logId}`,
publicParams,
secretParams,