nostr-wot-sdk 0.5.0 → 0.5.1

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,16 @@ 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.5.1] - 2025-02-05
9
+
10
+ ### Removed
11
+
12
+ - Removed deprecated extension connection utilities entirely:
13
+ - `checkExtension`, `connectExtension`, `checkAndConnect`
14
+ - `ExtensionConnector`, `getDefaultConnector`, `resetDefaultConnector`
15
+ - `ExtensionConnectionState`, `ExtensionConnectionResult`, `ExtensionConnectionOptions` types
16
+ - Removed `src/extension.ts` file
17
+
8
18
  ## [0.5.0] - 2025-02-05
9
19
 
10
20
  ### Changed
@@ -24,7 +34,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
34
 
25
35
  - Removed event-based connection (`nostr-wot-check`, `nostr-wot-connect` events)
26
36
  - Removed `ExtensionConnectionOptions` from React exports
27
- - Extension connection utilities (`checkExtension`, `connectExtension`, `checkAndConnect`, `ExtensionConnector`) are still exported but deprecated
28
37
 
29
38
  ## [0.4.2] - 2025-02-05
30
39
 
@@ -201,6 +210,7 @@ function Profile({ pubkey }) {
201
210
  - TypeScript support with full type definitions
202
211
  - Error classes: `WoTError`, `NetworkError`, `NotFoundError`, `TimeoutError`, `ValidationError`
203
212
 
213
+ [0.5.1]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.5.0...v0.5.1
204
214
  [0.5.0]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.4.2...v0.5.0
205
215
  [0.4.2]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.4.1...v0.4.2
206
216
  [0.4.1]: https://github.com/nostr-wot/nostr-wot-sdk/compare/v0.4.0...v0.4.1
package/dist/index.cjs CHANGED
@@ -577,235 +577,9 @@ var WoT = class {
577
577
  }
578
578
  };
579
579
 
580
- // src/extension.ts
581
- function checkExtension(timeout = 100) {
582
- return new Promise((resolve) => {
583
- var _a;
584
- if (typeof window === "undefined") {
585
- resolve(false);
586
- return;
587
- }
588
- const win = window;
589
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
590
- resolve(true);
591
- return;
592
- }
593
- const handler = () => {
594
- window.removeEventListener("nostr-wot-present", handler);
595
- clearTimeout(timer);
596
- resolve(true);
597
- };
598
- window.addEventListener("nostr-wot-present", handler);
599
- const timer = setTimeout(() => {
600
- window.removeEventListener("nostr-wot-present", handler);
601
- resolve(false);
602
- }, timeout);
603
- window.dispatchEvent(new CustomEvent("nostr-wot-check"));
604
- });
605
- }
606
- function connectExtension(timeout = 5e3) {
607
- return new Promise((resolve, reject) => {
608
- var _a;
609
- if (typeof window === "undefined") {
610
- reject(new Error("Not in browser environment"));
611
- return;
612
- }
613
- const win = window;
614
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
615
- resolve(win.nostr.wot);
616
- return;
617
- }
618
- let timer;
619
- const onReady = () => {
620
- var _a2;
621
- cleanup();
622
- const ext = (_a2 = window.nostr) == null ? void 0 : _a2.wot;
623
- if (ext) {
624
- resolve(ext);
625
- } else {
626
- reject(new Error("Extension ready event fired but API not found"));
627
- }
628
- };
629
- const onError = (e) => {
630
- cleanup();
631
- const detail = e.detail;
632
- reject(new Error((detail == null ? void 0 : detail.error) || "Connection failed"));
633
- };
634
- const cleanup = () => {
635
- clearTimeout(timer);
636
- window.removeEventListener("nostr-wot-ready", onReady);
637
- window.removeEventListener("nostr-wot-error", onError);
638
- };
639
- window.addEventListener("nostr-wot-ready", onReady);
640
- window.addEventListener("nostr-wot-error", onError);
641
- window.dispatchEvent(new CustomEvent("nostr-wot-connect"));
642
- timer = setTimeout(() => {
643
- cleanup();
644
- reject(new Error("Connection timeout"));
645
- }, timeout);
646
- });
647
- }
648
- async function checkAndConnect(options = {}) {
649
- var _a;
650
- const { checkTimeout = 100, connectTimeout = 5e3, autoConnect = true } = options;
651
- if (typeof window === "undefined") {
652
- return { state: "not-installed", extension: null };
653
- }
654
- const win = window;
655
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
656
- return { state: "connected", extension: win.nostr.wot };
657
- }
658
- const isInstalled = await checkExtension(checkTimeout);
659
- if (!isInstalled) {
660
- return { state: "not-installed", extension: null };
661
- }
662
- if (!autoConnect) {
663
- return { state: "idle", extension: null };
664
- }
665
- try {
666
- const extension = await connectExtension(connectTimeout);
667
- return { state: "connected", extension };
668
- } catch (error) {
669
- return {
670
- state: "error",
671
- extension: null,
672
- error: error instanceof Error ? error.message : "Unknown error"
673
- };
674
- }
675
- }
676
- var ExtensionConnector = class {
677
- constructor(options = {}) {
678
- this.options = options;
679
- this.state = "idle";
680
- this.extension = null;
681
- this.connectionPromise = null;
682
- this.listeners = /* @__PURE__ */ new Set();
683
- }
684
- /**
685
- * Get current state
686
- */
687
- getState() {
688
- return this.state;
689
- }
690
- /**
691
- * Get current extension instance
692
- */
693
- getExtension() {
694
- return this.extension;
695
- }
696
- /**
697
- * Get current error
698
- */
699
- getError() {
700
- return this.error;
701
- }
702
- /**
703
- * Get current result
704
- */
705
- getResult() {
706
- return {
707
- state: this.state,
708
- extension: this.extension,
709
- error: this.error
710
- };
711
- }
712
- /**
713
- * Subscribe to state changes
714
- */
715
- subscribe(listener) {
716
- this.listeners.add(listener);
717
- return () => {
718
- this.listeners.delete(listener);
719
- };
720
- }
721
- notify() {
722
- const result = this.getResult();
723
- for (const listener of this.listeners) {
724
- listener(result);
725
- }
726
- }
727
- setState(state, extension = null, error) {
728
- this.state = state;
729
- this.extension = extension;
730
- this.error = error;
731
- this.notify();
732
- }
733
- /**
734
- * Connect to the extension
735
- * Returns existing promise if already connecting
736
- */
737
- async connect() {
738
- if (this.state === "connected" && this.extension) {
739
- return this.getResult();
740
- }
741
- if (this.connectionPromise) {
742
- return this.connectionPromise;
743
- }
744
- this.connectionPromise = this.doConnect();
745
- const result = await this.connectionPromise;
746
- this.connectionPromise = null;
747
- return result;
748
- }
749
- async doConnect() {
750
- var _a;
751
- const { checkTimeout = 100, connectTimeout = 5e3 } = this.options;
752
- if (typeof window === "undefined") {
753
- this.setState("not-installed");
754
- return this.getResult();
755
- }
756
- const win = window;
757
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
758
- this.setState("connected", win.nostr.wot);
759
- return this.getResult();
760
- }
761
- this.setState("checking");
762
- const isInstalled = await checkExtension(checkTimeout);
763
- if (!isInstalled) {
764
- this.setState("not-installed");
765
- return this.getResult();
766
- }
767
- this.setState("connecting");
768
- try {
769
- const extension = await connectExtension(connectTimeout);
770
- this.setState("connected", extension);
771
- } catch (error) {
772
- this.setState(
773
- "error",
774
- null,
775
- error instanceof Error ? error.message : "Unknown error"
776
- );
777
- }
778
- return this.getResult();
779
- }
780
- /**
781
- * Reset state and disconnect
782
- */
783
- reset() {
784
- this.state = "idle";
785
- this.extension = null;
786
- this.error = void 0;
787
- this.connectionPromise = null;
788
- this.notify();
789
- }
790
- };
791
- var defaultConnector = null;
792
- function getDefaultConnector(options) {
793
- if (!defaultConnector) {
794
- defaultConnector = new ExtensionConnector(options);
795
- }
796
- return defaultConnector;
797
- }
798
- function resetDefaultConnector() {
799
- if (defaultConnector) {
800
- defaultConnector.reset();
801
- defaultConnector = null;
802
- }
803
- }
804
-
805
580
  exports.DEFAULT_MAX_HOPS = DEFAULT_MAX_HOPS;
806
581
  exports.DEFAULT_ORACLE = DEFAULT_ORACLE;
807
582
  exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
808
- exports.ExtensionConnector = ExtensionConnector;
809
583
  exports.MAX_BATCH_SIZE = MAX_BATCH_SIZE;
810
584
  exports.NetworkError = NetworkError;
811
585
  exports.NotFoundError = NotFoundError;
@@ -813,11 +587,6 @@ exports.TimeoutError = TimeoutError;
813
587
  exports.ValidationError = ValidationError;
814
588
  exports.WoT = WoT;
815
589
  exports.WoTError = WoTError;
816
- exports.checkAndConnect = checkAndConnect;
817
- exports.checkExtension = checkExtension;
818
- exports.connectExtension = connectExtension;
819
- exports.getDefaultConnector = getDefaultConnector;
820
590
  exports.isValidOracleUrl = isValidOracleUrl;
821
591
  exports.isValidPubkey = isValidPubkey;
822
592
  exports.normalizePubkey = normalizePubkey;
823
- exports.resetDefaultConnector = resetDefaultConnector;
package/dist/index.d.cts CHANGED
@@ -539,110 +539,6 @@ declare class WoT {
539
539
  getTrustScoreBatch(targets: string[]): Promise<Record<string, number | null>>;
540
540
  }
541
541
 
542
- /**
543
- * Extension connection module
544
- * Handles the event-based communication flow with the nostr-wot browser extension
545
- */
546
-
547
- /**
548
- * Extension connection state
549
- */
550
- type ExtensionConnectionState = 'idle' | 'checking' | 'connecting' | 'connected' | 'not-installed' | 'error';
551
- /**
552
- * Extension connection result
553
- */
554
- interface ExtensionConnectionResult {
555
- state: ExtensionConnectionState;
556
- extension: NostrWoTExtension | null;
557
- error?: string;
558
- }
559
- /**
560
- * Extension connection options
561
- */
562
- interface ExtensionConnectionOptions {
563
- /**
564
- * Timeout for extension check (ms)
565
- * @default 100
566
- */
567
- checkTimeout?: number;
568
- /**
569
- * Timeout for connection (ms)
570
- * @default 5000
571
- */
572
- connectTimeout?: number;
573
- /**
574
- * Auto-connect after checking
575
- * @default true
576
- */
577
- autoConnect?: boolean;
578
- }
579
- /**
580
- * Check if the nostr-wot extension is installed
581
- * Uses the nostr-wot-check / nostr-wot-present event handshake
582
- */
583
- declare function checkExtension(timeout?: number): Promise<boolean>;
584
- /**
585
- * Connect to the nostr-wot extension
586
- * Uses the nostr-wot-connect / nostr-wot-ready event handshake
587
- */
588
- declare function connectExtension(timeout?: number): Promise<NostrWoTExtension>;
589
- /**
590
- * Check and connect to the extension in one call
591
- */
592
- declare function checkAndConnect(options?: ExtensionConnectionOptions): Promise<ExtensionConnectionResult>;
593
- /**
594
- * Extension connector class for managing connection state
595
- */
596
- declare class ExtensionConnector {
597
- private options;
598
- private state;
599
- private extension;
600
- private error;
601
- private connectionPromise;
602
- private listeners;
603
- constructor(options?: ExtensionConnectionOptions);
604
- /**
605
- * Get current state
606
- */
607
- getState(): ExtensionConnectionState;
608
- /**
609
- * Get current extension instance
610
- */
611
- getExtension(): NostrWoTExtension | null;
612
- /**
613
- * Get current error
614
- */
615
- getError(): string | undefined;
616
- /**
617
- * Get current result
618
- */
619
- getResult(): ExtensionConnectionResult;
620
- /**
621
- * Subscribe to state changes
622
- */
623
- subscribe(listener: (result: ExtensionConnectionResult) => void): () => void;
624
- private notify;
625
- private setState;
626
- /**
627
- * Connect to the extension
628
- * Returns existing promise if already connecting
629
- */
630
- connect(): Promise<ExtensionConnectionResult>;
631
- private doConnect;
632
- /**
633
- * Reset state and disconnect
634
- */
635
- reset(): void;
636
- }
637
- /**
638
- * Get the default extension connector
639
- */
640
- declare function getDefaultConnector(options?: ExtensionConnectionOptions): ExtensionConnector;
641
- /**
642
- * Reset the default connector (useful for testing)
643
- */
644
- declare function resetDefaultConnector(): void;
645
-
646
542
  /**
647
543
  * Base error class for WoT SDK errors
648
544
  */
@@ -708,4 +604,4 @@ declare const MAX_BATCH_SIZE = 10000;
708
604
  */
709
605
  declare function normalizePubkey(pubkey: string): string;
710
606
 
711
- 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 };
607
+ export { type BatchResult, DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, type DistanceBatchOptions, type DistanceResult, type ExtensionConfig, 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, isValidOracleUrl, isValidPubkey, normalizePubkey };
package/dist/index.d.ts CHANGED
@@ -539,110 +539,6 @@ declare class WoT {
539
539
  getTrustScoreBatch(targets: string[]): Promise<Record<string, number | null>>;
540
540
  }
541
541
 
542
- /**
543
- * Extension connection module
544
- * Handles the event-based communication flow with the nostr-wot browser extension
545
- */
546
-
547
- /**
548
- * Extension connection state
549
- */
550
- type ExtensionConnectionState = 'idle' | 'checking' | 'connecting' | 'connected' | 'not-installed' | 'error';
551
- /**
552
- * Extension connection result
553
- */
554
- interface ExtensionConnectionResult {
555
- state: ExtensionConnectionState;
556
- extension: NostrWoTExtension | null;
557
- error?: string;
558
- }
559
- /**
560
- * Extension connection options
561
- */
562
- interface ExtensionConnectionOptions {
563
- /**
564
- * Timeout for extension check (ms)
565
- * @default 100
566
- */
567
- checkTimeout?: number;
568
- /**
569
- * Timeout for connection (ms)
570
- * @default 5000
571
- */
572
- connectTimeout?: number;
573
- /**
574
- * Auto-connect after checking
575
- * @default true
576
- */
577
- autoConnect?: boolean;
578
- }
579
- /**
580
- * Check if the nostr-wot extension is installed
581
- * Uses the nostr-wot-check / nostr-wot-present event handshake
582
- */
583
- declare function checkExtension(timeout?: number): Promise<boolean>;
584
- /**
585
- * Connect to the nostr-wot extension
586
- * Uses the nostr-wot-connect / nostr-wot-ready event handshake
587
- */
588
- declare function connectExtension(timeout?: number): Promise<NostrWoTExtension>;
589
- /**
590
- * Check and connect to the extension in one call
591
- */
592
- declare function checkAndConnect(options?: ExtensionConnectionOptions): Promise<ExtensionConnectionResult>;
593
- /**
594
- * Extension connector class for managing connection state
595
- */
596
- declare class ExtensionConnector {
597
- private options;
598
- private state;
599
- private extension;
600
- private error;
601
- private connectionPromise;
602
- private listeners;
603
- constructor(options?: ExtensionConnectionOptions);
604
- /**
605
- * Get current state
606
- */
607
- getState(): ExtensionConnectionState;
608
- /**
609
- * Get current extension instance
610
- */
611
- getExtension(): NostrWoTExtension | null;
612
- /**
613
- * Get current error
614
- */
615
- getError(): string | undefined;
616
- /**
617
- * Get current result
618
- */
619
- getResult(): ExtensionConnectionResult;
620
- /**
621
- * Subscribe to state changes
622
- */
623
- subscribe(listener: (result: ExtensionConnectionResult) => void): () => void;
624
- private notify;
625
- private setState;
626
- /**
627
- * Connect to the extension
628
- * Returns existing promise if already connecting
629
- */
630
- connect(): Promise<ExtensionConnectionResult>;
631
- private doConnect;
632
- /**
633
- * Reset state and disconnect
634
- */
635
- reset(): void;
636
- }
637
- /**
638
- * Get the default extension connector
639
- */
640
- declare function getDefaultConnector(options?: ExtensionConnectionOptions): ExtensionConnector;
641
- /**
642
- * Reset the default connector (useful for testing)
643
- */
644
- declare function resetDefaultConnector(): void;
645
-
646
542
  /**
647
543
  * Base error class for WoT SDK errors
648
544
  */
@@ -708,4 +604,4 @@ declare const MAX_BATCH_SIZE = 10000;
708
604
  */
709
605
  declare function normalizePubkey(pubkey: string): string;
710
606
 
711
- 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 };
607
+ export { type BatchResult, DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, type DistanceBatchOptions, type DistanceResult, type ExtensionConfig, 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, isValidOracleUrl, isValidPubkey, normalizePubkey };
package/dist/index.js CHANGED
@@ -575,229 +575,4 @@ var WoT = class {
575
575
  }
576
576
  };
577
577
 
578
- // src/extension.ts
579
- function checkExtension(timeout = 100) {
580
- return new Promise((resolve) => {
581
- var _a;
582
- if (typeof window === "undefined") {
583
- resolve(false);
584
- return;
585
- }
586
- const win = window;
587
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
588
- resolve(true);
589
- return;
590
- }
591
- const handler = () => {
592
- window.removeEventListener("nostr-wot-present", handler);
593
- clearTimeout(timer);
594
- resolve(true);
595
- };
596
- window.addEventListener("nostr-wot-present", handler);
597
- const timer = setTimeout(() => {
598
- window.removeEventListener("nostr-wot-present", handler);
599
- resolve(false);
600
- }, timeout);
601
- window.dispatchEvent(new CustomEvent("nostr-wot-check"));
602
- });
603
- }
604
- function connectExtension(timeout = 5e3) {
605
- return new Promise((resolve, reject) => {
606
- var _a;
607
- if (typeof window === "undefined") {
608
- reject(new Error("Not in browser environment"));
609
- return;
610
- }
611
- const win = window;
612
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
613
- resolve(win.nostr.wot);
614
- return;
615
- }
616
- let timer;
617
- const onReady = () => {
618
- var _a2;
619
- cleanup();
620
- const ext = (_a2 = window.nostr) == null ? void 0 : _a2.wot;
621
- if (ext) {
622
- resolve(ext);
623
- } else {
624
- reject(new Error("Extension ready event fired but API not found"));
625
- }
626
- };
627
- const onError = (e) => {
628
- cleanup();
629
- const detail = e.detail;
630
- reject(new Error((detail == null ? void 0 : detail.error) || "Connection failed"));
631
- };
632
- const cleanup = () => {
633
- clearTimeout(timer);
634
- window.removeEventListener("nostr-wot-ready", onReady);
635
- window.removeEventListener("nostr-wot-error", onError);
636
- };
637
- window.addEventListener("nostr-wot-ready", onReady);
638
- window.addEventListener("nostr-wot-error", onError);
639
- window.dispatchEvent(new CustomEvent("nostr-wot-connect"));
640
- timer = setTimeout(() => {
641
- cleanup();
642
- reject(new Error("Connection timeout"));
643
- }, timeout);
644
- });
645
- }
646
- async function checkAndConnect(options = {}) {
647
- var _a;
648
- const { checkTimeout = 100, connectTimeout = 5e3, autoConnect = true } = options;
649
- if (typeof window === "undefined") {
650
- return { state: "not-installed", extension: null };
651
- }
652
- const win = window;
653
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
654
- return { state: "connected", extension: win.nostr.wot };
655
- }
656
- const isInstalled = await checkExtension(checkTimeout);
657
- if (!isInstalled) {
658
- return { state: "not-installed", extension: null };
659
- }
660
- if (!autoConnect) {
661
- return { state: "idle", extension: null };
662
- }
663
- try {
664
- const extension = await connectExtension(connectTimeout);
665
- return { state: "connected", extension };
666
- } catch (error) {
667
- return {
668
- state: "error",
669
- extension: null,
670
- error: error instanceof Error ? error.message : "Unknown error"
671
- };
672
- }
673
- }
674
- var ExtensionConnector = class {
675
- constructor(options = {}) {
676
- this.options = options;
677
- this.state = "idle";
678
- this.extension = null;
679
- this.connectionPromise = null;
680
- this.listeners = /* @__PURE__ */ new Set();
681
- }
682
- /**
683
- * Get current state
684
- */
685
- getState() {
686
- return this.state;
687
- }
688
- /**
689
- * Get current extension instance
690
- */
691
- getExtension() {
692
- return this.extension;
693
- }
694
- /**
695
- * Get current error
696
- */
697
- getError() {
698
- return this.error;
699
- }
700
- /**
701
- * Get current result
702
- */
703
- getResult() {
704
- return {
705
- state: this.state,
706
- extension: this.extension,
707
- error: this.error
708
- };
709
- }
710
- /**
711
- * Subscribe to state changes
712
- */
713
- subscribe(listener) {
714
- this.listeners.add(listener);
715
- return () => {
716
- this.listeners.delete(listener);
717
- };
718
- }
719
- notify() {
720
- const result = this.getResult();
721
- for (const listener of this.listeners) {
722
- listener(result);
723
- }
724
- }
725
- setState(state, extension = null, error) {
726
- this.state = state;
727
- this.extension = extension;
728
- this.error = error;
729
- this.notify();
730
- }
731
- /**
732
- * Connect to the extension
733
- * Returns existing promise if already connecting
734
- */
735
- async connect() {
736
- if (this.state === "connected" && this.extension) {
737
- return this.getResult();
738
- }
739
- if (this.connectionPromise) {
740
- return this.connectionPromise;
741
- }
742
- this.connectionPromise = this.doConnect();
743
- const result = await this.connectionPromise;
744
- this.connectionPromise = null;
745
- return result;
746
- }
747
- async doConnect() {
748
- var _a;
749
- const { checkTimeout = 100, connectTimeout = 5e3 } = this.options;
750
- if (typeof window === "undefined") {
751
- this.setState("not-installed");
752
- return this.getResult();
753
- }
754
- const win = window;
755
- if ((_a = win.nostr) == null ? void 0 : _a.wot) {
756
- this.setState("connected", win.nostr.wot);
757
- return this.getResult();
758
- }
759
- this.setState("checking");
760
- const isInstalled = await checkExtension(checkTimeout);
761
- if (!isInstalled) {
762
- this.setState("not-installed");
763
- return this.getResult();
764
- }
765
- this.setState("connecting");
766
- try {
767
- const extension = await connectExtension(connectTimeout);
768
- this.setState("connected", extension);
769
- } catch (error) {
770
- this.setState(
771
- "error",
772
- null,
773
- error instanceof Error ? error.message : "Unknown error"
774
- );
775
- }
776
- return this.getResult();
777
- }
778
- /**
779
- * Reset state and disconnect
780
- */
781
- reset() {
782
- this.state = "idle";
783
- this.extension = null;
784
- this.error = void 0;
785
- this.connectionPromise = null;
786
- this.notify();
787
- }
788
- };
789
- var defaultConnector = null;
790
- function getDefaultConnector(options) {
791
- if (!defaultConnector) {
792
- defaultConnector = new ExtensionConnector(options);
793
- }
794
- return defaultConnector;
795
- }
796
- function resetDefaultConnector() {
797
- if (defaultConnector) {
798
- defaultConnector.reset();
799
- defaultConnector = null;
800
- }
801
- }
802
-
803
- export { DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, ExtensionConnector, MAX_BATCH_SIZE, NetworkError, NotFoundError, TimeoutError, ValidationError, WoT, WoTError, checkAndConnect, checkExtension, connectExtension, getDefaultConnector, isValidOracleUrl, isValidPubkey, normalizePubkey, resetDefaultConnector };
578
+ export { DEFAULT_MAX_HOPS, DEFAULT_ORACLE, DEFAULT_TIMEOUT, MAX_BATCH_SIZE, NetworkError, NotFoundError, TimeoutError, ValidationError, WoT, WoTError, isValidOracleUrl, isValidPubkey, normalizePubkey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-wot-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "JavaScript/TypeScript SDK for querying Nostr Web of Trust",
5
5
  "author": "Leon Acosta <leon@nostr-wot.com>",
6
6
  "license": "MIT",