@keyringnetwork/keyring-connect-sdk 3.0.1 → 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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "@keyringnetwork/contracts-abi";
1
2
  export { KeyringConnect } from "./main";
2
3
  export * from "./types";
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.KeyringConnect = void 0;
18
+ __exportStar(require("@keyringnetwork/contracts-abi"), exports);
18
19
  var main_1 = require("./main");
19
20
  Object.defineProperty(exports, "KeyringConnect", { enumerable: true, get: function () { return main_1.KeyringConnect; } });
20
21
  __exportStar(require("./types"), exports);
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
  /**
@@ -45,12 +51,9 @@ class KeyringConnect {
45
51
  */
46
52
  static isKeyringConnectInstalled() {
47
53
  return __awaiter(this, void 0, void 0, function* () {
48
- try {
49
- return this.getExtensionState().then((state) => state ? Boolean(state.manifest) : false);
50
- }
51
- catch (error) {
52
- return false;
53
- }
54
+ return this.getExtensionState()
55
+ .then((state) => (state ? Boolean(state.manifest) : false))
56
+ .catch(() => false);
54
57
  });
55
58
  }
56
59
  /**
@@ -62,9 +65,21 @@ class KeyringConnect {
62
65
  const timeout = new Promise((resolve) => {
63
66
  setTimeout(() => resolve(null), this.EXTENSION_TIMEOUT);
64
67
  });
68
+ // Check if Chrome is available first
69
+ if (!this.isChromeRuntimeAvailable()) {
70
+ return null;
71
+ }
65
72
  let extensionResponse;
66
- extensionResponse = this.getExtensionStateViaChromeAPI();
67
- 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
+ }
68
83
  });
69
84
  }
70
85
  /**
@@ -132,25 +147,13 @@ class KeyringConnect {
132
147
  }
133
148
  return config;
134
149
  }
135
- static validateProofConfig(config) {
136
- var _a;
137
- if ((_a = config.proof_config) === null || _a === void 0 ? void 0 : _a.datasource) {
138
- if (config.proof_config.datasource.proof_sources.length === 0) {
139
- throw new Error("At least one proof source is required");
140
- }
141
- if (!config.proof_config.datasource.proof_sources.some((source) => source.claims.length > 0)) {
142
- throw new Error("At least one claim is required per proof source");
143
- }
144
- }
145
- }
146
150
  static validateConfigData(config) {
147
151
  this.validateClientConfig(config);
148
- this.validateProofConfig(config);
149
152
  this.validateCredentialConfig(config);
150
153
  return config;
151
154
  }
152
155
  static convertToLaunchConfig(config) {
153
- var _a, _b;
156
+ var _a;
154
157
  const launchConfig = {
155
158
  client: {
156
159
  client_name: config.name,
@@ -169,10 +172,6 @@ class KeyringConnect {
169
172
  websocketProxyUrl: config.krn_config.websocketProxyUrl,
170
173
  }
171
174
  : undefined,
172
- proof_config: config.proof_config,
173
- session_info: {
174
- access_token: (_b = config.krn_config) === null || _b === void 0 ? void 0 : _b.keyring_access_token,
175
- },
176
175
  };
177
176
  return launchConfig;
178
177
  }
@@ -218,21 +217,6 @@ class KeyringConnect {
218
217
  });
219
218
  });
220
219
  }
221
- static launchExtensionViaChromeAPI(launchConfig) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- return this.sendChromeMessage({
224
- type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT,
225
- data: launchConfig,
226
- });
227
- });
228
- }
229
- static getExtensionStateViaChromeAPI() {
230
- return __awaiter(this, void 0, void 0, function* () {
231
- return this.sendChromeMessage({
232
- type: types_1.EVENT_ACTIONS.GET_STATUS,
233
- });
234
- });
235
- }
236
220
  }
237
221
  exports.KeyringConnect = KeyringConnect;
238
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;
@@ -72,9 +60,6 @@ export type ExtensionLaunchConfig = {
72
60
  notaryUrl?: string;
73
61
  websocketProxyUrl?: string;
74
62
  };
75
- session_info?: {
76
- access_token?: string;
77
- };
78
63
  };
79
64
  export type ExtensionStatus = "idle" | "mounted" | "proving" | "prove_error" | "prove_success" | "error";
80
65
  export type AttestationStatus = "onboarding_required" | "onboarding_pending" | "attestation_ready" | "non_compliant";
@@ -109,47 +94,6 @@ export interface ExtensionState {
109
94
  tlsn_proof?: string;
110
95
  credentialData?: CredentialData;
111
96
  }
112
- export interface DataSource {
113
- id: string;
114
- name: string;
115
- label: string;
116
- user_actions: string[];
117
- link: string;
118
- login_url: string;
119
- target_url: string | null;
120
- image: string;
121
- proof_sources: ProofSource[];
122
- }
123
- export interface ProofSource {
124
- id: string;
125
- endpoint: TlsnEndpoint;
126
- claims: Claim[];
127
- label?: string;
128
- }
129
- export interface TlsnEndpoint {
130
- url: string;
131
- method: string;
132
- headers: string[];
133
- disclosable_fields: DisclosableField[];
134
- required_cookies: string[] | null;
135
- data_bounds: DataBounds | null;
136
- body: string | null;
137
- }
138
- export interface Claim {
139
- id: string;
140
- label: string;
141
- rule_id: string;
142
- entity_type: string;
143
- }
144
- export interface DataBounds {
145
- max_sent_data: number;
146
- max_recv_data: number;
147
- }
148
- export interface DisclosableField {
149
- label: string;
150
- path: string;
151
- key: string;
152
- }
153
97
  export interface CredentialData {
154
98
  trader: `0x${string}`;
155
99
  policyId: number;
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "3.0.1",
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,7 +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"
30
+ },
31
+ "dependencies": {
32
+ "@keyringnetwork/contracts-abi": "2.6.0"
22
33
  }
23
- }
34
+ }