@keyringnetwork/keyring-connect-sdk 2.1.0 → 2.1.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.
@@ -0,0 +1 @@
1
+ export declare const EXTENSION_TIMEOUT = 2000;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXTENSION_TIMEOUT = void 0;
4
+ exports.EXTENSION_TIMEOUT = 2000;
package/dist/main.d.ts CHANGED
@@ -5,18 +5,21 @@ import { ExtensionSDKConfig, ExtensionState } from "./types";
5
5
  export declare class KeyringConnect {
6
6
  private static keyringConnectUrl;
7
7
  /**
8
- * Launch the Keyring Connect Extension with the provided configuration
9
- * @note This will redirect to the Keyring Connect page if it is not installed
8
+ * Tries to launch the Keyring Connect Extension with the provided configuration.
9
+ * If the extension is not installed, it will redirect to the Keyring Connect page.
10
+ * @param data - The configuration for the extension
10
11
  */
11
12
  static launchExtension(data: ExtensionSDKConfig): Promise<void>;
12
13
  /**
13
14
  * Check if Keyring Connect Extension is installed and ready to use
15
+ * @returns Promise that resolves with true if extension is installed and ready to use, false otherwise
14
16
  */
15
17
  static isKeyringConnectInstalled(): Promise<boolean>;
16
18
  /**
17
- * Get the current state of the Keyring Connect Extension to allow for UI updates
19
+ * Get the current state of the Keyring Connect Extension
20
+ * @returns Promise that resolves with extension state or null if unavailable
18
21
  */
19
- static getExtensionState(): Promise<ExtensionState>;
22
+ static getExtensionState(): Promise<ExtensionState | null>;
20
23
  private static validateClientConfig;
21
24
  private static validateCredentialConfig;
22
25
  private static validateProofConfig;
package/dist/main.js CHANGED
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.KeyringConnect = void 0;
16
16
  const contracts_abi_1 = require("@keyringnetwork/contracts-abi");
17
+ const constants_1 = require("./constants");
17
18
  const datasources_json_1 = __importDefault(require("./constants/datasources.json"));
18
19
  const types_1 = require("./types");
19
20
  /**
@@ -21,8 +22,9 @@ const types_1 = require("./types");
21
22
  */
22
23
  class KeyringConnect {
23
24
  /**
24
- * Launch the Keyring Connect Extension with the provided configuration
25
- * @note This will redirect to the Keyring Connect page if it is not installed
25
+ * Tries to launch the Keyring Connect Extension with the provided configuration.
26
+ * If the extension is not installed, it will redirect to the Keyring Connect page.
27
+ * @param data - The configuration for the extension
26
28
  */
27
29
  static launchExtension(data) {
28
30
  return __awaiter(this, void 0, void 0, function* () {
@@ -46,15 +48,12 @@ class KeyringConnect {
46
48
  }
47
49
  /**
48
50
  * Check if Keyring Connect Extension is installed and ready to use
51
+ * @returns Promise that resolves with true if extension is installed and ready to use, false otherwise
49
52
  */
50
53
  static isKeyringConnectInstalled() {
51
54
  return __awaiter(this, void 0, void 0, function* () {
52
55
  try {
53
- const timeout = new Promise((resolve) => {
54
- setTimeout(() => resolve(false), 2000);
55
- });
56
- const checkExtension = this.getExtensionState().then((state) => Boolean(state.manifest));
57
- return Promise.race([timeout, checkExtension]);
56
+ return this.getExtensionState().then((state) => state ? Boolean(state.manifest) : false);
58
57
  }
59
58
  catch (error) {
60
59
  return false;
@@ -62,11 +61,15 @@ class KeyringConnect {
62
61
  });
63
62
  }
64
63
  /**
65
- * Get the current state of the Keyring Connect Extension to allow for UI updates
64
+ * Get the current state of the Keyring Connect Extension
65
+ * @returns Promise that resolves with extension state or null if unavailable
66
66
  */
67
67
  static getExtensionState() {
68
68
  return __awaiter(this, void 0, void 0, function* () {
69
- return new Promise((resolve) => {
69
+ const timeout = new Promise((resolve) => {
70
+ setTimeout(() => resolve(null), constants_1.EXTENSION_TIMEOUT);
71
+ });
72
+ const extensionResponse = new Promise((resolve) => {
70
73
  window.addEventListener("message", (event) => {
71
74
  if (event.data.type === types_1.EVENT_ACTIONS.KEYRING_CONNECT_STATUS) {
72
75
  resolve(event.data.data);
@@ -74,6 +77,7 @@ class KeyringConnect {
74
77
  });
75
78
  window.postMessage({ type: types_1.EVENT_ACTIONS.GET_STATUS }, "*");
76
79
  });
80
+ return Promise.race([timeout, extensionResponse]);
77
81
  });
78
82
  }
79
83
  static validateClientConfig(config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "An SDK for interacting with Keyring Connect browser extension",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",