aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-18 21:42:23 -0700
committerAdam Soltys <[email protected]>2026-11-18 21:42:23 -0700
commitcb5826cec34bd6933f1d8d3f1d76629b15ba44a1 (patch)
treefb223d4a75dbab11ae22fd94ca111bad44252f12
parent2acc1f999f502413c18052129b01196e489f3b8f (diff)
downloadcoinosv3-cb5826cec34bd6933f1d8d3f1d76629b15ba44a1.tar.gz
coinosv3-cb5826cec34bd6933f1d8d3f1d76629b15ba44a1.zip
Signer sign-in links name relays that are up. "I tried pasting from Coinos into Amber, and it just left Coinos in the spinning, waiting for signer state" (Adam, 2026-11-19, signing a PAFF account in through Amber). The nostrconnect:// link named relay.coinos.io and nos.lol, and nos.lol was refusing connections from the phone and the laptop. Amber publishes its approval to the link's relays, and the page waits on those same relays, so a dead one can leave the sign-in spinning until it times out. The link now names three relays: relay.coinos.io, then relay.primal.net (up, and it keeps NIP-46 traffic), then nos.lol or offchain.pub. Any relay this device has recently marked dead is left out and the next one takes its place; relay.coinos.io is always kept. New connect-relays-test passes, as do signer-resume, amber-dm-upgrade and features-smoke.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6TV6sjEZSpqqBen9T5
-rw-r--r--src/nostr-login.js21
-rw-r--r--tools/connect-relays-test.js18
2 files changed, 37 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)));
diff --git a/tools/connect-relays-test.js b/tools/connect-relays-test.js
new file mode 100644
index 0000000..f54407d
--- /dev/null
+++ b/tools/connect-relays-test.js
@@ -0,0 +1,18 @@
+// The relays a nostrconnect:// link names: relay.coinos.io first, then the
+// next live ones, three in all, leaving out any this device found dead.
+// Run: bun tools/connect-relays-test.js
+import { connectRelays } from '../src/nostr-login.js';
+import { markRelaySick } from '../src/nostr.js';
+let ok = true;
+const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };
+const fresh = connectRelays();
+check('three relays, ours first, primal second', fresh.length === 3 && fresh[0] === 'wss://relay.coinos.io' && fresh[1] === 'wss://relay.primal.net', fresh.join(' '));
+check('nos.lol is no longer second', fresh[1] !== 'wss://nos.lol');
+markRelaySick('wss://nos.lol', 'test');
+const after = connectRelays();
+check('a relay found dead is left out, the next one takes its place', !after.includes('wss://nos.lol') && after.includes('wss://offchain.pub') && after.length === 3, after.join(' '));
+markRelaySick('wss://relay.primal.net', 'test'); markRelaySick('wss://offchain.pub', 'test');
+const one = connectRelays();
+check('relay.coinos.io stays whatever else is down', one[0] === 'wss://relay.coinos.io', one.join(' '));
+console.log(ok ? '\n✅ connect links name live relays' : '\n❌ failed');
+process.exit(ok ? 0 : 1);