commit 066cbd4f741deb21674859d16b127b19820260eb
parent cbefdbd5b663bc241c762a6efeba74d7e9f34eb4
Author: triesap <tyson@radroots.org>
Date: Tue, 25 Aug 2026 03:45:54 +0000
nostr-connect: decode connect pending responses
Diffstat:
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/crates/nostr_connect/src/message.rs b/crates/nostr_connect/src/message.rs
@@ -856,8 +856,10 @@ impl Response {
}
if let Some(error) = envelope.error {
- if matches!(method, Method::GetPublicKey | Method::GetSessionCapability)
- && envelope.result.is_none()
+ if matches!(
+ method,
+ Method::Connect | Method::GetPublicKey | Method::GetSessionCapability
+ ) && envelope.result.is_none()
&& error == PENDING_CONNECTION_ERROR
{
return Ok(Self::PendingConnection);
diff --git a/crates/nostr_connect/tests/protocol.rs b/crates/nostr_connect/tests/protocol.rs
@@ -413,18 +413,24 @@ fn auth_url_response_parses_from_result_and_error_fields() {
}
#[test]
-fn get_public_key_pending_response_parses_as_typed_pending_connection() {
- let response = Response::from_envelope(
- &Method::GetPublicKey,
- ResponseEnvelope {
- id: "req-pending".to_owned(),
- result: None,
- error: Some(PENDING_CONNECTION_ERROR.to_owned()),
- },
- )
- .expect("parse pending get_public_key response");
+fn connect_and_poll_pending_responses_parse_as_typed_pending_connection() {
+ for method in [
+ Method::Connect,
+ Method::GetPublicKey,
+ Method::GetSessionCapability,
+ ] {
+ let response = Response::from_envelope(
+ &method,
+ ResponseEnvelope {
+ id: "req-pending".to_owned(),
+ result: None,
+ error: Some(PENDING_CONNECTION_ERROR.to_owned()),
+ },
+ )
+ .expect("parse pending connection response");
- assert_eq!(response, Response::PendingConnection);
+ assert_eq!(response, Response::PendingConnection);
+ }
}
#[test]