@konemono/nostr-login 1.12.13 → 1.12.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.12.13",
3
+ "version": "1.12.14",
4
4
  "description": "Extended fork of nostr-login with multi-relay support, QR scanner, and improved stability",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "@rollup/plugin-commonjs": "^25.0.7",
31
31
  "@rollup/plugin-node-resolve": "^15.2.3",
32
32
  "@rollup/plugin-terser": "^0.4.4",
33
- "@konemono/nostr-login-components": "^1.1.13",
33
+ "@konemono/nostr-login-components": "^1.1.14",
34
34
  "prettier": "^3.2.2",
35
35
  "rollup": "^4.9.6",
36
36
  "rollup-plugin-typescript2": "^0.36.0"
@@ -865,12 +865,17 @@ class AuthNostrService extends EventEmitter implements Signer {
865
865
  }
866
866
 
867
867
  /**
868
- * subscriptionを再開する
868
+ * subscriptionを再開する。
869
+ * タイムアウト付きで、ハングを防止する。
869
870
  */
870
871
  private async ensureSubscription() {
871
872
  if (this.signer && this.signer.rpc) {
872
873
  try {
873
- await (this.signer.rpc as any).resubscribe?.();
874
+ const resubscribePromise = (this.signer.rpc as any).resubscribe?.();
875
+ if (resubscribePromise) {
876
+ const timeoutMs = 10000;
877
+ await Promise.race([resubscribePromise, new Promise<never>((_, reject) => setTimeout(() => reject(new Error('ensureSubscription timed out')), timeoutMs))]);
878
+ }
874
879
  console.log('ensureSubscription: subscription re-established');
875
880
  } catch (e) {
876
881
  console.warn('ensureSubscription: failed to resubscribe', e);
@@ -37,8 +37,31 @@ class NostrRpc extends NDKNostrRpc {
37
37
  public async subscribe(filter: NDKFilter): Promise<NDKSubscription> {
38
38
  filter.kinds = filter.kinds?.filter(k => k === 24133);
39
39
  this.lastSubscribeFilter = { ...filter };
40
- this.sub = await super.subscribe(filter);
41
- return this.sub;
40
+
41
+ // NDKNostrRpc.subscribe() はEOSE待ちのPromiseを返すが、
42
+ // リレーが不安定な状態ではEOSEが届かず無限にハングする。
43
+ // NIP-46ではリアルタイムのレスポンスのみ必要なので、
44
+ // EOSE待ちをスキップして直接subscribeする。
45
+ const sub = this._ndk.subscribe(filter, {
46
+ closeOnEose: false,
47
+ groupable: false,
48
+ });
49
+
50
+ sub.on('event', async (event: NDKEvent) => {
51
+ try {
52
+ const parsedEvent = await this.parseEvent(event);
53
+ if ((parsedEvent as NDKRpcRequest).method) {
54
+ this.emit('request', parsedEvent);
55
+ } else {
56
+ this.emit(`response-${parsedEvent.id}`, parsedEvent);
57
+ }
58
+ } catch (e) {
59
+ console.error('error parsing event in subscription', e);
60
+ }
61
+ });
62
+
63
+ this.sub = sub;
64
+ return sub;
42
65
  }
43
66
 
44
67
  public stop() {