-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
3,421 additions
and
1,339 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "xmtp_api_d14n" | ||
edition = "2021" | ||
license.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
derive_builder = "0.20" | ||
once_cell.workspace = true | ||
parking_lot.workspace = true | ||
prost.workspace = true | ||
prost-types.workspace = true | ||
xmtp_proto.workspace = true | ||
|
||
[dev-dependencies] | ||
xmtp_api_grpc.workspace = true | ||
tokio.workspace = true | ||
|
||
[features] | ||
http-api = [] | ||
grpc-api = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Decentralization API for XMTP | ||
|
||
Backwards-compatible with non-d14n endpoints (endpoints/v3/*), includes new d14n | ||
endpoints (endpoints/d14n). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use derive_builder::Builder; | ||
use prost::Message; | ||
use std::borrow::Cow; | ||
use xmtp_proto::traits::{BodyError, Endpoint}; | ||
use xmtp_proto::xmtp::mls::api::v1::FetchKeyPackagesRequest; | ||
use xmtp_proto::xmtp::xmtpv4::message_api::FILE_DECRIPTOR_SET; | ||
use xmtp_proto::xmtp::xmtpv4::message_api::{GetInboxIdsRequest, GetInboxIdsResponse}; | ||
|
||
#[derive(Debug, Builder, Default)] | ||
#[builder(setter(strip_option))] | ||
pub struct GetInboxIds { | ||
#[builder(setter(into))] | ||
envelopes: Vec<ClientEnvelope>, | ||
} | ||
|
||
impl GetInboxIds { | ||
pub fn builder() -> GetInboxIdsBuilder { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Endpoint for GetInboxIds { | ||
type Output = GetInboxIdsResponse; | ||
|
||
fn http_endpoint(&self) -> Cow<'static, str> { | ||
todo!() | ||
} | ||
|
||
fn grpc_endpoint(&self) -> Cow<'static, str> { | ||
crate::path_and_query::<PublishClientEnvelopesRequest>(FILE_DESCRIPTOR_SET) | ||
} | ||
|
||
fn body(&self) -> Result<Vec<u8>, BodyError> { | ||
Ok(PublishClientEnvelopesRequest { | ||
envelopes: self.envelopes.clone(), | ||
} | ||
.encode_to_vec()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod publish_client_envelopes; | ||
pub use publish_client_envelopes::*; | ||
|
||
mod query_envelopes; | ||
pub use query_envelopes::*; |
38 changes: 38 additions & 0 deletions
38
xmtp_api_d14n/src/endpoints/d14n/publish_client_envelopes.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use derive_builder::Builder; | ||
use prost::Message; | ||
use std::borrow::Cow; | ||
use xmtp_proto::traits::{BodyError, Endpoint}; | ||
use xmtp_proto::xmtp::xmtpv4::envelopes::ClientEnvelope; | ||
use xmtp_proto::xmtp::xmtpv4::payer_api::PublishClientEnvelopesRequest; | ||
use xmtp_proto::xmtp::xmtpv4::payer_api::FILE_DESCRIPTOR_SET; | ||
|
||
#[derive(Debug, Builder, Default)] | ||
#[builder(setter(strip_option))] | ||
pub struct PublishClientEnvelopes { | ||
#[builder(setter(into))] | ||
envelopes: Vec<ClientEnvelope>, | ||
} | ||
|
||
impl PublishClientEnvelopes { | ||
pub fn builder() -> PublishClientEnvelopesBuilder { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Endpoint for PublishClientEnvelopes { | ||
type Output = (); | ||
fn http_endpoint(&self) -> Cow<'static, str> { | ||
todo!() | ||
} | ||
|
||
fn grpc_endpoint(&self) -> Cow<'static, str> { | ||
crate::path_and_query::<PublishClientEnvelopesRequest>(FILE_DESCRIPTOR_SET) | ||
} | ||
|
||
fn body(&self) -> Result<Vec<u8>, BodyError> { | ||
Ok(PublishClientEnvelopesRequest { | ||
envelopes: self.envelopes.clone(), | ||
} | ||
.encode_to_vec()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use derive_builder::Builder; | ||
use prost::Message; | ||
use std::borrow::Cow; | ||
use xmtp_proto::traits::{BodyError, Endpoint}; | ||
use xmtp_proto::xmtp::xmtpv4::message_api::EnvelopesQuery; | ||
use xmtp_proto::xmtp::xmtpv4::message_api::FILE_DESCRIPTOR_SET; | ||
use xmtp_proto::xmtp::xmtpv4::message_api::{QueryEnvelopesRequest, QueryEnvelopesResponse}; | ||
|
||
/// Query a single thing | ||
#[derive(Debug, Builder, Default, Clone)] | ||
pub struct QueryEnvelope { | ||
#[builder(setter(into))] | ||
topics: Vec<Vec<u8>>, | ||
#[builder(setter(into))] | ||
originator_node_ids: Vec<u32>, | ||
} | ||
|
||
impl QueryEnvelope { | ||
pub fn builder() -> QueryEnvelopeBuilder { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Endpoint for QueryEnvelope { | ||
type Output = QueryEnvelopesResponse; | ||
|
||
fn http_endpoint(&self) -> Cow<'static, str> { | ||
todo!() | ||
} | ||
|
||
fn grpc_endpoint(&self) -> Cow<'static, str> { | ||
crate::path_and_query::<QueryEnvelopesRequest>(FILE_DESCRIPTOR_SET) | ||
} | ||
|
||
fn body(&self) -> Result<Vec<u8>, BodyError> { | ||
Ok(QueryEnvelopesRequest { | ||
query: Some(EnvelopesQuery { | ||
topics: self.topics.clone(), | ||
originator_node_ids: self.originator_node_ids.clone(), | ||
last_seen: None, | ||
}), | ||
limit: 1, | ||
} | ||
.encode_to_vec()) | ||
} | ||
} | ||
|
||
/// Batch Query | ||
#[derive(Debug, Builder, Default)] | ||
#[builder(setter(strip_option))] | ||
pub struct QueryEnvelopes { | ||
#[builder(setter(into))] | ||
envelopes: EnvelopesQuery, | ||
#[builder(setter(into))] | ||
limit: u32, | ||
} | ||
|
||
impl QueryEnvelopes { | ||
pub fn builder() -> QueryEnvelopesBuilder { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Endpoint for QueryEnvelopes { | ||
type Output = QueryEnvelopesResponse; | ||
|
||
fn http_endpoint(&self) -> Cow<'static, str> { | ||
todo!() | ||
} | ||
|
||
fn grpc_endpoint(&self) -> Cow<'static, str> { | ||
crate::path_and_query::<QueryEnvelopesRequest>(FILE_DESCRIPTOR_SET) | ||
} | ||
|
||
fn body(&self) -> Result<Vec<u8>, BodyError> { | ||
Ok(QueryEnvelopesRequest { | ||
query: Some(self.envelopes.clone()), | ||
limit: self.limit, | ||
} | ||
.encode_to_vec()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod d14n; | ||
pub mod v3; | ||
|
||
pub use d14n::*; | ||
pub use v3::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use derive_builder::Builder; | ||
use prost::Message; | ||
use std::borrow::Cow; | ||
use xmtp_proto::traits::{BodyError, Endpoint}; | ||
use xmtp_proto::xmtp::mls::api::v1::FILE_DESCRIPTOR_SET; | ||
use xmtp_proto::xmtp::mls::api::v1::{FetchKeyPackagesRequest, FetchKeyPackagesResponse}; | ||
|
||
#[derive(Debug, Builder, Default)] | ||
#[builder(setter(strip_option))] | ||
pub struct FetchKeyPackages { | ||
#[builder(setter(into))] | ||
installation_keys: Vec<Vec<u8>>, | ||
} | ||
|
||
impl FetchKeyPackages { | ||
pub fn builder() -> FetchKeyPackagesBuilder { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Endpoint for FetchKeyPackages { | ||
type Output = FetchKeyPackagesResponse; | ||
fn http_endpoint(&self) -> Cow<'static, str> { | ||
todo!() | ||
} | ||
|
||
fn grpc_endpoint(&self) -> Cow<'static, str> { | ||
crate::path_and_query::<FetchKeyPackagesRequest>(FILE_DESCRIPTOR_SET) | ||
} | ||
|
||
fn body(&self) -> Result<Vec<u8>, BodyError> { | ||
Ok(FetchKeyPackagesRequest { | ||
installation_keys: self.installation_keys.clone(), | ||
} | ||
.encode_to_vec()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use xmtp_api_grpc::{grpc_client::GrpcClient, LOCALHOST_ADDRESS}; | ||
use xmtp_proto::api_client::ApiBuilder; | ||
use xmtp_proto::traits::Query; | ||
|
||
#[test] | ||
fn test_file_descriptor() { | ||
let pnq = crate::path_and_query::<FetchKeyPackagesRequest>(FILE_DESCRIPTOR_SET); | ||
println!("{}", pnq); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_fetch_key_packages() { | ||
let mut client = GrpcClient::builder(); | ||
client.set_app_version("0.0.0".into()).unwrap(); | ||
client.set_tls(false); | ||
client.set_host(LOCALHOST_ADDRESS.to_string()); | ||
let client = client.build().await.unwrap(); | ||
|
||
let endpoint = FetchKeyPackages::builder() | ||
.installation_keys(vec![vec![1, 2, 3]]) | ||
.build() | ||
.unwrap(); | ||
|
||
let result: FetchKeyPackagesResponse = endpoint.query(&client).await.unwrap(); | ||
assert_eq!(result.key_packages, vec![]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
mod fetch_key_packages; | ||
pub use fetch_key_packages::*; | ||
|
||
mod query_group_messages; | ||
pub use query_group_messages::*; | ||
|
||
mod query_welcome_messages; | ||
pub use query_welcome_messages::*; | ||
|
||
mod send_group_messages; | ||
pub use send_group_messages::*; | ||
|
||
mod send_welcome_messages; | ||
pub use send_welcome_messages::*; |
Oops, something went wrong.