@konemono/nostr-login 1.11.11 → 1.11.13
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 +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/unpkg.js +2 -2
- package/package.json +2 -1
- package/src/modules/AuthNostrService.ts +42 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konemono/nostr-login",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.esm.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"author": "a-fralou",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@nostr-dev-kit/ndk": "^2.3.1",
|
|
15
|
+
"events": "^3.3.0",
|
|
15
16
|
"nostr-tools": "^1.17.0",
|
|
16
17
|
"tseep": "^1.2.1"
|
|
17
18
|
},
|
|
@@ -96,13 +96,13 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
96
96
|
if (this.signerPromise) {
|
|
97
97
|
try {
|
|
98
98
|
await this.signerPromise;
|
|
99
|
-
} catch {}
|
|
99
|
+
} catch { }
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
if (this.readyPromise) {
|
|
103
103
|
try {
|
|
104
104
|
await this.readyPromise;
|
|
105
|
-
} catch {}
|
|
105
|
+
} catch { }
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -559,7 +559,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
559
559
|
if (this.signerPromise) {
|
|
560
560
|
try {
|
|
561
561
|
await this.signerPromise;
|
|
562
|
-
} catch {}
|
|
562
|
+
} catch { }
|
|
563
563
|
}
|
|
564
564
|
|
|
565
565
|
// we remove support for iframe from nip05 and bunker-url methods,
|
|
@@ -601,7 +601,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
601
601
|
}
|
|
602
602
|
|
|
603
603
|
private async initSignerInternal(info: Info, listen: boolean, connect: boolean, eventToAddAccount: boolean, resolve: () => void) {
|
|
604
|
-
|
|
604
|
+
// リレー接続
|
|
605
605
|
if (info.relays && !info.iframeUrl) {
|
|
606
606
|
for (const r of info.relays) {
|
|
607
607
|
this.ndk.addExplicitRelay(r, undefined);
|
|
@@ -612,9 +612,9 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
612
612
|
|
|
613
613
|
const localSigner = new PrivateKeySigner(info.sk!);
|
|
614
614
|
this.signer = new Nip46Signer(
|
|
615
|
-
this.ndk,
|
|
616
|
-
localSigner,
|
|
617
|
-
info.signerPubkey!,
|
|
615
|
+
this.ndk,
|
|
616
|
+
localSigner,
|
|
617
|
+
info.signerPubkey!,
|
|
618
618
|
info.iframeUrl ? new URL(info.iframeUrl!).origin : undefined
|
|
619
619
|
);
|
|
620
620
|
|
|
@@ -622,7 +622,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
622
622
|
this.signer.removeAllListeners?.('connectionLost');
|
|
623
623
|
this.signer.once('connectionLost', () => {
|
|
624
624
|
console.log('Connection lost detected');
|
|
625
|
-
|
|
625
|
+
|
|
626
626
|
// ★ 再接続処理を呼び出す(非同期で実行、エラーは握りつぶさない)
|
|
627
627
|
this.handleReconnection(info).catch(err => {
|
|
628
628
|
console.error('Reconnection handling failed:', err);
|
|
@@ -633,8 +633,8 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
633
633
|
// iframe restart は既存のまま
|
|
634
634
|
this.signer.removeAllListeners?.('iframeRestart');
|
|
635
635
|
this.signer.on('iframeRestart', async () => {
|
|
636
|
-
const iframeUrl = info.iframeUrl +
|
|
637
|
-
(info.iframeUrl!.includes('?') ? '&' : '?') +
|
|
636
|
+
const iframeUrl = info.iframeUrl +
|
|
637
|
+
(info.iframeUrl!.includes('?') ? '&' : '?') +
|
|
638
638
|
'pubkey=' + info.pubkey + '&rebind=' + localSigner.pubkey;
|
|
639
639
|
this.emit('iframeRestart', { pubkey: info.pubkey, iframeUrl });
|
|
640
640
|
});
|
|
@@ -689,7 +689,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
689
689
|
const stats = this.ndk.pool.stats();
|
|
690
690
|
if (stats.connected === 0) {
|
|
691
691
|
console.log('Reconnecting to relays...');
|
|
692
|
-
|
|
692
|
+
|
|
693
693
|
// 既存のリレーを切断
|
|
694
694
|
for (const relay of this.ndk.pool.relays.values()) {
|
|
695
695
|
try {
|
|
@@ -729,7 +729,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
729
729
|
if (this.reconnectAttempts < this.MAX_RECONNECT_ATTEMPTS) {
|
|
730
730
|
const delay = 2000 * this.reconnectAttempts; // 2秒, 4秒, 6秒
|
|
731
731
|
console.log(`Retrying in ${delay}ms...`);
|
|
732
|
-
|
|
732
|
+
|
|
733
733
|
setTimeout(() => {
|
|
734
734
|
this.handleReconnection(info).catch(err => {
|
|
735
735
|
console.error('Retry failed:', err);
|
|
@@ -742,7 +742,8 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
|
|
745
|
-
|
|
745
|
+
|
|
746
|
+
// ★ 修正: ensureSigner - 再接続処理を同期的に実行
|
|
746
747
|
private async ensureSigner() {
|
|
747
748
|
// signerがnullの場合のみ再初期化
|
|
748
749
|
if (!this.signer && this.currentInfo) {
|
|
@@ -755,14 +756,40 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
755
756
|
throw new Error('No signer available');
|
|
756
757
|
}
|
|
757
758
|
|
|
758
|
-
//
|
|
759
|
+
// リレー接続確認(切断されていれば再接続を同期的に実行)
|
|
759
760
|
const stats = this.ndk.pool.stats();
|
|
760
761
|
if (stats.connected === 0 && this.currentInfo) {
|
|
761
762
|
console.log('NDK relays disconnected, attempting reconnection...');
|
|
762
763
|
await this.handleReconnection(this.currentInfo);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Signer接続確認(失敗したら再接続を同期的に実行)
|
|
768
|
+
try {
|
|
769
|
+
// キャッシュ期間内ならスキップ
|
|
770
|
+
const now = Date.now();
|
|
771
|
+
if (this.signer['lastPingTime'] &&
|
|
772
|
+
now - this.signer['lastPingTime'] < this.signer['pingCacheDuration']) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// ping確認
|
|
777
|
+
if (this.signer.remotePubkey) {
|
|
778
|
+
await this.signer['_rpc'].pingWithTimeout(this.signer.remotePubkey, 2000);
|
|
779
|
+
this.signer['lastPingTime'] = now;
|
|
780
|
+
}
|
|
781
|
+
} catch (error) {
|
|
782
|
+
// ping失敗 = 接続切断
|
|
783
|
+
console.log('Connection lost during ensureSigner, attempting reconnection...');
|
|
784
|
+
if (this.currentInfo) {
|
|
785
|
+
await this.handleReconnection(this.currentInfo);
|
|
786
|
+
} else {
|
|
787
|
+
throw error;
|
|
788
|
+
}
|
|
763
789
|
}
|
|
764
790
|
}
|
|
765
791
|
|
|
792
|
+
|
|
766
793
|
public async signEvent(event: any) {
|
|
767
794
|
if (this.localSigner) {
|
|
768
795
|
event.pubkey = getPublicKey(this.localSigner.privateKey!);
|
|
@@ -779,7 +806,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
779
806
|
return event;
|
|
780
807
|
}
|
|
781
808
|
|
|
782
|
-
|
|
809
|
+
|
|
783
810
|
|
|
784
811
|
private async codec_call(method: string, pubkey: string, param: string) {
|
|
785
812
|
return new Promise<string>((resolve, reject) => {
|