@konemono/nostr-login 1.7.23 → 1.7.24

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.7.23",
3
+ "version": "1.7.24",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -144,7 +144,36 @@ class NostrRpc extends NDKNostrRpc {
144
144
  return Math.random().toString(36).substring(7);
145
145
  }
146
146
 
147
+ protected async ensureConnected(): Promise<void> {
148
+ const connectedRelays = Array.from(this._ndk.pool.relays.values()).filter(r => r.status === 1);
149
+
150
+ if (connectedRelays.length === 0) {
151
+ console.log('No connected relays, reconnecting...');
152
+ await this._ndk.connect();
153
+
154
+ await new Promise<void>((resolve, reject) => {
155
+ const timeout = setTimeout(() => {
156
+ reject(new Error('Failed to reconnect to relays'));
157
+ }, 5000);
158
+
159
+ const checkConnection = () => {
160
+ const connected = Array.from(this._ndk.pool.relays.values()).filter(r => r.status === 1);
161
+ if (connected.length > 0) {
162
+ clearTimeout(timeout);
163
+ console.log('Reconnected to', connected.length, 'relays');
164
+ resolve();
165
+ } else {
166
+ setTimeout(checkConnection, 100);
167
+ }
168
+ };
169
+ checkConnection();
170
+ });
171
+ }
172
+ }
173
+
147
174
  public async sendRequest(remotePubkey: string, method: string, params: string[] = [], kind = 24133, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse> {
175
+ await this.ensureConnected();
176
+
148
177
  const id = this.getId();
149
178
 
150
179
  this.setResponseHandler(id, cb);
@@ -166,6 +195,7 @@ class NostrRpc extends NDKNostrRpc {
166
195
  if (this.requests.has(id)) {
167
196
  this.requests.delete(id);
168
197
  this.requestTimeouts.delete(id);
198
+ console.log('NIP46 request timeout for', id);
169
199
  if (cb) {
170
200
  cb({
171
201
  id,
@@ -283,6 +313,10 @@ export class IframeNostrRpc extends NostrRpc {
283
313
  }
284
314
 
285
315
  public async sendRequest(remotePubkey: string, method: string, params: string[] = [], kind = 24133, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse> {
316
+ if (!this.iframePort) {
317
+ await this.ensureConnected();
318
+ }
319
+
286
320
  const id = this.getId();
287
321
 
288
322
  const event = await this.createRequestEvent(id, remotePubkey, method, params, kind);