nostr-wot-sdk 0.4.0 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.4.2] - 2025-02-05
9
+
10
+ ### Fixed
11
+
12
+ - **Extension disconnection issue** - SDK now always gets fresh reference from `window.nostr.wot`
13
+ - Previously, the SDK cached the extension reference and never refreshed it
14
+ - When extension reloaded (updates, service worker restarts), the cached reference became stale
15
+ - Now the SDK checks `window.nostr.wot` on every call to handle extension reloads gracefully
16
+
17
+ ## [0.4.1] - 2025-02-05
18
+
19
+ ### Changed
20
+
21
+ - **`getDetails` now returns `score`** in addition to `hops` and `paths`
22
+ - Extension: `{ hops: 2, paths: 5, score: 0.65 }`
23
+ - Oracle fallback: `{ hops: 2, paths: 5, score: 0 }` (score is 0 when using oracle)
24
+
25
+ - **`getDistanceBatch` now accepts options object** instead of boolean
26
+ - `{ includePaths: true }` - Include path counts
27
+ - `{ includeScores: true }` - Include trust scores
28
+ - `{ includePaths: true, includeScores: true }` - Include both
29
+ - Legacy boolean `true` still works (backwards compatible, same as `{ includePaths: true }`)
30
+
31
+ ### Added
32
+
33
+ - New `DistanceBatchOptions` type exported for TypeScript users
34
+
8
35
  ## [0.4.0] - 2025-02-05
9
36
 
10
37
  ### Breaking Changes
@@ -153,6 +180,8 @@ function Profile({ pubkey }) {
153
180
  - TypeScript support with full type definitions
154
181
  - Error classes: `WoTError`, `NetworkError`, `NotFoundError`, `TimeoutError`, `ValidationError`
155
182
 
183
+ [0.4.2]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.4.1...v0.4.2
184
+ [0.4.1]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.4.0...v0.4.1
156
185
  [0.4.0]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.3.2...v0.4.0
157
186
  [0.3.2]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.3.1...v0.3.2
158
187
  [0.3.1]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.3.0...v0.3.1
package/README.md CHANGED
@@ -124,11 +124,11 @@ const results = await wot.batchCheck(['pk1...', 'pk2...', 'pk3...']);
124
124
 
125
125
  #### `getDetails(target, options?)`
126
126
 
127
- Get distance and path count details.
127
+ Get distance, path count, and score details.
128
128
  ```javascript
129
129
  const details = await wot.getDetails('def456...');
130
- // Returns: { hops: 2, paths: 5 }
131
- // Oracle may also return: bridges, mutual
130
+ // Returns: { hops: 2, paths: 5, score: 0.65 }
131
+ // Oracle may also return: bridges, mutual (but score will be 0)
132
132
  ```
133
133
 
134
134
  #### `getMyPubkey()`
@@ -157,17 +157,28 @@ const config = await wot.getExtensionConfig();
157
157
 
158
158
  ### Batch Operations
159
159
 
160
- #### `getDistanceBatch(targets, includePaths?)`
160
+ #### `getDistanceBatch(targets, options?)`
161
161
 
162
162
  Get distances for multiple pubkeys in a single call.
163
163
  ```javascript
164
- // Without paths (faster, default)
164
+ // Default (just hops)
165
165
  const distances = await wot.getDistanceBatch(['pk1...', 'pk2...']);
166
166
  // Returns: { 'pk1...': 2, 'pk2...': null }
167
167
 
168
- // With paths (includes path count for scoring)
169
- const details = await wot.getDistanceBatch(['pk1...', 'pk2...'], true);
168
+ // With paths
169
+ const withPaths = await wot.getDistanceBatch(['pk1...', 'pk2...'], { includePaths: true });
170
170
  // Returns: { 'pk1...': { hops: 2, paths: 5 }, 'pk2...': null }
171
+
172
+ // With scores
173
+ const withScores = await wot.getDistanceBatch(['pk1...', 'pk2...'], { includeScores: true });
174
+ // Returns: { 'pk1...': { hops: 2, score: 0.65 }, 'pk2...': null }
175
+
176
+ // With both
177
+ const full = await wot.getDistanceBatch(['pk1...', 'pk2...'], { includePaths: true, includeScores: true });
178
+ // Returns: { 'pk1...': { hops: 2, paths: 5, score: 0.65 }, 'pk2...': null }
179
+
180
+ // Legacy boolean still works (backwards compatible)
181
+ const legacy = await wot.getDistanceBatch(['pk1...'], true); // same as { includePaths: true }
171
182
  ```
172
183
 
173
184
  #### `getTrustScoreBatch(targets)`
package/dist/index.cjs CHANGED
@@ -336,30 +336,42 @@ var WoT = class {
336
336
  /**
337
337
  * Checks if browser extension is available and returns it
338
338
  * Uses event-based connection flow for reliable detection
339
+ * Always returns fresh reference from window.nostr.wot to handle extension reloads
339
340
  */
340
341
  async getExtension() {
341
- var _a, _b;
342
- if (this.extensionChecked) return this.extension;
343
- this.extensionChecked = true;
342
+ var _a, _b, _c;
344
343
  if (typeof window === "undefined") return null;
345
344
  const win = window;
346
345
  if ((_a = win.nostr) == null ? void 0 : _a.wot) {
347
346
  this.extension = win.nostr.wot;
348
- } else {
349
- const result = await checkAndConnect({
350
- checkTimeout: 100,
351
- connectTimeout: 5e3,
352
- autoConnect: true
353
- });
354
- if (result.state === "connected" && result.extension) {
355
- this.extension = result.extension;
347
+ this.extensionChecked = true;
348
+ if (!this.extensionPubkey) {
349
+ try {
350
+ this.extensionPubkey = await this.extension.getMyPubkey();
351
+ } catch (e) {
352
+ if ((_b = win.nostr) == null ? void 0 : _b.getPublicKey) {
353
+ try {
354
+ this.extensionPubkey = await win.nostr.getPublicKey();
355
+ } catch (e2) {
356
+ }
357
+ }
358
+ }
356
359
  }
360
+ return this.extension;
357
361
  }
358
- if (this.extension) {
362
+ if (this.extensionChecked) return this.extension;
363
+ this.extensionChecked = true;
364
+ const result = await checkAndConnect({
365
+ checkTimeout: 100,
366
+ connectTimeout: 5e3,
367
+ autoConnect: true
368
+ });
369
+ if (result.state === "connected" && result.extension) {
370
+ this.extension = result.extension;
359
371
  try {
360
372
  this.extensionPubkey = await this.extension.getMyPubkey();
361
373
  } catch (e) {
362
- if ((_b = win.nostr) == null ? void 0 : _b.getPublicKey) {
374
+ if ((_c = win.nostr) == null ? void 0 : _c.getPublicKey) {
363
375
  try {
364
376
  this.extensionPubkey = await win.nostr.getPublicKey();
365
377
  } catch (e2) {
@@ -621,10 +633,11 @@ var WoT = class {
621
633
  const myPubkey = await this.getEffectivePubkey();
622
634
  const maxHops = (_a = options == null ? void 0 : options.maxHops) != null ? _a : this.maxHops;
623
635
  try {
624
- return await this.apiRequest(
636
+ const response = await this.apiRequest(
625
637
  `/details/${myPubkey}/${normalizedTarget}?maxHops=${maxHops}`,
626
638
  options
627
639
  );
640
+ return { ...response, score: 0 };
628
641
  } catch (error) {
629
642
  if (error instanceof NotFoundError) {
630
643
  return null;
@@ -745,26 +758,32 @@ var WoT = class {
745
758
  const normalizedTarget = this.validatePubkey(target, "target");
746
759
  return ext.getPath(normalizedTarget);
747
760
  }
748
- async getDistanceBatch(targets, includePaths = false) {
761
+ async getDistanceBatch(targets, options = false) {
749
762
  if (!Array.isArray(targets) || targets.length === 0) {
750
763
  return {};
751
764
  }
752
765
  const normalizedTargets = targets.map(
753
766
  (t, i) => this.validatePubkey(t, `targets[${i}]`)
754
767
  );
768
+ const opts = typeof options === "boolean" ? { includePaths: options } : options || {};
769
+ const { includePaths, includeScores } = opts;
755
770
  const ext = await this.getExtension();
756
771
  if (ext) {
757
- if (includePaths) {
758
- return ext.getDistanceBatch(normalizedTargets, true);
759
- }
760
- return ext.getDistanceBatch(normalizedTargets, false);
772
+ return ext.getDistanceBatch(normalizedTargets, opts);
761
773
  }
762
- if (includePaths) {
774
+ if (includePaths || includeScores) {
763
775
  const results2 = {};
764
776
  await Promise.all(
765
777
  normalizedTargets.map(async (pubkey) => {
766
778
  const details = await this.getDetails(pubkey);
767
- results2[pubkey] = details ? { hops: details.hops, paths: details.paths } : null;
779
+ if (!details) {
780
+ results2[pubkey] = null;
781
+ return;
782
+ }
783
+ const result = { hops: details.hops };
784
+ if (includePaths) result.paths = details.paths;
785
+ if (includeScores) result.score = details.score;
786
+ results2[pubkey] = result;
768
787
  })
769
788
  );
770
789
  return results2;
package/dist/index.d.cts CHANGED
@@ -88,7 +88,7 @@ interface QueryOptions {
88
88
  timeout?: number;
89
89
  }
90
90
  /**
91
- * Distance result from extension (simpler)
91
+ * Distance result from extension
92
92
  */
93
93
  interface ExtensionDistanceResult {
94
94
  /**
@@ -99,6 +99,24 @@ interface ExtensionDistanceResult {
99
99
  * Number of distinct paths to target
100
100
  */
101
101
  paths: number;
102
+ /**
103
+ * Trust score (0-1)
104
+ * Note: Only available from extension, oracle returns 0
105
+ */
106
+ score: number;
107
+ }
108
+ /**
109
+ * Options for getDistanceBatch
110
+ */
111
+ interface DistanceBatchOptions {
112
+ /**
113
+ * Include path count in results
114
+ */
115
+ includePaths?: boolean;
116
+ /**
117
+ * Include trust scores in results
118
+ */
119
+ includeScores?: boolean;
102
120
  }
103
121
  /**
104
122
  * Full distance result with additional details (from oracle)
@@ -231,8 +249,8 @@ interface NostrWoTExtension {
231
249
  */
232
250
  getTrustScore(target: string): Promise<number | null>;
233
251
  /**
234
- * Get distance and path count details
235
- * @returns Object with hops and paths count, or null if not connected
252
+ * Get distance, path count, and score details
253
+ * @returns Object with hops, paths, and score, or null if not connected
236
254
  */
237
255
  getDetails(target: string): Promise<ExtensionDistanceResult | null>;
238
256
  /**
@@ -243,17 +261,40 @@ interface NostrWoTExtension {
243
261
  /**
244
262
  * Get distances for multiple pubkeys in a single call
245
263
  * @param targets - Array of target pubkeys
246
- * @param includePaths - When true, includes path count for each target
247
- * @returns Map of pubkey to hop count (or { hops, paths } if includePaths is true)
248
- */
249
- getDistanceBatch(targets: string[], includePaths?: false): Promise<Record<string, number | null>>;
250
- getDistanceBatch(targets: string[], includePaths: true): Promise<Record<string, {
264
+ * @param options - Options object or boolean for backwards compatibility
265
+ * - `{ includePaths: true }` - Include path counts
266
+ * - `{ includeScores: true }` - Include trust scores
267
+ * - `{ includePaths: true, includeScores: true }` - Include both
268
+ * - `true` (legacy) - Same as `{ includePaths: true }`
269
+ * @returns Map of pubkey to result based on options
270
+ */
271
+ getDistanceBatch(targets: string[], options?: false | undefined): Promise<Record<string, number | null>>;
272
+ getDistanceBatch(targets: string[], options: true | {
273
+ includePaths: true;
274
+ includeScores?: false;
275
+ }): Promise<Record<string, {
251
276
  hops: number;
252
277
  paths: number;
253
278
  } | null>>;
254
- getDistanceBatch(targets: string[], includePaths?: boolean): Promise<Record<string, number | {
279
+ getDistanceBatch(targets: string[], options: {
280
+ includePaths?: false;
281
+ includeScores: true;
282
+ }): Promise<Record<string, {
283
+ hops: number;
284
+ score: number;
285
+ } | null>>;
286
+ getDistanceBatch(targets: string[], options: {
287
+ includePaths: true;
288
+ includeScores: true;
289
+ }): Promise<Record<string, {
255
290
  hops: number;
256
291
  paths: number;
292
+ score: number;
293
+ } | null>>;
294
+ getDistanceBatch(targets: string[], options?: boolean | DistanceBatchOptions): Promise<Record<string, number | {
295
+ hops: number;
296
+ paths?: number;
297
+ score?: number;
257
298
  } | null>>;
258
299
  /**
259
300
  * Get trust scores for multiple pubkeys in a single call
@@ -330,6 +371,7 @@ declare class WoT {
330
371
  /**
331
372
  * Checks if browser extension is available and returns it
332
373
  * Uses event-based connection flow for reliable detection
374
+ * Always returns fresh reference from window.nostr.wot to handle extension reloads
333
375
  */
334
376
  private getExtension;
335
377
  /**
@@ -455,17 +497,40 @@ declare class WoT {
455
497
  /**
456
498
  * Get distances for multiple pubkeys in a single call
457
499
  * @param targets - Array of target pubkeys
458
- * @param includePaths - When true, includes path count for each target
459
- * @returns Record of pubkey to hop count (or { hops, paths } if includePaths is true)
460
- */
461
- getDistanceBatch(targets: string[], includePaths?: false): Promise<Record<string, number | null>>;
462
- getDistanceBatch(targets: string[], includePaths: true): Promise<Record<string, {
500
+ * @param options - Options object or boolean for backwards compatibility
501
+ * - `{ includePaths: true }` - Include path counts
502
+ * - `{ includeScores: true }` - Include trust scores
503
+ * - `{ includePaths: true, includeScores: true }` - Include both
504
+ * - `true` (legacy) - Same as `{ includePaths: true }`
505
+ * @returns Record of pubkey to result based on options
506
+ */
507
+ getDistanceBatch(targets: string[], options?: false | undefined): Promise<Record<string, number | null>>;
508
+ getDistanceBatch(targets: string[], options: true | {
509
+ includePaths: true;
510
+ includeScores?: false;
511
+ }): Promise<Record<string, {
463
512
  hops: number;
464
513
  paths: number;
465
514
  } | null>>;
466
- getDistanceBatch(targets: string[], includePaths?: boolean): Promise<Record<string, number | {
515
+ getDistanceBatch(targets: string[], options: {
516
+ includePaths?: false;
517
+ includeScores: true;
518
+ }): Promise<Record<string, {
519
+ hops: number;
520
+ score: number;
521
+ } | null>>;
522
+ getDistanceBatch(targets: string[], options: {
523
+ includePaths: true;
524
+ includeScores: true;
525
+ }): Promise<Record<string, {
467
526
  hops: number;
468
527
  paths: number;
528
+ score: number;
529
+ } | null>>;
530
+ getDistanceBatch(targets: string[], options?: boolean | DistanceBatchOptions): Promise<Record<string, number | {
531
+ hops: number;
532
+ paths?: number;
533
+ score?: number;
469
534
  } | null>>;
470
535
  /**
471
536
  * Get trust scores for multiple pubkeys in a single call
@@ -644,4 +709,4 @@ declare const MAX_BATCH_SIZE = 10000;
644
709
  */
645
710
  declare function normalizePubkey(pubkey: string): string;
646
711
 
647
- export { type BatchResult, DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, type DistanceResult, type ExtensionConfig, type ExtensionConnectionOptions, type ExtensionConnectionResult, type ExtensionConnectionState, ExtensionConnector, type ExtensionDistanceResult, type ExtensionStatus, type GraphStats, MAX_BATCH_SIZE, NetworkError, type NostrContactEvent, type NostrWindow, type NostrWoTExtension, NotFoundError, type QueryOptions, type ScoringConfig, TimeoutError, ValidationError, WoT, WoTError, type WoTFallbackOptions, type WoTOptions, checkAndConnect, checkExtension, connectExtension, getDefaultConnector, isValidOracleUrl, isValidPubkey, normalizePubkey, resetDefaultConnector };
712
+ export { type BatchResult, DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, type DistanceBatchOptions, type DistanceResult, type ExtensionConfig, type ExtensionConnectionOptions, type ExtensionConnectionResult, type ExtensionConnectionState, ExtensionConnector, type ExtensionDistanceResult, type ExtensionStatus, type GraphStats, MAX_BATCH_SIZE, NetworkError, type NostrContactEvent, type NostrWindow, type NostrWoTExtension, NotFoundError, type QueryOptions, type ScoringConfig, TimeoutError, ValidationError, WoT, WoTError, type WoTFallbackOptions, type WoTOptions, checkAndConnect, checkExtension, connectExtension, getDefaultConnector, isValidOracleUrl, isValidPubkey, normalizePubkey, resetDefaultConnector };
package/dist/index.d.ts CHANGED
@@ -88,7 +88,7 @@ interface QueryOptions {
88
88
  timeout?: number;
89
89
  }
90
90
  /**
91
- * Distance result from extension (simpler)
91
+ * Distance result from extension
92
92
  */
93
93
  interface ExtensionDistanceResult {
94
94
  /**
@@ -99,6 +99,24 @@ interface ExtensionDistanceResult {
99
99
  * Number of distinct paths to target
100
100
  */
101
101
  paths: number;
102
+ /**
103
+ * Trust score (0-1)
104
+ * Note: Only available from extension, oracle returns 0
105
+ */
106
+ score: number;
107
+ }
108
+ /**
109
+ * Options for getDistanceBatch
110
+ */
111
+ interface DistanceBatchOptions {
112
+ /**
113
+ * Include path count in results
114
+ */
115
+ includePaths?: boolean;
116
+ /**
117
+ * Include trust scores in results
118
+ */
119
+ includeScores?: boolean;
102
120
  }
103
121
  /**
104
122
  * Full distance result with additional details (from oracle)
@@ -231,8 +249,8 @@ interface NostrWoTExtension {
231
249
  */
232
250
  getTrustScore(target: string): Promise<number | null>;
233
251
  /**
234
- * Get distance and path count details
235
- * @returns Object with hops and paths count, or null if not connected
252
+ * Get distance, path count, and score details
253
+ * @returns Object with hops, paths, and score, or null if not connected
236
254
  */
237
255
  getDetails(target: string): Promise<ExtensionDistanceResult | null>;
238
256
  /**
@@ -243,17 +261,40 @@ interface NostrWoTExtension {
243
261
  /**
244
262
  * Get distances for multiple pubkeys in a single call
245
263
  * @param targets - Array of target pubkeys
246
- * @param includePaths - When true, includes path count for each target
247
- * @returns Map of pubkey to hop count (or { hops, paths } if includePaths is true)
248
- */
249
- getDistanceBatch(targets: string[], includePaths?: false): Promise<Record<string, number | null>>;
250
- getDistanceBatch(targets: string[], includePaths: true): Promise<Record<string, {
264
+ * @param options - Options object or boolean for backwards compatibility
265
+ * - `{ includePaths: true }` - Include path counts
266
+ * - `{ includeScores: true }` - Include trust scores
267
+ * - `{ includePaths: true, includeScores: true }` - Include both
268
+ * - `true` (legacy) - Same as `{ includePaths: true }`
269
+ * @returns Map of pubkey to result based on options
270
+ */
271
+ getDistanceBatch(targets: string[], options?: false | undefined): Promise<Record<string, number | null>>;
272
+ getDistanceBatch(targets: string[], options: true | {
273
+ includePaths: true;
274
+ includeScores?: false;
275
+ }): Promise<Record<string, {
251
276
  hops: number;
252
277
  paths: number;
253
278
  } | null>>;
254
- getDistanceBatch(targets: string[], includePaths?: boolean): Promise<Record<string, number | {
279
+ getDistanceBatch(targets: string[], options: {
280
+ includePaths?: false;
281
+ includeScores: true;
282
+ }): Promise<Record<string, {
283
+ hops: number;
284
+ score: number;
285
+ } | null>>;
286
+ getDistanceBatch(targets: string[], options: {
287
+ includePaths: true;
288
+ includeScores: true;
289
+ }): Promise<Record<string, {
255
290
  hops: number;
256
291
  paths: number;
292
+ score: number;
293
+ } | null>>;
294
+ getDistanceBatch(targets: string[], options?: boolean | DistanceBatchOptions): Promise<Record<string, number | {
295
+ hops: number;
296
+ paths?: number;
297
+ score?: number;
257
298
  } | null>>;
258
299
  /**
259
300
  * Get trust scores for multiple pubkeys in a single call
@@ -330,6 +371,7 @@ declare class WoT {
330
371
  /**
331
372
  * Checks if browser extension is available and returns it
332
373
  * Uses event-based connection flow for reliable detection
374
+ * Always returns fresh reference from window.nostr.wot to handle extension reloads
333
375
  */
334
376
  private getExtension;
335
377
  /**
@@ -455,17 +497,40 @@ declare class WoT {
455
497
  /**
456
498
  * Get distances for multiple pubkeys in a single call
457
499
  * @param targets - Array of target pubkeys
458
- * @param includePaths - When true, includes path count for each target
459
- * @returns Record of pubkey to hop count (or { hops, paths } if includePaths is true)
460
- */
461
- getDistanceBatch(targets: string[], includePaths?: false): Promise<Record<string, number | null>>;
462
- getDistanceBatch(targets: string[], includePaths: true): Promise<Record<string, {
500
+ * @param options - Options object or boolean for backwards compatibility
501
+ * - `{ includePaths: true }` - Include path counts
502
+ * - `{ includeScores: true }` - Include trust scores
503
+ * - `{ includePaths: true, includeScores: true }` - Include both
504
+ * - `true` (legacy) - Same as `{ includePaths: true }`
505
+ * @returns Record of pubkey to result based on options
506
+ */
507
+ getDistanceBatch(targets: string[], options?: false | undefined): Promise<Record<string, number | null>>;
508
+ getDistanceBatch(targets: string[], options: true | {
509
+ includePaths: true;
510
+ includeScores?: false;
511
+ }): Promise<Record<string, {
463
512
  hops: number;
464
513
  paths: number;
465
514
  } | null>>;
466
- getDistanceBatch(targets: string[], includePaths?: boolean): Promise<Record<string, number | {
515
+ getDistanceBatch(targets: string[], options: {
516
+ includePaths?: false;
517
+ includeScores: true;
518
+ }): Promise<Record<string, {
519
+ hops: number;
520
+ score: number;
521
+ } | null>>;
522
+ getDistanceBatch(targets: string[], options: {
523
+ includePaths: true;
524
+ includeScores: true;
525
+ }): Promise<Record<string, {
467
526
  hops: number;
468
527
  paths: number;
528
+ score: number;
529
+ } | null>>;
530
+ getDistanceBatch(targets: string[], options?: boolean | DistanceBatchOptions): Promise<Record<string, number | {
531
+ hops: number;
532
+ paths?: number;
533
+ score?: number;
469
534
  } | null>>;
470
535
  /**
471
536
  * Get trust scores for multiple pubkeys in a single call
@@ -644,4 +709,4 @@ declare const MAX_BATCH_SIZE = 10000;
644
709
  */
645
710
  declare function normalizePubkey(pubkey: string): string;
646
711
 
647
- export { type BatchResult, DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, type DistanceResult, type ExtensionConfig, type ExtensionConnectionOptions, type ExtensionConnectionResult, type ExtensionConnectionState, ExtensionConnector, type ExtensionDistanceResult, type ExtensionStatus, type GraphStats, MAX_BATCH_SIZE, NetworkError, type NostrContactEvent, type NostrWindow, type NostrWoTExtension, NotFoundError, type QueryOptions, type ScoringConfig, TimeoutError, ValidationError, WoT, WoTError, type WoTFallbackOptions, type WoTOptions, checkAndConnect, checkExtension, connectExtension, getDefaultConnector, isValidOracleUrl, isValidPubkey, normalizePubkey, resetDefaultConnector };
712
+ export { type BatchResult, DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, type DistanceBatchOptions, type DistanceResult, type ExtensionConfig, type ExtensionConnectionOptions, type ExtensionConnectionResult, type ExtensionConnectionState, ExtensionConnector, type ExtensionDistanceResult, type ExtensionStatus, type GraphStats, MAX_BATCH_SIZE, NetworkError, type NostrContactEvent, type NostrWindow, type NostrWoTExtension, NotFoundError, type QueryOptions, type ScoringConfig, TimeoutError, ValidationError, WoT, WoTError, type WoTFallbackOptions, type WoTOptions, checkAndConnect, checkExtension, connectExtension, getDefaultConnector, isValidOracleUrl, isValidPubkey, normalizePubkey, resetDefaultConnector };
package/dist/index.js CHANGED
@@ -334,30 +334,42 @@ var WoT = class {
334
334
  /**
335
335
  * Checks if browser extension is available and returns it
336
336
  * Uses event-based connection flow for reliable detection
337
+ * Always returns fresh reference from window.nostr.wot to handle extension reloads
337
338
  */
338
339
  async getExtension() {
339
- var _a, _b;
340
- if (this.extensionChecked) return this.extension;
341
- this.extensionChecked = true;
340
+ var _a, _b, _c;
342
341
  if (typeof window === "undefined") return null;
343
342
  const win = window;
344
343
  if ((_a = win.nostr) == null ? void 0 : _a.wot) {
345
344
  this.extension = win.nostr.wot;
346
- } else {
347
- const result = await checkAndConnect({
348
- checkTimeout: 100,
349
- connectTimeout: 5e3,
350
- autoConnect: true
351
- });
352
- if (result.state === "connected" && result.extension) {
353
- this.extension = result.extension;
345
+ this.extensionChecked = true;
346
+ if (!this.extensionPubkey) {
347
+ try {
348
+ this.extensionPubkey = await this.extension.getMyPubkey();
349
+ } catch (e) {
350
+ if ((_b = win.nostr) == null ? void 0 : _b.getPublicKey) {
351
+ try {
352
+ this.extensionPubkey = await win.nostr.getPublicKey();
353
+ } catch (e2) {
354
+ }
355
+ }
356
+ }
354
357
  }
358
+ return this.extension;
355
359
  }
356
- if (this.extension) {
360
+ if (this.extensionChecked) return this.extension;
361
+ this.extensionChecked = true;
362
+ const result = await checkAndConnect({
363
+ checkTimeout: 100,
364
+ connectTimeout: 5e3,
365
+ autoConnect: true
366
+ });
367
+ if (result.state === "connected" && result.extension) {
368
+ this.extension = result.extension;
357
369
  try {
358
370
  this.extensionPubkey = await this.extension.getMyPubkey();
359
371
  } catch (e) {
360
- if ((_b = win.nostr) == null ? void 0 : _b.getPublicKey) {
372
+ if ((_c = win.nostr) == null ? void 0 : _c.getPublicKey) {
361
373
  try {
362
374
  this.extensionPubkey = await win.nostr.getPublicKey();
363
375
  } catch (e2) {
@@ -619,10 +631,11 @@ var WoT = class {
619
631
  const myPubkey = await this.getEffectivePubkey();
620
632
  const maxHops = (_a = options == null ? void 0 : options.maxHops) != null ? _a : this.maxHops;
621
633
  try {
622
- return await this.apiRequest(
634
+ const response = await this.apiRequest(
623
635
  `/details/${myPubkey}/${normalizedTarget}?maxHops=${maxHops}`,
624
636
  options
625
637
  );
638
+ return { ...response, score: 0 };
626
639
  } catch (error) {
627
640
  if (error instanceof NotFoundError) {
628
641
  return null;
@@ -743,26 +756,32 @@ var WoT = class {
743
756
  const normalizedTarget = this.validatePubkey(target, "target");
744
757
  return ext.getPath(normalizedTarget);
745
758
  }
746
- async getDistanceBatch(targets, includePaths = false) {
759
+ async getDistanceBatch(targets, options = false) {
747
760
  if (!Array.isArray(targets) || targets.length === 0) {
748
761
  return {};
749
762
  }
750
763
  const normalizedTargets = targets.map(
751
764
  (t, i) => this.validatePubkey(t, `targets[${i}]`)
752
765
  );
766
+ const opts = typeof options === "boolean" ? { includePaths: options } : options || {};
767
+ const { includePaths, includeScores } = opts;
753
768
  const ext = await this.getExtension();
754
769
  if (ext) {
755
- if (includePaths) {
756
- return ext.getDistanceBatch(normalizedTargets, true);
757
- }
758
- return ext.getDistanceBatch(normalizedTargets, false);
770
+ return ext.getDistanceBatch(normalizedTargets, opts);
759
771
  }
760
- if (includePaths) {
772
+ if (includePaths || includeScores) {
761
773
  const results2 = {};
762
774
  await Promise.all(
763
775
  normalizedTargets.map(async (pubkey) => {
764
776
  const details = await this.getDetails(pubkey);
765
- results2[pubkey] = details ? { hops: details.hops, paths: details.paths } : null;
777
+ if (!details) {
778
+ results2[pubkey] = null;
779
+ return;
780
+ }
781
+ const result = { hops: details.hops };
782
+ if (includePaths) result.paths = details.paths;
783
+ if (includeScores) result.score = details.score;
784
+ results2[pubkey] = result;
766
785
  })
767
786
  );
768
787
  return results2;