greenart7c3 / Amber

MIT License
122 stars 7 forks source link

Deep-link nostrconnect:// URIs for NIP-46 #14

Closed alexgleason closed 4 months ago

alexgleason commented 6 months ago

From NIP-46:

Direct connection initiated by the client

The client provides a connection token (or encodes the token in a QR code) and the signer initiates a connection to the client via the specified relay(s).

nostrconnect://<local-keypair-pubkey>?relay=<wss://relay-to-connect-on>&metadata=<json metadata in the form: {"name":"...", "url": "...", "description": "..."}>

nostrconnect URIs should be deep-linked into Amber so it can establish a NIP-46 connection with clients.

greenart7c3 commented 6 months ago

Do you know any application that uses nostrconnect URI?

alexgleason commented 6 months ago

Just posted: https://github.com/nostr-protocol/nips/discussions/1153

greenart7c3 commented 4 months ago

Implemented in the 1.0.0 pre release

You can also use:

name=appname&url=example.com&description=

instead of

metadata=<json metadata in the form: {"name":"...", "url": "...", "description": "..."}>

This makes the qrcode smaller Nostrudel uses it like that

alexgleason commented 4 months ago

I'm trying it out. What happens on the Amber side after the deep-link happens? Does it send a message over the relay?

alexgleason commented 4 months ago

The deep-link opens Amber, but then nothing happens. Here's the link:

nostrconnect://d4ac0aa9df4ae9c491fde58ae4846079ad20332a59d7a360a186122320ad780f?relay=wss%3A%2F%2Fditto.ngrok.app%2Frelay&metadata=%7B%22name%22%3A%22Ditto%22%2C%22url%22%3A%22https%3A%2F%2Fditto.ngrok.app%22%7D

Here's what I see in Amber after clicking the link:

image

On Amber, my pubkey is c75a8da64105da4bcaef479ac2d2f1dbe591fb427819a8283ca46ac50da93f52

Nothing happens on the relay either:

nak req -a c75a8da64105da4bcaef479ac2d2f1dbe591fb427819a8283ca46ac50da93f52 --stream wss://ditto.ngrok.app/relay
connecting to wss://ditto.ngrok.app/relay... ok.

EDIT: Is the client perhaps supposed to send a connect event first?

alexgleason commented 4 months ago

NEVER MIND, my URL was wrong. It was missing the "description" property. Now it works. Thank you!

greenart7c3 commented 4 months ago

I'll add some error messages when something fails

alexgleason commented 4 months ago

In the original spec, url and description were optional, and there was an icons property too. Also, it had some more logic about what the signer is supposed to do after deep-linking (it sends the pubkey back to the app).

https://github.com/nostr-protocol/nips/blob/4bb393735ea501f0bac3e2cb255ae9a3caab6a68/46.md#nostr-connect-uri

They steamrolled it so hard in the rewrite. They didn't care about this auth flow at all. Even though I think it's the better one. We will have to go back and re-spec some of those things.

I wonder what Nostrudel does.

greenart7c3 commented 4 months ago

Nostrudel is not using the metadata tag. It generates the local key pair and the nostrconnect uri and waits for the connect command ack

greenart7c3 commented 4 months ago

I didn't realize that the old spec had connect as an optional command. Every app now sends the connect first to setup the bunker

alexgleason commented 4 months ago

and waits for the connect command ack

So I should be expecting to see an event from Amber come through on the relay? :thinking: This is the part I'm stuck on now.

greenart7c3 commented 4 months ago

Yes it should send the event to the relay

alexgleason commented 4 months ago

I can't seem to get it to connect to my relay. I tried with both a nostrconnect:// URI and by manually adding a relay in the "New App" screen.

Relay network logs show no connection being attempted. I tried force closing and reopening the app.

greenart7c3 commented 4 months ago

Try changing the notification type to direct connection in settings

alexgleason commented 4 months ago

Here's what I'm seeing. It never makes a request to my relay. It doesn't even open the WebSocket connection.

https://github.com/greenart7c3/Amber/assets/3639540/03d0b9f2-321e-4e3c-b31f-b599966cacc4

greenart7c3 commented 4 months ago

I tested with your relay and it sends a ok but never receives a response in nostrudel. With relay.nsec.app it works. Does you relay store ephemeral events?

alexgleason commented 4 months ago

Does you relay store ephemeral events?

No, but it does relay them when you filter by author. Eg:

➜  ~ nak req -k 24133 -a d4ac0aa9df4ae9c491fde58ae4846079ad20332a59d7a360a186122320ad780f --stream wss://ditto.ngrok.app/relay
connecting to wss://ditto.ngrok.app/relay... ok.
{"id":"0d41b5812be2faa00968d44d0d8b82b72d3b414bd2d0178916b8f44c2dbb1bb3","pubkey":"d4ac0aa9df4ae9c491fde58ae4846079ad20332a59d7a360a186122320ad780f","created_at":1715543973,"kind":24133,"tags":[["p","0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd"]],"content":"Sl6bmNSwpsfwbREwtDVNpRAqnaMQga2w1t+zC1uhr49uuhQwieTLyEx9OS6XMn2Lm8OiZqcZ2SJijXBXc9c88X60pLeHeRKORrjx1ocjW/TWhl9P2vGz8CFAYzkxR65ItTVvfO8Zr/pkn1Jr1bL/FsU6IB4MbyqzLr5CeloWXG0kwbLfFzAM4DB9E/jm76hdSifvNsb9aR/FUXZajcnamQ==?iv=OaEe3j7H7ibB2aMroBj+iA==","sig":"4cb97d35e0714bcb04ce10bdfecdf07132d8ebdf18ec38fd740fe65dff941cbffe08a96463e655a5533bad1b4d97af399363f93fcf4f7b9518a996be470ab25b"}

This is what I see when I use NIP-46 between Soapbox (as the signer) and Ditto (as the app)

In my relay logs I also see this, when that happens:

  ditto:http   <-- GET /relay
  ditto:http   --> GET /relay 101 0ms

With Amber, I don't even see the GET /relay

alexgleason commented 4 months ago

Are you able to confirm that Amber makes outgoing connections to relays other than relay.nsec.app?

greenart7c3 commented 4 months ago

yes just tested with relay.damus.io

2024-05-12 17:04:24.067  9693-10090 Relay                   com.greenart7c3.nostrsigner.debug    D  Connect onOpen wss://relay.damus.io okhttp3.internal.ws.RealWebSocket@312366a
2024-05-12 17:04:24.522  9693-10090 Relay                   com.greenart7c3.nostrsigner.debug    W  Relay on OK wss://relay.damus.io, 63fe4cc3028ce2d8312ef5b329766837357af3d617dc3020cbded381e6e2293c, true,
greenart7c3 commented 4 months ago

Same thing happens with your relay but it never leaves the loading screen in nostrudel

alexgleason commented 4 months ago

I'm trying another relay I manage. relay.mostr.pub. It's running strfry, like relay.damus.io, so it should work.

Amber doesn't show up in the logs when I try to connect through it.

alex@mostr-relay:~$ grep Amber /var/log/nginx/access.log
alex@mostr-relay:~$ 

Amethyst:

image

alexgleason commented 4 months ago

I wonder if it's somehow a connection issue between my phone. I'm running the latest APK from 2 days ago. I wish I could get debug logs from it more easily.

It's the "free" version without Google Play.

greenart7c3 commented 4 months ago

it should be connectinh when you press the grant permissions button I had some weird dns issues once in my work and on 4g but it was solved when i updated okhttp dependency Can you install android studio to check your phone logs?

alexgleason commented 4 months ago

I have Android Studio. Let me try.

greenart7c3 commented 4 months ago

Relay on OK wss://relay.mostr.pub, 2d9bab3d66242658925cc868e45ea033c6fdcad0c1e36167c56114a082fed7ad, false, blocked: the event doesn't match the allowed filters

alexgleason commented 4 months ago

Ah-hah!

2024-05-12 15:34:54.282 25334-25397 ConnectivityService     com.greenart7c3.nostrsigner          D  Checking connectivity...
2024-05-12 15:34:54.283 25334-25397 ConnectivityService     com.greenart7c3.nostrsigner          D  Relay wss://ditto.ngrok.app/relay is not connected, reconnecting...
2024-05-12 15:34:54.283 25334-25397 Relay                   com.greenart7c3.nostrsigner          D  Relay.connect wss://ditto.ngrok.app/relay hasProxy: false
2024-05-12 15:34:54.290 25334-29779 Relay                   com.greenart7c3.nostrsigner          W  Relay onFailure wss://ditto.ngrok.app/relay, null null
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W  java.net.UnknownHostException: Unable to resolve host "ditto.ngrok.app": No address associated with hostname
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:147)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.net.InetAddress.getAllByName(InetAddress.java:1152)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.Dns$Companion$DnsSystem.lookup(Unknown Source:5)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(Unknown Source:145)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RouteSelector.nextProxy(Unknown Source:20)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RouteSelector.next(Unknown Source:17)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RealRoutePlanner.planConnect$okhttp(Unknown Source:59)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RealRoutePlanner.plan(Unknown Source:39)
2024-05-12 15:34:54.290 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.FastFallbackExchangeFinder.launchTcpConnect(Unknown Source:16)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.FastFallbackExchangeFinder.find(Unknown Source:74)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RealCall.initExchange$okhttp(Unknown Source:29)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.ConnectInterceptor.intercept(Unknown Source:11)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source:149)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.cache.CacheInterceptor.intercept(Unknown Source:141)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source:149)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.BridgeInterceptor.intercept(Unknown Source:170)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source:149)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(Unknown Source:34)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source:149)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at com.greenart7c3.nostrsigner.service.HttpClientManager$DefaultContentTypeInterceptor.intercept(Unknown Source:25)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source:149)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(Unknown Source:116)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at okhttp3.internal.connection.RealCall$AsyncCall.run(Unknown Source:45)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
2024-05-12 15:34:54.291 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.lang.Thread.run(Thread.java:1012)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W  Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at libcore.io.Linux.android_getaddrinfo(Native Method)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:133)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:222)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:133)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W      at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
2024-05-12 15:34:54.292 25334-29779 System.err              com.greenart7c3.nostrsigner          W      ... 26 more
2024-05-12 15:34:54.293 25334-29779 System.err              com.greenart7c3.nostrsigner          W  Caused by: android.system.ErrnoException: android_getaddrinfo failed: EACCES (Permission denied)
2024-05-12 15:34:54.293 25334-29779 System.err              com.greenart7c3.nostrsigner          W      ... 31 more
alexgleason commented 4 months ago

Caused by: android.system.ErrnoException: android_getaddrinfo failed: EACCES (Permission denied)

Is this really just an Android permissions issue?

alexgleason commented 4 months ago

Omg. Wtf dude. 🤦 Sorry for wasting so much time on this. I don't remember being prompted.

Screenshot_20240512-153910

greenart7c3 commented 4 months ago

no problem

alexgleason commented 4 months ago

Now I am seeing the connect event come through!

Thanks again!