Skip to content

Commit d17f94b

Browse files
authored
feat: publish verify attestation (#82)
1 parent edd6b6b commit d17f94b

File tree

8 files changed

+29
-4
lines changed

8 files changed

+29
-4
lines changed

examples/http_client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async fn main() -> anyhow::Result<()> {
5252
.publish(
5353
topic.clone(),
5454
message.clone(),
55+
None,
5556
1100,
5657
Duration::from_secs(30),
5758
false,

examples/webhook.rs

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ async fn main() -> anyhow::Result<()> {
194194
.publish(
195195
topic.clone(),
196196
message.clone(),
197+
None,
197198
1100,
198199
Duration::from_secs(30),
199200
false,

examples/websocket_client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ async fn main() -> anyhow::Result<()> {
9393
.publish(
9494
topic.clone(),
9595
Arc::from("Hello WalletConnect!"),
96+
None,
9697
0,
9798
Duration::from_secs(60),
9899
false,

relay_client/src/http.rs

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl Client {
105105
&self,
106106
topic: Topic,
107107
message: impl Into<Arc<str>>,
108+
attestation: impl Into<Option<Arc<str>>>,
108109
tag: u32,
109110
ttl: Duration,
110111
prompt: bool,
@@ -120,6 +121,7 @@ impl Client {
120121
self.request(rpc::Publish {
121122
topic,
122123
message: message.into(),
124+
attestation: attestation.into(),
123125
ttl_secs,
124126
tag,
125127
prompt,

relay_client/src/websocket.rs

+2
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ impl Client {
156156
&self,
157157
topic: Topic,
158158
message: impl Into<Arc<str>>,
159+
attestation: impl Into<Option<Arc<str>>>,
159160
tag: u32,
160161
ttl: Duration,
161162
prompt: bool,
162163
) -> EmptyResponseFuture<Publish> {
163164
let (request, response) = create_request(Publish {
164165
topic,
165166
message: message.into(),
167+
attestation: attestation.into(),
166168
ttl_secs: ttl.as_secs() as u32,
167169
tag,
168170
prompt,

relay_rpc/src/rpc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ pub struct Publish {
529529
/// Message to publish.
530530
pub message: Arc<str>,
531531

532+
#[serde(default, skip_serializing_if = "is_default")]
533+
pub attestation: Option<Arc<str>>,
534+
532535
/// Duration for which the message should be kept in the mailbox if it can't
533536
/// be delivered, in seconds.
534537
#[serde(rename = "ttl")]
@@ -556,6 +559,7 @@ impl Publish {
556559
data: SubscriptionData {
557560
topic: self.topic.clone(),
558561
message: self.message.clone(),
562+
attestation: self.attestation.clone(),
559563
published_at,
560564
tag: self.tag,
561565
},
@@ -728,6 +732,9 @@ pub struct SubscriptionData {
728732
/// The message for the subscription.
729733
pub message: Arc<str>,
730734

735+
#[serde(default, skip_serializing_if = "is_default")]
736+
pub attestation: Option<Arc<str>>,
737+
731738
/// Message publish timestamp in UTC milliseconds.
732739
pub published_at: i64,
733740

relay_rpc/src/rpc/tests.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn request() {
77
Params::Publish(Publish {
88
topic: "topic".into(),
99
message: "payload".into(),
10+
attestation: Some(Arc::from("attestation_payload")),
1011
ttl_secs: 12,
1112
tag: 0,
1213
prompt: false,
@@ -17,7 +18,7 @@ fn request() {
1718

1819
assert_eq!(
1920
&serialized,
20-
r#"{"id":1,"jsonrpc":"2.0","method":"irn_publish","params":{"topic":"topic","message":"payload","ttl":12,"tag":0}}"#
21+
r#"{"id":1,"jsonrpc":"2.0","method":"irn_publish","params":{"topic":"topic","message":"payload","attestation":"attestation_payload","ttl":12,"tag":0}}"#
2122
);
2223

2324
let deserialized: Payload = serde_json::from_str(&serialized).unwrap();
@@ -91,6 +92,7 @@ fn subscription() {
9192
let data = SubscriptionData {
9293
topic: "test_topic".into(),
9394
message: "test_message".into(),
95+
attestation: Some(Arc::from("test_attestation")),
9496
published_at: 123,
9597
tag: 1000,
9698
};
@@ -104,7 +106,7 @@ fn subscription() {
104106

105107
assert_eq!(
106108
&serialized,
107-
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123,"tag":1000}}}"#
109+
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","attestation":"test_attestation","publishedAt":123,"tag":1000}}}"#
108110
);
109111

110112
let deserialized: Payload = serde_json::from_str(&serialized).unwrap();
@@ -127,7 +129,6 @@ fn batch_receive() {
127129
));
128130

129131
let serialized = serde_json::to_string(&payload).unwrap();
130-
eprintln!("{serialized}");
131132

132133
assert_eq!(
133134
&serialized,
@@ -289,6 +290,7 @@ fn validation() {
289290
params: Params::Publish(Publish {
290291
topic: topic.clone(),
291292
message: message.clone(),
293+
attestation: None,
292294
ttl_secs: 0,
293295
tag: 0,
294296
prompt: false,
@@ -303,6 +305,7 @@ fn validation() {
303305
params: Params::Publish(Publish {
304306
topic: topic.clone(),
305307
message: message.clone(),
308+
attestation: None,
306309
ttl_secs: 0,
307310
tag: 0,
308311
prompt: false,
@@ -317,6 +320,7 @@ fn validation() {
317320
params: Params::Publish(Publish {
318321
topic: topic.clone(),
319322
message: message.clone(),
323+
attestation: None,
320324
ttl_secs: 0,
321325
tag: 0,
322326
prompt: false,
@@ -331,6 +335,7 @@ fn validation() {
331335
params: Params::Publish(Publish {
332336
topic: Topic::from("invalid"),
333337
message: message.clone(),
338+
attestation: None,
334339
ttl_secs: 0,
335340
tag: 0,
336341
prompt: false,
@@ -407,6 +412,7 @@ fn validation() {
407412
data: SubscriptionData {
408413
topic: topic.clone(),
409414
message: message.clone(),
415+
attestation: None,
410416
published_at: 123,
411417
tag: 1000,
412418
},
@@ -423,6 +429,7 @@ fn validation() {
423429
data: SubscriptionData {
424430
topic: topic.clone(),
425431
message: message.clone(),
432+
attestation: None,
426433
published_at: 123,
427434
tag: 1000,
428435
},
@@ -439,6 +446,7 @@ fn validation() {
439446
data: SubscriptionData {
440447
topic: Topic::from("invalid"),
441448
message,
449+
attestation: None,
442450
published_at: 123,
443451
tag: 1000,
444452
},

relay_rpc/src/rpc/watch.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub struct WatchEventPayload {
8585
pub topic: Topic,
8686
/// The published message.
8787
pub message: Arc<str>,
88+
/// The Verify attestation JWT.
89+
pub attestation: Option<Arc<str>>,
8890
/// Message publishing timestamp.
8991
pub published_at: i64,
9092
/// Message tag.
@@ -224,6 +226,7 @@ mod test {
224226
status: WatchStatus::Accepted,
225227
topic,
226228
message: Arc::from("test message"),
229+
attestation: Some(Arc::from("test attestation")),
227230
published_at: iat.timestamp(),
228231
tag: 1100,
229232
},
@@ -233,7 +236,7 @@ mod test {
233236
// lowercase.
234237
assert_eq!(
235238
serde_json::to_string(&claims).unwrap(),
236-
r#"{"iss":"did:key:z6Mku3wsRZTAHjr6xrYWVUfyGeNSNz1GJRVfazp3N76AL9gE","aud":"wss://relay.walletconnect.com","sub":"https://example.com","iat":946684800,"exp":32503680000,"act":"irn_watchEvent","typ":"subscriber","whu":"https://example.com","evt":{"messageId":12345678,"status":"accepted","topic":"474e88153f4db893de42c35e1891dc0e37a02e11961385de0475460fb48b8639","message":"test message","publishedAt":946684800,"tag":1100}}"#
239+
r#"{"iss":"did:key:z6Mku3wsRZTAHjr6xrYWVUfyGeNSNz1GJRVfazp3N76AL9gE","aud":"wss://relay.walletconnect.com","sub":"https://example.com","iat":946684800,"exp":32503680000,"act":"irn_watchEvent","typ":"subscriber","whu":"https://example.com","evt":{"messageId":12345678,"status":"accepted","topic":"474e88153f4db893de42c35e1891dc0e37a02e11961385de0475460fb48b8639","message":"test message","attestation":"test attestation","publishedAt":946684800,"tag":1100}}"#
237240
);
238241

239242
// Verify that the claims can be encoded and decoded correctly.

0 commit comments

Comments
 (0)