@konemono/nostr-login 1.11.4 → 1.11.5
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/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/unpkg.js +1 -1
- package/package.json +1 -1
- package/src/modules/AuthNostrService.ts +11 -0
- package/src/modules/Nip46.ts +24 -22
package/package.json
CHANGED
|
@@ -610,6 +610,17 @@ 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
|
+
|
|
613
624
|
// we should notify the banner the same way as
|
|
614
625
|
// the onAuthUrl does
|
|
615
626
|
this.signer.on(`iframeRestart`, async () => {
|
package/src/modules/Nip46.ts
CHANGED
|
@@ -408,34 +408,36 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
// 接続確認(必要時のみping)
|
|
411
|
-
|
|
412
|
-
|
|
411
|
+
// Nip46.tsのNip46Signerクラス
|
|
412
|
+
private async ensureConnection(retries: number = 2): Promise<void> {
|
|
413
|
+
if (!this._remotePubkey) return;
|
|
413
414
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
// 最近ping成功していればスキップ
|
|
417
|
-
if (now - this.lastPingTime < this.pingCacheDuration) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
415
|
+
const now = Date.now();
|
|
420
416
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
this.lastPingTime = now;
|
|
425
|
-
console.log('Connection check OK');
|
|
426
|
-
return;
|
|
427
|
-
} catch (error) {
|
|
428
|
-
if (i === retries) {
|
|
429
|
-
console.error('Connection check failed after retries', error);
|
|
430
|
-
throw new Error('NIP-46 connection lost');
|
|
431
|
-
}
|
|
417
|
+
if (now - this.lastPingTime < this.pingCacheDuration) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
432
420
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
421
|
+
for (let i = 0; i <= retries; i++) {
|
|
422
|
+
try {
|
|
423
|
+
await this._rpc.pingWithTimeout(this._remotePubkey, 10000);
|
|
424
|
+
this.lastPingTime = now;
|
|
425
|
+
console.log('Connection check OK');
|
|
426
|
+
return;
|
|
427
|
+
} catch (error) {
|
|
428
|
+
if (i === retries) {
|
|
429
|
+
console.error('Ping failed, triggering reconnection');
|
|
430
|
+
// 再接続処理をトリガー
|
|
431
|
+
this.emit('connectionLost');
|
|
432
|
+
throw new Error('NIP-46 connection lost');
|
|
436
433
|
}
|
|
434
|
+
|
|
435
|
+
const delay = Math.min(1000 * Math.pow(2, i), 5000);
|
|
436
|
+
console.log(`Ping failed, retrying in ${delay}ms...`);
|
|
437
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
437
438
|
}
|
|
438
439
|
}
|
|
440
|
+
}
|
|
439
441
|
|
|
440
442
|
private async setSignerPubkey(signerPubkey: string, sameAsUser: boolean = false) {
|
|
441
443
|
console.log('setSignerPubkey', signerPubkey);
|