commit b5b8dee87cbe9f2e6af2ffb63f60cfdd3e9ac054
parent a9cad9021fcc319d0441a92206585e8ac94a4455
Author: triesap <tyson@radroots.org>
Date: Thu, 9 Apr 2026 22:08:01 +0000
nostr-connect: type pending capability responses
Diffstat:
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/crates/nostr-connect/src/message.rs b/crates/nostr-connect/src/message.rs
@@ -308,6 +308,11 @@ impl RadrootsNostrConnectResponse {
Self::RemoteSessionCapability(capability) => {
RadrootsNostrConnectPendingConnectionPollOutcome::ApprovedCapability(capability)
}
+ Self::Error { error, .. }
+ if error == RADROOTS_NOSTR_CONNECT_PENDING_CONNECTION_ERROR =>
+ {
+ RadrootsNostrConnectPendingConnectionPollOutcome::PendingApproval
+ }
Self::Error { error, .. } => {
RadrootsNostrConnectPendingConnectionPollOutcome::Rejected { message: error }
}
@@ -423,8 +428,11 @@ impl RadrootsNostrConnectResponse {
}
if let Some(error) = envelope.error {
- if matches!(method, RadrootsNostrConnectMethod::GetPublicKey)
- && envelope.result.is_none()
+ if matches!(
+ method,
+ RadrootsNostrConnectMethod::GetPublicKey
+ | RadrootsNostrConnectMethod::GetSessionCapability
+ ) && envelope.result.is_none()
&& error == RADROOTS_NOSTR_CONNECT_PENDING_CONNECTION_ERROR
{
return Ok(Self::PendingConnection);
diff --git a/crates/nostr-connect/tests/coverage.rs b/crates/nostr-connect/tests/coverage.rs
@@ -765,6 +765,18 @@ fn response_surface_covers_success_and_error_paths() {
);
assert_eq!(
RadrootsNostrConnectResponse::from_envelope(
+ &RadrootsNostrConnectMethod::GetSessionCapability,
+ RadrootsNostrConnectResponseEnvelope {
+ id: "req-pending-capability".to_owned(),
+ result: None,
+ error: Some(RADROOTS_NOSTR_CONNECT_PENDING_CONNECTION_ERROR.to_owned()),
+ },
+ )
+ .expect("parse typed pending capability response"),
+ RadrootsNostrConnectResponse::PendingConnection
+ );
+ assert_eq!(
+ RadrootsNostrConnectResponse::from_envelope(
&RadrootsNostrConnectMethod::Ping,
RadrootsNostrConnectResponseEnvelope {
id: "req-error".to_owned(),
@@ -1042,6 +1054,14 @@ fn pending_connection_poll_outcome_uses_typed_variants() {
message: "rejected".to_owned(),
}
);
+ assert_eq!(
+ RadrootsNostrConnectResponse::Error {
+ result: None,
+ error: RADROOTS_NOSTR_CONNECT_PENDING_CONNECTION_ERROR.to_owned(),
+ }
+ .into_pending_connection_poll_outcome(),
+ RadrootsNostrConnectPendingConnectionPollOutcome::PendingApproval
+ );
assert_eq!(
RadrootsNostrConnectResponse::AuthUrl("https://auth.example.com/challenge".to_owned())