Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Feb 2, 2024
1 parent 31162f3 commit 21ffb1e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gateway-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bytes>,
pub installation: Vec<Bytes>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<_, _>>()?,
Expand Down
85 changes: 85 additions & 0 deletions xps-gateway/src/rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyPackageResult, ErrorObjectOwned>;

Expand Down
6 changes: 3 additions & 3 deletions xps-gateway/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"]
);

Expand Down

0 comments on commit 21ffb1e

Please sign in to comment.