@@ -23,11 +23,6 @@ type UploadParams = {
2323 * Explicit padding is only needed for the legacy encryption, as libsession deterministic encryption already pads the data.
2424 */
2525 shouldPad ?: boolean ;
26- /**
27- * When using the deterministic encryption, this is the seed used to generate the encryption key (libsession encrypt)
28- * When not using the deterministic encryption, this is used as the encryption key (legacy encrypt)
29- */
30- encryptionKey : Uint8Array ;
3126} ;
3227
3328export interface RawPreview {
@@ -80,17 +75,18 @@ async function uploadToFileServer(params: UploadParams): Promise<AttachmentPoint
8075 'Using deterministic encryption for attachment upload: ' ,
8176 attachment . fileName
8277 ) ;
78+ const seed = await UserUtils . getUserEd25519Seed ( ) ;
8379 const encryptedContent = await MultiEncryptWrapperActions . attachmentEncrypt ( {
8480 allowLarge : false ,
85- seed : params . encryptionKey ,
81+ seed,
8682 data : new Uint8Array ( attachment . data ) ,
8783 domain : 'attachment' ,
8884 } ) ;
8985 pointer . key = encryptedContent . encryptionKey ;
9086 attachmentData = encryptedContent . encryptedData ;
9187 } else {
9288 // this is the legacy attachment encryption
93- pointer . key = new Uint8Array ( params . encryptionKey ) ;
89+ pointer . key = new Uint8Array ( crypto . randomBytes ( 64 ) ) ;
9490 const iv = new Uint8Array ( crypto . randomBytes ( 16 ) ) ;
9591
9692 const dataToEncrypt = ! shouldPad ? attachment . data : addAttachmentPadding ( attachment . data ) ;
@@ -115,15 +111,10 @@ async function uploadToFileServer(params: UploadParams): Promise<AttachmentPoint
115111export async function uploadAttachmentsToFileServer (
116112 attachments : Array < Attachment >
117113) : Promise < Array < AttachmentPointerWithUrl > > {
118- const encryptionKey = window . sessionFeatureFlags . useDeterministicEncryption
119- ? await UserUtils . getUserEd25519Seed ( )
120- : crypto . randomBytes ( 32 ) ;
121-
122114 const promises = ( attachments || [ ] ) . map ( async attachment =>
123115 uploadToFileServer ( {
124116 attachment,
125117 shouldPad : true ,
126- encryptionKey,
127118 } )
128119 ) ;
129120
@@ -140,13 +131,9 @@ export async function uploadLinkPreviewToFileServer(
140131 }
141132 return preview as any ;
142133 }
143- const encryptionKey = window . sessionFeatureFlags . useDeterministicEncryption
144- ? await UserUtils . getUserEd25519Seed ( )
145- : crypto . randomBytes ( 32 ) ;
146134
147135 const image = await uploadToFileServer ( {
148136 attachment : preview . image ,
149- encryptionKey,
150137 } ) ;
151138 return {
152139 ...preview ,
0 commit comments