@keyringnetwork/keyring-connect-sdk 2.4.0 → 3.0.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.
package/dist/main.d.ts CHANGED
@@ -37,10 +37,7 @@ export declare class KeyringConnect {
37
37
  private static validateConfigData;
38
38
  private static convertToLaunchConfig;
39
39
  private static isChromeRuntimeAvailable;
40
- private static get communicationMethod();
41
40
  private static sendChromeMessage;
42
41
  private static launchExtensionViaChromeAPI;
43
- private static launchExtensionViaPostMessage;
44
42
  private static getExtensionStateViaChromeAPI;
45
- private static getExtensionStateViaPostMessage;
46
43
  }
package/dist/main.js CHANGED
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.KeyringConnect = void 0;
13
- const contracts_abi_1 = require("@keyringnetwork/contracts-abi");
14
13
  const types_1 = require("./types");
15
14
  /**
16
15
  * Class for interacting with the Keyring Connect browser extension
@@ -37,12 +36,7 @@ class KeyringConnect {
37
36
  }
38
37
  const validatedConfig = this.validateConfigData(data);
39
38
  const launchConfig = this.convertToLaunchConfig(validatedConfig);
40
- if (this.communicationMethod === "chromeApi") {
41
- yield this.launchExtensionViaChromeAPI(launchConfig);
42
- }
43
- else {
44
- yield this.launchExtensionViaPostMessage(launchConfig);
45
- }
39
+ yield this.launchExtensionViaChromeAPI(launchConfig);
46
40
  });
47
41
  }
48
42
  /**
@@ -69,12 +63,7 @@ class KeyringConnect {
69
63
  setTimeout(() => resolve(null), this.EXTENSION_TIMEOUT);
70
64
  });
71
65
  let extensionResponse;
72
- if (this.communicationMethod === "chromeApi") {
73
- extensionResponse = this.getExtensionStateViaChromeAPI();
74
- }
75
- else {
76
- extensionResponse = this.getExtensionStateViaPostMessage();
77
- }
66
+ extensionResponse = this.getExtensionStateViaChromeAPI();
78
67
  return Promise.race([timeout, extensionResponse]);
79
68
  });
80
69
  }
@@ -100,12 +89,6 @@ class KeyringConnect {
100
89
  lastStateString = stateString;
101
90
  callback(state);
102
91
  };
103
- const messageHandler = (event) => {
104
- if (event.data.type === types_1.EVENT_ACTIONS.KEYRING_CONNECT_STATUS &&
105
- isActive) {
106
- processState(event.data.data);
107
- }
108
- };
109
92
  const pollStatus = () => {
110
93
  if (!isActive)
111
94
  return;
@@ -114,14 +97,12 @@ class KeyringConnect {
114
97
  .catch(() => processState(null));
115
98
  timerId = setTimeout(pollStatus, interval);
116
99
  };
117
- window.addEventListener("message", messageHandler);
118
100
  // Start polling after initial delay
119
101
  timerId = setTimeout(pollStatus, initialDelay);
120
102
  return () => {
121
103
  isActive = false;
122
104
  if (timerId)
123
105
  clearTimeout(timerId);
124
- window.removeEventListener("message", messageHandler);
125
106
  };
126
107
  }
127
108
  static validateClientConfig(config) {
@@ -139,18 +120,16 @@ class KeyringConnect {
139
120
  }
140
121
  }
141
122
  static validateCredentialConfig(config) {
142
- if (!config.credential_config) {
143
- return config;
123
+ const { credential_config } = config;
124
+ if (!credential_config) {
125
+ throw new Error("Credential config is required");
144
126
  }
145
- if (!config.credential_config.chain_id) {
127
+ if (!credential_config.chain_id) {
146
128
  throw new Error("Chain ID is required");
147
129
  }
148
- if (!config.credential_config.wallet_address) {
130
+ if (!credential_config.wallet_address) {
149
131
  throw new Error("Wallet address is required");
150
132
  }
151
- if (!(config.credential_config.chain_id in contracts_abi_1.SupportedChainIds)) {
152
- throw new Error("Invalid chain ID");
153
- }
154
133
  return config;
155
134
  }
156
135
  static validateProofConfig(config) {
@@ -179,7 +158,6 @@ class KeyringConnect {
179
158
  client_logo_url: config.logo_url,
180
159
  client_policy_id: config.policy_id,
181
160
  client_entity_id: (_a = config.krn_config) === null || _a === void 0 ? void 0 : _a.entity_id,
182
- isolate_proving: !!config.credential_config,
183
161
  credential_config: config.credential_config,
184
162
  },
185
163
  krn_config: config.krn_config
@@ -202,12 +180,6 @@ class KeyringConnect {
202
180
  var _a;
203
181
  return typeof ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.sendMessage) === "function";
204
182
  }
205
- static get communicationMethod() {
206
- if (this.isChromeRuntimeAvailable()) {
207
- return "chromeApi";
208
- }
209
- return "postMessage";
210
- }
211
183
  static sendChromeMessage(message) {
212
184
  return __awaiter(this, void 0, void 0, function* () {
213
185
  return new Promise((resolve, reject) => {
@@ -254,11 +226,6 @@ class KeyringConnect {
254
226
  });
255
227
  });
256
228
  }
257
- static launchExtensionViaPostMessage(launchConfig) {
258
- return __awaiter(this, void 0, void 0, function* () {
259
- window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data: launchConfig }, "*");
260
- });
261
- }
262
229
  static getExtensionStateViaChromeAPI() {
263
230
  return __awaiter(this, void 0, void 0, function* () {
264
231
  return this.sendChromeMessage({
@@ -266,18 +233,6 @@ class KeyringConnect {
266
233
  });
267
234
  });
268
235
  }
269
- static getExtensionStateViaPostMessage() {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- return new Promise((resolve) => {
272
- window.addEventListener("message", (event) => {
273
- if (event.data.type === types_1.EVENT_ACTIONS.KEYRING_CONNECT_STATUS) {
274
- resolve(event.data.data);
275
- }
276
- });
277
- window.postMessage({ type: types_1.EVENT_ACTIONS.GET_STATUS }, "*");
278
- });
279
- });
280
- }
281
236
  }
282
237
  exports.KeyringConnect = KeyringConnect;
283
238
  KeyringConnect.EXTENSION_TIMEOUT = 2000;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { KrnSupportedChainId as SupportedChainId } from "@keyringnetwork/contracts-abi";
2
1
  export declare enum EVENT_ACTIONS {
3
2
  LAUNCH_KEYRING_CONNECT = "LAUNCH_KEYRING_CONNECT",
4
3
  GET_STATUS = "GET_STATUS",
@@ -25,7 +24,7 @@ export type ExtensionSDKConfig = {
25
24
  * The wallet address and chain ID of the user.
26
25
  */
27
26
  credential_config: {
28
- chain_id: SupportedChainId;
27
+ chain_id: number;
29
28
  wallet_address: string;
30
29
  };
31
30
  /**
@@ -57,9 +56,8 @@ export type ExtensionLaunchConfig = {
57
56
  client_logo_url: string;
58
57
  client_policy_id: number;
59
58
  client_entity_id?: string;
60
- isolate_proving?: boolean;
61
59
  credential_config: {
62
- chain_id: SupportedChainId;
60
+ chain_id: number;
63
61
  wallet_address: string;
64
62
  };
65
63
  };
@@ -78,7 +76,6 @@ export type ExtensionLaunchConfig = {
78
76
  access_token?: string;
79
77
  };
80
78
  };
81
- export type ExtensionCommunicationMethod = "chromeApi" | "postMessage";
82
79
  export type ExtensionStatus = "idle" | "mounted" | "proving" | "prove_error" | "prove_success" | "error";
83
80
  export type AttestationStatus = "onboarding_required" | "onboarding_pending" | "attestation_ready" | "non_compliant";
84
81
  export type CredentialStatus = "expired" | "valid" | "none";
package/package.json CHANGED
@@ -1,26 +1,23 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "2.4.0",
3
+ "version": "3.0.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",
7
+ "scripts": {
8
+ "build": "rm -rf dist && tsc",
9
+ "dev": "tsc --watch",
10
+ "build_and_publish": "pnpm build && npm publish"
11
+ },
7
12
  "files": [
8
13
  "dist"
9
14
  ],
10
15
  "keywords": [],
11
16
  "author": "",
12
17
  "license": "ISC",
13
- "dependencies": {
14
- "@keyringnetwork/contracts-abi": "2.4.0"
15
- },
16
18
  "devDependencies": {
17
19
  "@types/chrome": "^0.0.268",
18
20
  "ts-node": "^10.9.2",
19
21
  "typescript": "^5.6.3"
20
- },
21
- "scripts": {
22
- "build": "rm -rf dist && tsc",
23
- "dev": "tsc --watch",
24
- "build_and_publish": "pnpm build && npm publish"
25
22
  }
26
23
  }
package/readme.md CHANGED
@@ -17,7 +17,6 @@ pnpm install @keyringnetwork/keyring-connect-sdk
17
17
  - Redirect the user back to the app where they left off after extension installation
18
18
  - Monitor extension status and user state
19
19
  - Full TypeScript support with comprehensive type definitions
20
- - Support for isolated proving mode (verification without credential creation)
21
20
 
22
21
  ## Usage
23
22
 
@@ -41,6 +40,10 @@ const extensionConfig = {
41
40
  app_url: "https://myapp.com",
42
41
  logo_url: "https://myapp.com/logo.png",
43
42
  policy_id: 123,
43
+ credential_config: {
44
+ chain_id: 1,
45
+ wallet_address: '0x123abc'
46
+ }
44
47
  };
45
48
 
46
49
  // This method handles both launching the extension if installed