| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2018 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The idea with this file is to make it webpackable for the style guide
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-24 13:14:11 -07:00
										 |  |  | import type { ReadonlyDeep } from 'type-fest'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | import * as Crypto from './Crypto'; | 
					
						
							|  |  |  | import * as Curve from './Curve'; | 
					
						
							|  |  |  | import { start as conversationControllerStart } from './ConversationController'; | 
					
						
							|  |  |  | import * as Groups from './groups'; | 
					
						
							| 
									
										
										
										
											2023-04-20 17:23:19 -04:00
										 |  |  | import OS from './util/os/osMain'; | 
					
						
							| 
									
										
										
										
											2024-08-08 16:10:25 -07:00
										 |  |  | import { isProduction } from './util/version'; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | import * as RemoteConfig from './RemoteConfig'; | 
					
						
							| 
									
										
										
										
											2024-08-08 16:10:25 -07:00
										 |  |  | import { DataReader, DataWriter } from './sql/Client'; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Components
 | 
					
						
							|  |  |  | import { ConfirmationDialog } from './components/ConfirmationDialog'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // State
 | 
					
						
							|  |  |  | import { createApp } from './state/roots/createApp'; | 
					
						
							|  |  |  | import { createSafetyNumberViewer } from './state/roots/createSafetyNumberViewer'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Types
 | 
					
						
							|  |  |  | import * as TypesAttachment from './types/Attachment'; | 
					
						
							|  |  |  | import * as VisualAttachment from './types/VisualAttachment'; | 
					
						
							|  |  |  | import * as MessageType from './types/Message2'; | 
					
						
							|  |  |  | import { Address } from './types/Address'; | 
					
						
							|  |  |  | import { QualifiedAddress } from './types/QualifiedAddress'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Processes / Services
 | 
					
						
							|  |  |  | import { initializeGroupCredentialFetcher } from './services/groupCredentialFetcher'; | 
					
						
							|  |  |  | import { initializeNetworkObserver } from './services/networkObserver'; | 
					
						
							|  |  |  | import { initializeUpdateListener } from './services/updateListener'; | 
					
						
							|  |  |  | import { calling } from './services/calling'; | 
					
						
							| 
									
										
										
										
											2022-10-07 17:19:02 -07:00
										 |  |  | import * as storage from './services/storage'; | 
					
						
							| 
									
										
										
										
											2024-03-15 07:20:33 -07:00
										 |  |  | import { backupsService } from './services/backups'; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import type { LoggerType } from './types/Logging'; | 
					
						
							|  |  |  | import type { | 
					
						
							|  |  |  |   AttachmentType, | 
					
						
							|  |  |  |   AttachmentWithHydratedData, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   AddressableAttachmentType, | 
					
						
							|  |  |  |   LocalAttachmentV2Type, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | } from './types/Attachment'; | 
					
						
							|  |  |  | import type { MessageAttributesType, QuotedMessageType } from './model-types.d'; | 
					
						
							|  |  |  | import type { SignalCoreType } from './window.d'; | 
					
						
							| 
									
										
										
										
											2023-04-20 12:31:59 -04:00
										 |  |  | import type { | 
					
						
							|  |  |  |   EmbeddedContactType, | 
					
						
							|  |  |  |   EmbeddedContactWithHydratedAvatar, | 
					
						
							|  |  |  | } from './types/EmbeddedContact'; | 
					
						
							|  |  |  | import type { | 
					
						
							|  |  |  |   LinkPreviewType, | 
					
						
							|  |  |  |   LinkPreviewWithHydratedData, | 
					
						
							|  |  |  | } from './types/message/LinkPreviews'; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | import type { StickerType, StickerWithHydratedData } from './types/Stickers'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  | type EncryptedReader = ( | 
					
						
							|  |  |  |   attachment: Partial<AddressableAttachmentType> | 
					
						
							|  |  |  | ) => Promise<Uint8Array>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type EncryptedWriter = (data: Uint8Array) => Promise<LocalAttachmentV2Type>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | type MigrationsModuleType = { | 
					
						
							|  |  |  |   attachmentsPath: string; | 
					
						
							|  |  |  |   copyIntoAttachmentsDirectory: ( | 
					
						
							|  |  |  |     path: string | 
					
						
							|  |  |  |   ) => Promise<{ path: string; size: number }>; | 
					
						
							|  |  |  |   copyIntoTempDirectory: ( | 
					
						
							|  |  |  |     path: string | 
					
						
							|  |  |  |   ) => Promise<{ path: string; size: number }>; | 
					
						
							|  |  |  |   deleteAttachmentData: (path: string) => Promise<void>; | 
					
						
							|  |  |  |   deleteAvatar: (path: string) => Promise<void>; | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |   deleteDownloadData: (path: string) => Promise<void>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   deleteDraftFile: (path: string) => Promise<void>; | 
					
						
							|  |  |  |   deleteExternalMessageFiles: ( | 
					
						
							|  |  |  |     attributes: MessageAttributesType | 
					
						
							|  |  |  |   ) => Promise<void>; | 
					
						
							|  |  |  |   deleteSticker: (path: string) => Promise<void>; | 
					
						
							|  |  |  |   deleteTempFile: (path: string) => Promise<void>; | 
					
						
							|  |  |  |   doesAttachmentExist: (path: string) => Promise<boolean>; | 
					
						
							| 
									
										
										
										
											2024-10-08 17:07:59 -05:00
										 |  |  |   ensureAttachmentIsReencryptable: ( | 
					
						
							|  |  |  |     attachment: TypesAttachment.LocallySavedAttachment | 
					
						
							|  |  |  |   ) => Promise<TypesAttachment.ReencryptableAttachment>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   getAbsoluteAttachmentPath: (path: string) => string; | 
					
						
							|  |  |  |   getAbsoluteAvatarPath: (src: string) => string; | 
					
						
							|  |  |  |   getAbsoluteBadgeImageFilePath: (path: string) => string; | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |   getAbsoluteDownloadsPath: (path: string) => string; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   getAbsoluteDraftPath: (path: string) => string; | 
					
						
							|  |  |  |   getAbsoluteStickerPath: (path: string) => string; | 
					
						
							|  |  |  |   getAbsoluteTempPath: (path: string) => string; | 
					
						
							|  |  |  |   loadAttachmentData: ( | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |     attachment: Partial<AttachmentType> | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   ) => Promise<AttachmentWithHydratedData>; | 
					
						
							|  |  |  |   loadContactData: ( | 
					
						
							| 
									
										
										
										
											2024-07-24 13:14:11 -07:00
										 |  |  |     contact: ReadonlyArray<ReadonlyDeep<EmbeddedContactType>> | undefined | 
					
						
							| 
									
										
										
										
											2023-04-20 12:31:59 -04:00
										 |  |  |   ) => Promise<Array<EmbeddedContactWithHydratedAvatar> | undefined>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   loadMessage: ( | 
					
						
							|  |  |  |     message: MessageAttributesType | 
					
						
							|  |  |  |   ) => Promise<MessageAttributesType>; | 
					
						
							|  |  |  |   loadPreviewData: ( | 
					
						
							| 
									
										
										
										
											2024-07-24 13:14:11 -07:00
										 |  |  |     preview: ReadonlyArray<ReadonlyDeep<LinkPreviewType>> | undefined | 
					
						
							| 
									
										
										
										
											2023-04-20 12:31:59 -04:00
										 |  |  |   ) => Promise<Array<LinkPreviewWithHydratedData>>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   loadQuoteData: ( | 
					
						
							|  |  |  |     quote: QuotedMessageType | null | undefined | 
					
						
							|  |  |  |   ) => Promise<QuotedMessageType | null>; | 
					
						
							|  |  |  |   loadStickerData: ( | 
					
						
							|  |  |  |     sticker: StickerType | undefined | 
					
						
							|  |  |  |   ) => Promise<StickerWithHydratedData | undefined>; | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   readAttachmentData: EncryptedReader; | 
					
						
							|  |  |  |   readAvatarData: EncryptedReader; | 
					
						
							|  |  |  |   readDraftData: EncryptedReader; | 
					
						
							|  |  |  |   readStickerData: EncryptedReader; | 
					
						
							|  |  |  |   readTempData: EncryptedReader; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   saveAttachmentToDisk: (options: { | 
					
						
							|  |  |  |     data: Uint8Array; | 
					
						
							|  |  |  |     name: string; | 
					
						
							|  |  |  |   }) => Promise<null | { fullPath: string; name: string }>; | 
					
						
							|  |  |  |   processNewAttachment: (attachment: AttachmentType) => Promise<AttachmentType>; | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   processNewSticker: (stickerData: Uint8Array) => Promise< | 
					
						
							|  |  |  |     LocalAttachmentV2Type & { | 
					
						
							|  |  |  |       width: number; | 
					
						
							|  |  |  |       height: number; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   >; | 
					
						
							|  |  |  |   processNewEphemeralSticker: (stickerData: Uint8Array) => Promise< | 
					
						
							|  |  |  |     LocalAttachmentV2Type & { | 
					
						
							|  |  |  |       width: number; | 
					
						
							|  |  |  |       height: number; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   >; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   upgradeMessageSchema: ( | 
					
						
							|  |  |  |     attributes: MessageAttributesType, | 
					
						
							| 
									
										
										
										
											2024-03-06 16:49:21 -05:00
										 |  |  |     options?: { maxVersion?: number } | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   ) => Promise<MessageAttributesType>; | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   writeNewAttachmentData: EncryptedWriter; | 
					
						
							|  |  |  |   writeNewDraftData: EncryptedWriter; | 
					
						
							|  |  |  |   writeNewAvatarData: EncryptedWriter; | 
					
						
							|  |  |  |   writeNewStickerData: EncryptedWriter; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   writeNewBadgeImageFileData: (data: Uint8Array) => Promise<string>; | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   writeNewPlaintextTempData: (data: Uint8Array) => Promise<string>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function initializeMigrations({ | 
					
						
							|  |  |  |   getRegionCode, | 
					
						
							|  |  |  |   Attachments, | 
					
						
							|  |  |  |   Type, | 
					
						
							|  |  |  |   VisualType, | 
					
						
							|  |  |  |   logger, | 
					
						
							|  |  |  |   userDataPath, | 
					
						
							|  |  |  | }: { | 
					
						
							|  |  |  |   getRegionCode: () => string | undefined; | 
					
						
							|  |  |  |   Attachments: AttachmentsModuleType; | 
					
						
							|  |  |  |   Type: typeof TypesAttachment; | 
					
						
							|  |  |  |   VisualType: typeof VisualAttachment; | 
					
						
							|  |  |  |   logger: LoggerType; | 
					
						
							|  |  |  |   userDataPath: string; | 
					
						
							|  |  |  | }): MigrationsModuleType { | 
					
						
							|  |  |  |   if (!Attachments) { | 
					
						
							|  |  |  |     throw new Error('initializeMigrations: Missing provided attachments!'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     createAbsolutePathGetter, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |     createPlaintextReader, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     createWriterForNew, | 
					
						
							|  |  |  |     createDoesExist, | 
					
						
							| 
									
										
										
										
											2024-10-08 17:07:59 -05:00
										 |  |  |     ensureAttachmentIsReencryptable, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     getAvatarsPath, | 
					
						
							|  |  |  |     getDraftPath, | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |     getDownloadsPath, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     getPath, | 
					
						
							|  |  |  |     getStickersPath, | 
					
						
							|  |  |  |     getBadgesPath, | 
					
						
							|  |  |  |     getTempPath, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |     readAndDecryptDataFromDisk, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     saveAttachmentToDisk, | 
					
						
							|  |  |  |   } = Attachments; | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     getImageDimensions, | 
					
						
							|  |  |  |     makeImageThumbnail, | 
					
						
							|  |  |  |     makeObjectUrl, | 
					
						
							|  |  |  |     makeVideoScreenshot, | 
					
						
							|  |  |  |     revokeObjectUrl, | 
					
						
							|  |  |  |   } = VisualType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const attachmentsPath = getPath(userDataPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function createEncryptedReader(basePath: string): EncryptedReader { | 
					
						
							|  |  |  |     const fallbackReader = createPlaintextReader(basePath); | 
					
						
							|  |  |  |     const pathGetter = createAbsolutePathGetter(basePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return async ( | 
					
						
							|  |  |  |       attachment: Partial<AddressableAttachmentType> | 
					
						
							|  |  |  |     ): Promise<Uint8Array> => { | 
					
						
							|  |  |  |       // In-memory
 | 
					
						
							|  |  |  |       if (attachment.data != null) { | 
					
						
							|  |  |  |         return attachment.data; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (attachment.path == null) { | 
					
						
							|  |  |  |         throw new Error('Attachment was not downloaded yet'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (attachment.version !== 2) { | 
					
						
							|  |  |  |         return fallbackReader(attachment.path); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (attachment.localKey == null || attachment.size == null) { | 
					
						
							|  |  |  |         throw new Error('Failed to decrypt v2 attachment'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const absolutePath = pathGetter(attachment.path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return readAndDecryptDataFromDisk({ | 
					
						
							|  |  |  |         absolutePath, | 
					
						
							|  |  |  |         keysBase64: attachment.localKey, | 
					
						
							|  |  |  |         size: attachment.size, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function createEncryptedWriterForNew(basePath: string): EncryptedWriter { | 
					
						
							|  |  |  |     const pathGetter = createAbsolutePathGetter(basePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return data => | 
					
						
							|  |  |  |       Attachments.writeNewAttachmentData({ | 
					
						
							|  |  |  |         data, | 
					
						
							|  |  |  |         getAbsoluteAttachmentPath: pathGetter, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const readAttachmentData = createEncryptedReader(attachmentsPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const loadAttachmentData = Type.loadData(readAttachmentData); | 
					
						
							|  |  |  |   const loadContactData = MessageType.loadContactData(loadAttachmentData); | 
					
						
							|  |  |  |   const loadPreviewData = MessageType.loadPreviewData(loadAttachmentData); | 
					
						
							|  |  |  |   const loadQuoteData = MessageType.loadQuoteData(loadAttachmentData); | 
					
						
							|  |  |  |   const loadStickerData = MessageType.loadStickerData(loadAttachmentData); | 
					
						
							|  |  |  |   const getAbsoluteAttachmentPath = createAbsolutePathGetter(attachmentsPath); | 
					
						
							|  |  |  |   const deleteOnDisk = Attachments.createDeleter(attachmentsPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const writeNewAttachmentData = createEncryptedWriterForNew(attachmentsPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const copyIntoAttachmentsDirectory = | 
					
						
							|  |  |  |     Attachments.copyIntoAttachmentsDirectory(attachmentsPath); | 
					
						
							|  |  |  |   const doesAttachmentExist = createDoesExist(attachmentsPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const stickersPath = getStickersPath(userDataPath); | 
					
						
							|  |  |  |   const getAbsoluteStickerPath = createAbsolutePathGetter(stickersPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const writeNewStickerData = createEncryptedWriterForNew(stickersPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const deleteSticker = Attachments.createDeleter(stickersPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const readStickerData = createEncryptedReader(stickersPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const badgesPath = getBadgesPath(userDataPath); | 
					
						
							|  |  |  |   const getAbsoluteBadgeImageFilePath = createAbsolutePathGetter(badgesPath); | 
					
						
							|  |  |  |   const writeNewBadgeImageFileData = createWriterForNew(badgesPath, '.svg'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const tempPath = getTempPath(userDataPath); | 
					
						
							|  |  |  |   const getAbsoluteTempPath = createAbsolutePathGetter(tempPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const writeNewTempData = createEncryptedWriterForNew(tempPath); | 
					
						
							|  |  |  |   const writeNewPlaintextTempData = createWriterForNew(tempPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const deleteTempFile = Attachments.createDeleter(tempPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const readTempData = createEncryptedReader(tempPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const copyIntoTempDirectory = | 
					
						
							|  |  |  |     Attachments.copyIntoAttachmentsDirectory(tempPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const draftPath = getDraftPath(userDataPath); | 
					
						
							|  |  |  |   const getAbsoluteDraftPath = createAbsolutePathGetter(draftPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const writeNewDraftData = createEncryptedWriterForNew(draftPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const deleteDraftFile = Attachments.createDeleter(draftPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const readDraftData = createEncryptedReader(draftPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |   const downloadsPath = getDownloadsPath(userDataPath); | 
					
						
							|  |  |  |   const getAbsoluteDownloadsPath = createAbsolutePathGetter(downloadsPath); | 
					
						
							|  |  |  |   const deleteDownloadOnDisk = Attachments.createDeleter(downloadsPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const avatarsPath = getAvatarsPath(userDataPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const readAvatarData = createEncryptedReader(avatarsPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const getAbsoluteAvatarPath = createAbsolutePathGetter(avatarsPath); | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   const writeNewAvatarData = createEncryptedWriterForNew(avatarsPath); | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   const deleteAvatar = Attachments.createDeleter(avatarsPath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     attachmentsPath, | 
					
						
							|  |  |  |     copyIntoAttachmentsDirectory, | 
					
						
							|  |  |  |     copyIntoTempDirectory, | 
					
						
							|  |  |  |     deleteAttachmentData: deleteOnDisk, | 
					
						
							|  |  |  |     deleteAvatar, | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |     deleteDownloadData: deleteDownloadOnDisk, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     deleteDraftFile, | 
					
						
							|  |  |  |     deleteExternalMessageFiles: MessageType.deleteAllExternalFiles({ | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |       deleteAttachmentData: Type.deleteData({ | 
					
						
							|  |  |  |         deleteOnDisk, | 
					
						
							|  |  |  |         deleteDownloadOnDisk, | 
					
						
							|  |  |  |       }), | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |       deleteOnDisk, | 
					
						
							|  |  |  |     }), | 
					
						
							|  |  |  |     deleteSticker, | 
					
						
							|  |  |  |     deleteTempFile, | 
					
						
							|  |  |  |     doesAttachmentExist, | 
					
						
							| 
									
										
										
										
											2024-10-08 17:07:59 -05:00
										 |  |  |     ensureAttachmentIsReencryptable, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     getAbsoluteAttachmentPath, | 
					
						
							|  |  |  |     getAbsoluteAvatarPath, | 
					
						
							|  |  |  |     getAbsoluteBadgeImageFilePath, | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |     getAbsoluteDownloadsPath, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     getAbsoluteDraftPath, | 
					
						
							|  |  |  |     getAbsoluteStickerPath, | 
					
						
							|  |  |  |     getAbsoluteTempPath, | 
					
						
							|  |  |  |     loadAttachmentData, | 
					
						
							|  |  |  |     loadContactData, | 
					
						
							|  |  |  |     loadMessage: MessageType.createAttachmentLoader(loadAttachmentData), | 
					
						
							|  |  |  |     loadPreviewData, | 
					
						
							|  |  |  |     loadQuoteData, | 
					
						
							|  |  |  |     loadStickerData, | 
					
						
							|  |  |  |     readAttachmentData, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |     readAvatarData, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     readDraftData, | 
					
						
							|  |  |  |     readStickerData, | 
					
						
							|  |  |  |     readTempData, | 
					
						
							|  |  |  |     saveAttachmentToDisk, | 
					
						
							|  |  |  |     processNewAttachment: (attachment: AttachmentType) => | 
					
						
							|  |  |  |       MessageType.processNewAttachment(attachment, { | 
					
						
							|  |  |  |         writeNewAttachmentData, | 
					
						
							| 
									
										
										
										
											2024-10-08 17:07:59 -05:00
										 |  |  |         ensureAttachmentIsReencryptable, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         makeObjectUrl, | 
					
						
							|  |  |  |         revokeObjectUrl, | 
					
						
							|  |  |  |         getImageDimensions, | 
					
						
							|  |  |  |         makeImageThumbnail, | 
					
						
							|  |  |  |         makeVideoScreenshot, | 
					
						
							| 
									
										
										
										
											2024-01-04 11:34:53 -08:00
										 |  |  |         deleteOnDisk, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         logger, | 
					
						
							|  |  |  |       }), | 
					
						
							|  |  |  |     processNewSticker: (stickerData: Uint8Array) => | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |       MessageType.processNewSticker(stickerData, false, { | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         writeNewStickerData, | 
					
						
							|  |  |  |         getImageDimensions, | 
					
						
							|  |  |  |         logger, | 
					
						
							|  |  |  |       }), | 
					
						
							|  |  |  |     processNewEphemeralSticker: (stickerData: Uint8Array) => | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |       MessageType.processNewSticker(stickerData, true, { | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         writeNewStickerData: writeNewTempData, | 
					
						
							|  |  |  |         getImageDimensions, | 
					
						
							|  |  |  |         logger, | 
					
						
							|  |  |  |       }), | 
					
						
							|  |  |  |     upgradeMessageSchema: ( | 
					
						
							|  |  |  |       message: MessageAttributesType, | 
					
						
							| 
									
										
										
										
											2024-03-06 16:49:21 -05:00
										 |  |  |       options: { maxVersion?: number } = {} | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     ) => { | 
					
						
							| 
									
										
										
										
											2024-03-06 16:49:21 -05:00
										 |  |  |       const { maxVersion } = options; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       return MessageType.upgradeSchema(message, { | 
					
						
							| 
									
										
										
										
											2024-01-08 16:31:24 -08:00
										 |  |  |         deleteOnDisk, | 
					
						
							| 
									
										
										
										
											2024-10-08 17:07:59 -05:00
										 |  |  |         doesAttachmentExist, | 
					
						
							|  |  |  |         ensureAttachmentIsReencryptable, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         getImageDimensions, | 
					
						
							| 
									
										
										
										
											2024-01-08 16:31:24 -08:00
										 |  |  |         getRegionCode, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         makeImageThumbnail, | 
					
						
							| 
									
										
										
										
											2024-01-08 16:31:24 -08:00
										 |  |  |         makeObjectUrl, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         makeVideoScreenshot, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |         readAttachmentData, | 
					
						
							| 
									
										
										
										
											2024-01-08 16:31:24 -08:00
										 |  |  |         revokeObjectUrl, | 
					
						
							|  |  |  |         writeNewAttachmentData, | 
					
						
							|  |  |  |         writeNewStickerData, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |         logger, | 
					
						
							|  |  |  |         maxVersion, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |     writeNewAttachmentData, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     writeNewAvatarData, | 
					
						
							|  |  |  |     writeNewDraftData, | 
					
						
							|  |  |  |     writeNewBadgeImageFileData, | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |     writeNewPlaintextTempData, | 
					
						
							|  |  |  |     writeNewStickerData, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type StringGetterType = (basePath: string) => string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type AttachmentsModuleType = { | 
					
						
							|  |  |  |   getAvatarsPath: StringGetterType; | 
					
						
							|  |  |  |   getBadgesPath: StringGetterType; | 
					
						
							| 
									
										
										
										
											2024-08-19 13:05:35 -07:00
										 |  |  |   getDownloadsPath: StringGetterType; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   getDraftPath: StringGetterType; | 
					
						
							|  |  |  |   getPath: StringGetterType; | 
					
						
							|  |  |  |   getStickersPath: StringGetterType; | 
					
						
							|  |  |  |   getTempPath: StringGetterType; | 
					
						
							|  |  |  |   getUpdateCachePath: StringGetterType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createDeleter: (root: string) => (relativePath: string) => Promise<void>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   createPlaintextReader: ( | 
					
						
							|  |  |  |     root: string | 
					
						
							|  |  |  |   ) => (relativePath: string) => Promise<Uint8Array>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   copyIntoAttachmentsDirectory: ( | 
					
						
							|  |  |  |     root: string | 
					
						
							|  |  |  |   ) => (sourcePath: string) => Promise<{ path: string; size: number }>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createWriterForNew: ( | 
					
						
							|  |  |  |     root: string, | 
					
						
							|  |  |  |     suffix?: string | 
					
						
							|  |  |  |   ) => (bytes: Uint8Array) => Promise<string>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createAbsolutePathGetter: ( | 
					
						
							|  |  |  |     rootPath: string | 
					
						
							|  |  |  |   ) => (relativePath: string) => string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createDoesExist: (root: string) => (relativePath: string) => Promise<boolean>; | 
					
						
							|  |  |  |   saveAttachmentToDisk: ({ | 
					
						
							|  |  |  |     data, | 
					
						
							|  |  |  |     name, | 
					
						
							|  |  |  |   }: { | 
					
						
							|  |  |  |     data: Uint8Array; | 
					
						
							|  |  |  |     name: string; | 
					
						
							|  |  |  |   }) => Promise<null | { fullPath: string; name: string }>; | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-08 17:07:59 -05:00
										 |  |  |   ensureAttachmentIsReencryptable: ( | 
					
						
							|  |  |  |     attachment: TypesAttachment.LocallySavedAttachment | 
					
						
							|  |  |  |   ) => Promise<TypesAttachment.ReencryptableAttachment>; | 
					
						
							| 
									
										
										
										
											2024-07-11 12:44:09 -07:00
										 |  |  |   readAndDecryptDataFromDisk: (options: { | 
					
						
							|  |  |  |     absolutePath: string; | 
					
						
							|  |  |  |     keysBase64: string; | 
					
						
							|  |  |  |     size: number; | 
					
						
							|  |  |  |   }) => Promise<Uint8Array>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   writeNewAttachmentData: (options: { | 
					
						
							|  |  |  |     data: Uint8Array; | 
					
						
							|  |  |  |     getAbsoluteAttachmentPath: (relativePath: string) => string; | 
					
						
							|  |  |  |   }) => Promise<LocalAttachmentV2Type>; | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const setup = (options: { | 
					
						
							|  |  |  |   Attachments: AttachmentsModuleType; | 
					
						
							|  |  |  |   getRegionCode: () => string | undefined; | 
					
						
							|  |  |  |   logger: LoggerType; | 
					
						
							|  |  |  |   userDataPath: string; | 
					
						
							|  |  |  | }): SignalCoreType => { | 
					
						
							|  |  |  |   const { Attachments, getRegionCode, logger, userDataPath } = options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Migrations = initializeMigrations({ | 
					
						
							|  |  |  |     getRegionCode, | 
					
						
							|  |  |  |     Attachments, | 
					
						
							|  |  |  |     Type: TypesAttachment, | 
					
						
							|  |  |  |     VisualType: VisualAttachment, | 
					
						
							|  |  |  |     logger, | 
					
						
							|  |  |  |     userDataPath, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Components = { | 
					
						
							|  |  |  |     ConfirmationDialog, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Roots = { | 
					
						
							|  |  |  |     createApp, | 
					
						
							|  |  |  |     createSafetyNumberViewer, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Services = { | 
					
						
							| 
									
										
										
										
											2024-03-15 07:20:33 -07:00
										 |  |  |     backups: backupsService, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |     calling, | 
					
						
							|  |  |  |     initializeGroupCredentialFetcher, | 
					
						
							|  |  |  |     initializeNetworkObserver, | 
					
						
							|  |  |  |     initializeUpdateListener, | 
					
						
							| 
									
										
										
										
											2022-10-07 17:19:02 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Testing
 | 
					
						
							|  |  |  |     storage, | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const State = { | 
					
						
							|  |  |  |     Roots, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Types = { | 
					
						
							|  |  |  |     Message: MessageType, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Mostly for debugging
 | 
					
						
							|  |  |  |     Address, | 
					
						
							|  |  |  |     QualifiedAddress, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     Components, | 
					
						
							|  |  |  |     Crypto, | 
					
						
							|  |  |  |     Curve, | 
					
						
							|  |  |  |     // Note: used in test/index.html, and not type-checked!
 | 
					
						
							|  |  |  |     conversationControllerStart, | 
					
						
							|  |  |  |     Groups, | 
					
						
							|  |  |  |     Migrations, | 
					
						
							|  |  |  |     OS, | 
					
						
							|  |  |  |     RemoteConfig, | 
					
						
							|  |  |  |     Services, | 
					
						
							|  |  |  |     State, | 
					
						
							|  |  |  |     Types, | 
					
						
							| 
									
										
										
										
											2024-08-08 16:10:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ...(isProduction(window.getVersion()) | 
					
						
							|  |  |  |       ? {} | 
					
						
							|  |  |  |       : { | 
					
						
							|  |  |  |           DataReader, | 
					
						
							|  |  |  |           DataWriter, | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2022-06-13 14:39:35 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; |