From 21ffb1e656289eea1dfa75d42d9c80f0537852f6 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Fri, 2 Feb 2024 17:08:53 -0500 Subject: [PATCH] doc --- gateway-types/src/lib.rs | 2 +- registry/src/lib.rs | 2 +- xps-gateway/src/rpc/api.rs | 85 +++++++++++++++++++++++++++ xps-gateway/tests/integration_test.rs | 6 +- 4 files changed, 90 insertions(+), 5 deletions(-) diff --git a/gateway-types/src/lib.rs b/gateway-types/src/lib.rs index 6da5370..7c64ec2 100644 --- a/gateway-types/src/lib.rs +++ b/gateway-types/src/lib.rs @@ -53,7 +53,7 @@ pub struct KeyPackageResult { /// A message relating to the operation pub message: String, /// A list of key packages - pub key_packages: Vec, + pub installation: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] diff --git a/registry/src/lib.rs b/registry/src/lib.rs index 64a0d68..4159704 100644 --- a/registry/src/lib.rs +++ b/registry/src/lib.rs @@ -69,7 +69,7 @@ where Ok(KeyPackageResult { status: Status::Completed, message: "Key packages retrieved".to_string(), - key_packages: properties + installation: properties .into_iter() .map(TryFrom::try_from) .collect::>()?, diff --git a/xps-gateway/src/rpc/api.rs b/xps-gateway/src/rpc/api.rs index 2ec242d..85abf69 100644 --- a/xps-gateway/src/rpc/api.rs +++ b/xps-gateway/src/rpc/api.rs @@ -222,6 +222,91 @@ pub trait Xps { signature: Signature, ) -> Result<(), ErrorObjectOwned>; + /// ## JSON-RPC Endpoint Documentation + /// + /// #### Request: + /// + /// - **Method:** `POST` + /// - **URL:** `/rpc/v1/fetchKeyPackages` + /// - **Headers:** + /// - `Content-Type: application/json` + /// - **Body:** + /// - **JSON Object:** + /// - `jsonrpc`: `"2.0"` + /// - `method`: `"fetchKeyPackages"` + /// - `params`: Array (optional parameters as required) + /// - `id`: Request identifier (integer or string) + /// + /// ### Endpoint: `fetchKeyPackages` + /// + /// #### Description + /// + /// The `fetchKeyPackages` endpoint is responsible for retrieving the contact bundle for the XMTP device installations. The request must be made to a valid did with an XMTP profile. + /// + /// #### Request + /// + /// The request for this endpoint should contain a valid DID. All returned information is public. + /// + /// ##### Parameters: + /// + /// - `DID` (string): Unique XMTP identifier for the user requesting the installation. + /// + /// ##### Example Request: + /// + /// ```json + /// { + /// "jsonrpc": "2.0", + /// "method": "fetchKeyPackages", + /// "params": { + /// "did": "12345" + /// }, + /// "id": 1 + /// } + /// ``` + /// + /// #### Response + /// + /// The response will provide an optionally empty list of installation bundles. + /// + /// ##### Result Fields: + /// + /// - `status` (string): The status of the request, e.g., 'success'. + /// - `installation` (array): Array of installation bundles. + /// + /// ##### Example Response: + /// + /// ```json + /// { + /// "jsonrpc": "2.0", + /// "result": { + /// "status": "success", + /// "installation": ["bundle1...", "bundle2..."] + /// }, + /// "id": 1 + /// } + /// ``` + /// + /// #### Error Handling + /// + /// In case of an error, the response will include an error object with details. + /// + /// ##### Error Object Fields: + /// + /// - `code` (integer): Numeric code representing the error type. + /// - `message` (string): Description of the error. + /// + /// ##### Example Error Response: + /// + /// ```json + /// { + /// "jsonrpc": "2.0", + /// "error": { + /// "code": 403, + /// "message": "User not authorized for installation." + /// }, + /// "id": 1 + /// } + /// ``` #[method(name = "fetchKeyPackages")] async fn fetch_key_packages(&self, did: String) -> Result; diff --git a/xps-gateway/tests/integration_test.rs b/xps-gateway/tests/integration_test.rs index de580e6..b73e45b 100644 --- a/xps-gateway/tests/integration_test.rs +++ b/xps-gateway/tests/integration_test.rs @@ -198,7 +198,7 @@ async fn test_fetch_key_packages() -> Result<(), Error> { assert_eq!(res.status, Status::Completed); assert_eq!(&res.message, "Key packages retrieved"); assert_eq!( - res.key_packages, + res.installation, vec![ b"000000000000000000000000000000000000000000000000000000000000000000", b"111111111111111111111111111111111111111111111111111111111111111111" @@ -241,7 +241,7 @@ async fn test_fetch_key_packages_revoke() -> Result<(), Error> { assert_eq!(res.status, Status::Completed); assert_eq!(&res.message, "Key packages retrieved"); assert_eq!( - res.key_packages, + res.installation, vec![hex::decode( b"000000000000000000000000000000000000000000000000000000000000000000" ) @@ -284,7 +284,7 @@ async fn test_fetch_key_packages_client() -> Result<(), Error> { assert_eq!(res.status, Status::Completed); assert_eq!(&res.message, "Key packages retrieved"); assert_eq!( - res.key_packages, + res.installation, vec![b"000000000000000000000000000000000000000000000000000000000000000000"] );