aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nostr-login.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/nostr-login.js b/src/nostr-login.js
index 562a5d4..e5490ec 100644
--- a/src/nostr-login.js
+++ b/src/nostr-login.js
@@ -36,7 +36,7 @@ import { hex, bech32 } from '@scure/base';
import { sha256 } from '@noble/hashes/sha256';
import { entropyToMnemonic } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
-import { getPublicKey, finalizeEvent, nip44 } from './nostr.js';
+import { getPublicKey, finalizeEvent, nip44, liveRelayList } from './nostr.js';
import { SimplePool } from 'nostr-tools/pool';
import { generateSecretKey } from 'nostr-tools/pure';
import { decode as nip19decode } from 'nostr-tools/nip19';
@@ -208,7 +208,24 @@ export function nostrConnectPending(timeoutMs = 180_000) {
} catch {}
return null;
}
-export async function nostrConnect({ relays = ['wss://relay.coinos.io', 'wss://nos.lol'], timeoutMs = 180_000, resume = null } = {}) {
+// The relays a nostrconnect:// link names: the signer app publishes its
+// approval there and we wait there, so a dead one is a login that spins
+// until it times out. A PAFF account's Amber sign-in sat on "waiting for
+// signer" while nos.lol (the link's second relay) refused connections, and
+// relay.nsec.app was down the same night (Adam, 2026-11-19). So the link
+// leads with relay.coinos.io and relay.primal.net (up, and both keep NIP-46
+// traffic), leaves out any relay this device has recently found dead, and
+// names three: one relay's outage no longer strands the handshake.
+const CONNECT_RELAYS = ['wss://relay.coinos.io', 'wss://relay.primal.net', 'wss://nos.lol', 'wss://offchain.pub'];
+export function connectRelays(candidates = CONNECT_RELAYS, n = 3) {
+ let live = candidates;
+ try { live = liveRelayList(candidates); } catch {}
+ const picked = live.slice(0, n);
+ // our own relay always: its ops are ours to fix, and the poller reads it
+ if (!picked.includes(candidates[0])) picked.unshift(candidates[0]);
+ return picked.slice(0, n);
+}
+export async function nostrConnect({ relays = connectRelays(), timeoutMs = 180_000, resume = null } = {}) {
const { BunkerSigner, createNostrConnectURI } = await loadNip46();
const local = resume ? hex.decode(resume.local) : generateSecretKey();
const secret = resume ? resume.secret : hex.encode(crypto.getRandomValues(new Uint8Array(16)));