@wireapp/wire-apps-js-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -3
- package/build/WireAppSdk.d.ts +22 -2
- package/build/WireAppSdk.d.ts.map +1 -1
- package/build/WireAppSdk.js +88 -27
- package/build/WireAppSdk.js.map +1 -1
- package/build/WireAppSdkOptions.d.ts +26 -0
- package/build/WireAppSdkOptions.d.ts.map +1 -0
- package/build/WireAppSdkOptions.js +17 -0
- package/build/WireAppSdkOptions.js.map +1 -0
- package/build/api/ConversationService.d.ts +1 -0
- package/build/api/ConversationService.d.ts.map +1 -1
- package/build/api/ConversationService.js +7 -0
- package/build/api/ConversationService.js.map +1 -1
- package/build/api/MlsApiClient.d.ts +2 -0
- package/build/api/MlsApiClient.d.ts.map +1 -1
- package/build/api/MlsApiClient.js +4 -0
- package/build/api/MlsApiClient.js.map +1 -1
- package/build/api/MlsService.d.ts +1 -0
- package/build/api/MlsService.d.ts.map +1 -1
- package/build/api/MlsService.js +3 -0
- package/build/api/MlsService.js.map +1 -1
- package/build/api/UserService.d.ts +0 -1
- package/build/api/UserService.d.ts.map +1 -1
- package/build/api/UserService.js +2 -4
- package/build/api/UserService.js.map +1 -1
- package/build/api/UsersApiClient.d.ts +0 -2
- package/build/api/UsersApiClient.d.ts.map +1 -1
- package/build/api/UsersApiClient.js +0 -4
- package/build/api/UsersApiClient.js.map +1 -1
- package/build/api/response/MlsKeyPackageCountResponse.d.ts +4 -0
- package/build/api/response/MlsKeyPackageCountResponse.d.ts.map +1 -0
- package/build/api/response/MlsKeyPackageCountResponse.js +17 -0
- package/build/api/response/MlsKeyPackageCountResponse.js.map +1 -0
- package/build/core/CoreCryptoClient.d.ts +4 -4
- package/build/core/CoreCryptoClient.d.ts.map +1 -1
- package/build/core/CoreCryptoClient.js +9 -10
- package/build/core/CoreCryptoClient.js.map +1 -1
- package/build/core/CoreCryptoService.d.ts +3 -1
- package/build/core/CoreCryptoService.d.ts.map +1 -1
- package/build/core/CoreCryptoService.js +21 -7
- package/build/core/CoreCryptoService.js.map +1 -1
- package/build/core/HttpClient.d.ts.map +1 -1
- package/build/core/HttpClient.js +2 -1
- package/build/core/HttpClient.js.map +1 -1
- package/build/core/WebSocketClient.d.ts.map +1 -1
- package/build/core/WebSocketClient.js +3 -3
- package/build/core/WebSocketClient.js.map +1 -1
- package/build/core/WireApplicationManager.d.ts +0 -1
- package/build/core/WireApplicationManager.d.ts.map +1 -1
- package/build/core/WireApplicationManager.js +0 -4
- package/build/core/WireApplicationManager.js.map +1 -1
- package/build/core/WireEventsHandler.d.ts +8 -0
- package/build/core/WireEventsHandler.d.ts.map +1 -1
- package/build/core/WireEventsHandler.js +9 -0
- package/build/core/WireEventsHandler.js.map +1 -1
- package/build/core/event/MlsWelcomeEventProcessor.d.ts +2 -3
- package/build/core/event/MlsWelcomeEventProcessor.d.ts.map +1 -1
- package/build/core/event/MlsWelcomeEventProcessor.js +12 -10
- package/build/core/event/MlsWelcomeEventProcessor.js.map +1 -1
- package/build/core/event/TeamMemberJoinEventProcessor.d.ts +13 -0
- package/build/core/event/TeamMemberJoinEventProcessor.d.ts.map +1 -0
- package/build/core/event/TeamMemberJoinEventProcessor.js +60 -0
- package/build/core/event/TeamMemberJoinEventProcessor.js.map +1 -0
- package/build/core/event/processors.index.d.ts +1 -0
- package/build/core/event/processors.index.d.ts.map +1 -1
- package/build/core/event/processors.index.js +1 -0
- package/build/core/event/processors.index.js.map +1 -1
- package/build/db/DatabaseService.d.ts +2 -1
- package/build/db/DatabaseService.d.ts.map +1 -1
- package/build/db/DatabaseService.js +12 -5
- package/build/db/DatabaseService.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/model/EventContentDTO.d.ts +10 -1
- package/build/model/EventContentDTO.d.ts.map +1 -1
- package/build/service/KeyPackageReplenisher.d.ts +15 -0
- package/build/service/KeyPackageReplenisher.d.ts.map +1 -0
- package/build/service/KeyPackageReplenisher.js +82 -0
- package/build/service/KeyPackageReplenisher.js.map +1 -0
- package/build/utils/ApiDateReviver.d.ts +3 -0
- package/build/utils/ApiDateReviver.d.ts.map +1 -0
- package/build/utils/ApiDateReviver.js +26 -0
- package/build/utils/ApiDateReviver.js.map +1 -0
- package/build/utils/DependencyInjectionTokens.d.ts +1 -0
- package/build/utils/DependencyInjectionTokens.d.ts.map +1 -1
- package/build/utils/DependencyInjectionTokens.js +1 -0
- package/build/utils/DependencyInjectionTokens.js.map +1 -1
- package/build/utils/StoragePaths.d.ts +3 -3
- package/build/utils/StoragePaths.d.ts.map +1 -1
- package/build/utils/StoragePaths.js +10 -5
- package/build/utils/StoragePaths.js.map +1 -1
- package/package.json +2 -2
- package/src/WireAppSdk.ts +97 -28
- package/src/WireAppSdkOptions.ts +42 -0
- package/src/api/ConversationService.ts +10 -0
- package/src/api/MlsApiClient.ts +6 -0
- package/src/api/MlsService.ts +4 -0
- package/src/api/UserService.ts +2 -5
- package/src/api/UsersApiClient.ts +0 -6
- package/src/api/response/MlsKeyPackageCountResponse.ts +19 -0
- package/src/core/CoreCryptoClient.ts +13 -10
- package/src/core/CoreCryptoService.ts +17 -3
- package/src/core/HttpClient.ts +2 -1
- package/src/core/WebSocketClient.ts +4 -4
- package/src/core/WireApplicationManager.ts +0 -5
- package/src/core/WireEventsHandler.ts +11 -0
- package/src/core/event/MlsWelcomeEventProcessor.ts +9 -6
- package/src/core/event/TeamMemberJoinEventProcessor.ts +48 -0
- package/src/core/event/processors.index.ts +1 -0
- package/src/db/DatabaseService.ts +5 -4
- package/src/index.ts +1 -0
- package/src/model/EventContentDTO.ts +12 -0
- package/src/service/KeyPackageReplenisher.ts +71 -0
- package/src/utils/ApiDateReviver.ts +27 -0
- package/src/utils/DependencyInjectionTokens.ts +1 -0
- package/src/utils/StoragePaths.ts +12 -5
|
@@ -40,14 +40,14 @@ import {Decoder, Encoder} from 'bazinga64'
|
|
|
40
40
|
import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
|
|
41
41
|
import {obfuscateId} from '../utils/ObfuscateUtil.js'
|
|
42
42
|
import {join} from 'node:path'
|
|
43
|
-
import {CRYPTOGRAPHY_STORAGE_PATH} from '../utils/StoragePaths.js'
|
|
44
43
|
import {CryptographicSystemError} from '../exception/WireException.js'
|
|
45
44
|
import {rmSync} from 'node:fs'
|
|
46
45
|
import {QualifiedId} from '../model/QualifiedId.js'
|
|
47
46
|
import type {DecryptedMlsMessage} from '../model/DecryptedMlsMessage.js'
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
export const MLS_DEFAULT_KEY_PACKAGE_COUNT = 100
|
|
50
49
|
|
|
50
|
+
// TODO: Baris: If we can find a way to make this class only reachable from CoreCryptoService, that will be awesome.
|
|
51
51
|
export class CoreCryptoClient {
|
|
52
52
|
private logger = LoggerFactory.getLogger(this.constructor.name)
|
|
53
53
|
|
|
@@ -63,12 +63,16 @@ export class CoreCryptoClient {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
static async create(
|
|
66
|
+
cryptographyStoragePath: string,
|
|
66
67
|
userId: string,
|
|
67
68
|
ciphersuiteCode: number,
|
|
68
69
|
cryptographyStorageKey: Uint8Array,
|
|
69
70
|
mlsTransport: CoreCryptoMlsTransport
|
|
70
71
|
): Promise<CoreCryptoClient> {
|
|
71
|
-
const db = await Database.open(
|
|
72
|
+
const db = await Database.open(
|
|
73
|
+
this.clientStoragePath(cryptographyStoragePath, userId),
|
|
74
|
+
new DatabaseKey(cryptographyStorageKey)
|
|
75
|
+
)
|
|
72
76
|
const coreCrypto = CoreCrypto.new(db)
|
|
73
77
|
|
|
74
78
|
const coreCryptoClient = new CoreCryptoClient(this.getMlsCiphersuiteName(ciphersuiteCode), mlsTransport, coreCrypto)
|
|
@@ -76,12 +80,12 @@ export class CoreCryptoClient {
|
|
|
76
80
|
return coreCryptoClient
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
static clientStoragePath(userId: string): string {
|
|
80
|
-
return join(
|
|
83
|
+
static clientStoragePath(cryptographyStoragePath: string, userId: string): string {
|
|
84
|
+
return join(cryptographyStoragePath, userId)
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
static deleteClientStorage(userId: string): void {
|
|
84
|
-
const storagePath = this.clientStoragePath(userId)
|
|
87
|
+
static deleteClientStorage(cryptographyStoragePath: string, userId: string): void {
|
|
88
|
+
const storagePath = this.clientStoragePath(cryptographyStoragePath, userId)
|
|
85
89
|
for (const suffix of ['', '-wal', '-shm']) {
|
|
86
90
|
rmSync(`${storagePath}${suffix}`, {recursive: true, force: true})
|
|
87
91
|
}
|
|
@@ -130,7 +134,7 @@ export class CoreCryptoClient {
|
|
|
130
134
|
})
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
async mlsGenerateKeyPackages(count: number =
|
|
137
|
+
async mlsGenerateKeyPackages(count: number = MLS_DEFAULT_KEY_PACKAGE_COUNT): Promise<Uint8Array[]> {
|
|
134
138
|
return await this.coreCrypto.transaction(async (context) => {
|
|
135
139
|
const keyPackages: Uint8Array[] = []
|
|
136
140
|
for (let i = 0; i < count; i++) {
|
|
@@ -238,7 +242,7 @@ export class CoreCryptoClient {
|
|
|
238
242
|
const packageCount = await this.coreCrypto.transaction(async (context) => {
|
|
239
243
|
return (await context.getKeyPackages()).length
|
|
240
244
|
})
|
|
241
|
-
return packageCount <
|
|
245
|
+
return packageCount < MLS_DEFAULT_KEY_PACKAGE_COUNT / 2
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
async wipeConversation(mlsGroupId: ConversationId) {
|
|
@@ -333,5 +337,4 @@ export class CoreCryptoClient {
|
|
|
333
337
|
|
|
334
338
|
private PROTEUS_PREKEYS_FROM_COUNT: number = 0
|
|
335
339
|
private PROTEUS_PREKEYS_MAX_COUNT: number = 10
|
|
336
|
-
private MLS_DEFAULT_KEYPACKAGE_COUNT = 100
|
|
337
340
|
}
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
import {ConversationId, CoreCryptoError, GroupInfo, MlsError} from '@wireapp/core-crypto/native'
|
|
18
18
|
import {ClientsService} from '../api/ClientsService.js'
|
|
19
19
|
import {CryptoClientId} from '../model/CryptoClientId.js'
|
|
20
|
-
import {WIRE_CRYPTOGRAPHY_STORAGE_KEY} from '../utils/DependencyInjectionTokens.js'
|
|
20
|
+
import {WIRE_CRYPTOGRAPHY_STORAGE_KEY, WIRE_STORAGE_PATH} from '../utils/DependencyInjectionTokens.js'
|
|
21
|
+
import {getCryptographyStoragePath} from '../utils/StoragePaths.js'
|
|
21
22
|
import {MlsService} from '../api/MlsService.js'
|
|
22
23
|
import {CoreCryptoClient} from './CoreCryptoClient.js'
|
|
23
24
|
import {CoreCryptoMlsTransport} from './CoreCryptoMlsTransport.js'
|
|
@@ -48,6 +49,7 @@ export class CoreCryptoService {
|
|
|
48
49
|
|
|
49
50
|
constructor(
|
|
50
51
|
@inject(WIRE_CRYPTOGRAPHY_STORAGE_KEY) private cryptographyStorageKey: Uint8Array,
|
|
52
|
+
@inject(WIRE_STORAGE_PATH) private storagePath: string,
|
|
51
53
|
private featureConfigsService: FeatureConfigsService,
|
|
52
54
|
private clientsService: ClientsService,
|
|
53
55
|
private mlsService: MlsService,
|
|
@@ -74,13 +76,14 @@ export class CoreCryptoService {
|
|
|
74
76
|
`No stored deviceId found. Wiping cryptographic storage. userId: ${obfuscateId(appQualifiedId.id)}`
|
|
75
77
|
)
|
|
76
78
|
try {
|
|
77
|
-
CoreCryptoClient.deleteClientStorage(appQualifiedId.id)
|
|
79
|
+
CoreCryptoClient.deleteClientStorage(getCryptographyStoragePath(this.storagePath), appQualifiedId.id)
|
|
78
80
|
} catch (exception) {
|
|
79
81
|
throw new CryptographicSystemError('Error when deleting stale cryptographic storage', exception as Error)
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
this.coreCryptoClient = await CoreCryptoClient.create(
|
|
86
|
+
getCryptographyStoragePath(this.storagePath),
|
|
84
87
|
appQualifiedId.id,
|
|
85
88
|
this.defaultCiphersuiteCode,
|
|
86
89
|
this.cryptographyStorageKey,
|
|
@@ -134,7 +137,11 @@ export class CoreCryptoService {
|
|
|
134
137
|
|
|
135
138
|
await this.coreCryptoClient.initMlsClient(cryptoClientId)
|
|
136
139
|
await this.uploadClientWithMlsPublicKey()
|
|
137
|
-
|
|
140
|
+
try {
|
|
141
|
+
await this.uploadMlsKeyPackages()
|
|
142
|
+
} catch (exception) {
|
|
143
|
+
this.logger.error('Failed to upload initial MLS key packages; scheduled replenishment will retry', exception)
|
|
144
|
+
}
|
|
138
145
|
|
|
139
146
|
this.appProperties.setShouldRejoinConversations(true)
|
|
140
147
|
}
|
|
@@ -176,6 +183,13 @@ export class CoreCryptoService {
|
|
|
176
183
|
return await this.coreCryptoClient!.mlsGenerateKeyPackages()
|
|
177
184
|
}
|
|
178
185
|
|
|
186
|
+
getDefaultCiphersuiteCode(): number {
|
|
187
|
+
if (this.defaultCiphersuiteCode === undefined) {
|
|
188
|
+
throw new CryptographicSystemError('CoreCryptoClient is not initialized.')
|
|
189
|
+
}
|
|
190
|
+
return this.defaultCiphersuiteCode
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
async encryptMlsMessage(mlsGroupId: string, message: Uint8Array): Promise<Uint8Array> {
|
|
180
194
|
const mlsGroupIdBytes = Decoder.fromBase64(mlsGroupId).asBytes
|
|
181
195
|
return await this.coreCryptoClient!.encryptMlsMessage(new ConversationId(mlsGroupIdBytes), message)
|
package/src/core/HttpClient.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import {apiDateReviver} from '../utils/ApiDateReviver.js'
|
|
17
18
|
import {WIRE_API_HOST} from '../utils/DependencyInjectionTokens.js'
|
|
18
19
|
import type {WireApiError} from '../exception/WireApiError.js'
|
|
19
20
|
import {inject, singleton} from 'tsyringe'
|
|
@@ -194,7 +195,7 @@ export class HttpClient {
|
|
|
194
195
|
const contentType = response.headers.get('content-type')
|
|
195
196
|
|
|
196
197
|
if (contentType?.includes('application/json')) {
|
|
197
|
-
const data = (await response.
|
|
198
|
+
const data = JSON.parse(await response.text(), apiDateReviver) as T
|
|
198
199
|
return {data, response}
|
|
199
200
|
}
|
|
200
201
|
|
|
@@ -21,6 +21,7 @@ import {EventRouter} from './event/EventRouter.js'
|
|
|
21
21
|
import {inject, singleton} from 'tsyringe'
|
|
22
22
|
import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
|
|
23
23
|
import type {EventResponse} from '../api/response/EventResponse.js'
|
|
24
|
+
import {apiDateReviver} from '../utils/ApiDateReviver.js'
|
|
24
25
|
import {NotificationsService} from '../service/NotificationsService.js'
|
|
25
26
|
import {AppProperties} from '../service/AppProperties.js'
|
|
26
27
|
import type {BackendConnectionListener} from './BackendConnectionListener.js'
|
|
@@ -230,10 +231,9 @@ export class WebSocketClient {
|
|
|
230
231
|
}
|
|
231
232
|
|
|
232
233
|
private async handleEvent(data: Buffer) {
|
|
233
|
-
const jsonString = data.toString('utf-8')
|
|
234
|
-
const event = JSON.parse(jsonString) as EventResponse
|
|
235
|
-
|
|
236
234
|
try {
|
|
235
|
+
const event = JSON.parse(data.toString('utf-8'), apiDateReviver) as EventResponse
|
|
236
|
+
|
|
237
237
|
if (!event.transient && !this.processedEventIds.has(event.id)) {
|
|
238
238
|
this.processedEventIds.clear()
|
|
239
239
|
await this.eventRouter.route(event)
|
|
@@ -242,7 +242,7 @@ export class WebSocketClient {
|
|
|
242
242
|
// TODO: Send back ACK event (To be done when we have Async notifications again)
|
|
243
243
|
}
|
|
244
244
|
} catch (exception) {
|
|
245
|
-
this.logger.error(
|
|
245
|
+
this.logger.error('Error processing event:', exception)
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -188,11 +188,6 @@ export class WireApplicationManager {
|
|
|
188
188
|
this.logger.debug("Member's role is updated in the conversation with id: " + obfuscateId(conversationId.id))
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
async getUser(userQualifiedId: QualifiedId): Promise<WireUser> {
|
|
192
|
-
this.logger.debug('App requested to get user info: ' + obfuscateId(userQualifiedId.id))
|
|
193
|
-
return await this.userService.getUser(userQualifiedId)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
191
|
async getUsers(userIds: QualifiedId[]): Promise<WireUser[]> {
|
|
197
192
|
this.logger.debug(`App requested to get info for ${userIds.length} users`)
|
|
198
193
|
return await this.userService.getUsers(userIds)
|
|
@@ -32,6 +32,7 @@ import {obfuscateId} from '../utils/ObfuscateUtil.js'
|
|
|
32
32
|
import {container} from 'tsyringe'
|
|
33
33
|
import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
|
|
34
34
|
import type {QualifiedId} from '../model/QualifiedId.js'
|
|
35
|
+
import type {TeamId} from '../model/TeamId.js'
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Abstract class exposed by the SDK to handle events.
|
|
@@ -106,4 +107,14 @@ export abstract class WireEventsHandler {
|
|
|
106
107
|
`Received onUserLeftConversation, ID: ${obfuscateId(conversationId.id)} - length: ${members.length}`
|
|
107
108
|
)
|
|
108
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A user has joined the team.
|
|
113
|
+
*
|
|
114
|
+
* @param userId the user ID of the user who joined
|
|
115
|
+
* @param teamId the ID of the team
|
|
116
|
+
*/
|
|
117
|
+
public async onTeamMemberJoined(userId: QualifiedId, teamId: TeamId): Promise<void> {
|
|
118
|
+
this.logger.info(`Received onTeamMemberJoined, userId: ${userId}, teamId: ${teamId}`)
|
|
119
|
+
}
|
|
109
120
|
}
|
|
@@ -25,17 +25,17 @@ import {WireEventsHandler} from './../WireEventsHandler.js'
|
|
|
25
25
|
import {WIRE_EVENTS_HANDLER, EVENT_PROCESSOR} from '../../utils/DependencyInjectionTokens.js'
|
|
26
26
|
import {ConversationMapper} from '../../mappers/conversation/ConversationMapper.js'
|
|
27
27
|
import {QualifiedId} from '../../model/QualifiedId.js'
|
|
28
|
-
import {
|
|
28
|
+
import {LoggerFactory} from '../../utils/logger/LoggerFactory.js'
|
|
29
29
|
|
|
30
30
|
@injectable({token: EVENT_PROCESSOR})
|
|
31
31
|
export class MlsWelcomeEventProcessor implements EventProcessor<MLSWelcomeDTO> {
|
|
32
32
|
readonly eventType = 'conversation.mls-welcome' as const
|
|
33
|
+
private logger = LoggerFactory.getLogger(this.constructor.name)
|
|
33
34
|
|
|
34
35
|
constructor(
|
|
35
36
|
private coreCryptoService: CoreCryptoService,
|
|
36
37
|
private conversationService: ConversationService,
|
|
37
38
|
private mlsService: MlsService,
|
|
38
|
-
private appProperties: AppProperties,
|
|
39
39
|
@inject(WIRE_EVENTS_HANDLER) private wireEventsHandler: WireEventsHandler
|
|
40
40
|
) {}
|
|
41
41
|
|
|
@@ -52,10 +52,13 @@ export class MlsWelcomeEventProcessor implements EventProcessor<MLSWelcomeDTO> {
|
|
|
52
52
|
conversationResponse
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
try {
|
|
56
|
+
if (await this.coreCryptoService.hasTooFewKeyPackageCount()) {
|
|
57
|
+
const keyPackages = await this.coreCryptoService.mlsGenerateKeyPackages()
|
|
58
|
+
await this.mlsService.uploadMlsKeyPackages(keyPackages)
|
|
59
|
+
}
|
|
60
|
+
} catch (exception) {
|
|
61
|
+
this.logger.error('Failed to replenish MLS key packages after joining conversation', exception)
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
await this.wireEventsHandler.onAppAddedToConversation(ConversationMapper.fromEntity(conversation), members)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {inject, injectable} from 'tsyringe'
|
|
18
|
+
import type {EventProcessor} from './EventProcessor.js'
|
|
19
|
+
import type {TeamMemberJoinDTO} from '../../model/EventContentDTO.js'
|
|
20
|
+
import {WireEventsHandler} from '../WireEventsHandler.js'
|
|
21
|
+
import {EVENT_PROCESSOR, WIRE_EVENTS_HANDLER} from '../../utils/DependencyInjectionTokens.js'
|
|
22
|
+
import {LoggerFactory} from '../../utils/logger/LoggerFactory.js'
|
|
23
|
+
import {QualifiedId} from '../../model/QualifiedId.js'
|
|
24
|
+
import {TeamId} from '../../model/TeamId.js'
|
|
25
|
+
import {AppProperties} from '../../service/AppProperties.js'
|
|
26
|
+
|
|
27
|
+
@injectable({token: EVENT_PROCESSOR})
|
|
28
|
+
export class TeamMemberJoinEventProcessor implements EventProcessor<TeamMemberJoinDTO> {
|
|
29
|
+
private logger = LoggerFactory.getLogger(this.constructor.name)
|
|
30
|
+
|
|
31
|
+
readonly eventType = 'team.member-join' as const
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
private appProperties: AppProperties,
|
|
35
|
+
@inject(WIRE_EVENTS_HANDLER) private wireEventsHandler: WireEventsHandler
|
|
36
|
+
) {}
|
|
37
|
+
|
|
38
|
+
async process(event: TeamMemberJoinDTO): Promise<void> {
|
|
39
|
+
// The event only carries a non-qualified user id, team members share the application's domain
|
|
40
|
+
const userId = new QualifiedId(event.data.user, this.appProperties.getApplicationQualifiedId().domain)
|
|
41
|
+
const teamId = new TeamId(event.team)
|
|
42
|
+
this.logger.info(`Processing TeamMemberJoin event for teamId: ${teamId}, userId: ${userId}`)
|
|
43
|
+
|
|
44
|
+
await this.wireEventsHandler.onTeamMemberJoined(userId, teamId)
|
|
45
|
+
|
|
46
|
+
this.logger.info(`Processed TeamMemberJoin event for teamId: ${teamId}`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import Database, {type Database as DB} from 'better-sqlite3'
|
|
18
|
-
import {singleton} from 'tsyringe'
|
|
18
|
+
import {inject, singleton} from 'tsyringe'
|
|
19
19
|
import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
|
|
20
20
|
import {BetterSQLite3Database, drizzle} from 'drizzle-orm/better-sqlite3'
|
|
21
21
|
import {migrate} from 'drizzle-orm/better-sqlite3/migrator'
|
|
22
|
-
import {
|
|
22
|
+
import {getDatabasePath} from '../utils/StoragePaths.js'
|
|
23
|
+
import {WIRE_STORAGE_PATH} from '../utils/DependencyInjectionTokens.js'
|
|
23
24
|
import {dirname, join} from 'node:path'
|
|
24
25
|
import {fileURLToPath} from 'node:url'
|
|
25
26
|
import {DatabaseError} from '../exception/WireException.js'
|
|
@@ -30,7 +31,7 @@ export class DatabaseService {
|
|
|
30
31
|
private readonly sqliteClient: DB
|
|
31
32
|
public readonly db: BetterSQLite3Database
|
|
32
33
|
|
|
33
|
-
constructor() {
|
|
34
|
+
constructor(@inject(WIRE_STORAGE_PATH) private readonly storagePath: string) {
|
|
34
35
|
this.logger.info('DatabaseService being created')
|
|
35
36
|
this.sqliteClient = new Database(this.getDatabasePath())
|
|
36
37
|
this.sqliteClient.pragma('foreign_keys = ON')
|
|
@@ -40,7 +41,7 @@ export class DatabaseService {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
protected getDatabasePath(): string {
|
|
43
|
-
return
|
|
44
|
+
return getDatabasePath(this.storagePath)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
protected getMigrationsFolder(): string {
|
package/src/index.ts
CHANGED
|
@@ -122,6 +122,17 @@ interface MessageTimerUpdateEventData {
|
|
|
122
122
|
message_timer: number | null
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
export interface TeamMemberJoinDTO {
|
|
126
|
+
type: string
|
|
127
|
+
team: string
|
|
128
|
+
time: Date
|
|
129
|
+
data: TeamMemberIdData
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface TeamMemberIdData {
|
|
133
|
+
user: string
|
|
134
|
+
}
|
|
135
|
+
|
|
125
136
|
export type EventContentDTO =
|
|
126
137
|
| MLSWelcomeDTO
|
|
127
138
|
| NewMLSMessageDTO
|
|
@@ -133,3 +144,4 @@ export type EventContentDTO =
|
|
|
133
144
|
| MemberUpdateDTO
|
|
134
145
|
| MlsResetDTO
|
|
135
146
|
| MessageTimerUpdateDTO
|
|
147
|
+
| TeamMemberJoinDTO
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {singleton} from 'tsyringe'
|
|
18
|
+
import {MlsService} from '../api/MlsService.js'
|
|
19
|
+
import {MLS_DEFAULT_KEY_PACKAGE_COUNT} from '../core/CoreCryptoClient.js'
|
|
20
|
+
import {CoreCryptoService} from '../core/CoreCryptoService.js'
|
|
21
|
+
import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
|
|
22
|
+
|
|
23
|
+
@singleton()
|
|
24
|
+
export class KeyPackageReplenisher {
|
|
25
|
+
private static readonly CHECK_INTERVAL_MS = 24 * 60 * 60 * 1_000
|
|
26
|
+
private logger = LoggerFactory.getLogger(this.constructor.name)
|
|
27
|
+
private activeRun: object | undefined
|
|
28
|
+
private timer: ReturnType<typeof setTimeout> | undefined
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
private mlsService: MlsService,
|
|
32
|
+
private coreCryptoService: CoreCryptoService
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
start(): void {
|
|
36
|
+
if (this.activeRun) return
|
|
37
|
+
|
|
38
|
+
const run = {}
|
|
39
|
+
this.activeRun = run
|
|
40
|
+
void this.checkAndSchedule(run)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
stop(): void {
|
|
44
|
+
this.activeRun = undefined
|
|
45
|
+
if (this.timer) clearTimeout(this.timer)
|
|
46
|
+
this.timer = undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async checkAndSchedule(run: object): Promise<void> {
|
|
50
|
+
try {
|
|
51
|
+
const count = await this.mlsService.getAvailableKeyPackageCount(
|
|
52
|
+
this.coreCryptoService.getDefaultCiphersuiteCode()
|
|
53
|
+
)
|
|
54
|
+
if (count < MLS_DEFAULT_KEY_PACKAGE_COUNT / 2) {
|
|
55
|
+
this.logger.info(
|
|
56
|
+
`Found ${count} available MLS key packages, replenishing with ${MLS_DEFAULT_KEY_PACKAGE_COUNT} new packages`
|
|
57
|
+
)
|
|
58
|
+
const keyPackages = await this.coreCryptoService.mlsGenerateKeyPackages()
|
|
59
|
+
await this.mlsService.uploadMlsKeyPackages(keyPackages)
|
|
60
|
+
} else {
|
|
61
|
+
this.logger.info(`Found ${count} available MLS key packages, replenishment is not needed`)
|
|
62
|
+
}
|
|
63
|
+
} catch (exception) {
|
|
64
|
+
this.logger.error('Failed to check or replenish MLS key packages', exception)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (run === this.activeRun) {
|
|
68
|
+
this.timer = setTimeout(() => void this.checkAndSchedule(run), KeyPackageReplenisher.CHECK_INTERVAL_MS)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Converts API `time` fields during JSON.parse, preserving unparseable strings. */
|
|
18
|
+
export function apiDateReviver(key: string, value: unknown): unknown {
|
|
19
|
+
if (key !== 'time') return value
|
|
20
|
+
|
|
21
|
+
if (typeof value !== 'string') {
|
|
22
|
+
throw new TypeError('API timestamp must be a string')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const time = new Date(value)
|
|
26
|
+
return Number.isNaN(time.getTime()) ? value : time
|
|
27
|
+
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
export const WIRE_API_HOST = 'WIRE_API_HOST'
|
|
18
18
|
export const WIRE_SDK_API_TOKEN = 'WIRE_SDK_API_TOKEN'
|
|
19
19
|
export const WIRE_CRYPTOGRAPHY_STORAGE_KEY = 'WIRE_CRYPTOGRAPHY_STORAGE_KEY'
|
|
20
|
+
export const WIRE_STORAGE_PATH = 'WIRE_STORAGE_PATH'
|
|
20
21
|
|
|
21
22
|
export const WIRE_EVENTS_HANDLER = 'WIRE_EVENTS_HANDLER'
|
|
22
23
|
|
|
@@ -16,8 +16,15 @@
|
|
|
16
16
|
|
|
17
17
|
import {join} from 'node:path'
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
// the SDK-managed storage folder in the directory where
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
|
|
19
|
+
// Relative paths are resolved against process.cwd() when the SDK is created, so
|
|
20
|
+
// by default host apps get the SDK-managed storage folder in the directory where
|
|
21
|
+
// the process starts. Host apps can override it with `WireAppSdkOptions.storagePath`.
|
|
22
|
+
export const DEFAULT_STORAGE_PATH = './storage'
|
|
23
|
+
|
|
24
|
+
export function getDatabasePath(storagePath: string): string {
|
|
25
|
+
return join(storagePath, 'apps.db')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getCryptographyStoragePath(storagePath: string): string {
|
|
29
|
+
return join(storagePath, 'cryptography')
|
|
30
|
+
}
|