@keyringnetwork/keyring-connect-sdk 3.1.0 → 3.2.0

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
@@ -9,6 +9,9 @@ export declare class KeyringConnect {
9
9
  /**
10
10
  * Tries to launch the Keyring Connect Extension with the provided configuration.
11
11
  * If the extension is not installed, it will redirect to the Keyring Connect page.
12
+ * @throws If the extension is not installed and running in a non-browser environment,
13
+ * if required configuration fields are missing, if Chrome runtime is not available,
14
+ * if extension communication times out, or if the extension returns an error.
12
15
  * @param data - The configuration for the extension
13
16
  */
14
17
  static launchExtension(data: ExtensionSDKConfig): Promise<void>;
@@ -33,11 +36,8 @@ export declare class KeyringConnect {
33
36
  static subscribeToExtensionState(callback: (state: ExtensionState | null) => void): () => void;
34
37
  private static validateClientConfig;
35
38
  private static validateCredentialConfig;
36
- private static validateProofConfig;
37
39
  private static validateConfigData;
38
40
  private static convertToLaunchConfig;
39
41
  private static isChromeRuntimeAvailable;
40
42
  private static sendChromeMessage;
41
- private static launchExtensionViaChromeAPI;
42
- private static getExtensionStateViaChromeAPI;
43
43
  }
package/dist/main.js CHANGED
@@ -18,6 +18,9 @@ class KeyringConnect {
18
18
  /**
19
19
  * Tries to launch the Keyring Connect Extension with the provided configuration.
20
20
  * If the extension is not installed, it will redirect to the Keyring Connect page.
21
+ * @throws If the extension is not installed and running in a non-browser environment,
22
+ * if required configuration fields are missing, if Chrome runtime is not available,
23
+ * if extension communication times out, or if the extension returns an error.
21
24
  * @param data - The configuration for the extension
22
25
  */
23
26
  static launchExtension(data) {
@@ -36,7 +39,10 @@ class KeyringConnect {
36
39
  }
37
40
  const validatedConfig = this.validateConfigData(data);
38
41
  const launchConfig = this.convertToLaunchConfig(validatedConfig);
39
- yield this.launchExtensionViaChromeAPI(launchConfig);
42
+ yield this.sendChromeMessage({
43
+ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT,
44
+ data: launchConfig,
45
+ });
40
46
  });
41
47
  }
42
48
  /**
@@ -59,9 +65,21 @@ class KeyringConnect {
59
65
  const timeout = new Promise((resolve) => {
60
66
  setTimeout(() => resolve(null), this.EXTENSION_TIMEOUT);
61
67
  });
68
+ // Check if Chrome is available first
69
+ if (!this.isChromeRuntimeAvailable()) {
70
+ return null;
71
+ }
62
72
  let extensionResponse;
63
- extensionResponse = this.getExtensionStateViaChromeAPI();
64
- return Promise.race([timeout, extensionResponse]);
73
+ extensionResponse = this.sendChromeMessage({
74
+ type: types_1.EVENT_ACTIONS.GET_STATUS,
75
+ });
76
+ try {
77
+ return yield Promise.race([timeout, extensionResponse]);
78
+ }
79
+ catch (error) {
80
+ // If there's an error (like Chrome runtime not available), return null
81
+ return null;
82
+ }
65
83
  });
66
84
  }
67
85
  /**
@@ -129,20 +147,8 @@ class KeyringConnect {
129
147
  }
130
148
  return config;
131
149
  }
132
- static validateProofConfig(config) {
133
- var _a;
134
- if ((_a = config.proof_config) === null || _a === void 0 ? void 0 : _a.datasource) {
135
- if (config.proof_config.datasource.proof_sources.length === 0) {
136
- throw new Error("At least one proof source is required");
137
- }
138
- if (!config.proof_config.datasource.proof_sources.some((source) => source.claims.length > 0)) {
139
- throw new Error("At least one claim is required per proof source");
140
- }
141
- }
142
- }
143
150
  static validateConfigData(config) {
144
151
  this.validateClientConfig(config);
145
- this.validateProofConfig(config);
146
152
  this.validateCredentialConfig(config);
147
153
  return config;
148
154
  }
@@ -166,7 +172,6 @@ class KeyringConnect {
166
172
  websocketProxyUrl: config.krn_config.websocketProxyUrl,
167
173
  }
168
174
  : undefined,
169
- proof_config: config.proof_config,
170
175
  };
171
176
  return launchConfig;
172
177
  }
@@ -212,21 +217,6 @@ class KeyringConnect {
212
217
  });
213
218
  });
214
219
  }
215
- static launchExtensionViaChromeAPI(launchConfig) {
216
- return __awaiter(this, void 0, void 0, function* () {
217
- return this.sendChromeMessage({
218
- type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT,
219
- data: launchConfig,
220
- });
221
- });
222
- }
223
- static getExtensionStateViaChromeAPI() {
224
- return __awaiter(this, void 0, void 0, function* () {
225
- return this.sendChromeMessage({
226
- type: types_1.EVENT_ACTIONS.GET_STATUS,
227
- });
228
- });
229
- }
230
220
  }
231
221
  exports.KeyringConnect = KeyringConnect;
232
222
  KeyringConnect.EXTENSION_TIMEOUT = 2000;
package/dist/types.d.ts CHANGED
@@ -27,14 +27,6 @@ export type ExtensionSDKConfig = {
27
27
  chain_id: number;
28
28
  wallet_address: string;
29
29
  };
30
- /**
31
- * Additional configuration to customize the extension's verification process.
32
- * @note should be used with caution as strict validation is applied to the proof config.
33
- */
34
- proof_config?: {
35
- datasource?: DataSource;
36
- entity_type?: string;
37
- };
38
30
  /**
39
31
  * Keyring Network configuration for the extension.
40
32
  * @note this is meant to be used for internal testing and development purposes.
@@ -61,10 +53,6 @@ export type ExtensionLaunchConfig = {
61
53
  wallet_address: string;
62
54
  };
63
55
  };
64
- proof_config?: {
65
- datasource?: DataSource;
66
- entity_type?: string;
67
- };
68
56
  krn_config?: {
69
57
  keyring_api_url?: string;
70
58
  keyring_user_app_url?: string;
@@ -106,47 +94,6 @@ export interface ExtensionState {
106
94
  tlsn_proof?: string;
107
95
  credentialData?: CredentialData;
108
96
  }
109
- export interface DataSource {
110
- id: string;
111
- name: string;
112
- label: string;
113
- user_actions: string[];
114
- link: string;
115
- login_url: string;
116
- target_url: string | null;
117
- image: string;
118
- proof_sources: ProofSource[];
119
- }
120
- export interface ProofSource {
121
- id: string;
122
- endpoint: TlsnEndpoint;
123
- claims: Claim[];
124
- label?: string;
125
- }
126
- export interface TlsnEndpoint {
127
- url: string;
128
- method: string;
129
- headers: string[];
130
- disclosable_fields: DisclosableField[];
131
- required_cookies: string[] | null;
132
- data_bounds: DataBounds | null;
133
- body: string | null;
134
- }
135
- export interface Claim {
136
- id: string;
137
- label: string;
138
- rule_id: string;
139
- entity_type: string;
140
- }
141
- export interface DataBounds {
142
- max_sent_data: number;
143
- max_recv_data: number;
144
- }
145
- export interface DisclosableField {
146
- label: string;
147
- path: string;
148
- key: string;
149
- }
150
97
  export interface CredentialData {
151
98
  trader: `0x${string}`;
152
99
  policyId: number;
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
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",
7
7
  "scripts": {
8
8
  "build": "rm -rf dist && tsc",
9
9
  "dev": "tsc --watch",
10
- "build_and_publish": "pnpm build && npm publish"
10
+ "build_and_publish": "pnpm build && npm publish",
11
+ "test": "jest",
12
+ "test:watch": "jest --watch",
13
+ "test:coverage": "jest --coverage",
14
+ "test:ci": "jest --ci --coverage --watchAll=false"
11
15
  },
12
16
  "files": [
13
17
  "dist"
@@ -17,10 +21,14 @@
17
21
  "license": "ISC",
18
22
  "devDependencies": {
19
23
  "@types/chrome": "^0.0.268",
24
+ "@types/jest": "^29.5.0",
25
+ "jest": "^29.7.0",
26
+ "jest-environment-jsdom": "^29.7.0",
27
+ "ts-jest": "^29.1.0",
20
28
  "ts-node": "^10.9.2",
21
29
  "typescript": "^5.6.3"
22
30
  },
23
31
  "dependencies": {
24
- "@keyringnetwork/contracts-abi": "2.5.0"
32
+ "@keyringnetwork/contracts-abi": "2.6.0"
25
33
  }
26
- }
34
+ }
package/readme.md CHANGED
@@ -42,7 +42,7 @@ const extensionConfig = {
42
42
  policy_id: 123,
43
43
  credential_config: {
44
44
  chain_id: 1,
45
- wallet_address: '0x123abcd'
45
+ wallet_address: '0x123abc'
46
46
  }
47
47
  };
48
48