@konemono/nostr-login 1.10.12 → 1.10.14
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
|
@@ -703,20 +703,34 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
703
703
|
event.id = getEventHash(event);
|
|
704
704
|
event.sig = await this.localSigner.sign(event);
|
|
705
705
|
} else {
|
|
706
|
-
|
|
707
|
-
if (this.ndk.pool.stats().connected === 0) {
|
|
708
|
-
console.log('NDK relays disconnected, reconnecting...');
|
|
709
|
-
await this.ndk.connect();
|
|
710
|
-
}
|
|
706
|
+
await this.ensureSigner();
|
|
711
707
|
|
|
712
|
-
event.pubkey = this.signer
|
|
708
|
+
event.pubkey = this.signer!.remotePubkey;
|
|
713
709
|
event.id = getEventHash(event);
|
|
714
|
-
event.sig = await this.signer
|
|
710
|
+
event.sig = await this.signer!.sign(event);
|
|
715
711
|
}
|
|
716
712
|
console.log('signed', { event });
|
|
717
713
|
return event;
|
|
718
714
|
}
|
|
719
715
|
|
|
716
|
+
private async ensureSigner() {
|
|
717
|
+
// signerがキャンセル等で破棄されている場合は再初期化
|
|
718
|
+
if (!this.signer && this.params.userInfo) {
|
|
719
|
+
console.log('Signer was destroyed, reinitializing...');
|
|
720
|
+
await this.initSigner(this.params.userInfo);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (!this.signer) {
|
|
724
|
+
throw new Error('No signer available');
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// リレー接続を確認・再接続
|
|
728
|
+
if (this.ndk.pool.stats().connected === 0) {
|
|
729
|
+
console.log('NDK relays disconnected, reconnecting...');
|
|
730
|
+
await this.ndk.connect();
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
720
734
|
private async codec_call(method: string, pubkey: string, param: string) {
|
|
721
735
|
return new Promise<string>((resolve, reject) => {
|
|
722
736
|
this.signer!.rpc.sendRequest(this.signer!.remotePubkey!, method, [pubkey, param], 24133, (response: NDKRpcResponse) => {
|
|
@@ -733,6 +747,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
733
747
|
if (this.localSigner) {
|
|
734
748
|
return this.localSigner.encrypt(new NDKUser({ pubkey }), plaintext);
|
|
735
749
|
} else {
|
|
750
|
+
await this.ensureSigner();
|
|
736
751
|
return this.signer!.encrypt(new NDKUser({ pubkey }), plaintext);
|
|
737
752
|
}
|
|
738
753
|
}
|
|
@@ -744,7 +759,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
744
759
|
// decrypt is broken in ndk v2.3.1, and latest
|
|
745
760
|
// ndk v2.8.1 doesn't allow to override connect easily,
|
|
746
761
|
// so we reimplement and fix decrypt here as a temporary fix
|
|
747
|
-
|
|
762
|
+
await this.ensureSigner();
|
|
748
763
|
return this.codec_call('nip04_decrypt', pubkey, ciphertext);
|
|
749
764
|
}
|
|
750
765
|
}
|
|
@@ -754,6 +769,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
754
769
|
return this.nip44Codec.encrypt(this.localSigner.privateKey!, pubkey, plaintext);
|
|
755
770
|
} else {
|
|
756
771
|
// no support of nip44 in ndk yet
|
|
772
|
+
await this.ensureSigner();
|
|
757
773
|
return this.codec_call('nip44_encrypt', pubkey, plaintext);
|
|
758
774
|
}
|
|
759
775
|
}
|
|
@@ -763,6 +779,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
763
779
|
return this.nip44Codec.decrypt(this.localSigner.privateKey!, pubkey, ciphertext);
|
|
764
780
|
} else {
|
|
765
781
|
// no support of nip44 in ndk yet
|
|
782
|
+
await this.ensureSigner();
|
|
766
783
|
return this.codec_call('nip44_decrypt', pubkey, ciphertext);
|
|
767
784
|
}
|
|
768
785
|
}
|
|
@@ -16,6 +16,13 @@ class ProcessManager extends EventEmitter {
|
|
|
16
16
|
reject(new Error('Cancelled by user'));
|
|
17
17
|
}
|
|
18
18
|
this.pendingCalls.clear();
|
|
19
|
+
|
|
20
|
+
// タイマーとカウントをリセットして次の署名要求に備える
|
|
21
|
+
if (this.callTimer) {
|
|
22
|
+
clearTimeout(this.callTimer);
|
|
23
|
+
this.callTimer = undefined;
|
|
24
|
+
}
|
|
25
|
+
this.callCount = 0;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
public onAuthUrl() {
|