@konemono/nostr-login 1.7.42 → 1.7.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.7.42",
3
+ "version": "1.7.43",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -532,21 +532,19 @@ class AuthNostrService extends EventEmitter implements Signer {
532
532
  } catch {}
533
533
  }
534
534
 
535
- // we remove support for iframe from nip05 and bunker-url methods,
536
- // only nostrconnect flow will use it.
537
- // info.iframeUrl = info.iframeUrl || (await this.getIframeUrl(info.domain));
538
535
  console.log('initSigner info', info);
539
536
 
540
- // start listening for the ready signal
541
537
  const iframeOrigin = info.iframeUrl ? new URL(info.iframeUrl!).origin : undefined;
542
- if (iframeOrigin) this.starterReady = new ReadyListener(['starterDone', 'starterError'], iframeOrigin);
543
538
 
544
- // notify modals so they could show the starter iframe,
545
- // FIXME shouldn't this come from nostrconnect service list?
539
+ if (iframeOrigin) {
540
+ this.starterReady = new ReadyListener(['starterDone', 'starterError'], iframeOrigin);
541
+ }
542
+
546
543
  this.emit('onIframeUrl', info.iframeUrl);
547
544
 
548
545
  this.signerPromise = new Promise<void>(async (ok, err) => {
549
546
  this.signerErrCallback = err;
547
+
550
548
  try {
551
549
  console.log('NDK relays before connect:', Array.from(this.ndk.pool.relays.keys()));
552
550
 
@@ -559,87 +557,70 @@ class AuthNostrService extends EventEmitter implements Signer {
559
557
 
560
558
  console.log('NDK relays after add:', Array.from(this.ndk.pool.relays.keys()));
561
559
 
562
- // 全リレーを待たずに、接続できたものだけで進める
563
- this.ndk.connect(CONNECT_TIMEOUT).catch(e => {
564
- console.log('Some relays failed to connect, continuing anyway:', e);
565
- });
560
+ // 接続開始(失敗しても続行)
561
+ this.ndk.connect(CONNECT_TIMEOUT).catch(() => {});
562
+
563
+ // 少なくとも1つ接続されるのを待つ(致命扱いしない)
564
+ await new Promise<void>(resolve => {
565
+ const start = Date.now();
566
566
 
567
- // 少なくとも1つのリレーが接続するまで待つ
568
- await new Promise<void>((resolve, reject) => {
569
- const checkConnection = () => {
570
- const connectedRelays = Array.from(this.ndk.pool.relays.values()).filter(r => r.status === 3);
567
+ const timer = setInterval(() => {
568
+ const connected = this.ndk.pool.connectedRelays();
571
569
 
572
- if (connectedRelays.length > 0) {
570
+ if (connected.length > 0) {
571
+ clearInterval(timer);
573
572
  resolve();
574
- } else {
575
- setTimeout(checkConnection, 100);
573
+ return;
576
574
  }
577
- };
578
-
579
- const timeoutId = setTimeout(() => {
580
- const connectedRelays = Array.from(this.ndk.pool.relays.values()).filter(r => r.status === 3);
581
575
 
582
- if (connectedRelays.length > 0) {
576
+ if (Date.now() - start > CONNECT_TIMEOUT) {
577
+ // タイムアウトしても続行
578
+ clearInterval(timer);
583
579
  resolve();
584
- } else {
585
- reject(new Error('No relays connected'));
586
580
  }
587
- }, CONNECT_TIMEOUT);
588
-
589
- checkConnection();
581
+ }, 100);
590
582
  });
591
583
 
592
584
  console.log(
593
585
  'NDK connected relays:',
594
- Array.from(this.ndk.pool.relays.entries()).map(([url, relay]) => ({
595
- url,
596
- status: relay.status,
597
- })),
586
+ this.ndk.pool.connectedRelays().map(r => r.url),
598
587
  );
599
588
 
600
589
  const localSigner = new NDKPrivateKeySigner(info.sk!);
601
590
  this.signer = new Nip46Signer(this.ndk, localSigner, info.signerPubkey!, iframeOrigin);
602
591
 
603
- // we should notify the banner the same way as
604
- // the onAuthUrl does
605
- this.signer.on(`iframeRestart`, async () => {
592
+ this.signer.on('iframeRestart', async () => {
606
593
  const iframeUrl = info.iframeUrl + (info.iframeUrl!.includes('?') ? '&' : '?') + 'pubkey=' + info.pubkey + '&rebind=' + localSigner.pubkey;
607
- this.emit('iframeRestart', { pubkey: info.pubkey, iframeUrl });
594
+
595
+ this.emit('iframeRestart', {
596
+ pubkey: info.pubkey,
597
+ iframeUrl,
598
+ });
608
599
  });
609
600
 
610
- // OAuth flow
611
- // if (!listen) {
612
601
  this.signer.on('authUrl', (url: string) => {
613
602
  console.log('nostr login auth url', url);
614
-
615
- // notify our UI
616
- this.emit('onAuthUrl', { url, iframeUrl: info.iframeUrl, eventToAddAccount });
603
+ this.emit('onAuthUrl', {
604
+ url,
605
+ iframeUrl: info.iframeUrl,
606
+ eventToAddAccount,
607
+ });
617
608
  });
618
- // }
619
609
 
620
610
  if (listen) {
621
- // nostrconnect: flow
622
- // wait for the incoming message from signer
623
611
  await this.listen(info);
624
612
  } else if (connect) {
625
- // bunker: flow
626
- // send 'connect' message to signer
627
613
  await this.connect(info, this.params.optionsModal.perms);
628
614
  } else {
629
- // provide saved pubkey as a hint
630
- await this.signer!.initUserPubkey(info.pubkey);
615
+ await this.signer.initUserPubkey(info.pubkey);
631
616
  }
632
617
 
633
- // ensure, we're using it in callbacks above
634
- // and expect info to be valid after this call
635
- info.pubkey = this.signer!.userPubkey!;
636
- // learned after nostrconnect flow
637
- info.signerPubkey = this.signer!.remotePubkey;
618
+ info.pubkey = this.signer.userPubkey!;
619
+ info.signerPubkey = this.signer.remotePubkey;
638
620
 
639
621
  ok();
640
622
  } catch (e) {
641
623
  console.log('initSigner failure', e);
642
- // make sure signer isn't set
643
624
  this.signer = null;
644
625
  err(e);
645
626
  }