1- /* @ts -ignore */
21import * as libsignal from 'libsignal'
32import { LRUCache } from 'lru-cache'
43import type { LIDMapping , SignalAuthState , SignalKeyStoreWithTransaction } from '../Types'
@@ -26,7 +25,7 @@ export function makeLibSignalRepository(
2625 pnToLIDFunc ?: ( jids : string [ ] ) => Promise < LIDMapping [ ] | undefined >
2726) : SignalRepositoryWithLIDStore {
2827 const lidMapping = new LIDMappingStore ( auth . keys as SignalKeyStoreWithTransaction , logger , pnToLIDFunc )
29- const storage = signalStorage ( auth , lidMapping )
28+ const storage = signalStorage ( auth , lidMapping , logger )
3029
3130 const parsedKeys = auth . keys as SignalKeyStoreWithTransaction
3231 const migratedSessionCache = new LRUCache < string , true > ( {
@@ -77,7 +76,7 @@ export function makeLibSignalRepository(
7776 } ,
7877 async decryptMessage ( { jid, type, ciphertext } ) {
7978 const addr = jidToSignalProtocolAddress ( jid )
80- const session = new libsignal . SessionCipher ( storage , addr )
79+ const session = new libsignal . SessionCipher ( storage , addr , logger )
8180
8281 async function doDecrypt ( ) {
8382 let result : Buffer
@@ -102,7 +101,7 @@ export function makeLibSignalRepository(
102101
103102 async encryptMessage ( { jid, data } ) {
104103 const addr = jidToSignalProtocolAddress ( jid )
105- const cipher = new libsignal . SessionCipher ( storage , addr )
104+ const cipher = new libsignal . SessionCipher ( storage , addr , logger )
106105
107106 // Use transaction to ensure atomicity
108107 return parsedKeys . transaction ( async ( ) => {
@@ -137,7 +136,7 @@ export function makeLibSignalRepository(
137136
138137 async injectE2ESession ( { jid, session } ) {
139138 logger . trace ( { jid } , 'injecting E2EE session' )
140- const cipher = new libsignal . SessionBuilder ( storage , jidToSignalProtocolAddress ( jid ) )
139+ const cipher = new libsignal . SessionBuilder ( storage , jidToSignalProtocolAddress ( jid ) , logger )
141140 return parsedKeys . transaction ( async ( ) => {
142141 await cipher . initOutgoing ( session )
143142 } , jid )
@@ -296,7 +295,7 @@ export function makeLibSignalRepository(
296295 const pnSession = pnSessions [ pnAddrStr ]
297296 if ( pnSession ) {
298297 // Session exists (guaranteed from device discovery)
299- const fromSession = libsignal . SessionRecord . deserialize ( pnSession )
298+ const fromSession = libsignal . SessionRecord . deserialize ( pnSession , logger )
300299 if ( fromSession . haveOpenSession ( ) ) {
301300 // Queue for bulk update: copy to LID, delete from PN
302301 sessionUpdates [ lidAddrStr ] = fromSession . serialize ( )
@@ -358,7 +357,8 @@ const jidToSignalSenderKeyName = (group: string, user: string): SenderKeyName =>
358357
359358function signalStorage (
360359 { creds, keys } : SignalAuthState ,
361- lidMapping : LIDMappingStore
360+ lidMapping : LIDMappingStore ,
361+ logger ?: ILogger
362362) : SenderKeyStore & libsignal . SignalStorage {
363363 // Shared function to resolve PN signal address to LID if mapping exists
364364 const resolveLIDSignalAddress = async ( id : string ) : Promise < string > => {
@@ -388,7 +388,7 @@ function signalStorage(
388388 const { [ wireJid ] : sess } = await keys . get ( 'session' , [ wireJid ] )
389389
390390 if ( sess ) {
391- return libsignal . SessionRecord . deserialize ( sess )
391+ return libsignal . SessionRecord . deserialize ( sess , logger )
392392 }
393393 } catch ( e ) {
394394 return null
0 commit comments