@konemono/nostr-login 1.7.33 → 1.7.34
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 +1 -1
- package/src/modules/Nip46.ts +26 -1
package/package.json
CHANGED
package/src/modules/Nip46.ts
CHANGED
|
@@ -13,6 +13,11 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
13
13
|
private sub?: NDKSubscription;
|
|
14
14
|
protected _useNip44: boolean = false;
|
|
15
15
|
|
|
16
|
+
public cleanupTimersAndRequests() {
|
|
17
|
+
this.clearAllTimeouts(); // private/protected なメソッドを呼び出す
|
|
18
|
+
this.requests.clear(); // requests Setをクリア
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
public constructor(ndk: NDK, signer: PrivateKeySigner, processManager?: ProcessManager) {
|
|
17
22
|
super(ndk, signer, ndk.debug.extend('nip46:signer:rpc'));
|
|
18
23
|
this._ndk = ndk;
|
|
@@ -34,7 +39,7 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
protected clearAllTimeouts() {
|
|
38
43
|
for (const timeout of this.requestTimeouts.values()) {
|
|
39
44
|
clearTimeout(timeout);
|
|
40
45
|
}
|
|
@@ -305,6 +310,14 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
305
310
|
protected async createRequestEvent(id: string, remotePubkey: string, method: string, params: string[] = [], kind = 24133) {
|
|
306
311
|
this.requests.add(id);
|
|
307
312
|
const localUser = await this._signer.user();
|
|
313
|
+
|
|
314
|
+
if (!localUser.pubkey) {
|
|
315
|
+
throw new Error('CORRUPTION: Missing local pubkey. Signer state compromised.');
|
|
316
|
+
}
|
|
317
|
+
if (!remotePubkey) {
|
|
318
|
+
throw new Error('CORRUPTION: Missing remote pubkey. Signer state compromised.');
|
|
319
|
+
}
|
|
320
|
+
|
|
308
321
|
const remoteUser = this._ndk.getUser({ pubkey: remotePubkey });
|
|
309
322
|
const request = { id, method, params };
|
|
310
323
|
|
|
@@ -509,6 +522,18 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
509
522
|
await this.initUserPubkey(sameAsUser ? signerPubkey : '');
|
|
510
523
|
}
|
|
511
524
|
|
|
525
|
+
public forceResetState() {
|
|
526
|
+
console.log('Nip46Signer state reset due to connection failure or timeout.');
|
|
527
|
+
|
|
528
|
+
// 1. ユーザー公開鍵をクリア
|
|
529
|
+
this._userPubkey = '';
|
|
530
|
+
|
|
531
|
+
// 2. リモート公開鍵をクリア
|
|
532
|
+
this.remotePubkey = ''; // 親クラスのプロパティをクリア
|
|
533
|
+
|
|
534
|
+
// 3. RPC側のタイマーとリクエストを、公開メソッド経由でクリア
|
|
535
|
+
(this._rpc as NostrRpc).cleanupTimersAndRequests();
|
|
536
|
+
}
|
|
512
537
|
public async initUserPubkey(hintPubkey?: string) {
|
|
513
538
|
if (this._userPubkey) throw new Error('Already called initUserPubkey');
|
|
514
539
|
|