@konemono/nostr-login 1.11.6 → 1.11.8

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.11.6",
3
+ "version": "1.11.8",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,7 +12,6 @@
12
12
  "author": "a-fralou",
13
13
  "dependencies": {
14
14
  "@nostr-dev-kit/ndk": "^2.3.1",
15
- "events": "^3.3.0",
16
15
  "nostr-tools": "^1.17.0",
17
16
  "tseep": "^1.2.1"
18
17
  },
@@ -610,17 +610,6 @@ class AuthNostrService extends EventEmitter implements Signer {
610
610
  const localSigner = new PrivateKeySigner(info.sk!);
611
611
  this.signer = new Nip46Signer(this.ndk, localSigner, info.signerPubkey!, info.iframeUrl ? new URL(info.iframeUrl!).origin : undefined);
612
612
 
613
- // ★ once を使う - 1回だけ実行される ★
614
- this.signer.once('connectionLost', async () => {
615
- console.log('Connection lost, attempting to reconnect...');
616
- this.signer = null;
617
-
618
- if (this.params.userInfo) {
619
- await this.initSigner(this.params.userInfo);
620
- }
621
- });
622
-
623
-
624
613
  // we should notify the banner the same way as
625
614
  // the onAuthUrl does
626
615
  this.signer.on(`iframeRestart`, async () => {
@@ -15,8 +15,7 @@ class NostrRpc extends NDKNostrRpc {
15
15
  protected requests: Set<string> = new Set();
16
16
  private sub?: NDKSubscription;
17
17
  protected _useNip44: boolean = false;
18
- protected eventEmitter: EventEmitter = new EventEmitter();
19
-
18
+ private eventEmitter: EventEmitter = new EventEmitter();
20
19
 
21
20
  public constructor(ndk: NDK, signer: PrivateKeySigner) {
22
21
  super(ndk, signer, ndk.debug.extend('nip46:signer:rpc'));
@@ -150,7 +149,7 @@ class NostrRpc extends NDKNostrRpc {
150
149
  }
151
150
 
152
151
  // タイムアウト対応のping
153
- public async pingWithTimeout(remotePubkey: string, timeoutMs: number = 10000): Promise<void> {
152
+ public async pingWithTimeout(remotePubkey: string, timeoutMs: number = 3000): Promise<void> {
154
153
  return withTimeout(this.ping(remotePubkey), timeoutMs, `Ping timeout after ${timeoutMs}ms`);
155
154
  }
156
155
 
@@ -234,14 +233,6 @@ class NostrRpc extends NDKNostrRpc {
234
233
  return this;
235
234
  }
236
235
 
237
- public override once = <EventKey extends string | symbol = string>(
238
- event: EventKey,
239
- listener: (...args: any[]) => void
240
- ): this => {
241
- this.eventEmitter.once(event as string, listener);
242
- return this;
243
- }
244
-
245
236
  public override emit = <EventKey extends string | symbol = string>(
246
237
  event: EventKey,
247
238
  ...args: any[]
@@ -382,7 +373,6 @@ export class ReadyListener {
382
373
  }
383
374
  }
384
375
 
385
-
386
376
  export class Nip46Signer extends NDKNip46Signer {
387
377
  private _userPubkey: string = '';
388
378
  private _rpc: IframeNostrRpc;
@@ -417,7 +407,10 @@ export class Nip46Signer extends NDKNip46Signer {
417
407
  this._remotePubkey = value;
418
408
  }
419
409
 
420
- // 接続確認(必要時のみping)
410
+ // Nip46.tsのNip46Signerクラス内
411
+ // 接続確認(必要時のみping リトライ付き 最大10秒)
412
+ // リトライ回数: 2回(計3回試行)
413
+ //合計最大時間: 2秒(ping) × 3回 + 2秒(待機) × 2回 = 10秒
421
414
  private async ensureConnection(retries: number = 2): Promise<void> {
422
415
  if (!this._remotePubkey) return;
423
416
 
@@ -430,48 +423,18 @@ export class Nip46Signer extends NDKNip46Signer {
430
423
 
431
424
  for (let i = 0; i <= retries; i++) {
432
425
  try {
433
- await this._rpc.pingWithTimeout(this._remotePubkey, 10000);
426
+ await this._rpc.pingWithTimeout(this._remotePubkey, 2000); // 2秒タイムアウト
434
427
  this.lastPingTime = now;
435
428
  console.log('Connection check OK');
436
429
  return;
437
430
  } catch (error) {
438
431
  if (i === retries) {
439
- console.error('Ping failed, attempting reconnection');
440
-
441
- // 再接続を試みる
442
- try {
443
- this.emit('connectionLost');
444
-
445
- // 再接続完了を待つ(最大10秒)
446
- await new Promise<void>((resolve, reject) => {
447
- const timeout = setTimeout(() => reject(new Error('Reconnection timeout')), 10000);
448
-
449
- const checkReconnection = async () => {
450
- try {
451
- await this._rpc.pingWithTimeout(this._remotePubkey!, 10000);
452
- clearTimeout(timeout);
453
- this.lastPingTime = Date.now();
454
- console.log('Reconnection successful');
455
- resolve();
456
- } catch (e) {
457
- // まだ再接続中、1秒後に再確認
458
- setTimeout(checkReconnection, 1000);
459
- }
460
- };
461
-
462
- // 少し待ってから確認開始
463
- setTimeout(checkReconnection, 2000);
464
- });
465
-
466
- return;
467
- } catch (reconnectError) {
468
- console.error('Reconnection failed:', reconnectError);
469
- throw new Error('NIP-46 connection lost and reconnection failed');
470
- }
432
+ console.error('Connection check failed after retries', error);
433
+ throw new Error('NIP-46 connection lost');
471
434
  }
472
435
 
473
- const delay = Math.min(1000 * Math.pow(2, i), 5000);
474
- console.log(`Ping failed, retrying in ${delay}ms...`);
436
+ const delay = 2000; // 2秒間隔で再送
437
+ console.log(`Ping failed (${i + 1}/${retries + 1}), retrying in ${delay}ms...`);
475
438
  await new Promise(resolve => setTimeout(resolve, delay));
476
439
  }
477
440
  }
@@ -580,23 +543,6 @@ export class Nip46Signer extends NDKNip46Signer {
580
543
  }
581
544
 
582
545
  // EventEmitter互換メソッド
583
- // ★ ここに once を追加 ★
584
- public override on = <EventKey extends string | symbol = string>(
585
- event: EventKey,
586
- listener: (...args: any[]) => void
587
- ): this => {
588
- this._rpc.on(event as string, listener);
589
- return this;
590
- }
591
-
592
- public override once = <EventKey extends string | symbol = string>(
593
- event: EventKey,
594
- listener: (...args: any[]) => void
595
- ): this => {
596
- this._rpc.once(event as string, listener);
597
- return this;
598
- }
599
-
600
546
  public override emit = <EventKey extends string | symbol = string>(
601
547
  event: EventKey,
602
548
  ...args: any[]