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

NIP-46 auth #1311

Merged
merged 25 commits into from
Aug 27, 2024
Merged

NIP-46 auth #1311

merged 25 commits into from
Aug 27, 2024

Conversation

riccardobl
Copy link
Member

@riccardobl riccardobl commented Aug 18, 2024

Description

Solves #864 .
This PR updates the behavior of the "Login with Nostr" button by adding an intermediary page that presents the following login options:

  • Login with extension: the current behavior using the browser extension eg. alby
  • Login by pasting a bunker:// token
  • Login by using a nip-05 address
  • Login by copying or scanning the nostrconnect:/// url with the signer

Screenshots

Screenshot from 2024-08-18 11-34-53

Screenshot from 2024-08-18 11-35-01

image

image

image

Additional Context

  • I've updated the nostr-tools dependency to the latest version

Still wip

Checklist

Are your changes backwards compatible? Please answer below:

yes

Did you QA this? Could we deploy this straight to production? Please answer below:

yes

For frontend changes: Tested on mobile? Please answer below:

Yes

Did you introduce any new environment variables? If so, call them out explicitly here:

no

@stackernews stackernews deleted a comment from socket-security bot Aug 18, 2024
@stackernews stackernews deleted a comment from socket-security bot Aug 18, 2024
@huumn
Copy link
Member

huumn commented Aug 18, 2024

@SocketSecurity ignore npm/[email protected]

Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the PR and integrating it with my relay code!

I left some suggestions regarding the reconnect logic.

Will look at Relay.subscribe and the rest tomorrow.

@riccardobl riccardobl requested a review from ekzyis August 21, 2024 09:21
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Hey @riccardobl, sorry for the delayed review.

I tested your code today with nsec.app and pasted the bunker:// string into SN and it works well! I haven't tested nostrconnect:// though. I expected clicking on the QR code would open nsec.app but it didn't. Guess it doesn't register for this scheme?

Anyway, looking through the code, I have two questions:

  1. Have you looked into the NIP-46 implementation from NDK1? Maybe I missed something or forgot the reason, but I wonder why we don't simply use NDK's implementation. That should work just as well with less lines of code we have to maintain ourselves, no?

  2. I am currently confused why you need long-living connections with a subscription pool (this.subs) for your implementation. Was it not possible to implement NIP-46 with the existing implementation of relay.fetch? I wrote it for NWC and afaict, NIP-46 has a similar request-response flow so I wonder why it needed changes. Is it because we need to handle connections to multiple relays at once? That's something my relay code is lacking.

Footnotes

  1. https://github.com/nostr-dev-kit/ndk/tree/master/ndk/src/signers/nip46

@riccardobl
Copy link
Member Author

riccardobl commented Aug 24, 2024

I expected clicking on the QR code would open nsec.app but it didn't. Guess it doesn't register for this scheme?

Clicking or scanning the QR is for the nip-46 nostrconnect:// flow , currently this is not supported by many signers. The only one that i've found that is production looking is nostrum , but it seems it diverges from the spec ( nostr-connect/nostrum#22 ) so it doesn't work properly atm.
I made sure to implement the full nip-46 despite the current status of the various signers.

Have you looked into the NIP-46 implementation from NDK1? Maybe I missed something or forgot the reason, but I wonder why we don't simply use NDK's implementation. That should work just as well with less lines of code we have to maintain ourselves, no?

Mainly because it is not a dependency that is currently available in stacker news and it didn't feel right to add a new dependency just for this, also ndk doesn't support nostrconnect:// flow from what i can tell

I am currently confused why you need long-living connections with a subscription pool (this.subs) for your implementation. Was it not possible to implement NIP-46 with the existing implementation of relay.fetch? I wrote it for NWC and afaict, NIP-46 has a similar request-response flow so I wonder why it needed changes. Is it because we need to handle connections to multiple relays at once? That's something my relay code is lacking.

Mostly because we would need to re-subscribe at least 3 times to the same filter to use the fetch logic, it would be slower and provide no benefit imo, i think it makes sense to use fetch where you don't have a back and forth communication. Also the nostrconnect:// flow needs to listen for an app initiating the connection, so it can't timeout.

subscription pool (this.subs)

The reason to track subscription is to close them once the connection is established in one of the supported methods or if the signer is closed

@riccardobl riccardobl marked this pull request as ready for review August 24, 2024 09:50
@riccardobl riccardobl requested a review from ekzyis August 24, 2024 09:50
@ekzyis ekzyis changed the base branch from master to ndk August 27, 2024 01:00
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Hi @riccardobl, thanks again for your PR!

We've decided to merge it into an intermediate branch1 since we're looking into using only NDK for all our nostr code instead of the library mess of nostr-tools and nostr that we currently have. We will do this ourselves in this branch before merging it into master since it's out of the scope of this PR. Your changes look good and you couldn't have known that we will be looking into NDK (we didn't even know that ourselves before I reviewed this PR) so it's okay that you didn't use NDK.

I will approve this PR and @huumn will send you your sats for #864. Looking forward to more contributions from you!

Footnotes

  1. I will merge the bugfixes you provided for existing relay code separately into master

@ekzyis ekzyis merged commit ca30bfd into stackernews:ndk Aug 27, 2024
6 checks passed
@ekzyis ekzyis mentioned this pull request Aug 27, 2024
@riccardobl riccardobl mentioned this pull request Dec 4, 2024
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.

3 participants