1
- const { DeviceLists, RequestType, KeysUploadRequest, KeysQueryRequest } = require ( "@matrix-org/matrix-sdk-crypto-wasm" ) ;
2
-
3
- function * zip ( ...arrays ) {
1
+ /*
2
+ Copyright 2022-2025 The Matrix.org Foundation C.I.C.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import {
18
+ DeviceLists ,
19
+ RequestType ,
20
+ KeysUploadRequest ,
21
+ KeysQueryRequest ,
22
+ OlmMachine ,
23
+ } from "@matrix-org/matrix-sdk-crypto-wasm" ;
24
+
25
+ export function * zip ( ...arrays : Array < Array < any > > ) : Generator < any > {
4
26
const len = Math . min ( ...arrays . map ( ( array ) => array . length ) ) ;
5
27
6
28
for ( let nth = 0 ; nth < len ; ++ nth ) {
@@ -10,7 +32,7 @@ function* zip(...arrays) {
10
32
11
33
// Add a machine to another machine, i.e. be sure a machine knows
12
34
// another exists.
13
- async function addMachineToMachine ( machineToAdd , machine ) {
35
+ export async function addMachineToMachine ( machineToAdd : OlmMachine , machine : OlmMachine ) : Promise < void > {
14
36
const toDeviceEvents = JSON . stringify ( [ ] ) ;
15
37
const changedDevices = new DeviceLists ( ) ;
16
38
const oneTimeKeyCounts = new Map ( ) ;
@@ -29,9 +51,12 @@ async function addMachineToMachine(machineToAdd, machine) {
29
51
expect ( outgoingRequests ) . toHaveLength ( 2 ) ;
30
52
31
53
let keysUploadRequest ;
54
+
32
55
// Read the `KeysUploadRequest`.
33
56
{
34
57
expect ( outgoingRequests [ 0 ] ) . toBeInstanceOf ( KeysUploadRequest ) ;
58
+ keysUploadRequest = outgoingRequests [ 0 ] as KeysUploadRequest ;
59
+
35
60
expect ( outgoingRequests [ 0 ] . id ) . toBeDefined ( ) ;
36
61
expect ( outgoingRequests [ 0 ] . type ) . toStrictEqual ( RequestType . KeysUpload ) ;
37
62
expect ( outgoingRequests [ 0 ] . body ) . toBeDefined ( ) ;
@@ -48,27 +73,26 @@ async function addMachineToMachine(machineToAdd, machine) {
48
73
} ,
49
74
} ) ;
50
75
const marked = await machineToAdd . markRequestAsSent (
51
- outgoingRequests [ 0 ] . id ,
76
+ keysUploadRequest . id ,
52
77
outgoingRequests [ 0 ] . type ,
53
78
hypotheticalResponse ,
54
79
) ;
55
80
expect ( marked ) . toStrictEqual ( true ) ;
56
-
57
- keysUploadRequest = outgoingRequests [ 0 ] ;
58
81
}
59
82
60
83
{
61
84
expect ( outgoingRequests [ 1 ] ) . toBeInstanceOf ( KeysQueryRequest ) ;
85
+ let keysQueryRequest = outgoingRequests [ 1 ] as KeysQueryRequest ;
62
86
63
87
let bootstrapCrossSigningResult = await machineToAdd . bootstrapCrossSigning ( true ) ;
64
88
let signingKeysUploadRequest = bootstrapCrossSigningResult . uploadSigningKeysRequest ;
65
89
66
90
// Let's forge a `KeysQuery`'s response.
67
91
let keyQueryResponse = {
68
- device_keys : { } ,
69
- master_keys : { } ,
70
- self_signing_keys : { } ,
71
- user_signing_keys : { } ,
92
+ device_keys : { } as Record < string , any > ,
93
+ master_keys : { } as Record < string , any > ,
94
+ self_signing_keys : { } as Record < string , any > ,
95
+ user_signing_keys : { } as Record < string , any > ,
72
96
} ;
73
97
const userId = machineToAdd . userId . toString ( ) ;
74
98
const deviceId = machineToAdd . deviceId . toString ( ) ;
@@ -81,15 +105,10 @@ async function addMachineToMachine(machineToAdd, machine) {
81
105
keyQueryResponse . user_signing_keys [ userId ] = keys . user_signing_key ;
82
106
83
107
const marked = await machine . markRequestAsSent (
84
- outgoingRequests [ 1 ] . id ,
85
- outgoingRequests [ 1 ] . type ,
108
+ keysQueryRequest . id ,
109
+ keysQueryRequest . type ,
86
110
JSON . stringify ( keyQueryResponse ) ,
87
111
) ;
88
112
expect ( marked ) . toStrictEqual ( true ) ;
89
113
}
90
114
}
91
-
92
- module . exports = {
93
- zip,
94
- addMachineToMachine,
95
- } ;
0 commit comments