diff --git a/ts/groups.ts b/ts/groups.ts index 50980e42b..6b1413a70 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -1307,7 +1307,7 @@ export async function modifyGroupV2({ await conversationJobQueue.add({ type: conversationQueueJobEnum.enum.GroupUpdate, conversationId: conversation.id, - groupChangeBase64: Bytes.toBase64(groupChangeBuffer), + groupChangeBase64, recipients: groupV2Info.members, revision: groupV2Info.revision, }); diff --git a/ts/test-electron/util/sendToGroup_test.ts b/ts/test-electron/util/sendToGroup_test.ts index 0c06f733b..0f4acd5b7 100644 --- a/ts/test-electron/util/sendToGroup_test.ts +++ b/ts/test-electron/util/sendToGroup_test.ts @@ -178,12 +178,7 @@ describe('sendToGroup', () => { it('returns true for certain types of error subclasses', async () => { assert.isTrue( _shouldFailSend( - new OutgoingIdentityKeyError( - 'something', - new Uint8Array(), - 200, - new Uint8Array() - ), + new OutgoingIdentityKeyError('something'), 'testing OutgoingIdentityKeyError' ) ); diff --git a/ts/textsecure/Errors.ts b/ts/textsecure/Errors.ts index ff7e71913..6e78d5cc1 100644 --- a/ts/textsecure/Errors.ts +++ b/ts/textsecure/Errors.ts @@ -73,15 +73,8 @@ export class ReplayableError extends Error { export class OutgoingIdentityKeyError extends ReplayableError { identifier: string; - identityKey: Uint8Array; - // Note: Data to resend message is no longer captured - constructor( - incomingIdentifier: string, - _m: Uint8Array, - _t: number, - identityKey: Uint8Array - ) { + constructor(incomingIdentifier: string) { const identifier = incomingIdentifier.split('.')[0]; super({ @@ -90,7 +83,6 @@ export class OutgoingIdentityKeyError extends ReplayableError { }); this.identifier = identifier; - this.identityKey = identityKey; } } diff --git a/ts/textsecure/OutgoingMessage.ts b/ts/textsecure/OutgoingMessage.ts index 726f73c32..5a50136e0 100644 --- a/ts/textsecure/OutgoingMessage.ts +++ b/ts/textsecure/OutgoingMessage.ts @@ -707,12 +707,7 @@ export default class OutgoingMessage { await this.reloadDevicesAndSend(identifier, true)(); } catch (error) { if (error?.message?.includes('untrusted identity for address')) { - const newError = new OutgoingIdentityKeyError( - identifier, - error.originalMessage, - error.timestamp, - error.identityKey && new Uint8Array(error.identityKey) - ); + const newError = new OutgoingIdentityKeyError(identifier); this.registerError(identifier, 'Untrusted identity', newError); } else { this.registerError( diff --git a/ts/textsecure/getKeysForIdentifier.ts b/ts/textsecure/getKeysForIdentifier.ts index 4fb8a466f..0333f9c6d 100644 --- a/ts/textsecure/getKeysForIdentifier.ts +++ b/ts/textsecure/getKeysForIdentifier.ts @@ -8,13 +8,18 @@ import { PublicKey, } from '@signalapp/signal-client'; -import { UnregisteredUserError, HTTPError } from './Errors'; +import { + UnregisteredUserError, + HTTPError, + OutgoingIdentityKeyError, +} from './Errors'; import { Sessions, IdentityKeys } from '../LibSignalStores'; import { Address } from '../types/Address'; import { QualifiedAddress } from '../types/QualifiedAddress'; import { UUID } from '../types/UUID'; import type { ServerKeysType, WebAPIType } from './WebAPI'; import * as log from '../logging/log'; +import { isRecord } from '../util/isRecord'; export async function getKeysForIdentifier( identifier: string, @@ -54,20 +59,32 @@ async function getServerKeys( server: WebAPIType, accessKey?: string ): Promise<{ accessKeyFailed?: boolean; keys: ServerKeysType }> { - if (!accessKey) { - return { - keys: await server.getKeysForIdentifier(identifier), - }; - } - try { + if (!accessKey) { + return { + keys: await server.getKeysForIdentifier(identifier), + }; + } + return { keys: await server.getKeysForIdentifierUnauth(identifier, undefined, { accessKey, }), }; - } catch (error) { - if (error.code === 401 || error.code === 403) { + } catch (error: unknown) { + if ( + error instanceof Error && + error.message.includes('untrusted identity') + ) { + throw new OutgoingIdentityKeyError(identifier); + } + + if ( + accessKey && + isRecord(error) && + typeof error.code === 'number' && + (error.code === 401 || error.code === 403) + ) { return { accessKeyFailed: true, keys: await server.getKeysForIdentifier(identifier), diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index 69afd2cf5..3042a6358 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -1268,8 +1268,8 @@ async function fetchKeysForIdentifier( }); window.Signal.Data.updateConversation(emptyConversation.attributes); } - } catch (error) { - if (error.name === 'UnregisteredUserError') { + } catch (error: unknown) { + if (error instanceof UnregisteredUserError) { await markIdentifierUnregistered(identifier); return; }