From c427caf473f193aaebf4eef073428d553013d444 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 5 Jan 2023 17:03:13 +0100 Subject: [PATCH] feat(crypto-js): Rename requests `extra` field to `body`. --- bindings/matrix-sdk-crypto-js/src/requests.rs | 40 +++++++++---------- .../matrix-sdk-crypto-js/tests/device.test.js | 28 ++++++------- bindings/matrix-sdk-crypto-js/tests/helper.js | 8 ++-- .../tests/machine.test.js | 8 ++-- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/bindings/matrix-sdk-crypto-js/src/requests.rs b/bindings/matrix-sdk-crypto-js/src/requests.rs index 1c4de8f84..f0e46a68e 100644 --- a/bindings/matrix-sdk-crypto-js/src/requests.rs +++ b/bindings/matrix-sdk-crypto-js/src/requests.rs @@ -39,15 +39,15 @@ pub struct KeysUploadRequest { /// A JSON-encoded string containing the rest of the payload: `device_keys`, /// `one_time_keys`, `fallback_keys`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } #[wasm_bindgen] impl KeysUploadRequest { /// Create a new `KeysUploadRequest`. #[wasm_bindgen(constructor)] - pub fn new(id: JsString, extra: JsString) -> KeysUploadRequest { - Self { id: Some(id), extra } + pub fn new(id: JsString, body: JsString) -> KeysUploadRequest { + Self { id: Some(id), body } } /// Get its request type. @@ -73,15 +73,15 @@ pub struct KeysQueryRequest { /// A JSON-encoded string containing the rest of the payload: `timeout`, /// `device_keys`, `token`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } #[wasm_bindgen] impl KeysQueryRequest { /// Create a new `KeysQueryRequest`. #[wasm_bindgen(constructor)] - pub fn new(id: JsString, extra: JsString) -> KeysQueryRequest { - Self { id: Some(id), extra } + pub fn new(id: JsString, body: JsString) -> KeysQueryRequest { + Self { id: Some(id), body } } /// Get its request type. @@ -108,15 +108,15 @@ pub struct KeysClaimRequest { /// A JSON-encoded string containing the rest of the payload: `timeout`, /// `one_time_keys`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } #[wasm_bindgen] impl KeysClaimRequest { /// Create a new `KeysClaimRequest`. #[wasm_bindgen(constructor)] - pub fn new(id: JsString, extra: JsString) -> KeysClaimRequest { - Self { id: Some(id), extra } + pub fn new(id: JsString, body: JsString) -> KeysClaimRequest { + Self { id: Some(id), body } } /// Get its request type. @@ -150,7 +150,7 @@ pub struct ToDeviceRequest { /// A JSON-encoded string containing the rest of the payload: `messages`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } #[wasm_bindgen] @@ -161,9 +161,9 @@ impl ToDeviceRequest { id: JsString, event_type: JsString, txn_id: JsString, - extra: JsString, + body: JsString, ) -> ToDeviceRequest { - Self { id: Some(id), event_type, txn_id, extra } + Self { id: Some(id), event_type, txn_id, body } } /// Get its request type. @@ -188,15 +188,15 @@ pub struct SignatureUploadRequest { /// A JSON-encoded string containing the rest of the payload: `signed_keys`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } #[wasm_bindgen] impl SignatureUploadRequest { /// Create a new `SignatureUploadRequest`. #[wasm_bindgen(constructor)] - pub fn new(id: JsString, extra: JsString) -> SignatureUploadRequest { - Self { id: Some(id), extra } + pub fn new(id: JsString, body: JsString) -> SignatureUploadRequest { + Self { id: Some(id), body } } /// Get its request type. @@ -272,15 +272,15 @@ pub struct KeysBackupRequest { /// A JSON-encoded string containing the rest of the payload: `rooms`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } #[wasm_bindgen] impl KeysBackupRequest { /// Create a new `KeysBackupRequest`. #[wasm_bindgen(constructor)] - pub fn new(id: JsString, extra: JsString) -> KeysBackupRequest { - Self { id: Some(id), extra } + pub fn new(id: JsString, body: JsString) -> KeysBackupRequest { + Self { id: Some(id), body } } /// Get its request type. @@ -305,7 +305,7 @@ pub struct SigningKeysUploadRequest { /// A JSON-encoded string containing the rest of the payload: `master_key`, /// `self_signing_key`, `user_signing_key`. #[wasm_bindgen(readonly)] - pub extra: JsString, + pub body: JsString, } macro_rules! request { @@ -358,7 +358,7 @@ macro_rules! request { )* )? $( - extra: { + body: { let mut map = serde_json::Map::new(); $( map.insert(stringify!($grouped_field_name).to_owned(), serde_json::to_value(&$request.$grouped_field_name).unwrap()); diff --git a/bindings/matrix-sdk-crypto-js/tests/device.test.js b/bindings/matrix-sdk-crypto-js/tests/device.test.js index 73c3a78cd..14ecc2051 100644 --- a/bindings/matrix-sdk-crypto-js/tests/device.test.js +++ b/bindings/matrix-sdk-crypto-js/tests/device.test.js @@ -177,7 +177,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send the verification request to `m2`. @@ -228,7 +228,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send the verification ready to `m1`. @@ -281,7 +281,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send the SAS start to `m1`. @@ -326,7 +326,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send the SAS accept to `m2`. @@ -349,7 +349,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: toDeviceRequest.event_type, - content: JSON.parse(toDeviceRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(toDeviceRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send te SAS key to `m1`. @@ -369,7 +369,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: toDeviceRequest.event_type, - content: JSON.parse(toDeviceRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(toDeviceRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send te SAS key to `m2`. @@ -438,7 +438,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send te SAS confirmation to `m2`. @@ -462,7 +462,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send te SAS confirmation to `m1`. @@ -479,7 +479,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send te SAS done to `m1`. @@ -499,7 +499,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: toDeviceRequest.event_type, - content: JSON.parse(toDeviceRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(toDeviceRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send te SAS key to `m2`. @@ -585,7 +585,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send the verification request to `m2`. @@ -639,7 +639,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send the verification ready to `m1`. @@ -796,7 +796,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId1.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId2.toString()][deviceId2.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId2.toString()][deviceId2.toString()], }]; // Let's send the verification request to `m2`. @@ -816,7 +816,7 @@ describe('Key Verification', () => { const toDeviceEvents = [{ sender: userId2.toString(), type: outgoingVerificationRequest.event_type, - content: JSON.parse(outgoingVerificationRequest.extra).messages[userId1.toString()][deviceId1.toString()], + content: JSON.parse(outgoingVerificationRequest.body).messages[userId1.toString()][deviceId1.toString()], }]; // Let's send the verification request to `m2`. diff --git a/bindings/matrix-sdk-crypto-js/tests/helper.js b/bindings/matrix-sdk-crypto-js/tests/helper.js index 9be52c9e1..0d3136bed 100644 --- a/bindings/matrix-sdk-crypto-js/tests/helper.js +++ b/bindings/matrix-sdk-crypto-js/tests/helper.js @@ -30,9 +30,9 @@ async function addMachineToMachine(machineToAdd, machine) { expect(outgoingRequests[0]).toBeInstanceOf(KeysUploadRequest); expect(outgoingRequests[0].id).toBeDefined(); expect(outgoingRequests[0].type).toStrictEqual(RequestType.KeysUpload); - expect(outgoingRequests[0].extra).toBeDefined(); + expect(outgoingRequests[0].body).toBeDefined(); - const body = JSON.parse(outgoingRequests[0].extra); + const body = JSON.parse(outgoingRequests[0].body); expect(body.device_keys).toBeDefined(); expect(body.one_time_keys).toBeDefined(); @@ -64,9 +64,9 @@ async function addMachineToMachine(machineToAdd, machine) { const userId = machineToAdd.userId.toString(); const deviceId = machineToAdd.deviceId.toString(); keyQueryResponse.device_keys[userId] = {}; - keyQueryResponse.device_keys[userId][deviceId] = JSON.parse(keysUploadRequest.extra).device_keys; + keyQueryResponse.device_keys[userId][deviceId] = JSON.parse(keysUploadRequest.body).device_keys; - const keys = JSON.parse(signingKeysUploadRequest.extra); + const keys = JSON.parse(signingKeysUploadRequest.body); keyQueryResponse.master_keys[userId] = keys.master_key; keyQueryResponse.self_signing_keys[userId] = keys.self_signing_key; keyQueryResponse.user_signing_keys[userId] = keys.user_signing_key; diff --git a/bindings/matrix-sdk-crypto-js/tests/machine.test.js b/bindings/matrix-sdk-crypto-js/tests/machine.test.js index 448b1da97..dbbd7f723 100644 --- a/bindings/matrix-sdk-crypto-js/tests/machine.test.js +++ b/bindings/matrix-sdk-crypto-js/tests/machine.test.js @@ -198,9 +198,9 @@ describe(OlmMachine.name, () => { expect(outgoingRequests[0]).toBeInstanceOf(KeysUploadRequest); expect(outgoingRequests[0].id).toBeDefined(); expect(outgoingRequests[0].type).toStrictEqual(RequestType.KeysUpload); - expect(outgoingRequests[0].extra).toBeDefined(); + expect(outgoingRequests[0].body).toBeDefined(); - const body = JSON.parse(outgoingRequests[0].extra) + const body = JSON.parse(outgoingRequests[0].body) expect(body.device_keys).toBeDefined(); expect(body.one_time_keys).toBeDefined(); } @@ -209,9 +209,9 @@ describe(OlmMachine.name, () => { expect(outgoingRequests[1]).toBeInstanceOf(KeysQueryRequest); expect(outgoingRequests[1].id).toBeDefined(); expect(outgoingRequests[1].type).toStrictEqual(RequestType.KeysQuery); - expect(outgoingRequests[1].extra).toBeDefined(); + expect(outgoingRequests[1].body).toBeDefined(); - const body = JSON.parse(outgoingRequests[1].extra); + const body = JSON.parse(outgoingRequests[1].body); expect(body.timeout).toBeDefined(); expect(body.device_keys).toBeDefined(); expect(body.token).toBeDefined();