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

Allow for user to define the secret key over an environment variable. #82

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

SilberWitch
Copy link

Need to be able to change the key to something I can auth with. Uses the same env variable technique as NAK does.

@SilberWitch
Copy link
Author

SilberWitch commented Feb 4, 2025

Used my Silberengel account, that is allowed to write to all four relays.

This works with nostr.land and returns:

The event has been transmitted to the relay wss://nostr.land
The received event id from the relay: 3c5092905468a9176fa200b95c3563f5905c8e268bb3d774407e9355e9605695

wss://mleku.realy.lol returns:
Exception error: auth-required: auth required for request processing

wss://nostr.wine returns:
Exception error: Connection error

wss://gitcitadel.nostr1.com returns:
Exception error: auth-required: you must auth

@Sebastix
Copy link
Member

Sebastix commented Feb 6, 2025

Did some debugging and shared my notes here:
nostrability/nostrability#163 (comment)

When the library sends a AUTH message to the relay, a dummy secret key is used. See https://github.com/nostrver-se/nostr-php/blob/main/src/Request/Request.php#L169

On wss://nostr.wine I get a connection error too. The WebSocket in Nostr-PHP marks the connection as invalid (when switching protocols from http to websockets) as there is no message from the server. The match logic is applied (https://github.com/sirn-se/websocket-php/blob/v3.2-main/src/Http/HttpHandler.php#L62):

preg_match('!^HTTP/(?P<version>[0-9/.]+) (?P<code>[0-9]*) (?P<reason>.*)!', $status, $matches);

where $status has the value HTTP/1.1 101 when the client tries to open the websocket connection with wss://nostr.wine.

Compared to other relays, the $status has the value HTTP/1.1 101 Switching Protocols which seems to be more correct following the WebSocket protocol specs.

FYI @Mazin

@Sebastix
Copy link
Member

Sebastix commented Feb 7, 2025

@SilberWitch See sirn-se/websocket-php#100 with a proposed change of fixing the connection to wss://nostr.wine

@SilberWitch
Copy link
Author

Painful, how you're having to patch all of these faulty AUTH implementations from your library.

@Sebastix
Copy link
Member

Sebastix commented Feb 7, 2025

Nostrability could fix this with @alltheseas ;)

@Sebastix
Copy link
Member

sirn-se/websocket-php#100 (comment) merged so with a next release of this package the connection will work with wss://nostr.wine


// pull environment variable containing key that is allowed to AUTH to this relay
// uses the same env name as NAK
$private_key = getenv('NOSTR_SECRET_KEY');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this env variable is not set, I would suggest to fallback to a generated private key (or use a harcoded one like 11111111)

@@ -5,6 +5,7 @@
composer.lock
test*.php
vendor/
/.vscode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants