@keyringnetwork/keyring-connect-sdk 1.0.3 → 1.0.5

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/dist/main.d.ts CHANGED
@@ -3,9 +3,10 @@ import { ExtensionSDKConfig, ExtensionState } from './types';
3
3
  * Class for interacting with the Keyring Connect browser extension
4
4
  */
5
5
  export declare class KeyringConnect {
6
+ private static keyringConnectUrl;
6
7
  /**
7
8
  * Launch the Keyring Connect Extension with the provided configuration
8
- * @note This will throw an error if the extension is not installed
9
+ * @note This will redirect to the Keyring Connect page if it is not installed
9
10
  */
10
11
  static launchExtension(data: ExtensionSDKConfig): Promise<void>;
11
12
  /**
package/dist/main.js CHANGED
@@ -18,14 +18,22 @@ const types_1 = require("./types");
18
18
  class KeyringConnect {
19
19
  /**
20
20
  * Launch the Keyring Connect Extension with the provided configuration
21
- * @note This will throw an error if the extension is not installed
21
+ * @note This will redirect to the Keyring Connect page if it is not installed
22
22
  */
23
23
  static launchExtension(data) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  var _a;
26
26
  const keyringConnectAvailable = yield this.isKeyringConnectInstalled();
27
27
  if (!keyringConnectAvailable) {
28
- throw new Error('Keyring Connect is not installed');
28
+ if (typeof window !== "undefined") {
29
+ const url = new URL(this.keyringConnectUrl);
30
+ url.searchParams.set("ref", window.location.href);
31
+ window.location.href = url.toString();
32
+ }
33
+ else {
34
+ throw new Error("Keyring Connect is not installed");
35
+ }
36
+ return;
29
37
  }
30
38
  this.validateClientConfig(data);
31
39
  this.validateProofConfig(data);
@@ -34,16 +42,16 @@ class KeyringConnect {
34
42
  try {
35
43
  const decodedJwt = (0, jwt_decode_1.jwtDecode)(data.krn_config.auth0_id_token);
36
44
  if (!decodedJwt) {
37
- throw new Error('Failed to decode auth token');
45
+ throw new Error("Failed to decode auth token");
38
46
  }
39
47
  launchConfig.auth_user = Object.assign(Object.assign({}, decodedJwt), { id_token: data.krn_config.auth0_id_token });
40
48
  }
41
49
  catch (error) {
42
- throw new Error('Invalid auth token provided');
50
+ throw new Error("Invalid auth token provided");
43
51
  }
44
52
  }
45
- console.log('launching keyring connect');
46
- window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data: launchConfig }, '*');
53
+ console.log("launching keyring connect");
54
+ window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data: launchConfig }, "*");
47
55
  });
48
56
  }
49
57
  /**
@@ -69,37 +77,37 @@ class KeyringConnect {
69
77
  static getExtensionState() {
70
78
  return __awaiter(this, void 0, void 0, function* () {
71
79
  return new Promise((resolve) => {
72
- window.addEventListener('message', (event) => {
80
+ window.addEventListener("message", (event) => {
73
81
  if (event.data.type === types_1.EVENT_ACTIONS.KEYRING_CONNECT_STATUS) {
74
82
  resolve(event.data.data);
75
83
  }
76
84
  });
77
- window.postMessage({ type: types_1.EVENT_ACTIONS.GET_STATUS }, '*');
85
+ window.postMessage({ type: types_1.EVENT_ACTIONS.GET_STATUS }, "*");
78
86
  });
79
87
  });
80
88
  }
81
89
  static validateClientConfig(config) {
82
90
  if (!config.name) {
83
- throw new Error('Name is required');
91
+ throw new Error("Name is required");
84
92
  }
85
93
  if (!config.app_url) {
86
- throw new Error('App URL is required');
94
+ throw new Error("App URL is required");
87
95
  }
88
96
  if (!config.logo_url) {
89
- throw new Error('Logo URL is required');
97
+ throw new Error("Logo URL is required");
90
98
  }
91
99
  if (!config.policy_id) {
92
- throw new Error('Policy ID is required');
100
+ throw new Error("Policy ID is required");
93
101
  }
94
102
  }
95
103
  static validateProofConfig(config) {
96
104
  var _a;
97
105
  if ((_a = config.proof_config) === null || _a === void 0 ? void 0 : _a.datasource) {
98
106
  if (config.proof_config.datasource.proof_sources.length === 0) {
99
- throw new Error('At least one proof source is required');
107
+ throw new Error("At least one proof source is required");
100
108
  }
101
109
  if (!config.proof_config.datasource.proof_sources.some((source) => source.claims.length > 0)) {
102
- throw new Error('At least one claim is required per proof source');
110
+ throw new Error("At least one claim is required per proof source");
103
111
  }
104
112
  }
105
113
  }
@@ -129,3 +137,4 @@ class KeyringConnect {
129
137
  }
130
138
  }
131
139
  exports.KeyringConnect = KeyringConnect;
140
+ KeyringConnect.keyringConnectUrl = "https://app.keyring.network/connect";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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",
@@ -18,7 +18,7 @@
18
18
  "jwt-decode": "^4.0.0"
19
19
  },
20
20
  "scripts": {
21
- "build": "tsc",
21
+ "build": "rm -rf dist && tsc",
22
22
  "dev": "tsc --watch"
23
23
  }
24
24
  }
package/readme.md CHANGED
@@ -33,13 +33,7 @@ const extensionConfig = {
33
33
  };
34
34
 
35
35
  try {
36
- const isInstalled = await KeyringConnect.isKeyringConnectInstalled();
37
-
38
- if (isInstalled) {
39
- await KeyringConnect.launchExtension(extensionConfig);
40
- } else {
41
- // show UI to install extension
42
- }
36
+ await KeyringConnect.launchExtension(extensionConfig);
43
37
  } catch (error) {
44
38
  console.error('Failed to launch Keyring Connect:', error);
45
39
  }