@keyringnetwork/keyring-connect-sdk 2.1.0 → 2.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.
@@ -164,10 +164,7 @@
164
164
  ],
165
165
  "endpoint": {
166
166
  "body": null,
167
- "data_bounds": {
168
- "max_recv_data": 2500,
169
- "max_sent_data": 800
170
- },
167
+ "data_bounds": null,
171
168
  "disclosable_fields": [
172
169
  {
173
170
  "label": "user kyc",
@@ -229,10 +226,7 @@
229
226
  ],
230
227
  "endpoint": {
231
228
  "body": null,
232
- "data_bounds": {
233
- "max_recv_data": 2500,
234
- "max_sent_data": 800
235
- },
229
+ "data_bounds": null,
236
230
  "disclosable_fields": [
237
231
  {
238
232
  "label": "user kyc",
@@ -310,10 +304,7 @@
310
304
  ],
311
305
  "endpoint": {
312
306
  "body": null,
313
- "data_bounds": {
314
- "max_recv_data": 10000,
315
- "max_sent_data": 1000
316
- },
307
+ "data_bounds": null,
317
308
  "disclosable_fields": [
318
309
  {
319
310
  "label": "country of primary address",
@@ -369,10 +360,7 @@
369
360
  ],
370
361
  "endpoint": {
371
362
  "body": null,
372
- "data_bounds": {
373
- "max_recv_data": 10000,
374
- "max_sent_data": 1000
375
- },
363
+ "data_bounds": null,
376
364
  "disclosable_fields": [
377
365
  {
378
366
  "label": "country of primary address",
@@ -432,10 +420,7 @@
432
420
  ],
433
421
  "endpoint": {
434
422
  "body": "{\"dpIdCache\":null}",
435
- "data_bounds": {
436
- "max_recv_data": 10000,
437
- "max_sent_data": 5000
438
- },
423
+ "data_bounds": null,
439
424
  "disclosable_fields": [
440
425
  {
441
426
  "label": "mailing address",
@@ -536,7 +521,7 @@
536
521
  "image": "https://main.cdn.krnprod.net/logos/revolut.svg",
537
522
  "label": "Revolut",
538
523
  "link": "https://www.revolut.com",
539
- "login_url": "https://sso.revolut.com/signin",
524
+ "login_url": "https://app.revolut.com/start",
540
525
  "name": "Revolut",
541
526
  "proof_sources": [
542
527
  {
@@ -568,10 +553,7 @@
568
553
  ],
569
554
  "endpoint": {
570
555
  "body": null,
571
- "data_bounds": {
572
- "max_recv_data": 10000,
573
- "max_sent_data": 5000
574
- },
556
+ "data_bounds": null,
575
557
  "disclosable_fields": [
576
558
  {
577
559
  "label": "country of primary address",
@@ -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,30 @@ 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>;
23
+ /**
24
+ * Subscribe to extension state changes
25
+ * @param callback Function called with extension state updates
26
+ * The state parameter will be null if the extension is not installed
27
+ * or if an error occurs during state retrieval which indicates that
28
+ * the extension is not available (e.g. was disabled)
29
+ * @returns Unsubscribe function to stop polling
30
+ */
31
+ static subscribeToExtensionState(callback: (state: ExtensionState | null) => void): () => void;
20
32
  private static validateClientConfig;
21
33
  private static validateCredentialConfig;
22
34
  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,8 +77,55 @@ 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
  }
83
+ /**
84
+ * Subscribe to extension state changes
85
+ * @param callback Function called with extension state updates
86
+ * The state parameter will be null if the extension is not installed
87
+ * or if an error occurs during state retrieval which indicates that
88
+ * the extension is not available (e.g. was disabled)
89
+ * @returns Unsubscribe function to stop polling
90
+ */
91
+ static subscribeToExtensionState(callback) {
92
+ const interval = 3000;
93
+ const initialDelay = 0;
94
+ let isActive = true;
95
+ let timerId = null;
96
+ let lastStateString = "";
97
+ const processState = (state) => {
98
+ // Deduplicate state updates
99
+ const stateString = JSON.stringify(state);
100
+ if (stateString === lastStateString)
101
+ return;
102
+ lastStateString = stateString;
103
+ callback(state);
104
+ };
105
+ const messageHandler = (event) => {
106
+ if (event.data.type === types_1.EVENT_ACTIONS.KEYRING_CONNECT_STATUS &&
107
+ isActive) {
108
+ processState(event.data.data);
109
+ }
110
+ };
111
+ const pollStatus = () => {
112
+ if (!isActive)
113
+ return;
114
+ this.getExtensionState()
115
+ .then((state) => processState(state))
116
+ .catch(() => processState(null));
117
+ timerId = setTimeout(pollStatus, interval);
118
+ };
119
+ window.addEventListener("message", messageHandler);
120
+ // Start polling after initial delay
121
+ timerId = setTimeout(pollStatus, initialDelay);
122
+ return () => {
123
+ isActive = false;
124
+ if (timerId)
125
+ clearTimeout(timerId);
126
+ window.removeEventListener("message", messageHandler);
127
+ };
128
+ }
79
129
  static validateClientConfig(config) {
80
130
  if (!config.name) {
81
131
  throw new Error("Name is required");
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.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",