From 66ac55f158f7835ece70fe4bae98a3cb176a0f22 Mon Sep 17 00:00:00 2001 From: Tsachi Herman Date: Wed, 10 Jan 2024 16:58:42 -0500 Subject: [PATCH] stage --- xps-gateway/src/rpc/api.rs | 11 ++++++++++- xps-gateway/src/rpc/methods.rs | 21 ++++++++++++++++++++- xps-gateway/src/types.rs | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/xps-gateway/src/rpc/api.rs b/xps-gateway/src/rpc/api.rs index c1ec944..0797193 100644 --- a/xps-gateway/src/rpc/api.rs +++ b/xps-gateway/src/rpc/api.rs @@ -2,7 +2,7 @@ use jsonrpsee::{proc_macros::rpc, types::ErrorObjectOwned}; -use crate::types::Message; +use crate::types::{GrantInstallationResult, Message, Signature}; /// XPS JSON-RPC Interface Methods #[rpc(server, client, namespace = "xps")] @@ -10,4 +10,13 @@ pub trait Xps { // Placeholder for send_message, see [the discussion](https://github.com/xmtp/xps-gateway/discussions/11) #[method(name = "sendMessage")] async fn send_message(&self, _message: Message) -> Result<(), ErrorObjectOwned>; + + #[method(name = "grantInstallation")] + async fn grant_installation( + &self, + did: String, + name: String, + value: String, + signature: Signature, + ) -> Result; } diff --git a/xps-gateway/src/rpc/methods.rs b/xps-gateway/src/rpc/methods.rs index 6dc1556..eb6d732 100644 --- a/xps-gateway/src/rpc/methods.rs +++ b/xps-gateway/src/rpc/methods.rs @@ -5,7 +5,7 @@ use super::api::*; use async_trait::async_trait; use jsonrpsee::types::ErrorObjectOwned; -use crate::types::Message; +use crate::types::{GrantInstallationResult, Message, Signature}; /// Gateway Methods for XPS pub struct XpsMethods; @@ -17,4 +17,23 @@ impl XpsServer for XpsMethods { log::debug!("xps_sendMessage called"); todo!(); } + + async fn grant_installation( + &self, + _did: String, + _name: String, + _value: String, + _signature: Signature, + ) -> Result { + /*if name.len() > 32 { + Err(GrantInstallationResult {}) + }*/ + + let result = GrantInstallationResult { + status: "my-status".to_string(), + message: "my message".to_string(), + transaction: "my transaction".to_string(), + }; + Ok(result) + } } diff --git a/xps-gateway/src/types.rs b/xps-gateway/src/types.rs index c734427..cd689d9 100644 --- a/xps-gateway/src/types.rs +++ b/xps-gateway/src/types.rs @@ -15,3 +15,26 @@ pub struct Message { /// Signature of S s: Vec, } + +#[derive(Serialize, Deserialize)] +pub struct Signature { + /// Signature of V + #[serde(rename = "V")] + v: i64, + /// Signature of R + #[serde(rename = "R")] + r: Vec, + /// Signature of S + #[serde(rename = "S")] + s: Vec, +} + +#[derive(Serialize, Deserialize, Clone)] +pub struct GrantInstallationResult { + #[serde(rename = "status")] + pub status: String, + #[serde(rename = "message")] + pub message: String, + #[serde(rename = "tx")] + pub transaction: String, +}