Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically re-send event after NIP-42 authentication #509

Closed
reyamir opened this issue Jul 25, 2024 · 3 comments
Closed

Automatically re-send event after NIP-42 authentication #509

reyamir opened this issue Jul 25, 2024 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@reyamir
Copy link
Contributor

reyamir commented Jul 25, 2024

Describe the bug
Construct a client which also set automatic_authentication to true (default). It will not automatically auth.

To Reproduce
Repo: https://github.com/reyamir/rust-nostr-debug.git

let keys: Keys = Keys::generate();
let signer = NostrSigner::Keys(keys);

// Config
let opts = Options::new().automatic_authentication(true);

// Setup nostr client
let client = ClientBuilder::default().signer(signer).opts(opts).build();

client.add_relay("wss://relay.damus.io").await?;
client.connect().await;

// Add nip-17 relay
client.add_relay("wss://auth.nostr1.com").await?;
client.connect_relay("wss://auth.nostr1.com").await?;

// Send private message
let receiver =
    PublicKey::from_bech32("npub1zfss807aer0j26mwp2la0ume0jqde3823rmu97ra6sgyyg956e0s6xw445")
        .unwrap();
let message = "Hello world";

match client
    .send_private_msg_to(["wss://auth.nostr1.com"], receiver, message, None)
    .await
{
    Ok(output) => println!("Ok: {:?}", output),
    Err(e) => println!("Err: {}", e),
}

Ok(())

The result is Err: event not published: auth-required: you must auth

Expected behavior
Automatically auth when add new relay.

Build environment

  • Library: nostr-sdk
  • Language: Rust
  • Language version: 1.78
  • Tag/commit: 79b84f6
  • OS+version: macOS 14
@reyamir reyamir added the bug Something isn't working label Jul 25, 2024
@yukibtc
Copy link
Member

yukibtc commented Jul 25, 2024

As temporary workaround: subscribe with autoclosing option using a filter that get nothing, like Filter::new().kind(Kind::TextNote).limit(0) (or use get_events_of with that filter).

The issue shouldn't be the authentication but the fact that AUTH message is sent after you send the first event (or REQ). So, after the authentication, the event should be re-sent (same issue of few days ago with REQ).

I'll try to search a way to automatically re-send the event if the error is related to authentication.

@reyamir
Copy link
Contributor Author

reyamir commented Jul 25, 2024

Yo thank you, your workaround help me resolve the weird bug in my chat app 😅

@yukibtc yukibtc changed the title automatic_authentication is not working Automatically re-send event after NIP-42 authentication Jul 25, 2024
@yukibtc yukibtc added the help wanted Extra attention is needed label Aug 7, 2024
@yukibtc yukibtc added this to the Release v0.36 milestone Sep 9, 2024
@yukibtc yukibtc modified the milestones: Release v0.36, Release v0.38 Oct 14, 2024
yukibtc added a commit that referenced this issue Dec 2, 2024
Fixes #509

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
yukibtc added a commit that referenced this issue Dec 2, 2024
Fixes #509

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
yukibtc added a commit that referenced this issue Dec 2, 2024
Fixes #509

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
yukibtc added a commit that referenced this issue Dec 2, 2024
* Remove `Client::spawn_notification_handler`
* Add `SharedState`
* Auth relays (NIP42) directly in the `InnerRelay`

Fixes #509

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
yukibtc added a commit that referenced this issue Dec 3, 2024
* Remove `Client::spawn_notification_handler`
* Add `SharedState`
* Auth relays (NIP42) directly in the `InnerRelay`

Fixes #509

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
@yukibtc yukibtc closed this as completed in aca302e Dec 3, 2024
@yukibtc
Copy link
Member

yukibtc commented Dec 3, 2024

Fixed in #667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants