Skip to content

Commit 46c1816

Browse files
committed
feat(crypto-js): Rename requests extra field to body.
1 parent fa56d98 commit 46c1816

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

src/requests.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ pub struct KeysUploadRequest {
3939
/// A JSON-encoded string containing the rest of the payload: `device_keys`,
4040
/// `one_time_keys`, `fallback_keys`.
4141
#[wasm_bindgen(readonly)]
42-
pub extra: JsString,
42+
pub body: JsString,
4343
}
4444

4545
#[wasm_bindgen]
4646
impl KeysUploadRequest {
4747
/// Create a new `KeysUploadRequest`.
4848
#[wasm_bindgen(constructor)]
49-
pub fn new(id: JsString, extra: JsString) -> KeysUploadRequest {
50-
Self { id: Some(id), extra }
49+
pub fn new(id: JsString, body: JsString) -> KeysUploadRequest {
50+
Self { id: Some(id), body }
5151
}
5252

5353
/// Get its request type.
@@ -73,15 +73,15 @@ pub struct KeysQueryRequest {
7373
/// A JSON-encoded string containing the rest of the payload: `timeout`,
7474
/// `device_keys`, `token`.
7575
#[wasm_bindgen(readonly)]
76-
pub extra: JsString,
76+
pub body: JsString,
7777
}
7878

7979
#[wasm_bindgen]
8080
impl KeysQueryRequest {
8181
/// Create a new `KeysQueryRequest`.
8282
#[wasm_bindgen(constructor)]
83-
pub fn new(id: JsString, extra: JsString) -> KeysQueryRequest {
84-
Self { id: Some(id), extra }
83+
pub fn new(id: JsString, body: JsString) -> KeysQueryRequest {
84+
Self { id: Some(id), body }
8585
}
8686

8787
/// Get its request type.
@@ -108,15 +108,15 @@ pub struct KeysClaimRequest {
108108
/// A JSON-encoded string containing the rest of the payload: `timeout`,
109109
/// `one_time_keys`.
110110
#[wasm_bindgen(readonly)]
111-
pub extra: JsString,
111+
pub body: JsString,
112112
}
113113

114114
#[wasm_bindgen]
115115
impl KeysClaimRequest {
116116
/// Create a new `KeysClaimRequest`.
117117
#[wasm_bindgen(constructor)]
118-
pub fn new(id: JsString, extra: JsString) -> KeysClaimRequest {
119-
Self { id: Some(id), extra }
118+
pub fn new(id: JsString, body: JsString) -> KeysClaimRequest {
119+
Self { id: Some(id), body }
120120
}
121121

122122
/// Get its request type.
@@ -150,7 +150,7 @@ pub struct ToDeviceRequest {
150150

151151
/// A JSON-encoded string containing the rest of the payload: `messages`.
152152
#[wasm_bindgen(readonly)]
153-
pub extra: JsString,
153+
pub body: JsString,
154154
}
155155

156156
#[wasm_bindgen]
@@ -161,9 +161,9 @@ impl ToDeviceRequest {
161161
id: JsString,
162162
event_type: JsString,
163163
txn_id: JsString,
164-
extra: JsString,
164+
body: JsString,
165165
) -> ToDeviceRequest {
166-
Self { id: Some(id), event_type, txn_id, extra }
166+
Self { id: Some(id), event_type, txn_id, body }
167167
}
168168

169169
/// Get its request type.
@@ -188,15 +188,15 @@ pub struct SignatureUploadRequest {
188188

189189
/// A JSON-encoded string containing the rest of the payload: `signed_keys`.
190190
#[wasm_bindgen(readonly)]
191-
pub extra: JsString,
191+
pub body: JsString,
192192
}
193193

194194
#[wasm_bindgen]
195195
impl SignatureUploadRequest {
196196
/// Create a new `SignatureUploadRequest`.
197197
#[wasm_bindgen(constructor)]
198-
pub fn new(id: JsString, extra: JsString) -> SignatureUploadRequest {
199-
Self { id: Some(id), extra }
198+
pub fn new(id: JsString, body: JsString) -> SignatureUploadRequest {
199+
Self { id: Some(id), body }
200200
}
201201

202202
/// Get its request type.
@@ -272,15 +272,15 @@ pub struct KeysBackupRequest {
272272

273273
/// A JSON-encoded string containing the rest of the payload: `rooms`.
274274
#[wasm_bindgen(readonly)]
275-
pub extra: JsString,
275+
pub body: JsString,
276276
}
277277

278278
#[wasm_bindgen]
279279
impl KeysBackupRequest {
280280
/// Create a new `KeysBackupRequest`.
281281
#[wasm_bindgen(constructor)]
282-
pub fn new(id: JsString, extra: JsString) -> KeysBackupRequest {
283-
Self { id: Some(id), extra }
282+
pub fn new(id: JsString, body: JsString) -> KeysBackupRequest {
283+
Self { id: Some(id), body }
284284
}
285285

286286
/// Get its request type.
@@ -305,7 +305,7 @@ pub struct SigningKeysUploadRequest {
305305
/// A JSON-encoded string containing the rest of the payload: `master_key`,
306306
/// `self_signing_key`, `user_signing_key`.
307307
#[wasm_bindgen(readonly)]
308-
pub extra: JsString,
308+
pub body: JsString,
309309
}
310310

311311
macro_rules! request {
@@ -358,7 +358,7 @@ macro_rules! request {
358358
)*
359359
)?
360360
$(
361-
extra: {
361+
body: {
362362
let mut map = serde_json::Map::new();
363363
$(
364364
map.insert(stringify!($grouped_field_name).to_owned(), serde_json::to_value(&$request.$grouped_field_name).unwrap());

tests/device.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Key Verification', () => {
177177
const toDeviceEvents = [{
178178
sender: userId1.toString(),
179179
type: outgoingVerificationRequest.event_type,
180-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()],
180+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()],
181181
}];
182182

183183
// Let's send the verification request to `m2`.
@@ -228,7 +228,7 @@ describe('Key Verification', () => {
228228
const toDeviceEvents = [{
229229
sender: userId2.toString(),
230230
type: outgoingVerificationRequest.event_type,
231-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()],
231+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()],
232232
}];
233233

234234
// Let's send the verification ready to `m1`.
@@ -281,7 +281,7 @@ describe('Key Verification', () => {
281281
const toDeviceEvents = [{
282282
sender: userId2.toString(),
283283
type: outgoingVerificationRequest.event_type,
284-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()],
284+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()],
285285
}];
286286

287287
// Let's send the SAS start to `m1`.
@@ -326,7 +326,7 @@ describe('Key Verification', () => {
326326
const toDeviceEvents = [{
327327
sender: userId1.toString(),
328328
type: outgoingVerificationRequest.event_type,
329-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()],
329+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()],
330330
}];
331331

332332
// Let's send the SAS accept to `m2`.
@@ -349,7 +349,7 @@ describe('Key Verification', () => {
349349
const toDeviceEvents = [{
350350
sender: userId2.toString(),
351351
type: toDeviceRequest.event_type,
352-
content: JSON.parse(toDeviceRequest.extra).messages[userId1.toString()][deviceId1.toString()],
352+
content: JSON.parse(toDeviceRequest.body).messages[userId1.toString()][deviceId1.toString()],
353353
}];
354354

355355
// Let's send te SAS key to `m1`.
@@ -369,7 +369,7 @@ describe('Key Verification', () => {
369369
const toDeviceEvents = [{
370370
sender: userId1.toString(),
371371
type: toDeviceRequest.event_type,
372-
content: JSON.parse(toDeviceRequest.extra).messages[userId2.toString()][deviceId2.toString()],
372+
content: JSON.parse(toDeviceRequest.body).messages[userId2.toString()][deviceId2.toString()],
373373
}];
374374

375375
// Let's send te SAS key to `m2`.
@@ -438,7 +438,7 @@ describe('Key Verification', () => {
438438
const toDeviceEvents = [{
439439
sender: userId1.toString(),
440440
type: outgoingVerificationRequest.event_type,
441-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()],
441+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()],
442442
}];
443443

444444
// Let's send te SAS confirmation to `m2`.
@@ -462,7 +462,7 @@ describe('Key Verification', () => {
462462
const toDeviceEvents = [{
463463
sender: userId2.toString(),
464464
type: outgoingVerificationRequest.event_type,
465-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()],
465+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()],
466466
}];
467467

468468
// Let's send te SAS confirmation to `m1`.
@@ -479,7 +479,7 @@ describe('Key Verification', () => {
479479
const toDeviceEvents = [{
480480
sender: userId2.toString(),
481481
type: outgoingVerificationRequest.event_type,
482-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()],
482+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()],
483483
}];
484484

485485
// Let's send te SAS done to `m1`.
@@ -499,7 +499,7 @@ describe('Key Verification', () => {
499499
const toDeviceEvents = [{
500500
sender: userId1.toString(),
501501
type: toDeviceRequest.event_type,
502-
content: JSON.parse(toDeviceRequest.extra).messages[userId2.toString()][deviceId2.toString()],
502+
content: JSON.parse(toDeviceRequest.body).messages[userId2.toString()][deviceId2.toString()],
503503
}];
504504

505505
// Let's send te SAS key to `m2`.
@@ -585,7 +585,7 @@ describe('Key Verification', () => {
585585
const toDeviceEvents = [{
586586
sender: userId1.toString(),
587587
type: outgoingVerificationRequest.event_type,
588-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()],
588+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()],
589589
}];
590590

591591
// Let's send the verification request to `m2`.
@@ -639,7 +639,7 @@ describe('Key Verification', () => {
639639
const toDeviceEvents = [{
640640
sender: userId2.toString(),
641641
type: outgoingVerificationRequest.event_type,
642-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()],
642+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()],
643643
}];
644644

645645
// Let's send the verification ready to `m1`.
@@ -796,7 +796,7 @@ describe('Key Verification', () => {
796796
const toDeviceEvents = [{
797797
sender: userId1.toString(),
798798
type: outgoingVerificationRequest.event_type,
799-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()],
799+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()],
800800
}];
801801

802802
// Let's send the verification request to `m2`.
@@ -816,7 +816,7 @@ describe('Key Verification', () => {
816816
const toDeviceEvents = [{
817817
sender: userId2.toString(),
818818
type: outgoingVerificationRequest.event_type,
819-
content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()],
819+
content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()],
820820
}];
821821

822822
// Let's send the verification request to `m2`.

tests/helper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ async function addMachineToMachine(machineToAdd, machine) {
3030
expect(outgoingRequests[0]).toBeInstanceOf(KeysUploadRequest);
3131
expect(outgoingRequests[0].id).toBeDefined();
3232
expect(outgoingRequests[0].type).toStrictEqual(RequestType.KeysUpload);
33-
expect(outgoingRequests[0].extra).toBeDefined();
33+
expect(outgoingRequests[0].body).toBeDefined();
3434

35-
const body = JSON.parse(outgoingRequests[0].extra);
35+
const body = JSON.parse(outgoingRequests[0].body);
3636
expect(body.device_keys).toBeDefined();
3737
expect(body.one_time_keys).toBeDefined();
3838

@@ -64,9 +64,9 @@ async function addMachineToMachine(machineToAdd, machine) {
6464
const userId = machineToAdd.userId.toString();
6565
const deviceId = machineToAdd.deviceId.toString();
6666
keyQueryResponse.device_keys[userId] = {};
67-
keyQueryResponse.device_keys[userId][deviceId] = JSON.parse(keysUploadRequest.extra).device_keys;
67+
keyQueryResponse.device_keys[userId][deviceId] = JSON.parse(keysUploadRequest.body).device_keys;
6868

69-
const keys = JSON.parse(signingKeysUploadRequest.extra);
69+
const keys = JSON.parse(signingKeysUploadRequest.body);
7070
keyQueryResponse.master_keys[userId] = keys.master_key;
7171
keyQueryResponse.self_signing_keys[userId] = keys.self_signing_key;
7272
keyQueryResponse.user_signing_keys[userId] = keys.user_signing_key;

tests/machine.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ describe(OlmMachine.name, () => {
198198
expect(outgoingRequests[0]).toBeInstanceOf(KeysUploadRequest);
199199
expect(outgoingRequests[0].id).toBeDefined();
200200
expect(outgoingRequests[0].type).toStrictEqual(RequestType.KeysUpload);
201-
expect(outgoingRequests[0].extra).toBeDefined();
201+
expect(outgoingRequests[0].body).toBeDefined();
202202

203-
const body = JSON.parse(outgoingRequests[0].extra)
203+
const body = JSON.parse(outgoingRequests[0].body)
204204
expect(body.device_keys).toBeDefined();
205205
expect(body.one_time_keys).toBeDefined();
206206
}
@@ -209,9 +209,9 @@ describe(OlmMachine.name, () => {
209209
expect(outgoingRequests[1]).toBeInstanceOf(KeysQueryRequest);
210210
expect(outgoingRequests[1].id).toBeDefined();
211211
expect(outgoingRequests[1].type).toStrictEqual(RequestType.KeysQuery);
212-
expect(outgoingRequests[1].extra).toBeDefined();
212+
expect(outgoingRequests[1].body).toBeDefined();
213213

214-
const body = JSON.parse(outgoingRequests[1].extra);
214+
const body = JSON.parse(outgoingRequests[1].body);
215215
expect(body.timeout).toBeDefined();
216216
expect(body.device_keys).toBeDefined();
217217
expect(body.token).toBeDefined();

0 commit comments

Comments
 (0)